{"text": "! Algebraic routines\n!\n! author ....... Jan Tomec\n! copyright .... Copyright 2020, Project THREAD - University of Rijeka, Faculty of Civil Engineering\n! credits ...... Jan Tomec, Gordan Jelenić\n! license ...... GPL\n! version ...... 1.0.0\n! maintainer ... Jan Tomec\n! email ........ jan.tomec@gradri.uniri.hr\n! status ....... Development\n! date ......... 06/04/2020\n!\n! ------------------------------------------------------------------------------\n\nmodule vector_algebra\n\t\n\timplicit none\n\t\n\tprivate\n\t\n\tpublic :: cross_product, tensor_product, skew, rv2mat\n\t\n\tcontains\n\t\n\t! compute cross product\n\tpure function cross_product(a, b)\n\t\n\t\timplicit none\n\t\t\n\t\tdouble precision, dimension (3), intent (in) :: a, b\n\t\tdouble precision, dimension (3) :: cross_product\n\t\t\n\t\tcross_product(1) = a(2) * b(3) - a(3) * b(2)\n\t\tcross_product(2) = a(3) * b(1) - a(1) * b(3)\n\t\tcross_product(3) = a(1) * b(2) - a(2) * b(1)\n\t\t\n\tend function cross_product\n\t\n\t! compute tensor product\n\tpure function tensor_product(a, b)\n\t\n\t\timplicit none\n\t\t\n\t\tdouble precision, dimension (3), intent (in) :: a, b\n\t\tdouble precision, dimension (3, 3) :: tensor_product\n\t\tinteger :: i, j\n\t\t\n\t\tdo i = 1, 3\n\t\t\tdo j = 1, 3\n\t\t\t\ttensor_product (i, j) = a (i) * b (j)\n\t\t\tend do\n\t\tend do\n\t\t\n\tend function tensor_product\n\t\n\t! create skew-symmetric matrix from rotation vector\n\t! from Argyris_J.H.--An_excursion_into_large_rotations, p.88\n\tpure function skew (r)\n\t\t\n\t\timplicit none\n\t\t\n\t\tdouble precision, dimension (3), intent (in) :: r\n\t\tdouble precision, dimension (3, 3) :: skew\n\t\t\n\t\tskew (1, 1) = 0.0D0\n\t\tskew (1, 2) = - r (3)\n\t\tskew (1, 3) = r (2)\n\t\tskew (2, 1) = r (3)\n\t\tskew (2, 2) = 0.0D0\n\t\tskew (2, 3) = - r (1)\n\t\tskew (3, 1) = - r (2)\n\t\tskew (3, 2) = r (1)\n\t\tskew (3, 3) = 0.0D0\n\t\t\n\tend function skew\n\t\n\t! create skew-symmetric matrix squared from rotation vector\n\t! from Argyris_J.H.--An_excursion_into_large_rotations, p.88\n\tpure function skew2 (r)\n\t\n\t\timplicit none\n\t\t\n\t\tdouble precision, dimension (3), intent (in) :: r\n\t\tdouble precision, dimension (3, 3) :: skew2\n\t\t\n\t\tskew2 (1, 1) = - (r (2) ** 2 + r (3) ** 2)\n\t\tskew2 (1, 2) = r (1) * r (2)\n\t\tskew2 (1, 3) = r (1) * r (3)\n\t\tskew2 (2, 1) = r (1) * r (2)\n\t\tskew2 (2, 2) = - (r (1) ** 2 + r (3) ** 2)\n\t\tskew2 (2, 3) = r (2) * r (3)\n\t\tskew2 (3, 1) = r (1) * r (3)\n\t\tskew2 (3, 2) = r (2) * r (3)\n\t\tskew2 (3, 3) = - (r (1) ** 2 + r (2) ** 2)\n\t\t\n\tend function skew2\n\t\n\t! create rotation matrix from rotation vector\n\t! from Argyris_J.H.--An_excursion_into_large_rotations, p.88\n\tfunction rv2mat (r) result (T)\n\t\t\n\t\timplicit none\n\t\t\n\t\tdouble precision, dimension (3), intent (in) :: r\n\t\tdouble precision, dimension (3, 3) :: T, T1, T2, I, S, S2\n\t\tdouble precision :: sin_r, norm_r, sin_hr, norm_hr\n\t\tinteger :: j\n\t\t\n\t\tI = 0.0D0\n\t\tdo j = 1, 3\n\t\t\tI (j, j) = 1.0D0\n\t\tend do\n\t\t\n\t\tnorm_r = norm2 (r)\n\t\tif (norm_r .eq. 0.0D0) then\n\t\t\tT = I\n\t\t\treturn\n\t\tend if\n\t\t\n\t\tsin_r = sin (norm_r)\n\t\tnorm_hr = norm2 (r / 2.0D0)\n\t\tsin_hr = sin (norm_hr)\n\t\t\n\t\tS = skew (r)\n\t\tS2 = skew2 (r)\n\t\t\n\t\tT1 = sin_r / norm_r * S\n\t\tT2 = 0.5D0 * (sin_hr / norm_hr) ** 2 * S2\n\t\tT = I + T1 + T2\n\t\t\n\tend function rv2mat\n\t\nend module", "meta": {"hexsha": "9050f1931f3013b296dc33d25c093ab742905757", "size": 3103, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/0_vector_algebra.f90", "max_stars_repo_name": "tomecj/THREAD", "max_stars_repo_head_hexsha": "5a974aff848150d16ca0c7905867e222f1e06020", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-26T17:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-26T17:23:40.000Z", "max_issues_repo_path": "source/0_vector_algebra.f90", "max_issues_repo_name": "tomecj/BEAM-App", "max_issues_repo_head_hexsha": "5a974aff848150d16ca0c7905867e222f1e06020", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/0_vector_algebra.f90", "max_forks_repo_name": "tomecj/BEAM-App", "max_forks_repo_head_hexsha": "5a974aff848150d16ca0c7905867e222f1e06020", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.3308270677, "max_line_length": 100, "alphanum_fraction": 0.5726716081, "num_tokens": 1210, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475699138559, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7999283296676312}} {"text": " program demo_conjg\n use, intrinsic :: iso_fortran_env, only : real_kinds, &\n & real32, real64, real128\n implicit none\n complex :: z = (2.0, 3.0)\n complex(kind=real64) :: dz = ( &\n & 1.2345678901234567_real64, &\n & -1.2345678901234567_real64)\n complex :: arr(3,3)\n integer :: i\n\n print *, z\n z= conjg(z)\n print *, z\n print *\n\n print *, dz\n dz = conjg(dz)\n print *, dz\n print *\n\n ! the function is elemental so it can take arrays\n arr(1,:)=[(-1.0, 2.0),( 3.0, 4.0),( 5.0,-6.0)]\n arr(2,:)=[( 7.0,-8.0),( 8.0, 9.0),( 9.0, 9.0)]\n arr(3,:)=[( 1.0, 9.0),( 2.0, 0.0),(-3.0,-7.0)]\n\n write(*,*)'original'\n write(*,'(3(\"(\",g8.2,\",\",g8.2,\")\",1x))')(arr(i,:),i=1,3)\n arr = conjg(arr)\n write(*,*)'conjugate'\n write(*,'(3(\"(\",g8.2,\",\",g8.2,\")\",1x))')(arr(i,:),i=1,3)\n\n end program demo_conjg\n", "meta": {"hexsha": "2aecef4206d99dccc49d6fd96221565784453c75", "size": 939, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/conjg.f90", "max_stars_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_stars_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-12-31T17:21:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T15:56:29.000Z", "max_issues_repo_path": "example/conjg.f90", "max_issues_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_issues_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/conjg.f90", "max_forks_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_forks_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-06T15:56:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-06T15:56:31.000Z", "avg_line_length": 27.6176470588, "max_line_length": 64, "alphanum_fraction": 0.4547390841, "num_tokens": 373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582612793112, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.7998812352389285}} {"text": "c ==========================================================================\nc Example 1 of help file of lsode:\nc a simple function with banded jacobian - upper and lower band = 1\nc note that number of rows of PD = nupper + 2*nlower + 1\nc ==========================================================================\n\n\nc Rate of change \n subroutine derivsband (neq, t, y, ydot,out,IP)\n integer neq, IP(*)\n DOUBLE PRECISION T, Y(5), YDOT(5), out(*)\n ydot(1) = 0.1*y(1) -0.2*y(2)\n ydot(2) = -0.3*y(1) +0.1*y(2) -0.2*y(3)\n ydot(3) = -0.3*y(2) +0.1*y(3) -0.2*y(4)\n ydot(4) = -0.3*y(3) +0.1*y(4) -0.2*y(5)\n ydot(5) = -0.3*y(4) +0.1*y(5)\n RETURN\n END\n\nc The jacobian matrix \n subroutine jacband (neq, t, y, ml, mu, pd, nrowpd,RP,IP)\n INTEGER NEQ, ML, MU, nrowpd, ip(*)\n DOUBLE PRECISION T, Y(5), PD(nrowpd,5), rp(*)\n\n PD(:,:) = 0.D0\n\n PD(1,1) = 0.D0\n PD(1,2) = -.02D0\n PD(1,3) = -.02D0\n PD(1,4) = -.02D0\n PD(1,5) = -.02D0\n\n PD(2,:) = 0.1D0\n\n PD(3,1) = -0.3D0\n PD(3,2) = -0.3D0\n PD(3,3) = -0.3D0\n PD(3,4) = -0.3D0\n PD(3,5) = 0.D0\n\n RETURN\n END\n", "meta": {"hexsha": "151abd8932652a8df6868860c38b07f4494426fe", "size": 1278, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "deSolve/doc/dynload/odeband.f", "max_stars_repo_name": "solgenomics/R_libs", "max_stars_repo_head_hexsha": "a936847f6063cdf3d207e8364f05f2e13be2d878", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "deSolve/doc/dynload/odeband.f", "max_issues_repo_name": "solgenomics/R_libs", "max_issues_repo_head_hexsha": "a936847f6063cdf3d207e8364f05f2e13be2d878", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-08-17T15:14:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-23T21:55:49.000Z", "max_forks_repo_path": "deSolve/doc/dynload/odeband.f", "max_forks_repo_name": "solgenomics/R_libs", "max_forks_repo_head_hexsha": "a936847f6063cdf3d207e8364f05f2e13be2d878", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:34:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:34:16.000Z", "avg_line_length": 29.7209302326, "max_line_length": 76, "alphanum_fraction": 0.3881064163, "num_tokens": 495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458253565792, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.7998812336259661}} {"text": "\n! $UWHPSC/codes/fortran/taylor.f90\n\nprogram taylor\n\n implicit none \n real (kind=8) :: x, exp_true, y\n real (kind=8), external :: exptaylor\n integer :: n\n\n n = 20 ! number of terms to use\n x = 1.0\n exp_true = exp(x)\n y = exptaylor(x,n) ! uses function below\n print *, \"x = \",x\n print *, \"exp_true = \",exp_true\n print *, \"exptaylor = \",y\n print *, \"error = \",y - exp_true\n\nend program taylor\n\n!==========================\nfunction exptaylor(x,n)\n!==========================\n implicit none\n\n ! function arguments:\n real (kind=8), intent(in) :: x\n integer, intent(in) :: n\n real (kind=8) :: exptaylor\n\n ! local variables:\n real (kind=8) :: term, partial_sum\n integer :: j\n\n term = 1.\n partial_sum = term\n\n do j=1,n\n ! j'th term is x**j / j! which is the previous term times x/j:\n term = term*x/j \n ! add this term to the partial sum:\n partial_sum = partial_sum + term \n enddo\n exptaylor = partial_sum ! this is the value returned\nend function exptaylor\n\n", "meta": {"hexsha": "6dc0c374f246f90bfd809916e982ee4a0d6cfc22", "size": 1103, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/codes/fortran/taylor.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/codes/fortran/taylor.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/codes/fortran/taylor.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.9791666667, "max_line_length": 72, "alphanum_fraction": 0.5339981868, "num_tokens": 324, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915913, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7998287176487132}} {"text": "program main\nimplicit none\n\ninteger :: i\nreal(kind=8) :: radius\nreal(kind=8), dimension(3) :: point_A, point_B, midpoint, dist\n\nopen (unit=3, file='input', status='old', action='read')\n\n\nread(3,*) point_A(1), point_A(2), point_A(3)\nread(3,*) point_B(1), point_B(2), point_B(3)\n\n! coordinates of midpoint:\ndo i = 1, 3\n midpoint(i) = (point_A(i) + point_B(i))/2.0\nend do\n\nwrite(*,*) 'midpoint:', midpoint\n\n! distance from midpoint per coordinate\ndo i = 1, 3\n dist(i) = dabs(midpoint(i) - point_A(i))\nend do\n\n! largest distance from midpoint (x, y, or z)\nradius = MAXVAL(dist)\n\nwrite(*,*) 'box size:', radius\n\nend program main\n", "meta": {"hexsha": "f4ebe2954ab4d3dbf801af9f078e596d2af22d78", "size": 626, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "4_set_up_cluster/using_programs_and_cluster/NCI_plot/midpoint/midpoint.f95", "max_stars_repo_name": "ElenaKusevska/Scripts_for_comp_chem_jobs", "max_stars_repo_head_hexsha": "21972c32805d3346b0547db7175dfaa7475fce31", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4_set_up_cluster/using_programs_and_cluster/NCI_plot/midpoint/midpoint.f95", "max_issues_repo_name": "ElenaKusevska/Scripts_for_comp_chem_jobs", "max_issues_repo_head_hexsha": "21972c32805d3346b0547db7175dfaa7475fce31", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4_set_up_cluster/using_programs_and_cluster/NCI_plot/midpoint/midpoint.f95", "max_forks_repo_name": "ElenaKusevska/Scripts_for_comp_chem_jobs", "max_forks_repo_head_hexsha": "21972c32805d3346b0547db7175dfaa7475fce31", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.5625, "max_line_length": 62, "alphanum_fraction": 0.661341853, "num_tokens": 210, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533013520764, "lm_q2_score": 0.8577681068080748, "lm_q1q2_score": 0.7998287029877098}} {"text": "program trapezoidal_with_different_n\n ! Author : Anantha Rao (Reg no: 20181044)\n ! Program to compute the Integral f(x)=exp(x) with different number of bin sizes in powers of 10\n implicit none\n integer:: n,i\n ! n : number of bins\n ! i : counter\n\n real*8::a,b,h,func, fa,fb,trap_summ, error, actual_value\n ! a : Lower limit of the integral\n ! b : Upper limit of the integral\n ! h : Bin size\n ! trap_summ : Value of the integral using trapezoidal technique\n ! error : Value of the error between computed and analytical value\n ! actual_value : Analytical value of the integral\n\n\n open(unit=7, file='20181044_trap_e3.dat')\n n = 1\n a = 0\n b = 3\n actual_value = exp(3.0d0)-1\n ! write(*,*) \"Give the value of n\"\n ! read(*,*) n\n ! write(*,*) \"Give the lower limit of the integral\"\n ! read(*,*) a\n ! write(*,*) \"Give the upper limit of the integral\"\n ! read(*,*) b\n\n print *,\"Welcome to this program.&\n & This program does integration on I=0^3 exp(x)dx using trapezoidal rule on different number of bins (n)\"\n\n do\n h=(b-a)/real(n)\n write(*,10) n\n 10 format(\"Computing for n=\",i10)\n\n fa = func(a)/2.0d0\n fb = func(b)/2.0d0\n trap_summ=0.0d0\n\n do i=1, n-1\n trap_summ = trap_summ+func(a+h*i)\n end do\n \n trap_summ=(trap_summ+fa+fb)*h\n error=ABS(actual_value - trap_summ)\n write(7,*) n,\"\",\"\",trap_summ,\"\",error\n if (n .ge. 1000000000) exit\n n=n*10\n end do\n print*, \"Done!, Output stored in 20181044_trap_e^3.dat\"\n\nEND PROGRAM\n\nreal*8 function func(x)\n !evaluates f(x)=e^x\n implicit none\n real*8::x\n func=exp(x)\nend function\n\n", "meta": {"hexsha": "17487655b7333d9abb33fc744946791050475d76", "size": 1772, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/assgn02_solns/Assgn02_p2_trap.f90", "max_stars_repo_name": "Anantha-Rao12/ComPhys", "max_stars_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Solutions/assgn02_solns/Assgn02_p2_trap.f90", "max_issues_repo_name": "Anantha-Rao12/ComPhys", "max_issues_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Solutions/assgn02_solns/Assgn02_p2_trap.f90", "max_forks_repo_name": "Anantha-Rao12/ComPhys", "max_forks_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.126984127, "max_line_length": 115, "alphanum_fraction": 0.579006772, "num_tokens": 546, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037363973295, "lm_q2_score": 0.8633916117313211, "lm_q1q2_score": 0.7997628759208352}} {"text": "! pythagore_triplets.f90 \n!\n! FUNCTIONS:\n! pythagore_triplets - Entry point of console application.\n!\n\n!****************************************************************************\n!\n! PROGRAM: pythagore_triplets\n!\n! PURPOSE: Entry point for the console application.\n!\n!****************************************************************************\n\n program pythagore_triplets\n\n implicit none\n\n ! Variables\n integer :: narg\n character(256) :: arg\n integer :: perimeter\n integer :: a, b, c\n real :: abound, bbound\n logical :: foundit\n\n ! Body of pythagore_triplets\n narg = command_argument_count()\n if (narg < 1) then \n write(*,*) 'ERROR: Need constraint as input!'\n write(*,*) 'Please try again...'\n call exit_proc()\n end if\n \n call get_command_argument(1, arg)\n read(arg,*) perimeter\n \n abound = (perimeter - 3.) / 3.\n foundit = .false.\n \n write(*,*) 'Generating a Pythagorean triplet (a, b, c)...'\n write(*,'(A,I0,A)') 'Using perimeter = ', perimeter, ' as constraint...'\n write(*,'(A,F10.3)') 'a should be less than or equal to ', abound\n \n a = 1\n outerLoop: do while (a <= floor(abound))\n bbound = (perimeter - a) / 2.\n do b = a + 1, floor(bbound)\n c = perimeter - a - b\n if (a * a + b * b == c * c) then\n foundit = .true.\n exit outerLoop\n end if\n end do\n a = a + 1\n end do outerLoop\n \n if (foundit) then\n write(*,'(A,I0,A,I0,A,I0,A)') 'The triplet is (a, b, c) = (', a, ', ', b, ', ', c, ')'\n else\n write(*,*) 'Could not find triplet with this constraint!'\n end if\n \n call exit_proc()\n \n contains\n \n subroutine exit_proc()\n write(*,*) 'Press Enter to terminate'\n read(*,*)\n stop\n end subroutine\n end program pythagore_triplets\n\n", "meta": {"hexsha": "34d98dfb9fd1f17b637bbf4af8e40e45562e2104", "size": 1962, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pythagore_triplets/pythagore_triplets/pythagore_triplets.f90", "max_stars_repo_name": "aliakatas/PythagoreanTriplets", "max_stars_repo_head_hexsha": "19b7a68d60b297defe6a03bb1560e69e78b28b9b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pythagore_triplets/pythagore_triplets/pythagore_triplets.f90", "max_issues_repo_name": "aliakatas/PythagoreanTriplets", "max_issues_repo_head_hexsha": "19b7a68d60b297defe6a03bb1560e69e78b28b9b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pythagore_triplets/pythagore_triplets/pythagore_triplets.f90", "max_forks_repo_name": "aliakatas/PythagoreanTriplets", "max_forks_repo_head_hexsha": "19b7a68d60b297defe6a03bb1560e69e78b28b9b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.16, "max_line_length": 94, "alphanum_fraction": 0.4826707441, "num_tokens": 515, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.8840392909114836, "lm_q1q2_score": 0.7997466175732855}} {"text": "C$Procedure TRACE ( Trace of a 3x3 matrix )\n \n DOUBLE PRECISION FUNCTION TRACE ( MATRIX )\n \nC$ Abstract\nC\nC Return the trace of a 3x3 matrix.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC MATRIX\nC\nC$ Declarations\n \n DOUBLE PRECISION MATRIX ( 3,3 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC MATRIX I 3x3 matrix of double precision numbers.\nC TRACE O The trace of MATRIX.\nC\nC$ Detailed_Input\nC\nC MATRIX is a double precision 3x3 matrix.\nC\nC$ Detailed_Output\nC\nC TRACE is the trace of MATRIX, i.e. it is the sum of the\nC diagonal elements of MATRIX.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Particulars\nC\nC TRACE simply executes in FORTRAN code the following loop:\nC\nC TRACE = Summation from I = 1 to 3 of MATRIX(I,I)\nC\nC No error detection or correction is implemented within this\nC function.\nC\nC$ Examples\nC\nC | 3 5 7 |\nC Suppose that MATRIX = | 0 -2 8 | , then\nC | 4 0 -1 |\nC\nC TRACE (MATRIX) = 0. (which is the sum of 3, -2 and -1).\nC\nC$ Restrictions\nC\nC No checking is performed to guard against floating point overflow\nC or underflow. This routine should probably not be used if the\nC input matrix is expected to have large double precision numbers\nC along the diagonal.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC\nC$ Literature_References\nC\nC None\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WLT)\nC\nC-&\n \nC$ Index_Entries\nC\nC trace of a 3x3_matrix\nC\nC-&\n \n \n TRACE = MATRIX(1,1) + MATRIX(2,2) + MATRIX(3,3)\nC\n RETURN\n END\n", "meta": {"hexsha": "4260b3b2b74ea5673bc050ea9a7fcd59b6ce8af0", "size": 3348, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/trace.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/trace.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/trace.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 26.15625, "max_line_length": 72, "alphanum_fraction": 0.6586021505, "num_tokens": 980, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7997031715813143}} {"text": "*dk next_power_of_2\n integer function next_power_of_2(ii)\nC\nC#######################################################################\nC $Log: next_power_of_2.f,v $\nC Revision 2.00 2007/11/05 19:46:02 spchu\nC Import to CVS\nC\nCPVCS\nCPVCS Rev 1.21 02 Oct 2007 12:40:28 spchu\nCPVCS original version\nC\nC#######################################################################\nC\nC Calculate the power of 2 >= ii\nC i.e. 2**ceiling(log2(ii))\nC\n \n real base_2_log_ii\n if (ii .le. 1) then\n next_power_of_2 = 1\n else\nC So ii > 1\n base_2_log_ii = log(float(ii)) / log(2.0)\n ii_log_2 = int(base_2_log_ii)\nC *** truncate base_2_log_ii\n if (2**ii_log_2 .ge. ii) then\n next_power_of_2 = 2**ii_log_2\n else\n next_power_of_2 = 2**(ii_log_2+1)\n endif\n endif\nC\n goto 9999\n 9999 continue\n return\n end\n", "meta": {"hexsha": "0980b6abb993b64f4358a1e5ba40f223e37e36bd", "size": 934, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/next_power_of_2.f", "max_stars_repo_name": "millerta/LaGriT-1", "max_stars_repo_head_hexsha": "511ef22f3b7e839c7e0484604cd7f6a2278ae6b9", "max_stars_repo_licenses": ["CNRI-Python"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2017-02-09T17:54:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T22:22:32.000Z", "max_issues_repo_path": "src/next_power_of_2.f", "max_issues_repo_name": "millerta/LaGriT-1", "max_issues_repo_head_hexsha": "511ef22f3b7e839c7e0484604cd7f6a2278ae6b9", "max_issues_repo_licenses": ["CNRI-Python"], "max_issues_count": 166, "max_issues_repo_issues_event_min_datetime": "2017-01-26T17:15:45.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T21:36:28.000Z", "max_forks_repo_path": "src/lg_core/next_power_of_2.f", "max_forks_repo_name": "daniellivingston/LaGriT", "max_forks_repo_head_hexsha": "decd0ce0e5dab068034ef382cabcd134562de832", "max_forks_repo_licenses": ["Intel"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2017-02-08T21:56:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T06:48:36.000Z", "avg_line_length": 24.5789473684, "max_line_length": 72, "alphanum_fraction": 0.4882226981, "num_tokens": 303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395168021653, "lm_q2_score": 0.8558511414521922, "lm_q1q2_score": 0.7997031711187447}} {"text": "C Copyright 2021 Dennis Decker Jensen\nC Date: 26 April 2021\nC Modified: 2 May 2021\nC Purpose: Find prime factors in integers\nC Tectonics: gfortran --std=f95 -ffixed-form -c primefactors.f\n\n SUBROUTINE PRIMEFACTORS_TRIALDIV(NUM,IFACS,MXFACS,NFACS)\nC https://en.wikipedia.org/wiki/Trial_division\n DIMENSION IFACS(2, MXFACS)\n\n N=NUM\n DO 90 I=1,MXFACS\n IFACS(1,I)=0\n IFACS(2,I)=0\n 90 CONTINUE\n\n I=1\n IFACS(1,I)=2\n 100 IF (MOD(N,2).EQ.0) THEN\n IFACS(2,I)=IFACS(2,I)+1\n N=N/2\n GOTO 100\n ENDIF\n\n K=3\n 300 IF (K*K.GT.N) GOTO 500\n IF (IFACS(2,I).NE.0) THEN\n I=I+1\n IF (I.EQ.MXFACS) THEN\n PRINT*, 'OVERFLOW: '//\n 1 'INCREASE MXFACS '//\n 2 'TO ACCOMODATE NO PRIME FACTORS'\n NFACS=0\n RETURN\n ENDIF\n ENDIF\n IFACS(1,I)=K\n 400 IF (MOD(N,K).EQ.0) THEN\n IFACS(2,I)=IFACS(2,I)+1\n N=N/K\n GOTO 400\n ELSE\n K=K+2 \n ENDIF\n GOTO 300\n 500 IF (N.NE.1) THEN\nC IF (NUM.EQ.9974) PRINT *,'K',K,'N',N,'F',IFACS\n IF (N.EQ.IFACS(1,I)) THEN\n IFACS(2,I)=IFACS(2,I)+1\n ELSE\n IF (IFACS(2,I).NE.0) THEN\n I=I+1\n IF (I.EQ.MXFACS) THEN\n PRINT *,'OVERFLOW, MISSING LAST FACTOR', N\n ENDIF\n ENDIF\n IFACS(1,I)=N\n IFACS(2,I)=1\n ENDIF\n ENDIF\n NFACS=I\n END\n\n SUBROUTINE PRIMEFACTORS_WHEEL(NUM, IFACS, MXFACS, NFACS)\nC https://en.wikipedia.org/wiki/Wheel_factorization\n DIMENSION IFACS(2,MXFACS)\n DIMENSION INC(8)\nC Wheel: 7, 11, 13, 17, 19, 23, 29, 31\n DATA INC/ 4, 2, 4, 2, 4, 6, 2, 6/\n\n I=1\n J=1\n K=7\n N=NUM\n\n DO 90 L=1,MXFACS\n IFACS(1,L)=0\n IFACS(2,L)=0\n 90 CONTINUE\n\n DO WHILE (MOD(N,2).EQ.0)\n IFACS(2,I)=IFACS(2,I)+1 \n N=N/2\n ENDDO\n IF (IFACS(2,I).GT.0) THEN\n IFACS(1,I)=2\n I=I+1\n ENDIF\n\n DO WHILE (MOD(N,3).EQ.0)\n IFACS(2,I)=IFACS(2,I)+1\n N=N/3\n ENDDO\n IF (IFACS(2,I).GT.0) THEN\n IFACS(1,I)=3\n I=I+1\n ENDIF\n\n DO WHILE (MOD(N,5).EQ.0)\n IFACS(2,I)=IFACS(2,I)+1\n N=N/5\n ENDDO\n IF (IFACS(2,I).GT.0) THEN\n IFACS(1,I)=5\n I=I+1\n ENDIF\n\n DO WHILE (K*K.LE.N)\nC IF (NUM.EQ.646)\nC 1 PRINT *,'K',K,'N',N,'I',I,'F',IFACS\n IF (MOD(N,K).EQ.0) THEN\n IFACS(2,I)=IFACS(2,I)+1\n N=N/K\n ELSE\n IF (IFACS(2,I).GT.0) THEN\n IFACS(1,I)=K\n I=I+1\n ENDIF\n K=K+INC(J)\n IF (J.LT.8) THEN\n J=J+1\n ELSE\n J=1\n ENDIF\n ENDIF\n ENDDO\n IF (IFACS(2,I).GT.0) THEN\n IFACS(1,I)=K\n I=I+1\n ENDIF\nC PRINT *,'K',K,'N',N,'I',I,'F',IFACS\n IF (N.NE.1) THEN\n IF (N.EQ.IFACS(1,I-1)) THEN\n IFACS(2,I-1)=IFACS(2,I-1)+1\n ELSE\n IFACS(1,I)=N\n IFACS(2,I)=1\n I=I+1\n ENDIF\n ENDIF \nC PRINT *,'K',K,'N',N,'I',I,'F',IFACS \n NFACS=I-1\n END\n", "meta": {"hexsha": "7e77ed6bd5142ca9a2cce93281f3d4c2b8f3efee", "size": 3720, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "euler/primefactors.f", "max_stars_repo_name": "dennisdjensen/Sketchbook", "max_stars_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-04-26T19:30:58.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-12T16:34:23.000Z", "max_issues_repo_path": "euler/primefactors.f", "max_issues_repo_name": "dennisdjensen/sketchbook", "max_issues_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_issues_repo_licenses": ["0BSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "euler/primefactors.f", "max_forks_repo_name": "dennisdjensen/sketchbook", "max_forks_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.8333333333, "max_line_length": 64, "alphanum_fraction": 0.3930107527, "num_tokens": 1286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895028, "lm_q2_score": 0.8652240773641087, "lm_q1q2_score": 0.7995897517370352}} {"text": "module geom\n\npublic :: lola2distaz\npublic :: distaz2lola\n\npublic :: str2vec\npublic :: strdip2normal\npublic :: strdip2updip\npublic :: normal2strike\npublic :: normal2updip\n\npublic :: perspective\n\n! public :: nvec2sdvec\npublic :: pnpoly\n\n!--------------------------------------------------------------------------------------------------!\ncontains\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine lola2distaz(lon1,lat1,lon2,lat2,dist,az,dist_unit,az_unit,ierr)\n!----\n! Given the latitude and longitude of two points, compute the great circle distance between them\n! and the azimuth from point 1 to point 2 measured clockwise from north.\n!\n! Inputs\n! lon1: starting longitude, in degrees\n! lat1: starting latitude, in degrees\n! lon2: ending longitude, in degrees\n! lat2: ending latitude, in degrees\n!\n! Outputs\n! dist: distance between points along sphere, in radians\n! az: azimuth pointing from point 1 to point 2, clockwise from north, in degrees\n! dist_unit: radians\n! az_unit: degrees, radians\n! ierr: error status\n!----\n\nuse io, only: stderr\nuse trig, only: pi, d2r, r2d\nimplicit none\n\n! Arguments\ndouble precision :: dist, az, lon1, lat1, lon2, lat2\ncharacter(len=*) :: dist_unit, az_unit\ninteger :: ierr\n\n! Local variables\ndouble precision :: lon1r, lat1r, lon2r, lat2r, colat1, colat2, dlon, dlat, a\n\n\nierr = 0\ndist = 0.0d0\naz = 0.0d0\n\nif (abs(lat1).gt.90.0d0) then\n write(stderr,*) 'distaz2lola: input latitude 1 is greater than 90'\n ierr = 1\n return\nendif\n\nif (abs(lat2).gt.90.0d0) then\n write(stderr,*) 'distaz2lola: input latitude 2 is greater than 90'\n ierr = 1\n return\nendif\n\n! Check if points are polar opposite\nif (dabs(lat1+lat2).le.1.0d-6.and.dabs(mod((lon1-lon2)+1.8d2,3.6d2)).le.1.0d-6) then\n dist = pi\n az = 0.0d0\n return\nendif\n\n! Convert lon/lat to radians\nlon1r = lon1*d2r\nlat1r = lat1*d2r\nlon2r = lon2*d2r\nlat2r = lat2*d2r\n\n! Haversine formula for distance (more accurate over short distances than Spherical Law of Cosines)\ncolat1 = pi/2.0d0-lat1r\ncolat2 = pi/2.0d0-lat2r\ndlon = lon2r-lon1r\ndlat = lat2r-lat1r\na = dsin(dlat/2.0d0)*dsin(dlat/2.0d0) + dcos(lat1r)*dcos(lat2r)*dsin(dlon/2.0d0)*dsin(dlon/2.0d0)\nif (a.ge.1.0d0) then\n dist = 0.0d0\nelse\n dist = 2.0d0*datan2(dsqrt(a),dsqrt(1.0d0-a))\nendif\n\nif (dist_unit.eq.'radians') then\n dist = dist\nelse\n write(stderr,*) 'lola2distaz: no dist_unit named ',trim(dist_unit)\n ierr = 2\n return\nendif\n\n! Calculate azimuth\nif (dist.lt.1.0d-6) then\n az = 0.0d0\nelse\n ! Spherical Law of Sines\n az = datan2(dsin(dlon)*dcos(lat2r), dcos(lat1r)*dsin(lat2r)-dsin(lat1r)*dcos(lat2r)*dcos(dlon))\nendif\n\nif (az_unit.eq.'degrees') then\n az = az*r2d\nelseif (az_unit.eq.'radians') then\n az = az\nelse\n write(stderr,*) 'lola2distaz: no az_unit named ',trim(az_unit)\n ierr = 2\n return\nendif\n\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine distaz2lola(lon1,lat1,dist,az,lon2,lat2,dist_unit,az_unit,ierr)\n!----\n! Given a longitude and latitude and distance and azimuth clockwise from north away from this\n! initial point, compute the ending longitude and latitude.\n!\n! Inputs\n! lon1: starting longitude, in degrees\n! lat1: starting latitude, in degrees\n! dist: distance between points along sphere, in dist_unit\n! az: azimuth pointing from point 1 to point 2, clockwise from north, in az_unit\n! dist_unit: radians\n! az_unit: degrees, radians\n!\n! Outputs\n! lon2: ending latitude, in degrees\n! lat2: ending latitude, in degrees\n! ierr: error status\n!----\n\nuse io, only: stderr\nuse trig, only: d2r, r2d\n\nimplicit none\n\n! Arguments\ndouble precision :: lon1, lat1, lon2, lat2, dist, az\ncharacter(len=*) :: dist_unit, az_unit\ninteger :: ierr\n\n! Local variables\ndouble precision :: distr, azr, lon1r, lat1r\n\n\nierr = 0\nlon2 = 0.0d0\nlat2 = 0.0d0\n\nif (abs(lat1).gt.90.0d0) then\n write(stderr,*) 'distaz2lola: input latitude is greater than 90'\n ierr = 1\n return\nendif\n\n! Convert all input quantities to radians\n! Distance\nif (dist_unit.eq.'radians') then\n distr = dist\nelse\n write(stderr,*) 'distaz2lola: no dist_unit named ',trim(dist_unit)\n ierr = 2\n return\nendif\n\n! Azimuth\nif (az_unit.eq.'degrees') then\n azr = az*d2r ! deg -> rad\nelseif (az_unit.eq.'radians') then\n azr = az\nelse\n write(stderr,*) 'distaz2lola: no az_unit named ',trim(az_unit)\n ierr = 2\n return\nendif\n\nlon1r = lon1*d2r ! deg -> rad\nlat1r = lat1*d2r ! deg -> rad\n\n! Spherical law of cosines\nlat2 = dasin(dsin(lat1r)*dcos(distr)+dcos(lat1r)*dsin(distr)*dcos(azr))\n\n! Spherical law of cosines and law of sines\nlon2 = lon1r + datan2(dsin(azr)*dsin(distr)*dcos(lat1r), dcos(distr)-dsin(lat1r)*dsin(lat2))\n\nlon2 = lon2*r2d\nlat2 = lat2*r2d\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine str2vec(str,strike_vec)\n!----\n! Given the strike (degrees CW from north) of a plane, calculate the vector parallel to strike\n! (east, north, and vertical components).\n!----\n\nuse trig, only: d2r\n\nimplicit none\n\n! Arguments\ndouble precision :: str, strike_vec(3)\n\nstrike_vec(1) = sin(str*d2r)\nstrike_vec(2) = cos(str*d2r)\nstrike_vec(3) = 0.0d0\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine strdip2normal(str,dip,normal_vec)\n!----\n! Given the strike (degrees CW from north) and dip (degrees from horizontal) of a plane, calculate\n! the normal vector (east, north, and vertical components).\n!----\n\nuse trig, only: d2r\n\nimplicit none\n\n! Arguments\ndouble precision :: str, dip, normal_vec(3)\n\nnormal_vec(1) = sin(dip*d2r)*sin((str+90.0d0)*d2r)\nnormal_vec(2) = sin(dip*d2r)*cos((str+90.0d0)*d2r)\nnormal_vec(3) = cos(dip*d2r)\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine strdip2updip(str,dip,updip_vec)\n!----\n! Given the strike (degrees CW from north) and dip (degrees from horizontal) of a plane, calculate\n! the vector pointing up-dip (east, north, and vertical components).\n!----\n\nuse trig, only: d2r\n\nimplicit none\n\n! Arguments\ndouble precision :: str, dip, updip_vec(3)\n\nupdip_vec(1) = -cos(dip*d2r)*sin((str+90.0d0)*d2r)\nupdip_vec(2) = -cos(dip*d2r)*cos((str+90.0d0)*d2r)\nupdip_vec(3) = sin(dip*d2r)\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine normal2strike(normal_vec,strike_vec)\nuse algebra, only: normalize\nimplicit none\n! Arguments\ndouble precision :: normal_vec(3), strike_vec(3)\n\nif (abs(normal_vec(1)).lt.1.0d-6.and.abs(normal_vec(2)).lt.1.0d-6) then\n strike_vec(1) = 1.0d0\n strike_vec(2) = 0.0d0\n strike_vec(3) = 0.0d0\nelse\n strike_vec(1) = -normal_vec(2)\n strike_vec(2) = normal_vec(1)\n strike_vec(3) = 0.0d0\nendif\n\ncall normalize(strike_vec)\n\nreturn\nend\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine normal2updip(normal_vec,updip_vec)\nuse trig, only: pi\nimplicit none\n! Arguments\ndouble precision :: normal_vec(3), updip_vec(3)\n\nif (abs(normal_vec(1)).lt.1.0d-6.and.abs(normal_vec(2)).lt.1.0d-6) then\n updip_vec(1) = 0.0d0\n updip_vec(2) = 1.0d0\n updip_vec(3) = 0.0d0\nelse\n updip_vec(1) = normal_vec(3)*cos(atan2(normal_vec(2),normal_vec(1))+pi)\n updip_vec(2) = normal_vec(3)*sin(atan2(normal_vec(2),normal_vec(1))+pi)\n updip_vec(3) = sqrt(normal_vec(1)*normal_vec(1)+normal_vec(2)*normal_vec(2))\nendif\n\nreturn\nend\n\n!--------------------------------------------------------------------------------------------------!\n\n!\n! subroutine nvec2sdvec(normal_vector,strike_vector,dip_vector)\n! !----\n! ! Calculate the vectors parallel to strike and dip of a plane, given its normal vector.\n! !----\n!\n! use io, only: stderr\n!\n! implicit none\n!\n! ! Arguments\n! double precision :: normal_vector(3), strike_vector(3), dip_vector(3)\n!\n! ! Local variables\n! double precision :: magnitude, strike_angle\n!\n! ! Initialize strike, dip vectors\n! strike_vector = 0.0d0\n! dip_vector = 0.0d0\n!\n! ! Normalize normal vector\n! magnitude = normal_vector(1)*normal_vector(1) + &\n! normal_vector(2)*normal_vector(2) + &\n! normal_vector(3)*normal_vector(3)\n!\n! if (magnitude.lt.1.0d-10) then\n! write(stderr,*) 'normalvec2strdipvec: normal vector magnitude is zero'\n! return\n! endif\n!\n! normal_vector = normal_vector/magnitude\n!\n! ! Strike is horizontal, parallel to plane\n! strike_angle = atan2(normal_vector(1),normal_vector(2))\n! strike_vector(1) = sin(strike_angle)\n! strike_vector(2) = cos(strike_angle)\n! strike_vector(3) = 0.0d0\n!\n! ! Up-dip is perpendicular to strike, normal\n! dip_vector(1) = normal_vector(2)*strike_vector(3) - normal_vector(3)*strike_vector(2)\n! dip_vector(2) = normal_vector(3)*strike_vector(1) - normal_vector(1)*strike_vector(3)\n! dip_vector(3) = normal_vector(1)*strike_vector(2) - normal_vector(2)*strike_vector(1)\n!\n! return\n! end subroutine\n\n!--------------------------------------------------------------------------------------------------!\n!--------------------------------------------------------------------------------------------------!\n!--------------------------------------------------------------------------------------------------!\n!--------------------------------------------------------------------------------------------------!\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine perspective(point_x,point_y,point_z,view_x,view_y,view_z,look_x,look_y,look_z,x,y)\n!----\n! Project a point in 3-D onto a 2-D plane, given viewing coordinates and the look vector of the\n! viewer. The center of the plane corresponds to the vanishing point of the look direction.\n!----\n\nuse algebra, only: dot_product, cross_product, normalize\n\nimplicit none\n\n! Arguments\ndouble precision :: point_x, point_y, point_z, view_x, view_y, view_z, look_x, look_y, look_z\ndouble precision :: x, y\n\n! Local variables\ndouble precision :: vec(3), look_vec(3), dot, proj, ang_from_vanish, updip(3), strike(3), azimuth\n\n\n! Calculate the angle between the look vector and the vector from the viewing location to the\n! point of interest\n\n! Vector viewer->point (point of interest vector)\nvec(1) = point_x - view_x\nvec(2) = point_y - view_y\nvec(3) = point_z - view_z\n\n! Look vector\nlook_vec(1) = look_x\nlook_vec(2) = look_y\nlook_vec(3) = look_z\n\n! Dot product of point of interest vector and look vector\ncall dot_product(vec,look_vec,dot)\nif (dot.lt.0.0d0) then\n ! point is behind the viewer\n x = 1e10\n y = 1e10\n return\nendif\n\n! Projection of point of interest vector on look vector direction\nproj = dot/sqrt(look_x**2+look_y**2+look_z**2)\n\n! Angle from vanishing point to point of interest\nang_from_vanish = proj/sqrt(vec(1)**2+vec(2)**2+vec(3)**2)\nang_from_vanish = acos(ang_from_vanish)\n\n! Vector parallel to plane\nvec = vec - proj*look_vec/sqrt(look_x**2+look_y**2+look_z**2)\n\n! Up-dip and along-strike vectors\nif (look_vec(3).ge.0.0d0) then\n call normal2updip(look_vec,updip)\n call normal2strike(look_vec,strike)\n strike = -strike\nelse\n call normal2updip(-look_vec,updip)\n call normal2strike(-look_vec,strike)\nendif\ncall normalize(updip)\ncall normalize(strike)\n\n! Project parallel vector onto strike and updip vectors\ncall dot_product(vec,strike,x)\ncall dot_product(vec,updip,y)\nazimuth = atan2(y,x)\n\n! Apparent position of projected point for viewer\nx = tan(ang_from_vanish)*cos(azimuth)\ny = tan(ang_from_vanish)*sin(azimuth)\n\n\nreturn\nend subroutine\n\n\n\n!--------------------------------------------------------------------------------------------------!\n!--------------------------------------------------------------------------------------------------!\n!--------------------------------------------------------------------------------------------------!\n!--------------------------------------------------------------------------------------------------!\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine pnpoly(PX,PY,XX,YY,N,INOUT,eps)\n\n!----\n! SUBROUTINE pnpoly\n! WRITTEN BY RANDOLPH FRANKLIN, UNIVERSITY OF OTTAWA, 7/70.\n!\n! PURPOSE: TO DETERMINE WHETHER A POINT IS INSIDE A POLYGON\n!\n! USAGE: CALL PNPOLY (PX, PY, XX, YY, N, INOUT )\n!\n! PARAMETERS:\n! PX - X-COORDINATE OF POINT IN QUESTION.\n! PY - Y-COORDINATE OF POINT IN QUESTION.\n! XX - N LONG VECTOR CONTAINING X-COORDINATES OF\n! VERTICES OF POLYGON.\n! YY - N LONG VECTOR CONTAINING Y-COORDINATES OF\n! VERTICES OF POLYGON.\n! N - NUMBER OF VERTICES IN THE POLYGON.\n! INOUT - THE SIGNAL RETURNED:\n! -1 IF THE POINT IS OUTSIDE OF THE POLYGON,\n! 0 IF THE POINT IS ON AN EDGE OR AT A VERTEX,\n! 1 IF THE POINT IS INSIDE OF THE POLYGON.\n! eps - Threshold for distance from boundary\n!\n! REMARKS:\n! - THE VERTICES MAY BE LISTED CLOCKWISE OR ANTICLOCKWISE.\n! - THE FIRST MAY OPTIONALLY BE REPEATED, IF SO N MAY OPTIONALLY BE INCREASED BY 1.\n! - THE INPUT POLYGON MAY BE A COMPOUND POLYGON CONSISTING OF SEVERAL SEPARATE SUBPOLYGONS. IF SO,\n! THE FIRST VERTEX OF EACH SUBPOLYGON MUST BE REPEATED, AND WHEN CALCULATING N, THESE FIRST\n! VERTICES MUST BE COUNTED TWICE.\n! - INOUT IS THE ONLY PARAMETER WHOSE VALUE IS CHANGED.\n!\n! METHOD:\n! A VERTICAL LINE IS DRAWN THRU THE POINT IN QUESTION. IF IT CROSSES THE POLYGON AN ODD NUMBER OF\n! TIMES, THEN THE POINT IS INSIDE OF THE POLYGON.\n!\n! Modifications and translation to Modern Fortran by Matt Herman\n!----\n\n! use io, only: stderr\nimplicit none\n\n! Arguments\ndouble precision :: PX, PY, XX(N), YY(N), eps\ninteger :: N, INOUT\n\n! Local variables\ndouble precision :: X(N), Y(N), var\ninteger :: I, J\nlogical :: MX, MY, NX, NY\n\n\n! Compute the coordinates of the points on the clipping path (xx,yy) relative to the point of\n! interest (px,py)\ndo I = 1,N\n X(I) = XX(I)-PX\n Y(I) = YY(I)-PY\n\n ! Check whether point of interest is at a vertex of the polygon\n if (abs(X(I)).lt.eps.and.abs(Y(I)).lt.eps) then\n ! write(stderr,*) 'pnpoly: point of interest is at a vertex'\n INOUT = 0\n return\n endif\nenddo\n\n\n! Initialize point of interest as outside of polygon\nINOUT = -1\n\n\n! Loop over line segments in polygon to determine whether a vertical ray from above the\n! point of interest crosses the line segment\ndo I = 1,N\n J = 1 + mod(I,N)\n\n ! Is the first point in the segment path right/east of of the point of interest?\n if (X(I).ge.0.0d0) then\n MX = .true.\n else\n MX = .false.\n endif\n\n ! Is the second point in the segment right/east of of the point of interest?\n if (X(J).ge.0.0d0) then\n NX = .true.\n else\n NX = .false.\n endif\n\n ! Is the first point in the segment above/north of of the point of interest?\n if (Y(I).ge.0.0d0) then\n MY = .true.\n else\n MY = .false.\n endif\n\n ! Is the second point in the segment above/north of of the point of interest?\n if (Y(J).ge.0.0d0) then\n NY = .true.\n else\n NY = .false.\n endif\n ! write(stderr,*) 'MX:',MX\n ! write(stderr,*) 'NX:',NX\n ! write(stderr,*) 'MY:',MY\n ! write(stderr,*) 'NY:',NY\n\n ! Check whether the point of interest is on a horizontal line\n if (dabs(Y(I)).lt.eps.and.dabs(Y(J)).lt.eps) then\n if (MX.and..not.NX .or. .not.MX.and.NX) then\n ! write(stderr,*) 'point of interest lies on this horizontal line segment'\n INOUT = 0\n return\n endif\n endif\n\n ! Check whether the point of interest is on a vertical line\n if (dabs(X(I)).lt.eps.and.dabs(X(J)).lt.eps) then\n if (MY.and..not.NY .or. .not.MY.and.NY) then\n ! write(stderr,*) 'point of interest lies on this vertical line segment'\n INOUT = 0\n return\n endif\n endif\n\n ! If the line segment is below, left, or right of the point of interest, go to the next segment\n if (MX.and.NX) then\n ! write(stderr,*) 'line segment is right of the point of interest'\n cycle\n elseif (.not.(MX.or.NX)) then\n ! write(stderr,*) 'line segment is left of the point of interest'\n cycle\n elseif (.not.(MY.or.NY)) then\n ! write(stderr,*) 'line segment is below the point of interest'\n cycle\n endif\n\n ! Check whether the line segment is above the point\n if (MY.and.NY.and..not.MX.and.NX) then\n ! write(stderr,*) 'line segment is above the point of interest'\n INOUT = -INOUT\n cycle\n else\n ! write(stderr,*) 'checking whether line segment is above the point of interest'\n var = (Y(I)*X(J)-X(I)*Y(J))/(X(J)-X(I))\n endif\n\n if (var.lt.-eps) then\n ! write(stderr,*) 'line segment is below the point of interest'\n cycle\n elseif (dabs(var).lt.eps) then\n ! write(stderr,*) 'point of interest is on the line segment'\n INOUT = 0\n return\n else\n ! write(stderr,*) 'line segment is above the point of interest'\n INOUT = -INOUT\n endif\nenddo\n\nreturn\nend subroutine\n\n\nend module\n", "meta": {"hexsha": "a5fbd05e46282d3209cf6fd2eee4a6808923eac9", "size": 17369, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/geom_module.f90", "max_stars_repo_name": "mherman09/ElasticHalfspaceToolbox", "max_stars_repo_head_hexsha": "168b9391654f6d3940f8778789ec7642574a523a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-05-07T03:34:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-11T16:08:50.000Z", "max_issues_repo_path": "src/geom_module.f90", "max_issues_repo_name": "mherman09/ElasticHalfspaceToolbox", "max_issues_repo_head_hexsha": "168b9391654f6d3940f8778789ec7642574a523a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-10-09T19:27:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-04T13:17:03.000Z", "max_forks_repo_path": "src/geom_module.f90", "max_forks_repo_name": "mherman09/Hdef", "max_forks_repo_head_hexsha": "2b1606bb69810ddcfe59ea23601d14a30b840ea8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1051779935, "max_line_length": 100, "alphanum_fraction": 0.6045828775, "num_tokens": 5024, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850110816423, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7995057165814011}} {"text": "module sys_variables\n implicit none\n\n public pi, d2r, r2d\n double precision, parameter :: pi = 4.0d0*atan(1.0d0)\n double precision, parameter :: d2r = pi/180.0d0\n double precision, parameter :: r2d = 180.0d0/pi\n\nend module sys_variables\n", "meta": {"hexsha": "46d4aa6277bdce832bbf90a7766c258d8d8f3187", "size": 252, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "wagl/f90_sources/sys_variables.f90", "max_stars_repo_name": "Oceancolour-RG/wagl", "max_stars_repo_head_hexsha": "f002a1c0a373d21758d44d2a808bdfd755d90226", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2018-05-30T23:42:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-25T14:21:46.000Z", "max_issues_repo_path": "wagl/f90_sources/sys_variables.f90", "max_issues_repo_name": "Oceancolour-RG/wagl", "max_issues_repo_head_hexsha": "f002a1c0a373d21758d44d2a808bdfd755d90226", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 52, "max_issues_repo_issues_event_min_datetime": "2018-02-20T05:31:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-23T23:38:15.000Z", "max_forks_repo_path": "wagl/f90_sources/sys_variables.f90", "max_forks_repo_name": "Oceancolour-RG/wagl", "max_forks_repo_head_hexsha": "f002a1c0a373d21758d44d2a808bdfd755d90226", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2018-02-20T05:08:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-12T23:16:41.000Z", "avg_line_length": 25.2, "max_line_length": 57, "alphanum_fraction": 0.6944444444, "num_tokens": 84, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850075259039, "lm_q2_score": 0.8539127566694177, "lm_q1q2_score": 0.7995057118046911}} {"text": "! Name: ARPIT KUMAR JAIN, Roll No: 180122009\nPROGRAM ChebyshevAndLagrangeInterpolation\n IMPLICIT NONE\n REAL, PARAMETER :: pi = acos(-1.0)\n INTEGER:: n, k, i\n REAL:: point, FuncVal, LagVal, CheVal\n REAL, DIMENSION(:), ALLOCATABLE:: Lx, LF, Cx, CF\n\n n = 16\n ! we have to find 17 points so n = 16 and our index will be 0 to 17\n\n ! Lx is Lagrange equal distance point (17 points)\n ALLOCATE(Lx(0:n));\n\n ! LF is Lagrange Function value at Lagrange equal distance points\n ALLOCATE(LF(0:n));\n\n ! Cx is Chebychev Nodes (17)\n ALLOCATE(Cx(0:n));\n\n ! CF is Value of Function at Chebyshev Nodes\n ALLOCATE(CF(0:n));\n\n\n DO i = 0, n\n ! Finding 17 equal distance points\n Lx(i) = -1.0 + i * (2.0/16)\n\n ! Finding Function values at lagrange points\n LF(i) = 1./(1. + 25 * Lx(i) * Lx(i))\n ENDDO\n\n DO k = 0, n\n ! Calculating Chebyshev Nodes\n Cx(k) = cos(((2*k+1 )*pi)/(2*n+2))\n\n ! Calculating Function value at those nodes\n CF(k) = 1./(1. + 25 * Cx(k) * Cx(k))\n ENDDO\n\n ! Opening the file output.txt \n OPEN(UNIT = 20, FILE = 'output.txt', FORM = \"formatted\")\n\n ! Calculating at 102 different values between -1 to 1\n DO i = 0, 101\n point = -1.0 + i * (2.0/101)\n\n ! FuncVal is a original function value at point \n FuncVal = 1./(1. + 25 * point * point)\n\n ! LagVal is a Lagrange Interpolation Value at Lagrange Point\n CALL LagrangeInterpolation(point, n, LF, Lx, LagVal)\n\n ! CheVal is a Lagrange Interpolation Value at Chebyshev Points\n CALL LagrangeInterpolation(point, n, CF, Cx, CheVal)\n\n WRITE(20, *) point, FuncVal, LagVal, CheVal\n\n ENDDO\n\n CLOSE(20)\n\n CONTAINS \n SUBROUTINE LagrangeInterpolation(point, n, F, X, ans)\n IMPLICIT NONE\n ! PnX is a Lagrange Polynomial\n REAL:: point, PnX, ans\n INTEGER:: n, i, j\n REAL, DIMENSION(0:n):: X, F, Lagrange\n\n PnX = 0.0\n DO i = 0, n\n Lagrange(i) = 1.0\n DO j = 0, n\n if(i .NE. j) Lagrange(i) = Lagrange(i) * ((point - x(j)) / (x(i) - x(j)));\n ENDDO\n PnX = PnX + F(i) * Lagrange(i)\n ENDDO\n\n ! storeing PnX value in the ans\n ans = PnX\n END SUBROUTINE LagrangeInterpolation\n\nEND PROGRAM ChebyshevAndLagrangeInterpolation", "meta": {"hexsha": "aee28f7e11f1b1efb70b540601806f25846a73ec", "size": 2405, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Chebyshev/Arpit.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Chebyshev/Arpit.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chebyshev/Arpit.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 28.630952381, "max_line_length": 90, "alphanum_fraction": 0.5634095634, "num_tokens": 786, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850021922959, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.7995056985481568}} {"text": "!**********************************************************************\n! pi - compute pi by integrating f(x) = 4/(1 + x**2) \n!\n! (C) 2001 by Argonne National Laboratory. MPICH example\n! Modified by Thomas Hauser\n! \n! Program: \n! 1) reads the number of rectangles used in the approximation.\n! 2) calculates the areas of it's rectangles.\n! \n!\n! Variables:\n!\n! pi the calculated result\n! n number of points of integration. \n! x midpoint of each rectangle's interval\n! f function to integrate\n! sum,pi area of rectangles\n! tmp temporary scratch space for global summation\n! i do loop index\n!****************************************************************************\nPROGRAM approx_pi\n\n INTEGER, PARAMETER :: dp = KIND(1.0d0)\n REAL(dp):: PI25DT = 3.141592653589793238462643d0\n \n REAL(dp) :: pi, h, sum, x, f, a\n INTEGER :: n, i\n ! function to integrate\n f(a) = 4.0_dp / (1.0_dp + a*a)\n\n WRITE(6, 98)\n98 FORMAT('Enter the number of intervals:')\n READ(5,99) n\n99 FORMAT(i10)\n\n\n ! calculate the interval size\n h = 1.0_dp/ DBLE(n)\n\n sum = 0.0_DP\n !$OMP PARALLEL DO PRIVATE(x), SHARED(h ,n) &\n !$OMP& REDUCTION(+: sum)\n DO i = 1, n\n x = h * (DBLE(i) - 0.5_dp)\n sum = sum + f(x)\n ENDDO\n !$OMP END PARALLEL DO\n pi = h * sum\n\n\n WRITE(6, 97) n, pi, ABS(pi - PI25DT)\n97 FORMAT(' pi(', I15 ,' ) is approximately: ', F18.16, &\n ' Error is: ', F18.16)\n\nEND PROGRAM approx_pi\n\n\n\n\n", "meta": {"hexsha": "6dd4013cdcce83c85f9c65ccb4a90163d828a92d", "size": 1525, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "OpenMP/Lab/Pi/pi_best.f90", "max_stars_repo_name": "rctraining/USGS-Advanced-HPC-Workshop", "max_stars_repo_head_hexsha": "4b206f6478fef8655eeffee025a43bb4414e7d83", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "OpenMP/Lab/Pi/pi_best.f90", "max_issues_repo_name": "rctraining/USGS-Advanced-HPC-Workshop", "max_issues_repo_head_hexsha": "4b206f6478fef8655eeffee025a43bb4414e7d83", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "OpenMP/Lab/Pi/pi_best.f90", "max_forks_repo_name": "rctraining/USGS-Advanced-HPC-Workshop", "max_forks_repo_head_hexsha": "4b206f6478fef8655eeffee025a43bb4414e7d83", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0, "max_line_length": 77, "alphanum_fraction": 0.5213114754, "num_tokens": 459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921834855049, "lm_q2_score": 0.8670357494949105, "lm_q1q2_score": 0.7993391890592705}} {"text": "! Computes an approximation of Pi with a Monte Carlo algorithm\n! Coarrays version with steady results\n! Vincent Magnin, 2021-04-22\n! Last modification: 2021-05-03\n! MIT license\n! $ caf -Wall -Wextra -std=f2018 -pedantic -O3 pi_monte_carlo_coarrays_steady.f90 && time cafrun -n 4 ./a.out\n! or with ifort :\n! $ ifort -O3 -coarray pi_monte_carlo_coarrays_steady.f90 && time ./a.out\n\nprogram pi_monte_carlo_coarrays_steady\n use, intrinsic :: iso_fortran_env, only: wp=>real64, int64\n implicit none\n real(wp) :: x, y ! Coordinates of a point\n integer(int64) :: n ! Total number of points\n integer(int64) :: k ! Points into the quarter disk\n integer(int64) :: it, kt ! for intermediate sum\n integer(int64) :: i ! Loop counter\n integer(int64) :: n_per_image ! Number of parallel images\n\n n = 1000000000\n k = 0\n call random_init(repeatable=.true., image_distinct=.true.)\n\n print '(i2, a, i2, a)', this_image(), \"/\", num_images(), \" images\"\n n_per_image = n / num_images()\n print '(a, i11, a)', \"I will compute\", n_per_image, \" points\"\n\n do i = 1, n_per_image\n ! Computing a random point (x,y) into the square 0<=x<1, 0<=y<1:\n call random_number(x)\n call random_number(y)\n\n ! Is it in the quarter disk (R=1, center=origin) ?\n if ((x**2 + y**2) < 1.0_wp) k = k + 1\n\n ! Once in a while (20 times):\n if (mod(i, n_per_image/20) == 0) then\n kt = k\n call co_sum(kt, result_image = 1)\n if (this_image() == 1) then\n it = i*num_images()\n write(*, '(a, i0, a, i0, a, F17.15)') \"4 * \", kt, \" / \", it, \" = \", (4.0_wp * kt) / it\n end if\n end if\n end do\n\nend program pi_monte_carlo_coarrays_steady\n", "meta": {"hexsha": "3bf0a0b35a197983a47251a5bcf6b6c171211ca4", "size": 1796, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pi_monte_carlo_coarrays_steady.f90", "max_stars_repo_name": "everythingfunctional/exploring_coarrays", "max_stars_repo_head_hexsha": "e5b33a3135b9869705634f7634145155aceac937", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pi_monte_carlo_coarrays_steady.f90", "max_issues_repo_name": "everythingfunctional/exploring_coarrays", "max_issues_repo_head_hexsha": "e5b33a3135b9869705634f7634145155aceac937", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pi_monte_carlo_coarrays_steady.f90", "max_forks_repo_name": "everythingfunctional/exploring_coarrays", "max_forks_repo_head_hexsha": "e5b33a3135b9869705634f7634145155aceac937", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.4166666667, "max_line_length": 109, "alphanum_fraction": 0.5913140312, "num_tokens": 574, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.8670357477770336, "lm_q1q2_score": 0.7993391837555405}} {"text": "! Extend operators for a user-defined vector type. Create new operator .DOT. to\n! calculate dot product.\nMODULE vector_operators\nTYPE :: vector\n REAL :: x\n REAL :: y\n REAL :: z\nEND TYPE vector\n\nINTERFACE OPERATOR(+)\n MODULE PROCEDURE add_vectors\n MODULE PROCEDURE add_vector_and_scalar\nEND INTERFACE\n\nINTERFACE OPERATOR(-)\n MODULE PROCEDURE sub_vectors\nEND INTERFACE\n\nINTERFACE OPERATOR(*)\n MODULE PROCEDURE mult_by_scalar\nEND INTERFACE\n\nINTERFACE OPERATOR(/)\n MODULE PROCEDURE div_by_scalar\nEND INTERFACE\n\nINTERFACE OPERATOR(.DOT.)\n MODULE PROCEDURE dot_product\nEND INTERFACE\n\nINTERFACE ASSIGNMENT(=)\n MODULE PROCEDURE array_to_vector\n MODULE PROCEDURE vector_to_array\nEND INTERFACE\n\nCONTAINS\n TYPE(vector) FUNCTION add_vectors(v1, v2)\n IMPLICIT NONE\n TYPE(vector), INTENT(IN) :: v1, v2\n add_vectors = vector(v1%x + v2%x, v1%y + v2%y, v1%z + v2%z)\n END FUNCTION add_vectors\n\n TYPE(vector) FUNCTION sub_vectors(v1, v2)\n IMPLICIT NONE\n TYPE(vector), INTENT(IN) :: v1, v2\n sub_vectors = vector(v1%x - v2%x, v1%y - v2%y, v1%z - v2%z)\n END FUNCTION sub_vectors\n\n TYPE(vector) FUNCTION mult_by_scalar(v, s)\n IMPLICIT NONE\n TYPE(vector), INTENT(IN) :: v\n REAL, INTENT(IN) :: s\n mult_by_scalar = vector(v%x * s, v%y * s, v%z * s)\n END FUNCTION mult_by_scalar\n\n TYPE(vector) FUNCTION div_by_scalar(v, s)\n IMPLICIT NONE\n TYPE(vector), INTENT(IN) :: v\n REAL, INTENT(IN) :: s\n div_by_scalar = vector(v%x / s, v%y / s, v%z / s)\n END FUNCTION div_by_scalar\n\n REAL FUNCTION dot_product(v1, v2)\n IMPLICIT NONE\n TYPE(vector), INTENT(IN) :: v1, v2\n dot_product = v1%x * v2%x + v1%y * v2%y + v1%z * v2%z\n END FUNCTION dot_product\n\n SUBROUTINE vector_to_array(vec, arr)\n IMPLICIT NONE\n REAL, DIMENSION(3), INTENT(IN) :: arr\n TYPE(vector), INTENT(OUT) :: vec\n vec = vector(arr(1), arr(2), arr(3))\n END SUBROUTINE vector_to_array\n\n SUBROUTINE array_to_vector(arr, vec)\n IMPLICIT NONE\n TYPE(vector), INTENT(IN) :: vec\n REAL, DIMENSION(3), INTENT(OUT) :: arr\n arr(1) = vec%x\n arr(2) = vec%y\n arr(3) = vec%z\n END SUBROUTINE array_to_vector\n\n TYPE(vector) FUNCTION add_vector_and_scalar(v, s)\n IMPLICIT NONE\n TYPE(vector), INTENT(IN) :: v\n REAL, INTENT(IN) :: s\n add_vector_and_scalar = vector(v%x + s, v%y + s, v%z + s)\n END FUNCTION add_vector_and_scalar\n\nEND MODULE vector_operators\n\nPROGRAM test_vector_operators\nUSE vector_operators\nIMPLICIT NONE\nTYPE(vector) :: u, v\nREAL :: s\nREAL, DIMENSION(3) :: a\na = [7., 8., 9.]\ns = 2\nu = vector(1., 2., 3.)\nv = vector(4., 5., 4.)\nWRITE(*, *) u + v\nWRITE(*, *) u * s\nWRITE(*, *) v / 3.\nWRITE(*, *) u .DOT. v\nv = a\nWRITE(*, *) v\na = u\nWRITE(*, *) a\nEND PROGRAM test_vector_operators\n", "meta": {"hexsha": "9972026355cfbd5797c7b6044f0c6f0e218c0161", "size": 2660, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap13/test_vector_operators.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap13/test_vector_operators.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap13/test_vector_operators.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5398230088, "max_line_length": 79, "alphanum_fraction": 0.6894736842, "num_tokens": 881, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067244294588, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.799215317991651}} {"text": "! Driver for FFTLog-f90.\n!\n! FFTLog-f90 is the Fortran 90 version of FFTLog, a Fortran 77 code by\n! Andrew Hamilton to compute the Fourier-Bessel, or Hankel, transform of\n! of a series of logarithmically spaced points.\n!\n! The main reference for the algorithm is Andrew Hamilton's webpage,\n! http://casa.colorado.edu/~ajsh/FFTLog. He first introduced FFTLog in a\n! paper on the nonlinearities in the cosmological structures\n! (http://xxx.lanl.gov/abs/astro-ph/9905191).\n!\n! The Fourier-Bessel, or Hankel, transform F(r) of a function f(k) is defined\n! as in eq. 159 of Hamilton's paper:\n!\n! /\n! F(r) = | dk * k * J_mu(k*r) * f(k)\n! /\n!\n! where J_mu(k*r) is the Bessel function of order mu and argument k*r. \n!\n! IMPORTANT: Currently, FFTLog-f90 only supports the sine transform (mu=0.5)\n! and returns the following integral:\n!\n! 1 / sin(k*r)\n! F(r) = ---------- | dk * k^2 * ---------- * f(k)\n! (2*pi)^2 / k*r\n!\n! If f(k)=P(k) is the power spectrum of a homogeneous 3D random field, then the\n! integral will yield the two-point correlation function xi(r), as in eq. 3.104\n! of http://arxiv.org/abs/1405.2280.\n!\n! To generalise FFTLog-f90 to arbitrary Bessel order, one needs to use\n! the FHTQ subroutine rather than the FFTL one.\n!\n! ARGUMENTS\n!\n! This is the list of command-line arguments taken by FFTLog-f90:\n!\n! 1. The path of the input file, containing the k and f(k) columns.\n!\n! 2. The path of the output file, containing the r and F(r) columns. The file\n! will have as many rows as the input file, unless a third argument is given.\n! By default, the range in r will go from 1/k_max to 1/k_min and will contain\n! as many points as the rows in the input file.\n!\n! 3. [OPTIONAL] N_OUTFILE, the number of r values to include in the output file.\n! Set to zero to use the same number of points in the input file (default behaviour).\n! If positive, then f(k) will be interpolated in N_OUTFILE points and fed to FFTLog.\n!\n! 4. [OPTIONAL] The order mu of the Bessel function J_mu. By default we take mu=0.5,\n! which corresponds to a regular Fourier transform.\n!\n! 5. [OPTIONAL] The bias q of the Hankel transformation, as defined in eq. 156.\n! By default we take it to vanish (b=0).\n!\n! 6. [OPTIONAL] Inferior limit in k for the integration. By default it is set \n! to the first value in the k column.\n!\n! 7. [OPTIONAL] Superior limit in k for the integration. By default it is set \n! to the first value in the k column.\n!\n! Created by Guido Walter Pettinari on 26/07/2010\n! Last modified on 09/09/2015 by GWP\n\n\nPROGRAM fftlog_f90\n\n\tIMPLICIT NONE\n\n\tREAL ( KIND = 8 ), PARAMETER :: PI=3.141592653589793238462643383279502884197d0, CONSTANT=1/(2*PI*PI)\n\tREAL ( KIND = 8 ) :: xx_inf_limit = -1d300, xx_sup_limit = 1d300, dln_xx, dlog_xx, log_xmedian,&\n &log_xxmedian, log_xxmax, log_xxmin, rk, kr, mu, CENTRAL_INDEX, q, x, temp1, temp2\n\tINTEGER :: N_ARGUMENTS, DIRECTION, KR_OPTION, UNIT, error, N_INFILE=0, N_USED=0, FIRST_USED_INDEX = 0,&\n &LAST_USED_INDEX=0, N_OUTFILE=0, i=0\n\tLOGICAL :: INTERPOLATION = .FALSE., FFT_OK\n\tCHARACTER(512) :: input_filename, output_filename\n\tCHARACTER(128) :: buffer\n !\tThe arrays xx and yy will contain the x and y values from the input file, respectively.\n ! They will be overwritten by the FFTL subroutine with the Hankel transform.\n\tREAL ( KIND = 8 ), DIMENSION(:), ALLOCATABLE :: xx, yy\n ! Parameters for the spline interpolation\n\tREAL ( KIND = 8 ), DIMENSION(:), ALLOCATABLE :: yy_second_derivative, yy_interp, wsave\n !\tComplain if the input file has more than N_MAX lines, because it would require\n ! about 2 GB or RAM. Increase N_MAX if you have more memory than that.\n\tINTEGER, PARAMETER :: N_MAX=67108864\n\t\n \n \n ! =======================================================================================\n ! = Parse arguments =\n ! =======================================================================================\n \n\tN_ARGUMENTS = COMMAND_ARGUMENT_COUNT()\n\t\n\tIF ( N_ARGUMENTS.GT.7 .OR. N_ARGUMENTS.LT.2 ) STOP &\n & \"FFTLog-f95 can have between 2 and 7 arguments. For more details, please refer to the&\n & documentation in fftlog_driver.f90 (https://github.com/coccoinomane/fftlog-f90).\"\n\n\n\tCALL GET_COMMAND_ARGUMENT( 1, input_filename )\n\tCALL GET_COMMAND_ARGUMENT( 2, output_filename )\n\n\tIF ( N_ARGUMENTS .GE. 3 ) THEN\n\t\tCALL GET_COMMAND_ARGUMENT( 3, buffer )\n\t\tREAD ( buffer, * ) N_OUTFILE\n\tEND IF\n\n\t! order of Bessel function ( mu = 0.5 for sine transform )\n mu = 0.5d0\n\tIF ( N_ARGUMENTS .GE. 4 ) THEN\n\t\tCALL GET_COMMAND_ARGUMENT( 4, buffer )\n\t\tREAD ( buffer, * ) mu\n\tEND IF\n IF (mu .NE. 0.5d0) STOP &\n & \"FFTLog-f90 so far only supports sine (mu=0.5) and cosine (mu=0.5) transforms. Make&\n & sure that the fourth argument is either 0.5 or -0.5, respectively.\"\n\n\t! bias exponent: q = 0 is unbiased ( good for power spectrum <-> correlation function )\n q = 0.d0\n\tIF ( N_ARGUMENTS .GE. 5 ) THEN\n\t\tCALL GET_COMMAND_ARGUMENT( 5, buffer )\n\t\tREAD ( buffer, * ) q\n\tEND IF\n\n\tIF ( N_ARGUMENTS == 6 ) THEN\n\t\tCALL GET_COMMAND_ARGUMENT( 6, buffer )\n\t\tREAD ( buffer, * ) xx_sup_limit\n\tEND IF\n\t\t\n\tIF ( N_ARGUMENTS == 7 ) THEN\n\t\tCALL GET_COMMAND_ARGUMENT( 6, buffer )\n\t\tREAD ( buffer, * ) xx_inf_limit\n\t\tCALL GET_COMMAND_ARGUMENT( 7, buffer )\n\t\tREAD ( buffer, * ) xx_sup_limit\n\tEND IF\n\t\n \n \n ! =======================================================================================\n ! = Read input file =\n ! ======================================================================================= \n \n ! Select the entries of input_filename to process\n\tOPEN ( UNIT=50, FILE=input_filename, STATUS='OLD', IOSTAT=error )\n\tIF ( error /= 0 ) STOP \"Input file could not be opened, exiting...\"\n\tDO\n\t\tREAD (UNIT=50, FMT=*, IOSTAT=error) temp1\n\t\tIF ( error < 0 ) EXIT\n\t\tN_INFILE = N_INFILE + 1\t\t\n\t\tIF ( temp1 < xx_inf_limit .OR. temp1 > xx_sup_limit ) CYCLE\n\t\tN_USED = N_USED + 1\n\t\tLAST_USED_INDEX = N_INFILE\n\tEND DO\n\tCLOSE(UNIT = 50)\n\tFIRST_USED_INDEX = LAST_USED_INDEX - N_USED + 1\n\t\n !\tControl block\t\n\tIF ( N_USED == 0 ) STOP \"Either the input file is empty or incompatible with the specified integration limits.\"\t\n\tIF ( N_OUTFILE .LE. 0 ) THEN\t\n\t\tN_OUTFILE = N_USED\n\t\tINTERPOLATION = .FALSE.\n\t\tPRINT *, \"No interpolation of input data will be performed.\"\n\tELSE\n\t\tINTERPOLATION = .TRUE.\n\tEND IF\t\t\n IF ( (N_USED > N_MAX) .OR. (N_OUTFILE > N_MAX) ) &\n &STOP \"The number you specified or the number of elements of the input file are greater that N_MAX\"\n\n ! It is now safe to allocate memory to the arrays\n\tALLOCATE( xx(N_USED), yy(N_USED), yy_second_derivative(N_USED) )\n ALLOCATE( yy_interp(N_OUTFILE), wsave ( 2*N_OUTFILE + 3*(N_OUTFILE/2) + 19 ) )\n\n ! Read the first two columns of the input file\n\tOPEN ( UNIT=50, FILE=input_filename, STATUS='OLD', IOSTAT=error )\n\tIF ( error /= 0 ) STOP \"Input file could not be opened, exiting...\"\n !\tDump the rows of the file that are smaller than xx_inf_limit\n\tDO i = 1, FIRST_USED_INDEX - 1\n\t\tREAD ( 50, FMT=*, IOSTAT=error )\n\tEND DO\n\tDO i = 1, N_USED\n\t\tREAD ( 50, FMT=*, IOSTAT=error ) temp1, temp2\n\t\tIF ( error < 0 ) EXIT\n\t\txx(i) = temp1\n\t\tyy(i) = temp2\n\tEND DO\n\tCLOSE( UNIT = 50 )\n\t\n\tPRINT *, \"Inferior integration limit = \", xx(1)\n\tPRINT *, \"corresponding in input file to row = \", FIRST_USED_INDEX\n\tPRINT *, \"Superior integration limit = \", xx(N_USED)\n\tPRINT *, \"corresponding in input file to row = \", LAST_USED_INDEX\t\n\tPRINT *, \"Order of Bessel function mu = \", mu\n\tPRINT *, \"Number of elements in input file = \", N_INFILE\n PRINT *, \"Number of elements used = \", N_USED\n\tPRINT *, \"Number of elements in output file = \", N_OUTFILE\n\n\n\n ! =======================================================================================\n ! = Prepare integrand f(k) =\n ! ======================================================================================= \n\n ! Take the logarithm of the x limits\n\tlog_xxmin = LOG10( xx(1) )\n\tlog_xxmax = LOG10( xx(N_USED) )\n \n ! Logarithmic step in x\n\tdlog_xx = (log_xxmax-log_xxmin) / (N_OUTFILE-1)\n\n\t! central index (1/2 integral if N_OUTFILE is even)\n\tCENTRAL_INDEX = dble( N_OUTFILE+1 ) / 2.d0\n\t\n\t! logarithmical spacing between points (needed by fhti). Was dlnr\n\tdln_xx = dlog_xx * LOG(10.d0)\n\n\t! central point of periodic interval at log10 (xxmedian). Was logrc\n\tlog_xxmedian = ( log_xxmin + log_xxmax) / 2.d0\n\n\t! sensible approximate choice of k_c r_c\n\tkr = 1.d0\n\n\t! tell fhti to change kr to low-ringing value\n\tKR_OPTION = 2\n\n\t! forward transform\n\tDIRECTION = 1\n\n\t! central point in k-space. Was logkc\n\tlog_xmedian = LOG10 (kr) - log_xxmedian\n\n\t! rk = r_c/k_c\n rk = 10.d0 ** ( log_xxmedian - log_xmedian )\n\n ! Interpolate the input \n\tIF( INTERPOLATION ) THEN\n\t\t! Compute the second derivative of the input array yy. The prototype is\n ! spline_cubic_set ( n, t, y, ibcbeg, ybcbeg, ibcend, ybcend, ypp )\n\t\tCALL SPLINE_CUBIC_SET ( N_USED, xx, yy, 0, 0.0d0, 0, 0.0d0, yy_second_derivative )\n\t\tDO i = 1, N_OUTFILE ! the x's are the input domain\n\t\t\tx = 10.d0 ** ( log_xxmedian + ( i - CENTRAL_INDEX )*dlog_xx )\n ! Interpolate the input array yy in x. The prototype is\n\t\t\t! spline_cubic_val ( n, t, y, ypp, tval, yval, ypval, yppval )\n\t\t\tCALL SPLINE_CUBIC_VAL ( N_USED, xx, yy, yy_second_derivative, x, yy_interp(i), temp1, temp2 )\n\t\t\tyy_interp(i) = yy_interp(i)*x\n\t\tEND DO\n\t\tDEALLOCATE ( yy_second_derivative )\n\tELSE\n\t\tDO i = 1, N_USED\n\t\t\tyy(i) = xx(i) * yy(i)\n\t\tEND DO\n\tEND IF\n \n \n \n ! =======================================================================================\n ! = Call FFTLog =\n ! =======================================================================================\n\n ! Initialize FFTLog transform. Note that fhti resets kr\n\tCALL FHTI ( N_OUTFILE, mu, q, dln_xx, kr, KR_OPTION, wsave, FFT_OK )\n\tIF( .NOT. FFT_OK ) STOP \"FHTI not ok!\"\n\n ! Call FFTLog\n\tIF( INTERPOLATION ) THEN \n\t\tCALL FFTL ( N_OUTFILE, yy_interp, rk, DIRECTION, wsave )\n\tELSE\n\t\tCALL FFTL ( N_OUTFILE, yy, rk, DIRECTION, wsave )\n\tEND IF\n\t\n\n\n ! =======================================================================================\n ! = Write result to file =\n ! =======================================================================================\n\n\tOPEN( UNIT=40, FILE = output_filename, STATUS = \"REPLACE\", IOSTAT = error )\n\tIF ( error /= 0 ) STOP \"Output file could not be opened, exiting...\"\n\tIF ( INTERPOLATION ) THEN \n\t\tDO i = 1, N_OUTFILE ! now the x's are the output domain\n\t\t\tx = 10.d0 ** ( log_xmedian + ( i - CENTRAL_INDEX ) * dlog_xx )\n\t\t\tWRITE ( 40, '(3g24.16)' ) x, CONSTANT * yy_interp(i)/x\n\t\tEND DO\n\t\tDEALLOCATE ( yy_interp )\n\tELSE\n\t\tDO i = 1, N_OUTFILE ! now the x's are the output domain\n\t\t\tx = 10.d0 ** ( log_xmedian + ( i - CENTRAL_INDEX )*dlog_xx )\n\t\t\tWRITE( 40, '(3g24.16)' ) x, CONSTANT * yy(i)/x\n\t\tEND DO\n\tEND IF\n\tDEALLOCATE(xx,yy,wsave)\n\t\nEND PROGRAM fftlog_f90\n\n\n", "meta": {"hexsha": "bb9755bf7e3b5d3ec63a23c79141fbf957c538bd", "size": 11207, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fftlog_driver.f90", "max_stars_repo_name": "coccoinomane/fftlog-f90", "max_stars_repo_head_hexsha": "85c617abac1a6536f124f9bcc00b37b0f3cc9cec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-01-23T16:51:48.000Z", "max_stars_repo_stars_event_max_datetime": "2017-10-12T09:11:18.000Z", "max_issues_repo_path": "fftlog_driver.f90", "max_issues_repo_name": "coccoinomane/fftlog-f90", "max_issues_repo_head_hexsha": "85c617abac1a6536f124f9bcc00b37b0f3cc9cec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fftlog_driver.f90", "max_forks_repo_name": "coccoinomane/fftlog-f90", "max_forks_repo_head_hexsha": "85c617abac1a6536f124f9bcc00b37b0f3cc9cec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.9898305085, "max_line_length": 113, "alphanum_fraction": 0.6021236727, "num_tokens": 3278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.7989589081971049}} {"text": "!To find the roots of a Quadratic Equation by Quadratic Formula\r\n\r\nprogram QuadraticFormula\r\n\r\n implicit none\r\n\r\n real::a,b,c,d,rt1,rt2 !Declaring Variables\r\n\r\n print*,\"Enter the coefficient of x^2 :\"\r\n read*,a\r\n print*,\"Enter the coefficient of x :\"\r\n read*,b\r\n print*,\"Enter the constant term :\"\r\n read*,c\r\n\r\n d=(b**2)-(4*a*c) !Determinant\r\n\r\n if(d>0) then\r\n rt1=(-b+sqrt(d))/(2*a)\r\n rt2=(-b-sqrt(d))/(2*a)\r\n print*,\"First Root = \",rt1,\"| Second Root = \",rt2\r\n else if(d==0) then\r\n rt1=(-b+sqrt(d))/(2*a)\r\n print*,\"Root = \",rt1\r\n else\r\n print*,\"No Real roots exist\"\n end if\r\n\nend program\r\n", "meta": {"hexsha": "0ee63707a4d8a5622ece7dc5c513f9dbda715d13", "size": 674, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "1_Quadratic_Formula.f90", "max_stars_repo_name": "Official-Satyam-Tiwari/FORTRAN", "max_stars_repo_head_hexsha": "5f15194bc7a2bdf84ce4516fa291f49072f6b227", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1_Quadratic_Formula.f90", "max_issues_repo_name": "Official-Satyam-Tiwari/FORTRAN", "max_issues_repo_head_hexsha": "5f15194bc7a2bdf84ce4516fa291f49072f6b227", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1_Quadratic_Formula.f90", "max_forks_repo_name": "Official-Satyam-Tiwari/FORTRAN", "max_forks_repo_head_hexsha": "5f15194bc7a2bdf84ce4516fa291f49072f6b227", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.4666666667, "max_line_length": 64, "alphanum_fraction": 0.5430267062, "num_tokens": 208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9664104924150546, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.7989429540561995}} {"text": "SUBROUTINE linearstandingwave2D(g,z,time,sol,Lx,Ly,h,X,Y,pp,uu,vv,ww,eta,etax,etaxx,etay,etayy,Nfs)\n! By Allan P. Engsig-Karup.\n! FIXME: This implementation has in fact not been validated for all output\nUSE Precision\nUSE Constants\nUSE DataTypes\nIMPLICIT NONE\nINTEGER :: Nfs\nTYPE (SFparam) :: sol\nREAL(KIND=long) :: Lx, Ly, kx, ky, h, w, T, time, k, z, HH, c, g\nREAL(KIND=long), DIMENSION(Nfs) :: eta, etax, etaxx, pp, uu, vv, ww, X,Y, etay, etayy\nkx = two*pi/Lx; ky = two*pi/Ly \nk = SQRT(kx**2+ky**2)\nc = SQRT(g/k*TANH(k*h))\nT = SQRT( (two*pi)**2/(g*k*TANH(k*h)) ); \nsol%T=T\nsol%k=k\nsol%c=c\nw = two*pi/T\n!print * ,''\n!print * ,' Computed wave period, T = ',T\nHH = sol%HH\neta = half*HH*COS(w*time)*COS(kx*X)*COS(ky*Y)\netax = -kx*half*HH*COS(w*time)*SIN(kx*X)*COS(ky*Y)\netaxx = -kx**2*half*HH*COS(w*time)*COS(kx*X)*COS(ky*Y)\netay = -ky*half*HH*COS(w*time)*SIN(kx*X)*COS(ky*Y)\netayy = -ky**2*half*HH*COS(w*time)*COS(kx*X)*COS(ky*Y)\npp = -half*HH*c*COSH(k*(z+h))/SINH(k*h)*SIN(w*time)*COS(kx*X)*COS(ky*Y)\nuu = kx*half*HH*c*COSH(k*(z+h))/SINH(k*h)*SIN(w*time)*SIN(kx*X)*COS(ky*Y)\nvv = ky*half*HH*c*COSH(k*(z+h))/SINH(k*h)*SIN(w*time)*COS(kx*X)*SIN(ky*Y)\nww = -half*k*HH*c*SINH(k*(z+h))/SINH(k*h)*SIN(w*time)*COS(kx*X)*COS(ky*Y)\nEND SUBROUTINE linearstandingwave2D\n", "meta": {"hexsha": "acfddc5164c547e84921358b937a727bc6145305", "size": 1283, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/analyticalsolutions/linearstandingwave2D.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/analyticalsolutions/linearstandingwave2D.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/analyticalsolutions/linearstandingwave2D.f90", "max_forks_repo_name": "apengsigkarup/OceanWave3D", "max_forks_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-01T12:17:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T16:23:37.000Z", "avg_line_length": 38.8787878788, "max_line_length": 99, "alphanum_fraction": 0.6266562744, "num_tokens": 598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9664104914476338, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.7989429532564214}} {"text": "! Program to solve a second order DE using Gauss Seidel method\n! Author: Anantha Rao\n! Reg no: 20181044\n\nprogram diff_eq\nimplicit none\n\nreal*8, parameter:: f_x=0.0d0, end_x=1.0d0, dx=0.01 ! INTERVAL\nreal*8 :: f_y, end_y\ninteger, parameter:: nop=int((end_x-f_x)/dx) ! NO OF GRID POINTS IN THE INTERVAL\ninteger :: i,j,k, ll,cond\n\n! Pre factors for calculation \nreal*8 :: x(nop), y(nop), y_old(nop), limit\nreal*8, parameter :: dum1=1.0/(2.0 - 10.0d0*dx*dx)\nreal*8, parameter :: dum2 = (1.0d0-2.5*dx)\nreal*8, parameter :: dum3 = (1.0d0+2.5*dx)\n real*8, parameter :: dum4 = -10.0d0*dx*dx\n\n! Solving differential equation: y'' -5y' + 10y = 10x\n! y'(i) = (y(i+1) - y(i-1))/(2*dx)\n! y'' = (y(i+1) + y(i-1) - 2*y(i))/h^2\n\nwrite(*,*) 'no of grid points', nop\n! INITIALIZATION \n limit = 0.0001 ! Convergence condition\n ll = 0 ! Specifies how many iterations you need for convergence \n cond = 0! Variable whose value decides exit from the do loop\n\n open(080, file='b_value_dx_01_limit_0001.dat', status='unknown')\n x(1)=f_x; x(nop)=end_x; y(1)=0.0d0; y(nop)=40.0d0 ! SPECIFYING BOUNDARY CONDITIONS\n\n ! SETTING UP THE GRID\n do i=2,nop-1\n x(i) = x(i-1) +dx \n ! Setting y-values at each point\n ! Use straight line with slope (end_y-f_y)/(end_x-f_x)\n y(i) = (end_y - f_y)*x(i)/(end_x - f_x) ! Initial condition \n end do\n\n !write(*,*) (x(j),y(j), j=1,nop)\n\n do \n ll=ll+1\n if(cond==1) exit\n\n ! write(*,*) 'll',ll\n\n y_old=y\n do i=2,nop-1 ! NOTE: Boundary points are not updated\n ! JACOBI METHOD\n ! y(i) = dum1*(dum2*y_old(i+1) + dum3*y_old(i-1) + dum4*x(i)) ! UPDATE STEP\n\n ! GAUSS SEIDEL METHOD\n y(i) = dum1*(dum2*y_old(i+1) + dum3*y(i-1) + dum4*x(i)) ! UPDATE STEP\n end do\n\n cond=1\n do i=2,nop-1\n if(abs(y_old(i) - y(i)).ge.limit) cond=0 ! CONDITION TO CHECK CONV\n end do\n\n end do\n\n write(*,*) 'No of iterations required to achieve convergence', ll\n\n do i=1,nop\n write(80,*) x(i), y(i)\n end do\n close(80)\n\nend program diff_eq\n", "meta": {"hexsha": "b60bf123eac330ee2e3275df1415f20c72155038", "size": 2098, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/assgn06_solns/Assgn06_Q2/20181044_diff_eq.f90", "max_stars_repo_name": "Anantha-Rao12/ComPhys", "max_stars_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Solutions/assgn06_solns/Assgn06_Q2/20181044_diff_eq.f90", "max_issues_repo_name": "Anantha-Rao12/ComPhys", "max_issues_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Solutions/assgn06_solns/Assgn06_Q2/20181044_diff_eq.f90", "max_forks_repo_name": "Anantha-Rao12/ComPhys", "max_forks_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.7397260274, "max_line_length": 86, "alphanum_fraction": 0.586749285, "num_tokens": 768, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7988992496097818}} {"text": " FUNCTION BESSI(N,X)\n!\n! This subroutine calculates the first kind modified Bessel function\n! of integer order N, for any REAL X. We use here the classical\n! recursion formula, when X > N. For X < N, the Miller's algorithm\n! is used to avoid overflows. \n! REFERENCE:\n! C.W.CLENSHAW, CHEBYSHEV SERIES FOR MATHEMATICAL FUNCTIONS,\n! MATHEMATICAL TABLES, VOL.5, 1962.\n!\n PARAMETER (IACC = 40,BIGNO = 1.D10, BIGNI = 1.D-10)\n REAL *8 X,BESSI,BESSI0,BESSI1,TOX,BIM,BI,BIP\n IF (N.EQ.0) THEN\n BESSI = BESSI0(X)\n RETURN\n ENDIF\n IF (N.EQ.1) THEN\n BESSI = BESSI1(X)\n RETURN\n ENDIF\n IF(X.EQ.0.D0) THEN\n BESSI=0.D0\n RETURN\n ENDIF\n TOX = 2.D0/X\n BIP = 0.D0\n BI = 1.D0\n BESSI = 0.D0\n M = 2*((N+INT(SQRT(FLOAT(IACC*N)))))\n DO 12 J = M,1,-1\n BIM = BIP+DFLOAT(J)*TOX*BI\n BIP = BI\n BI = BIM\n IF (ABS(BI).GT.BIGNO) THEN\n BI = BI*BIGNI\n BIP = BIP*BIGNI\n BESSI = BESSI*BIGNI\n ENDIF\n IF (J.EQ.N) BESSI = BIP\n 12 CONTINUE\n BESSI = BESSI*BESSI0(X)/BI\n RETURN\n END function BESSI\n! ----------------------------------------------------------------------\n! Auxiliary Bessel functions for N=0, N=1\n FUNCTION BESSI0(X)\n REAL *8 X,BESSI0,Y,P1,P2,P3,P4,P5,P6,P7, &\n Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9,AX,BX\n DATA P1,P2,P3,P4,P5,P6,P7/1.D0,3.5156229D0,3.0899424D0,1.2067429D0, &\n 0.2659732D0,0.360768D-1,0.45813D-2/\n DATA Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9/0.39894228D0,0.1328592D-1, &\n 0.225319D-2,-0.157565D-2,0.916281D-2,-0.2057706D-1, &\n 0.2635537D-1,-0.1647633D-1,0.392377D-2/\n IF(ABS(X).LT.3.75D0) THEN\n Y=(X/3.75D0)**2\n BESSI0=P1+Y*(P2+Y*(P3+Y*(P4+Y*(P5+Y*(P6+Y*P7)))))\n ELSE\n AX=ABS(X)\n Y=3.75D0/AX\n BX=EXP(AX)/SQRT(AX)\n AX=Q1+Y*(Q2+Y*(Q3+Y*(Q4+Y*(Q5+Y*(Q6+Y*(Q7+Y*(Q8+Y*Q9)))))))\n BESSI0=AX*BX\n ENDIF\n RETURN\n END function BESSI0 \n! ----------------------------------------------------------------------\n FUNCTION BESSI1(X)\n REAL *8 X,BESSI1,Y,P1,P2,P3,P4,P5,P6,P7, &\n Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9,AX,BX\n DATA P1,P2,P3,P4,P5,P6,P7/0.5D0,0.87890594D0,0.51498869D0, &\n 0.15084934D0,0.2658733D-1,0.301532D-2,0.32411D-3/\n DATA Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9/0.39894228D0,-0.3988024D-1, &\n -0.362018D-2,0.163801D-2,-0.1031555D-1,0.2282967D-1, &\n -0.2895312D-1,0.1787654D-1,-0.420059D-2/\n IF(ABS(X).LT.3.75D0) THEN\n Y=(X/3.75D0)**2\n BESSI1=X*(P1+Y*(P2+Y*(P3+Y*(P4+Y*(P5+Y*(P6+Y*P7))))))\n ELSE\n AX=ABS(X)\n Y=3.75D0/AX\n BX=EXP(AX)/SQRT(AX)\n AX=Q1+Y*(Q2+Y*(Q3+Y*(Q4+Y*(Q5+Y*(Q6+Y*(Q7+Y*(Q8+Y*Q9)))))))\n BESSI1=AX*BX\n ENDIF\n RETURN\n END function BESSI1\n! ----------------------------------------------------------------------\n\n! end of file tbessi.f90\n\n", "meta": {"hexsha": "fcf6638545aa38ed16035558d81268c497206ba7", "size": 2899, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/bessel/beselI.f90", "max_stars_repo_name": "dlg0/p2f", "max_stars_repo_head_hexsha": "bed2ca3b2271899b32f7f44769bf2018ec350e20", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-04-18T22:34:36.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-21T05:12:33.000Z", "max_issues_repo_path": "src/bessel/beselI.f90", "max_issues_repo_name": "dlg0/p2f", "max_issues_repo_head_hexsha": "bed2ca3b2271899b32f7f44769bf2018ec350e20", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-02-05T15:25:04.000Z", "max_issues_repo_issues_event_max_datetime": "2016-02-05T15:25:04.000Z", "max_forks_repo_path": "src/bessel/beselI.f90", "max_forks_repo_name": "dlg0/p2f", "max_forks_repo_head_hexsha": "bed2ca3b2271899b32f7f44769bf2018ec350e20", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.8571428571, "max_line_length": 76, "alphanum_fraction": 0.5153501207, "num_tokens": 1279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308165850442, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7988778349888956}} {"text": "subroutine PreGLQ(x1, x2, n, zero, w)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis routine will find the zeros and weights that are\n!\tused in Gauss-Legendre quadrature routines. (Based on routines\n!\tin Numerical Recipes).\n!\n!\tCalling Parameters:\n!\t\tIN\n!\t\t\tx1: Lower bound of integration.\n!\t\t\tx2:\tUpper bound of integration.\n!\t\t\tn:\tNumber of points used in the quadrature. n points\n!\t\t\t\twill integrate a polynomial of degree 2n-1 exactly.\n!\t\tOUT\n!\t\t\tzero:\tArray of n Gauss points, which correspond to the zeros\n!\t\t\t\tof P(n,0).\n!\t\t\tw:\tArray of n weights used in the quadrature.\n!\n!\n!\tNote \n!\t\t1.\tIf EPS is less than what is defined, then the do \n!\t\t\tloop for finding the roots might never terminate for some\n!\t\t\tvalues of lmax. If the algorithm doesn't converge, consider\n!\t\t\tincreasing itermax, or decreasing eps.\n!\n!\tDependencies:\tNone\n!\n!\tWritten by Mark Wieczorek 2003\n!\n!\tCopyright (c) 2005-2006, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\tIMPLICIT NONE\n\tREAL*8, INTENT(IN) :: \tX1, X2\n\tREAL*8, INTENT(OUT) ::\tZERO(N), W(N)\n\tINTEGER, INTENT(IN) ::\tN\n\t\n\tINTEGER ::\tI, J, M, ITER\n\tINTEGER, PARAMETER ::\tITERMAX = 1000\n\tREAL*8, PARAMETER ::\tEPS = 1.0D-15\n\tREAL*8 ::\tP1, P2, P3, PP, Z, Z1, XM, XU\n\t\n\t\n\tZERO = 0.0D0\n\tW = 0.0D0\n\t\n\t! The roots are symmetric in the interval, so we only have to find half of them. \n\tM = (N+1)/2\n\t\n\tXM = (X2 + X1) / 2.0D0\t! midpoint of integration\n\tXU = (X2 - X1) / 2.0D0\t! Scaling factor between interval of integration, and that of \n\t\t\t\t! the -1 to 1 interval for the Gauss-Legendre interval\n\t\n\tDO I = 1,M \n\t\tITER = 0\n\t\tZ = COS(3.141592654d0 * (I - .25D0)/(N+.5D0))\t! Approximation for the ith root\n\t\t\t\t\t\t\t\n\t\t! Find the true value using newtons method\n\t\tDO\n\t\t\tITER = ITER +1\n\t\t\t\n\t\t\tP1 = 1.0D0\n\t\t\tP2 = 0.0D0\n\t\t\t\n\t\t\t! determine the legendre polynomial evaluated at z (p1) using recurrence relationships\n\t\t\tDO J=1, N \t\n\t\t\t\tP3 = P2\n\t\t\t\tP2 = P1\n\t\t\t\tP1 = (DBLE(2*J-1)*Z*P2-DBLE(J-1)*P3)/DBLE(J)\n\t\t\tENDDO\n\t\t\t\n\t\t\t! This is the derivative of the legendre polynomial using recurrence relationships\n\t\t\tPP=DBLE(N)*(Z*P1-P2)/(Z*Z-1.0D0)\n\t\t\n\t\t\tZ1 = Z\n\t\t\tZ = Z1-P1/PP \n\t\t\n\t\t\tIF (ABS(Z-Z1) <= EPS) EXIT\n\t\t\t\n\t\t\tIF (ITER > ITERMAX) THEN\n\t\t\t\tPRINT*, \"ERROR --- PreGLQ\"\n\t\t\t\tPRINT*, \"Root Finding of PreGLQ not converging.\"\n\t\t\t\tPRINT*, \"m , n = \", m, n\n\t\t\t\tSTOP\n\t\t\tENDIF\t\t\t\n\t\tENDDO\n\t\t\n\t\tZERO(I) = XM + XU*Z\n\t\tZERO(N+1-I) = XM - XU*Z\n\t\tW(I)= 2.0D0 * XU / ((1.0D0-Z*Z)*PP*PP)\n\t\tW(N+1-I)=W(I) \t\t\n\tENDDO\nEND SUBROUTINE PreGLQ\n\n\n\nINTEGER FUNCTION NGLQ(DEGREE)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tFor a polynomial of order degree, this simple function\n!\twill determine how many gauss-legendre quadrature points\n!\tare needed in order to integrate the function exactly.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\tIMPLICIT NONE\n\tINTEGER, INTENT(IN) ::\tDEGREE\n\t\n\tNGLQ = CEILING((DEGREE+1.0D0)/2.0D0) \t\n\t\nEND FUNCTION NGLQ\n\n\nINTEGER FUNCTION NGLQSH(DEGREE)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function returns the number of gauss-legendre points that\n!\tare needed to exactly integrate a spherical harmonic field of \n!\tLmax = degree\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\tIMPLICIT NONE\n\tINTEGER, INTENT(IN) ::\tDEGREE\n\t\n\tNGLQSH = DEGREE + 1.0D0\n\nEND FUNCTION NGLQSH\n\n\nINTEGER FUNCTION NGLQSHN(DEGREE, N)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function returns the number of gauss-legendre points that\n!\tare needed to exactly integrate a spherical harmonic field of \n!\tLmax = degree raised to the nth power. Here, the maximum degree\n!\tof the integrand is n*lmax + lmax, or (n+1)*lmax\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\tIMPLICIT NONE\n\tINTEGER, INTENT(IN) ::\tDEGREE, N\n\t\n\tNGLQSHN = CEILING( ((N+1.0D0)*DEGREE + 1.0D0)/2.0D0)\n\nEND FUNCTION NGLQSHN\n\n", "meta": {"hexsha": "a8d3552f16e014fcc019e7ee8c6a9f90d92652f5", "size": 4020, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "shtools/PreGLQ.f95", "max_stars_repo_name": "dchandan/PySHTOOLS", "max_stars_repo_head_hexsha": "8b1c32229db87b43d3f40d8f759a3e939f9d9a54", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-11-19T14:48:22.000Z", "max_stars_repo_stars_event_max_datetime": "2017-11-19T14:48:22.000Z", "max_issues_repo_path": "shtools/PreGLQ.f95", "max_issues_repo_name": "dchandan/PySHTOOLS", "max_issues_repo_head_hexsha": "8b1c32229db87b43d3f40d8f759a3e939f9d9a54", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-01-30T07:08:55.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-30T07:08:55.000Z", "max_forks_repo_path": "shtools/PreGLQ.f95", "max_forks_repo_name": "dchandan/PySHTOOLS", "max_forks_repo_head_hexsha": "8b1c32229db87b43d3f40d8f759a3e939f9d9a54", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.5342465753, "max_line_length": 89, "alphanum_fraction": 0.5619402985, "num_tokens": 1320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308165850442, "lm_q2_score": 0.8558511414521922, "lm_q1q2_score": 0.798877829840962}} {"text": "!Autor: Claudio Iván Esparza Castañeda\n!Título: Eliminación de Gauss\n!Descripción: esuelve un sistema de ecuaciones empleando el método de eliminación de Gauss\n!Fecha: 28/04/2020\n\nProgram Gaussito\n implicit none\n INTEGER::i, j, k, N, M\n REAL::S, sum\n REAL, allocatable, dimension(:, :)::A, B\n REAL, allocatable, dimension(:)::X\n \n open(unit=14, file=\"Matriz.dat\", status=\"old\")\n N=0\n do i=1, 10000\n read(14, *, end=15) S\n N=N+1\n end do\n15 close(14)\n write(*, 1) N, N\n1 format(\"El archivo contiene un sistema de\", I2, \" X\", I2)\n \n M=N+1\n \n allocate(A(1:N, 1:M), B(1:N, 1:M), X(1:N))\n open(42, file=\"Matriz.dat\", status=\"old\")\n do i=1, N\n read(42, *) A(i, :)\n write(*, *) A(i, :)\n end do\n close(42)\n \n do k=1, N-1\n do i=k+1, N\n S=A(i, k)/A(k, k)\n do j=k+1, N\n A(i, j)=A(i, j)-A(k, j)*S\n end do\n A(i, k)=0.0d0\n A(i, M)=A(i, M)-S*A(k, M)\n end do\n end do\n \n X(N)=A(N, M)/A(N, N)\n \n do i=N-1, 1, -1\n sum=A(i, M)\n do j=i+1, N\n sum=sum-A(i, j)*X(j)\n end do\n X(i)=sum/A(i, i)\n end do\n\n \n write(*, *)\n write(*, *) X\n deallocate(A, B, X)\nend Program Gaussito\n\n\n\n", "meta": {"hexsha": "1400454bd0b79e2803385c2bc54e683db71e8f1a", "size": 1176, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "23.- Gauss/Gauss.f90", "max_stars_repo_name": "clivan/Fortran", "max_stars_repo_head_hexsha": "4f842c6433899cc36b8c27c71f7667ba0ed15312", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "23.- Gauss/Gauss.f90", "max_issues_repo_name": "clivan/Fortran", "max_issues_repo_head_hexsha": "4f842c6433899cc36b8c27c71f7667ba0ed15312", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "23.- Gauss/Gauss.f90", "max_forks_repo_name": "clivan/Fortran", "max_forks_repo_head_hexsha": "4f842c6433899cc36b8c27c71f7667ba0ed15312", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.9677419355, "max_line_length": 91, "alphanum_fraction": 0.5204081633, "num_tokens": 483, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966717067253, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7988282972059255}} {"text": "! Sieve of Eratosthenes Fortran 95 Module\nmodule sieve\n implicit none\n contains\n subroutine smsv(n, parr, cnt)\n ! find and count the prime nos. <= n\n ! dummy arguments\n integer, intent(in) :: n\n integer, intent(out), dimension(:) :: parr\n integer, intent(out) :: cnt\n ! local data\n integer :: i, j\n logical, dimension(n) :: sv\n ! processing\n sv(1) = .false.\n sv(2:) = .true.\n do i = 2, int(sqrt(real(n)))\n do j = i*i, n, i\n sv(j) = .false.\n end do\n end do\n cnt = 0\n do i = 2, n\n if (sv(i)) then\n cnt = cnt+1\n parr(cnt) = i\n end if\n end do\n end subroutine smsv\n\n subroutine cmpseg(lo, hi, n, p, s)\n ! dummy argumentes\n integer, intent(in) :: lo, hi, n\n integer, intent(in), dimension(n) :: p\n logical, intent(out), dimension(hi-lo+1) :: s\n ! local data\n integer :: i, j, k\n ! processing\n s = .true.\n do i = 1, n\n j = (lo/p(i))*p(i)\n !j = lo-mod(lo, p(i))\n if (j < lo) j = j+p(i)\n do k = j, hi, p(i)\n s(k-lo+1) = .false.\n end do\n end do\n end subroutine cmpseg\n\n subroutine sgsv(n, parr, cnt)\n ! find and count the prime nos. <= n\n ! dummy arguments\n integer, intent(in) :: n\n integer, intent(out), dimension(:) :: parr\n integer, intent(out) :: cnt\n ! local data\n integer :: i, ssiz, psiz, lo, hi\n logical, dimension(int(sqrt(real(n)))+1) :: sieve\n ! processing\n ! compute base primes\n ssiz = int(sqrt(real(n)))+1\n call smsv(ssiz, parr, cnt)\n psiz = cnt\n ! compute subsequent segments\n do lo = ssiz+1, n, ssiz\n ! compute current segment\n hi = min(lo+ssiz-1, n)\n call cmpseg(lo, hi, psiz, parr, sieve)\n ! compute and count primes found in current segement\n do i = lo, hi\n if (sieve(i-lo+1)) then\n cnt = cnt+1\n parr(cnt) = i\n end if\n end do\n end do\n end subroutine sgsv\n\n subroutine pp(n)\n ! print the primes p where p <= n\n ! dummy argument\n integer, intent(in) :: n\n ! local data\n integer :: i, cnt, ssiz, psiz, lo, hi\n integer, dimension(npub(int(sqrt(real(n)))+1)) :: parr\n logical, dimension(int(sqrt(real(n)))+1) :: sieve\n ! processing\n print *, size(sieve), size(parr)\n ssiz = int(sqrt(real(n))) + 1\n ! compute base primes\n call smsv(ssiz, parr, cnt)\n do i = 1, min(cnt, n)\n write (*,'(i12)',advance='no') parr(i)\n if (mod(i, 6) == 0) print *,\n end do\n psiz = cnt\n ! compute sieves and primes for subsequent m sized segments\n do lo = ssiz+1, n, ssiz\n ! compute the next sieve segment\n hi = min(lo+ssiz-1, n)\n call cmpseg(lo, hi, psiz, parr, sieve)\n ! print primes in segment above\n do i = lo, hi\n if (i > n) then\n print *,\n return\n end if\n if (sieve(i-lo+1)) then\n cnt = cnt+1\n write (*,'(i12)',advance='no') i\n if (mod(cnt, 6) == 0) print *,\n end if\n end do\n end do\n if (mod(cnt, 6) /= 0) print *,\n end subroutine pp\n\n subroutine gaps()\n ! local data\n integer, parameter :: SIZ = 2**34\n integer :: i, gap, maxgap, p1, p2, psiz, ssiz, lo, hi\n integer, dimension(npub(SIZ)) :: p\n logical, dimension(int(sqrt(real(SIZ)))) :: seg\n ! processing\n ssiz = int(sqrt(real(SIZ)))\n call smsv(ssiz, p, psiz)\n maxgap = 0\n do i = 2, psiz\n gap = p(i)-p(i-1)-1\n if (gap > maxgap) then\n print *, p(i-1), p(i), gap\n maxgap = gap\n end if\n end do\n p1 = p(psiz)\n do lo = ssiz+1, SIZ, ssiz\n hi = min(lo+ssiz-1, SIZ)\n call cmpseg(lo, hi, psiz, p, seg)\n do i = lo, hi\n if (seg(i-lo+1)) then\n p2 = i\n gap = p2-p1-1\n if (gap > maxgap) then\n print *, p1, p2, gap\n maxgap = gap\n end if\n p1 = p2\n end if\n end do\n end do\n end subroutine gaps\n\n ! number theoretic size of logical array allocation on the stack\n function np(n) result(parr)\n ! find and return the first n prime nos.\n ! dummy arguments\n integer, intent(in) :: n\n ! function result \n integer, dimension(npub(nthpub(n))) :: parr\n ! local variables\n integer :: i, ssiz, psiz, cnt, lo, hi\n logical, dimension(nthpub(n)) :: sieve\n ! processing\n ssiz = nthpub(n)\n ! compute base primes\n call smsv(ssiz, parr, cnt)\n psiz = cnt\n ! compute sieves and primes for subsequent m sized segments\n lo = ssiz+1\n do\n ! compute current segment\n hi = lo+ssiz-1\n call cmpseg(lo, hi, psiz, parr, sieve)\n ! compute the primes in the segment above\n do i = 1, ssiz\n if (sieve(i)) then\n cnt = cnt+1\n parr(cnt) = lo+i-1\n if (cnt == n) return\n end if\n end do\n lo = lo+ssiz\n end do\n end function np\n\n function nthp(n) result(p)\n ! find and return the nth prime no. p\n ! dummy arguments\n integer, intent(in) :: n\n ! function result location\n integer :: p\n ! local data\n integer :: i, ssiz, psiz, cnt, lo, hi\n integer, dimension(npub(nthpub(n))) :: parr \n logical, dimension(nthpub(n)) :: sieve\n ! processing\n ssiz = nthpub(n)\n ! compute base primes\n call smsv(ssiz, parr, cnt)\n if (cnt > n) then\n p = parr(n)\n return\n end if\n psiz = cnt\n ! compute sieves and primes for subsequent m sized segments\n lo = ssiz+1\n do\n ! compute the next sieve segment\n hi = lo+ssiz-1\n call cmpseg(lo, hi, psiz, parr, sieve)\n ! count primes found in current sieve segment\n do i = lo, hi\n if (sieve(i-lo+1)) then\n cnt = cnt+1\n if (cnt == n) then\n p = i\n return\n end if\n end if\n end do\n lo = lo+ssiz\n end do\n end function nthp\n\n ! auxiliary pure functions return sizes for automatic array allocation \n pure function nthpub(n) result(ub)\n ! dummy argument\n integer, intent(in) :: n\n ! function result location\n integer :: ub\n ! processing\n ub = INT(SQRT(n*LOG(REAL(n)) + n*LOG(LOG(REAL(n)))))+1\n end function nthpub\n\n pure function npub(n) result(ub)\n ! dummy argument\n integer, intent(in) :: n\n ! function result location\n integer :: ub\n ! processing\n ub = INT(1.25506*(n/LOG(REAL(n))))\n end function npub \nend module sieve\n", "meta": {"hexsha": "05e69307e912af38285745da2944d1e4661b70f8", "size": 7655, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sieve.f90", "max_stars_repo_name": "joshroybal/fortran-sieve", "max_stars_repo_head_hexsha": "c32dd2166a176eba01179df45e70a0a7cb55758f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sieve.f90", "max_issues_repo_name": "joshroybal/fortran-sieve", "max_issues_repo_head_hexsha": "c32dd2166a176eba01179df45e70a0a7cb55758f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sieve.f90", "max_forks_repo_name": "joshroybal/fortran-sieve", "max_forks_repo_head_hexsha": "c32dd2166a176eba01179df45e70a0a7cb55758f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.3729508197, "max_line_length": 77, "alphanum_fraction": 0.4557805356, "num_tokens": 2030, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768620069627, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7987192703957674}} {"text": "\nsubmodule(forlab_math) forlab_math_degcir\n\n implicit none\n real(sp), parameter ::pi_sp = acos(-1.0_sp)\n real(dp), parameter ::pi_dp = acos(-1.0_dp)\n\ncontains\n\n module procedure acosd_sp\n acosd_sp = acos(x)*180/pi_sp\n end procedure\n\n module procedure acosd_dp\n acosd_dp = acos(x)*180/pi_dp\n end procedure\n\n module procedure asind_sp\n asind_sp = asin(x)*180/pi_sp\n end procedure\n\n module procedure asind_dp\n asind_dp = asin(x)*180/pi_dp\n end procedure\n\n module procedure atand_sp\n atand_sp = atan(x)*180/pi_sp\n end procedure\n\n module procedure atand_dp\n atand_dp = atan(x)*180/pi_dp\n end procedure\n\n module procedure cosd_sp\n cosd_sp = cos(x*pi_sp/180)\n end procedure\n\n module procedure cosd_dp\n cosd_dp = cos(x*pi_dp/180)\n end procedure\n\n module procedure sind_sp\n sind_sp = sin(x*pi_sp/180)\n end procedure\n\n module procedure sind_dp\n sind_dp = sin(x*pi_dp/180)\n end procedure\n\n module procedure tand_sp\n tand_sp = tan(x*pi_sp/180)\n end procedure\n\n module procedure tand_dp\n tand_dp = tan(x*pi_dp/180)\n end procedure\n\nend submodule forlab_math_degcir\n", "meta": {"hexsha": "7ba76caa25ba4ba03dc10f7b50fc02ff3c001044", "size": 1168, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_math_degcir.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "src/forlab_math_degcir.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "src/forlab_math_degcir.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 19.7966101695, "max_line_length": 47, "alphanum_fraction": 0.6849315068, "num_tokens": 331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391558356, "lm_q2_score": 0.8652240947405564, "lm_q1q2_score": 0.7986357180179444}} {"text": "PROGRAM MONTYHALL\n\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: trials = 10000\n INTEGER :: i, choice, prize, remaining, show, staycount = 0, switchcount = 0\n LOGICAL :: door(3)\n REAL :: rnum\n\n CALL RANDOM_SEED\n DO i = 1, trials\n door = .FALSE.\n CALL RANDOM_NUMBER(rnum)\n prize = INT(3*rnum) + 1\n door(prize) = .TRUE. ! place car behind random door\n\n CALL RANDOM_NUMBER(rnum)\n choice = INT(3*rnum) + 1 ! choose a door\n\n DO\n CALL RANDOM_NUMBER(rnum)\n show = INT(3*rnum) + 1\n IF (show /= choice .AND. show /= prize) EXIT ! Reveal a goat\n END DO\n\n SELECT CASE(choice+show) ! Calculate remaining door index\n CASE(3)\n remaining = 3\n CASE(4)\n remaining = 2\n CASE(5)\n remaining = 1\n END SELECT\n\n IF (door(choice)) THEN ! You win by staying with your original choice\n staycount = staycount + 1\n ELSE IF (door(remaining)) THEN ! You win by switching to other door\n switchcount = switchcount + 1\n END IF\n\n END DO\n\n WRITE(*, \"(A,F6.2,A)\") \"Chance of winning by not switching is\", real(staycount)/trials*100, \"%\"\n WRITE(*, \"(A,F6.2,A)\") \"Chance of winning by switching is\", real(switchcount)/trials*100, \"%\"\n\nEND PROGRAM MONTYHALL\n", "meta": {"hexsha": "e3f914a4e5628dcae032f2d2b60bc98fc4bd4a0f", "size": 1303, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Monty-Hall-problem/Fortran/monty-hall-problem.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Monty-Hall-problem/Fortran/monty-hall-problem.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Monty-Hall-problem/Fortran/monty-hall-problem.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 27.7234042553, "max_line_length": 97, "alphanum_fraction": 0.5855717575, "num_tokens": 383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750413739075, "lm_q2_score": 0.8376199694135333, "lm_q1q2_score": 0.7984822109982971}} {"text": " MODULE random_standard_gamma_mod\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n CONTAINS\n\n!*********************************************************************\n\n FUNCTION random_standard_gamma(a)\n!**********************************************************************C\n! C\n! C\n! (STANDARD-) G A M M A DISTRIBUTION C\n! C\n! C\n!**********************************************************************C\n!**********************************************************************C\n! C\n! PARAMETER A >= 1.0 ! C\n! C\n!**********************************************************************C\n! C\n! FOR DETAILS SEE: C\n! C\n! AHRENS, J.H. AND DIETER, U. C\n! GENERATING GAMMA VARIATES BY A C\n! MODIFIED REJECTION TECHNIQUE. C\n! COMM. ACM, 25,1 (JAN. 1982), 47 - 54. C\n! C\n! STEP NUMBERS CORRESPOND TO ALGORITHM 'GD' IN THE ABOVE PAPER C\n! (STRAIGHTFORWARD IMPLEMENTATION) C\n! C\n! Modified by Barry W. Brown, Feb 3, 1988 to use RANF instead of C\n! SUNIF. The argument IR thus goes away. C\n! C\n!**********************************************************************C\n! C\n! PARAMETER 0.0 < A < 1.0 ! C\n! C\n!**********************************************************************C\n! C\n! FOR DETAILS SEE: C\n! C\n! AHRENS, J.H. AND DIETER, U. C\n! COMPUTER METHODS FOR SAMPLING FROM GAMMA, C\n! BETA, POISSON AND BINOMIAL DISTRIBUTIONS. C\n! COMPUTING, 12 (1974), 223 - 246. C\n! C\n! (ADAPTED IMPLEMENTATION OF ALGORITHM 'GS' IN THE ABOVE PAPER) C\n! C\n!**********************************************************************C\n! INPUT: A =PARAMETER (MEAN) OF THE STANDARD GAMMA DISTRIBUTION\n! OUTPUT: SGAMMA = SAMPLE FROM THE GAMMA-(A)-DISTRIBUTION\n! COEFFICIENTS Q(K) - FOR Q0 = SUM(Q(K)*A**(-K))\n! COEFFICIENTS A(K) - FOR Q = Q0+(T*T/2)*SUM(A(K)*V**K)\n! COEFFICIENTS E(K) - FOR EXP(Q)-1 = SUM(E(K)*Q**K)\n! JJV added Save statement for vars in Data satatements\n! PREVIOUS A PRE-SET TO ZERO - AA IS A', AAA IS A\"\n! SQRT32 IS THE SQUAREROOT OF 32 = 5.656854249492380\n! .. Use Statements ..\n USE random_standard_uniform_mod\n USE random_standard_exponential_mod\n USE random_standard_normal_mod\n! ..\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n! .. Function Return Value ..\n REAL :: random_standard_gamma\n! ..\n! .. Scalar Arguments ..\n REAL, INTENT (IN) :: a\n! ..\n! .. Local Scalars ..\n REAL, SAVE :: a1, a2, a3, a4, a5, a6, a7, aa, aaa, b, c, d, e1, &\n e2, e3, e4, e5, q0, q1, q2, q3, q4, q5, q6, q7, s, s2, si, &\n sqrt32\n REAL :: b0, e, p, q, r, t, u, v, w, x\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS, ALOG, EXP, SIGN, SQRT\n! ..\n! .. Data Statements ..\n DATA q1, q2, q3, q4, q5, q6, q7/0.04166669, 0.02083148, &\n 0.00801191, 0.00144121, -.00007388, 0.00024511, 0.00024240/\n DATA a1, a2, a3, a4, a5, a6, a7/0.3333333, -.2500030, 0.2000062, &\n -.1662921, 0.1423657, -.1367177, 0.1233795/\n DATA e1, e2, e3, e4, e5/1., 0.4999897, 0.1668290, 0.0407753, &\n 0.0102930/\n DATA aa/0.0/\n DATA aaa/0.0/\n DATA sqrt32/5.656854/\n! ..\n! .. Executable Statements ..\n\n IF (a/=aa) THEN\n IF (a<1.0) GO TO 40\n\n! STEP 1: RECALCULATIONS OF S2,S,D IF A HAS CHANGED\n\n aa = a\n s2 = a - 0.5\n s = SQRT(s2)\n d = sqrt32 - 12.0*s\n END IF\n\n! STEP 2: T=STANDARD NORMAL DEVIATE,\n! X=(S,1/2)-NORMAL DEVIATE.\n! IMMEDIATE ACCEPTANCE (I)\n\n t = random_standard_normal()\n x = s + 0.5*t\n random_standard_gamma = x*x\n IF (t>=0.0) RETURN\n\n! STEP 3: U= 0,1 -UNIFORM SAMPLE. SQUEEZE ACCEPTANCE (S)\n\n u = random_standard_uniform()\n IF (d*u<=t*t*t) RETURN\n\n! STEP 4: RECALCULATIONS OF Q0,B,SI,C IF NECESSARY\n\n IF (a/=aaa) THEN\n aaa = a\n r = 1.0/a\n q0 = ((((((q7*r+q6)*r+q5)*r+q4)*r+q3)*r+q2)*r+q1)*r\n\n! APPROXIMATION DEPENDING ON SIZE OF PARAMETER A\n! THE CONSTANTS IN THE EXPRESSIONS FOR B, SI AND\n! C WERE ESTABLISHED BY NUMERICAL EXPERIMENTS\n\n IF (a>3.686) THEN\n IF (a>13.022) THEN\n\n! CASE 3: A .GT. 13.022\n\n b = 1.77\n si = 0.75\n c = 0.1515/s\n GO TO 10\n END IF\n\n! CASE 2: 3.686 .LT. A .LE. 13.022\n\n b = 1.654 + 0.0076*s2\n si = 1.68/s + 0.275\n c = 0.062/s + 0.024\n GO TO 10\n\n! CASE 1: A .LE. 3.686\n\n END IF\n b = 0.463 + s + 0.178*s2\n si = 1.235\n c = 0.195/s - 0.079 + 0.16*s\n\n! STEP 5: NO QUOTIENT TEST IF X NOT POSITIVE\n\n END IF\n10 CONTINUE\n IF (x>0.0) THEN\n\n! STEP 6: CALCULATION OF V AND QUOTIENT Q\n\n v = t/(s+s)\n IF (ABS(v)>0.25) THEN\n q = q0 - s*t + 0.25*t*t + (s2+s2)*ALOG(1.0+v)\n ELSE\n\n q = q0 + 0.5*t*t*((((((a7*v+a6)*v+a5)*v+a4)*v+ &\n a3)*v+a2)*v+a1)*v\n END IF\n\n! STEP 7: QUOTIENT ACCEPTANCE (Q)\n\n IF (ALOG(1.0-u)<=q) RETURN\n\n! STEP 8: E=STANDARD EXPONENTIAL DEVIATE\n! U= 0,1 -UNIFORM DEVIATE\n! T=(B,SI)-DOUBLE EXPONENTIAL (LAPLACE) SAMPLE\n\n END IF\n20 CONTINUE\n e = random_standard_exponential()\n u = random_standard_uniform()\n u = u + u - 1.0\n t = b + SIGN(si*e,u)\n DO WHILE (t<(-.7187449))\n e = random_standard_exponential()\n u = random_standard_uniform()\n u = u + u - 1.0\n t = b + SIGN(si*e,u)\n\n! STEP 9: REJECTION IF T .LT. TAU(1) = -.71874483771719\n\n END DO\n\n! STEP 10: CALCULATION OF V AND QUOTIENT Q\n\n v = t/(s+s)\n IF (ABS(v)>0.25) THEN\n q = q0 - s*t + 0.25*t*t + (s2+s2)*ALOG(1.0+v)\n ELSE\n\n q = q0 + 0.5*t*t*((((((a7*v+a6)*v+a5)*v+a4)*v+a3)*v+a2)*v+a1)*v\n END IF\n\n! STEP 11: HAT ACCEPTANCE (H) (IF Q NOT POSITIVE GO TO STEP 8)\n\n IF (q<=0.0) GO TO 20\n IF (q>0.5) THEN\n\n! JJV modified the code through line 125 to handle large Q case\n\n IF (q>=15.0) THEN\n\n! JJV Here Q is large enough that Q = log(exp(Q) - 1.0) (for real Q)\n! JJV so reformulate test at 120 in terms of one EXP, if not too big\n! JJV 87.49823 is close to the largest real which can be\n! JJV exponentiated (87.49823 = log(1.0E38))\n\n IF (q+e-0.5*t*t>87.49823) GO TO 30\n IF (c*ABS(u)>EXP(q+e-0.5*t*t)) GO TO 20\n GO TO 30\n END IF\n\n w = EXP(q) - 1.0\n ELSE\n\n w = ((((e5*q+e4)*q+e3)*q+e2)*q+e1)*q\n END IF\n\n! IF T IS REJECTED, SAMPLE AGAIN AT STEP 8\n\n IF (c*ABS(u)>w*EXP(e-0.5*t*t)) GO TO 20\n30 CONTINUE\n x = s + 0.5*t\n random_standard_gamma = x*x\n RETURN\n\n! ALTERNATE METHOD FOR PARAMETERS A BELOW 1 (.3678794=EXP(-1.))\n\n! JJV changed B to B0 (which was added to declarations for this)\n! JJV in 130 to END to fix rare and subtle bug.\n! JJV Line: '130 aa = 0.0' was removed (unnecessary, wasteful).\n! JJV Reasons: the state of AA only serves to tell the A .GE. 1.0\n! JJV case if certain A-dependant constants need to be recalculated.\n! JJV The A .LT. 1.0 case (here) no longer changes any of these, and\n! JJV the recalculation of B (which used to change with an\n! JJV A .LT. 1.0 call) is governed by the state of AAA anyway.\n\n40 CONTINUE\n b0 = 1.0 + 0.3678794*a\n50 CONTINUE\n p = b0*random_standard_uniform()\n IF (p<1.0) THEN\n random_standard_gamma = EXP(ALOG(p)/a)\n IF (random_standard_exponential() divide by 2 to ensure MPI partition has at least 2 per axis--for 2D and 3D\nif (lx3 == 1) then\n max_mpi = max_gcd(lx2/2, max_cpu)\nelseif (lx2 == 1) then\n max_mpi = max_gcd(lx3/2, max_cpu)\nelse\n max_mpi = max_gcd2(lx2/2, lx3/2, max_cpu)\nend if\n\nend function max_mpi\n\n\npure integer function max_gcd(L, M)\n!! find the Greatest Common Factor to evenly partition the simulation grid\n!! Output range is [M, 1]\n\ninteger, intent(in) :: L,M\ninteger :: i\n\nif (M < 1) error stop \"max_gcd: CPU count must be at least one\"\n\nmax_gcd = 1\ndo i = M, 2, -1\n max_gcd = max(gcd(L, i), max_gcd)\n if (i < max_gcd) exit\nend do\n\nend function max_gcd\n\n\npure integer function max_gcd2(lx2, lx3, M)\n!! find the Greatest Common Factor to evenly partition the simulation grid\n!! Output range is [M, 1]\n!!\n!! 1. find factors of each dimension\n!! 2. choose partition that yields highest CPU count usage\n\ninteger, intent(in) :: lx2, lx3, M\ninteger :: f2, f3, i,j, t2, t3\n\nif (M < 1) error stop \"max_gcd2: CPU count must be at least one\"\n\nmax_gcd2 = 1\nt2 = 1\nt3 = huge(0)\nx2 : do i = M,2,-1\n x3 : do j = M,2,-1\n f2 = max_gcd(lx2, i)\n f3 = max_gcd(lx3, j)\n if (M < f2 * f3) cycle x3 !< too big for CPU count\n if (f2 * f3 < max_gcd2) exit x3 !< too small for max CPU count\n if (lx2 / i == 1) cycle x2\n if (lx3 / j == 1) cycle x3\n if (abs(f2-f3) > abs(t2-t3)) cycle x3\n\n t2 = f2\n t3 = f3\n ! print *, \"lid2, lid3: \", f2, f3\n max_gcd2 = f2 * f3\n end do x3\n if (i*M < max_gcd2) exit x2\nend do x2\n\n! print *, \"final: lid2, lid3: \", t2, t3\n\nend function max_gcd2\n\n\nend module partition\n", "meta": {"hexsha": "f4ee66139b3920cce0577b9f1b1425c3ff00589b", "size": 2078, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "benchmark/partition.f90", "max_stars_repo_name": "geospace-code/h5fortran-mpi", "max_stars_repo_head_hexsha": "f18d5037f1fffcea954fedf2aedcf0f77605a937", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2022-01-13T21:38:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-04T02:39:43.000Z", "max_issues_repo_path": "benchmark/partition.f90", "max_issues_repo_name": "geospace-code/h5fortran-mpi", "max_issues_repo_head_hexsha": "f18d5037f1fffcea954fedf2aedcf0f77605a937", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-07-22T18:37:07.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-22T19:32:33.000Z", "max_forks_repo_path": "benchmark/partition.f90", "max_forks_repo_name": "geospace-code/h5fortran-mpi", "max_forks_repo_head_hexsha": "f18d5037f1fffcea954fedf2aedcf0f77605a937", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-21T06:27:09.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-21T06:27:09.000Z", "avg_line_length": 20.78, "max_line_length": 77, "alphanum_fraction": 0.6410009625, "num_tokens": 784, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611631680358, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7981975021918432}} {"text": "C$Procedure VLCOMG ( Vector linear combination, general dimension )\n \n SUBROUTINE VLCOMG ( N, A, V1, B, V2, SUM )\n \nC$ Abstract\nC\nC Compute a vector linear combination of two double precision\nC vectors of arbitrary dimension.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC VECTOR\nC\nC$ Declarations\n \n INTEGER N\n DOUBLE PRECISION A\n DOUBLE PRECISION V1 ( N )\n DOUBLE PRECISION B\n DOUBLE PRECISION V2 ( N )\n DOUBLE PRECISION SUM ( N )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC N I Dimension of vector space\nC A I Coefficient of V1\nC V1 I Vector in N-space\nC B I Coefficient of V2\nC V2 I Vector in N-space\nC SUM O Linear Vector Combination A*V1 + B*V2\nC\nC$ Detailed_Input\nC\nC N This variable contains the dimension of the V1, V2 and SUM.\nC A This double precision variable multiplies V1.\nC V1 This is an arbitrary, double precision N-dimensional vector.\nC B This double precision variable multiplies V2.\nC V2 This is an arbitrary, double precision N-dimensional vector.\nC\nC$ Detailed_Output\nC\nC SUM is an arbitrary, double precision N-dimensional vector\nC which contains the linear combination A*V1 + B*V2.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Particulars\nC\nC For each index from 1 to N, this routine implements in FORTRAN\nC code the expression:\nC\nC SUM(I) = A*V1(I) + B*V2(I)\nC\nC No error checking is performed to guard against numeric overflow.\nC\nC$ Examples\nC\nC We can easily use this routine to perform vector projections\nC to 2-planes in N-space. Let X be an arbitray N-vector\nC and let U and V be orthonormal N-vectors spanning the plane\nC of interest. The projection of X onto this 2-plane, PROJUV can\nC be obtained by the following code fragment.\nC\nC CALL VLCOMG ( N, VDOT(X,U,N), U, VDOT(X,V,N), V, PROJUV )\nC\nC$ Restrictions\nC\nC No error checking is performed to guard against numeric overflow\nC or underflow. The user is responsible for insuring that the\nC input values are reasonable.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC\nC$ Literature_References\nC\nC None\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WLT)\nC\nC-&\n \nC$ Index_Entries\nC\nC linear combination of two n-dimensional vectors\nC\nC-&\n \n \nC$ Revisions\nC\nC- Beta Version 1.0.1, 1-Feb-1989 (WLT)\nC\nC Example section of header upgraded.\nC\nC-&\n \n INTEGER I\n \n DO I = 1,N\n SUM(I) = A*V1(I) + B*V2(I)\n END DO\n \n RETURN\n END\n", "meta": {"hexsha": "99faf97e411cd16580dd43614247d7274eb54b00", "size": 4324, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/vlcomg.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/vlcomg.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/vlcomg.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 27.8967741935, "max_line_length": 72, "alphanum_fraction": 0.6646623497, "num_tokens": 1247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545362802362, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7981808061986204}} {"text": " real function SRANE(STDDEV)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1994-10-20 SRANE Krogh Changes to use M77CON\nc>> 1994-06-24 SRANE CLL Changed common to use RANC[D/S]1 & RANC[D/S]2.\nc>> 1992-03-16 CLL\nc>> 1991-11-26 CLL Reorganized common. Using RANCM[A/D/S].\nc>> 1991-11-22 CLL Added call to RAN0, and SGFLAG in common.\nc>> 1991-01-15 CLL Reordered common contents for efficiency.\nC>> 1990-01-23 CLL Making names in common same in all subprogams.\nC>> 1987-04-22 SRANE Lawson Initial code.\nc Returns one pseudorandom number from the Exponential\nc distribution with standard deviation, STDDEV, which should be\nc positive.\nc If U is random, uniform on [0, 1], the Exponential variable is\nc given by SRANE = -STDDEV * log(U)\nc This variable has mean = STDDEV\nc and variance = STDDEV**2\nc Reference: NBS AMS 55, P. 930.\nc Code based on subprogram written for JPL by Stephen L. Ritchie,\nc Heliodyne Corp. and Wiley R. Bunton, JPL, 1969.\nc Adapted to Fortran 77 for the JPL MATH77 library by C. L. Lawson &\nc S. Y. Chiu, JPL, Apr 1987.\nc ------------------------------------------------------------------\nc--S replaces \"?\": ?RANE, ?RANUA, RANC?1, RANC?2, ?PTR, ?NUMS, ?GFLAG\nC RANCS1 and RANCS2 are common blocks.\nc Calls RAN0 to initialize SPTR and SGFLAG.\nc ------------------------------------------------------------------\n integer M\n parameter(M = 97)\n real SNUMS(M), STDDEV\n common/RANCS2/SNUMS\n integer SPTR\n logical SGFLAG\n common/RANCS1/SPTR, SGFLAG\n save /RANCS1/, /RANCS2/, FIRST\n logical FIRST\n data FIRST / .true. /\nc ------------------------------------------------------------------\n if(FIRST) then\n FIRST = .false.\n call RAN0\n endif\nc\n SPTR = SPTR - 1\n if(SPTR .eq. 0) then\n call SRANUA(SNUMS, M)\n SPTR = M\n endif\n SRANE = -STDDEV * log(SNUMS(SPTR))\n return\n end\n", "meta": {"hexsha": "0969ba0ba213eb7452ca17b212550046079aacfb", "size": 2150, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/srane.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/srane.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/srane.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 39.8148148148, "max_line_length": 72, "alphanum_fraction": 0.5702325581, "num_tokens": 640, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545274901875, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7981808006802293}} {"text": "program main\n implicit none\n integer(4), parameter :: N_max = 10000\n integer(4), dimension(N_max) :: amicables\n integer(4) :: i,ia,s1,s2\n\n ia = 1\n amicables = 0\n do i=2,N_max\n if (any(amicables==i)) then\n cycle\n endif\n ! get sum of divisors of this number\n s1 = sum_div(i)\n s2 = sum_div(s1)\n if (s2 == i .and. s1 /= i) then\n ! amicable numbers\n amicables(ia) = i\n amicables(ia+1) = s1\n ia = ia + 2\n endif\n enddo\n\n write(*,*) \"sum of amicables: \",sum(amicables)\n\n\ncontains\n\n\n pure function sum_div(n)\n ! Default\n implicit none\n\n ! Function arguments\n integer(4), intent(in) :: n\n integer(4) :: sum_div\n\n ! Local variables\n integer(4) :: i1,i2,nmax\n\n ! Figure out max number to try\n nmax = int(sqrt(1D0*n))\n\n ! 1 is always a divisor\n sum_div = 1\n do i1=2,nmax\n if (mod(n,i1)==0) then\n ! work out if a perfect square\n i2 = n/i1\n if (i2 /= i1) then\n sum_div = sum_div + i1 + i2\n else\n sum_div = sum_div + i1\n endif\n endif\n enddo\n\n return\n end function sum_div\n\n\nend program main\n", "meta": {"hexsha": "aa7b0271c6cb8fad502393094e4857ad4282fa3e", "size": 1186, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/problem21/problem21.f90", "max_stars_repo_name": "plaplant/Project_Euler", "max_stars_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/problem21/problem21.f90", "max_issues_repo_name": "plaplant/Project_Euler", "max_issues_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/problem21/problem21.f90", "max_forks_repo_name": "plaplant/Project_Euler", "max_forks_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-01-07T21:43:45.000Z", "max_forks_repo_forks_event_max_datetime": "2017-01-07T21:43:45.000Z", "avg_line_length": 18.8253968254, "max_line_length": 48, "alphanum_fraction": 0.5379426644, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012655937035, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7981570523111576}} {"text": "\tFUNCTION PR_TMKF ( tmpk )\nC************************************************************************\nC* PR_TMKF\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes TMPF from TMPK. The following equation is\t*\nC* used:\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* TMPF = ( ( TMPK - TMCK ) * 9 / 5 ) + 32\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_TMKF ( TMPK )\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tTMPK\t\tREAL\t\tTemperature in Kelvin\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_TMKF\t\tREAL\t\tTemperature in Fahrenheit\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* I. Graffman/CSC\t 8/83\tOriginal source code\t\t\t*\nC* I. Graffman/RDS\t12/84\tModified equation\t\t\t*\nC* M. desJardins/GSFC\t 4/86\tAdded PARAMETER statement\t\t*\nC* I. Graffman/RDS\t12/87\tGEMPAK4\t\t\t\t\t*\nC* G. Huffman/GSC\t 8/88\tModified documentation\t\t\t*\nC* G. Krueger/EAI 4/96 Replaced C->K constant with PR_TMKC\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\nC*\n\tPARAMETER\t( RPRM = 9.0 / 5.0 )\nC*\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tIF ( ERMISS ( tmpk ) ) THEN\n\t PR_TMKF = RMISSD\n\t ELSE\n\t PR_TMKF = ( ( PR_TMKC (tmpk) ) * RPRM ) + 32.\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "3b5f58aa836a31b9a51541f37abc59a9bfe6ba99", "size": 1256, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prtmkf.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/prmcnvlib/pr/prtmkf.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/prmcnvlib/pr/prtmkf.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 31.4, "max_line_length": 73, "alphanum_fraction": 0.4498407643, "num_tokens": 422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191322715436, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7981534096494775}} {"text": "!SUBROUTINE CHASE.f90\r\n!**************************************************************\r\n!**************************************************************\r\n! Subroutine Name: Chase\r\n! Purpose : Use Thomas Algorithm to solve spares Linear Algebra Equations\r\n! Author: Yang Yang\r\n! October. 2013. \r\n!**************************************************************\r\n!**************************************************************\r\n \r\nSUBROUTINE Chase(c,e,b,f,Nx,x)\r\nIMPLICIT NONE\r\n \r\nINTEGER Nx\r\nREAL*8 e(2:Nx),b(Nx),c(1:Nx-1),f(Nx),x(Nx)\r\n! LU diag\r\nREAL*8 l(2:Nx),u(Nx),y(Nx)\r\n! Control Varibles:\r\nINTEGER i\r\n \r\n! Thomas Algorithm:\r\n \r\n ! step one: LU Decompose\r\n ! x--> x\r\n ! |\r\n ! V\r\n ! x --> x\r\n u(1)= b(1)\r\n DO i=2,Nx\r\n l(i) = e(i) / u(i-1)\r\n u(i) = b(i) - l(i)*c(i-1)\r\n END DO\r\n \r\n ! step two: Backward (pop)\r\n ! |1 | |f(1)|\r\n ! |x 1 | |f(2)|\r\n ! | x 1 | |f(3)|\r\n ! L=| . . | f=| . |\r\n ! | . . | | . |\r\n ! | x 1| |f(N)|\r\n ! so y(i)=[y(1),y(2)......y(N)]\r\n y(1) = f(1)\r\n DO i=2,Nx\r\n y(i) = f(i) - l(i)*y(i-1)\r\n END DO\r\n \r\n ! |x x | |y(1)|\r\n ! | x x | |y(2)|\r\n ! | x x | |y(3)|\r\n ! | . . | | . |\r\n ! U=| . . | y= | . |\r\n ! | . . | | . |\r\n ! | . . | | . |\r\n ! | x x| |y(N)|\r\n x(Nx) = y(Nx) / u(Nx)\r\n DO i=Nx-1,1,-1\r\n x(i) = ( y(i)-c(i)*x(i+1) ) / u(i)\r\n END DO\r\n \r\nEND SUBROUTINE CHASE", "meta": {"hexsha": "7f6a893f10410e588510eb782a763abe9fb80141", "size": 1628, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "OneDimensionUnsteadyHeatConduct/CHASE.f90", "max_stars_repo_name": "shihe000/matlabcfd", "max_stars_repo_head_hexsha": "1134a2385efaa4c9824a309fbb79fd33afff17c1", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2018-03-12T02:18:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-09T01:53:49.000Z", "max_issues_repo_path": "OneDimensionUnsteadyHeatConduct/CHASE.f90", "max_issues_repo_name": "shihe000/matlabcfd", "max_issues_repo_head_hexsha": "1134a2385efaa4c9824a309fbb79fd33afff17c1", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "OneDimensionUnsteadyHeatConduct/CHASE.f90", "max_forks_repo_name": "shihe000/matlabcfd", "max_forks_repo_head_hexsha": "1134a2385efaa4c9824a309fbb79fd33afff17c1", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-06-02T11:35:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-05T21:28:17.000Z", "avg_line_length": 27.1333333333, "max_line_length": 74, "alphanum_fraction": 0.2696560197, "num_tokens": 569, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191246389617, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.798153405229243}} {"text": "program demo_math_arange\n use forlab_math, only: arange\n use forlab_io, only: disp\n\n call disp(arange(3)) !! [1,2,3]\n call disp(arange(-1)) !! [1,0,-1]\n call disp(arange(0,2)) !! [0,1,2]\n call disp(arange(1,-1)) !! [1,0,-1]\n call disp(arange(0, 2, 2)) !! [0,2]\n\n call disp(arange(3.0)) !! [1.0,2.0,3.0]\n call disp(arange(0.0,5.0)) !! [0.0,1.0,2.0,3.0,4.0,5.0]\n call disp(arange(0.0,6.0,2.5)) !! [0.0,2.5,5.0]\n\n call disp((1.0,1.0)*arange(3)) !! [(1.0,1.0),(2.0,2.0),[3.0,3.0]]\n\n call disp(arange(0.0,2.0,-2.0)) !! [0.0,2.0]. Not recommended: `step` argument is negative!\n call disp(arange(0.0,2.0,0.0)) !! [0.0,1.0,2.0]. Not recommended: `step` argument is zero!\n\nend program demo_math_arange", "meta": {"hexsha": "12e2e35350b7080ab98d9959beeeef6592430e8b", "size": 850, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/math/demo_math_arange.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "example/math/demo_math_arange.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "example/math/demo_math_arange.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 42.5, "max_line_length": 104, "alphanum_fraction": 0.4858823529, "num_tokens": 353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088064979618, "lm_q2_score": 0.8596637577007394, "lm_q1q2_score": 0.7981194032764964}} {"text": "program finite\n implicit none\n interface \n subroutine finitedifference(n,h,array1,array2)\n implicit none\n integer n\n real h\n real::array1(n),array2(n)\n end subroutine\n end interface\n \n \n real::b(2001,2)\n integer::i,j\n integer::n=2001\n real::array1(2001),array2(2001)\n\n open(11,file='fort.7',status='old')\n\n do i=1,2001\n read(11,*)(b(i,j),j=1,2)\n array1(i)=b(i,2)\n end do\n\n\n call finitedifference(n,0.01,array1,array2)\n\n\n do i=1,2001\n write(15,*)array2(i)\n end do\n\n end\n\n\n!!!this subroutine is to obtain the second derivative\n! with a forth-order accuracy\n!!!caution: there are arrays as parameter,so there should be\n! an interface when calls it.\n! n----------- number of grids\n! h ---------- step length of small interval\n! array1 ----- fundamental function\n! array2 ----- second derivative of fundamental function\n subroutine finitedifference(n,h,array1,array2)\n implicit none\n integer::n\n real::h\n integer::i\n real::array1(n),array2(n)\n\n do i=1,1000\n array2(i)=(2.*array1(i)-5.*array1(i+1)+4.*array1(i+2)-1.*array1(i+3))/h**2\n end do\n \n do i=2001,1001,-1\n array2(i)=(2.*array1(i)-5.*array1(i-1)+4.*array1(i-2)-1.*array1(i-3))/h**2\n end do\n \n end subroutine\n \n \n \n\n\n\n\n", "meta": {"hexsha": "6964980ab36b6313682cdde62e9399c0172a59b5", "size": 1475, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "finite_dif1.f90", "max_stars_repo_name": "yazhouLY/samples", "max_stars_repo_head_hexsha": "15ee20e233aa74f46ab022dfc69f3d11fb67b608", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "finite_dif1.f90", "max_issues_repo_name": "yazhouLY/samples", "max_issues_repo_head_hexsha": "15ee20e233aa74f46ab022dfc69f3d11fb67b608", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "finite_dif1.f90", "max_forks_repo_name": "yazhouLY/samples", "max_forks_repo_head_hexsha": "15ee20e233aa74f46ab022dfc69f3d11fb67b608", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.0149253731, "max_line_length": 86, "alphanum_fraction": 0.533559322, "num_tokens": 416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.798119393093217}} {"text": "module grid\n\n use iso_fortran_env, only: r64 => real64\n implicit none\n\ncontains\n\n ! linear grid\n elemental function space_linear(i,n,h) result(f)\n integer, intent(in) :: i,n\n real(r64), intent(in) :: h\n real(r64) :: f,x\n x = real(i - 1, r64) / real(n - 1, r64)\n f = x * h\n end function\n\n ! logarithm-like grid (starting at 0)\n ! goes from 0 to h and it's more linear for h < 1\n ! and more logarithmic for h > 1.\n elemental function space_linlog(i,n,h) result(f)\n integer, intent(in) :: i,n\n real(r64), intent(in) :: h\n real(r64) :: f,x\n x = real(i - 1, r64) / real(n - 1, r64)\n f = (1 + h) ** x - 1\n end function\n\n ! logarithm-like grid (starting at 0)\n ! goes from 0 to h and it's more linear for h < 1\n ! and more logarithmic for h > 1.\n elemental function space_asinh(i,n,h) result(f)\n integer, intent(in) :: i,n\n real(r64), intent(in) :: h\n real(r64) :: f,x\n x = real(i - 1, r64) / real(n - 1, r64)\n f = sinh( x * asinh(h) )\n end function\n\n elemental function space_pow2(i,n,k) result(f)\n integer, intent(in) :: i,n\n real(r64), intent(in) :: k\n real(r64) :: f,t\n t = real(i - 1, r64) / real(n - 1, r64)\n f = (2 * t + (k - 1) * t**2) / (k + 1)\n end function\n\n ! linear-logarithmic log\n ! linear steps from 0 to y1, and logarithmic from y1 to y2\n ! it is assumed that y1 = 1 and y2 > 1\n pure subroutine space_linlog2(x, y2)\n real(r64), intent(out) :: x(:)\n real(r64), intent(in) :: y2\n real(r64) :: y1, n2f\n integer :: n1, n2, n, i\n \n n = size(x)\n n2f = n - 1\n y1 = 1.0\n\n do i = 1, 50\n N2f = N - 1 / (1 - (Y1 / Y2)**(1 / N2f))\n end do\n\n n2 = min(floor(n2f), n - 1)\n n1 = n - n2\n\n do i = 1, n1\n x(i) = (i - 1) * (y1 / n1)\n end do\n\n do i = n1, n\n x(i) = y1 * (y2 / y1)**((i - n1) / real(n2, r64))\n end do\n end subroutine\n\nend module", "meta": {"hexsha": "28ba0524cc025ae0c5600f73dad0090c17928194", "size": 1877, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/grid.f90", "max_stars_repo_name": "gronki/diskvert", "max_stars_repo_head_hexsha": "459238a46fc173c9fec3ff609cd42595bbc0c858", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/grid.f90", "max_issues_repo_name": "gronki/diskvert", "max_issues_repo_head_hexsha": "459238a46fc173c9fec3ff609cd42595bbc0c858", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/grid.f90", "max_forks_repo_name": "gronki/diskvert", "max_forks_repo_head_hexsha": "459238a46fc173c9fec3ff609cd42595bbc0c858", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.6973684211, "max_line_length": 60, "alphanum_fraction": 0.5423548215, "num_tokens": 730, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129328, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.7981193863833449}} {"text": "module cholf90\n implicit none\ncontains\n subroutine cholesky ( a, n, nn, u, nullty, ifault )\n!*****************************************************************************80\n!\n!! CHOLESKY computes the Cholesky factorization of a PDS matrix.\n!\n! Discussion:\n!\n! For a positive definite symmetric matrix A, the Cholesky factor U\n! is an upper triangular matrix such that A = U' * U.\n!\n! This routine was originally named \"CHOL\", but that conflicted with\n! a built in MATLAB routine name.\n!\n! Modified:\n!\n! 01 February 2008\n!\n! Author:\n!\n! Michael Healy\n! Modifications by AJ Miller.\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! Michael Healy,\n! Algorithm AS 6:\n! Triangular decomposition of a symmetric matrix,\n! Applied Statistics,\n! Volume 17, Number 2, 1968, pages 195-197.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A((N*(N+1))/2), a positive definite matrix \n! stored by rows in lower triangular form as a one dimensional array, \n! in the sequence\n! A(1,1),\n! A(2,1), A(2,2),\n! A(3,1), A(3,2), A(3,3), and so on.\n!\n! Input, integer ( kind = 4 ) N, the order of A.\n!\n! Input, integer NN, the dimension of the array used to store A, \n! which should be at least (N*(N+1))/2.\n!\n! Output, real ( kind = 8 ) U((N*(N+1))/2), an upper triangular matrix,\n! stored by columns, which is the Cholesky factor of A. The program is\n! written in such a way that A and U can share storage.\n!\n! Output, integer ( kind = 4 ) NULLTY, the rank deficiency of A. If NULLTY is zero,\n! the matrix is judged to have full rank.\n!\n! Output, integer ( kind = 4 ) IFAULT, an error indicator.\n! 0, no error was detected;\n! 1, if N < 1;\n! 2, if A is not positive semi-definite.\n! 3, NN < (N*(N+1))/2.\n!\n! Local Parameters:\n!\n! Local, real ( kind = 8 ) ETA, should be set equal to the smallest positive\n! value such that 1.0 + ETA is calculated as being greater than 1.0 in the\n! accuracy being used.\n!\n implicit none\n\n integer ( kind = 4 ), intent(in) :: n\n integer ( kind = 4 ), intent(in) :: nn\n\n real ( kind = 8 ), intent(in) :: a(nn)\n real ( kind = 8 ), parameter :: eta = 1.0D-19\n integer ( kind = 4 ) i\n integer ( kind = 4 ) icol\n integer ( kind = 4 ), intent(out) :: ifault\n integer ( kind = 4 ) ii\n integer ( kind = 4 ) irow\n integer ( kind = 4 ) j\n integer ( kind = 4 ) k\n integer ( kind = 4 ) kk\n integer ( kind = 4 ) l\n integer ( kind = 4 ) m\n integer ( kind = 4 ), intent(out) :: nullty\n real ( kind = 8 ), intent(out) :: u(nn)\n real ( kind = 8 ) w\n real ( kind = 8 ) x\n\n ifault = 0\n nullty = 0\n\n if ( n <= 0 ) then\n ifault = 1\n return\n end if\n\n if ( nn < ( n * ( n + 1 ) ) / 2 ) then\n ifault = 3\n return\n end if\n\n j = 1\n k = 0\n ii = 0\n!\n! Factorize column by column, ICOL = column number.\n!\n do icol = 1, n\n\n ii = ii + icol\n x = eta * eta * a(ii)\n l = 0\n kk = 0\n!\n! IROW = row number within column ICOL.\n!\n do irow = 1, icol\n\n kk = kk + irow\n k = k + 1\n w = a(k)\n m = j\n\n do i = 1, irow - 1\n l = l + 1\n w = w - u(l) * u(m)\n m = m + 1\n end do\n\n l = l + 1\n\n if ( irow == icol ) then\n exit\n end if\n\n if ( u(l) /= 0.0D+00 ) then\n\n u(k) = w / u(l)\n\n else\n\n u(k) = 0.0D+00\n\n if ( abs ( x * a(k) ) < w * w ) then\n ifault = 2\n return\n end if\n\n end if\n\n end do\n!\n! End of row, estimate relative accuracy of diagonal element.\n!\n if ( abs ( w ) <= abs ( eta * a(k) ) ) then\n\n u(k) = 0.0D+00\n nullty = nullty + 1\n\n else\n\n if ( w < 0.0D+00 ) then\n ifault = 2\n return\n end if\n\n u(k) = sqrt ( w )\n\n end if\n\n j = j + icol\n\n end do\n\n return\nend subroutine cholesky\n!-----------------------------------------------------------------------------\nsubroutine subchl ( a, b, n, u, nullty, ifault, ndim, det )\n\n!*****************************************************************************80\n! \n!! SUBCHL computes the Cholesky factorization of a (subset of a) PDS matrix.\n!\n! Modified:\n!\n! 11 February 2008\n!\n! Author:\n!\n! FORTRAN77 version by Michael Healy, PR Freeman\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! PR Freeman,\n! Remark AS R44:\n! A Remark on AS 6 and AS7: Triangular decomposition of a symmetric matrix\n! and Inversion of a positive semi-definite symmetric matrix,\n! Applied Statistics,\n! Volume 31, Number 3, 1982, pages 336-339.\n!\n! Michael Healy,\n! Algorithm AS 6:\n! Triangular decomposition of a symmetric matrix,\n! Applied Statistics,\n! Volume 17, Number 2, 1968, pages 195-197.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A((M*(M+1))/2), a positive definite matrix \n! stored by rows in lower triangular form as a one dimensional array, \n! in the sequence\n! A(1,1),\n! A(2,1), A(2,2),\n! A(3,1), A(3,2), A(3,3), and so on. \n! In the simplest case, M, the order of A, is equal to N.\n!\n! Input, integer ( kind = 4 ) B(N), indicates the order in which the\n! rows and columns of A are to be used. In the simplest case, \n! B = (1,2,3...,N).\n!\n! Input, integer ( kind = 4 ) N, the order of the matrix, that is, \n! the matrix formed by using B to select N rows and columns of A.\n!\n! Output, real ( kind = 8 ) U((N*(N+1))/2), an upper triangular matrix,\n! stored by columns, which is the Cholesky factor of A. The program is\n! written in such a way that A and U can share storage.\n!\n! Output, integer ( kind = 4 ) NULLTY, the rank deficiency of A. \n! If NULLTY is zero, the matrix is judged to have full rank.\n!\n! Output, integer ( kind = 4 ) IFAULT, an error indicator.\n! 0, no error was detected;\n! 1, if N < 1;\n! 2, if A is not positive semi-definite.\n!\n! Input, integer ( kind = 4 ) NDIM, the dimension of A and U, which might \n! be presumed to be (N*(N+1))/2.\n!\n! Output, real ( kind = 8 ) DET, the determinant of the matrix.\n!\n implicit none\n\n integer ( kind = 4 ) n\n integer ( kind = 4 ) ndim\n\n real ( kind = 8 ) a(ndim)\n integer ( kind = 4 ) b(n)\n real ( kind = 8 ) det\n real ( kind = 8 ), parameter :: eta = 1.0D-09\n integer ( kind = 4 ) i\n integer ( kind = 4 ) icol\n integer ( kind = 4 ) ifault\n integer ( kind = 4 ) ii\n integer ( kind = 4 ) ij\n integer ( kind = 4 ) irow\n integer ( kind = 4 ) j\n integer ( kind = 4 ) jj\n integer ( kind = 4 ) k\n integer ( kind = 4 ) kk\n integer ( kind = 4 ) l\n integer ( kind = 4 ) m\n integer ( kind = 4 ) nullty\n real ( kind = 8 ) u(ndim)\n real ( kind = 8 ) w\n real ( kind = 8 ) x\n\n ifault = 0\n nullty = 0\n det = 1.0D+00\n\n if ( n <= 0 ) then\n ifault = 1\n return\n end if\n\n ifault = 2\n j = 1\n k = 0\n\n do icol = 1, n\n\n ij = ( b(icol) * ( b(icol) - 1 ) ) / 2\n ii = ij + b(icol)\n x = eta * eta * a(ii)\n l = 0\n\n do irow = 1, icol\n\n kk = ( b(irow) * ( b(irow) + 1 ) ) / 2\n k = k + 1\n jj = ij + b(irow)\n w = a(jj)\n m = j\n\n do i = 1, irow - 1\n l = l + 1\n w = w - u(l) * u(m)\n m = m + 1\n end do\n\n l = l + 1\n\n if ( irow == icol ) then\n exit\n end if\n\n if ( u(l) /= 0.0D+00 ) then\n\n u(k) = w / u(l)\n\n else\n\n if ( abs ( x * a(kk) ) < w * w ) then\n ifault = 2\n return\n end if\n\n u(k) = 0.0D+00\n\n end if\n\n end do\n\n if ( abs ( eta * a(kk) ) <= abs ( w ) ) then\n\n if ( w < 0.0D+00 ) then\n ifault = 2\n return\n end if\n\n u(k) = sqrt ( w )\n\n else\n\n u(k) = 0.0D+00\n nullty = nullty + 1\n\n end if\n\n j = j + icol\n det = det * u(k) * u(k)\n\n end do\n\n return\nend subroutine subchl\nend module cholf90\n", "meta": {"hexsha": "89eb033284ef456a26b700da5d0e83a329b1a9e5", "size": 7782, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/cholesky.f90", "max_stars_repo_name": "BingzhangChen/HOT", "max_stars_repo_head_hexsha": "c166ac038cd67a0e4dd5c8512bf5d678eb07b6cc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/cholesky.f90", "max_issues_repo_name": "BingzhangChen/HOT", "max_issues_repo_head_hexsha": "c166ac038cd67a0e4dd5c8512bf5d678eb07b6cc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/cholesky.f90", "max_forks_repo_name": "BingzhangChen/HOT", "max_forks_repo_head_hexsha": "c166ac038cd67a0e4dd5c8512bf5d678eb07b6cc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.2342857143, "max_line_length": 87, "alphanum_fraction": 0.5255718324, "num_tokens": 2692, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7981193830791823}} {"text": "!*****************************************************************************************\n!> author: Jacob Williams\n!\n! Routines for the manipulation of vectors.\n\n module vector_module\n\n use kind_module, only: wp\n use numbers_module, only: one,zero,pi\n\n implicit none\n\n private\n\n integer,parameter,public :: x_axis = 1\n integer,parameter,public :: y_axis = 2\n integer,parameter,public :: z_axis = 3\n\n public :: cross\n public :: unit\n public :: uhat_dot\n public :: ucross\n public :: axis_angle_rotation\n public :: cross_matrix\n public :: outer_product\n public :: box_product\n public :: vector_projection\n public :: vector_projection_on_plane\n public :: axis_angle_rotation_to_rotation_matrix\n public :: spherical_to_cartesian\n public :: cartesian_to_spherical\n public :: rotation_matrix\n public :: rotation_matrix_dot\n public :: angle_between_vectors\n\n !test routine:\n public :: vector_test\n\n contains\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n!\n! Cross product of two 3x1 vectors\n\n pure function cross(r,v) result(rxv)\n\n implicit none\n\n real(wp),dimension(3),intent(in) :: r\n real(wp),dimension(3),intent(in) :: v\n real(wp),dimension(3) :: rxv\n\n rxv = [r(2)*v(3) - v(2)*r(3), &\n r(3)*v(1) - v(3)*r(1), &\n r(1)*v(2) - v(1)*r(2) ]\n\n end function cross\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n!\n! Unit vector\n\n pure function unit(r) result(u)\n\n implicit none\n\n real(wp),dimension(:),intent(in) :: r\n real(wp),dimension(size(r)) :: u\n\n real(wp) :: rmag\n\n rmag = norm2(r)\n\n if (rmag==zero) then\n u = zero\n else\n u = r / rmag\n end if\n\n end function unit\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n!\n! Time derivative of a unit vector.\n\n pure function uhat_dot(u,udot) result(uhatd)\n\n implicit none\n\n real(wp),dimension(3),intent(in) :: u !! vector [`u`]\n real(wp),dimension(3),intent(in) :: udot !! derivative of vector [`du/dt`]\n real(wp),dimension(3) :: uhatd !! derivative of unit vector [`d(uhat)/dt`]\n\n real(wp) :: umag !! vector magnitude\n real(wp),dimension(3) :: uhat !! unit vector\n\n umag = norm2(u)\n\n if (umag == zero) then !singularity\n uhatd = zero\n else\n uhat = u / umag\n uhatd = ( udot - dot_product(uhat,udot)*uhat ) / umag\n end if\n\n end function uhat_dot\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n!\n! Unit vector of the cross product of two 3x1 vectors\n\n pure function ucross(v1,v2) result(u)\n\n implicit none\n\n real(wp),dimension(3),intent(in) :: v1\n real(wp),dimension(3),intent(in) :: v2\n real(wp),dimension(3) :: u\n\n u = unit(cross(v1,v2))\n\n end function ucross\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n! date: 7/20/2014\n!\n! Rotate a 3x1 vector in space, given an axis and angle of rotation.\n!\n!# Reference\n! * [Wikipedia](http://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula)\n\n pure subroutine axis_angle_rotation(v,k,theta,vrot)\n\n implicit none\n\n real(wp),dimension(3),intent(in) :: v !! vector to rotate\n real(wp),dimension(3),intent(in) :: k !! rotation axis\n real(wp),intent(in) :: theta !! rotation angle [rad]\n real(wp),dimension(3),intent(out) :: vrot !! result\n\n real(wp),dimension(3) :: khat\n real(wp) :: ct,st\n\n ct = cos(theta)\n st = sin(theta)\n khat = unit(k) !rotation axis unit vector\n\n vrot = v*ct + cross(khat,v)*st + khat*dot_product(khat,v)*(one-ct)\n\n end subroutine axis_angle_rotation\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n! date: 7/20/2014\n!\n! Computes the cross product matrix, where:\n! ``cross(a,b) == matmul(cross_matrix(a),b)``\n\n pure function cross_matrix(r) result(rcross)\n\n implicit none\n\n real(wp),dimension(3),intent(in) :: r\n real(wp),dimension(3,3) :: rcross\n\n rcross(:,1) = [zero,r(3),-r(2)]\n rcross(:,2) = [-r(3),zero,r(1)]\n rcross(:,3) = [r(2),-r(1),zero]\n\n end function cross_matrix\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n! date: 7/21/2014\n!\n! Computes the outer product of the two vectors.\n\n pure function outer_product(a,b) result(c)\n\n implicit none\n\n real(wp),dimension(:),intent(in) :: a\n real(wp),dimension(:),intent(in) :: b\n real(wp),dimension(size(a),size(b)) :: c\n\n integer :: i\n\n do i=1,size(b)\n c(:,i) = a*b(i)\n end do\n\n end function outer_product\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n! date: 7/21/2014\n!\n! Computes the box product (scalar triple product) of the three vectors.\n\n pure function box_product(a,b,c) result(d)\n\n implicit none\n\n real(wp),dimension(:),intent(in) :: a\n real(wp),dimension(:),intent(in) :: b\n real(wp),dimension(:),intent(in) :: c\n real(wp) :: d\n\n d = dot_product(a,cross(b,c))\n\n end function box_product\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n! date: 7/21/2014\n!\n! The projection of one vector onto another vector.\n!\n!# Reference\n! * [Wikipedia](http://en.wikipedia.org/wiki/Gram-Schmidt_process)\n\n pure function vector_projection(a,b) result(c)\n\n implicit none\n\n real(wp),dimension(:),intent(in) :: a !! the original vector\n real(wp),dimension(size(a)),intent(in) :: b !! the vector to project on to\n real(wp),dimension(size(a)) :: c !! the projection of a onto b\n\n real(wp) :: amag2\n\n amag2 = dot_product(a,a)\n\n if (amag2==zero) then\n c = zero\n else\n c = a * dot_product(a,b) / amag2\n end if\n\n end function vector_projection\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Project a vector onto a plane.\n!\n!# Reference\n! * [Projection of a Vector onto a Plane](http://www.maplesoft.com/support/help/Maple/view.aspx?path=MathApps/ProjectionOfVectorOntoPlane)\n\n pure subroutine vector_projection_on_plane(a,b,c)\n\n implicit none\n\n real(wp),dimension(3),intent(in) :: a !! the original vector\n real(wp),dimension(3),intent(in) :: b !! the plane to project on to (a normal vector)\n real(wp),dimension(3),intent(out) :: c !! the projection of a onto the b plane\n\n c = a - vector_projection(a,b)\n\n end subroutine vector_projection_on_plane\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n! date: 7/20/2014\n!\n! Computes the rotation matrix that corresponds to a\n! rotation about the axis `k` by an angle `theta`.\n\n pure subroutine axis_angle_rotation_to_rotation_matrix(k,theta,rotmat)\n\n implicit none\n\n real(wp),dimension(3),intent(in) :: k !! rotation axis\n real(wp),intent(in) :: theta !! rotation angle [rad]\n real(wp),dimension(3,3),intent(out) :: rotmat !! rotation matrix\n\n real(wp),dimension(3,3),parameter :: I = &\n reshape([one,zero,zero,zero,one,zero,zero,zero,one],[3,3]) !! 3x3 identity matrix\n\n real(wp),dimension(3,3) :: w\n real(wp),dimension(3) :: khat\n real(wp) :: ct,st\n\n ct = cos(theta)\n st = sin(theta)\n khat = unit(k)\n w = cross_matrix(khat)\n\n rotmat = I + w*st + matmul(w,w)*(one-ct)\n\n end subroutine axis_angle_rotation_to_rotation_matrix\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n! date: 9/24/2014\n!\n! Convert spherical (r,alpha,beta) to Cartesian (x,y,z).\n\n pure function spherical_to_cartesian(r,alpha,beta) result(rvec)\n\n implicit none\n\n real(wp),intent(in) :: r !! magnitude\n real(wp),intent(in) :: alpha !! right ascension [rad]\n real(wp),intent(in) :: beta !! declination [rad]\n real(wp),dimension(3) :: rvec !! [x,y,z] vector\n\n rvec(1) = r * cos(alpha) * cos(beta)\n rvec(2) = r * sin(alpha) * cos(beta)\n rvec(3) = r * sin(beta)\n\n end function spherical_to_cartesian\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n! date: 3/6/2016\n!\n! Convert Cartesian (x,y,z) to spherical (r,alpha,beta).\n\n pure subroutine cartesian_to_spherical(rvec,r,alpha,beta)\n\n implicit none\n\n real(wp),dimension(3),intent(in) :: rvec !! [x,y,z] vector\n real(wp),intent(out) :: r !! magnitude\n real(wp),intent(out) :: alpha !! right ascension [rad]\n real(wp),intent(out) :: beta !! declination [rad]\n\n real(wp) :: r1\n\n r1 = rvec(1)*rvec(1)+rvec(2)*rvec(2)\n r = sqrt(r1+rvec(3)*rvec(3))\n\n if (r/=zero) then\n beta = atan2(rvec(3),sqrt(r1))\n if (r1/=zero) then\n alpha = atan2(rvec(2),rvec(1))\n else\n alpha = zero\n end if\n else\n alpha = zero\n beta = zero\n end if\n\n end subroutine cartesian_to_spherical\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n! date: 2/3/2015\n!\n! The 3x3 rotation matrix for a rotation about the x, y, or z-axis.\n!\n! EXAMPLE\n!```Fortran\n! real(wp),dimension(3,3) :: rotmat\n! real(wp),dimension(3) :: vec,vec2\n! real(wp) :: ang\n! ang = pi / 4.0_wp\n! vec = [1.414_wp, 0.0_wp, 0.0_wp]\n! rotmat = rotation_matrix(z_axis,ang)\n! vec2 = matmul(rotmat,vec)\n!```\n\n pure function rotation_matrix(axis,angle) result(rotmat)\n\n implicit none\n\n real(wp),dimension(3,3) :: rotmat !! the rotation matrix\n integer,intent(in) :: axis !! x_axis, y_axis, or z_axis\n real(wp),intent(in) :: angle !! angle in radians\n\n real(wp) :: c,s\n\n !precompute these:\n c = cos(angle)\n s = sin(angle)\n\n select case (axis)\n case(x_axis); rotmat = reshape([one, zero, zero, zero, c, -s, zero, s, c],[3,3])\n case(y_axis); rotmat = reshape([c, zero, s, zero, one, zero, -s, zero, c],[3,3])\n case(z_axis); rotmat = reshape([c, -s, zero, s, c, zero, zero, zero, one],[3,3])\n case default; rotmat = zero\n end select\n\n end function rotation_matrix\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n! date: 3/19/2016\n!\n! Time derivative of the 3x3 rotation matrix\n! for a rotation about the x, y, or z-axis.\n\n pure function rotation_matrix_dot(axis,angle,angledot) result(rotmatdot)\n\n implicit none\n\n real(wp),dimension(3,3) :: rotmatdot !! the rotation matrix derivative \\( d \\mathbf{C} / d t \\)\n integer,intent(in) :: axis !! x_axis, y_axis, or z_axis\n real(wp),intent(in) :: angle !! angle in radians\n real(wp),intent(in) :: angledot !! time derivative of angle in radians/sec\n\n real(wp) :: c,s\n\n !precompute these:\n c = cos(angle)\n s = sin(angle)\n\n !first compute d[C]/da (time derivate w.r.t. the angle):\n select case (axis)\n case(x_axis); rotmatdot = reshape([zero, zero, zero, zero, -s, -c, zero, c, -s],[3,3])\n case(y_axis); rotmatdot = reshape([-s, zero, c, zero, zero, zero, -c, zero, -s],[3,3])\n case(z_axis); rotmatdot = reshape([-s, -c, zero, c, -s, zero, zero, zero, zero],[3,3])\n case default\n rotmatdot = zero\n return\n end select\n\n rotmatdot = rotmatdot * angledot ! d[C]/dt = d[C]/da * da/dt\n\n end function rotation_matrix_dot\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n! date: 3/13/2015\n!\n! The angle between two vectors (in radians).\n\n pure function angle_between_vectors(v1,v2) result(ang)\n\n implicit none\n\n real(wp) :: ang !! [rad]\n real(wp),dimension(3),intent(in) :: v1\n real(wp),dimension(3),intent(in) :: v2\n\n real(wp) :: d,c\n\n d = dot_product(v1,v2)\n c = norm2(cross(v1,v2))\n ang = atan2(c,d)\n\n end function angle_between_vectors\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n! date: 7/20/2014\n!\n! Unit test routine for the [[vector_module]].\n\n subroutine vector_test()\n\n implicit none\n\n integer :: i\n real(wp) :: theta\n real(wp),dimension(3) :: v,k,v2,v3\n real(wp),dimension(3,3) :: rotmat\n\n write(*,*) ''\n write(*,*) '---------------'\n write(*,*) ' vector_test'\n write(*,*) '---------------'\n write(*,*) ''\n\n v = [1.2_wp, 3.0_wp, -5.0_wp]\n k = [-0.1_wp, 16.2_wp, 2.1_wp]\n theta = 0.123_wp\n\n call axis_angle_rotation(v,k,theta,v2)\n\n call axis_angle_rotation_to_rotation_matrix(k,theta,rotmat)\n v3 = matmul(rotmat,v)\n\n write(*,*) 'Single test:'\n write(*,*) ''\n write(*,*) ' v1 :', v\n write(*,*) ' v2 :', v2\n write(*,*) ' v3 :', v3\n write(*,*) ' Error:', v3-v2\n\n write(*,*) ''\n write(*,*) '0-360 test:'\n write(*,*) ''\n do i=0,360,10\n\n theta = i * 180.0_wp/pi\n\n call axis_angle_rotation(v,k,theta,v2)\n\n call axis_angle_rotation_to_rotation_matrix(k,theta,rotmat)\n v3 = matmul(rotmat,v)\n\n write(*,*) 'Error:', norm2(v3-v2)\n\n end do\n\n !z-axis rotation test:\n theta = pi / 4.0_wp\n v = [one/cos(theta), 0.0_wp, 0.0_wp]\n rotmat = rotation_matrix(z_axis,theta)\n v2 = matmul(rotmat,v)\n write(*,*) v2 !should be [1, -1, 0]\n\n\n end subroutine vector_test\n !****************************************************************************************\n\n!*****************************************************************************************\n end module vector_module\n!*****************************************************************************************\n", "meta": {"hexsha": "557dc952301d41a276cd3d7122574bd89caef2e7", "size": 15850, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/vector_module.f90", "max_stars_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_stars_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-12-26T03:54:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-26T03:54:38.000Z", "max_issues_repo_path": "src/vector_module.f90", "max_issues_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_issues_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/vector_module.f90", "max_forks_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_forks_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.6816479401, "max_line_length": 140, "alphanum_fraction": 0.4678233438, "num_tokens": 3958, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.8723473862936942, "lm_q1q2_score": 0.79811146085399}} {"text": "SUBROUTINE beta_angle (r_sat, v_sat, r_sun, beta)\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: beta_angle.f90\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Computation of Sun angle with respect to the orbital plane\r\n! ----------------------------------------------------------------------\r\n! Input arguments:\r\n! - r_sat: \t\t\tSatellite position vector (m) \r\n! - v_sat: \t\t\tSatellite velocity vector (m/sec)\r\n! - r_sun:\t\t\tSun position vector (m)\r\n!\r\n! Output arguments:\r\n! - beta:\t\t\tSun angle with the orbital plane in degrees (see Note 1)\r\n! ----------------------------------------------------------------------\r\n! Note 1:\r\n! Beta angle is computed based on the input vectors in inertial system\r\n! Sign conventions for beta angle:\r\n! Postiive: above orbital plane\r\n! Negative: below orbital plane \t\r\n! ----------------------------------------------------------------------\r\n! Dr. Thomas D. Papanikolaou, Geoscience Australia June 2016\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n USE mdl_precision\r\n USE mdl_num\r\n IMPLICIT NONE\r\n\t \r\n! ----------------------------------------------------------------------\r\n! Dummy arguments declaration\r\n! ----------------------------------------------------------------------\r\n! IN\r\n REAL (KIND = prec_d), INTENT(IN) :: r_sat(3), v_sat(3), r_sun(3)\r\n! OUT\r\n REAL (KIND = prec_d), INTENT(OUT) :: beta\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Local variables declaration\r\n! ----------------------------------------------------------------------\r\n REAL (KIND = prec_d) :: Xsat(3), dXsat(3), Xsun(3), dERA\r\n REAL (KIND = prec_d) :: pcross(3), pdot, beta_rad\r\n REAL (KIND = prec_d) :: eV_i(3)\r\n INTEGER (KIND = prec_int4) :: eV_opt \r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Unit Vectors\r\n! ----------------------------------------------------------------------\r\n! Xsat:\t\tSatellite position unit vector\r\n Xsat = (1D0 / sqrt(r_sat(1)**2 + r_sat(2)**2 + r_sat(3)**2) ) * r_sat\r\n\t \r\n! dXsat:\tSatellite Velocity unit vector\r\n dXsat = (1D0 / sqrt(v_sat(1)**2 + v_sat(2)**2 + v_sat(3)**2) ) * v_sat\r\n\t \r\n! Xsun:\t\tSun position unit vector\r\n Xsun = (1D0 / sqrt(r_sun(1)**2 + r_sun(2)**2 + r_sun(3)**2) ) * r_sun\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Inertial geocentric satellite velocity unit vector\r\n! ----------------------------------------------------------------------\r\n eV_opt = 1 \r\n !PRINT *,'eV_opt',eV_opt \r\n\r\n\t \r\n if (eV_opt == 1) then \r\n! ----------------------------------------------------------------------\r\n! 1. Satellite Velocity unit vector in ICRF (obtained from orbit integration)\r\n eV_i = (1D0 / sqrt(v_sat(1)**2 + v_sat(2)**2 + v_sat(3)**2) ) * v_sat\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n elseif (eV_opt == 2) then\r\n! ----------------------------------------------------------------------\r\n! 2. Approximate value used in Kouba (2009), Eq.(3)\r\n! ----------------------------------------------------------------------\r\n! Earth angular velocity | IERS 2010 constants: omega = 7.292115D-05\r\n! Omega as derivative of the Earth Rotation Angle (ERA), dERA/dt in rad/s\r\n dERA = 2.0D0 * PI_global * 1.00273781191135448D0 * (1.0D0/86400.0D0)\r\n! ----------------------------------------------------------------------\r\n eV_i(1) = dXsat(1) - dERA * Xsat(2) \t\t\t\t\t\t\t\t\t\t\t\t\t\t \r\n eV_i(2) = dXsat(2) + dERA * Xsat(1) \t\t\t\t\t\t\t\t\t\t\t\t\t\t \r\n eV_i(3) = dXsat(3) \t\t\t\t\t\t\t\t\t\t\t\t\t\t \r\n! ----------------------------------------------------------------------\r\n end if\r\n! ----------------------------------------------------------------------\r\n\r\n\t \r\n\t \r\n! ----------------------------------------------------------------------\r\n! BETA : Sun angle with the orbtial plane\r\n! ----------------------------------------------------------------------\r\n CALL productcross (eV_i , Xsat , pcross)\t! -Normal (antiparallel) \r\n !CALL productcross (Xsat , eV_i , pcross)\t! +Normal \r\n CALL productdot (pcross , Xsun , pdot)\t\t\t\t\r\n\t \r\n !beta_rad = acos (pdot) - PI_global\t\t\t\t\t\t! Kouba (2009), Eq.(2)\r\n beta_rad = acos(pdot) - PI_global/2.0D0\t\t\t\t\t! correction to Eq.(2): pi has been changed to pi/2 \r\n\t\t \r\n ! Degrees\r\n beta = beta_rad * (180.0D0 / PI_global) \t \r\n \r\n\t \r\nEND\r\n", "meta": {"hexsha": "a580b20dc5d7fd5fc39f3f04f74b597c55c62929", "size": 4756, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/beta_angle.f90", "max_stars_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_stars_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2021-07-08T23:35:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:17:58.000Z", "max_issues_repo_path": "src/fortran/beta_angle.f90", "max_issues_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_issues_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-09-27T14:27:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T23:50:02.000Z", "max_forks_repo_path": "src/fortran/beta_angle.f90", "max_forks_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_forks_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2021-07-12T05:42:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T15:15:34.000Z", "avg_line_length": 43.2363636364, "max_line_length": 103, "alphanum_fraction": 0.3523969722, "num_tokens": 1068, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9653811591688146, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7980919962409656}} {"text": "module mats\n implicit none\n\n public\n\n contains\n\n function identity(n) result(I)\n integer, intent(in) :: n\n real :: I(n, n)\n \n integer :: j, k\n do j = 1, n\n do k = 1, n\n if (j == k) then\n I(j, k) = 1\n else\n I(j, k) = 0\n end if\n end do\n end do\n end function identity\n\n ! only call with triangular matrices\n function tri_det(M) result(det)\n real, intent(in) :: M(:, :)\n real :: det\n\n integer :: i\n det = 1\n do i = 1, size(M, 1)\n det = det * M(i, i)\n end do\n end function tri_det\n\n subroutine print_mat(M)\n real, intent(in) :: M(:, :)\n\n integer :: i\n do i = 1, size(M, 2)\n print *, M(:, i)\n end do\n end subroutine print_mat\nend module mats\n", "meta": {"hexsha": "fdd9180f091ac2ca3dc21b2da1c7b9f5659e2a9b", "size": 753, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mats.f90", "max_stars_repo_name": "Ergoold/matrix-maths", "max_stars_repo_head_hexsha": "4011f36ff1903d7b77b9a7eb8c3980f2d7a62775", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mats.f90", "max_issues_repo_name": "Ergoold/matrix-maths", "max_issues_repo_head_hexsha": "4011f36ff1903d7b77b9a7eb8c3980f2d7a62775", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mats.f90", "max_forks_repo_name": "Ergoold/matrix-maths", "max_forks_repo_head_hexsha": "4011f36ff1903d7b77b9a7eb8c3980f2d7a62775", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.7333333333, "max_line_length": 38, "alphanum_fraction": 0.5086321381, "num_tokens": 244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533163686645, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7980412454500887}} {"text": " MODULE random_nc_chisq_mod\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n CONTAINS\n\n!*********************************************************************\n\n FUNCTION random_nc_chisq(df,pnonc)\n! .. Use Statements ..\n USE random_standard_gamma_mod\n USE random_standard_normal_mod\n! ..\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n! .. Function Return Value ..\n REAL :: random_nc_chisq\n! ..\n! .. Scalar Arguments ..\n REAL, INTENT (IN) :: df, pnonc\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC SQRT\n! ..\n! .. Executable Statements ..\n\n!**********************************************************************\n! REAL FUNCTION GENNCH( DF, PNONC )\n! Generate random value of Noncentral CHIsquare variable\n! Function\n! Generates random deviate from the distribution of a noncentral\n! chisquare with DF degrees of freedom and noncentrality parameter\n! PNONC.\n! Arguments\n! DF --> Degrees of freedom of the chisquare\n! (Must be >= 1.0)\n! REAL DF\n! PNONC --> Noncentrality parameter of the chisquare\n! (Must be >= 0.0)\n! REAL PNONC\n! Method\n! Uses fact that noncentral chisquare is the sum of a chisquare\n! deviate with DF-1 degrees of freedom plus the square of a normal\n! deviate with mean sqrt(PNONC) and standard deviation 1.\n!**********************************************************************\n! JJV changed these to call SGAMMA and SNORM directly\n! REAL random_chisq,random_normal\n! EXTERNAL random_chisq,random_normal\n! JJV changed abort to df < 1, and added case: df = 1\n IF (df<1.0 .OR. pnonc<0.0) THEN\n WRITE (*,*) 'DF < 1 or PNONC < 0 in GENNCH - ABORT'\n WRITE (*,*) 'Value of DF: ', df, ' Value of PNONC', pnonc\n STOP 'DF < 1 or PNONC < 0 in GENNCH - ABORT'\n END IF\n\n! JJV changed this to call SGAMMA and SNORM directly\n! random_nc_chisq = random_chisq(df-1.0) + random_normal(sqrt(pnonc),1.0)**2\n\n IF (df<1.000001) THEN\n! JJV case DF = 1.0\n random_nc_chisq = (random_standard_normal()+SQRT(pnonc))**2\n ELSE\n\n! JJV case DF > 1.0\n random_nc_chisq = 2.0*random_standard_gamma((df-1.0)/2.0) + &\n (random_standard_normal()+SQRT(pnonc))**2\n END IF\n RETURN\n\n END FUNCTION random_nc_chisq\n\n!*********************************************************************\n\n END MODULE random_nc_chisq_mod\n", "meta": {"hexsha": "576441fee370ba26f8ad03d146ffb927b544b217", "size": 2620, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/random_nc_chisq_mod.f90", "max_stars_repo_name": "urbanjost/fpm_tools", "max_stars_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/random_nc_chisq_mod.f90", "max_issues_repo_name": "urbanjost/fpm_tools", "max_issues_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/random_nc_chisq_mod.f90", "max_forks_repo_name": "urbanjost/fpm_tools", "max_forks_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-14T11:36:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-14T11:36:01.000Z", "avg_line_length": 34.4736842105, "max_line_length": 81, "alphanum_fraction": 0.5213740458, "num_tokens": 685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.8688267643505193, "lm_q1q2_score": 0.7980002185363604}} {"text": "program problem_45\n implicit none\n logical :: isPentagonal, isHexagonal, found\n integer(kind=8) :: n, i, triangle\n \n i = 286\n found = .FALSE.\n do while (.NOT. found)\n n = triangle(i)\n if (isPentagonal(n) .AND. isHexagonal(n)) then\n found = .TRUE.\n print *, n, i\n endif\n i = i + 1\n enddo\n\nend program problem_45\n\ninteger(kind=8) function triangle(number) result(output)\n implicit none\n integer(kind=8) :: number\n output = (number / 2d0) * (number + 1d0)\n \nend function triangle\n\nlogical function isPentagonal(number) result(decision)\n implicit none\n integer(kind=8) :: number\n real*16 :: n\n n = (1d0 / 6d0) * (sqrt(24d0 * number + 1d0) + 1d0)\n decision = (n == floor(n))\n \nend function isPentagonal\n\nlogical function isHexagonal(number) result(decision)\n implicit none\n integer(kind=8) :: number\n real(kind=8) :: n\n n = 25d-2 * (sqrt(8d0 * number + 1d0) + 1d0)\n \n decision = (n == floor(n))\nend function isHexagonal\n", "meta": {"hexsha": "25c81842d4d3d6d511128f2e84c8cce1c57ff58b", "size": 1037, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Problem_45/main.f95", "max_stars_repo_name": "jdalzatec/EulerProject", "max_stars_repo_head_hexsha": "2f2f4d9c009be7fd63bb229bb437ea75db77d891", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-28T05:32:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T05:32:58.000Z", "max_issues_repo_path": "Problem_45/main.f95", "max_issues_repo_name": "jdalzatec/EulerProject", "max_issues_repo_head_hexsha": "2f2f4d9c009be7fd63bb229bb437ea75db77d891", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Problem_45/main.f95", "max_forks_repo_name": "jdalzatec/EulerProject", "max_forks_repo_head_hexsha": "2f2f4d9c009be7fd63bb229bb437ea75db77d891", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.1162790698, "max_line_length": 56, "alphanum_fraction": 0.6007714561, "num_tokens": 326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9626731094431571, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.7979970940425736}} {"text": "program meanVarianceSD\r\n\r\n implicit none;\r\n integer, parameter::MAX_SIZE = 100;\r\n integer n;\r\n integer i;\r\n real sumX, sumY, sumXY, meanX, meanY, Xpow2, Ypow2, X, Y, RESULT;\r\n \r\n real, dimension(2, MAX_SIZE)::arrXY\r\n \r\n print *, \"Enter no of terms : \"\r\n read *, n\r\n \r\n \r\n do i = 1, n\r\n print *, \"x = \"\r\n read *, arrXY(1, i);\r\n print *, \"y = \"\r\n read *, arrXY(2, i);\r\n end do;\r\n\r\n meanX = 0;\r\n meanY = 0;\r\n \r\n do i = 1, n, 1\r\n meanX = meanX + arrXY(1, i); \r\n meanY = meanY + arrXY(2, i);\r\n end do;\r\n \r\n meanX = meanX / n;\r\n meanY = meanY / n;\r\n \r\n Xpow2 = 0;\r\n Ypow2 = 0;\r\n\r\n sumX = 0;\r\n sumY = 0;\r\n sumXY = 0;\r\n do i = 1, n , 1\r\n X = (arrXY(1, i) - meanX)\r\n Y = (arrXY(2, i) - meanY)\r\n sumX = sumX + X**2;\r\n sumY = sumY + Y**2;\r\n sumXY = sumXY + X * Y;\r\n end do;\r\n RESULT = sumXY / (SQRT(sumX) * SQRT(sumY));\r\n\r\n print *, \"RESULT = \", RESULT;\r\n! print *, \"MeanX = \", meanX;\r\n! print *, \"MeanY = \", meanY;\r\n! print *, \"sumX = \", sumX;\r\n! print *, \"sumY = \", sumY;\r\n! print *, \"sumXY = \", sumXY;\r\n \r\nend program meanVarianceSD", "meta": {"hexsha": "f02651a05eda26ce13fecff5883f42d499aa6a77", "size": 1203, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "III-sem/NumericalMethod/FortranProgram/Practice/correlation.f95", "max_stars_repo_name": "ASHD27/JMI-MCA", "max_stars_repo_head_hexsha": "61995cd2c8306b089a9b40d49d9716043d1145db", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-03-18T16:27:33.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-07T12:39:32.000Z", "max_issues_repo_path": "III-sem/NumericalMethod/FortranProgram/Practice/correlation.f95", "max_issues_repo_name": "ASHD27/JMI-MCA", "max_issues_repo_head_hexsha": "61995cd2c8306b089a9b40d49d9716043d1145db", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "III-sem/NumericalMethod/FortranProgram/Practice/correlation.f95", "max_forks_repo_name": "ASHD27/JMI-MCA", "max_forks_repo_head_hexsha": "61995cd2c8306b089a9b40d49d9716043d1145db", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-11-11T06:49:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-07T12:41:20.000Z", "avg_line_length": 21.8727272727, "max_line_length": 71, "alphanum_fraction": 0.4413965087, "num_tokens": 431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9678992932829917, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.797996117965952}} {"text": "! examples/Fortran/nlls_example.f90\n! \n! Attempts to fit the model y_i = x_1 e^(x_2 t_i)\n! For parameters x_1 and x_2, and input data (t_i, y_i)\nmodule fndef_example\n use ral_nlls_double, only : params_base_type\n implicit none\n\n integer, parameter :: wp = kind(0d0)\n\n type, extends(params_base_type) :: params_type\n real(wp), dimension(:), allocatable :: t ! The m data points t_i\n real(wp), dimension(:), allocatable :: y ! The m data points y_i\n end type\n\ncontains\n ! Calculate r_i(x; t_i, y_i) = x_1 e^(x_2 * t_i) - y_i\n subroutine eval_r(status, n, m, x, r, params)\n integer, intent(out) :: status\n integer, intent(in) :: n\n integer, intent(in) :: m\n real(wp), dimension(*), intent(in) :: x\n real(wp), dimension(*), intent(out) :: r\n class(params_base_type), intent(inout) :: params\n\n real(wp) :: x1, x2\n\n x1 = x(1)\n x2 = x(n)\n select type(params)\n type is(params_type)\n r(1:m) = x1 * exp(x2*params%t(:)) - params%y(:)\n end select\n\n status = 0 ! Success\n end subroutine eval_r\n ! Calculate:\n ! J_i1 = e^(x_2 * t_i)\n ! J_i2 = t_i x_1 e^(x_2 * t_i)\n subroutine eval_J(status, n, m, x, J, params)\n integer, intent(out) :: status\n integer, intent(in) :: n\n integer, intent(in) :: m\n real(wp), dimension(*), intent(in) :: x\n real(wp), dimension(*), intent(out) :: J\n class(params_base_type), intent(inout) :: params\n\n real(wp) :: x1, x2\n\n x1 = x(1)\n x2 = x(n)\n select type(params)\n type is(params_type)\n J( 1: m) = exp(x2*params%t(1:m)) ! J_i1\n J(m+1:2*m) = params%t(1:m) * x1 * exp(x2*params%t(1:m))! J_i2\n end select\n\n status = 0 ! Success\n end subroutine eval_J\n ! Calculate\n ! HF = sum_i r_i H_i\n ! Where H_i = [ 0 t_i e^(x_2 t_i) ]\n ! [ t_i e^(x_2 t_i) t_i^2 x_1 e^(x_2 t_i) ]\n subroutine eval_HF(status, n, m, x, r, HF, params)\n integer, intent(out) :: status\n integer, intent(in) :: n\n integer, intent(in) :: m\n real(wp), dimension(*), intent(in) :: x\n real(wp), dimension(*), intent(in) :: r\n real(wp), dimension(*), intent(out) :: HF\n class(params_base_type), intent(inout) :: params\n\n real(wp) :: x1, x2\n\n x1 = x(1)\n x2 = x(2)\n select type(params)\n type is(params_type)\n HF( 1) = sum(r(1:m) * 0) ! H_11\n HF( 2) = sum(r(1:m) * params%t(1:m) * exp(x2*params%t(1:m))) ! H_21\n HF(1*n+1) = HF(2) ! H_12\n HF(1*n+2) = sum(r(1:m) * (params%t(1:m)**2) * x1 * exp(x2*params%t(1:m)))! H_22\n end select\n\n status = 0 ! Success\n end subroutine eval_HF\nend module fndef_example\n\nprogram nlls_example\n use ral_nlls_double\n use fndef_example\n implicit none\n\n type(nlls_options) :: options\n type(nlls_inform) :: inform\n\n integer :: m,n\n real(wp), allocatable :: x(:)\n type(params_type) :: params\n\n ! Data to be fitted\n m = 5\n allocate(params%t(m), params%y(m))\n params%t(:) = (/ 1.0, 2.0, 4.0, 5.0, 8.0 /)\n params%y(:) = (/ 3.0, 4.0, 6.0, 11.0, 20.0 /)\n \n ! Call fitting routine\n n = 2\n allocate(x(n))\n x = (/ 2.5, 0.25 /) ! Initial guess\n call nlls_solve(n, m, x, eval_r, eval_J, eval_HF, params, options, inform)\n if(inform%status.ne.0) then\n print *, \"ral_nlls() returned with error flag \", inform%status\n stop\n endif\n\n ! Print result\n print *, \"Found a local optimum at x = \", x\n print *, \"Took \", inform%iter, \" iterations\"\n print *, \" \", inform%f_eval, \" function evaluations\"\n print *, \" \", inform%g_eval, \" gradient evaluations\"\n print *, \" \", inform%h_eval, \" hessian evaluations\"\nend program nlls_example\n", "meta": {"hexsha": "58c41f57e9e2a17f56e90c2edd970f3e31f4aeef", "size": 3833, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "libRALFit/example/Fortran/nlls_example.f90", "max_stars_repo_name": "andpic/RALFit", "max_stars_repo_head_hexsha": "d8bd77217b5163f79069eaf7c5238a854f4843e3", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-04-02T12:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T00:11:45.000Z", "max_issues_repo_path": "libRALFit/example/Fortran/nlls_example.f90", "max_issues_repo_name": "andpic/RALFit", "max_issues_repo_head_hexsha": "d8bd77217b5163f79069eaf7c5238a854f4843e3", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 95, "max_issues_repo_issues_event_min_datetime": "2016-09-13T15:16:54.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-23T14:08:27.000Z", "max_forks_repo_path": "libRALFit/example/Fortran/nlls_example.f90", "max_forks_repo_name": "andpic/RALFit", "max_forks_repo_head_hexsha": "d8bd77217b5163f79069eaf7c5238a854f4843e3", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-04-02T12:24:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-23T17:12:42.000Z", "avg_line_length": 30.9112903226, "max_line_length": 88, "alphanum_fraction": 0.5510044352, "num_tokens": 1291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002492, "lm_q2_score": 0.8633916152464017, "lm_q1q2_score": 0.7978962950605198}} {"text": "! This file is provided as part of the \"projet long\" for the \"Calcul Scientifique et Analyse de Données\" course\n! at INP-ENSEEIHT\n! Date: 02/2019\n! Authors: P. Amestoy, P. Berger, A. Buttari, Y. Diouane, S. Gratton, R. Guivarch, F.H. Rouet, E. Simon\n!\n! This file contains the implementation of\n! - one routine for computing the eigenpairs of a symmetric matrix with the deflated power method\n!--------------------------------------------------------------------------------------------------------------------\n\n!! deflated_power_method\n! ---------------------\n!\n! routine that computes a certain amount of eigenvalues and eigenvectors of a matrix A\n! using the deflated power method\n!\n! ..Input arguments\n! n : integer, size of the matrix A\n! m : integer, maximum number of searched eigenvalues\n! a : double precision matrix\n!\n! percentage : double precision, fraction of the trace we would like to obtain\n!\n! maxit : integer, maximum number of iterations of the power method\n! eps : the tolerance for the stopping criterion of the power method\n\n! ..Output arguments\n! w : double precision vector, the eigenvalues\n! v : double precision matrix, the corresponding eigenvectors\n! n_ev : integer, the number of computed eigenvalues\n! acc_ev : double precision vector, residual for each eigenvalues\n! it_ev : integer vector, number of iterations for each eigenvalues\n!\n! ierr : integer, indicates how the routine ends\n! O : OK\n! 1 : the maximum number of eigenvalues is reached before obtaining the percentage (WARNING)\n! -1 : inconsistancy of the values of the arguments (ERROR)\n! -2 : allocation problem (ERROR)\n! -3 : maxit reached (ERROR)\n!--------------------------------------------------------------------------------------------------------------------\n subroutine deflated_power_method(n, m, a, percentage, maxit, eps, w, v, n_ev, acc_ev, it_ev, ierr)\n implicit none\n !! the subspace dimensions\n integer, intent(in) :: n, m\n !! the target matrix (symetric)\n double precision, dimension(n,n), intent(in) :: a\n !! the percentage of the trace we want to obtain\n double precision, intent(in) :: percentage\n !! maximum # of iteration\n integer, intent(in) :: maxit\n !! the tolerance for the stopping criterion\n double precision, intent(in) :: eps\n !! the m dominant eigenvalues\n double precision, dimension(m), intent(out) :: w\n !! the m associated eigenvectors\n double precision, dimension(n, m), intent(out) :: v\n !! number of computed eigenvalues\n integer, intent(out) :: n_ev\n !! residual for each eigenvalues\n double precision, dimension(m), intent(out) :: acc_ev\n !! number of iterations for each eigenvalues\n integer, dimension(m), intent(out) :: it_ev\n !! a flag for signaling errors\n integer, intent(out) :: ierr\n\n ! external functions\n double precision, external :: dnrm2 ! two-norm\n double precision, external :: ddot ! scalar product\n double precision, external :: dlange \n \n ! constants\n integer, parameter :: ione = 1\n double precision, parameter :: done = 1.d0, dzero = 0.d0\n\n ! local variables\n integer :: i, j, conv, k\n double precision, allocatable, dimension(:) :: y ! work vector\n double precision :: beta, moins_beta\n double precision :: norme, normeA\n double precision :: trace, eig_sum\n double precision :: alpha\n\n ierr = 0\n !! check the parameter consistancy\n if((percentage.gt.1d0) .or. (percentage.lt.0d0)) then\n ierr = -1\n return\n end if\n if(m.gt.n) then\n ierr = -1\n return\n end if\n \n !! compute the trace\n trace = 0.d0\n do i=1, n\n trace = trace + a(i,i)\n end do\n\n !! work vector\n allocate(y(n), stat=ierr)\n if(ierr .ne. 0) then\n ierr = -2\n return\n end if\n\n eig_sum = 0.D0\n n_ev = 0\n i = 0\n\n do while((i.lt.m).and.(eig_sum/trace.le.percentage))\n\n i = i + 1\n\n !! Frobenius Norm of A\n normeA = dlange('f', n, n, a, n, y )\n\n !! power method\n\n k = 0\n conv = 0\n \n !! x_0 random\n call random_number(v(:,i))\n\n do while((conv.eq.0).and.(k.lt.maxit))\n\n !! y_k+1 = A*x_k\n call dgemv('n', n, n, done, a, n, v(1,i), ione, dzero, y, ione)\n \n !! x_k+1 = y_k+1 / ||y_k+1||\n norme = dnrm2(n, y, ione)\n v(:,i) = y/norme\n \n !! beta_k+1 = x-k+1^T A X_k+1\n call dgemv('n', n, n, done, a, n, v(1,i), ione, dzero, y, ione)\n beta = ddot(n, v(1,i), ione, y, ione)\n moins_beta = - beta\n\n !! norm introduced in 2.1.2\n !! ||beta*x_k - A*x_k||/||A|| < eps\n ! v(:,i) contains x_k\n ! y contains A*x_k\n ! y <- y - beta * v(:,i)\n call daxpy(n, moins_beta, v(1,i), ione, y, ione)\n norme = dnrm2(n, y, ione)/normeA\n\n if(norme.le.eps) conv = 1\n\n k = k + 1\n write(*,'(\" IT:\",i5,\" -- Accuracy is: \",es10.2,a)',advance='no') k, norme, char(13)\n\n end do\n\n if(k.ge.maxit) then\n ierr = -3\n return\n end if\n\n w(i) = beta\n it_ev(i) = k\n acc_ev(i) = norme\n eig_sum = eig_sum + w(i)\n write(*,'(\"Eigenvalue \",i4,\":\",f10.3)') i, w(i)\n\n !! deflation\n !! A <- A - beta * v(:,i)^T * v(:,i)\n if(i.lt.n) then\n ! BLAS routine DGER\n ! A <- - beta * v(:,i)^T * v(:,i) + A\n call DGER(n, n, moins_beta, v(1,i), ione, v(1,i), ione, A, n)\n end if\n\n end do\n\n !! number max of eigenvalues reached\n if(eig_sum/trace.le.percentage) ierr = 1\n\n n_ev = i\n\n deallocate(y)\n \n return\n\n end subroutine deflated_power_method\n", "meta": {"hexsha": "eb14a1415f83fe0602b2fdcc9e847408f21469a3", "size": 6323, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Projects/Eigenfaces/2 - Calcul des couples propres/Code Fortran+matlab/Fortran/power_v11.f90", "max_stars_repo_name": "faicaltoubali/ENSEEIHT", "max_stars_repo_head_hexsha": "6db0aef64d68446b04f17d1eae574591026002b5", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-05-02T12:32:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-12T20:20:35.000Z", "max_issues_repo_path": "Projects/Eigenfaces/2 - Calcul des couples propres/Code Fortran+matlab/Fortran/power_v11.f90", "max_issues_repo_name": "faicaltoubali/ENSEEIHT", "max_issues_repo_head_hexsha": "6db0aef64d68446b04f17d1eae574591026002b5", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-01-14T20:03:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-30T01:10:00.000Z", "max_forks_repo_path": "Projects/Eigenfaces/2 - Calcul des couples propres/Code Fortran+matlab/Fortran/power_v11.f90", "max_forks_repo_name": "faicaltoubali/ENSEEIHT", "max_forks_repo_head_hexsha": "6db0aef64d68446b04f17d1eae574591026002b5", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-11-11T21:28:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-19T13:54:22.000Z", "avg_line_length": 34.1783783784, "max_line_length": 117, "alphanum_fraction": 0.5122568401, "num_tokens": 1674, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.8633916011860785, "lm_q1q2_score": 0.7978962838706313}} {"text": "C\nC file tblktri.f\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC * *\nC * copyright (c) 1999 by UCAR *\nC * *\nC * UNIVERSITY CORPORATION for ATMOSPHERIC RESEARCH *\nC * *\nC * all rights reserved *\nC * *\nC * FISHPACK version 4.1 *\nC * *\nC * A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE SOLUTION OF *\nC * *\nC * SEPARABLE ELLIPTIC PARTIAL DIFFERENTIAL EQUATIONS *\nC * *\nC * BY *\nC * *\nC * JOHN ADAMS, PAUL SWARZTRAUBER AND ROLAND SWEET *\nC * *\nC * OF *\nC * *\nC * THE NATIONAL CENTER FOR ATMOSPHERIC RESEARCH *\nC * *\nC * BOULDER, COLORADO (80307) U.S.A. *\nC * *\nC * WHICH IS SPONSORED BY *\nC * *\nC * THE NATIONAL SCIENCE FOUNDATION *\nC * *\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC\nC PROGRAM TO ILLUSTRATE THE USE OF SUBROUTINE BLKTRI TO\nC SOLVE THE EQUATION\nC\nC .5/S*(D/DS)(.5/S*DU/DS)+.5/T*(D/DT)(.5/T*DU/DT)\nC (1)\nC = 15/4*S*T*(S**4+T**4)\nC\nC ON THE RECTANGLE 0 .LT. S .LT. 1 AND 0 .LT. T .LT. 1\nC WITH THE BOUNDARY CONDITIONS\nC\nC U(0,T) = 0\nC 0 .LE. T .LE. 1\nC U(1,T) = T**5\nC\nC AND\nC\nC U(S,0) = 0\nC 0 .LE. S .LE. 1\nC U(S,1) = S**5\nC\nC THE EXACT SOLUTION OF THIS PROBLEM IS U(S,T) = (S*T)**5\nC\nC DEFINE THE INTEGERS M = 50 AND N = 63. THEN DEFINE THE\nC GRID INCREMENTS DELTAS = 1/(M+1) AND DELTAT = 1/(N+1).\nC\nC THE GRID IS THEN GIVEN BY S(I) = I*DELTAS FOR I = 1,...,M\nC AND T(J) = J*DELTAT FOR J = 1,...,N.\nC\nC THE APPROXIMATE SOLUTION IS GIVEN AS THE SOLUTION TO\nC THE FOLLOWING FINITE DIFFERENCE APPROXIMATION OF EQUATION (1).\nC\nC .5/(S(I)*DELTAS)*((U(I+1,J)-U(I,J))/(2*S(I+.5)*DELTAS)\nC -(U(I,J)-U(I-1,J))/(2*S(I-.5)*DELTAS))\nC +.5/(T(I)*DELTAT)*((U(I,J+1)-U(I,J))/(2*T(I+.5)*DELTAT) (2)\nC -(U(I,J)-U(I,J-1))/(2*T(I-.5)*DELTAT))\nC = 15/4*S(I)*T(J)*(S(I)**4+T(J)**4)\nC\nC WHERE S(I+.5) = .5*(S(I+1)+S(I))\nC S(I-.5) = .5*(S(I)+S(I-1))\nC T(I+.5) = .5*(T(I+1)+T(I))\nC T(I-.5) = .5*(T(I)+T(I-1))\nC\nC THE APPROACH IS TO WRITE EQUATION (2) IN THE FORM\nC\nC AM(I)*U(I-1,J)+BM(I,J)*U(I,J)+CM(I)*U(I+1,J)\nC +AN(J)*U(I,J-1)+BN(J)*U(I,J)+CN(J)*U(I,J+1) (3)\nC = Y(I,J)\nC\nC AND THEN CALL SUBROUTINE BLKTRI TO DETERMINE U(I,J)\nC\nC\nC\n DIMENSION Y(75,105) ,AM(75) ,BM(75) ,CM(75) ,\n 1 AN(105) ,BN(105) ,CN(105) ,W(823) ,\n 2 S(75) ,T(105)\nC\n IFLG = 0\n NP = 1\n N = 63\n MP = 1\n M = 50\n IDIMY = 75\nC\nC GENERATE AND STORE GRID POINTS FOR THE PURPOSE OF COMPUTING THE\nC COEFFICIENTS AND THE ARRAY Y.\nC\n DELTAS = 1./FLOAT(M+1)\n DO 101 I=1,M\n S(I) = FLOAT(I)*DELTAS\n 101 CONTINUE\n DELTAT = 1./FLOAT(N+1)\n DO 102 J=1,N\n T(J) = FLOAT(J)*DELTAT\n 102 CONTINUE\nC\nC COMPUTE THE COEFFICIENTS AM,BM,CM CORRESPONDING TO THE S DIRECTION\nC\n HDS = DELTAS/2.\n TDS = DELTAS+DELTAS\n DO 103 I=1,M\n TEMP1 = 1./(S(I)*TDS)\n TEMP2 = 1./((S(I)-HDS)*TDS)\n TEMP3 = 1./((S(I)+HDS)*TDS)\n AM(I) = TEMP1*TEMP2\n CM(I) = TEMP1*TEMP3\n BM(I) = -(AM(I)+CM(I))\n 103 CONTINUE\nC\nC COMPUTE THE COEFFICIENTS AN,BN,CN CORRESPONDING TO THE T DIRECTION\nC\n HDT = DELTAT/2.\n TDT = DELTAT+DELTAT\n DO 104 J=1,N\n TEMP1 = 1./(T(J)*TDT)\n TEMP2 = 1./((T(J)-HDT)*TDT)\n TEMP3 = 1./((T(J)+HDT)*TDT)\n AN(J) = TEMP1*TEMP2\n CN(J) = TEMP1*TEMP3\n BN(J) = -(AN(J)+CN(J))\n 104 CONTINUE\nC\nC COMPUTE RIGHT SIDE OF EQUATION\nC\n DO 106 J=1,N\n DO 105 I=1,M\n Y(I,J) = 3.75*S(I)*T(J)*(S(I)**4+T(J)**4)\n 105 CONTINUE\n 106 CONTINUE\nC\nC THE NONZERO BOUNDARY CONDITIONS ENTER THE LINEAR SYSTEM VIA\nC THE RIGHT SIDE Y(I,J). IF THE EQUATIONS (3) GIVEN ABOVE\nC ARE EVALUATED AT I=M AND J=1,...,N THEN THE TERM CM(M)*U(M+1,J)\nC IS KNOWN FROM THE BOUNDARY CONDITION TO BE CM(M)*T(J)**5.\nC THEREFORE THIS TERM CAN BE INCLUDED IN THE RIGHT SIDE Y(M,J).\nC THE SAME ANALYSIS APPLIES AT J=N AND I=1,..,M. NOTE THAT THE\nC CORNER AT J=N,I=M INCLUDES CONTRIBUTIONS FROM BOTH BOUNDARIES.\nC\n DO 107 J=1,N\n Y(M,J) = Y(M,J)-CM(M)*T(J)**5\n 107 CONTINUE\n DO 108 I=1,M\n Y(I,N) = Y(I,N)-CN(N)*S(I)**5\n 108 CONTINUE\nC\nC DETERMINE THE APPROXIMATE SOLUTION U(I,J)\nC\n 109 CALL BLKTRI (IFLG,NP,N,AN,BN,CN,MP,M,AM,BM,CM,IDIMY,Y,IERROR,W)\n IFLG = IFLG+1\n IF (IFLG-1) 109,109,110\nC\nC COMPUTE DISCRETIZATION ERROR\nC\n 110 ERR = 0.\n DO 112 J=1,N\n DO 111 I=1,M\n Z = ABS(Y(I,J)-(S(I)*T(J))**5)\n IF (Z .GT. ERR) ERR = Z\n 111 CONTINUE\n 112 CONTINUE\n IW = INT(W(1))\n PRINT 1001 , IERROR,ERR,IW\n STOP\nC\n 1001 FORMAT (1H1,20X,25HSUBROUTINE BLKTRI EXAMPLE,//\n 1 10X,\"** important for TBLKTRI example: to avoid **\",/\n 2 10X,\"** large discretization error, compile it **\",/\n 3 10X,\"** and FISHPACK routines in double precision **\",///\n 4 10X,46HTHE OUTPUT FROM THE NCAR CONTROL DATA 7600 WAS//\n 5 32X,10HIERROR = 0/\n 6 18X,34HDISCRETIZATION ERROR = 1.64478E-05/\n 7 12X,32HREQUIRED LENGTH OF W ARRAY = 823//\n 8 10X,32HTHE OUTPUT FROM YOUR COMPUTER IS//\n 9 32X,8HIERROR =,I2/18X,22HDISCRETIZATION ERROR =,E12.5/\n 1 12X,28HREQUIRED LENGTH OF W ARRAY =,I4)\nC\n END\n", "meta": {"hexsha": "0b7bf515395adb7565d13c488440df8cdbcd6339", "size": 7002, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/test/tblktri.f", "max_stars_repo_name": "ipelupessy/omuse", "max_stars_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2020-03-25T10:02:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T00:28:35.000Z", "max_issues_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/test/tblktri.f", "max_issues_repo_name": "ipelupessy/omuse", "max_issues_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 45, "max_issues_repo_issues_event_min_datetime": "2020-03-03T16:07:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T09:01:07.000Z", "max_forks_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/test/tblktri.f", "max_forks_repo_name": "ipelupessy/omuse", "max_forks_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-03-03T13:28:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T09:20:02.000Z", "avg_line_length": 36.6596858639, "max_line_length": 72, "alphanum_fraction": 0.4075978292, "num_tokens": 2306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140233, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7978919492407819}} {"text": "!> Sigmoid func & gate\nprogram main\n\n use auto_diff, only: sigmoid\n use auto_diff, only: tree_t, rk, assignment(=)\n use auto_diff, only: operator(*), operator(+)\n implicit none\n type(tree_t) :: w0, w1, w2, x0, x1\n type(tree_t) :: y\n \n w0 = 2.0_rk\n w1 = -3.0_rk\n w2 = -3.0_rk\n x0 = -1.0_rk\n x1 = -2.0_rk\n\n print *, \"sigmoid demo: y = 1/(1 + exp(-z)), z = w0*x0 + w1*x1 + w2\"\n y = sigmoid(w0*x0 + w1*x1 + w2)\n\n print *, \"y = \", y%get_value() ! should be 0.73\n call y%backward()\n\n print *, \"dy/dw0 = \", w0%get_grad() ! should be -0.20\n print *, \"dy/dw1 = \", w1%get_grad() ! should be -0.39\n print *, \"dy/dw2 = \", w2%get_grad() ! should be 0.20\n print *, \"dy/dx0 = \", x0%get_grad() ! should be 0.39\n print *, \"dy/dx1 = \", x1%get_grad() ! should be -0.59\n\nend program main\n\n!> sigmoid demo: y = 1/(1 + exp(-z), z = w0*x0 + w1*x1 + w2\n!> y = 0.73105857863000490 \n!> dy/dw0 = -0.19661193324148185\n!> dy/dw1 = -0.39322386648296370\n!> dy/dw2 = 0.19661193324148185\n!> dy/dx0 = 0.39322386648296370\n!> dy/dx1 = -0.58983579972444555\n", "meta": {"hexsha": "afdd7aab83dcd805dd07530946e881fac2c798d0", "size": 1109, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo2.f90", "max_stars_repo_name": "zoziha/Auto-Diff", "max_stars_repo_head_hexsha": "35e62246675cbe6dcd04ce25a81f7885653feabe", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-11-25T13:38:15.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-25T04:14:44.000Z", "max_issues_repo_path": "example/demo2.f90", "max_issues_repo_name": "zoziha/Auto-Diff", "max_issues_repo_head_hexsha": "35e62246675cbe6dcd04ce25a81f7885653feabe", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-24T20:39:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T12:53:58.000Z", "max_forks_repo_path": "example/demo2.f90", "max_forks_repo_name": "zoziha/Auto-Diff", "max_forks_repo_head_hexsha": "35e62246675cbe6dcd04ce25a81f7885653feabe", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.1842105263, "max_line_length": 72, "alphanum_fraction": 0.5563570784, "num_tokens": 478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850039701653, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.7976706343330144}} {"text": "\nsubmodule (stdlib_quadrature) stdlib_quadrature_trapz\n use stdlib_error, only: check\n implicit none\n\ncontains\n\n \n pure module function trapz_dx_dp(y, dx) result(integral)\n real(dp), dimension(:), intent(in) :: y\n real(dp), intent(in) :: dx\n real(dp) :: integral\n\n integer :: n\n\n n = size(y)\n \n select case (n)\n case (0:1)\n integral = 0.0_dp\n case (2)\n integral = 0.5_dp*dx*(y(1) + y(2))\n case default\n integral = dx*(sum(y(2:n-1)) + 0.5_dp*(y(1) + y(n)))\n end select\n end function trapz_dx_dp\n \n\n module function trapz_x_dp(y, x) result(integral)\n real(dp), dimension(:), intent(in) :: y\n real(dp), dimension(:), intent(in) :: x\n real(dp) :: integral\n\n integer :: i\n integer :: n\n\n n = size(y)\n call check(size(x) == n, \"trapz: Arguments `x` and `y` must be the same size.\")\n\n select case (n)\n case (0:1)\n integral = 0.0_dp\n case (2)\n integral = 0.5_dp*(x(2) - x(1))*(y(1) + y(2))\n case default\n integral = 0.0_dp\n do i = 2, n\n integral = integral + (x(i) - x(i-1))*(y(i) + y(i-1))\n end do\n integral = 0.5_dp*integral\n end select\n end function trapz_x_dp\n\n\n pure module function trapz_weights_dp(x) result(w)\n real(dp), dimension(:), intent(in) :: x\n real(dp), dimension(size(x)) :: w\n\n integer :: i\n integer :: n\n\n n = size(x)\n\n select case (n)\n case (0)\n ! no action needed\n case (1)\n w(1) = 0.0_dp\n case (2)\n w = 0.5_dp*(x(2) - x(1))\n case default\n w(1) = 0.5_dp*(x(2) - x(1))\n w(n) = 0.5_dp*(x(n) - x(n-1))\n do i = 2, size(x)-1\n w(i) = 0.5_dp*(x(i+1) - x(i-1))\n end do\n end select\n end function trapz_weights_dp\n\nend submodule stdlib_quadrature_trapz\n", "meta": {"hexsha": "17c3291c262b78ff90f8ab8f0e2fbcf852a8af4d", "size": 2030, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stdlib_quadrature_trapz.f90", "max_stars_repo_name": "zoziha/dp-stdlib", "max_stars_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-12-08T04:45:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-09T11:42:41.000Z", "max_issues_repo_path": "src/stdlib_quadrature_trapz.f90", "max_issues_repo_name": "zoziha/dp-stdlib", "max_issues_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-12-08T12:35:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-17T02:33:12.000Z", "max_forks_repo_path": "src/stdlib_quadrature_trapz.f90", "max_forks_repo_name": "zoziha/dp-stdlib", "max_forks_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-09T01:54:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T01:54:34.000Z", "avg_line_length": 25.0617283951, "max_line_length": 87, "alphanum_fraction": 0.4778325123, "num_tokens": 614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.8740772384450967, "lm_q1q2_score": 0.7975396710820749}} {"text": "program calculadora\n implicit none\n integer :: menu,f,i\n real :: a,b,c,d\n ! coeficientes de la ecuación\n real :: discr, discr2, discr3, discr4\n ! discriminantes de la ecuación\n real :: x1,x2,z1\n ! variables para las posibles soluciones soluciones\n real :: term, den\n real(kind=8) :: facto\n complex:: z2,z3,part1\n\n print*, \"Elija el numero de las siguientes opciones para realizar una operación\"\n print*, \"realizar una ecuación cuadratica de la forma ax²+bx+c=0 --------------(1)\"\n print*, \"realizar una ecuación de tercer grado de la forma ax³+bx²+cx+d=0 ----(2)\"\n print*, \"obtener el factorial de un numero entero -----------------------------(3)\"\n\n read*, menu\n call system (\"cis\")\n select case (menu)\n\n\n case (1)\n ! Entrada de datos\n write (*,*) \"Ingrese coeficientes a,b,c de una ecuacion de la forma ax²+bx+c=0 con una coma entre ellos ejemplo: 4,9,6\"\n read(*,*) a,b,c\n if( a == 0 ) then\n write(*,*) \"La ecuación no tiene término cuadrático\"\n stop\n endif\n\n ! Bloque de procesamiento y salida\n discr = b**2 - 4.0*a*c\n den = 2.0*a\n term = sqrt(abs(discr))\n if (discr >= 0 ) then\n x1 = (-b+term)/den\n x2 = (-b-term)/den\n print*, \"a continuación se muestran las raices de la ecuación\"\n write(*,*) \"x1 = \", x1\n write(*,*) \"x2 = \", x2\n else\n x1 = -b/den\n x2 = term/den\n print*, \"a continuación se muestran las raices con su parte real e imaginaria\"\n write(*,*) \"x1 = (\", x1, \" ,\", x2, \")\"\n write(*,*) \"x1 = (\", x1, \" ,\", -x2, \")\"\n endif\n stop\n\n case (2)\n write (*,*) \"Ingrese coeficientes a,b,c,d de una ecuacion de la forma ax³+bx²+cx+d=0 ejemplo: 2,6,3,8\"\n read(*,*) a,b,c,d\n part1 = -b/3*a\n discr2= -(b**2) + 3*a*c\n discr3= -2*(b**3) + 9*a*b*c - (27*(a**2))*d\n discr4=(discr3 + sqrt(4*(discr2**3)+discr3**2))**(1/3)\n z1=part1+(((2**1/3)*discr2)/(discr4*3*a))+discr4/(a*(32**(1/3)))\n z2=part1+(((1+i*(3**(1/2)))*discr2)/(a*(32**(2/3))*discr4))-((discr4*(1-i*(3**(1/2))))/(a*(62**1/3)))\n z3=part1+(((1-i*(3**(1/2)))*discr2)/(a*(32**(2/3))*discr4))-((discr4*(1+i*(3**(1/2))))/(a*(62**1/3)))\n write(*,*) \"z1 = \", z1\n write(*,*) \"z2 = \", z2\n write(*,*) \"z3 = \", z3\n stop\n\n case (3)\n print*, \"este programa calcula el factorial de cualquier numero entero\"\n print*, \"Ingrese un numero entero\"\n read*, i\n f=1\n facto=0\n do while(f<=i)\n facto=i*(i-1)+facto\n f=f+1\n end do\n print*, facto\n\n case default\n print*, \"entrada incorrecta\"\n\n end select\nend program calculadora\n", "meta": {"hexsha": "44679c72d7ee20556fe24587ce9859ca9f62a61f", "size": 2562, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "calculadora.f90", "max_stars_repo_name": "Angelpacman/fundamentos-de-fortran", "max_stars_repo_head_hexsha": "041bc92a948d8d48db39a9eef50d0035cd1aeb0c", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calculadora.f90", "max_issues_repo_name": "Angelpacman/fundamentos-de-fortran", "max_issues_repo_head_hexsha": "041bc92a948d8d48db39a9eef50d0035cd1aeb0c", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calculadora.f90", "max_forks_repo_name": "Angelpacman/fundamentos-de-fortran", "max_forks_repo_head_hexsha": "041bc92a948d8d48db39a9eef50d0035cd1aeb0c", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.5, "max_line_length": 123, "alphanum_fraction": 0.5565964091, "num_tokens": 968, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947055100816, "lm_q2_score": 0.8438951104066295, "lm_q1q2_score": 0.7974764113401106}} {"text": "! Lagrange polynomial basis \n\nsubroutine lagrange_basis_values(center, xi, phi)\n use ader_weno\n implicit none\n ! Argument list\n integer, intent(IN) :: center\n double precision, intent(IN) :: xi\n double precision, intent(OUT) :: phi(0:N)\n ! Local variables \n integer :: i, k\n double precision :: lagrange_weight, tmp_lagrange_weight, v, k_faculty\n \n tmp_lagrange_weight = 1.0d0\n k_faculty = 1.0d0\n\n ! First find the denominator \n \n do i = 1, N+1\n if (i .ne. center) then\n tmp_lagrange_weight = tmp_lagrange_weight*(xGP(center) - xGP(i))\n end if\n end do\n \n lagrange_weight = 1.0d0/tmp_lagrange_weight\n \n phi(0) = 1.0d0\n \n do i = 1, N\n phi(i) = 0.0d0\n end do\n \n do i = 0, N\n if (i+1 .ne. center) then\n v = xi - xGP(i+1)\n do k = N, 1, -1\n phi(k) = (phi(k)*v + phi(k - 1));\n end do\n phi(0) = phi(0)*v;\n end if\n end do\n \n do k = 0, N\n phi(k) = phi(k)*k_faculty*lagrange_weight\n k_faculty = k_faculty*dble(k+1)\n end do\n \nend subroutine lagrange_basis_values\n\n\nsubroutine BaseFunc1D(phi,phi_xi,xi)\n use ader_weno\n implicit none\n ! Argument list\n double precision, intent(in ) :: xi ! coordinate in [0,1] where to evaluate the basis\n double precision, intent(out) :: phi(N+1), phi_xi(N+1) ! the basis and its derivative w.r.t. xi\n ! Local variables\n integer :: i,j,m\n double precision :: tmp\n !\n ! Initialize variables\n phi = 1.0d0\n phi_xi = 0.0d0\n ! Lagrange polynomial and its derivative\n do m = 1, N+1\n do j = 1, N+1\n if (j .eq. m) cycle\n phi(m) = phi(m)*(xi-xGP(j))/(xGP(m)-xGP(j))\n end do\n\n do i = 1, N+1\n if( i .EQ. m) cycle\n tmp = 1.0d0\n do j = 1, N+1\n if( j .eq. i) cycle\n if( j .eq. m) cycle\n tmp = tmp*(xi-xGP(j))/(xGP(m)-xGP(j))\n end do\n phi_xi(m) = phi_xi(m) + tmp/(xGP(m)-xGP(i))\n end do\n end do\n\nend subroutine BaseFunc1D\n", "meta": {"hexsha": "7b08256aa53785e3572671e9cf46f4d3f258299b", "size": 2125, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ADER-WENO-1D-LINEAR-CONVECTION/basis.f90", "max_stars_repo_name": "dasikasunder/ADER-WENO", "max_stars_repo_head_hexsha": "8d40b341be7610ac89a144077a9f759a0154909a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-19T07:50:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-19T07:50:53.000Z", "max_issues_repo_path": "ADER-WENO-1D-LINEAR-CONVECTION/basis.f90", "max_issues_repo_name": "dasikasunder/ADER-WENO", "max_issues_repo_head_hexsha": "8d40b341be7610ac89a144077a9f759a0154909a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ADER-WENO-1D-LINEAR-CONVECTION/basis.f90", "max_forks_repo_name": "dasikasunder/ADER-WENO", "max_forks_repo_head_hexsha": "8d40b341be7610ac89a144077a9f759a0154909a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.2976190476, "max_line_length": 117, "alphanum_fraction": 0.5308235294, "num_tokens": 704, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362489, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.797378374267887}} {"text": "! Triangle, pentagonal, and hexagonal numbers \n! are generated by the following\n! formulae:\n\n! Triangle Tn=n(n+1)/2 1, 3, 6, 10, 15, ...\n! Pentagonal Pn=n(3n-1)/2 1, 5, 12, 22, 35, ...\n! Hexagonal Hn=n(2n-1) 1, 6, 15, 28, 45, ...\n\n! It can be verified that:\n! T[285] = P[165] = H[143] = 40755.\n\n! Find the next triangle number that\n! is also pentagonal and hexagonal.\n\n! Project Euler: 45\n\n! Answer: 1533776805 \n\nprogram main\n\nuse euler\n\nimplicit none\n\n\n integer (int64), parameter :: START = 40755;\n integer (int64) :: n, tri;\n\n n = START;\n\n do while(.TRUE.)\n\n tri = n;\n call triangle(tri);\n\n if(pentagonal(tri) .AND. hexagonal(tri)) then\n exit\n endif\n\n call inc(n, 1_int64);\n\n end do\n\n call printint(tri);\n\n\ncontains\n\n\n pure subroutine triangle(n)\n\n integer (int64), intent(inout) :: n;\n n = (n ** 2 - n) / 2;\n\n end subroutine triangle\n\n\n ! Utilise the fact that we can test if a number is pentagonal or not by\n ! using: 24x + 1 == y;\n ! Where y is a perfect square. AND, for non generalised solutions of\n ! n >= 0, we also must qualify that (24x + 1)**0.5 % 6 == 5\n\n pure function pentagonal(x)\n\n integer (int64), intent(in) :: x;\n integer (int64) :: tmp;\n logical :: pentagonal;\n\n tmp = 24 * x + 1;\n \n pentagonal = (perfect_square(tmp) .AND. &\n mod(int(sqrt(real(tmp))), 6) == 5)\n\n end function pentagonal\n\n\n pure function hexagonal(x)\n\n integer (int64), intent(in) :: x;\n logical :: hexagonal;\n real :: tmp;\n\n tmp = (sqrt(real(8 * x + 1)) + 1) / 4;\n hexagonal = is_natural(tmp)\n\n end function hexagonal\n\n\nend program main\n\n", "meta": {"hexsha": "63ea06bb209c3756569e1771fc48398b823028b1", "size": 1977, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/tri_pent_hex.f95", "max_stars_repo_name": "guynan/project_euler", "max_stars_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-03-08T09:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T13:52:49.000Z", "max_issues_repo_path": "fortran/tri_pent_hex.f95", "max_issues_repo_name": "guynan/project_euler", "max_issues_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-11-03T01:20:46.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-24T22:54:59.000Z", "max_forks_repo_path": "fortran/tri_pent_hex.f95", "max_forks_repo_name": "guynan/project_euler", "max_forks_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-11-03T01:14:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T13:52:51.000Z", "avg_line_length": 21.7252747253, "max_line_length": 79, "alphanum_fraction": 0.4936772888, "num_tokens": 543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632316144274, "lm_q2_score": 0.8376199694135333, "lm_q1q2_score": 0.7972996509507437}} {"text": "! HOW TO COMPILE THROUGH COMMAND LINE (CMD OR TERMINAL)\n! gfortran -c newton_raphson.f95\n! gfortran -o newton_raphson newton_raphson.o\n!\n! The program is open source and can use to numeric study purpose.\n! The program was build by Aulia Khalqillah,S.Si., M.Si\n!\n! email: auliakhalqillah.mail@gmail.com\n! ==============================================================================\nprogram newton\nimplicit none\n\ninteger :: iter,info\nreal :: limiterror = 1.0e-6\nreal :: x,f,df,error,xr,xrold\nreal :: start, finish\ncharacter(len=100) :: fmt\n\n\nwrite(*,*)\"\"\nwrite(*,*)\"---------------------------------\"\nwrite(*,*)\"NEWTON'S METHOD - FINDING ROOT\"\nwrite(*,*)\"---------------------------------\"\nwrite(*,*) \"\"\n\nwrite (*,\"(a)\",advance='no') \"Masukan tebakan awal:\"\nread *, x\n\nfmt = \"(a12,a13,a13,a13)\"\nwrite (*,*) \"\"\nwrite(*,fmt)\"ITER\",\"X[ROOT]\",\"F(X)\",\"INFO\"\ncall cpu_time(start)\n! start process\nopen(unit=1, file='newtonraphson.txt', status='replace')\n iter = 1\n info = 0\n ! Calculate initial root estimation\n xr = x - (f(x)/df(x))\n xrold = x\n x = xr\n error = abs((xr - xrold)/xr) * 100\n if ((error < limiterror) .or. isnan(xr)) then\n x = xrold\n info = 1\n error = 0\n write (*,*) iter, x, f(x), info, error\n write (1,*) iter, x, f(x), info, error\n else \n ! Calculate the next root estimation when error > limit of error\n do while (error > limiterror)\n xr = x - (f(x)/df(x))\n xrold = x\n x = xr\n\n if (xr == 0) then\n error = 100\n else \n error = abs((xr - xrold)/xr) * 100\n end if \n \n if (abs(f(x)) < limiterror) then\n info = 1\n else\n info = 0\n end if\n ! Write the result on terminal display and save it to file\n if (isnan(error)) then\n exit\n else\n write (*,*) iter, x, f(x), info, error\n write (1,*) iter, x, f(x), info, error\n ! update to next iteration\n iter = iter + 1\n end if\n end do\n end if\nclose(1)\ncall cpu_time(finish)\nprint '(\"Time = \",f12.8,\" seconds.\")',finish-start\nend program \n\nfunction f(x)\nreal :: f, x\nf = (x**2)-(2*x)+1\nend function\n\nfunction df(x)\nreal :: df, x\ndf = (2*x)-2\nend function \n\n\n", "meta": {"hexsha": "fd6f262386bf069db156065a860992324e802577", "size": 2500, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "newton_raphson.f90", "max_stars_repo_name": "auliakhalqillah/Newton-sMethod", "max_stars_repo_head_hexsha": "1755c301d816816416d887a6bc3a5571d3c707b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "newton_raphson.f90", "max_issues_repo_name": "auliakhalqillah/Newton-sMethod", "max_issues_repo_head_hexsha": "1755c301d816816416d887a6bc3a5571d3c707b1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "newton_raphson.f90", "max_forks_repo_name": "auliakhalqillah/Newton-sMethod", "max_forks_repo_head_hexsha": "1755c301d816816416d887a6bc3a5571d3c707b1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.8817204301, "max_line_length": 80, "alphanum_fraction": 0.4724, "num_tokens": 689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767938900121, "lm_q2_score": 0.9086178944582997, "lm_q1q2_score": 0.7972911169003621}} {"text": "SUBROUTINE invmtx(a,b,deter,nsize)\r\n!***********************************************************************\r\n!\r\n!***this routine inverts a square matrix \"a\"\r\n!\r\n! a - given nsize*nsize matrix\r\n! b - inverse of \"a\"\r\n! nsize - matrix size\r\n!\r\n!***********************************************************************\r\nIMPLICIT NONE\r\nINTEGER (kind=4),INTENT(IN) :: nsize\r\nREAL (kind=8),INTENT(IN) :: a(nsize,nsize)\r\nREAL (kind=8),INTENT(OUT):: b(nsize,nsize),deter\r\n\r\nREAL (kind=8) :: denom,t1,t2,t3,t4\r\n\r\nSELECT CASE (nsize)\r\nCASE (1)\r\n !***inverse of a 1*1 matrix\r\n deter=a(1,1)\r\n IF(deter == 0d0) RETURN\r\n b(1,1) = 1d0/a(1,1)\r\n\r\nCASE (2)\r\n !***inverse of a 2*2 matrix\r\n deter = a(1,1)*a(2,2)-a(2,1)*a(1,2)\r\n IF(deter == 0d0) RETURN\r\n b(1,1) = a(2,2)/deter\r\n b(2,2) = a(1,1)/deter\r\n b(2,1) =-a(2,1)/deter\r\n b(1,2) =-a(1,2)/deter\r\n\r\nCASE (3)\r\n !*** inverse of a 3*3 matrix\r\n t1 = a(2,2)*a(3,3) - a(3,2)*a(2,3)\r\n t2 =-a(2,1)*a(3,3) + a(3,1)*a(2,3)\r\n t3 = a(2,1)*a(3,2) - a(3,1)*a(2,2)\r\n deter = a(1,1)*t1 + a(1,2)*t2 + a(1,3)*t3\r\n IF(deter == 0d0) RETURN\r\n b(1,1) = t1/deter\r\n b(2,1) = t2/deter\r\n b(3,1) = t3/deter\r\n b(2,2) = ( a(1,1)*a(3,3) - a(3,1)*a(1,3))/deter\r\n b(3,2) = (-a(1,1)*a(3,2) + a(1,2)*a(3,1))/deter\r\n b(3,3) = ( a(1,1)*a(2,2) - a(2,1)*a(1,2))/deter\r\n b(1,2) = (-a(1,2)*a(3,3) + a(3,2)*a(1,3))/deter\r\n b(1,3) = ( a(1,2)*a(2,3) - a(2,2)*a(1,3))/deter\r\n b(2,3) = (-a(1,1)*a(2,3) + a(2,1)*a(1,3))/deter\r\n\r\nCASE (4)\r\n !*** inverse of a 4*4 matrix\r\n t1= a(2,2)*a(3,3)*a(4,4) + a(2,3)*a(3,4)*a(4,2) + &\r\n a(2,4)*a(3,2)*a(4,3) - a(2,3)*a(3,2)*a(4,4) - &\r\n a(2,2)*a(3,4)*a(4,3) - a(2,4)*a(3,3)*a(4,2)\r\n t2=-a(2,1)*a(3,3)*a(4,4) - a(2,3)*a(3,4)*a(4,1) - &\r\n a(2,4)*a(3,1)*a(4,3) + a(2,4)*a(3,3)*a(4,1) + &\r\n a(2,3)*a(3,1)*a(4,4) + a(2,1)*a(3,4)*a(4,3)\r\n t3=+a(2,1)*a(3,2)*a(4,4) + a(2,2)*a(3,4)*a(4,1) + &\r\n a(2,4)*a(3,1)*a(4,2) - a(2,4)*a(3,2)*a(4,1) - &\r\n a(2,2)*a(3,1)*a(4,4) - a(2,1)*a(3,4)*a(4,2)\r\n t4=-a(2,1)*a(3,2)*a(4,3) - a(2,2)*a(3,3)*a(4,1) - &\r\n a(2,3)*a(3,1)*a(4,2) + a(2,3)*a(3,2)*a(4,1) + &\r\n a(2,2)*a(3,1)*a(4,3) + a(2,1)*a(3,3)*a(4,2)\r\n deter= a(1,1)*t1 + a(1,2)*t2 + a(1,3)*t3 + a(1,4)*t4\r\n IF(deter == 0d0) RETURN\r\n denom = 1.d0/deter\r\n b(1,1) = t1*denom\r\n b(2,1) = t2*denom\r\n b(3,1) = t3*denom\r\n b(4,1) = t4*denom\r\n b(1,2) =(- a(1,2)*a(3,3)*a(4,4) - a(1,3)*a(3,4)*a(4,2) &\r\n - a(1,4)*a(3,2)*a(4,3) + a(1,3)*a(3,2)*a(4,4) &\r\n + a(1,2)*a(3,4)*a(4,3) + a(1,4)*a(3,3)*a(4,2))*denom\r\n b(2,2) =( a(1,1)*a(3,3)*a(4,4) + a(1,3)*a(3,4)*a(4,1) &\r\n + a(1,4)*a(3,1)*a(4,3) - a(1,4)*a(3,3)*a(4,1) &\r\n - a(1,3)*a(3,1)*a(4,4) - a(1,1)*a(3,4)*a(4,3))*denom\r\n b(3,2) =(- a(1,1)*a(3,2)*a(4,4) - a(1,2)*a(3,4)*a(4,1) &\r\n - a(1,4)*a(3,1)*a(4,2) + a(1,4)*a(3,2)*a(4,1) &\r\n + a(1,2)*a(3,1)*a(4,4) + a(1,1)*a(3,4)*a(4,2))*denom\r\n b(4,2) =( a(1,1)*a(3,2)*a(4,3) + a(1,2)*a(3,3)*a(4,1) &\r\n + a(1,3)*a(3,1)*a(4,2) - a(1,3)*a(3,2)*a(4,1) &\r\n - a(1,2)*a(3,1)*a(4,3) - a(1,1)*a(3,3)*a(4,2))*denom\r\n b(1,3) =( a(1,2)*a(2,3)*a(4,4) + a(1,3)*a(2,4)*a(4,2) &\r\n + a(1,4)*a(2,2)*a(4,3) - a(1,3)*a(2,2)*a(4,4) &\r\n - a(1,2)*a(2,4)*a(4,3) - a(1,4)*a(2,3)*a(4,2))*denom\r\n b(2,3) =(- a(1,1)*a(2,3)*a(4,4) - a(1,3)*a(2,4)*a(4,1) &\r\n - a(1,4)*a(2,1)*a(4,3) + a(1,4)*a(2,3)*a(4,1) &\r\n + a(1,3)*a(2,1)*a(4,4) + a(1,1)*a(2,4)*a(4,3))*denom\r\n b(3,3) =( a(1,1)*a(2,2)*a(4,4) + a(1,2)*a(2,4)*a(4,1) &\r\n + a(1,4)*a(2,1)*a(4,2) - a(1,4)*a(2,2)*a(4,1) &\r\n - a(1,2)*a(2,1)*a(4,4) - a(1,1)*a(2,4)*a(4,2))*denom\r\n b(4,3) =(- a(1,1)*a(2,2)*a(4,3) - a(1,2)*a(2,3)*a(4,1) &\r\n - a(1,3)*a(2,1)*a(4,2) + a(1,3)*a(2,2)*a(4,1) &\r\n + a(1,2)*a(2,1)*a(4,3) + a(1,1)*a(2,3)*a(4,2))*denom\r\n b(1,4) =(- a(1,2)*a(2,3)*a(3,4) - a(1,3)*a(2,4)*a(3,2) &\r\n - a(1,4)*a(2,2)*a(3,3) + a(1,4)*a(2,3)*a(3,2) &\r\n + a(1,3)*a(2,2)*a(3,4) + a(1,2)*a(2,4)*a(3,3))*denom\r\n b(2,4) =( a(1,1)*a(2,3)*a(3,4) + a(1,3)*a(2,4)*a(3,1) &\r\n + a(1,4)*a(2,1)*a(3,3) - a(1,4)*a(2,3)*a(3,1) &\r\n - a(1,3)*a(2,1)*a(3,4) - a(1,1)*a(2,4)*a(3,3))*denom\r\n b(3,4) =(- a(1,1)*a(2,2)*a(3,4) - a(1,2)*a(2,4)*a(3,1) &\r\n - a(1,4)*a(2,1)*a(3,2) + a(1,4)*a(2,2)*a(3,1) &\r\n + a(1,2)*a(2,1)*a(3,4) + a(1,1)*a(2,4)*a(3,2))*denom\r\n b(4,4) =( a(1,1)*a(2,2)*a(3,3) + a(1,2)*a(2,3)*a(3,1) &\r\n + a(1,3)*a(2,1)*a(3,2) - a(1,3)*a(2,2)*a(3,1) &\r\n - a(1,2)*a(2,1)*a(3,3) - a(1,1)*a(2,3)*a(3,2))*denom\r\nEND SELECT\r\nRETURN\r\n\r\nEND SUBROUTINE invmtx\r\n", "meta": {"hexsha": "332d2edb74745e3b9e64396d232d2c173ff17874", "size": 4928, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/auxil/invmtx.f90", "max_stars_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_stars_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/auxil/invmtx.f90", "max_issues_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_issues_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/auxil/invmtx.f90", "max_forks_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_forks_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.0, "max_line_length": 73, "alphanum_fraction": 0.3591720779, "num_tokens": 2972, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9724147241686291, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.7972763478106003}} {"text": "PROGRAM test_kemp_binomial\r\nIMPLICIT NONE\r\n\r\nINTEGER :: n, nrep, i, ix\r\nREAL :: p, mean = 0.0, sumsq = 0.0, stdev = 0.0, dev\r\nLOGICAL :: first\r\n\r\nINTERFACE\r\n FUNCTION random_binomial(n, p, first) RESULT(ran_binom)\r\n IMPLICIT NONE\r\n INTEGER, INTENT(IN) :: n\r\n REAL, INTENT(IN) :: p\r\n LOGICAL, INTENT(IN) :: first\r\n INTEGER :: ran_binom\r\n END FUNCTION random_binomial\r\nEND INTERFACE\r\n\r\nWRITE(*, *) 'Enter n & p: '\r\nREAD(*, *) n, p\r\nWRITE(*, *) 'How many random deviates?: '\r\nREAD(*, *) nrep\r\n\r\nfirst = .TRUE.\r\nDO i = 1, nrep\r\n ix = random_binomial(n, p, first)\r\n dev = ix - mean\r\n mean = mean + dev/i\r\n sumsq = sumsq + dev*(ix - mean)\r\n first = .FALSE.\r\nEND DO\r\n\r\nIF (nrep > 1) stdev = SQRT(sumsq / (nrep-1))\r\nWRITE(*, '(1x, \"Mean = \", f8.2, 5x, \"Std. devn. = \", f8.2)') mean, stdev\r\n\r\nSTOP\r\nEND PROGRAM test_kemp_binomial\r\n\r\n\r\n\r\nFUNCTION random_binomial(n, p, first) RESULT(ran_binom)\r\n\r\n! FUNCTION GENERATES A RANDOM BINOMIAL VARIATE USING C.D.Kemp's method.\r\n! This algorithm is suitable when many random variates are required\r\n! with the SAME parameter values for n & p.\r\n\r\n! P = BERNOULLI SUCCESS PROBABILITY\r\n! (0 <= REAL <= 1)\r\n! N = NUMBER OF BERNOULLI TRIALS\r\n! (1 <= INTEGER)\r\n! FIRST = .TRUE. for the first call using the current parameter values\r\n! = .FALSE. if the values of (n,p) are unchanged from last call\r\n\r\n! Reference: Kemp, C.D. (1986). `A modal method for generating binomial\r\n! variables', Commun. Statist. - Theor. Meth. 15(3), 805-813.\r\n\r\nIMPLICIT NONE\r\n\r\nINTEGER, INTENT(IN) :: n\r\nREAL, INTENT(IN) :: p\r\nLOGICAL, INTENT(IN) :: first\r\nINTEGER :: ran_binom\r\n\r\nINTERFACE\r\n FUNCTION bin_prob(n, p, r) RESULT(prob)\r\n IMPLICIT NONE\r\n INTEGER, INTENT(IN) :: n, r\r\n REAL, INTENT(IN) :: p\r\n REAL :: prob\r\n END FUNCTION bin_prob\r\nEND INTERFACE\r\n\r\n! Local variables\r\n\r\nINTEGER :: ru, rd\r\nINTEGER, SAVE :: r0\r\nREAL :: u, pd, pu, zero = 0.0, one = 1.0\r\nREAL, SAVE :: odds_ratio, p_r\r\n\r\nIF (first) THEN\r\n r0 = (n+1)*p\r\n p_r = bin_prob(n, p, r0)\r\n odds_ratio = p / (one - p)\r\nEND IF\r\n\r\nCALL RANDOM_NUMBER(u)\r\nu = u - p_r\r\nIF (u < zero) THEN\r\n ran_binom = r0\r\n RETURN\r\nEND IF\r\n\r\npu = p_r\r\nru = r0\r\npd = p_r\r\nrd = r0\r\nDO\r\n rd = rd - 1\r\n IF (rd >= 0) THEN\r\n pd = pd * (rd+1) / (odds_ratio * REAL(n-rd))\r\n u = u - pd\r\n IF (u < zero) THEN\r\n ran_binom = rd\r\n RETURN\r\n END IF\r\n END IF\r\n\r\n ru = ru + 1\r\n IF (ru <= n) THEN\r\n pu = pu * (n-ru+1) * odds_ratio / REAL(ru)\r\n u = u - pu\r\n IF (u < zero) THEN\r\n ran_binom = ru\r\n RETURN\r\n END IF\r\n END IF\r\nEND DO\r\n\r\n! This point should not be reached, but just in case:\r\n\r\nran_binom = r0\r\nRETURN\r\n\r\nEND FUNCTION random_binomial\r\n\r\n\r\n\r\nFUNCTION bin_prob(n, p, r) RESULT(prob)\r\n! Calculate a binomial probability\r\n\r\nIMPLICIT NONE\r\n\r\nINTEGER, INTENT(IN) :: n, r\r\nREAL, INTENT(IN) :: p\r\nREAL :: prob\r\n\r\n! Local variable\r\nREAL :: one = 1.0\r\n\r\nprob = EXP( lngamma(DBLE(n+1)) - lngamma(DBLE(r+1)) - lngamma(DBLE(n-r+1)) &\r\n + r*LOG(p) + (n-r)*LOG(one - p) )\r\nRETURN\r\n\r\n\r\nCONTAINS\r\n\r\n\r\nFUNCTION lngamma(z) RESULT(lanczos)\r\n\r\n! Uses Lanczos-type approximation to ln(gamma) for z > 0.\r\n! Reference:\r\n! Lanczos, C. 'A precision approximation of the gamma\r\n! function', J. SIAM Numer. Anal., B, 1, 86-96, 1964.\r\n! Accuracy: About 14 significant digits except for small regions\r\n! in the vicinity of 1 and 2.\r\n\r\n! Programmer: Alan Miller\r\n! 1 Creswick Street, Brighton, Vic. 3187, Australia\r\n! Latest revision - 14 October 1996\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: doub_prec = SELECTED_REAL_KIND(15, 60)\r\nREAL(doub_prec), INTENT(IN) :: z\r\nREAL(doub_prec) :: lanczos\r\n\r\n! Local variables\r\n\r\nREAL(doub_prec) :: a(9) = (/ 0.9999999999995183D0, 676.5203681218835D0, &\r\n -1259.139216722289D0, 771.3234287757674D0, &\r\n -176.6150291498386D0, 12.50734324009056D0, &\r\n -0.1385710331296526D0, 0.9934937113930748D-05, &\r\n 0.1659470187408462D-06 /), zero = 0.D0, &\r\n one = 1.d0, lnsqrt2pi = 0.9189385332046727D0, &\r\n half = 0.5d0, sixpt5 = 6.5d0, seven = 7.d0, tmp\r\nINTEGER :: j\r\n\r\nIF (z <= zero) THEN\r\n WRITE(*, *)'Error: zero or -ve argument for lngamma'\r\n RETURN\r\nEND IF\r\n\r\nlanczos = zero\r\ntmp = z + seven\r\nDO j = 9, 2, -1\r\n lanczos = lanczos + a(j)/tmp\r\n tmp = tmp - one\r\nEND DO\r\nlanczos = lanczos + a(1)\r\nlanczos = LOG(lanczos) + lnsqrt2pi - (z + sixpt5) + (z - half)*LOG(z + sixpt5)\r\nRETURN\r\n\r\nEND FUNCTION lngamma\r\n\r\nEND FUNCTION bin_prob\r\n\r\n\r\n\r\n\r\n", "meta": {"hexsha": "b11550a572931f108bbf81466833951c8d965859", "size": 4834, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/t_kemp_b.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/t_kemp_b.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/t_kemp_b.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 24.4141414141, "max_line_length": 79, "alphanum_fraction": 0.5614398014, "num_tokens": 1565, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404116305638, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7972443439649624}} {"text": "PROGRAM F014\n\n ! Copyright 2021 Melwyn Francis Carlo\n\n IMPLICIT NONE\n\n INTEGER :: N_COUNT = 1E5\n\n INTEGER :: MAX_COUNT = 0\n INTEGER :: MAX_COUNT_NUMBER = 0\n\n INTEGER :: I_COUNT\n\n INTEGER (KIND=8) :: N\n\n DO WHILE (N_COUNT < 1E6)\n\n I_COUNT = 0\n N = N_COUNT;\n\n DO WHILE (N /= 1)\n\n IF (MOD(N, INT(2, 8)) == 0) THEN\n N = N / 2;\n ELSE\n N = (3 * N) + 1;\n END IF\n\n I_COUNT = I_COUNT + 1\n\n END DO\n\n I_COUNT = I_COUNT + 1\n\n IF (I_COUNT > MAX_COUNT) THEN\n MAX_COUNT = I_COUNT;\n MAX_COUNT_NUMBER = N_COUNT;\n END IF\n\n N_COUNT = N_COUNT + 1\n\n END DO\n\n PRINT ('(I0)'), MAX_COUNT_NUMBER\n\nEND PROGRAM F014\n", "meta": {"hexsha": "6d11be8b72ccda46c4a44c261d0c7663b4cf0556", "size": 785, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "problems/014/014.f90", "max_stars_repo_name": "melwyncarlo/ProjectEuler", "max_stars_repo_head_hexsha": "c4d30ed528ae6de82232f3d2044d608c6e8f1c37", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "problems/014/014.f90", "max_issues_repo_name": "melwyncarlo/ProjectEuler", "max_issues_repo_head_hexsha": "c4d30ed528ae6de82232f3d2044d608c6e8f1c37", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "problems/014/014.f90", "max_forks_repo_name": "melwyncarlo/ProjectEuler", "max_forks_repo_head_hexsha": "c4d30ed528ae6de82232f3d2044d608c6e8f1c37", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.7021276596, "max_line_length": 44, "alphanum_fraction": 0.472611465, "num_tokens": 233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632856092016, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.797220605193384}} {"text": "module interpolate_module\n\n contains\n\n function interpolate(r, npts_model, model_r, model_var)\n \n! given the array of model coordinates (model_r), and variable (model_var),\n! find the value of model_var at point r using linear interpolation.\n! Eventually, we can do something fancier here.\n \n double precision, intent(in ) :: r\n integer , intent(in ) :: npts_model\n double precision, intent(in ) :: model_r(npts_model), model_var(npts_model)\n double precision :: interpolate\n\n ! Local variables\n integer :: i, id\n double precision :: slope,minvar,maxvar\n \n! find the location in the coordinate array where we want to interpolate\n do i = 1, npts_model\n if (model_r(i) .ge. r) exit\n enddo\n \n if (i .eq. npts_model+1) i = i-1\n id = i\n \n if (id .eq. 1) then\n\n slope = (model_var(id+1) - model_var(id))/(model_r(id+1) - model_r(id))\n interpolate = slope*(r - model_r(id)) + model_var(id)\n\n ! safety check to make sure interpolate lies within the bounding points\n minvar = min(model_var(id+1),model_var(id))\n maxvar = max(model_var(id+1),model_var(id))\n interpolate = max(interpolate,minvar)\n interpolate = min(interpolate,maxvar)\n \n else if (id .eq. npts_model) then\n\n slope = (model_var(id) - model_var(id-1))/(model_r(id) - model_r(id-1))\n interpolate = slope*(r - model_r(id)) + model_var(id)\n\n ! safety check to make sure interpolate lies within the bounding points\n minvar = min(model_var(id),model_var(id-1))\n maxvar = max(model_var(id),model_var(id-1))\n interpolate = max(interpolate,minvar)\n interpolate = min(interpolate,maxvar)\n\n else\n\n if (r .ge. model_r(id)) then\n\n slope = (model_var(id+1) - model_var(id))/(model_r(id+1) - model_r(id))\n interpolate = slope*(r - model_r(id)) + model_var(id)\n\n ! safety check to make sure interpolate lies within the bounding points\n minvar = min(model_var(id+1),model_var(id))\n maxvar = max(model_var(id+1),model_var(id))\n interpolate = max(interpolate,minvar)\n interpolate = min(interpolate,maxvar)\n\n else\n\n slope = (model_var(id) - model_var(id-1))/(model_r(id) - model_r(id-1))\n interpolate = slope*(r - model_r(id)) + model_var(id)\n\n ! safety check to make sure interpolate lies within the bounding points\n minvar = min(model_var(id),model_var(id-1))\n maxvar = max(model_var(id),model_var(id-1))\n interpolate = max(interpolate,minvar)\n interpolate = min(interpolate,maxvar)\n\n end if\n\n endif\n\n end function interpolate\n\nend module interpolate_module\n", "meta": {"hexsha": "5c34fef50389828e75536306ce4c63c73dd9f1ee", "size": 2897, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorials/AMR_PETSc_C/Source/interpolate.f90", "max_stars_repo_name": "memmett/BoxLib", "max_stars_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Tutorials/AMR_PETSc_C/Source/interpolate.f90", "max_issues_repo_name": "memmett/BoxLib", "max_issues_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorials/AMR_PETSc_C/Source/interpolate.f90", "max_forks_repo_name": "memmett/BoxLib", "max_forks_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-08-06T13:09:09.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-06T13:09:09.000Z", "avg_line_length": 35.7654320988, "max_line_length": 83, "alphanum_fraction": 0.5975146703, "num_tokens": 692, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625126757597, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7971932615429138}} {"text": "! Program to solve the Laplace equation using Dirichlet boundary conditions \n! Author: Anantha Rao\n! Reg no:20181044\n\nprogram laplace\n implicit none\n\n integer, parameter:: lx=34, ly=34 ! BOUNDARIES AT x,y=0 and x,y=34\n real*8 :: old_temp(1:lx, 1:ly), temp(1:lx, 1:ly)\n integer :: i,j,jj,ii,kk\n real*8 :: bound_temp, increment_temp, dx, dy, prefactor\n character(len=30) :: filename\n integer :: iunit, ci,cii,test, counter\n\n bound_temp=0.0d0; increment_temp=0.1d0\n old_temp=0.0d0 ! INITIAL CONDITION FOR WHOLE LATTICE\n\n ! BOUNDARY CONDITIONS\n do i=1,ly\n old_temp(1,i) = 3.7d0 !LEFT BOUNDARY at x=1\n old_temp(lx,i) = 0.4d0 !RIGHT BOUNDARY t x=34\n end do\n\n do i=2, lx-1 ! BOUNDARY CONDITIONS ALONG Y\n old_temp(i,1) = 3.7d0 - dfloat(i-1)*increment_temp ! LOWER BOUNDARY\n old_temp(i,ly) = 3.7d0 - dfloat(i-1)*increment_temp ! TOP BOUNDARY \n end do\n\n temp=old_temp\n iunit=71; ci=0\n write(filename, '(\"initialize_\",i0,\".dat\")') ci\n open(newunit=iunit, file=filename) !WRITE DOWN THE BC AT ZEROTH ITERATION \n\n do ii=1,lx\n do jj=1,ly\n write(iunit,*) ii,jj,old_temp(ii,jj)\n end do\n end do\n close(iunit)\n\n dx=0.05d0; dy=0.05d0 ! we will not be using this\n test=0; counter=0; prefactor=(0.5d0*dx*dx*dy*dy)/(dx*dx + dy*dy)\n\n do ! LOOP OVER ITERATIONS\n counter= counter+1\n test=0\n do jj=2,ly-1 ! UPDATE STEP\n do ii=2,lx-1\n temp(ii,jj) = 0.25*(old_temp(ii-1,jj) +old_temp(ii+1,jj) + old_temp(ii,jj-1) + old_temp(ii,jj+1))\n end do\n end do\n\n ! CHECK FOR CONVERGENCE AT EACH LATTICE SITE\n do jj=2,ly-1\n do ii=2,lx-1\n if((abs(temp(jj,ii) - old_temp(jj,ii))).gt.0.0001d0) test=1\n end do\n end do\n \n if (test.eq.0) exit ! EXIT CONDITION\n old_temp = temp ! AFTER TEST CONDITION\n end do\n write(*,*) 'counter', counter\n\n ! WRITE THE CONVERGED RESULT: SOLN TO THE EQN WITH BC\n\n iunit=71; ci=10000\n write(filename,'(\"initialize_\",i0,\".dat\")') ci\n\n open(newunit=iunit, file=filename)\n do ii=1,lx\n do jj=1,ly\n write(iunit,*) ii,jj,temp(ii,jj)\n end do\n end do\n close(iunit)\n\nend program laplace\n\n", "meta": {"hexsha": "ae699648ab8411620fd3f026d191178e9d99ecc6", "size": 2354, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/assgn06_solns/Assgn06_Q3/20181044_laplace.f90", "max_stars_repo_name": "Anantha-Rao12/ComPhys", "max_stars_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Solutions/assgn06_solns/Assgn06_Q3/20181044_laplace.f90", "max_issues_repo_name": "Anantha-Rao12/ComPhys", "max_issues_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Solutions/assgn06_solns/Assgn06_Q3/20181044_laplace.f90", "max_forks_repo_name": "Anantha-Rao12/ComPhys", "max_forks_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.425, "max_line_length": 113, "alphanum_fraction": 0.5756159728, "num_tokens": 798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680097, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.7971932532332106}} {"text": " !----------------------------------------\n ! Kim-Tuan\n !----------------------------------------\n \n ! calculate flow stress using Kim-Tuan rule\n DOUBLE PRECISION FUNCTION KimTuan(HARDK,HARDT,HARDA,HARDH,\n & HARDSTRESS0,eqpStrain)\n IMPLICIT NONE\n DOUBLE PRECISION HARDK,HARDT,HARDA,HARDH,HARDSTRESS0,eqpStrain\n IF (eqpStrain == 0.0D0) THEN\n calc_FlowStress = HARDSTRESS0\n RETURN\n END IF\n calc_FlowStress = HARDSTRESS0 + \n & HARDK*(1.0D0-EXP(-1.0D0*HARDT*eqpStrain**HARDA))*eqpStrain**HARDH\n RETURN\n END FUNCTION KimTuan\n\n\n ! calculate first order differential of Kim-Tuan flow stress\n DOUBLE PRECISION FUNCTION calc_KimTuan_differential(HARDK,HARDT,\n & HARDA,HARDH,HARDSTRESS0,eqpStrain)\n IMPLICIT NONE\n DOUBLE PRECISION HARDK,HARDT,HARDA,HARDH,HARDSTRESS0,eqpStrain\n IF (eqpStrain == 0.0D0) THEN\n calc_KimTuan_differential = 0.0D0\n RETURN\n END IF\n calc_KimTuan_differential = \n & (HARDK*HARDA*HARDT*eqpStrain**(HARDA-1.0D0))*\n & EXP(-1.0D0*HARDT*eqpStrain**HARDA)\n calc_KimTuan_differential = calc_KimTuan_differential + \n & HARDK*(1.0D0-EXP(-1.0D0*HARDT*eqpStrain**HARDA))*\n & HARDH*eqpStrain**(HARDH-1.0D0)\n RETURN\n END FUNCTION calc_KimTuan_differential\n\n\n !----------------------------------------\n ! Swift\n !----------------------------------------\n\n ! calculate flow stress\n DOUBLE PRECISION FUNCTION Swift(HARDK,HARDSTRAIN0,\n & HARDN,eqpStrain)\n IMPLICIT NONE\n DOUBLE PRECISION HARDK,HARDSTRAIN0,HARDN,eqpStrain\n calc_FlowStress = HARDK*(HARDSTRAIN0 + eqpStrain)**HARDN\n RETURN\n END FUNCTION Swift\n\n\n ! calculate first order differential of Kim-Tuan flow stress\n DOUBLE PRECISION FUNCTION calc_Swift_differential(HARDK,\n & HARDSTRAIN0,HARDN,eqpStrain)\n IMPLICIT NONE\n DOUBLE PRECISION HARDK,HARDSTRAIN0,HARDN,eqpStrain\n calc_Swift_differential = HARDK*HARDN*\n & ((HARDSTRAIN0 + eqpStrain)**(HARDN-1.0D0))\n RETURN\n END FUNCTION calc_Swift_differential", "meta": {"hexsha": "a118764821aab439cd529d5e3105decfbae78971", "size": 2126, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src_fortran/HardeningRules.for", "max_stars_repo_name": "yossy11/Subroutines", "max_stars_repo_head_hexsha": "eefc1ac126ab8bbcfdc62f85844f5fecfd151cb2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-09-13T14:22:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-18T07:20:31.000Z", "max_issues_repo_path": "src_fortran/HardeningRules.for", "max_issues_repo_name": "yossy11/Subroutines", "max_issues_repo_head_hexsha": "eefc1ac126ab8bbcfdc62f85844f5fecfd151cb2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-09-13T14:15:26.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-14T14:11:34.000Z", "max_forks_repo_path": "src_fortran/HardeningRules.for", "max_forks_repo_name": "yossy11/Subroutines", "max_forks_repo_head_hexsha": "eefc1ac126ab8bbcfdc62f85844f5fecfd151cb2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-13T14:22:50.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-13T14:22:50.000Z", "avg_line_length": 34.8524590164, "max_line_length": 72, "alphanum_fraction": 0.6222953904, "num_tokens": 681, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308073258007, "lm_q2_score": 0.853912760387131, "lm_q1q2_score": 0.7970684773139628}} {"text": "subroutine calcOverlapAreas(nTurbines, turbineX, turbineY, rotorDiameter, wakeDiameters, &\n wakeCenters, wakeOverlapTRel_mat)\n! calculate overlap of rotors and wake zones (wake zone location defined by wake \n! center and wake diameter)\n! turbineX,turbineY is x,y-location of center of rotor\n!\n! wakeOverlap(TURBI,TURB,ZONEI) = overlap area of zone ZONEI of wake of turbine \n! TURB with rotor of downstream turbine\n! TURBI\n\n implicit none\n \n ! define precision to be the standard for a double precision ! on local system\n integer, parameter :: dp = kind(0.d0)\n \n ! in\n integer, intent(in) :: nTurbines\n real(dp), dimension(nTurbines), intent(in) :: turbineX, turbineY, rotorDiameter\n real(dp), dimension(nTurbines, nTurbines, 3), intent(in) :: wakeDiameters\n real(dp), dimension(nTurbines, nTurbines), intent(in) :: wakeCenters\n \n ! out \n real(dp), dimension(nTurbines, nTurbines, 3), intent(out) :: wakeOverlapTRel_mat\n \n ! local\n integer :: turb, turbI, zone\n real(dp), parameter :: pi = 3.141592653589793_dp, tol = 0.000001_dp\n real(dp) :: OVdYd, OVr, OVRR, OVL, OVz\n real(dp), dimension(nTurbines, nTurbines, 3) :: wakeOverlap\n \n wakeOverlapTRel_mat = 0.0_dp\n wakeOverlap = 0.0_dp\n \n OVdYd = wakeCenters(turbI, turb)-turbineY(turbI) ! distance between wake center and rotor center\n OVr = rotorDiameter(turbI)/2 ! rotor diameter\n \n OVRR = wakeDiameters(turbI, turb, zone)/2.0_dp ! wake diameter\n OVdYd = abs(OVdYd)\n if (OVdYd >= 0.0_dp + tol) then\n ! calculate the distance from the wake center to the vertical line between\n ! the two circle intersection points\n OVL = (-OVr*OVr+OVRR*OVRR+OVdYd*OVdYd)/(2.0_dp*OVdYd)\n else\n OVL = 0.0_dp\n end if\n\n OVz = OVRR*OVRR-OVL*OVL\n\n ! Finish calculating the distance from the intersection line to the outer edge of the wake zone\n if (OVz > 0.0_dp + tol) then\n OVz = sqrt(OVz)\n else\n OVz = 0.0_dp\n end if\n\n if (OVdYd < (OVr+OVRR)) then ! if the rotor overlaps the wake zone\n\n if (OVL < OVRR .and. (OVdYd-OVL) < OVr) then\n wakeOverlap(turbI, turb, zone) = OVRR*OVRR*dacos(OVL/OVRR) + OVr*OVr*dacos((OVdYd-OVL)/OVr) - OVdYd*OVz\n else if (OVRR > OVr) then\n wakeOverlap(turbI, turb, zone) = pi*OVr*OVr\n else\n wakeOverlap(turbI, turb, zone) = pi*OVRR*OVRR\n end if\n else\n wakeOverlap(turbI, turb, zone) = 0.0_dp\n end if\n\n\n do turb = 1, nTurbines\n \n do turbI = 1, nTurbines\n \n wakeOverlap(turbI, turb, 3) = wakeOverlap(turbI, turb, 3)-wakeOverlap(turbI, turb, 2)\n wakeOverlap(turbI, turb, 2) = wakeOverlap(turbI, turb, 2)-wakeOverlap(turbI, turb, 1)\n \n end do\n \n end do\n \n wakeOverlapTRel_mat = wakeOverlap\n\n do turbI = 1, nTurbines\n wakeOverlapTRel_mat(turbI, :, :) = wakeOverlapTRel_mat(turbI, :, &\n :)/((pi*rotorDiameter(turbI) &\n *rotorDiameter(turbI))/4.0_dp)\n end do\n \n ! do turbI = 1, nTurbines\n! do turb = 1, nTurbines\n! do zone = 1, 3\n! print *, \"wakeOverlapTRel_mat[\", turbI, \", \", turb, \", \", zone, \"] = \", wakeOverlapTRel_mat(turbI, turb, zone)\n! end do\n! end do\n! end do\n \n \n \nend subroutine calcOverlapAreas", "meta": {"hexsha": "17b0fe269b545eaa301f2d6d9dcd601af995f564", "size": 3568, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/gaussianwake/overlap_floris.f90", "max_stars_repo_name": "Kenneth-T-Moore/gaussian-wake", "max_stars_repo_head_hexsha": "49fbd695519615f0a3d12caf1e3658e02029fb1d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-10-21T15:32:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-23T04:44:11.000Z", "max_issues_repo_path": "src/gaussianwake/overlap_floris.f90", "max_issues_repo_name": "Kenneth-T-Moore/gaussian-wake", "max_issues_repo_head_hexsha": "49fbd695519615f0a3d12caf1e3658e02029fb1d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-08-01T20:04:06.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-24T18:21:38.000Z", "max_forks_repo_path": "src/gaussianwake/overlap_floris.f90", "max_forks_repo_name": "Kenneth-T-Moore/gaussian-wake", "max_forks_repo_head_hexsha": "49fbd695519615f0a3d12caf1e3658e02029fb1d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-07-01T19:03:06.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-23T10:40:17.000Z", "avg_line_length": 36.0404040404, "max_line_length": 128, "alphanum_fraction": 0.5871636771, "num_tokens": 1119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660989095221, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.7970229784092581}} {"text": "MODULE SLAE\n!\n! Module for the solution of systems of linear equations.\n! \n USE precise, ONLY: DEFAULTP\n IMPLICIT NONE\n INTEGER, PARAMETER, PRIVATE :: WP=DEFAULTP\n\n\nCONTAINS\n\n\n SUBROUTINE gauss(A,B,X,ERROR)\n\n! Gauss elimination with partial Pivot element search (row switching)\n! Solves the system of linear equations\n! Ax = b\n! A and b are changed by the routine!\n!\n REAL(WP), INTENT(IN OUT) :: A(:,:)\n REAL(WP), INTENT(IN OUT) :: B(:)\n\n INTEGER, INTENT(IN OUT) :: ERROR\n REAL(WP), INTENT(OUT) :: X(:)\n REAL(WP) :: am, P\n INTEGER :: I, J, K, ITMP, NEQ, l\n INTEGER, ALLOCATABLE :: IDX(:)\n\n ! Initialize some local variables\n ERROR = 0\n NEQ = SIZE(B)\n ALLOCATE(IDX(NEQ))\n \n ! Initialize index array (the rows are not actually switched. Only\n ! the inices are interchanged\n DO i = 1, NEQ\n IDX(i) = i\n END DO\n\n ! Loop over the equations from first to next to last Eq\n DO K = 1, NEQ-1\n J = K\n ! Search for Pivot element (largest number in column below\n ! current position\n DO I = K+1, NEQ\n IF ( ABS(A(IDX(I),K)) > ABS(A(IDX(J),K))) J = I\n END DO\n ! Make row with Pivot element the current row\n ITMP = IDX(J)\n IDX(J) = IDX(K)\n IDX(K) = ITMP\n\n ! Return error condition if pivot element is too small\n IF (ABS(A(IDX(K),K)) < 0.00000000000001) THEN\n PRINT*, IDX(K), K, A(IDX(K),K)\n ERROR=-1\n RETURN\n ENDIF\n ! Gauss elimination procedure\n DO I = K+1, NEQ\n\n ! Divide rows by pivot element\n am = A(IDX(I),K) / A(IDX(K),K)\n\n ! Subtract pivot element row from rows below\n !DO J = K+1, NEQ\n DO J = 1, NEQ\n A(IDX(I),J) = A(IDX(I),J) - am*A(IDX(K),J)\n END DO\n B(IDX(I)) = B(IDX(I)) - am*B(IDX(K))\n !!! Poor man debugger; uncomment if you want to see the matrix changes\n !!do l = 1, neq\n !! WRITE(6,'(5G12.6)') (A(IDX(l),J), J = 1, neq), B(IDX(l))\n !!END DO\n !!WRITE(6,*)\n END DO\n END DO\n\n ! Back substitution part\n ! Start with last unknown\n ! Walk your way back up from next to last to first row (unknown)\n DO K = NEQ, 1, -1\n X(K) = B(IDX(K)) \n DO I = K+1, NEQ\n X(K) = X(K) - A(IDX(K),I)*X(I)\n END DO\n ! Compute unknown\n X(K) = X(K) / A(IDX(K), K)\n END DO\n\n ! Done\n RETURN\n END SUBROUTINE gauss\n\n\n SUBROUTINE gauss_simple(A,B,X,error)\n! Bare bone Gauss elimination\n! Solves the system of linear equations\n! Ax = b\n! A and b are changed by the routine!\n! Whenever a diagonal element is zero this routine will fail to produce\n! a solution\n\n REAL(WP), INTENT(IN OUT) :: A(:,:)\n REAL(WP), INTENT(IN OUT) :: B(:)\n \n INTEGER, INTENT(IN OUT) :: ERROR\n REAL(WP), INTENT(OUT) :: X(:)\n\n INTEGER :: i, k, J, N\n REAL(wp) :: md\n\n N = SIZE(B) \n ERROR = 0\n \n ! Gauss elimination (creation of upper triangular matrix)\n DO k = 1, N-1\n IF (ABS(a(k,k)) < 0.0000001) THEN\n error = -1\n RETURN\n ENDIF \n DO i = k+1, N\n md = a(i,k)/a(k,k)\n DO j = k+1, n\n a(i,j) = a(i,j) - md*a(k,j)\n END DO\n b(i) = b(i) - md*b(k)\n END DO \n !!! Poor man debugger; uncomment if you want to see the matrix changes\n !!DO i = 1, n\n !! WRITE(6,'(5G12.6)') (A(i,J), J = 1, n), B(I)\n !!END do\n END DO \n \n ! Back substitution part\n DO k = n, 1, -1\n x(k) = b(k)\n DO I = K+1, N\n x(k) = x(k) - A(k,i)*X(I)\n END DO\n x(k) = x(k) / a(k,k)\n END DO \n RETURN \n END SUBROUTINE gauss_simple\n\n\n\n\n SUBROUTINE GSIT(A,B,EPS,OMEGA,MAXIT,X,ERROR)\n!\n! Gauss-Seidel over-relaxation algorithm for the iterative solution of\n! systems of linear equations:\n! A*X = B\n!\n! The matrix A is of size (NEQ,NEQ) and has to be diagonal dominant.\n! B is the right hand side vector of size (NEQ).\n! eps is a small real number specifying the required accuracy of\n! the solution.\n! OMEGA is the relaxation parameter (real). Must be in the open interval\n! (0,2). If you do not know the problem dependend proper value, let\n! omega=1.0 (no relaxation, pure Gauss-Seidel iteration).\n! Start testing with omega=1.5, if you are of the adventurous kind.\n! MaxIt is the maximum number of iterations allowd for solving the LGS.\n! X contains the initial solution when the procedure is called and\n! on return provides the solution vector X.\n! Error returns the status of the subroutine:\n! error = -1 : Critical error condition. One of the main diagonal \n! elements of the matrix is (almost) zero. The\n! system can not be solved with this routine.\n! error = -2 : The solution did not converge to the required accuracy.\n! The parameter MaxIt iterations was reached.\n! error > 0 : The system is successfully solved and ERROR iterations\n! have been used for the solution.\n!\n INTEGER, INTENT(IN) :: MAXIT\n REAL(WP), INTENT(IN) :: A(:,:)\n REAL(WP), INTENT(IN) :: B(:)\n REAL(WP), INTENT(IN) :: EPS,OMEGA\n \n INTEGER, INTENT(IN OUT) :: ERROR\n REAL(WP), INTENT(OUT) :: X(:)\n\n INTEGER :: I, J\n INTEGER :: NEQ\n REAL(WP) :: Xold(SIZE(X))\n\n ! Initialize variables\n ERROR = 0\n NEQ = SIZE(B) ! Number of equations\n\n ! Simple error check. None of the elements on the main diagonal\n ! of A is allowed to be zero\n DO i = 1, NEQ\n IF (ABS(A(i,i)) < 0.0000001) THEN\n ERROR = -1\n RETURN\n END IF\n END DO\n\n DO J = 1, MAXIT ! LOOP OVER ITERATIONS\n Xold = X ! Store last solution for convergence test\n ! The following loop contains the Gauss-Seidel over relaxation algorithm\n DO I = 1, NEQ\n X(i) = (1.-omega)*X(i) &\n - omega*SUM(A(i,1:i-1)*X(1:i-1))/A(i,i) &\n - omega*SUM(A(i,i+1:NEQ)*X(i+1:NEQ))/A(i,i) &\n + omega*B(i)/A(i,i)\n END DO \n ! Check for convergence. If the absolute difference between\n ! the next to last (Xold) and the last iteration step is smaller\n ! than eps exit iteration loop\n IF (SQRT(SUM((X-Xold)**2))/SQRT(SUM(Xold**2)) < eps ) THEN\n error = j\n EXIT \n END IF\n ! This line should not be reached if the matrix is properly\n ! scaled\n error = -2 ! Return value for bad convergence, i.e. j=MaxIt\n END DO\n\n RETURN\n END SUBROUTINE gsit \n\n\n SUBROUTINE SIMQIT(A,R,N,NMAX,SING,AV,DX,X,iter)\n! \n! Iterative solution of a non-singular, REAL linear system of equations\n! A X = R, WHERE A, X and R are (n by n), (n by 1) and (n by 1) matrices,\n! respectively. (n by c) means: n rows, c columns.\n\n! Method: Incomplete Gauss elimination: Those matrix coefficients \n! the absolute \n! value of which exceeds the column pivot element times the value \n! AVERH are \n! eliminated before a Gauss-Seidel iteration WITH column pivoting \n! is applied. \n! IF no convergence is encountered, another elimination step \n! is performed\n! WITH half the previous value of AVERH. The starting value of \n! AVERH is AV.\n\n! PARAMETER A (input; changed): Two-index array of size 1:NMAX >= n,\n! 1: >= n + 2) containing the elements of the matrix A. FIRST INDEX \n! COUNTS COLUMNS, LAST INDEX COUNTS ROWS.\n! PARAMETER R (input; changed): One-index array containing the elements \n! of the matrix R\n! PARAMETER N (input): Number of unknowns\n! PARAMETER NMAX (input): Maximum defined value of first index of A\n! PARAMETER SING (input): Lower limit of absolute value of pivot\n! elements. IF\n! a division by an element the absolute value of which is smaller \n! than SING\n! would be required, elimination is stopped WITH an error message \n! indicating\n! the indices of those equations which are responsible for the \n! difficulty.\n! It is recommended to generate the equation system such that \n! maximum \n! absolute values of the elements of A in each row and column DO\n! not differ \n! by orders of magnitude. THEN, for SING a value of 10**-5 times \n! that \n! maximum absolute value may be recommended.\n! PARAMETER AV (input): See above under method. Recommended value: \n! SQRT(1/N).\n! PARAMETER DX: The iteration stops IF the maximum absolute change of \n! any \n! unknown within one iteration step is smaller than DX.\n! PARAMETER X (input and RESULT): array of size 1: >= n containing \n! an estimated\n! solution when calling the SUBROUTINE (IF no estimation is \n! available, 0 is\n! recommended), and the solution vector X after RETURN\n! Parameter iter (output): integer, number of iterations needed\n!\n\n USE precise, ONLY: DEFAULTP\n IMPLICIT NONE\n INTEGER, PARAMETER :: WP=DEFAULTP\n\n INTEGER IS, ITER, IZ, IZPIV, IZ1, N, NMAX\n REAL(wp) AA,AV, AVERH, ALIMIT, BMAX, DX, DXMAX, DXMAXV, SAVEAIJ, SING\n !REAL(wp) A(NMAX,N+2), R(N), X(N)\n REAL(wp), DIMENSION(:,:) :: A\n REAL(wp), DIMENSION(:) :: R, X\n! Initial values for R and (n+2)nd column of A (equation numbers)\n DO IS=1,N\n A(IS,N+2)=IS+0.5\n END DO \n DO IZ=1,N\n DO IS=1,N\n R(IZ)=R(IZ)-X(IS)*A(IS,IZ)\n END DO \n END DO \n AVERH=AV*1.4\n iter=1\n3 CONTINUE\n AVERH=AVERH/1.4\n iter=iter+1\n !PRINT*, \"simqit: iter=\", iter\n! For all rows\n !!PRINT*, A(N,:)\n DO IZ = 1,N\n! Search for pivot element \n !PRINT*, IZ\n\t BMAX=0.\n\t DO IZ1 = IZ,N\n\t IF(ABS(A(IZ,IZ1)).GT.BMAX)THEN\n\t IZPIV = IZ1\n\t BMAX = ABS(A(IZ,IZ1))\n\t ENDIF\n END DO \n !!PRINT*, BMAX\n\t IF (BMAX.LT.SING) THEN\n\t WRITE(*,*)'Equation system is singular: Bmax=',BMAX\n\t STOP\n\t ENDIF\n! Exchange of pivot and IZ rows; normalization of pivot row\n\t ALIMIT = BMAX*AVERH\n\t BMAX=SIGN(BMAX,A(IZ,IZPIV))\n\t IF (IZPIV.EQ.IZ) THEN\n\t DO IS=1,N\n A(IS,IZ)=A(IS,IZ)/BMAX\n END DO \n\t ELSE\n\t DO IS = 1,N\n SAVEAIJ=A(IS,IZPIV)\n\t A(IS,IZPIV)=A(IS,IZ)\n A(IS,IZ)=SAVEAIJ/BMAX\n END DO \n\t ENDIF\n\t SAVEAIJ=A(IZPIV,N+2)\n\t A(IZPIV,N+2)=A(IZ,N+2)\n\t A(IZ,N+2)=SAVEAIJ\n\t SAVEAIJ=R(IZPIV)\n\t R(IZPIV)=R(IZ)\n\t R(IZ)=SAVEAIJ/BMAX\n! Elimination of large coefficients\n\t DO IZ1=IZ+1,N\n\t AA=-A(IZ,IZ1)\n\t IF (ABS(AA).GT.ALIMIT) THEN\n\t DO IS=1,N\n A(IS,IZ1)=A(IS,IZ1)+AA*A(IS,IZ)\n END DO \n\t R(IZ1) =R(IZ1) +AA*R(IZ)\n\t ENDIF\n END DO \n END DO \n! Determination of changes of X stored in A(IZ,N+1)\n DXMAXV=1.E30\n60 CONTINUE \n DXMAX=0\n DO IZ=N,1,-1\n\t A(IZ,N+1)=R(IZ)\n\t DO IS=IZ+1,N\n A(IZ,N+1)=A(IZ,N+1)-A(IS,IZ)*A(IS,N+1)\n END DO \n\t DXMAX=MAX(DXMAX,ABS(A(IZ,N+1)))\n X(IZ)=X(IZ)+A(IZ,N+1)\n END DO \n IF(DXMAX.LT.DX) RETURN\n! Update of absolute value vector R\n DO IZ=1,N\n\t R(IZ)=0.\n\t DO IS=1,IZ-1\n R(IZ)=R(IZ)-A(IS,N+1)*A(IS,IZ)\n END DO \n END DO \n IF(DXMAX.GT.0.8*DXMAXV) GOTO 3\n DXMAXV=DXMAX\n GOTO 60\n END SUBROUTINE simqit\n\n\n\nEND MODULE SLAE \n", "meta": {"hexsha": "55b4f73a41c88234a02cf3b2f3f417babdd2a5df", "size": 10825, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "slae.f90", "max_stars_repo_name": "LukeMcCulloch/3D-linear-wave-resistance", "max_stars_repo_head_hexsha": "67f7621e307f9b745f435ee240890241254a3e9d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-08T15:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-08T15:23:23.000Z", "max_issues_repo_path": "slae.f90", "max_issues_repo_name": "LukeMcCulloch/3D-linear-wave-resistance", "max_issues_repo_head_hexsha": "67f7621e307f9b745f435ee240890241254a3e9d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slae.f90", "max_forks_repo_name": "LukeMcCulloch/3D-linear-wave-resistance", "max_forks_repo_head_hexsha": "67f7621e307f9b745f435ee240890241254a3e9d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.7135278515, "max_line_length": 76, "alphanum_fraction": 0.5987990762, "num_tokens": 3521, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133515091156, "lm_q2_score": 0.8479677564567913, "lm_q1q2_score": 0.7970162159429682}} {"text": "module mydefs\n\n implicit none\n\n integer, parameter :: rk = selected_real_kind(15,300)\n integer, parameter :: ik = selected_int_kind(5)\n integer, parameter :: iw1=15, iw2=16, iw3=17, iw4=18\n real(rk), parameter :: pi = 3.141592653589793238462643383279502884197_rk \n real(rk), parameter :: autoaa = 0.529177_rk\n\ncontains\n\n real(rk) function rad(ang)\n\n real(rk), intent(inout) :: ang\n real(rk) :: den\n\n den = 180.000000_rk\n rad = ang * pi / den\n\n end function rad\n\n real(rk) function deg(ang)\n\n real(rk), intent(inout) :: ang\n real(rk) :: den\n\n den = 180.000000_rk\n deg = ang * den / pi\n\n end function deg\n\n\nend module mydefs\n", "meta": {"hexsha": "b5b925a55450a77cf4be82359ffab2c7d2fa3459", "size": 680, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mydefs.f90", "max_stars_repo_name": "esertan/2drtheta", "max_stars_repo_head_hexsha": "35317e0772d9c45474ed523b1c1e363908e10bc9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mydefs.f90", "max_issues_repo_name": "esertan/2drtheta", "max_issues_repo_head_hexsha": "35317e0772d9c45474ed523b1c1e363908e10bc9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mydefs.f90", "max_forks_repo_name": "esertan/2drtheta", "max_forks_repo_head_hexsha": "35317e0772d9c45474ed523b1c1e363908e10bc9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.4285714286, "max_line_length": 80, "alphanum_fraction": 0.6308823529, "num_tokens": 222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026663679976, "lm_q2_score": 0.8688267728417087, "lm_q1q2_score": 0.796977115339602}} {"text": "module factorial_mod\ncontains\n ! computes the factorial of n\n integer function factorial(n)\n implicit none\n integer, intent(in) :: n\n integer r\n integer i\n if(n < 0) then\n write(*,*) 'Received negative input'\n stop\n end if\n r = 1\n do i = 1,n\n r = r*i\n end do\n factorial=r\n end function factorial\nend module factorial_mod\n", "meta": {"hexsha": "38b87dfa7628f07c97de87a3e2a6e9d92b6cc77d", "size": 401, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "content/code/fortran/factorial.f90", "max_stars_repo_name": "transferorbit/coderefinery_testing", "max_stars_repo_head_hexsha": "b1011345cd6ed614e702b372bd2d987521bba130", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2019-03-11T12:36:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-30T00:32:11.000Z", "max_issues_repo_path": "content/code/fortran/factorial.f90", "max_issues_repo_name": "transferorbit/coderefinery_testing", "max_issues_repo_head_hexsha": "b1011345cd6ed614e702b372bd2d987521bba130", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 126, "max_issues_repo_issues_event_min_datetime": "2016-12-13T11:12:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T20:17:17.000Z", "max_forks_repo_path": "content/code/fortran/factorial.f90", "max_forks_repo_name": "transferorbit/coderefinery_testing", "max_forks_repo_head_hexsha": "b1011345cd6ed614e702b372bd2d987521bba130", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 37, "max_forks_repo_forks_event_min_datetime": "2016-12-13T11:00:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-18T13:53:07.000Z", "avg_line_length": 20.05, "max_line_length": 45, "alphanum_fraction": 0.5710723192, "num_tokens": 105, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391558355999, "lm_q2_score": 0.8633916099737807, "lm_q1q2_score": 0.796944262825738}} {"text": "!-------------------------------------------------------------------\n!..AN IMPLICIT FD SOLVER FOR THE 1-D LINEAR CONVECTION EQUATION \n!-------------------------------------------------------------------\nModule vars\n integer, parameter :: imax=401, ntout=1 \n integer :: ntmax\n real, dimension(imax) :: wave_n\n real, dimension(imax) :: a, b1, c \n real :: sigma, d, dx=0.1, x1 , b=0.025, pi= 3.1415926 !ACOS(-1.)\nEnd module\n\nprogram IMPLICIT_FDE\n use vars\n\n call INIT !..Read the input data, and initialize the wave\n DO nt = 1,ntmax !..Start the solution loop \n\n do i = 2, imax-1\n a(i) = -(sigma/2.)-d\n b1(i) = 2.*d + 1. \n c(i) = (sigma/2.)-d\n enddo\n\n call THOMAS(imax, 2, imax-1, a, b1, c, wave_n(:))\n \n!..Output intermediate solutions\n if( MOD(nt,ntout) .eq. 0 .or. nt .eq. ntmax ) call IO(nt)\n ENDDO \n\n stop\nend program IMPLICIT_FDE\n \n!------------------------------------------------------------------------\nsubroutine INIT\n use vars\n\n write(*,'(/(a))',advance='no')' Enter sigma, d and ntmax : '\n read(*,*) sigma, d, ntmax\n x1=-imax*dx/2.\n x = x1\n do i = 1,imax !..Initialize the wave \n wave_n(i) = exp(-b * log(2.) * (x/dx)**2)\n x = x+dx\n enddo\n call IO(0)\n\n return \nend subroutine INIT\n\n!-------------------------------------------------------------------\nsubroutine IO(nt)\n use vars\n character :: fname*32,string*6,ext*3\n write(string,'(f5.3)') float(nt)/1000\n read(string,'(2x,a3)') ext\n fname = 'wave-'//ext//'.dat' \n open(1,file=fname,form='formatted')\n !write(1,*)'ZONE'\n x = x1\n do i=1,imax\n write(1,'(2e14.6)')x, wave_n(i)\n x = x+dx\n enddo\n close(1)\n return \nend\n!-------------------------------------------------------------------\nsubroutine THOMAS(imax, il, iu, a, b, c, f)\n integer :: imax, il ,iu, ilp1, iupil\n real, dimension(imax) :: a, b, c, f, x\n real :: z\n x(il) = c(il) / b(il)\n f(il) = f(il) / b(il)\n ilp1 = il+1\n do i = ilp1, iu\n z= 1. / (b(i)- a(i)*x(i-1))\n x(i)= c(i) * z \n f(i)= ( f(i) - a(i) * f(i-1) ) * z\n \n ENDDO\n iupil = iu + il\n do ii = ilp1, iu\n i = iupil - ii\n f(i) = f(i) - x(i) * f(i+1)\n ENDDO\n \n return\n end", "meta": {"hexsha": "6c7dec2d132733263dee7dc0a252457a745bc325", "size": 2282, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Homework4/hw4_bonus.f90", "max_stars_repo_name": "Atknssl/AE305-Homeworks", "max_stars_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-06T18:42:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-04T13:27:27.000Z", "max_issues_repo_path": "Homework4/hw4_bonus.f90", "max_issues_repo_name": "Atknssl/AE305-Homeworks", "max_issues_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework4/hw4_bonus.f90", "max_forks_repo_name": "Atknssl/AE305-Homeworks", "max_forks_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.9318181818, "max_line_length": 73, "alphanum_fraction": 0.4395267309, "num_tokens": 787, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966702001757, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7968693526992359}} {"text": "module mGf90\n use cholf90\n use gasdevf90\n implicit none\n\ncontains\n real function multigauss(R,mu,n) result(G)\n!!$ Generates a one dimensional array of length n containing multivariate Gaussian pseudo-random numbers\n!!$ where R is the lower-triangular Cholesky factor of the covariance matrix of the desired distribution \n!!$ and mu is a one dimensional array of length n, containing the mean value for each random variable. \n!!$ R must be a one dimensional array, containing the lower-triangular matrix stored by row, starting from the \n!!$ uppermost, leftmost entry (first row, first column). \n implicit none\n integer, intent(in) :: n\n real, intent(in) :: R(n*(n+1)/2)\n real, intent(in) :: mu(n)\n real :: Nu(n)\n dimension :: G(n)\n integer :: i, j\n \n if( n*(n+1)/2 .ne. size(R) ) then\n write(6,*) ' n*(n+1)/2 != size(R) in multiGauss '\n write(6,*) ' Cholesky factor matrix has size ', size(R) \n write(6,*) ' but you are requesting a vector of size ',n\n stop\n else\n \n!!$ generate an array of independent Gaussian variates\n do j = 1, n\n Nu(j) = gasdev()\n end do\n\n!!$ start with the desired mean, and add the product of \n!!$ [the lower-triangular Cholesky factor of the covariance matrix] x [ the vector of iid Gaussian variates]\n do i = 1, n\n G(i) = mu(i)\n do j = 1,i\n G(i) = G(i) + R( i*(i-1)/2 + j ) * Nu(j)\n end do\n end do\n\n end if\n return\n end function multigauss\nend module mGf90\n", "meta": {"hexsha": "cf5d2f6e01f076969b62f5b0300e197cd61fcd0a", "size": 1499, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/multiGauss.f90", "max_stars_repo_name": "BingzhangChen/HOT", "max_stars_repo_head_hexsha": "c166ac038cd67a0e4dd5c8512bf5d678eb07b6cc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/multiGauss.f90", "max_issues_repo_name": "BingzhangChen/HOT", "max_issues_repo_head_hexsha": "c166ac038cd67a0e4dd5c8512bf5d678eb07b6cc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/multiGauss.f90", "max_forks_repo_name": "BingzhangChen/HOT", "max_forks_repo_head_hexsha": "c166ac038cd67a0e4dd5c8512bf5d678eb07b6cc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.5869565217, "max_line_length": 111, "alphanum_fraction": 0.6357571714, "num_tokens": 438, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172601537141, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.7968380596674863}} {"text": "subroutine gausspp(a, b, l, deter)\n implicit none\n\n real, dimension(:,:), intent(inout) :: a\n real, dimension(:), intent(inout) :: b\n integer, dimension(:), intent(inout) :: l\n real, intent(out) :: deter\n\n real :: piv, z\n integer :: i, j, k, m, n, p, li, lk\n\n n = size(b)\n\n deter = 1\n\n l = (/(i,i=1,n)/)\n\n do k=1, n-1\n piv=a(l(k),k)\n p = k\n do i = k+1, n\n if(abs(piv) < abs(a(l(i), k))) then\n piv = a(l(i), k)\n p = i\n end if\n end do\n\n if(abs(piv) < 1.e-12) then\n print*, 'Pivote nulo na etapa: ', k\n print*, 'A matriz do sistema e singular! '\n stop\n end if\n\n deter=deter*piv\n\n if(p /= k) then\n\n deter = -deter\n\n m = l(k)\n l(k) = l(p)\n l(p) = m\n end if\n\n piv = a(l(k), k)\n lk = l(k)\n\n do i=k+1, n\n li = l(i)\n z=a(li,k)/piv\n\n do j=k+1,n\n a(li, j) = a(li, j) - z*a(lk, j)\n end do\n\n b(li)=b(li)-z*b(lk)\n end do\n print*, 'Etapa',k, l(:)\n end do\n piv = a(l(n),n)\n\n if(abs(piv)<1.e-12) then\n print*, 'Pivote nulo na etapa: ', n\n print*, 'A matriz do sisema e singular!'\n stop\n end if\n\n deter = deter*piv\n\nend subroutine\n", "meta": {"hexsha": "21af3072ea58bf2c97145a526d93be3a6302b54f", "size": 1184, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Practica2_gausspp/gausspp.f95", "max_stars_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_stars_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Practica2_gausspp/gausspp.f95", "max_issues_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_issues_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practica2_gausspp/gausspp.f95", "max_forks_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_forks_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.676056338, "max_line_length": 48, "alphanum_fraction": 0.4670608108, "num_tokens": 452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.8652240738888188, "lm_q1q2_score": 0.7966893908077427}} {"text": "PROGRAM LAPLACE\n INTEGER, PARAMETER :: XSIZE=11,YSIZE=11\n REAL(8), DIMENSION(1:XSIZE,1:YSIZE) :: PHIOLD,PHINEW,ERROR\n REAL :: MAXDELTA\n REAL(8) :: ERRORSUM,NSQ=XSIZE*YSIZE\n\n REAL(8), PARAMETER :: CONVERGENCE = EPSILON(ERRORSUM)\n INTEGER :: ITERATIONS = 0\n\n INTEGER :: I,J\n\n DO I=1,XSIZE\n DO J=1,YSIZE\n PHINEW(I,J) = (I*I-J*J)/(NSQ)\n END DO\n END DO\n \n PHINEW(2:XSIZE-1,2:YSIZE-1)=0\n\n open(10,file='gs_11.csv')\n\n GAUSS_ITERATION: DO\n ITERATIONS = ITERATIONS+1\n PHIOLD=PHINEW\n\n DO I=2,XSIZE-1\n DO J=2,YSIZE-1\n PHINEW(I,J)=0.25*(&\n &PHINEW(I-1,J)+&\n &PHINEW(I+1,J)+&\n &PHINEW(I,J-1)+&\n &PHINEW(I,J+1))\n END DO\n END DO\n ERROR = PHIOLD-PHINEW\n ERRORSUM = SQRT(SUM(ERROR*ERROR)/NSQ)\n write(10,*) ERRORSUM, ITERATIONS \n IF (ERRORSUM < 2*CONVERGENCE) EXIT GAUSS_ITERATION\n\n END DO GAUSS_ITERATION\n \n close(10)\nEND PROGRAM LAPLACE\n", "meta": {"hexsha": "28df421597a5aad4268a7a95c61bdc3ba068f745", "size": 1063, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "a3/gs/laplace.f95", "max_stars_repo_name": "cheekujodhpur/ae320", "max_stars_repo_head_hexsha": "7eb6a6d1fbf3fc2dcde546b96505e365a0b134a3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-04-11T21:21:24.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-15T06:20:02.000Z", "max_issues_repo_path": "a3/gs/laplace.f95", "max_issues_repo_name": "cheekujodhpur/ae320", "max_issues_repo_head_hexsha": "7eb6a6d1fbf3fc2dcde546b96505e365a0b134a3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "a3/gs/laplace.f95", "max_forks_repo_name": "cheekujodhpur/ae320", "max_forks_repo_head_hexsha": "7eb6a6d1fbf3fc2dcde546b96505e365a0b134a3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.1590909091, "max_line_length": 62, "alphanum_fraction": 0.5230479774, "num_tokens": 371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541593883189, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7965852201806652}} {"text": "program exo4_3\n \n ! A program which reads an integer value limit and \n ! prints the coefficients of the first limit lines of this Pascal triangle.\n implicit none\n integer :: limit, k, n, iter_n, iter_k\n\n write(6, '(a)', advance='no') \"Pascal triangle - Numbe of rows: \"\n read(5, '(i3)') limit\n do iter_n = 0, limit-1\n n = iter_n\n do iter_k = 0, n\n k = iter_k\n write(6, '(i3)', advance='no') pascal_rule(n, k)\n end do\n print *, ''\n end do\n \ncontains\n recursive integer function factorial(number) result(facto)\n integer, intent(in) :: number\n if ( number .eq. 0 .or. number .eq. 1 ) then\n facto = 1\n else\n facto = number * factorial(number-1)\n end if \n end function factorial\n\n ! This function implements \"n choose k\" => nCk = n! / ((n - k)!k!)\n integer function pascal_rule(n, k) result(binomial_coefficient)\n integer, intent(in) :: n,k\n binomial_coefficient = factorial(n) / (factorial(n-k) * factorial(k))\n end function pascal_rule \n\nend program exo4_3", "meta": {"hexsha": "3b575a3e76146b81719ea3afb82956aa0fef55d3", "size": 1114, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exo/exo4_3.f90", "max_stars_repo_name": "eusojk/fortran-programs", "max_stars_repo_head_hexsha": "60fe727a341615153e044e7ac7deabc435444e39", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exo/exo4_3.f90", "max_issues_repo_name": "eusojk/fortran-programs", "max_issues_repo_head_hexsha": "60fe727a341615153e044e7ac7deabc435444e39", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exo/exo4_3.f90", "max_forks_repo_name": "eusojk/fortran-programs", "max_forks_repo_head_hexsha": "60fe727a341615153e044e7ac7deabc435444e39", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.8285714286, "max_line_length": 79, "alphanum_fraction": 0.5861759425, "num_tokens": 311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9715639677785087, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7965788204574558}} {"text": "program tarefa5\n \n ! Definindo a variáveis com precisão dupla \n real*8 :: dlnx, dx, derro, dlogx\n \n ! definindo precisão e erro inicial \n eprec = 10e-5\n erro = 2*eprec\n slnx = 0e0\n n = 0\n \n ! Recebe o valor de x\n print *, 'Digite um x Real, 0 < x < 2:'\n read (*,*) x\n\n ! verifica se está dentro do raio de convergencia\n if ((x.le.0) .or. (2e0.le.x)) then\n print *, 'x está fora do raio de convergencia'\n ! sai do programa\n stop\n end if\n\n slogx = log(x)\n\n ! calcula a aproximação até atingir o erro eprec\n ! ou até que não haja mais variação no erro \n do while ((erro.ge.eprec) .and. (erro.ne.abs(slogx - slnx)))\n erro = abs(slogx - slnx)\n n = n + 1\n slnx = slnx -(1e0 - x)**n/n\n end do\n \n print *, 'Precisão Simples'\n print *, 'Num iter: ', n\n print *, 'log(x): ', slogx\n print *, 'Aprox: ', slnx\n print *, 'erro: ', erro\n \n ! valores iniciais para a precisão dupla\n dx = x\n derro = 0d0\n dlnx = 0d0\n n = 0\n \n dlogx = dlog(dx)\n \n ! calcula a aproximação até que não haja mais variação do erro\n do while (derro.ne.abs(dlogx - dlnx))\n derro = abs(dlogx - dlnx)\n n = n + 1\n dlnx = dlnx -(1 - dx)**n/n\n end do\n \n print *, ''\n print *, ''\n print *, 'Precisão Dupla'\n print *, 'Num iter: ', n-1\n print *, 'dlog(x): ', dlogx\n print *, 'Aprox: ', dlnx\n print *, 'erro: ', derro\n \nend program tarefa5\n", "meta": {"hexsha": "68b5e726390456394ba982ebfb12e759ff66225c", "size": 1516, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "projeto-1/tarefa-5/tarefa-5-10407962.f90", "max_stars_repo_name": "ArexPrestes/introducao-fisica-computacional", "max_stars_repo_head_hexsha": "bf6e7a0134c11ddbaf9125c42eb0982250f970d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "projeto-1/tarefa-5/tarefa-5-10407962.f90", "max_issues_repo_name": "ArexPrestes/introducao-fisica-computacional", "max_issues_repo_head_hexsha": "bf6e7a0134c11ddbaf9125c42eb0982250f970d9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "projeto-1/tarefa-5/tarefa-5-10407962.f90", "max_forks_repo_name": "ArexPrestes/introducao-fisica-computacional", "max_forks_repo_head_hexsha": "bf6e7a0134c11ddbaf9125c42eb0982250f970d9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0634920635, "max_line_length": 66, "alphanum_fraction": 0.5237467018, "num_tokens": 534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009503523291, "lm_q2_score": 0.8705972667296309, "lm_q1q2_score": 0.7965102667050794}} {"text": "! sum all the elements of the array\nreal function sum_array (array, n1, n2, n3)\n implicit none\n integer :: n1,n2,n3,i1,i2,i3\n real array(n1,n2,n3)\n\n do i3=1, n3\n do i2=1, n2\n do i1=1, n1\n sum_array = sum_array + array(i1,i2,i3)\n end do\n end do\n end do\nend function sum_array\n\nprogram main\n implicit none\n integer :: n1,n2,n3,L,is1,ie1,is2,ie2,is3,ie3\n parameter(L=4, n1=100, n2=100, n3=100)\n real, dimension(:,:,:), allocatable :: u,v\n real, dimension(-L:L) :: c\n real result, sum_array\n\n is1=1;ie1=n1\n is2=1;ie2=n2\n is3=1;ie3=n3\n\n c = 3.\n\n allocate(v(n1,n2,n3))\n allocate(u(n1,n2,n3))\n\n ! Simple case\n u = 1.; v = 1.;\n call stencil8(u,v,c,n1,n2,n3,is1,ie1,is2,ie2,is3,ie3)\n result = sum_array (u, n1, n2, n3)\n PRINT *, (\"the sum is\"), result\n deallocate(v)\n deallocate(u)\n\nend program main\n\nsubroutine stencil8(u,v,c,n1,n2,n3,is1,ie1,is2,ie2,is3,ie3)\n ! Stencil length : 2*L\n\n implicit none\n integer :: i1,i2,i3,is1,ie1,is2,ie2,is3,ie3,n1,n2,n3,L\n parameter(L=4)\n real, dimension(n1,n2,n3) :: u, v\n real, dimension(-L:L) :: c\n real c_4,c_3,c_1, c_2, c0, c1, c2,c3,c4\n\n c_4 = c(-4); c_3 = c(-3); c_2 = c(-2); c_1 = c(-1);\n c0 = c(0);\n c4 = c(4); c3 = c(3); c2 = c(2); c1 = c(1);\n\n do i3=is3+L,ie3-L\n do i2=is2+L,ie2-L\n do i1=is1+L,ie1-L\n u(i1,i2,i3) = &\n + c_4 * (v(i1-4,i2,i3) + v(i1,i2-4,i3) + v(i1,i2,i3-4))&\n + c_3 * (v(i1-3,i2,i3) + v(i1,i2-3,i3) + v(i1,i2,i3-3))&\n + c_2 * (v(i1-2,i2,i3) + v(i1,i2-2,i3) + v(i1,i2,i3-2))&\n + c_1 * (v(i1-1,i2,i3) + v(i1,i2-1,i3) + v(i1,i2,i3-1))&\n + c0 * v(i1, i2,i3) * 3&\n + c1 * (v(i1+1,i2,i3) + v(i1,i2+1,i3) + v(i1,i2,i3+1))&\n + c2 * (v(i1+2,i2,i3) + v(i1,i2+2,i3) + v(i1,i2,i3+2))&\n + c3 * (v(i1+3,i2,i3) + v(i1,i2+3,i3) + v(i1,i2,i3+3))&\n + c4 * (v(i1+4,i2,i3) + v(i1,i2+4,i3) + v(i1,i2,i3+4))\n end do\n end do\n end do\n\nend subroutine stencil8\n", "meta": {"hexsha": "3af3447d7bb475a85b2be53c6defa4d07be04cff", "size": 2030, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/SAC-New/stencil_3d_8.f90", "max_stars_repo_name": "DVSR1966/par4all", "max_stars_repo_head_hexsha": "86b33ca9da736e832b568c5637a2381f360f1996", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 51, "max_stars_repo_stars_event_min_datetime": "2015-01-31T01:51:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T02:01:50.000Z", "max_issues_repo_path": "packages/PIPS/validation/SAC-New/stencil_3d_8.f90", "max_issues_repo_name": "DVSR1966/par4all", "max_issues_repo_head_hexsha": "86b33ca9da736e832b568c5637a2381f360f1996", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2017-05-29T09:29:00.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-11T16:01:39.000Z", "max_forks_repo_path": "packages/PIPS/validation/SAC-New/stencil_3d_8.f90", "max_forks_repo_name": "DVSR1966/par4all", "max_forks_repo_head_hexsha": "86b33ca9da736e832b568c5637a2381f360f1996", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-03-26T08:05:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T02:01:51.000Z", "avg_line_length": 27.0666666667, "max_line_length": 72, "alphanum_fraction": 0.515270936, "num_tokens": 961, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521253, "lm_q2_score": 0.8740772335247531, "lm_q1q2_score": 0.7964414296299138}} {"text": "! Las variables de tipo complex son aquellas que almacenan numeros complejos.\n! Un numero complejo está compuesto por una parte real y otra imaginaria.\n! Dos unidades numericas consecutivas almacenan estas dos partes.\n\n!Por ejemplo, el número representado por (1.0, -1.0) es igual a 1.0 - 1.0i\n!La función generica cmplx() crea un número complejo. Produce un resultado que\n!cuyas partes imaginarias y reales son de precisión simple.\n\n! Las versiones más modernas de Fortran (90/95) nos permiten tener mayor control sobre la precisión de\n! datos de tipo real e integer mediante el especificador kind.\n\n!En la programación científica, uno usualmente necesita saber el rango y precisión de los datos\n!del hardware en el que se está trabajando.\n\n!La función intrinseca kind() nos permite consultar los detalles de la representación de datos del hardware\n!en el que se está trabajando.\n\nprogram tipos_compl\nreal :: a\nreal :: b\ncomplex :: z\ncomplex, parameter :: z2 = (2.0, 3.1)\n\ncomplex(kind=4) :: z_4bytes\ncomplex(kind=8) :: z_8bytes\ncomplex(kind=16) :: z_16bytes\n\nz = cmplx(a, b)\nprint *, z\n\nprint *, z2\n\nprint *, \"¿Cuántos bytes puede almacenar una variable de tipo complex por defecto?: \", kind(z)\n\nprint *, \"¿Cuántos bytes almacena z_4bytes?: \", kind(z_4bytes)\n\nprint *, \"¿Cuántos bytes almacena z_8bytes?: \", kind(z_8bytes)\n\nprint *, \"¿Cuántos bytes almacena z_16bytes?: \", kind(z_16bytes)\n\nend program tipos_compl\n", "meta": {"hexsha": "ece62063581dfd6640e175073c917b12fff7ce6c", "size": 1417, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Constantes, variables y tipos de datos/tipos_compl.f90", "max_stars_repo_name": "kotoromo/Fortran-Basico", "max_stars_repo_head_hexsha": "1d37a82754acd1c231981adc3dea2d606e76d6c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Constantes, variables y tipos de datos/tipos_compl.f90", "max_issues_repo_name": "kotoromo/Fortran-Basico", "max_issues_repo_head_hexsha": "1d37a82754acd1c231981adc3dea2d606e76d6c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Constantes, variables y tipos de datos/tipos_compl.f90", "max_forks_repo_name": "kotoromo/Fortran-Basico", "max_forks_repo_head_hexsha": "1d37a82754acd1c231981adc3dea2d606e76d6c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.7380952381, "max_line_length": 107, "alphanum_fraction": 0.752293578, "num_tokens": 408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088025362857, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.7963594592076811}} {"text": " MODULE MATRIXUTIL\n USE CONFIG\n\n IMPLICIT NONE\n PRIVATE\n PUBLIC :: MATRIX_PRINT, MATRIX_IDENT, MATRIX_TRANSLATE,\n + MATRIX_SCALE, MATRIX_ROTATE, MATRIX_MULT\n CONTAINS\n SUBROUTINE MATRIX_PRINT(MATRIX)\n REAL(DP), INTENT(IN) :: MATRIX(:, :)\n INTEGER :: ROW, COL\n DO ROW=1, SIZE(MATRIX, 2)\n WRITE (0,'(*(F10.3))')\n + (MATRIX(COL, ROW), COL=1, SIZE(MATRIX, 1))\n ENDDO\n END SUBROUTINE MATRIX_PRINT\n\n PURE SUBROUTINE MATRIX_IDENT(M)\n REAL(DP), INTENT(INOUT) :: M(:, :)\n INTEGER :: I\n\n M(:, :) = 0\n FORALL(I = 1:MIN(SIZE(M, 1), SIZE(M, 2))) M(I, I) = 1\n END SUBROUTINE MATRIX_IDENT\n\n PURE SUBROUTINE MATRIX_TRANSLATE(M, S)\n REAL(DP), INTENT(INOUT) :: M(:, :)\n REAL(DP), INTENT(IN) :: S(3)\n INTEGER :: I\n\n CALL MATRIX_IDENT(M)\n FORALL(I = 1:3) M(4, I) = S(I)\n END SUBROUTINE MATRIX_TRANSLATE\n\n PURE SUBROUTINE MATRIX_SCALE(M, S)\n REAL(DP), INTENT(INOUT) :: M(:, :)\n REAL(DP), INTENT(IN) :: S(3)\n INTEGER :: I\n\n CALL MATRIX_IDENT(M)\n FORALL (I = 1:MIN(SIZE(M, 1), SIZE(M, 2), 3))\n M(I, I) = M(I, I) * S(I)\n END FORALL\n END SUBROUTINE MATRIX_SCALE\n\n PURE SUBROUTINE MATRIX_ROTATE(M, S, D)\n REAL(DP), INTENT(INOUT) :: M(:, :)\n REAL(DP), INTENT(IN) :: S\n INTEGER, INTENT(IN) :: D ! 1: X, 2: Y, 3: Z\n INTEGER :: I\n REAL(DP) :: X(4)\n INTEGER, PARAMETER :: RM(2, 4, 3) =\n + RESHAPE([2,2, 2,3, 3,2, 3,3,\n + 1,1, 3,1, 1,3, 3,3,\n + 1,1, 1,2, 2,1, 2,2], [2, 4, 3])\n\n X = [COS(S), -SIN(S), SIN(S), COS(S)]\n CALL MATRIX_IDENT(M)\n FORALL (I = 1:4) M(RM(1, I, D), RM(2, I, D)) = X(I)\n END SUBROUTINE MATRIX_ROTATE\n\n PURE FUNCTION MATRIX_MULT(A, B) RESULT(C)\n ! A n x m SIZE(A, 2), SIZE(A, 1)\n ! B m x p SIZE(B, 2), SIZE(A, 2)\n ! C n x p SIZE(B, 1), SIZE(A, 2)\n\n REAL(DP), INTENT(IN), DIMENSION(:, :) :: A, B\n REAL(DP) :: C(SIZE(B,1), SIZE(A,2))\n INTEGER :: I, J, K\n\n C(:, :) = 0\n DO I = 1, SIZE(A, 2)\n DO J = 1, SIZE(B, 2)\nC DO K = 1, SIZE(B, 1)\n C(:, I) = C(:, I) + A(J, I) * B(:, J)\nC END DO\n END DO\n END DO\n END FUNCTION MATRIX_MULT ! possibly faster than MATMUL()\n END MODULE MATRIXUTIL\n\n", "meta": {"hexsha": "8e4f3a3c2f4f186e4dce1bff6da7a97e6d78e0e8", "size": 2894, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/matrixutil.for", "max_stars_repo_name": "AnAverageHuman/graphics3", "max_stars_repo_head_hexsha": "2df87dc2d5dad375a876263cdff54171543419fb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/matrixutil.for", "max_issues_repo_name": "AnAverageHuman/graphics3", "max_issues_repo_head_hexsha": "2df87dc2d5dad375a876263cdff54171543419fb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/matrixutil.for", "max_forks_repo_name": "AnAverageHuman/graphics3", "max_forks_repo_head_hexsha": "2df87dc2d5dad375a876263cdff54171543419fb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.2926829268, "max_line_length": 68, "alphanum_fraction": 0.403593642, "num_tokens": 871, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480237330998, "lm_q2_score": 0.8670357683915537, "lm_q1q2_score": 0.7963552183267385}} {"text": "module procedures\nimplicit none\ncontains\n\nsubroutine writes2d (A)\n real(kind=8), allocatable, dimension(:,:), intent(in) :: A\n integer :: n, m, i, j\n\n n = size(A, 1)\n m = size(A, 2)\n\n do i = 1,n\n write(*,'(20F8.3)') (A(i,j), j = 1, m)\n end do\n write(*,*)\nend subroutine writes2d\n\nsubroutine writes1d (A)\n real(kind=8), allocatable, dimension(:), intent(in) :: A\n integer :: n, i\n \n n = size(A)\n\n! write(*,*) (A(i), i = 1, n)\n write(*,'(20F8.3)') (A(i), i = 1, n)\n write(*,*)\nend subroutine writes1d\n\nfunction inv(A) result(Ainv)\n real(kind=8), dimension(:,:), intent(in) :: A\n real(kind=8), dimension(size(A,1),size(A,2)) :: Ainv\n\n real(kind=8), dimension(size(A,1)) :: work ! work array for LAPACK\n integer, dimension(size(A,1)) :: ipiv ! pivot indices\n integer :: n, info\n\n ! Store A in Ainv to prevent it from being overwritten by LAPACK\n Ainv = A\n n = size(A,1)\n\n ! DGETRF computes a LU factorization of a general M-by-N matrix\n call DGETRF(n, n, Ainv, n, ipiv, info)\n\n if (info /= 0) then\n stop 'Matrix is numerically singular!'\n end if\n\n ! DGETRI computes the inverse of a matrix using the LU factorization\n ! computed by DGETRF.\n call DGETRI(n, Ainv, n, ipiv, work, n, info)\n\n if (info /= 0) then\n stop 'Matrix inversion failed!'\n end if\n\nend function inv\n\nreal(kind=8) function matnorm_inf(A)\n real(kind=8), allocatable, dimension(:,:), intent(in) :: A\n real(kind=8), allocatable, dimension(:) :: rowsums\n integer :: n, i, j\n\n n = size(A,1)\n allocate(rowsums(n))\n\n do i = 1, n\n rowsums(i) = 0.0\n do j = 1, n\n rowsums(i) = rowsums(i) + dabs(A(i,j))\n end do\n end do\n\n matnorm_inf = maxval(rowsums)\n deallocate (rowsums)\nend function matnorm_inf\n\nreal(kind=8) function matnorm_one(A)\n real(kind=8), allocatable, dimension(:,:), intent(in) :: A\n real(kind=8), allocatable, dimension(:) :: columnsums\n integer :: n, i, j\n\n n = size(A,1)\n allocate(columnsums(n))\n\n do i = 1, n\n columnsums(i) = 0.0\n do j = 1, n\n columnsums(i) = columnsums(i) + dabs(A(j,i))\n end do\n end do\n\n matnorm_one = maxval(columnsums)\n deallocate (columnsums)\nend function matnorm_one\n\nsubroutine TrueRelativeError_infinity_norm (A, residual, X_new, TRE)\n real(kind=8), allocatable, dimension(:,:), intent(in) :: A\n real(kind=8), allocatable, dimension(:), intent(in) :: X_new, residual\n\n real(kind=8), allocatable, dimension(:,:) :: work_matrix, work_residual\n real(kind=8), intent(out) :: TRE\n\n allocate (work_matrix (size(A,1),size(A,2)), work_residual(size(residual),1))\n\n work_matrix = matmul(inv(A),work_residual)\n TRE = matnorm_inf(work_matrix)/maxval(X_new)\n\nend subroutine TrueRelativeError_infinity_norm\n\nsubroutine TrueRelativeError_one_norm (A, residual, X_new, TRE)\n real(kind=8), allocatable, dimension(:,:), intent(in) :: A\n real(kind=8), allocatable, dimension(:), intent(in) :: X_new, residual\n\n real(kind=8), allocatable, dimension(:,:) :: work_matrix, work_residual\n real(kind=8), intent(out) :: TRE\n\n allocate (work_matrix (size(A,1),size(A,2)), work_residual(size(residual),1))\n\n work_matrix = matmul(inv(A),work_residual)\n TRE = matnorm_one(work_matrix)/sum(X_new)\n\nend subroutine TrueRelativeError_one_norm\n\nsubroutine Gauss_Siedel (A, B, X_old, n, tolerance, X_new)\n real(kind=8), allocatable, dimension(:,:), intent(inout) :: A\n real(kind=8), allocatable, dimension(:), intent(in) :: B\n real(kind=8), allocatable, dimension(:), intent(inout) :: X_old\n integer, intent(in) :: n\n real(kind=8), intent(in) :: tolerance\n real(kind=8), allocatable, dimension(:), intent(out) :: X_new\n real(kind=8), allocatable, dimension(:) :: residual, residual_abs\n integer :: i, j, iters\n real(kind=8) TRE_inf, TRE_one\n\n allocate ( X_new(n), residual(n), residual_abs(n) )\n\n do i = 1, n\n residual_abs(i) = i !initialize\n end do\n\n open (unit=9, file='plot.dat', status='new', action='write')\n\n iters = 0\n do while (maxval(residual_abs) .ge. tolerance)\n ! Find [x]:\n do i = 1, n\n X_new(i) = B(i)\n do j = 1, i-1\n X_new(i) = X_new(i) - A(i,j)*X_new(j)\n end do\n do j = i+1, n\n X_new(i) = X_new(i) - A(i,j)*X_old(j)\n end do\n X_new(i) = X_new(i)/A(i,i)\n end do\n iters = iters + 1\n ! Determine the residual: \n do i = 1, n\n residual(i) = B(i)\n do j = 1, n\n residual(i) = residual(i) - A(i,j)*X_new(j)\n end do\n end do\n do i = 1, n\n residual_abs(i) = dabs(residual(i))\n end do\n !Determine the true relative error:\n call TrueRelativeError_infinity_norm (A, residual, X_new, TRE_inf)\n call TrueRelativeError_one_norm (A, residual, X_new, TRE_one)\n ! Write the output:\n write(*,*)\n write(*,*) \"---------------------------------------------\"\n write(*,*) \"iteration:\", iters\n write(*,*) \"---------------------------------------------\"\n call writes1d(X_new)\n write(*,*)\n write(*,*) \"residual:\"\n call writes1d(residual)\n write(*,*) \"TrueRelativeEror (infinity norm), rueRelativeEror (one norm)\"\n write(*,*) TRE_inf, TRE_one\n write(*,*)\n write(9,*) iters, maxval(residual_abs)\n do i = 1, n\n X_old(i) = X_new(i)\n end do\n end do\n\n close(9)\nend subroutine Gauss_Siedel\n\nend module procedures\n", "meta": {"hexsha": "7d4c0e45cd5f0e79f5955316815f0b4f54240b98", "size": 5418, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ME_Numerical_Methods/HW5/ex2/with_pivoting/mod.f95", "max_stars_repo_name": "ElenaKusevska/Fortran_exercises", "max_stars_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ME_Numerical_Methods/HW5/ex2/with_pivoting/mod.f95", "max_issues_repo_name": "ElenaKusevska/Fortran_exercises", "max_issues_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ME_Numerical_Methods/HW5/ex2/with_pivoting/mod.f95", "max_forks_repo_name": "ElenaKusevska/Fortran_exercises", "max_forks_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.21875, "max_line_length": 80, "alphanum_fraction": 0.5996677741, "num_tokens": 1699, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762114, "lm_q2_score": 0.8856314723088733, "lm_q1q2_score": 0.796290193923923}} {"text": "PROGRAM tminim\r\n\r\n! Use minim to maximize the objective function:\r\n\r\n! 1/{1 + (x-y)^2} + sin(pi.y.z/2) + exp[-{(x+z)/y - 2}^2]\r\n\r\n! with respect to x, y and z.\r\n! We will actually minimize its negative.\r\n! The maximum occurs at x = y = z = +/-sqrt(4n+1) for any integer n.\r\n\r\nUSE Nelder_Mead\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(14, 60)\r\nREAL (dp) :: object, p(3), simp, step(3), stopcr, var(3)\r\nINTEGER :: ier, iprint, iquad, maxf, nloop, nop\r\nLOGICAL :: first\r\n\r\nINTERFACE\r\n SUBROUTINE objfun(p, func)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(14, 60)\r\n REAL (dp), INTENT(IN) :: p(:)\r\n REAL (dp), INTENT(OUT) :: func\r\n END SUBROUTINE objfun\r\nEND INTERFACE\r\n\r\n! Set up starting values & step sizes.\r\n! Parameters p(1), p(2), p(3) are x, y & z.\r\n\r\np(1) = 0._dp\r\np(2) = 1._dp\r\np(3) = 2._dp\r\nstep = 0.4_dp\r\nnop = 3\r\n\r\n! Set max. no. of function evaluations = 250, print every 10.\r\n\r\nmaxf = 250\r\niprint = 10\r\n\r\n! Set value for stopping criterion. Stopping occurs when the\r\n! standard deviation of the values of the objective function at\r\n! the points of the current simplex < stopcr.\r\n\r\nstopcr = 1.d-04\r\nnloop = 6\r\n\r\n! Fit a quadratic surface to be sure a minimum has been found.\r\n\r\niquad = 1\r\n\r\n! As function value is being evaluated in REAL (dp), it\r\n! should be accurate to about 15 decimals. If we set simp = 1.d-6,\r\n! we should get about 9 dec. digits accuracy in fitting the surface.\r\n\r\nsimp = 1.d-6\r\n\r\n! Now call MINIM to do the work.\r\n\r\nfirst = .true.\r\nDO\r\n CALL minim(p, step, nop, object, maxf, iprint, stopcr, nloop, &\r\n iquad, simp, var, objfun, ier)\r\n\r\n! If ier > 0, try a few more function evaluations.\r\n\r\n IF (ier == 0) EXIT\r\n IF (.NOT. first) STOP\r\n first = .false.\r\n maxf = 100\r\nEND DO\r\n\r\n! Successful termination.\r\n\r\nWRITE(*, 900) object, p\r\n900 FORMAT(' Success !'/' Objective function = ', f12.6/ ' at: ', 3f12.6)\r\nWRITE(*, 910) var\r\n910 FORMAT(' Elements of var = ', 3f12.6)\r\n\r\nSTOP\r\n\r\nEND PROGRAM tminim\r\n\r\n\r\n\r\nSUBROUTINE objfun(p, func)\r\n\r\n! This is the subroutine which the user must write.\r\n! Remember that we are minimizing the negative of the function we\r\n! really want to maximize.\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(14, 60)\r\nREAL (dp), INTENT(IN) :: p(:)\r\nREAL (dp), INTENT(OUT) :: func\r\n\r\n! Local variables\r\n\r\nREAL (dp), PARAMETER :: half = 0.5_dp, one = 1._dp, pi = 3.14159265357989_dp, &\r\n two = 2._dp\r\nREAL (dp) :: x, y, z\r\n\r\nx = p(1)\r\ny = p(2)\r\nz = p(3)\r\nfunc = -one/(one + (x-y)**2) - SIN(half*pi*y*z) - EXP(-((x+z)/y - two)**2)\r\nRETURN\r\nEND SUBROUTINE objfun\r\n\r\n", "meta": {"hexsha": "04aa13e581b1a299bea7a30149c20d578827eef5", "size": 2687, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/t_minim.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/t_minim.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/t_minim.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 24.4272727273, "max_line_length": 80, "alphanum_fraction": 0.6096017864, "num_tokens": 865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248225478306, "lm_q2_score": 0.8479677506936879, "lm_q1q2_score": 0.7962627666214234}} {"text": "program isingmodel\n\n! JS: NOTE: There is a book on reserve in the science library,\n! JS: David Chandler, \"Introduction to Modern Statistical Mechanics\"\n! JS: that describes both the Ising model and the Monte Carlo procedure\n! JS: in some depth. It might be a useful resource if you get stuck.\n\n! array, defining variables\n\nimplicit none\nreal :: kT, E, E2, M, C, paccept,ptrial, Estart,Eflip, Etot\n\ninteger :: col, row, east,west,north,south\ninteger :: nMC\ninteger, parameter :: numL = 24 ! the number of row or column\ninteger, parameter :: J = -1 ! define a ferromagnetic system\ninteger, dimension(:,:), allocatable :: spin \n\nallocate(spin(numL,numL))\n\n! random number generator\ncall random_seed()\n\n! initialized our spin array\ndo col=1,numL\n do row=1,numL\n call random_number(paccept)\n if (paccept .lt. 0.5) then\n spin(col,row) = +1\n else \n spin(col,row) = -1\n end if\n end do\nend do\nwrite(*,*), 'print the initial configurations :', spin\n! program structure:\n\n! defining the loops (and what do we mean by loops)\n\n! loop over temperature (kT in units of the coupling, J)\n\ndo kT=4.0, 0.1, -0.05 !JS: Start at kT=4, and go to kT=0.1 in steps of -0.05\n\n! JS: First, run a set of MC steps to equilibrate our system. \n! JS: In other words, so that the configuration of the spins is\n! JS: in an equilibrium configuration consistent with Boltzman's laws\n! JS: for the particular temperature \n\n! loop MC trials\n do nMC=1,10000\n\n! spatial loop in the 2D plane (incorporate pbc )\n\n do col=1,numL\n do row=1,numL\n\n east = col+1\n west = col-1\n north = row-1\n south = row+1\n\n if (col.eq.1) west = numL\n if (col.eq.numL) east = 1\n if (row.eq.1) north = numL\n if (row.eq.numL) south = 1\n\n! try flip a spin at position (col,row)\n! calculate energy (function)\n\n Estart = J*(spin(col,row)*spin(east,row) &\n + spin(col,row)*spin(west,row) &\n + spin(col,row)*spin(col,north) &\n + spin(col,row)*spin(col,south) )\n\n Eflip = J*((-spin(col,row))*spin(east,row) &\n + (-spin(col,row))*spin(west,row) &\n + (-spin(col,row))*spin(col,north) &\n + (-spin(col,row))*spin(col,south) )\n\n! acceptance/rejectance for MC algorithm (define as subroutine?)\n\n if (Eflip .lt. Estart) then \n spin(col,row) = -spin(col,row)\n else \n call random_number(paccept)\n ptrial = EXP(-(Eflip-Estart)/kT)\n\n if (paccept .lt. ptrial) then\n spin(col,row) = -spin(col,row)\n end if\n end if\n\n end do\n end do\n\n end do ! loop over nMC\n \n!Caculate the total energy of the final configuration\n \n! JS: Now that the above has finished, and we are in equilibrium,\n! JS: run another MC cycle again, this time to collect statistics\n! JS: In other words, another do-loop over nMC, row, col, etc.\n! JS: flipping spins as appropriate, etc.\n\n! JS: BUT now, every time (mod(nMC, 50) .eq. 0), collect E, E^2, M to calculate\n! JS: averages. This E will have to be the total energy of the entire system\n! JS: calculated over all the spins. You might want to create functions to \n! JS: give you the value of E, M, E^2, or you could just do it inline.\n\n! JS: When the datacollection is over (you have completed this second run of\n! JS: nMC steps), it will be time to output the averages.\n\n!OUTPUT: Graphs; (Averages) Heat Capacity (-^2, ;derivative of , \n! Temperature, Energy (to get Heat Capacity), Magnetization \n! JS: (You will want to report these as an intensive property, \n! JS: i.e., /N, C/N, /N, where N is the total number of spins (16*16)\n\nend do !JS: loop over kT values (slowly cooling the system by lowering kT)\n\ncall count_Etot(numL,spin,Etot)\nwrite(*,*), 'print the equilibrium configurations :', spin\nwrite(*,*),\"Temperature =\", kT\nwrite(*,*),\"the total energy at this Temperature =\", Etot\ndeallocate(spin)\n\n\ncontains \n\nsubroutine count_Etot(numL,spin,Etot)\nimplicit none\ninteger,intent(in) :: numL\ninteger,dimension(numL,numL),intent(in) :: spin\nreal,intent(out) :: Etot\nEtot = sum(spin)\nend subroutine count_Etot\n\nend program isingmodel\n", "meta": {"hexsha": "aff9788607fa2243937fd335abd80a3cb4473518", "size": 4364, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ising_start.f90", "max_stars_repo_name": "KarimElgammal/monte-carlo-ising-model-simulation", "max_stars_repo_head_hexsha": "de1c57c353f465343dae22f86e159de2f4c1ca35", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-07T09:33:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-07T09:33:37.000Z", "max_issues_repo_path": "ising_start.f90", "max_issues_repo_name": "KarimElgammal/monte-carlo-ising-model-simulation", "max_issues_repo_head_hexsha": "de1c57c353f465343dae22f86e159de2f4c1ca35", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ising_start.f90", "max_forks_repo_name": "KarimElgammal/monte-carlo-ising-model-simulation", "max_forks_repo_head_hexsha": "de1c57c353f465343dae22f86e159de2f4c1ca35", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.6231884058, "max_line_length": 81, "alphanum_fraction": 0.6310724106, "num_tokens": 1231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545348152283, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.7961975732896964}} {"text": "PROGRAM LAPLACE\n INTEGER, PARAMETER :: XSIZE=101,YSIZE=101\n REAL(8), DIMENSION(1:XSIZE,1:YSIZE) :: PHIOLD,PHINEW,ERROR\n REAL :: MAXDELTA\n REAL(8) :: ERRORSUM,NSQ=XSIZE*YSIZE\n\n REAL(8), PARAMETER :: CONVERGENCE = EPSILON(ERRORSUM)\n INTEGER :: ITERATIONS = 0\n\n INTEGER :: I,J\n\n DO I=1,XSIZE\n DO J=1,YSIZE\n PHINEW(I,J) = (I*I-J*J)/(NSQ)\n END DO\n END DO\n \n PHINEW(2:XSIZE-1,2:YSIZE-1)=0\n\n open(10,file='jacobi_101.csv')\n\n JACOBI_ITERATION: DO\n ITERATIONS = ITERATIONS+1\n PHIOLD=PHINEW\n\n PHINEW(2:XSIZE-1,2:YSIZE-1)=0.25*(&\n &PHIOLD(1:XSIZE-2,2:YSIZE-1)+&\n &PHIOLD(3:XSIZE,2:YSIZE-1)+&\n &PHIOLD(2:XSIZE-1,1:YSIZE-2)+&\n &PHIOLD(2:XSIZE-1,3:YSIZE))\n ERROR = PHIOLD-PHINEW\n ERRORSUM = SQRT(SUM(ERROR*ERROR)/NSQ)\n write(10,*) ERRORSUM, ITERATIONS \n IF (ERRORSUM < 2*CONVERGENCE) EXIT JACOBI_ITERATION\n\n END DO JACOBI_ITERATION\n \n close(10)\nEND PROGRAM LAPLACE\n", "meta": {"hexsha": "48d34a6f8ec480dca32d3cebb911a616e2668b55", "size": 1017, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "a3/jacobi/laplace.f95", "max_stars_repo_name": "cheekujodhpur/ae320", "max_stars_repo_head_hexsha": "7eb6a6d1fbf3fc2dcde546b96505e365a0b134a3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-04-11T21:21:24.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-15T06:20:02.000Z", "max_issues_repo_path": "a3/jacobi/laplace.f95", "max_issues_repo_name": "cheekujodhpur/ae320", "max_issues_repo_head_hexsha": "7eb6a6d1fbf3fc2dcde546b96505e365a0b134a3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "a3/jacobi/laplace.f95", "max_forks_repo_name": "cheekujodhpur/ae320", "max_forks_repo_head_hexsha": "7eb6a6d1fbf3fc2dcde546b96505e365a0b134a3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.425, "max_line_length": 62, "alphanum_fraction": 0.5801376598, "num_tokens": 389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.7961834940874984}} {"text": "subroutine shape1(s,nnode,shape,deriv)\n\n!-----------------------------------------------------------------------\n!\n! This routine evaluates shape functions and their first derivates \n! for 1-d continuos with 2 3 4 & 5 nodes\n!\n!-----------------------------------------------------------------------\n\n use typre\n implicit none\n integer(ip), intent(in) :: nnode\n real(rp), intent(in) :: s\n real(rp), intent(out) :: deriv(nnode), shape(nnode)\n real :: s1, s2, s3, s4, a, c\n\n if(nnode==2) then \n shape(1)= 0.5_rp*(1.0_rp-s) ! 1 2\n shape(2)= 0.5_rp*(1.0_rp+s)\n deriv(1)=-0.5_rp\n deriv(2)= 0.5_rp\n else if(nnode==3) then\n shape(1)= 0.5_rp*s*(s-1.0_rp) ! 1 3 2\n shape(2)= 0.5_rp*s*(s+1.0_rp)\n shape(3)=-(s+1.0_rp)*(s-1.0_rp)\n deriv(1)= s-0.5_rp\n deriv(2)= s+0.5_rp\n deriv(3)=-2.0_rp*s\n else if(nnode==4) then\n a = 9.0_rp/16.0_rp\n s1= s + 1.0_rp\n s2= s - 1.0_rp \n s3= s + 1.0_rp/3.0_rp\n s4= s - 1.0_rp/3.0_rp \n c = 3.0_rp*a\n shape(1)= -a*s2*s3*s4 ! 1 3 4 2\n shape(2)= a*s1*s3*s4\n shape(3)= c*s1*s2*s4\n shape(4)= -c*s1*s2*s3\n deriv(1)= - a*(s2*s3+s2*s4+s3*s4)\n deriv(2)= a*(s1*s3+s1*s4+s3*s4)\n deriv(3)= c*(s1*s2+s1*s4+s2*s4)\n deriv(4)= - c*(s1*s2+s1*s3+s2*s3)\n! * * * * * * * * * * * * * * * * * * \n! *Valores calculados para nnode=5 *\n! * * * * * * * * * * * * * * * * * * \n else if(nnode==5) then \n s1 = s + 1.0_rp \n s2 = s - 1.0_rp\n s3 = s + 1.0_rp/2.0_rp\n s4 = s - 1.0_rp/2.0_rp\n shape(1) = 2.0_rp/3.0_rp*s*s3*s4*s2 ! 1 3 4 5 2\n shape(2) =-8.0_rp/3.0_rp*s*s1*s4*s2 \n shape(3) = 4.0_rp*s1*s3*s4*s2 \n shape(4) =-8.0_rp/3.0_rp*s*s1*s3*s2\n shape(5) = 2.0_rp/3.0_rp*s*s1*s3*s4\n deriv(1) = 2.0_rp/3.0_rp*(s*s3*s4+s*s3*s2+s*s4*s2+s3*s4*s2)\n deriv(2) =-8.0_rp/3.0_rp*(s*s1*s4+s*s1*s2+s*s4*s2+s1*s4*s2)\n deriv(3) = 4.0_rp*(s1*s3*s4+s1*s3*s2+s1*s4*s2+s3*s4*s2)\n deriv(4) =-8.0_rp/3.0_rp*(s*s1*s3+s*s1*s2+s*s3*s2+s1*s3*s2)\n deriv(5) = 2.0_rp/3.0_rp*(s*s1*s3+s*s1*s4+s*s3*s4+s1*s3*s4)\n\n end if\n! a= 0.0_rp \n! c= 0.0_rp\n! a = a + shape(1)+ shape(2)+ shape(3)+ shape(4)\n! c = c + deriv(1)+ deriv(2)+ deriv(3)+ deriv(4)\n \nend subroutine shape1\n \n", "meta": {"hexsha": "5d49cceb145dd5973229f46f861d2265a3eb7975", "size": 2344, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/domain/shape1.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/domain/shape1.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/domain/shape1.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.014084507, "max_line_length": 72, "alphanum_fraction": 0.4611774744, "num_tokens": 1080, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122744874229, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7961621294016443}} {"text": "! chk_norm2_hypot.f90 --\r\n! Check if the compiler supports the new NORM2 and HYPOT functions\r\n!\r\n! Note: there is a whole list of such special functions defined for the Fortran 2008 standard, not\r\n! all of them are tested here\r\n!\r\n! For an extensive discussion of the calculation of the Euclidean norm:\r\n! https://www.researchgate.net/publication/298896236\r\n!\r\nprogram chk_norm2_hypot\r\n implicit none\r\n\r\n real, dimension(4) :: vector = (/ 1.0, 2.0, 3.0, 4.0 /)\r\n real :: x = 3.0, y = 4.0\r\n\r\n write( *, '(a)' ) 'HYPOT function - the (3,4,5) triangle'\r\n write( *, '(a,2f7.4,a,f7.4)' ) 'The hypothenusa of a rectangular triangle with sides', x, y, ' is ', hypot(x,y)\r\n\r\n write( *, '(a)' ) '2-norm of a vector:'\r\n write( *, '(a,4f10.4)' ) 'Vector: ', vector\r\n write( *, '(a,f10.4)' ) 'Euclidean norm of the vector:', norm2(vector)\r\n\r\n !\r\n ! Special attention to very large values - ideally there should be no overflow\r\n !\r\n vector(1:2) = (/ (3.0/10.0) * huge(x), (4.0/10.0) * huge(x) /)\r\n\r\n write( *, '(a)' ) '2-norm of a vector with very large components:'\r\n write( *, '(a,2e14.4)' ) 'Vector: ', vector(1:2)\r\n write( *, '(a,e14.4)' ) 'Euclidean norm:', norm2(vector(1:2))\r\n write( *, '(a,e14.4)' ) 'Expected: ', (5.0/10.0) * huge(x)\r\n\r\n !\r\n ! Special attention to very small values - ideally there should be no underflow\r\n !\r\n vector(1:2) = (/ 30.0 * tiny(x), 40.0 * tiny(x) /)\r\n\r\n write( *, '(a)' ) '2-norm of a vector with very large components:'\r\n write( *, '(a,2e14.4)' ) 'Vector: ', vector(1:2)\r\n write( *, '(a,e14.4)' ) 'Euclidean norm:', norm2(vector(1:2))\r\n write( *, '(a,e14.4)' ) 'Expected: ', 50.0 * tiny(x)\r\n\r\nend program chk_norm2_hypot\r\n", "meta": {"hexsha": "a8df8ce225368538a4d860e269850475eb95cc92", "size": 1904, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "chkfeatures/chk_norm2_hypot.f90", "max_stars_repo_name": "timcera/flibs_from_svn", "max_stars_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-11T04:06:45.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-11T04:06:45.000Z", "max_issues_repo_path": "chkfeatures/chk_norm2_hypot.f90", "max_issues_repo_name": "timcera/flibs_from_svn", "max_issues_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chkfeatures/chk_norm2_hypot.f90", "max_forks_repo_name": "timcera/flibs_from_svn", "max_forks_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-03-15T14:46:56.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-15T14:46:56.000Z", "avg_line_length": 43.2727272727, "max_line_length": 116, "alphanum_fraction": 0.5262605042, "num_tokens": 615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8774767954920548, "lm_q1q2_score": 0.7961454205102982}} {"text": " program aritmetica\n implicit none\n \n real :: pi\n real :: radio_cilindro\n real :: altura_cilindro\n real :: area_cilindro\n real :: volumen_cilindro\n \n pi=3.1415926535\n ! 3.14159265358979323846264338\n\n print *, 'Introduzca el radio de la base del cilindro:'\n read(*,*) radio_cilindro\n\n print *, 'Introduzca la altura del cilindro:'\n read(*,*) altura_cilindro\n \n area_cilindro = pi*radio_cilindro**2.0\n volumen_cilindro = area_cilindro*altura_cilindro\n\n print *, 'Radio del cilindro: ', radio_cilindro\n print *, 'Altura del cilindro: ',altura_cilindro\n print *, 'Area del cilindro: ',area_cilindro \n print *, 'Volumen del cilindro: ',volumen_cilindro\n end program aritmetica\n", "meta": {"hexsha": "2db01c03dacd440e84e1955ea903456dc9ab7167", "size": 830, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Programas/aritmetica.f90", "max_stars_repo_name": "Marc-xyz/InicioRapidoEnFortran", "max_stars_repo_head_hexsha": "8cfe017877061bbfbb2bef66e16c2afc9375243d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-25T22:00:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-25T22:00:53.000Z", "max_issues_repo_path": "Programas/aritmetica.f90", "max_issues_repo_name": "Marc-xyz/InicioRapidoEnFortran", "max_issues_repo_head_hexsha": "8cfe017877061bbfbb2bef66e16c2afc9375243d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Programas/aritmetica.f90", "max_forks_repo_name": "Marc-xyz/InicioRapidoEnFortran", "max_forks_repo_head_hexsha": "8cfe017877061bbfbb2bef66e16c2afc9375243d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.7407407407, "max_line_length": 63, "alphanum_fraction": 0.6024096386, "num_tokens": 254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191322715436, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7960909312712342}} {"text": "DOUBLE PRECISION FUNCTION D_H(N_SITES,N_PARTICLES,stats) \n\n !Calculates the number of states of N_particles Bosons/Ferminos in N_sites lattice sites\n ! Wikipedia:\n ! D_B = (N_particles + N_sites - 1)!)/(N_particles! * (L-1)!)))\n ! D_F = N_sites!/(N_particles! (N_sites-N_particles)!)))\n\n !N_SITES (IN): INTEGER, number of lattice sites\n !N_PARTICLES (IN): INTEGER, umber of partcles\n !stats (IN)! 'F' or 'B' for Fermions or Bosons, respectively\n\n IMPLICIT NONE\n INTEGER, INTENT(IN):: N_SITES,N_PARTICLES\n CHARACTER(LEN=*), INTENT(IN),OPTIONAL :: stats\n\n INTEGER :: N_,K_,i\n DOUBLE PRECISION :: Num,Den,N_STATES\n\n IF(PRESENT(stats)) THEN\n SELECT CASE (stats)\n CASE(\"B\")\n\n IF(N_PARTICLES.GT.1) THEN\n N_ = N_SITES+N_PARTICLES-1;\n K_ = N_PARTICLES;\n write(*,*) N_,k_\n Num = 1.0;\n do while (n_.gt.0) \n Num = Num*n_;\n n_ = n_-1;\n end do\n Den = 1.0;\n do while (k_.gt.0) \n Den = Den*k_;\n k_ = k_-1;\n end do\n ELSE\n num = n_sites\n den = 1\n END IF\n\n CASE(\"F\")\n N_STATES = N_SITES\n N_ = N_STATES\n Num = 1.0;\n do while (n_.gt.0) \n Num = Num*n_\n n_ = n_-1;\n end do\n k_ = N_STATES - N_PARTICLES\n Den = 1.0\n do while (k_.gt.0)\n Den = Den*k_;\n k_ = k_-1;\n end do\n k_ = N_PARTICLES\n do while (k_.gt.0) \n Den = Den*k_;\n k_ = k_-1;\n end do\n\n CASE DEFAULT\n D_H = N_SITES\n END SELECT\n\n D_H = Num/Den;\n\n ELSE\n\n D_H = N_SITES\n\n END IF\n\nEND FUNCTION D_H\n\n\nMODULE CREATIONDESTRUCTION\n\n implicit none\n private\n public :: A_DAGGER,A_,TUNNELING_,TUNNELING_F_\n\n interface A_DAGGER\n procedure A_DAGGER_INT,A_DAGGER_REAL\n end interface A_DAGGER\n\n interface A_\n procedure A_INT,A_REAL\n end interface A_\n\ncontains\n !Bosonic tunelling\n FUNCTION TUNNELING_(k,STATE) result(NEW_STATE)\n\n \n INTEGER, INTENT(IN) :: k\n INTEGER, DIMENSION(:), INTENT(IN) :: STATE\n \n DOUBLE PRECISION, DIMENSION(SIZE(STATE,1)) :: NEW_STATE\n \n NEW_STATE = STATE \n IF(STATE(K).GT.0) THEN\n NEW_STATE(k) = NEW_STATE(k) - 1 \n NEW_STATE(k+1) = NEW_STATE(k+1) + 1 \n ELSE\n NEW_STATE = 0\n END IF \n \n END FUNCTION TUNNELING_\n\n !FERMIONIC tunelling\n FUNCTION TUNNELING_F_(k,STATE) result(NEW_STATE)\n\n \n INTEGER, INTENT(IN) :: k\n INTEGER, DIMENSION(:), INTENT(IN) :: STATE\n \n DOUBLE PRECISION, DIMENSION(SIZE(STATE,1)) :: NEW_STATE\n \n NEW_STATE = STATE \n IF(K.LT.SIZE(STATE,1))THEN\n IF(STATE(K).EQ.1 .AND. STATE(K+1).EQ.0) THEN\n NEW_STATE(k) = NEW_STATE(k) - 1 \n NEW_STATE(k+1) = NEW_STATE(k+1) + 1\n ELSE\n NEW_STATE = 0\n END IF \n ELSE\n! write(*,*) 'mw,k',k,state(k),state(k-1)\n IF(STATE(K).EQ.1 .AND. STATE(K-1).EQ.0) THEN\n NEW_STATE(k) = NEW_STATE(k) - 1 \n NEW_STATE(k-1) = NEW_STATE(k-1) + 1\n ELSE\n NEW_STATE = 0\n END IF \n END IF\n \n\n END FUNCTION TUNNELING_F_\n \n\n !BOSONIC CREATION AND DESTRUCTION OPERATORE\n FUNCTION A_DAGGER_INT(k,STATE) result(NEW_STATE)\n\n \n INTEGER, INTENT(IN) :: k\n INTEGER, DIMENSION(:), INTENT(IN) :: STATE\n \n DOUBLE PRECISION, DIMENSION(SIZE(STATE,1)) :: NEW_STATE\n \n !WRITE(*,*) k,NEW_STATE\n NEW_STATE = STATE \n NEW_STATE(k) = NEW_STATE(k) + 1\n NEW_STATE = SQRT(1.0*NEW_STATE(K))*NEW_STATE\n !WRITE(*,*) k,NEW_STATE\n END FUNCTION A_DAGGER_INT\n\n FUNCTION A_DAGGER_REAL(k,STATE) result(NEW_STATE)\n\n \n INTEGER, INTENT(IN) :: k\n DOUBLE PRECISION, DIMENSION(:), INTENT(IN) :: STATE\n \n DOUBLE PRECISION, DIMENSION(SIZE(STATE,1)) :: NEW_STATE\n \n NEW_STATE = STATE \n !WRITE(*,*) k,NEW_STATE\n NEW_STATE(k) = NEW_STATE(k) + 1\n NEW_STATE = SQRT(1.0*NEW_STATE(K))*NEW_STATE\n !WRITE(*,*) k,NEW_STATE\n END FUNCTION A_DAGGER_REAL\n\n FUNCTION A_INT(k,STATE) result(NEW_STATE)\n !A_DAGGER |n> = sqrt(n+1) |n+1>\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: K\n INTEGER, DIMENSION(:), INTENT(IN) :: STATE\n \n DOUBLE PRECISION, DIMENSION(SIZE(STATE,1)) :: NEW_STATE\n\n NEW_STATE = STATE \n! WRITE(*,*) k,NEW_STATE\n IF(STATE(k).GT.0) THEN\n NEW_STATE(k) = NEW_STATE(k) - 1\n NEW_STATE = SQRT(1.0*NEW_STATE(K))*NEW_STATE\n ELSE\n NEW_STATE =0\n END IF\n ! WRITE(*,*) k,NEW_STATE\n END FUNCTION A_INT\n \n FUNCTION A_REAL(k,STATE) result(NEW_STATE)\n !A_DAGGER |n> = sqrt(n+1) |n+1>\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: K\n DOUBLE PRECISION, DIMENSION(:), INTENT(IN) :: STATE\n \n DOUBLE PRECISION, DIMENSION(SIZE(STATE,1)) :: NEW_STATE\n\n NEW_STATE = STATE \n IF(STATE(k).GT.0) THEN\n NEW_STATE(k) = NEW_STATE(k) - 1\n NEW_STATE = SQRT(1.0*NEW_STATE(K))*NEW_STATE\n ELSE\n NEW_STATE =0\n END IF\n END FUNCTION A_REAL\n\n\nend module CREATIONDESTRUCTION\n\n\nSUBROUTINE Manybody_basis(D_BARE,N_SITES,N_BODIES,STATS,states_occ,INFO)\n\n! CREATES A MATRIX WITH AS MANY ROWS AS STATES AND AS MANY COLUMNS AS LATTICE SITES\n! EACH ROW OF THIS MATRIX IS A BASIS STATE IN THE OCCUPATION NUMBER\n! \n! D_BARE (IN) INTEGER : NUMBER OF STATES\n! N_SITES (IN) INTEGER : NUMBER OF LATTICE SITES\n! N_BODIES (IN) INTEGER : NUMBER OF PARTICLES\n! STATS (IN) CHAR : 'F' or '' B\n! states_occ (OUT) (D_BARE,N_SITES)) : STATES LABELLED AS OCCUPATION OF THE LATTICE\n! INFO (INOUT) : ERROR FLAG\n \n IMPLICIT NONE\n INTEGER, INTENT(IN) :: D_BARE,N_SITES,N_BODIES\n CHARACTER(LEN=*),INTENT(IN):: stats\n INTEGER, DIMENSION(D_BARE,N_SITES), intent(out) :: states_occ\n INTEGER, INTENT(INOUT) :: INFO\n\n LOGICAL MORE\n INTEGER i,j,INTEGER_SPACE\n\n INTEGER, ALLOCATABLE,DIMENSION(:) :: STATE_\n\n i = 0\n STATES_OCC = 0\n MORE = .FALSE.\n\n INFO = 0\n SELECT CASE (stats)\n CASE(\"B\")\n ALLOCATE(STATE_(N_SITES))\n STATE_ = 0\n STATE_(1) = N_BODIES \n DO i=1,D_BARE \n CALL COMP_NEXT(N_BODIES,N_SITES,STATE_,MORE) ! DEFINED IN subset.f90\n STATES_OCC(i,:) = STATE_\n !write(*,*) state_\n END DO\n \n CASE(\"F\")\n\n IF(N_BODIES .LE. 2*N_SITES) THEN\n ALLOCATE(STATE_(N_SITES))\n STATE_=0\n j =1\n INTEGER_SPACE = 2**N_SITES -1\n DO i=1,INTEGER_SPACE\n \n CALL BVEC_NEXT_GRLEX(N_SITES,STATE_) ! DEFINED IN bvec.f90\n IF(SUM(STATE_) .EQ. N_BODIES) THEN\n STATES_OCC(j,:) = STATE_\n !write(*,*) j\n j=j+1\n ELSE\n \n END IF \n END DO \n ELSE\n WRITE(*,*) \"ERROR\"\n WRITE(*,*) \"THE NUMBER OF PARTICLES IS LARGER THAN THE NUMBER OF AVAILABLE STATES\"\n INFO = -1\n END IF\n\n END SELECT\n\nEND SUBROUTINE Manybody_basis\n\n\nSUBROUTINE TENSORMULT(N,A,B,C,INFO) \n ! TENSOR MULTIMPLICATION OF MATRICES A AND B TO PRODUCE C \n !N, INTEGER(3), IN: DIMENSION OF MATRIX A,B,C N(1,2,3), RESPECTIVELY\n !A COMPLEX*18, DIMENSION (N(1),N(2)), IN\n !B COMPLEX*18, DIMENSION (N(1),N(2)), IN\n !C COMPLEX*18, DIMENSION (N(3),N(3)), OUT\n !INFO: ERROR FLAG\n IMPLICIT NONE\n INTEGER, DIMENSION(3), INTENT(IN) :: N\n INTEGER, INTENT(INOUT) :: INFO\n COMPLEX*16, DIMENSION(N(1),N(1)), INTENT(IN) :: A\n COMPLEX*16, DIMENSION(N(2),N(2)), INTENT(IN) :: B\n COMPLEX*16, DIMENSION(N(3),N(3)), INTENT(OUT) :: C\n \n INTEGER i,j,r\n \n !WRITE(*,*) A\n !WRITE(*,*) B\n !write(*,*) N\n DO i=1,N(2)\n DO j=1,N(2)\n !if(abs(B(i,j)).gt.0) then\n ! do r=1,size(a,1)\n ! write(*,*) abs(A(r,:))\n ! end do\n ! write(*,*)\n ! write(*,*)\n ! write(*,*) (i-1)*N(1)+1,i*N(1),(j-1)*N(1)+1,j*N(1)\n !end if\n C((i-1)*N(1)+1:i*N(1),(j-1)*N(1)+1:j*N(1)) = A*B(i,j)\n END DO\n END DO\n \nEND SUBROUTINE TENSORMULT\n", "meta": {"hexsha": "e1d275334245f433a06c283b972934115338bd28", "size": 8529, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/FORTRAN/Manybody/HilbertDimension.f90", "max_stars_repo_name": "gsinuco/OPENMMF", "max_stars_repo_head_hexsha": "2cc0d0f2a4ded895c189050c38dbf2e8985e2d55", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-05-12T19:28:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T05:37:17.000Z", "max_issues_repo_path": "examples/FORTRAN/Manybody/HilbertDimension.f90", "max_issues_repo_name": "gsinuco/OPENMMF", "max_issues_repo_head_hexsha": "2cc0d0f2a4ded895c189050c38dbf2e8985e2d55", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/FORTRAN/Manybody/HilbertDimension.f90", "max_forks_repo_name": "gsinuco/OPENMMF", "max_forks_repo_head_hexsha": "2cc0d0f2a4ded895c189050c38dbf2e8985e2d55", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-05-12T19:28:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-16T21:09:32.000Z", "avg_line_length": 27.0761904762, "max_line_length": 91, "alphanum_fraction": 0.5334740298, "num_tokens": 2669, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475778774729, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.796086393570242}} {"text": "C PROGRAM FOR LAGRANGE INTERPOLATION\nC GAURAV RUDRA MALIK; ROLL NO : 23\n\tDIMENSION X(100),F(100)\n\tWRITE(*,*)'ENTER THE NUMBER OF TERMS; MAX: 100'\n\tREAD(*,*) I\n\tWRITE(*,*)'ENTER THE VALUE OF X AND THE CORRESPONDING VALUE OF F(X)'\n\tDO 1 J=1,I\n\tREAD(*,*),X(J),F(J)\n1\tCONTINUE\n\tWRITE(*,*)'THE ENTERED VALUES ARE'\n\tDO 2 J=1,I\n\tWRITE(*,3)X(J),F(J)\n2\tCONTINUE\n3\tFORMAT(F12.6'\t'F12.6)\n\tA=X(1)\n\tB=X(1)\n\tDO 4 J=1,I\n\tIF(X(I).GT.A)THEN\n\tA=X(I)\n\tENDIF\n\tIF(X(I).LT.B)THEN\n\tB=X(I)\n\tENDIF\n4\tCONTINUE\n\tWRITE(*,*)'ENTER THE NUMBER AT WHICH THE VALUE OF FUNCTION IS REQUIRED'\n5\tREAD(*,*),E\n\tIF((E.GT.A).OR.(E.LT.B))THEN\n\tWRITE(*,*)'INVALID INPUT FOR INTERPOLATION, ENTER AGAIN'\n\tGOTO 5\n\tENDIF\n\tC=1.0\n\tD=1.0\n\tS=0.0\n\tDO 7 J=1,I\n\tD=1.0\n\tDO 6 K=1,I\n\tIF(J.NE.K) THEN\n\tC=(E-X(K))/(X(J)-X(K))\n\tD=D*C\n\tENDIF\n6\tCONTINUE\n\tD=D*F(J)\n\tS=S+D\n7\tCONTINUE\n\tWRITE(*,*)'THE VALUE INTERPOLATED AT X =',E,' IS FOUND TO BE',S\n\tSTOP\n\tEND\n\nRESULT\n\n ENTER THE NUMBER OF TERMS; MAX: 100\n10\n ENTER THE VALUE OF X AND THE CORRESPONDING VALUE OF F(X)\n1\n3\n2\n6\n3\n11\n4\n18\n5\n27\n6\n38\n7\n51\n8\n66\n9\n83\n10\n102\n THE ENTERED VALUES ARE\n 1.000000\t 3.000000\n 2.000000\t 6.000000\n 3.000000\t 11.000000\n 4.000000\t 18.000000\n 5.000000\t 27.000000\n 6.000000\t 38.000000\n 7.000000\t 51.000000\n 8.000000\t 66.000000\n 9.000000\t 83.000000\n 10.000000\t 102.000000\n ENTER THE NUMBER AT WHICH THE VALUE OF FUNCTION IS REQUIRED\n4.5\n THE VALUE INTERPOLATED AT X = 4.5 IS FOUND TO BE 22.25\n\n\n\n\n", "meta": {"hexsha": "3b5db6653404353b8f70626fb6375fb3f530699b", "size": 1464, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Lagrange_Interpolation.f", "max_stars_repo_name": "GauravR-Malik/ComputationPhysics_Fortran", "max_stars_repo_head_hexsha": "70ab4d6fe815538c23715799159e46e63dbbde3c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lagrange_Interpolation.f", "max_issues_repo_name": "GauravR-Malik/ComputationPhysics_Fortran", "max_issues_repo_head_hexsha": "70ab4d6fe815538c23715799159e46e63dbbde3c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lagrange_Interpolation.f", "max_forks_repo_name": "GauravR-Malik/ComputationPhysics_Fortran", "max_forks_repo_head_hexsha": "70ab4d6fe815538c23715799159e46e63dbbde3c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.9130434783, "max_line_length": 72, "alphanum_fraction": 0.6331967213, "num_tokens": 654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.8688267728417087, "lm_q1q2_score": 0.7959405551642534}} {"text": "module gauss_seidel\n implicit none\n public solve, gauss_seidel_iter\n\ncontains\nfunction solve(a, x_initial, b, n, atol, rtol, relaxation) result(x_new)\n integer, intent(in) :: n\n real(8), intent(in) :: atol, rtol\n real(8), intent(in) :: x_initial(n)\n real(8), intent(in) :: b(n)\n real(8), intent(in) :: a(n, n)\n real(8), intent(in), optional :: relaxation\n !f2py real(8) :: relaxation = 1\n \n integer :: i\n real(8) :: x_new(n), x_old(n), w = 1.d0\n \n if (present(relaxation)) w = relaxation\n\n x_new = x_initial\n \n do \n do i = 1, n\n x_old = x_new\n x_new(i) = gauss_seidel_iter(a, x_new, x_old, b, n, i)\n x_new(i) = x_old(i) + w*(x_new(i)-x_old(i))\n end do\n print*, x_new\n if(maxval(abs(x_new-x_old)) < atol + rtol * maxval(abs(x_new))) exit\n end do\n return\nend function solve\n\npure real(8) function gauss_seidel_iter(a, x_new, x_old, b, n, i) \n integer, intent(in) :: n\n integer, intent(in) :: i\n real(8), intent(in) :: x_new(n)\n real(8), intent(in) :: x_old(n)\n real(8), intent(in) :: b(n)\n real(8), intent(in) :: a(n, n)\n\n gauss_seidel_iter = 1.d0/a(i,i) * (b(i) - & \n sum(a(i,:i-1)*x_new(:i-1)) &\n - sum(a(i,i+1:)*x_old(i+1:)))\n return\nend function gauss_seidel_iter\nend module gauss_seidel", "meta": {"hexsha": "308ea25aa6681f9a6d3251049a9d320da6bff163", "size": 1369, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "linear_systems/gauss_seidel.f90", "max_stars_repo_name": "gabrimig/numerial_methods", "max_stars_repo_head_hexsha": "e5017f3db4ad9cae00ead046f07bacd8d5bd49dd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "linear_systems/gauss_seidel.f90", "max_issues_repo_name": "gabrimig/numerial_methods", "max_issues_repo_head_hexsha": "e5017f3db4ad9cae00ead046f07bacd8d5bd49dd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-11-09T11:39:01.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-09T11:39:01.000Z", "max_forks_repo_path": "linear_systems/gauss_seidel.f90", "max_forks_repo_name": "gabrimig/numerial_methods", "max_forks_repo_head_hexsha": "e5017f3db4ad9cae00ead046f07bacd8d5bd49dd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.1276595745, "max_line_length": 76, "alphanum_fraction": 0.5551497443, "num_tokens": 452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947086083138, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7955207859735565}} {"text": "module reg_mod\r\nimplicit none\r\ncontains\r\nsubroutine linear_regression(x,y,slope,intcep,ierr)\r\n! regress y(:) on x(:), where size(x) == size(y)\r\nreal , intent(in) :: x(:),y(:)\r\nreal , intent(out) :: slope,intcep\r\ninteger, intent(out), optional :: ierr\r\ninteger :: ierr_,n\r\nreal :: xmean,ymean\r\nif (present(ierr)) ierr = 0\r\nn = size(x)\r\nierr_ = findloc([n>1, size(y)==n],.false.,dim=1)\r\nif (ierr_ /= 0) then\r\n if (present(ierr)) then\r\n ! if error flag passed, set it and return\r\n ierr = ierr_\r\n return\r\n else\r\n ! otherwise stop\r\n print*,\"in linear_regression, ierr_ =\",ierr_\r\n error stop\r\n end if\r\nend if\r\nxmean = sum(x)/n\r\nymean = sum(y)/n\r\nslope = sum((x-xmean)*(y-ymean))/sum((x-xmean)**2)\r\n! should check that denominator above is nonzero\r\nintcep = ymean - slope*xmean\r\nend subroutine linear_regression\r\nend module reg_mod\r\n!\r\nprogram test_reg\r\nuse reg_mod, only: linear_regression\r\nimplicit none\r\ninteger, parameter :: n = 10**3\r\nreal :: x(n),y(n),noise(n),slope,intcep\r\ninteger :: ierr\r\ncall random_seed()\r\ncall random_number(x)\r\ncall random_number(noise)\r\ny = 5*x + 3 + (noise - 0.5)\r\ncall linear_regression(x,y,slope,intcep)\r\nprint \"('slope, intercept =',2(1x,f0.4))\",slope,intcep\r\n! pass error flag ierr\r\ncall linear_regression(x(2:),y,slope,intcep,ierr) \r\nif (ierr /= 0) print*,\"after linear_regression, ierr =\",ierr\r\n! no error flag passed -- stop in procedure upon error\r\ncall linear_regression(x(2:),y,slope,intcep)\r\nend program test_reg\r\n! sample output:\r\n! slope, intercept = 4.9824 3.0011\r\n! after linear_regression, ierr = 2\r\n! in linear_regression, ierr_ = 2\r\n! ERROR STOP ", "meta": {"hexsha": "c9e62617ed368b4b65f108ca9ee94bc4b4295776", "size": 1724, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "optional_err.f90", "max_stars_repo_name": "awvwgk/FortranTip", "max_stars_repo_head_hexsha": "3810038667e3d5d2ab33c39d4bd0f41870025420", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "optional_err.f90", "max_issues_repo_name": "awvwgk/FortranTip", "max_issues_repo_head_hexsha": "3810038667e3d5d2ab33c39d4bd0f41870025420", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "optional_err.f90", "max_forks_repo_name": "awvwgk/FortranTip", "max_forks_repo_head_hexsha": "3810038667e3d5d2ab33c39d4bd0f41870025420", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.3454545455, "max_line_length": 61, "alphanum_fraction": 0.63225058, "num_tokens": 502, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065459, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7955207810816166}} {"text": "module difference_of_squares\n contains\n integer function square_of_sum(n)\n implicit none\n integer :: i,n\n\n square_of_sum = 0\n\n do i = 1,n\n square_of_sum = square_of_sum + i\n end do\n\n square_of_sum = square_of_sum * square_of_sum\n end function square_of_sum\n\n integer function sum_of_squares(n)\n implicit none\n integer :: i, n\n\n sum_of_squares = 0\n\n do i = 1,n\n sum_of_squares = sum_of_squares + i**2\n end do\n\n end function sum_of_squares\n\n integer function difference(n)\n implicit none\n integer :: n\n\n difference = square_of_sum(n) - sum_of_squares(n)\n end function difference\n\nend module difference_of_squares\n", "meta": {"hexsha": "5236ba43ad9dc5bbaf83653cfaf7b16893e480e6", "size": 670, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exercises/practice/difference-of-squares/.meta/example.f90", "max_stars_repo_name": "hiljusti/fortran", "max_stars_repo_head_hexsha": "998dae09b8ef463752c3e15598d115c5aec7e64c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2017-06-28T12:57:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-22T03:30:48.000Z", "max_issues_repo_path": "exercises/practice/difference-of-squares/.meta/example.f90", "max_issues_repo_name": "hiljusti/fortran", "max_issues_repo_head_hexsha": "998dae09b8ef463752c3e15598d115c5aec7e64c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 92, "max_issues_repo_issues_event_min_datetime": "2017-06-28T13:27:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T08:46:33.000Z", "max_forks_repo_path": "exercises/practice/difference-of-squares/.meta/example.f90", "max_forks_repo_name": "hiljusti/fortran", "max_forks_repo_head_hexsha": "998dae09b8ef463752c3e15598d115c5aec7e64c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 20, "max_forks_repo_forks_event_min_datetime": "2017-07-29T03:43:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-08T05:59:28.000Z", "avg_line_length": 18.6111111111, "max_line_length": 53, "alphanum_fraction": 0.6955223881, "num_tokens": 184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.93812402119614, "lm_q2_score": 0.8479677564567913, "lm_q1q2_score": 0.7954989215319143}} {"text": "program ilist05s512\n! CAP372 - exercise 5 - 2019-09-15\n! - Each subtask i hold one row of matrix A and one column of matrix B .\n! - The result is stored in one element of C .\n! - After that, every subtask i, 0≤i ')\", advance='no') \n read (*,*) xmax\n write(*,\"('Number of grid points (typically a few hundreds) > ')\", advance='no')\n read (*,*) mesh\n !\n ! allocate arrays, initialize grid\n !\n allocate ( x(0:mesh), y(0:mesh), p(0:mesh), vpot(0:mesh), f(0:mesh) )\n dx = xmax/mesh \n ddx12=dx*dx/12.0_dp\n !\n ! set up the potential (must be even w.r.t. x=0)\n !\n do i = 0, mesh\n x(i) = float(i) * dx\n vpot(i) = 0.5_dp * x(i)*x(i)\n end do\n !\n write(*,\"('output file name > ')\", advance='no') \n read (*,'(a)') fileout\n ! output to fort.7 file by default if fileout not provided\n if ( fileout /= ' ' ) &\n open (7,file=fileout,status='unknown',form='formatted')\n\n ! this is the entry point for a new eigenvalue search\n search_loop: do \n !\n ! read number of nodes (stop if < 0)\n ! \n write(*,\"('nodes (type -1 to stop) > ')\", advance='no') \n read (*,*) nodes\n if (nodes < 0) then\n close(7)\n deallocate ( f, vpot, p, y, x )\n stop \n end if\n !\n ! set initial lower and upper bounds to the eigenvalue\n !\n eup=maxval (vpot(:))\n elw=minval (vpot(:))\n !\n ! Set trial energy\n !\n write(*,\"('Trial energy (0=search with bisection) > ')\", advance='no') \n read (*,*) e\n if ( e == 0.0_dp ) then\n ! search eigenvalues with bisection (max 1000 iterations)\n e = 0.5_dp * (elw + eup)\n n_iter = 1000\n else\n ! test a single energy value (no bisection)\n n_iter = 1\n endif\n \n iterate: do kkk = 1, n_iter\n !\n ! set up the f-function used by the Numerov algorithm\n ! and determine the position of its last crossing, i.e. change of sign\n ! f < 0 means classically allowed region\n ! f > 0 means classically forbidden region\n !\n f(0)=ddx12*(2.0_dp*(vpot(0)-e))\n icl=-1\n do i=1,mesh\n f(i)=ddx12*2.0_dp*(vpot(i)-e)\n ! beware: if f(i) is exactly zero the change of sign is not observed\n ! the following line is a trick to prevent missing a change of sign \n ! in this unlikely but not impossible case:\n if ( f(i) == 0.0_dp) f(i)=1.d-20\n ! store the index 'icl' where the last change of sign has been found\n if ( f(i) /= sign(f(i),f(i-1)) ) icl=i\n end do\n \n if (icl >= mesh-2) then\n deallocate ( f, vpot, p, y, x )\n print *, 'Error: last change of sign too far'\n stop 1\n else if (icl < 1) then\n deallocate ( f, vpot, p, y, x )\n print *, 'Error: no classical turning point'\n stop 1\n end if\n !\n ! f(x) as required by the Numerov algorithm (note f90 array syntax)\n !\n f = 1.0_dp - f\n y = 0.0_dp\n !\n ! determination of the wave-function in the first two points \n !\n hnodes = nodes/2\n !\n ! beware the integer division: 1/2 = 0 !\n ! if nodes is even, there are 2*hnodes nodes\n ! if nodes is odd, there are 2*hnodes+1 nodes (one is in x=0)\n ! hnodes is thus the number of nodes in the x>0 semi-axis (x=0 excepted)\n !\n if (2*hnodes == nodes) then\n ! even number of nodes: wavefunction is even\n y(0) = 1.0_dp\n ! assume f(-1) = f(1)\n y(1) = 0.5_dp*(12.0_dp-10.0_dp*f(0))*y(0)/f(1)\n else\n ! odd number of nodes: wavefunction is odd\n y(0) = 0.0_dp\n y(1) = dx\n end if\n !\n ! outward integration and count number of crossings\n !\n ncross=0\n do i =1,icl-1\n y(i+1)=((12.0_dp-10.0_dp*f(i))*y(i)-f(i-1)*y(i-1))/f(i+1)\n if ( y(i) /= sign(y(i),y(i+1)) ) ncross=ncross+1\n end do\n fac = y(icl)\n !\n if (2*hnodes == nodes) then\n ! even number of nodes: no node in x=0\n ncross = 2*ncross\n else\n ! odd number of nodes: node in x=0\n ncross = 2*ncross+1\n end if\n !\n ! check number of crossings\n !\n if ( n_iter > 1 ) then\n if (ncross /= nodes) then\n ! Incorrect number of crossings: adjust energy\n if ( kkk == 1) &\n print '(\"Bisection Energy Nodes Discontinuity\")'\n print '(i5,f25.15,i5)', kkk, e, ncross\n if (ncross > nodes) then\n ! Too many crossings: current energy is too high,\n ! lower the upper bound\n eup = e\n else \n ! Too few crossings: current energy is too low,\n ! raise the lower bound\n elw = e\n end if\n ! New trial value:\n e = 0.5_dp * (eup+elw)\n ! go to beginning of do loop, don't perform inward integration\n cycle\n end if\n else\n print *, e, ncross, nodes\n end if\n !\n ! Correct number of crossings: proceed to inward integration\n !\n ! Determination of the wave-function in the last two points\n ! assuming y(mesh+1) = 0\n !\n y(mesh) = dx\n y(mesh-1) = (12.0_dp-10.0_dp*f(mesh))*y(mesh)/f(mesh-1)\n norm = 1.0d100\n do i = mesh-1,icl+1,-1\n y(i-1)=((12.0_dp-10.0_dp*f(i))*y(i)-f(i+1)*y(i+1))/f(i-1)\n ! the following lines prevent overflows if starting from too far\n if ( abs(y(i-1)) > norm ) then\n y(i-1:mesh) = y(i-1:mesh) / norm\n endif\n end do\n !\n ! rescale function to match at the classical turning point (icl)\n !\n fac = fac/y(icl)\n y(icl:) = y(icl:)*fac\n !\n ! normalize on the [-xmax,xmax] segment\n ! the x=0 point must be counted once\n !\n norm = (2.0_dp*dot_product (y, y) - y(0)*y(0)) * dx \n y = y / sqrt(norm)\n !\n if ( n_iter > 1 ) then\n ! calculate the discontinuity in the first derivative\n ! y'(i;RIGHT) - y'(i;LEFT)\n djump = ( y(icl+1) + y(icl-1) - (14.0_dp-12.0_dp*f(icl))*y(icl) ) / dx\n print '(i5,f25.15,i5,f14.8)', kkk, e, nodes, djump\n if (djump*y(icl) > 0.0_dp) then\n ! Energy is too high --> choose lower energy range\n eup = e\n else\n ! Energy is too low --> choose upper energy range\n elw = e\n endif\n e = 0.5_dp * (eup+elw)\n ! ---- convergence test\n if ( eup-elw < 1.d-10) exit iterate\n endif\n !\n end do iterate\n !\n ! ---- convergence has been achieved (or it wasn't required) -----\n !\n ! Calculation of the classical probability density for energy e:\n !\n norm = 0.0_dp\n p(icl:) = 0.0_dp\n do i=0,icl\n arg = (e - x(i)**2/2.0_dp)\n if ( arg > 0.0_dp) then\n p(i) = 1.0_dp/sqrt(arg)\n else\n p(i) = 0.0_dp\n end if\n norm = norm + 2.0_dp*dx*p(i)\n enddo\n ! The point at x=0 must be counted once:\n norm = norm - dx*p(0)\n ! Normalize p(x) so that Int p(x)dx = 1\n p(:icl-1) = p(:icl-1)/norm\n ! lines starting with # ignored by gnuplot\n write (7,'(\"# x y(x) y(x)^2 classical p(x) V\")')\n ! x<0 region:\n do i=mesh,1,-1\n ! if exponent is > 99, the format X.Y-100 is misinterpreted by gnuplot\n if ( abs(y(i)) < 1.0D-50 ) y(i) = 0.0_dp\n write (7,'(f8.3,3e16.8,f12.6)') & \n -x(i), (-1)**nodes*y(i), y(i)*y(i), p(i), vpot(i)\n enddo\n ! x>0 region:\n do i=0,mesh\n write (7,'(f8.3,3e16.8,f12.6)') &\n x(i), y(i), y(i)*y(i), p(i), vpot(i)\n enddo\n ! two blank lines separating blocks of data, useful for gnuplot plotting\n write (7,'(/)')\n \n end do search_loop\n \nend program harmonic1\n\n\n", "meta": {"hexsha": "24b00d3bd0dc8333e194f2438ec846b8997b96a3", "size": 8938, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/assgn07_solns/Assgn07_numerov_method/Assgn07_harmonic1.f90", "max_stars_repo_name": "Anantha-Rao12/ComPhys", "max_stars_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Solutions/assgn07_solns/Assgn07_numerov_method/Assgn07_harmonic1.f90", "max_issues_repo_name": "Anantha-Rao12/ComPhys", "max_issues_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Solutions/assgn07_solns/Assgn07_numerov_method/Assgn07_harmonic1.f90", "max_forks_repo_name": "Anantha-Rao12/ComPhys", "max_forks_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.7283018868, "max_line_length": 82, "alphanum_fraction": 0.496196017, "num_tokens": 2731, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625012602593, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7953877087224284}} {"text": "program average\n\n![-3-]@copyright wikipedia, modified @alpaca-tc. http://en.wikipedia.org/wiki/Fortran\n![-4-] Read in some numbers and take the average\n![-5-] As written, if there are no data points, an average of zero is returned\n![-6-] While this may not be desired behavior, it keeps this example simple\n\nimplicit none\n\nreal, dimension(:), allocatable :: points\ninteger :: number_of_points\nreal :: average_points=0., positive_average=0., negative_average=0.\n\nwrite (*,*) \"Input number of points to average:\"\nread (*,*) number_of_points\n\nallocate (points(number_of_points))\n\nwrite (*,*) \"Enter the points to average:\"\nread (*,*) points\n\n![-22-] Take the average by summing points and dividing by number_of_points\nif (number_of_points > 0) average_points = sum(points) / number_of_points\n\n![-25-] Now form average over positive and negative points only\nif (count(points > 0.) > 0) then\n positive_average = sum(points, points > 0.) / count(points > 0.)\nend if\n\nif (count(points < 0.) > 0) then\n negative_average = sum(points, points < 0.) / count(points < 0.)\nend if\n\ndeallocate (points) ![-34-] Print result to terminal\n\n![-36-] Print result to terminal\nwrite (*,'(a,g12.4)') 'Average = ', average_points\nwrite (*,'(a,g12.4)') 'Average of positive points = ', positive_average\nwrite (*,'(a,g12.4)') 'Average of negative points = ', negative_average\n\nend program average\n", "meta": {"hexsha": "c0ea3dce2667ba76d0050e0b8eebbd666d7c0f6f", "size": 1426, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "spec/assets/source_code/fortran.f", "max_stars_repo_name": "alpaca-tc/comment_extractor", "max_stars_repo_head_hexsha": "9c22b80271c13d4a35fd381ab2a3bd2ae88eee0a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-05T16:40:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-05T16:40:42.000Z", "max_issues_repo_path": "spec/assets/source_code/fortran.f", "max_issues_repo_name": "alpaca-tc/comment_extractor", "max_issues_repo_head_hexsha": "9c22b80271c13d4a35fd381ab2a3bd2ae88eee0a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "spec/assets/source_code/fortran.f", "max_forks_repo_name": "alpaca-tc/comment_extractor", "max_forks_repo_head_hexsha": "9c22b80271c13d4a35fd381ab2a3bd2ae88eee0a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.9523809524, "max_line_length": 94, "alphanum_fraction": 0.6851332398, "num_tokens": 384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299591537478, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.7953866617601214}} {"text": "module constants \nimplicit none \n\n real, parameter,private :: pi = 3.1415926536 \n real, parameter, private :: e = 2.7182818285 \n \ncontains \n subroutine show_consts() \n print*, \"Pi = \", pi \n print*, \"e = \", e \n end subroutine show_consts \n \n function ePowerx(x)result(ePx) \n implicit none\n real::x\n real::ePx\n ePx = e ** x\n end function ePowerx\n \n function areaCircle(r)result(a) \n implicit none\n real::r\n real::a\n a = pi * r**2 \n end function areaCircle\n \nend module constants \n\n\nprogram module_example \nuse constants \nimplicit none \n\n call show_consts() \n \n Print*, \"e raised to the power of 2.0 = \", ePowerx(2.0)\n print*, \"Area of a circle with radius 7.0 = \", areaCircle(7.0) \n \nend program module_example\n", "meta": {"hexsha": "3543bd89353dbb7d879a3d4eb359f242790d5eb2", "size": 834, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "nmodule/nmodule.f90", "max_stars_repo_name": "akkiturb/Ilkay-s-Fortran-Class", "max_stars_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-18T19:31:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-18T19:31:01.000Z", "max_issues_repo_path": "nmodule/nmodule.f90", "max_issues_repo_name": "akkiturb/Scientific-computing-in-Fortran", "max_issues_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "nmodule/nmodule.f90", "max_forks_repo_name": "akkiturb/Scientific-computing-in-Fortran", "max_forks_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-04T19:45:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-10T14:22:05.000Z", "avg_line_length": 20.85, "max_line_length": 67, "alphanum_fraction": 0.5827338129, "num_tokens": 229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133464597458, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.7951125835123806}} {"text": "PROGRAM MonteCarlo2\n ! This program demonstrates the parallelization of a program that uses the\n ! Monte Carlo method by simulating a random walk in two dimensions of 100,000\n ! particles in 10 steps. The program outputs the distribution of the \n ! distances that the particles have travled.\n\n USE IFPORT\n\n IMPLICIT NONE\n INCLUDE 'mpif.h'\n\n ! Configuration variables\n INTEGER, PARAMETER :: n = 100000\n REAL, PARAMETER :: pi = 3.1415926\n INTEGER, DIMENSION(0:9) :: localDist, globalDist\n\n ! MPI variables\n INTEGER :: nprocs\n INTEGER :: myrank\n INTEGER :: ierr\n\n ! Count and temporary variables\n INTEGER :: i, ista, iend, step, temp\n REAL :: x, y, angle\n\n CALL MPI_INIT(ierr)\n CALL MPI_COMM_SIZE(MPI_COMM_WORLD, nprocs, ierr)\n CALL MPI_COMM_RANK(MPI_COMM_WORLD, myrank, ierr)\n\n CALL para_range(1, n, nprocs, myrank, ista, iend)\n\n DO i = 0, 9\n localDist(i) = 0\n ENDDO\n\n CALL srand(100 + myrank)\n DO i = ista, iend\n x = 0.0\n y = 0.0\n DO step = 1, 10\n angle = 2.0 * pi * rand()\n x = x + cos(angle)\n y = y + sin(angle)\n ENDDO\n temp = sqrt(x**2 + y**2)\n localDist(temp) = localDist(temp) + 1\n ENDDO\n CALL MPI_REDUCE(localDist, globalDist, 10, MPI_INTEGER, MPI_SUM, 0, &\n MPI_COMM_WORLD, ierr)\n\n IF (myrank == 0) write (*,*) 'distribution =', globalDist\n\n CALL MPI_FINALIZE(ierr)\nEND PROGRAM MonteCarlo2\n\n\nSUBROUTINE para_range(n1, n2, nprocs, irank, ista, iend)\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: n1\n INTEGER, INTENT(IN) :: n2\n INTEGER, INTENT(IN) :: nprocs\n INTEGER, INTENT(IN) :: irank\n INTEGER, INTENT(OUT) :: ista\n INTEGER, INTENT(OUT) :: iend\n\n INTEGER :: iwork1\n INTEGER :: iwork2\n\n iwork1 = (n2 - n1 + 1) / nprocs\n iwork2 = MOD(n2 - n1 + 1, nprocs)\n ista = irank * iwork1 + n1 + MIN(irank, iwork2)\n iend = ista + iwork1 - 1\n IF (iwork2 > irank) iend = iend + 1\nEND\n", "meta": {"hexsha": "3df226fc3b0661ad2253a12dd4f69d8a720a3530", "size": 1929, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/omp/apps/mpi/ex5/version2/mc.f90", "max_stars_repo_name": "tianyi93/hpxMP_mirror", "max_stars_repo_head_hexsha": "668e8881a6f2f437a614ae92e205ae49f083691e", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2018-07-16T14:39:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-08T11:25:09.000Z", "max_issues_repo_path": "examples/omp/apps/mpi/ex5/version2/mc.f90", "max_issues_repo_name": "tianyi93/hpxMP_mirror", "max_issues_repo_head_hexsha": "668e8881a6f2f437a614ae92e205ae49f083691e", "max_issues_repo_licenses": ["BSL-1.0"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2018-06-18T14:59:09.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-16T20:43:57.000Z", "max_forks_repo_path": "examples/omp/apps/mpi/ex5/version2/mc.f90", "max_forks_repo_name": "tianyi93/hpxMP_mirror", "max_forks_repo_head_hexsha": "668e8881a6f2f437a614ae92e205ae49f083691e", "max_forks_repo_licenses": ["BSL-1.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2018-06-22T18:44:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-21T11:17:28.000Z", "avg_line_length": 25.3815789474, "max_line_length": 79, "alphanum_fraction": 0.6298600311, "num_tokens": 654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.8856314617436728, "lm_q1q2_score": 0.7950271889014976}} {"text": "!TITLE Projectile Motion ProjectileMotion.f90\n! Fortran for Science and Engineering\n!COMMENT\n! Objective: Compute the position (x and y co-ordinates) and the velocity\n! (magnitude and direction) of a projectile, given t,\n! the time since launch, u, the launch velocity, a, the\n! initial angle of launch (in degrees), and g,\n! the acceleration due to gravity.\n! Input: -\n! Output: -\n! Author: Chris B. Kirov\n! Date: 31.03.20\n\nprogram ProjectileMotion\n implicit none\n\n ! Constants !\n real, parameter :: PI = 3.1415927 ! pi\n real, parameter :: g = 9.81 ! acceleration due to gravity\n\n ! Initial conditions !\n real a ! launch angle in degrees\n real u ! launch velocity\n real t ! time of flight\n\n ! Wanted values !\n real theta ! direction at time t in degrees\n real x ! horizontal displacement\n real y ! vertical displacement\n real vx ! horizontal velocity\n real vy ! vertical velocity\n real v ! resultant velocity\n\n ! Read input !\n print *, \"Type launch angle [degrees]:\"\n read *, a\n\n print *, \"Type launch velocity [m/s]:\"\n read *, u\n\n print *, \"Type time of flight [s]:\"\n read *, t\n\n ! Calculate wanted values !\n a = a * PI / 180. ! convert to radians\n\n x = u * cos(a) * t\n y = u * sin(a) * t - g * t * t / 2.0\n\n vx = u * cos(a)\n vy = u * sin(a) - g * t\n\n v = sqrt(vx * vx + vy * vy)\n theta = tan(vy / vx) * 180 / PI ! directly converted in degrees\n\n ! Print results !\n print *, \"Horizontal displacement, x: \", x, \"Vertical displacement, y: \", y\n print *, \"Horizontal velocity, Vx: \", vx, \"Vertical velocity, Vy: \", vy\n print *, \"Resultant velocity magnitude, V: \", v, \"Resultant Velocity Direction, Theta: \", theta\nend program ProjectileMotion\n", "meta": {"hexsha": "dacb0721b9cb4bb5e1ed076d2cc0ac21e5f4f114", "size": 2299, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Visual Studio 2010/Projects/Chapter22 Exercise 6/7. Fortran/0ProgramInFortran.f90", "max_stars_repo_name": "Ziezi/Programming-Principles-and-Practice-Using-C-by-Bjarne-Stroustrup-", "max_stars_repo_head_hexsha": "6fd64801863e883508f15d16398744405f4f9e34", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-10-24T15:16:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-14T13:53:50.000Z", "max_issues_repo_path": "Visual Studio 2010/Projects/Chapter22 Exercise 6/7. Fortran/0ProgramInFortran.f90", "max_issues_repo_name": "ChrisBKirov/Programming-Principles-and-Practice-Using-C-by-Bjarne-Stroustrup-", "max_issues_repo_head_hexsha": "6fd64801863e883508f15d16398744405f4f9e34", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Visual Studio 2010/Projects/Chapter22 Exercise 6/7. Fortran/0ProgramInFortran.f90", "max_forks_repo_name": "ChrisBKirov/Programming-Principles-and-Practice-Using-C-by-Bjarne-Stroustrup-", "max_forks_repo_head_hexsha": "6fd64801863e883508f15d16398744405f4f9e34", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-10-29T15:30:37.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-18T15:15:09.000Z", "avg_line_length": 37.6885245902, "max_line_length": 99, "alphanum_fraction": 0.4806437582, "num_tokens": 506, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392795, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7950175764173864}} {"text": "module nrtools\n use nrtype\ncontains\n recursive function rcsv_bicoef(n, k) result(bicoef)\n !===========================================================================!\n ! Recursive function for the calculation of binomial coefficients. !\n ! April 19th 2016. !\n ! Daniel Celis Garza !\n !---------------------------------------------------------------------------!\n ! This function recursively calculates the binomial coefficient for a given !\n ! n and k. !\n ! n choose k = n!/( k! * (n - k)! ) = n choose (n - k) !\n !\n ! n!/( k! * (n - k)! ) = n(n-1)(n-2)...(n-k+1)/k !\n ! = (n/k) * (n-1)!/( (k-1)! * (n-k)! ) !\n !---------------------------------------------------------------------------!\n ! Inputs:\n ! n = integer n\n ! k = integer k\n !---------------------------------------------------------------------------!\n ! Outputs:\n ! bicoef = integer type i16 !\n !===========================================================================!\n implicit none\n integer, intent(in) :: n, k\n real(dp) :: bicoef\n\n ! Identify Key Scenarios.\n iks: if (k > n) then\n write(*,*) \" Error: nrtools: rcsv_bicoef: iks: n must be greater than k. k = \", k, \", n = \", n\n return\n else if (k == 0._dp) then iks\n bicoef = 1._dp\n else if (k > n/2) then iks\n ! Recurse function so as to reduce the number of operations to at most n/2 at the numerator and denominator.\n bicoef = rcsv_bicoef(n, n-k)\n else iks\n ! Calculate binomial coefficient.\n bicoef = float(n)/float(k) * rcsv_bicoef(n-1, k-1)\n end if iks\n\n end function rcsv_bicoef\n\n function ln_gamma(x)\n ! Approximates the natural logarithm of the gamma function for x \\in \\reals and x > 0\n implicit none\n real(dp), intent(in) :: x\n real(dp) :: ln_gamma\n real(dp) :: tmp\n real(dp), parameter, dimension(7) :: coef = [1.000000000190015_dp,76.18009172947146_dp,-86.50532032941677_dp,&\n 0._dp,0._dp,0._dp,0._dp]\n real(dp), parameter :: sqrtau = sqrt(tau)\n\n ! Check that x > 0.\n xg0: if (x <= 0._dp) then\n write(*,*) \" Error: nrtools: ln_gamma: xg0: x must be greater than 0. x = \", x\n return\n end if xg0\n\n tmp = x + 5.5_dp\n tmp = (x + 0.5_dp) * log(tmp) - tmp\n ln_gamma = tmp + log(sqrtau * (coef(1) + sum( coef(2:7) / arthm_prog( x + 1._dp, 1._dp, size(coef(2:7)) ) ) ) / x )\n\n end function ln_gamma\n\n function arthm_prog(first, step, n)\n ! Calculates the arithmetic progression with step = step.\n implicit none\n real(dp), intent(in) :: first, step\n integer, intent(in) :: n\n real(dp) :: arthm_prog(n)\n integer :: i ! Counter\n\n arthm_prog(1) = first\n\n do i = 2, n\n arthm_prog(i) = arthm_prog(i-1) + step\n end do\n\n end function arthm_prog\n\n recursive function rcsv_gamma(z) result(gamma)\n\n ! Approximates the gamma function via Lanczos' approximation, with gamma = 8, N = 9\n ! https://en.wikipedia.org/wiki/Lanczos_approximation\n implicit none\n complex(dpc), intent(in) :: z\n complex(dpc) :: gamma\n complex(dpc) :: tmp, t\n real(dp) :: x\n integer :: i\n real(dp), parameter, dimension(9) :: coef = [0.99999999999980993_dp, 676.5203681218851_dp, -1259.1392167224028_dp, &\n 771.32342877765313_dp, -176.61502916214059_dp, 12.507343278686905_dp,&\n -0.13857109526572012_dp, 9.9843695780195716d-6, 1.5056327351493116d-7]\n real(dp), parameter :: sqrtau = sqrt(tau)\n\n tmp = z\n\n ! Calculate Gamma Function\n cgf: if( real(tmp) <= 0.5_dp ) then\n\n gamma = pi / ( sin(pi*tmp) * rcsv_gamma(1._dp-tmp) )\n\n else cgf\n\n tmp = tmp - 1._dp\n x = coef(1)\n\n ! Calculate the Arithmetic Progression and Divide.\n apd: do i = 2, size(coef)\n x = x + coef(i) / (tmp + i - 1)\n end do apd\n\n t = tmp + size(coef) - 1.5_dp\n\n gamma = sqrtau * t ** (tmp + 0.5_dp) * exp(-t) * x\n\n end if cgf\n end function rcsv_gamma\n\n recursive function rcsv_ln_gamma(z) result(ln_gamma)\n ! Calculates the value of the natural logarithm of the gamma function for gamma = 8 and N = 9\n implicit none\n complex(dpc), intent(in) :: z\n complex(dpc) :: ln_gamma\n complex(dpc) :: tmp, t\n real(dp) :: x\n integer :: i\n real(dp), parameter, dimension(9) :: coef = [0.99999999999980993_dp, 676.5203681218851_dp, -1259.1392167224028_dp, &\n 771.32342877765313_dp, -176.61502916214059_dp, 12.507343278686905_dp,&\n -0.13857109526572012_dp, 9.9843695780195716d-6, 1.5056327351493116d-7]\n real(dp), parameter :: lnsqrtau = log(sqrt(tau)), lnpi = log(pi)\n\n tmp = z\n\n ! Calculate Ln(Gamma), it takes the main branch cut.\n clg: if (real(tmp) <= 0.5_dp) then\n\n ln_gamma = lnpi - log(sin(pi*tmp)) - rcsv_ln_gamma(1._dp-tmp)\n\n else clg\n\n tmp = tmp - 1._dp\n x = coef(1)\n\n ! Calculate tge Arithmetic Progression and Divide.\n apd: do i = 2, size(coef)\n x = x + coef(i) / (tmp + i - 1)\n end do apd\n\n t = tmp + size(coef) - 1.5_dp\n\n ln_gamma = lnsqrtau + log(t)*(tmp + 0.5_dp) -t + log(x)\n\n end if clg\n\n end function rcsv_ln_gamma\nend module nrtools\n", "meta": {"hexsha": "c6454089f2e4ed0046446d2d6810774ff6132dd2", "size": 5181, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "number_theory/nrtools.f08", "max_stars_repo_name": "dcelisgarza/applied_math", "max_stars_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2015-09-30T19:22:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T23:33:04.000Z", "max_issues_repo_path": "number_theory/nrtools.f08", "max_issues_repo_name": "dcelisgarza/applied_math", "max_issues_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "number_theory/nrtools.f08", "max_forks_repo_name": "dcelisgarza/applied_math", "max_forks_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.5849056604, "max_line_length": 120, "alphanum_fraction": 0.5493148041, "num_tokens": 1673, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896693699845, "lm_q2_score": 0.8633916134888614, "lm_q1q2_score": 0.7950020783212262}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! MODULE CONSTANTS_MODULE\n!\n! This module defines constants that are used by other modules \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nmodule constants_module\n\n real, parameter :: PI = 3.141592653589793\n real, parameter :: OMEGA_E = 7.292e-5 ! Angular rotation rate of the earth\n\n real, parameter :: DEG_PER_RAD = 180./PI\n real, parameter :: RAD_PER_DEG = PI/180.\n \n ! Mean Earth Radius in m. The value below is consistent\n ! with NCEP's routines and grids.\n real, parameter :: A_WGS84 = 6378137.\n real, parameter :: B_WGS84 = 6356752.314\n real, parameter :: RE_WGS84 = A_WGS84\n real, parameter :: E_WGS84 = 0.081819192\n\n real, parameter :: A_NAD83 = 6378137.\n real, parameter :: RE_NAD83 = A_NAD83\n real, parameter :: E_NAD83 = 0.0818187034\n\n real, parameter :: EARTH_RADIUS_M = 6370000. ! same as MM5 system\n real, parameter :: EARTH_CIRC_M = 2.*PI*EARTH_RADIUS_M\n\n real, parameter :: G = 9.81 ! m/s\n\nend module constants_module\n", "meta": {"hexsha": "96694e2ab6706f868436ddcc1c4d4ece43602801", "size": 1109, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Emissions/EPA_Anthropgenic/ANTHRO_EPA_CAMSE/src_2d/constants_module.f90", "max_stars_repo_name": "mattldawson/IPT", "max_stars_repo_head_hexsha": "b9c08dc0d2161897e87971d72206dd5bfa98adf6", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-08-09T12:27:15.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-04T20:57:33.000Z", "max_issues_repo_path": "Emissions/EPA_Anthropgenic/ANTHRO_EPA_CAMSE/src_2d/constants_module.f90", "max_issues_repo_name": "mattldawson/IPT", "max_issues_repo_head_hexsha": "b9c08dc0d2161897e87971d72206dd5bfa98adf6", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 15, "max_issues_repo_issues_event_min_datetime": "2020-08-14T16:51:34.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-08T15:57:38.000Z", "max_forks_repo_path": "Emissions/EPA_Anthropgenic/ANTHRO_EPA_CAMSE/src_2d/constants_module.f90", "max_forks_repo_name": "mattldawson/IPT", "max_forks_repo_head_hexsha": "b9c08dc0d2161897e87971d72206dd5bfa98adf6", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-01-15T18:07:32.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-08T19:08:24.000Z", "avg_line_length": 35.7741935484, "max_line_length": 80, "alphanum_fraction": 0.5798016231, "num_tokens": 323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966732132748, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7948893801827254}} {"text": "! ToDo: mergeSort is not right\nmodule sorting \n use iso_fortran_env, only: i4 => int32, i8 => int64\n implicit none\ncontains\n subroutine bubbleSort(array)\n implicit none\n integer, dimension(:):: array\n integer :: i, j, tem\n i = size(array)\n do while (i > 1)\n do j = 1, i - 1 \n if (array(j) > array(j + 1)) then\n tem = array(j)\n array(j) = array(j + 1)\n array(j + 1) = tem\n end if \n end do\n i = i - 1\n end do \n end subroutine bubbleSort\n\n subroutine selectSort(array) \n implicit none\n integer, dimension(:) :: array\n integer :: i, j, tem\n \n\n do i = 1, size(array) - 1\n do j = i + 1, size(array)\n if (array(i) > array(j)) then\n tem = array(i)\n array(i) = array(j)\n array(j) = tem\n end if \n end do\n end do\n end subroutine selectSort\n\n pure recursive function mergeSort(array) result(res)\n implicit none\n integer, dimension(:), intent(in) :: array\n integer, dimension(size(array)) :: res\n integer, dimension(size(array)/2) :: left\n integer, dimension(size(array) - size(array)/2) :: right \n integer :: mid, l, r, i \n \n if (size(array) > 1) then \n mid = size(array) / 2\n left = array(:mid) \n right = array(mid+1:)\n mergeSort(left)\n mergeSort(right)\n end if \n \n l = 1\n r = 1\n i = 1\n do while(l <= size(left) .and. r <= size(right))\n if (left(l) < right(r)) then \n res(i) = left(l)\n l = l + 1\n else\n res(i) = right(r)\n r = r + 1\n end if\n i = i + 1\n end do\n\n do while(l <= size(left))\n res(i) = left(l)\n l = l + 1\n i = i + 1\n end do \n do while(r <= size(right))\n res(i) = right(r)\n r = r + 1\n i = i + 1\n end do \n end function mergeSort\n\n pure recursive function quickSort(x) result(res)\n integer, dimension(:), intent(in) :: x !! Input array\n integer, dimension(size(x)) :: res\n integer, dimension(size(x)- 1) :: tem\n integer :: pivot\n\n if(size(x) > 1)then\n pivot = x(size(x) / 2 + 1)\n tem = [x(1 : size(x)/2), x(size(x) / 2 + 2:)]\n res = [quickSort(pack(tem, tem < pivot)), pivot, &\n quickSort(pack(tem, tem >= pivot))]\n else\n res = x\n endif\n end function quickSort\nend module sorting \n\nprogram test\n use sorting, only : bubbleSort, selectSort, mergeSort, quickSort\n implicit none\n integer, dimension(5) :: array = [2, 9, 3, 0, -1]\n integer, dimension(8) :: array_8, res \n call bubbleSort(array)\n print *, array\n \n array = [2, 9, 3, 0, -1]\n call selectSort(array)\n print *, array\n\n\n array_8 = [2, 11, 4, 1, 9, 3, 0, -1]\n res = mergeSort(array_8)\n print *, res\n \n array_8 = [2, 11, 4, 1, 9, 3, 0, -1]\n print *, \"OA: \", array_8\n res = quickSort(array_8)\n print *, res\nend program test\n", "meta": {"hexsha": "d70bd9c8f9524c54cc8d5ea1426fb9c73d63d467", "size": 3346, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Algorithm/sorting/sorting.f90", "max_stars_repo_name": "ComplicatedPhenomenon/Fortran_Takeoff", "max_stars_repo_head_hexsha": "a13180050367e59a91973af96ab680c2b76097be", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithm/sorting/sorting.f90", "max_issues_repo_name": "ComplicatedPhenomenon/Fortran_Takeoff", "max_issues_repo_head_hexsha": "a13180050367e59a91973af96ab680c2b76097be", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithm/sorting/sorting.f90", "max_forks_repo_name": "ComplicatedPhenomenon/Fortran_Takeoff", "max_forks_repo_head_hexsha": "a13180050367e59a91973af96ab680c2b76097be", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.652892562, "max_line_length": 68, "alphanum_fraction": 0.4572624029, "num_tokens": 931, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.8723473813156294, "lm_q1q2_score": 0.7948652276246005}} {"text": "module statistics\n !! Provides routines for basic statistical methods. \n \n implicit none\n \n public :: factorial, mean, variance, standardDeviation, covariance\n \ncontains\n\npure integer function factorial(x) result(xfac)\n !! Returns the factorial of the scalar value \\(\\mathbf{x}\\),\n !! $$ x! = n(n-1)(n-2)\\cdots(3)(2)(1) $$\n\n integer, intent(in) :: x\n\n integer :: i\n \n xfac = 1\n if (x >= 0) then\n do i = x, 1, -1\n xfac = xfac * i\n end do\n end if\n\nend function factorial\n \npure real function mean(x) result(mu)\n !! Returns the arithmatic mean of a vector \\(\\mathbf{x}\\).\n !! $$ \\mu = \\frac{1}{n} \\sum_{i=1}^n x_i $$\n\n implicit none\n\n real, allocatable, intent(in) :: x(:)\n \n real :: Sx\n integer :: n, i, l, u\n\n mu = 0.0\n Sx = 0.0\n \n if (allocated(x)) then\n n = size(x)\n l = lbound(x,1)\n u = ubound(x,1)\n \n do i = l, u\n Sx = Sx + x(i)\n end do\n\n mu = Sx / n\n end if\nend function mean\n\npure real function median(x) result (xm)\n !! Returns the median of a vector. If the vector has an odd number\n !! of elements, the \"mean of middle\" two is returned.\n\n implicit none\n\n real, allocatable, intent(in) :: x(:)\n\n integer :: n, nd2\n real :: xmm1, xmp1\n\n n = size(x)\n nd2 = n/2\n\n if (mod(n,2) .eq. 0) then\n xm = x(nd2)\n else\n xmm1 = x(nd2-1)\n xmp1 = x(nd2+1)\n xm = (xmm1 + xmp1) / 2.0\n end if\n \nend function median\n\npure real function variance(x) result(ss)\n !! Returns the sample variance of the vector \\(\\mathbf{x}\\),\n !! $$ s^2 = \\frac{1}{n-1} \\sum_{i=1}^n \\left(x_i - \\mu_x \\right)^2 $$\n\n implicit none\n\n real, allocatable, intent(in) :: x(:)\n\n integer :: n, i, l, u\n real :: xb\n\n n = size(x)\n\n xb = mean(x)\n ss = 0.0\n \n if (allocated(x)) then\n l = lbound(x,1)\n u = ubound(x,1)\n do i = l, u\n ss = ss + (x(i) - xb)**2\n end do\n\n ss = 1 / (n - 1) * ss\n end if\n \nend function variance\n\npure real function standardDeviation(x) result(s)\n !! Returns the sample standard deviation of a vector \\(\\mathbf{x}\\),\n !! $$ s = \\sqrt{\\frac{1}{n-1} \\sum_{i=1}^n \\left(x_i - \\mu_x \\right)^2} $$\n\n implicit none\n\n real, allocatable, intent(in) :: x(:)\n\n s = sqrt(variance(x))\n\nend function standardDeviation\n\npure real function covariance(x, y) result(sigma)\n !! Returns the covariance of two vectors \\(\\mathbf{x}\\) and \\(\\mathbf{y}\\),\n !! $$ \\sigma(x,y) =\\frac{1}{n-1} \\sum_{i=1}^n \\left(x_i - \\mu_x \\right) \\left(y_i-\\mu_y\\right) $$\n\n implicit none\n \n real, allocatable, intent(in) :: x(:), y(:)\n \n real :: Sx, Sy, xb, yb\n integer :: n, i, l, u\n\n !!@todo If x and y aren't same size, return error\n !!@todo Handle x and y not same bound start/end\n sigma = 0.0\n \n if (allocated(x).and. allocated(y)) then\n n = size(x)\n\n xb = mean(x)\n yb = mean(y)\n\n l = lbound(x,1)\n u = ubound(x,1)\n do i = l, u\n Sx = x(i) - xb\n Sy = y(i) - yb\n sigma = sigma + (Sx*Sy / n)\n end do\n end if\n\nend function covariance\n\nend module statistics\n\n", "meta": {"hexsha": "2c127c2ca57ed0ad9885fe66e59a39c92af43542", "size": 2995, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/src/statistics.f90", "max_stars_repo_name": "ArmchairPhysicist/peano", "max_stars_repo_head_hexsha": "17b7ca6217c57063dea536e2be9c5fcd2c63b8fb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-12-15T15:22:53.000Z", "max_stars_repo_stars_event_max_datetime": "2018-04-04T02:40:08.000Z", "max_issues_repo_path": "doc/src/statistics.f90", "max_issues_repo_name": "ArmchairPhysicist/peano", "max_issues_repo_head_hexsha": "17b7ca6217c57063dea536e2be9c5fcd2c63b8fb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/src/statistics.f90", "max_forks_repo_name": "ArmchairPhysicist/peano", "max_forks_repo_head_hexsha": "17b7ca6217c57063dea536e2be9c5fcd2c63b8fb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.7039473684, "max_line_length": 99, "alphanum_fraction": 0.5662771285, "num_tokens": 1055, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029487, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.7947245375142948}} {"text": "program main\n implicit none\n integer :: n, ans\n print \"(a)\", \"Number n is \"\n read *, n\n print \"(a, i0)\", \"n! is \", factorial_f(n)\n call factorial_s(n, ans)\n print \"(a, i0)\", \"n! is \", ans\ncontains\n recursive function factorial_f(i) result(answer)\n integer :: answer\n integer, intent(in) :: i\n\n if (i == 0) then\n answer = 1\n else\n answer = i * factorial_f(i - 1)\n end if\n end function factorial_f\n\n recursive subroutine factorial_s(i, answer)\n integer, intent(in) :: i\n integer, intent(inout) :: answer\n\n if (i == 0) then\n answer = 1\n else\n call factorial_s(i - 1, answer)\n answer = i * answer\n end if\n end subroutine factorial_s\nend program main\n", "meta": {"hexsha": "f6d96e368789feb5f9604d93d3936e7f8dd3c4b7", "size": 819, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Lecture_04/recursive_factorial/factorial.f90", "max_stars_repo_name": "avsukhorukov/TdP2021-22", "max_stars_repo_head_hexsha": "dd3adf2ece93bcd685912614b848c5dddbcdf6de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture_04/recursive_factorial/factorial.f90", "max_issues_repo_name": "avsukhorukov/TdP2021-22", "max_issues_repo_head_hexsha": "dd3adf2ece93bcd685912614b848c5dddbcdf6de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture_04/recursive_factorial/factorial.f90", "max_forks_repo_name": "avsukhorukov/TdP2021-22", "max_forks_repo_head_hexsha": "dd3adf2ece93bcd685912614b848c5dddbcdf6de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.8181818182, "max_line_length": 52, "alphanum_fraction": 0.5238095238, "num_tokens": 217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252812, "lm_q2_score": 0.865224084314688, "lm_q1q2_score": 0.794691228097905}} {"text": "\nprogram main\n\nuse euler\n\nimplicit none\n\n ! This one is done by a pen and paper reduction of the problem. I\n ! found that I could represent the right corner trivially as the\n ! number of what iteration of square it was, squared. The subsequent\n ! results were as follows;\n !\n ! S0 = n**2;\n ! S1 = n**2 - (n - 1);\n ! S2 = n**2 - 2(n - 1);\n ! S3 = n**2 - 3(n - 1);\n !\n ! Thus, our formula for the sum of all of these 'rings' in the square\n ! is subsequently: 4n**2 - 6(n-1). Note however, this solution is for\n ! n in reals > 1\n\n integer (int64), parameter :: MAX_N = 1001;\n integer (int64) :: sum_diag, n;\n\n sum_diag = 1;\n\n do n = 3, MAX_N, 2\n sum_diag = sum_diag + outer_spiral_sum(n);\n end do\n\n call printint(sum_diag);\n\ncontains\n\n pure function outer_spiral_sum(n)\n\n integer (int64), intent(in) :: n;\n integer (int64) :: outer_spiral_sum;\n\n outer_spiral_sum = (4 * n ** 2) - 6 * n + 6;\n\n end function outer_spiral_sum\n\n\nend program main\n\n", "meta": {"hexsha": "74c6b80f338a0fc051515ed0c465d560d555817d", "size": 1147, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/number_spiral_diagonals.f95", "max_stars_repo_name": "guynan/project_euler", "max_stars_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-03-08T09:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T13:52:49.000Z", "max_issues_repo_path": "fortran/number_spiral_diagonals.f95", "max_issues_repo_name": "guynan/project_euler", "max_issues_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-11-03T01:20:46.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-24T22:54:59.000Z", "max_forks_repo_path": "fortran/number_spiral_diagonals.f95", "max_forks_repo_name": "guynan/project_euler", "max_forks_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-11-03T01:14:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T13:52:51.000Z", "avg_line_length": 24.4042553191, "max_line_length": 77, "alphanum_fraction": 0.5361813426, "num_tokens": 328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422241476943, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7946636736155598}} {"text": "! Created by EverLookNeverSee@GitHub on 6/8/20\n! For more information see FCS/img/Exercise_09_b.png\n\nprogram main\n implicit none\n ! declaring and initializing variables\n integer :: i, j, m, n\n real :: norm, tmp, sum_of_elements = 0.0\n real, allocatable, dimension(:,:) :: A\n ! getting shape of matrix from user input\n print *, \"Enter the shape of matrix(rows, columns):\"\n read *, m, n\n ! allocating mem space to matrix\n allocate(A(m, n))\n ! getting matrix elements from user input\n do i = 1, m\n do j = 1, n\n print *, \"A(\", i, j, \"):\"\n read *, A(i, j)\n end do\n end do\n ! sum of all squared elements in matrix\n do i = 1, m\n do j = 1, n\n tmp = (abs(A(i, j))) ** 2\n sum_of_elements = sum_of_elements + tmp\n end do\n end do\n ! square root of sum\n norm = sqrt(sum_of_elements)\n ! printing results\n print *, \"Norm =\", norm\nend program main", "meta": {"hexsha": "a8c2197ad67e060bcec666dff8f90c940e963bb8", "size": 963, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical methods/Exercise_09_b.f90", "max_stars_repo_name": "EverLookNeverSee/FCS", "max_stars_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-14T10:30:25.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-17T13:03:15.000Z", "max_issues_repo_path": "src/numerical methods/Exercise_09_b.f90", "max_issues_repo_name": "EverLookNeverSee/FCS", "max_issues_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-06-06T13:54:45.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-25T20:32:23.000Z", "max_forks_repo_path": "src/numerical methods/Exercise_09_b.f90", "max_forks_repo_name": "EverLookNeverSee/FCS", "max_forks_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-08T12:57:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T12:57:46.000Z", "avg_line_length": 29.1818181818, "max_line_length": 56, "alphanum_fraction": 0.5773624091, "num_tokens": 279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8757869819218865, "lm_q1q2_score": 0.7946122320062635}} {"text": "!\n! Modified Date: 03/16/2018\n! Description: Adjust the function\n!\nMODULE wm\n IMPLICIT NONE\n PRIVATE\n PUBLIC :: IsThisALeapYear, days_passed_of_this_year\nCONTAINS\n FUNCTION IsThisALeapYear(year) RESULT(leap_day)\n IMPLICIT NONE\n INTEGER :: year\n INTEGER :: leap_day\n\n IF(MOD(year,400) == 0) THEN\n leap_day = 1\n ELSE IF(MOD(year,100) == 0) THEN\n leap_day = 0\n ELSE IF (MOD(year,4) == 0) THEN\n leap_day = 1\n ELSE\n leap_day = 0\n END IF\n\n END FUNCTION IsThisALeapYear\n\n FUNCTION days_passed_of_this_year(year, month, day) RESULT(day_of_year)\n IMPLICIT NONE\n INTEGER :: year, month, day\n INTEGER :: day_of_year\n INTEGER :: i\n day_of_year = day\n DO i = 1, month - 1\n SELECT CASE(i)\n CASE(1, 3, 5, 7, 8, 10, 12)\n day_of_year = day_of_year + 31\n CASE(4, 6, 9, 11)\n day_of_year = day_of_year + 30\n CASE(2)\n day_of_year = day_of_year + 28 + IsThisALeapYear(year)\n END SELECT\n END DO\n END FUNCTION days_passed_of_this_year\nEND MODULE wm\nPROGRAM doy\n USE wm\n\n IMPLICIT NONE\n\n INTEGER :: i, days_accumulated\n INTEGER :: month_begin, day_begin, year_begin, &\n month_end, day_end, year_end\n WRITE (*,*)'This program caculates interval in days of 2 time'\n WRITE (*,*)'Begin date: month(1-12),day(1-31), year in that order'\n READ (*,*) month_begin, day_begin, year_begin\n WRITE (*,*)'End date: month(1-12),day(1-31), year in that order'\n READ (*,*) month_end, day_end, year_end\n\n IF (year_begin == year_end) THEN\n days_accumulated = days_passed_of_this_year(year_end, month_end, day_end)- &\n days_passed_of_this_year(year_begin, month_begin,day_begin)\n ELSE\n days_accumulated = IsThisALeapYear(year_begin) + 365 - days_passed_of_this_year(year_begin, month_begin,day_begin)\n DO i = year_begin+1, year_end -1\n days_accumulated = days_accumulated + IsThisALeapYear(i)+365\n END DO\n days_accumulated = days_accumulated + days_passed_of_this_year(year_end, month_end, day_end)\n END IF\n\n WRITE (*,*)day_begin, month_begin, year_begin\n WRITE (*,*)day_end, month_end, year_end\n WRITE (*,*)'day passed =',days_accumulated\nEND PROGRAM doy\n", "meta": {"hexsha": "251e41d6b3d0356a38d22b6b3e1819ff5ad70413", "size": 2230, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "basics/Module/cal_days.f90", "max_stars_repo_name": "ComplicatedPhenomenon/Fortran_Takeoff", "max_stars_repo_head_hexsha": "a13180050367e59a91973af96ab680c2b76097be", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "basics/Module/cal_days.f90", "max_issues_repo_name": "ComplicatedPhenomenon/Fortran_Takeoff", "max_issues_repo_head_hexsha": "a13180050367e59a91973af96ab680c2b76097be", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "basics/Module/cal_days.f90", "max_forks_repo_name": "ComplicatedPhenomenon/Fortran_Takeoff", "max_forks_repo_head_hexsha": "a13180050367e59a91973af96ab680c2b76097be", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.1351351351, "max_line_length": 119, "alphanum_fraction": 0.6659192825, "num_tokens": 686, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171238, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7945797453207193}} {"text": " subroutine inversep(a,c,n)\n!============================================================\n! Inverse matrix\n! Method: Based on Doolittle LU factorization for Ax=b\n! Alex G. December 2009\n! This version does parallel processing, using OpenMP.\n!\n! Note: A and C are both double precision.\n!-----------------------------------------------------------\n! input ...\n! a(n,n) - array of coefficients for matrix A\n! n - dimension\n! output ...\n! c(n,n) - inverse matrix of A\n! comments ...\n! the original matrix a(n,n) will be destroyed \n! during the calculation\n!===========================================================\nuse iso_c_binding\n\nimplicit none \ninteger n\nreal(8)\ta(n,n), c(n,n)\nreal(8), allocatable :: L(:,:), U(:,:), b(:), d(:), x(:)\nreal(8)\tcoeff\ninteger\ti, j, k\n\n! step 0: initialization for matrices L and U and b\n! Fortran 90/95 allows such operations on matrices\n\nallocate (L(n,n))\nallocate (U(n,n))\nallocate (b(n))\nallocate (d(n))\nallocate (x(n))\nL=0.0\nU=0.0\nb=0.0\n\n! step 1: forward elimination\n\n!$omp parallel default(private) shared(a,n,L)\n!$omp do\ndo k=1, n-1\n do i=k+1,n\n coeff=a(i,k)/a(k,k)\n L(i,k) = coeff\n do j=k+1,n\n a(i,j) = a(i,j)-coeff*a(k,j)\n end do\n end do\nend do\n!$omp end do\n!$omp end parallel\n\n! Step 2: prepare L and U matrices \n! L matrix is a matrix of the elimination coefficient\n! + the diagonal elements are 1.0\ndo i=1,n\n L(i,i) = 1.0\nend do\n! U matrix is the upper triangular part of A\ndo j=1,n\n do i=1,j\n U(i,j) = a(i,j)\n end do\nend do\n\n! Step 3: compute columns of the inverse matrix C\n!$omp parallel default(private) shared(U,L,n,c)\n!$omp do\ndo k=1,n\n b(k)=1.0\n d(1) = b(1)\n! Step 3a: Solve Ld=b using the forward substitution\n do i=2,n\n d(i)=b(i)\n do j=1,i-1\n d(i) = d(i) - L(i,j)*d(j)\n end do\n end do\n! Step 3b: Solve Ux=d using the back substitution\n x(n)=d(n)/U(n,n)\n do i = n-1,1,-1\n x(i) = d(i)\n do j=n,i+1,-1\n x(i)=x(i)-U(i,j)*x(j)\n end do\n x(i) = x(i)/u(i,i)\n end do\n! Step 3c: fill the solutions x(n) into column k of C\n do i=1,n\n c(i,k) = x(i)\n end do\n b(k)=0.0\nend do\n!$omp end do\n!$omp end parallel\ndeallocate(L)\ndeallocate(U)\ndeallocate(b)\ndeallocate(d)\ndeallocate(x)\nend subroutine inversep\n", "meta": {"hexsha": "0bb19cc8295f7d3faf88a6ef1536eb53b8830051", "size": 2230, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "inversep.f90", "max_stars_repo_name": "teuben/ppmap", "max_stars_repo_head_hexsha": "2ff0b07350f883ee34ff4acc5eab374cdde8d327", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-05-31T16:15:35.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-12T14:22:57.000Z", "max_issues_repo_path": "inversep.f90", "max_issues_repo_name": "teuben/ppmap", "max_issues_repo_head_hexsha": "2ff0b07350f883ee34ff4acc5eab374cdde8d327", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-09-05T20:28:54.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-05T20:28:54.000Z", "max_forks_repo_path": "inversep.f90", "max_forks_repo_name": "teuben/ppmap", "max_forks_repo_head_hexsha": "2ff0b07350f883ee34ff4acc5eab374cdde8d327", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-05-31T16:15:28.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-07T16:35:39.000Z", "avg_line_length": 21.2380952381, "max_line_length": 61, "alphanum_fraction": 0.567264574, "num_tokens": 749, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554476, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.794579738516623}} {"text": "program main\n implicit none\n\n integer :: required_divisors = 500\n integer :: num, i\n\n num = 0\n i = 0\n do while (count_divisors(num) < required_divisors)\n num = num + i\n i = i + 1\n end do\n\n print *, num\n\n\ncontains\nfunction count_divisors(number)\n implicit none\n integer, intent(in) :: number\n integer :: count_divisors\n integer :: i\n\n count_divisors = 1\n do i = 2, number / 2\n if (mod(number, i) == 0) then\n count_divisors = count_divisors + 1\n end if\n end do\n\n count_divisors = count_divisors + 1\n \n end function count_divisors\nend program main", "meta": {"hexsha": "7ec11456056c2573c557cffc4ef263fa60bf6328", "size": 685, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Problem_12/main.f95", "max_stars_repo_name": "jdalzatec/EulerProject", "max_stars_repo_head_hexsha": "2f2f4d9c009be7fd63bb229bb437ea75db77d891", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-28T05:32:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T05:32:58.000Z", "max_issues_repo_path": "Problem_12/main.f95", "max_issues_repo_name": "jdalzatec/EulerProject", "max_issues_repo_head_hexsha": "2f2f4d9c009be7fd63bb229bb437ea75db77d891", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Problem_12/main.f95", "max_forks_repo_name": "jdalzatec/EulerProject", "max_forks_repo_head_hexsha": "2f2f4d9c009be7fd63bb229bb437ea75db77d891", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.1470588235, "max_line_length": 54, "alphanum_fraction": 0.5532846715, "num_tokens": 183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129328, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7945797283104781}} {"text": "module funcs\nimplicit none\ncontains\n\nreal(kind=8) function f(x)\n real(kind=8) x\n\n f = 2*sin(sinh(1/(sin(x)))**(-6))*(1/sin(x)) - 0.5\nend function f\n\nend module funcs\n", "meta": {"hexsha": "ce93d49d35ecad34c6789d0e6c50d5e533b234cc", "size": 170, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ME_Numerical_Methods/HW4/ex2/mod.f95", "max_stars_repo_name": "ElenaKusevska/Fortran_exercises", "max_stars_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ME_Numerical_Methods/HW4/ex2/mod.f95", "max_issues_repo_name": "ElenaKusevska/Fortran_exercises", "max_issues_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ME_Numerical_Methods/HW4/ex2/mod.f95", "max_forks_repo_name": "ElenaKusevska/Fortran_exercises", "max_forks_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.1666666667, "max_line_length": 53, "alphanum_fraction": 0.6352941176, "num_tokens": 62, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9559813526452772, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7945572591317858}} {"text": "!**********************************************************************************************************\n!\n! C O N V E R S I O N D E T E M P E R A T U R A\n!\n! Program: fahtocel\n! Autor: David Duran\n! Fecha: 28 de junio del 2021\n! Lenguaje: Fortran-90\n! Versión: 0.3\n! Descripción: Este programa convierte de Fahrenheit a Celsius y viceversa.\n!\n!**********************************************************************************************************\n\nprogram fahtocel\n\n integer :: opcion\n integer:: fh\n real :: cl\n\n do\n \n print*, \"\"\n print*, \"OPCIÓN 1: Convertir de Fahrenheit a Celsius.\"\n print*, \"OPCIÓN 2: Convertir de Celsius a Fahrenheit.\"\n print*, \"\"\n print*, \"Escriba la opción que prefiera, 1 o 2\"\n print*, \"\"\n read*, opcion\n\n if (opcion == 1) then\n print*, \"\"\n print*, \"********************************************************\"\n print*, \"Nota: Solo se aceptan valores entre -50 y 150 (inclusivo)\"\n print*, \"Ingrese la temperatura en Fahrenheit: \"\n print*, \"********************************************************\"\n read*, fh\n \n if (-50 <= fh .AND. fh <= 150) then\n cl= (fh - 32) / 1.8\n print*, \"\"\n print*, \"La temperatura en Celsius es: \", cl\n else \n print*, \"\"\n print*, \"Valores no aceptados, intente nuevamente.\"\n end if\n else if(opcion == 2) then\n print*, \"\"\n print*, \"**********************************\"\n print*, \"Ingrese la temperatura en Celsius: \"\n print*, \"**********************************\"\n read*, cl\n fh= (cl*1.8)+32;\n print*, \"\"\n print*, \"La temperatura en Fahrenheit es: \",fh\n else\n print*, \"Opción inválida\"\n end if\n\n end do\n\nend program fahtocel", "meta": {"hexsha": "7356ebb956305185ba84d786c87fa63f2cea42bb", "size": 1935, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fahtocel.f90", "max_stars_repo_name": "totallynotdavid/fortran", "max_stars_repo_head_hexsha": "da1551313ea6016fef19bc37445a3cb462e6fd8a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fahtocel.f90", "max_issues_repo_name": "totallynotdavid/fortran", "max_issues_repo_head_hexsha": "da1551313ea6016fef19bc37445a3cb462e6fd8a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fahtocel.f90", "max_forks_repo_name": "totallynotdavid/fortran", "max_forks_repo_head_hexsha": "da1551313ea6016fef19bc37445a3cb462e6fd8a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.7213114754, "max_line_length": 107, "alphanum_fraction": 0.3896640827, "num_tokens": 450, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939516, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.7945537903275264}} {"text": "subroutine laplacegridfortran(n, top, bottom, left, right, tol, iter_max, &\n phi, err_max, iters)\n\n implicit none\n integer, parameter :: dp = kind(0.d0)\n\n ! inputs\n real(dp), intent(in) :: top, bottom, left, right, tol\n integer, intent(in) :: n, iter_max\n\n ! outputs\n real(dp), intent(out), dimension(n+1, n+1) :: phi\n real(dp), intent(out) :: err_max\n integer, intent(out) :: iters\n\n ! local\n integer :: i, j\n real(dp) :: phi_prev\n\n\n phi(1, :) = bottom\n phi(n+1, :) = top\n phi(:, 1) = left\n phi(:, n+1) = right\n\n iters = 0\n err_max = 1e6\n\n do while (err_max > tol .and. iters < iter_max)\n\n err_max = -1.0\n\n ! iterating over interior points\n do i = 2, n\n do j = 2, n\n\n ! save previous point\n phi_prev = phi(i, j)\n\n ! update point\n phi(i, j) = (phi(i-1,j) + phi(i+1,j) + phi(i,j-1) + phi(i,j+1))/4.0\n\n ! update maximum error\n err_max = max(err_max, abs(phi(i, j) - phi_prev))\n end do\n end do\n\n iters = iters + 1\n\n end do\n\nend subroutine laplacegridfortran\n", "meta": {"hexsha": "f24afa5e478ef79c70a3c312c32984a5c2473cee", "size": 1165, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "onboarding/laplace.f90", "max_stars_repo_name": "BYUFLOWLab/BYUFLOWLab.github.io", "max_stars_repo_head_hexsha": "769487cf5a0b46afecd3984281f2dab0c1ac9b68", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-15T13:08:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-15T13:08:51.000Z", "max_issues_repo_path": "onboarding/laplace.f90", "max_issues_repo_name": "BYUFLOWLab/BYUFLOWLab.github.io", "max_issues_repo_head_hexsha": "769487cf5a0b46afecd3984281f2dab0c1ac9b68", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "onboarding/laplace.f90", "max_forks_repo_name": "BYUFLOWLab/BYUFLOWLab.github.io", "max_forks_repo_head_hexsha": "769487cf5a0b46afecd3984281f2dab0c1ac9b68", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-06-08T07:48:58.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-02T22:54:15.000Z", "avg_line_length": 21.9811320755, "max_line_length": 83, "alphanum_fraction": 0.5107296137, "num_tokens": 364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572635, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.794451223235439}} {"text": "c square matrix multiplication\n program matmul02\n integer n\n parameter (n=100)\n integer a(n,n), b(n,n), c(n,n), x\n integer i, j, k\n logical flg\n print *,n\nC initialize the square matrices with ones\n do j=1, n\n do i=1, n\n a(i,j) = 1\n b(i,j) = 1\n enddo\n enddo\nC multiply the two square matrices of ones\n do j=1, n\n do i=1, n\n x = 0\n do k=1, n\n x = x + a(i,k)*b(k,j)\n enddo\n c(i,j) = x\n enddo\n enddo\nC The result should be a square matrice of n\n flg = .TRUE.\n do j=1, n\n do i=1, n\n flg = flg .AND. (c(i,j) .EQ. n)\n enddo\n enddo\n if (flg .EQV. .FALSE.) then\n print *, (\"CHECK FAILED\")\n else\n print *, (\"CHECK SUCCEED\")\n endif\n end\n\n", "meta": {"hexsha": "d5cf0951f7fce6b6d33bc811ce7e096c1d40f10f", "size": 873, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Gpu/matmul02.f", "max_stars_repo_name": "DVSR1966/par4all", "max_stars_repo_head_hexsha": "86b33ca9da736e832b568c5637a2381f360f1996", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 51, "max_stars_repo_stars_event_min_datetime": "2015-01-31T01:51:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T02:01:50.000Z", "max_issues_repo_path": "packages/PIPS/validation/Gpu/matmul02.f", "max_issues_repo_name": "DVSR1966/par4all", "max_issues_repo_head_hexsha": "86b33ca9da736e832b568c5637a2381f360f1996", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2017-05-29T09:29:00.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-11T16:01:39.000Z", "max_forks_repo_path": "packages/PIPS/validation/Gpu/matmul02.f", "max_forks_repo_name": "DVSR1966/par4all", "max_forks_repo_head_hexsha": "86b33ca9da736e832b568c5637a2381f360f1996", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-03-26T08:05:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T02:01:51.000Z", "avg_line_length": 21.825, "max_line_length": 44, "alphanum_fraction": 0.4444444444, "num_tokens": 279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391386, "lm_q2_score": 0.8705972566572504, "lm_q1q2_score": 0.7943644223320557}} {"text": " MODULE funcs\n\t \t\timplicit none\n\t CONTAINS\n\t \t\tFUNCTION xFunc(x)\n\t \t\tREAL :: xFunc\n\t\t\tREAL :: x\n\t\t\txFunc = sin(x)/x\n\t\t\tRETURN\n\t \t\tEND FUNCTION xFunc\n\t END MODULE funcs\n\t \n\t MODULE integration\n\t \t\tUSE funcs\n\t\t\tCONTAINS\n\t\t\t SUBROUTINE trapzd(a, b, s, n)\n\t\t\t\t\t INTEGER n\n\t\t\t\t\t REAL a, b, s\n\t\t\t\t\t INTEGER it, j\n\t\t\t\t\t REAL del, sum, tnm, x\n\t\t\t\t\t if (n.eq.1) then\n\t\t\t\t\t\t\t\t\ts = 0.5*(b-a)*(xFunc(a) + xFunc(b))\n\t\t\t\t\t else\n\t\t\t\t\t\t\t\t\tit = 2**(n-2)\n\t\t\t\t\t\t\t\t\ttnm=it\n\t\t\t\t\t\t\t\t\tdel=(b-a)/tnm\n\t\t\t\t\t\t\t\t\tx=a+0.5*del\n\t\t\t\t\t\t\t\t\tsum = 0.\n\t\t\t\t\t\t\t\t\tdo j = 1, it\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsum = sum + xFunc(x)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tx = x + del\n\t\t\t\t\t\t\t\t\tend do\n\t\t\t\t\t\t\t\t\ts = 0.5*(s+(b-a)*sum/tnm)\n\t\t\t\t\t endif\n\t\t\t\t\t return\n\t\t\t END SUBROUTINE trapzd\n\n\t\t\t SUBROUTINE qsimp(a, b, s)\n\t\t\t\t\t INTEGER JMAX\n\t\t\t\t\t REAL a, b, s, EPS\n\t\t\t\t\t PARAMETER (EPS=1.e-6, JMAX=20)\n\n\t\t\t\t\t INTEGER j\n\t\t\t\t\t REAL os, ost, st\n\t\t\t\t\t ost=-1.e30\n\t\t\t\t\t os=-1.e30\n\t\t\t\t\t do j = 1, JMAX\n\t\t\t\t\t\t\t\tcall trapzd(a, b, st, j)\n\t\t\t\t\t\t\t\ts=(4.*st-ost)/3.\n\t\t\t\t\t\t\t\tjj: if (j.gt.5) then\n\t\t\t\t\t\t\t\t\tkk: if (abs(s-os).lt.EPS*abs(os)) then\n\t\t\t\t\t\t\t\t\t\t\t return\n\t\t\t\t\t\t\t\t\tend if kk\n\t\t\t\t\t\t\t\t\tmm: if (s.eq.0 .and. olds.eq.0) then\n\t\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\tend if mm\n\t\t\t\t\t\t\t\tend if jj\n\t\t\t\t\t\t\t\tos = s\n\t\t\t\t\t\t\t\tost = st\n\t\t\t\t\t end do\n\t\t\t END SUBROUTINE qsimp\n\t END MODULE integration\n\t \n\t PROGRAM CalIntegrator\n\t\t USE integration\n\t\t implicit none\n\t\t REAL a, b, s, pi\n\t\t INTEGER n\n\t\t pi = 3.141592654\n\t\t a = pi/2\n\t\t b = pi\n\t\t CALL qsimp(a, b, s)\n\t\t WRITE (*,*) s\n\t END PROGRAM CalIntegrator", "meta": {"hexsha": "626fc6b3a4b6555a96a7fdb4983a4e35a4baed39", "size": 1525, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Raw-Src/1D-Integration-Another-Method-final-ver1.1.f", "max_stars_repo_name": "tqbdev/Calculate-Integration-in-Fortran", "max_stars_repo_head_hexsha": "7bce95598a4cbd719e9f66c58622a3a24cfaa126", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Raw-Src/1D-Integration-Another-Method-final-ver1.1.f", "max_issues_repo_name": "tqbdev/Calculate-Integration-in-Fortran", "max_issues_repo_head_hexsha": "7bce95598a4cbd719e9f66c58622a3a24cfaa126", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Raw-Src/1D-Integration-Another-Method-final-ver1.1.f", "max_forks_repo_name": "tqbdev/Calculate-Integration-in-Fortran", "max_forks_repo_head_hexsha": "7bce95598a4cbd719e9f66c58622a3a24cfaa126", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.8904109589, "max_line_length": 47, "alphanum_fraction": 0.468852459, "num_tokens": 528, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222396, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7943609394816861}} {"text": "subroutine SphericalCapCoef(coef, theta, lmax)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis routine will return the coefficients for a spherical\n!\tcap (located at the north pole) with angular radius theta,\n!\tusing the geodesy 4-pi normalization.\n!\n!\tCalling Parameters:\n!\t\tIN\n!\t\t\ttheta\tAngular radius of spherical cap in RADIANS.\n!\t\tOUT\n!\t\t\tcoef\tm=0 coefficients normalized according to the \n!\t\t\t\tgeodesy convention, further normalized such\n!\t\t\t\tthat the degree-0 term is 1. (i.e., function \n!\t\t\t\thas an average value of one over the entire\n!\t\t\t\tsphere).\n!\t\tOPTIONAL\n!\t\t\tlmax\tMaximum spherical harmonic degree.\n!\n!\tDependencies: PlBar\n!\n!\tWritten by Mark Wieczorek\n!\n!\tCopyright (c) 2005, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\tuse SHTOOLS, only: PlBar\n\n\timplicit none\n\treal*8, intent(out) ::\tcoef(:)\n\treal*8, intent(in) ::\ttheta\n\tinteger, intent(in), optional ::\tlmax\n\treal*8 ::\tx, top, bot, pi\n\treal*8, allocatable ::\tpl(:)\n\tinteger ::\tl, lmax2, astat\n\t\n\t\n\tpi = acos(-1.0d0)\n\tcoef = 0.0d0\n\tx = cos(theta)\n\t\n\tif (present(lmax) ) then\n\t\tlmax2 = lmax\n\telse\n\t\tlmax2 = size(coef) - 1\n\tendif\n\t\n\tallocate(pl(lmax2+3), stat = astat)\n\t\n\tif(astat /=0) then\n\t\tprint*, \"Error --- SphericalCapCoef\"\n\t\tprint*, \"Unable to allocate array pl\", astat\n\t\tstop\n\tendif\n\t\n\tcall PlBar(pl, lmax2+2, x)\n\t\n\tcoef(1) = 1.0d0\n\t\n\tbot = pl(1) - pl(2) / sqrt(3.0d0)\n\t\n\tdo l=1, lmax2\n\t\ttop = pl(l) / sqrt(dble(2*l-1)) -pl(l+2) / sqrt(dble(2*l+3))\n\t\tcoef(l+1) = top / (bot * sqrt(dble(2*l+1)) )\n\tenddo\n\t\n\tdeallocate (pl)\n\t\t\nend subroutine SphericalCapCoef\n\n", "meta": {"hexsha": "459b48791bb395dd6c1e79d49e9d51acbd6a08db", "size": 1649, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/SphericalCapCoef.f95", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "spherical_splines/SHTOOLS/src/SphericalCapCoef.f95", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "spherical_splines/SHTOOLS/src/SphericalCapCoef.f95", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 22.9027777778, "max_line_length": 78, "alphanum_fraction": 0.5973317162, "num_tokens": 554, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002787, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7942708936009091}} {"text": "module stdlib_quadrature\n !! ([Specification](../page/specs/stdlib_quadrature.html#description))\n use stdlib_kinds, only: sp, dp, qp\n\n implicit none\n\n private\n\n ! array integration\n public :: trapz\n public :: trapz_weights\n public :: simps\n public :: simps_weights\n public :: gauss_legendre\n public :: gauss_legendre_lobatto\n\n\n interface trapz\n !! version: experimental\n !!\n !! Integrates sampled values using trapezoidal rule\n !! ([Specification](../page/specs/stdlib_quadrature.html#description))\n pure module function trapz_dx_sp(y, dx) result(integral)\n real(sp), dimension(:), intent(in) :: y\n real(sp), intent(in) :: dx\n real(sp) :: integral\n end function trapz_dx_sp\n pure module function trapz_dx_dp(y, dx) result(integral)\n real(dp), dimension(:), intent(in) :: y\n real(dp), intent(in) :: dx\n real(dp) :: integral\n end function trapz_dx_dp\n pure module function trapz_dx_qp(y, dx) result(integral)\n real(qp), dimension(:), intent(in) :: y\n real(qp), intent(in) :: dx\n real(qp) :: integral\n end function trapz_dx_qp\n module function trapz_x_sp(y, x) result(integral)\n real(sp), dimension(:), intent(in) :: y\n real(sp), dimension(:), intent(in) :: x\n real(sp) :: integral\n end function trapz_x_sp\n module function trapz_x_dp(y, x) result(integral)\n real(dp), dimension(:), intent(in) :: y\n real(dp), dimension(:), intent(in) :: x\n real(dp) :: integral\n end function trapz_x_dp\n module function trapz_x_qp(y, x) result(integral)\n real(qp), dimension(:), intent(in) :: y\n real(qp), dimension(:), intent(in) :: x\n real(qp) :: integral\n end function trapz_x_qp\n end interface trapz\n\n\n interface trapz_weights\n !! version: experimental\n !!\n !! Integrates sampled values using trapezoidal rule weights for given abscissas\n !! ([Specification](../page/specs/stdlib_quadrature.html#description_1))\n pure module function trapz_weights_sp(x) result(w)\n real(sp), dimension(:), intent(in) :: x\n real(sp), dimension(size(x)) :: w\n end function trapz_weights_sp\n pure module function trapz_weights_dp(x) result(w)\n real(dp), dimension(:), intent(in) :: x\n real(dp), dimension(size(x)) :: w\n end function trapz_weights_dp\n pure module function trapz_weights_qp(x) result(w)\n real(qp), dimension(:), intent(in) :: x\n real(qp), dimension(size(x)) :: w\n end function trapz_weights_qp\n end interface trapz_weights\n\n\n interface simps\n !! version: experimental\n !!\n !! Integrates sampled values using Simpson's rule\n !! ([Specification](../page/specs/stdlib_quadrature.html#description_3))\n ! \"recursive\" is an implementation detail\n pure recursive module function simps_dx_sp(y, dx, even) result(integral)\n real(sp), dimension(:), intent(in) :: y\n real(sp), intent(in) :: dx\n integer, intent(in), optional :: even\n real(sp) :: integral\n end function simps_dx_sp\n pure recursive module function simps_dx_dp(y, dx, even) result(integral)\n real(dp), dimension(:), intent(in) :: y\n real(dp), intent(in) :: dx\n integer, intent(in), optional :: even\n real(dp) :: integral\n end function simps_dx_dp\n pure recursive module function simps_dx_qp(y, dx, even) result(integral)\n real(qp), dimension(:), intent(in) :: y\n real(qp), intent(in) :: dx\n integer, intent(in), optional :: even\n real(qp) :: integral\n end function simps_dx_qp\n recursive module function simps_x_sp(y, x, even) result(integral)\n real(sp), dimension(:), intent(in) :: y\n real(sp), dimension(:), intent(in) :: x\n integer, intent(in), optional :: even\n real(sp) :: integral\n end function simps_x_sp\n recursive module function simps_x_dp(y, x, even) result(integral)\n real(dp), dimension(:), intent(in) :: y\n real(dp), dimension(:), intent(in) :: x\n integer, intent(in), optional :: even\n real(dp) :: integral\n end function simps_x_dp\n recursive module function simps_x_qp(y, x, even) result(integral)\n real(qp), dimension(:), intent(in) :: y\n real(qp), dimension(:), intent(in) :: x\n integer, intent(in), optional :: even\n real(qp) :: integral\n end function simps_x_qp\n end interface simps\n\n\n interface simps_weights\n !! version: experimental\n !!\n !! Integrates sampled values using trapezoidal rule weights for given abscissas\n !! ([Specification](../page/specs/stdlib_quadrature.html#description_3))\n pure recursive module function simps_weights_sp(x, even) result(w)\n real(sp), dimension(:), intent(in) :: x\n integer, intent(in), optional :: even\n real(sp), dimension(size(x)) :: w\n end function simps_weights_sp\n pure recursive module function simps_weights_dp(x, even) result(w)\n real(dp), dimension(:), intent(in) :: x\n integer, intent(in), optional :: even\n real(dp), dimension(size(x)) :: w\n end function simps_weights_dp\n pure recursive module function simps_weights_qp(x, even) result(w)\n real(qp), dimension(:), intent(in) :: x\n integer, intent(in), optional :: even\n real(qp), dimension(size(x)) :: w\n end function simps_weights_qp\n end interface simps_weights\n\n\n interface gauss_legendre\n !! version: experimental\n !!\n !! Computes Gauss-Legendre quadrature nodes and weights.\n pure module subroutine gauss_legendre_fp64 (x, w, interval)\n real(dp), intent(out) :: x(:), w(:)\n real(dp), intent(in), optional :: interval(2)\n end subroutine\n end interface gauss_legendre\n\n\n interface gauss_legendre_lobatto\n !! version: experimental\n !!\n !! Computes Gauss-Legendre-Lobatto quadrature nodes and weights.\n pure module subroutine gauss_legendre_lobatto_fp64 (x, w, interval)\n real(dp), intent(out) :: x(:), w(:)\n real(dp), intent(in), optional :: interval(2)\n end subroutine\n end interface gauss_legendre_lobatto\n\n\n ! Interface for a simple f(x)-style integrand function.\n ! Could become fancier as we learn about the performance\n ! ramifications of different ways to do callbacks.\n abstract interface\n pure function integrand_sp(x) result(f)\n import :: sp\n real(sp), intent(in) :: x\n real(sp) :: f\n end function integrand_sp\n pure function integrand_dp(x) result(f)\n import :: dp\n real(dp), intent(in) :: x\n real(dp) :: f\n end function integrand_dp\n pure function integrand_qp(x) result(f)\n import :: qp\n real(qp), intent(in) :: x\n real(qp) :: f\n end function integrand_qp\n end interface\n\n\n\nend module stdlib_quadrature\n", "meta": {"hexsha": "28c9bd06e55125c36a701ef019fd9b00e25676a9", "size": 7392, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stdlib_quadrature.f90", "max_stars_repo_name": "LKedward/stdlib-fpm", "max_stars_repo_head_hexsha": "312e798a2777d571efcf7e5f96f81a7297590685", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-05-05T10:52:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-26T02:40:56.000Z", "max_issues_repo_path": "src/stdlib_quadrature.f90", "max_issues_repo_name": "LKedward/stdlib-fpm", "max_issues_repo_head_hexsha": "312e798a2777d571efcf7e5f96f81a7297590685", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-03-20T12:36:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-17T07:56:11.000Z", "max_forks_repo_path": "src/stdlib_quadrature.f90", "max_forks_repo_name": "LKedward/stdlib-fpm", "max_forks_repo_head_hexsha": "312e798a2777d571efcf7e5f96f81a7297590685", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.9052631579, "max_line_length": 87, "alphanum_fraction": 0.5928030303, "num_tokens": 1745, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218412907381, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.7942708891034406}} {"text": "!\n! CalculiX - A 3-dimensional finite element program\n! Copyright (C) 1998-2021 Guido Dhondt\n!\n! This program is free software; you can redistribute it and/or\n! modify it under the terms of the GNU General Public License as\n! published by the Free Software Foundation(version 2);\n! \n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of \n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n! GNU General Public License for more details.\n!\n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n! \n subroutine cubic(a0,a1,a2,solreal,solimag,n)\n!\n! solves the cubic equation x**3+a2*x**2+a1*x+a0=0\n! (analytical solution)\n! there are three solutions in C (complex plane)\n! the real part of the solutions is stored in solreal(1..3),\n! the imaginary part in solimag(1..3). The real solutions have\n! the lower indices, their number is n\n!\n! Reference: Abramowitz, M. and Stegun, I., Handbook of \n! Mathematical Functions (10th printing, 1972 p 17)\n! \n implicit none\n! \n integer n\n!\n real*8 a0,a1,a2,solreal(3),solimag(3),q,r,d,s1,s2,\n & a,phi,s1r,s1i\n!\n write(30,*) 'a2,a1,a0 ',a2,a1,a0\n q=a1/3.d0-a2*a2/9.d0\n r=(a1*a2-3.d0*a0)/6.d0-(a2**3)/27.d0\n!\n d=q**3+r*r\n write(30,*) 'q,r,d ',q,r,d\n!\n if(d.gt.0) then\n!\n! one real solution, two complex conjugate complex\n! solutions\n!\n n=1\n s1=(r+dsqrt(d))**(1.d0/3.d0)\n s2=(r-dsqrt(d))\n if(s2.gt.0.d0) then\n s2=s2**(1.d0/3.d0)\n else\n s2=-(-s2)**(1.d0/3.d0)\n endif\n write(30,*) 'd>0 s1,s2 ',s1,s2\n!\n solreal(1)=(s1+s2)-a2/3.d0\n solreal(2)=-(s1+s2)/2.d0-a2/3.d0\n solreal(3)=solreal(2)\n!\n solimag(1)=0.d0\n solimag(2)=(s1-s2)*dsqrt(3.d0)/2.d0\n solimag(3)=-solimag(2)\n else\n!\n! three real solutions\n!\n n=3\n!\n! amplitude and phase of s1\n! \n a=(r*r-d)**(1.d0/6.d0)\n phi=(datan2(dsqrt(-d),r))/3.d0\nc phi=(datan(dsqrt(-d)/r))/3.d0\n write(30,*) 'd <=0 a,phi ',a,phi\n!\n! real and imaginary part of s1\n!\n s1r=a*dcos(phi)\n s1i=a*dsin(phi)\n write(30,*) 'd >=0 s1r,s1i ',s1r,s1i\n!\n solreal(1)=2.d0*s1r-a2/3.d0\n solreal(2)=-s1r-a2/3.d0-s1i*dsqrt(3.d0)\n solreal(3)=-s1r-a2/3.d0+s1i*dsqrt(3.d0)\n!\n solimag(1)=0.d0\n solimag(2)=0.d0\n solimag(3)=0.d0\n endif\n!\n return\n end\n \n\n", "meta": {"hexsha": "814707fcda0f602789d4aace096e8e2808806e74", "size": 2781, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ccx_prool/CalculiX/ccx_2.19/src/cubic.f", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/CalculiX/ccx_2.19/src/cubic.f", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ccx_prool/CalculiX/ccx_2.19/src/cubic.f", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0909090909, "max_line_length": 71, "alphanum_fraction": 0.5584322186, "num_tokens": 966, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109770159682, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7940527306190625}} {"text": "!> @brief This function returns the linearly interpolated y value between the two supplied points.\n!>\n!> @param[in] x1 The first x value.\n!>\n!> @param[in] x2 The second x value.\n!>\n!> @param[in] y1 The first y value.\n!>\n!> @param[in] y2 The second y value.\n!>\n!> @param[in] x The x value where the y value is desired.\n!>\n\nELEMENTAL FUNCTION func_interpolate_REAL32_points(x1, x2, y1, y2, x) RESULT(ans)\n USE ISO_FORTRAN_ENV\n\n IMPLICIT NONE\n\n ! Declare input variables ...\n REAL(kind = REAL32), INTENT(in) :: x\n REAL(kind = REAL32), INTENT(in) :: x1\n REAL(kind = REAL32), INTENT(in) :: x2\n REAL(kind = REAL32), INTENT(in) :: y1\n REAL(kind = REAL32), INTENT(in) :: y2\n\n ! Declare output variables ...\n REAL(kind = REAL32) :: ans\n\n ! Calculate value ...\n ans = (y1 * (x2 - x) + y2 * (x - x1)) / (x2 - x1)\nEND FUNCTION func_interpolate_REAL32_points\n", "meta": {"hexsha": "2e908318215f1f352a3433f6cd12d2144a6ab446", "size": 1158, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mod_safe/func_interpolate_points/func_interpolate_REAL32_points.f90", "max_stars_repo_name": "Guymer/fortranlib", "max_stars_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-28T02:05:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-16T16:50:21.000Z", "max_issues_repo_path": "mod_safe/func_interpolate_points/func_interpolate_REAL32_points.f90", "max_issues_repo_name": "Guymer/fortranlib", "max_issues_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-06-17T16:49:20.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-11T18:47:36.000Z", "max_forks_repo_path": "mod_safe/func_interpolate_points/func_interpolate_REAL32_points.f90", "max_forks_repo_name": "Guymer/fortranlib", "max_forks_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-11T04:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-11T04:51:33.000Z", "avg_line_length": 36.1875, "max_line_length": 98, "alphanum_fraction": 0.4835924007, "num_tokens": 285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706048, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.7940116398893666}} {"text": "module greatcircle\n !!Author : Masashi Ogiso (masashi.ogiso@gmail.com)\n !!Copyright: (c) Masashi Ogiso 2020\n !!License : MIT License https://opensource.org/licenses/MIT\n private\n public :: greatcircle_dist, latctog, latgtoc\n\n contains\n\n subroutine greatcircle_dist(lat0, lon0, lat1, lon1, delta_out, distance, azimuth, backazimuth)\n use nrtype, only : fp\n use constants, only : pi, r_earth, r2r1, deg2rad, rad2deg\n implicit none\n\n !!Calculate distance, azimuth, backazimuth using Vincenty (1975, Survey review)\n !!Input: (lat0, lon0) (point A) , (lat1, lon1) (point B)\n !!output: delta(rad), dist(km), az(rad, point A -> point B), baz(rad, point B -> point A)\n \n real(kind = fp), intent(in) :: lat0, lon0, lat1, lon1\n real(kind = fp), intent(out), optional :: delta_out, distance, azimuth, backazimuth\n \n real(kind = fp) :: c, b, delta, lat_0, lat_1, sin_lat0, cos_lat0, sin_lat1, cos_lat1, lon_diff, &\n & cos_ldiff, sin_ldiff\n \n !!geographical latitude to geocentral latitude\n call latgtoc(lat0, lat_0)\n call latgtoc(lat1, lat_1)\n\n sin_lat0 = sin(lat_0)\n cos_lat0 = cos(lat_0)\n sin_lat1 = sin(lat_1)\n cos_lat1 = cos(lat_1)\n lon_diff = (lon1 - lon0) * deg2rad\n cos_ldiff = cos(lon_diff)\n sin_ldiff = sin(lon_diff)\n delta = atan2(sqrt(cos_lat1 * sin_ldiff * cos_lat1 * sin_ldiff &\n & + (cos_lat0 * sin_lat1 - sin_lat0 * cos_lat1 * cos_ldiff) &\n & * (cos_lat0 * sin_lat1 - sin_lat0 * cos_lat1 * cos_ldiff)), &\n & (sin_lat0 * sin_lat1 + cos_lat0 * cos_lat1 * cos_ldiff))\n\n c = atan2(cos_lat1 * sin_ldiff, cos_lat0 * sin_lat1 - sin_lat0 * cos_lat1 * cos_ldiff)\n if(c .lt. 0.0_fp) c = c + 2.0_fp * pi\n b = pi + atan2(cos_lat0 * sin_ldiff, -sin_lat0 * cos_lat1 + cos_lat0 * sin_lat1 * cos_ldiff)\n if(b .ge. 2.0_fp * pi) b = b - 2.0_fp * pi\n \n if(present(delta_out)) delta_out = delta\n if(present(distance)) distance = r_earth * delta\n if(present(azimuth)) azimuth = c\n if(present(backazimuth)) backazimuth = b\n \n return\n end subroutine greatcircle_dist\n\n subroutine latgtoc(lat_in, lat_out)\n use nrtype, only : fp\n use constants, only : r2r1, deg2rad\n real(kind = fp), intent(in) :: lat_in !!degree\n real(kind = fp), intent(out) :: lat_out !!radian\n\n lat_out = atan(r2r1 * r2r1 * tan(lat_in * deg2rad))\n return\n end subroutine latgtoc\n\n subroutine latctog(lat_in, lat_out)\n use nrtype, only : fp\n use constants, only : r2r1, deg2rad, rad2deg\n real(kind = fp), intent(in) :: lat_in !!radian\n real(kind = fp), intent(out) :: lat_out !!degree\n\n lat_out = atan(tan(lat_in) / (r2r1 * r2r1)) * rad2deg\n return\n end subroutine latctog\n\n\nend module greatcircle\n\n", "meta": {"hexsha": "71c22a93e8141d7b0da0f4223493237dfa4bc6e2", "size": 2779, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "greatcircle.f90", "max_stars_repo_name": "mogiso/AmplitudeSourceLocation", "max_stars_repo_head_hexsha": "ad00d36e0b14c0e1262b88c4bc2caf04e0570140", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2020-10-30T10:43:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-26T06:21:37.000Z", "max_issues_repo_path": "greatcircle.f90", "max_issues_repo_name": "mogiso/AmplitudeSourceLocation", "max_issues_repo_head_hexsha": "ad00d36e0b14c0e1262b88c4bc2caf04e0570140", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "greatcircle.f90", "max_forks_repo_name": "mogiso/AmplitudeSourceLocation", "max_forks_repo_head_hexsha": "ad00d36e0b14c0e1262b88c4bc2caf04e0570140", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-18T12:00:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T12:00:20.000Z", "avg_line_length": 36.0909090909, "max_line_length": 101, "alphanum_fraction": 0.641597697, "num_tokens": 914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611608990299, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7939418982826316}} {"text": " SUBROUTINE lendeg( alat, amlat, amlong)\n! lendeg returns the length, in meters, of a degree of latitude\n! and longitude, given the latitude. The formula is taken from pg. 5\n! of Nathaniel Bowditch's \"American Practical Navigator\", Vol II., 1981\n! It is based on the WGS72 ellipsoid. Note that it's Volume TWO.\n! Read the preface of the book, it's worth the time.\n! This routine gets different answers from Bowditch on different\n! computers, try your computer and insert the results here!\n! Use a latitude of 45.0 degrees.\n! Bowditch gets lat meters = 111132, long meters = 78847\n! Casio fx-450 calculator = 111132.92 = 78847.306\n! Masscomp 5400 (68020) = 111132 = 78840.3\n!\n! Paul Henkart, March 1991\n! mod 14 Aug 07 - g95 ca't declare and set in same statement,\n!\n REAL alat, amlat, amlong\n REAL*8 pi\n DATA pi/3.141592654/\n REAL*8 alatrads\n!\n alatrads = ABS(alat) * pi / 180.D0\n amlat = 111132.92D0 - 559.82D0 * DCOS(2.D0*alatrads)\n & + 1.175D0 * DCOS(4.D0*alatrads) \n & - 0.0023D0 * DCOS(6.D0*alatrads)\n amlong = 111412.84D0 * DCOS(alatrads) \n & - 93.5D0 * DCOS(3.D0*alatrads)\n & + 0.118D0 * DCOS(5.D0*alatrads)\n RETURN\n END\n!\n!\n!\n SUBROUTINE dlendeg( dlat, dmlat, dmlong)\n! REAL*8 arguments\n REAL*8 dlat, dmlat, dmlong\n REAL*8 pi\n DATA pi/3.141592654/\n REAL*8 dlatrads\n!\n dlatrads = DABS(dlat) * pi / 180.D0\n dmlat = 111132.92D0 - 559.82D0 * DCOS(2.D0*dlatrads)\n & + 1.175D0 * DCOS(4.D0*dlatrads)\n & - 0.0023D0 * DCOS(6.D0*dlatrads)\n dmlong = 111412.84D0 * DCOS(dlatrads)\n & - 93.5D0 * DCOS(3.D0*dlatrads)\n & + 0.118D0 * DCOS(5.D0*dlatrads)\n RETURN\n END\n\n", "meta": {"hexsha": "dc6469f697cda820a68a2786895dfddd0fc7dc88", "size": 1768, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lendeg.f", "max_stars_repo_name": "henkart/sioseis-2020.5.0", "max_stars_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lendeg.f", "max_issues_repo_name": "henkart/sioseis-2020.5.0", "max_issues_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lendeg.f", "max_forks_repo_name": "henkart/sioseis-2020.5.0", "max_forks_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.6666666667, "max_line_length": 71, "alphanum_fraction": 0.6148190045, "num_tokens": 676, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850075259039, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7939394936385992}} {"text": "\nsubroutine linspace(xmin, xmax, n, x)\n ! Outputs n linearly spaced points between xmin and xmax.\n !\n ! Parameters\n ! ---------\n ! xmin : float\n ! Minimum x value.\n ! xmax : float\n ! Maximum x value.\n ! n : int\n ! Number of points.\n !\n ! Returns\n ! -------\n ! x : array\n ! Linearly space points.\n\n implicit none\n\n integer, parameter :: dp = kind(1.d0)\n\n integer, intent(in) :: n\n real(kind=dp), intent(in) :: xmin, xmax\n real(kind=dp), intent(out) :: x(n)\n\n integer :: i\n real(kind=dp) :: dx\n\n dx = (xmax-xmin)/(n-1)\n\n x(1) = xmin\n\n do i = 2, n\n x(i) = xmin + (i-1)*dx\n end do\n\nend subroutine linspace\n\n\nsubroutine midpoint(x, n, xmid)\n ! Outputs the midpoints of array x\n !\n ! Parameters\n ! ---------\n ! x : array\n ! array values.\n ! n : int\n ! Number of points in x.\n !\n ! Returns\n ! -------\n ! xmid : array\n ! Midpoint of two adjacent points in x.\n\n implicit none\n\n integer, parameter :: dp = kind(1.d0)\n\n integer, intent(in) :: n\n real(kind=dp), intent(in) :: x(n)\n real(kind=dp), intent(out) :: xmid(n-1)\n\n integer :: i\n\n do i = 1, n-1\n xmid(i) = 0.5*(x(i) + x(i+1))\n end do\n\nend subroutine midpoint\n", "meta": {"hexsha": "79b75a0b7a37c7001d51e9098795eec7aeed1dfc", "size": 1172, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "magpie/src/utils.f90", "max_stars_repo_name": "knaidoo29/magpie", "max_stars_repo_head_hexsha": "efab3c2666aab2c928ca12a631758bc1b43c149c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "magpie/src/utils.f90", "max_issues_repo_name": "knaidoo29/magpie", "max_issues_repo_head_hexsha": "efab3c2666aab2c928ca12a631758bc1b43c149c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "magpie/src/utils.f90", "max_forks_repo_name": "knaidoo29/magpie", "max_forks_repo_head_hexsha": "efab3c2666aab2c928ca12a631758bc1b43c149c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.5070422535, "max_line_length": 59, "alphanum_fraction": 0.5563139932, "num_tokens": 400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.888758786126321, "lm_q1q2_score": 0.7939365783112425}} {"text": "C ****************************************************************************\nC FILE: mpi_pi_send.f\nC DESCRIPTION: \nC MPI pi Calculation Example - Fortran Version \nC Point-to-Point Communication example\nC This program calculates pi using a \"dartboard\" algorithm. See\nC Fox et al.(1988) Solving Problems on Concurrent Processors, vol.1\nC page 207. All processes contribute to the calculation, with the\nC master averaging the values for pi. SPMD Version: Conditional \nC statements check if the process is the master or a worker.\nC This version uses low level sends and receives to collect results \nC Note: Requires Fortran90 compiler due to random_number() function\nC AUTHOR: Blaise Barney. Adapted from Ros Leibensperger, Cornell Theory\nC Center. Converted to MPI: George L. Gusciora, MHPCC (1/95) \nC LAST REVISED: 06/13/13 Blaise Barney\nC ****************************************************************************\nC Explanation of constants and variables used in this program:\nC DARTS = number of throws at dartboard \nC ROUNDS = number of times \"DARTS\" is iterated \nC MASTER = task ID of master task\nC taskid = task ID of current task \nC numtasks = number of tasks\nC homepi = value of pi calculated by current task\nC pi = average of pi for this iteration\nC avepi = average pi value for all iterations \nC pirecv = pi received from worker \nC pisum = sum of workers' pi values \nC seednum = seed number - based on taskid\nC source = source of incoming message\nC mtype = message type \nC i, n = misc\n\n program pi_send \n include 'mpif.h'\n\n integer DARTS, ROUNDS, MASTER\n parameter(DARTS = 100000) \n parameter(ROUNDS = 1000)\n parameter(MASTER = 0)\n\n integer \ttaskid, numtasks, source, mtype, i, n,\n & status(MPI_STATUS_SIZE)\n real*4\tseednum\n real*8 \thomepi, pi, avepi, pirecv, pisum, dboard\n\nC Obtain number of tasks and task ID\n call MPI_INIT( ierr )\n call MPI_COMM_RANK( MPI_COMM_WORLD, taskid, ierr )\n call MPI_COMM_SIZE( MPI_COMM_WORLD, numtasks, ierr )\n write(*,*)'task ID = ', taskid\n\n avepi = 0\n\n do 40 i = 1, ROUNDS\nC Calculate pi using dartboard algorithm \n homepi = dboard(DARTS)\n\nC ******************** start of worker section ***************************\nC All workers send result to master. Steps include: \nC -set message type equal to this round number\nC -set message size to 8 bytes (size of real8)\nC -send local value of pi (homepi) to master task\n if (taskid .ne. MASTER) then\n mtype = i \n sbytes = 8\t\n call MPI_SEND( homepi, 1, MPI_DOUBLE_PRECISION, MASTER, i, \n & MPI_COMM_WORLD, ierr )\n\nC ******************** end of worker section *****************************\n else\nC ******************** start of master section **************************\nC Master receives messages from all workers. Steps include:\nC -set message type equal to this round \nC -set message size to 8 bytes (size of real8)\nC -receive any message of type mytpe\nC -keep running total of pi in pisum\nC Master then calculates the average value of pi for this iteration \nC Master also calculates and prints the average value of pi over all \nC iterations \n mtype = i\t\n sbytes = 8\n pisum = 0\n do 30 n = 1, numtasks-1\n call MPI_RECV( pirecv, 1, MPI_DOUBLE_PRECISION,\n & MPI_ANY_SOURCE, mtype, MPI_COMM_WORLD, status, ierr )\n pisum = pisum + pirecv\n 30 continue\n pi = (pisum + homepi)/numtasks\n avepi = ((avepi*(i-1)) + pi) / i\n! write(*,32) DARTS*i, avepi\n! 32 format(' After ',i9,' throws, average value of pi = ',f10.8) \nC ********************* end of master section ****************************\n endif\n 40 continue\n\n if (taskid .eq. MASTER) then\n print *, ' '\n print *,'Real value of PI: 3.1415926535897'\n print *, ' '\n endif\n\n call MPI_FINALIZE(ierr)\n\n end\n\n\nC *****************************************************************************\nC function dboard.f\nC DESCRIPTION:\nC Used in pi calculation example codes.\nC See mpi_pi_send.f and mpi_pi_reduce.f\nC Throw darts at board. Done by generating random numbers\nC between 0 and 1 and converting them to values for x and y\nC coordinates and then testing to see if they \"land\" in\nC the circle.\" If so, score is incremented. After throwing the\nC specified number of darts, pi is calculated. The computed value\nC of pi is returned as the value of this function, dboard.\nC Note: Requires Fortran90 compiler due to random_number() function\nC \nC Explanation of constants and variables used in this function:\nC darts \t= number of throws at dartboard\nC score\t= number of darts that hit circle\nC n\t\t= index variable\nC r \t\t= random number between 0 and 1 \nC x_coord\t= x coordinate, between -1 and 1 \nC x_sqr\t= square of x coordinate\nC y_coord\t= y coordinate, between -1 and 1 \nC y_sqr\t= square of y coordinate\nC pi\t\t= computed value of pi\nC **************************************************************************/\n\n real*8 function dboard(darts)\n integer darts, score, n\n real*4\tr\n real*8\tx_coord, x_sqr, y_coord, y_sqr, pi\n\n score = 0\n\nC \"throw darts at the board\"\n do 10 n = 1, darts\nC generate random numbers for x and y coordinates\n call random_number(r)\n x_coord = (2.0 * r) - 1.0\n\tx_sqr = x_coord * x_coord\n\n call random_number(r)\n y_coord = (2.0 * r) - 1.0\n\ty_sqr = y_coord * y_coord\n\nC if dart lands in circle, increment score\n\tif ((x_sqr + y_sqr) .le. 1.0) then\n\t score = score + 1\n endif\n\n 10 continue\n\nC calculate pi\n pi = 4.0 * score / darts\n dboard = pi\n end\n", "meta": {"hexsha": "dc08a67b82f5fbe0dbebbffe5df1486c8e04bca7", "size": 5980, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "calc_pi/calc_pi_p2p/mpi_pi_send.f", "max_stars_repo_name": "cdances/Parallel_Programming", "max_stars_repo_head_hexsha": "77b70ce1daf09c0fb0fffd1648911c3871314c92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-02-26T12:41:09.000Z", "max_stars_repo_stars_event_max_datetime": "2018-02-26T12:41:09.000Z", "max_issues_repo_path": "calc_pi/calc_pi_p2p/mpi_pi_send.f", "max_issues_repo_name": "cdances/Parallel_Programming", "max_issues_repo_head_hexsha": "77b70ce1daf09c0fb0fffd1648911c3871314c92", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc_pi/calc_pi_p2p/mpi_pi_send.f", "max_forks_repo_name": "cdances/Parallel_Programming", "max_forks_repo_head_hexsha": "77b70ce1daf09c0fb0fffd1648911c3871314c92", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.1428571429, "max_line_length": 79, "alphanum_fraction": 0.5891304348, "num_tokens": 1590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.8723473663814338, "lm_q1q2_score": 0.7937549803693068}} {"text": "!*********************************************************\n!>\n! A number of constants used in math and physics\n!\n\nmodule nfConstants\n implicit none\n\n integer, parameter :: sp = selected_real_kind(6, 37)\n integer, parameter :: dp = selected_real_kind(15, 307)\n integer, parameter :: qp = selected_real_kind(33, 4931)\n\n ! Math constants\n\n ! Pi\n real(dp), parameter :: pi_ = 2.d0*acos(0.d0)\n\n ! Eulers number\n real(dp), parameter :: e_ = exp(1.d0)\n\n ! Euler-Mascheroni constant\n real(dp), parameter :: em_ = 0.57721566490153286d0\n\n ! Complex i\n complex(dp), parameter :: i_ = (0,1)\n\n ! Physics constants\n\n ! Speed of light in m/s\n real(dp), parameter :: c_ = 2.99792458d8\n ! Speed of light in cm/s (cgs units)\n real(dp), parameter :: c_cgs_ = 2.99792458d10\n\n ! Planck constant in J*s\n real(dp), parameter :: h_ = 6.626070040d-34\n ! Reduced Planck constant, h/2*pi, in J*s\n real(dp), parameter :: hbar_ = 1.054571800d-34\n ! Planck constant in eV*s\n real(dp), parameter :: h_eV_ = 4.135667662d-15\n ! Reduced Planck constant, \\(h/2\\pi\\), in \\(eV\\) \\(s\\)\n real(dp), parameter :: hbar_eV_ = 6.582119514d-16\n ! Planck constant in \\(erg\\) \\(s\\) (cgs units)\n real(dp), parameter :: h_cgs_ = 6.626070040d-27\n ! Reduced Planck constant, \\(h/2\\pi\\), in \\(erg\\) \\(s\\) (cgs units)\n real(dp), parameter :: hbar_cgs_ = 1.054571800d-27\n ! Reduced Planck constant, \\(hc/2\\pi\\), in \\(MeV\\) \\(fm\\)\n real(dp), parameter :: hbarc_ = 197.3269788d0\n\n ! Gravitational constant in m^3 kg^-1 s^-2\n real(dp), parameter :: G_ = 6.6743d-11\n ! Gravitational constant in cm^3 g^-1 s^-2 (dyne cm^2 g^-2) (cgs units)\n real(dp), parameter :: G_cgs_ = 6.6743d-8\n\n ! Mass of electron in g (cgs units)\n real(dp), parameter :: me_ = 9.10938356d-28\n ! Mass of muon in g (cgs units)\n real(dp), parameter :: mmu_ = 1.883531594d-25\n ! Mass of tau in g (cgs units)\n real(dp), parameter :: mtau_ = 3.16747d-24\n ! Mass of proton in g (cgs units)\n real(dp), parameter :: mp_ = 1.672621898d-24\n ! Mass of neutron in g (cgs units)\n real(dp), parameter :: mn_ = 1.674927471d-24\n ! Mass of alpha particle in g (cgs units)\n real(dp), parameter :: malpha_ = 6.644657230d-24\n ! Atomic mass unit in g (cgs units)\n real(dp), parameter :: amu_ = 1.660539d-24\n\n ! Bohr radius in cm (cgs units)\n real(dp), parameter :: bohrr_ = 5.2917721067d-9\n ! Fine-structure constant\n real(dp), parameter :: alpha_ = 7.2973525664d-3\n ! Hartree energy in J\n real(dp), parameter :: eHartree_ = 4.359744650d-18\n ! Hartree energy in eV\n real(dp), parameter :: eHartree_eV_ = 27.21138602d0\n\n ! Avagadro's number\n real(dp), parameter :: na_ = 6.0221367d23\n ! Boltzmann constant in J K^-1\n real(dp), parameter :: k_ = 1.38064852d-23\n ! Faraday constant in C mol^-1\n real(dp), parameter :: F_ = 96485.33289d0\n ! Rydberg constant in m^-1\n real(dp), parameter :: ryd_ = 10973731.568508d0\n ! Stefan-Boltzmann constant in W m^-2 K^-4\n real(dp), parameter :: stefboltz_ = 5.670367d-8\n ! Wien displacement law constant in m K\n real(dp), parameter :: wiend_ = 2.8977729d-3\n\n ! Electric charge in C\n real(dp), parameter :: ec_ = 1.6021766208d-19\n ! Electric charge in cm^{3/2} g^{1/2} s^-1 (cgs units)\n real(dp), parameter :: ec_cgs_ = 4.8032d-10\n ! Electron volt in J\n real(dp), parameter :: ev_ = 1.6021766208d-19\n ! Electron volt in erg (cgs units)\n real(dp), parameter :: ev_cgs_ = 1.60217733d-12\n\n ! Electric constant (vacuum permittivity) in F m^-1\n real(dp), parameter :: epsilon0_ = 8.854187817d-12\n ! Magnetic constant (vacuum permeability) in N A^-2\n real(dp), parameter :: mu0_ = 1.2566370614d-6\n\n ! Solar mass in g\n real(dp), parameter :: msolar_ = 1.988435d33\n ! Solar radius in cm\n real(dp), parameter :: rsolar_ = 6.955d10\n ! Solar luminosity in erg s^-1\n real(dp), parameter :: lumsolar_ = 3.839d33\n ! Astronomical Unit in cm\n real(dp), parameter :: au_ = 1.49597870700d13\n\nend module nfConstants", "meta": {"hexsha": "1f7f2e2d5cdc26aa7d0842b7cfbf10a550536af5", "size": 3912, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/nfConstants.f90", "max_stars_repo_name": "joshhooker/numFortran", "max_stars_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/nfConstants.f90", "max_issues_repo_name": "joshhooker/numFortran", "max_issues_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/nfConstants.f90", "max_forks_repo_name": "joshhooker/numFortran", "max_forks_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.3157894737, "max_line_length": 73, "alphanum_fraction": 0.6513292434, "num_tokens": 1440, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542184, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7936849436575264}} {"text": "program ChiTest\n use GSLMiniBind\n use iso_c_binding\n implicit none\n\n real, dimension(5) :: dset1 = (/ 199809., 200665., 199607., 200270., 199649. /)\n real, dimension(5) :: dset2 = (/ 522573., 244456., 139979., 71531., 21461. /)\n\n real :: dist, prob\n integer :: dof\n\n print *, \"Dataset 1:\"\n print *, dset1\n dist = chi2UniformDistance(dset1)\n dof = size(dset1) - 1\n write(*, '(A,I4,A,F12.4)') 'dof: ', dof, ' distance: ', dist\n prob = chi2Probability(dof, dist)\n write(*, '(A,F9.6)') 'probability: ', prob\n write(*, '(A,L)') 'uniform? ', chiIsUniform(dset1, 0.05)\n\n ! Lazy copy/past :|\n print *, \"Dataset 2:\"\n print *, dset2\n dist = chi2UniformDistance(dset2)\n dof = size(dset2) - 1\n write(*, '(A,I4,A,F12.4)') 'dof: ', dof, ' distance: ', dist\n prob = chi2Probability(dof, dist)\n write(*, '(A,F9.6)') 'probability: ', prob\n write(*, '(A,L)') 'uniform? ', chiIsUniform(dset2, 0.05)\n\ncontains\n\nfunction chi2Probability(dof, distance)\n real :: chi2Probability\n integer, intent(in) :: dof\n real, intent(in) :: distance\n\n ! in order to make this work, we need linking with GSL library\n chi2Probability = gsl_sf_gamma_inc(real(0.5*dof, c_double), real(0.5*distance, c_double))\nend function chi2Probability\n\nfunction chiIsUniform(dset, significance)\n logical :: chiIsUniform\n real, dimension(:), intent(in) :: dset\n real, intent(in) :: significance\n\n integer :: dof\n real :: dist\n\n dof = size(dset) - 1\n dist = chi2UniformDistance(dset)\n chiIsUniform = chi2Probability(dof, dist) > significance\nend function chiIsUniform\n\nfunction chi2UniformDistance(ds)\n real :: chi2UniformDistance\n real, dimension(:), intent(in) :: ds\n\n real :: expected, summa = 0.0\n\n expected = sum(ds) / size(ds)\n summa = sum( (ds - expected) ** 2 )\n\n chi2UniformDistance = summa / expected\nend function chi2UniformDistance\n\nend program ChiTest\n", "meta": {"hexsha": "11f9fa42b131dc8d56095055d290c12ae5dbe2ed", "size": 1859, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Verify-distribution-uniformity-Chi-squared-test/Fortran/verify-distribution-uniformity-chi-squared-test-2.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Verify-distribution-uniformity-Chi-squared-test/Fortran/verify-distribution-uniformity-chi-squared-test-2.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Verify-distribution-uniformity-Chi-squared-test/Fortran/verify-distribution-uniformity-chi-squared-test-2.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 27.3382352941, "max_line_length": 91, "alphanum_fraction": 0.660570199, "num_tokens": 622, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7936610224452258}} {"text": "! Math Algorithms\n!\n! Purpose: Program that calculates the roots of polynomial equations up to the second degree\n! Language: Fortran 95\n! Author: José Cintra\n! Year: 2020\n! Web Site: https://github.com/JoseCintra/MathAlgorithms\n! License: Unlicense, described in http://unlicense.org\n! Online demo: https://onlinegdb.com/S1SvELfLd\n\nPROGRAM Equation\n\n ! Variables\n IMPLICIT NONE\n REAL :: a,b,c ! Coefficients of the equation\n REAL :: x1,x2 ! Roots of the equation\n REAL :: delta ! For Bhaskara formula\n\n ! Data entry\n ! Change these Coefficients to test other input values\n a = 3\n b = 4\n c = 0\n\n ! Calculations\n PRINT *,\"\"\n WRITE (*,'(a)') \"The roots of that equation are:\"\n IF (a == 0 .AND. b == 0) THEN\n WRITE (*,'(a)') \"Invalid coefficients.\"\n ELSE IF (a == 0) THEN ! First degree equation\n x1 = -c/b\n PRINT *, x1\n ELSE ! Second degree equation\n delta = b*b -4*a*c\n IF (delta < 0) THEN\n WRITE (*,'(a)') \"This equation has no real roots.\"\n ELSE\n x1 = (-b + sqrt(delta)) / (2*a)\n x2 = (-b - sqrt(delta)) / (2*a)\n PRINT *, x1\n PRINT *, x2\n END IF\n END IF\n\n ! END\n PRINT *,\"\"\n WRITE (*, '(a)') \"END of execution\"\n\nEND PROGRAM Equation\n\n\n", "meta": {"hexsha": "fbfa2c4cdcf5b217d93ed1dd5083e738655c7599", "size": 1287, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Algorithms/PolyEquationUpTo2.f95", "max_stars_repo_name": "JoseCintra/MathAlgorithms", "max_stars_repo_head_hexsha": "afa6b22f72890604083b54af8f741d51b26510b8", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-10-28T12:04:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-13T23:16:35.000Z", "max_issues_repo_path": "Algorithms/PolyEquationUpTo2.f95", "max_issues_repo_name": "JoseCintra/MathAlgorithms", "max_issues_repo_head_hexsha": "afa6b22f72890604083b54af8f741d51b26510b8", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/PolyEquationUpTo2.f95", "max_forks_repo_name": "JoseCintra/MathAlgorithms", "max_forks_repo_head_hexsha": "afa6b22f72890604083b54af8f741d51b26510b8", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-29T09:20:17.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-29T09:20:17.000Z", "avg_line_length": 24.75, "max_line_length": 98, "alphanum_fraction": 0.5780885781, "num_tokens": 396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.8840392863287584, "lm_q1q2_score": 0.7935979005360354}} {"text": "Module Fortranpi\nUSE MPI\nIMPLICIT NONE\ncontains\nsubroutine dboard(darts, dartsscore)\n integer, intent(in) :: darts\n double precision, intent(out) :: dartsscore\n double precision :: x_coord, y_coord\n integer :: score, n\n\nscore = 0\ndo n = 1, darts\n call random_number(x_coord)\n call random_number(y_coord)\n\n if ((x_coord**2 + y_coord**2) <= 1.0d0) then\n score = score + 1\n end if\nend do\n\ndartsscore = 4.0d0*score/darts\n\nend subroutine dboard\n\nsubroutine pi(avepi, DARTS, ROUNDS) bind(C, name=\"pi_\")\n use, intrinsic :: iso_c_binding, only : c_double, c_int\n real(c_double), intent(out) :: avepi\n integer(c_int), intent(in) :: DARTS, ROUNDS\n integer :: MASTER, rank, i, n\n integer, allocatable :: seed(:)\n double precision :: pi_est, homepi, pirecv, pisum\n\n! we set it to zero in the sequential run\nrank = 0\n! initialize the random number generator\n! we make sure the seed is different for each task\ncall random_seed()\ncall random_seed(size = n)\nallocate(seed(n))\nseed = 12 + rank*11\ncall random_seed(put=seed(1:n))\ndeallocate(seed)\n\navepi = 0\ndo i = 0, ROUNDS-1\n call dboard(darts, pi_est)\n ! calculate the average value of pi over all iterations\n avepi = ((avepi*i) + pi_est)/(i + 1)\nend do\nend subroutine pi\n\n\nsubroutine snowpi(avepi, DARTS, ROUNDS, proc_num, numprocs) bind(C, name=\"snowpi_\")\nuse, intrinsic :: iso_c_binding, only : c_double, c_int\nreal(c_double), intent(out) :: avepi\ninteger(c_int), intent(in) :: DARTS, ROUNDS, proc_num, numprocs\ninteger :: i, n, mynpts\ninteger, allocatable :: seed(:)\ndouble precision :: pi_est\n\n if (proc_num .eq. 1) then\n\t mynpts = ROUNDS - (numprocs-1)*(ROUNDS/numprocs)\n else\n mynpts = ROUNDS/numprocs\n endif\n\n ! initialize the random number generator\n ! we make sure the seed is different for each task\n call random_seed()\n call random_seed(size = n)\n allocate(seed(n))\n seed = 12 + proc_num*11\n call random_seed(put=seed(1:n))\n deallocate(seed)\n\n avepi=0.0d0\n do i = 0, mynpts-1\n call dboard(darts, pi_est)\n ! calculate the average value of pi over all iterations\n avepi = ((avepi*i) + pi_est)/(i + 1)\n end do\n\n\nend subroutine snowpi\n\nend module Fortranpi\n", "meta": {"hexsha": "0894f9568561445ff94649f2380ef5be07d771d8", "size": 2479, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Fpi.f90", "max_stars_repo_name": "ignacio82/MyPi", "max_stars_repo_head_hexsha": "e6426ed776e1c7bb2fb842bcd8f5026067183093", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Fpi.f90", "max_issues_repo_name": "ignacio82/MyPi", "max_issues_repo_head_hexsha": "e6426ed776e1c7bb2fb842bcd8f5026067183093", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Fpi.f90", "max_forks_repo_name": "ignacio82/MyPi", "max_forks_repo_head_hexsha": "e6426ed776e1c7bb2fb842bcd8f5026067183093", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-08-29T11:46:02.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-29T11:46:02.000Z", "avg_line_length": 28.4942528736, "max_line_length": 83, "alphanum_fraction": 0.6083098023, "num_tokens": 711, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7935620947499731}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! BKMATH Module\n! Author: Brian Krauth, Simon Fraser University\n!\n! Mathematical procedures related to SMLE program. All real-valued functions \n! work in either single or double precision; results will be of same type as\n! inputs.\n!\n! Public procedures available (by category) are:\n! \n! Probability and statistics:\n!\n!\tPDFN(x):\tStandard normal PDF of x. For PDFN, CDFN,\n!\t\t\tand CDFINVN, x can be scalar, vector, or\n!\t\t\t2-dimensional matrix. Result will be in \n!\t\t\tsame type as x. \n!\tCDFN(x):\tStandard normal CDF of x\n! \tCDFINVN(x):\tInverse standard normal CDF of x\n!\tCHOL(x):\tCholesky decomposition of x, assuming\n!\t\t\tx is symmetric and positive definite.\n!\tOLS(x,y):\tOLS coefficients for a regression of y on x.\n!\tRANDINT(n):\tVector of n random integers between 1 and n.\n!\t\n!\n! Combinatorics:\n!\n!\tFACTORIAL(x):\tFactorial of x (i.e., x!)\n!\tNCHOOSEK(n,k):\t(n!)/(k!(n-k)!)\n!\n! Halton sequences (Halton sequences give an improvement over random numbers for simulation-based\n!\testimation. See Kenneth Train's book for more information):\n!\n!\tFIND_PRIMES(n):\t\tGives the first n prime numbers. DOES IT INCLUDE 2?\n!\tHMAT(r,c):\t\tGives an r-by-c matrix of Halton sequences\n!\tHALTON_SEQUENCE(n,s):\tGives a Halton sequence.\n!\tRHALT(r,c):\t\tGives an r-by-c matrix of randomized Halton sequences\n!\t\t\t\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nmodule bkmath \nuse bklib, only : SP, DP, runif\nimplicit none\nprivate\nprivate :: pdfns0,pdfnd0,pdfns1,pdfns2,pdfnd1,pdfnd2, &\n cdfn0,cdfn1,cdfn2,cdfn0d,cdfn1d,cdfn2d, &\n cdfinvn0,cdfinvn1,cdfinvn2,cdfinvn0d,cdfinvn1d,cdfinvn2d, &\n chols,chold,olss,olsd,factorial0,factorial1,nchoosek0,nchoosek1, &\n swap,outerprod,outerand,inversed\npublic :: pdfn,cdfn,cdfinvn,chol,ols,randint,factorial,nchoosek,find_primes, &\n hmat,halton_sequence,rhalt,inverse\ninterface pdfn\n module procedure pdfns0,pdfnd0,pdfns1,pdfns2,pdfnd1,pdfnd2\nend interface\ninterface cdfn\n module procedure cdfn0,cdfn1,cdfn2,cdfn0d,cdfn1d,cdfn2d\nend interface\ninterface cdfinvn\n module procedure cdfinvn0,cdfinvn1,cdfinvn2,cdfinvn0d,cdfinvn1d,cdfinvn2d\nend interface\ninterface chol\n module procedure chols,chold\nend interface\ninterface ols\n module procedure olss,olsd\nend interface\ninterface factorial\n module procedure factorial0,factorial1\nend interface\ninterface nchoosek\n module procedure nchoosek0,nchoosek1\nend interface\ninterface inverse\n module procedure inversed\nend interface\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\ncontains\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nsubroutine inversed(a)\n real(kind=DP), dimension(:,:), intent(inout) :: a\n integer, dimension(size(a,1)) :: ipiv,indxr,indxc\n logical, dimension(size(a,1)) :: lpiv\n real(kind=DP) :: pivinv\n real(kind=DP), dimension(size(a,1)) :: dumc\n integer, target, dimension(2) :: irc\n integer :: i,l,n\n integer, pointer :: irow,icol\n n=size(a,1)\n irow => irc(1)\n icol => irc(2)\n ipiv=0\n do i=1,n\n lpiv = (ipiv==0)\n irc = maxloc(abs(a),outerand(lpiv,lpiv))\n ipiv(icol)=ipiv(icol)+1\n if (ipiv(icol) > 1) stop \"Singular matrix\"\n if (irow /= icol) then\n call swap(a(irow,:),a(icol,:))\n end if\n indxr(i) = irow\n indxc(i) = icol\n if (a(icol,icol)==0.0_dp) stop \"Singular matrix\"\n pivinv=1.0_dp/a(icol,icol)\n a(icol,icol)=1.0_dp\n a(icol,:)=a(icol,:)*pivinv\n dumc=a(:,icol)\n a(:,icol)=0.0_dp\n a(icol,icol)=pivinv\n a(1:(icol-1),:)=a(1:(icol-1),:)-outerprod(dumc(1:(icol-1)),a(icol,:))\n a(icol+1:,:)=a(icol+1:,:)-outerprod(dumc(icol+1:),a(icol,:))\n end do\n do l=n,1,-1\n call swap(a(:,indxr(l)),a(:,indxc(l)))\n end do\nend subroutine inversed\n\n\nsubroutine swap(a,b)\n real(kind=DP), dimension(:), intent(inout) :: a,b\n real(kind=DP), dimension(size(a)) :: dum\n dum=a\n a=b\n b=dum\nend subroutine swap\n \nfunction outerprod(a,b) result (outer)\n real(kind=DP), dimension(:), intent(in) :: a,b\n real(kind=DP), dimension(size(a),size(b)) :: outer\n outer = spread(a,dim=2,ncopies=size(b))*spread(b,dim=1,ncopies=size(a))\nend function outerprod\n\nfunction outerand(a,b) result (outer)\n logical, dimension(:), intent(in) :: a,b\n logical, dimension(size(a),size(b)) :: outer\n outer = spread(a,dim=2,ncopies=size(b)) .and. spread(b,dim=1,ncopies=size(a))\nend function outerand\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! PDFN function\n!\n! Format: pdfn(x)\n!\n! Gives standard normal PDF of x.\n! \n! X can be either single or double precision, and can be a scalar,\n! vector, or 2-dimensional array. The output\n! vector will be the same type as X.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\npure function pdfns0(a) result (pdfn)\n real(kind=SP), intent(in) :: a\n real(kind=SP) :: pdfn\n real(kind=SP), parameter :: pi=3.14159265 ! 3589793238462643\n pdfn = exp((-a**2)/2.0)/((2.0*pi)**0.5)\nend function pdfns0\npure function pdfnd0(a) result (pdfn)\n real(kind=DP), intent(in) :: a\n real(kind=DP) :: pdfn\n real(kind=DP), parameter :: pi=3.14159265358979323_dp ! 8462643d0\n pdfn = exp((-a**2)/2.0_dp)/((2.0_dp*pi)**0.5_dp)\nend function pdfnd0\npure function pdfns1(a) result (pdfn)\n real(kind=SP), dimension(:), intent(in) :: a\n real(kind=SP), dimension(size(a)) :: pdfn\n real(kind=SP), parameter :: pi=3.14159265 ! 3589793238462643\n pdfn = exp((-a**2)/2.0)/((2.0*pi)**0.5)\nend function pdfns1\npure function pdfnd1(a) result (pdfn)\n real(kind=DP), dimension(:), intent(in) :: a\n real(kind=DP), dimension(size(a)) :: pdfn\n real(kind=DP), parameter :: pi=3.14159265358979323_dp ! 8462643d0\n pdfn = exp((-a**2)/2.0_dp)/((2.0_dp*pi)**0.5_dp)\nend function pdfnd1\npure function pdfns2(a) result (pdfn)\n real(kind=SP), dimension(:,:), intent(in) :: a\n real(kind=SP), dimension(size(a,1),size(a,2)) :: pdfn\n real(kind=SP), parameter :: pi=3.14159265 ! 3589793238462643\n pdfn = exp((-a**2)/2.0)/((2.0*pi)**0.5)\nend function pdfns2\npure function pdfnd2(a) result (pdfn)\n real(kind=DP), dimension(:,:), intent(in) :: a\n real(kind=DP), dimension(size(a,1),size(a,2)) :: pdfn\n real(kind=DP), parameter :: pi=3.14159265358979323_dp ! 8462643d0\n pdfn = exp((-a**2)/2.0_dp)/((2.0_dp*pi)**0.5_dp)\nend function pdfnd2\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! CDFN function\n!\n! Format: cdfn(x)\n!\n! Gives standard normal CDF of x.\n! \n! X can be either single or double precision, and can be a scalar,\n! vector, or 2-dimensional array. The output\n! vector will be the same type as X.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nfunction cdfn0(x) result(cdfn)\n real, intent(in) :: x\n real :: cdfn\n cdfn = real(cdfn0d(real(x,kind=DP)),kind=SP)\nend function cdfn0\nfunction cdfn1(x) result(cdfn)\n real, dimension(:), intent(in) :: x\n real, dimension(size(x)) :: cdfn\n cdfn=real(cdfn1d(real(x,kind=DP)),kind=SP)\nend function cdfn1\nfunction cdfn2(x) result(cdfn)\n real, dimension(:,:), intent(in) :: x\n real, dimension(Size(x,1),Size(x,2)) :: cdfn\n real, dimension(Size(x,1)*Size(x,2)) :: tmpx\n tmpx = reshape(x,(/ size(x,1)*size(x,2) /))\n tmpx = cdfn1(tmpx)\n cdfn = reshape(tmpx,(/ size(x,1), size(x,2) /))\nend function cdfn2\npure function cdfn0d(x) result(cdfn)\n real(kind=DP), intent(in) :: x\n real(kind=DP) :: cdfn\n real(kind=DP), parameter :: a1 = 0.398942280444_dp, a2 = 0.399903438504_dp, &\n a3 = 5.75885480458_dp, a4 = 29.8213557808_dp, a5 = 2.62433121679_dp, &\n a6 = 48.6959930692_dp, a7 = 5.92885724438_dp, b0 = 0.398942280385_dp, &\n b1 = 3.8052e-08_dp, b2 = 1.00000615302_dp, b3 = 3.98064794e-04_dp, &\n b4 = 1.98615381364_dp, b5 = 0.151679116635_dp, b6 = 5.29330324926_dp, &\n b7 = 4.8385912808_dp, b8 = 15.1508972451_dp, b9 = 0.742380924027_dp, &\n b10 = 30.789933034_dp, b11 = 3.99019417011_dp\n real(kind=DP) :: y\n logical :: smallx\n y = 0.5_dp * x**2\n cdfn=0.0_dp\n smallx = (abs(x) < 1.28_dp)\n if (smallx) cdfn = 0.5_dp - abs(x) * ( a1 - a2 * y / ( y + a3 - a4 / ( y + a5 &\n + a6 / ( y + a7 ) ) ) )\n if ((.not.smallx).and.(abs(x) < 12.7_dp)) cdfn = exp ( - y ) * b0 / ( abs(x) - b1 &\n + b2 / ( abs(x) + b3 &\n + b4 / ( abs(x) - b5 &\n + b6 / ( abs(x) + b7 &\n - b8 / ( abs(x) + b9 &\n + b10 / ( abs(x) + b11 ) ) ) ) ) )\n if ( x > 0.0_dp ) cdfn = 1.0_dp-cdfn\nend function cdfn0d\n!function cdfn0d(x)\n! real(kind=DP), intent(in) :: x\n! real(kind=DP) :: cdfn0d\n! real(kind=DP) :: xtmp(1)\n! xtmp(1)=x\n! xtmp=cdfn1d(xtmp)\n! cdfn0d=xtmp(1)\n!end function cdfn0d\npure function cdfn1d(x) result(cdfn)\n real(kind=DP), dimension(:), intent(in) :: x\n real(kind=DP), dimension(size(x)) :: cdfn\n real(kind=DP), parameter :: a1 = 0.398942280444_dp, a2 = 0.399903438504_dp, &\n a3 = 5.75885480458_dp, a4 = 29.8213557808_dp, a5 = 2.62433121679_dp, &\n a6 = 48.6959930692_dp, a7 = 5.92885724438_dp, b0 = 0.398942280385_dp, &\n b1 = 3.8052e-08_dp, b2 = 1.00000615302_dp, b3 = 3.98064794e-04_dp, &\n b4 = 1.98615381364_dp, b5 = 0.151679116635_dp, b6 = 5.29330324926_dp, &\n b7 = 4.8385912808_dp, b8 = 15.1508972451_dp, b9 = 0.742380924027_dp, &\n b10 = 30.789933034_dp, b11 = 3.99019417011_dp\n real(kind=DP), dimension(size(x)) :: y\n logical, dimension(size(x)) :: smallx\n y = 0.5_dp * x**2\n cdfn=0.0_dp\n smallx = (abs(x) < 1.28_dp)\n where (smallx) cdfn = 0.5_dp - abs(x) * ( a1 - a2 * y / ( y + a3 - a4 / ( y + a5 &\n + a6 / ( y + a7 ) ) ) )\n where ((.not.smallx).and.(abs(x) < 12.7_dp)) cdfn = exp ( - y ) * b0 / ( abs(x) - b1 &\n + b2 / ( abs(x) + b3 &\n + b4 / ( abs(x) - b5 &\n + b6 / ( abs(x) + b7 &\n - b8 / ( abs(x) + b9 &\n + b10 / ( abs(x) + b11 ) ) ) ) ) )\n where ( x > 0.0_dp ) cdfn = 1.0_dp-cdfn\nend function cdfn1d\nfunction cdfn2d(x) result(cdfn)\n real(kind=DP), dimension(:,:), intent(in) :: x\n real(kind=DP), dimension(Size(x,1),Size(x,2)) :: cdfn\n real(kind=DP), dimension(Size(x,1)*Size(x,2)) :: tmpx\n tmpx = reshape(x,(/ size(x,1)*size(x,2) /))\n tmpx = cdfn1d(tmpx)\n cdfn = reshape(tmpx,(/ size(x,1), size(x,2) /))\nend function cdfn2d\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! CDFINVN function\n!\n! Format: cdfinvn(x)\n!\n! Gives inverse of standard normal CDF of x.\n! \n! X can be either single or double precision, and can be a scalar,\n! vector, or 2-dimensional array. The output\n! vector will be the same type as X. In order for the inverse \n! CDF to exist, X must be strictly between zero and one. This\n! function does not check!\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nfunction cdfinvn0(p) result(cdfinvn)\n real, intent(in) :: p\n real :: cdfinvn\n real, dimension(1) :: tmp\n tmp(1) = p\n tmp = cdfinvn1(tmp)\n cdfinvn=tmp(1)\nend function cdfinvn0\nfunction cdfinvn1(p) result(cdfinvn)\n real, dimension(:), intent(in) :: p\n real, dimension(Size(p)) :: cdfinvn\n logical, dimension(Size(p)) :: maskgt\n real, dimension(Size(p)) :: y,xp\n real, parameter :: lim=1.0e20, p0=-0.32223243, p1=-1.0, &\n p2=-0.34224208, p3=-0.02042312, &\n p4=-0.45364221e-4, q0=0.09934846, &\n q1=0.58858157, q2=0.53110346, &\n q3=0.10353775, q4=0.38560700e-2\n maskgt = (p > 0.5)\n xp = p\n where (maskgt) xp = 1-xp\n y = sqrt(-2.0*log(xp))\n xp = y + ((((p4*y + p3) * y + p2)* y + p1)*y + p0)/ &\n ((((q4*y + q3) * y + q2) * y + q1) * y + q0)\n where (maskgt) xp = -xp\n where (p == 0.5) xp = 0.0\n cdfinvn = -xp\nend function cdfinvn1\nfunction cdfinvn2(p) result(cdfinvn)\n real, dimension(:,:), intent(in) :: p\n real, dimension(Size(p,1),Size(p,2)) :: cdfinvn\n real, dimension(Size(p,1)*Size(p,2)) :: tmp\n tmp = reshape(p,(/ size(p,1)*size(p,2) /))\n tmp = cdfinvn1(tmp)\n cdfinvn = reshape(tmp,(/ size(p,1), size(p,2) /))\nend function cdfinvn2\npure function cdfinvn0d(p) result(cdfinvn)\n real(kind=DP), intent(in) :: p\n real(kind=DP) :: cdfinvn\n logical :: maskgt\n real(kind=DP) :: y\n real(kind=DP), parameter :: p0=-0.322232431088_dp, p1=-1.0_dp, & \n p2=-0.342242088547_dp, p3=-0.0204231210245_dp, &\n p4=-0.453642210148e-4_dp, q0=0.0993484626060_dp, &\n q1=0.588581570495_dp, q2=0.531103462366_dp, &\n q3=0.103537752850_dp, q4=0.38560700634e-2_dp, &\n minp=1.0e-300_dp\n maskgt = (p > 0.5_dp)\n cdfinvn = p\n if (maskgt) cdfinvn = 1.0_dp-cdfinvn\n if (cdfinvn < minp) then\n cdfinvn = minp\n end if\n y = sqrt(-2.0_dp*log(cdfinvn))\n cdfinvn = y + ((((p4*y + p3) * y + p2)* y + p1)*y + p0)/ &\n ((((q4*y + q3) * y + q2) * y + q1) * y + q0)\n if (.not.maskgt) cdfinvn=-cdfinvn\n if (p == 0.5_dp) cdfinvn = 0.0_dp\nend function cdfinvn0d\npure function cdfinvn1d(p) result(cdfinvn)\n real(kind=DP), dimension(:), intent(in) :: p\n real(kind=DP), dimension(size(p)) :: cdfinvn\n logical, dimension(size(p)) :: maskgt\n real(kind=DP), dimension(size(p)) :: y\n real(kind=DP), parameter :: p0=-0.322232431088_dp, p1=-1.0_dp, & \n p2=-0.342242088547_dp, p3=-0.0204231210245_dp, &\n p4=-0.453642210148e-4_dp, q0=0.0993484626060_dp, &\n q1=0.588581570495_dp, q2=0.531103462366_dp, &\n q3=0.103537752850_dp, q4=0.38560700634e-2_dp, &\n minp=1.0e-300_dp\n maskgt = (p > 0.5_dp)\n cdfinvn = p\n where (maskgt) cdfinvn = 1.0_dp-cdfinvn\n where (cdfinvn < minp) cdfinvn=minp\n y = sqrt(-2.0_dp*log(cdfinvn))\n cdfinvn = y + ((((p4*y + p3) * y + p2)* y + p1)*y + p0)/ &\n ((((q4*y + q3) * y + q2) * y + q1) * y + q0)\n where (.not.maskgt) cdfinvn=-cdfinvn\n where (p == 0.5_dp) cdfinvn = 0.0_dp\nend function cdfinvn1d\nfunction cdfinvn2d(p) result(cdfinvn)\n real(kind=DP), dimension(:,:), intent(in) :: p\n real(kind=DP), dimension(Size(p,1),Size(p,2)) :: cdfinvn\n real(kind=DP), dimension(Size(p,1)*Size(p,2)) :: tmp\n tmp = reshape(p,(/ size(p,1)*size(p,2) /))\n tmp = cdfinvn1d(tmp)\n cdfinvn = reshape(tmp,(/ size(p,1), size(p,2) /))\nend function cdfinvn2d\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! CHOL function\n!\n! Format: chol(a)\n!\n! Gives Cholesky decomposition of the symmetric positive definite\n! matrix A, i.e., the matrix L such that LL'=a. If A is not\n! a symmetric positive definite matrix, then this function\n! will give back garbage. A can be either single or double\n! precision, with the result being of the same type as A.\n! \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nfunction chols(a) result(chol)\n real(kind=SP), dimension(:,:), intent(in) :: a\n real(kind=SP), dimension(size(a,1),size(a,2)) :: chol\n real(kind=SP), dimension(size(a,1)) :: p\n integer :: i,n\n real(kind=SP) :: sumn\n n = size(a,1) ! should check to make sure a is square\n chol = a\n do i=1,n\n sumn = chol(i,i) - dot_product(chol(1:i-1,i),chol(1:i-1,i))\n p(i) = sqrt(sumn)\n chol(i,i+1:n) = (chol(i+1:n,i)-matmul(chol(1:i-1,i),chol(1:i-1,i+1:n)))/p(i)\n end do\n do i = 1,n\n chol(i,i)=p(i)\n chol(i+1:n,i) = 0.0\n end do\nend function chols\nfunction chold(a) result(chol)\n real(kind=DP), dimension(:,:), intent(in) :: a\n real(kind=DP), dimension(size(a,1),size(a,1)) :: chol\n real(kind=DP), dimension(size(a,1)) :: p\n integer :: i,n\n real(kind=DP) :: sumn\n n = size(a,1) ! should check to make sure a is square\n chol = a\n do i=1,n\n sumn = chol(i,i) - dot_product(chol(1:i-1,i),chol(1:i-1,i))\n p(i) = sqrt(sumn)\n chol(i,i+1:n) = (chol(i+1:n,i)-matmul(chol(1:i-1,i),chol(1:i-1,i+1:n)))/p(i)\n end do\n do i = 1,n\n chol(i,i)=p(i)\n chol(i+1:n,i) = 0.0_dp\n end do\nend function chold\n\n\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! OLS function\n!\n! Format: ols(x,y)\n!\n! Gives OLS coefficient vector for regression of x on y.\n! \n! X and Y can be either single or double precision. The output\n! vector will be the same type as X and Y. X should have a \n! column of ones if you want an intercept.\n! \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nfunction olss(x,y) result(olsout)\n real(kind=SP), dimension(:,:), intent(in) :: x\n real(kind=SP), dimension(:), intent(in) :: y\n real(kind=SP), dimension(size(x,2)) :: olsout,xprimey,p\n real(kind=SP), dimension(size(x,2),size(x,2)) :: xprimex\n real(kind=SP) :: summ\n integer :: i,n\n n=size(x,2)\n xprimex = matmul(transpose(x),x)\n xprimey = matmul(transpose(x),y)\n do i=1,n\n summ = xprimex(i,i)-dot_product(xprimex(i,1:i-1),xprimex(i,1:i-1))\n p(i) = sqrt(summ)\n xprimex(i+1:n,i) = (xprimex(i,i+1:n)-matmul(xprimex(i+1:n,1:i-1),xprimex(i,1:i-1)))/p(i)\n end do\n do i=1,n\n olsout(i)=(xprimey(i)-dot_product(xprimex(i,1:i-1),olsout(1:i-1)))/p(i)\n end do\n do i=n,1, -1\n olsout(i)=(olsout(i)-dot_product(xprimex(i+1:n,i),olsout(i+1:n)))/p(i)\n end do\nend function olss\nfunction olsd(x,y) result(ols)\n real(kind=DP), dimension(:,:), intent(in) :: x\n real(kind=DP), dimension(:), intent(in) :: y\n real(kind=DP), dimension(size(x,2)) :: ols,xprimey,p\n real(kind=DP), dimension(size(x,2),size(x,2)) :: xprimex\n real(kind=DP) :: summ\n integer :: i,n\n n=size(x,2)\n xprimex = matmul(transpose(x),x)\n xprimey = matmul(transpose(x),y)\n do i=1,n\n summ = xprimex(i,i)-dot_product(xprimex(i,1:i-1),xprimex(i,1:i-1))\n p(i) = sqrt(summ)\n xprimex(i+1:n,i) = (xprimex(i,i+1:n)-matmul(xprimex(i+1:n,1:i-1),xprimex(i,1:i-1)))/p(i)\n end do\n do i=1,n\n ols(i)=(xprimey(i)-dot_product(xprimex(i,1:i-1),ols(1:i-1)))/p(i)\n end do\n do i=n,1, -1\n ols(i)=(ols(i)-dot_product(xprimex(i+1:n,i),ols(i+1:n)))/p(i)\n end do\nend function olsd\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! RANDINT subroutine (formerly a function)\n!\n! Format: randint(n)\n!\n! Gives a list of n random integers between 1 and n.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine randint(randintout)\n integer, dimension(:), intent(out) :: randintout\n real, dimension(size(randintout)) :: rnd_num\n integer :: n\n n=size(randintout)\n call runif(rnd_num)\n randintout = 1+floor(real(n,SP)*rnd_num)\nend subroutine randint\n\n\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! FACTORIAL function\n!\n! Format: factorial(x)\n!\n! Given the integer (or vector of integers) x, returns \n!\tx! or x*(x-1)*(x-2)*...*3*2*1\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\npure function factorial0(n) result(factorial)\n integer, intent(in) :: n\n integer :: factorial\n integer :: i\n factorial=1\n if (n > 1) then\n do i=2,n\n factorial=factorial*i\n end do\n end if\nend function factorial0\npure function factorial1(n) result(factorial)\n integer, dimension(:), intent(in) :: n\n integer, dimension(size(n)) :: factorial\n integer :: i,maxn\n factorial=1\n maxn=maxval(n)\n if (maxn > 1) then\n do i=2,maxn\n where (n >= i) factorial=factorial*i\n end do\n end if\nend function factorial1\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! NCHOOSEK function\n!\n! Format: nchoosek(n,k)\n!\n! Gives the number of k-length combinations of n items, or\n! n!\n! ----------\n! k!(n-k)!\n! \n! N and K can both be scalars, or both be vectors, but\n! must be integers.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\npure function nchoosek0(n,k) result(nchoosek)\n integer, intent(in) :: n,k\n integer :: nchoosek\n nchoosek = factorial(n)/(factorial(k)*factorial(n-k))\nend function nchoosek0\npure function nchoosek1(n,k) result(nchoosek)\n integer, dimension(:), intent(in) :: n\n integer, dimension(size(n)), intent(in) :: k\n integer, dimension(size(n)) :: nchoosek\n nchoosek = factorial(n)/(factorial(k)*factorial(n-k))\nend function nchoosek1\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! FIND_PRIMES function\n!\n! Format: find_primes(n)\n!\n! Returns the first n primes in a vector of length n, through \n! a very brute-force algorithm.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nfunction find_primes(n) result(primes)\n integer, intent(in) :: n\n integer, dimension(n) :: primes\n integer :: i,j,nprimes\n logical :: isaprime\n primes(1)=2\n nprimes=1\n do i=3,huge(1)\n isaprime = .true.\n do j=1,nprimes\n if (modulo(i,primes(j)) == 0) then\n isaprime = .false.\n exit\n end if\n end do\n if (isaprime) then\n nprimes=nprimes+1\n primes(nprimes) = i\n if (nprimes == n) return\n end if\n end do\nend function find_primes\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! RHALT function\n!\n! Format: rhalt(r,c,shift)\n!\n! Gives a randomized Halton matrix with r rows and c columns.\n! \"shift\" is the random number\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nfunction rhalt(r,c,shift) result(rhaltout)\n integer, intent(in) :: r,c\n real(kind=DP), intent(in) :: shift\n real(kind=DP), dimension(r,c) :: rhaltout\n rhaltout=hmat(r,c)+shift\n where (rhaltout > 1.0_dp) rhaltout=rhaltout-1.0_dp\nend function rhalt\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! HMAT function\n!\n! Format: hmat(r,c)\n!\n! Gives a Halton matrix with r rows and c columns.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nfunction hmat(r,c) result(hmatout)\n integer, intent(in) :: r,c\n real(kind=DP), dimension(r,c) :: hmatout\n integer, dimension(c) :: prim\n integer :: droppit,i\n real(kind=DP), dimension(:), allocatable :: tmp\n prim=find_primes(c)\n droppit = max(10,prim(c))\n allocate(tmp(r+droppit))\n do i=1,c\n tmp = halton_sequence(r+droppit,prim(i))\n hmatout(:,i) = tmp((droppit+1):(droppit+r))\n end do\n deallocate(tmp)\nend function hmat\n \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! HALTON_SEQUENCE function\n!\n! Format: halton_sequence(n,s)\n!\n! Gives a Halton sequence\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nfunction halton_sequence(n,s) result(hseqout)\n integer, intent(in) :: n,s\n real(kind=DP), dimension(n) :: hseqout\n integer :: i,j,k,len\n real(kind=DP), dimension(:), allocatable :: x\n k = ceiling(log(real(n+1))/log(real(s)))\n allocate(x(1+s**k))\n x(1) = 0.0_dp\n len=1\n do i=1,k\n do j=1,(s-1)\n x((j*len+1):((j+1)*len))=x(1:len)+real(j,DP)/real(s**i,DP)\n end do\n len=len*s\n end do\n hseqout = x(2:(n+1))\n deallocate(x)\nend function halton_sequence\n\n\nend module bkmath\n", "meta": {"hexsha": "0cb6754e4519c870f2cad7a5b684ea40e8f896b1", "size": 22472, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/bkmath.f90", "max_stars_repo_name": "bvkrauth/smle", "max_stars_repo_head_hexsha": "8a2e177e176051d0ff36ddac7b5fa4c941f6b919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-28T11:27:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-28T11:27:54.000Z", "max_issues_repo_path": "src/lib/bkmath.f90", "max_issues_repo_name": "bvkrauth/smle", "max_issues_repo_head_hexsha": "8a2e177e176051d0ff36ddac7b5fa4c941f6b919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-03-23T18:42:48.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-23T19:42:50.000Z", "max_forks_repo_path": "src/lib/bkmath.f90", "max_forks_repo_name": "bvkrauth/smle", "max_forks_repo_head_hexsha": "8a2e177e176051d0ff36ddac7b5fa4c941f6b919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-06T07:31:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T07:31:51.000Z", "avg_line_length": 32.9985315712, "max_line_length": 99, "alphanum_fraction": 0.5789871841, "num_tokens": 8070, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810466522863, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7935452775595411}} {"text": "program main\n ! Default\n implicit none\n\n ! Parameters\n integer(4), parameter :: target_sum = 1000\n\n ! Variables\n integer(4) :: a,b,c\n\n ! Do work\n outer: do a=1,target_sum\n do b=a,target_sum\n do c=b+1,target_sum\n if (is_triplet(a,b,c)) then\n if (a+b+c==target_sum) then\n write(*,*) 'Special triple is: ',a,b,c\n write(*,*) 'Product is: ',a*b*c\n exit outer\n endif\n endif\n enddo\n enddo\n enddo outer\n\n\ncontains\n\n\n pure function is_triplet(a,b,c)\n ! Default\n implicit none\n\n ! Function arguments\n integer(4), intent(in) :: a,b,c\n logical :: is_triplet\n\n ! Check if numbers are a triplet\n ! Assumes that a <= b < c\n if (a**2 + b**2 == c**2) then\n is_triplet = .true.\n else\n is_triplet = .false.\n endif\n\n return\n end function is_triplet\n\n\nend program main\n", "meta": {"hexsha": "7a4b778c966bd8f1470f530d6bea449ef9a641dc", "size": 935, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/problem9/problem9.f90", "max_stars_repo_name": "plaplant/Project_Euler", "max_stars_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/problem9/problem9.f90", "max_issues_repo_name": "plaplant/Project_Euler", "max_issues_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/problem9/problem9.f90", "max_forks_repo_name": "plaplant/Project_Euler", "max_forks_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-01-07T21:43:45.000Z", "max_forks_repo_forks_event_max_datetime": "2017-01-07T21:43:45.000Z", "avg_line_length": 18.3333333333, "max_line_length": 55, "alphanum_fraction": 0.5315508021, "num_tokens": 268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039739, "lm_q2_score": 0.8596637487122112, "lm_q1q2_score": 0.7935033081937408}} {"text": "! Name: ARPIT KUMAR JAIN, Roll No: 180122009\nPROGRAM ChebyshevInterpolationSinPiX\n IMPLICIT NONE\n REAL, PARAMETER :: pi = acos(-1.0)\n INTEGER:: n, k\n REAL:: Point \n REAL, DIMENSION(:), ALLOCATABLE:: X, F\n\n WRITE(*, fmt = '(/A)', ADVANCE = \"NO\") \"Enter Order of Interpolation Polynomial: \"\n READ(*, *) n\n ALLOCATE(X(0:n));\n ALLOCATE(F(0:n));\n WRITE(*, 10, ADVANCE = \"NO\") n\n 10 FORMAT(/, \"Enter the X value to find Q\", i0, \"(X): \")\n READ(*, *) point\n\n DO k = 0, n\n X(k) = cos(((2*k+1 )*pi)/(2*n+2))\n F(k) = Sin(pi * X(k))\n ENDDO\n\n CALL NewtonInterpolation(point, n, F, X)\n\n CONTAINS \n SUBROUTINE NewtonInterpolation(point, n, F, X)\n IMPLICIT NONE\n REAL:: point, QnX, polynomialTerm\n INTEGER:: n, i, j\n REAL, DIMENSION(0:n):: X, F\n REAL, DIMENSION(0:n, 0:n):: DD ! DD for Divided Difference\n DD = 0.0\n\n DO i = 0, n\n DD(i, i) = F(i)\n ENDDO\n\n DO j = 1, n\n DO i = 0, n-j\n DD(i, i+j) = ( DD(i+1, i+j) - DD(i, i+j-1) ) / ( X(i+j) - X(i) )\n ! WRITE(*, fmt = '(A, i0, A, i0, A, f0.9)') \"DD[\", i, \"...\", i+j, \"] = \", DD(i, i+j)\n ENDDO\n ENDDO\n\n QnX = DD(0, 0) ! QnX = a0 (initialize)\n\n DO i = 0, n-1\n polynomialTerm = 1.0\n DO j = 0, i\n polynomialTerm = polynomialTerm * (point - X(j))\n ENDDO\n QnX = QnX + DD(0, i+1) * polynomialTerm\n ENDDO\n\n WRITE(*, fmt = '(/A)') \"Result of Newton Interpolation\"\n WRITE(*, 11) n, point, QnX\n 11 FORMAT(\"Q\", i0, \"(\", f0.3, \") = \", f0.8/)\n END SUBROUTINE NewtonInterpolation\n\nEND PROGRAM ChebyshevInterpolationSinPiX", "meta": {"hexsha": "459c7a17c7764cfede9d19bd4af3557e265ddaa9", "size": 1740, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Chebyshev/2.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Chebyshev/2.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chebyshev/2.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 29.4915254237, "max_line_length": 100, "alphanum_fraction": 0.4862068966, "num_tokens": 625, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7935033048750351}} {"text": "\n\nprogram main\n\nimplicit none\n\n\n integer, parameter :: N_DIVISORS = 500\n integer, parameter :: ONE = 1\n\n print*, max_tri_divis(N_DIVISORS)\n\n\ncontains\n\n ! This is here because I really miss the '+=' operator from C\n ! Operates on TWO instances of 64 bit numbers.\n\n pure subroutine inc(base, offset)\n\n integer, intent(out) :: base\n integer, intent(in) :: offset\n\n base = base + offset\n\n return\n\n end subroutine inc\n\n\n ! Calculate what Triangle number is the first to have in excess of\n ! `m` divisors \n \n pure function max_tri_divis(m)\n\n integer, intent(in) :: m\n integer :: max_tri_divis\n integer :: i, tri\n\n i = 3 \n tri = 3 \n\n do while (.true.)\n if (numdivis(tri) > m) then\n max_tri_divis = tri\n exit\n endif\n\n call inc(tri, i)\n call inc(i, ONE)\n\n end do\n\n return\n\n end function max_tri_divis\n\n\n ! Calculate the number of divisors for a given number `x` by\n ! by searching up to the square and multiplying that count by 2\n\n pure function numdivis(x)\n \n integer, intent(in) :: x\n integer :: numdivis\n\n ! local\n integer :: i\n\n i = 1\n numdivis = 0\n\n do while ((i ** 2) < x)\n\n if (mod(x, i) == 0) then\n call inc(numdivis, ONE)\n endif\n\n call inc(i, ONE)\n\n end do\n\n numdivis = 2 * numdivis\n\n return\n \n end function numdivis\n\n\nend program main\n\n", "meta": {"hexsha": "9b33eada7dbda236efaa8871c3df338b97f7ae1d", "size": 1940, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/divis_tri_number.f95", "max_stars_repo_name": "guynan/project_euler", "max_stars_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-03-08T09:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T13:52:49.000Z", "max_issues_repo_path": "fortran/divis_tri_number.f95", "max_issues_repo_name": "guynan/project_euler", "max_issues_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-11-03T01:20:46.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-24T22:54:59.000Z", "max_forks_repo_path": "fortran/divis_tri_number.f95", "max_forks_repo_name": "guynan/project_euler", "max_forks_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-11-03T01:14:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T13:52:51.000Z", "avg_line_length": 21.0869565217, "max_line_length": 74, "alphanum_fraction": 0.4293814433, "num_tokens": 402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308165850442, "lm_q2_score": 0.8499711813581708, "lm_q1q2_score": 0.7933892938889121}} {"text": "program main\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n real(dp), parameter :: Gammaba = 1.d-2, Gammaca = 1.d0, omegaca = 10.d0\n real(dp) :: Omegas, omegap, alpha\n\n open(unit = 1, file = 'AbsorptionCoefficient-1.txt', status = 'unknown')\n omegap = 0.d0\n Omegas = 0.d0\n do while (omegap <= 20.d0)\n alpha = omegap * ((omegap - omegaca) + Gammaba**2)**2&\n * (Gammaba * Omegas**2 + Gammaca * ((omegap - omegaca)**2 + Gammaba**2))&\n / ((omegap - omegaca)**2 * (Omegas**2 - ((omegap - omegaca)**2 + Gammaba**2))**2&\n + (Gammaba * Omegas**2 + Gammaca * ((omegap - omegaca)**2 + Gammaba**2))**2)\n write(1,'(2f20.8)') omegap / omegaca, alpha\n omegap = omegap + 1.d-2\n end do\n close(1)\n\n open(unit = 2, file = 'AbsorptionCoefficient-2.txt', status = 'unknown')\n omegap = 0.d0\n Omegas = .5d0 * Gammaca\n do while (omegap <= 20.d0)\n alpha = omegap * ((omegap - omegaca) + Gammaba**2)**2&\n * (Gammaba * Omegas**2 + Gammaca * ((omegap - omegaca)**2 + Gammaba**2))&\n / ((omegap - omegaca)**2 * (Omegas**2 - ((omegap - omegaca)**2 + Gammaba**2))**2&\n + (Gammaba * Omegas**2 + Gammaca * ((omegap - omegaca)**2 + Gammaba**2))**2)\n write(2,'(2f20.8)') omegap / omegaca, alpha\n omegap = omegap + 1.d-2\n end do\n close(2)\n\n open(unit = 3, file = 'AbsorptionCoefficient-3.txt', status = 'unknown')\n omegap = 0.d0\n Omegas = 5.d0 * Gammaca\n do while (omegap <= 20.d0)\n alpha = omegap * ((omegap - omegaca) + Gammaba**2)**2&\n * (Gammaba * Omegas**2 + Gammaca * ((omegap - omegaca)**2 + Gammaba**2))&\n / ((omegap - omegaca)**2 * (Omegas**2 - ((omegap - omegaca)**2 + Gammaba**2))**2&\n + (Gammaba * Omegas**2 + Gammaca * ((omegap - omegaca)**2 + Gammaba**2))**2)\n write(3,'(2f20.8)') omegap / omegaca, alpha\n omegap = omegap + 1.d-2\n end do\n close(3)\n\nend program main\n", "meta": {"hexsha": "c9d068e650e57048b9272032532eaefbdc91596b", "size": 1967, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Assignment-4/AbsorptionCoefficient.f90", "max_stars_repo_name": "Chen-Jialin/Nonlinear-Optics-Assignments", "max_stars_repo_head_hexsha": "f81a28b475a3f0a331a5be17f113b258c296965f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Assignment-4/AbsorptionCoefficient.f90", "max_issues_repo_name": "Chen-Jialin/Nonlinear-Optics-Assignments", "max_issues_repo_head_hexsha": "f81a28b475a3f0a331a5be17f113b258c296965f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Assignment-4/AbsorptionCoefficient.f90", "max_forks_repo_name": "Chen-Jialin/Nonlinear-Optics-Assignments", "max_forks_repo_head_hexsha": "f81a28b475a3f0a331a5be17f113b258c296965f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.8510638298, "max_line_length": 89, "alphanum_fraction": 0.5449923742, "num_tokens": 767, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430803622103, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7933892810970817}} {"text": "program intrinsics_19c\n! Test math intrinsics both declarations and executable statements.\n! Single and double precision, complex only.\ninteger, parameter :: dp = kind(0.d0)\n\nreal, parameter :: &\n s1 = abs((0.5,0.5)), &\n s5 = aimag((0.4,0.5))\ncomplex, parameter :: &\n s2 = exp((0.5,0.5)), &\n s3 = log((0.5,0.5)), &\n s4 = sqrt((0.5,0.5))\n\nreal(dp), parameter :: &\n d1 = abs((0.5_dp,0.5_dp)), &\n d5 = aimag((0.4,0.5))\ncomplex(dp), parameter :: &\n d2 = exp((0.5_dp,0.5_dp)), &\n d3 = log((0.5_dp,0.5_dp)), &\n d4 = sqrt((0.5_dp,0.5_dp))\n\ncomplex :: x\ncomplex(dp) :: y\n\nx = (0.5,0.5)\ny = (0.5_dp,0.5_dp)\n\nprint *, abs((0.5,0.5)), abs((0.5_dp,0.5_dp)), s1, d1, abs(x), abs(y)\nprint *, exp((0.5,0.5)), exp((0.5_dp,0.5_dp)), s2, d2, exp(x), exp(y)\nprint *, log((0.5,0.5)), log((0.5_dp,0.5_dp)), s3, d3, log(x), log(y)\nprint *, sqrt((0.5,0.5)), sqrt((0.5_dp,0.5_dp)), s4, d4, sqrt(x), sqrt(y)\nx = (0.4,0.5)\ny = (0.4_dp,0.5_dp)\nprint *, aimag((0.5,0.5)), aimag((0.5_dp,0.5_dp)), s5, d5, aimag(x), aimag(y)\n\nend\n", "meta": {"hexsha": "4cb50a712b243c0c26c14ff98018b0657cceb4d9", "size": 1030, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/intrinsics_19c.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/intrinsics_19c.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/intrinsics_19c.f90", "max_forks_repo_name": "Thirumalai-Shaktivel/lfortran", "max_forks_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-03-28T19:40:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:28:55.000Z", "avg_line_length": 27.8378378378, "max_line_length": 77, "alphanum_fraction": 0.5533980583, "num_tokens": 461, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9648551505674445, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.7932934194265738}} {"text": "\nmodule ToroidCurrents\n contains \n\n function rho(r, r0, y)\n USE Types \n real(kind=dp) :: rho, r, r0, y\n \n rho = sqrt((r-r0)**2+y**2)\n end function rho\n\n function currentInToroidR(r, r0, y, turns, I) result (curr)\n USE Types \n real(kind=dp) :: r, r0, y, curr, rho1, rho2, turns, I\n \n rho1 = rho(8d-3, r0, y)\n rho2 = rho(10d-3, r0, y)\n\n curr = turns * I /(2*pi*(rho2-rho1)*r)*(-y/rho(r, r0, y))\n\n end function currentInToroidR\n\n function currentInToroidY(r, r0, y, turns, I) result (curr)\n USE Types \n real(kind=dp) :: r, r0, y, curr, rho1, rho2, turns, I\n \n rho1 = rho(8d-3, r0, y)\n rho2 = rho(10d-3, r0, y)\n\n curr = turns * I /(2*pi*(rho2-rho1)*r)*((r-r0)/rho(r, r0, y))\n\n end function currentInToroidY\n\nEnd module ToroidCurrents\n\nFUNCTION currdens1( model, n, args) RESULT(curr)\n USE DefUtils\n Use ToroidCurrents\n IMPLICIT None\n TYPE(Model_t) :: model\n INTEGER :: n\n REAL(KIND=dp) :: x, y, z, args(4), curr, f, omega, &\n theta, r0, r, turns, I, t\n\n x = args(1)\n y = args(2)\n z = args(3)\n t = args(4)\n\n r0 = 45d-3\n turns = 100d0\n\n f = 50d0\n omega = 2d0*pi*f\n\n I = 2d0 * sin(omega * t)\n\n r = sqrt(x**2 + z**2)\n\n theta = atan(x/z)\n\n curr = currentInToroidR(r, r0, y, turns, I) * sin(theta)\n\nEND FUNCTION currdens1\n\nFUNCTION currdens2( model, n, args) RESULT(curr)\n USE DefUtils\n Use ToroidCurrents\n IMPLICIT None\n TYPE(Model_t) :: model\n INTEGER :: n\n REAL(KIND=dp) :: x, y, z, args(4), curr, f, omega, &\n theta, r0, r, turns, I, t\n\n x = args(1)\n y = args(2)\n z = args(3)\n t = args(4)\n\n r0 = 45d-3\n turns = 100d0\n\n f = 50d0\n omega = 2d0*pi*f\n\n I = 2d0 * sin(omega * t)\n\n r = sqrt(x**2 + z**2)\n\n theta = atan(x/z)\n\n curr = currentInToroidY(r, r0, y, turns, I)\n\nEND FUNCTION currdens2\n\nFUNCTION currdens3( model, n, args) RESULT(curr)\n USE DefUtils\n Use ToroidCurrents\n IMPLICIT None\n TYPE(Model_t) :: model\n INTEGER :: n\n REAL(KIND=dp) :: x, y, z, args(4), curr, f, omega, &\n theta, r0, r, turns, I, t\n\n x = args(1)\n y = args(2)\n z = args(3)\n t = args(4)\n\n r0 = 45d-3\n turns = 100d0\n\n f = 50d0\n omega = 2d0*pi*f\n\n I = 2d0 * sin(omega * t)\n\n r = sqrt(x**2 + z**2)\n\n theta = atan(x/z)\n\n curr = currentInToroidR(r, r0, y, turns, I) * cos(theta)\n\nEND FUNCTION currdens3\n\n", "meta": {"hexsha": "4f9e1f57c195259158421c34aedc97dc4085d9c6", "size": 2366, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "benchmark_apps/elmerfem/fem/tests/mgdyn_anisotropic_cond/currents.f90", "max_stars_repo_name": "readex-eu/readex-apps", "max_stars_repo_head_hexsha": "38493b11806c306f4e8f1b7b2d97764b45fac8e2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-25T13:10:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-15T20:26:35.000Z", "max_issues_repo_path": "elmerfem/fem/tests/mgdyn_anisotropic_cond/currents.f90", "max_issues_repo_name": "jcmcmurry/pipelining", "max_issues_repo_head_hexsha": "8fface1a501b5050f58e7b902aacdcdde68e9648", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "elmerfem/fem/tests/mgdyn_anisotropic_cond/currents.f90", "max_forks_repo_name": "jcmcmurry/pipelining", "max_forks_repo_head_hexsha": "8fface1a501b5050f58e7b902aacdcdde68e9648", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-08-02T23:23:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-26T12:39:30.000Z", "avg_line_length": 18.7777777778, "max_line_length": 67, "alphanum_fraction": 0.5583262891, "num_tokens": 941, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632288833652, "lm_q2_score": 0.8333246035907932, "lm_q1q2_score": 0.7932110478818827}} {"text": "\n\tsubroutine qbezier(y1,y2,y3,xp3,yp,offset)\n\n!\tQuadratic Bezier spline interpolation in 1d\n!\ty1, y2, and y3 are for x=-1, 0, and 1, respectively\n!\tthe returned value, yp, is the result of the \n!\tinterpolation for 0<= xp <= 1 if offset=0\n!\n!\tIf offset is not 0, it is assumed it is offset=1 and\n!\tthen y1, y2 and y3 are for x=0,1, and 2, respectively\n!\tand still 0<= xp <= 1\n!\n!\tC. Allende Prieto, Feb 2004\n!\n! \tThe value xp is not actually needed, but 3 derived quantities in xp3\n!\txp3=( (1-xp)**2, xp**2, 2*xp*(1-xp) )\n!\n\n\tuse share, only: dp\n\timplicit none\n\t\n\tinteger\t::\toffset\n\treal(dp)::\t y1,y2,y3,xp3(3),yp,c0,yprime\n\n\t\n\tif (offset == 0) then\n\n\t\typrime=0.5_dp*(y3-y1)\n\t\tc0=y2+0.5_dp*yprime\n\n\t\t!yp=y2*(1.0_dp-xp)**2+y3*xp**2+c0*2.d0*xp*(1.0_dp-xp)\n\t\typ=y2*xp3(1) + y3*xp3(2) + c0*xp3(3)\n\n\telse\n\n\t\typrime=0.5_dp*(y3-y1)\n\t\tc0=y2-0.5_dp*yprime\n\t\t\n\t\t!yp=y1*(1.0_dp-xp)**2+y2*xp**2+c0*2.d0*xp*(1.0_dp-xp)\n\t\typ=y1*xp3(1) + y2*xp3(2) + c0*xp3(3)\n\t\t\n\n\tendif\n\t\t\n\tend subroutine qbezier\n", "meta": {"hexsha": "6a1bf9be4073ae4c71b1b101b9b1e3d217d0f479", "size": 982, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ferre/src/qbezier.f90", "max_stars_repo_name": "dnidever/apogee", "max_stars_repo_head_hexsha": "83ad7496a0b4193df9e2c01b06dc36cb879ea6c1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-04-11T13:35:24.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-14T06:12:51.000Z", "max_issues_repo_path": "ferre/src/qbezier.f90", "max_issues_repo_name": "dnidever/apogee", "max_issues_repo_head_hexsha": "83ad7496a0b4193df9e2c01b06dc36cb879ea6c1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ferre/src/qbezier.f90", "max_forks_repo_name": "dnidever/apogee", "max_forks_repo_head_hexsha": "83ad7496a0b4193df9e2c01b06dc36cb879ea6c1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2018-09-20T22:07:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T07:13:38.000Z", "avg_line_length": 21.347826087, "max_line_length": 71, "alphanum_fraction": 0.6303462322, "num_tokens": 448, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632316144274, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7932110363672947}} {"text": "FUNCTION convlv(data,respns)\n!-----------------------------------------------------------------------------\n! \n! Description:\n!\n! External function convolving two time-series. Convolution is perfomed in \n! the frequency domain. Unit time-step is assumed.\n!\n! Dependencies:\n!\n! Subroutine realft\n!\n! References:\n!\n! Numerical Recipes in Fortran90, pag. 1253\n!\n! Notes:\n!\n! Respns is assumed to have LESS number of points than Data.\n! The Respns time-series is assumed to NOT have values at negative times.\n! Input time-series are both zero-padded to avoid side-effects. Convolution\n! result is then truncated up to the original number of points before being\n! passed.\n! \n! Author: W. Imperatori\n!\n! Modified: January 2009 (v1.3)\n!\n\nuse def_kind; use interfaces, only: realft\n\nimplicit none\n\n! first input time-series (actually it is NOT modified)\nreal(kind=r_single),dimension(:),intent(inout):: data\n! second input time-series\nreal(kind=r_single),dimension(:),intent(in) :: respns\n! output function\nreal(kind=r_single),dimension(size(data)) :: convlv\n! local variables\ninteger(kind=i_single) :: n,m\ncomplex(kind=r_single),dimension(size(data)) :: tmpd,tmpr\nreal(kind=r_single),dimension(2*size(data)) :: pad1,pad2\n\n!-----------------------------------------------------------------------------\n\n! extract sizes\t\nn=size(data)\nm=size(respns) \n\n! check m > n\nif (m > n) call error_handling(9,'null','CONVLV (fourier.f90)')\n\n! check for 2**N number of points\nif ( iand(n,n-1) /=0 ) call error_handling(5,'null','CONVLV (fourier.f90)')\n\n! zero-pad input data to avoid side-effects (conservative assumption: zero-padding\n! equal to first input length - in theory it could be equal to non-zero length\n! of second input vector)\npad1(1:n) = data; pad1(n+1:) = 0. \n\n! zero-pad also respns to have same number of points in frequency\npad2(1:m)=respns(:); pad2(m+1:)=0. \n\n! FFT of input time-series\ncall realft(pad1,1,tmpd)\ncall realft(pad2,1,tmpr)\n\n! multiply FFTs\ntmpr(1)=cmplx(real(tmpd(1))*real(tmpr(1))/n,aimag(tmpd(1))*aimag(tmpr(1))/n,kind=r_single)\ntmpr(2:)=tmpd(2:)*tmpr(2:)/n\n\n! IFFT of multiplied Fourier spectra\t\ncall realft(pad2,-1,tmpr)\n\n! return only first n points (exclude padding values)\nconvlv = pad2(1:n)\n\nEND FUNCTION convlv\n\n!===================================================================================================\n\nFUNCTION correl(data1,data2)\n!-------------------------------------------------------------------------------\n!\n! Description:\n!\n! Compute correlation between two time series in the frequency domain\n!\n! Dependencies:\n!\n! Subroutine realft\n!\n! Notes:\n!\n! Time-series are not padded here. They should be passed already padded to \n! avoid side-effects\n!\n! References:\n!\n! Numerical Recipes in Fortran90, pag. 1254\n!\n! Author: W. Imperatori\n!\n! Modified: January 2009 (v1.3) \n!\n! *** NOT USED IN THIS VERSION ***\n!\n\nuse def_kind; use interfaces, only: realft\n\nimplicit none\n\n! input arrays\nreal(kind=r_single),dimension(:),intent(in) :: data1,data2\n! function\nreal(kind=r_single),dimension(size(data1)) :: correl\n! local variables\ncomplex(kind=r_single),dimension(size(data1)) :: cdat1,cdat2\ninteger(kind=i_single) :: n\nreal(kind=r_single),dimension(2*size(data1)) :: pad1,pad2\n\n!------------------------------------------------------------------------------\t\n\nn = size(data1)\n\n! checks for equal series length and 2**N npts \nif (n /= size(data2)) call error_handling(9,'null','CORREL (fourier.f90)') \nif (iand(n,n-1) /= 0) call error_handling(5,'null','CORREL (fourier.f90)')\n\n! zero-pad input data to avoid side-effects\npad1(1:n) = data1; pad1(n+1:) = 0. \npad2(1:n) = data2; pad2(n+1:) = 0. \n\n! FFT\ncall realft(pad1,1,cdat1)\ncall realft(pad2,1,cdat2)\n\n! perform multiplication with complex conjugate\ncdat1(1)=cmplx(real(cdat1(1))*real(cdat2(1))/n,aimag(cdat1(1))*aimag(cdat2(1))/n,kind=r_single)\ncdat1(2:)=cdat1(2:)*conjg(cdat2(2:))/n\n\n! IFFT\ncall realft(pad1,-1,cdat1)\n\n! return only N points (exclude padding values)\ncorrel(1:n/2) = pad1(1:n/2); correl(n/2 +1:) = pad1(3*n/2 +1:)\n\nEND FUNCTION correl\n\n!===================================================================================================\n\nFUNCTION lag_correl(seq1,seq2)\n!--------------------------------------------------------------------\n!\n! Description:\n!\n! Evaluate at which lag value the correlation of two sequences has \n! its maximum\n!\n! Dependencies:\n!\n! Function correl\n!\n! Author: W. Imperatori\n!\n! Modified: January 2009 (v1.3)\n!\n! *** NOT USED IN THIS VERSION ***\n!\n\nuse def_kind; use interfaces, only: correl\n\nimplicit none\n\n! input time-series\nreal(kind=r_single),dimension(:),intent(in):: seq1,seq2\n! function\nreal(kind=r_single) :: lag_correl\n! local variables\ninteger(kind=i_single) :: max_index,n\n\n!--------------------------------------------------------------------\n\nn = size(seq1)\n\nmax_index = maxloc(correl(seq1,seq2),dim=1)\n\nif (max_index > n/2) then\n lag_correl = -(max_index - n - 1) \nelse \n lag_correl = (max_index - 1) \nendif\n \nEND FUNCTION lag_correl\n\n!===================================================================================================\n\nSUBROUTINE four1d(data,isign)\n!---------------------------------------------------------------------\n!\n! Description:\n!\n! External subroutine from Numerical Recipes, prepares input for \n! FAST FOURIER TRANSFORM (FFT) or inverse (IFFT) computation\n!\n! Dependencies:\n!\n! Subroutine fourrow, function arth\n!\n! References:\n!\n! Numerical Recipes in Fortran90, pag. 1239-1240\n!\n! Notes:\n!\n! i_sign=1 -> FFT, i_sign=-1 -> IFFT\n!\n! Warning:\n!\n! This subroutine works ONLY with 2**n number of points\n!\n! Authors: W. Imperatori\n!\n! Modified: January 2009 (v1.3)\n!\n\nuse constants; use def_kind; use interfaces, only: fourrow, arth\n\nimplicit none\n\n! input-output vector where complex transform will be stored\ncomplex(kind=r_single),dimension(:),intent(inout) :: data\n! flag for FFT/IFFT\ninteger(kind=i_single),intent(in) :: isign\n! locals\ncomplex(kind=r_single),dimension(:,:),allocatable :: dat,temp\ncomplex(kind=r_double),dimension(:),allocatable :: w,wp\nreal(kind=r_double),dimension(:),allocatable :: theta\ninteger(kind=i_single) :: n,m1,m2,j\n\n!-----------------------------------------------------------------------\n\nn=size(data) \n\nif ( iand(n,n-1) /=0 ) call error_handling(5,'null','four1d (fft.f90)')\n\nm1=2**ceiling(0.5*log(real(n,kind=r_single))/0.693147) \nm2=n/m1\n\nallocate(dat(m1,m2),theta(m1),w(m1),wp(m1),temp(m2,m1))\n\ndat=reshape(data,shape(dat))\n\ncall fourrow(dat,isign) !first transform \n\ntheta=arth(0,isign,m1)*pi_double/n\nwp=cmplx(-2.0*sin(0.5*theta)**2,sin(theta),kind=r_double)\nw=cmplx(1.0,0.0,kind=r_double)\n\ndo j=2,m2\n w=w*wp+w\n dat(:,j)=dat(:,j)*w\nenddo\n\ntemp=transpose(dat)\n\ncall fourrow(temp,isign) !second transform\n \ndata=reshape(temp,shape(data))\n \ndeallocate(dat,w,wp,theta,temp)\n\nEND SUBROUTINE four1d\n\n!===================================================================================================\n\nSUBROUTINE fourrow(data,isign)\n!---------------------------------------------------------------------\n!\n! Description:\n!\n! External subroutine from Numerical Recipes, calculates FAST FOURIER\n! TRANSFORM (FFT) and its inverse (IFFT) for single-precision complex\n! data\n!\n! Dependencies:\n!\n! Subroutine swap\n!\n! References:\n!\n! Numerical Recipes in Fortran90, pag. 1235\n!\n! Notes:\n!\n! i_sign=1 -> FFT, i_sign=-1 -> IFFT\n!\n! Warning:\n!\n! This subroutine works ONLY with 2**n number of points\n!\n! Authors: W. Imperatori, M. Mai, B. Mena\n!\n! Modified: January 2009 (v1.3)\n!\n\nuse constants; use def_kind; use interfaces, only: swap\n\nimplicit none\n\n! input/output array\ncomplex(kind=r_single),dimension(:,:),intent(inout) :: data\n! flag for FFT/IFFT\ninteger(kind=i_single),intent(in) :: isign\n! locals\ninteger(kind=i_single) :: n,i,istep,j,m,mmax,n2\nreal(kind=r_double) :: theta\ncomplex(kind=r_single), dimension(size(data,1)) :: temp\ncomplex(kind=r_double) :: w,wp\ncomplex(kind=r_single) :: ws\n\n!---------------------------------------------------------------------\n\nn=size(data,2) \n \nif ( iand(n,n-1) /= 0 ) call error_handling(5,'null','fourrow (fft.f90)')\n\nn2=n/2\n\nj=n2\n\ndo i=1,n-2\n if (j > i) call swap(data(:,j+1),data(:,i+1))\n m=n2\n\n do\n if (m < 2 .or. j < m) exit\n j=j-m\n m=m/2\n enddo\n \n j=j+m\n\nenddo\n\nmmax=1\n\ndo\n if (n <= mmax) exit\n istep=2*mmax\n theta=pi/(isign*mmax)\n wp=cmplx(-2.0*sin(0.5*theta)**2,sin(theta),kind=r_double)\n w=cmplx(1.0,0.0,kind=r_double)\n\n do m=1,mmax\n ws=w\n\n do i=m,n,istep\n j=i+mmax\n temp=ws*data(:,j)\n data(:,j)=data(:,i)-temp\n data(:,i)=data(:,i)+temp\n enddo\n w=w*wp+w\n enddo\n\n mmax=istep\n\nenddo\n\nEND SUBROUTINE fourrow\n\n!===================================================================================================\n\nSUBROUTINE realft(data,isign,zdata)\n!-------------------------------------------------------------------\n!\n! Description:\n!\n! External subroutine performing FFT and IFFT of real time-series \n!\n! Dependencies:\n!\n! subroutine four1d, function zroots_unity\n!\n! References:\n!\n! Numerical Recipes in Fortran90, pag. 1243\n!\n! Author: W. Imperatori\n!\n! Modified: January 2009 (v1.3)\n!\n\nuse def_kind; use interfaces, only: four1d, zroots_unity\n\nimplicit none\n\nreal(kind=r_single),dimension(:),intent(inout) :: data\ninteger(kind=i_single),intent(in) :: isign\ncomplex(kind=r_single),dimension(:),optional,target:: zdata\n! local variables\ninteger(kind=i_single) :: n,ndum,nh,nq\ncomplex(kind=r_single),dimension(size(data)/4) :: w\ncomplex(kind=r_single),dimension(size(data)/4-1) :: h1,h2\ncomplex(kind=r_single),dimension(:),pointer :: cdata\ncomplex(kind=r_single) :: z\nreal(kind=r_single) :: c1=0.5,c2\n\n!------------------------------------------------------------------\n\nn=size(data) \n\nif ( iand(n,n-1) /= 0 ) call error_handling(5,'null','realft (fft.f90)')\n\nnh=n/2\nnq=n/4\n\nif (present(zdata)) then\n\n if ( n/2 /= size(zdata) ) call error_handling(7,'null','realft (fft.f90)')\n \n ndum=size(zdata)\n cdata=>zdata\n if (isign == 1) cdata=cmplx(data(1:n-1:2),data(2:n:2),kind=r_single)\nelse\n allocate(cdata(n/2))\n cdata=cmplx(data(1:n-1:2),data(2:n:2),kind=r_single)\nendif\n\nif (isign == 1) then\n c2=-0.5 \n call four1d(cdata,+1)\nelse\n c2=0.5\nendif\n \nw=zroots_unity(sign(n,isign),n/4) \nw=cmplx(-aimag(w),real(w),kind=r_single)\nh1=c1*(cdata(2:nq)+conjg(cdata(nh:nq+2:-1)))\nh2=c2*(cdata(2:nq)-conjg(cdata(nh:nq+2:-1)))\ncdata(2:nq)=h1+w(2:nq)*h2\ncdata(nh:nq+2:-1)=conjg(h1-w(2:nq)*h2)\nz=cdata(1)\n\nif (isign == 1) then\n cdata(1)=cmplx(real(z)+aimag(z),real(z)-aimag(z),kind=r_single)\nelse\n cdata(1)=cmplx(c1*(real(z)+aimag(z)),c1*(real(z)-aimag(z)),kind=r_single)\n call four1d(cdata,-1) \nendif\n\nif (present(zdata)) then\n if (isign /= 1) then\n data(1:n-1:2)=real(cdata)\n data(2:n:2)=aimag(cdata)\n endif\nelse\n data(1:n-1:2)=real(cdata)\n data(2:n:2)=aimag(cdata)\n deallocate(cdata)\nendif\n\nEND SUBROUTINE realft\n\n!===================================================================================================\n\nFUNCTION arth(first,increment,n)\n!-------------------------------------------------------\n!\n! Description:\n!\n! Return an arithmetic progression\n!\n! Dependencies:\n!\n! None\n!\n! References:\n!\n! Numerical Recipes in Fortran90, pag. 1371\n!\n! Author: W. Imperatori\n!\n! Modified: January 2009 (v1.3)\n!\n\nuse def_kind\n\nimplicit none\n\ninteger(kind=i_single),intent(in) :: first,increment,n\ninteger(kind=i_single),dimension(n):: arth\n! local variables\ninteger(kind=i_single) :: k,k2,temp\ninteger(kind=i_single),parameter :: NPAR_ARTH=16,NPAR2_ARTH=8\n\n!------------------------------------------------------------\n \nif (n > 0) arth(1)=first\n\nif (n <= NPAR_ARTH) then\n\n do k=2,n\n arth(k)=arth(k-1)+increment\n enddo\n\nelse\n\n do k=2,NPAR2_ARTH\n arth(k)=arth(k-1)+increment\n enddo\n\n temp=increment*NPAR2_ARTH\n k=NPAR2_ARTH\n\n do\n if (k >= n) exit\n k2=k+k\n arth(k+1:min(k2,n))=temp+arth(1:min(k,n-k))\n temp=temp+temp\n k=k2\n enddo\n\nendif\n\nEND FUNCTION arth\n\n!===================================================================================================\n\nSUBROUTINE swap(a,b)\n!-------------------------------------------------------\n!\n! Description:\n!\n! Swap the content of a and b\n!\n! Dependencies:\n!\n! None\n!\n! References:\n!\n! Numerical Recipes in Fortran90, pag. 1366-1367\n!\n! Author: W. Imperatori\n!\n! Modified: January 2009 (v1.3)\n!\n\nuse def_kind\n\nimplicit none\n\n! arrays to be swapped\ncomplex(kind=r_single),dimension(:),intent(inout):: a,b\n! local variable\ncomplex(kind=r_single),dimension(size(a)) :: dum\n\n!-------------------------------------------------------\n \ndum=a\na=b\nb=dum\n\nEND SUBROUTINE swap\n\n!===================================================================================================\n\nFUNCTION zroots_unity(n,nn)\n!-------------------------------------------------------\n!\n! Description:\n!\n! Return nn powers of the n-th root of unity\n!\n! Dependencies:\n!\n! None\n!\n! References:\n!\n! Numerical Recipes in Fortran90, pag. 1379\n!\n! Author: W. Imperatori\n!\n! Modified: January 2009 (v1.3)\n!\n\nuse constants; use def_kind\n\nimplicit none\n\n! input variables\ninteger(kind=i_single),intent(in) :: n,nn\n! function\ncomplex(kind=r_single),dimension(nn):: zroots_unity\n! local variables\ninteger(kind=i_single) :: k\nreal(kind=r_single) :: theta\n\n!-------------------------------------------------------\n \nzroots_unity(1)=1.0\ntheta=pi_double/n\nk=1\n\ndo\n if (k >= nn) exit\n zroots_unity(k+1)=cmplx(cos(k*theta),sin(k*theta),kind=r_single)\n zroots_unity(k+2:min(2*k,nn))=zroots_unity(k+1)*zroots_unity(2:min(k,nn-k))\n k=2*k\nenddo\n\nEND FUNCTION zroots_unity\n", "meta": {"hexsha": "4b0af188aebf7a7d52df07c08399235ff66f9436", "size": 14579, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "bbp/src/sdsu/bbtoolbox/fourier.f90", "max_stars_repo_name": "kevinmilner/bbp", "max_stars_repo_head_hexsha": "d9ba291b123be4e85f76317ef23600a339b2354d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2017-10-31T09:16:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T23:44:29.000Z", "max_issues_repo_path": "bbp/src/sdsu/bbtoolbox/fourier.f90", "max_issues_repo_name": "kevinmilner/bbp", "max_issues_repo_head_hexsha": "d9ba291b123be4e85f76317ef23600a339b2354d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 37, "max_issues_repo_issues_event_min_datetime": "2017-05-23T15:15:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-05T09:13:18.000Z", "max_forks_repo_path": "bbp/src/sdsu/bbtoolbox/fourier.f90", "max_forks_repo_name": "kevinmilner/bbp", "max_forks_repo_head_hexsha": "d9ba291b123be4e85f76317ef23600a339b2354d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2017-09-21T17:43:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-29T06:34:30.000Z", "avg_line_length": 23.6288492707, "max_line_length": 100, "alphanum_fraction": 0.5459908087, "num_tokens": 4029, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922388, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7931882755845484}} {"text": "C$Procedure ROTATE ( Generate a rotation matrix )\n \n SUBROUTINE ROTATE ( ANGLE, IAXIS, MOUT )\n \nC$ Abstract\nC\nC Calculate the 3x3 rotation matrix generated by a rotation\nC of a specified angle about a specified axis. This rotation\nC is thought of as rotating the coordinate system.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC MATRIX, ROTATION\nC\nC$ Declarations\n \n DOUBLE PRECISION ANGLE\n INTEGER IAXIS\n DOUBLE PRECISION MOUT ( 3,3 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC ANGLE I Angle of rotation (radians).\nC IAXIS I Axis of rotation (X=1, Y=2, Z=3).\nC MOUT O Resulting rotation matrix [ANGLE]\nC IAXIS\nC$ Detailed_Input\nC\nC ANGLE The angle given in radians, through which the rotation\nC is performed.\nC\nC IAXIS The index of the axis of rotation. The X, Y, and Z\nC axes have indices 1, 2 and 3 respectively.\nC\nC$ Detailed_Output\nC\nC MOUT Rotation matrix which describes the rotation of the\nC COORDINATE system through ANGLE radians about the\nC axis whose index is IAXIS.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Particulars\nC\nC A rotation about the first, i.e. x-axis, is described by\nC\nC | 1 0 0 |\nC | 0 cos(theta) sin(theta) |\nC | 0 -sin(theta) cos(theta) |\nC\nC A rotation about the second, i.e. y-axis, is described by\nC\nC | cos(theta) 0 -sin(theta) |\nC | 0 1 0 |\nC | sin(theta) 0 cos(theta) |\nC\nC A rotation about the third, i.e. z-axis, is described by\nC\nC | cos(theta) sin(theta) 0 |\nC | -sin(theta) cos(theta) 0 |\nC | 0 0 1 |\nC\nC ROTATE decides which form is appropriate according to the value\nC of IAXIS.\nC\nC$ Examples\nC\nC If ROTATE is called from a FORTRAN program as follows:\nC\nC CALL ROTATE (PI/4, 3, MOUT)\nC\nC then MOUT will be given by\nC\nC | SQRT(2)/2 SQRT(2)/2 0 |\nC MOUT = |-SQRT(2)/2 SQRT(2)/2 0 |\nC | 0 0 1 |\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC 1) If the axis index is not in the range 1 to 3 it will be\nC treated the same as that integer 1, 2, or 3 that is congruent\nC to it mod 3.\nC\nC$ Files\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.M. Owen (JPL)\nC W.L. Taber (JPL)\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WMO)\nC\nC-&\n \nC$ Index_Entries\nC\nC generate a rotation matrix\nC\nC-&\n \n \nC$ Revisions\nC\nC- Beta Version 1.1.0, 3-JAN-1989 (WLT)\nC\nC Upgrade the routine to work with negative axis indexes. Also take\nC care of the funky way the indices (other than the input) were\nC obtained via the MOD function. It works but isn't as clear\nC (or fast) as just reading the axes from data.\nC\nC-&\nC\nC\n DOUBLE PRECISION S\n DOUBLE PRECISION C\n \n INTEGER TEMP\n INTEGER I1\n INTEGER I2\n INTEGER I3\n INTEGER INDEXS ( 5 )\n SAVE INDEXS\n \n DATA INDEXS / 3, 1, 2, 3, 1 /\nC\nC Get the sine and cosine of ANGLE\nC\n S = DSIN(ANGLE)\n C = DCOS(ANGLE)\nC\nC Get indices for axes. The first index is for the axis of rotation.\nC The next two axes follow in right hand order (XYZ). First get the\nC non-negative value of IAXIS mod 3 .\nC\n TEMP = MOD ( MOD(IAXIS,3) + 3, 3 )\n \n I1 = INDEXS( TEMP + 1 )\n I2 = INDEXS( TEMP + 2 )\n I3 = INDEXS( TEMP + 3 )\n \nC\nC Construct the rotation matrix\nC\n MOUT(I1,I1) = 1.D0\n MOUT(I2,I1) = 0.D0\n MOUT(I3,I1) = 0.D0\n MOUT(I1,I2) = 0.D0\n MOUT(I2,I2) = C\n MOUT(I3,I2) = -S\n MOUT(I1,I3) = 0.D0\n MOUT(I2,I3) = S\n MOUT(I3,I3) = C\nC\n RETURN\n END\n \n", "meta": {"hexsha": "fe586d669aa9b61df844da396a79c13b59afa48f", "size": 5677, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/rotate.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/rotate.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/rotate.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 27.1626794258, "max_line_length": 72, "alphanum_fraction": 0.5960894839, "num_tokens": 1763, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939913343093499, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7931882707524119}} {"text": "module libfft\n\tuse mylib\n\tCONTAINS\nsubroutine dft(input_file, x_fft)\n implicit none\n\t! dummy vars\n\tcharacter (len=30) :: input_file\n\tcomplex, dimension(:), allocatable :: x_fft\n\t\n\t! local vars\n\treal, parameter :: PI = 4*atan(1.0)\n real, dimension(:), allocatable :: x\n integer :: N, k, i\n\tcomplex :: A, x_fft_sum\n \n ! Find how many lines are in the file\n call number_of_lines(input_file, N)\n\t\n\t! Load data from input_file\n allocate(x(N))\n call loadArrayFromFile(input_file, N, x)\n \n\t! allocate memory for FFT array\n allocate(x_fft(N))\n\t\n\t! Main Loop\n\tdo k=1,N\n\t\tA = exp(cmplx(0,-2*PI*k/N))\n\t\tx_fft_sum = 0\n\t\tdo i=1,N\n\t\t\tx_fft_sum = x_fft_sum + x(i) * (A**i)\n\t\tenddo\n\t\tx_fft(k) = x_fft_sum\n\tenddo\t\n\nend subroutine\n\nend module libfft", "meta": {"hexsha": "20f7394a52f174f53b59dbabcd4fde620be3308b", "size": 761, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "dft.f03", "max_stars_repo_name": "swapnilpravin/libfft", "max_stars_repo_head_hexsha": "e0d8cc6e16df0b7732f5f3c54654f4d3c6c4b5ff", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "dft.f03", "max_issues_repo_name": "swapnilpravin/libfft", "max_issues_repo_head_hexsha": "e0d8cc6e16df0b7732f5f3c54654f4d3c6c4b5ff", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dft.f03", "max_forks_repo_name": "swapnilpravin/libfft", "max_forks_repo_head_hexsha": "e0d8cc6e16df0b7732f5f3c54654f4d3c6c4b5ff", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.0263157895, "max_line_length": 44, "alphanum_fraction": 0.6517739816, "num_tokens": 249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465116437761, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.7931436919724231}} {"text": "program compute_stats_test\n use, intrinsic :: iso_fortran_env, only : sp => REAL32\n implicit none\n type stats_type\n real(kind=sp) :: sum, mean, stddev\n integer :: n\n end type stats_type\n type(stats_type) :: stats\n integer, parameter :: data_size = 10\n real(kind=sp), dimension(data_size) :: v\n real(kind=sp) :: mean, stddev\n call init_vector(v)\n call compute_stats(v, mean, stddev)\n print '(2(A14, F10.5))', 'mean = ', mean, 'stddev = ', stddev\n stats = compute_stats_alt(v)\n print '(2(A14, F10.5))', 'mean = ', mean, 'stddev = ', stddev\n\ncontains\n\n subroutine init_vector(v)\n implicit none\n real(kind=sp), dimension(:), intent(inout) :: v\n integer :: i\n v = [ (real(i, kind=sp), i = 1, size(v)) ]\n end subroutine init_vector\n\n subroutine compute_stats(v, mean, stddev)\n implicit none\n real(kind=sp), dimension(:), intent(in) :: v\n real(kind=sp), intent(out) :: mean, stddev\n real(kind=sp) :: s, s2\n integer :: n\n n = size(v)\n s = sum(v)\n s2 = sum(v*v)\n mean = s/n\n stddev = sqrt((s*s - s2)/(n - 1))\n end subroutine compute_stats\n\n function compute_stats_alt(v) result(stats)\n implicit none\n real(kind=sp), dimension(:), intent(in) :: v\n type(stats_type) :: stats\n real(kind=sp) :: sum2\n stats%n = size(v)\n stats%sum = sum(v)\n sum2 = sum(v**2)\n stats%mean = stats%sum/stats%n\n stats%stddev = sqrt((stats%sum**2 - sum2)/(stats%n - 1))\n end function compute_stats_alt\n \nend program compute_stats_test\n", "meta": {"hexsha": "0a90420cb863761a15eecf9897697d85aa2be650", "size": 1634, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/Functions/compute_stats_test.f90", "max_stars_repo_name": "Gjacquenot/training-material", "max_stars_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 115, "max_stars_repo_stars_event_min_datetime": "2015-03-23T13:34:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T00:27:21.000Z", "max_issues_repo_path": "Fortran/Functions/compute_stats_test.f90", "max_issues_repo_name": "Gjacquenot/training-material", "max_issues_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 56, "max_issues_repo_issues_event_min_datetime": "2015-02-25T15:04:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T07:42:48.000Z", "max_forks_repo_path": "Fortran/Functions/compute_stats_test.f90", "max_forks_repo_name": "Gjacquenot/training-material", "max_forks_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 59, "max_forks_repo_forks_event_min_datetime": "2015-11-26T11:44:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T00:27:22.000Z", "avg_line_length": 30.8301886792, "max_line_length": 65, "alphanum_fraction": 0.5728274174, "num_tokens": 461, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8740772302445241, "lm_q1q2_score": 0.7930609534139007}} {"text": "subroutine basis_function_b_val ( tdata, tval, yval )\n\n!*****************************************************************************80\n!\n!! BASIS_FUNCTION_B_VAL evaluates the B spline basis function.\n!\n! Discussion:\n!\n! The B spline basis function is a piecewise cubic which\n! has the properties that:\n!\n! * it equals 2/3 at TDATA(3), 1/6 at TDATA(2) and TDATA(4);\n! * it is 0 for TVAL <= TDATA(1) or TDATA(5) <= TVAL;\n! * it is strictly increasing from TDATA(1) to TDATA(3),\n! and strictly decreasing from TDATA(3) to TDATA(5);\n! * the function and its first two derivatives are continuous\n! at each node TDATA(I).\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Alan Davies, Philip Samuels,\n! An Introduction to Computational Geometry for Curves and Surfaces,\n! Clarendon Press, 1996,\n! ISBN: 0-19-851478-6,\n! LC: QA448.D38.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) TDATA(5), the nodes associated with the\n! basis function. The entries of TDATA are assumed to be distinct\n! and increasing.\n!\n! Input, real ( kind = 8 ) TVAL, a point at which the B spline basis\n! function is to be evaluated.\n!\n! Output, real ( kind = 8 ) YVAL, the value of the function at TVAL.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: ndata = 5\n\n integer ( kind = 4 ) left\n integer ( kind = 4 ) right\n real ( kind = 8 ) tdata(ndata)\n real ( kind = 8 ) tval\n real ( kind = 8 ) u\n real ( kind = 8 ) yval\n\n if ( tval <= tdata(1) .or. tdata(ndata) <= tval ) then\n yval = 0.0D+00\n return\n end if\n!\n! Find the interval [ TDATA(LEFT), TDATA(RIGHT) ] containing TVAL.\n!\n call r8vec_bracket ( ndata, tdata, tval, left, right )\n!\n! U is the normalized coordinate of TVAL in this interval.\n!\n u = ( tval - tdata(left) ) / ( tdata(right) - tdata(left) )\n!\n! Now evaluate the function.\n!\n if ( tval < tdata(2) ) then\n yval = u**3 / 6.0D+00\n else if ( tval < tdata(3) ) then\n yval = ( ( ( - 3.0D+00 &\n * u + 3.0D+00 ) &\n * u + 3.0D+00 ) &\n * u + 1.0D+00 ) / 6.0D+00\n else if ( tval < tdata(4) ) then\n yval = ( ( ( + 3.0D+00 &\n * u - 6.0D+00 ) &\n * u + 0.0D+00 ) &\n * u + 4.0D+00 ) / 6.0D+00\n else if ( tval < tdata(5) ) then\n yval = ( 1.0D+00 - u )**3 / 6.0D+00\n end if\n\n return\nend\nsubroutine basis_function_beta_val ( beta1, beta2, tdata, tval, yval )\n\n!*****************************************************************************80\n!\n!! BASIS_FUNCTION_BETA_VAL evaluates the beta spline basis function.\n!\n! Discussion:\n!\n! With BETA1 = 1 and BETA2 = 0, the beta spline basis function\n! equals the B spline basis function.\n!\n! With BETA1 large, and BETA2 = 0, the beta spline basis function\n! skews to the right, that is, its maximum increases, and occurs\n! to the right of the center.\n!\n! With BETA1 = 1 and BETA2 large, the beta spline becomes more like\n! a linear basis function; that is, its value in the outer two intervals\n! goes to zero, and its behavior in the inner two intervals approaches\n! a piecewise linear function that is 0 at the second node, 1 at the\n! third, and 0 at the fourth.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 09 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Alan Davies, Philip Samuels,\n! An Introduction to Computational Geometry for Curves and Surfaces,\n! Clarendon Press, 1996,\n! ISBN: 0-19-851478-6,\n! LC: QA448.D38.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) BETA1, the skew or bias parameter.\n! BETA1 = 1 for no skew or bias.\n!\n! Input, real ( kind = 8 ) BETA2, the tension parameter.\n! BETA2 = 0 for no tension.\n!\n! Input, real ( kind = 8 ) TDATA(5), the nodes associated with the\n! basis function. The entries of TDATA are assumed to be distinct\n! and increasing.\n!\n! Input, real ( kind = 8 ) TVAL, a point at which the B spline\n! basis function is to be evaluated.\n!\n! Output, real ( kind = 8 ) YVAL, the value of the function at TVAL.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: ndata = 5\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) beta1\n real ( kind = 8 ) beta2\n real ( kind = 8 ) c\n real ( kind = 8 ) d\n integer ( kind = 4 ) left\n integer ( kind = 4 ) right\n real ( kind = 8 ) tdata(ndata)\n real ( kind = 8 ) tval\n real ( kind = 8 ) u\n real ( kind = 8 ) yval\n\n if ( tval <= tdata(1) .or. tdata(ndata) <= tval ) then\n yval = 0.0D+00\n return\n end if\n!\n! Find the interval [ TDATA(LEFT), TDATA(RIGHT) ] containing TVAL.\n!\n call r8vec_bracket ( ndata, tdata, tval, left, right )\n!\n! U is the normalized coordinate of TVAL in this interval.\n!\n u = ( tval - tdata(left) ) / ( tdata(right) - tdata(left) )\n!\n! Now evaluate the function.\n!\n if ( tval < tdata(2) ) then\n\n yval = 2.0D+00 * u**3\n\n else if ( tval < tdata(3) ) then\n\n a = beta2 + 4.0D+00 * beta1 + 4.0D+00 * beta1 * beta1 &\n + 6.0D+00 * ( 1.0D+00 - beta1 * beta1 ) &\n - 3.0D+00 * ( 2.0D+00 + beta2 + 2.0D+00 * beta1 ) &\n + 2.0D+00 * ( 1.0D+00 + beta2 + beta1 + beta1 * beta1 )\n\n b = - 6.0D+00 * ( 1.0D+00 - beta1 * beta1 ) &\n + 6.0D+00 * ( 2.0D+00 + beta2 + 2.0D+00 * beta1 ) &\n - 6.0D+00 * ( 1.0D+00 + beta2 + beta1 + beta1 * beta1 )\n\n c = - 3.0D+00 * ( 2.0D+00 + beta2 + 2.0D+00 * beta1 ) &\n + 6.0D+00 * ( 1.0D+00 + beta2 + beta1 + beta1 * beta1 )\n\n d = - 2.0D+00 * ( 1.0D+00 + beta2 + beta1 + beta1 * beta1 )\n\n yval = ( ( d * u + c ) * u + b ) * u + a\n\n else if ( tval < tdata(4) ) then\n\n a = beta2 + 4.0D+00 * beta1 + 4.0D+00 * beta1 * beta1\n\n b = - 6.0D+00 * beta1 * ( 1.0D+00 - beta1 * beta1 )\n\n c = - 3.0D+00 * ( beta2 + 2.0D+00 * beta1**2 + 2.0D+00 * beta1**3 )\n\n d = 2.0D+00 * ( beta2 + beta1 + beta1**2 + beta1**3 )\n\n yval = ( ( d * u + c ) * u + b ) * u + a\n\n else if ( tval < tdata(5) ) then\n\n yval = 2.0D+00 * beta1**3 * ( 1.0D+00 - u )**3\n\n end if\n\n yval = yval / ( 2.0D+00 + beta2 + 4.0D+00 * beta1 + 4.0D+00 * beta1**2 &\n + 2.0D+00 * beta1**3 )\n\n return\nend\nsubroutine basis_matrix_b_uni ( mbasis )\n\n!*****************************************************************************80\n!\n!! BASIS_MATRIX_B_UNI sets up the uniform B spline basis matrix.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 17 June 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! James Foley, Andries vanDam, Steven Feiner, John Hughes,\n! Computer Graphics, Principles and Practice,\n! Second Edition,\n! Addison Wesley, 1995,\n! ISBN: 0201848406,\n! LC: T385.C5735.\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) MBASIS(4,4), the basis matrix.\n!\n implicit none\n\n real ( kind = 8 ) mbasis(4,4)\n!\n! In the following statement, the matrix appears as though it\n! has been transposed.\n!\n mbasis(1:4,1:4) = real ( reshape ( &\n (/ -1, 3, -3, 1, &\n 3, -6, 0, 4, &\n -3, 3, 3, 1, &\n 1, 0, 0, 0 /), &\n (/ 4, 4 /) ), kind = 8 ) / 6.0D+00\n\n return\nend\nsubroutine basis_matrix_beta_uni ( beta1, beta2, mbasis )\n\n!*****************************************************************************80\n!\n!! BASIS_MATRIX_BETA_UNI sets up the uniform beta spline basis matrix.\n!\n! Discussion:\n!\n! If BETA1 = 1 and BETA2 = 0, then the beta spline reduces to\n! the B spline.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! James Foley, Andries vanDam, Steven Feiner, John Hughes,\n! Computer Graphics, Principles and Practice,\n! Second Edition,\n! Addison Wesley, 1995,\n! ISBN: 0201848406,\n! LC: T385.C5735.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) BETA1, the skew or bias parameter.\n! BETA1 = 1 for no skew or bias.\n!\n! Input, real ( kind = 8 ) BETA2, the tension parameter.\n! BETA2 = 0 for no tension.\n!\n! Output, real ( kind = 8 ) MBASIS(4,4), the basis matrix.\n!\n implicit none\n\n real ( kind = 8 ) beta1\n real ( kind = 8 ) beta2\n real ( kind = 8 ) delta\n real ( kind = 8 ) mbasis(4,4)\n\n mbasis(1,1) = - 2.0D+00 * beta1 * beta1 * beta1\n mbasis(1,2) = 2.0D+00 * beta2 &\n + 2.0 * beta1 * ( beta1 * beta1 + beta1 + 1.0D+00 )\n mbasis(1,3) = - 2.0D+00 * ( beta2 + beta1 * beta1 + beta1 + 1.0D+00 )\n mbasis(1,4) = 2.0D+00\n\n mbasis(2,1) = 6.0D+00 * beta1 * beta1 * beta1\n mbasis(2,2) = - 3.0D+00 * beta2 &\n - 6.0D+00 * beta1 * beta1 * ( beta1 + 1.0D+00 )\n mbasis(2,3) = 3.0D+00 * beta2 + 6.0D+00 * beta1 * beta1\n mbasis(2,4) = 0.0D+00\n\n mbasis(3,1) = - 6.0D+00 * beta1 * beta1 * beta1\n mbasis(3,2) = 6.0D+00 * beta1 * ( beta1 - 1.0D+00 ) * ( beta1 + 1.0D+00 )\n mbasis(3,3) = 6.0D+00 * beta1\n mbasis(3,4) = 0.0D+00\n\n mbasis(4,1) = 2.0D+00 * beta1 * beta1 * beta1\n mbasis(4,2) = 4.0D+00 * beta1 * ( beta1 + 1.0D+00 ) + beta2\n mbasis(4,3) = 2.0D+00\n mbasis(4,4) = 0.0D+00\n\n delta = ( ( 2.0D+00 &\n * beta1 + 4.0D+00 ) &\n * beta1 + 4.0D+00 ) &\n * beta1 + 2.0D+00 + beta2\n\n mbasis(1:4,1:4) = mbasis(1:4,1:4) / delta\n\n return\nend\nsubroutine basis_matrix_bezier ( mbasis )\n\n!*****************************************************************************80\n!\n!! BASIS_MATRIX_BEZIER sets up the cubic Bezier spline basis matrix.\n!\n! Discussion:\n!\n! This basis matrix assumes that the data points are stored as\n! ( P1, P2, P3, P4 ). P1 is the function value at T = 0, while\n! P2 is used to approximate the derivative at T = 0 by\n! dP/dt = 3 * ( P2 - P1 ). Similarly, P4 is the function value\n! at T = 1, and P3 is used to approximate the derivative at T = 1\n! by dP/dT = 3 * ( P4 - P3 ).\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! James Foley, Andries vanDam, Steven Feiner, John Hughes,\n! Computer Graphics, Principles and Practice,\n! Second Edition,\n! Addison Wesley, 1995,\n! ISBN: 0201848406,\n! LC: T385.C5735.\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) MBASIS(4,4), the basis matrix.\n!\n implicit none\n\n real ( kind = 8 ) mbasis(4,4)\n\n mbasis(1,1) = -1.0D+00\n mbasis(1,2) = 3.0D+00\n mbasis(1,3) = -3.0D+00\n mbasis(1,4) = 1.0D+00\n\n mbasis(2,1) = 3.0D+00\n mbasis(2,2) = -6.0D+00\n mbasis(2,3) = 3.0D+00\n mbasis(2,4) = 0.0D+00\n\n mbasis(3,1) = -3.0D+00\n mbasis(3,2) = 3.0D+00\n mbasis(3,3) = 0.0D+00\n mbasis(3,4) = 0.0D+00\n\n mbasis(4,1) = 1.0D+00\n mbasis(4,2) = 0.0D+00\n mbasis(4,3) = 0.0D+00\n mbasis(4,4) = 0.0D+00\n\n return\nend\nsubroutine basis_matrix_hermite ( mbasis )\n\n!*****************************************************************************80\n!\n!! BASIS_MATRIX_HERMITE sets up the Hermite spline basis matrix.\n!\n! Discussion:\n!\n! This basis matrix assumes that the data points are stored as\n! ( P1, P2, P1', P2' ), with P1 and P1' being the data value and\n! the derivative dP/dT at T = 0, while P2 and P2' apply at T = 1.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! James Foley, Andries vanDam, Steven Feiner, John Hughes,\n! Computer Graphics, Principles and Practice,\n! Second Edition,\n! Addison Wesley, 1995,\n! ISBN: 0201848406,\n! LC: T385.C5735.\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) MBASIS(4,4), the basis matrix.\n!\n implicit none\n\n real ( kind = 8 ) mbasis(4,4)\n\n mbasis(1,1) = 2.0D+00\n mbasis(1,2) = -2.0D+00\n mbasis(1,3) = 1.0D+00\n mbasis(1,4) = 1.0D+00\n\n mbasis(2,1) = -3.0D+00\n mbasis(2,2) = 3.0D+00\n mbasis(2,3) = -2.0D+00\n mbasis(2,4) = -1.0D+00\n\n mbasis(3,1) = 0.0D+00\n mbasis(3,2) = 0.0D+00\n mbasis(3,3) = 1.0D+00\n mbasis(3,4) = 0.0D+00\n\n mbasis(4,1) = 1.0D+00\n mbasis(4,2) = 0.0D+00\n mbasis(4,3) = 0.0D+00\n mbasis(4,4) = 0.0D+00\n\n return\nend\nsubroutine basis_matrix_overhauser_nonuni ( alpha, beta, mbasis )\n\n!*****************************************************************************80\n!\n!! BASIS_MATRIX_OVERHAUSER_NONUNI: nonuniform Overhauser spline basis matrix.\n!\n! Discussion:\n!\n! This basis matrix assumes that the data points P1, P2, P3 and\n! P4 are not uniformly spaced in T, and that P2 corresponds to T = 0,\n! and P3 to T = 1.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) ALPHA, BETA.\n! ALPHA = || P2 - P1 || / ( || P3 - P2 || + || P2 - P1 || )\n! BETA = || P3 - P2 || / ( || P4 - P3 || + || P3 - P2 || ).\n!\n! Output, real ( kind = 8 ) MBASIS(4,4), the basis matrix.\n!\n implicit none\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ) beta\n real ( kind = 8 ) mbasis(4,4)\n\n mbasis(1,1) = - ( 1.0D+00 - alpha ) * ( 1.0D+00 - alpha ) / alpha\n mbasis(1,2) = beta + ( 1.0D+00 - alpha ) / alpha\n mbasis(1,3) = alpha - 1.0D+00 / ( 1.0D+00 - beta )\n mbasis(1,4) = beta * beta / ( 1.0D+00 - beta )\n\n mbasis(2,1) = 2.0D+00 * ( 1.0D+00 - alpha ) * ( 1.0D+00 - alpha ) / alpha\n mbasis(2,2) = ( - 2.0D+00 * ( 1.0D+00 - alpha ) - alpha * beta ) / alpha\n mbasis(2,3) = ( 2.0D+00 * ( 1.0D+00 - alpha ) &\n - beta * ( 1.0D+00 - 2.0D+00 * alpha ) ) / ( 1.0D+00 - beta )\n mbasis(2,4) = - beta * beta / ( 1.0D+00 - beta )\n\n mbasis(3,1) = - ( 1.0D+00 - alpha ) * ( 1.0D+00 - alpha ) / alpha\n mbasis(3,2) = ( 1.0D+00 - 2.0D+00 * alpha ) / alpha\n mbasis(3,3) = alpha\n mbasis(3,4) = 0.0D+00\n\n mbasis(4,1) = 0.0D+00\n mbasis(4,2) = 1.0D+00\n mbasis(4,3) = 0.0D+00\n mbasis(4,4) = 0.0D+00\n\n return\nend\nsubroutine basis_matrix_overhauser_nul ( alpha, mbasis )\n\n!*****************************************************************************80\n!\n!! BASIS_MATRIX_OVERHAUSER_NUL sets the nonuniform left Overhauser basis matrix.\n!\n! Discussion:\n!\n! This basis matrix assumes that the data points P1, P2, and\n! P3 are not uniformly spaced in T, and that P1 corresponds to T = 0,\n! and P2 to T = 1.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 27 August 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) ALPHA.\n! ALPHA = || P2 - P1 || / ( || P3 - P2 || + || P2 - P1 || )\n!\n! Output, real ( kind = 8 ) MBASIS(3,3), the basis matrix.\n!\n implicit none\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ) mbasis(3,3)\n\n mbasis(1,1) = 1.0D+00 / alpha\n mbasis(1,2) = - 1.0D+00 / ( alpha * ( 1.0D+00 - alpha ) )\n mbasis(1,3) = 1.0D+00 / ( 1.0D+00 - alpha )\n\n mbasis(2,1) = - ( 1.0D+00 + alpha ) / alpha\n mbasis(2,2) = 1.0D+00 / ( alpha * ( 1.0D+00 - alpha ) )\n mbasis(2,3) = - alpha / ( 1.0D+00 - alpha )\n\n mbasis(3,1) = 1.0D+00\n mbasis(3,2) = 0.0D+00\n mbasis(3,3) = 0.0D+00\n\n return\nend\nsubroutine basis_matrix_overhauser_nur ( beta, mbasis )\n\n!*****************************************************************************80\n!\n!! BASIS_MATRIX_OVERHAUSER_NUR: the nonuniform right Overhauser basis matrix.\n!\n! Discussion:\n!\n! This basis matrix assumes that the data points PN-2, PN-1, and\n! PN are not uniformly spaced in T, and that PN-1 corresponds to T = 0,\n! and PN to T = 1.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 27 August 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) BETA.\n! BETA = || P(N) - P(N-1) ||\n! / ( || P(N) - P(N-1) || + || P(N-1) - P(N-2) || )\n!\n! Output, real ( kind = 8 ) MBASIS(3,3), the basis matrix.\n!\n implicit none\n\n real ( kind = 8 ) beta\n real ( kind = 8 ) mbasis(3,3)\n\n mbasis(1,1) = 1.0D+00 / beta\n mbasis(1,2) = - 1.0D+00 / ( beta * ( 1.0D+00 - beta ) )\n mbasis(1,3) = 1.0D+00 / ( 1.0D+00 - beta )\n\n mbasis(2,1) = - ( 1.0D+00 + beta ) / beta\n mbasis(2,2) = 1.0D+00 / ( beta * ( 1.0D+00 - beta ) )\n mbasis(2,3) = - beta / ( 1.0D+00 - beta )\n\n mbasis(3,1) = 1.0D+00\n mbasis(3,2) = 0.0D+00\n mbasis(3,3) = 0.0D+00\n\n return\nend\nsubroutine basis_matrix_overhauser_uni ( mbasis )\n\n!*****************************************************************************80\n!\n!! BASIS_MATRIX_OVERHAUSER_UNI sets the uniform Overhauser spline basis matrix.\n!\n! Discussion:\n!\n! This basis matrix assumes that the data points P1, P2, P3 and\n! P4 are uniformly spaced in T, and that P2 corresponds to T = 0,\n! and P3 to T = 1.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! James Foley, Andries vanDam, Steven Feiner, John Hughes,\n! Computer Graphics, Principles and Practice,\n! Second Edition,\n! Addison Wesley, 1995,\n! ISBN: 0201848406,\n! LC: T385.C5735.\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) MBASIS(4,4), the basis matrix.\n!\n implicit none\n\n real ( kind = 8 ) mbasis(4,4)\n\n mbasis(1,1) = - 1.0D+00 / 2.0D+00\n mbasis(1,2) = 3.0D+00 / 2.0D+00\n mbasis(1,3) = - 3.0D+00 / 2.0D+00\n mbasis(1,4) = 1.0D+00 / 2.0D+00\n\n mbasis(2,1) = 2.0D+00 / 2.0D+00\n mbasis(2,2) = - 5.0D+00 / 2.0D+00\n mbasis(2,3) = 4.0D+00 / 2.0D+00\n mbasis(2,4) = - 1.0D+00 / 2.0D+00\n\n mbasis(3,1) = - 1.0D+00 / 2.0D+00\n mbasis(3,2) = 0.0D+00\n mbasis(3,3) = 1.0D+00 / 2.0D+00\n mbasis(3,4) = 0.0D+00\n\n mbasis(4,1) = 0.0D+00\n mbasis(4,2) = 2.0D+00 / 2.0D+00\n mbasis(4,3) = 0.0D+00\n mbasis(4,4) = 0.0D+00\n\n return\nend\nsubroutine basis_matrix_overhauser_uni_l ( mbasis )\n\n!*****************************************************************************80\n!\n!! BASIS_MATRIX_OVERHAUSER_UNI_L sets the left uniform Overhauser basis matrix.\n!\n! Discussion:\n!\n! This basis matrix assumes that the data points P1, P2, and P3\n! are not uniformly spaced in T, and that P1 corresponds to T = 0,\n! and P2 to T = 1.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) MBASIS(3,3), the basis matrix.\n!\n implicit none\n\n real ( kind = 8 ) mbasis(3,3)\n\n mbasis(1,1) = 2.0D+00\n mbasis(1,2) = - 4.0D+00\n mbasis(1,3) = 2.0D+00\n\n mbasis(2,1) = - 3.0D+00\n mbasis(2,2) = 4.0D+00\n mbasis(2,3) = - 1.0D+00\n\n mbasis(3,1) = 1.0D+00\n mbasis(3,2) = 0.0D+00\n mbasis(3,3) = 0.0D+00\n\n return\nend\nsubroutine basis_matrix_overhauser_uni_r ( mbasis )\n\n!*****************************************************************************80\n!\n!! BASIS_MATRIX_OVERHAUSER_UNI_R sets the right uniform Overhauser basis matrix.\n!\n! Discussion:\n!\n! This basis matrix assumes that the data points P(N-2), P(N-1),\n! and P(N) are uniformly spaced in T, and that P(N-1) corresponds to\n! T = 0, and P(N) to T = 1.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) MBASIS(3,3), the basis matrix.\n!\n implicit none\n\n real ( kind = 8 ) mbasis(3,3)\n\n mbasis(1,1) = 2.0D+00\n mbasis(1,2) = - 4.0D+00\n mbasis(1,3) = 2.0D+00\n\n mbasis(2,1) = - 3.0D+00\n mbasis(2,2) = 4.0D+00\n mbasis(2,3) = - 1.0D+00\n\n mbasis(3,1) = 1.0D+00\n mbasis(3,2) = 0.0D+00\n mbasis(3,3) = 0.0D+00\n\n return\nend\nsubroutine basis_matrix_tmp ( left, n, mbasis, ndata, tdata, ydata, tval, yval )\n\n!*****************************************************************************80\n!\n!! BASIS_MATRIX_TMP computes Q = T * MBASIS * P\n!\n! Discussion:\n!\n! YDATA is a vector of data values, most frequently the values of some\n! function sampled at uniformly spaced points. MBASIS is the basis\n! matrix for a particular kind of spline. T is a vector of the\n! powers of the normalized difference between TVAL and the left\n! endpoint of the interval.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 February 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) LEFT, indicats that TVAL is in the interval\n! [ TDATA(LEFT), TDATA(LEFT+1) ], or that this is the \"nearest\"\n! interval to TVAL.\n! For TVAL < TDATA(1), use LEFT = 1.\n! For TDATA(NDATA) < TVAL, use LEFT = NDATA - 1.\n!\n! Input, integer ( kind = 4 ) N, the order of the basis matrix.\n!\n! Input, real ( kind = 8 ) MBASIS(N,N), the basis matrix.\n!\n! Input, integer ( kind = 4 ) NDATA, the dimension of the vectors TDATA\n! and YDATA.\n!\n! Input, real ( kind = 8 ) TDATA(NDATA), the abscissa values. This routine\n! assumes that the TDATA values are uniformly spaced, with an\n! increment of 1.0.\n!\n! Input, real ( kind = 8 ) YDATA(NDATA), the data values to be\n! interpolated or approximated.\n!\n! Input, real ( kind = 8 ) TVAL, the value of T at which the spline is to be\n! evaluated.\n!\n! Output, real ( kind = 8 ) YVAL, the value of the spline at TVAL.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: maxn = 4\n integer ( kind = 4 ) n\n integer ( kind = 4 ) ndata\n\n real ( kind = 8 ) arg\n integer ( kind = 4 ) first\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n integer ( kind = 4 ) left\n real ( kind = 8 ) mbasis(n,n)\n real ( kind = 8 ) tdata(ndata)\n real ( kind = 8 ) tval\n real ( kind = 8 ) tvec(maxn)\n real ( kind = 8 ) ydata(ndata)\n real ( kind = 8 ) yval\n\n if ( left == 1 ) then\n arg = 0.5D+00 * ( tval - tdata(left) )\n first = left\n else if ( left < ndata - 1 ) then\n arg = tval - tdata(left)\n first = left - 1\n else if ( left == ndata - 1 ) then\n arg = 0.5D+00 * ( 1.0D+00 + tval - tdata(left) )\n first = left - 1\n end if\n!\n! TVEC(I) = ARG^(N-I).\n!\n tvec(n) = 1.0D+00\n do i = n-1, 1, -1\n tvec(i) = arg * tvec(i+1)\n end do\n\n yval = 0.0D+00\n do j = 1, n\n yval = yval + dot_product ( tvec(1:n), mbasis(1:n,j) ) &\n * ydata(first - 1 + j)\n end do\n\n return\nend\nsubroutine bc_val ( n, t, xcon, ycon, xval, yval )\n\n!*****************************************************************************80\n!\n!! BC_VAL evaluates a parameterized N-th degree Bezier curve in 2D.\n!\n! Discussion:\n!\n! BC_VAL(T) is the value of a vector function of the form\n!\n! BC_VAL(T) = ( X(T), Y(T) )\n!\n! where\n!\n! X(T) = sum ( 0 <= I <= N ) XCON(I) * BERN(I,N)(T)\n! Y(T) = sum ( 0 <= I <= N ) YCON(I) * BERN(I,N)(T)\n!\n! BERN(I,N)(T) is the I-th Bernstein polynomial of order N\n! defined on the interval [0,1],\n!\n! XCON(0:N) and YCON(0:N) are the coordinates of N+1 \"control points\".\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! David Kahaner, Cleve Moler, Steven Nash,\n! Numerical Methods and Software,\n! Prentice Hall, 1989,\n! ISBN: 0-13-627258-4,\n! LC: TA345.K34.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the degree of the Bezier curve.\n! N must be at least 0.\n!\n! Input, real ( kind = 8 ) T, the point at which the Bezier curve should\n! be evaluated. The best results are obtained within the interval\n! [0,1] but T may be anywhere.\n!\n! Input, real ( kind = 8 ) XCON(0:N), YCON(0:N), the X and Y coordinates\n! of the control points. The Bezier curve will pass through\n! the points ( XCON(0), YCON(0) ) and ( XCON(N), YCON(N) ), but\n! generally NOT through the other control points.\n!\n! Output, real ( kind = 8 ) XVAL, YVAL, the X and Y coordinates of the point\n! on the Bezier curve corresponding to the given T value.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) bval(0:n)\n real ( kind = 8 ) t\n real ( kind = 8 ) xcon(0:n)\n real ( kind = 8 ) xval\n real ( kind = 8 ) ycon(0:n)\n real ( kind = 8 ) yval\n\n call bp01 ( n, t, bval )\n\n xval = dot_product ( xcon(0:n), bval(0:n) )\n yval = dot_product ( ycon(0:n), bval(0:n) )\n\n return\nend\nfunction bez_val ( n, x, a, b, y )\n\n!*****************************************************************************80\n!\n!! BEZ_VAL evaluates an N-th degree Bezier function at a point.\n!\n! Discussion:\n!\n! The Bezier function has the form:\n!\n! BEZ(X) = sum ( 0 <= I <= N ) Y(I) * BERN(N,I)( (X-A)/(B-A) )\n!\n! BERN(N,I)(X) is the I-th Bernstein polynomial of order N\n! defined on the interval [0,1],\n!\n! Y(0:N) is a set of coefficients,\n!\n! and if, for I = 0 to N, we define the N+1 points\n!\n! X(I) = ( (N-I)*A + I*B) / N,\n!\n! equally spaced in [A,B], the pairs ( X(I), Y(I) ) can be regarded as\n! \"control points\".\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! David Kahaner, Cleve Moler, Steven Nash,\n! Numerical Methods and Software,\n! Prentice Hall, 1989,\n! ISBN: 0-13-627258-4,\n! LC: TA345.K34.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the degree of the Bezier function.\n! N must be at least 0.\n!\n! Input, real ( kind = 8 ) X, the point at which the Bezier function should\n! be evaluated. The best results are obtained within the interval\n! [A,B] but X may be anywhere.\n!\n! Input, real ( kind = 8 ) A, B, the interval over which the Bezier function\n! has been defined. This is the interval in which the control\n! points have been set up. Note BEZ(A) = Y(0) and BEZ(B) = Y(N),\n! although BEZ will not, in general pass through the other\n! control points. A and B must not be equal.\n!\n! Input, real ( kind = 8 ) Y(0:N), a set of data defining the Y coordinates\n! of the control points.\n!\n! Output, real ( kind = 8 ) BEZ_VAL, the value of the Bezier function at X.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) bez_val\n real ( kind = 8 ) bval(0:n)\n real ( kind = 8 ) x\n real ( kind = 8 ) x01\n real ( kind = 8 ) y(0:n)\n\n if ( b - a == 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BEZ_VAL - Fatal error!'\n write ( *, '(a,g14.6)' ) ' Null interval, A = B = ', a\n stop 1\n end if\n!\n! X01 lies in [0,1], in the same relative position as X in [A,B].\n!\n x01 = ( x - a ) / ( b - a )\n\n call bp01 ( n, x01, bval )\n\n bez_val = dot_product ( y(0:n), bval(0:n) )\n\n return\nend\nsubroutine bp01 ( n, x, bern )\n\n!*****************************************************************************80\n!\n!! BP01 evaluates the Bernstein basis polynomials for [0,1] at a point.\n!\n! Discussion:\n!\n! For any N greater than or equal to 0, there is a set of N+1 Bernstein\n! basis polynomials, each of degree N, which form a basis for\n! all polynomials of degree N on [0,1].\n!\n! BERN(N,I,X) = [N!/(I!*(N-I)!)] * (1-X)^(N-I) * X^I\n!\n! N is the degree;\n!\n! 0 <= I <= N indicates which of the N+1 basis polynomials\n! of degree N to choose;\n!\n! X is a point in [0,1] at which to evaluate the basis polynomial.\n!\n! First values:\n!\n! B(0,0,X) = 1\n!\n! B(1,0,X) = 1-X\n! B(1,1,X) = X\n!\n! B(2,0,X) = (1-X)^2\n! B(2,1,X) = 2 * (1-X) * X\n! B(2,2,X) = X^2\n!\n! B(3,0,X) = (1-X)^3\n! B(3,1,X) = 3 * (1-X)^2 * X\n! B(3,2,X) = 3 * (1-X) * X^2\n! B(3,3,X) = X^3\n!\n! B(4,0,X) = (1-X)^4\n! B(4,1,X) = 4 * (1-X)^3 * X\n! B(4,2,X) = 6 * (1-X)^2 * X^2\n! B(4,3,X) = 4 * (1-X) * X^3\n! B(4,4,X) = X^4\n!\n! Special values:\n!\n! B(N,I,1/2) = C(N,K) / 2^N\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! David Kahaner, Cleve Moler, Steven Nash,\n! Numerical Methods and Software,\n! Prentice Hall, 1989,\n! ISBN: 0-13-627258-4,\n! LC: TA345.K34.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the degree of the Bernstein basis\n! polynomials. N must be at least 0.\n!\n! Input, real ( kind = 8 ) X, the evaluation point.\n!\n! Output, real ( kind = 8 ) BERN(0:N), the values of the N+1 Bernstein basis\n! polynomials at X.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) bern(0:n)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n real ( kind = 8 ) x\n\n if ( n == 0 ) then\n\n bern(0) = 1.0D+00\n\n else if ( 0 < n ) then\n\n bern(0) = 1.0D+00 - x\n bern(1) = x\n\n do i = 2, n\n bern(i) = x * bern(i-1)\n do j = i-1, 1, -1\n bern(j) = x * bern(j-1) + ( 1.0D+00 - x ) * bern(j)\n end do\n bern(0) = ( 1.0D+00 - x ) * bern(0)\n end do\n\n end if\n\n return\nend\nsubroutine bpab ( n, a, b, x, bern )\n\n!*****************************************************************************80\n!\n!! BPAB evaluates the Bernstein basis polynomials for [A,B] at a point.\n!\n! Discussion:\n!\n! BERN(N,I,X) = [N!/(I!*(N-I)!)] * (B-X)^(N-I) * (X-A)^I / (B-A)^N\n!\n! B(0,0,X) = 1\n!\n! B(1,0,X) = ( B-X ) / (B-A)\n! B(1,1,X) = ( X-A ) / (B-A)\n!\n! B(2,0,X) = ( (B-X)^2 ) / (B-A)^2\n! B(2,1,X) = ( 2 * (B-X * (X-A) ) / (B-A)^2\n! B(2,2,X) = ( (X-A)^2 ) / (B-A)^2\n!\n! B(3,0,X) = ( (B-X)^3 ) / (B-A)^3\n! B(3,1,X) = ( 3 * (B-X)^2 * (X-A) ) / (B-A)^3\n! B(3,2,X) = ( 3 * (B-X) * (X-A)^2 ) / (B-A)^3\n! B(3,3,X) = ( (X-A)^3 ) / (B-A)^3\n!\n! B(4,0,X) = ( (B-X)^4 ) / (B-A)^4\n! B(4,1,X) = ( 4 * (B-X)^3 * (X-A) ) / (B-A)^4\n! B(4,2,X) = ( 6 * (B-X)^2 * (X-A)^2 ) / (B-A)^4\n! B(4,3,X) = ( 4 * (B-X) * (X-A)^3 ) / (B-A)^4\n! B(4,4,X) = ( (X-A)^4 ) / (B-A)^4\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! David Kahaner, Cleve Moler, Steven Nash,\n! Numerical Methods and Software,\n! Prentice Hall, 1989,\n! ISBN: 0-13-627258-4,\n! LC: TA345.K34.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the degree of the Bernstein basis\n! polynomials. There is a set of N+1 Bernstein basis polynomials, each\n! of degree N, which form a basis for polynomials of degree N on [A,B].\n! N must be at least 0.\n!\n! Input, real ( kind = 8 ) A, B, the endpoints of the interval on which the\n! polynomials are to be based. A and B should not be equal.\n! Input, real ( kind = 8 ) X, the point at which the polynomials are to be\n! evaluated. X need not lie in the interval [A,B].\n!\n! Output, real ( kind = 8 ) BERN(0:N), the values of the N+1 Bernstein basis\n! polynomials at X.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) bern(0:n)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n real ( kind = 8 ) x\n\n if ( b == a ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BPAB - Fatal error!'\n write ( *, '(a,g14.6)' ) ' A = B = ', a\n stop 1\n end if\n\n if ( n == 0 ) then\n\n bern(0) = 1.0D+00\n\n else if ( 0 < n ) then\n\n bern(0) = ( b - x ) / ( b - a )\n bern(1) = ( x - a ) / ( b - a )\n\n do i = 2, n\n bern(i) = ( x - a ) * bern(i-1) / ( b - a )\n do j = i-1, 1, -1\n bern(j) = ( ( b - x ) * bern(j) + ( x - a ) * bern(j-1) ) / ( b - a )\n end do\n bern(0) = ( b - x ) * bern(0) / ( b - a )\n end do\n\n end if\n\n return\nend\nsubroutine bpab_approx ( n, a, b, ydata, xval, yval )\n\n!*****************************************************************************80\n!\n!! BPAB_APPROX evaluates the Bernstein polynomial approximant to F(X) on [A,B].\n!\n! Formula:\n!\n! BERN(F)(X) = sum ( 0 <= I <= N ) F(X(I)) * B_BASE(I,X)\n!\n! where\n!\n! X(I) = ( ( N - I ) * A + I * B ) / N\n! B_BASE(I,X) is the value of the I-th Bernstein basis polynomial at X.\n!\n! Discussion:\n!\n! The Bernstein polynomial BERN(F) for F(X) is an approximant, not an\n! interpolant; in other words, its value is not guaranteed to equal\n! that of F at any particular point. However, for a fixed interval\n! [A,B], if we let N increase, the Bernstein polynomial converges\n! uniformly to F everywhere in [A,B], provided only that F is continuous.\n! Even if F is not continuous, but is bounded, the polynomial converges\n! pointwise to F(X) at all points of continuity. On the other hand,\n! the convergence is quite slow compared to other interpolation\n! and approximation schemes.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! David Kahaner, Cleve Moler, Steven Nash,\n! Numerical Methods and Software,\n! Prentice Hall, 1989,\n! ISBN: 0-13-627258-4,\n! LC: TA345.K34.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the degree of the Bernstein polynomial\n! to be used. N must be at least 0.\n!\n! Input, real ( kind = 8 ) A, B, the endpoints of the interval on which the\n! approximant is based. A and B should not be equal.\n!\n! Input, real ( kind = 8 ) YDATA(0:N), the data values at N+1 equally\n! spaced points in [A,B]. If N = 0, then the evaluation point should\n! be 0.5 * ( A + B). Otherwise, evaluation point I should be\n! ( (N-I)*A + I*B ) / N ).\n!\n! Input, real ( kind = 8 ) XVAL, the point at which the Bernstein polynomial\n! approximant is to be evaluated. XVAL does not have to lie in the\n! interval [A,B].\n!\n! Output, real ( kind = 8 ) YVAL, the value of the Bernstein polynomial\n! approximant for F, based in [A,B], evaluated at XVAL.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) bvec(0:n)\n real ( kind = 8 ) xval\n real ( kind = 8 ) ydata(0:n)\n real ( kind = 8 ) yval\n!\n! Evaluate the Bernstein basis polynomials at XVAL.\n!\n call bpab ( n, a, b, xval, bvec )\n!\n! Now compute the sum of YDATA(I) * BVEC(I).\n!\n yval = dot_product ( ydata(0:n), bvec(0:n) )\n\n return\nend\nsubroutine chfev ( x1, x2, f1, f2, d1, d2, ne, xe, fe, next, ierr )\n\n!*****************************************************************************80\n!\n!! CHFEV evaluates a cubic polynomial given in Hermite form.\n!\n! Discussion:\n!\n! This routine evaluates a cubic polynomial given in Hermite form at an\n! array of points. While designed for use by SPLINE_PCHIP_VAL, it may\n! be useful directly as an evaluator for a piecewise cubic\n! Hermite function in applications, such as graphing, where\n! the interval is known in advance.\n!\n! The cubic polynomial is determined by function values\n! F1, F2 and derivatives D1, D2 on the interval [X1,X2].\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 25 June 2008\n!\n! Author:\n!\n! Original FORTRAN77 version by Fred Fritsch.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! Fred Fritsch, Ralph Carlson,\n! Monotone Piecewise Cubic Interpolation,\n! SIAM Journal on Numerical Analysis,\n! Volume 17, Number 2, April 1980, pages 238-246.\n!\n! David Kahaner, Cleve Moler, Steven Nash,\n! Numerical Methods and Software,\n! Prentice Hall, 1989,\n! ISBN: 0-13-627258-4,\n! LC: TA345.K34.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X1, X2, the endpoints of the interval of\n! definition of the cubic. X1 and X2 must be distinct.\n!\n! Input, real ( kind = 8 ) F1, F2, the values of the function at X1 and\n! X2, respectively.\n!\n! Input, real ( kind = 8 ) D1, D2, the derivative values at X1 and\n! X2, respectively.\n!\n! Input, integer ( kind = 4 ) NE, the number of evaluation points.\n!\n! Input, real ( kind = 8 ) XE(NE), the points at which the function is to\n! be evaluated. If any of the XE are outside the interval\n! [X1,X2], a warning error is returned in NEXT.\n!\n! Output, real ( kind = 8 ) FE(NE), the value of the cubic function\n! at the points XE.\n!\n! Output, integer ( kind = 4 ) NEXT(2), indicates the number of\n! extrapolation points:\n! NEXT(1) = number of evaluation points to the left of interval.\n! NEXT(2) = number of evaluation points to the right of interval.\n!\n! Output, integer ( kind = 4 ) IERR, error flag.\n! 0, no errors.\n! -1, NE < 1.\n! -2, X1 == X2.\n!\n implicit none\n\n integer ( kind = 4 ) ne\n\n real ( kind = 8 ) c2\n real ( kind = 8 ) c3\n real ( kind = 8 ) d1\n real ( kind = 8 ) d2\n real ( kind = 8 ) del1\n real ( kind = 8 ) del2\n real ( kind = 8 ) delta\n real ( kind = 8 ) f1\n real ( kind = 8 ) f2\n real ( kind = 8 ) fe(ne)\n real ( kind = 8 ) h\n integer ( kind = 4 ) i\n integer ( kind = 4 ) ierr\n integer ( kind = 4 ) next(2)\n real ( kind = 8 ) x\n real ( kind = 8 ) x1\n real ( kind = 8 ) x2\n real ( kind = 8 ) xe(ne)\n real ( kind = 8 ) xma\n real ( kind = 8 ) xmi\n\n if ( ne < 1 ) then\n ierr = -1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CHFEV - Fatal error!'\n write ( *, '(a)' ) ' Number of evaluation points is less than 1.'\n write ( *, '(a,i8)' ) ' NE = ', ne\n stop 1\n end if\n\n h = x2 - x1\n\n if ( h == 0.0D+00 ) then\n ierr = -2\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CHFEV - Fatal error!'\n write ( *, '(a)' ) ' The interval [X1,X2] is of zero length.'\n stop 1\n end if\n!\n! Initialize.\n!\n ierr = 0\n next(1) = 0\n next(2) = 0\n xmi = min ( 0.0D+00, h )\n xma = max ( 0.0D+00, h )\n!\n! Compute cubic coefficients expanded about X1.\n!\n delta = ( f2 - f1 ) / h\n del1 = ( d1 - delta ) / h\n del2 = ( d2 - delta ) / h\n c2 = -( del1 + del1 + del2 )\n c3 = ( del1 + del2 ) / h\n!\n! Evaluation loop.\n!\n do i = 1, ne\n\n x = xe(i) - x1\n fe(i) = f1 + x * ( d1 + x * ( c2 + x * c3 ) )\n!\n! Count the extrapolation points.\n!\n if ( x < xmi ) then\n next(1) = next(1) + 1\n end if\n\n if ( xma < x ) then\n next(2) = next(2) + 1\n end if\n\n end do\n\n return\nend\nsubroutine data_to_dif ( ntab, xtab, ytab, diftab )\n\n!*****************************************************************************80\n!\n!! DATA_TO_DIF sets up a divided difference table from raw data.\n!\n! Discussion:\n!\n! Space can be saved by using a single array for both the DIFTAB and\n! YTAB dummy parameters. In that case, the divided difference table will\n! overwrite the Y data without interfering with the computation.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 04 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Carl deBoor,\n! A Practical Guide to Splines,\n! Springer, 2001,\n! ISBN: 0387953663.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NTAB, the number of pairs of points\n! (XTAB(I),YTAB(I)) which are to be used as data. The\n! number of entries to be used in DIFTAB, XTAB and YTAB.\n!\n! Input, real ( kind = 8 ) XTAB(NTAB), the X values at which data was taken.\n! These values must be distinct.\n!\n! Input, real ( kind = 8 ) YTAB(NTAB), the corresponding Y values.\n!\n! Output, real ( kind = 8 ) DIFTAB(NTAB), the divided difference coefficients\n! corresponding to the input (XTAB,YTAB).\n!\n implicit none\n\n integer ( kind = 4 ) ntab\n\n real ( kind = 8 ) diftab(ntab)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n logical r8vec_distinct\n real ( kind = 8 ) xtab(ntab)\n real ( kind = 8 ) ytab(ntab)\n\n if ( .not. r8vec_distinct ( ntab, xtab ) ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DATA_TO_DIF - Fatal error!'\n write ( *, '(a)' ) ' Two entries of XTAB are equal!'\n return\n end if\n!\n! Copy the data values into DIFTAB.\n!\n diftab(1:ntab) = ytab(1:ntab)\n!\n! Compute the divided differences.\n!\n do i = 2, ntab\n do j = ntab, i, -1\n\n diftab(j) = ( diftab(j) - diftab(j-1) ) / ( xtab(j) - xtab(j+1-i) )\n\n end do\n end do\n\n return\nend\nsubroutine dif_val ( ntab, xtab, diftab, xval, yval )\n\n!*****************************************************************************80\n!\n!! DIF_VAL evaluates a divided difference polynomial at a point.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Carl deBoor,\n! A Practical Guide to Splines,\n! Springer, 2001,\n! ISBN: 0387953663.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NTAB, the number of divided difference\n! coefficients in DIFTAB, and the number of points XTAB.\n!\n! Input, real ( kind = 8 ) XTAB(NTAB), the X values upon which the\n! divided difference polynomial is based.\n!\n! Input, real ( kind = 8 ) DIFTAB(NTAB), the divided difference\n! polynomial coefficients.\n!\n! Input, real ( kind = 8 ) XVAL, the value where the polynomial\n! is to be evaluated.\n!\n! Output, real ( kind = 8 ) YVAL, the value of the polynomial at XVAL.\n!\n implicit none\n\n integer ( kind = 4 ) ntab\n\n real ( kind = 8 ) diftab(ntab)\n integer ( kind = 4 ) i\n real ( kind = 8 ) xtab(ntab)\n real ( kind = 8 ) xval\n real ( kind = 8 ) yval\n\n yval = diftab(ntab)\n do i = 1, ntab-1\n yval = diftab(ntab-i) + ( xval - xtab(ntab-i) ) * yval\n end do\n\n return\nend\nsubroutine least_set_old ( ntab, xtab, ytab, ndeg, ptab, b, c, d, eps, ierror )\n\n!*****************************************************************************80\n!\n!! LEAST_SET_OLD constructs the least squares polynomial approximation to data.\n!\n! Discussion:\n!\n! The least squares polynomial is not returned directly as a simple\n! polynomial. Instead, it is represented in terms of a set of\n! orthogonal polynomials appopriate for the given data. This makes\n! the computation more accurate, but means that the user can not\n! easily evaluate the computed polynomial. Instead, the routine\n! LEAST_EVAL should be used to evaluate the least squares polynomial\n! at any point. (However, the value of the least squares polynomial\n! at each of the data points is returned as part of this computation.)\n!\n!\n! A discrete unweighted inner product is used, so that\n!\n! ( F(X), G(X) ) = sum ( 1 <= I <= NTAB ) F(XTAB(I)) * G(XTAB(I)).\n!\n! The least squares polynomial is determined using a set of\n! orthogonal polynomials PHI. These polynomials can be defined\n! recursively by:\n!\n! PHI(0)(X) = 1\n! PHI(1)(X) = X - B(1)\n! PHI(I)(X) = ( X - B(I) ) * PHI(I-1)(X) - D(I) * PHI(I-2)(X)\n!\n! The array B(1:NDEG) contains the values\n!\n! B(I) = ( X*PHI(I-1), PHI(I-1) ) / ( PHI(I-1), PHI(I-1) )\n!\n! The array D(2:NDEG) contains the values\n!\n! D(I) = ( PHI(I-1), PHI(I-1) ) / ( PHI(I-2), PHI(I-2) )\n!\n! Using this basis, the least squares polynomial can be represented as\n!\n! P(X)(I) = sum ( 0 <= I <= NDEG ) C(I) * PHI(I)(X)\n!\n! The array C(0:NDEG) contains the values\n!\n! C(I) = ( YTAB(I), PHI(I) ) / ( PHI(I), PHI(I) )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 May 2004\n!\n! Author:\n!\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! Gisela Engeln-Muellges, Frank Uhlig,\n! Numerical Algorithms with C,\n! Springer, 1996,\n! ISBN: 3-540-60530-4.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NTAB, the number of data points.\n!\n! Input, real ( kind = 8 ) XTAB(NTAB), the X data. The values in XTAB\n! should be distinct, and in increasing order.\n!\n! Input, real ( kind = 8 ) YTAB(NTAB), the Y data values corresponding\n! to the X data in XTAB.\n!\n! Input, integer ( kind = 4 ) NDEG, the degree of the polynomial which the\n! program is to use. NDEG must be at least 0, and less than or\n! equal to NTAB-1.\n!\n! Output, real ( kind = 8 ) PTAB(NTAB), the value of the least\n! squares polynomial at the points XTAB(1:NTAB).\n!\n! Output, real ( kind = 8 ) B(1:NDEG), C(0:NDEG), D(2:NDEG), arrays\n! needed to evaluate the polynomial.\n!\n! Output, real ( kind = 8 ) EPS, the root-mean-square discrepancy of the\n! polynomial fit.\n!\n! Output, integer ( kind = 4 ) IERROR, error flag.\n! zero, no error occurred;\n! nonzero, an error occurred, and the polynomial could not be computed.\n!\n implicit none\n\n integer ( kind = 4 ) ndeg\n integer ( kind = 4 ) ntab\n\n real ( kind = 8 ) b(1:ndeg)\n real ( kind = 8 ) c(0:ndeg)\n real ( kind = 8 ) d(2:ndeg)\n real ( kind = 8 ) eps\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i0l1\n integer ( kind = 4 ) i1l1\n integer ( kind = 4 ) ierror\n integer ( kind = 4 ) it\n integer ( kind = 4 ) k\n integer ( kind = 4 ) mdeg\n real ( kind = 8 ) ptab(ntab)\n real ( kind = 8 ) rn0\n real ( kind = 8 ) rn1\n real ( kind = 8 ) s\n real ( kind = 8 ) sum2\n real ( kind = 8 ) xtab(ntab)\n real ( kind = 8 ) y_sum\n real ( kind = 8 ) ytab(ntab)\n real ( kind = 8 ) ztab(2*ntab)\n\n ierror = 0\n!\n! Check NDEG.\n!\n if ( ndeg < 0 ) then\n ierror = 1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LEAST_SET_OLD - Fatal error!'\n write ( *, '(a)' ) ' NDEG < 0.'\n stop 1\n end if\n\n if ( ntab <= ndeg ) then\n ierror = 1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LEAST_SET_OLD - Fatal error!'\n write ( *, '(a)' ) ' NTAB <= NDEG.'\n stop 1\n end if\n!\n! Check that the abscissas are strictly increasing.\n!\n do i = 1, ntab-1\n if ( xtab(i+1) <= xtab(i) ) then\n ierror = 1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LEAST_SET_OLD - Fatal error!'\n write ( *, '(a)' ) ' XTAB must be strictly increasing, but'\n write ( *, '(a,i8,a,g14.6)' ) ' XTAB(', i, ') = ', xtab(i)\n write ( *, '(a,i8,a,g14.6)' ) ' XTAB(', i+1, ') = ', xtab(i+1)\n stop 1\n end if\n end do\n\n i0l1 = 0\n i1l1 = ntab\n!\n! The polynomial is of degree at least 0.\n!\n y_sum = sum ( ytab(1:ntab) )\n rn0 = ntab\n c(0) = y_sum / real ( ntab, kind = 8 )\n\n ptab(1:ntab) = y_sum / real ( ntab, kind = 8 )\n\n if ( ndeg == 0 ) then\n eps = sum ( ( ptab(1:ntab) - ytab(1:ntab) )**2 )\n eps = sqrt ( eps / real ( ntab, kind = 8 ) )\n return\n end if\n!\n! The polynomial is of degree at least 1.\n!\n b(1) = sum ( xtab(1:ntab) ) / real ( ntab, kind = 8 )\n\n s = 0.0D+00\n sum2 = 0.0D+00\n do i = 1, ntab\n ztab(i1l1+i) = xtab(i) - b(1)\n s = s + ztab(i1l1+i)**2\n sum2 = sum2 + ztab(i1l1+i) * ( ytab(i) - ptab(i) )\n end do\n\n rn1 = s\n c(1) = sum2 / s\n\n do i = 1, ntab\n ptab(i) = ptab(i) + c(1) * ztab(i1l1+i)\n end do\n\n if ( ndeg == 1 ) then\n eps = sum ( ( ptab(1:ntab) - ytab(1:ntab) )**2 )\n eps = sqrt ( eps / real ( ntab, kind = 8 ) )\n return\n end if\n\n ztab(1:ntab) = 1.0D+00\n\n mdeg = 2\n k = 2\n\n do\n\n d(k) = rn1 / rn0\n\n sum2 = 0.0D+00\n do i = 1, ntab\n sum2 = sum2 + xtab(i) * ztab(i1l1+i) * ztab(i1l1+i)\n end do\n\n b(k) = sum2 / rn1\n\n s = 0.0D+00\n sum2 = 0.0D+00\n do i = 1, ntab\n ztab(i0l1+i) = ( xtab(i) - b(k) ) * ztab(i1l1+i) &\n - d(k) * ztab(i0l1+i)\n s = s + ztab(i0l1+i) * ztab(i0l1+i)\n sum2 = sum2 + ztab(i0l1+i) * ( ytab(i) - ptab(i) )\n end do\n\n rn0 = rn1\n rn1 = s\n\n c(k) = sum2 / rn1\n\n it = i0l1\n i0l1 = i1l1\n i1l1 = it\n\n do i = 1, ntab\n ptab(i) = ptab(i) + c(k) * ztab(i1l1+i)\n end do\n\n if ( ndeg <= mdeg ) then\n exit\n end if\n\n mdeg = mdeg + 1\n k = k + 1\n\n end do\n!\n! Compute the RMS error.\n!\n eps = sum ( ( ptab(1:ntab) - ytab(1:ntab) )**2 )\n eps = sqrt ( eps / real ( ntab, kind = 8 ) )\n\n return\nend\nsubroutine least_val_old ( x, ndeg, b, c, d, value )\n\n!*****************************************************************************80\n!\n!! LEAST_VAL_OLD evaluates a least squares polynomial defined by LEAST_SET_OLD.\n!\n! Discussion:\n!\n! This is an \"old\" version of the routine.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 May 2004\n!\n! Author:\n!\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! Gisela Engeln-Muellges, Frank Uhlig,\n! Numerical Algorithms with C,\n! Springer, 1996,\n! ISBN: 3-540-60530-4.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the point at which the polynomial is\n! to be evaluated.\n!\n! Input, integer ( kind = 4 ) NDEG, the degree of the least squares\n! polynomial.\n!\n! Input, real ( kind = 8 ) B(1:NDEG), C(0:NDEG), D(2:NDEG), arrays\n! defined by LEAST_SET_OLD, and needed to evaluate the polynomial.\n!\n! Output, real ( kind = 8 ) VALUE, the value of the polynomial at X.\n!\n implicit none\n\n integer ( kind = 4 ) ndeg\n\n real ( kind = 8 ) b(1:ndeg)\n real ( kind = 8 ) c(0:ndeg)\n real ( kind = 8 ) d(2:ndeg)\n integer ( kind = 4 ) k\n real ( kind = 8 ) sk\n real ( kind = 8 ) skp1\n real ( kind = 8 ) skp2\n real ( kind = 8 ) value\n real ( kind = 8 ) x\n\n if ( ndeg <= 0 ) then\n\n value = c(0)\n\n else if ( ndeg == 1 ) then\n\n value = c(0) + c(1) * ( x - b(1) )\n\n else\n\n skp2 = c(ndeg)\n skp1 = c(ndeg-1) + ( x - b(ndeg) ) * skp2\n\n do k = ndeg-2, 0, -1\n sk = c(k) + ( x - b(k+1) ) * skp1 - d(k+2) * skp2\n skp2 = skp1\n skp1 = sk\n end do\n\n value = sk\n\n end if\n\n return\nend\nsubroutine least_set ( point_num, x, f, w, nterms, b, c, d )\n\n!*****************************************************************************80\n!\n!! LEAST_SET defines a least squares polynomial for given data.\n!\n! Discussion:\n!\n! This routine is based on ORTPOL by Conte and deBoor.\n!\n! The polynomial may be evaluated at any point X by calling LEAST_VAL.\n!\n! Thanks to Andrew Telford for pointing out a mistake in the form of\n! the check that there are enough unique data points, 25 June 2008.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 25 June 2008\n!\n! Author:\n!\n! Original FORTRAN77 version by Samuel Conte, Carl deBoor.\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! Samuel Conte, Carl deBoor,\n! Elementary Numerical Analysis,\n! Second Edition,\n! McGraw Hill, 1972,\n! ISBN: 07-012446-4,\n! LC: QA297.C65.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) POINT_NUM, the number of data values.\n!\n! Input, real ( kind = 8 ) X(POINT_NUM), the abscissas of the data points.\n! At least NTERMS of the values in X must be distinct.\n!\n! Input, real ( kind = 8 ) F(POINT_NUM), the data values at the points X(*).\n!\n! Input, real ( kind = 8 ) W(POINT_NUM), the weights associated with\n! the data points. Each entry of W should be positive.\n!\n! Input, integer ( kind = 4 ) NTERMS, the number of terms to use in the\n! approximating polynomial. NTERMS must be at least 1.\n! The degree of the polynomial is NTERMS-1.\n!\n! Output, real ( kind = 8 ) B(NTERMS), C(NTERMS), D(NTERMS), are quantities\n! defining the least squares polynomial for the input data,\n! which will be needed to evaluate the polynomial.\n!\n implicit none\n\n integer ( kind = 4 ) point_num\n integer ( kind = 4 ) nterms\n\n real ( kind = 8 ) b(nterms)\n real ( kind = 8 ) c(nterms)\n real ( kind = 8 ) d(nterms)\n real ( kind = 8 ) f(point_num)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n real ( kind = 8 ) p\n real ( kind = 8 ) pj(point_num)\n real ( kind = 8 ) pjm1(point_num)\n real ( kind = 8 ) s(nterms)\n real ( kind = 8 ), parameter :: tol = 0.0D+00\n integer ( kind = 4 ) unique_num\n real ( kind = 8 ) w(point_num)\n real ( kind = 8 ) x(point_num)\n!\n! Make sure at least NTERMS X values are unique.\n!\n call r8vec_unique_count ( point_num, x, tol, unique_num )\n\n if ( unique_num < nterms ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LEAST_SET - Fatal error!'\n write ( *, '(a)' ) ' The number of distinct X values must be'\n write ( *, '(a,i8)') ' at least NTERMS = ', nterms\n write ( *, '(a,i8)' ) ' but the input data has only ', unique_num\n write ( *, '(a)' ) ' distinct entries.'\n return\n end if\n!\n! Make sure all W entries are positive.\n!\n do i = 1, point_num\n if ( w(i) <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LEAST_SET - Fatal error!'\n write ( *, '(a)' ) ' All weights W must be positive,'\n write ( *, '(a,i8)' ) ' but weight ', i\n write ( *, '(a,g14.6)' ) ' is ', w(i)\n return\n end if\n end do\n!\n! Start inner product summations at zero.\n!\n b(1:nterms) = 0.0D+00\n c(1:nterms) = 0.0D+00\n d(1:nterms) = 0.0D+00\n s(1:nterms) = 0.0D+00\n!\n! Set the values of P(-1,X) and P(0,X) at all data points.\n!\n pjm1(1:point_num) = 0.0D+00\n pj(1:point_num) = 1.0D+00\n!\n! Now compute the value of P(J,X(I)) as\n!\n! P(J,X(I)) = ( X(I) - B(J) ) * P(J-1,X(I)) - C(J) * P(J-2,X(I))\n!\n! where\n!\n! S(J) = < P(J,X), P(J,X) >\n! B(J) = < x*P(J,X), P(J,X) > / < P(J,X), P(J,X) >\n! C(J) = S(J) / S(J-1)\n!\n! and the least squares coefficients are\n!\n! D(J) = < F(X), P(J,X) > / < P(J,X), P(J,X) >\n!\n do j = 1, nterms\n\n d(j) = d(j) + sum ( w(1:point_num) * f(1:point_num) * pj(1:point_num) )\n b(j) = b(j) + sum ( w(1:point_num) * x(1:point_num) * pj(1:point_num)**2 )\n s(j) = s(j) + sum ( w(1:point_num) * pj(1:point_num)**2 )\n\n d(j) = d(j) / s(j)\n\n if ( j == nterms ) then\n c(j) = 0.0D+00\n return\n end if\n\n b(j) = b(j) / s(j)\n\n if ( j == 1 ) then\n c(j) = 0.0D+00\n else\n c(j) = s(j) / s(j-1)\n end if\n\n do i = 1, point_num\n p = pj(i)\n pj(i) = ( x(i) - b(j) ) * pj(i) - c(j) * pjm1(i)\n pjm1(i) = p\n end do\n\n end do\n\n return\nend\nsubroutine least_val ( nterms, b, c, d, x, px )\n\n!*****************************************************************************80\n!\n!! LEAST_VAL evaluates a least squares polynomial defined by LEAST_SET.\n!\n! Discussion:\n!\n! The least squares polynomial is assumed to be defined as a sum\n!\n! P(X) = sum ( 1 <= I <= NTERMS ) D(I) * P(I-1,X)\n!\n! where the orthogonal basis polynomials P(I,X) satisfy the following\n! three term recurrence:\n!\n! P(-1,X) = 0\n! P(0,X) = 1\n! P(I,X) = ( X - B(I-1) ) * P(I-1,X) - C(I-1) * P(I-2,X)\n!\n! Therefore, the least squares polynomial can be evaluated as follows:\n!\n! If NTERMS is 1, then the value of P(X) is D(1) * P(0,X) = D(1).\n!\n! Otherwise, P(X) is defined as the sum of NTERMS > 1 terms. We can\n! reduce the number of terms by 1, because the polynomial P(NTERMS,X)\n! can be rewritten as a sum of polynomials; Therefore, P(NTERMS,X)\n! can be eliminated from the sum, and its coefficient merged in with\n! those of other polynomials. Repeat this process for P(NTERMS-1,X)\n! and so on until a single term remains.\n! P(NTERMS,X) of P(NTERMS-1,X)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 May 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Samuel Conte, Carl deBoor,\n! Elementary Numerical Analysis,\n! Second Edition,\n! McGraw Hill, 1972,\n! ISBN: 07-012446-4,\n! LC: QA297.C65.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NTERMS, the number of terms in the least\n! squares polynomial. NTERMS must be at least 1. The input value of NTERMS\n! may be reduced from the value given to LEAST_SET. This will\n! evaluate the least squares polynomial of the lower degree specified.\n!\n! Input, real ( kind = 8 ) B(NTERMS), C(NTERMS), D(NTERMS), the information\n! computed by LEAST_SET.\n!\n! Input, real ( kind = 8 ) X, the point at which the least squares polynomial\n! is to be evaluated.\n!\n! Output, real ( kind = 8 ) PX, the value of the least squares\n! polynomial at X.\n!\n implicit none\n\n integer ( kind = 4 ) nterms\n\n real ( kind = 8 ) b(nterms)\n real ( kind = 8 ) c(nterms)\n real ( kind = 8 ) d(nterms)\n integer ( kind = 4 ) i\n real ( kind = 8 ) prev\n real ( kind = 8 ) prev2\n real ( kind = 8 ) px\n real ( kind = 8 ) x\n\n px = d(nterms)\n prev = 0.0D+00\n\n do i = nterms - 1, 1, -1\n\n prev2 = prev\n prev = px\n\n if ( i == nterms-1 ) then\n px = d(i) + ( x - b(i) ) * prev\n else\n px = d(i) + ( x - b(i) ) * prev - c(i+1) * prev2\n end if\n\n end do\n\n return\nend\nsubroutine least_val2 ( nterms, b, c, d, x, px, pxp )\n\n!*****************************************************************************80\n!\n!! LEAST_VAL2 evaluates a least squares polynomial defined by LEAST_SET.\n!\n! Discussion:\n!\n! This routine also computes the derivative of the polynomial.\n!\n! The least squares polynomial is assumed to be defined as a sum\n!\n! P(X) = sum ( 1 <= I <= NTERMS ) D(I) * P(I-1,X)\n!\n! where the orthogonal basis polynomials P(I,X) satisfy the following\n! three term recurrence:\n!\n! P(-1,X) = 0\n! P(0,X) = 1\n! P(I,X) = ( X - B(I-1) ) * P(I-1,X) - C(I-1) * P(I-2,X)\n!\n! Therefore, the least squares polynomial can be evaluated as follows:\n!\n! If NTERMS is 1, then the value of P(X) is D(1) * P(0,X) = D(1).\n!\n! Otherwise, P(X) is defined as the sum of NTERMS > 1 terms. We can\n! reduce the number of terms by 1, because the polynomial P(NTERMS,X)\n! can be rewritten as a sum of polynomials; Therefore, P(NTERMS,X)\n! can be eliminated from the sum, and its coefficient merged in with\n! those of other polynomials. Repeat this process for P(NTERMS-1,X)\n! and so on until a single term remains.\n! P(NTERMS,X) of P(NTERMS-1,X)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 May 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NTERMS, the number of terms in the least\n! squares polynomial. NTERMS must be at least 1. The value of NTERMS\n! may be reduced from the value given to LEAST_SET.\n! This will cause LEAST_VAL to evaluate the least squares polynomial\n! of the lower degree specified.\n!\n! Input, real ( kind = 8 ) B(NTERMS), C(NTERMS), D(NTERMS), the information\n! computed by LEAST_SET.\n!\n! Input, real ( kind = 8 ) X, the point at which the least squares polynomial\n! is to be evaluated.\n!\n! Output, real ( kind = 8 ) PX, PXP, the value and derivative of the least\n! squares polynomial at X.\n!\n implicit none\n\n integer ( kind = 4 ) nterms\n\n real ( kind = 8 ) b(nterms)\n real ( kind = 8 ) c(nterms)\n real ( kind = 8 ) d(nterms)\n integer ( kind = 4 ) i\n real ( kind = 8 ) px\n real ( kind = 8 ) pxm1\n real ( kind = 8 ) pxm2\n real ( kind = 8 ) pxp\n real ( kind = 8 ) pxpm1\n real ( kind = 8 ) pxpm2\n real ( kind = 8 ) x\n\n px = d(nterms)\n pxp = 0.0D+00\n pxm1 = 0.0D+00\n pxpm1 = 0.0D+00\n\n do i = nterms - 1, 1, -1\n\n pxm2 = pxm1\n pxpm2 = pxpm1\n pxm1 = px\n pxpm1 = pxp\n\n if ( i == nterms - 1 ) then\n px = d(i) + ( x - b(i) ) * pxm1\n pxp = pxm1 + ( x - b(i) ) * pxpm1\n else\n px = d(i) + ( x - b(i) ) * pxm1 - c(i+1) * pxm2\n pxp = pxm1 + ( x - b(i) ) * pxpm1 - c(i+1) * pxpm2\n end if\n\n end do\n\n return\nend\nsubroutine parabola_val2 ( dim_num, ndata, tdata, ydata, left, tval, yval )\n\n!*****************************************************************************80\n!\n!! PARABOLA_VAL2 evaluates a parabolic interpolant through tabular data.\n!\n! Discussion:\n!\n! This routine is a utility routine used by OVERHAUSER_SPLINE_VAL.\n! It constructs the parabolic interpolant through the data in\n! 3 consecutive entries of a table and evaluates this interpolant\n! at a given abscissa value.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 January 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) DIM_NUM, the dimension of a single data point.\n! DIM_NUM must be at least 1.\n!\n! Input, integer ( kind = 4 ) NDATA, the number of data points.\n! NDATA must be at least 3.\n!\n! Input, real ( kind = 8 ) TDATA(NDATA), the abscissas of the data\n! points. The values in TDATA must be in strictly ascending order.\n!\n! Input, real ( kind = 8 ) YDATA(DIM_NUM,NDATA), the data points\n! corresponding to the abscissas.\n!\n! Input, integer ( kind = 4 ) LEFT, the location of the first of the three\n! consecutive data points through which the parabolic interpolant\n! must pass. 1 <= LEFT <= NDATA - 2.\n!\n! Input, real ( kind = 8 ) TVAL, the value of T at which the parabolic\n! interpolant is to be evaluated. Normally, TDATA(1) <= TVAL <= T(NDATA),\n! and the data will be interpolated. For TVAL outside this range,\n! extrapolation will be used.\n!\n! Output, real ( kind = 8 ) YVAL(DIM_NUM), the value of the parabolic\n! interpolant at TVAL.\n!\n implicit none\n\n integer ( kind = 4 ) ndata\n integer ( kind = 4 ) dim_num\n\n real ( kind = 8 ) dif1\n real ( kind = 8 ) dif2\n integer ( kind = 4 ) i\n integer ( kind = 4 ) left\n real ( kind = 8 ) t1\n real ( kind = 8 ) t2\n real ( kind = 8 ) t3\n real ( kind = 8 ) tval\n real ( kind = 8 ) tdata(ndata)\n real ( kind = 8 ) ydata(dim_num,ndata)\n real ( kind = 8 ) y1\n real ( kind = 8 ) y2\n real ( kind = 8 ) y3\n real ( kind = 8 ) yval(dim_num)\n!\n! Check.\n!\n if ( left < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PARABOLA_VAL2 - Fatal error!'\n write ( *, '(a)' ) ' LEFT < 1.'\n write ( *, '(a,i8)' ) ' LEFT = ', left\n stop 1\n end if\n\n if ( ndata-2 < left ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PARABOLA_VAL2 - Fatal error!'\n write ( *, '(a)' ) ' NDATA-2 < LEFT.'\n write ( *, '(a,i8)' ) ' NDATA = ', ndata\n write ( *, '(a,i8)' ) ' LEFT = ', left\n stop 1\n end if\n\n if ( dim_num < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PARABOLA_VAL2 - Fatal error!'\n write ( *, '(a)' ) ' DIM_NUM < 1.'\n stop 1\n end if\n!\n! Copy out the three abscissas.\n!\n t1 = tdata(left)\n t2 = tdata(left+1)\n t3 = tdata(left+2)\n\n if ( t2 <= t1 .or. t3 <= t2 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PARABOLA_VAL2 - Fatal error!'\n write ( *, '(a)' ) ' T2 <= T1 or T3 <= T2.'\n stop 1\n end if\n!\n! Construct and evaluate a parabolic interpolant for the data\n! in each dimension.\n!\n do i = 1, dim_num\n\n y1 = ydata(i,left)\n y2 = ydata(i,left+1)\n y3 = ydata(i,left+2)\n\n dif1 = ( y2 - y1 ) / ( t2 - t1 )\n dif2 = ( ( y3 - y1 ) / ( t3 - t1 ) &\n - ( y2 - y1 ) / ( t2 - t1 ) ) / ( t3 - t2 )\n\n yval(i) = y1 + ( tval - t1 ) * ( dif1 + ( tval - t2 ) * dif2 )\n\n end do\n\n return\nend\n!function pchst ( arg1, arg2 )\n\n!*****************************************************************************80\n!\n!! PCHST: PCHIP sign-testing routine.\n!\n! Discussion:\n!\n! This routine essentially computes the sign of ARG1 * ARG2.\n!\n! The object is to do this without multiplying ARG1 * ARG2, to avoid\n! possible over/underflow problems.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 25 June 2008\n!\n! Author:\n!\n! Original FORTRAN77 version by Fred Fritsch.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! Fred Fritsch, Ralph Carlson,\n! Monotone Piecewise Cubic Interpolation,\n! SIAM Journal on Numerical Analysis,\n! Volume 17, Number 2, April 1980, pages 238-246.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) ARG1, ARG2, two values to check.\n!\n! Output, real ( kind = 8 ) PCHST,\n! -1.0, if ARG1 and ARG2 are of opposite sign.\n! 0.0, if either argument is zero.\n! +1.0, if ARG1 and ARG2 are of the same sign.\n!\n! implicit none\n\n! real ( kind = 8 ) arg1\n! real ( kind = 8 ) arg2\n! real ( kind = 8 ) pchst\n\n! pchst = sign ( 1.0D+00, arg1 ) * sign ( 1.0D+00, arg2 )\n\n! if ( arg1 == 0.0D+00 .or. arg2 == 0.0D+00 ) then\n! pchst = 0.0D+00\n! end if\n\n! return\n!end\n!subroutine r8_swap ( x, y )\n\n!*****************************************************************************80\n!\n!! R8_SWAP swaps two real values.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 May 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, real ( kind = 8 ) X, Y. On output, the values of X and\n! Y have been interchanged.\n!\n! implicit none\n\n! real ( kind = 8 ) x\n! real ( kind = 8 ) y\n! real ( kind = 8 ) z\n\n! z = x\n! x = y\n! y = z\n\n! return\n!end\n!function r8_uniform_01 ( seed )\n\n!*****************************************************************************80\n!\n!! R8_UNIFORM_01 is a portable pseudorandom number generator.\n!\n! Discussion:\n!\n! This routine implements the recursion\n!\n! seed = 16807 * seed mod ( 2**31 - 1 )\n! unif = seed / ( 2**31 - 1 )\n!\n! The integer arithmetic never requires more than 32 bits,\n! including a sign bit.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 11 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Paul Bratley, Bennett Fox, Linus Schrage,\n! A Guide to Simulation,\n! Springer Verlag, pages 201-202, 1983.\n!\n! Bennett Fox,\n! Algorithm 647:\n! Implementation and Relative Efficiency of Quasirandom\n! Sequence Generators,\n! ACM Transactions on Mathematical Software,\n! Volume 12, Number 4, pages 362-376, 1986.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) SEED, the \"seed\" value, which should\n! NOT be 0. (Otherwise, the output values of SEED and UNIFORM will be zero.)\n! On output, SEED has been updated.\n!\n! Output, real ( kind = 8 ) R8_UNIFORM_01, a new pseudorandom variate,\n! strictly between 0 and 1.\n!\n! implicit none\n\n! integer ( kind = 4 ) k\n! integer ( kind = 4 ) seed\n! real ( kind = 8 ) r8_uniform_01\n\n! k = seed / 127773\n\n! seed = 16807 * ( seed - k * 127773 ) - k * 2836\n\n! if ( seed < 0 ) then\n! seed = seed + 2147483647\n! end if\n!\n! Although SEED can be represented exactly as a 32 bit integer,\n! it generally cannot be represented exactly as a 32 bit real number!\n!\n! r8_uniform_01 = real ( seed, kind = 8 ) * 4.656612875E-10\n\n! return\n!end\nsubroutine r83_mxv ( n, a, x, b )\n\n!*****************************************************************************80\n!\n!! R83_MXV multiplies an R83 matrix times a vector.\n!\n! Discussion:\n!\n! The R83 storage format is used for a tridiagonal matrix.\n! The superdiagonal is stored in entries (1,2:N), the diagonal in\n! entries (2,1:N), and the subdiagonal in (3,1:N-1). Thus, the\n! original matrix is \"collapsed\" vertically into the array.\n!\n! Example:\n!\n! Here is how an R83 matrix of order 5 would be stored:\n!\n! * A12 A23 A34 A45\n! A11 A22 A33 A44 A55\n! A21 A32 A43 A54 *\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 November 2003\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the linear system.\n!\n! Input, real ( kind = 8 ) A(3,N), the R83 matrix.\n!\n! Input, real ( kind = 8 ) X(N), the vector to be multiplied by A.\n!\n! Output, real ( kind = 8 ) B(N), the product A * x.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(3,n)\n real ( kind = 8 ) b(n)\n real ( kind = 8 ) x(n)\n\n b(1:n) = a(2,1:n) * x(1:n)\n b(1:n-1) = b(1:n-1) + a(1,2:n) * x(2:n)\n b(2:n) = b(2:n) + a(3,1:n-1) * x(1:n-1)\n\n return\nend\nsubroutine r83_np_fs ( n, a, b, x )\n\n!*****************************************************************************80\n!\n!! R83_NP_FS factors and solves an R83 system.\n!\n! Discussion:\n!\n! The R83 storage format is used for a tridiagonal matrix.\n! The superdiagonal is stored in entries (1,2:N), the diagonal in\n! entries (2,1:N), and the subdiagonal in (3,1:N-1). Thus, the\n! original matrix is \"collapsed\" vertically into the array.\n!\n! This algorithm requires that each diagonal entry be nonzero.\n! It does not use pivoting, and so can fail on systems that\n! are actually nonsingular.\n!\n! Here is how an R83 matrix of order 5 would be stored:\n!\n! * A12 A23 A34 A45\n! A11 A22 A33 A44 A55\n! A21 A32 A43 A54 *\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 November 2003\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the linear system.\n!\n! Input/output, real ( kind = 8 ) A(3,N).\n! On input, the tridiagonal matrix.\n! On output, the data in these vectors has been overwritten\n! by factorization information.\n!\n! Input, real ( kind = 8 ) B(N), the right hand side of the linear system.\n!\n! Output, real ( kind = 8 ) X(N), the solution of the linear system.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(3,n)\n real ( kind = 8 ) b(n)\n integer ( kind = 4 ) i\n real ( kind = 8 ) x(n)\n real ( kind = 8 ) xmult\n!\n! The diagonal entries can't be zero.\n!\n do i = 1, n\n if ( a(2,i) == 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R83_NP_FS - Fatal error!'\n write ( *, '(a,i8,a)' ) ' A(2,', i, ') = 0.'\n return\n end if\n end do\n\n x(1:n) = b(1:n)\n\n do i = 2, n\n xmult = a(3,i-1) / a(2,i-1)\n a(2,i) = a(2,i) - xmult * a(1,i)\n x(i) = x(i) - xmult * x(i-1)\n end do\n\n x(n) = x(n) / a(2,n)\n do i = n - 1, 1, -1\n x(i) = ( x(i) - a(1,i+1) * x(i+1) ) / a(2,i)\n end do\n\n return\nend\nsubroutine r83_uniform ( n, seed, a )\n\n!*****************************************************************************80\n!\n!! R83_UNIFORM randomizes an R83 matrix.\n!\n! Discussion:\n!\n! The R83 storage format is used for a tridiagonal matrix.\n! The superdiagonal is stored in entries (1,2:N), the diagonal in\n! entries (2,1:N), and the subdiagonal in (3,1:N-1). Thus, the\n! original matrix is \"collapsed\" vertically into the array.\n!\n! Here is how an R83 matrix of order 5 would be stored:\n!\n! * A12 A23 A34 A45\n! A11 A22 A33 A44 A55\n! A21 A32 A43 A54 *\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 19 September 2003\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the linear system.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random number\n! generator.\n!\n! Output, real ( kind = 8 ) A(3,N), the R83 matrix.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(3,n)\n integer ( kind = 4 ) seed\n\n a(1,1) = 0.0D+00\n call r8vec_uniform_01 ( n-1, seed, a(1,2:n) )\n\n call r8vec_uniform_01 ( n, seed, a(2,1:n) )\n\n call r8vec_uniform_01 ( n-1, seed, a(3,1:n-1) )\n a(3,n) = 0.0D+00\n\n return\nend\nsubroutine r85_np_fs ( n, a, b, x )\n\n!*****************************************************************************80\n!\n!! R85_NP_FS factors and solves an R85 linear system.\n!\n! Discussion:\n!\n! The R85 storage format represents a pentadiagonal matrix as a 5\n! by N array, in which each row corresponds to a diagonal, and\n! column locations are preserved. Thus, the original matrix is\n! \"collapsed\" vertically into the array.\n!\n! The factorization algorithm requires that each diagonal entry be nonzero.\n!\n! No pivoting is performed, and therefore the algorithm may fail\n! in simple cases where the matrix is not singular.\n!\n! Example:\n!\n! Here is how an R85 matrix of order 6 would be stored:\n!\n! * * A13 A24 A35 A46\n! * A12 A23 A34 A45 A56\n! A11 A22 A33 A44 A55 A66\n! A21 A32 A43 A54 A65 *\n! A31 A42 A53 A64 * *\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 17 September 2003\n!\n! Author:\n!\n! Original FORTRAN77 version by Ward Cheney, David Kincaid.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! Ward Cheney, David Kincaid,\n! Numerical Mathematics and Computing,\n! Brooks-Cole Publishing, 2004,\n! ISBN: 0534201121.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the linear system.\n!\n! Input/output, real ( kind = 8 ) A(5,N),\n! On input, the pentadiagonal matrix.\n! On output, the data has been overwritten by factorization information.\n!\n! Input/output, real ( kind = 8 ) B(N).\n! On input, B contains the right hand side of the linear system.\n! On output, B has been overwritten by factorization information.\n!\n! Output, real ( kind = 8 ) X(N), the solution of the linear system.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(5,n)\n real ( kind = 8 ) b(n)\n integer ( kind = 4 ) i\n real ( kind = 8 ) x(n)\n real ( kind = 8 ) xmult\n\n do i = 1, n\n if ( a(3,i) == 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R85_NP_FS - Fatal error!'\n write ( *, '(a,i8,a)' ) ' A(3,', i, ') = 0.'\n stop 1\n end if\n end do\n\n do i = 2, n - 1\n\n xmult = a(2,i) / a(3,i-1)\n a(3,i) = a(3,i) - xmult * a(4,i-1)\n a(4,i) = a(4,i) - xmult * a(5,i-1)\n\n b(i) = b(i) - xmult * b(i-1)\n\n xmult = a(1,i+1) / a(3,i-1)\n a(2,i+1) = a(2,i+1) - xmult * a(4,i-1)\n a(3,i+1) = a(3,i+1) - xmult * a(5,i-1)\n\n b(i+1) = b(i+1) - xmult * b(i-1)\n\n end do\n\n call r8vec_print ( n, b, ' Bpart1: ')\n\n xmult = a(2,n) / a(3,n-1)\n a(3,n) = a(3,n) - xmult * a(4,n-1)\n\n x(n) = ( b(n) - xmult * b(n-1) ) / a(3,n)\n x(n-1) = ( b(n-1) - a(4,n-1) * x(n) ) / a(3,n-1)\n\n do i = n - 2, 1, -1\n x(i) = ( b(i) - a(4,i) * x(i+1) - a(5,i) * x(i+2) ) / a(3,i)\n end do\n\n return\nend\nsubroutine r85_print ( n, a, title )\n\n!*****************************************************************************80\n!\n!! R85_PRINT prints an R85 matrix.\n!\n! Discussion:\n!\n! The R85 storage format represents a pentadiagonal matrix as a 5\n! by N array, in which each row corresponds to a diagonal, and\n! column locations are preserved. Thus, the original matrix is\n! \"collapsed\" vertically into the array.\n!\n! Example:\n!\n! Here is how an R85 matrix of order 6 would be stored:\n!\n! * * A13 A24 A35 A46\n! * A12 A23 A34 A45 A56\n! A11 A22 A33 A44 A55 A66\n! A21 A32 A43 A54 A65 *\n! A31 A42 A53 A64 * *\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 17 September 2003\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the matrix.\n! N must be positive.\n!\n! Input, real ( kind = 8 ) A(5,N), the matrix.\n!\n! Input, character ( len = * ) TITLE, a title.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(5,n)\n character ( len = * ) title\n\n call r85_print_some ( n, a, 1, 1, n, n, title )\n\n return\nend\nsubroutine r85_print_some ( n, a, ilo, jlo, ihi, jhi, title )\n\n!*****************************************************************************80\n!\n!! R85_PRINT_SOME prints some of an R85 matrix.\n!\n! Discussion:\n!\n! The R85 storage format represents a pentadiagonal matrix as a 5\n! by N array, in which each row corresponds to a diagonal, and\n! column locations are preserved. Thus, the original matrix is\n! \"collapsed\" vertically into the array.\n!\n! Example:\n!\n! Here is how an R85 matrix of order 6 would be stored:\n!\n! * * A13 A24 A35 A46\n! * A12 A23 A34 A45 A56\n! A11 A22 A33 A44 A55 A66\n! A21 A32 A43 A54 A65 *\n! A31 A42 A53 A64 * *\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 January 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the matrix.\n! N must be positive.\n!\n! Input, real ( kind = 8 ) A(5,N), the matrix.\n!\n! Input, integer ( kind = 4 ) ILO, JLO, IHI, JHI, the first row and\n! column, and the last row and column, to be printed.\n!\n! Input, character ( len = * ) TITLE, a title.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: incx = 5\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(5,n)\n character ( len = 14 ) ctemp(incx)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i2hi\n integer ( kind = 4 ) i2lo\n integer ( kind = 4 ) ihi\n integer ( kind = 4 ) ilo\n integer ( kind = 4 ) inc\n integer ( kind = 4 ) j\n integer ( kind = 4 ) j2\n integer ( kind = 4 ) j2hi\n integer ( kind = 4 ) j2lo\n integer ( kind = 4 ) jhi\n integer ( kind = 4 ) jlo\n character ( len = * ) title\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n!\n! Print the columns of the matrix, in strips of 5.\n!\n do j2lo = jlo, jhi, incx\n\n j2hi = j2lo + incx - 1\n j2hi = min ( j2hi, n )\n j2hi = min ( j2hi, jhi )\n\n inc = j2hi + 1 - j2lo\n\n write ( *, '(a)' ) ' '\n\n do j = j2lo, j2hi\n j2 = j + 1 - j2lo\n write ( ctemp(j2), '(i7,7x)' ) j\n end do\n\n write ( *, '('' Col: '',5a14)' ) ( ctemp(j2), j2 = 1, inc )\n write ( *, '(a)' ) ' Row'\n write ( *, '(a)' ) ' ---'\n!\n! Determine the range of the rows in this strip.\n!\n i2lo = max ( ilo, 1 )\n i2lo = max ( i2lo, j2lo - 2 )\n\n i2hi = min ( ihi, n )\n i2hi = min ( i2hi, j2hi + 2 )\n\n do i = i2lo, i2hi\n!\n! Print out (up to) 5 entries in row I, that lie in the current strip.\n!\n do j2 = 1, inc\n\n j = j2lo - 1 + j2\n\n if ( 2 < i-j .or. 2 < j-i ) then\n ctemp(j2) = ' '\n else if ( j == i+2 ) then\n write ( ctemp(j2), '(g14.6)' ) a(1,j)\n else if ( j == i+1 ) then\n write ( ctemp(j2), '(g14.6)' ) a(2,j)\n else if ( j == i ) then\n write ( ctemp(j2), '(g14.6)' ) a(3,j)\n else if ( j == i-1 ) then\n write ( ctemp(j2), '(g14.6)' ) a(4,j)\n else if ( j == i-2 ) then\n write ( ctemp(j2), '(g14.6)' ) a(5,j)\n end if\n\n end do\n\n write ( *, '(i5,1x,5a14)' ) i, ( ctemp(j2), j2 = 1, inc )\n\n end do\n\n end do\n\n return\nend\nsubroutine r8ge_fs ( n, a, b, info )\n\n!*****************************************************************************80\n!\n!! R8GE_FS factors and solves an R8GE system.\n!\n! Discussion:\n!\n! The R8GE storage format is used for a general M by N matrix. A storage\n! space is made for each entry. The two dimensional logical\n! array can be thought of as a vector of M*N entries, starting with\n! the M entries in the column 1, then the M entries in column 2\n! and so on. Considered as a vector, the entry A(I,J) is then stored\n! in vector location I+(J-1)*M.\n!\n! R8GE storage is used by LINPACK and LAPACK.\n!\n! R8GE_FS does not save the LU factors of the matrix, and hence cannot\n! be used to efficiently solve multiple linear systems, or even to\n! factor A at one time, and solve a single linear system at a later time.\n!\n! R8GE_FS uses partial pivoting, but no pivot vector is required.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 04 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the matrix.\n! N must be positive.\n!\n! Input/output, real ( kind = 8 ) A(N,N).\n! On input, A is the coefficient matrix of the linear system.\n! On output, A is in unit upper triangular form, and\n! represents the U factor of an LU factorization of the\n! original coefficient matrix.\n!\n! Input/output, real ( kind = 8 ) B(N).\n! On input, B is the right hand side of the linear system.\n! On output, B is the solution of the linear system.\n!\n! Output, integer ( kind = 4 ) INFO, singularity flag.\n! 0, no singularity detected.\n! nonzero, the factorization failed on the INFO-th step.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n,n)\n real ( kind = 8 ) b(n)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) info\n integer ( kind = 4 ) ipiv\n integer ( kind = 4 ) jcol\n real ( kind = 8 ) piv\n real ( kind = 8 ) row(n)\n real ( kind = 8 ) temp\n\n info = 0\n\n do jcol = 1, n\n!\n! Find the maximum element in column I.\n!\n piv = abs ( a(jcol,jcol) )\n ipiv = jcol\n do i = jcol + 1, n\n if ( piv < abs ( a(i,jcol) ) ) then\n piv = abs ( a(i,jcol) )\n ipiv = i\n end if\n end do\n\n if ( piv == 0.0D+00 ) then\n info = jcol\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8GE_FS - Fatal error!'\n write ( *, '(a,i8)' ) ' Zero pivot on step ', info\n stop 1\n end if\n!\n! Switch rows JCOL and IPIV, and B.\n!\n if ( jcol /= ipiv ) then\n\n row(1:n) = a(jcol,1:n)\n a(jcol,1:n) = a(ipiv,1:n)\n a(ipiv,1:n) = row(1:n)\n\n temp = b(jcol)\n b(jcol) = b(ipiv)\n b(ipiv) = temp\n\n end if\n!\n! Scale the pivot row.\n!\n a(jcol,jcol+1:n) = a(jcol,jcol+1:n) / a(jcol,jcol)\n b(jcol) = b(jcol) / a(jcol,jcol)\n a(jcol,jcol) = 1.0D+00\n!\n! Use the pivot row to eliminate lower entries in that column.\n!\n do i = jcol + 1, n\n if ( a(i,jcol) /= 0.0D+00 ) then\n temp = - a(i,jcol)\n a(i,jcol) = 0.0D+00\n a(i,jcol+1:n) = a(i,jcol+1:n) + temp * a(jcol,jcol+1:n)\n b(i) = b(i) + temp * b(jcol)\n end if\n end do\n\n end do\n!\n! Back solve.\n!\n do jcol = n, 2, -1\n b(1:jcol-1) = b(1:jcol-1) - a(1:jcol-1,jcol) * b(jcol)\n end do\n\n return\nend\nsubroutine r8vec_bracket ( n, x, xval, left, right )\n\n!*****************************************************************************80\n!\n!! R8VEC_BRACKET searches a sorted R8VEC for successive brackets of a value.\n!\n! Discussion:\n!\n! An R8VEC is an array of double precision real values.\n!\n! If the values in the vector are thought of as defining intervals\n! on the real line, then this routine searches for the interval\n! nearest to or containing the given value.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, length of input array.\n!\n! Input, real ( kind = 8 ) X(N), an array sorted into ascending order.\n!\n! Input, real ( kind = 8 ) XVAL, a value to be bracketed.\n!\n! Output, integer ( kind = 4 ) LEFT, RIGHT, the results of the search.\n! Either:\n! XVAL < X(1), when LEFT = 1, RIGHT = 2;\n! X(N) < XVAL, when LEFT = N-1, RIGHT = N;\n! or\n! X(LEFT) <= XVAL <= X(RIGHT).\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) left\n integer ( kind = 4 ) right\n real ( kind = 8 ) x(n)\n real ( kind = 8 ) xval\n\n do i = 2, n - 1\n\n if ( xval < x(i) ) then\n left = i - 1\n right = i\n return\n end if\n\n end do\n\n left = n - 1\n right = n\n\n return\nend\nsubroutine r8vec_bracket3 ( n, t, tval, left )\n\n!*****************************************************************************80\n!\n!! R8VEC_BRACKET3 finds the interval containing or nearest a given value.\n!\n! Discussion:\n!\n! An R8VEC is an array of double precision real values.\n!\n! The routine always returns the index LEFT of the sorted array\n! T with the property that either\n! * T is contained in the interval [ T(LEFT), T(LEFT+1) ], or\n! * T < T(LEFT) = T(1), or\n! * T > T(LEFT+1) = T(N).\n!\n! The routine is useful for interpolation problems, where\n! the abscissa must be located within an interval of data\n! abscissas for interpolation, or the \"nearest\" interval\n! to the (extreme) abscissa must be found so that extrapolation\n! can be carried out.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, length of the input array.\n!\n! Input, real ( kind = 8 ) T(N), an array sorted into ascending order.\n!\n! Input, real ( kind = 8 ) TVAL, a value to be bracketed by entries of T.\n!\n! Input/output, integer ( kind = 4 ) LEFT.\n!\n! On input, if 1 <= LEFT <= N-1, LEFT is taken as a suggestion for the\n! interval [ T(LEFT), T(LEFT+1) ] in which TVAL lies. This interval\n! is searched first, followed by the appropriate interval to the left\n! or right. After that, a binary search is used.\n!\n! On output, LEFT is set so that the interval [ T(LEFT), T(LEFT+1) ]\n! is the closest to TVAL; it either contains TVAL, or else TVAL\n! lies outside the interval [ T(1), T(N) ].\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) high\n integer ( kind = 4 ) left\n integer ( kind = 4 ) low\n integer ( kind = 4 ) mid\n real ( kind = 8 ) t(n)\n real ( kind = 8 ) tval\n!\n! Check the input data.\n!\n if ( n < 2 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8VEC_BRACKET3 - Fatal error!'\n write ( *, '(a)' ) ' N must be at least 2.'\n stop 1\n end if\n!\n! If LEFT is not between 1 and N-1, set it to the middle value.\n!\n if ( left < 1 .or. n - 1 < left ) then\n left = ( n + 1 ) / 2\n end if\n!\n! CASE 1: TVAL < T(LEFT):\n! Search for TVAL in [T(I), T(I+1)] for intervals I = 1 to LEFT-1.\n!\n if ( tval < t(left) ) then\n\n if ( left == 1 ) then\n return\n else if ( left == 2 ) then\n left = 1\n return\n else if ( t(left-1) <= tval ) then\n left = left - 1\n return\n else if ( tval <= t(2) ) then\n left = 1\n return\n end if\n!\n! ...Binary search for TVAL in [T(I), T(I+1)] for intervals I = 2 to LEFT-2.\n!\n low = 2\n high = left - 2\n\n do\n\n if ( low == high ) then\n left = low\n return\n end if\n\n mid = ( low + high + 1 ) / 2\n\n if ( t(mid) <= tval ) then\n low = mid\n else\n high = mid - 1\n end if\n\n end do\n!\n! CASE2: T(LEFT+1) < TVAL:\n! Search for TVAL in {T(I),T(I+1)] for intervals I = LEFT+1 to N-1.\n!\n else if ( t(left+1) < tval ) then\n\n if ( left == n - 1 ) then\n return\n else if ( left == n - 2 ) then\n left = left + 1\n return\n else if ( tval <= t(left+2) ) then\n left = left + 1\n return\n else if ( t(n-1) <= tval ) then\n left = n - 1\n return\n end if\n!\n! ...Binary search for TVAL in [T(I), T(I+1)] for intervals I = LEFT+2 to N-2.\n!\n low = left + 2\n high = n - 2\n\n do\n\n if ( low == high ) then\n left = low\n return\n end if\n\n mid = ( low + high + 1 ) / 2\n\n if ( t(mid) <= tval ) then\n low = mid\n else\n high = mid - 1\n end if\n\n end do\n!\n! CASE3: T(LEFT) <= TVAL <= T(LEFT+1):\n! T is in [T(LEFT), T(LEFT+1)], as the user said it might be.\n!\n else\n\n end if\n\n return\nend\nfunction r8vec_distinct ( n, x )\n\n!*****************************************************************************80\n!\n!! R8VEC_DISTINCT is true if the entries in an R8VEC are distinct.\n!\n! Discussion:\n!\n! An R8VEC is an array of double precision real values.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 September 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of entries in the vector.\n!\n! Input, real ( kind = 8 ) X(N), the vector to be checked.\n!\n! Output, logical R8VEC_DISTINCT is TRUE if all N elements of X\n! are distinct.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n logical r8vec_distinct\n real ( kind = 8 ) x(n)\n\n r8vec_distinct = .false.\n\n do i = 2, n\n do j = 1, i - 1\n if ( x(i) == x(j) ) then\n return\n end if\n end do\n end do\n\n r8vec_distinct = .true.\n\n return\nend\nsubroutine r8vec_even ( n, alo, ahi, a )\n\n!*****************************************************************************80\n!\n!! R8VEC_EVEN returns N real values, evenly spaced between ALO and AHI.\n!\n! Discussion:\n!\n! An R8VEC is an array of double precision real values.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 17 February 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of values.\n!\n! Input, real ( kind = 8 ) ALO, AHI, the low and high values.\n!\n! Output, real ( kind = 8 ) A(N), N evenly spaced values.\n! Normally, A(1) = ALO and A(N) = AHI.\n! However, if N = 1, then A(1) = 0.5*(ALO+AHI).\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n real ( kind = 8 ) ahi\n real ( kind = 8 ) alo\n integer ( kind = 4 ) i\n\n if ( n == 1 ) then\n\n a(1) = 0.5D+00 * ( alo + ahi )\n\n else\n\n do i = 1, n\n a(i) = ( real ( n - i, kind = 8 ) * alo &\n + real ( i - 1, kind = 8 ) * ahi ) &\n / real ( n - 1, kind = 8 )\n end do\n\n end if\n\n return\nend\nsubroutine r8vec_indicator ( n, a )\n\n!*****************************************************************************80\n!\n!! R8VEC_INDICATOR sets an R8VEC to the indicator vector.\n!\n! Discussion:\n!\n! An R8VEC is an array of double precision real values.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 09 February 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of elements of A.\n!\n! Output, real ( kind = 8 ) A(N), the array to be initialized.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n integer ( kind = 4 ) i\n\n do i = 1, n\n a(i) = real ( i, kind = 8 )\n end do\n\n return\nend\nsubroutine r8vec_order_type ( n, a, order )\n\n!*****************************************************************************80\n!\n!! R8VEC_ORDER_TYPE determines the order type of an R8VEC.\n!\n! Discussion:\n!\n! An R8VEC is an array of double precision real values.\n!\n! We assume the array is increasing or decreasing, and we want to\n! verify that.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of entries of the array.\n!\n! Input, real ( kind = 8 ) A(N), the array to be checked.\n!\n! Output, integer ( kind = 4 ) ORDER, order indicator:\n! -1, no discernable order;\n! 0, all entries are equal;\n! 1, ascending order;\n! 2, strictly ascending order;\n! 3, descending order;\n! 4, strictly descending order.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) order\n!\n! Search for the first value not equal to A(1).\n!\n i = 1\n\n do\n\n i = i + 1\n\n if ( n < i ) then\n order = 0\n return\n end if\n\n if ( a(1) < a(i) ) then\n\n if ( i == 2 ) then\n order = 2\n else\n order = 1\n end if\n\n exit\n\n else if ( a(i) < a(1) ) then\n\n if ( i == 2 ) then\n order = 4\n else\n order = 3\n end if\n\n exit\n\n end if\n\n end do\n!\n! Now we have a \"direction\". Examine subsequent entries.\n!\n do\n\n i = i + 1\n if ( n < i ) then\n exit\n end if\n\n if ( order == 1 ) then\n\n if ( a(i) < a(i-1) ) then\n order = -1\n exit\n end if\n\n else if ( order == 2 ) then\n\n if ( a(i) < a(i-1) ) then\n order = -1\n exit\n else if ( a(i) == a(i-1) ) then\n order = 1\n end if\n\n else if ( order == 3 ) then\n\n if ( a(i-1) < a(i) ) then\n order = -1\n exit\n end if\n\n else if ( order == 4 ) then\n\n if ( a(i-1) < a(i) ) then\n order = -1\n exit\n else if ( a(i) == a(i-1) ) then\n order = 3\n end if\n\n end if\n\n end do\n\n return\nend\nsubroutine r8vec_print ( n, a, title )\n\n!*****************************************************************************80\n!\n!! R8VEC_PRINT prints an R8VEC.\n!\n! Discussion:\n!\n! An R8VEC is an array of double precision real values.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of components of the vector.\n!\n! Input, real ( kind = 8 ) A(N), the vector to be printed.\n!\n! Input, character ( len = * ) TITLE, a title.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n integer ( kind = 4 ) i\n character ( len = * ) title\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(i8,g14.6)' ) i, a(i)\n end do\n\n return\nend\nsubroutine r8vec_sort_bubble_a ( n, a )\n\n!*****************************************************************************80\n!\n!! R8VEC_SORT_BUBBLE_A ascending sorts an R8VEC using bubble sort.\n!\n! Discussion:\n!\n! An R8VEC is an array of double precision real values.\n!\n! Bubble sort is simple to program, but inefficient. It should not\n! be used for large arrays.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of entries in the array.\n!\n! Input/output, real ( kind = 8 ) A(N).\n! On input, an unsorted array.\n! On output, the array has been sorted.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n\n do i = 1, n-1\n do j = i+1, n\n if ( a(j) < a(i) ) then\n call r8_swap ( a(i), a(j) )\n end if\n end do\n end do\n\n return\nend\n!subroutine r8vec_uniform_01 ( n, seed, r )\n\n!*****************************************************************************80\n!\n!! R8VEC_UNIFORM_01 returns a unit pseudorandom R8VEC.\n!\n! Discussion:\n!\n! An R8VEC is an array of double precision real values.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 19 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Paul Bratley, Bennett Fox, Linus Schrage,\n! A Guide to Simulation,\n! Springer Verlag, pages 201-202, 1983.\n!\n! Bennett Fox,\n! Algorithm 647:\n! Implementation and Relative Efficiency of Quasirandom\n! Sequence Generators,\n! ACM Transactions on Mathematical Software,\n! Volume 12, Number 4, pages 362-376, 1986.\n!\n! Peter Lewis, Allen Goodman, James Miller,\n! A Pseudo-Random Number Generator for the System/360,\n! IBM Systems Journal,\n! Volume 8, pages 136-143, 1969.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, the number of entries in the vector.\n!\n! Input/output, integer ( kind = 4 ) SEED, the \"seed\" value, which should\n! NOT be 0. On output, SEED has been updated.\n!\n! Output, real ( kind = 8 ) R(N), the vector of pseudorandom values.\n!\n! implicit none\n\n! integer ( kind = 4 ) n\n\n! integer ( kind = 4 ) i\n! integer ( kind = 4 ) k\n! integer ( kind = 4 ) seed\n! real ( kind = 8 ) r(n)\n!\n! do i = 1, n\n\n! k = seed / 127773\n\n! seed = 16807 * ( seed - k * 127773 ) - k * 2836\n\n! if ( seed < 0 ) then\n! seed = seed + 2147483647\n! end if\n\n! r(i) = real ( seed, kind = 8 ) * 4.656612875D-10\n\n! end do\n\n! return\n!end\nsubroutine r8vec_unique_count ( n, a, tol, unique_num )\n\n!*****************************************************************************80\n!\n!! R8VEC_UNIQUE_COUNT counts the unique elements in an unsorted R8VEC.\n!\n! Discussion:\n!\n! An R8VEC is an array of double precision real values.\n!\n! Because the array is unsorted, this algorithm is O(N^2).\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 08 December 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of elements of A.\n!\n! Input, real ( kind = 8 ) A(N), the unsorted array to examine.\n!\n! Input, real ( kind = 8 ) TOL, a nonnegative tolerance for equality.\n! Set it to 0.0 for the strictest test.\n!\n! Output, integer ( kind = 4 ) UNIQUE_NUM, the number of unique elements.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n integer ( kind = 4 ) unique_num\n real ( kind = 8 ) tol\n\n unique_num = 0\n\n do i = 1, n\n\n unique_num = unique_num + 1\n\n do j = 1, i - 1\n\n if ( abs ( a(i) - a(j) ) <= tol ) then\n unique_num = unique_num - 1\n exit\n end if\n\n end do\n\n end do\n\n return\nend\nsubroutine spline_b_val ( ndata, tdata, ydata, tval, yval )\n\n!*****************************************************************************80\n!\n!! SPLINE_B_VAL evaluates a cubic B spline approximant.\n!\n! Discussion:\n!\n! The cubic B spline will approximate the data, but is not\n! designed to interpolate it.\n!\n! In effect, two \"phantom\" data values are appended to the data,\n! so that the spline will interpolate the first and last data values.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 11 February 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Carl deBoor,\n! A Practical Guide to Splines,\n! Springer, 2001,\n! ISBN: 0387953663.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NDATA, the number of data values.\n!\n! Input, real ( kind = 8 ) TDATA(NDATA), the abscissas of the data.\n!\n! Input, real ( kind = 8 ) YDATA(NDATA), the data values.\n!\n! Input, real ( kind = 8 ) TVAL, a point at which the spline is\n! to be evaluated.\n!\n! Output, real ( kind = 8 ) YVAL, the value of the function at TVAL.\n!\n implicit none\n\n integer ( kind = 4 ) ndata\n\n real ( kind = 8 ) bval\n integer ( kind = 4 ) left\n integer ( kind = 4 ) right\n real ( kind = 8 ) tdata(ndata)\n real ( kind = 8 ) tval\n real ( kind = 8 ) u\n real ( kind = 8 ) ydata(ndata)\n real ( kind = 8 ) yval\n!\n! Find the nearest interval [ TDATA(LEFT), TDATA(RIGHT) ] to TVAL.\n!\n call r8vec_bracket ( ndata, tdata, tval, left, right )\n!\n! Evaluate the 5 nonzero B spline basis functions in the interval,\n! weighted by their corresponding data values.\n!\n u = ( tval - tdata(left) ) / ( tdata(right) - tdata(left) )\n yval = 0.0D+00\n!\n! B function associated with node LEFT - 1, (or \"phantom node\"),\n! evaluated in its 4th interval.\n!\n bval = ( ( ( - 1.0D+00 &\n * u + 3.0D+00 ) &\n * u - 3.0D+00 ) &\n * u + 1.0D+00 ) / 6.0D+00\n\n if ( 0 < left-1 ) then\n yval = yval + ydata(left-1) * bval\n else\n yval = yval + ( 2.0D+00 * ydata(1) - ydata(2) ) * bval\n end if\n!\n! B function associated with node LEFT,\n! evaluated in its third interval.\n!\n bval = ( ( ( 3.0D+00 &\n * u - 6.0D+00 ) &\n * u + 0.0D+00 ) &\n * u + 4.0D+00 ) / 6.0D+00\n\n yval = yval + ydata(left) * bval\n!\n! B function associated with node RIGHT,\n! evaluated in its second interval.\n!\n bval = ( ( ( - 3.0D+00 &\n * u + 3.0D+00 ) &\n * u + 3.0D+00 ) &\n * u + 1.0D+00 ) / 6.0D+00\n\n yval = yval + ydata(right) * bval\n!\n! B function associated with node RIGHT+1, (or \"phantom node\"),\n! evaluated in its first interval.\n!\n bval = u**3 / 6.0D+00\n\n if ( right+1 <= ndata ) then\n yval = yval + ydata(right+1) * bval\n else\n yval = yval + ( 2.0D+00 * ydata(ndata) - ydata(ndata-1) ) * bval\n end if\n\n return\nend\nsubroutine spline_beta_val ( beta1, beta2, ndata, tdata, ydata, tval, yval )\n\n!*****************************************************************************80\n!\n!! SPLINE_BETA_VAL evaluates a cubic beta spline approximant.\n!\n! Discussion:\n!\n! The cubic beta spline will approximate the data, but is not\n! designed to interpolate it.\n!\n! If BETA1 = 1 and BETA2 = 0, the cubic beta spline will be the\n! same as the cubic B spline approximant.\n!\n! With BETA1 = 1 and BETA2 large, the beta spline becomes more like\n! a linear spline.\n!\n! In effect, two \"phantom\" data values are appended to the data,\n! so that the spline will interpolate the first and last data values.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 11 February 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) BETA1, the skew or bias parameter.\n! BETA1 = 1 for no skew or bias.\n!\n! Input, real ( kind = 8 ) BETA2, the tension parameter.\n! BETA2 = 0 for no tension.\n!\n! Input, integer ( kind = 4 ) NDATA, the number of data values.\n!\n! Input, real ( kind = 8 ) TDATA(NDATA), the abscissas of the data.\n!\n! Input, real ( kind = 8 ) YDATA(NDATA), the data values.\n!\n! Input, real ( kind = 8 ) TVAL, a point at which the spline is\n! to be evaluated.\n!\n! Output, real ( kind = 8 ) YVAL, the value of the function at TVAL.\n!\n implicit none\n\n integer ( kind = 4 ) ndata\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) beta1\n real ( kind = 8 ) beta2\n real ( kind = 8 ) bval\n real ( kind = 8 ) c\n real ( kind = 8 ) d\n real ( kind = 8 ) delta\n integer ( kind = 4 ) left\n integer ( kind = 4 ) right\n real ( kind = 8 ) tdata(ndata)\n real ( kind = 8 ) tval\n real ( kind = 8 ) u\n real ( kind = 8 ) ydata(ndata)\n real ( kind = 8 ) yval\n!\n! Find the nearest interval [ TDATA(LEFT), TDATA(RIGHT) ] to TVAL.\n!\n call r8vec_bracket ( ndata, tdata, tval, left, right )\n!\n! Evaluate the 5 nonzero beta spline basis functions in the interval,\n! weighted by their corresponding data values.\n!\n u = ( tval - tdata(left) ) / ( tdata(right) - tdata(left) )\n\n delta = ( ( 2.0D+00 &\n * beta1 + 4.0D+00 ) &\n * beta1 + 4.0D+00 ) &\n * beta1 + 2.0D+00 + beta2\n\n yval = 0.0D+00\n!\n! Beta function associated with node LEFT - 1, (or \"phantom node\"),\n! evaluated in its 4th interval.\n!\n bval = 2.0D+00 * ( beta1 * ( 1.0D+00 - u ) )**3 / delta\n\n if ( 0 < left-1 ) then\n yval = yval + ydata(left-1) * bval\n else\n yval = yval + ( 2.0D+00 * ydata(1) - ydata(2) ) * bval\n end if\n!\n! Beta function associated with node LEFT,\n! evaluated in its third interval.\n!\n a = beta2 + ( 4.0D+00 + 4.0D+00 * beta1 ) * beta1\n\n b = - 6.0D+00 * beta1 * ( 1.0D+00 - beta1 ) * ( 1.0D+00 + beta1 )\n\n c = ( ( - 6.0D+00 &\n * beta1 - 6.0D+00 ) &\n * beta1 + 0.0D+00 ) &\n * beta1 - 3.0D+00 * beta2\n\n d = ( ( + 2.0D+00 &\n * beta1 + 2.0D+00 ) &\n * beta1 + 2.0D+00 ) &\n * beta1 + 2.0D+00 * beta2\n\n bval = ( a + u * ( b + u * ( c + u * d ) ) ) / delta\n\n yval = yval + ydata(left) * bval\n!\n! Beta function associated with node RIGHT,\n! evaluated in its second interval.\n!\n a = 2.0D+00\n\n b = 6.0D+00 * beta1\n\n c = 3.0D+00 * beta2 + 6.0D+00 * beta1 * beta1\n\n d = - 2.0D+00 * ( 1.0D+00 + beta2 + beta1 + beta1 * beta1 )\n\n bval = ( a + u * ( b + u * ( c + u * d ) ) ) / delta\n\n yval = yval + ydata(right) * bval\n!\n! Beta function associated with node RIGHT+1, (or \"phantom node\"),\n! evaluated in its first interval.\n!\n bval = 2.0D+00 * u**3 / delta\n\n if ( right + 1 <= ndata ) then\n yval = yval + ydata(right+1) * bval\n else\n yval = yval + ( 2.0D+00 * ydata(ndata) - ydata(ndata-1) ) * bval\n end if\n\n return\nend\nsubroutine spline_bezier_val ( dim_num, interval_num, data_val, point_num, &\n point_t, point_val )\n\n!*****************************************************************************80\n!\n!! SPLINE_BEZIER_VAL evaluates a cubic Bezier spline.\n!\n! Discussion:\n!\n! The cubic Bezier spline of N parts is defined by choosing\n! 3*N+1 equally spaced T-abscissa values in the interval [0,N].\n! This defines N subintervals, each of length 1, and each containing\n! 4 successives T abscissa values.\n!\n! At each abscissa value, a DIM_NUM-dimensional Bezier control\n! value is assigned. Over each interval, a Bezier cubic function\n! is used to define the value of the Bezier spline. To the left of\n! the first interval, or to the right of the last interval,\n! extrapolation may be used to extend the spline definition to\n! the entire real line.\n!\n! Note that the Bezier spline will pass through the 1st, 4th,\n! and in general 3*I+1 control values exactly. The other control\n! values are not interpolating points.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 17 June 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) DIM_NUM, the spatial dimension.\n!\n! Input, integer ( kind = 4 ) INTERVAL_NUM, the number of intervals.\n!\n! Input, real ( kind = 8 ) DATA_VAL(DIM_NUM,3*INTERVAL_NUM+1), the control\n! values.\n!\n! Input, integer ( kind = 4 ) POINT_NUM, the number of sample points at\n! which the Bezier cubic spline is to be evaluated.\n!\n! Input, real ( kind = 8 ) POINT_T(POINT_NUM), the \"T\" values associated\n! with the points. A value of T between 0 and 1, for instance,\n! is associated with the first interval, and a value of T between\n! INTERVAL_NUM-1 and INTERVAL_NUM is in the last interval.\n!\n! Output, real ( kind = 8 ) POINT_VAL(DIM_NUM,POINT_NUM), the value\n! of the Bezier cubic spline at the sample points.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: cubic = 3\n integer ( kind = 4 ) interval_num\n integer ( kind = 4 ) dim_num\n integer ( kind = 4 ) point_num\n\n real ( kind = 8 ) bernstein_val(0:cubic)\n real ( kind = 8 ) data_val(dim_num,cubic*interval_num+1)\n integer ( kind = 4 ) dim\n integer ( kind = 4 ) interval\n integer ( kind = 4 ) offset\n integer ( kind = 4 ) point\n real ( kind = 8 ) point_t(point_num)\n real ( kind = 8 ) point_val(dim_num,point_num)\n real ( kind = 8 ) t\n real ( kind = 8 ) t_01\n\n do point = 1, point_num\n\n t = point_t(point)\n\n interval = int ( t + 1 )\n\n interval = max ( interval, 1 )\n interval = min ( interval, interval_num )\n\n offset = 1 + ( interval - 1 ) * cubic\n\n t_01 = t - real ( interval - 1, kind = 8 )\n\n call bp01 ( cubic, t_01, bernstein_val )\n\n do dim = 1, dim_num\n point_val(dim,point) = dot_product ( &\n data_val(dim,offset:offset+cubic), bernstein_val(0:cubic) )\n end do\n\n end do\n\n return\nend\nsubroutine spline_constant_val ( ndata, tdata, ydata, tval, yval )\n\n!*****************************************************************************80\n!\n!! SPLINE_CONSTANT_VAL evaluates a piecewise constant spline at a point.\n!\n! Discussion:\n!\n! NDATA-1 points TDATA define NDATA intervals, with the first\n! and last being semi-infinite.\n!\n! The value of the spline anywhere in interval I is YDATA(I).\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 November 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NDATA, the number of data points defining\n! the spline. NDATA must be at least 1.\n!\n! Input, real ( kind = 8 ) TDATA(NDATA-1), the breakpoints. The values\n! of TDATA should be distinct and increasing.\n!\n! Input, real ( kind = 8 ) YDATA(NDATA), the values of the spline in\n! the intervals defined by the breakpoints.\n!\n! Input, real ( kind = 8 ) TVAL, the point at which the spline is\n! to be evaluated.\n!\n! Output, real ( kind = 8 ) YVAL, the value of the spline at TVAL.\n!\n implicit none\n\n integer ( kind = 4 ) ndata\n\n integer ( kind = 4 ) i\n real ( kind = 8 ) tdata(ndata-1)\n real ( kind = 8 ) tval\n real ( kind = 8 ) ydata(ndata)\n real ( kind = 8 ) yval\n!\n! Check NDATA.\n!\n if ( ndata < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_CONSTANT_VAL - Fatal error!'\n write ( *, '(a)' ) ' NDATA < 1.'\n stop 1\n end if\n\n do i = 1, ndata-1\n if ( tval <= tdata(i) ) then\n yval = ydata(i)\n return\n end if\n end do\n\n yval = ydata(ndata)\n\n return\nend\nsubroutine spline_cubic_set_full ( n, t, y, ibcbeg, ybcbeg, ibcend, ybcend, &\n ypp )\n\n!*****************************************************************************80\n!\n!! SPLINE_CUBIC_SET_FULL computes second derivatives of piecewise cubic spline.\n!\n! Discussion:\n!\n! DELETE THIS FUNCTION WHEN YOU ARE SATISFIED WITH THE CURRENT\n! VERSION OF SPLINE_CUBIC_SET.\n!\n! For data interpolation, the user must call SPLINE_CUBIC_SET to\n! determine the second derivative data, passing in the data to be\n! interpolated, and the desired boundary conditions.\n!\n! The data to be interpolated, plus the SPLINE_CUBIC_SET output,\n! defines the spline. The user may then call SPLINE_CUBIC_VAL to\n! evaluate the spline at any point.\n!\n! The cubic spline is a piecewise cubic polynomial. The intervals\n! are determined by the \"knots\" or abscissas of the data to be\n! interpolated. The cubic spline has continous first and second\n! derivatives over the entire interval of interpolation.\n!\n! For any point T in the interval T(IVAL), T(IVAL+1), the form of\n! the spline is\n!\n! SPL(T) = A(IVAL)\n! + B(IVAL) * ( T - T(IVAL) )\n! + C(IVAL) * ( T - T(IVAL) )^2\n! + D(IVAL) * ( T - T(IVAL) )^3\n!\n! If we assume that we know the values Y(*) and YPP(*), which represent\n! the values and second derivatives of the spline at each knot, then\n! the coefficients can be computed as:\n!\n! A(IVAL) = Y(IVAL)\n! B(IVAL) = ( Y(IVAL+1) - Y(IVAL) ) / ( T(IVAL+1) - T(IVAL) )\n! - ( YPP(IVAL+1) + 2 * YPP(IVAL) ) * ( T(IVAL+1) - T(IVAL) ) / 6\n! C(IVAL) = YPP(IVAL) / 2\n! D(IVAL) = ( YPP(IVAL+1) - YPP(IVAL) ) / ( 6 * ( T(IVAL+1) - T(IVAL) ) )\n!\n! Since the first derivative of the spline is\n!\n! SPL'(T) = B(IVAL)\n! + 2 * C(IVAL) * ( T - T(IVAL) )\n! + 3 * D(IVAL) * ( T - T(IVAL) )^2,\n!\n! the requirement that the first derivative be continuous at interior\n! knot I results in a total of N-2 equations, of the form:\n!\n! B(IVAL-1) + 2 C(IVAL-1) * (T(IVAL)-T(IVAL-1))\n! + 3 * D(IVAL-1) * (T(IVAL) - T(IVAL-1))^2 = B(IVAL)\n!\n! or, setting H(IVAL) = T(IVAL+1) - T(IVAL)\n!\n! ( Y(IVAL) - Y(IVAL-1) ) / H(IVAL-1)\n! - ( YPP(IVAL) + 2 * YPP(IVAL-1) ) * H(IVAL-1) / 6\n! + YPP(IVAL-1) * H(IVAL-1)\n! + ( YPP(IVAL) - YPP(IVAL-1) ) * H(IVAL-1) / 2\n! =\n! ( Y(IVAL+1) - Y(IVAL) ) / H(IVAL)\n! - ( YPP(IVAL+1) + 2 * YPP(IVAL) ) * H(IVAL) / 6\n!\n! or\n!\n! YPP(IVAL-1) * H(IVAL-1) + 2 * YPP(IVAL) * ( H(IVAL-1) + H(IVAL) )\n! + YPP(IVAL) * H(IVAL)\n! =\n! 6 * ( Y(IVAL+1) - Y(IVAL) ) / H(IVAL)\n! - 6 * ( Y(IVAL) - Y(IVAL-1) ) / H(IVAL-1)\n!\n! Boundary conditions must be applied at the first and last knots.\n! The resulting tridiagonal system can be solved for the YPP values.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 June 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Carl deBoor,\n! A Practical Guide to Splines,\n! Springer, 2001,\n! ISBN: 0387953663.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of data points; N must be\n! at least 2.\n!\n! Input, real ( kind = 8 ) T(N), the points where data is specified.\n! The values should be distinct, and increasing.\n!\n! Input, real ( kind = 8 ) Y(N), the data values to be interpolated.\n!\n! Input, integer ( kind = 4 ) IBCBEG, the left boundary condition flag:\n! 0: the spline should be a quadratic over the first interval;\n! 1: the first derivative at the left endpoint should be YBCBEG;\n! 2: the second derivative at the left endpoint should be YBCBEG;\n! 3: Not-a-knot: the third derivative is continuous at T(2).\n!\n! Input, real ( kind = 8 ) YBCBEG, the left boundary value, if needed.\n!\n! Input, integer ( kind = 4 ) IBCEND, the right boundary condition flag:\n! 0: the spline should be a quadratic over the last interval;\n! 1: the first derivative at the right endpoint should be YBCEND;\n! 2: the second derivative at the right endpoint should be YBCEND;\n! 3: Not-a-knot: the third derivative is continuous at T(N-1).\n!\n! Input, real ( kind = 8 ) YBCEND, the right boundary value, if needed.\n!\n! Output, real ( kind = 8 ) YPP(N), the second derivatives of\n! the cubic spline.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n,n)\n real ( kind = 8 ) b(n)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) ibcbeg\n integer ( kind = 4 ) ibcend\n integer ( kind = 4 ) info\n real ( kind = 8 ) t(n)\n real ( kind = 8 ) y(n)\n real ( kind = 8 ) ybcbeg\n real ( kind = 8 ) ybcend\n real ( kind = 8 ) ypp(n)\n!\n! Check.\n!\n if ( n <= 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_CUBIC_SET - Fatal error!'\n write ( *, '(a)' ) ' The number of knots must be at least 2.'\n write ( *, '(a,i8)' ) ' The input value of N = ', n\n stop 1\n end if\n\n do i = 1, n - 1\n if ( t(i+1) <= t(i) ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_CUBIC_SET - Fatal error!'\n write ( *, '(a)' ) ' The knots must be strictly increasing, but'\n write ( *, '(a,i8,a,g14.6)' ) ' T(', i,') = ', t(i)\n write ( *, '(a,i8,a,g14.6)' ) ' T(',i+1,') = ', t(i+1)\n stop 1\n end if\n end do\n!\n! Zero out the matrix.\n!\n a(1:n,1:n) = 0.0D+00\n!\n! Set the first equation.\n!\n if ( ibcbeg == 0 ) then\n b(1) = 0.0D+00\n a(1,1) = 1.0D+00\n a(1,2) = -1.0D+00\n else if ( ibcbeg == 1 ) then\n b(1) = ( y(2) - y(1) ) / ( t(2) - t(1) ) - ybcbeg\n a(1,1) = ( t(2) - t(1) ) / 3.0D+00\n a(1,2) = ( t(2) - t(1) ) / 6.0D+00\n else if ( ibcbeg == 2 ) then\n b(1) = ybcbeg\n a(1,1) = 1.0D+00\n a(1,2) = 0.0D+00\n else if ( ibcbeg == 3 ) then\n b(1) = 0.0D+00\n a(1,1) = - ( t(3) - t(2) )\n a(1,2) = ( t(3) - t(1) )\n a(1,3) = - ( t(2) - t(1) )\n else\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_CUBIC_SET - Fatal error!'\n write ( *, '(a)' ) ' The boundary flag IBCBEG must be 0, 1, 2 or 3.'\n write ( *, '(a,i8)' ) ' The input value is IBCBEG = ', ibcbeg\n stop 1\n end if\n!\n! Set the intermediate equations.\n!\n do i = 2, n - 1\n b(i) = ( y(i+1) - y(i) ) / ( t(i+1) - t(i) ) &\n - ( y(i) - y(i-1) ) / ( t(i) - t(i-1) )\n a(i,i-1) = ( t(i) - t(i-1) ) / 6.0D+00\n a(i,i) = ( t(i+1) - t(i-1) ) / 3.0D+00\n a(i,i+1) = ( t(i+1) - t(i) ) / 6.0D+00\n end do\n!\n! Set the last equation.\n!\n if ( ibcend == 0 ) then\n b(n) = 0.0D+00\n a(n,n-1) = -1.0D+00\n a(n,n) = 1.0D+00\n else if ( ibcend == 1 ) then\n b(n) = ybcend - ( y(n) - y(n-1) ) / ( t(n) - t(n-1) )\n a(n,n-1) = ( t(n) - t(n-1) ) / 6.0D+00\n a(n,n) = ( t(n) - t(n-1) ) / 3.0D+00\n else if ( ibcend == 2 ) then\n b(n) = ybcend\n a(n,n-1) = 0.0D+00\n a(n,n) = 1.0D+00\n else if ( ibcend == 3 ) then\n b(n) = 0.0D+00\n a(n,n-2) = - ( t(n) - t(n-1) )\n a(n,n-1) = ( t(n) - t(n-2) )\n a(n,n) = - ( t(n-1) - t(n-2) )\n else\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_CUBIC_SET - Fatal error!'\n write ( *, '(a)' ) ' The boundary flag IBCEND must be 0, 1, 2 or 3.'\n write ( *, '(a,i8)' ) ' The input value is IBCEND = ', ibcend\n stop 1\n end if\n!\n! Special case:\n! N = 2, IBCBEG = IBCEND = 0.\n!\n if ( n == 2 .and. ibcbeg == 0 .and. ibcend == 0 ) then\n\n ypp(1) = 0.0D+00\n ypp(2) = 0.0D+00\n!\n! Solve the linear system.\n!\n else\n\n call r8ge_fs ( n, a, b, info )\n ypp = b\n\n end if\n\n return\nend\nsubroutine spline_cubic_set ( n, t, y, ibcbeg, ybcbeg, ibcend, ybcend, ypp )\n\n!*****************************************************************************80\n!\n!! SPLINE_CUBIC_SET computes the second derivatives of a piecewise cubic spline.\n!\n! Discussion:\n!\n! For data interpolation, the user must call SPLINE_CUBIC_SET to\n! determine the second derivative data, passing in the data to be\n! interpolated, and the desired boundary conditions.\n!\n! The data to be interpolated, plus the SPLINE_CUBIC_SET output,\n! defines the spline. The user may then call SPLINE_CUBIC_VAL to\n! evaluate the spline at any point.\n!\n! The cubic spline is a piecewise cubic polynomial. The intervals\n! are determined by the \"knots\" or abscissas of the data to be\n! interpolated. The cubic spline has continous first and second\n! derivatives over the entire interval of interpolation.\n!\n! For any point T in the interval T(IVAL), T(IVAL+1), the form of\n! the spline is\n!\n! SPL(T) = A(IVAL)\n! + B(IVAL) * ( T - T(IVAL) )\n! + C(IVAL) * ( T - T(IVAL) )^2\n! + D(IVAL) * ( T - T(IVAL) )^3\n!\n! If we assume that we know the values Y(*) and YPP(*), which represent\n! the values and second derivatives of the spline at each knot, then\n! the coefficients can be computed as:\n!\n! A(IVAL) = Y(IVAL)\n! B(IVAL) = ( Y(IVAL+1) - Y(IVAL) ) / ( T(IVAL+1) - T(IVAL) )\n! - ( YPP(IVAL+1) + 2 * YPP(IVAL) ) * ( T(IVAL+1) - T(IVAL) ) / 6\n! C(IVAL) = YPP(IVAL) / 2\n! D(IVAL) = ( YPP(IVAL+1) - YPP(IVAL) ) / ( 6 * ( T(IVAL+1) - T(IVAL) ) )\n!\n! Since the first derivative of the spline is\n!\n! SPL'(T) = B(IVAL)\n! + 2 * C(IVAL) * ( T - T(IVAL) )\n! + 3 * D(IVAL) * ( T - T(IVAL) )^2,\n!\n! the requirement that the first derivative be continuous at interior\n! knot I results in a total of N-2 equations, of the form:\n!\n! B(IVAL-1) + 2 C(IVAL-1) * (T(IVAL)-T(IVAL-1))\n! + 3 * D(IVAL-1) * (T(IVAL) - T(IVAL-1))^2 = B(IVAL)\n!\n! or, setting H(IVAL) = T(IVAL+1) - T(IVAL)\n!\n! ( Y(IVAL) - Y(IVAL-1) ) / H(IVAL-1)\n! - ( YPP(IVAL) + 2 * YPP(IVAL-1) ) * H(IVAL-1) / 6\n! + YPP(IVAL-1) * H(IVAL-1)\n! + ( YPP(IVAL) - YPP(IVAL-1) ) * H(IVAL-1) / 2\n! =\n! ( Y(IVAL+1) - Y(IVAL) ) / H(IVAL)\n! - ( YPP(IVAL+1) + 2 * YPP(IVAL) ) * H(IVAL) / 6\n!\n! or\n!\n! YPP(IVAL-1) * H(IVAL-1) + 2 * YPP(IVAL) * ( H(IVAL-1) + H(IVAL) )\n! + YPP(IVAL) * H(IVAL)\n! =\n! 6 * ( Y(IVAL+1) - Y(IVAL) ) / H(IVAL)\n! - 6 * ( Y(IVAL) - Y(IVAL-1) ) / H(IVAL-1)\n!\n! Boundary conditions must be applied at the first and last knots.\n! The resulting tridiagonal system can be solved for the YPP values.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 07 June 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Carl deBoor,\n! A Practical Guide to Splines,\n! Springer, 2001,\n! ISBN: 0387953663.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of data points; N must be\n! at least 2.\n!\n! Input, real ( kind = 8 ) T(N), the points where data is specified.\n! The values should be distinct, and increasing.\n!\n! Input, real ( kind = 8 ) Y(N), the data values to be interpolated.\n!\n! Input, integer ( kind = 4 ) IBCBEG, the left boundary condition flag:\n! 0: the spline should be a quadratic over the first interval;\n! 1: the first derivative at the left endpoint should be YBCBEG;\n! 2: the second derivative at the left endpoint should be YBCBEG;\n! 3: Not-a-knot: the third derivative is continuous at T(2).\n!\n! Input, real ( kind = 8 ) YBCBEG, the left boundary value, if needed.\n!\n! Input, integer ( kind = 4 ) IBCEND, the right boundary condition flag:\n! 0: the spline should be a quadratic over the last interval;\n! 1: the first derivative at the right endpoint should be YBCEND;\n! 2: the second derivative at the right endpoint should be YBCEND;\n! 3: Not-a-knot: the third derivative is continuous at T(N-1).\n!\n! Input, real ( kind = 8 ) YBCEND, the right boundary value, if needed.\n!\n! Output, real ( kind = 8 ) YPP(N), the second derivatives of\n! the cubic spline.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a1(n)\n real ( kind = 8 ) a2(n)\n real ( kind = 8 ) a3(n)\n real ( kind = 8 ) a4(n)\n real ( kind = 8 ) a5(n)\n real ( kind = 8 ) b(n)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) ibcbeg\n integer ( kind = 4 ) ibcend\n real ( kind = 8 ) t(n)\n real ( kind = 8 ) y(n)\n real ( kind = 8 ) ybcbeg\n real ( kind = 8 ) ybcend\n real ( kind = 8 ) ypp(n)\n!\n! Check.\n!\n if ( n <= 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_CUBIC_SET - Fatal error!'\n write ( *, '(a)' ) ' The number of knots must be at least 2.'\n write ( *, '(a,i8)' ) ' The input value of N = ', n\n stop 1\n end if\n\n do i = 1, n - 1\n if ( t(i+1) <= t(i) ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_CUBIC_SET - Fatal error!'\n write ( *, '(a)' ) ' The knots must be strictly increasing, but'\n write ( *, '(a,i8,a,g14.6)' ) ' T(', i,') = ', t(i)\n write ( *, '(a,i8,a,g14.6)' ) ' T(',i+1,') = ', t(i+1)\n stop 1\n end if\n end do\n!\n! Zero out the matrix.\n!\n a1(1:n) = 0.0D+00\n a2(1:n) = 0.0D+00\n a3(1:n) = 0.0D+00\n a4(1:n) = 0.0D+00\n a5(1:n) = 0.0D+00\n!\n! Set the first equation.\n!\n if ( ibcbeg == 0 ) then\n b(1) = 0.0D+00\n a3(1) = 1.0D+00\n a4(1) = -1.0D+00\n else if ( ibcbeg == 1 ) then\n b(1) = ( y(2) - y(1) ) / ( t(2) - t(1) ) - ybcbeg\n a3(1) = ( t(2) - t(1) ) / 3.0D+00\n a4(1) = ( t(2) - t(1) ) / 6.0D+00\n else if ( ibcbeg == 2 ) then\n b(1) = ybcbeg\n a3(1) = 1.0D+00\n a4(1) = 0.0D+00\n else if ( ibcbeg == 3 ) then\n b(1) = 0.0D+00\n a3(1) = - ( t(3) - t(2) )\n a4(1) = ( t(3) - t(1) )\n a5(1) = - ( t(2) - t(1) )\n else\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_CUBIC_SET - Fatal error!'\n write ( *, '(a)' ) ' The boundary flag IBCBEG must be 0, 1, 2 or 3.'\n write ( *, '(a,i8)' ) ' The input value is IBCBEG = ', ibcbeg\n stop 1\n end if\n!\n! Set the intermediate equations.\n!\n do i = 2, n - 1\n b(i) = ( y(i+1) - y(i) ) / ( t(i+1) - t(i) ) &\n - ( y(i) - y(i-1) ) / ( t(i) - t(i-1) )\n a2(i) = ( t(i+1) - t(i) ) / 6.0D+00\n a3(i) = ( t(i+1) - t(i-1) ) / 3.0D+00\n a4(i) = ( t(i) - t(i-1) ) / 6.0D+00\n end do\n!\n! Set the last equation.\n!\n if ( ibcend == 0 ) then\n b(n) = 0.0D+00\n a2(n) = -1.0D+00\n a3(n) = 1.0D+00\n else if ( ibcend == 1 ) then\n b(n) = ybcend - ( y(n) - y(n-1) ) / ( t(n) - t(n-1) )\n a2(n) = ( t(n) - t(n-1) ) / 6.0D+00\n a3(n) = ( t(n) - t(n-1) ) / 3.0D+00\n else if ( ibcend == 2 ) then\n b(n) = ybcend\n a2(n) = 0.0D+00\n a3(n) = 1.0D+00\n else if ( ibcend == 3 ) then\n b(n) = 0.0D+00\n a1(n) = - ( t(n) - t(n-1) )\n a2(n) = ( t(n) - t(n-2) )\n a3(n) = - ( t(n-1) - t(n-2) )\n else\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_CUBIC_SET - Fatal error!'\n write ( *, '(a)' ) ' The boundary flag IBCEND must be 0, 1, 2 or 3.'\n write ( *, '(a,i8)' ) ' The input value is IBCEND = ', ibcend\n stop 1\n end if\n!\n! Special case:\n! N = 2, IBCBEG = IBCEND = 0.\n!\n if ( n == 2 .and. ibcbeg == 0 .and. ibcend == 0 ) then\n\n ypp(1) = 0.0D+00\n ypp(2) = 0.0D+00\n!\n! Solve the linear system.\n!\n else\n\n call penta ( n, a1, a2, a3, a4, a5, b, ypp )\n\n end if\n\n return\nend\nsubroutine penta ( n, a1, a2, a3, a4, a5, b, x )\n\n!*****************************************************************************80\n!\n!! PENTA solves a pentadiagonal system of linear equations.\n!\n! Discussion:\n!\n! The matrix A is pentadiagonal. It is entirely zero, except for\n! the main diagaonal, and the two immediate sub- and super-diagonals.\n!\n! The entries of Row I are stored as:\n!\n! A(I,I-2) -> A1(I)\n! A(I,I-1) -> A2(I)\n! A(I,I) -> A3(I)\n! A(I,I+1) -> A4(I)\n! A(I,I-2) -> A5(I)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 07 June 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Cheney, Kincaid,\n! Numerical Mathematics and Computing,\n! 1985, pages 233-236.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the matrix.\n!\n! Input, real ( kind = 8 ) A1(N), A2(N), A3(N), A4(N), A5(N), the nonzero\n! elements of the matrix. Note that the data in A2, A3 and A4\n! is overwritten by this routine during the solution process.\n!\n! Input, real ( kind = 8 ) B(N), the right hand side of the linear system.\n!\n! Output, real ( kind = 8 ) X(N), the solution of the linear system.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a1(n)\n real ( kind = 8 ) a2(n)\n real ( kind = 8 ) a3(n)\n real ( kind = 8 ) a4(n)\n real ( kind = 8 ) a5(n)\n real ( kind = 8 ) b(n)\n integer ( kind = 4 ) i\n real ( kind = 8 ) x(n)\n real ( kind = 8 ) xmult\n\n do i = 2, n - 1\n xmult = a2(i) / a3(i-1)\n a3(i) = a3(i) - xmult * a4(i-1)\n a4(i) = a4(i) - xmult * a5(i-1)\n b(i) = b(i) - xmult * b(i-1)\n xmult = a1(i+1) / a3(i-1)\n a2(i+1) = a2(i+1) - xmult * a4(i-1)\n a3(i+1) = a3(i+1) - xmult * a5(i-1)\n b(i+1) = b(i+1) - xmult * b(i-1)\n end do\n\n xmult = a2(n) / a3(n-1)\n a3(n) = a3(n) - xmult * a4(n-1)\n x(n) = ( b(n) - xmult * b(n-1) ) / a3(n)\n x(n-1) = ( b(n-1) - a4(n-1) * x(n) ) / a3(n-1)\n do i = n - 2, 1, -1\n x(i) = ( b(i) - a4(i) * x(i+1) - a5(i) * x(i+2) ) / a3(i)\n end do\n\n return\nend\nsubroutine spline_cubic_val ( n, t, y, ypp, tval, yval, ypval, yppval )\n\n!*****************************************************************************80\n!\n!! SPLINE_CUBIC_VAL evaluates a piecewise cubic spline at a point.\n!\n! Discussion:\n!\n! SPLINE_CUBIC_SET must have already been called to define the\n! values of YPP.\n!\n! For any point T in the interval T(IVAL), T(IVAL+1), the form of\n! the spline is\n!\n! SPL(T) = A\n! + B * ( T - T(IVAL) )\n! + C * ( T - T(IVAL) )^2\n! + D * ( T - T(IVAL) )^3\n!\n! Here:\n! A = Y(IVAL)\n! B = ( Y(IVAL+1) - Y(IVAL) ) / ( T(IVAL+1) - T(IVAL) )\n! - ( YPP(IVAL+1) + 2 * YPP(IVAL) ) * ( T(IVAL+1) - T(IVAL) ) / 6\n! C = YPP(IVAL) / 2\n! D = ( YPP(IVAL+1) - YPP(IVAL) ) / ( 6 * ( T(IVAL+1) - T(IVAL) ) )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 November 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Carl deBoor,\n! A Practical Guide to Splines,\n! Springer, 2001,\n! ISBN: 0387953663.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of data values.\n!\n! Input, real ( kind = 8 ) T(N), the knot values.\n!\n! Input, real ( kind = 8 ) Y(N), the data values at the knots.\n!\n! Input, real ( kind = 8 ) YPP(N), the second derivatives of the\n! spline at the knots.\n!\n! Input, real ( kind = 8 ) TVAL, a point, typically between T(1) and\n! T(N), at which the spline is to be evalulated. If TVAL lies outside\n! this range, extrapolation is used.\n!\n! Output, real ( kind = 8 ) YVAL, YPVAL, YPPVAL, the value of the spline, and\n! its first two derivatives at TVAL.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) dt\n real ( kind = 8 ) h\n integer ( kind = 4 ) left\n integer ( kind = 4 ) right\n real ( kind = 8 ) t(n)\n real ( kind = 8 ) tval\n real ( kind = 8 ) y(n)\n real ( kind = 8 ) ypp(n)\n real ( kind = 8 ) yppval\n real ( kind = 8 ) ypval\n real ( kind = 8 ) yval\n!\n! Determine the interval [T(LEFT), T(RIGHT)] that contains TVAL.\n! Values below T(1) or above T(N) use extrapolation.\n!\n call r8vec_bracket ( n, t, tval, left, right )\n!\n! Evaluate the polynomial.\n!\n dt = tval - t(left)\n h = t(right) - t(left)\n\n yval = y(left) &\n + dt * ( ( y(right) - y(left) ) / h &\n - ( ypp(right) / 6.0D+00 + ypp(left) / 3.0D+00 ) * h &\n + dt * ( 0.5D+00 * ypp(left) &\n + dt * ( ( ypp(right) - ypp(left) ) / ( 6.0D+00 * h ) ) ) )\n\n ypval = ( y(right) - y(left) ) / h &\n - ( ypp(right) / 6.0D+00 + ypp(left) / 3.0D+00 ) * h &\n + dt * ( ypp(left) &\n + dt * ( 0.5D+00 * ( ypp(right) - ypp(left) ) / h ) )\n\n yppval = ypp(left) + dt * ( ypp(right) - ypp(left) ) / h\n\n return\nend\nsubroutine spline_cubic_val2 ( n, t, y, ypp, left, tval, yval, ypval, yppval )\n\n!*****************************************************************************80\n!\n!! SPLINE_CUBIC_VAL2 evaluates a piecewise cubic spline at a point.\n!\n! Discussion:\n!\n! This routine is a modification of SPLINE_CUBIC_VAL; it allows the\n! user to speed up the code by suggesting the appropriate T interval\n! to search first.\n!\n! SPLINE_CUBIC_SET must have already been called to define the\n! values of YPP.\n!\n! In the LEFT interval, let RIGHT = LEFT+1. The form of the spline is\n!\n! SPL(T) =\n! A\n! + B * ( T - T(LEFT) )\n! + C * ( T - T(LEFT) )^2\n! + D * ( T - T(LEFT) )^3\n!\n! Here:\n! A = Y(LEFT)\n! B = ( Y(RIGHT) - Y(LEFT) ) / ( T(RIGHT) - T(LEFT) )\n! - ( YPP(RIGHT) + 2 * YPP(LEFT) ) * ( T(RIGHT) - T(LEFT) ) / 6\n! C = YPP(LEFT) / 2\n! D = ( YPP(RIGHT) - YPP(LEFT) ) / ( 6 * ( T(RIGHT) - T(LEFT) ) )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 February 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Carl deBoor,\n! A Practical Guide to Splines,\n! Springer, 2001,\n! ISBN: 0387953663.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of knots.\n!\n! Input, real ( kind = 8 ) T(N), the knot values.\n!\n! Input, real ( kind = 8 ) Y(N), the data values at the knots.\n!\n! Input, real ( kind = 8 ) YPP(N), the second derivatives of the spline at\n! the knots.\n!\n! Input/output, integer ( kind = 4 ) LEFT, the suggested T interval to\n! search. LEFT should be between 1 and N-1. If LEFT is not in this range,\n! then its value will be ignored. On output, LEFT is set to the\n! actual interval in which TVAL lies.\n!\n! Input, real ( kind = 8 ) TVAL, a point, typically between T(1) and T(N), at\n! which the spline is to be evalulated. If TVAL lies outside\n! this range, extrapolation is used.\n!\n! Output, real ( kind = 8 ) YVAL, YPVAL, YPPVAL, the value of the spline, and\n! its first two derivatives at TVAL.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) dt\n real ( kind = 8 ) h\n integer ( kind = 4 ) left\n integer ( kind = 4 ) right\n real ( kind = 8 ) t(n)\n real ( kind = 8 ) tval\n real ( kind = 8 ) y(n)\n real ( kind = 8 ) ypp(n)\n real ( kind = 8 ) yppval\n real ( kind = 8 ) ypval\n real ( kind = 8 ) yval\n!\n! Determine the interval [T(LEFT), T(RIGHT)] that contains TVAL.\n!\n! What you want from R8VEC_BRACKET3 is that TVAL is to be computed\n! by the data in interval [T(LEFT), T(RIGHT)].\n!\n call r8vec_bracket3 ( n, t, tval, left )\n right = left + 1\n!\n! In the interval LEFT, the polynomial is in terms of a normalized\n! coordinate ( DT / H ) between 0 and 1.\n!\n dt = tval - t(left)\n h = t(right) - t(left)\n\n yval = y(left) + dt * ( ( y(right) - y(left) ) / h &\n - ( ypp(right) / 6.0D+00 + ypp(left) / 3.0D+00 ) * h &\n + dt * ( 0.5D+00 * ypp(left) &\n + dt * ( ( ypp(right) - ypp(left) ) / ( 6.0D+00 * h ) ) ) )\n\n ypval = ( y(right) - y(left) ) / h &\n - ( ypp(right) / 6.0D+00 + ypp(left) / 3.0D+00 ) * h &\n + dt * ( ypp(left) &\n + dt * ( 0.5D+00 * ( ypp(right) - ypp(left) ) / h ) )\n\n yppval = ypp(left) + dt * ( ypp(right) - ypp(left) ) / h\n\n return\nend\nsubroutine spline_hermite_set ( ndata, tdata, ydata, ypdata, c )\n\n!*****************************************************************************80\n!\n!! SPLINE_HERMITE_SET sets up a piecewise cubic Hermite interpolant.\n!\n! Discussion:\n!\n! Once the array C is computed, then in the interval\n! (TDATA(I), TDATA(I+1)), the interpolating Hermite polynomial\n! is given by\n!\n! SVAL(TVAL) = C(1,I)\n! + ( TVAL - TDATA(I) ) * ( C(2,I)\n! + ( TVAL - TDATA(I) ) * ( C(3,I)\n! + ( TVAL - TDATA(I) ) * C(4,I) ) )\n!\n! This is algorithm CALCCF of Conte and deBoor.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 11 February 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Samuel Conte, Carl deBoor,\n! Elementary Numerical Analysis,\n! Second Edition,\n! McGraw Hill, 1972,\n! ISBN: 07-012446-4,\n! LC: QA297.C65.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NDATA, the number of data points.\n! NDATA must be at least 2.\n!\n! Input, real ( kind = 8 ) TDATA(NDATA), the abscissas of the data points.\n! The entries of TDATA are assumed to be strictly increasing.\n!\n! Input, real ( kind = 8 ) Y(NDATA), YP(NDATA), the value of the\n! function and its derivative at TDATA(1:NDATA).\n!\n! Output, real ( kind = 8 ) C(4,NDATA), the coefficients of the\n! Hermite polynomial.\n! C(1,1:NDATA) = Y(1:NDATA) and C(2,1:NDATA) = YP(1:NDATA).\n! C(3,1:NDATA-1) and C(4,1:NDATA-1) are the quadratic and cubic\n! coefficients.\n!\n implicit none\n\n integer ( kind = 4 ) ndata\n\n real ( kind = 8 ) c(4,ndata)\n real ( kind = 8 ) divdif1\n real ( kind = 8 ) divdif3\n real ( kind = 8 ) dt\n integer ( kind = 4 ) i\n real ( kind = 8 ) tdata(ndata)\n real ( kind = 8 ) ydata(ndata)\n real ( kind = 8 ) ypdata(ndata)\n!\n! Check NDATA.\n!\n if ( ndata < 2 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_HERMITE_SET - Fatal error!'\n write ( *, '(a)' ) ' NDATA < 2.'\n stop 1\n end if\n\n c(1,1:ndata) = ydata(1:ndata)\n c(2,1:ndata) = ypdata(1:ndata)\n\n do i = 1, ndata - 1\n dt = tdata(i+1) - tdata(i)\n divdif1 = ( c(1,i+1) - c(1,i) ) / dt\n divdif3 = c(2,i) + c(2,i+1) - 2.0D+00 * divdif1\n c(3,i) = ( divdif1 - c(2,i) - divdif3 ) / dt\n c(4,i) = divdif3 / ( dt * dt )\n end do\n\n c(3,ndata) = 0.0D+00\n c(4,ndata) = 0.0D+00\n\n return\nend\nsubroutine spline_hermite_val ( ndata, tdata, c, tval, sval, spval )\n\n!*****************************************************************************80\n!\n!! SPLINE_HERMITE_VAL evaluates a piecewise cubic Hermite interpolant.\n!\n! Discussion:\n!\n! SPLINE_HERMITE_SET must be called first, to set up the\n! spline data from the raw function and derivative data.\n!\n! In the interval (TDATA(I), TDATA(I+1)), the interpolating\n! Hermite polynomial is given by\n!\n! SVAL(TVAL) = C(1,I)\n! + ( TVAL - TDATA(I) ) * ( C(2,I)\n! + ( TVAL - TDATA(I) ) * ( C(3,I)\n! + ( TVAL - TDATA(I) ) * C(4,I) ) )\n!\n! and\n!\n! SVAL'(TVAL) = C(2,I)\n! + ( TVAL - TDATA(I) ) * ( 2 * C(3,I)\n! + ( TVAL - TDATA(I) ) * 3 * C(4,I) )\n!\n! This is algorithm PCUBIC of Conte and deBoor.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 11 February 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Samuel Conte, Carl deBoor,\n! Elementary Numerical Analysis,\n! Second Edition,\n! McGraw Hill, 1972,\n! ISBN: 07-012446-4,\n! LC: QA297.C65.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NDATA, the number of data points.\n! NDATA must be at least 2.\n!\n! Input, real ( kind = 8 ) TDATA(NDATA), the abscissas of the data points.\n! The entries of TDATA are assumed to be strictly increasing.\n!\n! Input, real ( kind = 8 ) C(4,NDATA), the coefficient data computed by\n! SPLINE_HERMITE_SET.\n!\n! Input, real ( kind = 8 ) TVAL, the point where the interpolant is to\n! be evaluated.\n!\n! Output, real ( kind = 8 ) SVAL, SPVAL, the value of the interpolant\n! and its derivative at TVAL.\n!\n implicit none\n\n integer ( kind = 4 ) ndata\n\n real ( kind = 8 ) c(4,ndata)\n real ( kind = 8 ) dt\n integer ( kind = 4 ) left\n integer ( kind = 4 ) right\n real ( kind = 8 ) spval\n real ( kind = 8 ) sval\n real ( kind = 8 ) tdata(ndata)\n real ( kind = 8 ) tval\n!\n! Check NDATA.\n!\n if ( ndata < 2 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_HERMITE_VAL - Fatal error!'\n write ( *, '(a)' ) ' NDATA < 2.'\n stop 1\n end if\n!\n! Find the interval [ TDATA(LEFT), TDATA(RIGHT) ] that contains\n! or is nearest to TVAL.\n!\n call r8vec_bracket ( ndata, tdata, tval, left, right )\n!\n! Evaluate the cubic polynomial.\n!\n dt = tval - tdata(left)\n\n sval = c(1,left) + dt * ( c(2,left) + dt * ( c(3,left) + dt * c(4,left) ) )\n\n spval = c(2,left) + dt * ( 2.0D+00 * c(3,left) + dt * 3.0D+00 * c(4,left) )\n\n return\nend\nsubroutine spline_linear_int ( ndata, tdata, ydata, a, b, int_val )\n\n!*****************************************************************************80\n!\n!! SPLINE_LINEAR_INT evaluates the integral of a piecewise linear spline.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 November 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NDATA, the number of data points defining\n! the spline. NDATA must be at least 2.\n!\n! Input, real ( kind = 8 ) TDATA(NDATA), YDATA(NDATA), the values of\n! the independent and dependent variables at the data points. The\n! values of TDATA should be distinct and increasing.\n!\n! Input, real ( kind = 8 ) A, B, the interval over which the\n! integral is desired.\n!\n! Output, real ( kind = 8 ) INT_VAL, the value of the integral.\n!\n implicit none\n\n integer ( kind = 4 ) ndata\n\n real ( kind = 8 ) a\n real ( kind = 8 ) a_copy\n integer ( kind = 4 ) a_left\n integer ( kind = 4 ) a_right\n real ( kind = 8 ) b\n real ( kind = 8 ) b_copy\n integer ( kind = 4 ) b_left\n integer ( kind = 4 ) b_right\n integer ( kind = 4 ) i_left\n real ( kind = 8 ) int_val\n real ( kind = 8 ) tdata(ndata)\n real ( kind = 8 ) tval\n real ( kind = 8 ) ydata(ndata)\n real ( kind = 8 ) yp\n real ( kind = 8 ) yval\n!\n! Check NDATA.\n!\n if ( ndata < 2 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_LINEAR_INT - Fatal error!'\n write ( *, '(a)' ) ' NDATA < 2.'\n stop 1\n end if\n\n int_val = 0.0D+00\n\n if ( a == b ) then\n return\n end if\n\n a_copy = min ( a, b )\n b_copy = max ( a, b )\n!\n! Find the interval [ TDATA(A_LEFT), TDATA(A_RIGHT) ] that contains, or is\n! nearest to, A.\n!\n call r8vec_bracket ( ndata, tdata, a_copy, a_left, a_right )\n!\n! Find the interval [ TDATA(B_LEFT), TDATA(B_RIGHT) ] that contains, or is\n! nearest to, B.\n!\n call r8vec_bracket ( ndata, tdata, b_copy, b_left, b_right )\n!\n! If A and B are in the same interval...\n!\n if ( a_left == b_left ) then\n\n tval = ( a_copy + b_copy ) / 2.0D+00\n\n yp = ( ydata(a_right) - ydata(a_left) ) / &\n ( tdata(a_right) - tdata(a_left) )\n\n yval = ydata(a_left) + ( tval - tdata(a_left) ) * yp\n\n int_val = yval * ( b_copy - a_copy )\n\n return\n end if\n!\n! Otherwise, integrate from:\n!\n! A to TDATA(A_RIGHT),\n! TDATA(A_RIGHT) to TDATA(A_RIGHT+1),...\n! TDATA(B_LEFT-1) to TDATA(B_LEFT),\n! TDATA(B_LEFT) to B.\n!\n! Use the fact that the integral of a linear function is the\n! value of the function at the midpoint times the width of the interval.\n!\n tval = ( a_copy + tdata(a_right) ) / 2.0D+00\n\n yp = ( ydata(a_right) - ydata(a_left) ) / &\n ( tdata(a_right) - tdata(a_left) )\n\n yval = ydata(a_left) + ( tval - tdata(a_left) ) * yp\n\n int_val = int_val + yval * ( tdata(a_right) - a_copy )\n\n do i_left = a_right, b_left - 1\n\n tval = ( tdata(i_left+1) + tdata(i_left) ) / 2.0D+00\n\n yp = ( ydata(i_left+1) - ydata(i_left) ) / &\n ( tdata(i_left+1) - tdata(i_left) )\n\n yval = ydata(i_left) + ( tval - tdata(i_left) ) * yp\n\n int_val = int_val + yval * ( tdata(i_left + 1) - tdata(i_left) )\n\n end do\n\n tval = ( tdata(b_left) + b_copy ) / 2.0D+00\n\n yp = ( ydata(b_right) - ydata(b_left) ) / &\n ( tdata(b_right) - tdata(b_left) )\n\n yval = ydata(b_left) + ( tval - tdata(b_left) ) * yp\n\n int_val = int_val + yval * ( b_copy - tdata(b_left) )\n\n if ( b < a ) then\n int_val = - int_val\n end if\n\n return\nend\nsubroutine spline_linear_intset ( n, int_x, int_v, data_x, data_y )\n\n!*****************************************************************************80\n!\n!! SPLINE_LINEAR_INTSET: piecewise linear spline with given integral properties.\n!\n! Discussion:\n!\n! The user has in mind an interval, divided by INT_N+1 points into\n! INT_N intervals. A linear spline is to be constructed,\n! with breakpoints at the centers of each interval, and extending\n! continuously to the left of the first and right of the last\n! breakpoints. The constraint on the linear spline is that it is\n! required that it have a given integral value over each interval.\n!\n! A tridiagonal linear system of equations is solved for the\n! values of the spline at the breakpoints.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 27 January 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of intervals.\n!\n! Input, real ( kind = 8 ) INT_X(N+1), the points that define the intervals.\n! Interval I lies between INT_X(I) and INT_X(I+1).\n!\n! Input, real ( kind = 8 ) INT_V(N), the desired value of the integral of the\n! linear spline over each interval.\n!\n! Output, real ( kind = 8 ) DATA_X(N), DATA_Y(N), the values of the\n! independent and dependent variables at the data points. The values\n! of DATA_X are the interval midpoints. The values of DATA_Y are\n! determined in such a way that the exact integral of the linear\n! spline over interval I is equal to INT_V(I).\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(3,n)\n real ( kind = 8 ) data_x(n)\n real ( kind = 8 ) data_y(n)\n real ( kind = 8 ) int_v(n)\n real ( kind = 8 ) int_x(n+1)\n!\n! Set up the easy stuff.\n!\n data_x(1:n) = 0.5D+00 * ( int_x(1:n) + int_x(2:n+1) )\n!\n! Set up C, D, E, the coefficients of the linear system.\n!\n a(3,1:n-2) = 1.0D+00 &\n - ( 0.5D+00 * ( data_x(2:n-1) + int_x(2:n-1) ) - data_x(1:n-2) ) &\n / ( data_x(2:n-1) - data_x(1:n-2) )\n a(3,n-1) = 0.0D+00\n a(3,n) = 0.0D+00\n\n a(2,1) = int_x(2) - int_x(1)\n\n a(2,2:n-1) = 1.0D+00 &\n + ( 0.5D+00 * ( data_x(2:n-1) + int_x(2:n-1) ) &\n - data_x(1:n-2) ) &\n / ( data_x(2:n-1) - data_x(1:n-2) ) &\n - ( 0.5D+00 * ( data_x(2:n-1) + int_x(3:n) ) - data_x(2:n-1) ) &\n / ( data_x(3:n) - data_x(2:n-1) )\n\n a(2,n) = int_x(n+1) - int_x(n)\n\n a(1,1) = 0.0D+00\n a(1,2) = 0.0D+00\n\n a(1,3:n) = ( 0.5D+00 * ( data_x(2:n-1) + int_x(3:n) ) &\n - data_x(2:n-1) ) / ( data_x(3:n) - data_x(2:n-1) )\n!\n! Set up DATA_Y, which begins as the right hand side of the linear system.\n!\n data_y(1) = int_v(1)\n data_y(2:n-1) = 2.0D+00 * int_v(2:n-1) / ( int_x(3:n) - int_x(2:n-1) )\n data_y(n) = int_v(n)\n!\n! Solve the linear system.\n!\n call r83_np_fs ( n, a, data_y, data_y )\n\n return\nend\nsubroutine spline_linear_val ( ndata, tdata, ydata, tval, yval, ypval )\n\n!*****************************************************************************80\n!\n!! SPLINE_LINEAR_VAL evaluates a piecewise linear spline at a point.\n!\n! Discussion:\n!\n! Because of the extremely simple form of the linear spline,\n! the raw data points ( TDATA(I), YDATA(I)) can be used directly to\n! evaluate the spline at any point. No processing of the data\n! is required.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NDATA, the number of data points defining\n! the spline. NDATA must be at least 2.\n!\n! Input, real ( kind = 8 ) TDATA(NDATA), YDATA(NDATA), the values of\n! the independent and dependent variables at the data points. The\n! values of TDATA should be distinct and increasing.\n!\n! Input, real ( kind = 8 ) TVAL, the point at which the spline is\n! to be evaluated.\n!\n! Output, real ( kind = 8 ) YVAL, YPVAL, the value of the spline and\n! its first derivative dYdT at TVAL. YPVAL is not reliable if TVAL\n! is exactly equal to TDATA(I) for some I.\n!\n implicit none\n\n integer ( kind = 4 ) ndata\n\n integer ( kind = 4 ) left\n integer ( kind = 4 ) right\n real ( kind = 8 ) tdata(ndata)\n real ( kind = 8 ) tval\n real ( kind = 8 ) ydata(ndata)\n real ( kind = 8 ) ypval\n real ( kind = 8 ) yval\n!\n! Check NDATA.\n!\n if ( ndata < 2 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_LINEAR_VAL - Fatal error!'\n write ( *, '(a)' ) ' NDATA < 2.'\n stop 1\n end if\n!\n! Find the interval [ TDATA(LEFT), TDATA(RIGHT) ] that contains, or is\n! nearest to, TVAL.\n!\n call r8vec_bracket ( ndata, tdata, tval, left, right )\n!\n! Now evaluate the piecewise linear function.\n!\n ypval = ( ydata(right) - ydata(left) ) / ( tdata(right) - tdata(left) )\n\n yval = ydata(left) + ( tval - tdata(left) ) * ypval\n\n return\nend\nsubroutine spline_overhauser_nonuni_val ( ndata, tdata, ydata, tval, yval )\n\n!*****************************************************************************80\n!\n!! SPLINE_OVERHAUSER_NONUNI_VAL evaluates the nonuniform Overhauser spline.\n!\n! Discussion:\n!\n! The nonuniformity refers to the fact that the abscissa values\n! need not be uniformly spaced.\n!\n! Thanks to Doug Fortune for pointing out that the point distances\n! used to define ALPHA and BETA should be the Euclidean distances\n! between the points.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 08 May 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NDATA, the number of data points.\n! 3 <= NDATA is required.\n!\n! Input, real ( kind = 8 ) TDATA(NDATA), the abscissas of the data points.\n! The values of TDATA are assumed to be distinct and increasing.\n!\n! Input, real ( kind = 8 ) YDATA(NDATA), the data values.\n!\n! Input, real ( kind = 8 ) TVAL, the value where the spline is to\n! be evaluated.\n!\n! Output, real ( kind = 8 ) YVAL, the value of the spline at TVAL.\n!\n implicit none\n\n integer ( kind = 4 ) ndata\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ) beta\n real ( kind = 8 ) d21\n real ( kind = 8 ) d32\n real ( kind = 8 ) d43\n integer ( kind = 4 ) left\n real ( kind = 8 ) mbasis(4,4)\n real ( kind = 8 ) mbasis_l(3,3)\n real ( kind = 8 ) mbasis_r(3,3)\n integer ( kind = 4 ) right\n real ( kind = 8 ) tdata(ndata)\n real ( kind = 8 ) tval\n real ( kind = 8 ) ydata(ndata)\n real ( kind = 8 ) yval\n!\n! Check NDATA.\n!\n if ( ndata < 3 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_OVERHAUSER_NONUNI_VAL - Fatal error!'\n write ( *, '(a)' ) ' NDATA < 3.'\n stop 1\n end if\n!\n! Find the nearest interval [ TDATA(LEFT), TDATA(RIGHT) ] to TVAL.\n!\n call r8vec_bracket ( ndata, tdata, tval, left, right )\n!\n! Evaluate the spline in the given interval.\n!\n if ( left == 1 ) then\n\n d21 = sqrt ( ( tdata(2) - tdata(1) )**2 &\n + ( ydata(2) - ydata(1) )**2 )\n\n d32 = sqrt ( ( tdata(3) - tdata(2) )**2 &\n + ( ydata(3) - ydata(2) )**2 )\n\n alpha = d21 / ( d32 + d21 )\n\n call basis_matrix_overhauser_nul ( alpha, mbasis_l )\n\n call basis_matrix_tmp ( left, 3, mbasis_l, ndata, tdata, ydata, tval, yval )\n\n else if ( left < ndata - 1 ) then\n\n d21 = sqrt ( ( tdata(left) - tdata(left-1) )**2 &\n + ( ydata(left) - ydata(left-1) )**2 )\n\n d32 = sqrt ( ( tdata(left+1) - tdata(left) )**2 &\n + ( ydata(left+1) - ydata(left) )**2 )\n\n d43 = sqrt ( ( tdata(left+2) - tdata(left+1) )**2 &\n + ( ydata(left+2) - ydata(left+1) )**2 )\n\n alpha = d21 / ( d32 + d21 )\n beta = d32 / ( d43 + d32 )\n\n call basis_matrix_overhauser_nonuni ( alpha, beta, mbasis )\n\n call basis_matrix_tmp ( left, 4, mbasis, ndata, tdata, ydata, tval, yval )\n\n else if ( left == ndata - 1 ) then\n\n d32 = sqrt ( ( tdata(ndata-1) - tdata(ndata-2) )**2 &\n + ( ydata(ndata-1) - ydata(ndata-2) )**2 )\n\n d43 = sqrt ( ( tdata(ndata) - tdata(ndata-1) )**2 &\n + ( ydata(ndata) - ydata(ndata-1) )**2 )\n\n beta = d32 / ( d43 + d32 )\n\n call basis_matrix_overhauser_nur ( beta, mbasis_r )\n\n call basis_matrix_tmp ( left, 3, mbasis_r, ndata, tdata, ydata, tval, yval )\n\n else\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_OVERHAUSER_NONUNI_VAL - Fatal error!'\n write ( *, '(a,i8)' ) ' Nonsensical value of LEFT = ', left\n write ( *, '(a,i8)' ) ' but 0 < LEFT < NDATA = ', ndata\n write ( *, '(a)' ) ' is required.'\n stop 1\n\n end if\n\n return\nend\nsubroutine spline_overhauser_uni_val ( ndata, tdata, ydata, tval, yval )\n\n!*****************************************************************************80\n!\n!! SPLINE_OVERHAUSER_UNI_VAL evaluates the uniform Overhauser spline.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NDATA, the number of data points.\n! NDATA must be at least 3.\n!\n! Input, real ( kind = 8 ) TDATA(NDATA), the abscissas of the data points.\n! The values of TDATA are assumed to be distinct and increasing.\n! This routine also assumes that the values of TDATA are uniformly\n! spaced; for instance, TDATA(1) = 10, TDATA(2) = 11, TDATA(3) = 12...\n!\n! Input, real ( kind = 8 ) YDATA(NDATA), the data values.\n!\n! Input, real ( kind = 8 ) TVAL, the value where the spline is to\n! be evaluated.\n!\n! Output, real ( kind = 8 ) YVAL, the value of the spline at TVAL.\n!\n implicit none\n\n integer ( kind = 4 ) ndata\n\n integer ( kind = 4 ) left\n real ( kind = 8 ) mbasis(4,4)\n real ( kind = 8 ) mbasis_l(3,3)\n real ( kind = 8 ) mbasis_r(3,3)\n integer ( kind = 4 ) right\n real ( kind = 8 ) tdata(ndata)\n real ( kind = 8 ) tval\n real ( kind = 8 ) ydata(ndata)\n real ( kind = 8 ) yval\n!\n! Check NDATA.\n!\n if ( ndata < 3 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_OVERHAUSER_UNI_VAL - Fatal error!'\n write ( *, '(a)' ) ' NDATA < 3.'\n stop 1\n end if\n!\n! Find the nearest interval [ TDATA(LEFT), TDATA(RIGHT) ] to TVAL.\n!\n call r8vec_bracket ( ndata, tdata, tval, left, right )\n!\n! Evaluate the spline in the given interval.\n!\n if ( left == 1 ) then\n\n call basis_matrix_overhauser_uni_l ( mbasis_l )\n\n call basis_matrix_tmp ( left, 3, mbasis_l, ndata, tdata, ydata, tval, yval )\n\n else if ( left < ndata - 1 ) then\n\n call basis_matrix_overhauser_uni ( mbasis )\n\n call basis_matrix_tmp ( left, 4, mbasis, ndata, tdata, ydata, tval, yval )\n\n else if ( left == ndata - 1 ) then\n\n call basis_matrix_overhauser_uni_r ( mbasis_r )\n\n call basis_matrix_tmp ( left, 3, mbasis_r, ndata, tdata, ydata, tval, yval )\n\n end if\n\n return\nend\nsubroutine spline_overhauser_val ( dim_num, ndata, tdata, ydata, tval, yval )\n\n!*****************************************************************************80\n!\n!! SPLINE_OVERHAUSER_VAL evaluates an Overhauser spline.\n!\n! Discussion:\n!\n! Over the first and last intervals, the Overhauser spline is a\n! quadratic. In the intermediate intervals, it is a piecewise cubic.\n! The Overhauser spline is also known as the Catmull-Rom spline.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 08 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! JA Brewer, DC Anderson,\n! Visual Interaction with Overhauser Curves and Surfaces,\n! SIGGRAPH 77,\n! in Proceedings of the 4th Annual Conference on Computer Graphics\n! and Interactive Techniques,\n! ASME, July 1977, pages 132-137.\n!\n! Edwin Catmull, Raphael Rom,\n! A Class of Local Interpolating Splines,\n! in Computer Aided Geometric Design,\n! edited by Robert Barnhill, Richard Reisenfeld,\n! Academic Press, 1974, pages 317-326,\n! ISBN: 0120790505.\n!\n! David Rogers, Alan Adams,\n! Mathematical Elements of Computer Graphics,\n! Second Edition,\n! McGraw Hill, 1989,\n! ISBN: 0070535299.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) DIM_NUM, the dimension of a single data point.\n! DIM_NUM must be at least 1.\n!\n! Input, integer ( kind = 4 ) NDATA, the number of data points.\n! NDATA must be at least 3.\n!\n! Input, real ( kind = 8 ) TDATA(NDATA), the abscissas of the data\n! points. The values in TDATA must be in strictly ascending order.\n!\n! Input, real ( kind = 8 ) YDATA(DIM_NUM,NDATA), the data points\n! corresponding to the abscissas.\n!\n! Input, real ( kind = 8 ) TVAL, the abscissa value at which the spline\n! is to be evaluated. Normally, TDATA(1) <= TVAL <= T(NDATA), and\n! the data will be interpolated. For TVAL outside this range,\n! extrapolation will be used.\n!\n! Output, real ( kind = 8 ) YVAL(DIM_NUM), the value of the spline at TVAL.\n!\n implicit none\n\n integer ( kind = 4 ) ndata\n integer ( kind = 4 ) dim_num\n\n integer ( kind = 4 ) left\n integer ( kind = 4 ) order\n integer ( kind = 4 ) right\n real ( kind = 8 ) tdata(ndata)\n real ( kind = 8 ) tval\n real ( kind = 8 ) ydata(dim_num,ndata)\n real ( kind = 8 ) yl(dim_num)\n real ( kind = 8 ) yr(dim_num)\n real ( kind = 8 ) yval(dim_num)\n!\n! Check.\n!\n call r8vec_order_type ( ndata, tdata, order )\n\n if ( order /= 2 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_OVERHAUSER_VAL - Fatal error!'\n write ( *, '(a)' ) ' The data abscissas are not strictly ascending.'\n stop 1\n end if\n\n if ( ndata < 3 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_OVERHAUSER_VAL - Fatal error!'\n write ( *, '(a)' ) ' NDATA < 3.'\n stop 1\n end if\n\n if ( dim_num < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_OVERHAUSER_VAL - Fatal error!'\n write ( *, '(a)' ) ' DIM_NUM < 1.'\n stop 1\n end if\n!\n! Locate the abscissa interval T(LEFT), T(LEFT+1) nearest to or\n! containing TVAL.\n!\n call r8vec_bracket ( ndata, tdata, tval, left, right )\n!\n! Evaluate the \"left hand\" quadratic defined at T(LEFT-1), T(LEFT), T(RIGHT).\n!\n if ( 0 < left-1 ) then\n call parabola_val2 ( dim_num, ndata, tdata, ydata, left-1, tval, yl )\n end if\n!\n! Evaluate the \"right hand\" quadratic defined at T(LEFT), T(RIGHT), T(RIGHT+1).\n!\n if ( right+1 <= ndata ) then\n call parabola_val2 ( dim_num, ndata, tdata, ydata, left, tval, yr )\n end if\n!\n! Average the quadratics.\n!\n if ( left == 1 ) then\n\n yval(1:dim_num) = yr(1:dim_num)\n\n else if ( right < ndata ) then\n\n yval(1:dim_num) = &\n ( ( tdata(right) - tval ) * yl(1:dim_num) &\n + ( tval - tdata(left) ) * yr(1:dim_num) ) &\n / ( tdata(right) - tdata(left) )\n\n else\n\n yval(1:dim_num) = yl(1:dim_num)\n\n end if\n\n return\nend\nsubroutine spline_pchip_set ( n, x, f, d )\n\n!*****************************************************************************80\n!\n!! SPLINE_PCHIP_SET sets derivatives for a piecewise cubic Hermite interpolant.\n!\n! Discussion:\n!\n! This routine computes what would normally be called a Hermite\n! interpolant. However, the user is only required to supply function\n! values, not derivative values as well. This routine computes\n! \"suitable\" derivative values, so that the resulting Hermite interpolant\n! has desirable shape and monotonicity properties.\n!\n! The interpolant will have an extremum at each point where\n! monotonicity switches direction.\n!\n! The resulting piecewise cubic Hermite function may be evaluated\n! by SPLINE_PCHIP_VAL.\n!\n! This routine was originally named \"PCHIM\".\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 December 2008\n!\n! Author:\n!\n! Original FORTRAN77 version by Fred Fritsch.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! Fred Fritsch, Ralph Carlson,\n! Monotone Piecewise Cubic Interpolation,\n! SIAM Journal on Numerical Analysis,\n! Volume 17, Number 2, April 1980, pages 238-246.\n!\n! Fred Fritsch, Judy Butland,\n! A Method for Constructing Local Monotone Piecewise Cubic Interpolants,\n! SIAM Journal on Scientific and Statistical Computing,\n! Volume 5, Number 2, 1984, pages 300-304.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of data points. N must be\n! at least 2.\n!\n! Input, real ( kind = 8 ) X(N), the strictly increasing independent\n! variable values.\n!\n! Input, real ( kind = 8 ) F(N), dependent variable values to be\n! interpolated. F(I) is the value corresponding to X(I).\n! This routine is designed for monotonic data, but it will work for any\n! F array. It will force extrema at points where monotonicity switches\n! direction.\n!\n! Output, real ( kind = 8 ) D(N), the derivative values at the\n! data points. If the data are monotonic, these values will determine\n! a monotone cubic Hermite function.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) d(n)\n real ( kind = 8 ) del1\n real ( kind = 8 ) del2\n real ( kind = 8 ) dmax\n real ( kind = 8 ) dmin\n real ( kind = 8 ) drat1\n real ( kind = 8 ) drat2\n real ( kind = 8 ) dsave\n real ( kind = 8 ) f(n)\n real ( kind = 8 ) h1\n real ( kind = 8 ) h2\n real ( kind = 8 ) hsum\n real ( kind = 8 ) hsumt3\n integer ( kind = 4 ) i\n integer ( kind = 4 ) ierr\n integer ( kind = 4 ) nless1\n real ( kind = 8 ) pchst\n real ( kind = 8 ) temp\n real ( kind = 8 ) w1\n real ( kind = 8 ) w2\n real ( kind = 8 ) x(n)\n!\n! Check the arguments.\n!\n if ( n < 2 ) then\n ierr = -1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_PCHIP_SET - Fatal error!'\n write ( *, '(a)' ) ' Number of data points less than 2.'\n stop 1\n end if\n\n do i = 2, n\n if ( x(i) <= x(i-1) ) then\n ierr = -3\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_PCHIP_SET - Fatal error!'\n write ( *, '(a)' ) ' X array not strictly increasing.'\n stop 1\n end if\n end do\n\n ierr = 0\n nless1 = n - 1\n h1 = x(2) - x(1)\n del1 = ( f(2) - f(1) ) / h1\n dsave = del1\n!\n! Special case N=2, use linear interpolation.\n!\n if ( n == 2 ) then\n d(1) = del1\n d(n) = del1\n return\n end if\n!\n! Normal case, 3 <= N.\n!\n h2 = x(3) - x(2)\n del2 = ( f(3) - f(2) ) / h2\n!\n! Set D(1) via non-centered three point formula, adjusted to be\n! shape preserving.\n!\n hsum = h1 + h2\n w1 = ( h1 + hsum ) / hsum\n w2 = -h1 / hsum\n d(1) = w1 * del1 + w2 * del2\n\n if ( pchst ( d(1), del1 ) <= 0.0D+00 ) then\n\n d(1) = 0.0D+00\n!\n! Need do this check only if monotonicity switches.\n!\n else if ( pchst ( del1, del2 ) < 0.0D+00 ) then\n\n dmax = 3.0D+00 * del1\n\n if ( abs ( dmax ) < abs ( d(1) ) ) then\n d(1) = dmax\n end if\n\n end if\n!\n! Loop through interior points.\n!\n do i = 2, nless1\n\n if ( 2 < i ) then\n h1 = h2\n h2 = x(i+1) - x(i)\n hsum = h1 + h2\n del1 = del2\n del2 = ( f(i+1) - f(i) ) / h2\n end if\n!\n! Set D(I)=0 unless data are strictly monotonic.\n!\n d(i) = 0.0D+00\n\n temp = pchst ( del1, del2 )\n\n if ( temp < 0.0D+00 ) then\n\n ierr = ierr + 1\n dsave = del2\n!\n! Count number of changes in direction of monotonicity.\n!\n else if ( temp == 0.0D+00 ) then\n\n if ( del2 /= 0.0D+00 ) then\n if ( pchst ( dsave, del2 ) < 0.0D+00 ) then\n ierr = ierr + 1\n end if\n dsave = del2\n end if\n!\n! Use Brodlie modification of Butland formula.\n!\n else\n\n hsumt3 = 3.0D+00 * hsum\n w1 = ( hsum + h1 ) / hsumt3\n w2 = ( hsum + h2 ) / hsumt3\n dmax = max ( abs ( del1 ), abs ( del2 ) )\n dmin = min ( abs ( del1 ), abs ( del2 ) )\n drat1 = del1 / dmax\n drat2 = del2 / dmax\n d(i) = dmin / ( w1 * drat1 + w2 * drat2 )\n\n end if\n\n end do\n!\n! Set D(N) via non-centered three point formula, adjusted to be\n! shape preserving.\n!\n w1 = -h2 / hsum\n w2 = ( h2 + hsum ) / hsum\n d(n) = w1 * del1 + w2 * del2\n\n if ( pchst ( d(n), del2 ) <= 0.0D+00 ) then\n d(n) = 0.0D+00\n else if ( pchst ( del1, del2 ) < 0.0D+00 ) then\n!\n! Need do this check only if monotonicity switches.\n!\n dmax = 3.0D+00 * del2\n\n if ( abs ( dmax ) < abs ( d(n) ) ) then\n d(n) = dmax\n end if\n\n end if\n\n return\nend\nsubroutine spline_pchip_val ( n, x, f, d, ne, xe, fe )\n\n!*****************************************************************************80\n!\n!! SPLINE_PCHIP_VAL evaluates a piecewise cubic Hermite function.\n!\n! Description:\n!\n! This routine may be used by itself for Hermite interpolation, or as an\n! evaluator for SPLINE_PCHIP_SET.\n!\n! This routine evaluates the cubic Hermite function at the points XE.\n!\n! Most of the coding between the call to CHFEV and the end of\n! the IR loop could be eliminated if it were permissible to\n! assume that XE is ordered relative to X.\n!\n! CHFEV does not assume that X1 is less than X2. Thus, it would\n! be possible to write a version of SPLINE_PCHIP_VAL that assumes a strictly\n! decreasing X array by simply running the IR loop backwards\n! and reversing the order of appropriate tests.\n!\n! The present code has a minor bug, which I have decided is not\n! worth the effort that would be required to fix it.\n! If XE contains points in [X(N-1),X(N)], followed by points less than\n! X(N-1), followed by points greater than X(N), the extrapolation points\n! will be counted (at least) twice in the total returned in IERR.\n!\n! The evaluation will be most efficient if the elements of XE are\n! increasing relative to X; that is, for all J <= K,\n! X(I) <= XE(J)\n! implies\n! X(I) <= XE(K).\n!\n! If any of the XE are outside the interval [X(1),X(N)],\n! values are extrapolated from the nearest extreme cubic,\n! and a warning error is returned.\n!\n! This routine was originally called \"PCHFE\".\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 14 August 2005\n!\n! Author:\n!\n! Original FORTRAN77 version by Fred Fritsch.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! Fred Fritsch, Ralph Carlson,\n! Monotone Piecewise Cubic Interpolation,\n! SIAM Journal on Numerical Analysis,\n! Volume 17, Number 2, April 1980, pages 238-246.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of data points. N must be\n! at least 2.\n!\n! Input, real ( kind = 8 ) X(N), the strictly increasing independent\n! variable values.\n!\n! Input, real ( kind = 8 ) F(N), the function values.\n!\n! Input, real ( kind = 8 ) D(N), the derivative values.\n!\n! Input, integer ( kind = 4 ) NE, the number of evaluation points.\n!\n! Input, real ( kind = 8 ) XE(NE), points at which the function is to\n! be evaluated.\n!\n! Output, real ( kind = 8 ) FE(NE), the values of the cubic Hermite\n! function at XE.\n!\n implicit none\n\n integer ( kind = 4 ) n\n integer ( kind = 4 ) ne\n\n real ( kind = 8 ) d(n)\n real ( kind = 8 ) f(n)\n real ( kind = 8 ) fe(ne)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) ierc\n integer ( kind = 4 ) ierr\n integer ( kind = 4 ) ir\n integer ( kind = 4 ) j\n integer ( kind = 4 ) j_first\n integer ( kind = 4 ) j_new\n integer ( kind = 4 ) j_save\n integer ( kind = 4 ) next(2)\n integer ( kind = 4 ) nj\n real ( kind = 8 ) x(n)\n real ( kind = 8 ) xe(ne)\n!\n! Check arguments.\n!\n if ( n < 2 ) then\n ierr = -1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_PCHIP_VAL - Fatal error!'\n write ( *, '(a)' ) ' Number of data points less than 2.'\n stop 1\n end if\n\n do i = 2, n\n if ( x(i) <= x(i-1) ) then\n ierr = -3\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_PCHIP_VAL - Fatal error!'\n write ( *, '(a)' ) ' X array not strictly increasing.'\n stop 1\n end if\n end do\n\n if ( ne < 1 ) then\n ierr = -4\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_PCHIP_VAL - Fatal error!'\n write ( *, '(a)' ) ' Number of evaluation points less than 1.'\n return\n end if\n\n ierr = 0\n!\n! Loop over intervals.\n! The interval index is IL = IR-1.\n! The interval is X(IL) <= X < X(IR).\n!\n j_first = 1\n ir = 2\n\n do\n!\n! Skip out of the loop if have processed all evaluation points.\n!\n if ( ne < j_first ) then\n exit\n end if\n!\n! Locate all points in the interval.\n!\n j_save = ne + 1\n\n do j = j_first, ne\n if ( x(ir) <= xe(j) ) then\n j_save = j\n if ( ir == n ) then\n j_save = ne + 1\n end if\n exit\n end if\n end do\n!\n! Have located first point beyond interval.\n!\n j = j_save\n\n nj = j - j_first\n!\n! Skip evaluation if no points in interval.\n!\n if ( nj /= 0 ) then\n!\n! Evaluate cubic at XE(J_FIRST:J-1).\n!\n call chfev ( x(ir-1), x(ir), f(ir-1), f(ir), d(ir-1), d(ir), &\n nj, xe(j_first:j-1), fe(j_first:j-1), next, ierc )\n\n if ( ierc < 0 ) then\n ierr = -5\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_PCHIP_VAL - Fatal error!'\n write ( *, '(a)' ) ' Error return from CHFEV.'\n stop 1\n end if\n!\n! In the current set of XE points, there are NEXT(2) to the right of X(IR).\n!\n if ( next(2) /= 0 ) then\n\n if ( ir < n ) then\n ierr = -5\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_PCHIP_VAL - Fatal error!'\n write ( *, '(a)' ) ' IR < N.'\n stop 1\n end if\n!\n! These are actually extrapolation points.\n!\n ierr = ierr + next(2)\n\n end if\n!\n! In the current set of XE points, there are NEXT(1) to the left of X(IR-1).\n!\n if ( next(1) /= 0 ) then\n!\n! These are actually extrapolation points.\n!\n if ( ir <= 2 ) then\n ierr = ierr + next(1)\n else\n\n j_new = -1\n\n do i = j_first, j - 1\n if ( xe(i) < x(ir-1) ) then\n j_new = i\n exit\n end if\n end do\n\n if ( j_new == -1 ) then\n ierr = -5\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_PCHIP_VAL - Fatal error!'\n write ( *, '(a)' ) ' Could not bracket the data point.'\n stop 1\n end if\n!\n! Reset J. This will be the new J_FIRST.\n!\n j = j_new\n!\n! Now find out how far to back up in the X array.\n!\n do i = 1, ir-1\n if ( xe(j) < x(i) ) then\n exit\n end if\n end do\n!\n! At this point, either XE(J) < X(1) or X(i-1) <= XE(J) < X(I) .\n!\n! Reset IR, recognizing that it will be incremented before cycling.\n!\n ir = max ( 1, i-1 )\n\n end if\n\n end if\n\n j_first = j\n\n end if\n\n ir = ir + 1\n\n if ( n < ir ) then\n exit\n end if\n\n end do\n\n return\nend\nsubroutine spline_quadratic_val ( ndata, tdata, ydata, tval, yval, ypval )\n\n!*****************************************************************************80\n!\n!! SPLINE_QUADRATIC_VAL evaluates a piecewise quadratic spline at a point.\n!\n! Discussion:\n!\n! Because of the simple form of a piecewise quadratic spline,\n! the raw data points ( TDATA(I), YDATA(I)) can be used directly to\n! evaluate the spline at any point. No processing of the data\n! is required.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 October 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NDATA, the number of data points defining\n! the spline. NDATA should be odd and at least 3.\n!\n! Input, real ( kind = 8 ) TDATA(NDATA), YDATA(NDATA), the values of\n! the independent and dependent variables at the data points. The\n! values of TDATA should be distinct and increasing.\n!\n! Input, real ( kind = 8 ) TVAL, the point at which the spline is to\n! be evaluated.\n!\n! Output, real ( kind = 8 ) YVAL, YPVAL, the value of the spline and\n! its first derivative dYdT at TVAL. YPVAL is not reliable if TVAL\n! is exactly equal to TDATA(I) for some I.\n!\n implicit none\n\n integer ( kind = 4 ) ndata\n\n real ( kind = 8 ) dif1\n real ( kind = 8 ) dif2\n integer ( kind = 4 ) left\n integer ( kind = 4 ) right\n real ( kind = 8 ) t1\n real ( kind = 8 ) t2\n real ( kind = 8 ) t3\n real ( kind = 8 ) tdata(ndata)\n real ( kind = 8 ) tval\n real ( kind = 8 ) y1\n real ( kind = 8 ) y2\n real ( kind = 8 ) y3\n real ( kind = 8 ) ydata(ndata)\n real ( kind = 8 ) ypval\n real ( kind = 8 ) yval\n\n if ( ndata < 3 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_QUADRATIC_VAL - Fatal error!'\n write ( *, '(a)' ) ' NDATA < 3.'\n stop 1\n end if\n\n if ( mod ( ndata, 2 ) == 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_QUADRATIC_VAL - Fatal error!'\n write ( *, '(a)' ) ' NDATA must be odd.'\n stop 1\n end if\n!\n! Find the interval [ TDATA(LEFT), TDATA(RIGHT) ] that contains, or is\n! nearest to, TVAL.\n!\n call r8vec_bracket ( ndata, tdata, tval, left, right )\n!\n! Force LEFT to be odd.\n!\n if ( mod ( left, 2 ) == 0 ) then\n left = left - 1\n end if\n!\n! Copy out the three abscissas.\n!\n t1 = tdata(left)\n t2 = tdata(left+1)\n t3 = tdata(left+2)\n\n if ( t2 <= t1 .or. t3 <= t2 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SPLINE_QUADRATIC_VAL - Fatal error!'\n write ( *, '(a)' ) ' T2 <= T1 or T3 <= T2.'\n stop 1\n end if\n!\n! Construct and evaluate a parabolic interpolant for the data\n! in each dimension.\n!\n y1 = ydata(left)\n y2 = ydata(left+1)\n y3 = ydata(left+2)\n\n dif1 = ( y2 - y1 ) / ( t2 - t1 )\n\n dif2 = ( ( y3 - y1 ) / ( t3 - t1 ) &\n - ( y2 - y1 ) / ( t2 - t1 ) ) / ( t3 - t2 )\n\n yval = y1 + ( tval - t1 ) * ( dif1 + ( tval - t2 ) * dif2 )\n ypval = dif1 + dif2 * ( 2.0D+00 * tval - t1 - t2 )\n\n return\nend\n!subroutine timestamp ( )\n\n!*****************************************************************************80\n!\n!! TIMESTAMP prints the current YMDHMS date as a time stamp.\n!\n! Example:\n!\n! 31 May 2001 9:45:54.872 AM\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 May 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! None\n!\n! implicit none\n\n! character ( len = 8 ) ampm\n! integer ( kind = 4 ) d\n! integer ( kind = 4 ) h\n! integer ( kind = 4 ) m\n! integer ( kind = 4 ) mm\n! character ( len = 9 ), parameter, dimension(12) :: month = (/ &\n! 'January ', 'February ', 'March ', 'April ', &\n! 'May ', 'June ', 'July ', 'August ', &\n! 'September', 'October ', 'November ', 'December ' /)\n! integer ( kind = 4 ) n\n! integer ( kind = 4 ) s\n! integer ( kind = 4 ) values(8)\n! integer ( kind = 4 ) y\n\n! call date_and_time ( values = values )\n\n! y = values(1)\n! m = values(2)\n! d = values(3)\n! h = values(5)\n! n = values(6)\n! s = values(7)\n! mm = values(8)\n\n! if ( h < 12 ) then\n! ampm = 'AM'\n! else if ( h == 12 ) then\n! if ( n == 0 .and. s == 0 ) then\n! ampm = 'Noon'\n! else\n! ampm = 'PM'\n! end if\n! else\n! h = h - 12\n! if ( h < 12 ) then\n! ampm = 'PM'\n! else if ( h == 12 ) then\n! if ( n == 0 .and. s == 0 ) then\n! ampm = 'Midnight'\n! else\n! ampm = 'AM'\n! end if\n! end if\n! end if\n\n! write ( *, '(i2.2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) &\n! d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm )\n\n! return\n!end\n", "meta": {"hexsha": "8286520a3fa6924e5c4461ae8680c0049c1066ba", "size": 170268, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "spline.f90", "max_stars_repo_name": "bourbaki122/Spherical_collapse_F90", "max_stars_repo_head_hexsha": "085303d8e4cb61fc661c0b2a94a348d21b739e81", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "spline.f90", "max_issues_repo_name": "bourbaki122/Spherical_collapse_F90", "max_issues_repo_head_hexsha": "085303d8e4cb61fc661c0b2a94a348d21b739e81", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "spline.f90", "max_forks_repo_name": "bourbaki122/Spherical_collapse_F90", "max_forks_repo_head_hexsha": "085303d8e4cb61fc661c0b2a94a348d21b739e81", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.9623222401, "max_line_length": 80, "alphanum_fraction": 0.5541088167, "num_tokens": 60593, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669025, "lm_q2_score": 0.8740772236840656, "lm_q1q2_score": 0.7930609496521975}} {"text": "!##############################################################################\n! PROGRAM newton\n!\n! ## The Newton method to find the root of a function\n!\n! This code is published under the GNU General Public License v3\n! (https://www.gnu.org/licenses/gpl-3.0.en.html)\n!\n! Authors: Hans Fehr and Fabian Kindermann\n! contact@ce-fortran.com\n!\n! #VC# VERSION: 1.0 (23 January 2018)\n!\n!##############################################################################\nprogram newton\n\n implicit none\n integer :: iter\n real*8 :: xold, x, f, fprime\n\n ! set initial guess\n xold = 0.05d0\n\n ! start iteration process\n do iter = 1, 200\n\n ! calculate function value\n f = 0.5d0*xold**(-0.2d0)+0.5d0*xold**(-0.5d0)-2d0\n\n ! calculate derivative\n fprime = -0.1d0*xold**(-1.2d0)-0.25d0*xold**(-1.5d0)\n\n ! calculate new value\n x = xold - f/fprime\n\n write(*,'(i4,f12.7)')iter, abs(x-xold)\n\n ! check for convergence\n if(abs(x-xold) < 1d-6)then\n write(*,'(/a,f12.7,a,f12.9)')' x = ',x,' f = ',f\n stop\n endif\n\n ! copy old value\n xold = x\n enddo\n\n write(*,'(a)')'Error: no convergence'\n\nend program\n", "meta": {"hexsha": "f4f6c65df58762ce7d9216b81ca4f5fa10a81f6f", "size": 1243, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog02/prog02_06/prog02_06.f90", "max_stars_repo_name": "aswinvk28/modflow_fortran", "max_stars_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "complete/prog02/prog02_06/prog02_06.f90", "max_issues_repo_name": "aswinvk28/modflow_fortran", "max_issues_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "complete/prog02/prog02_06/prog02_06.f90", "max_forks_repo_name": "aswinvk28/modflow_fortran", "max_forks_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-07T12:27:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-07T12:27:47.000Z", "avg_line_length": 24.3725490196, "max_line_length": 79, "alphanum_fraction": 0.4778761062, "num_tokens": 371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653856, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7928573741989551}} {"text": "! compute pi using the sum in Leibniz formula\nprogram sum\n implicit none\n real :: s\n integer :: i,N\n\n N = 100000\n s = 0.\n\n do i = 1,N\n if (mod(i, 2) == 0) then\n s = s - 1. / (2. * i - 1.)\n else\n s = s + 1. / (2. * i - 1.)\n end if\n end do\n\n write (*,*) s * 4.\n\nend program\n", "meta": {"hexsha": "ee951bcda86b1263558532590c760d5c01db6f8c", "size": 339, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lec02/sum.f90", "max_stars_repo_name": "rekka/intro-fortran-2016", "max_stars_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-05T01:54:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T01:54:57.000Z", "max_issues_repo_path": "lec02/sum.f90", "max_issues_repo_name": "rekka/intro-fortran-2016", "max_issues_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lec02/sum.f90", "max_forks_repo_name": "rekka/intro-fortran-2016", "max_forks_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-06-22T12:39:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-25T04:45:37.000Z", "avg_line_length": 16.1428571429, "max_line_length": 45, "alphanum_fraction": 0.4159292035, "num_tokens": 127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107861416413, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7928263712403654}} {"text": "program exo4_5\n ! A program which reads an integer value limit and print the first limit prime numbers, by any method.\n implicit none\n integer :: limit, limit_counter = 0, number = 2\n\n write(6, '(a)', advance='no') \"Number of primes: \"\n read(5, '(i3)') limit\n if ( limit .eq. 0 ) stop '`limit` must be at least 1'\n write(6, '(a, i3, a)') 'The first ', limit, ' prime number(s) are: '\n\n do \n if ( is_prime(number) .eqv. .true. ) then\n limit_counter = limit_counter + 1\n write(6, '(i5, a)', advance='no') number, ' '\n end if\n\n if ( limit_counter .eq. limit ) then\n write(6, '(a)') ' '\n exit\n end if\n\n number = number + 1\n end do\n\ncontains\n\n logical function is_prime(n)\n integer, intent(in) :: n\n integer :: iter_i\n is_prime = .true.\n do iter_i = 2, int( sqrt( real(n) ) ) \n if ( modulo(n, iter_i) .eq. 0 ) then\n is_prime = .false.\n exit\n end if\n end do\n end function is_prime\n\nend program exo4_5", "meta": {"hexsha": "e6c61f15bb4de131a3843c00f4480cc4cb5c973b", "size": 1108, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exo/exo4_5.f90", "max_stars_repo_name": "eusojk/fortran-programs", "max_stars_repo_head_hexsha": "60fe727a341615153e044e7ac7deabc435444e39", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exo/exo4_5.f90", "max_issues_repo_name": "eusojk/fortran-programs", "max_issues_repo_head_hexsha": "60fe727a341615153e044e7ac7deabc435444e39", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exo/exo4_5.f90", "max_forks_repo_name": "eusojk/fortran-programs", "max_forks_repo_head_hexsha": "60fe727a341615153e044e7ac7deabc435444e39", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.4102564103, "max_line_length": 107, "alphanum_fraction": 0.5189530686, "num_tokens": 324, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172688214137, "lm_q2_score": 0.8354835330070838, "lm_q1q2_score": 0.7928047522863474}} {"text": "! Exercise 2, p. 68\n!\n! Calculating the temperature due to cold front passage\n\nprogram ex_2\n\n use iso_fortran_env, only: real32, int32, output_unit\n\n implicit none\n\n real(real32), parameter :: temp1 = 12. ! temperature in Atlanta (°C)\n real(real32), parameter :: temp2 = 24. ! temperature in Miami (°C)\n\n real(real32), parameter :: dx = 960. ! distance between Atlanta & Miami (km)\n real(real32), parameter :: c = 20. ! speed in km/h\n\n real(real32), parameter :: dt = 1. ! time increment (h)\n\n integer(int32) :: i\n\n ! update temperature in Miami\n time_loop: do i = 6, 48, 6\n ! print result to screen\n write(output_unit, *) \"Temperature after\", i*dt, \" hours is\" , update_temp(temp1, temp2, c, dx, i*dt), \"degrees.\"\n end do time_loop\n\n contains\n\n real(real32) pure function update_temp(temp1, temp2, c, dx, dt)\n real(real32), intent(in) :: temp1, temp2, c, dx, dt\n\n update_temp = temp2 - c * (temp2 - temp1) / dx * dt\n end function update_temp\n \n\nend program ex_2\n", "meta": {"hexsha": "0617bbc7dfbe498279d38bfd788d17a8c0233dc9", "size": 1075, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/ModernFortran/exercises/ex_2.f95", "max_stars_repo_name": "kkirstein/proglang-playground", "max_stars_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fortran/ModernFortran/exercises/ex_2.f95", "max_issues_repo_name": "kkirstein/proglang-playground", "max_issues_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran/ModernFortran/exercises/ex_2.f95", "max_forks_repo_name": "kkirstein/proglang-playground", "max_forks_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.0540540541, "max_line_length": 121, "alphanum_fraction": 0.6102325581, "num_tokens": 313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172615983308, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7928047520822307}} {"text": "subroutine mg_residual(phi, ap, aw, ae, as, an, b, f, nx, ny, xi, xf, res)\nuse kind_parameters\nimplicit none\n\ninteger, intent(in):: nx, ny, xi, xf\nreal(kind=dp), intent(in), dimension(nx,xi-1:xf+1):: phi, ap, b, aw, ae, as, an, f\nreal(kind=dp), intent(out), dimension(nx,xi-1:xf+1):: res\n!real(kind=dp), dimension(nx), intent(in):: dx\n!real(kind=dp), dimension(ny), intent(in):: dy\ninteger:: i, j\n\n! Calculate the residual r = f - Au, where u is the guessed value\n! Input\n! u Matrix for variables\n! f Right Hand Side\n! hx grid spacing in x direction\n! hy grid spacing in y direction\n!\n! Output\n! r Residual\n\n! Author: Pratanu Roy\n! History:\n! First Written: July 20, 2012\n! Modified: Feb 11, 2013\n\ndo j = xi,xf\n\n do i = 2,nx-1\n\n !res(i,j) = 1.0/(dx(i)*dy(j))*(ap(i,j)*phi(i,j) - (aw(i,j)*phi(i-1,j) + ae(i,j)*phi(i+1,j) + as(i,j)*phi(i,j-1) + an(i,j)*phi(i,j+1)) - b(i,j)*dx(i)*dy(j) - f(i,j)*dx(i)*dy(j))\n res(i,j) = ap(i,j)*phi(i,j) - (aw(i,j)*phi(i-1,j) + ae(i,j)*phi(i+1,j) + as(i,j)*phi(i,j-1) + an(i,j)*phi(i,j+1)) - b(i,j)- f(i,j)\n !res(i,j) = 1.0/(dx(i)*dy(j))*(ap(i,j)*phi(i,j) - (aw(i,j)*phi(i-1,j) + ae(i,j)*phi(i+1,j) + as(i,j)*phi(i,j-1) + an(i,j)*phi(i,j+1)) - b(i,j)*dx(i)*dy(j) - f(i,j)*dx(i)*dy(j))\n\n end do\n\nend do\n\ncall exchange_data(res, nx, xi, xf)\n\nend subroutine\n", "meta": {"hexsha": "264fc10c1d00b4ebe63381db25c66b057432e3a5", "size": 1336, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mg_residual.f90", "max_stars_repo_name": "pratanuroy/Multigrid_Cavity", "max_stars_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-11T12:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-11T12:01:52.000Z", "max_issues_repo_path": "mg_residual.f90", "max_issues_repo_name": "pratanuroy/Multigrid_Cavity", "max_issues_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mg_residual.f90", "max_forks_repo_name": "pratanuroy/Multigrid_Cavity", "max_forks_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.8095238095, "max_line_length": 184, "alphanum_fraction": 0.5651197605, "num_tokens": 530, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7927781048651834}} {"text": "program jacobi\n use tools\n\n implicit none\n integer, parameter :: dim = 3 ! matirx dimension\n real(dp), parameter :: eps = 0.5e-4\n real(dp), dimension(dim, dim) :: a\n real(dp), dimension(dim, 2) :: x\n real(dp), dimension(dim) :: b\n\n real(dp) :: error\n integer :: i, itn\n\n ! the A,B matrix\n ! data(a(1, i), i=1, 4)/10.0, -2.0, -1.0, -1.0/\n ! data(a(2, i), i=1, 4)/-2.0, 10.0, -1.0, -1.0/\n ! data(a(3, i), i=1, 4)/-1.0, -1.0, 10.0, -2.0/\n ! data(a(4, i), i=1, 4)/-1.0, -1.0, -2.0, 10.0/\n ! data(b(i), i=1, 4)/3.0, 15.0, 27.0, -9.0/\n\n ! data(a(1, i), i=1, 3)/9.0, 2.0, 4.0/\n ! data(a(2, i), i=1, 3)/1.0, 10.0, 4.0/\n ! data(a(3, i), i=1, 3)/2.0, -4.0, 10.0/\n ! data(b(i), i=1, 3)/20, 6, -15/\n\n ! data(a(1, i), i=1, 3)/4.0, -1.0, -1.0/\n ! data(a(2, i), i=1, 3)/-2.0, 6.0, 1.0/\n ! data(a(3, i), i=1, 3)/-1.0, 1.0, 7.0/\n ! data(b(i), i=1, 3)/3.0, 9.0, -6.0/\n\n data(a(1, i), i=1, 3)/6.0, 1.0, 1.0/\n data(a(2, i), i=1, 3)/1.0, 4.0, -1.0/\n data(a(3, i), i=1, 3)/1.0, -1.0, 5.0/\n data(b(i), i=1, 3)/20.0, 6.0, 7.0/\n\n call dominance(dim, a) ! to check if it is strictly dominant\n\n print *, ''\n print *, 'table:'\n write (*, form_header6) 'itn', 'x1', 'x2', 'x3', 'x4', 'error'\n write (*, line6) '-------', '-------', '-------', '-------', '-------', '---------'\n\n x(:, 1) = 1.0\n itn = 0\n\n call jac(dim, a, x, b, error, itn)\n\n do while (error >= eps)\n x(:, 1) = x(:, 2)\n itn = itn + 1\n call jac(dim, a, x, b, error, itn)\n end do\n\n print *, ''\n print *, 'result:'\n write (*, form_result1rj) (x(i, 2), '-- value of x', i, i=1, dim)\nend program jacobi\n", "meta": {"hexsha": "42e5de41fd4dc3cefa8996046f17d031790960a2", "size": 1583, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "programs/jacobi.f95", "max_stars_repo_name": "okarin001/fortran-numerical-analysis", "max_stars_repo_head_hexsha": "1e9b88df3d338ff1143b1cd63e057759b47d6876", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "programs/jacobi.f95", "max_issues_repo_name": "okarin001/fortran-numerical-analysis", "max_issues_repo_head_hexsha": "1e9b88df3d338ff1143b1cd63e057759b47d6876", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "programs/jacobi.f95", "max_forks_repo_name": "okarin001/fortran-numerical-analysis", "max_forks_repo_head_hexsha": "1e9b88df3d338ff1143b1cd63e057759b47d6876", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.2931034483, "max_line_length": 85, "alphanum_fraction": 0.4567277322, "num_tokens": 830, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541544761566, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7927086218158179}} {"text": "MODULE LagrangePolynomialsModule\n\n USE KindModule, ONLY: &\n DP, Zero, One\n\n IMPLICIT NONE\n PRIVATE\n\n PUBLIC :: LagrangeP\n PUBLIC :: dLagrangeP\n\nCONTAINS\n\n\n PURE REAL(DP) FUNCTION LagrangeP( x, i, xx, nn )\n\n INTEGER, INTENT(in) :: i, nn\n REAL(DP), INTENT(in) :: x, xx(nn)\n\n INTEGER :: j\n\n LagrangeP = One\n DO j = 1, nn\n IF( j == i ) CYCLE\n LagrangeP = LagrangeP * ( x - xx(j) ) / ( xx(i) - xx(j) )\n END DO\n\n RETURN\n END FUNCTION LagrangeP\n\n\n PURE REAL(DP) FUNCTION dLagrangeP( x, i, xx, nn )\n\n INTEGER, INTENT(in) :: i, nn\n REAL(DP), INTENT(in) :: x, xx(nn)\n\n INTEGER :: j, k\n REAL(DP) :: Denominator, Numerator\n\n Denominator = One\n DO j = 1, nn\n IF( j == i ) CYCLE\n Denominator = Denominator * ( xx(i) - xx(j) )\n END DO\n\n dLagrangeP = Zero\n DO j = 1, nn\n IF( j == i ) CYCLE\n Numerator = One\n DO k = 1, nn\n IF( k == i .OR. k == j ) CYCLE\n Numerator = Numerator * ( x - xx(k) )\n END DO\n dLagrangeP = dLagrangeP + Numerator / Denominator\n END DO\n\n RETURN\n END FUNCTION dLagrangeP\n\n\nEND MODULE LagrangePolynomialsModule\n", "meta": {"hexsha": "1bf20d061257ad7c6159c03f41a34e1c58c7f16d", "size": 1144, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Modules/Library/LagrangePolynomialsModule.f90", "max_stars_repo_name": "srichers/thornado", "max_stars_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-12-08T16:16:55.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-24T19:31:21.000Z", "max_issues_repo_path": "Modules/Library/LagrangePolynomialsModule.f90", "max_issues_repo_name": "srichers/thornado", "max_issues_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2019-07-10T20:13:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-11T13:21:00.000Z", "max_forks_repo_path": "Modules/Library/LagrangePolynomialsModule.f90", "max_forks_repo_name": "srichers/thornado", "max_forks_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2018-11-14T01:13:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T02:08:20.000Z", "avg_line_length": 18.4516129032, "max_line_length": 63, "alphanum_fraction": 0.5594405594, "num_tokens": 401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.865224073888819, "lm_q1q2_score": 0.7926400999253572}} {"text": "module tools\n use types\n ! ----------------------------------------------------------------\n ! tools:\n ! This module contains all the functions and subroutines\n ! author:\n ! Exam-roll -- 20419PHY083\n ! env details:\n ! compiler -- gfortran v10.2.0\n ! OS -- macOS 12.0 x86_64\n ! Kernel -- Darwin 21.0.0\n ! Note:\n ! - depends on the module \"types\"\n ! ----------------------------------------------------------------\n implicit none\n\ncontains\n function fn(x) result(z)\n ! ----------------------------------------------------------------\n ! Single variable function:\n ! function with one variable that needs to be calculated\n ! input:\n ! x -- input of the function\n ! output:\n ! z -- output of the function f(x)\n ! ----------------------------------------------------------------\n implicit none\n real(dp), intent(in) :: x\n real(dp) :: z\n\n z = 2.0*x**3.0 - 3.0*x**2.0 + 4.0*x - 5.0\n ! z = 0.5*exp(-((1 + x)/2.0)**2.0)\n ! z = 1/(x + 2)\n end function fn\n\n function f(x, y) result(z)\n ! ----------------------------------------------------------------\n ! Two variable function:\n ! function with two variables that needs to be calculated\n ! inputs:\n ! x,y -- inputs of the function\n ! output:\n ! z -- output of the function f(x,y)\n ! ----------------------------------------------------------------\n implicit none\n real(dp), intent(in) :: x, y\n real(dp) :: z\n\n ! z = exp(x) + y\n z = -x*y\n ! z = sqrt(1 - x**2.0)\n end function f\n\n subroutine oela(x0, y0, x_point, h)\n ! ----------------------------------------------------------------\n ! Euler method:\n ! Finds the value of y at a given x by using a picewise linear\n ! approximation of the solution\n ! inputs:\n ! h -- interval size (keep it small for better result)\n ! x0 -- initial value of x (also used as output)\n ! y0 -- initial value of y (also used as output)\n ! x_point -- the value of x at which y (f(x)) is to be calculated\n ! internals:\n ! x_new -- new value of x's calculated\n ! y_new -- new value of y's calculated\n ! k1 -- slope\n ! outputs:\n ! y0, x0 -- values of the required y at given x\n ! ----------------------------------------------------------------\n implicit none\n real(dp), intent(in) :: x_point, h\n real(dp) :: x0, y0\n real(dp) :: k1, x_new, y_new\n integer :: itn\n\n x_new = x0\n y_new = y0\n itn = 0\n\n do while (x_new <= x_point)\n ! displaying the values\n write (*, form_table3) itn, x_new, y_new\n x0 = x_new\n y0 = y_new\n\n ! valus of slope\n k1 = f(x_new, y_new)\n ! calculating the y\n y_new = y_new + h*k1\n\n ! preparing for the next value\n x_new = x_new + h\n itn = itn + 1\n end do\n end subroutine oela\n\n subroutine mod_oela(x0, y0, x_point, h)\n ! ----------------------------------------------------------------\n ! Modified Euler method:\n ! Finds the value of y at a given x also known as Heun's method\n ! inputs:\n ! h -- interval size (keep it small for better result)\n ! x0 -- initial value of x (also used as output)\n ! y0 -- initial value of y (also used as output)\n ! x_point -- the value of x at which y (f(x)) is to be calculated\n ! internals:\n ! x_new -- new value of x's calculated\n ! y_new -- new value of y's calculated\n ! k1, k2 -- slope\n ! outputs:\n ! y0, x0 -- values of the required y at given x\n ! ----------------------------------------------------------------\n implicit none\n real(dp), intent(in) :: h, x_point\n real(dp) :: x0, y0\n real(dp) :: k1, k2, k, x_new, y_new\n integer :: itn\n\n x_new = x0\n y_new = y0\n itn = 0\n\n do while (x_new <= x_point)\n ! displaying the values\n write (*, form_table3) itn, x_new, y_new\n x0 = x_new\n y0 = y_new\n\n ! values of slope\n k1 = f(x_new, y_new)\n k2 = f(x_new + h, y_new + h*k1)\n\n ! weighted average of the slopes\n k = (k1 + k2)/2.0\n\n ! calculating the y\n y_new = y_new + h*k\n\n ! preparing for the next value\n x_new = x_new + h\n itn = itn + 1\n end do\n end subroutine mod_oela\n\n subroutine g_quad(k, a, b, int_val)\n ! ----------------------------------------------------------------\n ! Gaussian quadrature method:\n ! Integrates a given function by fitting a polynomial at unequal\n ! intervals whose abscissa and weights are calculated using the\n ! zeros of the legendre polynomial and Newton's method.\n ! inputs:\n ! k -- number of points needed\n ! x() -- the arrays of x's\n ! y() -- the arrays of corresponding y's (f(x)'s)\n ! x_point -- the value of x at which f'(x) is to be calculated\n ! internal:\n ! h -- class height\n ! loc -- determines the position of x_point on the table\n ! and gets the respective index for calculation\n ! y -- value of the integral before scaling\n ! output:\n ! int_val -- the result of the derivation after scaling\n ! Note:\n ! - used function fn() because only 1 variable\n ! - used subroutine absc_wght() for abscissa and weights\n ! ----------------------------------------------------------------\n implicit none\n integer, intent(in) :: k\n integer, intent(in) :: a, b\n real(dp), intent(out) :: int_val\n\n real(dp), dimension(k) :: x, w\n real(dp) :: fun, y, p, q\n integer :: i\n\n call absc_wght(k, x, w) ! calculating the weighting factors\n\n ! printing the above weighting factors\n write (*, form_header2) 'abscissa', 'weights'\n write (*, line2) '--------', '--------'\n do i = 1, k\n write (*, form_table2) x(i), w(i)\n end do\n\n ! main integration\n y = 0.0\n p = (a + b)/2.0; q = (b - a)/2.0\n\n ! loop to calculate the values for each weighted factor\n do i = 1, k\n fun = fn(p + q*x(i))\n y = y + w(i)*fun\n end do\n\n int_val = q*y ! final result\n end subroutine g_quad\n\n subroutine absc_wght(points, abscissa, weights)\n ! ----------------------------------------------------------------\n ! Gaussian quadrature Weighting Factors:\n ! calculate the abscissa and weights for the gaussian quadrature\n ! method {g_quad()} using the zeros of the legendre polynomial\n ! inputs:\n ! points -- number of data points\n ! abscissa -- the abscissa\n ! weights -- the weights\n ! internals:\n ! p0 -- Pn coefficient of the legendre polynomial\n ! p1 -- Pn-1 coefficient of the legendre polynomial\n ! p2 -- Pn-2 coefficient of the legendre polynomial\n ! m -- finds the mid-point\n ! x -- initial guess of the abscissa which is further refined\n ! using the Newton-rhapson method\n ! p0_dash -- the derivative of the legendre polynomial\n ! Note:\n ! - Newton's method is used to refine the value of abscissa (x)\n ! - since the weighted factors are symmetric we can break it into half\n ! and calculate only one half and then set the other half\n ! ----------------------------------------------------------------\n implicit none\n integer, intent(in) :: points\n real(dp), dimension(points), intent(out) :: abscissa, weights\n\n real(dp), parameter :: eps = 1.0e-15\n integer :: i, j, m\n real(dp) :: p0, p1, p2, p0_dash, x, x_old\n\n if (mod(points, 2) == 0) then ! finding the mid-point\n m = points/2\n else\n m = (points + 1)/2\n end if\n\n ! loop to calculate the zeros of legendre polynomial\n do i = 1, m\n x = cos(pi*(i - 0.25)/(points + 0.5)) ! initial guess of x\n\n do while (abs(x - x_old) > eps)\n p0 = 1.0\n p1 = x\n\n ! loop to calculate the legendre polynomial\n do j = 1, points\n p2 = p1\n p1 = p0\n p0 = ((2.0*j - 1.0)*x*p1 - (j - 1.0)*p2)/j ! legendre polynomial\n end do\n\n p0_dash = points*(x*p0 - p1)/(x**2.0 - 1.0) ! legendre polynomial derivative\n\n x_old = x\n x = x_old - p0/p0_dash ! newton's method for refining x\n\n ! arranging the abscissa\n abscissa(i) = -x ! the -abscissa's\n abscissa(points + 1 - i) = x ! the +abscissa's\n\n ! arranging the weights\n weights(i) = (2.0*(1 - x**2.0))/(points*p1)**2.0 ! the weights for -abscissa\n weights(points + 1 - i) = weights(i) ! the weights for +abscissa\n end do\n end do\n end subroutine absc_wght\n\n subroutine rungkut_2(x0, y0, x_point, h)\n ! ----------------------------------------------------------------\n ! Runge-Kutte two point method:\n ! Finds the value of y at a given x also known as Polygon method\n ! inputs:\n ! h -- interval size (keep it small for better result)\n ! x0 -- initial value of x (also used as output)\n ! y0 -- initial value of y (also used as output)\n ! x_point -- the value of x at which y (f(x)) is to be calculated\n ! internals:\n ! x_new -- new value of x's calculated\n ! y_new -- new value of y's calculated\n ! k1, k2 -- slopes\n ! outputs:\n ! y0, x0 -- values of the required y at given x\n ! ----------------------------------------------------------------\n implicit none\n real(dp), intent(in) :: h, x_point\n real(dp) :: x0, y0\n real(dp) :: k1, k2, x_new, y_new\n integer :: itn\n\n x_new = x0\n y_new = y0\n itn = 0\n\n do while (x_new <= x_point)\n ! displaying the values\n write (*, form_table3) itn, x_new, y_new\n x0 = x_new\n y0 = y_new\n ! value of slopes\n k1 = f(x_new, y_new)\n k2 = f(x_new + h/2.0, y_new + k1*h/2.0)\n ! calculating the y\n y_new = y_new + h*k2\n ! preparing for next values\n x_new = x_new + h\n itn = itn + 1\n end do\n end subroutine rungkut_2\n\n subroutine rungkut_4(x0, y0, x_point, h)\n ! ----------------------------------------------------------------\n ! Runge-Kutte two point method:\n ! Finds the value of y at a given x also known as Polygon method\n ! inputs:\n ! h -- interval size (keep it small for better result)\n ! x0 -- initial value of x (also used as output)\n ! y0 -- initial value of y (also used as output)\n ! x_point -- the value of x at which y (f(x)) is to be calculated\n ! internals:\n ! x_new -- new value of x's calculated\n ! y_new -- new value of y's calculated\n ! k1,k2,k3,k4 -- slopes\n ! outputs:\n ! y0, x0 -- values of the required y at given x\n ! ----------------------------------------------------------------\n implicit none\n real(dp), intent(in) :: x_point, h\n real(dp) :: x0, y0\n real(dp) :: k1, k2, k3, k4, k, x_new, y_new\n integer :: itn\n\n x_new = x0\n y_new = y0\n itn = 0\n\n do while (x_new <= x_point)\n ! displaying the values\n write (*, form_table3) itn, x_new, y_new\n x0 = x_new\n y0 = y_new\n\n ! values of slopes\n k1 = f(x_new, y_new)\n k2 = f(x_new + h/2.0, y_new + k1*h/2.0)\n k3 = f(x_new + h/2.0, y_new + k2*h/2.0)\n k4 = f(x_new + h, y_new + k3*h)\n\n ! weighted average of the slopes\n k = (k1 + 2.0*(k2 + k3) + k4)/6.0\n\n ! calculating the y\n y_new = y_new + k*h\n\n ! preparingg for the next value\n x_new = x_new + h\n itn = itn + 1\n end do\n end subroutine rungkut_4\n\n subroutine neum_diff(n, x, y, x_point, poly, deriv)\n ! ----------------------------------------------------------------\n ! Newton's differentiation:\n ! Calculates the differentiation of y at a given x using newton's\n ! interpolation polynomial and the difference table calculated\n ! by the subroutine newinter()\n ! inputs:\n ! n -- number of points for interpolation\n ! x() -- the arrays of x's\n ! y() -- the arrays of corresponding y's (f(x)'s)\n ! x_point -- the value of x at which f'(x) is to be calculated\n ! internal:\n ! m -- the mid-point of the table of n points\n ! h -- class height\n ! loc -- determines the position of x_point on the table\n ! and gets the respective index for calculation\n ! output:\n ! deriv -- the result of the derivation\n ! poly -- the used interpolation polynomial\n ! Note:\n ! - used the subroutine newinter\n ! - used forward difference table and modified the formula a bit\n ! to calculate the backward differentiation.\n ! ----------------------------------------------------------------\n implicit none\n integer, intent(in) :: n\n real(dp), dimension(n), intent(in) :: x, y\n real(dp), intent(in) :: x_point\n real(dp), intent(out) :: deriv\n character(len=8), intent(out) :: poly\n\n real(dp), dimension(n, n) :: del_f\n real(dp) :: h, sum_1, sum_2, x_sum\n integer :: a, b, m, loc\n\n ! condition to get the mid-point of the data points\n if (mod(n, 2) == 0) then\n m = n/2\n else\n m = (n + 1)/2\n end if\n\n loc = minloc(x, mask=(x >= x_point), dim=1) ! position of an x in the array\n\n ! check if x_point is outside the given data points\n if ((loc == 0) .or. (loc == n + 1)) then\n stop 'your {x_point} is outside the given data points'\n end if\n\n call newinter(n, x, y, del_f) ! calculating the difference table\n\n ! conditon for forward and backward differentiation\n if (x_point <= x(m)) then ! forward case\n poly = 'forward'\n if (loc == 1) then\n a = loc\n b = a + 1\n else\n a = loc\n b = a - 1\n end if\n\n ! calculation of the derivative\n h = abs(x(a) - x(b))\n x_sum = ((x_point - x(b)) + (x_point - x(a)))\n sum_1 = del_f(b, 1)/h\n sum_2 = del_f(b, 2)/(2.0*h*h)\n\n else if (x_point > x(m)) then ! backward case\n poly = 'backward'\n if (loc == n) then\n a = loc\n b = a - 1\n else\n a = loc\n b = a + 1\n end if\n\n ! calculation of the derivative\n h = abs(x(a) - x(b))\n x_sum = ((x_point - x(b)) + (x_point - x(a)))\n sum_1 = del_f(b, 1)/h\n sum_2 = del_f(b - 1, 2)/(2.0*h*h)\n end if\n\n deriv = sum_1 + sum_2*x_sum ! final result\n end subroutine neum_diff\n\n subroutine newinter(n, x, y, del_f)\n ! ----------------------------------------------------------------\n ! Newton's interpolation table:\n ! Calculates the forward differences and gives us the F.D. table\n ! inputs:\n ! n -- number of points for interpolation\n ! x() -- the arrays of x's (used just for tabulation)\n ! y() -- the arrays of corresponding y's (f(x)'s)\n ! output:\n ! del_f(,) -- the forward difference coefficients\n ! Note:\n ! - This same table is used for backward difference because it is\n ! same as forward difference, just the position is different.\n ! ----------------------------------------------------------------\n implicit none\n integer, intent(in) :: n\n real(dp), dimension(n), intent(in) :: y, x\n real(dp), dimension(n, n), intent(out) :: del_f\n\n real(dp), dimension(n, n) :: del_y\n integer :: i, j, p\n\n ! loop to calculate the differences\n do j = 1, n\n do i = 1, n - j\n if (j == 1) then ! calculating the 1st difference column\n del_y(i, 1) = y(i + 1) - y(i)\n else ! calculate the other coloumns\n del_y(i, j) = del_y(i + 1, j - 1) - del_y(i, j - 1)\n end if\n end do\n end do\n\n del_f = del_y\n\n ! printing the difference table\n print *, 'the difference table:'\n write (*, form_header3n) 'x', 'y', \"del_f's\"\n write (*, line3n) '------', '------', '-------------------------'\n do i = 1, n\n write (*, form_tableip) x(i), y(i), (del_f(i, p), p=1, n - i)\n end do\n end subroutine newinter\n\n subroutine jac(n, a, x, b, err, itn)\n ! ----------------------------------------------------------------\n ! Jacobi method:\n ! calculate the single value of x,y and z using the iterative\n ! method of simultaneous displacememnts\n ! inputs:\n ! n -- number of data points (dimension of the matrix)\n ! a -- matrix of the coefficients A\n ! b -- matrix of the constants B\n ! x(:,1) -- initial x1,x2,x3\n ! itn -- iteration number\n ! internals:\n ! sum_ax() -- sum of the off diagonal terms of A\n ! aberror -- difference of the values of old x's with new x's\n ! output:\n ! err -- the eucledian norm of \"error\"\n ! x(:,2) -- final x1,x2,x3\n ! Note:\n ! - use the subroutine dominance() to check if the solution will\n ! converge or not\n ! ----------------------------------------------------------------\n implicit none\n integer, intent(in) :: n, itn\n real(dp), dimension(n), intent(in) :: b\n real(dp), dimension(n, n), intent(in) :: a\n real(dp), intent(out) :: err\n real(dp), dimension(n, 2) :: x\n\n real(dp), dimension(n) :: sum_ax, aberror\n integer :: p, q\n\n !loop to calculate x1,x2,x3\n do p = 1, n\n sum_ax(p) = 0.0\n do q = 1, n\n if (q /= p) then\n sum_ax(p) = sum_ax(p) + a(p, q)*x(q, 1)\n end if\n end do\n x(p, 2) = (b(p) - sum_ax(p))/a(p, p)\n end do\n\n ! error calculation\n aberror = x(:, 1) - x(:, 2)\n err = norm2(aberror) ! taking the eucledian norm\n\n ! printing the values\n write (*, form_table6) itn, (x(p, 2), p=1, n), err\n end subroutine jac\n\n subroutine dominance(n, a)\n ! ----------------------------------------------------------------\n ! Diagonally dominance checker:\n ! checks if the matrix is strictly diagonally dominant\n ! inputs:\n ! n -- dimension of the matrix\n ! a -- matrix of the coefficients A\n ! internals:\n ! row_sum -- sum of the off diagonal row elements\n ! Note:\n ! - used for the jacobi method equation solver.\n ! - if dominance test failed, need to make the matrix dominant\n ! ----------------------------------------------------------------\n implicit none\n integer, intent(in) :: n\n real(dp), dimension(n, n), intent(in) :: a\n\n real(dp) :: row_sum\n integer :: p, q\n\n ! loop to calculate the sum of off diagonal terms\n do p = 1, n\n row_sum = 0.0\n do q = 1, n\n if (q /= p) then\n row_sum = row_sum + abs(a(p, q)) ! off-diag element sum\n end if\n end do\n\n ! condition for strictly diagonally dominant\n if (abs(a(p, p)) < row_sum) then\n stop \"-- !! the matirx is NOT strictly diagonally dominant !! --\"\n end if\n end do\n end subroutine dominance\n\n subroutine monte_pi(sq_points, points_inside, approx_pi)\n ! ----------------------------------------------------------------\n ! Monte Carlo Pi:\n ! Calculates the approximate value of pi using Monte Carlo method\n ! inputs:\n ! sq_points -- total points inside square including the circle\n ! points_inside -- total points inside the circle\n ! internals:\n ! rand_x, rand_y -- uniform random number in the range [0,1)\n ! ----------------------------------------------------------------\n implicit none\n integer, intent(in) :: sq_points\n integer, intent(out) :: points_inside\n real(dp), intent(out) :: approx_pi\n\n integer :: i, cr_points\n real(dp) :: x, y, rand_x, rand_y, cr_radi\n\n call random_seed() ! to maintain the state random_number generator\n\n do i = 1, sq_points\n ! generating uniform random numbers in the range [0,1)\n call random_number(rand_x)\n call random_number(rand_y)\n\n ! scaling in the range [a,b]: x = a + (b-a)*x\n x = -1 + 2*rand_x\n y = -1 + 2*rand_y\n\n cr_radi = x**2.0 + y**2.0 ! radius of the circle\n\n ! condition to check if the hits were perfect\n if (cr_radi <= 1.0) then\n cr_points = cr_points + 1\n end if\n end do\n\n ! final result\n points_inside = cr_points\n approx_pi = 4.0*(float(cr_points)/float(sq_points))\n end subroutine monte_pi\n\n subroutine monte_int(a, b, s_size, approx_int)\n ! ----------------------------------------------------------------\n ! Monte Carlo Integration:\n ! Calculates the approximate value of integral using MC method\n ! inputs:\n ! a,b -- lower and upper limit\n ! s_size -- size of the sample\n ! internals:\n ! rand_x, rand_y -- uniform random number in the range [0,1)\n ! sum_f -- sum of the function from 1 to sample size\n ! output:\n ! approx_int -- the approximate value of the integral\n ! ----------------------------------------------------------------\n implicit none\n integer, intent(in) :: a, b, s_size\n real(dp), intent(out) :: approx_int\n\n real(dp) :: x, y, sum_f, rand_x, rand_y\n integer :: i\n\n call random_seed() ! to maintain the state random_number generator\n\n ! loop to calculate the integral\n do i = 1, s_size\n ! generating uniform random numbers in the range [0,1)\n call random_number(rand_x)\n call random_number(rand_y)\n\n ! scaling in the range [a,b]: x = a + (b-a)*x\n x = a + rand_x*(b - a)\n y = a + rand_y*(b - a)\n\n sum_f = sum_f + f(x, y) ! summing all the values of the given function\n end do\n\n approx_int = float(b - a)*(sum_f/float(s_size)) ! final result of integral\n end subroutine monte_int\n\n subroutine garphmonte_pi(sq_points, points_inside, approx_pi)\n ! ----------------------------------------------------------------\n ! Monte Carlo Pi:\n ! Calculates the approximate value of pi using Monte Carlo method\n ! inputs:\n ! sq_points -- total points inside square including the circle\n ! points_inside -- total points inside the circle\n ! internals:\n ! rand_x, rand_y -- uniform random number in the range [0,1)\n ! Note:\n ! - this subroutine can be used to get the points in a output file\n ! and can be plotted using a graphing tool\n ! ----------------------------------------------------------------\n implicit none\n integer, intent(in) :: sq_points\n integer, intent(out) :: points_inside\n real(dp), intent(out) :: approx_pi\n\n integer :: i, cr_points\n real(dp) :: cr_radi\n real(dp) :: x, y, rand_x, rand_y\n\n call random_seed() ! to maintain the state random_number generator\n\n open (1, file='values_inside.dat')\n open (2, file='values_outside.dat')\n\n do i = 1, sq_points\n ! generating uniform random numbers in the range [0,1)\n call random_number(rand_x)\n call random_number(rand_y)\n\n ! scaling in the range [a,b]: x = a + (b-a)*x\n x = -1 + 2*rand_x\n y = -1 + 2*rand_y\n\n cr_radi = x**2.0 + y**2.0 ! radius of the circle\n\n ! condition to check if the hits were perfect\n if (cr_radi <= 1.0) then\n cr_points = cr_points + 1\n write (1, \"(2f15.5)\") x, y\n else\n write (2, \"(2f15.5)\") x, y\n end if\n end do\n\n close (1); close (2)\n\n ! final result\n points_inside = cr_points\n approx_pi = 4.0*(float(cr_points)/float(sq_points))\n end subroutine garphmonte_pi\n\nend module tools\n", "meta": {"hexsha": "5eb0668fbdec34b0bc19b30069f28f11a79cbaec", "size": 23346, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "module/tools.f95", "max_stars_repo_name": "okarin001/fortran-numerical-analysis", "max_stars_repo_head_hexsha": "1e9b88df3d338ff1143b1cd63e057759b47d6876", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "module/tools.f95", "max_issues_repo_name": "okarin001/fortran-numerical-analysis", "max_issues_repo_head_hexsha": "1e9b88df3d338ff1143b1cd63e057759b47d6876", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "module/tools.f95", "max_forks_repo_name": "okarin001/fortran-numerical-analysis", "max_forks_repo_head_hexsha": "1e9b88df3d338ff1143b1cd63e057759b47d6876", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.835443038, "max_line_length": 84, "alphanum_fraction": 0.5156343699, "num_tokens": 6572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.8774767954920547, "lm_q1q2_score": 0.7926197058850569}} {"text": "PROGRAM question4\n IMPLICIT NONE\n\n INTEGER:: i, n \n REAL, DIMENSION(:), ALLOCATABLE:: x \n REAL:: sum = 0.0, mean, variance\n\n WRITE(*, *) \"Enter dimention of the array\"\n READ(*, *) n\n ALLOCATE(x(n))\n WRITE(*, 10) n\n 10 FORMAT(/,\"Enter \", i0, \" real number for this array\")\n READ(*, *) (x(i), i = 1, n)\n\n DO i = 1, n\n sum = sum + x(i)\n ENDDO\n\n mean = sum/n\n sum = 0.0\n DO i = 1, n\n sum = sum + (x(i) - mean)**2\n ENDDO\n variance = sum/(n-1)\n\n WRITE(*, 11) mean, variance\n 11 FORMAT(/,\"mean of data = \", f0.3/, \"variance of the data = \", f0.3/)\n\nEND", "meta": {"hexsha": "ffe008c61b2b853a51fa08ef6a36e3d6dedea5e5", "size": 617, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Practice-1/4.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Practice-1/4.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practice-1/4.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 21.275862069, "max_line_length": 75, "alphanum_fraction": 0.5040518639, "num_tokens": 230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915912, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7925584452797598}} {"text": "module forlab_math\n\n use stdlib_kinds, only: sp, dp, qp, int8, int16, int32, int64\n use stdlib_optval, only: optval\n implicit none\n private\n\n public :: angle\n public :: cosd, sind, tand\n public :: acosd, asind, atand\n public :: arange, signum\n\n public :: is_close, all_close\n public :: cross, operator(.c.)\n\n interface acosd\n !! degree circular functions\n pure elemental module function acosd_sp(x)\n real(sp), intent(in)::x\n real(sp)::acosd_sp\n end function acosd_sp\n pure elemental module function acosd_dp(x)\n real(dp), intent(in)::x\n real(dp)::acosd_dp\n end function acosd_dp\n end interface acosd\n interface asind\n !! degree circular functions\n pure elemental module function asind_sp(x)\n real(sp), intent(in)::x\n real(sp)::asind_sp\n end function asind_sp\n pure elemental module function asind_dp(x)\n real(dp), intent(in)::x\n real(dp)::asind_dp\n end function asind_dp\n end interface asind\n interface atand\n !! degree circular functions\n pure elemental module function atand_sp(x)\n real(sp), intent(in)::x\n real(sp)::atand_sp\n end function atand_sp\n pure elemental module function atand_dp(x)\n real(dp), intent(in)::x\n real(dp)::atand_dp\n end function atand_dp\n end interface atand\n\n interface cosd\n pure elemental module function cosd_sp(x)\n real(sp), intent(in)::x\n real(sp)::cosd_sp\n end function cosd_sp\n pure elemental module function cosd_dp(x)\n real(dp), intent(in)::x\n real(dp)::cosd_dp\n end function cosd_dp\n end interface cosd\n interface sind\n pure elemental module function sind_sp(x)\n real(sp), intent(in)::x\n real(sp)::sind_sp\n end function sind_sp\n pure elemental module function sind_dp(x)\n real(dp), intent(in)::x\n real(dp)::sind_dp\n end function sind_dp\n end interface sind\n interface tand\n pure elemental module function tand_sp(x)\n real(sp), intent(in)::x\n real(sp)::tand_sp\n end function tand_sp\n pure elemental module function tand_dp(x)\n real(dp), intent(in)::x\n real(dp)::tand_dp\n end function tand_dp\n end interface tand\n\n interface angle\n !! Version: experimental\n !!\n !! angle compute the phase angle.\n !!([Interface](../interface/angle.html))\n module procedure :: angle_sp\n pure module function angle_2_sp(x, y) result(angle)\n real(sp), dimension(3), intent(in) :: x, y\n real(sp) :: angle\n end function angle_2_sp\n module procedure :: angle_dp\n pure module function angle_2_dp(x, y) result(angle)\n real(dp), dimension(3), intent(in) :: x, y\n real(dp) :: angle\n end function angle_2_dp\n end interface angle\n\n !> Version: experimental\n !>\n !> Returns a boolean scalar/array where two scalar/arrays are element-wise equal within a tolerance.\n !> ([Specification](../page/specs/forlab_math.html#is_close))\n interface is_close\n elemental module function is_close_rsp(a, b, rel_tol, abs_tol) result(close)\n real(sp), intent(in) :: a, b\n real(sp), intent(in), optional :: rel_tol, abs_tol\n logical :: close\n end function is_close_rsp\n elemental module function is_close_rdp(a, b, rel_tol, abs_tol) result(close)\n real(dp), intent(in) :: a, b\n real(dp), intent(in), optional :: rel_tol, abs_tol\n logical :: close\n end function is_close_rdp\n elemental module function is_close_csp(a, b, rel_tol, abs_tol) result(close)\n complex(sp), intent(in) :: a, b\n real(sp), intent(in), optional :: rel_tol, abs_tol\n logical :: close\n end function is_close_csp\n elemental module function is_close_cdp(a, b, rel_tol, abs_tol) result(close)\n complex(dp), intent(in) :: a, b\n real(dp), intent(in), optional :: rel_tol, abs_tol\n logical :: close\n end function is_close_cdp\n end interface is_close\n\n !> Version: experimental\n !>\n !> Returns a boolean scalar where two arrays are element-wise equal within a tolerance.\n !> ([Specification](../page/specs/forlab_math.html#all_close))\n interface all_close\n logical module function all_close_rsp(a, b, rel_tol, abs_tol) result(close)\n real(sp), intent(in) :: a(..), b(..)\n real(sp), intent(in), optional :: rel_tol, abs_tol\n end function all_close_rsp\n logical module function all_close_rdp(a, b, rel_tol, abs_tol) result(close)\n real(dp), intent(in) :: a(..), b(..)\n real(dp), intent(in), optional :: rel_tol, abs_tol\n end function all_close_rdp\n logical module function all_close_csp(a, b, rel_tol, abs_tol) result(close)\n complex(sp), intent(in) :: a(..), b(..)\n real(sp), intent(in), optional :: rel_tol, abs_tol\n end function all_close_csp\n logical module function all_close_cdp(a, b, rel_tol, abs_tol) result(close)\n complex(dp), intent(in) :: a(..), b(..)\n real(dp), intent(in), optional :: rel_tol, abs_tol\n end function all_close_cdp\n end interface all_close\n\n !> Version: experimental\n !>\n !> `arange` creates a rank-1 `array` of the `integer/real` type\n !> with fixed-spaced values of given spacing, within a given interval.\n !> ([Specification](../page/specs/forlab_math.html#arange))\n interface arange\n pure module function arange_r_sp(start, end, step) result(result)\n real(sp), intent(in) :: start\n real(sp), intent(in), optional :: end, step\n real(sp), allocatable :: result(:)\n end function arange_r_sp\n pure module function arange_r_dp(start, end, step) result(result)\n real(dp), intent(in) :: start\n real(dp), intent(in), optional :: end, step\n real(dp), allocatable :: result(:)\n end function arange_r_dp\n pure module function arange_i_int8(start, end, step) result(result)\n integer(int8), intent(in) :: start\n integer(int8), intent(in), optional :: end, step\n integer(int8), allocatable :: result(:)\n end function arange_i_int8\n pure module function arange_i_int16(start, end, step) result(result)\n integer(int16), intent(in) :: start\n integer(int16), intent(in), optional :: end, step\n integer(int16), allocatable :: result(:)\n end function arange_i_int16\n pure module function arange_i_int32(start, end, step) result(result)\n integer(int32), intent(in) :: start\n integer(int32), intent(in), optional :: end, step\n integer(int32), allocatable :: result(:)\n end function arange_i_int32\n pure module function arange_i_int64(start, end, step) result(result)\n integer(int64), intent(in) :: start\n integer(int64), intent(in), optional :: end, step\n integer(int64), allocatable :: result(:)\n end function arange_i_int64\n end interface arange\n\n !> Version: experimental\n !>\n !> `signum` returns the sign of variables.\n !> ([Specification](../page/specs/forlab_math.html#signum))\n interface signum\n real(sp) elemental module function signum_rsp(x) result(sign)\n real(sp), intent(in) :: x\n end function signum_rsp\n real(dp) elemental module function signum_rdp(x) result(sign)\n real(dp), intent(in) :: x\n end function signum_rdp\n integer(int8) elemental module function signum_iint8(x) result(sign)\n integer(int8), intent(in) :: x\n end function signum_iint8\n integer(int16) elemental module function signum_iint16(x) result(sign)\n integer(int16), intent(in) :: x\n end function signum_iint16\n integer(int32) elemental module function signum_iint32(x) result(sign)\n integer(int32), intent(in) :: x\n end function signum_iint32\n integer(int64) elemental module function signum_iint64(x) result(sign)\n integer(int64), intent(in) :: x\n end function signum_iint64\n complex(sp) elemental module function signum_csp(x) result(sign)\n complex(sp), intent(in) :: x\n end function signum_csp\n complex(dp) elemental module function signum_cdp(x) result(sign)\n complex(dp), intent(in) :: x\n end function signum_cdp\n end interface signum\n\n interface cross\n pure module function cross_rsp(x, y) result(cross)\n real(sp), intent(in) :: x(3), y(3)\n real(sp) :: cross(3)\n end function cross_rsp\n pure module function cross_rdp(x, y) result(cross)\n real(dp), intent(in) :: x(3), y(3)\n real(dp) :: cross(3)\n end function cross_rdp\n pure module function cross_iint8(x, y) result(cross)\n integer(int8), intent(in) :: x(3), y(3)\n integer(int8) :: cross(3)\n end function cross_iint8\n pure module function cross_iint16(x, y) result(cross)\n integer(int16), intent(in) :: x(3), y(3)\n integer(int16) :: cross(3)\n end function cross_iint16\n pure module function cross_iint32(x, y) result(cross)\n integer(int32), intent(in) :: x(3), y(3)\n integer(int32) :: cross(3)\n end function cross_iint32\n pure module function cross_iint64(x, y) result(cross)\n integer(int64), intent(in) :: x(3), y(3)\n integer(int64) :: cross(3)\n end function cross_iint64\n end interface cross\n\n interface operator(.c.)\n procedure :: cross_rsp\n procedure :: cross_rdp\n procedure :: cross_iint8\n procedure :: cross_iint16\n procedure :: cross_iint32\n procedure :: cross_iint64\n end interface operator(.c.)\n\ncontains\n\n elemental function angle_sp(value) result(angle)\n real(sp) :: angle\n complex(sp), intent(in) :: value\n\n angle = aimag(log(value))\n\n end function angle_sp\n elemental function angle_dp(value) result(angle)\n real(dp) :: angle\n complex(dp), intent(in) :: value\n\n angle = aimag(log(value))\n\n end function angle_dp\n\nend module forlab_math\n", "meta": {"hexsha": "db8e8f768e1eb4d54a3bfba5f104667bf3f38246", "size": 10602, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_math.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/forlab_math.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/forlab_math.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.1217712177, "max_line_length": 104, "alphanum_fraction": 0.6051688361, "num_tokens": 2561, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.7925584302150818}} {"text": "program Simspson_Rule\r\n\r\n implicit none\r\n\r\n real :: a,b,h,s,Integration\r\n integer :: n,i\r\n real,parameter :: pi=3.14\r\n\r\n print*,\"SIMPSON's 1/3rd RULE\"\r\n print*,\"Function : y=5*(x**3)-3*(x**2)+(2*x)+1\"\r\n\r\n print*,\"Enter lower limit :\"\r\n read*,a\r\n\r\n print*,\"Enter upper limit :\"\r\n read*,b\r\n\r\n print*,\"Enter number of iterations (it must be even) :\"\r\n read*,n\r\n\r\n h=(b-a)/n\r\n s=f(a)+f(b)\r\n\r\n do i=1,2,(n-1)\r\n s=s+4*f(a+i*h)\r\n end do\r\n do i=2,2,(n-2)\r\n s=s+2*f(a+i*h)\r\n end do\r\n\r\n Integration=(h*s)/3\r\n print*,\"Answer of Integration : \",Integration\r\n\r\nend program\r\n\r\nfunction f(x)\r\n implicit none\r\n real :: f ! Dummy Variable\r\n real :: x ! Local Variable\r\n! f=5*x**3-3*x**2+2*x+1\r\n f=x*sin(x)\r\nend function\r\n", "meta": {"hexsha": "c9fdb71fd7e7996bbb30d1971810b415d056c0d4", "size": 797, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "5_Simspon_one_third_rule.f90", "max_stars_repo_name": "Official-Satyam-Tiwari/FORTRAN", "max_stars_repo_head_hexsha": "5f15194bc7a2bdf84ce4516fa291f49072f6b227", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5_Simspon_one_third_rule.f90", "max_issues_repo_name": "Official-Satyam-Tiwari/FORTRAN", "max_issues_repo_head_hexsha": "5f15194bc7a2bdf84ce4516fa291f49072f6b227", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5_Simspon_one_third_rule.f90", "max_forks_repo_name": "Official-Satyam-Tiwari/FORTRAN", "max_forks_repo_head_hexsha": "5f15194bc7a2bdf84ce4516fa291f49072f6b227", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.5348837209, "max_line_length": 60, "alphanum_fraction": 0.5119196989, "num_tokens": 271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871156, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.7923369755006207}} {"text": "module math\n ! Module with some mathematical functions\n implicit none\n\n public :: newton\n private :: norm, distance_between_points\n\ncontains\n \n function norm(r_in) result(norm_value)\n ! 2-norm of r\n implicit none\n real(8), dimension(3), intent(in) :: r_in\n real(8) :: norm_value\n norm_value = sqrt(sum((r_in)**2.0))\n end function norm\n \n function distance_between_points(r1,r2) result(r)\n ! distance between two points\n implicit none\n real(8), dimension(3), intent(in) :: r1, r2\n real(8) :: r\n r = norm(r2-r1) \n end function distance_between_points\n \n function newton(m1,m2,r1,r2) result(f)\n ! Newton's universal law of gravity\n implicit none\n real(8), intent(in) :: m1, m2\n real(8), dimension(3), intent(in) :: r1, r2\n real(8), dimension(3) :: f, r12\n real(8) :: r\n real(8), parameter :: G = 6.67384e-11\n r = distance_between_points(r1,r2)\n r12 = (r2-r1)/r\n f = -G*m1*m2/r**2.0*r12\n end function newton\n \nend module math\n", "meta": {"hexsha": "3d5f5184573e533f0142059aed013ad0fd12e83d", "size": 998, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "math.f90", "max_stars_repo_name": "tukiains/nbs", "max_stars_repo_head_hexsha": "b0239b430ec1ea6216c9fbafe352bc39467dc3d3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "math.f90", "max_issues_repo_name": "tukiains/nbs", "max_issues_repo_head_hexsha": "b0239b430ec1ea6216c9fbafe352bc39467dc3d3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math.f90", "max_forks_repo_name": "tukiains/nbs", "max_forks_repo_head_hexsha": "b0239b430ec1ea6216c9fbafe352bc39467dc3d3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.95, "max_line_length": 51, "alphanum_fraction": 0.6382765531, "num_tokens": 321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750427013548, "lm_q2_score": 0.8311430499496095, "lm_q1q2_score": 0.7923079264316483}} {"text": "! Created by mus on 29/07/2021.\n! Derivation of Lagrange polynomials at the GLL points based on results from Funaro 1993 || Check Heiner Igel pg 196\n! N: Polynomial order\n! primed: derivative of lagrange polynomial matrix, each \"k\" row is the derivative of \"lk(xi)\" Lagrange polynomial. Each row is a the value of the derivative at a GLL point\n! dummy arguments: dij -> derivation matrix | xi, wi -> GLL points and weights ...\n! ... Lxi, Lxj -> Legendre polynomial value at xi and xj | lk -> k-th lagrange polynomial | sum -> summation return for the last derivation sum\n\nsubroutine lagrangeprime(N,primed)\n implicit none\n integer, intent(in) :: N\n real (kind=8), dimension(N+1,N+1), intent(out) :: primed\n real (kind=8), dimension(N+1,N+1) :: dij\n real (kind=8), dimension(N+1) :: xi, wi\n real (kind=8) :: Lxi, Lxj, sum, lk\n integer :: i,j,k\n real (kind=8), external :: legendrep\n\n\n call zwgljd(xi,wi,N+1,0.,0.)\n\n\n do i=0,N\n do j=0,N\n if (i/=j) then\n Lxi = legendrep(N,xi(i+1))\n Lxj = legendrep(N,xi(j+1))\n dij(i+1,j+1) = (Lxi / Lxj) / (xi(i+1) - xi(j+1))\n elseif (i==j) then\n if (i==0 .and. j==0) then\n dij(i+1,j+1) = -0.25 * N * (N + 1)\n elseif (i>=1 .and. i<=N-1) then\n dij(i+1,j+1) = 0\n elseif (i==N) then\n dij(i+1,j+1) = 0.25 * N *(N + 1)\n endif\n end if\n end do\n end do\n\n\n do k=0,N\n do i=0,N\n sum = 0\n do j=0,N\n call lagrangep(N,k,xi(j+1),lk,1)\n sum = sum + dij(i+1,j+1) * lk\n end do\n primed(k+1,i+1) = sum\n end do\n end do\nend subroutine lagrangeprime", "meta": {"hexsha": "2618ae7aa96b78dea34c33ee90a699eab40a85dd", "size": 1945, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lagrangeprime.f90", "max_stars_repo_name": "musbenziane/SEM1D", "max_stars_repo_head_hexsha": "6fa594662fd2b2403c584ca8781964bc40ef888b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-08T19:47:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-08T19:47:07.000Z", "max_issues_repo_path": "lagrangeprime.f90", "max_issues_repo_name": "musbenziane/SEM1D", "max_issues_repo_head_hexsha": "6fa594662fd2b2403c584ca8781964bc40ef888b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lagrangeprime.f90", "max_forks_repo_name": "musbenziane/SEM1D", "max_forks_repo_head_hexsha": "6fa594662fd2b2403c584ca8781964bc40ef888b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-08T19:47:12.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-08T19:47:12.000Z", "avg_line_length": 38.137254902, "max_line_length": 172, "alphanum_fraction": 0.4791773779, "num_tokens": 593, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012701768144, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.792222032913685}} {"text": "***********************************************************************\nc ORBEL_EGET.F\n***********************************************************************\n* PURPOSE: Solves Kepler's eqn. e is ecc. m is mean anomaly.\n*\n* Input:\n* e ==> eccentricity anomaly. (real scalar)\n* m ==> mean anomaly. (real scalar)\n* Returns:\n* orbel_eget ==> eccentric anomaly. (real scalar)\n*\n* ALGORITHM: Quartic convergence from Danby\n* REMARKS: For results very near roundoff, give it M between\n* 0 and 2*pi. One can condition M before calling EGET\n* by calling my double precision function MOD2PI(M). \n* This is not done within the routine to speed it up\n* and because it works fine even for large M.\n* AUTHOR: M. Duncan \n* DATE WRITTEN: May 7, 1992.\n* REVISIONS: May 21, 1992. Now have it go through EXACTLY two iterations\n* with the premise that it will only be called if\n*\t we have an ellipse with e between 0.15 and 0.8\n***********************************************************************\n\n\treal*8 function orbel_eget(e,m)\n\n include '../swift.inc'\n\nc... Inputs Only: \n\treal*8 e,m\n\nc... Internals:\n\treal*8 x,sm,cm,sx,cx\n\treal*8 es,ec,f,fp,fpp,fppp,dx\n\nc----\nc... Executable code \n\nc Function to solve Kepler's eqn for E (here called\nc x) for given e and M. returns value of x.\nc MAY 21 : FOR e < 0.18 use ESOLMD for speed and sufficient accuracy\nc MAY 21 : FOR e > 0.8 use EHIE - this one may not converge fast enough.\n\n\t call orbel_scget(m,sm,cm)\n\nc begin with a guess accurate to order ecc**3\t\n\t x = m + e*sm*( 1.d0 + e*( cm + e*( 1.d0 -1.5d0*sm*sm)))\n\nc Go through one iteration for improved estimate\n\t call orbel_scget(x,sx,cx)\n\t es = e*sx\n\t ec = e*cx\n\t f = x - es - m\n\t fp = 1.d0 - ec \n\t fpp = es \n\t fppp = ec \n\t dx = -f/fp\n\t dx = -f/(fp + dx*fpp/2.d0)\n\t dx = -f/(fp + dx*fpp/2.d0 + dx*dx*fppp/6.d0)\n\t orbel_eget = x + dx\n\nc Do another iteration.\nc For m between 0 and 2*pi this seems to be enough to\nc get near roundoff error for eccentricities between 0 and 0.8\n\n\t x = orbel_eget\n\t call orbel_scget(x,sx,cx)\n\t es = e*sx\n\t ec = e*cx\n\t f = x - es - m\n\t fp = 1.d0 - ec \n\t fpp = es \n\t fppp = ec \n\t dx = -f/fp\n\t dx = -f/(fp + dx*fpp/2.d0)\n\t dx = -f/(fp + dx*fpp/2.d0 + dx*dx*fppp/6.d0)\n\n\t orbel_eget = x + dx\n\n\treturn\n\tend ! orbel_eget\nc---------------------------------------------------------------------\n", "meta": {"hexsha": "09fdc8ffb4355427b2e6960b49955ea7d8e422ff", "size": 2544, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/swift_j/orbel/orbel_eget.f", "max_stars_repo_name": "Simske/exostriker", "max_stars_repo_head_hexsha": "587b0af4c9cadb46637a4ac61a5392a596e966b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 69, "max_stars_repo_stars_event_min_datetime": "2020-01-06T13:31:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T11:23:14.000Z", "max_issues_repo_path": "exostriker/source/swift_j/orbel/orbel_eget.f", "max_issues_repo_name": "sai-33/Exostriker", "max_issues_repo_head_hexsha": "f59fa51c6bdce3a2ed51d6621fe42bfcd8c2846f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 67, "max_issues_repo_issues_event_min_datetime": "2019-11-30T14:45:05.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T20:26:06.000Z", "max_forks_repo_path": "exostriker/source/swift_j/orbel/orbel_eget.f", "max_forks_repo_name": "sai-33/Exostriker", "max_forks_repo_head_hexsha": "f59fa51c6bdce3a2ed51d6621fe42bfcd8c2846f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-01-06T13:44:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T11:23:17.000Z", "avg_line_length": 30.6506024096, "max_line_length": 77, "alphanum_fraction": 0.5188679245, "num_tokens": 773, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012671214071, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7922220188530096}} {"text": "! Created by EverLookNeverSee@GitHub on 5/29/20\n! For more information see FCS/img/Exercise_03.png\n\nprogram main\n implicit none\n ! n --> rod length\n ! r --> crank radius\n ! w --> angular Velocity(rpm)\n ! theta --> crank angle\n ! x --> displaceemnt\n ! v --> velocity\n ! declaring variables\n integer :: i,theta, j = 1\n real :: n, r, w, radian_theta\n real, dimension(37) :: x, v\n ! initializing variables\n n = 4; r = 4; w = 2000; theta = 360\n ! making variation of theta\n do i = 0, theta, 10\n ! the argument of trigonometric functions must be in radians\n radian_theta = i * 3.141593 / 180.0\n ! storing results in two arrays\n x(j) = r * (1 + n - cos(radian_theta) - sqrt((n ** 2) - (sin(radian_theta)) ** 2))\n v(j) = (w * r) * (sin(radian_theta) + &\n sin(2 * radian_theta) / 2 * (sqrt(n ** 2 - sin(radian_theta) ** 2)))\n ! increasing counter of arrays blocks\n j = j + 1\n end do\n ! do loop for formated print\n do i = 1, 37, 1\n print \"(a2,i2,a3,f15.10,10x,a2,i2,a3,f17.10)\", \"x(\", i, \"): \", x(i), \"v(\", i, \"): \", v(i)\n end do\nend program main\n", "meta": {"hexsha": "73f678abfe734aa7d3c0b8873881ce9403239d7e", "size": 1165, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical methods/Exercise_03.f90", "max_stars_repo_name": "EverLookNeverSee/FCS", "max_stars_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-14T10:30:25.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-17T13:03:15.000Z", "max_issues_repo_path": "src/numerical methods/Exercise_03.f90", "max_issues_repo_name": "EverLookNeverSee/FCS", "max_issues_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-06-06T13:54:45.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-25T20:32:23.000Z", "max_forks_repo_path": "src/numerical methods/Exercise_03.f90", "max_forks_repo_name": "EverLookNeverSee/FCS", "max_forks_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-08T12:57:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T12:57:46.000Z", "avg_line_length": 34.2647058824, "max_line_length": 97, "alphanum_fraction": 0.5527896996, "num_tokens": 394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545362802364, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.7921675134600319}} {"text": "subroutine fine_to_coarse_vface(r_h, nx, ny, xi_h, xf_h, xi_2h, xf_2h, r_2h)\nuse kind_parameters\nimplicit none\n\ninteger, intent(in):: nx, ny, xi_h, xf_h, xi_2h, xf_2h\nreal(kind=dp), intent(in), dimension(nx,xi_h-1:xf_h+1):: r_h\nreal(kind=dp), intent(out), dimension(nx/2+1,xi_2h-1:xf_2h+1):: r_2h\ninteger:: i,j\ninteger:: imax, jmax\n\n! Apply full weighting to get interpolated values from fine to coarse grid\n! Input\n! r_h Variable in fine grid\n! f Right Hand Side\n! hx, hy grid spacing\n!\n! Output\n! r_2h Variable in coarse grid\n\n! Author: Pratanu Roy\n! History:\n! First Written: July 20, 2012\n! Indices Rechecked on Jan 13, 2013\n\nimax = nx/2+1\njmax = (ny+1)/2\n\ndo j = xi_2h,xf_2h\n\n do i = 2,imax-1\n\n r_2h(i,j) = 1.0d0/2.0d0*(r_h(2*i-2,2*j-1) + r_h(2*i-1,2*j-1))\n !r_2h(i,j) = (r_h(2*i-2,2*j-1) + r_h(2*i-1,2*j-1))\n\n end do\n\nend do\n\nif (xi_2h .eq. 2) then\n\ndo j = 1,1\n\n do i = 2,imax-1\n\n r_2h(i,j) = 1.0/2.0*(r_h(2*i-2,2*j-1) + r_h(2*i-1,2*j-1))\n !r_2h(i,j) = (r_h(2*i-2,2*j-1) + r_h(2*i-1,2*j-1))\n\n end do\n\nend do\n\nelse if (xf_2h .eq. jmax-1) then\n\ndo j = jmax,jmax\n\n do i = 2,imax-1\n\n r_2h(i,j) = 1.0/2.0*(r_h(2*i-2,2*j-1) + r_h(2*i-1,2*j-1))\n !r_2h(i,j) = (r_h(2*i-2,2*j-1) + r_h(2*i-1,2*j-1))\n\n end do\n\nend do\n\nend if\n\ndo j = xi_2h,xf_2h\n\n do i = 1,1\n\n r_2h(i,j) = r_h(2*i-1,2*j-1)\n\n end do\n\nend do\n\ndo j = xi_2h,xf_2h\n\n do i = imax,imax\n\n r_2h(i,j) = r_h(2*i-2,2*j-1)\n\n end do\n\nend do\n\ncall exchange_data(r_2h, imax, xi_2h, xf_2h)\n\nend subroutine\n", "meta": {"hexsha": "b40d8a73f611f4102002691e26d47c704d41d81b", "size": 1504, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fine_to_coarse_vface.f90", "max_stars_repo_name": "pratanuroy/Multigrid_Cavity", "max_stars_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-11T12:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-11T12:01:52.000Z", "max_issues_repo_path": "fine_to_coarse_vface.f90", "max_issues_repo_name": "pratanuroy/Multigrid_Cavity", "max_issues_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fine_to_coarse_vface.f90", "max_forks_repo_name": "pratanuroy/Multigrid_Cavity", "max_forks_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.7111111111, "max_line_length": 76, "alphanum_fraction": 0.5990691489, "num_tokens": 737, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069962657176, "lm_q2_score": 0.8705972751232809, "lm_q1q2_score": 0.7921625515645431}} {"text": "module tools\n use mpi\n implicit none\ncontains\n !*****************************************************************************!\n\n function cross(a, b)\n real(8),dimension(3) :: cross\n real(8),dimension(3),intent(in) :: a, b\n\n cross(1) = a(2) * b(3) - a(3) * b(2)\n cross(2) = a(3) * b(1) - a(1) * b(3)\n cross(3) = a(1) * b(2) - a(2) * b(1)\n end function cross\n\n !*****************************************************************************!\n\n function dot(a, b)\n real(8) :: dot\n real(8),dimension(3),intent(in) :: a, b\n\n dot = a(1)*b(1) + a(2)*b(2) + a(3)*b(3)\n\n end function dot\n\n !*****************************************************************************!\n\n function dot3d(a, b)\n real(8) :: dot3d\n real(8),dimension(3),intent(in) :: a, b\n\n dot3d = a(1)*b(1) + a(2)*b(2) + a(3)*b(3)\n\n end function dot3d\n\n !*****************************************************************************!\n\n function norm3d(a)\n real(8) :: norm3d\n real(8),dimension(3),intent(in) :: a\n\n norm3d = sqrt(a(1)**2 + a(2)**2 + a(3)**2)\n\n end function norm3d\n\n!*****************************************************************************!\nsubroutine gaussQuadrature(t,w,npts)\n implicit none\n integer,intent(in) :: npts\n real(8),intent(out) :: t(:),w(:)\n ! allocate(t(1:npts))\n ! allocate(w(1:npts))\n if (npts==1) then\n t(1) = 0.0d0\n w(1) = 2.0d0\n elseif (npts==2) then\n t(1) = -1.0d0/sqrt(3.0d0)\n t(2) = -t(1)\n w(1) = 1.0d0\n w(2) = w(1)\n elseif (npts==3) then\n t(1) = 0.000000000000000d0\n t(2) = 0.774596669241483d0\n t(3) = -t(2)\n w(1) = 0.888888888888889d0\n w(2) = 0.555555555555556d0\n w(3) = w(2)\n elseif (npts==4) then\n t(1) = 0.339981043584856d0\n t(2) = 0.861136311594053d0\n t(3:4) = -t(1:2)\n w(1) = 0.652145154862546d0\n w(2) = 0.347854845137454d0\n w(3:4) = w(1:2)\n elseif (npts==5) then\n t(1) = 0.000000000000000d0\n t(2) = 0.538469310105683d0\n t(3) = 0.906179845938664d0\n t(4:5) = -t(2:3)\n w(1) = 0.568888888888889d0\n w(2) = 0.478628670499366d0\n w(3) = 0.236926885056189d0\n w(4:5) = w(2:3)\n elseif (npts==6) then\n t(1) = 0.238619186083197d0\n t(2) = 0.661209386466265d0\n t(3) = 0.932469514203152d0\n t(4:6) = -t(1:3)\n w(1) = 0.467913934572691d0\n w(2) = 0.360761573048139d0\n w(3) = 0.171324492379170d0\n w(4:6) = w(1:3)\n elseif (npts==7) then\n t(1) = 0.000000000000000d0\n t(2) = 0.405845151377397d0\n t(3) = 0.741531185599394d0\n t(4) = 0.949107912342759d0\n t(5:7) = -t(2:4)\n w(1) = 0.417959183673469d0\n w(2) = 0.381830050505119d0\n w(3) = 0.279705391489277d0\n w(4) = 0.129484966168870d0\n w(5:7) = w(2:4)\n elseif(npts ==8) then\n t(1) = 0.183434642495650d0\n t(2) = 0.525532409916329d0\n t(3) = 0.796666477413627d0\n t(4) = 0.960289856497536d0\n t(5:8) = -t(1:4)\n w(1) = 0.362683783378362d0\n w(2) = 0.313706645877887d0\n w(3) = 0.222381034453374d0\n w(4) = 0.101228536290376d0\n w(5:8) = w(1:4)\n endif\n\n return\n\nend subroutine gaussQuadrature\n!*****************************************************************************!\nsubroutine gaussQuadratureTriangles(V,wei,nQ)\n implicit none\n integer,intent(in) :: nQ\n real(8),intent(out) :: V(:,:),wei(:)\n if (nQ==3) then\n V(1,:) = (/ 4.0d0, 1.0d0, 1.0d0 /)\n V(2,:) = (/ 1.0d0, 4.0d0, 1.0d0 /)\n V(3,:) = (/ 1.0d0, 1.0d0, 4.0d0 /)\n V = V/6.0d0\n wei =1.0d0/3.0d0\n elseif (nQ==4) then\n\n V(1,:) = (/0.33333333d0, 0.33333333d0, 0.33333333d0/)\n V(2,:) = (/0.60000000d0, 0.20000000d0, 0.20000000d0/)\n V(3,:) = (/0.20000000d0, 0.60000000d0, 0.20000000d0/)\n V(4,:) = (/0.20000000d0, 0.20000000d0, 0.60000000d0/)\n wei = (/-0.56250000d0,0.52083333d0,0.52083333d0,0.52083333d0/)\n elseif (nQ==6) then\n\n V(1,:) = (/ 0.10810301d0, 0.44594849d0, 0.44594849d0 /)\n V(2,:) = (/ 0.44594849d0, 0.10810301d0, 0.44594849d0 /)\n V(3,:) = (/ 0.44594849d0, 0.44594849d0, 0.10810301d0 /)\n V(4,:) = (/ 0.81684757d0, 0.09157621d0, 0.09157621d0 /)\n V(5,:) = (/ 0.09157621d0, 0.81684757d0, 0.09157621d0 /)\n V(6,:) = (/ 0.09157621d0, 0.09157621d0, 0.81684757d0 /)\n\n wei = (/0.22338158d0,0.22338158d0,0.22338158d0,0.10995174d0,0.10995174d0,0.10995174d0/)\n elseif (nQ==7) then\n\n V(1,:) = (/ 0.33333333d0, 0.33333333d0, 0.33333333d0 /)\n V(2,:) = (/ 0.05971587d0, 0.47014206d0, 0.47014206d0 /)\n V(3,:) = (/ 0.47014206d0, 0.05971587d0, 0.47014206d0 /)\n V(4,:) = (/ 0.47014206d0, 0.47014206d0, 0.05971587d0 /)\n V(5,:) = (/ 0.79742698d0, 0.10128650d0, 0.10128650d0 /)\n V(6,:) = (/ 0.10128650d0, 0.79742698d0, 0.10128650d0 /)\n V(7,:) = (/ 0.10128650d0, 0.10128650d0, 0.79742698d0 /)\n\n wei = (/0.22500000d0,0.13239415d0,0.13239415d0,0.13239415d0,0.12593918d0,0.12593918d0,0.12593918d0/)\n endif\n return\nend subroutine gaussQuadratureTriangles\n!*****************************************************************************!\n subroutine divide_work(start,finish,n_size)\n\n implicit none\n\n integer :: ierr , n_procs , id , lWork\n\n integer, intent(out) :: start , finish\n\n integer, intent(in) :: n_size\n\n !---------------------------------------------!\n\n call mpi_comm_size(MPI_COMM_WORLD,N_procs,ierr)\n\n call mpi_comm_rank(MPI_COMM_WORLD,id,ierr)\n\n lWork = n_size / n_procs\n\n start = 1+id*lWork\n\n finish = (id+1)*lWork\n\n if (id == N_procs-1) then\n\n finish = n_size\n\n endif\n\n return\n\n end subroutine divide_work\nend module\n", "meta": {"hexsha": "d5495560ba385683f9564af89698488aebe89c44", "size": 5490, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/BEMExtra/tools.f90", "max_stars_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_stars_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/BEMExtra/tools.f90", "max_issues_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_issues_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/BEMExtra/tools.f90", "max_forks_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_forks_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1538461538, "max_line_length": 104, "alphanum_fraction": 0.5173041894, "num_tokens": 2462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7920432098112534}} {"text": "module interact_module\n\n contains\n subroutine interact(a, b, c, ok)\n implicit none\n\n real, intent(out) :: a, b, c\n logical, intent(out) :: ok\n integer :: io_status = 0\n\n print *, &\n ' type in the coefficients a, b and c'\n read(*,*,iostat=io_status) a, b, c\n\n ok = io_status==0\n end subroutine\nend module\n\nmodule solve_module\n\n contains\n subroutine solve(e, f, g, root1, root2, ifail)\n implicit none\n\n real, intent(in) :: e, f, g\n real, intent(out) :: root1, root2\n integer, intent(inout) :: ifail\n real :: term, a2\n\n term = f*f-4.*e*g\n a2 = e*2.\n if (term<0.) then\n ifail = 1\n else\n term = sqrt(term)\n root1 = (-f+term)/a2\n root2 = (-f-term)/a2\n end if\n end subroutine\nend module\n\nprogram ch1901\n ! Roots of a Quadratic Equation\n use interact_module\n use solve_module\n implicit none\n\n real :: p, q, r, root1, root2\n integer :: ifail = 0\n logical :: ok = .true.\n\n call interact(p,q,r,ok)\n if (ok) then\n call solve(p,q,r,root1,root2,ifail)\n if (ifail==1) then\n print *, ' complex roots'\n print *, ' calculation abandoned'\n else\n print *, ' roots are ', root1, ' ', root2\n end if\n else\n print *, ' error in data input program ends'\n end if\nend program\n", "meta": {"hexsha": "10bbef8ecac17568e601aca86f5c3974fb9a7c02", "size": 1442, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch19/ch1901.f90", "max_stars_repo_name": "hechengda/fortran", "max_stars_repo_head_hexsha": "44735609ece7995d049016f758590d710b8a4f15", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ch19/ch1901.f90", "max_issues_repo_name": "hechengda/fortran", "max_issues_repo_head_hexsha": "44735609ece7995d049016f758590d710b8a4f15", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch19/ch1901.f90", "max_forks_repo_name": "hechengda/fortran", "max_forks_repo_head_hexsha": "44735609ece7995d049016f758590d710b8a4f15", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.1846153846, "max_line_length": 53, "alphanum_fraction": 0.5249653259, "num_tokens": 413, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026663679976, "lm_q2_score": 0.863391602943619, "lm_q1q2_score": 0.7919914194999212}} {"text": " subroutine wtan(xr,xi,yr,yi)\n*\n* PURPOSE\n* wtan compute the tangent of a complex number\n* y = yr + i yi = tan(x), x = xr + i xi\n*\n* CALLING LIST / PARAMETERS\n* subroutine wtan(xr,xi,yr,yi)\n* double precision xr,xi,yr,yi\n*\n* xr,xi: real and imaginary parts of the complex number\n* yr,yi: real and imaginary parts of the result\n* yr,yi may have the same memory cases than xr et xi\n*\n* ALGORITHM\n* based on the formula :\n*\n* 0.5 sin(2 xr) + i 0.5 sinh(2 xi)\n* tan(xr + i xi) = ---------------------------------\n* cos(xr)^2 + sinh(xi)^2\n* \n* noting d = cos(xr)^2 + sinh(xi)^2, we have :\n*\n* yr = 0.5 * sin(2 * xr) / d (1)\n*\n* yi = 0.5 * sinh(2 * xi) / d (2)\n*\n* to avoid spurious overflows in computing yi with \n* formula (2) (which results in NaN for yi)\n* we use also the following formula :\n*\n* yi = sign(xi) when |xi| > LIM (3)\n*\n* Explanations for (3) :\n*\n* we have d = sinh(xi)^2 ( 1 + (cos(xr)/sinh(xi))^2 ), \n* so when : \n*\n* (cos(xr)/sinh(xi))^2 < epsm ( epsm = max relative error\n* for coding a real in a f.p.\n* number set F(b,p,emin,emax) \n* epsm = 0.5 b^(1-p) )\n* which is forced when :\n*\n* 1/sinh(xi)^2 < epsm (4) \n* <=> |xi| > asinh(1/sqrt(epsm)) (= 19.06... in ieee 754 double)\n*\n* sinh(xi)^2 is a good approximation for d (relative to the f.p. \n* arithmetic used) and then yr may be approximate with :\n*\n* yr = cosh(xi)/sinh(xi) \n* = sign(xi) (1 + exp(-2 |xi|))/(1 - exp(-2|xi|)) \n* = sign(xi) (1 + 2 u + 2 u^2 + 2 u^3 + ...)\n*\n* with u = exp(-2 |xi|)). Now when :\n*\n* 2 exp(-2|xi|) < epsm (2) \n* <=> |xi| > 0.5 * log(2/epsm) (= 18.71... in ieee 754 double)\n* \n* sign(xi) is a good approximation for yr.\n*\n* Constraint (1) is stronger than (2) and we take finaly \n*\n* LIM = 1 + log(2/sqrt(epsm)) \n*\n* (log(2/sqrt(epsm)) being very near asinh(1/sqrt(epsm))\n*\n* AUTHOR\n* Bruno Pincon \n*\n implicit none\n\n* PARAMETER\n double precision xr, xi, yr, yi\n\n* LOCAL VAR\n double precision sr, si, d\n* EXTERNAL\n\n double precision dlamch\n\n external dlamch\n\n* STATIC VAR\n logical first\n\n double precision LIM\n\n save first\n data first /.true./\n save LIM\n\n if (first) then\n* epsm is gotten with dlamch('e')\n LIM = 1.d0 + log(2.d0/sqrt(dlamch('e')))\n first = .false.\n endif\n\n* (0) avoid memory pb ...\n sr = xr\n si = xi\n\n* (1) go on ....\n d = cos(sr)**2 + sinh(si)**2\n yr= 0.5d0*sin(2.d0*sr)/d\n if (abs(si) .lt. LIM) then\n yi=0.5d0*sinh(2.d0*si)/d\n else\n yi=sign(1.d0,si)\n endif \n\n end\n\n\n\n\n", "meta": {"hexsha": "2c41b93260f77a501ee41df376c8888711e16280", "size": 3120, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/calelm/wtan.f", "max_stars_repo_name": "alpgodev/numx", "max_stars_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-07-25T20:28:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-10T18:52:08.000Z", "max_issues_repo_path": "src/math/calelm/wtan.f", "max_issues_repo_name": "alpgodev/numx", "max_issues_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/math/calelm/wtan.f", "max_forks_repo_name": "alpgodev/numx", "max_forks_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.6666666667, "max_line_length": 72, "alphanum_fraction": 0.4580128205, "num_tokens": 995, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897542390751, "lm_q2_score": 0.8418256452674009, "lm_q1q2_score": 0.7919809419232688}} {"text": "! Compute the Planck spectrum for a multigroup problem, to serve as\n! initial conditions.\n\nmodule constants_module\n\n use amrex_fort_module, only : rt => amrex_real\n\n ! fundamental constants\n real(rt), parameter :: h_planck = 6.62606896e-27_rt ! erg s\n real(rt), parameter :: k_B = 1.3806504e-16_rt ! erg / K\n real(rt), parameter :: c_light = 2.99792458e10_rt ! cm / s\n real(rt), parameter :: ev2erg = 1.602176487e-12_rt ! erg/eV\n real(rt), parameter :: pi = 3.14159265358979323846e0_rt\n real(rt), parameter :: sigma_SB = 5.670400e-5_rt ! erg/s/cm^2/K^4\n real(rt), parameter :: a_rad = 4.0e0_rt*sigma_SB/c_light\n\n ! problem parameters\n\n ! specify the energy groups. Ultimately we will work in terms of\n ! frequency, but we set the limits in terms of energy.\n\n ! note: E_min and E_max MUST match the parameters used in CASTRO\n ! to define the group structure.\n integer, parameter :: ngroups_derive = 128 ! number of groups to compute\n real(rt), parameter :: E_min = 0.5e0_rt*ev2erg ! min group energy (erg)\n real(rt), parameter :: E_max = 306e3_rt*ev2erg ! max group energy (erg)\n\n ! instead of computing the group structure based on the above, read the group\n ! structure in from group_structure.dat\n logical, parameter :: use_group_file = .false.\n\n ! physical parameters\n real(rt), parameter :: E_rad = 1.e12_rt ! initial radiation energy density\n real(rt), parameter :: T_0 = (E_rad/a_rad)**0.25e0_rt\n\n\nend module constants_module\n\nfunction safe_print(x) result (sx)\n implicit none\n real(rt) :: x, sx\n sx = x\n if (x < 1.e-99_rt) sx = 0.e0_rt\n\n return\nend function safe_print\n\nfunction planck(nu,T) result (B)\n\n ! the Planck function for a Blackbody (actually, energy density,\n ! B = (4 pi / c) I, where I is the normal Planck function\n !\n ! nu = frequency (Hz)\n ! T = temperature (K)\n\n ! see Swesty and Myra (2009), eq. 23, but note that we are working\n ! in Hz here, so we have units of erg / cm^3 / Hz, where they\n ! have units of erg / cm^3 / MeV. As a result, we have one\n ! less factor of h_planck.\n use constants_module\n implicit none\n\n real(rt), intent(in) :: nu, T\n real(rt) :: B\n\n B = (8.e0_rt*pi*h_planck*nu**3/c_light**3)/(exp(h_planck*nu/(k_B*T)) - 1.e0_rt)\n\n\n return\nend function planck\n\n\nprogram analytic\n\n ! compute the analytic solution to the radiating sphere, as given\n ! by Swesty and Myra (2009), Eq. 76.\n\n use constants_module\n\n implicit none\n\n integer :: ngroups\n real(rt), allocatable :: nu_groups(:), dnu_groups(:), xnu(:)\n real(rt) :: alpha\n real(rt) :: E, F\n real(rt) :: F_radsphere, planck\n real(rt) :: P_simpsonrule\n real(rt) :: safe_print\n integer :: n\n\n character(len=256) :: header_line\n integer :: ipos\n\n if (use_group_file) then\n ! open the file\n open(unit=10,file=\"group_structure.dat\")\n\n ! read in the number of groups\n read(10,fmt='(a256)') header_line\n ipos = index(header_line, \"=\") + 1\n read (header_line(ipos:),*) ngroups\n\n allocate (nu_groups(ngroups), dnu_groups(ngroups))\n\n ! skip the next header line\n read(10,*) header_line\n\n ! read in the group centers and weights (widths)\n do n = 1, ngroups\n read(10,*) nu_groups(n), dnu_groups(n)\n enddo\n\n else\n ngroups = ngroups_derive\n allocate(nu_groups(ngroups),dnu_groups(ngroups),xnu(ngroups+1))\n\n ! try to mimic the way the groups are setup in RadMultiGroup.cpp\n\n ! do geometrically spaced group BOUNDARIES\n xnu(1) = E_min/h_planck\n alpha = (E_max/E_min)**(1.e0_rt/(ngroups))\n\n do n = 2, ngroups+1\n xnu(n) = alpha*xnu(n-1)\n enddo\n\n do n = 1, ngroups\n nu_groups(n) = 0.5e0_rt*(xnu(n) + xnu(n+1))\n enddo\n\n do n = 1, ngroups\n if (n == 1) then\n dnu_groups(n) = 0.5e0_rt*(nu_groups(2) - nu_groups(1))\n\n else if (n < ngroups) then\n dnu_groups(n) = 0.5e0_rt*(nu_groups(n+1) - nu_groups(n-1))\n\n else\n dnu_groups(n) = 0.5e0_rt*(nu_groups(n) - nu_groups(n-1))\n endif\n\n enddo\n\n endif\n\n\n ! compute the analytic radiating sphere solution for each point\n1000 format(1x, i3, 4(1x,g20.10))\n\n print *, \"# group, group center (Hz), ambient BB spectrum x dnu (erg/cm^3)\"\n do n = 1, ngroups\n P_simpsonrule = (dnu_groups(n)/6.0e0_rt)* &\n ( planck(xnu(n),T_0) + &\n 4.0e0_rt*planck(nu_groups(n),T_0) + &\n planck(xnu(n+1),T_0))\n\n write(*,1000) n, nu_groups(n), dnu_groups(n), &\n safe_print(planck(nu_groups(n),T_0)*dnu_groups(n))\n\n enddo\n\nend program analytic\n", "meta": {"hexsha": "8bf78329e97648097b83b279c9ccb79d585c8c72", "size": 4529, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Exec/radiation_tests/RadSourceTest/planck.f90", "max_stars_repo_name": "MargotF/Castro", "max_stars_repo_head_hexsha": "5cdb549af422ef44c9b1822d0fefe043b3533c57", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 178, "max_stars_repo_stars_event_min_datetime": "2017-05-03T18:07:03.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T22:34:53.000Z", "max_issues_repo_path": "Exec/radiation_tests/RadSourceTest/planck.f90", "max_issues_repo_name": "MargotF/Castro", "max_issues_repo_head_hexsha": "5cdb549af422ef44c9b1822d0fefe043b3533c57", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 1334, "max_issues_repo_issues_event_min_datetime": "2017-05-04T14:23:24.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T00:12:06.000Z", "max_forks_repo_path": "Exec/radiation_tests/RadSourceTest/planck.f90", "max_forks_repo_name": "MargotF/Castro", "max_forks_repo_head_hexsha": "5cdb549af422ef44c9b1822d0fefe043b3533c57", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 86, "max_forks_repo_forks_event_min_datetime": "2017-06-12T15:27:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-09T22:21:44.000Z", "avg_line_length": 27.7852760736, "max_line_length": 83, "alphanum_fraction": 0.6480459263, "num_tokens": 1478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897442783526, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7919809335380772}} {"text": "! SYNOPSIS:\n!\n! # gfortran -o gcd-f gcd.f03\n! # ./gcd-f 11 22 33 121\n!\n\nprogram GCD\n implicit none\n\n integer, allocatable :: ns(:)\n integer :: i, n\n character*20 :: tmpstr\n\n n = command_argument_count()\n\n allocate (ns(n)) ! allocate memory for numbers given in command line\n\n do i = 1, n\n call get_command_argument(i, tmpstr)\n ns(i) = str2int(tmpstr)\n end do\n\n print *, gcdn(ns)\n\n deallocate (ns)\n\n! If we declare functions first,\n! we have to specify its types within\n! the `program' section.\n! See http://en.wikibooks.org/wiki/Fortran/Fortran_procedures_and_functions\ncontains\n\n pure integer function str2int(s)\n character*(*), intent(in) :: s\n read (s, *) str2int\n end function\n\n pure recursive integer function gcd2(a, b) result(GCD)\n integer, intent(in) :: a, b\n if (b == 0) then\n GCD = a\n else\n GCD = gcd2(b, mod(a, b))\n end if\n end function gcd2\n\n pure integer function gcdn(n)\n integer, intent(in) :: n(:) ! n is an array\n integer :: i\n gcdn = n(1)\n do i = 2, size(n)\n gcdn = gcd2(gcdn, n(i))\n end do\n end function\n\nend program\n", "meta": {"hexsha": "c2c585dd6435825b9aa597514910c16a0d8b12cc", "size": 1106, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "gcd.f03", "max_stars_repo_name": "ip1981/GCD", "max_stars_repo_head_hexsha": "7e77b68f6879917a27a0fa3426b9ceef242a9879", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2015-04-18T04:59:43.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-05T12:48:32.000Z", "max_issues_repo_path": "gcd.f03", "max_issues_repo_name": "ip1981/gcd", "max_issues_repo_head_hexsha": "7e77b68f6879917a27a0fa3426b9ceef242a9879", "max_issues_repo_licenses": ["WTFPL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gcd.f03", "max_forks_repo_name": "ip1981/gcd", "max_forks_repo_head_hexsha": "7e77b68f6879917a27a0fa3426b9ceef242a9879", "max_forks_repo_licenses": ["WTFPL"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2016-11-23T17:57:40.000Z", "max_forks_repo_forks_event_max_datetime": "2016-11-23T17:57:40.000Z", "avg_line_length": 19.4035087719, "max_line_length": 75, "alphanum_fraction": 0.630198915, "num_tokens": 353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897426182321, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7919809302738607}} {"text": "FUNCTION expint_sp(n,x)\n USE mo_kind, ONLY : i4, sp\n USE mo_nrutil, ONLY : arth,assert,nrerror\n USE mo_constants, ONLY : EULER\n USE mo_utils, ONLY : eq\n\n IMPLICIT NONE\n\n INTEGER(i4), INTENT(IN) :: n\n REAL(SP), INTENT(IN) :: x\n REAL(SP) :: expint_sp\n INTEGER(i4), PARAMETER :: MAXIT=100_i4\n REAL(SP), PARAMETER :: EPS=epsilon(x),BIG=huge(x)*EPS\n INTEGER(i4) :: i,nm1\n REAL(SP) :: a,b,c,d,del,fact,h\n\n call assert(n >= 0_i4, x >= 0.0_sp, (x > 0.0_sp .or. n > 1_i4), &\n 'expint_sp args')\n\n if (n == 0_i4) then\n expint_sp=exp(-x)/x\n RETURN\n end if\n\n nm1=n-1_i4\n\n if (eq(x,0.0_sp)) then\n expint_sp=1.0_sp/nm1\n\n else if (x > 1.0_sp) then\n b=x+n\n c=BIG\n d=1.0_sp/b\n h=d\n\n do i=1_i4,MAXIT\n a=-i*(nm1+i)\n b=b+2.0_sp\n d=1.0_sp/(a*d+b)\n c=b+a/c\n del=c*d\n h=h*del\n if (abs(del-1.0_sp) <= EPS) exit\n end do\n\n if (i > MAXIT) call nrerror('expint_sp: continued fraction failed')\n expint_sp=h*exp(-x)\n\n else\n if (nm1 /= 0_i4) then\n expint_sp=1.0_sp/nm1\n else\n expint_sp=-log(x)-EULER\n end if\n\n fact=1.0_sp\n\n do i=1_i4,MAXIT\n fact=-fact*x/i\n if (i /= nm1) then\n del=-fact/(i-nm1)\n else\n del=fact*(-log(x)-EULER+sum(1.0_sp/arth(1_i4,1_i4,nm1)))\n end if\n\n expint_sp=expint_sp+del\n\n if (abs(del) < abs(expint_sp)*EPS) exit\n end do\n\n if (i > MAXIT) call nrerror('expint_sp: series failed')\n end if\nEND FUNCTION expint_sp\n\nFUNCTION expint_dp(n,x)\n USE mo_kind, ONLY : i4, dp\n USE mo_nrutil, ONLY : arth,assert,nrerror\n USE mo_constants, ONLY : EULER_D\n USE mo_utils, ONLY : eq\n\n IMPLICIT NONE\n\n INTEGER(i4), INTENT(IN) :: n\n REAL(dp), INTENT(IN) :: x\n REAL(dp) :: expint_dp\n INTEGER(i4), PARAMETER :: MAXIT=100_i4\n REAL(dp), PARAMETER :: EPS=epsilon(x),BIG=huge(x)*EPS\n INTEGER(i4) :: i,nm1\n REAL(dp) :: a,b,c,d,del,fact,h\n\n call assert(n >= 0_i4, x >= 0.0_dp, (x > 0.0_dp .or. n > 1_i4), &\n 'expint_dp args')\n\n if (n == 0_i4) then\n expint_dp=exp(-x)/x\n RETURN\n end if\n\n nm1=n-1_i4\n\n if (eq(x,0.0_dp)) then\n expint_dp=1.0_dp/nm1\n\n else if (x > 1.0_dp) then\n b=x+n\n c=BIG\n d=1.0_dp/b\n h=d\n\n do i=1_i4,MAXIT\n a=-i*(nm1+i)\n b=b+2.0_dp\n d=1.0_dp/(a*d+b)\n c=b+a/c\n del=c*d\n h=h*del\n if (abs(del-1.0_dp) <= EPS) exit\n end do\n\n if (i > MAXIT) call nrerror('expint_dp: continued fraction failed')\n expint_dp=h*exp(-x)\n\n else\n if (nm1 /= 0_i4) then\n expint_dp=1.0_dp/nm1\n else\n expint_dp=-log(x)-EULER_D\n end if\n\n fact=1.0_dp\n\n do i=1_i4,MAXIT\n fact=-fact*x/i\n if (i /= nm1) then\n del=-fact/(i-nm1)\n else\n del=fact*(-log(x)-EULER_D+sum(1.0_dp/arth(1_i4,1_i4,nm1)))\n end if\n\n expint_dp=expint_dp+del\n\n if (abs(del) < abs(expint_dp)*EPS) exit\n end do\n\n if (i > MAXIT) call nrerror('expint_dp: series failed')\n end if\nEND FUNCTION expint_dp\n", "meta": {"hexsha": "593655c75b73c5fde3c18015de05e52dfaf52ad2", "size": 3443, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "nr_jams/expint.f90", "max_stars_repo_name": "mcuntz/jams_fortran", "max_stars_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2020-02-28T00:14:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-20T23:32:41.000Z", "max_issues_repo_path": "nr_jams/expint.f90", "max_issues_repo_name": "mcuntz/jams_fortran", "max_issues_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-09T15:33:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T16:16:09.000Z", "max_forks_repo_path": "nr_jams/expint.f90", "max_forks_repo_name": "mcuntz/jams_fortran", "max_forks_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-09T08:08:56.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-09T08:08:56.000Z", "avg_line_length": 23.2635135135, "max_line_length": 75, "alphanum_fraction": 0.4891083358, "num_tokens": 1203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.8740772253241803, "lm_q1q2_score": 0.7919050639353037}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! d_rot2_vec2gen\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine computes the generator for a Givens rotation represented by 2\n! real numbers: A strictly real cosine and a scrictly real sine. The first\n! column is constructed to be parallel with the real vector [A,B]^T. \n!\n! The rot2 refers to a rotation desribed by two double and the vec2 to a vector\n! of lenght two described by two double.\n! \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! A REAL(8) \n! the first component of the real vector [A,B]^T\n!\n! B REAL(8) \n! the second component of the real vector [A,B]^T\n!\n! OUTPUT VARIABLES:\n!\n! C REAL(8)\n! on exit contains the generator for the cosine\n! component of the Givens rotation\n!\n! S REAL(8)\n! on exit contains the generator for the sine\n! component of the Givens rotation\n!\n! NRM REAL(8)\n! on exit contains the norm of the vector [A,B]^T\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine d_rot2_vec2gen(A,B,C,S,NRM)\n\n implicit none\n \n ! input variables\n real(8), intent(in) :: A,B\n real(8), intent(inout) :: C,S,NRM\n\n ! construct rotation\n if ((A.EQ.0d0).AND.(B.EQ.0d0)) then\n C = 1d0\n S = 0d0\n NRM = 0d0\n else if (abs(A).GE.abs(B)) then\n S = B/A\n NRM = sign(sqrt(1d0 + S*S),A)\n C = 1.d0/NRM\n S = S*C\n NRM = A*NRM\n else\n C = A/B;\n NRM = sign(sqrt(1d0 + C*C),B)\n S = 1.d0/NRM\n C = C*S\n NRM = B*NRM\n end if\n \nend subroutine d_rot2_vec2gen\n", "meta": {"hexsha": "d939da002a1c46b699bbdcd35301e9cbe3914d3a", "size": 1892, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/AMVW/src/double/d_rot2_vec2gen.f90", "max_stars_repo_name": "trcameron/FPML", "max_stars_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/AMVW/src/double/d_rot2_vec2gen.f90", "max_issues_repo_name": "trcameron/FPML", "max_issues_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/AMVW/src/double/d_rot2_vec2gen.f90", "max_forks_repo_name": "trcameron/FPML", "max_forks_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2388059701, "max_line_length": 80, "alphanum_fraction": 0.4571881607, "num_tokens": 530, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542185, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.791887344762449}} {"text": "!Subroutine comes here \n\n!Subroutine to find the inverse of a square matrix\n!Author : Louisda16th a.k.a Ashwith J. Rego\n!Reference : Algorithm has been well explained in:\n!http://math.uww.edu/~mcfarlat/inverse.htm \n!http://www.tutor.ms.unimelb.edu.au/matrix/matrix_inverse.html\nSUBROUTINE FINDInv(matrix, inverse, n, errorflag)\n use prec\n IMPLICIT NONE\n !Declarations\n INTEGER, INTENT(IN) :: n\n INTEGER, INTENT(OUT) :: errorflag !Return error status. -1 for error, 0 for normal\n REAL(dp), INTENT(IN), DIMENSION(n,n) :: matrix !Input matrix\n REAL(dp), INTENT(OUT), DIMENSION(n,n) :: inverse !Inverted matrix\n \n LOGICAL :: FLAG = .TRUE.\n INTEGER :: i, j, k, l\n REAL(dp) :: m\n REAL(dp), DIMENSION(n,2*n) :: augmatrix !augmented matrix\n \n !Augment input matrix with an identity matrix\n DO i = 1, n\n DO j = 1, 2*n\n IF (j <= n ) THEN\n augmatrix(i,j) = matrix(i,j)\n ELSE IF ((i+n) == j) THEN\n augmatrix(i,j) = 1d0\n Else\n augmatrix(i,j) = 0d0\n ENDIF\n END DO\n END DO\n \n !Reduce augmented matrix to upper traingular form\n DO k =1, n-1\n IF (augmatrix(k,k) == 0d0) THEN\n FLAG = .FALSE.\n DO i = k+1, n\n IF (augmatrix(i,k) /= 0d0) THEN\n DO j = 1,2*n\n augmatrix(k,j) = augmatrix(k,j)+augmatrix(i,j)\n END DO\n FLAG = .TRUE.\n EXIT\n ENDIF\n IF (FLAG .EQV. .FALSE.) THEN\n PRINT*, \"Matrix is non - invertible\"\n inverse = 0d0\n errorflag = -1\n return\n ENDIF\n END DO\n ENDIF\n DO j = k+1, n\n m = augmatrix(j,k)/augmatrix(k,k)\n DO i = k, 2*n\n augmatrix(j,i) = augmatrix(j,i) - m*augmatrix(k,i)\n END DO\n END DO\n END DO\n \n !Test for invertibility\n DO i = 1, n\n IF (augmatrix(i,i) == 0d0) THEN\n PRINT*, \"Matrix is non - invertible\"\n inverse = 0d0\n errorflag = -1\n return\n ENDIF\n END DO\n \n !Make diagonal elements as 1\n DO i = 1 , n\n m = augmatrix(i,i)\n DO j = i , (2 * n)\n augmatrix(i,j) = (augmatrix(i,j) / m)\n END DO\n END DO\n \n !Reduced right side half of augmented matrix to identity matrix\n DO k = n-1, 1, -1\n DO i =1, k\n m = augmatrix(i,k+1)\n DO j = k, (2*n)\n augmatrix(i,j) = augmatrix(i,j) -augmatrix(k+1,j) * m\n END DO\n END DO\n END DO\n \n !store answer\n DO i =1, n\n DO j = 1, n\n inverse(i,j) = augmatrix(i,j+n)\n END DO\n END DO\n errorflag = 0\nEND SUBROUTINE FINDinv\n", "meta": {"hexsha": "23767d1024aa2380e80b86ecc6a44f19c5393516", "size": 2981, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "CrySPY/f-fingerprint/findinv.f90", "max_stars_repo_name": "sgbaird/CrySPY", "max_stars_repo_head_hexsha": "fc24b312c999aebf6a8a2a56c8d9f17357a277a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 57, "max_stars_repo_stars_event_min_datetime": "2018-01-13T13:01:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T14:25:38.000Z", "max_issues_repo_path": "CrySPY/f-fingerprint/findinv.f90", "max_issues_repo_name": "sgbaird/CrySPY", "max_issues_repo_head_hexsha": "fc24b312c999aebf6a8a2a56c8d9f17357a277a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2018-10-27T09:07:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T15:12:19.000Z", "max_forks_repo_path": "CrySPY/f-fingerprint/findinv.f90", "max_forks_repo_name": "sgbaird/CrySPY", "max_forks_repo_head_hexsha": "fc24b312c999aebf6a8a2a56c8d9f17357a277a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 30, "max_forks_repo_forks_event_min_datetime": "2017-08-18T07:31:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T14:37:27.000Z", "avg_line_length": 30.1111111111, "max_line_length": 88, "alphanum_fraction": 0.4686346863, "num_tokens": 844, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467158, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.7918873396005459}} {"text": "Calculate various trigonometric functions from the Fortran library.\n INTEGER BIT(32),B,IP\t!Stuff for bit fiddling.\n INTEGER ENUFF,I\t\t!Step through the test angles.\n PARAMETER (ENUFF = 17)\t!A selection of special values.\n INTEGER ANGLE(ENUFF)\t!All in whole degrees.\n DATA ANGLE/0,30,45,60,90,120,135,150,180,\t!Here they are.\n 1 210,225,240,270,300,315,330,360/\t\t!Thus check angle folding.\n REAL PI,DEG2RAD\t\t!Special numbers.\n REAL D,R,FD,FR,AD,AR\t!Degree, Radian, F(D), F(R), inverses.\n PI = 4*ATAN(1.0)\t\t!SINGLE PRECISION 1·0.\n DEG2RAD = PI/180\t\t!Limited precision here too for a transcendental number.\nCase the first: sines.\n WRITE (6,10) (\"Sin\", I = 1,4)\t!Supply some names.\n 10 FORMAT (\" Deg.\",A7,\"(Deg)\",A7,\"(Rad) Rad - Deg\",\t!Ah, layout.\n 1 6X,\"Arc\",A3,\"D\",6X,\"Arc\",A3,\"R\",9X,\"Diff\")\n DO I = 1,ENUFF\t\t!Step through the test values.\n D = ANGLE(I)\t\t\t!The angle in degrees, in floating point.\n R = D*DEG2RAD\t\t\t!Approximation, in radians.\n FD = SIND(D); AD = ASIND(FD)\t\t!Functions working in degrees.\n FR = SIN(R); AR = ASIN(FR)/DEG2RAD\t!Functions working in radians.\n WRITE (6,11) INT(D),FD,FR,FR - FD,AD,AR,AR - AD\t!Results.\n 11 FORMAT (I4,\":\",3F12.8,3F13.7)\t!Ah, alignment with FORMAT 10...\n END DO\t\t\t!On to the next test value.\nCase the second: cosines.\n WRITE (6,10) (\"Cos\", I = 1,4)\n DO I = 1,ENUFF\n D = ANGLE(I)\n R = D*DEG2RAD\n FD = COSD(D); AD = ACOSD(FD)\n FR = COS(R); AR = ACOS(FR)/DEG2RAD\n WRITE (6,11) INT(D),FD,FR,FR - FD,AD,AR,AR - AD\n END DO\nCase the third: tangents.\n WRITE (6,10) (\"Tan\", I = 1,4)\n DO I = 1,ENUFF\n D = ANGLE(I)\n R = D*DEG2RAD\n FD = TAND(D); AD = ATAND(FD)\n FR = TAN(R); AR = ATAN(FR)/DEG2RAD\n WRITE (6,11) INT(D),FD,FR,FR - FD,AD,AR,AR - AD\n END DO\n WRITE (6,*) \"...Special deal for 90 degrees...\"\n D = 90\n R = D*DEG2RAD\n FD = TAND(D); AD = ATAND(FD)\n FR = TAN(R); AR = ATAN(FR)/DEG2RAD\n WRITE (6,*) \"TanD =\",FD,\"Atan =\",AD\n WRITE (6,*) \"TanR =\",FR,\"Atan =\",AR\nConvert PI to binary...\n PI = PI - 3\t!I know it starts with three, and I need the fractional part.\n BIT(1:2) = 1\t!So, the binary is 11. something.\n B = 2\t\t!Two bits known.\n DO I = 1,26\t!For single precision, more than enough additional bits.\n PI = PI*2\t\t!Hoist a bit to the hot spot.\n IP = PI\t\t\t!The integral part.\n PI = PI - IP\t\t!Remove it from the work in progress.\n B = B + 1\t\t!Another bit bitten.\n BIT(B) = IP\t\t!Place it.\n END DO\t\t!On to the next.\n WRITE (6,20) BIT(1:B)\t!Reveal the bits.\n 20 FORMAT (\" Pi ~ \",2I1,\".\",66I1)\t!A known format.\n WRITE (6,*) \" = 11.00100100001111110110101010001000100001...\"\t!But actually...\n END\t\t!So much for that.\n", "meta": {"hexsha": "0bd890883a59fd88d55308867d3bee3f33a88499", "size": 2874, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Trigonometric-functions/Fortran/trigonometric-functions-3.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Trigonometric-functions/Fortran/trigonometric-functions-3.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Trigonometric-functions/Fortran/trigonometric-functions-3.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 44.90625, "max_line_length": 86, "alphanum_fraction": 0.5678496868, "num_tokens": 1065, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404018582426, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.7918393563725394}} {"text": "module math\n\n use, intrinsic :: iso_fortran_env, dp=>real64\n\n implicit none\n\n private\n\n public :: PI, &\n multiplyMatrixByVector, &\n getSD\n\n real(dp), parameter :: PI = 4.0_dp * datan(1.0_dp)\n ! TODO: add test as for different PCs NaN code can be different\n real(dp), parameter :: NAN_64 = transfer(-2251799813685248_int64, 1._dp)\n\ncontains\n\n\n function multiplyMatrixByVector(A,x) result(y)\n\n real(dp),dimension(3,3),intent(in) :: A\n real(dp),dimension(3),intent(in) :: x\n real(dp),dimension(3) :: y\n ! TODO: rewrite it with elemental operations\n y(1) = A(1, 1)*x(1) + A(1, 2)*x(2) + A(1, 3)*x(3)\n y(2) = A(2, 1)*x(1) + A(2, 2)*x(2) + A(2, 3)*x(3)\n y(3) = A(3, 1)*x(1) + A(3, 2)*x(2) + A(3, 3)*x(3)\n\n end function\n\n \n function getSD(array) result(sD)\n real(dp), dimension(:), intent(in) :: array\n real(dp) :: sD\n real(dp) :: avg\n real(dp) :: sumOfRestsSquared = 0.0_dp\n\n avg = sum(array) / size(array)\n sumOfRestsSquared = sum((array(:) - avg) ** 2)\n sD = sqrt(sumOfRestsSquared / size(array))\n ! NOTE: this shouldn't be here. What shoud we do when we have \n ! only 1 element?\n if (size(array) == 1) then\n sD = 100.0_dp\n end if\n end function getSD\nend module\n", "meta": {"hexsha": "66cbba98532f3ff3ae25405d83d0e752b501b4d1", "size": 1358, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test_project/modules/1_math.f90", "max_stars_repo_name": "lycantropos/run-fortran", "max_stars_repo_head_hexsha": "13b6ab3b1e2eb0ab56f4f189f8ad665899f65bae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-04-28T19:47:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-05T15:55:52.000Z", "max_issues_repo_path": "test_project/modules/1_math.f90", "max_issues_repo_name": "lycantropos/run-fortran", "max_issues_repo_head_hexsha": "13b6ab3b1e2eb0ab56f4f189f8ad665899f65bae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-07-04T13:37:20.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-11T07:00:02.000Z", "max_forks_repo_path": "test_project/modules/1_math.f90", "max_forks_repo_name": "lycantropos/run-fortran", "max_forks_repo_head_hexsha": "13b6ab3b1e2eb0ab56f4f189f8ad665899f65bae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.7142857143, "max_line_length": 76, "alphanum_fraction": 0.5449189985, "num_tokens": 459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723468, "lm_q2_score": 0.8577681013541611, "lm_q1q2_score": 0.7917535587044514}} {"text": "! Name: ARPIT KUMAR JAIN, Roll No: 180122009\n! Home Assignment Programme-1\n! UV-vis & CD spectra\n!\nPROGRAM HA_Q1\n\n IMPLICIT NONE\n\n ! Declaration of variables \n REAL, PARAMETER :: pi = acos(-1.0)\n REAL:: sigma, nu, nu_i, E_nu, deltaE_nu\n REAL, DIMENSION(40):: lamda_i, fosc, Rstr\n CHARACTER*11:: filename\n INTEGER:: i, lamda, outunit, inunit\n \n ! σ = 2480 cm−1\n sigma = 2480\n\n OPEN(UNIT = inunit, FILE = \"input.dat\") ! Open the input file\n DO i = 1, 40 ! loop over input dataset\n READ(inunit, *) lamda_i(i), fosc(i), Rstr(i) ! Read the input\n ENDDO\n CLOSE(inunit)\n\n WRITE(filename, fmt = \"(A)\") \"output1.dat\" ! filename = output1.dat\n\n OPEN(UNIT = outunit, FILE = filename, FORM = \"formatted\") ! Open the output file\n DO lamda = 200, 600\n\n ! V = 1/λ, λ in \"nm\" and V in \"cm\" so multiply by 10^7\n nu = 10**7 / lamda \n\n ! Set E_nu and deltaE_nu = 0.0 in each iteration so that for each nu we have new E and delE \n E_nu = 0.0\n deltaE_nu = 0.0\n\n DO i = 1, 40\n nu_i = 10**7 / lamda_i(i) ! Vi = 1/λi, λi in \"nm\" and Vi in \"cm\" so multiply by 10^7\n\n ! Calculation for E_nu & deltaE_nu \"SUM i = 1 to n\" part\n E_nu = E_nu + fosc(i) * EXP(-( ( (nu - nu_i) / sigma) * ( (nu - nu_i) / sigma)))\n deltaE_nu = deltaE_nu + nu_i * Rstr(i) * EXP(-( ( (nu - nu_i) / sigma) * ( (nu - nu_i) / sigma)))\n ENDDO\n \n ! Multiply E_nu with constant part which is not effected by SUM over 1 to n \n E_nu = E_nu * 1.3062974 * (10**8) / sigma\n\n ! Multiply deltaE_nu with its constant part \n deltaE_nu = deltaE_nu * ( 1.0 / (22.96 * sqrt(pi) * sigma)) ! (10^-40) / (2.296 * 10^-39) = 1 / 22.96 \n\n WRITE(outunit, *) lamda, E_nu, deltaE_nu ! Write the Output in file\n ENDDO\n CLOSE(outunit)\nEND PROGRAM HA_Q1\n", "meta": {"hexsha": "0f70ab1107109333568a558e39a93c8c2e0eb317", "size": 2079, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "4. Home Assignment-1/1.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "4. Home Assignment-1/1.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4. Home Assignment-1/1.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 37.8, "max_line_length": 118, "alphanum_fraction": 0.5127465127, "num_tokens": 676, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.7917162771243053}} {"text": "program heat\n implicit none\n ! introduce a constants M and pi\n integer, parameter :: M = 10\n real, parameter :: pi = 4. * atan(1.)\n integer :: i, k, N\n real :: h, tau, x\n real, dimension(M + 1) :: u, v\n\n h = 1. / M\n tau = h * h / 2.\n N = 1. / tau\n\n ! initialize the initial data and print the values\n do k=1,M + 1\n x = (k - 1) * h\n u(k) = sin(pi * x)\n write(*,*)0., x, u(k)\n end do\n ! print empty line\n write(*,*)\n\n do i=1,N\n\n ! one step of explicit finite difference method\n v(1) = u(1) ! constant boundary condition\n do k = 2,M\n v(k) = u(k) + (tau / (h * h)) * (u(k - 1) - 2 * u(k) + u(k + 1))\n end do\n v(M + 1) = u(M + 1) ! constant boundary condition\n\n ! can be also written as\n ! v(2:M) = u(2:M) + (tau / (h * h)) * (u(1:M-1) - 2 * u(2:M) + u(3:M+1))\n\n ! print solution values\n do k = 1, M + 1\n write(*,*)i * tau, (k - 1) * h, v(k)\n end do\n ! print empty line\n write(*,*)\n\n u = v\n end do\n\nend program\n", "meta": {"hexsha": "6366483d9df5609f2cf51531b97ab67fd07f8828", "size": 1092, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lec09/heat.f90", "max_stars_repo_name": "rekka/intro-fortran-2016", "max_stars_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-05T01:54:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T01:54:57.000Z", "max_issues_repo_path": "lec09/heat.f90", "max_issues_repo_name": "rekka/intro-fortran-2016", "max_issues_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lec09/heat.f90", "max_forks_repo_name": "rekka/intro-fortran-2016", "max_forks_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-06-22T12:39:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-25T04:45:37.000Z", "avg_line_length": 23.7391304348, "max_line_length": 80, "alphanum_fraction": 0.4423076923, "num_tokens": 396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661945, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7916782619331882}} {"text": "! HOW TO COMPILE THROUGH COMMAND LINE (CMD OR TERMINAL)\n! gfortran -c newton_interpolation.f95\n! gfortran -o newton_interpolation newton_interpolation.o\n!\n! The program is open source and can use to numeric study purpose.\n! The program was build by Aulia Khalqillah,S.Si., M.Si\n!\n! email: auliakhalqillah.mail@gmail.com\n! ==============================================================================\nprogram newtonint\n implicit none\n \n integer, parameter :: N = 5\n integer :: nrow,ncol\n integer :: i,j,k\n real :: x(N),y(N), ms(N-1)\n real :: m(N,N)\n real :: xq, P\n\n ! Initial data\n x(1) = 0.0\n x(2) = 0.2\n x(3) = 0.4\n x(4) = 0.6\n x(5) = 0.8\n y(1) = 1.0\n y(2) = 1.2214\n y(3) = 1.4918\n y(4) = 1.8221\n y(5) = 2.2255\n\n ! Generate initial zero matrix NxN\n nrow = N\n ncol = N \n do i = 1,nrow\n do j = 1,ncol\n m(i,j) = 0\n write(*,*) i,j,m(i,j)\n end do\n end do\n \n write(*,*)\n ! Save the y data to the first column of matrix as zero degree\n do i = 1,nrow\n m(i,1) = y(i)\n end do\n\n ! Check the current matrix\n do i = 1,nrow\n write(*,*) (m(i,j), j = 1,ncol)\n end do\n\n write(*,*)\n ! Calculate the data for remaining column of matrix by using y data \n do j = 2,ncol \n do i = j,nrow\n m(i,j) = (m(i,j-1) - m(i-1,j-1))/(x(i) - x(i-(j-1)))\n end do\n end do\n\n ! Check the current matrix\n do i = 1,nrow\n write(*,*) (m(i,j), j = 1,ncol)\n end do\n\n write(*,*)\n ! Calculate the newton interpolation \n xq = 0.75\n ! Calculate multiplication iteration section\n ms(1) = (xq - x(1))\n do k = 1,n-1\n ms(k+1) = ms(k) * (xq - x(k+1))\n end do\n\n write(*,*)\n ! calculate the summation section\n P = 0\n do k = 2,n\n P = P + (m(k,k) * ms(k-1))\n end do\n\n P = y(1) + P\n write(*,*) P\nend program newtonint", "meta": {"hexsha": "de2176a978a9289cc31f8cafcef88e30f610d191", "size": 1915, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "newton_interpolation.f95", "max_stars_repo_name": "auliakhalqillah/newton_interpolation", "max_stars_repo_head_hexsha": "876521131a5f605565749aa800e9be652db07203", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "newton_interpolation.f95", "max_issues_repo_name": "auliakhalqillah/newton_interpolation", "max_issues_repo_head_hexsha": "876521131a5f605565749aa800e9be652db07203", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "newton_interpolation.f95", "max_forks_repo_name": "auliakhalqillah/newton_interpolation", "max_forks_repo_head_hexsha": "876521131a5f605565749aa800e9be652db07203", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.7976190476, "max_line_length": 80, "alphanum_fraction": 0.4966057441, "num_tokens": 692, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.8688267898240861, "lm_q1q2_score": 0.7916573403068552}} {"text": " subroutine DSBASD(KORDER, LEFT, T, X, IDERIV, BDERIV)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1994-10-20 DSBASD Krogh Changes to use M77CON\nc>> 1993-01-12 DSBASD CLL Bringing all computation inline.\nc>> 1992-11-02 C. L. Lawson, JPL\nc>> 1988-03-22 C. L. Lawson, JPL\nc\nc Given the knot-set T(i), i = 1, ..., NT, this subr computes\nc values at X of the derivative of order IDERIV of each of the\nc the KORDER B-spline basis functions of order KORDER\nc that are nonzero on the open interval (T(LEFT), T(LEFT+1).\nc Require T(LEFT) < T(LEFT+1) and KORDER .le. LEFT .le.\nc NT-KORDER.\nc For proper evaluation, X must lie in the closed interval\nc [T(LEFT), T(LEFT+1], otherwise the computation constitutes\nc extrapolation.\nc The basis functions whose derivatives are returned will be those\nc indexed from LEFT+1-KORDER through LEFT, and their values will be\nc stored in BDERIV(I), I = 1, ..., KORDER.\nc ------------------------------------------------------------------\nc Method:\nc\nc In general there are two stages: First compute values of basis\nc functions of order KORDER-IDERIV. Then, if IDERIV > 0, transform\nc these values to produce values of higher order derivatives of\nc higher order basis functions, ultimately obtaining values of\nc the IDERIV derivative of basis functions of order KORDER.\nc\nc The first stage uses the recursion:\nC\nC X - T(I) T(I+J+1) - X\nC B(I,J+1)(X) = -----------B(I,J)(X) + ---------------B(I+1,J)(X)\nC T(I+J)-T(I) T(I+J+1)-T(I+1)\nC\nc where B(I,J) denotes the basis function of order J and index I.\nc For order J, the only basis functions that can be nonzero on\nc [T(LEFT), T(LEFT+1] are those indexed from LEFT+1-J to LEFT.\nc For order 1, the only basis function nonzero on this interval is\nc is B(LEFT,1), whose value is 1. The organization of the calculation\nc using the above recursion follows Algorithm (8) in Chapter X of the\nc book by DeBoor.\nc\nc For the second stage, let B(ID, K, J) denote the value at X of the\nc IDth derivative of the basis function of order K, with index J.\nc From the first stage we will have values of B(0, KORDER-IDERIV, j)\nc for j = LEFT+1-KORDER+IDERIV), ..., LEFT, stored in BDERIV(i), for\nc i = 1+IDERIV, ..., KORDER.\nc\nc Loop for ID = 1, ..., IDERIV\nc Replace the contents of BDERIV() by values of\nc B(ID, KORDER-IDERIV+ID, j) for\nc j = LEFT+1-KORDER+IDERIV-ID), ..., LEFT, storing these in\nc BDERIV(i), i = 1+IDERIV-ID, ..., KORDER.\nc End loop\nc\nc The above loop uses formula (10), p. 138, of\nc A PRACTICAL GUIDE TO SPLINES by Carl DeBoor, Springer-Verlag,\nc 1978, when ID = 1, and successive derivatives of that formula\nc when ID > 1. Note that we are using Formula (10) in the special\nc case in which (Alpha sub i) = 1, and all other Alpha's are zero.\nc\nc This approach and implementation by C. L. Lawson, JPL, March 1988.\nC ------------------------------------------------------------------\nC KORDER [in] Gives both the order of the B-spline basis functions\nc whose derivatives are to be evaluated,\nc and the number of such functions to be evaluated.\nc Note that the polynomial degree of these functions is one less\nc than the order. Example: For cubic splines the order is 4.\nc Require 1 .le. KORDER .le. KMAX, where KMAX is an internal\nc parameter.\nc LEFT [in] Index identifying the left end of the interval\nc [T(LEFT), T(LEFT+1)] relative to which the B-spline basis\nc functions will be evaluated.\nc Require KORDER .le. LEFT .le. NT-KORDER\nc and T(LEFT) < T(LEFT+1)\nc The evaluation is proper if T(LEFT) .le. X .le. T(LEFT+1), and\nc otherwise constitutes extrapolation.\nC DIVISION BY ZERO will result if T(LEFT) = T(LEFT+1)\nC T() [in] Knot sequence, indexed from 1 to NT, with\nc NT .ge. LEFT+KORDER. Knot values must be nonincreasing.\nc Repetition of values is permitted and has the effect of\nc decreasing the order of contimuity at the repeated knot.\nc Proper function representation by splines of order K is\nc supported on the interval from T(K) to T(NT+1-K).\nc Extrapolation can be done outside this interval.\nC X [in] The abcissa at which the B-spline basis functions are to\nc be evaluated. The evaluation is proper if T(KORDER) .le. X .le\nc T(NT+1-KORDER), and constitutes extrapolation otherwise.\nc IDERIV [in] Order of derivative requested. Require IDERIV .ge. 0.\nc Derivatives of order .ge. KORDER are zero.\nC BDERIV() [out] On normal return, this array will contain in\nc BDERIV(i), i = 1, ...,KORDER, the values computed by this subr.\nc These are values at X of the derivative of order IDERIV of each\nc of the basis functions indexed LEFT+1-KORDER through LEFT.\nC ------------------------------------------------------------------\nc--D replaces \"?\": ?SBASD\nc Both versions use IERM1, IERV1\nC ------------------------------------------------------------------\n integer KMAX\n parameter(KMAX = 20)\n integer I, I1, ID, IDERIV, ISTART, IT1, IT2\n integer J, JP1, K1, KORDER, LEFT\n double precision BDERIV(KORDER), DELTAL(KMAX), DELTAR(KMAX), FLK1\n double precision SAVED, T(LEFT+KORDER), TERM, X\nC ------------------------------------------------------------------\n ID = IDERIV\n if(ID .lt. 0 ) then\n call IERM1('DSBASD',2,2,'Require IDERIV .ge. 0',\n * 'IDERIV',ID,'.')\n return\n endif\n if(ID .ge. KORDER) then\n do 5 I = 1, KORDER\n BDERIV(I) = 0.0d0\n 5 continue\n return\n endif\n if(KORDER .gt. KMAX) then\n call IERM1('DSBASD',1,2,'Require KORDER .le. KMAX.',\n * 'KORDER',KORDER,',')\n call IERV1('KMAX',KMAX,'.')\n return\n endif\n ISTART = 1+ID\n K1 = KORDER - ID\nc\nc Evaluate K1 basis functions of order K1. Store values in\nc BDERIV(ISTART:ISTART+K1-1)\nc\n BDERIV(ISTART) = 1.0d0\n do 30 J = 1, K1-1\n JP1 = J + 1\n DELTAR(J) = T(LEFT+J) - X\n DELTAL(J) = X - T(LEFT+1-J)\n SAVED = 0.0d0\n do 26 I=1,J\n TERM = BDERIV(ID+I)/(DELTAR(I) + DELTAL(JP1-I))\n BDERIV(ID+I) = SAVED + DELTAR(I)*TERM\n SAVED = DELTAL(JP1-I)*TERM\n 26 continue\n BDERIV(ID+JP1) = SAVED\n 30 continue\nc\nc Loop IDERIV times, each time advancing the order of the\nc derivative by one, so final results are values of derivatives\nc of order IDERIV.\nc\n do 70 I1 = ISTART, 2, -1\n FLK1 = dble(K1)\n IT1 = LEFT+1-I1\n IT2 = IT1 - K1\n do 50 I = I1, KORDER\n BDERIV(I) = BDERIV(I) * FLK1 /(T(IT1+I) - T(IT2+I))\n 50 continue\nc\n BDERIV(I1-1) = -BDERIV(I1)\n do 60 I = I1, KORDER-1\n BDERIV(I) = BDERIV(I) - BDERIV(I+1)\n 60 continue\n K1 = K1 + 1\n 70 continue\n return\n end\n", "meta": {"hexsha": "6c4f5ddbdfbe6dff315b85fd0f64e4efa8011d1c", "size": 7212, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dsbasd.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/dsbasd.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/dsbasd.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 43.4457831325, "max_line_length": 72, "alphanum_fraction": 0.5973377704, "num_tokens": 2226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065459, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.7915464281087242}} {"text": "!-------------------------------------------------------------------------------!\r\n! !\r\n\r\n subroutine gauss(n,a,b,c) \r\n\r\n! !\r\n! This subroutine solves the n x n linear system ac = b !\r\n! by Gauss-elimination with pivoting !\r\n! !\r\n! On input: !\r\n! n dimension of the system !\r\n! a(n,n) coefficient matrix !\r\n! b(n) righthand side !\r\n! !\r\n! On output: !\r\n! c(n) solutions to the system !\r\n! !\r\n! Authors: !\r\n! Per J\\\"onsson, Malm\\\"o University, Sweden !\r\n! e-mail per.jonsson@ts.mah.se !\r\n! !\r\n! Lars Eklundh, Lund University, Sweden !\r\n! e-mail lars.eklundh@nateko.lu.se !\r\n! !\r\n! Updated 26/3-2005 !\r\n! !\r\n!-------------------------------------------------------------------------------!\r\n \r\n implicit none \r\n \r\n integer :: i,j,k,n,pos(1)\r\n double precision :: a(n,n),b(n),c(n),f,temp1(n),temp2\r\n \r\n!---- Elimination ---------------------------------------------------------------\r\n \r\n do i = 1,n-1\r\n pos(1:1) = maxloc(abs(a(i:n,i)))\r\n if (pos(1) > 1) then\r\n temp1 = a(i,:)\r\n temp2 = b(i)\r\n a(i,:) = a(i+pos(1)-1,:)\r\n b(i) = b(i+pos(1)-1)\r\n a(i+pos(1)-1,:) = temp1\r\n b(i+pos(1)-1) = temp2\r\n end if\r\n do j = i+1,n\r\n f = - a(j,i)/a(i,i)\r\n a(j,:) = a(j,:) + f*a(i,:)\r\n b(j) = b(j) + f*b(i)\r\n end do\r\n end do\r\n\r\n!---- Back substitution ---------------------------------------------------------\r\n \r\n do i = 1,n\r\n if (abs(a(i,i)) < 1d-80) then\r\n c = 0.d0\r\n!\t write(*,*) 'Bad condition in gauss'\r\n return\r\n end if\r\n end do\r\n\r\n c(n) = b(n)/a(n,n)\r\n do i = n-1,1,-1\r\n c(i) = (b(i) - sum(a(i,i+1:n)*c(i+1:n)) )/a(i,i) \t\r\n end do\r\n \r\n end subroutine gauss\r\n", "meta": {"hexsha": "aa15713d3eb219f49826df5bd822bd26072c28ad", "size": 3126, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/Smooth_Gapfill_LAI/gauss.f90", "max_stars_repo_name": "bucricket/projectMASpreprocess", "max_stars_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-28T20:26:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T20:26:59.000Z", "max_issues_repo_path": "source/Smooth_Gapfill_LAI/gauss.f90", "max_issues_repo_name": "bucricket/projectMASpreprocess", "max_issues_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/Smooth_Gapfill_LAI/gauss.f90", "max_forks_repo_name": "bucricket/projectMASpreprocess", "max_forks_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-04-20T21:04:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-16T08:05:44.000Z", "avg_line_length": 45.3043478261, "max_line_length": 82, "alphanum_fraction": 0.2098528471, "num_tokens": 567, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810421953309, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.791521269939306}} {"text": "SUBROUTINE spear(data1,data2,n,wksp1,wksp2,d,zd,probd,rs,probrs)\r\nINTEGER n\r\nREAL*8 d,probd,probrs,rs,zd,data1(n),data2(n),wksp1(n),wksp2(n)\r\n!CU USES betai,crank,erfcc,sort2\r\nINTEGER j\r\nREAL*8 aved,df,en,en3n,fac,sf,sg,t,vard,betai,erfcc\r\ndo j=1,n\r\n wksp1(j)=data1(j)\r\n wksp2(j)=data2(j)\r\nenddo\r\ncall sort2(n,wksp1,wksp2)\r\ncall crank(n,wksp1,sf)\r\ncall sort2(n,wksp2,wksp1)\r\ncall crank(n,wksp2,sg)\r\nd=0.\r\ndo j=1,n\r\n d=d+(wksp1(j)-wksp2(j))**2\r\nenddo\r\nen=n\r\nen3n=en**3-en\r\naved=en3n/6.-(sf+sg)/12.\r\nfac=(1.-sf/en3n)*(1.-sg/en3n)\r\nvard=((en-1.)*en**2*(en+1.)**2/36.)*fac\r\nzd=(d-aved)/sqrt(vard)\r\nprobd=erfcc(abs(zd)/1.4142136)\r\nrs=(1.-(6./en3n)*(d+(sf+sg)/12.))/sqrt(fac)\r\nfac=(1.+rs)*(1.-rs)\r\nif(fac.gt.0.)then\r\n t=rs*sqrt((en-2.)/fac)\r\n df=en-2.\r\n probrs=betai(0.5*df,0.5,df/(df+t**2))\r\nelse\r\n probrs=0.\r\nendif\r\nreturn\r\nEND\r\n", "meta": {"hexsha": "b8f1d2c73a8d2ffe52608816ec428d7f48e79f53", "size": 835, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "spear/spear.f90", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "spear/spear.f90", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "spear/spear.f90", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.5675675676, "max_line_length": 65, "alphanum_fraction": 0.6263473054, "num_tokens": 410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810436809827, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7915212653593331}} {"text": "program main\n implicit none\n integer :: i, n\n real(8) :: ff_0, ff_p, ff_m, dfdx_f, dfdx_m, dfdx_e\n real(8) :: x, h\n\n x = 0d0\n dfdx_e = exp(x)\n \n h = 1d0\n \n n = 16\n open(20,file=\"fd_error.out\")\n do i = 1, n\n ff_0 = exp(x)\n ff_p = exp(x+h)\n ff_m = exp(x-h)\n\n dfdx_f = (ff_p-ff_0)/h\n dfdx_m = (ff_p-ff_m)/(2d0*h)\n\n write(20,\"(5e16.6e3)\")h,dfdx_f,abs(dfdx_f - dfdx_e),dfdx_m,abs(dfdx_m - dfdx_e)\n \n h = h/2d0\n end do\n close(20)\n\n \nend program main\n", "meta": {"hexsha": "1fd46aea964fc77e21b8a7503ddfc2c487358973", "size": 493, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lesson1_1.f90", "max_stars_repo_name": "shunsuke-sato/intro_qm_fortran", "max_stars_repo_head_hexsha": "c39921b64c4ccf39223e5fb9e7d00001e8d91972", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/lesson1_1.f90", "max_issues_repo_name": "shunsuke-sato/intro_qm_fortran", "max_issues_repo_head_hexsha": "c39921b64c4ccf39223e5fb9e7d00001e8d91972", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lesson1_1.f90", "max_forks_repo_name": "shunsuke-sato/intro_qm_fortran", "max_forks_repo_head_hexsha": "c39921b64c4ccf39223e5fb9e7d00001e8d91972", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.4333333333, "max_line_length": 84, "alphanum_fraction": 0.5436105477, "num_tokens": 227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8479677545357569, "lm_q1q2_score": 0.7915192288431742}} {"text": "\tFUNCTION PR_WCMP ( drct, sped, dcmp )\nC************************************************************************\nC* PR_WCMP \t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes the wind component toward a specified\t\t*\nC* direction. The following equation is used:\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* WCMP = -COS ( DRCT - DCMP ) * SPED\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* WCMP = component of wind in meters/second\t\t\t*\nC* DRCT = wind direction in degrees\t\t\t\t*\nC* DCMP = direction of desired component\t\t\t*\nC* SPED = wind speed in meters/second\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_WCMP ( DRCT, SPED, DCMP )\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tDRCT\t\tREAL\t\tWind direction in degrees\t*\nC*\tSPED\t\tREAL\t\tWind speed in meters/second\t*\nC*\tDCMP\t\tREAL\t\tDirection of desired component\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_WCMP\t\tREAL\t\tComponent of wind in m/s\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* John Nielsen/MIT\t 9/88\t\t\t\t\t\t*\nC* John Nielsen/SUNYA\t 8/90\tGEMPAK 5\t\t\t\t*\nC* J. Whistler/SSAI\t 7/91\tChanged COSD to COS and converted to rad*\nC* T. Piper/GSC\t\t11/98\tUpdated prolog\t\t\t\t*\nC************************************************************************\nC*\n\tINCLUDE\t\t'GEMPRM.PRM'\n\tINCLUDE\t\t'ERMISS.FNC'\nC------------------------------------------------------------------------\nC\nC* \tCheck for missing input parameters.\nC\n\tIF ( ERMISS (sped) .or. ERMISS (drct) .or. ERMISS (dcmp)) THEN\n\t PR_WCMP = RMISSD\n\t ELSE\nC\nC*\tCalculate wind speed toward specified direction.\nC\n\t PR_WCMP = (-COS( ( drct - dcmp ) * DTR )) * sped\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "aa8d1239c26079de2fad753d2154c4e49d4cedd9", "size": 1558, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prwcmp.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/prmcnvlib/pr/prwcmp.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/prmcnvlib/pr/prwcmp.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 31.7959183673, "max_line_length": 73, "alphanum_fraction": 0.5109114249, "num_tokens": 490, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9626731115849662, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7914993685909039}} {"text": " !! ----------------------------------------------------------------------- !!\n !>\n !! Tsunami initial height.\n !! Tsunami height eta(:,:) ( in m-unit ) must be defined here.\n !<\n !! --\n block\n\n real, parameter :: aa = 16000.\n real, parameter :: bb = 16000.\n integer :: i, j, i0, j0\n real :: hx, hy\n !! ----\n\n i0 = nx/2\n j0 = ny/2\n eta(:,:) = 0.0\n do j=1, ny\n if( -bb <= (j-j0)*dy .and. (j-j0) * dy <= bb ) then\n hy = ( 1 + cos( pi * ( j-j0 ) * dy / bb ) ) / 2.0\n else\n hy = 0.0\n end if\n do i=1, nx\n\n if( -aa <= (i-i0)*dx .and. (i-i0) * dx <= aa ) then\n hx = ( 1 + cos( pi * ( i-i0 ) * dx / aa ) ) / 2.0\n else\n hx = 0.0\n end if\n\n eta(i,j) = hx * hy\n\n end do\n\n end do\n\n end block\n", "meta": {"hexsha": "b291cd49f8380db130864ba9c50c515a87fd4b2d", "size": 827, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "blk_initheight.f90", "max_stars_repo_name": "takuto-maeda/tsunami_pml", "max_stars_repo_head_hexsha": "94f84e456874b85203d6fce9f5e0309010d95eb8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-01-20T06:58:05.000Z", "max_stars_repo_stars_event_max_datetime": "2017-10-08T22:35:21.000Z", "max_issues_repo_path": "blk_initheight.f90", "max_issues_repo_name": "takuto-maeda/tsunami_pml", "max_issues_repo_head_hexsha": "94f84e456874b85203d6fce9f5e0309010d95eb8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "blk_initheight.f90", "max_forks_repo_name": "takuto-maeda/tsunami_pml", "max_forks_repo_head_hexsha": "94f84e456874b85203d6fce9f5e0309010d95eb8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-12-08T13:32:25.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-08T13:32:25.000Z", "avg_line_length": 21.2051282051, "max_line_length": 79, "alphanum_fraction": 0.345828295, "num_tokens": 295, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474194456935, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7913442982767174}} {"text": "MODULE vector_module\nIMPLICIT NONE\nTYPE :: vector\n REAL :: x\n REAL :: y\nEND TYPE vector\n\nCONTAINS\n TYPE (vector) FUNCTION vector_add(v1, v2)\n IMPLICIT NONE\n TYPE (vector), INTENT(IN) :: v1, v2\n vector_add = vector(v1%x + v2%x, v1%y + v2%y)\n END FUNCTION vector_add\n\n TYPE (vector) FUNCTION vector_sub(v1, v2)\n IMPLICIT NONE\n TYPE (vector), INTENT(IN) :: v1, v2\n vector_sub = vector(v1%x - v2%x, v1%y - v2%y)\n END FUNCTION vector_sub\nEND MODULE vector_module\n\nPROGRAM test_vectors\nUSE vector_module\nIMPLICIT NONE\nTYPE (vector) :: a, b, c\na = vector(1., 2.)\nb = vector(6., 9.)\nc = vector_add(a, b)\nWRITE(*, *) c\nc = vector_sub(a, b)\nWRITE(*, *) c\nEND PROGRAM test_vectors\n", "meta": {"hexsha": "3173cb4efa505e03d5700b1dd65fc170174bb976", "size": 682, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap12/test_vectors.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap12/test_vectors.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap12/test_vectors.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.6666666667, "max_line_length": 47, "alphanum_fraction": 0.6774193548, "num_tokens": 236, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465188527685, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7912493175191871}} {"text": "subroutine apply_pde_operator(t, q, output)\n\n! For the PDE q_t = g(q), calculates g(q).\n!\n! Args:\n! t: Time at which the operator is evaluated.\n! q: PDE solution at time t.\n! output: g(q), calculated here.\n\n implicit none\n \n integer :: mx, mbc, meqn\n double precision :: x_lower, dx\n common /claw_config/ mx, mbc, x_lower, dx, meqn\n \n double precision, intent(in) :: t\n double precision, dimension(1-mbc:mx+mbc, meqn), intent(in) :: q\n double precision, dimension(1-mbc:mx+mbc, meqn), intent(out) :: output\n\n integer :: ix\n\n do ix = 1, mx\n output(ix, 1) = (q(ix-1, 1) - 2 * q(ix, 1) + q(ix+1, 1)) / dx**2\n end do\n\nend subroutine apply_pde_operator\n", "meta": {"hexsha": "2c03c69a6a9d80a9d469c4a276801b288865571b", "size": 697, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/1d/Order2Linear/apply_pde_operator.f90", "max_stars_repo_name": "claridge/implicit_solvers", "max_stars_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-04-29T00:16:18.000Z", "max_stars_repo_stars_event_max_datetime": "2017-04-29T00:16:18.000Z", "max_issues_repo_path": "applications/1d/Order2Linear/apply_pde_operator.f90", "max_issues_repo_name": "claridge/implicit_solvers", "max_issues_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/1d/Order2Linear/apply_pde_operator.f90", "max_forks_repo_name": "claridge/implicit_solvers", "max_forks_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.8148148148, "max_line_length": 74, "alphanum_fraction": 0.6154949785, "num_tokens": 232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465134460243, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7912493147618135}} {"text": "module non_linear_solvers\n !! Module for solving non-linear equations of the form:\n !! $$ \\mathbf{f}\\left(\\mathbf{x}\\right)=\\mathbf{0} $$\n !! There are specific functions for the scalar case.\n\n use linear_solvers, only: solve\n\n implicit none\n\ncontains\n\n function Bisection(f,a,b,err_x) result(x)\n !! Solves the scalar non-linear equation:\n !! $$ f(x)=0 $$\n !! using the bisection method on the interval \\([a,b]\\)\n interface\n function f(x) result(y)\n !! function defining the non-linear equation\n real, intent(in) :: x\n !! independent variable\n real :: y\n !! dependent variable\n end function\n end interface\n real, intent(in) :: a\n !! left boundary of the interval\n real, intent(in) :: b\n !! right boundary of the interval\n real, intent(in) :: err_x\n !! admisible error in the solution, that is:\n !! $$ x_\\mathrm{true} = x \\pm \\frac{\\epsilon_{x}}{2} $$\n real :: x\n !! numerical aproximation to the solution\n\n integer :: N, i\n real :: x_l, x_r\n\n if(f(a)*f(b)>=0) error stop \"f(a) and f(b) must have different signs\"\n\n if (a>b) then\n error stop \"a cannot be greater than b\"\n else if(a==b) then\n x=a\n return\n else\n N = ceiling(log((b-a)/err_x)/log(2.))\n end if\n x_l = a\n x_r = b\n do i = 1, N\n x = (x_l+x_r)/2\n if ( f(x)==0)then\n exit\n else if(f(x)*f(x_l)>0) then\n x_l = x\n else\n x_r = x\n end if\n end do\n end function\n\n function Newton(f, df, x0, err_x, err_f, max_iter) result(x)\n !! Solves the scalar non-linear equation:\n !! $$ f(x) = 0 $$\n !! using Newton's method.\n interface\n function f(x) result(y)\n !! function defining the non-linear equation\n real, intent(in) :: x\n !! independent variable\n real :: y\n !! dependent variable\n end function\n function df(x) result(y)\n !! derivative of function \\(f\\)\n real, intent(in) :: x\n !! independent variable\n real :: y\n !! dependent variable\n end function\n end interface\n real, intent(in) :: x0\n !! initial aproximation to the solution\n real, intent(in) :: err_x\n !! admisible error in the solution\n real, intent(in) :: err_f\n !! admisible error in the equation\n integer, intent(in) :: max_iter\n !! maximum number of iterations\n real :: x\n !! numerical aproximation to the solution\n\n integer :: i\n real :: x_old\n\n x_old = x0\n do i = 1, max_iter\n x = x_old - f(x_old)/df(x_old)\n if ( ( abs(f(x))max_iter) print*, \"maximum number of iterations reached without convergence\"\n end function\n\n function Secant(f, x0, err_x, err_f, max_iter) result(x)\n !! Solves the scalar non-linear equation:\n !! $$ f(x) = 0 $$\n !! using the secant method.\n interface\n function f(x) result(y)\n !! function defining the non-linear equation\n real, intent(in) :: x\n !! independent variable\n real :: y\n !! dependent variable\n end function\n end interface\n real, intent(in) :: x0(2)\n !! array containing the first and second aproximations to the solution\n real, intent(in) :: err_x\n !! admisible error in the solution\n real, intent(in) :: err_f\n !! admisible error in the equation\n integer, intent(in) :: max_iter\n !! maximum number of iterations\n real :: x\n !! numerical aproximation to the solution\n\n integer :: i\n real :: x_old(2)\n\n x_old = x0\n do i = 1, max_iter\n x = x_old(2) - f(x_old(2))* (x_old(2) - x_old(1)) / ( f(x_old(2))-f(x_old(1)))\n if ( ( abs(f(x))max_iter) print*, \"maximum number of iterations reached without convergence\"\n end function\n\n function VectorNewton(f, J, x0, err_x, err_f, max_iter) result(x)\n !! Solves the vector non-linear equation:\n !! $$ f(x) = 0 $$\n !! using Newton's method.\n interface\n function f(x) result(y)\n !! function defining the non-linear equation\n real, intent(in) :: x(:)\n !! independent variable\n real :: y(size(x))\n !! dependent variable\n end function\n function J(x) result(y)\n !! jacobian of function \\(f\\)\n real, intent(in) :: x(:)\n !! independent variable\n real :: y(size(x), size(x))\n !! dependent variable\n end function\n end interface\n real, intent(in) :: x0(:)\n !! initial aproximation to the solution: \\((x_0,y_0)\\)\n real, intent(in) :: err_x\n !! admisible error in the solution\n real, intent(in) :: err_f\n !! admisible error in the equation\n integer, intent(in) :: max_iter\n !! maximum number of iterations\n real :: x(size(x0))\n !! numerical aproximation to the solution\n\n integer :: i\n real :: x_old(size(x0))\n\n x_old = x0\n print*, J(x_old)\n do i = 1, max_iter\n x = x_old - solve(J(x_old),f(x_old))\n if ( ( norm2(f(x))max_iter) print*, \"maximum number of iterations reached without convergence\"\n end function\n\nend module\n", "meta": {"hexsha": "f52d059c61005e10e07b230cb8d7649e15b11ecc", "size": 5304, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/non_linear_solvers.f08", "max_stars_repo_name": "MPenaR/NumericalMethods", "max_stars_repo_head_hexsha": "b3a46676d762d749c9d278efe4c98f41d3886a4b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-20T01:52:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-20T01:52:07.000Z", "max_issues_repo_path": "docs/src/non_linear_solvers.f08", "max_issues_repo_name": "MPenaR/NumericalMethods", "max_issues_repo_head_hexsha": "b3a46676d762d749c9d278efe4c98f41d3886a4b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-03-19T22:17:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-07T17:57:58.000Z", "max_forks_repo_path": "src/non_linear_solvers.f90", "max_forks_repo_name": "MPenaR/NumericalMethods", "max_forks_repo_head_hexsha": "b3a46676d762d749c9d278efe4c98f41d3886a4b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.5161290323, "max_line_length": 86, "alphanum_fraction": 0.5812594268, "num_tokens": 1504, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465044347828, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7912493071388219}} {"text": "!>\n!! This module handles the diffusion terms in the equation. It provides a second and fourth order centred discretization of\n!!\n!! \\\\( \\\\Delta q = q_{xx} + q_{yy} + q_{zz} \\\\)\n!!\nMODULE diffusion\n\nIMPLICIT NONE\n\nPUBLIC :: GetRHSDiffusion, InitializeDiffusion\n\nTYPE diffusion_parameter\n INTEGER :: i_min, i_max, j_min, j_max, k_min, k_max\n DOUBLE PRECISION :: nu\nEND TYPE\n\nTYPE(diffusion_parameter) :: param\n\n!> Finite difference weight in the fourth order centred stencil\nDOUBLE PRECISION, PARAMETER :: w1 = 1.0_8/12.0_8\n\n!> Finite difference weight in the fourth order centred stencil\nDOUBLE PRECISION, PARAMETER :: w2 = 4.0_8/3.0_8\n\n!> Finite difference weight in the fourth order centred stencil\nDOUBLE PRECISION, PARAMETER :: w3 = 5.0_8/2.0_8\n\nCONTAINS\n\n !> Computes the contribution from the diffusive terms to the right hand side of the initial value problem.\n !! param[in] Q The solution\n !! param[out] RQ Discrete diffusion operator applied to Q\n !! param[in] order Either two or four.\n SUBROUTINE GetRHSDiffusion(Q, RQ, dx, dy, dz, i_start, i_end, j_start, j_end, k_start, k_end, order)\n DOUBLE PRECISION, DIMENSION(param%i_min:, param%j_min:, param%k_min:), INTENT(IN) :: Q\n DOUBLE PRECISION, DIMENSION(param%i_min:, param%j_min:, param%k_min:), INTENT(OUT) :: RQ\n DOUBLE PRECISION, INTENT(IN) :: dx, dy, dz\n INTEGER, INTENT(IN) :: i_start, i_end, j_start, j_end, k_start, k_end, order\n \n DOUBLE PRECISION :: stencil_i, stencil_j, stencil_k, coeff_i, coeff_j, coeff_k\n \n INTEGER :: i, j, k\n \n SELECT CASE (order)\n \n CASE (2)\n \n coeff_i = 1.0/(dx*dx)\n coeff_j = 1.0/(dy*dy)\n coeff_k = 1.0/(dz*dz)\n \n DO k=k_start, k_end\n DO j=j_start, j_end\n DO i=i_start, i_end\n stencil_i = coeff_i*(Q(i+1,j,k) - 2.0*Q(i,j,k) + Q(i-1,j,k))\n stencil_j = coeff_j*(Q(i,j+1,k) - 2.0*Q(i,j,k) + Q(i,j-1,k))\n stencil_k = coeff_k*(Q(i,j,k+1) - 2.0*Q(i,j,k) + Q(i,j,k-1))\n RQ(i,j,k) = RQ(i,j,k) + param%nu*(stencil_i + stencil_j + stencil_k)\n END DO\n END DO\n END DO \n \n CASE (4)\n \n coeff_i = 1.0/(dx*dx)\n coeff_j = 1.0/(dy*dy)\n coeff_k = 1.0/(dz*dz)\n \n DO k=k_start, k_end\n DO j=j_start, j_end\n DO i=i_start, i_end\n stencil_i = coeff_i*( -w1*Q(i+2,j,k) + w2*Q(i+1,j,k) &\n - w3*Q(i,j,k) + w2*Q(i-1,j,k) - w1*Q(i-2,j,k) )\n \n stencil_j = coeff_j*( -w1*Q(i,j+2,k) + w2*Q(i,j+1,k) &\n -w3*Q(i,j,k) + w2*Q(i,j-1,k) - w1*Q(i,j-2,k) )\n \n stencil_k = coeff_k*( -w1*Q(i,j,k+2) + w2*Q(i,j,k+1) &\n -w3*Q(i,j,k) + w2*Q(i,j,k-1) - w1*Q(i,j,k-2) )\n \n RQ(i,j,k) = RQ(i,j,k) + param%nu*( stencil_i + stencil_j + stencil_k ) \n END DO\n END DO\n END DO\n \n CASE DEFAULT\n WRITE(*,'(A,I2,A)') 'No implementation available for order = ', order, ' .. now exiting'\n STOP \n END SELECT \n \n END SUBROUTINE GetRHSDiffusion\n\n !> Initialize the diffusion module\n SUBROUTINE InitializeDiffusion(i_min, i_max, j_min, j_max, k_min, k_max, nu)\n \n DOUBLE PRECISION, INTENT(IN) :: nu \n INTEGER, INTENT(IN) :: i_min, i_max, j_min, j_max, k_min, k_max\n \n param%nu = nu \n param%i_min = i_min\n param%i_max = i_max\n param%j_min = j_min\n param%j_max = j_max\n param%k_min = k_min\n param%k_max = k_max\n \n END SUBROUTINE InitializeDiffusion\n \nEND MODULE diffusion", "meta": {"hexsha": "ea172995b8d4a15c9513436b2f72ac4f9af77e76", "size": 4205, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/diffusion.f90", "max_stars_repo_name": "Parallel-in-Time/PararealF90", "max_stars_repo_head_hexsha": "a8318a79b92465a8a3cf775cc7fd096ff0494529", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-03-17T15:04:00.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-10T08:05:52.000Z", "max_issues_repo_path": "src/diffusion.f90", "max_issues_repo_name": "Parallel-in-Time/PararealF90", "max_issues_repo_head_hexsha": "a8318a79b92465a8a3cf775cc7fd096ff0494529", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-09-23T09:08:12.000Z", "max_issues_repo_issues_event_max_datetime": "2015-09-23T09:32:24.000Z", "max_forks_repo_path": "src/diffusion.f90", "max_forks_repo_name": "Parallel-in-Time/PararealF90", "max_forks_repo_head_hexsha": "a8318a79b92465a8a3cf775cc7fd096ff0494529", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-10-24T20:15:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-10T08:05:36.000Z", "avg_line_length": 38.5779816514, "max_line_length": 123, "alphanum_fraction": 0.4939357907, "num_tokens": 1180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133548753619, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.791243173923181}} {"text": "module stress_routines_lib\n\t! module containing various routines for computation of stresses and stress invariants\n\n\t! load additional modules\n\tuse iso_c_binding, only: dbl => c_double\n\tuse constants_lib, only: Pi\n\tuse math_routines_lib, only: calc_rot_matrix_zyz\n\n\timplicit none\n\n\n\t! definition and initialization of constant arrays\n\n\t! deviatoric operator\n\treal(kind=dbl), dimension(6,6), parameter :: I_dev = &\n\t\t\t reshape( (/ 2._dbl/3._dbl, -1._dbl/3._dbl, -1._dbl/3._dbl, 0._dbl, 0._dbl, 0._dbl, &\n\t\t\t\t\t\t-1._dbl/3._dbl, 2._dbl/3._dbl, -1._dbl/3._dbl, 0._dbl, 0._dbl, 0._dbl, &\n\t\t\t\t\t\t-1._dbl/3._dbl, -1._dbl/3._dbl, 2._dbl/3._dbl, 0._dbl, 0._dbl, 0._dbl, &\n\t\t\t\t\t\t0._dbl, 0._dbl, 0._dbl, 1._dbl, 0._dbl, 0._dbl, &\n\t\t\t\t\t\t0._dbl, 0._dbl, 0._dbl, 0._dbl, 1._dbl, 0._dbl, &\n\t\t\t\t\t\t0._dbl, 0._dbl, 0._dbl, 0._dbl, 0._dbl, 1._dbl /), (/ 6, 6 /) )\n\n\t! dsigma_m/dsigma\n\treal(kind=dbl), dimension(6), bind(c) :: Dsigma_mDsigma = (/ 1._dbl/3._dbl, 1._dbl/3._dbl, 1._dbl/3._dbl, &\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t 0._dbl, 0._dbl, 0._dbl /)\n\n\t! numerical zero\n\treal(kind=dbl), parameter :: num_zero = 1.0d-10\n\n\t! scaling vector for strain vector to convert engineering shear strain components\n\treal(kind=dbl), dimension(6), bind(c) :: eps_eng_scale = (/ 1._dbl, 1._dbl, 1._dbl, 0.5_dbl, 0.5_dbl, 0.5_dbl /)\n\n\ncontains\n\n\n\tfunction calc_I1(sigma) bind(c)\n\t\timplicit none\n\t\t! computes first invariant of stress tensor\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl) :: calc_I1\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of first invariant\n\t\tcalc_I1 = sum(sigma(1:3))\n\n\tend function calc_I1\n\n\n\n\n\tfunction calc_I2(sigma) bind(c)\n\t\timplicit none\n\t\t! computes second invariant of stress tensor\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl) :: calc_I2\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: s11\n\t\treal(kind=dbl) :: s22\n\t\treal(kind=dbl) :: s33\n\t\treal(kind=dbl) :: s12\n\t\treal(kind=dbl) :: s13\n\t\treal(kind=dbl) :: s23\n\t\t! --------------------------------------------------------------------------\n\n\t\t! unpacking of stress vector\n\t\ts11 = sigma(1)\n\t\ts22 = sigma(2)\n\t\ts33 = sigma(3)\n\t\ts12 = sigma(4)\n\t\ts13 = sigma(5)\n\t\ts23 = sigma(6)\n\n\t\t! compuation of second invariant\n\t\tcalc_I2 = s11*s22 + s22*s33 + s11*s33 - s12**2 - s13**2 - s23**2\n\n\tend function calc_I2\n\n\n\n\n\tfunction calc_I3(sigma) bind(c)\n\t\timplicit none\n\t\t! computes third invariant of stress tensor\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl) :: calc_I3\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: s11\n\t\treal(kind=dbl) :: s22\n\t\treal(kind=dbl) :: s33\n\t\treal(kind=dbl) :: s12\n\t\treal(kind=dbl) :: s13\n\t\treal(kind=dbl) :: s23\n\t\t! --------------------------------------------------------------------------\n\n\t\t! unpacking of stress vector\n\t\ts11 = sigma(1)\n\t\ts22 = sigma(2)\n\t\ts33 = sigma(3)\n\t\ts12 = sigma(4)\n\t\ts13 = sigma(5)\n\t\ts23 = sigma(6)\n\n\t\t! compuation of second invariant\n\t\tcalc_I3 = s11*s22*s33 + 2._dbl*s12*s23*s13 - s12**2*s33 - s23**2*s11 - s13**2*s22\n\n\tend function calc_I3\n\n\n\n\n\tfunction calc_s_mean(sigma) bind(c)\n\t\timplicit none\n\t\t! computes mean stress\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl) :: calc_s_mean\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of mean stress\n\t\tcalc_s_mean = 1._dbl/3._dbl * sum( sigma(1:3) )\n\n\tend function calc_s_mean\n\n\n\n\n\tsubroutine calc_s_dev(s_dev, sigma) bind(c)\n\t\timplicit none\n\t\t! computes deviatoric stress vector\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), intent(out), dimension(6) :: s_dev\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n\n\t\t! internal variable\n\t\treal(kind=dbl) :: s_mean\t\t\t\t\t\t\t\t! mean stress\n\t\t! --------------------------------------------------------------------------\n\n\t\t! compuation of s_mean\n\t\ts_mean = calc_s_mean(sigma)\n\n\t\t! computation of s_dev\n\t\ts_dev = sigma - (/ s_mean, s_mean, s_mean, 0._dbl, 0._dbl, 0._dbl /)\n\n\tend subroutine calc_s_dev\n\n\n\n\tfunction calc_J2(sigma) bind(c)\n\t\timplicit none\n\t\t! computes second invariant of deviatoric stress vector\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl) :: calc_J2\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation J2\n\t\tcalc_J2 = 1._dbl/3._dbl*calc_I1(sigma)**2 - calc_I2(sigma)\n\n\t\t! test if J2 < 0 (J2 must be positive)\n\t\tif (calc_J2 < 0._dbl) then\n\t\t\tcalc_J2 = 0._dbl\n\t\tend if\n\n\tend function calc_J2\n\n\n\n\n\tfunction calc_J3(sigma) bind(c)\n\t\timplicit none\n\t\t! computes third invariant of deviatoric stress vector\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl) :: calc_J3\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation J3\n\t\tcalc_J3 = 2._dbl/27._dbl*calc_I1(sigma)**3 - 1._dbl/3._dbl*calc_I1(sigma)*calc_I2(sigma) + calc_I3(sigma)\n\n\tend function calc_J3\n\n\n\n\tsubroutine calc_DI1Dsigma(DI1Dsigma, sigma) bind(c)\n\t\timplicit none\n\t ! computes the gradient of the first invariant of the stress vector with respect to sigma\n\t ! dI1/dsigma\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), intent(out), dimension(6) :: DI1Dsigma\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! dI1/dsigma\n\t\tDI1Dsigma = (/ 1._dbl, 1._dbl, 1._dbl, 0._dbl, 0._dbl, 0._dbl /)\n\n\tend subroutine calc_DI1Dsigma\n\n\n\n\tsubroutine calc_DI2Dsigma(DI2Dsigma, sigma) bind(c)\n\t\timplicit none\n\t ! computes the gradient of the second invariant of the stress vector with respect to sigma\n\t ! dI2/dsigma\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), intent(out), dimension(6) :: DI2Dsigma\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! dI2/dsigma\n\t\tDI2Dsigma = (/ sigma(2) + sigma(3), &\n\t\t\t\t\t\tsigma(1) + sigma(3), &\n\t\t\t\t\t\tsigma(2) + sigma(1), &\n\t\t\t\t\t\t-2._dbl*sigma(4), &\n\t\t\t\t\t\t-2._dbl*sigma(5), &\n\t\t\t\t\t\t-2._dbl*sigma(6) /)\n\n\tend subroutine calc_DI2Dsigma\n\n\n\n\tsubroutine calc_DI3Dsigma(DI3Dsigma, sigma) bind(c)\n\t\timplicit none\n\t ! computes the gradient of the third invariant of the stress vector with respect to sigma\n\t ! dI3/dsigma\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), dimension(6), intent(out) :: DI3Dsigma\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: s11\n\t\treal(kind=dbl) :: s22\n\t\treal(kind=dbl) :: s33\n\t\treal(kind=dbl) :: s12\n\t\treal(kind=dbl) :: s13\n\t\treal(kind=dbl) :: s23\n\t\t! --------------------------------------------------------------------------\n\n\t\t! unpacking of stress vector\n\t\ts11 = sigma(1)\n\t\ts22 = sigma(2)\n\t\ts33 = sigma(3)\n\t\ts12 = sigma(4)\n\t\ts13 = sigma(5)\n\t\ts23 = sigma(6)\n\n\t\t! dI3/dsigma\n\t\tDI3Dsigma = (/ s22*s33 - s23**2, &\n\t\t\t\t\t\ts11*s33 - s13**2, &\n\t\t\t\t\t\ts11*s22 - s12**2, &\n\t\t\t\t\t\t2._dbl*(s23*s13 - s12*s33), &\n\t\t\t\t\t\t2._dbl*(s12*s23 - s13*s22), &\n\t\t\t\t\t\t2._dbl*(s12*s13 - s23*s11) /)\n\n\tend subroutine calc_DI3Dsigma\n\n\n\n\tsubroutine calc_DJ2Dsigma(DJ2Dsigma, sigma) bind(c)\n\t\timplicit none\n\t ! computes the gradient of the second invariant of the deviatoric stress vector with respect to sigma\n\t ! dJ2/dsigma\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), dimension(6), intent(out) :: DJ2Dsigma\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: I1\n\t\treal(kind=dbl), dimension(6) :: DI1Dsigma\n\t\treal(kind=dbl), dimension(6) :: DI2Dsigma\n\t\t! --------------------------------------------------------------------------\n\n\t\t!return s_dev\n\t\t!calc_DJ2Dsigma = calc_s_dev(sigma)\n\n\t\tcall calc_DI1Dsigma(DI1Dsigma, sigma)\n\t\tcall calc_DI2Dsigma(DI2Dsigma, sigma)\n\n\t\tDJ2Dsigma = 2._dbl/3._dbl*calc_I1(sigma)*DI1Dsigma - DI2Dsigma\n\n\tend subroutine calc_DJ2Dsigma\n\n\n\n\tsubroutine calc_DJ3Dsigma(DJ3Dsigma, sigma) bind(c)\n\t\timplicit none\n\t ! computes the gradient if the third invariant of the deviatoric stress vector with respect to sigma\n\t ! dJ3/dsigma\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), dimension(6), intent(out) :: DJ3Dsigma\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: dJ3dI1\t\t! dJ3/dI1\n\t\treal(kind=dbl) :: dJ3dI2\t\t! dJ3/dI2\n\t\treal(kind=dbl) :: dJ3dI3\t\t! dJ3/dI3\n\t\treal(kind=dbl), dimension(6) :: DI1Dsigma\n\t\treal(kind=dbl), dimension(6) :: DI2Dsigma\n\t\treal(kind=dbl), dimension(6) :: DI3Dsigma\n\t\t! --------------------------------------------------------------------------\n\n\t\t! dJ3/dI1\n\t\tdJ3dI1 = 6._dbl/27._dbl*calc_I1(sigma)**2 - 1._dbl/3._dbl*calc_I2(sigma)\n\n\t\t! dJ3/dI2\n\t\tdJ3dI2 = -1._dbl/3._dbl*calc_I1(sigma)\n\n\t\t! dJ3/dI2\n\t\tdJ3dI3 = 1._dbl\n\n\t\tcall calc_DI1Dsigma(DI1Dsigma, sigma)\n\t\tcall calc_DI2Dsigma(DI2Dsigma, sigma)\n\t\tcall calc_DI3Dsigma(DI3Dsigma, sigma)\n\n\t ! dJ3/dsigma\n\t DJ3Dsigma = dJ3dI1*DI1Dsigma + dJ3dI2*DI2Dsigma + dJ3dI3*DI3Dsigma\n\n\tend subroutine calc_DJ3Dsigma\n\n\n\n\tfunction calc_rho(sigma) bind(c)\n\t\timplicit none\n\t\t! computes the Haigh Westergaard coordinate rho\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl) :: calc_rho\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: J2\t\t\t\t\t\t\t\t\t! second invariant of deviatoric stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of J2\n\t\tJ2 = calc_J2(sigma)\n\n\t\t! computation of rho\n\t\tcalc_rho = sqrt(2._dbl*J2)\n\n\tend function calc_rho\n\n\n\n\tfunction calc_theta(sigma) bind(c)\n\t\timplicit none\n\t\t! computes the Haigh Westergaard coordinate theta\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl) :: calc_theta\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: J2\t\t\t\t\t\t\t\t\t! second invariant of deviatoric stress vector\n\t\treal(kind=dbl) :: J3\t\t\t\t\t\t\t\t\t! third invariant of deviatoric stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of J2 and J3\n\t\tJ2 = calc_J2(sigma)\n\t\tJ3 = calc_J3(sigma)\n\n\t\t! computation of theta\n\t\t! test if both J2 and J3 are zero, or J2 is negative, i.e a stress state on the hydrostatic axis\n\t\tif ( (abs(J3) < epsilon(1._dbl) .and. sqrt(J2)**3 < epsilon(1._dbl) ) .or. &\n\n\t\t\t\t(J2 <= 0._dbl) ) then\n\n\t\t\t! set theta to zero\n\t\t\tcalc_theta = 0._dbl\n\n\t\telse if ( 3._dbl*sqrt(3._dbl)/2._dbl * J3/sqrt(J2)**3 > 1._dbl ) then\n\n\t\t\t! set theta to zero\n\t\t\tcalc_theta = 0._dbl\n\n\t\telse if ( 3._dbl*sqrt(3._dbl)/2._dbl * J3/sqrt(J2)**3 < -1._dbl ) then\n\n\t\t\tcalc_theta = Pi/3._dbl\n\n\t\telse\n\n\t\t\tcalc_theta = 1._dbl/3._dbl * acos( 3._dbl*sqrt(3._dbl)/2._dbl * J3/sqrt(J2)**3 )\n\n\t\tend if\n\n\tend function calc_theta\n\n\n\n\tsubroutine calc_DrhoDsigma(DrhoDsigma, sigma) bind(c)\n\t\timplicit none\n\t ! computes the gradient of the Haigh Weestergaard coordinate rho with respect to sigma ( drho/dsigma )\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), dimension(6), intent(out) :: DrhoDsigma\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: rho\n\t\treal(kind=dbl), dimension(6) :: DJ2Dsigma\n\t\t! --------------------------------------------------------------------------\n\n\t\t! compute rho\n\t\trho = calc_rho(sigma)\n\n\t\t! droh/dsigma\n\t\tif (rho < epsilon(rho)) then\t! numerically equivalent to zero\n\t\t\tDrhoDsigma = huge(rho)*1.0D-10\n\t\telse\n\t\t\tcall calc_DJ2Dsigma(DJ2Dsigma, sigma)\n\t\t DrhoDsigma = 1._dbl/rho * DJ2Dsigma\n\t\tend if\n\n\tend subroutine calc_DrhoDsigma\n\n\n\n\tsubroutine calc_DthetaDsigma(DthetaDsigma, sigma) bind(c)\n\t\timplicit none\n\t ! computes the gradient of the Haigh Weestergaard coordinate theta with respect to sigma ( dtheta/dsigma )\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), dimension(6), intent(out) :: DthetaDsigma\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: dtheta_dJ2\t\t\t\t! dtheta/dJ2\n\t\treal(kind=dbl) :: dtheta_dJ3\t\t\t\t! dtheta/dJ3\n\t\treal(kind=dbl), dimension(6) :: DJ2Dsigma\n\t\treal(kind=dbl), dimension(6) :: DJ3Dsigma\n\t\t! --------------------------------------------------------------------------\n\n\t\t! check if cos(3*theta) is outside the interval ]-1,1[\n\t\tif ( .not. (cos(3._dbl*calc_theta(sigma)) < 1._dbl) .or. &\n\t\t\t .not. (cos(3._dbl*calc_theta(sigma)) > -1._dbl) ) then\n\n\t\t\t! cos(3*theta) is on the borders of or outside the interval,\n\t\t\t! set dtheta/dJ2 and dtheta/dJ3 to zero\n\t\t\tdtheta_dJ2 = 0.0_dbl\n\t\t\tdtheta_dJ3 = 0.0_dbl\n\n\t\telse\n\n\t\t\t! dtheta/dJ2\n\t\t\tdtheta_dJ2 = sqrt(27._dbl)/4._dbl * calc_J3(sigma)/ &\n\t\t\t\t\t\t\t( sqrt(calc_J2(sigma))**5 * sqrt(1._dbl - cos(3._dbl*calc_theta(sigma))**2) )\n\n\t\t\t! dtheta/dJ3\n\t\t\tdtheta_dJ3 = -sqrt(3._dbl)/2._dbl * 1._dbl/ &\n\t\t\t\t\t\t\t( sqrt(calc_J2(sigma))**3 * sqrt(1._dbl - cos(3._dbl*calc_theta(sigma))**2) )\n\n\t\tend if\n\n\t\tcall calc_DJ2Dsigma(DJ2Dsigma, sigma)\n\t\tcall calc_DJ3Dsigma(DJ3Dsigma, sigma)\n\n\t ! DthetaDsigma\n\t DthetaDsigma = dtheta_dJ2*DJ2Dsigma + dtheta_dJ3*DJ3Dsigma\n\n\tend subroutine calc_DthetaDsigma\n\n\n\n\tsubroutine calc_C_elastic(C_elastic, E,nu) bind(c)\n\t\timplicit none\n\t\t! computes elasticity matrix according to the generalized hooke's law\n\t\t! sigma = C * epsilon\n\t ! see \"Concepts and Application of Finite Element Analysis\" p. 79, Cook R. et al, 2002, John Wiley & Sons\n\t ! engineering shear strains are assumed -> tau_xy = 2*epsilon_xy\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), dimension(6,6), intent(out) :: C_elastic\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in) :: E\t\t! elasticity module\n\t\treal(kind=dbl), intent(in) :: nu\t\t! poisson ratio\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: a\n\t\treal(kind=dbl) :: b\n\t\treal(kind=dbl) :: c\n\t\t! --------------------------------------------------------------------------\n\n\t\t! initialization of internal variables\n\t\ta = E*(1._dbl-nu)/( (1._dbl+nu)*(1._dbl-2._dbl*nu) )\n\t\tb = nu/(1._dbl-nu)\n\t\tc = (1._dbl-2._dbl*nu)/( 2._dbl*(1._dbl-nu) )\n\n\t\t! initialization of C_el with zeros\n\t\tC_elastic = 0._dbl\n\n\t\t! initialization of non zero components of C_el\n\t\tC_elastic(1,1) = a\n\t\tC_elastic(2,2) = a\n\t\tC_elastic(3,3) = a\n\t\tC_elastic(4,4) = a*c\n\t\tC_elastic(5,5) = a*c\n\t\tC_elastic(6,6) = a*c\n\t\tC_elastic(1,2) = a*b\n\t\tC_elastic(1,3) = a*b\n\t\tC_elastic(2,1) = a*b\n\t\tC_elastic(2,3) = a*b\n\t\tC_elastic(3,1) = a*b\n\t\tC_elastic(3,2) = a*b\n\n\tend subroutine calc_C_elastic\n\n\n\n\n\tsubroutine calc_inverse_C_elastic(inverse_C_elastic, E,nu) bind(c)\n\t\timplicit none\n\t ! computes inverse elasticity matrix C^(-1) according to the generalized hooke's law\n\t ! epsilon = C^(-1) * sigma\n\t ! see \"Festigkeitslehre\" p. 86; Mang H. and G. Hofstetter; 2004, SpringerWienNewYork\n\t ! engineering shear strains are assumed -> tau_xy = 2*epsilon_xy\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), dimension(6,6), intent(out) :: inverse_C_elastic\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in) :: E\t\t! elasticity module\n\t\treal(kind=dbl), intent(in) :: nu\t\t! poisson ratio\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: c\n\t\treal(kind=dbl) :: G\n\t\t! --------------------------------------------------------------------------\n\n\t\t! initialization of internal variables\n\t\tc = -nu/E\n\t\tG = E/( 2._dbl*(1._dbl+nu) )\n\n\t\t! initialization of C_el with zeros\n\t\tinverse_C_elastic = 0._dbl\n\n\t\t! initialization of non zero components of C_el\n\t\tinverse_C_elastic(1,1) = 1._dbl/E\n\t\tinverse_C_elastic(2,2) = 1._dbl/E\n\t\tinverse_C_elastic(3,3) = 1._dbl/E\n\t\tinverse_C_elastic(4,4) = 1._dbl/G\n\t\tinverse_C_elastic(5,5) = 1._dbl/G\n\t\tinverse_C_elastic(6,6) = 1._dbl/G\n\t\tinverse_C_elastic(1,2) = c\n\t\tinverse_C_elastic(1,3) = c\n\t\tinverse_C_elastic(2,1) = c\n\t\tinverse_C_elastic(2,3) = c\n\t\tinverse_C_elastic(3,1) = c\n\t\tinverse_C_elastic(3,2) = c\n\n\tend subroutine calc_inverse_C_elastic\n\n\n! CORRECTED TRANSVERSE ISOTROPIC ELASTICITY MATRIX, ERROR IN WITTKE'S BOOK !!!!!!\n\tsubroutine calc_transv_istr_C_elastic(transv_istr_C_elastic, E1, E2, G2, nu1, nu2) bind(c)\n\t\t! computes transverse isotropic elasticity matrix,\n\t\t! defined according to 'Rock Mechanics Based on an Anisotropic Jointed Rock Model' by Walter Wittke, p. 42 ff\n\t\t! C_el(1,2) = C_el(2,1) is wrong in the book, here the corrected expressions are implemented\n\t\t! C_el(3,3) is wrong in the book, here the corrected expressions are implemented\n\t\t! sigma = C_el * epsilon\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in) :: E1\t\t! elasticity constant parallel to the structure (isotropic) plane\n\t\treal(kind=dbl), intent(in) :: E2\t\t! elasticity constant perpendicular to the structure (isotropic) plane\n\t\treal(kind=dbl), intent(in) :: G2\t\t! shear modulus for shear loading in/parallel to the structure (isotropic) plane\n\t\treal(kind=dbl), intent(in) :: nu1\t\t! poisson ration perpendicular to the structure (isotropic) plane\n\t\treal(kind=dbl), intent(in) :: nu2\t\t! poisson ration in the structure (isotropic) plane\n\n\t\t! return variable\n\t\treal(kind=dbl), dimension(6,6), intent(out) :: transv_istr_C_elastic\t\t! return variable\n!f2py\tintent(out) :: calc_transv_istr_C_elastic\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: n\t\t! auxiliary variable\n\t\treal(kind=dbl) :: m\t\t! auxiliary variable\n\t\t! --------------------------------------------------------------------------\n\n\t\t! initialize auxiliary variables\n\t\tn = E1/E2\n\t\tm = 1._dbl-nu1-2._dbl*n*nu2**2\n\n\t\t! initialize elasticity matrix with zeros\n\t\ttransv_istr_C_elastic = 0._dbl\n\n\t\t! compute nonzero components of elasticity matrix\n\t\ttransv_istr_C_elastic(1,1) = E1*(1._dbl-n*nu2**2)/((1._dbl+nu1)*m)\n\t\ttransv_istr_C_elastic(1,2) = E1*(nu1+n*nu2**2)/((1._dbl+nu1)*m)\t\t! E1*(1._dbl+n*nu2**2)/((1._dbl+nu1)*m) in Wittke's book which is wrong\n\t\ttransv_istr_C_elastic(2,1) = E1*(nu1+n*nu2**2)/((1._dbl+nu1)*m)\t\t! E1*(1._dbl+n*nu2**2)/((1._dbl+nu1)*m) in Wittke's book which is wrong\n\t\ttransv_istr_C_elastic(2,2) = E1*(1._dbl-n*nu2**2)/((1._dbl+nu1)*m)\n\t\ttransv_istr_C_elastic(1:2,3) = E1*nu2/m\n\t\ttransv_istr_C_elastic(3,1:2) = E1*nu2/m\n\t\ttransv_istr_C_elastic(3,3) = E2*(1._dbl-nu1)/m\t\t\t\t\t\t\t! E1*(1._dbl-nu1)/m in Wittke's book which is wrong\n\t\ttransv_istr_C_elastic(4,4) = E1/(2._dbl*(1._dbl+nu1))\n\t\ttransv_istr_C_elastic(5,5) = G2\n\t\ttransv_istr_C_elastic(6,6) = G2\n\n\tend subroutine calc_transv_istr_C_elastic\n\n\n\n\tsubroutine calc_inv_transv_istr_C_elastic(inv_transv_istr_C_elastic, E1, E2, G2, nu1, nu2) bind(c)\n\t\t! computes transverse isotropic elasticity matrix,\n\t\t! defined according to 'Rock Mechanics Based on an Anisotropic Jointed Rock Model' by Walter Wittke, p. 42 ff\n\t\t! epsilon = C_el^(⁻1) * sigma\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in) :: E1\t\t! elasticity constant parallel to the structure (isotropic) plane\n\t\treal(kind=dbl), intent(in) :: E2\t\t! elasticity constant perpendicular to the structure (isotropic) plane\n\t\treal(kind=dbl), intent(in) :: G2\t\t! shear modulus for shear loading in/parallel to the structure (isotropic) plane\n\t\treal(kind=dbl), intent(in) :: nu1\t\t! poisson ration perpendicular to the structure (isotropic) plane\n\t\treal(kind=dbl), intent(in) :: nu2\t\t! poisson ration in the structure (isotropic) plane\n\n\t\t! return variable\n\t\treal(kind=dbl), dimension(6,6), intent(out) :: inv_transv_istr_C_elastic\t\t! return variable\n\n\t\t! internal variables\n\t\t! --------------------------------------------------------------------------\n\n\t\t! initialize elasticity matrix with zeros\n\t\tinv_transv_istr_C_elastic = 0._dbl\n\n\t\t! compute nonzero components of elasticity matrix\n\t\tinv_transv_istr_C_elastic(1,1) = 1._dbl/E1\n\t\tinv_transv_istr_C_elastic(1,2) = -nu1/E1\n\t\tinv_transv_istr_C_elastic(2,1) = -nu1/E1\n\t\tinv_transv_istr_C_elastic(2,2) = 1._dbl/E1\n\t\tinv_transv_istr_C_elastic(1:2,3) = -nu2/E2\n\t\tinv_transv_istr_C_elastic(3,1:2) = -nu2/E2\n\t\tinv_transv_istr_C_elastic(3,3) = 1._dbl/E2\n\t\tinv_transv_istr_C_elastic(4,4) = 2._dbl*(1._dbl+nu1)/E1\n\t\tinv_transv_istr_C_elastic(5,5) = 1._dbl/G2\n\t\tinv_transv_istr_C_elastic(6,6) = 1._dbl/G2\n\n\tend subroutine calc_inv_transv_istr_C_elastic\n\n\n\n\tsubroutine calc_sig_princ_hw(sig_princ_hw, s_mean, rho, theta) bind(c)\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! return variable\n\t\treal(kind=dbl), dimension(3), intent(out) :: sig_princ_hw\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in) :: s_mean\n\t\treal(kind=dbl), intent(in) :: rho\n\t\treal(kind=dbl), intent(in) :: theta\n\n\t\t! internal variables\n\t\treal(kind=dbl), dimension(3) :: s_mean_vec\n\t\treal(kind=dbl), dimension(3) :: theta_vec\n\t\t! --------------------------------------------------------------------------\n\n\t\ts_mean_vec = (/ s_mean, s_mean, s_mean /)\n\n\t\ttheta_vec = (/ cos(theta), -sin(Pi/6._dbl-theta), -sin(Pi/6._dbl+theta) /)\n\n\t\tsig_princ_hw = s_mean_vec + sqrt(2._dbl/3._dbl)*rho*theta_vec\n\n\tend subroutine calc_sig_princ_hw\n\n\n\n\tsubroutine calc_sig_princ_hw_sig(sig_princ_hw_sig, sigma) bind(c)\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! return variable\n\t\treal(kind=dbl), dimension(3), intent(out) :: sig_princ_hw_sig\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: s_mean\n\t\treal(kind=dbl) :: rho\n\t\treal(kind=dbl) :: theta\n\t\treal(kind=dbl), dimension(3) :: s_mean_vec\n\t\treal(kind=dbl), dimension(3) :: theta_vec\n\t\t! --------------------------------------------------------------------------\n\n\t\t! test if shear stress components are zero\n\t\tif ( (abs(sigma(4)) < epsilon(1._dbl)) .and. &\n\t\t\t\t(abs(sigma(5)) < epsilon(1._dbl)) .and. &\n\t\t\t\t(abs(sigma(6)) < epsilon(1._dbl)) ) then\n\n\t\t\t! shear stresses are zero and therefore\n\t\t\t! the components of sigma already resemble\n\t\t\t! the principal stresses\n\t\t\tsig_princ_hw_sig = sort_sig_princ(sigma(1:3))\n\t\t\treturn\n\n\t\tend if\n\n\t\ts_mean = calc_s_mean(sigma)\n\t\trho = calc_rho(sigma)\n\t\ttheta = calc_theta(sigma)\n\n\t\ts_mean_vec = (/ s_mean, s_mean, s_mean /)\n\n\t\ttheta_vec = (/ cos(theta), -sin(Pi/6._dbl-theta), -sin(Pi/6._dbl+theta) /)\n\n\t\tsig_princ_hw_sig = s_mean_vec + sqrt(2._dbl/3._dbl)*rho*theta_vec\n\n\tend subroutine calc_sig_princ_hw_sig\n\n\n\n\tsubroutine calc_Dsigma_princDsigma(Dsigma_princDsigma, sigma) bind(c)\n\t\t! computes derivatives of principal stress vector\n\t\t! with respect to the stress vector via HW-coordinates\n\t\t! dsigma_princ/dsigma\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! return variable\n\t\treal(kind=dbl), dimension(3,6), intent(out) :: Dsigma_princDsigma\t! dsigma_princ/dsigma\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: s_mean\t\t\t\t\t\t\t\t\t! HW-coordinate\n\t\treal(kind=dbl) :: rho\t\t\t\t\t\t\t\t\t\t! HW-coordinate\n\t\treal(kind=dbl) :: theta\t\t\t\t\t\t\t\t\t\t! HW-coordinate\n\t\treal(kind=dbl), dimension(3,1) :: Dsig_princDs_mean\t\t\t! dsigma_princ/ds_mean initialized as rank 2 variable (matrix with 1 column),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! so that it can be transposed and used in matrix multiplications\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! (not possible with rank 1 arrays, i.e. vectors)\n\n\t\treal(kind=dbl), dimension(3,1) :: Dsig_princDrho\t\t\t! dsigma_princ/drho initialized as rank 2 variable (matrix with 1 column),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! so that it can be transposed and used in matrix multiplications\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! (not possible with rank 1 arrays, i.e. vectors)\n\n\t\treal(kind=dbl), dimension(3,1) :: Dsig_princDtheta\t\t\t! dsigma_princ/dtheta initialized as rank 2 variable (matrix with 1 column),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! so that it can be transposed and used in matrix multiplications\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! (not possible with rank 1 arrays, i.e. vectors)\n\n\t\treal(kind=dbl), dimension(6,1) :: Ds_meanDsig\t\t\t\t! ds_mean/dsigma initialized as rank 2 variable (matrix with 1 column),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! so that it can be transposed and used in matrix multiplications\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! (not possible with rank 1 arrays, i.e. vectors)\n\n\t\treal(kind=dbl), dimension(6,1) :: DrhoDsig\t\t\t\t\t! drho/dsigma initialized as rank 2 variable (matrix with 1 column),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! so that it can be transposed and used in matrix multiplications\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! (not possible with rank 1 arrays, i.e. vectors)\n\n\t\treal(kind=dbl), dimension(6,1) :: dthetaDsig\t\t\t\t! dtheta/dsigma initialized as rank 2 variable (matrix with 1 column),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! so that it can be transposed and used in matrix multiplications\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! (not possible with rank 1 arrays, i.e. vectors)\n\t\treal(kind=dbl), dimension(6) :: DrhoDsig_vec\n\t\treal(kind=dbl), dimension(6) :: DthetaDsig_vec\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of HW-coordinates\n\t\ts_mean = calc_s_mean(sigma)\n\t\trho = calc_rho(sigma)\n\t\ttheta = calc_theta(sigma)\n\n\t\t! computation of dsigma_princ/ds_mean\n\t\tDsig_princDs_mean = reshape( (/ 1._dbl, 1._dbl, 1._dbl /), (/3,1/) )\n\n\t\t! computation of dsigma_princ/drho\n\t\tDsig_princDrho = sqrt(2._dbl/3._dbl) * &\n\t\t\t\t\t\t\treshape( (/ cos(theta), -sin(Pi/6._dbl-theta), -sin(Pi/6._dbl+theta) /), &\n\t\t\t\t\t\t\t\t\t(/3,1/) )\n\n\t\t! computation of dsigma_princ/dtheta\n\t\tDsig_princDtheta = sqrt(2._dbl/3._dbl) * rho * &\n\t\t\t\t\t\t\treshape( (/ -sin(theta), cos(Pi/6._dbl-theta), -cos(Pi/6._dbl+theta) /), &\n\t\t\t\t\t\t\t\t\t(/3,1/) )\n\n\t\t! computation of ds_mean/dsigma and assignment to\n\t\t! rank 2 (matrix) variable Ds_meanDsig\n\t\tDs_meanDsig = reshape( Dsigma_mDsigma, (/6,1/) )\n\n\t\t! computation of drho/dsigma and assignment to\n\t\t! rank 2 (matrix) variable DrhoDsig\n\t\tcall calc_DrhoDsigma(DrhoDsig_vec, sigma)\n\t\tDrhoDsig = reshape( DrhoDsig_vec, (/6,1/) )\n\n\t\t! computation of dtheta/dsigma and assignment to\n\t\t! rank 2 (matrix) variable DthetaDsig\n\t\tcall calc_DthetaDsigma(DthetaDsig_vec, sigma)\n\t\tDthetaDsig = reshape( DthetaDsig_vec, (/6,1/) )\n\n\t\t! computation of dsigma_princ/dsigma with chain rule\n\t\t! dsigma_princ/dsigma = (dsigma_princ/ds_mean * ds_mean/dsigma) +\n\t\t! \t\t\t\t\t\t+ (dsigma_princ/drho * drho/dsigma) +\n\t\t! \t\t\t\t\t\t+ (dsigma_princ/dtheta * dtheta/dsigma)\n\t\tDsigma_princDsigma = matmul( Dsig_princDs_mean, transpose(Ds_meanDsig) ) + &\n\t\t\t\t\t\t\t\t\tmatmul( Dsig_princDrho, transpose(DrhoDsig) ) + &\n\t\t\t\t\t\t\t\t\tmatmul( Dsig_princDtheta, transpose(DthetaDsig) )\n\n\tend subroutine calc_Dsigma_princDsigma\n\n\n\n\tfunction sort_sig_princ(sig_princ)\n\t\t! sorts the entries of the principal stress vector,\n\t\t! depending on their size in descending order\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! return variable\n\t\treal(kind=dbl), dimension(3) :: sort_sig_princ\n\n\t\t! input variable\n\t\treal(kind=dbl), intent(in), dimension(3) :: sig_princ\n\n\t\t! internal variables\n\t\tinteger, dimension(1) :: ind_max\t! index of maximum sigma component\n\t\tinteger, dimension(1) :: ind_min\t! index of minimum sigma component\n\t\tinteger, dimension(1) :: ind_mid\t! index of intermediate sigma component\n\t\t! --------------------------------------------------------------------------\n\n\t\t! find index of maximum value\n\t\tind_max = maxloc(sig_princ)\n\t\t! find index of minimum value\n\t\tind_min = minloc(sig_princ)\n\n\t\tif (ind_max(1) == ind_min(1)) then\n\t\t\t! all components have the same size\n\t\t\t! return principal stress vector in unchanged order\n\t\t\tsort_sig_princ = sig_princ\n\t\t\treturn\n\t\telse\n\t\t\t! find index of intermediate value\n\t\t\tind_mid = 6 - ind_max - ind_min\n\n\t\t\t! assign maximum value to first entry of array\n\t\t\tsort_sig_princ(1) = sig_princ(ind_max(1))\n\t\t\t! assign intermediate value to second entry of array\n\t\t\tsort_sig_princ(2) = sig_princ(ind_mid(1))\n\t\t\t! assign minimum value to third(last) entry of array\n\t\t\tsort_sig_princ(3) = sig_princ(ind_min(1))\n\t\tend if\n\n\tend function sort_sig_princ\n\n\n\n\tsubroutine calc_rot_matrix_epsilon(rot_matrix_epsilon, alpha, beta, gam) bind(c)\n\t\t! computes rotation matrix for coordinate transformation of the strain vector,\n\t\t! with shear strains in engineering notation\n\t\t! according to 'Concepts and Applications of Finite Element Analysis' by Robert D. Cook et al, p. 274, ff\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in) :: alpha\t\t! rotation around z axis\n\t\treal(kind=dbl), intent(in) :: beta\t\t! rotation around rotated y axis\n\t\treal(kind=dbl), intent(in) :: gam\t\t! rotation around rotated z axis, in case if transverse isotropy zero\n\n\t\t! output variable\n\t\treal(kind=dbl), dimension(6,6), intent(out) :: rot_matrix_epsilon\t! output rotation matrix\n\n\t\t! internal variables\n\t\treal(kind=dbl), dimension(3,3) :: T\t\t\t\t\t\t! rotation matrix with direction cosines of angles between original and rotated coordinate axes\n\t\treal(kind=dbl) :: lx, mx, nx\t\t\t\t\t\t\t! components of rotated x-base vector (first line of T)\n\t\treal(kind=dbl) :: ly, my, ny\t\t\t\t\t\t\t! components of rotated y-base vector (second line of T)\n\t\treal(kind=dbl) :: lz, mz, nz\t\t\t\t\t\t\t! components of rotated z-base vector (third line of T)\n\t\treal(kind=dbl), dimension(3,3) :: T11, T12, T21, T22\t! submatrices of rotation matrix\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of rotation matrix out of the three euler rotation angle defined by zyz convention\n\t\tcall calc_rot_matrix_zyz(T, alpha, beta, gam)\n\n\t\t! assign values of T to components\n\t\tlx = T(1,1)\n\t\tmx = T(1,2)\n\t\tnx = T(1,3)\n\t\tly = T(2,1)\n\t\tmy = T(2,2)\n\t\tny = T(2,3)\n\t\tlz = T(3,1)\n\t\tmz = T(3,2)\n\t\tnz = T(3,3)\n\n\t\t! fill submatrices\n\t\tT11 = T**2\n\t\tT12(:,1) = T(:,1)*T(:,2)\n\t\tT12(:,2) = T(:,1)*T(:,3)\n\t\tT12(:,3) = T(:,2)*T(:,3)\n\t\tT21(1,:) = 2._dbl*T(1,:)*T(2,:)\n\t\tT21(2,:) = 2._dbl*T(1,:)*T(3,:)\n\t\tT21(3,:) = 2._dbl*T(2,:)*T(3,:)\n\t\tT22 = reshape((/ (lx*my+mx*ly), (lx*mz+mx*lz), (ly*mz+my*lz), &\n\t\t\t\t\t\t\t(lx*ny+nx*ly), (lx*nz+nx*lz), (ly*nz+ny*lz), &\n\t\t\t\t\t\t\t(mx*ny+nx*my), (mx*nz+nx*mz), (my*nz+ny*mz) /), (/3,3/))\n\n\t\t! fill rotation matrix with submatrices\n\t\trot_matrix_epsilon(1:3,1:3) = T11\n\t\trot_matrix_epsilon(1:3,4:6) = T12\n\t\trot_matrix_epsilon(4:6,1:3) = T21\n\t\trot_matrix_epsilon(4:6,4:6) = T22\n\n\tend subroutine calc_rot_matrix_epsilon\n\n\n\n\tsubroutine calc_rot_matrix_sigma(rot_matrix_sigma, alpha, beta, gam) bind(c)\n\t\t! computes rotation matrix for coordinate transformation of the stress vector,\n\t\t! according to 'Concepts and Applications of Finite Element Analysis' by Robert D. Cook et al, p. 274, ff\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in) :: alpha\t\t! rotation around z axis\n\t\treal(kind=dbl), intent(in) :: beta\t\t! rotation around rotated y axis\n\t\treal(kind=dbl), intent(in) :: gam\t\t! rotation around rotated z axis, in case if transverse isotropy zero\n\n\t\t!output variable\n\t\treal(kind=dbl), dimension(6,6), intent(out) :: rot_matrix_sigma\t\t! output stress rotation matrix\n\n\t\t! internal variables\n\t\treal(kind=dbl), dimension(6,6) :: T_epsilon\t\t! rotation matrix for strain vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! compute rotation matrix for strain vector\n\t\tcall calc_rot_matrix_epsilon(T_epsilon, alpha, beta, gam)\n\n\t\t! change submatrices of T_epsilon and assign them to output stress rotation matrix\n\t\trot_matrix_sigma(1:3,1:3) = T_epsilon(1:3,1:3)\n\t\trot_matrix_sigma(1:3,4:6) = 2._dbl*T_epsilon(1:3,4:6)\n\t\trot_matrix_sigma(4:6,1:3) = 0.5_dbl*T_epsilon(4:6,1:3)\n\t\trot_matrix_sigma(4:6,4:6) = T_epsilon(4:6,4:6)\n\n\tend subroutine calc_rot_matrix_sigma\n\n\n\n\tsubroutine rotate_sigma(sigma_rotated, sigma, alpha, beta, gam) bind(c)\n\t\t! computes and returns rotated stress vector\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! input variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n\t\treal(kind=dbl), intent(in) :: alpha\t\t\t\t\t\t! first euler rotation angle, around z-axis, eastwards positive (zyz convention)\n\t\treal(kind=dbl), intent(in) :: beta\t\t\t\t\t\t! second euler rotation angle, around rotated y-axis, downwards positive (zyz convention)\n\t\treal(kind=dbl), intent(in) :: gam\t\t\t\t\t\t! third euler rotation angle, around rotated z-axis, eastwards positive (zyz convention)\n\n\t\t! return variable\n\t\treal(kind=dbl), dimension(6), intent(out) :: sigma_rotated\t\t\t! rotated stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl), dimension(6,6) :: T_sig\t\t\t\t\t! rotation matrix for rotation of stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of stress rotation matrix with the three euler rotation angle defined by zyz convention\n\t\tcall calc_rot_matrix_sigma(T_sig, alpha, beta, gam)\n\n\t\t! compute rotated stress vector\n\t\tsigma_rotated = matmul(T_sig, sigma)\n\n\tend subroutine rotate_sigma\n\n\n\n\tsubroutine rotate_epsilon(epsilon_rotated, eps, alpha, beta, gam) bind(c)\n\t\t! computes and returns rotated strain vector\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! input variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: eps\t\t\t! strain vector\n\t\treal(kind=dbl), intent(in) :: alpha\t\t\t\t\t\t! first euler rotation angle, around z-axis, eastwards positive (zyz convention)\n\t\treal(kind=dbl), intent(in) :: beta\t\t\t\t\t\t! second euler rotation angle, around rotated y-axis, downwards positive (zyz convention)\n\t\treal(kind=dbl), intent(in) :: gam\t\t\t\t\t\t! third euler rotation angle, around rotated z-axis, eastwards positive (zyz convention)\n\n\t\t! return variable\n\t\treal(kind=dbl), dimension(6), intent(out) :: epsilon_rotated\t\t\t! rotated strain vector\n\n\t\t! internal variables\n\t\treal(kind=dbl), dimension(6,6) :: T_eps\t\t\t\t\t! rotation matrix for rotation of strain vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of strain rotation matrix with the three euler rotation angle defined by zyz convention\n\t\tcall calc_rot_matrix_epsilon(T_eps, alpha, beta, gam)\n\n\t\t! compute rotated stress vector\n\t\tepsilon_rotated = matmul(T_eps, eps)\n\n\tend subroutine rotate_epsilon\n\n\n\n\tsubroutine rotate_material_matrix(C_rot, C, alpha, beta, gam) bind(c)\n\t\t! computes and returns rotated material tensor/matrix (C_elastic or C_elastoplastic),\n\t\t! according to: 'Rock Mechanics Based on an Anisotropic Jointed Rock Model' by Walter Wittke, p. 45 ff\n\t\t!\t\t\t\t'Concepts and Applications of Finite Element Analysis' by Robert D. Cook et al, p. 275, ff\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! input variables\n\t\treal(kind=dbl), intent(in), dimension(6,6) :: C\t\t\t! material matrix\n\t\treal(kind=dbl), intent(in) :: alpha\t\t\t\t\t\t! first euler rotation angle, around z-axis, eastwards positive (zyz convention)\n\t\treal(kind=dbl), intent(in) :: beta\t\t\t\t\t\t! second euler rotation angle, around rotated y-axis, downwards positive (zyz convention)\n\t\treal(kind=dbl), intent(in) :: gam\t\t\t\t\t\t! third euler rotation angle, around rotated z-axis, eastwards positive (zyz convention)\n\n\t\t! return variable\n\t\treal(kind=dbl), dimension(6,6), intent(out) :: C_rot\t\t\t! rotated material matrix\n!f2py\tintent(out) :: rotate_material_matrix\n\n\t\t! internal variables\n\t\treal(kind=dbl), dimension(6,6) :: T_eps\t\t\t\t\t! strain rotation matrix for rotation of material matrix\n\t\treal(kind=dbl), dimension(6,6) :: T_sigma\t\t\t\t! stress rotation matrix for rotation of material matrix\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of strain rotation matrix\n\t\tcall calc_rot_matrix_epsilon(T_eps, -alpha, -beta, -gam)\n\n\t\t! computation of stress rotation matrix\n\t\tcall calc_rot_matrix_sigma(T_sigma, alpha, beta, gam)\n\n\t\t! compute rotated material matrix\n\t\tC_rot = matmul(T_sigma, matmul(C,T_eps))\n\n\tend subroutine rotate_material_matrix\n\n\n\n\tsubroutine rotate_inv_material_matrix(C_inv_rot, C_inv, alpha, beta, gam) bind(c)\n\t\t! computes and returns rotated material tensor/matrix (inverse C_elastic or inverse C_elastoplastic),\n\t\t! according to: 'Rock Mechanics Based on an Anisotropic Jointed Rock Model' by Walter Wittke, p. 45 ff\n\t\t!\t\t\t\t'Concepts and Applications of Finite Element Analysis' by Robert D. Cook et al, p. 275, ff\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! input variables\n\t\treal(kind=dbl), intent(in), dimension(6,6) :: C_inv\t\t\t! material matrix\n\t\treal(kind=dbl), intent(in) :: alpha\t\t\t\t\t\t! first euler rotation angle, around z-axis, eastwards positive (zyz convention)\n\t\treal(kind=dbl), intent(in) :: beta\t\t\t\t\t\t! second euler rotation angle, around rotated y-axis, downwards positive (zyz convention)\n\t\treal(kind=dbl), intent(in) :: gam\t\t\t\t\t\t! third euler rotation angle, around rotated z-axis, eastwards positive (zyz convention)\n\n\t\t! return variable\n\t\treal(kind=dbl), dimension(6,6), intent(out) :: C_inv_rot\t\t\t! rotated inverse material matrix\n\n\t\t! internal variables\n\t\treal(kind=dbl), dimension(6,6) :: T_sig\t\t\t\t\t! rotation matrix for rotation of inverse material matrix\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of rotation matrix\n\t\tcall calc_rot_matrix_sigma(T_sig, alpha, beta, gam)\n\n\t\t! compute rotated inverse material matrix\n\t\tC_inv_rot = matmul(transpose(T_sig), matmul(C_inv,T_sig))\n\n\tend subroutine rotate_inv_material_matrix\n\n\n\n!\tfunction calc_gen_l_vec(sigma)\n!\t\t! computes the normed generalized loading vector l\n!\t\t! according to \"On failure criteria for anisotropic cohesive-frictional materials\" by S. Pietruszczak and Z. Mroz, 2000\n!\t\timplicit none\n!\n!\t\t! --------------------------------------------------------------------------\n!\t\t! input variables\n!\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t\t! stress vector\n!\n!\t\t! return variable\n!\t\treal(kind=dbl), dimension(3) :: calc_gen_l_vec\t\t! generalized loading vector\n!!f2py\tintent(out) :: calc_gen_loading_vec\n!\n!\t\t! internal variables\n!\t\treal(kind=dbl), dimension(3) :: L\t\t! loading vector\n!\t\t! --------------------------------------------------------------------------\n!\n!\t\t! compute L\n!!\t\tL(1) = sqrt(sigma(1)**2+sigma(4)**2+sigma(5)**2)\t\t! s11, s12, s13\n!!\t\tL(2) = sqrt(sigma(2)**2+sigma(4)**2+sigma(6)**2)\t\t! s22, s12, s23\n!!\t\tL(3) = sqrt(sigma(3)**2+sigma(5)**2+sigma(6)**2)\t\t! s33, s13, s23\n!\t\tif (.not. all(sigma .eq. 0._dbl)) then\n!\t\t\tL = calc_gen_l_vec_unnormed(sigma)\t\t\t! not all stress components are zero, proceed to compute L\n!\n!\t\t\t! compute generalized loading vector\n!\t\t\tcalc_gen_l_vec = 1._dbl/norm2(L) * L\n!\t\telse\n!\n!\t\t\tcalc_gen_l_vec = 0._dbl\t\t! all stress components are zero, set l to zero and return\n!\n!\t\tend if\n!\n!\tend function calc_gen_l_vec\n!\n!\n!\n!\tfunction calc_gen_l_vec_unnormed(sigma)\n!\t ! computes unnormed generalized loading vector L\n!\t implicit none\n!\n!\t ! --------------------------------------------------------------------------\n!\t ! passed variables\n!\t\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n!\n!\t ! return variable\n!\t real(kind=dbl), dimension(3) :: calc_gen_l_vec_unnormed\t! L\n!! f2py\t\tintent(out) :: calc_gen_loading_vec_unnormed\n!\n!\t ! internal variables\n!\t ! --------------------------------------------------------------------------\n!\n!\t\t! compute L\n!\t\tcalc_gen_l_vec_unnormed(1) = sqrt(sigma(1)**2+sigma(4)**2+sigma(5)**2)\t\t! s11, s12, s13\n!\t\tcalc_gen_l_vec_unnormed(2) = sqrt(sigma(2)**2+sigma(4)**2+sigma(6)**2)\t\t! s22, s12, s23\n!\t\tcalc_gen_l_vec_unnormed(3) = sqrt(sigma(3)**2+sigma(5)**2+sigma(6)**2)\t\t! s33, s13, s23\n!\n!\t end function calc_gen_l_vec_unnormed\n\nend module stress_routines_lib\n", "meta": {"hexsha": "3342d9544da77336b62e6b0e492fbdf42bcdda2b", "size": 41555, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "libraries/stress_routines_lib.f90", "max_stars_repo_name": "yuyong1990/TsaiWu-Fortran", "max_stars_repo_head_hexsha": "a111ca1717adfbbaf3e9e34f4189a441e16441b8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2017-11-19T15:12:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T15:34:59.000Z", "max_issues_repo_path": "libraries/stress_routines_lib.f90", "max_issues_repo_name": "OVGULIU/TsaiWu-Fortran", "max_issues_repo_head_hexsha": "a111ca1717adfbbaf3e9e34f4189a441e16441b8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "libraries/stress_routines_lib.f90", "max_forks_repo_name": "OVGULIU/TsaiWu-Fortran", "max_forks_repo_head_hexsha": "a111ca1717adfbbaf3e9e34f4189a441e16441b8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2017-02-11T12:56:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-01T11:29:18.000Z", "avg_line_length": 35.1565143824, "max_line_length": 138, "alphanum_fraction": 0.6069305739, "num_tokens": 12348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939913354875362, "lm_q2_score": 0.8418256393148982, "lm_q1q2_score": 0.7912431608685624}} {"text": "c ===============================\nc\nc Tensor Library for ME725\nc \nc P.Sathananthan\nc\nc ===============================\nc\nc Subroutines implemented to date\nc\nc tpose (A,B) -> Aij = Bji (implemented & verified)\nc det (A,x) -> det(Aij) = x (implemented & verified)\nc scale2 (A,B,m) -> Bij = m.*Aij (implemented & verified)\nc scale4 (A,B,m) -> Bijkl = m.*Aijkl (implemented)\nc invert (A,B) -> B = inv (A) (implemented & verified)\nc tc_2s2 (A,B,C) -> Cij = Aik*Bkj (implemented)\nc tc_2d2 (A,B,c) -> c = Aij*Bji (implemented)\nc tc_4d4 (A4,B4,C4) -> Cijkl = Aijmn*Bmnkl (implemented)\nc tc_4d2 (A4,B,C) -> Cij = Aijkl*Bkl (implemented)\nc tc_2d4 (A,B4,C) -> Cij = Akl*Bklij (implemented)\nc transform2 -> B = QAQt (implemented)\nc qzrad -> rot tensor about z (implemented)\nc qxrad -> rot tensor about x (implemented)\nc qyrad -> rot tensor about y (implemented)\nc tp_2dy2 -> Cijkl = AijXBkl\nc\nc -------------------------------\nc\nc 2nd order tensor indexing (aij)\nc\nc a11 a12 a13 (1) (2) (3) \nc a21 a22 a23 (4) (5) (6)\nc a31 a32 a33 (7) (8) (9)\nc\nc index (i,j) = 3*(i-1)+j \nc\nc -------------------------------\nc\nc 4th order tensor indexing (aijkl)\nc\nc a1111 a1112 ... a1132 a1133 (1,1) (1,2) ... (1,8) (1,9)\nc . . . .\nc . . . .\nc . . . .\nc a3311 a3312 ... a3332 a3333 (9,1) (9,2) ... (9,8) (9,9)\nc \nc\nc index1 (i,j) = 3*(i-1)+j\nc index2 (k,l) = 3*(k-1)+l\nc \nc ===============================\nc\nc transpose 2nd order tensor subroutine\nc\nc input: Aij (a 2nd order tensor)\nc output: Bji (a 2nd order tensor Aij=Bji)\nc\n subroutine tpose (A,B)\nc\nc variable declaration region\nc declare intent to avoid accidental changes (C.Butcher)\nc \n implicit none\n double precision, intent (in) :: A(9)\n double precision, intent (out) :: B(9)\nc\nc hard-code transpose for SPEED!!!\nc\n B(1)=A(1)\n B(2)=A(4)\n B(3)=A(7)\n B(4)=A(2)\n B(5)=A(5)\n B(6)=A(8)\n B(7)=A(3)\n B(8)=A(6)\n B(9)=A(9)\nc\n return\nc\n end subroutine tpose\nc\nc determinant of a 2nd order tensor subroutine\nc\nc\n subroutine det (A,x)\nc\n implicit none\n double precision, intent (in) :: A(9)\n double precision, intent (out) :: x\nc\n x = A(1)*A(5)*A(9)+A(2)*A(6)*A(7)+A(3)*A(4)*A(8)\n & -A(1)*A(6)*A(8)-A(2)*A(4)*A(9)-A(3)*A(5)*A(7)\nc\n return\n end subroutine det\nc\nc scale 2nd order tensor subroutine\nc\n subroutine scale2 (A,B,m)\nc\n implicit none\n double precision, intent (in) :: A(9)\n double precision, intent (out) :: B(9)\n double precision, intent (in) :: m\nc\n B(1)=m*A(1)\n\tB(2)=m*A(2)\n B(3)=m*A(3)\n B(4)=m*A(4)\n B(5)=m*A(5)\n B(6)=m*A(6)\n B(7)=m*A(7)\n B(8)=m*A(8)\n B(9)=m*A(9)\nc\n return\n end subroutine scale2\nc\nc scale 4th order tensor subroutine\nc\n subroutine scale4 (A4,B4,m)\nc\n implicit none\n double precision, intent (in) :: A4(9,9)\n double precision, intent (out) :: B4(9,9)\n double precision, intent (in) :: m\n integer ij\nc\n do ij=1,9\n B4(ij,1)=m*A4(ij,1)\n\t B4(ij,2)=m*A4(ij,2)\n B4(ij,3)=m*A4(ij,3)\n B4(ij,4)=m*A4(ij,4)\n B4(ij,5)=m*A4(ij,5)\n B4(ij,6)=m*A4(ij,6)\n B4(ij,7)=m*A4(ij,7)\n B4(ij,8)=m*A4(ij,8)\n B4(ij,9)=m*A4(ij,9)\n end do\nc\n return\n end subroutine scale4\nc\nc invert 2nd order tensor subroutine\nc using cofactor method\nc\n subroutine invert (A,B)\nc\n implicit none\n double precision, intent (in) :: A(9)\n double precision, intent (out) :: B(9)\n double precision minor (9)\n double precision det_A\nc\nc DETERMINE WHETHER MATRIX IS SINGULAR (NOT INVERTIBLE)\nc\n call det (A,det_A)\n if (det_A.EQ.0.0_8) then\n B = (/ 0,0,0,0,0,0,0,0,0 /)\n return\n end if\nc\nc MATRIX OF MINORS (COFACTORS FROM HERE)\nc\n minor (1) = A(5)*A(9) - A(6)*A(8)\n minor (2) = -A(4)*A(9) + A(6)*A(7)\n minor (3) = A(4)*A(8) - A(5)*A(7)\n minor (4) = -A(2)*A(9) + A(3)*A(8)\n minor (5) = A(1)*A(9) - A(3)*A(7)\n minor (6) = -A(1)*A(8) + A(2)*A(7)\n minor (7) = A(2)*A(6) - A(3)*A(5)\n minor (8) = -A(1)*A(6) + A(3)*A(4)\n minor (9) = A(1)*A(5) - A(2)*A(4) \nc\nc TRANSPOSE MAT TO GET ADJUGATE AND FIND INV\nc\n call tpose (minor,B)\n call scale2 (B,B,1.0_8/det_A)\nc\n end subroutine invert\nc\nc\nc Single Contraction of 2 2nd order Tensors\nc\n subroutine tc_2s2 (A,B,C)\nc\n implicit none\n double precision, intent (in) :: A(9),B(9)\n double precision, intent (out) :: C(9)\nc\n C(1)=A(1)*B(1)+A(2)*B(4)+A(3)*B(7)\n C(2)=A(1)*B(2)+A(2)*B(5)+A(3)*B(8)\n C(3)=A(1)*B(3)+A(2)*B(6)+A(3)*B(9) \n C(4)=A(4)*B(1)+A(5)*B(4)+A(6)*B(7)\n C(5)=A(4)*B(2)+A(5)*B(5)+A(6)*B(8)\n C(6)=A(4)*B(3)+A(5)*B(6)+A(6)*B(9)\n C(7)=A(7)*B(1)+A(8)*B(4)+A(9)*B(7)\n C(8)=A(7)*B(2)+A(8)*B(5)+A(9)*B(8)\n C(9)=A(7)*B(3)+A(8)*B(6)+A(9)*B(9)\nc \n end subroutine tc_2s2\nc\nc Double Contraction of 2 2nd order Tensors\nc\n subroutine tc_2d2 (A,B,c)\nc\n implicit none\n double precision, intent (inout) :: A(9),B(9)\n double precision, intent (out) :: c\nc\n c = A(1)*B(1)+A(2)*B(4)+A(3)*B(7)\n & +A(4)*B(2)+A(5)*B(5)+A(6)*B(8)\n & +A(7)*B(3)+A(8)*B(6)+A(9)*B(9)\nc \n end subroutine tc_2d2\nc\nc\nc Double Contraction of 2 4th order Tensors\nc\n subroutine tc_4d4 (A,B,C)\nc\n implicit none\n double precision, intent (in) :: A(9,9),B(9,9)\n double precision, intent (out) :: C(9,9)\n integer ij,kl\nc\n do ij=1,9\n do kl=1,9\n C(ij,kl)=A(ij,1)*B(1,kl)+A(ij,2)*B(2,kl)+A(ij,3)*B(3,kl)+\n & A(ij,4)*B(4,kl)+A(ij,5)*B(5,kl)+A(ij,6)*B(6,kl)+\n & A(ij,7)*B(7,kl)+A(ij,8)*B(8,kl)+A(ij,9)*B(9,kl)\n end do\n end do \nc \n end subroutine tc_4d4\nc\nc\nc Double Contraction of 4th and 2nd order Tensors\nc\n subroutine tc_4d2 (A4,B,C)\nc\n implicit none\n double precision, intent (in) :: A4(9,9),B(9)\n double precision, intent (out) :: C(9)\n integer ij\nc\n do ij=1,9\n C(ij)=A4(ij,1)*B(1)+A4(ij,2)*B(2)+A4(ij,3)*B(3)+\n & A4(ij,4)*B(4)+A4(ij,5)*B(5)+A4(ij,6)*B(6)+\n & A4(ij,7)*B(7)+A4(ij,8)*B(8)+A4(ij,9)*B(9)\n end do \nc \n end subroutine tc_4d2\nc\nc\nc Double Contraction of 2nd and 4th order Tensors\nc\n subroutine tc_2d4 (A,B4,C)\nc\n implicit none\n double precision, intent (in) :: A(9),B4(9,9)\n double precision, intent (out) :: C(9)\n integer ij\nc\n do ij=1,9\n C(ij)=A(1)*B4(1,ij)+A(2)*B4(2,ij)+A(3)*B4(3,ij)+\n & A(4)*B4(4,ij)+A(5)*B4(5,ij)+A(6)*B4(6,ij)+\n & A(7)*B4(7,ij)+A(8)*B4(8,ij)+A(9)*B4(9,ij)\n end do \nc \n end subroutine tc_2d4\nc\nc Transformation of second order tensor\nc\n subroutine transform2 (A,Q,C)\nc\n implicit none\n double precision, intent (in) :: A(9), Q(9)\n double precision, intent (out) :: C(9)\n double precision :: B(9)\n double precision :: Qt(9) \nc\nc calculate qt\nc\n call tpose (Q,Qt)\nc\nc let B = QA\nc we want B = (QA)Qt\nc then B = BQt\nc\n call tc_2s2 (A,Qt,B)\n call tc_2s2 (Q,B,C)\nc\n return\nc\n end subroutine transform2\nc\nc Rotation tensor for rotation about z-axis\nc IN RADIANS!!!!!!!!!!!\nc\n subroutine qzrad (th,Q)\nc\n implicit none\n double precision, intent (in) :: th\n double precision, intent (out) :: Q(9)\nc\n Q(1) = COS(th) \n Q(2) = SIN(th)\n Q(3) = 0.0_8\n Q(4) = -SIN(th)\n Q(5) = COS(th)\n Q(6) = 0.0_8\n Q(7) = 0.0_8\n Q(8) = 0.0_8\n Q(9) = 1.0_8\n return\nc\n end subroutine qzrad\nc\nc Rotation tensor for rotation about x-axis\nc IN RADIANS!!!!!!!!!!!\nc\n subroutine qxrad (th,Q)\nc\n implicit none\n double precision, intent (in) :: th\n double precision, intent (out) :: Q(9)\nc\n Q(1) = 1.0_8\n Q(2) = 0.0_8\n Q(3) = 0.0_8\n Q(4) = 0\n Q(5) = COS(th)\n Q(6) = -SIN(th)\n Q(7) = 0.0_8\n Q(8) = SIN(th)\n Q(9) = COS(th)\n return\nc\n end subroutine qxrad\nc\nc Rotation tensor for rotation about y-axis\nc IN RADIANS!!!!!!!!!!!\nc\n subroutine qyrad (th,Q)\nc\n implicit none\n double precision, intent (in) :: th\n double precision, intent (out) :: Q(9)\nc\n Q(1) = COS(th) \n Q(2) = 0.0_8\n Q(3) = SIN(th)\n Q(4) = 0.0_8\n Q(5) = 1.0_8\n Q(6) = 0.0_8\n Q(7) = -SIN(th)\n Q(8) = 0.0_8\n Q(9) = COS(th)\n return\nc\n end subroutine qyrad\nc\nc Dyadic Product of 2 2nd order tensors\nc\n subroutine tp_2dy2 (A,B,C4)\nc\n implicit none\n double precision, intent (in) :: A(9), B(9)\n double precision, intent (out) :: C4(9,9)\n integer ij\n \n do ij=1,9\n C4(ij,1) = A(ij)*B(1)\n C4(ij,2) = A(ij)*B(2)\n C4(ij,3) = A(ij)*B(3)\n C4(ij,4) = A(ij)*B(4)\n C4(ij,5) = A(ij)*B(5)\n C4(ij,6) = A(ij)*B(6)\n C4(ij,7) = A(ij)*B(7)\n C4(ij,8) = A(ij)*B(8)\n C4(ij,9) = A(ij)*B(9)\n end do\nc\n return\nc\n end subroutine tp_2dy2\nc\n", "meta": {"hexsha": "a02e7874149e564d34d0339832975b478ff1b18b", "size": 9868, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "TLIB/tensor.f", "max_stars_repo_name": "kengwit/UMAT", "max_stars_repo_head_hexsha": "75594749924d167c6b2e4b2635530ea37152a70c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "TLIB/tensor.f", "max_issues_repo_name": "kengwit/UMAT", "max_issues_repo_head_hexsha": "75594749924d167c6b2e4b2635530ea37152a70c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2018-06-26T22:03:53.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-17T15:10:04.000Z", "max_forks_repo_path": "TLIB/tensor.f", "max_forks_repo_name": "kengwit/UMAT", "max_forks_repo_head_hexsha": "75594749924d167c6b2e4b2635530ea37152a70c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-04T07:20:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T14:03:25.000Z", "avg_line_length": 25.3025641026, "max_line_length": 69, "alphanum_fraction": 0.4724361573, "num_tokens": 3930, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.8872045847699186, "lm_q1q2_score": 0.7912188457098726}} {"text": "! Copyright (C) 2012 The SPEED FOUNDATION\n! Author: Ilario Mazzieri\n!\n! This file is part of SPEED.\n!\n! SPEED is free software; you can redistribute it and/or modify it\n! under the terms of the GNU Affero General Public License as\n! published by the Free Software Foundation, either version 3 of the\n! License, or (at your option) any later version.\n!\n! SPEED is distributed in the hope that it will be useful, but\n! WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n! Affero General Public License for more details.\n!\n! You should have received a copy of the GNU Affero General Public License\n! along with SPEED. If not, see .\n\n!> @brief Makes Gauss Legendre nodes and weights \n!! @author Ilario Mazzieri\n!> @date September, 2013 \n!> @version 1.0\n!> @param[in] ngp number of Gauss points\n!> @param[out] xabsc Gauss points\n!> @param[out] weig weights for the Gauss quadrature rule\n\n \n subroutine MAKE_GL_NW(ngp, xabsc, weig)\n\n implicit none\n\n INTEGER, parameter :: dbp = SELECTED_REAL_KIND (15,307)\n REAL(dbp) :: newv\n REAL(dbp) :: EPS, M_PI\n PARAMETER (EPS=3.0d-15) !EPS is the relative precision\n PARAMETER (M_PI=3.141592654d0) \n \n INTEGER*4 i, j, m\n REAL(dbp) p1, p2, p3, pp, z, z1\n INTEGER*4, INTENT(IN) :: ngp ! # of Gauss Points\n REAL(dbp), INTENT(OUT) :: xabsc(ngp), weig(ngp)\n\n\n m = (ngp + 1) / 2\n!* Roots are symmetric in the interval - so only need to find half of them */\n\n do i = 1, m ! Loop over the desired roots */\n\n z = cos( M_PI * (i-0.25d0) / (ngp+0.5d0) )\n!* Starting with the above approximation to the ith root,\n!* we enter the main loop of refinement by NEWTON'S method */\n\n100 p1 = 1.0d0\n p2 = 0.0d0\n!* Loop up the recurrence relation to get the Legendre\n!* polynomial evaluated at z */\n\n do j = 1, ngp\n p3 = p2\n p2 = p1\n p1 = ((2.0d0*j-1.0d0) * z * p2 - (j-1.0d0)*p3) / j\n enddo\n\n!* p1 is now the desired Legendre polynomial. We next compute pp,\n!* its derivative, by a standard relation involving also p2, the\n!* polynomial of one lower order. */\n pp = ngp*(z*p1-p2)/(z*z-1.0d0)\n z1 = z\n z = z1 - p1/pp ! Newton's Method */\n\n if (dabs(z-z1) .gt. EPS) GOTO 100\n\n xabsc(i) = - z ! Roots will be bewteen -1.0 & 1.0 */\n xabsc(ngp+1-i) = + z ! and symmetric about the origin */\n weig(i) = 2.0d0/((1.0d0-z*z)*pp*pp) ! Compute the weight and its */\n weig(ngp+1-i) = weig(i) ! symmetric counterpart */\n\n end do ! i loop\n\n End subroutine MAKE_GL_NW\n\n", "meta": {"hexsha": "914d1c296a75401ae09caf3d44b9b190bb4f524a", "size": 3049, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SRC/SPEED-MDOF190510/MAKE_GL_NW.f90", "max_stars_repo_name": "research-group-of-Xinzheng-Lu/SCI-effects-simulation", "max_stars_repo_head_hexsha": "6f91a4afce51303ac33d9dce005247290679b428", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-05-11T17:26:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-31T12:41:29.000Z", "max_issues_repo_path": "SRC/SPEED-MDOF190510/MAKE_GL_NW.f90", "max_issues_repo_name": "research-group-of-Xinzheng-Lu/SCI-effects-simulation", "max_issues_repo_head_hexsha": "6f91a4afce51303ac33d9dce005247290679b428", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SRC/SPEED-MDOF190510/MAKE_GL_NW.f90", "max_forks_repo_name": "research-group-of-Xinzheng-Lu/SCI-effects-simulation", "max_forks_repo_head_hexsha": "6f91a4afce51303ac33d9dce005247290679b428", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-05-15T06:26:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-10T07:22:41.000Z", "avg_line_length": 37.1829268293, "max_line_length": 96, "alphanum_fraction": 0.5549360446, "num_tokens": 884, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.8757869965109764, "lm_q1q2_score": 0.791093324814907}} {"text": "program roots\n\n implicit none\n\n intrinsic :: selected_real_kind, abs, sqrt\n integer, parameter :: wp = selected_real_kind(15)\n real(wp) :: p, q, d\n\n write (*, *) \"Solving x² + p·x + q = 0, please enter p and q\"\n read (*, *) p, q\n\td = 0.25_wp * p**2 - q\n\t\n\t! descriminant is positive, we have two real roots\n if (d > 0.0_wp) then\n write (*, *) \"x1 =\", -0.5_wp*p + sqrt(d)\n write (*, *) \"x2 =\", -0.5_wp*p - sqrt(d)\n\t! descriminant is negative, we have two complex roots\n else if (d < 0.0_wp) then\n write (*, *) \"x1 =\", -0.5_wp*p, \"+ i ·\", sqrt(abs(d))\n write (*, *) \"x2 =\", -0.5_wp*p, \"- i ·\", sqrt(abs(d))\n\t! descriminant is zero, we have only one root\n\telse \n write(*, *) \"x1 = x2 =\", -0.5_wp * p\n end if\n\nend program roots\n", "meta": {"hexsha": "d8783bd18baff3477f604e6183eaeb7b9c1b0700", "size": 749, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exercises/fortran-exercises/ex7-logical/app/main.f90", "max_stars_repo_name": "marvinfriede/projects", "max_stars_repo_head_hexsha": "7050cd76880c8ff0d9de17b8676e82f1929a68e0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exercises/fortran-exercises/ex7-logical/app/main.f90", "max_issues_repo_name": "marvinfriede/projects", "max_issues_repo_head_hexsha": "7050cd76880c8ff0d9de17b8676e82f1929a68e0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-04-14T20:15:26.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-14T20:20:54.000Z", "max_forks_repo_path": "exercises/fortran-exercises/ex7-logical/app/main.f90", "max_forks_repo_name": "marvinfriede/projects", "max_forks_repo_head_hexsha": "7050cd76880c8ff0d9de17b8676e82f1929a68e0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.7407407407, "max_line_length": 63, "alphanum_fraction": 0.5607476636, "num_tokens": 276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9648551535992067, "lm_q2_score": 0.8198933293122507, "lm_q1q2_score": 0.7910783041885366}} {"text": "\n PROGRAM TEST\n\n! Version 1.4.\n\n! This is a sample program using the FMZM modules for doing arithmetic using the FM, IM, and ZM\n! derived types.\n\n! The program's output to the screen is also saved in file SampleFM.out.\n! The program checks all the results and the last line of the output file should be\n! \"All results were ok.\"\n\n! These examples show various ways to use the FM package, but the methods used are not always\n! the most advanced for the sample problem.\n\n USE FMZM\n\n IMPLICIT NONE\n\n! Declare the multiple precision variables. The three types are:\n! (FM) for multiple precision real\n! (IM) for multiple precision integer\n! (ZM) for multiple precision complex\n\n TYPE (FM), SAVE :: X1, X2, X3, X4\n TYPE (FM), SAVE, ALLOCATABLE :: A(:,:), B(:,:), V1(:), V2(:)\n TYPE (IM), SAVE :: I1, I2, I3\n TYPE (ZM), SAVE :: Z1, Z2, Z3, Z4\n\n! Declare the function name of a type (FM) function that will be passed as an argument\n! to a subroutine called from this program.\n\n TYPE (FM), EXTERNAL :: F\n\n! Declare the other variables (not multiple precision).\n\n CHARACTER(80) :: ST1\n CHARACTER(175) :: FMT\n INTEGER :: ITER, J, K, KOUT, NERROR\n INTEGER :: SEED(7)\n DOUBLE PRECISION :: VALUE\n\n! Write output to the screen (unit *), and also to the file SampleFM.out.\n\n KOUT = 18\n OPEN (KOUT,FILE='SampleFM.out')\n\n NERROR = 0\n\n\n! 1. Find a root of the equation f(x) = x**5 - 3x**4 + x**3 - 4x**2 + x - 6 = 0.\n\n! Set precision to give at least 60 significant digits.\n\n CALL FM_SET(60)\n\n! Use Newton's method with initial guess x = 3.12.\n! Horner's rule is used to evaluate the function.\n\n! X1 is the previous iterate.\n! X2 is the current iterate.\n\n! TO_FM is a function for converting other types of numbers to type FM. Note that\n! TO_FM(3.12) converts the REAL constant to FM, but it is accurate only to single\n! precision, since the number 3.12 cannot be represented exactly in binary and has\n! already been rounded to single precision. Similarly, TO_FM(3.12D0) agrees with\n! 3.12 to double precision accuracy, and TO_FM('3.12') or TO_FM(312)/TO_FM(100)\n! agrees to full FM accuracy.\n! Here, TO_FM(3.12) would be ok, since Newton iteration will correct the error\n! coming from single precision, but it is a good habit to use the more accurate\n! form.\n\n X1 = TO_FM('3.12')\n\n! Print the first iteration.\n\n FMT = \"(//' Sample 1. Real root of f(x) = x**5 - 3x**4 + x**3 - 4x**2 + x - 6 = 0.'//\"// &\n \"' Iteration Newton approximation')\"\n WRITE (* ,FMT)\n WRITE (KOUT,FMT)\n\n! FM_FORM is a formatting subroutine.\n\n CALL FM_FORM('F65.60',X1,ST1)\n WRITE (* ,\"(/I10,4X,A)\") 0,TRIM(ST1)\n WRITE (KOUT,\"(/I10,4X,A)\") 0,TRIM(ST1)\n\n DO ITER = 1, 10\n\n! X3 is f(X1).\n\n X3 = ((((X1-3)*X1+1)*X1-4)*X1+1)*X1-6\n\n! X4 is f'(X1).\n\n X4 = (((5*X1-12)*X1+3)*X1-8)*X1+1\n\n X2 = X1 - X3/X4\n\n! Print each iteration.\n\n CALL FM_FORM('F65.60',X2,ST1)\n WRITE (* ,\"(/I10,4X,A)\") ITER,TRIM(ST1)\n WRITE (KOUT,\"(/I10,4X,A)\") ITER,TRIM(ST1)\n\n! Stop iterating if X1 and X2 agree to over 60 places.\n\n X4 = ABS(X1-X2)\n IF (X4 < 1.0D-61) EXIT\n\n! Set X1 = X2 for the next iteration.\n\n X1 = X2\n ENDDO\n\n! Check the answer.\n\n X3 = TO_FM('3.1206562153267265004709560135237974846546239355990660149888284358')\n\n! It is slightly safer to do this test with .NOT. instead of\n! IF (ABS(X3-X2) >= 1.0D-61) THEN\n! because if the result of ABS(X3-X2) is FM's UNKNOWN value,\n! the comparison returns false for all comparisons.\n\n IF (.NOT.(ABS(X3-X2) < 1.0D-61)) THEN\n NERROR = NERROR + 1\n WRITE (* ,\"(/' Error in sample case number 1.'/)\")\n WRITE (KOUT,\"(/' Error in sample case number 1.'/)\")\n ENDIF\n\n\n! 2. Higher Precision. Compute the root above to 500 decimal places.\n\n CALL FM_SET(500)\n\n! It is tempting to just say X1 = X3 here to initialize the start of the higher\n! precision iterations to be the check value defined above. That will not work,\n! because precision has changed. Most of the digits of X3 may be undefined at\n! the new precision.\n! The most flexible way to pad a lower precision value with zeros when raising\n! precision is to use subroutine FM_EQU, but here it is easier to re-define X1\n! from scratch at the new precision.\n\n X1 = TO_FM('3.1206562153267265004709560135237974846546239355990660149888284358')\n\n DO ITER = 1, 10\n\n! X3 is f(X1).\n\n X3 = ((((X1-3)*X1+1)*X1-4)*X1+1)*X1-6\n\n! X4 is f'(X1).\n\n X4 = (((5*X1-12)*X1+3)*X1-8)*X1+1\n\n X2 = X1 - X3/X4\n\n! Stop iterating if X1 and X2 agree to over 500 places.\n\n X4 = ABS(X1-X2)\n\n! Compare this test to the similar one in case 1 above.\n! For machines with 64-bit double precision, 1.0D-501 would be smaller than the\n! smallest positive number. So this error tolerance is converted to an FM number\n! from character form.\n\n IF (X4 < TO_FM('1.0E-501')) EXIT\n\n! Set X1 = X2 for the next iteration.\n\n X1 = X2\n ENDDO\n\n! For very high precision output, it is sometimes more convenient to use FM_PRINT\n! to format and print the numbers, since the line breaks are handled automatically.\n! The unit number for the output, KW, and the format codes to be used, JFORM1 and\n! JFORM2, are internal FM variables.\n! Subroutine FM_SETVAR is used to re-define these, and the new values will remain in\n! effect for any further calls to FM_PRINT.\n\n! Other variables that can be changed and the options they control are listed in the\n! documentation at the top of file FM.f95.\n\n! Set the FM_PRINT format to F505.500\n\n CALL FM_SETVAR(' JFORM1 = 2 ')\n CALL FM_SETVAR(' JFORM2 = 500 ')\n\n! Set the output screen width to 90 columns.\n\n CALL FM_SETVAR(' KSWIDE = 90 ')\n\n FMT = \"(///' Sample 2. Find the root above to 500 decimal places.'/)\"\n WRITE (* ,FMT)\n WRITE (KOUT,FMT)\n\n! Write to the output file.\n\n CALL FM_SETVAR(' KW = 18 ')\n CALL FM_PRINT(X2)\n\n! Write to the screen (unit 6).\n\n CALL FM_SETVAR(' KW = 6 ')\n CALL FM_PRINT(X2)\n\n! Check the answer.\n\n X3 = TO_FM('3.1206562153267265004709560135237974846546239355990660149888284358190264999' // &\n '517954689783257450017151095811923431332682839420040840535954560118152245371'// &\n '792881305271951017118938898212403662058307303983547376913282000110058273504'// &\n '202838670709895619275413484521549282591891156945200789415818387529512010999'// &\n '602155131321076797099026664236992803703462570149559724389392331827597552460'// &\n '610612200485579529156910428115547013787714423708578161025641555097481179969'// &\n '175028390105904786831680128384331143259309155577171683842444352768419176139060')\n\n IF (.NOT.(ABS(X3-X2) < TO_FM('1.0E-501'))) THEN\n NERROR = NERROR + 1\n WRITE (* ,\"(/' Error in sample case number 2.'/)\")\n WRITE (KOUT,\"(/' Error in sample case number 2.'/)\")\n ENDIF\n\n\n! 3. Compute the Riemann zeta function for s=3.\n\n! Use Gosper's formula: zeta(3) =\n! (5/4)*Sum[ (-1)**k * (k!)**2 / ((k+1)**2 * (2k+1)!) ]\n! while k = 0, 1, ....\n\n! X1 is the current partial sum.\n! X2 is the current term.\n! X3 is k!\n! X4 is (2k+1)!\n\n CALL FM_SET(60)\n X1 = 1\n X3 = 1\n X4 = 1\n DO K = 1, 200\n X3 = K*X3\n J = 2*K*(2*K+1)\n X4 = J*X4\n X2 = X3**2\n J = (K+1)*(K+1)\n X2 = (X2/J)/X4\n IF (MOD(K,2) == 0) THEN\n X1 = X1 + X2\n ELSE\n X1 = X1 - X2\n ENDIF\n\n! Test for convergence.\n! Here the rate of convergence is much slower than in the Newton iterations above.\n! Asking for 60 digits in the call to FM_SET will cause the internal precision to\n! be set slightly higher than that, giving the user a few guard digits.\n! X2 is the difference between the two most recent partial sums, so the test\n! below will stop the sum when the last two partial sums agree to at least 65\n! significant digits.\n\n IF (ABS(X2/X1) < 1.0D-65) THEN\n FMT = \"(///' Sample 3.',2X,I5,' terms were added in the zeta sum.'/)\"\n WRITE (* ,FMT) K\n WRITE (KOUT,FMT) K\n EXIT\n ENDIF\n ENDDO\n\n! Print the result.\n\n X1 = (5*X1)/4\n CALL FM_FORM('F63.60',X1,ST1)\n WRITE (* ,\"(' zeta(3) = ',A)\") TRIM(ST1)\n WRITE (KOUT,\"(' zeta(3) = ',A)\") TRIM(ST1)\n\n! Check the answer.\n\n X3 = TO_FM('1.202056903159594285399738161511449990764986292340498881792271555')\n IF (.NOT.(ABS(X1-X3) < 1.0D-61)) THEN\n NERROR = NERROR + 1\n WRITE (* ,\"(/' Error in sample case number 3.'/)\")\n WRITE (KOUT,\"(/' Error in sample case number 3.'/)\")\n ENDIF\n\n\n! 4. Integer multiple precision calculations.\n\n! Fermat's theorem says x**(p-1) mod p = 1 when p is prime and x is not a\n! multiple of p.\n! If x**(p-1) mod p gives 1 for some p with several different x's, then it is\n! very likely that p is prime (but it is not certain until further tests are done).\n\n! Find a 70-digit number p that is \"probably\" prime.\n\n! Use FM_RANDOM_NUMBER to generate a random 70-digit starting value and search for\n! a prime from that point.\n\n! Initialize the generator.\n! Note that VALUE is double precision, unlike the similar Fortran intrinsic random\n! number routine, which returns a single-precision result.\n\n SEED = (/ 2718281,8284590,4523536,0287471,3526624,9775724,7093698 /)\n CALL FM_RANDOM_SEED_PUT(SEED)\n\n! I1 is the value p being tested.\n\n I1 = 0\n I3 = TO_IM(10)**13\n DO J = 1, 6\n CALL FM_RANDOM_NUMBER(VALUE)\n I2 = 1.0D13*VALUE\n I1 = I1*I3 + I2\n ENDDO\n I3 = TO_IM(10)**70\n I1 = MOD(I1,I3)\n\n! To speed up the search, test only values that are not\n! multiples of 2, 3, 5, 7, 11, 13.\n\n K = 2*3*5*7*11*13\n I1 = (I1/K)*K + K + 1\n I3 = 3\n\n DO J = 1, 100\n I2 = I1 - 1\n\n! Compute 3**(p-1) mod p\n\n I3 = POWER_MOD(I3,I2,I1)\n IF (I3 == 1) THEN\n\n! Check that 7**(p-1) mod p is also 1.\n\n I3 = 7\n I3 = POWER_MOD(I3,I2,I1)\n IF (I3 == 1) THEN\n FMT = \"(///' Sample 4.',2X,I5,' values were checked before finding a prime p.'/)\"\n WRITE (* ,FMT) J\n WRITE (KOUT,FMT) J\n EXIT\n ENDIF\n ENDIF\n\n I3 = 3\n I1 = I1 + K\n ENDDO\n\n! Print the result.\n\n CALL IM_FORM('I72',I1,ST1)\n WRITE (* ,\"(' p =',A)\") TRIM(ST1)\n WRITE (KOUT,\"(' p =',A)\") TRIM(ST1)\n\n! Check the answer.\n\n I3 = TO_IM('9552131129056058313103536357738804884840825498503088946760768419490591')\n IF (.NOT.(I1 == I3)) THEN\n NERROR = NERROR + 1\n WRITE (* ,\"(/' Error in sample case number 4.'/)\")\n WRITE (KOUT,\"(/' Error in sample case number 4.'/)\")\n ENDIF\n\n\n! 5. Log Integral function.\n\n! Estimate the number of primes less than 10**30.\n\n FMT = \"(///' Sample 5. Log integral. Estimate the number of primes less than 10**30.'/\"// &\n \"' It should be accurate to about 15 significant digits.'/)\"\n WRITE (* ,FMT)\n WRITE (KOUT,FMT)\n\n I2 = TO_IM(LOG_INTEGRAL(TO_FM('1.0E+30')))\n\n! Print the result.\n\n CALL IM_FORM('I30',I2,ST1)\n WRITE (* ,\"(' int(li(1.0e+30)) = ',A)\") TRIM(ST1)\n WRITE (KOUT,\"(' int(li(1.0e+30)) = ',A)\") TRIM(ST1)\n\n! Check the answer.\n\n I3 = TO_IM('14692398897720447639079087669')\n IF (.NOT.(I2 == I3)) THEN\n NERROR = NERROR + 1\n WRITE (* ,\"(/' Error in sample case number 5.'/)\")\n WRITE (KOUT,\"(/' Error in sample case number 5.'/)\")\n ENDIF\n\n\n! 6. Gamma function.\n\n! Check that gamma(1/2) is sqrt(pi)\n\n FMT = \"(///' Sample 6. Check that gamma(1/2) = sqrt(pi).'/)\"\n WRITE (* ,FMT)\n WRITE (KOUT,FMT)\n\n X2 = GAMMA(TO_FM('0.5'))\n\n! Print the result.\n\n CALL FM_FORM('F63.60',X2,ST1)\n WRITE (* ,\"(' gamma(1/2) = ',A)\") TRIM(ST1)\n WRITE (KOUT,\"(' gamma(1/2) = ',A)\") TRIM(ST1)\n\n! Check the answer.\n\n X3 = SQRT(ACOS(TO_FM(-1)))\n IF (.NOT.(ABS(X3-X2) < 1.0D-61)) THEN\n NERROR = NERROR + 1\n WRITE (* ,\"(/' Error in sample case number 6.'/)\")\n WRITE (KOUT,\"(/' Error in sample case number 6.'/)\")\n ENDIF\n\n\n! 7. Psi and polygamma functions.\n\n! Rational series can often be summed using these functions.\n! Sum (n=1 to infinity) 1/(n**2 * (8n+1)**2) =\n! 16*(psi(1) - psi(9/8)) + polygamma(1,1) + polygamma(1,9/8)\n! Reference: Abramowitz & Stegun, Handbook of Mathematical Functions,\n! chapter 6, Example 10.\n\n FMT = \"(///' Sample 7. Psi and polygamma functions.'/)\"\n WRITE (* ,FMT)\n WRITE (KOUT,FMT)\n\n X2 = 16*(PSI(TO_FM(1)) - PSI(TO_FM(9)/8)) + POLYGAMMA(1,TO_FM(1)) + POLYGAMMA(1,TO_FM(9)/8)\n\n! Print the result.\n\n CALL FM_FORM('F65.60',X2,ST1)\n FMT = \"(' Sum (n=1 to infinity) 1/(n**2 * (8n+1)**2) = '/9X,A)\"\n WRITE (* ,FMT) TRIM(ST1)\n WRITE (KOUT,FMT) TRIM(ST1)\n\n! Check the answer.\n\n X3 = TO_FM('1.3499486145413024755107829105035147950644978635837270816327396M-2')\n IF (.NOT.(ABS(X3-X2) < 1.0D-61)) THEN\n NERROR = NERROR + 1\n WRITE (* ,\"(/' Error in sample case number 7.'/)\")\n WRITE (KOUT,\"(/' Error in sample case number 7.'/)\")\n ENDIF\n\n\n! 8. Incomplete gamma and gamma functions.\n\n! Find the probability that an observed chi-square for a correct model should be\n! less that 2.3 when the number of degrees of freedom is 5.\n! Reference: Knuth, Volume 2, 3rd ed., Page 56, and Press, Flannery, Teukolsky,\n! Vetterling, Numerical Recipes, 1st ed., Page 165.\n\n FMT = \"(///' Sample 8. Incomplete gamma and gamma functions.'/)\"\n WRITE (* ,FMT)\n WRITE (KOUT,FMT)\n\n X1 = TO_FM(5)/2\n X2 = INCOMPLETE_GAMMA1(X1,TO_FM('2.3')/2) / GAMMA(X1)\n\n! Print the result.\n\n CALL FM_FORM('F62.60',X2,ST1)\n WRITE (* ,\"(' Probability = ',A)\") TRIM(ST1)\n WRITE (KOUT,\"(' Probability = ',A)\") TRIM(ST1)\n\n! Check the answer.\n\n X3 = TO_FM('0.19373313011487144632751025918250599953472318607121386973066283739')\n IF (.NOT.(ABS(X3-X2) < 1.0D-61)) THEN\n NERROR = NERROR + 1\n WRITE (* ,\"(/' Error in sample case number 8.'/)\")\n WRITE (KOUT,\"(/' Error in sample case number 8.'/)\")\n ENDIF\n\n\n! 9. Error function.\n\n! Find the probability that a value drawn from a normal distribution is within\n! 1 or 2 or 3 standard deviations from the mean.\n\n FMT = \"(///' Sample 9. Error function. Probability that a value drawn from a normal'/\"// &\n \"' distribution is within k standard deviations from the mean.'/)\"\n WRITE (* ,FMT)\n WRITE (KOUT,FMT)\n\n DO K = 1, 3\n X1 = K / SQRT(TO_FM(2))\n X2 = ERF(X1)\n\n! Print the results.\n\n CALL FM_FORM('F52.50',X2,ST1)\n WRITE (* ,\"(' k = ',I2,', probability = ',A)\") K,TRIM(ST1)\n WRITE (KOUT,\"(' k = ',I2,', probability = ',A)\") K,TRIM(ST1)\n\n! Check the answer.\n\n IF (K == 1) THEN\n X3 = TO_FM('0.68268949213708589717046509126407584495582593345320878197478890049')\n ELSE IF (K == 2) THEN\n X3 = TO_FM('0.95449973610364158559943472566693312505644755259664313203266799974')\n ELSE\n X3 = TO_FM('0.99730020393673981094669637046481004524434126368323870127155602929')\n ENDIF\n IF (.NOT.(ABS(X3-X2) < 1.0D-61)) THEN\n NERROR = NERROR + 1\n WRITE (* ,\"(/' Error in sample case number 9.'/)\")\n WRITE (KOUT,\"(/' Error in sample case number 9.'/)\")\n ENDIF\n ENDDO\n\n\n! 10. Array operations.\n\n! Find the dominant eigenvalue and a corresponding eigenvector for this 5x5 matrix:\n\n! 3 1 4 1 5\n! 9 2 6 5 3\n! A = 5 8 9 7 9\n! 3 2 3 8 4\n! 6 2 6 4 3\n\n! Use the power method. Compute B = A**n. If v1 is an initial guess for the\n! largest magnitude eigenvector, v2 = B*v1 should be a more accurate approximation.\n! The ratio of the elements of v3 = A*v2 to those of v2 gives an estimate of the\n! corresponding eigenvalue. By repeatedly squaring the matrix, each iteration uses\n! the next higher power of 2 for n.\n\n FMT = \"(///' Sample 10. Eigenvalue from matrix powers.')\"\n WRITE (* ,FMT)\n WRITE (KOUT,FMT)\n\n! These type FM arrays were declared as allocatable. Allocate them now, and initialize.\n\n ALLOCATE( A(5,5) )\n ALLOCATE( B(5,5) )\n ALLOCATE( V1(5) )\n ALLOCATE( V2(5) )\n\n! To initialize the matrix, we can use array sections to set one row at a time, and the\n! FMZM interface will take care of converting from integer to type (FM). If the values\n! were not integers, we could say A(1,1:5) = (/ TO_FM(' 3.7 '),TO_FM(' 4.2 '), etc.\n\n A(1,1:5) = (/ 3, 1, 4, 1, 5 /)\n A(2,1:5) = (/ 9, 2, 6, 5, 3 /)\n A(3,1:5) = (/ 5, 8, 9, 7, 9 /)\n A(4,1:5) = (/ 3, 2, 3, 8, 4 /)\n A(5,1:5) = (/ 6, 2, 6, 4, 3 /)\n\n! Initialize all elements of the initial guess vector to 1.\n\n V1 = 1\n\n B = A\n WRITE (* ,\"(/' Iteration eigenvalue approximation ')\")\n WRITE (KOUT,\"(/' Iteration eigenvalue approximation ')\")\n DO J = 1, 7\n B = MATMUL(B,B)\n V1 = MATMUL(B,V1)\n V2 = MATMUL(A,V1)\n X1 = V2(1) / V1(1)\n CALL FM_FORM('F64.57',X1,ST1)\n WRITE (* ,\"(/I10,A)\") J,TRIM(ST1)\n WRITE (KOUT,\"(/I10,A)\") J,TRIM(ST1)\n ENDDO\n\n! Normalize the eigenvector (L-2 norm).\n\n V2 = V2 / NORM2(V2)\n WRITE (* ,\"(/' The corresponding eigenvector is'/)\")\n WRITE (KOUT,\"(/' The corresponding eigenvector is'/)\")\n DO J = 1, 5\n CALL FM_FORM('F61.57',V2(J),ST1)\n WRITE (* ,\"(A)\") TRIM(ST1)\n WRITE (KOUT,\"(A)\") TRIM(ST1)\n ENDDO\n\n! Check the answer.\n\n X3 = TO_FM('23.91276717232132858935703922800330450554912919599927298216827247803204')\n IF (.NOT.(ABS(X3-X1) < 1.0D-61)) THEN\n NERROR = NERROR + 1\n WRITE (* ,\"(/' Error in sample case number 10.'/)\")\n WRITE (KOUT,\"(/' Error in sample case number 10.'/)\")\n ENDIF\n\n\n! 11. Function and subroutine example.\n\n! Find the integral from 0 to 1/2 of 2*exp(-x**2)/sqrt(pi).\n\n! The exact value of the integral is erf(1/2).\n! Use a simple numerical integration routine to apply an integration rule\n! using 100 intervals.\n\n CALL FM_SET(40)\n\n FMT = \"(///' Sample 11. Function and subroutine example.'/)\"\n WRITE (* ,FMT)\n WRITE (KOUT,FMT)\n\n X1 = 0\n X2 = TO_FM(' 0.5 ')\n CALL PLAN_9(F,X1,X2,100,X3)\n\n! Print the result.\n\n CALL FM_FORM('F32.30',X3,ST1)\n WRITE (* ,\"(' Integral = ',A)\") TRIM(ST1)\n WRITE (KOUT,\"(' Integral = ',A)\") TRIM(ST1)\n\n! Check the answer.\n\n X4 = ERF(TO_FM('0.5'))\n IF (.NOT.(ABS(X3-X4) < 1.0D-31)) THEN\n NERROR = NERROR + 1\n WRITE (* ,\"(/' Error in sample case number 11.'/)\")\n WRITE (KOUT,\"(/' Error in sample case number 11.'/)\")\n ENDIF\n\n\n! Complex arithmetic.\n\n! Set precision to give at least 30 significant digits.\n\n CALL FM_SET(30)\n\n\n! 12. Find a complex root of the equation\n! f(x) = x**5 - 3x**4 + x**3 - 4x**2 + x - 6 = 0.\n\n! Newton's method with initial guess x = .56 + 1.06 i.\n\n! Z1 is the previous iterate.\n! Z2 is the current iterate.\n\n Z1 = TO_ZM('.56 + 1.06 i')\n\n! Print the first iteration.\n\n FMT = \"(///' Sample 12. Complex root of f(x) = x**5 - 3x**4 + x**3 - 4x**2 + x - 6 = 0.',\" &\n //\"//' Iteration Newton approximation')\"\n WRITE (* ,FMT)\n WRITE (KOUT,FMT)\n CALL ZM_FORM('F32.30','F32.30',Z1,ST1)\n WRITE (* ,\"(/I6,4X,A)\") 0,TRIM(ST1)\n WRITE (KOUT,\"(/I6,4X,A)\") 0,TRIM(ST1)\n\n DO ITER = 1, 10\n\n! Z3 is f(Z1).\n\n Z3 = ((((Z1-3)*Z1+1)*Z1-4)*Z1+1)*Z1-6\n\n! Z4 is f'(Z1).\n\n Z4 = (((5*Z1-12)*Z1+3)*Z1-8)*Z1+1\n\n Z2 = Z1 - Z3/Z4\n\n! Print each iteration.\n\n CALL ZM_FORM('F32.30','F32.30',Z2,ST1)\n WRITE (* ,\"(/I6,4X,A)\") ITER,TRIM(ST1)\n WRITE (KOUT,\"(/I6,4X,A)\") ITER,TRIM(ST1)\n\n! Stop iterating if Z1 and Z2 agree to over 30 places.\n\n IF (ABS(Z1-Z2) < 1.0D-31) EXIT\n\n! Set Z1 = Z2 for the next iteration.\n\n Z1 = Z2\n ENDDO\n\n! Check the answer.\n\n Z3 = TO_ZM('0.561958308335403235498111195347453 + 1.061134679604332556983391239058885 i')\n IF (.NOT.(ABS(Z3-Z2) < 1.0D-31)) THEN\n NERROR = NERROR + 1\n WRITE (* ,\"(/' Error in sample case number 12.'/)\")\n WRITE (KOUT,\"(/' Error in sample case number 12.'/)\")\n ENDIF\n\n\n! 13. Compute exp(1.23-2.34i).\n\n! Use the direct Taylor series.\n\n! Z1 is x.\n! Z2 is the current term, x**n/n!.\n! Z3 is the current partial sum.\n\n Z1 = TO_ZM('1.23-2.34i')\n Z2 = 1\n Z3 = 1\n DO K = 1, 100\n Z2 = Z2*Z1/K\n Z4 = Z3 + Z2\n\n! Test for convergence.\n\n! This is a common way to check for series convergence -- wait until the term\n! being added is so close to zero that the sum does not change. That is fine\n! here, because we are using the default round-to-nearest rounding mode.\n\n! There is a pitfall if we were to re-run the program with a different rounding\n! mode. For example, if we change the rounding mode to round toward +infinity,\n! then at 30-digit precision the addition 1.2 + 3.4e-100 rounds up to 1.200...001\n! and so the test to see if the sum did not change might never be satisfied.\n! This problem can occur with either type FM or ZM sums.\n\n! For cases where other rounding modes might be used, doing the convergence check\n! like we did in the zeta sum of example 3 above is better. Here that would be\n! IF (ABS(Z2/Z3) < 1.0D-35) THEN\n\n IF (Z4 == Z3) THEN\n FMT = \"(///' Sample 13.',2X,I5,' terms were added to get exp(1.23-2.34i).'/)\"\n WRITE (* ,FMT) K\n WRITE (KOUT,FMT) K\n EXIT\n ENDIF\n Z3 = Z4\n ENDDO\n\n! Print the result.\n\n CALL ZM_FORM('F33.30','F32.30',Z3,ST1)\n WRITE (* ,\"(' Result= ',A)\") TRIM(ST1)\n WRITE (KOUT,\"(' Result= ',A)\") TRIM(ST1)\n\n! Check the answer.\n\n Z4 = TO_ZM('-2.379681796854777515745457977696745 - 2.458032970832342652397461908326042 i')\n IF (.NOT.(ABS(Z4-Z3) < 1.0D-31)) THEN\n NERROR = NERROR + 1\n WRITE (* ,\"(/' Error in sample case number 13.'/)\")\n WRITE (KOUT,\"(/' Error in sample case number 13.'/)\")\n ENDIF\n\n\n! 14. Exception handling.\n\n! Iterate (real) exp(x) starting at 1.0 until overflow occurs.\n\n! Testing to see if a type FM number is one of the special cases (+-overflow,\n! +-underflow or unknown) by direct comparison can be tricky. When X1 is\n! +overflow, the statement\n! IF (X1 == TO_FM(' +OVERFLOW ')) THEN\n! will return false, since the comparison routine cannot be sure that two\n! different overflowed results would have been equal if the overflow threshold\n! had been higher.\n\n! Function IS_OVERFLOW can be used to directly check whether a number is + or -\n! overflow, so that is a safer test.\n\n! The FM warning message is written on unit KW, so in this test it appears on the\n! screen and not in the output file.\n\n CALL FM_SET(60)\n\n X1 = TO_FM(1)\n\n FMT = \"(///' Sample 14. Exception handling.'//12X,\" // &\n \"' Iterate exp(x) starting at 1.0 until overflow occurs.'//\" // &\n \"12X,' An FM warning message will be printed before the last iteration.')\"\n WRITE (*,FMT)\n FMT = \"(///' Sample 14. Exception handling.'//\" // &\n \"12X,' Iterate exp(x) starting at 1.0 until overflow occurs.')\"\n WRITE (KOUT,FMT)\n\n DO J = 1, 10\n X1 = EXP(X1)\n CALL FM_FORM('ES60.40',X1,ST1)\n WRITE (* ,\"(/' Iteration',I3,5X,A)\") J,TRIM(ST1)\n WRITE (KOUT,\"(/' Iteration',I3,5X,A)\") J,TRIM(ST1)\n IF (IS_OVERFLOW(X1)) EXIT\n ENDDO\n\n! Check that the last result was +overflow.\n\n IF (IS_OVERFLOW(X1)) THEN\n WRITE (* ,\"(/' Overflow was correctly detected.')\")\n WRITE (KOUT,\"(/' Overflow was correctly detected.')\")\n ELSE\n NERROR = NERROR + 1\n WRITE (* ,\"(/' Error in sample case number 14.'/)\")\n WRITE (* ,\"(/' Overflow was not correctly detected.')\")\n WRITE (KOUT ,\"(/' Error in sample case number 14.'/)\")\n WRITE (KOUT ,\"(/' Overflow was not correctly detected.')\")\n ENDIF\n\n IF (NERROR == 0) THEN\n WRITE (* ,\"(//A/)\") ' All results were ok -- no errors were found.'\n WRITE (KOUT,\"(//A/)\") ' All results were ok -- no errors were found.'\n ELSE\n WRITE (* ,\"(//I3,A/)\") NERROR,' error(s) found.'\n WRITE (KOUT,\"(//I3,A/)\") NERROR,' error(s) found.'\n ENDIF\n\n STOP\n END PROGRAM TEST\n\n SUBROUTINE PLAN_9(F,A,B,N,RESULT)\n\n! Sample subroutine usage for FM.\n\n! Integrate F(X) from A to B using N subintervals, and return the answer in RESULT.\n\n! This does numerical integration using a 9-point rule.\n! It is not a very good way to do high-precision integration, but it is a short routine\n! and can often get 20 to 30 digits if f(x) is well-behaved and the interval of integration\n! is not too big.\n\n USE FMZM\n IMPLICIT NONE\n TYPE (FM) :: A, B, RESULT\n TYPE (FM), SAVE :: H, H8, XJ\n TYPE (FM), EXTERNAL :: F\n INTEGER :: N, J\n INTENT (IN) :: N, A, B\n INTENT (INOUT) :: RESULT\n\n H = (B - A)/N\n H8 = H/8\n RESULT = 0\n DO J = 1, N\n XJ = A + (J-1)*H\n RESULT = RESULT + 989*F(XJ) + 5888*F(XJ+ H8) - 928*F(XJ+2*H8) + &\n 10496*F(XJ+3*H8) - 4540*F(XJ+4*H8) + 10496*F(XJ+5*H8) - &\n 928*F(XJ+6*H8) + 5888*F(XJ+7*H8) + 989*F(XJ+8*H8)\n ENDDO\n RESULT = H*RESULT/28350\n\n END SUBROUTINE PLAN_9\n\n FUNCTION F(X) RESULT (RETURN_VALUE)\n\n! Sample function usage for FM.\n\n! The test function for the integration subroutine is 2*exp(-x**2)/sqrt(pi).\n\n USE FMZM\n IMPLICIT NONE\n TYPE (FM) :: RETURN_VALUE, X\n TYPE (FM), SAVE :: PI\n\n! Compare the usage here with the SQRT(ACOS(TO_FM(-1))) usage in the gamma example\n! in the main program. There pi was only used once, so ACOS(TO_FM(-1)) is more like\n! what a non-multiple-precision program would do to get pi.\n\n! If we need pi in a function like F that will be called hundreds of times, the acos\n! call will be done every time. Here, since the argument is -1, the acos routine will\n! recognize it as a special case and return the saved value of pi without needlessly\n! making the program slower. But if another formula were used, like pi = 6*asin(1/2),\n! it would be better to call FM_PI, since pi would be computed only once and later calls\n! just use the saved value of pi.\n\n! Another reason to call FM_PI instead of using a formula is that in case the calling\n! program changed the trig function mode to degrees, instead of the default radians,\n! then ACOS(TO_FM(-1)) would give 180, not pi.\n\n! For this case the 2/sqrt(pi) could have been factored out of the integral so pi would\n! not be needed every time F is called, but it was left in to illustrate similar but\n! more complicated situations.\n\n CALL FM_PI(PI)\n RETURN_VALUE = 2*EXP(-X**2)/SQRT(PI)\n\n END FUNCTION F\n", "meta": {"hexsha": "f3452dce2e3298c02c58ba828f275a82b0be6c9f", "size": 30695, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Libraries/FM/SampleFM.f95", "max_stars_repo_name": "andreypudov/projecteuler", "max_stars_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2022-01-30T20:37:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T21:03:21.000Z", "max_issues_repo_path": "Libraries/FM/SampleFM.f95", "max_issues_repo_name": "andreypudov/projecteuler", "max_issues_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Libraries/FM/SampleFM.f95", "max_forks_repo_name": "andreypudov/projecteuler", "max_forks_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.2006880734, "max_line_length": 100, "alphanum_fraction": 0.5282945105, "num_tokens": 9124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037323284109, "lm_q2_score": 0.853912754810561, "lm_q1q2_score": 0.7909825718638578}} {"text": "! Created by EverLookNeverSee@GitHub on 6/1/20\n! For more information see FCS/img/Exercise_08_a.png\n\nprogram main\n implicit none\n ! declaring and initializing variables\n real :: sum = 0.0, theta = 1.57079, t = 1.0\n integer :: i = 0\n ! iterating and calculating cos serie till obtaining correct result\n do\n sum = sum + t\n i = i + 1\n t = t * (-theta * theta) / (2 * i * (2 * i - 1))\n if (sum + t == sum) exit\n end do\n ! printing results\n print *, \"Cos(\", theta, \"):\", sum\nend program main", "meta": {"hexsha": "a11941a8c1752b1e5b890d64f8296c54b2beeb18", "size": 541, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical methods/Exercise_08_a.f90", "max_stars_repo_name": "EverLookNeverSee/FCS", "max_stars_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-14T10:30:25.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-17T13:03:15.000Z", "max_issues_repo_path": "src/numerical methods/Exercise_08_a.f90", "max_issues_repo_name": "EverLookNeverSee/FCS", "max_issues_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-06-06T13:54:45.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-25T20:32:23.000Z", "max_forks_repo_path": "src/numerical methods/Exercise_08_a.f90", "max_forks_repo_name": "EverLookNeverSee/FCS", "max_forks_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-08T12:57:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T12:57:46.000Z", "avg_line_length": 30.0555555556, "max_line_length": 71, "alphanum_fraction": 0.5859519409, "num_tokens": 169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561135, "lm_q2_score": 0.853912760387131, "lm_q1q2_score": 0.7909825683432009}} {"text": "module geometry\n !! Provides routines for basic geometrical and trigonometric functions in 2D and 3D.\n \n implicit none\n\n public :: norm, distance\n \ncontains\n\n pure real function norm(p) result(d)\n !! Returns the \\(L_2\\)-norm of a vector \\(\\mathbf{p}\\),\n !! $$ \\lVert \\mathbf{p} \\rVert = \\sqrt{\\sum_{i=1}^n p_i} $$\n\n implicit none\n\n real, allocatable, intent(in) :: p(:)\n integer :: l, u, i\n \n l = lbound(p,1)\n u = ubound(p,1)\n\n d = 0.0\n do i = l, u\n d = d + p(i)**2\n end do\n\n d = sqrt(d)\n\n end function norm\n \n pure real function distance(p, q) result(d)\n !! Returns the Euclidean distance between two points \\(\\mathbf{x}\\) and \\(\\mathbf{y}\\), \n !! $$ \\lVert \\mathbf{q} - \\mathbf{p} \\rVert = \\sqrt{\\sum_{i=1}^n \\left(q_i - p_i\\right)^2} $$ \n \n implicit none\n\n real, allocatable, intent(in) :: p(:), q(:)\n integer :: l, u, i\n\n !! @todo Check rank of p vs q\n l = lbound(p,1)\n u = ubound(p,1)\n\n d = 0.0\n do i = l, u\n d = d + (q(i) - p(i))**2\n end do\n\n d = sqrt(d)\n \n end function distance\nend module geometry\n", "meta": {"hexsha": "bcc1164f68a2c76ddfba15db9f15ab8bbe235f62", "size": 1106, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/geometry.f90", "max_stars_repo_name": "ArmchairPhysicist/peano", "max_stars_repo_head_hexsha": "17b7ca6217c57063dea536e2be9c5fcd2c63b8fb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-12-15T15:22:53.000Z", "max_stars_repo_stars_event_max_datetime": "2018-04-04T02:40:08.000Z", "max_issues_repo_path": "src/geometry.f90", "max_issues_repo_name": "ArmchairPhysicist/peano", "max_issues_repo_head_hexsha": "17b7ca6217c57063dea536e2be9c5fcd2c63b8fb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/geometry.f90", "max_forks_repo_name": "ArmchairPhysicist/peano", "max_forks_repo_head_hexsha": "17b7ca6217c57063dea536e2be9c5fcd2c63b8fb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.8679245283, "max_line_length": 98, "alphanum_fraction": 0.547920434, "num_tokens": 385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029487, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7909076024455108}} {"text": "module circle\n! MODULE circle\n! This is a practise module intended for learning about modules in Fortran.\n! It contains the following subprograms :\n! CircArea : calculates a circle's area\n! CircPeri : calculates the 'perimeter' (circumference) of a circle\n\n implicit none\n real, parameter::pi=atan(1.0)*4\n \n contains\n \n ! FUNCTION CircArea\n ! Input : the circle's radius\n ! Output : the circle's area\n function circarea(radius) result(area)\n real,intent(in)::radius\n real::area\n \n area = pi * radius * radius\n return\n end function circarea\n \n ! FUNCTION CircPeri\n ! Input : the circle's radius\n ! Output : the circle's circumference\n function circperi(radius) result(circumference)\n real,intent(in)::radius\n real::circumference\n \n circumference = 2 * pi * radius\n return\n end function circperi\n\nend module circle\n", "meta": {"hexsha": "af2853f58aaeff6c82da79f1522d5d0928c6c530", "size": 863, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "modules/circle.f90", "max_stars_repo_name": "muxwan/fortrite", "max_stars_repo_head_hexsha": "2c28c8bb3b3366dbc0e6e21b92ca0668fa3b292e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "modules/circle.f90", "max_issues_repo_name": "muxwan/fortrite", "max_issues_repo_head_hexsha": "2c28c8bb3b3366dbc0e6e21b92ca0668fa3b292e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "modules/circle.f90", "max_forks_repo_name": "muxwan/fortrite", "max_forks_repo_head_hexsha": "2c28c8bb3b3366dbc0e6e21b92ca0668fa3b292e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.9722222222, "max_line_length": 75, "alphanum_fraction": 0.6998841251, "num_tokens": 223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966702001758, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7908659322903813}} {"text": "program MC_ex01_p04_Buffon\r\n use mc_randoms\r\n implicit none\r\n real,parameter :: pi=4.0*atan(1.0)\r\n integer::seed=13,iarg,j,k,n,hits\r\n real(8)::result,l=2,d=10,error=0\r\n character(len=80)::arg\r\n\r\n !RNG seed from arguments, default seed 13\r\n iarg=command_argument_count()\r\n if (iarg==1) then\r\n call get_command_argument(1,arg)\r\n read(arg,*) seed\r\n end if\r\n\r\n call seed_lcg(int(seed,ik))\r\n\r\n !Simulation part\r\n n=10000\r\n !Do 100 simulations with the new throw count\r\n do j=1,100\r\n !Simulate a single set of throws\r\n hits=0\r\n do k=1,n\r\n hits=hits+throw()\r\n end do\r\n if(hits==0) then\r\n result=0\r\n else\r\n result=n*2*l/(d*hits)\r\n end if\r\n error=error+abs(result-pi)\r\n end do\r\n error=error/100\r\n\r\n print*,\"Error: \",error\r\n\r\n\r\ncontains\r\n integer function throw()\r\n implicit none\r\n real(rk)::y,alpha\r\n !Randomize the position and the angle of the needle.\r\n !It's only necessary to look at the other half of the throwing space, since the situation can always be mirrored\r\n y=rand_lcg()*d/2\r\n alpha=rand_lcg()*pi/2\r\n !Check if the end of the needle crosses a line\r\n if (l/2*sin(alpha)>=y) then\r\n throw=1\r\n else\r\n throw=0\r\n end if\r\n end function\r\n\r\nend program MC_ex01_p04_Buffon", "meta": {"hexsha": "4337071693c65926c43313984ca1925b8f682189", "size": 1421, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Nico_Toikka_ex1/p04/buffon/ex04_buffon.f95", "max_stars_repo_name": "toicca/basics-of-mc", "max_stars_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Nico_Toikka_ex1/p04/buffon/ex04_buffon.f95", "max_issues_repo_name": "toicca/basics-of-mc", "max_issues_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Nico_Toikka_ex1/p04/buffon/ex04_buffon.f95", "max_forks_repo_name": "toicca/basics-of-mc", "max_forks_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.8363636364, "max_line_length": 121, "alphanum_fraction": 0.5679099226, "num_tokens": 396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653856, "lm_q2_score": 0.8376199714402813, "lm_q1q2_score": 0.7908613935573988}} {"text": "! Created by EverLookNeverSee@GitHub on 6/11/20\n! For more information see FCS/img/Exercise_13.png\n\nprogram main\n implicit none\n ! declaring variables\n integer :: n, i, j\n real :: tmp_1, tmp_2, tmp_3, tmp_4, tmp_5, corr, numerator, denominator\n real, allocatable, dimension(:) :: x, y\n ! initializing temporary variables\n tmp_1 = 0.0; tmp_2 = 0.0; tmp_3 = 0.0; tmp_4 = 0.0; tmp_5 = 0.0\n ! specifying number of elements in sets\n do\n print *, \"Enter the number of elements in sets:\"\n read *, n\n if (n <= 0) then\n print *, \"You should enter a positive integer number!\"\n cycle\n else\n exit\n end if\n end do\n ! allocating memory space to arrays\n allocate(x(n))\n allocate(y(n))\n ! assigning values to sets using user input\n ! x set\n do i = 1, n\n print *, \"x(\", i, \"):\"\n read *, x(i)\n end do\n ! y set\n do j = 1, n\n print *, \"y(\", j, \"):\"\n read *, y(j)\n end do\n ! --------------------------------------------------------------------\n ! tmp_1\n do i = 1, n\n tmp_1 = tmp_1 + (x(i) * y(i))\n end do\n ! tmp_2\n do i = 1, n\n tmp_2 = tmp_2 + x(i)\n end do\n ! tmp_3\n do i = 1, n\n tmp_3 = tmp_3 + y(i)\n end do\n ! tmp_4\n do i = 1, n\n tmp_4 = tmp_4 + x(i) ** 2\n end do\n ! tmp_5\n do i = 1, n\n tmp_5 = tmp_5 + y(i) ** 2\n end do\n ! --------------------------------------------------------------------\n ! calculating the numerator\n numerator = (n * tmp_1) - (tmp_2 * tmp_3)\n ! calculating denominator\n denominator = sqrt(n * tmp_4 - tmp_2 ** 2) * sqrt(n * tmp_5 - tmp_3 ** 2)\n ! calculating correlation coefficient\n corr = numerator / denominator\n ! printing result\n print *, \"Correletion coefficient:\", corr\nend program main", "meta": {"hexsha": "ac19cede0022dab74313693a082cfb72e8ad8dc7", "size": 1863, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical methods/Exercise_13.f90", "max_stars_repo_name": "EverLookNeverSee/FCS", "max_stars_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-14T10:30:25.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-17T13:03:15.000Z", "max_issues_repo_path": "src/numerical methods/Exercise_13.f90", "max_issues_repo_name": "EverLookNeverSee/FCS", "max_issues_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-06-06T13:54:45.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-25T20:32:23.000Z", "max_forks_repo_path": "src/numerical methods/Exercise_13.f90", "max_forks_repo_name": "EverLookNeverSee/FCS", "max_forks_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-08T12:57:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T12:57:46.000Z", "avg_line_length": 27.8059701493, "max_line_length": 77, "alphanum_fraction": 0.4970477724, "num_tokens": 584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455085, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.7907951505888614}} {"text": " function dzasum ( n, zx, incx )\n\nc*********************************************************************72\nc\ncc DZASUM takes the sum of the absolute values.\nc\nc Discussion:\nc\nc This routine uses double precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vector.\nc\nc Input, double complex X(*), the vector.\nc\nc Input, integer INCX, the increment between successive entries of X.\nc\nc Output, double precision DZASUM, the sum of the absolute values.\nc\n implicit none\n\n double precision dzasum\n integer i\n integer incx\n integer ix\n integer n\n double precision stemp\n double precision zabs1\n double complex zx(*)\n\n dzasum = 0.0d0\n stemp = 0.0d0\n if( n.le.0 .or. incx.le.0 )return\n if(incx.eq.1)go to 20\nc\nc code for increment not equal to 1\nc\n ix = 1\n do i = 1,n\n stemp = stemp + zabs1(zx(ix))\n ix = ix + incx\n end do\n dzasum = stemp\n return\nc\nc code for increment equal to 1\nc\n 20 do i = 1,n\n stemp = stemp + zabs1(zx(i))\n end do\n dzasum = stemp\n return\n end\n function dznrm2 ( n, x, incx )\n\nc*********************************************************************72\nc\ncc DZNRM2 returns the euclidean norm of a vector.\nc\nc Discussion:\nc\nc This routine uses double precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Sven Hammarling\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vector.\nc\nc Input, double complex X(*), the vector.\nc\nc Input, integer INCX, the increment between successive entries of X.\nc\nc Output, double precision DZNRM2, the norm of the vector.\nc\n implicit none\n\n integer incx, n\n double complex x( * )\n\n\n double precision one , zero\n parameter ( one = 1.0d+0, zero = 0.0d+0 )\n\n double precision dznrm2\n integer ix\n double precision norm, scale, ssq, temp\n\n intrinsic abs, dimag, dble, sqrt\n\n if( n.lt.1 .or. incx.lt.1 )then\n norm = zero\n else\n scale = zero\n ssq = one\n\n do ix = 1, 1 + ( n - 1 )*incx, incx\n if( dble( x( ix ) ).ne.zero )then\n temp = abs( dble( x( ix ) ) )\n if( scale.lt.temp )then\n ssq = one + ssq*( scale/temp )**2\n scale = temp\n else\n ssq = ssq + ( temp/scale )**2\n end if\n end if\n if( dimag( x( ix ) ).ne.zero )then\n temp = abs( dimag( x( ix ) ) )\n if( scale.lt.temp )then\n ssq = one + ssq*( scale/temp )**2\n scale = temp\n else\n ssq = ssq + ( temp/scale )**2\n end if\n end if\n end do\n norm = scale * sqrt( ssq )\n end if\n\n dznrm2 = norm\n\n return\n end\n function izamax ( n, zx, incx )\n\nc*********************************************************************72\nc\ncc IZAMAX finds the index of element having maximum absolute value.\nc\nc Discussion:\nc\nc This routine uses double precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vector.\nc\nc Input, double complex X(*), the vector.\nc\nc Input, integer INCX, the increment between successive entries of X.\nc\nc Output, integer IZAMAX, the index of the element of maximum\nc absolute value.\nc\n implicit none\n\n integer izamax\n double complex zx(*)\n double precision smax\n integer i,incx,ix,n\n double precision zabs1\n\n izamax = 0\n if( n.lt.1 .or. incx.le.0 )return\n izamax = 1\n if(n.eq.1)return\n if(incx.eq.1)go to 20\nc\nc code for increment not equal to 1\nc\n ix = 1\n smax = zabs1(zx(1))\n ix = ix + incx\n do i = 2,n\n if ( smax .lt. zabs1(zx(ix)) ) then\n izamax = i\n smax = zabs1(zx(ix))\n end if\n ix = ix + incx\n end do\n return\nc\nc code for increment equal to 1\nc\n 20 smax = zabs1(zx(1))\n do i = 2,n\n if ( smax .lt. zabs1(zx(i)) ) then\n izamax = i\n smax = zabs1(zx(i))\n end if\n end do\n\n return\n end\n subroutine zaxpy ( n, za, zx, incx, zy, incy )\n\nc*********************************************************************72\nc\ncc ZAXPY computes constant times a vector plus a vector.\nc\nc Discussion:\nc\nc This routine uses double precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of elements in CX and CY.\nc\nc Input, double complex CA, the multiplier of CX.\nc\nc Input, double complex CX(*), the first vector.\nc\nc Input, integer INCX, the increment between successive entries of CX.\nc\nc Input/output, double complex CY(*), the second vector.\nc On output, CY(*) has been replaced by CY(*) + CA * CX(*).\nc\nc Input, integer INCY, the increment between successive entries of CY.\nc\n implicit none\n\n double complex zx(*),zy(*),za\n integer i,incx,incy,ix,iy,n\n double precision zabs1\n if(n.le.0)return\n if (zabs1(za) .eq. 0.0d0) return\n if (incx.eq.1.and.incy.eq.1)go to 20\nc\nc code for unequal increments or equal increments\nc not equal to 1\nc\n ix = 1\n iy = 1\n if(incx.lt.0)ix = (-n+1)*incx + 1\n if(incy.lt.0)iy = (-n+1)*incy + 1\n do i = 1,n\n zy(iy) = zy(iy) + za*zx(ix)\n ix = ix + incx\n iy = iy + incy\n end do\n return\nc\nc code for both increments equal to 1\nc\n 20 do i = 1,n\n zy(i) = zy(i) + za*zx(i)\n end do\n return\n end\n subroutine zcopy ( n, zx, incx, zy, incy )\n\nc*********************************************************************72\nc\ncc ZCOPY copies a vector, x, to a vector, y.\nc\nc Discussion:\nc\nc This routine uses double precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of elements in CX and CY.\nc\nc Input, double complex CX(*), the first vector.\nc\nc Input, integer INCX, the increment between successive entries of CX.\nc\nc Output, double complex CY(*), the second vector.\nc\nc Input, integer INCY, the increment between successive entries of CY.\nc\n implicit none\n\n double complex zx(*),zy(*)\n integer i,incx,incy,ix,iy,n\nc\n if(n.le.0)return\n if(incx.eq.1.and.incy.eq.1)go to 20\nc\nc code for unequal increments or equal increments\nc not equal to 1\nc\n ix = 1\n iy = 1\n if(incx.lt.0)ix = (-n+1)*incx + 1\n if(incy.lt.0)iy = (-n+1)*incy + 1\n do i = 1,n\n zy(iy) = zx(ix)\n ix = ix + incx\n iy = iy + incy\n end do\n return\nc\nc code for both increments equal to 1\nc\n 20 do i = 1,n\n zy(i) = zx(i)\n end do\n\n return\n end\n function zdotc ( n, zx, incx, zy, incy )\n\nc*********************************************************************72\nc\ncc ZDOTC forms the dot product of a vector.\nc\nc Discussion:\nc\nc This routine uses double precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vectors.\nc\nc Input, double complex CX(*), the first vector.\nc\nc Input, integer INCX, the increment between successive entries in CX.\nc\nc Input, double complex CY(*), the second vector.\nc\nc Input, integer INCY, the increment between successive entries in CY.\nc\nc Output, double complex ZDOTC, the conjugated dot product of \nc the corresponding entries of CX and CY.\nc\n implicit none\n\n double complex zx(*),zy(*),ztemp\n double complex zdotc\n integer i,incx,incy,ix,iy,n\n\n ztemp = (0.0d0,0.0d0)\n zdotc = (0.0d0,0.0d0)\n if(n.le.0)return\n if(incx.eq.1.and.incy.eq.1)go to 20\nc\nc code for unequal increments or equal increments\nc not equal to 1\nc\n ix = 1\n iy = 1\n if(incx.lt.0)ix = (-n+1)*incx + 1\n if(incy.lt.0)iy = (-n+1)*incy + 1\n do i = 1,n\n ztemp = ztemp + dconjg(zx(ix))*zy(iy)\n ix = ix + incx\n iy = iy + incy\n end do\n zdotc = ztemp\n return\nc\nc code for both increments equal to 1\nc\n 20 do i = 1,n\n ztemp = ztemp + dconjg(zx(i))*zy(i)\n end do\n\n zdotc = ztemp\n\n return\n end\n function zdotu ( n, zx, incx, zy, incy )\n\nc*********************************************************************72\nc\ncc ZDOTU forms the dot product of two vectors.\nc\nc Discussion:\nc\nc This routine uses double precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vectors.\nc\nc Input, double complex CX(*), the first vector.\nc\nc Input, integer INCX, the increment between successive entries in CX.\nc\nc Input, double complex CY(*), the second vector.\nc\nc Input, integer INCY, the increment between successive entries in CY.\nc\nc Output, double complex ZDOTU, the unconjugated dot product of \nc the corresponding entries of CX and CY.\nc\n implicit none\n\n double complex zx(*),zy(*),ztemp\n double complex zdotu\n integer i,incx,incy,ix,iy,n\n\n ztemp = (0.0d0,0.0d0)\n zdotu = (0.0d0,0.0d0)\n if(n.le.0)return\n if(incx.eq.1.and.incy.eq.1)go to 20\nc\nc code for unequal increments or equal increments\nc not equal to 1\nc\n ix = 1\n iy = 1\n if(incx.lt.0)ix = (-n+1)*incx + 1\n if(incy.lt.0)iy = (-n+1)*incy + 1\n do i = 1,n\n ztemp = ztemp + zx(ix)*zy(iy)\n ix = ix + incx\n iy = iy + incy\n end do\n zdotu = ztemp\n return\nc\nc code for both increments equal to 1\nc\n 20 do i = 1,n\n ztemp = ztemp + zx(i)*zy(i)\n end do\n\n zdotu = ztemp\n\n return\n end\n subroutine zdrot ( n, zx, incx, zy, incy, c, s )\n\nc*********************************************************************72\nc\ncc ZDROT applies a plane rotation.\nc\nc Discussion:\nc\nc The cos and sin (c and s) are double precision and the vectors \nc zx and zy are double complex.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vectors.\nc\nc Input/output, double complex CX(*), one of the vectors to be rotated.\nc\nc Input, integer INCX, the increment between successive entries of CX.\nc\nc Input/output, double complex CY(*), one of the vectors to be rotated.\nc\nc Input, integer INCY, the increment between successive elements of CY.\nc\nc Input, double precision C, S, parameters (presumably the cosine and \nc sine of some angle) that define a plane rotation.\nc\n implicit none\n\n double complex zx(1),zy(1),ztemp\n double precision c,s\n integer i,incx,incy,ix,iy,n\n\n if(n.le.0)return\n if(incx.eq.1.and.incy.eq.1)go to 20\nc\nc code for unequal increments or equal increments not equal\nc to 1\nc\n ix = 1\n iy = 1\n if(incx.lt.0)ix = (-n+1)*incx + 1\n if(incy.lt.0)iy = (-n+1)*incy + 1\n do i = 1,n\n ztemp = c*zx(ix) + s*zy(iy)\n zy(iy) = c*zy(iy) - s*zx(ix)\n zx(ix) = ztemp\n ix = ix + incx\n iy = iy + incy\n end do\n return\nc\nc code for both increments equal to 1\nc\n 20 do i = 1,n\n ztemp = c*zx(i) + s*zy(i)\n zy(i) = c*zy(i) - s*zx(i)\n zx(i) = ztemp\n end do\n\n return\n end\n subroutine zdscal ( n, da, zx, incx )\n\nc*********************************************************************72\nc\ncc ZDSCAL scales a vector by a constant.\nc\nc Discussion:\nc\nc This routine uses double precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vector.\nc\nc Input, double precision SA, the multiplier.\nc\nc Input/output, double complex CX(*), the vector to be scaled.\nc\nc Input, integer INCX, the increment between successive entries of \nc the vector CX.\nc\n implicit none\n\n double precision da\n integer i\n integer incx\n integer ix\n integer n\n double complex zx(*)\n\n if ( n .le. 0 .or. incx .le. 0 ) then\n return\n end if\n\n if ( incx .eq. 1 ) then\n\n do i = 1, n\n zx(i) = dcmplx ( da, 0.0d0 ) * zx(i)\n end do\n\n else\n\n ix = 1\n do i = 1, n\n zx(ix) = dcmplx ( da, 0.0d0 ) * zx(ix)\n ix = ix + incx\n end do\n\n end if\n\n return\n end\n subroutine zrotg ( ca, cb, c, s )\n\nc*********************************************************************72\nc\ncc ZROTG generates a Givens rotation.\nc\nc Discussion:\nc\nc This routine uses double precision complex arithmetic.\nc\nc Given values A and B, this routine computes:\nc\nc If A = 0:\nc\nc R = B\nc C = 0\nc S = (1,0).\nc\nc If A /= 0:\nc\nc ALPHA = A / abs ( A )\nc NORM = sqrt ( ( abs ( A ) )^2 + ( abs ( B ) )^2 )\nc R = ALPHA * NORM\nc C = abs ( A ) / NORM\nc S = ALPHA * conj ( B ) / NORM\nc\nc In either case, the computed numbers satisfy the equation:\nc\nc ( C S ) * ( A ) = ( R )\nc ( -conj ( S ) C ) ( B ) = ( 0 )\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input/output, double complex CA, on input, the value A. On output,\nc the value R.\nc\nc Input, double complex CB, the value B.\nc\nc Output, double precision C, the cosine of the \nc Givens rotation.\nc\nc Output, double complex S, the sine of the \nc Givens rotation.\nc\n implicit none\n\n double complex ca,cb,s\n double precision c\n double precision norm,scale\n double complex alpha\n\n if (cdabs(ca) .eq. 0.0d0) then\n c = 0.0d0\n s = (1.0d0,0.0d0)\n ca = cb\n else\n scale = cdabs(ca) + cdabs(cb)\n norm = scale*dsqrt((cdabs(ca/dcmplx(scale,0.0d0)))**2 +\n & (cdabs(cb/dcmplx(scale,0.0d0)))**2)\n alpha = ca /cdabs(ca)\n c = cdabs(ca) / norm\n s = alpha * dconjg(cb) / norm\n ca = alpha * norm\n end if\n\n return\n end\n subroutine zscal ( n, za, zx, incx )\n\nc*********************************************************************72\nc\ncc ZSCAL scales a vector by a constant.\nc\nc Discussion:\nc\nc This routine uses double precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vector.\nc\nc Input, double complex CA, the multiplier.\nc\nc Input/output, double complex CX(*), the vector to be scaled.\nc\nc Input, integer INCX, the increment between successive entries of CX.\nc\n implicit none\n\n double complex za,zx(*)\n integer i,incx,ix,n\n\n if( n.le.0 .or. incx.le.0 )return\n if(incx.eq.1)go to 20\nc\nc code for increment not equal to 1\nc\n ix = 1\n do i = 1,n\n zx(ix) = za*zx(ix)\n ix = ix + incx\n end do\n\n return\nc\nc code for increment equal to 1\nc\n 20 do i = 1,n\n zx(i) = za*zx(i)\n end do\n\n return\n end\n subroutine zswap ( n, zx, incx, zy, incy )\n\nc*********************************************************************72\nc\ncc ZSWAP interchanges two vectors.\nc\nc Discussion:\nc\nc This routine uses double precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vectors.\nc\nc Input/output, double complex CX(*), one of the vectors to swap.\nc\nc Input, integer INCX, the increment between successive entries of CX.\nc\nc Input/output, double complex CY(*), one of the vectors to swap.\nc\nc Input, integer INCY, the increment between successive elements of CY.\nc\n implicit none\n\n double complex zx(*),zy(*),ztemp\n integer i,incx,incy,ix,iy,n\n\n if(n.le.0)return\n if(incx.eq.1.and.incy.eq.1)go to 20\nc\nc code for unequal increments or equal increments not equal\nc to 1\nc\n ix = 1\n iy = 1\n if(incx.lt.0)ix = (-n+1)*incx + 1\n if(incy.lt.0)iy = (-n+1)*incy + 1\n do i = 1,n\n ztemp = zx(ix)\n zx(ix) = zy(iy)\n zy(iy) = ztemp\n ix = ix + incx\n iy = iy + incy\n end do\n\n return\nc\nc code for both increments equal to 1\nc\n 20 do i = 1,n\n ztemp = zx(i)\n zx(i) = zy(i)\n zy(i) = ztemp\n end do\n\n return\n end\n", "meta": {"hexsha": "b67eb60cdff444b8ad3820bb656e0549e725160e", "size": 21742, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "blas1_z/blas1_z.f", "max_stars_repo_name": "SourangshuGhosh/Basic-Linear-Algebra-Subprograms", "max_stars_repo_head_hexsha": "5b8b011a1acac19193203c54a97ebeed56fed6d3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-07-29T09:14:47.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-14T17:38:52.000Z", "max_issues_repo_path": "blas1_z/blas1_z.f", "max_issues_repo_name": "SourangshuGhosh/Basic-Linear-Algebra-Subprograms", "max_issues_repo_head_hexsha": "5b8b011a1acac19193203c54a97ebeed56fed6d3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "blas1_z/blas1_z.f", "max_forks_repo_name": "SourangshuGhosh/Basic-Linear-Algebra-Subprograms", "max_forks_repo_head_hexsha": "5b8b011a1acac19193203c54a97ebeed56fed6d3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.9345991561, "max_line_length": 74, "alphanum_fraction": 0.5806733511, "num_tokens": 6915, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487572, "lm_q2_score": 0.9099070048165069, "lm_q1q2_score": 0.7905515603998367}} {"text": "subroutine fem1d_heat_steady ( n, a, b, ua, ub, k, f, x, u )\n\n!*****************************************************************************80\n!\n!! FEM1D_HEAT_STEADY solves the steady 1D heat equation with finite elements.\n!\n! Discussion:\n!\n! The program uses the finite element method, with piecewise linear basis\n! functions to solve the steady state heat equation in one dimension.\n!\n! The problem is defined on the region A <= x <= B.\n!\n! The following differential equation is imposed between A and B:\n!\n! - d/dx k(x) du/dx = f(x)\n!\n! where k(x) and f(x) are given functions.\n!\n! At the boundaries, the following conditions are applied:\n!\n! u(A) = UA\n! u(B) = UB\n!\n! A set of N equally spaced nodes is defined on this\n! interval, with A = X(1) < X(2) < ... < X(N) = B.\n!\n! At each node I, we associate a piecewise linear basis function V(I,X),\n! which is 0 at all nodes except node I. This implies that V(I,X) is\n! everywhere 0 except that\n!\n! for X(I-1) <= X <= X(I):\n!\n! V(I,X) = ( X - X(I-1) ) / ( X(I) - X(I-1) ) \n!\n! for X(I) <= X <= X(I+1):\n!\n! V(I,X) = ( X(I+1) - X ) / ( X(I+1) - X(I) )\n!\n! We now assume that the solution U(X) can be written as a linear\n! sum of these basis functions:\n!\n! U(X) = sum ( 1 <= J <= N ) U(J) * V(J,X)\n!\n! where U(X) on the left is the function of X, but on the right,\n! is meant to indicate the coefficients of the basis functions.\n!\n! To determine the coefficient U(J), we multiply the original\n! differential equation by the basis function V(J,X), and use\n! integration by parts, to arrive at the I-th finite element equation:\n!\n! Integral K(X) * U'(X) * V'(I,X) dx = Integral F(X) * V(I,X) dx\n!\n! We note that the functions U(X) and U'(X) can be replaced by\n! the finite element form involving the linear sum of basis functions,\n! but we also note that the resulting integrand will only be nonzero\n! for terms where J = I - 1, I, or I + 1.\n!\n! By writing this equation for basis functions I = 2 through N - 1,\n! and using the boundary conditions, we have N linear equations\n! for the N unknown coefficients U(1) through U(N), which can\n! be easily solved.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 07 April 2011\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of nodes.\n!\n! Input, real ( kind = 8 ) A, B, the left and right endpoints.\n!\n! Input, real ( kind = 8 ) UA, UB, the prescribed value of U at A and B.\n!\n! Input, external K, a function which evaluates k(x);\n!\n! Input, external F, a function which evaluates f(x);\n!\n! Input, real ( kind = 8 ) X(N), the mesh points.\n!\n! Output, real ( kind = 8 ) U(N), the finite element coefficients, which \n! are also the value of the computed solution at the mesh points.\n!\n implicit none\n\n integer ( kind = 4 ) n\n integer ( kind = 4 ), parameter :: quad_num = 2\n\n real ( kind = 8 ) a\n real ( kind = 8 ) abscissa(quad_num)\n real ( kind = 8 ) al\n real ( kind = 8 ) am\n real ( kind = 8 ) ar\n real ( kind = 8 ) amat(n,n)\n real ( kind = 8 ) b\n real ( kind = 8 ) bm\n real ( kind = 8 ) bvec(n)\n real ( kind = 8 ), external :: f\n real ( kind = 8 ) fxq\n integer ( kind = 4 ) i\n integer ( kind = 4 ) ierror\n real ( kind = 8 ), external :: k\n real ( kind = 8 ) kxq\n integer ( kind = 4 ) q\n real ( kind = 8 ) weight(quad_num)\n real ( kind = 8 ) wq\n real ( kind = 8 ) u(n)\n real ( kind = 8 ) ua\n real ( kind = 8 ) ub\n real ( kind = 8 ) vl\n real ( kind = 8 ) vlp\n real ( kind = 8 ) vm\n real ( kind = 8 ) vmp\n real ( kind = 8 ) vr\n real ( kind = 8 ) vrp\n real ( kind = 8 ) x(n)\n real ( kind = 8 ) xl\n real ( kind = 8 ) xm\n real ( kind = 8 ) xq\n real ( kind = 8 ) xr\n!\n! Define a quadrature rule on the interval [-1,+1].\n!\n abscissa(1) = -0.577350269189625764509148780502D+00\n abscissa(2) = +0.577350269189625764509148780502D+00\n weight(1) = 1.0D+00\n weight(2) = 1.0D+00\n!\n! Zero out the matrix and right hand side.\n!\n amat(1:n,1:n) = 0.0D+00\n bvec(1:n) = 0.0D+00\n!\n! Equation 1 is the left boundary condition, U(A) = UA;\n!\n amat(1,1) = 1.0D+00\n bvec(1) = ua\n!\n! Equation I involves the basis function at node I.\n! This basis function is nonzero from X(I-1) to X(I+1).\n! Equation I looks like this:\n!\n! Integral K(X) U'(X) V'(I,X) \n! + C(X) * U(X) V(I,X) dx \n! = Integral F(X) V(I,X) dx\n!\n! Then, we realize that U(X) = sum ( 1 <= J <= N ) U(J) * V(J,X), \n! (U(X) means the function; U(J) is the coefficient of V(J,X) ).\n!\n! The only V functions that are nonzero when V(I,X) is nonzero are\n! V(I-1,X) and V(I+1,X). \n!\n! Let's use the shorthand \n!\n! VL(X) = V(I-1,X)\n! VM(X) = V(I,X)\n! VR(X) = V(I+1,X)\n!\n! So our equation becomes\n!\n! Integral K(X) [ VL'(X) U(I-1) + VM'(X) U(I) + VR'(X) U(I+1) ] * VM'(X) dx\n! = Integral F(X) VM(X) dx.\n!\n! \n!\n! This is actually a set of N-2 linear equations for the N coefficients U.\n!\n! Now gather the multipliers of U(I-1) to get the matrix entry A(I,I-1), \n! and so on.\n!\n do i = 2, n - 1\n!\n! Get the left, right and middle coordinates.\n!\n xl = x(i-1)\n xm = x(i)\n xr = x(i+1)\n!\n! Make temporary variables for A(I,I-1), A(I,I), A(I,I+1) and B(I).\n!\n al = 0.0D+00\n am = 0.0D+00\n ar = 0.0D+00\n bm = 0.0D+00\n!\n! We approximate the integrals by using a weighted sum of\n! the integrand values at quadrature points.\n!\n do q = 1, quad_num\n!\n! Integrate over the LEFT interval, between XL and XM, where:\n!\n! VL(X) = ( XM - X ) / ( XM - XL )\n! VM(X) = ( X - XL ) / ( XM - XL )\n! VR(X) = 0\n!\n! VL'(X) = - 1 / ( XM - XL )\n! VM'(X) = + 1 / ( XM - XL ) \n! VR'(X) = 0\n!\n xq = ( ( 1.0D+00 - abscissa(q) ) * xl &\n + ( 1.0D+00 + abscissa(q) ) * xm ) &\n / 2.0D+00\n\n wq = weight(q) * ( xm - xl ) / 2.0D+00\n\n vl = ( xm - xq ) / ( xm - xl )\n vlp = - 1.0D+00 / ( xm - xl )\n\n vm = ( xq - xl ) / ( xm - xl )\n vmp = + 1.0D+00 / ( xm - xl )\n\n vr = 0.0D+00\n vrp = 0.0D+00\n\n kxq = k ( xq )\n fxq = f ( xq )\n\n al = al + wq * ( kxq * vlp * vmp )\n am = am + wq * ( kxq * vmp * vmp )\n ar = ar + wq * ( kxq * vrp * vmp )\n bm = bm + wq * ( fxq * vm )\n!\n! Integrate over the RIGHT interval, between XM and XR, where:\n!\n! VL(X) = 0\n! VM(X) = ( XR - X ) / ( XR - XM )\n! VR(X) = ( X - XM ) / ( XR - XM )\n!\n! VL'(X) = 0\n! VM'(X) = - 1 / ( XR - XM )\n! VR'(X) = + 1 / ( XR - XM ) \n!\n xq = ( ( 1.0D+00 - abscissa(q) ) * xm &\n + ( 1.0D+00 + abscissa(q) ) * xr ) &\n / 2.0D+00\n\n wq = weight(q) * ( xr - xm ) / 2.0D+00\n\n vl = 0.0D+00\n vlp = 0.0D+00\n\n vm = ( xr - xq ) / ( xr - xm )\n vmp = - 1.0D+00 / ( xr - xm )\n\n vr = ( xq - xm ) / ( xr - xm )\n vrp = 1.0D+00 / ( xr - xm )\n\n kxq = k ( xq )\n fxq = f ( xq )\n\n al = al + wq * ( kxq * vlp * vmp )\n am = am + wq * ( kxq * vmp * vmp )\n ar = ar + wq * ( kxq * vrp * vmp )\n bm = bm + wq * ( fxq * vm )\n\n end do\n\n amat(i,i-1) = al\n amat(i,i) = am\n amat(i,i+1) = ar\n bvec(i) = bm\n\n end do\n!\n! Equation N is the right boundary condition, U(B) = UB;\n!\n amat(n,n) = 1.0D+00\n bvec(n) = ub\n!\n! Solve the linear system.\n!\n! call r8mat_print ( n, n, amat, ' Matrix A:' )\n\n call r8mat_solve2 ( n, amat, bvec, u, ierror )\n\n return\nend\nsubroutine r8mat_print ( m, n, a, title )\n\n!*****************************************************************************80\n!\n!! R8MAT_PRINT prints an R8MAT.\n!\n! Discussion:\n!\n! An R8MAT is an array of R8 values.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, the number of rows in A.\n!\n! Input, integer ( kind = 4 ) N, the number of columns in A.\n!\n! Input, real ( kind = 8 ) A(M,N), the matrix.\n!\n! Input, character ( len = * ) TITLE, a title.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(m,n)\n character ( len = * ) title\n\n call r8mat_print_some ( m, n, a, 1, 1, m, n, title )\n\n return\nend\nsubroutine r8mat_print_some ( m, n, a, ilo, jlo, ihi, jhi, title )\n\n!*****************************************************************************80\n!\n!! R8MAT_PRINT_SOME prints some of an R8MAT.\n!\n! Discussion:\n!\n! An R8MAT is an array of R8 values.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 September 2009\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the number of rows and columns.\n!\n! Input, real ( kind = 8 ) A(M,N), an M by N matrix to be printed.\n!\n! Input, integer ( kind = 4 ) ILO, JLO, the first row and column to print.\n!\n! Input, integer ( kind = 4 ) IHI, JHI, the last row and column to print.\n!\n! Input, character ( len = * ) TITLE, a title.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: incx = 5\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(m,n)\n character ( len = 14 ) ctemp(incx)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i2hi\n integer ( kind = 4 ) i2lo\n integer ( kind = 4 ) ihi\n integer ( kind = 4 ) ilo\n integer ( kind = 4 ) inc\n integer ( kind = 4 ) j\n integer ( kind = 4 ) j2\n integer ( kind = 4 ) j2hi\n integer ( kind = 4 ) j2lo\n integer ( kind = 4 ) jhi\n integer ( kind = 4 ) jlo\n character ( len = * ) title\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n\n if ( m <= 0 .or. n <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' (None)'\n return\n end if\n\n do j2lo = max ( jlo, 1 ), min ( jhi, n ), incx\n\n j2hi = j2lo + incx - 1\n j2hi = min ( j2hi, n )\n j2hi = min ( j2hi, jhi )\n\n inc = j2hi + 1 - j2lo\n\n write ( *, '(a)' ) ' '\n\n do j = j2lo, j2hi\n j2 = j + 1 - j2lo\n write ( ctemp(j2), '(i8,6x)' ) j\n end do\n\n write ( *, '('' Col '',5a14)' ) ctemp(1:inc)\n write ( *, '(a)' ) ' Row'\n write ( *, '(a)' ) ' '\n\n i2lo = max ( ilo, 1 )\n i2hi = min ( ihi, m )\n\n do i = i2lo, i2hi\n\n do j2 = 1, inc\n\n j = j2lo - 1 + j2\n\n if ( a(i,j) == real ( int ( a(i,j) ), kind = 8 ) ) then\n write ( ctemp(j2), '(f8.0,6x)' ) a(i,j)\n else\n write ( ctemp(j2), '(g14.6)' ) a(i,j)\n end if\n\n end do\n\n write ( *, '(i5,a,5a14)' ) i, ':', ( ctemp(j), j = 1, inc )\n\n end do\n\n end do\n\n return\nend\nsubroutine r8mat_solve2 ( n, a, b, x, ierror )\n\n!*****************************************************************************80\n!\n!! R8MAT_SOLVE2 computes the solution of an N by N linear system.\n!\n! Discussion:\n!\n! An R8MAT is an array of R8 values.\n!\n! The linear system may be represented as\n!\n! A*X = B\n!\n! If the linear system is singular, but consistent, then the routine will\n! still produce a solution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 29 October 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of equations.\n!\n! Input/output, real ( kind = 8 ) A(N,N).\n! On input, A is the coefficient matrix to be inverted.\n! On output, A has been overwritten.\n!\n! Input/output, real ( kind = 8 ) B(N).\n! On input, B is the right hand side of the system.\n! On output, B has been overwritten.\n!\n! Output, real ( kind = 8 ) X(N), the solution of the linear system.\n!\n! Output, integer ( kind = 4 ) IERROR.\n! 0, no error detected.\n! 1, consistent singularity.\n! 2, inconsistent singularity.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n,n)\n real ( kind = 8 ) amax\n real ( kind = 8 ) b(n)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) ierror\n integer ( kind = 4 ) imax\n integer ( kind = 4 ) ipiv(n)\n integer ( kind = 4 ) j\n integer ( kind = 4 ) k\n real ( kind = 8 ) x(n)\n\n ierror = 0\n\n ipiv(1:n) = 0\n x(1:n) = 0.0D+00\n!\n! Process the matrix.\n!\n do k = 1, n\n!\n! In column K:\n! Seek the row IMAX with the properties that:\n! IMAX has not already been used as a pivot;\n! A(IMAX,K) is larger in magnitude than any other candidate.\n!\n amax = 0.0D+00\n imax = 0\n do i = 1, n\n if ( ipiv(i) == 0 ) then\n if ( amax < abs ( a(i,k) ) ) then\n imax = i\n amax = abs ( a(i,k) )\n end if\n end if\n end do\n!\n! If you found a pivot row IMAX, then,\n! eliminate the K-th entry in all rows that have not been used for pivoting.\n!\n if ( imax /= 0 ) then\n\n ipiv(imax) = k\n a(imax,k+1:n) = a(imax,k+1:n) / a(imax,k)\n b(imax) = b(imax) / a(imax,k)\n a(imax,k) = 1.0D+00\n\n do i = 1, n\n\n if ( ipiv(i) == 0 ) then\n a(i,k+1:n) = a(i,k+1:n) - a(i,k) * a(imax,k+1:n)\n b(i) = b(i) - a(i,k) * b(imax)\n a(i,k) = 0.0D+00\n end if\n\n end do\n\n end if\n\n end do\n!\n! Now, every row with nonzero IPIV begins with a 1, and\n! all other rows are all zero. Begin solution.\n!\n do j = n, 1, -1\n\n imax = 0\n do k = 1, n\n if ( ipiv(k) == j ) then\n imax = k\n end if\n end do\n\n if ( imax == 0 ) then\n\n x(j) = 0.0D+00\n\n if ( b(j) == 0.0D+00 ) then\n ierror = 1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8MAT_SOLVE2 - Warning:'\n write ( *, '(a,i8)' ) ' Consistent singularity, equation = ', j\n else\n ierror = 2\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8MAT_SOLVE2 - Error:'\n write ( *, '(a,i8)' ) ' Inconsistent singularity, equation = ', j\n end if\n\n else\n\n x(j) = b(imax)\n\n do i = 1, n\n if ( i /= imax ) then\n b(i) = b(i) - a(i,j) * x(j)\n end if\n end do\n\n end if\n\n end do\n\n return\nend\nsubroutine r8vec_even ( n, alo, ahi, a )\n\n!*****************************************************************************80\n!\n!! R8VEC_EVEN returns an R8VEC of evenly spaced values.\n!\n! Discussion:\n!\n! An R8VEC is a vector of R8's.\n!\n! If N is 1, then the midpoint is returned.\n!\n! Otherwise, the two endpoints are returned, and N-2 evenly\n! spaced points between them.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 09 December 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of values.\n!\n! Input, real ( kind = 8 ) ALO, AHI, the low and high values.\n!\n! Output, real ( kind = 8 ) A(N), N evenly spaced values.\n! Normally, A(1) = ALO and A(N) = AHI.\n! However, if N = 1, then A(1) = 0.5*(ALO+AHI).\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n real ( kind = 8 ) ahi\n real ( kind = 8 ) alo\n integer ( kind = 4 ) i\n\n if ( n == 1 ) then\n\n a(1) = 0.5D+00 * ( alo + ahi )\n\n else\n\n do i = 1, n\n a(i) = ( real ( n - i, kind = 8 ) * alo &\n + real ( i - 1, kind = 8 ) * ahi ) &\n / real ( n - 1, kind = 8 )\n end do\n\n end if\n\n return\nend\nsubroutine timestamp ( )\n\n!*****************************************************************************80\n!\n!! TIMESTAMP prints the current YMDHMS date as a time stamp.\n!\n! Example:\n!\n! 31 May 2001 9:45:54.872 AM\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 May 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! None\n!\n implicit none\n\n character ( len = 8 ) ampm\n integer ( kind = 4 ) d\n integer ( kind = 4 ) h\n integer ( kind = 4 ) m\n integer ( kind = 4 ) mm\n character ( len = 9 ), parameter, dimension(12) :: month = (/ &\n 'January ', 'February ', 'March ', 'April ', &\n 'May ', 'June ', 'July ', 'August ', &\n 'September', 'October ', 'November ', 'December ' /)\n integer ( kind = 4 ) n\n integer ( kind = 4 ) s\n integer ( kind = 4 ) values(8)\n integer ( kind = 4 ) y\n\n call date_and_time ( values = values )\n\n y = values(1)\n m = values(2)\n d = values(3)\n h = values(5)\n n = values(6)\n s = values(7)\n mm = values(8)\n\n if ( h < 12 ) then\n ampm = 'AM'\n else if ( h == 12 ) then\n if ( n == 0 .and. s == 0 ) then\n ampm = 'Noon'\n else\n ampm = 'PM'\n end if\n else\n h = h - 12\n if ( h < 12 ) then\n ampm = 'PM'\n else if ( h == 12 ) then\n if ( n == 0 .and. s == 0 ) then\n ampm = 'Midnight'\n else\n ampm = 'AM'\n end if\n end if\n end if\n\n write ( *, '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) &\n d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm )\n\n return\nend", "meta": {"hexsha": "22e5d74e26936131c091ca19ff30ae6ef97bc9a1", "size": 16812, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fem1d_heat_steady/fem1d_heat_steady.f90", "max_stars_repo_name": "mjasher/computation", "max_stars_repo_head_hexsha": "63d83e476af5c6da5361a6bc8a7692372931a220", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fem1d_heat_steady/fem1d_heat_steady.f90", "max_issues_repo_name": "mjasher/computation", "max_issues_repo_head_hexsha": "63d83e476af5c6da5361a6bc8a7692372931a220", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fem1d_heat_steady/fem1d_heat_steady.f90", "max_forks_repo_name": "mjasher/computation", "max_forks_repo_head_hexsha": "63d83e476af5c6da5361a6bc8a7692372931a220", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.8423913043, "max_line_length": 80, "alphanum_fraction": 0.5094575303, "num_tokens": 6086, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.8652240756264638, "lm_q1q2_score": 0.7905349192909596}} {"text": "!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n! %\r\n! Copyright (C) 2015 Adrian Martinez Vargas %\r\n! %\r\n! This software may be modified and distributed under the terms %\r\n! of the MIT license. See the LICENSE.txt file for details. %\r\n! %\r\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\n\r\nsubroutine rotscale(X,Y,Z,nd,X0,Y0,Z0,ang1,ang2,ang3,anis1,anis2,invert,Xr,Yr,Zr)\r\n !-----------------------------------------------------------------------\r\n\r\n ! Rotate coordinates\r\n ! ******************\r\n\r\n ! This is implemented as in http://www.ccgalberta.com/ccgresources/report06/2004-403-angle_rotations.pdf\r\n\r\n\r\n\r\n ! INPUT PARAMETERS:\r\n \r\n ! X,Y, Z X,Y,Z arrays with coordinates\r\n ! nd number of data points\r\n ! X0,Y0,Z0 New origin of coordinate\r\n ! ang1 Azimuth angle for principal direction\r\n ! ang2 Dip angle for principal direction\r\n ! ang3 Third rotation angle\r\n ! anis1 First anisotropy ratio\r\n ! anis2 Second anisotropy ratio\r\n ! invert If 0 do rotation, if 1 invert rotation\r\n\r\n\r\n ! Rerurn\r\n ! Xr,Yr,Zr New rotated and scaled X,Y,Z arrays with coordinates\r\n\r\n\r\n !-----------------------------------------------------------------------\r\n\r\n implicit none\r\n\r\n ! input\r\n real*8, intent(in), dimension(nd) ::X,Y,Z\r\n real*8, intent(in) :: ang1,ang2,ang3,anis1,anis2, X0,Y0,Z0\r\n integer, intent(in) :: invert, nd\r\n\r\n ! output\r\n real*8, intent(out), dimension(nd) ::Xr,Yr,Zr\r\n\r\n ! internal variables\r\n real*8 :: alpha, beta, theta, sina,sinb,sint, &\r\n cosa,cosb,cost,afac1,afac2, &\r\n X1,Y1,Z1, X2,Y2,Z2\r\n integer :: i\r\n \r\n \r\n !parameters\r\n real*8 :: DEG2RAD,EPSLON\r\n\r\n DEG2RAD=3.141592654/180.0\r\n EPSLON=1.e-20\r\n\r\n alpha = ang1 * DEG2RAD\r\n beta = ang2 * DEG2RAD\r\n theta = ang3 * DEG2RAD\r\n\r\n ! Get the required sines and cosines:\r\n\r\n sina = dble(sin(alpha))\r\n sinb = dble(sin(beta))\r\n sint = dble(sin(theta))\r\n cosa = dble(cos(alpha))\r\n cosb = dble(cos(beta))\r\n cost = dble(cos(theta))\r\n\r\n ! Construct the rotation matrix in the required memory:\r\n\r\n afac1 = 1.0 / dble(max(anis1,EPSLON))\r\n afac2 = 1.0 / dble(max(anis2,EPSLON))\r\n \r\n if (invert == 0) then\r\n do i=1,nd\r\n !shift \r\n X1 = X(i)-X0\r\n Y1 = Y(i)-Y0\r\n Z1 = Z(i)-Z0\r\n ! rotate using equation 4 on http://www.ccgalberta.com/ccgresources/report06/2004-403-angle_rotations.pdf\r\n X2= (cosa*cost+sina*sinb*sint)*X1 + (-sina*cost+cosa*sinb*sint)*Y1 +(-cosb*sint)*Z1\r\n Y2= (sina*cosb)*X1 + (cosa*cosb)*Y1 + (sinb)*Z1\r\n Z2= (cosa*sint-sina*sinb*cost)*X1 + (-sina*sint-cosa*sinb*cost)*Y1 + (cosb*cost)*Z1\r\n !rescale\r\n Xr(i)= X2\r\n Yr(i)= Y2*afac1\r\n Zr(i)= Z2*afac2\r\n end do\r\n else\r\n do i=1,nd\r\n !rescale\r\n X1 = X(i)\r\n Y1 = Y(i)/afac1\r\n Z1 = Z(i)/afac2\r\n ! rotate using equation 5 on http://www.ccgalberta.com/ccgresources/report06/2004-403-angle_rotations.pdf\r\n X2= (cosa*cost+sina*sinb*sint)*X1 + (sina*cosb)*Y1 + (cosa*sint-sina*sinb*cost)*Z1\r\n Y2=(-sina*cost+cosa*sinb*sint)*X1 + (cosa*cosb)*Y1 +(-sina*sint-cosa*sinb*cost)*Z1\r\n Z2= (-cosb*sint)*X1 + (sinb)*Y1 + (cosb*cost)*Z1\r\n !shift \r\n Xr(i) = X2+X0\r\n Yr(i) = Y2+Y0\r\n Zr(i) = Z2+Z0\r\n end do\r\n end if \r\n \r\n ! Return to calling program:\r\n return\r\n \r\nend subroutine rotscale\r\n", "meta": {"hexsha": "77300f4cf2f6541768a84467323641cde9b354da", "size": 4103, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "for_code/rotscale.f90", "max_stars_repo_name": "cmrajan/pygslib", "max_stars_repo_head_hexsha": "acdf96d9ec17658f18fe9f078104c6259b479f52", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 94, "max_stars_repo_stars_event_min_datetime": "2015-10-23T20:35:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T08:24:49.000Z", "max_issues_repo_path": "for_code/rotscale.f90", "max_issues_repo_name": "kaufmanno/pygslib", "max_issues_repo_head_hexsha": "7fb0c201eba6304b1914cf88a437aa9dc42e7021", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 55, "max_issues_repo_issues_event_min_datetime": "2016-09-19T17:20:46.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-20T03:44:01.000Z", "max_forks_repo_path": "for_code/rotscale.f90", "max_forks_repo_name": "kaufmanno/pygslib", "max_forks_repo_head_hexsha": "7fb0c201eba6304b1914cf88a437aa9dc42e7021", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 47, "max_forks_repo_forks_event_min_datetime": "2016-03-31T08:17:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T02:35:33.000Z", "avg_line_length": 35.0683760684, "max_line_length": 118, "alphanum_fraction": 0.4474774555, "num_tokens": 1166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813501370535, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.7903210489068542}} {"text": "subroutine bkfilter(n, y, up, dn, k, ybp, yt)\r\n\r\n! Aubhik 20.02.2005\r\n!\r\n! Baxter and King (1999) Band-Pass filter\r\n!\r\n! y is a data vector of length n\r\n! ybp is the band pass filtered series, with 0.0 for the first and last k observations\r\n! n is the length of the data vector y\r\n! up is the lower frequency\r\n!\tfor example, the business cycle band will have up = 6 for quarterly data\r\n!\tand up = 1.5 for annual data\r\n! dn is the higher frequency\r\n!\tfor example, the business cycle band will have dn = 32 for quarterly data\r\n!\tand dn = 8 for annual data\r\n! k is the number of leads and lags used by the symmetric moving-average \r\n!\trepresentation of the band pass filter. Baxter and King (1999) find\r\n!\tthat k = 12 is a practical choice.\r\n! \r\n! Algorithm provided by Bob King. This subroutine is the Fortran 90 version of \r\n! bpf.m and filtk.m written by Baxter and King (1999). The band pass filter is \r\n! a moving average involving 2k+1 terms. The weights are symmetric and calculated\r\n! in akvec. \r\n\r\nimplicit none\r\n\r\ninteger n, up, dn, k\r\nreal y(n), ybp(n), yt(n)\r\n\r\ninteger j\r\nreal pi, omlbar, omubar, kr, kj, theta\r\nreal akvec(k+1), avec(2*k+1), tvec(2*k+1)\r\n\r\nintent(in):: n, up, dn, k, y\r\nintent(out):: ybp, yt\r\n\r\npi = 2.0*acos(0.0)\r\n\r\nomlbar = 2.0*pi/dble(dn)\r\nomubar = 2.0*pi/dble(up)\r\n\r\nakvec = 0.0\r\navec = 0.0\r\n\r\nkr = dble(k)\r\n\r\nakvec(1) = (omubar - omlbar)/pi\r\n\r\ndo j = 1, k\r\n kj = dble(j)\r\n akvec(j+1) = (dsin(dble(kj*omubar)) - dsin(dble(kj*omlbar)))/(kj*pi)\r\nend do\r\n\r\ntheta = akvec(1) + 2.0*sum(akvec(2:k+1))\r\ntheta = -1.0*(theta/(2.0*kr + 1.0))\r\n\r\nakvec = akvec + theta\r\n\r\navec(k+1) = akvec(1)\r\n\r\ndo j = 1, k\r\n avec(k+1 - j) = akvec(j+1)\r\n avec(k+1 + j) = akvec(j+1)\r\nend do\r\n\r\ndo j = 1, k*2+1\r\n tvec(j) = 1.0 - avec(j)\r\nend do\r\n\r\nybp = 0.0\r\nyt = 0.0\r\n\r\ndo j = k + 1, n - k\r\n ybp(j) = dot_product(avec, y(j - k: j + k))\r\n yt(j) = dot_product(tvec, y(j - k: j + k))\r\nend do\r\n\r\nend subroutine bkfilter\r\n", "meta": {"hexsha": "2951a1c144f7b07c5b79ca664c1dae488bfc3d39", "size": 1945, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pymaclab/filters/src/bkfilter.f90", "max_stars_repo_name": "radovankavicky/pymaclab", "max_stars_repo_head_hexsha": "21da758f64ed0b62969c9289576f677e977cfd98", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 96, "max_stars_repo_stars_event_min_datetime": "2015-01-25T05:59:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-29T14:05:22.000Z", "max_issues_repo_path": "pymaclab/filters/src/bkfilter.f90", "max_issues_repo_name": "1zinnur9/pymaclab", "max_issues_repo_head_hexsha": "21da758f64ed0b62969c9289576f677e977cfd98", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2015-12-17T19:25:46.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-19T07:05:20.000Z", "max_forks_repo_path": "pymaclab/filters/src/bkfilter.f90", "max_forks_repo_name": "1zinnur9/pymaclab", "max_forks_repo_head_hexsha": "21da758f64ed0b62969c9289576f677e977cfd98", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 36, "max_forks_repo_forks_event_min_datetime": "2016-01-31T15:22:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-29T07:03:07.000Z", "avg_line_length": 24.6202531646, "max_line_length": 87, "alphanum_fraction": 0.6215938303, "num_tokens": 700, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377320263431, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7902778629839213}} {"text": "subroutine distancef(vart, varf, ntt, ntf, nxy, dist)\n! Estimate the Euclidean distance between the given atmospheric circulation \n! variable, say X, daily or monthly mean and all other daily or monthly means within the training period\n! \n! \n! INPUT-> vart(nxy,ntt) : X array for all months/days of the training period\n! varf(nxy,ntf) : X array for the month/day under scrutiny for the analogue search\n! ntt : number of months/days in the training period \n! ntf : number of months/days under scrutiny for the analogue search \n! nxy : number of gridpoints\n!\n! OUTPUT-> dist(ntf,ntt) : distance array\n! \n! \n implicit none\n integer ::ntt, ntf, nxy\n real vart(nxy, ntt), varf(nxy, ntf), dist(ntf, ntt)\n integer ::n, m\n\n !$OMP PARALLEL DO PRIVATE(m)\n do n=1,ntt\n\n do m=1,ntf\n dist(m,n) = sqrt(sum(( vart(:,n) - varf(:,m) )**2))\n end do\n\n end do\n !$OMP END PARALLEL DO\n\nend subroutine distancef\n", "meta": {"hexsha": "587616153c1586d10b10a4f5108c6205c4cfa730", "size": 1095, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ncl_code/distancef.f90", "max_stars_repo_name": "terrayl/Dynamico", "max_stars_repo_head_hexsha": "561701a3665751ac5d7564acf4cfbf60f199e5b3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ncl_code/distancef.f90", "max_issues_repo_name": "terrayl/Dynamico", "max_issues_repo_head_hexsha": "561701a3665751ac5d7564acf4cfbf60f199e5b3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-01-11T13:00:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-11T13:00:15.000Z", "max_forks_repo_path": "ncl_code/distancef.f90", "max_forks_repo_name": "terrayl/Dynamico", "max_forks_repo_head_hexsha": "561701a3665751ac5d7564acf4cfbf60f199e5b3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.3225806452, "max_line_length": 104, "alphanum_fraction": 0.5744292237, "num_tokens": 299, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.958537730841905, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.7902778558059576}} {"text": "c ===================================\nc MAIN PROGRAM\nc\t\tThis program takes a function and\nc\t\tcomputes its definite integral in\nc\t\ta region (a, b)\nc ===================================\n program main\n\nc\t Variables\n real*8 a, b, h, hn, error, conv, res, reslast, sum, x\n real*8 f, df2, df4\n integer n, choice, i, j, l\n j = 1\n conv = 1\n\nc Parameters\nc\t\tdefining the region to integrate\n a = 0.0d0\n b = 1.0d0\n\nc User's choice of polynomial order\n1 write(*,*) 'Choose the order of the polynomial (1, 2, or 3)'\n read(*,*) choice\n\n if ((choice.ne.1) .and. (choice.NE.2) .and. (choice.NE.3)) then\n write(*,*) '--- not supported choice ---'\n go to 1\n endif\n if (choice .eq. 1) then\n go to 10\n endif\n if (choice .eq. 2) then\n go to 20\n endif\n if (choice .eq. 3) then\n go to 30\n endif\nc end of polynomial choice\n\n\nc ---------------------------------\nc\t 1st degree polynomial - Trapezoid\nc ---------------------------------\n10 continue\n write(*,*) 'Method of choice: Trapezoid (1st degree polynomial)'\nc\t Starting parameters\n n = 2\n l = 2\n\n15 continue\n res = 0\n sum = 0\n x = a\n hn = h(a,b,n)\n\nc loop to calculate f0 + 2f1 + 2f2 + ... + 2fn-1 + fn\n i = 1\n11 continue\n if (i.gt.1) then\n x = x + hn\n endif\n if (i.eq.1 .or. i.eq.n) then\n sum = sum + f(x)\n else\n sum = sum + 2 * f(x)\n endif\n i = i + 1\nc\t\tending of loop\n if (i.lt.(n+1)) then\n go to 11\n endif\n\nc\t Calculation of the result\n res = sum * (hn/2.0d0)\n\nc Use of Romberg's method\n if (j.gt.1) then\n reslast = res\n res = res - (res - reslast)/(l**2 - 1)\n conv = reslast - res\n endif\n\nc\t Calculation of the error\n error = - (1.0d0/12.0d0) * hn * (b-a) * df2( (b-a)/2 )\n\n if (error.gt.1.0d-9 .or. abs(conv).gt.1.0d-9) then\n j = j + 1\n n = n * l\n go to 15\n endif\n go to 99\nc\t End of Trapezoid\n\n\nc -------------------------------\nc\t 2nd degree polynomial - Simpson\nc -------------------------------\n20 continue\n write(*,*) 'Method of choice: Simpson (2nd degree polynomial)'\nc\t Starting parameters\n n = 2\n l = 2\n\n25 continue\n res = 0\n sum = 0\n x = a\n hn = h(a,b,n)\n\nc loop to calculate f1 + 4f2 + f3 + ... + fn-1 + 4fn + fn+1\n i = 1\n21 continue\n if (i.gt.1) then\n x = x + hn\n endif\n if (i.eq.1 .or. i.eq.n) then\n sum = sum + f(x)\n elseif (mod(i,2).eq.0) then\n sum = sum + 4 * f(x)\n else\n sum = sum + 2 * f(x)\n endif\n i = i + 1\nc\t\tending of loop\n if (i.lt.(n+1)) then\n go to 21\n endif\n\nc\t Calculation of the result\n res = sum * (hn/3.0d0)\n\nc Use of Romberg's method\n if (j.gt.1) then\n reslast = res\n res = res - (res - reslast)/(l**4 - 1)\n conv = reslast - res\n endif\n\nc\t Calculation of the error\n error = - (1.0d0/80.0d0) * (hn**4) * (b-a) * df4( (b-a)/2 )\n\n if (error.gt.1.0d-9 .or. abs(conv).gt.1.0d-9) then\n j = j + 1\n n = n * l\n go to 25\n endif\n\n go to 99\nc\t End of Simpson\n\n\nc -----------------------------------\nc\t 3rd degree polynomial - Simpson 3/8\nc -----------------------------------\n30 continue\n write(*,*) 'Method of choice: Simpson 3/8 (3rd degree polynomial)'\nc\t Starting parameters\n n = 3\n l = 2\n\n35 continue\n res = 0\n sum = 0\n x = a\n hn = h(a,b,n)\n\nc loop to calculate f0 + 2f1 + 2f2 + ... + 2fn-1 + fn\n i = 1\n31 continue\n if (i.gt.1) then\n x = x + hn\n endif\n if (i.eq.1 .or. i.eq.n) then\n sum = sum + f(x)\n elseif (mod(i,3).eq.1) then\n sum = sum + 2 * f(x)\n else\n sum = sum + 3 * f(x)\n endif\n i = i + 1\nc\t\tending of loop\n if (i.lt.(n+1)) then\n go to 31\n endif\n\nc\t Calculation of the result\n res = sum * (3.0d0*hn/8.0d0)\n\nc Use of Romberg's method\n if (j.gt.1) then\n reslast = res\n res = res - (res - reslast)/(l**4 - 1)\n conv = reslast - res\n endif\n\nc\t Calculation of the error\n error = - (1.0d0/12.0d0) * hn * (b-a) * df2( (b-a)/2 )\n\n if (error.gt.1.0d-9 .or. abs(conv).gt.1.0d-9) then\n j = j + 1\n n = n * l\n go to 35\n endif\n go to 99\nc \t End of Simpson 3/8\n\n\n99 continue\n write(*,*) '-----------------------------------'\n write(*,*) 'number of points: ', n\n write(*,*) 'result: ', res\n write(*,*) 'error', error\n write(*,*) 'convergence', conv\n end\n\n\n\n\nc =========================================\nc\t FUNCTION\nc\t\tDefinition of the function to integrate\nc =========================================\n real*8 function f(x)\n real*8 x\n \n f = log(x+2.0d-1)\n \n return\n end\n\n\nc =============================================\nc\t FUNCTION\nc\t\tDefinition of the function's 2nd derivative\nc =============================================\n real*8 function df2(x)\n real*8 x\n \n df2 = - 1.0d0 / (x + 2.0d-1)**2\n \n return\n end\n\n\nc =============================================\nc\t FUNCTION\nc\t\tDefinition of the function's 4th derivative\nc =============================================\n real*8 function df4(x)\n real*8 x\n \n df4 = - 6.0d0 / (x + 2.0d-1)**4\n \n return\n end\n\n\nc ==============================================\nc\t FUNCTION\nc\t\tcalculating the steps from the needed points\nc ==============================================\n real*8 function h(a,b,n)\n real*8 a, b\n integer n\n \n h = (b-a)/(n-1)\n \n return\n end\n\n", "meta": {"hexsha": "ee56c1feffd4a031ed4c380ef1f4c0a422759d30", "size": 5880, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "computational math/numerical integral calculation - differential equation integration 1.(a2).f", "max_stars_repo_name": "ttetrafon/sciences", "max_stars_repo_head_hexsha": "0c0717a420c0af96c2ca58c796e387c6c5a99b73", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "computational math/numerical integral calculation - differential equation integration 1.(a2).f", "max_issues_repo_name": "ttetrafon/sciences", "max_issues_repo_head_hexsha": "0c0717a420c0af96c2ca58c796e387c6c5a99b73", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "computational math/numerical integral calculation - differential equation integration 1.(a2).f", "max_forks_repo_name": "ttetrafon/sciences", "max_forks_repo_head_hexsha": "0c0717a420c0af96c2ca58c796e387c6c5a99b73", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.6974169742, "max_line_length": 72, "alphanum_fraction": 0.4261904762, "num_tokens": 1909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012671214071, "lm_q2_score": 0.8354835309589073, "lm_q1q2_score": 0.7902013822400018}} {"text": " subroutine cqdrtc(Coef,Sol,NSol)\nc Combutes the zeros of a quadratic polynomial\nccccccccccccccccccccccccccccccccccccccccccccccccc\nc Input\nc Coef - array of coefficients\n COMPLEX*16 Coef(3)\nccccccccccccccccccccccccccccccccccccccccccccccccc\nc Output\nc Sol - Array of solutions\nc NSol - # of solutions (only one if Coef(1) = 0 etc.)\nc NSol = -1 means a and b are zero\n COMPLEX*16 Sol(2)\n INTEGER NSol\nccccccccccccccccccccccccccccccccccccccccccccccccc\nc Local Variables\n COMPLEX*16 q, Sqrt\n DOUBLE PRECISION Sgn, Root\n\n IF(Coef(1).eq.0.d0) THEN\n IF(Coef(2).eq.0.d0) THEN\n NSol = -1\n RETURN\n ELSE\n NSol = 1\n Sol(1) = -Coef(3)/Coef(2)\n END IF\n ELSE\n NSol = 2\n Root = DBLE(Sqrt(Coef(2)**2-4.d0*Coef(1)*Coef(3)))\n Sgn = SIGN(DBLE(CONJG(Coef(2))*Root),1.d0)\n q = -0.5d0*(Coef(2) + Sgn*Root)\n\n Sol(1) = q/Coef(1)\n Sol(2) = Coef(3)/q\n END IF\n\n RETURN\n END\n\n\n subroutine ccubic(Coef,Sol,NSol)\nc Combutes the zeros of a cubic polynomial\nccccccccccccccccccccccccccccccccccccccccccccccccc\nc Input\nc Coef - array of coefficients\n COMPLEX*16 Coef(4)\nccccccccccccccccccccccccccccccccccccccccccccccccc\nc Output\nc Sol - Array of solutions\nc NSol - # of solutions (only one if Coef(1) = 0 etc.)\nc NSol = -1 means a, b, and c are zero\n COMPLEX*16 Sol(4)\n INTEGER NSol\nccccccccccccccccccccccccccccccccccccccccccccccccc\nc Local Variables\n COMPLEX*16 P1, P2, Q, R, Coef2(3), a, b, c\n DOUBLE PRECISION Sgn, Theta\nc PARAMETERS\n COMPLEX*16 I\n PARAMETER(I = (0.d0, 1.d0))\n DOUBLE PRECISION Pi\n PARAMETER(Pi = 3.141592653589793238462643d0)\n\n IF(Coef(1).eq.0.d0) THEN\n Coef2(1) = Coef(2)\n Coef2(2) = Coef(3)\n Coef2(3) = Coef(4)\n CALL CQdrtc(Coef2,Sol,NSol)\n ELSE\n a = Coef(2)/Coef(1)\n b = Coef(3)/Coef(1)\n c = Coef(4)/Coef(1)\n NSol = 3\n Q = (a**2 - 3.d0*b)/9.d0\n R = (2.d0*a**3 - 9.d0*a*b + 27.d0*c)/54.d0\n\n IF(((DIMAG(Q).eq.0.d0).and.(DIMAG(R).eq.0.d0)).and.\n & (DIMAG(R**2).lt.DIMAG(Q**3))) THEN\n Theta = ACOS (DBLE(R/SQRT(Q**3)))\n Sol(1) = -2*SQRT(Q)*Cos(Theta/3.d0) - a/3.d0\n Sol(2) = -2*SQRT(Q)*Cos((Theta+2.d0*Pi)/3.d0) - a/3.d0\n Sol(3) = -2*SQRT(Q)*Cos((Theta-2.d0*Pi)/3.d0) - a/3.d0\n ELSE\n Sgn = SIGN(1.d0, DBLE(CONJG(R)*SQRT(R**2-Q**3)))\n P1 = -(R + Sgn*SQRT(R**2-Q**3))**(1.d0/3.d0)\n IF(P1.eq.0.d0) THEN\n P2 = 0.d0\n ELSE\n P2 = Q/P1\n END IF\n Sol(1) = (P1 + P2) - a/3.d0\n Sol(2) = -0.5d0*(P1 + P2) - a/3.d0 +\n & I*SQRT(3.d0)/2.d0*(P1-P2)\n Sol(3) = -0.5d0*(P1 + P2) - a/3.d0 -\n & I*SQRT(3.d0)/2.d0*(P1-P2)\n END IF\n END IF\n\n RETURN\n END\n", "meta": {"hexsha": "895d049ce6e8151a97d1fd97c35c3d1e7413759b", "size": 3036, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH/czeros.f", "max_stars_repo_name": "xraypy/feff85exafs", "max_stars_repo_head_hexsha": "ec8dcb07ca8ee034d0fa7431782074f0f65357a5", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2016-01-05T21:29:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:59:17.000Z", "max_issues_repo_path": "src/MATH/czeros.f", "max_issues_repo_name": "xraypy/feff85exafs", "max_issues_repo_head_hexsha": "ec8dcb07ca8ee034d0fa7431782074f0f65357a5", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2015-01-04T18:37:30.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T12:06:12.000Z", "max_forks_repo_path": "src/MATH/czeros.f", "max_forks_repo_name": "xraypy/feff85exafs", "max_forks_repo_head_hexsha": "ec8dcb07ca8ee034d0fa7431782074f0f65357a5", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2016-01-05T21:29:26.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T13:11:01.000Z", "avg_line_length": 30.0594059406, "max_line_length": 66, "alphanum_fraction": 0.5260210804, "num_tokens": 1164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012655937034, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.7902013809636307}} {"text": "MODULE module_circle\n\n IMPLICIT NONE\n REAL, PARAMETER :: PI = 3.1415926\n\nCONTAINS\n\n REAL FUNCTION circle_area( radius )\n IMPLICIT NONE\n REAL, INTENT(IN) :: radius\n\n circle_area=PI*(radius**2)\n END FUNCTION\n\n REAL FUNCTION circle_perimeter( radius )\n IMPLICIT NONE\n REAL, INTENT(IN) :: radius\n\n circle_perimeter=2*PI*radius\n END FUNCTION\n\n\nEND MODULE module_circle\n\n", "meta": {"hexsha": "16b3beebc2330f04445e4b4a9be65201dfa99c4f", "size": 425, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/example_project_2/myLibrary/module_circle.f90", "max_stars_repo_name": "aperezhortal/fortran_debugging_tutorial", "max_stars_repo_head_hexsha": "17f8cf83cf0289485456e5c40d110ddf71fc4554", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-08-29T19:48:44.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-29T19:48:44.000Z", "max_issues_repo_path": "examples/example_project_2/myLibrary/module_circle.f90", "max_issues_repo_name": "aperezhortal/fortran_debugging_introduction", "max_issues_repo_head_hexsha": "17f8cf83cf0289485456e5c40d110ddf71fc4554", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/example_project_2/myLibrary/module_circle.f90", "max_forks_repo_name": "aperezhortal/fortran_debugging_introduction", "max_forks_repo_head_hexsha": "17f8cf83cf0289485456e5c40d110ddf71fc4554", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.0, "max_line_length": 44, "alphanum_fraction": 0.6447058824, "num_tokens": 108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9433475699138558, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7901667607456471}} {"text": "PROGRAM F007\n\n ! Copyright 2021 Melwyn Francis Carlo\n\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: NTH = 10001, N = 1E+6\n INTEGER :: I, J, PRIMES_N\n LOGICAL, DIMENSION(N+1) :: INTEGERS_LIST\n\n ! USING THE ALGORITHM OF SIEVE OF EROSTHENES\n INTEGERS_LIST = .TRUE.\n I = 2\n DO WHILE ((I*I) <= N)\n IF (INTEGERS_LIST(I)) THEN\n J = I * I\n DO WHILE (J <= N)\n INTEGERS_LIST(J) = .FALSE.\n J = J + I\n END DO\n END IF\n I = I + 1\n END DO\n\n PRIMES_N = 0\n DO I = 2, N\n IF (INTEGERS_LIST(I)) THEN\n PRIMES_N = PRIMES_N + 1\n IF (PRIMES_N == NTH) THEN\n GOTO 10\n END IF\n END IF\n END DO\n\n 10 CONTINUE\n\n PRINT ('(I0)'), I\n\nEND PROGRAM F007\n", "meta": {"hexsha": "434107d06f5e0a3316e541a60f95a49d049198d0", "size": 801, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "problems/007/007.f90", "max_stars_repo_name": "melwyncarlo/ProjectEuler", "max_stars_repo_head_hexsha": "c4d30ed528ae6de82232f3d2044d608c6e8f1c37", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "problems/007/007.f90", "max_issues_repo_name": "melwyncarlo/ProjectEuler", "max_issues_repo_head_hexsha": "c4d30ed528ae6de82232f3d2044d608c6e8f1c37", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "problems/007/007.f90", "max_forks_repo_name": "melwyncarlo/ProjectEuler", "max_forks_repo_head_hexsha": "c4d30ed528ae6de82232f3d2044d608c6e8f1c37", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.025, "max_line_length": 48, "alphanum_fraction": 0.4843945069, "num_tokens": 274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.948154530420204, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.790120496242843}} {"text": "! The number 3797 has an interesting property.\n! Being prime itself, it is possible\n! to continuously remove digits from left to right,\n! and remain prime at each stage: 3797, 797, 97, and 7.\n! Similarly we can work from right to left: 3797, 379, 37, and 3.\n\n! Find the sum of the only eleven primes that are\n! both truncatable from left to right and right to left.\n\n! NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes.\n\n! Answer: 748317\n! Project Euler: 37\n\n\nprogram main\n\nuse euler\n\nimplicit none\n\n integer (kind=8), parameter :: PRIME_C = 11;\n integer (kind=8), parameter :: BASE = 10;\n integer (kind=8), parameter :: TWO = 2;\n integer (kind=8) :: c, sum, i;\n\n c = 0;\n sum = 0;\n i = 3;\n\n\n do while(.true.)\n\n if(truncatable_prime(i)) then\n\n call inc(c, ONE);\n call inc(sum, i);\n\n if(c == PRIME_C) then\n goto 24\n endif\n endif\n\n call inc(i, TWO);\n\n end do\n\n\n24 CONTINUE\n\n call printint(sum);\n\n\ncontains\n\n\n ! Establishes whether an integer is a truncatable prime. We do this\n ! efficiently by leveraging most of the work into\n ! `possibly_truncatable`, whereby we can check if a number is even\n ! remotely worth running through an expensive check to see if it is\n ! prime. We then check if it is truncatable from both L&R\n\n pure function truncatable_prime(i)\n\n integer (kind=8), intent(in) :: i;\n logical :: truncatable_prime\n\n truncatable_prime = .false.\n\n if(i < 10 .OR. (.NOT. possibly_truncatable(i))) then\n return\n endif\n\n truncatable_prime = (right_trunc(i) .AND. left_trunc(i))\n\n return\n\n end function truncatable_prime\n\n\n pure function right_trunc(i)\n\n integer (kind=8), intent(in) :: i;\n integer (kind=8) :: tmp;\n logical :: right_trunc;\n\n tmp = i;\n right_trunc = .false.\n\n do while(tmp /= 0)\n\n if(.NOT. isprime(tmp)) then\n return;\n endif\n\n tmp = tmp / 10;\n\n end do\n\n right_trunc = .true.\n\n end function right_trunc\n\n\n ! Truncate from the left in a method that is much akin to how we do it\n ! in the `right_trunc` function.\n\n pure function left_trunc(i)\n\n integer (kind=8), intent(in) :: i;\n integer (kind=8) :: tmp;\n logical :: left_trunc\n\n tmp = i;\n left_trunc = .false.\n\n do while(tmp /= 0)\n\n if(.NOT. isprime(tmp)) then\n return;\n endif\n\n tmp = intrev(intrev(tmp) / 10);\n\n end do\n\n left_trunc = .true.\n\n return\n\n end function left_trunc\n\n\n ! For a number to be prime it must be odd, unless it is two. In this\n ! notion, we may reduce our search space by testing if any of the\n ! digits is even. If so, we know that this number is impossible to\n ! be a truncatable prime. This saves a lot of cycles as we don't need \n ! to expensively check if numbers are prime or not if they aren't even\n ! in the realms of probability of being true.\n\n pure function possibly_truncatable(i)\n\n integer (kind=8), intent(in) :: i;\n integer (kind=8) :: tmp, end_d;\n logical :: possibly_truncatable, has_2;\n\n possibly_truncatable = .false.\n has_2 = .false.\n tmp = i;\n\n do while(tmp /= 0)\n\n ! Check if the end digit is even, but allow one\n ! occurance of two\n end_d = mod(tmp, BASE);\n\n if(mod(end_d, 2) == 0) then\n\n if (end_d == 2) then\n\n if(has_2) then\n return;\n else\n has_2 = .true.\n endif \n else\n return;\n\n endif\n endif\n\n tmp = tmp / BASE;\n end do\n \n possibly_truncatable = .true.\n\n end function possibly_truncatable\n\n\nend program main\n\n", "meta": {"hexsha": "d29b822b584c6d814209b40d5a560c1430270b40", "size": 4848, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/truncatable_primes.f95", "max_stars_repo_name": "guynan/project_euler", "max_stars_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-03-08T09:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T13:52:49.000Z", "max_issues_repo_path": "fortran/truncatable_primes.f95", "max_issues_repo_name": "guynan/project_euler", "max_issues_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-11-03T01:20:46.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-24T22:54:59.000Z", "max_forks_repo_path": "fortran/truncatable_primes.f95", "max_forks_repo_name": "guynan/project_euler", "max_forks_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-11-03T01:14:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T13:52:51.000Z", "avg_line_length": 26.6373626374, "max_line_length": 78, "alphanum_fraction": 0.4597772277, "num_tokens": 1020, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545377452443, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7901204925350375}} {"text": "\tFUNCTION PR_WCEQ ( tmpf, sknt )\nC************************************************************************\nC* PR_WCEQ\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes WCEQ, the wind chill equivalent temperature,\t*\nC* from TMPF and SKNT. The input values will first be converted to\t*\nC* Celsius and meters per second. The output will be calculated in\t*\nC* Fahrenheit.\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* WCEQ is the temperature with calm winds that produces the same\t*\nC* cooling effect as the given temperature with the given wind speed.\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* The following equation is used:\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC*\tPR_WCEQ = 33.0 - ( (33.0 - TMPC) * WCI (SPED) / WCI (1.34) )\t*\nC*\t\t\t\t\t\t\t\t\t*\nC*\t\twhere: WCI ( V ) = ( 10.0 * SQRT ( V ) + 10.45 - V )\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* From: R. Falconer, \"Windchill, A Useful Wintertime Weather\t\t*\nC*\t\t\tVariable\", Weatherwise, Dec 1968.\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_WCEQ ( TMPF, SKNT )\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tTMPF\t\tREAL\t\tAir temperature in deg F\t*\nC*\tSKNT\t\tREAL\t\tWind speed in knots\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_WCEQ\t\tREAL\t\tWind Chill equivalent\t\t*\nC*\t\t\t\t\t temperature in deg F\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. Nelson\t\t 7/92\tEnvironmental Information\t\t*\nC*\t\t\t\t Summaries C-3, 1975.\t\t\t*\nC* S. Jacobs/EAI\t 3/93\tCleaned up\t\t\t\t*\nC* S. Jacobs/NCEP\t 3/96\tRecoded and commented equation\t\t*\nC* M. Linda/GSC\t\t10/97\tCorrected the prologue format\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\n\tINCLUDE\t\t'ERMISS.FNC'\nC*\n\tWCI ( vel ) = ( 10.0 * SQRT ( vel ) + 10.45 - vel )\nC------------------------------------------------------------------------\nC*\tConvert input variables to Celsius and meters/second.\nC\n\ttmpc = PR_TMFC ( tmpf )\n\tsped = PR_KNMS ( sknt )\nC\nC*\tCompute the wind chill temp if the inputs are not missing\nC*\tand the wind speed is greater than 1.34 m/s.\nC\n\tIF ( ( ERMISS ( tmpc ) ) .or. ( ERMISS ( sped ) ) ) THEN\n\t wndchl = RMISSD\n\tELSE IF ( sped .le. 1.34 ) THEN\n\t wndchl = tmpc\n\tELSE\n\t wndchl = 33.0 - ( ( 33.0-tmpc ) * WCI(sped) / WCI(1.34) )\n\tEND IF\nC\nC*\tConvert to Fahrenheit for the user.\nC\n\tPR_WCEQ = PR_TMCF ( wndchl )\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "0a674f4489176af5232d7bf10072491e132d9c49", "size": 2186, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prwceq.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/prmcnvlib/pr/prwceq.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/prmcnvlib/pr/prwceq.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 33.1212121212, "max_line_length": 73, "alphanum_fraction": 0.5416285453, "num_tokens": 747, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9664104904802131, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.7901125440989899}} {"text": " subroutine my_func(x, y)\n implicit none\n complex(kind=kind(0d0)), dimension(3), intent(in) :: x\n complex(kind=kind(0d0)), dimension(2), intent(out) :: y\n\n integer :: j\n do j = 1, 2\n y(j) = log(x(j) / ((0d0,1d0) + cos(x(j+1))**2))\n end do\n end subroutine my_func\n\n subroutine my_func_jac(x_value, y_value, dy_dx)\n use adjac\n implicit none\n complex(kind=kind(0d0)), dimension(3), intent(in) :: x_value\n complex(kind=kind(0d0)), dimension(2), intent(out) :: y_value\n complex(kind=kind(0d0)), dimension(2,3), intent(out) :: dy_dx\n\n type(adjac_complexan), dimension(3) :: x\n type(adjac_complexan), dimension(2) :: y\n integer :: j\n\n call adjac_reset()\n call adjac_set_independent(x, x_value)\n\n do j = 1, 2\n y(j) = log(x(j) / ((0d0,1d0) + cos(x(j+1))**2))\n end do\n\n call adjac_get_value(y, y_value)\n call adjac_get_dense_jacobian(y, dy_dx)\n call adjac_free()\n end subroutine my_func_jac\n\nprogram simple\n implicit none\n double precision, parameter :: dx = 1e-7\n\n complex(kind=kind(0d0)), dimension(3) :: x, x2\n complex(kind=kind(0d0)), dimension(2) :: y, y2\n complex(kind=kind(0d0)), dimension(2,3) :: dy_dx\n\n integer :: i\n\n do i = 1, 3\n x(i) = i + (0d0,1d0) * i**2\n end do\n\n ! Evaluate function values\n call my_func(x, y)\n write(*,*) '-- my_func:'\n write(*,*) y\n\n ! Find jacobian by numerical differentiation\n dy_dx = 0\n do i = 1, 3\n x2 = x\n x2(i) = x(i) + dx\n call my_func(x2, y2)\n dy_dx(:,i) = (y2 - y) / dx\n end do\n\n write(*,*) '-- Jacobian via numerical differentiation:'\n do i = 1, 2\n write(*,*) cmplx(dy_dx(i,:))\n end do\n\n ! Get the same results via adjac\n dy_dx = 0\n call my_func_jac(x, y, dy_dx)\n write(*,*) '-- my_func_jac value:'\n write(*,*) y\n write(*,*) '-- my_func_jac Jacobian:'\n do i = 1, 2\n write(*,*) cmplx(dy_dx(i,:))\n end do\n\nend program simple\n", "meta": {"hexsha": "f3e7cb4f847ca881a6d9d00de6d88dafde7e7dbd", "size": 1994, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "examples/simple.f95", "max_stars_repo_name": "gyzhangqm/adjac", "max_stars_repo_head_hexsha": "49e19123b7abee390ecfc29ae8c6327bc957690a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2017-07-18T18:55:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-12T19:01:59.000Z", "max_issues_repo_path": "examples/simple.f95", "max_issues_repo_name": "pv/adjac", "max_issues_repo_head_hexsha": "49e19123b7abee390ecfc29ae8c6327bc957690a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/simple.f95", "max_forks_repo_name": "pv/adjac", "max_forks_repo_head_hexsha": "49e19123b7abee390ecfc29ae8c6327bc957690a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-07-30T21:02:25.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-23T19:12:17.000Z", "avg_line_length": 25.2405063291, "max_line_length": 69, "alphanum_fraction": 0.5682046138, "num_tokens": 682, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521253, "lm_q2_score": 0.8670357701094303, "lm_q1q2_score": 0.7900253911219991}} {"text": "\n FUNCTION IDAY(YYYY, MM, DD) RESULT(IVAL)\n!====IDAY IS A COMPANION TO CALEND; GIVEN A CALENDAR DATE, YYYY, MM,\n! DD, IDAY IS RETURNED AS THE DAY OF THE YEAR.\n! EXAMPLE: IDAY(1984, 4, 22) = 113\n\n INTEGER, INTENT(IN) :: YYYY, MM, DD\n INTEGER :: IVAL\n\n IVAL = 3055*(MM+2)/100 - (MM+10)/13*2 -91 + &\n (1-(MODULO(YYYY, 4)+3)/4 &\n + (MODULO(YYYY, 100) + 99)/100 - &\n (MODULO(YYYY, 400)+399)/400)*(MM+10)/13 + DD\n\n RETURN\n END FUNCTION IDAY\n\n\nFUNCTION JD_OUT(YYYY, MM, DD) RESULT(IVAL)\n INTEGER, INTENT(IN) :: YYYY\n INTEGER, INTENT(IN) :: MM\n INTEGER, INTENT(IN) :: DD\n INTEGER*8 :: IVAL\n! DATE ROUTINE JD(YYYY, MM, DD) CONVERTS CALENDER DATE TO\n! JULIAN DATE. SEE CACM 1968 11(10):657, LETTER TO THE\n! EDITOR BY HENRY F. FLIEGEL AND THOMAS C. VAN FLANDERN.\n! EXAMPLE JD(1970, 1, 1) = 2440588\n IVAL = DD - 32075 + 1461*(YYYY+4800+(MM-14)/12)/4 + &\n 367*(MM-2-((MM-14)/12)*12)/12 - 3*((YYYY+4900+(MM-14)/12)/100)/4\n RETURN\n END FUNCTION JD_OUT\n\n SUBROUTINE CDATE(JD,YYYY,MM,DD)\n!====GIVEN A JULIAN DAY NUMBER, NNNNNNNN, YYYY,MM,DD ARE RETURNED AS THE\n! CALENDAR DATE. JD = NNNNNNNN IS THE JULIAN DATE FROM AN EPOCH\n! IN THE VERY DISTANT PAST. SEE CACM 1968 11(10):657,\n! LETTER TO THE EDITOR BY FLIEGEL AND VAN FLANDERN.\n! EXAMPLE CALL CDATE(2440588, YYYY, MM, DD) RETURNS 1970 1 1 .\n\n INTEGER,INTENT(IN) :: JD\n INTEGER,INTENT(OUT) :: YYYY,MM,DD\n INTEGER L\n\n L = JD + 68569\n N = 4*L/146097\n L = L - (146097*N + 3)/4\n YYYY = 4000*(L+1)/1461001\n L = L - 1461*YYYY/4 + 31\n MM = 80*L/2447\n DD = L - 2447*MM/80\n L = MM/11\n MM = MM + 2 - 12*L\n YYYY = 100*(N-49) + YYYY + L\n RETURN\n END SUBROUTINE CDATE\n\n\n\n\n FUNCTION REF_ATT (R_TIME, R_DATE)\n!\n!=======================================================================\n! !\n! This function encodes the relative time attribute that gives the !\n! elapsed interval since a specified reference time. The \"units\" !\n! attribute takes the form \"time-unit since reference-time\". !\n! !\n! On Input: !\n! !\n! r_time Time-reference (real; %Y%m%d.%f, for example, !\n! 20020115.5 for 15 Jan 2002, 12:0:0). !\n! !\n! On Output: !\n! !\n! ref_att Time-reference for \"units\" attribute (string). !\n! r_date Calendar date vector (real): !\n! r_date(1) => reference date (yyyymmdd.f). !\n! r_date(2) => year. !\n! r_date(3) => year day. !\n! r_date(4) => month. !\n! r_date(5) => day. !\n! r_date(6) => hour. !\n! r_date(7) => minute. !\n! r_date(8) => second. !\n! !\n!=======================================================================\n!\n!\n \n!\n! Imported variable declarations.\n!\n USE GLOBAL\n REAL(WP), INTENT(IN) :: R_TIME\n REAL(WP), DIMENSION(8), INTENT(OUT) :: R_DATE\n CHARACTER (LEN=19) :: REF_ATT\n!\n! Local variable declarations.\n!\n INTEGER(WP) :: IDAY, IHOUR, ISEC, IYEAR, LEAP, MINUTE, MONTH\n INTEGER(WP), DIMENSION(13) :: IYD = &\n & (/ 1,32,60,91,121,152,182,213,244,274,305,335,366 /)\n INTEGER(WP), DIMENSION(13) :: IYDL = &\n & (/ 1,32,61,92,122,153,183,214,245,275,306,336,367 /)\n REAL(WP) :: DAY, SEC, YDAY\n CHARACTER (LEN=19) :: TEXT\n!\n!-----------------------------------------------------------------------\n! Decode reference time.\n!-----------------------------------------------------------------------\n!\n IYEAR=MAX(1,INT(R_TIME*0.0001))\n MONTH=MIN(12,MAX(1,INT((R_TIME-REAL(IYEAR*10000))*0.01)))\n DAY=R_TIME-AINT(R_TIME*0.01)*100.0\n IDAY=INT(DAY)\n SEC=(DAY-AINT(DAY))*86400.0\n IHOUR=INT(SEC/3600.0)\n MINUTE=INT(MOD(SEC,3600.0)/60.0)\n ISEC=INT(MOD(SEC,60.0))\n!\n!-----------------------------------------------------------------------\n! Get year day.\n!-----------------------------------------------------------------------\n!\n LEAP=MOD(IYEAR,4)\n IF (LEAP.EQ.0) THEN\n YDAY=REAL(IYDL(MONTH))+REAL(IDAY)-1.0\n ELSE\n YDAY=REAL(IYD(MONTH))+REAL(IDAY)-1.0\n END IF\n!\n!-----------------------------------------------------------------------\n! Build output date vector.\n!-----------------------------------------------------------------------\n!\n R_DATE(1)=R_TIME\n R_DATE(2)=REAL(IYEAR)\n R_DATE(3)=MAX(1.0,YDAY)\n R_DATE(4)=REAL(MONTH)\n R_DATE(5)=MAX(1.0,REAL(IDAY))\n R_DATE(6)=REAL(IHOUR)\n R_DATE(7)=REAL(MINUTE)\n R_DATE(8)=REAL(ISEC)\n!\n!-----------------------------------------------------------------------\n! Build reference-time string.\n!-----------------------------------------------------------------------\n!\n WRITE (TEXT,10) IYEAR, MONTH, IDAY, IHOUR, MINUTE, ISEC\n 10 FORMAT (I4,'-',I2.2,'-',I2.2,1X,I2.2,':',I2.2,':',I2.2)\n REF_ATT=TEXT\n RETURN\n END FUNCTION REF_ATT\n\n SUBROUTINE CONVERSION(NUMBER, YEAR, MONTH, DAY)\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: NUMBER\n INTEGER, INTENT(OUT) :: YEAR, MONTH, DAY\n\n YEAR = NUMBER / 10000\n MONTH = MOD(NUMBER, 10000) / 100\n DAY = MOD(NUMBER, 100)\n END SUBROUTINE CONVERSION\n", "meta": {"hexsha": "5b4e5ed4a1bea96b68252221cda43a4599dbf6c8", "size": 6134, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "EFDC_src/date_time.f90", "max_stars_repo_name": "T-Carlotto/SW2D-EFDC", "max_stars_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2018-03-31T22:19:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T01:35:23.000Z", "max_issues_repo_path": "EFDC_src/date_time.f90", "max_issues_repo_name": "T-Carlotto/SW2D-EFDC", "max_issues_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-04-02T06:13:13.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-10T07:15:07.000Z", "max_forks_repo_path": "EFDC_src/date_time.f90", "max_forks_repo_name": "T-Carlotto/SW2D-EFDC", "max_forks_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2018-06-27T02:55:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-09T07:51:23.000Z", "avg_line_length": 37.1757575758, "max_line_length": 77, "alphanum_fraction": 0.4129442452, "num_tokens": 1701, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.929440403812707, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.789997558030702}} {"text": "! Ricker wavelet\nsubroutine ricker(nt,f0,dt,source)\n implicit none\n integer :: nt, it\n real (kind=8) :: f0, pt, a_ricker, dt, t0,t\n real (kind=8),dimension(nt) :: source, temp\n\n source = 0\n temp = 0\n pt = 1 / f0\n t0=pt/dt\n a_ricker=4./pt\n\n do it=1,nt+1\n t=(it-t0)*dt\n temp(it) = -2.*a_ricker*t*exp(-(a_ricker*t)**2)\n enddo\n\n do it=1,nt\n source(it) = temp(it+1) - temp(it)\n end do\n\n source = -source\n\n\nEND subroutine ricker\n", "meta": {"hexsha": "0cc3a7c02b260ca28f624793b01fcc11883be4c1", "size": 525, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ricker.f90", "max_stars_repo_name": "musbenziane/SEM1D", "max_stars_repo_head_hexsha": "6fa594662fd2b2403c584ca8781964bc40ef888b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-08T19:47:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-08T19:47:07.000Z", "max_issues_repo_path": "ricker.f90", "max_issues_repo_name": "musbenziane/SEM1D", "max_issues_repo_head_hexsha": "6fa594662fd2b2403c584ca8781964bc40ef888b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ricker.f90", "max_forks_repo_name": "musbenziane/SEM1D", "max_forks_repo_head_hexsha": "6fa594662fd2b2403c584ca8781964bc40ef888b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-08T19:47:12.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-08T19:47:12.000Z", "avg_line_length": 19.4444444444, "max_line_length": 62, "alphanum_fraction": 0.5085714286, "num_tokens": 191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404018582427, "lm_q2_score": 0.84997116805678, "lm_q1q2_score": 0.7899975440066135}} {"text": "subroutine eigenvalueprob(NDIM,A,W,WORK,workmax,A_OLD)\nimplicit none\n\n!Global variables\n\nINTEGER, INTENT(IN) :: NDIM, workmax\nREAL(kind=4), intent(out) :: WORK(workmax), W(NDIM)\nREAL(kind=4), intent(inout) ::A(NDIM,NDIM),A_OLD(NDIM,NDIM)\n\n\n!Local Variables\ninteger :: LDA,LWORK, INFO, J, I\nreal(kind=4) :: eps\nreal(kind=4) :: slamch\nCHARACTER :: JOBZ,UPLO\nREAL ZERO\nPARAMETER ( ZERO = 0.0 )\nreal(kind=4) :: cpu_sekunden, st0, ste\n\n external slamch\n external ssyev\n\n eps = slamch('e')\n print*,' relative machine precision epsilon ',&\n ' eps = ',eps\n\n JOBZ = 'V'\n UPLO = 'U'\n\n LDA = NDIM\n\n LWORK = workmax\n\n\n call cpu_time(st0)\n!--------------------------------!\n\n CALL ssyev(JOBZ,UPLO,NDIM,A,LDA,W,WORK, LWORK, INFO)\n!--------------------------------! \n\n \n print*,' LAPACK INFO = ',info\n\n IF( INFO.GT.0 ) THEN\n WRITE(*,*)'The calculation was unsuccessfull.'\n STOP\n END IF\n\n print*,' '\n\n!-------------------------! \n PRINT*,' Eigenvalues :'\n PRINT*,' '\n DO J = 1, NDIM\n WRITE(*,*) W( J )\n END DO\n WRITE(*,*)\n\n!-------------------------!\n WRITE(*,*) 'Eigenvectors:'\n WRITE(*,*) 'Columnwise saved'\n do i = 1, ndim\n write(*,*)(A(i,j),j=1,ndim)\n end do\n\n call cpu_time(ste)\n cpu_sekunden = (ste - st0)\n print*, ''\n print*,' CPU Time: ',cpu_sekunden\n\n!---------------------------!\n\n\n\n\nend subroutine eigenvalueprob", "meta": {"hexsha": "163eeb36c57694ad920b376f1eb2c52db31d867b", "size": 1495, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "eingenvalueprob.f90", "max_stars_repo_name": "bypasser11/Eigenvalue_Solver_LAPACK", "max_stars_repo_head_hexsha": "014672951f490a6e399d3d8e85899345ebb69be3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "eingenvalueprob.f90", "max_issues_repo_name": "bypasser11/Eigenvalue_Solver_LAPACK", "max_issues_repo_head_hexsha": "014672951f490a6e399d3d8e85899345ebb69be3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "eingenvalueprob.f90", "max_forks_repo_name": "bypasser11/Eigenvalue_Solver_LAPACK", "max_forks_repo_head_hexsha": "014672951f490a6e399d3d8e85899345ebb69be3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.6710526316, "max_line_length": 60, "alphanum_fraction": 0.4989966555, "num_tokens": 466, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.78998413108909}} {"text": "FUNCTION random_gamma(s, b, first) RESULT(fn_val)\r\n\r\n! Adapted from Fortran 77 code from the book:\r\n! Dagpunar, J. 'Principles of random variate generation'\r\n! Clarendon Press, Oxford, 1988. ISBN 0-19-852202-9\r\n\r\n! N.B. This version is in `double precision' and includes scaling\r\n\r\n! FUNCTION GENERATES A RANDOM GAMMA VARIATE.\r\n! CALLS EITHER random_gamma1 (S > 1.0)\r\n! OR random_exponential (S = 1.0)\r\n! OR random_gamma2 (S < 1.0).\r\n\r\n! S = SHAPE PARAMETER OF DISTRIBUTION (0 < REAL).\r\n! B = Scale parameter\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n\r\nREAL (dp), INTENT(IN) :: s, b\r\nLOGICAL, INTENT(IN) :: first\r\nREAL (dp) :: fn_val\r\n\r\n! Local parameters\r\nREAL (dp), PARAMETER :: one = 1.0_dp, zero = 0.0_dp\r\n\r\nIF (s <= zero) THEN\r\n WRITE(*, *) 'SHAPE PARAMETER VALUE MUST BE POSITIVE'\r\n STOP\r\nEND IF\r\n\r\nIF (s >= one) THEN\r\n fn_val = random_gamma1(s, first)\r\nELSE IF (s < one) THEN\r\n fn_val = random_gamma2(s, first)\r\nEND IF\r\n\r\n! Now scale the random variable\r\nfn_val = b * fn_val\r\nRETURN\r\n\r\nCONTAINS\r\n\r\n\r\nFUNCTION random_gamma1(s, first) RESULT(fn_val)\r\n\r\n! Adapted from Fortran 77 code from the book:\r\n! Dagpunar, J. 'Principles of random variate generation'\r\n! Clarendon Press, Oxford, 1988. ISBN 0-19-852202-9\r\n\r\n! FUNCTION GENERATES A RANDOM VARIATE IN [0,INFINITY) FROM\r\n! A GAMMA DISTRIBUTION WITH DENSITY PROPORTIONAL TO GAMMA**(S-1)*EXP(-GAMMA),\r\n! BASED UPON BEST'S T DISTRIBUTION METHOD\r\n\r\n! S = SHAPE PARAMETER OF DISTRIBUTION\r\n! (1.0 < REAL)\r\n\r\nREAL (dp), INTENT(IN) :: s\r\nLOGICAL, INTENT(IN) :: first\r\nREAL (dp) :: fn_val\r\n\r\n! Local variables\r\nREAL (dp) :: d, r, g, f, x\r\nREAL (dp), SAVE :: b, h\r\nREAL (dp), PARAMETER :: sixty4 = 64.0_dp, three = 3.0_dp, pt75 = 0.75_dp, &\r\n two = 2.0_dp, half = 0.5_dp\r\n\r\nIF (s <= one) THEN\r\n WRITE(*, *) 'IMPERMISSIBLE SHAPE PARAMETER VALUE'\r\n STOP\r\nEND IF\r\n\r\nIF (first) THEN ! Initialization, if necessary\r\n b = s - one\r\n h = SQRT(three*s - pt75)\r\nEND IF\r\n\r\nDO\r\n CALL RANDOM_NUMBER(r)\r\n g = r - r*r\r\n IF (g <= zero) CYCLE\r\n f = (r - half)*h/SQRT(g)\r\n x = b + f\r\n IF (x <= zero) CYCLE\r\n CALL RANDOM_NUMBER(r)\r\n d = sixty4*g*(r*g)**2\r\n IF (d <= zero) EXIT\r\n IF (d*x < x - two*f*f) EXIT\r\n IF (LOG(d) < two*(b*LOG(x/b) - f)) EXIT\r\nEND DO\r\nfn_val = x\r\n\r\nRETURN\r\nEND FUNCTION random_gamma1\r\n\r\n\r\n\r\nFUNCTION random_gamma2(s, first) RESULT(fn_val)\r\n\r\n! Adapted from Fortran 77 code from the book:\r\n! Dagpunar, J. 'Principles of random variate generation'\r\n! Clarendon Press, Oxford, 1988. ISBN 0-19-852202-9\r\n\r\n! FUNCTION GENERATES A RANDOM VARIATE IN [0,INFINITY) FROM\r\n! A GAMMA DISTRIBUTION WITH DENSITY PROPORTIONAL TO\r\n! GAMMA2**(S-1) * EXP(-GAMMA2),\r\n! USING A SWITCHING METHOD.\r\n\r\n! S = SHAPE PARAMETER OF DISTRIBUTION\r\n! (REAL < 1.0)\r\n\r\nREAL (dp), INTENT(IN) :: s\r\nLOGICAL, INTENT(IN) :: first\r\nREAL (dp) :: fn_val\r\n\r\n! Local variables\r\nREAL (dp) :: r, x, w\r\nREAL (dp), SAVE :: a, p, c, uf, vr, d\r\nREAL (dp), PARAMETER :: vsmall = EPSILON(one)\r\n\r\nIF (s <= zero .OR. s >= one) THEN\r\n WRITE(*, *) 'SHAPE PARAMETER VALUE OUTSIDE PERMITTED RANGE'\r\n STOP\r\nEND IF\r\n\r\nIF (first) THEN ! Initialization, if necessary\r\n a = one - s\r\n p = a/(a + s*EXP(-a))\r\n IF (s < vsmall) THEN\r\n WRITE(*, *) 'SHAPE PARAMETER VALUE TOO SMALL'\r\n STOP\r\n END IF\r\n c = one/s\r\n uf = p*(vsmall/a)**s\r\n vr = one - vsmall\r\n d = a*LOG(a)\r\nEND IF\r\n\r\nDO\r\n CALL RANDOM_NUMBER(r)\r\n IF (r >= vr) THEN\r\n CYCLE\r\n ELSE IF (r > p) THEN\r\n x = a - LOG((one - r)/(one - p))\r\n w = a*LOG(x)-d\r\n ELSE IF (r > uf) THEN\r\n x = a*(r/p)**c\r\n w = x\r\n ELSE\r\n fn_val = zero\r\n RETURN\r\n END IF\r\n\r\n CALL RANDOM_NUMBER(r)\r\n IF (one-r <= w .AND. r > zero) THEN\r\n IF (r*(w + one) >= one) CYCLE\r\n IF (-LOG(r) <= w) CYCLE\r\n END IF\r\n EXIT\r\nEND DO\r\n\r\nfn_val = x\r\nRETURN\r\n\r\nEND FUNCTION random_gamma2\r\n\r\nEND FUNCTION random_gamma\r\n\r\n\r\n\r\nPROGRAM demo_gamma\r\n! Demo program to generate a small smaple of random gamma's\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n\r\nREAL (dp) :: shape, scale, rg(100), avge, mean\r\nLOGICAL :: first\r\nINTEGER :: i, order(100)\r\n\r\nINTERFACE\r\n FUNCTION random_gamma(s, b, first) RESULT(fn_val)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n REAL (dp), INTENT(IN) :: s, b\r\n LOGICAL, INTENT(IN) :: first\r\n REAL (dp) :: fn_val\r\n END FUNCTION random_gamma\r\n\r\n RECURSIVE SUBROUTINE quick_sort(list, order)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n REAL (dp), DIMENSION (:), INTENT(IN OUT) :: list\r\n INTEGER, DIMENSION (:), INTENT(OUT) :: order\r\n END SUBROUTINE quick_sort\r\nEND INTERFACE\r\n\r\nWRITE(*, '(a)', ADVANCE='NO') ' Enter the shape & scale parameter values: '\r\nREAD(*, *) shape, scale\r\n\r\nfirst = .TRUE.\r\nDO i = 1, 100\r\n rg(i) = random_gamma(shape, scale, first)\r\n first = .FALSE.\r\nEND DO\r\n\r\nCALL quick_sort(rg, order)\r\nWRITE(*, '(\" \", 10f7.3)') rg\r\n\r\nmean = shape * scale\r\navge = SUM( rg ) / 100._dp\r\nWRITE(*, '(a, g12.5, a, g12.5)') &\r\n ' Population mean = ', mean, ' Sample mean = ', avge\r\n\r\nSTOP\r\nEND PROGRAM demo_gamma\r\n\r\n\r\n\r\nRECURSIVE SUBROUTINE quick_sort(list, order)\r\n\r\n! Quick sort routine from:\r\n! Brainerd, W.S., Goldberg, C.H. & Adams, J.C. (1990) \"Programmer's Guide to\r\n! Fortran 90\", McGraw-Hill ISBN 0-07-000248-7, pages 149-150.\r\n! Modified by Alan Miller to include an associated integer array which gives\r\n! the positions of the elements in the original order.\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n\r\nREAL (dp), DIMENSION (:), INTENT(IN OUT) :: list\r\nINTEGER, DIMENSION (:), INTENT(OUT) :: order\r\n\r\n! Local variable\r\nINTEGER :: i\r\n\r\nDO i = 1, SIZE(list)\r\n order(i) = i\r\nEND DO\r\n\r\nCALL quick_sort_1(1, SIZE(list))\r\nRETURN\r\n\r\n\r\nCONTAINS\r\n\r\n\r\nRECURSIVE SUBROUTINE quick_sort_1(left_end, right_end)\r\n\r\nINTEGER, INTENT(IN) :: left_end, right_end\r\n\r\n! Local variables\r\nINTEGER :: i, j, itemp\r\nREAL (dp) :: reference, temp\r\nINTEGER, PARAMETER :: max_simple_sort_size = 6\r\n\r\nIF (right_end < left_end + max_simple_sort_size) THEN\r\n ! Use interchange sort for small lists\r\n CALL interchange_sort(left_end, right_end)\r\n\r\nELSE\r\n ! Use partition (\"quick\") sort\r\n reference = list((left_end + right_end)/2)\r\n i = left_end - 1\r\n j = right_end + 1\r\n\r\n DO\r\n ! Scan list from left end until element >= reference is found\r\n DO\r\n i = i + 1\r\n IF (list(i) >= reference) EXIT\r\n END DO\r\n ! Scan list from right end until element <= reference is found\r\n DO\r\n j = j - 1\r\n IF (list(j) <= reference) EXIT\r\n END DO\r\n\r\n\r\n IF (i < j) THEN\r\n ! Swap two out-of-order elements\r\n temp = list(i)\r\n list(i) = list(j)\r\n list(j) = temp\r\n itemp = order(i)\r\n order(i) = order(j)\r\n order(j) = itemp\r\n ELSE IF (i == j) THEN\r\n i = i + 1\r\n EXIT\r\n ELSE\r\n EXIT\r\n END IF\r\n END DO\r\n\r\n IF (left_end < j) CALL quick_sort_1(left_end, j)\r\n IF (i < right_end) CALL quick_sort_1(i, right_end)\r\nEND IF\r\n\r\nRETURN\r\nEND SUBROUTINE quick_sort_1\r\n\r\n\r\nSUBROUTINE interchange_sort(left_end, right_end)\r\n\r\nINTEGER, INTENT(IN) :: left_end, right_end\r\n\r\n! Local variables\r\nINTEGER :: i, j, itemp\r\nREAL (dp) :: temp\r\n\r\nDO i = left_end, right_end - 1\r\n DO j = i+1, right_end\r\n IF (list(i) > list(j)) THEN\r\n temp = list(i)\r\n list(i) = list(j)\r\n list(j) = temp\r\n itemp = order(i)\r\n order(i) = order(j)\r\n order(j) = itemp\r\n END IF\r\n END DO\r\nEND DO\r\n\r\nRETURN\r\nEND SUBROUTINE interchange_sort\r\n\r\nEND SUBROUTINE quick_sort\r\n", "meta": {"hexsha": "5b67364bee83c37b0bf927c3bee6d87a8116c6a7", "size": 7842, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/r_gamma.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/r_gamma.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/r_gamma.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 23.8358662614, "max_line_length": 78, "alphanum_fraction": 0.5933435348, "num_tokens": 2467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320037, "lm_q2_score": 0.8633916117313211, "lm_q1q2_score": 0.7899178040958653}} {"text": "!=====================================================================!\n! Module containing test problems for Newton's method\n!=====================================================================!\n\nmodule test_problems\n\n implicit none\n\ncontains\n \n ! f = 2x^2 -5\n pure function f1(x) \n real(8), intent(in) :: x(:)\n real(8) :: f1(size(x))\n f1 = 2.0d0*x*x - 5.0d0 \n end function f1\n\n ! dfdx = 4x\n pure function dfdx1(x)\n real(8), intent(in) :: x(:)\n real(8) :: dfdx1(size(x),size(x))\n dfdx1(1,1) = 4.0d0*x(1)\n end function dfdx1\n\n ! f = sin(x) + x\n pure function f2(x) \n real(8), intent(in) :: x(:)\n real(8) :: f2(size(x))\n f2 = sin(x) + x\n end function f2\n\n ! dfdx = cos(x) + 1\n pure function dfdx2(x)\n real(8), intent(in) :: x(:)\n real(8) :: dfdx2(size(x),size(x))\n dfdx2(1,1) = cos(x(1)) + 1.0d0\n end function dfdx2\n\n ! f = cos(x)\n pure function f3(x) \n real(8), intent(in) :: x(:)\n real(8) :: f3(size(x))\n f3 = cos(x)\n end function f3\n\n ! dfdx = sin(x)\n pure function dfdx3(x)\n real(8), intent(in) :: x(:)\n real(8) :: dfdx3(size(x),size(x))\n dfdx3(1,1) = -sin(x(1))\n end function dfdx3\n\n ! Chandrasekhar H equations\n function chandra_res(x)\n\n real(8), intent(in) :: x(:)\n real(8) :: chandra_res(size(x)) \n integer, parameter :: N = 200\n real(8), parameter :: c = 0.9d0\n\n if ( n .ne. 200) stop \"variable-mismatch\"\n \n assemble: block\n \n real(8) :: mui, muj, alpha, beta\n integer :: i, j\n\n do i = 1, N\n \n mui = (dble(i) - 0.5d0)/dble(N)\n\n ! Find the term within integral\n alpha = 0.0d0\n do j = 1, N\n muj = (dble(j) - 0.5d0)/dble(N)\n alpha = mui*x(j)/(mui+muj)\n end do\n\n ! Evaluate the inverse term\n beta = 1.0d0 - c*alpha/(2.0d0*dble(N))\n\n ! Assmble residual\n chandra_res(i) = x(i) - 1.0d0/beta\n \n end do\n\n end block assemble\n\n end function chandra_res\n\n !===================================================================!\n ! Finite difference approximation for jacobian\n !===================================================================!\n \n function chandra_jac(x)\n\n use nonlinear_algebra, only : diffjac\n \n real(8), intent(in) :: x(:)\n real(8) :: chandra_jac(size(x),size(x))\n integer, parameter :: N = 200\n \n call diffjac(x, chandra_res, chandra_jac)\n \n end function chandra_jac\n\nend module test_problems\n\n!=====================================================================!\n! Main program to solve the test problems using different methods\n!=====================================================================!\n\nprogram test_nonlinear\n \n use test_problems, only : f1, f2, f3, dfdx1, dfdx2, dfdx3, &\n & chandra_res, chandra_jac\n \n use nonlinear_algebra, only : newton, secant, chord, fixed_point, &\n & shamanskii\n\n implicit none\n \n real(8), parameter :: tau_r = 1.0d-6\n real(8), parameter :: tau_a = 1.0d-6\n integer, parameter :: maxit = 100\n \n integer :: iter, flag\n real(8) :: tol\n\n ! Test nonlinear solvers on chandrasekhar method\n test_chandra: block\n\n integer, parameter :: npts = 200\n real(8) :: x(npts,4)\n\n print *, \"Chandrasekhar Equation using Newton method\"\n \n x(:,1) = 2.0d0\n call newton(chandra_res, chandra_jac, tau_r, tau_a, maxit, x(:,1))\n !print *, x(:,1)\n\n print *, \"Chandrasekhar Equation using chord method\"\n x(:,2) = 1.0d0\n call chord(chandra_res, chandra_jac, tau_r, tau_a, maxit, x(:,2))\n !print *, x(:,2)\n\n print *, \"Chandrasekhar Equation using fixed point method\"\n x(:,3) = 1.0d0\n call fixed_point(chandra_res, tau_r, tau_a, maxit, x(:,3))\n !print *, x(:,3)\n\n print *, \"Chandrasekhar Equation using shamanskii method\"\n x(:,4) = 1.0d0\n call shamanskii(chandra_res, chandra_jac, 2, tau_r, tau_a, maxit, x(:,4))\n !print *, x(:,4)\n\n end block test_chandra\n\n test_f1 : block\n\n integer, parameter :: npts = 1\n real(8) :: x(npts), x0(npts)\n\n print *, \"function 1 using newton method\"\n x = 10.0d0\n call newton(f1, dfdx1, tau_r, tau_a, maxit, x)\n print *, x\n\n print *, \"function 1 using secant method\"\n x = 10.0d0\n x0 = 0.99d0*x\n call secant(f1, tau_r, tau_a, maxit, x0, x)\n print *, x\n\n print *, \"function 1 using chord method\"\n x = 10.0d0\n call chord(f1, dfdx1, tau_r, tau_a, maxit, x)\n print *, x\n\n end block test_f1\n\n test_f2: block\n\n integer, parameter :: npts = 1\n real(8) :: x(npts), x0(npts)\n\n print *, \"function 2 using newton method\"\n x = 0.5d0\n call newton(f2, dfdx2, tau_r, tau_a, maxit, x)\n print *, x\n\n print *, \"function 2 using secant method\"\n x = 0.5d0\n x0 = 0.99d0*x\n call secant(f2, tau_r, tau_a, maxit, x0, x)\n print *, x\n\n print *, \"function 2 using chord method\"\n x = 0.5d0\n call chord(f2, dfdx2, tau_r, tau_a, maxit, x)\n print *, x\n\n end block test_f2\n \n test_f3: block\n\n integer, parameter :: npts = 1\n real(8) :: x(npts), x0(npts)\n\n print *, \"function 3 using newton method\"\n x = 3.0d0\n call newton(f3, dfdx3, tau_r, tau_a, maxit, x)\n print *, x\n\n print *, \"function 3 using secant method\"\n x = 3.0d0\n x0 = 0.99d0*x\n call secant(f3, tau_r, tau_a, maxit, x0, x)\n print *, x\n\n print *, \"function 3 using chord method\"\n x = 3.0d0\n call chord(f3, dfdx3, tau_r, tau_a, maxit, x)\n print *, x\n\n end block test_f3\n\nend program test_nonlinear\n", "meta": {"hexsha": "ed6652f9bdf3fb38bc08d71bbc00ab5b790001f9", "size": 5495, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/nonlinear/test.f90", "max_stars_repo_name": "komahanb/math6644-iterative-methods", "max_stars_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-03-19T16:36:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-14T21:29:38.000Z", "max_issues_repo_path": "test/nonlinear/test.f90", "max_issues_repo_name": "komahanb/math6644-iterative-methods", "max_issues_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/nonlinear/test.f90", "max_forks_repo_name": "komahanb/math6644-iterative-methods", "max_forks_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-23T02:14:36.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-23T02:14:36.000Z", "avg_line_length": 23.9956331878, "max_line_length": 77, "alphanum_fraction": 0.5348498635, "num_tokens": 1859, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900957313305, "lm_q2_score": 0.863391595913457, "lm_q1q2_score": 0.789917797637484}} {"text": "program insertion\nimplicit none\n\n!-----------------------------------------------------------------\n! This programme sorts a series of values in increasing order,\n! using insertion sort, implemented with one working array\n!\n! It works like this:\n! unsorted: A = [5, 3, 4, 1, 2, 6]\n! sorting:\n! pass 1: A = [3, 5, 4, 1, 2, 6]\n! pass 2: A = [3, 4, 5, 1, 2, 6]\n! pass 3: A = [1, 3, 4, 5, 2, 6]\n! pass 4: A = [1, 2, 3, 4, 5, 6]\n! pass 5: B = [1, 2, 3, 4, 5, 6]\n!------------------------------------------------------\n\nreal(kind=8), allocatable, dimension(:) :: A\nreal :: temp\ninteger :: i, j, k, n\n\n!------------------------------------------------------------\n! Make some random array:\n!------------------------------------------------------------\n\nwrite(*,*) 'size od array?'\nread(*,*) n\nallocate (A(n))\n\ncall random_seed()\ndo i = 1, n\n call random_number(A(i))\n A(i) = (A(i) * 100.0)\n A(i) = real(nint(A(i)*1000)) / 1000.0 !rounding off to 3 decimal places\nend do\n\n!------------------------------------------------------------\n! Prepare output file:\n!------------------------------------------------------------\n\nopen(unit=1, file='insert', status='replace', action='write')\nwrite(1,*) 'here you can see the details of how the loops and conditionals'\nwrite(1,*) 'really work'\n\nwrite(1,*)\nwrite(1,*) '(using one array)'\nwrite(1,*)\nwrite(1,'(A3,10F7.3)') ' A ', A\nwrite(*,'(A3,10F7.3)') ' A ', A\nwrite(1,*)\n\n!------------------------------------------------------------\n! The actual sorting:\n!------------------------------------------------------------\n\ndo i = 2, n\n write (1,*) 'i', i\n do j = 1, i-1 \n write(1,*) ' j', j\n if (A(j) .ge. A(i)) then\n write(1,*) 'found it'\n temp = A(i)\n do k = i-1, j, -1 !from the last value different from 0, to \n! the first one greater than i\n A(k+1) = A(k) !move every element by one\n write(1,*) ' k', k\n end do\n A(j) = temp\n exit\n end if\n end do\n write(1,'(I4,10F7.3)') i, A\n write(1,*) \n write(*,'(I4,10F7.3)') i, A\nend do\n\nend program insertion\n", "meta": {"hexsha": "6a52e8a8d91ed59188c2bb1621a428205cb9d290", "size": 2125, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "insertion_sort/insertion1array_writes.f95", "max_stars_repo_name": "ElenaKusevska/Fortran_exercises", "max_stars_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "insertion_sort/insertion1array_writes.f95", "max_issues_repo_name": "ElenaKusevska/Fortran_exercises", "max_issues_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "insertion_sort/insertion1array_writes.f95", "max_forks_repo_name": "ElenaKusevska/Fortran_exercises", "max_forks_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.2435897436, "max_line_length": 75, "alphanum_fraction": 0.4117647059, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.888758786126321, "lm_q1q2_score": 0.7898921917008238}} {"text": "! Created by EverLookNeverSee@GitHub on 4/15/20.\n! This program calculates the roots of a quadratic equaion.\n\nprogram roots\n implicit none\n ! defining variables\n real :: a, b, c, x_1, x_2, delta, sr_delta\n ! getting user input\n print *, \"Enter the values of a, b, c:\"\n read *, a, b, c\n ! calculating delta\n delta = (b ** 2) - (4.0 * a * c)\n if (delta > 0.0) then\n sr_delta = sqrt(delta)\n x_1 = (-b + sr_delta) / (2.0 * a)\n x_2 = (-b - sr_delta) / (2.0 * a)\n print *, \"roots are:\", x_1, x_2\n elseif (delta == 0.0) then\n x_1 = -b / (2.0 * a)\n x_2 = x_1\n print *, \"roots are equal:\", x_1, x_2\n else ! value of delta is less than 0.0\n print *, \"This quadratic equation has no real root.\"\n end if\nend program roots", "meta": {"hexsha": "82ea72b6ee1d3af26997842c09e779b3b5295cff", "size": 805, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/other/roots.f90", "max_stars_repo_name": "EverLookNeverSee/FCS", "max_stars_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-14T10:30:25.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-17T13:03:15.000Z", "max_issues_repo_path": "src/other/roots.f90", "max_issues_repo_name": "EverLookNeverSee/FCS", "max_issues_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-06-06T13:54:45.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-25T20:32:23.000Z", "max_forks_repo_path": "src/other/roots.f90", "max_forks_repo_name": "EverLookNeverSee/FCS", "max_forks_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-08T12:57:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T12:57:46.000Z", "avg_line_length": 32.2, "max_line_length": 60, "alphanum_fraction": 0.5552795031, "num_tokens": 275, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191348157373, "lm_q2_score": 0.826711791935942, "lm_q1q2_score": 0.789773593814212}} {"text": "SUBROUTINE interp_lin (x, y, x_int, y_int)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Subroutine: interp_lin.f90\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Linear interpolation based on two data points\r\n! ----------------------------------------------------------------------\r\n! Input arguments:\r\n! - x:\t\t\tArray with two values of the x variable\r\n! - y:\t\t\tArray with two values of the y variable given as a \r\n! function of x. y = f(x)\r\n! - x_int:\t\tValue of x variable that the interpolation of y is required \r\n!\r\n! Output arguments:\r\n! - y_int:\t\tInterpolated value of y variable at the value x_int\r\n! ----------------------------------------------------------------------\r\n! Dr. Thomas Papanikolaou, Geoscience Australia March 2016\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n USE mdl_precision\r\n USE mdl_num\r\n IMPLICIT NONE\r\n\r\n! ----------------------------------------------------------------------\r\n! Dummy arguments declaration\r\n! ----------------------------------------------------------------------\r\n! IN\r\n REAL (KIND = prec_d), INTENT(IN) :: x(2), y(2), x_int\r\n! OUT\r\n REAL (KIND = prec_d), INTENT(OUT) :: y_int\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n y_int = y(1) + ( x_int - x(1) ) * ( (y(2) - y(1)) / (x(2) - x(1)) )\r\n! ----------------------------------------------------------------------\r\n\r\n\r\nEND\r\n", "meta": {"hexsha": "37acc19b6f2f9cb74db5e9e40d32dcfbfa5f002d", "size": 1605, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/interp_lin.f90", "max_stars_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_stars_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2021-07-08T23:35:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:17:58.000Z", "max_issues_repo_path": "src/fortran/interp_lin.f90", "max_issues_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_issues_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-09-27T14:27:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T23:50:02.000Z", "max_forks_repo_path": "src/fortran/interp_lin.f90", "max_forks_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_forks_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2021-07-12T05:42:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T15:15:34.000Z", "avg_line_length": 37.3255813953, "max_line_length": 74, "alphanum_fraction": 0.3239875389, "num_tokens": 301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191284552529, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.7897735926346241}} {"text": "MODULE MathConstants\r\n\r\n SAVE\r\n REAL (KIND=8), PARAMETER :: pi = 3.1415926535898D0, RadDeg = 180.0D0 / pi, DegRad = pi / 180.0D0\r\n COMPLEX (KIND=8), PARAMETER :: i = ( 0.0D0, 1.0D0 )\r\n\r\nEND MODULE MathConstants\r\n\r\n", "meta": {"hexsha": "ba3d31496cead6ca7b108b63e394eb536055c49a", "size": 224, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "at_2020_11_4/misc/MathConstants.f90", "max_stars_repo_name": "IvanaEscobar/sandbox", "max_stars_repo_head_hexsha": "71d62af2c112686c5ce26def35593247cf6a0ccc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "at_2020_11_4/misc/MathConstants.f90", "max_issues_repo_name": "IvanaEscobar/sandbox", "max_issues_repo_head_hexsha": "71d62af2c112686c5ce26def35593247cf6a0ccc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2022-02-15T23:32:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T21:35:12.000Z", "max_forks_repo_path": "at_2020_11_4/misc/MathConstants.f90", "max_forks_repo_name": "IvanaEscobar/sandbox", "max_forks_repo_head_hexsha": "71d62af2c112686c5ce26def35593247cf6a0ccc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.8888888889, "max_line_length": 103, "alphanum_fraction": 0.6205357143, "num_tokens": 91, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.93812402119614, "lm_q2_score": 0.8418256472515684, "lm_q1q2_score": 0.7897368613456847}} {"text": "!> \\file p80.f90\n!! \\BRIEF \n!> Module with p80 function - compute pressure from depth\nMODULE mp80\nCONTAINS\n!> Function to compute pressure from depth using Saunder's (1981) formula with eos80.\nFUNCTION p80(dpth,xlat)\n\n ! Compute Pressure from depth using Saunder's (1981) formula with eos80.\n\n ! Reference:\n ! Saunders, Peter M. (1981) Practical conversion of pressure\n ! to depth, J. Phys. Ooceanogr., 11, 573-574, (1981)\n\n ! Coded by:\n ! R. Millard\n ! March 9, 1983\n ! check value: p80=7500.004 dbars at lat=30 deg., depth=7321.45 meters\n\n ! Modified (slight format changes + added ref. details):\n ! J. Orr, 16 April 2009\n\n USE msingledouble\n IMPLICIT NONE\n\n! Input variables:\n !> depth [m]\n REAL(kind=rx), INTENT(in) :: dpth\n !> latitude [degrees]\n REAL(kind=rx), INTENT(in) :: xlat\n\n! Output variable:\n !> pressure [db]\n REAL(kind=rx) :: p80\n\n! Local variables:\n REAL(kind=rx) :: pi\n REAL(kind=rx) :: plat, d, c1\n\n pi=3.141592654\n\n plat = ABS(xlat*pi/180.)\n d = SIN(plat)\n c1 = 5.92e-3+d**2 * 5.25e-3\n\n p80 = ((1-c1)-SQRT(((1-c1)**2)-(8.84e-6*dpth))) / 4.42e-6\n\n RETURN\nEND FUNCTION p80\nEND MODULE mp80\n", "meta": {"hexsha": "8efd55242e47cc7e7070d30bedcf81366e748f48", "size": 1178, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/p80.f90", "max_stars_repo_name": "tomaslovato/mocsy", "max_stars_repo_head_hexsha": "ede19cde4be5cd37ed192a3f3394e81302d11616", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2017-06-20T13:08:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-04T09:51:49.000Z", "max_issues_repo_path": "src/p80.f90", "max_issues_repo_name": "tomaslovato/mocsy", "max_issues_repo_head_hexsha": "ede19cde4be5cd37ed192a3f3394e81302d11616", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-11-12T19:46:14.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-23T14:57:14.000Z", "max_forks_repo_path": "src/p80.f90", "max_forks_repo_name": "tomaslovato/mocsy", "max_forks_repo_head_hexsha": "ede19cde4be5cd37ed192a3f3394e81302d11616", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2015-11-01T01:06:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-04T12:58:24.000Z", "avg_line_length": 23.0980392157, "max_line_length": 89, "alphanum_fraction": 0.6298811545, "num_tokens": 423, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763574, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.789736855520434}} {"text": "real, dimension(n,m) :: a = reshape( [ (i, i=1, n*m) ], [ n, m ] )\nreal, dimension(m,k) :: b = reshape( [ (i, i=1, m*k) ], [ m, k ] )\nreal, dimension(size(a,1), size(b,2)) :: c ! C is an array whose first dimension (row) size\n ! is the same as A's first dimension size, and\n ! whose second dimension (column) size is the same\n ! as B's second dimension size.\n\nc = matmul( a, b )\n\nprint *, 'A'\ndo i = 1, n\n print *, a(i,:)\nend do\n\nprint *,\nprint *, 'B'\ndo i = 1, m\n print *, b(i,:)\nend do\n\nprint *,\nprint *, 'C = AB'\ndo i = 1, n\n print *, c(i,:)\nend do\n", "meta": {"hexsha": "f2c0d858c526a96593293d2e050890c64673294b", "size": 699, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Matrix-multiplication/Fortran/matrix-multiplication-1.f", "max_stars_repo_name": "mullikine/RosettaCodeData", "max_stars_repo_head_hexsha": "4f0027c6ce83daa36118ee8b67915a13cd23ab67", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-05T13:42:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T13:42:20.000Z", "max_issues_repo_path": "Task/Matrix-multiplication/Fortran/matrix-multiplication-1.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Matrix-multiplication/Fortran/matrix-multiplication-1.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.8846153846, "max_line_length": 96, "alphanum_fraction": 0.4406294707, "num_tokens": 207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.965899577232538, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7896948409115542}} {"text": "! Modern Fortran statistical computations module\nmodule stats_module\ncontains\n ! function returns real mean of all array elements\n function mean(x, n) result(m)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n real, intent(in), dimension(n) :: x\n ! function result location\n real :: m\n ! processing\n m = sum(x) / n\n end function mean\n\n ! function returns array of deviations about central tendency m\n function compute_dev(x, m, n) result(dev)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n real, intent(in) :: m\n real, dimension(n), intent(in) :: x\n ! function result location\n real, dimension(n) :: dev\n ! processing\n dev = x - m\n end function compute_dev\n\n ! function returns array of absolute deviations about central tendency m\n function compute_adev(x, m, n) result(dev)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n real, intent(in) :: m\n real, dimension(n), intent(in) :: x\n ! function result location\n real, dimension(n) :: dev\n ! processing\n dev = abs(x - m)\n end function compute_adev\n\n ! function returns real population variance of x\n function pop_var(x, n) result(var)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n real, intent(in), dimension(n) :: x\n ! function return location\n real :: var\n ! processing\n var = sum(compute_dev(x, mean(x, n), n)**2) / n\n end function pop_var\n\n ! function returns real sample variance of x\n function sam_var(x, n) result(var)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n real, intent(in), dimension(n) :: x\n ! function return location\n real :: var\n ! processing\n var = sum(compute_dev(x, mean(x, n), n)**2) / (n - 1)\n end function sam_var\n\n ! function returns real population standard deviation of x\n function pop_std(x, n) result(std)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n real, intent(in), dimension(n) :: x\n ! function return location\n real :: std\n ! processing\n std = sqrt(pop_var(x, n))\n end function pop_std\n\n ! function returns real sample standard deviation of x\n function sam_std(x, n) result(std)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n real, intent(in), dimension(n) :: x\n ! function return location\n real :: std\n ! processing\n std = sqrt(sam_var(x, n))\n end function sam_std\n\n ! functions returns index of kth element of x\n ! C. A. R. Hoare's algorithm\n ! implementation works on index array only - preserves data set array\n function quick_select(k, n, x) result(v)\n implicit none\n ! dummy arguments\n integer, intent(in) :: k, n\n real, intent(in), dimension(n) :: x\n ! function return location\n real :: v\n ! local variables\n integer :: i, j, left, right, tmp\n integer, dimension(n) :: idx\n real :: pivot\n ! processing\n do i=1,n\n idx(i)=i\n end do\n left=1\n right=n\n do while (left < right)\n pivot=x(idx(k))\n i=left\n j=right\n do\n do while (x(idx(i)) < pivot)\n i=i+1\n end do\n do while (pivot < x(idx(j)))\n j=j-1\n end do\n if (i <= j) then\n tmp=idx(i)\n idx(i)=idx(j)\n idx(j)=tmp\n i=i+1\n j=j-1\n end if\n if (i > j) exit\n end do\n if (j < k) left=i\n if (k < i) right=j\n end do\n v=x(idx(k))\n end function quick_select\n\n ! function returns median of x\n function median(x, n) result(mdn)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n real, intent(in), dimension(n) :: x\n ! function return location\n real :: mdn\n ! processing\n if (mod(n, 2) /= 0) then\n mdn=quick_select(n/2+1, n, x)\n else\n mdn=(quick_select(n/2, n, x) + quick_select(n/2+1, n, x))/2\n end if\n end function median\n\n !funcition returns median absolute deviation of x\n function median_deviation(x, n) result(mad)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n real, intent(in), dimension(n) :: x\n ! function return location\n real :: mad\n ! processing\n mad = median( compute_adev(x, median(x, n), n), n )\n end function median_deviation\n\n ! function computes the mean absolute deviation of x\n function mean_deviation(x, n) result(aad)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n real, intent(in), dimension(n) :: x\n ! function return location\n real :: aad\n ! processing\n aad = mean( compute_adev(x, mean(x, n), n), n )\n end function mean_deviation\n\n ! function computes the skewness of x (expected value 1/N)\n function skewness(x, n) result(skw)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n real, intent(in), dimension(n) :: x\n ! function return location\n real :: skw\n ! processing\n skw = sum(compute_dev(x, mean(x, n), n)**3) / ((n - 1) * sam_std(x, n)**3)\n end function skewness\n\n ! function computes the sample covariance of data sets x and y\n function covar(x, y, n) result(cov)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n real, dimension(n), intent(in) :: x, y\n ! function return location\n real :: cov\n ! processing\n cov = sum(compute_dev(x,mean(x,n),n)*compute_dev(y,mean(y,n),n))/(n-1)\n end function covar\n\n ! correlation coefficient of data sets x and y\n function p(x, y, n) result(corr)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n real, dimension(n), intent(in) :: x, y\n ! function return location\n real :: corr\n ! processing\n corr = covar(x, y, n) / (sam_std(x, n) * sam_std(y, n))\n end function p\nend module stats_module\n", "meta": {"hexsha": "a73a011a1b672076ff85f73ddc9be10a2ad6303a", "size": 6123, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "stats_module.f95", "max_stars_repo_name": "joshroybal/presidential_election_stats_fortran", "max_stars_repo_head_hexsha": "c0bf40c11b21a4d9097959d20c84355abc1449f7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "stats_module.f95", "max_issues_repo_name": "joshroybal/presidential_election_stats_fortran", "max_issues_repo_head_hexsha": "c0bf40c11b21a4d9097959d20c84355abc1449f7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "stats_module.f95", "max_forks_repo_name": "joshroybal/presidential_election_stats_fortran", "max_forks_repo_head_hexsha": "c0bf40c11b21a4d9097959d20c84355abc1449f7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.8820754717, "max_line_length": 80, "alphanum_fraction": 0.5788012412, "num_tokens": 1630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611643025387, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7895985106649522}} {"text": "program main\n implicit none\n integer :: clock, i, n\n integer, allocatable :: seed(:)\n integer(4) :: n_in, n_tot = 100000000\n real(8) :: x, y\n real(8) :: pi\n\n call SYSTEM_CLOCK(clock)\n call RANDOM_SEED(size = n)\n allocate(seed(n))\n do i = 1, n\n seed(i) = clock + 37 * i\n end do\n call RANDOM_SEED(put = seed)\n do i = 1, n_tot\n call RANDOM_NUMBER(x)\n x = 2 * x - 1\n call RANDOM_NUMBER(y)\n y = 2 * y - 1\n if (x**2 + y**2 <= 1.d0) then\n n_in = n_in + 1\n end if\n end do\n pi = 4 * dble(n_in) / dble(n_tot)\n write(*,'(f10.8)') pi\nend program main\n", "meta": {"hexsha": "1fc11ae9fc5fbabbae7f1968b2b8c3fa7bc09896", "size": 647, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Week-11-Assignment-3/Exercises/find-pi-1.f90", "max_stars_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_stars_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-15T10:30:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T08:22:51.000Z", "max_issues_repo_path": "Week-11-Assignment-3/Exercises/find-pi-1.f90", "max_issues_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_issues_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Week-11-Assignment-3/Exercises/find-pi-1.f90", "max_forks_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_forks_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.1071428571, "max_line_length": 41, "alphanum_fraction": 0.5069551777, "num_tokens": 229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195636, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.7895841771028688}} {"text": " FUNCTION BESSY0 (X)\n IMPLICIT NONE\n REAL *8 X,BESSY0,BESSJ0,FS,FR,Z,FP,FQ,XX\n! ---------------------------------------------------------------------\n! This subroutine calculates the Second Kind Bessel Function of\n! order 0, for any real number X. The polynomial approximation by\n! series of Chebyshev polynomials is used for 0 0)\n DO WHILE (x < 3.0)\n value = f(x)\n IF(ABS(value) < e) THEN\n WRITE(*,\"(A,F12.9)\") \"Root found at x =\", x\n s = .NOT. s\n ELSE IF ((value > 0) .NEQV. s) THEN\n WRITE(*,\"(A,F12.9)\") \"Root found near x = \", x\n s = .NOT. s\n END IF\n x = x + step\n END DO\n\nEND PROGRAM ROOTS_OF_A_FUNCTION\n", "meta": {"hexsha": "5df4e9efff3399fed92ccde678624909ea362d49", "size": 571, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Roots-of-a-function/Fortran/roots-of-a-function-1.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Roots-of-a-function/Fortran/roots-of-a-function-1.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Roots-of-a-function/Fortran/roots-of-a-function-1.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 21.1481481481, "max_line_length": 52, "alphanum_fraction": 0.534150613, "num_tokens": 238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947163538936, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.7895275223568622}} {"text": "program main1\r\n use Matrix\r\n\r\n implicit none\r\n\r\n! Command-line Args\r\n integer :: argc\r\n\r\n character(len=32) :: matrix_fname, vector_fname\r\n\r\n! Matrices\r\n integer :: m, n, i\r\n double precision, allocatable :: A(:, :)\r\n\r\n! Determinant\r\n double precision :: d\r\n\r\n! Spectral Radius\r\n double precision :: r\r\n\r\n! For LU decomposition & Cholesky also\r\n double precision, allocatable :: L(:, :), U(:, :)\r\n\r\n! For PLU decomposition\r\n double precision, allocatable :: P(:, :)\r\n\r\n! Vectors\r\n integer :: t\r\n double precision, allocatable :: b(:)\r\n double precision, allocatable :: x(:)\r\n double precision, allocatable :: y(:)\r\n\r\n! Error\r\n double precision :: e\r\n\r\n! Get Command-Line Args\r\n matrix_fname = 'matrix.txt'\r\n vector_fname = 'vector.txt'\r\n\r\n argc = iargc()\r\n\r\n if (argc == 1) then\r\n call getarg(1, matrix_fname)\r\n elseif(argc == 2) then\r\n call getarg(1, matrix_fname)\r\n call getarg(2, vector_fname)\r\n elseif (argc > 2) then\r\n goto 92\r\n end if\r\n\r\n call read_matrix(matrix_fname, A, m, n)\r\n call read_vector(vector_fname, b, t)\r\n\r\n if (m /= n) then\r\n goto 90\r\n elseif (m /= t) then\r\n goto 91\r\n end if\r\n\r\n! Print Matrix\r\n! Print Matrix Name\r\n write(*, *) 'A:'\r\n call print_matrix(A, m, n)\r\n\r\n! Print Matrix\r\n! Print Matrix Name\r\n write(*, *) 'b:'\r\n call print_vector(b, t)\r\n\r\n! Print its Determinant\r\n d = det(A, n)\r\n write(*, *) 'Matrix Determinant =', d\r\n\r\n! Print its Spectral Radius\r\n r = spectral_radius(A, n)\r\n write(*, *) 'Spectral Radius =', r\r\n\r\n\r\n if (d == 0.0D0) then\r\n goto 93\r\n endif\r\n\r\n! Decomposition Time!\r\n! Allocate Result Matrices\r\n allocate(P(n, n))\r\n allocate(L(n, n))\r\n allocate(U(n, n))\r\n\r\n! Linear System Time!\r\n! Allocate Result Vectors\r\n allocate(x(n))\r\n allocate(y(n))\r\n\r\n! Try LU Decomposition\r\n call info(':: Decomposição LU (sem pivoteamento) ::')\r\n if (.NOT. LU_DECOMP(A, L, U, n)) then\r\n goto 81\r\n else if (.NOT. LU_solve(A, x, y, b, n)) then\r\n goto 81\r\n end if\r\n\r\n write(*, *) 'L:'\r\n call print_matrix(L, n, n)\r\n\r\n write(*, *) 'U:'\r\n call print_matrix(U, n, n)\r\n\r\n write(*, *) 'y:'\r\n call print_vector(y, n)\r\n\r\n write(*, *) 'x:'\r\n call print_vector(x, n)\r\n\r\n! Try PLU Decomposition\r\n81 call info(':: Decomposição PLU (com pivoteamento) ::')\r\n if (.NOT. PLU_DECOMP(A, P, L, U, n)) then\r\n goto 82\r\n else if (.NOT. PLU_solve(A, x, y, b, n)) then\r\n goto 82\r\n end if\r\n\r\n write(*, *) 'P:'\r\n call print_matrix(P, n, n)\r\n \r\n write(*, *) 'L:'\r\n call print_matrix(L, n, n)\r\n\r\n write(*, *) 'U:'\r\n call print_matrix(U, n, n)\r\n\r\n write(*, *) 'y:'\r\n call print_vector(y, n)\r\n\r\n write(*, *) 'x:'\r\n call print_vector(x, n)\r\n\r\n call info(\"DET\")\r\n d = 1.0D0\r\n do i = 1, n\r\n d = d * U(i, i) * L(i, i)\r\n end do\r\n write(*, *) d\r\n\r\n write(*, *) 'x:'\r\n call print_vector(x, n)\r\n\r\n! Try Cholesky Decomposition\r\n82 call info(':: Decomposição de Cholesky ::')\r\n if (.NOT. CHOLESKY_DECOMP(A, L, n)) then\r\n goto 83\r\n else if (.NOT. Cholesky_solve(A, x, y, b, n)) then\r\n goto 83\r\n end if\r\n\r\n write(*, *) 'L:'\r\n call print_matrix(L, n, n)\r\n\r\n write(*, *) 'y:'\r\n call print_vector(y, n)\r\n\r\n write(*, *) 'x:'\r\n call print_vector(x, n)\r\n\r\n! Try Jacobi Method\r\n83 call info(':: Método de Jacobi ::')\r\n if (.NOT. Jacobi(A, x, b, e, n)) then\r\n goto 84\r\n end if\r\n\r\n write(*, *) 'x:'\r\n call print_vector(x, n)\r\n\r\n print *, 'e =', e\r\n\r\n! Try Gauss-Seidel Method\r\n84 call info(':: Método de Gauss-Seidel ::')\r\n if (.NOT. Gauss_Seidel(A, x, b, e, n)) then\r\n goto 85\r\n end if\r\n\r\n write(*, *) 'A:'\r\n call print_matrix(A, n, n)\r\n\r\n write(*, *) 'x:'\r\n call print_vector(x, n)\r\n\r\n write(*, *) 'b:'\r\n call print_vector(b, n)\r\n\r\n print *, 'e = ', e\r\n\r\n85 call info('Sucesso!')\r\n deallocate(A)\r\n deallocate(P)\r\n deallocate(L)\r\n deallocate(U)\r\n deallocate(b)\r\n goto 100\r\n\r\n90 call error('Essa matriz não é quadrada! Assim o programa não faz sentido.')\r\n goto 100\r\n91 call error('A matriz `A` e o vetor `b` não possuem a mesma dimensão. Não tem como fazer Ax = b!')\r\n goto 100\r\n92 call error('Parâmetros em excesso: O programa espera apenas o nome do arquivo da matriz.')\r\n goto 100\r\n93 call error('O Determinante é 0! Os métodos não se aplicam nesse caso.')\r\n goto 100\r\n\r\n100 stop\r\n\r\nend program main1", "meta": {"hexsha": "5f5f3fba539f73d86dead73c6fc85b8c0e6f81d2", "size": 4576, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/main1.f95", "max_stars_repo_name": "pedromxavier/COC473", "max_stars_repo_head_hexsha": "2bab0c45de6c13bba7ea7580992e1b8d090f3257", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/main1.f95", "max_issues_repo_name": "pedromxavier/COC473", "max_issues_repo_head_hexsha": "2bab0c45de6c13bba7ea7580992e1b8d090f3257", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/main1.f95", "max_forks_repo_name": "pedromxavier/COC473", "max_forks_repo_head_hexsha": "2bab0c45de6c13bba7ea7580992e1b8d090f3257", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.6872037915, "max_line_length": 102, "alphanum_fraction": 0.5369318182, "num_tokens": 1405, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065459, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.7895275223451117}} {"text": "\tFUNCTION PR_SPED ( uwnd, vwnd )\nC************************************************************************\nC* PR_SPED \t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes SPED from UWND and VWND. The following\t*\nC* equation is used:\t\t\t\t \t\t\t*\nC* \t\t\t\t\t\t\t\t\t*\nC* SPED = SQRT ( (UWND**2) + (VWND**2) )\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes SKNT if UKNT and VKNT are input.\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_SPED ( UWND, VWND )\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tUWND\t\tREAL\t\tU component of velocity\t\t*\nC*\tVWND\t\tREAL\t\tV component of velocity\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_SPED\t\tREAL\t\tWind speed \t\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* P. Kocin/914\t\t1980\tOriginal source code\t\t\t*\nC* I. Graffman/RDS\t12/87\tGEMPAK4\t\t\t\t\t*\nC* G. Huffman/GSC\t 7/88\tDocumentation\t\t\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\nC*\tCheck for missing data.\nC\n\tIF ( ERMISS ( uwnd ) .or. ERMISS ( vwnd ) ) THEN\n\t PR_SPED = RMISSD\n\t ELSE\n\t PR_SPED = SQRT ( ( uwnd **2 ) + ( vwnd **2 ) )\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "fbf74ac588cd6735d7be6919081ad99f44cc2e49", "size": 1196, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prsped.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/prmcnvlib/pr/prsped.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/prmcnvlib/pr/prsped.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 30.6666666667, "max_line_length": 73, "alphanum_fraction": 0.4406354515, "num_tokens": 381, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947055100816, "lm_q2_score": 0.8354835371034369, "lm_q1q2_score": 0.7895275191035837}} {"text": "MODULE tools\nINTEGER, PARAMETER :: DBL = SELECTED_REAL_KIND(p=13)\nCONTAINS\n SUBROUTINE derivative(func, x, step_size, result)\n IMPLICIT NONE\n INTEGER, PARAMETER :: DBL = SELECTED_REAL_KIND(p=13)\n REAL(KIND=DBL), EXTERNAL :: func\n REAL(KIND=DBL), INTENT(IN) :: x\n REAL(KIND=DBL), INTENT(IN) :: step_size\n REAL(KIND=DBL), INTENT(OUT) :: result\n ! Calculate average rate of change at x over step_size\n result = (func(x + step_size) - func(x)) / step_size\n END SUBROUTINE derivative\n\n REAL(KIND=DBL) FUNCTION f1(x)\n IMPLICIT NONE\n REAL(KIND=DBL), INTENT(IN) :: x\n f1 = x**2 + 1._DBL\n END FUNCTION f1\n\n REAL(KIND=DBL) FUNCTION f2(x)\n IMPLICIT NONE\n REAL(KIND=DBL), INTENT(IN) :: x\n f2 = 10._DBL * SIN(20._DBL * x)\n END FUNCTION f2\nEND MODULE tools\n\nPROGRAM test_der_2\nUSE tools\nIMPLICIT NONE\nREAL(KIND=DBL) :: x, step_size, result\nx = 0._DBL\nstep_size = 0.000001_DBL\nCALL derivative(f2, x, step_size, result)\nWRITE(*, *) result\nEND PROGRAM test_der_2\n", "meta": {"hexsha": "4254cefd95c917723f16e2b1e94691fc336eeca9", "size": 966, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap11/test_der_2.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap11/test_der_2.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap11/test_der_2.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.1081081081, "max_line_length": 56, "alphanum_fraction": 0.7008281573, "num_tokens": 334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810496235896, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7894759239014951}} {"text": "!##############################################################################\n! PROGRAM bisection\n!\n! ## A bisection method to find the root of a function\n!\n! This code is published under the GNU General Public License v3\n! (https://www.gnu.org/licenses/gpl-3.0.en.html)\n!\n! Authors: Hans Fehr and Fabian Kindermann\n! contact@ce-fortran.com\n!\n! #VC# VERSION: 1.0 (23 January 2018)\n!\n!##############################################################################\nprogram bisection\n\n implicit none\n integer :: iter\n real*8 :: x, a, b, fx, fa, fb\n\n ! set initial guesses and function values\n a = 0.05d0\n b = 0.25d0\n fa = 0.5d0*a**(-0.2d0)+0.5d0*a**(-0.5d0)-2d0\n fb = 0.5d0*b**(-0.2d0)+0.5d0*b**(-0.5d0)-2d0\n\n ! check whether there is a root in [a,b]\n if(fa*fb >= 0d0)then\n stop 'Error: There is no root in [a,b]'\n endif\n\n ! start iteration process\n do iter = 1, 200\n\n ! calculate new bisection point and function value\n x = (a+b)/2d0\n fx = 0.5d0*x**(-0.2d0)+0.5d0*x**(-0.5d0)-2d0\n\n write(*,'(i4,f12.7)')iter, abs(x-a)\n\n ! check for convergence\n if(abs(x-a) < 1d-6)then\n write(*,'(/a,f12.7,a,f12.9)')' x = ',x,' f = ',fx\n stop\n endif\n\n ! calculate new interval\n if(fa*fx < 0d0)then\n b = x\n fb = fx\n else\n a = x\n fa = fx\n endif\n enddo\n\n write(*,'(a)')'Error: no convergence'\n\nend program\n", "meta": {"hexsha": "d6298143277acadd6cd549f069b2e7c1b822de26", "size": 1520, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog02/prog02_05/prog02_05.f90", "max_stars_repo_name": "aswinvk28/modflow_fortran", "max_stars_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "complete/prog02/prog02_05/prog02_05.f90", "max_issues_repo_name": "aswinvk28/modflow_fortran", "max_issues_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "complete/prog02/prog02_05/prog02_05.f90", "max_forks_repo_name": "aswinvk28/modflow_fortran", "max_forks_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-07T12:27:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-07T12:27:47.000Z", "avg_line_length": 25.3333333333, "max_line_length": 79, "alphanum_fraction": 0.4684210526, "num_tokens": 498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391386, "lm_q2_score": 0.8652240947405565, "lm_q1q2_score": 0.7894617550775785}} {"text": "module class_Polygon\n\n implicit none\n private\n real :: pi = acos(-1.0d0)\n\n type, public :: Polygon\n integer :: nSides\n real :: side\n contains\n procedure :: area => polygon_area\n procedure :: print => polygon_print\n end type\n\ncontains\n\n pure function polygon_area(this) result(area)\n\n class(Polygon), intent(in) :: this\n real :: area\n real :: perimeter, apothem\n\n perimeter = this%nSides * this%side\n apothem = this%side / (2.0d0 * tan(pi / this%nSides))\n\n area = (perimeter * apothem) / 2.0d0\n\n end function\n\n subroutine polygon_print(this)\n\n class(Polygon), intent(in) :: this\n real:: area\n\n area = this%area()\n print *, 'Polygon: nSides = ', this%nSides, ' side = ', this%side, ' area = ', area\n\n end subroutine\n\nend module\n", "meta": {"hexsha": "d50226e4191986b3f123ff02e522552c2756c3e3", "size": 778, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "chapter-01/recipe-09/fortran-example/geometry_polygon.f90", "max_stars_repo_name": "istupsm/cmake-cookbook", "max_stars_repo_head_hexsha": "342d0171802153619ea124c5b8e792ce45178895", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1600, "max_stars_repo_stars_event_min_datetime": "2018-05-24T01:32:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T09:24:11.000Z", "max_issues_repo_path": "chapter-01/recipe-09/fortran-example/geometry_polygon.f90", "max_issues_repo_name": "istupsm/cmake-cookbook", "max_issues_repo_head_hexsha": "342d0171802153619ea124c5b8e792ce45178895", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 280, "max_issues_repo_issues_event_min_datetime": "2017-08-27T13:10:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-23T15:09:58.000Z", "max_forks_repo_path": "chapter-01/recipe-09/fortran-example/geometry_polygon.f90", "max_forks_repo_name": "istupsm/cmake-cookbook", "max_forks_repo_head_hexsha": "342d0171802153619ea124c5b8e792ce45178895", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 475, "max_forks_repo_forks_event_min_datetime": "2018-05-23T15:26:27.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T07:28:19.000Z", "avg_line_length": 18.9756097561, "max_line_length": 87, "alphanum_fraction": 0.6323907455, "num_tokens": 229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392795, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7893343428341576}} {"text": "! In this module you can define for example global constants\n\nMODULE constants\n ! definition of variables for double precisions and complex variables \n INTEGER, PARAMETER :: dp = KIND(1.0D0)\n INTEGER, PARAMETER :: dpc = KIND((1.0D0,1.0D0))\n ! Global Truncation parameter\n REAL(DP), PARAMETER, PUBLIC :: truncation=1.0E-10\nEND MODULE constants\n\nPROGRAM improved_exp\n USE constants\n IMPLICIT NONE \n REAL (dp) :: x, term, final_sum\n INTEGER :: n, loop_over_x\n\n ! loop over x-values, no floats as loop variables\n DO loop_over_x=0, 100, 10\n x=loop_over_x\n ! initialize the EXP sum\n final_sum=1.0 ; term=1.0 ; n = 1\n DO WHILE ( ABS(term) > truncation)\n term = -term*x/FLOAT(n)\n final_sum=final_sum+term\n n=n+1\n ENDDO\n ! write the argument x, the exact value, the computed value and n\n WRITE(*,*) x ,EXP(-x), final_sum, n\n ENDDO\n\nEND PROGRAM improved_exp\n", "meta": {"hexsha": "2848b05d58fa1af44790d33e1f9623541137d258", "size": 916, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/Programs/LecturePrograms/programs/IntroProgramming/Fortran/program5.f90", "max_stars_repo_name": "kimrojas/ComputationalPhysicsMSU", "max_stars_repo_head_hexsha": "a47cfc18b3ad6adb23045b3f49fab18c0333f556", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 220, "max_stars_repo_stars_event_min_datetime": "2016-08-25T09:18:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T14:09:16.000Z", "max_issues_repo_path": "doc/Programs/LecturePrograms/programs/IntroProgramming/Fortran/program5.f90", "max_issues_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_issues_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-01-18T10:43:38.000Z", "max_issues_repo_issues_event_max_datetime": "2020-02-08T13:15:42.000Z", "max_forks_repo_path": "doc/Programs/LecturePrograms/programs/IntroProgramming/Fortran/program5.f90", "max_forks_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_forks_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 136, "max_forks_repo_forks_event_min_datetime": "2016-08-25T09:04:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T09:54:21.000Z", "avg_line_length": 28.625, "max_line_length": 72, "alphanum_fraction": 0.6703056769, "num_tokens": 284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465116437761, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7893343403676581}} {"text": "implicit none\r\nreal :: a, b, m, f\r\n\r\na = 1.0\r\nb = 2.0\r\n\r\ndo while (b - a > 1.0e-11)\r\n m = (a + b) / 2.0\r\n if (f(a) * f(m) < 0.0) then\r\n b = m\r\n else\r\n a = m\r\n end if\r\n print*, 'Current m: ', m\r\n print*, 'Current (b - a): ', b-a\r\nend do\r\nstop\r\nend\r\n\r\nreal function f(x)\r\n implicit none\r\n real :: x\r\n\r\n f = x**2 - 3.0\r\n\r\n return\r\nend\r\n", "meta": {"hexsha": "6601e3b5689e269084d58a6758457b25c7705370", "size": 349, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "4670 Numerical Analysis/Class Examples/bb1.f90", "max_stars_repo_name": "mwebber3/UnderGraduateCourses", "max_stars_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4670 Numerical Analysis/Class Examples/bb1.f90", "max_issues_repo_name": "mwebber3/UnderGraduateCourses", "max_issues_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4670 Numerical Analysis/Class Examples/bb1.f90", "max_forks_repo_name": "mwebber3/UnderGraduateCourses", "max_forks_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 12.4642857143, "max_line_length": 35, "alphanum_fraction": 0.4498567335, "num_tokens": 153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922388, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7892771768838863}} {"text": "MODULE coord\n\t\n\tuse constantes\n\timplicit none\n\t\n\tcontains\n\nsubroutine cart_sph(x,r)\n\t!----------------------------------------------------------\n\t! Switching from cartesian to spherical coordinates\n\t! CALLING SEQUENCE: call cart_sph(x,r)\n\t! INPUT: x: position vector in cartesian coordinates\n\t! OUTPUT: r: position vector in spherical coordinates \n\t! (radial distance,azimuthal angle,polar angle)\t\t\t!\n\t!----------------------------------------------------------\n\n\treal(kind=8), dimension(:,:), intent(in) :: x\n\treal(kind=8), dimension(:,:), intent(out) :: r\n\n\tr(1,:) = sqrt(x(1,:)**2+x(2,:)**2+x(3,:)**2)\n\t\n\t!longitude\n\twhere (x(2,:) < 0.d0)\n\t\tr(2,:) = 2.d0*pi-acos(x(1,:)/sqrt(x(1,:)**2+x(2,:)**2)) \n\telsewhere \n\t\tr(2,:) = acos(x(1,:)/sqrt(x(1,:)**2+x(2,:)**2)) \n\tend where\n\n\twhere (x(1,:) .eq. 0.d0 .and. x(2,:).eq. 0.d0)\n\t\tr(2,:) = pi/2.d0\n\tend where\n\t\n\t!colatitude\n\twhere (r(1,:) .ne. 0.d0)\n\t\tr(3,:) = pi/2.d0 - acos(x(3,:)/r(1,:))\n\telsewhere\n\t\tr(3,:) = pi/2.d0\n\tend where\n\nend subroutine cart_sph\n\nsubroutine cart_cyl(x,r)\n\t!----------------------------------------------------------\n\t! Switching from cartesian to cylindrical coordinates\n\t! CALLING SEQUENCE: call cart_cyl(x,r)\n\t! INPUT: x: position vector in cartesian coordinates\n\t! OUTPUT: r: position vector in cylindrical coordinates \n\t!\t (radial distance,angular coordinate,altitude)\t\t\t!\n\t!----------------------------------------------------------\n\n\treal(kind=8), dimension(:,:), intent(in) :: x\n\treal(kind=8), dimension(:,:), intent(out) :: r\n\t\n\t! altitude\n\tr(3,:)=x(3,:)\n\n\t! radial distance\n\tr(1,:) = sqrt(x(1,:)**2+x(2,:)**2)\n\t\n\t! angular coordinate\n\twhere (x(1,:) .ge. 0.d0 .and. x(2,:) .ne. 0.d0)\n\t\tr(2,:) = asin(x(2,:)/r(1,:)) \n\tend where \n\twhere (x(1,:) .lt. 0.d0 .and. x(2,:) .ne. 0.d0)\n\t\tr(2,:) = pi - asin(x(2,:)/r(1,:)) \n\tend where\n\n\twhere (x(1,:) .eq. 0.d0 .and. x(2,:).eq. 0.d0)\n\t\tr(2,:) = 0.d0\n\tend where\n\nend subroutine cart_cyl\n\nsubroutine sph_cart(r,x)\n\t!----------------------------------------------------------\n\t! Switching from spherical to cartesian coordinates \n\t! CALLING SEQUENCE: call cart_sph(r,x)\n\t! INPUT: r: position vector in spherical coordinates\n\t!\t (radial distance,azimuthal angle,polar angle)\t\n\t! OUTPUT: x: position vector in cartesian coordinates \n\t!----------------------------------------------------------\n\n\treal(kind=8), dimension(:,:), intent(in) :: r\n\treal(kind=8), dimension(:,:), intent(out) :: x\n\n\tx(1,:) = r(1,:)*cos(r(3,:))*cos(r(2,:)) \n\tx(2,:) = r(1,:)*cos(r(3,:))*sin(r(2,:)) \n\tx(3,:) = r(1,:)*sin(r(3,:))\n\nend subroutine sph_cart\n\nsubroutine cyl_cart(r,x)\n\t!----------------------------------------------------------\n\t! Switching from cylindrical to cartesian coordinates\n\t! CALLING SEQUENCE: call cyl_cart(r,x)\n\t! INPUT: r: position vector in cylindrical coordinates \n\t!\t (radial distance,angular coordinate,altitude)\n\t! OUTPUT: x: position vector in cartesian coordinates \n\t!----------------------------------------------------------\n\n\treal(kind=8), dimension(:,:), intent(in) :: r\n\treal(kind=8), dimension(:,:), intent(out) :: x\n\n\tx(1,:) = r(1,:)*cos(r(2,:))\n\tx(2,:) = r(1,:)*sin(r(2,:)) \n\tx(3,:) = r(3,:)\n\nend subroutine cyl_cart\n\nsubroutine sph_cart_vect(Vr,r,Vx)\n\t!-------------------------------------------------------------------------------------\n\t! Switching from spherical to cartesian coordinates for a vector at a point r\n\t! CALLING SEQUENCE: call sph_cart_vect(Vr,r,Vx)\n\t! INPUT: Vr : vector in spherical coordinates\n\t!\t (radial distance,azimuthal angle,polar angle)\t\n\t! r : position vector in spherical coordinates\n\t!\t (radial distance,azimuthal angle,polar angle)\n\t! OUTPUT: Vx: vector in cartesian coordinates (Vx,Vy,Vz)\n\t!-------------------------------------------------------------------------------------\n\n\treal(kind=8), dimension(:,:), intent(in) :: r,Vr\n\treal(kind=8), dimension(:,:), intent(out) :: Vx\n\t\n\tVx(1,:)=Vr(1,:)*cos(r(2,:))*cos(r(3,:))-Vr(2,:)*sin(r(2,:))-Vr(3,:)*sin(r(3,:))*cos(r(2,:))\n\tVx(2,:)=Vr(1,:)*sin(r(2,:))*cos(r(3,:))+Vr(2,:)*cos(r(2,:))-Vr(3,:)*sin(r(2,:))*sin(r(3,:))\n\tVx(3,:)=Vr(1,:)*sin(r(3,:))+Vr(3,:)*cos(r(3,:))\n\nend subroutine sph_cart_vect\nsubroutine cyl_cart_vect(Vr,r,Vx)\n\t!-------------------------------------------------------------------------------------\n\t! Switching from cylindrical to cartesian coordinates for a vector at a point r\n\t! CALLING SEQUENCE: call cyl_cart_vect(Vr,r,Vx)\n\t! INPUT: Vr : vector in cylindrical coordinates\n\t! (radial distance,angular coordinate,altitude)\n\t! r : position vector in cylindrical coordinates\n\t! (radial distance,angular coordinate,altitude)\n\t!\t\t\t\t\n\t! OUTPUT: Vx: vector in cartesian coordinates (Vx,Vy,Vz)\n\t!-------------------------------------------------------------------------------------\n\n\treal(kind=8), dimension(:,:), intent(in) :: r,Vr\n\treal(kind=8), dimension(:,:), intent(out) :: Vx\n\t\n\tVx(1,:)=Vr(1,:)*cos(r(2,:))-Vr(2,:)*sin(r(2,:))\n\tVx(2,:)=Vr(1,:)*sin(r(2,:))+Vr(2,:)*cos(r(2,:))\n\tVx(3,:)=Vr(3,:)\n\nend subroutine cyl_cart_vect\nsubroutine rot(Vin,theta,Vout)\n\t!------------------------------------------------------\n\t! Rotation of the Vin vector by an angle theta\n\t! CALLING SEQUENCE: call rot(Vin,theta,Vout)\n\t! INPUT: Vin: vector in cartesian coordinates\n\t! theta: angle in degre\n\t!\t\t\t\t\n\t! OUTPUT: Vout: modified vector in cartesian coordinates.\n\t!------------------------------------------------------\n\treal(kind=8), dimension(:,:), intent(in) :: Vin\n\treal(kind=8), dimension(:), intent(in) :: theta\n\treal(kind=8), dimension(:,:), intent(out) :: Vout\n\treal(kind=8), dimension(3,3)\t\t\t :: matrot\n\tinteger\t\t\t\t\t\t\t\t\t :: i\n\t\n\twrite(*,*) theta\n\tdo i=1,size(theta)\n!\t\tmatrot(1,1) = cos(theta(i)*pi/180.) ; matrot(1,2) = -sin(theta(i)*pi/180.) ; matrot(1,3)=0.d0\n!\t\tmatrot(2,1) = sin(theta(i)*pi/180.) ; matrot(2,2) = cos(theta(i)*pi/180.) ; matrot(2,3)=0.d0\n!\t\tmatrot(3,1) = 0.d0\t\t \t\t ; matrot(3,2) = 0.d0\t\t\t\t ; matrot(3,3)=1.d0\n\n\t\tmatrot(1,1) = cos(theta(i)*pi/180.) ; matrot(1,2) = 0.d0\t\t; matrot(1,3)=-sin(theta(i)*pi/180.)\n\t\tmatrot(2,1) = 0.d0\t\t\t\t ; matrot(2,2) = 1.d0\t\t; matrot(2,3)=0.d0\n\t\tmatrot(3,1) = sin(theta(i)*pi/180.) ; matrot(3,2) = 0.d0\t\t; matrot(3,3)=cos(theta(i)*pi/180.) \n\n\t\tVout(:,i) = matmul(matrot,Vin(:,i)) \n\n\tenddo\n\nend subroutine rot\n\n\nEND MODULE coord\n", "meta": {"hexsha": "6f9cc4b1c8ce5bdfc32bd1a47334baac237738c3", "size": 6310, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "RaytracingCode/coord.f90", "max_stars_repo_name": "maserlib/ARTEMIS-P", "max_stars_repo_head_hexsha": "4c10d3b92bcab079bc1f19b25f2613b1a23476c2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-17T13:50:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-17T13:50:47.000Z", "max_issues_repo_path": "RaytracingCode/coord.f90", "max_issues_repo_name": "maserlib/ARTEMIS-P", "max_issues_repo_head_hexsha": "4c10d3b92bcab079bc1f19b25f2613b1a23476c2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "RaytracingCode/coord.f90", "max_forks_repo_name": "maserlib/ARTEMIS-P", "max_forks_repo_head_hexsha": "4c10d3b92bcab079bc1f19b25f2613b1a23476c2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-29T17:32:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T17:32:19.000Z", "avg_line_length": 34.6703296703, "max_line_length": 97, "alphanum_fraction": 0.5191759113, "num_tokens": 1989, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922388, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7892771693442375}} {"text": "!=====================================================================================\r\nmodule det ! �s�񎮌v�Z���W���[���u���l�v�Z�̂��߂�Fortran90/95�v���O���~���O����v�����p\r\n implicit none\r\ncontains\r\n recursive function det_mat(a,n) result(det)\r\n integer, intent(in) :: n\r\n real(8), intent(in) :: a(n, n)\r\n real(8) det, b(n-1, n-1)\r\n integer i\r\n if (n > 1) then\r\n det = 0.0d0\r\n do i = 1, n\r\n b(1:i-1, 1:n-1) = a(1:i-1, 2:n)\r\n b(i:n-1, 1:n-1) = a(i+1:n, 2:n)\r\n det = det + (-1.0d0) ** (i + 1) &\r\n * a(i, 1) * det_mat(b, n-1)\r\n \r\n enddo\r\n else\r\n det = a(1,1)\r\n endif\r\n end function det_mat\r\n !=====================================================================================\r\n subroutine trans_rank_2(A,A_T)\r\n\t real(8),intent(in)::A(:,:)\r\n\t real(8),allocatable,intent(out)::A_T(:,:)\r\n\t integer n,m,i,j\r\n\t \r\n\t n=size(A,1)\r\n\t m=size(A,2)\r\n\t if(.not. allocated(A_T) )allocate(A_T(m,n))\r\n\t \r\n\t do i=1,n\r\n\t\tdo j=1, m\r\n\t\t\tA_T(j,i)=A(i,j)\r\n\t\tenddo\r\n\t enddo\r\n\t \r\n end subroutine trans_rank_2\r\n !================================================================================== \r\n function trans1(A) result(A_T)\r\n\t real(8),intent(in)::A(:)\r\n\t real(8),allocatable::A_T(:,:)\r\n\t integer n,m,i,j\r\n\t \r\n\t n=size(A)\r\n\t if(.not. allocated(A_T) )allocate(A_T(1,n))\r\n\t \r\n\t do i=1,n\r\n\t\t\tA_T(1,i)=A(i)\r\n\t enddo\r\n\t \r\n end function trans1\r\n !================================================================================== \r\n function trans2(A) result(A_T)\r\n\t real(8),intent(in)::A(:,:)\r\n\t real(8),allocatable::A_T(:,:)\r\n\t integer n,m,i,j\r\n\t \r\n\t n=size(A,1)\r\n\t m=size(A,2)\r\n\t if(.not. allocated(A_T) )allocate(A_T(m,n))\r\n\t \r\n\t do i=1,n\r\n\t\tdo j=1, m\r\n\t\t\tA_T(j,i)=A(i,j)\r\n\t\tenddo\r\n\t enddo\r\n\t \r\n end function trans2\r\n !================================================================================== \r\n subroutine inverse_rank_2(A,A_inv)\r\n\t real(8),intent(in)::A(:,:)\r\n\t real(8),allocatable::A_inv(:,:)\r\n\t real(8) detA,detA_1\r\n\t integer m,n\r\n\t \r\n\t m=size(A,1)\r\n\t n=size(A,2)\r\n\t if(.not. allocated(A_inv) )allocate(A_inv(m,n))\r\n\t detA=det_mat(A,n)\r\n\t if(detA==0.0d0) stop \"ERROR: inverse, detA=0\"\r\n\t detA_1=1.0d0/detA\r\n\t if(n==2)then\r\n\t\tA_inv(1,1)=detA_1*A(2,2)\r\n\t\tA_inv(1,2)=-detA_1*A(1,2)\r\n\t\tA_inv(2,1)=-detA_1*A(2,1)\r\n\t\tA_inv(2,2)=detA_1*A(1,1)\r\n\t elseif(n==3)then\r\n\t\tA_inv(1,1)=detA_1*(A(2,2)*A(3,3)-A(2,3)*A(3,2))\r\n\t\tA_inv(1,2)=detA_1*(A(1,3)*A(3,2)-A(1,2)*A(3,3))\r\n\t\tA_inv(1,3)=detA_1*(A(1,2)*A(2,3)-A(1,3)*A(2,2))\r\n\t\tA_inv(2,1)=detA_1*(A(2,3)*A(3,1)-A(2,1)*A(3,3))\r\n\t\tA_inv(2,2)=detA_1*(A(1,1)*A(3,3)-A(1,3)*A(3,1))\r\n\t\tA_inv(2,3)=detA_1*(A(1,3)*A(2,1)-A(1,1)*A(2,3))\r\n\t\tA_inv(3,1)=detA_1*(A(2,1)*A(3,2)-A(2,2)*A(3,1))\r\n\t\tA_inv(3,2)=detA_1*(A(1,2)*A(3,1)-A(1,1)*A(3,2))\r\n\t\tA_inv(3,3)=detA_1*(A(1,1)*A(2,2)-A(1,2)*A(2,1))\r\n\t else\r\n\t\tprint *, \"ERROR: Aij with i=j=\",n,\"/=2or3\"\r\n\t endif\r\n\t \r\n end subroutine inverse_rank_2\r\n !================================================================================== \r\n\tsubroutine tensor_exponential(A,expA,TOL,itr_tol)\r\n\treal(8),intent(in)::A(:,:),TOL\r\n\treal(8),allocatable,intent(inout)::expA(:,:)\r\n\treal(8),allocatable::increA(:,:)\r\n\tinteger, intent(in)::itr_tol\r\n\treal(8) increment,NN\r\n\tinteger i,j,n\r\n\t\r\n\tif(.not. allocated(expA) )allocate(expA(size(A,1),size(A,2) ))\r\n\tallocate(increA(size(A,1),size(A,2) ))\r\n\tif(size(A,1)/=size(A,2)) stop \"ERROR:tensor exp is not a square matrix\"\r\n\t\r\n\texpA(:,:)=0.0d0\r\n\tdo n=1,size(expA,1)\r\n\t\texpA(n,n)=1.0d0\r\n\tenddo\r\n\tNN=1.0d0\r\n\tincreA(:,:)=expA(:,:)\r\n\tdo n=1,itr_tol\r\n\t\tif(n>1)then\r\n\t\t\tNN = NN*(NN+1.0d0)\r\n\t\tendif\r\n\t\tincreA(:,:)=matmul(increA,A)\r\n\t\texpA(:,:)= expA(:,:)+1.0d0/NN*increA(:,:)\r\n\t\t\r\n\t\tincrement=0.0d0\r\n\t\tdo i=1,size(A,1)\r\n\t\t\tdo j=1,size(A,2)\r\n\t\t\t\tincrement=increment+1.0d0/NN*increA(i,j)*increA(i,j)\r\n\t\t\tenddo\r\n\t\tenddo\r\n\t\t\r\n\t\tif(increment<=TOL)then\r\n\t\t\texit\r\n\t\telse\r\n\t\t\tif(n>=itr_tol)then\r\n\t\t\t\t stop \"tensor exponential is not converged\"\r\n\t\t\tendif\r\n\t\t\tcycle\r\n\t\tendif\r\n\tenddo\r\n\t\r\n\tdeallocate(increA)\r\n\t\r\n\tend subroutine tensor_exponential\r\n !================================================================================== \r\n subroutine tensor_expo_der(A,expA_A,TOL,itr_tol)\r\n\treal(8),intent(in)::A(:,:),TOL\r\n\treal(8),allocatable,intent(inout)::expA_A(:,:,:,:)\r\n\treal(8),allocatable::increA_1(:,:),increA_2(:,:),increA_3(:,:,:,:),I_ij(:,:),A_inv(:,:)\r\n\tinteger, intent(in)::itr_tol\r\n\treal(8) increment,NN\r\n\tinteger i,j,k,l,n,m,o\r\n\t\r\n\tif(.not. allocated(expA_A) )allocate(expA_A(size(A,1),size(A,1),size(A,1),size(A,1) ))\r\n\tallocate(I_ij(size(A,1),size(A,1) ))\r\n\tallocate(increA_1(size(A,1),size(A,1) ))\r\n\tallocate(increA_2(size(A,1),size(A,1) ))\r\n\tallocate(increA_3(size(A,1),size(A,1),size(A,1),size(A,1) ) )\r\n\tif(size(A,1)/=size(A,2)) stop \"ERROR:tensor exp is not a square matrix\"\r\n\t\r\n\tcall inverse_rank_2(A,A_inv)\r\n\r\n\tI_ij(:,:)=0.0d0\r\n\tdo n=1,size(expA_A,1)\r\n\t\tI_ij(n,n)=1.0d0\r\n\tenddo\r\n\tNN=1.0d0\r\n\t\r\n\tdo i=1,size(A,1)\r\n\t\tdo j=1,size(A,1)\r\n\t\t\tdo k=1, size(A,1)\r\n\t\t\t\tdo l=1, size(A,1)\r\n\t\t\t\t\texpA_A(i,j,k,l)=I_ij(i,k)*I_ij(l,j)\r\n\t\t\t\tenddo\r\n\t\t\tenddo\r\n\t\tenddo\r\n\tenddo\r\n\t\r\n\tincreA_1(:,:)=I_ij(:,:)\r\n\tincreA_2(:,:)=I_ij(:,:)\r\n\tdo n=1,itr_tol\r\n\t\tif(n>2)then\r\n\t\t\tNN = NN*(NN+1.0d0)\r\n\t\tendif\r\n\t\tincreA_1(:,:)=A_inv(:,:)\r\n\t\tincreA_2(:,:)=matmul(increA_2,A)\r\n\t\t\r\n\t\tincreA_3(:,:,:,:)=0.0d0\r\n\t\tdo m=1,n\r\n\t\t\tincreA_1(:,:)=matmul(increA_1,A )\r\n\t\t\t\r\n\t\t\tincreA_2(:,:)=matmul(increA_2,A_inv)\r\n\r\n\t\t\tdo i=1,size(A,1)\r\n\t\t\t\tdo j=1,size(A,1)\r\n\t\t\t\t\tdo k=1, size(A,1)\r\n\t\t\t\t\t\tdo l=1, size(A,1)\r\n\t\t\t\t\t\t\tincreA_3(i,j,k,l)=increA_3(i,j,k,l)+increA_1(i,k)*increA_2(l,j)\r\n\t\t\t\t\t\t\texpA_A(i,j,k,l)=expA_A(i,j,k,l)+1.0d0/NN*increA_3(i,j,k,l)\r\n\t\t\t\t\t\tenddo\r\n\t\t\t\t\tenddo\r\n\t\t\t\tenddo\r\n\t\t\tenddo\t\t\t\r\n\t\tenddo\r\n\r\n\t\tdo i=1,size(A,1)\r\n\t\t\tdo j=1,size(A,1)\r\n\t\t\t\tdo k=1, size(A,1)\r\n\t\t\t\t\tdo l=1, size(A,1)\r\n\t\t\t\t\t\tincrement=increment+1.0d0/NN*increA_3(i,j,k,l)&\r\n\t\t\t\t\t\t\t*increA_3(i,j,k,l)&\r\n\t\t\t\t\t\t\t*increA_3(i,j,k,l)&\r\n\t\t\t\t\t\t\t*increA_3(i,j,k,l)\r\n\t\t\t\t\tenddo\r\n\t\t\t\tenddo\r\n\t\t\tenddo\r\n\t\tenddo\t\t\t\r\n\r\n\t\tif(increment<=TOL)then\r\n\t\t\texit\r\n\t\telse\r\n\t\t\tif(n>=itr_tol)then\r\n\t\t\t\t stop \"tensor exponential is not converged\"\r\n\t\t\tendif\r\n\t\t\tcycle\r\n\t\tendif\r\n\tenddo\r\n\t\r\n\tdeallocate(increA_1,increA_2,increA_3,I_ij,A_inv)\r\n\t\r\n\tend subroutine tensor_expo_der\r\n !================================================================================== \r\nend module det\r\n\r\n", "meta": {"hexsha": "399f5d0e5c12e34ca39d8050f11acbb238164731", "size": 6343, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/MathClass/det_ls.f90", "max_stars_repo_name": "kazulagi/plantfem_min", "max_stars_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2020-06-21T08:21:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:28:30.000Z", "max_issues_repo_path": "src/MathClass/det_ls.f90", "max_issues_repo_name": "kazulagi/plantfem_min", "max_issues_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-08T05:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:39:29.000Z", "max_forks_repo_path": "src/MathClass/det_ls.f90", "max_forks_repo_name": "kazulagi/plantfem_min", "max_forks_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-10-20T18:28:59.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-15T08:35:25.000Z", "avg_line_length": 26.4291666667, "max_line_length": 90, "alphanum_fraction": 0.4893583478, "num_tokens": 2484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096135894201, "lm_q2_score": 0.8615382058759128, "lm_q1q2_score": 0.7892634328775048}} {"text": "program main\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n real(dp), parameter :: pi = acos(-1.d0)\n real(dp) :: epsilonA = 1.d0, epsilonB = 1.d0, t = 5.d-1, k, E1, E2\n\n ! reduced zone scheme\n open(unit = 1, file = '3-E-k-ReducedZoneScheme-2.txt', status = 'unknown')\n k = -pi\n do while(k <= pi)\n ! acoustic mode\n E1 = ((epsilonA + epsilonB) - sqrt((epsilonA - epsilonB)**2 + 4.d0 * (2.d0 + 2.d0 * cos(k)))) / 2.d0\n ! optical mode\n E2 = ((epsilonA + epsilonB) + sqrt((epsilonA - epsilonB)**2 + 4.d0 * (2.d0 + 2.d0 * cos(k)))) / 2.d0\n write(1,'(3f20.8)') k, E1, E2\n k = k + 1.d-2\n end do\n close(1)\n\n ! extended zone scheme\n ! optical mode\n open(unit = 2, file = '3-E-k-ExtendedZoneScheme-Optical-2.txt', status = 'unknown')\n k = 0.d0\n do while (k <= pi)\n E1 = ((epsilonA + epsilonB) + sqrt((epsilonA - epsilonB)**2 + 4.d0 * (2.d0 + 2.d0 * cos(-2.d0 * pi + k)))) / 2.d0\n E2 = ((epsilonA + epsilonB) + sqrt((epsilonA - epsilonB)**2 + 4.d0 * (2.d0 + 2.d0 * cos(pi + k)))) / 2.d0\n write(2,'(4f20.8)') -2.d0 * pi + k, E1, pi + k, E2\n k = k + 1.d-2\n end do\n close(2)\nend program main\n", "meta": {"hexsha": "8968d64874abcc2c578f5d340d95554b60a8facf", "size": 1217, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Assignment-6/3-E-k-2.f90", "max_stars_repo_name": "Chen-Jialin/Solid-State-Physics-Assignments", "max_stars_repo_head_hexsha": "d513fa41203eb79a73b784e64bbec0ed0c388b28", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-07T08:22:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T08:22:50.000Z", "max_issues_repo_path": "Assignment-6/3-E-k-2.f90", "max_issues_repo_name": "Chen-Jialin/Solid-State-Physics-Assignments", "max_issues_repo_head_hexsha": "d513fa41203eb79a73b784e64bbec0ed0c388b28", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Assignment-6/3-E-k-2.f90", "max_forks_repo_name": "Chen-Jialin/Solid-State-Physics-Assignments", "max_forks_repo_head_hexsha": "d513fa41203eb79a73b784e64bbec0ed0c388b28", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-29T12:03:27.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T12:03:27.000Z", "avg_line_length": 38.03125, "max_line_length": 121, "alphanum_fraction": 0.5242399343, "num_tokens": 473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474246069457, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7892182789880082}} {"text": "PROGRAM PIB1D_INFINITE_WELL\n IMPLICIT NONE\n\n REAL, PARAMETER :: PI = acos(-1.0)\n REAL, ALLOCATABLE:: potential(:), x(:)\n DOUBLE PRECISION, ALLOCATABLE:: hmat(:,:), eigenVal(:), work(:)\n DOUBLE PRECISION:: Expect_X\n REAL:: xmax, xmin, dx, hbar = 1.0, m = 1.0, tconst\n INTEGER:: nx, lwork, i, ifail, Expect_N, n\n\n WRITE(*, fmt = '(/A)', ADVANCE = 'NO') \"Enter the number of grid points: \"\n READ(*, *) nx\n\n xmax = 5.0\n xmin = 0.0\n dx = (xmax - xmin)/(nx - 1)\n \n ALLOCATE(potential(nx), hmat(nx,nx), eigenVal(nx), x(nx), work(64*nx))\n DO i = 1, nx\n x(i) = xmin + (i-1)*dx\n ENDDO\n\n tconst = (hbar**2) / (2.0 * m * dx**2)\n hmat = 0.0\n\n potential = 0.0\n\n DO i = 1, nx-1\n hmat(i, i) = potential(i) + 2.0 * tconst\n hmat(i, i+1) = -tconst\n hmat(i+1, i) = -tconst\n ENDDO\n hmat(nx, nx) = potential(nx) + 2.0 * tconst\n \n lwork = 64*nx\n CALL dsyev('V', 'U', nx, hmat, nx, eigenVal, work, lwork, ifail)\n \n ! Sorting but no need as eigenVal is already sorted\n ! DO i = 1, nx\n ! DO j = i, nx\n ! IF(eigenVal(i) .GT. eigenVal(j)) THEN\n ! tmp = eigenVal(j)\n ! eigenVal(j) = eigenVal(i)\n ! eigenVal(i) = tmp\n ! ENDIF \n ! ENDDO\n ! ENDDO\n\n OPEN(UNIT = 20, FILE = 'output.txt')\n ! WRITE(20, *) 'Grid Point (Value of x) eigenValue Calculated Exect EigenValue WaveFunction'\n DO i = 1, nx\n WRITE(20, 10) x(i), eigenVal(i), i**2 * pi**2/(2.0 * (xmax-xmin)**2), (hmat(i, n)/sqrt(dx), n = 1, 5)\n 10 FORMAT(f8.3, 3x, f0.3, 3x, f0.3, 3x, f8.3, 3x, f8.3, 3x, f8.3, 3x, f8.3, 3x, f8.3, 3x)\n ENDDO\n CLOSE(20)\n \n WRITE(*, fmt = '(/A)', ADVANCE = 'NO') \"Expectation value for n = \"\n\n ! Expect_N is a expectation value of quantum number N\n READ(*, *) Expect_N\n \n ! Expect_X is a expectation value of position x\n Expect_X = 0.0\n \n DO i = 1, nx \n Expect_X = Expect_X + hmat(i, Expect_N) * x(i) * hmat(i, Expect_N) !*dx\n ENDDO\n\n WRITE(*, *) Expect_X\n\nEND PROGRAM PIB1D_INFINITE_WELL\n", "meta": {"hexsha": "c7abb235ca5207b94af41b646d063d6d08d8c752", "size": 2152, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Particle In a Box (PIB)/1_InfiniteWell.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Particle In a Box (PIB)/1_InfiniteWell.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Particle In a Box (PIB)/1_InfiniteWell.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 29.8888888889, "max_line_length": 125, "alphanum_fraction": 0.5162639405, "num_tokens": 818, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129327, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.7891207111196641}} {"text": "SUBROUTINE running_average ( x, ave, std_dev, nvals, reset )\r\n!\r\n! Purpose:\r\n! To calculate the running average, standard deviation,\r\n! and number of data points as data values x are received. \r\n! If \"reset\" is .TRUE., clear running sums and exit. \r\n!\r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 06/26/02 S. J. Chapman Original code\r\n!\r\nIMPLICIT NONE\r\n\r\n! Data dictionary: declare calling parameter types & definitions\r\nREAL, INTENT(IN) :: x ! Input data value.\r\nREAL, INTENT(OUT) :: ave ! Running average.\r\nREAL, INTENT(OUT) :: std_dev ! Running standard deviation.\r\nINTEGER, INTENT(OUT) :: nvals ! Current number of points.\r\nLOGICAL, INTENT(IN) :: reset ! Reset flag: clear sums if true\r\n\r\n! Data dictionary: declare local variable types & definitions\r\nINTEGER, SAVE :: n ! Number of input values.\r\nREAL, SAVE :: sum_x ! Sum of input values.\r\nREAL, SAVE :: sum_x2 ! Sum of input values squared.\r\n\r\n! If the reset flag is set, clear the running sums at this time.\r\ncalc_sums: IF ( reset ) THEN\r\n\r\n n = 0 \r\n sum_x = 0.\r\n sum_x2 = 0.\r\n ave = 0.\r\n std_dev = 0.\r\n nvals = 0\r\n \r\nELSE\r\n \r\n ! Accumulate sums.\r\n n = n + 1\r\n sum_x = sum_x + x\r\n sum_x2 = sum_x2 + x**2\r\n \r\n ! Calculate average.\r\n ave = sum_x / REAL(n)\r\n\r\n ! Calculate standard deviation.\r\n IF ( n >= 2 ) THEN \r\n std_dev = SQRT( (REAL(n) * sum_x2 - sum_x**2) &\r\n / (REAL(n) * REAL(n-1)) )\r\n ELSE\r\n std_dev = 0.\r\n END IF\r\n\r\n ! Number of data points.\r\n nvals = n\r\n\r\nEND IF calc_sums\r\n \r\nEND SUBROUTINE running_average\r\n", "meta": {"hexsha": "b39981147068562184d9c5c33528851b4db28f21", "size": 1747, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap9/running_average.f90", "max_stars_repo_name": "yangyang14641/FortranLearning", "max_stars_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-03-12T02:18:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-05T07:58:56.000Z", "max_issues_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap9/running_average.f90", "max_issues_repo_name": "yangyang14641/FortranLearning", "max_issues_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap9/running_average.f90", "max_forks_repo_name": "yangyang14641/FortranLearning", "max_forks_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-05-11T02:36:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T06:36:55.000Z", "avg_line_length": 28.6393442623, "max_line_length": 65, "alphanum_fraction": 0.5649685175, "num_tokens": 479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.7890278580800338}} {"text": "function legpts(n,I_in) result(x)\n! Returns legendre points on interval I by applying the recurrence relation for the Legendre polynomials and their derivatives to perform Newton iteration on the WKB approximation to the roots.\n!This code was adapted from Chebfun (https://www.chebfun.org) legpts.m\n! === Parameters ===========================================\n! n - number of chebyshev points\n! I_in - (array) 2x1 array containing inteval\n! === Output ==============================================\n! c - (array) nx1 array of chebyshev points\n\n\ninteger, intent(in) :: n\nreal(kind=8), intent(in), optional :: I_in(2)\nreal(kind=8) :: I(2), eps\nreal(kind=8), allocatable :: x(:), Pm1(:), Pm2(:), PPm1(:), PPm2(:), P(:), PP(:), dx(:), xp(:)\ninteger :: counter, j, npn, nnn\n\nif(present(I_in)) then\n I = I_in\nelse\n I = (/ -1.d0, 1.d0 /)\nendif\n\nallocate(x(n))\n\nif(n .eq. 1) then\n x(1) = 0.d0\n RETURN\nendif\n\n\nnpn = ceiling(n / 2.d0) ! num positive nodes\nnnn = floor(n / 2.0d0) ! num negative nodes\n\nallocate(xp(npn))\nallocate(P(npn))\nallocate(PP(npn))\nallocate(Pm1(npn))\nallocate(Pm2(npn))\nallocate(PPm2(npn))\nallocate(PPm1(npn))\nallocate(dx(npn))\n\ndo j = 1, npn\n xp(j) = real(npn - (j - 1))\nenddo\n\n! form initial guess\nxp = PI * (4.d0 * xp - 1.d0) / (4.d0 * n + 2.d0)\nxp = (1.d0 - (n - 1.d0) / (8.d0 * n**3) - 1.d0 / (384.d0 * n**4) * (39.d0 - 28.d0 / sin(xp)**2) ) * cos(xp)\n\nPm2 = 1.d0\nPm1 = xp\nPPm2 = 0.d0\nPPm1 = 1.d0\neps = .00000000000000023d0\ndx = 2.d0 * eps\ncounter = 0\n\n! Newton Interations\ndo while ( maxval(abs(dx)) > eps .and. counter < 10)\n counter = counter + 1;\n do j = 1, n-1\n P = ((2.d0 * j + 1.d0) * Pm1 * xp - j * Pm2) / (j + 1.d0);\n Pm2 = Pm1;\n Pm1 = P;\n PP = ((2.d0 * j + 1.d0) * (Pm2 + xp * PPm1) - j * PPm2) / (j + 1.d0);\n PPm2 = PPm1;\n PPm1 = PP;\n enddo\n ! Newton correction and update\n dx = -P / PP;\n xp = xp + dx;\n ! reinitialize\n Pm2 = 1;\n Pm1 = xp;\n PPm2 = 0;\n PPm1 = 1;\nenddo\n\n! reflect positive points\nx(n-npn+1:n) = xp\ndo j = 1, nnn\n x(j) = -1 * xp(npn - j + 1)\nend do\n\n! scale according to interval\nx = (I(2) - I(1))/2.d0 * x + (I(2) + I(1))/2.d0\n\nend function legpts\n", "meta": {"hexsha": "6ac1d83eab0873889bc3efe5eea36767be09af12", "size": 2195, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "partitioned/fortran/tools/functions/legpts.f90", "max_stars_repo_name": "buvoli/epbm", "max_stars_repo_head_hexsha": "32ffe175a2e3456799ebc3e6feeb085ff5c83f81", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "partitioned/fortran/tools/functions/legpts.f90", "max_issues_repo_name": "buvoli/epbm", "max_issues_repo_head_hexsha": "32ffe175a2e3456799ebc3e6feeb085ff5c83f81", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "partitioned/fortran/tools/functions/legpts.f90", "max_forks_repo_name": "buvoli/epbm", "max_forks_repo_head_hexsha": "32ffe175a2e3456799ebc3e6feeb085ff5c83f81", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.3888888889, "max_line_length": 193, "alphanum_fraction": 0.5494305239, "num_tokens": 861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218262741297, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7890278575153249}} {"text": "PROGRAM Radioactive_Decay\n!--------------------------------------------------------\n! 给定放射性元素的初量值和半衰期,计算一定时间后的剩余量\n! 变量名:\n!  InitialAmount : 放射性元素的初量值(mg)\n! RemainingAmount : 放射性元素的剩余量(mg)\n! HalfLife : 放射性元素的半衰期(天)\n! Time : 给定时间 (天)\n! 输入变量:InitialAmount,HalfLife,Time\n! 输出变量:RemainingAmount\n!--------------------------------------------------------\n\nIMPLICIT NONE\nREAL :: InitialAmount, RemainingAmount, HalfLife, Time\n\nPRINT *, \"输入初量值(mg),半衰期(天),时间(天)\"\nREAD *, InitialAmount, HalfLife, Time\n\nRemainingAmount=InitialAmount*0.5**(Time/HalfLife)\nPRINT *, \"剩余量=\",RemainingAmount,\" (mg)\"\n\nEND PROGRAM Radioactive_Decay\n", "meta": {"hexsha": "5df63dd34cff6ecdeef0464c8150e79f3b869107", "size": 678, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "testfortran90/e_121_03.f90", "max_stars_repo_name": "quchunguang/test", "max_stars_repo_head_hexsha": "dd1dde14a69d9e8b2c9ed3efbf536df7840f0487", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-06T02:02:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-06T02:02:59.000Z", "max_issues_repo_path": "testfortran90/e_121_03.f90", "max_issues_repo_name": "SrikanthParsha14/test", "max_issues_repo_head_hexsha": "8cee69e09c8557d53d8d30382cec8ea5c1f82f6e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "testfortran90/e_121_03.f90", "max_forks_repo_name": "SrikanthParsha14/test", "max_forks_repo_head_hexsha": "8cee69e09c8557d53d8d30382cec8ea5c1f82f6e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-06-17T13:20:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-17T13:20:39.000Z", "avg_line_length": 29.4782608696, "max_line_length": 57, "alphanum_fraction": 0.5545722714, "num_tokens": 235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458251637412, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.7889985996925695}} {"text": "C User-defined Rate Law functions\nC Note: the default argument type for rate laws, as read from the equations file, is single precision\nC but all the internal calculations are performed in REAL*8\n\nC Arrhenius\n KPP_REAL FUNCTION ARR( A0,B0,C0 )\n INCLUDE 'KPP_ROOT_Parameters.h'\n INCLUDE 'KPP_ROOT_Global.h'\n \n REAL A0,B0,C0 \n ARR = DBLE(A0) * EXP(-DBLE(B0)/TEMP) * (TEMP/300.0D0)**DBLE(C0) \n \n RETURN\n END \n\n\nC Simplified Arrhenius, with two arguments\nC Note: The argument B0 has a changed sign when compared to ARR\n KPP_REAL FUNCTION ARR2( A0,B0 )\n INCLUDE 'KPP_ROOT_Parameters.h'\n INCLUDE 'KPP_ROOT_Global.h'\n \n REAL A0,B0 \n ARR2 = DBLE(A0) * EXP( DBLE(B0)/TEMP ) \n \n RETURN\n END \n\n KPP_REAL FUNCTION EP2(A0,C0,A2,C2,A3,C3)\n INCLUDE 'KPP_ROOT_Parameters.h' \n INCLUDE 'KPP_ROOT_Global.h'\n \n REAL A0,C0,A2,C2,A3,C3\n REAL*8 K0,K2,K3\n \n K0 = DBLE(A0) * EXP(-DBLE(C0)/TEMP)\n K2 = DBLE(A2) * EXP(-DBLE(C2)/TEMP)\n K3 = DBLE(A3) * EXP(-DBLE(C3)/TEMP)\n K3 = K3*CFACTOR*1.0d6\n EP2 = K0 + K3/(1.0d0+K3/K2 )\n \n RETURN\n END \n\n\n KPP_REAL FUNCTION EP3(A1,C1,A2,C2) \n INCLUDE 'KPP_ROOT_Parameters.h' \n INCLUDE 'KPP_ROOT_Global.h'\n \n REAL A1, C1, A2, C2\n REAL*8 K1, K2\n \n K1 = DBLE(A1) * EXP(-DBLE(C1)/TEMP)\n K2 = DBLE(A2) * EXP(-DBLE(C2)/TEMP)\n EP3 = K1 + K2*(1.0d6*CFACTOR)\n \n RETURN\n END \n\n\n KPP_REAL FUNCTION FALL ( A0,B0,C0,A1,B1,C1,CF)\n INCLUDE 'KPP_ROOT_Parameters.h' \n INCLUDE 'KPP_ROOT_Global.h'\n \n REAL A0,B0,C0,A1,B1,C1,CF\n REAL*8 K0, K1\n \n K0 = DBLE(A0) * EXP(-DBLE(B0)/TEMP)* (TEMP/300.0D0)**DBLE(C0)\n K1 = DBLE(A1) * EXP(-DBLE(B1)/TEMP)* (TEMP/300.0D0)**DBLE(C1)\n K0 = K0*CFACTOR*1.0D6\n K1 = K0/K1\n FALL = (K0/(1.0d0+K1))*\n * DBLE(CF)**(1.0d0/(1.0d0+(DLOG10(K1))**2))\n \n RETURN\n END\n", "meta": {"hexsha": "00c1c381ba9e1ddbcc63f0c890191cc0073ee4e7", "size": 2136, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "chem/KPP/kpp/kpp-2.1/util/UserRateLaws.f", "max_stars_repo_name": "matzegoebel/WRF-fluxavg", "max_stars_repo_head_hexsha": "686ae53053bf7cb55d6f078916d0de50f819fc62", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2018-08-27T12:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-16T14:22:54.000Z", "max_issues_repo_path": "chem/KPP/kpp/kpp-2.1/util/UserRateLaws.f", "max_issues_repo_name": "teb-model/wrf-teb", "max_issues_repo_head_hexsha": "60882e61a2a3d91f1c94cb5b542f46ffaebfad71", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2018-09-18T16:44:30.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-07T10:59:59.000Z", "max_forks_repo_path": "chem/KPP/kpp/kpp-2.1/util/UserRateLaws.f", "max_forks_repo_name": "teb-model/wrf-teb", "max_forks_repo_head_hexsha": "60882e61a2a3d91f1c94cb5b542f46ffaebfad71", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-08-31T21:51:56.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-21T21:41:59.000Z", "avg_line_length": 27.7402597403, "max_line_length": 102, "alphanum_fraction": 0.5276217228, "num_tokens": 741, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075701109192, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7888255872829566}} {"text": "PROGRAM question3\n IMPLICIT NONE\n ! ----------------- Static Dimension Statements ------------------- !\n ! INTEGER :: i, j, k\n ! REAL, DIMENSION(3):: a, b, sum\n\n ! WRITE(*, *) \"Enter 3 Real Number for first vector in a line\"\n ! READ(*, *) (a(i), i = 1, 3)\n ! WRITE(*, *) \"Enter 3 Real Number for Second vector in a line\"\n ! READ(*, *) (b(j), j = 1, 3)\n \n ! DO k = 1, 3\n ! sum(k) = a(k) + b(k)\n ! ENDDO\n\n ! WRITE(*, *) \"The sum of these vector is\"\n ! WRITE(*, *) (sum(k), k = 1, 3)\n ! WRITE(*, *) \"The lenghth of final vector is = 3\"\n\n\n ! ----------------- Allocatable Arrays ------------------- ! \n INTEGER :: i, j, k, n, m, sum_size\n REAL, DIMENSION(:), ALLOCATABLE:: a, b, sum\n \n 10 FORMAT(\"Enter \", i0, \" real number for this vector: \")\n\n WRITE(*, '(A)', ADVANCE = \"NO\") \"Enter dimention of first vector: \"\n READ(*, *) n\n WRITE(*, *)\n ALLOCATE(a(n))\n WRITE(*, 10, ADVANCE = \"NO\") n\n READ(*, *) (a(i), i = 1, n)\n \n WRITE(*, *)\n WRITE(*, '(A)', ADVANCE = \"NO\") \"Enter dimention of second vector: \"\n READ (*, *) m\n ALLOCATE(b(m))\n WRITE(*, 10, ADVANCE = \"NO\") m\n READ(*, *) (b(j), j = 1, m)\n \n sum_size = MAX(n, m)\n ALLOCATE(sum(sum_size))\n\n DO k = 1, sum_size\n IF(n == 0) THEN\n sum(k) = b(k)\n ELSE IF(m == 0) THEN\n sum(k) = a(k)\n ELSE \n sum(k) = a(k) + b(k)\n n = n-1\n m = m-1\n ENDIF\n ENDDO\n\n WRITE(*, *)\n WRITE(*, '(A)', ADVANCE = \"NO\") \"The sum of these vector is: \"\n WRITE(*, *) (sum(k), k = 1, sum_size)\n\n WRITE(*, 11) sum_size\n 11 FORMAT(/,\"Length of final vector = \", i0/)\n\nEND", "meta": {"hexsha": "1567851921cf4c1f68a1dc66fc423756c28db084", "size": 1700, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Practice-1/3.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Practice-1/3.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practice-1/3.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 26.9841269841, "max_line_length": 73, "alphanum_fraction": 0.4494117647, "num_tokens": 582, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.8705972633721708, "lm_q1q2_score": 0.7887522626885852}} {"text": "! triangle - SSS configuration\n! input - the lengths of the three sides\n! output -\n! the angles opposite each side\n! the semiperimeter and the area\n! type of triangle\n\n program triangle\n print*,\"SSS Congruence\"\n print*,\"Enter the lengths of the three sides:\"\n read(*,*) a, b, c\n\n! Error conditions\n! (1) the sides must be positive in length\n if(a.le.0.0 .or. b.le.0.0 .or. c.le.0.0) then\n print*,\"ERROR: The sides must be positive in length\"\n stop 1\n end if\n! (2) The triangle inequality must be strictly satisfied.\n! a + b < c; b + c < a; c + a < c\n! A sufficient and necessary condition is that no side may\n! exceed the semiperimeter.\n s = (a + b + c) / 2.0 ! semiperimeter\n if (max(a,b,c) .ge. s) then\n print*,\"ERROR: (triangle inequality) max(a,b,c) < s\"\n stop 1\n end if\n\n write(6,*) \"sides:\", a, b, c\n\n! law of cosines\n alpha = acos((b*b + c*c - a*a) / (2*b*c))\n beta = acos((a*a + c*c - b*b) / (2*a*c))\n gamm = acos((a*a + b*b - c*c) / (2*a*b))\n\n! angles in degrees\n pi = 4*atan(1.d0)\n dalpha = 180 * alpha / pi\n dbeta = 180 * beta / pi\n dgamma = 180 * gamm / pi\n\n! output solution of triangle\n print*,\"------- SOLUTION ------------------------------------\"\n write(6,*) \"a =\", a, \" (given)\"\n write(6,*) \"b =\", b, \" (given)\"\n write(6,*) \"c =\", c, \" (given)\"\n write(6,*) \"A =\", alpha, \"degrees:\", dalpha\n write(6,*) \"B =\", beta, \"degrees:\", dbeta\n write(6,*) \"C =\", gamm, \"degrees:\", dgamma\n print*,\"-----------------------------------------------------\"\n\n! output semiperimeter and area\n write(6,*) \"semiperimeter:\", s\n area = sqrt(s * (s-a) * (s-b) * (s-c)) ! Heron's formula\n write(6,*) \"area:\", area\n\n! angle sum\n sum1 = alpha + beta + gamm\n err1 = sum1 - pi\n sum2 = dalpha + dbeta + dgamma\n err2 = sum2 - 180.0\n write(6,*) \"angle sum (radians):\", sum1, \" error:\", err1\n write(6,*) \"angle sum (degrees):\", sum2, \" error:\", err2\n\n! Nesbitt's inequality\n symsum = a/(b+c) + b/(a+c) + c/(a+b)\n print*,\"Nesbitt's symmetric sum:\", symsum\n if (symsum.lt.1.5) then\n print*,\" Error: sum < 1.5\"\n end if\n if (symsum.ge.2) then\n print*,\" Error: sum > 2\"\n end if\n\n end program\n", "meta": {"hexsha": "267534fd2ab859008232a62513c3cda72034c1e4", "size": 2398, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sss.f90", "max_stars_repo_name": "econrad003/fortran-examples", "max_stars_repo_head_hexsha": "c323474b6eb9abc16305ec2bb6e95851311df146", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sss.f90", "max_issues_repo_name": "econrad003/fortran-examples", "max_issues_repo_head_hexsha": "c323474b6eb9abc16305ec2bb6e95851311df146", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sss.f90", "max_forks_repo_name": "econrad003/fortran-examples", "max_forks_repo_head_hexsha": "c323474b6eb9abc16305ec2bb6e95851311df146", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.5526315789, "max_line_length": 68, "alphanum_fraction": 0.4970809008, "num_tokens": 785, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541593883189, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7887483224594829}} {"text": "! **\n! * Provides a root finder using Newton's method\n! **\nmodule newton\n use kinds, only: dp\n implicit none\n private\n public :: root\n\n contains\n\n ! **\n ! * Searches for the root of the function f(x, [p2,p3,p4,p5])-offset_in.\n ! *\n ! * Input:\n ! * - f: function, whose root will be searched\n ! * - df: derivative of f(x,...)\n ! * - xguess: an initial guess for the root\n ! * - minx_in (optional): if this parameter is present, the root is only searched for in the right neighborhood of minx_in\n ! * - max_iter_in (optional): maximum amount of iterations in Newton's method\n ! * - eps_in (optional): if this parameter is present, the root is approximated until the absolute difference between subsequent guesses for the root abs(dx)<=eps.\n ! * Default value, if parameter is not present: 1.d-08\n ! * - offset_in (optional): if this parameter is present, the root is only searched for in the right neighborhood of minx_in\n ! * - p2, p3, p4, p5 (optional): optional parameters for the function f and its derivative df\n ! *\n ! * Return value: the x* for which f(x*,...)-offset_in=0.\n ! **\n real(dp) function root(f,df,xguess,minx_in,max_iter_in,eps_in, offset_in,p2,p3,p4,p5)\n procedure(real(dp)) :: f,df\n real(dp), intent(in) :: xguess\n real(dp), intent(in), optional :: p2,p3,p4,p5\n real(dp), intent(in), optional :: eps_in, minx_in, offset_in\n integer, intent(in), optional :: max_iter_in\n\n integer :: i, max_iter\n real(dp) :: x,xn,dx,val,eps,minx,offset\n\n eps = 1.d-08\n minx = -10.d14\n max_iter = 400\n offset = 0.0_dp\n if (present(eps_in)) eps = eps_in\n if (present(minx_in)) minx = minx_in\n if (present(max_iter_in)) max_iter = max_iter_in\n if (present(offset_in)) offset = offset_in\n\n x=xguess\n do i=1, max_iter\n val = f(x,p2,p3,p4,p5)-offset\n dx = val/df(x,p2,p3,p4,p5)\n xn = x - dx\n if (xn <= minx) xn=minx+0.000000000001_dp\n ! if (abs(dx) <= eps .AND. xn > minx) then\n if (abs(dx) <= eps*(1+abs(xn)) .AND. abs(val)<=eps) then\n root = xn\n return\n end if\n x = xn\n end do\n print *, \"Could not find root of equation within \",max_iter,\" iterations.\"\n print *, \"This usually happens when the optimal continuous choice is almost 0, often indicating a problem with the model.\"\n stop\n end function root\nend module newton\n", "meta": {"hexsha": "719fb3e550dfa7fb33eeb6eb05b3060d70c56da3", "size": 2956, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "newton.f90", "max_stars_repo_name": "carlozanella/ncegm", "max_stars_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-03-14T23:31:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-14T23:31:35.000Z", "max_issues_repo_path": "newton.f90", "max_issues_repo_name": "carlozanella/ncegm", "max_issues_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "newton.f90", "max_forks_repo_name": "carlozanella/ncegm", "max_forks_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.4769230769, "max_line_length": 175, "alphanum_fraction": 0.5152232747, "num_tokens": 735, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541577509315, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7887483153624872}} {"text": "module signals\n\nuse, intrinsic:: iso_c_binding, only: c_int\nuse comm, only: sp, dp, J\n\nimplicit none (type, external)\nprivate\npublic :: signoise\n\ninterface randn\nprocedure randn_r, randn_c\nend interface randn\n\ninterface signoise\nprocedure signoise_r, signoise_c\nend interface signoise\n\nreal(dp) :: pi = 4._dp * atan(1._dp)\nreal(sp) :: pi_sp = 4._sp * atan(1._sp)\n\ncontains\n\nsubroutine signoise_c(fs,f0,snr,Ns,x) bind(c)\n! generate noisy tone\n\nreal(dp),intent(in) :: fs,f0,snr\ninteger(c_int), intent(in) :: Ns\ncomplex(dp),intent(out) :: x(Ns)\n\nreal(dp) :: t(Ns),nvar\ncomplex(dp) :: noise(Ns)\ninteger :: i\n\nt = [(i, i=0,size(x)-1)] / fs\nx = sqrt(2._dp) * exp(J * 2._dp * pi * f0 * t)\n!--- add noise\ncall randn(noise)\n\nnvar = 10._dp**(-snr/10._dp)\n\nx = x + sqrt(nvar)*noise\n\nend subroutine signoise_c\n\n\nsubroutine signoise_r(fs,f0,snr,Ns,x) bind(c)\n! generate noisy tone\n\nreal(sp),intent(in) :: fs,f0,snr\ninteger(c_int), intent(in) :: Ns\nreal(sp),intent(out) :: x(Ns)\n\n\nreal(sp) :: t(Ns),nvar\nreal(sp) :: noise(Ns)\ninteger(c_int) :: i\n\nt = [(i, i=0, size(x)-1)] / fs\nx = sqrt(2._sp) * cos(2._sp * pi_sp * f0 * t)\n\n!--- add noise\ncall randn(noise)\n\nnvar = 10._sp**(-snr / 10._sp)\n\nx = x + sqrt(nvar) * noise\n\nend subroutine signoise_r\n\n!---------------------------------\n\nimpure elemental subroutine randn_c(noise)\n! implements Box-Muller Transform\n! https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform\n!\n! Input:\n! N: length of 1-D noise vector\n! Output:\n! noise: Gaussian 1-D noise vector\n\ncomplex(dp), intent(out) :: noise\nreal(dp) :: u1, u2, x_i, x_r\n\ncall random_number(u1)\ncall random_number(u2)\n\nx_r = sqrt(-2._dp * log(u1)) * cos(2._dp * pi * u2)\nx_i = sqrt(-2._dp * log(u1)) * sin(2._dp * pi * u2)\n\nnoise = cmplx(x_r, x_i, dp) !complex() can only handle scalars\n\nend subroutine randn_c\n\n\nimpure elemental subroutine randn_r(noise)\n! implements Box-Muller Transform\n! https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform\n!\n! Input:\n! N: length of 1-D noise vector\n! Output:\n! noise: Gaussian 1-D noise vector\n\nreal(sp), intent(out) :: noise\nreal(sp) :: u1, u2\n\ncall random_number(u1)\ncall random_number(u2)\n\nnoise = sqrt(-2._sp * log(u1)) * cos(2._sp * pi_sp * u2)\n\nend subroutine randn_r\n\nend module signals\n", "meta": {"hexsha": "df917d1a6060d29c591e6e6fd829da89769894d4", "size": 2227, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/signals.f90", "max_stars_repo_name": "scivision/spectral_analysis", "max_stars_repo_head_hexsha": "1ce5bcf2d9ce3dbc15c4e9fe124585fb7e57ad6e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2017-10-18T17:58:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-17T12:02:45.000Z", "max_issues_repo_path": "src/signals.f90", "max_issues_repo_name": "scivision/spectral_analysis", "max_issues_repo_head_hexsha": "1ce5bcf2d9ce3dbc15c4e9fe124585fb7e57ad6e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/signals.f90", "max_forks_repo_name": "scivision/spectral_analysis", "max_forks_repo_head_hexsha": "1ce5bcf2d9ce3dbc15c4e9fe124585fb7e57ad6e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-04-19T19:38:54.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-24T03:10:52.000Z", "avg_line_length": 19.3652173913, "max_line_length": 63, "alphanum_fraction": 0.6663673103, "num_tokens": 765, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464796, "lm_q2_score": 0.8596637577007394, "lm_q1q2_score": 0.7885718532318353}} {"text": "! A fortran f90 code to test mlfv_mod (Mittag-Leffler f90 implementation)\n! \n! \n! Created by Davide Verotta on 3/12/10.\n! Copyright 2010 UCSF. All rights reserved.\n! \n! Completely modified by Eduardo Mendes (with the permission of Davide Verotta) on 5/12/15 \n! to fix bugs, to deal with complex numbers and to include the derivative\n! of the Mittag-Leffler function\n!\n! Examples: I have tried to reproduce Figres 5 to 15 of the paper Computation of the Mittag-Leffler\n! function and its derivatives. Fract. Calc. Appl. Anal. 5(2002), 491-518 \n! by R.Gorenflo, J.Loutchko, and Yu. Luchko\n!\n! Obs.: The derivative shown here is not the time derivative shown on the paper but the derivative\n! shown on Section 4 of the aforementioned paper.\n!\n! Please nota that the way the Mittag-Leffler function is called.\n! In case where z is not complex, use real to get the real part of the result.\n\nprogram test_mlfv\n\nuse mlfv_mod\n\nimplicit none\n\ninteger, parameter :: npoints = 4\n\nreal(8) :: alpha,beta,y,x\nreal(8), dimension(npoints+1) :: t\ncomplex(8) :: z,aux\ninteger :: fi\ninteger :: i\ncharacter(len=3) :: imag_unity = '+i*'\ncharacter(len=3) :: imag_unitz = '+i*'\nreal(8), parameter :: pi = 3.1415926535897932384626434D0\n\nfi=8\n\n! Figure 5\n\nalpha=0.25d0\nbeta=1.0d0\n\n\nprint *,' '\nprint *,'********************************************************************************************************'\nwrite(*,\"(a36,f4.2,a9,f4.2,a20)\") \" Mittag-Leffer function for alpha = \",alpha,\", beta = \", beta,\" E_{alpha,beta}(-t)\"\nprint *,' '\nprint *,'Figure 5 of the paper Fract. Calc. Appl. Anal. 5(2002), 491-518 by R.Gorenflo, J.Loutchko and Yu. Luchko'\nprint *,'********************************************************************************************************'\nprint *, ' '\n\nprint*,\"---------------------------------------------------------------------------------------------------\"\nprint*, \" t alpha beta y Derivative of E \"\nprint*,\"---------------------------------------------------------------------------------------------------\"\n\n\t\ndo i=1,(npoints+1)\n t(i)=(dble(i-1)*(10d0-0d0)/dble(npoints)) ! 10\n z=dcmplx(-t(i),0)\n y=real(mlfv(alpha,beta,z,fi))\n x=real(mlfvderiv(alpha,beta,z,fi))\n write(*,\"(5E20.12)\") t(i),alpha,beta,y,x\nend do\n\nprint *,' '\n\n! Figure 6\n\nalpha=1.75d0\nbeta=1.0d0\n\n\nprint *,' '\nprint *,'********************************************************************************************************'\nwrite(*,\"(a36,f4.2,a9,f4.2,a20)\") \" Mittag-Leffer function for alpha = \",alpha,\", beta = \", beta,\" E_{alpha,beta}(-t)\"\nprint *,' '\nprint *,'Figure 6 of the paper Fract. Calc. Appl. Anal. 5(2002), 491-518 by R.Gorenflo, J.Loutchko and Yu. Luchko'\nprint *,'********************************************************************************************************'\nprint *, ' '\n\nprint*,\"---------------------------------------------------------------------------------------------------\"\nprint*, \" t alpha beta y Derivative of E \"\nprint*,\"---------------------------------------------------------------------------------------------------\"\n\n\t\ndo i=1,(npoints+1)\n t(i)=(dble(i-1)*(50d0-0d0)/dble(npoints)) ! 50\n z=dcmplx(-t(i),0)\n y=real(mlfv(alpha,beta,z,fi))\n x=real(mlfvderiv(alpha,beta,z,fi))\n write(*,\"(5E20.12)\") t(i),alpha,beta,y,x\nend do\n\nprint *,' '\n\n! Figure 7\n\nalpha=2.25d0\nbeta=1.0d0\n\n\nprint *,' '\nprint *,'********************************************************************************************************'\nwrite(*,\"(a36,f4.2,a9,f4.2,a20)\") \" Mittag-Leffer function for alpha = \",alpha,\", beta = \", beta,\" E_{alpha,beta}(-t)\"\nprint *,' '\nprint *,'Figure 7 of the paper Fract. Calc. Appl. Anal. 5(2002), 491-518 by R.Gorenflo, J.Loutchko and Yu. Luchko'\nprint *,'********************************************************************************************************'\nprint *, ' '\n\nprint*,\"---------------------------------------------------------------------------------------------------\"\nprint*, \" t alpha beta y Derivative of E \"\nprint*,\"---------------------------------------------------------------------------------------------------\"\n\n\t\ndo i=1,(npoints+1)\n t(i)=(dble(i-1)*(100d0-0d0)/dble(npoints)) ! 100\n z=dcmplx(-t(i),0)\n y=real(mlfv(alpha,beta,z,fi))\n x=real(mlfvderiv(alpha,beta,z,fi))\n write(*,\"(5E20.12)\") t(i),alpha,beta,y,x\nend do\n\nprint *,' '\n\n! Figure 8\n\nalpha=0.75d0\nbeta=1.0d0\n\nprint *,'********************************************************************************************************'\nwrite(*,\"(a36,f4.2,a9,f4.2,a20)\") \" Mittag-Leffer function for alpha = \",alpha,\", beta = \", beta,\"arg(z) = alpha*pi/4\"\nprint *,' '\nprint *,'Figure 8 of the paper Fract. Calc. Appl. Anal. 5(2002), 491-518 by R.Gorenflo, J.Loutchko and Yu. Luchko'\nprint *,'********************************************************************************************************'\nprint *, ' '\n\nprint*,\"-----------------------------------------------------------------------------------------------------------------------\"\nprint*, \" t z alpha beta y abs(y) \"\nprint*,\"-----------------------------------------------------------------------------------------------------------------------\"\n\ndo i=1,(npoints+1)\n t(i)=(dble(i-1)*(5d0-0d0)/dble(npoints))\n z=dcmplx(t(i),0)*exp(dcmplx(0,1)*alpha*pi/4d0)\n if (aimag(z)<0.) then \n imag_unitz = '-i*'\n else\n imag_unitz = '+i*'\n end if\n aux=mlfv(alpha,beta,z,fi)\n if (aimag(aux)<0.) then \n imag_unity = '-i*'\n else\n imag_unity = '+i*'\n end if\n! write(*,\"(4E20.12)\") t(i),alpha,beta,y\n write(*,\"(f6.2,3x,e11.5,a3,e11.5,3x,f4.2,4x,f4.2,3x,e11.5,a3,e11.5,4x,e11.5)\") t(i),real(z),&\n &imag_unitz,abs(aimag(z)),alpha,beta,real(aux),imag_unity,abs(aimag(aux)),abs(aux)\nend do\n\nprint *,' '\n\n! Figure 9\n\nalpha=0.75d0\nbeta=1.0d0\n\nprint *,'********************************************************************************************************'\nwrite(*,\"(a36,f4.2,a9,f4.2,a20)\") \" Mittag-Leffer function for alpha = \",alpha,\", beta = \", beta,\"arg(z) = alpha*pi/2\"\nprint *,' '\nprint *,'Figure 9 of the paper Fract. Calc. Appl. Anal. 5(2002), 491-518 by R.Gorenflo, J.Loutchko and Yu. Luchko'\nprint *,'********************************************************************************************************'\nprint *, ' '\n\nprint*,\"-----------------------------------------------------------------------------------------------------------------------\"\nprint*, \" t z alpha beta y abs(y) \"\nprint*,\"-----------------------------------------------------------------------------------------------------------------------\"\n\ndo i=1,(npoints+1)\n t(i)=(dble(i-1)*(50d0-0d0)/dble(npoints))\n z=dcmplx(t(i),0)*exp(dcmplx(0,1)*alpha*pi/2d0)\n if (aimag(z)<0.) then \n imag_unitz = '-i*'\n else\n imag_unitz = '+i*'\n end if\n aux=mlfv(alpha,beta,z,fi)\n if (aimag(aux)<0.) then \n imag_unity = '-i*'\n else\n imag_unity = '+i*'\n end if\n! write(*,\"(4E20.12)\") t(i),alpha,beta,y\n write(*,\"(f6.2,3x,e11.5,a3,e11.5,3x,f4.2,4x,f4.2,3x,e11.5,a3,e11.5,4x,e11.5)\") t(i),real(z),&\n &imag_unitz,abs(aimag(z)),alpha,beta,real(aux),imag_unity,abs(aimag(aux)),abs(aux)\nend do\n\nprint *,' '\n\n! Figure 10\n\nalpha=0.75d0\nbeta=1.0d0\n\nprint *,'**********************************************************************************************************'\nwrite(*,\"(a36,f4.2,a9,f4.2,a22)\") \" Mittag-Leffer function for alpha = \",alpha,\", beta = \", beta,\"arg(z) = alpha*3*pi/4\"\nprint *,' '\nprint *,'Figure 10 of the paper Fract. Calc. Appl. Anal. 5(2002), 491-518 by R.Gorenflo, J.Loutchko and Yu. Luchko'\nprint *,'**********************************************************************************************************'\nprint *, ' '\n\nprint*,\"-----------------------------------------------------------------------------------------------------------------------\"\nprint*, \" t z alpha beta y abs(y) \"\nprint*,\"-----------------------------------------------------------------------------------------------------------------------\"\n\ndo i=1,(npoints+1)\n t(i)=(dble(i-1)*(50d0-0d0)/dble(npoints))\n z=dcmplx(t(i),0)*exp(dcmplx(0,1)*alpha*3d0*pi/4d0)\n if (aimag(z)<0.) then \n imag_unitz = '-i*'\n else\n imag_unitz = '+i*'\n end if\n aux=mlfv(alpha,beta,z,fi)\n if (aimag(aux)<0.) then \n imag_unity = '-i*'\n else\n imag_unity = '+i*'\n end if\n! write(*,\"(4E20.12)\") t(i),alpha,beta,y\n write(*,\"(f6.2,3x,e11.5,a3,e11.5,3x,f4.2,4x,f4.2,3x,e11.5,a3,e11.5,4x,e11.5)\") t(i),real(z),&\n &imag_unitz,abs(aimag(z)),alpha,beta,real(aux),imag_unity,abs(aimag(aux)),abs(aux)\nend do\n\nprint *,' '\n\n! Figure 11\n\nalpha=0.75d0\nbeta=1.0d0\n\nprint *,'**********************************************************************************************************'\nwrite(*,\"(a36,f4.2,a9,f4.2,a22)\") \" Mittag-Leffer function for alpha = \",alpha,\", beta = \", beta,\"arg(z) = pi\"\nprint *,' '\nprint *,'Figure 11 of the paper Fract. Calc. Appl. Anal. 5(2002), 491-518 by R.Gorenflo, J.Loutchko and Yu. Luchko'\nprint *,'**********************************************************************************************************'\nprint *, ' '\n\nprint*,\"-----------------------------------------------------------------------------------------------------------------------\"\nprint*, \" t z alpha beta y real(y) \"\nprint*,\"-----------------------------------------------------------------------------------------------------------------------\"\n\ndo i=1,(npoints+1)\n t(i)=(dble(i-1)*(100d0-0d0)/dble(npoints))\n z=dcmplx(t(i),0)*exp(dcmplx(0,1)*pi)\n if (aimag(z)<0.) then \n imag_unitz = '-i*'\n else\n imag_unitz = '+i*'\n end if\n aux=mlfv(alpha,beta,z,fi)\n if (aimag(aux)<0.) then \n imag_unity = '-i*'\n else\n imag_unity = '+i*'\n end if\n! write(*,\"(4E20.12)\") t(i),alpha,beta,y\n write(*,\"(f6.2,3x,e11.5,a3,e11.5,3x,f4.2,4x,f4.2,3x,e11.5,a3,e11.5,4x,e11.5)\") t(i),real(z),&\n &imag_unitz,abs(aimag(z)),alpha,beta,real(aux),imag_unity,abs(aimag(aux)),real(aux)\nend do\n\nprint *,' '\n\n! Figure 12\n\nalpha=1.25d0\nbeta=1.0d0\n\nprint *,'********************************************************************************************************'\nwrite(*,\"(a36,f4.2,a9,f4.2,a20)\") \" Mittag-Leffer function for alpha = \",alpha,\", beta = \", beta,\"arg(z) = alpha*pi/4\"\nprint *,' '\nprint *,'Figure 12 of the paper Fract. Calc. Appl. Anal. 5(2002), 491-518 by R.Gorenflo, J.Loutchko and Yu. Luchko'\nprint *,'********************************************************************************************************'\nprint *, ' '\n\nprint*,\"-----------------------------------------------------------------------------------------------------------------------\"\nprint*, \" t z alpha beta y abs(y) \"\nprint*,\"-----------------------------------------------------------------------------------------------------------------------\"\n\ndo i=1,(npoints+1)\n t(i)=(dble(i-1)*(5d0-0d0)/dble(npoints))\n z=dcmplx(t(i),0)*exp(dcmplx(0,1)*alpha*pi/4d0)\n if (aimag(z)<0.) then \n imag_unitz = '-i*'\n else\n imag_unitz = '+i*'\n end if\n aux=mlfv(alpha,beta,z,fi)\n if (aimag(aux)<0.) then \n imag_unity = '-i*'\n else\n imag_unity = '+i*'\n end if\n! write(*,\"(4E20.12)\") t(i),alpha,beta,y\n write(*,\"(f6.2,3x,e11.5,a3,e11.5,3x,f4.2,4x,f4.2,3x,e11.5,a3,e11.5,4x,e11.5)\") t(i),real(z),&\n &imag_unitz,abs(aimag(z)),alpha,beta,real(aux),imag_unity,abs(aimag(aux)),abs(aux)\nend do\n\nprint *,' '\n\n! Figure 13\n\nalpha=1.25d0\nbeta=1.0d0\n\nprint *,'********************************************************************************************************'\nwrite(*,\"(a36,f4.2,a9,f4.2,a20)\") \" Mittag-Leffer function for alpha = \",alpha,\", beta = \", beta,\"arg(z) = alpha*pi/2\"\nprint *,' '\nprint *,'Figure 13 of the paper Fract. Calc. Appl. Anal. 5(2002), 491-518 by R.Gorenflo, J.Loutchko and Yu. Luchko'\nprint *,'********************************************************************************************************'\nprint *, ' '\n\nprint*,\"-----------------------------------------------------------------------------------------------------------------------\"\nprint*, \" t z alpha beta y abs(y) \"\nprint*,\"-----------------------------------------------------------------------------------------------------------------------\"\n\ndo i=1,(npoints+1)\n t(i)=(dble(i-1)*(50d0-0d0)/dble(npoints))\n z=dcmplx(t(i),0)*exp(dcmplx(0,1)*alpha*pi/2d0)\n if (aimag(z)<0.) then \n imag_unitz = '-i*'\n else\n imag_unitz = '+i*'\n end if\n aux=mlfv(alpha,beta,z,fi)\n if (aimag(aux)<0.) then \n imag_unity = '-i*'\n else\n imag_unity = '+i*'\n end if\n! write(*,\"(4E20.12)\") t(i),alpha,beta,y\n write(*,\"(f6.2,3x,e11.5,a3,e11.5,3x,f4.2,4x,f4.2,3x,e11.5,a3,e11.5,4x,e11.5)\") t(i),real(z),&\n &imag_unitz,abs(aimag(z)),alpha,beta,real(aux),imag_unity,abs(aimag(aux)),abs(aux)\nend do\n\nprint *,' '\n\n! Figure 14\n\nalpha=1.25d0\nbeta=1.0d0\n\nprint *,'**********************************************************************************************************'\nwrite(*,\"(a36,f4.2,a9,f4.2,a22)\") \" Mittag-Leffer function for alpha = \",alpha,\", beta = \", beta,\"arg(z) = alpha*3*pi/4\"\nprint *,' '\nprint *,'Figure 14 of the paper Fract. Calc. Appl. Anal. 5(2002), 491-518 by R.Gorenflo, J.Loutchko and Yu. Luchko'\nprint *,'**********************************************************************************************************'\nprint *, ' '\n\nprint*,\"-----------------------------------------------------------------------------------------------------------------------\"\nprint*, \" t z alpha beta y abs(y) \"\nprint*,\"-----------------------------------------------------------------------------------------------------------------------\"\n\ndo i=1,(npoints+1)\n t(i)=(dble(i-1)*(50d0-0d0)/dble(npoints))\n z=dcmplx(t(i),0)*exp(dcmplx(0,1)*alpha*3d0*pi/4d0)\n if (aimag(z)<0.) then \n imag_unitz = '-i*'\n else\n imag_unitz = '+i*'\n end if\n aux=mlfv(alpha,beta,z,fi)\n if (aimag(aux)<0.) then \n imag_unity = '-i*'\n else\n imag_unity = '+i*'\n end if\n! write(*,\"(4E20.12)\") t(i),alpha,beta,y\n write(*,\"(f6.2,3x,e11.5,a3,e11.5,3x,f4.2,4x,f4.2,3x,e11.5,a3,e11.5,4x,e11.5)\") t(i),real(z),&\n &imag_unitz,abs(aimag(z)),alpha,beta,real(aux),imag_unity,abs(aimag(aux)),abs(aux)\nend do\n\nprint *,' '\n\n! Figure 15\n\nalpha=1.25d0\nbeta=1.0d0\n\nprint *,'**********************************************************************************************************'\nwrite(*,\"(a36,f4.2,a9,f4.2,a22)\") \" Mittag-Leffer function for alpha = \",alpha,\", beta = \", beta,\"arg(z) = pi\"\nprint *,' '\nprint *,'Figure 15 of the paper Fract. Calc. Appl. Anal. 5(2002), 491-518 by R.Gorenflo, J.Loutchko and Yu. Luchko'\nprint *,'**********************************************************************************************************'\nprint *, ' '\n\nprint*,\"-----------------------------------------------------------------------------------------------------------------------\"\nprint*, \" t z alpha beta y real(y) \"\nprint*,\"-----------------------------------------------------------------------------------------------------------------------\"\n\ndo i=1,(npoints+1)\n t(i)=(dble(i-1)*(100d0)/dble(npoints))\n z=dcmplx(t(i),0)*exp(dcmplx(0,1)*pi)\n if (aimag(z)<0.) then \n imag_unitz = '-i*'\n else\n imag_unitz = '+i*'\n end if\n aux=mlfv(alpha,beta,z,fi)\n if (aimag(aux)<0.) then \n imag_unity = '-i*'\n else\n imag_unity = '+i*'\n end if\n! write(*,\"(4E20.12)\") t(i),alpha,beta,y\n write(*,\"(f6.2,3x,e11.5,a3,e11.5,3x,f4.2,4x,f4.2,3x,e11.5,a3,e11.5,4x,e11.5)\") t(i),real(z),&\n &imag_unitz,abs(aimag(z)),alpha,beta,real(aux),imag_unity,abs(aimag(aux)),real(aux)\nend do\n\nprint *,' '\n\t\nend program test_mlfv", "meta": {"hexsha": "701012b2ddfa8070ac37f0c583f7b27bbbaba3a4", "size": 16745, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test_mlfv.f90", "max_stars_repo_name": "emammendes/Fortran-Code---Mittag-Leffler-Function", "max_stars_repo_head_hexsha": "911ea9253d8367b19f94b026a457ff35a724d34c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test_mlfv.f90", "max_issues_repo_name": "emammendes/Fortran-Code---Mittag-Leffler-Function", "max_issues_repo_head_hexsha": "911ea9253d8367b19f94b026a457ff35a724d34c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-10-26T14:55:14.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-30T14:45:02.000Z", "max_forks_repo_path": "test_mlfv.f90", "max_forks_repo_name": "emammendes/Fortran-Code---Mittag-Leffler-Function", "max_forks_repo_head_hexsha": "911ea9253d8367b19f94b026a457ff35a724d34c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.5862884161, "max_line_length": 128, "alphanum_fraction": 0.3871603464, "num_tokens": 4630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951698485603, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.788531515022772}} {"text": "! Created by EverLookNeverSee@GitHub on 6/7/20\n! For more information see FCS/img/Exercise_09_a.png\n\nprogram main\n implicit none\n ! declaring and initializing variables\n integer :: i, n\n real :: norm, tmp, sum_of_elements = 0.0\n real, allocatable, dimension(:) :: A\n print *, \"please enter number of elements in the vector:\"\n read *, n\n allocate(A(n))\n read *, A\n ! sum of all squared elements in the vector\n do i = 1, n\n tmp = (abs(A(i))) ** 2\n sum_of_elements = sum_of_elements + tmp\n end do\n ! square root of sum\n norm = sqrt(sum_of_elements)\n ! printing results\n print *, \"norm=\", norm\nend program main", "meta": {"hexsha": "f5068e7c3793004c570455f5ab87bbc13ebd6912", "size": 668, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical methods/Exercise_09_a.f90", "max_stars_repo_name": "EverLookNeverSee/FCS", "max_stars_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-14T10:30:25.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-17T13:03:15.000Z", "max_issues_repo_path": "src/numerical methods/Exercise_09_a.f90", "max_issues_repo_name": "EverLookNeverSee/FCS", "max_issues_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-06-06T13:54:45.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-25T20:32:23.000Z", "max_forks_repo_path": "src/numerical methods/Exercise_09_a.f90", "max_forks_repo_name": "EverLookNeverSee/FCS", "max_forks_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-08T12:57:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T12:57:46.000Z", "avg_line_length": 29.0434782609, "max_line_length": 61, "alphanum_fraction": 0.6392215569, "num_tokens": 187, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951698485602, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.7885315003488677}} {"text": "!> \nmodule MathConstants\n use PrecisionMod, only: MK, SP\n implicit none\n real(MK), parameter :: eps = 2.220446049250313e-16_MK\n ! Pi related\n real(MK), parameter :: pi = 3.141592653589793238462643383279502884197169399375105820974944_MK\n real(MK), parameter :: pi_half = 1.570796326794896619231321691639751442098584699687552910487472_MK\n real(MK), parameter :: twopi = 6.283185307179586476925286766559005768394338798750211641949889_MK\n real(MK), parameter :: fourpi = 12.56637061435917295385057353311801153678867759750042328389977_MK\n real(MK), parameter :: twopi_inv = 0.159154943091895335768883763372514362034459645740456448747667_MK\n real(MK), parameter :: fourpi_inv = 0.079577471545947667884441881686257181017229822870228224373833_MK\n real(MK), parameter :: four_third_pi = 4.188790204786390984616857844372670512262892532500141094633259_MK\n real(MK), parameter :: rad2deg = 57.29577951308232087679815481410517033240547246656432154916024_MK\n real(MK), parameter :: deg2rad = 0.017453292519943295769236907684886127134428718885417254560971_MK\n ! NaN\n integer, parameter :: NaN=-999999\n real(MK), parameter :: rNaN=-999999._MK\n real(SP), parameter :: NaN_SP=-999999._SP\n\n interface is_nan\n module procedure iis_nan, ris_nan\n end interface\ncontains\n logical function iis_nan(x)\n integer,intent(in) ::x\n iis_nan=(x==-NaN)\n end function\n \n logical function ris_nan(x)\n use PrecisionMod, only:PRECISION_EPS\n real(MK),intent(in) ::x\n ris_nan=abs(x-rNaN)0.0) viol = 1\nEND SUBROUTINE \tMOP_C4_Tanaka\n\n\nEND MODULE ProblemBank\n", "meta": {"hexsha": "0ba1926585105d749d6dc500332d35ae37688383", "size": 3421, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ProblemBank.f90", "max_stars_repo_name": "ynaranjani/MOPSO_FORTRAN", "max_stars_repo_head_hexsha": "f11761eaf8140e6553820029d1293219a6b0a220", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-05-17T23:22:47.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-26T06:29:48.000Z", "max_issues_repo_path": "ProblemBank.f90", "max_issues_repo_name": "ynaranjani/MOPSO_FORTRAN", "max_issues_repo_head_hexsha": "f11761eaf8140e6553820029d1293219a6b0a220", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ProblemBank.f90", "max_forks_repo_name": "ynaranjani/MOPSO_FORTRAN", "max_forks_repo_head_hexsha": "f11761eaf8140e6553820029d1293219a6b0a220", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-18T11:45:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-18T11:45:41.000Z", "avg_line_length": 22.5065789474, "max_line_length": 80, "alphanum_fraction": 0.5545162233, "num_tokens": 1665, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.7882522527057088}} {"text": " PROGRAM xqrdcmp\r\nC driver for routine qrdcmp\r\n INTEGER NP\r\n PARAMETER(NP=20)\r\n INTEGER i,j,k,l,m,n\r\n REAL con,a(NP,NP),c(NP),d(NP),q(NP,NP),qt(NP,NP),r(NP,NP),\r\n * x(NP,NP)\r\n CHARACTER txt*3\r\n LOGICAL sing\r\n open(7,file='MATRX1.DAT',status='old')\r\n read(7,*)\r\n10 read(7,*)\r\n read(7,*) n,m\r\n read(7,*)\r\n read(7,*) ((a(k,l), l=1,n), k=1,n)\r\n read(7,*)\r\n read(7,*) ((x(k,l), k=1,n), l=1,m)\r\nC print out a-matrix for comparison with product of Q and R\r\nC decomposition matrices.\r\n write(*,*) 'Original matrix:'\r\n do 11 k=1,n\r\n write(*,'(1x,6f12.6)') (a(k,l), l=1,n)\r\n11 continue\r\nC perform the decomposition\r\n call qrdcmp(a,n,NP,c,d,sing)\r\n if (sing) write(*,*) 'Singularity in QR decomposition.'\r\nC find the Q and R matrices\r\n do 13 k=1,n\r\n do 12 l=1,n\r\n if (l.gt.k) then\r\n r(k,l)=a(k,l)\r\n q(k,l)=0.0\r\n else if (l.lt.k) then\r\n r(k,l)=0.0\r\n q(k,l)=0.0\r\n else\r\n r(k,l)=d(k)\r\n q(k,l)=1.0\r\n endif\r\n12 continue\r\n13 continue\r\n do 21 i=n-1,1,-1\r\n con=0.0\r\n do 14 k=i,n\r\n con=con+a(k,i)**2\r\n14 continue\r\n con=con/2.0\r\n do 17 k=i,n\r\n do 16 l=i,n\r\n qt(k,l)=0.0\r\n do 15 j=i,n\r\n qt(k,l)=qt(k,l)+q(j,l)*a(k,i)*a(j,i)/con\r\n15 continue\r\n16 continue\r\n17 continue\r\n do 19 k=i,n\r\n do 18 l=i,n\r\n q(k,l)=q(k,l)-qt(k,l)\r\n18 continue\r\n19 continue\r\n21 continue\r\nC compute product of Q and R matrices for comparison with original matrix.\r\n do 24 k=1,n\r\n do 23 l=1,n\r\n x(k,l)=0.0\r\n do 22 j=1,n\r\n x(k,l)=x(k,l)+q(k,j)*r(j,l)\r\n22 continue\r\n23 continue\r\n24 continue\r\n write(*,*) 'Product of Q and R matrices:'\r\n do 25 k=1,n\r\n write(*,'(1x,6f12.6)') (x(k,l), l=1,n)\r\n25 continue\r\n write(*,*) 'Q matrix of the decomposition:'\r\n do 26 k=1,n\r\n write(*,'(1x,6f12.6)') (q(k,l), l=1,n)\r\n26 continue\r\n write(*,*) 'R matrix of the decomposition:'\r\n do 27 k=1,n\r\n write(*,'(1x,6f12.6)') (r(k,l), l=1,n)\r\n27 continue\r\n write(*,*) '***********************************'\r\n write(*,*) 'Press RETURN for next problem:'\r\n read(*,*)\r\n read(7,'(a3)') txt\r\n if (txt.ne.'END') goto 10\r\n close(7)\r\n END\r\n", "meta": {"hexsha": "fb26331d564ac0bf35e5fd37d5fdca7bab3569b2", "size": 2514, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xqrdcmp.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xqrdcmp.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xqrdcmp.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.9333333333, "max_line_length": 79, "alphanum_fraction": 0.4451073986, "num_tokens": 856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242074, "lm_q2_score": 0.8499711775577735, "lm_q1q2_score": 0.7882320673057381}} {"text": "integer function PlmIndex(l,m)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will return the index corresponding \n!\tto a given l and m in the arrays of Legendre Polynomials\n!\tgenerated by routines such as PlmBar and PlmSchmidt.\n!\n!\tCalling Parameters:\n!\t\tl\tSpherical harmonic angular degree.\n!\t\tm\tSpherical harmonic angular order.\n!\n!\tDependencies:\tNone\n!\n!\tWritten by Mark Wieczorek (May 2004)\n!\n!\tCopyright (c) 2005, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\tinteger, intent(in)\t:: l, m\n\t\n\tif (l < 0) then\n\t\tprint*, \"Error --- PlmIndex\"\n\t\tprint*, \"L must be greater of equal to 0.\"\n\t\tprint*, \"L = \", l\n\t\tprint*, \"M = \", m\n\t\tstop\n\telseif (m < 0 .or. m > l) then\n\t\tprint*, \"Error --- PlmIndex\"\n\t\tprint*, \"M must be greater than or equal to zero and less than or equal to L.\"\n\t\tprint*, \"L = \", l\n\t\tprint*, \"M = \", m\n\t\tstop\n\tendif\n\t\n\tPlmIndex = l*(l+1)/2+m+1\n\t\nend function PlmIndex\n\n", "meta": {"hexsha": "6c8b5de995d66c73acb69669362406f13c737235", "size": 1007, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/PlmIndex.f95", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "spherical_splines/SHTOOLS/src/PlmIndex.f95", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "spherical_splines/SHTOOLS/src/PlmIndex.f95", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 24.5609756098, "max_line_length": 80, "alphanum_fraction": 0.5700099305, "num_tokens": 302, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242073, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.7882320637813891}} {"text": "** Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.\n** See https://llvm.org/LICENSE.txt for license information.\n** SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n\n* Exponentiation (** operator) to real, double, or complex powers.\n\n\tprogram p\n\timplicit complex (c), real*8 (d)\n\n\tinteger rslts(18), expect(18)\n\n\tinteger ctoi\n\tctoi(c) = real(c) + aimag(c)\n\n\tdata x2 / 2.0/, d2 / 2.0d0/, i2 / 2 /\n\tdata c2, c23, c11, c12/ (2, 0), (2, 3), (1, 1), (1, 2) /\n\nc --- tests 1 - 6: exponentiation to real power:\n\n\trslts(1) = 2.1 ** 2.0\n\trslts(2) = 2.1 ** x2\n\trslts(3) = (3 ** x2) * 100.001\n\trslts(4) = (i2 + 1) ** 3.01\n\trslts(5) = i2 ** (x2 + 1) + .01\n\trslts(6) = x2 ** 0.0 * 100\n\nc --- tests 7 - 12: exponentiation to double prec. power:\n\n\trslts(7) = 2.1d0 ** 2.0d0\n\trslts(8) = 2.1d0 ** x2\n\trslts(9) = (3 ** d2) * 100.001\n\trslts(10) = (x2 + 1) ** 3.01d0\n\trslts(11) = i2 ** (d2 + 1) + .01\n\trslts(12) = d2 ** 0.0 * 100\n\nc --- tests 13 - 18: exponentiation to complex power:\n\n\trslts(13) = ctoi( (2.1, 0.0) ** (2.0, 0.0) )\n\trslts(14) = ctoi( (2.1, 0.0) ** c2)\n\trslts(15) = ctoi( c23 ** x2 + .001 )\n\trslts(16) = c23 ** c11 + 10\n\trslts(17) = ctoi( 10 ** c12 )\n\trslts(18) = ctoi(x2 ** (-1.0, 2.0) * 10)\n\nc --- check results:\n\n\tcall check(rslts, expect, 18)\n\n\tdata expect / 4, 4, 900, 27, 8, 100,\n + 4, 4, 900, 27, 8, 100,\n + 4, 4, 7, 9, -11, 5 /\n\n\tend\n", "meta": {"hexsha": "d0c2343ae123cb2ceed3bdce7185f4ace61cf0bd", "size": 1421, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "test/f90_correct/src/gg10.f", "max_stars_repo_name": "abrahamtovarmob/flang", "max_stars_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 716, "max_stars_repo_stars_event_min_datetime": "2017-05-17T17:58:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T11:20:58.000Z", "max_issues_repo_path": "test/f90_correct/src/gg10.f", "max_issues_repo_name": "abrahamtovarmob/flang", "max_issues_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 794, "max_issues_repo_issues_event_min_datetime": "2017-05-18T19:27:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:22:11.000Z", "max_forks_repo_path": "test/f90_correct/src/gg10.f", "max_forks_repo_name": "abrahamtovarmob/flang", "max_forks_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 157, "max_forks_repo_forks_event_min_datetime": "2017-05-17T18:50:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:06:45.000Z", "avg_line_length": 26.3148148148, "max_line_length": 80, "alphanum_fraction": 0.5432793807, "num_tokens": 664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552538, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.7881949227280809}} {"text": "\nsubroutine sphbes(n,x,sj,sjp)\n ! Calculates the spherical bessel function $j_l(x)$ and its first derivative $j'_l(x)$ \n ! at the point $x\\le 0$, for l=0,1,...n \n implicit none\n integer, intent(in) :: n ! Maximum l to be calculated\n real(8), intent(in) :: x ! The argument at which the bessel functions are calculated\n real(8), intent(out) :: sj(*) ! values of spherical bessel function\n real(8), intent(out) :: sjp(*)! values of first derivative of the spherical bessel function\n !\n integer(4) :: l\n real(8) :: factor ! Multiplying factor between the spherical bessel func and the regular bessel func of half integer order\n real(8) :: rj(n+1) ! Array containing the regular bessel function of order i-1/2\n real(8) :: rjp(n+1)! Array containing the first derivative of the regular bessel function of order i-1/2\n real(8), parameter :: rtpio2 = 1.25331413731550025120788d+0\n external bessj\n intrinsic sqrt \n\n if(n.lt.0.or.x.lt.0.)then\n write(6,*) \"ERROR in sphbes:bad arguments\"\n write(6,*)' input: x = ',x\n write(6,*)' input: n = ',n\n stop 'bad arguments in sphbes'\n endif\n \n if(x.gt.0.0d0)then\n call bessj(x,n,rj,rjp)\n \n factor=rtpio2/sqrt(x)\n do l=1,n+1\n sj(l)=factor*rj(l)\n sjp(l)=factor*rjp(l)-sj(l)/(2.0d0*x)\n enddo\n else\n do l=1,n+1\n sj(l)=0.0d0\n sjp(l)=0.0d0\n enddo\n sj(1)=1.0d0\n sjp(2)=1.0d0/3.0d0 \n endif\nend subroutine sphbes\n\nsubroutine bessj(x,nl,rj,rjp)\n !Returns the regular Bessel functions of first kind\n !$\\texttt{rj(l)}=J_{l-\\frac{1}{2}}$ and their derivatives\n !$\\texttt{rjp(l)}=J'_{l-\\frac{1}{2}}$, for positive \\texttt{x} and for\n !$1\\le l \\le nl+1$, using Steed's method.\n implicit none\n real(8), intent(in) :: x\n integer, intent(in) :: nl\n real(8), intent(out) :: rj(*) \n real(8), intent(out) :: rjp(*) \n ! \n integer :: i, isign, l \n real(8) :: xnu, b, c, d, del, f, fact, gam, h, p, q, rjl, rjl1, rjmu, rjp1, rjpl, rjtemp, w, xi, xi2, xmu, xmu2\n integer, parameter :: maxit=10000\n real(8), parameter :: eps=1.e-16\n real(8), parameter :: fpmin=1.e-30\n real(8), parameter :: pi=3.141592653589793d+0\n ! Original subroutine: bessjy.for (c) copr. 1986-92 numerical recipes software &124i..\n if(x.le.0..or.nl.lt.0) stop 'bad arguments in bessj'\n xnu=dble(nl)+0.5d0\n xmu=0.5d0\n xmu2=xmu*xmu\n xi=1.d0/x\n xi2=2.d0*xi\n ! The Wronskian\n w=xi2/pi\n ! Evaluate the continued fraction expansion for J'_(nl-1/2)/J_(nl-1/2)\n ! by the modified Lentz's method. isign keeps track of sign changes in\n ! the denominator\n isign=1\n h=xnu*xi\n if(h.lt.fpmin)h=fpmin\n b=xi2*xnu\n d=0.d0\n c=h\n do i=1,maxit\n b=b+xi2\n d=b-d\n if(abs(d).lt.fpmin) d=fpmin\n c=b-1.d0/c\n if(abs(c).lt.fpmin) c=fpmin\n d=1.d0/d\n del=c*d\n h=del*h\n if(d.lt.0.d0) isign=-isign\n if(abs(del-1.d0).lt.eps) goto 1\n enddo\n!11 continue\n stop 'x too large in bessjy; try asymptotic expansion'\n1 continue\n ! Initialize J and J' for downward recurrence\n rjl=isign*fpmin\n rjpl=h*rjl\n ! Store values for later rescaling \n rjl1=rjl\n rjp1=rjpl\n ! Downward recurrence (unnormalized)\n fact=xnu*xi\n do l=nl,0,-1\n rjtemp=fact*rjl+rjpl\n fact=fact-xi\n rjpl=fact*rjtemp-rjl\n rjl=rjtemp\n enddo\n if(rjl.eq.0.d0)rjl=eps\n f=rjpl/rjl\n ! Equation 6.7.3 Numerical Recipies in Fortran\n p=-.5d0*xi\n q=1.d0\n ! Equation 6.7.6 Numerical Recipies in Fortran\n gam=(p-f)/q\n ! Equation 6.7.7 Numerical Recipies in Fortran\n rjmu=sqrt(w/((p-f)*gam+q))\n rjmu=sign(rjmu,rjl)\n ! Scale original J and J'\n fact=rjmu/rjl\n rj(nl+1)=rjl1*fact\n rjp(nl+1)=rjp1*fact\n fact=xnu*xi\n ! Downward recurence\n do l=nl,1,-1\n rj(l)=fact*rj(l+1)+rjp(l+1)\n fact=fact-xi\n rjp(l)=fact*rj(l)-rj(l+1)\n enddo ! l\nend subroutine bessj\n\n\nsubroutine ylm(y,v,lmax)\n ! This subroutine calculates spherical harmonics up to l=lmax for a\n ! given vector in cartesian coordinates\n !\n ! The spherical harmonics (Condon and Shortley convention)\n ! $Y_{0,0},Y_{1,-1},Y_{1,0},Y_{1,1},Y_{2,-2} ...Y_{LMAX,LMAX}$\n ! for vector V (given in Cartesian coordinates)\n ! are calculated. In the Condon Shortley convention the\n ! spherical harmonics are defined as\n !\n !\\begin{equation} \n ! Y_{l,m}=(-1)^m \\sqrt{\\frac{1}{2\\pi}} P_l^m(cos(\\theta))e^{im\\phi}\n !\\end{equation}\n !\n !\\noindent\n !where $P_l^m(cos(\\theta))$ is the normalized Associated Legendre\n ! function. Thus,\n !\\begin{equation} \n ! Y_{l,-m}=(-1)^m Y^*_{l,m}\n !\\end{equation}\n !\n !The output is writen to the vector Y(:) such that\n ! Y(k)$=Y_{l,m}$ with $k=l^2+l+m+1$, thus,\n ! Y(1)$=Y_{0,0}$, Y(2)$=Y_{1,-1}$, Y(3)$=Y_{1,0}$, Y(4)$=Y_{1,1}$...\n !Y(lmax*lmax+1)$=Y_{lmax,-lmax}... $Y((lmax+1)*(lmax+1))$=Y_{lmax,lmax}$\n !\n ! The basic algorithm used to calculate the spherical\n ! harmonics for vector V is as follows:\n !\n !\\begin{subequations}\n !\\begin{align}\n ! Y_{0,0}=&\\sqrt{\\frac{1}{4\\pi}}\\\\\n ! Y_{1,0}=&\\sqrt{\\frac{3}{4\\pi}}cos(\\theta)\\\\\n ! Y_{1,1}=&-\\sqrt{\\frac{3}{8\\pi}}sin(\\theta)e^{i\\phi}\\\\\n ! Y_{1,-1}=&-Y_{1,1}\\\\\n ! Y_{l,l}=&-\\sqrt{\\frac{2l+1}{2l}}sin(\\theta)e^{i\\phi}Y_{l-1,l-1}\\\\\n ! Y_{l,m}=&\\sqrt{\\frac{(2l-1)(2l+1)}{(l-m)(l+m)}}%\n !cos(\\theta)Y_{l-1,m}-\\sqrt{\\frac{(l-1+m)(l-1-m)(2l+1)}{(2l-3)(l-m)(l+m)}}%\n !Y_{l-2,m}\n !\\end{align}\n !\\end{subequations}\n !\n implicit none\n integer,intent(in):: lmax ! maximum l for which the spherical harmonics are calculated\n real(8),intent(in) :: v(3) ! vector (cartesian coordinates) for which the spherical harmonics are calculated\n complex*16,intent(out) :: y((lmax+1)*(lmax+1)) ! the values of the spherical harmonics dimension (lmax+1)^2\n !\n integer :: i2l, i4l2, index, index2, l, m, msign\n real(8) :: a, b, c, ab, abc, abmax, abcmax\n real(8) :: d4ll1c, d2l13, pi\n real(8) :: costh, sinth, cosph, sinph\n real(8) :: temp1, temp2, temp3\n real(8) :: yllr, yll1r, yl1l1r, ylmr\n real(8) :: ylli, yll1i, yl1l1i, ylmi\n pi = (4.0d+0)*atan(1.0d+0)\n ! y(0,0)\n yllr = 1.0d+0/sqrt(4.0d+0*pi)\n ylli = 0.0d+0\n y(1) = cmplx(yllr,ylli,8)\n ! continue only if spherical harmonics for (l .gt. 0) are desired\n if (lmax .le. 0) return \n ! calculate sin(phi), cos(phi), sin(theta), cos(theta)\n ! theta, phi ... polar angles of vector v\n abmax = max(abs(v(1)),abs(v(2)))\n if (abmax .gt. 0.0d+0) then\n a = v(1)/abmax\n b = v(2)/abmax\n ab = sqrt(a*a+b*b)\n cosph = a/ab\n sinph = b/ab\n else\n cosph = 1.0d+0\n sinph = 0.0d+0\n endif\n abcmax = max(abmax,abs(v(3)))\n if (abcmax .gt. 0.0d+0) then\n a = v(1)/abcmax\n b = v(2)/abcmax\n c = v(3)/abcmax\n ab = a*a + b*b\n abc = sqrt(ab + c*c)\n costh = c/abc\n sinth = sqrt(ab)/abc\n else\n costh = 1.0d+0\n sinth = 0.0d+0\n endif\n ! y(1,0)\n y(3) = cmplx(sqrt(3.0d+0)*yllr*costh,0.0d+0,8)\n ! y(1,1) ( = -conjg(y(1,-1)))\n temp1 = -sqrt(1.5d+0)*yllr*sinth\n y(4) = cmplx(temp1*cosph,temp1*sinph,8)\n y(2) = -conjg(y(4))\n !\n do l = 2, lmax\n index = l*l+1\n index2 = index + 2*l\n msign = 1 - 2*mod(l,2)\n ! yll = y(l,l) = f(y(l-1,l-1)) ... formula 1\n yl1l1r = dble(y(index-1))\n yl1l1i = aimag(y(index-1))\n temp1 = -sqrt(dble(2*l+1)/dble(2*l))*sinth\n yllr = temp1*(cosph*yl1l1r - sinph*yl1l1i)\n ylli = temp1*(cosph*yl1l1i + sinph*yl1l1r)\n y(index2) = cmplx(yllr,ylli,8)\n y(index) = msign*conjg(y(index2))\n index2 = index2 - 1\n index = index + 1\n ! yll1 = y(l,l-1) = f(y(l-1,l-1)) ... formula 2\n ! (the coefficient for y(l-2,l-1) in formula 2 is zero)\n temp2 = sqrt(dble(2*l+1))*costh\n yll1r = temp2*yl1l1r\n yll1i = temp2*yl1l1i\n y(index2) = cmplx(yll1r,yll1i,8)\n y(index) = -msign*conjg(y(index2))\n index2 = index2 - 1\n index = index + 1\n !\n i4l2 = index2 - 4*l + 2\n i2l = index2 - 2*l\n d4ll1c = costh*sqrt(dble(4*l*l-1))\n d2l13 = -sqrt(dble(2*l+1)/dble(2*l-3))\n do m = l - 2, 0, -1\n ! ylm = y(l,m) = f(y(l-2,m),y(l-1,m)) ... formula 2\n temp1 = 1.0d+0/sqrt(dble((l+m)*(l-m)))\n temp2 = d4ll1c*temp1\n temp3 = d2l13*sqrt(dble((l+m-1)*(l-m-1)))*temp1\n ylmr = temp2*dble(y(i2l)) + temp3*dble(y(i4l2))\n ylmi = temp2*aimag(y(i2l)) + temp3*aimag(y(i4l2))\n y(index2) = cmplx(ylmr,ylmi,8)\n y(index) = msign*conjg(y(index2))\n !\n msign = -msign\n index2 = index2 - 1\n index = index + 1\n i4l2 = i4l2 - 1\n i2l = i2l - 1\n enddo ! m\n enddo ! l\nend subroutine ylm\n", "meta": {"hexsha": "efc5063e8e81ff8b8d521100cb75e64e9eaa1755", "size": 8755, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sphbes.f90", "max_stars_repo_name": "kunyuan/PyGW", "max_stars_repo_head_hexsha": "7b32065586f7d7cc221d051b5254397fdf0a3076", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-07-06T01:56:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-13T13:07:06.000Z", "max_issues_repo_path": "sphbes.f90", "max_issues_repo_name": "kunyuan/PyGW", "max_issues_repo_head_hexsha": "7b32065586f7d7cc221d051b5254397fdf0a3076", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sphbes.f90", "max_forks_repo_name": "kunyuan/PyGW", "max_forks_repo_head_hexsha": "7b32065586f7d7cc221d051b5254397fdf0a3076", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-06T01:56:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-06T01:56:59.000Z", "avg_line_length": 32.1875, "max_line_length": 125, "alphanum_fraction": 0.5709880069, "num_tokens": 3662, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391664210672, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7881949156808599}} {"text": "\n PROGRAM TEST\n USE FMZM\n\n! FM_FIND_MIN is a multiple precision function minimization routine that uses Brent's method.\n\n! The function to be minimized or maximized is F(X,NF).\n! X is the argument to the function.\n! NF is the function number in case extrema to several functions are needed.\n\n IMPLICIT NONE\n CHARACTER(80) :: ST1,ST2\n\n! declare the multiple precision variables.\n\n TYPE (FM), SAVE :: A, B, TOL, XVAL, FVAL\n TYPE (FM), EXTERNAL :: F\n\n! Set the FM precision to 50 significant digits (plus a few more \"guard digits\")\n\n CALL FM_SET(50)\n\n! Find a minimum of the first function, X**3 - 9*X + 17.\n! A, B are two endpoints of an interval in which the search takes place.\n\n A = 1\n B = 2\n\n! TOL is the error tolerance. For most functions, the best accuracy we can obtain\n! corresponds to about half the digits being used for the arithmetic.\n! EPSILON(A) gives the relative accuracy of full precision, so SQRT(EPSILON(A))\n! gives the relative accuracy of half precision.\n\n TOL = SQRT(EPSILON(A))\n\n! For this call no trace output will be done (KPRT = 0).\n! KW = 6 is used, so any error messages will go to the screen.\n\n WRITE (*,*) ' '\n WRITE (*,*) ' '\n WRITE (*,*) ' Case 1. Call FM_FIND_MIN to find a relative minimum between 1 and 2'\n WRITE (*,*) ' for f(x) = X**3 - 9*X + 17.'\n WRITE (*,*) ' Use KPRT = 0, so no output will be done in the routine, then'\n WRITE (*,*) ' write the results from the main program.'\n\n CALL FM_FIND_MIN(1,A,B,TOL,XVAL,FVAL,F,1,0,6)\n\n! Write the result, using F32.30 format.\n\n CALL FM_FORM('F32.30',XVAL,ST1)\n CALL FM_FORM('F32.30',FVAL,ST2)\n WRITE (*,\"(/' A minimum for function 1 is'/' x = ',A/' f(x) = ',A)\") &\n TRIM(ST1),TRIM(ST2)\n\n! Find a maximum of the first function, X**3 - 9*X + 17.\n\n! This time we use FM_FIND_MIN's built-in trace (KPRT = 1) to print the final\n! approximation to the root. The output will appear on more than one line, to\n! allow for the possibility that precision could be hundreds or thousands of digits,\n! so the number might not fit on one line.\n\n WRITE (*,*) ' '\n WRITE (*,*) ' '\n WRITE (*,*) ' Case 2. Find a relative maximum between -5 and 1.'\n WRITE (*,*) ' Use KPRT = 1, so FM_FIND_MIN will print the results.'\n\n CALL FM_FIND_MIN(2,-TO_FM('5.0D0'),TO_FM('1.0D0'),TOL,XVAL,FVAL,F,1,1,6)\n\n! Find a maximum of the first function, X**3 - 9*X + 17.\n\n! See what happens when the maximum value is at an endpoint of the search interval.\n! The algorithm still finds a relative maximum in the interior of the interval,\n! not the absolute maximum at x=5.\n\n WRITE (*,*) ' '\n WRITE (*,*) ' '\n WRITE (*,*) ' Case 3. Find a relative maximum between -5 and 5.'\n WRITE (*,*) ' Use KPRT = 2, so FM_FIND_MIN will print all iterations,'\n WRITE (*,*) ' as well as the final results.'\n\n CALL FM_FIND_MIN(2,-TO_FM('5.0D0'),TO_FM('5.0D0'),TOL,XVAL,FVAL,F,1,2,6)\n\n! Find a minimum of the second function, gamma(x).\n\n WRITE (*,*) ' '\n WRITE (*,*) ' '\n WRITE (*,*) ' Case 4. The gamma function has one minimum for positive x.'\n WRITE (*,*) ' Find it, printing all iterations.'\n WRITE (*,*) ' Fortran did not provide gamma(x) before the Fortran 2008 standard, '\n WRITE (*,*) ' so this case was not included in the original fmin.f95.'\n\n CALL FM_FIND_MIN(1,TO_FM('0.1D0'),TO_FM('3.0D0'),TOL,XVAL,FVAL,F,2,2,6)\n\n\n WRITE (*,*) ' '\n\n END PROGRAM TEST\n\n\n FUNCTION F(X,NF) RESULT (RETURN_VALUE)\n USE FMZM\n\n! X is the argument to the function.\n! NF is the function number.\n\n IMPLICIT NONE\n INTEGER :: NF\n TYPE (FM) :: RETURN_VALUE,X\n\n IF (NF == 1) THEN\n RETURN_VALUE = X**3 - 9*X + 17\n ELSE IF (NF == 2) THEN\n RETURN_VALUE = GAMMA(X)\n ELSE\n RETURN_VALUE = 3*X**2 + X - 2\n ENDIF\n\n END FUNCTION F\n", "meta": {"hexsha": "b6819078a08e8eb6220cdfd35eb1a12d2a073cde", "size": 4302, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Libraries/FM/FMsamples/fminFMv2.f95", "max_stars_repo_name": "andreypudov/projecteuler", "max_stars_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2022-01-30T20:37:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T21:03:21.000Z", "max_issues_repo_path": "Libraries/FM/FMsamples/fminFMv2.f95", "max_issues_repo_name": "andreypudov/projecteuler", "max_issues_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Libraries/FM/FMsamples/fminFMv2.f95", "max_forks_repo_name": "andreypudov/projecteuler", "max_forks_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.1512605042, "max_line_length": 97, "alphanum_fraction": 0.5660158066, "num_tokens": 1209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039739, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7881949104414517}} {"text": "* Home work #2\r\n* Question (1)\r\n* Write a Fortran program to calculate and find\r\n* error% between exact derivatives and numerical\r\n* derivatives of the following function using\r\n* all methods (forward , backward , 3-point method,\r\n* 5-point method)\r\n\r\n* (ii)f(x)=x^6-cos(x) at x=2\r\n\r\n write(*,*)'f(x)=X^6-cos(x)'\r\n write(*,*)'exact (df(x)/dx)= 6*X^5+sin(x)'\r\n write(*,*)'Enter the value of X ,to calculate df(x)/dx'\r\n Read(*,*)X\r\n10 write(*,*)'Enter the value of H'\r\n Read(*,*)h\r\n If(H.LE.0)stop\r\n exact= 6*x**5+sin(x)\r\n fx=x**6-cos(x)\r\n fx1h_forward=(x+h)**6-cos(x+h)\r\n fx2h_forward=(x+2*h)**6-cos(x+2*h)\r\n fx1h_backward=(x-h)**6-cos(x-h)\r\n fx2h_backward=(x-2*h)**6-cos(x-2*h)\r\n\r\n* Forward Difference Deivative\r\n fbrime_forward=(fx1h_forward-fx)/h\r\n\r\n* Backward Difference Deivative\r\n fbrime_backward=(fx-fx1h_backward)/h\r\n\r\n* 3-point Difference Deivative\r\n fbrime_3_point=(fx1h_forward-fx1h_backward)/(2*h)\r\n\r\n* 5-point Difference Deivative\r\n fbrime_5_point_1= fx2h_backward -8*fx1h_backward\r\n fbrime_5_point_2=8*fx1h_forward-fx2h_forward\r\n fbrime_5_point=(fbrime_5_point_1 + fbrime_5_point_2)/(12*h)\r\n\r\n Error_forward=abs(exact-fbrime_forward)\r\n Error_backward=abs(exact-fbrime_backward)\r\n Error_3_point=abs(exact-fbrime_3_point)\r\n Error_5_point=abs(exact-fbrime_5_point)\r\n20 format(4f 12.6)\r\n write(*,*)' H Error fbrime exact'\r\n write(*,20)H,Error_forward,fbrime_forward,exact\r\n write(*,20)H,Error_backward,fbrime_backward,exact\r\n write(*,20)H,Error_3_point,fbrime_3_point,exact\r\n write(*,20)H,Error_5_point,fbrime_5_point,exact\r\n Go to 10\r\n* Stop\r\n End\r\n", "meta": {"hexsha": "108ba576eb540a18a282679ea8a3cc7dadca1861", "size": 1875, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "HW(2)/Problem(1)/Problem(1)(ii)/Problem-1-ii-.f", "max_stars_repo_name": "Melhabbash/Computational-Physics-", "max_stars_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW(2)/Problem(1)/Problem(1)(ii)/Problem-1-ii-.f", "max_issues_repo_name": "Melhabbash/Computational-Physics-", "max_issues_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW(2)/Problem(1)/Problem(1)(ii)/Problem-1-ii-.f", "max_forks_repo_name": "Melhabbash/Computational-Physics-", "max_forks_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.0576923077, "max_line_length": 68, "alphanum_fraction": 0.5904, "num_tokens": 599, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813526452772, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7881702317052719}} {"text": "!============================================================================\n! peuc.f90 Purser, October 2005\n! Package for handy vector and matrix operations in Euclidean geometry.\n! This package is primarily intended for 3D operations and three of the\n! functions (Cross_product, Triple_product and Axial) do not possess simple\n! generalizations to a generic number N of dimensions. The others, while\n! admitting such N-dimensional generalizations, have not all been provided\n! with such generic forms here at the time of writing, though some of these \n! may be added at a future date.\n!\n! FUNCTION:\n! Normalized: Normalized version of given vector\n! Cross_product: Vector cross-product of the given 2 vectors\n! Outer_product: outer-product matrix of the given 2 vectors\n! Triple_product: Scalar triple product of given 3 vectors\n! Det: Determinant of given matrix\n! Axial: Convert axial-vector <--> 2-form (antisymmetric matrix)\n! Diag: Diagnl of given matrix, or diagonal matrix of given elements\n! Trace: Trace of given matrix\n! Identity: Identity 3*3 matrix, or identity n*n matrix for a given n\n! Sarea: Spherical area subtended by three vectors\n! Huarea: Spherical area subtended by right-angled spheical triangle\n! SUBROUTINE:\n! Gram: Right-handed orthogonal basis and rank, nrank. The first \n! nrank basis vectors span the column range of matrix given,\n! OR (\"plain\" version) simple unpivoted gram-schmidt of a\n! square matrix.\n!============================================================================\nmodule peuc\n!============================================================================\nuse kinds\nimplicit none\nprivate\npublic:: normalized,cross_product,outer_product,triple_product,det,axial, &\n diag,trace,identity,sarea,huarea,gram\n\ninterface normalized\n module procedure normalized_s,normalized_d\nend interface\ninterface cross_product\n module procedure cross_product_s,cross_product_d\nend interface\ninterface outer_product\n module procedure outer_product_s,outer_product_d\nend interface\ninterface triple_product\n module procedure triple_product_s,triple_product_d\nend interface\ninterface det\n module procedure det_s,det_d\nend interface\ninterface axial\n module procedure axial3_s,axial3_d,axial33_s,axial33_d\nend interface\ninterface diag\n module procedure diagn_s,diagn_d,diagnn_s,diagnn_d\nend interface\ninterface trace\n module procedure trace_s,trace_d\nend interface\ninterface identity\n module procedure identity_i,identity3_i\nend interface\ninterface huarea\n module procedure huarea_s,huarea_d\nend interface\ninterface sarea\n module procedure sarea_s,sarea_d\nend interface\ninterface gram\n module procedure gram_s,gram_d,plaingram_s,plaingram_d\nend interface\n\ncontains\n\n!=============================================================================\nfunction normalized_s(a)result(b)\n!=============================================================================\nreal(sp),dimension(:),intent(IN):: a\nreal(sp),dimension(size(a)) :: b\nreal(sp) :: s\ns=sqrt(dot_product(a,a)); if(s==0)then; b=0;else;b=a/s;endif\nend function normalized_s\n!=============================================================================\nfunction normalized_d(a)result(b)\n!=============================================================================\nreal(dp),dimension(:),intent(IN):: a\nreal(dp),dimension(size(a)) :: b\nreal(dp) :: s\ns=sqrt(dot_product(a,a)); if(s==0)then; b=0;else;b=a/s;endif\nend function normalized_d\n\n!=============================================================================\nfunction cross_product_s(a,b)\n!=============================================================================\nreal(sp),dimension(3) :: cross_product_s\nreal(sp),dimension(3),intent(in):: a,b\ncross_product_s(1)=a(2)*b(3)-a(3)*b(2)\ncross_product_s(2)=a(3)*b(1)-a(1)*b(3)\ncross_product_s(3)=a(1)*b(2)-a(2)*b(1)\nend function cross_product_s\n!=============================================================================\nfunction cross_product_d(a,b)result(cross_product)\n!=============================================================================\nreal(dp),dimension(3) :: cross_product\nreal(dp),dimension(3),intent(in):: a,b\ncross_product(1)=a(2)*b(3)-a(3)*b(2)\ncross_product(2)=a(3)*b(1)-a(1)*b(3)\ncross_product(3)=a(1)*b(2)-a(2)*b(1)\nend function cross_product_d\n\n!=============================================================================\nfunction outer_product_s(a,b)result(c)\n!=============================================================================\nreal(sp),dimension(:), intent(in ):: a\nreal(sp),dimension(:), intent(in ):: b\nreal(sp),DIMENSION(size(a),size(b)):: c\ninteger :: nb,i\nnb=size(b)\ndo i=1,nb; c(:,i)=a*b(i); enddo\nend function outer_product_s\n!=============================================================================\nfunction outer_product_d(a,b)result(c)\n!=============================================================================\nreal(dp),dimension(:), intent(in ):: a\nreal(dp),dimension(:), intent(in ):: b\nreal(dp),dimension(size(a),size(b)):: c\ninteger :: nb,i\nnb=size(b)\ndo i=1,nb; c(:,i)=a*b(i); enddo\nend function outer_product_d\n\n!=============================================================================\nfunction triple_product_s(a,b,c)result(tripleproduct)\n!=============================================================================\nreal(sp),dimension(3),intent(IN ):: a,b,c\nreal(sp) :: tripleproduct\ntripleproduct=dot_product( cross_product(a,b),c )\nend function triple_product_s\n!=============================================================================\nfunction triple_product_d(a,b,c)result(tripleproduct)\n!=============================================================================\nreal(dp),dimension(3),intent(IN ):: a,b,c\nreal(dp) :: tripleproduct\ntripleproduct=dot_product( cross_product(a,b),c )\nend function triple_product_d\n\n!=============================================================================\nfunction det_s(a)result(det)\n!=============================================================================\nreal(sp),dimension(:,:),intent(IN ) ::a\nreal(sp) :: det\nreal(sp),dimension(size(a,1),size(a,1)):: b\ninteger :: n,nrank\nn=size(a,1)\nif(n==3)then\n det=triple_product(a(:,1),a(:,2),a(:,3))\nelse\n call gram(a,b,nrank,det)\n if(nranknrank)exit\n ab(k:m,k:n)=matmul( transpose(a(:,k:m)),b(:,k:n) )\n ii =maxloc( abs( ab(k:m,k:n)) )+k-1\n val=maxval( abs( ab(k:m,k:n)) )\n if(val<=vcrit)then\n nrank=k-1\n exit\n endif\n i=ii(1)\n j=ii(2)\n tv=b(:,j)\n b(:,j)=-b(:,k)\n b(:,k)=tv\n tv=a(:,i)\n a(:,i)=-a(:,k)\n a(:,k)=tv\n w(k:n)=matmul( transpose(b(:,k:n)),tv )\n b(:,k)=matmul(b(:,k:n),w(k:n) )\n s=dot_product(b(:,k),b(:,k))\n s=sqrt(s)\n if(w(k)<0)s=-s\n det=det*s\n b(:,k)=b(:,k)/s\n do l=k,n\n do j=l+1,n\n s=dot_product(b(:,l),b(:,j))\n b(:,j)=normalized( b(:,j)-b(:,l)*s )\n enddo\n enddo\nenddo\nend subroutine gram_s\n \n!=============================================================================\nsubroutine gram_d(as,b,nrank,det)\n!=============================================================================\nreal(dp),dimension(:,:),intent(IN ) :: as\nreal(dp),dimension(:,:),intent(OUT) :: b\ninteger, intent(OUT) :: nrank\nreal(dp), intent(OUT) :: det\n!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \nreal(dp),parameter :: crit=1.e-9_dp\nreal(dp),dimension(size(as,1),size(as,2)):: a\nreal(dp),dimension(size(as,2),size(as,1)):: ab\nreal(dp),dimension(size(as,1)) :: tv,w\nreal(dp) :: val,s,vcrit\ninteger :: i,j,k,l,m,n\ninteger,dimension(2) :: ii\n!-----------------------------------------------------------------------------\nn=size(as,1)\nm=size(as,2)\nif(n/=size(b,1) .or. n/=size(b,2))stop 'In gram; incompatible dimensions'\na=as\nb=identity(n)\ndet=1\nval=maxval(abs(a))\nif(val==0)then\n nrank=0\n return\nendif\nvcrit=val*crit\nnrank=min(n,m)\ndo k=1,n\n if(k>nrank)exit\n ab(k:m,k:n)=matmul( transpose(a(:,k:m)),b(:,k:n) )\n ii =maxloc( abs( ab(k:m,k:n)) )+k-1\n val=maxval( abs( ab(k:m,k:n)) )\n if(val<=vcrit)then\n nrank=k-1\n exit\n endif\n i=ii(1)\n j=ii(2)\n tv=b(:,j)\n b(:,j)=-b(:,k)\n b(:,k)=tv\n tv=a(:,i)\n a(:,i)=-a(:,k)\n a(:,k)=tv\n w(k:n)=matmul( transpose(b(:,k:n)),tv )\n b(:,k)=matmul(b(:,k:n),w(k:n) )\n s=dot_product(b(:,k),b(:,k))\n s=sqrt(s)\n if(w(k)<0)s=-s\n det=det*s\n b(:,k)=b(:,k)/s\n do l=k,n\n do j=l+1,n\n s=dot_product(b(:,l),b(:,j))\n b(:,j)=normalized( b(:,j)-b(:,l)*s )\n enddo\n enddo\nenddo\nend subroutine gram_d\n \n!=============================================================================\nsubroutine plaingram_s(b,nrank)\n!=============================================================================\n! A \"plain\" (unpivoted) version of Gram-Schmidt, for square matrices only.\nreal(sp),dimension(:,:),intent(INOUT) :: b\ninteger, intent( OUT) :: nrank\n!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \nreal(sp),parameter :: crit=1.e-5_sp\nreal(sp) :: val,vcrit\ninteger :: j,k,n\n!-----------------------------------------------------------------------------\nn=size(b,1); if(n/=size(b,2))stop 'In gram; matrix needs to be square'\nval=maxval(abs(b))\nnrank=0\nif(val==0)then\n b=0\n return\nendif\nvcrit=val*crit\ndo k=1,n\n val=sqrt(dot_product(b(:,k),b(:,k)))\n if(val<=vcrit)then\n b(:,k:n)=0\n return\n endif\n b(:,k)=b(:,k)/val\n nrank=k\n do j=k+1,n\n b(:,j)=b(:,j)-b(:,k)*dot_product(b(:,k),b(:,j))\n enddo\nenddo\nend subroutine plaingram_s\n\n!=============================================================================\nsubroutine plaingram_d(b,nrank)\n!=============================================================================\n! A \"plain\" (unpivoted) version of Gram-Schmidt, for square matrices only.\nreal(dp),dimension(:,:),intent(INOUT) :: b\ninteger, intent( OUT) :: nrank\n!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \nreal(dp),parameter :: crit=1.e-9_dp\nreal(dp) :: val,vcrit\ninteger :: j,k,n\n!-----------------------------------------------------------------------------\nn=size(b,1); if(n/=size(b,2))stop 'In gram; matrix needs to be square'\nval=maxval(abs(b))\nnrank=0\nif(val==0)then\n b=0\n return\nendif\nvcrit=val*crit\ndo k=1,n\n val=sqrt(dot_product(b(:,k),b(:,k)))\n if(val<=vcrit)then\n b(:,k:n)=0\n return\n endif\n b(:,k)=b(:,k)/val\n nrank=k\n do j=k+1,n\n b(:,j)=b(:,j)-b(:,k)*dot_product(b(:,k),b(:,j))\n enddo\nenddo\nend subroutine plaingram_d\n\nend module peuc\n", "meta": {"hexsha": "c34d44a60692d43213ec469bc5ec3a40376e5558", "size": 21611, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "NEMS/src/ENS_Cpl/peuc.f", "max_stars_repo_name": "pvelissariou1/ADC-WW3-NWM-SCHISM-NEMS", "max_stars_repo_head_hexsha": "707ddcd84417211e3a7c92aa15d8cd8ddfa080ab", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NEMS/src/ENS_Cpl/peuc.f", "max_issues_repo_name": "pvelissariou1/ADC-WW3-NWM-SCHISM-NEMS", "max_issues_repo_head_hexsha": "707ddcd84417211e3a7c92aa15d8cd8ddfa080ab", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-31T15:49:26.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-04T14:17:45.000Z", "max_forks_repo_path": "NEMS/src/ENS_Cpl/peuc.f", "max_forks_repo_name": "pvelissariou1/ADC-WW3-NWM-SCHISM-NEMS", "max_forks_repo_head_hexsha": "707ddcd84417211e3a7c92aa15d8cd8ddfa080ab", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-01T09:29:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-01T09:29:46.000Z", "avg_line_length": 37.1323024055, "max_line_length": 79, "alphanum_fraction": 0.424089584, "num_tokens": 5483, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012747599251, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7881594704074638}} {"text": "module gaussian_model\ncontains\n subroutine gaussian(output, mu, sigma, k, seed)\n integer, intent(in) :: k, seed\n real(8), intent(in) :: mu, sigma\n real(8), intent(out) :: output(k)\n\n integer :: i, n\n real(8) :: r, theta\n real(8), dimension(:), allocatable :: temp\n integer(4), dimension(:), allocatable :: seed_arr\n\n ! get random seed array size and fill seed_arr with provided seed\n call random_seed(size = n)\n allocate(seed_arr(n))\n seed_arr = seed\n call random_seed(put = seed_arr)\n\n ! create 2k random numbers uniformly from [0,1]\n if(allocated(temp)) then\n deallocate(temp)\n end if\n allocate(temp(k*2))\n call random_number(temp)\n\n ! Use Box-Muller transfrom to create normally distributed variables\n do i = 1, k\n r = (-2.0 * log(temp(2*i-1)))**0.5\n theta = 2 * 3.1415926 * temp(2*i)\n output(i) = mu + sigma * r * sin(theta)\n end do\n end subroutine gaussian\nend module gaussian_model\n\nprogram main\n use gaussian_model\n implicit none\n\n integer, parameter :: k = 100\n integer :: seed = 9, i\n real(8) :: mu = 10.0, sigma = 2.0\n real(8) :: output(k)\n\n call gaussian(output, mu, sigma, k, seed)\n \n do i = 1, k\n write(*,*) output(i)\n end do\nend program main\n", "meta": {"hexsha": "b9054dca69f2f0a36bb1fd33575179e5790db033", "size": 1256, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/extensions/models/gaussian_f90/gaussian_model_simple.f90", "max_stars_repo_name": "shoshijak/abcpy", "max_stars_repo_head_hexsha": "ad12808782fa72c0428122fc659fd3ff22d3e854", "max_stars_repo_licenses": ["BSD-3-Clause-Clear"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/extensions/models/gaussian_f90/gaussian_model_simple.f90", "max_issues_repo_name": "shoshijak/abcpy", "max_issues_repo_head_hexsha": "ad12808782fa72c0428122fc659fd3ff22d3e854", "max_issues_repo_licenses": ["BSD-3-Clause-Clear"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/extensions/models/gaussian_f90/gaussian_model_simple.f90", "max_forks_repo_name": "shoshijak/abcpy", "max_forks_repo_head_hexsha": "ad12808782fa72c0428122fc659fd3ff22d3e854", "max_forks_repo_licenses": ["BSD-3-Clause-Clear"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.12, "max_line_length": 71, "alphanum_fraction": 0.6242038217, "num_tokens": 380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012701768145, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7881594646307272}} {"text": "module dlg\n\ncontains\n function dlg_pDeriv ( x, y, array, dir ) result ( dArray )\n implicit none\n \n real, dimension (:,:), allocatable :: dArray\n integer :: nX, nY, i, j\n integer, intent(IN) :: dir\n real, intent(IN) :: array (:,:), x(:), y(:)\n real :: dS\n\n nX = size ( array, 1 )\n nY = size ( array, 2 )\n\n allocate ( dArray ( nX, nY ) )\n dArray = 0.0\n \n if ( dir == 2 ) then\n \n do i=1,nX\n do j=1,nY\n\n if ( j > 1 .AND. j < nY ) then\n\n dS = ((y(j+1)-y(j)) + (y(j)-y(j-1))) / 2.0\n\n dArray(i,j) = 1.0 / ( 2.0 * dS ) * &\n ( array(i,j+1) - array(i,j-1) )\n\n elseif ( j == 1 ) then\n\n dS = ((y(j+1)-y(j)) + (y(j+2)-y(j+1))) / 2.0\n\n dArray(i,j) = 1.0 / ( 2.0 * dS ) * &\n ( &\n -3.0 * array(i,j) + 4.0 * array(i,j+1) &\n - array(i,j+2) )\n\n elseif ( j == nY ) then\n\n dS = ((y(j-1)-y(j-2)) + (y(j)-y(j-1))) / 2.0\n\n dArray(i,j) = 1.0 / ( 2.0 * dS ) * &\n ( &\n 3.0 * array(i,j) - 4.0 * array(i,j-1) &\n + array(i,j-2) )\n\n endif\n\n enddo\n enddo\n \n elseif ( dir == 1 ) then\n \n do i=1,nX\n do j=1,nY\n\n if ( i > 1 .AND. i < nX ) then\n\n dS = ((x(i+1)-x(i)) + (x(i)-x(i-1))) / 2.0\n\n dArray(i,j) = 1.0 / ( 2.0 * dS ) * &\n ( array(i+1,j) - array(i-1,j) )\n\n elseif ( i == 1 ) then\n\n dS = ((x(i+1)-x(i)) + (x(i+2)-x(i+1))) / 2.0\n\n dArray(i,j) = 1.0 / ( 2.0 * dS ) * &\n ( &\n -3.0 * array(i,j) + 4.0 * array(i+1,j) &\n - array(i+2,j) )\n\n elseif ( i == nX ) then\n\n dS = ((x(i-1)-x(i-2)) + (x(i)-x(i-1))) / 2.0\n\n dArray(i,j) = 1.0 / ( 2.0 * dS ) * &\n ( &\n 3.0 * array(i,j) - 4.0 * array(i-1,j) &\n + array(i-1,j) )\n\n endif\n\n enddo\n enddo\n \n end if \n \n end function dlg_pDeriv\n\nend module dlg\n", "meta": {"hexsha": "1d9efbb667dce3eae713708b6153f1b6c665c9c5", "size": 2617, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/dlg.f90", "max_stars_repo_name": "efdazedo/aorsa2d", "max_stars_repo_head_hexsha": "ce0b8c930715277eeb4d23e60cc88434ffdaa583", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-02-13T21:57:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-10T16:47:51.000Z", "max_issues_repo_path": "src/dlg.f90", "max_issues_repo_name": "efdazedo/aorsa2d", "max_issues_repo_head_hexsha": "ce0b8c930715277eeb4d23e60cc88434ffdaa583", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-02-23T20:33:30.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-23T20:34:31.000Z", "max_forks_repo_path": "src/dlg.f90", "max_forks_repo_name": "efdazedo/aorsa2d", "max_forks_repo_head_hexsha": "ce0b8c930715277eeb4d23e60cc88434ffdaa583", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-02-15T16:50:58.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-23T14:07:59.000Z", "avg_line_length": 27.8404255319, "max_line_length": 68, "alphanum_fraction": 0.2716851357, "num_tokens": 790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404057671712, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.788135502780626}} {"text": "program check_array_handler\n use fsvd_mod\n implicit none\n integer, parameter :: nrow = 6, ncol = 5, dp = kind(1.0d0)\n real(dp) :: x(nrow, ncol), y(nrow, ncol)\n integer :: xshape(2)\n integer :: i, j\n real(dp) :: va(ncol), vb(nrow), res(nrow)\n! for SVD\n integer :: k\n real(dp), allocatable :: U(:, :), S(:), VT(:, :)\n\n do i = 1, ncol\n do j = 1, nrow\n x(j, i) = 3.d0 * i\n end do\n end do\n\n xshape = shape(x)\n write (6, *) \"Rows in x =\", size(x, 1)\n write (6, *) \"Columns in x =\", size(x, 2)\n\n write (6, *)\n write (6, *) \"********************\"\n write (6, *) \"Test | Array division\"\n call array_division(x, 3.d0, nrow, ncol, y)\n write (6, *) \"Output array =>\"\n call print_array2d(y, nrow, ncol)\n\n do i = 1, ncol\n va(i) = 1.d0 * i\n end do\n\n do i = 1, nrow\n vb(i) = 1.d0\n res(i) = 1.d0\n end do\n\n write (6, *)\n write (6, *) \"********************\"\n write (6, *) \"Test | dgemv from subroutine\"\n call sub_dgemv(x, va, vb, 3.d0, 0.d0, nrow, ncol, res)\n write (6, *) \"Input vector =>\"\n call print_vector(va, ncol)\n write (6, *) \"Output [3.d0 * dot(x, y)] =>\"\n call print_vector(res, nrow)\n\n \n write (6, *)\n write (6, *) \"********************\"\n write (6, *) \"Test | SVD from subroutine\"\n DATA x/ &\n 8.79, 6.11,-9.15, 9.57,-3.49, 9.84, &\n 9.93, 6.91,-7.93, 1.64, 4.02, 0.15, &\n 9.83, 5.04, 4.86, 8.83, 9.80,-8.99, &\n 5.45,-0.27, 4.85, 0.74,10.00,-6.02, &\n 3.16, 7.98, 3.01, 5.80, 4.27,-5.31 &\n /\n write (6, *) \"Input matrix =>\"\n call print_array2d(x, nrow, ncol)\n k = min(nrow, ncol)\n allocate (U(nrow, k), S(k), VT(k, ncol))\n do j = 1, k\n do i = 1, nrow\n U(i, j) = 0.d0\n end do\n end do\n do j = 1, ncol\n do i = 1, k\n VT(i, j) = 0.d0\n end do\n end do\n do i = 1, k\n S(i) = 0.d0\n end do\n call sub_dgesvd(x, k, nrow, ncol, U, S, VT)\n call print_svd_result(U, S, VT, k, nrow, ncol)\n\n\n write (6, *)\n write (6, *) \"********************\"\n write (6, *) \"Test | SVD from module\"\n write (6, *) \"Input matrix =>\"\n call print_array2d(x, nrow, ncol)\n call print_extmod()\n! call sub_dgesvd(x, k, nrow, ncol, U, S, VT)\n call fsvd_mod_dgesvd(x, k, nrow, ncol, U, S, VT)\n call print_svd_result(U, S, VT, k, nrow, ncol)\n\nend program check_array_handler\n\nsubroutine print_svd_result(U, S, VT, k, nrow, ncol)\n implicit none\n integer, parameter :: dp = kind(1.0d0)\n integer, intent(in) :: k, nrow, ncol\n real(dp), intent(in) :: U(nrow, k), S(k), VT(k, ncol)\n write (6, *) \"Output U =>\"\n call print_array2d(U, nrow, k)\n write (6, *) \"Output S =>\"\n call print_vector(S, k)\n write (6, *) \"Output transpose(V) =>\"\n call print_array2d(VT, k, ncol)\nend subroutine print_svd_result\n", "meta": {"hexsha": "25c577af2998e9ecfd95c99e5a9d56df003ec302", "size": 2941, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/fpydemo/flibs/check_array_handler.f95", "max_stars_repo_name": "banskt/fpydemo", "max_stars_repo_head_hexsha": "786802ea280afb9945772f656da9d139b431b2ac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/fpydemo/flibs/check_array_handler.f95", "max_issues_repo_name": "banskt/fpydemo", "max_issues_repo_head_hexsha": "786802ea280afb9945772f656da9d139b431b2ac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/fpydemo/flibs/check_array_handler.f95", "max_forks_repo_name": "banskt/fpydemo", "max_forks_repo_head_hexsha": "786802ea280afb9945772f656da9d139b431b2ac", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-02-03T05:40:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-03T05:40:24.000Z", "avg_line_length": 28.2788461538, "max_line_length": 62, "alphanum_fraction": 0.4855491329, "num_tokens": 1125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037782, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7881354924521968}} {"text": "program main\n implicit none\n\n integer :: limit, i, prod, min_value\n integer, dimension(:), allocatable :: numbers\n\n limit = 20\n allocate(numbers(limit))\n\n prod = 1\n do i = 1, limit\n if (isPrime(i)) then\n prod = prod * i\n numbers(i) = 1\n else\n numbers(i) = i\n end if\n end do\n\n min_value = prod\n do while (count(mod(min_value, numbers) /= 0) /= 0)\n min_value = min_value + prod\n end do\n \n print *, min_value\n\n\ncontains\nfunction isPrime(number)\n implicit none\n integer, intent(in) :: number\n logical :: isPrime\n integer :: i\n\n isPrime = .True.\n do i = 2, number / 2\n if (mod(number, i) .eq. 0) then\n isPrime = .FALSE.\n exit\n end if\n end do\n ! isPrime = .FALSE.\n \n end function isPrime\nend program main", "meta": {"hexsha": "5246176255b3216eba0dcb1498d78ae01edb9893", "size": 916, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Problem_5/main.f95", "max_stars_repo_name": "jdalzatec/EulerProject", "max_stars_repo_head_hexsha": "2f2f4d9c009be7fd63bb229bb437ea75db77d891", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-28T05:32:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T05:32:58.000Z", "max_issues_repo_path": "Problem_5/main.f95", "max_issues_repo_name": "jdalzatec/EulerProject", "max_issues_repo_head_hexsha": "2f2f4d9c009be7fd63bb229bb437ea75db77d891", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Problem_5/main.f95", "max_forks_repo_name": "jdalzatec/EulerProject", "max_forks_repo_head_hexsha": "2f2f4d9c009be7fd63bb229bb437ea75db77d891", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.3555555556, "max_line_length": 55, "alphanum_fraction": 0.5032751092, "num_tokens": 244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403959948495, "lm_q2_score": 0.8479677583778257, "lm_q1q2_score": 0.7881354891375512}} {"text": "C$Procedure TRACEG ( Trace of a matrix, general dimension )\n \n DOUBLE PRECISION FUNCTION TRACEG ( MATRIX, NDIM )\n \nC$ Abstract\nC\nC Return the trace of a square matrix of arbitrary dimension.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC MATRIX\nC\nC$ Declarations\n \n INTEGER NDIM\n DOUBLE PRECISION MATRIX ( NDIM,NDIM )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC MATRIX I NDIM x NDIM matrix of double precision numbers.\nC NDIM I Dimension of the matrix.\nC TRACEG O The trace of MATRIX.\nC\nC$ Detailed_Input\nC\nC MATRIX is a double precision square matrix of arbitrary\nC dimension. The input matrix must be square or else\nC the concept is meaningless.\nC\nC NDIM is the dimension of MATRIX.\nC\nC$ Detailed_Output\nC\nC TRACEG is the trace of MATRIX, i.e. it is the sum of the\nC diagonal elements of MATRIX.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Particulars\nC\nC TRACEG simply executes in FORTRAN code the following loop:\nC\nC TRACEG = Summation from I = 1 to NDIM of MATRIX(I,I)\nC\nC No error detection or correction is implemented within this\nC function.\nC\nC$ Examples\nC\nC | 3 5 7 |\nC Suppose that MATRIX = | 0 -2 8 | (with NDIM = 3), then\nC | 3 0 -1 |\nC\nC TRACEG (MATRIX, 3) = 0. (which is the sum of 3, -2 and -1).\nC\nC$ Restrictions\nC\nC No checking is performed to guard against floating point overflow\nC or underflow. This routine should probably not be used if the\nC input matrix is expected to have large double precision numbers\nC along the diagonal.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WLT)\nC\nC-&\n \nC$ Index_Entries\nC\nC trace of a nxn_matrix\nC\nC-&\n \n INTEGER I\n \n TRACEG = 0.0D0\n DO I = 1,NDIM\n TRACEG = TRACEG + MATRIX(I,I)\n END DO\n \n RETURN\n END\n", "meta": {"hexsha": "08e3ebc38470166eb0d90ff508cdb144e3995226", "size": 3729, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/traceg.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/traceg.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/traceg.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 27.0217391304, "max_line_length": 72, "alphanum_fraction": 0.655135425, "num_tokens": 1066, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403979493139, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.7881354872238999}} {"text": "module PlaneGeomModule\n!------------------------------------------------------------------------------\n! Lagrangian Particle / Panel Method\n!------------------------------------------------------------------------------\n!\n!> @author\n!> Peter Bosler, Department of Mathematics, University of Michigan\n!\n!> @defgroup PlaneGeom Planar Geometry\n!> defines functions for performing geometric calculations in the plane\n!\n!\n! DESCRIPTION:\n!> @file\n!> defines functions for performing geometric calculations in the plane\n!\n!------------------------------------------------------------------------------\n\nuse NumberKindsModule\n\nimplicit none\n\npublic\n\ncontains\n!----------------\n! Basic geometry : length, area, centers of mass, etc.\n!----------------\n\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Euclidean distance between two points in the plane\n!\n!> @ingroup PlaneGeom\n!\n!> @param[in] xyA double precision real size(2); vector in the plane\n!> @param[in] xyB double precision real size(2); vector in the plane\n!> @return Distance double precision real, scalar distance between xyA and xyB\n!------------------------------------------------------------------------------\npure function Distance( xyA, xyB)\n\treal(kreal) :: Distance\n\treal(kreal), intent(in) :: xyA(2), xyB(2)\n\tDistance = sqrt( sum( (xyB - xyA)*(xyB - xyA) ) )\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Find midpoint of line segment connecting two points in the plane\n!\n!> @ingroup PlaneGeom\n!\n!> @param[in] xyA double precision real size(2); vector in the plane\n!> @param[in] xyB double precision real size(2); vector in the plane\n!> @return Midpoint double precision real size(2)\n!------------------------------------------------------------------------------\npure function Midpoint( xyA, xyB )\n\treal(kreal) :: Midpoint(2)\n\treal(kreal), intent(in) :: xyA(2), xyB(2)\n\tMidpoint = 0.5_kreal*(xyA + xyB)\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Cetroid of a triangle created by three points in the plane\n!\n!> @ingroup PlaneGeom\n!\n!> @param[in] xyA double precision real size(2); vector in the plane\n!> @param[in] xyB double precision real size(2); vector in the plane\n!> @param[in] xyC double precision real size(2); vector in the plane\n!> @return TriCentroid double precision real size(2)\n!------------------------------------------------------------------------------\npure function TriCentroid( xyA, xyB, xyC )\n\treal(kreal) :: TriCentroid(2)\n\treal(kreal), intent(in) :: xyA(2), xyB(2), xyC(2)\n\tTriCentroid = (xyA + xyB + xyC)/3.0_kreal\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Cetroid of a quadrilateral created by four points in the plane\n!\n!> @ingroup PlaneGeom\n!\n!> @param[in] xyA double precision real size(2); vector in the plane\n!> @param[in] xyB double precision real size(2); vector in the plane\n!> @param[in] xyC double precision real size(2); vector in the plane\n!> @param[in] xyD double precision real size(2); vector in the plane\n!> @return QuadCentroid double precision real size(2)\n!------------------------------------------------------------------------------\npure function QuadCentroid( xyA, xyB, xyC, xyD )\n\treal(kreal) :: QuadCentroid(2)\n\treal(kreal), intent(in) :: xyA(2), xyB(2), xyC(2), xyD(2)\n\tQuadCentroid = 0.25_kreal*(xyA + xyB + xyC + xyD)\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief area of a planar triangle whose vertices are the input vectors\n!\n!> @ingroup PlaneGeom\n!\n!> @param[in] xA double precision real size(2); vector in the plane\n!> @param[in] xB double precision real size(2); vector in the plane\n!> @param[in] xC double precision real size(2); vector in the plane\n!> @return TriArea double precision real; scalar area of triangle \n!------------------------------------------------------------------------------\npure function TriArea( xA, xB, xC )\n\treal(kreal) :: TriArea\n\treal(kreal), intent(in) :: xA(2), xB(2), xC(2)\n\tTriArea = 0.5_kreal*abs( -xB(1)*xA(2) + xC(1)*xA(2) + xA(1)*xB(2) - xC(1)*xB(2) - xA(1)*xC(2) + xB(1)*xC(2))\nend function\n\n\n!----------------\n! Misc. functions\n!----------------\n!\n\nend module\n\n\n", "meta": {"hexsha": "f9b871f5b07a03d6b9f5da855867789c91fe642d", "size": 4422, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/PlaneGeometry.f90", "max_stars_repo_name": "pbosler/lpm-v2", "max_stars_repo_head_hexsha": "b562c5c942b5e29cef4cfc4f85c0b1341cae690b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2016-01-12T17:27:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-05T12:55:10.000Z", "max_issues_repo_path": "src/PlaneGeometry.f90", "max_issues_repo_name": "pbosler/lpm-v2", "max_issues_repo_head_hexsha": "b562c5c942b5e29cef4cfc4f85c0b1341cae690b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-01-13T22:23:56.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-11T17:47:31.000Z", "max_forks_repo_path": "src/PlaneGeometry.f90", "max_forks_repo_name": "pbosler/lpm-v2", "max_forks_repo_head_hexsha": "b562c5c942b5e29cef4cfc4f85c0b1341cae690b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.6612903226, "max_line_length": 109, "alphanum_fraction": 0.5316598824, "num_tokens": 1086, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896845856297, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7880589127464489}} {"text": "! Auto differentiation\n! ====================\n\n! This is a powerful numerical technique which provides numerically exact vaulues of a first derivative,\n! not an approximation.\n\n! Represent a variable by a pair containing its value and first derivative's value {x, d}, and\n! implementation is by extensive use of operator overloading.\n!\n! For example:\n! x**2 is represented by {x**2, 2*x} (a specific case of x**n)\n! sin(x) is represented by {sin(x), cos(x)}\n!\n! The product rule: {x dx}*{y dy} => {xy (x*dy+y*dx)}\n!\n! so x**2*sin(x) => {x**2 2*x}*{sin(x) cos(x)} => {x**2*sin(x) (x**2*cos(x)+2*x*sin(x))}\n\n! The advantage is that complicated algebra calculating first derivatives is avoided without using an approximation\n! - very useful when working with a Jacobian for example.\n! The disadvantage is that the function value is always calculated as well.\n\n!\n! Attribution\n! ===========\n! Read about this somewhere at least 10 years ago and thought it looked interesting. So the idea was someone else's\n! but the implementation is all mine.\n\n!\n! Example\n! =======\n!\n! To find the first an second derivatives of 1/(1-x) at x=0.5\n!\n! 1) Set the auto_var x call x%set(0.5) - the components of x are now {0.5 1}\n! 2) Assign the auto_var f f = 1/(1-x) which generates the following call sequence:\n! sub_n_x {0.5 1} -> {0.5 -1}\n! div_r_x\n! quotient rule {0.5 -1} -> {2 4}\n! 3) So f is now set to {2 4}\n!\n!\n! Usage\n! =====\n!\n! To get the numerical value of the derivative of x**2 at x = 3\n!\n! type(auto_var) :: x, y\n! call x%set(3)\n! y = x**2\n! write(*,'(a,f0.1)') 'Derivative of x**2 at x = 3 is ',y%get_derivative()\n!\n! Tested\n! ======\n! gfortran -o autodiff -cpp -DUTEST autodiff.f90\n! \n! ./autodiff\n! passed :: x**2\n! passed :: x**3 + x\n! passed :: 3*x**2\n! passed :: 3*x**4 + 2*x\n! passed :: 3*x**2 + 2*x - 5\n! passed :: (x + 2)*(x + 3)*(x - 1)\n! passed :: (x + 2)*(3 - x)*(x**2 - 1)\n! passed :: (x + 2)/(x**2 - 1)\n! passed :: 1.5d0/(x-1) - 0.5d0/(x+1) [previous function as partial fractions]\n! passed :: 1/(1-x)\n! passed :: 4/x\n! passed :: e**x\n! passed :: 2**x\n! passed :: sin(x)\n! passed :: cos(x)\n! passed :: sin(1/x)\n! passed :: sqrt(x)\n! passed :: ||y||\n! passed :: sqrt(9+u(2)**2) == ||u||\n! passed :: _t_ x _x_ (1)\n! passed :: _t_ x _x_ (2)\n! passed :: _t_ x _x_ (3)\n! passed :: x**2 - 2*x*y , Fx\n! passed :: x**2 - 2*x*y , Fy\n! passed :: (x-1)*sin(z) + (y+x)*cos(z/2)**2 Fx\n! passed :: (x-1)*sin(z) + (y+x)*cos(z/2)**2 Fy\n! passed :: (x-1)*sin(z) + (y+x)*cos(z/2)**2 Fz\n! passed :: log(4 + x)\n! passed :: log(4 + x**2)\n! sub_n_x\n! div_n_x\n! quotient rule\n! passed :: 1/(1-x)\n\n\nmodule auto_diff\n implicit none\n \n public :: auto_var\n public :: set_val, make_var, make_const, get_val, get_der, create\n public :: operator(==), operator(+), operator(-), operator(*), operator(/), operator(**), assignment(=)\n public :: operator(<), operator(>)\n public :: cos, sin, tan, sqrt, operator(.dot.), operator(.cross.)\n public :: cosh, sinh, tanh, exp, log\n\n \n#ifdef UTEST\n public :: utest\n#endif\n integer :: debug_level = 0\n \nprivate\n\n type auto_var\n private\n real(8) :: x = 0\n real(8) :: d = 1\n contains\n procedure, public :: set => set_ad\n procedure, public :: set_constant => set_constant_ad\n procedure, public :: get_value => get_value_ad\n procedure, public :: get_derivative => get_derivative_ad\n end type auto_var\n\n interface create\n module procedure create_av\n end interface\n \n interface make_var\n module procedure make_var_s\n module procedure make_var_v\n end interface\n \n interface sqrt\n module procedure sqrt_av\n end interface\n\n interface norm2\n module procedure norm2_av\n end interface\n\n interface assignment(=)\n module procedure assign_s\n module procedure assign_v\n end interface\n \n interface operator(+)\n module procedure add_x_x_v\n module procedure add_x_x\n module procedure add_x_r\n module procedure add_r_x\n module procedure add_x_n\n module procedure add_n_x\n end interface\n\n interface operator(-)\n module procedure sub_x_x_v\n module procedure sub_x_x\n module procedure sub_x_r\n module procedure sub_r_x\n module procedure sub_r_x_a\n module procedure sub_x_n\n module procedure sub_n_x\n end interface\n\n interface operator(*)\n module procedure mult_x_x\n module procedure mult_x_r\n module procedure mult_r_x\n module procedure mult_x_n\n module procedure mult_n_x\n end interface\n\n interface operator(/)\n module procedure div_x_x\n module procedure div_xv_x\n module procedure div_x_r\n module procedure div_r_x\n module procedure div_x_n\n module procedure div_n_x\n end interface\n\n interface operator(**)\n module procedure pow_x_x\n module procedure pow_x_n\n module procedure pow_x_r\n module procedure pow_n_x\n module procedure pow_r_x\n end interface\n\n interface operator(==)\n module procedure equal\n end interface\n\n interface operator(<)\n module procedure less_than\n end interface\n\n interface operator(>)\n module procedure greater_than\n end interface\n\n interface operator(<=)\n module procedure less_equal\n end interface\n\n interface operator(>=)\n module procedure greater_equal\n end interface\n\n interface get_val\n module procedure get_val_s\n module procedure get_val_v\n end interface\n\n interface get_der\n module procedure get_der_s\n module procedure get_der_v\n end interface\n\n interface set_val\n module procedure set_val_n\n module procedure set_val_r\n end interface\n\n interface sin\n module procedure sin_x_r\n end interface\n\n interface cos\n module procedure cos_x_r\n end interface\n\n interface tan\n module procedure tan_x_r\n end interface\n\n interface sinh\n module procedure sinh_x_r\n end interface\n\n interface cosh\n module procedure cosh_x_r\n end interface\n\n interface tanh\n module procedure tanh_x_r\n end interface\n\n interface log\n module procedure log_x_r\n end interface\n\n interface exp\n module procedure exp_x_r\n end interface\n\n interface operator(.dot.)\n module procedure dot_x_y\n module procedure dot_r_x\n module procedure dot_x_r\n end interface\n\n interface operator(.cross.)\n module procedure cross_x_y\n end interface\n \ncontains\n\n subroutine set_ad(this, v)\n class(auto_var), intent(inout) :: this\n real(8), intent(in) :: v\n this%x = v\n this%d = 1\n end subroutine set_ad\n\n subroutine set_constant_ad(this, v)\n class(auto_var), intent(inout) :: this\n real(8), intent(in) :: v\n this%x = v\n this%d = 0\n end subroutine set_constant_ad\n \n function get_value_ad(this)\n class(auto_var), intent(in) :: this\n real(8) :: get_value_ad\n get_value_ad = this%x\n end function get_value_ad\n \n function get_derivative_ad(this)\n class(auto_var), intent(in) :: this\n real(8) :: get_derivative_ad\n get_derivative_ad = this%d\n end function get_derivative_ad\n\n type(auto_var) function create_av(x) result(r)\n real(8), intent(in) :: x\n r%x = x\n end function create_av\n \n subroutine assign_s(a, b)\n type(auto_var), intent(out) :: a\n type(auto_var), intent(in) :: b\n a%x = b%x\n a%d = b%d\n end subroutine assign_s\n \n subroutine assign_v(a, b)\n type(auto_var), intent(out) :: a(:)\n type(auto_var), intent(in) :: b(:)\n integer :: i\n do i=1,size(b)\n a(i)%x = b(i)%x\n a(i)%d = b(i)%d\n end do\n end subroutine assign_v\n \n function cross_x_y(a, b)\n type(auto_var) :: cross_x_y(3)\n type(auto_var), intent(in) :: a(3), b(3)\n integer :: i, j, k\n do i=1,3\n j = merge(1,i+1,i==3)\n k = merge(1,j+1,j==3)\n cross_x_y(i) = a(j)*b(k) - a(k)*b(j)\n end do\n end function cross_x_y\n\n function sqrt_av(x)\n type(auto_var) :: sqrt_av\n type(auto_var), intent(in) :: x\n sqrt_av = pow_x_r(x,0.5d0)\n end function sqrt_av\n\n function norm2_av(x)\n type(auto_var) :: norm2_av\n type(auto_var), intent(in) :: x(:)\n type(auto_var) :: v\n norm2_av%d = 0\n v = x .dot. x\n norm2_av = pow_x_r(v,0.5d0)\n end function norm2_av\n\n function dot_x_y(x, y)\n type(auto_var) :: dot_x_y\n type(auto_var), intent(in) :: x(:), y(:)\n integer :: i\n dot_x_y%d = 0\n do i=1,size(x)\n dot_x_y = dot_x_y + x(i)*y(i)\n end do\n end function dot_x_y\n\n function dot_r_x(r, x)\n type(auto_var) :: dot_r_x\n real(8), intent(in) :: r(:)\n type(auto_var), intent(in) :: x(:)\n type(auto_var) :: s(size(x))\n integer :: i\n do i=1,size(x)\n call set_val(s(i),r(i))\n end do\n dot_r_x = dot_x_y(s, x)\n end function dot_r_x\n\n function dot_x_r(x, r)\n type(auto_var) :: dot_x_r\n real(8), intent(in) :: r(:)\n type(auto_var), intent(in) :: x(:)\n type(auto_var) :: s(size(x))\n integer :: i\n do i=1,size(x)\n call set_val(s(i),r(i))\n end do\n dot_x_r = dot_x_y(s, x)\n end function dot_x_r\n\n real(8) function get_val_s(x)\n type(auto_var), intent(in) :: x\n get_val_s = x%x\n end function get_val_s\n\n function get_val_v(x)\n type(auto_var), intent(in) :: x(:)\n real(8) :: get_val_v(size(x))\n integer :: i\n do i=1,size(x)\n get_val_v(i) = x(i)%x\n end do\n end function get_val_v\n\n real(8) function get_der_s(x)\n type(auto_var), intent(in) :: x\n get_der_s = x%d\n end function get_der_s\n\n function get_der_v(x)\n type(auto_var), intent(in) :: x(:)\n real(8) :: get_der_v(size(x))\n integer :: i\n do i=1,size(x)\n get_der_v(i) = x(i)%d\n end do\n end function get_der_v\n\n subroutine set_val_r(x, v, isvar)\n type(auto_var), intent(inout) :: x\n real(8), intent(in) :: v\n logical, optional, intent(in) :: isvar\n x%x = v\n if (present(isvar)) then\n x%d = merge(1,0,isvar)\n end if\n end subroutine set_val_r\n\n subroutine set_val_n(x, v, isvar)\n type(auto_var), intent(inout) :: x\n integer, intent(in) :: v\n logical, optional, intent(in) :: isvar\n x%x = v\n if (present(isvar)) then\n x%d = merge(1,0,isvar)\n end if\n end subroutine set_val_n\n\n subroutine make_var_s(x, f)\n type(auto_var), intent(inout) :: x\n logical, optional, intent(in) :: f\n if (present(f)) then\n x%d = merge(1, 0, f)\n else\n x%d = 1\n end if\n end subroutine make_var_s\n\n ! Create an auto_var version of the input array\n subroutine make_var_v(in, out, index)\n real(8), intent(in) :: in(:)\n type(auto_var), intent(out) :: out(size(in))\n integer, optional, intent(in) :: index\n integer :: i\n do i=1,size(in)\n out(i)%x = in(i)\n if (present(index)) then\n out(i)%d = merge(1, 0, index == i)\n else\n out(i)%d = 0\n end if\n end do\n end subroutine make_var_v\n\n subroutine make_const(x)\n type(auto_var), intent(inout) :: x\n x%d = 0\n end subroutine make_const\n\n\n !----------------------------------------------------------------------------\n ! Equality test\n function equal(x, y) result(m)\n logical :: m\n type(auto_var), intent(in) :: x\n type(auto_var), intent(in) :: y\n\n m = abs(x%x-y%x) < 1.0d-8 .and. abs(x%d-y%d) < 1.0d-8\n end function equal\n\n !----------------------------------------------------------------------------\n ! Less-than test\n function less_than(x, y) result(m)\n logical :: m\n type(auto_var), intent(in) :: x\n type(auto_var), intent(in) :: y\n\n m = x%x < y%x\n end function less_than\n\n !----------------------------------------------------------------------------\n ! Greater-than test\n function greater_than(x, y) result(m)\n logical :: m\n type(auto_var), intent(in) :: x\n type(auto_var), intent(in) :: y\n\n m = x%x > y%x\n end function greater_than\n\n !----------------------------------------------------------------------------\n ! Less-equal test\n function less_equal(x, y) result(m)\n logical :: m\n type(auto_var), intent(in) :: x\n type(auto_var), intent(in) :: y\n\n m = x%x <= y%x\n end function less_equal\n\n !----------------------------------------------------------------------------\n ! Greater-equal test\n function greater_equal(x, y) result(m)\n logical :: m\n type(auto_var), intent(in) :: x\n type(auto_var), intent(in) :: y\n\n m = x%x >= y%x\n end function greater_equal\n\n !----------------------------------------------------------------------------\n ! Add\n\n function add_x_x_v(x, y) result(m)\n type(auto_var), intent(in) :: x(:)\n type(auto_var), intent(in) :: y(:)\n type(auto_var) :: m(size(x))\n integer :: i\n if (debug_level > 0) write(*,'(a)') 'add_x_x_v'\n do i=1,size(x)\n m(i) = x(i) + y(i)\n end do\n end function add_x_x_v\n\n function add_x_x(x, y) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n type(auto_var), intent(in) :: y\n if (debug_level > 0) write(*,'(a)') 'add_x_x'\n m%x = x%x + y%x\n m%d = x%d + y%d\n end function add_x_x\n\n function add_x_r(x, r) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n real(8), intent(in) :: r\n if (debug_level > 0) write(*,'(a)') 'add_x_r'\n m%x = x%x + r\n m%d = x%d\n end function add_x_r\n\n function add_r_x(r, x) result(m)\n type(auto_var) :: m\n real(8), intent(in) :: r\n type(auto_var), intent(in) :: x\n if (debug_level > 0) write(*,'(a)') 'add_r_x'\n m%x = x%x + r\n m%d = x%d\n end function add_r_x\n\n function add_x_n(x, r) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n integer, intent(in) :: r\n if (debug_level > 0) write(*,'(a)') 'add_x_n'\n m%x = x%x + r\n m%d = x%d\n end function add_x_n\n\n function add_n_x(r, x) result(m)\n type(auto_var) :: m\n integer, intent(in) :: r\n type(auto_var), intent(in) :: x\n if (debug_level > 0) write(*,'(a)') 'add_n_x'\n m%x = x%x + r\n m%d = x%d\n end function add_n_x\n\n !----------------------------------------------------------------------------\n ! Subtract\n\n function sub_x_x_v(x, y) result(m)\n type(auto_var), intent(in) :: x(:)\n type(auto_var), intent(in) :: y(:)\n type(auto_var) :: m(size(x))\n integer :: i\n if (debug_level > 0) write(*,'(a)') 'sub_x_x_v'\n do i=1,size(x)\n m(i) = x(i) - y(i)\n end do\n end function sub_x_x_v\n\n function sub_x_x(x, y) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n type(auto_var), intent(in) :: y\n if (debug_level > 0) write(*,'(a)') 'sub_x_x'\n m%x = x%x - y%x\n m%d = x%d - y%d\n end function sub_x_x\n\n function sub_x_r(x, r) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n real(8), intent(in) :: r\n if (debug_level > 0) write(*,'(a)') 'sub_x_r'\n m%x = x%x - r\n m%d = x%d\n end function sub_x_r\n\n function sub_r_x(r, x) result(m)\n type(auto_var) :: m\n real(8), intent(in) :: r\n type(auto_var), intent(in) :: x\n if (debug_level > 0) write(*,'(a)') 'sub_r_x'\n m%x = r - x%x\n m%d = -x%d\n end function sub_r_x\n\n function sub_r_x_a(r, x) result(m)\n real(8), intent(in) :: r(:)\n type(auto_var), intent(in) :: x(:)\n type(auto_var) :: m(size(r))\n integer :: i\n if (debug_level > 0) write(*,'(a)') 'sub_r_x_a'\n do i=1, size(r)\n m(i) = r(i) - x(i)\n end do\n end function sub_r_x_a\n\n function sub_x_n(x, r) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n integer, intent(in) :: r\n if (debug_level > 0) write(*,'(a)') 'sub_x_n'\n m%x = x%x - r\n m%d = x%d\n end function sub_x_n\n\n function sub_n_x(r, x) result(m)\n type(auto_var) :: m\n integer, intent(in) :: r\n type(auto_var), intent(in) :: x\n if (debug_level > 0) write(*,'(a)') 'sub_n_x'\n m%x = r - x%x\n m%d = -x%d\n end function sub_n_x\n\n !----------------------------------------------------------------------------\n ! Multiply\n\n function mult_x_x(uf, vf) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: uf\n type(auto_var), intent(in) :: vf\n if (debug_level > 0) write(*,'(a)') 'product rule'\n associate (u =>uf%x, v => vf%x, du => uf%d, dv => vf%d)\n m%x = u*v\n m%d = u*dv + v*du\n end associate\n end function mult_x_x\n\n function mult_x_r(x, r) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n real(8), intent(in) :: r\n if (debug_level > 0) write(*,'(a)') 'mult_x_r'\n m = mult_x_x(x,auto_var(r,0))\n end function mult_x_r\n\n function mult_r_x(r, x) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n real(8), intent(in) :: r\n if (debug_level > 0) write(*,'(a)') 'mult_r_x'\n m = mult_x_x(auto_var(r,0),x)\n end function mult_r_x\n\n function mult_x_n(x, r) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n integer, intent(in) :: r\n if (debug_level > 0) write(*,'(a)') 'mult_x_r'\n m = mult_x_x(x,auto_var(r,0))\n end function mult_x_n\n\n function mult_n_x(r, x) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n integer, intent(in) :: r\n if (debug_level > 0) write(*,'(a)') 'mult_n_x'\n m = mult_x_x(auto_var(r,0),x)\n end function mult_n_x\n\n !----------------------------------------------------------------------------\n ! Divide\n\n function div_x_x(uf, vf) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: uf\n type(auto_var), intent(in) :: vf\n if (debug_level > 0) write(*,'(a)') 'quotient rule'\n associate (u =>uf%x, v => vf%x, du => uf%d, dv => vf%d)\n m%x = u/v\n m%d = (v * du - u * dv)/v**2\n end associate\n end function div_x_x\n\n function div_x_r(x, r) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n real(8), intent(in) :: r\n if (debug_level > 0) write(*,'(a)') 'div_x_r'\n m = div_x_x(x,auto_var(r,0))\n end function div_x_r\n\n function div_xv_x(x, r) result(m)\n type(auto_var), intent(in) :: x(:)\n type(auto_var), intent(in) :: r\n type(auto_var) :: m(size(x))\n integer :: i\n if (debug_level > 0) write(*,'(a)') 'div_xv_x'\n do i=1, size(x)\n m(i) = div_x_x(x(i),r)\n end do\n end function div_xv_x\n\n function div_r_x(r, x) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n real(8), intent(in) :: r\n if (debug_level > 0) write(*,'(a)') 'div_r_x'\n m = div_x_x(auto_var(r,0),x)\n end function div_r_x\n\n function div_x_n(x, r) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n integer, intent(in) :: r\n if (debug_level > 0) write(*,'(a)') 'div_x_n'\n m = div_x_x(x,auto_var(r,0))\n end function div_x_n\n\n function div_n_x(r, x) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n integer, intent(in) :: r\n if (debug_level > 0) write(*,'(a)') 'div_n_x'\n m = div_x_x(auto_var(r,0),x)\n end function div_n_x\n\n !----------------------------------------------------------------------------\n ! Power\n\n function pow_x_x(x, y) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n type(auto_var), intent(in) :: y\n if (debug_level > 0) write(*,'(a)') 'pow_x_x'\n stop '[pow_x_x] not yet implemented'\n m%x = x%x ** y%x\n m%d = x%d * (1 + log(x%x))*m%x\n end function pow_x_x\n\n function pow_x_n(x, r) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n integer, intent(in) :: r\n if (debug_level > 0) write(*,'(a)') 'x**n'\n m%x = x%x ** r\n m%d = x%d * r*x%x ** (r-1)\n end function pow_x_n\n\n function pow_x_r(x, r) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n real(8), intent(in) :: r\n if (debug_level > 0) write(*,'(a)') 'x**r'\n m%x = x%x ** r\n m%d = x%d * r*x%x ** (r-1)\n end function pow_x_r\n\n function pow_n_x(r, x) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n integer, intent(in) :: r\n if (debug_level > 0) write(*,'(a)') 'n**x'\n m%x = r ** x%x\n m%d = x%d * r**x%x * log(dble(r))\n end function pow_n_x\n\n function pow_r_x(r, x) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n real(8), intent(in) :: r\n if (debug_level > 0) write(*,'(a)') 'r**x'\n m%x = r ** x%x\n m%d = x%d * r**x%x * log(r)\n end function pow_r_x\n\n !----------------------------------------------------------------------------\n ! Trig\n function sin_x_r(x) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n if (debug_level > 0) write(*,'(a)') 'sin_x_r'\n m%x = sin(x%x)\n m%d = x%d * cos(x%x)\n end function sin_x_r\n\n function cos_x_r(x) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n if (debug_level > 0) write(*,'(a)') 'cos_x_r'\n m%x = cos(x%x)\n m%d = x%d * (-sin(x%x))\n end function cos_x_r\n\n function tan_x_r(x) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n if (debug_level > 0) write(*,'(a)') 'tan_x_r'\n m = div_x_x(sin(x),cos(x))\n end function tan_x_r\n\n !----------------------------------------------------------------------------\n ! Exponential\n function sinh_x_r(x) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n if (debug_level > 0) write(*,'(a)') 'sinh_x_r'\n m%x = sinh(x%x)\n m%d = x%d * cosh(x%x)\n end function sinh_x_r\n\n function cosh_x_r(x) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n if (debug_level > 0) write(*,'(a)') 'cosh_x_r'\n m%x = cosh(x%x)\n m%d = x%d * sinh(x%x)\n end function cosh_x_r\n\n function tanh_x_r(x) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n if (debug_level > 0) write(*,'(a)') 'tanh_x_r'\n m = div_x_x(sinh(x),cosh(x))\n end function tanh_x_r\n\n function log_x_r(x) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n if (debug_level > 0) write(*,'(a)') 'log_x_r'\n m%x = log(x%x)\n m%d = x%d/x%x\n end function log_x_r\n\n function exp_x_r(x) result(m)\n type(auto_var) :: m\n type(auto_var), intent(in) :: x\n if (debug_level > 0) write(*,'(a)') 'exp_x_r'\n m%x = exp(x%x)\n m%d = m%x\n end function exp_x_r\n \n\n !============================================================================\n !\n ! Unit test\n#ifdef UTEST\n subroutine utest\n\n type(auto_var) :: x, y, z, f, u(2), s(3), t(3), v(3)\n real(8) :: e = exp(1.0d0)\n\n call set_val(x,3)\n y = x**2\n call testResult('x**2',auto_var(9,6),y)\n\n y = x**3 + x\n call testResult('x**3 + x',auto_var(30,28),y)\n\n y = 3*x**2\n call testResult('3*x**2',auto_var(27,18),y)\n\n y = 3*x**4 + x*2\n call testResult('3*x**4 + 2*x',auto_var(3*3**4+2*3,12*3**3+2),y)\n\n y = 3*x**2 + x*2.0d0 - 5\n call testResult('3*x**2 + 2*x - 5',auto_var(28,20),y)\n\n y = (x + 2)*(x + 3)*(x - 1)\n call testResult('(x + 2)*(x + 3)*(x - 1)',auto_var((3+2)*(3+3)*(3-1),3*3**2+8*3+1),y)\n\n y = (x + 2)*(3 - x)*(x**2 - 1)\n call testResult('(x + 2)*(3 - x)*(x**2 - 1)',auto_var(0,-40),y)\n\n y = (x + 2)/(x**2 - 1)\n call testResult('(x + 2)/(x**2 - 1)',auto_var(1.5d0/2 - 0.5d0/4,-1.5d0/2**2+0.5d0/4**2),y)\n ! and now the same function as partial fractions\n y = 1.5d0/(x-1) - 0.5d0/(x+1)\n call testResult('1.5d0/(x-1) - 0.5d0/(x+1) [previous function as partial fractions]',&\n auto_var(1.5d0/2 - 0.5d0/4,-1.5d0/2**2+0.5d0/4**2),y)\n\n call set_val(x,0.5d0)\n y = 1.0d0/(1-x)\n call testResult('1/(1-x)',auto_var(2,4),y)\n\n call set_val(x,4)\n y = 4/x\n call testResult('4/x',auto_var(1,-1.0/4),y)\n\n y = e**x\n call testResult('e**x',auto_var(e**4,e**4),y)\n\n y = 2**x\n call testResult('2**x',auto_var(2**4,2**4*log(2.0d0)),y)\n\n!!$ y = x**x ! - not yet correctly implemented\n!!$ call testResult('x**x',auto_var(4**4,(1+log(4.0d0))*4**4),y)\n\n call set_val(x,1)\n y = sin(x)\n call testResult('sin(x)',auto_var(sin(1.0d0),cos(1.0d0)),y)\n\n call set_val(x,2)\n y = cos(x)\n call testResult('cos(x)',auto_var(cos(2.0d0),-sin(2.0d0)),y)\n\n call set_val(x,2)\n y = sin(1/x)\n call testResult('sin(1/x)',auto_var(sin(1/2.0d0),-cos(1/2.0d0)/4),y)\n \n y = sqrt(x)\n call testResult('sqrt(x)',auto_var(sqrt(2.0d0), 0.5d0/sqrt(2.0d0)),y)\n\n call set_val(u(1),3,.false.)\n call set_val(u(2),4,.false.)\n y = norm2(u)\n call testResult('||y||',auto_var(5,0),y)\n call make_var(u(2))\n y = norm2(u)\n call testResult('sqrt(9+u(2)**2) == ||u||',sqrt(9 + u(2)**2),y)\n\n ! Cross product\n call set_val(x,2)\n call make_var([0.0d0, 1.0d0, -1.0d0],t)\n t(1) = x**2\n call set_val(s(1), 2, .false.)\n s(2) = x\n s(3) = 1/x\n v = t .cross. s\n call testResult('_t_ x _x_ (1)',auto_var(2.5d0,0.75d0),v(1))\n call testResult('_t_ x _x_ (2)',auto_var(-4.0d0,-1.0),v(2))\n call testResult('_t_ x _x_ (3)',auto_var(6.0d0,12.0d0),v(3))\n \n ! Partial derivatives\n call set_val(x,3,.true.)\n call set_val(y,2,.false.)\n z = x**2 - 2*x*y\n call testResult('x**2 - 2*x*y , Fx',auto_var(-3,2),z)\n\n call set_val(x,3,.false.)\n call set_val(y,2,.true.)\n z = x**2 - 2.0d0*x*y\n call testResult('x**2 - 2*x*y , Fy',auto_var(-3,-6),z)\n\n call set_val(x,2,.true.); call set_val(y,3,.false.); call set_val(z,0.6d0,.false.)\n f = (x-1)*sin(z) + (y+x)*cos(z/2)**2\n call testResult('(x-1)*sin(z) + (y+x)*cos(z/2)**2 Fx',auto_var(sin(0.6d0)+5*cos(0.3d0)**2,sin(0.6d0)+cos(0.3d0)**2),f)\n\n call set_val(x,2,.false.); call set_val(y,3,.true.); call set_val(z,0.6d0,.false.)\n f = (x-1)*sin(z) + (y+x)*cos(z/2)**2\n call testResult('(x-1)*sin(z) + (y+x)*cos(z/2)**2 Fy',auto_var(sin(0.6d0)+5*cos(0.3d0)**2,cos(0.3d0)**2),f)\n\n call set_val(x,2,.false.); call set_val(y,3,.false.); call set_val(z,0.6d0,.true.)\n f = (x-1)*sin(z) + (y+x)*cos(z/2)**2\n call testResult('(x-1)*sin(z) + (y+x)*cos(z/2)**2 Fz', &\n auto_var(sin(0.6d0)+5*cos(0.3d0)**2,cos(0.6d0) - 5*cos(0.3d0)*sin(0.3d0)),f)\n \n \n call set_val(x,3,.true.)\n f = log(4.0d0 + x)\n call testResult('log(4 + x)', &\n auto_var(log(4.0d0 + 3),1/(4.0+3)),f)\n\n call set_val(x,3,.true.)\n call set_val(y,2,.false.)\n f = log(4.0d0 + x**2)\n call testResult('log(4 + x**2)', &\n auto_var(log(4.0d0 + 3**2),2*3/(4.0+3**2)),f)\n \n ! The example in the comment at the top with call sequence\n block\n type(auto_var) :: f, x\n debug_level = 1\n write(*,'(a)') 'Call sequence for 1/(1-x), '\n call x%set(0.5d0)\n f = 1/(1-x)\n call testResult('1/(1-x)', &\n auto_var(1/(1-0.5d0),1/(1-0.5d0)**2),f)\n end block\n\n \n \n contains\n subroutine testResult(str,ref,res)\n character(len=*), intent(in) :: str\n type(auto_var), intent(in) :: res\n type(auto_var), intent(in) :: ref\n if (res == ref) then\n write(*,'(a)') 'passed'//' :: '//str\n else\n write(*,'(2(a,f0.6))') 'FAILED :: '//str//' => ', res%x - ref%x,' ; ', res%d - ref%d\n end if\n end subroutine testResult\n\n end subroutine utest\n#endif\nend module auto_diff\n\n#ifdef UTEST\nprogram tauto\n use auto_diff\n call utest\nend program tauto\n#endif\n", "meta": {"hexsha": "f010cb6c85c9cbf16830cd2dcbc2e470a5f597b2", "size": 27263, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "autodiff.f90", "max_stars_repo_name": "sgeard/autodiff", "max_stars_repo_head_hexsha": "2de76c2b5d896ddcdc2fc94489599df2083d9c8a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2020-10-27T19:34:16.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-17T13:36:48.000Z", "max_issues_repo_path": "autodiff.f90", "max_issues_repo_name": "sgeard/autodiff", "max_issues_repo_head_hexsha": "2de76c2b5d896ddcdc2fc94489599df2083d9c8a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-12-10T15:41:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-10T15:41:02.000Z", "max_forks_repo_path": "autodiff.f90", "max_forks_repo_name": "sgeard/autodiff", "max_forks_repo_head_hexsha": "2de76c2b5d896ddcdc2fc94489599df2083d9c8a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.9131293189, "max_line_length": 122, "alphanum_fraction": 0.5540842901, "num_tokens": 9168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.920789673717312, "lm_q2_score": 0.8558511414521922, "lm_q1q2_score": 0.7880588932883531}} {"text": "!> Author: Jabir Ali Ouassou\n!> Category: Foundation\n!>\n!> This file defines functions that perform some common calculus operations.\n\nmodule calculus_m\n use :: basic_m\ncontains\n\n !--------------------------------------------------------------------------------\n ! Specific implementations of the `mean` interface\n !--------------------------------------------------------------------------------\n\n pure function mean_array_re(x) result(r)\n !! Calculates the mean value of a real-valued array.\n real(wp), dimension(:), intent(in) :: x !! Real-valued array\n real(wp) :: r !! Mean value \n\n r = sum(x)/max(1,size(x))\n end function\n\n pure function mean_array_cx(x) result(r)\n !! Calculates the mean value of a complex-valued array.\n complex(wp), dimension(:), intent(in) :: x !! Complex-valued array\n complex(wp) :: r !! Mean value \n\n r = sum(x)/max(1,size(x))\n end function\n\n !--------------------------------------------------------------------------------\n ! Specific implementations of the `differentiate` interface\n !--------------------------------------------------------------------------------\n\n pure function differentiate_array_re(x, y) result(r)\n !! This function calculates the numerical derivative of an array y with respect to x, using a central difference approximation\n !! at the interior points and forward/backward difference approximations at the exterior points. Note that since all the three\n !! approaches yield two-point approximations of the derivative, the mesh spacing of x does not necessarily have to be uniform.\n real(wp), dimension(:), intent(in) :: x !! Variable x\n real(wp), dimension(size(x)), intent(in) :: y !! Function y(x)\n real(wp), dimension(size(x)) :: r !! Derivative dy/dx\n\n ! Differentiate using finite differences\n associate(n => size(x))\n r( 1 ) = (y( 1+1 ) - y( 1 ))/(x( 1+1 ) - x( 1 ))\n r(1+1:n-1) = (y(1+2:n) - y(1:n-2))/(x(1+2:n) - x(1:n-2))\n r( n ) = (y( n ) - y( n-1 ))/(x( n ) - x( n-1 ))\n end associate\n end function\n\n pure function differentiate_array_cx(x, y) result(r)\n !! Complex version of differentiate_array_re.\n real(wp), dimension(:), intent(in) :: x !! Variable x\n complex(wp), dimension(size(x)), intent(in) :: y !! Function y(x)\n complex(wp), dimension(size(x)) :: r !! Derivative dy/dx\n\n ! Differentiate using finite differences\n associate(n => size(x))\n r( 1 ) = (y( 1+1 ) - y( 1 ))/(x( 1+1 ) - x( 1 ))\n r(1+1:n-1) = (y(1+2:n) - y(1:n-2))/(x(1+2:n) - x(1:n-2))\n r( n ) = (y( n ) - y( n-1 ))/(x( n ) - x( n-1 ))\n end associate\n end function\n\n !--------------------------------------------------------------------------------\n ! Specific implementations of the `integrate` interface\n !--------------------------------------------------------------------------------\n\n pure function integrate_array_re(x, y) result(r)\n !! This function calculates the integral of an array y with respect to x using a trapezoid\n !! approximation. Note that the mesh spacing of x does not necessarily have to be uniform.\n real(wp), dimension(:), intent(in) :: x !! Variable x\n real(wp), dimension(size(x)), intent(in) :: y !! Function y(x)\n real(wp) :: r !! Integral ∫y(x)·dx\n\n ! Integrate using the trapezoidal rule\n associate(n => size(x))\n r = sum((y(1+1:n-0) + y(1+0:n-1))*(x(1+1:n-0) - x(1+0:n-1)))/2\n end associate\n end function\n\n pure function integrate_array_cx(x, y) result(r)\n !! Complex version of integrate_array_re.\n real(wp), dimension(:), intent(in) :: x !! Variable x\n complex(wp), dimension(size(x)), intent(in) :: y !! Function y(x)\n complex(wp) :: r !! Integral ∫y(x)·dx\n\n ! Integrate using the trapezoidal rule\n associate(n => size(x))\n r = sum((y(1+1:n-0) + y(1+0:n-1))*(x(1+1:n-0) - x(1+0:n-1)))/2\n end associate\n end function\n\n function integrate_range_re(x, y, a, b) result(r)\n !! This function constructs a piecewise hermitian cubic interpolation of an array y(x) based on\n !! discrete numerical data, and subsequently evaluates the integral of the interpolation in the\n !! range (a,b). Note that the mesh spacing of x does not necessarily have to be uniform.\n real(wp), dimension(:), intent(in) :: x !! Variable x\n real(wp), dimension(size(x)), intent(in) :: y !! Function y(x)\n real(wp), intent(in) :: a !! Left endpoint\n real(wp), intent(in) :: b !! Right endpoint\n real(wp) :: r !! Integral ∫y(x)·dx\n\n external :: dpchez\n real(wp), external :: dpchqa\n real(wp), dimension(size(x)) :: d\n integer :: err\n\n ! Create a PCHIP interpolation of the input data\n call dpchez(size(x), x, y, d, .false., 0, 0, err)\n\n ! Integrate the interpolation in the provided range\n r = dpchqa(size(x), x, y, d, a, b, err)\n end function\n\n function integrate_range_cx(x, y, a, b) result(r)\n !! Complex version of integrate_range_re.\n real(wp), dimension(:), intent(in) :: x !! Variable x\n complex(wp), dimension(size(x)), intent(in) :: y !! Function y(x)\n real(wp), intent(in) :: a !! Left endpoint\n real(wp), intent(in) :: b !! Right endpoint\n complex(wp) :: r !! Integral ∫y(x)·dx\n\n ! Integrate the real and imaginary parts separately\n r = cx( integrate_range_re(x, re(y), a, b),&\n integrate_range_re(x, im(y), a, b) )\n end function\n\n !--------------------------------------------------------------------------------\n ! Specific implementations of the `interpolate` interface\n !--------------------------------------------------------------------------------\n\n function interpolate_array_re(x, y, p) result(r)\n !! This function constructs a piecewise hermitian cubic interpolation of an array y(x) based on discrete numerical data,\n !! and evaluates the interpolation at points p. Note that the mesh spacing of x does not necessarily have to be uniform.\n real(wp), dimension(:), intent(in) :: x !! Variable x\n real(wp), dimension(size(x)), intent(in) :: y !! Function y(x)\n real(wp), dimension(:), intent(in) :: p !! Interpolation domain p\n real(wp), dimension(size(p)) :: r !! Interpolation result y(p)\n\n external :: dpchez\n external :: dpchfe\n real(wp), dimension(size(x)) :: d\n integer :: err\n\n ! Create a PCHIP interpolation of the input data\n call dpchez(size(x), x, y, d, .false., 0, 0, err)\n\n ! Extract the interpolated data at provided points\n call dpchfe(size(x), x, y, d, 1, .false., size(p), p, r, err)\n end function\n\n function interpolate_array_cx(x, y, p) result(r)\n !! Complex version of interpolate_array_re.\n real(wp), dimension(:), intent(in) :: x !! Variable x\n complex(wp), dimension(size(x)), intent(in) :: y !! Function y(x)\n real(wp), dimension(:), intent(in) :: p !! Interpolation domain p\n complex(wp), dimension(size(p)) :: r !! Interpolation result y(p)\n\n ! Interpolate the real and imaginary parts separately\n r = cx( interpolate_array_re(x, re(y), p),&\n interpolate_array_re(x, im(y), p) )\n end function\n\n function interpolate_point_re(x, y, p) result(r)\n !! Wrapper for interpolate_array_re that accepts scalar arguments.\n real(wp), dimension(:), intent(in) :: x !! Variable x\n real(wp), dimension(size(x)), intent(in) :: y !! Function y(x)\n real(wp), intent(in) :: p !! Interpolation point p\n real(wp) :: r !! Interpolation result y(p)\n real(wp), dimension(1) :: rs\n\n ! Perform the interpolation\n rs = interpolate_array_re(x, y, [p])\n\n ! Extract the scalar result\n r = rs(1)\n end function\n\n function interpolate_point_cx(x, y, p) result(r)\n !! Complex version of interpolate_point_re.\n real(wp), dimension(:), intent(in) :: x !! Variable x\n complex(wp), dimension(size(x)), intent(in) :: y !! Function y(x)\n real(wp), intent(in) :: p !! Interpolation point p\n complex(wp) :: r !! Interpolation result y(p)\n complex(wp), dimension(1) :: rs\n\n ! Perform the interpolation\n rs = cx( interpolate_array_re(x, re(y), [p]),&\n interpolate_array_re(x, im(y), [p]) )\n\n ! Extract the scalar result\n r = rs(1)\n end function\n\n pure function interpolate_point_matrix_re(x, y, p) result(r)\n !! Perform a Piecewise Cubic Hermitian Interpolation of a matrix function using Catmull-Rom splines.\n real(wp), dimension(:), intent(in) :: x !! Variable x\n real(wp), dimension(:,:,:), intent(in) :: y !! Function y(x)\n real(wp), intent(in) :: p !! Interpolation point p\n real(wp), dimension(size(y,1),size(y,2)) :: r !! Interpolation result y(p)\n\n integer :: n, m\n real(wp) :: t\n\n ! Find the nearest known point y(x)\n m = size(x)\n n = floor(p*(m-1) + 1);\n \n ! Perform the interpolation\n if (n <= 0) then\n ! Exterior: nearest extrapolation\n r = y(:,:,1)\n else if (n >= m) then\n ! Exterior: nearest extrapolation\n r = y(:,:,m)\n else\n ! Interior: spline interpolation\n t = (p - x(max(n,1)))/(x(min(n+1,m)) - x(max(n,1)))\n r = y(:,:,max(n-1,1)) * ( -0.5*t +1.0*t**2 -0.5*t**3) &\n + y(:,:,max(n-0,1)) * (+1.0 -2.5*t**2 +1.5*t**3) &\n + y(:,:,min(n+1,m)) * ( +0.5*t +2.0*t**2 -1.5*t**3) &\n + y(:,:,min(n+2,m)) * ( -0.5*t**2 +0.5*t**3) \n end if\n end function\n\n !--------------------------------------------------------------------------------\n ! Specific implementations of the `linspace` interface\n !--------------------------------------------------------------------------------\n\n pure subroutine linspace_array_re(array, first, last)\n !! Populates an existing array with elements from `first` to `last`, inclusive.\n real(wp), dimension(:), intent(out) :: array !! Output array to populate\n real(wp), intent(in) :: first !! Value of first element\n real(wp), intent(in) :: last !! Value of last element\n integer :: n\n\n do n=1,size(array)\n array(n) = first + ((last-first)*(n-1))/(size(array)-1)\n end do\n end subroutine\nend module\n", "meta": {"hexsha": "1bd034bbc0cc1304d7ed3faa807c2c6313632a02", "size": 10982, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/foundation/calculus.f", "max_stars_repo_name": "jabirali/NEUS", "max_stars_repo_head_hexsha": "f9e3f18a45c84272ebaafcb7b834eebf47acb9b8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-22T02:20:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-11T08:43:07.000Z", "max_issues_repo_path": "src/foundation/calculus.f", "max_issues_repo_name": "jabirali/NEUS", "max_issues_repo_head_hexsha": "f9e3f18a45c84272ebaafcb7b834eebf47acb9b8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/foundation/calculus.f", "max_forks_repo_name": "jabirali/NEUS", "max_forks_repo_head_hexsha": "f9e3f18a45c84272ebaafcb7b834eebf47acb9b8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-11T03:24:08.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-11T03:24:08.000Z", "avg_line_length": 45.3801652893, "max_line_length": 130, "alphanum_fraction": 0.5160262247, "num_tokens": 2823, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.940789754239075, "lm_q2_score": 0.8376199694135333, "lm_q1q2_score": 0.7880242851702995}} {"text": "PROGRAM F044\n\n ! Copyright 2021 Melwyn Francis Carlo\n\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: MAX_N = 5E3\n\n INTEGER :: MIN_PD = 1E7\n\n INTEGER :: I, J, P1, P2, P1PP2, P1MP2\n\n REAL :: SQRT_TERM\n\n DO I = 1, MAX_N\n\n P1 = FLOOR(0.5 * I * ((3 * I) - 1))\n\n DO J = (I + 1), MAX_N\n\n P2 = FLOOR(0.5 * J * ((3 * J) - 1))\n\n P1PP2 = P1 + P2\n\n SQRT_TERM = SQRT(1.0E0 + (24.0E0 * REAL(P1PP2)))\n\n IF (SQRT_TERM - INT(SQRT_TERM) > 0) CYCLE\n\n IF (MOD((INT(SQRT_TERM) + 1), 6) /= 0) CYCLE\n\n P1MP2 = P2 - P1\n\n SQRT_TERM = SQRT(1.0E0 + (24.0E0 * REAL(P1MP2)))\n\n IF (SQRT_TERM - INT(SQRT_TERM) > 0) CYCLE\n\n IF (MOD((INT(SQRT_TERM) + 1), 6) == 0) THEN\n IF (P1MP2 < MIN_PD) MIN_PD = P1MP2\n END IF\n\n END DO\n\n END DO\n\n PRINT ('(I0)'), MIN_PD\n\nEND PROGRAM F044\n", "meta": {"hexsha": "cd3601c6c630feba667ab77a631f38050ca84a5b", "size": 909, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "problems/044/044.f90", "max_stars_repo_name": "melwyncarlo/ProjectEuler", "max_stars_repo_head_hexsha": "c4d30ed528ae6de82232f3d2044d608c6e8f1c37", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "problems/044/044.f90", "max_issues_repo_name": "melwyncarlo/ProjectEuler", "max_issues_repo_head_hexsha": "c4d30ed528ae6de82232f3d2044d608c6e8f1c37", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "problems/044/044.f90", "max_forks_repo_name": "melwyncarlo/ProjectEuler", "max_forks_repo_head_hexsha": "c4d30ed528ae6de82232f3d2044d608c6e8f1c37", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.9375, "max_line_length": 60, "alphanum_fraction": 0.4708470847, "num_tokens": 356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789548, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7880242761527745}} {"text": "function norm(A,nrm_type) result(nrm)\n! Returns matrix norm of A. Only Supports 1 norm and Inf norm\n! === Parameters ===\n! A - (matrix)\n! nrm_type - (integer) nrm_type=1 for one norm and nrm_type=-1 for Inf norm\n! === Output ===\n! nrm - (double) matrix norm\ncomplex(kind=8), intent(in) :: A(:,:)\ninteger, intent(in) :: nrm_type\nreal(kind=8) :: nrm, nrm_canidate\ninteger :: i,j,d1,d2\nd1 = size(A,1)\nd2 = size(A,2)\nnrm = 0.d0\nif(nrm_type == -1) then ! Infinity nrm\n do i=1,d1\n nrm_canidate = 0.d0\n do j=1,d2\n nrm_canidate = nrm_canidate + abs(A(i,j))\n enddo\n if(nrm_canidate > nrm) then\n nrm = nrm_canidate\n endif\n enddo\nelseif(nrm_type == 1) then ! 1 nrm\n do j=1,d2\n nrm_canidate = 0.d0\n do i=1,d1\n nrm_canidate = nrm_canidate + abs(A(i,j))\n enddo\n if(nrm_canidate > nrm) then\n nrm = nrm_canidate\n endif\n enddo\nendif\nend function norm", "meta": {"hexsha": "6ddef0351f60ca04b15be1cc56deb50ce0f4cc35", "size": 1004, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "partitioned/fortran/tools/functions/norm.f90", "max_stars_repo_name": "buvoli/epbm", "max_stars_repo_head_hexsha": "32ffe175a2e3456799ebc3e6feeb085ff5c83f81", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "partitioned/fortran/tools/functions/norm.f90", "max_issues_repo_name": "buvoli/epbm", "max_issues_repo_head_hexsha": "32ffe175a2e3456799ebc3e6feeb085ff5c83f81", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "partitioned/fortran/tools/functions/norm.f90", "max_forks_repo_name": "buvoli/epbm", "max_forks_repo_head_hexsha": "32ffe175a2e3456799ebc3e6feeb085ff5c83f81", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.8888888889, "max_line_length": 76, "alphanum_fraction": 0.5607569721, "num_tokens": 351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897459384733, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7880242744040623}} {"text": "!Autor: Claudio Iván Esparza Castañeda\n!Título: Newton-Raphson simple\n!Descripción: Calcula las raíces de una función por medio del método de Newton-Raphson\n!Fecha: 17/03/2020\n \n\nProgram newrap\n implicit none\n REAL::e, er, x, y, f, fp, xe\n INTEGER::i\n CALL graf1()\n WRITE(*, *) \"Valor inicial\" !Preguntar final del intervalo\n READ(*, *) x !Ingresar final del intervalo\n WRITE(*, *) \"Error esperado\" !Preguntar el error\n READ(*, *) er !Ingresar el error\n i=0 !Inicializar contador de ciclos\n do\n i=i+1 !Añadir uno al contador\n xe=x !Asignar x anterior\n x=x-f(x)/fp(x)\n if (x .NE. 0) then !Validación del intervalo\n e=abs((x-xe)/x)*100 !Cálculo del error\n end if\n if (e b) then\n a = a - b\n end if\n end do\n print *, n, p, a\n end do\n end do\n\nend program greatest_common_divisor\n", "meta": {"hexsha": "922ae8871c830772da5be2bf5cc589b03b5768dd", "size": 518, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "hands-on/session_01/exercise_03.f90", "max_stars_repo_name": "gjbex/FortranForProgrammers", "max_stars_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-15T14:56:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-15T14:56:20.000Z", "max_issues_repo_path": "hands-on/session_01/exercise_03.f90", "max_issues_repo_name": "gjbex/FortranForProgrammers", "max_issues_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hands-on/session_01/exercise_03.f90", "max_forks_repo_name": "gjbex/FortranForProgrammers", "max_forks_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5454545455, "max_line_length": 51, "alphanum_fraction": 0.4247104247, "num_tokens": 141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.8633916117313211, "lm_q1q2_score": 0.7877897271961247}} {"text": "program main\n ! Default\n implicit none\n\n integer(4), parameter :: grid_size = 20\n integer(8) :: nvalid\n\n ! compute combinatorics\n nvalid = two_n_choose_n(grid_size)\n write(*,*) \"number of valid paths: \",nvalid\n\n\ncontains\n\n\n pure function two_n_choose_n(n)\n ! Default\n implicit none\n\n ! Function arguments\n integer(4), intent(in) :: n\n integer(8) :: two_n_choose_n\n\n ! Local variables\n integer(4) :: i\n\n two_n_choose_n = 1\n do i=1,n\n two_n_choose_n = two_n_choose_n * (n+i)/i\n enddo\n\n return\n end function two_n_choose_n\n\n\nend program main\n", "meta": {"hexsha": "c43aefba3b7ca1b86b0ffc964808d3d0ac3706dd", "size": 599, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/problem15/problem15.f90", "max_stars_repo_name": "plaplant/Project_Euler", "max_stars_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/problem15/problem15.f90", "max_issues_repo_name": "plaplant/Project_Euler", "max_issues_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/problem15/problem15.f90", "max_forks_repo_name": "plaplant/Project_Euler", "max_forks_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-01-07T21:43:45.000Z", "max_forks_repo_forks_event_max_datetime": "2017-01-07T21:43:45.000Z", "avg_line_length": 16.1891891892, "max_line_length": 48, "alphanum_fraction": 0.6410684474, "num_tokens": 178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.938124016006303, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.787774604010912}} {"text": "C Matrix multiplicaiton, version with call to MATMUL\n\n PROGRAM MAIN \n PARAMETER (L=200, M=200, N=200)\n REAL Z(L,N), X(L,M), Y(M,N)\n\nC Initialization\n\n DO I = 1,L\n DO J = 1,M\n X(I,J) = I\n ENDDO\n ENDDO\n\n DO J = 1,M\n DO K = 1,N\n Y(J,K) = J\n ENDDO\n ENDDO\n \n CALL MATMUL(Z,X,Y,L,M,N)\n \n END\n\n SUBROUTINE MATMUL(Z,X,Y,L,M,N)\n REAL Z(L,N), X(L,M), Y(M,N)\n \n \n DO I=1,L\n DO K=1,N\n Z(I,K) = 0.\n DO J=1,M\n Z(I,K) = Z(I,K) + X(I,J)*Y(J,K)\n ENDDO\n ENDDO\n ENDDO\n END\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "033a6f7c3579026668ba61e8bb60ceb6b1513e67", "size": 684, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/ArrayBoundCheck/TD_Matrixmultiply.f", "max_stars_repo_name": "DVSR1966/par4all", "max_stars_repo_head_hexsha": "86b33ca9da736e832b568c5637a2381f360f1996", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 51, "max_stars_repo_stars_event_min_datetime": "2015-01-31T01:51:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T02:01:50.000Z", "max_issues_repo_path": "packages/PIPS/validation/ArrayBoundCheck/TD_Matrixmultiply.f", "max_issues_repo_name": "DVSR1966/par4all", "max_issues_repo_head_hexsha": "86b33ca9da736e832b568c5637a2381f360f1996", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2017-05-29T09:29:00.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-11T16:01:39.000Z", "max_forks_repo_path": "packages/PIPS/validation/ArrayBoundCheck/TD_Matrixmultiply.f", "max_forks_repo_name": "DVSR1966/par4all", "max_forks_repo_head_hexsha": "86b33ca9da736e832b568c5637a2381f360f1996", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-03-26T08:05:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T02:01:51.000Z", "avg_line_length": 12.0, "max_line_length": 56, "alphanum_fraction": 0.3728070175, "num_tokens": 235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476800298183, "lm_q2_score": 0.8976952832120991, "lm_q1q2_score": 0.7877067847557239}} {"text": "SUBROUTINE colinearity_angle (r_sat, v_sat, r_sun, epsilon_angle, epsilon_dot)\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: colinearity_angle.f90\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Computation of the colinearity angle between the orbital plane and the Sun vector \r\n! ----------------------------------------------------------------------\r\n! Input arguments:\r\n! - r_sat: \t\t\tSatellite position vector (m) \r\n! - v_sat: \t\t\tSatellite velocity vector (m/sec)\r\n! - r_sun:\t\t\tSun position vector (m)\r\n!\r\n! Output arguments:\r\n! - epsilon_angle:\t\tColinearity angle in degrees\r\n! - epsilon_angle:\t\tColinearity angle partial derivative w.r.t. time \r\n! ----------------------------------------------------------------------\r\n! Author :\tDr. Thomas Papanikolaou at Geoscience Australia\r\n! Created:\t24 April 2020\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n USE mdl_precision\r\n USE mdl_num\r\n IMPLICIT NONE\r\n\t \r\n! ----------------------------------------------------------------------\r\n! Dummy arguments declaration\r\n! ----------------------------------------------------------------------\r\n! IN\r\n REAL (KIND = prec_d), INTENT(IN) :: r_sat(3), v_sat(3), r_sun(3)\r\n! OUT\r\n REAL (KIND = prec_d), INTENT(OUT) :: epsilon_angle, epsilon_dot\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Local variables declaration\r\n! ----------------------------------------------------------------------\r\n REAL (KIND = prec_d) :: Xsat(3), dXsat(3), Xsun(3)\r\n REAL (KIND = prec_q) :: r_norm, v_norm\r\n REAL (KIND = prec_q) :: rr_dot, vv_dot\r\n REAL (KIND = prec_q) :: h_angmom(3), h_dot, h_norm\r\n REAL (KIND = prec_q) :: er(3), et(3), en(3) \r\n\t REAL (KIND = prec_d) :: sn_dot, rn_cross(3), srn_dot, x_cross(3), y_cross(3) \r\n\t REAL (KIND = prec_d) :: ry_dot, vy_dot\r\n\t REAL (KIND = prec_d) :: acos_ry\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Unit Vectors\r\n! ----------------------------------------------------------------------\r\n! Xsat:\t\tSatellite position unit vector\r\n Xsat = (1D0 / sqrt(r_sat(1)**2 + r_sat(2)**2 + r_sat(3)**2) ) * r_sat\r\n\t \r\n! dXsat:\tSatellite Velocity unit vector\r\n dXsat = (1D0 / sqrt(v_sat(1)**2 + v_sat(2)**2 + v_sat(3)**2) ) * v_sat\r\n\t \r\n! Xsun:\t\tSun position unit vector\r\n Xsun = (1D0 / sqrt(r_sun(1)**2 + r_sun(2)**2 + r_sun(3)**2) ) * r_sun\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Orbit normal vector (cross-track)\r\n! ----------------------------------------------------------------------\r\n! cross product of r,v : angular momentum per unit mass\r\n CALL productcross(r_sat, v_sat, h_angmom)\r\n CALL productdot(h_angmom, h_angmom, h_dot)\r\n h_norm = sqrt(h_dot)\r\n\r\n! Cross-track or normal component\r\n en = (1D0 / h_norm) * h_angmom\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Colinearity angle: epsilon\r\n! ----------------------------------------------------------------------\r\nCALL productcross(en, Xsun, x_cross)\r\n\r\nCALL productcross(en, x_cross, y_cross)\r\n\r\nCALL productdot(Xsat, y_cross, ry_dot)\r\n\r\nCALL productdot(dXsat, y_cross, vy_dot)\r\n\r\nacos_ry = ACOS( ry_dot ) * (180.0D0 / PI_global)\r\n\r\n! Epsilon angle and partial derivative of epsilon w.r.t. time\r\nIF ( acos_ry <= 90.0D0 ) THEN\r\n\tepsilon_angle = acos_ry\t\r\n\tepsilon_dot = (-1.0D0 / sin(epsilon_angle) ) * vy_dot \r\n\t\r\nELSE\r\n\tepsilon_angle = 180.0D0 - acos_ry\r\n\tepsilon_dot = (1.0D0 / sin(epsilon_angle) ) * vy_dot \r\n\t\r\nEND IF \r\n\r\n\r\nEND\r\n", "meta": {"hexsha": "c04252005d354e0b5583a26d38d566bc8f5ee609", "size": 3880, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/colinearity_angle.f03", "max_stars_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_stars_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2021-07-08T23:35:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:17:58.000Z", "max_issues_repo_path": "src/fortran/colinearity_angle.f03", "max_issues_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_issues_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-09-27T14:27:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T23:50:02.000Z", "max_forks_repo_path": "src/fortran/colinearity_angle.f03", "max_forks_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_forks_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2021-07-12T05:42:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T15:15:34.000Z", "avg_line_length": 38.8, "max_line_length": 86, "alphanum_fraction": 0.4242268041, "num_tokens": 907, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741268224331, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7875042694376587}} {"text": "module matrix_multiplier_mod\n use,intrinsic :: iso_fortran_env\n implicit none\ncontains\n function matmul_mod(a,b,md) result(ret)\n integer(int64),intent(in):: a(:,:),b(:,:),md\n integer(int64),allocatable:: ret(:,:)\n integer(int32):: i,j,k,ni,nj,nk\n \n ni = size(a(1,:))\n nj = size(b(:,1))\n nk = size(a(:,1))\n allocate(ret(ni,nj), source=0_int64)\n \n do i=1,ni\n do j=1,nj\n do k=1,nk\n ret(j,i) = mod(ret(j,i)+mod(a(k,i)*b(j,k),md),md)\n end do\n end do\n end do\n end function\n \n \n function matmuler(a,e,md) result(ret)\n integer(int64),intent(in):: a(:,:),md\n integer(int64),value:: e\n integer(int64), allocatable:: ma(:,:), ret(:,:)\n integer(int32):: i\n \n \n allocate(ma, source=a)\n allocate(ret, mold=a)\n ret(:,:) = 0\n do i=1,size(ret(:,1))\n ret(i,i) = 1\n end do\n do while(e>0)\n if (btest(e,0)) then\n ret = matmul_mod(ret, ma, md)\n end if\n e = shiftr(e,1)\n ma = matmul_mod(ma,ma, md)\n end do\n end function\nend module", "meta": {"hexsha": "e3ec4aa0cd56c3323427267c850c673d1af3b92c", "size": 1206, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/matrix_multiplier.f90", "max_stars_repo_name": "ohtorilab/fortran_lib", "max_stars_repo_head_hexsha": "e3551a0730a91f79e8e09796f147f761b2df6fc1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-03T16:05:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-03T16:05:57.000Z", "max_issues_repo_path": "src/matrix_multiplier.f90", "max_issues_repo_name": "ohtorilab/fortran_lib", "max_issues_repo_head_hexsha": "e3551a0730a91f79e8e09796f147f761b2df6fc1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-18T11:40:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-18T11:40:03.000Z", "max_forks_repo_path": "src/matrix_multiplier.f90", "max_forks_repo_name": "ohtorilab/fortran_lib", "max_forks_repo_head_hexsha": "e3551a0730a91f79e8e09796f147f761b2df6fc1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-12T01:06:14.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-12T01:06:14.000Z", "avg_line_length": 26.2173913043, "max_line_length": 69, "alphanum_fraction": 0.4709784411, "num_tokens": 354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947055100816, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7874873364087387}} {"text": "! cholesky_d.f -*-f90-*-\n! Using Cholesky decomposition, cholesky_d.f solve a linear equation Ax=b,\n! where A is a n by n positive definite real symmetric matrix, x and b are\n! real*8 vectors length n.\n!\n! Time-stamp: <2015-06-25 18:05:47 takeshi>\n! Author: Takeshi NISHIMATSU\n! Licence: GPLv3\n!\n! [1] A = G tG, where G is a lower triangular matrix and tG is transpose of G.\n! [2] Solve Gy=b with forward elimination\n! [3] Solve tGx=y with backward elimination\n!\n! Reference: Taketomo MITSUI: Solvers for linear equations [in Japanese]\n! http://www2.math.human.nagoya-u.ac.jp/~mitsui/syllabi/sis/info_math4_chap2.pdf\n!\n! Comment: This Cholesky decomposition is used in src/elastic.F and\n! src/optimize-inho-strain.F of feram http://loto.sourceforge.net/feram/ .\n!!\n subroutine solve(nn,n, G, b)\n implicit none\n integer, intent(in) :: n,nn\n real*8, intent(in) :: G(nn,nn)\n real*8, intent(out) :: b(nn)\n real*8 :: tmp\n integer :: i,j\n\n ! [2]\n do i = 1, n\n tmp = 0.0d0\n do j = 1, i-1\n tmp = tmp + G(i,j)*b(j)\n end do\n b(i) = (b(i)-tmp)/G(i,i)\n end do\n\n ! [3]\n do i = n, 1, -1\n tmp = 0.0d0\n do j = i+1, n\n tmp = tmp + b(j)*G(j,i)\n end do\n b(i) = (b(i)-tmp)/G(i,i)\n end do\n\n\n end subroutine\n", "meta": {"hexsha": "5ec8c5d837616f250dae1515e1504cf372e983ea", "size": 1414, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/2d/ag_ho/solve.f", "max_stars_repo_name": "mjberger/ho_amrclaw_amrcart", "max_stars_repo_head_hexsha": "0e0d37dda52b8c813f7fc4bd7e61c5fdb33b0ada", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-06T23:14:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-06T23:14:49.000Z", "max_issues_repo_path": "src/2d/ag_ho/solve.f", "max_issues_repo_name": "mjberger/ho_amrclaw_amrcart", "max_issues_repo_head_hexsha": "0e0d37dda52b8c813f7fc4bd7e61c5fdb33b0ada", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/2d/ag_ho/solve.f", "max_forks_repo_name": "mjberger/ho_amrclaw_amrcart", "max_forks_repo_head_hexsha": "0e0d37dda52b8c813f7fc4bd7e61c5fdb33b0ada", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.4583333333, "max_line_length": 91, "alphanum_fraction": 0.5509193777, "num_tokens": 460, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065458, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7874873317931624}} {"text": "module pdflib\n\n! Code to generate various probability distribution functions\n! and get random samples from them, including beta, binomial, chi, exponential, gamma,\n! inverse chi, inverse gamma, multinomial, normal, scaled inverse chi, and uniform. \n!\n! FORTRAN77 version of some routines by Barry Brown, James Lovato\n! Original and adapted FORTRAN90 code by John Burkardt (see individual \n! subroutines for details)\n!\n! Shaped into a module for FERRE by Carlos Allende Prieto\n! November 2017\n\n\nuse ranlib\n\nimplicit none\n\npublic\n\ncontains \n\nfunction i4_binomial_pdf ( n, p, k )\n\n!*****************************************************************************80\n!\n!! I4_BINOMIAL_PDF evaluates the binomial PDF.\n!\n! Discussion:\n!\n! pdf(n,p,k) = C(n,k) p^k (1-p)^(n-k)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 09 June 2013\n!\n! Author:\n!\n! John Burkardt.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of binomial trials.\n! 0 < N.\n!\n! Input, real ( kind = 8 ) P, the probability of a success in one trial.\n!\n! Input, integer ( kind = 4 ) K, the number of successes.\n!\n! Output, real ( kind = 8 ) I4_BINOMIAL_PDF, the probability of K successes\n! in N trials with a per-trial success probability of P.\n!\n implicit none\n\n real ( kind = 8 ) i4_binomial_pdf\n integer ( kind = 4 ) k\n integer ( kind = 4 ) n\n real ( kind = 8 ) p\n! real ( kind = 8 ) r8_choose\n real ( kind = 8 ) value\n\n if ( k < 0 ) then\n value = 0.0D+00\n else if ( k <= n ) then\n value = r8_choose ( n, k ) * p ** k * ( 1.0D+00 - p ) ** k\n else\n value = 0.0D+00\n end if\n\n i4_binomial_pdf = value\n\n return\nend function i4_binomial_pdf\n\n\nfunction i4_binomial_sample ( n, pp )\n\n!*****************************************************************************80\n!\n!! I4_BINOMIAL_SAMPLE generates a binomial random deviate.\n!\n! Discussion:\n!\n! This procedure generates a single random deviate from a binomial\n! distribution whose number of trials is N and whose\n! probability of an event in each trial is P.\n!\n! The previous version of this program relied on the assumption that\n! local memory would be preserved between calls. It set up data\n! one time to be preserved for use over multiple calls. In the\n! interests of portability, this assumption has been removed, and\n! the \"setup\" data is recomputed on every call.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 April 2013\n!\n! Author:\n!\n! Original FORTRAN77 version by Barry Brown, James Lovato.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! Voratas Kachitvichyanukul, Bruce Schmeiser,\n! Binomial Random Variate Generation,\n! Communications of the ACM,\n! Volume 31, Number 2, February 1988, pages 216-222.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of binomial trials, from which a\n! random deviate will be generated.\n! 0 < N.\n!\n! Input, real ( kind = 8 ) PP, the probability of an event in each trial of\n! the binomial distribution from which a random deviate is to be generated.\n! 0.0 < PP < 1.0.\n!\n! Output, integer ( kind = 4 ) I4_BINOMIAL_SAMPLE, a random deviate from the\n! distribution.\n!\n implicit none\n\n real ( kind = 8 ) al\n real ( kind = 8 ) alv\n real ( kind = 8 ) amaxp\n real ( kind = 8 ) c\n real ( kind = 8 ) f\n real ( kind = 8 ) f1\n real ( kind = 8 ) f2\n real ( kind = 8 ) ffm\n real ( kind = 8 ) fm\n real ( kind = 8 ) g\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i4_binomial_sample\n integer ( kind = 4 ) ix\n integer ( kind = 4 ) ix1\n integer ( kind = 4 ) k\n integer ( kind = 4 ) m\n integer ( kind = 4 ) mp\n real ( kind = 8 ) pp\n integer ( kind = 4 ) n\n real ( kind = 8 ) p\n real ( kind = 8 ) p1\n real ( kind = 8 ) p2\n real ( kind = 8 ) p3\n real ( kind = 8 ) p4\n real ( kind = 8 ) q\n real ( kind = 8 ) qn\n real ( kind = 8 ) r\n! real ( kind = 8 ) r8_uniform_01_sample\n real ( kind = 8 ) t\n real ( kind = 8 ) u\n real ( kind = 8 ) v\n real ( kind = 8 ) w\n real ( kind = 8 ) w2\n real ( kind = 8 ) x\n real ( kind = 8 ) x1\n real ( kind = 8 ) x2\n real ( kind = 8 ) xl\n real ( kind = 8 ) xll\n real ( kind = 8 ) xlr\n real ( kind = 8 ) xm\n real ( kind = 8 ) xnp\n real ( kind = 8 ) xnpq\n real ( kind = 8 ) xr\n real ( kind = 8 ) ynorm\n real ( kind = 8 ) z\n real ( kind = 8 ) z2\n\n if ( pp <= 0.0D+00 .or. 1.0D+00 <= pp ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'I4_BINOMIAL_SAMPLE - Fatal error!'\n write ( *, '(a)' ) ' PP is out of range.'\n stop 1\n end if\n\n p = min ( pp, 1.0D+00 - pp )\n q = 1.0D+00 - p\n xnp = real ( n, kind = 8 ) * p\n\n if ( xnp < 30.0D+00 ) then\n\n qn = q ** n\n r = p / q\n g = r * real ( n + 1, kind = 8 )\n\n do\n\n ix = 0\n f = qn\n u = r8_uniform_01_sample ( )\n\n do\n\n if ( u < f ) then\n if ( 0.5D+00 < pp ) then\n ix = n - ix\n end if\n i4_binomial_sample = ix\n return\n end if\n\n if ( 110 < ix ) then\n exit\n end if\n\n u = u - f\n ix = ix + 1\n f = f * ( g / real ( ix, kind = 8 ) - r )\n\n end do\n\n end do\n\n end if\n\n ffm = xnp + p\n m = ffm\n fm = m\n xnpq = xnp * q\n p1 = int ( 2.195D+00 * sqrt ( xnpq ) - 4.6D+00 * q ) + 0.5D+00\n xm = fm + 0.5D+00\n xl = xm - p1\n xr = xm + p1\n c = 0.134D+00 + 20.5D+00 / ( 15.3D+00 + fm )\n al = ( ffm - xl ) / ( ffm - xl * p )\n xll = al * ( 1.0D+00 + 0.5D+00 * al )\n al = ( xr - ffm ) / ( xr * q )\n xlr = al * ( 1.0D+00 + 0.5D+00 * al )\n p2 = p1 * ( 1.0D+00 + c + c )\n p3 = p2 + c / xll\n p4 = p3 + c / xlr\n!\n! Generate a variate.\n!\n do\n\n u = r8_uniform_01_sample ( ) * p4\n v = r8_uniform_01_sample ( )\n!\n! Triangle\n!\n if ( u < p1 ) then\n ix = xm - p1 * v + u\n if ( 0.5D+00 < pp ) then\n ix = n - ix\n end if\n i4_binomial_sample = ix\n return\n end if\n!\n! Parallelogram\n!\n if ( u <= p2 ) then\n\n x = xl + ( u - p1 ) / c\n v = v * c + 1.0D+00 - abs ( xm - x ) / p1\n\n if ( v <= 0.0D+00 .or. 1.0D+00 < v ) then\n cycle\n end if\n\n ix = x\n\n else if ( u <= p3 ) then\n\n ix = xl + log ( v ) / xll\n if ( ix < 0 ) then\n cycle\n end if\n v = v * ( u - p2 ) * xll\n\n else\n\n ix = xr - log ( v ) / xlr\n if ( n < ix ) then\n cycle\n end if\n v = v * ( u - p3 ) * xlr\n\n end if\n\n k = abs ( ix - m )\n\n if ( k <= 20 .or. xnpq / 2.0D+00 - 1.0D+00 <= k ) then\n\n f = 1.0D+00\n r = p / q\n g = real ( n + 1, kind = 8 ) * r\n\n if ( m < ix ) then\n mp = m + 1\n do i = m + 1, ix\n f = f * ( g / i - r )\n end do\n else if ( ix < m ) then\n ix1 = ix + 1\n do i = ix + 1, m\n f = f / ( g / real ( i, kind = 8 ) - r )\n end do\n end if\n\n if ( v <= f ) then\n if ( 0.5D+00 < pp ) then\n ix = n - ix\n end if\n i4_binomial_sample = ix\n return\n end if\n\n else\n\n amaxp = ( k / xnpq ) * ( ( k * ( k / 3.0D+00 &\n + 0.625D+00 ) + 0.1666666666666D+00 ) / xnpq + 0.5D+00 )\n ynorm = - real ( k * k, kind = 8 ) / ( 2.0D+00 * xnpq )\n alv = log ( v )\n\n if ( alv < ynorm - amaxp ) then\n if ( 0.5D+00 < pp ) then\n ix = n - ix\n end if\n i4_binomial_sample = ix\n return\n end if\n\n if ( ynorm + amaxp < alv ) then\n cycle\n end if\n\n x1 = real ( ix + 1, kind = 8 )\n f1 = fm + 1.0D+00\n z = real ( n + 1, kind = 8 ) - fm\n w = real ( n - ix + 1, kind = 8 )\n z2 = z * z\n x2 = x1 * x1\n f2 = f1 * f1\n w2 = w * w\n\n t = xm * log ( f1 / x1 ) + ( n - m + 0.5D+00 ) * log ( z / w ) &\n + real ( ix - m, kind = 8 ) * log ( w * p / ( x1 * q )) &\n + ( 13860.0D+00 - ( 462.0D+00 - ( 132.0D+00 - ( 99.0D+00 - 140.0D+00 &\n / f2 ) / f2 ) / f2 ) / f2 ) / f1 / 166320.0D+00 &\n + ( 13860.0D+00 - ( 462.0D+00 - ( 132.0D+00 - ( 99.0D+00 - 140.0D+00 &\n / z2 ) / z2 ) / z2 ) / z2 ) / z / 166320.0D+00 &\n + ( 13860.0D+00 - ( 462.0D+00 - ( 132.0D+00 - ( 99.0D+00 - 140.0D+00 &\n / x2 ) / x2 ) / x2 ) / x2 ) / x1 / 166320.0D+00 &\n + ( 13860.0D+00 - ( 462.0D+00 - ( 132.0D+00 - ( 99.0D+00 - 140.0D+00 &\n / w2 ) / w2 ) / w2 ) / w2 ) / w / 166320.0D+00\n\n if ( alv <= t ) then\n if ( 0.5D+00 < pp ) then\n ix = n - ix\n end if\n i4_binomial_sample = ix\n return\n end if\n\n end if\n\n end do\n\n return\nend function i4_binomial_sample\n\n\nfunction i4vec_multinomial_pdf ( n, p, m, x )\n\n!*****************************************************************************80\n!\n!! I4VEC_MULTINOMIAL_PDF evaluates the multinomial PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 June 2013\n!\n! Author:\n!\n! John Burkardt.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of trials.\n!\n! Input, real ( kind = 8 ) P(M), the probability of each outcome\n! on any single trial.\n!\n! Input, integer ( kind = 4 ) M, the number of possible outcomes\n! of a single trial.\n!\n! Input, integer ( kind = 4 ) X(M), the results of N trials,\n! with X(I) the number of times outcome I occurred.\n!\n! Output, real ( kind = 8 ) I4VEC_MULTINOMIAL_PDF, the probability\n! density function evaluated at X.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) bot\n integer ( kind = 4 ) c\n integer ( kind = 4 ) i\n real ( kind = 8 ) i4vec_multinomial_pdf\n integer ( kind = 4 ) j\n real ( kind = 8 ) p(m)\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) top\n integer ( kind = 4 ) x(m)\n!\n! The combinatorial coefficient is an integer.\n!\n c = 1\n top = n\n do i = 1, m\n bot = 1\n do j = 1, x(i)\n c = ( c * top ) / bot\n top = top - 1\n bot = bot + 1\n end do\n end do\n\n pdf = real ( c, kind = 8 )\n do i = 1, m\n pdf = pdf * p(i) ** x(i)\n end do\n\n i4vec_multinomial_pdf = pdf\n\n return\nend function i4vec_multinomial_pdf\n\n\nsubroutine i4vec_multinomial_sample ( n, p, ncat, ix )\n\n!*****************************************************************************80\n!\n!! I4VEC_MULTINOMIAL_SAMPLE generates a multinomial random deviate.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 March 2013\n!\n! Author:\n!\n! Original FORTRAN77 version by Barry Brown, James Lovato.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! Luc Devroye,\n! Non-Uniform Random Variate Generation,\n! Springer, 1986,\n! ISBN: 0387963057,\n! LC: QA274.D48.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of trials.\n!\n! Input, real ( kind = 8 ) P(NCAT). P(I) is the probability that an event\n! will be classified into category I. Thus, each P(I) must be between \n! 0.0 and 1.0, and the P's must sum to 1.\n!\n! Input, integer ( kind = 4 ) NCAT, the number of possible outcomes\n! of a single trial.\n!\n! Output, integer ( kind = 4 ) IX(NCAT), a random observation from \n! the multinomial distribution. All IX(i) will be nonnegative and their \n! sum will be N.\n!\n implicit none\n\n integer ( kind = 4 ) n\n integer ( kind = 4 ) ncat\n\n integer ( kind = 4 ) i\n! integer ( kind = 4 ) i4_binomial_sample\n integer ( kind = 4 ) icat\n integer ( kind = 4 ) ix(ncat)\n integer ( kind = 4 ) ntot\n real ( kind = 8 ) p(ncat)\n real ( kind = 8 ) prob\n real ( kind = 8 ) ptot\n\n if ( n < 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'I4VEC_MULTINOMIAL_SAMPLE - Fatal error!'\n write ( *, '(a)' ) ' N < 0'\n stop 1\n end if\n\n if ( ncat <= 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'I4VEC_MULTINOMIAL_SAMPLE - Fatal error!'\n write ( *, '(a)' ) ' NCAT <= 1'\n stop 1\n end if\n\n do i = 1, ncat\n\n if ( p(i) < 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'I4VEC_MULTINOMIAL_SAMPLE - Fatal error!'\n write ( *, '(a)' ) ' Some P(i) < 0.'\n stop 1\n end if\n\n if ( 1.0D+00 < p(i) ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'I4VEC_MULTINOMIAL_SAMPLE - Fatal error!'\n write ( *, '(a)' ) ' Some 1 < P(i).'\n stop 1\n end if\n\n end do\n!\n! Initialize variables.\n!\n ntot = n\n ptot = 1.0D+00\n do i = 1, ncat\n ix(i) = 0\n end do\n!\n! Generate the observation.\n!\n do icat = 1, ncat - 1\n prob = p(icat) / ptot\n ix(icat) = i4_binomial_sample ( ntot, prob )\n ntot = ntot - ix(icat)\n if ( ntot <= 0 ) then\n return\n end if\n ptot = ptot - p(icat)\n end do\n\n ix(ncat) = ntot\n\n return\nend subroutine i4vec_multinomial_sample\n\n\nfunction r8_beta_pdf ( alpha, beta, rval )\n\n!*****************************************************************************80\n!\n!! R8_BETA_PDF evaluates the PDF of a beta distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 July 2015\n!\n! Author:\n!\n! Original FORTRAN90 version by Guannan Zhang.\n! This version by John Burkardt.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) ALPHA, BETA, shape parameters.\n! 0.0 < ALPHA, BETA.\n!\n! Input, real ( kind = 8 ) RVAL, the point where the PDF is evaluated.\n!\n! Output, real ( kind = 8 ) R8_BETA_PDF, the value of the PDF at RVAL.\n!\n implicit none\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ) beta\n real ( kind = 8 ) r8_beta_pdf\n! real ( kind = 8 ) r8_gamma_log\n real ( kind = 8 ) rval\n real ( kind = 8 ) temp\n\n if ( alpha <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_BETA_PDF - Fatal error!'\n write ( *, '(a)' ) ' Parameter ALPHA is not positive.'\n stop 1\n end if\n\n if ( beta <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_BETA_PDF - Fatal error!'\n write ( *, '(a)' ) ' Parameter BETA is not positive.'\n stop 1\n end if\n\n if ( rval <= 0.0D+00 .or. 1.0D+00 <= rval ) then\n\n r8_beta_pdf = 0.0D+00\n\n else\n\n temp = r8_gamma_log ( alpha + beta ) - r8_gamma_log ( alpha ) &\n - r8_gamma_log ( beta )\n\n r8_beta_pdf = exp ( temp ) * rval ** ( alpha - 1.0D+00 ) &\n * ( 1.0D+00 - rval ) ** ( beta - 1.0D+00 )\n\n end if\n \n return\nend function r8_beta_pdf\n\n\nfunction r8_beta_sample ( aa, bb )\n\n!*****************************************************************************80\n!\n!! R8_BETA_SAMPLE generates a beta random deviate.\n!\n! Discussion:\n!\n! This procedure returns a single random deviate from the beta distribution\n! with parameters A and B. The density is\n!\n! x^(a-1) * (1-x)^(b-1) / Beta(a,b) for 0 < x < 1\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 April 2013\n!\n! Author:\n!\n! Original FORTRAN77 version by Barry Brown, James Lovato.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! Russell Cheng,\n! Generating Beta Variates with Nonintegral Shape Parameters,\n! Communications of the ACM,\n! Volume 21, Number 4, April 1978, pages 317-322.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) AA, the first parameter of the beta distribution.\n! 0.0 < AA.\n!\n! Input, real ( kind = 8 ) BB, the second parameter of the beta distribution.\n! 0.0 < BB.\n!\n! Output, real ( kind = 8 ) R8_BETA_SAMPLE, a beta random variate.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) aa\n real ( kind = 8 ) alpha\n real ( kind = 8 ) b\n real ( kind = 8 ) bb\n real ( kind = 8 ) beta\n real ( kind = 8 ) delta\n real ( kind = 8 ) gamma\n real ( kind = 8 ) k1\n real ( kind = 8 ) k2\n real ( kind = 8 ), parameter :: log4 = 1.3862943611198906188D+00\n real ( kind = 8 ), parameter :: log5 = 1.6094379124341003746D+00\n real ( kind = 8 ) r\n real ( kind = 8 ) r8_beta_sample\n! real ( kind = 8 ) r8_uniform_01_sample\n real ( kind = 8 ) s\n real ( kind = 8 ) t\n real ( kind = 8 ) u1\n real ( kind = 8 ) u2\n real ( kind = 8 ) v\n real ( kind = 8 ) w\n real ( kind = 8 ) y\n real ( kind = 8 ) z\n\n if ( aa <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_BETA_SAMPLE - Fatal error!'\n write ( *, '(a)' ) ' AA <= 0.0'\n stop 1\n end if\n\n if ( bb <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_BETA_SAMPLE - Fatal error!'\n write ( *, '(a)' ) ' BB <= 0.0'\n stop 1\n end if\n!\n! Algorithm BB\n!\n if ( 1.0D+00 < aa .and. 1.0D+00 < bb ) then\n\n a = min ( aa, bb )\n b = max ( aa, bb )\n alpha = a + b\n beta = sqrt ( ( alpha - 2.0D+00 ) / ( 2.0D+00 * a * b - alpha ) )\n gamma = a + 1.0D+00 / beta\n\n do\n\n u1 = r8_uniform_01_sample ( )\n u2 = r8_uniform_01_sample ( )\n v = beta * log ( u1 / ( 1.0D+00 - u1 ) )\n w = a * exp ( v )\n\n z = u1 ** 2 * u2\n r = gamma * v - log4\n s = a + r - w\n\n if ( 5.0D+00 * z <= s + 1.0D+00 + log5 ) then\n exit\n end if\n\n t = log ( z )\n if ( t <= s ) then\n exit\n end if\n\n if ( t <= ( r + alpha * log ( alpha / ( b + w ) ) ) ) then\n exit\n end if\n\n end do\n!\n! Algorithm BC\n!\n else\n\n a = max ( aa, bb )\n b = min ( aa, bb )\n alpha = a + b\n beta = 1.0D+00 / b\n delta = 1.0D+00 + a - b\n k1 = delta * ( 1.0D+00 / 72.0D+00 + b / 24.0D+00 ) &\n / ( a / b - 7.0D+00 / 9.0D+00 )\n k2 = 0.25D+00 + ( 0.5D+00 + 0.25D+00 / delta ) * b\n\n do\n\n u1 = r8_uniform_01_sample ( )\n u2 = r8_uniform_01_sample ( )\n\n if ( u1 < 0.5D+00 ) then\n\n y = u1 * u2\n z = u1 * y\n\n if ( k1 <= 0.25D+00 * u2 + z - y ) then\n cycle\n end if\n\n else\n\n z = u1 ** 2 * u2\n\n if ( z <= 0.25D+00 ) then\n\n v = beta * log ( u1 / ( 1.0D+00 - u1 ) )\n w = a * exp ( v )\n\n if ( aa == a ) then\n r8_beta_sample = w / ( b + w )\n else\n r8_beta_sample = b / ( b + w )\n end if\n\n return\n\n end if\n\n if ( k2 < z ) then\n cycle\n end if\n\n end if\n\n v = beta * log ( u1 / ( 1.0D+00 - u1 ) )\n w = a * exp ( v )\n\n if ( log ( z ) <= alpha * ( log ( alpha / ( b + w ) ) + v ) - log4 ) then\n exit\n end if\n\n end do\n\n end if\n\n if ( aa == a ) then\n r8_beta_sample = w / ( b + w )\n else\n r8_beta_sample = b / ( b + w )\n end if\n\n return\nend function r8_beta_sample\n\n\nfunction r8_chi_pdf ( df, rval )\n\n!*****************************************************************************80\n!\n!! R8_CHI_PDF evaluates the PDF of a chi-squared distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 March 2013\n!\n! Author:\n!\n! Original FORTRAN90 version by Guannan Zhang.\n! Modifications by John Burkardt.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) DF, the degrees of freedom.\n! 0.0 < DF.\n!\n! Input, real ( kind = 8 ) RVAL, the point where the PDF is evaluated.\n!\n! Output, real ( kind = 8 ) R8_CHI_PDF, the value of the PDF at RVAL.\n!\n implicit none\n\n real ( kind = 8 ) df\n real ( kind = 8 ) r8_chi_pdf\n! real ( kind = 8 ) r8_gamma_log\n real ( kind = 8 ) rval\n real ( kind = 8 ) temp1\n real ( kind = 8 ) temp2\n\n if ( df <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_CHI_PDF - Fatal error!'\n write ( *, '(a)' ) ' Degrees of freedom must be positive.'\n stop 1\n end if\n \n if ( rval <= 0.0D+00 ) then\n\n r8_chi_pdf = 0.0D+00\n\n else\n\n temp2 = df * 0.5D+00\n\n temp1 = ( temp2 - 1.0D+00 ) * log ( rval ) - 0.5D+00 * rval &\n - temp2 * log ( 2.0D+00 ) - r8_gamma_log ( temp2 )\n\n r8_chi_pdf = exp ( temp1 )\n\n end if\n\n return\nend function r8_chi_pdf\n\n\nfunction r8_chi_sample ( df )\n\n!*****************************************************************************80\n!\n!! R8_CHI_SAMPLE generates a Chi-Square random deviate.\n!\n! Discussion:\n!\n! This procedure generates a random deviate from the chi square distribution\n! with DF degrees of freedom random variable.\n!\n! The algorithm exploits the relation between chisquare and gamma.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 March 2013\n!\n! Author:\n!\n! Original FORTRAN77 version by Barry Brown, James Lovato.\n! FORTRAN90 version by John Burkardt.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) DF, the degrees of freedom.\n! 0.0 < DF.\n!\n! Output, real ( kind = 8 ) R8_CHI_SAMPLE, a random deviate \n! from the distribution.\n!\n implicit none\n\n real ( kind = 8 ) arg1\n real ( kind = 8 ) arg2\n real ( kind = 8 ) df\n real ( kind = 8 ) r8_chi_sample\n! real ( kind = 8 ) r8_gamma_sample\n\n if ( df <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_CHI_SAMPLE - Fatal error!'\n write ( *, '(a)' ) ' DF <= 0.'\n write ( *, '(a,g14.6)' ) ' Value of DF: ', df\n stop 1\n end if\n\n arg1 = 1.0D+00\n arg2 = df / 2.0D+00\n\n r8_chi_sample = 2.0D+00 * r8_gamma_sample ( arg1, arg2 )\n\n return\nend function r8_chi_sample\n\n\nfunction r8_choose ( n, k )\n\n!*****************************************************************************80\n!\n!! R8_CHOOSE computes the binomial coefficient C(N,K) as an R8.\n!\n! Discussion:\n!\n! The value is calculated in such a way as to avoid overflow and\n! roundoff. The calculation is done in R8 arithmetic.\n!\n! The formula used is:\n!\n! C(N,K) = N! / ( K! * (N-K)! )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 March 2008\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! ML Wolfson, HV Wright,\n! Algorithm 160:\n! Combinatorial of M Things Taken N at a Time,\n! Communications of the ACM,\n! Volume 6, Number 4, April 1963, page 161.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, K, are the values of N and K.\n!\n! Output, real ( kind = 8 ) R8_CHOOSE, the number of combinations of N\n! things taken K at a time.\n!\n implicit none\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) k\n integer ( kind = 4 ) mn\n integer ( kind = 4 ) mx\n integer ( kind = 4 ) n\n real ( kind = 8 ) r8_choose\n real ( kind = 8 ) value\n\n mn = min ( k, n - k )\n\n if ( mn < 0 ) then\n\n value = 0.0D+00\n\n else if ( mn == 0 ) then\n\n value = 1.0D+00\n\n else\n\n mx = max ( k, n - k )\n value = real ( mx + 1, kind = 8 )\n\n do i = 2, mn\n value = ( value * real ( mx + i, kind = 8 ) ) / real ( i, kind = 8 )\n end do\n\n end if\n\n r8_choose = value\n\n return\nend function r8_choose\n\n\nfunction r8_exponential_pdf ( beta, rval )\n\n!*****************************************************************************80\n!\n!! R8_EXPONENTIAL_PDF evaluates the PDF of an exponential distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 March 2013\n!\n! Author:\n!\n! Original FORTRAN90 version by Guannan Zhang.\n! Modifications by John Burkardt.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) BETA, the scale value.\n! 0.0 < BETA.\n!\n! Input, real ( kind = 8 ) RVAL, the point where the PDF is evaluated.\n!\n! Output, real ( kind = 8 ) R8_EXPONENTIAL_PDF, the value of the PDF at RVAL.\n!\n implicit none\n\n real ( kind = 8 ) beta\n real ( kind = 8 ) r8_exponential_pdf\n real ( kind = 8 ) rval\n\n if ( beta <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_EXPONENTIAL_PDF - Fatal error!'\n write ( *, '(a)' ) ' BETA parameter must be positive.'\n stop 1\n end if\n\n if ( rval < 0.0D+00 ) then\n r8_exponential_pdf = 0.0D+00\n else\n r8_exponential_pdf = exp ( - rval / beta ) / beta\n end if\n\n return\nend function r8_exponential_pdf\n\n\nfunction r8_exponential_01_pdf ( rval )\n\n!*****************************************************************************80\n!\n!! R8_EXPONENTIAL_01_PDF: PDF of a standard exponential distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 09 June 2013\n!\n! Author:\n!\n! John Burkardt.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) RVAL, the point where the PDF is evaluated.\n!\n! Output, real ( kind = 8 ) R8_EXPONENTIAL_01_PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) r8_exponential_01_pdf\n real ( kind = 8 ) rval\n\n if ( rval < 0.0D+00 ) then\n r8_exponential_01_pdf = 0.0D+00\n else\n r8_exponential_01_pdf = exp ( - rval )\n end if\n\n return\nend function r8_exponential_01_pdf\n\n\nfunction r8_exponential_01_sample ( )\n\n!*****************************************************************************80\n!\n!! R8_EXPONENTIAL_01_SAMPLE samples the standard exponential PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 April 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) R8_EXPONENTIAL_01_SAMPLE, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) r\n real ( kind = 8 ) r8_exponential_01_sample\n! real ( kind = 8 ) r8_uniform_01_sample\n\n r = r8_uniform_01_sample ( )\n\n r8_exponential_01_sample = - log ( r )\n\n return\nend function r8_exponential_01_sample\n\n\nfunction r8_gamma_log ( x )\n\n!*****************************************************************************80\n!\n!! R8_GAMMA_LOG evaluates the logarithm of the gamma function.\n!\n! Discussion:\n!\n! This routine calculates the LOG(GAMMA) function for a positive real\n! argument X. Computation is based on an algorithm outlined in\n! references 1 and 2. The program uses rational functions that\n! theoretically approximate LOG(GAMMA) to at least 18 significant\n! decimal digits. The approximation for X > 12 is from reference\n! 3, while approximations for X < 12.0 are similar to those in\n! reference 1, but are unpublished.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 April 2013\n!\n! Author:\n!\n! Original FORTRAN77 version by William Cody, Laura Stoltz.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! William Cody, Kenneth Hillstrom,\n! Chebyshev Approximations for the Natural Logarithm of the\n! Gamma Function,\n! Mathematics of Computation,\n! Volume 21, Number 98, April 1967, pages 198-203.\n!\n! Kenneth Hillstrom,\n! ANL/AMD Program ANLC366S, DGAMMA/DLGAMA,\n! May 1969.\n!\n! John Hart, Ward Cheney, Charles Lawson, Hans Maehly,\n! Charles Mesztenyi, John Rice, Henry Thatcher,\n! Christoph Witzgall,\n! Computer Approximations,\n! Wiley, 1968,\n! LC: QA297.C64.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the function.\n! 0.0 < X.\n!\n! Output, real ( kind = 8 ) R8_GAMMA_LOG, the value of the function.\n!\n implicit none\n\n real ( kind = 8 ), dimension ( 7 ) :: c = (/ &\n -1.910444077728D-03, &\n 8.4171387781295D-04, &\n -5.952379913043012D-04, &\n 7.93650793500350248D-04, &\n -2.777777777777681622553D-03, &\n 8.333333333333333331554247D-02, &\n 5.7083835261D-03 /)\n real ( kind = 8 ) corr\n real ( kind = 8 ) :: d1 = -5.772156649015328605195174D-01\n real ( kind = 8 ) :: d2 = 4.227843350984671393993777D-01\n real ( kind = 8 ) :: d4 = 1.791759469228055000094023D+00\n real ( kind = 8 ), parameter :: frtbig = 2.25D+76\n integer ( kind = 4 ) i\n real ( kind = 8 ), dimension ( 8 ) :: p1 = (/ &\n 4.945235359296727046734888D+00, &\n 2.018112620856775083915565D+02, &\n 2.290838373831346393026739D+03, &\n 1.131967205903380828685045D+04, &\n 2.855724635671635335736389D+04, &\n 3.848496228443793359990269D+04, &\n 2.637748787624195437963534D+04, &\n 7.225813979700288197698961D+03 /)\n real ( kind = 8 ), dimension ( 8 ) :: p2 = (/ &\n 4.974607845568932035012064D+00, &\n 5.424138599891070494101986D+02, &\n 1.550693864978364947665077D+04, &\n 1.847932904445632425417223D+05, &\n 1.088204769468828767498470D+06, &\n 3.338152967987029735917223D+06, &\n 5.106661678927352456275255D+06, &\n 3.074109054850539556250927D+06 /)\n real ( kind = 8 ), dimension ( 8 ) :: p4 = (/ &\n 1.474502166059939948905062D+04, &\n 2.426813369486704502836312D+06, &\n 1.214755574045093227939592D+08, &\n 2.663432449630976949898078D+09, &\n 2.940378956634553899906876D+10, &\n 1.702665737765398868392998D+11, &\n 4.926125793377430887588120D+11, &\n 5.606251856223951465078242D+11 /)\n real ( kind = 8 ), dimension ( 8 ) :: q1 = (/ &\n 6.748212550303777196073036D+01, &\n 1.113332393857199323513008D+03, &\n 7.738757056935398733233834D+03, &\n 2.763987074403340708898585D+04, &\n 5.499310206226157329794414D+04, &\n 6.161122180066002127833352D+04, &\n 3.635127591501940507276287D+04, &\n 8.785536302431013170870835D+03 /)\n real ( kind = 8 ), dimension ( 8 ) :: q2 = (/ &\n 1.830328399370592604055942D+02, &\n 7.765049321445005871323047D+03, &\n 1.331903827966074194402448D+05, &\n 1.136705821321969608938755D+06, &\n 5.267964117437946917577538D+06, &\n 1.346701454311101692290052D+07, &\n 1.782736530353274213975932D+07, &\n 9.533095591844353613395747D+06 /)\n real ( kind = 8 ), dimension ( 8 ) :: q4 = (/ &\n 2.690530175870899333379843D+03, &\n 6.393885654300092398984238D+05, &\n 4.135599930241388052042842D+07, &\n 1.120872109616147941376570D+09, &\n 1.488613728678813811542398D+10, &\n 1.016803586272438228077304D+11, &\n 3.417476345507377132798597D+11, &\n 4.463158187419713286462081D+11 /)\n real ( kind = 8 ) r8_gamma_log\n real ( kind = 8 ) res\n real ( kind = 8 ), parameter :: sqrtpi = 0.9189385332046727417803297D+00\n real ( kind = 8 ) x\n real ( kind = 8 ), parameter :: xbig = 2.55D+305\n real ( kind = 8 ) xden\n real ( kind = 8 ), parameter :: xinf = 1.79D+308\n real ( kind = 8 ) xm1\n real ( kind = 8 ) xm2\n real ( kind = 8 ) xm4\n real ( kind = 8 ) xnum\n real ( kind = 8 ) y\n real ( kind = 8 ) ysq\n\n y = x\n\n if ( 0.0D+00 < y .and. y <= xbig ) then\n\n if ( y <= epsilon ( y ) ) then\n\n res = - log ( y )\n!\n! EPS < X <= 1.5.\n!\n else if ( y <= 1.5D+00 ) then\n\n if ( y < 0.6796875D+00 ) then\n corr = -log ( y )\n xm1 = y\n else\n corr = 0.0D+00\n xm1 = ( y - 0.5D+00 ) - 0.5D+00\n end if\n\n if ( y <= 0.5D+00 .or. 0.6796875D+00 <= y ) then\n\n xden = 1.0D+00\n xnum = 0.0D+00\n do i = 1, 8\n xnum = xnum * xm1 + p1(i)\n xden = xden * xm1 + q1(i)\n end do\n\n res = corr + ( xm1 * ( d1 + xm1 * ( xnum / xden ) ) )\n\n else\n\n xm2 = ( y - 0.5D+00 ) - 0.5D+00\n xden = 1.0D+00\n xnum = 0.0D+00\n do i = 1, 8\n xnum = xnum * xm2 + p2(i)\n xden = xden * xm2 + q2(i)\n end do\n\n res = corr + xm2 * ( d2 + xm2 * ( xnum / xden ) )\n\n end if\n!\n! 1.5 < X <= 4.0.\n!\n else if ( y <= 4.0D+00 ) then\n\n xm2 = y - 2.0D+00\n xden = 1.0D+00\n xnum = 0.0D+00\n do i = 1, 8\n xnum = xnum * xm2 + p2(i)\n xden = xden * xm2 + q2(i)\n end do\n\n res = xm2 * ( d2 + xm2 * ( xnum / xden ) )\n!\n! 4.0 < X <= 12.0.\n!\n else if ( y <= 12.0D+00 ) then\n\n xm4 = y - 4.0D+00\n xden = -1.0D+00\n xnum = 0.0D+00\n do i = 1, 8\n xnum = xnum * xm4 + p4(i)\n xden = xden * xm4 + q4(i)\n end do\n\n res = d4 + xm4 * ( xnum / xden )\n!\n! Evaluate for 12 <= argument.\n!\n else\n\n res = 0.0D+00\n\n if ( y <= frtbig ) then\n\n res = c(7)\n ysq = y * y\n\n do i = 1, 6\n res = res / ysq + c(i)\n end do\n\n end if\n\n res = res / y\n corr = log ( y )\n res = res + sqrtpi - 0.5D+00 * corr\n res = res + y * ( corr - 1.0D+00 )\n\n end if\n!\n! Return for bad arguments.\n!\n else\n\n res = xinf\n\n end if\n!\n! Final adjustments and return.\n!\n r8_gamma_log = res\n\n return\nend function r8_gamma_log\n\n\nfunction r8_gamma_pdf ( beta, alpha, rval )\n\n!*****************************************************************************80\n!\n!! R8_GAMMA_PDF evaluates the PDF of a gamma distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 March 2013\n!\n! Author:\n!\n! Original FORTRAN90 version by Guannan Zhang.\n! Modifications by John Burkardt.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) BETA, the rate parameter.\n! 0.0 < BETA.\n!\n! Input, real ( kind = 8 ) ALPHA, the shape parameter.\n! 0.0 < ALPHA.\n!\n! Input, real ( kind = 8 ) RVAL, the point where the PDF is evaluated.\n!\n! Output, real ( kind = 8 ) R8_GAMMA_PDF, the value of the PDF at RVAL.\n!\n implicit none\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ) beta\n! real ( kind = 8 ) r8_gamma_log\n real ( kind = 8 ) r8_gamma_pdf\n real ( kind = 8 ) rval\n real ( kind = 8 ) temp\n\n if ( alpha <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_GAMMA_PDF - Fatal error!'\n write ( *, '(a)' ) ' Parameter ALPHA is not positive.'\n stop 1\n end if\n\n if ( beta <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_GAMMA_PDF - Fatal error!'\n write ( *, '(a)' ) ' Parameter BETA is not positive.'\n stop 1\n end if\n\n if ( rval <= 0.0D+00 ) then\n\n r8_gamma_pdf = 0.0D+00\n\n else\n\n temp = alpha * log ( beta ) + ( alpha - 1.0D+00 ) * log ( rval ) &\n - beta * rval - r8_gamma_log ( alpha )\n\n r8_gamma_pdf = exp ( temp )\n\n end if\n\n return \nend function r8_gamma_pdf\n\n\nfunction r8_gamma_sample ( a, r )\n\n!*****************************************************************************80\n!\n!! R8_GAMMA_SAMPLE generates a Gamma random deviate.\n!\n! Discussion:\n!\n! This procedure generates random deviates from the gamma distribution whose\n! density is (A^R)/Gamma(R) * X^(R-1) * Exp(-A*X)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 March 2013\n!\n! Author:\n!\n! Original FORTRAN77 version by Barry Brown, James Lovato.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! Joachim Ahrens, Ulrich Dieter,\n! Generating Gamma Variates by a Modified Rejection Technique,\n! Communications of the ACM,\n! Volume 25, Number 1, January 1982, pages 47-54.\n!\n! Joachim Ahrens, Ulrich Dieter,\n! Computer Methods for Sampling from Gamma, Beta, Poisson and\n! Binomial Distributions,\n! Computing,\n! Volume 12, Number 3, September 1974, pages 223-246.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the rate parameter.\n! A nonzero.\n!\n! Input, real ( kind = 8 ) R, the shape parameter.\n! 0.0 < R.\n!\n! Output, real ( kind = 8 ) R8_GAMMA_SAMPLE, a random deviate \n! from the distribution.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) r\n real ( kind = 8 ) r8_gamma_sample\n! real ( kind = 8 ) r8_gamma_01_sample\n\n r8_gamma_sample = r8_gamma_01_sample ( r ) / a\n\n return\nend function r8_gamma_sample\n\n\nfunction r8_gamma_01_pdf ( alpha, rval )\n\n!*****************************************************************************80\n!\n!! R8_GAMMA_01_PDF evaluates the PDF of a standard gamma distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 09 June 2013\n!\n! Author:\n!\n! John Burkardt.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) ALPHA, the shape parameter.\n! 0.0 < ALPHA.\n!\n! Input, real ( kind = 8 ) RVAL, the point where the PDF is evaluated.\n!\n! Output, real ( kind = 8 ) R8_GAMMA_01_PDF, the value of the PDF at RVAL.\n!\n implicit none\n\n real ( kind = 8 ) alpha\n! real ( kind = 8 ) r8_gamma_log\n real ( kind = 8 ) r8_gamma_01_pdf\n real ( kind = 8 ) rval\n real ( kind = 8 ) temp\n\n if ( alpha <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_GAMMA_01_PDF - Fatal error!'\n write ( *, '(a)' ) ' Parameter ALPHA is not positive.'\n stop 1\n end if\n\n if ( rval <= 0.0D+00 ) then\n\n r8_gamma_01_pdf = 0.0D+00\n\n else\n\n temp = ( alpha - 1.0D+00 ) * log ( rval ) - rval - r8_gamma_log ( alpha )\n\n r8_gamma_01_pdf = exp ( temp )\n\n end if\n\n return \nend function r8_gamma_01_pdf\n\n\nfunction r8_gamma_01_sample ( a )\n\n!*****************************************************************************80\n!\n!! R8_GAMMA_01_SAMPLE samples the standard Gamma distribution.\n!\n! Discussion:\n!\n! This procedure corresponds to algorithm GD in the reference.\n!\n! pdf ( a; x ) = 1/gamma(a) * x^(a-1) * exp ( - x )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 April 2013\n!\n! Author:\n!\n! Original FORTRAN77 version by Barry Brown, James Lovato.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! Joachim Ahrens, Ulrich Dieter,\n! Generating Gamma Variates by a Modified Rejection Technique,\n! Communications of the ACM,\n! Volume 25, Number 1, January 1982, pages 47-54.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the shape parameter. \n! 0.0 < A.\n!\n! Output, real ( kind = 8 ) R8_GAMMA_01_SAMPLE, a random deviate \n! from the distribution.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ), parameter :: a1 = 0.3333333D+00\n real ( kind = 8 ), parameter :: a2 = -0.2500030D+00\n real ( kind = 8 ), parameter :: a3 = 0.2000062D+00\n real ( kind = 8 ), parameter :: a4 = -0.1662921D+00\n real ( kind = 8 ), parameter :: a5 = 0.1423657D+00\n real ( kind = 8 ), parameter :: a6 = -0.1367177D+00\n real ( kind = 8 ), parameter :: a7 = 0.1233795D+00\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) d\n real ( kind = 8 ) e\n real ( kind = 8 ), parameter :: e1 = 1.0D+00\n real ( kind = 8 ), parameter :: e2 = 0.4999897D+00\n real ( kind = 8 ), parameter :: e3 = 0.1668290D+00\n real ( kind = 8 ), parameter :: e4 = 0.0407753D+00\n real ( kind = 8 ), parameter :: e5 = 0.0102930D+00\n real ( kind = 8 ) p\n real ( kind = 8 ) q\n real ( kind = 8 ) q0\n real ( kind = 8 ), parameter :: q1 = 0.04166669D+00\n real ( kind = 8 ), parameter :: q2 = 0.02083148D+00\n real ( kind = 8 ), parameter :: q3 = 0.00801191D+00\n real ( kind = 8 ), parameter :: q4 = 0.00144121D+00\n real ( kind = 8 ), parameter :: q5 = -0.00007388D+00\n real ( kind = 8 ), parameter :: q6 = 0.00024511D+00\n real ( kind = 8 ), parameter :: q7 = 0.00024240D+00\n real ( kind = 8 ) r\n! real ( kind = 8 ) r8_exponential_01_sample\n real ( kind = 8 ) r8_gamma_01_sample\n! real ( kind = 8 ) r8_normal_01_sample\n! real ( kind = 8 ) r8_uniform_01_sample\n real ( kind = 8 ) s\n real ( kind = 8 ) s2\n real ( kind = 8 ) si\n real ( kind = 8 ), parameter :: sqrt32 = 5.656854D+00\n real ( kind = 8 ) t\n real ( kind = 8 ) u\n real ( kind = 8 ) v\n real ( kind = 8 ) w\n real ( kind = 8 ) x\n\n if ( 1.0D+00 <= a ) then\n\n s2 = a - 0.5D+00\n s = sqrt ( s2 )\n d = sqrt32 - 12.0D+00 * s\n!\n! Immediate acceptance.\n!\n t = r8_normal_01_sample ( )\n x = s + 0.5D+00 * t\n r8_gamma_01_sample = x * x\n\n if ( 0.0D+00 <= t ) then\n return\n end if\n!\n! Squeeze acceptance.\n!\n u = r8_uniform_01_sample ( )\n if ( d * u <= t * t * t ) then\n return\n end if\n\n r = 1.0D+00 / a\n q0 = (((((( q7 &\n * r + q6 ) &\n * r + q5 ) &\n * r + q4 ) &\n * r + q3 ) &\n * r + q2 ) &\n * r + q1 ) &\n * r\n!\n! Approximation depending on size of parameter A.\n!\n if ( 13.022D+00 < a ) then\n b = 1.77D+00\n si = 0.75D+00\n c = 0.1515D+00 / s\n else if ( 3.686D+00 < a ) then\n b = 1.654D+00 + 0.0076D+00 * s2\n si = 1.68D+00 / s + 0.275D+00\n c = 0.062D+00 / s + 0.024D+00\n else\n b = 0.463D+00 + s + 0.178D+00 * s2\n si = 1.235D+00\n c = 0.195D+00 / s - 0.079D+00 + 0.16D+00 * s\n end if\n!\n! Quotient test.\n!\n if ( 0.0D+00 < x ) then\n\n v = 0.5D+00 * t / s\n\n if ( 0.25D+00 < abs ( v ) ) then\n q = q0 - s * t + 0.25D+00 * t * t + 2.0D+00 * s2 * log ( 1.0D+00 + v )\n else\n q = q0 + 0.5D+00 * t * t * (((((( a7 &\n * v + a6 ) &\n * v + a5 ) &\n * v + a4 ) &\n * v + a3 ) &\n * v + a2 ) &\n * v + a1 ) &\n * v\n end if\n\n if ( log ( 1.0D+00 - u ) <= q ) then\n return\n end if\n\n end if\n\n do\n\n e = r8_exponential_01_sample ( )\n u = 2.0D+00 * r8_uniform_01_sample ( ) - 1.0D+00\n \n if ( 0.0D+00 <= u ) then\n t = b + abs ( si * e )\n else\n t = b - abs ( si * e )\n end if\n!\n! Possible rejection.\n!\n if ( t < -0.7187449D+00 ) then\n cycle\n end if\n!\n! Calculate V and quotient Q.\n!\n v = 0.5D+00 * t / s\n\n if ( 0.25D+00 < abs ( v ) ) then\n q = q0 - s * t + 0.25D+00 * t * t + 2.0D+00 * s2 * log ( 1.0D+00 + v )\n else\n q = q0 + 0.5D+00 * t * t * (((((( a7 &\n * v + a6 ) &\n * v + a5 ) &\n * v + a4 ) &\n * v + a3 ) &\n * v + a2 ) &\n * v + a1 ) &\n * v\n end if\n!\n! Hat acceptance.\n!\n if ( q <= 0.0D+00 ) then\n cycle\n end if\n\n if ( 0.5D+00 < q ) then\n w = exp ( q ) - 1.0D+00\n else\n w = (((( e5 * q + e4 ) * q + e3 ) * q + e2 ) * q + e1 ) * q\n end if\n!\n! May have to sample again.\n!\n if ( c * abs ( u ) <= w * exp ( e - 0.5D+00 * t * t ) ) then\n exit\n end if\n\n end do\n\n x = s + 0.5D+00 * t\n r8_gamma_01_sample = x * x\n\n return\n!\n! Method for A < 1.\n!\n else\n\n b = 1.0D+00 + 0.3678794D+00 * a\n\n do\n\n p = b * r8_uniform_01_sample ( )\n\n if ( p < 1.0D+00 ) then\n\n r8_gamma_01_sample = exp ( log ( p ) / a )\n\n if ( r8_gamma_01_sample <= r8_exponential_01_sample ( ) ) then\n return\n end if\n\n cycle\n\n end if\n\n r8_gamma_01_sample = - log ( ( b - p ) / a )\n\n if ( ( 1.0D+00 - a ) * log ( r8_gamma_01_sample ) <= &\n r8_exponential_01_sample ( ) ) then\n exit\n end if\n\n end do\n\n end if\n\n return\nend function r8_gamma_01_sample\n\n\nfunction r8_invchi_pdf ( df, rval )\n\n!*****************************************************************************80\n!\n!! R8_INVCHI_PDF evaluates the PDF of an inverse chi-squared distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 March 2013\n!\n! Author:\n!\n! Original FORTRAN90 version by Guannan Zhang.\n! Modifications by John Burkardt.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) DF, the degrees of freedom.\n! 0.0 < DF.\n!\n! Input, real ( kind = 8 ) RVAL, the point where the PDF is evaluated.\n!\n! Output, real ( kind = 8 ) R8_INVCHI_PDF, the value of the PDF at RVAL.\n!\n implicit none\n\n real ( kind = 8 ) df\n! real ( kind = 8 ) r8_gamma_log\n real ( kind = 8 ) r8_invchi_pdf\n real ( kind = 8 ) rval\n real ( kind = 8 ) temp1\n real ( kind = 8 ) temp2 \n\n if ( df <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_INVCHI_PDF - Fatal error!'\n write ( *, '(a)' ) ' Degrees of freedom must be positive.'\n stop 1\n end if\n\n if ( rval <= 0.0D+00 ) then\n\n r8_invchi_pdf = 0.0D+00\n\n else\n\n temp2 = df * 0.5D+00\n temp1 = - temp2 * log ( 2.0D+00 ) - ( temp2 + 1.0D+00 ) * log ( rval ) &\n - 0.5D+00 / rval - r8_gamma_log ( temp2 )\n\n r8_invchi_pdf = exp ( temp1 )\n\n end if\n\n return\nend function r8_invchi_pdf\n\n\nfunction r8_invchi_sample ( df )\n\n!*****************************************************************************80\n!\n!! R8_INVCHI_SAMPLE samples an inverse chi-squared distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 May 2013\n!\n! Author:\n!\n! John Burkardt.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) DF, the degrees of freedom.\n! 0.0 < DF.\n!\n! Output, real ( kind = 8 ) R8_INVCHI_SAMPLE, a sample value.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) df\n! real ( kind = 8 ) r8_gamma_sample\n real ( kind = 8 ) r8_invchi_sample\n real ( kind = 8 ) value\n\n a = 0.5D+00\n b = 0.5D+00 * df\n\n value = r8_gamma_sample ( a, b )\n\n if ( value /= 0.0D+00 ) then\n value = 1.0D+00 / value\n end if\n\n r8_invchi_sample = value\n\n return\nend function r8_invchi_sample\n\n\nfunction r8_invgam_pdf ( beta, alpha, rval )\n\n!*****************************************************************************80\n!\n!! R8_INVGAM_PDF evaluates the PDF of an inverse gamma distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 March 2013\n!\n! Author:\n!\n! Original FORTRAN90 version by Guannan Zhang.\n! Modifications by John Burkardt.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) BETA, the rate parameter.\n! 0.0 < BETA.\n!\n! Input, real ( kind = 8 ) ALPHA, the shape parameter.\n! 0.0 < ALPHA.\n!\n! Input, real ( kind = 8 ) RVAL, the point where the PDF is evaluated.\n!\n! Output, real ( kind = 8 ) R8_INVGAM_PDF, the value of the PDF at RVAL.\n!\n implicit none\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ) beta\n! real ( kind = 8 ) r8_gamma_log\n real ( kind = 8 ) r8_invgam_pdf\n real ( kind = 8 ) rval\n real ( kind = 8 ) temp\n\n if ( alpha <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_INVGAM_PDF - Fatal error!'\n write ( *, '(a)' ) ' Parameter ALPHA is not positive.'\n stop 1\n end if\n\n if ( beta <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_INVGAM_PDF - Fatal error!'\n write ( *, '(a)' ) ' Parameter BETA is not positive.'\n stop 1\n end if\n\n if ( rval <= 0.0D+00 ) then\n\n r8_invgam_pdf = 0.0D+00\n\n else\n\n temp = alpha * log ( beta ) - ( alpha + 1.0D+00 ) * log ( rval ) &\n - beta / rval - r8_gamma_log ( alpha )\n\n r8_invgam_pdf = exp ( temp )\n\n end if\n\n return\nend function r8_invgam_pdf\n\n\nfunction r8_invgam_sample ( beta, alpha )\n\n!*****************************************************************************80\n!\n!! R8_INVGAM_SAMPLE samples an inverse gamma distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 May 2013\n!\n! Author:\n!\n! Original FORTRAN90 version by Guannan Zhang.\n! Modifications by John Burkardt.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) BETA, the rate parameter.\n! 0.0 < BETA.\n!\n! Input, real ( kind = 8 ) ALPHA, the shape parameter.\n! 0.0 < ALPHA.\n!\n! Output, real ( kind = 8 ) R8_INVGAM_SAMPLE, a sample value.\n!\n implicit none\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ) beta\n! real ( kind = 8 ) r8_gamma_sample\n real ( kind = 8 ) r8_invgam_sample\n real ( kind = 8 ) value\n\n value = r8_gamma_sample ( beta, alpha )\n\n if ( value /= 0.0D+00 ) then\n value = 1.0D+00 / value\n end if\n\n r8_invgam_sample = value\n\n return\nend function r8_invgam_sample\n\n\nfunction r8_normal_pdf ( av, sd, rval )\n\n!*****************************************************************************80\n!\n!! R8_NORMAL_PDF evaluates the PDF of a normal distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 March 2013\n!\n! Author:\n!\n! Original FORTRAN90 version by Guannan Zhang.\n! Modifications by John Burkardt.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) AV, the mean value.\n!\n! Input, real ( kind = 8 ) SD, the standard deviation.\n! 0.0 < SD.\n!\n! Input, real ( kind = 8 ) RVAL, the point where the PDF is evaluated.\n!\n! Output, real ( kind = 8 ) R8_NORMAL_PDF, the value of the PDF at RVAL.\n!\n implicit none\n\n real ( kind = 8 ) av\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) r8_normal_pdf\n real ( kind = 8 ) rtemp\n real ( kind = 8 ) rval\n real ( kind = 8 ) sd\n\n if ( sd <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_NORMAL_PDF - Fatal error!'\n write ( *, '(a)' ) ' Standard deviation must be positive.'\n stop 1\n end if\n\n rtemp = ( rval - av ) * ( rval - av ) * 0.5D+00 / ( sd * sd )\n\n r8_normal_pdf = exp ( - rtemp ) / sd / sqrt ( 2.0D+00 * pi )\n\n return\nend function r8_normal_pdf\n\n\nfunction r8_normal_sample ( av, sd )\n\n!*****************************************************************************80\n!\n!! R8_NORMAL_SAMPLE generates a normal random deviate.\n!\n! Discussion:\n!\n! This procedure generates a single random deviate from a normal distribution\n! with mean AV, and standard deviation SD.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 April 2013\n!\n! Author:\n!\n! Original FORTRAN77 version by Barry Brown, James Lovato.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! Joachim Ahrens, Ulrich Dieter,\n! Extensions of Forsythe's Method for Random\n! Sampling from the Normal Distribution,\n! Mathematics of Computation,\n! Volume 27, Number 124, October 1973, page 927-937.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) AV, the mean.\n!\n! Input, real ( kind = 8 ) SD, the standard deviation.\n!\n! Output, real ( kind = 8 ) R8_NORMAL_SAMPLE, a random deviate \n! from the distribution.\n!\n implicit none\n\n real ( kind = 8 ) av\n real ( kind = 8 ) r8_normal_sample\n! real ( kind = 8 ) r8_normal_01_sample\n real ( kind = 8 ) sd\n\n r8_normal_sample = sd * r8_normal_01_sample ( ) + av\n\n return\nend function r8_normal_sample\n\n\nfunction r8_normal_01_pdf ( rval )\n\n!*****************************************************************************80\n!\n!! R8_NORMAL_01_PDF evaluates the PDF of a standard normal distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 09 June 2013\n!\n! Author:\n!\n! John Burkardt.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) RVAL, the point where the PDF is evaluated.\n!\n! Output, real ( kind = 8 ) R8_NORMAL_01_PDF, the value of the PDF at RVAL.\n!\n implicit none\n\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) r8_normal_01_pdf\n real ( kind = 8 ) rval\n\n r8_normal_01_pdf = exp ( - 0.5D+00 * rval ** 2 ) / sqrt ( 2.0D+00 * pi )\n\n return\nend function r8_normal_01_pdf\n\n\nfunction r8_normal_01_sample ( )\n\n!*****************************************************************************80\n!\n!! R8_NORMAL_01_SAMPLE returns a unit pseudonormal R8.\n!\n! Discussion:\n!\n! The standard normal probability distribution function (PDF) has\n! mean 0 and standard deviation 1.\n!\n! The Box-Muller method is used, which is efficient, but\n! generates two values at a time.\n!\n! Typically, we would use one value and save the other for the next call.\n! However, the fact that this function has saved memory makes it difficult\n! to correctly handle cases where we want to re-initialize the code,\n! or to run in parallel. Therefore, we will instead use the first value\n! and DISCARD the second.\n!\n! EFFICIENCY must defer to SIMPLICITY.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) R8_NORMAL_01_SAMPLE, a sample of the standard\n! normal PDF.\n!\n implicit none\n\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) r1\n real ( kind = 8 ) r2\n real ( kind = 8 ) r8_normal_01_sample\n! real ( kind = 8 ) r8_uniform_01_sample\n real ( kind = 8 ) x\n\n r1 = r8_uniform_01_sample ( )\n r2 = r8_uniform_01_sample ( )\n\n x = sqrt ( - 2.0D+00 * log ( r1 ) ) * cos ( 2.0D+00 * pi * r2 )\n\n r8_normal_01_sample = x\n\n return\nend function r8_normal_01_sample\n\n\nfunction r8_scinvchi_pdf ( df, s, rval )\n\n!*****************************************************************************80\n!\n!! R8_SCINVCHI_PDF: PDF for a scaled inverse chi-squared distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 March 2013\n!\n! Author:\n!\n! Original FORTRAN90 version by Guannan Zhang.\n! Modifications by John Burkardt.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) DF, the degrees of freedom.\n! 0.0 < DF.\n!\n! Input, real ( kind = 8 ) S, the scale factor.\n! 0.0 < S.\n!\n! Input, real ( kind = 8 ) RVAL, the point where the PDF is evaluated.\n!\n! Output, real ( kind = 8 ) R8_SCINVCHI_PDF, the value of the PDF at RVAL.\n! inverse-chi-square distribution.\n!\n implicit none\n\n real ( kind = 8 ) df\n! real ( kind = 8 ) r8_gamma_log\n real ( kind = 8 ) r8_scinvchi_pdf\n real ( kind = 8 ) rval\n real ( kind = 8 ) s\n real ( kind = 8 ) temp1\n real ( kind = 8 ) temp2\n\n if ( df <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_SCINVCHI_PDF - Fatal error!'\n write ( *, '(a)' ) ' Degrees of freedom must be positive.'\n stop 1\n end if\n\n if ( s <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_SCINVCHI_PDF - Fatal error!'\n write ( *, '(a)' ) ' Scale parameter must be positive.'\n stop 1\n end if\n\n if ( rval <= 0.0D+00 ) then\n\n r8_scinvchi_pdf = 0.0D+00\n\n else\n\n temp2 = df * 0.5D+00\n temp1 = temp2 * log ( temp2 ) + temp2 * log ( s ) &\n - ( temp2 * s / rval ) & \n - ( temp2 + 1.0D+00 ) * log ( rval ) - r8_gamma_log ( temp2 )\n\n r8_scinvchi_pdf = exp ( temp1 )\n\n end if\n\n return\nend function r8_scinvchi_pdf\n\n\nfunction r8_scinvchi_sample ( df, s )\n\n!*****************************************************************************80\n!\n!! R8_SCINVCHI_SAMPLE: sample a scaled inverse chi-squared distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 May 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) DF, the degrees of freedom.\n! 0.0 < DF.\n!\n! Input, real ( kind = 8 ) S, the scale factor.\n! 0.0 < S.\n!\n! Input, real ( kind = 8 ) R8_SCINVCHI_SAMPLE, a sample value.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) df\n! real ( kind = 8 ) r8_gamma_sample\n real ( kind = 8 ) r8_scinvchi_sample\n real ( kind = 8 ) s\n real ( kind = 8 ) value\n\n a = 0.5D+00 * df * s\n b = 0.5D+00 * df\n\n value = r8_gamma_sample ( a, b )\n\n if ( value /= 0.0D+00 ) then\n value = 1.0D+00 / value\n end if\n\n r8_scinvchi_sample = value\n\n return\nend function r8_scinvchi_sample\n\n\nfunction r8_uniform_pdf ( lower, upper, rval )\n\n!*****************************************************************************80\n!\n!! R8_UNIFORM_PDF evaluates the PDF of a uniform distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 March 2013\n!\n! Author:\n!\n! Original FORTRAN90 version by Guannan Zhang.\n! Modifications by John Burkardt.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) LOWER, UPPER, the lower and upper range limits.\n! LOWER < UPPER.\n!\n! Input, real ( kind = 8 ) RVAL, the point where the PDF is evaluated.\n!\n! Output, real ( kind = 8 ) R8_UNIFORM_PDF, the value of the PDF at RVAL.\n!\n implicit none\n\n real ( kind = 8 ) lower\n real ( kind = 8 ) r8_uniform_pdf\n real ( kind = 8 ) rval\n real ( kind = 8 ) upper\n\n if ( upper <= lower ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_UNIFORM_PDF - Fatal error!'\n write ( *, '(a)' ) ' For uniform PDF, the lower limit must be '\n write ( *, '(a)' ) ' less than the upper limit!'\n stop 1\n end if\n\n if ( rval < lower ) then\n r8_uniform_pdf = 0.0D+00\n else if ( rval <= upper ) then\n r8_uniform_pdf = 1.0D+00 / ( upper - lower )\n else\n r8_uniform_pdf = 0.0D+00\n end if\n\n return\nend function r8_uniform_pdf\n\n\nfunction r8_uniform_sample ( low, high )\n\n!*****************************************************************************80\n!\n!! R8_UNIFORM_SAMPLE generates a uniform random deviate.\n!\n! Discussion:\n!\n! This procedure generates a real deviate uniformly distributed between\n! LOW and HIGH.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 March 2013\n!\n! Author:\n!\n! Original FORTRAN77 version by Barry Brown, James Lovato.\n! FORTRAN90 version by John Burkardt.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) LOW, HIGH, the lower and upper bounds.\n!\n! Output, real ( kind = 8 ) R8_UNIFORM_SAMPLE, a random deviate \n! from the distribution.\n!\n implicit none\n\n real ( kind = 8 ) high\n real ( kind = 8 ) low\n! real ( kind = 8 ) r8_uniform_01_sample\n real ( kind = 8 ) r8_uniform_sample\n\n r8_uniform_sample = low + ( high - low ) * r8_uniform_01_sample ( )\n\n return\nend function r8_uniform_sample\n\n\nfunction r8_uniform_01_pdf ( rval )\n\n!*****************************************************************************80\n!\n!! R8_UNIFORM_01_PDF evaluates the PDF of a standard uniform distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 09 June 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) RVAL, the point where the PDF is evaluated.\n!\n! Output, real ( kind = 8 ) R8_UNIFORM_01_PDF, the value of the PDF at RVAL.\n!\n implicit none\n\n real ( kind = 8 ) r8_uniform_01_pdf\n real ( kind = 8 ) rval\n\n if ( rval < 0.0D+00 ) then\n r8_uniform_01_pdf = 0.0D+00\n else if ( rval <= 1.0D+00 ) then\n r8_uniform_01_pdf = 1.0D+00\n else\n r8_uniform_01_pdf = 0.0D+00\n end if\n\n return\nend function r8_uniform_01_pdf\n\n\nfunction r8_uniform_01_sample ( )\n\n!*****************************************************************************80\n!\n!! R8_UNIFORM_01_SAMPLE generates a uniform random deviate from [0,1].\n!\n! Discussion:\n!\n! This function should be the only way that the package accesses random\n! numbers.\n!\n! Setting OPTION to 0 accesses the R8_UNI_01() function in RNGLIB,\n! for which there are versions in various languages, which should result\n! in the same values being returned.\n!\n! Setting OPTION to 1 in the FORTRAN90 version calls the system\n! RNG \"random_number()\".\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 August 2013\n!\n! Author:\n!\n! Original FORTRAN77 version by Barry Brown, James Lovato.\n! FORTRAN90 version by John Burkardt.\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) R8_UNIFORM_01_SAMPLE, a random deviate \n! from the distribution.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: option = 0\n! real ( kind = 8 ) r8_uni_01\n real ( kind = 8 ) r8_uniform_01_sample\n real ( kind = 8 ) value\n\n if ( option == 0 ) then\n value = r8_uni_01 ( )\n else\n call random_number ( harvest = value )\n end if\n \n r8_uniform_01_sample = value\n\n return\nend function r8_uniform_01_sample\n\n\nsubroutine r8ge_print ( m, n, a, title )\n\n!*****************************************************************************80\n!\n!! R8GE_PRINT prints an R8GE matrix.\n!\n! Discussion:\n!\n! The R8GE storage format is used for a general M by N matrix. A storage \n! space is made for each entry. The two dimensional logical\n! array can be thought of as a vector of M*N entries, starting with\n! the M entries in the column 1, then the M entries in column 2\n! and so on. Considered as a vector, the entry A(I,J) is then stored\n! in vector location I+(J-1)*M.\n!\n! R8GE storage is used by LINPACK and LAPACK.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 07 May 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, the number of rows of the matrix.\n! M must be positive.\n!\n! Input, integer ( kind = 4 ) N, the number of columns of the matrix.\n! N must be positive.\n!\n! Input, real ( kind = 8 ) A(M,N), the R8GE matrix.\n!\n! Input, character ( len = * ) TITLE, a title.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(m,n)\n character ( len = * ) title\n\n call r8ge_print_some ( m, n, a, int(1,kind=4), int(1,kind=4), m, n, title )\n\n return\nend subroutine r8ge_print\n\n\nsubroutine r8ge_print_some ( m, n, a, ilo, jlo, ihi, jhi, title )\n\n!*****************************************************************************80\n!\n!! R8GE_PRINT_SOME prints some of an R8GE matrix.\n!\n! Discussion:\n!\n! The R8GE storage format is used for a general M by N matrix. A storage \n! space is made for each entry. The two dimensional logical\n! array can be thought of as a vector of M*N entries, starting with\n! the M entries in the column 1, then the M entries in column 2\n! and so on. Considered as a vector, the entry A(I,J) is then stored\n! in vector location I+(J-1)*M.\n!\n! R8GE storage is used by LINPACK and LAPACK.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 21 March 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, the number of rows of the matrix.\n! M must be positive.\n!\n! Input, integer ( kind = 4 ) N, the number of columns of the matrix.\n! N must be positive.\n!\n! Input, real ( kind = 8 ) A(M,N), the R8GE matrix.\n!\n! Input, integer ( kind = 4 ) ILO, JLO, IHI, JHI, the first row and\n! column, and the last row and column to be printed.\n!\n! Input, character ( len = * ) TITLE, a title.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: incx = 5\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(m,n)\n character ( len = 14 ) ctemp(incx)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i2hi\n integer ( kind = 4 ) i2lo\n integer ( kind = 4 ) ihi\n integer ( kind = 4 ) ilo\n integer ( kind = 4 ) inc\n integer ( kind = 4 ) j\n integer ( kind = 4 ) j2\n integer ( kind = 4 ) j2hi\n integer ( kind = 4 ) j2lo\n integer ( kind = 4 ) jhi\n integer ( kind = 4 ) jlo\n character ( len = * ) title\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n!\n! Print the columns of the matrix, in strips of 5.\n!\n do j2lo = jlo, jhi, incx\n\n j2hi = j2lo + incx - 1\n j2hi = min ( j2hi, n )\n j2hi = min ( j2hi, jhi )\n\n inc = j2hi + 1 - j2lo\n\n write ( *, '(a)' ) ' '\n\n do j = j2lo, j2hi\n j2 = j + 1 - j2lo\n write ( ctemp(j2), '(i7,7x)' ) j\n end do\n\n write ( *, '('' Col: '',5a14)' ) ( ctemp(j2), j2 = 1, inc )\n write ( *, '(a)' ) ' Row'\n write ( *, '(a)' ) ' ---'\n!\n! Determine the range of the rows in this strip.\n!\n i2lo = max ( ilo, 1 )\n i2hi = min ( ihi, m )\n\n do i = i2lo, i2hi\n!\n! Print out (up to) 5 entries in row I, that lie in the current strip.\n!\n do j2 = 1, inc\n\n j = j2lo - 1 + j2\n\n write ( ctemp(j2), '(g14.6)' ) a(i,j)\n\n end do\n\n write ( *, '(i5,1x,5a14)' ) i, ( ctemp(j2), j2 = 1, inc )\n\n end do\n\n end do\n\n return\nend subroutine r8ge_print_some\n\n\nsubroutine r8ge_to_r8po ( n, a, b )\n\n!*****************************************************************************80\n!\n!! R8GE_TO_R8PO copies an R8GE matrix to an R8PO matrix.\n!\n! Discussion:\n!\n! The R8PO format assumes the matrix is square and symmetric; it is also \n! typically assumed that the matrix is positive definite. These are not\n! required here. The copied R8PO matrix simply zeros out the lower triangle\n! of the R8GE matrix.\n!\n! The R8GE storage format is used for a general M by N matrix. A storage \n! space is made for each entry. The two dimensional logical\n! array can be thought of as a vector of M*N entries, starting with\n! the M entries in the column 1, then the M entries in column 2\n! and so on. Considered as a vector, the entry A(I,J) is then stored\n! in vector location I+(J-1)*M.\n!\n! The R8PO storage format is used for a symmetric positive definite \n! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an\n! upper triangular matrix, so it will be in R8GE storage format.)\n!\n! Only the diagonal and upper triangle of the square array are used.\n! This same storage scheme is used when the matrix is factored by\n! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle\n! is set to zero.\n!\n! R8PO storage is used by LINPACK and LAPACK.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 02 August 2015\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the matrix.\n!\n! Input, real ( kind = 8 ) A(N,N), the R8PO matrix.\n!\n! Output, real ( kind = 8 ) B(N,N), the R8GE matrix.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n,n)\n real ( kind = 8 ) b(n,n)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n\n do i = 1, n\n do j = 1, n\n if ( i <= j ) then\n b(i,j) = a(i,j)\n else\n b(i,j) = 0.0D+00\n end if\n end do\n end do\n\n return\nend subroutine r8ge_to_r8po\n\n\nfunction r8mat_norm_fro_affine ( m, n, a1, a2 )\n\n!*****************************************************************************80\n!\n!! R8MAT_NORM_FRO_AFFINE returns the Frobenius norm of an R8MAT difference.\n!\n! Discussion:\n!\n! An R8MAT is an MxN array of R8's, stored by (I,J) -> [I+J*M].\n!\n! The Frobenius norm is defined as\n!\n! R8MAT_NORM_FRO = sqrt (\n! sum ( 1 <= I <= M ) sum ( 1 <= j <= N ) A(I,J) * A(I,J) )\n!\n! The matrix Frobenius norm is not derived from a vector norm, but\n! is compatible with the vector L2 norm, so that:\n!\n! r8vec_norm_l2 ( A * x ) <= r8mat_norm_fro ( A ) * r8vec_norm_l2 ( x ).\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 March 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, the number of rows.\n!\n! Input, integer ( kind = 4 ) N, the number of columns.\n!\n! Input, real ( kind = 8 ) A1(M,N), A2(M,N), the matrices for whose \n! difference the Frobenius norm is desired.\n!\n! Output, real ( kind = 8 ) R8MAT_NORM_FRO_AFFINE, the Frobenius \n! norm of A1 - A2.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a1(m,n)\n real ( kind = 8 ) a2(m,n)\n real ( kind = 8 ) r8mat_norm_fro_affine\n\n r8mat_norm_fro_affine = sqrt ( sum ( ( a1(1:m,1:n) - a2(1:m,1:n) )**2 ) )\n\n return\nend function r8mat_norm_fro_affine\n\n\nsubroutine r8po_det ( n, a_lu, det )\n\n!*****************************************************************************80\n!\n!! R8PO_DET computes the determinant of a matrix factored by R8PO_FA.\n!\n! Discussion:\n!\n! The R8PO storage format is used for a symmetric positive definite \n! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an\n! upper triangular matrix, so it will be in R8GE storage format.)\n!\n! Only the diagonal and upper triangle of the square array are used.\n! This same storage scheme is used when the matrix is factored by\n! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle\n! is set to zero.\n!\n! R8PO storage is used by LINPACK and LAPACK.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 29 July 2015\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the matrix.\n!\n! Input, real ( kind = 8 ) A_LU(N,N), the LU factors from R8PO_FA.\n!\n! Output, real ( kind = 8 ) DET, the determinant of A.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a_lu(n,n)\n real ( kind = 8 ) det\n integer ( kind = 4 ) i\n\n det = 1.0D+00\n\n do i = 1, n\n det = det * a_lu(i,i) ** 2\n end do\n\n return\nend subroutine r8po_det\n\n\nsubroutine r8po_fa ( n, a, r )\n\n!*****************************************************************************80\n!\n!! R8PO_FA factors an R8PO matrix.\n!\n! Discussion:\n!\n! The R8PO storage format is used for a symmetric positive definite \n! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an\n! upper triangular matrix, so it will be in R8GE storage format.)\n!\n! Only the diagonal and upper triangle of the square array are used.\n! This same storage scheme is used when the matrix is factored by\n! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle\n! is set to zero.\n!\n! R8PO storage is used by LINPACK and LAPACK.\n!\n! The positive definite symmetric matrix A has a Cholesky factorization\n! of the form:\n!\n! A = R' * R\n!\n! where R is an upper triangular matrix with positive elements on\n! its diagonal.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 03 August 2015\n!\n! Author:\n!\n! John Burkardt.\n!\n! Reference:\n!\n! Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\n! LINPACK User's Guide,\n! SIAM, 1979,\n! ISBN13: 978-0-898711-72-1,\n! LC: QA214.L56.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the matrix.\n!\n! Input, real ( kind = 8 ) A(N,N), the matrix.\n!\n! Output, real ( kind = 8 ) R(N,N), the Cholesky factor R.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n,n)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) info\n integer ( kind = 4 ) j\n integer ( kind = 4 ) k\n real ( kind = 8 ) r(n,n)\n real ( kind = 8 ) s\n\n r(1:n,1:n) = a(1:n,1:n)\n\n do j = 1, n\n\n do k = 1, j - 1\n r(k,j) = ( r(k,j) - sum ( r(1:k-1,k) * r(1:k-1,j) ) ) / r(k,k)\n end do\n\n s = r(j,j) - sum ( r(1:j-1,j)**2 )\n\n if ( s <= 0.0D+00 ) then\n info = j\n write ( *, '(a)' ) ''\n write ( *, '(a)' ) 'R8PO_FA - Fatal error!'\n write ( *, '(a,i4)' ) ' Factorization failed on column ', j\n stop 1\n end if\n\n r(j,j) = sqrt ( s )\n\n end do\n\n info = 0\n!\n! Since the Cholesky factor is stored in R8GE format, be sure to\n! zero out the lower triangle.\n!\n do i = 1, n\n do j = 1, i - 1\n r(i,j) = 0.0D+00\n end do\n end do\n\n return\nend subroutine r8po_fa\n\n\nsubroutine r8po_inverse ( n, r, b )\n\n!*****************************************************************************80\n!\n!! R8PO_INVERSE computes the inverse of a matrix factored by R8PO_FA.\n!\n! Discussion:\n!\n! The R8PO storage format is used for a symmetric positive definite \n! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an\n! upper triangular matrix, so it will be in R8GE storage format.)\n!\n! Only the diagonal and upper triangle of the square array are used.\n! This same storage scheme is used when the matrix is factored by\n! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle\n! is set to zero.\n!\n! R8PO storage is used by LINPACK and LAPACK.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 03 August 2015\n!\n! Author:\n!\n! John Burkardt.\n!\n! Reference:\n!\n! Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\n! LINPACK User's Guide,\n! SIAM, 1979,\n! ISBN13: 978-0-898711-72-1,\n! LC: QA214.L56.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the matrix.\n!\n! Input, real ( kind = 8 ) R(N,N), the Cholesky factor..\n!\n! Output, real ( kind = 8 ) B(N,N), the inverse matrix, in R8PO storage.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) b(n,n)\n integer ( kind = 4 ) j\n integer ( kind = 4 ) k\n real ( kind = 8 ) r(n,n)\n real ( kind = 8 ) t\n\n b(1:n,1:n) = r(1:n,1:n)\n!\n! Compute Inverse ( R ).\n!\n do k = 1, n\n\n b(k,k) = 1.0D+00 / b(k,k)\n b(1:k-1,k) = - b(1:k-1,k) * b(k,k)\n\n do j = k + 1, n\n t = b(k,j)\n b(k,j) = 0.0D+00\n b(1:k,j) = b(1:k,j) + t * b(1:k,k)\n end do\n\n end do\n!\n! Compute Inverse ( R ) * ( Inverse ( R ) )'.\n!\n do j = 1, n\n\n do k = 1, j - 1\n t = b(k,j)\n b(1:k,k) = b(1:k,k) + t * b(1:k,j)\n end do\n\n b(1:j,j) = b(1:j,j) * b(j,j)\n\n end do\n\n return\nend subroutine r8po_inverse\n\n\nsubroutine r8po_mv ( n, a, x, b )\n\n!*****************************************************************************80\n!\n!! R8PO_MV multiplies an R8PO matrix by an R8VEC.\n!\n! Discussion:\n!\n! The R8PO storage format is used for a symmetric positive definite \n! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an\n! upper triangular matrix, so it will be in R8GE storage format.)\n!\n! Only the diagonal and upper triangle of the square array are used.\n! This same storage scheme is used when the matrix is factored by\n! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle\n! is set to zero.\n!\n! R8PO storage is used by LINPACK and LAPACK.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 01 October 2003\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the matrix.\n!\n! Input, real ( kind = 8 ) A(N,N), the R8PO matrix.\n!\n! Input, real ( kind = 8 ) X(N), the vector to be multiplied by A.\n!\n! Output, real ( kind = 8 ) B(N), the product A * x.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n,n)\n real ( kind = 8 ) b(n)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n real ( kind = 8 ) x(n)\n\n do i = 1, n\n b(i) = 0.0D+00\n do j = 1, i-1\n b(i) = b(i) + a(j,i) * x(j)\n end do\n do j = i, n\n b(i) = b(i) + a(i,j) * x(j)\n end do\n end do\n\n return\nend subroutine r8po_mv\n\n\nsubroutine r8po_print ( n, a, title )\n\n!*****************************************************************************80\n!\n!! R8PO_PRINT prints an R8PO matrix.\n!\n! Discussion:\n!\n! The R8PO storage format is used for a symmetric positive definite \n! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an\n! upper triangular matrix, so it will be in R8GE storage format.)\n!\n! Only the diagonal and upper triangle of the square array are used.\n! This same storage scheme is used when the matrix is factored by\n! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle\n! is set to zero.\n!\n! R8PO storage is used by LINPACK and LAPACK.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 02 October 2003\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the matrix.\n!\n! Input, real ( kind = 8 ) A(N,N), the R8PO matrix.\n!\n! Input, character ( len = * ) TITLE, a title.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n,n)\n character ( len = * ) title\n\n call r8po_print_some ( n, a, int(1,kind=4), int(1,kind=4), n, n, title )\n\n return\nend subroutine r8po_print\n\n\nsubroutine r8po_print_some ( n, a, ilo, jlo, ihi, jhi, title )\n\n!*****************************************************************************80\n!\n!! R8PO_PRINT_SOME prints some of an R8PO matrix.\n!\n! Discussion:\n!\n! The R8PO storage format is used for a symmetric positive definite \n! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an\n! upper triangular matrix, so it will be in R8GE storage format.)\n!\n! Only the diagonal and upper triangle of the square array are used.\n! This same storage scheme is used when the matrix is factored by\n! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle\n! is set to zero.\n!\n! R8PO storage is used by LINPACK and LAPACK.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 01 October 2003\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the matrix.\n!\n! Input, real ( kind = 8 ) A(N,N), the R8PO matrix.\n!\n! Input, integer ( kind = 4 ) ILO, JLO, IHI, JHI, the first row and\n! column, and the last row and column to be printed.\n!\n! Input, character ( len = * ) TITLE, a title.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: incx = 5\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n,n)\n real ( kind = 8 ) aij\n character ( len = 14 ) ctemp(incx)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i2hi\n integer ( kind = 4 ) i2lo\n integer ( kind = 4 ) ihi\n integer ( kind = 4 ) ilo\n integer ( kind = 4 ) inc\n integer ( kind = 4 ) j\n integer ( kind = 4 ) j2\n integer ( kind = 4 ) j2hi\n integer ( kind = 4 ) j2lo\n integer ( kind = 4 ) jhi\n integer ( kind = 4 ) jlo\n character ( len = * ) title\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n!\n! Print the columns of the matrix, in strips of 5.\n!\n do j2lo = jlo, jhi, incx\n\n j2hi = j2lo + incx - 1\n j2hi = min ( j2hi, n )\n j2hi = min ( j2hi, jhi )\n\n inc = j2hi + 1 - j2lo\n\n write ( *, '(a)' ) ' '\n\n do j = j2lo, j2hi\n j2 = j + 1 - j2lo\n write ( ctemp(j2), '(i7,7x)' ) j\n end do\n\n write ( *, '('' Col: '',5a14)' ) ( ctemp(j2), j2 = 1, inc )\n write ( *, '(a)' ) ' Row'\n write ( *, '(a)' ) ' ---'\n!\n! Determine the range of the rows in this strip.\n!\n i2lo = max ( ilo, 1 )\n i2hi = min ( ihi, n )\n\n do i = i2lo, i2hi\n!\n! Print out (up to) 5 entries in row I, that lie in the current strip.\n!\n do j2 = 1, inc\n\n j = j2lo - 1 + j2\n\n if ( i <= j ) then\n aij = a(i,j)\n else\n aij = a(j,i)\n end if\n\n write ( ctemp(j2), '(g14.6)' ) aij\n\n end do\n\n write ( *, '(i5,1x,5a14)' ) i, ( ctemp(j2), j2 = 1, inc )\n\n end do\n\n end do\n\n return\nend subroutine r8po_print_some\n\n\nsubroutine r8ut_print ( m, n, a, title )\n\n!*****************************************************************************80\n!\n!! R8UT_PRINT prints an R8UT matrix.\n!\n! Discussion:\n!\n! The R8UT storage format is used for an M by N upper triangular \n! matrix. The format stores all M*N entries, even those which are zero.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 07 May 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, the number of rows of the matrix.\n! M must be positive.\n!\n! Input, integer ( kind = 4 ) N, the number of columns of the matrix.\n! N must be positive.\n!\n! Input, real ( kind = 8 ) A(M,N), the R8UT matrix.\n!\n! Input, character ( len = * ) TITLE, a title.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(m,n)\n character ( len = * ) title\n\n call r8ut_print_some ( m, n, a, int(1,kind=4), int(1,kind=4), m, n, title )\n\n return\nend subroutine r8ut_print\n\n\nsubroutine r8ut_print_some ( m, n, a, ilo, jlo, ihi, jhi, title )\n\n!*****************************************************************************80\n!\n!! R8UT_PRINT_SOME prints some of an R8UT matrix.\n!\n! Discussion:\n!\n! The R8UT storage format is used for an M by N upper triangular \n! matrix. The format stores all M*N entries, even those which are zero.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 21 March 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, the number of rows of the matrix.\n! M must be positive.\n!\n! Input, integer ( kind = 4 ) N, the number of columns of the matrix.\n! N must be positive.\n!\n! Input, real ( kind = 8 ) A(M,N), the R8UT matrix.\n!\n! Input, integer ( kind = 4 ) ILO, JLO, IHI, JHI, the first row and\n! column, and the last row and column to be printed.\n!\n! Input, character ( len = * ) TITLE, a title.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: incx = 5\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(m,n)\n character ( len = 14 ) ctemp(incx)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i2hi\n integer ( kind = 4 ) i2lo\n integer ( kind = 4 ) ihi\n integer ( kind = 4 ) ilo\n integer ( kind = 4 ) inc\n integer ( kind = 4 ) j\n integer ( kind = 4 ) j2\n integer ( kind = 4 ) j2hi\n integer ( kind = 4 ) j2lo\n integer ( kind = 4 ) jhi\n integer ( kind = 4 ) jlo\n character ( len = * ) title\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n!\n! Print the columns of the matrix, in strips of 5.\n!\n do j2lo = jlo, jhi, incx\n\n j2hi = j2lo + incx - 1\n j2hi = min ( j2hi, n )\n j2hi = min ( j2hi, jhi )\n\n inc = j2hi + 1 - j2lo\n\n write ( *, '(a)' ) ' '\n\n do j = j2lo, j2hi\n j2 = j + 1 - j2lo\n write ( ctemp(j2), '(i7,7x)' ) j\n end do\n\n write ( *, '(a,5a14)' ) ' Col: ', ( ctemp(j2), j2 = 1, inc )\n write ( *, '(a)' ) ' Row'\n write ( *, '(a)' ) ' ---'\n!\n! Determine the range of the rows in this strip.\n!\n i2lo = max ( ilo, 1 )\n i2hi = min ( ihi, m )\n i2hi = min ( i2hi, j2hi )\n\n do i = i2lo, i2hi\n!\n! Print out (up to) 5 entries in row I, that lie in the current strip.\n!\n do j2 = 1, inc\n\n j = j2lo - 1 + j2\n\n if ( j < i ) then\n ctemp(j2) = ' '\n else\n write ( ctemp(j2), '(g14.6)' ) a(i,j)\n end if\n\n end do\n\n write ( *, '(i5,1x,5a14)' ) i, ( ctemp(j2), j2 = 1, inc )\n\n end do\n\n end do\n\n return\nend subroutine r8ut_print_some\n\n\nsubroutine r8ut_sl ( n, a, b, x )\n\n!*****************************************************************************80\n!\n!! R8UT_SL solves a linear system A*x=b with A an R8UT matrix.\n!\n! Discussion:\n!\n! The R8UT storage format is used for an M by N upper triangular \n! matrix. The format stores all M*N entries, even those which are zero.\n!\n! No factorization of the upper triangular matrix is required.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 03 August 2015\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the matrix.\n!\n! Input, real ( kind = 8 ) A(N,N), the R8UT matrix.\n!\n! Input, real ( kind = 8 ) B(N), the right hand side.\n!\n! Output, real ( kind = 8 ) X(N), the solution vector.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n,n)\n real ( kind = 8 ) b(n)\n integer ( kind = 4 ) j\n real ( kind = 8 ) x(n)\n\n x(1:n) = b(1:n)\n\n do j = n, 1, -1\n x(j) = x(j) / a(j,j)\n x(1:j-1) = x(1:j-1) - a(1:j-1,j) * x(j)\n end do\n\n return\nend subroutine r8ut_sl\n\n\nsubroutine r8ut_zeros ( m, n, a )\n\n!*****************************************************************************80\n!\n!! R8UT_ZEROS zeroes an R8UT matrix.\n!\n! Discussion:\n!\n! The R8UT storage format is used for an M by N upper triangular \n! matrix. The format stores all M*N entries, even those which are zero.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 26 January 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the number of rows and columns of \n! the matrix. M and N must be positive.\n!\n! Output, real ( kind = 8 ) A(M,N), the R8UT matrix.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(m,n)\n\n a(1:m,1:n) = 0.0D+00\n\n return\nend subroutine r8ut_zeros\n\n\nfunction r8vec_multinormal_pdf ( n, mu, r, c_det, x )\n\n!*****************************************************************************80\n!\n!! R8VEC_MULTINORMAL_PDF evaluates a multivariate normal PDF.\n!\n! Discussion:\n!\n! PDF ( MU(1:N), C(1:N,1:N); X(1:N) ) = \n! 1 / ( 2 * pi ) ^ ( N / 2 ) * 1 / sqrt ( det ( C ) )\n! * exp ( - ( X - MU )' * inverse ( C ) * ( X - MU ) / 2 )\n!\n! Here,\n!\n! X is the argument vector of length N,\n! MU is the mean vector of length N,\n! C is an N by N positive definite symmetric covariance matrix.\n!\n! The properties of C guarantee that it has an upper triangular\n! matrix R, the Cholesky factor, such that C = R' * R. It is the\n! matrix R that is required by this routine.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the spatial dimension.\n!\n! Input, real ( kind = 8 ) MU(N), the mean vector.\n!\n! Input, real ( kind = 8 ) R(N,N), the upper triangular Cholesky\n! factor of the covariance matrix C.\n!\n! Input, real ( kind = 8 ) C_DET, the determinant of the\n! covariance matrix C.\n!\n! Input, real ( kind = 8 ) X(N), a sample of the distribution.\n!\n! Output, real ( kind = 8 ) R8VEC_MULTINORMAL_PDF, the PDF evaluated\n! at X.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) b(n)\n real ( kind = 8 ) c_det\n real ( kind = 8 ) mu(n)\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) r(n,n)\n real ( kind = 8 ) r8vec_multinormal_pdf\n real ( kind = 8 ) x(n)\n real ( kind = 8 ) xcx\n real ( kind = 8 ) y(n)\n!\n! Compute:\n! inverse(R')*(x-mu) = y\n! by solving:\n! R'*y = x-mu\n!\n b(1:n) = x(1:n) - mu(1:n)\n call r8ut_sl ( n, r, b, y )\n!\n! Compute:\n! (x-mu)' * inv(C) * (x-mu)\n! = (x-mu)' * inv(R'*R) * (x-mu)\n! = (x-mu)' * inv(R) * inv(R) * (x-mu)\n! = y' * y.\n!\n xcx = dot_product ( y, y )\n\n pdf = 1.0D+00 / sqrt ( ( 2.0D+00 * pi ) ** n ) &\n * 1.0D+00 / sqrt ( c_det ) &\n * exp ( -0.5D+00 * xcx )\n\n r8vec_multinormal_pdf = pdf\n\n return\nend function r8vec_multinormal_pdf\n\n\nsubroutine r8vec_multinormal_sample ( n, mu, r, x )\n\n!*****************************************************************************80\n!\n!! R8VEC_MULTINORMAL_SAMPLE samples a multivariate normal PDF.\n!\n! Discussion:\n!\n! PDF ( MU(1:N), C(1:N,1:N); X(1:N) ) = \n! 1 / ( 2 * pi ) ^ ( N / 2 ) * 1 / det ( C )\n! * exp ( - ( X - MU )' * inverse ( C ) * ( X - MU ) / 2 )\n!\n! Here,\n!\n! X is the argument vector of length N,\n! MU is the mean vector of length N,\n! C is an N by N positive definite symmetric covariance matrix.\n!\n! The properties of C guarantee that it has an upper triangular\n! matrix R, the Cholesky factor, such that C = R' * R. It is the\n! matrix R that is required by this routine.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 June 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the spatial dimension.\n!\n! Input, real ( kind = 8 ) MU(N), the mean vector.\n!\n! Input, real ( kind = 8 ) R(N,N), the upper triangular Cholesky\n! factor of the covariance matrix C.\n!\n! Output, real ( kind = 8 ) X(N), a sample of the distribution.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n real ( kind = 8 ) mu(n)\n real ( kind = 8 ) r(n,n)\n! real ( kind = 8 ) r8_normal_01_sample\n real ( kind = 8 ) x(n)\n real ( kind = 8 ) z(n)\n!\n! Compute X = MU + R' * Z\n! where Z is a vector of standard normal variates.\n!\n do j = 1, n\n z(j) = r8_normal_01_sample ( )\n end do\n\n do i = 1, n\n x(i) = mu(i)\n do j = 1, i\n x(i) = x(i) + r(j,i) * z(j)\n end do\n end do\n\n return\nend subroutine r8vec_multinormal_sample\n\n\nsubroutine r8vec_print ( n, a, title )\n\n!*****************************************************************************80\n!\n!! R8VEC_PRINT prints an R8VEC.\n!\n! Discussion:\n!\n! An R8VEC is a vector of R8's.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 August 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of components of the vector.\n!\n! Input, real ( kind = 8 ) A(N), the vector to be printed.\n!\n! Input, character ( len = * ) TITLE, a title.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n integer ( kind = 4 ) i\n character ( len = * ) title\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n write ( *, '(a)' ) ' '\n\n do i = 1, n\n write ( *, '(2x,i8,a,1x,g16.8)' ) i, ':', a(i)\n end do\n\n return\nend subroutine r8vec_print\n\n\n\nend module pdflib\n\n", "meta": {"hexsha": "f2bfce34155518857fdf62da072b9f133366e940", "size": 87305, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "external/ferre/src/pdflib.f90", "max_stars_repo_name": "sdss/apogee", "max_stars_repo_head_hexsha": "e134409dc14b20f69e68a0d4d34b2c1b5056a901", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-04-11T13:35:24.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-14T06:12:51.000Z", "max_issues_repo_path": "external/ferre/src/pdflib.f90", "max_issues_repo_name": "sdss/apogee", "max_issues_repo_head_hexsha": "e134409dc14b20f69e68a0d4d34b2c1b5056a901", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "external/ferre/src/pdflib.f90", "max_forks_repo_name": "sdss/apogee", "max_forks_repo_head_hexsha": "e134409dc14b20f69e68a0d4d34b2c1b5056a901", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2018-09-20T22:07:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T07:13:38.000Z", "avg_line_length": 22.489696033, "max_line_length": 86, "alphanum_fraction": 0.5526716683, "num_tokens": 30062, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947163538935, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7874873317542145}} {"text": "********************************************************************************\nC Input Variables:\nC S Susceptible population\nC I Infected population\nC R Recovered population\nC gamma Rate of recovery from an infection\nC rho Basic reproduction Number\nC\nC State Variables:\nC beta Rate of infection\nC rateInfect Current state dependent rate of infection\nC rateRecover Current state dependent rate of recovery\nC\nC Output Variables:\nC S Susceptible population\nC I Infected population\nC R Recovered population\nC totalRates Sum of total rates; taking advantage of Markovian identities\nC to improve performance.\n********************************************************************************\n subroutine SIR(S, I, R, gamma, rho,\n & totalRates)\n integer S, I, R\n\n double precision rateInfect, rateRecover, totalRates, gamma, rho\n double precision, parameter :: beta = rho * gamma !\n\n rateInfect = beta * S * I / (S + I + R)\n rateRecover = gamma * I\n totalRates = rateInfect + rateRecover\n\n ! Determine which event fired. With probability rateInfect/totalRates\n ! the next event is infection.\n if (rand() < (rateInfect/totalRates)) then\n ! Delta for infection\n S = S - 1\n I = I + 1\n ! Determine the event fired. With probability rateRecover/totalRates\n ! the next event is recovery.\n else\n ! Delta for recovery\n I = I - 1\n R = R + 1\n endif\n end subroutine SIR\n", "meta": {"hexsha": "7638a9be77f3ddde56740fa18a731136ce05a05c", "size": 1652, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/Gillespie-SIR.for", "max_stars_repo_name": "rsulli55/automates", "max_stars_repo_head_hexsha": "1647a8eef85c4f03086a10fa72db3b547f1a0455", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2018-12-19T16:32:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-05T07:58:15.000Z", "max_issues_repo_path": "tests/data/program_analysis/Gillespie-SIR.for", "max_issues_repo_name": "rsulli55/automates", "max_issues_repo_head_hexsha": "1647a8eef85c4f03086a10fa72db3b547f1a0455", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 183, "max_issues_repo_issues_event_min_datetime": "2018-12-20T17:03:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-23T22:21:42.000Z", "max_forks_repo_path": "tests/data/program_analysis/Gillespie-SIR.for", "max_forks_repo_name": "rsulli55/automates", "max_forks_repo_head_hexsha": "1647a8eef85c4f03086a10fa72db3b547f1a0455", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-01-04T22:37:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T17:34:16.000Z", "avg_line_length": 35.9130434783, "max_line_length": 80, "alphanum_fraction": 0.5435835351, "num_tokens": 369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810421953309, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7874091649121648}} {"text": "! Created by EverLookNeverSee@GitHub on 6/3/20\n! For more information see FCS/img/Exercise_08_b.png\n\nfunction fact(n) result(factorial)\n integer, intent(in) :: n\n integer :: i\n real :: factorial, temp\n if (n < 0) then\n factorial = -1.0 ! error\n else if(n == 0) then\n factorial = 1.0 ! factorial of zero\n else\n temp = 1.0\n do i = 2, n\n temp = temp * i\n end do\n factorial = temp\n end if\nend function fact\n\nprogram main\n implicit none\n ! x --> the exponent of `e`\n ! Ea --> approximation error\n ! fact --> declaration of fact function\n ! sum --> current sum of elements in series\n ! previous --> sum of elements in previous step\n ! declaring and initializing variables\n integer :: i = 1\n real :: sum = 1.0 , x = 1.2, previous, Ea, fact\n do\n ! Adding up second element of series -> `x` itself\n if (i == 1) then\n sum = sum + x\n i = i + 1\n ! Calculating and adding up rest of elements of series\n else\n previous = sum\n sum = sum + (x ** i / fact(i))\n Ea = sum - previous\n ! Exit whenever approximation error is less than 10e-10\n if (Ea < 10e-10) then\n exit\n ! keep going to calculate and add up next element of series\n else\n i = i + 1\n cycle\n end if\n end if\n end do\n ! printing results\n print *, \"Sum:\", sum\n print *, \"EXP(\", x, \"):\", EXP(x) ! This is fortran intrinsic exp function\nend program main", "meta": {"hexsha": "1149e0c3d0fa9efda31b62a8a10609164b75808e", "size": 1616, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical methods/Exercise_08_b.f90", "max_stars_repo_name": "EverLookNeverSee/FCS", "max_stars_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-14T10:30:25.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-17T13:03:15.000Z", "max_issues_repo_path": "src/numerical methods/Exercise_08_b.f90", "max_issues_repo_name": "EverLookNeverSee/FCS", "max_issues_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-06-06T13:54:45.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-25T20:32:23.000Z", "max_forks_repo_path": "src/numerical methods/Exercise_08_b.f90", "max_forks_repo_name": "EverLookNeverSee/FCS", "max_forks_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-08T12:57:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T12:57:46.000Z", "avg_line_length": 29.9259259259, "max_line_length": 80, "alphanum_fraction": 0.5303217822, "num_tokens": 437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465188527685, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7873986849259648}} {"text": "PROGRAM meulerb\n \n! Code converted using TO_F90 by Alan Miller\n! Date: 2004-06-28 Time: 12:58:11\n\n! ==========================================================\n! Purpose: This program computes Euler number En using\n! subroutine EULERB\n! Example: Compute Euler number En for n = 0,2,...,10\n! Computed results:\n\n! n En\n! --------------------------\n! 0 .100000000000D+01\n! 2 -.100000000000D+01\n! 4 .500000000000D+01\n! 6 -.610000000000D+02\n! 8 .138500000000D+04\n! 10 -.505210000000D+05\n! ==========================================================\n\nDOUBLE PRECISION :: e\nDIMENSION e(0:200)\nWRITE(*,*)' Please enter Nmax '\n! READ(*,*)N\nn=10\nCALL eulerb(n,e)\nWRITE(*,*)' n En'\nWRITE(*,*)' --------------------------'\nDO k=0,n,2\n WRITE(*,20)k,e(k)\nEND DO\n20 FORMAT(2X,i3,d22.12)\nEND PROGRAM meulerb\n\n\nSUBROUTINE eulerb(n,en)\n\n! ======================================\n! Purpose: Compute Euler number En\n! Input : n --- Serial number\n! Output: EN(n) --- En\n! ======================================\n\n\nINTEGER, INTENT(IN) :: n\nDOUBLE PRECISION, INTENT(OUT) :: en(0:n)\nIMPLICIT DOUBLE PRECISION (a-h,o-z)\n\n\nhpi=2.0D0/3.141592653589793D0\nen(0)=1.0D0\nen(2)=-1.0D0\nr1=-4.0D0*hpi**3\nDO m=4,n,2\n r1=-r1*(m-1)*m*hpi*hpi\n r2=1.0D0\n isgn=1.0D0\n DO k=3,1000,2\n isgn=-isgn\n s=(1.0D0/k)**(m+1)\n r2=r2+isgn*s\n IF (s < 1.0D-15) EXIT\n END DO\n en(m)=r1*r2\nEND DO\nRETURN\nEND SUBROUTINE eulerb\n", "meta": {"hexsha": "4a95fb49c9a1881d15d217686019b93f7510f29e", "size": 1703, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MATLAB/f2matlab/comp_spec_func/meulerb.f90", "max_stars_repo_name": "vasaantk/bin", "max_stars_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATLAB/f2matlab/comp_spec_func/meulerb.f90", "max_issues_repo_name": "vasaantk/bin", "max_issues_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATLAB/f2matlab/comp_spec_func/meulerb.f90", "max_forks_repo_name": "vasaantk/bin", "max_forks_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.6811594203, "max_line_length": 66, "alphanum_fraction": 0.4321785085, "num_tokens": 552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069962657176, "lm_q2_score": 0.8652240738888188, "lm_q1q2_score": 0.7872734381689624}} {"text": "! ===============================================================\nSUBROUTINE clawpack5_rpn2(ixy,maxm,meqn,mwaves,maux,mbc,mx,ql,qr, &\n auxl,auxr,wave,s,amdq,apdq)\n! ===============================================================\n\n! Riemann solver for Burgers' equation in 2d:\n! u_t + 0.5*(u^2)_x + 0.5*(u^2)_y = 0\n\n! waves: 1\n! equations: 1\n\n! Conserved quantities:\n! 1 q\n\n! On input, ql contains the state vector at the left edge of each cell\n! qr contains the state vector at the right edge of each cell\n!\n! This data is along a slice in the x-direction if ixy=1\n! or the y-direction if ixy=2.\n! On output, wave contains the waves,\n! s the speeds,\n! amdq the left-going flux difference A^- \\Delta q\n! apdq the right-going flux difference A^+ \\Delta q\n!\n! Note that the i'th Riemann problem has left state qr(i-1,:)\n! and right state ql(i,:)\n! From the basic clawpack routines, this routine is called with ql = qr\n\n\n implicit double precision (a-h,o-z)\n\n dimension wave(meqn, mwaves, 1-mbc:maxm+mbc)\n dimension s(mwaves, 1-mbc:maxm+mbc)\n dimension ql(meqn, 1-mbc:maxm+mbc)\n dimension qr(meqn, 1-mbc:maxm+mbc)\n dimension apdq(meqn, 1-mbc:maxm+mbc)\n dimension amdq(meqn, 1-mbc:maxm+mbc)\n logical efix\n\n! # x- and y- Riemann problems are identical, so it doesn't matter if\n! # ixy=1 or 2.\n\n efix = .true.\n\n DO i = 2-mbc, mx+mbc\n! # wave is jump in q, speed comes from R-H condition:\n wave(1,1,i) = ql(1,i) - qr(1,i-1)\n s(1,i) = 0.5d0*(qr(1,i-1) + ql(1,i))\n\n! # compute left-going and right-going flux differences:\n\n amdq(1,i) = dmin1(s(1,i), 0.d0) * wave(1,1,i)\n apdq(1,i) = dmax1(s(1,i), 0.d0) * wave(1,1,i)\n\n IF (efix) THEN\n! # entropy fix for transonic rarefactions:\n if (qr(1,i-1).lt.0.d0 .and. ql(1,i).gt.0.d0) then\n amdq(1,i) = - 0.5d0 * qr(1,i-1)**2\n apdq(1,i) = 0.5d0 * ql(1,i)**2\n end if\n END IF\n ENDDO\n\n return\n END SUBROUTINE clawpack5_rpn2\n", "meta": {"hexsha": "059463ede775583322cafdf786c25e52d778aedd", "size": 2239, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/burgers/2d/rp/clawpack5_rpn2_burgers.f90", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/clawpack/burgers/2d/rp/clawpack5_rpn2_burgers.f90", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/clawpack/burgers/2d/rp/clawpack5_rpn2_burgers.f90", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 33.9242424242, "max_line_length": 73, "alphanum_fraction": 0.5149620366, "num_tokens": 726, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002787, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7872408104117592}} {"text": " SUBROUTINE SPFIT (M,X,Y,SIG,NMAX,SEEKN,COMTRN,CHBBAS,P,NFIT,\n * SIGFAC, W)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1994-10-20 SPFIT Krogh Changes to use M77CON\nc>> 1990-08-13 SPFIT CLL Fixed to assure NFIT .ge. 0 in OK cases.\nC>> 1987-12-09 SPFIT Lawson Initial code.\nC Least squares polynomial fit to discrete data.\nC Uses either the Monomial or the Chebyshev basis.\nC ------------------------------------------------------------------\nC M [integer, in] No. of data points.\nC\nC (X(I),I=1,M) [float, in] Abcissas of data.\nC\nC (Y(I),I=1,M) [float, in] Ordinates of data.\nC\nC (SIG(I),I=1,M) [float, in] Standard deviations of data Y().\nC If SIG(1) .lt. 0., the subr will funcrtion as though all\nC SIG(I) ate equal to abs(SIG(1)).\nC In this latter case SIG() can be dimensioned 1 rather than M.\nC\nC NMAX [integer, in] Specifies the highest degree polynomial to be\nc considered.\nC\nC SEEKN [logical, in] If .true. this subr will determine the\nc optimal degree NFIT in the range [0, NMAX] for fitting the\nc given data and compute that fit.\nC If .false. this subr will do the fit with NFIT = NMAX\nC unless this produces a near-singular problem, in which case\nC NFIT will be reduced.\nC\nC COMTRN [logical, in] If .true. this subr will compute\nc transformation parameters, P(1) and P(2), so that the\nc transformed abcissa variable ranges from -1.0 to +1.0.\nC If .false., will use P(1) and P(2) as given on entry.\nC\nC CHBBAS [logical, in] If .true. this subr will use the Chebyshev\nc basis. If .false., will use the Monomial basis.\nC\nC (P(J),J=1,NMAX+3) [float, inout] P(1) and P(2) define a\nc transformation of the abcissa variable as follows:\nC\nC S = ( X - P(1) ) / P(2)\nC\nC (P(I+3),I=0,...,NMAX) are polynomial coefficients computed\nC by this subr. P(I+3) is the coeff of S**I, if the Monomial\nC bases is used and of the I-th degree Chebyshev polynomial if\nC the Chebyshev basis is used.\nC If this subr sets NFIT < NMAX then it will also set the\nc coefficients P(I+3) for I = NFIT+1, ..., NMAX to zero.\nC\nC NFIT [integer, out] On a successful return NFIT will be the\nc degree of the fitted polynomial. It will be set as\nc described above in the specification of SEEKN.\nc If input values are inconsistent, NFIT will be set to -1\nc to indicate an error condition, and no fit will be done.\nC\nC SIGFAC [float,out] Factor by which the given SIG() values should\nC be multiplied to improve consistency with the fit, i.e.,\nc SIGFAC*SIG(i) is the a posteriori estimate of the standard\nc deviation of the error in Y(i). In particular,\nc if all SIG(i) = 1.0, then SIGFAC is an estimate\nc of the standard deviation of the data error.\nc Let SUMSQ = the sum from 1 to M of\nc ((Residual at ith point)/SIG(i))**2\nc Then SIGFAC = sqrt(SUMSQ / max(M-NFIT-1, 1)).\nC\nC W() [float, work] Working space. Must be dimensioned at least\nC (NMAX+3)*(NMAX+3). W() will be used in this subr as a\nc 2-dim array: W(NDIM+3,NDIM+3).\nC ------------------------------------------------------------------\nC C.L.LAWSON, JPL, 1969 DEC 10\nC C.L.L., JPL, 1970 JAN 12 Calling sequence changed.\nC C.L.L., JPL, 1982 Aug 24:\nc To improve portability we are replacing use of\nc subrs BHSLR1 and BHSLR2 by SROTG and SROT.\nC This uses Givens rotations instead of Householder\nc transformations. Accuracy should be the same.\nc Execution time will be greater. Storage required\nc for the work array W() will be less.\nc Name changed from PFIT to LSPOL2.\nc C.L.Lawson, JPL, 1984 March 6. Adapted to Fortran 77.\nc See type declaration for W(,).\nC Counting on the Fortran 77 rule that a DO-loop will\nc be skipped if the values of the control parameters\nc imply no iterations.\nc Name changed from LSPOL2 to [S/D]PFIT,\nC 1984 APR 18 Using 'Modified Givens' rather than standard\nC Givens to reduce execution time. Requires one more\nC column in W().\nc 1990-08-10 CLL. In cases of the Y() values lying randomly around\nc zero with no polynomial trend, and SEEKN = .true., the preferred\nc fit according to our degree determination test may be with no\nc coefficients at all.\nc In this case the subr formerly set NSOLVE = 0 and NFIT = -1.\nc Setting NFIT = -1 is a bad choice on two counts. It indicates an\nc error, whereas this is not an error condition. Also it may be\nc incompatible with subsequent programs that expect a valid\nc polynomial degree for use in polynomial evaluation.\nc Changed to set NFIT = max(NSOLVE-1, 0) so we can still set\nc NSOLVE = 0 in this case but NFIT will not be set less than 0.\nc Having NSOLVE = 0 causes all polynomial coefficients to be set to\nc zero on return.\nc ------------------------------------------------------------------\nc--S replaces \"?\": ?PFIT, ?ERV1, ?ERM1, ?ROTMG, ?ROTM\nc Both versions use IERM1, IERV1\nc Generic intrinsic functions referenced: SQRT, MAX, MIN, ABS\nc ------------------------------------------------------------------\nc The dimensions of X(), Y(), and SIG() must be at least M.\nC\n external IERM1, IERV1, SERV1, SERM1, R1MACH, SROTMG, SROTM\n logical SEEKN, COMTRN, CHBBAS\n integer I, II, IDATA, IDIM, IRANK, IROW, J, LIMIT, LROW, M\n integer N, NFIT, NMAX, NP1, NP2, NP3, NSOLVE\n real R1MACH\n real CMIN, DENOM, FAC, HALF\n real ONE, P(NMAX+3), PARAM(5)\n real S, S2, SIG(*), SIGFAC, SIGMA, SIZE\n real T, TEMP, TEN, TENEPS, TWO\n real W(NMAX+3,NMAX+3), X(*), XMAX, XMIN, Y(*), ZERO\n parameter(ZERO = 0.E0, HALF = .5E0, ONE = 1.E0, TWO = 2.E0)\n parameter(TEN = 10.E0, FAC = 1.01E0 )\nC ------------------------------------------------------------------\nC\nC N = NMAX = MAX DEGREE TO BE CONSIDERED.\nC NP1 = N+1 = NO. OF COEFFS IN A POLY OF DEGREE N\nC NP2 = N+2 = COL INDEX FOR y DATA AND ROW INDEX FOR RESIDUAL NORM.\nC NP3 = N+3. Col NP3 holds the scale factors for the modified\nc Givens method. Row NP3 is used for the entry of additional\nc data after the first NP2 data points have been entered.\nC Total array space used used in W() is NP3 rows by NP3 cols.\nC\n N = NMAX\n NP1=N+1\n NP2=NP1+1\n NP3 = NP2+1\n IF (N.LT.0 .OR. M.LE.0 .OR. SIG(1).EQ.ZERO) THEN\n CALL IERM1('SPFIT',1,0,\n * 'No fit done. Require NMAX .ge. 0, M > 0, and SIG(1) .ne. 0.',\n * 'NMAX',N,',')\n CALL IERV1('M',M,',')\n CALL SERV1('SIG(1)',SIG(1),'.')\n NFIT = -1\n RETURN\n END IF\nC\nc R1MACH(4) is the smallest no. that can be added to 1.0\nc and will give a no. larger than 1.0 in storage.\nc\n TENEPS = TEN * R1MACH(4)\n IDIM = NP3\n SIGMA=ABS(SIG(1))\nC ------------------------------------------------------------------\nC COMPUTE P(1),P(2) IF REQUESTED\nC\nC CHANGE OF INDEPENDENT VARIABLE IS GIVEN BY S=(X-P(1))/P(2)\nC OR X=P(1) + P(2)*S\nC\n IF (COMTRN) THEN\n XMIN = X(1)\n XMAX = XMIN\n DO 30 I=2,M\n XMIN = MIN(XMIN,X(I))\n 30 XMAX = MAX(XMAX,X(I))\n P(1) = (XMAX+XMIN)*HALF\n P(2) = (XMAX-XMIN)*HALF\n IF (P(2) .EQ. ZERO) P(2)=ONE\n ELSE\n IF (P(2) .EQ. ZERO) THEN\n CALL SERM1('SPFIT',2,0,\n * 'No fit done. With COMTRN = .FALSE. require P(2) .ne. 0.',\n * 'P(2)',P(2),'.')\n NFIT = -1\n RETURN\n END IF\n END IF\nC\nC ------------------------------------------------------------------\nC\nC ACCUMULATION LOOP BEGINS HERE\nC IDATA COUNTS THE TOTAL NO. OF DATA POINTS ACCUMULATED.\nC LROW is the index of the row of W(,) in which the\nc new row of data will be placed.\nC\n DO 150 IDATA = 1, M\n LROW = MIN( IDATA, NP3 )\n S=(X(IDATA)-P(1))/P(2)\n IF ( SIG(1) .GT. ZERO ) THEN\n SIGMA = SIG(IDATA)\n IF (SIGMA .LE. ZERO) THEN\n CALL SERM1('SPFIT',3,0,\n * 'No fit done. With SIG(1) > 0. require all SIG(I) > 0.',\n * 'SIG(1)',SIG(1),',')\n CALL IERV1('I',IDATA,',')\n CALL SERV1('SIG(I)',SIGMA,'.')\n NFIT = -1\n RETURN\n END IF\n END IF\n W(LROW,1) = ONE/SIGMA\n W(LROW,NP2) = Y(IDATA)/SIGMA\n W(LROW,NP3) = ONE\n IF (N .GT. 0) THEN\n IF (CHBBAS) THEN\nC Chebyshev basis\n W(LROW,2) = S / SIGMA\n S2 = TWO * S\n DO 120 J = 3,NP1\n 120 W(LROW,J) = S2 * W(LROW,J-1) - W(LROW,J-2)\n ELSE\nC Monomial basis\n DO 100 J = 2,NP1\n 100 W(LROW,J) = S * W(LROW,J-1)\n END IF\n END IF\nC\nC Accumulate new data row into triangular array.\nc\n DO 145 IROW = 1,LROW-1\n CALL SROTMG(W(IROW,NP3),W(LROW,NP3),W(IROW,IROW),\n * W(LROW,IROW),PARAM)\n IF(IROW .LT. NP2) CALL SROTM(NP2-IROW, W(IROW,IROW+1),\n * IDIM, W(LROW,IROW+1), IDIM, PARAM)\n 145 CONTINUE\n 150 CONTINUE\nC END OF ACCUMULATION LOOP\nC ------------------------------------------------------------------\nC\nC Replace Modified Givens weights by their square roots.\nC\n DO 155 I = 1, MIN(NP2,M)\n W(I,NP3) = SQRT(W(I,NP3))\n 155 CONTINUE\nC\nC ------------------------------------------------------------------\nC\nC Set IRANK = no. of leading diagonal elements of\nc the triangular matrix that are not extremely small\nc relative to the other elements in the same column.\nc\n IRANK = MIN(NP1, M)\nC Fortran 77 skips this loop if IRANK .le. 1.\n DO 240 J = 2,IRANK\n SIZE = ZERO\n DO 136 II = 1, J-1\n SIZE = MAX( SIZE, ABS(W(II,J)*W(II,NP3)) )\n 136 CONTINUE\nC\n IF( ABS(W(J,J)*W(J,NP3)) .LT. TENEPS * SIZE ) THEN\n IRANK = J-1\n GO TO 260\n END IF\n 240 CONTINUE\n 260 CONTINUE\nC ------------------------------------------------------------------\nC\nC TEMPORARILY COPY RT-SIDE VECTOR INTO P()\nC\n DO 160 I = 1,IRANK\n 160 P(I+2) = W(I,NP2)\nC ------------------------------------------------------------------\nC\nC Now we deal with 3 possible cases.\nC We must determine NSOLVE and SIGFAC for each of these cases.\nc NSOLVE is the no. of coefficients that will be computed.\nc We initially set NSOLVE = IRANK, but NSOLVE may be\nc reset to a smaller value in Case 3 below.\nc 1. SEEKN = .false. and IRANK = NMAX+1\nC This is the simple case.\nc 2. SEEKN = .false. and IRANK .lt. NMAX+1\nC Requires extra work to compute SIGFAC.\nc 3. SEEKN = .true.\nc This requires more work to determine NSOLVE and SIGFAC.\nC\n NSOLVE = IRANK\n IF( .NOT. SEEKN .AND. IRANK .EQ. NP1 ) THEN\nC\nC Here for Case 1.\nc\n TEMP = M - NP1\n IF( TEMP .EQ. ZERO ) THEN\n SIGFAC = ZERO\n ELSE\nc Here M .gt. NP1.\n SIGFAC = ABS(W(NP2,NP2)*W(NP2,NP3)) / SQRT( TEMP )\n END IF\n GO TO 235\n END IF\nC ------------------------------------------------------------------\nC\nC Here for Cases 2 and 3.\nc\nC Set SIZE = max abs value of elts in col NP2.\nC SIZE is used to scale quantities to avoid possible\nc trouble due to overflow or underflow.\nC\n SIZE = ZERO\n DO 215 I = 1,MIN(NP2,M)\n W(I,NP2) = ABS(W(I,NP2)*W(I,NP3))\n SIZE = MAX( SIZE, W(I,NP2) )\n 215 CONTINUE\nc SIZE will be zero if and only if all of\nc the given Y() data is zero.\nc\n IF( SIZE .EQ. ZERO) THEN\n SIGFAC = ZERO\n NSOLVE = 1\n GO TO 235\n END IF\nC ------------------------------------------------------------------\nC\nc Col NP2 now contains data from which sums of squares of\nc residuals can be computed for various possible settings\nc of NSOLVE. We will set LIMIT = the largest row index to\nc be used in Col NP2 in analyzing residual norms.\nc In the usual case of M .ge. NP2, we set LIMIT = NP2.\nc Otherwise, when M .le. NP1, we set LIMIT = M+1 and set\nc W(LIMIT,NP2) = 0. This reflects the fact that there is the\nc possibility of reducing the residual norm to zero by\nc exact interpolation when M .le. NP1. The subr will do this\nc unless it must set NSOLVE smaller than M due to IRANK being\nc less than M.\nC Transform col NP2 so the (i+1)-st elt is\nc Sum(i) divided by SIZE**2, where Sum(i)\nc is the sum of squares of weighted residuals that\nc would be obtained if only the first i coefficients\nc were computed.\nc\n IF( M .GE. NP2 ) THEN\n LIMIT = NP2\n ELSE\n LIMIT = M + 1\n W(LIMIT,NP2) = ZERO\n END IF\nC\n W(LIMIT,NP2) = (W(LIMIT,NP2)/SIZE)**2\n DO 220 I = LIMIT-1, 1, -1\n W(I,NP2) = ( W(I,NP2)/SIZE )**2 + W(I+1,NP2)\n 220 CONTINUE\nc ------------------------------------------------------------------\nc\nc > Do Case 3 if SEEKN is true, and Case 2 if SEEKN is false.\nc\n IF( SEEKN ) THEN\nc > Divide each W(i,NP2) by the no. of degrees of\nc > freedom which is M - (i-1).\nc > Then set CMIN = smallest of these quotients.\nc > Then set NSOLVE.\nc\n DENOM = M\n W(1,NP2) = W(1,NP2) / DENOM\n CMIN = W(1,NP2)\n DO 222 I = 2, IRANK + 1\n DENOM = MAX( DENOM-1, ONE)\n W(I,NP2) = W(I,NP2) / DENOM\n CMIN = MIN( CMIN, W(I,NP2) )\n 222 CONTINUE\nc\n TEMP = FAC * CMIN\n DO 230 I=1, IRANK+1\n IF(W(I,NP2) .LE. TEMP) THEN\n NSOLVE = I-1\n GO TO 232\n END IF\n 230 CONTINUE\n 232 CONTINUE\n ELSE\n DENOM = MAX(M-NSOLVE, 1)\n W(NSOLVE+1,NP2) = W(NSOLVE+1,NP2) / DENOM\n END IF\nc\n SIGFAC = SIZE * SQRT( W(NSOLVE+1, NP2) )\nC ------------------------------------------------------------------\nC\nC Solve for NSOLVE coefficients.\nC\n 235 CONTINUE\n DO 290 I=NSOLVE,1,-1\n T = P(I+2)\nc Fortran 77 will skip this loop when I .EQ. NSOLVE.\n DO 270 J = I+1,NSOLVE\n T = T - W(I,J) * P(J+2)\n 270 CONTINUE\n P(I+2) = T / W(I,I)\n 290 CONTINUE\nC ------------------------------------------------------------------\nC\nC Set missing high order coeffs to zero.\nc\nC Counting on Fortran 77 skipping following loop if\nc NSOLVE .GE. NP1.\nC\n DO 300 I = NSOLVE+1, NP1\n 300 P(I+2) = ZERO\n NFIT = max(NSOLVE - 1, 0)\n RETURN\n END\n", "meta": {"hexsha": "0d51f61a2ed0ac73417accfa7c6b759f39ef8add", "size": 15611, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/spfit.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/spfit.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/spfit.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 39.1253132832, "max_line_length": 72, "alphanum_fraction": 0.5157260906, "num_tokens": 4729, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693688269984, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7872177969014292}} {"text": " PROGRAM xeigsrt\r\nC driver for routine eigsrt\r\n INTEGER NP\r\n PARAMETER(NP=10)\r\n INTEGER i,j,nrot\r\n REAL d(NP),v(NP,NP),c(NP,NP)\r\n DATA c /5.0,4.3,3.0,2.0,1.0,0.0,-1.0,-2.0,-3.0,-4.0,\r\n * 4.3,5.1,4.0,3.0,2.0,1.0,0.0,-1.0,-2.0,-3.0,\r\n * 3.0,4.0,5.0,4.0,3.0,2.0,1.0,0.0,-1.0,-2.0,\r\n * 2.0,3.0,4.0,5.0,4.0,3.0,2.0,1.0,0.0,-1.0,\r\n * 1.0,2.0,3.0,4.0,5.0,4.0,3.0,2.0,1.0,0.0,\r\n * 0.0,1.0,2.0,3.0,4.0,5.0,4.0,3.0,2.0,1.0,\r\n * -1.0,0.0,1.0,2.0,3.0,4.0,5.0,4.0,3.0,2.0,\r\n * -2.0,-1.0,0.0,1.0,2.0,3.0,4.0,5.0,4.0,3.0,\r\n * -3.0,-2.0,-1.0,0.0,1.0,2.0,3.0,4.0,5.0,4.0,\r\n * -4.0,-3.0,-2.0,-1.0,0.0,1.0,2.0,3.0,4.0,5.0/\r\n call jacobi(c,NP,NP,d,v,nrot)\r\n write(*,*) 'Unsorted Eigenvectors:'\r\n do 11 i=1,NP\r\n write(*,'(/1x,a,i3,a,f12.6)') 'Eigenvalue',i,' =',d(i)\r\n write(*,*) 'Eigenvector:'\r\n write(*,'(10x,5f12.6)') (v(j,i),j=1,NP)\r\n11 continue\r\n write(*,'(//,1x,a,//)') '****** sorting ******'\r\n call eigsrt(d,v,NP,NP)\r\n write(*,*) 'Sorted Eigenvectors:'\r\n do 12 i=1,NP\r\n write(*,'(/1x,a,i3,a,f12.6)') 'Eigenvalue',i,' =',d(i)\r\n write(*,*) 'Eigenvector:'\r\n write(*,'(10x,5f12.6)') (v(j,i),j=1,NP)\r\n12 continue\r\n END\r\n", "meta": {"hexsha": "8ca84759e62cfda5e25cb11ff2df595c7e5c46fd", "size": 1296, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xeigsrt.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xeigsrt.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xeigsrt.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.2727272727, "max_line_length": 63, "alphanum_fraction": 0.4328703704, "num_tokens": 725, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.8688267694452331, "lm_q1q2_score": 0.7871482087940005}} {"text": "!solve eq x=cos(x)\nprogram xcosx\n implicit none\n real x1,x2,eps\n integer it,itmax \n x1=0\n eps=1e-7\n itmax=10000000\n do it =1,itmax\n x2=cos(x1)\n if(abs(x2-x1) itmax) then \n print *,'No Convergence!'\n else \n print *,\"X=\",x2,cos(x2)-x2,it\n endif\n\nend program xcosx", "meta": {"hexsha": "37d1aebebd2a6c01fd0280de97e630195870c647", "size": 364, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "90and95/solveNonLinear/xcosx/xcosx.f90", "max_stars_repo_name": "terasakisatoshi/Fortran", "max_stars_repo_head_hexsha": "f2d7c94ad7a7efcd6545800b54674452d45a98f3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "90and95/solveNonLinear/xcosx/xcosx.f90", "max_issues_repo_name": "terasakisatoshi/Fortran", "max_issues_repo_head_hexsha": "f2d7c94ad7a7efcd6545800b54674452d45a98f3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "90and95/solveNonLinear/xcosx/xcosx.f90", "max_forks_repo_name": "terasakisatoshi/Fortran", "max_forks_repo_head_hexsha": "f2d7c94ad7a7efcd6545800b54674452d45a98f3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.3333333333, "max_line_length": 37, "alphanum_fraction": 0.5412087912, "num_tokens": 138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.7871141284316833}} {"text": "*> \\brief \\b SGET24\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE SGET24( COMP, JTYPE, THRESH, ISEED, NOUNIT, N, A, LDA,\n* H, HT, WR, WI, WRT, WIT, WRTMP, WITMP, VS,\n* LDVS, VS1, RCDEIN, RCDVIN, NSLCT, ISLCT,\n* RESULT, WORK, LWORK, IWORK, BWORK, INFO )\n*\n* .. Scalar Arguments ..\n* LOGICAL COMP\n* INTEGER INFO, JTYPE, LDA, LDVS, LWORK, N, NOUNIT, NSLCT\n* REAL RCDEIN, RCDVIN, THRESH\n* ..\n* .. Array Arguments ..\n* LOGICAL BWORK( * )\n* INTEGER ISEED( 4 ), ISLCT( * ), IWORK( * )\n* REAL A( LDA, * ), H( LDA, * ), HT( LDA, * ),\n* $ RESULT( 17 ), VS( LDVS, * ), VS1( LDVS, * ),\n* $ WI( * ), WIT( * ), WITMP( * ), WORK( * ),\n* $ WR( * ), WRT( * ), WRTMP( * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> SGET24 checks the nonsymmetric eigenvalue (Schur form) problem\n*> expert driver SGEESX.\n*>\n*> If COMP = .FALSE., the first 13 of the following tests will be\n*> be performed on the input matrix A, and also tests 14 and 15\n*> if LWORK is sufficiently large.\n*> If COMP = .TRUE., all 17 test will be performed.\n*>\n*> (1) 0 if T is in Schur form, 1/ulp otherwise\n*> (no sorting of eigenvalues)\n*>\n*> (2) | A - VS T VS' | / ( n |A| ulp )\n*>\n*> Here VS is the matrix of Schur eigenvectors, and T is in Schur\n*> form (no sorting of eigenvalues).\n*>\n*> (3) | I - VS VS' | / ( n ulp ) (no sorting of eigenvalues).\n*>\n*> (4) 0 if WR+sqrt(-1)*WI are eigenvalues of T\n*> 1/ulp otherwise\n*> (no sorting of eigenvalues)\n*>\n*> (5) 0 if T(with VS) = T(without VS),\n*> 1/ulp otherwise\n*> (no sorting of eigenvalues)\n*>\n*> (6) 0 if eigenvalues(with VS) = eigenvalues(without VS),\n*> 1/ulp otherwise\n*> (no sorting of eigenvalues)\n*>\n*> (7) 0 if T is in Schur form, 1/ulp otherwise\n*> (with sorting of eigenvalues)\n*>\n*> (8) | A - VS T VS' | / ( n |A| ulp )\n*>\n*> Here VS is the matrix of Schur eigenvectors, and T is in Schur\n*> form (with sorting of eigenvalues).\n*>\n*> (9) | I - VS VS' | / ( n ulp ) (with sorting of eigenvalues).\n*>\n*> (10) 0 if WR+sqrt(-1)*WI are eigenvalues of T\n*> 1/ulp otherwise\n*> If workspace sufficient, also compare WR, WI with and\n*> without reciprocal condition numbers\n*> (with sorting of eigenvalues)\n*>\n*> (11) 0 if T(with VS) = T(without VS),\n*> 1/ulp otherwise\n*> If workspace sufficient, also compare T with and without\n*> reciprocal condition numbers\n*> (with sorting of eigenvalues)\n*>\n*> (12) 0 if eigenvalues(with VS) = eigenvalues(without VS),\n*> 1/ulp otherwise\n*> If workspace sufficient, also compare VS with and without\n*> reciprocal condition numbers\n*> (with sorting of eigenvalues)\n*>\n*> (13) if sorting worked and SDIM is the number of\n*> eigenvalues which were SELECTed\n*> If workspace sufficient, also compare SDIM with and\n*> without reciprocal condition numbers\n*>\n*> (14) if RCONDE the same no matter if VS and/or RCONDV computed\n*>\n*> (15) if RCONDV the same no matter if VS and/or RCONDE computed\n*>\n*> (16) |RCONDE - RCDEIN| / cond(RCONDE)\n*>\n*> RCONDE is the reciprocal average eigenvalue condition number\n*> computed by SGEESX and RCDEIN (the precomputed true value)\n*> is supplied as input. cond(RCONDE) is the condition number\n*> of RCONDE, and takes errors in computing RCONDE into account,\n*> so that the resulting quantity should be O(ULP). cond(RCONDE)\n*> is essentially given by norm(A)/RCONDV.\n*>\n*> (17) |RCONDV - RCDVIN| / cond(RCONDV)\n*>\n*> RCONDV is the reciprocal right invariant subspace condition\n*> number computed by SGEESX and RCDVIN (the precomputed true\n*> value) is supplied as input. cond(RCONDV) is the condition\n*> number of RCONDV, and takes errors in computing RCONDV into\n*> account, so that the resulting quantity should be O(ULP).\n*> cond(RCONDV) is essentially given by norm(A)/RCONDE.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] COMP\n*> \\verbatim\n*> COMP is LOGICAL\n*> COMP describes which input tests to perform:\n*> = .FALSE. if the computed condition numbers are not to\n*> be tested against RCDVIN and RCDEIN\n*> = .TRUE. if they are to be compared\n*> \\endverbatim\n*>\n*> \\param[in] JTYPE\n*> \\verbatim\n*> JTYPE is INTEGER\n*> Type of input matrix. Used to label output if error occurs.\n*> \\endverbatim\n*>\n*> \\param[in] ISEED\n*> \\verbatim\n*> ISEED is INTEGER array, dimension (4)\n*> If COMP = .FALSE., the random number generator seed\n*> used to produce matrix.\n*> If COMP = .TRUE., ISEED(1) = the number of the example.\n*> Used to label output if error occurs.\n*> \\endverbatim\n*>\n*> \\param[in] THRESH\n*> \\verbatim\n*> THRESH is REAL\n*> A test will count as \"failed\" if the \"error\", computed as\n*> described above, exceeds THRESH. Note that the error\n*> is scaled to be O(1), so THRESH should be a reasonably\n*> small multiple of 1, e.g., 10 or 100. In particular,\n*> it should not depend on the precision (single vs. double)\n*> or the size of the matrix. It must be at least zero.\n*> \\endverbatim\n*>\n*> \\param[in] NOUNIT\n*> \\verbatim\n*> NOUNIT is INTEGER\n*> The FORTRAN unit number for printing out error messages\n*> (e.g., if a routine returns INFO not equal to 0.)\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The dimension of A. N must be at least 0.\n*> \\endverbatim\n*>\n*> \\param[in,out] A\n*> \\verbatim\n*> A is REAL array, dimension (LDA, N)\n*> Used to hold the matrix whose eigenvalues are to be\n*> computed.\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of A, and H. LDA must be at\n*> least 1 and at least N.\n*> \\endverbatim\n*>\n*> \\param[out] H\n*> \\verbatim\n*> H is REAL array, dimension (LDA, N)\n*> Another copy of the test matrix A, modified by SGEESX.\n*> \\endverbatim\n*>\n*> \\param[out] HT\n*> \\verbatim\n*> HT is REAL array, dimension (LDA, N)\n*> Yet another copy of the test matrix A, modified by SGEESX.\n*> \\endverbatim\n*>\n*> \\param[out] WR\n*> \\verbatim\n*> WR is REAL array, dimension (N)\n*> \\endverbatim\n*>\n*> \\param[out] WI\n*> \\verbatim\n*> WI is REAL array, dimension (N)\n*>\n*> The real and imaginary parts of the eigenvalues of A.\n*> On exit, WR + WI*i are the eigenvalues of the matrix in A.\n*> \\endverbatim\n*>\n*> \\param[out] WRT\n*> \\verbatim\n*> WRT is REAL array, dimension (N)\n*> \\endverbatim\n*>\n*> \\param[out] WIT\n*> \\verbatim\n*> WIT is REAL array, dimension (N)\n*>\n*> Like WR, WI, these arrays contain the eigenvalues of A,\n*> but those computed when SGEESX only computes a partial\n*> eigendecomposition, i.e. not Schur vectors\n*> \\endverbatim\n*>\n*> \\param[out] WRTMP\n*> \\verbatim\n*> WRTMP is REAL array, dimension (N)\n*> \\endverbatim\n*>\n*> \\param[out] WITMP\n*> \\verbatim\n*> WITMP is REAL array, dimension (N)\n*>\n*> Like WR, WI, these arrays contain the eigenvalues of A,\n*> but sorted by increasing real part.\n*> \\endverbatim\n*>\n*> \\param[out] VS\n*> \\verbatim\n*> VS is REAL array, dimension (LDVS, N)\n*> VS holds the computed Schur vectors.\n*> \\endverbatim\n*>\n*> \\param[in] LDVS\n*> \\verbatim\n*> LDVS is INTEGER\n*> Leading dimension of VS. Must be at least max(1, N).\n*> \\endverbatim\n*>\n*> \\param[out] VS1\n*> \\verbatim\n*> VS1 is REAL array, dimension (LDVS, N)\n*> VS1 holds another copy of the computed Schur vectors.\n*> \\endverbatim\n*>\n*> \\param[in] RCDEIN\n*> \\verbatim\n*> RCDEIN is REAL\n*> When COMP = .TRUE. RCDEIN holds the precomputed reciprocal\n*> condition number for the average of selected eigenvalues.\n*> \\endverbatim\n*>\n*> \\param[in] RCDVIN\n*> \\verbatim\n*> RCDVIN is REAL\n*> When COMP = .TRUE. RCDVIN holds the precomputed reciprocal\n*> condition number for the selected right invariant subspace.\n*> \\endverbatim\n*>\n*> \\param[in] NSLCT\n*> \\verbatim\n*> NSLCT is INTEGER\n*> When COMP = .TRUE. the number of selected eigenvalues\n*> corresponding to the precomputed values RCDEIN and RCDVIN.\n*> \\endverbatim\n*>\n*> \\param[in] ISLCT\n*> \\verbatim\n*> ISLCT is INTEGER array, dimension (NSLCT)\n*> When COMP = .TRUE. ISLCT selects the eigenvalues of the\n*> input matrix corresponding to the precomputed values RCDEIN\n*> and RCDVIN. For I=1, ... ,NSLCT, if ISLCT(I) = J, then the\n*> eigenvalue with the J-th largest real part is selected.\n*> Not referenced if COMP = .FALSE.\n*> \\endverbatim\n*>\n*> \\param[out] RESULT\n*> \\verbatim\n*> RESULT is REAL array, dimension (17)\n*> The values computed by the 17 tests described above.\n*> The values are currently limited to 1/ulp, to avoid\n*> overflow.\n*> \\endverbatim\n*>\n*> \\param[out] WORK\n*> \\verbatim\n*> WORK is REAL array, dimension (LWORK)\n*> \\endverbatim\n*>\n*> \\param[in] LWORK\n*> \\verbatim\n*> LWORK is INTEGER\n*> The number of entries in WORK to be passed to SGEESX. This\n*> must be at least 3*N, and N+N**2 if tests 14--16 are to\n*> be performed.\n*> \\endverbatim\n*>\n*> \\param[out] IWORK\n*> \\verbatim\n*> IWORK is INTEGER array, dimension (N*N)\n*> \\endverbatim\n*>\n*> \\param[out] BWORK\n*> \\verbatim\n*> BWORK is LOGICAL array, dimension (N)\n*> \\endverbatim\n*>\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> If 0, successful exit.\n*> If <0, input parameter -INFO had an incorrect value.\n*> If >0, SGEESX returned an error code, the absolute\n*> value of which is returned.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\date December 2016\n*\n*> \\ingroup single_eig\n*\n* =====================================================================\n SUBROUTINE SGET24( COMP, JTYPE, THRESH, ISEED, NOUNIT, N, A, LDA,\n $ H, HT, WR, WI, WRT, WIT, WRTMP, WITMP, VS,\n $ LDVS, VS1, RCDEIN, RCDVIN, NSLCT, ISLCT,\n $ RESULT, WORK, LWORK, IWORK, BWORK, INFO )\n*\n* -- LAPACK test routine (version 3.7.0) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* December 2016\n*\n* .. Scalar Arguments ..\n LOGICAL COMP\n INTEGER INFO, JTYPE, LDA, LDVS, LWORK, N, NOUNIT, NSLCT\n REAL RCDEIN, RCDVIN, THRESH\n* ..\n* .. Array Arguments ..\n LOGICAL BWORK( * )\n INTEGER ISEED( 4 ), ISLCT( * ), IWORK( * )\n REAL A( LDA, * ), H( LDA, * ), HT( LDA, * ),\n $ RESULT( 17 ), VS( LDVS, * ), VS1( LDVS, * ),\n $ WI( * ), WIT( * ), WITMP( * ), WORK( * ),\n $ WR( * ), WRT( * ), WRTMP( * )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n REAL ZERO, ONE\n PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )\n REAL EPSIN\n PARAMETER ( EPSIN = 5.9605E-8 )\n* ..\n* .. Local Scalars ..\n CHARACTER SORT\n INTEGER I, IINFO, ISORT, ITMP, J, KMIN, KNTEIG, LIWORK,\n $ RSUB, SDIM, SDIM1\n REAL ANORM, EPS, RCNDE1, RCNDV1, RCONDE, RCONDV,\n $ SMLNUM, TMP, TOL, TOLIN, ULP, ULPINV, V, VIMIN,\n $ VRMIN, WNORM\n* ..\n* .. Local Arrays ..\n INTEGER IPNT( 20 )\n* ..\n* .. Arrays in Common ..\n LOGICAL SELVAL( 20 )\n REAL SELWI( 20 ), SELWR( 20 )\n* ..\n* .. Scalars in Common ..\n INTEGER SELDIM, SELOPT\n* ..\n* .. Common blocks ..\n COMMON / SSLCT / SELOPT, SELDIM, SELVAL, SELWR, SELWI\n* ..\n* .. External Functions ..\n LOGICAL SSLECT\n REAL SLAMCH, SLANGE\n EXTERNAL SSLECT, SLAMCH, SLANGE\n* ..\n* .. External Subroutines ..\n EXTERNAL SCOPY, SGEESX, SGEMM, SLACPY, SORT01, XERBLA\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC ABS, MAX, MIN, REAL, SIGN, SQRT\n* ..\n* .. Executable Statements ..\n*\n* Check for errors\n*\n INFO = 0\n IF( THRESH.LT.ZERO ) THEN\n INFO = -3\n ELSE IF( NOUNIT.LE.0 ) THEN\n INFO = -5\n ELSE IF( N.LT.0 ) THEN\n INFO = -6\n ELSE IF( LDA.LT.1 .OR. LDA.LT.N ) THEN\n INFO = -8\n ELSE IF( LDVS.LT.1 .OR. LDVS.LT.N ) THEN\n INFO = -18\n ELSE IF( LWORK.LT.3*N ) THEN\n INFO = -26\n END IF\n*\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'SGET24', -INFO )\n RETURN\n END IF\n*\n* Quick return if nothing to do\n*\n DO 10 I = 1, 17\n RESULT( I ) = -ONE\n 10 CONTINUE\n*\n IF( N.EQ.0 )\n $ RETURN\n*\n* Important constants\n*\n SMLNUM = SLAMCH( 'Safe minimum' )\n ULP = SLAMCH( 'Precision' )\n ULPINV = ONE / ULP\n*\n* Perform tests (1)-(13)\n*\n SELOPT = 0\n LIWORK = N*N\n DO 120 ISORT = 0, 1\n IF( ISORT.EQ.0 ) THEN\n SORT = 'N'\n RSUB = 0\n ELSE\n SORT = 'S'\n RSUB = 6\n END IF\n*\n* Compute Schur form and Schur vectors, and test them\n*\n CALL SLACPY( 'F', N, N, A, LDA, H, LDA )\n CALL SGEESX( 'V', SORT, SSLECT, 'N', N, H, LDA, SDIM, WR, WI,\n $ VS, LDVS, RCONDE, RCONDV, WORK, LWORK, IWORK,\n $ LIWORK, BWORK, IINFO )\n IF( IINFO.NE.0 .AND. IINFO.NE.N+2 ) THEN\n RESULT( 1+RSUB ) = ULPINV\n IF( JTYPE.NE.22 ) THEN\n WRITE( NOUNIT, FMT = 9998 )'SGEESX1', IINFO, N, JTYPE,\n $ ISEED\n ELSE\n WRITE( NOUNIT, FMT = 9999 )'SGEESX1', IINFO, N,\n $ ISEED( 1 )\n END IF\n INFO = ABS( IINFO )\n RETURN\n END IF\n IF( ISORT.EQ.0 ) THEN\n CALL SCOPY( N, WR, 1, WRTMP, 1 )\n CALL SCOPY( N, WI, 1, WITMP, 1 )\n END IF\n*\n* Do Test (1) or Test (7)\n*\n RESULT( 1+RSUB ) = ZERO\n DO 30 J = 1, N - 2\n DO 20 I = J + 2, N\n IF( H( I, J ).NE.ZERO )\n $ RESULT( 1+RSUB ) = ULPINV\n 20 CONTINUE\n 30 CONTINUE\n DO 40 I = 1, N - 2\n IF( H( I+1, I ).NE.ZERO .AND. H( I+2, I+1 ).NE.ZERO )\n $ RESULT( 1+RSUB ) = ULPINV\n 40 CONTINUE\n DO 50 I = 1, N - 1\n IF( H( I+1, I ).NE.ZERO ) THEN\n IF( H( I, I ).NE.H( I+1, I+1 ) .OR. H( I, I+1 ).EQ.\n $ ZERO .OR. SIGN( ONE, H( I+1, I ) ).EQ.\n $ SIGN( ONE, H( I, I+1 ) ) )RESULT( 1+RSUB ) = ULPINV\n END IF\n 50 CONTINUE\n*\n* Test (2) or (8): Compute norm(A - Q*H*Q') / (norm(A) * N * ULP)\n*\n* Copy A to VS1, used as workspace\n*\n CALL SLACPY( ' ', N, N, A, LDA, VS1, LDVS )\n*\n* Compute Q*H and store in HT.\n*\n CALL SGEMM( 'No transpose', 'No transpose', N, N, N, ONE, VS,\n $ LDVS, H, LDA, ZERO, HT, LDA )\n*\n* Compute A - Q*H*Q'\n*\n CALL SGEMM( 'No transpose', 'Transpose', N, N, N, -ONE, HT,\n $ LDA, VS, LDVS, ONE, VS1, LDVS )\n*\n ANORM = MAX( SLANGE( '1', N, N, A, LDA, WORK ), SMLNUM )\n WNORM = SLANGE( '1', N, N, VS1, LDVS, WORK )\n*\n IF( ANORM.GT.WNORM ) THEN\n RESULT( 2+RSUB ) = ( WNORM / ANORM ) / ( N*ULP )\n ELSE\n IF( ANORM.LT.ONE ) THEN\n RESULT( 2+RSUB ) = ( MIN( WNORM, N*ANORM ) / ANORM ) /\n $ ( N*ULP )\n ELSE\n RESULT( 2+RSUB ) = MIN( WNORM / ANORM, REAL( N ) ) /\n $ ( N*ULP )\n END IF\n END IF\n*\n* Test (3) or (9): Compute norm( I - Q'*Q ) / ( N * ULP )\n*\n CALL SORT01( 'Columns', N, N, VS, LDVS, WORK, LWORK,\n $ RESULT( 3+RSUB ) )\n*\n* Do Test (4) or Test (10)\n*\n RESULT( 4+RSUB ) = ZERO\n DO 60 I = 1, N\n IF( H( I, I ).NE.WR( I ) )\n $ RESULT( 4+RSUB ) = ULPINV\n 60 CONTINUE\n IF( N.GT.1 ) THEN\n IF( H( 2, 1 ).EQ.ZERO .AND. WI( 1 ).NE.ZERO )\n $ RESULT( 4+RSUB ) = ULPINV\n IF( H( N, N-1 ).EQ.ZERO .AND. WI( N ).NE.ZERO )\n $ RESULT( 4+RSUB ) = ULPINV\n END IF\n DO 70 I = 1, N - 1\n IF( H( I+1, I ).NE.ZERO ) THEN\n TMP = SQRT( ABS( H( I+1, I ) ) )*\n $ SQRT( ABS( H( I, I+1 ) ) )\n RESULT( 4+RSUB ) = MAX( RESULT( 4+RSUB ),\n $ ABS( WI( I )-TMP ) /\n $ MAX( ULP*TMP, SMLNUM ) )\n RESULT( 4+RSUB ) = MAX( RESULT( 4+RSUB ),\n $ ABS( WI( I+1 )+TMP ) /\n $ MAX( ULP*TMP, SMLNUM ) )\n ELSE IF( I.GT.1 ) THEN\n IF( H( I+1, I ).EQ.ZERO .AND. H( I, I-1 ).EQ.ZERO .AND.\n $ WI( I ).NE.ZERO )RESULT( 4+RSUB ) = ULPINV\n END IF\n 70 CONTINUE\n*\n* Do Test (5) or Test (11)\n*\n CALL SLACPY( 'F', N, N, A, LDA, HT, LDA )\n CALL SGEESX( 'N', SORT, SSLECT, 'N', N, HT, LDA, SDIM, WRT,\n $ WIT, VS, LDVS, RCONDE, RCONDV, WORK, LWORK, IWORK,\n $ LIWORK, BWORK, IINFO )\n IF( IINFO.NE.0 .AND. IINFO.NE.N+2 ) THEN\n RESULT( 5+RSUB ) = ULPINV\n IF( JTYPE.NE.22 ) THEN\n WRITE( NOUNIT, FMT = 9998 )'SGEESX2', IINFO, N, JTYPE,\n $ ISEED\n ELSE\n WRITE( NOUNIT, FMT = 9999 )'SGEESX2', IINFO, N,\n $ ISEED( 1 )\n END IF\n INFO = ABS( IINFO )\n GO TO 250\n END IF\n*\n RESULT( 5+RSUB ) = ZERO\n DO 90 J = 1, N\n DO 80 I = 1, N\n IF( H( I, J ).NE.HT( I, J ) )\n $ RESULT( 5+RSUB ) = ULPINV\n 80 CONTINUE\n 90 CONTINUE\n*\n* Do Test (6) or Test (12)\n*\n RESULT( 6+RSUB ) = ZERO\n DO 100 I = 1, N\n IF( WR( I ).NE.WRT( I ) .OR. WI( I ).NE.WIT( I ) )\n $ RESULT( 6+RSUB ) = ULPINV\n 100 CONTINUE\n*\n* Do Test (13)\n*\n IF( ISORT.EQ.1 ) THEN\n RESULT( 13 ) = ZERO\n KNTEIG = 0\n DO 110 I = 1, N\n IF( SSLECT( WR( I ), WI( I ) ) .OR.\n $ SSLECT( WR( I ), -WI( I ) ) )KNTEIG = KNTEIG + 1\n IF( I.LT.N ) THEN\n IF( ( SSLECT( WR( I+1 ), WI( I+1 ) ) .OR.\n $ SSLECT( WR( I+1 ), -WI( I+1 ) ) ) .AND.\n $ ( .NOT.( SSLECT( WR( I ),\n $ WI( I ) ) .OR. SSLECT( WR( I ),\n $ -WI( I ) ) ) ) .AND. IINFO.NE.N+2 )RESULT( 13 )\n $ = ULPINV\n END IF\n 110 CONTINUE\n IF( SDIM.NE.KNTEIG )\n $ RESULT( 13 ) = ULPINV\n END IF\n*\n 120 CONTINUE\n*\n* If there is enough workspace, perform tests (14) and (15)\n* as well as (10) through (13)\n*\n IF( LWORK.GE.N+( N*N ) / 2 ) THEN\n*\n* Compute both RCONDE and RCONDV with VS\n*\n SORT = 'S'\n RESULT( 14 ) = ZERO\n RESULT( 15 ) = ZERO\n CALL SLACPY( 'F', N, N, A, LDA, HT, LDA )\n CALL SGEESX( 'V', SORT, SSLECT, 'B', N, HT, LDA, SDIM1, WRT,\n $ WIT, VS1, LDVS, RCONDE, RCONDV, WORK, LWORK,\n $ IWORK, LIWORK, BWORK, IINFO )\n IF( IINFO.NE.0 .AND. IINFO.NE.N+2 ) THEN\n RESULT( 14 ) = ULPINV\n RESULT( 15 ) = ULPINV\n IF( JTYPE.NE.22 ) THEN\n WRITE( NOUNIT, FMT = 9998 )'SGEESX3', IINFO, N, JTYPE,\n $ ISEED\n ELSE\n WRITE( NOUNIT, FMT = 9999 )'SGEESX3', IINFO, N,\n $ ISEED( 1 )\n END IF\n INFO = ABS( IINFO )\n GO TO 250\n END IF\n*\n* Perform tests (10), (11), (12), and (13)\n*\n DO 140 I = 1, N\n IF( WR( I ).NE.WRT( I ) .OR. WI( I ).NE.WIT( I ) )\n $ RESULT( 10 ) = ULPINV\n DO 130 J = 1, N\n IF( H( I, J ).NE.HT( I, J ) )\n $ RESULT( 11 ) = ULPINV\n IF( VS( I, J ).NE.VS1( I, J ) )\n $ RESULT( 12 ) = ULPINV\n 130 CONTINUE\n 140 CONTINUE\n IF( SDIM.NE.SDIM1 )\n $ RESULT( 13 ) = ULPINV\n*\n* Compute both RCONDE and RCONDV without VS, and compare\n*\n CALL SLACPY( 'F', N, N, A, LDA, HT, LDA )\n CALL SGEESX( 'N', SORT, SSLECT, 'B', N, HT, LDA, SDIM1, WRT,\n $ WIT, VS1, LDVS, RCNDE1, RCNDV1, WORK, LWORK,\n $ IWORK, LIWORK, BWORK, IINFO )\n IF( IINFO.NE.0 .AND. IINFO.NE.N+2 ) THEN\n RESULT( 14 ) = ULPINV\n RESULT( 15 ) = ULPINV\n IF( JTYPE.NE.22 ) THEN\n WRITE( NOUNIT, FMT = 9998 )'SGEESX4', IINFO, N, JTYPE,\n $ ISEED\n ELSE\n WRITE( NOUNIT, FMT = 9999 )'SGEESX4', IINFO, N,\n $ ISEED( 1 )\n END IF\n INFO = ABS( IINFO )\n GO TO 250\n END IF\n*\n* Perform tests (14) and (15)\n*\n IF( RCNDE1.NE.RCONDE )\n $ RESULT( 14 ) = ULPINV\n IF( RCNDV1.NE.RCONDV )\n $ RESULT( 15 ) = ULPINV\n*\n* Perform tests (10), (11), (12), and (13)\n*\n DO 160 I = 1, N\n IF( WR( I ).NE.WRT( I ) .OR. WI( I ).NE.WIT( I ) )\n $ RESULT( 10 ) = ULPINV\n DO 150 J = 1, N\n IF( H( I, J ).NE.HT( I, J ) )\n $ RESULT( 11 ) = ULPINV\n IF( VS( I, J ).NE.VS1( I, J ) )\n $ RESULT( 12 ) = ULPINV\n 150 CONTINUE\n 160 CONTINUE\n IF( SDIM.NE.SDIM1 )\n $ RESULT( 13 ) = ULPINV\n*\n* Compute RCONDE with VS, and compare\n*\n CALL SLACPY( 'F', N, N, A, LDA, HT, LDA )\n CALL SGEESX( 'V', SORT, SSLECT, 'E', N, HT, LDA, SDIM1, WRT,\n $ WIT, VS1, LDVS, RCNDE1, RCNDV1, WORK, LWORK,\n $ IWORK, LIWORK, BWORK, IINFO )\n IF( IINFO.NE.0 .AND. IINFO.NE.N+2 ) THEN\n RESULT( 14 ) = ULPINV\n IF( JTYPE.NE.22 ) THEN\n WRITE( NOUNIT, FMT = 9998 )'SGEESX5', IINFO, N, JTYPE,\n $ ISEED\n ELSE\n WRITE( NOUNIT, FMT = 9999 )'SGEESX5', IINFO, N,\n $ ISEED( 1 )\n END IF\n INFO = ABS( IINFO )\n GO TO 250\n END IF\n*\n* Perform test (14)\n*\n IF( RCNDE1.NE.RCONDE )\n $ RESULT( 14 ) = ULPINV\n*\n* Perform tests (10), (11), (12), and (13)\n*\n DO 180 I = 1, N\n IF( WR( I ).NE.WRT( I ) .OR. WI( I ).NE.WIT( I ) )\n $ RESULT( 10 ) = ULPINV\n DO 170 J = 1, N\n IF( H( I, J ).NE.HT( I, J ) )\n $ RESULT( 11 ) = ULPINV\n IF( VS( I, J ).NE.VS1( I, J ) )\n $ RESULT( 12 ) = ULPINV\n 170 CONTINUE\n 180 CONTINUE\n IF( SDIM.NE.SDIM1 )\n $ RESULT( 13 ) = ULPINV\n*\n* Compute RCONDE without VS, and compare\n*\n CALL SLACPY( 'F', N, N, A, LDA, HT, LDA )\n CALL SGEESX( 'N', SORT, SSLECT, 'E', N, HT, LDA, SDIM1, WRT,\n $ WIT, VS1, LDVS, RCNDE1, RCNDV1, WORK, LWORK,\n $ IWORK, LIWORK, BWORK, IINFO )\n IF( IINFO.NE.0 .AND. IINFO.NE.N+2 ) THEN\n RESULT( 14 ) = ULPINV\n IF( JTYPE.NE.22 ) THEN\n WRITE( NOUNIT, FMT = 9998 )'SGEESX6', IINFO, N, JTYPE,\n $ ISEED\n ELSE\n WRITE( NOUNIT, FMT = 9999 )'SGEESX6', IINFO, N,\n $ ISEED( 1 )\n END IF\n INFO = ABS( IINFO )\n GO TO 250\n END IF\n*\n* Perform test (14)\n*\n IF( RCNDE1.NE.RCONDE )\n $ RESULT( 14 ) = ULPINV\n*\n* Perform tests (10), (11), (12), and (13)\n*\n DO 200 I = 1, N\n IF( WR( I ).NE.WRT( I ) .OR. WI( I ).NE.WIT( I ) )\n $ RESULT( 10 ) = ULPINV\n DO 190 J = 1, N\n IF( H( I, J ).NE.HT( I, J ) )\n $ RESULT( 11 ) = ULPINV\n IF( VS( I, J ).NE.VS1( I, J ) )\n $ RESULT( 12 ) = ULPINV\n 190 CONTINUE\n 200 CONTINUE\n IF( SDIM.NE.SDIM1 )\n $ RESULT( 13 ) = ULPINV\n*\n* Compute RCONDV with VS, and compare\n*\n CALL SLACPY( 'F', N, N, A, LDA, HT, LDA )\n CALL SGEESX( 'V', SORT, SSLECT, 'V', N, HT, LDA, SDIM1, WRT,\n $ WIT, VS1, LDVS, RCNDE1, RCNDV1, WORK, LWORK,\n $ IWORK, LIWORK, BWORK, IINFO )\n IF( IINFO.NE.0 .AND. IINFO.NE.N+2 ) THEN\n RESULT( 15 ) = ULPINV\n IF( JTYPE.NE.22 ) THEN\n WRITE( NOUNIT, FMT = 9998 )'SGEESX7', IINFO, N, JTYPE,\n $ ISEED\n ELSE\n WRITE( NOUNIT, FMT = 9999 )'SGEESX7', IINFO, N,\n $ ISEED( 1 )\n END IF\n INFO = ABS( IINFO )\n GO TO 250\n END IF\n*\n* Perform test (15)\n*\n IF( RCNDV1.NE.RCONDV )\n $ RESULT( 15 ) = ULPINV\n*\n* Perform tests (10), (11), (12), and (13)\n*\n DO 220 I = 1, N\n IF( WR( I ).NE.WRT( I ) .OR. WI( I ).NE.WIT( I ) )\n $ RESULT( 10 ) = ULPINV\n DO 210 J = 1, N\n IF( H( I, J ).NE.HT( I, J ) )\n $ RESULT( 11 ) = ULPINV\n IF( VS( I, J ).NE.VS1( I, J ) )\n $ RESULT( 12 ) = ULPINV\n 210 CONTINUE\n 220 CONTINUE\n IF( SDIM.NE.SDIM1 )\n $ RESULT( 13 ) = ULPINV\n*\n* Compute RCONDV without VS, and compare\n*\n CALL SLACPY( 'F', N, N, A, LDA, HT, LDA )\n CALL SGEESX( 'N', SORT, SSLECT, 'V', N, HT, LDA, SDIM1, WRT,\n $ WIT, VS1, LDVS, RCNDE1, RCNDV1, WORK, LWORK,\n $ IWORK, LIWORK, BWORK, IINFO )\n IF( IINFO.NE.0 .AND. IINFO.NE.N+2 ) THEN\n RESULT( 15 ) = ULPINV\n IF( JTYPE.NE.22 ) THEN\n WRITE( NOUNIT, FMT = 9998 )'SGEESX8', IINFO, N, JTYPE,\n $ ISEED\n ELSE\n WRITE( NOUNIT, FMT = 9999 )'SGEESX8', IINFO, N,\n $ ISEED( 1 )\n END IF\n INFO = ABS( IINFO )\n GO TO 250\n END IF\n*\n* Perform test (15)\n*\n IF( RCNDV1.NE.RCONDV )\n $ RESULT( 15 ) = ULPINV\n*\n* Perform tests (10), (11), (12), and (13)\n*\n DO 240 I = 1, N\n IF( WR( I ).NE.WRT( I ) .OR. WI( I ).NE.WIT( I ) )\n $ RESULT( 10 ) = ULPINV\n DO 230 J = 1, N\n IF( H( I, J ).NE.HT( I, J ) )\n $ RESULT( 11 ) = ULPINV\n IF( VS( I, J ).NE.VS1( I, J ) )\n $ RESULT( 12 ) = ULPINV\n 230 CONTINUE\n 240 CONTINUE\n IF( SDIM.NE.SDIM1 )\n $ RESULT( 13 ) = ULPINV\n*\n END IF\n*\n 250 CONTINUE\n*\n* If there are precomputed reciprocal condition numbers, compare\n* computed values with them.\n*\n IF( COMP ) THEN\n*\n* First set up SELOPT, SELDIM, SELVAL, SELWR, and SELWI so that\n* the logical function SSLECT selects the eigenvalues specified\n* by NSLCT and ISLCT.\n*\n SELDIM = N\n SELOPT = 1\n EPS = MAX( ULP, EPSIN )\n DO 260 I = 1, N\n IPNT( I ) = I\n SELVAL( I ) = .FALSE.\n SELWR( I ) = WRTMP( I )\n SELWI( I ) = WITMP( I )\n 260 CONTINUE\n DO 280 I = 1, N - 1\n KMIN = I\n VRMIN = WRTMP( I )\n VIMIN = WITMP( I )\n DO 270 J = I + 1, N\n IF( WRTMP( J ).LT.VRMIN ) THEN\n KMIN = J\n VRMIN = WRTMP( J )\n VIMIN = WITMP( J )\n END IF\n 270 CONTINUE\n WRTMP( KMIN ) = WRTMP( I )\n WITMP( KMIN ) = WITMP( I )\n WRTMP( I ) = VRMIN\n WITMP( I ) = VIMIN\n ITMP = IPNT( I )\n IPNT( I ) = IPNT( KMIN )\n IPNT( KMIN ) = ITMP\n 280 CONTINUE\n DO 290 I = 1, NSLCT\n SELVAL( IPNT( ISLCT( I ) ) ) = .TRUE.\n 290 CONTINUE\n*\n* Compute condition numbers\n*\n CALL SLACPY( 'F', N, N, A, LDA, HT, LDA )\n CALL SGEESX( 'N', 'S', SSLECT, 'B', N, HT, LDA, SDIM1, WRT,\n $ WIT, VS1, LDVS, RCONDE, RCONDV, WORK, LWORK,\n $ IWORK, LIWORK, BWORK, IINFO )\n IF( IINFO.NE.0 .AND. IINFO.NE.N+2 ) THEN\n RESULT( 16 ) = ULPINV\n RESULT( 17 ) = ULPINV\n WRITE( NOUNIT, FMT = 9999 )'SGEESX9', IINFO, N, ISEED( 1 )\n INFO = ABS( IINFO )\n GO TO 300\n END IF\n*\n* Compare condition number for average of selected eigenvalues\n* taking its condition number into account\n*\n ANORM = SLANGE( '1', N, N, A, LDA, WORK )\n V = MAX( REAL( N )*EPS*ANORM, SMLNUM )\n IF( ANORM.EQ.ZERO )\n $ V = ONE\n IF( V.GT.RCONDV ) THEN\n TOL = ONE\n ELSE\n TOL = V / RCONDV\n END IF\n IF( V.GT.RCDVIN ) THEN\n TOLIN = ONE\n ELSE\n TOLIN = V / RCDVIN\n END IF\n TOL = MAX( TOL, SMLNUM / EPS )\n TOLIN = MAX( TOLIN, SMLNUM / EPS )\n IF( EPS*( RCDEIN-TOLIN ).GT.RCONDE+TOL ) THEN\n RESULT( 16 ) = ULPINV\n ELSE IF( RCDEIN-TOLIN.GT.RCONDE+TOL ) THEN\n RESULT( 16 ) = ( RCDEIN-TOLIN ) / ( RCONDE+TOL )\n ELSE IF( RCDEIN+TOLIN.LT.EPS*( RCONDE-TOL ) ) THEN\n RESULT( 16 ) = ULPINV\n ELSE IF( RCDEIN+TOLIN.LT.RCONDE-TOL ) THEN\n RESULT( 16 ) = ( RCONDE-TOL ) / ( RCDEIN+TOLIN )\n ELSE\n RESULT( 16 ) = ONE\n END IF\n*\n* Compare condition numbers for right invariant subspace\n* taking its condition number into account\n*\n IF( V.GT.RCONDV*RCONDE ) THEN\n TOL = RCONDV\n ELSE\n TOL = V / RCONDE\n END IF\n IF( V.GT.RCDVIN*RCDEIN ) THEN\n TOLIN = RCDVIN\n ELSE\n TOLIN = V / RCDEIN\n END IF\n TOL = MAX( TOL, SMLNUM / EPS )\n TOLIN = MAX( TOLIN, SMLNUM / EPS )\n IF( EPS*( RCDVIN-TOLIN ).GT.RCONDV+TOL ) THEN\n RESULT( 17 ) = ULPINV\n ELSE IF( RCDVIN-TOLIN.GT.RCONDV+TOL ) THEN\n RESULT( 17 ) = ( RCDVIN-TOLIN ) / ( RCONDV+TOL )\n ELSE IF( RCDVIN+TOLIN.LT.EPS*( RCONDV-TOL ) ) THEN\n RESULT( 17 ) = ULPINV\n ELSE IF( RCDVIN+TOLIN.LT.RCONDV-TOL ) THEN\n RESULT( 17 ) = ( RCONDV-TOL ) / ( RCDVIN+TOLIN )\n ELSE\n RESULT( 17 ) = ONE\n END IF\n*\n 300 CONTINUE\n*\n END IF\n*\n 9999 FORMAT( ' SGET24: ', A, ' returned INFO=', I6, '.', / 9X, 'N=',\n $ I6, ', INPUT EXAMPLE NUMBER = ', I4 )\n 9998 FORMAT( ' SGET24: ', A, ' returned INFO=', I6, '.', / 9X, 'N=',\n $ I6, ', JTYPE=', I6, ', ISEED=(', 3( I5, ',' ), I5, ')' )\n*\n RETURN\n*\n* End of SGET24\n*\n END\n", "meta": {"hexsha": "e0b75ff0fc28d0e31e08751872e451ae0c8094c4", "size": 32320, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lapack-netlib/TESTING/EIG/sget24.f", "max_stars_repo_name": "drhpc/OpenBLAS", "max_stars_repo_head_hexsha": "9721b57ecfd194f1a4aaa08d715735cd9e8ad8b6", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4392, "max_stars_repo_stars_event_min_datetime": "2015-01-02T18:15:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T12:14:38.000Z", "max_issues_repo_path": "lapack-netlib/TESTING/EIG/sget24.f", "max_issues_repo_name": "drhpc/OpenBLAS", "max_issues_repo_head_hexsha": "9721b57ecfd194f1a4aaa08d715735cd9e8ad8b6", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2067, "max_issues_repo_issues_event_min_datetime": "2015-01-01T03:50:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T18:59:43.000Z", "max_forks_repo_path": "lapack-netlib/TESTING/EIG/sget24.f", "max_forks_repo_name": "drhpc/OpenBLAS", "max_forks_repo_head_hexsha": "9721b57ecfd194f1a4aaa08d715735cd9e8ad8b6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1564, "max_forks_repo_forks_event_min_datetime": "2015-01-01T01:32:27.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:12:54.000Z", "avg_line_length": 32.4497991968, "max_line_length": 76, "alphanum_fraction": 0.4676980198, "num_tokens": 10646, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7871141157831876}} {"text": "program ej2\n\n !Programa que resuelve ecuaciones de segundo grado. Soporta raices complejas\n complex x_1, x_2, aux\n real a, b, c, disc\n\n print *, \"Sea la ecuación con la forma ax² + bx + c = 0\"\n print *, \"Porfavor ingresa los valores de los coeficientes a, b y c\"\n read *, a, b, c\n\n disc = b**2 - (4*a*c)\n\n if (disc < 0) then\n disc = - sqrt(abs(disc))\n aux = cmplx(0, disc)\n\n end if\n\n x_1 = (-b + aux)/(2*a)\n x_2 = (-b - aux)/(2*a)\n\n\n print *, \"Las raices son: x = {\", x_1, \", \", x_2, \"}\"\n\n\n\nend program ej2\n", "meta": {"hexsha": "ba5416e6cf41935ef231d40d6b01fd8c7ac09602", "size": 525, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sententicas de control/Ejercicios/ej2.f90", "max_stars_repo_name": "kotoromo/Fortran-Basico", "max_stars_repo_head_hexsha": "1d37a82754acd1c231981adc3dea2d606e76d6c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Sententicas de control/Ejercicios/ej2.f90", "max_issues_repo_name": "kotoromo/Fortran-Basico", "max_issues_repo_head_hexsha": "1d37a82754acd1c231981adc3dea2d606e76d6c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sententicas de control/Ejercicios/ej2.f90", "max_forks_repo_name": "kotoromo/Fortran-Basico", "max_forks_repo_head_hexsha": "1d37a82754acd1c231981adc3dea2d606e76d6c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.75, "max_line_length": 78, "alphanum_fraction": 0.5771428571, "num_tokens": 202, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474194456935, "lm_q2_score": 0.8244619306896956, "lm_q1q2_score": 0.7870704545641322}} {"text": "program kidou_ex2_7c\n !天体と軌道の力学(p.56)[例2.7c]\n \n implicit none\n integer::n\n real(8)::pi,e,l,u\n\n pi=4.0d0*atan(1.0d0)\n\n ![例2.7a]冥王星の離心近点離角uをニュートン・ラプソン法で求める。\n write(*,*)\"冥王星\"\n e=0.249d0 !離心率(文献値)\n l=(12.14d0/180)*pi !平均近点離角をラジアン表記へ変更\n \n u=l\n n=0\n write(*,*) n,(u/pi)*180d0\n \n do n=1,9\n u=u-((u-e*sin(u)-l)/(1-e*cos(u)))\n write(*,*) n,(u/pi)*180d0\n end do\n\n ![例2.7b]ハレー彗星の離心近点離角uをニュートン・ラプソン法で求める。\n write(*,*)\" ハレー彗星\"\n e=0.967d0 !離心率(文献値)\n l=(10d0/180)*pi !平均近点離角をラジアン表記へ変更\n \n u=l\n n=0\n write(*,*) n,(u/pi)*180d0\n \n do n=1,20\n u=u-((u-e*sin(u)-l)/(1-e*cos(u)))\n write(*,*) n,(u/pi)*180d0\n end do\n\nend program kidou_ex2_7c\n", "meta": {"hexsha": "0a481915b04536b6b47870c74b528499270ba3be", "size": 661, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "static/docs/notes/etc/ex2-7c.f90", "max_stars_repo_name": "aoshimash/kidou", "max_stars_repo_head_hexsha": "85fe340034ec44cfb57851146f484d34c4137b6d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "static/docs/notes/etc/ex2-7c.f90", "max_issues_repo_name": "aoshimash/kidou", "max_issues_repo_head_hexsha": "85fe340034ec44cfb57851146f484d34c4137b6d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "static/docs/notes/etc/ex2-7c.f90", "max_forks_repo_name": "aoshimash/kidou", "max_forks_repo_head_hexsha": "85fe340034ec44cfb57851146f484d34c4137b6d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.9487179487, "max_line_length": 40, "alphanum_fraction": 0.567322239, "num_tokens": 424, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474246069458, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.7870704464668471}} {"text": "MODULE MODULE_MATH\n\nCONTAINS\n \n SUBROUTINE NORMALIZE_VECT (a)\n \n DOUBLE PRECISION,DIMENSION(3),INTENT(INOUT)::a\n DOUBLE PRECISION::norm\n \n norm=sqrt(dot_product(a,a))\n a=a/norm\n \n END SUBROUTINE NORMALIZE_VECT\n \n SUBROUTINE PRODUCT_VECT(a,b,normal)\n \n DOUBLE PRECISION,DIMENSION(3),INTENT(IN)::a,b\n DOUBLE PRECISION,DIMENSION(3),INTENT(OUT)::normal\n \n normal(1)=a(2)*b(3)-a(3)*b(2)\n normal(2)=-a(1)*b(3)+a(3)*b(1)\n normal(3)=a(1)*b(2)-a(2)*b(1)\n \n END SUBROUTINE PRODUCT_VECT\n\n\n SUBROUTINE ROTANDTRANS_RMSD(center_orig,U,center_ref,coors,dim_coors,new_coors)\n\n IMPLICIT NONE\n\n INTEGER,INTENT(IN)::dim_coors\n DOUBLE PRECISION,DIMENSION(3),INTENT(IN)::center_orig,center_ref\n DOUBLE PRECISION,DIMENSION(3,3),INTENT(IN)::U\n DOUBLE PRECISION,DIMENSION(dim_coors,3),INTENT(IN)::coors\n\n DOUBLE PRECISION,DIMENSION(dim_coors,3),INTENT(OUT)::new_coors\n\n INTEGER::ii\n\n DO ii=1,dim_coors\n new_coors(ii,:)=matmul(transpose(U(:,:)),coors(ii,:)-center_orig)+center_ref\n END DO\n\n END SUBROUTINE ROTANDTRANS_RMSD\n\nEND MODULE MODULE_MATH\n", "meta": {"hexsha": "4edc159e4cb916d94b54fbff8f25e27bd24b09a5", "size": 1110, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "molmodmt/lib/libmath.f90", "max_stars_repo_name": "LMMV/MolModMT", "max_stars_repo_head_hexsha": "5725d6d5627b07edcbbd5e55318345a136b28c35", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-06-02T03:55:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T04:43:52.000Z", "max_issues_repo_path": "molmodmt/lib/libmath.f90", "max_issues_repo_name": "LMMV/MolModMT", "max_issues_repo_head_hexsha": "5725d6d5627b07edcbbd5e55318345a136b28c35", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 28, "max_issues_repo_issues_event_min_datetime": "2020-06-24T00:55:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-16T22:09:19.000Z", "max_forks_repo_path": "molmodmt/lib/libmath.f90", "max_forks_repo_name": "LMMV/MolModMT", "max_forks_repo_head_hexsha": "5725d6d5627b07edcbbd5e55318345a136b28c35", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-17T18:55:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-17T18:55:25.000Z", "avg_line_length": 23.6170212766, "max_line_length": 83, "alphanum_fraction": 0.6864864865, "num_tokens": 372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107861416413, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7870077395099089}} {"text": "!!\r\n!! Simple Fortran 90 module with program constants\r\n!! You could have delcared pi directly in the program units that\r\n!! need pi. However the purpose of modules is to make pieces of the\r\n!! code reusable and easier to maintain.\r\n!!\r\n!! 100212, lb \r\n!! \r\nMODULE fourthconst\r\n\r\n use precise, only : defaultp\r\n IMPLICIT NONE\r\n \r\n INTEGER, PARAMETER, PRIVATE :: WP=defaultp\r\n\r\n ! This defines the number pi. The key word parameter makes sure, \r\n ! the number pi is not overridden when the program is executed\r\n REAL(WP), PARAMETER :: one=1.0 \r\n REAL(WP), PARAMETER :: four=4.0 \r\n REAL(WP), PARAMETER :: pi=Four*ATAN(one) ! using a function to define the\r\n ! parameter value is a Fortran 2003\r\n ! extension supported by g95 but\r\n ! not all other compilers\r\n !real(wp), parameter :: pi=3.141592653589793 ! this is an alternative form\r\n\r\nEND MODULE fourthconst\r\n", "meta": {"hexsha": "56275017e322cc8a7e412b3c0dc23412767423ae", "size": 981, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fourthconst.f90", "max_stars_repo_name": "LukeMcCulloch/3DDoubleBodyFlows", "max_stars_repo_head_hexsha": "73fa94bf1df894a947aa39f80af206bebcbaddc3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-08T15:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-08T15:23:23.000Z", "max_issues_repo_path": "makeGeometry/fourthconst.f90", "max_issues_repo_name": "LukeMcCulloch/3D-linear-wave-resistance", "max_issues_repo_head_hexsha": "67f7621e307f9b745f435ee240890241254a3e9d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "makeGeometry/fourthconst.f90", "max_forks_repo_name": "LukeMcCulloch/3D-linear-wave-resistance", "max_forks_repo_head_hexsha": "67f7621e307f9b745f435ee240890241254a3e9d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.3333333333, "max_line_length": 77, "alphanum_fraction": 0.621814475, "num_tokens": 234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427872638409, "lm_q2_score": 0.8918110526265554, "lm_q1q2_score": 0.7869589299646715}} {"text": "************************************************************************\n*\n* SBFCT -- SYMMETRIC BANDED MATRIX FACTORIZATION.\n* SBSLV -- SYMMETRIC BANDED MATRIX SOLVE.\n*\n* THESE ROUTINES SOLVE LINEAR SYSTEMS A*X=B FOR THE VECTOR X WHEN A\n* IS A SYMMETRIC BANDED MATRIX. THE ROUTINE SBFCT COMPUTES THE\n* LOWER CHOLESKI FACTOR OF THE COEFFICIENT MATRIX A. IT IS ASSUMED\n* THAT GAUSSIAN ELIMINATION APPLIED TO A IS STABLE WITHOUT PIVOTING.\n* THE LOWER TRIANGULAR PART OF THE MATRIX A IS STORED BY COLUMN\n* AND THE ELEMENTS OF THE LOWER FACTOR OVERWRITE THOSE OF A IN THE\n* STANDARD MANNER. SUBSEQUENT CALLS TO THE ROUTINE SBSLV SOLVE THE\n* SYSTEM, CARRYING OUT THE FORWARD AND BACKWARD SUBSTITUTIONS.\n*\n* ARGUMENT DESCRIPTION\n* -------- -----------\n* NEQNS THE NUMBER OF EQATIONS.\n*\n* BANDW THE BANDWIDTH OF THE MATRIX. THE BANDWIDTH IS DEFINED\n* TO BE THE MAX { |I-J| : AIJ .NE. 0 }.\n*\n* A ARRAY CONTAINING EITHER THE LOWER TRIANGULAR ELEMENTS OF\n* THE COEFFICIENT MATRIX A OR THE ELEMENTS OF ITS LOWER\n* CHOLESKI FACTOR. THE ELEMENTS ARE STORED BY COLUMN SO\n* THAT AIJ, I.GE.J, IS STORED IN A(I-J,J).\n* \n* B ON INPUT THE ARRAY CONTAINS THE ELEMENTS OF THE RHS\n* VECTOR AND IS OVERWRITTEN WITH THE SOLUTION VECTOR.\n*\n************************************************************************\n subroutine sbfct(neqn,bandw,a)\n\n integer neqn,bandw,i,j,k\n double precision a(0:bandw,neqn)\n\n do 10 j=1,neqn\n do 11 k=1,min(bandw,j-1)\n do 11 i=0,min(bandw-k,neqn-j)\n 11 a(i,j) = a(i,j) - a(k,j-k)*a(k+i,j-k)\n a(0,j) = 1./sqrt(a(0,j))\n do 10 i=1,min(bandw,neqn-j)\n 10 a(i,j) = a(0,j)*a(i,j)\n\n return\n end\n subroutine sbslv(neqn,bandw,a,b)\n\n integer neqn,bandw,i,j\n double precision a(0:bandw,neqn),b(neqn)\n\n do 10 j=1,neqn\n b(j) = a(0,j)*b(j)\n do 10 i=1,min(bandw,neqn-j)\n 10 b(j+i) = b(j+i) - b(j)*a(i,j)\n\n do 20 j=neqn,1,-1\n do 21 i=1,min(bandw,neqn-j)\n 21 b(j) = b(j) - a(i,j)*b(j+i)\n 20 b(j) = a(0,j)*b(j)\n\n return\n end\n", "meta": {"hexsha": "01189ebef53deba27bba3602806580ecc9a9cd67", "size": 2165, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gwmfe2ds/source/common/sbsolve.f", "max_stars_repo_name": "mfeproject/legacy-gwmfe", "max_stars_repo_head_hexsha": "ef7c1139661067165b287877f012d5664aeab85d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "gwmfe2ds/source/common/sbsolve.f", "max_issues_repo_name": "mfeproject/legacy-gwmfe", "max_issues_repo_head_hexsha": "ef7c1139661067165b287877f012d5664aeab85d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gwmfe2ds/source/common/sbsolve.f", "max_forks_repo_name": "mfeproject/legacy-gwmfe", "max_forks_repo_head_hexsha": "ef7c1139661067165b287877f012d5664aeab85d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.3650793651, "max_line_length": 72, "alphanum_fraction": 0.56073903, "num_tokens": 716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533163686646, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7868927852138314}} {"text": "function kron(A,B) result(C)\n!\n! Copyright 2017, Viktor Reshiak, All rights reserved.\n!\n!\n! Purpose\n! =======\n! Kronecker product of two matrices\n!\n!\n! IN\n! ==\n! 1) na1 - first dimension of array A\n! 2) na2 - second dimension of array A\n! 3) A - array\n! 4) nb1 - first dimension of array B\n! 5) nb2 - second dimension of array B\n! 6) B - array\n!\n!\n! INOUT\n! =====\n! 1) C - resulting matrix\n!\n!\n\timplicit none\n\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n ! dummy arguments\n real(kind=8), intent(in), dimension(:,:) :: A\n real(kind=8), intent(in), dimension(:,:) :: B\n\n real(kind=8), dimension(size(A,1)*size(B,1),size(A,2)*size(B,2)) :: C\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n integer(kind=4) :: i, j\n integer(kind=4), dimension(2) :: sh_A, sh_B\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n sh_A = shape(A)\n sh_B = shape(B)\n\n do i = 1,sh_A(1)\n do j = 1,sh_A(2)\n C((i-1)*sh_B(1)+1:i*sh_B(1),(j-1)*sh_B(2)+1:j*sh_B(2)) = A(i,j) * B\n enddo\n enddo\n\nend function kron\n\n\n\n\n! function kron(na1,na2,A,nb1,nb2,B) result(C)\n! !\n! ! Copyright 2017, Viktor Reshiak, All rights reserved.\n! !\n! !\n! ! Purpose\n! ! =======\n! ! Kronecker product of two matrices\n! !\n! !\n! ! IN\n! ! ==\n! ! 1) na1 - first dimension of array A\n! ! 2) na2 - second dimension of array A\n! ! 3) A - array\n! ! 4) nb1 - first dimension of array B\n! ! 5) nb2 - second dimension of array B\n! ! 6) B - array\n! !\n! !\n! ! INOUT\n! ! =====\n! ! 1) C - resulting matrix\n! !\n! !\n! implicit none\n\n\n! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n! ! dummy arguments\n\n! integer(kind=4), intent(in) :: na1, na2, nb1, nb2\n! real(kind=8), intent(in), dimension(na1,na2) :: A\n! real(kind=8), intent(in), dimension(nb1,nb2) :: B\n\n! real(kind=8), dimension(na1*nb1,na2*nb2) :: C\n\n! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n! integer(kind=4) :: i, j\n\n! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n! do i = 1,na1\n! do j = 1,na2\n! C((i-1)*nb1+1:i*nb1,(j-1)*nb2+1:j*nb2) = A(i,j) * B\n! enddo\n! enddo\n\n! end function kron\n", "meta": {"hexsha": "557fcdd12cb34fdee0b715881712b0685798a57c", "size": 3165, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/OMP/kron.f90", "max_stars_repo_name": "revitmt/ChemicalKinetics", "max_stars_repo_head_hexsha": "61f174a1250c2bd248270ce1ef408e23e542b83b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/OMP/kron.f90", "max_issues_repo_name": "revitmt/ChemicalKinetics", "max_issues_repo_head_hexsha": "61f174a1250c2bd248270ce1ef408e23e542b83b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/OMP/kron.f90", "max_forks_repo_name": "revitmt/ChemicalKinetics", "max_forks_repo_head_hexsha": "61f174a1250c2bd248270ce1ef408e23e542b83b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.5217391304, "max_line_length": 100, "alphanum_fraction": 0.3146919431, "num_tokens": 918, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819238, "lm_q2_score": 0.8577681122619883, "lm_q1q2_score": 0.7868329609897083}} {"text": "!Subroutine to find the inverse of a square matrix\n!Author : Louisda16th a.k.a Ashwith J. Rego\n!Reference : Algorithm has been well explained in:\n!http://math.uww.edu/~mcfarlat/inverse.htm \n!http://www.tutor.ms.unimelb.edu.au/matrix/matrix_inverse.html\n\nSUBROUTINE InvertMatrix(matrix, inverse, n, errorflag)\n\tIMPLICIT NONE\n\t!Declarations\n\tINTEGER, INTENT(IN) :: n\n\tINTEGER, INTENT(OUT) :: errorflag !Return error status. -1 for error, 0 for normal\n\tREAL(8), INTENT(IN)\t:: matrix(n,n) !Input matrix\n\tREAL(8), INTENT(OUT)\t:: inverse(n,n) !Inverted matrix\n\t\n\tLOGICAL :: FLAG = .TRUE.\n\tINTEGER :: i, j, k\n\tREAL(8) :: m\n\tREAL(8), DIMENSION(n,2*n) :: augmatrix !augmented matrix\n\t\n\t!Augment input matrix with an identity matrix\n\tDO i = 1, n\n\t\tDO j = 1, 2*n\n\t\t\tIF (j <= n ) THEN\n\t\t\t\taugmatrix(i,j) = matrix(i,j)\n\t\t\tELSE IF ((i+n) == j) THEN\n\t\t\t\taugmatrix(i,j) = 1\n\t\t\tElse\n\t\t\t\taugmatrix(i,j) = 0\n\t\t\tENDIF\n\t\tEND DO\n\tEND DO\n\t\n\t!Reduce augmented matrix to upper traingular form\n\tDO k =1, n-1\n\t\tIF (augmatrix(k,k) == 0) THEN\n\t\t\tFLAG = .FALSE.\n\t\t\tDO i = k+1, n\n\t\t\t\tIF (augmatrix(i,k) /= 0) THEN\n\t\t\t\t\tDO j = 1,2*n\n\t\t\t\t\t\taugmatrix(k,j) = augmatrix(k,j)+augmatrix(i,j)\n\t\t\t\t\tEND DO\n\t\t\t\t\tFLAG = .TRUE.\n\t\t\t\t\tEXIT\n\t\t\t\tENDIF\n\t\t\t\tIF (FLAG .EQV. .FALSE.) THEN\n\t\t\t\t\tPRINT*, \"Matrix is non - invertible\"\n\t\t\t\t\tinverse = 0\n\t\t\t\t\terrorflag = -1\n\t\t\t\t\treturn\n\t\t\t\tENDIF\n\t\t\tEND DO\n\t\tENDIF\n\t\tDO j = k+1, n\t\t\t\n\t\t\tm = augmatrix(j,k)/augmatrix(k,k)\n\t\t\tDO i = k, 2*n\n\t\t\t\taugmatrix(j,i) = augmatrix(j,i) - m*augmatrix(k,i)\n\t\t\tEND DO\n\t\tEND DO\n\tEND DO\n\t\n\t!Test for invertibility\n\tDO i = 1, n\n\t\tIF (augmatrix(i,i) == 0) THEN\n\t\t\tPRINT*, \"Matrix is non - invertible\"\n\t\t\tinverse = 0\n\t\t\terrorflag = -1\n\t\t\treturn\n\t\tENDIF\n\tEND DO\n\t\n\t!Make diagonal elements as 1\n\tDO i = 1 , n\n\t\tm = augmatrix(i,i)\n\t\tDO j = i , (2 * n)\t\t\t\t\n\t\t\t augmatrix(i,j) = (augmatrix(i,j) / m)\n\t\tEND DO\n\tEND DO\n\t\n\t!Reduced right side half of augmented matrix to identity matrix\n\tDO k = n-1, 1, -1\n\t\tDO i =1, k\n\t\tm = augmatrix(i,k+1)\n\t\t\tDO j = k, (2*n)\n\t\t\t\taugmatrix(i,j) = augmatrix(i,j) -augmatrix(k+1,j) * m\n\t\t\tEND DO\n\t\tEND DO\n\tEND DO\t\t\t\t\n\t\n\t!store answer\n\tDO i =1, n\n\t\tDO j = 1, n\n\t\t\tinverse(i,j) = augmatrix(i,j+n)\n\t\tEND DO\n\tEND DO\n\terrorflag = 0\nEND SUBROUTINE InvertMatrix", "meta": {"hexsha": "ee33a977922f4dba570a38cd33075128bbc5e063", "size": 2216, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "FortranCode/rental-wedge-code/invertmatrix.f90", "max_stars_repo_name": "lnsongxf/housing-boom-bust", "max_stars_repo_head_hexsha": "bb75a2fd0646802dcdf4d5e56d1392bae7090e1c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-07-19T16:46:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-09T10:52:42.000Z", "max_issues_repo_path": "FortranCode/sensitivity-code/invertmatrix.f90", "max_issues_repo_name": "floswald/housing-boom-bust", "max_issues_repo_head_hexsha": "bb75a2fd0646802dcdf4d5e56d1392bae7090e1c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-09-20T08:31:12.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-20T08:48:49.000Z", "max_forks_repo_path": "FortranCode/landlord-code/invertmatrix.f90", "max_forks_repo_name": "kurtmitman/housing-boom-bust", "max_forks_repo_head_hexsha": "8c1ad640d79540488a5ef859f3c47ac5d4515e85", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-09-12T06:08:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T16:24:13.000Z", "avg_line_length": 23.0833333333, "max_line_length": 84, "alphanum_fraction": 0.6064981949, "num_tokens": 861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034425, "lm_q2_score": 0.8577681068080748, "lm_q1q2_score": 0.7868329598652336}} {"text": "program find_greatest_common_denominator\n implicit none\n integer :: gcd, temp\n integer :: number_1, number_2, x, y\n number_1 = 10\n number_2 = 15\n do x = 1,20\n do y = 1,20\n print *, \"the gcd of \",y,x,\"is \",gcd(y,x)\n end do\n \n end do\n temp = gcd(number_1,number_2)\n \n print *, temp, \"is the greatest common denominator\"\n\nend program find_greatest_common_denominator\n\nfunction gcd(a, b) result (tempb)\n implicit none\n integer, intent(in) :: a, b\n integer :: tempa, tempb, place_holder\n \n tempa = a\n tempb = b\n \n do while (.not.tempa.eq.0)\n \n place_holder = tempa\n \n if (tempa.eq.0) then\n exit\n end if\n \n tempa = mod(tempb,tempa)\n tempb = place_holder\n \n end do\n \nend function gcd\n", "meta": {"hexsha": "f2d18d2ec0f3ac27ea08c7727aa333f69de0d2db", "size": 827, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "greatest_common_denom.f95", "max_stars_repo_name": "Ji19283756/Fortran_stuff", "max_stars_repo_head_hexsha": "f945dd09e1be22df829cfab60fd1d38de6f525d3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "greatest_common_denom.f95", "max_issues_repo_name": "Ji19283756/Fortran_stuff", "max_issues_repo_head_hexsha": "f945dd09e1be22df829cfab60fd1d38de6f525d3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "greatest_common_denom.f95", "max_forks_repo_name": "Ji19283756/Fortran_stuff", "max_forks_repo_head_hexsha": "f945dd09e1be22df829cfab60fd1d38de6f525d3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.1707317073, "max_line_length": 55, "alphanum_fraction": 0.5610640871, "num_tokens": 238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.944176857294597, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7868058033704652}} {"text": "!Sk. Mashfiqur Rahman\n!Oklahoma State University\n!conjugate gradient method basic\n\nprogram CGM_example\nimplicit none\ninteger::NA,k,i,nx,ny\ndouble precision,allocatable::b(:),x(:),r(:),p(:),d(:)\ndouble precision::alpha,beta,eps\ndouble precision::m,z,y\n\nopen(7,file='input.txt')\nread(7,*)nx \t!number of rows\nread(7,*)NA \t!total no. of iterations\nclose(7)\n\nny=nx\n\nallocate(b(0:nx),x(0:nx),r(0:nx),p(0:nx),d(0:nx))\n\ndo i=0,nx\n write(*,*)'Enter the constants:'\n write(*,*)\n read(*,*) b(i)\nend do\n\ndo i=0,nx\np(i)=b(i)\nr(i)=b(i)\nend do\n\ndo i=0,nx\n x(i)=0.0d0\nend do\n\neps=1.0d-10\n\ndo k=1,NA\n\ncall matrix(nx,ny,p,d) \n\nz=0.0d0\ny=0.0d0 \ndo i=0,nx\nz= z+ (r(i) * r(i))\ny= y+ (d(i) * p(i))\nend do\n\nalpha = z/y\n\ndo i=0,nx\nx(i) = x(i) + alpha * p(i)\nend do\n\nm=0.0d0\ndo i=0,nx\nr(i) = r(i)-(alpha * d(i))\nm= m + r(i) * r(i)\nend do\nbeta = m/z\n\ndo i=0,nx\np(i) = r(i)+ (beta * p(i))\nend do\n\n!stopping criteria- the iteration will close whenever r(1:2) will be 0\nif (r(0).lt.eps .and. r(1).lt.eps .and. r(2).lt.eps .and. r(3).lt.eps) then\n exit\nend if\nend do\n \nwrite(*,*) \"solution is: \", x\n\nend\n\n\nsubroutine matrix(nx,ny,wf,w)\nimplicit none\ndouble precision,dimension(0:nx,0:ny)::A\ndouble precision,allocatable:: u(:)\ndouble precision,dimension(0:nx)::w,wf\ndouble precision::p\ninteger::i,j,nx,ny\n\nallocate(u(0:nx))\ndo i=0,nx\n u(i) = wf(i)\nend do\n\ndo i=0,nx\n do j=0,ny\n if (i.eq.j) then\n A(i,j)= 4.0d0\n else if (j.eq.i+1) then\n A(i,j)= 1.0d0\n else if (i.eq.j+1) then\n A(i,j)= 2.0d0\n else \n A(i,j)=0.0d0\n end if\n end do\nend do\n\np=0.0d0\ndo i=0,nx\n do j=0,ny\n p=p+A(i,j)*u(j)\n end do\n w(i)=p\n p=0.0d0\nend do\n\ndeallocate(u)\nreturn\nend", "meta": {"hexsha": "481f3437f7068a5f2c3abc3461421005797e5748", "size": 1658, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "cgm.f95", "max_stars_repo_name": "mashfiq10/CGM_Basic", "max_stars_repo_head_hexsha": "d28e2e558ec26618d7865e24c073c88be46d033d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cgm.f95", "max_issues_repo_name": "mashfiq10/CGM_Basic", "max_issues_repo_head_hexsha": "d28e2e558ec26618d7865e24c073c88be46d033d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cgm.f95", "max_forks_repo_name": "mashfiq10/CGM_Basic", "max_forks_repo_head_hexsha": "d28e2e558ec26618d7865e24c073c88be46d033d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.4173913043, "max_line_length": 75, "alphanum_fraction": 0.5989143546, "num_tokens": 741, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.944176863577751, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7868058027439048}} {"text": "\n! Quadratic Primes\n!\n! Project Euler: 27\n!\n! Answer: -59231\n\nprogram main\n\n use euler\n\nimplicit none\n\n integer (int32) :: chain, a, b;\n integer (int32) :: product, longest;\n integer (int32), parameter :: MAX_ = 1000;\n integer (int32), parameter :: MIN_ = -999;\n\n do a = MIN_, MAX_, 2\n\n do b = a, MAX_, 2\n\n chain = consecprimes(a, b);\n\n if(chain > longest) then\n longest = chain\n product = a * b\n end if\n end do\n\n end do\n\n print*, product\n\n\ncontains\n\n\n pure function consecprimes(a, b)\n\n integer (int32) :: n, consecprimes;\n integer (int32), intent(in) :: a, b;\n\n n = 1; consecprimes = 0;\n\n do while(isprime(quad_f(a, b, n)))\n consecprimes = consecprimes + 2;\n n = n + 2;\n end do\n\n end function consecprimes\n\n\n ! Quadratic function\n\n pure function quad_f(a, b, n)\n\n integer (int32), intent(in) :: a, b, n;\n integer (int32) :: quad_f;\n\n quad_f = (n ** 2) + (a * n) + b;\n\n end function quad_f\n\nend program main\n\n", "meta": {"hexsha": "9b6d5597534a54639e8ceeed6e7f331dbf0757fb", "size": 1329, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/quadratic_primes.f95", "max_stars_repo_name": "guynan/project_euler", "max_stars_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-03-08T09:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T13:52:49.000Z", "max_issues_repo_path": "fortran/quadratic_primes.f95", "max_issues_repo_name": "guynan/project_euler", "max_issues_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-11-03T01:20:46.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-24T22:54:59.000Z", "max_forks_repo_path": "fortran/quadratic_primes.f95", "max_forks_repo_name": "guynan/project_euler", "max_forks_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-11-03T01:14:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T13:52:51.000Z", "avg_line_length": 19.8358208955, "max_line_length": 56, "alphanum_fraction": 0.4326561324, "num_tokens": 325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653856, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7868058027252863}} {"text": "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc Compute reseau shape function A, where A is an inverted Gaussian:\nc\tA(i,j) = 255.*(1-exp(s*(i**2+j**2)))\nc where\nc\ts = -1/(2*sig**2)\nc i=-ia,...,ia and j=-ja,...,ja.\n\n subroutine compute_A(A,ia,ja)\n implicit none\nc Inputs...\n integer ia,ja\t\t\t!template half widths\nc Output...\n integer*2 A(-ia:ia,-ja:ja)\t!shape function\n\nc Routine also sets these values in common...\n common/ca/area,meanA,sigA\n real area,meanA,sigA\t\t!area, mean, and sigma of A\n\n common/cd/npixels,sii,sjj\n real npixels\n real sii,sjj\t\t\t!sum of i**2 and j**2\n\nc Local variables...\n real sig,s\n integer sumA,sumA2\n\n integer i,j,m,n,count\n logical xvptst\n character*80 msg\n 100 format('sig=',f6.2)\n 101 format(11i4)\n 102 format(' meanA=',f6.2,' sigmaA=',f6.2)\n 103 format('sii=',f10.2,' sjj=' f10.2)\n\nc Compute the Gaussian constant s...\n call xvp('sigma',sig,count)\n write(msg,100) sig\n call xvmessage(msg,0)\n s = -1/(2*sig**2)\t\n\nc Compute A, mean(A) and sigma(A)...\n sumA = 0.\n sumA2 = 0.\n do j=-ja,ja\n do i=-ia,ia\n A(i,j) = 255*(1 - exp(s*(i**2+j**2)))\n sumA = sumA + A(i,j)\n sumA2 = sumA2 + A(i,j)**2\n enddo\n enddo\n\nc Set the values in common/ca/...\n area = (2*ia+1)*(2*ja+1)\n meanA = sumA/area\t\t\t\t!mean of A\n sigA = sqrt(sumA2/area - meanA**2)\t!sigma of A\n npixels = area\n sii = (ia*(ia+1)*(2*ia+1)*(2*ja+1))/3.\n sjj = (ja*(ja+1)*(2*ja+1)*(2*ia+1))/3.\n\n if (xvptst('print')) then\n call xvmessage('reseau shape template A...',' ')\n do j=-ja,ja\n write(msg,101) (a(i,j),i=-ia,ia)\n call xvmessage(msg,' ')\n enddo\n write(msg,102) meanA,sigA\n call xvmessage(msg,' ')\nccc write(msg,103) sii,sjj\nccc call xvmessage(msg,0)\n endif\n\n return\n end\n", "meta": {"hexsha": "dab82624df37d03a2d89a2b6ab73aa5ee0931e64", "size": 1971, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vos/p2/prog/resloc/compute_A.f", "max_stars_repo_name": "NASA-AMMOS/VICAR", "max_stars_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-10-21T05:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T10:02:01.000Z", "max_issues_repo_path": "vos/p2/prog/resloc/compute_A.f", "max_issues_repo_name": "NASA-AMMOS/VICAR", "max_issues_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vos/p2/prog/resloc/compute_A.f", "max_forks_repo_name": "NASA-AMMOS/VICAR", "max_forks_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-09T01:51:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T00:23:24.000Z", "avg_line_length": 26.6351351351, "max_line_length": 75, "alphanum_fraction": 0.5525114155, "num_tokens": 686, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653856, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7868058007711306}} {"text": "! primes.f95\n! Calculate prime numbers\n!\n! vim: set ft=fortran sw=2 ts=2 :\n\nmodule primes\n implicit none\n\ncontains\n\n pure logical function is_prime (n)\n\n implicit none\n integer, intent( in ) :: n\n integer :: i, limit\n\n is_prime = .true.\n\n if (n < 2) then\n is_prime = .false.\n else\n limit = int(sqrt(real(n)))\n do i = 2, limit\n if (modulo(n, i) == 0) then\n is_prime = .false.\n exit\n end if\n end do\n end if\n\n end function is_prime\n\n\n\nend module primes\n\n", "meta": {"hexsha": "4a20cdd1a463bfa501dc48b108dfb702eb9d2081", "size": 595, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/Benchmark/src/primes.f90", "max_stars_repo_name": "kkirstein/proglang-playground", "max_stars_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fortran/Benchmark/src/primes.f90", "max_issues_repo_name": "kkirstein/proglang-playground", "max_issues_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran/Benchmark/src/primes.f90", "max_forks_repo_name": "kkirstein/proglang-playground", "max_forks_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.0810810811, "max_line_length": 40, "alphanum_fraction": 0.4974789916, "num_tokens": 155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843132, "lm_q2_score": 0.8723473663814338, "lm_q1q2_score": 0.7867881176564044}} {"text": "\tSUBROUTINE BDS_NBT ( rmin, rmax, rdb, nmbts, iscale, rmn, iret )\nC************************************************************************\nC* BDS_NBT\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This subroutine computes the number of packing bits given the\t*\nC* maximum number (< 50) of significant digits to preserve or the\t*\nC* binary precision to store the data. The binary precision is given\t*\nC* as zero, a negative integer, or as a postitive integer greater than\t*\nC* or equal to 50. If the binary precision is given, ISCALE will\t*\nC* always be zero in this case.\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* The binary precision translates as follows:\t\t\t\t*\nC* 53 => store data to nearest 8\t\t\t\t\t*\nC* 52 => store data to nearest 4\t\t\t\t\t*\nC* 51 => store data to nearest 2\t\t\t\t\t*\nC* 50 => store data to nearest 1\t\t\t\t\t*\nC* 0 => store data to nearest 1\t\t\t\t\t*\nC* -1 => store data to nearest 1/2\t\t\t\t*\nC* -2 => store data to nearest 1/4\t\t\t\t*\nC* -3 => store data to nearest 1/8\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Note that RDB - 50 give the nearest whole power of two for binary\t*\nC* precision.\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Note that a fractional number of significant digits is allowed.\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* BDS_NBT ( RMIN, RMAX, RDB, NMBTS, ISCALE, RMN, IRET )\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tRMIN \t\tREAL\t\tMinimum value\t\t\t*\nC*\tRMAX\t\tREAL\t\tMaximum value\t\t\t*\nC*\tRDB\t\tREAL\t\tMaximum # of significant digits\t*\nC*\t\t\t\t\t OR binary precision if < 0\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tNMBTS\t\tINTEGER\t\tNumber of bits for packing\t*\nC*\tISCALE\t\tINTEGER\t\tPower of 10 scaling to use\t*\nC*\tRMN\t\tREAL\t\tRounded miniumum\t\t*\nC*\tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC*\t\t\t\t\t 0 = normal return\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* K. Brill/NMC\t\t06/92\t\t\t\t\t\t*\nC* K. Brill/EMC\t\t12/95\tAdded binary precision; added RMN\t*\nC* K. Brill/EMC\t\t 1/97\tAdd .5 in rr= & rng2= for better rnd off*\nC* K. Brill/EMC\t\t 1/97\tUse 10**iscale in rounding the min\t*\nC* K. Brill/HPC\t\t 8/99\tName change for use in GDGRIB\t\t*\nC************************************************************************\nC*\n\tDATA\t\trln2/0.69314718/\nC-----------------------------------------------------------------------\n\tiret = 0\n\ticnt = 0\n\tiscale = 0\n\trmn = rmin\n\trange = rmax - rmin\n\tIF ( range .le. 0.00 ) THEN\n\t nmbts = 8\n\t RETURN\n\tEND IF\nC*\n\tIF ( rdb .gt. 0.0 .and. rdb .lt. 50. ) THEN\n\t po = FLOAT ( INT ( ALOG10 ( range ) ) )\n\t IF ( range .lt. 1.00 ) po = po - 1.\n\t po = po - rdb + 1.\n\t iscale = - INT ( po )\n\t rr = range * 10. ** ( -po ) + .5\n\t nmbts = INT ( ALOG ( rr ) / rln2 ) + 1\n\tELSE\n\t ibin = NINT ( -rdb )\n\t IF ( ibin .le. -50. ) ibin = ibin + 50\n\t rng2 = range * 2. ** ibin + .5\n\t nmbts = INT ( ALOG ( rng2 ) / rln2 ) + 1\n\tEND IF\n\tIF ( nmbts .le. 0 ) THEN\n\t iret = 1\n\t nmbts = 8\n\tEND IF\nC\nC*\tCompute RMN, the first packable value less than or equal to\nC*\tRMIN.\nC\n\ttp = 10. ** iscale\n\tx = ( ALOG ( range * tp ) - ALOG ( 2 ** nmbts - 1. ) ) / rln2\n\tixp = INT ( x )\n\tIF ( FLOAT ( ixp ) .ne. x .and. x .gt. 0. ) ixp = ixp + 1\n\tirmn = NINT ( ( rmin * tp ) / ( 2. ** ixp ) )\n\trmn = FLOAT ( irmn ) * ( 2. ** ixp )\n\tIF ( rmn .gt. rmin * tp ) rmn = rmn - ( 2. ** ixp )\n\trmn = rmn / tp\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "97595422b7330ae1ad53888623a9c722da617f1f", "size": 3190, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/programs/gd/gdgrib/oldfortran/bds_nbt.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/programs/gd/gdgrib/oldfortran/bds_nbt.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/programs/gd/gdgrib/oldfortran/bds_nbt.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 33.9361702128, "max_line_length": 73, "alphanum_fraction": 0.5203761755, "num_tokens": 1177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.941654159388319, "lm_q2_score": 0.8354835289107307, "lm_q1q2_score": 0.7867365400992204}} {"text": "! In program name, - is not allowed\n!works till 77\n! 78 and above is out of the reasonable bounds for calculation\nprogram factorial_generate\n character(len=10) :: argument\n Character(26) :: low = 'abcdefghijklmnopqrstuvwxyz'\n Character(26) :: cap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'\n integer :: number, check_capital_letters, check_small_letters, i\n integer(kind = 16):: factorial\n ! Anything not equal to single argument, Print Error\n IF(COMMAND_ARGUMENT_COUNT().NE.1)THEN\n write(*,'(g0.8)')\"Usage: please input a non-negative integer\"\n STOP\n ENDIF\n \n CALL GET_COMMAND_ARGUMENT(1,argument)\n if (argument == \"\") then\n write(*,'(g0.8)')\"Usage: please input a non-negative integer\"\n STOP\n endif\n ! Scan for letters\n check_capital_letters = scan(argument, cap)\n check_small_letters = scan(argument, low)\n ! If capital letters exist, print error\n if (check_capital_letters > 0) then\n write(*,'(g0.8)')\"Usage: please input a non-negative integer\"\n STOP\n endif\n ! If small letters exist, print error\n if (check_small_letters > 0) then\n write(*,'(g0.8)')\"Usage: please input a non-negative integer\"\n STOP\n endif\n ! read the cmd line arg into number\n read (argument, '(I10)') number\n\n if (number < 0) then\n write(*,'(g0.8)')\"Usage: please input a non-negative integer\"\n STOP\n endif\n if (number > 77) then\n write(*,'(g0.8)')\"Input is out of the reasonable bounds for calculation\"\n STOP\n endif\n\n factorial = 1\n do i = 1, number\n factorial = factorial * i\n end do\n write(*,'(g0.8)') factorial\nend program\n", "meta": {"hexsha": "9f8958b704ae81f2e06fe93f4ffb9fa1484c6825", "size": 1559, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "archive/f/fortran/factorial.f95", "max_stars_repo_name": "Sagarchoudhary14/sample-programs", "max_stars_repo_head_hexsha": "32d8165d39ef9663f9e0db7e3df4d34d16922628", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 422, "max_stars_repo_stars_event_min_datetime": "2018-08-14T11:57:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T23:54:34.000Z", "max_issues_repo_path": "archive/f/fortran/factorial.f95", "max_issues_repo_name": "shivamkchoudhary/sample-programs", "max_issues_repo_head_hexsha": "72c4db68481a72cc0cb4992a93575df540f147b0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1498, "max_issues_repo_issues_event_min_datetime": "2018-08-10T19:18:52.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-14T03:02:00.000Z", "max_forks_repo_path": "archive/f/fortran/factorial.f95", "max_forks_repo_name": "shivamkchoudhary/sample-programs", "max_forks_repo_head_hexsha": "72c4db68481a72cc0cb4992a93575df540f147b0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 713, "max_forks_repo_forks_event_min_datetime": "2018-08-12T21:37:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-02T22:57:21.000Z", "avg_line_length": 29.9807692308, "max_line_length": 76, "alphanum_fraction": 0.6895445799, "num_tokens": 447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894576856561, "lm_q2_score": 0.8791467643431002, "lm_q1q2_score": 0.786651256492662}} {"text": " PROGRAM delR_mean\n IMPLICIT NONE\n\n INTEGER (KIND=8),PARAMETER::n=5\n\n INTEGER (KIND=8):: i\n REAL (KIND=8):: Ra_av,Rb_av,Rd_av,R_av,Kad,Kab\n REAL (KIND=8):: Ra_dev,Rb_dev,Rd_dev,R_dev\n REAL (KIND=8),DIMENSION(n):: Ra,Rb,Rd,R\n\n!!!=======================================================================================\n!!!======================================================================================= \n OPEN(unit=11,file='delR.dat')\n OPEN(unit=12,file='delR_av.dat')\n OPEN(unit=13,file='delRa_av.dat')\n\n!!! Tinh gia tri trung binh\n Ra_av=0. ; Rb_av=0. ; Rd_av=0. ; R_av=0.\n\n DO i=1,n\n READ(11,*)Kad,Kab,Ra(i),Rb(i),Rd(i),R(i)\n Ra_av=Ra_av+Ra(i)\n Rb_av=Rb_av+Rb(i)\n Rd_av=Rd_av+Rd(i)\n R_av=R_av+R(i)\n END DO\n \n Ra_av=Ra_av/n ; Rb_av=Rb_av/n ; Rd_av=Rd_av/n ; R_av=R_av/n\n\n!!! Tinh standard deviation\n Ra_dev=0. \n DO i=1,n\n Ra_dev=Ra_dev+(Ra(i)-Ra_av)**2.\n END DO\n Ra_dev=sqrt(Ra_dev/n)\n\n Rb_dev=0. \n DO i=1,n\n Rb_dev=Rb_dev+(Rb(i)-Rb_av)**2.\n END DO\n Rb_dev=sqrt(Rb_dev/n)\n\n Rd_dev=0. \n DO i=1,n\n Rd_dev=Rd_dev+(Rd(i)-Rd_av)**2.\n END DO\n Rd_dev=sqrt(Rd_dev/n)\n\n R_dev=0. \n DO i=1,n\n R_dev=R_dev+(R(i)-R_av)**2.\n END DO\n R_dev=sqrt(R_dev/n)\n\n WRITE(12,*)Kad,Kab,Ra_av,Rb_av,Rd_av,R_av\n WRITE(13,*)Ra_av,Ra_dev,Rb_av,Rb_dev,Rd_av,Rd_dev,R_av,R_dev\n \n CLOSE(11)\n CLOSE(12)\n CLOSE(13)\n \n END PROGRAM delR_mean\n\n", "meta": {"hexsha": "43fb090f36cb760804533c241f7f1d98ee44ea77", "size": 1451, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "071OCT15_ISLET_SYNC_Human_30Remove/Ref/0.0Kab/3delR_mean.f90", "max_stars_repo_name": "danhtaihoang/islet-sync", "max_stars_repo_head_hexsha": "734d717ccaf979640425b1e03032f292952075c4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "071OCT15_ISLET_SYNC_Human_30Remove/Ref/0.0Kab/3delR_mean.f90", "max_issues_repo_name": "danhtaihoang/islet-sync", "max_issues_repo_head_hexsha": "734d717ccaf979640425b1e03032f292952075c4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "071OCT15_ISLET_SYNC_Human_30Remove/Ref/0.0Kab/3delR_mean.f90", "max_forks_repo_name": "danhtaihoang/islet-sync", "max_forks_repo_head_hexsha": "734d717ccaf979640425b1e03032f292952075c4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.671875, "max_line_length": 91, "alphanum_fraction": 0.5148173673, "num_tokens": 540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248225478307, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7865459374315623}} {"text": "* This program calculate the solution for the\r\n* diferintial equation:\r\n* dy/dx=-y , y(x=0)=1\r\n* the solution is : y= exp(-x)\r\n\r\n10 Print*,'Enter the value of step size )(.le. 0to stop)'\r\n Read(*,*)H\r\n if(H.LE.0)stop\r\n YMINUS=1\r\n YZERO=1.0-H+H**2/2\r\n Nstep=6.0/H\r\n do 20 IX=2,Nstep\r\n X=IX*H\r\n YPLUS=YMINUS-2*H*YZERO\r\n YMINUS=YZERO\r\n YZERO=YPLUS\r\n Exact=exp(-x)\r\n Write(*,*)X,Exact,Exact-YZERO\r\n20 continue\r\n go to 10\r\n End\r\n\r\n", "meta": {"hexsha": "85fe783fcf282b16b70cbc9a2416bfbf94282b55", "size": 568, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "last28-52009/Example/solution od differintial equation- example 2/solution od differintial equation- example 2.f", "max_stars_repo_name": "Melhabbash/Computational-Physics-", "max_stars_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "last28-52009/Example/solution od differintial equation- example 2/solution od differintial equation- example 2.f", "max_issues_repo_name": "Melhabbash/Computational-Physics-", "max_issues_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "last28-52009/Example/solution od differintial equation- example 2/solution od differintial equation- example 2.f", "max_forks_repo_name": "Melhabbash/Computational-Physics-", "max_forks_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.6956521739, "max_line_length": 65, "alphanum_fraction": 0.4700704225, "num_tokens": 191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660976007597, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7865087203539993}} {"text": "!=====================================================================!\n! Library of nonlinear solvers\n!=====================================================================!\n\nmodule nonlinear_algebra\n\n ! Import dependencies\n use iso_fortran_env, only : dp => REAL64\n\n ! Import linear solver\n use linear_algebra\n\n ! disable implicit datatypes\n implicit none\n\n ! all members are private by default\n private\n\n public :: newton, chord, secant, fixed_point, shamanskii\n public :: diffjac\n\ncontains\n\n !===================================================================!\n ! Form the jacobian using finite differences\n !===================================================================!\n \n subroutine diffjac(x, F, jac)\n \n real(8), intent(in) :: x(:)\n \n interface\n function F(x)\n real(8), intent(in) :: x(:)\n real(8) :: F(size(x))\n end function F\n end interface\n\n real(8), intent(inout) :: jac(size(x),size(x))\n\n integer :: nvars, i\n real(8), parameter :: h = 1.0e-8\n real(8) :: xhat(size(x))\n\n nvars = size(x)\n\n xhat = x\n \n ! Compute Jacobian with first order approx\n do i = 1, nvars\n\n ! Perturb x\n xhat(i) = x(i) + h\n\n ! Evaluate column\n jac(:,i) = (F(xhat) - F(x))/h\n\n ! Restore x\n xhat(i) = x(i)\n\n end do\n\n end subroutine diffjac\n\n !===================================================================!\n ! A method that features quadratic convergence\n !===================================================================!\n \n subroutine newton(F, FPRIME, tau_r, tau_a, max_it, x)\n\n real(8), intent(in) :: tau_r, tau_a\n integer, intent(in) :: max_it\n real(8), intent(inout) :: x(:)\n \n interface\n function F(x)\n real(8), intent(in) :: x(:)\n real(8) :: F(size(x))\n end function F\n function FPRIME(x)\n real(8), intent(in) :: x(:)\n real(8) :: FPRIME(size(x),size(x))\n end function FPRIME\n end interface\n\n ! local variables\n real(8) :: r0 \n real(8) :: jac(size(x),size(x))\n real(8) :: s(size(x))\n integer :: iter\n\n ! Initial residual\n r0 = norm2(F(x))\n\n iter = 0\n do while (norm2(F(x)) > tau_r*r0 + tau_a .and. iter .le. max_it)\n\n ! Increment the iteration count\n iter = iter + 1\n\n ! Compute Jacobian\n jac = FPRIME(x)\n\n ! Solve the linear system\n s = solve(jac, F(x))\n\n ! Apply the update\n x = x - s\n\n ! print details\n print *, iter, norm2(F(x))\n\n end do\n\n end subroutine newton\n\n !===================================================================!\n ! Use use supplied two points to form Jacobian (super-linear\n ! convergence)\n !===================================================================!\n \n subroutine secant(F, tau_r, tau_a, max_it, x0, x1)\n\n real(8), intent(in) :: tau_r, tau_a\n integer, intent(in) :: max_it\n real(8), intent(inout) :: x0(:), x1(:)\n \n interface\n function F(x)\n real(8), intent(in) :: x(:)\n real(8) :: F(size(x))\n end function F\n function FPRIME(x)\n real(8), intent(in) :: x(:)\n real(8) :: FPRIME(size(x),size(x))\n end function FPRIME\n end interface\n\n ! local variables\n real(8) :: r0 \n real(8) :: jac(size(x0),size(x0))\n real(8) :: s(size(x0))\n integer :: iter\n real(8) :: xtmp(size(x0))\n \n ! Initial residual\n r0 = norm2(F(x1))\n\n iter = 0\n \n do while (norm2(F(x1)) > tau_r*r0 + tau_a .and. iter .le. max_it)\n\n ! Increment the iteration count\n iter = iter + 1\n\n ! Apply the update\n xtmp = x1 \n x1 = x1 - F(x1)*(x1-x0)/(F(x1)-F(x0))\n x0 = xtmp\n \n ! print details\n print *, iter, norm2(F(x1))\n\n end do\n\n end subroutine secant\n\n !===================================================================!\n ! Use the same jacobian each iteration (linear convergence)\n !===================================================================!\n \n subroutine chord(F, FPRIME, tau_r, tau_a, max_it, x)\n\n real(8), intent(in) :: tau_r, tau_a\n integer, intent(in) :: max_it\n real(8), intent(inout) :: x(:)\n \n interface\n function F(x)\n real(8), intent(in) :: x(:)\n real(8) :: F(size(x))\n end function F\n function FPRIME(x)\n real(8), intent(in) :: x(:)\n real(8) :: FPRIME(size(x),size(x))\n end function FPRIME\n end interface\n\n ! local variables\n real(8) :: r0 \n real(8) :: jac(size(x),size(x))\n real(8) :: s(size(x))\n integer :: iter\n\n ! Initial residual\n r0 = norm2(F(x))\n\n ! Compute the jacobian once with the initial iterate\n jac = FPRIME(x)\n\n iter = 0\n do while (norm2(F(x)) > tau_r*r0 + tau_a .and. iter .le. max_it )\n\n ! Increment the iteration count\n iter = iter + 1\n \n ! Solve the linear system\n s = solve(jac, F(x))\n\n ! Apply the update\n x = x - s\n\n ! print details\n print *, iter, norm2(F(x))\n\n end do\n\n end subroutine chord\n\n !===================================================================!\n ! Eliminate linear solve by using identity jacobian\n !===================================================================!\n \n subroutine fixed_point(F, tau_r, tau_a, max_it, x)\n\n real(8), intent(in) :: tau_r, tau_a\n integer, intent(in) :: max_it\n real(8), intent(inout) :: x(:)\n\n interface\n function F(x)\n real(8), intent(in) :: x(:)\n real(8) :: F(size(x))\n end function F\n end interface\n\n ! local variables\n real(8) :: r0 \n integer :: iter\n\n ! Initial residual\n r0 = norm2(F(x))\n\n iter = 0\n do while (norm2(F(x)) > tau_r*r0 + tau_a .and. iter .le. max_it )\n\n ! Increment the iteration count\n iter = iter + 1\n\n ! Apply the update\n x = x - F(x)\n\n ! print details\n print *, iter, norm2(F(x))\n\n end do\n\n end subroutine fixed_point\n\n !===================================================================!\n ! Combines Newton and chord methods. This is efficient with LU\n ! factorization than the way its implemented here.\n !===================================================================!\n \n subroutine shamanskii(F, FPRIME, chord_iterations, tau_r, tau_a, max_it, x)\n\n real(8), intent(in) :: tau_r, tau_a\n integer, intent(in) :: max_it\n real(8), intent(inout) :: x(:)\n integer, intent(in) :: chord_iterations\n\n interface\n function F(x)\n real(8), intent(in) :: x(:)\n real(8) :: F(size(x))\n end function F\n function FPRIME(x)\n real(8), intent(in) :: x(:)\n real(8) :: FPRIME(size(x),size(x))\n end function FPRIME\n end interface\n\n ! Local variables\n real(8) :: r0 \n real(8) :: jac(size(x),size(x))\n real(8) :: s(size(x))\n integer :: newton_iter, chord_iter\n\n ! Initial residual\n r0 = norm2(F(x))\n \n newton_iter = 0\n quad_newton: do while (norm2(F(x)) > tau_r*r0 + tau_a .and. newton_iter .le. max_it)\n \n ! Increment the newton_iteration count\n newton_iter = newton_iter + 1\n\n ! Compute Jacobian\n jac = FPRIME(x)\n\n ! superlinear part \n chord_iter = 0\n suplin_chord: do while ( chord_iter .le. chord_iterations )\n\n ! Increment the iteration count\n chord_iter = chord_iter + 1\n\n ! Solve the linear system\n s = solve(jac, F(x))\n\n ! Apply the update\n x = x - s\n\n ! print details\n print *, \"sub-chord\", chord_iter, norm2(F(x))\n\n end do suplin_chord\n\n ! Solve the linear system\n s = solve(jac, F(x))\n\n ! Apply the update\n x = x - s\n\n ! print details\n print *, \"newton-\", newton_iter, norm2(F(x))\n\n end do quad_newton\n \n end subroutine shamanskii\n\nend module nonlinear_algebra\n", "meta": {"hexsha": "5d2ca34adea89a57e4e995f57615e82eec867be7", "size": 7939, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/nonlinear_algebra.f90", "max_stars_repo_name": "komahanb/math6644-iterative-methods", "max_stars_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-03-19T16:36:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-14T21:29:38.000Z", "max_issues_repo_path": "src/nonlinear_algebra.f90", "max_issues_repo_name": "komahanb/math6644-iterative-methods", "max_issues_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/nonlinear_algebra.f90", "max_forks_repo_name": "komahanb/math6644-iterative-methods", "max_forks_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-23T02:14:36.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-23T02:14:36.000Z", "avg_line_length": 23.8408408408, "max_line_length": 88, "alphanum_fraction": 0.4792795062, "num_tokens": 2134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.7865071903037686}} {"text": " program demo_exp\n implicit none\n real :: x , re, im\n complex :: cx\n\n x = 1.0\n write(*,*)\"Euler's constant is approximately\",exp(x)\n\n !! complex values\n ! given\n re=3.0\n im=4.0\n cx=cmplx(re,im)\n\n ! complex results from complex arguments are Related to Euler's formula\n write(*,*)'given the complex value ',cx\n write(*,*)'exp(x) is',exp(cx)\n write(*,*)'is the same as',exp(re)*cmplx(cos(im),sin(im),kind=kind(cx))\n\n ! exp(3) is the inverse function of log(3) so\n ! the real component of the input must be less than or equal to\n write(*,*)'maximum real component',log(huge(0.0))\n ! or for double precision\n write(*,*)'maximum doubleprecision component',log(huge(0.0d0))\n\n ! but since the imaginary component is passed to the cos(3) and sin(3)\n ! functions the imaginary component can be any real value\n\n end program demo_exp\n", "meta": {"hexsha": "d7dc5c234004e5368c12aff9cf91d2d0ea08d190", "size": 946, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/exp.f90", "max_stars_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_stars_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-12-31T17:21:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T15:56:29.000Z", "max_issues_repo_path": "example/exp.f90", "max_issues_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_issues_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/exp.f90", "max_forks_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_forks_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-06T15:56:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-06T15:56:31.000Z", "avg_line_length": 31.5333333333, "max_line_length": 78, "alphanum_fraction": 0.6035940803, "num_tokens": 263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526935, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7863858021487456}} {"text": "subroutine PlSchmidt(p,lmax,z)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function evalutates all of the Schmidt normalized legendre \n!\tpolynomials up to degree lmax. \n!\n!\tCalling Parameters:\n!\t\tOut\n!\t\t\tp:\tA vector of all Schmidt normalized Legendgre polynomials evaluated at \n!\t\t\t\tz up to lmax. The lenght must by greater or equal to (lmax+1).\n!\t\tIN\n!\t\t\tlmax:\tMaximum degree to compute.\n!\t\t\tz:\t[-1, 1], cos(colatitude) or sin(latitude).\n!\n!\tNotes:\n!\t\n!\t1.\tThe integral of plm**2 over (-1,1) is 2 * / (2l+1).\n!\t2.\tThe integral of Plm**2 over all space is 4 pi / (2l+1).\n!\n!\tDependencies:\tNone\n!\n!\tWritten by Mark Wieczorek June 2004\n!\n!\tCopyright (c) 2005, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\t\n\timplicit none\n\tinteger, intent(in) ::\tlmax\n\treal*8, intent(out) ::\tp(:)\n \treal*8, intent(in) ::\tz\n \treal*8 ::\tpm2, pm1, pl\n \tinteger ::\tl\n\n\n\tif (size(p) < lmax+1) then\n\t\tprint*, \"Error --- PlSchmidt\"\n \t\tprint*, \"P must be dimensioned as (LMAX+1) where LMAX is \", lmax \n \t\tprint*, \"Input array is dimensioned \", size(p)\n \t\tstop\n \telseif (lmax < 0) then \n \t\tprint*, \"Error --- PlSchmidt\"\n \t\tprint*, \"LMAX must be greater than or equal to 0.\"\n \t\tprint*, \"Input value is \", lmax\n \t\tstop\n \telseif(abs(z) > 1.0d0) then\n \t\tprint*, \"Error --- PlSchmidt\"\n \t\tprint*, \"ABS(Z) must be less than or equal to 1.\"\n \t\tprint*, \"Input value is \", z\n \t\tstop\n \tendif\n \t\n \tpm2 = 1.d0\n \tp(1) = 1.d0\n \t\n \tpm1 = z\n \tp(2) = pm1\n \t\n \tdo l = 2, lmax\n \tpl = ( dble(2*l-1) * z * pm1 - dble(l-1) * pm2 ) / dble(l)\n \tp(l+1) = pl\n \tpm2 = pm1\n \tpm1 = pl\n \tenddo\n\nend subroutine PlSchmidt\n\n", "meta": {"hexsha": "93ffb7408e98136e2e4cdd29b623c802d6de1569", "size": 1842, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/PlSchmidt.f95", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "spherical_splines/SHTOOLS/src/PlSchmidt.f95", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "spherical_splines/SHTOOLS/src/PlSchmidt.f95", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 27.0882352941, "max_line_length": 83, "alphanum_fraction": 0.5103148751, "num_tokens": 599, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467158, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.7863741714484248}} {"text": "program ch1211\n ! Stirling's Approximation\n implicit none\n\n real :: result, n, r\n\n print *, 'type in n and r'\n read *, n, r\n result = stirling(n)/(stirling(r)*stirling(n-r))\n print *, result\ncontains\n real function stirling(x)\n real, intent(in) :: x\n real, parameter :: pi = 3.1415927, &\n e = 2.7182828\n\n stirling = sqrt(2.*pi*x)*(x/e)**x\n end function\nend program\n", "meta": {"hexsha": "22c1d7a3a295655e3cce451e821300df5bd12e58", "size": 424, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch12/ch1211.f90", "max_stars_repo_name": "hechengda/fortran", "max_stars_repo_head_hexsha": "44735609ece7995d049016f758590d710b8a4f15", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ch12/ch1211.f90", "max_issues_repo_name": "hechengda/fortran", "max_issues_repo_head_hexsha": "44735609ece7995d049016f758590d710b8a4f15", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch12/ch1211.f90", "max_forks_repo_name": "hechengda/fortran", "max_forks_repo_head_hexsha": "44735609ece7995d049016f758590d710b8a4f15", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.2, "max_line_length": 52, "alphanum_fraction": 0.5660377358, "num_tokens": 130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632916317103, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7863741662623327}} {"text": "subroutine spline (x, y, b, c, d, n)\n!======================================================================\n! Calculate the coefficients b(i), c(i), and d(i), i=1,2,...,n\n! for cubic spline interpolation\n! s(x) = y(i) + b(i)*(x-x(i)) + c(i)*(x-x(i))**2 + d(i)*(x-x(i))**3\n! for x(i) <= x <= x(i+1)\n! Alex G: January 2010\n! from https://ww2.odu.edu/~agodunov/computing/programs/book2/Ch01/spline.f90\n!----------------------------------------------------------------------\n! input..\n! x = the arrays of data abscissas (in strictly increasing order)\n! y = the arrays of data ordinates\n! n = size of the arrays xi() and yi() (n>=2)\n! output..\n! b, c, d = arrays of spline coefficients\n! comments ...\n! spline.f90 program is based on fortran version of program spline.f\n! the accompanying function fspline can be used for interpolation\n!======================================================================\nimplicit none\ninteger n\ndouble precision x(n), y(n), b(n), c(n), d(n)\ninteger i, j, gap\ndouble precision h\n\ngap = n-1\n! check input\nif ( n < 2 ) return\nif ( n < 3 ) then\nb(1) = (y(2)-y(1))/(x(2)-x(1)) ! linear interpolation\nc(1) = 0.\nd(1) = 0.\nb(2) = b(1)\nc(2) = 0.\nd(2) = 0.\nreturn\nend if\n!\n! step 1: preparation\n!\nd(1) = x(2) - x(1)\nc(2) = (y(2) - y(1))/d(1)\ndo i = 2, gap\nd(i) = x(i+1) - x(i)\nb(i) = 2.0*(d(i-1) + d(i))\nc(i+1) = (y(i+1) - y(i))/d(i)\nc(i) = c(i+1) - c(i)\nend do\n!\n! step 2: end conditions\n!\nb(1) = -d(1)\nb(n) = -d(n-1)\nc(1) = 0.0\nc(n) = 0.0\nif(n /= 3) then\nc(1) = c(3)/(x(4)-x(2)) - c(2)/(x(3)-x(1))\nc(n) = c(n-1)/(x(n)-x(n-2)) - c(n-2)/(x(n-1)-x(n-3))\nc(1) = c(1)*d(1)**2/(x(4)-x(1))\nc(n) = -c(n)*d(n-1)**2/(x(n)-x(n-3))\nend if\n!\n! step 3: forward elimination\n\nif (abs(b(1)) .gt. 1.d100) then\n print*, b(1), x(1),y(1), c(1),d(1)\n print*, \"probable infinity in SPLINE\"\n stop\nend if\n\n!\ndo i = 2, n\nh = d(i-1)/b(i-1)\nb(i) = b(i) - h*d(i-1)\nc(i) = c(i) - h*c(i-1)\nend do\n!\n! step 4: back substitution\n!\nc(n) = c(n)/b(n)\ndo j = 1, gap\ni = n-j\nc(i) = (c(i) - d(i)*c(i+1))/b(i)\nend do\n!\n! step 5: compute spline coefficients\n!\nb(n) = (y(n) - y(gap))/d(gap) + d(gap)*(c(gap) + 2.0*c(n))\ndo i = 1, gap\nb(i) = (y(i+1) - y(i))/d(i) - d(i)*(c(i+1) + 2.0*c(i))\nd(i) = (c(i+1) - c(i))/d(i)\nc(i) = 3.*c(i)\nend do\nc(n) = 3.0*c(n)\nd(n) = d(n-1)\nend subroutine spline\n\n\n\nfunction ispline(u, x, y, b, c, d, n)\n!======================================================================\n! function ispline evaluates the cubic spline interpolation at point z\n! ispline = y(i)+b(i)*(u-x(i))+c(i)*(u-x(i))**2+d(i)*(u-x(i))**3\n! where x(i) <= u <= x(i+1)\n!----------------------------------------------------------------------\n! input..\n! u = the abscissa at which the spline is to be evaluated\n! x, y = the arrays of given data points\n! b, c, d = arrays of spline coefficients computed by spline\n! n = the number of data points\n! output:\n! ispline = interpolated value at point u\n!=======================================================================\nimplicit none\ndouble precision ispline\ninteger n\ndouble precision u, x(n), y(n), b(n), c(n), d(n)\ninteger i, j, k\ndouble precision dx\n! print*,\"isplining\", u\n! if u is ouside the x() interval take a boundary value (left or right)\nif(u <= x(1)) then\nispline = y(1)\nreturn\nend if\nif(u >= x(n)) then\nispline = y(n)\nreturn\nend if\n\n!*\n! binary search for for i, such that x(i) <= u <= x(i+1)\n!*\ni = 1\nj = n+1\ndo while (j > i+1)\nk = (i+j)/2\nif(u < x(k)) then\n j=k\n else\n i=k\nend if\nend do\n!*\n! evaluate spline interpolation\n!*\ndx = u - x(i)\nispline = y(i) + dx*(b(i) + dx*(c(i) + dx*d(i)))\nend function ispline\n\n\n\nFUNCTION DSdecimate(vectorin,meshin,meshout)\n!averages a vector of size meshin down to something of size meshout\ninteger, intent(IN) :: meshout\ninteger, intent(IN) :: meshin\ninteger decfactor,icnt\ndouble precision vectorin(meshin)\ndouble precision vectorout(meshout)\ndouble precision, dimension(meshout) :: DSdecimate\n! if(meshin.ne.meshout)then\ndecfactor = INT(meshin/meshout) !if it were a real decimator, this would be 10/9. And vectorIn would be a Roman legion.\nprint*, \"decfactor\",decfactor\nvectorOut = vectorIn(1:meshin:decfactor)\n\nDSdecimate = vectorOut\n\nreturn\nEND FUNCTION DSdecimate\n", "meta": {"hexsha": "8df168ef528aefc8f66ebb2ea641c61420212432", "size": 4195, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "numerical/spline.f90", "max_stars_repo_name": "Laen111/captnoper", "max_stars_repo_head_hexsha": "f90c75d3bf8725895f729be5671059da3b9c38c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-09-15T07:43:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-18T08:31:43.000Z", "max_issues_repo_path": "numerical/spline.f90", "max_issues_repo_name": "Laen111/captnoper", "max_issues_repo_head_hexsha": "f90c75d3bf8725895f729be5671059da3b9c38c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 15, "max_issues_repo_issues_event_min_datetime": "2020-11-03T05:21:31.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-25T20:06:40.000Z", "max_forks_repo_path": "numerical/spline.f90", "max_forks_repo_name": "Laen111/captnoper", "max_forks_repo_head_hexsha": "f90c75d3bf8725895f729be5671059da3b9c38c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-17T03:32:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-17T03:32:34.000Z", "avg_line_length": 24.6764705882, "max_line_length": 119, "alphanum_fraction": 0.5344457688, "num_tokens": 1537, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404096760996, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.786253090909278}} {"text": "PROGRAM TrapezoidalRuleForIntegration\n IMPLICIT NONE \n REAL:: a, b, Area\n INTEGER:: N ! N is number of segment\n WRITE(*, fmt = '(/A)', ADVANCE = 'NO') \"Enter the number of segment: \"\n READ(*, *) N \n WRITE(*, fmt = '(/A)') \"Enter the value of a & b\"\n READ(*, *) a, b\n\n CALL TrapezoidalRule(a, b, Area, N)\n WRITE(*, *) \"Area under the curve is: \", Area\n\n CONTAINS\n SUBROUTINE TrapezoidalRule(a, b, Area, N)\n IMPLICIT NONE \n REAL:: a, b, Area, Xi\n INTEGER:: N, i\n ! N is number of segment\n IF(N .LT. 1) THEN\n Area = 0.0\n RETURN \n ENDIF\n Area = (f(a) + f(b)) / 2.0\n DO i = 1, N-1\n Xi = a + i * (b-a)/N\n Area = Area + f(Xi)\n ENDDO\n Area = ((b-a)/N) * Area\n END SUBROUTINE TrapezoidalRule\n\n REAL FUNCTION f(x)\n IMPLICIT NONE \n REAL:: x \n f = 1.0/x \n return\n END FUNCTION f\n\nEND PROGRAM TrapezoidalRuleForIntegration", "meta": {"hexsha": "1fbdf2977b3db77fe8694526c5edc80b71736c9b", "size": 1000, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Numerical Integration/Trapezoidal_Rule.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Numerical Integration/Trapezoidal_Rule.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Numerical Integration/Trapezoidal_Rule.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 26.3157894737, "max_line_length": 74, "alphanum_fraction": 0.504, "num_tokens": 319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.936285002192296, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.7862303235182199}} {"text": "\tSUBROUTINE enercalc(Nx,dt,Es,enkin,enstr,enpot,en,dx,u,uold)\n\t!--------------------------------------------------------------------\n\t!\n\t!\n\t! PURPOSE\n\t!\n\t! This subroutine program calculates the energy for the nonlinear \n\t! Klein-Gordon equation in 1 dimension\n\t! u_{tt}-u_{xx}+u=Es*|u|^2u\n\t!\n\t! The energy density is given by \n\t! 0.5u_t^2+0.5u_x^2+0.5u^2+Es*0.25u^4\n\t!\n\t! INPUT \n\t!\n\t! .. Scalars ..\n\t! Nx\t\t\t\t= number of grid points in x\n\t! dt\t\t\t\t= timestep\n\t! Es\t\t\t\t= +1 for focusing, -1 for defocusing\n\t! dx = spatial discretization\n ! .. Vectors ..\n\t! u \t\t\t\t= approximate solution\n\t! uold \t\t\t= approximate solution\n\t!\n\t! OUTPUT\n\t!\n\t! .. Scalars ..\n\t! enkin\t\t\t= Kinetic energy\n\t! enstr\t\t\t= Strain energy\n\t! enpot\t\t\t= Potential energy\n\t! en\t\t\t\t= Total energy\n\t!\n\t! LOCAL VARIABLES\n\t!\n\t! .. Scalars ..\n\t! i\t\t\t\t= loop counter in x direction\n\t!\n\t! REFERENCES\n\t!\n\t! ACKNOWLEDGEMENTS\n\t!\n\t! ACCURACY\n\t!\t\t\n\t! ERROR INDICATORS AND WARNINGS\n\t!\n\t! FURTHER COMMENTS\n\t! Check that the initial iterate is consistent with the \n\t! boundary conditions for the domain specified\n\t!--------------------------------------------------------------------\n\t! External routines required\n\t!\n\t! External libraries required\n\t! \tOpenMP library\n\tUSE omp_lib\t\t \t \n\tIMPLICIT NONE\t\t\t\t\t \n\t! Declare variables\n\tINTEGER(KIND=4), INTENT(IN)\t\t\t:: Nx\n\tREAL(KIND=8), INTENT(IN)\t\t\t:: dt,Es,dx\n\tREAL(KIND=8), DIMENSION(1:Nx),INTENT(IN)\t:: u,uold\n\tREAL(KIND=8), INTENT(OUT)\t\t\t:: enkin,enstr\n\tREAL(KIND=8), INTENT(OUT)\t\t\t:: enpot,en\t\n\tINTEGER(KIND=4)\t\t\t\t\t:: i,ip\n\n\t\n\t!.. Strain energy ..\n enstr=0.0d0\n\t!!$OMP PARALLEL DO PRIVATE(i,ip) SCHEDULE(static)\n\tDO i=1,Nx\n ip=1+mod(i+1+Nx-1,Nx)\n\t\tenstr=enstr+0.5d0*abs( 0.5d0*(u(ip)+uold(ip)-u(i)-uold(i))/dx )**2\n\tEND DO\n\t!!$OMP END PARALLEL DO\n\n\t! .. Kinetic Energy ..\n enkin=0.0d0\n\t!!$OMP PARALLEL DO PRIVATE(i) SCHEDULE(static)\n\tDO i=1,Nx\n\t\tenkin=enkin+0.5d0*( abs(u(i)-uold(i))/dt )**2\n\tEND DO\n\t!!$OMP END PARALLEL DO\n\t\n\t! .. Potential Energy ..\n enpot=0.0d0\n\t!!$OMP PARALLEL DO PRIVATE(i) SCHEDULE(static)\n\tDO i=1,Nx\n\t\tenpot=enpot+0.5d0*(abs((u(i)+uold(i))*0.50d0))**2 &\n\t\t\t -0.125d0*Es*(abs(u(i))**4+abs(uold(i))**4)\n\tEND DO\n\t!!$OMP END PARALLEL DO\n enpot=enpot/Nx\n enkin=enkin/Nx\n enstr=enstr/Nx\t\n\ten=enpot+enkin+enstr\n\t\n\tEND SUBROUTINE enercalc\n", "meta": {"hexsha": "288fb1d65708cdbdaf8ac711503f3bd0e752f38c", "size": 2359, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Codes/Fortran1DFiniteDifference8thOrderCompact/enercalc.f90", "max_stars_repo_name": "bkmgit/KleinGordon1D", "max_stars_repo_head_hexsha": "ce6ba332e542d74b72069ae253cca5e0a2ade425", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-01-21T03:57:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-21T03:57:51.000Z", "max_issues_repo_path": "Codes/Fortran1DFiniteDifference8thOrderCompact/enercalc.f90", "max_issues_repo_name": "bkmgit/KleinGordon1D", "max_issues_repo_head_hexsha": "ce6ba332e542d74b72069ae253cca5e0a2ade425", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Codes/Fortran1DFiniteDifference8thOrderCompact/enercalc.f90", "max_forks_repo_name": "bkmgit/KleinGordon1D", "max_forks_repo_head_hexsha": "ce6ba332e542d74b72069ae253cca5e0a2ade425", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.5729166667, "max_line_length": 70, "alphanum_fraction": 0.5693090292, "num_tokens": 868, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.8652240791017535, "lm_q1q2_score": 0.7861580895521446}} {"text": "module shoelace_implementation\nimplicit none\ncontains\n\treal function shoelace(Ax, Ay, Bx, By, Cx, Cy, Dx, Dy)\n\timplicit none\n\t\treal, intent(in) :: Ax, Ay, Bx, By, Cx, Cy, Dx, Dy\n\t\t\n\t\tshoelace = 0.5 * ( &\n\t\t\t(Ax * By + Bx * Cy + Cx * Dy + Dx * Ay) - &\n\t\t\t(Bx * Ay + Cx * By + Dx * Cy + Ax * Dy) &\n\t\t)\n\tend function shoelace\n\t\n\tlogical function cross(X1, Y1, X2, Y2, X3, Y3)\n\timplicit none\n\t\treal, intent(in) :: X1, Y1, X2, Y2, X3, Y3\n\t\t\n\t\tcross = (Y3 - Y1) * (X2 - X1) > (Y2 - Y1) * (X3 - X1)\n\tend function cross\n\t\n\tlogical function intersect(Ax, Ay, Bx, By, Cx, Cy, Dx, Dy)\n\timplicit none\n\t\treal, intent(in) :: Ax, Ay, Bx, By, Cx, Cy, Dx, Dy\n\t\t\n\t\tintersect = &\n\t\t\t(cross(Ax, Ay, Cx, Cy, Dx, Dy) .neqv. cross(Bx, By, Cx, Cy, Dx, Dy)) .and. &\n\t\t\t(cross(Ax, Ay, Bx, By, Cx, Cy) .neqv. cross(Ax, Ay, Bx, By, Dx, Dy))\n\tend function intersect\nend module shoelace_implementation\n\n", "meta": {"hexsha": "0a039abab7ad851356fcd94269f1368eb14a7bdd", "size": 873, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "shoelace_implementation.f95", "max_stars_repo_name": "bachvaroff/shoelace", "max_stars_repo_head_hexsha": "910e5310112728bae37390fceab3122ce57700d1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "shoelace_implementation.f95", "max_issues_repo_name": "bachvaroff/shoelace", "max_issues_repo_head_hexsha": "910e5310112728bae37390fceab3122ce57700d1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "shoelace_implementation.f95", "max_forks_repo_name": "bachvaroff/shoelace", "max_forks_repo_head_hexsha": "910e5310112728bae37390fceab3122ce57700d1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1612903226, "max_line_length": 79, "alphanum_fraction": 0.5853379152, "num_tokens": 369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475778774728, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7861147366208829}} {"text": "FUNCTION lngamma(z) RESULT(lanczos)\r\n\r\n! Uses Lanczos-type approximation to ln(gamma) for z > 0.\r\n! Reference:\r\n! Lanczos, C. 'A precision approximation of the gamma\r\n! function', J. SIAM Numer. Anal., B, 1, 86-96, 1964.\r\n! Accuracy: About 14 significant digits except for small regions\r\n! in the vicinity of 1 and 2.\r\n\r\n! Programmer: Alan Miller\r\n! 1 Creswick Street, Brighton, Vic. 3187, Australia\r\n! e-mail: amiller @ bigpond.net.au\r\n! Latest revision - 14 October 1996\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: doub_prec = SELECTED_REAL_KIND(15, 60)\r\nREAL(doub_prec), INTENT(IN) :: z\r\nREAL(doub_prec) :: lanczos\r\n\r\n! Local variables\r\n\r\nREAL(doub_prec) :: a(9) = (/ 0.9999999999995183D0, 676.5203681218835D0, &\r\n -1259.139216722289D0, 771.3234287757674D0, &\r\n -176.6150291498386D0, 12.50734324009056D0, &\r\n -0.1385710331296526D0, 0.9934937113930748D-05, &\r\n 0.1659470187408462D-06 /), zero = 0.D0, &\r\n one = 1.d0, lnsqrt2pi = 0.9189385332046727D0, &\r\n half = 0.5d0, sixpt5 = 6.5d0, seven = 7.d0, tmp\r\nINTEGER :: j\r\n\r\nIF (z <= zero) THEN\r\n WRITE(*, *)'Error: zero or -ve argument for lngamma'\r\n RETURN\r\nEND IF\r\n\r\nlanczos = zero\r\ntmp = z + seven\r\nDO j = 9, 2, -1\r\n lanczos = lanczos + a(j)/tmp\r\n tmp = tmp - one\r\nEND DO\r\nlanczos = lanczos + a(1)\r\nlanczos = LOG(lanczos) + lnsqrt2pi - (z + sixpt5) + (z - half)*LOG(z + sixpt5)\r\nRETURN\r\n\r\nEND FUNCTION lngamma\r\n\r\n\r\n", "meta": {"hexsha": "a9410d52f9466a4d3623633d982b32b2710e7797", "size": 1626, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/lanczos.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/lanczos.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/lanczos.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 33.1836734694, "max_line_length": 79, "alphanum_fraction": 0.5639606396, "num_tokens": 533, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475715065794, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.786114727406982}} {"text": "MODULE INT_MOD\r\n\r\n! The Interpolation Module contains two procedures that interpolate data:\r\n! Subroutine linint uses linear interpolation.\r\n! Subroutine polintd uses polynomial interpolation.\r\n!\r\n! Created by: Elizabeth North\r\n! Modified by: Zachary Schlag\r\n! Created on: 2003\r\n! Last Modified on: 11 Aug 2008\r\n\r\nIMPLICIT NONE\r\nPUBLIC\r\n\r\nCONTAINS\r\n\r\n! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n! ~~ ~~\r\n! ~~ SUBROUTINE linint ~~\r\n! ~~ ~~\r\n! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\n SUBROUTINE linint(xa,ya,n,x,y,m)\r\n IMPLICIT NONE\r\n INTEGER, INTENT(IN) :: n\r\n DOUBLE PRECISION, INTENT(IN) :: xa(n),ya(n),x\r\n DOUBLE PRECISION, INTENT(OUT) :: y,m\r\n\r\n INTEGER :: jlo,jhi,k\r\n DOUBLE PRECISION :: b\r\n\r\n jlo=1 \r\n jhi=n\r\n\r\n !determine which two xa location that x lies between\r\n do\r\n k=(jhi+jlo)/2\r\n\r\n if(xa(k).gt.x)then\r\n jhi=k\r\n else\r\n jlo=k\r\n endif\r\n\r\n if (jhi-jlo == 1) exit\r\n enddo\r\n\r\n !calculate the slope and intersect\r\n m = ( ya(jlo) - ya(jhi) )/ ( xa(jlo) - xa(jhi) )\r\n b = ya(jlo) - m*xa(jlo)\r\n\r\n !linearly interpolate y\r\n y = m*x + b\r\n\r\n return\r\n\r\n END SUBROUTINE linint\r\n\r\n\r\n! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n! ~~ ~~\r\n! ~~ FUNCTION polintd ~~\r\n! ~~ ~~\r\n! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\n DOUBLE PRECISION FUNCTION polintd(xa,ya,n,x)\r\n IMPLICIT NONE\r\n INTEGER, INTENT(IN) :: n\r\n DOUBLE PRECISION, INTENT(IN) :: xa(n),ya(n),x\r\n\r\n INTEGER :: i,ns\r\n DOUBLE PRECISION :: dif,dift,a,b,c\r\n\r\n ns=1\r\n dif=abs(x-xa(1))\r\n\r\n !Here we find the index, ns, of the closest table entry\r\n do i=1,n\r\n dift=abs(x-xa(i))\r\n if (dift.lt.dif) then\r\n ns=i\r\n dif=dift\r\n endif\r\n enddo \r\n\r\n !calculate the value of c\r\n c = (xa(2)-x) * ( (ya(3)-ya(2)) / (xa(2)-xa(3)) )\r\n c = c - (xa(2)-x) * ( (ya(2)-ya(1)) / (xa(1)-xa(2)) )\r\n c = c / (xa(1) - xa(3))\r\n\r\n !calculate the values of a and b\r\n if (ns .EQ. 3) then\r\n a = (ya(3)-ya(2))/(xa(2)-xa(3))\r\n b = xa(3)-x\r\n else\r\n a = (ya(2)-ya(1))/(xa(1)-xa(2))\r\n b = xa(1)-x\r\n endif\r\n\r\n !calculate the value of polintd via polynomial interpolation\r\n polintd = ya(ns) + (xa(ns)-x)*a + b*c\r\n\r\n END FUNCTION polintd\r\n\r\nEND MODULE INT_MOD", "meta": {"hexsha": "7ca949272f8e4ff42ce6345d2d205c380ca286d0", "size": 3053, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "interpolation_module.f90", "max_stars_repo_name": "NOC-MSM/LTRANS-for-NEMO", "max_stars_repo_head_hexsha": "28ac1ae1b98d7b56d74110fa8f1f9cb6fcc305c8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-06-08T01:05:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-08T02:16:25.000Z", "max_issues_repo_path": "Model/interpolation_module.f90", "max_issues_repo_name": "Jhongesell/LTRANSv.2b", "max_issues_repo_head_hexsha": "18d4118df36597a1cdac1e1f15dc96b00bd8448d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-07-06T21:46:05.000Z", "max_issues_repo_issues_event_max_datetime": "2017-07-06T21:46:05.000Z", "max_forks_repo_path": "Model/interpolation_module.f90", "max_forks_repo_name": "Jhongesell/LTRANSv.2b", "max_forks_repo_head_hexsha": "18d4118df36597a1cdac1e1f15dc96b00bd8448d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2018-11-22T12:54:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-08T02:16:26.000Z", "avg_line_length": 28.0091743119, "max_line_length": 75, "alphanum_fraction": 0.3727481166, "num_tokens": 775, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.7860823775123316}} {"text": "! Created by EverLookNeverSee@GitHub on 5/27/20\n! This Program computes mean and standrd deviation of n experimental sequence.\n\nsubroutine mean(n, seq, mean_value)\n implicit none\n ! declaring parameters\n integer :: i, n\n real, intent(in) :: seq(n)\n real, intent(out) :: mean_value\n real :: sum = 0.\n ! Calculating mean value and returning it\n do i = 1, n\n sum = sum + seq(i)\n end do\n mean_value = sum / n\n return\nend subroutine mean\n\nsubroutine standrd_deviation(n, seq, x_bar, sd)\n implicit none\n ! declaring parameters\n integer :: i, n\n real, intent(in) :: seq(n)\n real, intent(in) :: x_bar\n real, intent(out) :: sd\n real :: sum = 0.\n ! calculating sum of elements minus mean value\n do i = 1, n\n sum = sum + (seq(i) - x_bar) ** 2\n end do\n ! calculating square root and returning result\n sd = sqrt(sum / (n - 1))\n return\nend subroutine standrd_deviation\n\n\nprogram main\n implicit none\n ! declaring variables\n real, allocatable, dimension(:) :: A\n real :: mean_value, sta_dev\n integer :: n, i\n ! specifying number of elements in sequence\n do\n print *,\"Enter nubmer of elements in sequence:\"\n read *, n\n if (n <= 0) then\n print *, \"Please enter a positive integer!\"\n cycle\n end if\n exit\n end do\n ! allocating memory space for array\n allocate(A(n))\n ! getting elements of the sequence\n do i = 1, n\n print *, \"A(\", i, \"):\"\n read *, A(i)\n end do\n ! calling subroutines and printing results\n call mean(n, A, mean_value)\n call standrd_deviation(n, A, mean_value, sta_dev)\n print *, \"mean:\", mean_value, \"standrd deviation:\", sta_dev\nend program main", "meta": {"hexsha": "a16ceaed3e3a758cb6663fdbfb322641290c4231", "size": 1750, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/other/mean_sd_x.f90", "max_stars_repo_name": "EverLookNeverSee/FCS", "max_stars_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-14T10:30:25.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-17T13:03:15.000Z", "max_issues_repo_path": "src/other/mean_sd_x.f90", "max_issues_repo_name": "EverLookNeverSee/FCS", "max_issues_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-06-06T13:54:45.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-25T20:32:23.000Z", "max_forks_repo_path": "src/other/mean_sd_x.f90", "max_forks_repo_name": "EverLookNeverSee/FCS", "max_forks_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-08T12:57:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T12:57:46.000Z", "avg_line_length": 27.34375, "max_line_length": 78, "alphanum_fraction": 0.6108571429, "num_tokens": 481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705931, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7860566531060229}} {"text": "MODULE m_legendre1\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! MODULE: m_legendre1.f03\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Module for calling the legendre_drv1 subroutine \r\n! \r\n! Subroutines contained within the module:\r\n! - legendre_drv1\r\n! ----------------------------------------------------------------------\r\n! Author :\tDr. Thomas Papanikolaou\r\n!\t\t\tCooperative Research Centre for Spatial Information, Australia\r\n! Created:\t16 November 2017\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n IMPLICIT NONE\r\n !SAVE \t\t\t\r\n \r\n\t \r\nContains\r\n\r\nSUBROUTINE legendre_drv1 (phi, nmax, dPnm_norm)\r\n\r\n\r\n! ---------------------------------------------------------------------------\r\n! Subroutine: legendre_drv1.f90\r\n! ---------------------------------------------------------------------------\r\n! Purpose:\r\n! Computation of the first order derivatives of the Normalized Associated\r\n! Legendre functions\r\n! \r\n! Evaluation of Legendre functions is based on Recurrence relations\r\n! ---------------------------------------------------------------------------\r\n! Input arguments:\r\n! - phi:\t\t\tSpherical latitude (radians)\r\n! - nmax:\t\t\tMaximum degree expansion\r\n! \r\n! Output arguments:\r\n! - dPnm_norm: \t\tFirst order derivatives of Normalized Associated Legendre\r\n! \t\t\t\tfunctions up to degree n\r\n! ---------------------------------------------------------------------------\r\n! Author :\tDr. Thomas Papanikolaou, Cooperative Research Centre for Spatial Information, Australia\r\n! Created:\tSeptember 2015\r\n! ----------------------------------------------------------------------\r\n! Last modified:\r\n! - Dr. Thomas Papanikolaou, 16 November 2017:\r\n!\tUpgraded from Fortran 90 to Fortran 2003 for considering the\r\n!\tFortran 2003 advantages in dynamic memory allocation\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n USE mdl_precision\r\n USE mdl_num\r\n USE m_legendre\r\n IMPLICIT NONE\r\n\r\n! ----------------------------------------------------------------------\r\n! Dummy arguments declaration\r\n! ----------------------------------------------------------------------\r\n! IN\r\n INTEGER (KIND = prec_int8), INTENT(IN) :: nmax\r\n REAL (KIND = prec_q), INTENT(IN) :: phi \r\n! OUT\r\n REAL (KIND = prec_q), INTENT(OUT), DIMENSION(:,:), ALLOCATABLE :: dPnm_norm\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Local variables declaration\r\n! ----------------------------------------------------------------------\r\n REAL (KIND = prec_q), DIMENSION(:,:), ALLOCATABLE :: Pnm_norm\r\n INTEGER (KIND = prec_int8) :: n, m\t \r\n INTEGER (KIND = prec_int2) :: AllocateStatus\r\n REAL (KIND = prec_q) :: pi\r\n REAL (KIND = prec_q) :: theta, c, s\r\n REAL (KIND = prec_q) :: dPoo, dP10,dP11, dP_f1,dP_f2,dP_f3, SQRT_nm_prod\r\n! ----------------------------------------------------------------------\r\n\r\n\t \r\n! ----------------------------------------------------------------------\r\n! Allocatable arrays\r\n! ----------------------------------------------------------------------\r\n ALLOCATE (dPnm_norm(nmax+1,nmax+1), STAT = AllocateStatus)\r\n! print *,\"dPnm_norm AllocateStatus=\", AllocateStatus\r\n IF (AllocateStatus /= 0) THEN\r\n PRINT *, \"Error: Not enough memory\"\r\n PRINT *, \"Error: SUBROUTINE legendre_drv1.f\"\r\n PRINT *, \"Error: Allocatable Array: Pnm_norm, Nmax =\", nmax\r\n! STOP \"*** Not enough memory ***\"\r\n END IF\r\n! ----------------------------------------------------------------------\r\ndPnm_norm = 0.0D0\r\n\r\n! ----------------------------------------------------------------------\r\n! Numerical Constants\r\n pi = PI_global\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Normalized associated Legendre functions\r\n CALL legendre (phi, nmax, Pnm_norm)\r\n! ----------------------------------------------------------------------\r\n\r\n theta = pi/2D0 - phi\r\n c = cos(theta)\r\n s = sin(theta)\r\n\r\n! Initial values\r\n dPoo = 0D0\r\n dP10 = - sqrt(3D0) * s\r\n dP11 = sqrt(3D0) * c\r\n\r\n\t \r\n! ----------------------------------------------------------------------\r\n! Derivatives for order m=0 and variable degree n\r\n! ----------------------------------------------------------------------\r\n DO n = 0 , nmax\r\n IF (n==0) THEN\r\n dPnm_norm(n+1,0+1) = dPoo\r\n ELSE IF (n==1) THEN\r\n dPnm_norm(n+1,0+1) = dP10\r\n ELSE \r\n dP_f1 = sqrt(2D0*n-1) * &\r\n \t\t ( c * dPnm_norm(n-1+1,0+1) - s * Pnm_norm(n-1+1,0+1) )\r\n\r\n dPnm_norm(n+1,0+1) = (sqrt(2D0*n+1) / n) * &\r\n \t\t (dP_f1 - ((n-1) / sqrt(2D0*n-3)) * dPnm_norm(n-2+1,0+1))\r\n END IF\r\n END DO\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Derivatives for equal degree n and order m \r\n! ----------------------------------------------------------------------\r\n DO n = 1 , nmax\r\n IF (n == 1) THEN\r\n dPnm_norm(n+1,n+1) = dP11\r\n ELSE\r\n dPnm_norm(n+1,n+1) = ( sqrt(2D0*n+1) / sqrt(2D0*n) ) * &\r\n \t\t (s * dPnm_norm(n-1+1,n-1+1) + c * Pnm_norm(n-1+1,n-1+1))\r\n END IF\r\n END DO\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Derivatives for variable degree n and order m\r\n! ----------------------------------------------------------------------\r\n DO n = 2 , nmax\r\n DO m = 1 , n\r\n! ----------------------------------------------------------------------\r\n\t\t\t ! Case : m = n - 1\r\n IF ( n == (m+1) ) THEN\r\n dP_f2 = c * dPnm_norm(n-1+1,m+1) - s * Pnm_norm(n-1+1,m+1)\r\n dPnm_norm(n+1,m+1) = sqrt(1D0*(2*n+1)) * dP_f2\r\n! ----------------------------------------------------------------------\r\n\t\t\t ! Case : n > m + 1\r\n ELSE IF ( n > (m+1) ) THEN\r\n dP_f2 = c * dPnm_norm(n-1+1,m+1) - s * Pnm_norm(n-1+1,m+1)\r\n dP_f3 = sqrt( (1D0*(n-1+m)*(n-1-m)) / (1D0*(2*n-3)) ) * dPnm_norm(n-2+1,m+1)\r\n SQRT_nm_prod = sqrt( (n+m)*(n-m) *1D0 )\t\t\t \r\n dPnm_norm(n+1,m+1) = ( sqrt(2D0*n+1) / SQRT_nm_prod ) * ( sqrt(2D0*n-1) * dP_f2 - dP_f3 )\r\n END IF\r\n! ----------------------------------------------------------------------\r\n END DO\r\n END DO\r\n! ----------------------------------------------------------------------\r\n\r\nEND SUBROUTINE\r\n\r\n\r\n\r\nEND Module\r\n", "meta": {"hexsha": "1099f33ab9cd913cfbddcf7d2c4db9d1bea3e8dd", "size": 6931, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/m_legendre1.f03", "max_stars_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_stars_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2021-07-08T23:35:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:17:58.000Z", "max_issues_repo_path": "src/fortran/m_legendre1.f03", "max_issues_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_issues_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-09-27T14:27:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T23:50:02.000Z", "max_forks_repo_path": "src/fortran/m_legendre1.f03", "max_forks_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_forks_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2021-07-12T05:42:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T15:15:34.000Z", "avg_line_length": 38.9382022472, "max_line_length": 108, "alphanum_fraction": 0.3456932622, "num_tokens": 1566, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897558991953, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7860143567831455}} {"text": "module SimpleVectors\n !! This module contains the basis linear algebra operation\n !! used in Krylov solver applied to the standard Fortran vectors \n use Precision\n implicit none\n public\n\ncontains\n !! y= alpha*x+beta*y\n !! It should cover daxpy, dcopy, dscal\n subroutine d_axpby(n,alpha,x,beta,y)\n implicit none\n integer, intent(in ) :: n\n real(kind=double), intent(in ) :: alpha\n real(kind=double), intent(in ) :: x(n)\n real(kind=double), intent(in ) :: beta\n real(kind=double), intent(inout) :: y(n)\n\n !! not optimized\n y=alpha*x+beta*y\n \n end subroutine d_axpby\n\n !! set identity dimensions\n function d_scalar_product(n,x,y) result(xty)\n implicit none\n integer, intent(in ) :: n\n real(kind=double), intent(in ) :: x(n)\n real(kind=double), intent(in ) :: y(n)\n real(kind=double) :: xty\n !local\n integer :: i\n\n !! not optimized\n xty=zero\n do i=1,n\n xty=xty+x(i)*y(i)\n end do\n \n end function d_scalar_product\n\n !! set identity dimensions\n function d_norm(n,x) result(out)\n implicit none\n integer, intent(in ) :: n\n real(kind=double), intent(in ) :: x(n)\n real(kind=double) :: out\n out=sqrt(d_scalar_product(n,x,x)) \n end function d_norm\n\nend module SimpleVectors\n", "meta": {"hexsha": "a2198e00174c1f258386ff60f7b2d6951fc6ae3c", "size": 1339, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/SimpleVectors.f90", "max_stars_repo_name": "enricofacca/KrylovAPI", "max_stars_repo_head_hexsha": "33ced13dcad32b83aae867bebac894e7b82aab8f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/SimpleVectors.f90", "max_issues_repo_name": "enricofacca/KrylovAPI", "max_issues_repo_head_hexsha": "33ced13dcad32b83aae867bebac894e7b82aab8f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/SimpleVectors.f90", "max_forks_repo_name": "enricofacca/KrylovAPI", "max_forks_repo_head_hexsha": "33ced13dcad32b83aae867bebac894e7b82aab8f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.75, "max_line_length": 67, "alphanum_fraction": 0.6056758775, "num_tokens": 373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.7858096134048512}} {"text": "module lagrange_mod\n\nuse constants_mod\n\n!integer, parameter :: RP = selected_real_kind(15)\n!real, parameter :: PI = 4.0_rp * atan(1.0_rp)\n!real, parameter :: TOL = 4.0e-16\n\nCONTAINS\n\nsubroutine lagrange_diffMatrix(x,n,d)\n\n integer, intent(in) :: n\n\n real(dp), dimension(n), intent(in) :: x\n real(dp), dimension(n,n), intent(out) :: d\n\n integer :: i,j\n real(dp), dimension(n) :: w\n\n call lagrange_barycentricweights(x,n,w)\n\n do i=1,n\n do j=1,n\n if (i.eq.j) cycle\n d(i,j) = w(j) / ( w(i) * (x(i)-x(j)) )\n d(i,i) = d(i,i) - d(i,j)\n end do\n end do\n\nend subroutine\n\nsubroutine lagrange_barycentricWeights(x,n,w)\n\n integer, intent(in) :: N\n real(dp), intent(in) :: x(N)\n real(dp), intent(out) :: w(N)\n\n integer :: i,j\n\n w = 1\n\n do j=1,n\n do i=1,n\n if (j.eq.i) cycle\n w(j) = w(j) / (x(j)-x(i))\n end do\n end do\n\nend subroutine\n\npure function lagrange_polynomial(N, nodes, j, x) result(lp)\n \n integer, intent(in) :: N\n real(dp), intent(in) :: nodes(N)\n integer, intent(in) :: j\n real(dp), intent(in) :: x\n\n real(dp) :: lp\n integer :: i\n\n lp = 1.0_dp\n\n if (abs(x-nodes(j)) < 10.0_dp*TOL) return !! Kronecker property\n\n do i = 1,N\n if (i == j) cycle\n lp = lp * (x - nodes(i))/(nodes(j) - nodes(i))\n end do\n \nend function\n\npure function lagrange_basis(N, nodes, x) result(lp)\n \n integer, intent(in) :: N\n real(dp), intent(in) :: nodes(N)\n real(dp), intent(in) :: x\n\n real(dp) :: lp(N)\n integer :: i\n\n !! Kronecker property\n if (any(abs(x-nodes) < 10*TOL)) then\n lp = merge(1.0_dp,0.0_dp,abs(x-nodes) < 10.0_dp*TOL)\n return\n end if\n\n do i = 1,N\n lp(i) = Lagrange_Polynomial(N, nodes, i, x)\n end do\n \nend function\n\npure subroutine lagrange_VanderMondeMatrix(N, M, xs, ys, Vdm)\n\n integer, intent(in) :: N, m\n real(dp), intent(in) :: xs(N), ys(M)\n real(dp), intent(out) :: Vdm(M,N)\n\n integer :: i\n\n do i = 1,M\n Vdm(i,:) = Lagrange_Basis(N, xs, ys(i))\n end do\n\nend subroutine\n\nend module\n", "meta": {"hexsha": "958c1487ba480b230c2ab2c7a926f898b11917d1", "size": 2272, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/utils/lagrange_mod.f90", "max_stars_repo_name": "jmark/nemo", "max_stars_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/utils/lagrange_mod.f90", "max_issues_repo_name": "jmark/nemo", "max_issues_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/utils/lagrange_mod.f90", "max_forks_repo_name": "jmark/nemo", "max_forks_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.8440366972, "max_line_length": 67, "alphanum_fraction": 0.5088028169, "num_tokens": 724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.8577680977182186, "lm_q1q2_score": 0.7858095966207194}} {"text": "\n! Starting with 1 and spiralling anticlockwise in the following way, a square\n! spiral with side length 7 is formed.\n!\n! 37 36 35 34 33 32 31\n! 38 17 16 15 14 13 30\n! 39 18 5 4 3 12 29\n! 40 19 6 1 2 11 28\n! 41 20 7 8 9 10 27\n! 42 21 22 23 24 25 26\n! 43 44 45 46 47 48 49\n!\n! It is interesting to note that the odd squares lie along the bottom right\n! diagonal, but what is more interesting is that 8 out of the 13 numbers lying\n! along both diagonals are prime; that is, a ratio of 8/13 62%.\n!\n! If one complete new layer is wrapped around the spiral above, a square\n! spiral with side length 9 will be formed. If this process is continued, what\n! is the side length of the square spiral for which the ratio of primes along\n! both diagonals first falls below 10%?\n!\n! Project Euler: 58\n!\n! Answer: 26241!/\n\n\nprogram main\n\nuse euler\n\n implicit none\n\n integer (int32), parameter :: END_PERCENT = 10; \n integer (int32) :: s1, s2, s3, diag_total, count, n;\n\n n = 5;\n diag_total = 5;\n count = 3;\n\n do while(.TRUE.)\n\n s1 = (n * n) - (n - 1);\n s2 = (n * n) - 2 * (n - 1);\n s3 = (n * n) - 3 * (n - 1);\n\n call inc(count, intbool(isprime(s1)) + intbool(isprime(s2)) &\n + intbool(isprime(s3)));\n call inc(diag_total, 4);\n\n if((100 * count) / diag_total < END_PERCENT) then\n exit\n end if\n\n call inc(n, 2);\n\n\n end do\n\n call printint(n);\n\n\ncontains\n\n function intbool (bool)\n\n logical, intent(in) :: bool;\n integer (int32) :: intbool;\n\n intbool = MERGE(1, 0, bool);\n\n end function intbool\n\n\nend program main\n\n", "meta": {"hexsha": "efae138d8c11616407a9f9d3a6eb733820e11a9b", "size": 1794, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/spiral_primes.f95", "max_stars_repo_name": "guynan/project_euler", "max_stars_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-03-08T09:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T13:52:49.000Z", "max_issues_repo_path": "fortran/spiral_primes.f95", "max_issues_repo_name": "guynan/project_euler", "max_issues_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-11-03T01:20:46.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-24T22:54:59.000Z", "max_forks_repo_path": "fortran/spiral_primes.f95", "max_forks_repo_name": "guynan/project_euler", "max_forks_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-11-03T01:14:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T13:52:51.000Z", "avg_line_length": 23.6052631579, "max_line_length": 78, "alphanum_fraction": 0.5540691193, "num_tokens": 553, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362488, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7857914110423376}} {"text": "implicit none\r\n\r\nreal :: a, b, m, f\r\ninteger :: counter\r\n\r\na = 1.0\r\nb = 2.0\r\ncounter = 0\r\n\r\ndo while ((b - a) > 1.0e-11)\r\n m = (a + b) / 2.0\r\n if (f(a) * f(m) < 0.0) then\r\n b = m\r\n else\r\n a = m\r\n end if\r\n\r\n print*, 'Counter: ', counter\r\n print*, 'M: ', m\r\n print*, 'b - a: ', b-a\r\nend do\r\n\r\nstop\r\nend\r\n\r\nreal function f(x)\r\n implicit none\r\n real :: x\r\n\r\n f = x**5 - 5.0 * x**4 + 10 * x**2 + 5 * x - 1\r\n\r\n return\r\nend\r\n", "meta": {"hexsha": "8ff7c9f45fc9ab141f73962433f5a811cbeaecad", "size": 435, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "4670 Numerical Analysis/Class Examples/bb2.f90", "max_stars_repo_name": "mwebber3/UnderGraduateCourses", "max_stars_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4670 Numerical Analysis/Class Examples/bb2.f90", "max_issues_repo_name": "mwebber3/UnderGraduateCourses", "max_issues_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4670 Numerical Analysis/Class Examples/bb2.f90", "max_forks_repo_name": "mwebber3/UnderGraduateCourses", "max_forks_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 12.7941176471, "max_line_length": 48, "alphanum_fraction": 0.4436781609, "num_tokens": 188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7857859929552976}} {"text": "subroutine PreGLQ(x1, x2, n, zero, w)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis routine will find the zeros and weights that are\n!\tused in Gauss-Legendre quadrature routines. (Based on routines\n!\tin Numerical Recipes).\n!\n!\tCalling Parameters:\n!\t\tIN\n!\t\t\tx1: \tLower bound of integration.\n!\t\t\tx2:\tUpper bound of integration.\n!\t\t\tn:\tNumber of points used in the quadrature. n points\n!\t\t\t\twill integrate a polynomial of degree 2n-1 exactly.\n!\t\tOUT\n!\t\t\tzero:\tArray of n Gauss points, which correspond to the zeros\n!\t\t\t\tof P(n,0).\n!\t\t\tw:\tArray of n weights used in the quadrature.\n!\n!\n!\tNote \n!\t\t1.\tIf EPS is less than what is defined, then the do \n!\t\t\tloop for finding the roots might never terminate for some\n!\t\t\tvalues of lmax. If the algorithm doesn't converge, consider\n!\t\t\tincreasing itermax, or decreasing eps.\n!\n!\tDependencies:\tNone\n!\n!\tWritten by Mark Wieczorek 2003\n!\n!\tCopyright (c) 2005-2006, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\treal*8, intent(in) :: \tx1, x2\n\treal*8, intent(out) ::\tzero(:), w(:)\n\tinteger, intent(in) ::\tn\n\tinteger ::\t\ti, j, m, iter\n\tinteger, parameter ::\titermax = 1000\n\treal*8, parameter ::\teps=1.0d-15\n\treal*8 ::\t\tp1, p2, p3, pp, z, z1, xm, xu\n\t\n\t\n\tif (size(zero) < n) then\n\t\tprint*, \"Error --- PreGLQ\"\n\t\tprint*, \"ZERO must be dimensioned as (N) where N is \", n\n\t\tprint*, \"Input array is dimensioned \", size(zero)\n\t\tstop\n\telseif (size(w) < n) then\n\t\tprint*, \"Error --- PreGLQ\"\n\t\tprint*, \"W must be dimensioned as (N) where N is \", n\n\t\tprint*, \"Input array is dimensioned \", size(w)\n\t\tstop\n\tendif\n\t\n\t\n\tzero = 0.0d0\n\tw = 0.0d0\n\t\n\tm=(n+1)/2 \t\t! The roots are symmetric in the interval, so we\n\t\t\t\t! only have to find half of them. \n\txm = (x2 + x1) / 2.0d0\t! midpoint of integration\n\txu = (x2 - x1) / 2.0d0\t! Scaling factor between interval of integration, and that of \n\t\t\t\t! the -1 to 1 interval for the Gauss-Legendre interval\n\t\n\t! Compute roots and weights\n\t\t\t\t\n\tdo i=1,m \n\t\titer = 0\n\t\tz=cos(3.141592654d0*(i-.25d0)/(n+.5d0))\t! Approximation for the ith root\n\t\t\t\t\t\t\t\n\t\t! Find the true value using newtons method\n\t\t\n\t\tdo\n\t\t\n\t\t\titer = iter +1\n\t\t\t\n\t\t\tp1=1.0d0\n\t\t\tp2=0.0d0\n\t\t\tdo j=1, n \t! determine the legendre polynomial evaluated at z (p1) using \n\t\t\t\t\t! recurrence relationships\n\t\t\t\tp3=p2\n\t\t\t\tp2=p1\n\t\t\t\tp1=(dble(2*j-1)*z*p2-dble(j-1)*p3)/dble(j)\n\t\t\tenddo\n\t\t\n\t\t\tpp=dble(n)*(z*p1-p2)/(z*z-1.0d0)\t! This is the derivative of the legendre polynomial\n\t\t\t\t\t\t\t\t! using recurrence relationships\n\t\t\n\t\t\tz1=z\t\t\t\t\t! This is newtons method here\n\t\t\tz=z1-p1/pp \n\t\t\n\t\t\tif (abs(z-z1) <= eps) exit\n\t\t\t\n\t\t\tif (iter >itermax) then\n\t\t\t\tprint*, \"ERROR --- PreGLQ\"\n\t\t\t\tprint*, \"Root Finding of PreGLQ not converging.\"\n\t\t\t\tprint*, \"m , n = \", m, n\n\t\t\t\tstop\n\t\t\tendif\n\t\t\t\n\t\tenddo\n\t\t\n\t\tzero(i) = xm + xu*z\n\t\tzero(n+1-i) = xm - xu*z\n\t\tw(i)= 2.0d0 * xu / ((1.0d0-z*z)*pp*pp)\n\t\tw(n+1-i)=w(i) \n\t\t\n\tenddo\n\t\nend subroutine PreGLQ\n\n\ninteger function NGLQ(degree)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tFor a polynomial of order degree, this simple function\n!\twill determine how many gauss-legendre quadrature points\n!\tare needed in order to integrate the function exactly.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\tinteger, intent(in) ::\tdegree\n\t\n\tnglq = ceiling((degree+1.0d0)/2.0d0) \t\n\t\nend function NGLQ\n\n\ninteger function NGLQSH(degree)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function returns the number of gauss-legendre points that\n!\tare needed to exactly integrate a spherical harmonic field of \n!\tLmax = degree\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\tinteger, intent(in) ::\tdegree\n\t\n\tnglqsh = degree + 1.0d0\n\nend function NGLQSH\n\n\ninteger function NGLQSHN(degree, n)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function returns the number of gauss-legendre points that\n!\tare needed to exactly integrate a spherical harmonic field of \n!\tLmax = degree raised to the nth power. Here, the maximum degree\n!\tof the integrand is n*lmax + lmax, or (n+1)*lmax\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\tinteger, intent(in) ::\tdegree, n\n\t\n\tnglqshn = ceiling( ((n+1.0d0)*degree + 1.0d0)/2.0d0)\n\nend function NGLQSHN\n\n", "meta": {"hexsha": "27bf5ef93472507a57594cf3139e50ef2646dba9", "size": 4390, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/PreGLQ.f95", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "spherical_splines/SHTOOLS/src/PreGLQ.f95", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "spherical_splines/SHTOOLS/src/PreGLQ.f95", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 27.0987654321, "max_line_length": 87, "alphanum_fraction": 0.5740318907, "num_tokens": 1384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921841290738, "lm_q2_score": 0.8519528019683106, "lm_q1q2_score": 0.7854338958834284}} {"text": "submodule(stdlib_math) stdlib_math_arange\n\ncontains\n\n !> `arange` creates a vector of the `real(sp)` type \n !> with evenly spaced values within a given interval.\n pure module function arange_r_sp(start, end, step) result(result)\n\n real(sp), intent(in) :: start\n real(sp), intent(in), optional :: end, step\n real(sp), allocatable :: result(:)\n \n real(sp) :: start_, end_, step_\n integer :: i\n\n start_ = merge(start, 1.0_sp, present(end))\n end_ = optval(end, start)\n step_ = optval(step, 1.0_sp)\n step_ = sign(merge(step_, 1.0_sp, step_ /= 0.0_sp), end_ - start_)\n\n allocate(result(floor((end_ - start_)/step_) + 1))\n\n result = [(start_ + (i - 1)*step_, i=1, size(result), 1)]\n\n end function arange_r_sp\n !> `arange` creates a vector of the `real(dp)` type \n !> with evenly spaced values within a given interval.\n pure module function arange_r_dp(start, end, step) result(result)\n\n real(dp), intent(in) :: start\n real(dp), intent(in), optional :: end, step\n real(dp), allocatable :: result(:)\n \n real(dp) :: start_, end_, step_\n integer :: i\n\n start_ = merge(start, 1.0_dp, present(end))\n end_ = optval(end, start)\n step_ = optval(step, 1.0_dp)\n step_ = sign(merge(step_, 1.0_dp, step_ /= 0.0_dp), end_ - start_)\n\n allocate(result(floor((end_ - start_)/step_) + 1))\n\n result = [(start_ + (i - 1)*step_, i=1, size(result), 1)]\n\n end function arange_r_dp\n !> `arange` creates a vector of the `real(qp)` type \n !> with evenly spaced values within a given interval.\n pure module function arange_r_qp(start, end, step) result(result)\n\n real(qp), intent(in) :: start\n real(qp), intent(in), optional :: end, step\n real(qp), allocatable :: result(:)\n \n real(qp) :: start_, end_, step_\n integer :: i\n\n start_ = merge(start, 1.0_qp, present(end))\n end_ = optval(end, start)\n step_ = optval(step, 1.0_qp)\n step_ = sign(merge(step_, 1.0_qp, step_ /= 0.0_qp), end_ - start_)\n\n allocate(result(floor((end_ - start_)/step_) + 1))\n\n result = [(start_ + (i - 1)*step_, i=1, size(result), 1)]\n\n end function arange_r_qp\n\n !> `arange` creates a vector of the `integer(int8)` type \n !> with evenly spaced values within a given interval.\n pure module function arange_i_int8(start, end, step) result(result)\n\n integer(int8), intent(in) :: start\n integer(int8), intent(in), optional :: end, step\n integer(int8), allocatable :: result(:)\n \n integer(int8) :: start_, end_, step_\n integer(int8) :: i\n\n start_ = merge(start, 1_int8, present(end))\n end_ = optval(end, start)\n step_ = optval(step, 1_int8)\n step_ = sign(merge(step_, 1_int8, step_ /= 0_int8), end_ - start_)\n\n allocate(result((end_ - start_)/step_ + 1))\n\n result = [(i, i=start_, end_, step_)]\n\n end function arange_i_int8\n !> `arange` creates a vector of the `integer(int16)` type \n !> with evenly spaced values within a given interval.\n pure module function arange_i_int16(start, end, step) result(result)\n\n integer(int16), intent(in) :: start\n integer(int16), intent(in), optional :: end, step\n integer(int16), allocatable :: result(:)\n \n integer(int16) :: start_, end_, step_\n integer(int16) :: i\n\n start_ = merge(start, 1_int16, present(end))\n end_ = optval(end, start)\n step_ = optval(step, 1_int16)\n step_ = sign(merge(step_, 1_int16, step_ /= 0_int16), end_ - start_)\n\n allocate(result((end_ - start_)/step_ + 1))\n\n result = [(i, i=start_, end_, step_)]\n\n end function arange_i_int16\n !> `arange` creates a vector of the `integer(int32)` type \n !> with evenly spaced values within a given interval.\n pure module function arange_i_int32(start, end, step) result(result)\n\n integer(int32), intent(in) :: start\n integer(int32), intent(in), optional :: end, step\n integer(int32), allocatable :: result(:)\n \n integer(int32) :: start_, end_, step_\n integer(int32) :: i\n\n start_ = merge(start, 1_int32, present(end))\n end_ = optval(end, start)\n step_ = optval(step, 1_int32)\n step_ = sign(merge(step_, 1_int32, step_ /= 0_int32), end_ - start_)\n\n allocate(result((end_ - start_)/step_ + 1))\n\n result = [(i, i=start_, end_, step_)]\n\n end function arange_i_int32\n !> `arange` creates a vector of the `integer(int64)` type \n !> with evenly spaced values within a given interval.\n pure module function arange_i_int64(start, end, step) result(result)\n\n integer(int64), intent(in) :: start\n integer(int64), intent(in), optional :: end, step\n integer(int64), allocatable :: result(:)\n \n integer(int64) :: start_, end_, step_\n integer(int64) :: i\n\n start_ = merge(start, 1_int64, present(end))\n end_ = optval(end, start)\n step_ = optval(step, 1_int64)\n step_ = sign(merge(step_, 1_int64, step_ /= 0_int64), end_ - start_)\n\n allocate(result((end_ - start_)/step_ + 1))\n\n result = [(i, i=start_, end_, step_)]\n\n end function arange_i_int64\n\nend submodule stdlib_math_arange\n", "meta": {"hexsha": "d91b0e20e330ae47ecb054664b1e2125b73dbd1d", "size": 5406, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stdlib_math_arange.f90", "max_stars_repo_name": "LKedward/stdlib-fpm", "max_stars_repo_head_hexsha": "312e798a2777d571efcf7e5f96f81a7297590685", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-05-05T10:52:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-26T02:40:56.000Z", "max_issues_repo_path": "src/stdlib_math_arange.f90", "max_issues_repo_name": "LKedward/stdlib-fpm", "max_issues_repo_head_hexsha": "312e798a2777d571efcf7e5f96f81a7297590685", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-03-20T12:36:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-17T07:56:11.000Z", "max_forks_repo_path": "src/stdlib_math_arange.f90", "max_forks_repo_name": "LKedward/stdlib-fpm", "max_forks_repo_head_hexsha": "312e798a2777d571efcf7e5f96f81a7297590685", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.8774193548, "max_line_length": 77, "alphanum_fraction": 0.5971143174, "num_tokens": 1550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218412907381, "lm_q2_score": 0.8519527963298946, "lm_q1q2_score": 0.7854338906852496}} {"text": " PROGRAM circle\n\n IMPLICIT NONE\n\n REAL x0, y0, z0, r0, PI, PHI, DelPHI\n REAL x, y, z\n INTEGER i,N\n\n PI=2.0*asin(1.0)\n\n write(*,*) PI \n\n write(*,*) 'Input center: '\n read(*,*) x0, y0, z0\n\n\n write(*,*) 'Input radius: '\n read(*,*) r0 \n\n write(*,*) 'Input number of segments: '\n read(*,*) N\n\n DelPHI = 2.0*PI/(real(N))\n \n do i=0,N-1\n PHI = DelPHI * i\n x = x0 + r0 * cos(PHI)\n z = z0 + r0 * sin(PHI)\n y = y0\n write(*,'(I5,3F12.6)') i+1, x, y, z\n end do\n\n END \n\n\n\n \n", "meta": {"hexsha": "6a1c21aff0769ddded41ac1b39664326a2f4d023", "size": 586, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Generate/Library_cases/circle.f", "max_stars_repo_name": "palkinev/T-FlowS-old-compressible", "max_stars_repo_head_hexsha": "7aa7219aa5526ac270b39d52ba8c12847e1d71a2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Generate/Library_cases/circle.f", "max_issues_repo_name": "palkinev/T-FlowS-old-compressible", "max_issues_repo_head_hexsha": "7aa7219aa5526ac270b39d52ba8c12847e1d71a2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Generate/Library_cases/circle.f", "max_forks_repo_name": "palkinev/T-FlowS-old-compressible", "max_forks_repo_head_hexsha": "7aa7219aa5526ac270b39d52ba8c12847e1d71a2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.4210526316, "max_line_length": 45, "alphanum_fraction": 0.4112627986, "num_tokens": 225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065458, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.7854257769927273}} {"text": "! Name: Arpit Kumar Jain, Roll No. 180122009\nPROGRAM PIB1D_Amonnia\n IMPLICIT NONE\n\n REAL, PARAMETER :: PI = acos(-1.0)\n REAL, ALLOCATABLE:: potential(:), x(:)\n DOUBLE PRECISION, ALLOCATABLE:: hmat(:,:), eigenVal(:), work(:)\n DOUBLE PRECISION:: EnergyDiff\n REAL:: xmax, xmin, dx, hbar, tconst, b, k, x0, c, mu\n INTEGER:: nx, lwork, i, ifail\n\n WRITE(*, fmt = '(/A)', ADVANCE = 'NO') \"Enter the number of grid points: \"\n READ(*, *) nx\n \n xmax = 10.0\n xmin = 0.0\n dx = (xmax - xmin)/(nx - 1)\n \n ALLOCATE(potential(nx), hmat(nx,nx), eigenVal(nx), x(nx), work(64*nx))\n DO i = 1, nx\n x(i) = xmin + (i-1)*dx\n ENDDO\n\n mu = 4668\n hbar = 1.00\n k = 0.08\n x0 = 5.00\n b = 0.06\n c = 1.37\n\n tconst = (hbar**2) / (2.0 * mu * dx**2)\n DO i = 1, nx\n potential(i) = 0.5 * k * (x(i)-x0)**2 + b * EXP(-c * (x(i)-x0)**2 ) \n ENDDO\n \n hmat = 0.0\n DO i = 1, nx-1\n hmat(i, i) = potential(i) + 2.0 * tconst\n hmat(i, i+1) = -tconst\n hmat(i+1, i) = -tconst\n ENDDO\n hmat(nx, nx) = potential(nx) + 2.0 * tconst\n \n lwork = 64*nx\n CALL dsyev('V', 'U', nx, hmat, nx, eigenVal, work, lwork, ifail)\n\n OPEN(UNIT = 20, FILE = 'potential.txt')\n DO i = 1, nx \n WRITE(20, 10) x(i), potential(i)\n 10 FORMAT(f0.6, 3x, f0.6)\n ENDDO\n CLOSE(20)\n\n OPEN(UNIT = 20, FILE = 'eigenstate.txt')\n DO i = 1, nx \n WRITE(20, 11) x(i), hmat(i, 1)/sqrt(dx), eigenVal(i)\n 11 FORMAT(f0.6, 3x, f0.6, 3x, f0.8)\n ENDDO\n CLOSE(20)\n\n EnergyDiff = 6579689.75 * (eigenVal(2) - eigenVal(1))\n WRITE(*, *) \"The difference between the second lowest and lowest is: \", EnergyDiff, \"GHz\"\n\nEND PROGRAM PIB1D_Amonnia\n", "meta": {"hexsha": "b719e361928313540e00c22cd321918a1ea6a5cd", "size": 1763, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Finite-difference application/Ammonia_Arpit.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Particle In a Box (PIB)/2_Ammonia_Arpit.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Particle In a Box (PIB)/2_Ammonia_Arpit.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 27.1230769231, "max_line_length": 93, "alphanum_fraction": 0.5155984118, "num_tokens": 707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067195846918, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7854140248246785}} {"text": "program prog1\n\nimplicit none\n\nreal, dimension(1:300) :: x, t, v\nreal :: xo, vo, a, cont\ninteger :: c\n\nxo = 0\nvo = 2\na = 10\n\ncont = 0\ndo c = 1,300\n cont = cont + 0.01\n t(c) = cont\n x(c) = xo + vo*t(c)**2 + (1d0/3d0)*a*t(c)**4\nend do\n\ncall derivada(x, t, v)\n\ndo c = 1,299\n write(*,*) t(c), x(c), v(c)\nend do\n\nopen(1,FILE = \"dados.txt\")\n\ndo c = 1,300\n write(1,*) t(c), x(c)\nend do\n\nclose (1)\n\nopen(2,FILE = \"dados2.txt\")\n\ndo c = 1,299\n write(2,*) t(c), v(c)\nend do\n\nclose(2)\n\nend program prog1\n\nsubroutine derivada(x, t, v)\n\nreal, dimension (1:300) :: x, t, v, dx, dt\ninteger :: c\n\ndo c = 1,299\n dx(c) = x(c + 1) - x(c)\n dt(c) = t(c + 1) - t(c)\n v(c) = dx(c)/dt(c)\nend do\n\nreturn\nend subroutine derivada", "meta": {"hexsha": "9adc667d641bdfd54166b5b5788933a51598640e", "size": 729, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "aula06/prog1.f90", "max_stars_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_stars_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aula06/prog1.f90", "max_issues_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_issues_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aula06/prog1.f90", "max_forks_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_forks_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.0178571429, "max_line_length": 48, "alphanum_fraction": 0.5308641975, "num_tokens": 319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7853803948003557}} {"text": "program linear_regression\n\n implicit none\n real :: x(10), y(10), b(2)\n\n interface\n subroutine estimate_coef(x, y, b)\n real, intent(in) :: x(:), y(:)\n real, intent(out) :: b(2)\n real :: m_x, m_y\n integer :: n\n end subroutine estimate_coef\n end interface\n\n x = (/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 /)\n y = (/ 1, 3, 2, 5, 7, 8, 8, 9, 10, 12 /)\n\n call estimate_coef(x, y, b)\n\n print *, \" Estimated coefficients in Fortran: \"\n print *, \"b(1) = \", b(1)\n print *, \"b(2) = \", b(2)\n\n stop\n \nend program linear_regression\n\nsubroutine estimate_coef(x, y, b)\n\n real, intent(in) :: x(:), y(:)\n real, intent(out) :: b(2)\n real :: m_x, m_y\n integer :: n\n\n ! number of observations/points\n n = size(x)\n\n ! mean of x and y vector\n m_x = sum(x)/n \n m_y = sum(y)/n\n\n ! calculating cross-deviation and deviation about x\n SS_xy = sum(y*x) - n*m_y*m_x\n SS_xx = sum(x*x) - n*m_x*m_x \n \n ! calculating regression coefficients \n b(2) = SS_xy / SS_xx \n b(1) = m_y - b(2)*m_x \n\n return\n \nend subroutine estimate_coef\n", "meta": {"hexsha": "7cac600fd6645db9b5a8057d9176de4d8b4720fb", "size": 1047, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code/linear_regression.f90", "max_stars_repo_name": "carlosal1015/pybr2019", "max_stars_repo_head_hexsha": "fa61c3e33b0acdb8ea88449590b137a4c7d908fb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-10-26T18:06:31.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-06T02:39:26.000Z", "max_issues_repo_path": "code/linear_regression.f90", "max_issues_repo_name": "carlosal1015/pybr2019", "max_issues_repo_head_hexsha": "fa61c3e33b0acdb8ea88449590b137a4c7d908fb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "code/linear_regression.f90", "max_forks_repo_name": "carlosal1015/pybr2019", "max_forks_repo_head_hexsha": "fa61c3e33b0acdb8ea88449590b137a4c7d908fb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-06T02:39:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-06T02:39:30.000Z", "avg_line_length": 19.7547169811, "max_line_length": 53, "alphanum_fraction": 0.5711556829, "num_tokens": 383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741268224333, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7853611037250742}} {"text": "\nmodule quadrature_omp\n\n ! Sample solution for Homework 4.\n\n use omp_lib\n\ncontains\n\nreal(kind=8) function trapezoid(f, a, b, n)\n\n ! Estimate the integral of f(x) from a to b using the\n ! Trapezoid Rule with n points.\n\n ! Input:\n ! f: the function to integrate\n ! a: left endpoint\n ! b: right endpoint\n ! n: number of points to use\n ! Returns:\n ! the estimate of the integral\n \n implicit none\n real(kind=8), intent(in) :: a,b\n real(kind=8), external :: f\n integer, intent(in) :: n\n\n ! Local variables:\n integer :: j\n real(kind=8) :: h, trap_sum, xj\n\n h = (b-a)/(n-1)\n trap_sum = 0.5d0*(f(a) + f(b)) ! endpoint contributions\n \n !$omp parallel do private(xj) reduction(+ : trap_sum) \n do j=2,n-1\n xj = a + (j-1)*h\n trap_sum = trap_sum + f(xj)\n enddo\n\n trapezoid = h * trap_sum\n\nend function trapezoid\n\nsubroutine error_table(f,a,b,nvals,int_true)\n implicit none\n real(kind=8), intent(in) :: a,b, int_true\n real(kind=8), external :: f\n integer, dimension(:), intent(in) :: nvals\n\n ! Local variables:\n integer :: j, n\n real(kind=8) :: sum, ratio, last_error, error, int_trap\n\n print *, \" n trapezoid error ratio\"\n last_error = 0.d0 \n do j=1,size(nvals)\n n = nvals(j)\n int_trap = trapezoid(f,a,b,n)\n error = abs(int_trap - int_true)\n ratio = last_error / error\n last_error = error ! for next n\n\n print 11, n, int_trap, error, ratio\n 11 format(i8, es22.14, es13.3, es13.3)\n enddo\n\nend subroutine error_table\n\n\nend module quadrature_omp\n\n", "meta": {"hexsha": "868c466e52ef099e53edb225b782bc12b759519f", "size": 1656, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/2013/solutions/homework4/quadrature_omp.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/2013/solutions/homework4/quadrature_omp.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/2013/solutions/homework4/quadrature_omp.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.6849315068, "max_line_length": 69, "alphanum_fraction": 0.5803140097, "num_tokens": 512, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331752, "lm_q2_score": 0.8791467754256017, "lm_q1q2_score": 0.7853500762986779}} {"text": "!> @file pybasefn.f90\n!> @brief Fortran module that computes the radial basis functions\n!> @author Zhisong Qu (zhisong.qu@anu.edu.au)\n\n!> Fortran module that computes the radial basis functions, adapted basefn.f90 in SPEC main code\nMODULE SPECbasefn\n\nCONTAINS\n\n!> Get the Chebyshev polynomials with zeroth, first derivatives\n SUBROUTINE get_cheby(lss, lrad, cheby)\n!f2py threadsafe\n\n USE SPECconstants, ONLY : zero, one, two\n USE SPECtypedefns, ONLY : REAL_KIND\n\n IMPLICIT NONE\n\n REAL(KIND=REAL_KIND),INTENT(IN) :: lss !< coordinate input lss\n INTEGER, INTENT(IN) :: lrad !< radial resolution\n REAL(KIND=REAL_KIND), INTENT(OUT) :: cheby(0:lrad,0:1) !< the value, first derivative of Chebyshev polynomial\n\n integer :: ll\n\n cheby = zero\n\n ; cheby( 0,0:1) = (/one ,zero /)\n ; cheby( 1,0:1) = (/lss ,one /)\n DO ll = 2, lrad ; cheby(ll,0:1) = (/two * lss * cheby(ll-1,0) - cheby(ll-2,0),two * cheby(ll-1,0) + two * lss * cheby(ll-1,1) - cheby(ll-2,1)/)\n ENDDO\n\n ! basis recombination\n DO ll = 1, lrad\n cheby(ll, 0) = cheby(ll, 0) - (-1)**ll\n ENDDO\n\n DO ll = 0, lrad\n cheby(ll, 0:1) = cheby(ll, 0:1) / FLOAT(ll+1) ! scale for better conditioning\n ENDDO\n\n return\n END SUBROUTINE get_cheby\n\n!> Get the Chebyshev polynomials with zeroth, first and second derivatives\n SUBROUTINE get_cheby_d2(lss, lrad, cheby)\n!f2py threadsafe\n\n USE SPECconstants, ONLY : zero, one, two\n USE SPECtypedefns, ONLY : REAL_KIND\n\n IMPLICIT NONE\n\n REAL(KIND=REAL_KIND),INTENT(IN) :: lss !< coordinate input lss\n INTEGER, INTENT(IN) :: lrad !< radial resolution\n REAL(KIND=REAL_KIND), INTENT(OUT) :: cheby(0:lrad,0:2) !< the value, first and second derivative of Chebyshev polynomial\n\n integer :: ll\n\n cheby = zero\n\n ; ; cheby( 0,0:2) = (/ one, zero, zero /) ! T_0: Chebyshev initialization; function, 1st-derivative, 2nd-derivative;\n ; ; cheby( 1,0:2) = (/ lss, one, zero /) ! T_1: Chebyshev initialization; function, 1st-derivative, 2nd-derivative;\n DO ll = 2, lrad \n cheby(ll,0:2) = (/ two * lss * cheby(ll-1,0) - cheby(ll-2,0) , &\n two * cheby(ll-1,0) + two * lss * cheby(ll-1,1) - cheby(ll-2,1) , &\n two * cheby(ll-1,1) + two * cheby(ll-1,1) + two * lss * cheby(ll-1,2) - cheby(ll-2,2) /)\n ENDDO \n\n DO ll = 1, lrad\n cheby(ll, 0) = cheby(ll, 0) - (-1)**ll\n ENDDO\n\n DO ll = 0, lrad\n cheby(ll, 0:2) = cheby(ll, 0:2) / FLOAT(ll+1) ! scale for better conditioning\n ENDDO\n\n return\n END SUBROUTINE get_cheby_d2\n\n!> Get the Zernike polynomials with zeroth, first derivatives\n SUBROUTINE get_zernike(r, lrad, mpol, zernike)\n!f2py threadsafe\n\n USE SPECconstants, ONLY : zero, one, two\n USE SPECtypedefns, ONLY : REAL_KIND\n\n IMPLICIT NONE\n\n REAL(KIND=REAL_KIND),INTENT(IN) :: r !< coordinate input r\n INTEGER, INTENT(IN) :: lrad !< radial resolution\n INTEGER, INTENT(IN) :: mpol !< poloidal resolution\n REAL(KIND=REAL_KIND), INTENT(OUT) :: zernike(0:lrad,0:mpol,0:1) !< the value, first derivative of Zernike polynomial\n\n REAL(KIND=REAL_KIND) :: rm, rm1 ! r to the power of m'th and m-1'th\n REAL(KIND=REAL_KIND) :: factor1, factor2, factor3, factor4\n INTEGER :: m, n ! Zernike R^m_n\n \n rm = one ! r to the power of m'th\n rm1 = zero ! r to the power of m-1'th\n zernike(:,:,:) = zero\n DO m = 0, mpol\n IF (lrad >= m) then\n zernike(m,m,0:1) = (/ rm, FLOAT(m)*rm1 /)\n ENDIF\n\n IF (lrad >= m+2) then\n zernike(m+2,m,0) = FLOAT(m+2)*rm*r**2 - FLOAT(m+1)*rm\n zernike(m+2,m,1) = FLOAT((m+2)**2)*rm*r - FLOAT((m+1)*m)*rm1\n ENDIF\n\n DO n = m+4, lrad, 2\n factor1 = FLOAT(n)/FLOAT(n**2 - m**2)\n factor2 = FLOAT(4 * (n-1))\n factor3 = FLOAT((n-2+m)**2)/FLOAT(n-2) + FLOAT((n-m)**2)/FLOAT(n)\n factor4 = FLOAT((n-2)**2-m**2) / FLOAT(n-2)\n\n zernike(n, m, 0) = factor1 * ((factor2*r**2 - factor3)*zernike(n-2,m,0) - factor4*zernike(n-4,m,0))\n zernike(n, m, 1) = factor1 * (two*factor2*r*zernike(n-2,m,0) + (factor2*r**2 - factor3)*zernike(n-2,m,1) - factor4*zernike(n-4,m,1))\n ENDDO\n\n rm1 = rm\n rm = rm * r\n\n ENDDO\n\n DO n = 2, lrad, 2\n zernike(n,0,0) = zernike(n,0,0) - (-1)**(n/2)\n ENDDO\n\n IF (mpol >= 1) then\n DO n = 3, lrad, 2\n zernike(n,1,0) = zernike(n,1,0) - (-1)**((n-1)/2) * FLOAT((n+1)/2) * r\n zernike(n,1,1) = zernike(n,1,1) - (-1)**((n-1)/2) * FLOAT((n+1)/2)\n ENDDO\n END if\n\n DO m = 0, mpol\n DO n = m, lrad, 2\n zernike(n,m,:) = zernike(n,m,:) / FLOAT(n+1)\n END do\n END do\n END SUBROUTINE get_zernike\n\n!> Get the Zernike polynomials with zeroth, first, second derivatives\n SUBROUTINE get_zernike_d2(r, lrad, mpol, zernike)\n!f2py threadsafe\n\n USE SPECconstants, ONLY : zero, one, two\n USE SPECtypedefns, ONLY : REAL_KIND\n\n IMPLICIT NONE\n\n REAL(KIND=REAL_KIND),INTENT(IN) :: r !< coordinate input r\n INTEGER, INTENT(IN) :: lrad !< radial resolution\n INTEGER, INTENT(IN) :: mpol !< poloidal resolution\n REAL(KIND=REAL_KIND), INTENT(OUT) :: zernike(0:lrad,0:mpol,0:2) !< the value, first/second derivative of Zernike polynomial\n\n REAL(KIND=REAL_KIND) :: rm, rm1, rm2 ! r to the power of m'th, m-1'th and m-2'th\n REAL(KIND=REAL_KIND) :: factor1, factor2, factor3, factor4\n INTEGER :: m, n ! Zernike R^m_n\n \n rm = one ! r to the power of m'th\n rm1 = zero ! r to the power of m-1'th\n rm2 = zero ! r to the power of m-2'th\n zernike(:,:,:) = zero\n DO m = 0, mpol\n IF (lrad >= m) then\n zernike(m,m,0:2) = (/ rm, FLOAT(m)*rm1, FLOAT(m*(m-1))*rm2 /)\n !write(0, *) m, m, r, zernike(m,m,:)\n ENDIF\n\n IF (lrad >= m+2) then\n zernike(m+2,m,0) = FLOAT(m+2)*rm*r**2 - FLOAT(m+1)*rm\n zernike(m+2,m,1) = FLOAT((m+2)**2)*rm*r - FLOAT((m+1)*m)*rm1 \n zernike(m+2,m,2) = FLOAT((m+2)**2*(m+1))*rm - FLOAT((m+1)*m*(m-1))*rm2 \n !write(0, *) m+2, m, r, zernike(m+2,m,:)\n ENDIF\n\n DO n = m+4, lrad, 2\n factor1 = FLOAT(n)/FLOAT(n**2 - m**2)\n factor2 = FLOAT(4 * (n-1))\n factor3 = FLOAT((n-2+m)**2)/FLOAT(n-2) + FLOAT((n-m)**2)/FLOAT(n)\n factor4 = FLOAT((n-2)**2-m**2) / FLOAT(n-2)\n\n zernike(n, m, 0) = factor1 * ((factor2*r**2 - factor3)*zernike(n-2,m,0) - factor4*zernike(n-4,m,0))\n zernike(n, m, 1) = factor1 * (two*factor2*r*zernike(n-2,m,0) + (factor2*r**2 - factor3)*zernike(n-2,m,1) - factor4*zernike(n-4,m,1))\n zernike(n, m, 2) = factor1 * (two*factor2*(two*r*zernike(n-2,m,1) + zernike(n-2,m,0)) &\n +(factor2*r**2 - factor3)*zernike(n-2,m,2) - factor4*zernike(n-4,m,2))\n !write(0, *) n, m, r, zernike(n,m,:)\n ENDDO\n\n rm2 = rm1\n rm1 = rm\n rm = rm * r\n\n ENDDO\n DO n = 2, lrad, 2\n zernike(n,0,0) = zernike(n,0,0) - (-1)**(n/2)\n ENDDO\n IF (mpol >= 1) then\n DO n = 3, lrad, 2\n zernike(n,1,0) = zernike(n,1,0) - (-1)**((n-1)/2) * FLOAT((n+1)/2) * r\n zernike(n,1,1) = zernike(n,1,1) - (-1)**((n-1)/2) * FLOAT((n+1)/2)\n ENDDO\n END if\n\n DO m = 0, mpol\n DO n = m, lrad, 2\n zernike(n,m,:) = zernike(n,m,:) / FLOAT(n+1)\n END do\n END do\n END SUBROUTINE get_zernike_d2\n\n!> Get the Zernike polynomials Z(n,m,r)/r^m\n SUBROUTINE get_zernike_rm(r, lrad, mpol, zernike)\n!f2py threadsafe\n\n USE SPECconstants, ONLY : zero, one, two\n USE SPECtypedefns, ONLY : REAL_KIND\n\n IMPLICIT NONE\n\n REAL(KIND=REAL_KIND),INTENT(IN) :: r !< coordinate input r\n INTEGER, INTENT(IN) :: lrad !< radial resolution\n INTEGER, INTENT(IN) :: mpol !< poloidal resolution\n REAL(KIND=REAL_KIND), INTENT(OUT) :: zernike(0:lrad,0:mpol) !< the value\n\n REAL(KIND=REAL_KIND) :: factor1, factor2, factor3, factor4\n INTEGER :: m, n ! Zernike R^m_n\n\n zernike(:,:) = zero\n DO m = 0, mpol\n IF (lrad >= m) then\n zernike(m,m) = one\n ENDIF\n\n IF (lrad >= m+2) then\n zernike(m+2,m) = FLOAT(m+2)*r**2 - FLOAT(m+1)\n ENDIF\n\n DO n = m+4, lrad, 2\n factor1 = FLOAT(n)/FLOAT(n**2 - m**2)\n factor2 = FLOAT(4 * (n-1))\n factor3 = FLOAT((n-2+m)**2)/FLOAT(n-2) + FLOAT((n-m)**2)/FLOAT(n)\n factor4 = FLOAT((n-2)**2-m**2) / FLOAT(n-2)\n\n zernike(n, m) = factor1 * ((factor2*r**2 - factor3)*zernike(n-2,m) - factor4*zernike(n-4,m))\n ENDDO\n\n ENDDO\n DO n = 2, lrad, 2\n zernike(n,0) = zernike(n,0) - (-1)**(n/2)\n ENDDO\n IF (mpol >= 1) then\n DO n = 3, lrad, 2\n zernike(n,1) = zernike(n,1) - (-1)**((n-1)/2) * FLOAT((n+1)/2)\n ENDDO\n END if\n\n DO m = 0, mpol\n DO n = m, lrad, 2\n zernike(n,m) = zernike(n,m) / FLOAT(n+1)\n END do\n END do\n END SUBROUTINE get_zernike_rm\n\nEND MODULE SPECbasefn", "meta": {"hexsha": "2d576612a082e4739ef5f2b4f18c39102574862b", "size": 9211, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pyoculus/problems/SPECfortran/pybasefn.f90", "max_stars_repo_name": "mbkumar/pyoculus", "max_stars_repo_head_hexsha": "8c925b139e27fd016b37aa4fe4653276af67e0a5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-09-24T12:14:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-09T12:12:51.000Z", "max_issues_repo_path": "pyoculus/problems/SPECfortran/pybasefn.f90", "max_issues_repo_name": "mbkumar/pyoculus", "max_issues_repo_head_hexsha": "8c925b139e27fd016b37aa4fe4653276af67e0a5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-04T16:46:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:46:25.000Z", "max_forks_repo_path": "pyoculus/problems/SPECfortran/pybasefn.f90", "max_forks_repo_name": "mbkumar/pyoculus", "max_forks_repo_head_hexsha": "8c925b139e27fd016b37aa4fe4653276af67e0a5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-07-24T16:09:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-04T15:56:07.000Z", "avg_line_length": 34.4981273408, "max_line_length": 149, "alphanum_fraction": 0.542069265, "num_tokens": 3507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810496235896, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7853209142976878}} {"text": "! From: \"James Van Buskirk\" \r\n! Newsgroups: comp.lang.fortran\r\n! Subject: Re: ? Strassen algorithm for multiplying matrix\r\n! Date: Thu, 14 Sep 2000 06:27:20 -0600\r\n\r\n! Latest revision - 16 September 2000\r\n\r\nmodule mykinds\r\n implicit none\r\n integer, parameter :: wp = selected_real_kind(12, 60)\r\n integer :: threshold\r\nend module mykinds\r\n\r\n\r\n\r\nmodule matrix_multiply\r\n use mykinds\r\n implicit none\r\n\r\ncontains\r\n\r\nrecursive subroutine strassen(a, b, c, N)\r\n integer, intent(in) :: N\r\n real(wp), intent(in) :: a(N,N), b(N,N)\r\n real(wp), intent(out) :: c(N,N)\r\n\r\n real(wp), dimension(N/2,N/2) :: a11,a21,a12,a22,b11,b21,b12,b22\r\n real(wp), dimension(N/2,N/2) :: q1,q2,q3,q4,q5,q6,q7\r\n\r\n if(iand(N,1) /= 0 .OR. N < threshold) then\r\n c = matmul(a,b)\r\n else\r\n a11 = a(:N/2,:N/2)\r\n a21 = a(N/2+1:,:N/2)\r\n a12 = a(:N/2,N/2+1:)\r\n a22 = a(N/2+1:,N/2+1:)\r\n b11 = b(:N/2,:N/2)\r\n b21 = b(N/2+1:,:N/2)\r\n b12 = b(:N/2,N/2+1:)\r\n b22 = b(N/2+1:,N/2+1:)\r\n call strassen(a11+a22, b11+b22, q1, N/2)\r\n call strassen(a21+a22, b11, q2, N/2)\r\n call strassen(a11, b12-b22, q3, N/2)\r\n call strassen(a22, -b11+b21, q4, N/2)\r\n call strassen(a11+a12, b22, q5, N/2)\r\n call strassen(-a11+a21, b11+b12, q6, N/2)\r\n call strassen(a12-a22, b21+b22, q7, N/2)\r\n c(:N/2,:N/2) = q1+q4-q5+q7\r\n c(N/2+1:,:N/2) = q2+q4\r\n c(:N/2,N/2+1:) = q3+q5\r\n c(N/2+1:,N/2+1:) = q1+q3-q2+q6\r\n end if\r\n\r\n return\r\nend subroutine strassen\r\n\r\n\r\nrecursive subroutine simple(a, b, c, N)\r\n use mykinds\r\n implicit none\r\n integer, intent(in) :: N\r\n real(wp), intent(in) :: a(N,N), b(N,N)\r\n real(wp), intent(out) :: c(N,N)\r\n real(wp), dimension(N/2,N/2) :: a11,a21,a12,a22,b11,b21,b12,b22,q1,q2\r\n\r\n if(iand(N,1) /= 0 .OR. N < threshold) then\r\n c = matmul(a,b)\r\n else\r\n a11 = a(:N/2,:N/2)\r\n a21 = a(N/2+1:,:N/2)\r\n a12 = a(:N/2,N/2+1:)\r\n a22 = a(N/2+1:,N/2+1:)\r\n b11 = b(:N/2,:N/2)\r\n b21 = b(N/2+1:,:N/2)\r\n b12 = b(:N/2,N/2+1:)\r\n b22 = b(N/2+1:,N/2+1:)\r\n call simple(a11, b11, q1, N/2)\r\n call simple(a12, b21, q2, N/2)\r\n c(:N/2,:N/2) = q1+q2\r\n call simple(a21, b11, q1, N/2)\r\n call simple(a22, b21, q2, N/2)\r\n c(N/2+1:,:N/2) = q1+q2\r\n call simple(a11, b12, q1, N/2)\r\n call simple(a12, b22, q2, N/2)\r\n c(:N/2,N/2+1:) = q1+q2\r\n call simple(a21, b12, q1, N/2)\r\n call simple(a22, b22, q2, N/2)\r\n c(N/2+1:,N/2+1:) = q1+q2\r\n end if\r\n\r\n return\r\nend subroutine simple\r\n\r\nend module matrix_multiply\r\n\r\n\r\nprogram strassen_test\r\n use mykinds\r\n use matrix_multiply\r\n implicit none\r\n real(wp), allocatable :: a(:,:), b(:,:), c(:,:), d(:,:), e(:,:)\r\n integer :: N\r\n real :: t0, t1\r\n\r\n write(*, '(a)', advance='no') ' Enter the order of the matrices:> '\r\n read(*,*) N\r\n write(*, '(a)', advance='no') ' Enter the threshold:> '\r\n read(*,*) threshold\r\n allocate(a(N,N), b(N,N), c(N,N), d(N,N), e(N,N))\r\n call random_seed()\r\n call random_number(a)\r\n call random_number(b)\r\n call cpu_time(t0)\r\n c = matmul(a,b)\r\n call cpu_time(t1)\r\n write(*,'(a, f10.3)') ' Time for matmul = ', t1-t0\r\n call cpu_time(t0)\r\n call strassen(a, b, d, N)\r\n call cpu_time(t1)\r\n write(*,'(a, f10.3)') ' Time for strassen = ', t1-t0\r\n write(*,'(a, g12.4)') ' RMS error for strassen = ', sqrt(sum((c-d)**2))/N\r\n call cpu_time(t0)\r\n call simple(a,b,e,N)\r\n call cpu_time(t1)\r\n write(*,'(a, f10.3)') ' Time for simple = ', t1-t0\r\n write(*,'(a, g12.4)') ' RMS error for simple = ', sqrt(sum((c-e)**2))/N\r\n stop\r\nend program strassen_test\r\n\r\n", "meta": {"hexsha": "54fc08c25c9079fd1a4e01564a10fccbb225963b", "size": 3697, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/strassen.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/strassen.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/strassen.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 28.4384615385, "max_line_length": 77, "alphanum_fraction": 0.5233973492, "num_tokens": 1479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825848, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.7852944841623595}} {"text": "! qinit routine for parabolic bowl problem, only single layer\nsubroutine qinit(meqn,mbc,mx,my,xlower,ylower,dx,dy,q,maux,aux)\n\n use geoclaw_module, only: grav\n\n implicit none\n\n ! Subroutine arguments\n integer, intent(in) :: meqn,mbc,mx,my,maux\n real(kind=8), intent(in) :: xlower,ylower,dx,dy\n real(kind=8), intent(inout) :: q(meqn,1-mbc:mx+mbc,1-mbc:my+mbc)\n real(kind=8), intent(inout) :: aux(maux,1-mbc:mx+mbc,1-mbc:my+mbc)\n\n ! Parameters for problem\n real(kind=8), parameter :: a = 1.d0\n real(kind=8), parameter :: sigma = 0.5d0\n real(kind=8), parameter :: h0 = 0.1d0\n\n ! Other storage\n integer :: i,j\n real(kind=8) :: omega,x,y,eta\n \n omega = sqrt(2.d0 * grav * h0) / a\n \n do i=1-mbc,mx+mbc\n x = xlower + (i - 0.5d0)*dx\n do j=1-mbc,my+mbc\n y = ylower + (j - 0.5d0) * dy\n eta = sigma * h0 / a**2 * (2.d0 * x - sigma)\n \n q(1,i,j) = max(0.d0,eta - aux(1,i,j))\n q(2,i,j) = 0.d0\n q(3,i,j) = sigma * omega * q(1,i,j)\n enddo\n enddo\n \nend subroutine qinit\n", "meta": {"hexsha": "1fb6b7628983d7102a066e9d1bfde1e11a7b1b91", "size": 1100, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/bowl_slosh/qinit.f90", "max_stars_repo_name": "AsianHam/geoclaw", "max_stars_repo_head_hexsha": "b5f9ee8cd6e64d107ba8bba1e6d588aa7bf6d417", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 51, "max_stars_repo_stars_event_min_datetime": "2015-07-01T13:39:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T16:13:17.000Z", "max_issues_repo_path": "tests/bowl_slosh/qinit.f90", "max_issues_repo_name": "AsianHam/geoclaw", "max_issues_repo_head_hexsha": "b5f9ee8cd6e64d107ba8bba1e6d588aa7bf6d417", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 274, "max_issues_repo_issues_event_min_datetime": "2015-02-20T18:25:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-09T23:51:47.000Z", "max_forks_repo_path": "tests/bowl_slosh/qinit.f90", "max_forks_repo_name": "AsianHam/geoclaw", "max_forks_repo_head_hexsha": "b5f9ee8cd6e64d107ba8bba1e6d588aa7bf6d417", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 66, "max_forks_repo_forks_event_min_datetime": "2015-01-10T00:05:00.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-24T22:05:16.000Z", "avg_line_length": 28.9473684211, "max_line_length": 70, "alphanum_fraction": 0.5490909091, "num_tokens": 420, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133548753619, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7852821362271336}} {"text": "SUBROUTINE qromb(func,a,b,ss)\r\nINTEGER*4 JMAX,JMAXP,K,KM\r\nREAL*8 a,b,func,ss,EPS\r\nEXTERNAL func\r\nPARAMETER (EPS=1.0d-6, JMAX=20, JMAXP=JMAX+1, K=5, KM=K-1)\r\n!CU USES polint,trapzd\r\nINTEGER*4 j\r\nREAL*8 dss,h(JMAXP),s(JMAXP)\r\nh(1)=1.\r\ndo j=1,JMAX\r\n\tcall trapzd(func,a,b,s(j),j)\r\n\tif (j.ge.K) then\r\n call polint(h(j-KM),s(j-KM),K,0.0d0,ss,dss)\r\n if (abs(dss).le.EPS*abs(ss)) return\r\n\tendif\r\n\ts(j+1)=s(j)\r\n\th(j+1)=0.25*h(j)\r\nend do\r\npause 'too many steps in qromb'\r\nEND\r\n", "meta": {"hexsha": "306ea1022b7455682a6cbabddd4dd4634844cbaf", "size": 488, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "grb_Liso/qromb.f90", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "grb_Liso/qromb.f90", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "grb_Liso/qromb.f90", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.2380952381, "max_line_length": 59, "alphanum_fraction": 0.6106557377, "num_tokens": 216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939913343093499, "lm_q2_score": 0.8354835391516132, "lm_q1q2_score": 0.7852821263835811}} {"text": "program calculatePi\n \n ! This is an implementation of the Leibniz Formula for Pi\n \n integer :: counter = 0\n real (16) :: pi = 0.0\n\n do while (.TRUE.)\n if ( modulo(counter, 2) == 0 ) then\n pi = pi + 4.0/(counter*2+1)\n else\n pi = pi - 4.0/(counter*2+1)\n end if\n\n counter = counter + 1\n print *, pi\n\n end do\n\nend program calculatePi\n", "meta": {"hexsha": "0612f4a8046bc5c0ee05d5cfffb7c0d7db906f78", "size": 410, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "CalculatePi.f90", "max_stars_repo_name": "LandonPowell/Math-Stuff", "max_stars_repo_head_hexsha": "a9915cb471f6cae97d53ba8bf2f45d44ccf852ed", "max_stars_repo_licenses": ["Zlib"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CalculatePi.f90", "max_issues_repo_name": "LandonPowell/Math-Stuff", "max_issues_repo_head_hexsha": "a9915cb471f6cae97d53ba8bf2f45d44ccf852ed", "max_issues_repo_licenses": ["Zlib"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CalculatePi.f90", "max_forks_repo_name": "LandonPowell/Math-Stuff", "max_forks_repo_head_hexsha": "a9915cb471f6cae97d53ba8bf2f45d44ccf852ed", "max_forks_repo_licenses": ["Zlib"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.5238095238, "max_line_length": 61, "alphanum_fraction": 0.5073170732, "num_tokens": 124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.960361162033533, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.7851667654688453}} {"text": "C$Procedure ROTVEC ( Transform a vector via a rotation )\n \n SUBROUTINE ROTVEC ( V1, ANGLE, IAXIS, VOUT )\n \nC$ Abstract\nC\nC Transform a vector to a new coordinate system rotated by ANGLE \nC radians about axis IAXIS. This transformation rotates V1 by \nC -ANGLE radians about the specified axis.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC ROTATION\nC VECTOR\nC\nC$ Declarations\n \n DOUBLE PRECISION V1 ( 3 )\n DOUBLE PRECISION ANGLE\n INTEGER IAXIS\n DOUBLE PRECISION VOUT ( 3 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC V1 I Vector whose coordinate system is to be rotated.\nC ANGLE I Angle of rotation in radians.\nC IAXIS I Axis of rotation (X=1, Y=2, Z=3).\nC VOUT O Resulting vector [ANGLE] * V1 expressed in\nC IAXIS\nC the new coordinate system.\nC\nC$ Detailed_Input\nC\nC V1 This is a vector (typically representing a vector fixed\nC in inertial space) which is to be expressed in another\nC coordinate system. The vector remains fixed but the\nC coordinate system changes.\nC\nC ANGLE The angle given in radians, through which the rotation\nC is performed.\nC\nC IAXIS The index of the axis of rotation. The X, Y, and Z\nC axes have indices 1, 2 and 3 respectively.\nC\nC$ Detailed_Output\nC\nC VOUT This is the vector expressed in the new coordinate system\nC specified by the angle of rotation and axis. If\nC [ANGLE] represents the rotation matrix described by\nC IAXIS\nC the angle and axis, (refer to the routine ROTATE)\nC then VOUT = [ANGLE] * V1\nC IAXIS\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC 1) If the axis index is not in the range 1 to 3 it will be treated\nC the same as that integer 1, 2, or 3 that is congruent to it mod\nC 3.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC A rotation about the first, i.e. x-axis, is described by\nC\nC | 1 0 0 |\nC | 0 cos(theta) sin(theta) |\nC | 0 -sin(theta) cos(theta) |\nC\nC A rotation about the second, i.e. y-axis, is described by\nC\nC | cos(theta) 0 -sin(theta) |\nC | 0 1 0 |\nC | sin(theta) 1 cos(theta) |\nC\nC A rotation about the third, i.e. z-axis, is described by\nC \nC | cos(theta) sin(theta) 0 |\nC | -sin(theta) cos(theta) 0 |\nC | 0 0 1 |\nC\nC ROTVEC decides which form is appropriate according to the value\nC of IAXIS and applies the rotation to the input vector.\nC\nC$ Examples\nC\nC Suppose that\nC\nC V1 = (1.414, 0, 0), ANGLE = PI/4, IAXIS = 3\nC\nC then after calling ROTVEC according to\nC\nC CALL ROTVEC (V1, ANGLE, IAXIS, VOUT)\nC\nC VOUT will be equal to (1, -1, 0).\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.M. Owen (JPL)\nC W.L. Taber (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.3, 23-APR-2010 (NJB)\nC\nC Header correction: assertions that the output\nC can overwrite the input have been removed.\nC\nC- SPICELIB Version 1.0.2, 04-OCT-1999 (NJB)\nC\nC Procedure line and abstract and were changed to dispel the\nC impression that the input vector is rotated by +ANGLE\nC radians about the specified axis.\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WMO)\nC\nC-&\n \nC$ Index_Entries\nC\nC rotate a vector\nC\nC-&\n \n \n \nC$ Revisions\nC\nC- Beta Version 1.1.0, 4-JAN-1989 (WLT)\nC\nC Upgrade the routine to work with negative axis indexes. Also take\nC care of the funky way the indices (other than the input) were\nC obtained via the MOD function. It works but isn't as clear\nC (or fast) as just reading the axes from data.\nC\nC-&\n DOUBLE PRECISION S\n DOUBLE PRECISION C\n \n INTEGER TMP\n INTEGER I1\n INTEGER I2\n INTEGER I3\n \n DOUBLE PRECISION TEMP (3)\n INTEGER INDEXS (5)\n SAVE INDEXS\n \n DATA INDEXS / 3, 1, 2, 3, 1 /\nC\nC Get the sine and cosine of ANGLE\nC\n S = DSIN(ANGLE)\n C = DCOS(ANGLE)\nC\nC Get indices for axes. The first index is for the axis of rotation.\nC The next two axes follow in right hand order (XYZ). First get the\nC non-negative value of IAXIS mod 3 .\nC\n TMP = MOD ( MOD(IAXIS,3) + 3, 3 )\n \n I1 = INDEXS( TMP + 1 )\n I2 = INDEXS( TMP + 2 )\n I3 = INDEXS( TMP + 3 )\nC\nC The coordinate along the axis of rotation does not change.\nC\n TEMP(1) = V1(I1)\n TEMP(2) = C*V1(I2) + S*V1(I3)\n TEMP(3) = -S*V1(I2) + C*V1(I3)\nC\nC Move the buffered vector to the output\nC\n VOUT(I1) = TEMP(1)\n VOUT(I2) = TEMP(2)\n VOUT(I3) = TEMP(3)\nC\n RETURN\n END\n", "meta": {"hexsha": "728698ecdcc348b91c92c9a0e7434c14cce99206", "size": 6699, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/rotvec.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/rotvec.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/rotvec.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 28.7510729614, "max_line_length": 72, "alphanum_fraction": 0.6080011942, "num_tokens": 2017, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9496693645535724, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.7851028560348838}} {"text": "!--------------------------------------------------\n!PHY2063 Task 1\n!URN 6309823 - Penguin Lab Group 1B\n!October 8th 2015\n!--------------------------------------------------\nPROGRAM Task1\n IMPLICIT NONE\n!\n REAL :: dmdt,h,r\n INTEGER :: i\n!\n REAL, DIMENSION(1:301) :: m\n REAL, DIMENSION(1:301) :: t\n REAL, DIMENSION(1:301) :: Error\n!\n!Open Files to store data\n!\n OPEN(unit=12,file='Task1.dat')\n!\n!Assign Values (r=rate, h=step, t=time, M=mass)\n!Error is error in Euler estimate\n!\n r=0.3\n h=0.1\n t(1)=0\n M(1)=0.1\n Error(1)=m(1)-0.1*exp(-0.3*t(1))\n!\n WRITE(12,*) t(1),M(1),Error(1)\n!\n!Euler method\n!\n DO i=1,301\n dmdt=-r*M(i)\n t(i+1)=t(i)+h\n M(i+1)=M(i)+h*dmdt\n Error(i+1)=m(i+1)-0.1*exp(-0.3*t(i+1))\n!\n!Write the values in the array to Task1.dat\n!\n WRITE(12,*) t(i+1),M(i+1),Error(i+1)\n END DO\n!\n Close (12)\n!\n!Run Program\n!Run gnuplot\n!Write \"plot \"Task1.dat\" using 1:2 with lines\" in the terminal\n!Find error: Run gnuplot\n!Write \"plot \"Task1.dat\" using 1:3 with lines\" in the terminal\n!\nEND PROGRAM Task1\n", "meta": {"hexsha": "4eaa58f16ead0a63ca480ee9b9c8ed2ede905fac", "size": 1041, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "assignment-0/Task1.f90", "max_stars_repo_name": "WilliamHoltam/numerical-physics", "max_stars_repo_head_hexsha": "00e51192872a8581df4f9556f2565cf14a01e70d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment-0/Task1.f90", "max_issues_repo_name": "WilliamHoltam/numerical-physics", "max_issues_repo_head_hexsha": "00e51192872a8581df4f9556f2565cf14a01e70d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-07-18T13:37:07.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-18T13:37:07.000Z", "max_forks_repo_path": "assignment-0/Task1.f90", "max_forks_repo_name": "WilliamHoltam/energy-entropy-and-numerical-physics", "max_forks_repo_head_hexsha": "00e51192872a8581df4f9556f2565cf14a01e70d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.641509434, "max_line_length": 62, "alphanum_fraction": 0.5513928915, "num_tokens": 412, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.785074533571101}} {"text": "*\n* Program heatbar - Calculate heat flows in a 100CM bar\n*\n* Bar initially starts out at 30 degrees C\n*\n* At 1 CM there is a 100 degree C heat source\n* At 63 CM there is a 0 degree heat source\n* At 100 CM there is a 60 degree source\n*\n* The program will print out the temperature at 10 50 and 80 CM\n* After 1, 10, and 100 time steps\n*\n* Written by - Charles Severance 18Mar92\n*\n REAL BAR(100)\n INTEGER TIME,POS,I\n*\n* Initialize the bar\n*\n DO I=1,100\n BAR(I) = 30.0\n ENDDO\n BAR(1) = 100.0\n BAR(63) = 0.0\n BAR(100) = 60.0\n*\n* Loop through the time steps. For each time step the new temperature\n* is calculated at each point in the bar. Make sure we don't recalcualte\n* the fixed temperature positions\n*\n DO TIME=1,100\n\n DO POS=2,62\n BAR(POS) = ( BAR(POS-1) + BAR(POS) + BAR(POS+1) ) / 3.0\n ENDDO\n DO POS=64,99\n BAR(POS) = ( BAR(POS-1) + BAR(POS) + BAR(POS+1) ) / 3.0\n ENDDO\n\n* The program will print out the temperature at 10 50 and 80 CM\n* After 1, 10, and 100 time steps\n\n IF ( TIME.EQ.1 .OR. TIME.EQ.10 .OR. TIME.EQ.100 ) THEN\n PRINT *,'Time step ',TIME\n PRINT *,'At Bar(10) = ',BAR(10)\n PRINT *,'At Bar(50) = ',BAR(50)\n PRINT *,'At Bar(80) = ',BAR(80)\n ENDIF\n ENDDO\n*\n END\n", "meta": {"hexsha": "41ecf42f3c40a815aa2a8af6ece0bd08928ba0d7", "size": 1333, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "archive/2000-eecs280/examples/examples.ftn/programs/heatbar.f", "max_stars_repo_name": "yashajoshi/cc4e", "max_stars_repo_head_hexsha": "dd166f7e70d4111945054b8cb39483eb8dfb591b", "max_stars_repo_licenses": ["Apache-2.0", "CC-BY-4.0"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2020-01-05T04:46:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T09:36:02.000Z", "max_issues_repo_path": "archive/2000-eecs280/examples/examples.ftn/programs/heatbar.f", "max_issues_repo_name": "yashajoshi/cc4e", "max_issues_repo_head_hexsha": "dd166f7e70d4111945054b8cb39483eb8dfb591b", "max_issues_repo_licenses": ["Apache-2.0", "CC-BY-4.0"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2021-07-01T01:19:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-07T01:30:45.000Z", "max_forks_repo_path": "archive/2000-eecs280/examples/examples.ftn/programs/heatbar.f", "max_forks_repo_name": "yashajoshi/cc4e", "max_forks_repo_head_hexsha": "dd166f7e70d4111945054b8cb39483eb8dfb591b", "max_forks_repo_licenses": ["Apache-2.0", "CC-BY-4.0"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2020-12-27T19:57:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T13:01:36.000Z", "avg_line_length": 25.6346153846, "max_line_length": 74, "alphanum_fraction": 0.5821455364, "num_tokens": 466, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034425, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7850745292042645}} {"text": "!C combine Fig_6.11_mandelbrotSolutionPart2.f90 and Fig_6.10_mandelbrotSolutionPart1.f90 into one file, and name it as mandel_par.f90\n!C (notice part2 of mandel_par_module has to come before part1 of main program))\n!C sample compile command: gfortran -fopenmp -o mandel_wrong mandel_par.f90\n\n MODULE mandel_par_module\n implicit none\n\n INTEGER, PARAMETER :: DP = SELECTED_REAL_KIND(14)\n\n INTEGER, PARAMETER :: NPOINTS=1000\n INTEGER, PARAMETER :: MAXITER=1000\n INTEGER :: numoutside=0\n\n TYPE d_complex\n REAL(KIND = DP) :: r\n REAL(KIND = DP) :: i\n END TYPE d_complex\n\n contains \n\n SUBROUTINE testpoint(c)\n\n!C Does the iteration z=z*z+c, until |z| > 2 when point is known to be outside set\n!C If loop count reaches MAXITER, point is considered to be inside the set\n\n implicit none\n TYPE(d_complex) :: z,c\n INTEGER :: iter\n REAL(KIND = DP) :: temp\n\n z = c\n\n DO iter = 1, MAXITER\n temp = (z%r*z%r) - (z%i*z%i) + c%r\n z%i = z%r*z%i*2 + c%i\n z%r = temp\n\n IF ((z%r*z%r + z%i*z%i) > 4.0) THEN \n !$OMP CRITICAL\n numoutside = numoutside + 1\n !$OMP END CRITICAL\n EXIT\n ENDIF\n ENDDO\n\n END SUBROUTINE\n\n END MODULE mandel_par_module\n", "meta": {"hexsha": "f2d183e56c0c2651aa6a4f8127c5f16d760bf205", "size": 1396, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Book/Fortran/Fig_6.11_mandelbrotSolutionPart2.f90", "max_stars_repo_name": "zafar-hussain/OmpCommonCore", "max_stars_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 37, "max_stars_repo_stars_event_min_datetime": "2020-04-21T18:05:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:10:18.000Z", "max_issues_repo_path": "Book/Fortran/Fig_6.11_mandelbrotSolutionPart2.f90", "max_issues_repo_name": "zafar-hussain/OmpCommonCore", "max_issues_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-12-09T19:42:54.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T21:27:04.000Z", "max_forks_repo_path": "Book/Fortran/Fig_6.11_mandelbrotSolutionPart2.f90", "max_forks_repo_name": "zafar-hussain/OmpCommonCore", "max_forks_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2020-09-05T18:54:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-23T02:19:12.000Z", "avg_line_length": 28.4897959184, "max_line_length": 133, "alphanum_fraction": 0.5680515759, "num_tokens": 397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.8652240877899775, "lm_q1q2_score": 0.7850283934044291}} {"text": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Compute LUT for automatic linear stretch.\nC\n SUBROUTINE ASTRETCH(HIST,NPTS,lut,nmin,nmax)\n IMPLICIT NONE\n INTEGER*4 NPTS\t\t!number of pixels in histogram\n INTEGER*4 NMIN,NMAX\t!linear stretch limits (returned)\n INTEGER*4 HIST(-32768:32767)\n INTEGER*2 LUT(-32768:32767)\n\n COMMON/C3/INMIN,INMAX,DNMIN,DNMAX\n INTEGER*4 INMIN,INMAX,DNMIN,DNMAX\n\n REAL*4 A,B,RTRUNC\n INTEGER*4 IDN\n\n CALL ASTRETCH_LIMITS(HIST,NPTS,nmin,nmax)\nC ....Compute stretch table\n A = FLOAT(DNMAX-DNMIN)/FLOAT(NMAX-NMIN)\n B = -A*NMIN+DNMIN\n DO IDN=INMIN,INMAX\n LUT(IDN) = RTRUNC(A*IDN+B)\n ENDDO\n RETURN\n END\n\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Compute linear stretch limits from histogram.\nC\n SUBROUTINE ASTRETCH_LIMITS(HIST,NPTS,nmin,nmax)\n IMPLICIT NONE\n INTEGER*4 NPTS\t\t!number of pixels in histogram\n INTEGER*4 NMIN,NMAX\t!linear stretch limits (returned)\n INTEGER*4 HIST(-32768:32767)\n\n COMMON/C3/INMIN,INMAX,DNMIN,DNMAX\n INTEGER*4 INMIN,INMAX,DNMIN,DNMAX\n\n REAL*4 RPARM(2),LPERC,HPERC\n INTEGER*4 ICOUNT,IDEF,NLEV\n CHARACTER*80 PRT\n 101 FORMAT('Percent saturation at low end=',F6.2,' at high end=',F6.2)\n\n CALL XVPARM('PERCENT',RPARM,ICOUNT,IDEF,1)\n LPERC = RPARM(1)/2.\n HPERC = LPERC\n CALL XVPARM('LPERCENT',RPARM,ICOUNT,IDEF,1)\n IF (IDEF.EQ.0) LPERC=RPARM(1)\n CALL XVPARM('HPERCENT',RPARM,ICOUNT,IDEF,1)\n IF (IDEF.EQ.0) HPERC=RPARM(1)\n WRITE (PRT,101) LPERC,HPERC\n CALL XVMESSAGE(PRT,' ')\n\n NLEV = INMAX - INMIN + 1\n CALL ASTRCH(HIST(INMIN),nmin,nmax,LPERC,HPERC,NLEV)\n NMIN = NMIN + INMIN\n NMAX = NMAX + INMIN\n IF (NMIN.EQ.NMAX) NMAX= NMAX+1\n RETURN\n END\n", "meta": {"hexsha": "7c44c1643dced5b9a6dc8666a858f7942f1f3baa", "size": 1878, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vos/p2/prog/stretch/astretch.f", "max_stars_repo_name": "NASA-AMMOS/VICAR", "max_stars_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-10-21T05:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T10:02:01.000Z", "max_issues_repo_path": "vos/p2/prog/stretch/astretch.f", "max_issues_repo_name": "NASA-AMMOS/VICAR", "max_issues_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vos/p2/prog/stretch/astretch.f", "max_forks_repo_name": "NASA-AMMOS/VICAR", "max_forks_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-09T01:51:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T00:23:24.000Z", "avg_line_length": 30.7868852459, "max_line_length": 76, "alphanum_fraction": 0.6666666667, "num_tokens": 669, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029487, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7850264744289712}} {"text": "! Solve Poisson equation\n! u_{xx} = f(x) x \\in [a, b]\n! with \n! u(a) = alpha, u(b) = beta\n! using Jacobi iteration and a fine-grain parallelism approach using OpenMP.\nprogram jacobi_omp1\n\n use omp_lib\n \n implicit none\n \n ! Problem specification and storage\n real(kind=8) :: a, b, alpha, beta\n real(kind=8), dimension(:), allocatable :: x, u, u_new, f\n real(kind=8) :: dx, tolerance, du_max\n\n integer(kind=4) :: n, num_threads\n integer(kind=8) :: i, num_iterations\n integer(kind=8), parameter :: MAX_ITERATIONS = 100000\n real(kind=8) :: time(2)\n\n ! Boundaries\n a = 0.d0\n b = 1.d0\n alpha = 0.d0\n beta = 3.d0\n\n ! Specify number of threads to use:\n num_threads = 4\n !$ call omp_set_num_threads(num_threads)\n !$ print \"('Using OpenMP with ',i3,' threads')\", num_threads\n\n N = 100\n\n ! Allocate storage for boundary points too\n allocate(x(0:N + 1), u(0:N + 1), u_new(0:N + 1), f(0:N + 1))\n\n call cpu_time(time(1))\n\n ! grid spacing:\n dx = (b - a) / (N + 1.d0)\n\n ! Set iniital guess and construct the grid\n ! Note that here we are breaking up the problem already to the threads\n !$omp parallel do\n do i=0, N + 1\n ! grid points:\n x(i) = i * dx\n ! source term:\n f(i) = exp(x(i))\n ! initial guess (satisfies boundary conditions and sets them)\n u(i) = alpha + x(i) * (beta - alpha)\n enddo\n\n ! Tolerance\n tolerance = 0.1d0 * dx**2\n\n ! Main Jacobi iteration loop\n ! Copy old values to new\n num_iterations = 0\n du_max = 1d99\n do while (du_max >= tolerance .and. num_iterations <= MAX_ITERATIONS)\n du_max = 0.d0\n !$omp parallel do reduction(max : du_max)\n do i=1, N\n u_new(i) = 0.5d0 * (u(i-1) + u(i+1) - dx**2 * f(i))\n ! print *, abs(u(i) - u_old(i))\n du_max = max(du_max, abs(u_new(i) - u(i)))\n end do\n\n if (mod(num_iterations, 1000) == 0) then\n print *, \"du_max, iteration = \", du_max, num_iterations\n end if\n\n ! Copy old data into new\n !$omp parallel do \n do i=1, N\n u(i) = u_new(i)\n end do\n num_iterations = num_iterations + 1\n end do\n\n call cpu_time(time(2))\n if (num_iterations > MAX_ITERATIONS) then\n print *, \"Iteration failed!\"\n stop\n end if\n print '(\"CPU time = \",f12.8, \" seconds\")', time(2) - time(1)\n print *, \"Total number of iterations: \", num_iterations\n\n ! Write out solution for checking\n open(unit=20, file=\"jacobi_omp1.txt\", status=\"unknown\")\n do i=0,n+1\n write(20,'(2e20.10)') x(i), u(i)\n enddo\n close(20)\n\nend program jacobi_omp1", "meta": {"hexsha": "648b8ea6a15f1ec8dddc2f1b82346bd373e0227e", "size": 2685, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/jacobi_omp1.f90", "max_stars_repo_name": "lihu8918/numerical-methods-pdes", "max_stars_repo_head_hexsha": "e3fb4d972174e832d223afb55ff7307d2305572b", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/jacobi_omp1.f90", "max_issues_repo_name": "lihu8918/numerical-methods-pdes", "max_issues_repo_head_hexsha": "e3fb4d972174e832d223afb55ff7307d2305572b", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/jacobi_omp1.f90", "max_forks_repo_name": "lihu8918/numerical-methods-pdes", "max_forks_repo_head_hexsha": "e3fb4d972174e832d223afb55ff7307d2305572b", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-23T08:01:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-23T08:01:01.000Z", "avg_line_length": 27.3979591837, "max_line_length": 76, "alphanum_fraction": 0.5679702048, "num_tokens": 845, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7850161328388973}} {"text": "PROGRAM MonteCarlo1\n ! This program demonstrates a serial Monte Carlo method by simulating a \n ! random walk in two dimensions of 100,000 particles in 10 steps. The program\n ! outputs the distribution of the distances that the particles have travled.\n\n USE IFPORT\n\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: n = 100000\n INTEGER, DIMENSION(0:9) :: total\n\n REAL :: pi, x, y, angle\n INTEGER :: i, step, temp\n\n pi = 3.1415926\n DO i = 0, 9\n total(i) = 0\n ENDDO\n\n CALL srand(100)\n DO i = 1, n\n x = 0.0\n y = 0.0\n DO step = 1, 10\n angle = 2.0 * pi * rand()\n x = x + cos(angle)\n y = y + sin(angle)\n ENDDO\n\n temp = sqrt(x**2 + y**2)\n total(temp) = total(temp) + 1\n ENDDO\n\n write (*,*) 'total =', total\nEND PROGRAM MonteCarlo1\n", "meta": {"hexsha": "bc8e36da3c0f1c6aa0d8b77072ca94b8d6f74c31", "size": 772, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/omp/apps/mpi/ex5/version1/mc.f90", "max_stars_repo_name": "tianyi93/hpxMP_mirror", "max_stars_repo_head_hexsha": "668e8881a6f2f437a614ae92e205ae49f083691e", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2018-07-16T14:39:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-08T11:25:09.000Z", "max_issues_repo_path": "examples/omp/apps/mpi/ex5/version1/mc.f90", "max_issues_repo_name": "tianyi93/hpxMP_mirror", "max_issues_repo_head_hexsha": "668e8881a6f2f437a614ae92e205ae49f083691e", "max_issues_repo_licenses": ["BSL-1.0"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2018-06-18T14:59:09.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-16T20:43:57.000Z", "max_forks_repo_path": "examples/omp/apps/mpi/ex5/version1/mc.f90", "max_forks_repo_name": "tianyi93/hpxMP_mirror", "max_forks_repo_head_hexsha": "668e8881a6f2f437a614ae92e205ae49f083691e", "max_forks_repo_licenses": ["BSL-1.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2018-06-22T18:44:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-21T11:17:28.000Z", "avg_line_length": 20.8648648649, "max_line_length": 79, "alphanum_fraction": 0.603626943, "num_tokens": 268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832974, "lm_q2_score": 0.8418256472515684, "lm_q1q2_score": 0.7849631086830797}} {"text": "program main\n ! Variables\n integer(4) :: i,n,imax,nmax\n\n nmax = 0\n imax = 1\n do i=2,999999\n n = count_collatz(i)\n if (n > nmax) then\n nmax = n\n imax = i\n endif\n enddo\n\n ! Write out answer\n write(*,*) \"Longest chain: \",nmax\n write(*,*) \"Starting number: \",imax\n\n\ncontains\n\n\n pure function count_collatz(n)\n ! Default\n implicit none\n\n ! Function arguments\n integer(4), intent(in) :: n\n integer(4) :: count_collatz\n\n ! Local variables\n integer(4) :: nsteps\n integer(8) :: n1\n\n ! Compute length of collatz chain\n n1 = n\n nsteps = 0\n do while (n1 /= 1)\n if (mod(n1,2)==0) then\n n1 = n1/2\n else\n n1 = 3*n1+1\n endif\n nsteps = nsteps + 1\n enddo\n\n count_collatz = nsteps\n return\n end function count_collatz\n\n\nend program main\n", "meta": {"hexsha": "55400d7e64c75f481206caaff4917351efcaec0d", "size": 859, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/problem14/problem14.f90", "max_stars_repo_name": "plaplant/Project_Euler", "max_stars_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/problem14/problem14.f90", "max_issues_repo_name": "plaplant/Project_Euler", "max_issues_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/problem14/problem14.f90", "max_forks_repo_name": "plaplant/Project_Euler", "max_forks_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-01-07T21:43:45.000Z", "max_forks_repo_forks_event_max_datetime": "2017-01-07T21:43:45.000Z", "avg_line_length": 16.2075471698, "max_line_length": 43, "alphanum_fraction": 0.545983702, "num_tokens": 289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942171172604, "lm_q2_score": 0.8688267728417087, "lm_q1q2_score": 0.7848061995845671}} {"text": " SUBROUTINE DG01ND( INDI, N, XR, XI, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the discrete Fourier transform, or inverse Fourier\nC transform, of a real signal.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC INDI CHARACTER*1\nC Indicates whether a Fourier transform or inverse Fourier\nC transform is to be performed as follows:\nC = 'D': (Direct) Fourier transform;\nC = 'I': Inverse Fourier transform.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC Half the number of real samples. N must be a power of 2.\nC N >= 2.\nC\nC XR (input/output) DOUBLE PRECISION array, dimension (N+1)\nC On entry with INDI = 'D', the first N elements of this\nC array must contain the odd part of the input signal; for\nC example, XR(I) = A(2*I-1) for I = 1,2,...,N.\nC On entry with INDI = 'I', the first N+1 elements of this\nC array must contain the the real part of the input discrete\nC Fourier transform (computed, for instance, by a previous\nC call of the routine).\nC On exit with INDI = 'D', the first N+1 elements of this\nC array contain the real part of the output signal, that is\nC of the computed discrete Fourier transform.\nC On exit with INDI = 'I', the first N elements of this\nC array contain the odd part of the output signal, that is\nC of the computed inverse discrete Fourier transform.\nC\nC XI (input/output) DOUBLE PRECISION array, dimension (N+1)\nC On entry with INDI = 'D', the first N elements of this\nC array must contain the even part of the input signal; for\nC example, XI(I) = A(2*I) for I = 1,2,...,N.\nC On entry with INDI = 'I', the first N+1 elements of this\nC array must contain the the imaginary part of the input\nC discrete Fourier transform (computed, for instance, by a\nC previous call of the routine).\nC On exit with INDI = 'D', the first N+1 elements of this\nC array contain the imaginary part of the output signal,\nC that is of the computed discrete Fourier transform.\nC On exit with INDI = 'I', the first N elements of this\nC array contain the even part of the output signal, that is\nC of the computed inverse discrete Fourier transform.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC Let A(1),....,A(2*N) be a real signal of 2*N samples. Then the\nC first N+1 samples of the discrete Fourier transform of this signal\nC are given by the formula:\nC\nC 2*N ((m-1)*(i-1))\nC FA(m) = SUM ( A(i) * W ),\nC i=1\nC 2\nC where m = 1,2,...,N+1, W = exp(-pi*j/N) and j = -1.\nC\nC This transform can be computed as follows. First, transform A(i),\nC i = 1,2,...,2*N, into the complex signal Z(i) = (X(i),Y(i)),\nC i = 1,2,...,N. That is, X(i) = A(2*i-1) and Y(i) = A(2*i). Next,\nC perform a discrete Fourier transform on Z(i) by calling SLICOT\nC Library routine DG01MD. This gives a new complex signal FZ(k),\nC such that\nC\nC N ((k-1)*(i-1))\nC FZ(k) = SUM ( Z(i) * V ),\nC i=1\nC\nC where k = 1,2,...,N, V = exp(-2*pi*j/N). Using the values of\nC FZ(k), the components of the discrete Fourier transform FA can be\nC computed by simple linear relations, implemented in the DG01NY\nC subroutine.\nC\nC Finally, let\nC\nC XR(k) = Re(FZ(k)), XI(k) = Im(FZ(k)), k = 1,2,...,N,\nC\nC be the contents of the arrays XR and XI on entry to DG01NY with\nC INDI = 'D', then on exit XR and XI contain the real and imaginary\nC parts of the Fourier transform of the original real signal A.\nC That is,\nC\nC XR(m) = Re(FA(m)), XI(m) = Im(FA(m)),\nC\nC where m = 1,2,...,N+1.\nC\nC If INDI = 'I', then the routine evaluates the inverse Fourier\nC transform of a complex signal which may itself be the discrete\nC Fourier transform of a real signal.\nC\nC Let FA(m), m = 1,2,...,2*N, denote the full discrete Fourier\nC transform of a real signal A(i), i=1,2,...,2*N. The relationship\nC between FA and A is given by the formula:\nC\nC 2*N ((m-1)*(i-1))\nC A(i) = SUM ( FA(m) * W ),\nC m=1\nC\nC where W = exp(pi*j/N).\nC\nC Let\nC\nC XR(m) = Re(FA(m)) and XI(m) = Im(FA(m)) for m = 1,2,...,N+1,\nC\nC be the contents of the arrays XR and XI on entry to the routine\nC DG01NY with INDI = 'I', then on exit the first N samples of the\nC complex signal FZ are returned in XR and XI such that\nC\nC XR(k) = Re(FZ(k)), XI(k) = Im(FZ(k)) and k = 1,2,...,N.\nC\nC Next, an inverse Fourier transform is performed on FZ (e.g. by\nC calling SLICOT Library routine DG01MD), to give the complex signal\nC Z, whose i-th component is given by the formula:\nC\nC N ((k-1)*(i-1))\nC Z(i) = SUM ( FZ(k) * V ),\nC k=1\nC\nC where i = 1,2,...,N and V = exp(2*pi*j/N).\nC\nC Finally, the 2*N samples of the real signal A can then be obtained\nC directly from Z. That is,\nC\nC A(2*i-1) = Re(Z(i)) and A(2*i) = Im(Z(i)), for i = 1,2,...N.\nC\nC Note that a discrete Fourier transform, followed by an inverse\nC transform will result in a signal which is a factor 2*N larger\nC than the original input signal.\nC\nC REFERENCES\nC\nC [1] Rabiner, L.R. and Rader, C.M.\nC Digital Signal Processing.\nC IEEE Press, 1972.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm requires 0( N*log(N) ) operations.\nC\nC CONTRIBUTORS\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Feb. 1997.\nC Supersedes Release 2.0 routine DG01BD by R. Dekeyser, and\nC F. Dumortier, State University of Gent, Belgium.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Complex signals, digital signal processing, fast Fourier\nC transform, real signals.\nC\nC ******************************************************************\nC\nC .. Scalar Arguments ..\n CHARACTER INDI\n INTEGER INFO, N\nC .. Array Arguments ..\n DOUBLE PRECISION XI(*), XR(*)\nC .. Local Scalars ..\n INTEGER J\n LOGICAL LINDI\nC .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nC .. External Subroutines ..\n EXTERNAL DG01MD, DG01NY, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC MOD\nC .. Executable Statements ..\nC\n INFO = 0\n LINDI = LSAME( INDI, 'D' )\nC\nC Test the input scalar arguments.\nC\n IF( .NOT.LINDI .AND. .NOT.LSAME( INDI, 'I' ) ) THEN\n INFO = -1\n ELSE\n J = 0\n IF( N.GE.2 ) THEN\n J = N\nC WHILE ( MOD( J, 2 ).EQ.0 ) DO\n 10 CONTINUE\n IF ( MOD( J, 2 ).EQ.0 ) THEN\n J = J/2\n GO TO 10\n END IF\nC END WHILE 10\n END IF\n IF ( J.NE.1 ) INFO = -2\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'DG01ND', -INFO )\n RETURN\n END IF\nC\nC Compute the Fourier transform of Z = (XR,XI).\nC\n IF ( .NOT.LINDI ) CALL DG01NY( INDI, N, XR, XI )\nC\n CALL DG01MD( INDI, N, XR, XI, INFO )\nC\n IF ( LINDI ) CALL DG01NY( INDI, N, XR, XI )\nC\n RETURN\nC *** Last line of DG01ND ***\n END\n", "meta": {"hexsha": "6e4277250dae4948f66b498adbe13b2583ce724e", "size": 7916, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/DG01ND.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/DG01ND.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/DG01ND.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 33.8290598291, "max_line_length": 72, "alphanum_fraction": 0.5512885296, "num_tokens": 2334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9626731105140616, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7848024027988839}} {"text": " SUBROUTINE DQRBD (IPASS, Q, E, N, V, MDV, NRV, C, MDC, NCC)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1996-03-30 DQRBD Krogh Added external statement.\nC>> 1994-10-20 DQRBD Krogh Changes to use M77CON\nC>> 1992-03-13 DQRBD FTK Removed implicit statements.\nC>> 1987-11-24 DQRBD Lawson Initial code.\nc--D replaces \"?\": ?QRBD, ?ROT, ?ROTG, ?SWAP\nc\nC Computes the singular value decomposition of an N order\nc upper bidiagonal matrix, B. This decomposition is of the form\nc\nc (1) B = U * S * (V**t)\nc\nc where U and V are each N x N orthogonal and S is N x N\nc diagonal, with nonnegative diagonal terms in nonincreasing\nc order. Note that these matrices also satisfy\nc\nc S = (U**t) * B * V\nc\nc The user may optionally provide an NRV x N matrix V1 in\nc the array V(,) and an N x NCC matrix C in the array C(,).\nc This subr will replace these matrices respectively by the\nc NRV x N matrix\nc V2 = V1 * V\nc and the N x NCC matrix\nc C2 = (U**t) * C1\nc\nc On entry the bidiagonal matrix, B, is to be given in the\nc arrays Q() and E() as indicated by the diagram:\nc\nC (Q1,E2,0... )\nC ( Q2,E3,0... )\nC B = ( . )\nC ( . 0)\nC ( 0 .EN)\nC ( QN)\nC\nC On return, the singular values, i.e. the diagonal terms of\nc S, will be stored in Q(1) through Q(N).\nc\nc THIS CODE IS BASED ON THE PAPER AND 'ALGOL' CODE..\nC REF..\nC 1. REINSCH,C.H. AND GOLUB,G.H. 'SINGULAR VALUE DECOMPOSITION\nC AND LEAST SQUARES SOLUTIONS' (NUMER. MATH.), VOL. 14,(1970).\nC\nC ------------------------------------------------------------------\nC Subroutine Arguments\nc\nc IPASS (Out) On return, IPASS = 1 means computation was\nc successful or N .le. 0.\nc IPASS = 2 means computation not successful after 10*N\nc iterations. The algorithm usually succeeds in about\nc 2*N iterations.\nc\nc Q() (In/Out) On entry must contain the diagonal terms of\nc the bidiagonal matrix B. On return contains the N\nc singular values of B. These will be nonnegative and\nc in nonincreasing order.\nc\nc E() (In/Work) On entry must contain the superdiagonal terms\nc of B. E(1) is not used. For i = 2, ..., N, E(i) must\nc contain B(i-1,i). The contents of this array will be\nc modified by this subr.\nc\nc N (In) The order of the bidiagonal matrix B and the\nc number of singular values to be produced.\nc\nc V(,) (In/Out) If NRV .gt. 0, on entry this array contains an\nc NRV x N matrix, V1. On return V(,) will contain the\nc NRV x N matrix V2 = V1 * V where V is defined by Eq.(1)\nc above. If NRV .eq. 0 the array V(,) will not be\nc referenced.\nc\nc MDV (In) First dimensioning parameter for the array V(,).\nc Require MDV .ge. NRV.\nc\nc NRV (In) No. of rows in matrix V1 in array V(,).\nc Require NRV .ge. 0.\nc\nc C(,) (In/Out) If NCC .gt. 0, on entry this array contains an\nc N x NCC matrix, C1. On return C(,) will contain the\nc N x NCC matrix C2 = (U**t) * C1 where U is defined by\nc Eq.(1) above. If NCC .eq. 0 the array C(,) will not be\nc referenced.\nc\nc MDC (In) First dimensioning parameter for the array C(,).\nc Require MDC .ge. N.\nc\nc NCC (In) No. of columns in matrix C1 in array C(,).\nc Require NCC .ge. 0.\nc ------------------------------------------------------------------\nc Subprograms referenced: ERMSG, D1MACH, DROT, DROTG, DSWAP.\nc ------------------------------------------------------------------\nc This code was originally developed by Charles L. Lawson and\nc Richard J. Hanson at Jet Propulsion Laboratory in 1973. The\nc original code was described and listed in the book,\nc\nc Solving Least Squares Problems\nc C. L. Lawson and R. J. Hanson\nc Prentice-Hall, 1974\nc\nc Feb, 1985, C. L. Lawson & S. Y. Chiu, JPL. Adapted code from the\nc Lawson & Hanson book to Fortran 77 for use in the JPL MATH77\nc library.\nc Prefixing subprogram names with S or D for s.p. or d.p. versions.\nc Using generic names for intrinsic functions.\nc Adding calls to BLAS and MATH77 error processing subrs in some\nc program units.\nc ------------------------------------------------------------------\n EXTERNAL D1MACH\n INTEGER I,II,IPASS,J,K,L,LP1,MDC,MDV,N,N10,NCC,NQRS,NRV\n DOUBLE PRECISION BIG,C(MDC,*),CS,D1MACH,DNORM,E(N),EPS,F,G,H\n DOUBLE PRECISION ONE,Q(N),SMALL,SN,T,TEN,TWO,V(MDV,N),X,Y,Z,ZERO\n PARAMETER(ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0, TEN = 10.0D0)\n LOGICAL WNTV ,HAVERS,FAIL\nc ------------------------------------------------------------------\n EPS = D1MACH(4)\n BIG = TEN / SQRT(EPS)\n IPASS = 1\n IF (N .LE. 0) RETURN\n N10 = 10 * N\n WNTV = NRV.GT.0\n HAVERS = NCC.GT.0\n FAIL = .FALSE.\n NQRS = 0\n E(1) = ZERO\n DNORM = ZERO\n DO 10 J = 1,N\n 10 DNORM = MAX(ABS(Q(J))+ABS(E(J)),DNORM)\n SMALL = DNORM * EPS\nC ------------------------------------------------------------------\nC Begin main loop.\n DO 200 K = N, 1, -1\nC\nC TEST FOR SPLITTING OR RANK DEFICIENCIES..\nC FIRST MAKE TEST FOR LAST DIAGONAL TERM, Q(K), BEING SMALL.\n 20 CONTINUE\n IF(K .EQ. 1) GO TO 50\n IF (ABS(Q(K)) .GT. SMALL) GO TO 50\nC\nC SINCE Q(K) IS SMALL WE WILL MAKE A SPECIAL PASS TO\nC TRANSFORM E(K) TO ZERO.\nC\n CS = ZERO\n SN = -ONE\n DO 40 II = 2,K\n I = K + 1 - II\n F = -SN * E(I + 1)\n E(I+1) = CS * E(I+1)\n CALL DROTG(Q(I),F,CS,SN)\nC TRANSFORMATION CONSTRUCTED TO ZERO POSITION (I,K).\nC\nC ACCUMULATE RT. TRANSFORMATIONS IN V.\n IF (WNTV) CALL DROT(NRV,V(1,I),1,V(1,K),1,CS,SN)\n 40 CONTINUE\nC\nC THE MATRIX IS NOW BIDIAGONAL, AND OF LOWER ORDER\nC SINCE E(K) .EQ. ZERO..\nC\n 50 DO 60 L = K, 1, -1\n IF (ABS(E(L)) .LE. SMALL) GO TO 100\n IF (ABS(Q(L-1)) .LE. SMALL) GO TO 70\n 60 CONTINUE\nC\nC THE ABOVE LOOP CAN'T COMPLETE SINCE E(1) = ZERO.\nC\n GO TO 100\nC\nC CANCELLATION OF E(L), L.GT.1.\nC\n 70 CS = ZERO\n SN = -ONE\n DO 90 I = L,K\n F = -SN * E(I)\n E(I) = CS * E(I)\n IF (ABS(F) .LE. SMALL) GO TO 100\n CALL DROTG(Q(I),F,CS,SN)\n IF (HAVERS) CALL DROT(NCC,C(I,1),MDC,C(L-1,1),MDC,CS,SN)\n 90 CONTINUE\nC\nC TEST FOR CONVERGENCE..\nC\n 100 Z = Q(K)\n IF (L .EQ. K) GO TO 170\nC\nC SHIFT FROM BOTTOM 2 BY 2 MINOR OF B**(T)*B.\nC\n X = Q(L)\n Y = Q(K-1)\n G = E(K-1)\n H = E(K)\n F = ((Y-Z)*(Y+Z) + (G-H)*(G+H)) / (TWO*H*Y)\nC\n IF (ABS(F) .LT. BIG) THEN\n G = SQRT(ONE + F**2)\n ELSE\n G = ABS(F)\n END IF\nC\n IF (F .GE. ZERO) THEN\n T = F + G\n ELSE\n T = F - G\n END IF\nC\n F = ((X-Z)*(X+Z) + H*(Y/T-H)) / X\nC\nC NEXT QR SWEEP..\n CS = ONE\n SN = ONE\n LP1 = L+1\n DO 160 I = LP1,K\n G = E(I)\n Y = Q(I)\n H = SN * G\n G = CS * G\n CALL DROTG(F,H,CS,SN)\n E(I-1) = F\n F = X * CS + G * SN\n G = -X*SN + G*CS\n H = Y * SN\n Y = Y * CS\nC\nC ACCUMULATE ROTATIONS (FROM THE RIGHT) IN 'V'\nC\n IF (WNTV) CALL DROT(NRV,V(1,I-1),1,V(1,I),1,CS,SN)\n CALL DROTG(F,H,CS,SN)\n Q(I-1) = F\n F = CS*G + SN*Y\n X = -SN*G + CS*Y\nC\nC APPLY ROTATIONS FROM THE LEFT TO RIGHT HAND SIDES IN 'C'\nC\n IF (HAVERS) CALL DROT(NCC,C(I-1,1),MDC,C(I,1),MDC,CS,SN)\n 160 CONTINUE\nC\n E(L) = ZERO\n E(K) = F\n Q(K) = X\n NQRS = NQRS + 1\n IF (NQRS .LE. N10) THEN\nc\nc Return for further iteration on Q(K).\n GO TO 20\n ELSE\nC Iteration count limit exceeded for Q(K).\n FAIL = .TRUE.\n END IF\nC ------------------------------------------------------------------\nC Accepting Q(K). Either convergence has been reached or\nc the iteration count limit has been exceeded.\nC Adjust sign of Q(K) to be nonnegative.\nc\n 170 IF (Z .LT. ZERO) THEN\n Q(K) = -Z\n IF (WNTV) THEN\n DO 180 J = 1,NRV\n 180 V(J,K) = -V(J,K)\n END IF\n END IF\nC\n 200 CONTINUE\nc End of main loop.\nc ------------------------------------------------------------------\n IF (N .EQ. 1) RETURN\nc\nc Test sing vals for being in order. If not in order then\nc sort them.\nc\n DO 210 I = 2,N\n IF (Q(I) .GT. Q(I-1)) GO TO 220\n 210 CONTINUE\nC Sing vals are sorted.\n GO TO 290\nc Sort the sing vals.\n 220 DO 270 I = 2,N\n T = Q(I-1)\n K = I-1\n DO 230 J = I,N\n IF (T .LT. Q(J)) THEN\n T = Q(J)\n K = J\n END IF\n 230 CONTINUE\n IF (K .NE. I-1) THEN\n Q(K) = Q(I-1)\n Q(I-1) = T\n IF (HAVERS) CALL DSWAP(NCC, C(I-1,1),MDC, C(K,1),MDC)\n IF (WNTV) CALL DSWAP(NRV, V(1,I-1),1, V(1,K),1)\n END IF\n 270 CONTINUE\nC\nc Sing vals are sorted.\nC\nC ------------------------------------------------------------------\n 290 CONTINUE\n IF (FAIL) THEN\nC Error message.\n IPASS = 2\n CALL ERMSG('DQRBD',1,0,\n * 'Convergence failure in computing singular values.','.')\n END IF\n RETURN\n END\n", "meta": {"hexsha": "2682baa3494702c78ed85af7faa7238f2300a42e", "size": 10968, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dqrbd.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/dqrbd.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/dqrbd.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 35.7263843648, "max_line_length": 72, "alphanum_fraction": 0.4466630197, "num_tokens": 3259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900957313305, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.7847728604082654}} {"text": " function tair(hr,jj)\n\n!! ~ ~ ~ PURPOSE ~ ~ ~\n!! this function approximates hourly air temperature from daily max and\n!! min temperatures as documented by Campbell (1985)\n\n!! ~ ~ ~ INCOMING VARIABLES ~ ~ ~\n!! name |units |definition\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n!! tmn(:) |deg C |minimum temperature for the day in HRU\n!! tmp_hi(:) |deg C |last maximum temperature in HRU\n!! tmp_lo(:) |deg C |last minimum temperature in HRU\n!! tmx(:) |deg C |maximum temperature for the day in HRU\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n\n!! ~ ~ ~ OUTGOING VARIABLES ~ ~ ~\n!! name |units |definition\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n!! tair |deg C |air temperature for hour in HRU\n!! tmp_hi(:) |deg C |last maximum temperature in HRU\n!! tmp_lo(:) |deg C |last minimum temperature in HRU\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n\n!! ~ ~ ~ LOCAL DEFINITIONS ~ ~ ~\n!! name |units |definition\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n!! hr |none |hour if the day\n!! jj |none |HRU number\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n\n!! ~ ~ ~ SUBROUTINES/FUNCTIONS CALLED ~ ~ ~\n!! Intrinsic: Real, Cos\n\n!! ~ ~ ~ ~ ~ ~ END SPECIFICATIONS ~ ~ ~ ~ ~ ~\n\n!! subroutine developed by A. Van Griensven\n!! Hydrology-Vrije Universiteit Brussel, Belgium\n!! subroutine modified by SLN\n\n use parm\n \n integer, intent (in) :: jj\n real, intent(in) :: hr\n real :: tair\n\n!! update hi or lo temperature depending on hour of day\n if (hr == 3) tmp_lo(jj) = tmn(jj)\n if (hr == 15) tmp_hi(jj) = tmx(jj)\n\n!! SWAT manual equation 2.3.1\n tair = 0.\n tair = 0.5 * (tmp_hi(jj) + tmp_lo(jj) + (tmp_hi(jj) - tmp_lo(jj) \n & * Cos(0.2618 * Real(hr - 15))))\n\n return\n end", "meta": {"hexsha": "4921a20dfe84747b58e676b66a9c3483040f5468", "size": 2178, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "modified_source_code/tair.f", "max_stars_repo_name": "gpignotti/swat_soil_moisture_sensitivity", "max_stars_repo_head_hexsha": "d2c3f6185acabf31440d613651192cdaabfe6b6c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "modified_source_code/tair.f", "max_issues_repo_name": "gpignotti/swat_soil_moisture_sensitivity", "max_issues_repo_head_hexsha": "d2c3f6185acabf31440d613651192cdaabfe6b6c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-07-02T19:37:29.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-02T19:37:29.000Z", "max_forks_repo_path": "modified_source_code/tair.f", "max_forks_repo_name": "gpignotti/swat_soil_moisture_sensitivity", "max_forks_repo_head_hexsha": "d2c3f6185acabf31440d613651192cdaabfe6b6c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.8928571429, "max_line_length": 75, "alphanum_fraction": 0.4104683196, "num_tokens": 728, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768620069626, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7847460308566677}} {"text": "!*****************************************************************************80\n!\n!! Evaluate the shape functions at gaus pts \n! Discussion:\n! Calculates shape fcns and derivatives at the gauss pts\n! Parameters:\n\nsubroutine inter_shape_fcns (xi, h)\n!\n USE global_parameters_M\n USE gauss_integration_M\n USE flags_M\n USE mesh_info_M\n\n implicit none\n!---Dummy variable\n real(dp) :: xi \n !real, dimension(3) :: elem_coord\n real(dp) :: h\n\n!---local\n integer :: i \n \n lagrange = .TRUE.\n ! Calculate shape function @ gauss pt\n if(lagrange .eqv. .TRUE.) then \n \tshape_fcn(1) = -0.5*xi*(1 - xi) \n \tshape_fcn(2) = (1 + xi)*(1 - xi)\n \tshape_fcn(3) = 0.5*xi*(1 + xi)\n\n \t! Derivative of shape function @ gauss pt\n \tder_shape_fcn(1) = xi - 0.5 \n \tder_shape_fcn(2) = -2.0*xi\n \tder_shape_fcn(3) = xi + 0.5\n g_jacobian = h*0.5 \n \n !! Compute jacobian\n \t!do i = 1, nodes_per_elem\n ! g_jacobian = g_jacobian + der_shape_fcn(i)/elem_coord(i)\n \t!end do\n ! Compute global derivative\n \tdo i = 1, nodes_per_elem\n \t global_der_shape_fcn(i) = der_shape_fcn(i)/g_jacobian \n \tend do\n end if\n hermite = .FALSE.\n!---Calculate using hermite polynomials \n !if(hermite .eqv. .TRUE.) then\n ! \n ! shape_fcn(1) = 0.25*(2.0 - 3.0*xi + xi**3) \n ! shape_fcn(2) = -h*(1.0 - xi)*(1.0 - xi*xi)/8.0\n ! shape_fcn(3) = 0.25*(2.0 + 3.0*xi - xi**3)\n ! shape_fcn(4) = h*(1.0 + xi)*(1.0 - xi*xi)/8.0\n ! \n ! der_shape_fcn(1)= -0.75*(1.0-xi*xi) \n ! der_shape_fcn(2)= h*(1.0+2.0*xi - 3.0*xi*xi)/8.0\n ! der_shape_fcn(3)= 0.75*(1.0 - xi*xi) \n ! der_shape_fcn(4)= h*(1.0 - 2.0*xi - 3.0*xi*xi)/8.0 \n ! g_jacobian = h*0.5\n ! \n ! ! Compute global derivative\n !\tdo i = 1, nodes_per_elem\n !\t global_der_shape_fcn(i) = der_shape_fcn(i)/g_jacobian \n !\tend do\n !\n !end if\n\nend \n", "meta": {"hexsha": "83a3daffbd063be2649ef939418aa050638af2ec", "size": 1958, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/inter_shape_fcns.f90", "max_stars_repo_name": "ZanderUF/ANL_ptkin", "max_stars_repo_head_hexsha": "cd094a51b8349879968cc4c395928643c6c51411", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-13T06:00:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-13T06:00:47.000Z", "max_issues_repo_path": "src/inter_shape_fcns.f90", "max_issues_repo_name": "ZanderUF/ANL_ptkin", "max_issues_repo_head_hexsha": "cd094a51b8349879968cc4c395928643c6c51411", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2018-09-14T15:27:30.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-19T20:23:09.000Z", "max_forks_repo_path": "src/inter_shape_fcns.f90", "max_forks_repo_name": "ZanderUF/ANL_ptkin", "max_forks_repo_head_hexsha": "cd094a51b8349879968cc4c395928643c6c51411", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-02T10:26:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-02T10:26:31.000Z", "avg_line_length": 28.3768115942, "max_line_length": 80, "alphanum_fraction": 0.5291113381, "num_tokens": 723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7846433561950531}} {"text": "program BSPE\n implicit none\n ! BS Variables & Input\n real :: S_0, K, T, sigma, r\n real :: BS_CALCULATE, PCparity, Phi\n real :: C_0, P_0\n\n print*, \"Input order: stock price ($), strike price ($), time to maturity (years), voltality (rate), interest rate.\"\n\n ! S_0: stock price, K: strike price, T: time to maturity, sigma: volatility, r: risk-free interest rate\n read*, S_0, K, T, sigma, r\n\n ! Output European call option price\n C_0 = BS_CALCULATE(S_0, K, T, sigma, r)\n print*, \"Price of European call option: \", C_0\n ! Output European put option price\n P_0 = PCparity(C_0, K, r, T, S_0)\n print*, \"Price of European put option: \", P_0\n\nend program BSPE\n\n! Calculate the value of the non-dividend paying call option\n! https://en.wikipedia.org/wiki/Black-Scholes_model#Black–Scholes_formula\nfunction BS_CALCULATE(S_0, K, T, sigma, r)\n implicit none\n real :: S_0, K, T, sigma, r, omega\n real :: BS_CALCULATE, Phi\n\n omega = ( r*T + (sigma**2 * T / 2) - log(K/S_0) ) / ( sigma * sqrt(T) )\n BS_CALCULATE = S_0 * Phi(omega) - K * exp(-r*T) * Phi(omega - sigma*sqrt(T))\nend function BS_CALCULATE\n\n! Calculate normal cdf\n! https://en.wikipedia.org/wiki/Normal_distribution#Cumulative_distribution_function\nfunction Phi(z)\n implicit none\n real, parameter :: pi = 4.D0*DATAN(1.D0)\n real :: Phi, z\n integer :: k\n\n ! Taylor series normal approximation\n Phi = 0.5\n do k = 0, 20\n Phi = Phi + ( ((-1.0)**k) * (z** (2.0*k+1.0)) ) / ( (2.0**k) * gamma(real(k+1)) * (2.0*k+1.0) ) * (1.0/sqrt(2*pi))\n end do\nend function Phi\n\nfunction PCparity(C_0, K, r, T, S_0)\n implicit none\n real :: PCparity, C_0, K, r, T, S_0\n\n PCparity = C_0 + K * exp(-r*T) - S_0\nend function PCparity\n", "meta": {"hexsha": "5e0ce6615237eb2884c36b9812b2bf820df5154a", "size": 1720, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "BSPE.f95", "max_stars_repo_name": "jjmarks/Black-Scholes-F95", "max_stars_repo_head_hexsha": "cc41ac48a77861803f7831d23545d482f2bddcaa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "BSPE.f95", "max_issues_repo_name": "jjmarks/Black-Scholes-F95", "max_issues_repo_head_hexsha": "cc41ac48a77861803f7831d23545d482f2bddcaa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "BSPE.f95", "max_forks_repo_name": "jjmarks/Black-Scholes-F95", "max_forks_repo_head_hexsha": "cc41ac48a77861803f7831d23545d482f2bddcaa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.8518518519, "max_line_length": 120, "alphanum_fraction": 0.6377906977, "num_tokens": 598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248174286374, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.784539775893187}} {"text": "module gammaf90\n use mtmod\n implicit none\n\ncontains\n real(8) function gammadev(alpha,beta) result(g)\n!!$ Generates pseudo-random numbers from a Gamma distribution with parameters alpha and beta, \n!!$ such that the mean of the distribution, mu = alpha * beta. \n!!$ (Different notations are used for the second parameter, sometimes defined as lambda = 1/beta)\n!!$ The algorithms in this routine are from \"Random Number Generation and Monte Carlo Methods\", by James E. Gentle\n!!$ (2nd edition, Springer-Verlag, New York, 2003)\n implicit none\n real(8), intent(in) :: alpha, beta\n real(8) :: am1, b, u1, u2, v, t, x, y\n integer :: i, j\n\n am1 = alpha - 1.0d0\n g = -1\n\n if( alpha .gt. 1.0d0 ) then \n do while( g .le. 0.0d0 ) \n u1 = grnd()\n u2 = grnd()\n v = (alpha - 1.0d0/(6.0d0*alpha))*u1/(am1*u2)\n if( 2.0d0 * (u2 - 1.0d0) /am1 + v + 1.0d0/v .le. 2.0d0 ) then\n g = am1 * v\n else if( 2*log(u2)/am1 - log(v) + v .le. 1.0d0 ) then\n g = am1 * v\n end if\n end do\n else ! alpha <= 1\n t = 0.07 + 0.75*sqrt(1.0d0 - alpha)\n b = 1.0d0 + exp(-t)*alpha/t\n do while( g .le. 0.0d0 ) \n u1 = grnd()\n u2 = grnd()\n v = b * u1\n if( v .le. 1 ) then\n x = t * v**(1.0d0/alpha)\n if( u2 .lt. (2.0d0-x)/(2.0d0+x) ) then\n g = x\n else if( u2 .lt. exp(-x) ) then\n g = x\n end if\n else\n x = - log(t*(b-v)/alpha)\n y = x/t\n if( u2*(alpha + y*(1.0d0-alpha)) .le. 1.0d0 ) then\n g = x\n else if( u2 .lt. y**am1 ) then\n g = x\n end if\n end if\n end do\n end if\n g = beta * g\n return\n end function gammadev\nend module gammaf90\n", "meta": {"hexsha": "0b6e6ec5f380bc998faf087208e45f334325a1cf", "size": 1809, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "DRAM/NPZDFix_sRun/S1_g1/Compile/gammadev.f90", "max_stars_repo_name": "BingzhangChen/NPZDFeCONT", "max_stars_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "DRAM/NPZDFix_sRun/S1_g1/Compile/gammadev.f90", "max_issues_repo_name": "BingzhangChen/NPZDFeCONT", "max_issues_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DRAM/NPZDFix_sRun/S1_g1/Compile/gammadev.f90", "max_forks_repo_name": "BingzhangChen/NPZDFeCONT", "max_forks_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.15, "max_line_length": 114, "alphanum_fraction": 0.4991708126, "num_tokens": 658, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242074, "lm_q2_score": 0.8459424314825852, "lm_q1q2_score": 0.7844959560923909}} {"text": "!\n! \"dftmod\" computes the modulus of the discrete Fourier transform\n! of \"bsarray\" and stores it in \"bsmod\"\n!\n!\nsubroutine dftmod (bsmod,bsarray,nfft,order)\nimplicit none\ninteger::i,j,k\ninteger::nfft,jcut\ninteger::order,order2\nreal(kind=8)::eps,zeta\nreal(kind=8)::arg,factor\nreal(kind=8)::sum1,sum2\nreal(kind=8)::bsmod(*)\nreal(kind=8)::bsarray(*)\nreal(kind=8)::pi\npi=3.1415926535897932384626433832795029d0\n!\n! get the modulus of the discrete Fourier transform\n!\nfactor = 2.0d0 * pi / dble(nfft)\ndo i = 1, nfft\n sum1 = 0.0d0\n sum2 = 0.0d0\n do j = 1, nfft\n arg = factor * dble((i-1)*(j-1))\n sum1 = sum1 + bsarray(j)*cos(arg)\n sum2 = sum2 + bsarray(j)*sin(arg)\n end do\n bsmod(i) = sum1**2 + sum2**2\nend do\n!\n! fix for exponential Euler spline interpolation failure\n!\neps = 1.0d-7\nif (bsmod(1) .lt. eps) bsmod(1) = 0.5d0 * bsmod(2)\ndo i = 2, nfft-1\n if (bsmod(i) .lt. eps) &\n & bsmod(i) = 0.5d0 * (bsmod(i-1)+bsmod(i+1))\nend do\nif (bsmod(nfft) .lt. eps) bsmod(nfft) = 0.5d0 * bsmod(nfft-1)\n!\n! compute and apply the optimal zeta coefficient\n!\njcut = 50\norder2 = 2 * order\ndo i = 1, nfft\n k = i - 1\n if (i .gt. nfft/2) k = k - nfft\n if (k .eq. 0) then\n zeta = 1.0d0\n else\n sum1 = 1.0d0\n sum2 = 1.0d0\n factor = pi * dble(k) / dble(nfft)\n do j = 1, jcut\n arg = factor / (factor+pi*dble(j))\n sum1 = sum1 + arg**order\n sum2 = sum2 + arg**order2\n end do\n do j = 1, jcut\n arg = factor / (factor-pi*dble(j))\n sum1 = sum1 + arg**order\n sum2 = sum2 + arg**order2\n end do\n zeta = sum2 / sum1\n end if\n bsmod(i) = bsmod(i) * zeta**2\nend do\n\nreturn\nend subroutine dftmod\n\n\n", "meta": {"hexsha": "86cdfbbb7729a17a3f51a876b026c64cf4d37e15", "size": 1720, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/dftmod.f90", "max_stars_repo_name": "Trebonius91/EVB-QMDFF", "max_stars_repo_head_hexsha": "8d03e1ad073becb0161b0377b630d7b65fe3c290", "max_stars_repo_licenses": ["MIT", "Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-13T15:27:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T15:27:13.000Z", "max_issues_repo_path": "src/dftmod.f90", "max_issues_repo_name": "chrinide/EVB-QMDFF", "max_issues_repo_head_hexsha": "8d03e1ad073becb0161b0377b630d7b65fe3c290", "max_issues_repo_licenses": ["MIT", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/dftmod.f90", "max_forks_repo_name": "chrinide/EVB-QMDFF", "max_forks_repo_head_hexsha": "8d03e1ad073becb0161b0377b630d7b65fe3c290", "max_forks_repo_licenses": ["MIT", "Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-02-14T03:51:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:51:49.000Z", "avg_line_length": 22.9333333333, "max_line_length": 69, "alphanum_fraction": 0.5825581395, "num_tokens": 692, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172659321807, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7844810993947985}} {"text": "PROGRAM LU\n ! This program demonstrates LU factorization (actually just Gaussian \n ! Elimination) by solving the following equation system:\n ! \n ! | 2 1 -1 | | 8 |\n ! | -3 -1 2 | X = | -11 |\n ! | -2 1 2 | | -3 |\n !\n ! The solution to this equation is:\n !\n ! | 2 |\n ! X = | 3 |\n ! | -1 |\n\n IMPLICIT NONE\n INCLUDE 'mpif.h'\n\n ! Configuration variables\n INTEGER, PARAMETER :: n = 3\n REAL, DIMENSION(n,n) :: a = &\n RESHAPE ( (/ 2, -3, -2, 1, -1, 1, -1, 2, 2 /), (/3,3/) )\n REAl, DIMENSION(n) :: b = (/ 8, -11, -3 /)\n\n ! MPI variables\n INTEGER :: nprocs\n INTEGER :: myrank\n INTEGER :: ierr\n INTEGER, DIMENSION(n) :: map ! column to process\n\n ! Count and temporary variables\n INTEGER :: i, ii, j, k, offset\n REAL :: s, ss\n\n ! Initialize MPI\n CALL MPI_INIT(ierr)\n CALL MPI_COMM_SIZE(MPI_COMM_WORLD, nprocs, ierr)\n CALL MPI_COMM_RANK(MPI_COMM_WORLD, myrank, ierr)\n\n ! Assign the column in a to the processes in a cylic manner\n DO i = 0, n\n map(i+1) = MOD(i, nprocs)\n ENDDO\n\n ! LU factorization\n DO k = 1, n\n IF (map(k) == myrank) THEN\n DO i = k+1, n\n a(i,k) = a(i,k) / a(k,k)\n ENDDO\n ENDIF\n CALL MPI_BCAST(a(k,k), n-k+1, MPI_REAL, map(k), MPI_COMM_WORLD, ierr)\n DO j = k+1, n\n IF (map(j) == myrank) THEN\n DO i = k+1, n\n a(i,j) = a(i,j) - a(i,k) * a(k,j)\n ENDDO\n ENDIF\n ENDDO\n ENDDO\n\n ! Forward elimination\n DO i = 2, n\n s = 0.0\n ! Process 0 owns column 1, process 1 owns column 2, etc. \n DO j = 1 + myrank, i - 1, nprocs\n s = s + a(i,j) * b(j)\n ENDDO\n CALL MPI_ALLREDUCE(s, ss, 1, MPI_REAL, MPI_SUM, MPI_COMM_WORLD, ierr)\n b(i) = b(i) - ss\n ENDDO\n\n ! Backward substitution\n DO i = n, 1, -1\n ! Starting from column i+1, find the first column that this process owns\n offset = myrank - map(i+1)\n IF (offset < 0) THEN\n offset = offset + nprocs\n ENDIF\n ii = i + 1 + offset\n\n s = 0.0\n DO j = ii, n, nprocs\n s = s + a(i, j) * b(j)\n ENDDO\n CALL MPI_ALLREDUCE(s, ss, 1, MPI_REAL, MPI_SUM, MPI_COMM_WORLD, ierr)\n b(i) = (b(i) - ss) / a(i,i)\n ENDDO\n\n IF (myrank == 0) write (*,*) \"x = (\", b, \")\"\n\n CALL MPI_Finalize(ierr)\nEND PROGRAM LU\n", "meta": {"hexsha": "b1adc1cc7de4f1d0c0d85a0e54e08b6dd367187b", "size": 2280, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/omp/apps/mpi/ex3/lu.f90", "max_stars_repo_name": "tianyi93/hpxMP_mirror", "max_stars_repo_head_hexsha": "668e8881a6f2f437a614ae92e205ae49f083691e", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2018-07-16T14:39:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-08T11:25:09.000Z", "max_issues_repo_path": "examples/omp/apps/mpi/ex3/lu.f90", "max_issues_repo_name": "tianyi93/hpxMP_mirror", "max_issues_repo_head_hexsha": "668e8881a6f2f437a614ae92e205ae49f083691e", "max_issues_repo_licenses": ["BSL-1.0"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2018-06-18T14:59:09.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-16T20:43:57.000Z", "max_forks_repo_path": "examples/omp/apps/mpi/ex3/lu.f90", "max_forks_repo_name": "tianyi93/hpxMP_mirror", "max_forks_repo_head_hexsha": "668e8881a6f2f437a614ae92e205ae49f083691e", "max_forks_repo_licenses": ["BSL-1.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2018-06-22T18:44:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-21T11:17:28.000Z", "avg_line_length": 24.5161290323, "max_line_length": 76, "alphanum_fraction": 0.5320175439, "num_tokens": 850, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436483, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7844693458868864}} {"text": "subroutine sieve(is_prime, n_max)\n! =====================================================\n! Uses the sieve of Eratosthenes to compute a logical\n! array of size n_max, where .true. in element i\n! indicates that i is a prime.\n! =====================================================\n integer, intent(in) :: n_max\n logical, intent(out) :: is_prime(n_max)\n integer :: i\n is_prime = .true.\n is_prime(1) = .false.\n do i = 2, int(sqrt(real(n_max)))\n if (is_prime (i)) is_prime (i * i : n_max : i) = .false.\n end do\n return\nend subroutine\n\nsubroutine logical_to_integer(prime_numbers, is_prime, num_primes, n)\n! =====================================================\n! Translates the logical array from sieve to an array\n! of size num_primes of prime numbers.\n! =====================================================\n integer :: i, j=0\n integer, intent(in) :: n\n logical, intent(in) :: is_prime(n)\n integer, intent(in) :: num_primes\n integer, intent(out) :: prime_numbers(num_primes)\n do i = 1, size(is_prime)\n if (is_prime(i)) then\n j = j + 1\n prime_numbers(j) = i\n end if\n end do\nend subroutine\n", "meta": {"hexsha": "6a75ba561741735675e0984e88a74e0a870452dc", "size": 1208, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "dev/primes.f95", "max_stars_repo_name": "banskt/fpydemo", "max_stars_repo_head_hexsha": "786802ea280afb9945772f656da9d139b431b2ac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "dev/primes.f95", "max_issues_repo_name": "banskt/fpydemo", "max_issues_repo_head_hexsha": "786802ea280afb9945772f656da9d139b431b2ac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dev/primes.f95", "max_forks_repo_name": "banskt/fpydemo", "max_forks_repo_head_hexsha": "786802ea280afb9945772f656da9d139b431b2ac", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-02-03T05:40:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-03T05:40:24.000Z", "avg_line_length": 34.5142857143, "max_line_length": 69, "alphanum_fraction": 0.5016556291, "num_tokens": 297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.8596637505099167, "lm_q1q2_score": 0.7843882877225872}} {"text": "!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!\n!   Futility Development Group    !\n!              All rights reserved.           !\n!                         !\n! Futility is a jointly-maintained, open-source project between the University !\n! of Michigan and Oak Ridge National Laboratory.  The copyright and license !\n! can be found in LICENSE.txt in the head directory of this repository.   !\n!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!\n!> @brief The global module for collecting all public members of\n!> extended math routines.\n!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!\nMODULE ExtendedMath\n\nUSE IntrType\nUSE Constants_Conversion\nIMPLICIT NONE\nPRIVATE\n\nPUBLIC :: GAMMAF\nPUBLIC :: Rational_Fraction\nPUBLIC :: GreatestCommonDivisor\nPUBLIC :: LeastCommonMultiple\nPUBLIC :: ATAN2PI\n\nINTERFACE LeastCommonMultiple\n MODULE PROCEDURE LeastCommonMultiple_scalar\n MODULE PROCEDURE LeastCommonMultiple_A1\nENDINTERFACE LeastCommonMultiple\n\nCONTAINS\n!\n!-------------------------------------------------------------------------------\n!> @brief Computes the GAMMA function\n!> @param z a double precision real to compute the value of gamma for\n!> @returns g the value of the GAMMA function at z\n!>\n!> This routine uses the Lanczos approximation to compute the gamma function\n!> The coefficients @c p are the coefficients used by the GNU Scientific\n!> Library. It is a double precision function and should be accurate to 15\n!> digits of precision. It agrees with the intrinsic function supplied by the\n!> Intel compiler.\n!>\n PURE RECURSIVE FUNCTION GAMMAF(z) RESULT(g)\n INTEGER(SIK),PARAMETER :: cg=7\n REAL(SDK),DIMENSION(0:8),PARAMETER :: p=(/0.99999999999980993_SDK, &\n 676.5203681218851_SDK,-1259.1392167224028_SDK,771.32342877765313_SDK, &\n -176.61502916214059_SDK,12.507343278686905_SDK, &\n -0.13857109526572012_SDK,9.9843695780195716e-6_SDK, &\n 1.5056327351493116e-7_SDK/)\n REAL(SDK),INTENT(IN) :: z\n REAL(SDK) :: g\n INTEGER(SIK) :: i\n REAL(SDK) :: t,w,x\n\n x=z\n IF(x < 0.5_SDK) THEN\n g=PI/(SIN(PI*x)*GAMMAF(1.0_SDK-x))\n ELSE\n x=x-1.0_SDK\n t=p(0)\n DO i=1,cg+1\n t=t+p(i)/(x+REAL(i,SDK))\n ENDDO\n w=x+REAL(cg,SDK)+0.5_SDK\n g=SQRT(2.0_SDK*PI)*(w**(x+0.5_SDK))*EXP(-w)*t\n ENDIF\n ENDFUNCTION GAMMAF\n!\n!-------------------------------------------------------------------------------\n!> @brief Computes a Rational Fraction less than a tolerance\n!> @param targval a real which is the target value of the rational fraction\n!> @param tol a real which is the tolerance for the rational fraction\n!> @param num an integer which is the numerator of the rational fraction\n!> @param denom an integer which is the denomenator of the rational fraction\n!>\n!> This routine calculates the rational fractions of a target value until the\n!> fraction is less than a tolererance from the original value. The rational\n!> fraction calculation will stop after 50 iterations, which is an arbitrary\n!> value that could easily be extended if tighter accuracy is required. The\n!> coeffiecients are stored such that:\n!> approx = c(0) + 1 / (c(1) + 1 / (c(2) + 1 / (c(3) +...)))\n!>\nSUBROUTINE Rational_Fraction(targval,tol,num,denom)\n REAL(SRK),INTENT(IN) :: targval\n REAL(SRK),INTENT(IN) :: tol\n INTEGER(SIK),INTENT(OUT) :: num\n INTEGER(SIK),INTENT(OUT) :: denom\n\n INTEGER(SIK) :: lev\n INTEGER(SIK) :: coef(50)\n REAL(SRK) :: targ\n\n coef=0\n\n targ=targval\n\n coef(1)=FLOOR(targ)\n targ=1.0_SRK/(targ-REAL(coef(1),SRK))\n DO lev=2,SIZE(coef)\n coef(lev)=FLOOR(targ)\n targ=1.0_SRK/(targ-REAL(coef(lev),SRK))\n num=coef(lev)\n denom=1\n CALL simplify_rat_frac(coef,lev,num,denom)\n IF(ABS(REAL(num,SRK)/REAL(denom,SRK)/targval-1.0_SRK) < tol) EXIT\n ENDDO\nENDSUBROUTINE Rational_Fraction\n!\n!-------------------------------------------------------------------------------\n!> @brief Simplifies the rational fraction to a simple fraction\n!> @param coef rational fraction coefficients in extended form\n!> @param lev the index of coef of the maximum non-zero location\n!> @param num an integer which is the numerator of the rational fraction\n!> @param denom an integer which is the denomenator of the rational fraction\n!>\n!> This routine takes the exapanded coefficients of the rational fraction and\n!> simplifies it to a single fraction:\n!> num / denom = c(0) + 1 / (c(1) + 1 / (c(2) + 1 / (c(3) +...)))\n!>\nRECURSIVE SUBROUTINE simplify_rat_frac(coef,lev,num,denom)\n INTEGER(SIK),INTENT(IN) :: coef(*)\n INTEGER(SIK),INTENT(IN) :: lev\n INTEGER(SIK),INTENT(INOUT) :: num\n INTEGER(SIK),INTENT(INOUT) :: denom\n\n INTEGER(SIK) :: tmpnum\n\n tmpnum=num\n num=coef(lev-1)*num+denom\n denom=tmpnum\n IF(lev > 2) THEN\n CALL simplify_rat_frac(coef,lev-1,num,denom)\n ENDIF\nENDSUBROUTINE simplify_rat_frac\n!\n!-------------------------------------------------------------------------------\n!> @brief Calculates the Greatest Common Divisor\n!> @param a1 an integer\n!> @param a2 an integer\n!> @returns b the greatest common divisor of a1 and a2\n!>\n!> This routine uses the Euclidean method to calculate the greatest common\n!> divisor between two positive numbers. If a negative number is input, the\n!> resulting value is 0.\n!>\nELEMENTAL FUNCTION GreatestCommonDivisor(a1,a2) RESULT(b)\n INTEGER(SIK),INTENT(IN) :: a1\n INTEGER(SIK),INTENT(IN) :: a2\n\n INTEGER(SIK) :: a,b,c\n\n a=0; b=0; c=0\n\n IF(a1 > 0 .AND. a2 > 0) THEN\n IF(a1 < a2) THEN\n a=a2\n b=a1\n ELSE\n a=a1\n b=a2\n ENDIF\n\n DO\n c=MOD(a,b)\n IF(c == 0) EXIT\n a=b\n b=c\n ENDDO\n ENDIF\nENDFUNCTION GreatestCommonDivisor\n!\n!-------------------------------------------------------------------------------\n!> @brief solves for the least common multiple of an array of integers\n!> @param u the array of integers to consider\n!> @returns lcm the least common multiple of the array\n!>\nPURE FUNCTION LeastCommonMultiple_A1(u) RESULT(lcm)\n INTEGER(SIK),INTENT(IN) :: u(:)\n\n INTEGER(SIK) :: lcm\n INTEGER(SIK) :: i\n\n lcm = 0\n IF(SIZE(u) == 0) RETURN\n IF(ANY(u == 0)) RETURN\n\n lcm = abs(u(1))\n DO i=2,SIZE(u)\n !In all likelihood there exists an 'a' and 'b' which will cause overflow\n lcm = LeastCommonMultiple(lcm,u(i))\n ENDDO\n\nENDFUNCTION LeastCommonMultiple_A1\n!\n!-------------------------------------------------------------------------------\n!> @brief solves for the least common multiple of a pair of integers\n!> @param u the first integer to consider\n!> @param v the second integer to consider\n!> @returns lcm the least common multiple of the array\n!>\nELEMENTAL FUNCTION LeastCommonMultiple_scalar(u,v) RESULT(lcm)\n INTEGER(SIK),INTENT(IN) :: u\n INTEGER(SIK),INTENT(IN) :: v\n\n INTEGER(SIK) :: lcm\n INTEGER(SIK) :: a,b\n\n lcm = 0\n IF(u == 0 .OR. v == 0) RETURN\n a = ABS(u)\n b = ABS(v)\n\n IF(a == b) THEN\n lcm = a\n ELSE\n !In all likelihood there exists an 'a' and 'b' which will cause overflow\n lcm = (a/GreatestCommonDivisor(a,b)) * b\n ENDIF\nENDFUNCTION LeastCommonMultiple_scalar\n!\n!-------------------------------------------------------------------------------\n!> @brief Calculates the angle from the origin to (x,y) from the +(x-axis) on\n!> [0,2pi)\n!> @param x the x-coordinate\n!> @param y the y-coordinate\n!> @returns theta the angle formed by the point (x,y) w.r.t. the positive x-axis\n!> on [0,2PI)\n!>\n!> This routine calls ATAN2 and casts the result to exist on [0,2pi). It is\n!> useful, since we often need to sort points by angle in the entire unit circle\n!> and the discontinuity at pi that is generated by the native ATAN2 function is\n!> inconvenient.\n!>\nELEMENTAL FUNCTION ATAN2PI(x,y) RESULT(theta)\n REAL(SRK),INTENT(IN) :: x\n REAL(SRK),INTENT(IN) :: y\n REAL(SRK) :: theta,xx,yy\n xx=x\n IF(x .APPROXEQA. 0.0_SRK) xx=0.0_SRK\n yy=y\n IF(y .APPROXEQA. 0.0_SRK) yy=0.0_SRK\n theta=ATAN2(yy,xx)\n IF(.NOT.(theta .APPROXGE. 0.0_SRK)) theta=TWOPI+theta\nENDFUNCTION ATAN2PI\n!\nENDMODULE ExtendedMath\n", "meta": {"hexsha": "ee8025cc848f1c7947da8f43b5a9bdd6a817beb6", "size": 8163, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ExtendedMath.f90", "max_stars_repo_name": "wgurecky/Futility", "max_stars_repo_head_hexsha": "cd7831395c7c56adcbbc5be38773d2e850c6b5b6", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/ExtendedMath.f90", "max_issues_repo_name": "wgurecky/Futility", "max_issues_repo_head_hexsha": "cd7831395c7c56adcbbc5be38773d2e850c6b5b6", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-22T20:53:29.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-22T20:53:29.000Z", "max_forks_repo_path": "src/ExtendedMath.f90", "max_forks_repo_name": "wgurecky/Futility", "max_forks_repo_head_hexsha": "cd7831395c7c56adcbbc5be38773d2e850c6b5b6", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.048582996, "max_line_length": 80, "alphanum_fraction": 0.6106823472, "num_tokens": 2359, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7843502118416088}} {"text": " MODULE stel_constants\n\n USE stel_kinds\n\n!----------------------------------------------------------------------\n! Mathematical constants\n!----------------------------------------------------------------------\n\n REAL(rprec), PARAMETER :: pi=3.14159265358979323846264338328_rprec\n REAL(rprec), PARAMETER :: pio2=1.570796326794896619231321691_rprec\n REAL(rprec), PARAMETER :: twopi=6.28318530717958647692528677_rprec\n REAL(rprec), PARAMETER :: sqrt2=1.41421356237309504880168872_rprec\n REAL(rprec), PARAMETER :: degree = twopi / 360\n REAL(rprec), PARAMETER :: one = 1.0_rprec\n REAL(rprec), PARAMETER :: zero = 0.0_rprec\n \n!----------------------------------------------------------------------\n! Physical constants\n!------------------------------------------------------------------\n\n REAL(rprec), PARAMETER :: mu0 = 2 * twopi * 1.0e-7_rprec\n\n END MODULE stel_constants\n", "meta": {"hexsha": "980c3827c7b45af47e8448326c34f1132351b2c9", "size": 925, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "LIBSTELL/Sources/Modules/stel_constants.f", "max_stars_repo_name": "jonathanschilling/VMEC_8_00", "max_stars_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "LIBSTELL/Sources/Modules/stel_constants.f", "max_issues_repo_name": "jonathanschilling/VMEC_8_00", "max_issues_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LIBSTELL/Sources/Modules/stel_constants.f", "max_forks_repo_name": "jonathanschilling/VMEC_8_00", "max_forks_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.5416666667, "max_line_length": 72, "alphanum_fraction": 0.4821621622, "num_tokens": 218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075701109193, "lm_q2_score": 0.8152324983301568, "lm_q1q2_score": 0.7843413580438812}} {"text": "\nsubmodule(forlab_linalg) forlab_linalg_inv\n\n implicit none\n\ncontains\n\n module procedure inv_rsp\n !! inv0 computes the real matrix inverse.\n integer :: i, j, k, m\n real(sp) :: D\n real(sp), dimension(:), allocatable :: x, y, e\n real(sp), dimension(:, :), allocatable :: L, U\n\n if (is_square(A)) then\n m = size(A, 1)\n if (m .le. 3) then\n D = det(A)\n else\n D = det(A, L, U)\n end if\n if (D .ne. 0._sp) then\n inv = zeros(m, m)\n if (m .eq. 2) then\n inv(1, 1) = A(2, 2)\n inv(1, 2) = -A(1, 2)\n inv(2, 1) = -A(2, 1)\n inv(2, 2) = A(1, 1)\n inv = inv/D\n elseif (m .eq. 3) then\n inv(1, 1) = A(2, 2)*A(3, 3) - A(2, 3)*A(3, 2)\n inv(1, 2) = A(1, 3)*A(3, 2) - A(1, 2)*A(3, 3)\n inv(1, 3) = A(1, 2)*A(2, 3) - A(1, 3)*A(2, 2)\n inv(2, 1) = A(2, 3)*A(3, 1) - A(2, 1)*A(3, 3)\n inv(2, 2) = A(1, 1)*A(3, 3) - A(1, 3)*A(3, 1)\n inv(2, 3) = A(1, 3)*A(2, 1) - A(1, 1)*A(2, 3)\n inv(3, 1) = A(2, 1)*A(3, 2) - A(2, 2)*A(3, 1)\n inv(3, 2) = A(1, 2)*A(3, 1) - A(1, 1)*A(3, 2)\n inv(3, 3) = A(1, 1)*A(2, 2) - A(1, 2)*A(2, 1)\n inv = inv/D\n else\n do k = 1, m\n x = zeros(m)\n y = zeros(m)\n e = zeros(m)\n e(k) = 1.\n y(1) = e(1)\n\n ! Forward substitution: Ly = e\n !==============================\n do i = 2, m\n y(i) = e(i)\n do j = 1, i - 1\n y(i) = y(i) - y(j)*L(i, j)\n end do\n end do\n\n ! Back substitution: Ux = y\n !===========================\n x(m) = y(m)/U(m, m)\n do i = m - 1, 1, -1\n x(i) = y(i)\n do j = m, i + 1, -1\n x(i) = x(i) - x(j)*U(i, j)\n end do\n x(i) = x(i)/U(i, i)\n end do\n\n ! The column k of the inverse is x\n !==================================\n inv(:, k) = x\n end do\n end if\n else\n call error_stop(\"Error: in det(A), A is not inversible (= 0).\")\n end if\n else\n call error_stop(\"Error: in inv(A), A should be square.\")\n end if\n return\n end procedure\n module procedure inv_rdp\n !! inv0 computes the real matrix inverse.\n integer :: i, j, k, m\n real(dp) :: D\n real(dp), dimension(:), allocatable :: x, y, e\n real(dp), dimension(:, :), allocatable :: L, U\n\n if (is_square(A)) then\n m = size(A, 1)\n if (m .le. 3) then\n D = det(A)\n else\n D = det(A, L, U)\n end if\n if (D .ne. 0._dp) then\n inv = zeros(m, m)\n if (m .eq. 2) then\n inv(1, 1) = A(2, 2)\n inv(1, 2) = -A(1, 2)\n inv(2, 1) = -A(2, 1)\n inv(2, 2) = A(1, 1)\n inv = inv/D\n elseif (m .eq. 3) then\n inv(1, 1) = A(2, 2)*A(3, 3) - A(2, 3)*A(3, 2)\n inv(1, 2) = A(1, 3)*A(3, 2) - A(1, 2)*A(3, 3)\n inv(1, 3) = A(1, 2)*A(2, 3) - A(1, 3)*A(2, 2)\n inv(2, 1) = A(2, 3)*A(3, 1) - A(2, 1)*A(3, 3)\n inv(2, 2) = A(1, 1)*A(3, 3) - A(1, 3)*A(3, 1)\n inv(2, 3) = A(1, 3)*A(2, 1) - A(1, 1)*A(2, 3)\n inv(3, 1) = A(2, 1)*A(3, 2) - A(2, 2)*A(3, 1)\n inv(3, 2) = A(1, 2)*A(3, 1) - A(1, 1)*A(3, 2)\n inv(3, 3) = A(1, 1)*A(2, 2) - A(1, 2)*A(2, 1)\n inv = inv/D\n else\n do k = 1, m\n x = zeros(m)\n y = zeros(m)\n e = zeros(m)\n e(k) = 1.\n y(1) = e(1)\n\n ! Forward substitution: Ly = e\n !==============================\n do i = 2, m\n y(i) = e(i)\n do j = 1, i - 1\n y(i) = y(i) - y(j)*L(i, j)\n end do\n end do\n\n ! Back substitution: Ux = y\n !===========================\n x(m) = y(m)/U(m, m)\n do i = m - 1, 1, -1\n x(i) = y(i)\n do j = m, i + 1, -1\n x(i) = x(i) - x(j)*U(i, j)\n end do\n x(i) = x(i)/U(i, i)\n end do\n\n ! The column k of the inverse is x\n !==================================\n inv(:, k) = x\n end do\n end if\n else\n call error_stop(\"Error: in det(A), A is not inversible (= 0).\")\n end if\n else\n call error_stop(\"Error: in inv(A), A should be square.\")\n end if\n return\n end procedure\n\n module procedure inv_csp\n !! inv computes the complex matrix inverse.\n real(sp), dimension(:, :), allocatable :: ar, ai\n !! AR stores the real part, AI stores the imaginary part\n integer :: flag, n\n real(sp) :: d, p, t, q, s, b\n integer, dimension(:), allocatable :: is, js\n integer :: i, j, k\n\n if (is_square(A)) then\n n = size(A, 1)\n inv = zeros(n, n)\n ar = zeros(n, n)\n ai = zeros(n, n)\n\n is = ones(n)\n js = ones(n)\n\n forall (i=1:n, j=1:n)\n ar(i, j) = real(A(i, j)); ai(i, j) = imag(A(i, j))\n end forall\n flag = 1\n do k = 1, n\n d = 0.0\n do i = k, n\n do j = k, n\n p = ar(i, j)*ar(i, j) + ai(i, j)*ai(i, j)\n if (p .gt. d) then\n d = p\n is(k) = i\n js(k) = j\n end if\n end do\n end do\n if (d + 1.0_sp .eq. 1.0_sp) then\n flag = 0\n call error_stop('ERROR: A is not inversible (= 0)')\n end if\n do j = 1, n\n t = ar(k, j)\n ar(k, j) = ar(is(k), j)\n ar(is(k), j) = t\n t = ai(k, j)\n ai(k, j) = ai(is(k), j)\n ai(is(k), j) = t\n end do\n do i = 1, n\n t = ar(i, k)\n ar(i, k) = ar(i, js(k))\n ar(i, js(k)) = t\n t = ai(i, k)\n ai(i, k) = ai(i, js(k))\n ai(i, js(k)) = t\n end do\n ar(k, k) = ar(k, k)/d\n ai(k, k) = -ai(k, k)/d\n do j = 1, n\n if (j .ne. k) then\n p = ar(k, j)*ar(k, k)\n q = ai(k, j)*ai(k, k)\n s = (ar(k, j) + ai(k, j))*(ar(k, k) + ai(k, k))\n ar(k, j) = p - q\n ai(k, j) = s - p - q\n end if\n end do\n do i = 1, n\n if (i .ne. k) then\n do j = 1, n\n if (j .ne. k) then\n p = ar(k, j)*ar(i, k)\n q = ai(k, j)*ai(i, k)\n s = (ar(k, j) + ai(k, j))*(ar(i, k) + ai(i, k))\n t = p - q\n b = s - p - q\n ar(i, j) = ar(i, j) - t\n ai(i, j) = ai(i, j) - b\n end if\n end do\n end if\n end do\n do i = 1, n\n if (i .ne. k) then\n p = ar(i, k)*ar(k, k)\n q = ai(i, k)*ai(k, k)\n s = (ar(i, k) + ai(i, k))*(ar(k, k) + ai(k, k))\n ar(i, k) = q - p\n ai(i, k) = p + q - s\n end if\n end do\n end do\n do k = n, 1, -1\n do j = 1, n\n t = ar(k, j)\n ar(k, j) = ar(js(k), j)\n ar(js(k), j) = t\n t = ai(k, j)\n ai(k, j) = ai(js(k), j)\n ai(js(k), j) = t\n end do\n do i = 1, n\n t = ar(i, k)\n ar(i, k) = ar(i, is(k))\n ar(i, is(k)) = t\n t = ai(i, k)\n ai(i, k) = ai(i, is(k))\n ai(i, is(k)) = t\n end do\n end do\n forall (i=1:n, j=1:n)\n inv(i, j) = cmplx(ar(i, j), ai(i, j), sp)\n end forall\n else\n call error_stop('Error: in inv(A), A should be square.')\n end if\n return\n end procedure inv_csp\n module procedure inv_cdp\n !! inv computes the complex matrix inverse.\n real(dp), dimension(:, :), allocatable :: ar, ai\n !! AR stores the real part, AI stores the imaginary part\n integer :: flag, n\n real(dp) :: d, p, t, q, s, b\n integer, dimension(:), allocatable :: is, js\n integer :: i, j, k\n\n if (is_square(A)) then\n n = size(A, 1)\n inv = zeros(n, n)\n ar = zeros(n, n)\n ai = zeros(n, n)\n\n is = ones(n)\n js = ones(n)\n\n forall (i=1:n, j=1:n)\n ar(i, j) = real(A(i, j)); ai(i, j) = imag(A(i, j))\n end forall\n flag = 1\n do k = 1, n\n d = 0.0\n do i = k, n\n do j = k, n\n p = ar(i, j)*ar(i, j) + ai(i, j)*ai(i, j)\n if (p .gt. d) then\n d = p\n is(k) = i\n js(k) = j\n end if\n end do\n end do\n if (d + 1.0_dp .eq. 1.0_dp) then\n flag = 0\n call error_stop('ERROR: A is not inversible (= 0)')\n end if\n do j = 1, n\n t = ar(k, j)\n ar(k, j) = ar(is(k), j)\n ar(is(k), j) = t\n t = ai(k, j)\n ai(k, j) = ai(is(k), j)\n ai(is(k), j) = t\n end do\n do i = 1, n\n t = ar(i, k)\n ar(i, k) = ar(i, js(k))\n ar(i, js(k)) = t\n t = ai(i, k)\n ai(i, k) = ai(i, js(k))\n ai(i, js(k)) = t\n end do\n ar(k, k) = ar(k, k)/d\n ai(k, k) = -ai(k, k)/d\n do j = 1, n\n if (j .ne. k) then\n p = ar(k, j)*ar(k, k)\n q = ai(k, j)*ai(k, k)\n s = (ar(k, j) + ai(k, j))*(ar(k, k) + ai(k, k))\n ar(k, j) = p - q\n ai(k, j) = s - p - q\n end if\n end do\n do i = 1, n\n if (i .ne. k) then\n do j = 1, n\n if (j .ne. k) then\n p = ar(k, j)*ar(i, k)\n q = ai(k, j)*ai(i, k)\n s = (ar(k, j) + ai(k, j))*(ar(i, k) + ai(i, k))\n t = p - q\n b = s - p - q\n ar(i, j) = ar(i, j) - t\n ai(i, j) = ai(i, j) - b\n end if\n end do\n end if\n end do\n do i = 1, n\n if (i .ne. k) then\n p = ar(i, k)*ar(k, k)\n q = ai(i, k)*ai(k, k)\n s = (ar(i, k) + ai(i, k))*(ar(k, k) + ai(k, k))\n ar(i, k) = q - p\n ai(i, k) = p + q - s\n end if\n end do\n end do\n do k = n, 1, -1\n do j = 1, n\n t = ar(k, j)\n ar(k, j) = ar(js(k), j)\n ar(js(k), j) = t\n t = ai(k, j)\n ai(k, j) = ai(js(k), j)\n ai(js(k), j) = t\n end do\n do i = 1, n\n t = ar(i, k)\n ar(i, k) = ar(i, is(k))\n ar(i, is(k)) = t\n t = ai(i, k)\n ai(i, k) = ai(i, is(k))\n ai(i, is(k)) = t\n end do\n end do\n forall (i=1:n, j=1:n)\n inv(i, j) = cmplx(ar(i, j), ai(i, j), dp)\n end forall\n else\n call error_stop('Error: in inv(A), A should be square.')\n end if\n return\n end procedure inv_cdp\n\nend submodule forlab_linalg_inv\n", "meta": {"hexsha": "7045c47122576b369741a066894115f6d1c07c32", "size": 12800, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_linalg_inv.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "src/forlab_linalg_inv.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "src/forlab_linalg_inv.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 32.73657289, "max_line_length": 75, "alphanum_fraction": 0.29015625, "num_tokens": 4051, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660976007597, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.7843405500992475}} {"text": "\tsubroutine estimate_ksat(perc_clay,esti_ksat)\n\n!!\tThis subroutine calculates ksat value for a soil layer\n!!\tgiven the % of clay in the soil layer\n\n!!\tBackground: Published work of Walter Rawls- calculated \n!!\tksat values based on soil texture (sand,silt and clay)\n!!\tidea: there exists a relationship between % clay and Ksat\n!!\tEquations used in this subroutine are based on the above\n!!\tidea (Jimmy willimas). \n\n!!\tNK June 28,2006\t\n\n\timplicit none\n\n\tinteger::i,eof\n\treal::esti_ksat,perc_clay,xc,exksat\n\texksat=5.0\n\n!\tprint *,\"Enter the % clay in the soil layer\"\n!\tread *,perc_clay\n\n\txc=100.0-perc_clay\n\testi_ksat=12.7*xc/(xc+exp(11.45-0.097*xc))+1.0\n\n!\tprint *,\"The estimated ksat value is \",min(esti_ksat,exksat)\n\n\treturn\n\n\tend subroutine estimate_ksat", "meta": {"hexsha": "a52f6d8fdea5390252229ec330414f434c11f4ed", "size": 756, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "modified_source_code/estimate_ksat.f", "max_stars_repo_name": "gpignotti/swat_soil_moisture_sensitivity", "max_stars_repo_head_hexsha": "d2c3f6185acabf31440d613651192cdaabfe6b6c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "modified_source_code/estimate_ksat.f", "max_issues_repo_name": "gpignotti/swat_soil_moisture_sensitivity", "max_issues_repo_head_hexsha": "d2c3f6185acabf31440d613651192cdaabfe6b6c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-07-02T19:37:29.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-02T19:37:29.000Z", "max_forks_repo_path": "modified_source_code/estimate_ksat.f", "max_forks_repo_name": "gpignotti/swat_soil_moisture_sensitivity", "max_forks_repo_head_hexsha": "d2c3f6185acabf31440d613651192cdaabfe6b6c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.2, "max_line_length": 62, "alphanum_fraction": 0.7341269841, "num_tokens": 245, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342061815148, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7843380105551597}} {"text": "module euler_utils_m\n use iso_fortran_env, only: int64, real32, real64\n implicit none\n private\n\n integer, parameter, public :: sp = real32, dp = real64\n real(sp), parameter, public :: tiny_sp = tiny(0._sp)\n real(dp), parameter, public :: tiny_dp = tiny(0._dp)\n\n public :: unit_digit, swap, digs_of_int, is_pandigital\n public :: fibonacci, reverse, is_palindromic, gcd, lcm, factorial\n public :: int_2_arr, arr_2_int, append, next_permutation\n\n !> A generic interface that returns the unit digit of an integer.\n !>\n !>### Usage\n !>```fortran\n !>program main\n !> use euler_utils_m\n !> implicit none\n !>\n !> print *, unit_digit(324) ! 4\n !> print *, unit_digit(543212345_int64) ! 5\n !>end program main\n !>```\n interface unit_digit\n module procedure unit_digit_int32\n module procedure unit_digit_int64\n end interface unit_digit\n\n !> A generic interface that swap two elements (the two elements\n !> have to be the same type. When swapping two character types,\n !> the two character variables must have the same length.).\n !>\n !>### Usage\n !>```fortran\n !>program main\n !> use euler_utils_m\n !> implicit none\n !>\n !> integer :: a, b\n !> a = 32; b = 23\n !> print *, a, b ! 32, 23\n !> call swap(a, b)\n !> print *, a, b ! 23, 32\n !>end program main\n !>```\n interface swap\n module procedure swap_sp, swap_dp\n module procedure swap_int32, swap_int64\n module procedure swap_equal_len_char\n end interface swap\n\n !> A generic interface that returns the length of an integer.\n !>\n !>### Usage\n !>```fortran\n !>program main\n !> user euler_utils_m\n !> implicit none\n !>\n !> print *, digs_of_int(12345) ! 5\n !> print *, digs_of_int(1234567890_int64) ! 10\n !>end program main\n !>```\n interface digs_of_int\n module procedure digs_of_int_int32\n module procedure digs_of_int_int64\n end interface digs_of_int\n\n !> A generic interface that returns the nth fibonacci number.\n !>\n !>### Usage\n !>```fortran\n !>program main\n !> use euler_utils_m\n !> implicit none\n !>\n !> print *, fibonacci(12) ! 144\n !> print *, fibonacci(12_int64) ! 144\n !>end program main\n !>```\n interface fibonacci\n module procedure fib32, fib64\n end interface fibonacci\n\n !> A generic interface that reverse the digits of an integer.\n !>\n !>### Usage\n !>```fortran\n !>program main\n !> use euler_utils_m\n !> implicit none\n !>\n !> print *, reverse(12345) ! 54321\n !> print *, reverse(12345_int64) ! 54321\n !>end program main\n !>```\n interface reverse\n module procedure reverse_int32, reverse_int64\n end interface reverse\n\n !> A generic interface that tells if an integer is a palindromic integer.\n !>\n !>### Usage\n !>```fortran\n !>program main\n !> use euler_utils_m\n !> implicit none\n !>\n !> integer :: a = 123454321, b = 1234\n !> print *, is_palindromic(a) ! T\n !> print *, is_palindromic(b) ! F\n !>end program main\n !>```\n interface is_palindromic\n module procedure is_palindromic_int32\n module procedure is_palindromic_int64\n end interface is_palindromic\n\n !> Greatest common divisor.\n !>\n !>### Usage\n !>```fortran\n !>program main\n !> use euler_utils_m\n !> implicit none\n !>\n !> print *, gcd(32, 24) ! 8\n !> print *, gcd(32_int64, 24_int64) ! 8\n !>end program main\n !>```\n interface gcd\n module procedure gcd_int32, gcd_int64\n end interface gcd\n\n !> Least common multiple.\n !>\n !>### Usage\n !>```fortran\n !>program main\n !> use euler_utils_m\n !> implicit none\n !>\n !> print *, lcm(3, 4) ! 12\n !> print *, lcm(3_int64, 4_int64) ! 12\n !>end program main\n !>```\n interface lcm\n module procedure lcm_int32, lcm_int64\n end interface lcm\n\n !> Factorial.\n !>\n !>### Usage\n !>```fortran\n !>program main\n !> use euler_utils_m\n !> implicit none\n !>\n !> print *, factorial(4) ! 24\n !> print *, factorial(4_int64) ! 24\n !>end program main\n !>```\n interface factorial\n module procedure factorial_int32\n module procedure factorial_int64\n end interface factorial\n\n !> To judge whether an integer is a pandigital number.\n !>\n !>### Usage\n !>```fortran\n !>program main\n !> use euler_utils_m\n !> implicit none\n !>\n !> print *, is_pandigital(1023456789) ! T\n !>end program main\n !>```\n interface is_pandigital\n module procedure is_pandigital_int32\n module procedure is_pandigital_int64\n end interface is_pandigital\n\n !> Convert integer to an integer array.\n !>\n !>### Usage\n !>```fortran\n !>program main\n !> use euler_utils_m\n !> implicit none\n !>\n !> integer :: a = 234\n !> integer, allocatable :: arr(:)\n !>\n !> call int_2_arr(a, arr)\n !> print *, arr ! [2, 3, 4]\n !>end program main\n !>```\n interface int_2_arr\n module procedure int_2_arr_int32\n module procedure int_2_arr_int64\n end interface int_2_arr\n\n !> Convert an integer arr to an integer.\n !>\n !>### Usage\n !>```fortran\n !>program main\n !> use euler_utils_m\n !> implicit none\n !>\n !> integer :: arr(3) = [2, 3, 4]\n !> integer :: a\n !>\n !> call arr_2_int(arr, a)\n !> print *, a ! 234\n !>end program main\n !>```\n interface arr_2_int\n module procedure arr_2_int_int32\n module procedure arr_2_int_int64\n end interface arr_2_int\n\n !> Append an element to the end of an array\n !>\n !>### Usage\n !>```fortran\n !>program main\n !> use euler_utils_m\n !> implicit none\n !>\n !> integer, allocatable :: arr(:)\n !>\n !> arr = [1, 2, 3]\n !> call append(arr, 4)\n !> print *, arr ! [1, 2, 3, 4]\n !>end program main\n !>```\n interface append\n module procedure append_sp, append_dp\n module procedure append_int32, append_int64\n end interface append\n\n !> An interface of variant permutation functions\n !>\n !>### Usage\n !>#### `next_permutation_int32/int64` (k-permutation of n)\n !>```fortran\n !>program main\n !> use euler_utils_m\n !> implicit none\n !>\n !> integer :: k, n\n !> integer, dimesion(2) :: arr\n !> logical :: next_permutation_available\n !>\n !> k = 2; n = 3\n !> arr = [1, 2]\n !> next_permutation_available = .true.\n !>\n !> do while (next_permutation_available)\n !> print *, arr\n !> call permutation(k, n, arr, next_permutation_available)\n !> end do\n !> ! Output: (1, 2), (1, 3), and (2, 3).\n !>end program main\n !>```\n !>\n !>#### `next_permutation2_int32` (permutation)\n !>```fortran\n !>program main\n !> use euler_utils_m\n !> implicit none\n !>\n !> integer :: arr(3)\n !> logical :: next_permutation_available\n !>\n !> arr = [1, 2, 3]\n !> next_permutation_available = .true.\n !>\n !> do while (next_permutation_available)\n !> print *, arr\n !> call permutation(arr, next_permutation_available)\n !> end do\n !> ! Output: (1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), \n !> ! (3, 1, 2), and (3, 2, 1).\n !>end program main\n !>```\n interface next_permutation\n module procedure next_permutation_int32\n module procedure next_permutation_int64\n module procedure next_permutation2_int32\n end interface next_permutation\n\ncontains\n\n pure integer function unit_digit_int32(n)\n integer, intent(in) :: n\n unit_digit_int32 = mod(n, 10)\n end function unit_digit_int32\n\n pure integer(int64) function unit_digit_int64(n)\n integer(int64), intent(in) :: n\n unit_digit_int64 = mod(n, 10_int64)\n end function unit_digit_int64\n\n pure subroutine swap_sp(a, b)\n real(sp), intent(inout) :: a, b\n real(sp) :: tmp\n\n tmp = a; a = b; b = tmp\n end subroutine swap_sp\n\n pure subroutine swap_dp(a, b)\n real(dp), intent(inout) :: a, b\n real(dp) :: tmp\n\n tmp = a; a = b; b = tmp\n end subroutine swap_dp\n\n pure subroutine swap_int32(a, b)\n integer, intent(inout) :: a, b\n integer :: tmp\n\n tmp = a; a = b; b = tmp\n end subroutine swap_int32\n\n pure subroutine swap_int64(a, b)\n integer(int64), intent(inout) :: a, b\n integer(int64) :: tmp\n\n tmp = a; a = b; b = tmp\n end subroutine swap_int64\n\n pure subroutine swap_equal_len_char(a, b)\n character(len=*), intent(inout) :: a\n character(len=len(a)), intent(inout) :: b\n character(len=len(a)) :: tmp\n\n tmp = a\n a = b\n b = tmp\n end subroutine swap_equal_len_char\n\n pure integer function digs_of_int_int32(n)\n integer, intent(in) :: n\n\n digs_of_int_int32 = floor(log10(real(n, sp))) + 1\n end function digs_of_int_int32\n\n pure integer(int64) function digs_of_int_int64(n)\n integer(int64), intent(in) :: n\n\n digs_of_int_int64 = floor(log10(real(n, sp))) + 1_int64\n end function digs_of_int_int64\n\n pure recursive function fib32(n) result(ans)\n integer, intent(in) :: n\n integer :: k, ans\n\n if (n < 0 .or. n > 92) then\n error stop \"fib32: Invalid input number.\"\n end if\n\n if (n == 0) then\n ans = 0\n else if (n == 1 .or. n == 2) then\n ans = 1\n else if (mod(n, 2) == 0) then\n k = n/2\n ans = fib32(k)*(fib32(k + 1)*2 - fib32(k))\n else\n k = (n - 1)/2\n ans = fib32(k + 1)**2 + fib32(k)**2\n end if\n end function fib32\n\n pure recursive function fib64(n) result(ans)\n integer(int64), intent(in) :: n\n integer(int64) :: k, ans\n\n if (n < 0_int64 .or. n > 92_int64) then\n error stop \"fib64: Invalid input number.\"\n end if\n\n if (n == 0_int64) then\n ans = 0_int64\n else if (n == 1_int64 .or. n == 2_int64) then\n ans = 1_int64\n else if (mod(n, 2_int64) == 0_int64) then\n k = n/2_int64\n ans = fib64(k)*(fib64(k + 1_int64)*2_int64 - fib64(k))\n else\n k = (n - 1_int64)/2_int64\n ans = fib64(k + 1_int64)**2_int64 + fib64(k)**2_int64\n end if\n end function fib64\n\n pure integer function reverse_int32(n)\n integer, intent(in) :: n\n integer :: reversed, tmp\n\n reversed = 0; tmp = n\n do while (tmp > 0)\n reversed = reversed*10 + mod(tmp, 10)\n tmp = tmp/10\n end do\n reverse_int32 = reversed\n end function reverse_int32\n\n pure integer(int64) function reverse_int64(n)\n integer(int64), intent(in) :: n\n integer(int64) :: reversed, tmp\n reversed = 0_int64; tmp = n\n do while (tmp > 0_int64)\n reversed = reversed*10_int64 + mod(tmp, 10_int64)\n tmp = tmp/10_int64\n end do\n reverse_int64 = reversed\n end function reverse_int64\n\n pure logical function is_palindromic_int32(n)\n integer, intent(in) :: n\n\n is_palindromic_int32 = .false.\n if (n == reverse_int32(n)) then\n is_palindromic_int32 = .true.\n end if\n end function is_palindromic_int32\n\n pure logical function is_palindromic_int64(n)\n integer(int64), intent(in) :: n\n\n is_palindromic_int64 = .false.\n if (n == reverse_int64(n)) then\n is_palindromic_int64 = .true.\n end if\n end function is_palindromic_int64\n\n pure recursive function gcd_int32(n1, n2) result(ans)\n integer, intent(in) :: n1, n2\n integer :: ans\n\n if (n2 == 0) then\n ans = n1\n else\n ans = gcd_int32(n2, mod(n1, n2))\n end if\n end function gcd_int32\n\n pure recursive function gcd_int64(n1, n2) result(ans)\n integer(int64), intent(in) :: n1, n2\n integer(int64) :: ans\n\n if (n2 == 0_int64) then\n ans = n1\n else\n ans = gcd_int64(n2, mod(n1, n2))\n end if\n end function gcd_int64\n\n pure integer function lcm_int32(n1, n2)\n integer, intent(in) :: n1, n2\n\n lcm_int32 = n1*n2/gcd_int32(n1, n2)\n end function lcm_int32\n\n pure integer(int64) function lcm_int64(n1, n2)\n integer(int64), intent(in) :: n1, n2\n\n lcm_int64 = n1*n2/gcd_int64(n1, n2)\n end function lcm_int64\n\n pure integer function factorial_int32(n)\n integer, intent(in) :: n\n integer :: i, tmp\n\n if (n >= 13) then\n error stop \"FACTORIAL_INT32: n >= 13.\"\n end if\n\n tmp = 1\n do i = 1, n\n tmp = tmp*i\n end do\n factorial_int32 = tmp\n end function factorial_int32\n\n pure integer(int64) function factorial_int64(n)\n integer(int64), intent(in) :: n\n integer(int64) :: i, tmp\n\n if (n >= 13_int64) then\n error stop \"FACTORIAL_INT32: n >= 13.\"\n end if\n\n tmp = 1_int64\n do i = 1_int64, n\n tmp = tmp*i\n end do\n factorial_int64 = tmp\n end function factorial_int64\n\n pure logical function is_pandigital_int32(n, digs)\n integer, intent(in) :: n\n integer, intent(in), optional :: digs\n integer :: tmp, j, l\n logical, allocatable :: logic_arr(:)\n\n if (present(digs)) then\n allocate (logic_arr(digs))\n l = digs\n else\n l = 9\n allocate (logic_arr(l))\n end if\n\n is_pandigital_int32 = .false.\n logic_arr = .false.\n tmp = n\n\n do\n j = unit_digit_int32(tmp)\n if (j == 0 .or. j > l) exit\n logic_arr(j) = .true.\n tmp = tmp/10\n end do\n\n if (count(logic_arr) == l) then\n is_pandigital_int32 = .true.\n else\n is_pandigital_int32 = .false.\n end if\n end function is_pandigital_int32\n\n pure logical function is_pandigital_int64(n, digs)\n integer(int64), intent(in) :: n\n integer(int64), intent(in), optional :: digs\n integer(int64) :: tmp, j, l\n logical, allocatable :: logic_arr(:)\n\n if (present(digs)) then\n allocate (logic_arr(digs))\n l = digs\n else\n l = 9_int64\n allocate (logic_arr(l))\n end if\n\n is_pandigital_int64 = .false.\n logic_arr = .false.\n tmp = n\n\n do\n j = unit_digit_int64(tmp)\n if (j == 0_int64 .or. j > l) exit\n logic_arr(j) = .true.\n tmp = tmp/10_int64\n end do\n\n if (count(logic_arr) == l) then\n is_pandigital_int64 = .true.\n else\n is_pandigital_int64 = .false.\n end if\n end function is_pandigital_int64\n\n pure subroutine int_2_arr_int32(n, arr)\n integer, intent(in) :: n\n integer, allocatable, intent(out) :: arr(:)\n integer :: tmp, i, l\n\n tmp = n\n l = digs_of_int_int32(tmp)\n\n if (l == 1) then\n allocate (arr(1))\n arr(1) = n\n return\n end if\n\n allocate (arr(l))\n do i = l, 1, -1\n arr(i) = unit_digit_int32(tmp)\n tmp = tmp/10\n end do\n end subroutine int_2_arr_int32\n\n pure subroutine int_2_arr_int64(n, arr)\n integer(int64), intent(in) :: n\n integer, allocatable, intent(out) :: arr(:)\n integer(int64) :: tmp\n integer :: i, l\n\n tmp = n\n l = int(digs_of_int_int64(tmp))\n\n if (l == 1) then\n allocate (arr(1))\n arr(1) = int(n)\n return\n end if\n\n allocate (arr(l))\n do i = l, 1, -1\n arr(i) = int(unit_digit_int64(tmp))\n tmp = tmp/10_int64\n end do\n end subroutine int_2_arr_int64\n\n pure subroutine arr_2_int_int32(arr, n)\n integer, intent(in) :: arr(:)\n integer, intent(out) :: n\n integer :: i, tmp, l\n\n l = size(arr, dim=1)\n tmp = 0\n\n do i = 1, l\n tmp = tmp*10 + arr(i)\n end do\n\n n = tmp\n end subroutine arr_2_int_int32\n\n pure subroutine arr_2_int_int64(arr, n)\n integer(int64), intent(in) :: arr(:)\n integer(int64), intent(out) :: n\n integer(int64) :: i, tmp, l\n\n l = size(arr, dim=1)\n tmp = 0_int64\n\n do i = 1_int64, l\n tmp = tmp*10_int64 + arr(i)\n end do\n\n n = tmp\n end subroutine arr_2_int_int64\n\n pure subroutine append_sp(arr, e)\n real(sp), allocatable, intent(inout) :: arr(:)\n real(sp), intent(in) :: e\n\n if (allocated(arr)) then\n arr = [arr, [e]]\n else\n arr = [e]\n end if\n end subroutine append_sp\n\n pure subroutine append_dp(arr, e)\n real(dp), allocatable, intent(inout) :: arr(:)\n real(dp), intent(in) :: e\n\n if (allocated(arr)) then\n arr = [arr, [e]]\n else\n arr = [e]\n end if\n end subroutine append_dp\n\n pure subroutine append_int32(arr, e)\n integer, allocatable, intent(inout) :: arr(:)\n integer, intent(in) :: e\n\n if (allocated(arr)) then\n arr = [arr, [e]]\n else\n arr = [e]\n end if\n end subroutine append_int32\n\n pure subroutine append_int64(arr, e)\n integer(int64), allocatable, intent(inout) :: arr(:)\n integer(int64), intent(in) :: e\n\n if (allocated(arr)) then\n arr = [arr, [e]]\n else\n arr = [e]\n end if\n end subroutine append_int64\n\n pure subroutine next_permutation_int32(k, n, idx, next_permutation_avail)\n integer, intent(in) :: k, n\n integer, intent(inout) :: idx(k)\n logical, intent(out) :: next_permutation_avail\n logical :: carr(k)\n integer :: i, x, end_arr(k)\n\n end_arr = [(i, i=n - k + 1, n)]\n next_permutation_avail = .true.\n if (all(idx == end_arr)) then\n next_permutation_avail = .false.\n return\n end if\n\n carr = .true.\n label_carry: do i = k, 1, -1\n if (idx(i) == n - k + i) carr(i) = .false.\n end do label_carry\n\n if (all(carr .eqv. .true.)) then\n idx(k) = idx(k) + 1\n else\n x = findloc(carr, value=.false., dim=1) - 1\n idx(x:k) = [(idx(x) + i, i=1, k - x + 1)]\n end if\n end subroutine next_permutation_int32\n\n pure subroutine next_permutation_int64(k, n, idx, next_permutation_avail)\n integer(int64), intent(in) :: k, n\n integer(int64), intent(inout) :: idx(k)\n logical, intent(out) :: next_permutation_avail\n logical :: carr(k)\n integer(int64) :: i, x, end_arr(k)\n\n end_arr = [(i, i=n - k + 1, n)]\n next_permutation_avail = .true.\n if (all(idx == end_arr)) then\n next_permutation_avail = .false.\n return\n end if\n\n carr = .true.\n label_carry: do i = k, 1, -1\n if (idx(i) == n - k + i) carr(i) = .false.\n end do label_carry\n\n if (all(carr .eqv. .true.)) then\n idx(k) = idx(k) + 1\n else\n x = findloc(carr, value=.false., dim=1) - 1\n idx(x:k) = [(idx(x) + i, i=1, k - x + 1)]\n end if\n end subroutine next_permutation_int64\n\n pure subroutine next_permutation2_int32(arr, next_permutation_avail)\n integer, intent(inout) :: arr(:)\n logical, intent(out) :: next_permutation_avail\n integer :: i, k, l\n\n k = 0; l = 0\n do i = size(arr) - 1, 1, -1\n if (arr(i) < arr(i + 1)) then\n k = i\n next_permutation_avail = .true.\n exit\n else\n next_permutation_avail = .false.\n end if\n end do\n\n do i = size(arr), 1, -1\n if (arr(k) < arr(i)) then\n l = i; exit\n end if\n end do\n\n call swap(arr(k), arr(l))\n arr(k + 1:size(arr)) = arr(size(arr):k + 1:-1)\n end subroutine next_permutation2_int32\n\nend module euler_utils_m\n", "meta": {"hexsha": "7b1fdc733220193c6a4b68ece29a47ea7343d10f", "size": 20503, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/euler_utils_m.f90", "max_stars_repo_name": "han190/PE-Fortran", "max_stars_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T07:07:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T07:45:48.000Z", "max_issues_repo_path": "docs/src/euler_utils_m.f90", "max_issues_repo_name": "han190/PE-Fortran", "max_issues_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-14T00:48:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T00:48:58.000Z", "max_forks_repo_path": "docs/src/euler_utils_m.f90", "max_forks_repo_name": "han190/PE-Fortran", "max_forks_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T21:29:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T21:29:45.000Z", "avg_line_length": 26.6966145833, "max_line_length": 77, "alphanum_fraction": 0.5396771204, "num_tokens": 6078, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624259, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7843019950184614}} {"text": "SUBROUTINE UNBIASED_CORRELATION( N, A, B, msg, lag, r, t, m)\n\n ! Computes the correlation of two series A and B of length\n ! N as a function of lag. The correlation is unbiased\n ! because the sums in the covariance and standard devia-\n ! tions are divided by m, not m-1, where m is the number\n ! of overlapping grid points.\n\n ! The correlation r is defined as \n !\n ! cov(A,B)\n ! r = -------------\n ! s(A) * s(B)\n !\n ! where cov() is covariance and s() is standard deviation.\n\n ! The series A and B must be prepared such that they\n ! are sent to this routine with zero lag. If necessary, this\n ! is accomplished by padding the beginning or ends (or both)\n ! of each time series with missing values (msg) so that their\n ! elements correspond one to one. The resultant time series\n ! will be of equal length N. Also, missing values (msg)\n ! distributed thoughout each time series is perfectly\n ! acceptable. Time series B will be shifted by the amount\n ! lag relative to time series A:\n\n ! RETURNS: r, the unbiased correlation, t, the significance\n ! of the unbiased correlation ( t is set to msg if B = A\n ! at lag 0, i.e. an autocorrelation at lag 0, or if the\n ! correlation is 1.0 in general), and m, the number of\n ! overlapping grid points.\n\n ! A: t1 t2 t3 t4 ... tN\n ! B: t1 t2 t3 t4 ... tN \n\n ! \\_ _/\n ! V\n ! lag = 2 (Defined to be > 0.) \n\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: N\n REAL(8), DIMENSION(N), INTENT(IN) :: A \n REAL(8), DIMENSION(N), INTENT(IN) :: B \n REAL(8), INTENT(IN) :: msg \n INTEGER, INTENT(IN) :: lag \n REAL(8), INTENT(OUT) :: r\n REAL(8), INTENT(OUT) :: t\n INTEGER, INTENT(OUT) :: m\n\n\n REAL(8), DIMENSION(:), ALLOCATABLE :: x\n REAL(8), DIMENSION(:), ALLOCATABLE :: y\n REAL(8), DIMENSION(:), ALLOCATABLE :: xdev\n REAL(8), DIMENSION(:), ALLOCATABLE :: ydev\n REAL(8), DIMENSION(:), ALLOCATABLE :: xdevydev\n REAL(8), DIMENSION(:), ALLOCATABLE :: xdevxdev\n REAL(8), DIMENSION(:), ALLOCATABLE :: ydevydev\n\n REAL(8) :: xmn\n REAL(8) :: ymn\n REAL(8) :: COVxy\n REAL(8) :: Sx\n REAL(8) :: Sy\n\n\n ALLOCATE( x(1:3*N) )\n ALLOCATE( y(1:3*N) )\n\n x(:) = msg\n y(:) = msg\n\n x(N+1:2*N) = A(:)\n y(N+1:2*N) = B(:)\n\n y = EOSHIFT( y, SHIFT = -lag, BOUNDARY = msg )\n\n WHERE ( x == msg ) y = msg\n WHERE ( y == msg ) x = msg\n\n m = COUNT( x /= msg )\n\n IF ( m < 3 ) THEN\n\n WRITE (*,'(A40, I1)') \"The number of overlapping points is m = \", m\n WRITE (*,'(A35)') \"The value of m should be 3 or more.\"\n WRITE (*,'(A17)') \"Decrease the lag.\"\n WRITE (*,'(A52)') \"Execution halted in SUBROUTINE UNBIASED_CORRELATION.\"\n STOP\n\n END IF\n\n xmn = SUM( x, DIM = 1, MASK = x /= msg ) / REAL(m)\n ymn = SUM( y, DIM = 1, MASK = y /= msg ) / REAL(m)\n\n ALLOCATE( xdev(1:3*N) )\n ALLOCATE( ydev(1:3*N) )\n\n xdev(:) = x(:) - xmn\n WHERE ( x == msg ) xdev(:) = msg\n\n ydev(:) = y(:) - ymn\n WHERE ( y == msg ) ydev(:) = msg\n\n ALLOCATE( xdevydev(1:3*N) )\n\n xdevydev(:) = xdev(:) * ydev(:)\n WHERE ( x == msg ) xdevydev(:) = msg\n \n COVxy = SUM( xdevydev, DIM = 1, MASK = xdevydev /= msg ) / REAL(m)\n\n ALLOCATE( xdevxdev(1:3*N) )\n\n xdevxdev(:) = xdev(:) * xdev(:)\n WHERE ( x == msg ) xdevxdev(:) = msg\n\n Sx = SQRT( SUM( xdevxdev, DIM = 1, MASK = xdevxdev /= msg ) / REAL(m) )\n\n ALLOCATE( ydevydev(1:3*N) )\n\n ydevydev(:) = ydev(:) * ydev(:)\n WHERE ( y == msg ) ydevydev(:) = msg\n\n Sy = SQRT( SUM( ydevydev, DIM = 1, MASK = ydevydev /= msg ) / REAL(m) )\n\n r = COVxy / ( Sx * Sy )\n\n IF ( r /= 1.0 ) THEN\n\n t = r * SQRT( (m - 2) / ( 1 - r*r ) )\n\n ELSE\n\n t = msg\n\n END IF\n\n DEALLOCATE( x, y, xdev, ydev, xdevydev, xdevxdev, ydevydev )\n\nEND SUBROUTINE UNBIASED_CORRELATION \n", "meta": {"hexsha": "9ff03ed49750c333e57cd318c9b4a5a250a0e2ac", "size": 3983, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/probability/unbiased_correlation.f90", "max_stars_repo_name": "fsobral/fkss", "max_stars_repo_head_hexsha": "16ef79b194358c20e5ffb3554c6362742de1018c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-21T12:20:08.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-21T12:20:08.000Z", "max_issues_repo_path": "tests/probability/unbiased_correlation.f90", "max_issues_repo_name": "fsobral/fkss", "max_issues_repo_head_hexsha": "16ef79b194358c20e5ffb3554c6362742de1018c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/probability/unbiased_correlation.f90", "max_forks_repo_name": "fsobral/fkss", "max_forks_repo_head_hexsha": "16ef79b194358c20e5ffb3554c6362742de1018c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2482269504, "max_line_length": 79, "alphanum_fraction": 0.5370323876, "num_tokens": 1400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.7843019885854113}} {"text": "!Calculates analytic vertical eddy diffusivity profiles\nsubroutine analytic_Kv(nlev, Ksurf, Km, Kbg, H, Kv)\nuse grid, only : Z_w\nimplicit none\ninteger, intent(in) :: nlev\nreal, intent(in) :: Ksurf ! Surface diffusivity\nreal, intent(in) :: Km ! maximal diffusivity\nreal, intent(in) :: Kbg ! Background diffusivity\nreal, intent(in) :: H ! MLD\nreal, intent(out) :: Kv(0:nlev) ! Output Kv file\n\nreal :: z !Water depth\n\ninteger :: k \n\nKv(nlev) = Ksurf\ndo k = 1, nlev\n z = Z_w(k) !Current depth\n if (z .gt. -H/2.d0) then\n Kv(k)=Ksurf + (Km - Ksurf)*( 1.d0 - 1.5**(-abs(z)**2.3) )\n elseif (z .le. -H/2d0 .and. z .ge. -H) then\n Kv(k)=Kbg + (Km - Kbg)*( 1.d0 - 1.5**(-(H+z)**2.3) )\n else\n Kv(k)=Kbg\n endif\nenddo\nEND subroutine analytic_Kv", "meta": {"hexsha": "716d3cbec3e456fa76cffb661c28341316ab5505", "size": 773, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/compute_Kv.f90", "max_stars_repo_name": "BingzhangChen/IBM", "max_stars_repo_head_hexsha": "16a443e159a088f2aecb0aefc1d1a4865462d62c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/compute_Kv.f90", "max_issues_repo_name": "BingzhangChen/IBM", "max_issues_repo_head_hexsha": "16a443e159a088f2aecb0aefc1d1a4865462d62c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/compute_Kv.f90", "max_forks_repo_name": "BingzhangChen/IBM", "max_forks_repo_head_hexsha": "16a443e159a088f2aecb0aefc1d1a4865462d62c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.6296296296, "max_line_length": 63, "alphanum_fraction": 0.6067270375, "num_tokens": 298, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.964855157641556, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.7842992328418962}} {"text": "subroutine eccf_decl(calday, daysperyear, delta, eccf)\n\n! Computes declination angle (latitude of subsolar point) and\n! eccentricity factor (which modulates insolation, accounting \n! for deviation of Sun-planet distance from its mean along orbit)\n! for a given calendar day and orbital parameters \n! (accessed thru common/orbpar)\n\n! Based on Pierrehumbert (2005), \"A first course in climate\"\n! (http://geosci.uchicago.edu/~rtp1/geo232)\n\n! Notes: \n! - Following (obscure) convention, the precession angle mvelp\n! (\"moving vernal equinox longitude of perihelion\") is\n! mvelp = pi - kappa1e \n! where kappa1e is the angle from perihelion to vernal equinox\n!\n! - To match the calendar currently used on Earth, vernal equinox\n! is defined to occur 80/365 of the way through the year\n\n! Rodrigo Caballero, University of Chicago, 2005.\n\nimplicit none\n\n! In\nreal calday ! calendar day\nreal daysperyear ! no. days in a year\nreal eccen, obliq, mvelp\ncommon/orbpar/eccen, obliq, mvelp\n\n! Out\nreal delta ! declination angle\nreal eccf ! eccentricity factor\n\n! Local\nreal kappa ! season angle (0 at vernal equinox)\nreal kappa1 ! longitude of perihelion (angle from perihelion to sun-planet axis)\nreal pi \nreal, external :: season_angle\n\nif (mvelp .eq. 0.) mvelp = 1.e-4\npi = abs(acos(-1.))\nkappa = season_angle(calday, daysperyear)\nkappa1 = pi - mvelp*pi/180. + kappa \n\ndelta = asin(sin(obliq*pi/180.)*sin(kappa))\neccf = ( 1. + eccen*cos(kappa1) ) / (1. - eccen*eccen)\neccf = eccf*eccf\n\nend subroutine eccf_decl\n!-------------------------------------------------------------------------\nreal function season_angle(calday, daysperyear)\n\n! \"Season angle\" is defined as the angle from vernal equinox to\n! position of sun-planet axis on day calday.\n\n! Here, it is found by numerically inverting the relation between \n! season angle and calendar time using Ridder's root-finding algorithm. \n\n! To match the calendar currently used on Earth, vernal equinox\n! is defined to occur 80/365 of the way through the year\n\nimplicit none\n\n! In\nreal calday ! calendar day\nreal daysperyear ! number of days in year\nreal eccen, obliq, mvelp\ncommon/orbpar/eccen, obliq, mvelp\n\n! Local\nreal period ! adimensional period of orbit\nreal params(10) ! dummy vector to carray parameters\nlogical success\nreal pi\nreal, external :: ridder,diff,integral\n\n\npi = abs(acos(-1.))\nperiod = integral(eccen,2.*pi) \n\nparams(1) = period\nparams(2) = calday/daysperyear - 80./365.\nseason_angle = ridder(success, diff, params, -2.*pi, 2.*pi, .0001)\n\nif (.not.success) then\nprint*,'damm'\nstop\nendif\n\nend function season_angle\n!------------------------------------------------------------------------\nreal function diff(params, kappa)\n\n! Returns the difference between time taken to reach \n! season angle kappa, and a specified target time\n\nimplicit none\n\n! In\nreal kappa ! season angle\nreal params(10) ! parameter vector\nreal eccen, obliq, mvelp\ncommon/orbpar/eccen, obliq, mvelp\n\n! Local\nreal period ! orbital period\nreal time ! time taken to reach season angle kappa \nreal target_time ! target time\nreal kappa1e ! angle between perihelion and vernal equinox\nreal pi\nreal, external :: integral\n\npi = abs(acos(-1.))\nperiod = params(1)\ntarget_time = params(2)\n\nkappa1e = pi - mvelp*pi/180. \ntime = integral(eccen, kappa1e+kappa) - integral(eccen, kappa1e)\n\ndiff = time/period - target_time ! note time is adimensionalised by period\n\nend function diff\n!------------------------------------------------------------------------\nreal function integral(e,x)\n\n! Returns indefinite integral of 1/(1+e*cos x)**2\n\nimplicit none\nreal e,x,oneme2,a,pi\n\noneme2 = 1.-e*e\na = atan( ((1.-e)/(1.+e))**0.5*tan(x/2.) )\n\npi = abs(acos(-1.))\nif (x .gt. pi) a = a + pi\nif (x .lt. -pi) a = a - pi\n\nintegral = 2./oneme2**1.5*a - e*sin(x)/oneme2/(1.+e*cos(x))\n\nend function integral\n!------------------------------------------------------------------------\nreal function ridder(success, func, params, xmin, xmax, acc)\n\n! Find zero crossing of func(x) in range xmin < x < xmax with accuracy acc\n! Use Ridder's method (Numerical Recipes)\n\nreal params(10),xmin,xmax,acc,func\nlogical success\nexternal func\n\nmaxit=60 ! max number of iterations\nsuccess=.true.\n\nfl=func(params,xmin)\nfh=func(params,xmax)\n\nif((fl.gt.0..and.fh.lt.0.).or.(fl.lt.0..and.fh.gt.0.))then\n xl=xmin\n xh=xmax\n ridder=-1.11e30\n do j=1,maxit\n xm=0.5*(xl+xh)\n fm=func(params,xm)\n s=sqrt(fm**2-fl*fh)\n if(s.eq.0.)return\n xnew=xm+(xm-xl)*(sign(1.,fl-fh)*fm/s)\n if (abs(xnew-ridder).le.acc) return\n ridder=xnew\n fnew=func(params,ridder)\n if (fnew.eq.0.) return\n if(sign(fm,fnew).ne.fm) then\n xl=xm\n fl=fm\n xh=ridder\n fh=fnew\n else if(sign(fl,fnew).ne.fl) then\n xh=ridder\n fh=fnew\n else if(sign(fh,fnew).ne.fh) then\n xl=ridder\n fl=fnew\n else\n stop 'never get here in ridder'\n endif\n if(abs(xh-xl).le.acc) return\n enddo\n stop 'ridder exceed maximum iterations maxit'\nelse if (fl.eq.0.) then\n ridder=xmin\nelse if (fh.eq.0.) then\n ridder=xmax\nelse\n success=.false.\nendif\n\nend function ridder\n", "meta": {"hexsha": "00eed27f84fa86ea409de0239083d6f84953d8ce", "size": 5220, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/radiation/insolation/src/eccf_decl.f90", "max_stars_repo_name": "CliMT/climt-legacy", "max_stars_repo_head_hexsha": "adbd4fe77426c90deb8d2c046a2f3dc3b72df89e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/radiation/insolation/src/eccf_decl.f90", "max_issues_repo_name": "CliMT/climt-legacy", "max_issues_repo_head_hexsha": "adbd4fe77426c90deb8d2c046a2f3dc3b72df89e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/radiation/insolation/src/eccf_decl.f90", "max_forks_repo_name": "CliMT/climt-legacy", "max_forks_repo_head_hexsha": "adbd4fe77426c90deb8d2c046a2f3dc3b72df89e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.3636363636, "max_line_length": 80, "alphanum_fraction": 0.6488505747, "num_tokens": 1572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.936285002192296, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.7842510016153641}} {"text": "\tProgram pai\n\tImplicit none\n\tinteger max\nc declarations\n\tReal volume, x, y, z, area\n\tInteger i, pi3, pi2\n\tprint*,'input the number for try'\n\tread(5,*) max\n\tpi3=0\nc use max as random seed\n\tcall srand(max)\nc execute\n\tDo 10 i=1, max\nc generate (x,y) within [-1,1]:\n\t x = rand()*2-1\n\t y = rand()*2-1\n\t z = rand()*2-1\n\t If ((x*x + y*y + z*z) .LE. 1) pi3 = pi3 + 1\n\t volume = 6.0 * pi3/Real(i) \nc volume inside sphere ~ pts/i = 4/3*pi*r**3 --> pi= pts*8\n \t if(mod(i,int(sqrt(i*1.0))).eq.1) Write(6,100) i, volume\n 10 \tContinue\n\n Write(6,100) max, volume\n100\tformat(1x,'try= ',i10,2x,'pai=',f8.4)\nc do-while loop to get enough significant numbers\n\tpi3=0\n\ti=0\n\tdo while(abs(volume-3.1415927).GT.1E-4)\n\t x = rand()*2-1\n\t y = rand()*2-1\n\t z = rand()*2-1\n\t i = i+1\n\t if ((x*x + y*y + z*z).LE.1) pi3 = pi3 +1\n volume = 6.0 * pi3/Real(i)\n \tenddo\n\twrite (6,200), i,volume\n200\tformat(i8,\" trials are needed, the final value of Pi is \",f5.3)\n\tstop\n\tend\n \t\n", "meta": {"hexsha": "4c6b86a3b870e12bd4847c4ae2a5952271b7d872", "size": 979, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "HW3/P1.f", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW3/P1.f", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW3/P1.f", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.3095238095, "max_line_length": 67, "alphanum_fraction": 0.5801838611, "num_tokens": 404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422227627597, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7841805512882758}} {"text": "c\nc This file contains a set of subroutines for the handling \nc of Legendre expansions. It contains 19 subroutines that are \nc user-callable. Following is a brief description of these \nc subroutines.\nc\nc legeexps - constructs Legendre nodes, and corresponding Gaussian\nc weights. Also constructs the matrix v converting the \nc coefficients of a legendre expansion into its values at \nc the n Gaussian nodes, and its inverse u, converting the\nc values of a function at n Gaussian nodes into the\nc coefficients of the corresponding Legendre series.\nc\nc legepol - evaluates a single Legendre polynomial (together\nc with its derivative) at the user-provided point\nc\nc legepols - evaluates a bunch of Legendre polynomials\nc at the user-provided point\nc legepls2 - an accelerated version of legepols, evaluating a \nc Legendre polynomials at the user-provided point; maximum\nc order of the polynomials to be evaluated is 290\nc\nc legepolders - evaluates a bunch of Legendre polynomials\nc at the user-provided point, and the derivatives of the \nc said polynomials \nc legeinmt - for the user-specified n, constructs the matrices of \nc spectral indefinite integration differentiation on the n \nc Gaussian nodes on the interval [-1,1]. \nc\nc legeinte - computes the indefinite integral of the legendre \nc expansion polin getting the expansion polout\nc\nc legediff - differentiates the legendre expansion polin getting \nc the expansion polout\nc\nc legefder - computes the value and the derivative of a Legendre \nc expansion at point X in interval [-1,1]; this subroutine \nc is not designed to be very efficient, but it does not\nc use any exdternally supplied arrays\nc\nc legefde2 - the same as legefder, except it is desigmed to be \nc fairly efficient; it uses externally supplied arrays\nc that are precomputed\nc \nc legeexev - computes the value of a Legendre expansion with \nc at point X in interval [-1,1]; same as legefder, but does\nc not compute the derivative of the expansion\nc\nc legeexe2 - the same as legeexev, except it is desigmed to be \nc fairly efficient; it uses externally supplied arrays\nc that are precomputed\nc\nc lematrin - constructs the matrix interpolating functions from \nc the n-point Gaussian grid on the interval [-1,1] to an \nc arbitrary m-point grid (the nodes of the latter are\nc user-provided)\nc \nc levecin - constructs the coefficients of the standard \nc interpolation formula connecting the values of a \nc function at n Gaussian nodes on the interval [a,b] with\nc its value at the point x \\in R^1\nc\nc legeodev - evaluates at the point x a Legendre expansion\nc having only odd-numbered elements; this is a fairly \nc efficient code, using external arrays that are \nc precomputed\nc\nc legeevev - evaluates at the point x a Legendre expansion\nc having only even-numbered elements; this is a fairly \nc efficient code, using external arrays that are \nc precomputed\nc\nc legepeven - evaluates even-numbered Legendre polynomials \nc of the argument x; this is a fairly efficient code, \nc using external arrays that are precomputed\nc\nc legepodd - evaluates odd-numbered Legendre polynomials \nc of the argument x; this is a fairly efficient code, \nc using external arrays that are precomputed\nc\nC legefdeq - computes the value and the derivative of a\nc Legendre Q-expansion with coefficients coefs\nC at point X in interval (-1,1); please note that this is\nc the evil twin of the subroutine legefder, evaluating the\nc proper (P-function) Legendre expansion; this subroutine \nc is not designed to be very efficient, but it does not\nc use any exdternally supplied arrays\nc\nc legeq - calculates the values and derivatives of a bunch \nc of Legendre Q-functions at the user-specified point \nc x on the interval (-1,1)\nc\nc legeqs - calculates the value and the derivative of a single\nc Legendre Q-function at the user-specified point \nc x on the interval (-1,1)\nc\nc legecfde - computes the value and the derivative of a Legendre \nc expansion with complex coefficients at point X in interval \nc [-1,1]; this subroutine is not designed to be very efficient, \nc but it does not use any exdternally supplied arrays. This is\nc a complex version of the subroutine legefder.\nc\nc legecfd2 - the same as legecfde, except it is designed to be \nc fairly efficient; it uses externally supplied arrays\nc that are precomputed. This is a complex version of the \nc subroutine legefde2.\nc\nc legecva2 - the same as legecfd2, except it is does not evaluate\nc the derivative of the function\nc\nc\n subroutine legeexps(itype,n,x,u,v,whts)\n implicit double precision (a-h,o-z)\n dimension x(1),whts(1),u(n,n),v(n,n)\nc\nc this subroutine constructs the gaussiaqn nodes \nc on the interval [-1,1], and the weights for the \nc corresponding order n quadrature. it also constructs\nc the matrix v converting the coefficients\nc of a legendre expansion into its values at the n\nc gaussian nodes, and its inverse u, converting the\nc values of a function at n gaussian nodes into the\nc coefficients of the corresponding legendre series.\nc no attempt has been made to make this code efficient, \nc but its speed is normally sufficient, and it is \nc mercifully short.\nc\nc input parameters:\nc\nc itype - the type of the calculation to be performed\nc itype=0 means that only the gaussian nodes are \nc to be constructed. \nc itype=1 means that only the nodes and the weights \nc are to be constructed\nc itype=2 means that the nodes, the weights, and\nc the matrices u, v are to be constructed\nc n - the number of gaussian nodes and weights to be generated\nc \nc output parameters:\nc\nc x - the order n gaussian nodes - computed independently\nc of the value of itype.\nc u - the n*n matrix converting the values at of a polynomial of order\nc n-1 at n legendre nodes into the coefficients of its \nc legendre expansion - computed only in itype=2\nc v - the n*n matrix converting the coefficients\nc of an n-term legendre expansion into its values at\nc n legendre nodes (note that v is the inverse of u)\nc - computed only in itype=2\nc whts - the corresponding quadrature weights - computed only \nc if itype .ge. 1\nc\nc . . . construct the nodes and the weights of the n-point gaussian \nc quadrature\nc\n ifwhts=0\n if(itype. gt. 0) ifwhts=1\n call legewhts(n,x,whts,ifwhts)\nc\nc construct the matrix of values of the legendre polynomials\nc at these nodes \nc\n if(itype .ne. 2) return\n do 1400 i=1,n\nc\n call legepols(x(i),n-1,u(1,i) )\n 1400 continue\nc\n do 1800 i=1,n\n do 1600 j=1,n\n v(i,j)=u(j,i)\n 1600 continue\n 1800 continue\nc\nc now, v converts coefficients of a legendre expansion\nc into its values at the gaussian nodes. construct its \nc inverse u, converting the values of a function at \nc gaussian nodes into the coefficients of a legendre \nc expansion of that function\nc\n do 2800 i=1,n\n d=1\n d=d*(2*i-1)/2\n do 2600 j=1,n\n u(i,j)=v(j,i)*whts(j)*d\n 2600 continue\n 2800 continue\n return\n end\nc\nc\nc\nc\nc\n subroutine legewhts_old(n,ts,whts,ifwhts)\n implicit double precision (a-h,o-z)\n dimension ts(1),whts(1)\nc\nc this subroutine constructs the nodes and the\nc weights of the n-point gaussian quadrature on \nc the interval [-1,1]\nc\nc input parameters:\nc\nc n - the number of nodes in the quadrature\nc\nc output parameters:\nc\nc ts - the nodes of the n-point gaussian quadrature\nc w - the weights of the n-point gaussian quadrature\nc\nc . . . construct the array of initial approximations\nc to the roots of the n-th legendre polynomial\nc\n eps=1.0d-14\n ZERO=0\n DONE=1\n pi=datan(done)*4\n h=pi/(2*n) \n do 1200 i=1,n\n t=(2*i-1)*h\n ts(n-i+1)=dcos(t)\n1200 CONTINUE\nc\nc use newton to find all roots of the legendre polynomial\nc\n ts(n/2+1)=0\n do 2000 i=1,n/2\nc\n xk=ts(i)\n ifout=0\n deltold=1\n do 1400 k=1,10\n call legepol(xk,n,pol,der)\n delta=-pol/der\nccccc call prin2('delta=*',delta,1)\n xk=xk+delta\n if(abs(delta) .lt. eps) ifout=ifout+1\nc\ncccc call prin2('delta=*',delta,1)\n\n \n if(ifout .eq. 3) goto 1600\n 1400 continue\n 1600 continue\n ts(i)=xk\n ts(n-i+1)=-xk\n 2000 continue\nc\nc now, use the explicit integral formulae \nc to obtain the weights\nc\n if(ifwhts .eq. 0) return\n a=-1\n b=1\n do 2200 i=1,n/2+1\n call prodend(a,ts,n,i,fm)\n call prodend(b,ts,n,i,fp)\n whts(i)=fp-fm\n whts(n-i+1)=whts(i)\n 2200 continue\n return\n end\nc\nc\nc\nc\nc\n subroutine legewhts(n,ts,whts,ifwhts)\n implicit double precision (a-h,o-z)\n dimension ts(*),whts(*)\nc\nc this subroutine constructs the nodes and the\nc weights of the n-point gaussian quadrature on \nc the interval [-1,1]\nc\nc input parameters:\nc\nc n - the number of nodes in the quadrature\nc\nc output parameters:\nc\nc ts - the nodes of the n-point gaussian quadrature\nc w - the weights of the n-point gaussian quadrature\nc\nc . . . construct the array of initial approximations\nc to the roots of the n-th legendre polynomial\nc\n eps=1.0d-14\n done = 1\n pi=datan(done)*4\n h=pi/(2.0d0*n)\n\n\n do i=1,n\n t=(2*i-1)*h\n ts(n-i+1)=cos(t)\n enddo\n\nc\nc use newton to find all roots of the legendre polynomial\nc\n ts(n/2+1)=0\n do 2000 i=1,n/2\nc\n xk=ts(i)\n ifout=0\n deltold=1\n do 1400 k=1,10\n call legepol_sum(xk,n,pol,der,sum)\n delta=-pol/der\n xk=xk+delta\n if(abs(delta) .lt. eps) ifout=ifout+1\nc\n if(ifout .eq. 3) goto 1600\n 1400 continue\n 1600 continue\n ts(i)=xk\n ts(n-i+1)=-xk\n 2000 continue\nc \nc construct the weights via the orthogonality relation\nc\n if(ifwhts .eq. 0) return\nc\n do 2400 i=1,(n+1)/2\n call legepol_sum(ts(i),n,pol,der,sum)\n whts(i)=1/sum\n whts(n-i+1)=whts(i)\n 2400 continue\nc\n return\n end\nc\nc\nc\nc\nc\n subroutine legepol_sum(x,n,pol,der,sum)\n implicit double precision (a-h,o-z)\nc\n done=1\n sum=0 \nc\n pkm1=1\n pk=x\n sum=sum+pkm1**2 /2\n sum=sum+pk**2 *(1+done/2)\nc\n pk=1\n pkp1=x\nc\nc if n=0 or n=1 - exit\nc\n if(n .ge. 2) goto 1200\n\n sum=0 \nc\n pol=1\n der=0\n sum=sum+pol**2 /2\n if(n .eq. 0) return\nc\n pol=x\n der=1\n sum=sum+pol**2*(1+done/2)\n return\n 1200 continue\nc\nc n is greater than 1. conduct recursion\nc\n do 2000 k=1,n-1\n pkm1=pk\n pk=pkp1\n pkp1=( (2*k+1)*x*pk-k*pkm1 )/(k+1)\n sum=sum+pkp1**2*(k+1+done/2)\n 2000 continue\nc\nc calculate the derivative\nc\n pol=pkp1\n der=n*(x*pkp1-pk)/(x**2-1)\n return\n end\nc\nc\nc\nc\nc\n subroutine legepol(x,n,pol,der)\n implicit double precision (a-h,o-z)\nc\n pkm1=1\n pk=x\nc\n pk=1\n pkp1=x\nc\nc if n=0 or n=1 - exit\nc\n if(n .ge. 2) goto 1200\n pol=1\n der=0\n if(n .eq. 0) return\nc\n pol=x\n der=1\n return\n 1200 continue\nc\nc n is greater than 1. conduct recursion\nc\n do 2000 k=1,n-1\n pkm1=pk\n pk=pkp1\n pkp1=( (2*k+1)*x*pk-k*pkm1 )/(k+1)\n 2000 continue\nc\nc calculate the derivative\nc\n pol=pkp1\n der=n*(x*pkp1-pk)/(x**2-1)\n return\n end\nc\nc\nc\nc\nc\n subroutine prodend(x,xs,n,i,f)\n implicit double precision (a-h,o-z)\n dimension xs(1)\nc\nc evaluate the product\nc\n f=1\n dlarge=1.0d20\n dsmall=f/dlarge\nc\n large=0\n do 2000 j=1,n\n dd=dabs(f)\n if( dd .gt. dsmall) goto 1200\n f=f*10000\n large=large-1\n 1200 continue\nc\n if( dd .lt. dlarge) goto 1400\n f=f/10000\n large=large+1\n 1400 continue\n if(j .eq. i) goto 2000\n f=f*(x-xs(j))/(xs(i)-xs(j))\n 2000 continue\n d10000=10000\n f=f*d10000**large\n f=f**2*(x-xs(i))\n return\n end\nc\nc\nc\nc\nc\n subroutine legepols(x,n,pols)\n implicit double precision (a-h,o-z)\n dimension pols(*)\nc\n pkm1=1\n pk=x\nc\n pk=1\n pkp1=x\nc\nc\nc if n=0 or n=1 - exit\nc\n if(n .ge. 2) goto 1200\n pols(1)=1\n if(n .eq. 0) return\nc\n pols(2)=x\n return\n 1200 continue\nc\n pols(1)=1\n pols(2)=x\nc\nc n is greater than 2. conduct recursion\nc\n do 2000 k=1,n-1\n pkm1=pk\n pk=pkp1\n pkp1=( (2*k+1)*x*pk-k*pkm1 )/(k+1)\n pols(k+2)=pkp1\n 2000 continue\nc\n return\n end\n\nc\nc\nc\nc\nc\n SUBROUTINE legepolders(X,VALs,ders,N)\n IMPLICIT double precision (A-H,O-Z)\n double precision vals(*),ders(*)\nC\nC This subroutine computes the values and the derivatives\nc of n+1 first Legendre polynomials at the point x \nC in interval [-1,1].\nc\nc input parameters:\nc\nC X = evaluation point\nC N = order of expansion \nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc\nc output parameters:\nc\nC VALs = computed values of Legendre polynomials\nC ders = computed values of the derivatives\nC\nC\n\n\n done=1\n pjm2=1\n pjm1=x\n derjm2=0\n derjm1=1\nc\n vals(1)=1\n ders(1)=0\nc\n vals(2)=x\n ders(2)=1\nc\n DO 600 J = 2,N\nc\n pj= ( (2*j-1)*x*pjm1-(j-1)*pjm2 ) / j\n derj=(2*j-1)*(pjm1+x*derjm1)-(j-1)*derjm2\nc\n derj=derj/j\n\n vals(j+1)=pj\n ders(j+1)=derj\nc \n pjm2=pjm1\n pjm1=pj\n derjm2=derjm1\n derjm1=derj\n 600 CONTINUE\nc\n RETURN\n END\nc\nc\nc\nc\nc\n subroutine legepls2(x,n,pols)\n implicit double precision (a-h,o-z)\n dimension pols(*),pjcoefs1(2000),pjcoefs2(300)\n save\n data ifcalled/0/\nc\nc if need be - initialize the arrays pjcoefs1, pjcoefs2\nc\n if(ifcalled .eq. 1) goto 1100\nc\n done=1\n ninit=290\n do 1050 j=2,ninit\nc\n pjcoefs1(j)=(2*j-done)/j\n pjcoefs2(j)=-(j-done)/j\nc\n 1050 continue\nc \n ifcalled=1\n 1100 continue\n\n pkm1=1\n pk=x\nc\n pk=1\n pkp1=x\nc\nc if n=0 or n=1 - exit\nc\n if(n .ge. 2) goto 1200\n pols(1)=1\n if(n .eq. 0) return\nc\n pols(2)=x\n return\n 1200 continue\nc\n pols(1)=1\n pols(2)=x\nc\nc n is greater than 2. conduct recursion\nc\n do 2000 k=1,n-1\n pkm1=pk\n pk=pkp1\n pkp1=x*pk*pjcoefs1(k+1)+pkm1*pjcoefs2(k+1)\n pols(k+2)=pkp1\n 2000 continue\nc\n return\n end\nc\nc\nc\nc\nc\n subroutine legeinmt(n,ainte,adiff,x,whts,endinter,\n 1 itype,w)\n implicit double precision (a-h,o-z)\n dimension ainte(1),w(1),x(1),whts(1),adiff(1),endinter(1)\nc\nc\nc for the user-specified n, this subroutine constructs\nc the matrices of spectral indefinite integration and/or\nc spectral differentiation on the n Gaussian nodes \nc on the interval [-1,1]. Actually, this is omnly a \nc memory management routine. All the actual work is done\nc by the subroutine legeinm0 (see)\nc\nc input parameters:\nc\nc n - the number of Gaussian nodes on the interval [-1,1]\nc itype - the type of the calculation to be performed\nc EXPLANATION: \nc itype=1 means that only the matrix ainte will \nc be constructed\nc itype=2 means that only the matrix adiff will \nc be constructed\nc itype=3 means that both matrices ainte and adiff\nc will be constructed\nc\nc output paramaters:\nc\nc ainte - the matrix of spectral indefinite integration on \nc the Gaussian nodes\nc adiff - the matrix of spectral differentiation on \nc the Gaussian nodes\nc x - the n Gaussian nodes on the intervl [-1,1]\nc whts - the n Gaussian weights on the interval [-1,1]\nc endinter - the interpolation coefficients converting the \nc values of a function at n Gaussian nodes into its\nc value at 1 (the right end of the interval)\nc\nc work arrays:\nc\nc w - must be 3* n**2 + 2*n +50 *8 locations long\nc\nc . . . allocate memory for the construction of the integrating\nc matrix\nc\n ipolin=1\n lpolin=n+5\nc\n ipolout=ipolin+lpolin\n lpolout=n+5\nc\n iu=ipolout+lpolout\n lu=n**2+1\nc\n iv=iu+lu\n lv=n**2+1\nc\n iw=iv+lv\n lw=n**2+1\nc\n ltot=iw+lw\nc\nc construct the integrating matrix\nc\n call legeinm0(n,ainte,adiff,w(ipolin),w(ipolout),\n 1 x,whts,w(iu),w(iv),w(iw),itype,endinter)\nc\n return\n end\nc\nc\nc\nc\nc\n subroutine legeinm0(n,ainte,adiff,polin,polout,\n 1 x,whts,u,v,w,itype,endinter)\n implicit double precision (a-h,o-z)\n dimension ainte(n,n),u(n,n),v(n,n),w(n,n),\n 1 endinter(1),x(n),whts(n),polin(n),polout(n),\n 2 adiff(n,n)\nc\nc for the user-specified n, this subroutine constructs\nc the matrices of spectral indefinite integration and/or\nc spectral differentiation on the n Gaussian nodes \nc on the interval [-1,1]\nc\nc input parameters:\nc\nc n - the number of Gaussian nodes on the interval [-1,1]\nc itype - the type of the calculation to be performed\nc EXPLANATION: \nc itype=1 means that only the matrix ainte will \nc be constructed\nc itype=2 means that only the matrix adiff will \nc be constructed\nc itype=3 means that both matrices ainte and adiff\nc will be constructed\nc\nc output paramaters:\nc\nc ainte - the matrix of spectral indefinite integration on \nc the Gaussian nodes\nc adiff - the matrix of spectral differentiation on \nc the Gaussian nodes\nc x - the n Gaussian nodes on the intervl [-1,1]\nc whts - the n Gaussian weights on the interval [-1,1]\nc\nc work arrays:\nc\nc polin, polout - must be n+3 double precision locations each\nc\nc u, v, w - must be n**2+1 double precision locations each\nc\nc . . . construct the matrices of the forward and inverse \nc Legendre transforms\nc\n itype2=2\n call legeexps(itype2,n,x,u,v,whts)\nc\ncccc call prin2('after legeexps, u=*',u,n*n)\nc\nc if the user so requested,\nc construct the matrix converting the coefficients of\nc the Legendre series of a function into the coefficients\nc of the indefinite integral of that function\nc\n if(itype. eq. 2) goto 2000\nc\n do 1600 i=1,n\nc\n do 1200 j=1,n+2\n polin(j)=0\n 1200 continue\nc\n polin(i)=1\nc\n call legeinte(polin,n,polout)\nc\n do 1400 j=1,n\n ainte(j,i)=polout(j)\n 1400 continue\nc\n 1600 continue\nc\ncccc call prin2('ainte initially is*',ainte,n*n)\nc\nc multiply the three, obtaining the integrating matrix\nc\n call matmul(ainte,u,w,n)\n call matmul(v,w,ainte,n)\nc\n 2000 continue\nc\nc if the user so requested,\nc construct the matrix converting the coefficients of\nc the Legendre series of a function into the coefficients\nc of the derivative of that function\nc\n if(itype. eq. 1) goto 3000\nc\n do 2600 i=1,n\nc\n do 2200 j=1,n+2\n polin(j)=0\n 2200 continue\nc\n polin(i)=1\nc\n call legediff(polin,n,polout)\nc\n do 2400 j=1,n\n adiff(j,i)=polout(j)\ncccc ainte(i,j)=polout(j)\n 2400 continue\nc\n 2600 continue\nc\ncccc call prin2('adiff initially is*',adiff,n*n)\nc\nc multiply the three, obtaining the integrating matrix\nc\n call matmul(adiff,u,w,n)\n call matmul(v,w,adiff,n)\nc\n 3000 continue\nc\nc construct the vector of interpolation coefficients\nc converting the values of a polynomial at the Gaussian\nc nodes into its value at the right end of the interval\nc\n do 3400 i=1,n\nc\n d=0\n do 3200 j=1,n\n d=d+u(j,i)\n 3200 continue\n endinter(i)=d\n 3400 continue\nc\n return\n end\nc\nc\nc\nc\nc\n subroutine legeinte(polin,n,polout)\n implicit double precision (a-h,o-z)\n dimension polin(*),polout(*)\nc\nc this subroutine computes the indefinite integral of the \nc legendre expansion polin getting the expansion polout\nc\nc\nc input parameters:\nc\nc polin - the legendre expansion to be integrated\nc n - the order of the expansion polin \nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc also nothe that the order of the integrated expansion is\nc n+1 (who could think!)\nc\nc output parameters:\nc\nc polout - the legendre expansion of the integral of the function \nc represented by the expansion polin\nc\n do 1200 i=1,n+2\n polout(i)=0\n 1200 continue\nc\n do 2000 k=2,n+1\n j=k-1\nc\ncccc polout(k+1)=polin(k)/(2*j+1)+polout(k+1)\n polout(k+1)=polin(k)/(2*j+1)\n polout(k-1)=-polin(k)/(2*j+1)+polout(k-1)\nc\n 2000 continue\nc\n polout(2)=polin(1)+polout(2)\nc\n dd=0\n sss=-1\n do 2200 k=2,n+1\nc\n dd=dd+polout(k)*sss\n sss=-sss\n 2200 continue\nc\nccc call prin2('dd=*',dd,1)\n polout(1)=-dd\nc\n return\n end\nc\nc\nc\nc\nc\n subroutine legediff(polin,n,polout)\n implicit double precision (a-h,o-z)\n dimension polin(1),polout(1)\nc\nc this subroutine differentiates the legendre \nc expansion polin getting the expansion polout\nc\nc\nc input parameters:\nc\nc polin - the legendre expansion to be differentiated\nc n - the order of the expansion polin \nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc also nothe that the order of the integrated expansion is\nc n+1 (who could think!)\nc\nc output parameters:\nc\nc polout - the legendre expansion of the derivative of the function \nc represented by the expansion polin\nc\n do 1200 k=1,n+1\n polout(k)=0\n 1200 continue\nc\n pk=polin(n+1)\n pkm1=polin(n)\n pkm2=0\n do 2000 k=n+1,2,-1\nc\n j=k-1\nc \n polout(k-1)=pk*(2*j-1)\n if(k .ge. 3) pkm2=polin(k-2)+pk\nc\n pk=pkm1\n pkm1=pkm2\nc\n 2000 continue\n return\n end\nc\nc\nc\nc\nc\n SUBROUTINE legeFDER(X,VAL,der,PEXP,N)\n IMPLICIT double precision (A-H,O-Z)\n double precision PEXP(*)\nC\nC This subroutine computes the value and the derivative\nc of a gaussian expansion with coefficients PEXP\nC at point X in interval [-1,1].\nc\nc input parameters:\nc\nC X = evaluation point\nC PEXP = expansion coefficients\nC N = order of expansion \nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc\nc output parameters:\nc\nC VAL = computed value\nC der = computed value of the derivative\nC\nC\n\n\n done=1\n pjm2=1\n pjm1=x\n derjm2=0\n derjm1=1\nc\n val=pexp(1)*pjm2+pexp(2)*pjm1 \n der=pexp(2)\nc\n DO 600 J = 2,N\nc\n pj= ( (2*j-1)*x*pjm1-(j-1)*pjm2 ) / j\n val=val+pexp(j+1)*pj\nc\n derj=(2*j-1)*(pjm1+x*derjm1)-(j-1)*derjm2\nc\n derj=derj/j\n der=der+pexp(j+1)*derj\nc \n pjm2=pjm1\n pjm1=pj\n derjm2=derjm1\n derjm1=derj\n 600 CONTINUE\nc\n RETURN\n END\n\n\nc\nc\nc\nc\nc\n SUBROUTINE legeFDE2(X,VAL,der,PEXP,N,\n 1 pjcoefs1,pjcoefs2,ninit)\n IMPLICIT double precision (A-H,O-Z)\n double precision PEXP(*),pjcoefs1(*),pjcoefs2(*)\nc\nC This subroutine computes the value and the derivative\nc of a gaussian expansion with coefficients PEXP\nC at point X in interval [-1,1].\nc\nc input parameters:\nc\nC X - evaluation point\nC PEXP - expansion coefficients\nC N - order of expansion \nc pjcoefs1, pjcoefs2 - two arrays precomputed on a previous call \nc on a previous call to this subroutine. Please note that this\nc is only an input parameter if the parameter ninit (see below) \nc has been set to 0; otherwise, these are output parameters\nc ninit - tells the subroutine whether and to what maximum order the \nc arrays coepnm1,coepnp1,coexpnp1 should be initialized.\nc EXPLANATION: The subroutine will initialize the first ninit\nc elements of each of the arrays pjcoefs1, pjcoefs2. On the first \nc call to this subroutine, ninit should be set to the maximum \nc order n for which this subroutine might have to be called; \nc on subsequent calls, ninit should be set to 0. PLEASE NOTE \nc THAT THAT THESE ARRAYS USED BY THIS SUBROUTINE\nc ARE IDENTICAL TO THE ARRAYS WITH THE SAME NAMES USED BY THE \nc SUBROUTINE LEGEEXE2. If these arrays have been initialized\nc by one of these two subroutines, they do not need to be \nc initialized by the other one.\nc\nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc\nc output parameters:\nc\nC VAL - computed value\nC der - computed value of the derivative\nC\nC\n if(ninit .eq. 0) goto 1400\nc\n done=1\n do 1200 j=2,ninit\nc\n pjcoefs1(j)=(2*j-done)/j\n pjcoefs2(j)=-(j-done)/j\nc\n 1200 continue\nc \n ifcalled=1\n 1400 continue\nc\n pjm2=1\n pjm1=x\n derjm2=0\n derjm1=1\nc\n val=pexp(1)*pjm2+pexp(2)*pjm1 \n der=pexp(2)\nc\n DO 1600 J = 2,N\nc\ncccc pj= ( (2*j-1)*x*pjm1-(j-1)*pjm2 ) / j\nc\n pj= pjcoefs1(j)*x*pjm1+pjcoefs2(j)*pjm2\n\n\n val=val+pexp(j+1)*pj\nc\ncccc derj=(2*j-1)*(pjm1+x*derjm1)-(j-1)*derjm2\n derj=pjcoefs1(j)*(pjm1+x*derjm1)+pjcoefs2(j)*derjm2\n\nccc call prin2('derj=*',derj,1)\n\n\ncccc derj=derj/j\n der=der+pexp(j+1)*derj\nc \n pjm2=pjm1\n pjm1=pj\n derjm2=derjm1\n derjm1=derj\n 1600 CONTINUE\nc\n RETURN\n END\nc\nc\nc\nc\nc\n SUBROUTINE legeexev(X,VAL,PEXP,N)\n IMPLICIT double precision (A-H,O-Z)\n double precision PEXP(*)\nC\nC This subroutine computes the value o a Legendre\nc expansion with coefficients PEXP at point X in interval [-1,1]\nC\nc input parameters:\nc\nC X = evaluation point\nC PEXP = expansion coefficients\nC N = order of expansion \nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc\nc output parameters:\nc\nC VAL = computed value\nC\n done=1\n pjm2=1\n pjm1=x\nc\n val=pexp(1)*pjm2+pexp(2)*pjm1 \n der=pexp(2)\nc\n DO 600 J = 2,N\nc\n pj= ( (2*j-1)*x*pjm1-(j-1)*pjm2 ) / j\n val=val+pexp(j+1)*pj\nc\n pjm2=pjm1\n pjm1=pj\n 600 CONTINUE\nc\n RETURN\n END\nc\nc\nc\nc\nc\n SUBROUTINE legeexe2(X,VAL,PEXP,N,\n 1 pjcoefs1,pjcoefs2,ninit)\n IMPLICIT double precision (A-H,O-Z)\n double precision PEXP(*),pjcoefs1(*),pjcoefs2(*)\nc\nC This subroutine computes the value o a Legendre\nc expansion with coefficients PEXP at point X in interval [-1,1]\nC\nc input parameters:\nc\nC X = evaluation point\nC PEXP = expansion coefficients\nC N = order of expansion \nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc\nc output parameters:\nc\nC VAL = computed value\nC\n done=1\n if(ninit .eq. 0) goto 1400\nc\n done=1\n do 1200 j=2,ninit\nc\n pjcoefs1(j)=(2*j-done)/j\n pjcoefs2(j)=-(j-done)/j\nc\n 1200 continue\nc \n ifcalled=1\n 1400 continue\nc\n pjm2=1\n pjm1=x\nc\n val=pexp(1)*pjm2+pexp(2)*pjm1 \n der=pexp(2)\nc\n DO 600 J = 2,N\nc\n pj= pjcoefs1(j)*x*pjm1+pjcoefs2(j)*pjm2\n\ncccc pj= ( (2*j-1)*x*pjm1-(j-1)*pjm2 ) / j\n val=val+pexp(j+1)*pj\nc\n pjm2=pjm1\n pjm1=pj\n 600 CONTINUE\nc\n RETURN\n END\nc\nc\nc\nc\nc\n subroutine lematrin(n,m,xs,amatrint,ts,w)\n implicit double precision (a-h,o-z)\n dimension amatrint(m,n),xs(1),w(1),ts(1)\nc\nc\nc This subroutine constructs the matrix interpolating\nc functions from the n-point Gaussian grid on the interval [-1,1]\nc to an arbitrary m-point grid (the nodes of the latter are\nc user-provided)\nc\nc Input parameters:\nc\nc n - the number of interpolation nodes\nc m - the number of nodes to which the functions will be interpolated\nc xs - the points at which the function is to be interpolated\nc\nc Output parameters:\nc\nc amatrint - the m \\times n matrix conerting the values of a function\nc at the n Legendre nodes into its values at m user-specified\nc (arbitrary) nodes\nc ts - the n Gaussian nodes on the interval [-1,1]\nc\nc Work arrays:\nc\nc w - must be at least 2*n**2+n + 100 double precision locations long \nc\n\n icoefs=1\n lcoefs=n+2\nc\n iu=icoefs+lcoefs\n lu=n**2+10\nc\n iv=iu+lu\nc\n ifinit=1\n do 2000 i=1,m\nc\n call levecin(n,xs(i),ts,w(iu),w(iv),w(icoefs),ifinit)\nc\n do 1400 j=1,n\n amatrint(i,j)=w(j)\n 1400 continue\nc\n ifinit=0\n 2000 continue\nc\n return\n end\n\nc\nc\nc\nc\nc\n subroutine levecin(n,x,ts,u,v,coefs,ifinit)\n implicit double precision (a-h,o-z)\n dimension u(n,n),v(n,n),ts(1),coefs(1)\nc\nc This subroutine constructs the coefficients of the \nc standard interpolation formula connecting the values of a \nc function at n Gaussian nodes on the interval [a,b] with\nc its value at the point x \\in R^1\nc\nc Input parameters:\nc\nc n - the number of interpolation nodes\nc x - the points at which the function is to be interpolated\nc ts - the n Gaussian nodes on the interval [-1,1]; please note that\nc it is an input parameter only if the parameter ifinit (see \nc below) has been set to 1; otherwise, it is an output parameter\nc u - the n*n matrix converting the values at of a polynomial of order\nc n-1 at n legendre nodes into the coefficients of its \nc legendre expansion; please note that\nc it is an input parameter only if the parameter ifinit (see \nc below) has been set to 1; otherwise, it is an output parameter\nc ifinit - an integer parameter telling the subroutine whether it should\nc initialize the Legendre expander; \nc ifinit=1 will cause the subroutine to perform the initialization\nc ifinit=0 will cause the subroutine to skip the initialization\nc\nc Output parameters:\nc\nc coefs - the interpolation coefficients\nc\nc Work arrays: \nc\nc v - must be at least n*n double precision locations long\nc\nc . . . construct the n Gausian nodes on the interval [-1,1]; \nc also the corresponding Gaussian expansion-evaluation \nc matrices\nc\n itype=2\n if(ifinit .ne.0) call legeexps(itype,n,ts,u,v,coefs)\nc\nc evaluate the n Legendre polynomials at the point where the\nc functions will have to be interpolated\nc\n call legepols(x,n+1,v)\nc\nc apply the interpolation matrix to the ector of values \nc of polynomials from the right \nc\n call lematvec(u,v,coefs,n)\n return\n end\nc\nc\nc\nc\nc\n subroutine lematvec(a,x,y,n)\n implicit double precision (a-h,o-z)\n dimension a(n,n),x(n),y(n)\nc\n do 1400 i=1,n\n d=0\n do 1200 j=1,n\n d=d+a(j,i)*x(j)\n 1200 continue\n y(i)=d\n 1400 continue\n return\n end\nc\nc\nc\nc\nc\n subroutine matmul(a,b,c,n)\n implicit double precision (a-h,o-z)\n dimension a(n,n),b(n,n),c(n,n)\nc\n do 2000 i=1,n\n do 1800 j=1,n\n d=0\n do 1600 k=1,n\n d=d+a(i,k)*b(k,j)\n 1600 continue\n c(i,j)=d\n 1800 continue\n 2000 continue\n return\nc\nc\nc\nc\n entry matmua(a,b,c,n)\nccc call prin2('in matmua, a=*',a,n**2)\nccc call prin2('in matmua, b=*',b,n**2)\n do 3000 i=1,n\n do 2800 j=1,n\n d=0\n do 2600 k=1,n\n d=d+a(i,k)*b(j,k)\n 2600 continue\n c(i,j)=d\n 2800 continue\n 3000 continue\nccc call prin2('exiting, c=*',c,n**2)\n return\n end\n\nc\nc\nc\nc\nc\n subroutine legeodev(x,nn,coefs,val,ninit,\n 1 coepnm1,coepnp1,coexpnp1)\n implicit double precision (a-h,o-z)\n dimension coepnm1(1),coepnp1(1),\n 1 coexpnp1(1),coefs(*)\nc\nc\nc This subroutine evaluates at the point x a Legendre expansion\nc having only odd-numbered elements\nc\nc Input parameters:\nc\nc x - point on the interval [-1,1] at which the Legendre expansion \nc is to be evaluated\nc nn - order of the expansion to be evaluated\nc coefs - odd-numbered coefficients of the Legendre expansion\nc to be evaluated at the point x (nn/2+2 of them things)\nc ninit - tells the subroutine whether and to what maximum order the \nc arrays coepnm1,coepnp1,coexpnp1 should be initialized.\nc EXPLANATION: The subroutine will initialize the first ninit/2+2\nc (or so) elements of each of the arrays coepnm1,\nc coepnp1, coexpnp1. On the first call to this subroutine, ninit \nc should be set to the maximum order nn for which this subroutine \nc might have to be called; on subsequent calls, ninit should be \nc set to 0. PLEASE NOTE THAT THAT THESE ARRAYS USED BY THIS SUBROUTINE\nc ARE IDENTICAL TO THE ARRAYS WITH THE SAME NAMES USED BY THE \nc SUBROUTINE LEGEPODD. IF these arrays have been initialized\nc by one of these two subroutines, they do not need to be \nc initialized by the other one.\nc coepnm1,coepnp1,coexpnp1 - should be nn/2+4 double precision elements long \nc each. Please note that these are input arrays only if ninit \nc (see above) has been set to 0; otherwise, these are output arrays.\nc \nc Output parameters:\nc\nc val - the value at the point x of the Legendre expansion with \nc coefficients coefs (see above) \nc EXPLANATION: On exit from the subroutine, pols(1) = P_0 (x),\nc pols(2) = P_2(x), pols(3) =P_4(x), etc.\nc coepnm1,coepnp1,coexpnp1 - should be nn/2+4 double precision elements long \nc each. Please note that these are output parameters only if ninit \nc (see above) has not been set to 0; otherwise, these are input \nc parameters\nc \nc \n if(ninit .eq. 0) goto 1400\n done=1\n n=0\n i=0\nc\n do 1200 nnn=2,ninit,2\nc\n n=n+2\n i=i+1\nc\n coepnm1(i)=-(5*n+7*(n*done)**2+2*(n*done)**3)\n coepnp1(i)=-(9+24*n+18*(n*done)**2+4*(n*done)**3)\n coexpnp1(i)=15+46*n+36*(n*done)**2+8*(n*done)**3\nc\n d=(2+n*done)*(3+n*done)*(1+2*n*done)\n coepnm1(i)=coepnm1(i)/d\n coepnp1(i)=coepnp1(i)/d\n coexpnp1(i)=coexpnp1(i)/d\nc\n 1200 continue\nc\n 1400 continue\nc\n x22=x**2\nc\n pi=x\n pip1=x*(2.5d0*x22-1.5d0)\nc\n val=coefs(1)*pi+coefs(2)*pip1\n\n do 2000 i=1,nn/2-2\nc\n pip2 = coepnm1(i)*pi +\n 1 (coepnp1(i)+coexpnp1(i)*x22)*pip1\nc\n val=val+coefs(i+2)*pip2\nc\n pi=pip1\n pip1=pip2\n\n\n 2000 continue\nc\n return\n end\nc\nc\nc\nc\nc\n subroutine legeevev(x,nn,coefs,val,ninit,\n 1 coepnm1,coepnp1,coexpnp1)\n implicit double precision (a-h,o-z)\n dimension coepnm1(1),coepnp1(1),\n 1 coexpnp1(1),coefs(*)\nc\nc\nc This subroutine evaluates at the point x a Legendre expansion\nc having only even-numbered elements\nc\nc Input parameters:\nc\nc x - point on the interval [-1,1] at which the Legendre expansion \nc is to be evaluated\nc nn - order of the expansion to be evaluated\nc coefs - even-numbered coefficients of the Legendre expansion\nc to be evaluated at the point x (nn/2+2 of them things)\nc ninit - tells the subroutine whether and to what maximum order the \nc arrays coepnm1,coepnp1,coexpnp1 should be initialized.\nc EXPLANATION: The subroutine will initialize the first ninit/2+2\nc (or so) elements of each of the arrays coepnm1,\nc coepnp1, coexpnp1. On the first call to this subroutine, ninit \nc should be set to the maximum order nn for which this subroutine \nc might have to be called; on subsequent calls, ninit should be \nc set to 0. PLEASE NOTE THAT THAT THESE ARRAYS USED BY THIS SUBROUTINE\nc ARE IDENTICAL TO THE ARRAYS WITH THE SAME NAMES USED BY THE \nc SUBROUTINE LEGEPEVEN. IF these aqrrays have been initialized\nc by one of these two subroutines, they do not need to be \nc initialized by the other one.\nc coepnm1,coepnp1,coexpnp1 - should be nn/2+4 double precision elements long \nc each. Please note that these are input arrays only if ninit \nc (see above) has been set to 0; otherwise, these are output arrays.\nc \nc Output parameters:\nc\nc val - the value at the point x of the Legendre expansion with \nc coefficients coefs (see above) \nc EXPLANATION: On exit from the subroutine, pols(1) = P_0 (x),\nc pols(2) = P_2(x), pols(3) =P_4(x), etc.\nc coepnm1,coepnp1,coexpnp1 - should be nn/2+4 double precision elements long \nc each. Please note that these are output parameters only if ninit \nc (see above) has not been set to 0; otherwise, these are input \nc parameters\nc \n if(ninit .eq. 0) goto 1400\nc\n done=1\n n=-1\n i=0\n do 1200 nnn=1,ninit,2\nc\n n=n+2\n i=i+1\nc\n coepnm1(i)=-(5*n+7*(n*done)**2+2*(n*done)**3)\n coepnp1(i)=-(9+24*n+18*(n*done)**2+4*(n*done)**3)\n coexpnp1(i)=15+46*n+36*(n*done)**2+8*(n*done)**3\nc\n d=(2+n*done)*(3+n*done)*(1+2*n*done)\n coepnm1(i)=coepnm1(i)/d\n coepnp1(i)=coepnp1(i)/d\n coexpnp1(i)=coexpnp1(i)/d\nc\n 1200 continue\nc\n 1400 continue\nc\n x22=x**2\nc\n pi=1\n pip1=1.5d0*x22-0.5d0\nc\n val=coefs(1)+coefs(2)*pip1\nc\nc n is greater than 2. conduct recursion\nc\n do 2000 i=1,nn/2-2\nc\n pip2 = coepnm1(i)*pi +\n 1 (coepnp1(i)+coexpnp1(i)*x22) *pip1\n val=val+coefs(i+2)*pip2\nc\n pi=pip1\n pip1=pip2\nc\n 2000 continue\nc\n return\n end\nc\nc\nc\nc\nc\n subroutine legepeven(x,nn,pols,ninit,\n 1 coepnm1,coepnp1,coexpnp1)\n implicit double precision (a-h,o-z)\n dimension pols(*),coepnm1(*),coepnp1(*),\n 1 coexpnp1(*)\nc\nc This subroutine evaluates even-numbered Legendre polynomials \nc of the argument x, up to order nn+1\nc\nc Input parameters:\nc\nc x - the argument for which the Legendre polynomials are \nc to be evaluated\nc nn - the maximum order for which the Legendre polynomials are\nc to be evaluated\nc ninit - tells the subroutine whether and to what maximum order the \nc arrays coepnm1,coepnp1,coexpnp1 should be initialized.\nc EXPLANATION: The subroutine ill initialize the first ninit/2+2\nc (or so) elements of each of the arrays coepnm1,\nc coepnp1, coexpnp1. On the first call to this subroutine, ninit \nc should be set to the maximum order nn for which this subroutine \nc might have to be called; on subsequent calls, ninit should be \nc set to 0.\nc coepnm1,coepnp1,coexpnp1 - should be nn/2+4 double precision elements long \nc each. Please note that these are input arrays only if ninit \nc (see above) has been set to 0; otherwise, these are output arrays.\nc PLEASE NOTE THAT THAT THESE ARRAYS USED BY THIS SUBROUTINE\nc ARE IDENTICAL TO THE ARRAYS WITH THE SAME NAMES USED BY THE \nc SUBROUTINE LEGEEVEV. IF these aqrrays have been initialized\nc by one of these two subroutines, they do not need to be \nc initialized by the other one.\nc \nc Output parameters:\nc\nc pols - even-numbered Legendre polynomials of the input parameter x\nc (nn/2+2 of them things)\nc EXPLANATION: On exit from the subroutine, pols(1) = P_0 (x),\nc pols(2) = P_2(x), pols(3) =P_4(x), etc.\nc coepnm1,coepnp1,coexpnp1 - should be nn/2+4 double precision elements long \nc each. Please note that these are output parameters only if ninit \nc (see above) has not been set to 0; otherwise, these are input \nc parameters. PLEASE NOTE THAT THAT THESE ARRAYS USED BY THIS SUBROUTINE\nc ARE IDENTICAL TO THE ARRAYS WITH THE SAME NAMES USED BY THE \nc SUBROUTINE LEGEEVEV. If these arrays have been initialized\nc by one of these two subroutines, they do not need to be \nc initialized by the other one.\nc \nc \n if(ninit .eq. 0) goto 1400\nc\n done=1\n n=-1\n i=0\n do 1200 nnn=1,ninit,2\nc\n n=n+2\n i=i+1\nc\n coepnm1(i)=-(5*n+7*(n*done)**2+2*(n*done)**3)\n coepnp1(i)=-(9+24*n+18*(n*done)**2+4*(n*done)**3)\n coexpnp1(i)=15+46*n+36*(n*done)**2+8*(n*done)**3\nc\n d=(2+n*done)*(3+n*done)*(1+2*n*done)\n coepnm1(i)=coepnm1(i)/d\n coepnp1(i)=coepnp1(i)/d\n coexpnp1(i)=coexpnp1(i)/d\nc\n 1200 continue\nc\n 1400 continue\nc\n x22=x**2\nc\n pols(1)=1\n pols(2)=1.5d0*x22-0.5d0\nc\nc n is greater than 2. conduct recursion\nc\n do 2000 i=1,nn/2\nc\n pols(i+2) = coepnm1(i)*pols(i) +\n 1 (coepnp1(i)+coexpnp1(i)*x22) *pols(i+1)\nc\n 2000 continue\nc\n return\n end\nc\nc\nc\nc\nc\n subroutine legepodd(x,nn,pols,ninit,\n 1 coepnm1,coepnp1,coexpnp1)\n implicit double precision (a-h,o-z)\n dimension pols(*),coepnm1(1),coepnp1(1),\n 1 coexpnp1(1)\nc\nc This subroutine evaluates odd-numbered Legendre polynomials \nc of the argument x, up to order nn+1\nc\nc Input parameters:\nc\nc x - the argument for which the Legendre polynomials are \nc to be evaluated\nc nn - the maximum order for which the Legendre polynomials are\nc to be evaluated\nc ninit - tells the subroutine whether and to what maximum order the \nc arrays coepnm1,coepnp1,coexpnp1 should be initialized.\nc EXPLANATION: The subroutine will initialize the first ninit/2+2\nc (or so) elements of each of the arrays coepnm1,\nc coepnp1, coexpnp1. On the first call to this subroutine, ninit \nc should be set to the maximum order nn for which this subroutine \nc might have to be called; on subsequent calls, ninit should be \nc set to 0.\nc coepnm1,coepnp1,coexpnp1 - should be nn/2+4 double precision elements long \nc each. Please note that these are input arrays only if ninit \nc (see above) has been set to 0; otherwise, these are output arrays.\nc \nc Output parameters:\nc\nc pols - the odd-numbered Legendre polynomials of the input parameter x\nc (nn/2+2 of them things)\nc EXPLANATION: On exit from the subroutine, pols(1) = P_1(x),\nc pols(2) = P_3(x), pols(3) = P_5 (x), etc.\nc coepnm1,coepnp1,coexpnp1 - should be nn/2+4 double precision elements long \nc each. Please note that these are output parameters only if ninit \nc (see above) has not been set to 0; otherwise, these are input \nc parameters. PLEASE NOTE THAT THAT THESE ARRAYS USED BY THIS \nc SUBROUTINE ARE IDENTICAL TO THE ARRAYS WITH THE SAME NAMES \nc SUSED BY THE UBROUTINE LEGEODEV. IF these arrays have been \nc initialized by one of these two subroutines, they do not need \nc to be initialized by the other one.\nc \n if(ninit .eq. 0) goto 1400\n done=1\n n=0\n i=0\nc\n do 1200 nnn=2,ninit,2\nc\n n=n+2\n i=i+1\nc\n coepnm1(i)=-(5*n+7*(n*done)**2+2*(n*done)**3)\n coepnp1(i)=-(9+24*n+18*(n*done)**2+4*(n*done)**3)\n coexpnp1(i)=15+46*n+36*(n*done)**2+8*(n*done)**3\nc\n d=(2+n*done)*(3+n*done)*(1+2*n*done)\n coepnm1(i)=coepnm1(i)/d\n coepnp1(i)=coepnp1(i)/d\n coexpnp1(i)=coexpnp1(i)/d\nc\n 1200 continue\nc\n 1400 continue\nc\n x22=x**2\nc\n pols(1)=x\n pols(2)=x*(2.5d0*x22-1.5d0)\nc\n do 2000 i=1,nn/2\nc\n pols(i+2) = coepnm1(i)*pols(i) +\n 1 (coepnp1(i)+coexpnp1(i)*x22)*pols(i+1)\nc\n 2000 continue\nc\n return\n end\nc\nc\nc\nc\nc\n subroutine legefdeq(x,val,der,coefs,n)\n implicit double precision (a-h,o-z)\n dimension coefs(*)\nC\nC This subroutine computes the value and the derivative\nc of a Legendre Q-expansion with coefficients coefs\nC at point X in interval (-1,1); please note that this is\nc the evil twin of the subroutine legefder, evaluating the\nc proper (P-function) Legendre expansion\nc\nc input parameters:\nc\nC X = evaluation point\nC coefs = expansion coefficients\nC N = order of expansion \nc\nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc\nc output parameters:\nc\nC VAL = computed value\nC der = computed value of the derivative\nC\nc\n val=0\n der=0\nc\n d= log( (1+x) /(1-x) ) /2\n pkm1=d\n pk=d*x-1\nc\n pk=d\n pkp1=d*x-1\n\n derk=(1/(1+x)+1/(1-x)) /2\n derkp1=d + derk *x \nc\n val=coefs(1)*pk+coefs(2)*pkp1\n der=coefs(1)*derk+coefs(2)*derkp1\nc\nc if n=0 or n=1 - exit\nc\n if(n .ge. 2) goto 1200\nc\n if(n .eq. 0) return\nc\n return\n 1200 continue\nc\nc n is greater than 2. conduct recursion\nc\n do 2000 k=1,n-1\n pkm1=pk\n pk=pkp1\nc\n pkp1=( (2*k+1)*x*pk-k*pkm1 )/(k+1)\nc\n derkm1=derk\n derk=derkp1\nc\n derkp1= ( (2*k+1)*pk+(2*k+1)*x*derk - k*derkm1 )/(k+1)\nc\n val=val+coefs(k+2)*pkp1\n der=der+coefs(k+2)*derkp1\nc\n 2000 continue\nc\n return\n end\nc\nc\nc\nc\nc\n subroutine legeqs(x,n,pols,ders)\n implicit double precision (a-h,o-z)\n dimension pols(*),ders(*)\nc\nc This subroutine calculates the values and derivatives of \nc a bunch of Legendre Q-functions at the user-specified point \nc x on the interval (-1,1)\nc\nc Input parameters:\nc\nc x - the point on the interval [-1,1] where the Q-functions and \nc their derivatives are to be evaluated\nc n - the highest order for which the functions are to be evaluated\nc \nc Output parameters:\nc\nc pols - the values of the Q-functions (the evil twins of the \nc Legeendre polynomials) at the point x (n+1 of them things)\nc ders - the derivatives of the Q-functions (the evil twins of the \nc Legeendre polynomials) at the point x (n+1 of them things)\nc \nc\n d= log( (1+x) /(1-x) ) /2\n pkm1=d\n pk=d*x-1\nc\n pk=d\n pkp1=d*x-1\n\n derk=(1/(1+x)+1/(1-x)) /2\n derkp1=d + derk *x \nc\nc if n=0 or n=1 - exit\nc\n if(n .ge. 2) goto 1200\n pols(1)=pk\n ders(1)=derk\n if(n .eq. 0) return\nc\n pols(2)=pkp1\n ders(2)=derkp1\n return\n 1200 continue\nc\n pols(1)=pk\n pols(2)=pkp1\nc\nc n is greater than 2. conduct recursion\nc\n ders(1)=derk\n ders(2)=derkp1\nc\n do 2000 k=1,n-1\n pkm1=pk\n pk=pkp1\nc\n pkp1=( (2*k+1)*x*pk-k*pkm1 )/(k+1)\n pols(k+2)=pkp1\nc\n derkm1=derk\n derk=derkp1\nc\n derkp1= ( (2*k+1)*pk+(2*k+1)*x*derk - k*derkm1 )/(k+1)\n ders(k+2)=derkp1\n 2000 continue\nc\n return\n end\nc\nc\nc\nc\nc\n\n\n subroutine legeq(x,n,pol,der)\n implicit double precision (a-h,o-z)\nc\nc This subroutine calculates the value and derivative of \nc a Legendre Q-function at the user-specified point \nc x on the interval (-1,1)\nc\nc\nc Input parameters:\nc\nc x - the point on the interval [-1,1] where the Q-functions and \nc their derivatives are to be evaluated\nc n - the order for which the function is to be evaluated\nc \nc Output parameters:\nc\nc pol - the value of the n-th Q-function (the evil twin of the \nc Legeendre polynomial) at the point x \nc ders - the derivatives of the Q-function at the point x \nc \nc\n d= log( (1+x) /(1-x) ) /2\n pk=d\n pkp1=d*x-1\nc\nc if n=0 or n=1 - exit\nc\n if(n .ge. 2) goto 1200\n pol=d\n\n der=(1/(1+x)+1/(1-x)) /2\n\n if(n .eq. 0) return\nc\n pol=pkp1\n der=d + der *x \n return\n 1200 continue\nc\nc n is greater than 1. conduct recursion\nc\n do 2000 k=1,n-1\n pkm1=pk\n pk=pkp1\n pkp1=( (2*k+1)*x*pk-k*pkm1 )/(k+1)\n 2000 continue\nc\nc calculate the derivative\nc\n pol=pkp1\n der=n*(x*pkp1-pk)/(x**2-1)\n return\n end\n\nc\nc\nc\nc\nc\n SUBROUTINE legecFDE(X,VAL,der,PEXP,N)\n IMPLICIT double precision (A-H,O-Z)\n double complex PEXP(*),val,der\nC\nC This subroutine computes the value and the derivative\nc of a gaussian expansion with complex coefficients PEXP\nC at point X in interval [-1,1].\nc\nc input parameters:\nc\nC X = evaluation point\nC PEXP = expansion coefficients\nC N = order of expansion \nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc\nc output parameters:\nc\nC VAL = computed value\nC der = computed value of the derivative\nC\nC\n done=1\n pjm2=1\n pjm1=x\n derjm2=0\n derjm1=1\nc\n val=pexp(1)*pjm2+pexp(2)*pjm1 \n der=pexp(2)\nc\n DO 600 J = 2,N\nc\n pj= ( (2*j-1)*x*pjm1-(j-1)*pjm2 ) / j\n val=val+pexp(j+1)*pj\nc\n derj=(2*j-1)*(pjm1+x*derjm1)-(j-1)*derjm2\nc\n derj=derj/j\n der=der+pexp(j+1)*derj\nc \n pjm2=pjm1\n pjm1=pj\n derjm2=derjm1\n derjm1=derj\n 600 CONTINUE\nc\n RETURN\n END\nc\nc\nc\nc\nc\n SUBROUTINE legecFD2(X,VAL,der,PEXP,N,\n 1 pjcoefs1,pjcoefs2,ninit)\n IMPLICIT double precision (A-H,O-Z)\n double precision pjcoefs1(*),pjcoefs2(*)\n double complex PEXP(*),val,der\nc\nC This subroutine computes the value and the derivative\nc of a Legendre expansion with complex coefficients PEXP\nC at point X in interval [-1,1].\nc\nc input parameters:\nc\nC X - evaluation point\nC PEXP - expansion coefficients\nC N - order of expansion \nc pjcoefs1, pjcoefs2 - two arrays precomputed on a previous call \nc on a previous call to this subroutine. Please note that this\nc is only an input parameter if the parameter ninit (see below) \nc has been set to 0; otherwise, these are output parameters\nc ninit - tells the subroutine whether and to what maximum order the \nc arrays coepnm1,coepnp1,coexpnp1 should be initialized.\nc EXPLANATION: The subroutine will initialize the first ninit\nc elements of each of the arrays pjcoefs1, pjcoefs2. On the first \nc call to this subroutine, ninit should be set to the maximum \nc order n for which this subroutine might have to be called; \nc on subsequent calls, ninit should be set to 0. PLEASE NOTE \nc THAT THAT THESE ARRAYS USED BY THIS SUBROUTINE\nc ARE IDENTICAL TO THE ARRAYS WITH THE SAME NAMES USED BY THE \nc SUBROUTINE LEGEEXE2. If these arrays have been initialized\nc by one of these two subroutines, they do not need to be \nc initialized by the other one.\nc\nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc\nc output parameters:\nc\nC VAL - computed value\nC der - computed value of the derivative\nC\n if(ninit .eq. 0) goto 1400\nc\n done=1\n do 1200 j=2,ninit\nc\n pjcoefs1(j)=(2*j-done)/j\n pjcoefs2(j)=-(j-done)/j\nc\n 1200 continue\nc \n ifcalled=1\n 1400 continue\nc\n pjm2=1\n pjm1=x\n derjm2=0\n derjm1=1\nc\n val=pexp(1)*pjm2+pexp(2)*pjm1 \n der=pexp(2)\nc\n DO 1600 J = 2,N\nc\ncccc pj= ( (2*j-1)*x*pjm1-(j-1)*pjm2 ) / j\nc\n pj= pjcoefs1(j)*x*pjm1+pjcoefs2(j)*pjm2\n\n\n val=val+pexp(j+1)*pj\nc\ncccc derj=(2*j-1)*(pjm1+x*derjm1)-(j-1)*derjm2\n derj=pjcoefs1(j)*(pjm1+x*derjm1)+pjcoefs2(j)*derjm2\n\nccc call prin2('derj=*',derj,1)\n\n\ncccc derj=derj/j\n der=der+pexp(j+1)*derj\nc \n pjm2=pjm1\n pjm1=pj\n derjm2=derjm1\n derjm1=derj\n 1600 CONTINUE\nc\n RETURN\n END\nc\nc\nc\nc\nc\n SUBROUTINE legecva2(X,VAL,PEXP,N,\n 1 pjcoefs1,pjcoefs2,ninit)\n IMPLICIT double precision (A-H,O-Z)\n double precision pjcoefs1(*),pjcoefs2(*)\n double complex PEXP(*),val\nc\nC This subroutine computes the value of a Legendre expansion \nc with complex coefficients PEXP at point X in interval [-1,1].\nc\nc input parameters:\nc\nC X - evaluation point\nC PEXP - expansion coefficients\nC N - order of expansion \nc pjcoefs1, pjcoefs2 - two arrays precomputed on a previous call \nc on a previous call to this subroutine. Please note that this\nc is only an input parameter if the parameter ninit (see below) \nc has been set to 0; otherwise, these are output parameters\nc ninit - tells the subroutine whether and to what maximum order the \nc arrays coepnm1,coepnp1,coexpnp1 should be initialized.\nc EXPLANATION: The subroutine will initialize the first ninit\nc elements of each of the arrays pjcoefs1, pjcoefs2. On the first \nc call to this subroutine, ninit should be set to the maximum \nc order n for which this subroutine might have to be called; \nc on subsequent calls, ninit should be set to 0. PLEASE NOTE \nc THAT THAT THESE ARRAYS USED BY THIS SUBROUTINE\nc ARE IDENTICAL TO THE ARRAYS WITH THE SAME NAMES USED BY THE \nc SUBROUTINE LEGEEXE2. If these arrays have been initialized\nc by one of these two subroutines, they do not need to be \nc initialized by the other one.\nc\nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc\nc output parameters:\nc\nC VAL - computed value\nC\n if(ninit .eq. 0) goto 1400\nc\n done=1\n do 1200 j=2,ninit\nc\n pjcoefs1(j)=(2*j-done)/j\n pjcoefs2(j)=-(j-done)/j\nc\n 1200 continue\nc \n ifcalled=1\n 1400 continue\nc\n pjm2=1\n pjm1=x\nc\n val=pexp(1)*pjm2+pexp(2)*pjm1 \nc\n DO 1600 J = 2,N\nc\n pj= pjcoefs1(j)*x*pjm1+pjcoefs2(j)*pjm2\n val=val+pexp(j+1)*pj\nc\n pjm2=pjm1\n pjm1=pj\n 1600 CONTINUE\nc\n RETURN\n END\n\n\n", "meta": {"hexsha": "ffd2177b435c7b645fc6b0349b312ab6238fb1ba", "size": 56249, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/Common/legeexps.f", "max_stars_repo_name": "jmark/FMM3D", "max_stars_repo_head_hexsha": "fd26f2b71f5dfd6e20bf797d3d01b8bb98dbc602", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Common/legeexps.f", "max_issues_repo_name": "jmark/FMM3D", "max_issues_repo_head_hexsha": "fd26f2b71f5dfd6e20bf797d3d01b8bb98dbc602", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Common/legeexps.f", "max_forks_repo_name": "jmark/FMM3D", "max_forks_repo_head_hexsha": "fd26f2b71f5dfd6e20bf797d3d01b8bb98dbc602", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.3214787085, "max_line_length": 78, "alphanum_fraction": 0.6074419101, "num_tokens": 17910, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475699138558, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7840567803663865}} {"text": "subroutine cudaclaw_qinit(maxmx,maxmy,meqn,mbc,mx,my, & \n xlower,ylower,dx,dy,q,maux,aux)\n\n !! # Set initial conditions for q.\n !! # Acoustics with smooth radially symmetric profile to test accuracy\n\n implicit none\n integer :: maxmx, maxmy, meqn, mbc, mx, my, maux\n double precision :: xlower, ylower, dx, dy\n double precision :: q(1-mbc:maxmx+mbc, 1-mbc:maxmy+mbc, meqn)\n double precision :: aux(1-mbc:maxmx+mbc, 1-mbc:maxmy+mbc, maux)\n\n double precision :: pi, pi2\n common /compi/ pi, pi2\n\n integer i,j\n double precision :: xc, yc, rc, pressure, width\n\n width = 0.2d0\n\n do i = 1-mbc,mx+mbc\n xc = xlower + (i - 0.5d0)*dx\n do j = 1-mbc,my+mbc\n yc = ylower + (j - 0.5d0)*dy\n rc = dsqrt(xc**2 + yc**2)\n\n if (abs(rc-0.5d0) .le. width) then\n pressure = 1.d0 + cos(pi*(rc - 0.5d0)/width)\n else\n pressure = 0.d0\n endif\n q(i,j,1) = pressure\n q(i,j,2) = 0.d0\n q(i,j,3) = 0.d0\n end do\n end do\n return\nend subroutine cudaclaw_qinit\n", "meta": {"hexsha": "fe40adb53e7bf17355e7a7d5b5142704cee6c26b", "size": 1109, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/cudaclaw/acoustics/2d/radial/user_cuda/qinit.f90", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/cudaclaw/acoustics/2d/radial/user_cuda/qinit.f90", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/cudaclaw/acoustics/2d/radial/user_cuda/qinit.f90", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 28.4358974359, "max_line_length": 74, "alphanum_fraction": 0.5482416592, "num_tokens": 399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.7840534559733995}} {"text": "implicit none\r\ndouble complex :: x, xold, f, fprime, top, bot\r\n\r\nx = (1.0d0, 3.0d0)\r\nxold = 2.0d0 * x\r\n\r\ndo while (abs(x - xold) > 1.0d-11)\r\n xold = x\r\n top = f(x)\r\n bot = fprime(x)\r\n x = x-top/bot\r\n print*, 'x = ', x\r\n print*, top\r\n print*,\r\nend do\r\nprint*, 'End of program.'\r\n\r\nstop\r\nend\r\n\r\ndouble complex function f(x)\r\n implicit none\r\n double complex :: x\r\n\r\n f = x**2 + 3.0d0\r\n\r\n return\r\nend\r\n\r\ndouble complex function fprime(x)\r\n implicit none\r\n double complex :: x\r\n\r\n fprime = 2.0d0 * x\r\n\r\n return\r\nend \r\n", "meta": {"hexsha": "ad8c407e4001fdf56167776475062cb4f0db83e7", "size": 528, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "4670 Numerical Analysis/Class Examples/newton1.f90", "max_stars_repo_name": "mwebber3/UnderGraduateCourses", "max_stars_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4670 Numerical Analysis/Class Examples/newton1.f90", "max_issues_repo_name": "mwebber3/UnderGraduateCourses", "max_issues_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4670 Numerical Analysis/Class Examples/newton1.f90", "max_forks_repo_name": "mwebber3/UnderGraduateCourses", "max_forks_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.8947368421, "max_line_length": 47, "alphanum_fraction": 0.5625, "num_tokens": 196, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012701768145, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7840113818061561}} {"text": "REAL FUNCTION ave_value ( func, first_value, last_value, n )\r\n!\r\n! Purpose:\r\n! To calculate the average value of function \"func\" over the \r\n! range [first_value, last_value] by taking n evenly-spaced\r\n! samples over the range, and averaging the results. Function \r\n! \"func\" is passed to this routine via a dummy argument.\r\n!\r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 11/24/06 S. J. Chapman Original code\r\n!\r\nIMPLICIT NONE\r\n\r\n! Data dictionary: declare calling parameter types & definitions\r\nREAL, EXTERNAL :: func ! Function to be evaluated\r\nREAL, INTENT(IN) :: first_value ! First value in range\r\nREAL, INTENT(IN) :: last_value ! Last value in rnage\r\nINTEGER, INTENT(IN) :: n ! Number of samples to average\r\n\r\n! Data dictionary: declare local variable types & definitions\r\nREAL :: delta ! Step size between samples\r\nINTEGER :: i ! Index variable\r\nREAL :: sum ! Sum of values to average\r\n \r\n! Get step size.\r\ndelta = ( last_value - first_value ) / REAL(n-1)\r\n \r\n! Accumulate sum.\r\nsum = 0.\r\nDO i = 1, n\r\n sum = sum + func ( REAL(i-1) * delta )\r\nEND DO\r\n \r\n! Get average.\r\nave_value = sum / REAL(n)\r\n \r\nEND FUNCTION ave_value\r\n", "meta": {"hexsha": "7fcc9a493668ce4e1c28fd18aadee25c17485ec0", "size": 1330, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap7/ave_value.f90", "max_stars_repo_name": "yangyang14641/FortranLearning", "max_stars_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-03-12T02:18:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-05T07:58:56.000Z", "max_issues_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap7/ave_value.f90", "max_issues_repo_name": "yangyang14641/FortranLearning", "max_issues_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap7/ave_value.f90", "max_forks_repo_name": "yangyang14641/FortranLearning", "max_forks_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-05-11T02:36:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T06:36:55.000Z", "avg_line_length": 33.25, "max_line_length": 67, "alphanum_fraction": 0.6037593985, "num_tokens": 321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012701768144, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7840113798077029}} {"text": "!============================================================================\r\n! Name : RBC_F90.f90\r\n! Description : Basic RBC model with full depreciation\r\n! Date : July 21, 2013\r\n!============================================================================\r\n\r\nprogram RBC_F90\r\n !----------------------------------------------------------------\r\n ! 0. variables to be defined\r\n !----------------------------------------------------------------\r\n \r\n implicit none\r\n \r\n integer, parameter :: nGridCapital = 17820\r\n integer, parameter :: nGridProductivity = 5\r\n \r\n real(8), parameter :: tolerance = 0.0000001\r\n real :: time_begin, time_end\t\r\n\r\n integer :: nCapital, nCapitalNextPeriod, gridCapitalNextPeriod, nProductivity, nProductivityNextPeriod \r\n integer :: iteration\r\n \r\n real(8) :: aalpha, bbeta, capitalSteadyState, outputSteadyState, consumptionSteadyState\r\n real(8) :: valueHighSoFar, valueProvisional, consumption, capitalChoice\t\r\n real(8) :: maxDifference,diff,diffHighSoFar\r\n\t \r\n real(8), dimension(nGridProductivity) :: vProductivity\r\n real(8), dimension(nGridProductivity,nGridProductivity) :: mTransition \r\n real(8), dimension(nGridCapital) :: vGridCapital\r\n real(8), dimension(nGridCapital,nGridProductivity) :: mOutput, mValueFunction, mValueFunctionNew, mPolicyFunction\r\n real(8), dimension(nGridCapital,nGridProductivity) :: expectedValueFunction\r\n \r\n call CPU_TIME(time_begin)\r\n \r\n !----------------------------------------------------------------\r\n ! 1. Calibration\r\n !----------------------------------------------------------------\r\n \r\n aalpha = 0.33333333333; ! Elasticity of output w.r.t\r\n bbeta = 0.95 ! Discount factor\r\n\r\n ! Productivity value\r\n vProductivity = (/0.9792, 0.9896, 1.0000, 1.0106, 1.0212/)\r\n\r\n ! Transition matrix\r\n mTransition = reshape( (/0.9727, 0.0273, 0., 0., 0., &\r\n 0.0041, 0.9806, 0.0153, 0.0, 0.0, &\r\n 0.0, 0.0082, 0.9837, 0.0082, 0.0, &\r\n 0.0, 0.0, 0.0153, 0.9806, 0.0041, &\r\n 0.0, 0.0, 0.0, 0.0273, 0.9727 /), (/5,5/))\r\n \r\n mTransition = transpose(mTransition)\r\n\r\n !----------------------------------------------------------------\r\n ! 2. Steady state\r\n !----------------------------------------------------------------\r\n\r\n capitalSteadyState = (aalpha*bbeta)**(1.0/(1.0-aalpha))\r\n outputSteadyState = capitalSteadyState**(aalpha)\r\n consumptionSteadyState = outputSteadyState-capitalSteadyState\r\n \r\n print *, 'Steady State values'\r\n print *, 'Output: ', outputSteadyState, 'Capital: ', capitalSteadyState, 'Consumption: ', consumptionSteadyState\r\n \r\n ! Grid for capital\r\n do nCapital = 1, nGridCapital\r\n vGridCapital(nCapital) = 0.5*capitalSteadyState+0.00001*(nCapital-1)\r\n end do\r\n\r\n !----------------------------------------------------------------\r\n ! 3. Pre-build Output for each point in the grid\r\n !----------------------------------------------------------------\r\n \r\n do nProductivity = 1, nGridProductivity\r\n do nCapital = 1, nGridCapital\r\n mOutput(nCapital, nProductivity) = vProductivity(nProductivity)*(vGridCapital(nCapital)**aalpha)\r\n end do\r\n end do\r\n\r\n !----------------------------------------------------------------\r\n ! 4. Main Iteration\r\n !----------------------------------------------------------------\r\n\r\n maxDifference = 10.0\r\n iteration = 0\r\n \r\n do while (maxDifference>tolerance)\r\n \r\n expectedValueFunction = matmul(mValueFunction,transpose(mTransition));\r\n \r\n do nProductivity = 1,nGridProductivity\r\n \r\n ! We start from previous choice (monotonicity of policy function)\r\n\r\n gridCapitalNextPeriod = 1\r\n \r\n do nCapital = 1,nGridCapital\r\n \r\n valueHighSoFar = -100000.0\r\n \r\n do nCapitalNextPeriod = gridCapitalNextPeriod,nGridCapital\r\n\r\n consumption = mOutput(nCapital,nProductivity)-vGridCapital(nCapitalNextPeriod)\r\n valueProvisional = (1.0-bbeta)*log(consumption)+bbeta*expectedValueFunction(nCapitalNextPeriod,nProductivity)\r\n\r\n if (valueProvisional>valueHighSoFar) then ! we break when we have achieved the max\r\n valueHighSoFar = valueProvisional\r\n capitalChoice = vGridCapital(nCapitalNextPeriod)\r\n gridCapitalNextPeriod = nCapitalNextPeriod\r\n else \r\n exit\r\n end if\r\n\r\n end do\r\n\r\n mValueFunctionNew(nCapital,nProductivity) = valueHighSoFar\r\n mPolicyFunction(nCapital,nProductivity) = capitalChoice\r\n \r\n end do\r\n \r\n end do\r\n\r\n maxDifference = maxval((abs(mValueFunctionNew-mValueFunction)))\r\n mValueFunction = mValueFunctionNew\r\n \r\n iteration = iteration+1\r\n if (mod(iteration,10)==0 .OR. iteration==1) then\r\n print *, 'Iteration:', iteration, 'Sup Diff:', MaxDifference\r\n end if\r\n \r\n end do\r\n \r\n !----------------------------------------------------------------\r\n ! 5. PRINT RESULTS\r\n !----------------------------------------------------------------\r\n \r\n print *, 'Iteration:', iteration, 'Sup Diff:', MaxDifference\r\n print *, ' '\r\n print *, 'My check:', mPolicyFunction(1000,3)\r\n print *, ' '\r\n\r\n call CPU_TIME (time_end)\r\n print *, 'Elapsed time is ', time_end - time_begin\r\n\r\nend program RBC_F90\r\n", "meta": {"hexsha": "be441742397b745b081804dc5beb77ea96a2e1ba", "size": 5528, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "RBC_F90.f90", "max_stars_repo_name": "leitec/Comparison-Programming-Languages-Economics", "max_stars_repo_head_hexsha": "dcff2d7135fb84c8f389f3ed2bea8500f7f31d11", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 197, "max_stars_repo_stars_event_min_datetime": "2015-01-04T10:13:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T19:01:46.000Z", "max_issues_repo_path": "RBC_F90.f90", "max_issues_repo_name": "leitec/Comparison-Programming-Languages-Economics", "max_issues_repo_head_hexsha": "dcff2d7135fb84c8f389f3ed2bea8500f7f31d11", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 15, "max_issues_repo_issues_event_min_datetime": "2015-05-24T17:29:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-25T20:54:46.000Z", "max_forks_repo_path": "RBC_F90.f90", "max_forks_repo_name": "leitec/Comparison-Programming-Languages-Economics", "max_forks_repo_head_hexsha": "dcff2d7135fb84c8f389f3ed2bea8500f7f31d11", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 119, "max_forks_repo_forks_event_min_datetime": "2015-01-01T17:08:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-21T17:41:39.000Z", "avg_line_length": 37.8630136986, "max_line_length": 124, "alphanum_fraction": 0.5097684515, "num_tokens": 1334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012640659995, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7840113767406645}} {"text": "program derivative\nimplicit none\n\nreal(kind=8) x1, x2, fx1, fx2, df, error, analytical_derivative\n\nx1 = 0.1\nx2 = 0.4\n\nwrite(*,*) \"x1: \", x1, \"x2: \", x2\n\nfx1 = 3*(x1**3) + x1**2 - x1\nfx2 = 3*(x2**3) + x2**2 - x2\n\nwrite(*,*) \"fx1: \", fx1, \"fx2: \", fx2\n\ndf = (fx2 - fx1)/(x2 - x1)\nanalytical_derivative = 9*x1*x1 + 2*x1 - 1\n\nwrite(*,*) \"df: \", df\nwrite(*,*) \"analytical: \", analytical_derivative\n\nerror = analytical_derivative - df\n\nwrite(*,*) \"error: \", error\n\nend program derivative\n", "meta": {"hexsha": "85eb816fa3d041b94c874f3d0ecdfa1720ce2206", "size": 482, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ME_Numerical_Methods/HW1/ex5/der.f95", "max_stars_repo_name": "ElenaKusevska/Fortran_exercises", "max_stars_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ME_Numerical_Methods/HW1/ex5/der.f95", "max_issues_repo_name": "ElenaKusevska/Fortran_exercises", "max_issues_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ME_Numerical_Methods/HW1/ex5/der.f95", "max_forks_repo_name": "ElenaKusevska/Fortran_exercises", "max_forks_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.8518518519, "max_line_length": 63, "alphanum_fraction": 0.5975103734, "num_tokens": 203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.83973396967765, "lm_q1q2_score": 0.783833560365229}} {"text": "! Objetivo: Calcular a integral da funcao f(x) = sin(x) no intervalo\n! [0, pi] utilizando o metodo de monte carlo amostragem por\n!\t importancia\n\nPROGRAM monte_carlo_9\n\n USE nrtype\n USE nrutil\n USE ran_state, ONLY: ran_seed\n USE nr, ONLY: ran1\n\n IMPLICIT none\n INTEGER :: iseed = 1234, intervalo, sub_intervalo\n REAL :: aleatorio, func, func_elev2, soma_func = 0., integral_func, N_chamadas\n REAL :: media = 0., media_elev2 = 0., erro, soma_func_elev2 = 0.\n REAL :: x_y, theta_y\n REAL, PARAMETER :: div_picubo_6= pi**3/6.\n INTEGER, PARAMETER :: dados_monte_carlo_9 = 7, quant_pontos = 1000, quant_amostras = 10\n\n CALL RAN_SEED(SEQUENCE = iseed)\n\n OPEN( dados_monte_carlo_9,file=\"dados_monte_carlo_9.dat\")\n DO intervalo = 10, quant_pontos, 10\n DO sub_intervalo = 1, quant_amostras\n CALL ran1(aleatorio)\n\n theta_y = ACOS(2.*aleatorio -1.)\n\n x_y =-pi*COS((theta_y-2.*pi)/3.) + pio2\n func = div_picubo_6*SIN(x_y)/(x_y*(pi-x_y))\n func_elev2 = func**2\n soma_func = soma_func + func\n soma_func_elev2 = soma_func_elev2 + func_elev2\n END DO\n N_chamadas = real(intervalo)\n media = soma_func/N_chamadas\n media_elev2 = soma_func_elev2/N_chamadas\n erro = pi*sqrt(((media_elev2-(media)**2))/N_chamadas)\n integral_func = media\n! O valor exato da integral está sendo escrito manualmente em um arquivo.dat \n! separado do programa\n WRITE(dados_monte_carlo_9, *) N_chamadas, integral_func, erro\n END DO\n CLOSE(dados_monte_carlo_9)\n\n PRINT *,\"O melhor resultado eh:\", integral_func,\"com erro de +-\", erro\n\nEND PROGRAM monte_carlo_9\n", "meta": {"hexsha": "701f0350692e8cd0d2d4a5476741d7785a65e637", "size": 1654, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Monte_Carlo/Monte_Carlo_9.f90", "max_stars_repo_name": "GuilhermeMonteiroPeixoto/Computational-Physics-using-Fortran", "max_stars_repo_head_hexsha": "3d2b3dd87d99b451aed5fe1e9e99813390396485", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Monte_Carlo/Monte_Carlo_9.f90", "max_issues_repo_name": "GuilhermeMonteiroPeixoto/Computational-Physics-using-Fortran", "max_issues_repo_head_hexsha": "3d2b3dd87d99b451aed5fe1e9e99813390396485", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Monte_Carlo/Monte_Carlo_9.f90", "max_forks_repo_name": "GuilhermeMonteiroPeixoto/Computational-Physics-using-Fortran", "max_forks_repo_head_hexsha": "3d2b3dd87d99b451aed5fe1e9e99813390396485", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.7551020408, "max_line_length": 90, "alphanum_fraction": 0.676541717, "num_tokens": 544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7838335538281359}} {"text": "module m\n type :: numseq_t(n)\n integer, len :: n = 3\n integer :: vals(n)\n contains\n procedure, pass(this) :: calc => calc_seq\n end type\ncontains\n elemental subroutine calc_seq( this )\n class(numseq_t(n=*)), intent(inout) :: this\n integer :: i, lb, ub\n lb = (this_image()-1)*size(this%vals) ; ub = lb + size(this%vals) - 1\n this%vals = fibonacci_number( [( i, i = lb, ub )] )\n end subroutine\n elemental recursive integer function fibonacci_number( n ) result(num)\n integer, intent(in) :: n\n select case ( n ) \n case ( 0:1 )\n num = n\n case default\n num = fibonacci_number(n-1) + fibonacci_number(n-2) \n end select\n end function\nend module\n use m, only : numseq_t\n type(numseq_t(n=5)) :: numseq[*]\n integer :: i \n call numseq%calc()\n sync all\n if ( this_image() == 1 ) then\n do i = 1, num_images()\n write( *, fmt=\"(*(g0,1x))\", advance=\"no\" ) numseq[i]%vals\n end do\n end if\n", "meta": {"hexsha": "4cddc18e0006ce9a2bd1fe4070409d746e1acab5", "size": 1004, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/more/x1.f90", "max_stars_repo_name": "urbanjost/fpm_tools", "max_stars_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "example/more/x1.f90", "max_issues_repo_name": "urbanjost/fpm_tools", "max_issues_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/more/x1.f90", "max_forks_repo_name": "urbanjost/fpm_tools", "max_forks_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-14T11:36:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-14T11:36:01.000Z", "avg_line_length": 28.6857142857, "max_line_length": 75, "alphanum_fraction": 0.5637450199, "num_tokens": 300, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418283357703, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.7836424781476851}} {"text": "PROGRAM question1\n IMPLICIT NONE\n\n INTEGER :: i = 0\n REAL :: x, exp = 1.0, term = 1.0\n WRITE(*, '(A)', ADVANCE = \"NO\") \"Enter x for calculate exp(x): \"\n READ(*, *) x\n\n ! Infinite DO loop untill it terminates \n DO\n term = term * (x/(i+1)) ! Calculating only one term\n if(term < 10**(-5.0)) exit ! Exit from DO loop and continue after DO loop\n exp = exp + term ! Adding new term in the exponent\n i = i + 1 ! Increment i for next step\n ENDDO\n\n WRITE(*, 10) x, exp ! Printing Output to the console\n 10 FORMAT(\"exp(\", f0.3, \") = \", f0.3)\n\nEND \n", "meta": {"hexsha": "6d413306717f3a2a1f26609cc2138a1d5319c08f", "size": 642, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Practice-1/1.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Practice-1/1.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practice-1/1.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 30.5714285714, "max_line_length": 82, "alphanum_fraction": 0.5202492212, "num_tokens": 200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7835996370916942}} {"text": "SUBROUTINE simul ( a, b, ndim, n, error )\r\n!\r\n! Purpose:\r\n! Subroutine to solve a set of n linear equations in n \r\n! unknowns using Gaussian elimination and the maximum \r\n! pivot technique.\r\n!\r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 11/23/06 S. J. Chapman Original code\r\n!\r\nIMPLICIT NONE\r\n\r\n! Data dictionary: declare calling parameter types & definitions\r\nINTEGER, INTENT(IN) :: ndim ! Dimension of arrays a and b\r\nREAL, INTENT(INOUT), DIMENSION(ndim,ndim) :: a \r\n ! Array of coefficients (n x n).\r\n ! This array is of size ndim x \r\n ! ndim, but only n x n of the \r\n ! coefficients are being used.\r\n ! The declared dimension ndim \r\n ! must be passed to the sub, or\r\n ! it won't be able to interpret\r\n ! subscripts correctly. (This\r\n ! array is destroyed during\r\n ! processing.)\r\nREAL, INTENT(INOUT), DIMENSION(ndim) :: b \r\n ! Input: Right-hand side of eqns.\r\n ! Output: Solution vector.\r\nINTEGER, INTENT(IN) :: n ! Number of equations to solve.\r\nINTEGER, INTENT(OUT) :: error ! Error flag:\r\n ! 0 -- No error\r\n ! 1 -- Singular equations\r\n\r\n\r\n! Data dictionary: declare constants\r\nREAL, PARAMETER :: EPSILON = 1.0E-6 ! A \"small\" number for comparison\r\n ! when determining singular eqns \r\n\r\n! Data dictionary: declare local variable types & definitions\r\nREAL :: factor ! Factor to multiply eqn irow by\r\n ! before adding to eqn jrow\r\nINTEGER :: irow ! Number of the equation currently\r\n ! being processed\r\nINTEGER :: ipeak ! Pointer to equation containing\r\n ! maximum pivot value\r\nINTEGER :: jrow ! Number of the equation compared\r\n ! to the current equation\r\nINTEGER :: kcol ! Index over all columns of eqn\r\nREAL :: temp ! Scratch value\r\n\r\n! Process n times to get all equations...\r\nmainloop: DO irow = 1, n\r\n \r\n ! Find peak pivot for column irow in rows irow to n\r\n ipeak = irow\r\n max_pivot: DO jrow = irow+1, n\r\n IF (ABS(a(jrow,irow)) > ABS(a(ipeak,irow))) THEN\r\n ipeak = jrow\r\n END IF\r\n END DO max_pivot\r\n \r\n ! Check for singular equations. \r\n singular: IF ( ABS(a(ipeak,irow)) < EPSILON ) THEN\r\n error = 1\r\n RETURN\r\n END IF singular\r\n \r\n ! Otherwise, if ipeak /= irow, swap equations irow & ipeak\r\n swap_eqn: IF ( ipeak /= irow ) THEN\r\n DO kcol = 1, n\r\n temp = a(ipeak,kcol)\r\n a(ipeak,kcol) = a(irow,kcol)\r\n a(irow,kcol) = temp \r\n END DO\r\n temp = b(ipeak)\r\n b(ipeak) = b(irow)\r\n b(irow) = temp \r\n END IF swap_eqn\r\n \r\n ! Multiply equation irow by -a(jrow,irow)/a(irow,irow), \r\n ! and add it to Eqn jrow (for all eqns except irow itself).\r\n eliminate: DO jrow = 1, n\r\n IF ( jrow /= irow ) THEN\r\n factor = -a(jrow,irow)/a(irow,irow)\r\n DO kcol = 1, n\r\n a(jrow,kcol) = a(irow,kcol)*factor + a(jrow,kcol)\r\n END DO\r\n b(jrow) = b(irow)*factor + b(jrow)\r\n END IF\r\n END DO eliminate\r\nEND DO mainloop\r\n \r\n! End of main loop over all equations. All off-diagonal\r\n! terms are now zero. To get the final answer, we must\r\n! divide each equation by the coefficient of its on-diagonal\r\n! term.\r\ndivide: DO irow = 1, n\r\n b(irow) = b(irow) / a(irow,irow)\r\n a(irow,irow) = 1.\r\nEND DO divide\r\n \r\n! Set error flag to 0 and return.\r\nerror = 0\r\nEND SUBROUTINE simul\r\n\r\n", "meta": {"hexsha": "42c441f7fd64fc026bbcf5ddce07c7c7de6f73ba", "size": 4215, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap9/simul/simul.f90", "max_stars_repo_name": "yangyang14641/FortranLearning", "max_stars_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-03-12T02:18:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-05T07:58:56.000Z", "max_issues_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap9/simul/simul.f90", "max_issues_repo_name": "yangyang14641/FortranLearning", "max_issues_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap9/simul/simul.f90", "max_forks_repo_name": "yangyang14641/FortranLearning", "max_forks_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-05-11T02:36:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T06:36:55.000Z", "avg_line_length": 39.0277777778, "max_line_length": 72, "alphanum_fraction": 0.4899169632, "num_tokens": 990, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037241905732, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7835996355263073}} {"text": "program pigreco\nimplicit none\ninteger i, n, j\ninteger, parameter :: jmax=150 !Numero di calcoli\nreal :: k(2), o(2), pi, random, c, start, finish, startt, finisht, pimedio(jmax), Tm(jmax)\n\ncall cpu_time(startt) !Calcola tempo totale\n\n! c centri, k è il punto\n\no(1)=0 !origine\no(2)=0\nn=100000 !Inizializza numero lanci\nc=0 !Inizializza c\n\nopen(UNIT=3, FILE=\"/Volumes/FILIPPO/Fortran/pigreco.csv\", STATUS=\"REPLACE\") !Genera file\n\nWRITE(3,fmt='(A21,I10,A6)') \"Stima di pigreco in: \", n, \" lanci\"\nWRITE(3,fmt='(A15,A16,A15)') \"Valore \", \" Errore % \", \"Tempo \"\n\ncall random_seed !Randomize\n\nDO j=1,jmax\ncall cpu_time(start)\nDO i=1,n !Iniziano i tentativi\ncall random_number(k(1:2))\nIF (distanza(o,k)<1) c=c+1 !verifica dove è il punto e se è il caso incrementa c\nEND DO\n\npi=(c/i)*4 !Assegna pigreco\n\ncall cpu_time(finish)\n\nWRITE(3,fmt='(F13.11,A1,F7.4,F15.4,A2)') pi, \" \", (ABS(pi-3.14159)/3.14159)*100 , ABS(finish-start), \" s\" !Scrive j righe nel file\n\ntm(j)=finish-start\npimedio(j)=pi\n\nc=0 !Azzera i centri\n\nEND DO\n\n!Scrive a schermo il valore medio\nWRITE(*,fmt='(A8,F10.8,A1)') \"Valore: \", SUM(pimedio)/jmax, \";\"\nWRITE(*,fmt='(A8,F6.4,A3)') \"errore: \", (ABS((SUM(pimedio)/jmax)-3.14159)/3.14159)*100, \" %;\"\nWRITE(*,fmt='(A8,F9.4,A8)') \"tempo: \", ABS(SUM(tm)/jmax), \" secondi\"\n\ncall cpu_time(finisht)\n\nWrite(3,fmt='(A17,F15.10,A8)') \"Tempo impiegato: \", ABS(finisht-startt), \" secondi\" !scrive il tempo totalr\n\nCONTAINS\n\nREAL FUNCTION distanza(a,b) !Distanza tra due punti\nREAL, DIMENSION (2) :: a, b\ndistanza=(((a(1)-b(1))**2)+((a(2)-b(2))**2))**0.5\nEND FUNCTION\n\n\nEND PROGRAM pigreco\n", "meta": {"hexsha": "8608ac173474a6f66c4e0ccd3e2c395bea9ffb1c", "size": 1607, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "2_Fortran/pigreco.f95", "max_stars_repo_name": "fvalle1/stuff", "max_stars_repo_head_hexsha": "b9decf9a5dcd4208b2b3cf6710be459b0f5bf3ea", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2_Fortran/pigreco.f95", "max_issues_repo_name": "fvalle1/stuff", "max_issues_repo_head_hexsha": "b9decf9a5dcd4208b2b3cf6710be459b0f5bf3ea", "max_issues_repo_licenses": ["WTFPL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2_Fortran/pigreco.f95", "max_forks_repo_name": "fvalle1/stuff", "max_forks_repo_head_hexsha": "b9decf9a5dcd4208b2b3cf6710be459b0f5bf3ea", "max_forks_repo_licenses": ["WTFPL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.3442622951, "max_line_length": 130, "alphanum_fraction": 0.6589919104, "num_tokens": 654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628702, "lm_q2_score": 0.8459424295406087, "lm_q1q2_score": 0.783599631539465}} {"text": "! An example program from Liao\n PROGRAM TRIANG\n WRITE(*,*) 'AREA is ', AREA3(10.0,8.2,9.9)\n! implicit data type by variable name, I, N integer, all other are real\n! warning of mismatched types for parameter by g77\n! WRITE(*,*) 'AREA is ', AREA3(10,8,9)\n END\n\n FUNCTION AREA3(A,B,C)\n S = (A+B+C)/2.0\n AREA3 = SQRT (S*(S-A)*(S-B)*(S-C))\n END\n", "meta": {"hexsha": "86881bcdaee5d64dc7c112264731ae6f8bcd5668", "size": 380, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/test2007_162.f", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/test2007_162.f", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/test2007_162.f", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 29.2307692308, "max_line_length": 71, "alphanum_fraction": 0.5763157895, "num_tokens": 130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465044347828, "lm_q2_score": 0.8376199673867853, "lm_q1q2_score": 0.7834649085400065}} {"text": "MODULE analytic\n\n USE precise, ONLY : defaultp\n use constants \n\n\n IMPLICIT NONE \n INTEGER, PARAMETER, PRIVATE :: WP=defaultp\n real, parameter, private :: e=2.718281828459045\n\nCONTAINS\n\n\n FUNCTION lamda_n(n,L) result(lamda)\n INTEGER :: n\n REAL(wp) :: L,lamda\n lamda = (2.*n-1)*pi/(2.*L)\n end function lamda_n\n\n\n FUNCTION alpha_(k,rho_c) result(alpha)\n REAL(wp) :: k,rho_c,alpha\n alpha = k/rho_c\n end function alpha_\n \n\n\n subroutine t_exact(L,k_bar,rho_c,n,dt,ncells,loc,temp_exact)\n\n INTEGER :: i ! summation dummy\n INTEGER :: j ! summation dummy\n INTEGER :: n ! timestep\n INTEGER :: ncells ! # of cells\n\n real, parameter :: e=2.718281828459045\n\n real(wp) :: L ! domain length\n real(wp) :: rho_c\n real(wp) :: k_bar\n real(wp) :: alpha\n real(wp) :: lamda\n real(wp) :: rational_term\n real(wp) :: dt\n real(wp) :: t\n\n REAL(wp), DIMENSION(ncells) :: loc ! x locations -> pass cells\n REAL(wp), DIMENSION(ncells) :: temp_exact ! solution\n\n alpha = alpha_(k_bar,rho_c)\n t=n*dt\n\n print '(\"1\")'\n do i=1,ncells\n do j=1,30\n lamda = lamda_n(j,L)\n rational_term = ((-1)**(j+1)) / (-1+2.*j)\n temp_exact(i) = temp_exact(i) + rational_term * e**(-alpha*(lamda**2)*t) *cos(lamda*loc(i))\n !print '(\"3\")'\n end do\n \n temp_exact(i) = (800./pi)*temp_exact(i)\n end do\n\n end subroutine t_exact\n\n\n\nEND MODULE analytic\n", "meta": {"hexsha": "2a8ccd88e3e83d74926b72c4d0df3a10b5de6153", "size": 1531, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/src/analytic.f90", "max_stars_repo_name": "LukeMcCulloch/ShallowWaterEquations", "max_stars_repo_head_hexsha": "108bc60b5b0b75a04088ece4db1fb9d1a95169f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/src/analytic.f90", "max_issues_repo_name": "LukeMcCulloch/ShallowWaterEquations", "max_issues_repo_head_hexsha": "108bc60b5b0b75a04088ece4db1fb9d1a95169f5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/src/analytic.f90", "max_forks_repo_name": "LukeMcCulloch/ShallowWaterEquations", "max_forks_repo_head_hexsha": "108bc60b5b0b75a04088ece4db1fb9d1a95169f5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.1884057971, "max_line_length": 104, "alphanum_fraction": 0.5558458524, "num_tokens": 473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.942506716354847, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7833579107712739}} {"text": " SUBROUTINE angeul( romtx, angls, rad )\r\n !*************************************************************************\r\n !\r\n ! transformation from rotation matrix to euler's angles\r\n !\r\n ! xg = r xn : ang glob -> nodl\r\n !\r\n ! angls(1) : rotation about z axe to take x axis in X-Y plane\r\n ! angls(2) : rotation about x axe to make z and Z coincide\r\n ! angls(3) : rotation about z axe to make x-y coincide with X-Y plane\r\n !\r\n !*************************************************************************\r\n IMPLICIT NONE\r\n !dummy arguments\r\n REAL (kind=8), INTENT(IN) :: romtx(3,3) !rotation matrix (t1,t2,t3)\r\n REAL (kind=8), INTENT(OUT) :: angls(3) !Euler angles\r\n LOGICAL, INTENT(IN), OPTIONAL :: rad !if present angles returned in rads\r\n !local variables\r\n REAL (kind=8) cosda,cosdg,sinda,sindg\r\n REAL (kind=8), PARAMETER :: pid2 = 1.5707963267948966192313216916398, & ! pid2 = ATAN(1d0)*2d0\r\n pi = 3.1415926535897932384626433832795, & ! pi = 2d0*pid2\r\n facto = 57.295779513082320876798154814105, & ! facto= 180d0/pi\r\n cuzer =1.0d-12\r\n\r\n\r\n IF ( romtx(3,3) >= 1d0 ) THEN !full positive proyection over Z axis\r\n angls(2) = 0d0 !second angle is null\r\n ELSE IF ( romtx(3,3) <= -1d0) THEN !full negative proyection over Z axis\r\n angls(2) = pi !second angle is Pi\r\n ELSE ! an intermediate angle exist\r\n angls(2) = ACOS( romtx(3,3) ) !compute angle\r\n END IF\r\n IF (angls(2) == 0d0) THEN !IF t3 is along Z axis\r\n angls(1) = 0d0 !first angle is null\r\n ELSE\r\n IF ( ABS(romtx(2,3)) < cuzer ) THEN\r\n IF (romtx(1,3) > 0d0) THEN\r\n angls(1) = pid2\r\n ELSE\r\n angls(1) =-pid2\r\n END IF\r\n ELSE\r\n angls(1) = ATAN( -romtx(1,3)/romtx(2,3) )\r\n IF (romtx(2,3) > 0d0 ) angls(1) = angls(1) + pi ! cosine of beta negative\r\n END IF\r\n END IF\r\n cosda = COS(angls(1))\r\n sinda = SIN(angls(1))\r\n cosdg = romtx(1,1)*cosda + romtx(2,1)*sinda\r\n sindg =-romtx(1,2)*cosda - romtx(2,2)*sinda\r\n IF (ABS(cosdg) < cuzer) THEN\r\n IF (sindg > 0d0) THEN\r\n angls(3) = pid2\r\n ELSE\r\n angls(3) =-pid2\r\n END IF\r\n ELSE\r\n angls(3) = ATAN( sindg/cosdg )\r\n IF (cosdg < 0.0) angls(3) = angls(3) + pi ! cosine negative\r\n END IF\r\n\r\n ! if code rad is not used in calling\r\n IF (.NOT.PRESENT (rad)) angls = angls*facto ! change radians to degrees\r\n\r\n RETURN\r\n END SUBROUTINE angeul\r\n", "meta": {"hexsha": "617f7296be9f9a388d6e18ba47837e8c5b176715", "size": 2579, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/shelq/angeul.f90", "max_stars_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_stars_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/shelq/angeul.f90", "max_issues_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_issues_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/shelq/angeul.f90", "max_forks_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_forks_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.4925373134, "max_line_length": 99, "alphanum_fraction": 0.5180302443, "num_tokens": 852, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947086083138, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.783342787623819}} {"text": "\n! Program by: Jostein Brandshoi\n\nPROGRAM exercise_2d\n ! This program solves the diffusion equation numerically for the atmospheric with the initial-\n ! and boundary conditions given in the exercise. After execution a file (with filename specified as a command line\n ! argument) will be outputed with the results for specific time-values. Thi program can be compiled and executed\n ! by itself just fine, but the script visualize_results.py automates the process and provides plot of the results.\n IMPLICIT NONE\n\n ! ------------------------------- VARIABLE DECLARATIONS -------------------------------\n integer :: j, n ! Counter variables used in loops below (j: space, n: time)\n integer, parameter :: j_max = 27, n_max = 1201 ! Maximum number of gridpoints in space and time\n\n double precision, parameter :: pi = 4 * atan(1.0) ! Defining pi using inverse tangent [dim-less]\n double precision, parameter :: H = 270.0 ! Hight of the atmospheric boundary layer [m]\n double precision, parameter :: psi_0 = 10.0 ! Initial maximum temperature [deg C]\n double precision, parameter :: K = 0.45 ! K = (kappa * delta_t) / delta_z [dim-less]\n double precision, parameter :: kappa_A = 30.0 ! Diffusion coefficient for the atmospehere [m^2/s]\n double precision, parameter :: delta_z = H / (j_max - 1.0) ! Increment in space (j_max points implies (j_max - 1) steps) [m]\n double precision, parameter :: delta_t = (K * delta_z ** 2) / kappa_A ! Increment in time [s]\n\n double precision, dimension(1 : j_max) :: psi_n, psi_np1 ! Arrays to store psi at n'th and (n + 1)'th time step [deg C]\n double precision :: z_j ! z-value in [0, H] to represent height. Used in initial con. [m]\n\n character(len = 32) :: output_filename ! Variable to hold output filename specified by cmd-line arg\n ! -------------------------------------------------------------------------------------\n\n ! -------------------------------- INITIAL CONDITION ----------------------------------\n do j = 1, j_max\n z_j = (j - 1) * delta_z ! Compute z-value at j'th grid point\n psi_n(j) = psi_0 * sin((pi * z_j) / H) ! Compute psi (t = 0) for each z_j according to the inital con.\n end do\n ! -------------------------------------------------------------------------------------\n\n ! ------- GETTING FILENAME FROM CMD-LINE AND WRITE RESULTS TO .DAT-FILE. EACH LINE CORRESPONDS TO ONE N-VALUES -------\n CALL GET_COMMAND_ARGUMENT(1, output_filename) ! Get command line argument that specifies output file\n open(unit = 10, file = output_filename, form = \"formatted\") ! Open file that will store results based on cmd-line arg\n ! -------------------------------------------------------------------------------------\n\n ! ------------------------ SOLVING THE EQUATION WITH FTCS-SCHEME ----------------------\n do n = 0, n_max - 2\n do j = 2, j_max - 1\n psi_np1(1) = 0.0 ! The bottom (z = 0) is held at 0 deg C for all times\n psi_np1(j_max) = 0.0 ! The top (z = H) is held at 0 deg C for all times\n psi_np1(j) = psi_n(j) + K * (psi_n(j + 1) - 2 * psi_n(j) + psi_n(j - 1))\n end do\n\n ! Write psi for the requested n-values to a .dat file where each line is on the form \"n psi(1) psi(2) ...\"\n if (n == 0 .or. n == 100 .or. n == 200 .or. n == 600 .or. n == 1199) then\n write(unit = 10, fmt = \"(28f20.14)\") float(n), psi_n(:) / psi_0\n end if\n\n psi_n = psi_np1 ! Update psi_n to be the value of the newly computed time step\n end do\n ! -------------------------------------------------------------------------------------\n\n close(unit = 10) ! Close file after writing\n\nEND PROGRAM exercise_2d\n", "meta": {"hexsha": "86763098100a1d6d4790809a17b4511a602f7b25", "size": 4112, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "project1/atmosphere_application.f90", "max_stars_repo_name": "jostbr/GEF4510-Projects", "max_stars_repo_head_hexsha": "1dc6d42b60672481ac6c0ea61268127a8c683e7b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-05T12:44:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-05T12:44:32.000Z", "max_issues_repo_path": "project1/atmosphere_application.f90", "max_issues_repo_name": "jostbr/GEF4510-Projects", "max_issues_repo_head_hexsha": "1dc6d42b60672481ac6c0ea61268127a8c683e7b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "project1/atmosphere_application.f90", "max_forks_repo_name": "jostbr/GEF4510-Projects", "max_forks_repo_head_hexsha": "1dc6d42b60672481ac6c0ea61268127a8c683e7b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.4098360656, "max_line_length": 141, "alphanum_fraction": 0.5070525292, "num_tokens": 963, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458263207691, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7832836259730145}} {"text": "subroutine multigrid_defect(u_local, res1, res2, aP_u, aW_u, aE_u, aS_u, aN_u, f_u, dx_mg, dy_mg, nx, ny, alpha)\nuse kind_parameters\nimplicit none \n\ninteger:: i, j, nx, ny\nreal(kind=dp), intent(in), dimension(nx,ny):: u_local, aP_u, f_u, aW_u, aE_u, aS_u, aN_u\nreal(kind=dp), intent(out), dimension(nx,ny):: res1, res2\nreal(kind=dp), dimension(nx):: dx_mg\nreal(kind=dp), dimension(ny):: dy_mg\nreal(kind=dp):: alpha\n\n! Calculate the residual r = f - Au, where u_local is the guessed value\n! Input\n! u_local Matrix for variables\n! f Right Hand Side\n! hx grid spacing in x direction\n! hy grid spacing in y direction\n! \n! Output \n! r Residual\n\n! Author: Pratanu Roy\n! History:\n! First Written: July 20, 2012\n\nalpha = 1.0\n\ndo j = 2,ny-1\n \n do i = 2,nx-1\n \n res1(i,j) = alpha/(dx_mg(i)*dy_mg(j))*(aW_u(i,j)*u_local(i-1,j) + aE_u(i,j)*u_local(i+1,j) + aS_u(i,j)*u_local(i,j-1) + aN_u(i,j)*u_local(i,j+1) - aP_u(i,j)*u_local(i,j))\n res2(i,j) = f_u(i,j) + res1(i,j)\n \n end do\n \nend do\n\nend subroutine", "meta": {"hexsha": "ba0874818e209b9c5bda0bbb4e1ff0decdb6472d", "size": 1054, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "multigrid_defect.f90", "max_stars_repo_name": "pratanuroy/Multigrid_Cavity", "max_stars_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-11T12:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-11T12:01:52.000Z", "max_issues_repo_path": "multigrid_defect.f90", "max_issues_repo_name": "pratanuroy/Multigrid_Cavity", "max_issues_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multigrid_defect.f90", "max_forks_repo_name": "pratanuroy/Multigrid_Cavity", "max_forks_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0256410256, "max_line_length": 178, "alphanum_fraction": 0.6299810247, "num_tokens": 390, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191246389618, "lm_q2_score": 0.8198933293122507, "lm_q1q2_score": 0.7832597776559034}} {"text": " FUNCTION bint(ri,rj,data,nx,ny)\n\n ! Performs bilinear interpolation to point i,j from data array\n ! with dimensions nx,ny\n\n IMPLICIT NONE\n\n REAL :: ri, rj\n INTEGER :: nx, ny\n REAL :: data(nx,ny)\n REAL :: bint\n REAL :: t,u\n INTEGER :: i1,i2,j1,j2\n\n i1 = INT(ri)\n i2 = INT(ri+1.)\n j1 = INT(rj)\n j2 = INT(rj+1.)\n\n if (ri .NE. float(i1)) then\n t = (ri - FLOAT(i1))/FLOAT(i2-i1)\n else\n t = 0.\n i2 = i1\n endif\n\n if (rj .NE. float(j1)) then\n u = (rj - FLOAT(j1))/FLOAT(j2-j1)\n else\n u = 0.\n j2 = j1\n endif\n bint = (1.-t)*(1.-u)*data(i1,j1) + &\n t*(1.-u)*data(i2,j1) + &\n t*u*data(i2,j2) + &\n (1.-t)*u*data(i1,j2)\n RETURN\nEND FUNCTION bint\n", "meta": {"hexsha": "1831e322b64f7da1221789272fd2f68fdbc853d4", "size": 726, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lfmpost/bint.f90", "max_stars_repo_name": "maxinye/laps-mirror", "max_stars_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_stars_repo_licenses": ["Intel", "Unlicense", "OLDAP-2.2.1", "NetCDF"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-04-05T12:28:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-29T06:37:29.000Z", "max_issues_repo_path": "src/lfmpost/bint.f90", "max_issues_repo_name": "longwosion/laps-mirror", "max_issues_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_issues_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lfmpost/bint.f90", "max_forks_repo_name": "longwosion/laps-mirror", "max_forks_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_forks_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-04-27T12:51:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T13:57:44.000Z", "avg_line_length": 18.6153846154, "max_line_length": 65, "alphanum_fraction": 0.5041322314, "num_tokens": 291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133430934989, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.783252900425766}} {"text": "program pg19\r\n implicit none\r\n integer :: flatarray(24),matDTQ(2,3,4),matTQD(3,4,2),matQTD(4,3,2)\r\n character(len=64) :: dfmt\r\n write(dfmt, '(a,i0,a)') '(' , ubound(matDTQ,2), 'i5.1)'\r\n flatarray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, &\r\n 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]\r\n print *, flatarray\r\n print *, \"\"\r\n print *, \"---------------\"\r\n matDTQ = reshape(flatarray,shape(matDTQ),order=[1,2,3])\r\n print *, \"\"\r\n print *, \"matDTQ(:,:,1)\"\r\n print *, \"\"\r\n write(*,dfmt) TRANSPOSE(matDTQ(:,:,1))\r\n print *, \"\"\r\n ! \r\n print *, \"matDTQ(:,:,2)\"\r\n print *, \"\"\r\n write(*,dfmt) TRANSPOSE(matDTQ(:,:,2))\r\n print *, \"\"\r\n ! \r\n print *, \"matDTQ(:,:,3)\"\r\n print *, \"\"\r\n write(*,dfmt) TRANSPOSE(matDTQ(:,:,3))\r\n print *, \"\"\r\n ! \r\n print *, \"matDTQ(:,:,4)\"\r\n print *, \"\"\r\n write(*,dfmt) TRANSPOSE(matDTQ(:,:,4))\r\n print *, \"\"\r\n print *, \"---------------\"\r\n !\r\n matTQD = reshape(matDTQ,shape(matTQD),order=[3,1,2])\r\n write(dfmt, '(a,i0,a)') '(' , ubound(matTQD,2), 'i5.1)'\r\n !\r\n print *,\"\"\r\n print *, \"matTQD(:,:,1)\"\r\n print *,\"\"\r\n write(*,dfmt) transpose(matTQD(:,:,1))\r\n print *,\"\"\r\n !\r\n print *,\"\"\r\n print *, \"matTQD(:,:,2)\"\r\n print *,\"\"\r\n write(*,dfmt) transpose(matTQD(:,:,2))\r\n print *,\"\"\r\n print *, \"---------------\"\r\n !\r\n matQTD = reshape(matDTQ,shape(matQTD),order=[3,2,1])\r\n write(dfmt, '(a,i0,a)') '(' , ubound(matQTD,2), 'i5.1)'\r\n !\r\n print *,\"\"\r\n print *, \"matQTD(:,:,1)\"\r\n print *,\"\"\r\n write(*,dfmt) transpose(matQTD(:,:,1))\r\n print *,\"\"\r\n !\r\n print *,\"\"\r\n print *, \"matQTD(:,:,2)\"\r\n print *,\"\"\r\n write(*,dfmt) transpose(matQTD(:,:,2))\r\n print *,\"\"\r\nend program pg19\r\n\r\n", "meta": {"hexsha": "6ee9f74ca69e86727a3a163d595696b5c0ec02e7", "size": 1791, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gadi/src/019-reshape.f90", "max_stars_repo_name": "rsoftone/fortran-training", "max_stars_repo_head_hexsha": "242e531bd575ac97a3a73f729532d1c257374efd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-02-24T22:33:27.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-24T22:33:27.000Z", "max_issues_repo_path": "docker/src/019-reshape.f90", "max_issues_repo_name": "rsoftone/fortran-training", "max_issues_repo_head_hexsha": "242e531bd575ac97a3a73f729532d1c257374efd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docker/src/019-reshape.f90", "max_forks_repo_name": "rsoftone/fortran-training", "max_forks_repo_head_hexsha": "242e531bd575ac97a3a73f729532d1c257374efd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-03-31T00:51:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-31T00:51:26.000Z", "avg_line_length": 27.1363636364, "max_line_length": 71, "alphanum_fraction": 0.4394193188, "num_tokens": 669, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593495, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.7831021202907803}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! z_rot3_vec3gen\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine computes the generators for a complex rotation represented\n! by 3 real numbers: the real and imaginary parts of a complex cosine,\n! CR and CI, and a strictly real sine, S. The CR, CI and S are \n! constructed to be parallel with the vector [AR+iAI,B]^T, where AR, \n! AI and B are real and i = sqrt(-1).\n!\n! If AR = AI = B = 0 then CR = 1, CI = S = 0 and NRM = 0.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! AR, AI REAL(8) \n! real and imaginary part of the first component \n! of the complex vector [AR+iAI,B]^T\n!\n! B REAL(8) \n! the second component \n! of the complex vector [AR+iAI,B]^T\n!\n! OUTPUT VARIABLES:\n!\n! CR, CI REAL(8)\n! on exit CR = AR/NRM, CI = AI/NRM\n!\n! S REAL(8)\n! on exit S = B/NRM\n!\n! NRM REAL(8)\n! on exit contains the norm \n! of the complex vector [AR+iAI,B]^T\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine z_rot3_vec3gen(AR,AI,B,CR,CI,S,NRM)\n\n implicit none\n \n ! input variables\n real(8), intent(in) :: AR, AI, B\n real(8), intent(inout) :: CR, CI, S, NRM\n \n ! compute variables\n real(8) :: tar, tai, tb\n real(8) :: nar, nai, nb\n\n ! set local variables\n nar = abs(AR)\n nai = abs(AI)\n nb = abs(B)\n\n ! AR = AI = B = 0\n if(nar.EQ.0d0 .AND. nai.EQ.0d0 .AND. nb.EQ.0d0)then\n \n CR = 1d0\n CI = 0d0\n S = 0d0\n NRM = 0d0\n \n ! |AR| >= |B| and |AR| >= |AI| \n else if(nar >= nb .AND. nar >= nai)then\n \n tb = B/AR\n tai = AI/AR\n NRM = sign(sqrt(1d0 + tb*tb + tai*tai),AR)\n CR = 1d0/NRM\n CI = tai*CR\n S = tb*CR\n NRM = AR*NRM\n \n ! |AI| >= |B| and |AI| >= |AR| \n else if(nai >= nb .AND. nai >= nar)then\n \n tb = B/AI\n tar = AR/AI\n NRM = sign(sqrt(1d0 + tb*tb + tar*tar),AI)\n CI = 1d0/NRM\n CR = tar*CI\n S = tb*CI\n NRM = AI*NRM\n \n ! |B| >= |AR| and |B| >= |AI| \n else\n tar = AR/B\n tai = AI/B\n NRM = sign(sqrt(1d0 + tai*tai + tar*tar),B)\n S = 1d0/NRM\n CR = tar*S\n CI = tai*S\n NRM = B*NRM\n \n end if\n\nend subroutine z_rot3_vec3gen\n", "meta": {"hexsha": "59d29cda019543d019e13a2e5c62bc8dcec7ec62", "size": 2483, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/AMVW/src/complex_double/z_rot3_vec3gen.f90", "max_stars_repo_name": "trcameron/FPML", "max_stars_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/AMVW/src/complex_double/z_rot3_vec3gen.f90", "max_issues_repo_name": "trcameron/FPML", "max_issues_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/AMVW/src/complex_double/z_rot3_vec3gen.f90", "max_forks_repo_name": "trcameron/FPML", "max_forks_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.5841584158, "max_line_length": 80, "alphanum_fraction": 0.4397905759, "num_tokens": 832, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107878954106, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7830241802432103}} {"text": "cy\r\n program idmat\r\n implicit none\r\n integer :: n !user supplied rank of identity matrix\r\n integer, allocatable, dimension(:,:) :: x1 \r\n print *, \"How big do you want the identity matrix to be?\"\r\n read *, n\r\n allocate(x1(n,n))\r\n call identityMatrix(x1, n)\r\n call printMatrix(x1, n)\r\n end program idmat\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n subroutine identityMatrix(X, n) ! takes an n x n matrix x1 and turns it into an identity matrix\r\n!changed this subroutine the args arent in the same order, conforms with the arg ordering of printMatrix \r\n!also, changed from x1 to X, to make it\r\n implicit none\r\n integer :: col, row, n \r\n integer, dimension(n,n) :: X !creating an identity matrix of rank n\r\n do col = 1, n !changed col and row position to access in column-major order\r\n do row = 1, n !http://kea.princeton.edu/ChE422/arrays.htm !details about column-major order\r\n X (row, col) = 0\r\n X (col, col ) = 1\r\n end do\r\n end do\r\n end subroutine identityMatrix\r\n\r\n\r\n subroutine printMatrix(array, n2) ! if this was to print a n x k matrix, I'd put a k on line 3, a k arg\r\n implicit none !in the subroutine and repalce the second n in the array(n,n) with a k\r\n integer, intent(in) :: array(n2,n2) !creating an n x n identity matrix\r\n integer, intent(in) :: n2 !declaring that it's an input and not to be changed by running the subroutine\r\n integer :: i\r\n do i = 1, n2\r\n print*, array(i,:)\r\n end do\r\n end subroutine printMatrix", "meta": {"hexsha": "b8a85a0b06dea0b0a672015d0dc55c927552f065", "size": 1576, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "identityMatrix.f", "max_stars_repo_name": "DU-ds/Fortran", "max_stars_repo_head_hexsha": "7145bb0fa1a863e3c0800355767896ee6dc54e19", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "identityMatrix.f", "max_issues_repo_name": "DU-ds/Fortran", "max_issues_repo_head_hexsha": "7145bb0fa1a863e3c0800355767896ee6dc54e19", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "identityMatrix.f", "max_forks_repo_name": "DU-ds/Fortran", "max_forks_repo_head_hexsha": "7145bb0fa1a863e3c0800355767896ee6dc54e19", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.5238095238, "max_line_length": 112, "alphanum_fraction": 0.616751269, "num_tokens": 406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8558511451289038, "lm_q1q2_score": 0.7830190300102694}} {"text": "!---------------------------------------------------------------------!\n! OWNER: Ithaca Combustion Enterprise, LLC !\n! COPYRIGHT: © 2012, Ithaca Combustion Enterprise, LLC !\n! LICENSE: BSD 3-Clause License (The complete text of the license can !\n! be found in the `LICENSE-ICE.txt' file included in the ISAT-CK7 !\n! source directory.) !\n!---------------------------------------------------------------------!\n\nsubroutine ellu_rad_upper( n, g, r )\n\n! Determine the radius r of the ball covering the ellipsoid E given\n! by { x | norm(G^T * x) <=1 ), where G is an n x n lower triangular\n! matrix. The array g contains the matrix G (unpacked).\n\n! S.B. Pope 6/12/04\n\nimplicit none\n\ninteger, parameter :: k_dp = kind(1.d0)\ninteger, intent(in) :: n\nreal(k_dp), intent(in) :: g(n,n)\nreal(k_dp), intent(out) :: r\n\ninteger :: itmax = 100 ! max. iterations in dgqt\nreal(k_dp) :: atol = 1.d-4, rtol = 1.d-4 ! tolerances for dgqt\n\ninteger :: info\nreal(k_dp) :: gi(n,n), alpha, delta, par, f\nreal(k_dp) :: a(n,n), b(n), x(n), z(n), wa1(n), wa2(n)\n\n! Method: E = { y | y^T * y <= 1 } where y = G^T * x.\n! Now x^T * x = y^T * G^{-1} * G^{-T} * y.\n! Thus, with f(y) = -2 * y^T * G^{-1} * G^{-T} * y, \n! r = sqrt(-f(y_m) ), where y_m is the minimizer of f, subject to |y|<=1.\n\ngi = g\ncall dtrtri( 'L', 'N', n, gi, n, info ) ! gi = G^{-1}\n\nif( info /= 0 ) then\n write(0,*)'ellu_rad_upper: dtrtri failed, info = ', info\n stop\nendif\n\na = gi\n\n! B = alpha * B * op(A) = -2 * G^{-1} * G^{-T}\n\nalpha = -2.d0\ncall dtrmm ( 'R', 'L', 'T', 'N', n, n, alpha, gi, n, a, n )\n\ndelta = 1.d0\npar = 0.d0\nb = 0.d0\n! minimize f(y) = (1/2) * y^T * A * y + b^T * y, subject to |y|<= delta\n! = -2 * y^T * G^{-1} * G^{-T} * y\n\ncall dgqt(n,a,n,b,delta,rtol,atol,itmax,par,f,x,info,z,wa1,wa2)\n\nif( info >= 3 ) then\n write(0,*)'ellu_rad_upper: dgqt incomplete convergence, info = ', info\nendif\n\nif( f > 0.d0 ) then\n write(0,*)'ellu_rad_upper: f positive, f = ', f\n stop\nendif\n\nr = sqrt( -f ) \n\nreturn\nend subroutine ellu_rad_upper\n", "meta": {"hexsha": "618dca65bd8b4f54d7681ba4ad65c4b1f5543d2e", "size": 2149, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/isat/ell_lib/ellu_rad_upper.f90", "max_stars_repo_name": "xuhan425/isat_ffd", "max_stars_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-10T20:16:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-15T11:09:44.000Z", "max_issues_repo_path": "src/isat/ell_lib/ellu_rad_upper.f90", "max_issues_repo_name": "xuhan425/isat_ffd", "max_issues_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-07T14:10:25.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T14:10:25.000Z", "max_forks_repo_path": "src/isat/ell_lib/ellu_rad_upper.f90", "max_forks_repo_name": "xuhan425/isat_ffd", "max_forks_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-06-07T03:44:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T05:54:10.000Z", "avg_line_length": 29.8472222222, "max_line_length": 74, "alphanum_fraction": 0.5081433225, "num_tokens": 761, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693674025231, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7829662340214821}} {"text": "PROGRAM calculatrice2\n\tIMPLICIT NONE\n\t\n\tINTEGER :: i, ok, n, m !n etant le nb de composantes et m etant le nb de vecteurs\n\tCHARACTER :: op\n\tREAL :: somme=0., produit=1., norme1=0., norme2=0., norme_sup, maxi, produitsca !somme1=0., somme2=0., somme3=0.\n\t!somme1->somme de carre des composantes de v1, somme2->somme de carre des composantes de v2, somme3->somme de carre de (v1+v2)\n\tREAL, DIMENSION(:), ALLOCATABLE :: v1, v2, v3\n\tCHARACTER(LEN=2), DIMENSION(:), ALLOCATABLE :: res\n\tLOGICAL, DIMENSION(:), ALLOCATABLE :: logi\n\t\n\tPRINT*, \"Vous voulez saisir 1 ou 2 vecteurs? (Tapez -1 pour quitter)\" \n\tREAD*, m\n\tIF(m==-1)STOP \"A bientot!\"\n\t\n\tIF(m==1)THEN\n\t\tPRINT*, \"Entrez le nombre de composantes du vecteur v1. (Tapez -1 pour quitter)\"\n\t\tREAD*, n\n\t\tIF(n==-1)STOP \"A bientot!\"\n\t\t\n\t\tALLOCATE (v1(n), STAT=ok)\n\t\tIF(ok/=0)STOP \"L'allocation a echoue\"\n\t\n\t\tDO i=1,n\n\t\t\tPRINT*, \"Entrez la composante\", i, \"de v1\"\n\t\t\tREAD*, v1(i)\n\t\tEND DO\n\t\t\n\t\tPRINT*, \"Entrez '+' pour la somme des composantes, '*' pour le produit des composantes\"\n\t\tPRINT*,\"'1' et '2' pour les normes 1 et 2, 's' pour la norme superieur.\"\n\t\tPRINT*, \"(Tapez q pour quitter.)\"\n\t\tREAD*, op\n\t\tIF(op=='q')STOP \"A bientot!\"\n\t\t\n\t\tSELECT CASE(op)\n\t\t\tCASE('+')\n\t\t\t\tDO i=1,n\n\t\t\t\t\tsomme=somme+v1(i)\n\t\t\t\tEND DO\n\t\t\t\tPRINT*, \"La somme des composantes de v1 est egale a\", somme\t\n\t\t\tCASE('*')\n\t\t\t\tDO i=1,n\n\t\t\t\t\tproduit=produit*v1(i)\n\t\t\t\tEND DO\n\t\t\t\tPRINT*, \"Le produit des composantes de v1 est egale a\", produit\n\t\t\tCASE('1')\n\t\t\t\tDO i=1,n\n\t\t\t\t\tnorme1=norme1+ABS(v1(i))\n\t\t\t\tEND DO\n\t\t\t\tPRINT*, \"La norme1 du vecteur v1 est egale a\", norme1\n\t\t\tCASE('2')\n\t\t\t\tDO i=1,n\n\t\t\t\t\tsomme=somme+v1(i)**2\n\t\t\t\t\tnorme2=SQRT(somme)\n\t\t\t\tEND DO\n\t\t\t\tPRINT*, \"La norme2 du vecteur v1 est egale a\", norme2\n\t\t\tCASE('s')\n\t\t\t\tmaxi=ABS(v1(1))\n\t\t\t\tDO i=2,n\n\t\t\t\t\tIF(maxi=v2(i))THEN\n\t\t\t\t\t\tres(i)=\">=\"\n\t\t\t\t\tELSE\n\t\t\t\t\t\tres(i)=\"<\"\n\t\t\t\t\tEND IF\n\t\t\t\tEND DO\n\t\t\t\tPRINT*, \"Le vecteur resultat est\", res\n\t\t\t\t!logi=v1=\"\n\t\t\t\t!END WHERE\n\t\t\t\t!PRINT*, res \n\t\t\tCASE DEFAULT\n\t\t\t\tPRINT*, \"Operateur invalide\" \n\t\tEND SELECT\n\tELSE\n\t\tPRINT*,\"Invalide!\"\n\tEND IF\t\t\n\t\n\tDEALLOCATE(v1, v2, v3, res)\nEND PROGRAM calculatrice2\n", "meta": {"hexsha": "f1d7a59b7abb927cfe3b173e4947f9800ff6857c", "size": 3933, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "calc_vecteur/calculatrice2.f90", "max_stars_repo_name": "psekercioglu/fortran90", "max_stars_repo_head_hexsha": "10a3c7fff3dd52ba6e2247bde18f25f8e81bf50d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc_vecteur/calculatrice2.f90", "max_issues_repo_name": "psekercioglu/fortran90", "max_issues_repo_head_hexsha": "10a3c7fff3dd52ba6e2247bde18f25f8e81bf50d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc_vecteur/calculatrice2.f90", "max_forks_repo_name": "psekercioglu/fortran90", "max_forks_repo_head_hexsha": "10a3c7fff3dd52ba6e2247bde18f25f8e81bf50d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.5743243243, "max_line_length": 127, "alphanum_fraction": 0.6033562166, "num_tokens": 1607, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.8807970701552505, "lm_q1q2_score": 0.7828161413828715}} {"text": "program norma\n\n implicit none\n \n real :: b\n real, DIMENSION(:), ALLOCATABLE :: numbers\n\n numbers = (/1.5, 54.236879,12.5,0.9,7.2 /)\n\n b = normainf(numbers)\n \n write(*,2) b\n 2 format(1f9.6)\n \n \n contains\n \n function normainf(vec) result(y)\n \n implicit none\n \n \n real, DIMENSION(:), ALLOCATABLE :: vec\n real :: y\n \n \n y = maxval(ABS(vec))\n \n end function normainf \n\n\nend program norma\n\n\n\n", "meta": {"hexsha": "51878115c70eb596eef1a7a958f4e804fe39d0fb", "size": 572, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Linear System/Fortran/norma.f90", "max_stars_repo_name": "arturofburgos/Comparing-Languages", "max_stars_repo_head_hexsha": "a20dc24699c762252c94c26e32c7053c04793d9d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-03-17T18:40:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-21T11:51:12.000Z", "max_issues_repo_path": "Linear System/Fortran/norma.f90", "max_issues_repo_name": "arturofburgos/Assessment-of-Programming-Languages-for-Computational-Numerical-Dynamics", "max_issues_repo_head_hexsha": "eefdc8800b424bbfb34286f4f507297300122a4d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Linear System/Fortran/norma.f90", "max_forks_repo_name": "arturofburgos/Assessment-of-Programming-Languages-for-Computational-Numerical-Dynamics", "max_forks_repo_head_hexsha": "eefdc8800b424bbfb34286f4f507297300122a4d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-11T01:20:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-11T01:20:01.000Z", "avg_line_length": 15.8888888889, "max_line_length": 50, "alphanum_fraction": 0.4248251748, "num_tokens": 145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505273888291, "lm_q2_score": 0.8652240964782011, "lm_q1q2_score": 0.7827254351885278}} {"text": "module ModHeatCN\n ! A module that contains all the necessary tools for solving the \n ! heat equation using the Crank-Nicholson method. The problem is\n ! 1D in space for an arbitrary space/time domain size. BCS are\n ! Dirichlet and set by variable \"Bound_I\".\n\n ! This module requires ModWrite2d and LAPACK to compile.\n ! Use compiler flag -llapack to compile against lapack.\n ! Also, be sure to force double precision to prevent failures.\n\n ! To use this module, do the following in an external program:\n ! 1) \"Use ModHeatCN\"\n ! 2) Set timestep, gridsize, etc.\n ! 3) call init_sim()\n ! 4) Set array DomainNow to your initial conditions.\n ! 5) call integrate()\n ! 6) call finalize_sim()\n\n use ModWrite2d, ONLY: write_record, init_file, close_file\n\n implicit none\n\n save\n public ! This says that all variables and subroutines in this file\n ! can be used by any file using this module.\n\n ! Parameter-like variables.\n real :: dt = 0.01, dx = 0.1, tLim(2)=(/0.0,0.1/), xLim(2) = (/0.0, 1.0/)\n real :: cDiffusion = 1.0\n real :: Bound_I(2) = (/0,0/) ! Dirichlet boundary values.\n integer :: nT, nX\n\n ! Output controls:\n logical :: DoTest = .false.\n character(len=100) :: NameOutFile\n\n ! Domain variables\n real, allocatable :: Coeffs_II(:,:)\n real, allocatable :: DomainNow(:), DomainNext(:)\n real, allocatable :: xGrid(:), tGrid(:)\n\n ! Variables that shouldn't be used by others.\n logical, private :: IsInitialized = .false.\n \ncontains\n !============================================================================\n subroutine init_sim(DxIn, DtIn)\n ! Set up the simulation, initialize domain, etc.\n ! Setting initial conditions is left to the external user.\n \n real, intent(in) :: DxIn, DtIn\n \n integer:: i\n real, allocatable :: CoeffA(:,:), CoeffB(:,:), invA(:,:)\n real :: r\n \n !------------------------------------------------------------------------\n ! Set dx, dt based on inputs. Because we cannot change our inputs, we\n ! copy them to new memory locations.\n dx = DxIn\n dt = DtIn\n\n write(*,*) '...initializing arrays...'\n\n ! Determine size of arrays.\n nX = ceiling( (xLim(2)-xLim(1))/dx + 1.0 )\n nT = ceiling( (tLim(2)-tLim(1))/dt + 1.0 ) \n\n if(DoTest) write(*,*) ' Grid size (nX, nT) = ', nX, nT\n\n ! Allocations\n allocate(DomainNext(nX))\n allocate(DomainNow(nX))\n allocate(xGrid(nX))\n allocate(tGrid(nT))\n allocate(Coeffs_II(nX, nX))\n\n ! It's usually a good idea to fill matrices with zeros.\n DomainNow = 0\n DomainNext = 0\n xGrid = 0\n tGrid = 0\n \n ! Set up time grid.\n do i=1, nT\n tGrid(i) = tLim(1) + (i-1)*dT\n end do\n\n ! Set up space grid.\n do i=1, nX\n xGrid(i) = (i-1) * dx\n end do\n\n ! Create \"r\", our important factor.\n r= cDiffusion**2.0 * dt / dx**2.0\n if(DoTest)write(*,*) \"r = \", r\n\n ! Create our matrix \"A\" and \"B\" of coefficients:\n allocate(CoeffA(nX,nX))\n allocate(CoeffB(nX,nX))\n allocate(invA(nX, nX))\n ! First and last row:\n CoeffA(1, 1:2) = (/2.0+2.0*r, -1.*r/)\n CoeffA(nX, nX-1:nX) = (/-1.*r, 2.0+2.0*r/)\n CoeffB(1, 1:2) = (/2.0-2.0*r, r/)\n CoeffB(nX, nX-1:nX) = (/ r, 2.0-2.0*r/)\n ! Rest of elements:\n do i=2, nX-1\n CoeffA(i, i-1:i+1) = (/-1.*r, 2.0+2.0*r, -1.*r/)\n CoeffB(i, i-1:i+1) = (/ r, 2.0-2.0*r, r/)\n end do\n\n if(DoTest)then\n write(*,*) 'A-Matrix:'\n do i=1, nX\n write(*,'(11(1x, E12.6))') CoeffA(i, :)\n end do\n write(*,*) 'B-Matrix:'\n do i=1, nX\n write(*,'(11(1x, E12.6))') CoeffB(i, :)\n end do\n end if\n\n ! Calculate A-1*B to get Coeffs_II\n invA = inv(CoeffA)\n Coeffs_II = matmul(invA, CoeffB)\n\n ! Get rid of unneeded Coeff arrays.\n deallocate(CoeffA)\n deallocate(CoeffB)\n\n call init_file('results.txt', 'Heat Equation Crank-Nicholson', &\n nX, nT, xGrid, tGrid(1), tGrid(nT))\n\n ! We're ready to roll.\n IsInitialized = .true.\n\n end subroutine init_sim\n\n !============================================================================\n subroutine integrate\n ! Integrate!\n integer :: j\n !------------------------------------------------------------------------\n if(.not. IsInitialized) then\n write(*,*) \"Domain not intialized!\"\n stop\n end if\n \n do j=1, nT-1\n call write_record(tGrid(j), DomainNow) ! Write domain to file.\n DomainNext = matmul(Coeffs_II, DomainNow) ! Integrate via matrices.\n DomainNow=DomainNext ! Move forward by copying Next to Now.\n ! Enforce boundary conditions:\n DomainNow(1) = Bound_I(1)\n DomainNow(nX)= Bound_I(2)\n end do\n \n ! Write final vector to file.\n call write_record(tGrid(nT), DomainNow)\n \n end subroutine integrate\n !============================================================================\n subroutine finalize_sim\n ! Finalize the simulation by deallocating arrays. This is a good habit!\n \n !------------------------------------------------------------------------\n deallocate(DomainNow)\n deallocate(DomainNext)\n deallocate(xGrid)\n deallocate(tGrid)\n\n ! Indicate that we are no longer initialized.\n IsInitialized = .false.\n \n call close_file\n\n write(*,'(a,i8.8,a)')'Finished simulation. Produced ', nX*nT, ' points.'\n end subroutine finalize_sim\n\n !============================================================================\n function inv(A) result(Ainv)\n ! Return the inverse of matrix A.\n real, dimension(:,:), intent(in) :: A\n real, dimension(size(A,1),size(A,2)) :: Ainv\n \n real, dimension(size(A,1)) :: work ! work array for LAPACK\n integer, dimension(size(A,1)) :: ipiv ! pivot indices\n integer :: n, info\n !------------------------------------------------------------------------\n\n ! Store A in Ainv to prevent it from being overwritten by LAPACK\n Ainv = A\n n = size(A,1)\n \n ! DGETRF computes an LU factorization of a general M-by-N matrix A\n ! using partial pivoting with row interchanges. It is from LAPACK.\n call DGETRF(n, n, Ainv, n, ipiv, info)\n \n if (info /= 0) then\n stop 'Matrix is numerically singular!'\n end if\n \n ! DGETRI computes the inverse of a matrix using the LU factorization\n ! computed by DGETRF. It is from LAPAPCK.\n call DGETRI(n, Ainv, n, ipiv, work, n, info)\n \n if (info /= 0) then\n stop 'Matrix inversion failed!'\n end if\n end function inv\n !============================================================================\n\nend module ModHeatCN\n", "meta": {"hexsha": "ba36b5f32a9d84e15f6459e34ab508ce04873559", "size": 6653, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran90/HeatCN/ModHeatCN.f90", "max_stars_repo_name": "spacecataz/sciprog_teaching", "max_stars_repo_head_hexsha": "ebaacdb0b7ff9d3e29568a427f8d6078fcf439b5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fortran90/HeatCN/ModHeatCN.f90", "max_issues_repo_name": "spacecataz/sciprog_teaching", "max_issues_repo_head_hexsha": "ebaacdb0b7ff9d3e29568a427f8d6078fcf439b5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran90/HeatCN/ModHeatCN.f90", "max_forks_repo_name": "spacecataz/sciprog_teaching", "max_forks_repo_head_hexsha": "ebaacdb0b7ff9d3e29568a427f8d6078fcf439b5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-01T02:31:54.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T02:31:54.000Z", "avg_line_length": 30.9441860465, "max_line_length": 79, "alphanum_fraction": 0.5382534195, "num_tokens": 1965, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947456, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7826680486344126}} {"text": "PROGRAM one\n IMPLICIT NONE\n REAL:: sumX, sumY, sumXSqure, sumXY, m, c, St, Sr, meanY, rSqure\n REAL, DIMENSION(5):: x, y\n INTEGER:: n, i\n n = 5\n sumX = 0.0\n sumY = 0.0\n sumXSqure = 0.0\n sumXY = 0.0\n DO i = 1, n\n READ(*, *) x(i), y(i)\n sumX = sumX + x(i)\n sumY = sumY + y(i)\n sumXY = sumXY + x(i) * y(i)\n sumXSqure = sumXSqure + x(i) * x(i)\n ENDDO\n meanY = sumY/n\n\n m = (n * sumXY - sumX * sumY) / (n * sumXSqure - sumX * sumX)\n c = (1.0/n) * (sumY - m * sumX) \n St = 0.0\n Sr = 0.0\n DO i = 1, n\n St = St + (y(i) - meanY) * (y(i) - meanY) \n Sr = Sr + (y(i) - c - m * x(i)) * (y(i) - c - m * x(i))\n ENDDO\n rSqure = (St - Sr) / St\n WRITE(*, *) \"Goodness of Fit is\", rSqure \n WRITE(*, *) m, c \nEND\n", "meta": {"hexsha": "b14c5da6ff7f12556e96505e81aca5b4ba746b95", "size": 804, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Practice-2/1.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Practice-2/1.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practice-2/1.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 25.125, "max_line_length": 68, "alphanum_fraction": 0.4378109453, "num_tokens": 364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632316144274, "lm_q2_score": 0.822189121808099, "lm_q1q2_score": 0.7826115944824852}} {"text": "implicit none\r\nreal :: x, xold, f, fprime\r\n\r\nx = 1.5\r\nxold = 23.3\r\n\r\ndo while (abs(xold - x) > 1.0e-11)\r\n xold = x\r\n x = x - f(x) / fprime(x)\r\n print*, x, f(x), abs(x - xold)\r\nend do\r\n\r\nstop\r\nend\r\n\r\nreal function f(x)\r\n implicit none\r\n real :: x\r\n\r\n f = x**2 - 3.0\r\n\r\n return\r\nend\r\n\r\nreal function fprime(x)\r\n implicit none\r\n real :: x\r\n\r\n fprime = 2.0 * x\r\n\r\n return\r\nend\r\n", "meta": {"hexsha": "80c9fbb54a9e36c81b9fb71e207d419061d2814b", "size": 385, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "4670 Numerical Analysis/Class Examples/ex2.f90", "max_stars_repo_name": "mwebber3/UnderGraduateCourses", "max_stars_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4670 Numerical Analysis/Class Examples/ex2.f90", "max_issues_repo_name": "mwebber3/UnderGraduateCourses", "max_issues_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4670 Numerical Analysis/Class Examples/ex2.f90", "max_forks_repo_name": "mwebber3/UnderGraduateCourses", "max_forks_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 11.6666666667, "max_line_length": 35, "alphanum_fraction": 0.5220779221, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939024825960626, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7825124830815817}} {"text": "!*********************************************\n!\n\n SUBROUTINE spline(x,y,N,yp1,ypn,y2)\n IMPLICIT REAL*8 (A-H,K,O-Z)\n INTEGER, PARAMETER :: DP=kind(1D0)\n INTEGER :: N,NMAX\n REAL(kind=DP), dimension(N) :: x,y,y2\n REAL(kind=DP) :: yp1,ypn\n PARAMETER (NMAX=100000)\n! ---------------------------------------------------------------------\n! Given arrays x(1:n) and y(1:n) containing a tabulated function, i.e., yi = f(xi), with\n! x1 < x2 < ... < xN , and given values yp1 and ypn for the first derivative of the interpolating\n! function at points 1 and n, respectively, this routine returns an array y2(1:n) of\n! length n which contains the second derivatives of the interpolating function at the tabulated\n! points xi. If yp1 and/or ypn are equal to 1 × 10**30 or larger, the routine is signaled to set\n! the corresponding boundary condition for a natural spline, with zero second derivative on\n! that boundary.\n! Parameter: NMAX is the largest anticipated value of n.\n! ---------------------------------------------------------------------- \n INTEGER :: i,k\n REAL(KIND=DP) :: p,qn,sig,un\n REAL(kind=DP), dimension(NMAX) :: u\n! The lower boundary condition is set either to be \"natural\" or else to have a specified derivative\n\n IF (yp1 .GT. .99e30) THEN \n y2(1)=0\n u(1)=0.\n ELSE\n y2(1)=-0.5\n u(1)=(3./(x(2)-x(1)))*((y(2)-y(1))/(x(2)-x(1))-yp1)\n END IF\n! This is the decomposition loop of the tridiagonal algorithm. y2 and u are used for temporary\n! storage of the decomposed factors.\n DO i=2,n-1\n sig=(x(i)-x(i-1))/(x(i+1)-x(i-1))\n p=sig*y2(i-1)+2.\n y2(i)=(sig-1.)/p\n u(i)=(6.*((y(i+1)-y(i))/(x(i+1)-x(i))-(y(i)-y(i-1))\n & /(x(i)-x(i-1)))/(x(i+1)-x(i-1))-sig*u(i-1))/p\n END DO\n! The upper boundary condition is set either to be \"natural\" or else to have a specified first derivative.\n IF (ypn .GT. .99e30) THEN\n qn=0.\n un=0.\n ELSE\n qn=0.5\n un=(3./(x(n)-x(n-1)))*(ypn-(y(n)-y(n-1))/(x(n)-x(n-1)))\n END IF \n y2(n)=(un-qn*u(n-1))/(qn*y2(n-1)+1.)\n! This is the backsubstitution loop of the tridiagonal algorithm.\n DO k=n-1,1,-1\n y2(k)=y2(k)*y2(k+1)+u(k)\n END DO\n \n RETURN\n END\n\n!***********************************************\n", "meta": {"hexsha": "8689f4a3c36969cff71ecbcb3d0534d84abc4d53", "size": 2403, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "TwoStateModel/spline.f", "max_stars_repo_name": "ebenjaminrandall/DelayDDEBifurcationAnalysis", "max_stars_repo_head_hexsha": "9020d83bf6e07f1d8af1d062954a68055b5cbe6f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-05-29T19:35:11.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-29T19:35:11.000Z", "max_issues_repo_path": "code/spline.f", "max_issues_repo_name": "ebenjaminrandall/Randall_VMPaper", "max_issues_repo_head_hexsha": "b84d2cc599a0a80b3f795a0e5a6999435f497103", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "code/spline.f", "max_forks_repo_name": "ebenjaminrandall/Randall_VMPaper", "max_forks_repo_head_hexsha": "b84d2cc599a0a80b3f795a0e5a6999435f497103", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.05, "max_line_length": 106, "alphanum_fraction": 0.5097794424, "num_tokens": 740, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624257, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.782501818826507}} {"text": "PROGRAM diff\r\n!\r\n! Purpose: \r\n! To test the effects of finite precision by differentiating\r\n! a function with 10 different step sizes, with both single\r\n! precision and double precision. The test will be based on \r\n! the function F(X) = 1./X.\r\n! \r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 11/27/95 S. J. Chapman Original code\r\n!\r\nIMPLICIT NONE\r\n\r\n! Data dictionary: declare constants\r\nINTEGER, PARAMETER :: SGL = SELECTED_REAL_KIND(p=6,r=37)\r\nINTEGER, PARAMETER :: DBL = SELECTED_REAL_KIND(p=13)\r\n\r\n! List of local variables:\r\nREAL(KIND=DBL) :: ans ! True (analytic) answer\r\nREAL(KIND=DBL) :: d_ans ! Double precision answer\r\nREAL(KIND=DBL) :: d_error ! Double precision percent error\r\nREAL(KIND=DBL) :: d_fx ! Double precision F(x)\r\nREAL(KIND=DBL) :: d_fxdx ! Double precision F(x+dx)\r\nREAL(KIND=DBL) :: d_dx ! Step size\r\nREAL(KIND=DBL) :: d_x = 0.15_DBL ! Location to evaluate dF(x)/dx\r\nINTEGER :: i ! Index variable\r\nREAL(KIND=SGL) :: s_ans ! Single precision answer\r\nREAL(KIND=SGL) :: s_error ! Single precision percent error\r\nREAL(KIND=SGL) :: s_fx ! Single precision F(x)\r\nREAL(KIND=SGL) :: s_fxdx ! Single precision F(x+dx)\r\nREAL(KIND=SGL) :: s_dx ! Step size\r\nREAL(KIND=SGL) :: s_x = 0.15_SGL ! Location to evaluate dF(x)/dx\r\n\r\n! Print headings.\r\nWRITE (*,1)\r\n1 FORMAT (1X,' DX TRUE ANS SP ANS DP ANS ', &\r\n ' SP ERR DP ERR ')\r\n \r\n! Calculate analytic solution at x=0.15.\r\nans = - ( 1.0_DBL / d_x**2 )\r\n \r\n! Calculate answer from definition of differentiation\r\nstep_size: DO i = 1, 10 \r\n \r\n ! Get delta x.\r\n s_dx = 1.0 / 10.0**i\r\n d_dx = 1.0_DBL / 10.0_DBL**i\r\n \r\n ! Calculate single precision answer.\r\n s_fxdx = 1. / ( s_x + s_dx ) \r\n s_fx = 1. / s_x\r\n s_ans = ( s_fxdx - s_fx ) / s_dx\r\n \r\n ! Calculate single precision error, in percent.\r\n s_error = ( s_ans - REAL(ans) ) / REAL(ans) * 100.\r\n \r\n ! Calculate double precision answer.\r\n d_fxdx = 1.0_DBL / ( d_x + d_dx ) \r\n d_fx = 1.0_DBL / d_x \r\n d_ans = ( d_fxdx - d_fx ) / d_dx\r\n\r\n ! Calculate double precision error, in percent.\r\n d_error = ( d_ans - ans ) / ans * 100.\r\n \r\n ! Tell user.\r\n WRITE (*,100) d_dx, ans, s_ans, d_ans, s_error, d_error\r\n 100 FORMAT (1X, ES10.3, F12.7, F12.7, ES22.14, F9.3, F9.3)\r\n \r\nEND DO step_size\r\n \r\nEND PROGRAM diff\r\n", "meta": {"hexsha": "68f70e3469d3d402ad313489e2626a1ea612b417", "size": 2578, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap11/diff.f90", "max_stars_repo_name": "yangyang14641/FortranLearning", "max_stars_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-03-12T02:18:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-05T07:58:56.000Z", "max_issues_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap11/diff.f90", "max_issues_repo_name": "yangyang14641/FortranLearning", "max_issues_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap11/diff.f90", "max_forks_repo_name": "yangyang14641/FortranLearning", "max_forks_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-05-11T02:36:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T06:36:55.000Z", "avg_line_length": 34.8378378378, "max_line_length": 69, "alphanum_fraction": 0.5713731575, "num_tokens": 791, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404057671714, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7824267748550402}} {"text": "SUBROUTINE simul ( a, b, soln, ndim, n, error )\nIMPLICIT NONE\n! Data dictionary: declare calling parameter types & definitions\nINTEGER, INTENT(IN) :: ndim\n! Dimension of arrays a and b\nREAL, INTENT(IN), DIMENSION(ndim,ndim) :: a\n! Array of coefficients (N x N).\n! This array is of size ndim x\n! ndim, but only N x N of the\n! coefficients are being used.\nREAL, INTENT(IN), DIMENSION(ndim) :: b\n! Input: Right-hand side of eqns.\nREAL, INTENT(OUT), DIMENSION(ndim) :: soln\n! Output: Solution vector.\nINTEGER, INTENT(IN) :: n\n! Number of equations to solve.\nINTEGER, INTENT(OUT) :: error\nREAL, PARAMETER :: EPSILON = 1.0E-6 ! A \"small\" number for comparison\n! when determining singular eqns\n! Data dictionary: declare local variable types & definitions\nREAL, DIMENSION(n,n) :: a1\n! Copy of \"a\" which will be\n! destroyed during the solution\nREAL :: factor\n! Factor to multiply eqn irow by\n! before adding to eqn jrow\nINTEGER :: irow\n! Number of the equation currently\n! being processed\nINTEGER :: ipeak\n! Pointer to equation containing\n! maximum pivot value\nINTEGER :: jrow\n! Number of the equation compared\n! to the current equation\nREAL :: temp\n! Scratch value\n\nREAL, DIMENSION(n) :: temp1\n! Scratch array\n! Make copies of arrays \"a\" and \"b\" for local use\na1 = a(1:n,1:n)\nsoln = b(1:n)\n! Process N times to get all equations...\nmainloop: DO irow = 1, n\n! Find peak pivot for column irow in rows irow to N\nipeak = irow\nmax_pivot: DO jrow = irow+1, n\nIF (ABS(a1(jrow,irow)) > ABS(a1(ipeak,irow))) THEN\nipeak = jrow\nEND IF\nEND DO max_pivot\n! Check for singular equations.\nsingular: IF ( ABS(a1(ipeak,irow)) < EPSILON ) THEN\nerror = 1\nRETURN\nEND IF singular\n! Otherwise, if ipeak /= irow, swap equations irow & ipeak\nswap_eqn: IF ( ipeak /= irow ) THEN\ntemp1 = a1(ipeak,1:n)\na1(ipeak,1:n) = a1(irow,1:n)\n! Swap rows in a\na1(irow,1:n) = temp1\ntemp = soln(ipeak)\nsoln(ipeak) = soln(irow)\n! Swap rows in b\nsoln(irow) = temp\nEND IF swap_eqn\n\n! Multiply equation irow by -a1(jrow,irow)/a1(irow,irow),\n! and add it to Eqn jrow (for all eqns except irow itself).\neliminate: DO jrow = 1, n\nIF ( jrow /= irow ) THEN\nfactor = -a1(jrow,irow)/a1(irow,irow)\na1(jrow,:) = a1(irow,1:n)*factor + a1(jrow,1:n)\nsoln(jrow) = soln(irow)*factor + soln(jrow)\nEND IF\nEND DO eliminate\nEND DO mainloop\n! End of main loop over all equations. All off-diagonal terms\n! are now zero. To get the final answer, we must divide\n! each equation by the coefficient of its on-diagonal term.\ndivide: DO irow = 1, n\nsoln(irow) = soln(irow) / a1(irow,irow)\na1(irow,irow) = 1.\nEND DO divide\n! Set error flag to 0 and return.\nerror = 0\nEND SUBROUTINE simul\n\nSUBROUTINE dsimul ( a, b, soln, ndim, n, error )\nUSE iso_Fortran_env\nIMPLICIT NONE\n\nREAL(KIND=REAL64), PARAMETER :: EPSILON = 1.0E-12\nINTEGER, INTENT(IN) :: ndim\nREAL(KIND=REAL64), INTENT(IN), DIMENSION(ndim,ndim) :: a\nREAL(KIND=REAL64), INTENT(IN), DIMENSION(ndim) :: b\nREAL(KIND=REAL64), INTENT(OUT), DIMENSION(ndim) :: soln\nINTEGER, INTENT(IN) :: n\nINTEGER, INTENT(OUT) :: error\nREAL(KIND=REAL64), DIMENSION(n,n) :: a1\nREAL(KIND=REAL64) :: factor\nINTEGER :: irow, ipeak, jrow\nREAL(KIND=REAL64) :: temp\nREAL(KIND=REAL64), DIMENSION(n) :: temp1\n\na1 = a(1:n,1:n)\nsoln = b(1:n)\n! Process N times to get all equations\nmainloop: DO irow = 1, n\n ! Find peak pivot for column irow in rows irow to N\n ipeak = irow\n max_pivot: DO jrow = irow+1, n\n IF (ABS(a1(jrow,irow)) > ABS(a1(ipeak,irow))) THEN\n ipeak = jrow\n END IF\n END DO max_pivot\n\n ! Check for singular equations\n singular: IF (ABS(a1(ipeak,irow)) < EPSILON) THEN\n error = 1\n RETURN\n END IF singular\n\n ! Otherwise, if ipeak /= irow, swap equations irow & ipeak\n swap_eqn: IF (ipeak /= irow) THEN\n temp1 = a1(ipeak,1:n)\n a1(ipeak,1:n) = a1(irow,1:n) ! Swap rows in a\n a1(irow,1:n) = temp1\n temp = soln(ipeak)\n soln(ipeak) = soln(irow) ! Swap rows in b\n soln(irow) = temp\n END IF swap_eqn\n\n ! Multiply equation irow by -a1(jrow,irow)/a1(irow,irow),\n ! and add it to Eqn jrow (for all eqns except irow itself).\n eliminate: DO jrow = 1, n\n IF (jrow /= irow) THEN\n factor = -a1(jrow,irow)/a1(irow,irow)\n a1(jrow,1:n) = a1(irow,1:n)*factor + a1(jrow,1:n)\n soln(jrow) = soln(irow)*factor + soln(jrow)\n END IF\n END DO eliminate\n END DO mainloop\n\n ! End of main loop over all equations. All off-diagonal\n ! terms are now zero. To get the final answer, we must\n ! divide each equation by the coefficient of its on-diagonal\n ! term.\n divide: DO irow = 1, n\n soln(irow) = soln(irow) / a1(irow,irow)\n END DO divide\n\n ! Set error flag to 0 and return.\n error = 0\nEND SUBROUTINE dsimul\n\nPROGRAM dbl_gauss_jordan\nUSE iso_Fortran_env\nIMPLICIT NONE\n!INTEGER, PARAMETER :: MAX_SIZE = 10\nREAL(KIND=REAL32), ALLOCATABLE, DIMENSION(:,:) :: a\nREAL(KIND=REAL32), ALLOCATABLE, DIMENSION(:) :: b\nREAL(KIND=REAL32), ALLOCATABLE, DIMENSION(:) :: soln\nREAL(KIND=REAL32), ALLOCATABLE, DIMENSION(:) :: serror\nREAL(KIND=REAL32) :: serror_max\nREAL(KIND=REAL64), ALLOCATABLE, DIMENSION(:,:) :: da\nREAL(KIND=REAL64), ALLOCATABLE, DIMENSION(:) :: db\nREAL(KIND=REAL64), ALLOCATABLE, DIMENSION(:) :: dsoln\nREAL(KIND=REAL64), ALLOCATABLE, DIMENSION(:) :: derror\nREAL(KIND=REAL64) :: derror_max\nINTEGER :: error_flag\nCHARACTER(len=20) :: file_name\nINTEGER :: i, j, n, istat\n!DO i = 1, n\nCHARACTER(len=80) :: msg\n\nWRITE(*, \"('Enter the file name containing the eqns:')\")\nREAD(*, '(A20)') file_name\n\n! Open input data file. Status is OLD because the input data must\n! already exist.\nOPEN (UNIT=1, FILE=file_name, STATUS='OLD', ACTION='READ', &\n IOSTAT=istat, IOMSG=msg)\n\n! Was the OPEN successful?\nfileopen: IF(istat == 0) THEN\n ! The file was opened successfully, so read the number of\n ! equations in the system.\n READ(1, *) n\n ALLOCATE(a(n,n), b(n), soln(n), serror(n), &\n da(n,n), db(n), dsoln(n), derror(n), STAT=istat)\n ! If the memory is available, read in equations and\n ! process them.\n !size_ok: IF (n <= MAX_SIZE) THEN\n solve: IF (istat == 0) THEN\n DO i = 1, n\n READ(1, *) (da(i, j), j = 1, n), db(i)\n END DO\n\n ! Copy the coefficients in single precision for the\n ! single precision solution.\n a = da\n b = db\n\n ! Display coefficients.\n !WRITE(*, \"(/,'Coefficients before call:')\")\n WRITE(*, '(A)') \"Coefficients:\"\n DO i = 1, n\n WRITE(*, \"(1X,7F11.4)\") (a(i, j), j = 1, n), b(i)\n END DO\n\n ! Solve equations\n CALL simul(a, b, soln, n, n, error_flag)\n CALL dsimul(da, db, dsoln, n, n, error_flag)\n\n ! Check for error.\n error_check: IF (error_flag /= 0) THEN\n WRITE(*, 1010)\n 1010 FORMAT(/'Zero pivot encountered!', &\n //'There is no unique solution to this system.')\n ELSE error_check\n ! No errors. Check for roundoff by substituting into\n ! the original equations, and calculate the differences.\n serror_max = 0.\n derror_max = 0._REAL64\n serror = 0.\n derror = 0._REAL64\n DO i = 1, n\n serror(i) = SUM(a(i,:) * soln(:)) - b(i)\n derror(i) = SUM(da(i,:) * dsoln(:)) - db(i)\n END DO\n serror_max = MAXVAL(ABS(serror))\n derror_max = MAXVAL(ABS(derror))\n\n !WRITE(*, \"(/,'Coefficients after call:')\")\n !DO i = 1, n\n ! WRITE(*, \"(1X,7F11.4)\") (a(i, j), j = 1, n), b(i)\n !END DO\n ! Write the final answer.\n !WRITE(*, \"(/,'The solutions are:')\")\n !DO i = 1, n\n ! WRITE(*,\"(2X,'X(',I2,') = ',F16.6)\") i, soln(i)\n !END DO\n\n ! Tell user about it.\n WRITE(*, 1030)\n 1030 FORMAT (/,' i SP x(i) DP x(i) ', &\n ' SP Err DP Err ')\n WRITE(*, 1040)\n 1040 FORMAT (' = ======= ======= ', &\n ' ====== ====== ')\n DO i = 1, n\n WRITE(*, 1050) i, soln(i), dsoln(i), serror(i), derror(i)\n 1050 FORMAT (I3, 2X, G15.6, G15.6, F15.8, F15.8)\n END DO\n\n ! Write maximum errors.\n WRITE(*, 1060) serror_max, derror_max\n 1060 FORMAT (/, 'Max single-precision error:', F15.8, &\n /, 'Max double-precision error:', F15.8)\n END IF error_check\n END IF solve\n DEALLOCATE(a, b, soln, serror, da, db, dsoln, derror)\nELSE fileopen\n ! Else file open failed. Tell user.\n WRITE(*, 1020) msg\n 1020 FORMAT('File open failed: ', A)\nEND IF fileopen\nEND PROGRAM dbl_gauss_jordan\n", "meta": {"hexsha": "1a1dd53093de0c2cc7ff6955aaa6539e605b9811", "size": 8327, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap11/dbl_gauss_jordan.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap11/dbl_gauss_jordan.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap11/dbl_gauss_jordan.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.6139705882, "max_line_length": 69, "alphanum_fraction": 0.6349225411, "num_tokens": 2867, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037784, "lm_q2_score": 0.8418256393148982, "lm_q1q2_score": 0.7824267588540929}} {"text": "! Fortran program to find the root of equation using bisection\n\nprogram bisection\n\timplicit none;\n\n\tinteger iterations /0/;\n\tReal F, x, a, b, c, eps /.00001/; ! tolerance;\n\tF(x) = (x**3 - x - 2); ! statement function\n\n\tx = 0;\n\tdo while((F(x) * F(x + 1)) .ge. 0)\n\t\tx = x + 1;\n\tend do\n\t\n\n\t\n\tif(F(x) .lt. 0) then\n\t\ta = x;\n\t\tb = x + 1; \n\telse\n\t\ta = x + 1;\n\t\tb = x;\n\tend if;\n\n\titerations = iterations + 1;\n\tdo while((abs(a - b)) > eps)\n\t\tc = (a + b ) / 2;\n\n\t\tif(F(c) .le. 0) then\n\t\t\ta = c;\n\t\telse\n\t\t\tb = c;\t\n\t\tend if;\n\tend do\n\n\tprint *, \"Iterations : \", iterations;\n\tprint *, \"Value of c : \", c;\n\tprint *,\"Root : \", F(c); \nend program bisection", "meta": {"hexsha": "6a05e00ab198b42604bce4c140cd327f6274b018", "size": 640, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "III-sem/NumericalMethod/FortranProgram/bisection.f95", "max_stars_repo_name": "ASHD27/JMI-MCA", "max_stars_repo_head_hexsha": "61995cd2c8306b089a9b40d49d9716043d1145db", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-03-18T16:27:33.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-07T12:39:32.000Z", "max_issues_repo_path": "III-sem/NumericalMethod/FortranProgram/bisection.f95", "max_issues_repo_name": "ASHD27/JMI-MCA", "max_issues_repo_head_hexsha": "61995cd2c8306b089a9b40d49d9716043d1145db", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "III-sem/NumericalMethod/FortranProgram/bisection.f95", "max_forks_repo_name": "ASHD27/JMI-MCA", "max_forks_repo_head_hexsha": "61995cd2c8306b089a9b40d49d9716043d1145db", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-11-11T06:49:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-07T12:41:20.000Z", "avg_line_length": 16.4102564103, "max_line_length": 62, "alphanum_fraction": 0.5296875, "num_tokens": 248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172601537141, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7823461522783086}} {"text": "MODULE PolyMod\r\n\r\n ! Polynomial approximant of order N at X0\r\n ! mbp 7/2015 incorporating subroutines from decades past\r\n\r\n IMPLICIT NONE\r\n INTEGER, PRIVATE :: i, j\r\n\r\n INTERFACE Poly\r\n MODULE PROCEDURE PolyR, PolyC, PolyZ\r\n END INTERFACE Poly\r\n\r\nCONTAINS\r\n\r\n FUNCTION PolyR( X0, X, F, N )\r\n\r\n INTEGER, INTENT( IN ) :: N ! order of the polynomial\r\n REAL, INTENT( IN ) :: x0, x( N ), f( N ) ! x, y values of the polynomial\r\n REAL :: ft( N ), h( N ), PolyR\r\n\r\n ! Initialize arrays\r\n\r\n h = x - x0\r\n ft = f\r\n\r\n ! Recursion for solution\r\n IF ( N >= 2) THEN\r\n DO i = 1, N - 1\r\n DO j = 1, N - i\r\n ft( j ) = ( h( j + i ) * ft( i ) - h( i ) * ft( i + 1 ) ) / &\r\n & ( h( j + i ) - h( j ) )\r\n END DO\r\n END DO\r\n ENDIF\r\n\r\n PolyR = ft( 1 )\r\n\r\n END FUNCTION PolyR\r\n\r\n !__________________________________________________________________________\r\n\r\n COMPLEX FUNCTION PolyC( x0, x, f, N )\r\n\r\n INTEGER, INTENT( IN ) :: N ! order of the polynomial\r\n COMPLEX, INTENT( IN ) :: x0, x( N ), f( N ) ! x, y values of the polynomial\r\n COMPLEX :: ft( N ), h( N )\r\n\r\n ! Initialize arrays\r\n h = x - x0\r\n ft = f\r\n\r\n ! Recursion for solution\r\n IF ( N >= 2) THEN\r\n DO i = 1, N-1\r\n DO j = 1, N-I\r\n ! ft( J ) = ( h( J+I ) * ft( J ) - h( J ) * ft( J+1 ) ) / &\r\n ! ( h( J+I ) - h( J ) )\r\n ft( J ) = ft( J ) + h( J ) * ( ft( J ) - ft( J+1 ) ) / &\r\n & ( h( J+I ) - h( J ) )\r\n END DO\r\n END DO\r\n ENDIF\r\n\r\n PolyC = ft( 1 )\r\n\r\n END FUNCTION PolyC\r\n\r\n !__________________________________________________________________________\r\n\r\n FUNCTION PolyZ( x0, x, F, N )\r\n\r\n INTEGER, INTENT( IN ) :: N ! order of the polynomial\r\n COMPLEX ( KIND=8 ), INTENT( IN ) :: x0, x( N ), f( N ) ! x, y values of the polynomial\r\n COMPLEX ( KIND=8 ) :: PolyZ\r\n COMPLEX ( KIND=8 ) :: fT( N ), h( N )\r\n\r\n ! Initialize arrays\r\n h = x - x0\r\n fT = f\r\n\r\n ! Recursion for solution\r\n IF ( N >= 2 ) THEN\r\n DO i = 1, N - 1\r\n DO j = 1, N - i\r\n fT( j ) = ( h( j + i ) * fT( j ) - h( j ) * fT( j + 1 ) ) / ( h( j + i ) - h( j ) )\r\n END DO\r\n END DO\r\n ENDIF\r\n PolyZ = fT( 1 )\r\n\r\n END FUNCTION PolyZ\r\n\r\nEND MODULE PolyMod\r\n\r\n", "meta": {"hexsha": "9bef1f38138ec6e4ad2e9378a05abea0368ad526", "size": 2479, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "at_2020_11_4/misc/PolyMod.f90", "max_stars_repo_name": "IvanaEscobar/sandbox", "max_stars_repo_head_hexsha": "71d62af2c112686c5ce26def35593247cf6a0ccc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "at_2020_11_4/misc/PolyMod.f90", "max_issues_repo_name": "IvanaEscobar/sandbox", "max_issues_repo_head_hexsha": "71d62af2c112686c5ce26def35593247cf6a0ccc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2022-02-15T23:32:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T21:35:12.000Z", "max_forks_repo_path": "at_2020_11_4/misc/PolyMod.f90", "max_forks_repo_name": "IvanaEscobar/sandbox", "max_forks_repo_head_hexsha": "71d62af2c112686c5ce26def35593247cf6a0ccc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.0947368421, "max_line_length": 97, "alphanum_fraction": 0.4441306979, "num_tokens": 803, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172601537142, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7823461502319093}} {"text": "! Solve Poisson equation\n! u_{xx} = f(x) x \\in [a, b]\n! with \n! u(a) = alpha, u(b) = beta\n! using Jacobi iteration and a coarse-grain parallelism approach using OpenMP.\nprogram jacobi_omp2\n\n use omp_lib\n \n implicit none\n \n ! Problem specification and storage\n real(kind=8) :: a, b, alpha, beta\n real(kind=8), dimension(:), allocatable :: x, u, u_new, f\n real(kind=8) :: dx, tolerance, du_max, du_max_thread\n\n integer(kind=4) :: n, num_threads, points_per_thread, thread_id, start, end\n integer(kind=8) :: i, num_iterations\n integer(kind=8), parameter :: MAX_ITERATIONS = 100000\n real(kind=8) :: time(2)\n\n ! Boundaries\n a = 0.d0\n b = 1.d0\n alpha = 0.d0\n beta = 3.d0\n\n ! Specify number of threads to use:\n num_threads = 2\n !$ call omp_set_num_threads(num_threads)\n !$ print \"('Using OpenMP with ',i3,' threads')\", num_threads\n\n N = 100\n\n ! Allocate storage for boundary points too\n allocate(x(0:N + 1), u(0:N + 1), u_new(0:N + 1), f(0:N + 1))\n\n call cpu_time(time(1))\n\n ! grid spacing:\n dx = (b - a) / (N + 1.d0)\n\n ! Tolerance\n tolerance = 0.1d0 * dx**2\n\n ! Determine how many points to handle with each thread.\n ! Note that dividing two integers and assigning to an integer will\n ! round down if the result is not an integer. \n ! This, together with the min(...) in the definition of iend below,\n ! insures that all points will get distributed to some thread.\n points_per_thread = (n + num_threads - 1) / num_threads\n print *, \"points_per_thread = \", points_per_thread\n\n ! Start of the parallel block... \n ! ------------------------------\n\n ! This is the only time threads are forked in this program:\n !$omp parallel private(thread_id, num_iterations, start, end, i, &\n !$OMP du_max_thread)\n\n ! Set thread is, default to 0 if in serial\n thread_id = 0\n !$ thread_id = omp_get_thread_num()\n\n ! Determine start and end index\n start = thread_id * points_per_thread + 1\n end = min((thread_id + 1) * points_per_thread, N)\n\n ! Output some thread information and indexing\n !$omp critical\n print '(\"Thread \",i2,\" will take i = \",i6,\" through i = \",i6)', &\n thread_id, start, end\n !$omp end critical\n\n ! Set iniital guess and construct the grid\n do i=start, end\n ! grid points:\n x(i) = i * dx\n ! source term:\n f(i) = exp(x(i))\n ! initial guess (satisfies boundary conditions and sets them)\n u(i) = alpha + x(i) * (beta - alpha)\n enddo\n ! Note that the above does not set the boundaries, do this in a single thread\n !$omp single\n x(0) = a\n x(N + 1) = b\n u(0) = alpha\n u(N + 1) = beta\n !$omp end single nowait\n\n ! Main Jacobi iteration loop\n do num_iterations=1, MAX_ITERATIONS\n \n ! Make one thread reset the global du_max\n !$omp single\n du_max = 0.d0\n !$omp end single\n\n ! Private to each thread\n du_max_thread = 0.d0\n do i=start, end\n u_new(i) = 0.5d0 * (u(i-1) + u(i+1) - dx**2 * f(i))\n du_max_thread = max(du_max_thread, abs(u_new(i) - u(i)))\n end do\n\n ! Compute global du_max\n !$omp critical\n du_max = max(du_max, du_max_thread)\n !$omp end critical\n\n ! Make sure all threads are done contributing to du_max\n !$omp barrier\n\n ! Have one thread print out the convergence info\n !$omp single\n if (mod(num_iterations, 1000) == 0) then\n print '(\"After \",i8,\" iterations, dumax = \",d16.6,/)', num_iterations, du_max\n end if\n !$omp end single nowait\n\n ! Copy new data into u\n do i=start, end\n u(i) = u_new(i)\n end do\n\n ! Check exit criteria\n if (du_max < tolerance) then\n exit\n end if\n\n ! Make sure all threads are caught up to this point before starting\n ! another iteration\n !$omp barrier\n end do\n\n !$omp end parallel\n\n call cpu_time(time(2))\n if (num_iterations > MAX_ITERATIONS) then\n print *, \"Iteration failed!\"\n stop\n end if\n print '(\"CPU time = \",f12.8, \" seconds\")', time(2) - time(1)\n print *, \"Total number of iterations: \", num_iterations\n\n ! Write out solution for checking\n open(unit=20, file=\"jacobi_omp2.txt\", status=\"unknown\")\n do i=0,n+1\n write(20,'(2e20.10)') x(i), u(i)\n enddo\n close(20)\n\nend program jacobi_omp2", "meta": {"hexsha": "9b98a53867cf1fe97e55bd68bd7678df3dd73d44", "size": 4495, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/jacobi_omp2.f90", "max_stars_repo_name": "fizisist/numerical-methods-pdes", "max_stars_repo_head_hexsha": "659045a19d8285f12447bb93401062c5e3666e18", "max_stars_repo_licenses": ["CC-BY-4.0", "MIT"], "max_stars_count": 100, "max_stars_repo_stars_event_min_datetime": "2016-01-18T21:25:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-03T02:57:22.000Z", "max_issues_repo_path": "src/jacobi_omp2.f90", "max_issues_repo_name": "QamarQQ/numerical-methods-pdes", "max_issues_repo_head_hexsha": "d714a9fd2a94110bd0d7bffefb9043e010c4b7f2", "max_issues_repo_licenses": ["CC-BY-4.0", "MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-01-28T04:19:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-06T22:37:08.000Z", "max_forks_repo_path": "src/jacobi_omp2.f90", "max_forks_repo_name": "QamarQQ/numerical-methods-pdes", "max_forks_repo_head_hexsha": "d714a9fd2a94110bd0d7bffefb9043e010c4b7f2", "max_forks_repo_licenses": ["CC-BY-4.0", "MIT"], "max_forks_count": 82, "max_forks_repo_forks_event_min_datetime": "2016-01-18T23:44:21.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-06T04:59:14.000Z", "avg_line_length": 29.1883116883, "max_line_length": 89, "alphanum_fraction": 0.5873192436, "num_tokens": 1288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.853912760387131, "lm_q1q2_score": 0.7822776830899455}} {"text": "* **********************************************************************\n*\n SUBROUTINE FERMID(ORD, X, RELERR, FD, IERR)\n*\n* **********************************************************************\n* FERMID returns in FD the value of the Fermi-Dirac integral of real\n* order ORD and real argument X, approximated with a relative\n* error RELERR. FERMID is a driver routine that selects FDNINT\n* for integer ORD .LE. 0, FDNEG for X .LE. 0, and FDETA, FDPOS or\n* FDASYM for X .GT. 0. A nonzero value is assigned to the error\n* flag IERR when an error condition occurs:\n* IERR = 1: on input, the requested relative error RELERR is\n* smaller than the machine precision;\n* IERR = 3: an integral of large negative integer order could\n* not be evaluated: increase the parameter NMAX\n* in subroutine FDNINT.\n* IERR = 4: an integral (probably of small argument and large\n* negative order) could not be evaluated with the\n* requested accuracy after the inclusion of ITMAX\n* terms of the series expansion: increase the\n* parameter ITMAX in the routine which produced the\n* error message and in its subroutines.\n* When an error occurs, a message is also printed on the standard\n* output unit by the subroutine FERERR, and the execution of the\n* program is not interrupted; to change/suppress the output unit\n* or to stop the program when an error occurs, only FERERR should\n* be modified.\n*\n* References:\n*\n* [1] M. Goano, \"Series expansion of the Fermi-Dirac integral F_j(x)\n* over the entire domain of real j and x\", Solid-State\n* Electronics, vol. 36, no. 2, pp. 217-221, 1993.\n*\n* [2] J. S. Blakemore, \"Approximation for Fermi-Dirac integrals,\n* especially the function F_1/2(eta) used to describe electron\n* density in a semiconductor\", Solid-State Electronics, vol. 25,\n* no. 11, pp. 1067-1076, 1982.\n*\n* If a single precision version is desired, change all occurrences of\n* *SP in columns 1 to 3 to blanks and comment the corresponding double\n* precision statements.\n*\n* Michele Goano, Politecnico di Torino (goano@polito.it).\n* Latest revision: March 23, 1994.\n* **********************************************************************\n* Parameters\n*SP REAL ONE, TEN, THREE, TWO, ZERO\n DOUBLE PRECISION ONE, TEN, THREE, TWO, ZERO\n*SP PARAMETER (ONE = 1.0E+0, TEN = 10.0E+0, THREE = 3.0E+0,\n*SP & TWO = 2.0E+0, ZERO = 0.0E+0)\n PARAMETER (ONE = 1.0D+0, TEN = 10.0D+0, THREE = 3.0D+0,\n & TWO = 2.0D+0, ZERO = 0.0D+0)\n* Scalar arguments\n INTEGER IERR\n*SP REAL ORD, X, RELERR, FD\n DOUBLE PRECISION ORD, X, RELERR, FD\n* Local scalars\n LOGICAL INTORD, TRYASY\n INTEGER NORD\n*SP REAL RKDIV, XASYMP\n DOUBLE PRECISION RKDIV, XASYMP\n* External subroutines\n EXTERNAL FDASYM, FDETA, FDNEG, FDNINT, FDPOS, FERERR\n* Intrinsic functions\n*SP INTRINSIC ABS, ANINT, EXP, LOG, LOG10, MAX, NINT, SQRT\n INTRINSIC ABS, ANINT, EXP, LOG, LOG10, MAX, NINT, SQRT\n* ----------------------------------------------------------------------\n* Parameters of the floating-point arithmetic system. Only the values\n* for very common machines are provided: the subroutine MACHAR [1]\n* can be used to determine the machine constants of any other system.\n*\n* [1] W. J. Cody,\"Algorithm 665. MACHAR: A subroutine to dynamically\n* determine machine parameters\", ACM Transactions on Mathematical\n* Software, vol. 14, no. 4, pp. 303-311, 1988.\n*\n INTEGER MACHEP, MINEXP, MAXEXP, NEGEXP\n* ANSI/IEEE standard 745-1985: IBM RISC 6000, DEC Alpha (S_floating\n* and T_floating), Apple Macintosh, SunSparc, most IBM PC compilers...\n*SP PARAMETER (MACHEP = -23, MINEXP = -126, MAXEXP = 128,\n*SP & NEGEXP = -24)\n PARAMETER (MACHEP = -52, MINEXP = -1022, MAXEXP = 1024,\n & NEGEXP = -53)\n* DEC VAX (F_floating and D_floating)\n*SP PARAMETER (MACHEP = -24, MINEXP = -128, MAXEXP = 127,\n*SP & NEGEXP = -24)\n*DP PARAMETER (MACHEP = -56, MINEXP = -128, MAXEXP = 127,\n*DP & NEGEXP = -56)\n* CRAY\n*SP PARAMETER (MACHEP = -47, MINEXP = -8193, MAXEXP = 8191,\n*SP & NEGEXP = -47)\n*DP PARAMETER (MACHEP = -95, MINEXP = -8193, MAXEXP = 8191,\n*DP & NEGEXP = -95)\n*\n*SP REAL BETA, EPS, XBIG, XMIN, XMAX\n DOUBLE PRECISION BETA, EPS, XBIG, XMIN, XMAX\n PARAMETER (BETA = TWO, EPS = BETA**MACHEP, XMIN = BETA**MINEXP,\n & XMAX = (BETA**(MAXEXP-1) -\n & BETA**(MAXEXP+NEGEXP-1))*BETA)\n XBIG = LOG(XMAX)\n* ----------------------------------------------------------------------\n IERR = 0\n FD = ZERO\n INTORD = ABS(ORD - ANINT(ORD)).LE.ABS(ORD)*EPS\n IF (RELERR.LT.EPS) THEN\n* Test on the accuracy requested by the user\n IERR = 1\n CALL FERERR(' FERMID: Input error: ' //\n & ' RELERR is smaller than the machine precision')\n ELSE IF (INTORD .AND. ORD.LE.ZERO) THEN\n* Analytic expression for integer ORD .le. 0\n NORD = NINT(ORD)\n CALL FDNINT(NORD, X, FD, IERR)\n ELSE IF (X.LE.ZERO) THEN\n* Series expansion for negative argument\n CALL FDNEG(ORD, X, XMIN, RELERR, FD, IERR)\n ELSE\n* Positive argument: approximations for k_div - 1 and x_min (RKDIV\n* and XASYMP)\n RKDIV = -LOG10(RELERR)\n XASYMP = MAX(ORD - ONE,\n & TWO*RKDIV - ORD*(TWO+RKDIV/TEN),\n & SQRT(ABS((2*RKDIV-ONE-ORD)*(2*RKDIV-ORD))))\n IF (X.GT.XASYMP .OR. INTORD) THEN\n* Asymptotic expansion, used also for positive integer order\n TRYASY = .TRUE.\n CALL FDASYM(ORD, X, EPS, XMAX, XMIN, RELERR, FD, IERR)\n ELSE\n TRYASY = .FALSE.\n END IF\n IF (.NOT.TRYASY .OR. IERR.NE.0) THEN\n IF (ORD.GT.-TWO .AND. X.LT.TWO/THREE) THEN\n* Taylor series expansion, involving eta function\n CALL FDETA(ORD, X, EPS, XMAX, RELERR, FD, IERR)\n ELSE\n* Series expansion for positive argument, involving confluent\n* hypergeometric functions\n CALL FDPOS(ORD, X, EPS, XMAX, RELERR, FD, IERR)\n END IF\n END IF\n END IF\n RETURN\n END\n\n* **********************************************************************\n*\n SUBROUTINE FERINC(ORD, X, B, RELERR, FDI, IERR)\n*\n* **********************************************************************\n* FERINC returns in FDI the value of the incomplete Fermi-Dirac integral\n* of real order ORD and real arguments X and B, approximated with\n* a relative error RELERR. Levin's u transform [2] is used to\n* sum the alternating series (21) of [1]. A nonzero value is\n* assigned to the error flag IERR when an error condition occurs:\n* IERR = 1: on input, the requested relative error RELERR is\n* smaller than the machine precision;\n* IERR = 2: on input, the lower bound B of the incomplete\n* integral is lower than zero;\n* IERR = 3: a complete integral of very large negative\n* integer order could not be evaluated: increase\n* the parameter NMAX in subroutine FDNINT.\n* IERR = 4: an integral (probably of small argument and large\n* negative order) could not be evaluated with the\n* requested accuracy after the inclusion of ITMAX\n* terms of the series expansion: increase the\n* parameter ITMAX in the routine which produced the\n* error message and in its subroutines.\n* When an error occurs, a message is also printed on the standard\n* output unit by the subroutine FERERR, and the execution of the\n* program is not interrupted; to change/suppress the output unit\n* and/or to stop the program when an error occurs, only FERERR\n* should be modified.\n*\n* References:\n*\n* [1] M. Goano, \"Series expansion of the Fermi-Dirac integral F_j(x)\n* over the entire domain of real j and x\", Solid-State\n* Electronics, vol. 36, no. 2, pp. 217-221, 1993.\n*\n* [2] T. Fessler, W. F. Ford, D. A. Smith, \"ALGORITHM 602. HURRY: An\n* acceleration algorithm for scalar sequences and series\", ACM\n* Transactions on Mathematical Software, vol. 9, no. 3,\n* pp. 355-357, September 1983.\n*\n* If a single precision version is desired, change all occurrences of\n* *SP in columns 1 to 3 to blanks and comment the corresponding double\n* precision statements.\n*\n* Michele Goano, Politecnico di Torino (goano@polito.it).\n* Latest revision: March 22, 1994.\n* **********************************************************************\n* Parameters\n INTEGER ITMAX\n PARAMETER (ITMAX = 100)\n*SP REAL ONE, TWO, ZERO\n DOUBLE PRECISION ONE, TWO, ZERO\n*SP PARAMETER (ONE = 1.0E+0, TWO = 2.0E+0, ZERO = 0.0E+0)\n PARAMETER (ONE = 1.0D+0, TWO = 2.0D+0, ZERO = 0.0D+0)\n* Scalar arguments\n INTEGER IERR\n*SP REAL ORD, X, B, RELERR, FDI\n DOUBLE PRECISION ORD, X, B, RELERR, FDI\n* Local scalars\n LOGICAL LOGGAM\n INTEGER JTERM\n*SP REAL BMX, BMXN, BN, EBMX, ENBMX, ENXMB,\n*SP & EXMB, FD, FDOLD, GAMMA, M, S, TERM, U,\n*SP & XMB, XMBN\n DOUBLE PRECISION BMX, BMXN, BN, EBMX, ENBMX, ENXMB,\n & EXMB, FD, FDOLD, GAMMA, M, S, TERM, U,\n & XMB, XMBN\n* Local arrays\n*SP REAL QNUM(ITMAX), QDEN(ITMAX)\n DOUBLE PRECISION QNUM(ITMAX), QDEN(ITMAX)\n* External subroutines\n EXTERNAL FERERR, FERMID, GAMMAC, M1KUMM, U1KUMM, WHIZ\n* Intrinsic functions\n INTRINSIC ABS, ANINT, EXP, LOG\n* ----------------------------------------------------------------------\n* Parameters of the floating-point arithmetic system. Only the values\n* for very common machines are provided: the subroutine MACHAR [1]\n* can be used to determine the machine constants of any other system.\n*\n* [1] W. J. Cody,\"Algorithm 665. MACHAR: A subroutine to dynamically\n* determine machine parameters\", ACM Transactions on Mathematical\n* Software, vol. 14, no. 4, pp. 303-311, 1988.\n*\n INTEGER MACHEP, MINEXP, MAXEXP, NEGEXP\n* ANSI/IEEE standard 745-1985: IBM RISC 6000, DEC Alpha (S_floating\n* and T_floating), Apple Macintosh, SunSparc, most IBM PC compilers...\n*SP PARAMETER (MACHEP = -23, MINEXP = -126, MAXEXP = 128,\n*SP & NEGEXP = -24)\n PARAMETER (MACHEP = -52, MINEXP = -1022, MAXEXP = 1024,\n & NEGEXP = -53)\n* DEC VAX (F_floating and D_floating)\n*SP PARAMETER (MACHEP = -24, MINEXP = -128, MAXEXP = 127,\n*SP & NEGEXP = -24)\n*DP PARAMETER (MACHEP = -56, MINEXP = -128, MAXEXP = 127,\n*DP & NEGEXP = -56)\n* CRAY\n*SP PARAMETER (MACHEP = -47, MINEXP = -8193, MAXEXP = 8191,\n*SP & NEGEXP = -47)\n*DP PARAMETER (MACHEP = -95, MINEXP = -8193, MAXEXP = 8191,\n*DP & NEGEXP = -95)\n*\n*SP REAL EPS, XMIN, XMAX, XTINY\n DOUBLE PRECISION EPS, XMIN, XMAX, XTINY\n PARAMETER (EPS = TWO**MACHEP, XMIN = TWO**MINEXP, XMAX =\n & (TWO**(MAXEXP-1) - TWO**(MAXEXP+NEGEXP-1))*TWO)\n XTINY = LOG(XMIN)\n* ----------------------------------------------------------------------\n IERR = 0\n FDI = ZERO\n IF (RELERR.LT.EPS) THEN\n* Test on the accuracy requested by the user\n IERR = 1\n CALL FERERR(\n & ' FERINC: Input error: RELERR smaller than machine precision')\n ELSE IF (B.LT.ZERO) THEN\n* Error in the argument B\n IERR = 2\n CALL FERERR(' FERINC: Input error: B is lower than zero')\n ELSE IF (B.EQ.ZERO) THEN\n* Complete integral\n CALL FERMID(ORD, X, RELERR, FDI, IERR)\n ELSE IF (ORD.LE.ZERO .AND.\n & ABS(ORD-ANINT(ORD)).LE.ABS(ORD)*EPS) THEN\n* Analytic expression for integer ORD .le. 0\n IF (NINT(ORD).EQ.0) THEN\n XMB = X - B\n IF (XMB.GE.ZERO) THEN\n FDI = XMB + LOG(ONE + EXP(-XMB))\n ELSE\n FDI = LOG(ONE + EXP(XMB))\n END IF\n ELSE\n FDI = ZERO\n END IF\n ELSE IF (B.LT.X) THEN\n* Series involving Kummer's function M\n CALL FERMID(ORD, X, RELERR, FD, IERR)\n CALL GAMMAC(ORD + TWO, EPS, XMAX, GAMMA, IERR)\n IF (IERR.EQ.-1) THEN\n LOGGAM = .TRUE.\n IERR = 0\n END IF\n BMX = B - X\n BMXN = BMX\n EBMX = -EXP(BMX)\n ENBMX = -EBMX\n BN = B\n FDI = XMAX\n DO 10 JTERM = 1, ITMAX\n FDOLD = FDI\n CALL M1KUMM(ORD, BN, EPS, XMAX, RELERR, M)\n TERM = ENBMX*M\n CALL WHIZ(TERM, JTERM, QNUM, QDEN, FDI, S)\n* Check truncation error and convergence\n BMXN = BMXN + BMX\n IF (ABS(FDI-FDOLD).LE.ABS(ONE-FDI)*RELERR .OR.\n & BMXN.LT.XTINY) GO TO 20\n ENBMX = ENBMX*EBMX\n BN = BN + B\n 10 CONTINUE\n IERR = 4\n CALL FERERR(\n & ' FERINC: RELERR not achieved: increase parameter ITMAX')\n 20 CONTINUE\n IF (LOGGAM) THEN\n FDI = FD - EXP((ORD+ONE)*LOG(B) - GAMMA)*(ONE - FDI)\n ELSE\n FDI = FD - B**(ORD + ONE)/GAMMA*(ONE - FDI)\n END IF\n ELSE\n* Series involving Kummer's function U\n CALL GAMMAC(ORD + ONE, EPS, XMAX, GAMMA, IERR)\n IF (IERR.EQ.-1) THEN\n LOGGAM = .TRUE.\n IERR = 0\n END IF\n XMB = X - B\n XMBN = XMB\n EXMB = -EXP(XMB)\n ENXMB = -EXMB\n BN = B\n FDI = XMAX\n DO 30 JTERM = 1, ITMAX\n FDOLD = FDI\n CALL U1KUMM(ORD + ONE, BN, EPS, XMAX, RELERR, U)\n TERM = ENXMB*U\n CALL WHIZ(TERM, JTERM, QNUM, QDEN, FDI, S)\n* Check truncation error and convergence\n XMBN = XMBN + XMB\n IF (ABS(FDI-FDOLD).LE.ABS(FDI)*RELERR .OR.\n & XMBN.LT.XTINY) GO TO 40\n ENXMB = ENXMB*EXMB\n BN = BN + B\n 30 CONTINUE\n IERR = 4\n CALL FERERR(\n & ' FERINC: RELERR not achieved: increase parameter ITMAX')\n 40 CONTINUE\n IF (LOGGAM) THEN\n FDI = EXP((ORD+ONE)*LOG(B) - GAMMA)*FDI\n ELSE\n FDI = B**(ORD + ONE)/GAMMA*FDI\n END IF\n END IF\n RETURN\n END\n\n* **********************************************************************\n*\n SUBROUTINE FDNINT(NORD, X, FD, IERR)\n*\n* **********************************************************************\n* FDNINT returns in FD the value of the Fermi-Dirac integral of integer\n* order NORD (-NMAX-1 .LE. NORD .LE. 0) and argument X, for\n* which an analytical expression is available. A nonzero value\n* is assigned to the error flag IERR when ABS(NORD).GT.NMAX+1:\n* to remedy, increase the parameter NMAX.\n*\n* If a single precision version is desired, change all occurrences of\n* *SP in columns 1 to 3 to blanks and comment the corresponding double\n* precision statements.\n*\n* Michele Goano, Politecnico di Torino (goano@polito.it).\n* Latest revision: March 22, 1994.\n* **********************************************************************\n* Parameters\n INTEGER NMAX\n PARAMETER (NMAX = 100)\n*SP REAL ONE\n DOUBLE PRECISION ONE, ZERO\n*SP PARAMETER (ONE = 1.0E+0, ZERO = 0.0E+0)\n PARAMETER (ONE = 1.0D+0, ZERO = 0.0D+0)\n* Scalar arguments\n INTEGER NORD, IERR\n*SP REAL X, FD\n DOUBLE PRECISION X, FD\n* Local scalars\n INTEGER I, K, N\n*SP REAL A\n DOUBLE PRECISION A\n* Local arrays\n*SP REAL QCOEF(NMAX)\n DOUBLE PRECISION QCOEF(NMAX)\n* External subroutines\n EXTERNAL FERERR\n* Intrinsic functions\n*SP INTRINSIC EXP, LOG, REAL\n INTRINSIC DBLE, EXP, LOG\n* ----------------------------------------------------------------------\n IERR = 0\n FD = ZERO\n* Test on the order, whose absolute value must be lower or equal than\n* NMAX+1\n IF (NORD.LT.-NMAX - 1) THEN\n IERR = 3\n CALL FERERR(\n & ' FDNINT: order too large: increase parameter NMAX')\n ELSE IF (NORD.EQ.0) THEN\n* Analytic expression for NORD .eq. 0\n IF (X.GE.ZERO) THEN\n FD = X + LOG(ONE + EXP(-X))\n ELSE\n FD = LOG(ONE + EXP(X))\n END IF\n ELSE IF (NORD.EQ.-1) THEN\n* Analytic expression for NORD .eq. -1\n IF (X.GE.ZERO) THEN\n FD = ONE/(ONE + EXP(-X))\n ELSE\n A = EXP(X)\n FD = A/(ONE + A)\n END IF\n ELSE\n* Evaluation of the coefficients of the polynomial P(a), having degree\n* (-NORD - 2), appearing at the numerator of the analytic expression\n* for NORD .le. -2\n N = -NORD - 1\n QCOEF(1) = ONE\n DO 20 K = 2, N\n QCOEF(K) = -QCOEF(K - 1)\n DO 10 I = K - 1, 2, -1\n*SP QCOEF(I) = REAL(I)*QCOEF(I) - REAL(K - (I-1))*QCOEF(I - 1)\n QCOEF(I) = DBLE(I)*QCOEF(I) - DBLE(K - (I-1))*QCOEF(I - 1)\n 10 CONTINUE\n 20 CONTINUE\n* Computation of P(a)\n IF (X.GE.ZERO) THEN\n A = EXP(-X)\n FD = QCOEF(1)\n DO 30 I = 2, N\n FD = FD*A + QCOEF(I)\n 30 CONTINUE\n ELSE\n A = EXP(X)\n FD = QCOEF(N)\n DO 40 I = N - 1, 1, -1\n FD = FD*A + QCOEF(I)\n 40 CONTINUE\n END IF\n* Evaluation of the Fermi-Dirac integral\n FD = FD*A*(ONE + A)**NORD\n END IF\n RETURN\n END\n\n\n* **********************************************************************\n*\n SUBROUTINE FDNEG(ORD, X, XMIN, RELERR, FD, IERR)\n*\n* **********************************************************************\n* FDNEG returns in FD the value of the Fermi-Dirac integral of real\n* order ORD and negative argument X, approximated with a relative\n* error RELERR. XMIN represent the smallest non-vanishing\n* floating-point number. Levin's u transform [2] is used to sum\n* the alternating series (13) of [1].\n*\n* References:\n*\n* [1] J. S. Blakemore, \"Approximation for Fermi-Dirac integrals,\n* especially the function F_1/2(eta) used to describe electron\n* density in a semiconductor\", Solid-State Electronics, vol. 25,\n* no. 11, pp. 1067-1076, 1982.\n*\n* [2] T. Fessler, W. F. Ford, D. A. Smith, \"ALGORITHM 602. HURRY: An\n* acceleration algorithm for scalar sequences and series\", ACM\n* Transactions on Mathematical Software, vol. 9, no. 3,\n* pp. 355-357, September 1983.\n*\n* If a single precision version is desired, change all occurrences of\n* *SP in columns 1 to 3 to blanks and comment the corresponding double\n* precision statements.\n*\n* Michele Goano, Politecnico di Torino (goano@polito.it).\n* Latest revision: February 5, 1996.\n* **********************************************************************\n* Parameters\n INTEGER ITMAX\n PARAMETER (ITMAX = 100)\n*SP REAL ONE, ZERO\n DOUBLE PRECISION ONE, ZERO\n*SP PARAMETER (ONE = 1.0E+0, ZERO = 0.0E+0)\n PARAMETER (ONE = 1.0D+0, ZERO = 0.0D+0)\n* Scalar arguments\n INTEGER IERR\n*SP REAL ORD, X, XMIN, RELERR, FD\n DOUBLE PRECISION ORD, X, XMIN, RELERR, FD\n* Local scalars\n INTEGER JTERM\n*SP REAL EX, ENX, FDOLD, S, TERM, XN, XTINY\n DOUBLE PRECISION EX, ENX, FDOLD, S, TERM, XN, XTINY\n* Local arrays\n*SP REAL QNUM(ITMAX), QDEN(ITMAX)\n DOUBLE PRECISION QNUM(ITMAX), QDEN(ITMAX)\n* External subroutines\n EXTERNAL FERERR, WHIZ\n* Intrinsic functions\n*SP INTRINSIC ABS, EXP, LOG, REAL\n INTRINSIC ABS, DBLE, EXP, LOG\n* ----------------------------------------------------------------------\n IERR = 0\n FD = ZERO\n XTINY = LOG(XMIN)\n*\n IF (X.GT.XTINY) THEN\n XN = X\n EX = -EXP(X)\n ENX = -EX\n DO 10 JTERM = 1, ITMAX\n FDOLD = FD\n*SP TERM = ENX/REAL(JTERM)**(ORD + ONE)\n TERM = ENX/DBLE(JTERM)**(ORD + ONE)\n CALL WHIZ(TERM, JTERM, QNUM, QDEN, FD, S)\n* Check truncation error and convergence\n XN = XN + X\n IF (ABS(FD-FDOLD).LE.ABS(FD)*RELERR .OR. XN.LT.XTINY) RETURN\n ENX = ENX*EX\n 10 CONTINUE\n IERR = 4\n CALL FERERR(\n & ' FDNEG: RELERR not achieved: increase parameter ITMAX')\n END IF\n RETURN\n END\n* **********************************************************************\n*\n SUBROUTINE FDPOS(ORD, X, EPS, XMAX, RELERR, FD, IERR)\n*\n* **********************************************************************\n* FDPOS returns in FD the value of the Fermi-Dirac integral of real\n* order ORD and argument X .GT. 0, approximated with a relative\n* error RELERR. EPS and XMAX represent the smallest positive\n* floating-point number such that 1.0+EPS .NE. 1.0, and the\n* largest finite floating-point number, respectively. Levin's u\n* transform [2] is used to sum the alternating series (11) of [1].\n*\n* References:\n*\n* [1] M. Goano, \"Series expansion of the Fermi-Dirac integral F_j(x)\n* over the entire domain of real j and x\", Solid-State\n* Electronics, vol. 36, no. 2, pp. 217-221, 1993.\n*\n* [2] T. Fessler, W. F. Ford, D. A. Smith, \"ALGORITHM 602. HURRY: An\n* acceleration algorithm for scalar sequences and series\", ACM\n* Transactions on Mathematical Software, vol. 9, no. 3,\n* pp. 355-357, September 1983.\n*\n* If a single precision version is desired, change all occurrences of\n* *SP in columns 1 to 3 to blanks and comment the corresponding double\n* precision statements.\n*\n* Michele Goano, Politecnico di Torino (goano@polito.it).\n* Latest revision: March 22, 1994.\n* **********************************************************************\n* Parameters\n INTEGER ITMAX\n PARAMETER (ITMAX = 100)\n*SP REAL ONE, TWO, ZERO\n DOUBLE PRECISION ONE, TWO, ZERO\n*SP PARAMETER (ONE = 1.0E+0, TWO = 2.0E+0, ZERO = 0.0E+0)\n PARAMETER (ONE = 1.0D+0, TWO = 2.0D+0, ZERO = 0.0D+0)\n* Scalar arguments\n INTEGER IERR\n*SP REAL ORD, X, EPS, XMAX, RELERR, FD\n DOUBLE PRECISION ORD, X, EPS, XMAX, RELERR, FD\n* Local scalars\n LOGICAL LOGGAM\n INTEGER JTERM\n*SP REAL FDOLD, GAMMA, M, S, SEGN, TERM, U, XN\n DOUBLE PRECISION FDOLD, GAMMA, M, S, SEGN, TERM, U, XN\n* Local arrays\n*SP REAL QNUM(ITMAX), QDEN(ITMAX)\n DOUBLE PRECISION QNUM(ITMAX), QDEN(ITMAX)\n* External subroutines\n EXTERNAL FERERR, GAMMAC, M1KUMM, U1KUMM, WHIZ\n* Intrinsic functions\n INTRINSIC ABS, EXP, LOG\n* ----------------------------------------------------------------------\n IERR = 0\n FD = ZERO\n*\n CALL GAMMAC(ORD + TWO, EPS, XMAX, GAMMA, IERR)\n IF (IERR.EQ.-1) LOGGAM = .TRUE.\n SEGN = ONE\n XN = X\n FD = XMAX\n DO 10 JTERM = 1, ITMAX\n FDOLD = FD\n CALL U1KUMM(ORD + ONE, XN, EPS, XMAX, RELERR, U)\n CALL M1KUMM(ORD, XN, EPS, XMAX, RELERR, M)\n TERM = SEGN*((ORD+ONE)*U - M)\n CALL WHIZ(TERM, JTERM, QNUM, QDEN, FD, S)\n* Check truncation error and convergence\n IF (ABS(FD-FDOLD).LE.ABS(FD+ONE)*RELERR) GO TO 20\n SEGN = -SEGN\n XN = XN + X\n 10 CONTINUE\n IERR = 4\n CALL FERERR(\n & ' FDPOS: RELERR not achieved: increase parameter ITMAX')\n 20 CONTINUE\n IF (LOGGAM) THEN\n FD = EXP((ORD+ONE)*LOG(X) - GAMMA)*(ONE + FD)\n ELSE\n FD = X**(ORD + ONE)/GAMMA*(ONE + FD)\n END IF\n RETURN\n END\n\n* **********************************************************************\n*\n SUBROUTINE FDETA(ORD, X, EPS, XMAX, RELERR, FD, IERR)\n*\n* **********************************************************************\n* FDETA returns in FD the value of the Fermi-Dirac integral of real\n* order ORD and argument X such that ABS(X) .LE. PI, approximated\n* with a relative error RELERR. EPS and XMAX represent the\n* smallest positive floating-point number such that\n* 1.0+EPS .NE. 1.0, and the largest finite floating-point number,\n* respectively. Taylor series expansion (4) of [1] is used,\n* involving eta function defined in (23.2.19) of [2].\n*\n*\n* References:\n*\n* [1] W. J. Cody and H. C. Thacher, Jr., \"Rational Chebyshev\n* approximations for Fermi-Dirac integrals of orders -1/2, 1/2 and\n* 3/2\", Mathematics of Computation, vol. 21, no. 97, pp. 30-40,\n* 1967.\n*\n* [2] E. V. Haynsworth and K. Goldberg, \"Bernoulli and Euler\n* Polynomials - Riemann Zeta Function\", in \"Handbook of\n* Mathematical Functions with Formulas, Graphs and Mathematical\n* Tables\" (M. Abramowitz and I. A. Stegun, eds.), no. 55 in\n* National Bureau of Standards Applied Mathematics Series, ch. 23,\n* pp. 803-819, Washington, D.C.: U.S. Government Printing Office,\n* 1964.\n*\n* If a single precision version is desired, change all occurrences of\n* *SP in columns 1 to 3 to blanks and comment the corresponding double\n* precision statements.\n*\n* Michele Goano, Politecnico di Torino (goano@polito.it).\n* Latest revision: March 22, 1994.\n* **********************************************************************\n* Parameters\n INTEGER ITMAX\n PARAMETER (ITMAX = 100)\n*SP REAL ONE, PI, TWO, ZERO\n DOUBLE PRECISION ONE, PI, TWO, ZERO\n*SP PARAMETER (ONE = 1.0E+0, PI = 3.141592653589793238462643E+0,\n*SP & TWO = 2.0E+0, ZERO = 0.0E+0)\n PARAMETER (ONE = 1.0D+0, PI = 3.141592653589793238462643D+0,\n & TWO = 2.0D+0, ZERO = 0.0D+0)\n* Scalar arguments\n INTEGER IERR\n*SP REAL ORD, X, EPS, XMAX, RELERR, FD\n DOUBLE PRECISION ORD, X, EPS, XMAX, RELERR, FD\n* Local scalars\n LOGICAL OKJM1, OKJM2\n INTEGER JTERM\n*SP REAL ETA, RJTERM, TERM, XNOFAC\n DOUBLE PRECISION ETA, RJTERM, TERM, XNOFAC\n* External subroutines\n EXTERNAL ETARIE, FERERR\n* Intrinsic functions\n*SP INTRINSIC ABS, REAL\n INTRINSIC ABS, DBLE\n* ----------------------------------------------------------------------\n IERR = 0\n FD = ZERO\n*\n OKJM1 = .FALSE.\n OKJM2 = .FALSE.\n XNOFAC = ONE\n DO 10 JTERM = 1, ITMAX\n*SP RJTERM = REAL(JTERM)\n RJTERM = DBLE(JTERM)\n CALL ETARIE(ORD + TWO - RJTERM, EPS, XMAX, RELERR, ETA)\n TERM = ETA*XNOFAC\n FD = FD + TERM\n* Check truncation error and convergence. The summation is terminated\n* when three consecutive terms of the series satisfy the bound on the\n* relative error\n IF (ABS(TERM).GT.ABS(FD)*RELERR) THEN\n OKJM1 = .FALSE.\n OKJM2 = .FALSE.\n ELSE IF (.NOT.OKJM1) THEN\n OKJM1 = .TRUE.\n ELSE IF (OKJM2) THEN\n RETURN\n ELSE\n OKJM2 = .TRUE.\n END IF\n XNOFAC = XNOFAC*X/RJTERM\n 10 CONTINUE\n IERR = 4\n CALL FERERR(\n & ' FDETA: RELERR not achieved: increase parameter ITMAX')\n RETURN\n END\n\n* **********************************************************************\n*\n SUBROUTINE FDASYM(ORD, X, EPS, XMAX, XMIN, RELERR, FD, IERR)\n*\n* **********************************************************************\n* FDASYM returns in FD the value of the Fermi-Dirac integral of real\n* order ORD and argument X .GT. 0, approximated with a relative\n* error RELERR by means of an asymptotic expansion. EPS, XMAX\n* and XMIN represent the smallest positive floating-point number\n* such that 1.0+EPS .NE. 1.0, the largest finite floating-point\n* number, and the smallest non-vanishing floating-point number,\n* respectively. A nonzero value is assigned to the error flag\n* IERR when the series does not converge. The expansion always\n* terminates after a finite number of steps in case of integer\n* ORD.\n*\n* References:\n*\n* [1] P. Rhodes, \"Fermi-Dirac function of integral order\", Proceedings\n* of the Royal Society of London. Series A - Mathematical and\n* Physical Sciences, vol. 204, pp. 396-405, 1950.\n*\n* [2] R. B. Dingle, \"Asymptotic Expansions: Their Derivation and\n* Interpretation\", London and New York: Academic Press, 1973.\n*\n* If a single precision version is desired, change all occurrences of\n* *SP in columns 1 to 3 to blanks and comment the corresponding double\n* precision statements.\n*\n* Michele Goano, Politecnico di Torino (goano@polito.it).\n* Latest revision: March 22, 1994.\n* **********************************************************************\n* Parameters\n INTEGER ITMAX\n PARAMETER (ITMAX = 100)\n*SP REAL HALF, ONE, PI, TWO, ZERO\n DOUBLE PRECISION HALF, ONE, PI, TWO, ZERO\n*SP PARAMETER (HALF = 0.5E+0, ONE = 1.0E+0,\n*SP & PI = 3.141592653589793238462643E+0, TWO = 2.0E+0,\n*SP & ZERO = 0.0E+0)\n PARAMETER (HALF = 0.5D+0, ONE = 1.0D+0,\n & PI = 3.141592653589793238462643D+0, TWO = 2.0D+0,\n & ZERO = 0.0D+0)\n* Scalar arguments\n INTEGER IERR\n*SP REAL ORD, X, EPS, XMAX, XMIN, RELERR, FD\n DOUBLE PRECISION ORD, X, EPS, XMAX, XMIN, RELERR, FD\n* Local scalars\n LOGICAL LOGGAM\n INTEGER N\n*SP REAL ADD, ADDOLD, ETA, GAMMA, SEQN, XGAM, XM2\n DOUBLE PRECISION ADD, ADDOLD, ETA, GAMMA, SEQN, XGAM, XM2\n* External subroutines\n EXTERNAL ETAN, FDNEG, FERERR, GAMMAC\n* Intrinsic functions\n*SP INTRINSIC ABS, ANINT, COS, EXP, LOG, REAL\n INTRINSIC ABS, ANINT, COS, DBLE, EXP, LOG\n* ----------------------------------------------------------------------\n IERR = 0\n FD = ZERO\n*\n CALL GAMMAC(ORD + TWO, EPS, XMAX, GAMMA, IERR)\n IF (IERR.EQ.-1) THEN\n LOGGAM = .TRUE.\n IERR = 0\n END IF\n SEQN = HALF\n XM2 = X**(-2)\n XGAM = ONE\n ADD = XMAX\n DO 10 N = 1, ITMAX\n ADDOLD = ADD\n*SP XGAM = XGAM*XM2*(ORD + ONE - REAL(2*N-2))*\n*SP & (ORD + ONE - REAL(2*N-1))\n XGAM = XGAM*XM2*(ORD + ONE - DBLE(2*N-2))*\n & (ORD + ONE - DBLE(2*N-1))\n CALL ETAN(2*N, ETA)\n ADD = ETA*XGAM\n IF (ABS(ADD).GE.ABS(ADDOLD) .AND.\n & ABS(ORD - ANINT(ORD)).GT.ABS(ORD)*EPS) THEN\n* Asymptotic series is diverging\n IERR = 1\n RETURN\n END IF\n SEQN = SEQN + ADD\n* Check truncation error and convergence\n IF (ABS(ADD).LE.ABS(SEQN)*RELERR) GO TO 20\n 10 CONTINUE\n IERR = 4\n CALL FERERR(\n & ' FDASYM: RELERR not achieved: increase parameter ITMAX')\n 20 CONTINUE\n CALL FDNEG(ORD, -X, XMIN, RELERR, FD, IERR)\n IF (LOGGAM) THEN\n FD = COS(ORD*PI)*FD + TWO*SEQN*EXP((ORD + ONE)*LOG(X) - GAMMA)\n ELSE\n FD = COS(ORD*PI)*FD + X**(ORD + ONE)*TWO*SEQN/GAMMA\n END IF\n RETURN\n END\n\n* **********************************************************************\n*\n SUBROUTINE M1KUMM(A, X, EPS, XMAX, RELERR, M)\n*\n* **********************************************************************\n* M1KUMM returns in M the value of Kummer's confluent hypergeometric\n* function M(1,2+A,-X), defined in (13.1.2) of [1], for real\n* arguments A and X, approximated with a relative error RELERR.\n* EPS and XMAX represent the smallest positive floating-point\n* number such that 1.0+EPS .NE. 1.0, and the largest finite\n* floating-point number, respectively. Asymptotic expansion [1]\n* or continued fraction representation [2] is used.\n* Renormalization is carried out as proposed in [3].\n*\n* References:\n*\n* [1] L. J. Slater, \"Confluent Hypergeometric Functions\", in \"Handbook\n* of Mathematical Functions with Formulas, Graphs and Mathematical\n* Tables\" (M. Abramowitz and I. A. Stegun, eds.), no. 55 in\n* National Bureau of Standards Applied Mathematics Series, ch. 13,\n* pp. 503-535, Washington, D.C.: U.S. Government Printing Office,\n* 1964.\n*\n* [2] P. Henrici, \"Applied and Computational Complex Analysis.\n* Volume 2. Special Functions-Integral Transforms-Asymptotics-\n* Continued Fractions\", New York: John Wiley & Sons, 1977.\n*\n* [3] W. H. Press, B. P. Flannery, S. A. Teukolsky, W. T. Vetterling,\n* \"Numerical Recipes. The Art of Scientific Computing\", Cambridge:\n* Cambridge University Press, 1986.\n*\n* If a single precision version is desired, change all occurrences of\n* *SP in columns 1 to 3 to blanks and comment the corresponding double\n* precision statements.\n*\n* Michele Goano, Politecnico di Torino (goano@polito.it).\n* Latest revision: March 22, 1994.\n* **********************************************************************\n* Parameters\n INTEGER ITMAX\n PARAMETER (ITMAX = 100)\n*SP REAL ONE, PI, TEN, THREE, TWO, ZERO\n DOUBLE PRECISION ONE, PI, TEN, THREE, TWO, ZERO\n*SP PARAMETER (ONE = 1.0E+0, PI = 3.141592653589793238462643E+0,\n*SP & TEN = 10.0E+0, THREE = 3.0E+0, TWO = 2.0E+0,\n*SP & ZERO = 0.0E+0)\n PARAMETER (ONE = 1.0D+0, PI = 3.141592653589793238462643D+0,\n & TEN = 10.0D+0, THREE = 3.0D+0, TWO = 2.0D+0,\n & ZERO = 0.0D+0)\n* Scalar arguments\n*SP REAL A, X, EPS, XMAX, RELERR, M\n DOUBLE PRECISION A, X, EPS, XMAX, RELERR, M\n* Local scalars\n LOGICAL OKASYM\n INTEGER IERR, N\n*SP REAL AA, ADD, ADDOLD, BB, FAC, GAMMA, GOLD, MLOG,\n*SP & P1, P2, Q1, Q2, RKDIV, RN, XASYMP, XBIG\n DOUBLE PRECISION AA, ADD, ADDOLD, BB, FAC, GAMMA, GOLD, MLOG,\n & P1, P2, Q1, Q2, RKDIV, RN, XASYMP, XBIG\n* External subroutines\n EXTERNAL GAMMAC\n* Intrinsic functions\n*SP INTRINSIC ABS, COS, EXP, LOG, LOG10, REAL\n INTRINSIC ABS, COS, EXP, LOG, LOG10, DBLE\n* ----------------------------------------------------------------------\n XBIG = LOG(XMAX)\n OKASYM = .TRUE.\n M = ZERO\n* Special cases\n IF (X.EQ.ZERO) THEN\n M = ONE\n ELSE\n* Approximations for k_div - 1 and x_min (RKDIV and XASYMP)\n RKDIV = -TWO/THREE*LOG10(RELERR)\n XASYMP = MAX(A - ONE,\n & TWO + RKDIV - A*(TWO+RKDIV/TEN),\n & ABS(RKDIV-A))\n IF (X.GT.XASYMP) THEN\n* Asymptotic expansion\n CALL GAMMAC(A+ONE, EPS, XMAX, GAMMA, IERR)\n IF (IERR.EQ.-1) THEN\n* Handling of the logarithm of the gamma function to avoid overflow\n MLOG = GAMMA - X - A*LOG(X)\n IF (MLOG.LT.XBIG) THEN\n M = ONE - COS(PI*A)*EXP(MLOG)\n ELSE\n OKASYM = .FALSE.\n GO TO 20\n END IF\n ELSE\n M = ONE - COS(PI*A)*GAMMA*EXP(-X)/X**A\n END IF\n ADDOLD = XMAX\n ADD = -A/X\n DO 10 N = 1, ITMAX\n* Divergence\n IF (ABS(ADD).GE.ABS(ADDOLD)) THEN\n OKASYM = .FALSE.\n GO TO 20\n END IF\n M = M + ADD\n* Check truncation error and convergence\n IF (ABS(ADD).LE.ABS(M)*RELERR) THEN\n M = M*(A + ONE)/X\n RETURN\n END IF\n ADDOLD = ADD\n*SP ADD = -ADD*(A - REAL(N))/X\n ADD = -ADD*(A - DBLE(N))/X\n 10 CONTINUE\n END IF\n* Continued fraction: initial conditions\n 20 CONTINUE\n GOLD = ZERO\n P1 = ONE\n Q1 = ONE\n P2 = A + TWO\n Q2 = X + A + TWO\n BB = A + TWO\n* Initial value of the normalization factor\n FAC = ONE\n DO 30 N = 1, ITMAX\n* Evaluation of a_(2N+1) and b_(2N+1)\n*SP RN = REAL(N)\n RN = DBLE(N)\n AA = -RN*X\n BB = BB + ONE\n P1 = (AA*P1 + BB*P2)*FAC\n Q1 = (AA*Q1 + BB*Q2)*FAC\n* Evaluation of a_(2N+2) and b_(2N+2)\n AA = (A + RN + ONE)*X\n BB = BB + ONE\n P2 = BB*P1 + AA*P2*FAC\n Q2 = BB*Q1 + AA*Q2*FAC\n IF (Q2.NE.ZERO) THEN\n* Renormalization and evaluation of w_(2N+2)\n FAC = ONE/Q2\n M = P2*FAC\n* Check truncation error and convergence\n IF (ABS(M-GOLD).LT.ABS(M)*RELERR) RETURN\n GOLD = M\n END IF\n 30 CONTINUE\n END IF\n RETURN\n END\n\n* **********************************************************************\n*\n SUBROUTINE U1KUMM(A, X, EPS, XMAX, RELERR, U)\n*\n* **********************************************************************\n* U1KUMM returns in U the value of Kummer's confluent hypergeometric\n* function U(1,1+A,X), defined in (13.1.3) of [1], for real\n* arguments A and X, approximated with a relative error RELERR.\n* EPS and XMAX represent the smallest positive floating-point\n* number such that 1.0+EPS .NE. 1.0, and the largest finite\n* floating-point number, respectively. The relation with the\n* incomplete gamma function is exploited, by means of (13.6.28)\n* and (13.1.29) of [1]. For A .LE. 0 an expansion in terms of\n* Laguerre polynomials is used [3]. Otherwise the recipe of [4]\n* is followed: series expansion (6.5.29) of [2] if X .LT. A+1,\n* continued fraction (6.5.31) of [2] if X .GE. A+1.\n*\n* References:\n*\n* [1] L. J. Slater, \"Confluent Hypergeometric Functions\", ch. 13 in\n* [5], pp. 503-535.\n*\n* [2] P. J. Davis, \"Gamma Function and Related Functions\", ch. 6 in\n* [5], pp. 253-293.\n*\n* [3] P. Henrici, \"Computational Analysis with the HP-25 Pocket\n* Calculator\", New York: John Wiley & Sons, 1977.\n*\n* [4] W. H. Press, B. P. Flannery, S. A. Teukolsky, W. T. Vetterling,\n* \"Numerical Recipes. The Art of Scientific Computing\", Cambridge:\n* Cambridge University Press, 1986.\n*\n* [5] M. Abramowitz and I. A. Stegun (eds.), \"Handbook of Mathematical\n* Functions with Formulas, Graphs and Mathematical Tables\", no. 55\n* in National Bureau of Standards Applied Mathematics Series,\n* Washington, D.C.: U.S. Government Printing Office, 1964.\n*\n* If a single precision version is desired, change all occurrences of\n* *SP in columns 1 to 3 to blanks and comment the corresponding double\n* precision statements.\n*\n* Michele Goano, Politecnico di Torino (goano@polito.it).\n* Latest revision: March 22, 1994.\n* **********************************************************************\n* Parameters\n INTEGER ITMAX\n PARAMETER (ITMAX = 100)\n*SP REAL ONE, ZERO\n DOUBLE PRECISION ONE, ZERO\n*SP PARAMETER (ONE = 1.0E+0, ZERO = 0.0E+0)\n PARAMETER (ONE = 1.0D+0, ZERO = 0.0D+0)\n* Scalar arguments\n*SP REAL A, X, EPS, XMAX, RELERR, U\n DOUBLE PRECISION A, X, EPS, XMAX, RELERR, U\n* Local scalars\n LOGICAL LOGGAM\n INTEGER IERR, N\n*SP REAL A0, A1, ANA, ANF, AP, B0, B1, DEL, FAC, G,\n*SP & GAMMA, GOLD, PLAGN, PLAGN1, PLAGN2, RN, T,\n*SP & ULOG, XBIG\n DOUBLE PRECISION A0, A1, ANA, ANF, AP, B0, B1, DEL, FAC, G,\n & GAMMA, GOLD, PLAGN, PLAGN1, PLAGN2, RN, T,\n & ULOG, XBIG\n* External subroutines\n EXTERNAL GAMMAC\n* Intrinsic functions\n*SP INTRINSIC ABS, EXP, LOG, REAL\n INTRINSIC ABS, DBLE, EXP, LOG\n* ----------------------------------------------------------------------\n XBIG = LOG(XMAX)\n U = ZERO\n* Special cases\n IF (X.EQ.ZERO) THEN\n U = -ONE/A\n* Laguerre polynomials\n ELSE IF (A.LE.ZERO) THEN\n U = ZERO\n PLAGN2 = ZERO\n PLAGN1 = ONE\n G = ONE\n DO 10 N = 1, ITMAX\n*SP RN = REAL(N)\n RN = DBLE(N)\n PLAGN = ((RN-A-ONE)*(PLAGN1-PLAGN2) + (RN+X)*PLAGN1)/RN\n T = G/(PLAGN1*PLAGN)\n U = U + T\n IF (ABS(T).LT.ABS(U)*RELERR) RETURN\n G = G*(RN - A)/(RN + ONE)\n PLAGN2 = PLAGN1\n PLAGN1 = PLAGN\n 10 CONTINUE\n* Series expansion\n ELSE IF (X.LT.A+ONE) THEN\n CALL GAMMAC(A, EPS, XMAX, GAMMA, IERR)\n IF (IERR.EQ.-1) LOGGAM = .TRUE.\n AP = A\n U = ONE/A\n DEL = U\n DO 20 N = 1, ITMAX\n AP = AP + ONE\n DEL = DEL*X/AP\n U = U + DEL\n IF (ABS(DEL).LT.ABS(U)*RELERR) THEN\n IF (LOGGAM) THEN\n ULOG = GAMMA + X + A*LOG(X)\n U = EXP(ULOG) - U\n ELSE\n U = GAMMA*EXP(X)/X**A - U\n END IF\n RETURN\n END IF\n 20 CONTINUE\n* Continued fraction\n ELSE\n GOLD = ZERO\n A0 = ONE\n A1 = X\n B0 = ZERO\n B1 = ONE\n FAC = ONE\n DO 30 N = 1, ITMAX\n*SP RN = REAL(N)\n RN = DBLE(N)\n ANA = RN - A\n A0 = (A1 + A0*ANA)*FAC\n B0 = (B1 + B0*ANA)*FAC\n ANF = RN*FAC\n A1 = X*A0 + ANF*A1\n B1 = X*B0 + ANF*B1\n IF (A1.NE.ZERO) THEN\n FAC = ONE/A1\n U = B1*FAC\n IF (ABS(U-GOLD).LT.ABS(U)*RELERR) RETURN\n GOLD = U\n END IF\n 30 CONTINUE\n END IF\n RETURN\n END\n\n* **********************************************************************\n*\n SUBROUTINE ETARIE(S, EPS, XMAX, RELERR, ETA)\n*\n* **********************************************************************\n* ETARIE returns in ETA the value of the eta function, for real argument\n* S, approximated with a relative error RELERR. EPS and XMAX\n* represent the smallest positive floating-point number such that\n* 1.0+EPS .NE. 1.0, and the largest finite floating-point number,\n* respectively. For S .GT. -1 Levin's u transform [2] is used to\n* sum the alternating series (23.2.19) of [1], except when S is a\n* positive integer. Otherwise the reflection formula (23.2.6) of\n* [1] is employed, involving gamma function evaluation, except in\n* the trivial zeros S = -2N.\n*\n* References:\n*\n* [1] E. V. Haynsworth and K. Goldberg, \"Bernoulli and Euler\n* Polynomials - Riemann Zeta Function\", in \"Handbook of\n* Mathematical Functions with Formulas, Graphs and Mathematical\n* Tables\" (M. Abramowitz and I. A. Stegun, eds.), no. 55 in\n* National Bureau of Standards Applied Mathematics Series, ch. 23,\n* pp. 803-819, Washington, D.C.: U.S. Government Printing Office,\n* 1964.\n*\n* [2] T. Fessler, W. F. Ford, D. A. Smith, \"ALGORITHM 602. HURRY: An\n* acceleration algorithm for scalar sequences and series\", ACM\n* Transactions on Mathematical Software, vol. 9, no. 3,\n* pp. 355-357, September 1983.\n*\n* If a single precision version is desired, change all occurrences of\n* *SP in columns 1 to 3 to blanks and comment the corresponding double\n* precision statements.\n*\n* Michele Goano, Politecnico di Torino (goano@polito.it).\n* Latest revision: March 22, 1994.\n* **********************************************************************\n* Parameters\n*SP REAL ONE, PI, PILOG, TWO, ZERO\n DOUBLE PRECISION ONE, PI, PILOG, TWO, ZERO\n*SP PARAMETER (ONE = 1.0E+0, PI = 3.141592653589793238462643E+0,\n*SP & PILOG = 1.144729885849400174143427E+0, TWO = 2.0E+0,\n*SP & ZERO = 0.0E+0)\n PARAMETER (ONE = 1.0D+0, PI = 3.141592653589793238462643D+0,\n & PILOG = 1.144729885849400174143427D+0, TWO = 2.0D+0,\n & ZERO = 0.0D+0)\n* Scalar arguments\n*SP REAL S, EPS, XMAX, RELERR, ETA\n DOUBLE PRECISION S, EPS, XMAX, RELERR, ETA\n* Local scalars\n LOGICAL LOGGAM\n INTEGER IERR\n*SP REAL ETALOG, GAMMA, TWOTOS, XBIG\n DOUBLE PRECISION ETALOG, GAMMA, TWOTOS, XBIG\n* External subroutines\n EXTERNAL ETALEV, ETAN, GAMMAC\n* Intrinsic functions\n INTRINSIC ANINT, EXP, LOG, MOD, SIN\n* ----------------------------------------------------------------------\n XBIG = LOG(XMAX)\n ETA = ZERO\n*\n IF (S.EQ.ZERO) THEN\n ETA = ONE/TWO\n ELSE IF (S.LT.ZERO .AND. MOD(S, TWO).EQ.ZERO) THEN\n ETA = ZERO\n ELSE IF (S.GT.-ONE) THEN\n IF (ABS(S-ANINT(S)).LE.ABS(S)*EPS) THEN\n CALL ETAN(NINT(S), ETA)\n ELSE\n CALL ETALEV(S, RELERR, ETA)\n END IF\n ELSE\n TWOTOS = TWO**S\n CALL GAMMAC(ONE - S, EPS, XMAX, GAMMA, IERR)\n IF (IERR.EQ.-1) LOGGAM = .TRUE.\n CALL ETALEV(ONE - S, RELERR, ETA)\n IF (LOGGAM) THEN\n ETALOG = (S - ONE)*PILOG+GAMMA+LOG(ETA)\n ETA = (TWOTOS - TWO)/(ONE - TWOTOS)*SIN(S*PI/TWO)*\n & EXP(ETALOG)\n ELSE\n ETA = (TWOTOS - TWO)/(ONE - TWOTOS)*SIN(S*PI/TWO)*\n & PI**(S - ONE)*GAMMA*ETA\n END IF\n END IF\n RETURN\n END\n\n* **********************************************************************\n*\n SUBROUTINE ETALEV(S, RELERR, ETA)\n*\n* **********************************************************************\n* ETALEV returns in ETA the value of the eta function, for real argument\n* S, approximated with a relative error RELERR. Levin's u\n* transform [2] is used to sum the alternating series (23.2.19)\n* of [1].\n*\n* References:\n*\n* [1] E. V. Haynsworth and K. Goldberg, \"Bernoulli and Euler\n* Polynomials - Riemann Zeta Function\", in \"Handbook of\n* Mathematical Functions with Formulas, Graphs and Mathematical\n* Tables\" (M. Abramowitz and I. A. Stegun, eds.), no. 55 in\n* National Bureau of Standards Applied Mathematics Series, ch. 23,\n* pp. 803-819, Washington, D.C.: U.S. Government Printing Office,\n* 1964.\n*\n* [2] T. Fessler, W. F. Ford, D. A. Smith, \"ALGORITHM 602. HURRY: An\n* acceleration algorithm for scalar sequences and series\", ACM\n* Transactions on Mathematical Software, vol. 9, no. 3,\n* pp. 355-357, September 1983.\n*\n* If a single precision version is desired, change all occurrences of\n* *SP in columns 1 to 3 to blanks and comment the corresponding double\n* precision statements.\n*\n* Michele Goano, Politecnico di Torino (goano@polito.it).\n* Latest revision: March 22, 1994.\n* **********************************************************************\n* Parameters\n INTEGER ITMAX\n PARAMETER (ITMAX = 100)\n*SP REAL ONE, ZERO\n DOUBLE PRECISION ONE, ZERO\n*SP PARAMETER (ONE = 1.0E+0, ZERO = 0.0E+0)\n PARAMETER (ONE = 1.0D+0, ZERO = 0.0D+0)\n* Scalar arguments\n*SP REAL S, RELERR, ETA\n DOUBLE PRECISION S, RELERR, ETA\n* Local scalars\n INTEGER JTERM\n*SP REAL ETAOLD, SEGN, SUM, TERM\n DOUBLE PRECISION ETAOLD, SEGN, SUM, TERM\n* Local arrays\n*SP REAL QNUM(ITMAX), QDEN(ITMAX)\n DOUBLE PRECISION QNUM(ITMAX), QDEN(ITMAX)\n* External subroutines\n EXTERNAL WHIZ\n* Intrinsic functions\n*SP INTRINSIC ABS, REAL\n INTRINSIC ABS, DBLE\n* ----------------------------------------------------------------------\n ETA = ZERO\n*\n SEGN = ONE\n DO 10 JTERM = 1, ITMAX\n ETAOLD = ETA\n*SP TERM = SEGN/REAL(JTERM)**S\n TERM = SEGN/DBLE(JTERM)**S\n CALL WHIZ(TERM, JTERM, QNUM, QDEN, ETA, SUM)\n* Check truncation error and convergence\n IF (ABS(ETA-ETAOLD).LE.ABS(ETA)*RELERR) RETURN\n SEGN = -SEGN\n 10 CONTINUE\n END\n\n* **********************************************************************\n*\n SUBROUTINE ETAN(N, ETA)\n*\n* **********************************************************************\n* ETAN returns in ETA the value of the eta function for integer\n* nonnegative argument N, approximated to 25 significant decimal\n* digits.\n*\n* Reference:\n*\n* E. V. Haynsworth and K. Goldberg, \"Bernoulli and Euler Polynomials -\n* Riemann Zeta Function\", in \"Handbook of Mathematical Functions with\n* Formulas, Graphs and Mathematical Tables\" (M. Abramowitz and\n* I. A. Stegun, eds.), no. 55 in National Bureau of Standards Applied\n* Mathematics Series, ch. 23, pp. 803-819, Washington, D.C.: U.S.\n* Government Printing Office, 1964.\n*\n* If a single precision version is desired, change all occurrences of\n* *SP in columns 1 to 3 to blanks and comment the corresponding double\n* precision statements.\n*\n* Michele Goano, Politecnico di Torino (goano@polito.it).\n* Latest revision: March 22, 1994.\n* **********************************************************************\n* Parameters\n*SP REAL HALF, ONE, ZERO\n DOUBLE PRECISION HALF, ONE, ZERO\n*SP PARAMETER (HALF = 0.5E+0, ONE = 1.0E+0, ZERO = 0.0E+0)\n PARAMETER (HALF = 0.5D+0, ONE = 1.0D+0, ZERO = 0.0D+0)\n* Scalar arguments\n INTEGER N\n*SP REAL ETA\n DOUBLE PRECISION ETA\n* Local arrays\n*SP REAL ETABLE(84)\n DOUBLE PRECISION ETABLE(84)\n* ----------------------------------------------------------------------\n SAVE ETABLE\n*SP DATA ETABLE(1), ETABLE(2), ETABLE(3), ETABLE(4),\n*SP & ETABLE(5), ETABLE(6), ETABLE(7), ETABLE(8),\n*SP & ETABLE(9), ETABLE(10), ETABLE(11), ETABLE(12),\n*SP & ETABLE(13), ETABLE(14), ETABLE(15), ETABLE(16) /\n*SP & 0.6931471805599453094172321E+0, 0.8224670334241132182362076E+0,\n*SP & 0.9015426773696957140498036E+0, 0.9470328294972459175765032E+0,\n*SP & 0.9721197704469093059356551E+0, 0.9855510912974351040984392E+0,\n*SP & 0.9925938199228302826704257E+0, 0.9962330018526478992272893E+0,\n*SP & 0.9980942975416053307677830E+0, 0.9990395075982715656392218E+0,\n*SP & 0.9995171434980607541440942E+0, 0.9997576851438581908531797E+0,\n*SP & 0.9998785427632651154921750E+0, 0.9999391703459797181709542E+0,\n*SP & 0.9999695512130992380826329E+0, 0.9999847642149061064416828E+0 /\n*SP DATA ETABLE(17), ETABLE(18), ETABLE(19), ETABLE(20),\n*SP & ETABLE(21), ETABLE(22), ETABLE(23), ETABLE(24),\n*SP & ETABLE(25), ETABLE(26), ETABLE(27), ETABLE(28),\n*SP & ETABLE(29), ETABLE(30), ETABLE(31), ETABLE(32) /\n*SP & 0.9999923782920410119769379E+0, 0.9999961878696101134796892E+0,\n*SP & 0.9999980935081716751068565E+0, 0.9999990466115815221150508E+0,\n*SP & 0.9999995232582155428163167E+0, 0.9999997616132308225478972E+0,\n*SP & 0.9999998808013184395032238E+0, 0.9999999403988923946283614E+0,\n*SP & 0.9999999701988569628344151E+0, 0.9999999850992319965687877E+0,\n*SP & 0.9999999925495504849635159E+0, 0.9999999962747534001087275E+0,\n*SP & 0.9999999981373694181121867E+0, 0.9999999990686822814539786E+0,\n*SP & 0.9999999995343403314542175E+0, 0.9999999997671698959514908E+0 /\n*SP DATA ETABLE(33), ETABLE(34), ETABLE(35), ETABLE(36),\n*SP & ETABLE(37), ETABLE(38), ETABLE(39), ETABLE(40),\n*SP & ETABLE(41), ETABLE(42), ETABLE(43), ETABLE(44),\n*SP & ETABLE(45), ETABLE(46), ETABLE(47), ETABLE(48) /\n*SP & 0.9999999998835848580460305E+0, 0.9999999999417923990453159E+0,\n*SP & 0.9999999999708961895298095E+0, 0.9999999999854480914338848E+0,\n*SP & 0.9999999999927240446065848E+0, 0.9999999999963620219331688E+0,\n*SP & 0.9999999999981810108432087E+0, 0.9999999999990905053804789E+0,\n*SP & 0.9999999999995452526765309E+0, 0.9999999999997726263336959E+0,\n*SP & 0.9999999999998863131653248E+0, 0.9999999999999431565821547E+0,\n*SP & 0.9999999999999715782909081E+0, 0.9999999999999857891453976E+0,\n*SP & 0.9999999999999928945726800E+0, 0.9999999999999964472863337E+0 /\n*SP DATA ETABLE(49), ETABLE(50), ETABLE(51), ETABLE(52),\n*SP & ETABLE(53), ETABLE(54), ETABLE(55), ETABLE(56),\n*SP & ETABLE(57), ETABLE(58), ETABLE(59), ETABLE(60),\n*SP & ETABLE(61), ETABLE(62), ETABLE(63), ETABLE(64) /\n*SP & 0.9999999999999982236431648E+0, 0.9999999999999991118215817E+0,\n*SP & 0.9999999999999995559107906E+0, 0.9999999999999997779553952E+0,\n*SP & 0.9999999999999998889776976E+0, 0.9999999999999999444888488E+0,\n*SP & 0.9999999999999999722444244E+0, 0.9999999999999999861222122E+0,\n*SP & 0.9999999999999999930611061E+0, 0.9999999999999999965305530E+0,\n*SP & 0.9999999999999999982652765E+0, 0.9999999999999999991326383E+0,\n*SP & 0.9999999999999999995663191E+0, 0.9999999999999999997831596E+0,\n*SP & 0.9999999999999999998915798E+0, 0.9999999999999999999457899E+0 /\n*SP DATA ETABLE(65), ETABLE(66), ETABLE(67), ETABLE(68),\n*SP & ETABLE(69), ETABLE(70), ETABLE(71), ETABLE(72),\n*SP & ETABLE(73), ETABLE(74), ETABLE(75), ETABLE(76),\n*SP & ETABLE(77), ETABLE(78), ETABLE(79), ETABLE(80) /\n*SP & 0.9999999999999999999728949E+0, 0.9999999999999999999864475E+0,\n*SP & 0.9999999999999999999932237E+0, 0.9999999999999999999966119E+0,\n*SP & 0.9999999999999999999983059E+0, 0.9999999999999999999991530E+0,\n*SP & 0.9999999999999999999995765E+0, 0.9999999999999999999997882E+0,\n*SP & 0.9999999999999999999998941E+0, 0.9999999999999999999999471E+0,\n*SP & 0.9999999999999999999999735E+0, 0.9999999999999999999999868E+0,\n*SP & 0.9999999999999999999999934E+0, 0.9999999999999999999999967E+0,\n*SP & 0.9999999999999999999999983E+0, 0.9999999999999999999999992E+0 /\n*SP DATA ETABLE(81), ETABLE(82), ETABLE(83), ETABLE(84) /\n*SP & 0.9999999999999999999999996E+0, 0.9999999999999999999999998E+0,\n*SP & 0.9999999999999999999999999E+0, 0.9999999999999999999999999E+0 /\n DATA ETABLE(1), ETABLE(2), ETABLE(3), ETABLE(4),\n & ETABLE(5), ETABLE(6), ETABLE(7), ETABLE(8),\n & ETABLE(9), ETABLE(10), ETABLE(11), ETABLE(12),\n & ETABLE(13), ETABLE(14), ETABLE(15), ETABLE(16) /\n & 0.6931471805599453094172321D+0, 0.8224670334241132182362076D+0,\n & 0.9015426773696957140498036D+0, 0.9470328294972459175765032D+0,\n & 0.9721197704469093059356551D+0, 0.9855510912974351040984392D+0,\n & 0.9925938199228302826704257D+0, 0.9962330018526478992272893D+0,\n & 0.9980942975416053307677830D+0, 0.9990395075982715656392218D+0,\n & 0.9995171434980607541440942D+0, 0.9997576851438581908531797D+0,\n & 0.9998785427632651154921750D+0, 0.9999391703459797181709542D+0,\n & 0.9999695512130992380826329D+0, 0.9999847642149061064416828D+0 /\n DATA ETABLE(17), ETABLE(18), ETABLE(19), ETABLE(20),\n & ETABLE(21), ETABLE(22), ETABLE(23), ETABLE(24),\n & ETABLE(25), ETABLE(26), ETABLE(27), ETABLE(28),\n & ETABLE(29), ETABLE(30), ETABLE(31), ETABLE(32) /\n & 0.9999923782920410119769379D+0, 0.9999961878696101134796892D+0,\n & 0.9999980935081716751068565D+0, 0.9999990466115815221150508D+0,\n & 0.9999995232582155428163167D+0, 0.9999997616132308225478972D+0,\n & 0.9999998808013184395032238D+0, 0.9999999403988923946283614D+0,\n & 0.9999999701988569628344151D+0, 0.9999999850992319965687877D+0,\n & 0.9999999925495504849635159D+0, 0.9999999962747534001087275D+0,\n & 0.9999999981373694181121867D+0, 0.9999999990686822814539786D+0,\n & 0.9999999995343403314542175D+0, 0.9999999997671698959514908D+0 /\n DATA ETABLE(33), ETABLE(34), ETABLE(35), ETABLE(36),\n & ETABLE(37), ETABLE(38), ETABLE(39), ETABLE(40),\n & ETABLE(41), ETABLE(42), ETABLE(43), ETABLE(44),\n & ETABLE(45), ETABLE(46), ETABLE(47), ETABLE(48) /\n & 0.9999999998835848580460305D+0, 0.9999999999417923990453159D+0,\n & 0.9999999999708961895298095D+0, 0.9999999999854480914338848D+0,\n & 0.9999999999927240446065848D+0, 0.9999999999963620219331688D+0,\n & 0.9999999999981810108432087D+0, 0.9999999999990905053804789D+0,\n & 0.9999999999995452526765309D+0, 0.9999999999997726263336959D+0,\n & 0.9999999999998863131653248D+0, 0.9999999999999431565821547D+0,\n & 0.9999999999999715782909081D+0, 0.9999999999999857891453976D+0,\n & 0.9999999999999928945726800D+0, 0.9999999999999964472863337D+0 /\n DATA ETABLE(49), ETABLE(50), ETABLE(51), ETABLE(52),\n & ETABLE(53), ETABLE(54), ETABLE(55), ETABLE(56),\n & ETABLE(57), ETABLE(58), ETABLE(59), ETABLE(60),\n & ETABLE(61), ETABLE(62), ETABLE(63), ETABLE(64) /\n & 0.9999999999999982236431648D+0, 0.9999999999999991118215817D+0,\n & 0.9999999999999995559107906D+0, 0.9999999999999997779553952D+0,\n & 0.9999999999999998889776976D+0, 0.9999999999999999444888488D+0,\n & 0.9999999999999999722444244D+0, 0.9999999999999999861222122D+0,\n & 0.9999999999999999930611061D+0, 0.9999999999999999965305530D+0,\n & 0.9999999999999999982652765D+0, 0.9999999999999999991326383D+0,\n & 0.9999999999999999995663191D+0, 0.9999999999999999997831596D+0,\n & 0.9999999999999999998915798D+0, 0.9999999999999999999457899D+0 /\n DATA ETABLE(65), ETABLE(66), ETABLE(67), ETABLE(68),\n & ETABLE(69), ETABLE(70), ETABLE(71), ETABLE(72),\n & ETABLE(73), ETABLE(74), ETABLE(75), ETABLE(76),\n & ETABLE(77), ETABLE(78), ETABLE(79), ETABLE(80) /\n & 0.9999999999999999999728949D+0, 0.9999999999999999999864475D+0,\n & 0.9999999999999999999932237D+0, 0.9999999999999999999966119D+0,\n & 0.9999999999999999999983059D+0, 0.9999999999999999999991530D+0,\n & 0.9999999999999999999995765D+0, 0.9999999999999999999997882D+0,\n & 0.9999999999999999999998941D+0, 0.9999999999999999999999471D+0,\n & 0.9999999999999999999999735D+0, 0.9999999999999999999999868D+0,\n & 0.9999999999999999999999934D+0, 0.9999999999999999999999967D+0,\n & 0.9999999999999999999999983D+0, 0.9999999999999999999999992D+0 /\n DATA ETABLE(81), ETABLE(82), ETABLE(83), ETABLE(84) /\n & 0.9999999999999999999999996D+0, 0.9999999999999999999999998D+0,\n & 0.9999999999999999999999999D+0, 0.9999999999999999999999999D+0 /\n* ----------------------------------------------------------------------\n ETA = ZERO\n IF (N.EQ.0) THEN\n ETA = HALF\n ELSE IF (N.LE.84) THEN\n ETA = ETABLE(N)\n ELSE IF (N.GT.84) THEN\n ETA = ONE\n END IF\n RETURN\n END\n\n* **********************************************************************\n*\n SUBROUTINE FERERR(ERRMSG)\n*\n* **********************************************************************\n* FERERR prints on the standard output unit an explanatory message of\n* the error condition occured in the package which approximates\n* the complete and incomplete Fermi-Dirac integral.\n*\n* Michele Goano, Politecnico di Torino (goano@polito.it).\n* Latest revision: March 22, 1994.\n* **********************************************************************\n* Scalar arguments\n CHARACTER*(*) ERRMSG\n* ----------------------------------------------------------------------\n WRITE (*, FMT = 99999) ERRMSG\n* If you want to interrupt the execution after an error has occurred,\n* replace the RETURN statement with a STOP\n STOP\nc RETURN\n99999 FORMAT (A)\n END\n*\n* **********************************************************************\n*\n SUBROUTINE GAMMAC(X, EPS, XINF, GAMMA, IERR)\nC-----------------------------------------------------------------------\nC This routine calculates the gamma function for a real argument X. The\nC logarithm of the gamma function is computed, and the error flag IERR\nC is set to -1, whenever the result would be too large to be represented\nC on the floating-point arithmetic system. Computation is based on an\nC algorithm outlined in W. J. Cody, 'An overview of software development\nC for special functions', Lecture Notes in Mathematics, 506, Numerical\nC Analysis Dundee, 1975, G. A. Watson (ed.), Springer Verlag, Berlin,\nC 1976. The program uses rational functions that approximate the gamma\nC function to at least 20 significant decimal digits. Coefficients for\nC the approximation over the interval (1,2) are unpublished. Those for\nC the approximation for X .GE. 12 are from Hart et al., Computer\nC Approximations, Wiley and Sons, New York, 1968.\nC\nC If a single precision version is desired, change all occurrences of CS\nC in columns 1 and 2 to blanks and comment the corresponding double\nC precision statements.\nC\nC Explanation of machine-dependent variables\nC\nC EPS - the smallest positive floating-point number such that\nC 1.0 + EPS .GT. 1.0\nC XINF - the largest machine representable floating-point number.\nC XBIG - the largest floating-point number such that EXP(XBIG) is\nC machine representable.\nC\nC Error returns\nC\nC The program returns LOG(GAMMA) and sets IERR = -1 when overflow would\nC occur.\nC\nC Author: W. J. Cody\nC Argonne National Laboratory\nC\nC Revised by M. Goano, Politecnico di Torino, to take advantage of\nC Fortran 77 control structures.\nC\nC Latest modification of the original version: May 18, 1982\nC of the revised version: March 21, 1994\nC-----------------------------------------------------------------------\n INTEGER I, IERR, J, N\nCS REAL C, EPS, FACT, GAMMA, HALF, ONE, P, PI, Q, RES,\nCS & SQRTPI, SUM, TWELVE, X, XBIG, XDEN, XINF,\nCS & XNUM, Y, Y1, YSQ, Z, ZERO\n DOUBLE PRECISION C, EPS, FACT, GAMMA, HALF, ONE, P, PI, Q, RES,\n & SQRTPI, SUM, TWELVE, X, XBIG, XDEN, XINF,\n & XNUM, Y, Y1, YSQ, Z, ZERO\n LOGICAL PARITY\n DIMENSION C(7), P(8), Q(8)\nCS INTRINSIC ALOG, EXP, FLOAT, IFIX, SIN\n INTRINSIC DBLE, DEXP, DLOG, DSIN, FLOAT, IFIX, SNGL\nC-----------------------------------------------------------------------\nC Mathematical constants\nC-----------------------------------------------------------------------\nCS PARAMETER (ONE = 1.0E+0, HALF = 0.5E+0, TWELVE = 12.0E+0,\nCS & ZERO = 0.0E+0, PI = 3.1415926535897932384626434E+0,\nCS & SQRTPI = 0.9189385332046727417803297E+0)\n PARAMETER (ONE = 1.0D+0, HALF = 0.5D+0, TWELVE = 12.0D+0,\n & ZERO = 0.0D+0, PI = 3.1415926535897932384626434D+0,\n & SQRTPI = 0.9189385332046727417803297D+0)\nC-----------------------------------------------------------------------\nC SAVE declaration for the arrays of the coefficients\nC-----------------------------------------------------------------------\n SAVE C, P, Q\nC-----------------------------------------------------------------------\nC Numerator and denominator coefficients for rational minimax\nC approximation over (1,2)\nC-----------------------------------------------------------------------\nCS DATA P /-1.71618513886549492533811E+0,\nCS & 2.47656508055759199108314E+1,\nCS & -3.79804256470945635097577E+2,\nCS & 6.29331155312818442661052E+2,\nCS & 8.66966202790413211295064E+2,\nCS & -3.14512729688483675254357E+4,\nCS & -3.61444134186911729807069E+4,\nCS & 6.64561438202405440627855E+4/\n DATA P /-1.71618513886549492533811D+0,\n & 2.47656508055759199108314D+1,\n & -3.79804256470945635097577D+2,\n & 6.29331155312818442661052D+2,\n & 8.66966202790413211295064D+2,\n & -3.14512729688483675254357D+4,\n & -3.61444134186911729807069D+4,\n & 6.64561438202405440627855D+4/\nCS DATA Q /-3.08402300119738975254353E+1,\nCS & 3.15350626979604161529144E+2,\nCS & -1.01515636749021914166146E+3,\nCS & -3.10777167157231109440444E+3,\nCS & 2.25381184209801510330112E+4,\nCS & 4.75584627752788110767815E+3,\nCS & -1.34659959864969306392456E+5,\nCS & -1.15132259675553483497211E+5/\n DATA Q /-3.08402300119738975254353D+1,\n & 3.15350626979604161529144D+2,\n & -1.01515636749021914166146D+3,\n & -3.10777167157231109440444D+3,\n & 2.25381184209801510330112D+4,\n & 4.75584627752788110767815D+3,\n & -1.34659959864969306392456D+5,\n & -1.15132259675553483497211D+5/\nC-----------------------------------------------------------------------\nC Coefficients for minimax approximation over (12, INF)\nC-----------------------------------------------------------------------\nCS DATA C /-1.910444077728E-03,\nCS & 8.4171387781295E-04,\nCS & -5.952379913043012E-04,\nCS & 7.93650793500350248E-04,\nCS & -2.777777777777681622553E-03,\nCS & 8.333333333333333331554247E-02,\nCS & 5.7083835261E-03/\n DATA C /-1.910444077728D-03,\n & 8.4171387781295D-04,\n & -5.952379913043012D-04,\n & 7.93650793500350248D-04,\n & -2.777777777777681622553D-03,\n & 8.333333333333333331554247D-02,\n & 5.7083835261D-03/\nC-----------------------------------------------------------------------\nC Machine dependent local variables\nC-----------------------------------------------------------------------\nCS XBIG = ALOG(XINF)\n XBIG = DLOG(XINF)\nC-----------------------------------------------------------------------\n IERR = 0\n PARITY = .FALSE.\n FACT = ONE\n N = 0\n Y = X\n IF (Y.LE.ZERO) THEN\nC-----------------------------------------------------------------------\nC Argument is negative\nC-----------------------------------------------------------------------\n Y = -X\nCS J = IFIX(Y)\n J = IFIX(SNGL(Y))\nCS RES = Y - FLOAT(J)\n RES = Y - DBLE(FLOAT(J))\n IF (J.NE.(J/2)*2) PARITY = .TRUE.\nCS FACT = -PI/SIN(PI*RES)\n FACT = -PI/DSIN(PI*RES)\n Y = Y + ONE\n END IF\nC-----------------------------------------------------------------------\nC Argument is positive\nC-----------------------------------------------------------------------\n IF (Y.LT.EPS) THEN\nC-----------------------------------------------------------------------\nC Argument .LT. EPS\nC-----------------------------------------------------------------------\n RES = ONE/Y\n ELSE IF (Y.GE.TWELVE) THEN\nC-----------------------------------------------------------------------\nC Evaluate for argument .GE. 12.0\nC-----------------------------------------------------------------------\n YSQ = Y*Y\n SUM = C(7)\n DO 10 I = 1, 6\n SUM = SUM/YSQ + C(I)\n 10 CONTINUE\nCS SUM = SUM/Y + (Y - HALF)*ALOG(Y) - Y + SQRTPI\n SUM = SUM/Y + (Y - HALF)*DLOG(Y) - Y + SQRTPI\n IF (SUM.GT.XBIG) THEN\nC-----------------------------------------------------------------------\nC Return the logarithm to avoid overflow\nC-----------------------------------------------------------------------\n RES = SUM\n IERR = -1\n ELSE\nCS RES = EXP(SUM)\n RES = DEXP(SUM)\n END IF\n ELSE\n Y1 = Y\n IF (Y.GE.ONE) THEN\nC-----------------------------------------------------------------------\nC 1.0 .LT. argument .LT. 12.0, reduce argument if necessary\nC-----------------------------------------------------------------------\nCS N = IFIX(Y) - 1\n N = IFIX(SNGL(Y)) - 1\nCS Y = Y - FLOAT(N)\n Y = Y - DBLE(FLOAT(N))\n Z = Y - ONE\n ELSE\nC-----------------------------------------------------------------------\nC 0.0 .LT. argument .LT. 1.0\nC-----------------------------------------------------------------------\n Z = Y\n Y = Y + ONE\n END IF\nC-----------------------------------------------------------------------\nC Evaluate approximation for 1.0 .LT. argument .LT. 2.0\nC-----------------------------------------------------------------------\n XNUM = ZERO\n XDEN = ONE\n DO 20 I = 1, 8\n XNUM = (XNUM + P(I))*Z\n XDEN = XDEN*Z + Q(I)\n 20 CONTINUE\n RES = XNUM/XDEN + ONE\n IF (Y.NE.Y1) THEN\n IF (Y1.GT.Y) THEN\nC-----------------------------------------------------------------------\nC Adjust result for case 2.0 .LT. argument .LT. 12.0\nC-----------------------------------------------------------------------\n DO 30 I = 1, N\n RES = RES*Y\n Y = Y + ONE\n 30 CONTINUE\n ELSE\nC-----------------------------------------------------------------------\nC Adjust result for case 0.0 .LT. argument .LT. 1.0\nC-----------------------------------------------------------------------\n RES = RES/Y1\n END IF\n END IF\n END IF\nC-----------------------------------------------------------------------\nC Final adjustments and return\nC-----------------------------------------------------------------------\n IF (PARITY) RES = -RES\n IF (FACT.NE.ONE) RES = FACT/RES\n GAMMA = RES\n 40 CONTINUE\n RETURN\n END\n*\n* **********************************************************************\n*\n SUBROUTINE WHIZ(TERM, ITERM, QNUM, QDEN, RESULT, S)\n************************************************************************\n* ALGORITHM 602, COLLECTED ALGORITHMS FROM ACM.\n* ALGORITHM APPEARED IN ACM-TRANS. MATH. SOFTWARE, VOL.9, NO. 3,\n* SEP., 1983, P. 355-357.\n*\n* The u algorithm for accelerating a series.\n*\n* Arguments:\n* TERM = last element of series\n* ITERM = order of TERM in the series = number of calls to WHIZ\n* QNUM = backward diagonal of numerator array, at least N long\n* QDEN = backward diagonal of denominator array, at least N long\n* RESULT = accelerated value of the sum\n* S = simple sum of the series\n*\n* Inputs: TERM, ITERM\n*\n* Outputs: RESULT, S\n*\n* If a single precision version is desired, change all occurrences of\n* *SP in columns 1 to 3 to blanks and comment the corresponding double\n* precision statements.\n*\n* Revised by M. Goano, Politecnico di Torino.\n* Latest modification of the revised version: April 12, 1993\n************************************************************************\n* Parameters\n*SP REAL ONE, ZERO\n DOUBLE PRECISION ONE, ZERO\n*SP PARAMETER (ONE = 1.0E+0, ZERO = 0.0E+0)\n PARAMETER (ONE = 1.0D+0, ZERO = 0.0D+0)\n* Scalar arguments\n INTEGER ITERM\n*SP REAL RESULT, S, TERM\n DOUBLE PRECISION RESULT, S, TERM\n* Array arguments\n*SP REAL QNUM(*), QDEN(*)\n DOUBLE PRECISION QNUM(*), QDEN(*)\n* Local scalars\n INTEGER J, K, L\n*SP REAL C, FACTOR, FJ, FL, FTERM, RATIO\n DOUBLE PRECISION C, FACTOR, FJ, FL, FTERM, RATIO\n* Intrinsic functions\n*SP INTRINSIC REAL\n INTRINSIC DBLE\n* ----------------------------------------------------------------------\n IF (ITERM.EQ.1) S = ZERO\n* Get ITERM diagonal\n S = TERM + S\n L = ITERM - 1\n*SP FTERM = REAL(ITERM)\n FTERM = DBLE(ITERM)\n QDEN(ITERM) = ONE/(TERM*FTERM**2)\n QNUM(ITERM) = S*QDEN(ITERM)\n IF (ITERM.GT.1) THEN\n FACTOR = ONE\n*SP FL = REAL(L)\n FL = DBLE(L)\n RATIO = FL/FTERM\n DO 10 K = 1, L\n J = ITERM - K\n*SP FJ = REAL(J)\n FJ = DBLE(J)\n C = FACTOR*FJ/FTERM\n FACTOR = FACTOR*RATIO\n QDEN(J) = QDEN(J + 1) - C*QDEN(J)\n QNUM(J) = QNUM(J + 1) - C*QNUM(J)\n 10 CONTINUE\n END IF\n RESULT = QNUM(1)/QDEN(1)\n RETURN\n END\n*\n* **********************************************************************\n*\n SUBROUTINE MACHAR(IBETA,IT,IRND,NGRD,MACHEP,NEGEP,IEXP,MINEXP,\n 1 MAXEXP,EPS,EPSNEG,XMIN,XMAX)\nC----------------------------------------------------------------------\nC This Fortran 77 subroutine is intended to determine the parameters\nC of the floating-point arithmetic system specified below. The\nC determination of the first three uses an extension of an algorithm\nC due to M. Malcolm, CACM 15 (1972), pp. 949-951, incorporating some,\nC but not all, of the improvements suggested by M. Gentleman and S.\nC Marovich, CACM 17 (1974), pp. 276-277. An earlier version of this\nC program was published in the book Software Manual for the\nC Elementary Functions by W. J. Cody and W. Waite, Prentice-Hall,\nC Englewood Cliffs, NJ, 1980.\nC\nC If a single precision version is desired, change all occurrences of\nC CS in columns 1 and 2 to blanks and comment the corresponding double\nC precision statements.\nC\nC Parameter values reported are as follows:\nC\nC IBETA - the radix for the floating-point representation\nC IT - the number of base IBETA digits in the floating-point\nC significand\nC IRND - 0 if floating-point addition chops\nC 1 if floating-point addition rounds, but not in the\nC IEEE style\nC 2 if floating-point addition rounds in the IEEE style\nC 3 if floating-point addition chops, and there is\nC partial underflow\nC 4 if floating-point addition rounds, but not in the\nC IEEE style, and there is partial underflow\nC 5 if floating-point addition rounds in the IEEE style,\nC and there is partial underflow\nC NGRD - the number of guard digits for multiplication with\nC truncating arithmetic. It is\nC 0 if floating-point arithmetic rounds, or if it\nC truncates and only IT base IBETA digits\nC participate in the post-normalization shift of the\nC floating-point significand in multiplication;\nC 1 if floating-point arithmetic truncates and more\nC than IT base IBETA digits participate in the\nC post-normalization shift of the floating-point\nC significand in multiplication.\nC MACHEP - the largest negative integer such that\nC 1.0+FLOAT(IBETA)**MACHEP .NE. 1.0, except that\nC MACHEP is bounded below by -(IT+3)\nC NEGEPS - the largest negative integer such that\nC 1.0-FLOAT(IBETA)**NEGEPS .NE. 1.0, except that\nC NEGEPS is bounded below by -(IT+3)\nC IEXP - the number of bits (decimal places if IBETA = 10)\nC reserved for the representation of the exponent\nC (including the bias or sign) of a floating-point\nC number\nC MINEXP - the largest in magnitude negative integer such that\nC FLOAT(IBETA)**MINEXP is positive and normalized\nC MAXEXP - the smallest positive power of BETA that overflows\nC EPS - FLOAT(IBETA)**MACHEP.\nC EPSNEG - FLOAT(IBETA)**NEGEPS.\nC XMIN - the smallest non-vanishing normalized floating-point\nC power of the radix, i.e., XMIN = FLOAT(IBETA)**MINEXP\nC XMAX - the largest finite floating-point number. In\nC particular XMAX = (1.0-EPSNEG)*FLOAT(IBETA)**MAXEXP\nC Note - on some machines XMAX will be only the\nC second, or perhaps third, largest number, being\nC too small by 1 or 2 units in the last digit of\nC the significand.\nC\nC Latest modification: May 30, 1989\nC\nC Author: W. J. Cody\nC Mathematics and Computer Science Division\nC Argonne National Laboratory\nC Argonne, IL 60439\nC\nC----------------------------------------------------------------------\n INTEGER I,IBETA,IEXP,IRND,IT,ITEMP,IZ,J,K,MACHEP,MAXEXP,\n 1 MINEXP,MX,NEGEP,NGRD,NXRES\nCS REAL\n DOUBLE PRECISION\n 1 A,B,BETA,BETAIN,BETAH,CONV,EPS,EPSNEG,ONE,T,TEMP,TEMPA,\n 2 TEMP1,TWO,XMAX,XMIN,Y,Z,ZERO\nC----------------------------------------------------------------------\nCS CONV(I) = REAL(I)\n CONV(I) = DBLE(I)\n ONE = CONV(1)\n TWO = ONE + ONE\n ZERO = ONE - ONE\nC----------------------------------------------------------------------\nC Determine IBETA, BETA ala Malcolm.\nC----------------------------------------------------------------------\n A = ONE\n 10 A = A + A\n TEMP = A+ONE\n TEMP1 = TEMP-A\n IF (TEMP1-ONE .EQ. ZERO) GO TO 10\n B = ONE\n 20 B = B + B\n TEMP = A+B\n ITEMP = INT(TEMP-A)\n IF (ITEMP .EQ. 0) GO TO 20\n IBETA = ITEMP\n BETA = CONV(IBETA)\nC----------------------------------------------------------------------\nC Determine IT, IRND.\nC----------------------------------------------------------------------\n IT = 0\n B = ONE\n 100 IT = IT + 1\n B = B * BETA\n TEMP = B+ONE\n TEMP1 = TEMP-B\n IF (TEMP1-ONE .EQ. ZERO) GO TO 100\n IRND = 0\n BETAH = BETA / TWO\n TEMP = A+BETAH\n IF (TEMP-A .NE. ZERO) IRND = 1\n TEMPA = A + BETA\n TEMP = TEMPA+BETAH\n IF ((IRND .EQ. 0) .AND. (TEMP-TEMPA .NE. ZERO)) IRND = 2\nC----------------------------------------------------------------------\nC Determine NEGEP, EPSNEG.\nC----------------------------------------------------------------------\n NEGEP = IT + 3\n BETAIN = ONE / BETA\n A = ONE\n DO 200 I = 1, NEGEP\n A = A * BETAIN\n 200 CONTINUE\n B = A\n 210 TEMP = ONE-A\n IF (TEMP-ONE .NE. ZERO) GO TO 220\n A = A * BETA\n NEGEP = NEGEP - 1\n GO TO 210\n 220 NEGEP = -NEGEP\n EPSNEG = A\nC----------------------------------------------------------------------\nC Determine MACHEP, EPS.\nC----------------------------------------------------------------------\n MACHEP = -IT - 3\n A = B\n 300 TEMP = ONE+A\n IF (TEMP-ONE .NE. ZERO) GO TO 320\n A = A * BETA\n MACHEP = MACHEP + 1\n GO TO 300\n 320 EPS = A\nC----------------------------------------------------------------------\nC Determine NGRD.\nC----------------------------------------------------------------------\n NGRD = 0\n TEMP = ONE+EPS\n IF ((IRND .EQ. 0) .AND. (TEMP*ONE-ONE .NE. ZERO)) NGRD = 1\nC----------------------------------------------------------------------\nC Determine IEXP, MINEXP, XMIN.\nC\nC Loop to determine largest I and K = 2**I such that\nC (1/BETA) ** (2**(I))\nC does not underflow.\nC Exit from loop is signaled by an underflow.\nC----------------------------------------------------------------------\n I = 0\n K = 1\n Z = BETAIN\n T = ONE + EPS\n NXRES = 0\n 400 Y = Z\n Z = Y * Y\nC----------------------------------------------------------------------\nC Check for underflow here.\nC----------------------------------------------------------------------\n A = Z * ONE\n TEMP = Z * T\n IF ((A+A .EQ. ZERO) .OR. (ABS(Z) .GE. Y)) GO TO 410\n TEMP1 = TEMP * BETAIN\n IF (TEMP1*BETA .EQ. Z) GO TO 410\n I = I + 1\n K = K + K\n GO TO 400\n 410 IF (IBETA .EQ. 10) GO TO 420\n IEXP = I + 1\n MX = K + K\n GO TO 450\nC----------------------------------------------------------------------\nC This segment is for decimal machines only.\nC----------------------------------------------------------------------\n 420 IEXP = 2\n IZ = IBETA\n 430 IF (K .LT. IZ) GO TO 440\n IZ = IZ * IBETA\n IEXP = IEXP + 1\n GO TO 430\n 440 MX = IZ + IZ - 1\nC----------------------------------------------------------------------\nC Loop to determine MINEXP, XMIN.\nC Exit from loop is signaled by an underflow.\nC----------------------------------------------------------------------\n 450 XMIN = Y\n Y = Y * BETAIN\nC----------------------------------------------------------------------\nC Check for underflow here.\nC----------------------------------------------------------------------\n A = Y * ONE\n TEMP = Y * T\n IF (((A+A) .EQ. ZERO) .OR. (ABS(Y) .GE. XMIN)) GO TO 460\n K = K + 1\n TEMP1 = TEMP * BETAIN\n IF ((TEMP1*BETA .NE. Y) .OR. (TEMP .EQ. Y)) THEN\n GO TO 450\n ELSE\n NXRES = 3\n XMIN = Y\n END IF\n 460 MINEXP = -K\nC----------------------------------------------------------------------\nC Determine MAXEXP, XMAX.\nC----------------------------------------------------------------------\n IF ((MX .GT. K+K-3) .OR. (IBETA .EQ. 10)) GO TO 500\n MX = MX + MX\n IEXP = IEXP + 1\n 500 MAXEXP = MX + MINEXP\nC----------------------------------------------------------------------\nC Adjust IRND to reflect partial underflow.\nC----------------------------------------------------------------------\n IRND = IRND + NXRES\nC----------------------------------------------------------------------\nC Adjust for IEEE-style machines.\nC----------------------------------------------------------------------\n IF (IRND .GE. 2) MAXEXP = MAXEXP - 2\nC----------------------------------------------------------------------\nC Adjust for machines with implicit leading bit in binary\nC significand, and machines with radix point at extreme\nC right of significand.\nC----------------------------------------------------------------------\n I = MAXEXP + MINEXP\n IF ((IBETA .EQ. 2) .AND. (I .EQ. 0)) MAXEXP = MAXEXP - 1\n IF (I .GT. 20) MAXEXP = MAXEXP - 1\n IF (A .NE. Y) MAXEXP = MAXEXP - 2\n XMAX = ONE - EPSNEG\n IF (XMAX*ONE .NE. XMAX) XMAX = ONE - BETA * EPSNEG\n XMAX = XMAX / (BETA * BETA * BETA * XMIN)\n I = MAXEXP + MINEXP + 3\n IF (I .LE. 0) GO TO 520\n DO 510 J = 1, I\n IF (IBETA .EQ. 2) XMAX = XMAX + XMAX\n IF (IBETA .NE. 2) XMAX = XMAX * BETA\n 510 CONTINUE\n 520 RETURN\nC---------- Last line of MACHAR ----------\n END\n", "meta": {"hexsha": "3e067744a3a9889bd90b948451cbba969c5dddd7", "size": 83165, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/sub_fermi.f", "max_stars_repo_name": "aravindhk/Vides", "max_stars_repo_head_hexsha": "65d9ea9764ddf5f6ef40e869bd31387d0e3e378f", "max_stars_repo_licenses": ["BSD-4-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-11-03T17:24:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-02T06:06:50.000Z", "max_issues_repo_path": "src/sub_fermi.f", "max_issues_repo_name": "aravindhk/Vides", "max_issues_repo_head_hexsha": "65d9ea9764ddf5f6ef40e869bd31387d0e3e378f", "max_issues_repo_licenses": ["BSD-4-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/sub_fermi.f", "max_forks_repo_name": "aravindhk/Vides", "max_forks_repo_head_hexsha": "65d9ea9764ddf5f6ef40e869bd31387d0e3e378f", "max_forks_repo_licenses": ["BSD-4-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.3962170234, "max_line_length": 72, "alphanum_fraction": 0.5188961703, "num_tokens": 25190, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705932, "lm_q2_score": 0.83973396967765, "lm_q1q2_score": 0.7821807101798065}} {"text": "C$Procedure VLCOM3 ( Vector linear combination, 3 dimensions )\n \n SUBROUTINE VLCOM3 ( A, V1, B, V2, C, V3, SUM )\n \nC$ Abstract\nC\nC This subroutine computes the vector linear combination\nC A*V1 + B*V2 + C*V3 of double precision, 3-dimensional vectors.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC VECTOR\nC\nC$ Declarations\n \n DOUBLE PRECISION A\n DOUBLE PRECISION V1 ( 3 )\n DOUBLE PRECISION B\n DOUBLE PRECISION V2 ( 3 )\n DOUBLE PRECISION C\n DOUBLE PRECISION V3 ( 3 )\n DOUBLE PRECISION SUM ( 3 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC A I Coefficient of V1\nC V1 I Vector in 3-space\nC B I Coefficient of V2\nC V2 I Vector in 3-space\nC C I Coefficient of V3\nC V3 I Vector in 3-space\nC SUM O Linear Vector Combination A*V1 + B*V2 + C*V3\nC\nC$ Detailed_Input\nC\nC A is a double precision number.\nC\nC V1 is a double precision 3-dimensional vector.\nC\nC B is a double precision number.\nC\nC V2 is a double precision 3-dimensional vector.\nC\nC C is a double precision number.\nC\nC V3 is a double precision 3-dimensional vector.\nC\nC$ Detailed_Output\nC\nC SUM is a double precision 3-dimensional vector which contains\nC the linear combination A*V1 + B*V2 + C*V3\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC For each index from 1 to 3, this routine implements in FORTRAN\nC code the expression:\nC\nC SUM(I) = A*V1(I) + B*V2(I) + C*V3(I)\nC\nC No error checking is performed to guard against numeric overflow.\nC\nC$ Examples\nC\nC Often one has the components (A,B,C) of a vector in terms\nC of a basis V1, V2, V3. The vector represented by (A,B,C) can\nC be obtained immediately from the call\nC\nC CALL VLCOM3 ( A, V1, B, V2, C, V3, VECTOR )\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 1-NOV-1990 (WLT)\nC\nC-&\n \nC$ Index_Entries\nC\nC linear combination of three 3-dimensional vectors\nC\nC-&\n \n \n SUM(1) = A*V1(1) + B*V2(1) + C*V3(1)\n SUM(2) = A*V1(2) + B*V2(2) + C*V3(2)\n SUM(3) = A*V1(3) + B*V2(3) + C*V3(3)\n \n RETURN\n END\n", "meta": {"hexsha": "8020553469f4a07501547257a2575c202da04cf3", "size": 4011, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/vlcom3.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/vlcom3.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/vlcom3.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 26.9194630872, "max_line_length": 72, "alphanum_fraction": 0.6459735727, "num_tokens": 1263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.931462503162843, "lm_q2_score": 0.83973396967765, "lm_q1q2_score": 0.7821807053868147}} {"text": "module comoving_nd_module\n\n use amrex_error_module\n use amrex_fort_module, only : rt => amrex_real\n\n contains\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n real(rt) function invEz(H0, Om, a)\n real(rt), intent(in) :: H0, Om, a\n invEz = 1.0d0 / ( H0*dsqrt(Om/a + (1.0d0-Om)*a*a) )\n end function invEz\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n subroutine fort_integrate_time_given_a(a0, a1, dt) &\n bind(C, name=\"fort_integrate_time_given_a\")\n\n use fundamental_constants_module, only: Hubble_const\n use comoving_module , only: comoving_h, comoving_OmM\n\n real(rt), intent(in ) :: a0, a1\n real(rt), intent( out) :: dt\n\n real(rt), parameter :: xacc = 1.0d-6\n real(rt) :: H0, Om, prev_soln, h\n integer :: iter, n, j\n\n H0 = comoving_h*Hubble_const\n Om = comoving_OmM\n\n prev_soln = -1.0d0\n ! trapezoidal integration\n do iter = 1, 20 ! max allowed iterations\n\n n = 2**iter\n\n h = (a1-a0)/(n-1)\n\n if (a0 .lt. 1.0d-10) then ! prevent division by zero in invEz\n dt = 0.5*invEz(H0, Om, a1)\n else\n dt = 0.5*(invEz(H0, Om, a0) + invEz(H0, Om, a1))\n endif\n\n do j = 1, n-2\n dt = dt + invEz(H0, Om, a0+j*h)\n enddo\n dt = dt*h\n\n if (iter .gt. 4) then\n if (abs(dt-prev_soln) .le. xacc*abs(prev_soln)) return\n endif\n prev_soln = dt\n enddo\n\n end subroutine fort_integrate_time_given_a\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n subroutine fort_integrate_comoving_a(old_a,new_a,dt) &\n bind(C, name=\"fort_integrate_comoving_a\")\n\n use fundamental_constants_module, only: Hubble_const\n use comoving_module , only: comoving_h, comoving_OmM, comoving_type\n\n implicit none\n\n real(rt), intent(in ) :: old_a, dt\n real(rt), intent( out) :: new_a\n\n real(rt), parameter :: xacc = 1.0d-8\n real(rt) :: H_0, OmL\n real(rt) :: Delta_t, prev_soln\n real(rt) :: start_a, end_a, start_slope, end_slope\n integer :: iter, j, nsteps\n\n if (comoving_h .eq. 0.0d0) then\n new_a = old_a\n return\n endif\n\n H_0 = comoving_h * Hubble_const\n OmL = 1.d0 - comoving_OmM \n\n prev_soln = 2.0d0 ! 0 0) then\n start_slope = H_0*dsqrt(comoving_OmM / start_a + OmL*start_a**2)\n else\n start_slope = comoving_h\n end if\n\n ! Compute a provisional value of ln(a) at the new time \n end_a = start_a + start_slope * Delta_t\n\n ! Compute the slope at the new time\n if (comoving_type > 0) then\n end_slope = H_0*dsqrt(comoving_OmM / end_a + OmL*end_a**2)\n else\n end_slope = comoving_h \n end if\n \n ! Now recompute a at the new time using the average of the two slopes\n end_a = start_a + 0.5d0 * (start_slope + end_slope) * Delta_t\n enddo\n\n new_a = end_a\n if (abs(1.0d0-new_a/prev_soln) .le. xacc) return\n prev_soln = new_a\n\n enddo\n\n end subroutine fort_integrate_comoving_a\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n subroutine fort_integrate_comoving_a_to_z(old_a,z_value,dt) &\n bind(C, name=\"fort_integrate_comoving_a_to_z\")\n\n use fundamental_constants_module, only: Hubble_const\n use comoving_module , only: comoving_h, comoving_OmM, comoving_type\n\n implicit none\n\n real(rt), intent(in ) :: old_a, z_value\n real(rt), intent(inout) :: dt\n\n real(rt), parameter :: xacc = 1.0d-8\n real(rt) :: H_0, OmL\n real(rt) :: Delta_t\n real(rt) :: start_a, end_a, start_slope, end_slope\n real(rt) :: a_value\n integer :: j, nsteps\n\n if (comoving_h .eq. 0.0d0) &\n call amrex_error(\"fort_integrate_comoving_a_to_z: Shouldn't be setting plot_z_values if not evolving a\")\n\n H_0 = comoving_h * Hubble_const\n OmL = 1.d0 - comoving_OmM \n \n ! Translate the target \"z\" into a target \"a\"\n a_value = 1.d0 / (1.d0 + z_value)\n\n ! Use lots of steps if we want to nail the z_value\n nsteps = 1024\n\n ! We integrate a, but stop when a = a_value (or close enough)\n Delta_t = dt/nsteps\n end_a = old_a\n do j = 1, nsteps\n ! This uses RK2 to integrate the ODE:\n ! da / dt = H_0 * sqrt(OmM/a + OmL*a^2)\n start_a = end_a\n\n ! Compute the slope at the old time\n if (comoving_type > 0) then\n start_slope = H_0*dsqrt(comoving_OmM / start_a + OmL*start_a**2)\n else\n start_slope = comoving_h\n end if\n\n ! Compute a provisional value of ln(a) at the new time \n end_a = start_a + start_slope * Delta_t\n\n ! Compute the slope at the new time\n if (comoving_type > 0) then\n end_slope = H_0*dsqrt(comoving_OmM / end_a + OmL*end_a**2)\n else\n end_slope = comoving_h \n end if\n \n ! Now recompute a at the new time using the average of the two slopes\n end_a = start_a + 0.5d0 * (start_slope + end_slope) * Delta_t\n\n ! We have crossed from a too small to a too big in this step\n if ( (end_a - a_value) * (start_a - a_value) < 0) then\n dt = ( ( end_a - a_value) * dble(j ) + &\n (a_value - start_a) * dble(j+1) ) / (end_a - start_a) * Delta_t\n exit\n end if\n end do\n\n end subroutine fort_integrate_comoving_a_to_z\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n subroutine fort_integrate_comoving_a_to_a(old_a,a_value,dt) &\n bind(C, name=\"fort_integrate_comoving_a_to_a\")\n\n use fundamental_constants_module, only: Hubble_const\n use comoving_module , only: comoving_h, comoving_OmM, comoving_type\n\n implicit none\n\n real(rt), intent(in ) :: old_a, a_value\n real(rt), intent(inout) :: dt\n\n real(rt), parameter :: xacc = 1.0d-8\n real(rt) :: H_0, OmL\n real(rt) :: Delta_t\n real(rt) :: start_a, end_a, start_slope, end_slope\n integer :: j, nsteps\n\n real(rt) :: max_dt\n\n if (comoving_h .eq. 0.0d0) &\n call amrex_error(\"fort_integrate_comoving_a_to_z: Shouldn't be setting plot_z_values if not evolving a\")\n\n H_0 = comoving_h * Hubble_const\n OmL = 1.d0 - comoving_OmM \n \n\n ! Use lots of steps if we want to nail the z_value\n! nsteps = 1024\n\n ! Use enough steps if we want to be close to the a_value\n nsteps = 2048\n\n ! We integrate a, but stop when a = a_value (or close enough)\n Delta_t = dt/nsteps\n end_a = old_a\n do j = 1, nsteps\n ! This uses RK2 to integrate the ODE:\n ! da / dt = H_0 * sqrt(OmM/a + OmL*a^2)\n start_a = end_a\n\n ! Compute the slope at the old time\n if (comoving_type > 0) then\n start_slope = H_0*dsqrt(comoving_OmM / start_a + OmL*start_a**2)\n else\n start_slope = comoving_h\n end if\n\n ! Compute a provisional value of ln(a) at the new time \n end_a = start_a + start_slope * Delta_t\n\n ! Compute the slope at the new time\n if (comoving_type > 0) then\n end_slope = H_0*dsqrt(comoving_OmM / end_a + OmL*end_a**2)\n else\n end_slope = comoving_h \n end if\n \n ! Now recompute a at the new time using the average of the two slopes\n end_a = start_a + 0.5d0 * (start_slope + end_slope) * Delta_t\n\n ! We have crossed from a too small to a too big in this step\n if ( (end_a - a_value) * (start_a - a_value) < 0) then\n dt = ( ( end_a - a_value) * dble(j ) + &\n (a_value - start_a) * dble(j+1) ) / (end_a - start_a) * Delta_t\n exit\n end if\n end do\n\n end subroutine fort_integrate_comoving_a_to_a\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n subroutine fort_est_maxdt_comoving_a(old_a,dt)\n\n use fundamental_constants_module, only: Hubble_const\n use comoving_module , only: comoving_h, comoving_OmM, comoving_type\n\n implicit none\n\n real(rt), intent(in ) :: old_a\n real(rt), intent(inout) :: dt\n\n real(rt) :: H_0, OmL\n real(rt) :: max_dt\n\n OmL = 1.d0 - comoving_OmM \n\n ! This subroutine computes dt based on not changing a by more than 5% \n ! if we use forward Euler integration\n ! d(ln(a)) / dt = H_0 * sqrt(OmM/a^3 + OmL)\n\n H_0 = comoving_h * Hubble_const\n\n if (H_0 .ne. 0.0d0) then\n if (comoving_type > 0) then\n max_dt = (0.05d0) / H_0 / dsqrt(comoving_OmM / old_a**3 + OmL)\n else\n max_dt = (0.05d0) / abs(comoving_h)\n end if\n dt = min(dt,max_dt) \n\n else \n\n ! dt is unchanged\n\n end if\n\n end subroutine fort_est_maxdt_comoving_a\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n ! This might only work for t=0=> a=.00625, although constant canceled\n subroutine fort_est_lindt_comoving_a(old_a,new_a,dt)\n\n use fundamental_constants_module, only: Hubble_const\n use comoving_module , only: comoving_h, comoving_OmM, comoving_type\n\n implicit none\n\n real(rt), intent(in ) :: old_a,new_a\n real(rt), intent(inout) :: dt\n\n real(rt) :: H_0, OmL\n real(rt) :: lin_dt\n\n OmL = 1.d0 - comoving_OmM \n\n ! This subroutine computes dt based on not changing a by more than 5% \n ! if we use forward Euler integration\n ! d(ln(a)) / dt = H_0 * sqrt(OmM/a^3 + OmL)\n\n H_0 = comoving_h * Hubble_const\n\n ! Could definately be optimized better\n if (H_0 .ne. 0.0d0) then\n\n lin_dt= ((new_a/(.75**(2/3)*(OmL+ comoving_OmM)**(1/3)))**(.75) - &\n ((old_a/(.75**(2/3)*(OmL+ comoving_OmM)**(1/3)))**(.75) ) ) /H_0\n dt=lin_dt\n \n else \n\n ! dt is unchanged\n\n end if\n\n end subroutine fort_est_lindt_comoving_a\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n subroutine fort_estdt_comoving_a(old_a,new_a,dt,change_allowed,fixed_da,final_a,dt_modified) &\n bind(C, name=\"fort_estdt_comoving_a\")\n\n use comoving_module , only: comoving_h\n\n implicit none\n\n real(rt), intent(in ) :: old_a, change_allowed, fixed_da, final_a\n real(rt), intent(inout) :: dt\n real(rt), intent( out) :: new_a\n integer , intent( out) :: dt_modified\n real(rt) a_value\n real(rt) max_dt\n max_dt = dt\n\n if (comoving_h .ne. 0.0d0) then\n\n if( fixed_da .le. 0.0d0) then\n ! First call this to make sure dt that we send to integration routine isnt outrageous\n call fort_est_maxdt_comoving_a(old_a,dt)\n \n ! Initial call to see if existing dt will work\n call fort_integrate_comoving_a(old_a,new_a,dt)\n \n ! Make sure a isn't growing too fast\n call enforce_percent_change(old_a,new_a,dt,change_allowed)\n else\n ! First call this to make sure dt that we send to integration routine isnt outrageous\n new_a = (old_a + fixed_da);\n call fort_est_lindt_comoving_a(old_a,new_a,dt) \n call fort_est_maxdt_comoving_a(old_a,dt)\n\n ! Then integrate old_a to a_value using dt as a guess for the maximum dt\n ! Output dt is based on a fraction of the input dt\n call fort_integrate_comoving_a_to_a(old_a,new_a,dt)\n endif \n\n ! Make sure we don't go past final_a (if final_a is set)\n if (final_a > 0.0d0) &\n call enforce_final_a(old_a,new_a,dt,final_a)\n\n dt_modified = 1\n\n else\n\n ! dt is unchanged by this call\n\n dt_modified = 0\n\n endif \n\n end subroutine fort_estdt_comoving_a\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n subroutine enforce_percent_change(old_a,new_a,dt,change_allowed)\n\n implicit none\n\n real(rt), intent(in ) :: old_a, change_allowed\n real(rt), intent(inout) :: dt\n real(rt), intent(inout) :: new_a\n\n integer :: i\n real(rt) :: factor\n\n factor = ( (new_a - old_a) / old_a ) / change_allowed\n\n ! Only go into this process if percent change exceeds change_allowed\n\n if (factor > 1.d0) then\n\n do i = 1, 100\n factor = ( (new_a - old_a) / old_a ) / change_allowed\n\n ! Note: 0.99 is just a fudge factor so we don't get bogged down.\n if (factor > 1.d0) then\n dt = (1.d0 / factor) * dt * 0.99d0\n call fort_integrate_comoving_a(old_a,new_a,dt)\n else if (i.lt.100) then\n call fort_integrate_comoving_a(old_a,new_a,dt)\n ! We're done\n return \n else\n call amrex_error(\"Too many iterations in enforce_percent_change\")\n end if\n end do\n\n else\n ! We don't need to do anything\n return \n end if\n\n end subroutine enforce_percent_change\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n subroutine enforce_final_a(old_a,new_a,dt,final_a)\n\n implicit none\n\n real(rt), intent(in ) :: old_a, final_a\n real(rt), intent(inout) :: dt\n real(rt), intent(inout) :: new_a\n\n integer :: i\n real(rt) :: factor\n real(rt), parameter :: eps = 1.d-10\n\n if (old_a > final_a) then\n call amrex_error(\"Oops -- old_a > final_a\")\n end if\n\n ! Only go into this process if new_a is past final_a\n if (new_a > final_a) then\n\n do i = 1, 100\n if ( (new_a > (final_a+eps)) .or. (new_a < final_a) ) then\n factor = (final_a - old_a) / (new_a - old_a)\n dt = dt * factor \n call fort_integrate_comoving_a(old_a,new_a,dt)\n else if (i.lt.100) then\n ! We're done\n return \n else\n call amrex_error(\"Too many iterations in enforce_final_a\")\n end if\n end do\n\n else\n ! We don't need to do anything\n return \n end if\n\n end subroutine enforce_final_a\n\n! ! :::\n! ! ::: ----------------------------------------------------------------\n! ! :::\n\n! subroutine fort_get_omb(frac) &\n! bind(C, name=\"fort_get_omb\")\n\n! use comoving_module, only: comoving_OmB, comoving_OmM\n\n! real(rt) :: frac\n\n! frac = comoving_OmB / comoving_OmM\n\n! end subroutine fort_get_omb\n\n\n! ! :::\n! ! ::: ----------------------------------------------------------------\n! ! :::\n\n! subroutine fort_get_omm(omm) &\n! bind(C, name=\"fort_get_omm\")\n\n! use comoving_module, only: comoving_OmM\n\n! real(rt) :: omm\n\n! omm = comoving_OmM\n\n! end subroutine fort_get_omm\n\n! ! :::\n! ! ::: ----------------------------------------------------------------\n! ! :::\n\n subroutine fort_get_hubble(hubble) &\n bind(C, name=\"fort_get_hubble\")\n\n use comoving_module, only: comoving_h\n\n real(rt) :: hubble\n\n hubble = comoving_h\n\n end subroutine fort_get_hubble\n\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n subroutine fort_set_omb(omb) &\n bind(C, name=\"fort_set_omb\")\n\n use comoving_module, only: comoving_OmB\n\n real(rt), intent(in) :: omb\n\n comoving_OmB = omb\n\n end subroutine fort_set_omb\n\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n subroutine fort_set_omm(omm) &\n bind(C, name=\"fort_set_omm\")\n\n use comoving_module, only: comoving_OmM\n\n real(rt), intent(in) :: omm\n\n comoving_OmM = omm\n\n end subroutine fort_set_omm\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n subroutine fort_set_hubble(hubble) &\n bind(C, name=\"fort_set_hubble\")\n\n use comoving_module, only: comoving_h\n\n real(rt), intent(in) :: hubble\n\n comoving_h = hubble\n\n end subroutine fort_set_hubble\n\nend module comoving_nd_module\n", "meta": {"hexsha": "8325f04e7fadab5f4f1a9487ca7248ac1f2ca8f9", "size": 17611, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source/comoving_nd.f90", "max_stars_repo_name": "Gosenca/axionyx_1.0", "max_stars_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-02-18T09:13:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T21:27:46.000Z", "max_issues_repo_path": "Source/comoving_nd.f90", "max_issues_repo_name": "Gosenca/axionyx_1.0", "max_issues_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-12T08:54:31.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-12T08:54:31.000Z", "max_forks_repo_path": "Source/comoving_nd.f90", "max_forks_repo_name": "Gosenca/axionyx_1.0", "max_forks_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-09-04T10:26:25.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T23:51:51.000Z", "avg_line_length": 29.4498327759, "max_line_length": 114, "alphanum_fraction": 0.5104764068, "num_tokens": 4722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660976007596, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.7821504503085729}} {"text": " SELECT CASE(typeRegression)\n CASE(linreg_id)\n x_cp = x\n y_cp = y\n CASE(logreg_id)\n x_cp = LOG(x)\n y_cp = y\n CASE(expreg_id)\n x_cp = x\n y_cp = LOG(y)\n CASE(potreg_id)\n x_cp = LOG10(x)\n y_cp = LOG10(y)\n END SELECT\n\n var_x = variance(x_cp)\n var_y = variance(y_cp)\n covar_xy = covariance(x_cp,y_cp)\n\n a = covar_xy / var_x\n\n SELECT CASE(typeRegression)\n CASE(expreg_id)\n b = EXP(mean(y_cp) - a*mean(x_cp))\n CASE(potreg_id)\n b = 10**(mean(y_cp) - a*mean(x_cp))\n CASE DEFAULT\n b = mean(y_cp) - a*mean(x_cp)\n END SELECT\n\n R2 = covar_xy**2/var_x/var_y\n\n", "meta": {"hexsha": "7710972284040b74691a92a2227263d6ca443d89", "size": 794, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Statistics_M/include_regression.f90", "max_stars_repo_name": "ecasglez/FortranUtilities", "max_stars_repo_head_hexsha": "a4c88fc190102524f0c669ac20489c5b85a754c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Statistics_M/include_regression.f90", "max_issues_repo_name": "ecasglez/FortranUtilities", "max_issues_repo_head_hexsha": "a4c88fc190102524f0c669ac20489c5b85a754c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Statistics_M/include_regression.f90", "max_forks_repo_name": "ecasglez/FortranUtilities", "max_forks_repo_head_hexsha": "a4c88fc190102524f0c669ac20489c5b85a754c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-16T08:04:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-16T08:04:24.000Z", "avg_line_length": 24.0606060606, "max_line_length": 47, "alphanum_fraction": 0.459697733, "num_tokens": 214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9678992923570261, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.7821276774639276}} {"text": "module util_mod\n use working_prec_mod, only: ik, rk\n implicit none\n private\n\n public :: det\n public :: inverse\n public :: trace\n public :: math_cross_product\n public :: math_euclidean_norm\ncontains\n\n ! det: returns determinant of 3x3 matrix (sarrus)\n pure real(rk) function det (matrix)\n real(rk), dimension(3,3), intent(in) :: matrix\n det = matrix(1,1)*matrix(2,2)*matrix(3,3) &\n + matrix(1,2)*matrix(2,3)*matrix(3,1) &\n + matrix(1,3)*matrix(2,1)*matrix(3,2) &\n - matrix(1,3)*matrix(2,2)*matrix(3,1) &\n - matrix(1,1)*matrix(2,3)*matrix(3,2) &\n - matrix(1,2)*matrix(2,1)*matrix(3,3)\n end function det\n\n pure function inverse(matrix) result (invbox)\n real(rk), intent(in) :: matrix(3,3)\n real(rk) :: invbox(3,3)\n real(rk) :: adj(3,3) ! adjunkt\n\n adj(1,1) = matrix(2,2)*matrix(3,3) - matrix(2,3)*matrix(3,2)\n adj(2,1) = matrix(3,1)*matrix(2,3) - matrix(3,3)*matrix(2,1)\n adj(3,1) = matrix(2,1)*matrix(3,2) - matrix(2,2)*matrix(3,1)\n adj(1,2) = matrix(3,2)*matrix(1,3) - matrix(3,3)*matrix(1,2)\n adj(2,2) = matrix(1,1)*matrix(3,3) - matrix(1,3)*matrix(3,1)\n adj(3,2) = matrix(3,1)*matrix(1,2) - matrix(3,2)*matrix(1,1)\n adj(1,3) = matrix(1,2)*matrix(2,3) - matrix(1,3)*matrix(2,2)\n adj(2,3) = matrix(2,1)*matrix(1,3) - matrix(2,3)*matrix(1,1)\n adj(3,3) = matrix(1,1)*matrix(2,2) - matrix(1,2)*matrix(2,1)\n\n invbox = 1._rk/det(matrix) * adj\n end function inverse\n\n pure real(rk) function trace (matrix)\n real(rk), intent(in) :: matrix(3,3)\n\n trace = ( matrix(1,1) + matrix(2,2) + matrix(3,3) )\n end function trace\n\n pure function math_cross_product (a, b) result (res)\n real(rk), dimension(3), intent(in) :: a, b\n real(rk), dimension(3) :: res\n\n res(1) = a(2) * b(3) - a(3) * b(2)\n res(2) = a(3) * b(1) - a(1) * b(3)\n res(3) = a(1) * b(2) - a(2) * b(1)\n end function math_cross_product\n\n pure function math_euclidean_norm (a) result (a_n)\n real(rk), dimension(:), intent(in) :: a\n real(rk) :: a_n\n\n a_n = sqrt (sum (a**2))\n end function math_euclidean_norm\n\n \nend module util_mod\n\n", "meta": {"hexsha": "7959c6e4e6cc83c2f6ad011681e565d024e97e23", "size": 2148, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/util.f90", "max_stars_repo_name": "runnermt/MC-programm-for-fluid-mixtures-of-dipolar-and-charged-hard-spheres", "max_stars_repo_head_hexsha": "3dd7d1518afb0e45caf7bb729d817b1ad2697852", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-06-15T08:24:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-29T22:29:48.000Z", "max_issues_repo_path": "src/util.f90", "max_issues_repo_name": "maTheiss/MC-programm-for-fluid-mixtures-of-dipolar-and-charged-hard-spheres", "max_issues_repo_head_hexsha": "3dd7d1518afb0e45caf7bb729d817b1ad2697852", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/util.f90", "max_forks_repo_name": "maTheiss/MC-programm-for-fluid-mixtures-of-dipolar-and-charged-hard-spheres", "max_forks_repo_head_hexsha": "3dd7d1518afb0e45caf7bb729d817b1ad2697852", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.0597014925, "max_line_length": 64, "alphanum_fraction": 0.5824022346, "num_tokens": 856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075722839016, "lm_q2_score": 0.8128673223709252, "lm_q1q2_score": 0.7820658061152065}} {"text": "program q1\n use utils\n implicit none\n\n call main()\n\ncontains\n\n subroutine main()\n !! Find roots via Newton's method\n print *\n print \"(a)\", \"1. Roots of cos x - x/5 = 0\"\n print \"(f18.12)\", newton(f1, df1, x0=-4.0, tol=1e-13)\n print \"(f18.12)\", newton(f1, df1, x0=-2.0, tol=1e-13)\n print \"(f18.12)\", newton(f1, df1, x0= 1.0, tol=1e-13)\n print *\n end subroutine\n\n pure function f1(x)\n !! Function for question 1\n real, intent(in) :: x\n real :: f1\n\n f1 = cos(x) - x/5\n end function\n\n pure function df1(x)\n !! Derivative of function for question 1\n real, intent(in) :: x\n real :: df1\n\n df1 = -sin(x) - 1.0 / 5.0\n end function\n\nend program q1\n", "meta": {"hexsha": "f3b0b16442d5b693100393b6d547d98ad04eb2af", "size": 691, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/phys395_final/q1.f90", "max_stars_repo_name": "YodaEmbedding/experiments", "max_stars_repo_head_hexsha": "567c6a1c18fac2d951fe2af54aaa4917b7d529d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/phys395_final/q1.f90", "max_issues_repo_name": "YodaEmbedding/experiments", "max_issues_repo_head_hexsha": "567c6a1c18fac2d951fe2af54aaa4917b7d529d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/phys395_final/q1.f90", "max_forks_repo_name": "YodaEmbedding/experiments", "max_forks_repo_head_hexsha": "567c6a1c18fac2d951fe2af54aaa4917b7d529d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.1944444444, "max_line_length": 57, "alphanum_fraction": 0.5774240232, "num_tokens": 259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035752930664, "lm_q2_score": 0.90192067455231, "lm_q1q2_score": 0.7819974711441945}} {"text": "! HOW TO COMPILE THROUGH COMMAND LINE (CMD OR TERMINAL)\n! gfortran -c SecondBackwardDif.f95\n! gfortran -o SecondBackwardDif SecondBackwardDif.o\n!\n! The program is open source and can use be to numerical study purpose.\n! The program was written by Aulia Khalqillah,S.Si\n!\n! email: auliakhalqillah.mail@gmail.com\n! ==============================================================================\nPROGRAM CenterDifference\n IMPLICIT NONE\n\n REAL :: A,B,H,X,RAWF,F\n REAL,DIMENSION(1000) :: RAWFS,FA,FX,XS,RES\n\n INTEGER :: I,N\n CHARACTER(len=100) :: FMT\n\n WRITE(*,*)\"\"\n WRITE(*,*)\"---------------------------------------------\"\n WRITE(*,*)\"BACKWARD DIFFERENCE METHOD - SECOND DERIVATIVE\"\n WRITE(*,*)\"---------------------------------------------\"\n WRITE(*,*) \"\"\n WRITE(*,\"(a)\",advance=\"no\") \"INSERT INITIAL BOUNDARY:\"\n READ *, A\n WRITE(*,\"(a)\",advance=\"no\") \"INSERT FINAL BOUNDARY:\"\n READ *, B\n WRITE(*,\"(a)\",advance=\"no\") \"INSERT DATA LENGTH:\"\n READ *, N\n\n FMT = \"(a12,a13,a20,a20,a15,a13)\"\n WRITE(*,*) \"\"\n WRITE(*,FMT)\"ITER\",\"Data(X)\",\"Raw F(X)\",\"Difference F(X)\",\"Analytic F(X)\",\"RESIDUAL\"\n OPEN(10, FILE ='SecondBdiffOut.txt', STATUS='replace')\n\n ! Residual between two point is calculated\n H = (B-A)/N\n X = A\n I = 1\n DO WHILE (I .le. N)\n RAWF = F(X)\n RAWFS(I) = RAWF ! Save the value\n FX(I) = ((F(X)-(2*F(X-H))+F(X-(2*H)))/(H**2)) ! Second Backward Difference is calculated\n XS(I) = X ! Save the value\n FA(I) = 6*XS(I) ! Analytic Calculation of Second Difference\n RES(I) = abs(real(FX(I))-real(FA(I))) ! Residual Calculation\n WRITE(*,*) I,XS(I),RAWFS(I),FX(I),FA(I),RES(I)\n WRITE(10,*) I,XS(I),RAWFS(I),FX(I),FA(I),RES(I)\n X = X + H\n I = I + 1\n END DO\nEND PROGRAM\n\nREAL FUNCTION F(X)\n IMPLICIT NONE\n REAL :: X\n F = X**3\nEND FUNCTION\n", "meta": {"hexsha": "ba7347a6e9cbce23d65b6b41ce314f136cb0054e", "size": 1789, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "SecondBackwardDif.f95", "max_stars_repo_name": "auliakhalqillah/Second-Derivative-Method", "max_stars_repo_head_hexsha": "757541e5bc96a34abb29ddf7850ef2e4560fe1d7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SecondBackwardDif.f95", "max_issues_repo_name": "auliakhalqillah/Second-Derivative-Method", "max_issues_repo_head_hexsha": "757541e5bc96a34abb29ddf7850ef2e4560fe1d7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SecondBackwardDif.f95", "max_forks_repo_name": "auliakhalqillah/Second-Derivative-Method", "max_forks_repo_head_hexsha": "757541e5bc96a34abb29ddf7850ef2e4560fe1d7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.3220338983, "max_line_length": 92, "alphanum_fraction": 0.5589714925, "num_tokens": 576, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.8670357529306639, "lm_q1q2_score": 0.7819974705727514}} {"text": "c****************************************************************\n\n\tsubroutine matmat(r_a,r_b,r_c)\n\nc****************************************************************\nc**\nc**\tFILE NAME: matmat.for\nc**\nc** DATE WRITTEN: 8/3/90\nc**\nc** PROGRAMMER:Scott Hensley\nc**\nc** \tFUNCTIONAL DESCRIPTION: The subroutine takes two 3x3 matrices\nc** and multiplies them to return another 3x3 matrix.\nc**\nc** ROUTINES CALLED:none\nc** \nc** NOTES: none\nc**\nc** UPDATE LOG:\nc**\nc*****************************************************************\n\n \timplicit none\n\nc\tINPUT VARIABLES:\n \treal*8 r_a(3,3),r_b(3,3) !3x3 matrix\n \nc \tOUTPUT VARIABLES:\n real*8 r_c(3,3) !3x3 matrix\n\nc\tLOCAL VARIABLES:\n\tinteger i \n\nc \tPROCESSING STEPS:\n\nc compute matrix product\n\n do i=1,3\n \t r_c(i,1) = r_a(i,1)*r_b(1,1) + r_a(i,2)*r_b(2,1) + \n + r_a(i,3)*r_b(3,1)\n\t r_c(i,2) = r_a(i,1)*r_b(1,2) + r_a(i,2)*r_b(2,2) + \n + r_a(i,3)*r_b(3,2)\n\t r_c(i,3) = r_a(i,1)*r_b(1,3) + r_a(i,2)*r_b(2,3) + \n + r_a(i,3)*r_b(3,3)\n enddo \n \n end \n", "meta": {"hexsha": "228deae184f2fac05b66f1279365d2c60b46cbb0", "size": 1170, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/alos2proc_f/src/matmat.f", "max_stars_repo_name": "vincentschut/isce2", "max_stars_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_stars_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_stars_count": 1133, "max_stars_repo_stars_event_min_datetime": "2022-01-07T21:24:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T21:33:08.000Z", "max_issues_repo_path": "contrib/alos2proc_f/src/matmat.f", "max_issues_repo_name": "vincentschut/isce2", "max_issues_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_issues_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_issues_count": 276, "max_issues_repo_issues_event_min_datetime": "2019-02-10T07:18:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:45:55.000Z", "max_forks_repo_path": "contrib/alos2proc_f/src/matmat.f", "max_forks_repo_name": "vincentschut/isce2", "max_forks_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_forks_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_forks_count": 235, "max_forks_repo_forks_event_min_datetime": "2019-02-10T05:00:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T07:37:24.000Z", "avg_line_length": 23.8775510204, "max_line_length": 66, "alphanum_fraction": 0.4205128205, "num_tokens": 387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9648551576415562, "lm_q2_score": 0.8104789086703224, "lm_q1q2_score": 0.7819947551902603}} {"text": " REAL FUNCTION slBEAR (A1, B1, A2, B2)\n*+\n* - - - - -\n* B E A R\n* - - - - -\n*\n* Bearing (position angle) of one point on a sphere relative to another\n* (single precision)\n*\n* Given:\n* A1,B1 r spherical coordinates of one point\n* A2,B2 r spherical coordinates of the other point\n*\n* (The spherical coordinates are RA,Dec, Long,Lat etc, in radians.)\n*\n* The result is the bearing (position angle), in radians, of point\n* A2,B2 as seen from point A1,B1. It is in the range +/- pi. If\n* A2,B2 is due east of A1,B1 the bearing is +pi/2. Zero is returned\n* if the two points are coincident.\n*\n* P.T.Wallace Starlink 23 March 1991\n*\n* Copyright (C) 1995 Rutherford Appleton Laboratory\n*\n* License:\n* This program is free software; you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation; either version 2 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program (see SLA_CONDITIONS); if not, write to the\n* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n* Boston, MA 02110-1301 USA\n*\n* Copyright (C) 1995 Association of Universities for Research in Astronomy Inc.\n*-\n\n IMPLICIT NONE\n\n REAL A1,B1,A2,B2\n\n REAL DA,X,Y\n\n\n DA=A2-A1\n Y=SIN(DA)*COS(B2)\n X=SIN(B2)*COS(B1)-COS(B2)*SIN(B1)*COS(DA)\n IF (X.NE.0.0.OR.Y.NE.0.0) THEN\n slBEAR=ATAN2(Y,X)\n ELSE\n slBEAR=0.0\n END IF\n\n END\n", "meta": {"hexsha": "e023d533a5d419938af6a1961e53c85b3e83b9f5", "size": 1869, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/slalib/bear.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/slalib/bear.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/slalib/bear.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.6393442623, "max_line_length": 80, "alphanum_fraction": 0.6548956661, "num_tokens": 565, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475746920262, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7819774124048373}} {"text": "SUBROUTINE PREENV( X, N )\r\n\r\n ! Forms the pre-envelope of the function\r\n ! Real( X( N ) ) is the input time series\r\n ! The output vector is complex\r\n ! N must be a power of 2 and <16384\r\n\r\n COMPLEX X( N )\r\n\r\n ! Check N is postive and a power of 2\r\n\r\n IF ( N <= 0 ) STOP 'FATAL ERROR in PREENV: N must be positive'\r\n\r\n NT = 2**( INT( LOG10( REAL( N ) ) / 0.30104 ) + 1 )\r\n IF ( NT /= N ) STOP 'FATAL ERROR in PREENV: N must be a power of 2'\r\n\r\n CALL CFFT( X, N, 1 ) ! forward Fourier transform\r\n X = X / N ! scaled appropriately\r\n\r\n IMID = N / 2\r\n X( IMID+1 : N ) = 0.0 ! Zero-out the negative spectrum (the upper N/2 positions)\r\n\r\n CALL CFFT( X, N, -1 ) ! inverse Fourier transform\r\n\r\nEND SUBROUTINE PREENV\r\n", "meta": {"hexsha": "39b8904fbfba2de24a9848580df65187e5467eb4", "size": 759, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "at_2020_11_4/tslib/preenv.f90", "max_stars_repo_name": "IvanaEscobar/sandbox", "max_stars_repo_head_hexsha": "71d62af2c112686c5ce26def35593247cf6a0ccc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "at_2020_11_4/tslib/preenv.f90", "max_issues_repo_name": "IvanaEscobar/sandbox", "max_issues_repo_head_hexsha": "71d62af2c112686c5ce26def35593247cf6a0ccc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2022-02-15T23:32:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T21:35:12.000Z", "max_forks_repo_path": "AcousticToolbox/tslib/preenv.f90", "max_forks_repo_name": "sarapierson234/SMALLBETS", "max_forks_repo_head_hexsha": "f78add47dada5848b4a44053011bc52bf4edbf2d", "max_forks_repo_licenses": ["Naumen", "Condor-1.1", "MS-PL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.1923076923, "max_line_length": 86, "alphanum_fraction": 0.5744400527, "num_tokens": 252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542887603538, "lm_q2_score": 0.8152324983301568, "lm_q1q2_score": 0.7819337471101878}} {"text": "! -----------\n! Vertical motion under gravity\n! -----------------------------\nprogram Vertical\n implicit none\n real :: g ! acceleration due to gravity\n real :: s ! displacement\n real :: t ! time\n real :: u ! initial speed (m / s)\n\n ! set values of variable\n g = 9.8\n t = 6.0\n u = 60.0\n\n ! calculate displacement\n s = u*t - g*(t**2) / 2.0\n\n ! output results\n write(*, \"('[F90] Time = ', f5.2, ', Displacement = ', f5.1)\") t, s\n \nend program Vertical\n", "meta": {"hexsha": "d72c2cdabe994606bc488fb343e9605cd67871ee", "size": 500, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/vertical.f90", "max_stars_repo_name": "apetcho/scicomp", "max_stars_repo_head_hexsha": "a9deece58df59ae88498697d8df07ac4296f4760", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/vertical.f90", "max_issues_repo_name": "apetcho/scicomp", "max_issues_repo_head_hexsha": "a9deece58df59ae88498697d8df07ac4296f4760", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/vertical.f90", "max_forks_repo_name": "apetcho/scicomp", "max_forks_repo_head_hexsha": "a9deece58df59ae88498697d8df07ac4296f4760", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.7391304348, "max_line_length": 72, "alphanum_fraction": 0.496, "num_tokens": 154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308091776496, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7818602782657161}} {"text": " MODULE funcs\n\t \t\timplicit none\n\t CONTAINS\t\t\t\n\t\t\tFUNCTION func(x, y, z)\n\t\t\tREAL func, x, y, z\n\t\t\tfunc = 1\n\t\t\tRETURN\n\t\t\tEND FUNCTION func\n\t\t\t\n\t\t\tFUNCTION y1(x)\n\t\t\tREAL y1, x\n\t\t\ty1 = -sqrt(4-x**2)\n\t\t\tRETURN\n\t\t\tEND FUNCTION y1\n\t\t\t\n\t\t\tFUNCTION y2(x)\n\t\t\tREAL y2, x\n\t\t\ty2 = sqrt(4-x**2)\n\t\t\tRETURN\n\t\t\tEND FUNCTION y2\n\t\t\t\n\t\t\tFUNCTION z1(x, y)\n\t\t\tREAL z1, x, y\n\t\t\tz1 = -sqrt(4-x**2-y**2)\n\t\t\tRETURN\n\t\t\tEND FUNCTION z1\n\t\t\t\n\t\t\tFUNCTION z2(x, y)\n\t\t\tREAL z2, x, y\n\t\t\tz2 = sqrt(4-x**2-y**2)\n\t\t\tRETURN\n\t\t\tEND FUNCTION z2\n\t END MODULE funcs\n\t \n\t MODULE integration\n\t \t\tUSE funcs\n\t\t\tCONTAINS\n\t\t\t SUBROUTINE qgaus(func,a,b,ss)\n\t\t\t\t REAL a,b,ss,func\n\t\t\t\t EXTERNAL func\n\t\t\t\t INTEGER j\n\t\t\t\t REAL dx,xm,xr\n\t\t\t\t real, dimension(5) :: w\n\t\t\t\t real, dimension(5) :: x\n\t\t\t\t w(1) = 0.2955242247\n\t\t\t\t w(2) = 0.2692667193\n\t\t\t\t w(3) = 0.2190863625\n\t\t\t\t w(4) = 0.1494513491\n\t\t\t\t w(5) = 0.0666713443\n\t\t\t\t \n\t\t\t\t x(1) = 0.1488743389\n\t\t\t\t x(2) = 0.4333953941\n\t\t\t\t x(3) = 0.6794095682\n\t\t\t\t x(4) = 0.8650633666\n\t\t\t\t x(5) = 0.9739065285\n\t\t\t\t \n\t\t\t\t xm=0.5*(b+a)\n\t\t\t\t xr=0.5*(b-a)\n\t\t\t\t ss=0\n\t\t\t\t do j=1,5\n\t\t\t\t dx=xr*x(j)\n\t\t\t\t ss=ss+w(j)*(func(xm+dx)+func(xm-dx))\n\t\t\t\t end do\n\t\t\t\t ss=xr*ss\n\t\t\t\t return\n\t\t\t END SUBROUTINE qgaus\n\t\t\t \n\t\t\t SUBROUTINE tripleD(x1, x2, ss)\n\t\t\t REAL x1, x2, ss\n\t\t\t call qgaus(h, x1, x2, ss)\n\t\t\t return\n\t\t\t END SUBROUTINE tripleD\n\t\t\t \n\t\t\t FUNCTION f(zz)\n\t\t\t REAL f, zz, x, y, z\n\t\t\t COMMON /xyz/ x,y,z\n\t\t\t z = zz\n\t\t\t f = func(x,y,z)\n\t\t\t return\n\t\t\t END FUNCTION f\n\t\t\t \n\t\t\t FUNCTION g(yy)\n\t\t\t REAL g,yy,x,y,z\n\t\t\t COMMON /xyz/ x,y,z\n\t\t\t REAL ss\n\t\t\t y=yy\n\t\t\t call qgaus(f,z1(x,y),z2(x,y),ss)\n\t\t\t g=ss\n\t\t\t return\n\t\t\t END FUNCTION g\n\t\t\t \n\t\t\t FUNCTION h(xx)\n\t\t\t REAL h,xx,x,y,z\n\t\t\t COMMON /xyz/ x,y,z\n\t\t\t REAL ss\n\t\t\t x=xx\n\t\t\t call qgaus(g,y1(x),y2(x),ss)\n\t\t\t h=ss\n\t\t\t return\n\t\t\t END FUNCTION h\n\t END MODULE integration\n\t \n\t PROGRAM CalIntegrator\n\t \t USE funcs\n\t\t USE integration\n\t\t implicit none\n\t\t REAL x1, x2, s, pi, ro\n\t\t INTEGER n\n\t\t pi = 3.141592654\n\t\t x1 = -2\n\t\t x2 = 2\n\t\t ro = 0.05\n\t\t call tripleD(x1, x2, s)\n\t\t WRITE (*,*) s*ro\n\t END PROGRAM CalIntegrator", "meta": {"hexsha": "84f32530be8f1772b5ab2aaa5602b770c7f30ac8", "size": 2064, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Raw-Src/3D-Integration-final-ver2.0.f", "max_stars_repo_name": "tqbdev/Calculate-Integration-in-Fortran", "max_stars_repo_head_hexsha": "7bce95598a4cbd719e9f66c58622a3a24cfaa126", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Raw-Src/3D-Integration-final-ver2.0.f", "max_issues_repo_name": "tqbdev/Calculate-Integration-in-Fortran", "max_issues_repo_head_hexsha": "7bce95598a4cbd719e9f66c58622a3a24cfaa126", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Raw-Src/3D-Integration-final-ver2.0.f", "max_forks_repo_name": "tqbdev/Calculate-Integration-in-Fortran", "max_forks_repo_head_hexsha": "7bce95598a4cbd719e9f66c58622a3a24cfaa126", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.947826087, "max_line_length": 41, "alphanum_fraction": 0.5310077519, "num_tokens": 842, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418283357703, "lm_q2_score": 0.8459424373085145, "lm_q1q2_score": 0.7817707906811083}} {"text": "module gcd_module\n implicit none\n\n contains\n integer function gcd(a, b)\n implicit none\n\n integer, intent(in) :: a, b\n integer :: temp\n\n if (a output.txt\n! $ gnuplot -c plot.plt -p\n!\n!-------------------------------------------------------------------------------\n!\n! Functions:\n!\n! u(t) >= 0 - Population size of prey at time t.\n! v(t) >= 0 - Population size of predator at time t.\n!\n! Equations:\n!\n! d/dt u = u * (alpha - beta * v)\n! d/dt v = -v * (gamma - delta * u)\n!\n! Model Parameters:\n!\n! u - Prey population.\n! v - Predator population.\n! alpha - Reproduction rate of prey.\n! beta - Death rate of prey by predator.\n! gamma - Death rate of predator.\n! delta - Reproduction rate of predator by prey.\n!\n!-------------------------------------------------------------------------------\nprogram main\n use, intrinsic :: iso_fortran_env, only: wp => real64\n implicit none\n real(kind=wp), parameter :: t_max = 30_wp\n real(kind=wp), parameter :: h = 0.001_wp\n integer, parameter :: n = t_max / h\n integer :: i\n real(kind=wp) :: t(n) = [ (h * i, i = 1, n) ]\n real(kind=wp) :: r(2)\n real(kind=wp) :: x(n), y(n)\n\n r = [ 20.0_wp, & ! Initial prey population.\n 5.0_wp ] ! Initial predator population.\n\n do i = 1, n\n x(i) = r(1)\n y(i) = r(2)\n\n r = r + rk4(r, t(i), h)\n\n print '(f15.8, 2(\" \", f15.8))', t(i), x(i), y(i)\n end do\ncontains\n function rk4(r, t, h)\n !! Runge-Kutta 4th order solver.\n real(kind=wp), intent(in) :: r(2) ! Initial values.\n real(kind=wp), intent(in) :: t ! Step.\n real(kind=wp), intent(in) :: h ! Step size.\n real(kind=wp) :: rk4(2)\n real(kind=wp) :: k1(2), k2(2), k3(2), k4(2)\n\n k1 = h * f(r, t)\n k2 = h * f(r + 0.5 * k1, t + 0.5 * h)\n k3 = h * f(r + 0.5 * k2, t + 0.5 * h)\n k4 = h * f(r + k3, t + h)\n\n rk4 = (k1 + (2 * k2) + (2 * k3) + k4) / 6\n end function rk4\n\n function f(r, t)\n !! Lotka-Volterra ODE.\n !!\n !! Point estimates for model parameters taken from:\n !! https://www.math.tamu.edu/~phoward/m442/modbasics.pdf\n real(kind=wp), parameter :: alpha = 0.47_wp\n real(kind=wp), parameter :: beta = 0.024_wp\n real(kind=wp), parameter :: delta = 0.023_wp\n real(kind=wp), parameter :: gamma = 0.76_wp\n real(kind=wp), intent(in) :: r(2)\n real(kind=wp), intent(in) :: t\n real(kind=wp) :: f(2)\n real(kind=wp) :: u, v\n\n u = r(1)\n v = r(2)\n\n f(1) = u * (alpha - beta * v)\n f(2) = -v * (gamma - delta * u)\n end function f\nend program main\n", "meta": {"hexsha": "1b4265aa2e6c0db841eaf3c78ec43222ce5095ff", "size": 2935, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sources/lotka.f90", "max_stars_repo_name": "kantel/learningfortran", "max_stars_repo_head_hexsha": "aa5dc845f21d5d38a6d197b4fa93df2bf7f774fa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sources/lotka.f90", "max_issues_repo_name": "kantel/learningfortran", "max_issues_repo_head_hexsha": "aa5dc845f21d5d38a6d197b4fa93df2bf7f774fa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sources/lotka.f90", "max_forks_repo_name": "kantel/learningfortran", "max_forks_repo_head_hexsha": "aa5dc845f21d5d38a6d197b4fa93df2bf7f774fa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.2527472527, "max_line_length": 80, "alphanum_fraction": 0.4350936968, "num_tokens": 919, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939516, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.7817031851097784}} {"text": "SUBROUTINE force_gm (GM, r, fx,fy,fz )\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: force_gm.f90\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Acceleration due to the central Earth Gravity Field\r\n! Computation of satellite's acceleration based on Newton's law of gravity\r\n! considering Earth as a point mass\r\n! ----------------------------------------------------------------------\r\n! Input arguments:\r\n! - r:\t\t\t\tposition vector (m)\r\n! \r\n! Output arguments:\r\n! - fx,fy,fz:\t\tAcceleration's cartesian components (m)\r\n! ----------------------------------------------------------------------\r\n! Author :\tDr. Thomas Papanikolaou, Cooperative Research Centre for Spatial Information, Australia\r\n! Created:\tJuly 2015\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n USE mdl_precision\r\n IMPLICIT NONE\r\n\r\n! ----------------------------------------------------------------------\r\n! Dummy arguments declaration\r\n! ----------------------------------------------------------------------\r\n! IN\r\n REAL (KIND = prec_q), INTENT(IN), DIMENSION(3) :: r\r\n REAL (KIND = prec_q), INTENT(IN) :: GM\t\r\n! OUT\r\n REAL (KIND = prec_q), INTENT(OUT) :: fx,fy,fz\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Local variables declaration\r\n! ----------------------------------------------------------------------\r\n REAL (KIND = prec_q) :: phi, lamda, radius\r\n REAL (KIND = prec_q) :: fr\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Numerical Constants\r\n! GM = GM_global \r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! computation of spherical coordinates\r\n CALL coord_r2sph (r , phi,lamda,radius)\r\n\r\n! Gradient of geopotential V\r\n fr = - GM / (radius ** 2) \r\n\r\n! Cartesian counterparts (fx,fy,fz) of acceleration fr\r\n fx = fr * cos(phi) * cos(lamda)\r\n fy = fr * cos(phi) * sin(lamda)\r\n fz = fr * sin(phi)\t \r\n\t \r\nEND\r\n", "meta": {"hexsha": "8075a30cae0166542659553a80acec0c3175a798", "size": 2223, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/force_gm.f90", "max_stars_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_stars_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2021-07-08T23:35:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:17:58.000Z", "max_issues_repo_path": "src/fortran/force_gm.f90", "max_issues_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_issues_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-09-27T14:27:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T23:50:02.000Z", "max_forks_repo_path": "src/fortran/force_gm.f90", "max_forks_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_forks_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2021-07-12T05:42:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T15:15:34.000Z", "avg_line_length": 36.4426229508, "max_line_length": 99, "alphanum_fraction": 0.3594242015, "num_tokens": 413, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338057771058, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7815994122506466}} {"text": "SUBROUTINE pearsn(x,y,n,r,prob,z)\r\nINTEGER n\r\nREAL*8 prob,r,z,x(n),y(n),TINY\r\nPARAMETER (TINY=1.e-20)\r\n!CU USES betai\r\nINTEGER j\r\nREAL*8 ax,ay,df,sxx,sxy,syy,t,xt,yt,betai\r\nax=0.\r\nay=0.\r\ndo j=1,n\r\n ax=ax+x(j)\r\n ay=ay+y(j)\r\nenddo\r\nax=ax/n\r\nay=ay/n\r\nsxx=0.\r\nsyy=0.\r\nsxy=0.\r\ndo j=1,n\r\n xt=x(j)-ax\r\n yt=y(j)-ay\r\n sxx=sxx+xt**2\r\n syy=syy+yt**2\r\n sxy=sxy+xt*yt\r\nenddo\r\nr=sxy/(sqrt(sxx*syy)+TINY)\r\nz=0.5*log(((1.+r)+TINY)/((1.-r)+TINY))\r\ndf=n-2\r\nt=r*sqrt(df/(((1.-r)+TINY)*((1.+r)+TINY)))\r\nprob=betai(0.5*df,0.5,df/(df+t**2))\r\n!C prob=erfcc(abs(z*sqrt(n-1.))/1.4142136)\r\nreturn\r\nEND\r\n", "meta": {"hexsha": "f8c7b6952db1b2dc718fd23d7536034e3a919d7a", "size": 591, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "p/pearsn.f90", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "p/pearsn.f90", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "p/pearsn.f90", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.3823529412, "max_line_length": 47, "alphanum_fraction": 0.5685279188, "num_tokens": 294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750440288019, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.7815838600871244}} {"text": "function funcre(param,npara,ifuge,timev)\n!------------------------------------------------------------------------\n!\n! This function yields a parabolic or periodic evolution\n!\n!------------------------------------------------------------------------\n use typre\n use def_parame\n implicit none\n real(rp) :: funcre\n integer(ip), intent(in) :: npara,ifuge\n real(rp), intent(in) :: param(npara),timev\n integer(ip) :: ipara\n real(rp) :: timea,timeb,funca,funcb,zerom,timec\n real(rp) :: timei,timef,Tgp,T0,Tp,Tn\n \n funcre=0.0_rp\n zerom=epsilon(1.0_rp)\n\n if(ifuge==0) then\n!\n! No time dependence \n!\n funcre=1.0_rp\n\n else if(ifuge==1) then\n!\n! Parabolic evolution\n!\n if(param(1)-zerom<=timev.and.timev<=param(2)+zerom) then \n funcre=param(3)*timev*timev+param(4)*timev+param(5)\n else if (timev>param(2)+zerom) then\n timea=param(2)\n funcre=param(3)*timea*timea+param(4)*timea+param(5)\n else if (timevparam(2)+zerom) then\n timea=param(2)\n funcre=param(3)*sin(param(4)*timea+param(5))+param(6)\n else if (timev=timef) then ! Look for the time inside the period\n timec=timev\n do while(timec>timef)\n timec=timec-(timef-timei)\n end do\n else\n timec=timev\n end if\n ipara=0\n do while(iparaparam(2)+zerom) then\n funcre=param(6)\n else if (timevparam(2)+zerom) then\n timea = param(2)\n else if (timev180 deg\n\n\nUSE PARAM_MOD, ONLY: PI,Earth_Radius,SphericalProjection,lonmin,latmin\nIMPLICIT NONE\nPRIVATE\nSAVE\n\n\n !Return x location given longitude\n INTERFACE lon2x\n MODULE PROCEDURE rlon2x !real input\n MODULE PROCEDURE dlon2x !double precision input\n END INTERFACE lon2x\n\n\n !Return y location given latitude\n INTERFACE lat2y\n MODULE PROCEDURE rlat2y !real input\n MODULE PROCEDURE dlat2y !double precision input\n END INTERFACE lat2y\n\n\n !Return longitude given x location\n INTERFACE x2lon\n MODULE PROCEDURE rx2lon !real input\n MODULE PROCEDURE dx2lon !double precision input\n END INTERFACE x2lon\n\n\n !Return latitude given y location\n INTERFACE y2lat\n MODULE PROCEDURE ry2lat !real input\n MODULE PROCEDURE dy2lat !double precision input\n END INTERFACE y2lat\n\n !The following procedures have been made public for the use of other modules:\n PUBLIC :: lon2x,lat2y,x2lon,y2lat\n\nCONTAINS\n\n DOUBLE PRECISION FUNCTION rlon2x(lon,lat)\n IMPLICIT NONE\n REAL, INTENT(IN) :: lon\n REAL, INTENT(IN), OPTIONAL :: lat\n DOUBLE PRECISION :: RCF ! Radian conversion factor\n DOUBLE PRECISION :: c,ax,ay,az,bx,by,bz,alon,alat,blon,blat,x180,xtralon\n\n RCF = DBLE(180.0) / PI\n\n if(SphericalProjection)then\n if( present(lat) )then\n\n if((lon-lonmin) .gt. 180.0)then\n alon = 180.0\n alat = lat\n blon = 0\n blat = lat\n\n alon = alon / RCF\n alat = alat / RCF\n blon = blon / RCF\n blat = blat / RCF\n\n c = cos(alat)\n ax = c * cos(alon)\n ay = c * sin(alon)\n az = sin(alat)\n\n c = cos(blat)\n bx = c * cos(blon)\n by = c * sin(blon)\n bz = sin(blat)\n\n x180 = acos(ax*bx + ay*by + az*bz) * Earth_Radius\n\n alon = lon\n blon = lonmin+180.0\n\n alon = alon / RCF\n blon = blon / RCF\n\n ax = c * cos(alon)\n ay = c * sin(alon)\n bx = c * cos(blon)\n by = c * sin(blon)\n\n xtralon = acos(ax*bx + ay*by + az*bz) * Earth_Radius\n rlon2x = x180 + xtralon\n else\n alon = lon\n alat = lat\n blon = lonmin\n blat = lat\n\n alon = alon / RCF\n alat = alat / RCF\n blon = blon / RCF\n blat = blat / RCF\n\n c = cos(alat)\n ax = c * cos(alon)\n ay = c * sin(alon)\n az = sin(alat)\n\n c = cos(blat)\n bx = c * cos(blon)\n by = c * sin(blon)\n bz = sin(blat)\n\n rlon2x = acos(ax*bx + ay*by + az*bz) * Earth_Radius\n endif\n else\n write(*,*) \"Problem lon2x: spherical projection without lat value\"\n endif\n else\n rlon2x = lon / RCF * Earth_Radius\n endif\n\n END FUNCTION rlon2x\n\n\n DOUBLE PRECISION FUNCTION dlon2x(lon,lat)\n IMPLICIT NONE\n DOUBLE PRECISION, INTENT(IN) :: lon\n DOUBLE PRECISION, INTENT(IN), OPTIONAL :: lat\n DOUBLE PRECISION :: RCF ! Radian conversion factor\n DOUBLE PRECISION :: c,ax,ay,az,bx,by,bz,alon,alat,blon,blat,x180,xtralon\n\n RCF = DBLE(180.0) / PI\n\n if(SphericalProjection)then\n if( present(lat) )then\n\n\tdlon2x = (lon-lonmin)/180.0 * Earth_Radius * pi * cos(lat/RCF)\n\n else\n write(*,*) \"Problem lon2x: spherical projection without lat value\"\n endif\n else\n dlon2x = lon / RCF * Earth_Radius\n endif\n\n END FUNCTION dlon2x\n\n\n DOUBLE PRECISION FUNCTION rlat2y(lat,lon)\n IMPLICIT NONE\n REAL, INTENT(IN) :: lat\n DOUBLE PRECISION, INTENT(IN), OPTIONAL :: lon\n DOUBLE PRECISION :: RCF ! Radian conversion factor\n DOUBLE PRECISION :: c,ax,ay,az,bx,by,bz,alon,alat,blon,blat\n\n RCF = DBLE(180.0) / PI\n\n if(SphericalProjection) then\n if( present(lon) )then\n alon = lon\n alat = lat\n blon = lon\n blat = latmin\n else\n\talon = lonmin\n\talat = lat\n blon = lonmin\n blat = latmin \n endif\n\n alon = alon / RCF\n alat = alat / RCF\n blon = blon / RCF\n blat = blat / RCF\n\n c = cos(alat)\n ax = c * cos(alon)\n ay = c * sin(alon)\n az = sin(alat)\n\n c = cos(blat)\n bx = c * cos(blon)\n by = c * sin(blon)\n bz = sin(blat)\n\n rlat2y = acos(ax*bx + ay*by + az*bz) * Earth_Radius\n\n else\n\n rlat2y = log( tan( pi/4.0 + lat/(RCF*2.0) ))*Earth_Radius\n\n endif\n\n END FUNCTION rlat2y\n\n\n DOUBLE PRECISION FUNCTION dlat2y(lat)\n IMPLICIT NONE\n DOUBLE PRECISION, INTENT(IN) :: lat\n DOUBLE PRECISION :: RCF ! Radian conversion factor\n DOUBLE PRECISION :: c,ax,ay,az,bx,by,bz,alon,alat,blon,blat\n\n RCF = DBLE(180.0) / PI\n\n if(SphericalProjection) then\n\n dlat2y = (lat-latmin)*Earth_Radius*pi/180.0\n\n else\n\n dlat2y = log( tan( pi/4.0 + lat/(RCF*2.0) ))*Earth_Radius\n\n endif\n\n END FUNCTION dlat2y\n\n\n DOUBLE PRECISION FUNCTION rx2lon(x,y)\n IMPLICIT NONE\n REAL, INTENT(IN) :: x\n REAL, INTENT(IN), OPTIONAL :: y\n DOUBLE PRECISION :: RCF ! Radian conversion factor\n DOUBLE PRECISION :: lat,c,ax,ay,az,bx,by,bz,alon,alat,blon,blat,x180\n\n RCF = DBLE(180.0) / PI\n\n if(SphericalProjection) then\n\n if( PRESENT(y) )then\n lat = (y * RCF / Earth_Radius + latmin) / RCF\n\n alon = 0\n alat = lat\n blon = 180.0\n blat = lat\n\n alon = alon / RCF\n blon = blon / RCF\n\n c = cos(alat)\n ax = c * cos(alon)\n ay = c * sin(alon)\n az = sin(alat)\n\n c = cos(blat)\n bx = c * cos(blon)\n by = c * sin(blon)\n bz = sin(blat)\n\n x180 = acos(ax*bx + ay*by + az*bz) * Earth_Radius\n\n if(x .gt. x180)then\n\n rx2lon = lonmin + 180.0 + RCF*acos( (cos((x180-x)/Earth_Radius) - sin(lat)*sin(lat)) &\n / (cos(lat)*cos(lat)) )\n else\n rx2lon = lonmin + RCF*acos( (cos(x/Earth_Radius) - sin(lat)*sin(lat)) &\n / (cos(lat)*cos(lat)) )\n endif\n else\n write(*,*) \"Problem x2lon: Spherical projection without y value\"\n endif\n\n else\n rx2lon = x / Earth_Radius * RCF\n endif\n\n END FUNCTION rx2lon\n\n\n DOUBLE PRECISION FUNCTION dx2lon(x,y)\n IMPLICIT NONE\n DOUBLE PRECISION, INTENT(IN) :: x\n DOUBLE PRECISION, INTENT(IN), OPTIONAL :: y\n DOUBLE PRECISION :: RCF ! Radian conversion factor\n DOUBLE PRECISION :: lat,c,ax,ay,az,bx,by,bz,alon,alat,blon,blat,x180\n\n RCF = DBLE(180.0) / PI\n\n if(SphericalProjection) then\n\n if( PRESENT(y) )then\n lat = y*180.0/(Earth_Radius*pi) + latmin\n\n\tdx2lon = x*180.0 / (Earth_Radius * pi * cos(lat/RCF)) + lonmin\n\n else\n write(*,*) \"Problem x2lon: Spherical projection without y value\"\n endif\n\n else\n dx2lon = x / Earth_Radius * RCF\n endif\n\n END FUNCTION dx2lon\n\n\n DOUBLE PRECISION FUNCTION ry2lat(y)\n IMPLICIT NONE\n REAL, INTENT(IN) :: y\n DOUBLE PRECISION :: RCF ! Radian conversion factor\n\n RCF = DBLE(180.0) / PI\n\n if(SphericalProjection) then\n ry2lat = y * RCF / Earth_Radius + latmin\n else\n ry2lat = 2.0*RCF * ( atan(exp(y/Earth_Radius)) - pi/4.0 )\n endif\n\n END FUNCTION ry2lat\n\n\n DOUBLE PRECISION FUNCTION dy2lat(y)\n IMPLICIT NONE\n DOUBLE PRECISION, INTENT(IN) :: y\n DOUBLE PRECISION :: RCF ! Radian conversion factor\n\n RCF = DBLE(180.0) / PI\n\n if(SphericalProjection) then\n\tdy2lat = y * RCF / Earth_Radius + latmin\n else\n dy2lat = 2.0*RCF * ( atan(exp(y/Earth_Radius)) - pi/4.0 )\n endif\n\n END FUNCTION dy2lat\n\nEND MODULE CONVERT_MOD\n", "meta": {"hexsha": "83d0f749cfb10d9a81e338ac0f7c0eaf77ef9155", "size": 10080, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Model6/conversion_module.f90", "max_stars_repo_name": "CaptainYin/ParLTRANS", "max_stars_repo_head_hexsha": "760734f058589ab464897dcf01f3f5528803d43b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Model6/conversion_module.f90", "max_issues_repo_name": "CaptainYin/ParLTRANS", "max_issues_repo_head_hexsha": "760734f058589ab464897dcf01f3f5528803d43b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Model6/conversion_module.f90", "max_forks_repo_name": "CaptainYin/ParLTRANS", "max_forks_repo_head_hexsha": "760734f058589ab464897dcf01f3f5528803d43b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.4566929134, "max_line_length": 96, "alphanum_fraction": 0.599702381, "num_tokens": 3127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517083920618, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7811262334157572}} {"text": "module fft_mod\n implicit none\n integer, parameter :: dp=selected_real_kind(15,300)\n real(kind=dp), parameter :: pi=3.141592653589793238460_dp\n\ncontains\n\n ! In place Cooley-Tukey FFT\nrecursive subroutine fft(x)\n complex(kind=dp), dimension(:), intent(inout) :: x\n complex(kind=dp) :: t\n integer :: N\n integer :: i\n complex(kind=dp), dimension(:), allocatable :: even, odd\n \n N=size(x)\n \n if(N .le. 1) return\n \n allocate(odd((N+1)/2))\n allocate(even(N/2))\n \n ! divide\n odd =x(1:N:2)\n even=x(2:N:2)\n \n ! conquer\n call fft(odd)\n call fft(even)\n \n ! combine\n do i=1,N/2\n \n \n t=exp(cmplx(0.0_dp,-2.0_dp*pi*real(i-1,dp)/real(N,dp),KIND=DP))*even(i)\n \n x(i) = odd(i) + t\n x(i+N/2) = odd(i) - t\n \n end do\n \n deallocate(odd)\n deallocate(even)\n \n end subroutine fft\n \nend module fft_mod\n \nprogram test\n use fft_mod\n implicit none\n complex(kind=dp), dimension(8) :: data = (/1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0/)\n real(kind=dp) :: mag, phase\n integer :: i\n \n call fft(data)\n \n do i=1,8\n write(*,'(\"(\", F20.15, \",\", F20.15, \"i )\")') data(i)\n mag = sqrt(real(data(i))**2 + aimag(data(i))**2)\n \n if (real(data(i)) .ne. 0.0) then\n phase = (atan(aimag(data(i))/real(data(i))))*(180.0_dp/pi)\n else \n phase = 0\n end if\n \n write (*,*) 'The magnitude is ->', mag, 'amps.'\n write (*,*) 'The phase is ->', phase, 'degrees.'\n print *\n end do\n \nend program test\n", "meta": {"hexsha": "f7fc92b4f1dd87aed694d7ef328dc3d0608fa4e3", "size": 1788, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "html/backups/code/FFT_test_code.f95", "max_stars_repo_name": "markkhusid/MKDynamics_website", "max_stars_repo_head_hexsha": "e9e5e9b2507588b29a252313cb159dd8e9129bd5", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "html/backups/code/FFT_test_code.f95", "max_issues_repo_name": "markkhusid/MKDynamics_website", "max_issues_repo_head_hexsha": "e9e5e9b2507588b29a252313cb159dd8e9129bd5", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "html/backups/code/FFT_test_code.f95", "max_forks_repo_name": "markkhusid/MKDynamics_website", "max_forks_repo_head_hexsha": "e9e5e9b2507588b29a252313cb159dd8e9129bd5", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.1621621622, "max_line_length": 106, "alphanum_fraction": 0.4574944072, "num_tokens": 543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9664104982195784, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7809246406778935}} {"text": "! Fortran 2008 Print Fibonacci\n! This program prints a user specified number of numbers from the\n! fibonacci sequence, starting at 0. Uses iteration to determine\n! the fibonacci numbers\n\nprogram print_fibos\n\timplicit none\n\t! Use 128-bit integers\n\tinteger(16) :: x, k, n\n\tinteger(16) :: fibo0 = 0\n\tinteger(16) :: fibo1 = 1\n\n\t! Get input from user\n\twrite (*, '(A$)') \"How many fibonacci numbers should be printed? \"\n\tread *, k\n\n\tif (k == 1) then\n\t\tprint *, fibo0\n\telse if (k == 2) then\n\t\tprint *, fibo0\n\t\tprint *, fibo1\n \telse\n\t\tprint *, fibo0\n\t\tprint *, fibo1\n\t\tdo n=3, k, 1\n\t\t\tx = fibo1 + fibo0\n\t\t\tfibo0 = fibo1\n\t\t\tfibo1 = x\n\t\t\tprint *, fibo1\n\t\tenddo\n\tend if\nend", "meta": {"hexsha": "e8417f18e8ed2fd9b30edfe85880201d642f7f30", "size": 670, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "fibo.f08", "max_stars_repo_name": "Arsh25/CS331_Fortran08", "max_stars_repo_head_hexsha": "ba0f8afc8c219ac476cdd63ec4e0812811fb40e7", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fibo.f08", "max_issues_repo_name": "Arsh25/CS331_Fortran08", "max_issues_repo_head_hexsha": "ba0f8afc8c219ac476cdd63ec4e0812811fb40e7", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fibo.f08", "max_forks_repo_name": "Arsh25/CS331_Fortran08", "max_forks_repo_head_hexsha": "ba0f8afc8c219ac476cdd63ec4e0812811fb40e7", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.9375, "max_line_length": 68, "alphanum_fraction": 0.6462686567, "num_tokens": 238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693716759489, "lm_q2_score": 0.8221891283434877, "lm_q1q2_score": 0.780807832912756}} {"text": "Program q1106 !Trapezoidal method for definite integral\r\nimplicit none\r\n integer n, i\r\n real S, dx, a, b\r\n real ubound, lbound\r\n real, external ::trapezoid, f\r\n\r\n read(*,*)a, b, n\r\n dx = (b-a)/n\r\n S = 0\r\n do i = 1, n\r\n ubound = f((a+(i-1))*dx)\r\n\t lbound = f(b-(n-i)*dx)\r\n\t S = S + trapezoid(ubound,lbound,dx)\r\n end do\r\n write(*,\"(F0.2)\")S\r\nend program q1106\r\n\r\nreal function trapezoid(ubound,lbound,dx)\r\nimplicit none\r\n real,intent(in)::ubound,lbound,dx\r\n trapezoid = (ubound+lbound)*dx/2.\r\n return\r\nend function trapezoid\r\n\r\nreal function f(x)\r\nimplicit none\r\n real,intent(in) :: x\r\n\t f=x**2\r\n return\r\nend function f\r\n", "meta": {"hexsha": "87076510310dc0c710e10536bb137e1bc36b4493", "size": 691, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "GitHub_FortranHomework/1106.f90", "max_stars_repo_name": "MikasaMumei/Freshman_year", "max_stars_repo_head_hexsha": "c7b94d7726b170119fca40c6f87ebf79433444de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-12-02T13:32:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-02T13:32:17.000Z", "max_issues_repo_path": "GitHub_FortranHomework/1106.f90", "max_issues_repo_name": "MikasaMumei/Freshman_year", "max_issues_repo_head_hexsha": "c7b94d7726b170119fca40c6f87ebf79433444de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "GitHub_FortranHomework/1106.f90", "max_forks_repo_name": "MikasaMumei/Freshman_year", "max_forks_repo_head_hexsha": "c7b94d7726b170119fca40c6f87ebf79433444de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.59375, "max_line_length": 58, "alphanum_fraction": 0.5730824891, "num_tokens": 240, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693674025232, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.7808078273303725}} {"text": "! =================================================\n! Jocobi iteration (point) method to solve linear \n! equation system 'Ax = b'.\n! =================================================\n\nsubroutine iter_ja_p(A, b, x, iter_cr, iter_max)\n\n use coordinates, only: Nx, Ny\n use log_config, only: log_conv_show\n implicit none\n\n integer*4, parameter :: n = Nx*Ny\n real*8, intent(in) :: A(n,n)\n real*8, intent(in) :: b(n)\n real*8, intent(inout) :: x(n)\n real*8, intent(in) :: iter_cr\n integer*4, intent(in) :: iter_max\n\n real*8 :: x0(n)\n real*8 :: iter_err, tmp\n integer*4 :: iter_cnt\n integer*4 :: I, J\n\n x0 = 0\n iter_cnt = 1\n do while (iter_cnt < iter_max)\n\n do I = 1, n\n tmp = 0.\n do J = 1, I - 1\n tmp = tmp + A(I,J)*x(J)\n end do\n do J = I + 1, n\n tmp = tmp + A(I,J)*x(J)\n end do\n x(I) = (b(I) - tmp)/A(I,I)\n end do\n\n iter_err = maxval(abs(x - x0)/x0)\n if (log_conv_show) print *, \"\", iter_cnt, iter_err\n if (iter_err < iter_cr) exit\n\n x0 = x\n iter_cnt = iter_cnt + 1\n\n end do\n\nend subroutine", "meta": {"hexsha": "555a05b87efec1f11015b5e3edd9e984c9c28e50", "size": 1224, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "iter_ja_p.f90", "max_stars_repo_name": "aviruch/unsteady-conduction-2d", "max_stars_repo_head_hexsha": "d154b0128bcd5be072cfcd75c66bb9ba268e0e68", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "iter_ja_p.f90", "max_issues_repo_name": "aviruch/unsteady-conduction-2d", "max_issues_repo_head_hexsha": "d154b0128bcd5be072cfcd75c66bb9ba268e0e68", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "iter_ja_p.f90", "max_forks_repo_name": "aviruch/unsteady-conduction-2d", "max_forks_repo_head_hexsha": "d154b0128bcd5be072cfcd75c66bb9ba268e0e68", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-27T15:02:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-27T15:02:18.000Z", "avg_line_length": 25.5, "max_line_length": 59, "alphanum_fraction": 0.4428104575, "num_tokens": 374, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.7807999593202398}} {"text": "\n! jacobi2d_main_omp.f90\n\nprogram jacobi2d_main\n implicit none\n real(kind=8) :: tol, dumax\n integer :: n,iter,maxiter,nthreads\n\n\n n = 120\n tol = 0.1 / (n+1)**2\n tol = 1.d-6\n maxiter = 100000\n\n\tprint \"('Solving Laplace equation on',i4,' by',i4,' grid by Jacobi iteration')\", n,n\n\tprint \"('Note: This is a lousy numerical method but illustrates OpenMP speedup')\"\n\tprint *,' '\n\t\n ! Specify number of threads to use:\n nthreads = 1\n call jacobi2d_sub(n, tol, maxiter, iter, dumax, nthreads)\n\n nthreads = 3\n call jacobi2d_sub(n, tol, maxiter, iter, dumax, nthreads)\n\n\nend program jacobi2d_main\n", "meta": {"hexsha": "76a910d504eb90a5e518dea56b9ad3decc2238f1", "size": 624, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/lectures/lecture1/jacobi2d_main_omp.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/lectures/lecture1/jacobi2d_main_omp.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/lectures/lecture1/jacobi2d_main_omp.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.2857142857, "max_line_length": 85, "alphanum_fraction": 0.6554487179, "num_tokens": 209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.7807970367917069}} {"text": "PROGRAM main\n!\n! Purpose:\n! Just for homework 9 in chapter6\n!\n! Record of revisions:\n! Date Programmer Description of change\n! ==== ========== =====================\n! 04/12/17 hopeful Original code\n!\nIMPLICIT NONE\n\nREAL,ALLOCATABLE :: nums(:)\nINTEGER :: length\nINTEGER :: i\nREAL, EXTERNAL :: RMS\n\nWRITE (*,*) 'Please input the data'' length:'\nREAD (*,*) length\nALLOCATE(nums(length))\nWRITE (*,*) 'Please input numbers:'\nDO i = 1, length\n READ (*,*) nums(i)\nEND DO\n\nWRITE (*,*) 'The RMS of those number is ', RMS(nums, length)\nDEALLOCATE(nums)\nEND PROGRAM main\n\n! 求均方根平均值的函数\nREAL FUNCTION RMS(nums,length)\nIMPLICIT NONE\n\nINTEGER :: length\nREAL :: nums(length)\nINTEGER :: i\n\nRMS = SQRT(SUM(nums*nums)/length)\nRETURN\nEND FUNCTION RMS\n", "meta": {"hexsha": "75436fd2a240d20f4e1765ab57c323a13eb76029", "size": 757, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "homework/chapter6/6_9/main.f90", "max_stars_repo_name": "hopeful0/fortran-study", "max_stars_repo_head_hexsha": "7bd50580436e747f428cefeda2ba595893867503", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "homework/chapter6/6_9/main.f90", "max_issues_repo_name": "hopeful0/fortran-study", "max_issues_repo_head_hexsha": "7bd50580436e747f428cefeda2ba595893867503", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "homework/chapter6/6_9/main.f90", "max_forks_repo_name": "hopeful0/fortran-study", "max_forks_repo_head_hexsha": "7bd50580436e747f428cefeda2ba595893867503", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.4634146341, "max_line_length": 60, "alphanum_fraction": 0.6380449141, "num_tokens": 222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299529686201, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7807970224144952}} {"text": " PROGRAM MAIN\nC GAUSSIAN ELIMINATION\nC From: http://users.metu.edu.tr/azulfu/courses/es361/programs/fortran/GAUEL.FOR\n\n IMPLICIT NONE\n REAL, DIMENSION (20,21) :: A\n INTEGER :: I, J, N\n\n 10 FORMAT(/,' GAUSS ELIMINATION')\n WRITE (*,10) \n\nC INITIALIZATION\nC DATA N/4/\nC DATA (A(1,J), J=1,5) /-40.0,28.5,0.,0.,1.81859/\nC DATA (A(2,J), J=1,5) /21.5,-40.0,28.5,0.,-1.5136/\nC DATA (A(3,J), J=1,5) /0.,21.5,-40.0,28.5,-0.55883/\nC DATA (A(4,J), J=1,5) /0.,0.,21.5,-40.0,1.69372/\n\n N = 4\n \n 11 FORMAT(5(X,F8.2))\n OPEN(10, FILE=\"INFILE-GAUSSIAN\")\n\n DO I = 1, N\n READ (10,11) A(I,1), A(I,2), A(I,3), A(I,4), A(I,5)\n END DO\n CLOSE(10)\nC END INITIALIZATION\n\n 12 FORMAT(/,' AUGMENTED MATRIX',/)\n WRITE(*,12)\n\n61 FORMAT(5(1X,f8.4))\n DO I=1,N\n WRITE(*, 61) A(I,1), A(I,2), A(I,3), A(I,4), A(I,5)\n END DO\n\n 13 FORMAT('')\n 14 FORMAT(' SOLUTION')\n 15 FORMAT(' ...........................................')\n 16 FORMAT(' I X(I)')\n \n WRITE(*,13)\n \n CALL GAUSS(N,A)\n\n WRITE(*,13)\n WRITE(*,14)\n WRITE(*,15)\n WRITE(*,16) \n WRITE(*,15)\n\n72 FORMAT(5X,I5, F12.6)\n\n DO I=1,N\n WRITE (*,72) I, A(I,N+1)\n END DO\n\n WRITE(*,15)\n WRITE(*,13)\n \n STOP\n END PROGRAM MAIN\nC*************************************\n SUBROUTINE GAUSS(N,A)\n\n REAL, DIMENSION(20,21) :: A\n INTEGER PV, I, J, K, N, R, JC, JR, KC, NV\n REAL :: EPS, EPS2, DET, TM, TEMP, VA\n\n EPS=1.0\n DO WHILE (1.0+EPS.GT.1.0) \n EPS=EPS/2.0\n END DO\n EPS=EPS*2\n \n 11 FORMAT (' MACHINE EPSILON=',E16.8)\n WRITE(*,11) EPS\n \n EPS2=EPS*2\n\n1005 DET=1.0\n DO 1010 I=1,N-1\n PV=I\n DO J=I+1,N\n IF (ABS(A(PV,I)) .LT. ABS(A(J,I))) PV=J\n END DO\n IF (PV.NE.I) THEN\n DO JC=1,N+1\n TM=A(I,JC)\n A(I,JC)=A(PV,JC)\n A(PV,JC)=TM\n END DO\n1045 DET=-1*DET\n END IF\n\n1050 IF (A(I,I).EQ.0.0) THEN\n STOP 'MATRIX IS SINGULAR'\n END IF\n\n DO JR=I+1,N\n IF (A(JR,I).NE.0.0) THEN\n R=A(JR,I)/A(I,I)\n DO KC=I+1,N+1\n TEMP=A(JR,KC)\n A(JR,KC)=A(JR,KC)-R*A(I,KC)\n IF (ABS(A(JR,KC)).LT.EPS2*TEMP) A(JR,KC)=0.0\n END DO\n END IF\n1060 END DO\n1010 CONTINUE\n DO I=1,N\n DET=DET*A(I,I)\n END DO\n\n 12 FORMAT(/,' DETERMINANT= ',F16.5,/)\n WRITE(*,12) DET\n\n IF (A(N,N).EQ.0.0) THEN\n STOP 'MATRIX IS SINGULAR'\n END IF\n\n A(N,N+1)=A(N,N+1)/A(N,N)\n DO NV=N-1,1,-1\n VA=A(NV,N+1)\n DO K=NV+1,N\n VA=VA-A(NV,K)*A(K,N+1)\n END DO\n A(NV,N+1)=VA/A(NV,NV)\n END DO\n RETURN\n1100 CONTINUE\n RETURN\n\n END\n", "meta": {"hexsha": "8b82290c3b8572c079bc153b2036cd87fe219023", "size": 2944, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/arrays/arrays-basic-08.f", "max_stars_repo_name": "mikiec84/delphi", "max_stars_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-03-03T11:57:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T21:19:54.000Z", "max_issues_repo_path": "tests/data/program_analysis/arrays/arrays-basic-08.f", "max_issues_repo_name": "mikiec84/delphi", "max_issues_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 385, "max_issues_repo_issues_event_min_datetime": "2018-02-21T16:52:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T07:44:56.000Z", "max_forks_repo_path": "tests/data/program_analysis/arrays/arrays-basic-08.f", "max_forks_repo_name": "mikiec84/delphi", "max_forks_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-03-20T01:08:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-29T01:04:49.000Z", "avg_line_length": 21.6470588235, "max_line_length": 84, "alphanum_fraction": 0.425951087, "num_tokens": 1132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.8670357580842941, "lm_q1q2_score": 0.780791530413439}} {"text": " double precision function deter3(r)\n implicit none\n double precision r(3,3)\nc\nc return the determinant of a 3x3 matrix\nc\n deter3 = \n $ r(1,1)*(r(2,2)*r(3,3)-r(2,3)*r(3,2)) -\n $ r(1,2)*(r(2,1)*r(3,3)-r(2,3)*r(3,1)) + \n $ r(1,3)*(r(2,1)*r(3,2)-r(2,2)*r(3,1))\nc\n end\n", "meta": {"hexsha": "6b5f41db05944622587a1d57a2cb3bb42b378da7", "size": 318, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ecce-v7.0/src/apps/symmetry/deter3.f", "max_stars_repo_name": "mattbernst/ECCE", "max_stars_repo_head_hexsha": "8e185a3b8190b5e168f034c0e0c366ca492fd49e", "max_stars_repo_licenses": ["ECL-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ecce-v7.0/src/apps/symmetry/deter3.f", "max_issues_repo_name": "mattbernst/ECCE", "max_issues_repo_head_hexsha": "8e185a3b8190b5e168f034c0e0c366ca492fd49e", "max_issues_repo_licenses": ["ECL-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ecce-v7.0/src/apps/symmetry/deter3.f", "max_forks_repo_name": "mattbernst/ECCE", "max_forks_repo_head_hexsha": "8e185a3b8190b5e168f034c0e0c366ca492fd49e", "max_forks_repo_licenses": ["ECL-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.4615384615, "max_line_length": 50, "alphanum_fraction": 0.4716981132, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.963230536035447, "lm_q2_score": 0.8104789086703224, "lm_q1q2_score": 0.7806780336439386}} {"text": "subroutine inverse(a,c,n)\n!============================================================\n! Inverse matrix\n! Method: Based on Doolittle LU factorization for Ax=b\n! Alex G. December 2009\n!-----------------------------------------------------------\n! input ...\n! a(n,n) - array of coefficients for matrix A\n! n - dimension\n! output ...\n! c(n,n) - inverse matrix of A\n! comments ...\n! the original matrix a(n,n) will be destroyed \n! during the calculation\n!===========================================================\nimplicit none \ninteger n\ndouble precision a(n,n), c(n,n)\ndouble precision L(n,n), U(n,n), b(n), d(n), x(n)\ndouble precision coeff\ninteger i, j, k\n\n! step 0: initialization for matrices L and U and b\n! Fortran 90/95 aloows such operations on matrices\nL=0.0\nU=0.0\nb=0.0\n\n! step 1: forward elimination\ndo k=1, n-1\n do i=k+1,n\n coeff=a(i,k)/a(k,k)\n L(i,k) = coeff\n do j=k+1,n\n a(i,j) = a(i,j)-coeff*a(k,j)\n end do\n end do\nend do\n\n! Step 2: prepare L and U matrices \n! L matrix is a matrix of the elimination coefficient\n! + the diagonal elements are 1.0\ndo i=1,n\n L(i,i) = 1.0\nend do\n! U matrix is the upper triangular part of A\ndo j=1,n\n do i=1,j\n U(i,j) = a(i,j)\n end do\nend do\n\n! Step 3: compute columns of the inverse matrix C\ndo k=1,n\n b(k)=1.0\n d(1) = b(1)\n! Step 3a: Solve Ld=b using the forward substitution\n do i=2,n\n d(i)=b(i)\n do j=1,i-1\n d(i) = d(i) - L(i,j)*d(j)\n end do\n end do\n! Step 3b: Solve Ux=d using the back substitution\n x(n)=d(n)/U(n,n)\n do i = n-1,1,-1\n x(i) = d(i)\n do j=n,i+1,-1\n x(i)=x(i)-U(i,j)*x(j)\n end do\n x(i) = x(i)/u(i,i)\n end do\n! Step 3c: fill the solutions x(n) into column k of C\n do i=1,n\n c(i,k) = x(i)\n end do\n b(k)=0.0\nend do\nend subroutine inverse\n", "meta": {"hexsha": "01b4e1797d917a04d37f4195c51f05b4b0229870", "size": 1786, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code/inverse_matrice.f90", "max_stars_repo_name": "bsenjean/P-SOET", "max_stars_repo_head_hexsha": "4df873bf849b24415436c80a9f2d3721ca59cca7", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-02-05T12:42:19.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-22T14:52:53.000Z", "max_issues_repo_path": "code/inverse_matrice.f90", "max_issues_repo_name": "bsenjean/P-SOET", "max_issues_repo_head_hexsha": "4df873bf849b24415436c80a9f2d3721ca59cca7", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "code/inverse_matrice.f90", "max_forks_repo_name": "bsenjean/P-SOET", "max_forks_repo_head_hexsha": "4df873bf849b24415436c80a9f2d3721ca59cca7", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.325, "max_line_length": 61, "alphanum_fraction": 0.5419932811, "num_tokens": 606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.7806717876863154}} {"text": "SUBROUTINE stencilf90(A, B, n, iters)\n IMPLICIT NONE\n INTEGER, INTENT( IN ) :: n, iters\n DOUBLE PRECISION, DIMENSION (n,n,n) :: A, B\n DOUBLE PRECISION :: c\n INTEGER :: count\n\n c = 1 / 7.\n\n DO count=1,iters\n A(2:N-1,2:N-1,2:N-1) = c * (B(2:N-1,2:N-1,2:N-1) + B(3:N,2:N-1,2:N-1) &\n + B(1:N-2,2:N-1,2:N-1) + B(2:N-1,3:N,2:N-1) + B(2:N-1,1:N-2,2:N-1) &\n + B(2:N-1,2:N-1,3:N) + B(2:N-1,2:N-1,1:N-2))\n \n B(2:N-1,2:N-1,2:N-1) = c * (A(2:N-1,2:N-1,2:N-1) + A(3:N,2:N-1,2:N-1) &\n + A(1:N-2,2:N-1,2:N-1) + A(2:N-1,3:N,2:N-1) + A(2:N-1,1:N-2,2:N-1) &\n + A(2:N-1,2:N-1,3:N) + A(2:N-1,2:N-1,1:N-2))\n END DO\nEND SUBROUTINE\n", "meta": {"hexsha": "08d787b47685461ec317b56e3df680e85c317b54", "size": 691, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "depspawn-blitz-0.10/benchmarks/stencilf90.f90", "max_stars_repo_name": "fraguela/depspawn", "max_stars_repo_head_hexsha": "b5760f4c0d38a1b245ee5274e2ccc5c5fe2d3d45", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2017-04-12T11:05:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T11:10:27.000Z", "max_issues_repo_path": "ibtk/third_party/blitz-0.10/benchmarks/stencilf90.f90", "max_issues_repo_name": "MSV-Project/IBAMR", "max_issues_repo_head_hexsha": "3cf614c31bb3c94e2620f165ba967cba719c45ea", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ibtk/third_party/blitz-0.10/benchmarks/stencilf90.f90", "max_forks_repo_name": "MSV-Project/IBAMR", "max_forks_repo_head_hexsha": "3cf614c31bb3c94e2620f165ba967cba719c45ea", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.55, "max_line_length": 79, "alphanum_fraction": 0.4457308249, "num_tokens": 380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409308, "lm_q2_score": 0.8354835371034369, "lm_q1q2_score": 0.7806717754520377}} {"text": "module gaussquad\n !\n ! This module is a revision of the Fortran 77 code gaussq.f\n !\n ! Original version 20 Jan 1975 from Stanford\n ! Modified 21 Dec 1983 by Eric Grosse\n ! f95 version Nov 2005 by Bill McLean\n !\n ! The routines are used to compute the nodes t(j) and weights\n ! w(j) for Gaussian-type quadrature rules with pre-assigned\n ! nodes. These quantities are used when one wishes to approximate\n ! \n ! / b\n ! |\n ! | f(x) w(x) dx\n ! |\n ! / a\n !\n ! by \n !\n ! n\n ! ---\n ! \\\n ! | f(t(j)) * w(j).\n ! /\n ! ---\n ! j=1 \n !\n ! (Note w(x) and w(j) have no connection with each other.)\n ! Here w(x) is one of six possible non-negative weight\n ! functions (listed below), and f(x) is the\n ! function to be integrated. Gaussian quadrature is particularly\n ! useful on infinite intervals (with appropriate weight\n ! functions), since then other techniques often fail.\n !\n ! Associated with each weight function w(x) is a set of\n ! orthogonal polynomials. The nodes t(j) are just the zeroes\n ! of the proper n-th degree polynomial.\n !\n ! References:\n !\n ! 1. Golub, G. H., and Welsch, J. H., Calculation of gaussian\n ! quadrature rules, Mathematics of Computation 23 (april,\n ! 1969), pp. 221-230.\n ! 2. Golub, G. H., Some modified matrix eigenvalue problems,\n ! Siam Review 15 (april, 1973), pp. 318-334 (section 7).\n ! 3. Stroud and Secrest, Gaussian Quadrature Formulas, Prentice-\n ! Hall, Englewood Cliffs, N.J., 1966.\n\n implicit none\n\n integer, parameter :: WP = selected_real_kind(15)\n character(len=*), parameter :: VERSION = \"2.4\"\n\n ! Use at most MAXITS QL iterations in the symmetric, tridiagonal \n ! eigenproblem routine.\n integer, parameter :: MAXITS = 30\n\n real(kind=WP), parameter :: ZERO = 0, HALF = 0.5_WP, &\n ONE = 1, TWO = 2, FOUR = 4\n\n intrinsic :: abs, epsilon, sqrt, sign\n\n !\n ! The f77 function dlgama, from the specfun library, returns the \n ! logarithm of the gamma function.\n !\n interface \n double precision function dlgama(x) \n double precision x\n end function dlgama\n end interface \n\n !\n ! The following named constants are used to select the type of\n ! quadrature rule.\n !\n integer, parameter :: &\n LEGENDRE = 0, & ! w(x) = 1 on (-1,1)\n CHEBYSHEV_FIRST = 1, & ! w(x) = 1/sqrt(1-x**2) on (-1,1)\n CHEBYSHEV_SECOND = 2, & ! w(x) = sqrt(1-x**2) on (-1,1)\n JACOBI = 3, & ! w(x) = (1-x)**alpha * (1+x)**beta on (-1,1)\n LAGUERRE = 4, & ! w(x) = exp(-x) * x**alpha on (0,Inf)\n HERMITE = 5 ! w(x) = exp(-x**2) on (-Inf,Inf)\n\n character(len=*), parameter :: RULE_NAME(0:5) = (/ &\n \"Legendre \", &\n \"Chebyshev (first kind) \", &\n \"Chebyshev (second kind)\", &\n \"Jacobi \", &\n \"Laguerre \", &\n \"Hermite \" /)\n\ncontains\n\n subroutine gauss_rule(icode, n, t, w, work, alpha, beta, endpt, info)\n !\n ! Computes an n-point Gauss quadrature rule.\n !\n integer, intent(in) :: icode, n\n real(kind=WP), intent(out) :: t(n), w(n), work(n)\n real(kind=WP), intent(in) :: alpha, beta\n character(len=1), intent(in) :: endpt\n integer, intent(out) :: info\n !\n ! The arguments have the following meanings:\n !\n ! icode The integer code specifying the weight function and interval,\n ! e.g., HERMITE.\n !\n ! n The number of quadrature points.\n !\n ! t, w Arrays holding the points and weights.\n !\n ! work A workspace array\n !\n ! alpha Ignored unless icode = JACOBI or LAGUERRE; defaults to 0.\n ! beta Ignored unless icode = JACOBI; defaults to 0.\n !\n ! endpt Specifies whether to compute a plain Gauss rule, in\n ! which all points are strictly in the interior of the\n ! interval, or a Gauss-Radau rule, in which one endpoint\n ! is a quadrature point, or a Gauss-Lobatto rule, in which \n ! both endpoints are quadrature points. Put \n ! endpt = 'N' for no endpoints (plain Gauss rule)\n ! endpt = 'B' for both endpoints (Lobatto rule)\n ! endpt = 'L' for left endpoint only (left Radau rule)\n ! endpt = 'R' for right endpoint only (right Radau rule)\n ! (The endpoint in question must be finite.)\n !\n ! info = 0 on successful return\n ! = -k if kth argument has an illegal value\n ! > 0 eigensystem routine failed\n !\n real(kind=WP) :: muzero, lo, hi\n\n info = 0\n if ( n < 1 ) then\n info = -2\n return\n end if\n if ( icode == JACOBI .or. icode == LAGUERRE ) then\n if ( alpha <= -ONE ) then\n info = -6\n return\n end if\n end if\n if ( icode == JACOBI .and. beta <= -ONE ) then\n info = -7\n return\n end if\n if ( endpt /= 'N' .and. endpt /= 'B' &\n .and. endpt /= 'L' .and. endpt /= 'R' ) then\n print *, endpt\n info = -8\n return\n end if\n\n call recur_coeffs(icode, n, alpha, beta, t, work, muzero, info)\n if ( info /= 0 ) return\n lo = -ONE\n hi = +ONE\n if ( n == 1 .and. endpt == 'B' ) then ! Need at least 2 points to \n info = -8 ! include both ends.\n return\n end if\n select case(icode)\n case(LAGUERRE)\n select case(endpt)\n case('L')\n lo = ZERO\n case('R','B')\n info = -8\n return\n end select\n case(HERMITE)\n select case(endpt)\n case('L','R','B')\n info = -8\n return\n end select\n end select\n call custom_gauss_rule(n, t, work, w, muzero, endpt, lo, hi, info)\n \n end subroutine gauss_rule\n \n subroutine custom_gauss_rule(n, a, b, w, muzero, endpt, lo, hi, info)\n integer, intent(in) :: n\n real(kind=WP), intent(inout) :: a(n), b(n), w(n)\n character(len=1), intent(in) :: endpt\n real(kind=WP), intent(in) :: muzero, lo, hi\n integer, intent(out) :: info\n !\n ! On entry:\n !\n ! a, b hold the coefficients in the 3-term recurrence relation for\n ! the orthonormal polynomials (as given by recur_coeffs for\n ! any of the classical weight functions).\n !\n ! On return:\n !\n ! a, w hold the points and weights of the Gauss rule.\n !\n ! The meanings of the other arguments are as for gauss_rule.\n !\n real(kind=WP) :: g, t1\n integer :: i\n\n ! The matrix of coefficients is assumed to be symmetric. The array t \n ! contains the diagonal elements, the array work the off-diagonal elements.\n !\n ! Make appropriate changes in the lower right 2 by 2 submatrix.\n !\n select case(endpt)\n case('L')\n if ( n == 1 ) then\n a(1) = lo\n else\n a(n) = solve(n, lo, a, b) * b(n-1)**2 + lo\n end if\n case('R')\n if ( n == 1 ) then\n a(1) = hi \n else\n a(n) = solve(n, hi, a, b) * b(n-1)**2 + hi\n end if\n case('B')\n if ( n == 1 ) then\n info = -6\n return\n end if\n g = solve(n, lo, a, b)\n t1 = ( lo - hi ) / ( solve(n, hi, a, b) - g )\n b(n-1) = sqrt(t1)\n a(n) = lo + g * t1\n end select\n \n call st_eigenproblem(n, a, b, w, info)\n do i = 1, n\n w(i) = muzero * w(i)**2\n end do\n\n contains\n\n function solve(n, shift, a, b) result(s)\n !\n ! This procedure performs elimination to solve for the\n ! n-th component of the solution delta to the equation\n !\n ! (Jn - shift*Identity) * delta = en,\n !\n ! where en is the vector of all zeroes except for 1 in\n ! the n-th position. The matrix Jn is symmetric tridiagonal, with \n ! diagonal elements a(i), off-diagonal elements b(i). This equation\n ! must be solved to obtain the appropriate changes in the lower\n ! 2 by 2 submatrix of coefficients for orthogonal polynomials.\n !\n integer, intent(in) :: n\n real(kind=WP), intent(in) :: shift, a(n), b(n)\n real(kind=WP) :: s\n\n integer :: nm1, i\n real(kind=WP) :: t\n\n t = a(1) - shift\n nm1 = n - 1\n do i = 2, nm1\n t = a(i) - shift - b(i-1)**2 / t\n end do\n s = ONE / t\n \n end function solve\n\n end subroutine custom_gauss_rule\n\n subroutine recur_coeffs(icode, n, alpha, beta, a, b, muzero, info)\n integer, intent(in) :: icode, n\n real(kind=WP), intent(in) :: alpha, beta\n real(kind=WP), intent(out) :: a(n), b(n), muzero\n integer, intent(out) :: info\n !\n ! This procedure supplies the coefficients a(j), b(j) of the\n ! recurrence relation\n !\n ! b p (x) = (x - a ) p (x) - b p (x)\n ! j j j j-1 j-1 j-2\n !\n ! For the various classical (normalized) orthogonal polynomials,\n ! and the zero-th moment\n !\n ! / \n ! |\n ! muzero = | w(x) dx\n ! |\n ! /\n !\n ! of the given weight function w(x). since the\n ! polynomials are orthonormalized, the tridiagonal matrix is\n ! guaranteed to be symmetric.\n !\n ! The input parameter alpha is used only for Laguerre and\n ! Jacobi polynomials, and the parameter beta is used only for\n ! Jacobi polynomials. The Laguerre and Jacobi polynomials\n ! require the gamma function.\n !\n real(kind=WP) :: pi, ri, ab, abi, a2b2\n integer :: i\n\n pi = FOUR * atan(ONE)\n\n select case ( icode )\n case(LEGENDRE)\n muzero = TWO\n do i = 1, n\n a(i) = ZERO\n ri = real(i, WP)\n b(i) = ri / sqrt(FOUR*ri*ri-ONE)\n end do\n case(CHEBYSHEV_FIRST)\n muzero = pi\n do i = 1, n\n a(i) = ZERO\n b(i) = HALF\n end do\n b(1) = sqrt(HALF)\n case(CHEBYSHEV_SECOND)\n muzero = HALF * pi\n do i = 1, n\n a(i) = ZERO\n b(i) = HALF\n end do\n case(HERMITE)\n muzero = sqrt(pi)\n do i = 1, n\n a(i) = ZERO\n b(i) = sqrt(HALF*i)\n end do\n case(JACOBI)\n ab = alpha + beta\n abi = TWO + ab\n muzero = TWO**(ab + ONE) * exp( &\n dlgama(alpha+ONE) + dlgama(beta+ONE) - dlgama(abi) )\n a(1) = (beta - alpha)/abi\n b(1) = sqrt( FOUR*(ONE+alpha)*(ONE+beta) / ((abi+ONE)*abi*abi) )\n a2b2 = beta*beta - alpha*alpha\n do i = 2, n\n abi = TWO*i + ab\n a(i) = a2b2 / ( (abi-TWO)*abi )\n b(i) = sqrt( FOUR*i*(i+alpha)*(i+beta)*(i+ab)/((abi*abi-ONE)*abi*abi) )\n end do\n return\n case(LAGUERRE)\n muzero = exp( dlgama(alpha+ONE) )\n do i = 1, n\n a(i) = TWO*i - ONE + alpha\n b(i) = sqrt(i*(i+alpha))\n end do\n case default ! Bad value of icode.\n info = -1\n end select\n\n end subroutine recur_coeffs\n\n subroutine st_eigenproblem(n, d, e, z, info)\n ! Finds the eigenvalues and first components of the eigenvectors of a \n ! symmetric tridiagonal matrix by the implicit QL method.\n integer, intent(in) :: n\n real(kind=WP), intent(inout) :: d(n), e(n)\n real(kind=WP), intent(out) :: z(n)\n integer, intent(out) :: info\n !\n ! This subroutine is a translation of an algol procedure,\n ! Num. Math. 12, 377-383(1968) by Martin and Wilkinson,\n ! as modified in Num. Math. 15, 450(1970) by Dubrulle.\n ! Handbook for Auto. Comp., vol.ii-linear algebra, 241-248(1971).\n ! This is a modified version of the 'eispack' routine imtql2.\n !\n ! n The order of the matrix.\n !\n ! d On entry, holds the diagonal elements of the matrix.\n ! On exit, holds the eigenvalues in ascending order.\n ! If info > 0 on exit, then the eigenvalues are correct but\n ! unordered for indices 1, 2, ..., info-1;\n\n !\n ! e On enty, holds the subdiagonal elements of the matrix\n ! in its first n-1 positions; e(n) is arbitrary.\n ! On exit, e is overwritten.\n !\n ! z Holds the first components of the orthonormal eigenvectors\n ! of the symmetric tridiagonal matrix. if info > 0 on exit,\n ! then z contains the eigenvector components associated with \n ! the stored eigenvalues.\n !\n ! info Set to 0 on a normal return. If info = j > 0 then the j-th\n ! eigenvalue has not been determined after MAXITS iterations.\n !\n integer :: i, j, k, l, m\n real(kind=WP) :: b, c, f, g, p, r, s\n\n info = 0\n\n z(1) = ONE\n z(2:n) = ZERO\n \n if (n == 1) return ! nothing to do for 1x1 matrix.\n\n e(n) = ZERO\n loop_over_l: do l = 1, n\n loop_over_j: do j = 1, MAXITS\n ! Look for small sub-diagonal element \n do m = l, n\n if (m == n) exit\n if ( abs(e(m)) <= epsilon(e) * (abs(d(m)) + abs(d(m+1)))) exit\n end do\n\n p = d(l)\n if (m == l) cycle loop_over_l\n if (j == MAXITS) then\n ! Set error -- no convergence to an eigenvalue after 30 iterations.\n info = l\n exit loop_over_l\n end if\n ! Form shift \n g = (d(l+1) - p) / (TWO * e(l))\n r = sqrt(g*g+ONE)\n g = d(m) - p + e(l) / (g + sign(r, g))\n s = ONE\n c = ONE\n p = ZERO\n loop_over_i: do i = m-1, l, -1\n f = s * e(i)\n b = c * e(i)\n if ( abs(f) < abs(g) ) then\n s = f / g\n r = dsqrt(s*s+ONE)\n e(i+1) = g * r\n c = ONE / r\n s = s * c\n else\n c = g / f\n r = sqrt(c*c+ONE)\n e(i+1) = f * r\n s = ONE / r\n c = c * s\n end if\n g = d(i+1) - p\n r = (d(i) - g) * s + TWO * c * b\n p = s * r\n d(i+1) = g + p\n g = c * r - b\n ! Form first component of vector.\n f = z(i+1)\n z(i+1) = s * z(i) + c * f\n z(i) = c * z(i) - s * f\n end do loop_over_i\n\n d(l) = d(l) - p\n e(l) = g\n e(m) = ZERO\n end do loop_over_j\n end do loop_over_l\n\n ! Order eigenvalues and eigenvectors.\n do i = 1, n-1\n ! Find p = d(k) = min d(j), i <= j <= n\n k = i\n p = d(i)\n do j = i+1, n\n if ( d(j) >= p ) cycle\n k = j\n p = d(j)\n end do \n if ( k == i ) cycle\n ! Swap d(i) and d(k), z(i) and z(k)\n d(k) = d(i)\n d(i) = p\n p = z(i)\n z(i) = z(k)\n z(k) = p\n end do\n\n end subroutine st_eigenproblem\n\n subroutine orthonormal_polynomials(n, m, x, a, b, muzero, p, ldp)\n integer, intent(in) :: n, m, ldp\n real(kind=WP), intent(in) :: x(m), a(n), b(n), muzero\n real(kind=WP), intent(out) :: p(ldp,0:n)\n !\n ! Returns p(i,j) = value of p_j at x(i), where p_j is the\n ! orthonormal polynomial of degree j determined by the recursion\n ! coefficients a(j), b(j) and zeroth moment muzeror, as computed with \n ! the subroutine recur_coeffs. Must have m <= ldp.\n !\n integer :: i, j\n real(kind=WP) :: c, rb\n\n c = ONE / sqrt(muzero)\n rb = ONE / b(1)\n do i = 1, m\n p(i,0) = c\n p(i,1) = rb * ( x(i) - a(1) ) * c\n end do\n do j = 2, n\n rb = ONE / b(j)\n do i = 1, m\n p(i,j) = rb * ( ( x(i) - a(j) ) * p(i,j-1) - b(j-1) * p(i,j-2) )\n end do\n end do\n \n end subroutine orthonormal_polynomials\n\nend module gaussquad\n", "meta": {"hexsha": "a307ae9f5569d9a2d5c01a0229716ee4fa61aab5", "size": 15880, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "DGV0D3V/gaussquad.f90", "max_stars_repo_name": "alexmalekseenko/DGV0D3V", "max_stars_repo_head_hexsha": "2136be5a4af6c2c83e7cf543460845447c510359", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "DGV0D3V/gaussquad.f90", "max_issues_repo_name": "alexmalekseenko/DGV0D3V", "max_issues_repo_head_hexsha": "2136be5a4af6c2c83e7cf543460845447c510359", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-04-13T05:30:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-13T05:30:11.000Z", "max_forks_repo_path": "DGV0D3V/gaussquad.f90", "max_forks_repo_name": "alexmalekseenko/DGV0D3V", "max_forks_repo_head_hexsha": "2136be5a4af6c2c83e7cf543460845447c510359", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.8949416342, "max_line_length": 79, "alphanum_fraction": 0.5068639798, "num_tokens": 4959, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541577509315, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7805736773666538}} {"text": "subroutine kupper_wavelet(ndata, sample, t0, m0, tdiff, wavelet)\r\n use nrtype, only : dp, fp\r\n use constants, only : pi\r\n implicit none\r\n !!Kupper wavelet wavelet(t) = 9.0 / 16.0 * pi * m0 / t0 (sin(pi / t0 * t) - 1.0 / 3.0 * sin(3.0 * pi / t0 * t))\r\n\r\n integer, intent(in) :: ndata !!number of data for output wavelet\r\n real(kind = dp), intent(in) :: sample !!sampling period (s)\r\n real(kind = dp), intent(in) :: t0, m0 !!t0: characteristic source duration time (s), m0: seismic moment (amplitude)\r\n real(kind = dp), intent(in) :: tdiff !!time for wavelet delay (s)\r\n real(kind = dp), intent(out) :: wavelet(ndata)\r\n\r\n integer :: i, tdiff_int\r\n real(kind = dp) :: time\r\n\r\n tdiff_int = int(tdiff / sample)\r\n \r\n wavelet(1 : ndata) = 0.0_dp\r\n do i = 1, ndata\r\n time = sample * dble(i - 1)\r\n if(time .ge. 0.0_dp .and. time .le. t0) then\r\n wavelet(i) = 9.0_dp / 16.0_dp * pi * m0 / t0 * &\r\n & (sin(pi / t0 * time) - 1.0_dp / 3.0_dp * sin(3.0_dp * pi / t0 * time)) !!From Takemura et al\r\n !wavelet(i) = m0 * 3.0_dp / 4.0_dp * pi / t0 * sin(pi * time / t0) ** 3 !!From OpenSWPC document\r\n endif\r\n enddo\r\n\r\n !!delay the initial time\r\n do i = ndata, 1, -1\r\n if(i - tdiff_int .ge. 1) then\r\n wavelet(i) = wavelet(i - tdiff_int)\r\n else\r\n wavelet(i) = 0.0_dp\r\n endif\r\n enddo\r\n\r\n return\r\nend subroutine kupper_wavelet\r\n\r\nsubroutine boxcar_wavelet(ndata, sample, t0, amp, tdiff, wavelet)\r\n use nrtype, only : dp, fp\r\n implicit none\r\n !!Boxcar function wavelet(t) = 1 / t0 (0<=t<=t0)\r\n\r\n integer, intent(in) :: ndata !!number of data for output wavelet\r\n real(kind = dp), intent(in) :: sample !!sampling period (s)\r\n real(kind = dp), intent(in) :: t0, amp !!t0: duration (s), amp: (amplitude)\r\n real(kind = dp), intent(in) :: tdiff !!time for wavelet delay (s)\r\n real(kind = dp), intent(out) :: wavelet(ndata)\r\n\r\n integer :: i, tdiff_int\r\n real(kind = dp) :: time\r\n\r\n tdiff_int = int(tdiff / sample)\r\n \r\n wavelet(1 : ndata) = 0.0_dp\r\n do i = 1, ndata\r\n time = sample * dble(i - 1)\r\n if(time .ge. 0.0_dp .and. time .le. t0) then\r\n wavelet(i) = amp / t0\r\n endif\r\n enddo\r\n\r\n !!delay the initial time\r\n do i = ndata, 1, -1\r\n if(i - tdiff_int .ge. 1) then\r\n wavelet(i) = wavelet(i - tdiff_int)\r\n else\r\n wavelet(i) = 0.0_dp\r\n endif\r\n enddo\r\n\r\n return\r\nend subroutine boxcar_wavelet\r\n\r\nsubroutine triangle_wavelet(ndata, sample, t0, amp, tdiff, wavelet)\r\n use nrtype, only : dp, fp\r\n implicit none\r\n !!triangle function wavelet(t) = 4 * t / t0**2 (0<=t<=t0/2), -4(t - t0) / t0**2\r\n\r\n integer, intent(in) :: ndata !!number of data for output wavelet\r\n real(kind = dp), intent(in) :: sample !!sampling period (s)\r\n real(kind = dp), intent(in) :: t0, amp !!t0: dulation (s), amp: (amplitude)\r\n real(kind = dp), intent(in) :: tdiff !!time for wavelet delay (s)\r\n real(kind = dp), intent(out) :: wavelet(ndata)\r\n\r\n integer :: i, tdiff_int\r\n real(kind = dp) :: time\r\n\r\n tdiff_int = int(tdiff / sample)\r\n \r\n wavelet(1 : ndata) = 0.0_dp\r\n do i = 1, ndata\r\n time = sample * dble(i - 1)\r\n if(time .ge. 0.0_dp .and. time .le. t0 / 2.0_dp) then\r\n wavelet(i) = amp * 4.0_dp * time / (t0 ** 2)\r\n elseif(time .gt. t0 / 2.0_dp .and. time .le. t0) then\r\n wavelet(i) = amp * (-4.0_dp * (time - t0) / (t0 ** 2))\r\n endif\r\n enddo\r\n\r\n !!delay the wavelet\r\n do i = ndata, 1, -1\r\n if(i - tdiff_int .ge. 1) then\r\n wavelet(i) = wavelet(i - tdiff_int)\r\n else\r\n wavelet(i) = 0.0_dp\r\n endif\r\n enddo\r\n\r\n return\r\nend subroutine triangle_wavelet\r\n\r\nsubroutine cosine_wavelet(ndata, sample, t0, amp, tdiff, wavelet)\r\n use nrtype, only : dp, fp\r\n use constants, only : pi\r\n implicit none\r\n !!cosine function wavelet(t) = 1 / t0 * (1 - cos(2*pi*t/t0))\r\n\r\n integer, intent(in) :: ndata !!number of data for output wavelet\r\n real(kind = dp), intent(in) :: sample !!sampling period (s)\r\n real(kind = dp), intent(in) :: t0, amp !!t0: duration (s), amp: (amplitude)\r\n real(kind = dp), intent(in) :: tdiff !!time for wavelet delay (s)\r\n real(kind = dp), intent(out) :: wavelet(ndata)\r\n\r\n integer :: i, tdiff_int\r\n real(kind = dp) :: time\r\n\r\n tdiff_int = int(tdiff / sample)\r\n \r\n wavelet(1 : ndata) = 0.0_dp\r\n do i = 1, ndata\r\n time = sample * dble(i - 1)\r\n if(time .ge. 0.0_dp .and. time .le. t0) then\r\n wavelet(i) = amp / t0 * (1.0_dp - cos(2.0_dp * pi * time / t0))\r\n endif\r\n enddo\r\n\r\n !!delay the wavelet\r\n do i = ndata, 1, -1\r\n if(i - tdiff_int .ge. 1) then\r\n wavelet(i) = wavelet(i - tdiff_int)\r\n else\r\n wavelet(i) = 0.0_dp\r\n endif\r\n enddo\r\n\r\n return\r\nend subroutine cosine_wavelet\r\n\r\n\r\nsubroutine ricker_wavelet(ndata, sample, fc, amp, tdiff, wavelet)\r\n use nrtype, only : dp, fp\r\n use constants, only : pi\r\n implicit none\r\n\r\n !!Ricker wavelet (shifted)\r\n !!wavelet(t) = -(2 * pi ** 2 * fc ** 2 * (t - 1.25 / fc) ** 2 - 1) * exp(-pi ** 2 * fc ** 2 * (t - 1.25 / fc) ** 2)\r\n !!Meaning of shifted, refer to the GMS wavepage\r\n\r\n integer, intent(in) :: ndata !!number of data for output wavelet\r\n real(kind = dp), intent(in) :: sample !!sampling period (s)\r\n real(kind = dp), intent(in) :: fc, amp !!fc: characteristic frequency (inverse of pulse width)\r\n real(kind = dp), intent(in) :: tdiff !!time for wavelet delay\r\n real(kind = dp), intent(out) :: wavelet(ndata)\r\n\r\n integer :: i, tdiff_int\r\n real(kind = dp) :: time\r\n wavelet(1 : ndata) = 0.0_dp\r\n do i = 1, ndata\r\n time = sample * dble(i - 1)\r\n if(pi ** 2 * fc ** 2 * (time - 1.25_dp / fc) ** 2 .le. 30.0_dp) then\r\n wavelet(i) = (2.0_dp * pi ** 2 * fc ** 2 * (time - 1.25_dp / fc) ** 2 - 1.0_dp) &\r\n & * exp(-pi ** 2 * fc ** 2 * (time - 1.25_dp / fc) ** 2)\r\n endif\r\n wavelet(i) = wavelet(i) * (-amp)\r\n enddo\r\n tdiff_int = int(tdiff / sample)\r\n\r\n !!delay the wavelet\r\n do i = ndata, 1, -1\r\n if(i - tdiff_int .ge. 1) then\r\n wavelet(i) = wavelet(i - tdiff_int)\r\n else\r\n wavelet(i) = 0.0_dp\r\n endif\r\n enddo\r\n\r\n return\r\nend subroutine ricker_wavelet\r\n\r\nsubroutine smoothed_ramp_function(ndata, sample, fc, amp, tdiff, wavelet)\r\n use nrtype, only : dp\r\n implicit none\r\n\r\n !!Ramp function (shifted) Refer to the GMS wavepage for meaning of shifted\r\n !!f(t) = 2fc(1 - (tanh(4fc(t-1/fc))) ** 2)\r\n\r\n integer, intent(in) :: ndata !!number of data for output wavelet\r\n real(kind = dp), intent(in) :: sample !!sampling period (s)\r\n real(kind = dp), intent(in) :: fc, amp !!fc: characteristic frequency (inverse of pulse width)\r\n real(kind = dp), intent(in) :: tdiff !!time for wavelet delay\r\n real(kind = dp), intent(out) :: wavelet(ndata)\r\n\r\n integer :: i, tdiff_int\r\n real(kind = dp) :: time\r\n\r\n wavelet(1 : ndata) = 0.0_dp\r\n do i = 1, ndata\r\n time = sample * dble(i - 1)\r\n wavelet(i) = 2.0_dp * fc &\r\n & * (1.0_dp &\r\n & - ((exp(4.0_dp * fc * (time - 1.0_dp / fc)) - (exp(-4.0_dp * fc * (time - 1.0_dp / fc)))) &\r\n & / (exp(4.0_dp * fc * (time - 1.0_dp / fc)) + (exp(-4.0_dp * fc * (time - 1.0_dp / fc))))) ** 2)\r\n wavelet(i) = wavelet(i) * amp\r\n enddo\r\n\r\n !!delay the wavelet\r\n tdiff_int = int(tdiff / sample)\r\n do i = ndata, 1, -1\r\n if(i - tdiff_int .ge. 1) then\r\n wavelet(i) = wavelet(i - tdiff_int)\r\n else\r\n wavelet(i) = 0.0_dp\r\n endif\r\n enddo\r\n \r\n return\r\nend subroutine smoothed_ramp_function\r\n\r\n", "meta": {"hexsha": "e98139e2f0d366a3e2f6dfa418c9e9dd2291528a", "size": 7632, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "wavelet.f90", "max_stars_repo_name": "mogiso/AmplitudeSourceLocation", "max_stars_repo_head_hexsha": "ad00d36e0b14c0e1262b88c4bc2caf04e0570140", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2020-10-30T10:43:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-26T06:21:37.000Z", "max_issues_repo_path": "wavelet.f90", "max_issues_repo_name": "mogiso/AmplitudeSourceLocation", "max_issues_repo_head_hexsha": "ad00d36e0b14c0e1262b88c4bc2caf04e0570140", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wavelet.f90", "max_forks_repo_name": "mogiso/AmplitudeSourceLocation", "max_forks_repo_head_hexsha": "ad00d36e0b14c0e1262b88c4bc2caf04e0570140", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-18T12:00:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T12:00:20.000Z", "avg_line_length": 33.038961039, "max_line_length": 128, "alphanum_fraction": 0.5555555556, "num_tokens": 2687, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768557238083, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7805621423154369}} {"text": "!Name : Anantha Rao\n!Reg no: 20181044\n\n! Runge Kutta 4th order to solve set of first order differential equations\n\nPROGRAM rk4\n IMPLICIT none\n\n ! Declarations\n ! t : time (initial value given)\n ! x : position \n ! v : velocity (=dx/dt)\n ! h : step-size (=0.01)\n ! f : dx/dt \n ! g : dv/dt\n ! E : energy\n\n real*8:: t,x,v,twant, h, x1,x2,x3, x4, v1, v2, v3, v4, f, g, E\n integer:: niter, i\n\n t=0.0; x=0.0; v=0.3; h=0.01; twant=50; niter=int((twant-t)/h)\n\n open(unit=50, file=\"q3_rk4.dat\")\n ! E = (v**2)/2 - cox(x)\n E = (v**2 + x**2)/2 \n do i=1,niter\n write(50,*) dfloat(i)*h, x, v, E\n\n x1=h*f(t,x,v)\n v1=h*g(t,x,v)\n\n x2=h*f(t+0.5*h,x+0.5*x1, v)\n v2=h*g(t+0.5*h, x, v+0.5*v1)\n\n x3=h*f(t+0.5*h,x+0.5*x2, v)\n v3=h*g(t+0.5*h, x, v+0.5*v2)\n \n x4=h*f(t+h,x+x3, v)\n v4=h*g(t+h, x, v+v3)\n \n x=x+(x1+2.0*x2+2.0*x4+x4)*(1/6.0)\n v=v+(v1+ 2.0*v2+ 2.0*v3+ v4)*(1/6.0)\n ! E = (v**2)/2 - cox(x)\n E = (v**2 + x*2)/2\n\n end do\nend program\n\n\n\n!define your function here\n real*8 function f(t,x,v)\n real*8:: t,x,v\n f=v\nend function\n\n!define your function here\n real*8 function g(t,x,v)\n real*8:: t,x,v, k,m\n k=1; m=1\n ! g = -cos(x)\n g=-x\nend function\n\n", "meta": {"hexsha": "f6bfe699738082bc6cb1ba55ae99037bac9b56bd", "size": 1307, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/assgn05_solns/Assgn05_Solutions/Assgn05_solutions_Q3/q3_rk4.f90", "max_stars_repo_name": "Anantha-Rao12/ComPhys", "max_stars_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Solutions/assgn05_solns/Assgn05_Solutions/Assgn05_solutions_Q3/q3_rk4.f90", "max_issues_repo_name": "Anantha-Rao12/ComPhys", "max_issues_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Solutions/assgn05_solns/Assgn05_Solutions/Assgn05_solutions_Q3/q3_rk4.f90", "max_forks_repo_name": "Anantha-Rao12/ComPhys", "max_forks_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.1076923077, "max_line_length": 74, "alphanum_fraction": 0.4774292272, "num_tokens": 576, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.7804826850188121}} {"text": "program main \r\n implicit none \r\n real :: refraction\r\n\treal :: deg2rad\r\n\treal :: rad2deg\r\n real :: n1 = 1.0\r\n real :: n2 = 1.7\r\n real :: theta1\r\n real :: theta2\r\n write (*,'(A3,1X,A3,1X,A7,A7)') 'n1', 'n2', 'theta1', 'theta2'\r\n write (*,'(A)') '====================='\r\n do theta1 = 0, 90, 15\r\n write (*,'(F3.1,1X,F3.1,1X,F6.2,1X,F6.2)') n1, n2, theta1, rad2deg(refraction(deg2rad(theta1), n1, n2))\r\n end do\r\n write (*,'(A)') '====================='\r\n do theta1 = 0, 90, 1\r\n theta2 = rad2deg(refraction(deg2rad(theta1), n2, n1))\r\n if (isnan(theta2)) then\r\n write (*,'(F3.1,1X,F3.1,1X,F6.2,1X,A)') n2, n1, theta1, '全反射'\r\n exit\r\n end if\r\n if (theta2 > 60) then\r\n write (*,'(F3.1,1X,F3.1,1X,F6.2,1X,F6.2)') n2, n1, theta1, theta2\r\n end if\r\n end do\r\n write (*,'(A)') '====================='\r\n n2 = 1.5\r\n do while (n2 < 2.0)\r\n do theta1 = 0, 90, 1\r\n theta2 = rad2deg(refraction(deg2rad(theta1), n2, n1))\r\n if (isnan(theta2)) then\r\n write (*,'(F3.1,1X,F3.1,1X,F6.2,1X,A)') n2, n1, theta1, '全反射'\r\n exit\r\n end if\r\n if (theta2 > 60) then\r\n write (*,'(F3.1,1X,F3.1,1X,F6.2,1X,F6.2)') n2, n1, theta1, theta2\r\n end if\r\n end do\r\n write (*,'(A)') '====================='\r\n n2 = n2 + 0.1\r\n end do\r\nend program main \r\n \r\nfunction refraction(theta1, n1, n2) \r\n implicit none \r\n real :: theta1\r\n real :: n1\r\n real :: n2\r\n real :: refraction \r\n \r\n refraction = asin(sin(theta1) * n1 / n2)\r\n return \r\nend function \r\n\r\nfunction rad2deg(rad)\r\n implicit none\r\n\treal,parameter :: pi = 3.14159265358979\r\n\treal :: rad\r\n\treal :: rad2deg\r\n\r\n rad2deg = rad / pi * 180.0\r\n return\r\nend function\r\n\r\nfunction deg2rad(deg)\r\n implicit none\r\n\treal,parameter :: pi = 3.14159265358979\r\n\treal :: deg\r\n\treal :: deg2rad\r\n\r\n deg2rad = deg / 180.0 * pi\r\n return\r\nend function\r\n", "meta": {"hexsha": "fd8b8217b72d54e7afde2810efd6a5b53535d796", "size": 2029, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "homework/chapter5/5_5/main.f90", "max_stars_repo_name": "hopeful0/fortran-study", "max_stars_repo_head_hexsha": "7bd50580436e747f428cefeda2ba595893867503", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "homework/chapter5/5_5/main.f90", "max_issues_repo_name": "hopeful0/fortran-study", "max_issues_repo_head_hexsha": "7bd50580436e747f428cefeda2ba595893867503", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "homework/chapter5/5_5/main.f90", "max_forks_repo_name": "hopeful0/fortran-study", "max_forks_repo_head_hexsha": "7bd50580436e747f428cefeda2ba595893867503", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.4189189189, "max_line_length": 112, "alphanum_fraction": 0.4775751602, "num_tokens": 757, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966671870767, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7804329137720937}} {"text": "PROGRAM pi_integration_serial\n IMPLICIT NONE\n INTEGER :: i\n REAL(kind=8) :: x, sum, step, pi\n REAL(kind=8) :: t_start, t_end\n\n INTEGER(kind=8), PARAMETER :: num_steps = 500000000\n\n sum=0.0\n step = 1.0/num_steps\n\n CALL cpu_time(t_start)\n\n DO i=0,num_steps\n x = (i+0.5)*step\n sum = sum + 4.0/(1.0+x*x)\n END DO\n\n pi = step * sum\n \n CALL cpu_time(t_end)\n\n WRITE(*,*) \"Value of pi = \",pi\n WRITE(*,*) \"Expended wall clock time = \",t_end-t_start\n \nEND PROGRAM pi_integration_serial\n", "meta": {"hexsha": "a90e84d1e7e9dc87eeb3a2ca86cc1761bc50b12a", "size": 499, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pi_integration/src/pi_integration_serial.f90", "max_stars_repo_name": "samjcus/pragma_pragma_pragma", "max_stars_repo_head_hexsha": "643d8440bde2ace2b8f940d783ca95e21d1c9f78", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pi_integration/src/pi_integration_serial.f90", "max_issues_repo_name": "samjcus/pragma_pragma_pragma", "max_issues_repo_head_hexsha": "643d8440bde2ace2b8f940d783ca95e21d1c9f78", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2016-02-25T23:12:14.000Z", "max_issues_repo_issues_event_max_datetime": "2016-02-26T00:17:58.000Z", "max_forks_repo_path": "pi_integration/src/pi_integration_serial.f90", "max_forks_repo_name": "samjcus/pragma_pragma_pragma", "max_forks_repo_head_hexsha": "643d8440bde2ace2b8f940d783ca95e21d1c9f78", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.4814814815, "max_line_length": 56, "alphanum_fraction": 0.6312625251, "num_tokens": 176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966762263737, "lm_q2_score": 0.8244619177503206, "lm_q1q2_score": 0.7804329110176754}} {"text": "!##############################################################################\n!# ****************************************************************************\n!# mprimitives \n!# ****************************************************************************\n!#\n!# \n!# This module contains a set of low-level mathematic functions without\n!# a big background of finite elements or similar, like linear transformation,\n!# parabolic profile, etc.\n!#\n!# The routines here are usually declared as PURE as they should not have\n!# any side effects!\n!#\n!# The following routines can be found here:\n!#\n!# 1.) mprim_getParabolicProfile\n!# -> Calculates the value of a parabolic profile along a line.\n!#\n!# 2.) mprim_invertMatrix\n!# -> Invert a full matrix\n!#\n!# 3.) mprim_kronecker\n!# -> Compute Kronecker delta symbol\n!#\n!# 4.) mprim_invert2x2MatrixDirect\n!# -> Inverts a 2x2 matrix directly without pivoting.\n!#\n!# 5.) mprim_invert3x3MatrixDirect\n!# -> Inverts a 3x3 matrix directly without pivoting.\n!#\n!# 6.) mprim_invert4x4MatrixDirect\n!# -> Inverts a 4x4 matrix directly without pivoting.\n!#\n!# 7.) mprim_invert5x5MatrixDirect\n!# -> Inverts a 5x5 matrix directly without pivoting.\n!#\n!# 8.) mprim_invert6x6MatrixDirect\n!# -> Inverts a 6x6 matrix directly without pivoting.\n!#\n!# 9.) mprim_invertMatrixPivot\n!# -> Inverts a n x n matrix directly with pivoting.\n!#\n!# 10.) mprim_signum\n!# -> Signum function\n!#\n!# 11.) mprim_linearRescale\n!# -> Scales a coordinate x linearly from the interval [a,b] to the\n!# interval [c,d]\n!#\n!# 12.) mprim_quadraticInterpolation\n!# -> Evaluate the quadratic interpolation polynomial of three values.\n!#\n!# 13.) mprim_SVD_factorise\n!# -> Compute the factorisation for a singular value decomposition\n!#\n!# 14.) mprim_SVD_backsubst\n!# -> Perform back substitution for a singular value decomposition\n!#\n!# 15.) mprim_stdDeviation\n!# -> Calculates the standard deviation of a vector\n!#\n!# 16.) mprim_meanDeviation\n!# -> Calculates the mean deviation of a vector\n!#\n!# 17.) mprim_meanValue\n!# -> Calculates the mean value of a vector\n!#\n!# 18.) mprim_degToRad\n!# -> Converts DEG to RAD\n!#\n!# 19.) mprim_radToDeg\n!# -> Converts RAD to DEG\n!#\n!# 20.) mprim_solve2x2Direct\n!# -> Solves a 2x2 matrix directly without pivoting.\n!#\n!# 21.) mprim_solve3x3Direct\n!# -> Solves a 3x3 matrix directly without pivoting.\n!#\n!# 22.) mprim_solve2x2BandDiag\n!# -> Solves a 2x2 block system containing only diagonal bands\n!#\n!# 23.) mprim_minmod\n!# -> Computes the minmod function for two and three parameters\n!#\n!# 24.) mprim_softmax\n!# -> Computes the soft-maximum function for two parameter\n!#\n!# 25.) mprim_softmin\n!# -> Computes the soft-minimum function for two parameter\n!#\n!# 26.) mprim_leastSquaresMin\n!# -> Solves a least-squares minimisation problem\n!#\n!# 27.) mprim_transposeMatrix\n!# -> Computes the transpose of a matrix\n!#\n!# 28.) mprim_horner\n!# -> Evaluates a polynomial using the horner scheme.\n!#\n!# 29.) mprim_hornerd1\n!# -> Evaluates the derivative of a polynomial using the horner scheme.\n!#\n!# 30.) mprim_hornerd2\n!# -> Evaluates the 2nd derivative of a polynomial using the horner scheme.\n!#\n!# 31.) mprim_polarToCartesian\n!# -> Converts polar coordinates to cartesian coordinates\n!#\n!# 32.) mprim_cartesianToPolar\n!# -> Converts cartesian coordinates to polar coordinates\n!# \n!##############################################################################\n\nmodule mprimitives\n\n!$ use omp_lib\n use fsystem\n use genoutput\n use linearalgebra\n\n implicit none\n\n private\n\n interface mprim_signum\n module procedure mprim_signumDP\n module procedure mprim_signumSP\n module procedure mprim_signumInt\n end interface\n\n public :: mprim_signum\n\n interface mprim_SVD_factorise\n module procedure mprim_SVD_factoriseDP\n module procedure mprim_SVD_factoriseSP\n end interface mprim_SVD_factorise\n\n public :: mprim_SVD_factorise\n public :: mprim_SVD_factoriseDP\n public :: mprim_SVD_factoriseSP\n\n interface mprim_SVD_backsubst\n module procedure mprim_SVD_backsubstDP\n module procedure mprim_SVD_backsubstSP\n end interface\n\n public :: mprim_SVD_backsubst\n public :: mprim_SVD_backsubstDP\n public :: mprim_SVD_backsubstSP\n\n ! Alternative name for backward compatibility\n interface mprim_kronecker\n module procedure kronecker\n end interface\n\n public :: mprim_kronecker\n\n interface mprim_invertMatrix\n module procedure mprim_invertMatrixDP\n module procedure mprim_invertMatrixSP\n end interface\n\n public :: mprim_invertMatrix\n public :: mprim_invertMatrixDP\n public :: mprim_invertMatrixSP\n \n interface mprim_invertMatrixPivot\n module procedure mprim_invertMatrixPivotDP\n module procedure mprim_invertMatrixPivotSP\n end interface\n\n public :: mprim_invertMatrixPivot\n public :: mprim_invertMatrixPivotDP\n public :: mprim_invertMatrixPivotSP\n \n interface mprim_invert2x2MatrixDirect\n module procedure mprim_invert2x2MatrixDirectDP\n module procedure mprim_invert2x2MatrixDirectSP\n end interface\n\n public :: mprim_invert2x2MatrixDirect\n public :: mprim_invert2x2MatrixDirectDP\n public :: mprim_invert2x2MatrixDirectSP\n\n interface mprim_invert3x3MatrixDirect\n module procedure mprim_invert3x3MatrixDirectDP\n module procedure mprim_invert3x3MatrixDirectSP\n end interface\n\n public :: mprim_invert3x3MatrixDirect\n public :: mprim_invert3x3MatrixDirectDP\n public :: mprim_invert3x3MatrixDirectSP\n\n interface mprim_invert4x4MatrixDirect\n module procedure mprim_invert4x4MatrixDirectDP\n module procedure mprim_invert4x4MatrixDirectSP\n end interface\n \n public :: mprim_invert4x4MatrixDirect\n public :: mprim_invert4x4MatrixDirectDP\n public :: mprim_invert4x4MatrixDirectSP\n\n interface mprim_invert5x5MatrixDirect\n module procedure mprim_invert5x5MatrixDirectDP\n module procedure mprim_invert5x5MatrixDirectSP\n end interface\n\n public :: mprim_invert5x5MatrixDirect\n public :: mprim_invert5x5MatrixDirectDP\n public :: mprim_invert5x5MatrixDirectSP\n\n interface mprim_invert6x6MatrixDirect\n module procedure mprim_invert6x6MatrixDirectDP\n module procedure mprim_invert6x6MatrixDirectSP\n end interface\n\n public :: mprim_invert6x6MatrixDirect\n public :: mprim_invert6x6MatrixDirectDP\n public :: mprim_invert6x6MatrixDirectSP\n\n interface mprim_linearRescale\n module procedure mprim_linearRescaleDP\n module procedure mprim_linearRescaleSP\n end interface mprim_linearRescale\n\n public :: mprim_linearRescale\n\n interface mprim_quadraticInterpolation\n module procedure mprim_quadraticInterpolationDP\n module procedure mprim_quadraticInterpolationSP\n end interface mprim_quadraticInterpolation\n\n public :: mprim_quadraticInterpolation \n\n interface mprim_stdDeviation\n module procedure mprim_stdDeviationDP\n module procedure mprim_stdDeviationSP\n end interface\n\n public :: mprim_stdDeviation\n \n interface mprim_meanDeviation\n module procedure mprim_meanDeviationDP\n module procedure mprim_meanDeviationSP\n end interface\n\n public :: mprim_meanDeviation\n\n interface mprim_meanValue\n module procedure mprim_meanValueDP\n module procedure mprim_meanValueSP\n end interface\n\n public :: mprim_meanValue\n\n interface mprim_solve2x2Direct\n module procedure mprim_solve2x2DirectDP\n module procedure mprim_solve2x2DirectSP\n end interface\n\n public :: mprim_solve2x2Direct\n\n interface mprim_solve3x3Direct\n module procedure mprim_solve3x3DirectDP\n module procedure mprim_solve3x3DirectSP\n end interface\n\n public :: mprim_solve3x3Direct\n\n interface mprim_solve2x2BandDiag\n module procedure mprim_solve2x2BandDiagDP\n module procedure mprim_solve2x2BandDiagSP\n end interface\n\n public :: mprim_solve2x2BandDiag\n\n interface mprim_minmod\n module procedure mprim_minmod2DP\n module procedure mprim_minmod2SP\n module procedure mprim_minmod3DP\n module procedure mprim_minmod3SP\n end interface\n\n public :: mprim_minmod\n\n interface mprim_softmax\n module procedure mprim_softmax2DP\n module procedure mprim_softmax3DP\n module procedure mprim_softmax2SP\n module procedure mprim_softmax3SP\n end interface\n\n public :: mprim_softmax\n\n interface mprim_softmin\n module procedure mprim_softmin2DP\n module procedure mprim_softmin3DP\n module procedure mprim_softmin2SP\n module procedure mprim_softmin3SP\n end interface\n\n public :: mprim_softmin\n\n interface mprim_leastSquaresMin\n module procedure mprim_leastSquaresMinDP\n module procedure mprim_leastSquaresMinSP\n end interface mprim_leastSquaresMin\n\n public :: mprim_leastSquaresMin\n public :: mprim_leastSquaresMinDP\n public :: mprim_leastSquaresMinSP\n\n interface mprim_transposeMatrix\n module procedure mprim_transposeMatrix1DP\n module procedure mprim_transposeMatrix1SP\n module procedure mprim_transposeMatrix2DP\n module procedure mprim_transposeMatrix2SP\n end interface mprim_transposeMatrix\n\n public :: mprim_transposeMatrix\n\n public :: mprim_getParabolicProfile\n public :: mprim_degToRad\n public :: mprim_radToDeg\n \n public :: mprim_horner\n public :: mprim_hornerd1\n public :: mprim_hornerd2\n\n interface mprim_horner\n module procedure mprim_hornerSP\n module procedure mprim_hornerDP\n end interface\n\n interface mprim_hornerd1\n module procedure mprim_hornerd1SP\n module procedure mprim_hornerd1DP\n end interface\n\n interface mprim_hornerd2\n module procedure mprim_hornerd2SP\n module procedure mprim_hornerd2DP\n end interface\n \n public :: mprim_polarToCartesian\n public :: mprim_cartesianToPolar\n \n interface mprim_polarToCartesian\n module procedure mprim_polarToCartesian2D\n module procedure mprim_polarToCartesian3D\n end interface\n \n interface mprim_cartesianToPolar\n module procedure mprim_cartesianToPolar2D\n module procedure mprim_cartesianToPolar3D\n end interface\n\ncontains\n\n ! ***************************************************************************\n\n!\n\n elemental real(DP) function mprim_getParabolicProfile (dpos,dlength,dmaxvalue)\n\n!\n ! Calculates the value of a parabolic profile along a line.\n ! dpos is a parameter value along a line of length dlength. The return value\n ! is the value of the profile and has its maximum dmax at position 0.5.\n!\n\n!\n\n ! Position on the line segment where to calculate the velocity\n real(DP), intent(in) :: dpos\n\n ! Length of the line segment\n real(DP), intent(in) :: dlength\n\n ! Maximum value of the profile\n real(DP), intent(in) :: dmaxvalue\n\n!\n\n!\n ! The value of the parabolic profile at position $dpos \\in [0,dmax]$.\n!\n!\n\n ! Result: Value of the parbolic profile on position dpos on the line segment\n mprim_getParabolicProfile = 4.0_DP*dmaxvalue*dpos*(dlength-dpos)/(dlength*dlength)\n\n end function\n\n ! ***************************************************************************\n\n!\n\n elemental real(DP) function mprim_signumDP (dval)\n\n!\n ! Signum function\n!\n\n!\n ! Value to be checked\n real(DP), intent(in) :: dval\n!\n\n!\n ! The value of the parabolic profile at position $dpos \\in [0,dmax]$.\n!\n!\n\n ! Result: Value of the parbolic profile on position dpos on the line segment\n if (dval .lt. 0.0_DP) then\n mprim_signumDP = -1.0_DP\n else if (dval .gt. 0.0_DP) then\n mprim_signumDP = 1.0_DP\n else\n mprim_signumDP = 0.0_DP\n end if\n\n end function\n\n ! ***************************************************************************\n\n!\n\n elemental real(SP) function mprim_signumSP (fval)\n\n!\n ! Signum function.\n!\n\n!\n ! Value to be checked\n real(SP), intent(in) :: fval\n!\n\n!\n ! The value of the parabolic profile at position $dpos \\in [0,dmax]$.\n!\n!\n\n ! Result: Value of the parbolic profile on position dpos on the line segment\n if (fval .lt. 0.0_SP) then\n mprim_signumSP = -1.0_SP\n else if (fval .gt. 0.0_SP) then\n mprim_signumSP = 1.0_SP\n else\n mprim_signumSP = 0.0_SP\n end if\n\n end function\n\n ! ***************************************************************************\n\n!\n\n elemental integer function mprim_signumInt (ival)\n\n!\n ! Signum function.\n!\n\n!\n ! Value to be checked\n integer(I32), intent(in) :: ival\n!\n\n!\n ! The value of the parabolic profile at position $dpos \\in [0,dmax]$.\n!\n!\n\n ! Result: Value of the parbolic profile on position dpos on the line segment\n select case (ival)\n case (:-1)\n mprim_signumInt = -1\n case (0)\n mprim_signumInt = 0\n case default\n mprim_signumInt = 1\n end select\n\n end function\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_invertMatrixDP(Da,Df,Dx,ndim,ipar,bsuccess)\n\n!\n ! This subroutine performs the direct inversion of a NxN system.\n !\n ! If the parameter ipar=0, then only factorisation of matrix A is performed.\n ! For ipar=1, the vector x is calculated using the factorised matrix A.\n ! For ipar=2, LAPACK routine DGESV is used to solve the dense linear system Ax=f.\n ! In addition, for NDIM=2,3,4 explicit formulas are employed to replace the\n ! more expensive LAPACK routine.\n!\n\n!\n ! dimension of the matrix\n integer, intent(in) :: ndim\n\n ! source right-hand side vector\n real(DP), dimension(ndim), intent(in) :: Df\n\n ! What to do?\n ! IPAR = 0 : invert matrix by means of Gaussian elimination with\n ! full pivoting and return the inverted matrix inv(A)\n ! IPAR = 1 : apply inverted matrix to the right-hand side vector\n ! and return x = inv(A)*f\n ! IPAR = 2 : invert matrix and apply it to the right-hand side\n ! vector. Return x = inv(A)*f\n integer, intent(in) :: ipar\n!\n\n!\n ! source square matrix to be inverted\n real(DP), dimension(ndim,ndim), intent(inout) :: Da\n!\n\n!\n ! destination vector containing inverted matrix times right-hand\n ! side vector\n real(DP), dimension(ndim), intent(out) :: Dx\n\n ! TRUE, if successful. FALSE if the system is indefinite.\n ! If FALSE, Db is undefined.\n logical, intent(out) :: bsuccess\n!\n\n!\n\n ! local variables\n real(DP), dimension(ndim,ndim) :: Db\n integer, dimension(ndim) :: Ipiv\n integer, dimension(ndim) :: Kindx,Kindy\n\n real(DP) :: dpivot,daux\n integer :: idim1,idim2,ix,iy,indx,indy,info\n\n interface\n pure subroutine DGESV( N, NRHS, A, LDA, IPIV, B, LDB, INFO )\n use fsystem\n integer, intent(in) :: N,LDA,LDB,NRHS\n integer, intent(inout) :: INFO\n integer, dimension(*), intent(inout) :: IPIV\n real(dp), dimension( LDA, * ), intent(inout) :: A\n real(dp), dimension( LDB, * ), intent(inout) :: B\n end subroutine\n end interface\n\n bsuccess = .false.\n\n select case (ipar)\n case (0)\n ! Perform factorisation of matrix Da\n\n ! Initialization\n Kindx=0; Kindy=0\n\n do idim1=1,ndim\n\n ! Determine pivotal element\n dpivot=0\n\n do iy=1,ndim\n if (Kindy(iy) /= 0) cycle\n\n do ix=1,ndim\n if (Kindx(ix) /= 0) cycle\n\n if (abs(Da(ix,iy)) .le. abs(dpivot)) cycle\n dpivot=Da(ix,iy); indx=ix; indy=iy\n end do\n end do\n\n ! Return if pivotal element is zero\n if (abs(dpivot) .le. 0._DP) return\n\n Kindx(indx)=indy; Kindy(indy)=indx; Da(indx,indy)=1._DP&\n &/dpivot\n\n do idim2=1,ndim\n if (idim2 == indy) cycle\n Da(1:indx-1,idim2)=Da(1:indx-1,idim2)-Da(1:indx-1, &\n & indy)*Da(indx,idim2)/dpivot\n Da(indx+1:ndim,idim2)=Da(indx+1:ndim,idim2)-Da(indx+1:ndim&\n &,indy)*Da(indx,idim2)/dpivot\n end do\n\n do ix=1,ndim\n if (ix /= indx) Da(ix,indy)=Da(ix,indy)/dpivot\n end do\n\n do iy=1,ndim\n if (iy /= indy) Da(indx,iy)=-Da(indx,iy)/dpivot\n end do\n end do\n\n do ix=1,ndim\n if (Kindx(ix) == ix) cycle\n\n do iy=1,ndim\n if (Kindx(iy) == ix) exit\n end do\n\n do idim1=1,ndim\n daux=Da(ix,idim1)\n Da(ix,idim1)=Da(iy,idim1)\n Da(iy,idim1)=daux\n end do\n\n Kindx(iy)=Kindx(ix); Kindx(ix)=ix\n end do\n\n do ix=1,ndim\n if (Kindy(ix) == ix) cycle\n\n do iy=1,ndim\n if (Kindy(iy) == ix) exit\n end do\n\n do idim1=1,ndim\n daux=Da(idim1,ix)\n Da(idim1,ix)=Da(idim1,iy)\n Da(idim1,iy)=daux\n end do\n\n Kindy(iy)=Kindy(ix); Kindy(ix)=ix\n end do\n\n\n case (1)\n ! Perform inversion of Da to solve the system Da * Dx = Df\n do idim1=1,ndim\n Dx(idim1)=0\n do idim2=1,ndim\n Dx(idim1)=Dx(idim1)+Da(idim1,idim2)*Df(idim2)\n end do\n end do\n\n case (2)\n ! Solve the dense linear system Ax=f calling LAPACK routine\n\n select case(ndim)\n case (1)\n if (Da(1,1) .ne. 0.0_DP) then\n Dx(1) = Df(1) / Da(1,1)\n else\n return\n end if\n\n case (2)\n call mprim_invert2x2MatrixDirectDP(Da,Db,bsuccess)\n if (.not. bsuccess) return\n ! Dx=matmul(Db,Df)\n Dx(1) = Db(1,1)*Df(1) + Db(1,2)*Df(2)\n Dx(2) = Db(2,1)*Df(1) + Db(2,2)*Df(2)\n\n case (3)\n call mprim_invert3x3MatrixDirectDP(Da,Db, bsuccess)\n if (.not. bsuccess) return\n ! Dx=matmul(Db,Df)\n Dx(1) = Db(1,1)*Df(1) + Db(1,2)*Df(2) + Db(1,3)*Df(3)\n Dx(2) = Db(2,1)*Df(1) + Db(2,2)*Df(2) + Db(2,3)*Df(3)\n Dx(3) = Db(3,1)*Df(1) + Db(3,2)*Df(2) + Db(3,3)*Df(3)\n\n case (4)\n call mprim_invert4x4MatrixDirectDP(Da,Db,bsuccess)\n if (.not. bsuccess) return\n ! Dx=matmul(Db,Df)\n Dx(1) = Db(1,1)*Df(1) + Db(1,2)*Df(2) &\n + Db(1,3)*Df(3) + Db(1,4)*Df(4)\n Dx(2) = Db(2,1)*Df(1) + Db(2,2)*Df(2) &\n + Db(2,3)*Df(3) + Db(2,4)*Df(4)\n Dx(3) = Db(3,1)*Df(1) + Db(3,2)*Df(2) &\n + Db(3,3)*Df(3) + Db(3,4)*Df(4)\n Dx(4) = Db(4,1)*Df(1) + Db(4,2)*Df(2) &\n + Db(4,3)*Df(3) + Db(4,4)*Df(4)\n\n case (5)\n call mprim_invert5x5MatrixDirectDP(Da,Db,bsuccess)\n if (.not. bsuccess) return\n ! Dx=matmul(Db,Df)\n Dx(1) = Db(1,1)*Df(1) + Db(1,2)*Df(2) &\n + Db(1,3)*Df(3) + Db(1,4)*Df(4) &\n + Db(1,5)*Df(5)\n Dx(2) = Db(2,1)*Df(1) + Db(2,2)*Df(2) &\n + Db(2,3)*Df(3) + Db(2,4)*Df(4) &\n + Db(2,5)*Df(5)\n Dx(3) = Db(3,1)*Df(1) + Db(3,2)*Df(2) &\n + Db(3,3)*Df(3) + Db(3,4)*Df(4) &\n + Db(3,5)*Df(5)\n Dx(4) = Db(4,1)*Df(1) + Db(4,2)*Df(2) &\n + Db(4,3)*Df(3) + Db(4,4)*Df(4) &\n + Db(4,5)*Df(5)\n Dx(5) = Db(5,1)*Df(1) + Db(5,2)*Df(2) &\n + Db(5,3)*Df(3) + Db(5,4)*Df(4) &\n + Db(5,5)*Df(5)\n\n case (6)\n call mprim_invert6x6MatrixDirectDP(Da,Db,bsuccess)\n if (.not. bsuccess) return\n ! Dx=matmul(Db,Df)\n Dx(1) = Db(1,1)*Df(1) + Db(1,2)*Df(2) &\n + Db(1,3)*Df(3) + Db(1,4)*Df(4) &\n + Db(1,5)*Df(5) + Db(1,6)*Df(6)\n Dx(2) = Db(2,1)*Df(1) + Db(2,2)*Df(2) &\n + Db(2,3)*Df(3) + Db(2,4)*Df(4) &\n + Db(2,5)*Df(5) + Db(2,6)*Df(6)\n Dx(3) = Db(3,1)*Df(1) + Db(3,2)*Df(2) &\n + Db(3,3)*Df(3) + Db(3,4)*Df(4) &\n + Db(3,5)*Df(5) + Db(3,6)*Df(6)\n Dx(4) = Db(4,1)*Df(1) + Db(4,2)*Df(2) &\n + Db(4,3)*Df(3) + Db(4,4)*Df(4) &\n + Db(4,5)*Df(5) + Db(4,6)*Df(6)\n Dx(5) = Db(5,1)*Df(1) + Db(5,2)*Df(2) &\n + Db(5,3)*Df(3) + Db(5,4)*Df(4) &\n + Db(5,5)*Df(5) + Db(5,6)*Df(6)\n Dx(6) = Db(6,1)*Df(1) + Db(6,2)*Df(2) &\n + Db(6,3)*Df(3) + Db(6,4)*Df(4) &\n + Db(6,5)*Df(5) + Db(6,6)*Df(6)\n\n case default\n ! Use LAPACK routine for general NxN system, where N > 6\n Ipiv=0; Dx=Df\n call DGESV(ndim,1,Da,ndim,Ipiv,Dx,ndim,info)\n\n if (info .ne. 0) return\n\n end select\n\n end select\n\n bsuccess = .true.\n\n end subroutine mprim_invertMatrixDP\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_invertMatrixSP(Fa,Ff,Fx,ndim,ipar,bsuccess)\n\n!\n ! This subroutine performs the direct inversion of a NxN system.\n !\n ! If the parameter ipar=0, then only factorisation of matrix A is performed.\n ! For ipar=1, the vector x is calculated using the factorised matrix A.\n ! For ipar=2, LAPACK routine DGESV is used to solve the dense linear system Ax=f.\n ! In addition, for NDIM=2,3,4 explicit formulas are employed to replace the\n ! more expensive LAPACK routine.\n!\n\n!\n ! dimension of the matrix\n integer, intent(in) :: ndim\n\n ! source right-hand side vector\n real(SP), dimension(ndim), intent(in) :: Ff\n\n ! What to do?\n ! IPAR = 0 : invert matrix by means of Gaussian elimination with\n ! full pivoting and return the inverted matrix inv(A)\n ! IPAR = 1 : apply inverted matrix to the right-hand side vector\n ! and return x = inv(A)*f\n ! IPAR = 2 : invert matrix and apply it to the right-hand side\n ! vector. Return x = inv(A)*f\n integer, intent(in) :: ipar\n!\n\n!\n ! source square matrix to be inverted\n real(SP), dimension(ndim,ndim), intent(inout) :: Fa\n!\n\n!\n ! destination vector containing inverted matrix times right-hand\n ! side vector\n real(SP), dimension(ndim), intent(out) :: Fx\n\n ! TRUE, if successful. FALSE if the system is indefinite.\n ! If FALSE, Fb is undefined.\n logical, intent(out) :: bsuccess\n!\n\n!\n\n ! local variables\n real(SP), dimension(ndim,ndim) :: Fb\n integer, dimension(ndim) :: Ipiv\n integer, dimension(ndim) :: Kindx,Kindy\n\n real(SP) :: fpivot,faux\n integer :: idim1,idim2,ix,iy,indx,indy,info\n\n interface\n pure subroutine SGESV( N, NRHS, A, LDA, IPIV, B, LDB, INFO )\n use fsystem\n integer, intent(in) :: N,LDA,LDB,NRHS\n integer, intent(inout) :: INFO\n integer, dimension(*), intent(inout) :: IPIV\n real(sp), dimension( LDA, * ), intent(inout) :: A\n real(sp), dimension( LDB, * ), intent(inout) :: B\n end subroutine\n end interface\n\n bsuccess = .false.\n\n select case (ipar)\n case (0)\n ! Perform factorisation of matrix Fa\n\n ! Initialization\n Kindx=0; Kindy=0\n\n do idim1=1,ndim\n\n ! Determine pivotal element\n fpivot=0\n\n do iy=1,ndim\n if (Kindy(iy) /= 0) cycle\n\n do ix=1,ndim\n if (Kindx(ix) /= 0) cycle\n\n if (abs(Fa(ix,iy)) .le. abs(fpivot)) cycle\n fpivot=Fa(ix,iy); indx=ix; indy=iy\n end do\n end do\n\n ! Return if pivotal element is zero\n if (abs(fpivot) .le. 0._SP) return\n\n Kindx(indx)=indy; Kindy(indy)=indx; Fa(indx,indy)=1._SP&\n &/fpivot\n\n do idim2=1,ndim\n if (idim2 == indy) cycle\n Fa(1:indx-1,idim2)=Fa(1:indx-1,idim2)-Fa(1:indx-1, &\n & indy)*Fa(indx,idim2)/fpivot\n Fa(indx+1:ndim,idim2)=Fa(indx+1:ndim,idim2)-Fa(indx+1:ndim&\n &,indy)*Fa(indx,idim2)/fpivot\n end do\n\n do ix=1,ndim\n if (ix /= indx) Fa(ix,indy)=Fa(ix,indy)/fpivot\n end do\n\n do iy=1,ndim\n if (iy /= indy) Fa(indx,iy)=-Fa(indx,iy)/fpivot\n end do\n end do\n\n do ix=1,ndim\n if (Kindx(ix) == ix) cycle\n\n do iy=1,ndim\n if (Kindx(iy) == ix) exit\n end do\n\n do idim1=1,ndim\n faux=Fa(ix,idim1)\n Fa(ix,idim1)=Fa(iy,idim1)\n Fa(iy,idim1)=faux\n end do\n\n Kindx(iy)=Kindx(ix); Kindx(ix)=ix\n end do\n\n do ix=1,ndim\n if (Kindy(ix) == ix) cycle\n\n do iy=1,ndim\n if (Kindy(iy) == ix) exit\n end do\n\n do idim1=1,ndim\n faux=Fa(idim1,ix)\n Fa(idim1,ix)=Fa(idim1,iy)\n Fa(idim1,iy)=faux\n end do\n\n Kindy(iy)=Kindy(ix); Kindy(ix)=ix\n end do\n\n\n case (1)\n ! Perform inversion of Fa to solve the system Fa * Fx = Ff\n do idim1=1,ndim\n Fx(idim1)=0\n do idim2=1,ndim\n Fx(idim1)=Fx(idim1)+Fa(idim1,idim2)*Ff(idim2)\n end do\n end do\n\n case (2)\n ! Solve the dense linear system Ax=f calling LAPACK routine\n\n select case(ndim)\n case (1)\n if (Fa(1,1) .ne. 0.0_SP) then\n Fx(1) = Ff(1) / Fa(1,1)\n else\n return\n end if\n\n case (2)\n call mprim_invert2x2MatrixDirectSP(Fa,Fb,bsuccess)\n if (.not. bsuccess) return\n ! Fx=matmul(Fb,Ff)\n Fx(1) = Fb(1,1)*Ff(1) + Fb(1,2)*Ff(2)\n Fx(2) = Fb(2,1)*Ff(1) + Fb(2,2)*Ff(2)\n\n case (3)\n call mprim_invert3x3MatrixDirectSP(Fa,Fb, bsuccess)\n if (.not. bsuccess) return\n ! Fx=matmul(Fb,Ff)\n Fx(1) = Fb(1,1)*Ff(1) + Fb(1,2)*Ff(2) + Fb(1,3)*Ff(3)\n Fx(2) = Fb(2,1)*Ff(1) + Fb(2,2)*Ff(2) + Fb(2,3)*Ff(3)\n Fx(3) = Fb(3,1)*Ff(1) + Fb(3,2)*Ff(2) + Fb(3,3)*Ff(3)\n\n case (4)\n call mprim_invert4x4MatrixDirectSP(Fa,Fb,bsuccess)\n if (.not. bsuccess) return\n ! Fx=matmul(Fb,Ff)\n Fx(1) = Fb(1,1)*Ff(1) + Fb(1,2)*Ff(2) &\n + Fb(1,3)*Ff(3) + Fb(1,4)*Ff(4)\n Fx(2) = Fb(2,1)*Ff(1) + Fb(2,2)*Ff(2) &\n + Fb(2,3)*Ff(3) + Fb(2,4)*Ff(4)\n Fx(3) = Fb(3,1)*Ff(1) + Fb(3,2)*Ff(2) &\n + Fb(3,3)*Ff(3) + Fb(3,4)*Ff(4)\n Fx(4) = Fb(4,1)*Ff(1) + Fb(4,2)*Ff(2) &\n + Fb(4,3)*Ff(3) + Fb(4,4)*Ff(4)\n\n case (5)\n call mprim_invert5x5MatrixDirectSP(Fa,Fb,bsuccess)\n if (.not. bsuccess) return\n ! Fx=matmul(Fb,Ff)\n Fx(1) = Fb(1,1)*Ff(1) + Fb(1,2)*Ff(2) &\n + Fb(1,3)*Ff(3) + Fb(1,4)*Ff(4) &\n + Fb(1,5)*Ff(5)\n Fx(2) = Fb(2,1)*Ff(1) + Fb(2,2)*Ff(2) &\n + Fb(2,3)*Ff(3) + Fb(2,4)*Ff(4) &\n + Fb(2,5)*Ff(5)\n Fx(3) = Fb(3,1)*Ff(1) + Fb(3,2)*Ff(2) &\n + Fb(3,3)*Ff(3) + Fb(3,4)*Ff(4) &\n + Fb(3,5)*Ff(5)\n Fx(4) = Fb(4,1)*Ff(1) + Fb(4,2)*Ff(2) &\n + Fb(4,3)*Ff(3) + Fb(4,4)*Ff(4) &\n + Fb(4,5)*Ff(5)\n Fx(5) = Fb(5,1)*Ff(1) + Fb(5,2)*Ff(2) &\n + Fb(5,3)*Ff(3) + Fb(5,4)*Ff(4) &\n + Fb(5,5)*Ff(5)\n\n case (6)\n call mprim_invert6x6MatrixDirectSP(Fa,Fb,bsuccess)\n if (.not. bsuccess) return\n ! Fx=matmul(Fb,Ff)\n Fx(1) = Fb(1,1)*Ff(1) + Fb(1,2)*Ff(2) &\n + Fb(1,3)*Ff(3) + Fb(1,4)*Ff(4) &\n + Fb(1,5)*Ff(5) + Fb(1,6)*Ff(6)\n Fx(2) = Fb(2,1)*Ff(1) + Fb(2,2)*Ff(2) &\n + Fb(2,3)*Ff(3) + Fb(2,4)*Ff(4) &\n + Fb(2,5)*Ff(5) + Fb(2,6)*Ff(6)\n Fx(3) = Fb(3,1)*Ff(1) + Fb(3,2)*Ff(2) &\n + Fb(3,3)*Ff(3) + Fb(3,4)*Ff(4) &\n + Fb(3,5)*Ff(5) + Fb(3,6)*Ff(6)\n Fx(4) = Fb(4,1)*Ff(1) + Fb(4,2)*Ff(2) &\n + Fb(4,3)*Ff(3) + Fb(4,4)*Ff(4) &\n + Fb(4,5)*Ff(5) + Fb(4,6)*Ff(6)\n Fx(5) = Fb(5,1)*Ff(1) + Fb(5,2)*Ff(2) &\n + Fb(5,3)*Ff(3) + Fb(5,4)*Ff(4) &\n + Fb(5,5)*Ff(5) + Fb(5,6)*Ff(6)\n Fx(6) = Fb(6,1)*Ff(1) + Fb(6,2)*Ff(2) &\n + Fb(6,3)*Ff(3) + Fb(6,4)*Ff(4) &\n + Fb(6,5)*Ff(5) + Fb(6,6)*Ff(6)\n\n case default\n ! Use LAPACK routine for general NxN system, where N > 6\n Ipiv=0; Fx=Ff\n call SGESV(ndim,1,Fa,ndim,Ipiv,Fx,ndim,info)\n\n if (info .ne. 0) return\n\n end select\n\n end select\n\n bsuccess = .true.\n\n end subroutine mprim_invertMatrixSP\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_invert2x2MatrixDirectDP(Da,Db,bsuccess)\n\n!\n ! This subroutine directly inverts a 2x2 system without any pivoting.\n ! 'Da' is a 2-dimensional 2x2 m matrix. The inverse of Da is written\n ! to the 2-dimensional 2x2 matrix Db.\n !\n ! Warning: For speed reasons, there is no array bounds checking\n ! activated in this routine! Da and Db are assumed to be 2x2 arrays!\n!\n\n!\n ! source square matrix to be inverted\n real(DP), dimension(2,2), intent(in) :: Da\n!\n\n!\n ! destination square matrix; receives $ A^{-1} $.\n real(DP), dimension(2,2), intent(out) :: Db\n\n ! TRUE, if successful. FALSE if the system is indefinite.\n ! If FALSE, Db is undefined.\n logical, intent(out) :: bsuccess\n!\n\n!\n\n real(DP) :: daux\n\n ! Explicit formula for 2x2 system\n Db(1,1)= Da(2,2)\n Db(2,1)=-Da(2,1)\n Db(1,2)=-Da(1,2)\n Db(2,2)= Da(1,1)\n daux=Da(1,1)*Da(2,2)-Da(1,2)*Da(2,1)\n if (daux .ne. 0.0_DP) then\n Db=Db*(1.0_DP/daux)\n bsuccess = .true.\n else\n bsuccess = .false.\n end if\n\n end subroutine mprim_invert2x2MatrixDirectDP\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_invert2x2MatrixDirectSP(Fa,Fb,bsuccess)\n\n!\n ! This subroutine directly inverts a 2x2 system without any pivoting.\n ! 'Fa' is a 2-dimensional 2x2 m matrix. The inverse of Fa is written\n ! to the 2-dimensional 2x2 matrix Fb.\n !\n ! Warning: For speed reasons, there is no array bounds checking\n ! activated in this routine! Fa and Fb are assumed to be 2x2 arrays!\n!\n\n!\n ! source square matrix to be inverted\n real(SP), dimension(2,2), intent(in) :: Fa\n!\n\n!\n ! destination square matrix; receives $ A^{-1} $.\n real(SP), dimension(2,2), intent(out) :: Fb\n\n ! TRUE, if successful. FALSE if the system is indefinite.\n ! If FALSE, Fb is undefined.\n logical, intent(out) :: bsuccess\n!\n\n!\n\n real(SP) :: faux\n\n ! Explicit formula for 2x2 system\n Fb(1,1)= Fa(2,2)\n Fb(2,1)=-Fa(2,1)\n Fb(1,2)=-Fa(1,2)\n Fb(2,2)= Fa(1,1)\n faux=Fa(1,1)*Fa(2,2)-Fa(1,2)*Fa(2,1)\n if (faux .ne. 0.0_SP) then\n Fb=Fb*(1.0_SP/faux)\n bsuccess = .true.\n else\n bsuccess = .false.\n end if\n\n end subroutine mprim_invert2x2MatrixDirectSP\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_invert3x3MatrixDirectDP(Da,Db,bsuccess)\n\n!\n ! This subroutine directly inverts a 3x3 system without any pivoting.\n ! 'Da' is a 2-dimensional 3x3 m matrix. The inverse of Da is written\n ! to the 2-dimensional 3x3 matrix Db.\n !\n ! Warning: For speed reasons, there is no array bounds checking\n ! activated in this routine! Da and Db are assumed to be 3x3 arrays!\n!\n\n!\n ! source square matrix to be inverted\n real(DP), dimension(3,3), intent(in) :: Da\n!\n\n!\n ! destination square matrix; receives $ A^{-1} $.\n real(DP), dimension(3,3), intent(out) :: Db\n\n ! TRUE, if successful. FALSE if the system is indefinite.\n ! If FALSE, Db is undefined.\n logical, intent(out) :: bsuccess\n!\n\n!\n\n real(DP) :: daux\n\n ! Explicit formula for 3x3 system\n Db(1,1)=Da(2,2)*Da(3,3)-Da(2,3)*Da(3,2)\n Db(2,1)=Da(2,3)*Da(3,1)-Da(2,1)*Da(3,3)\n Db(3,1)=Da(2,1)*Da(3,2)-Da(2,2)*Da(3,1)\n Db(1,2)=Da(1,3)*Da(3,2)-Da(1,2)*Da(3,3)\n Db(2,2)=Da(1,1)*Da(3,3)-Da(1,3)*Da(3,1)\n Db(3,2)=Da(1,2)*Da(3,1)-Da(1,1)*Da(3,2)\n Db(1,3)=Da(1,2)*Da(2,3)-Da(1,3)*Da(2,2)\n Db(2,3)=Da(1,3)*Da(2,1)-Da(1,1)*Da(2,3)\n Db(3,3)=Da(1,1)*Da(2,2)-Da(1,2)*Da(2,1)\n daux = Da(1,1)*Db(1,1)+Da(1,2)*Db(2,1)+Da(1,3)*Db(3,1)\n if (daux .ne. 0.0_DP) then\n !daux=Da(1,1)*Da(2,2)*Da(3,3)+Da(2,1)*Da(3,2)*Da(1,3)+ Da(3,1)&\n ! &*Da(1,2)*Da(2,3)-Da(1,1)*Da(3,2)*Da(2,3)- Da(3,1)*Da(2&\n ! &,2)*Da(1,3)-Da(2,1)*Da(1,2)*Da(3,3)\n Db=Db*(1.0_DP/daux)\n bsuccess = .true.\n else\n bsuccess = .false.\n end if\n\n end subroutine mprim_invert3x3MatrixDirectDP\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_invert3x3MatrixDirectSP(Fa,Fb,bsuccess)\n\n!\n ! This subroutine directly inverts a 3x3 system without any pivoting.\n ! 'Fa' is a 2-dimensional 3x3 m matrix. The inverse of Fa is written\n ! to the 2-dimensional 3x3 matrix Fb.\n !\n ! Warning: For speed reasons, there is no array bounds checking\n ! activated in this routine! Fa and Fb are assumed to be 3x3 arrays!\n!\n\n!\n ! source square matrix to be inverted\n real(SP), dimension(3,3), intent(in) :: Fa\n!\n\n!\n ! destination square matrix; receives $ A^{-1} $.\n real(SP), dimension(3,3), intent(out) :: Fb\n\n ! TRUE, if successful. FALSE if the system is indefinite.\n ! If FALSE, Fb is undefined.\n logical, intent(out) :: bsuccess\n!\n\n!\n\n real(SP) :: faux\n\n ! Explicit formula for 3x3 system\n Fb(1,1)=Fa(2,2)*Fa(3,3)-Fa(2,3)*Fa(3,2)\n Fb(2,1)=Fa(2,3)*Fa(3,1)-Fa(2,1)*Fa(3,3)\n Fb(3,1)=Fa(2,1)*Fa(3,2)-Fa(2,2)*Fa(3,1)\n Fb(1,2)=Fa(1,3)*Fa(3,2)-Fa(1,2)*Fa(3,3)\n Fb(2,2)=Fa(1,1)*Fa(3,3)-Fa(1,3)*Fa(3,1)\n Fb(3,2)=Fa(1,2)*Fa(3,1)-Fa(1,1)*Fa(3,2)\n Fb(1,3)=Fa(1,2)*Fa(2,3)-Fa(1,3)*Fa(2,2)\n Fb(2,3)=Fa(1,3)*Fa(2,1)-Fa(1,1)*Fa(2,3)\n Fb(3,3)=Fa(1,1)*Fa(2,2)-Fa(1,2)*Fa(2,1)\n faux = Fa(1,1)*Fb(1,1)+Fa(1,2)*Fb(2,1)+Fa(1,3)*Fb(3,1)\n if (faux .ne. 0.0_SP) then\n !faux=Fa(1,1)*Fa(2,2)*Fa(3,3)+Fa(2,1)*Fa(3,2)*Fa(1,3)+ Fa(3,1)&\n ! &*Fa(1,2)*Fa(2,3)-Fa(1,1)*Fa(3,2)*Fa(2,3)- Fa(3,1)*Fa(2&\n ! &,2)*Fa(1,3)-Fa(2,1)*Fa(1,2)*Fa(3,3)\n Fb=Fb*(1.0_SP/faux)\n bsuccess = .true.\n else\n bsuccess = .false.\n end if\n\n end subroutine mprim_invert3x3MatrixDirectSP\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_invert4x4MatrixDirectDP(Da,Db,bsuccess)\n\n!\n ! This subroutine directly inverts a 4x4 system without any pivoting.\n ! 'Da' is a 2-dimensional 4x4 m matrix. The inverse of Da is written\n ! to the 2-dimensional 4x4 matrix Db.\n !\n ! Warning: For speed reasons, there is no array bounds checking\n ! activated in this routine! Da and Db are assumed to be 4x4 arrays!\n!\n\n!\n ! source square matrix to be inverted\n real(DP), dimension(4,4), intent(in) :: Da\n!\n\n!\n ! destination square matrix; receives $ A^{-1} $.\n real(DP), dimension(4,4), intent(out) :: Db\n\n ! TRUE, if successful. FALSE if the system is indefinite.\n ! If FALSE, Db is undefined.\n logical, intent(out) :: bsuccess\n!\n\n!\n\n ! auxiliary variables\n real(DP) :: det,daux\n real(DP), dimension(6) :: W\n\n ! 2x2 determinants of rows 3-4\n W(1)=Da(3,1)*Da(4,2)-Da(3,2)*Da(4,1)\n W(2)=Da(3,1)*Da(4,3)-Da(3,3)*Da(4,1)\n W(3)=Da(3,1)*Da(4,4)-Da(3,4)*Da(4,1)\n W(4)=Da(3,2)*Da(4,3)-Da(3,3)*Da(4,2)\n W(5)=Da(3,2)*Da(4,4)-Da(3,4)*Da(4,2)\n W(6)=Da(3,3)*Da(4,4)-Da(3,4)*Da(4,3)\n ! pre-calculate first column of inverse\n Db(1,1)= Da(2,2)*W(6)-Da(2,3)*W(5)+Da(2,4)*W(4)\n Db(2,1)=-Da(2,1)*W(6)+Da(2,3)*W(3)-Da(2,4)*W(2)\n Db(3,1)= Da(2,1)*W(5)-Da(2,2)*W(3)+Da(2,4)*W(1)\n Db(4,1)=-Da(2,1)*W(4)+Da(2,2)*W(2)-Da(2,3)*W(1)\n daux = (Da(1,1)*Db(1,1)+Da(1,2)*Db(2,1)&\n +Da(1,3)*Db(3,1)+Da(1,4)*Db(4,1))\n if (daux .ne. 0.0_DP) then\n ! calculate determinant of A\n det = 1.0_DP / daux\n ! update first column of inverse\n Db(1,1)=Db(1,1)*det\n Db(2,1)=Db(2,1)*det\n Db(3,1)=Db(3,1)*det\n Db(4,1)=Db(4,1)*det\n ! calculate second column of inverse\n Db(1,2)=det*(-Da(1,2)*W(6)+Da(1,3)*W(5)-Da(1,4)*W(4))\n Db(2,2)=det*( Da(1,1)*W(6)-Da(1,3)*W(3)+Da(1,4)*W(2))\n Db(3,2)=det*(-Da(1,1)*W(5)+Da(1,2)*W(3)-Da(1,4)*W(1))\n Db(4,2)=det*( Da(1,1)*W(4)-Da(1,2)*W(2)+Da(1,3)*W(1))\n ! 2x2 determinants of rows 1-2\n W(1)=Da(1,1)*Da(2,2)-Da(1,2)*Da(2,1)\n W(2)=Da(1,1)*Da(2,3)-Da(1,3)*Da(2,1)\n W(3)=Da(1,1)*Da(2,4)-Da(1,4)*Da(2,1)\n W(4)=Da(1,2)*Da(2,3)-Da(1,3)*Da(2,2)\n W(5)=Da(1,2)*Da(2,4)-Da(1,4)*Da(2,2)\n W(6)=Da(1,3)*Da(2,4)-Da(1,4)*Da(2,3)\n ! calculate third column of inverse\n Db(1,3)=det*( Da(4,2)*W(6)-Da(4,3)*W(5)+Da(4,4)*W(4))\n Db(2,3)=det*(-Da(4,1)*W(6)+Da(4,3)*W(3)-Da(4,4)*W(2))\n Db(3,3)=det*( Da(4,1)*W(5)-Da(4,2)*W(3)+Da(4,4)*W(1))\n Db(4,3)=det*(-Da(4,1)*W(4)+Da(4,2)*W(2)-Da(4,3)*W(1))\n ! calculate fourth column of inverse\n Db(1,4)=det*(-Da(3,2)*W(6)+Da(3,3)*W(5)-Da(3,4)*W(4))\n Db(2,4)=det*( Da(3,1)*W(6)-Da(3,3)*W(3)+Da(3,4)*W(2))\n Db(3,4)=det*(-Da(3,1)*W(5)+Da(3,2)*W(3)-Da(3,4)*W(1))\n Db(4,4)=det*( Da(3,1)*W(4)-Da(3,2)*W(2)+Da(3,3)*W(1))\n\n ! 'old' implementation follows\n\n! real(DP) :: daux\n!\n! ! Explicit formula for 4x4 system\n! Db(1,1)=Da(2,2)*Da(3,3)*Da(4,4)+Da(2,3)*Da(3,4)*Da(4,2)+Da(2&\n! &,4)*Da(3,2)*Da(4,3)- Da(2,2)*Da(3,4)*Da(4,3)-Da(2,3)&\n! &*Da(3,2)*Da(4,4)-Da(2,4)*Da(3,3)*Da(4,2)\n! Db(2,1)=Da(2,1)*Da(3,4)*Da(4,3)+Da(2,3)*Da(3,1)*Da(4,4)+Da(2&\n! &,4)*Da(3,3)*Da(4,1)- Da(2,1)*Da(3,3)*Da(4,4)-Da(2,3)&\n! &*Da(3,4)*Da(4,1)-Da(2,4)*Da(3,1)*Da(4,3)\n! Db(3,1)=Da(2,1)*Da(3,2)*Da(4,4)+Da(2,2)*Da(3,4)*Da(4,1)+Da(2&\n! &,4)*Da(3,1)*Da(4,2)- Da(2,1)*Da(3,4)*Da(4,2)-Da(2,2)&\n! &*Da(3,1)*Da(4,4)-Da(2,4)*Da(3,2)*Da(4,1)\n! Db(4,1)=Da(2,1)*Da(3,3)*Da(4,2)+Da(2,2)*Da(3,1)*Da(4,3)+Da(2&\n! &,3)*Da(3,2)*Da(4,1)- Da(2,1)*Da(3,2)*Da(4,3)-Da(2,2)&\n! &*Da(3,3)*Da(4,1)-Da(2,3)*Da(3,1)*Da(4,2)\n! Db(1,2)=Da(1,2)*Da(3,4)*Da(4,3)+Da(1,3)*Da(3,2)*Da(4,4)+Da(1&\n! &,4)*Da(3,3)*Da(4,2)- Da(1,2)*Da(3,3)*Da(4,4)-Da(1,3)&\n! &*Da(3,4)*Da(4,2)-Da(1,4)*Da(3,2)*Da(4,3)\n! Db(2,2)=Da(1,1)*Da(3,3)*Da(4,4)+Da(1,3)*Da(3,4)*Da(4,1)+Da(1&\n! &,4)*Da(3,1)*Da(4,3)- Da(1,1)*Da(3,4)*Da(4,3)-Da(1,3)&\n! &*Da(3,1)*Da(4,4)-Da(1,4)*Da(3,3)*Da(4,1)\n! Db(3,2)=Da(1,1)*Da(3,4)*Da(4,2)+Da(1,2)*Da(3,1)*Da(4,4)+Da(1&\n! &,4)*Da(3,2)*Da(4,1)- Da(1,1)*Da(3,2)*Da(4,4)-Da(1,2)&\n! &*Da(3,4)*Da(4,1)-Da(1,4)*Da(3,1)*Da(4,2)\n! Db(4,2)=Da(1,1)*Da(3,2)*Da(4,3)+Da(1,2)*Da(3,3)*Da(4,1)+Da(1&\n! &,3)*Da(3,1)*Da(4,2)- Da(1,1)*Da(3,3)*Da(4,2)-Da(1,2)&\n! &*Da(3,1)*Da(4,3)-Da(1,3)*Da(3,2)*Da(4,1)\n! Db(1,3)=Da(1,2)*Da(2,3)*Da(4,4)+Da(1,3)*Da(2,4)*Da(4,2)+Da(1&\n! &,4)*Da(2,2)*Da(4,3)- Da(1,2)*Da(2,4)*Da(4,3)-Da(1,3)&\n! &*Da(2,2)*Da(4,4)-Da(1,4)*Da(2,3)*Da(4,2)\n! Db(2,3)=Da(1,1)*Da(2,4)*Da(4,3)+Da(1,3)*Da(2,1)*Da(4,4)+Da(1&\n! &,4)*Da(2,3)*Da(4,1)- Da(1,1)*Da(2,3)*Da(4,4)-Da(1,3)&\n! &*Da(2,4)*Da(4,1)-Da(1,4)*Da(2,1)*Da(4,3)\n! Db(3,3)=Da(1,1)*Da(2,2)*Da(4,4)+Da(1,2)*Da(2,4)*Da(4,1)+Da(1&\n! &,4)*Da(2,1)*Da(4,2)- Da(1,1)*Da(2,4)*Da(4,2)-Da(1,2)&\n! &*Da(2,1)*Da(4,4)-Da(1,4)*Da(2,2)*Da(4,1)\n! Db(4,3)=Da(1,1)*Da(2,3)*Da(4,2)+Da(1,2)*Da(2,1)*Da(4,3)+Da(1&\n! &,3)*Da(2,2)*Da(4,1)- Da(1,1)*Da(2,2)*Da(4,3)-Da(1,2)&\n! &*Da(2,3)*Da(4,1)-Da(1,3)*Da(2,1)*Da(4,2)\n! Db(1,4)=Da(1,2)*Da(2,4)*Da(3,3)+Da(1,3)*Da(2,2)*Da(3,4)+Da(1&\n! &,4)*Da(2,3)*Da(3,2)- Da(1,2)*Da(2,3)*Da(3,4)-Da(1,3)&\n! &*Da(2,4)*Da(3,2)-Da(1,4)*Da(2,2)*Da(3,3)\n! Db(2,4)=Da(1,1)*Da(2,3)*Da(3,4)+Da(1,3)*Da(2,4)*Da(3,1)+Da(1&\n! &,4)*Da(2,1)*Da(3,3)- Da(1,1)*Da(2,4)*Da(3,3)-Da(1,3)&\n! &*Da(2,1)*Da(3,4)-Da(1,4)*Da(2,3)*Da(3,1)\n! Db(3,4)=Da(1,1)*Da(2,4)*Da(3,2)+Da(1,2)*Da(2,1)*Da(3,4)+Da(1&\n! &,4)*Da(2,2)*Da(3,1)- Da(1,1)*Da(2,2)*Da(3,4)-Da(1,2)&\n! &*Da(2,4)*Da(3,1)-Da(1,4)*Da(2,1)*Da(3,2)\n! Db(4,4)=Da(1,1)*Da(2,2)*Da(3,3)+Da(1,2)*Da(2,3)*Da(3,1)+Da(1&\n! &,3)*Da(2,1)*Da(3,2)- Da(1,1)*Da(2,3)*Da(3,2)-Da(1,2)&\n! &*Da(2,1)*Da(3,3)-Da(1,3)*Da(2,2)*Da(3,1)\n! daux=Da(1,1)*Da(2,2)*Da(3,3)*Da(4,4)+Da(1,1)*Da(2,3)*Da(3,4)&\n! &*Da(4,2)+Da(1,1)*Da(2,4)*Da(3,2)*Da(4,3)+ Da(1,2)*Da(2&\n! &,1)*Da(3,4)*Da(4,3)+Da(1,2)*Da(2,3)*Da(3,1)*Da(4,4)+Da(1&\n! &,2)*Da(2,4)*Da(3,3)*Da(4,1)+ Da(1,3)*Da(2,1)*Da(3,2)&\n! &*Da(4,4)+Da(1,3)*Da(2,2)*Da(3,4)*Da(4,1)+Da(1,3)*Da(2,4)&\n! &*Da(3,1)*Da(4,2)+ Da(1,4)*Da(2,1)*Da(3,3)*Da(4,2)+Da(1&\n! &,4)*Da(2,2)*Da(3,1)*Da(4,3)+Da(1,4)*Da(2,3)*Da(3,2)*Da(4&\n! &,1)- Da(1,1)*Da(2,2)*Da(3,4)*Da(4,3)-Da(1,1)*Da(2,3)&\n! &*Da(3,2)*Da(4,4)-Da(1,1)*Da(2,4)*Da(3,3)*Da(4,2)- Da(1&\n! &,2)*Da(2,1)*Da(3,3)*Da(4,4)-Da(1,2)*Da(2,3)*Da(3,4)*Da(4&\n! &,1)-Da(1,2)*Da(2,4)*Da(3,1)*Da(4,3)- Da(1,3)*Da(2,1)&\n! &*Da(3,4)*Da(4,2)-Da(1,3)*Da(2,2)*Da(3,1)*Da(4,4)-Da(1,3)&\n! &*Da(2,4)*Da(3,2)*Da(4,1)- Da(1,4)*Da(2,1)*Da(3,2)*Da(4&\n! &,3)-Da(1,4)*Da(2,2)*Da(3,3)*Da(4,1)-Da(1,4)*Da(2,3)*Da(3&\n! &,1)*Da(4,2)\n! Db=Db*(1.0_DP/daux)\n\n bsuccess = .true.\n\n else\n bsuccess = .false.\n end if\n\n end subroutine mprim_invert4x4MatrixDirectDP\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_invert4x4MatrixDirectSP(Fa,Fb,bsuccess)\n\n!\n ! This subroutine directly inverts a 4x4 system without any pivoting.\n ! 'Fa' is a 2-dimensional 4x4 m matrix. The inverse of Fa is written\n ! to the 2-dimensional 4x4 matrix Fb.\n !\n ! Warning: For speed reasons, there is no array bounds checking\n ! activated in this routine! Fa and Fb are assumed to be 4x4 arrays!\n!\n\n!\n ! source square matrix to be inverted\n real(SP), dimension(4,4), intent(in) :: Fa\n!\n\n!\n ! destination square matrix; receives $ A^{-1} $.\n real(SP), dimension(4,4), intent(out) :: Fb\n\n ! TRUE, if successful. FALSE if the system is indefinite.\n ! If FALSE, Fb is undefined.\n logical, intent(out) :: bsuccess\n!\n\n!\n\n ! auxiliary variables\n real(SP) :: det,faux\n real(SP), dimension(6) :: W\n\n ! 2x2 determinants of rows 3-4\n W(1)=Fa(3,1)*Fa(4,2)-Fa(3,2)*Fa(4,1)\n W(2)=Fa(3,1)*Fa(4,3)-Fa(3,3)*Fa(4,1)\n W(3)=Fa(3,1)*Fa(4,4)-Fa(3,4)*Fa(4,1)\n W(4)=Fa(3,2)*Fa(4,3)-Fa(3,3)*Fa(4,2)\n W(5)=Fa(3,2)*Fa(4,4)-Fa(3,4)*Fa(4,2)\n W(6)=Fa(3,3)*Fa(4,4)-Fa(3,4)*Fa(4,3)\n ! pre-calculate first column of inverse\n Fb(1,1)= Fa(2,2)*W(6)-Fa(2,3)*W(5)+Fa(2,4)*W(4)\n Fb(2,1)=-Fa(2,1)*W(6)+Fa(2,3)*W(3)-Fa(2,4)*W(2)\n Fb(3,1)= Fa(2,1)*W(5)-Fa(2,2)*W(3)+Fa(2,4)*W(1)\n Fb(4,1)=-Fa(2,1)*W(4)+Fa(2,2)*W(2)-Fa(2,3)*W(1)\n faux = (Fa(1,1)*Fb(1,1)+Fa(1,2)*Fb(2,1)&\n +Fa(1,3)*Fb(3,1)+Fa(1,4)*Fb(4,1))\n if (faux .ne. 0.0_SP) then\n ! calculate determinant of A\n det = 1.0_SP / faux\n ! update first column of inverse\n Fb(1,1)=Fb(1,1)*det\n Fb(2,1)=Fb(2,1)*det\n Fb(3,1)=Fb(3,1)*det\n Fb(4,1)=Fb(4,1)*det\n ! calculate second column of inverse\n Fb(1,2)=det*(-Fa(1,2)*W(6)+Fa(1,3)*W(5)-Fa(1,4)*W(4))\n Fb(2,2)=det*( Fa(1,1)*W(6)-Fa(1,3)*W(3)+Fa(1,4)*W(2))\n Fb(3,2)=det*(-Fa(1,1)*W(5)+Fa(1,2)*W(3)-Fa(1,4)*W(1))\n Fb(4,2)=det*( Fa(1,1)*W(4)-Fa(1,2)*W(2)+Fa(1,3)*W(1))\n ! 2x2 determinants of rows 1-2\n W(1)=Fa(1,1)*Fa(2,2)-Fa(1,2)*Fa(2,1)\n W(2)=Fa(1,1)*Fa(2,3)-Fa(1,3)*Fa(2,1)\n W(3)=Fa(1,1)*Fa(2,4)-Fa(1,4)*Fa(2,1)\n W(4)=Fa(1,2)*Fa(2,3)-Fa(1,3)*Fa(2,2)\n W(5)=Fa(1,2)*Fa(2,4)-Fa(1,4)*Fa(2,2)\n W(6)=Fa(1,3)*Fa(2,4)-Fa(1,4)*Fa(2,3)\n ! calculate third column of inverse\n Fb(1,3)=det*( Fa(4,2)*W(6)-Fa(4,3)*W(5)+Fa(4,4)*W(4))\n Fb(2,3)=det*(-Fa(4,1)*W(6)+Fa(4,3)*W(3)-Fa(4,4)*W(2))\n Fb(3,3)=det*( Fa(4,1)*W(5)-Fa(4,2)*W(3)+Fa(4,4)*W(1))\n Fb(4,3)=det*(-Fa(4,1)*W(4)+Fa(4,2)*W(2)-Fa(4,3)*W(1))\n ! calculate fourth column of inverse\n Fb(1,4)=det*(-Fa(3,2)*W(6)+Fa(3,3)*W(5)-Fa(3,4)*W(4))\n Fb(2,4)=det*( Fa(3,1)*W(6)-Fa(3,3)*W(3)+Fa(3,4)*W(2))\n Fb(3,4)=det*(-Fa(3,1)*W(5)+Fa(3,2)*W(3)-Fa(3,4)*W(1))\n Fb(4,4)=det*( Fa(3,1)*W(4)-Fa(3,2)*W(2)+Fa(3,3)*W(1))\n\n ! 'old' implementation follows\n\n! real(SP) :: faux\n!\n! ! Explicit formula for 4x4 system\n! Fb(1,1)=Fa(2,2)*Fa(3,3)*Fa(4,4)+Fa(2,3)*Fa(3,4)*Fa(4,2)+Fa(2&\n! &,4)*Fa(3,2)*Fa(4,3)- Fa(2,2)*Fa(3,4)*Fa(4,3)-Fa(2,3)&\n! &*Fa(3,2)*Fa(4,4)-Fa(2,4)*Fa(3,3)*Fa(4,2)\n! Fb(2,1)=Fa(2,1)*Fa(3,4)*Fa(4,3)+Fa(2,3)*Fa(3,1)*Fa(4,4)+Fa(2&\n! &,4)*Fa(3,3)*Fa(4,1)- Fa(2,1)*Fa(3,3)*Fa(4,4)-Fa(2,3)&\n! &*Fa(3,4)*Fa(4,1)-Fa(2,4)*Fa(3,1)*Fa(4,3)\n! Fb(3,1)=Fa(2,1)*Fa(3,2)*Fa(4,4)+Fa(2,2)*Fa(3,4)*Fa(4,1)+Fa(2&\n! &,4)*Fa(3,1)*Fa(4,2)- Fa(2,1)*Fa(3,4)*Fa(4,2)-Fa(2,2)&\n! &*Fa(3,1)*Fa(4,4)-Fa(2,4)*Fa(3,2)*Fa(4,1)\n! Fb(4,1)=Fa(2,1)*Fa(3,3)*Fa(4,2)+Fa(2,2)*Fa(3,1)*Fa(4,3)+Fa(2&\n! &,3)*Fa(3,2)*Fa(4,1)- Fa(2,1)*Fa(3,2)*Fa(4,3)-Fa(2,2)&\n! &*Fa(3,3)*Fa(4,1)-Fa(2,3)*Fa(3,1)*Fa(4,2)\n! Fb(1,2)=Fa(1,2)*Fa(3,4)*Fa(4,3)+Fa(1,3)*Fa(3,2)*Fa(4,4)+Fa(1&\n! &,4)*Fa(3,3)*Fa(4,2)- Fa(1,2)*Fa(3,3)*Fa(4,4)-Fa(1,3)&\n! &*Fa(3,4)*Fa(4,2)-Fa(1,4)*Fa(3,2)*Fa(4,3)\n! Fb(2,2)=Fa(1,1)*Fa(3,3)*Fa(4,4)+Fa(1,3)*Fa(3,4)*Fa(4,1)+Fa(1&\n! &,4)*Fa(3,1)*Fa(4,3)- Fa(1,1)*Fa(3,4)*Fa(4,3)-Fa(1,3)&\n! &*Fa(3,1)*Fa(4,4)-Fa(1,4)*Fa(3,3)*Fa(4,1)\n! Fb(3,2)=Fa(1,1)*Fa(3,4)*Fa(4,2)+Fa(1,2)*Fa(3,1)*Fa(4,4)+Fa(1&\n! &,4)*Fa(3,2)*Fa(4,1)- Fa(1,1)*Fa(3,2)*Fa(4,4)-Fa(1,2)&\n! &*Fa(3,4)*Fa(4,1)-Fa(1,4)*Fa(3,1)*Fa(4,2)\n! Fb(4,2)=Fa(1,1)*Fa(3,2)*Fa(4,3)+Fa(1,2)*Fa(3,3)*Fa(4,1)+Fa(1&\n! &,3)*Fa(3,1)*Fa(4,2)- Fa(1,1)*Fa(3,3)*Fa(4,2)-Fa(1,2)&\n! &*Fa(3,1)*Fa(4,3)-Fa(1,3)*Fa(3,2)*Fa(4,1)\n! Fb(1,3)=Fa(1,2)*Fa(2,3)*Fa(4,4)+Fa(1,3)*Fa(2,4)*Fa(4,2)+Fa(1&\n! &,4)*Fa(2,2)*Fa(4,3)- Fa(1,2)*Fa(2,4)*Fa(4,3)-Fa(1,3)&\n! &*Fa(2,2)*Fa(4,4)-Fa(1,4)*Fa(2,3)*Fa(4,2)\n! Fb(2,3)=Fa(1,1)*Fa(2,4)*Fa(4,3)+Fa(1,3)*Fa(2,1)*Fa(4,4)+Fa(1&\n! &,4)*Fa(2,3)*Fa(4,1)- Fa(1,1)*Fa(2,3)*Fa(4,4)-Fa(1,3)&\n! &*Fa(2,4)*Fa(4,1)-Fa(1,4)*Fa(2,1)*Fa(4,3)\n! Fb(3,3)=Fa(1,1)*Fa(2,2)*Fa(4,4)+Fa(1,2)*Fa(2,4)*Fa(4,1)+Fa(1&\n! &,4)*Fa(2,1)*Fa(4,2)- Fa(1,1)*Fa(2,4)*Fa(4,2)-Fa(1,2)&\n! &*Fa(2,1)*Fa(4,4)-Fa(1,4)*Fa(2,2)*Fa(4,1)\n! Fb(4,3)=Fa(1,1)*Fa(2,3)*Fa(4,2)+Fa(1,2)*Fa(2,1)*Fa(4,3)+Fa(1&\n! &,3)*Fa(2,2)*Fa(4,1)- Fa(1,1)*Fa(2,2)*Fa(4,3)-Fa(1,2)&\n! &*Fa(2,3)*Fa(4,1)-Fa(1,3)*Fa(2,1)*Fa(4,2)\n! Fb(1,4)=Fa(1,2)*Fa(2,4)*Fa(3,3)+Fa(1,3)*Fa(2,2)*Fa(3,4)+Fa(1&\n! &,4)*Fa(2,3)*Fa(3,2)- Fa(1,2)*Fa(2,3)*Fa(3,4)-Fa(1,3)&\n! &*Fa(2,4)*Fa(3,2)-Fa(1,4)*Fa(2,2)*Fa(3,3)\n! Fb(2,4)=Fa(1,1)*Fa(2,3)*Fa(3,4)+Fa(1,3)*Fa(2,4)*Fa(3,1)+Fa(1&\n! &,4)*Fa(2,1)*Fa(3,3)- Fa(1,1)*Fa(2,4)*Fa(3,3)-Fa(1,3)&\n! &*Fa(2,1)*Fa(3,4)-Fa(1,4)*Fa(2,3)*Fa(3,1)\n! Fb(3,4)=Fa(1,1)*Fa(2,4)*Fa(3,2)+Fa(1,2)*Fa(2,1)*Fa(3,4)+Fa(1&\n! &,4)*Fa(2,2)*Fa(3,1)- Fa(1,1)*Fa(2,2)*Fa(3,4)-Fa(1,2)&\n! &*Fa(2,4)*Fa(3,1)-Fa(1,4)*Fa(2,1)*Fa(3,2)\n! Fb(4,4)=Fa(1,1)*Fa(2,2)*Fa(3,3)+Fa(1,2)*Fa(2,3)*Fa(3,1)+Fa(1&\n! &,3)*Fa(2,1)*Fa(3,2)- Fa(1,1)*Fa(2,3)*Fa(3,2)-Fa(1,2)&\n! &*Fa(2,1)*Fa(3,3)-Fa(1,3)*Fa(2,2)*Fa(3,1)\n! faux=Fa(1,1)*Fa(2,2)*Fa(3,3)*Fa(4,4)+Fa(1,1)*Fa(2,3)*Fa(3,4)&\n! &*Fa(4,2)+Fa(1,1)*Fa(2,4)*Fa(3,2)*Fa(4,3)+ Fa(1,2)*Fa(2&\n! &,1)*Fa(3,4)*Fa(4,3)+Fa(1,2)*Fa(2,3)*Fa(3,1)*Fa(4,4)+Fa(1&\n! &,2)*Fa(2,4)*Fa(3,3)*Fa(4,1)+ Fa(1,3)*Fa(2,1)*Fa(3,2)&\n! &*Fa(4,4)+Fa(1,3)*Fa(2,2)*Fa(3,4)*Fa(4,1)+Fa(1,3)*Fa(2,4)&\n! &*Fa(3,1)*Fa(4,2)+ Fa(1,4)*Fa(2,1)*Fa(3,3)*Fa(4,2)+Fa(1&\n! &,4)*Fa(2,2)*Fa(3,1)*Fa(4,3)+Fa(1,4)*Fa(2,3)*Fa(3,2)*Fa(4&\n! &,1)- Fa(1,1)*Fa(2,2)*Fa(3,4)*Fa(4,3)-Fa(1,1)*Fa(2,3)&\n! &*Fa(3,2)*Fa(4,4)-Fa(1,1)*Fa(2,4)*Fa(3,3)*Fa(4,2)- Fa(1&\n! &,2)*Fa(2,1)*Fa(3,3)*Fa(4,4)-Fa(1,2)*Fa(2,3)*Fa(3,4)*Fa(4&\n! &,1)-Fa(1,2)*Fa(2,4)*Fa(3,1)*Fa(4,3)- Fa(1,3)*Fa(2,1)&\n! &*Fa(3,4)*Fa(4,2)-Fa(1,3)*Fa(2,2)*Fa(3,1)*Fa(4,4)-Fa(1,3)&\n! &*Fa(2,4)*Fa(3,2)*Fa(4,1)- Fa(1,4)*Fa(2,1)*Fa(3,2)*Fa(4&\n! &,3)-Fa(1,4)*Fa(2,2)*Fa(3,3)*Fa(4,1)-Fa(1,4)*Fa(2,3)*Fa(3&\n! &,1)*Fa(4,2)\n! Fb=Fb*(1.0_SP/faux)\n\n bsuccess = .true.\n\n else\n bsuccess = .false.\n end if\n\n end subroutine mprim_invert4x4MatrixDirectSP\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_invert5x5MatrixDirectDP(Da,Db,bsuccess)\n\n!\n ! This subroutine directly inverts a 5x5 system without any pivoting.\n ! 'Da' is a 2-dimensional 5x5 matrix. The inverse of Da is written\n ! to the 2-dimensional 5x5 matrix Db.\n !\n ! Warning: For speed reasons, there is no array bounds checking\n ! activated in this routine! Da and Db are assumed to be 5x5 arrays!\n!\n\n!\n ! source square matrix to be inverted\n real(DP), dimension(5,5), intent(in) :: Da\n!\n\n!\n ! destination square matrix; receives $ A^{-1} $.\n real(DP), dimension(5,5), intent(out) :: Db\n\n ! TRUE, if successful. FALSE if the system is indefinite.\n ! If FALSE, Db is undefined.\n logical, intent(out) :: bsuccess\n!\n\n!\n\n ! auxiliary variables\n real(DP) :: det,daux\n real(DP), dimension(10) :: V,W\n\n ! 2x2 determinants of rows 4-5\n V( 1) = Da(4,1)*Da(5,2)-Da(4,2)*Da(5,1)\n V( 2) = Da(4,1)*Da(5,3)-Da(4,3)*Da(5,1)\n V( 3) = Da(4,1)*Da(5,4)-Da(4,4)*Da(5,1)\n V( 4) = Da(4,1)*Da(5,5)-Da(4,5)*Da(5,1)\n V( 5) = Da(4,2)*Da(5,3)-Da(4,3)*Da(5,2)\n V( 6) = Da(4,2)*Da(5,4)-Da(4,4)*Da(5,2)\n V( 7) = Da(4,2)*Da(5,5)-Da(4,5)*Da(5,2)\n V( 8) = Da(4,3)*Da(5,4)-Da(4,4)*Da(5,3)\n V( 9) = Da(4,3)*Da(5,5)-Da(4,5)*Da(5,3)\n V(10) = Da(4,4)*Da(5,5)-Da(4,5)*Da(5,4)\n ! 3x3 determinants of rows 3-4-5\n W( 1) = Da(3,1)*V( 5)-Da(3,2)*V( 2)+Da(3,3)*V( 1)\n W( 2) = Da(3,1)*V( 6)-Da(3,2)*V( 3)+Da(3,4)*V( 1)\n W( 3) = Da(3,1)*V( 7)-Da(3,2)*V( 4)+Da(3,5)*V( 1)\n W( 4) = Da(3,1)*V( 8)-Da(3,3)*V( 3)+Da(3,4)*V( 2)\n W( 5) = Da(3,1)*V( 9)-Da(3,3)*V( 4)+Da(3,5)*V( 2)\n W( 6) = Da(3,1)*V(10)-Da(3,4)*V( 4)+Da(3,5)*V( 3)\n W( 7) = Da(3,2)*V( 8)-Da(3,3)*V( 6)+Da(3,4)*V( 5)\n W( 8) = Da(3,2)*V( 9)-Da(3,3)*V( 7)+Da(3,5)*V( 5)\n W( 9) = Da(3,2)*V(10)-Da(3,4)*V( 7)+Da(3,5)*V( 6)\n W(10) = Da(3,3)*V(10)-Da(3,4)*V( 9)+Da(3,5)*V( 8)\n ! pre-calculate first column of inverse\n Db(1,1) = Da(2,2)*W(10)-Da(2,3)*W( 9)+Da(2,4)*W( 8)-Da(2,5)*W( 7)\n Db(2,1) =-Da(2,1)*W(10)+Da(2,3)*W( 6)-Da(2,4)*W( 5)+Da(2,5)*W( 4)\n Db(3,1) = Da(2,1)*W( 9)-Da(2,2)*W( 6)+Da(2,4)*W( 3)-Da(2,5)*W( 2)\n Db(4,1) =-Da(2,1)*W( 8)+Da(2,2)*W( 5)-Da(2,3)*W( 3)+Da(2,5)*W( 1)\n Db(5,1) = Da(2,1)*W( 7)-Da(2,2)*W( 4)+Da(2,3)*W( 2)-Da(2,4)*W( 1)\n daux = (Da(1,1)*Db(1,1)+Da(1,2)*Db(2,1)&\n +Da(1,3)*Db(3,1)+Da(1,4)*Db(4,1)+Da(1,5)*Db(5,1))\n if (daux .ne. 0.0_DP) then\n ! calculate determinant of A\n det = 1.0_DP / daux\n ! update first column of inverse\n Db(1,1)=Db(1,1)*det\n Db(2,1)=Db(2,1)*det\n Db(3,1)=Db(3,1)*det\n Db(4,1)=Db(4,1)*det\n Db(5,1)=Db(5,1)*det\n ! calculate second column of inverse\n Db(1,2) = det*(-Da(1,2)*W(10)+Da(1,3)*W( 9)-Da(1,4)*W( 8)+Da(1,5)*W( 7))\n Db(2,2) = det*( Da(1,1)*W(10)-Da(1,3)*W( 6)+Da(1,4)*W( 5)-Da(1,5)*W( 4))\n Db(3,2) = det*(-Da(1,1)*W( 9)+Da(1,2)*W( 6)-Da(1,4)*W( 3)+Da(1,5)*W( 2))\n Db(4,2) = det*( Da(1,1)*W( 8)-Da(1,2)*W( 5)+Da(1,3)*W( 3)-Da(1,5)*W( 1))\n Db(5,2) = det*(-Da(1,1)*W( 7)+Da(1,2)*W( 4)-Da(1,3)*W( 2)+Da(1,4)*W( 1))\n ! 3x3 determinants of rows 2-4-5\n W( 1) = Da(2,1)*V( 5)-Da(2,2)*V( 2)+Da(2,3)*V( 1)\n W( 2) = Da(2,1)*V( 6)-Da(2,2)*V( 3)+Da(2,4)*V( 1)\n W( 3) = Da(2,1)*V( 7)-Da(2,2)*V( 4)+Da(2,5)*V( 1)\n W( 4) = Da(2,1)*V( 8)-Da(2,3)*V( 3)+Da(2,4)*V( 2)\n W( 5) = Da(2,1)*V( 9)-Da(2,3)*V( 4)+Da(2,5)*V( 2)\n W( 6) = Da(2,1)*V(10)-Da(2,4)*V( 4)+Da(2,5)*V( 3)\n W( 7) = Da(2,2)*V( 8)-Da(2,3)*V( 6)+Da(2,4)*V( 5)\n W( 8) = Da(2,2)*V( 9)-Da(2,3)*V( 7)+Da(2,5)*V( 5)\n W( 9) = Da(2,2)*V(10)-Da(2,4)*V( 7)+Da(2,5)*V( 6)\n W(10) = Da(2,3)*V(10)-Da(2,4)*V( 9)+Da(2,5)*V( 8)\n ! calculate third column of inverse\n Db(1,3) = det*( Da(1,2)*W(10)-Da(1,3)*W( 9)+Da(1,4)*W( 8)-Da(1,5)*W( 7))\n Db(2,3) = det*(-Da(1,1)*W(10)+Da(1,3)*W( 6)-Da(1,4)*W( 5)+Da(1,5)*W( 4))\n Db(3,3) = det*( Da(1,1)*W( 9)-Da(1,2)*W( 6)+Da(1,4)*W( 3)-Da(1,5)*W( 2))\n Db(4,3) = det*(-Da(1,1)*W( 8)+Da(1,2)*W( 5)-Da(1,3)*W( 3)+Da(1,5)*W( 1))\n Db(5,3) = det*( Da(1,1)*W( 7)-Da(1,2)*W( 4)+Da(1,3)*W( 2)-Da(1,4)*W( 1))\n ! 2x2 determinants of rows 1-2\n V( 1) = Da(1,1)*Da(2,2)-Da(1,2)*Da(2,1)\n V( 2) = Da(1,1)*Da(2,3)-Da(1,3)*Da(2,1)\n V( 3) = Da(1,1)*Da(2,4)-Da(1,4)*Da(2,1)\n V( 4) = Da(1,1)*Da(2,5)-Da(1,5)*Da(2,1)\n V( 5) = Da(1,2)*Da(2,3)-Da(1,3)*Da(2,2)\n V( 6) = Da(1,2)*Da(2,4)-Da(1,4)*Da(2,2)\n V( 7) = Da(1,2)*Da(2,5)-Da(1,5)*Da(2,2)\n V( 8) = Da(1,3)*Da(2,4)-Da(1,4)*Da(2,3)\n V( 9) = Da(1,3)*Da(2,5)-Da(1,5)*Da(2,3)\n V(10) = Da(1,4)*Da(2,5)-Da(1,5)*Da(2,4)\n ! 3x3 determinants of rows 1-2-3\n W( 1) = Da(3,1)*V( 5)-Da(3,2)*V( 2)+Da(3,3)*V( 1)\n W( 2) = Da(3,1)*V( 6)-Da(3,2)*V( 3)+Da(3,4)*V( 1)\n W( 3) = Da(3,1)*V( 7)-Da(3,2)*V( 4)+Da(3,5)*V( 1)\n W( 4) = Da(3,1)*V( 8)-Da(3,3)*V( 3)+Da(3,4)*V( 2)\n W( 5) = Da(3,1)*V( 9)-Da(3,3)*V( 4)+Da(3,5)*V( 2)\n W( 6) = Da(3,1)*V(10)-Da(3,4)*V( 4)+Da(3,5)*V( 3)\n W( 7) = Da(3,2)*V( 8)-Da(3,3)*V( 6)+Da(3,4)*V( 5)\n W( 8) = Da(3,2)*V( 9)-Da(3,3)*V( 7)+Da(3,5)*V( 5)\n W( 9) = Da(3,2)*V(10)-Da(3,4)*V( 7)+Da(3,5)*V( 6)\n W(10) = Da(3,3)*V(10)-Da(3,4)*V( 9)+Da(3,5)*V( 8)\n ! calculate fourth column of inverse\n Db(1,4) = det*( Da(5,2)*W(10)-Da(5,3)*W( 9)+Da(5,4)*W( 8)-Da(5,5)*W( 7))\n Db(2,4) = det*(-Da(5,1)*W(10)+Da(5,3)*W( 6)-Da(5,4)*W( 5)+Da(5,5)*W( 4))\n Db(3,4) = det*( Da(5,1)*W( 9)-Da(5,2)*W( 6)+Da(5,4)*W( 3)-Da(5,5)*W( 2))\n Db(4,4) = det*(-Da(5,1)*W( 8)+Da(5,2)*W( 5)-Da(5,3)*W( 3)+Da(5,5)*W( 1))\n Db(5,4) = det*( Da(5,1)*W( 7)-Da(5,2)*W( 4)+Da(5,3)*W( 2)-Da(5,4)*W( 1))\n ! calculate fifth column of inverse\n Db(1,5) = det*(-Da(4,2)*W(10)+Da(4,3)*W( 9)-Da(4,4)*W( 8)+Da(4,5)*W( 7))\n Db(2,5) = det*( Da(4,1)*W(10)-Da(4,3)*W( 6)+Da(4,4)*W( 5)-Da(4,5)*W( 4))\n Db(3,5) = det*(-Da(4,1)*W( 9)+Da(4,2)*W( 6)-Da(4,4)*W( 3)+Da(4,5)*W( 2))\n Db(4,5) = det*( Da(4,1)*W( 8)-Da(4,2)*W( 5)+Da(4,3)*W( 3)-Da(4,5)*W( 1))\n Db(5,5) = det*(-Da(4,1)*W( 7)+Da(4,2)*W( 4)-Da(4,3)*W( 2)+Da(4,4)*W( 1))\n\n bsuccess = .true.\n else\n bsuccess = .false.\n end if\n\n end subroutine mprim_invert5x5MatrixDirectDP\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_invert5x5MatrixDirectSP(Fa,Fb,bsuccess)\n\n!\n ! This subroutine directly inverts a 5x5 system without any pivoting.\n ! 'Fa' is a 2-dimensional 5x5 matrix. The inverse of Fa is written\n ! to the 2-dimensional 5x5 matrix Fb.\n !\n ! Warning: For speed reasons, there is no array bounds checking\n ! activated in this routine! Fa and Fb are assumed to be 5x5 arrays!\n!\n\n!\n ! source square matrix to be inverted\n real(SP), dimension(5,5), intent(in) :: Fa\n!\n\n!\n ! destination square matrix; receives $ A^{-1} $.\n real(SP), dimension(5,5), intent(out) :: Fb\n\n ! TRUE, if successful. FALSE if the system is indefinite.\n ! If FALSE, Fb is undefined.\n logical, intent(out) :: bsuccess\n!\n\n!\n\n ! auxiliary variables\n real(SP) :: det,faux\n real(SP), dimension(10) :: V,W\n\n ! 2x2 determinants of rows 4-5\n V( 1) = Fa(4,1)*Fa(5,2)-Fa(4,2)*Fa(5,1)\n V( 2) = Fa(4,1)*Fa(5,3)-Fa(4,3)*Fa(5,1)\n V( 3) = Fa(4,1)*Fa(5,4)-Fa(4,4)*Fa(5,1)\n V( 4) = Fa(4,1)*Fa(5,5)-Fa(4,5)*Fa(5,1)\n V( 5) = Fa(4,2)*Fa(5,3)-Fa(4,3)*Fa(5,2)\n V( 6) = Fa(4,2)*Fa(5,4)-Fa(4,4)*Fa(5,2)\n V( 7) = Fa(4,2)*Fa(5,5)-Fa(4,5)*Fa(5,2)\n V( 8) = Fa(4,3)*Fa(5,4)-Fa(4,4)*Fa(5,3)\n V( 9) = Fa(4,3)*Fa(5,5)-Fa(4,5)*Fa(5,3)\n V(10) = Fa(4,4)*Fa(5,5)-Fa(4,5)*Fa(5,4)\n ! 3x3 determinants of rows 3-4-5\n W( 1) = Fa(3,1)*V( 5)-Fa(3,2)*V( 2)+Fa(3,3)*V( 1)\n W( 2) = Fa(3,1)*V( 6)-Fa(3,2)*V( 3)+Fa(3,4)*V( 1)\n W( 3) = Fa(3,1)*V( 7)-Fa(3,2)*V( 4)+Fa(3,5)*V( 1)\n W( 4) = Fa(3,1)*V( 8)-Fa(3,3)*V( 3)+Fa(3,4)*V( 2)\n W( 5) = Fa(3,1)*V( 9)-Fa(3,3)*V( 4)+Fa(3,5)*V( 2)\n W( 6) = Fa(3,1)*V(10)-Fa(3,4)*V( 4)+Fa(3,5)*V( 3)\n W( 7) = Fa(3,2)*V( 8)-Fa(3,3)*V( 6)+Fa(3,4)*V( 5)\n W( 8) = Fa(3,2)*V( 9)-Fa(3,3)*V( 7)+Fa(3,5)*V( 5)\n W( 9) = Fa(3,2)*V(10)-Fa(3,4)*V( 7)+Fa(3,5)*V( 6)\n W(10) = Fa(3,3)*V(10)-Fa(3,4)*V( 9)+Fa(3,5)*V( 8)\n ! pre-calculate first column of inverse\n Fb(1,1) = Fa(2,2)*W(10)-Fa(2,3)*W( 9)+Fa(2,4)*W( 8)-Fa(2,5)*W( 7)\n Fb(2,1) =-Fa(2,1)*W(10)+Fa(2,3)*W( 6)-Fa(2,4)*W( 5)+Fa(2,5)*W( 4)\n Fb(3,1) = Fa(2,1)*W( 9)-Fa(2,2)*W( 6)+Fa(2,4)*W( 3)-Fa(2,5)*W( 2)\n Fb(4,1) =-Fa(2,1)*W( 8)+Fa(2,2)*W( 5)-Fa(2,3)*W( 3)+Fa(2,5)*W( 1)\n Fb(5,1) = Fa(2,1)*W( 7)-Fa(2,2)*W( 4)+Fa(2,3)*W( 2)-Fa(2,4)*W( 1)\n faux = (Fa(1,1)*Fb(1,1)+Fa(1,2)*Fb(2,1)&\n +Fa(1,3)*Fb(3,1)+Fa(1,4)*Fb(4,1)+Fa(1,5)*Fb(5,1))\n if (faux .ne. 0.0_SP) then\n ! calculate determinant of A\n det = 1.0_SP / faux\n ! update first column of inverse\n Fb(1,1)=Fb(1,1)*det\n Fb(2,1)=Fb(2,1)*det\n Fb(3,1)=Fb(3,1)*det\n Fb(4,1)=Fb(4,1)*det\n Fb(5,1)=Fb(5,1)*det\n ! calculate second column of inverse\n Fb(1,2) = det*(-Fa(1,2)*W(10)+Fa(1,3)*W( 9)-Fa(1,4)*W( 8)+Fa(1,5)*W( 7))\n Fb(2,2) = det*( Fa(1,1)*W(10)-Fa(1,3)*W( 6)+Fa(1,4)*W( 5)-Fa(1,5)*W( 4))\n Fb(3,2) = det*(-Fa(1,1)*W( 9)+Fa(1,2)*W( 6)-Fa(1,4)*W( 3)+Fa(1,5)*W( 2))\n Fb(4,2) = det*( Fa(1,1)*W( 8)-Fa(1,2)*W( 5)+Fa(1,3)*W( 3)-Fa(1,5)*W( 1))\n Fb(5,2) = det*(-Fa(1,1)*W( 7)+Fa(1,2)*W( 4)-Fa(1,3)*W( 2)+Fa(1,4)*W( 1))\n ! 3x3 determinants of rows 2-4-5\n W( 1) = Fa(2,1)*V( 5)-Fa(2,2)*V( 2)+Fa(2,3)*V( 1)\n W( 2) = Fa(2,1)*V( 6)-Fa(2,2)*V( 3)+Fa(2,4)*V( 1)\n W( 3) = Fa(2,1)*V( 7)-Fa(2,2)*V( 4)+Fa(2,5)*V( 1)\n W( 4) = Fa(2,1)*V( 8)-Fa(2,3)*V( 3)+Fa(2,4)*V( 2)\n W( 5) = Fa(2,1)*V( 9)-Fa(2,3)*V( 4)+Fa(2,5)*V( 2)\n W( 6) = Fa(2,1)*V(10)-Fa(2,4)*V( 4)+Fa(2,5)*V( 3)\n W( 7) = Fa(2,2)*V( 8)-Fa(2,3)*V( 6)+Fa(2,4)*V( 5)\n W( 8) = Fa(2,2)*V( 9)-Fa(2,3)*V( 7)+Fa(2,5)*V( 5)\n W( 9) = Fa(2,2)*V(10)-Fa(2,4)*V( 7)+Fa(2,5)*V( 6)\n W(10) = Fa(2,3)*V(10)-Fa(2,4)*V( 9)+Fa(2,5)*V( 8)\n ! calculate third column of inverse\n Fb(1,3) = det*( Fa(1,2)*W(10)-Fa(1,3)*W( 9)+Fa(1,4)*W( 8)-Fa(1,5)*W( 7))\n Fb(2,3) = det*(-Fa(1,1)*W(10)+Fa(1,3)*W( 6)-Fa(1,4)*W( 5)+Fa(1,5)*W( 4))\n Fb(3,3) = det*( Fa(1,1)*W( 9)-Fa(1,2)*W( 6)+Fa(1,4)*W( 3)-Fa(1,5)*W( 2))\n Fb(4,3) = det*(-Fa(1,1)*W( 8)+Fa(1,2)*W( 5)-Fa(1,3)*W( 3)+Fa(1,5)*W( 1))\n Fb(5,3) = det*( Fa(1,1)*W( 7)-Fa(1,2)*W( 4)+Fa(1,3)*W( 2)-Fa(1,4)*W( 1))\n ! 2x2 determinants of rows 1-2\n V( 1) = Fa(1,1)*Fa(2,2)-Fa(1,2)*Fa(2,1)\n V( 2) = Fa(1,1)*Fa(2,3)-Fa(1,3)*Fa(2,1)\n V( 3) = Fa(1,1)*Fa(2,4)-Fa(1,4)*Fa(2,1)\n V( 4) = Fa(1,1)*Fa(2,5)-Fa(1,5)*Fa(2,1)\n V( 5) = Fa(1,2)*Fa(2,3)-Fa(1,3)*Fa(2,2)\n V( 6) = Fa(1,2)*Fa(2,4)-Fa(1,4)*Fa(2,2)\n V( 7) = Fa(1,2)*Fa(2,5)-Fa(1,5)*Fa(2,2)\n V( 8) = Fa(1,3)*Fa(2,4)-Fa(1,4)*Fa(2,3)\n V( 9) = Fa(1,3)*Fa(2,5)-Fa(1,5)*Fa(2,3)\n V(10) = Fa(1,4)*Fa(2,5)-Fa(1,5)*Fa(2,4)\n ! 3x3 determinants of rows 1-2-3\n W( 1) = Fa(3,1)*V( 5)-Fa(3,2)*V( 2)+Fa(3,3)*V( 1)\n W( 2) = Fa(3,1)*V( 6)-Fa(3,2)*V( 3)+Fa(3,4)*V( 1)\n W( 3) = Fa(3,1)*V( 7)-Fa(3,2)*V( 4)+Fa(3,5)*V( 1)\n W( 4) = Fa(3,1)*V( 8)-Fa(3,3)*V( 3)+Fa(3,4)*V( 2)\n W( 5) = Fa(3,1)*V( 9)-Fa(3,3)*V( 4)+Fa(3,5)*V( 2)\n W( 6) = Fa(3,1)*V(10)-Fa(3,4)*V( 4)+Fa(3,5)*V( 3)\n W( 7) = Fa(3,2)*V( 8)-Fa(3,3)*V( 6)+Fa(3,4)*V( 5)\n W( 8) = Fa(3,2)*V( 9)-Fa(3,3)*V( 7)+Fa(3,5)*V( 5)\n W( 9) = Fa(3,2)*V(10)-Fa(3,4)*V( 7)+Fa(3,5)*V( 6)\n W(10) = Fa(3,3)*V(10)-Fa(3,4)*V( 9)+Fa(3,5)*V( 8)\n ! calculate fourth column of inverse\n Fb(1,4) = det*( Fa(5,2)*W(10)-Fa(5,3)*W( 9)+Fa(5,4)*W( 8)-Fa(5,5)*W( 7))\n Fb(2,4) = det*(-Fa(5,1)*W(10)+Fa(5,3)*W( 6)-Fa(5,4)*W( 5)+Fa(5,5)*W( 4))\n Fb(3,4) = det*( Fa(5,1)*W( 9)-Fa(5,2)*W( 6)+Fa(5,4)*W( 3)-Fa(5,5)*W( 2))\n Fb(4,4) = det*(-Fa(5,1)*W( 8)+Fa(5,2)*W( 5)-Fa(5,3)*W( 3)+Fa(5,5)*W( 1))\n Fb(5,4) = det*( Fa(5,1)*W( 7)-Fa(5,2)*W( 4)+Fa(5,3)*W( 2)-Fa(5,4)*W( 1))\n ! calculate fifth column of inverse\n Fb(1,5) = det*(-Fa(4,2)*W(10)+Fa(4,3)*W( 9)-Fa(4,4)*W( 8)+Fa(4,5)*W( 7))\n Fb(2,5) = det*( Fa(4,1)*W(10)-Fa(4,3)*W( 6)+Fa(4,4)*W( 5)-Fa(4,5)*W( 4))\n Fb(3,5) = det*(-Fa(4,1)*W( 9)+Fa(4,2)*W( 6)-Fa(4,4)*W( 3)+Fa(4,5)*W( 2))\n Fb(4,5) = det*( Fa(4,1)*W( 8)-Fa(4,2)*W( 5)+Fa(4,3)*W( 3)-Fa(4,5)*W( 1))\n Fb(5,5) = det*(-Fa(4,1)*W( 7)+Fa(4,2)*W( 4)-Fa(4,3)*W( 2)+Fa(4,4)*W( 1))\n\n bsuccess = .true.\n else\n bsuccess = .false.\n end if\n\n end subroutine mprim_invert5x5MatrixDirectSP\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_invert6x6MatrixDirectDP(Da,Db,bsuccess)\n\n!\n ! This subroutine directly inverts a 6x6 system without any pivoting.\n ! 'Da' is a 2-dimensional 6x6 m matrix. The inverse of Da is written\n ! to the 2-dimensional 6x6 matrix Db.\n !\n ! Warning: For speed reasons, there is no array bounds checking\n ! activated in this routine! Da and Db are assumed to be 6x6 arrays!\n!\n\n!\n ! source square matrix to be inverted\n real(DP), dimension(6,6), intent(in) :: Da\n!\n\n!\n ! destination square matrix; receives $ A^{-1} $.\n real(DP), dimension(6,6), intent(out) :: Db\n\n ! TRUE, if successful. FALSE if the system is indefinite.\n ! If FALSE, Db is undefined.\n logical, intent(out) :: bsuccess\n!\n\n!\n\n ! auxiliary variables\n real(DP) :: det,daux\n real(DP), dimension(15) :: U, W\n real(DP), dimension(20) :: V\n\n ! 2x2 determinants of rows 5-6\n U(1) = Da(5,1)*Da(6,2)-Da(5,2)*Da(6,1)\n U(2) = Da(5,1)*Da(6,3)-Da(5,3)*Da(6,1)\n U(3) = Da(5,1)*Da(6,4)-Da(5,4)*Da(6,1)\n U(4) = Da(5,1)*Da(6,5)-Da(5,5)*Da(6,1)\n U(5) = Da(5,1)*Da(6,6)-Da(5,6)*Da(6,1)\n U(6) = Da(5,2)*Da(6,3)-Da(5,3)*Da(6,2)\n U(7) = Da(5,2)*Da(6,4)-Da(5,4)*Da(6,2)\n U(8) = Da(5,2)*Da(6,5)-Da(5,5)*Da(6,2)\n U(9) = Da(5,2)*Da(6,6)-Da(5,6)*Da(6,2)\n U(10) = Da(5,3)*Da(6,4)-Da(5,4)*Da(6,3)\n U(11) = Da(5,3)*Da(6,5)-Da(5,5)*Da(6,3)\n U(12) = Da(5,3)*Da(6,6)-Da(5,6)*Da(6,3)\n U(13) = Da(5,4)*Da(6,5)-Da(5,5)*Da(6,4)\n U(14) = Da(5,4)*Da(6,6)-Da(5,6)*Da(6,4)\n U(15) = Da(5,5)*Da(6,6)-Da(5,6)*Da(6,5)\n ! 3x3 determinants of rows 4-5-6\n V(1) = Da(4,1)*U(6)-Da(4,2)*U(2)+Da(4,3)*U(1)\n V(2) = Da(4,1)*U(7)-Da(4,2)*U(3)+Da(4,4)*U(1)\n V(3) = Da(4,1)*U(8)-Da(4,2)*U(4)+Da(4,5)*U(1)\n V(4) = Da(4,1)*U(9)-Da(4,2)*U(5)+Da(4,6)*U(1)\n V(5) = Da(4,1)*U(10)-Da(4,3)*U(3)+Da(4,4)*U(2)\n V(6) = Da(4,1)*U(11)-Da(4,3)*U(4)+Da(4,5)*U(2)\n V(7) = Da(4,1)*U(12)-Da(4,3)*U(5)+Da(4,6)*U(2)\n V(8) = Da(4,1)*U(13)-Da(4,4)*U(4)+Da(4,5)*U(3)\n V(9) = Da(4,1)*U(14)-Da(4,4)*U(5)+Da(4,6)*U(3)\n V(10) = Da(4,1)*U(15)-Da(4,5)*U(5)+Da(4,6)*U(4)\n V(11) = Da(4,2)*U(10)-Da(4,3)*U(7)+Da(4,4)*U(6)\n V(12) = Da(4,2)*U(11)-Da(4,3)*U(8)+Da(4,5)*U(6)\n V(13) = Da(4,2)*U(12)-Da(4,3)*U(9)+Da(4,6)*U(6)\n V(14) = Da(4,2)*U(13)-Da(4,4)*U(8)+Da(4,5)*U(7)\n V(15) = Da(4,2)*U(14)-Da(4,4)*U(9)+Da(4,6)*U(7)\n V(16) = Da(4,2)*U(15)-Da(4,5)*U(9)+Da(4,6)*U(8)\n V(17) = Da(4,3)*U(13)-Da(4,4)*U(11)+Da(4,5)*U(10)\n V(18) = Da(4,3)*U(14)-Da(4,4)*U(12)+Da(4,6)*U(10)\n V(19) = Da(4,3)*U(15)-Da(4,5)*U(12)+Da(4,6)*U(11)\n V(20) = Da(4,4)*U(15)-Da(4,5)*U(14)+Da(4,6)*U(13)\n ! 4x4 determinants of rows 3-4-5-6\n W(1) = Da(3,1)*V(11)-Da(3,2)*V(5)+Da(3,3)*V(2)-Da(3,4)*V(1)\n W(2) = Da(3,1)*V(12)-Da(3,2)*V(6)+Da(3,3)*V(3)-Da(3,5)*V(1)\n W(3) = Da(3,1)*V(13)-Da(3,2)*V(7)+Da(3,3)*V(4)-Da(3,6)*V(1)\n W(4) = Da(3,1)*V(14)-Da(3,2)*V(8)+Da(3,4)*V(3)-Da(3,5)*V(2)\n W(5) = Da(3,1)*V(15)-Da(3,2)*V(9)+Da(3,4)*V(4)-Da(3,6)*V(2)\n W(6) = Da(3,1)*V(16)-Da(3,2)*V(10)+Da(3,5)*V(4)-Da(3,6)*V(3)\n W(7) = Da(3,1)*V(17)-Da(3,3)*V(8)+Da(3,4)*V(6)-Da(3,5)*V(5)\n W(8) = Da(3,1)*V(18)-Da(3,3)*V(9)+Da(3,4)*V(7)-Da(3,6)*V(5)\n W(9) = Da(3,1)*V(19)-Da(3,3)*V(10)+Da(3,5)*V(7)-Da(3,6)*V(6)\n W(10) = Da(3,1)*V(20)-Da(3,4)*V(10)+Da(3,5)*V(9)-Da(3,6)*V(8)\n W(11) = Da(3,2)*V(17)-Da(3,3)*V(14)+Da(3,4)*V(12)-Da(3,5)*V(11)\n W(12) = Da(3,2)*V(18)-Da(3,3)*V(15)+Da(3,4)*V(13)-Da(3,6)*V(11)\n W(13) = Da(3,2)*V(19)-Da(3,3)*V(16)+Da(3,5)*V(13)-Da(3,6)*V(12)\n W(14) = Da(3,2)*V(20)-Da(3,4)*V(16)+Da(3,5)*V(15)-Da(3,6)*V(14)\n W(15) = Da(3,3)*V(20)-Da(3,4)*V(19)+Da(3,5)*V(18)-Da(3,6)*V(17)\n ! pre-calculate first column of inverse\n Db(1,1) = Da(2,2)*W(15)-Da(2,3)*W(14)+Da(2,4)*W(13)-Da(2,5)*W(12)+Da(2,6)*W(11)\n Db(2,1) =-Da(2,1)*W(15)+Da(2,3)*W(10)-Da(2,4)*W(9)+Da(2,5)*W(8)-Da(2,6)*W(7)\n Db(3,1) = Da(2,1)*W(14)-Da(2,2)*W(10)+Da(2,4)*W(6)-Da(2,5)*W(5)+Da(2,6)*W(4)\n Db(4,1) =-Da(2,1)*W(13)+Da(2,2)*W(9)-Da(2,3)*W(6)+Da(2,5)*W(3)-Da(2,6)*W(2)\n Db(5,1) = Da(2,1)*W(12)-Da(2,2)*W(8)+Da(2,3)*W(5)-Da(2,4)*W(3)+Da(2,6)*W(1)\n Db(6,1) =-Da(2,1)*W(11)+Da(2,2)*W(7)-Da(2,3)*W(4)+Da(2,4)*W(2)-Da(2,5)*W(1)\n\n daux = (Da(1,1)*Db(1,1)+Da(1,2)*Db(2,1)+Da(1,3)*Db(3,1)+&\n Da(1,4)*Db(4,1)+Da(1,5)*Db(5,1)+Da(1,6)*Db(6,1))\n\n if (daux .ne. 0.0_DP) then\n\n ! calculate determinant of A\n det = 1.0_DP / daux\n ! update first column of inverse\n Db(1,1) = det*Db(1,1)\n Db(2,1) = det*Db(2,1)\n Db(3,1) = det*Db(3,1)\n Db(4,1) = det*Db(4,1)\n Db(5,1) = det*Db(5,1)\n Db(6,1) = det*Db(6,1)\n ! calculate second column of inverse\n Db(1,2) = det*(-Da(1,2)*W(15)+Da(1,3)*W(14)-Da(1,4)*W(13)+Da(1,5)*W(12)-Da(1,6)*W(11))\n Db(2,2) = det*( Da(1,1)*W(15)-Da(1,3)*W(10)+Da(1,4)*W(9)-Da(1,5)*W(8)+Da(1,6)*W(7))\n Db(3,2) = det*(-Da(1,1)*W(14)+Da(1,2)*W(10)-Da(1,4)*W(6)+Da(1,5)*W(5)-Da(1,6)*W(4))\n Db(4,2) = det*( Da(1,1)*W(13)-Da(1,2)*W(9)+Da(1,3)*W(6)-Da(1,5)*W(3)+Da(1,6)*W(2))\n Db(5,2) = det*(-Da(1,1)*W(12)+Da(1,2)*W(8)-Da(1,3)*W(5)+Da(1,4)*W(3)-Da(1,6)*W(1))\n Db(6,2) = det*( Da(1,1)*W(11)-Da(1,2)*W(7)+Da(1,3)*W(4)-Da(1,4)*W(2)+Da(1,5)*W(1))\n ! 3x3 determinants of rows 2-5-6\n V(1) = Da(2,1)*U(6)-Da(2,2)*U(2)+Da(2,3)*U(1)\n V(2) = Da(2,1)*U(7)-Da(2,2)*U(3)+Da(2,4)*U(1)\n V(3) = Da(2,1)*U(8)-Da(2,2)*U(4)+Da(2,5)*U(1)\n V(4) = Da(2,1)*U(9)-Da(2,2)*U(5)+Da(2,6)*U(1)\n V(5) = Da(2,1)*U(10)-Da(2,3)*U(3)+Da(2,4)*U(2)\n V(6) = Da(2,1)*U(11)-Da(2,3)*U(4)+Da(2,5)*U(2)\n V(7) = Da(2,1)*U(12)-Da(2,3)*U(5)+Da(2,6)*U(2)\n V(8) = Da(2,1)*U(13)-Da(2,4)*U(4)+Da(2,5)*U(3)\n V(9) = Da(2,1)*U(14)-Da(2,4)*U(5)+Da(2,6)*U(3)\n V(10) = Da(2,1)*U(15)-Da(2,5)*U(5)+Da(2,6)*U(4)\n V(11) = Da(2,2)*U(10)-Da(2,3)*U(7)+Da(2,4)*U(6)\n V(12) = Da(2,2)*U(11)-Da(2,3)*U(8)+Da(2,5)*U(6)\n V(13) = Da(2,2)*U(12)-Da(2,3)*U(9)+Da(2,6)*U(6)\n V(14) = Da(2,2)*U(13)-Da(2,4)*U(8)+Da(2,5)*U(7)\n V(15) = Da(2,2)*U(14)-Da(2,4)*U(9)+Da(2,6)*U(7)\n V(16) = Da(2,2)*U(15)-Da(2,5)*U(9)+Da(2,6)*U(8)\n V(17) = Da(2,3)*U(13)-Da(2,4)*U(11)+Da(2,5)*U(10)\n V(18) = Da(2,3)*U(14)-Da(2,4)*U(12)+Da(2,6)*U(10)\n V(19) = Da(2,3)*U(15)-Da(2,5)*U(12)+Da(2,6)*U(11)\n V(20) = Da(2,4)*U(15)-Da(2,5)*U(14)+Da(2,6)*U(13)\n ! 4x4 determinants of rows 1-2-5-6\n W(1) = Da(1,1)*V(11)-Da(1,2)*V(5)+Da(1,3)*V(2)-Da(1,4)*V(1)\n W(2) = Da(1,1)*V(12)-Da(1,2)*V(6)+Da(1,3)*V(3)-Da(1,5)*V(1)\n W(3) = Da(1,1)*V(13)-Da(1,2)*V(7)+Da(1,3)*V(4)-Da(1,6)*V(1)\n W(4) = Da(1,1)*V(14)-Da(1,2)*V(8)+Da(1,4)*V(3)-Da(1,5)*V(2)\n W(5) = Da(1,1)*V(15)-Da(1,2)*V(9)+Da(1,4)*V(4)-Da(1,6)*V(2)\n W(6) = Da(1,1)*V(16)-Da(1,2)*V(10)+Da(1,5)*V(4)-Da(1,6)*V(3)\n W(7) = Da(1,1)*V(17)-Da(1,3)*V(8)+Da(1,4)*V(6)-Da(1,5)*V(5)\n W(8) = Da(1,1)*V(18)-Da(1,3)*V(9)+Da(1,4)*V(7)-Da(1,6)*V(5)\n W(9) = Da(1,1)*V(19)-Da(1,3)*V(10)+Da(1,5)*V(7)-Da(1,6)*V(6)\n W(10) = Da(1,1)*V(20)-Da(1,4)*V(10)+Da(1,5)*V(9)-Da(1,6)*V(8)\n W(11) = Da(1,2)*V(17)-Da(1,3)*V(14)+Da(1,4)*V(12)-Da(1,5)*V(11)\n W(12) = Da(1,2)*V(18)-Da(1,3)*V(15)+Da(1,4)*V(13)-Da(1,6)*V(11)\n W(13) = Da(1,2)*V(19)-Da(1,3)*V(16)+Da(1,5)*V(13)-Da(1,6)*V(12)\n W(14) = Da(1,2)*V(20)-Da(1,4)*V(16)+Da(1,5)*V(15)-Da(1,6)*V(14)\n W(15) = Da(1,3)*V(20)-Da(1,4)*V(19)+Da(1,5)*V(18)-Da(1,6)*V(17)\n ! calculate third column of inverse\n Db(1,3) = det*( Da(4,2)*W(15)-Da(4,3)*W(14)+Da(4,4)*W(13)-Da(4,5)*W(12)+Da(4,6)*W(11))\n Db(2,3) = det*(-Da(4,1)*W(15)+Da(4,3)*W(10)-Da(4,4)*W(9)+Da(4,5)*W(8)-Da(4,6)*W(7))\n Db(3,3) = det*( Da(4,1)*W(14)-Da(4,2)*W(10)+Da(4,4)*W(6)-Da(4,5)*W(5)+Da(4,6)*W(4))\n Db(4,3) = det*(-Da(4,1)*W(13)+Da(4,2)*W(9)-Da(4,3)*W(6)+Da(4,5)*W(3)-Da(4,6)*W(2))\n Db(5,3) = det*( Da(4,1)*W(12)-Da(4,2)*W(8)+Da(4,3)*W(5)-Da(4,4)*W(3)+Da(4,6)*W(1))\n Db(6,3) = det*(-Da(4,1)*W(11)+Da(4,2)*W(7)-Da(4,3)*W(4)+Da(4,4)*W(2)-Da(4,5)*W(1))\n ! calculate fourth column of inverse\n Db(1,4) = det*(-Da(3,2)*W(15)+Da(3,3)*W(14)-Da(3,4)*W(13)+Da(3,5)*W(12)-Da(3,6)*W(11))\n Db(2,4) = det*( Da(3,1)*W(15)-Da(3,3)*W(10)+Da(3,4)*W(9)-Da(3,5)*W(8)+Da(3,6)*W(7))\n Db(3,4) = det*(-Da(3,1)*W(14)+Da(3,2)*W(10)-Da(3,4)*W(6)+Da(3,5)*W(5)-Da(3,6)*W(4))\n Db(4,4) = det*( Da(3,1)*W(13)-Da(3,2)*W(9)+Da(3,3)*W(6)-Da(3,5)*W(3)+Da(3,6)*W(2))\n Db(5,4) = det*(-Da(3,1)*W(12)+Da(3,2)*W(8)-Da(3,3)*W(5)+Da(3,4)*W(3)-Da(3,6)*W(1))\n Db(6,4) = det*( Da(3,1)*W(11)-Da(3,2)*W(7)+Da(3,3)*W(4)-Da(3,4)*W(2)+Da(3,5)*W(1))\n ! 2x2 determinants of rows 3-4\n U(1) = Da(3,1)*Da(4,2)-Da(3,2)*Da(4,1)\n U(2) = Da(3,1)*Da(4,3)-Da(3,3)*Da(4,1)\n U(3) = Da(3,1)*Da(4,4)-Da(3,4)*Da(4,1)\n U(4) = Da(3,1)*Da(4,5)-Da(3,5)*Da(4,1)\n U(5) = Da(3,1)*Da(4,6)-Da(3,6)*Da(4,1)\n U(6) = Da(3,2)*Da(4,3)-Da(3,3)*Da(4,2)\n U(7) = Da(3,2)*Da(4,4)-Da(3,4)*Da(4,2)\n U(8) = Da(3,2)*Da(4,5)-Da(3,5)*Da(4,2)\n U(9) = Da(3,2)*Da(4,6)-Da(3,6)*Da(4,2)\n U(10) = Da(3,3)*Da(4,4)-Da(3,4)*Da(4,3)\n U(11) = Da(3,3)*Da(4,5)-Da(3,5)*Da(4,3)\n U(12) = Da(3,3)*Da(4,6)-Da(3,6)*Da(4,3)\n U(13) = Da(3,4)*Da(4,5)-Da(3,5)*Da(4,4)\n U(14) = Da(3,4)*Da(4,6)-Da(3,6)*Da(4,4)\n U(15) = Da(3,5)*Da(4,6)-Da(3,6)*Da(4,5)\n ! 3x3 determinants of rows 2-3-4\n V(1) = Da(2,1)*U(6)-Da(2,2)*U(2)+Da(2,3)*U(1)\n V(2) = Da(2,1)*U(7)-Da(2,2)*U(3)+Da(2,4)*U(1)\n V(3) = Da(2,1)*U(8)-Da(2,2)*U(4)+Da(2,5)*U(1)\n V(4) = Da(2,1)*U(9)-Da(2,2)*U(5)+Da(2,6)*U(1)\n V(5) = Da(2,1)*U(10)-Da(2,3)*U(3)+Da(2,4)*U(2)\n V(6) = Da(2,1)*U(11)-Da(2,3)*U(4)+Da(2,5)*U(2)\n V(7) = Da(2,1)*U(12)-Da(2,3)*U(5)+Da(2,6)*U(2)\n V(8) = Da(2,1)*U(13)-Da(2,4)*U(4)+Da(2,5)*U(3)\n V(9) = Da(2,1)*U(14)-Da(2,4)*U(5)+Da(2,6)*U(3)\n V(10) = Da(2,1)*U(15)-Da(2,5)*U(5)+Da(2,6)*U(4)\n V(11) = Da(2,2)*U(10)-Da(2,3)*U(7)+Da(2,4)*U(6)\n V(12) = Da(2,2)*U(11)-Da(2,3)*U(8)+Da(2,5)*U(6)\n V(13) = Da(2,2)*U(12)-Da(2,3)*U(9)+Da(2,6)*U(6)\n V(14) = Da(2,2)*U(13)-Da(2,4)*U(8)+Da(2,5)*U(7)\n V(15) = Da(2,2)*U(14)-Da(2,4)*U(9)+Da(2,6)*U(7)\n V(16) = Da(2,2)*U(15)-Da(2,5)*U(9)+Da(2,6)*U(8)\n V(17) = Da(2,3)*U(13)-Da(2,4)*U(11)+Da(2,5)*U(10)\n V(18) = Da(2,3)*U(14)-Da(2,4)*U(12)+Da(2,6)*U(10)\n V(19) = Da(2,3)*U(15)-Da(2,5)*U(12)+Da(2,6)*U(11)\n V(20) = Da(2,4)*U(15)-Da(2,5)*U(14)+Da(2,6)*U(13)\n ! 4x4 determinants of rows 1-2-3-4\n W(1) = Da(1,1)*V(11)-Da(1,2)*V(5)+Da(1,3)*V(2)-Da(1,4)*V(1)\n W(2) = Da(1,1)*V(12)-Da(1,2)*V(6)+Da(1,3)*V(3)-Da(1,5)*V(1)\n W(3) = Da(1,1)*V(13)-Da(1,2)*V(7)+Da(1,3)*V(4)-Da(1,6)*V(1)\n W(4) = Da(1,1)*V(14)-Da(1,2)*V(8)+Da(1,4)*V(3)-Da(1,5)*V(2)\n W(5) = Da(1,1)*V(15)-Da(1,2)*V(9)+Da(1,4)*V(4)-Da(1,6)*V(2)\n W(6) = Da(1,1)*V(16)-Da(1,2)*V(10)+Da(1,5)*V(4)-Da(1,6)*V(3)\n W(7) = Da(1,1)*V(17)-Da(1,3)*V(8)+Da(1,4)*V(6)-Da(1,5)*V(5)\n W(8) = Da(1,1)*V(18)-Da(1,3)*V(9)+Da(1,4)*V(7)-Da(1,6)*V(5)\n W(9) = Da(1,1)*V(19)-Da(1,3)*V(10)+Da(1,5)*V(7)-Da(1,6)*V(6)\n W(10) = Da(1,1)*V(20)-Da(1,4)*V(10)+Da(1,5)*V(9)-Da(1,6)*V(8)\n W(11) = Da(1,2)*V(17)-Da(1,3)*V(14)+Da(1,4)*V(12)-Da(1,5)*V(11)\n W(12) = Da(1,2)*V(18)-Da(1,3)*V(15)+Da(1,4)*V(13)-Da(1,6)*V(11)\n W(13) = Da(1,2)*V(19)-Da(1,3)*V(16)+Da(1,5)*V(13)-Da(1,6)*V(12)\n W(14) = Da(1,2)*V(20)-Da(1,4)*V(16)+Da(1,5)*V(15)-Da(1,6)*V(14)\n W(15) = Da(1,3)*V(20)-Da(1,4)*V(19)+Da(1,5)*V(18)-Da(1,6)*V(17)\n ! calculate fifth column of inverse\n Db(1,5) = det*( Da(6,2)*W(15)-Da(6,3)*W(14)+Da(6,4)*W(13)-Da(6,5)*W(12)+Da(6,6)*W(11))\n Db(2,5) = det*(-Da(6,1)*W(15)+Da(6,3)*W(10)-Da(6,4)*W(9)+Da(6,5)*W(8)-Da(6,6)*W(7))\n Db(3,5) = det*( Da(6,1)*W(14)-Da(6,2)*W(10)+Da(6,4)*W(6)-Da(6,5)*W(5)+Da(6,6)*W(4))\n Db(4,5) = det*(-Da(6,1)*W(13)+Da(6,2)*W(9)-Da(6,3)*W(6)+Da(6,5)*W(3)-Da(6,6)*W(2))\n Db(5,5) = det*( Da(6,1)*W(12)-Da(6,2)*W(8)+Da(6,3)*W(5)-Da(6,4)*W(3)+Da(6,6)*W(1))\n Db(6,5) = det*(-Da(6,1)*W(11)+Da(6,2)*W(7)-Da(6,3)*W(4)+Da(6,4)*W(2)-Da(6,5)*W(1))\n ! calculate sixth column of inverse\n Db(1,6) = det*(-Da(5,2)*W(15)+Da(5,3)*W(14)-Da(5,4)*W(13)+Da(5,5)*W(12)-Da(5,6)*W(11))\n Db(2,6) = det*( Da(5,1)*W(15)-Da(5,3)*W(10)+Da(5,4)*W(9)-Da(5,5)*W(8)+Da(5,6)*W(7))\n Db(3,6) = det*(-Da(5,1)*W(14)+Da(5,2)*W(10)-Da(5,4)*W(6)+Da(5,5)*W(5)-Da(5,6)*W(4))\n Db(4,6) = det*( Da(5,1)*W(13)-Da(5,2)*W(9)+Da(5,3)*W(6)-Da(5,5)*W(3)+Da(5,6)*W(2))\n Db(5,6) = det*(-Da(5,1)*W(12)+Da(5,2)*W(8)-Da(5,3)*W(5)+Da(5,4)*W(3)-Da(5,6)*W(1))\n Db(6,6) = det*( Da(5,1)*W(11)-Da(5,2)*W(7)+Da(5,3)*W(4)-Da(5,4)*W(2)+Da(5,5)*W(1))\n\n bsuccess = .true.\n\n else\n\n bsuccess = .false.\n\n end if\n\n end subroutine mprim_invert6x6MatrixDirectDP\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_invert6x6MatrixDirectSP(Fa,Fb,bsuccess)\n\n!\n ! This subroutine directly inverts a 6x6 system without any pivoting.\n ! 'Fa' is a 2-dimensional 6x6 m matrix. The inverse of Fa is written\n ! to the 2-dimensional 6x6 matrix Fb.\n !\n ! Warning: For speed reasons, there is no array bounds checking\n ! activated in this routine! Fa and Fb are assumed to be 6x6 arrays!\n!\n\n!\n ! source square matrix to be inverted\n real(SP), dimension(6,6), intent(in) :: Fa\n!\n\n!\n ! destination square matrix; receives $ A^{-1} $.\n real(SP), dimension(6,6), intent(out) :: Fb\n\n ! TRUE, if successful. FALSE if the system is indefinite.\n ! If FALSE, Fb is undefined.\n logical, intent(out) :: bsuccess\n!\n\n!\n\n ! auxiliary variables\n real(SP) :: det,faux\n real(SP), dimension(15) :: U, W\n real(SP), dimension(20) :: V\n\n ! 2x2 determinants of rows 5-6\n U(1) = Fa(5,1)*Fa(6,2)-Fa(5,2)*Fa(6,1)\n U(2) = Fa(5,1)*Fa(6,3)-Fa(5,3)*Fa(6,1)\n U(3) = Fa(5,1)*Fa(6,4)-Fa(5,4)*Fa(6,1)\n U(4) = Fa(5,1)*Fa(6,5)-Fa(5,5)*Fa(6,1)\n U(5) = Fa(5,1)*Fa(6,6)-Fa(5,6)*Fa(6,1)\n U(6) = Fa(5,2)*Fa(6,3)-Fa(5,3)*Fa(6,2)\n U(7) = Fa(5,2)*Fa(6,4)-Fa(5,4)*Fa(6,2)\n U(8) = Fa(5,2)*Fa(6,5)-Fa(5,5)*Fa(6,2)\n U(9) = Fa(5,2)*Fa(6,6)-Fa(5,6)*Fa(6,2)\n U(10) = Fa(5,3)*Fa(6,4)-Fa(5,4)*Fa(6,3)\n U(11) = Fa(5,3)*Fa(6,5)-Fa(5,5)*Fa(6,3)\n U(12) = Fa(5,3)*Fa(6,6)-Fa(5,6)*Fa(6,3)\n U(13) = Fa(5,4)*Fa(6,5)-Fa(5,5)*Fa(6,4)\n U(14) = Fa(5,4)*Fa(6,6)-Fa(5,6)*Fa(6,4)\n U(15) = Fa(5,5)*Fa(6,6)-Fa(5,6)*Fa(6,5)\n ! 3x3 determinants of rows 4-5-6\n V(1) = Fa(4,1)*U(6)-Fa(4,2)*U(2)+Fa(4,3)*U(1)\n V(2) = Fa(4,1)*U(7)-Fa(4,2)*U(3)+Fa(4,4)*U(1)\n V(3) = Fa(4,1)*U(8)-Fa(4,2)*U(4)+Fa(4,5)*U(1)\n V(4) = Fa(4,1)*U(9)-Fa(4,2)*U(5)+Fa(4,6)*U(1)\n V(5) = Fa(4,1)*U(10)-Fa(4,3)*U(3)+Fa(4,4)*U(2)\n V(6) = Fa(4,1)*U(11)-Fa(4,3)*U(4)+Fa(4,5)*U(2)\n V(7) = Fa(4,1)*U(12)-Fa(4,3)*U(5)+Fa(4,6)*U(2)\n V(8) = Fa(4,1)*U(13)-Fa(4,4)*U(4)+Fa(4,5)*U(3)\n V(9) = Fa(4,1)*U(14)-Fa(4,4)*U(5)+Fa(4,6)*U(3)\n V(10) = Fa(4,1)*U(15)-Fa(4,5)*U(5)+Fa(4,6)*U(4)\n V(11) = Fa(4,2)*U(10)-Fa(4,3)*U(7)+Fa(4,4)*U(6)\n V(12) = Fa(4,2)*U(11)-Fa(4,3)*U(8)+Fa(4,5)*U(6)\n V(13) = Fa(4,2)*U(12)-Fa(4,3)*U(9)+Fa(4,6)*U(6)\n V(14) = Fa(4,2)*U(13)-Fa(4,4)*U(8)+Fa(4,5)*U(7)\n V(15) = Fa(4,2)*U(14)-Fa(4,4)*U(9)+Fa(4,6)*U(7)\n V(16) = Fa(4,2)*U(15)-Fa(4,5)*U(9)+Fa(4,6)*U(8)\n V(17) = Fa(4,3)*U(13)-Fa(4,4)*U(11)+Fa(4,5)*U(10)\n V(18) = Fa(4,3)*U(14)-Fa(4,4)*U(12)+Fa(4,6)*U(10)\n V(19) = Fa(4,3)*U(15)-Fa(4,5)*U(12)+Fa(4,6)*U(11)\n V(20) = Fa(4,4)*U(15)-Fa(4,5)*U(14)+Fa(4,6)*U(13)\n ! 4x4 determinants of rows 3-4-5-6\n W(1) = Fa(3,1)*V(11)-Fa(3,2)*V(5)+Fa(3,3)*V(2)-Fa(3,4)*V(1)\n W(2) = Fa(3,1)*V(12)-Fa(3,2)*V(6)+Fa(3,3)*V(3)-Fa(3,5)*V(1)\n W(3) = Fa(3,1)*V(13)-Fa(3,2)*V(7)+Fa(3,3)*V(4)-Fa(3,6)*V(1)\n W(4) = Fa(3,1)*V(14)-Fa(3,2)*V(8)+Fa(3,4)*V(3)-Fa(3,5)*V(2)\n W(5) = Fa(3,1)*V(15)-Fa(3,2)*V(9)+Fa(3,4)*V(4)-Fa(3,6)*V(2)\n W(6) = Fa(3,1)*V(16)-Fa(3,2)*V(10)+Fa(3,5)*V(4)-Fa(3,6)*V(3)\n W(7) = Fa(3,1)*V(17)-Fa(3,3)*V(8)+Fa(3,4)*V(6)-Fa(3,5)*V(5)\n W(8) = Fa(3,1)*V(18)-Fa(3,3)*V(9)+Fa(3,4)*V(7)-Fa(3,6)*V(5)\n W(9) = Fa(3,1)*V(19)-Fa(3,3)*V(10)+Fa(3,5)*V(7)-Fa(3,6)*V(6)\n W(10) = Fa(3,1)*V(20)-Fa(3,4)*V(10)+Fa(3,5)*V(9)-Fa(3,6)*V(8)\n W(11) = Fa(3,2)*V(17)-Fa(3,3)*V(14)+Fa(3,4)*V(12)-Fa(3,5)*V(11)\n W(12) = Fa(3,2)*V(18)-Fa(3,3)*V(15)+Fa(3,4)*V(13)-Fa(3,6)*V(11)\n W(13) = Fa(3,2)*V(19)-Fa(3,3)*V(16)+Fa(3,5)*V(13)-Fa(3,6)*V(12)\n W(14) = Fa(3,2)*V(20)-Fa(3,4)*V(16)+Fa(3,5)*V(15)-Fa(3,6)*V(14)\n W(15) = Fa(3,3)*V(20)-Fa(3,4)*V(19)+Fa(3,5)*V(18)-Fa(3,6)*V(17)\n ! pre-calculate first column of inverse\n Fb(1,1) = Fa(2,2)*W(15)-Fa(2,3)*W(14)+Fa(2,4)*W(13)-Fa(2,5)*W(12)+Fa(2,6)*W(11)\n Fb(2,1) =-Fa(2,1)*W(15)+Fa(2,3)*W(10)-Fa(2,4)*W(9)+Fa(2,5)*W(8)-Fa(2,6)*W(7)\n Fb(3,1) = Fa(2,1)*W(14)-Fa(2,2)*W(10)+Fa(2,4)*W(6)-Fa(2,5)*W(5)+Fa(2,6)*W(4)\n Fb(4,1) =-Fa(2,1)*W(13)+Fa(2,2)*W(9)-Fa(2,3)*W(6)+Fa(2,5)*W(3)-Fa(2,6)*W(2)\n Fb(5,1) = Fa(2,1)*W(12)-Fa(2,2)*W(8)+Fa(2,3)*W(5)-Fa(2,4)*W(3)+Fa(2,6)*W(1)\n Fb(6,1) =-Fa(2,1)*W(11)+Fa(2,2)*W(7)-Fa(2,3)*W(4)+Fa(2,4)*W(2)-Fa(2,5)*W(1)\n\n faux = (Fa(1,1)*Fb(1,1)+Fa(1,2)*Fb(2,1)+Fa(1,3)*Fb(3,1)+&\n Fa(1,4)*Fb(4,1)+Fa(1,5)*Fb(5,1)+Fa(1,6)*Fb(6,1))\n\n if (faux .ne. 0.0_SP) then\n\n ! calculate determinant of A\n det = 1.0_SP / faux\n ! update first column of inverse\n Fb(1,1) = det*Fb(1,1)\n Fb(2,1) = det*Fb(2,1)\n Fb(3,1) = det*Fb(3,1)\n Fb(4,1) = det*Fb(4,1)\n Fb(5,1) = det*Fb(5,1)\n Fb(6,1) = det*Fb(6,1)\n ! calculate second column of inverse\n Fb(1,2) = det*(-Fa(1,2)*W(15)+Fa(1,3)*W(14)-Fa(1,4)*W(13)+Fa(1,5)*W(12)-Fa(1,6)*W(11))\n Fb(2,2) = det*( Fa(1,1)*W(15)-Fa(1,3)*W(10)+Fa(1,4)*W(9)-Fa(1,5)*W(8)+Fa(1,6)*W(7))\n Fb(3,2) = det*(-Fa(1,1)*W(14)+Fa(1,2)*W(10)-Fa(1,4)*W(6)+Fa(1,5)*W(5)-Fa(1,6)*W(4))\n Fb(4,2) = det*( Fa(1,1)*W(13)-Fa(1,2)*W(9)+Fa(1,3)*W(6)-Fa(1,5)*W(3)+Fa(1,6)*W(2))\n Fb(5,2) = det*(-Fa(1,1)*W(12)+Fa(1,2)*W(8)-Fa(1,3)*W(5)+Fa(1,4)*W(3)-Fa(1,6)*W(1))\n Fb(6,2) = det*( Fa(1,1)*W(11)-Fa(1,2)*W(7)+Fa(1,3)*W(4)-Fa(1,4)*W(2)+Fa(1,5)*W(1))\n ! 3x3 determinants of rows 2-5-6\n V(1) = Fa(2,1)*U(6)-Fa(2,2)*U(2)+Fa(2,3)*U(1)\n V(2) = Fa(2,1)*U(7)-Fa(2,2)*U(3)+Fa(2,4)*U(1)\n V(3) = Fa(2,1)*U(8)-Fa(2,2)*U(4)+Fa(2,5)*U(1)\n V(4) = Fa(2,1)*U(9)-Fa(2,2)*U(5)+Fa(2,6)*U(1)\n V(5) = Fa(2,1)*U(10)-Fa(2,3)*U(3)+Fa(2,4)*U(2)\n V(6) = Fa(2,1)*U(11)-Fa(2,3)*U(4)+Fa(2,5)*U(2)\n V(7) = Fa(2,1)*U(12)-Fa(2,3)*U(5)+Fa(2,6)*U(2)\n V(8) = Fa(2,1)*U(13)-Fa(2,4)*U(4)+Fa(2,5)*U(3)\n V(9) = Fa(2,1)*U(14)-Fa(2,4)*U(5)+Fa(2,6)*U(3)\n V(10) = Fa(2,1)*U(15)-Fa(2,5)*U(5)+Fa(2,6)*U(4)\n V(11) = Fa(2,2)*U(10)-Fa(2,3)*U(7)+Fa(2,4)*U(6)\n V(12) = Fa(2,2)*U(11)-Fa(2,3)*U(8)+Fa(2,5)*U(6)\n V(13) = Fa(2,2)*U(12)-Fa(2,3)*U(9)+Fa(2,6)*U(6)\n V(14) = Fa(2,2)*U(13)-Fa(2,4)*U(8)+Fa(2,5)*U(7)\n V(15) = Fa(2,2)*U(14)-Fa(2,4)*U(9)+Fa(2,6)*U(7)\n V(16) = Fa(2,2)*U(15)-Fa(2,5)*U(9)+Fa(2,6)*U(8)\n V(17) = Fa(2,3)*U(13)-Fa(2,4)*U(11)+Fa(2,5)*U(10)\n V(18) = Fa(2,3)*U(14)-Fa(2,4)*U(12)+Fa(2,6)*U(10)\n V(19) = Fa(2,3)*U(15)-Fa(2,5)*U(12)+Fa(2,6)*U(11)\n V(20) = Fa(2,4)*U(15)-Fa(2,5)*U(14)+Fa(2,6)*U(13)\n ! 4x4 determinants of rows 1-2-5-6\n W(1) = Fa(1,1)*V(11)-Fa(1,2)*V(5)+Fa(1,3)*V(2)-Fa(1,4)*V(1)\n W(2) = Fa(1,1)*V(12)-Fa(1,2)*V(6)+Fa(1,3)*V(3)-Fa(1,5)*V(1)\n W(3) = Fa(1,1)*V(13)-Fa(1,2)*V(7)+Fa(1,3)*V(4)-Fa(1,6)*V(1)\n W(4) = Fa(1,1)*V(14)-Fa(1,2)*V(8)+Fa(1,4)*V(3)-Fa(1,5)*V(2)\n W(5) = Fa(1,1)*V(15)-Fa(1,2)*V(9)+Fa(1,4)*V(4)-Fa(1,6)*V(2)\n W(6) = Fa(1,1)*V(16)-Fa(1,2)*V(10)+Fa(1,5)*V(4)-Fa(1,6)*V(3)\n W(7) = Fa(1,1)*V(17)-Fa(1,3)*V(8)+Fa(1,4)*V(6)-Fa(1,5)*V(5)\n W(8) = Fa(1,1)*V(18)-Fa(1,3)*V(9)+Fa(1,4)*V(7)-Fa(1,6)*V(5)\n W(9) = Fa(1,1)*V(19)-Fa(1,3)*V(10)+Fa(1,5)*V(7)-Fa(1,6)*V(6)\n W(10) = Fa(1,1)*V(20)-Fa(1,4)*V(10)+Fa(1,5)*V(9)-Fa(1,6)*V(8)\n W(11) = Fa(1,2)*V(17)-Fa(1,3)*V(14)+Fa(1,4)*V(12)-Fa(1,5)*V(11)\n W(12) = Fa(1,2)*V(18)-Fa(1,3)*V(15)+Fa(1,4)*V(13)-Fa(1,6)*V(11)\n W(13) = Fa(1,2)*V(19)-Fa(1,3)*V(16)+Fa(1,5)*V(13)-Fa(1,6)*V(12)\n W(14) = Fa(1,2)*V(20)-Fa(1,4)*V(16)+Fa(1,5)*V(15)-Fa(1,6)*V(14)\n W(15) = Fa(1,3)*V(20)-Fa(1,4)*V(19)+Fa(1,5)*V(18)-Fa(1,6)*V(17)\n ! calculate third column of inverse\n Fb(1,3) = det*( Fa(4,2)*W(15)-Fa(4,3)*W(14)+Fa(4,4)*W(13)-Fa(4,5)*W(12)+Fa(4,6)*W(11))\n Fb(2,3) = det*(-Fa(4,1)*W(15)+Fa(4,3)*W(10)-Fa(4,4)*W(9)+Fa(4,5)*W(8)-Fa(4,6)*W(7))\n Fb(3,3) = det*( Fa(4,1)*W(14)-Fa(4,2)*W(10)+Fa(4,4)*W(6)-Fa(4,5)*W(5)+Fa(4,6)*W(4))\n Fb(4,3) = det*(-Fa(4,1)*W(13)+Fa(4,2)*W(9)-Fa(4,3)*W(6)+Fa(4,5)*W(3)-Fa(4,6)*W(2))\n Fb(5,3) = det*( Fa(4,1)*W(12)-Fa(4,2)*W(8)+Fa(4,3)*W(5)-Fa(4,4)*W(3)+Fa(4,6)*W(1))\n Fb(6,3) = det*(-Fa(4,1)*W(11)+Fa(4,2)*W(7)-Fa(4,3)*W(4)+Fa(4,4)*W(2)-Fa(4,5)*W(1))\n ! calculate fourth column of inverse\n Fb(1,4) = det*(-Fa(3,2)*W(15)+Fa(3,3)*W(14)-Fa(3,4)*W(13)+Fa(3,5)*W(12)-Fa(3,6)*W(11))\n Fb(2,4) = det*( Fa(3,1)*W(15)-Fa(3,3)*W(10)+Fa(3,4)*W(9)-Fa(3,5)*W(8)+Fa(3,6)*W(7))\n Fb(3,4) = det*(-Fa(3,1)*W(14)+Fa(3,2)*W(10)-Fa(3,4)*W(6)+Fa(3,5)*W(5)-Fa(3,6)*W(4))\n Fb(4,4) = det*( Fa(3,1)*W(13)-Fa(3,2)*W(9)+Fa(3,3)*W(6)-Fa(3,5)*W(3)+Fa(3,6)*W(2))\n Fb(5,4) = det*(-Fa(3,1)*W(12)+Fa(3,2)*W(8)-Fa(3,3)*W(5)+Fa(3,4)*W(3)-Fa(3,6)*W(1))\n Fb(6,4) = det*( Fa(3,1)*W(11)-Fa(3,2)*W(7)+Fa(3,3)*W(4)-Fa(3,4)*W(2)+Fa(3,5)*W(1))\n ! 2x2 determinants of rows 3-4\n U(1) = Fa(3,1)*Fa(4,2)-Fa(3,2)*Fa(4,1)\n U(2) = Fa(3,1)*Fa(4,3)-Fa(3,3)*Fa(4,1)\n U(3) = Fa(3,1)*Fa(4,4)-Fa(3,4)*Fa(4,1)\n U(4) = Fa(3,1)*Fa(4,5)-Fa(3,5)*Fa(4,1)\n U(5) = Fa(3,1)*Fa(4,6)-Fa(3,6)*Fa(4,1)\n U(6) = Fa(3,2)*Fa(4,3)-Fa(3,3)*Fa(4,2)\n U(7) = Fa(3,2)*Fa(4,4)-Fa(3,4)*Fa(4,2)\n U(8) = Fa(3,2)*Fa(4,5)-Fa(3,5)*Fa(4,2)\n U(9) = Fa(3,2)*Fa(4,6)-Fa(3,6)*Fa(4,2)\n U(10) = Fa(3,3)*Fa(4,4)-Fa(3,4)*Fa(4,3)\n U(11) = Fa(3,3)*Fa(4,5)-Fa(3,5)*Fa(4,3)\n U(12) = Fa(3,3)*Fa(4,6)-Fa(3,6)*Fa(4,3)\n U(13) = Fa(3,4)*Fa(4,5)-Fa(3,5)*Fa(4,4)\n U(14) = Fa(3,4)*Fa(4,6)-Fa(3,6)*Fa(4,4)\n U(15) = Fa(3,5)*Fa(4,6)-Fa(3,6)*Fa(4,5)\n ! 3x3 determinants of rows 2-3-4\n V(1) = Fa(2,1)*U(6)-Fa(2,2)*U(2)+Fa(2,3)*U(1)\n V(2) = Fa(2,1)*U(7)-Fa(2,2)*U(3)+Fa(2,4)*U(1)\n V(3) = Fa(2,1)*U(8)-Fa(2,2)*U(4)+Fa(2,5)*U(1)\n V(4) = Fa(2,1)*U(9)-Fa(2,2)*U(5)+Fa(2,6)*U(1)\n V(5) = Fa(2,1)*U(10)-Fa(2,3)*U(3)+Fa(2,4)*U(2)\n V(6) = Fa(2,1)*U(11)-Fa(2,3)*U(4)+Fa(2,5)*U(2)\n V(7) = Fa(2,1)*U(12)-Fa(2,3)*U(5)+Fa(2,6)*U(2)\n V(8) = Fa(2,1)*U(13)-Fa(2,4)*U(4)+Fa(2,5)*U(3)\n V(9) = Fa(2,1)*U(14)-Fa(2,4)*U(5)+Fa(2,6)*U(3)\n V(10) = Fa(2,1)*U(15)-Fa(2,5)*U(5)+Fa(2,6)*U(4)\n V(11) = Fa(2,2)*U(10)-Fa(2,3)*U(7)+Fa(2,4)*U(6)\n V(12) = Fa(2,2)*U(11)-Fa(2,3)*U(8)+Fa(2,5)*U(6)\n V(13) = Fa(2,2)*U(12)-Fa(2,3)*U(9)+Fa(2,6)*U(6)\n V(14) = Fa(2,2)*U(13)-Fa(2,4)*U(8)+Fa(2,5)*U(7)\n V(15) = Fa(2,2)*U(14)-Fa(2,4)*U(9)+Fa(2,6)*U(7)\n V(16) = Fa(2,2)*U(15)-Fa(2,5)*U(9)+Fa(2,6)*U(8)\n V(17) = Fa(2,3)*U(13)-Fa(2,4)*U(11)+Fa(2,5)*U(10)\n V(18) = Fa(2,3)*U(14)-Fa(2,4)*U(12)+Fa(2,6)*U(10)\n V(19) = Fa(2,3)*U(15)-Fa(2,5)*U(12)+Fa(2,6)*U(11)\n V(20) = Fa(2,4)*U(15)-Fa(2,5)*U(14)+Fa(2,6)*U(13)\n ! 4x4 determinants of rows 1-2-3-4\n W(1) = Fa(1,1)*V(11)-Fa(1,2)*V(5)+Fa(1,3)*V(2)-Fa(1,4)*V(1)\n W(2) = Fa(1,1)*V(12)-Fa(1,2)*V(6)+Fa(1,3)*V(3)-Fa(1,5)*V(1)\n W(3) = Fa(1,1)*V(13)-Fa(1,2)*V(7)+Fa(1,3)*V(4)-Fa(1,6)*V(1)\n W(4) = Fa(1,1)*V(14)-Fa(1,2)*V(8)+Fa(1,4)*V(3)-Fa(1,5)*V(2)\n W(5) = Fa(1,1)*V(15)-Fa(1,2)*V(9)+Fa(1,4)*V(4)-Fa(1,6)*V(2)\n W(6) = Fa(1,1)*V(16)-Fa(1,2)*V(10)+Fa(1,5)*V(4)-Fa(1,6)*V(3)\n W(7) = Fa(1,1)*V(17)-Fa(1,3)*V(8)+Fa(1,4)*V(6)-Fa(1,5)*V(5)\n W(8) = Fa(1,1)*V(18)-Fa(1,3)*V(9)+Fa(1,4)*V(7)-Fa(1,6)*V(5)\n W(9) = Fa(1,1)*V(19)-Fa(1,3)*V(10)+Fa(1,5)*V(7)-Fa(1,6)*V(6)\n W(10) = Fa(1,1)*V(20)-Fa(1,4)*V(10)+Fa(1,5)*V(9)-Fa(1,6)*V(8)\n W(11) = Fa(1,2)*V(17)-Fa(1,3)*V(14)+Fa(1,4)*V(12)-Fa(1,5)*V(11)\n W(12) = Fa(1,2)*V(18)-Fa(1,3)*V(15)+Fa(1,4)*V(13)-Fa(1,6)*V(11)\n W(13) = Fa(1,2)*V(19)-Fa(1,3)*V(16)+Fa(1,5)*V(13)-Fa(1,6)*V(12)\n W(14) = Fa(1,2)*V(20)-Fa(1,4)*V(16)+Fa(1,5)*V(15)-Fa(1,6)*V(14)\n W(15) = Fa(1,3)*V(20)-Fa(1,4)*V(19)+Fa(1,5)*V(18)-Fa(1,6)*V(17)\n ! calculate fifth column of inverse\n Fb(1,5) = det*( Fa(6,2)*W(15)-Fa(6,3)*W(14)+Fa(6,4)*W(13)-Fa(6,5)*W(12)+Fa(6,6)*W(11))\n Fb(2,5) = det*(-Fa(6,1)*W(15)+Fa(6,3)*W(10)-Fa(6,4)*W(9)+Fa(6,5)*W(8)-Fa(6,6)*W(7))\n Fb(3,5) = det*( Fa(6,1)*W(14)-Fa(6,2)*W(10)+Fa(6,4)*W(6)-Fa(6,5)*W(5)+Fa(6,6)*W(4))\n Fb(4,5) = det*(-Fa(6,1)*W(13)+Fa(6,2)*W(9)-Fa(6,3)*W(6)+Fa(6,5)*W(3)-Fa(6,6)*W(2))\n Fb(5,5) = det*( Fa(6,1)*W(12)-Fa(6,2)*W(8)+Fa(6,3)*W(5)-Fa(6,4)*W(3)+Fa(6,6)*W(1))\n Fb(6,5) = det*(-Fa(6,1)*W(11)+Fa(6,2)*W(7)-Fa(6,3)*W(4)+Fa(6,4)*W(2)-Fa(6,5)*W(1))\n ! calculate sixth column of inverse\n Fb(1,6) = det*(-Fa(5,2)*W(15)+Fa(5,3)*W(14)-Fa(5,4)*W(13)+Fa(5,5)*W(12)-Fa(5,6)*W(11))\n Fb(2,6) = det*( Fa(5,1)*W(15)-Fa(5,3)*W(10)+Fa(5,4)*W(9)-Fa(5,5)*W(8)+Fa(5,6)*W(7))\n Fb(3,6) = det*(-Fa(5,1)*W(14)+Fa(5,2)*W(10)-Fa(5,4)*W(6)+Fa(5,5)*W(5)-Fa(5,6)*W(4))\n Fb(4,6) = det*( Fa(5,1)*W(13)-Fa(5,2)*W(9)+Fa(5,3)*W(6)-Fa(5,5)*W(3)+Fa(5,6)*W(2))\n Fb(5,6) = det*(-Fa(5,1)*W(12)+Fa(5,2)*W(8)-Fa(5,3)*W(5)+Fa(5,4)*W(3)-Fa(5,6)*W(1))\n Fb(6,6) = det*( Fa(5,1)*W(11)-Fa(5,2)*W(7)+Fa(5,3)*W(4)-Fa(5,4)*W(2)+Fa(5,5)*W(1))\n\n bsuccess = .true.\n\n else\n\n bsuccess = .false.\n\n end if\n\n end subroutine mprim_invert6x6MatrixDirectSP\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_invertMatrixPivotDP(Da,ndim,bsuccess)\n\n!\n ! This subroutine directly inverts a (ndim x ndim) system with pivoting.\n ! 'Da' is a 2-dimensional (ndim x ndim) matrix and will be replaced\n ! by its inverse.\n!\n\n!\n ! Dimension of the matrix Da.\n integer, intent(in) :: ndim\n!\n\n!\n ! source square matrix to be inverted\n real(DP), dimension(ndim,ndim), intent(inout) :: Da\n\n ! TRUE, if successful. FALSE if the system is indefinite.\n ! If FALSE, Db is undefined.\n logical, intent(out) :: bsuccess\n!\n\n!\n\n ! local variables\n integer, dimension(ndim) :: Kindx,Kindy\n\n real(DP) :: dpivot,daux\n integer :: idim1,idim2,ix,iy,indx,indy\n\n ! Perform factorisation of matrix Da\n\n bsuccess = .false.\n\n ! Initialisation\n Kindx=0\n Kindy=0\n\n do idim1=1,ndim\n\n ! Determine pivotal element\n dpivot=0\n\n do iy=1,ndim\n if (Kindy(iy) /= 0) cycle\n\n do ix=1,ndim\n if (Kindx(ix) /= 0) cycle\n\n if (abs(Da(ix,iy)) .le. abs(dpivot)) cycle\n dpivot=Da(ix,iy); indx=ix; indy=iy\n end do\n end do\n\n ! Return if pivotal element is zero\n if (dpivot .eq. 0.0_DP) return\n\n Kindx(indx)=indy; Kindy(indy)=indx; Da(indx,indy)=1._DP&\n &/dpivot\n\n do idim2=1,ndim\n if (idim2 == indy) cycle\n Da(1:indx-1,idim2)=Da(1:indx-1,idim2)-Da(1:indx-1, &\n & indy)*Da(indx,idim2)/dpivot\n Da(indx+1:ndim,idim2)=Da(indx+1:ndim,idim2)-Da(indx+1:ndim&\n &,indy)*Da(indx,idim2)/dpivot\n end do\n\n do ix=1,ndim\n if (ix /= indx) Da(ix,indy)=Da(ix,indy)/dpivot\n end do\n\n do iy=1,ndim\n if (iy /= indy) Da(indx,iy)=-Da(indx,iy)/dpivot\n end do\n end do\n\n do ix=1,ndim\n if (Kindx(ix) == ix) cycle\n\n do iy=1,ndim\n if (Kindx(iy) == ix) exit\n end do\n\n do idim1=1,ndim\n daux=Da(ix,idim1)\n Da(ix,idim1)=Da(iy,idim1)\n Da(iy,idim1)=daux\n end do\n\n Kindx(iy)=Kindx(ix); Kindx(ix)=ix\n end do\n\n do ix=1,ndim\n if (Kindy(ix) == ix) cycle\n\n do iy=1,ndim\n if (Kindy(iy) == ix) exit\n end do\n\n do idim1=1,ndim\n daux=Da(idim1,ix)\n Da(idim1,ix)=Da(idim1,iy)\n Da(idim1,iy)=daux\n end do\n\n Kindy(iy)=Kindy(ix); Kindy(ix)=ix\n end do\n\n bsuccess = .true.\n\n end subroutine mprim_invertMatrixPivotDP\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_invertMatrixPivotSP(Fa,ndim,bsuccess)\n\n!\n ! This subroutine directly inverts a (ndim x ndim) system with pivoting.\n ! 'Fa' is a 2-dimensional (ndim x ndim) matrix and will be replaced\n ! by its inverse.\n!\n\n!\n ! Dimension of the matrix Fa.\n integer, intent(in) :: ndim\n!\n\n!\n ! source square matrix to be inverted\n real(SP), dimension(ndim,ndim), intent(inout) :: Fa\n\n ! TRUE, if successful. FALSE if the system is indefinite.\n ! If FALSE, Db is undefined.\n logical, intent(out) :: bsuccess\n!\n\n!\n\n ! local variables\n integer, dimension(ndim) :: Kindx,Kindy\n\n real(SP) :: fpivot,faux\n integer :: idim1,idim2,ix,iy,indx,indy\n\n ! Perform factorisation of matrix Fa\n\n bsuccess = .false.\n\n ! Initialisation\n Kindx=0\n Kindy=0\n\n do idim1=1,ndim\n\n ! Determine pivotal element\n fpivot=0\n\n do iy=1,ndim\n if (Kindy(iy) /= 0) cycle\n\n do ix=1,ndim\n if (Kindx(ix) /= 0) cycle\n\n if (abs(Fa(ix,iy)) .le. abs(fpivot)) cycle\n fpivot=Fa(ix,iy); indx=ix; indy=iy\n end do\n end do\n\n ! Return if pivotal element is zero\n if (fpivot .eq. 0.0_SP) return\n\n Kindx(indx)=indy; Kindy(indy)=indx; Fa(indx,indy)=1._SP&\n &/fpivot\n\n do idim2=1,ndim\n if (idim2 == indy) cycle\n Fa(1:indx-1,idim2)=Fa(1:indx-1,idim2)-Fa(1:indx-1, &\n & indy)*Fa(indx,idim2)/fpivot\n Fa(indx+1:ndim,idim2)=Fa(indx+1:ndim,idim2)-Fa(indx+1:ndim&\n &,indy)*Fa(indx,idim2)/fpivot\n end do\n\n do ix=1,ndim\n if (ix /= indx) Fa(ix,indy)=Fa(ix,indy)/fpivot\n end do\n\n do iy=1,ndim\n if (iy /= indy) Fa(indx,iy)=-Fa(indx,iy)/fpivot\n end do\n end do\n\n do ix=1,ndim\n if (Kindx(ix) == ix) cycle\n\n do iy=1,ndim\n if (Kindx(iy) == ix) exit\n end do\n\n do idim1=1,ndim\n faux=Fa(ix,idim1)\n Fa(ix,idim1)=Fa(iy,idim1)\n Fa(iy,idim1)=faux\n end do\n\n Kindx(iy)=Kindx(ix); Kindx(ix)=ix\n end do\n\n do ix=1,ndim\n if (Kindy(ix) == ix) cycle\n\n do iy=1,ndim\n if (Kindy(iy) == ix) exit\n end do\n\n do idim1=1,ndim\n faux=Fa(idim1,ix)\n Fa(idim1,ix)=Fa(idim1,iy)\n Fa(idim1,iy)=faux\n end do\n\n Kindy(iy)=Kindy(ix); Kindy(ix)=ix\n end do\n\n bsuccess = .true.\n\n end subroutine mprim_invertMatrixPivotSP\n\n ! ***************************************************************************\n\n!\n\n elemental function kronecker(i,j) result(kron)\n\n!\n ! Compute the Kronecker delta symbol\n ! $$\n ! \\delta_{ij}\\left\\{\\begin{array}{ll}\n ! 1 & i=j\\\\\n ! 0 & i\\ne j\n ! \\end{array}\\right. $$\n!\n\n!\n ! Evaluation points I and J\n integer, intent(in) :: i,j\n!\n\n!\n ! Kronecker delta symbol\n integer :: kron\n!\n!\n\n kron=merge(1,0,i==j)\n end function kronecker\n\n !************************************************************************\n\n!\n\n elemental subroutine mprim_linearRescaleDP(dx,da,db,dc,dd,dy)\n\n!\n ! Scales a coordinate x linearly from the interval [a,b] to the\n ! interval [c,d].\n!\n\n!\n ! coordinate to be rescaled\n real(DP), intent(in) :: dx\n\n ! [a,b] - source interval\n real(DP), intent(in) :: da,db\n\n ! [c,d] - destination interval\n real(DP), intent(in) :: dc,dd\n!\n\n!\n ! Rescaled coordinate\n real(DP), intent(out) :: dy\n!\n\n!\n\n real(DP) :: d1,d2,d3\n\n ! Calculate the coefficients of the transformation\n ! D1*A+D2 = C, D1*B+D2 = D.\n ! Use them to calculate Y=D1*X+D2.\n\n if (dA .eq. db) then\n dy = dc\n return\n end if\n\n d3 = 1.0_DP/(da-db)\n d1 = (dc-dd)*d3\n d2 = (-db*dc+da*dd)*d3\n\n dy = d1*dx+d2\n\n end subroutine mprim_linearRescaleDP\n\n !************************************************************************\n\n!\n\n elemental subroutine mprim_linearRescaleSP(fx,fa,fb,fc,fd,fy)\n\n!\n ! Scales a coordinate x linearly from the interval [a,b] to the\n ! interval [c,d].\n!\n\n!\n ! coordinate to be rescaled\n real(SP), intent(in) :: fx\n\n ! [a,b] - source interval\n real(SP), intent(in) :: fa,fb\n\n ! [c,d] - destination interval\n real(SP), intent(in) :: fc,fd\n!\n\n!\n ! Rescaled coordinate\n real(SP), intent(out) :: fy\n!\n\n!\n\n real(SP) :: f1,f2,f3\n\n ! Calculate the coefficients of the transformation\n ! F1*A+F2 = C, F1*B+F2 = D.\n ! Use them to calculate Y=F1*X+F2.\n\n if (fA .eq. fb) then\n fy = fc\n return\n end if\n\n f3 = 1.0_SP/(fa-fb)\n f1 = (fc-fd)*f3\n f2 = (-fb*fc+fa*fd)*f3\n\n fy = f1*fx+f2\n\n end subroutine mprim_linearRescaleSP\n\n ! ***************************************************************************\n\n!\n\n elemental subroutine mprim_quadraticInterpolationDP (dx,d1,d2,d3,dy)\n\n!\n ! \n ! Calculates a quadratic interpolation. dx is a value in the range $[-1,1]$.\n ! The routine calculates the value $dy:=p(dx)$ with $p(.)$ being the quadratic\n ! interpolation polynomial with $p(-1)=d1$, $p(0)=d2$ and $p(1)=d3$.\n ! \n!\n\n!\n ! The parameter value in the range $ [-1,1] $ where the polynomial should be evaluated.\n real(DP), intent(in) :: dx\n\n ! The value $ p(-1) $.\n real(DP), intent(in) :: d1\n\n ! The value $ p(0) $.\n real(DP), intent(in) :: d2\n\n ! The value $ p(1) $.\n real(DP), intent(in) :: d3\n!\n\n!\n ! The value $ p(dx) $.\n real(DP), intent(out) :: dy\n!\n\n!\n\n ! The polynomial p(t) = a + bt + ct^2 has to fulfill:\n ! p(-1)=d1, p(0)=d2, p(1)=d3.\n !\n ! So the polynomial has the shape:\n ! p(t) = d2 + 1/2(d3-d1)t + 1/2(d3-2d2+d1)t^2\n !\n ! The Horner scheme gives us:\n ! p(t) = 1/2 ( (d3-2d2+d1)t + (d3-d1) ) t + d2\n\n dy = 0.5_DP * ( (d3 - 2.0_DP*d2 + d1)*dx + (d3-d1) ) * dx + d2\n\n end subroutine mprim_quadraticInterpolationDP\n\n ! ***************************************************************************\n\n!\n\n elemental subroutine mprim_quadraticInterpolationSP (fx,f1,f2,f3,fy)\n\n!\n ! \n ! Calculates a quadratic interpolation. fx is a value in the range $[-1,1]$.\n ! The routine calculates the value $fy:=p(fx)$ with $p(.)$ being the quadratic\n ! interpolation polynomial with $p(-1)=f1$, $p(0)=f2$ and $p(1)=f3$.\n ! \n!\n\n!\n ! The parameter value in the range $ [-1,1] $ where the polynomial should be evaluated.\n real(SP), intent(in) :: fx\n\n ! The value $ p(-1) $.\n real(SP), intent(in) :: f1\n\n ! The value $ p(0) $.\n real(SP), intent(in) :: f2\n\n ! The value $ p(1) $.\n real(SP), intent(in) :: f3\n!\n\n!\n ! The value $ p(fx) $.\n real(SP), intent(out) :: fy\n!\n\n!\n\n ! The polynomial p(t) = a + bt + ct^2 has to fulfill:\n ! p(-1)=f1, p(0)=f2, p(1)=f3.\n !\n ! So the polynomial has the shape:\n ! p(t) = f2 + 1/2(f3-f1)t + 1/2(f3-2f2+f1)t^2\n !\n ! The Horner scheme gives us:\n ! p(t) = 1/2 ( (f3-2f2+f1)t + (f3-f1) ) t + f2\n\n fy = 0.5_SP * ( (f3 - 2.0_SP*f2 + f1)*fx + (f3-f1) ) * fx + f2\n\n end subroutine mprim_quadraticInterpolationSP\n\n !************************************************************************\n\n!\n\n subroutine mprim_SVD_factoriseDP(Da,Dd,Db,ndim1,ndim2,ndim3,btransposedOpt)\n\n!\n ! \n ! This subroutine computes the factorisation for a singular value\n ! decomposition. Given an ndim2-by-ndim1 matrix Da, the routine\n ! decomposes it into the product $ A = U * D * B^T $\n ! where $U$ overwrites the matrix A and is returned in its memory\n ! position, $D$ is a diagonal matrix returned as vector Dd and\n ! $B$ is an n-by-n square matrix which is returned (instead\n ! of its transpose) as matrix Db.\n !\n ! The optional parameter btransposedOpt can be used to indicate\n ! that matrix A is stored in transposed format. Note that\n ! matrices D and B are not affected by this fact.\n !\n ! The details of this algorithm are given in numerical recipes in F90.\n ! \n!\n\n!\n ! Dimensions of the rectangular matrix Da\n integer, intent(in) :: ndim1,ndim2\n\n ! Dimension of the diagonal matrix Dd and the suare matrix Db\n integer, intent(in) :: ndim3\n\n ! OPTIONAL: Flag to indicate if the matrix A is transposed\n logical, intent(in), optional :: btransposedOpt\n!\n\n!\n ! Matrix that should be factorised on input.\n ! Matrix U on output.\n real(DP), dimension(ndim1,ndim2), intent(inout) :: Da\n!\n\n!\n ! Diagonal matrix\n real(DP), dimension(ndim3), intent(out) :: Dd\n\n ! Square matrix\n real(DP), dimension(ndim3,ndim3), intent(out) :: Db\n!\n!\n\n ! local variables\n real(DP), dimension(:), allocatable :: rv1\n real(DP) :: g, scale, anorm, s, f, h, c, x, y, z\n integer :: its, i, j, jj, k, l, nm, n, m, idot\n integer, parameter :: MAX_ITS = 30\n logical :: btransposed\n\n ! Do we have an optional transposed flag?\n if (present(btransposedOpt)) then\n btransposed = btransposedOpt\n else\n btransposed = .false.\n end if\n\n ! Is the matrix transposed?\n if (btransposed) then\n n=ndim1; m=ndim2\n else\n n=ndim2; m=ndim1\n end if\n\n ! Check if number of equations is larger than number of unknowns\n if (m < n) then\n call output_line('Fewer equations than unknowns!',&\n OU_CLASS_ERROR,OU_MODE_STD,'mprim_SVD_factoriseDP')\n call sys_halt()\n end if\n\n ! Allocate internal memory\n allocate(rv1(ndim3))\n\n if (btransposed) then\n\n ! Householder reduction to bidiagonal form\n g = 0.0_DP\n scale = 0.0_DP\n anorm = 0.0_DP\n\n do i = 1, n\n\n l = i+1\n rv1(i) = scale*g\n g = 0.0_DP\n scale = 0.0_DP\n\n if (i .le. m) then\n scale = sum(abs(Da(i,i:m)))\n if (scale .ne. 0.0_DP) then\n Da(i,i:m) = Da(i,i:m)/scale\n s = 0.0_DP\n do idot = i, m\n s = s+Da(i,idot)*Da(i,idot)\n end do\n f = Da(i,i)\n g = -sign(sqrt(s),f)\n h = f*g-s\n Da(i,i) = f-g\n if (i .ne. n) then\n do j = l, n\n s = 0.0_DP\n do k = i, m\n s = s+Da(i,k)*Da(j,k)\n end do\n f = s/h\n do k = i, m\n Da(j,k) = Da(j,k)+f*Da(i,k)\n end do\n end do\n end if\n do k = i, m\n Da(i,k) = scale*Da(i,k)\n end do\n end if\n end if\n\n Dd(i) = scale*g\n g = 0.0_DP\n s = 0.0_DP\n scale = 0.0_DP\n\n if ((i .le. m) .and. (i .ne. n)) then\n scale = sum(abs(Da(l:n,i)))\n if (scale .ne. 0.0_DP) then\n do k = l, n\n Da(k,i) = Da(k,i)/scale\n s = s+Da(k,i)*Da(k,i)\n end do\n f = Da(l,i)\n g = -sign(sqrt(s),f)\n h = f*g-s\n Da(l,i) = f-g\n do k = l, n\n rv1(k) = Da(k,i)/h\n end do\n\n if (i .ne. m) then\n do j = l, m\n s = 0.0_DP\n do k = l, n\n s = s+Da(k,j)*Da(k,i)\n end do\n do k = l, n\n Da(k,j) = Da(k,j)+s*rv1(k)\n end do\n end do\n end if\n\n do k = l, n\n Da(k,i) = scale*Da(k,i)\n end do\n end if\n end if\n anorm = max(anorm,(abs(Dd(i))+abs(rv1(i))))\n end do\n\n ! Accumulation of right-hand transformations\n do i = n, 1, -1\n if (i .lt. n) then\n if (g .ne. 0.0_DP) then\n do j = l, n\n Db(j,i) = (Da(j,i)/Da(l,i))/g\n end do\n do j = l, n\n s = 0.0_DP\n do k = l, n\n s = s+Da(k,i)*Db(k,j)\n end do\n do k = l, n\n Db(k,j) = Db(k,j)+s*Db(k,i)\n end do\n end do\n end if\n do j = l, n\n Db(i,j) = 0.0_DP\n Db(j,i) = 0.0_DP\n end do\n end if\n Db(i,i) = 1.0_DP\n g = rv1(i)\n l = i\n end do\n\n ! Accumulation of left-hand transformations\n do i = n, 1, -1\n l = i+1\n g = Dd(i)\n if (i .lt. n) then\n do j = l, n\n Da(j,i) = 0.0_DP\n end do\n end if\n if (g .ne. 0.0_DP) then\n g = 1.0_DP/g\n if (i .ne. n) then\n do j = l, n\n s = 0.0_DP\n do k = l, m\n s = s+Da(i,k)*Da(j,k)\n end do\n f = (s/Da(i,i))*g\n do k = i, m\n Da(j,k) = Da(j,k)+f*Da(i,k)\n end do\n end do\n end if\n do j = i, m\n Da(i,j) = Da(i,j)*g\n end do\n else\n do j = i, m\n Da(i,j) = 0.0_DP\n end do\n end if\n Da(i,i) = Da(i,i)+1.0_DP\n end do\n\n ! Diagonalisation of the bidiagonal form\n do k = n, 1, -1\n do its = 1, MAX_ITS\n do l = k, 1, -1\n nm = l-1\n if ((abs(rv1(l))+anorm) .eq. anorm) goto 5\n if ((abs(Dd(nm))+anorm) .eq. anorm) goto 4\n end do\n4 continue\n c = 0.0_DP\n s = 1.0_DP\n do i = l, k\n f = s*rv1(i)\n rv1(i) = c*rv1(i)\n if ((abs(f)+anorm) .eq. anorm) goto 5\n g = Dd(i)\n h = sqrt(f*f+g*g)\n Dd(i) = h\n h = 1.0_DP/h\n c = g*h\n s = -(f*h)\n do j = 1, m\n y = Da(nm,j)\n z = Da(i,j)\n Da(nm,j) = (y*c)+(z*s)\n Da(i,j) = -(y*s)+(z*c)\n end do\n end do\n5 continue\n z = Dd(k)\n if (l .eq. k) then\n if (z .lt. 0.0_DP) then\n Dd(k) = -z\n do j = 1, n\n Db(j,k) = -Db(j,k)\n end do\n end if\n goto 6\n end if\n if (its .eq. MAX_ITS) then\n call output_line('Convergence failed!',&\n OU_CLASS_ERROR,OU_MODE_STD,'mprim_SVD_factoriseDP')\n call sys_halt()\n end if\n x = Dd(l)\n nm = k-1\n y = Dd(nm)\n g = rv1(nm)\n h = rv1(k)\n f = ((y-z)*(y+z)+(g-h)*(g+h))/(2.0_DP*h*y)\n g = sqrt(f*f+1.0_DP)\n f = ((x-z)*(x+z)+h*((y/(f+sign(g,f)))-h))/x\n\n ! Next QR transformation\n c = 1.0_DP\n s = 1.0_DP\n do j = l, nm\n i = j+1\n g = rv1(i)\n y = Dd(i)\n h = s*g\n g = c*g\n z = sqrt(f*f+h*h)\n rv1(j) = z\n c = f/z\n s = h/z\n f = (x*c)+(g*s)\n g = -(x*s)+(g*c)\n h = y*s\n y = y*c\n do jj = 1, n\n x = Db(jj,j)\n z = Db(jj,i)\n Db(jj,j) = (x*c)+(z*s)\n Db(jj,i) = -(x*s)+(z*c)\n end do\n z = sqrt(f*f+h*h)\n Dd(j) = z\n if (z .ne. 0.0_DP) then\n z = 1.0_DP/z\n c = f*z\n s = h*z\n end if\n f = (c*g)+(s*y)\n x = -(s*g)+(c*y)\n do jj = 1, m\n y = Da(j,jj)\n z = Da(i,jj)\n Da(j,jj) = (y*c)+(z*s)\n Da(i,jj) = -(y*s)+(z*c)\n end do\n end do\n rv1(l) = 0.0_DP\n rv1(k) = f\n Dd(k) = x\n end do\n6 continue\n end do\n\n else\n\n ! Householder reduction to bidiagonal form\n g = 0.0_DP\n scale = 0.0_DP\n anorm = 0.0_DP\n\n do i = 1, n\n\n l = i+1\n rv1(i) = scale*g\n g = 0.0_DP\n scale = 0.0_DP\n\n if (i .le. m) then\n scale = sum(abs(Da(i:m,i)))\n if (scale .ne. 0.0_DP) then\n Da(i:m,i) = Da(i:m,i)/scale\n s = 0.0_DP\n do idot = i, m\n s = s+Da(idot,i)*Da(idot,i)\n end do\n f = Da(i,i)\n g = -sign(sqrt(s),f)\n h = f*g-s\n Da(i,i) = f-g\n if (i .ne. n) then\n do j = l, n\n s = 0.0_DP\n do k = i, m\n s = s+Da(k,i)*Da(k,j)\n end do\n f = s/h\n do k = i, m\n Da(k,j) = Da(k,j)+f*Da(k,i)\n end do\n end do\n end if\n do k = i, m\n Da(k,i) = scale*Da(k,i)\n end do\n end if\n end if\n\n Dd(i) = scale*g\n g = 0.0_DP\n s = 0.0_DP\n scale = 0.0_DP\n\n if ((i .le. m) .and. (i .ne. n)) then\n scale = sum(abs(Da(i,l:n)))\n if (scale .ne. 0.0_DP) then\n do k = l, n\n Da(i,k) = Da(i,k)/scale\n s = s+Da(i,k)*Da(i,k)\n end do\n f = Da(i,l)\n g = -sign(sqrt(s),f)\n h = f*g-s\n Da(i,l) = f-g\n do k = l, n\n rv1(k) = Da(i,k)/h\n end do\n\n if (i .ne. m) then\n do j = l, m\n s = 0.0_DP\n do k = l, n\n s = s+Da(j,k)*Da(i,k)\n end do\n do k = l, n\n Da(j,k) = Da(j,k)+s*rv1(k)\n end do\n end do\n end if\n\n do k = l, n\n Da(i,k) = scale*Da(i,k)\n end do\n end if\n end if\n anorm = max(anorm,(abs(Dd(i))+abs(rv1(i))))\n end do\n\n ! Accumulation of right-hand transformations\n do i = n, 1, -1\n if (i .lt. n) then\n if (g .ne. 0.0_DP) then\n do j = l, n\n Db(j,i) = (Da(i,j)/Da(i,l))/g\n end do\n do j = l, n\n s = 0.0_DP\n do k = l, n\n s = s+Da(i,k)*Db(k,j)\n end do\n do k = l, n\n Db(k,j) = Db(k,j)+s*Db(k,i)\n end do\n end do\n end if\n do j = l, n\n Db(i,j) = 0.0_DP\n Db(j,i) = 0.0_DP\n end do\n end if\n Db(i,i) = 1.0_DP\n g = rv1(i)\n l = i\n end do\n\n ! Accumulation of left-hand transformations\n do i = n, 1, -1\n l = i+1\n g = Dd(i)\n if (i .lt. n) then\n do j = l, n\n Da(i,j) = 0.0_DP\n end do\n end if\n if (g .ne. 0.0_DP) then\n g = 1.0_DP/g\n if (i .ne. n) then\n do j = l, n\n s = 0.0_DP\n do k = l, m\n s = s+Da(k,i)*Da(k,j)\n end do\n f = (s/Da(i,i))*g\n do k = i, m\n Da(k,j) = Da(k,j)+f*Da(k,i)\n end do\n end do\n end if\n do j = i, m\n Da(j,i) = Da(j,i)*g\n end do\n else\n do j = i, m\n Da(j,i) = 0.0_DP\n end do\n end if\n Da(i,i) = Da(i,i)+1.0_DP\n end do\n\n ! Diagonalisation of the bidiagonal form\n do k = n, 1, -1\n do its = 1, MAX_ITS\n do l = k, 1, -1\n nm = l-1\n if ((abs(rv1(l))+anorm) .eq. anorm) goto 2\n if ((abs(Dd(nm))+anorm) .eq. anorm) goto 1\n end do\n1 continue\n c = 0.0_DP\n s = 1.0_DP\n do i = l, k\n f = s*rv1(i)\n rv1(i) = c*rv1(i)\n if ((abs(f)+anorm) .eq. anorm) goto 2\n g = Dd(i)\n h = sqrt(f*f+g*g)\n Dd(i) = h\n h = 1.0_DP/h\n c = g*h\n s = -(f*h)\n do j = 1, m\n y = Da(j,nm)\n z = Da(j,i)\n Da(j,nm) = (y*c)+(z*s)\n Da(j,i) = -(y*s)+(z*c)\n end do\n end do\n2 continue\n z = Dd(k)\n if (l .eq. k) then\n if (z .lt. 0.0_DP) then\n Dd(k) = -z\n do j = 1, n\n Db(j,k) = -Db(j,k)\n end do\n end if\n goto 3\n end if\n if (its .eq. MAX_ITS) then\n call output_line('Convergence failed!',&\n OU_CLASS_ERROR,OU_MODE_STD,'mprim_SVD_factoriseDP')\n call sys_halt()\n end if\n x = Dd(l)\n nm = k-1\n y = Dd(nm)\n g = rv1(nm)\n h = rv1(k)\n f = ((y-z)*(y+z)+(g-h)*(g+h))/(2.0_DP*h*y)\n g = sqrt(f*f+1.0_DP)\n f = ((x-z)*(x+z)+h*((y/(f+sign(g,f)))-h))/x\n\n ! Next QR transformation\n c = 1.0_DP\n s = 1.0_DP\n do j = l, nm\n i = j+1\n g = rv1(i)\n y = Dd(i)\n h = s*g\n g = c*g\n z = sqrt(f*f+h*h)\n rv1(j) = z\n c = f/z\n s = h/z\n f = (x*c)+(g*s)\n g = -(x*s)+(g*c)\n h = y*s\n y = y*c\n do jj = 1, n\n x = Db(jj,j)\n z = Db(jj,i)\n Db(jj,j) = (x*c)+(z*s)\n Db(jj,i) = -(x*s)+(z*c)\n end do\n z = sqrt(f*f+h*h)\n Dd(j) = z\n if (z .ne. 0.0_DP) then\n z = 1.0_DP/z\n c = f*z\n s = h*z\n end if\n f = (c*g)+(s*y)\n x = -(s*g)+(c*y)\n do jj = 1, m\n y = Da(jj,j)\n z = Da(jj,i)\n Da(jj,j) = (y*c)+(z*s)\n Da(jj,i) = -(y*s)+(z*c)\n end do\n end do\n rv1(l) = 0.0_DP\n rv1(k) = f\n Dd(k) = x\n end do\n3 continue\n end do\n\n end if\n\n ! Deallocate internal memory\n deallocate(rv1)\n\n end subroutine mprim_SVD_factoriseDP\n\n !************************************************************************\n\n!\n\n subroutine mprim_SVD_factoriseSP(Fa,Fd,Fb,ndim1,ndim2,ndim3,btransposedOpt)\n\n!\n ! \n ! This subroutine computes the factorisation for a singular value\n ! decomposition. Given an ndim2-by-ndim1 matrix Fa, the routine\n ! decomposes it into the product $ A = U * D * B^T $\n ! where $U$ overwrites the matrix A and is returned in its memory\n ! position, $D$ is a diagonal matrix returned as vector Fd and\n ! $B$ is an n-by-n square matrix which is returned (instead\n ! of its transpose) as matrix Fb.\n !\n ! The optional parameter btransposedOpt can be used to indicate\n ! that matrix A is stored in transposed format. Note that\n ! matrices D and B are not affected by this fact.\n !\n ! The details of this algorithm are given in numerical recipes in F90.\n ! \n!\n\n!\n ! Dimensions of the rectangular matrix\n integer, intent(in) :: ndim1,ndim2,ndim3\n\n ! OPTIONAL: Flag to indicate if the matrix A is transposed\n logical, intent(in), optional :: btransposedOpt\n!\n\n!\n ! Matrix that should be factorised on input.\n ! Matrix U on output.\n real(SP), dimension(ndim1,ndim2), intent(inout) :: Fa\n!\n\n!\n ! Diagonal matrix\n real(SP), dimension(ndim3), intent(out) :: Fd\n\n ! Square matrix\n real(SP), dimension(ndim3,ndim3), intent(out) :: Fb\n!\n!\n\n ! local variables\n real(SP), dimension(:), allocatable :: rv1\n real(SP) :: g, scale, anorm, s, f, h, c, x, y, z\n integer :: its, i, j, jj, k, l, nm, n, m, idot\n integer, parameter :: MAX_ITS = 30\n logical :: btransposed\n\n ! Do we have an optional transposed flag?\n if (present(btransposedOpt)) then\n btransposed = btransposedOpt\n else\n btransposed = .false.\n end if\n\n ! Is the matrix transposed?\n if (btransposed) then\n n=ndim1; m=ndim2\n else\n n=ndim2; m=ndim1\n end if\n\n ! Check if number of equations is larger than number of unknowns\n if (m < n) then\n call output_line('Fewer equations than unknowns!',&\n OU_CLASS_ERROR,OU_MODE_STD,'mprim_SVD_factoriseSP')\n call sys_halt()\n end if\n\n ! Allocate internal memory\n allocate(rv1(ndim3))\n\n if (btransposed) then\n\n ! Householder reduction to bidiagonal form\n g = 0.0_SP\n scale = 0.0_SP\n anorm = 0.0_SP\n\n do i = 1, n\n\n l = i+1\n rv1(i) = scale*g\n g = 0.0_SP\n scale = 0.0_SP\n\n if (i .le. m) then\n scale = sum(abs(Fa(i,i:m)))\n if (scale .ne. 0.0_SP) then\n Fa(i,i:m) = Fa(i,i:m)/scale\n s = 0.0_SP\n do idot = i, m\n s = s+Fa(i,idot)*Fa(i,idot)\n end do\n f = Fa(i,i)\n g = -sign(sqrt(s),f)\n h = f*g-s\n Fa(i,i) = f-g\n if (i .ne. n) then\n do j = l, n\n s = 0.0_SP\n do k = i, m\n s = s+Fa(i,k)*Fa(j,k)\n end do\n f = s/h\n do k = i, m\n Fa(j,k) = Fa(j,k)+f*Fa(i,k)\n end do\n end do\n end if\n do k = i, m\n Fa(i,k) = scale*Fa(i,k)\n end do\n end if\n end if\n\n Fd(i) = scale*g\n g = 0.0_SP\n s = 0.0_SP\n scale = 0.0_SP\n\n if ((i .le. m) .and. (i .ne. n)) then\n scale = sum(abs(Fa(l:n,i)))\n if (scale .ne. 0.0_SP) then\n do k = l, n\n Fa(k,i) = Fa(k,i)/scale\n s = s+Fa(k,i)*Fa(k,i)\n end do\n f = Fa(l,i)\n g = -sign(sqrt(s),f)\n h = f*g-s\n Fa(l,i) = f-g\n do k = l, n\n rv1(k) = Fa(k,i)/h\n end do\n\n if (i .ne. m) then\n do j = l, m\n s = 0.0_SP\n do k = l, n\n s = s+Fa(k,j)*Fa(k,i)\n end do\n do k = l, n\n Fa(k,j) = Fa(k,j)+s*rv1(k)\n end do\n end do\n end if\n\n do k = l, n\n Fa(k,i) = scale*Fa(k,i)\n end do\n end if\n end if\n anorm = max(anorm,(abs(Fd(i))+abs(rv1(i))))\n end do\n\n ! Accumulation of right-hand transformations\n do i = n, 1, -1\n if (i .lt. n) then\n if (g .ne. 0.0_SP) then\n do j = l, n\n Fb(j,i) = (Fa(j,i)/Fa(l,i))/g\n end do\n do j = l, n\n s = 0.0_SP\n do k = l, n\n s = s+Fa(k,i)*Fb(k,j)\n end do\n do k = l, n\n Fb(k,j) = Fb(k,j)+s*Fb(k,i)\n end do\n end do\n end if\n do j = l, n\n Fb(i,j) = 0.0_SP\n Fb(j,i) = 0.0_SP\n end do\n end if\n Fb(i,i) = 1.0_SP\n g = rv1(i)\n l = i\n end do\n\n ! Accumulation of left-hand transformations\n do i = n, 1, -1\n l = i+1\n g = Fd(i)\n if (i .lt. n) then\n do j = l, n\n Fa(j,i) = 0.0_SP\n end do\n end if\n if (g .ne. 0.0_SP) then\n g = 1.0_SP/g\n if (i .ne. n) then\n do j = l, n\n s = 0.0_SP\n do k = l, m\n s = s+Fa(i,k)*Fa(j,k)\n end do\n f = (s/Fa(i,i))*g\n do k = i, m\n Fa(j,k) = Fa(j,k)+f*Fa(i,k)\n end do\n end do\n end if\n do j = i, m\n Fa(i,j) = Fa(i,j)*g\n end do\n else\n do j = i, m\n Fa(i,j) = 0.0_SP\n end do\n end if\n Fa(i,i) = Fa(i,i)+1.0_SP\n end do\n\n ! Diagonalisation of the bidiagonal form\n do k = n, 1, -1\n do its = 1, MAX_ITS\n do l = k, 1, -1\n nm = l-1\n if ((abs(rv1(l))+anorm) .eq. anorm) goto 5\n if ((abs(Fd(nm))+anorm) .eq. anorm) goto 4\n end do\n4 continue\n c = 0.0_SP\n s = 1.0_SP\n do i = l, k\n f = s*rv1(i)\n rv1(i) = c*rv1(i)\n if ((abs(f)+anorm) .eq. anorm) goto 5\n g = Fd(i)\n h = sqrt(f*f+g*g)\n Fd(i) = h\n h = 1.0_SP/h\n c = g*h\n s = -(f*h)\n do j = 1, m\n y = Fa(nm,j)\n z = Fa(i,j)\n Fa(nm,j) = (y*c)+(z*s)\n Fa(i,j) = -(y*s)+(z*c)\n end do\n end do\n5 continue\n z = Fd(k)\n if (l .eq. k) then\n if (z .lt. 0.0_SP) then\n Fd(k) = -z\n do j = 1, n\n Fb(j,k) = -Fb(j,k)\n end do\n end if\n goto 6\n end if\n if (its .eq. MAX_ITS) then\n call output_line('Convergence failed!',&\n OU_CLASS_ERROR,OU_MODE_STD,'mprim_SVD_factoriseSP')\n call sys_halt()\n end if\n x = Fd(l)\n nm = k-1\n y = Fd(nm)\n g = rv1(nm)\n h = rv1(k)\n f = ((y-z)*(y+z)+(g-h)*(g+h))/(2.0_SP*h*y)\n g = sqrt(f*f+1.0_SP)\n f = ((x-z)*(x+z)+h*((y/(f+sign(g,f)))-h))/x\n\n ! Next QR transformation\n c = 1.0_SP\n s = 1.0_SP\n do j = l, nm\n i = j+1\n g = rv1(i)\n y = Fd(i)\n h = s*g\n g = c*g\n z = sqrt(f*f+h*h)\n rv1(j) = z\n c = f/z\n s = h/z\n f = (x*c)+(g*s)\n g = -(x*s)+(g*c)\n h = y*s\n y = y*c\n do jj = 1, n\n x = Fb(jj,j)\n z = Fb(jj,i)\n Fb(jj,j) = (x*c)+(z*s)\n Fb(jj,i) = -(x*s)+(z*c)\n end do\n z = sqrt(f*f+h*h)\n Fd(j) = z\n if (z .ne. 0.0_SP) then\n z = 1.0_SP/z\n c = f*z\n s = h*z\n end if\n f = (c*g)+(s*y)\n x = -(s*g)+(c*y)\n do jj = 1, m\n y = Fa(j,jj)\n z = Fa(i,jj)\n Fa(j,jj) = (y*c)+(z*s)\n Fa(i,jj) = -(y*s)+(z*c)\n end do\n end do\n rv1(l) = 0.0_SP\n rv1(k) = f\n Fd(k) = x\n end do\n6 continue\n end do\n\n else\n\n ! Householder reduction to bidiagonal form\n g = 0.0_SP\n scale = 0.0_SP\n anorm = 0.0_SP\n\n do i = 1, n\n\n l = i+1\n rv1(i) = scale*g\n g = 0.0_SP\n scale = 0.0_SP\n\n if (i .le. m) then\n scale = sum(abs(Fa(i:m,i)))\n if (scale .ne. 0.0_SP) then\n Fa(i:m,i) = Fa(i:m,i)/scale\n s = 0.0_SP\n do idot = i, m\n s = s+Fa(idot,i)*Fa(idot,i)\n end do\n f = Fa(i,i)\n g = -sign(sqrt(s),f)\n h = f*g-s\n Fa(i,i) = f-g\n if (i .ne. n) then\n do j = l, n\n s = 0.0_SP\n do k = i, m\n s = s+Fa(k,i)*Fa(k,j)\n end do\n f = s/h\n do k = i, m\n Fa(k,j) = Fa(k,j)+f*Fa(k,i)\n end do\n end do\n end if\n do k = i, m\n Fa(k,i) = scale*Fa(k,i)\n end do\n end if\n end if\n\n Fd(i) = scale*g\n g = 0.0_SP\n s = 0.0_SP\n scale = 0.0_SP\n\n if ((i .le. m) .and. (i .ne. n)) then\n scale = sum(abs(Fa(i,l:n)))\n if (scale .ne. 0.0_SP) then\n do k = l, n\n Fa(i,k) = Fa(i,k)/scale\n s = s+Fa(i,k)*Fa(i,k)\n end do\n f = Fa(i,l)\n g = -sign(sqrt(s),f)\n h = f*g-s\n Fa(i,l) = f-g\n do k = l, n\n rv1(k) = Fa(i,k)/h\n end do\n\n if (i .ne. m) then\n do j = l, m\n s = 0.0_SP\n do k = l, n\n s = s+Fa(j,k)*Fa(i,k)\n end do\n do k = l, n\n Fa(j,k) = Fa(j,k)+s*rv1(k)\n end do\n end do\n end if\n\n do k = l, n\n Fa(i,k) = scale*Fa(i,k)\n end do\n end if\n end if\n anorm = max(anorm,(abs(Fd(i))+abs(rv1(i))))\n end do\n\n ! Accumulation of right-hand transformations\n do i = n, 1, -1\n if (i .lt. n) then\n if (g .ne. 0.0_SP) then\n do j = l, n\n Fb(j,i) = (Fa(i,j)/Fa(i,l))/g\n end do\n do j = l, n\n s = 0.0_SP\n do k = l, n\n s = s+Fa(i,k)*Fb(k,j)\n end do\n do k = l, n\n Fb(k,j) = Fb(k,j)+s*Fb(k,i)\n end do\n end do\n end if\n do j = l, n\n Fb(i,j) = 0.0_SP\n Fb(j,i) = 0.0_SP\n end do\n end if\n Fb(i,i) = 1.0_SP\n g = rv1(i)\n l = i\n end do\n\n ! Accumulation of left-hand transformations\n do i = n, 1, -1\n l = i+1\n g = Fd(i)\n if (i .lt. n) then\n do j = l, n\n Fa(i,j) = 0.0_SP\n end do\n end if\n if (g .ne. 0.0_SP) then\n g = 1.0_SP/g\n if (i .ne. n) then\n do j = l, n\n s = 0.0_SP\n do k = l, m\n s = s+Fa(k,i)*Fa(k,j)\n end do\n f = (s/Fa(i,i))*g\n do k = i, m\n Fa(k,j) = Fa(k,j)+f*Fa(k,i)\n end do\n end do\n end if\n do j = i, m\n Fa(j,i) = Fa(j,i)*g\n end do\n else\n do j = i, m\n Fa(j,i) = 0.0_SP\n end do\n end if\n Fa(i,i) = Fa(i,i)+1.0_SP\n end do\n\n ! Diagonalisation of the bidiagonal form\n do k = n, 1, -1\n do its = 1, MAX_ITS\n do l = k, 1, -1\n nm = l-1\n if ((abs(rv1(l))+anorm) .eq. anorm) goto 2\n if ((abs(Fd(nm))+anorm) .eq. anorm) goto 1\n end do\n1 continue\n c = 0.0_SP\n s = 1.0_SP\n do i = l, k\n f = s*rv1(i)\n rv1(i) = c*rv1(i)\n if ((abs(f)+anorm) .eq. anorm) goto 2\n g = Fd(i)\n h = sqrt(f*f+g*g)\n Fd(i) = h\n h = 1.0_SP/h\n c = g*h\n s = -(f*h)\n do j = 1, m\n y = Fa(j,nm)\n z = Fa(j,i)\n Fa(j,nm) = (y*c)+(z*s)\n Fa(j,i) = -(y*s)+(z*c)\n end do\n end do\n2 continue\n z = Fd(k)\n if (l .eq. k) then\n if (z .lt. 0.0_SP) then\n Fd(k) = -z\n do j = 1, n\n Fb(j,k) = -Fb(j,k)\n end do\n end if\n goto 3\n end if\n if (its .eq. MAX_ITS) then\n call output_line('Convergence failed!',&\n OU_CLASS_ERROR,OU_MODE_STD,'mprim_SVD_factoriseSP')\n call sys_halt()\n end if\n x = Fd(l)\n nm = k-1\n y = Fd(nm)\n g = rv1(nm)\n h = rv1(k)\n f = ((y-z)*(y+z)+(g-h)*(g+h))/(2.0_SP*h*y)\n g = sqrt(f*f+1.0_SP)\n f = ((x-z)*(x+z)+h*((y/(f+sign(g,f)))-h))/x\n\n ! Next QR transformation\n c = 1.0_SP\n s = 1.0_SP\n do j = l, nm\n i = j+1\n g = rv1(i)\n y = Fd(i)\n h = s*g\n g = c*g\n z = sqrt(f*f+h*h)\n rv1(j) = z\n c = f/z\n s = h/z\n f = (x*c)+(g*s)\n g = -(x*s)+(g*c)\n h = y*s\n y = y*c\n do jj = 1, n\n x = Fb(jj,j)\n z = Fb(jj,i)\n Fb(jj,j) = (x*c)+(z*s)\n Fb(jj,i) = -(x*s)+(z*c)\n end do\n z = sqrt(f*f+h*h)\n Fd(j) = z\n if (z .ne. 0.0_SP) then\n z = 1.0_SP/z\n c = f*z\n s = h*z\n end if\n f = (c*g)+(s*y)\n x = -(s*g)+(c*y)\n do jj = 1, m\n y = Fa(jj,j)\n z = Fa(jj,i)\n Fa(jj,j) = (y*c)+(z*s)\n Fa(jj,i) = -(y*s)+(z*c)\n end do\n end do\n rv1(l) = 0.0_SP\n rv1(k) = f\n Fd(k) = x\n end do\n3 continue\n end do\n\n end if\n\n ! Deallocate internal memory\n deallocate(rv1)\n\n end subroutine mprim_SVD_factoriseSP\n\n !************************************************************************\n\n!\n\n subroutine mprim_SVD_backsubstDP(Da,Dd,Db,Dx,Df,ndim1,ndim2,ndim3,btransposedOpt)\n\n!\n ! This subroutine solves $ A * x = f $ for vector $ x $,\n ! where the rectangular\n ! matrix $A$ has been decomposed into $ Da $, $ Dd $\n ! and $ Db $ by the routine\n ! mprim_SVD_factorise. The optional parameter btransposedOpt can be used\n ! to indicate that matrix A is stored in transposed format.\n!\n\n!\n ! Dimensions of the rectangular matrix\n integer, intent(in) :: ndim1,ndim2\n\n ! Dimension of the diagonal matrix Dd and the suare matrix Db\n integer, intent(in) :: ndim3\n\n ! OPTIONAL: Flag to indicate if the matrix A is transposed\n logical, intent(in), optional :: btransposedOpt\n\n ! Factorised matrix U\n real(DP), dimension(ndim1,ndim2), intent(in) :: Da\n\n ! Diagonal matrix D\n real(DP), dimension(ndim3), intent(in) :: Dd\n\n ! Square matrix B\n real(DP), dimension(ndim3,ndim3), intent(in) :: Db\n\n ! Right-hand side vector\n real(DP), dimension(ndim3), intent(in) :: Df\n!\n\n!\n ! Solution vector\n real(DP), dimension(ndim3), intent(out) :: Dx\n!\n!\n\n ! local variables\n real(DP), dimension(:), allocatable :: Daux\n integer :: i,n,m\n logical :: btransposed\n\n ! Do we have an optional transposed flag?\n if (present(btransposedOpt)) then\n btransposed = btransposedOpt\n else\n btransposed = .false.\n end if\n\n ! Is the matrix transposed?\n if (btransposed) then\n n=ndim1; m=ndim2\n else\n n=ndim2; m=ndim1\n end if\n\n ! Check if number of equations is larger than number of unknowns\n if (m < n) then\n call output_line('Fewer equations than unknowns!',&\n OU_CLASS_ERROR,OU_MODE_STD,'mprim_SVD_backsubstDP')\n call sys_halt()\n end if\n\n ! Allocate internal memory\n allocate(Daux(ndim3))\n\n ! Compute aux = (U^T * f)/D where D_i /= 0\n if (btransposed) then\n call DGEMV('n', ndim1, ndim2, 1.0_DP, Da, ndim1, Df, 1, 0.0_DP, Daux, 1)\n else\n call DGEMV('t', ndim1, ndim2, 1.0_DP, Da, ndim1, Df, 1, 0.0_DP, Daux, 1)\n end if\n\n do i =1, size(Dd)\n if (Dd(i) .ne. 0.0_DP) then\n Daux(i) = Daux(i)/Dd(i)\n else\n Daux(i) = 0.0_DP\n end if\n end do\n\n ! Compute x = B * aux\n call DGEMV('n', n, n, 1.0_DP, Db, n, Daux, 1, 0.0_DP, Dx, 1)\n\n ! Deallocate internal memory\n deallocate(Daux)\n end subroutine mprim_SVD_backsubstDP\n\n !************************************************************************\n\n!\n\n subroutine mprim_SVD_backsubstSP(Fa,Fd,Fb,Fx,Ff,ndim1,ndim2,ndim3,btransposedOpt)\n\n!\n ! This subroutine solves $ A * x = f $ for vector $ x $,\n ! where the rectangular\n ! matrix $A$ has been decomposed into $ Fa $, $ Fd $\n ! and $ Fb $ by the routine\n ! mprim_SVD_factorise. The optional parameter btransposedOpt can be used\n ! to indicate that matrix A is stored in transposed format.\n!\n\n!\n ! Dimensions of the rectangular matrix\n integer, intent(in) :: ndim1,ndim2\n\n ! Dimension of the diagonal matrix Dd and the suare matrix Db\n integer, intent(in) :: ndim3\n\n ! OPTIONAL: Flag to indicate if the matrix A is transposed\n logical, intent(in), optional :: btransposedOpt\n\n ! Factorised matrix U\n real(SP), dimension(ndim1,ndim2), intent(in) :: Fa\n\n ! Diagonal matrix D\n real(SP), dimension(ndim3), intent(in) :: Fd\n\n ! Square matrix B\n real(SP), dimension(ndim3,ndim3), intent(in) :: Fb\n\n ! Right-hand side vector\n real(SP), dimension(ndim3), intent(in) :: Ff\n!\n\n!\n ! Solution vector\n real(SP), dimension(ndim3), intent(out) :: Fx\n!\n!\n\n ! local variables\n real(SP), dimension(:), allocatable :: Faux\n integer :: i,n,m\n logical :: btransposed\n\n ! Do we have an optional transposed flag?\n if (present(btransposedOpt)) then\n btransposed = btransposedOpt\n else\n btransposed = .false.\n end if\n\n ! Is the matrix transposed?\n if (btransposed) then\n n=ndim1; m=ndim2\n else\n n=ndim2; m=ndim1\n end if\n\n ! Check if number of equations is larger than number of unknowns\n if (m < n) then\n call output_line('Fewer equations than unknowns!',&\n OU_CLASS_ERROR,OU_MODE_STD,'mprim_SVD_backsubstSP')\n call sys_halt()\n end if\n\n ! Allocate internal memory\n allocate(Faux(ndim3))\n\n ! Compute aux = (U^T * f)/D where D_i /= 0\n if (btransposed) then\n call SGEMV('n', ndim1, ndim2, 1.0_SP, Fa, ndim1, Ff, 1, 0.0_SP, Faux, 1)\n else\n call SGEMV('t', ndim1, ndim2, 1.0_SP, Fa, ndim1, Ff, 1, 0.0_SP, Faux, 1)\n end if\n\n do i =1, size(Fd)\n if (Fd(i) .ne. 0.0_SP) then\n Faux(i) = Faux(i)/Fd(i)\n else\n Faux(i) = 0.0_SP\n end if\n end do\n\n ! Compute x = B * aux\n call SGEMV('n', n, n, 1.0_SP, Fb, n, Faux, 1, 0.0_SP, Fx, 1)\n\n ! Deallocate internal memory\n deallocate(Faux)\n end subroutine mprim_SVD_backsubstSP\n\n !************************************************************************\n\n!\n\n pure function mprim_stdDeviationDP(Dval) result(stdDev)\n\n!\n ! This function calculates the standard deviation of the given data\n!\n\n!\n ! double data\n real(DP), dimension(:), intent(in) :: Dval\n!\n\n!\n ! standard deviation\n real(DP) :: stdDev\n!\n!\n\n ! local variable\n real(DP) :: mean\n integer(I32) :: i\n\n ! Compute mean\n mean = Dval(1)\n\n do i = 2, size(Dval)\n mean = mean + Dval(i)\n end do\n\n mean = mean/real(size(Dval), DP)\n\n ! Compute standard deviation\n stdDev = (Dval(1)-mean)*(Dval(1)-mean)\n\n do i = 2, size(Dval)\n stdDev = stdDev + (Dval(i)-mean)*(Dval(i)-mean)\n end do\n\n stdDev = sqrt(stdDev/real(size(Dval), DP))\n\n end function mprim_stdDeviationDP\n\n !************************************************************************\n\n!\n\n pure function mprim_stdDeviationSP(Fval) result(stdDev)\n\n!\n ! This function calculates the standard deviation of the given data\n!\n\n!\n ! single data\n real(SP), dimension(:), intent(in) :: Fval\n!\n\n!\n ! standard deviation\n real(SP) :: stdDev\n!\n!\n\n ! local variable\n real(SP) :: mean\n integer(I32) :: i\n\n ! Compute mean\n mean = Fval(1)\n\n do i = 2, size(Fval)\n mean = mean + Fval(i)\n end do\n\n mean = mean/real(size(Fval), SP)\n\n ! Compute standard deviation\n stdDev = (Fval(1)-mean)*(Fval(1)-mean)\n\n do i = 2, size(Fval)\n stdDev = stdDev + (Fval(i)-mean)*(Fval(i)-mean)\n end do\n\n stdDev = sqrt(stdDev/real(size(Fval), SP))\n\n end function mprim_stdDeviationSP\n\n !************************************************************************\n\n!\n\n pure function mprim_stdDeviationInt(Ival) result(stdDev)\n\n!\n ! This function calculates the standard deviation of the given data\n!\n\n!\n ! integer data\n integer, dimension(:), intent(in) :: Ival\n!\n\n!\n ! standard deviation\n real(DP) :: stdDev\n!\n!\n\n ! local variable\n real(DP) :: mean\n integer(I32) :: i\n\n ! Compute mean\n mean = real(Ival(1), DP)\n\n do i = 2, size(Ival)\n mean = mean + real(Ival(i), DP)\n end do\n\n mean = mean/real(size(Ival), DP)\n\n ! Compute standard deviation\n stdDev = (Ival(1)-mean)*(Ival(1)-mean)\n\n do i = 2, size(Ival)\n stdDev = stdDev + (Ival(i)-mean)*(Ival(i)-mean)\n end do\n\n stdDev = sqrt(stdDev/real(size(Ival), DP))\n\n end function mprim_stdDeviationInt\n\n !************************************************************************\n\n!\n\n pure function mprim_meanDeviationDP(Dval) result(meanDev)\n\n!\n ! This function calculates the mean deviation of the given data\n!\n\n!\n ! double data\n real(DP), dimension(:), intent(in) :: Dval\n!\n\n!\n ! mean deviation\n real(DP) :: meanDev\n!\n!\n\n ! local variable\n real(DP) :: mean\n integer(I32) :: i\n\n ! Compute mean\n mean = Dval(1)\n\n do i = 2, size(Dval)\n mean = mean + Dval(i)\n end do\n\n mean = mean/real(size(Dval), DP)\n\n ! Compute mean deviation\n meanDev = abs(Dval(1)-mean)\n\n do i = 2, size(Dval)\n meanDev = meanDev + abs(Dval(i)-mean)\n end do\n\n meandev = meanDev/real(size(Dval), DP)\n\n end function mprim_meanDeviationDP\n\n !************************************************************************\n\n!\n\n pure function mprim_meanDeviationSP(Fval) result(meanDev)\n\n!\n ! This function calculates the mean deviation of the given data\n!\n\n!\n ! single data\n real(SP), dimension(:), intent(in) :: Fval\n!\n\n!\n ! mean deviation\n real(SP) :: meanDev\n!\n!\n\n ! local variable\n real(SP) :: mean\n integer(I32) :: i\n\n ! Compute mean\n mean = Fval(1)\n\n do i = 2, size(Fval)\n mean = mean + Fval(i)\n end do\n\n mean = mean/real(size(Fval), SP)\n\n ! Compute mean deviation\n meanDev = abs(Fval(1)-mean)\n\n do i = 2, size(Fval)\n meanDev = meanDev + abs(Fval(i)-mean)\n end do\n\n meanDev = meanDev/real(size(Fval), SP)\n\n end function mprim_meanDeviationSP\n\n !************************************************************************\n\n!\n\n pure function mprim_meanDeviationInt(Ival) result(meanDev)\n\n!\n ! This function calculates the mean deviation of the given data\n!\n\n!\n ! integer data\n integer, dimension(:), intent(in) :: Ival\n!\n\n!\n ! mean deviation\n real(DP) :: meanDev\n!\n!\n\n ! local variable\n real(DP) :: mean\n integer(I32) :: i\n\n ! Compute mean\n mean = real(Ival(1), DP)\n\n do i = 2, size(Ival)\n mean = mean + real(Ival(i), DP)\n end do\n\n mean = mean/real(size(Ival), DP)\n\n ! Compute mean deviation\n meanDev = abs(Ival(1)-mean)\n\n do i = 2, size(Ival)\n meanDev = meanDev + abs(Ival(i)-mean)\n end do\n\n meanDev = meanDev/real(size(Ival), DP)\n\n end function mprim_meanDeviationInt\n\n !************************************************************************\n\n!\n\n pure function mprim_meanValueDP(Dval) result(meanVal)\n\n!\n ! This function calculates the mean value of the given data\n!\n\n!\n ! double data\n real(DP), dimension(:), intent(in) :: Dval\n!\n\n!\n ! mean value\n real(DP) :: meanVal\n!\n!\n\n ! local variable\n integer(I32) :: i\n\n ! Compute mean value\n meanVal = Dval(1)\n\n do i = 2, size(Dval)\n meanVal = meanVal + Dval(i)\n end do\n\n meanVal = meanVal/real(size(Dval), DP)\n end function mprim_meanValueDP\n\n !************************************************************************\n\n!\n\n pure function mprim_meanValueSP(Fval) result(meanVal)\n\n!\n ! This function calculates the mean value of the given data\n!\n\n!\n ! single data\n real(SP), dimension(:), intent(in) :: Fval\n!\n\n!\n ! mean value\n real(SP) :: meanVal\n!\n!\n\n ! local variable\n integer(I32) :: i\n\n ! Compute mean value\n meanVal = Fval(1)\n\n do i = 2, size(Fval)\n meanVal = meanVal + Fval(i)\n end do\n\n meanVal = meanVal/real(size(Fval), SP)\n end function mprim_meanValueSP\n\n !************************************************************************\n\n!\n\n pure function mprim_meanValueInt(Ival) result(meanVal)\n\n!\n ! This function calculates the mean value of the given data\n!\n\n!\n ! integer data\n integer, dimension(:), intent(in) :: Ival\n!\n\n!\n ! mean value\n integer :: meanVal\n!\n!\n\n ! local variable\n integer(I32) :: i\n\n ! Compute mean value\n meanVal = Ival(1)\n\n do i = 2, size(Ival)\n meanVal = meanVal + Ival(i)\n end do\n\n meanVal = meanVal/size(Ival)\n end function mprim_meanValueInt\n\n ! *****************************************************************************\n\n!\n\n elemental function mprim_degToRad(d) result(r)\n\n!\n ! This function converts DEG to RAD\n!\n\n!\n ! DEG\n real(DP), intent(in) :: d\n!\n\n!\n ! RAD\n real(DP) :: r\n!\n!\n\n r = d * (SYS_PI / 180._DP)\n end function mprim_degToRad\n\n ! *****************************************************************************\n\n!\n\n elemental function mprim_radToDeg(r) result(d)\n\n!\n ! This function converts RAD to DEG\n!\n\n!\n ! RAD\n real(DP), intent(in) :: r\n!\n\n!\n ! DEG\n real(DP) :: d\n!\n!\n\n d = r * (180._DP / SYS_PI)\n\n end function mprim_radToDeg\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_solve2x2DirectDP(Da,Db)\n\n!\n ! This subroutine directly solves a 2x2 system without any pivoting.\n ! 'Da' is a 2x2 matrix, Db a 2-tupel with the right hand\n ! side which is replaced by the solution.\n !\n ! Warning: For speed reasons, there is no array bounds checking\n ! activated in this routine! Da and Db are assumed to be 2x2 arrays!\n!\n\n!\n ! Matrix A.\n real(DP), dimension(2,2), intent(in) :: Da\n!\n\n!\n ! On entry: RHS vector b.\n ! On exit: Solution x with Ax=b.\n real(DP), dimension(2), intent(out) :: Db\n!\n\n!\n\n ! local variables\n real(DP) :: ddet,x1,x2\n\n ! Explicit formula for 2x2 systems, computed with Maple.\n ddet = 1.0_DP / (Da(1,1)*Da(2,2)-Da(1,2)*Da(2,1))\n x1 = Db(1)\n x2 = Db(2)\n Db(1) = -(Da(1,2)*x2 - Da(2,2)*x1) * ddet\n Db(2) = (Da(1,1)*x2 - Da(2,1)*x1) * ddet\n\n end subroutine mprim_solve2x2DirectDP\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_solve2x2DirectSP(Fa,Fb)\n\n!\n ! This subroutine directly solves a 2x2 system without any pivoting.\n ! 'Fa' is a 2x2 matrix, Fb a 2-tupel with the right hand\n ! side which is replaced by the solution.\n !\n ! Warning: For speed reasons, there is no array bounds checking\n ! activated in this routine! Fa and Fb are assumed to be 2x2 arrays!\n!\n\n!\n ! Matrix A.\n real(SP), dimension(2,2), intent(in) :: Fa\n!\n\n!\n ! On entry: RHS vector b.\n ! On exit: Solution x with Ax=b.\n real(SP), dimension(2), intent(out) :: Fb\n!\n\n!\n\n ! local variables\n real(SP) :: fdet,x1,x2\n\n ! Explicit formula for 2x2 systems, computed with Maple.\n fdet = 1.0_SP / (Fa(1,1)*Fa(2,2)-Fa(1,2)*Fa(2,1))\n x1 = Fb(1)\n x2 = Fb(2)\n Fb(1) = -(Fa(1,2)*x2 - Fa(2,2)*x1) * fdet\n Fb(2) = (Fa(1,1)*x2 - Fa(2,1)*x1) * fdet\n\n end subroutine mprim_solve2x2DirectSP\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_solve3x3DirectDP(Da,Db)\n\n!\n ! This subroutine directly solves a 3x3 system without any pivoting.\n ! 'Da' is a 3x3 matrix, Db a 3-tupel with the right hand\n ! side which is replaced by the solution.\n !\n ! Warning: For speed reasons, there is no array bounds checking\n ! activated in this routine! Da and Db are assumed to be 2x2 arrays!\n!\n\n!\n ! Matrix A.\n real(DP), dimension(3,3), intent(in) :: Da\n!\n\n!\n ! On entry: RHS vector b.\n ! On exit: Solution x with Ax=b.\n real(DP), dimension(3), intent(inout) :: Db\n!\n\n!\n\n ! local variables\n real(DP) :: ddet,x1,x2,x3\n\n ! Explicit formula for 3x3 systems, computed with Maple.\n ddet = 1.0_DP / &\n (Da(1,1)*Da(2,2)*Da(3,3) &\n -Da(1,1)*Da(3,2)*Da(2,3) &\n -Da(2,1)*Da(1,2)*Da(3,3) &\n +Da(3,2)*Da(2,1)*Da(1,3) &\n -Da(2,2)*Da(3,1)*Da(1,3) &\n +Da(3,1)*Da(1,2)*Da(2,3))\n x1 = Db(1)\n x2 = Db(2)\n x3 = Db(3)\n Db(1) = ddet * &\n (Da(1,2)*Da(2,3)*x3 &\n -Da(1,2)*x2*Da(3,3) &\n +Da(1,3)*Da(3,2)*x2 &\n -Da(1,3)*Da(2,2)*x3 &\n +x1*Da(2,2)*Da(3,3) &\n -x1*Da(3,2)*Da(2,3))\n Db(2) = - ddet * &\n (Da(1,1)*Da(2,3)*x3 &\n -Da(1,1)*x2*Da(3,3) &\n -Da(2,1)*Da(1,3)*x3 &\n -Da(2,3)*Da(3,1)*x1 &\n +x2*Da(3,1)*Da(1,3) &\n +Da(2,1)*x1*Da(3,3))\n Db(3) = ddet * &\n (Da(3,2)*Da(2,1)*x1 &\n -Da(1,1)*Da(3,2)*x2 &\n +Da(1,1)*Da(2,2)*x3 &\n -Da(2,2)*Da(3,1)*x1 &\n -Da(2,1)*Da(1,2)*x3 &\n +Da(3,1)*Da(1,2)*x2)\n\n end subroutine mprim_solve3x3DirectDP\n\n ! ***************************************************************************\n\n!\n\n pure subroutine mprim_solve3x3DirectSP(Fa,Fb)\n\n!\n ! This subroutine directly solves a 3x3 system without any pivoting.\n ! 'Fa' is a 3x3 matrix, Fb a 3-tupel with the right hand\n ! side which is replaced by the solution.\n !\n ! Warning: For speed reasons, there is no array bounds checking\n ! activated in this routine! Fa and Fb are assumed to be 2x2 arrays!\n!\n\n!\n ! Matrix A.\n real(SP), dimension(3,3), intent(in) :: Fa\n!\n\n!\n ! On entry: RHS vector b.\n ! On exit: Solution x with Ax=b.\n real(SP), dimension(3), intent(inout) :: Fb\n!\n\n!\n\n ! local variables\n real(SP) :: fdet,x1,x2,x3\n\n ! Explicit formula for 3x3 systems, computed with Maple.\n fdet = 1.0_SP / &\n (Fa(1,1)*Fa(2,2)*Fa(3,3) &\n -Fa(1,1)*Fa(3,2)*Fa(2,3) &\n -Fa(2,1)*Fa(1,2)*Fa(3,3) &\n +Fa(3,2)*Fa(2,1)*Fa(1,3) &\n -Fa(2,2)*Fa(3,1)*Fa(1,3) &\n +Fa(3,1)*Fa(1,2)*Fa(2,3))\n x1 = Fb(1)\n x2 = Fb(2)\n x3 = Fb(3)\n Fb(1) = fdet * &\n (Fa(1,2)*Fa(2,3)*x3 &\n -Fa(1,2)*x2*Fa(3,3) &\n +Fa(1,3)*Fa(3,2)*x2 &\n -Fa(1,3)*Fa(2,2)*x3 &\n +x1*Fa(2,2)*Fa(3,3) &\n -x1*Fa(3,2)*Fa(2,3))\n Fb(2) = - fdet * &\n (Fa(1,1)*Fa(2,3)*x3 &\n -Fa(1,1)*x2*Fa(3,3) &\n -Fa(2,1)*Fa(1,3)*x3 &\n -Fa(2,3)*Fa(3,1)*x1 &\n +x2*Fa(3,1)*Fa(1,3) &\n +Fa(2,1)*x1*Fa(3,3))\n Fb(3) = fdet * &\n (Fa(3,2)*Fa(2,1)*x1 &\n -Fa(1,1)*Fa(3,2)*x2 &\n +Fa(1,1)*Fa(2,2)*x3 &\n -Fa(2,2)*Fa(3,1)*x1 &\n -Fa(2,1)*Fa(1,2)*x3 &\n +Fa(3,1)*Fa(1,2)*x2)\n\n end subroutine mprim_solve3x3DirectSP\n\n ! ************************************************************************\n\n!\n\n pure subroutine mprim_solve2x2BandDiagDP (neqA,Da,Db,Dd,Dc,Dvec1,Dvec2)\n\n!\n ! This routine solves to a 2x2 block matrix with all blocks consisting\n ! of only diagonal bands.\n !\n ! \n!\n\n!\n ! Dimension of the matrix blocks\n integer, intent(in) :: neqA\n\n ! Submatrix A, only diagonal entries.\n real(DP), dimension(*), intent(in) :: Da\n\n ! Diagonal entries in the submatrix B.\n real(DP), dimension(*), intent(in) :: Db\n\n ! Diagonal entries in the submatrix D.\n real(DP), dimension(*), intent(in) :: Dd\n\n ! Diagonal elements of the local system matrix C\n real(DP), dimension(*), intent(in) :: Dc\n!\n\n!\n ! On entry: Right hand side F1.\n ! On exit: Solution vector U1.\n real(DP), dimension(*), intent(inout) :: Dvec1\n\n ! On entry: Right hand side F2.\n ! On exit: Solution vector U2.\n real(DP), dimension(*), intent(inout) :: Dvec2\n!\n\n!\n\n ! local variables\n integer :: i\n real(DP) :: ddet,a11,a12,a21,a22,x1,x2\n\n ! Such a system can be solved by reducing it to neqA*neqA 2x2 systems\n ! as there is only minimal coupling present between the entries.\n !\n ! Loop over the entries of the A matrix.\n do i=1,neqA\n\n ! Fetch a 2x2 system from the big matrix\n a11 = Da(i)\n a21 = Dd(i)\n a12 = Db(i)\n a22 = Dc(i)\n x1 = Dvec1(i)\n x2 = Dvec2(i)\n\n ! Solve the system, overwrite the input vector.\n ddet = 1.0_DP / (a11*a22 - a12*a21)\n Dvec1(i) = -(a12*x2 - a22*x1) * ddet\n Dvec2(i) = (a11*x2 - a21*x1) * ddet\n\n end do\n\n end subroutine mprim_solve2x2BandDiagDP\n\n ! ************************************************************************\n\n!\n\n pure subroutine mprim_solve2x2BandDiagSP (neqA,Fa,Fb,Dd,Fc,Fvec1,Fvec2)\n\n!\n ! This routine solves to a 2x2 block matrix with all blocks consisting\n ! of only diagonal bands.\n !\n ! \n!\n\n!\n ! Dimension of the matrix blocks\n integer, intent(in) :: neqA\n\n ! Submatrix A, only diagonal entries.\n real(SP), dimension(*), intent(in) :: Fa\n\n ! Diagonal entries in the submatrix B.\n real(SP), dimension(*), intent(in) :: Fb\n\n ! Diagonal entries in the submatrix D.\n real(SP), dimension(*), intent(in) :: Dd\n\n ! Diagonal elements of the local system matrix C\n real(SP), dimension(*), intent(in) :: Fc\n!\n\n!\n ! On entry: Right hand side F1.\n ! On exit: Solution vector U1.\n real(SP), dimension(*), intent(inout) :: Fvec1\n\n ! On entry: Right hand side F2.\n ! On exit: Solution vector U2.\n real(SP), dimension(*), intent(inout) :: Fvec2\n!\n\n!\n\n ! local variables\n integer :: i\n real(SP) :: fdet,a11,a12,a21,a22,x1,x2\n\n ! Such a system can be solved by reducing it to neqA*neqA 2x2 systems\n ! as there is only minimal coupling present between the entries.\n !\n ! Loop over the entries of the A matrix.\n do i=1,neqA\n\n ! Fetch a 2x2 system from the big matrix\n a11 = Fa(i)\n a21 = Dd(i)\n a12 = Fb(i)\n a22 = Fc(i)\n x1 = Fvec1(i)\n x2 = Fvec2(i)\n\n ! Solve the system, overwrite the input vector.\n fdet = 1.0_SP / (a11*a22 - a12*a21)\n Fvec1(i) = -(a12*x2 - a22*x1) * fdet\n Fvec2(i) = (a11*x2 - a21*x1) * fdet\n\n end do\n\n end subroutine mprim_solve2x2BandDiagSP\n\n !*****************************************************************************\n\n!\n\n elemental function mprim_minmod2DP(a,b) result (c)\n\n!\n ! The minmod functions returns zero if the two arguments a and b\n ! have different sign and the argument with the smallest absolute\n ! value otherwise.\n!\n\n!\n real(DP), intent(in) :: a,b\n!\n\n!\n real(DP) :: c\n!\n!\n\n if (a*b .le. 0.0_DP) then\n c = 0.0_DP\n else\n c = sign(min(abs(a), abs(b)), a)\n end if\n end function\n\n !*****************************************************************************\n\n!\n\n elemental function mprim_minmod2SP(a,b) result (c)\n\n!\n ! The minmod functions returns zero if the two arguments a and b\n ! have different sign and the argument with the smallest absolute\n ! value otherwise.\n!\n\n!\n real(SP), intent(in) :: a,b\n!\n\n!\n real(SP) :: c\n!\n!\n\n if (a*b .le. 0.0_DP) then\n c = 0.0_DP\n else\n c = sign(min(abs(a), abs(b)), a)\n end if\n end function\n\n !*****************************************************************************\n\n!\n\n elemental function mprim_minmod3DP(a,b,c) result (d)\n\n!\n ! The minmod functions returns zero if the two arguments a and b\n ! have different sign and the scaling parameter d by which the\n ! third argument c has to be scaled to obtain minmod(a,b) otherwise.\n!\n\n!\n real(DP), intent(in) :: a,b,c\n!\n\n!\n real(DP) :: d\n!\n!\n\n if (a*b*abs(c) .le. 0.0_DP) then\n d = 0.0_DP\n elseif (abs(a) .lt. abs(b)) then\n d = a/c\n else\n d = b/c\n end if\n end function\n\n !*****************************************************************************\n\n!\n\n elemental function mprim_minmod3SP(a,b,c) result (d)\n\n!\n ! The minmod functions returns zero if the two arguments a and b\n ! have different sign and the scaling parameter d by which the\n ! third argument c hass to be scaled to obtain minmod(a,b) otherwise.\n!\n\n!\n real(SP), intent(in) :: a,b,c\n!\n\n!\n real(SP) :: d\n!\n!\n\n if (a*b*abs(c) .le. 0.0_DP) then\n d = 0.0_DP\n elseif (abs(a) .lt. abs(b)) then\n d = a/c\n else\n d = b/c\n end if\n end function\n\n !*****************************************************************************\n\n!\n\n elemental function mprim_softmax2DP(a,b) result (c)\n\n!\n ! The softmax function computes the maximum value of the given\n ! data a and b but with smooth transition, that is, it does not\n ! switch abruptly between values a and b. This implementation is\n ! based on the idea of John D. Cook, c.f.\n ! http://www.johndcook.com/blog/2010/01/13/soft-maximum/\n ! This implementation is taken from\n ! http://www.johndcook.com/blog/2010/01/20/how-to-compute-the-soft-maximum/\n!\n\n!\n real(DP), intent(in) :: a,b\n!\n\n!\n real(DP) :: c\n!\n!\n\n ! local variables\n real(DP) :: dminval,dmaxval\n\n dminval = min(a,b)\n dmaxval = max(a,b)\n\n c = dmaxval + log(1.0_DP+exp(dminval-dmaxval))\n\n end function\n\n !*****************************************************************************\n\n!\n\n elemental function mprim_softmax3DP(a,b,c) result (d)\n\n!\n ! The softmax function computes the maximum value of the given\n ! data a and b but with smooth transition, that is, it does not\n ! switch abruptly between values a and b. This implementation is\n ! based on the idea of John D. Cook, c.f.\n ! http://www.johndcook.com/blog/2010/01/13/soft-maximum/\n ! The third parameter c is used to control the sharpness of the\n ! soft-maximum function. This implementation is taken from\n ! http://www.johndcook.com/blog/2010/01/20/how-to-compute-the-soft-maximum/\n!\n\n!\n real(DP), intent(in) :: a,b,c\n!\n\n!\n real(DP) :: d\n!\n!\n\n ! local variables\n real(DP) :: dminval,dmaxval\n\n dminval = min(a,b)\n dmaxval = max(a,b)\n\n d = dmaxval + log(1.0_DP+exp(c*(dminval-dmaxval)))/c\n\n end function\n\n !*****************************************************************************\n\n!\n\n elemental function mprim_softmax2SP(a,b) result (c)\n\n!\n ! The softmax function computes the maximum value of the given\n ! data a and b but with smooth transition, that is, it does not\n ! switch abruptly between values a and b. This implementation is\n ! based on the idea of John D. Cook, c.f.\n ! http://www.johndcook.com/blog/2010/01/13/soft-maximum/\n ! This implementation is taken from\n ! http://www.johndcook.com/blog/2010/01/20/how-to-compute-the-soft-maximum/\n!\n\n!\n real(SP), intent(in) :: a,b\n!\n\n!\n real(SP) :: c\n!\n!\n\n ! local variables\n real(SP) :: fminval,fmaxval\n\n fminval = min(a,b)\n fmaxval = max(a,b)\n\n c = fmaxval + log(1.0_SP+exp(fminval-fmaxval))\n\n end function\n\n !*****************************************************************************\n\n!\n\n elemental function mprim_softmax3SP(a,b,c) result (d)\n\n!\n ! The softmax function computes the maximum value of the given\n ! data a and b but with smooth transition, that is, it does not\n ! switch abruptly between values a and b. This implementation is\n ! based on the idea of John D. Cook, c.f.\n ! http://www.johndcook.com/blog/2010/01/13/soft-maximum/\n ! The third parameter c is used to control the sharpness of the\n ! soft-maximum function. This implementation is taken from\n ! http://www.johndcook.com/blog/2010/01/20/how-to-compute-the-soft-maximum/\n!\n\n!\n real(SP), intent(in) :: a,b,c\n!\n\n!\n real(SP) :: d\n!\n!\n\n ! local variables\n real(SP) :: fminval,fmaxval\n\n fminval = min(a,b)\n fmaxval = max(a,b)\n\n d = fmaxval + log(1.0_SP+exp(c*(fminval-fmaxval)))/c\n\n end function\n\n!*****************************************************************************\n\n!\n\n elemental function mprim_softmin2DP(a,b) result (c)\n\n!\n ! The softmin function computes the minimum value of the given\n ! data a and b but with smooth transition, that is, it does not\n ! switch abruptly between values a and b. This implementation is\n ! based on the idea of John D. Cook, c.f.\n ! http://www.johndcook.com/blog/2010/01/13/soft-maximum/\n ! This implementation is taken from\n ! http://www.johndcook.com/blog/2010/01/20/how-to-compute-the-soft-maximum/\n!\n\n!\n real(DP), intent(in) :: a,b\n!\n\n!\n real(DP) :: c\n!\n!\n\n ! local variables\n real(DP) :: dminval,dmaxval\n\n dminval = min(a,b)\n dmaxval = max(a,b)\n\n c = dminval - log(1.0_DP+exp(dminval-dmaxval))\n\n end function\n\n !*****************************************************************************\n\n!\n\n elemental function mprim_softmin3DP(a,b,c) result (d)\n\n!\n ! The softmin function computes the minimum value of the given\n ! data a and b but with smooth transition, that is, it does not\n ! switch abruptly between values a and b. This implementation is\n ! based on the idea of John D. Cook, c.f.\n ! http://www.johndcook.com/blog/2010/01/13/soft-maximum/\n ! The third parameter c is used to control the sharpness of the\n ! soft-maximum function. This implementation is taken from\n ! http://www.johndcook.com/blog/2010/01/20/how-to-compute-the-soft-maximum/\n!\n\n!\n real(DP), intent(in) :: a,b,c\n!\n\n!\n real(DP) :: d\n!\n!\n\n ! local variables\n real(DP) :: dminval,dmaxval\n\n dminval = min(a,b)\n dmaxval = max(a,b)\n\n d = dminval - log(1.0_DP+exp(c*(dminval-dmaxval)))/c\n\n end function\n\n !*****************************************************************************\n\n!\n\n elemental function mprim_softmin2SP(a,b) result (c)\n\n!\n ! The softmin function computes the minimum value of the given\n ! data a and b but with smooth transition, that is, it does not\n ! switch abruptly between values a and b. This implementation is\n ! based on the idea of John D. Cook, c.f.\n ! http://www.johndcook.com/blog/2010/01/13/soft-maximum/\n ! This implementation is taken from\n ! http://www.johndcook.com/blog/2010/01/20/how-to-compute-the-soft-maximum/\n!\n\n!\n real(SP), intent(in) :: a,b\n!\n\n!\n real(SP) :: c\n!\n!\n\n ! local variables\n real(SP) :: fminval,fmaxval\n\n fminval = min(a,b)\n fmaxval = max(a,b)\n\n c = fminval - log(1.0_SP+exp(fminval-fmaxval))\n\n end function\n\n !*****************************************************************************\n\n!\n\n elemental function mprim_softmin3SP(a,b,c) result (d)\n\n!\n ! The softmin function computes the minimum value of the given\n ! data a and b but with smooth transition, that is, it does not\n ! switch abruptly between values a and b. This implementation is\n ! based on the idea of John D. Cook, c.f.\n ! http://www.johndcook.com/blog/2010/01/13/soft-maximum/\n ! The third parameter c is used to control the sharpness of the\n ! soft-maximum function. This implementation is taken from\n ! http://www.johndcook.com/blog/2010/01/20/how-to-compute-the-soft-maximum/\n!\n\n!\n real(SP), intent(in) :: a,b,c\n!\n\n!\n real(SP) :: d\n!\n!\n\n ! local variables\n real(SP) :: fminval,fmaxval\n\n fminval = min(a,b)\n fmaxval = max(a,b)\n\n d = fminval - log(1.0_SP+exp(c*(fminval-fmaxval)))/c\n\n end function\n\n !*****************************************************************************\n\n!\n\n subroutine mprim_leastSquaresMinDP(Da,Db,Dx,ndim1,ndim2,ndim3,ndim4,&\n btransposedOpt,drcondOpt)\n\n!\n ! This subroutine solves the least-squares minimisation problem\n ! $$ min_x \\|Ax-b \\|_2 $$\n ! for given matrix $A$ and vector $b$. If matrix A has full rank\n ! the least-squares minimisation problem is solved using QR or LQ\n ! factorisation. If this approach fails then the least-squares\n ! minimisation problem is solved using a complete orthorgonal\n ! factorisation of matrix A which works also for rank-deficient\n ! matrices.\n!\n\n!\n ! Dimension of matrix\n integer, intent(in) :: ndim1,ndim2\n\n ! Dimension of right-hand side vector\n integer, intent(in) :: ndim3\n\n ! Dimension of solution vector\n integer, intent(in) :: ndim4\n\n ! Matrix for the least-squares minimisation\n real(DP), dimension(ndim1,ndim2), intent(in) :: Da\n\n ! Vector for the least-squares minimisation\n real(DP), dimension(ndim3), intent(in) :: Db\n\n ! OPTIONAL: Flag which indicates whether matrix A or its transpose\n ! should be used in the least-squares minimisation problem\n logical, intent(in), optional :: btransposedOpt\n\n ! OPTIONAL: Tolerance to determine the effective rank of matrix\n ! Da, which is defined as the order of the largest leading\n ! triangular submatrix in the QR factorisation with pivoting of A\n ! whose estimated condition number < 1/drcondOpt.\n real(DP), intent(in), optional :: drcondOpt\n!\n\n!\n ! Solution vector from the least-squares minimisation\n real(DP), dimension(ndim4), intent(out) :: Dx\n!\n\n!\n\n ! local variables\n real(DP), dimension(:,:), pointer :: p_Da\n real(DP), dimension(:), pointer :: p_Db,p_Dwork\n integer, dimension(:), pointer :: p_Ipvt\n integer :: nwork,naux,info,irank,n,m\n logical :: btransposed\n\n ! Do we have an optional transposed flag?\n if (present(btransposedOpt)) then\n btransposed = btransposedOpt\n else\n btransposed = .false.\n end if\n\n ! Determine size of working memory\n nwork = ndim1+ndim2\n\n ! Allocate working memory\n allocate(p_Dwork(nwork))\n\n ! Make a copy of the input matrix A which will be overwritten,\n ! e.g., be the QR or LQ factorisation\n allocate(p_Da(ndim1,ndim2))\n call lalg_copyVector(Da,p_Da,ndim1,ndim2)\n\n ! Determine size of source/destination vector\n naux = max(ndim3,ndim4)\n\n ! Make a copy of the input vector b which will be overwritten be\n ! the solution vector\n allocate(p_Db(naux))\n call lalg_copyVector(Db,p_Db,ndim3)\n \n ! Solve the least-squares minimisation problem using QR or LQ\n ! factorisation. It is assumed that matrix A has full rank.\n call dgels(merge('T','N',btransposed), ndim1, ndim2, 1, p_Da, ndim1,&\n p_Db, naux, p_Dwork, nwork, info)\n\n ! Check if solution procedure terminated without errors\n if (info .eq. 0) then\n\n ! Copy solution vector to output array\n call lalg_copyVector(p_Db,Dx,ndim4)\n\n ! Release internal memory\n deallocate(p_Da,p_Db,p_Dwork)\n\n ! That is it\n return\n end if\n \n ! Otherwise, ...\n if (info .lt. 0) then\n call output_line('Invalid parameter!',&\n OU_CLASS_ERROR,OU_MODE_STD,'mprim_leastSquareMinDP')\n call sys_halt()\n else\n \n ! Matrix A does not have full rank. In this case, we need to\n ! solve the least-squares minimisation problem using SVD.\n\n ! Release internal memory\n deallocate(p_Dwork)\n\n ! Again, make a copy of the input vector b which will be\n ! overwritten be the solution vector\n call lalg_copyVector(Db,p_Db,ndim3)\n\n ! Transposition of matrix A cannot be handled implicitly. In this\n ! case, we must transpose matrix A by hand before performing SVD.\n if (btransposed) then\n\n n = ndim1\n m = ndim2\n\n ! Transpose matrix A by hand\n deallocate(p_Da)\n allocate(p_Da(m,n))\n call mprim_transposeMatrix(Da,p_Da)\n\n else\n\n m = ndim1\n n = ndim2\n\n ! Make a copy of the input matrix A which will be overwritten.\n call lalg_copyVector(Da,p_Da,ndim1,ndim2)\n\n end if\n\n ! Allocate internal memory\n allocate(p_Ipvt(n))\n call lalg_clearVector(p_Ipvt)\n \n ! Determine size of working memory\n naux = min(m,n)\n nwork = max( naux+3*n+1, 2*naux+1 )\n allocate(p_Dwork(nwork))\n \n ! Do we have an optional tolerance paramter?\n if (present(drcondOpt)) then\n ! Solve the least-squares minimisation problem using SVD.\n call dgelsy(m, n, 1, p_Da, m, p_Db, m, p_Ipvt,&\n drcondOpt, irank, p_Dwork, nwork, info)\n else\n ! Solve the least-squares minimisation problem using SVD.\n call dgelsy(m, n, 1, p_Da, m, p_Db, m, p_Ipvt,&\n 1e-12_DP, irank, p_Dwork, nwork, info)\n end if\n\n ! Check if solution procedure terminated without errors\n if (info .eq. 0) then\n \n ! Copy solution vector to output array\n call lalg_copyVector(p_Db,Dx,ndim4)\n \n ! Release internal memory\n deallocate(p_Da,p_Db,p_Dwork,p_Ipvt)\n \n ! That is it\n return\n else\n call output_line('Unable to solve least-squares minimisation problem!',&\n OU_CLASS_ERROR,OU_MODE_STD,'mprim_leastSquareMinDP')\n call sys_halt() \n end if\n \n end if\n\n end subroutine mprim_leastSquaresMinDP\n\n !*****************************************************************************\n\n!\n\n subroutine mprim_leastSquaresMinSP(Fa,Fb,Fx,ndim1,ndim2,ndim3,ndim4,&\n btransposedOpt,frcondOpt)\n\n!\n ! This subroutine solves the least-squares minimisation problem\n ! $$ min_x \\|Ax-b \\|_2 $$\n ! for given matrix $A$ and vector $b$. If matrix A has full rank\n ! the least-squares minimisation problem is solved using QR or LQ\n ! factorisation. If this approach fails then the least-squares\n ! minimisation problem is solved using a complete orthorgonal\n ! factorisation of matrix A which works also for rank-deficient\n ! matrices.\n!\n\n!\n ! Dimension of matrix and vectors\n integer, intent(in) :: ndim1,ndim2\n\n ! Dimension of right-hand side vector\n integer, intent(in) :: ndim3\n\n ! Dimension of solution vector\n integer, intent(in) :: ndim4\n\n ! Matrix for the least-squares minimisation\n real(SP), dimension(ndim1,ndim2), intent(in) :: Fa\n\n ! Vector for the least-squares minimisation\n real(SP), dimension(ndim3), intent(in) :: Fb\n\n ! OPTIONAL: Flag which indicates whether matrix A or its transpose\n ! should be used in the least-squares minimisation problem\n logical, intent(in), optional :: btransposedOpt\n\n ! OPTIONAL: Tolerance to determine the effective rank of matrix\n ! Da, which is defined as the order of the largest leading\n ! triangular submatrix in the QR factorisation with pivoting of A\n ! whose estimated condition number < 1/frcondOpt.\n real(SP), intent(in), optional :: frcondOpt\n!\n\n!\n ! Solution vector from the least-squares minimisation\n real(SP), dimension(ndim4), intent(out) :: Fx\n!\n\n!\n\n ! local variables\n real(SP), dimension(:,:), pointer :: p_Fa\n real(SP), dimension(:), pointer :: p_Fb,p_Fwork\n integer, dimension(:), pointer :: p_Ipvt\n integer :: nwork,naux,info,irank,n,m\n logical :: btransposed\n\n ! Do we have an optional transposed flag?\n if (present(btransposedOpt)) then\n btransposed = btransposedOpt\n else\n btransposed = .false.\n end if\n\n ! Determine size of working memory\n nwork = ndim1+ndim2\n\n ! Allocate working memory\n allocate(p_Fwork(nwork))\n\n ! Make a copy of the input matrix A which will be overwritten,\n ! e.g., be the QR or LQ factorisation\n allocate(p_Fa(ndim1,ndim2))\n call lalg_copyVector(Fa,p_Fa,ndim1,ndim2)\n\n ! Determine size of source/destination vector\n naux = max(ndim3,ndim4)\n\n ! Make a copy of the input vector b which will be overwritten be\n ! the solution vector\n allocate(p_Fb(naux))\n call lalg_copyVector(Fb,p_Fb,ndim3)\n \n ! Solve the least-squares minimisation problem using QR or LQ\n ! factorisation. It is assumed that matrix A has full rank.\n call sgels(merge('T','N',btransposed), ndim1, ndim2, 1, p_Fa, ndim1,&\n p_Fb, naux, p_Fwork, nwork, info)\n\n ! Check if solution procedure terminated without errors\n if (info .eq. 0) then\n\n ! Copy solution vector to output array\n call lalg_copyVector(p_Fb,Fx,ndim4)\n\n ! Release internal memory\n deallocate(p_Fa,p_Fb,p_Fwork)\n\n ! That is it\n return\n end if\n \n ! Otherwise, ...\n if (info .lt. 0) then\n call output_line('Invalid parameter!',&\n OU_CLASS_ERROR,OU_MODE_STD,'mprim_leastSquareMinSP')\n call sys_halt()\n else\n \n ! Matrix A does not have full rank. In this case, we need to\n ! solve the least-squares minimisation problem using SVD.\n\n ! Release internal memory\n deallocate(p_Fwork)\n\n ! Again, make a copy of the input vector b which will be\n ! overwritten be the solution vector\n call lalg_copyVector(Fb,p_Fb,ndim3)\n\n ! Transposition of matrix A cannot be handled implicitly. In this\n ! case, we must transpose matrix A by hand before performing SVD.\n if (btransposed) then\n\n n = ndim1\n m = ndim2\n\n ! Transpose matrix A by hand\n deallocate(p_Fa)\n allocate(p_Fa(m,n))\n call mprim_transposeMatrix(Fa,p_Fa)\n\n else\n\n m = ndim1\n n = ndim2\n\n ! Make a copy of the input matrix A which will be overwritten.\n call lalg_copyVector(Fa,p_Fa,ndim1,ndim2)\n\n end if\n\n ! Allocate internal memory\n allocate(p_Ipvt(n))\n call lalg_clearVector(p_Ipvt)\n \n ! Determine size of working memory\n naux = min(m,n)\n nwork = max( naux+3*n+1, 2*naux+1 )\n allocate(p_Fwork(nwork))\n\n ! Do we have an optional tolerance paramter?\n if (present(frcondOpt)) then\n ! Solve the least-squares minimisation problem using SVD.\n call sgelsy(m, n, 1, p_Fa, m, p_Fb, m, p_Ipvt,&\n frcondOpt, irank, p_Fwork, nwork, info)\n else\n ! Solve the least-squares minimisation problem using SVD.\n call sgelsy(m, n, 1, p_Fa, m, p_Fb, m, p_Ipvt,&\n 1e-12_SP, irank, p_Fwork, nwork, info)\n end if\n\n ! Check if solution procedure terminated without errors\n if (info .eq. 0) then\n \n ! Copy solution vector to output array\n call lalg_copyVector(p_Fb,Fx,ndim4)\n \n ! Release internal memory\n deallocate(p_Fa,p_Fb,p_Fwork,p_Ipvt)\n \n ! That is it\n return\n else\n call output_line('Unable to solve least-squares minimisation problem!',&\n OU_CLASS_ERROR,OU_MODE_STD,'mprim_leastSquareMinSP')\n call sys_halt() \n end if\n \n end if\n\n end subroutine mprim_leastSquaresMinSP\n\n !*****************************************************************************\n\n!\n\n subroutine mprim_transposeMatrix1DP(Da)\n\n!\n ! This subroutine computes the transpose of the source matrix A in-place.\n!\n\n!\n ! On input: source matrix that should be transposed.\n ! On output: transposed matrix.\n real(DP), dimension(:,:), intent(inout) :: Da\n!\n!\n\n#if !defined(USE_INTEL_MKL)\n real(DP), dimension(:), allocatable :: Daux\n integer :: i,j,n\n#endif\n\n ! Check if matrix is square matrix\n if (size(Da,1) .ne. size(Da,2)) then\n call output_line('Matrix must be square matrix for in-place transposition!',&\n OU_CLASS_ERROR,OU_MODE_STD,'mprim_transposeMatrix1DP')\n call sys_halt()\n end if\n \n#ifdef USE_INTEL_MKL\n ! Call in-place transposition from Intel MKL library\n call mkl_dimatcopy('C', 'T', size(Da,1), size(Da,2), 1.0_DP, Da, size(Da,1), size(Da,2))\n#else\n n = size(Da,1)\n allocate(Daux(n))\n\n ! Loop over all columns of the square matrix\n do i=1,n\n ! Make a copy of the i-th column\n Daux(i:n) = Da(i:n,i)\n \n ! Swap content of i-th row and column\n do j=i,n\n Da(j,i) = Da(i,j)\n Da(i,j) = Daux(j)\n end do\n end do\n\n deallocate(Daux)\n#endif\n\n end subroutine mprim_transposeMatrix1DP\n\n !*****************************************************************************\n\n!\n\n subroutine mprim_transposeMatrix1SP(Fa)\n\n!\n ! This subroutine computes the transpose of the source matrix A in-place.\n!\n\n!\n ! On input: source matrix that should be transposed.\n ! On output: transposed matrix.\n real(SP), dimension(:,:), intent(inout) :: Fa\n!\n!\n\n#if !defined(USE_INTEL_MKL)\n real(SP), dimension(:), allocatable :: Faux\n integer :: i,j,n\n#endif\n\n ! Check if matrix is square matrix\n if (size(Fa,1) .ne. size(Fa,2)) then\n call output_line('Matrix must be square matrix for in-place transposition!',&\n OU_CLASS_ERROR,OU_MODE_STD,'mprim_transposeMatrix1SP')\n call sys_halt()\n end if\n \n#ifdef USE_INTEL_MKL\n ! Call in-place transposition from Intel MKL library\n call mkl_simatcopy('C', 'T', size(Fa,1), size(Fa,2), 1.0_SP, Fa, size(Fa,1), size(Fa,2))\n#else\n n = size(Fa,1)\n allocate(Faux(n))\n\n ! Loop over all columns of the square matrix\n do i=1,n\n ! Make a copy of the i-th column\n Faux(i:n) = Fa(i:n,i)\n \n ! Swap content of i-th row and column\n do j=i,n\n Fa(j,i) = Fa(i,j)\n Fa(i,j) = Faux(j)\n end do\n end do\n\n deallocate(Faux)\n#endif\n\n end subroutine mprim_transposeMatrix1SP\n\n !*****************************************************************************\n\n!\n\n subroutine mprim_transposeMatrix2DP(DaSrc,DaDest)\n\n!\n ! This subroutine computes the transpose of the source matrix A out-of-place.\n!\n\n!\n ! Source matrix that should be transposed.\n real(DP), dimension(:,:), intent(in) :: DaSrc\n!\n\n!\n ! Destination matrix containing the transposed of matrix A on output\n real(DP), dimension(:,:), intent(out) :: DaDest\n!\n!\n\n#if !defined(USE_INTEL_MKL)\n integer :: i,j\n#endif\n\n ! Check if matrix dimensions are compatible\n if ((size(DaSrc,1) .ne. size(DaDest,2)) .or.&\n (size(DaSrc,2) .ne. size(DaDest,1))) then\n call output_line('Matrix dimensions mismatch!',&\n OU_CLASS_ERROR,OU_MODE_STD,'mprim_transposeMatrix2DP')\n call sys_halt()\n end if\n\n#ifdef USE_INTEL_MKL\n ! Call out-of-place transposition from Intel MKL library\n call mkl_domatcopy('C', 'T', size(DaSrc,1), size(DaSrc,2), 1.0_DP,&\n DaSrc, size(DaSrc,1), DaDest, size(DaDest,1))\n#else\n ! Loop over all columns of the square matrix\n !$omp parallel do private(j) default(shared)\n do i=1,size(DaSrc,1)\n ! Swap content of i-th row and column\n do j=1,size(DaSrc,2)\n DaDest(j,i) = DaSrc(i,j)\n end do\n end do\n !$omp end parallel do\n#endif\n\n end subroutine mprim_transposeMatrix2DP\n\n !*****************************************************************************\n\n!\n\n subroutine mprim_transposeMatrix2SP(FaSrc,FaDest)\n\n!\n ! This subroutine computes the transpose of the source matrix A out-of-place.\n!\n\n!\n ! Source matrix that should be transposed.\n real(SP), dimension(:,:), intent(in) :: FaSrc\n!\n\n!\n ! Destination matrix containing the transposed of matrix A on output\n real(SP), dimension(:,:), intent(out) :: FaDest\n!\n!\n\n#if !defined(USE_INTEL_MKL)\n integer :: i,j\n#endif\n\n ! Check if matrix dimensions are compatible\n if ((size(FaSrc,1) .ne. size(FaDest,2)) .or.&\n (size(FaSrc,2) .ne. size(FaDest,1))) then\n call output_line('Matrix dimensions mismatch!',&\n OU_CLASS_ERROR,OU_MODE_STD,'mprim_transposeMatrix2SP')\n call sys_halt()\n end if\n\n#ifdef USE_INTEL_MKL\n ! Call out-of-place transposition from Intel MKL library\n call mkl_somatcopy('C', 'T', size(FaSrc,1), size(FaSrc,2), 1.0_SP,&\n FaSrc, size(FaSrc,1), FaDest, size(FaDest,1))\n#else\n ! Loop over all columns of the square matrix\n !$omp parallel do private(j) default(shared)\n do i=1,size(FaSrc,1)\n ! Swap content of i-th row and column\n do j=1,size(FaSrc,2)\n FaDest(j,i) = FaSrc(i,j)\n end do\n end do\n !$omp end parallel do\n#endif\n\n end subroutine mprim_transposeMatrix2SP\n\n !*****************************************************************************\n\n!\n\n pure real(DP) function mprim_hornerDP(dx,Dai)\n \n!\n ! Applies the horner scheme to evaluate a polynomial\n ! p(x) = a_0 + a_1 x + a_2 x^2 + ...\n ! given as a list of coefficients.\n!\n\n!\n ! Point where to evaluate\n real(DP), intent(in) :: dx\n\n ! List of coefficients\n real(DP), dimension(:), intent(in) :: Dai\n!\n\n!\n ! p(x)\n!\n\n!\n \n integer :: i\n \n mprim_hornerDP = 0.0_DP\n do i = ubound(Dai,1),1,-1\n mprim_hornerDP = mprim_hornerDP * dx + Dai(i)\n end do\n \n end function\n\n !*****************************************************************************\n\n!\n\n pure real(DP) function mprim_hornerd1DP(dx,Dai)\n \n!\n ! Applies the extended horner scheme to evaluate the derivative p'(x) of a polynomial\n ! p(x) = a_0 + a_1 x + a_2 x^2 + ...\n ! given as a list of coefficients.\n!\n\n!\n ! Point where to evaluate\n real(DP), intent(in) :: dx\n\n ! List of coefficients\n real(DP), dimension(:), intent(in) :: Dai\n!\n\n!\n ! p'(x)\n!\n\n!\n\n integer :: i\n real(DP) :: dy\n \n dy = 0.0_DP\n mprim_hornerd1DP = 0.0_DP\n do i = ubound(Dai,1),1,-1\n mprim_hornerd1DP = mprim_hornerd1DP * dx + dy\n dy = dy * dx + Dai(i)\n end do\n \n end function\n \n !*****************************************************************************\n\n!\n\n pure real(DP) function mprim_hornerd2DP(dx,Dai)\n \n!\n ! Applies the extended horner scheme to evaluate the 2nd derivative p''(x) of a polynomial\n ! p(x) = a_0 + a_1 x + a_2 x^2 + ...\n ! given as a list of coefficients.\n!\n\n!\n ! Point where to evaluate\n real(DP), intent(in) :: dx\n\n ! List of coefficients\n real(DP), dimension(:), intent(in) :: Dai\n!\n\n!\n ! p''(x)\n!\n\n!\n\n integer :: i\n real(DP) :: dy, dy1\n \n dy = 0.0_DP\n dy1 = 0.0_DP\n mprim_hornerd2DP = 0.0_DP\n do i = ubound(Dai,1),1,-1\n mprim_hornerd2DP = mprim_hornerd2DP * dx + dy1\n dy1 = dy1 * dx + dy\n dy = dy * dx + Dai(i)\n end do\n \n end function\n \n !*****************************************************************************\n\n!\n\n pure real(DP) function mprim_hornerSP(fx,Fai)\n \n!\n ! Applies the horner scheme to evaluate a polynomial\n ! p(x) = a_0 + a_1 x + a_2 x^2 + ...\n ! given as a list of coefficients.\n!\n\n!\n ! Point where to evaluate\n real(SP), intent(in) :: fx\n\n ! List of coefficients\n real(SP), dimension(:), intent(in) :: Fai\n!\n\n!\n ! p(x)\n!\n\n!\n \n integer :: i\n \n mprim_hornerSP = 0.0_DP\n do i = ubound(Fai,1),1,-1\n mprim_hornerSP = mprim_hornerSP * fx + Fai(i)\n end do\n \n end function\n\n !*****************************************************************************\n\n!\n\n pure real(DP) function mprim_hornerd1SP(fx,Fai)\n \n!\n ! Applies the extended horner scheme to evaluate the derivative p'(x) of a polynomial\n ! p(x) = a_0 + a_1 x + a_2 x^2 + ...\n ! given as a list of coefficients.\n!\n\n!\n ! Point where to evaluate\n real(SP), intent(in) :: fx\n\n ! List of coefficients\n real(SP), dimension(:), intent(in) :: Fai\n!\n\n!\n ! p'(x)\n!\n\n!\n\n integer :: i\n real(SP) :: fy\n \n fy = 0.0_DP\n mprim_hornerd1SP = 0.0_DP\n do i = ubound(Fai,1),1,-1\n mprim_hornerd1SP = mprim_hornerd1SP * fx + fy\n fy = fy * fx + Fai(i)\n end do\n \n end function\n \n !*****************************************************************************\n\n!\n\n pure real(DP) function mprim_hornerd2SP(fx,Fai)\n \n!\n ! Applies the extended horner scheme to evaluate the 2nd derivative p''(x) of a polynomial\n ! p(x) = a_0 + a_1 x + a_2 x^2 + ...\n ! given as a list of coefficients.\n!\n\n!\n ! Point where to evaluate\n real(SP), intent(in) :: fx\n\n ! List of coefficients\n real(SP), dimension(:), intent(in) :: Fai\n!\n\n!\n ! p''(x)\n!\n\n!\n\n integer :: i\n real(SP) :: fy, fy1\n \n fy = 0.0_DP\n fy1 = 0.0_DP\n mprim_hornerd2SP = 0.0_DP\n do i = ubound(Fai,1),1,-1\n mprim_hornerd2SP = mprim_hornerd2SP * fx + fy1\n fy1 = fy1 * fx + fy\n fy = fy * fx + Fai(i)\n end do\n \n end function\n \n ! ***************************************************************************\n\n!\n\n elemental subroutine mprim_polarToCartesian2D(dr,dphi,dx,dy)\n\n!\n ! Calculates 2D cartesian coordinates from polar coordinates\n!\n\n!\n ! Radius and angle of a point.\n real(DP), intent(in) :: dr, dphi\n!\n\n!\n ! X/Y cartesian coordinate of the point\n real(DP), intent(out) :: dx,dy\n!\n\n!\n\n dx = dr * cos(dphi)\n dy = dr * sin(dphi)\n\n end subroutine\n\n ! ***************************************************************************\n\n!\n\n elemental subroutine mprim_polarToCartesian3D(dr,dphi,dpsi,dx,dy,dz)\n\n!\n ! Calculates 3D cartesian coordinates from polar coordinates\n!\n\n!\n ! Radius, Y-angle and Z-angle of a point.\n real(DP), intent(in) :: dr, dphi, dpsi\n!\n\n!\n ! X/Y/Z cartesian coordinate of the point.\n real(DP), intent(out) :: dx,dy,dz\n!\n\n!\n\n dx = dr * cos(dphi)\n dy = dr * sin(dphi)\n dz = dr * sin(dpsi)\n\n end subroutine\n\n ! ***************************************************************************\n\n!\n\n elemental subroutine mprim_cartesianToPolar2D(dx,dy,dr,dphi)\n\n!\n ! Calculates 2D cartesian coordinates from polar coordinates\n!\n\n!\n ! X/Y cartesian coordinate of a point\n real(DP), intent(in) :: dx,dy\n!\n\n!\n ! Radius and angle of a point.\n real(DP), intent(out) :: dr, dphi\n!\n\n!\n\n dr = sqrt(dx**2 + dy**2)\n dphi = atan2 (dy,dx)\n\n end subroutine\n\n ! ***************************************************************************\n\n!\n\n elemental subroutine mprim_cartesianToPolar3D(dx,dy,dz,dr,dphi,dpsi)\n\n!\n ! Calculates 3D cartesian coordinates from polar coordinates\n!\n\n!\n ! X/Y/Z cartesian coordinate of a point\n real(DP), intent(in) :: dx,dy,dz\n!\n\n!\n ! Radius, Y-angle and Z-angle of a point.\n real(DP), intent(out) :: dr, dphi, dpsi\n!\n\n!\n\n dr = sqrt(dx**2 + dy**2 + dz**2)\n dphi = atan2 (dy,dx)\n \n if (dr .gt. SYS_EPSREAL_DP) then\n dpsi = asin (dy/dr)\n else\n dpsi = 0.0_DP\n end if\n\n end subroutine\n\nend module mprimitives\n", "meta": {"hexsha": "87370ac5c044d19cfa40a9f205e0a04450dba69c", "size": 184290, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "kernel/Mathematics/mprimitives.f90", "max_stars_repo_name": "trmcnealy/Featflow2", "max_stars_repo_head_hexsha": "4af17507bc2d80396bf8ea85c9e30e9e4d2383df", "max_stars_repo_licenses": ["Intel", "Unlicense"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-08-02T11:51:34.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-10T14:14:21.000Z", "max_issues_repo_path": "kernel/Mathematics/mprimitives.f90", "max_issues_repo_name": "tudo-math-ls3/FeatFlow2", "max_issues_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_issues_repo_licenses": ["Intel", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "kernel/Mathematics/mprimitives.f90", "max_forks_repo_name": "tudo-math-ls3/FeatFlow2", "max_forks_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_forks_repo_licenses": ["Intel", "Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.6524537409, "max_line_length": 100, "alphanum_fraction": 0.5086222801, "num_tokens": 73807, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632261523028, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.7804263095399112}} {"text": "*deck aratio_tri\n subroutine aratio_tri(xl1,yl1,zl1,\n * xl2,yl2,zl2,\n * xl3,yl3,zl3,\n * arattri)\nC\nC\nC #####################################################################\nC\nC PURPOSE -\nC\nC Finds the aspect ratio of a tri.\nC\nC INPUT ARGUMENTS -\nC\nC (x1,y1,z1),...,(x3,y3,z3) - The coordinates of the tri.\nC\nC OUTPUT ARGUMENTS -\nC\nC arattri : The aspect ratio of the tri.\nC\nC CHANGE HISTORY -\nC\nC $Log: aratio_tri.f,v $\nC Revision 2.00 2007/11/05 19:45:46 spchu\nC Import to CVS\nC\nCPVCS \nCPVCS Rev 1.1 Fri Jan 08 16:58:28 1999 kuprat\nCPVCS We now prevent zero divides using SAFE.\nCPVCS \nCPVCS Rev 1.0 Fri Aug 29 14:11:34 1997 dcg\nCPVCS Initial revision.\nC\nC ######################################################################\nC\nC\n implicit none\nC\n include \"consts.h\"\n include \"local_element.h\"\nC\n real*8 xl1,yl1,zl1,xl2,yl2,zl2,xl3,yl3,zl3\n real*8 arattri\n real*8 rcir\n real*8 rinsc\n real*8 ax4,ay4,az4,farea\n real*8 ds1,ds2,ds3\n\n include \"statementfunctions.h\"\nC\nC ######################################################################\nC\n ax4 = (yl3 - yl1)*(zl2 - zl1)-(zl3-zl1)*(yl2-yl1)\n ay4 = -((xl3 - xl1)*(zl2 - zl1)-(zl3 - zl1)*\n * (xl2 - xl1))\n az4 = (xl3 - xl1)*(yl2 - yl1)-(yl3 - yl1)*\n * (xl2 - xl1)\nC radius of inscribed circle is 2*area of triangle/perimeter\nC radius of circumscribed circle is l1*l2*l3/4*area where l1,l2,l3 are edge\nC lengths\nC\n farea=.5*sqrt(ax4**2+ay4**2+az4**2)\n ds1 = sqrt((xl3 - xl2)**2+(yl3 - yl2)**2+\n * (zl3 - zl2)**2)\n ds2 = sqrt((xl1 - xl3)**2+(yl1 - yl3)**2+\n * (zl1 - zl3)**2)\n ds3 = sqrt((xl2 - xl1)**2+(yl2 - yl1)**2 +\n * (zl2 - zl1)**2)\n rinsc = 2.*farea/safe(ds1+ds2+ds3)\n rcir= ds1*ds2*ds3/safe(4.*farea)\n \n arattri= 2.*rinsc/safe(rcir)\n \n return\n end\n", "meta": {"hexsha": "27384d5cdf361573900338c1caa770d2e412a7ec", "size": 2029, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/aratio_tri.f", "max_stars_repo_name": "millerta/LaGriT-1", "max_stars_repo_head_hexsha": "511ef22f3b7e839c7e0484604cd7f6a2278ae6b9", "max_stars_repo_licenses": ["CNRI-Python"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2017-02-09T17:54:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T22:22:32.000Z", "max_issues_repo_path": "src/aratio_tri.f", "max_issues_repo_name": "millerta/LaGriT-1", "max_issues_repo_head_hexsha": "511ef22f3b7e839c7e0484604cd7f6a2278ae6b9", "max_issues_repo_licenses": ["CNRI-Python"], "max_issues_count": 166, "max_issues_repo_issues_event_min_datetime": "2017-01-26T17:15:45.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T21:36:28.000Z", "max_forks_repo_path": "src/lg_core/aratio_tri.f", "max_forks_repo_name": "daniellivingston/LaGriT", "max_forks_repo_head_hexsha": "decd0ce0e5dab068034ef382cabcd134562de832", "max_forks_repo_licenses": ["Intel"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2017-02-08T21:56:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T06:48:36.000Z", "avg_line_length": 26.3506493506, "max_line_length": 76, "alphanum_fraction": 0.4805322819, "num_tokens": 744, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850128595114, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7802293333135091}} {"text": "SUBROUTINE R3x3 (R1, R2, R3)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: matrixRxR (matrix_RxR.f90)\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Multiply 2 matrices 3x3 \r\n! ----------------------------------------------------------------------\r\n! Input arguments:\r\n! - R1 : Matrix 1 with dimensions 3x3\r\n! - R1 : Matrix 2 with dimensions 3x3\r\n!\r\n! Output arguments:\r\n! - R3 : Matrix 3x3 obtained from multiplication R1*R2\r\n! ----------------------------------------------------------------------\r\n! Author :\tDr. Thomas Papanikolaou\r\n!\t\t\tCooperative Research Centre for Spatial Information, Australia\r\n! Created:\t7 March 2018\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n USE mdl_precision\r\n IMPLICIT NONE\r\n\r\n! ---------------------------------------------------------------------------\r\n! Dummy arguments declaration\r\n! ---------------------------------------------------------------------------\r\n! IN\r\n REAL (KIND = prec_q), INTENT(IN), DIMENSION(3,3) :: R1, R2\r\n! OUT\r\n REAL (KIND = prec_d), INTENT(OUT), DIMENSION(3,3) :: R3\r\n! ---------------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Local variables declaration\r\n! ----------------------------------------------------------------------\r\n INTEGER (KIND = prec_int8) :: R1_i, R1_j, R2_i, R2_j\r\n INTEGER (KIND = prec_int8) :: i, j, n, m\r\n REAL (KIND = prec_q) :: R3_ij\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n R1_i = size(R1, dim = 1)\r\n R1_j = size(R1, dim = 2)\r\n\t \r\n R2_i = size(R2, dim = 1)\r\n R2_j = size(R2, dim = 2)\r\n\t \r\n DO i = 1 , R1_i\t \r\n DO m = 1 , R2_j\r\n ! R3(i,m)\t\t \r\n R3_ij = 0.0D0\r\n DO j = 1 , R1_j\r\n n = j\r\n\t\t\tR3_ij = R1(i,j) * R2(n,m) + R3_ij\r\n End Do\r\n R3(i,m) = R3_ij \r\n End Do\r\n End Do\r\n\t\r\n\r\n\r\n\r\nEND SUBROUTINE\r\n", "meta": {"hexsha": "81903627fe1dc69ae53d440e76b3d5952b0b294b", "size": 2084, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/R3x3.f03", "max_stars_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_stars_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2021-07-08T23:35:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:17:58.000Z", "max_issues_repo_path": "src/fortran/R3x3.f03", "max_issues_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_issues_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-09-27T14:27:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T23:50:02.000Z", "max_forks_repo_path": "src/fortran/R3x3.f03", "max_forks_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_forks_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2021-07-12T05:42:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T15:15:34.000Z", "avg_line_length": 31.5757575758, "max_line_length": 78, "alphanum_fraction": 0.3282149712, "num_tokens": 491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.936285009303773, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7802293303504247}} {"text": "function logsum(N,X) result(Xsum)\n ! calculate log(sum exp(x))\n implicit none\n integer, intent(in) :: N ! length of X\n real(8), intent(in) :: X(N) ! data\n real(8) :: Xsum, maxv\n integer :: i\n maxv = maxval(X)\n Xsum = 0.0d0\n do i = 1, N\n Xsum = Xsum + exp(X(i) - maxv)\n enddo\n Xsum = log(Xsum) + maxv\nend function\n\nsubroutine forward_F(T,N,lnpi,lnA,lnf,lnalpha)\n implicit none\n integer, intent(in) :: T,N\n real(8), intent(in) :: lnpi(N), lnA(N,N), lnf(T,N)\n real(8), intent(out) :: lnalpha(T,N)\n integer :: tt,i,j\n real(8) :: temp(N)\n real(8), external :: logsum\n \n lnalpha(1,:) = lnpi(:) + lnf(1,:)\n \n do tt = 2, T\n do j = 1, N\n temp(:) = lnalpha(tt-1,:) + lnA(:,j)\n lnalpha(tt,j) = logsum(N,temp) + lnf(tt,j)\n enddo\n enddo\nend subroutine\n\nsubroutine backward_F(T,N,lnpi,lnA,lnf,lnbeta)\n implicit none\n integer, intent(in) :: T,N\n real(8), intent(in) :: lnpi(N), lnA(N,N), lnf(T,N)\n real(8), intent(out) :: lnbeta(T,N)\n integer :: tt,i,j\n real(8) :: temp(N)\n real(8), external :: logsum\n \n lnbeta(T,:) = 0.0d0\n \n do tt = T-1,1,-1\n do i = 1, N\n temp(:) = lnA(i,:) + lnf(tt+1,:) + lnbeta(tt+1,:)\n lnbeta(tt,i) = logsum(N,temp)\n enddo\n enddo\nend subroutine\n\nsubroutine compute_lnEta_F(T,N,lnalpha,lnA,lnbeta,lnf,lnP_f,lneta)\n implicit none\n integer, intent(in) :: T,N\n real(8), intent(in) :: lnA(N,N), lnf(T,N), lnalpha(T,N), lnbeta(T,N), lnP_f\n real(8), intent(out) :: lneta(T-1,N,N)\n integer :: i,j,tt\n\n do tt = 1, T-1\n do i = 1, N\n do j = 1, N\n lneta(tt,i,j) = lnalpha(tt,i) + lnA(i,j) &\n + lnf(tt+1,j) + lnbeta(tt+1,j) - lnP_f\n enddo\n enddo\n enddo\nend subroutine\n\nsubroutine viterbi_F(T,N,lnpi,lnA,lnf,z,lnP)\n implicit none\n integer, intent(in) :: T,N\n real(8), intent(in) :: lnpi(N), lnA(N,N), lnf(T,N)\n integer(8), intent(out) :: z(T)\n real(8), intent(out) :: lnP\n integer :: tt,i,j,imax(1)\n real(8) :: lndelta(T,N)\n real(8) :: temp(N)\n\n ! Initialization\n lndelta(1,:) = lnpi + lnf(1,:)\n\n ! Induction\n do tt = 2, T\n do j = 1, N\n temp(:) = lndelta(tt-1,:) + lnA(:,j)\n lndelta(tt,j) = maxval(temp(:)) + lnf(tt,j)\n enddo\n enddo\n\n lnP = maxval(lndelta(T,:))\n\n ! Traceback\n imax = maxloc(lndelta(T,:))\n z(T) = imax(1)\n \n do tt = T-1, 1, -1\n imax = maxloc(lndelta(tt,:) + lnA(:,z(tt+1)))\n z(tt) = imax(1)\n enddo\n\n ! make numbering consistent to that of python\n z(:) = z(:) - 1\n\nend subroutine\n", "meta": {"hexsha": "d7cf206f998100fe2cff22c93a9565b82b04c255", "size": 2681, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pyvb/_hmmf.f90", "max_stars_repo_name": "lucidfrontier45/PyVB", "max_stars_repo_head_hexsha": "5218fbcf9ffa106a644e318b03a8005f3daf9f57", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2015-07-23T07:43:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-05T06:04:55.000Z", "max_issues_repo_path": "pyvb/_hmmf.f90", "max_issues_repo_name": "lucidfrontier45/PyVB", "max_issues_repo_head_hexsha": "5218fbcf9ffa106a644e318b03a8005f3daf9f57", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pyvb/_hmmf.f90", "max_forks_repo_name": "lucidfrontier45/PyVB", "max_forks_repo_head_hexsha": "5218fbcf9ffa106a644e318b03a8005f3daf9f57", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2015-11-17T21:32:55.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-17T15:59:50.000Z", "avg_line_length": 25.0560747664, "max_line_length": 79, "alphanum_fraction": 0.5117493473, "num_tokens": 994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850075259039, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7802293269310606}} {"text": "! Generic math subroutines\r\nmodule math_mod\r\n\r\n implicit none\r\n real,parameter :: pi = 3.1415926535897932\r\n real,parameter :: infinity = huge(0.)\r\n \r\ncontains\r\n\r\n\r\nfunction isinf(x) result(is)\r\n\r\n implicit none\r\n\r\n real,intent(in) :: x\r\n\r\n logical :: is\r\n\r\n ! Check for infinity\r\n if (x >= infinity) then\r\n is = .true.\r\n else\r\n is = .false.\r\n end if\r\n\r\nend function isinf\r\n\r\n\r\nsubroutine math_plane_normal(p1,p2,p3,ans)\r\n implicit none\r\n real,dimension(3) :: p1,p2,p3,a,b,ans\r\n\r\n a = p2 - p1\r\n b = p3 - p1\r\n ans = cross(a,b)\r\nend subroutine math_plane_normal\r\n\r\n\r\nreal function math_max(dim,vec)\r\n implicit none\r\n integer :: dim,i\r\n real :: vec(dim)\r\n math_max = vec(1)\r\n do i=1,dim\r\n if(vec(i) > math_max) math_max = vec(i)\r\n end do\r\nend function math_max\r\n\r\n\r\nreal function math_length(dim,p1,p2)\r\n implicit none\r\n integer :: dim,i\r\n real,dimension(dim) :: p1,p2\r\n math_length = 0.0\r\n do i=1,dim\r\n math_length = math_length + (p2(i)-p1(i))**2\r\n end do\r\n math_length = sqrt(math_length)\r\nend function math_length\r\n\r\n\r\nsubroutine math_reflect_point(A,B,C,D,P,ans)\r\n implicit none\r\n real :: A,B,C,D,P(3),ans(3),mult\r\n mult = 2.0*(A*P(1) + B*P(2) + C*P(3) + D)/(A**2 + B**2 + C**2)\r\n ans(1) = P(1) - mult*A\r\n ans(2) = P(2) - mult*B\r\n ans(3) = P(3) - mult*C\r\nend subroutine math_reflect_point\r\n\r\n\r\nreal function math_mag(n,vec)\r\n implicit none\r\n integer :: n\r\n real :: vec(n)\r\n math_mag = sqrt(dot_product(vec,vec))\r\nend function math_mag\r\n\r\n\r\nfunction dist(a, b) result(c)\r\n ! Calculates the cartesian distance between 2 points\r\n\r\n implicit none\r\n\r\n real,dimension(3),intent(in) :: a, b\r\n real :: c\r\n\r\n c = sqrt(sum((a-b)**2))\r\n\r\nend function dist\r\n\r\n\r\nfunction cross(a, b) result(c)\r\n ! Calculates the cross-product of two 3-element vectors\r\n\r\n implicit none\r\n\r\n real :: a(3), b(3), c(3)\r\n\r\n c(1) = a(2)*b(3) - a(3)*b(2)\r\n c(2) = a(3)*b(1) - a(1)*b(3)\r\n c(3) = a(1)*b(2) - a(2)*b(1)\r\n\r\nend function cross\r\n\r\n\r\nfunction inner(a, b) result(c)\r\n ! Calculates the 3D Euclidean inner product\r\n\r\n implicit none\r\n real, dimension(3) :: a, b\r\n real :: c\r\n\r\n c = a(1)*b(1)+a(2)*b(2)+a(3)*b(3)\r\n\r\nend function inner\r\n\r\n\r\nfunction inner2(a, b) result(c)\r\n ! Calculates the 2D Euclidean inner product\r\n\r\n implicit none\r\n real, dimension(2) :: a, b\r\n real :: c\r\n\r\n c = a(1)*b(1)+a(2)*b(2)\r\n\r\nend function inner2\r\n\r\n\r\nfunction outer(a, b) result(c)\r\n ! Calculates the outer product of two vectors\r\n\r\n implicit none\r\n\r\n real,dimension(3) :: a, b\r\n real,dimension(3,3) :: c\r\n\r\n integer :: i\r\n\r\n c = 0.\r\n\r\n do i=1,3\r\n c(i,:) = a(i)*b(:)\r\n end do\r\n\r\nend function\r\n\r\nfunction norm(a) result(c)\r\n ! Calculates the norm of the vector\r\n\r\n implicit none\r\n real, dimension(3) :: a\r\n real :: c\r\n\r\n c = sqrt(inner(a, a))\r\n\r\nend function norm\r\n\r\n\r\nfunction det3(a) result(c)\r\n ! Calculates the determinant of a 3x3 matrix\r\n\r\n implicit none\r\n\r\n real,dimension(3,3) :: a\r\n real :: c\r\n\r\n c = a(1,1)*(a(2,2)*a(3,3)-a(2,3)*a(3,2))\r\n c = c - a(1,2)*(a(2,1)*a(3,3)-a(2,3)*a(3,1))\r\n c = c + a(1,3)*(a(2,1)*a(3,2)-a(3,1)*a(2,2))\r\n\r\nend function det3\r\n\r\n\r\nsubroutine math_rot_x(vec,th)\r\n implicit none\r\n real :: vec(3),th,rm(3,3),ans(3)\r\n\r\n rm(1,1) = 1.0;\r\n rm(1,2) = 0.0;\r\n rm(1,3) = 0.0;\r\n rm(2,1) = 0.0;\r\n rm(2,2) = cos(th);\r\n rm(2,3) = -sin(th);\r\n rm(3,1) = 0.0;\r\n rm(3,2) = sin(th);\r\n rm(3,3) = cos(th);\r\n ans = matmul(rm,vec)\r\n vec = ans\r\nend subroutine math_rot_x\r\n\r\n\r\nsubroutine math_rot_y(vec,th)\r\n implicit none\r\n real :: vec(3),th,rm(3,3),ans(3)\r\n\r\n rm(1,1) = cos(th);\r\n rm(1,2) = 0.0;\r\n rm(1,3) = sin(th);\r\n rm(2,1) = 0.0;\r\n rm(2,2) = 1.0;\r\n rm(2,3) = 0.0;\r\n rm(3,1) = -sin(th);\r\n rm(3,2) = 0.0;\r\n rm(3,3) = cos(th);\r\n ans = matmul(rm,vec)\r\n vec = ans\r\nend subroutine math_rot_y\r\n\r\n\r\nsubroutine math_rot_z(vec,th)\r\n implicit none\r\n real :: vec(3),th,rm(3,3),ans(3)\r\n\r\n rm(1,1) = cos(th);\r\n rm(1,2) = -sin(th);\r\n rm(1,3) = 0.0;\r\n rm(2,1) = sin(th);\r\n rm(2,2) = cos(th);\r\n rm(2,3) = 0.0;\r\n rm(3,1) = 0.0;\r\n rm(3,2) = 0.0;\r\n rm(3,3) = 1.0;\r\n ans = matmul(rm,vec)\r\n vec = ans\r\nend subroutine math_rot_z\r\n\r\n\r\nsubroutine matinv(n, a, ai)\r\n ! This sobroutine inverts a matrix \"a\" and returns the inverse in \"ai\"\r\n ! n - Input by user, an integer specifying the size of the matrix to be inverted.\r\n ! a - Input by user, an n by n real array containing the matrix to be inverted.\r\n ! ai - Returned by subroutine, an n by n real array containing the inverted matrix.\r\n ! d - Work array, an n by 2n real array used by the subroutine.\r\n ! io - Work array, a 1-dimensional integer array of length n used by the subroutine.\r\n ! THIS FUNCTION SHOULD NEVER BE callED! NEVER INVERT A MARTIX EXPLICITLY!\r\n ! Unless you know what you're doing. Odds are you may not, so be careful.\r\n\r\n implicit none\r\n\r\n integer :: n,i,j,k,m,itmp\r\n real :: a(n,n),ai(n,n),tmp,r\r\n real,allocatable,dimension(:,:) :: d\r\n integer,allocatable,dimension(:) :: io\r\n\r\n allocate(d(n,2*n))\r\n allocate(io(n))\r\n\r\n d(:,:) = 0.0\r\n io(:) = 0\r\n\r\n! Fill in the \"io\" and \"d\" matrix.\r\n! ********************************\r\n do i=1,n\r\n io(i)=i\r\n end do\r\n do i=1,n\r\n do j=1,n\r\n d(i,j)=a(i,j)\r\n if(i.eq.j)then\r\n d(i,n+j)=1.\r\n else\r\n d(i,n+j)=0.\r\n endif\r\n end do\r\n end do\r\n\r\n! Scaling\r\n! *******\r\n do i=1,n\r\n m=1\r\n do k=2,n\r\n if(abs(d(i,k)).gt.abs(d(i,m))) m=k\r\n end do\r\n tmp=d(i,m)\r\n do k=1,2*n\r\n d(i,k)=d(i,k)/tmp\r\n end do\r\n end do\r\n\r\n! Lower Elimination\r\n! *****************\r\n do i=1,n-1\r\n! Pivoting\r\n! ********\r\n m=i\r\n do j=i+1,n\r\n if(abs(d(io(j),i)).gt.abs(d(io(m),i))) m=j\r\n end do\r\n itmp=io(m)\r\n io(m)=io(i)\r\n io(i)=itmp\r\n! Scale the Pivot element to unity\r\n! ********************************\r\n r=d(io(i),i)\r\n do k=1,2*n\r\n d(io(i),k)=d(io(i),k)/r\r\n end do\r\n! ********************************\r\n do j=i+1,n\r\n r=d(io(j),i)\r\n do k=1,2*n\r\n d(io(j),k)=d(io(j),k)-r*d(io(i),k)\r\n end do\r\n end do\r\n end do\r\n\r\n! Upper Elimination\r\n! *****************\r\n r=d(io(n),n)\r\n do k=1,2*n\r\n d(io(n),k)=d(io(n),k)/r\r\n end do\r\n do i=n-1,1,-1\r\n do j=i+1,n\r\n r=d(io(i),j)\r\n do k=1,2*n\r\n d(io(i),k)=d(io(i),k)-r*d(io(j),k)\r\n end do\r\n end do\r\n end do\r\n\r\n! Fill Out \"ai\" matrix\r\n do i=1,n\r\n do j=1,n\r\n ai(i,j)=d(io(i),n+j)\r\n end do\r\n end do\r\n\r\n ! Cleanup\r\n deallocate(d)\r\n deallocate(io)\r\n\r\nend subroutine matinv\r\n\r\n\r\nfunction matmul_lu(n, A, x) result(b)\r\n ! Gives the matrix product [L][U]x = b where A = [L\\U] (Doolittle LU decomposition)\r\n ! NOT TESTED\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: n\r\n real,dimension(n,n),intent(in) :: A\r\n real,dimension(n),intent(in) :: x\r\n\r\n real,dimension(n) :: b, d\r\n integer :: i, j\r\n\r\n d = 0.\r\n\r\n ! [U]x = d\r\n do i=1,n\r\n do j=i,n\r\n d(i) = d(i) + A(i,j)*x(j)\r\n end do\r\n end do\r\n\r\n ! [L]x = b\r\n do i=1,n\r\n do j=1,i-1\r\n b(i) = b(i) + A(i,j)*d(j)\r\n end do\r\n b(i) = b(i) + d(i) ! L(i,i) = 1.\r\n end do\r\n\r\nend function matmul_lu\r\n\r\n\r\nsubroutine lu_solve(n, A, b, x)\r\n ! Solves a general [A]x=b on an nxn matrix\r\n ! This replaces A (in place) with its LU decomposition (permuted row-wise)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: n\r\n real,dimension(n),intent(in) :: b\r\n real,dimension(:),allocatable,intent(out) :: x\r\n real,dimension(n,n),intent(inout) :: A\r\n\r\n integer,allocatable,dimension(:) :: indx\r\n integer :: D, info\r\n\r\n allocate(indx(n))\r\n\r\n ! Compute decomposition\r\n call lu_decomp(A, n, indx, D, info)\r\n\r\n ! if the matrix is nonsingular, then backsolve to find X\r\n if (info == 1) then\r\n write(*,*) 'Subroutine lu_solve() failed. The given matrix is singular (i.e. no solution). Quitting...'\r\n stop\r\n else\r\n call lu_back_sub(A, n, indx, b, x)\r\n end if\r\n\r\n ! Cleanup\r\n deallocate(indx)\r\n\r\nend subroutine lu_solve\r\n\r\n\r\n!*******************************************************\r\n!* LU decomposition routines used by test_lu.f90 *\r\n!* *\r\n!* F90 version by J-P Moreau, Paris *\r\n!* improved for F95 by Cory Goates, Logan, UT, USA *\r\n!* --------------------------------------------------- *\r\n!* Reference: *\r\n!* *\r\n!* \"Numerical Recipes By W.H. Press, B. P. Flannery, *\r\n!* S.A. Teukolsky and W.T. Vetterling, Cambridge *\r\n!* University Press, 1986\" [BIBLI 08]. *\r\n!* *\r\n!*******************************************************\r\n\r\n\r\nsubroutine lu_decomp(A, N, indx, D, code)\r\n ! Given an N x N matrix A, this routine replaces it by the LU\r\n ! decomposition of a rowwise permutation of itself. A and N \r\n ! are input. indx is an output vector which records the row \r\n ! permutation effected by the partial pivoting; D is output \r\n ! as -1 or 1, depending on whether the number of row inter- \r\n ! changes was even or odd, respectively. This routine is used\r\n ! in combination with LUBKSB to solve linear equations or to \r\n ! invert a matrix. Return code is 1 if matrix is singular. \r\n\r\n implicit none\r\n\r\n\r\n real,dimension(N,N),intent(inout) :: A\r\n integer,intent(in) :: N\r\n integer,dimension(N),intent(out) :: indx\r\n integer,intent(out) :: code, D\r\n\r\n real,dimension(N) :: VV\r\n real,parameter :: tiny=1.5e-20\r\n integer :: i, j, k, imax\r\n real :: amax, dum, sum\r\n\r\n ! Initialize\r\n D = 1\r\n code = 0\r\n imax = 0\r\n\r\n ! Loop over rows to get implicit scaling information\r\n do i=1,N\r\n\r\n ! Get largest element in this row\r\n amax=0.0\r\n do j=1,N\r\n if (abs(A(i,j)) > amax) then\r\n amax = abs(A(i,j))\r\n end if\r\n end do\r\n\r\n ! Check the largest element in this row is nonzero\r\n if (amax <= tiny) then\r\n code = 1 ! Singular matrix\r\n return\r\n end if\r\n\r\n ! Store implicit scaling\r\n vv(i) = 1.0 / amax\r\n\r\n end do\r\n\r\n ! Loop over columns of Crout's method\r\n do j=1,N\r\n do i=1,J-1\r\n sum = A(i,j)\r\n do k=1,i-1\r\n sum = sum - A(i,k)*A(k,j)\r\n end do\r\n A(i,j) = sum\r\n end do\r\n\r\n ! Initialize search for largest pivot element\r\n amax = 0.0\r\n do i=j,N\r\n\r\n sum = A(i,j)\r\n do k=1,j-1\r\n sum = sum - A(i,k)*A(k,j)\r\n end do\r\n A(i,j) = sum\r\n\r\n ! Determine figure of merit for the pivot\r\n dum = vv(i)*abs(sum)\r\n if (dum >= amax) then\r\n imax = i\r\n amax = dum\r\n end if\r\n\r\n end do\r\n\r\n ! Figure out if we need to interchange rows\r\n if (j /= imax) then\r\n\r\n ! Perform interchange\r\n do k=1,N\r\n dum = A(imax,k)\r\n A(imax,k) = A(j,k)\r\n A(j,k) = dum\r\n end do\r\n\r\n ! Update the sign of D since a row interchange has occurred\r\n D = -D\r\n\r\n ! Interchange the implicit scaling factor\r\n vv(imax) = vv(j)\r\n\r\n end if\r\n\r\n ! Store pivoting\r\n indx(j) = imax\r\n\r\n ! Replace zero pivot element with small parameter\r\n if (abs(A(j,j)) < tiny) then\r\n A(j,j) = tiny\r\n end if\r\n\r\n ! Divide by pivot element\r\n if (j /= N) then\r\n dum = 1.0 / A(j,j)\r\n do i=j+1,N\r\n A(i,j) = A(i,j)*dum\r\n end do\r\n end if\r\n\r\n end do\r\n\r\nend subroutine lu_decomp\r\n\r\n\r\nsubroutine lu_back_sub(A, N, indx, b, x)\r\n ! Solves the set of N linear equations Ax = b. Here A is \r\n ! input, not as the matrix A but rather as its LU decomposition, \r\n ! determined by the routine LUDCMP. indx is input as the permuta-\r\n ! tion vector returned by LUDCMP. b is input as the right-hand \r\n ! side vector b. The solution vector is x. A, N, b and\r\n ! indx are not modified by this routine and can be used for suc- \r\n ! cessive calls with different right-hand sides. This routine is \r\n ! also efficient for plain matrix inversion. \r\n\r\n implicit none\r\n\r\n integer,intent(in) :: N\r\n real,dimension(N,N),intent(in) :: A\r\n real,dimension(N),intent(in) :: b\r\n integer,dimension(N),intent(in) :: indx\r\n real,dimension(:),allocatable,intent(out) :: x\r\n\r\n real :: sum\r\n integer :: ii,i,j,ll\r\n\r\n ! Initialize solution\r\n allocate(x, source=b)\r\n\r\n ! Set tracker to ignore leading zeros in b\r\n ii = 0\r\n\r\n ! Forward substitution\r\n do i=1,N\r\n\r\n ! Untangle pivoting\r\n ll = indx(i)\r\n sum = x(ll)\r\n x(ll) = x(i)\r\n\r\n ! If a nonzero element of b has already been encountered\r\n if (ii /= 0) then\r\n do J=ii,i-1\r\n sum = sum - A(i,J)*x(J)\r\n end do\r\n\r\n ! Check for first nonzero element of b\r\n else if(sum /= 0.0) then\r\n ii = i\r\n end if\r\n\r\n x(i) = sum\r\n\r\n end do\r\n\r\n ! Back substitution\r\n do i=N,1,-1\r\n sum = x(i)\r\n do j=i+1,N\r\n sum = sum - A(i,j)*x(j)\r\n end do\r\n x(i) = sum / A(i,i)\r\n end do\r\n\r\nend subroutine lu_back_sub\r\n\r\n\r\nsubroutine math_snyder_ludcmp(a,n)\r\n ! Computes the LU decomposition for a diagonally dominant matrix (no pivoting is done). \r\n ! Inputs: n = number of equations/unknowns \r\n ! a = nxn coefficient matrix \r\n ! Outputs: a = nxn matrix containing the LU matrices \r\n ! \r\n ! Deryl Snyder, 10-16-98 \r\n implicit none\r\n integer :: n,i,j,k\r\n real a(n,n),z\r\n\r\n do k=1,n-1\r\n do i=k+1,n\r\n z=a(i,k)/a(k,k) !compute gauss factor\r\n a(i,k)=z !store gauss factor in matrix\r\n do j=k+1,n\r\n a(i,j)=a(i,j)-z*a(k,j) !apply row operation\r\n end do\r\n end do\r\n end do\r\nend subroutine math_snyder_ludcmp\r\n\r\n\r\nsubroutine math_snyder_lusolv(a,b,x,n)\r\n ! Solves for the unknowns (x) given the LU matrix and the right hand side. C\r\n ! Inputs: n = number of equations/unknowns \r\n ! a = nxn matrix containing the L and U values \r\n ! b = n vector containing right hand side values \r\n ! Outputs: x = n vector containing solution \r\n ! \r\n ! Deryl Snyder, 10-16-98 \r\n\r\n implicit none\r\n\r\n integer :: n,i,j,k\r\n real a(n,n),b(n),x(n)\r\n\r\n do i=1,n\r\n x(i)=b(i)\r\n end do\r\n\r\n ! Forward substitution\r\n do k=1,n-1\r\n do i=k+1,n\r\n x(i)=x(i)-a(i,k)*x(k)\r\n enddo\r\n enddo\r\n\r\n ! Back substitution\r\n do i=n,1,-1\r\n do j=i+1,n\r\n x(i)=x(i)-a(i,j)*x(j)\r\n end do\r\n x(i)=x(i)/a(i,i)\r\n end do\r\n\r\nend subroutine math_snyder_lusolv\r\n\r\n\r\nsubroutine quadratic_fit(pts, a, b, c)\r\n ! Fits a parabola through three specified \r\n ! points and returns the coefficients a, b, c defining this parabola \r\n ! according to the equation y = a * x**2 + b * x + c \r\n ! pts = list of three (x, y) points \r\n ! Outputs: a, b, c = quadratic coefficients \r\n\r\n implicit none\r\n\r\n real, dimension(3, 2), intent(in) :: pts\r\n real, intent(out) :: a, b, c\r\n\r\n integer :: i\r\n real, dimension(3, 3) :: m, m_inv\r\n real, dimension(3) :: v, coeff\r\n\r\n do i = 1, 3\r\n m(i, 1) = pts(i, 1)**2\r\n m(i, 2) = pts(i, 1)\r\n m(i, 3) = 1.0\r\n end do\r\n\r\n call matinv(3, m, m_inv)\r\n\r\n v(:) = pts(:, 2)\r\n coeff = matmul(m_inv, v)\r\n\r\n a = coeff(1)\r\n b = coeff(2)\r\n c = coeff(3)\r\n\r\nend subroutine quadratic_fit\r\n\r\nend module math_mod", "meta": {"hexsha": "3c97565c0110810ab0a06aad8756439aff7b344a", "size": 16176, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "common/math.f95", "max_stars_repo_name": "usuaero/MFTran", "max_stars_repo_head_hexsha": "d0b2dba72bce2930d24aafbbe1cbe4adc49d487f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "common/math.f95", "max_issues_repo_name": "usuaero/MFTran", "max_issues_repo_head_hexsha": "d0b2dba72bce2930d24aafbbe1cbe4adc49d487f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "common/math.f95", "max_forks_repo_name": "usuaero/MFTran", "max_forks_repo_head_hexsha": "d0b2dba72bce2930d24aafbbe1cbe4adc49d487f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.4095513748, "max_line_length": 114, "alphanum_fraction": 0.49993818, "num_tokens": 4991, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620596782468, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.7801592046865131}} {"text": "program main\n\n!*****************************************************************************80\n!\n!! MAIN is the main program for HEATED_PLATE_OPENMP.\n!\n! Discussion:\n!\n! This code solves the steady state heat equation on a rectangular region.\n!\n! The sequential version of this program needs approximately\n! 18/eps iterations to complete. \n!\n!\n! The physical region, and the boundary conditions, are suggested\n! by this diagram;\n!\n! W = 0\n! +------------------+\n! | |\n! W = 100 | | W = 100\n! | |\n! +------------------+\n! W = 100\n!\n! The region is covered with a grid of M by N nodes, and an N by N\n! array W is used to record the temperature. The correspondence between\n! array indices and locations in the region is suggested by giving the\n! indices of the four corners:\n!\n! I = 0\n! [0][0]-------------[0][N-1]\n! | |\n! J = 0 | | J = N-1\n! | |\n! [M-1][0]-----------[M-1][N-1]\n! I = M-1\n!\n! The steady state solution to the discrete heat equation satisfies the\n! following condition at an interior grid point:\n!\n! W[Central] = (1/4) * ( W[North] + W[South] + W[East] + W[West] )\n!\n! where \"Central\" is the index of the grid point, \"North\" is the index\n! of its immediate neighbor to the \"north\", and so on.\n! \n! Given an approximate solution of the steady state heat equation, a\n! \"better\" solution is given by replacing each interior point by the\n! average of its 4 neighbors - in other words, by using the condition\n! as an ASSIGNMENT statement:\n!\n! W[Central] <= (1/4) * ( W[North] + W[South] + W[East] + W[West] )\n!\n! If this process is repeated often enough, the difference between \n! successive estimates of the solution will go to zero.\n!\n! This program carries out such an iteration, using a tolerance specified by\n! the user, and writes the final estimate of the solution to a file that can\n! be used for graphic processing.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 18 October 2011\n!\n! Author:\n!\n! Original FORTRAN90 version by Michael Quinn.\n! This version by John Burkardt.\n!\n! Reference:\n!\n! Michael Quinn,\n! Parallel Programming in C with MPI and OpenMP,\n! McGraw-Hill, 2004,\n! ISBN13: 978-0071232654,\n! LC: QA76.73.C15.Q55.\n!\n! Local parameters:\n!\n! Local, real ( kind = 8 ) DIFF, the norm of the change in the solution from \n! one iteration to the next.\n!\n! Local, real ( kind = 8 ) MEAN, the average of the boundary values, used \n! to initialize the values of the solution in the interior.\n!\n! Local, real ( kind = 8 ) U(M,N), the solution at the previous iteration.\n!\n! Local, real ( kind = 8 ) W(M,N), the solution computed at the latest \n! iteration.\n!\n use omp_lib\n\n implicit none\n\n integer ( kind = 4 ), parameter :: m = 500\n integer ( kind = 4 ), parameter :: n = 500\n\n real ( kind = 8 ) diff\n real ( kind = 8 ) :: eps = 0.001D+00\n integer ( kind = 4 ) i\n integer ( kind = 4 ) iterations\n integer ( kind = 4 ) iterations_print\n integer ( kind = 4 ) j\n real ( kind = 8 ) mean\n real ( kind = 8 ) u(m,n)\n real ( kind = 8 ) w(m,n)\n real ( kind = 8 ) wtime\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'HEATED_PLATE_OPENMP'\n write ( *, '(a)' ) ' FORTRAN90 version'\n write ( *, '(a)' ) &\n ' A program to solve for the steady state temperature distribution'\n write ( *, '(a)' ) ' over a rectangular plate.'\n write ( *, '(a)' ) ' '\n write ( *, '(a,i8,a,i8,a)' ) ' Spatial grid of ', m, ' by ', n, ' points.'\n write ( *, '(a,g14.6)' ) &\n ' The iteration will repeat until the change is <= ', eps\n write ( *, '(a,i8)' ) &\n ' The number of processors available = ', omp_get_num_procs ( )\n write ( *, '(a,i8)' ) &\n ' The number of threads available = ', omp_get_max_threads ( )\n!\n! Set the boundary values, which don't change.\n!\n! OpenMP Note:\n! You CANNOT set MEAN to zero inside the parallel region.\n!\n mean = 0.0D+00\n!\n!$omp parallel shared ( w ) private ( i, j ) \n\n !$omp do\n do i = 2, m - 1\n w(i,1) = 100.0D+00\n w(i,n) = 100.0D+00\n end do\n !$omp end do\n\n !$omp do\n do j = 1, n\n w(m,j) = 100.0D+00\n w(1,j) = 0.0D+00\n end do\n !$omp end do\n!\n! Average the boundary values, to come up with a reasonable\n! initial value for the interior.\n!\n !$omp do reduction ( + : mean )\n do i = 2, m - 1\n mean = mean + w(i,1) + w(i,n)\n end do\n !$omp end do\n\n !$omp do reduction ( + : mean )\n do j = 1, n\n mean = mean + w(1,j) + w(m,j)\n end do\n !$omp end do\n\n!$omp end parallel\n!\n! OpenMP note:\n! You cannot normalize MEAN inside the parallel region. It\n! only gets its correct value once you leave the parallel region.\n! So we interrupt the parallel region, set MEAN, and go back in.\n!\n mean = mean / dble ( 2 * m + 2 * n - 4 )\n write ( *, '(a)' ) ' '\n write ( *, '(a,g14.6)' ) ' MEAN = ', mean\n!\n! Initialize the interior solution to the mean value.\n!\n!$omp parallel shared ( mean, w ) private ( i, j )\n\n !$omp do\n do j = 2, n - 1\n do i = 2, m - 1\n w(i,j) = mean\n end do\n end do\n !$omp end do\n\n!$omp end parallel\n!\n! Iterate until the new solution W differs from the old solution U\n! by no more than EPS.\n!\n iterations = 0\n iterations_print = 1\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Iteration Change'\n write ( *, '(a)' ) ' '\n\n wtime = omp_get_wtime ( )\n\n diff = eps\n\n do while ( eps <= diff )\n!\n! OpenMP node: You CANNOT set DIFF to 0.0 inside the parallel region.\n!\n diff = 0.0D+00\n\n!$omp parallel shared ( u, w ) private ( i, j ) \n\n !$omp do\n do j = 1, n\n do i = 1, m\n u(i,j) = w(i,j)\n end do\n end do\n !$omp end do\n\n !$omp do\n do j = 2, n - 1\n do i = 2, m - 1\n w(i,j) = 0.25D+00 * ( u(i-1,j) + u(i+1,j) + u(i,j-1) + u(i,j+1) )\n end do\n end do\n !$omp end do\n\n !$omp do reduction ( max : diff )\n do j = 1, n\n do i = 1, m\n diff = max ( diff, abs ( u(i,j) - w(i,j) ) )\n end do\n end do\n !$omp end do\n\n!$omp end parallel\n\n iterations = iterations + 1\n\n if ( iterations == iterations_print ) then\n write ( *, '(2x,i8,2x,g14.6)' ) iterations, diff\n iterations_print = 2 * iterations_print\n end if\n\n end do\n\n wtime = omp_get_wtime ( ) - wtime\n\n write ( *, '(a)' ) ' '\n write ( *, '(2x,i8,2x,g14.6)' ) iterations, diff\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Error tolerance achieved.'\n write ( *, '(a,g14.6)' ) ' Wall clock time = ', wtime\n!\n! Terminate.\n!\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'HEATED_PLATE_OPENMP:'\n write ( *, '(a)' ) ' Normal end of execution.'\n\n stop\nend\n", "meta": {"hexsha": "84c40ec5d2f8ec6bd5823708679c4d3e7469e6e5", "size": 6893, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "share/ukernels/heatedplate.f90", "max_stars_repo_name": "vivek224/vSched", "max_stars_repo_head_hexsha": "5ecf2cdf553277571490665b42e00a0b61b2a8c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-06-11T17:16:02.000Z", "max_stars_repo_stars_event_max_datetime": "2018-10-01T18:37:28.000Z", "max_issues_repo_path": "share/ukernels/heatedplate.f90", "max_issues_repo_name": "vivek224/vSched", "max_issues_repo_head_hexsha": "5ecf2cdf553277571490665b42e00a0b61b2a8c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-08-09T00:12:11.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-09T00:12:51.000Z", "max_forks_repo_path": "share/ukernels/heatedplate.f90", "max_forks_repo_name": "vlkale/lw-sched", "max_forks_repo_head_hexsha": "5ecf2cdf553277571490665b42e00a0b61b2a8c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.1098484848, "max_line_length": 80, "alphanum_fraction": 0.5467865951, "num_tokens": 2183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.779983423836197}} {"text": "! Objetivo: Usar pares ordenados a partir de um gerador aleatorio do\n! tipo rapido e \"sujo\" para obter coordenadas de pontos em\n!\t \tum espaço bidimensional.\n\nPROGRAM aleatorio_sujo_xy\n\tIMPLICIT none\n\tINTEGER, PARAMETER :: im = 6075, ia = 106, ic = 1283\n\tREAL, PARAMETER :: im_real = REAL(im)\n\tREAL :: ran_x, ran_y\n\tINTEGER, PARAMETER :: dados_aleatorio_xy = 7\n\tINTEGER :: num_repeticoes, jran = 1\n! Abrir arquivo.dat de saida de dados\n\tOPEN(dados_aleatorio_xy,FILE=\"dados_aleatorio_xy.dat\")\n! Essas constantes dao um periodo de comprimento máximo im. Por isso im eh a\n! quantidade de numeros aleatorios gerados diferentes. O gerador produz 2*im numeros\n! aleatorios pois im eh impar. O primeiro numero a repetir sera na coordenada y, pois\n! im eh impar e estamos distribuindo aos pares. O primeiro numero a se repetir na\n! coordenada x sera apos 2im numeros gerados.\n\tDO num_repeticoes = 1, im\n\t\tjran = MOD(jran*ia+ic,im)\n\t\tran_x = REAL(jran)/im_real\n\n\t\tjran = MOD(jran*ia+ic,im)\n\t\tran_y = REAL(jran)/im_real\n! Escrever as coordenadas no arquivo de dados\n\t\tWRITE(dados_aleatorio_xy,*) ran_x,ran_y\n\tEND DO\n! Fechar arquivo.dat de saida de dados\n\tCLOSE(dados_aleatorio_xy)\nEND PROGRAM aleatorio_sujo_xy\n", "meta": {"hexsha": "96e67deeb2c460be25be4360bf0eff24c7c14e15", "size": 1214, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "aleatorio_sujo_xy.f90", "max_stars_repo_name": "GuilhermeMonteiroPeixoto/Computational-Physics-using-Fortran", "max_stars_repo_head_hexsha": "3d2b3dd87d99b451aed5fe1e9e99813390396485", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aleatorio_sujo_xy.f90", "max_issues_repo_name": "GuilhermeMonteiroPeixoto/Computational-Physics-using-Fortran", "max_issues_repo_head_hexsha": "3d2b3dd87d99b451aed5fe1e9e99813390396485", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aleatorio_sujo_xy.f90", "max_forks_repo_name": "GuilhermeMonteiroPeixoto/Computational-Physics-using-Fortran", "max_forks_repo_head_hexsha": "3d2b3dd87d99b451aed5fe1e9e99813390396485", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.1612903226, "max_line_length": 85, "alphanum_fraction": 0.7512355848, "num_tokens": 392, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.7798660832875789}} {"text": "program main\n use RandomClass\n use MathClass\n use IOClass\n implicit none\n\n integer(int32),parameter :: sample = 2**11\n real(real64),parameter :: dt = 0.0010d0\n type(Random_) :: random\n type(IO_) :: f,z\n type(Math_) :: Math\n integer(int32) :: i, n, nn,count\n real(real64) :: g_n, g_nn, period, period_list(sample)\n complex(kind(0d0) ),allocatable :: wave(:)\n real(real64) :: spectre(sample),t\n real(real64),allocatable :: histogram(:,:)\n\n ! get random wave & zero crossing\n call f%open(\"random_wave.csv\")\n \n g_n = -1.0d0\n g_nn= 0.0d0\n n = 0\n nn = 0\n period = 0.0d0 \n count=0\n period_list(:) = 0.0d0\n wave = period_list\n do i=1,sample\n ! generate wave\n\n ! Gaussian process\n !g_nn = random%Gauss(mu=0.0d0, sigma=1.0d0) \n \n ! wave\n !g_nn = sin(dble(i)*2*Math%PI)+10.0d0*sin(dble(i)/2.0d0*Math%PI)\n t = dble(i)*dt\n \n ! wave\n g_nn = 1.0d0*sin( 2.0d0*Math%PI*10.0d0*t )&\n + 0.5d0*sin( 2.0d0*Math%PI*20.0d0*t )&\n + 0.8d0*sin( 2.0d0*Math%PI*40.0d0*t )\n \n wave(i) = g_nn\n !g_nn = random%ChiSquared(k=1.0d0) \n \n if( g_n*g_nn < 0.0d0 )then\n count=count+1\n nn = i\n period = dble(nn) - dble(n)\n period_list(count) = period\n n = nn\n g_n = g_nn\n endif\n \n call f%write( trim(str(dble(i))) //\", \"//str(g_nn) )\n \n enddo\n call f%close()\n\n ! get histogram\n histogram = random%histogram(list=period_list,division=20)\n call z%open(\"zero_cross.csv\")\n \n do i=1,size(histogram,1)\n write(z%fh,*) histogram(i,1),histogram(i,2)\n enddo\n call z%close()\n\n call z%open(\"wave.txt\")\n do i=1,sample\n call z%write(str(dble(i)*dt )//\" \"//str(dble(wave(i) )) ) \n enddo\n call z%close()\n\n spectre = FFT(wave)\n call z%open(\"spectre.txt\")\n do i=1,sample\n call z%write( str( dble(i)*2.0d0/dble(sample) )//\" \"//str(dble( abs(spectre(i)) )) ) \n enddo\n call z%close()\n\n \nend program main", "meta": {"hexsha": "74c0be8cd5688ab63ea396521b4826ad14c2f8eb", "size": 2137, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/playon_std/sample_wave_fft.f90", "max_stars_repo_name": "kazulagi/plantfem_min", "max_stars_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2020-06-21T08:21:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:28:30.000Z", "max_issues_repo_path": "Tutorial/std/sample_wave_fft.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-08T05:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:39:29.000Z", "max_forks_repo_path": "Tutorial/std/sample_wave_fft.f90", "max_forks_repo_name": "kazulagi/plantFEM_binary", "max_forks_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-10-20T18:28:59.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-15T08:35:25.000Z", "avg_line_length": 25.4404761905, "max_line_length": 96, "alphanum_fraction": 0.5222274216, "num_tokens": 736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308091776495, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.7798660683575727}} {"text": "program Hailstone\n implicit none\n\n integer :: i, maxn\n integer :: maxseqlen = 0, seqlen\n integer, allocatable :: seq(:)\n\n call hs(27, seqlen)\n allocate(seq(seqlen))\n call hs(27, seqlen, seq)\n write(*,\"(a,i0,a)\") \"Hailstone sequence for 27 has \", seqlen, \" elements\"\n write(*,\"(a,4(i0,a),3(i0,a),i0)\") \"Sequence = \", seq(1), \", \", seq(2), \", \", seq(3), \", \", seq(4), \" ...., \", &\n seq(seqlen-3), \", \", seq(seqlen-2), \", \", seq(seqlen-1), \", \", seq(seqlen)\n\n do i = 1, 99999\n call hs(i, seqlen)\n if (seqlen > maxseqlen) then\n maxseqlen = seqlen\n maxn = i\n end if\n end do\n write(*,*)\n write(*,\"(a,i0,a,i0,a)\") \"Longest sequence under 100000 is for \", maxn, \" with \", maxseqlen, \" elements\"\n\n deallocate(seq)\n\ncontains\n\nsubroutine hs(number, length, seqArray)\n integer, intent(in) :: number\n integer, intent(out) :: length\n integer, optional, intent(inout) :: seqArray(:)\n integer :: n\n\n n = number\n length = 1\n if(present(seqArray)) seqArray(1) = n\n do while(n /= 1)\n if(mod(n,2) == 0) then\n n = n / 2\n else\n n = n * 3 + 1\n end if\n length = length + 1\n if(present(seqArray)) seqArray(length) = n\n end do\nend subroutine\n\nend program\n", "meta": {"hexsha": "4112821c455b3480446b15c45b0f9ef062d58e97", "size": 1234, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Hailstone-sequence/Fortran/hailstone-sequence.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Hailstone-sequence/Fortran/hailstone-sequence.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Hailstone-sequence/Fortran/hailstone-sequence.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 24.68, "max_line_length": 114, "alphanum_fraction": 0.5623987034, "num_tokens": 443, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066391, "lm_q2_score": 0.8774767762675404, "lm_q1q2_score": 0.7798651906514084}} {"text": "C++*************************************************\nC Program POLAR_DIST to compute distance\nC of two points given by their polar coordinates (angle and separation)\nC from the Cartesian coordinates of two points\nC--*************************************************\n PROGRAM POLAR_DIST \n REAL*4 R1,A1,R2,A2,DIST,A,B,PI\n PI=ACOS(-1.)\n\n WRITE(6,20)\n20 FORMAT('Program POLAR_DIST to compute the distance',\n 1 ' of two points given by their polar coordinates')\n WRITE(6,21)\n21 FORMAT(' Enter the rho,theta(deg) coordinates of the first point (origin):')\n READ(5,*) R1,A1\n A1=A1*PI/180.\n WRITE(6,22)\n22 FORMAT(' Enter the rho,theta(deg) coordinates of the second point:')\n READ(5,*) R2,A2\n A2=A2*PI/180.\n A=R1*COS(A1)-R2*COS(A2)\n B=R1*SIN(A1)-R2*SIN(A2)\n DIST=SQRT(A*A+B*B)\n\n WRITE(6,30) DIST \n30 FORMAT(' Distance: ',G12.5)\n\n STOP\n END\n\n", "meta": {"hexsha": "16cdc44332a16ebaa5a63885cb36887698ac8f7c", "size": 977, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "source/maths/polar_dist.for", "max_stars_repo_name": "jlprieur/shell_galaxies", "max_stars_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/maths/polar_dist.for", "max_issues_repo_name": "jlprieur/shell_galaxies", "max_issues_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/maths/polar_dist.for", "max_forks_repo_name": "jlprieur/shell_galaxies", "max_forks_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.5161290323, "max_line_length": 84, "alphanum_fraction": 0.5301944729, "num_tokens": 269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075755433746, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7797678934455834}} {"text": "! Example illustrating how subtracting the minimum in a log-sum-exp\n! routine can result in overflow, while subtracting the maximum\n!\n! Jason R. Blevins \n! Columbus, February 5, 2013\nprogram log_sum_exp_test\n implicit none\n\n real, dimension(3) :: v = (/ -100.0, -200.0, -300.0 /)\n real :: max, min\n\n max = maxval(v)\n min = minval(v)\n\n print *, 'No centering:'\n print *, 'v = ', v\n print *, 'exp(v) = ', exp(v)\n print *, 'sum(exp(v)) = ', sum(exp(v))\n print *, 'log(sum(exp(v))) = ', log(sum(exp(v)))\n print *, ''\n print *, 'Subtracting the maximum:'\n print *, 'v - max = ', v - max\n print *, 'exp(v - max) = ', exp(v - max)\n print *, 'sum(exp(v - max)) = ', sum(exp(v - max))\n print *, 'log(sum(exp(v - max))) + max = ', log(sum(exp(v - max))) + max\n print *, ''\n print *, 'Subtracting the minimum:'\n print *, 'v - min = ', v - min\n print *, 'exp(v - min) = ', exp(v - min)\n print *, 'sum(exp(v - min)) = ', sum(exp(v - min))\n print *, 'log(sum(exp(v - min))) + min = ', log(sum(exp(v - min))) + min\nend program log_sum_exp_test\n", "meta": {"hexsha": "495c436d0c952b8a860bac420b29adfff7064d26", "size": 1243, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/log_sum_exp_test.f90", "max_stars_repo_name": "jrblevin/scicomp", "max_stars_repo_head_hexsha": "43c565496addc0449ab2e63d653b4aa7cba33b61", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2017-10-12T15:14:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-18T04:21:07.000Z", "max_issues_repo_path": "fortran/log_sum_exp_test.f90", "max_issues_repo_name": "jrblevin/scicomp", "max_issues_repo_head_hexsha": "43c565496addc0449ab2e63d653b4aa7cba33b61", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/log_sum_exp_test.f90", "max_forks_repo_name": "jrblevin/scicomp", "max_forks_repo_head_hexsha": "43c565496addc0449ab2e63d653b4aa7cba33b61", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-30T12:46:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-30T12:46:47.000Z", "avg_line_length": 37.6666666667, "max_line_length": 74, "alphanum_fraction": 0.4851166533, "num_tokens": 360, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362488, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7797152534085035}} {"text": "! This will be a subroutine since it does not\n! return any values.\nsubroutine fssor(U, m, n, omega, tol, maxiters, info)\n \n! Here we declare the types for the inputs.\n! This is where we use the c_double and c_int types.\n! The 'dimension' statement tells the compiler that\n! the argument is an array of the given shape.\n integer, intent(in) :: m, n, maxiters\n double precision, intent(out) :: info\n double precision, dimension(m,n), intent(inout) :: U\n double precision, intent(in) :: omega, tol\n \n! Temporary variables:\n! 'maxerr' is a temporary value.\n! It is used to determine when to stop iteration.\n! 'i', 'j', and 'k' are indices for the loops.\n! lcf and rcf will be precomputed values\n! used on the inside of the loops.\n double precision :: maxerr, temp, lcf, rcf\n integer i, j, k\n \n lcf = 1.0D0 - omega\n rcf = 0.25D0 * omega\n do k = 1, maxiters\n maxerr = 0.0D0\n do j = 2, n-1\n do i = 2, m-1\n temp = U(i,j)\n U(i,j) = lcf * U(i,j) + rcf * (U(i,j-1) + U(i,j+1) + U(i-1,j) + U(i+1,j))\n maxerr = max(abs(U(i,j) - temp), maxerr)\n enddo\n enddo\n! Break the outer loop if within\n! the desired tolerance.\n if (maxerr < tol) exit\n enddo\n! Here we have it set status to 0 if\n! the desired tolerance was attained\n! within the the given maximum\n! number of iterations.\n if (maxerr < tol) then\n info = 0\n else\n info = 1\n end if\nend subroutine fssor\n", "meta": {"hexsha": "d96ff192c727cd7d3cf1606d0af4b3c576d67e00", "size": 1538, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Python/f2py/fssor/fssor.f90", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Python/f2py/fssor/fssor.f90", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Python/f2py/fssor/fssor.f90", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 32.0416666667, "max_line_length": 89, "alphanum_fraction": 0.589076723, "num_tokens": 477, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819238, "lm_q2_score": 0.8499711832583696, "lm_q1q2_score": 0.7796808173662227}} {"text": "MODULE generic_procedure_module\nIMPLICIT NONE\n! Declare type vector\nTYPE :: vector\n REAL :: x\n REAL :: y\nCONTAINS\n GENERIC :: add => vector_plus_vector, vector_plus_scalar\n PROCEDURE, PASS :: vector_plus_scalar\n PROCEDURE, PASS :: vector_plus_vector\nEND TYPE vector\n\nCONTAINS\n TYPE (vector) FUNCTION vector_plus_vector(this, v2)\n IMPLICIT NONE\n CLASS(vector), INTENT(IN) :: this\n CLASS(vector), INTENT(IN) :: v2\n vector_plus_vector%x = this%x + v2%x\n vector_plus_vector%y = this%y + v2%y\n END FUNCTION vector_plus_vector\n\n TYPE (vector) FUNCTION vector_plus_scalar(this, scalar)\n IMPLICIT NONE\n CLASS(vector), INTENT(IN) :: this\n REAL, INTENT(IN) :: scalar\n vector_plus_scalar%x = this%x + scalar\n vector_plus_scalar%y = this%y + scalar\n END FUNCTION vector_plus_scalar\nEND MODULE generic_procedure_module\n\nPROGRAM test_generic_procedures\nUSE generic_procedure_module\nIMPLICIT NONE\nTYPE(vector) :: v1\nTYPE(vector) :: v2\nREAL :: s\n\nWRITE(*, *) 'ENTER FIRST VECTOR (X, Y):'\nREAD(*, *) v1%x, v1%y\nWRITE(*, *) 'ENTER SECOND VECTOR (X, Y):'\nREAD(*, *) v2%x, v2%y\nWRITE(*, *) 'ENTER A SCALAR:'\nREAD(*, *) s\nWRITE(*, 1000) v1%add(v2)\n1000 FORMAT ('The sum of the vectors is (',F8.2,',',F8.2,')')\nWRITE(*, 1010) v1%add(s)\n1010 FORMAT ('The sum of the vector and the scalar is (',F8.2,',',F8.2,')')\nEND PROGRAM test_generic_procedures\n", "meta": {"hexsha": "c4212e74d713394b37baa10a8e40d7671d905d69", "size": 1345, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap13/test_generic_procedures.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap13/test_generic_procedures.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap13/test_generic_procedures.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.4489795918, "max_line_length": 75, "alphanum_fraction": 0.7078066914, "num_tokens": 418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8670357615200474, "lm_q1q2_score": 0.7795703880401992}} {"text": " program linearAlgebra01\n!\n! This program fills two matrices with random numbers and forms their sum.\n! The matrices are square and their size is determined by a user-provided\n! command line argument.\n!\n!\n! Hrant P. Hratchian, 2021.\n!\n!\n USE OMP_LIB\n implicit none\n integer,parameter::iOut=6\n integer::nDim,nOMP,i,j,k\n real::tStart,tEnd,tmp\n real,dimension(:,:),allocatable::matrixA,matrixB,matrixC\n character(len=256)::commandLineArg\n logical::fail=.false.\n!\n! Format statements.\n!\n 1000 Format('My Matrix Multiplication: nDim = ',I10,' Job Time: ',F10.3,' s.')\n 8999 format(1x,'The program and completed normally.')\n 9000 format(1x,'Wrong number of command line arguments found.')\n 9999 Format(1x,'The program FAILED!')\n!\n! Begin by loading nDim and nOMP from the command line arguments. Then,\n! allocating memory for matrixA, matrixB, and matrixC and start up OpenMP.\n!\n if(COMMAND_ARGUMENT_COUNT().ne.2) then\n write(iOut,9000)\n fail = .true.\n goto 999\n endIf\n call GET_COMMAND_ARGUMENT(1,commandLineArg)\n read(commandLineArg,*) nDim\n call GET_COMMAND_ARGUMENT(2,commandLineArg)\n read(commandLineArg,*) nOMP\n Allocate(matrixA(nDim,nDim),matrixB(nDim,nDim),matrixC(nDim,nDim))\n call random_number(matrixA)\n call random_number(matrixB)\n call omp_set_num_threads(nOMP)\n!\n! Carry out matrix multiplication using explicit nested loops.\n!\n call CPU_TIME(tStart)\n!$OMP PARALLEL DO Shared(matrixA,matrixB,matrixC,nDim,tmp) Reduction(+: tmp)\n do i = 1,nDim\n do j = 1,nDim\n tmp = float(0)\n do k = 1,nDim\n tmp = tmp + matrixA(i,k)*matrixB(k,j)\n endDo\n matrixC(i,j) = tmp\n endDo\n endDo\n!$OMP END PARALLEL DO\n call CPU_TIME(tEnd)\n write(iOut,1000) nDim,tEnd-tStart\n!\n! Wrap up the program. First, check to see if we have hit a failure and\n! print an appropriate message. Then, deallocate memory for allocatable\n! arrays.\n!\n 999 if(fail) then\n write(iOut,9999)\n else\n write(iOut,8999)\n endIf\n DeAllocate(matrixA,matrixB,matrixC)\n end program linearAlgebra01\n", "meta": {"hexsha": "bfb2c15385f4d725a68c418224fb74db1a1c1dbc", "size": 2229, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "LinearAlgebraOpenMP/linearAlgebra01.f03", "max_stars_repo_name": "hphratchian/examplesFortranOpenMP", "max_stars_repo_head_hexsha": "49e493cf6f12a3b7c94f46f566b584bcfd22e7ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "LinearAlgebraOpenMP/linearAlgebra01.f03", "max_issues_repo_name": "hphratchian/examplesFortranOpenMP", "max_issues_repo_head_hexsha": "49e493cf6f12a3b7c94f46f566b584bcfd22e7ba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LinearAlgebraOpenMP/linearAlgebra01.f03", "max_forks_repo_name": "hphratchian/examplesFortranOpenMP", "max_forks_repo_head_hexsha": "49e493cf6f12a3b7c94f46f566b584bcfd22e7ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-27T22:08:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-27T22:08:33.000Z", "avg_line_length": 30.9583333333, "max_line_length": 80, "alphanum_fraction": 0.6536563481, "num_tokens": 622, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.7794524363406443}} {"text": " Program Ex0202\n\n Implicit None\n\n* Guess Number\n Integer N\n Parameter (N = 30)\n* Guess Minimum\n Double Precision xMin\n Parameter (xMin = 0.0D0)\n* Guess Maximum\n Double Precision xMax\n Parameter (xMax = 3.0D0)\n* Y Value of Guess Minimum\n Double Precision yMin\n Parameter (yMin = 1.0D0)\n* X Interval\n Double Precision H\n Parameter (H = (xMax - xMin) / Dble(N))\n* Data Storage\n Double Precision y(N), x(N), yExt(N), yDif(N), yRat(N)\n Double Precision y0, xTmp, yTmp\n* Dummy\n Integer I\n* Diff Func\n Double Precision Func\n External Func\n\n Open(11, File = '02-02.txt')\n 1000 Format(5F14.7)\n 1010 Format(5A14)\n 1020 Format(A50)\n\n* Initial Value\n Do 10 I = 1, N\n x(I) = Dble(I)/Dble(N) * xMax + \n $ (Dble(1.0D0) - Dble(I) / Dble(N)) * xMin\n yExt(I) = DExp(-x(I)*x(I)/2.0D0)\n 10 Continue\n\n*-- Euler's Method\n\n y0 = yMiN\n y(1) = y0 + H * Func(xMin,y0)\n yDif(1) = y(1) - yExt(1) \n yRat(1) = yDif(1) / yExt(1)\n\n Do 20 I = 2, N\n y(I) = y(I-1) + H * Func(x(I-1), y(I-1))\n yDif(I) = y(I) - yExt(I)\n yRat(I) = yDif(I) / yExt(I)\n 20 Continue\n\n Write(11,*)\n Write(11,1020) 'Euler Method '\n Write(11,*)\n Write(11,1010) '--------------','--------------','--------------',\n $ '--------------','--------------'\n Write(11,1010) 'x', 'Exact y', 'Calc y', 'Error Value', \n $ 'Error Ratio'\n Write(11,1010) '--------------','--------------','--------------',\n $ '--------------','--------------'\n Do 30 I = 1, N\n Write(11,1000) x(I), yExt(I), y(I), yDif(I), yRat(I)\n 30 Continue\n Write(11,1010) '--------------','--------------','--------------',\n $ '--------------','--------------'\n Write(11,*)\n\n yTmp = y(N)\n Do 40 I = 1, N\n xTmp = Dble(I)/Dble(N) * xMin + H +\n $ (Dble(1.0D0) - Dble(I) / Dble(N)) * xMax\n yTmp = yTmp - H * Func(xTmp, yTmp)\n 40 Continue\n Write(11,'(A18,F14.7)') 'Recursion Value: ', yTmp\n Write(11,'(A18,F14.7)') 'Recursion Error: ', yMin - yTmp\n Write(11,*)\n\n*-- Adams-Bashforth's Method (1th extrapolate)\n\n Do 110 I = 1, N\n x(I) = Dble(I)/Dble(N) * xMax + \n $ (Dble(1.0D0) - Dble(I) / Dble(N)) * xMin\n yExt(I) = DExp(-x(I)*x(I)/2.0D0)\n 110 Continue\n\n y0 = yMiN\n y(1) = y0 + H * Func(xMin,y0)\n yDif(1) = y(1) - yExt(1) \n yRat(1) = yDif(1) / yExt(1)\n\n Do 120 I = 2, 2\n y(I) = y(I-1) + H * Func(x(I-1), y(I-1))\n yDif(I) = y(I) - yExt(I)\n yRat(I) = yDif(I) / yExt(I)\n 120 Continue\n\n Do 130 I = 3, N\n y(I) = y(I-1) + H * (1.5D0 * Func(x(I-1), y(I-1)) - \n $ 0.5D0 * Func(x(I-2), y(I-2)))\n yDif(I) = y(I) - yExt(I)\n yRat(I) = yDif(I) / yExt(I)\n 130 Continue\n\n Write(11,*)\n Write(11,1020) '1th Adams-Bashforth Method '\n Write(11,*)\n Write(11,1010) '--------------','--------------','--------------',\n $ '--------------','--------------'\n Write(11,1010) 'x', 'Exact y', 'Calc y', 'Error Value', \n $ 'Error Ratio'\n Write(11,1010) '--------------','--------------','--------------',\n $ '--------------','--------------'\n Do 140 I = 1, N\n Write(11,1000) x(I), yExt(I), y(I), yDif(I), yRat(I)\n 140 Continue\n Write(11,1010) '--------------','--------------','--------------',\n $ '--------------','--------------'\n Write(11,*)\n\n Do 150 I = 1, N\n x(I) = Dble(I)/Dble(N) * xMin + \n $ (Dble(1.0D0) - Dble(I) / Dble(N)) * xMax\n yExt(I) = DExp(-x(I)*x(I)/2.0D0)\n 150 Continue\n \n y0 = y(N)\n y(1) = y0 - H * Func(xMax,y0)\n yDif(1) = y(1) - yExt(1) \n yRat(1) = yDif(1) / yExt(1)\n \n Do 160 I = 2, 2\n y(I) = y(I-1) - H * Func(x(I-1), y(I-1))\n yDif(I) = y(I) - yExt(I)\n yRat(I) = yDif(I) / yExt(I)\n 160 Continue\n \n Do 170 I = 3, N\n y(I) = y(I-1) - H * (1.5D0 * Func(x(I-1), y(I-1)) - \n $ 0.5D0 * Func(x(I-2), y(I-2)))\n yDif(I) = y(I) - yExt(I)\n yRat(I) = yDif(I) / yExt(I)\n 170 Continue\n \n Write(11,'(A18,F14.7)') 'Recursion Value: ', y(N)\n Write(11,'(A18,F14.7)') 'Recursion Error: ', yMin - y(N)\n Write(11,*)\n\n*-- Adams-Bashforth's Method (3th extrapolate)\n\n Do 210 I = 1, N\n x(I) = Dble(I)/Dble(N) * xMax + \n $ (Dble(1.0D0) - Dble(I) / Dble(N)) * xMin\n yExt(I) = DExp(-x(I)*x(I)/2.0D0)\n 210 Continue\n\n y0 = yMiN\n y(1) = y0 + H * Func(xMin,y0)\n yDif(1) = y(1) - yExt(1) \n yRat(1) = yDif(1) / yExt(1)\n\n Do 220 I = 2, 4\n y(I) = y(I-1) + H * Func(x(I-1), y(I-1))\n yDif(I) = y(I) - yExt(I)\n yRat(I) = yDif(I) / yExt(I)\n 220 Continue\n\n Do 230 I = 5, N\n y(I) = y(I-1) + H / 24.0D0 * ( 55.0D0 * Func(x(I-1),y(I-1)) - \n $ 59.0D0 * Func(x(I-2),y(I-2)) + 37.0D0 * Func(x(I-3),y(I-3)) - \n $ 9.0D0 * Func(x(I-4),y(I-4)) )\n yDif(I) = y(I) - yExt(I)\n yRat(I) = yDif(I) / yExt(I)\n 230 Continue\n\n Write(11,*)\n Write(11,1020) '3th Adams-Bashforth Method '\n Write(11,*)\n Write(11,1010) '--------------','--------------','--------------',\n $ '--------------','--------------'\n Write(11,1010) 'x', 'Exact y', 'Calc y', 'Error Value', \n $ 'Error Ratio'\n Write(11,1010) '--------------','--------------','--------------',\n $ '--------------','--------------'\n Do 240 I = 1, N\n Write(11,1000) x(I), yExt(I), y(I), yDif(I), yRat(I)\n 240 Continue\n Write(11,1010) '--------------','--------------','--------------',\n $ '--------------','--------------'\n Write(11,*)\n\n Do 250 I = 1, N\n x(I) = Dble(I)/Dble(N) * xMin + \n $ (Dble(1.0D0) - Dble(I) / Dble(N)) * xMax\n yExt(I) = DExp(-x(I)*x(I)/2.0D0)\n 250 Continue\n \n y0 = y(N)\n y(1) = y0 - H * Func(xMax,y0)\n yDif(1) = y(1) - yExt(1) \n yRat(1) = yDif(1) / yExt(1)\n \n Do 260 I = 2, 4\n y(I) = y(I-1) - H * Func(x(I-1), y(I-1))\n yDif(I) = y(I) - yExt(I)\n yRat(I) = yDif(I) / yExt(I)\n 260 Continue\n \n Do 270 I = 5, N\n y(I) = y(I-1) - H / 24.0D0 * ( 55.0D0 * Func(x(I-1),y(I-1)) - \n $ 59.0D0 * Func(x(I-2),y(I-2)) + 37.0D0 * Func(x(I-3),y(I-3)) - \n $ 9.0D0 * Func(x(I-4),y(I-4)) )\n yDif(I) = y(I) - yExt(I)\n yRat(I) = yDif(I) / yExt(I)\n 270 Continue\n \n Write(11,'(A18,F14.7)') 'Recursion Value: ', y(N)\n Write(11,'(A18,F14.7)') 'Recursion Error: ', yMin - y(N)\n Write(11,*)\n\n End Program Ex0202\n\n*-----------------------------------------------------------------------\n*\n Function Func(x,y)\n\n Implicit None\n\n Double Precision Func, x, y\n\n Func = -x*y\n\n Return\n End Function Func\n\n", "meta": {"hexsha": "6bdf42f006faea168e128796627b6a6bc88eab5c", "size": 7125, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Exercise/Chapter-02/02-02/02-02.for", "max_stars_repo_name": "ajz34/Comp-Phys-Koonin", "max_stars_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-10-29T12:21:38.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-31T17:03:43.000Z", "max_issues_repo_path": "Exercise/Chapter-02/02-02/02-02.for", "max_issues_repo_name": "ajz34/Comp-Phys-Koonin", "max_issues_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Exercise/Chapter-02/02-02/02-02.for", "max_forks_repo_name": "ajz34/Comp-Phys-Koonin", "max_forks_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0632911392, "max_line_length": 72, "alphanum_fraction": 0.3863859649, "num_tokens": 2724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582477806521, "lm_q2_score": 0.8376199653600371, "lm_q1q2_score": 0.7793704052749907}} {"text": "program insertion\nimplicit none\n\n!-----------------------------------------------------------------\n! This programme sorts a series of values in increasing order,\n! using insertion sort, implemented with two working arrays.\n!\n! It works like this:\n! unsorted: A = [5, 3, 4, 1, 2, 6]\n! sorting:\n! pass 1: B = [5, 0, 0, 0, 0, 0]\n! pass 2: B = [3, 5, 0, 0, 0, 0]\n! pass 3: B = [3, 4, 5, 0, 0, 0]\n! pass 4: B = [1, 3, 4, 5, 0, 0]\n! pass 5: B = [1, 2, 3, 4, 5, 0]\n! pass 6: B = [1, 2, 3, 4, 5, 6]\n!------------------------------------------------------\n\nreal(kind=8), allocatable, dimension(:) :: A, B\ninteger :: i, j, k, n\nlogical :: sorted\n\n!------------------------------------------------------------\n! Make some random array:\n!------------------------------------------------------------\n\nwrite(*,*) 'size od array?'\nread(*,*) n\nallocate (A(n), B(n))\n\ncall random_seed()\ndo i = 1, n\n call random_number(A(i))\n A(i) = (A(i) * 100.0)\n A(i) = real(nint(A(i)*1000)) / 1000.0 !rounding off to 3 decimal places\n B(i) = 0.0\nend do\n\n!------------------------------------------------------------\n! Prepare output file:\n!------------------------------------------------------------\n\nopen(unit=1, file='insert', status='replace', action='write')\nwrite(1,*) 'here you can see the details of how the loops and conditionals'\nwrite(1,*) 'really work'\n\nwrite(1,*)\nwrite(1,*) '(using two arrays)'\nwrite(1,*)\nwrite(1,'(A3,10F10.5)') ' A ', A\nwrite(*,'(A3,10F10.5)') ' A ', A\nwrite(1,*)\n\n!------------------------------------------------------------\n! The actual sorting:\n!------------------------------------------------------------\n\ndo i = 1, n\n write (1,*) 'i', i\n sorted = .false.\n do j = 1, i-1 !Because B can only have elements up to i-1 diff. from 0\n write(1,*) ' j', j\n if (B(j) .ge. A(i)) then\n write(1,*) 'found it'\n do k = i-1, j, -1 !from the last value different from 0, to the \n! first one greater than i\n B(k+1) = B(k) !move every element by one\n write(1,*) ' k', k\n end do\n B(j) = A(i)\n sorted = .true.\n exit\n end if\n end do\n if (.not. sorted) B(i) = A(i)\n write(1,'(I4)')\n write(1,'(I4,A3,20F7.3)') i, ' B ', B\n write(*,'(I4,A3,20F7.3)') i, ' B ', B\nend do\n\nend program insertion\n", "meta": {"hexsha": "2db7d932e00a6084785f304ef395896088d2a880", "size": 2316, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "insertion_sort/insertion2arrays.f95", "max_stars_repo_name": "ElenaKusevska/Fortran_exercises", "max_stars_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "insertion_sort/insertion2arrays.f95", "max_issues_repo_name": "ElenaKusevska/Fortran_exercises", "max_issues_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "insertion_sort/insertion2arrays.f95", "max_forks_repo_name": "ElenaKusevska/Fortran_exercises", "max_forks_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.243902439, "max_line_length": 75, "alphanum_fraction": 0.4235751295, "num_tokens": 756, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782092, "lm_q2_score": 0.8933094117351309, "lm_q1q2_score": 0.7792761201024769}} {"text": "SUBROUTINE verlet(pos, acc, dt, time) \n IMPLICIT NONE\n REAL(8), INTENT(INOUT) :: pos, acc, dt, time\n REAL(8) :: prev_pos, next_pos\n\n\n prev_pos = pos\n time = 0d0\n\n DO\n IF (pos > 0d0) THEN\n time = time + dt\n next_pos = pos * 2d0 - prev_pos + acc * dt ** 2\n prev_pos = pos\n pos = next_pos\n ELSE\n EXIT\n END IF\n END DO\nEND SUBROUTINE verlet\n\nSUBROUTINE stormer_verlet(pos, acc, dt, time, vel) \n IMPLICIT NONE\n REAL(8), INTENT(INOUT) :: pos, acc, dt, time, vel\n REAL(8) :: prev_pos, next_pos\n\n prev_pos = pos \n time = 0d0\n vel = 0d0\n\n DO\n IF (pos > 0d0) THEN\n time = time + dt\n next_pos = pos * 2 - prev_pos + acc * dt ** 2\n prev_pos = pos\n pos = next_pos\n vel = vel + acc * dt\n ELSE\n EXIT\n END IF\n END DO\nEND SUBROUTINE stormer_verlet \n\nSUBROUTINE velocity_verlet(pos, acc, dt, time, vel) \n IMPLICIT NONE\n REAL(8), INTENT(INOUT) :: pos, acc, dt, time, vel\n\n time = 0d0\n vel = 0d0\n\n DO\n IF (pos > 0d0) THEN\n time = time + dt\n pos = pos + vel * dt + 0.5d0 * acc * dt ** 2 \n vel = vel + acc * dt\n ELSE\n EXIT\n END IF\n END DO\nEND SUBROUTINE velocity_verlet \n\nPROGRAM verlet_integration\n\n IMPLICIT NONE \n REAL(8) :: pos,acc, dt, time, vel\n \n INTERFACE\n SUBROUTINE verlet(pos, acc, dt, time)\n REAL(8), INTENT(INOUT) :: pos, acc, dt, time\n REAL(8) :: prev_pos, next_pos\n END SUBROUTINE\n END INTERFACE \n \n INTERFACE \n SUBROUTINE stormer_verlet(pos, acc, dt, time, vel) \n REAL(8), INTENT(INOUT) :: pos, acc, dt, time, vel\n REAL(8) :: prev_pos, next_pos\n END SUBROUTINE \n END INTERFACE \n \n INTERFACE \n SUBROUTINE velocity_verlet(pos, acc, dt, time, vel) \n REAL(8), INTENT(INOUT) :: pos, acc, dt, time, vel\n REAL(8) :: prev_pos, next_pos \n END SUBROUTINE \n END INTERFACE \n \n pos = 5d0\n acc = -10d0\n dt = 0.01d0\n ! Verlet \n CALL verlet(pos, acc, dt, time)\n \n WRITE(*,*) '[#]'\n WRITE(*,*) 'Time for Verlet integration:'\n WRITE(*,*) time \n \n ! stormer Verlet \n pos = 5d0\n CALL stormer_verlet(pos, acc, dt, time, vel)\n \n WRITE(*,*) '[#]'\n WRITE(*,*) 'Time for Stormer Verlet integration:'\n WRITE(*,*) time\n WRITE(*,*) '[#]'\n WRITE(*,*) 'Velocity for Stormer Verlet integration:'\n WRITE(*,*) vel\n \n \n \n ! Velocity Verlet\n pos = 5d0\n CALL velocity_verlet(pos, acc, dt, time, vel)\n \n WRITE(*,*) '[#]'\n WRITE(*,*) 'Time for velocity Verlet integration:'\n WRITE(*,*) time\n WRITE(*,*) '[#]'\n WRITE(*,*) 'Velocity for velocity Verlet integration:'\n WRITE(*,*) vel\n\nEND PROGRAM verlet_integration\n", "meta": {"hexsha": "3fda9f950d8a309bd68610557c0142e361b11ccb", "size": 3017, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "contents/verlet_integration/code/fortran/verlet.f90", "max_stars_repo_name": "alzawad26/algorithm-archive", "max_stars_repo_head_hexsha": "98ca4ab8115dd9013e6a5267cb757d61f0350ad7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1975, "max_stars_repo_stars_event_min_datetime": "2018-04-28T13:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T13:14:47.000Z", "max_issues_repo_path": "contents/verlet_integration/code/fortran/verlet.f90", "max_issues_repo_name": "alzawad26/algorithm-archive", "max_issues_repo_head_hexsha": "98ca4ab8115dd9013e6a5267cb757d61f0350ad7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 632, "max_issues_repo_issues_event_min_datetime": "2018-04-28T10:27:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T20:38:53.000Z", "max_forks_repo_path": "contents/verlet_integration/code/fortran/verlet.f90", "max_forks_repo_name": "alzawad26/algorithm-archive", "max_forks_repo_head_hexsha": "98ca4ab8115dd9013e6a5267cb757d61f0350ad7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 433, "max_forks_repo_forks_event_min_datetime": "2018-04-27T22:50:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-22T06:16:03.000Z", "avg_line_length": 24.5284552846, "max_line_length": 61, "alphanum_fraction": 0.5048060988, "num_tokens": 923, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.8933094017937621, "lm_q1q2_score": 0.77927610550088}} {"text": "program VectorProducts\n\n real, dimension(3) :: a, b, c\n\n a = (/ 3, 4, 5 /)\n b = (/ 4, 3, 5 /)\n c = (/ -5, -12, -13 /)\n\n print *, dot_product(a, b)\n print *, cross_product(a, b)\n print *, s3_product(a, b, c)\n print *, v3_product(a, b, c)\n\ncontains\n\n function cross_product(a, b)\n real, dimension(3) :: cross_product\n real, dimension(3), intent(in) :: a, b\n\n cross_product(1) = a(2)*b(3) - a(3)*b(2)\n cross_product(2) = a(3)*b(1) - a(1)*b(3)\n cross_product(3) = a(1)*b(2) - b(1)*a(2)\n end function cross_product\n\n function s3_product(a, b, c)\n real :: s3_product\n real, dimension(3), intent(in) :: a, b, c\n\n s3_product = dot_product(a, cross_product(b, c))\n end function s3_product\n\n function v3_product(a, b, c)\n real, dimension(3) :: v3_product\n real, dimension(3), intent(in) :: a, b, c\n\n v3_product = cross_product(a, cross_product(b, c))\n end function v3_product\n\nend program VectorProducts\n", "meta": {"hexsha": "fee14d2fe48b72bf5ccd6ae31fb6249f4382b82b", "size": 942, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Vector-products/Fortran/vector-products.f", "max_stars_repo_name": "mullikine/RosettaCodeData", "max_stars_repo_head_hexsha": "4f0027c6ce83daa36118ee8b67915a13cd23ab67", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Vector-products/Fortran/vector-products.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Vector-products/Fortran/vector-products.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 23.55, "max_line_length": 54, "alphanum_fraction": 0.6050955414, "num_tokens": 341, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9643214460461697, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7792365394184332}} {"text": " subroutine polfit(aamatr,cof,gmmatr,ier,ipivot,npfmax,npft,\n $ noutpt,nttyo,xvec,yvec)\nc\nc This subroutine fits an exact polynomial through npft points.\nc Each point is an x,y pair, where the values of x are in the\nc xvec array, those of y in the yvec array. The method is to solve\nc the matrix equation (A)(c) = (y) where:\nc\nc | 1 x(1) x(1)**2 ... |\nc | 1 x(2) x(2)**2 ... |\nc A = | 1 x(3) x(3)**2 ... |\nc | ... |\nc | 1 x(n) x(n)**2 ... |\nc\nc and solve for the coefficients (c), which give the\nc representation:\nc\nc y = c(1) + c(2)*x + c(3)*x**2 + ... + c(n)*x**n-1\nc\nc It is assumed that the xvec array contains distinct values\nc (i.e., there are no duplicates). The matrix A is the\nc array aamatr, the matrix dimension n is npft, and the\nc vector c is the array cof.\nc\nc If the xvec array was scaled using EQLIBU/scalx1.f, the resulting\nc yvec array should be rescaled using EQLIBU/rscaly.f.\nc\nc This subroutine is called by:\nc\nc EQPT/intrp.f\nc Any\nc\nc-----------------------------------------------------------------------\nc\nc Input:\nc\nc xvec = the x vector\nc yvec = the y vector\nc npft = number of x,y points\nc\nc Output:\nc\nc cof = the array of coefficients fo the fitted polynomial\nc ier = error flag (returned by EQLIBU/msolvr.f):\nc = 0 Okay\nc = 1 Encountered a zero matrix\nc = 2 Encountered a non-zero, computationally\nc singular matrix\nc\nc-----------------------------------------------------------------------\nc\n implicit none\nc\nc-----------------------------------------------------------------------\nc\nc Calling sequence variable declarations.\nc\n integer npfmax\nc\n integer ipivot(npfmax)\n integer ier,noutpt,npft,nttyo\nc\n real*8 aamatr(npfmax,npfmax),gmmatr(npfmax,npfmax)\n real*8 cof(npfmax),xvec(npfmax),yvec(npfmax)\nc\nc-----------------------------------------------------------------------\nc\nc Local variable declarations.\nc\n integer i,j\nc\n logical qpr\nc\n real*8 aax\nc\nc-----------------------------------------------------------------------\nc\n data qpr /.false./\nc\nc-----------------------------------------------------------------------\nc\nc Initialize error flag.\nc\n ier = 0\nc\nc Set up a matrix equation.\nc\n do j = 1,npft\n cof(j) = 0.\n aax = 1.\n aamatr(j,1) = 1.\n do i = 2,npft\n aax = aax*xvec(j)\n aamatr(j,i) = aax\n enddo\n enddo\nc\nc* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc\nc Solve the matrix equation.\nc\nc Calling sequence substitutions:\nc cof for delvec\nc npft for kdim\nc npfmax for kmax\nc yvec for rhsvec\nc\n call msolvr(aamatr,cof,gmmatr,ier,ipivot,npft,npfmax,\n $ noutpt,nttyo,qpr,yvec)\nc\n end\n", "meta": {"hexsha": "2e4c7358d7bedd49aa82af02a8431e6b0ba51007", "size": 3042, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/eqlibu/src/polfit.f", "max_stars_repo_name": "39alpha/eq3_6", "max_stars_repo_head_hexsha": "4ff7eec3d34634f1470ae5f67d8e294694216b6e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/eqlibu/src/polfit.f", "max_issues_repo_name": "39alpha/eq3_6", "max_issues_repo_head_hexsha": "4ff7eec3d34634f1470ae5f67d8e294694216b6e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-11-30T15:48:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-02T18:16:22.000Z", "max_forks_repo_path": "src/eqlibu/src/polfit.f", "max_forks_repo_name": "39alpha/eq3_6", "max_forks_repo_head_hexsha": "4ff7eec3d34634f1470ae5f67d8e294694216b6e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.1607142857, "max_line_length": 72, "alphanum_fraction": 0.4707429323, "num_tokens": 909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067228145364, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.779181425753675}} {"text": "!-------------------------------------------------------------------------------\n! Copyright (c) 2019 FrontISTR Commons\n! This software is released under the MIT License, see LICENSE.txt\n!-------------------------------------------------------------------------------\n!> \\brief This module provides data for gauss quadrature\nmodule gauss_integration\n use hecmw\n implicit none\n real(kind=kreal) :: XG(3, 3) !< abscissa of gauss points\n real(kind=kreal) :: WGT(3, 3) !< wieght of gauss points\n !****************************\n !* Gauss Integration Table **\n !****************************\n !** 1st ***\n data XG (1,1)/0.0/\n data WGT(1,1)/2.0/\n !** 2nd ***\n data XG(2,1),XG(2,2)/-0.577350269189626,0.577350269189626/\n data WGT(2,1),WGT(2,2)/1.0,1.0/\n !** 3rd ***\n data XG(3,1),XG(3,2),XG(3,3)/ &\n -0.7745966692, &\n 0.0, &\n 0.7745966692/\n data WGT(3,1),WGT(3,2),WGT(3,3)/ &\n 0.5555555555, &\n 0.8888888888, &\n 0.5555555555/\n ! end of this module\nend module gauss_integration\n", "meta": {"hexsha": "554ed39d659cc0b85c120d6a50b5753a2311eca8", "size": 1074, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fistr1/src/lib/GaussM.f90", "max_stars_repo_name": "masae-hayashi/FrontISTR", "max_stars_repo_head_hexsha": "a488de9eb45b3238ba0cd11454c71a03450666a6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 64, "max_stars_repo_stars_event_min_datetime": "2016-09-08T05:26:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T03:36:57.000Z", "max_issues_repo_path": "fistr1/src/lib/GaussM.f90", "max_issues_repo_name": "masae-hayashi/FrontISTR", "max_issues_repo_head_hexsha": "a488de9eb45b3238ba0cd11454c71a03450666a6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-04-12T09:46:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-17T09:51:51.000Z", "max_forks_repo_path": "fistr1/src/lib/GaussM.f90", "max_forks_repo_name": "masae-hayashi/FrontISTR", "max_forks_repo_head_hexsha": "a488de9eb45b3238ba0cd11454c71a03450666a6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-10-05T01:47:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-16T07:05:26.000Z", "avg_line_length": 34.6451612903, "max_line_length": 80, "alphanum_fraction": 0.4581005587, "num_tokens": 345, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067211996141, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7791814203946021}} {"text": "!--------------------------------------------------\n!..Homework 1\n!..Team 31\n!..AE305 - Numerical Methods\n!\n!..This program calculates the take-off time of an airplane\n!..at a provided altitude using either Euler's Metod \n!..or RK2 method for a provided time step size and \n!..outputs results to a file.\n!--------------------------------------------------\nModule data\n implicit none\n real,parameter:: WParea=29.24, takeoffweight=88250, TmaxSL=16256, nrofengines=2, friccoeff=0.02, grav=9.81\n real,parameter :: CL=1.792 ! CL is assumed constant\n real,parameter :: CD=0.2150 ! as CL is assumed constant, CD also became constant\n! Density obtained from the standart atmosphere table.\n real,parameter :: airdensitySL=1.225, airdensity1000m=1.112, airdensity2000m=1.007 \n \n real :: rho, thrust ! These variables will be set when altitude is selected\n\n contains\n \n Function Liftf(vel) ! Calculate Lift\n real :: vel, Liftf\n Liftf = CL*(1./2)*rho*(vel**2)*WParea\n return\n End Function Liftf\n \n Function Dragf(vel) ! Calculate Drag\n real :: vel, Dragf\n Dragf = CD*(1./2)*rho*(vel**2)*WParea\n return\n End Function Dragf\n\n Function Thrustf(dens) ! Calculate Thrust\n real :: dens, Thrustf\n Thrustf = TmaxSL*(dens/airdensitySL)\n return\n End Function Thrustf\n\n Function ODE(vel) ! Slope function for velocity\n real:: vel\n real :: ODE\n ODE = (thrust-Dragf(vel)-friccoeff*(takeoffweight-Liftf(vel)))*(grav/takeoffweight)\n return\n End\nEnd module\n\nPROGRAM HOMEWORK1\n use data\n\n implicit none\n\n character*40 :: fname\n real :: stepsize, k1, k2, velocity, velocityx, lift, time\n real, parameter:: a1 =1./4 , a2=3./4, p1=2./3 ! a1 and a2 are weights for RK2 Method\n integer :: method, selectedaltitude ! Inputs stored in these variables\n\n! Initial values\n time=0.\n velocity=0.\n lift=0.\n\n! Select numerical Method\n write(*,'(a)')'Select Method:'\n write(*,'(a)')' [1] Eulers Method'\n write(*,'(a)')' [2] RK Method'\n write(*,'(a)',advance='no')'Input :> '\n read(*,*) method\n\n! Check if selection is valid\n if(.not.(method .eq. 1 .or. method .eq. 2)) then\n write(*,*) 'Unidentified input, stopping program...'\n stop\n endif\n\n! Select altitude\n write(*,'(/,a)')'Select one of the available altitudes:'\n write(*,'(a)')' [1] 0 m (Sea Level)'\n write(*,'(a)')' [2] 1000 m '\n write(*,'(a)')' [3] 2000 m '\n write(*,'(a)',advance='no')'Input :> '\n read(*,*) selectedaltitude\n\n! Set proper variables for selected altitude\n Select case(selectedaltitude)\n case(1)\n write(*,*) 'Selected Sea Level'\n ! Set density and thrust for sea level\n rho = airdensitySL\n thrust = TmaxSL*nrofengines\n case(2)\n write(*,*) 'Selected 1000 m'\n ! Set density and thrust for 1000 m\n rho = airdensity1000m\n thrust = Thrustf(rho)*nrofengines\n case(3)\n ! Set density and thrust for 2000 m\n write(*,*) 'Selected 2000 m'\n rho = airdensity2000m\n thrust = Thrustf(rho)*nrofengines\n case default\n ! Validation check\n write(*,*) 'Unidentified input, stopping program...'\n stop\n end Select\n\n! Select time step\n write(*,'(/,(a))',advance='no')'Enter Time Step :> '\n read(*,*) stepsize\n\n! Open the output file\n write(*,'(/,a)',advance='no')'Enter the output file name [velocity.dat] :> '\n read(*,\"(a)\") fname\n if( fname .eq. \" \") fname = \"velocity.dat\"\n open(1,file=fname,form=\"formatted\")\n\n! Write the inital values to the output file\n write(1,\"(3f12.3)\") time, velocity\n\n! Use selected method\n Select case(method)\n case(1) ! EULER METHOD \n write(*,*) 'Using Eulers Method'\n do while ( lift .lt. takeoffweight ) ! Check if lift off occured \n time = time + stepsize ! New time is defined\n velocity = velocity + ODE(velocity)*stepsize ! New velocity is defined\n lift = Liftf(velocity) ! Calculate the lift to check if lift off occured\n write(1,\"(2f12.3)\") time, velocity\n enddo\n write(*,'(a,f6.3)') 'Minimum time needed to take off:', time ! Write result to terminal\n case(2) ! RK2 METHOD \n write(*,*) 'Using RK Method'\n do while ( lift .lt. takeoffweight ) ! Check if lift off occured \n time = time + stepsize ! New time is defined\n k1 = ODE(velocity) ! k1 is calculated which is the slope at previous velocity\n velocityx = velocity + k1*p1*stepsize ! velocityx is calculated\n k2 = ODE(velocityx) ! k2 is calculated which is the slope at velocityx\n velocity = velocity + ( a1*k1 + a2*k2 )* stepsize ! New velocity is defined\n lift = Liftf(velocity) ! Calculate the lift to check if lift off occured\n write(1,\"(2f12.3)\") time, velocity\n enddo\n write(*,'(a,f6.3)') 'Minimum time needed to take off:', time ! Write result to terminal\n End select\n\n!..Close the output file\n close(1)\n\n stop\nEND PROGRAM HOMEWORK1\n", "meta": {"hexsha": "a17756b66b73525f81425ddd9b04c142e372669e", "size": 5325, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Homework1/homework1.f90", "max_stars_repo_name": "Atknssl/AE305-Homeworks", "max_stars_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-06T18:42:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-04T13:27:27.000Z", "max_issues_repo_path": "Homework1/homework1.f90", "max_issues_repo_name": "Atknssl/AE305-Homeworks", "max_issues_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework1/homework1.f90", "max_forks_repo_name": "Atknssl/AE305-Homeworks", "max_forks_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.2649006623, "max_line_length": 122, "alphanum_fraction": 0.578028169, "num_tokens": 1499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067228145365, "lm_q2_score": 0.8267117898012105, "lm_q1q2_score": 0.7791814197176788}} {"text": "module nfSpecialFunctions\n use nfConstants\n implicit none\n\n public :: legendrePoly\n\n interface legendrePoly\n module procedure legendrePoly_i, legendrePoly_r, legendrePoly_d\n end interface\n\ncontains\n\n recursive function legendrePolyFunc(n,x) result(res)\n integer :: i, n\n real(dp), allocatable :: poly(:)\n real(dp) :: x, res\n\n allocate(poly(n+1))\n poly(1) = 1.d0\n poly(2) = x\n if(n.eq.0) then\n res = 1\n elseif(n.eq.1) then\n res = x\n else\n do i=2,n\n res = 0.d0\n res = (2*(i-1)+1)*x*poly(i)\n res = res - (i-1)*poly(i-1)\n res = res/(i)\n poly(i+1) = res\n end do\n res = poly(n+1)\n end if\n deallocate(poly)\n end function\n\n real(dp) function legendrePoly_i(n,x)\n integer :: n, x\n legendrePoly_i = legendrePolyFunc(n,dble(x))\n end function\n\n real(dp) function legendrePoly_r(n,x)\n integer :: n\n real :: x\n legendrePoly_r = legendrePolyFunc(n,dble(x))\n end function\n\n real(dp) function legendrePoly_d(n,x)\n integer :: n\n real(dp) :: x\n legendrePoly_d = legendrePolyFunc(n,dble(x))\n end function\n\n end module nfSpecialFunctions", "meta": {"hexsha": "9635f3b13580e7d0964475b335bc400f0714f29b", "size": 1150, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/nfSpecialFunctions.f90", "max_stars_repo_name": "joshhooker/numFortran", "max_stars_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/nfSpecialFunctions.f90", "max_issues_repo_name": "joshhooker/numFortran", "max_issues_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/nfSpecialFunctions.f90", "max_forks_repo_name": "joshhooker/numFortran", "max_forks_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.9090909091, "max_line_length": 67, "alphanum_fraction": 0.6147826087, "num_tokens": 364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.779140871315135}} {"text": "program epstest\n\nuse, intrinsic :: iso_fortran_env, only : real32, real64\nuse, intrinsic :: ieee_arithmetic, only : ieee_next_after\n\nimplicit none (type, external)\n\nreal(real32) :: one32_eps, eps32\nreal(real64) :: one64_eps, eps64\n\neps32 = epsilon(0._real32)\neps64 = epsilon(0._real64)\n\nprint *, \"epsilon real32\", eps32\nprint *, \"epsilon real64\", eps64\n\none32_eps = ieee_next_after(1._real32, 2.)\none64_eps = ieee_next_after(1._real64, 2.)\n\n!> this test should be bit exact true\nif (one32_eps - eps32 /= 1) error stop \"real32 epsilon not meeting specification\"\nif (one64_eps - eps64 /= 1) error stop \"real64 epsilon not meeting specification\"\n\nend program\n", "meta": {"hexsha": "37a17f904e450d3ca8bd7635f6424ccba45c9848", "size": 656, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "real/epsilon.f90", "max_stars_repo_name": "supershushu/fortran2018-examples", "max_stars_repo_head_hexsha": "f0dc03b80326bc7c06fa31945b6e7406a60c1fa8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-05-11T03:51:26.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T08:08:43.000Z", "max_issues_repo_path": "real/epsilon.f90", "max_issues_repo_name": "supershushu/fortran2018-examples", "max_issues_repo_head_hexsha": "f0dc03b80326bc7c06fa31945b6e7406a60c1fa8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "real/epsilon.f90", "max_forks_repo_name": "supershushu/fortran2018-examples", "max_forks_repo_head_hexsha": "f0dc03b80326bc7c06fa31945b6e7406a60c1fa8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.24, "max_line_length": 81, "alphanum_fraction": 0.7454268293, "num_tokens": 197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7791408696190469}} {"text": "subroutine cell_area (nlat, nlon, numlon, lon_w, lat_s, re, area)\n\n use precision\n\n implicit none\n! ------------------------ code history ---------------------------\n! source file: cell_area.F\n! purpose: area of grid cells\n! date last revised: March 1996\n! author: Gordon Bonan\n! standardized:\n! reviewed:\n! -----------------------------------------------------------------\n\n! ------------------- input variables -----------------------------\n integer nlat !number of latitude points\n integer nlon !maximum number of longitude points\n integer numlon(nlat) !number of longitude points for each latitude \n real(r8) lon_w(nlon+1,nlat) !grid cell longitude, western edge (degrees)\n real(r8) lat_s(nlat+1) !grid cell latitude, southern edge (degrees)\n! -----------------------------------------------------------------\n\n! ------------------- output variables ----------------------------\n real(r8) re !radius of earth (km)\n real(r8) area(nlon,nlat) !cell area (km**2)\n! -----------------------------------------------------------------\n\n! ------------------- local variables -----------------------------\n integer i !longitude index\n integer j !latitude index\n\n real(r8) dx !cell width\n real(r8) dy !cell length\n real(r8) deg2rad !pi/180\n real(r8) one\n parameter (one=1.) ! Argument to atan\n! -----------------------------------------------------------------\n\n deg2rad = (4.*atan(one)) / 180.\n re = 6371.227709\n\n do j = 1, nlat\n do i = 1, numlon(j)\n dx = (lon_w(i+1,j)-lon_w(i,j)) * deg2rad\n dy = sin(lat_s(j+1)*deg2rad) - sin(lat_s(j)*deg2rad)\n area(i,j) = dx*dy*re*re\n end do\n end do\n\n return\nend subroutine cell_area\n", "meta": {"hexsha": "28dbe75b1c1f68d864f39a341e76d5d7db35b8bf", "size": 1779, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "components/eam/tools/icesst/regrid/cell_area.f90", "max_stars_repo_name": "Fa-Li/E3SM", "max_stars_repo_head_hexsha": "a91995093ec6fc0dd6e50114f3c70b5fb64de0f0", "max_stars_repo_licenses": ["zlib-acknowledgement", "FTL", "RSA-MD"], "max_stars_count": 235, "max_stars_repo_stars_event_min_datetime": "2018-04-23T16:30:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T17:53:12.000Z", "max_issues_repo_path": "components/eam/tools/icesst/regrid/cell_area.f90", "max_issues_repo_name": "Fa-Li/E3SM", "max_issues_repo_head_hexsha": "a91995093ec6fc0dd6e50114f3c70b5fb64de0f0", "max_issues_repo_licenses": ["zlib-acknowledgement", "FTL", "RSA-MD"], "max_issues_count": 2372, "max_issues_repo_issues_event_min_datetime": "2018-04-20T18:12:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:43:17.000Z", "max_forks_repo_path": "components/eam/tools/icesst/regrid/cell_area.f90", "max_forks_repo_name": "Fa-Li/E3SM", "max_forks_repo_head_hexsha": "a91995093ec6fc0dd6e50114f3c70b5fb64de0f0", "max_forks_repo_licenses": ["zlib-acknowledgement", "FTL", "RSA-MD"], "max_forks_count": 254, "max_forks_repo_forks_event_min_datetime": "2018-04-20T20:43:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T20:13:38.000Z", "avg_line_length": 34.2115384615, "max_line_length": 74, "alphanum_fraction": 0.4547498595, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947101574299, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7791121530382431}} {"text": "SUBROUTINE productdot(r1,r2 , dp)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: productdot.f90\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Dot product between two vectors (scalar product)\r\n! ----------------------------------------------------------------------\r\n! Input arguments:\r\n! - r1 : first vector [x1 y1 z1]'\r\n! - r2 : second vector [x2 y2 z2]'\r\n!\r\n! Output arguments:\r\n! - dp : Dot product of r1,r2 vectors (scalar)\r\n! ----------------------------------------------------------------------\r\n! Dr. Thomas Papanikolaou, Geoscience Australia 24 November 2015\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n USE mdl_precision\r\n IMPLICIT NONE\r\n\r\n! ---------------------------------------------------------------------------\r\n! Dummy arguments declaration\r\n! ---------------------------------------------------------------------------\r\n! IN\r\n REAL (KIND = prec_q), INTENT(IN), DIMENSION(3) :: r1, r2\r\n! OUT\r\n REAL (KIND = prec_q), INTENT(OUT) :: dp\r\n! ---------------------------------------------------------------------------\r\n\r\n\r\n\r\n dp = r1(1) * r2(1) + r1(2) * r2(2) + r1(3) * r2(3)\r\n\t \r\n\r\nEND\r\n\r\n", "meta": {"hexsha": "3f39d517433e759f0f8ff1625543915b0605c50e", "size": 1266, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/productdot.f90", "max_stars_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_stars_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2021-07-08T23:35:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:17:58.000Z", "max_issues_repo_path": "src/fortran/productdot.f90", "max_issues_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_issues_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-09-27T14:27:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T23:50:02.000Z", "max_forks_repo_path": "src/fortran/productdot.f90", "max_forks_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_forks_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2021-07-12T05:42:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T15:15:34.000Z", "avg_line_length": 31.65, "max_line_length": 78, "alphanum_fraction": 0.308056872, "num_tokens": 251, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.7790493994463097}} {"text": "! Crude Monte-Carlo integration\n\nPROGRAM crude_mc_integration\n USE constants\n USE f90library\n IMPLICIT NONE\n INTEGER :: i, idum, samples\n REAL(DP) :: x, sumf, sum2f, fx, sigma\n\n INTERFACE\n DOUBLE PRECISION FUNCTION func(x)\n IMPLICIT NONE\n DOUBLE PRECISION , INTENT(IN) :: x\n\n END FUNCTION func\n END INTERFACE\n WRITE(*,*) ' Enter number of MC sampling points'\n READ(*,*) samples\n ! initialise the total sum, standard deviation and seed idum \n sumf=0. ; sum2f=0. ; idum=-1\n DO i=1, samples\n x=ran1(idum)\n fx=func(x)\n sumf=sumf+fx\n sum2f=sum2f+fx*fx\n ENDDO\n sumf=sumf/FLOAT(samples)\n sum2f=sum2f/FLOAT(samples)\n sigma=SQRT((sum2f-sumf*sumf)/FLOAT(samples))\n WRITE(*,*) samples, sumf, sigma\n\nEND PROGRAM crude_mc_integration\n\n! The explicit function to be evaluated\n\nREAL(DP) FUNCTION func(x)\n USE constants\n IMPLICIT NONE\n REAL(DP), INTENT(IN) :: x\n func=4/(1.+x*x) \n\nEND FUNCTION func\n\n\n", "meta": {"hexsha": "fa6aec2a4454a10ff52f7f3b1987c9ab0a70ab9c", "size": 957, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/Programs/LecturePrograms/programs/MCIntro/f90/program1.f90", "max_stars_repo_name": "kimrojas/ComputationalPhysicsMSU", "max_stars_repo_head_hexsha": "a47cfc18b3ad6adb23045b3f49fab18c0333f556", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 220, "max_stars_repo_stars_event_min_datetime": "2016-08-25T09:18:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T14:09:16.000Z", "max_issues_repo_path": "doc/Programs/LecturePrograms/programs/MCIntro/f90/program1.f90", "max_issues_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_issues_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-01-18T10:43:38.000Z", "max_issues_repo_issues_event_max_datetime": "2020-02-08T13:15:42.000Z", "max_forks_repo_path": "doc/Programs/LecturePrograms/programs/MCIntro/f90/program1.f90", "max_forks_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_forks_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 136, "max_forks_repo_forks_event_min_datetime": "2016-08-25T09:04:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T09:54:21.000Z", "avg_line_length": 21.2666666667, "max_line_length": 67, "alphanum_fraction": 0.6666666667, "num_tokens": 308, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915913, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7790493991047448}} {"text": "!*********************************************************\n!>\n! Spline Functions:\n!\n! * Natural Cubic Spline\n\nmodule cubicSpline\n use matrixSolver\n implicit none\n\n private :: dp\n integer, parameter :: dp = kind(0.d0)\n\ncontains\n\n subroutine naturalCubicSpline(xi, yi, splineA, splineB, splineC, splineD)\n implicit none\n integer :: n\n real(dp) :: xi(:), yi(:), splineA(:), splineB(:), splineC(:), splineD(:)\n real(dp), dimension(:), allocatable :: a,b,c,f,h\n\n n = size(xi,1)\n allocate(a(n), b(n), c(n), f(n), h(n))\n a(1) = 0.d0\n b(1) = 1.d0\n c(1) = 0.d0\n f(1) = 0.d0\n splineA(1:n) = yi(1:n)\n splineB(1:n) = 0.d0\n splineC(1:n) = 0.d0\n splineD(1:n) = 0.d0\n h(1:n) = abs(xi(2:n+1)-xi(1:n))\n a(2:n) = h(1:n-1)\n b(2:n) = 2.d0*(h(1:n-1)+h(2:n))\n c(2:n) = h(2:n)\n f(2:n) = abs(3.d0*(yi(3:n+1)-yi(2:n))/h(2:n) - 3.d0*(yi(2:n)-yi(1:n-1))/h(1:n-1))\n a(n) = 0.d0\n b(n) = 1.d0\n c(n) = 0.d0\n f(n) = 0.d0\n call tridiagonalSolver(a,b,c,f,splineC)\n splineD(1:n-1) = (splineC(2:n) - splineC(1:n-1))/(3.d0*h(1:n-1))\n splineB(1:n-1) = (yi(2:n) - yi(1:n-1))/h(1:n-1) - splineC(1:n-1)*h(1:n-1) -&\n splineD(1:n-1)*h(1:n-1)*h(1:n-1)\n deallocate(a,b,c,f,h)\n end subroutine naturalCubicSpline\n\n real(dp) function computeNaturalCubicSpline(xi, x, splineA, splineB, splineC, splineD)\n implicit none\n integer :: i, n\n real(dp) :: xi(:), x, splineA(:), splineB(:), splineC(:), splineD(:), output, dx\n\n n = size(xi,1)\n do i=n-1,1,-1\n if(x.ge.xi(i)) then\n exit\n end if\n end do\n dx = x - xi(i)\n output = splineA(i) + dx*(splineB(i) + dx*(splineC(i) + splineD(i)*dx))\n computeNaturalCubicSpline = output\n end function computeNaturalCubicSpline\n\nend module\n", "meta": {"hexsha": "563d3ab4c60bee0e7652bf398b3c6a92741a29ab", "size": 1776, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "srcOLD/cubicSpline.f90", "max_stars_repo_name": "joshhooker/numFortran", "max_stars_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "srcOLD/cubicSpline.f90", "max_issues_repo_name": "joshhooker/numFortran", "max_issues_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "srcOLD/cubicSpline.f90", "max_forks_repo_name": "joshhooker/numFortran", "max_forks_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.3230769231, "max_line_length": 88, "alphanum_fraction": 0.5253378378, "num_tokens": 725, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810436809827, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.778926390385542}} {"text": "program compute_factorial\n implicit none\n integer :: i\n integer, dimension(5) :: values = [ (i, i=1,5) ]\n\n print *, values\n print *, factorial(values)\n\ncontains\n\n elemental integer function factorial(n)\n implicit none\n integer, value :: n\n integer :: i\n\n factorial = 1\n do i = 2, n\n factorial = factorial*i\n end do\n end function factorial\n\nend program compute_factorial\n", "meta": {"hexsha": "3c9fa04bea47f6a440cb06a790f138b1cf4dc110", "size": 444, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/arrays/compute_factorial.f90", "max_stars_repo_name": "caguerra/Fortran-MOOC", "max_stars_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-05-20T12:03:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T19:46:26.000Z", "max_issues_repo_path": "source_code/arrays/compute_factorial.f90", "max_issues_repo_name": "caguerra/Fortran-MOOC", "max_issues_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-30T04:25:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T08:21:30.000Z", "max_forks_repo_path": "source_code/arrays/compute_factorial.f90", "max_forks_repo_name": "caguerra/Fortran-MOOC", "max_forks_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-09-27T07:30:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T16:23:19.000Z", "avg_line_length": 19.3043478261, "max_line_length": 52, "alphanum_fraction": 0.5923423423, "num_tokens": 107, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771662, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.7788823181997787}} {"text": "subroutine cal_sd(n,x,sd)\n implicit none\n integer,intent(in) :: n\n double precision, intent(in) :: x(n)\n double precision, intent(out) :: sd\n integer :: i\n double precision :: mean, mean2\n mean = 0.d0\n mean2 = 0.d0\n do i = 1, n\n mean = mean + x(i)\n mean2 = mean2 + x(i)**2\n end do\n mean = mean/n\n mean2 = mean2/n\n sd = sqrt(mean2 - mean**2)\nend subroutine cal_sd", "meta": {"hexsha": "7795b7c44e123b78e4c2d7752ec6527c4ba348f3", "size": 381, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "extra/src/sub_cal_sd.f90", "max_stars_repo_name": "lusystemsbio/numericalR", "max_stars_repo_head_hexsha": "014d849062d56181c0423e721c25383896d620bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "extra/src/sub_cal_sd.f90", "max_issues_repo_name": "lusystemsbio/numericalR", "max_issues_repo_head_hexsha": "014d849062d56181c0423e721c25383896d620bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "extra/src/sub_cal_sd.f90", "max_forks_repo_name": "lusystemsbio/numericalR", "max_forks_repo_head_hexsha": "014d849062d56181c0423e721c25383896d620bb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.4117647059, "max_line_length": 38, "alphanum_fraction": 0.6141732283, "num_tokens": 136, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303292, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7788823094215688}} {"text": "program main\n ! Default\n implicit none\n\n ! Parameters\n integer(4), parameter :: max_divisor = 20\n\n ! Variables\n integer(4) :: i\n\n ! Do work\n i = max_divisor + 1\n do\n if (is_divisible(i)) then\n exit\n else\n i = i + 1\n endif\n enddo\n\n ! Write out result\n write(*,*) \"Smallest number divisible by all numbers less than \",max_divisor,&\n \": \",i\n\n\ncontains\n\n\n pure function is_divisible(targ)\n ! Default\n implicit none\n\n ! Function arguments\n integer(4), intent(in) :: targ\n logical :: is_divisible\n\n ! Local variables\n integer(4) :: i\n\n ! Check if the number is divisible by all factors\n do i=2,max_divisor\n if (mod(targ,i)/=0) then\n is_divisible = .false.\n return\n endif\n enddo\n\n is_divisible = .true.\n return\n end function is_divisible\n\n\nend program main\n", "meta": {"hexsha": "b03e27664fd40c1619b9055133a2ee68f1ee38c0", "size": 877, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/problem5/problem5.f90", "max_stars_repo_name": "plaplant/Project_Euler", "max_stars_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/problem5/problem5.f90", "max_issues_repo_name": "plaplant/Project_Euler", "max_issues_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/problem5/problem5.f90", "max_forks_repo_name": "plaplant/Project_Euler", "max_forks_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-01-07T21:43:45.000Z", "max_forks_repo_forks_event_max_datetime": "2017-01-07T21:43:45.000Z", "avg_line_length": 16.2407407407, "max_line_length": 80, "alphanum_fraction": 0.590649943, "num_tokens": 252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834278, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.7788466085433264}} {"text": "program main\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n integer, allocatable :: seed(:)\n integer :: n\n real(dp) :: t_begin, t_end\n integer :: i, num_pt = 1000\n\n interface\n function Random_pt_annulus_general(r_1_, r_2_)\n ! 变换抽样一般方法产生圆环上均匀分布的随机点\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n real(dp), intent(in), optional :: r_1_, r_2_\n real(dp) :: Random_pt_annulus_general(2) ! (r, theta)\n end function Random_pt_annulus_general\n\n function Random_pt_annulus(r_1_, r_2_)\n ! 抽样法产生圆环上均匀分布的随机点\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n real(dp), intent(in), optional :: r_1_, r_2_\n real(dp) :: Random_pt_annulus(2)\n end function Random_pt_annulus\n\n function Gaussian_Box_Muller_improved(x_bar_, sigma_square_)\n ! Box-Muller 法产生服从正态分布的随机数,其中随机数的三角函数通过抽样得到\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n real(dp), intent(in), optional :: x_bar_, sigma_square_ ! 均值和方差\n real(dp) :: Gaussian_Box_Muller_improved\n end function Gaussian_Box_Muller_improved\n\n function Marsaglia_3d_sphere()\n ! 三维球面上的 Marsaglia 方法\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n real(dp) :: Marsaglia_3d_sphere(3) ! (x, y, z)\n end function Marsaglia_3d_sphere\n end interface\n\n call random_seed(size=n)\n allocate(seed(n))\n seed = 1\n call random_seed(put=seed)\n call cpu_time(t_begin)\n open(unit=11, file='1.2.2.3-Random-Points-on-Annulus-Transform-Sampling-General-Method.txt', status='replace')\n do i = 1, num_pt\n write(11, '(2f16.8)') Random_pt_annulus_general(1.d0, 2.d0)\n end do\n close(11)\n call cpu_time(t_end)\n write(*,*)&\n 'Generate random points uniformly distributed on annulus by transform sampling general method. Time consumed = ',&\n t_end - t_begin\n\n call cpu_time(t_begin)\n open(unit=11, file='1.2.2.3-Random-Points-on-Annulus-Sampling.txt', status='replace')\n do i = 1, num_pt\n write(11, '(2f16.8)') Random_pt_annulus(1.d0, 2.d0)\n end do\n close(11)\n call cpu_time(t_end)\n write(*,*)&\n 'Generate random points uniformly distributed on annulus by sampling. Time consumed = ',&\n t_end - t_begin\n\n open(unit=11, file='1.2.2.3-Gaussian-Random-Variable.txt', status='replace')\n do i = 1, num_pt\n write(11, '(f16.8)') Gaussian_Box_Muller_improved(1.d0, 1.d0)\n end do\n close(11)\n\n open(unit=11, file='1.2.2.3-Random-Points-on-3d-Sphere.txt')\n do i = 1, num_pt\n write(11, '(3f16.8)') Marsaglia_3d_sphere()\n end do\n close(11)\nend program main\n\nfunction Random_pt_annulus_general(r_1_, r_2_)\n ! 变换抽样一般方法产生圆环上均匀分布的随机点\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n real(dp), parameter :: pi = acos(-1.d0)\n\n real(dp), intent(in), optional :: r_1_, r_2_\n real(dp) :: Random_pt_annulus_general(2) ! (x, y)\n\n real(dp) :: r_inner, r_outer ! 内径和外径\n real(dp) :: xi\n real(dp) :: r, theta\n\n if ((present(r_1_)) .and. (present(r_2_))) then\n if (r_1_ < r_2_) then\n r_inner = r_1_\n r_outer = r_2_\n else if (r_1_ > r_2_) then\n r_inner = r_2_\n r_outer = r_1_\n else\n write(*,*) 'Inner radius equals outer radius, cannot generate random points.'\n Random_pt_annulus_general = 0.d0\n return\n end if\n else\n r_inner = 0.d0\n r_outer = 1.d0\n end if\n\n call random_number(xi)\n r = sqrt((r_outer**2.d0 - r_inner**2.d0) * xi + r_inner**2.d0)\n call random_number(xi)\n theta = 2.d0 * pi * xi\n Random_pt_annulus_general(1) = r * cos(theta)\n Random_pt_annulus_general(2) = r * sin(theta)\nend function Random_pt_annulus_general\n\nfunction Random_pt_annulus(r_1_, r_2_)\n ! hit-or-miss 法产生圆环上均匀分布的随机点\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n real(dp), intent(in), optional :: r_1_, r_2_\n real(dp) :: Random_pt_annulus(2) ! (x, y)\n\n real(dp) :: r_inner, r_outer ! 内径和外径\n\n if ((present(r_1_)) .and. (present(r_2_))) then\n if (r_1_ < r_2_) then\n r_inner = r_1_\n r_outer = r_2_\n else if (r_1_ > r_2_) then\n r_inner = r_2_\n r_outer = r_1_\n else\n write(*,*) 'Inner radius equals outer radius, cannot generate random points.'\n Random_pt_annulus = 0.d0\n return\n end if\n else\n r_inner = 0.d0\n r_outer = 1.d0\n end if\n\n do while (.true.)\n call random_number(Random_pt_annulus(1))\n call random_number(Random_pt_annulus(2))\n Random_pt_annulus = (2 * Random_pt_annulus - 1) * r_outer\n if ((r_inner**2 <= sum(Random_pt_annulus**2)) .and. (sum(Random_pt_annulus**2) < r_outer**2)) then\n return\n end if\n end do\nend function\n\nfunction Gaussian_Box_Muller_improved(x_bar_, sigma_square_)\n ! Box-Muller 法产生服从正态分布的随机数,其中随机数的三角函数通过 hit-or-miss 法得到\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n real(dp), intent(in), optional :: x_bar_, sigma_square_ ! 均值和方差\n real(dp) :: Gaussian_Box_Muller_improved\n\n real(dp) :: x_bar, sigma_square\n real(dp) :: u, v, xi\n\n if (present(x_bar_)) then\n x_bar = x_bar_\n else\n x_bar = 0.d0\n end if\n if (present(sigma_square_)) then\n sigma_square = sigma_square_\n else\n sigma_square = 1.d0\n end if\n\n do while (.true.)\n call random_number(u)\n call random_number(v)\n u = 2.d0 * u - 1.d0\n v = 2.d0 * v - 1.d0\n if (u**2.d0 + v**2.d0 < 1.d0) then\n exit\n end if\n end do\n call random_number(xi)\n Gaussian_Box_Muller_improved = u * sqrt(-2.d0 * log(xi))\n ! Gaussian_Box_Muller_improved = v * sqrt(-2.d0 * log(xi))\n Gaussian_Box_Muller_improved = Gaussian_Box_Muller_improved * sqrt(sigma_square) + x_bar\nend function Gaussian_Box_Muller_improved\n\nfunction Marsaglia_3d_sphere()\n ! 三维球面上的 Marsaglia 方法\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n real(dp) :: Marsaglia_3d_sphere(3) ! (x, y, z)\n\n real(dp) :: u, v, r_square\n\n do while (.true.)\n call random_number(u)\n call random_number(v)\n u = 2.d0 * u - 1.d0\n v = 2.d0 * v - 1.d0\n r_square = u**2.d0 + v**2.d0\n if (r_square <= 1) then\n exit\n end if\n end do\n\n Marsaglia_3d_sphere(1) = 2.d0 * u * sqrt(1 - r_square)\n Marsaglia_3d_sphere(2) = 2.d0 * v * sqrt(1 - r_square)\n Marsaglia_3d_sphere(3) = 1 - 2.d0 * r_square\nend function Marsaglia_3d_sphere", "meta": {"hexsha": "eef9bcea5a7d485a998d132997cb79ac6d789087", "size": 6840, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Chap1-Monte-Carlo-Method-Basic/1.2.2.3-Random-Points-on-Annulus.f90", "max_stars_repo_name": "Chen-Jialin/Computational-Physics-Practice", "max_stars_repo_head_hexsha": "5bbb271123ee75727d266e6ca83d090ad8919abb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chap1-Monte-Carlo-Method-Basic/1.2.2.3-Random-Points-on-Annulus.f90", "max_issues_repo_name": "Chen-Jialin/Computational-Physics-Practice", "max_issues_repo_head_hexsha": "5bbb271123ee75727d266e6ca83d090ad8919abb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chap1-Monte-Carlo-Method-Basic/1.2.2.3-Random-Points-on-Annulus.f90", "max_forks_repo_name": "Chen-Jialin/Computational-Physics-Practice", "max_forks_repo_head_hexsha": "5bbb271123ee75727d266e6ca83d090ad8919abb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.9502262443, "max_line_length": 118, "alphanum_fraction": 0.610380117, "num_tokens": 2226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.7788416352771216}} {"text": "!-------------------------------------------------------------------------------------------------\n! Fortran source code for module ctef2py.getgauss\n!-------------------------------------------------------------------------------------------------\n! Remarks:\n! . Enter Python documentation for this module in ``./getgauss.rst``.\n! You might want to check the f2py output for the interfaces of the C-wrapper functions.\n! It will be autmatically included in the ctef2py documentation.\n! . Documument the Fortran routines in this file. This documentation will not be included\n! in the ctef2py documentation (because there is no recent sphinx\n! extension for modern fortran.\n\n! ---------------------------------------------------------------------------------------------------------------\n! ORIGINAL AUTHORS : MIKE BLASKIEWISC, RODERIK BRUCE, MICHAELA SCHAUMANN, TOM MERTENS\n! ---------------------------------------------------------------------------------------------------------------\n! VERSION 2.0 : UPDATE TO TRACK MULTIPLE BUNCHES AND HAVE DIFFERENT PARTICLE TYPES (P-PB) \n! AUTHOR : TOM MERTENS\n! DATE : 19/12/2016\n! COPYRIGHT : CERN\n! \n! DESCRIPTION : \n! FUNCTION TO GET DOUBLE GAUSSIAN\n! RETURNS TWO GAUSSIAN DISTRIBUTED RANDOM NUMBERS WITH SIGMA SQRT 3\n! ---------------------------------------------------------------------------------------------------------------\n\nsubroutine getgaussrv(iseed,grv1,grv2)\n double precision, intent(inout) :: iseed\n double precision, intent(out):: grv1,grv2\n double precision :: r1,r2,facc,amp\n \n 44 continue\n call random_number(iseed)\n r1 = 2*iseed-1\n r2 = 2*iseed-1\n amp = r1**2 + r2**2\n \n if ((amp.ge.1).or.(amp.lt. 1.e-8)) go to 44\n facc = sqrt(-2.*log(amp)/amp)\n grv1 = r1*facc/sqrt(3.)\n grv2 = r2*facc/sqrt(3.)\n return\nend subroutine getgaussrv\n \n \n", "meta": {"hexsha": "8b370c07c66439229eb707732d86584267e6c0dd", "size": 1899, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ctef2py/f90_getgauss/getgauss.f90", "max_stars_repo_name": "tomerten/ctef2py", "max_stars_repo_head_hexsha": "190b83819e0ada830b76577e3f46d0d1cbbbacd7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ctef2py/f90_getgauss/getgauss.f90", "max_issues_repo_name": "tomerten/ctef2py", "max_issues_repo_head_hexsha": "190b83819e0ada830b76577e3f46d0d1cbbbacd7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ctef2py/f90_getgauss/getgauss.f90", "max_forks_repo_name": "tomerten/ctef2py", "max_forks_repo_head_hexsha": "190b83819e0ada830b76577e3f46d0d1cbbbacd7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.1590909091, "max_line_length": 113, "alphanum_fraction": 0.4876250658, "num_tokens": 455, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.8479677545357569, "lm_q1q2_score": 0.7788416301115716}} {"text": " FUNCTION expint(n,x)\r\n INTEGER n,MAXIT\r\n REAL expint,x,EPS,FPMIN,EULER\r\n PARAMETER (MAXIT=100,EPS=1.e-7,FPMIN=1.e-30,EULER=.5772156649)\r\n INTEGER i,ii,nm1\r\n REAL a,b,c,d,del,fact,h,psi\r\n nm1=n-1\r\n if(n.lt.0.or.x.lt.0..or.(x.eq.0..and.(n.eq.0.or.n.eq.1)))then\r\n pause 'bad arguments in expint'\r\n else if(n.eq.0)then\r\n expint=exp(-x)/x\r\n else if(x.eq.0.)then\r\n expint=1./nm1\r\n else if(x.gt.1.)then\r\n b=x+n\r\n c=1./FPMIN\r\n d=1./b\r\n h=d\r\n do 11 i=1,MAXIT\r\n a=-i*(nm1+i)\r\n b=b+2.\r\n d=1./(a*d+b)\r\n c=b+a/c\r\n del=c*d\r\n h=h*del\r\n if(abs(del-1.).lt.EPS)then\r\n expint=h*exp(-x)\r\n return\r\n endif\r\n11 continue\r\n pause 'continued fraction failed in expint'\r\n else\r\n if(nm1.ne.0)then\r\n expint=1./nm1\r\n else\r\n expint=-log(x)-EULER\r\n endif\r\n fact=1.\r\n do 13 i=1,MAXIT\r\n fact=-fact*x/i\r\n if(i.ne.nm1)then\r\n del=-fact/(i-nm1)\r\n else\r\n psi=-EULER\r\n do 12 ii=1,nm1\r\n psi=psi+1./ii\r\n12 continue\r\n del=fact*(-log(x)+psi)\r\n endif\r\n expint=expint+del\r\n if(abs(del).lt.abs(expint)*EPS) return\r\n13 continue\r\n pause 'series failed in expint'\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "c55002b1568e96a5b4225f8e6bb87f22ef102000", "size": 1461, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/expint.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/expint.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/expint.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.6315789474, "max_line_length": 69, "alphanum_fraction": 0.4455852156, "num_tokens": 471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191271831559, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7788071966118577}} {"text": "real function pnorm(x,mean,sd)\n! This function calculates the area of the tail left to x \n! of the Gaussian curve with mean and sd\nimplicit none\nreal, intent(in) :: x, mean, sd\nreal :: x_\nreal, parameter :: inv_sqrt2 = 1d0/sqrt(2d0)\n\nx_ = (x-mean)/sd\npnorm = 0.5*(1d0+erf(x_*inv_sqrt2))\nreturn\nend function pnorm\n\n", "meta": {"hexsha": "30d5350b73558c0fcec9cc0d49eef40aca0776d1", "size": 330, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "DRAM/src/pnorm.f90", "max_stars_repo_name": "BingzhangChen/NPZDFeCONT", "max_stars_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "DRAM/src/pnorm.f90", "max_issues_repo_name": "BingzhangChen/NPZDFeCONT", "max_issues_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DRAM/src/pnorm.f90", "max_forks_repo_name": "BingzhangChen/NPZDFeCONT", "max_forks_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5714285714, "max_line_length": 58, "alphanum_fraction": 0.6787878788, "num_tokens": 110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9553191297273499, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.778807187964711}} {"text": "!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n!\n SUBROUTINE plag_coeff(npoi,nder,x,xp,coef)\n !\n ! npoi - number of points (determines the order of Lagrange\n ! polynomial\n ! which is equal npoi-1)\n ! nder - number of derivatives computed 0 - function only, 1 - first\n ! derivative\n ! x - actual point where function and derivatives are evaluated\n ! xp(npoi) - array of points where function is known\n ! coef(0:nder,npoi) - weights for computation of function and\n ! derivatives,\n ! f=sum(fun(1:npoi)*coef(0,1:npoi) gives the function value\n ! df=sum(fun(1:npoi)*coef(1,1:npoi) gives the derivative value value\n !\n !\n INTEGER, INTENT(in) :: npoi,nder\n double precision, INTENT(in) :: x\n double precision, DIMENSION(npoi), INTENT(in) :: xp\n double precision, DIMENSION(0:nder,npoi), INTENT(out) :: coef\n double precision, DIMENSION(:), ALLOCATABLE :: dummy\n !\n INTEGER :: i,k,j\n double precision :: fac\n !\n DO i=1,npoi\n coef(0,i)=1.d0\n DO k=1,npoi\n IF(k.EQ.i) CYCLE\n coef(0,i)=coef(0,i)*(x-xp(k))/(xp(i)-xp(k))\n ENDDO\n ENDDO\n !\n IF(nder.EQ.0) RETURN\n !\n ALLOCATE(dummy(npoi))\n !\n DO i=1,npoi\n dummy=1.d0\n dummy(i)=0.d0\n DO k=1,npoi\n IF(k.EQ.i) CYCLE\n fac=(x-xp(k))/(xp(i)-xp(k))\n DO j=1,npoi\n IF(j.EQ.k) THEN\n dummy(j)=dummy(j)/(xp(i)-xp(k))\n ELSE\n dummy(j)=dummy(j)*fac\n ENDIF\n ENDDO\n ENDDO\n coef(1,i)=SUM(dummy)\n ENDDO\n !\n DEALLOCATE(dummy)\n !\n RETURN\n END SUBROUTINE plag_coeff\n\n", "meta": {"hexsha": "1ec07913253459042102f5a471e5364e83690cad", "size": 1846, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SRC/plag_coeff.f90", "max_stars_repo_name": "Forsti5/GORILLA", "max_stars_repo_head_hexsha": "a28576e625a55b2c3adacf0dbb6806294f888e6f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-22T02:43:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-22T02:43:24.000Z", "max_issues_repo_path": "SRC/plag_coeff.f90", "max_issues_repo_name": "Forsti5/GORILLA", "max_issues_repo_head_hexsha": "a28576e625a55b2c3adacf0dbb6806294f888e6f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2019-10-25T07:52:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-16T13:19:04.000Z", "max_forks_repo_path": "SRC/plag_coeff.f90", "max_forks_repo_name": "Forsti5/GORILLA", "max_forks_repo_head_hexsha": "a28576e625a55b2c3adacf0dbb6806294f888e6f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-03-04T08:07:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T11:21:31.000Z", "avg_line_length": 30.262295082, "max_line_length": 80, "alphanum_fraction": 0.5297941495, "num_tokens": 535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672955, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7787449660421514}} {"text": "PROGRAM mbernoa\n \n! Code converted using TO_F90 by Alan Miller\n! Date: 2004-06-28 Time: 12:58:09\n\n! ===========================================================\n! Purpose: This program computes Bernoulli number Bn using\n! subroutine BERNOA\n! Example: Compute Bernouli number Bn for n = 0,1,...,10\n! Computed results:\n\n! n Bn\n! --------------------------\n! 0 .100000000000D+01\n! 1 -.500000000000D+00\n! 2 .166666666667D+00\n! 4 -.333333333333D-01\n! 6 .238095238095D-01\n! 8 -.333333333333D-01\n! 10 .757575757576D-01\n! ===========================================================\n\nDOUBLE PRECISION :: b\nDIMENSION b(0:200)\nWRITE(*,*)' Please enter Nmax'\n! READ(*,*)N\nn=10\nCALL bernoa(n,b)\nWRITE(*,*)' n Bn'\nWRITE(*,*)' --------------------------'\nWRITE(*,20)0,b(0)\nWRITE(*,20)1,b(1)\nDO k=2,n,2\n WRITE(*,20)k,b(k)\nEND DO\n20 FORMAT(2X,i3,d22.12)\nEND PROGRAM mbernoa\n\n\nSUBROUTINE bernoa(n,bn)\n\n! ======================================\n! Purpose: Compute Bernoulli number Bn\n! Input : n --- Serial number\n! Output: BN(n) --- Bn\n! ======================================\n\n\nINTEGER, INTENT(IN) :: n\nDOUBLE PRECISION, INTENT(OUT) :: bn(0:n)\nIMPLICIT DOUBLE PRECISION (a-h,o-z)\n\n\nbn(0)=1.0D0\nbn(1)=-0.5D0\nDO m=2,n\n s=-(1.0D0/(m+1.0D0)-0.5D0)\n DO k=2,m-1\n r=1.0D0\n DO j=2,k\n r=r*(j+m-k)/j\n END DO\n s=s-r*bn(k)\n END DO\n bn(m)=s\nEND DO\nDO m=3,n,2\n bn(m)=0.0D0\nEND DO\nRETURN\nEND SUBROUTINE bernoa\n", "meta": {"hexsha": "d54b5f1a033934120a98a915a1f7f497ee1f3d04", "size": 1744, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MATLAB/f2matlab/comp_spec_func/mbernoa.f90", "max_stars_repo_name": "vasaantk/bin", "max_stars_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATLAB/f2matlab/comp_spec_func/mbernoa.f90", "max_issues_repo_name": "vasaantk/bin", "max_issues_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATLAB/f2matlab/comp_spec_func/mbernoa.f90", "max_forks_repo_name": "vasaantk/bin", "max_forks_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.2222222222, "max_line_length": 67, "alphanum_fraction": 0.4220183486, "num_tokens": 563, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047847, "lm_q2_score": 0.8688267779364222, "lm_q1q2_score": 0.7786871951484392}} {"text": "! In program name, - is not allowed\n!works till 100938872634753805466563377840038871040\n! Commenting out of the reasonable bounds for calculation\nprogram prime_check\n character(len=10) :: argument\n Character(26) :: low = 'abcdefghijklmnopqrstuvwxyz'\n Character(26) :: cap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'\n integer :: check_capital_letters, check_small_letters, i, decimal_check, even_check, remainder, flag_prime\n integer(kind = 16):: number\n ! Anything not equal to single argument, Print Error\n IF(COMMAND_ARGUMENT_COUNT().NE.1)THEN\n write(*,'(g0.8)')\"Usage: please input a non-negative integer\"\n STOP\n ENDIF\n \n CALL GET_COMMAND_ARGUMENT(1,argument)\n if (argument == \"\") then\n write(*,'(g0.8)')\"Usage: please input a non-negative integer\"\n STOP\n endif\n ! Scan for letters\n check_capital_letters = scan(argument, cap)\n check_small_letters = scan(argument, low)\n decimal_check = scan(argument, '.')\n ! If capital letters exist, print error\n if (check_capital_letters > 0) then\n write(*,'(g0.8)')\"Usage: please input a non-negative integer\"\n STOP\n endif\n ! If small letters exist, print error\n if (check_small_letters > 0) then\n write(*,'(g0.8)')\"Usage: please input a non-negative integer\"\n STOP\n endif\n\n ! Decimal Check\n if (decimal_check > 0) then\n write(*,'(g0.8)')\"Usage: please input a non-negative integer\"\n STOP\n endif\n ! read the cmd line arg into number\n read (argument, '(I10)') number\n\n ! negative number\n if (number < 0) then\n write(*,'(g0.8)')\"Usage: please input a non-negative integer\"\n STOP\n endif\n\n ! ! Maximum Limit\n ! if (number > 100938872634753805466563377840038871040) then\n ! write(*,'(g0.8)')\"Input is out of the reasonable bounds for calculation\"\n ! STOP\n ! endif\n\n ! 2 is Prime\n if (number == 2) then\n write(*,'(g0.8)')\"Prime\"\n STOP\n endif\n ! 0, 1 and even numbers are Even\n even_check = modulo(number, 2)\n if ((number == 0) .or. (number == 1) .or. ( even_check == 0 )) then\n write(*,'(g0.8)')\"Composite\"\n STOP\n endif\n ! Check Prime\n max = number / 2\n flag_prime = 1\n do i = 3, max\n remainder = modulo(number, i)\n if (remainder == 0) then\n flag_prime = 0\n exit\n end if\n end do\n\n if(flag_prime == 1) then\n write(*,'(g0.8)') \"Prime\"\n else \n write(*,'(g0.8)') \"Composite\"\n end if\nend program\n", "meta": {"hexsha": "5366b09b05d833d7f2fc66031a1bb5eb03320320", "size": 2340, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "archive/f/fortran/prime-number.f95", "max_stars_repo_name": "Sagarchoudhary14/sample-programs", "max_stars_repo_head_hexsha": "32d8165d39ef9663f9e0db7e3df4d34d16922628", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 422, "max_stars_repo_stars_event_min_datetime": "2018-08-14T11:57:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T23:54:34.000Z", "max_issues_repo_path": "archive/f/fortran/prime-number.f95", "max_issues_repo_name": "shivamkchoudhary/sample-programs", "max_issues_repo_head_hexsha": "72c4db68481a72cc0cb4992a93575df540f147b0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1498, "max_issues_repo_issues_event_min_datetime": "2018-08-10T19:18:52.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-14T03:02:00.000Z", "max_forks_repo_path": "archive/f/fortran/prime-number.f95", "max_forks_repo_name": "shivamkchoudhary/sample-programs", "max_forks_repo_head_hexsha": "72c4db68481a72cc0cb4992a93575df540f147b0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 713, "max_forks_repo_forks_event_min_datetime": "2018-08-12T21:37:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-02T22:57:21.000Z", "avg_line_length": 27.8571428571, "max_line_length": 108, "alphanum_fraction": 0.6641025641, "num_tokens": 723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912913, "lm_q2_score": 0.8688267728417087, "lm_q1q2_score": 0.7786871833593096}} {"text": "module surfaces\n\n use vector_class, only : vector\n use constants, only : wp\n\n implicit none\n\n private\n public :: intersect_sphere, intersect_cylinder, intersect_ellipse, intersect_cone\n public :: reflect_refract\n\n contains\n\n logical function intersect_sphere(orig, dir, t, centre, radius)\n ! calculates where a line, with origin:orig and direction:dir hits a sphere, centre:centre and radius:radius\n ! returns true if intersection exists\n ! returns t, the paramertised parameter of the line equation\n ! adapted from scratchapixel\n \n implicit none\n\n type(vector), intent(IN) :: dir, orig, centre\n real(kind=wp), intent(OUT) :: t\n real(kind=wp), intent(IN) :: radius\n\n type(vector) :: L\n real(kind=wp) :: t0, t1, a, b, c, tmp\n\n intersect_sphere = .false.\n\n L = orig - centre\n a = dir .dot. dir\n b = 2._wp * (dir .dot. L)\n c = (l .dot. l) - radius**2\n\n if(.not. solveQuadratic(a, b, c, t0, t1))return\n if(t0 > t1)then\n tmp = t1\n t1 = t0\n t0 = tmp\n end if\n if(t0 < 0._wp)then\n t0 = t1\n if(t0 < 0._wp)return\n end if\n\n t = t0\n intersect_sphere = .true.\n return\n\n end function intersect_sphere\n\n logical function intersect_cylinder(orig, dir, t, centre, radius)\n ! calculates where a line, with origin:orig and direction:dir hits a cylinder, centre:centre and radius:radius\n ! returns true if intersection exists\n ! returns t, the paramertised parameter of the line equation\n ! adapted from scratchapixel\n ! need to check z height after moving ray\n ! if not this is an infinte cylinder\n ! cylinder lies length ways along z-axis\n \n implicit none\n\n type(vector), intent(IN) :: dir, orig, centre\n real(kind=wp), intent(OUT) :: t\n real(kind=wp), intent(IN) :: radius\n\n type(vector) :: L\n real(kind=wp) :: t0, t1, a, b, c, tmp\n\n intersect_cylinder = .false.\n\n L = orig - centre\n a = dir%z**2 + dir%y**2\n b = 2._wp * (dir%z * L%z + dir%y * L%y)\n c = L%z**2 + L%y**2 - radius**2\n\n if(.not. solveQuadratic(a, b, c, t0, t1))return\n if(t0 > t1)then\n tmp = t1\n t1 = t0\n t0 = tmp\n end if\n if(t0 < 0._wp)then\n t0 = t1\n if(t0 < 0._wp)return\n end if\n\n t = t0\n intersect_cylinder = .true.\n return\n end function intersect_cylinder\n\n\n logical function intersect_ellipse(orig, dir, t, centre, semia, semib)\n ! calculates where a line, with origin:orig and direction:dir hits a ellipse, centre:centre and axii:semia, semib\n ! returns true if intersection exists\n ! returns t, the paramertised parameter of the line equation\n ! adapted from scratchapixel and pbrt\n ! need to check z height after moving ray\n ! if not this is an infinte ellipse-cylinder\n ! ellipse lies length ways along z-axis\n ! semia and semib are the semimajor axis which are the half width and height.\n \n implicit none\n\n type(vector), intent(IN) :: dir, orig, centre\n real(kind=wp), intent(OUT) :: t\n real(kind=wp), intent(IN) :: semia, semib\n\n type(vector) :: L\n real(kind=wp) :: t0, t1, a, b, c, tmp, semia2div, semib2div\n\n intersect_ellipse = .false.\n\n semia2div = 1._wp / semia**2\n semib2div = 1._wp / semib**2\n\n L = orig - centre\n a = semia2div * dir%z**2 + semib2div * dir%y**2\n b = 2._wp * (semia2div * dir%z * L%z + semib2div * dir%y * L%y)\n c = semia2div * L%z**2 + semib2div * L%y**2 - 1._wp\n\n if(.not. solveQuadratic(a, b, c, t0, t1))return\n if(t0 > t1)then\n tmp = t1\n t1 = t0\n t0 = tmp\n end if\n if(t0 < 0._wp)then\n t0 = t1\n if(t0 < 0._wp)return\n end if\n\n t = t0\n intersect_ellipse = .true.\n return\n end function intersect_ellipse\n\n\n logical function intersect_cone(orig, dir, t, centre, radius, height)\n ! calculates where a line, with origin:orig and direction:dir hits a cone, radius:radius and height:height with centre:centre.\n ! centre is the point under the apex at the cone's base.\n ! returns true if intersection exists\n ! returns t, the paramertised parameter of the line equation\n ! adapted from scratchapixel and pbrt\n ! need to check z height after moving ray\n ! if not this is an infinte cone\n ! cone lies height ways along z-axis\n\n implicit none\n\n type(vector), intent(IN) :: orig, dir, centre\n real(kind=wp), intent(IN) :: radius, height\n real(kind=wp), intent(OUT) :: t\n\n type(vector) :: L\n real(kind=wp) :: t0, t1, a, b, c, tmp, k\n\n\n intersect_cone = .false.\n k = radius / height\n k = k**2\n\n L = orig - centre\n a = dir%x**2 + dir%y**2 - (k*dir%z**2)\n b = 2._wp*((dir%x * L%x) + (dir%y * L%y) - (k*dir%z * (L%z - height)))\n c = L%x**2 + L%y**2 - (k*(L%z - height)**2)\n\n if(.not. solveQuadratic(a, b, c, t0, t1))return\n if(t0 > t1)then\n tmp = t1\n t1 = t0\n t0 = tmp\n end if\n if(t0 < 0._wp)then\n t0 = t1\n if(t0 < 0._wp)return\n end if\n\n t = t0\n\n intersect_cone = .true.\n return\n\n end function intersect_cone\n\n\n logical function solveQuadratic(a, b, c, x0, x1)\n ! solves quadratic equation given coeffs a, b, and c\n ! returns true if real soln\n ! returns x0 and x1\n ! adapted from scratchapixel\n\n implicit none\n\n real(kind=wp), intent(IN) :: a, b, c\n real(kind=wp), intent(OUT) :: x0, x1\n\n real(kind=wp) :: discrim, q\n\n solveQuadratic = .false.\n\n discrim = b**2 - 4._wp * a * c\n if(discrim < 0._wp)then\n return\n elseif(discrim == 0._wp)then\n x0 = -0.5_wp*b/a\n x1 = x0\n else\n if(b > 0._wp)then\n q = -0.5_wp * (b + sqrt(discrim))\n else\n q = -0.5_wp * (b - sqrt(discrim))\n end if\n x0 = q / a\n x1 = c / q\n end if\n solveQuadratic = .true.\n return\n\n end function solveQuadratic\n\n\n\n subroutine reflect_refract(I, N, n1, n2, rflag)\n ! wrapper routine for fresnel calculation\n !\n !\n use random, only : ran2\n use vector_class\n\n implicit none\n\n type(vector), intent(INOUT) :: I !incident vector\n type(vector), intent(INOUT) :: N ! normal vector\n real(kind=wp), intent(IN) :: n1, n2 !refractive indcies\n logical, intent(OUT) :: rflag !reflection flag\n\n rflag = .FALSE.\n\n !draw random number, if less than fresnel coefficents, then reflect, else refract\n if(ran2() <= fresnel(I, N, n1, n2))then\n call reflect(I, N)\n rflag = .true.\n else\n call refract(I, N, n1/n2)\n end if\n\n end subroutine reflect_refract\n\n\n subroutine reflect(I, N)\n ! get vector of reflected photon\n !\n !\n use vector_class\n\n implicit none\n\n type(vector), intent(INOUT) :: I ! incident vector\n type(vector), intent(IN) :: N ! normal vector\n\n type(vector) :: R\n\n R = I - 2._wp * (N .dot. I) * N\n I = R\n\n end subroutine reflect\n\n\n subroutine refract(I, N, eta)\n ! get vector of refracted photon\n !\n !\n use vector_class\n\n implicit none\n\n type(vector), intent(INOUT) :: I\n type(vector), intent(IN) :: N\n real(kind=wp), intent(IN) :: eta\n\n type(vector) :: T, Ntmp\n real(kind=wp) :: c1, c2\n\n Ntmp = N\n\n c1 = (Ntmp .dot. I)\n if(c1 < 0._wp)then\n c1 = -c1\n else\n Ntmp = (-1._wp) * N\n end if\n c2 = sqrt(1._wp - (eta)**2 * (1._wp-c1**2))\n\n T = eta*I + (eta * c1 - c2) * Ntmp \n\n I = T\n\n end subroutine refract\n\n\n function fresnel(I, N, n1, n2) result (tir)\n ! calculates the fresnel coefficents\n !\n !\n use vector_class\n use ieee_arithmetic, only : ieee_is_nan\n\n implicit none\n\n real(kind=wp), intent(IN) :: n1, n2\n type(vector), intent(IN) :: I, N\n\n real(kind=wp) :: costt, sintt, sint2, cost2, tir, f1, f2\n\n costt = abs(I .dot. N)\n\n sintt = sqrt(1._wp - costt * costt)\n sint2 = n1/n2 * sintt\n if(sint2 > 1._wp)then\n tir = 1.0_wp\n return\n elseif(costt == 1._wp)then\n tir = 0._wp\n return\n else\n sint2 = (n1/n2)*sintt\n cost2 = sqrt(1._wp - sint2 * sint2)\n f1 = abs((n1*costt - n2*cost2) / (n1*costt + n2*cost2))**2\n f2 = abs((n1*cost2 - n2*costt) / (n1*cost2 + n2*costt))**2\n\n tir = 0.5_wp * (f1 + f2)\n if(ieee_is_nan(tir) .or. tir > 1._wp .or. tir < 0._wp)print*,'TIR: ', tir, f1, f2, costt,sintt,cost2,sint2\n return\n end if\n end function fresnel\nend module surfaces", "meta": {"hexsha": "ed4281f584eec21ed32ef04b8572d88f9987371e", "size": 9233, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/surfaces.f90", "max_stars_repo_name": "lewisfish/signedMCRT", "max_stars_repo_head_hexsha": "16f728b68c5a487eb791ca4ce839ede89188b16f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-16T13:03:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-16T13:03:55.000Z", "max_issues_repo_path": "src/surfaces.f90", "max_issues_repo_name": "lewisfish/signedMCRT", "max_issues_repo_head_hexsha": "16f728b68c5a487eb791ca4ce839ede89188b16f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/surfaces.f90", "max_forks_repo_name": "lewisfish/signedMCRT", "max_forks_repo_head_hexsha": "16f728b68c5a487eb791ca4ce839ede89188b16f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.2359882006, "max_line_length": 130, "alphanum_fraction": 0.5365536662, "num_tokens": 2819, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122672782973, "lm_q2_score": 0.8128673087708698, "lm_q1q2_score": 0.7786555667411116}} {"text": "program problem76\n implicit none\n integer :: i\n integer, dimension(100) :: memo\n\n ! https://oeis.org/A000041\n do i=1,100\n memo(i)=-1\n end do\n memo(1:10)=(/ 1, 2, 3, 5, 7, 11, 15, 22, 30, 42 /)\n \n print *, partitions(100)-1\n\ncontains\n\n pure function plus_minus(n)\n implicit none\n integer, intent(in) :: n\n integer :: plus_minus\n\n plus_minus=(-1)**((n-1)/2)\n \n end function plus_minus\n\n ! https://oeis.org/A001318\n pure function pentagonal(n)\n implicit none\n integer, intent(in) :: n\n integer :: pentagonal,m\n\n if (mod(n,2)==1) then\n m=1\n else\n m=-1\n end if\n m=m*(n+1)/2\n pentagonal=m*(3*m-1)/2\n\n end function pentagonal\n\n ! https://en.wikipedia.org/wiki/Partition_(number_theory)#Generating_function\n recursive function partitions(n) result(r)\n implicit none\n integer, intent(in) :: n\n integer :: r,i\n\n if (n<0) then\n r=0\n return\n else if (n==0) then\n r=1\n return\n else if (memo(n)>-1) then\n r=memo(n)\n return\n else\n r=0\n i=1\n do while (pentagonal(i)<=n)\n r=r+plus_minus(i)*partitions(n-pentagonal(i))\n ! print *,r,i,plus_minus(i),pentagonal(i),partitions(n-pentagonal(i))\n i=i+1\n end do\n memo(n)=r\n return\n end if\n\n end function partitions\n\nend program problem76\n", "meta": {"hexsha": "a40d1c24b555c855bc6ef0197b1f133ef13140da", "size": 1394, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem76.f08", "max_stars_repo_name": "jamesmcclain/Dioskouroi", "max_stars_repo_head_hexsha": "e433cbf7a1306d2755723f1028a4a3034da9d64a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "problem76.f08", "max_issues_repo_name": "jamesmcclain/Dioskouroi", "max_issues_repo_head_hexsha": "e433cbf7a1306d2755723f1028a4a3034da9d64a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "problem76.f08", "max_forks_repo_name": "jamesmcclain/Dioskouroi", "max_forks_repo_head_hexsha": "e433cbf7a1306d2755723f1028a4a3034da9d64a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.6338028169, "max_line_length": 79, "alphanum_fraction": 0.5602582496, "num_tokens": 445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947455, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7786544698629256}} {"text": "SUBROUTINE coord_r2sph (r , phi,lamda,radius)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: coord_r2sph.f90\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Geocentric spherical coordinates\r\n! Computation of the (geocentric) spherical coordinates i.e. longitude\r\n! and latitude, from position vector components (Cartesian coordinates)\r\n! ----------------------------------------------------------------------\r\n! Input arguments:\r\n! - r:\t\t\t\tPosition vector r = [x y z]\r\n!\r\n! Output arguments:\r\n! - phi:\t\t\tLatitude (radians)\r\n! - lamda:\t\t\tLongitude (radians)\r\n! ----------------------------------------------------------------------\r\n! Dr. Thomas Papanikolaou, Geoscience Australia July 2015\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n USE mdl_precision\r\n IMPLICIT NONE\r\n\r\n! ---------------------------------------------------------------------------\r\n! Dummy arguments declaration\r\n! ---------------------------------------------------------------------------\r\n REAL (KIND = prec_q), INTENT(IN), DIMENSION(3) :: r\r\n REAL (KIND = prec_q), INTENT(OUT) :: phi,lamda,radius\r\n! ---------------------------------------------------------------------------\r\n\r\n! ---------------------------------------------------------------------------\r\n! Local variables declaration\r\n! ---------------------------------------------------------------------------\r\n REAL (KIND = prec_q) :: x,y,z\r\n! ---------------------------------------------------------------------------\r\n\r\n! ---------------------------------------------------------------------------\r\n x = r(1)\r\n y = r(2)\r\n z = r(3)\r\n\r\n radius = sqrt(x**2 + y**2 + z**2)\r\n\r\n! Phi computation: analytical\r\n phi = atan( z / sqrt(x**2 + y**2) )\r\n\r\n! Lamda computation\r\n CALL arctan (y,x, lamda)\r\n! ---------------------------------------------------------------------------\r\n\r\nEND\r\n", "meta": {"hexsha": "711f4382d60e5e238dbe9eda89ba6768637053fc", "size": 2007, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/coord_r2sph.f90", "max_stars_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_stars_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2021-07-08T23:35:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:17:58.000Z", "max_issues_repo_path": "src/fortran/coord_r2sph.f90", "max_issues_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_issues_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-09-27T14:27:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T23:50:02.000Z", "max_forks_repo_path": "src/fortran/coord_r2sph.f90", "max_forks_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_forks_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2021-07-12T05:42:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T15:15:34.000Z", "avg_line_length": 37.1666666667, "max_line_length": 78, "alphanum_fraction": 0.3054309915, "num_tokens": 345, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693674025231, "lm_q2_score": 0.8198933293122507, "lm_q1q2_score": 0.7786275793855136}} {"text": " subroutine wwdiv(ar, ai, br, bi, cr, ci, ierr)\n*\n* PURPOSE\n* complex division algorithm : compute c := a / b\n* where :\n* \n* a = ar + i ai\n* b = br + i bi\n* c = cr + i ci\n*\n* inputs : ar, ai, br, bi (double precision)\n* outputs : cr, ci (double precision)\n* ierr (integer) ierr = 1 if b = 0 (else 0)\n*\n* IMPLEMENTATION NOTES\n* 1/ Use scaling with ||b||_oo; the original wwdiv.f used a scaling\n* with ||b||_1. It results fewer operations. From the famous\n* Golberg paper. This is known as Smith's method.\n* 2/ Currently set c = NaN + i NaN in case of a division by 0 ;\n* is that the good choice ?\n*\n* AUTHOR\n* Bruno Pincon \n*\n implicit none\n \n* PARAMETERS\n double precision ar, ai, br, bi, cr, ci\n integer ierr\n\n* LOCAL VARIABLES\n double precision r, d\n\n* TEXT\n ierr = 0\n\n* Treat special cases\n if (bi .eq. 0d0) then\n if (br .eq. 0d0) then\n ierr = 1\n* got NaN + i NaN\n cr = bi / br\n ci = cr\n else\n cr = ar / br\n ci = ai / br\n endif\n elseif (br .eq. 0d0) then\n cr = ai / bi\n ci = (-ar) / bi\n else\n* Generic division algorithm\n if (abs(br) .ge. abs(bi)) then\n r = bi / br\n d = br + r*bi\n cr = (ar + ai*r) / d\n ci = (ai - ar*r) / d\n else\n r = br / bi\n d = bi + r*br\n cr = (ar*r + ai) / d\n ci = (ai*r - ar) / d\n endif\n endif\n \n end\n\n\n", "meta": {"hexsha": "b2a3a5eeed7b274709b4afe8cccf14b639f9bc32", "size": 1711, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/calelm/wwdiv.f", "max_stars_repo_name": "alpgodev/numx", "max_stars_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-07-25T20:28:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-10T18:52:08.000Z", "max_issues_repo_path": "src/math/calelm/wwdiv.f", "max_issues_repo_name": "alpgodev/numx", "max_issues_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/math/calelm/wwdiv.f", "max_forks_repo_name": "alpgodev/numx", "max_forks_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.7971014493, "max_line_length": 74, "alphanum_fraction": 0.4430157802, "num_tokens": 514, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693645535724, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7786275791393574}} {"text": "!================================================================================\n! ActII es un codigo para colocar particulas sobre una recta alternando entre po-\n! sitvo y negativo segun la particula es par o impar.\n! Autor: Martin Alejandro Paredes Sosa\n!================================================================================\nProgram ActII\n Implicit None\n Real *4 :: sep, pos, neg, l\n Integer :: N, i !Numero de particulas , Contador\n\n !Datos de Entrada\n Write(*,*) \"Ingrese el numero de puntos\"\n Read(*,*) N\n Write(*,*) \"Ingrese la longitud dode poner los puntos\"\n Read(*,*) l\n \n !Separación entre partículas\n sep = l/real(N)\n\t\n Open(1, file=\"Out.dat\") !Abrir Archivo de Salida\n\n\n\n i=1 !Inicio Contador de la particula\n do while (i<=N) !Terminar al recorer cada particula\n pos=((-1)**i)*((int((i-1)/2)*sep)+ (sep/2) )!Calculo de Posicion\n write(1,*)i, pos !Escribir Valor En Archivo 1 (Out.dat)\n i = i+1 !Avance contador\n\n end do\n close(1)\n\nEnd Program ActII\n\n\n!======================================================================\n!============== EXTRAS / INTENTOS DIFERENTES ==========================\n!======================================================================\n \n !INTENTO DE COLOCAR UNA PARTICULA CENTRAL !! NO SE LOGRO\n !i=1\n !do while (i<=N)\n ! pos=((-1)**i)*((int((i-1-mod(N,2))/2)*sep)+ (sep*mod(N,2)/2) )\n ! write(*,*)i, pos\n ! i = i+1\n !end do\n\n !PRIMER INTENTO SE LOGRO REDUCIR \n !Incio de Contador\n !i=1\n !neg = (sep*(-1)) / 2 !Primera Posicion negativa\n !write(*,*) i,neg\n !i=i+1\n !pos = sep / 2 !Primera Posision positiva\n !write(*,*) i,pos \n !do while (i<=N-1)\n ! i = i + 1\n ! neg = neg - sep !Calculo de los puntos del lado negativo (impares) Posicion\n ! write(*,*) i,neg\n ! if (i==N) exit !Salida de Emergencia para N impar\n ! i = i + 1\n ! pos = pos + sep !Calculo de los puntos del lado positivo (pares) Posicion\n ! write(*,*) i,pos \n !end do\n\n", "meta": {"hexsha": "8632580c0f13467044ea31653ed8b39f164ca2a9", "size": 2077, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Portafolio_I/Tarea_I/Act_2/Act2.f03", "max_stars_repo_name": "maps16/DesExpII", "max_stars_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Portafolio_I/Tarea_I/Act_2/Act2.f03", "max_issues_repo_name": "maps16/DesExpII", "max_issues_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Portafolio_I/Tarea_I/Act_2/Act2.f03", "max_forks_repo_name": "maps16/DesExpII", "max_forks_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.4696969697, "max_line_length": 87, "alphanum_fraction": 0.4790563312, "num_tokens": 635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216356, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7785178458874983}} {"text": "program matrix_products\n\nimplicit none\n\ninterface\n\tsubroutine mat_mul_1(mat_a,mat_b,mat_c)\n\t\treal*8, intent(out):: mat_c(:,:)\n\t\treal*8, intent(in):: mat_a(:,:), mat_b(:,:)\n\tend subroutine\nend interface\n\ninterface\n\tsubroutine mat_mul_2(mat_a,mat_b,mat_c)\n\t\treal*8, intent(out):: mat_c(:,:)\n\t\treal*8, intent(in):: mat_a(:,:), mat_b(:,:)\n\tend subroutine\nend interface\n\nreal*8, allocatable :: A(:,:), B(:,:), C(:,:), D(:,:), E(:,:)\ninteger*4 :: iterations, max_N, ii, jj\nreal*4 :: start, finish\nreal*4, allocatable :: timing(:,:)\n\nwrite(*,*) \"Enter the timing iterations and up to how many rows the test matrices should have\"\nread(*,*) iterations, max_N\n\n! Allocate the timing array\nallocate(timing(2:max_N,0:3))\n\n! Generating two square random matrices, from 2 x 2 to max_N x max_n\ndo ii = 2, max_N\n\t! \"input size\"\n\ttiming(ii,0) = ii\n\n\t! Allocate all the matrices using the new size\n\tallocate(A(1:ii,1:ii))\n\tallocate(B(1:ii,1:ii))\n\tallocate(D(1:ii,1:ii))\n\tallocate(E(1:ii,1:ii))\n\tallocate(C(1:ii,1:ii))\n\n\t! Populate the arrays with uniformly distributed values\n\tcall random_number(A)\n\tcall random_number(B)\n\n\n\t!----------------------\n\t! Timing products\n\t!----------------------\n\t! Measuring performance of the first product definition\n\tcall cpu_time(start)\n\tdo jj = 1, iterations\n\t\tcall mat_mul_1(A,B,C)\n\tend do\n\tcall cpu_time(finish)\n\ttiming(ii,1) = (finish-start)/iterations\n\n\t! Measuring performance of the second product definition\n\t! Transposing and storing before entering the timing loop\n\tD = transpose(B)\n\tE = transpose(A)\n\tcall cpu_time(start)\n\tdo jj = 1, iterations\n\t\tcall mat_mul_2(D,E,C) ! This gives us C transpose\n\tend do\n\tcall cpu_time(finish)\n\ttiming(ii,2) = (finish-start)/iterations\n\n\t! Measuring performance of built-in product definition\n\tcall cpu_time(start)\n\tdo jj = 1, iterations\n\t\tC = matmul(A,B)\n\tend do\n\tcall cpu_time(finish)\n\ttiming(ii,3) = (finish-start)/iterations\n\n\t! Release the variables for the incoming allocation\n\tdeallocate(A)\n\tdeallocate(B)\n\tdeallocate(D)\n\tdeallocate(E)\n\tdeallocate(C)\nend do\n\nopen(15,file = \"performance.dat\")\n! Write the performance measurements\ndo ii = 2, max_N\n\twrite(15,*) timing(ii,0:3)\nend do\nclose(15)\n\nend program matrix_products\n\n\nsubroutine mat_mul_1(mat_a,mat_b,mat_c)\n\timplicit none\n\treal*8, intent(in):: mat_a(:,:), mat_b(:,:)\n\treal*8, intent(out) :: mat_c(:,:)\n\tinteger*4:: M,N,O,P,ii,jj,kk\n\treal*8:: cumulative\n\tinteger*4:: shape_a(2), shape_b(2)\n\t\n\tshape_a = shape(mat_a)\n\tshape_b = shape(mat_b)\n\tM = shape_a(1)\n\tN = shape_a(2)\n\tO = shape_b(1)\n\tP = shape_b(2)\n\t\n\tdo ii = 1,M\n\t\tdo jj = 1, P\n\t\t\tcumulative = 0.d0\n\t\t\tdo kk = 1, N\n\t\t\t\tcumulative = cumulative + mat_a(ii,kk)*mat_b(kk,jj)\n\t\t\tend do\n\t\t\tmat_c(ii,jj) = cumulative\n\t\tend do\n\tend do\n\t\nend subroutine\n\t\n\nsubroutine mat_mul_2(mat_a,mat_b, mat_c)\n\timplicit none\n\treal*8, intent(in):: mat_a(:,:), mat_b(:,:)\n\treal*8, intent(out) :: mat_c(:,:)\n\tinteger*4:: M,N,O,P,ii,jj,kk\n\treal*8:: cumulative\n\tinteger*4:: shape_a(2), shape_b(2)\n\t\n\tshape_a = shape(mat_a)\n\tshape_b = shape(mat_b)\n\tM = shape_a(1)\n\tN = shape_a(2)\n\tO = shape_b(1)\n\tP = shape_b(2)\n\t\n\tdo jj = 1,P\n\t\tdo ii = 1, M\n\t\t\tcumulative = 0.d0\n\t\t\tdo kk = 1, N\n\t\t\t\tcumulative = cumulative + mat_a(ii,kk)*mat_b(kk,jj)\n\t\t\tend do\n\t\t\tmat_c(ii,jj) = cumulative\n\t\tend do\n\tend do\n\t\nend subroutine\n\t\n\n", "meta": {"hexsha": "b3080c9bc87a6d7629c941ac6451c7268ebcf129", "size": 3266, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "week_1/performance/products.f90", "max_stars_repo_name": "eigen-carmona/quantum-computation-unipd", "max_stars_repo_head_hexsha": "f53b40bd83cb85119ce4b494e10e01b256917659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-01-11T19:41:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-05T19:22:24.000Z", "max_issues_repo_path": "week_1/performance/products.f90", "max_issues_repo_name": "eigen-carmona/quantum-computation-unipd", "max_issues_repo_head_hexsha": "f53b40bd83cb85119ce4b494e10e01b256917659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week_1/performance/products.f90", "max_forks_repo_name": "eigen-carmona/quantum-computation-unipd", "max_forks_repo_head_hexsha": "f53b40bd83cb85119ce4b494e10e01b256917659", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.6291390728, "max_line_length": 94, "alphanum_fraction": 0.6671769749, "num_tokens": 1063, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.88720460564669, "lm_q2_score": 0.8774767810736693, "lm_q1q2_score": 0.7785014415165917}} {"text": "module mod_inv\n#include \n use mod_kinds, only: rk,ik,rdouble,rsingle\n use mod_constants, only: ONE\n use mod_determinant, only: det_3x3\n\n implicit none\n ! External procedures defined in LAPACK\n external DGETRI\n external DGETRF\n external DGECON\n external DLANGE\n external SGETRI\n external SGETRF\n external SGECON\n external SLANGE\n real(rdouble) :: DLANGE\n real(rsingle) :: SLANGE\n\ncontains\n\n !> Compute and return the inverse of a 3x3 matrix.\n !!\n !! This implements an explicit formula for inverting a 3x3 matrix.\n !! See: http://mathworld.wolfram.com/MatrixInverse.html \n !!\n !! @author Nathan A. Wukie (AFRL)\n !! @date 8/14/2017\n !!\n !---------------------------------------------------------------------------\n function inv_3x3(A) result(Ainv)\n real(rk), intent(in) :: A(3,3)\n\n real(rk) :: Ainv(3,3), det\n\n det = det_3x3(A)\n\n Ainv(1,1) = ONE/det * (A(2,2)*A(3,3) - A(2,3)*A(3,2))\n Ainv(1,2) = ONE/det * (A(1,3)*A(3,2) - A(1,2)*A(3,3))\n Ainv(1,3) = ONE/det * (A(1,2)*A(2,3) - A(1,3)*A(2,2))\n\n Ainv(2,1) = ONE/det * (A(2,3)*A(3,1) - A(2,1)*A(3,3))\n Ainv(2,2) = ONE/det * (A(1,1)*A(3,3) - A(1,3)*A(3,1))\n Ainv(2,3) = ONE/det * (A(1,3)*A(2,1) - A(1,1)*A(2,3))\n\n Ainv(3,1) = ONE/det * (A(2,1)*A(3,2) - A(2,2)*A(3,1))\n Ainv(3,2) = ONE/det * (A(1,2)*A(3,1) - A(1,1)*A(3,2))\n Ainv(3,3) = ONE/det * (A(1,1)*A(2,2) - A(1,2)*A(2,1))\n\n\n end function inv_3x3\n !***************************************************************************\n\n\n\n\n !> Returns the inverse of a matrix calculated by finding the LU\n !! decomposition. Depends on LAPACK.\n !!\n !!\n !!\n !!\n !!\n !---------------------------------------------------------------------------\n function inv(A) result(Ainv)\n real(rk), dimension(:,:), intent(inout) :: A\n real(rk), dimension(size(A,1),size(A,2)) :: Ainv\n\n real(rk), dimension(size(A,1)) :: work ! work array for LAPACK\n integer, dimension(size(A,1)) :: ipiv ! pivot indices\n integer :: n, info\n\n\n\n ! Store A in Ainv to prevent it from being overwritten by LAPACK\n Ainv = A\n n = size(A,1)\n\n\n !\n ! DGETRF computes an LU factorization of a general M-by-N matrix A\n ! using partial pivoting with row interchanges.\n !\n if ( rk == rdouble ) then\n call DGETRF(n, n, Ainv, n, ipiv, info)\n else if ( rk == rsingle ) then\n call SGETRF(n, n, Ainv, n, ipiv, info)\n else\n call chidg_signal(FATAL,\"inv: Invalid selected precision for matrix inversion.\")\n end if\n\n if (info /= 0) then\n call chidg_signal(FATAL,\"inv: Matrix is numerically singular!\")\n end if\n\n\n\n !\n ! DGETRI computes the inverse of a matrix using the LU factorization\n ! computed by DGETRF.\n !\n if ( rk == rdouble ) then\n call DGETRI(n, Ainv, n, ipiv, work, n, info)\n else if ( rk == rsingle ) then\n call SGETRI(n, Ainv, n, ipiv, work, n, info)\n else\n call chidg_signal(FATAL,\"inv: Invalid selected precision for matrix inversion.\")\n end if\n\n\n\n if (info /= 0) then\n call chidg_signal(FATAL,\"inv: matrix inversion failed!.\")\n end if\n\n end function inv\n !**************************************************************************************\n\nend module mod_inv\n", "meta": {"hexsha": "1c2682cf4e792b2dd94416338d06cdaf71694a89", "size": 3579, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical_methods/mod_inv.f90", "max_stars_repo_name": "wanglican/ChiDG", "max_stars_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-07T11:24:04.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-07T11:24:04.000Z", "max_issues_repo_path": "src/numerical_methods/mod_inv.f90", "max_issues_repo_name": "haohb/ChiDG", "max_issues_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/numerical_methods/mod_inv.f90", "max_forks_repo_name": "haohb/ChiDG", "max_forks_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-27T17:12:32.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-27T17:12:32.000Z", "avg_line_length": 29.825, "max_line_length": 92, "alphanum_fraction": 0.487845767, "num_tokens": 1128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768635777511, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.778437879857854}} {"text": "\tFUNCTION PR_TMFK ( tmpf )\nC************************************************************************\nC* PR_TMFK\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes TMPK from TMPF. The following equation is\t*\nC* used:\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* TMPK = ( TMPF - 32 ) * 5 / 9 + TMCK\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_TMFK ( TMPF )\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tTMPF\t\tREAL\t\tTemperature in Fahrenheit\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_TMFK\t\tREAL\t\tTemperature in Kelvin\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. Goodman/RDS\t 8/84\tOriginal source\t\t\t\t*\nC* I. Graffman/RDS\t12/84\tModified equation\t\t\t*\nC* M. desJardins/GSFC\t 4/86\tAdded PARAMETER statement\t\t*\nC* I. Graffman/RDS\t12/87\tGEMPAK4\t\t\t\t\t*\nC* G. Huffman/GSC\t 8/88\tModified documentation\t\t\t*\nC* G. Krueger/EAI 4/96 Replaced C->K constant with TMCK\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tIF ( ERMISS ( tmpf ) ) THEN\n\t PR_TMFK = RMISSD\n\t ELSE\n\t tmpc = PR_TMFC ( tmpf )\n\t PR_TMFK = PR_TMCK ( tmpc )\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "2ddb9ac57f4d9fc25797cef665a522a1ed512707", "size": 1213, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prtmfk.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/prmcnvlib/pr/prtmfk.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/prmcnvlib/pr/prtmfk.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 31.9210526316, "max_line_length": 73, "alphanum_fraction": 0.4509480627, "num_tokens": 382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768651485395, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7784378709720271}} {"text": "subroutine allencahn_fort_rhs(blockno, mbc,mx,my,meqn,mfields, & \n xlower,ylower,dx,dy,dt, method,q,rhs)\n IMPLICIT NONE\n\n INTEGER mbc,mx,my, mfields, meqn, method\n DOUBLE PRECISION xlower,ylower,dx,dy, dt\n DOUBLE PRECISION rhs(1-mbc:mx+mbc,1-mbc:my+mbc,mfields) \n DOUBLE PRECISION q(1-mbc:mx+mbc,1-mbc:my+mbc,meqn)\n\n INTEGER i,j, blockno\n DOUBLE PRECISION lambda, D, u\n\n lambda = -1.d0/dt\n\n D = 0.001d0\n\n do j = 1,my\n do i = 1,mx\n u = q(i,j,1)\n rhs(i,j,1) = lambda*u - (u-u**3)/D**2\n end do\n end do\n\nend subroutine allencahn_fort_rhs\n\n\nsubroutine allencahn_update_q(mbc,mx,my,meqn,mfields,rhs,q)\n IMPLICIT NONE\n\n INTEGER mbc,mx,my, mfields, meqn\n DOUBLE PRECISION rhs(1-mbc:mx+mbc,1-mbc:my+mbc,mfields) \n DOUBLE PRECISION q(1-mbc:mx+mbc,1-mbc:my+mbc,meqn)\n\n INTEGER i,j\n\n do j = 1-mbc,my+mbc\n do i = 1-mbc,mx+mbc\n q(i,j,1) = rhs(i,j,1)\n end do\n end do\n!!100 format(2F16.8)\n\nend subroutine allencahn_update_q\n\n", "meta": {"hexsha": "949b90b6ccba1b09c862729230a6875cea769cbe", "size": 1054, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/elliptic/allencahn/fortran/allencahn_fort_rhs.f90", "max_stars_repo_name": "ForestClaw/ForestClaw", "max_stars_repo_head_hexsha": "c81095f3e525f99cfb771c9049e9d272eb12d4cb", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "applications/elliptic/allencahn/fortran/allencahn_fort_rhs.f90", "max_issues_repo_name": "ForestClaw/ForestClaw", "max_issues_repo_head_hexsha": "c81095f3e525f99cfb771c9049e9d272eb12d4cb", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-08-02T09:52:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-02T14:16:23.000Z", "max_forks_repo_path": "applications/elliptic/allencahn/fortran/allencahn_fort_rhs.f90", "max_forks_repo_name": "ForestClaw/ForestClaw", "max_forks_repo_head_hexsha": "c81095f3e525f99cfb771c9049e9d272eb12d4cb", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.4222222222, "max_line_length": 65, "alphanum_fraction": 0.6043643264, "num_tokens": 407, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765140114859, "lm_q2_score": 0.8519528019683106, "lm_q1q2_score": 0.7784092662047237}} {"text": "subroutine matgen(imat, a, n, info)\n implicit none\n\n real(kind(1.d0)), allocatable :: a(:,:)\n integer :: imat, n, info\n\n real(kind(1.d0)), allocatable :: work(:), d(:)\n character(len=3) :: path\n character :: type, dist\n integer :: kl, ku, mode\n real(kind(1.d0)) :: anorm, cndnum, rcondc\n integer :: iseed(4)\n real(kind(1.d0)), parameter :: done=1.d0, dmone=-1.d0\n \n !ehouarn\n integer :: i,j\n double precision :: eps, norme_f\n intrinsic epsilon \n !ehouarn\n \n iseed = (/1988, 1989, 1990, 1991/)\n info = 0\n path(1:1) = 'Double precision'\n path(2:3) = 'GE'\n\n select case(imat)\n case(1:11)\n call dlatb4( path, imat, n, n, type, kl, ku, anorm, mode, cndnum, dist )\n rcondc = 1.d0 / cndnum\n \n write(*,'(\"=======================\")')\n ! write(*,'(\"Type : \",a1)')type\n ! write(*,'(\"KL : \",i4)')kl\n ! write(*,'(\"KL : \",i4)')ku\n write(*,'(\"Anorm : \",es10.3)')anorm\n write(*,'(\"Cond : \",es10.3)')cndnum\n write(*,'(\" \")')\n \n allocate(a(n,n), work(3*n), d(n), stat=info)\n if(info .ne. 0) return\n \n call dlatms( n, n, dist, iseed, type, &\n & d, mode, cndnum, anorm, kl, ku, &\n & 'no packing', a, n, work, info )\n if(info .ne. 0) return\n \n deallocate(d, work, stat=info)\n case(12)\n !write(*,'(\"Generate matrix with bad determinant\")')\n !info = 1 ! to remove when the generator is implemented \n write(*,'(\"Generate numerically singular matrix \")')\n call dlatb4( path, 8, n, n, type, kl, ku, anorm, mode, cndnum, dist )\n rcondc = 1.d0 / cndnum\n \n write(*,'(\"=======================\")')\n ! write(*,'(\"Type : \",a1)')type\n ! write(*,'(\"KL : \",i4)')kl\n ! write(*,'(\"KL : \",i4)')ku\n write(*,'(\"Anorm : \",es10.3)')anorm\n write(*,'(\"Cond : \",es10.3)')cndnum\n write(*,'(\" \")')\n \n allocate(a(n,n), work(3*n), d(n), stat=info)\n if(info .ne. 0) return\n \n call dlatms( n, n, dist, iseed, type, &\n & d, mode, cndnum, anorm, kl, ku, &\n & 'no packing', a, n, work, info )\n if(info .ne. 0) return\n \n deallocate(d, work, stat=info)\n \n eps=epsilon(eps)\n a(:,1)=eps*a(:,1)\n if(n.gt.5)then\n i=(n+1)/2\n a(:,i)=eps*a(:,i)\n endif\n a(:,n)=eps*a(:,n)\n \n case default\n write(*,'(\"Wrong matrix id\")')\n info = 1\n end select\n\n\n return\nend subroutine matgen\n \n", "meta": {"hexsha": "246844fb03a2c23dc47a67d8717ea609bdc94679", "size": 2422, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "1A/S6/Calcul_scientifique/TPs/TP2/tlin/lib/matgen.f90", "max_stars_repo_name": "MOUDDENEHamza/ENSEEIHT", "max_stars_repo_head_hexsha": "a90b1dee0c8d18a9578153a357278d99405bb534", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-05-02T12:32:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-12T20:20:35.000Z", "max_issues_repo_path": "Calcul_Scientifique/TP2/tlin/lib/matgen.f90", "max_issues_repo_name": "Hathoute/ENSEEIHT", "max_issues_repo_head_hexsha": "d42f0b0dedb269e6df3b1c006d4d45e52fc518b8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-01-14T20:03:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-30T01:10:00.000Z", "max_forks_repo_path": "Calcul_Scientifique/TP2/tlin/lib/matgen.f90", "max_forks_repo_name": "Hathoute/ENSEEIHT", "max_forks_repo_head_hexsha": "d42f0b0dedb269e6df3b1c006d4d45e52fc518b8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-11-11T21:28:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-19T13:54:22.000Z", "avg_line_length": 26.9111111111, "max_line_length": 77, "alphanum_fraction": 0.4938067713, "num_tokens": 866, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593496, "lm_q2_score": 0.8670357718273068, "lm_q1q2_score": 0.778333920965728}} {"text": "C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC * *\nC * copyright (c) 1999 by UCAR *\nC * *\nC * UNIVERSITY CORPORATION for ATMOSPHERIC RESEARCH *\nC * *\nC * all rights reserved *\nC * *\nC * FISHPACK version 4.1 *\nC * *\nC * A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE SOLUTION OF *\nC * *\nC * SEPARABLE ELLIPTIC PARTIAL DIFFERENTIAL EQUATIONS *\nC * *\nC * BY *\nC * *\nC * JOHN ADAMS, PAUL SWARZTRAUBER AND ROLAND SWEET *\nC * *\nC * OF *\nC * *\nC * THE NATIONAL CENTER FOR ATMOSPHERIC RESEARCH *\nC * *\nC * BOULDER, COLORADO (80307) U.S.A. *\nC * *\nC * WHICH IS SPONSORED BY *\nC * *\nC * THE NATIONAL SCIENCE FOUNDATION *\nC * *\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC PROGRAM TO ILLUSTRATE THE USE OF SUBROUTINE POISTG TO\nC SOLVE THE EQUATION\nC\nC (1/COS(X))(D/DX)(COS(X)(DU/DX)) + (D/DY)(DU/DY) =\nC\nC 2*Y**2*(6-Y**2)*SIN(X)\nC\nC ON THE RECTANGLE -PI/2 .LT. X .LT. PI/2 AND\nC 0 .LT. Y .LT. 1 WITH THE BOUNDARY CONDITIONS\nC\nC (DU/DX) (-PI/2,Y) = (DU/DX)(PI/2,Y) = 0 , 0 .LE. Y .LE. 1 (2)\nC\nC U(X,0) = 0 (3)\nC -PI/2 .LE. X .LE. PI/2\nC (DU/DY)(X,1) = 4SIN(X) (4)\nC\nC USING FINITE DIFFERENCES ON A STAGGERED GRID WITH\nC DELTAX (= DX) = PI/40 AND DELTAY (= DY) = 1/20 .\nC TO SET UP THE FINITE DIFFERENCE EQUATIONS WE DEFINE\nC THE GRID POINTS\nC\nC X(I) = -PI/2 + (I-0.5)DX I=1,2,...,40\nC\nC Y(J) = (J-O.5)DY J=1,2,...,20\nC\nC AND LET V(I,J) BE AN APPROXIMATION TO U(X(I),Y(J)).\nC NUMBERING THE GRID POINTS IN THIS FASHION GIVES THE SET\nC OF UNKNOWNS AS V(I,J) FOR I=1,2,...,40 AND J=1,2,...,20.\nC HENCE, IN THE PROGRAM M = 40 AND N = 20. AT THE INTERIOR\nC GRID POINT (X(I),Y(J)), WE REPLACE ALL DERIVATIVES IN\nC EQUATION (1) BY SECOND ORDER CENTRAL FINITE DIFFERENCES,\nC MULTIPLY BY DY**2, AND COLLECT COEFFICIENTS OF V(I,J) TO\nC GET THE FINITE DIFFERENCE EQUATION\nC\nC A(I)V(I-1,J) + B(I)V(I,J) + C(I)V(I+1,J)\nC\nC + V(I,J-1) - 2V(I,J) + V(I,J+1) = F(I,J) (5)\nC\nC WHERE S = (DY/DX)**2, AND FOR I=2,3,...,39\nC\nC A(I) = S*COS(X(I)-DX/2)\nC\nC B(I) = -S*(COS(X(I)-DX/2)+COS(X(I)+DX/2))\nC\nC C(I) = S*COS(X(I)+DX/2)\nC\nC F(I,J) = 2DY**2*Y(J)**2*(6-Y(J)**2)*SIN(X(I)) , J=1,2,...,19.\nC\nC TO OBTAIN EQUATIONS FOR I = 1, WE REPLACE EQUATION (2)\nC BY THE SECOND ORDER APPROXIMATION\nC\nC (V(1,J)-V(0,J))/DX = 0\nC\nC AND USE THIS EQUATION TO ELIMINATE V(0,J) IN EQUATION (5)\nC TO ARRIVE AT THE EQUATION\nC\nC B(1)V(1,J) + C(1)V(2,J) + V(1,J-1) - 2V(1,J) + V(1,J+1)\nC\nC = F(1,J)\nC\nC WHERE\nC\nC B(1) = -S*(COS(X(1)-DX/2)+COS(X(1)+DX/2))\nC\nC C(1) = -B(1)\nC\nC FOR COMPLETENESS, WE SET A(1) = 0.\nC TO OBTAIN EQUATIONS FOR I = 40, WE REPLACE THE DERIVATIVE\nC IN EQUATION (2) AT X=PI/2 IN A SIMILAR FASHION, USE THIS\nC EQUATION TO ELIMINATE THE VIRTUAL UNKNOWN V(41,J) IN EQUATION\nC (5) AND ARRIVE AT THE EQUATION\nC\nC A(40)V(39,J) + B(40)V(40,J)\nC\nC + V(40,J-1) - 2V(40,J) + V(40,J+1) = F(40,J)\nC\nC WHERE\nC\nC A(40) = -B(40) = -S*(COS(X(40)-DX/2)+COS(X(40)+DX/2))\nC\nC FOR COMPLETENESS, WE SET C(40) = 0. HENCE, IN THE\nC PROGRAM MPEROD = 1.\nC FOR J = 1, WE REPLACE EQUATION (3) BY THE SECOND ORDER\nC APPROXIMATION\nC\nC (V(I,0) + V(I,1))/2 = 0\nC\nC TO ARRIVE AT THE CONDITION\nC\nC V(I,0) = -V(I,1) .\nC\nC FOR J = 20, WE REPLACE EQUATION (4) BY THE SECOND ORDER\nC APPROXIMATION\nC\nC (V(I,21) - V(I,20))/DY = 4*SIN(X)\nC\nC AND COMBINE THIS EQUATION WITH EQUATION (5) TO ARRIVE AT\nC THE EQUATION\nC\nC A(I)V(I-1,20) + B(I)V(I,20) + C(I)V(I+1,20)\nC\nC + V(I,19) - 2V(I,20) + V(I,21) = F(I,20)\nC\nC WHERE\nC\nC V(I,21) = V(I,20) AND\nC\nC F(I,20) = 2*DY**2*Y(J)**2*(6-Y(J)**2)*SIN(X(I)) - 4*DY*SIN(X(I))\nC\nC HENCE, IN THE PROGRAM NPEROD = 2 .\nC THE EXACT SOLUTION TO THIS PROBLEM IS\nC\nC U(X,Y) = Y**4*COS(X) .\nC\n DIMENSION F(42,20) ,A(40) ,B(40) ,C(40) ,\n 1 W(600) ,X(40) ,Y(20)\nC\nC FROM DIMENSION STATEMENT WE GET VALUE OF IDIMF = 42. ALSO\nC NOTE THAT W HAS BEEN DIMENSIONED\nC 9M + 4N + M(INT(LOG2(N))) = 360 + 80 + 160 = 600 .\nC\n IDIMF = 42\n MPEROD = 1\n M = 40\n PI = PIMACH(DUM)\n DX = PI/FLOAT(M)\n NPEROD = 2\n N = 20\n DY = 1./FLOAT(N)\nC\nC GENERATE AND STORE GRID POINTS FOR COMPUTATION.\nC\n DO 101 I=1,M\n X(I) = -PI/2.+(FLOAT(I)-0.5)*DX\n 101 CONTINUE\n DO 102 J=1,N\n Y(J) = (FLOAT(J)-0.5)*DY\n 102 CONTINUE\nC\nC GENERATE COEFFICIENTS .\nC\n S = (DY/DX)**2\n A(1) = 0.\n B(1) = -S*COS(-PI/2.+DX)/COS(X(1))\n C(1) = -B(1)\n DO 103 I=2,M\n A(I) = S*COS(X(I)-DX/2.)/COS(X(I))\n C(I) = S*COS(X(I)+DX/2.)/COS(X(I))\n B(I) = -(A(I)+C(I))\n 103 CONTINUE\n A(40) = -B(40)\n C(40) = 0.\nC\nC GENERATE RIGHT SIDE OF EQUATION.\nC\n DO 105 I=1,M\n DO 104 J=1,N\n F(I,J) = 2.*DY**2*Y(J)**2*(6.-Y(J)**2)*SIN(X(I))\n 104 CONTINUE\n 105 CONTINUE\n DO 106 I=1,M\n F(I,N) = F(I,N)-4.*DY*SIN(X(I))\n 106 CONTINUE\n CALL POISTG (NPEROD,N,MPEROD,M,A,B,C,IDIMF,F,IERROR,W)\nC\nC COMPUTE DISCRETIZATION ERROR. THE EXACT SOLUTION IS\nC\nC U(X,Y) = Y**4*SIN(X)\nC\n ERR = 0.\n DO 108 I=1,M\n DO 107 J=1,N\n T = ABS(F(I,J)-Y(J)**4*SIN(X(I)))\n IF (T .GT. ERR) ERR = T\n 107 CONTINUE\n 108 CONTINUE\n PRINT 1001 , IERROR,ERR,W(1)\n STOP\nC\n 1001 FORMAT (1H1,20X,25HSUBROUTINE POISTG EXAMPLE///\n 1 10X,46HTHE OUTPUT FROM THE NCAR CONTROL DATA 7600 WAS//\n 2 32X,10HIERROR = 0/\n 3 18X,34HDISCRETIZATION ERROR = 5.64171E-04/\n 4 12X,32HREQUIRED LENGTH OF W ARRAY = 560//\n 5 10X,32HTHE OUTPUT FROM YOUR COMPUTER IS//\n 6 32X,8HIERROR =,I2/18X,22HDISCRETIZATION ERROR =,E12.5/\n 7 12X,28HREQUIRED LENGTH OF W ARRAY =,F4.0)\nC\n END\n", "meta": {"hexsha": "0287df6a19803891fd9c3aa621e19c139a2d84d1", "size": 7519, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/test/tpoistg.f", "max_stars_repo_name": "ipelupessy/omuse", "max_stars_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2020-03-25T10:02:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T00:28:35.000Z", "max_issues_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/test/tpoistg.f", "max_issues_repo_name": "ipelupessy/omuse", "max_issues_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 45, "max_issues_repo_issues_event_min_datetime": "2020-03-03T16:07:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T09:01:07.000Z", "max_forks_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/test/tpoistg.f", "max_forks_repo_name": "ipelupessy/omuse", "max_forks_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-03-03T13:28:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T09:20:02.000Z", "avg_line_length": 34.1772727273, "max_line_length": 71, "alphanum_fraction": 0.4150817928, "num_tokens": 2680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.946596665680527, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7782814956972267}} {"text": " SUBROUTINE avevar(data,n,ave,var)\r\n INTEGER n\r\n REAL ave,var,data(n)\r\n INTEGER j\r\n REAL s,ep\r\n ave=0.0\r\n do 11 j=1,n\r\n ave=ave+data(j)\r\n11 continue\r\n ave=ave/n\r\n var=0.0\r\n ep=0.0\r\n do 12 j=1,n\r\n s=data(j)-ave\r\n ep=ep+s\r\n var=var+s*s\r\n12 continue\r\n var=(var-ep**2/n)/(n-1)\r\n return\r\n END\r\n", "meta": {"hexsha": "2de3e8cf18f9c0fdbc052afc7a4d059164f61622", "size": 393, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/avevar.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/avevar.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/avevar.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.7142857143, "max_line_length": 40, "alphanum_fraction": 0.4427480916, "num_tokens": 133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122213606241, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7782634896992664}} {"text": "C LAST UPDATE 10/12/92\nC+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nC\n SUBROUTINE SVDFIT(X,Y,SIG,NDATA,A,MA,U,V,W,MP,NP,CHISQ,FUNCS)\n IMPLICIT NONE\nC\nC Purpose: Performs linear least squares given a set of NDATA points\nC X(I),Y(I) with individual standard deviations SIG(I) to \nC determine the MA coefficients of A of the fitting function\nC y = sum j {Aj * AFUNCj(x)} by singular value decomposition.\nC of the NDATA by MA matrix. Arrays U,V,W provide workspace\nC on input, on output they define the singular value\nC decomposition and can be used to obtain the covariance\nC matrix. MP,NP are the physical dimensions of the matrices\nC U,V,W . It is necessary that MP>=NDATA, NP>=MA. The program \nC returns values for the MA fit parameters A and CHISQ.\nC The user supplied subroutine FUNCS(X,AFUNC,MA) returns the\nC MA basis functions evaluated at x = X in the array AFUNC.\nC\n INTEGER NDATA,MA,MP,NP\n REAL X(NDATA),Y(NDATA),SIG(NDATA)\n REAL A(MA),V(NP,NP),U(MP,NP),W(NP)\n REAL CHISQ\nC\nC Calls 2: SVDVAR , FUNCS\nC Called by: \nC\n EXTERNAL FUNCS\nC\nC-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\nC Local variables:\nC\n INTEGER NMAX,MMAX\n REAL TOL\n PARAMETER(NMAX=1000,MMAX=50,TOL=1.0E-05)\n REAL B(NMAX),AFUNC(MMAX)\n REAL THRESH,WMAX,SUM,TMP \n INTEGER I,J\nC\nC---------------------------------------------------------------------\n DO 20 I=1,NDATA\n CALL FUNCS(X(I),AFUNC,MA)\n TMP = 1.0/SIG(I)\n DO 10 J=1,MA\n U(I,J) = AFUNC(J)*TMP\n 10 CONTINUE\n B(I) = Y(I)*TMP\n 20 CONTINUE\n CALL SVDCMP(U,NDATA,MA,MP,NP,W,V)\n WMAX = 0.0\n DO 30 J=1,MA\n IF(W(J).GT.WMAX)WMAX = W(J)\n 30 CONTINUE\n THRESH = TOL*WMAX\n DO 40 J=1,MA\n IF(W(J).LT.THRESH)W(J) = 0.0\n 40 CONTINUE\n CALL SVBKSB(U,W,V,NDATA,MA,MP,NP,B,A)\n CHISQ = 0.0\n DO 60 I=1,NDATA\n CALL FUNCS(X(I),AFUNC,MA)\n SUM = 0.0\n DO 50 J=1,MA\n SUM = SUM + A(J)*AFUNC(J)\n 50 CONTINUE\n CHISQ = CHISQ + ((Y(I)-SUM)/SIG(I))**2\n 60 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "39c420668744fa4f27252a22bb2b3bb942cb13af", "size": 2265, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "software/libs/mlib/svdfit.f", "max_stars_repo_name": "scattering-central/CCP13", "max_stars_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "software/libs/mlib/svdfit.f", "max_issues_repo_name": "scattering-central/CCP13", "max_issues_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "software/libs/mlib/svdfit.f", "max_forks_repo_name": "scattering-central/CCP13", "max_forks_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-09-05T15:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T11:13:45.000Z", "avg_line_length": 32.3571428571, "max_line_length": 72, "alphanum_fraction": 0.5302428256, "num_tokens": 723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474194456936, "lm_q2_score": 0.8152324960856177, "lm_q1q2_score": 0.7782595986364065}} {"text": "program bisection_method\nimplicit none\n\nreal(kind=8) :: A, B, eps, root, maximum, minimum\ninteger :: iters\n\nwrite(*,*) 'number?'\nread(*,*) A\n\nB = abs(A) !in case it's a negative number\nif (B .ge. 1) then\n maximum = B\nelse if (B .lt. 1) then\n maximum = 1\nend if\nminimum = 0.0\n\neps = 0.00000000000001\niters = 0\ndo while (abs(B-root*root) .ge. eps)\n root = minimum + (maximum - minimum)/2.0d0\n iters = iters + 1\n write(*,*) iters, root, abs(B-root*root)\n if (root*root .gt. B) then\n maximum = root\n else if (root*root .lt. B) then\n minimum = root\n end if\nend do\n\nwrite(*,*) 'number of iterations:', iters\nif (A .ge. 0.0d0) then\n write(*,*) root\nelse\n write(*,*) root, 'i' ! because the result is imaginary for a negative A\nend if\n\nend program bisection_method\n", "meta": {"hexsha": "1dbeeda125089aa1b6b63c0a3115d9b39cfd7aa7", "size": 788, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "sqrt/bisection.f95", "max_stars_repo_name": "ElenaKusevska/Fortran_exercises", "max_stars_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sqrt/bisection.f95", "max_issues_repo_name": "ElenaKusevska/Fortran_exercises", "max_issues_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sqrt/bisection.f95", "max_forks_repo_name": "ElenaKusevska/Fortran_exercises", "max_forks_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.2051282051, "max_line_length": 74, "alphanum_fraction": 0.6307106599, "num_tokens": 289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.8354835411997898, "lm_q1q2_score": 0.7782215906373124}} {"text": "program main\n ! Default\n implicit none\n\n ! Parameters\n integer(8) :: targ = 600851475143\n\n ! Variables\n integer(8) :: i,max_fac,max_try\n\n ! Determine maximum value we should try\n max_try = int(sqrt(1D0*targ))\n\n max_fac = 1\n do i=2,max_try\n ! Check that i is a factor of the number\n if (mod(targ,i)==0) then\n ! Now check to see if i is prime\n if (is_prime(i)) then\n max_fac = i\n endif\n endif\n enddo\n\n ! Write out answer\n write(*,*) \"Max factor: \",max_fac\n\ncontains\n\n pure function is_prime(targ)\n ! Default\n implicit none\n\n ! Function arguments\n integer(8), intent(in) :: targ\n logical :: is_prime\n\n ! Local variables\n integer(8) :: i,max_try\n\n ! Find the max we should try\n max_try = int(sqrt(1D0*targ))\n\n do i=2,max_try\n if (mod(targ,i)==0) then\n is_prime = .false.\n return\n endif\n enddo\n\n is_prime = .true.\n return\n end function is_prime\n\nend program main\n", "meta": {"hexsha": "af525244af73b6f8bbcda6fd0e2fb46838627e92", "size": 1000, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/problem3/problem3.f90", "max_stars_repo_name": "plaplant/Project_Euler", "max_stars_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/problem3/problem3.f90", "max_issues_repo_name": "plaplant/Project_Euler", "max_issues_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/problem3/problem3.f90", "max_forks_repo_name": "plaplant/Project_Euler", "max_forks_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-01-07T21:43:45.000Z", "max_forks_repo_forks_event_max_datetime": "2017-01-07T21:43:45.000Z", "avg_line_length": 17.8571428571, "max_line_length": 45, "alphanum_fraction": 0.59, "num_tokens": 296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314624993576759, "lm_q2_score": 0.8354835289107307, "lm_q1q2_score": 0.7782215760113603}} {"text": " subroutine mapc2m_torus(blockno,xc,yc,xp,yp,zp,alpha, beta)\n implicit none\n\n integer blockno\n double precision xc,yc,xp,yp,zp\n double precision alpha, beta, r1, R\n\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n r1 = alpha*(1 + beta*sin(pi2*xc))\n R = 1 + r1*cos(pi2*yc)\n\n xp = R*cos(pi2*xc)\n yp = R*sin(pi2*xc)\n zp = r1*sin(pi2*yc)\n\n end\n\n", "meta": {"hexsha": "f1e080d4923c2dacddbad91de9023958355afacb", "size": 410, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/mappings/torus/mapc2m_torus.f", "max_stars_repo_name": "scivision/forestclaw", "max_stars_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/mappings/torus/mapc2m_torus.f", "max_issues_repo_name": "scivision/forestclaw", "max_issues_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mappings/torus/mapc2m_torus.f", "max_forks_repo_name": "scivision/forestclaw", "max_forks_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.5238095238, "max_line_length": 65, "alphanum_fraction": 0.5634146341, "num_tokens": 141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.951863227517834, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7782190838768313}} {"text": "module fit\n\nimplicit none\n\ncontains\n!----------------------------------------------------\nsubroutine linear_polynom_fit(n,x,y,p1,p2)\n\nimplicit none\ninteger, intent(in) :: n\ndouble precision, intent(in) :: x(n), y(n)\ndouble precision, intent(out) :: p1, p2\n!----------------------------------------------------\ndouble precision :: sumx, sumy, sumx2, sumxy\n\nsumx = 0.0d0\nsumy = 0.0d0\nsumx2 = 0.0d0\nsumxy = 0.0d0\n\nsumx = sum(x)\nsumy = sum(y)\nsumx2 = sum(x**2)\nsumxy = sum(x*y)\n\np1 = (n*sumxy - sumx*sumy)/(n*sumx2 - sumx**2)\np2 = (sumy - p1*sumx)/n\n\nend subroutine\n!----------------------------------------------------\nsubroutine quadr_polynom_fit(n,x,y,p1,p2,p3)\n\nimplicit none\ninteger, intent(in) :: n\ndouble precision, intent(in) :: x(n), y(n)\ndouble precision, intent(out) :: p1, p2, p3\n!----------------------------------------------------\ndouble precision :: S1,S2,S3,S4,Sy0,Sy1,Sy2\ndouble precision :: A(3,3),B(3)\ninteger :: info,lwork,ipiv(3)\ndouble precision :: work(3)\n!----------------------------------------------------\n\nA = 0.0d0\nB = 0.0d0\n\nS1 = 0.0d0\nS2 = 0.0d0\nS3 = 0.0d0\nS4 = 0.0d0\nSy0 = 0.0d0\nSy1 = 0.0d0\nSy2 = 0.0d0\n\nS1 = sum(x)\nS2 = sum(x*x)\nS3 = sum(x*x*x)\nS4 = sum(x*x*x*x)\n\nSy0 = sum(y)\nSy1 = sum(y*x)\nSy2 = sum(y*x*x)\n\nA(1,:) = (/S4, S3, S2/)\nA(2,:) = (/S3, S2, S1/)\nA(3,:) = (/S2, S1, dble(n)/)\n\nB(:) = (/Sy2, Sy1, Sy0/)\n\n! ==== Calculate inverse of matrix A ==== !\n\ncall dgetrf(3,3,A,3,ipiv,info)\nlwork = size(work)\ncall dgetri(3,A,3,ipiv,work,lwork,info)\n\np1 = dot_product(A(1,:),B)\np2 = dot_product(A(2,:),B)\np3 = dot_product(A(3,:),B)\n\nend subroutine\n!----------------------------------------------------\nsubroutine cubic_polynom_fit(n,x,y,p1,p2,p3,p4)\n\nimplicit none\ninteger, intent(in) :: n\ndouble precision, intent(in) :: x(n), y(n)\ndouble precision, intent(out) :: p1,p2,p3,p4\n!----------------------------------------------------\ndouble precision :: S1,S2,S3,S4,S5,S6\ndouble precision :: Sy0,Sy1,Sy2,Sy3\ndouble precision :: A(4,4),B(4)\ninteger :: info,lwork,ipiv(4)\ndouble precision :: work(4)\n!----------------------------------------------------\n\nA = 0.0d0\nB = 0.0d0\n\nS1 = sum(x)\nS2 = sum(x*x)\nS3 = sum(x*x*x)\nS4 = sum(x*x*x*x)\nS5 = sum(x*x*x*x*x)\nS6 = sum(x*x*x*x*x*x)\n\nSy0 = sum(y)\nSy1 = sum(y*x)\nSy2 = sum(y*x*x)\nSy3 = sum(y*x*x*x)\n\nA(1,:) = (/S6, S5, S4, S3/)\nA(2,:) = (/S5, S4, S3, S2/)\nA(3,:) = (/S4, S3, S2, S1/)\nA(4,:) = (/S3, S2, S1, dble(n)/)\n\nB(:) = (/Sy3, Sy2, Sy1, Sy0/)\n\n! ==== Calculate inverse of matrix A ==== !\n\ncall dgetrf(4,4,A,4,ipiv,info)\nlwork = size(work)\ncall dgetri(4,A,4,ipiv,work,lwork,info)\n\np1 = dot_product(A(1,:),B)\np2 = dot_product(A(2,:),B)\np3 = dot_product(A(3,:),B)\np4 = dot_product(A(4,:),B)\n \nend subroutine\n!----------------------------------------------------\nsubroutine quart_polynom_fit(n,x,y,p1,p2,p3,p4,p5)\n\nimplicit none\ninteger, intent(in) :: n\ndouble precision, intent(in) :: x(n), y(n)\ndouble precision, intent(out) :: p1,p2,p3,p4,p5\n!----------------------------------------------------\ndouble precision :: S1,S2,S3,S4,S5,S6\ndouble precision :: S7,S8,Sy0,Sy1,Sy2\ndouble precision :: Sy3,Sy4\ndouble precision :: A(5,5),B(5)\ninteger :: info,lwork,ipiv(5)\ndouble precision :: work(5)\n!----------------------------------------------------\n\nA = 0.0d0\nB = 0.0d0\n\nS1 = sum(x)\nS2 = sum(x*x)\nS3 = sum(x*x*x)\nS4 = sum(x*x*x*x)\nS5 = sum(x*x*x*x*x)\nS6 = sum(x*x*x*x*x*x)\nS7 = sum(x*x*x*x*x*x*x)\nS8 = sum(x*x*x*x*x*x*x*x)\n\nSy0 = sum(y)\nSy1 = sum(y*x)\nSy2 = sum(y*x*x)\nSy3 = sum(y*x*x*x)\nSy4 = sum(y*x*x*x*x)\n\nA(1,:) = (/S8, S7, S6, S5, S4/)\nA(2,:) = (/S7, S6, S5, S4, S3/)\nA(3,:) = (/S6, S5, S4, S3, S2/)\nA(4,:) = (/S5, S4, S3, S2, S1/)\nA(5,:) = (/S4, S3, S2, S1, dble(n)/)\n\nB(:) = (/Sy4, Sy3, Sy2, Sy1, Sy0/)\n\n! ==== Calculate inverse of matrix A ==== !\n\ncall dgetrf(5,5,A,5,ipiv,info)\nlwork = size(work)\ncall dgetri(5,A,5,ipiv,work,lwork,info)\n\np1 = dot_product(A(1,:),B)\np2 = dot_product(A(2,:),B)\np3 = dot_product(A(3,:),B)\np4 = dot_product(A(4,:),B)\np5 = dot_product(A(5,:),B)\n \n\nend subroutine\n!-------------------------\nend module\n", "meta": {"hexsha": "dd06c8b782363cc8c98d0c663fad4fd46fe8418e", "size": 4342, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tools/irc-fit/source/fit.f90", "max_stars_repo_name": "svarganov/NAST", "max_stars_repo_head_hexsha": "7e87c4aeec03f84a895f4e7cc270db807ce514c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tools/irc-fit/source/fit.f90", "max_issues_repo_name": "svarganov/NAST", "max_issues_repo_head_hexsha": "7e87c4aeec03f84a895f4e7cc270db807ce514c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-19T13:10:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-20T01:08:41.000Z", "max_forks_repo_path": "tools/irc-fit/source/fit.f90", "max_forks_repo_name": "svarganov/NAST", "max_forks_repo_head_hexsha": "7e87c4aeec03f84a895f4e7cc270db807ce514c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-14T00:11:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-14T00:11:42.000Z", "avg_line_length": 23.0957446809, "max_line_length": 59, "alphanum_fraction": 0.4698295716, "num_tokens": 1568, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037732, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7781867723806984}} {"text": "FUNCTION declination(idoy)\n!\nIMPLICIT NONE\n!\nINCLUDE 'p1unconv.inc'\n!\n! Function arguments\n!\nINTEGER :: idoy\nREAL :: declination\n!\n! Local variables\n!\nREAL :: b\n!\n! + + + purpose + + +\n! this function calculates the declination of the earth with respect\n! the sun based on the day of the year\n \n! + + + keywords + + +\n! solar declination\n \n! + + + argument declarations + + +\n \n! + + + argument definitions + + +\n! idoy - day of year\n \n! + + + local varaibles + + +\n \n! + + + local definitions + + +\n! b - sub calculation (time of year, radians)\n \n! + + + common blocks + + +\n \n! + + + end specifications + + +\n \n! calculate declination angle (dec)\n!\nb = (360.0/365.0)*(idoy-81.25)*degtorad \ndeclination = 23.45*sin(b) \n! \nEND FUNCTION declination\n", "meta": {"hexsha": "c17a246e03c09b2fc5866465aaa3735e551a8a60", "size": 903, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Project Documents/Source Code Original/Declination.f90", "max_stars_repo_name": "USDA-ARS-WMSRU/upgm-standalone", "max_stars_repo_head_hexsha": "1ae5dee5fe2cdba97b69c19d51b1cf61ceeab3d7", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Project Documents/Source Code Original/Declination.f90", "max_issues_repo_name": "USDA-ARS-WMSRU/upgm-standalone", "max_issues_repo_head_hexsha": "1ae5dee5fe2cdba97b69c19d51b1cf61ceeab3d7", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Project Documents/Source Code Original/Declination.f90", "max_forks_repo_name": "USDA-ARS-WMSRU/upgm-standalone", "max_forks_repo_head_hexsha": "1ae5dee5fe2cdba97b69c19d51b1cf61ceeab3d7", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.0, "max_line_length": 88, "alphanum_fraction": 0.5182724252, "num_tokens": 239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9658995742876885, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7781597816080863}} {"text": "module m_maths\n !! Math routines\n use variableKind\n use m_allocate, only: allocate\n use m_deallocate, only: deallocate\n use m_errors, only: eMsg, msg\n use m_sort, only: argsort\n use m_select, only: argSelect\n use m_array1D, only: arange\n use m_unitTester, only: tester\n implicit none\n\n private\n\n public :: crossproduct\n interface crossproduct\n !! Compute the cross product between two arrays of length 2 or 3\n module function crossproduct_r1D(a,b) result(res)\n !! Interfaced with crossproduct()\n real(r32),intent(in) :: a(3) !! 1D Array\n real(r32),intent(in) :: b(3) !! 1D Array\n real(r32) :: res(3) !! cross product\n end function\n module function crossproduct_d1D(a,b) result(res)\n !! Interfaced with crossproduct()\n real(r64),intent(in) :: a(3) !! 1D Array\n real(r64),intent(in) :: b(3) !! 1D Array\n real(r64) :: res(3) !! cross product\n end function\n end interface\n\n public :: cumprod\n interface cumprod\n !! Compute the variance of an array\n module function cumprod_r1D(this) result(res)\n !! Interfaced with cumprod()\n real(r32),intent(in) :: this(:) !! 1D array\n real(r32) :: res(size(this)) !! Cumulative product\n end function\n module function cumprod_d1D(this) result(res)\n !! Interfaced with cumprod()\n real(r64),intent(in) :: this(:) !! 1D array\n real(r64) :: res(size(this)) !! Cumulative product\n end function\n module function cumprod_i1D(this) result(res)\n !! Interfaced with cumprod()\n integer(i32),intent(in) :: this(:) !! 1D array\n integer(i32) :: res(size(this)) !! Cumulative product\n end function\n module function cumprod_id1D(this) result(res)\n !! Interfaced with cumprod()\n integer(i64),intent(in) :: this(:) !! 1D array\n integer(i64) :: res(size(this)) !! Cumulative product\n end function\n end interface\n\n public :: cumsum\n interface cumsum\n !! Compute the variance of an array\n module function cumsum_r1D(this) result(res)\n !! Interfaced with cumsum()\n real(r32),intent(in) :: this(:) !! 1D array\n real(r32) :: res(size(this)) !! Cumulative sum\n end function\n module function cumsum_d1D(this) result(res)\n !! Interfaced with cumsum()\n real(r64),intent(in) :: this(:) !! 1D array\n real(r64) :: res(size(this)) !! Cumulative sum\n end function\n module function cumsum_i1D(this) result(res)\n !! Interfaced with cumsum()\n integer(i32),intent(in) :: this(:) !! 1D array\n integer(i32) :: res(size(this)) !! Cumulative sum\n end function\n module function cumsum_id1D(this) result(res)\n !! Interfaced with cumsum()\n integer(i64),intent(in) :: this(:) !! 1D array\n integer(i64) :: res(size(this)) !! Cumulative sum\n end function\n end interface\n\n\n\n public :: geometricMean\n interface geometricMean\n !! Compute the geometric mean of a vector\n module function geometricMean_r1D(this) result(res)\n !! Interfaced with geometricMean()\n real(r32),intent(in) :: this(:)\n real(r64) :: res\n end function\n module function geometricMean_d1D(this) result(res)\n !! Interfaced with geometricMean()\n real(r64),intent(in) :: this(:)\n real(r64) :: res\n end function\n module function geometricMean_i1D(this) result(res)\n !! Interfaced with geometricMean()\n integer(i32),intent(in) :: this(:)\n real(r64) :: res\n end function\n module function geometricMean_id1D(this) result(res)\n !! Interfaced with geometricMean()\n integer(i64),intent(in) :: this(:)\n real(r64) :: res\n end function\n end interface\n\n public :: mean\n interface mean\n !! Compute the mean\n module function mean_r1D(this) result(res)\n !! Interfaced with mean()\n real(r32), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! mean\n end function\n module function mean_d1D(this) result(res)\n !! Interfaced with mean()\n real(r64), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! mean\n end function\n module function mean_i1D(this) result(res)\n !! Interfaced with mean()\n integer(i32), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! mean\n end function\n module function mean_id1D(this) result(res)\n !! Interfaced with mean()\n integer(i64), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! mean\n end function\n end interface\n\n public :: median\n interface median\n !! Compute the median of a set of numbers\n module function median_r1D(this) result(res)\n !! Interfaced with median()\n real(r32), intent(in) :: this(:) !! 1D array\n real(r32) :: res !! median\n end function\n module function median_d1D(this) result(res)\n !! Interfaced with median()\n real(r64), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! median\n end function\n module function median_i1D(this) result(res)\n !! Interfaced with median()\n integer(i32), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! median\n end function\n module function median_id1D(this) result(res)\n !! Interfaced with median()\n integer(i64), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! median\n end function\n end interface\n\n public :: norm1\n interface norm1\n !! Compute the L1 norm of a set of numbers\n module function norm1_r1D(this) result(res)\n !! Interfaced with norm1()\n real(r32), intent(in) :: this(:) !! 1D array\n real(r32) :: res !! L1 norm\n end function\n module function norm1_d1D(this) result(res)\n !! Interfaced with norm1()\n real(r64), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! L1 norm\n end function\n module function norm1_i1D(this) result(res)\n !! Interfaced with norm1()\n integer(i32), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! L1 norm\n end function\n module function norm1_id1D(this) result(res)\n !! Interfaced with norm1()\n integer(i64), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! L1 norm\n end function\n end interface\n\n public :: normI\n interface normI\n !! Compute the Linfinity norm of a set of numbers\n module function normI_r1D(this) result(res)\n !! Interfaced with normI()\n real(r32), intent(in) :: this(:) !! 1D array\n real(r32) :: res !! Linfinity norm\n end function\n module function normI_d1D(this) result(res)\n !! Interfaced with normI()\n real(r64), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! Linfinity norm\n end function\n module function normI_i1D(this) result(res)\n !! Interfaced with normI()\n integer(i32), intent(in) :: this(:) !! 1D array\n integer(i32) :: res !! Linfinity norm\n end function\n module function normI_id1D(this) result(res)\n !! Interfaced with normI()\n integer(i64), intent(in) :: this(:) !! 1D array\n integer(i64) :: res !! Linfinity norm\n end function\n end interface\n\n public :: project\n interface project\n !! Project a vector a onto vector b\n module function project_r1D(a,b) result(c)\n !! Interfaced with project()\n real(r32),intent(in) :: a(:) !! 1D array\n real(r32),intent(in) :: b(size(a)) !! 1D array\n real(r32) :: c(size(a)) !! 1D array\n end function\n module function project_d1D(a,b) result(c)\n !! Interfaced with project()\n real(r64),intent(in) :: a(:) !! 1D array\n real(r64),intent(in) :: b(size(a)) !! 1D array\n real(r64) :: c(size(a)) !! 1D array\n end function\n end interface\n\n public :: trimmedmean\n interface trimmedmean\n !! Compute the Trimmed mean of an array, alpha is a percent value to trim from either end\n module function trimmedmean_r1D(this,alpha) result(res)\n !! Interfaced with trimmedmean()\n real(r32), intent(in) :: this(:) !! 1D array\n real(r32), intent(in) :: alpha !! Percentage to trim off each end\n real(r64) :: res !! trimmedmean\n end function\n module function trimmedmean_d1D(this,alpha) result(res)\n !! Interfaced with trimmedmean()\n real(r64), intent(in) :: this(:) !! 1D array\n real(r64), intent(in) :: alpha !! Percentage to trim off each end\n real(r64) :: res !! trimmedmean\n end function\n module function trimmedmean_i1D(this,alpha) result(res)\n !! Interfaced with trimmedmean()\n integer(i32), intent(in) :: this(:) !! 1D array\n real(r64), intent(in) :: alpha !! Percentage to trim off each end\n real(r64) :: res !! trimmedmean\n end function\n module function trimmedmean_id1D(this,alpha) result(res)\n !! Interfaced with trimmedmean()\n integer(i64), intent(in) :: this(:) !! 1D array\n real(r64), intent(in) :: alpha !! Percentage to trim off each end\n real(r64) :: res !! trimmedmean\n end function\n end interface\n\n \n\n public :: std\n interface std\n !! Compute the standard deviation of an array\n module function std_r1D(this) result(res)\n !! Interfaced with std()\n real(r32), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! standard deviation\n end function\n module function std_d1D(this) result(res)\n !! Interfaced with std()\n real(r64), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! standard deviation\n end function\n module function std_i1D(this) result(res)\n !! Interfaced with std()\n integer(i32), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! standard deviation\n end function\n module function std_id1D(this) result(res)\n !! Interfaced with std()\n integer(i64), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! standard deviation\n end function\n end interface\n\n public :: variance\n interface variance\n !! Compute the variance of an array\n module function variance_r1D(this) result(res)\n !! Interfaced with variance()\n real(r32), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! variance\n end function\n module function variance_d1D(this) result(res)\n !! Interfaced with variance()\n real(r64), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! variance\n end function\n module function variance_i1D(this) result(res)\n !! Interfaced with variance()\n integer(i32), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! variance\n end function\n module function variance_id1D(this) result(res)\n !! Interfaced with variance()\n integer(i64), intent(in) :: this(:) !! 1D array\n real(r64) :: res !! variance\n end function\n end interface\nend module\n", "meta": {"hexsha": "3ec784b8c50e7a0b7d06b5e3617ef6adce0fba19", "size": 10587, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/maths/m_maths.f90", "max_stars_repo_name": "leonfoks/coretran", "max_stars_repo_head_hexsha": "bf998d4353badc91d3a12d23c78781c8377b9578", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 72, "max_stars_repo_stars_event_min_datetime": "2017-10-20T15:19:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T11:17:43.000Z", "max_issues_repo_path": "src/maths/m_maths.f90", "max_issues_repo_name": "leonfoks/coretran", "max_issues_repo_head_hexsha": "bf998d4353badc91d3a12d23c78781c8377b9578", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2017-10-20T15:54:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T09:45:01.000Z", "max_forks_repo_path": "src/maths/m_maths.f90", "max_forks_repo_name": "leonfoks/coretran", "max_forks_repo_head_hexsha": "bf998d4353badc91d3a12d23c78781c8377b9578", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-02-20T15:07:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-10T17:58:00.000Z", "avg_line_length": 34.4853420195, "max_line_length": 94, "alphanum_fraction": 0.6276565599, "num_tokens": 2960, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172688214138, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7780109450399506}} {"text": "c # -----------------------------------------------------\nc # GAUSSIAN_SUM\nc #\nc # Computes the value q at a point (x,y,z), where q\nc # is defined by the sum\nc #\nc # q = sum_{i=1,n} g(x,y,z;xi,yi,zi,a,hmax)\nc #\nc # g(x,y,z;xi,yi,zi,a,hmax) = hmax*exp(-a*r2)\nc #\nc # r2 = (x-xi)**2 + (y-yi)**2 + (z-zi)**2\nc #\nc # Note : 'td' means \"time dependent\"\nc # -----------------------------------------------------\n\n double precision function gaussian_sum(xp,yp,zp)\n implicit none\n\n double precision xp, yp, zp, q\n\n integer m, get_n_locations, n\n double precision w(3), qv, a, hmax\n double precision gaussian_flat, gaussian_sphere\n logical isflat\n\n n = get_n_locations()\n\nc # Get time dependent (td) parameters\n call get_td_gaussian_parms(a,hmax)\n\n q = 0\n do m = 1,n\n call get_td_gaussian_locations(m,w)\n if (isflat()) then\n qv = gaussian_flat(xp,yp,zp,w,a,hmax)\n else\n qv = gaussian_sphere(xp,yp,zp,w,a,hmax)\n endif\n q = q + qv\n enddo\n\n gaussian_sum = q\n\n end\n\n double precision function gaussian_flat(x,y,z,w,a,hmax)\n implicit none\n\n double precision x,y,z,w(3),q, a, r2, hmax\n\n r2 = (x-w(1))**2 + (y - w(2))**2 + (z - w(3))**2\n gaussian_flat = hmax*exp(-a*r2)\n\n end\n\n\n double precision function gaussian_sphere(x,y,z,w,a,hmax)\n implicit none\n\n double precision x,y,z,w(3),a,q, hmax\n\n double precision get_gc_distance, d\n\n d = get_gc_distance(x,y,z,w)\n q = hmax*exp(-a*d**2)\n\n gaussian_sphere = q\n\n end\n\n\n integer function get_n_locations()\n implicit none\n\n integer n_com\n common /comexp2/ n_com\n\n get_n_locations = n_com\n\n\n end\n\n subroutine set_n_locations(n)\n implicit none\n\n integer n\n\n integer n_com\n common /comexp2/ n_com\n\n n_com = n\n\n end\n\n\n subroutine set_initial_gaussian_locations(w,n)\n implicit none\n\n integer i, n, m\n double precision w(3,n)\n\n double precision wc_init_com(3,100), a_init_com, hmax_init_com\n common /comexpinit1/ wc_init_com, a_init_com, hmax_init_com\n\nc # Locations of initial exponentials\n if (n .gt. 100) then\n write(6,*) 'set_initial_gaussian_locations : n > 100'\n stop\n endif\n\n do i = 1,n\n do m = 1,3\n wc_init_com(m,i) = w(m,i)\n enddo\n enddo\n\n call set_n_locations(n)\n call set_td_gaussian_locations(w,n)\n\n end\n\n subroutine get_initial_gaussian_locations(i,w)\n implicit none\n\n integer i,m\n double precision w(3)\n\n double precision wc_init_com(3,100), a_init_com, hmax_init_com\n\n integer n, get_n_locations\n common /comexpinit1/ wc_init_com, a_init_com, hmax_init_com\n\n n = get_n_locations()\n\n if (i .gt. n) then\n write(6,*) 'get_initial_gaussian_locations : i .gt. n'\n stop\n endif\n\n do m = 1,3\n w(m) = wc_init_com(m,i)\n enddo\n\n end\n\n\nc # ------------------------------------------\nc # Set time dependent Gaussian parms\nc # ------------------------------------------\n subroutine set_td_gaussian_locations(w,n)\n implicit none\n\n integer i, n, m\n double precision w(3,n)\n\n double precision wc_td_com(3,100), a_td_com\n double precision hmax_td_com\n\n common /comexptd1/ wc_td_com, a_td_com, hmax_td_com\n\n if (n .gt. 100) then\n write(6,*) 'set_td_gaussian_locations : n > 100'\n stop\n endif\n\nc # Locations of initial exponentials\n do i = 1,n\n do m = 1,3\n wc_td_com(m,i) = w(m,i)\n enddo\n enddo\n end\n\n\n subroutine get_td_gaussian_locations(i,w)\n implicit none\n\n integer i\n double precision w(3)\n\n integer m, n, get_n_locations\n\n double precision wc_td_com(3,100), a_td_com\n double precision hmax_td_com\n integer n_com\n\n common /comexptd1/ wc_td_com, a_td_com, hmax_td_com\n\n n = get_n_locations()\n if (i .gt. n) then\n write(6,*) 'get_td_gaussian_locations : i .gt. n'\n stop\n endif\n\n do m = 1,3\n w(m) = wc_td_com(m,i)\n enddo\n\n end\n\nc # ----------------------------------------------------\nc # Set a,hmax parameters for Gaussians\nc # ----------------------------------------------------\n\n subroutine set_initial_gaussian_parms(a,hmax)\n implicit none\n\n double precision a,hmax\n\n double precision wc_init_com(3,100), a_init_com, hmax_init_com\n\n common /comexpinit1/ wc_init_com, a_init_com, hmax_init_com\n\n a_init_com = a\n hmax_init_com = hmax\n\n call set_td_gaussian_parms(a,hmax)\n\n end\n\n\n subroutine get_initial_gaussian_parms(a,hmax)\n implicit none\n\n double precision a,hmax\n\n double precision wc_init_com(3,100), a_init_com, hmax_init_com\n\n common /comexpinit1/ wc_init_com, a_init_com, hmax_init_com\n\n a = a_init_com\n hmax = hmax_init_com\n\n end\n\n subroutine set_td_gaussian_parms(a,hmax)\n implicit none\n\n double precision a,hmax\n\n double precision wc_td_com(3,100), a_td_com, hmax_td_com\n\n common /comexpinit1/ wc_td_com, a_td_com, hmax_td_com\n\n a_td_com = a\n hmax_td_com = hmax\n\n end\n\n\n subroutine get_td_gaussian_parms(a,hmax)\n implicit none\n\n double precision a,hmax\n\n double precision wc_td_com(3,100), a_td_com, hmax_td_com\n\n common /comexpinit1/ wc_td_com, a_td_com, hmax_td_com\n\n a = a_td_com\n hmax = hmax_td_com\n\n end\n\n\nc # ------------------------------------------------\nc # Great circle distance on sphere\nc # ------------------------------------------------\n double precision function get_gc_distance(x,y,z,w)\n implicit none\n\n double precision x,y,z,w(3)\n double precision p(3), pn, wn, ca, th\n double precision rsphere, get_scale\n integer m\n\nc rsphere = get_scale()\n rsphere = 1.0\n\n p(1) = x\n p(2) = y\n p(3) = z\n pn = sqrt(p(1)*p(1) + p(2)*p(2) + p(3)*p(3))\n if (abs(pn - rsphere) .ge. 1e-3) then\n write(6,*) 'get_gc_distance : Point is not on the sphere; '\n write(6,*) x, y, z, abs(pn-rsphere)\n stop\n endif\n\n wn = sqrt(w(1)*w(1) + w(2)*w(2) + w(3)*w(3))\n do m = 1,3\n w(m) = w(m)/wn\n enddo\n ca = (w(1)*x + w(2)*y + w(3)*z)/pn\n if (abs(ca) .gt. 1) then\n write(6,*) 'get_gc_distance : abs(ca) > 1; ', ca\n write(6,*) w(1), w(2), w(3), x,y,z\n stop\n endif\n th = acos(ca)\n get_gc_distance = th*rsphere\n\n end\n", "meta": {"hexsha": "731d2ef9851abfd54ff42f1c28244a47c5ed8711", "size": 6769, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/transport/all/gaussian.f", "max_stars_repo_name": "scivision/forestclaw", "max_stars_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-09T23:06:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-09T23:06:42.000Z", "max_issues_repo_path": "applications/clawpack/transport/all/gaussian.f", "max_issues_repo_name": "scottaiton/forestclaw", "max_issues_repo_head_hexsha": "2abaab636e6e93f5507a6f231490144a3f805b59", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/clawpack/transport/all/gaussian.f", "max_forks_repo_name": "scottaiton/forestclaw", "max_forks_repo_head_hexsha": "2abaab636e6e93f5507a6f231490144a3f805b59", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.2664473684, "max_line_length": 68, "alphanum_fraction": 0.5426207712, "num_tokens": 1969, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172644875641, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.778010937310607}} {"text": "program main2\r\n use Matrix\r\n\r\n implicit none\r\n\r\n! Command-line Args\r\n integer :: argc\r\n\r\n character(len=32) :: matrix_fname, vector_fname\r\n\r\n! Matrices\r\n integer :: m, n\r\n double precision, allocatable :: A(:, :)\r\n double precision, allocatable :: LL(:, :)\r\n double precision, allocatable :: XX(:, :)\r\n\r\n! Vectors\r\n integer :: t\r\n double precision, allocatable :: b(:)\r\n double precision, allocatable :: x(:)\r\n\r\n! Eigenvalue\r\n double precision :: l\r\n\r\n! Get Command-Line Args\r\n matrix_fname = 'matrix2.txt'\r\n vector_fname = 'vector2.txt'\r\n\r\n argc = iargc()\r\n\r\n if (argc == 1) then\r\n call getarg(1, matrix_fname)\r\n elseif(argc == 2) then\r\n call getarg(1, matrix_fname)\r\n call getarg(2, vector_fname)\r\n elseif (argc > 2) then\r\n goto 92\r\n end if\r\n\r\n call read_matrix(matrix_fname, A, m, n)\r\n call read_vector(vector_fname, b, t)\r\n\r\n if (m /= n) then\r\n goto 90\r\n elseif (m /= t) then\r\n goto 91\r\n end if\r\n\r\n! Print Matrix\r\n! Print Matrix Name\r\n write(*, *) 'A:'\r\n call print_matrix(A, m, n)\r\n\r\n! Print Matrix\r\n! Print Matrix Name\r\n write(*, *) 'b:'\r\n call print_vector(b, t)\r\n\r\n! Eigenvalue Time\r\n! Power Method\r\n allocate(x(n))\r\n call info(':: Método das Potências (Power Method) ::')\r\n if (.not. power_method(A, n, x, l)) then\r\n goto 80\r\n end if \r\n\r\n write(*, *) 'x:'\r\n call print_vector(x, n)\r\n\r\n write(*, *) 'lambda:'\r\n write(*, *) l\r\n\r\n! Jacobi Eigenvalues/vectors time\r\n allocate(LL(n, n))\r\n allocate(XX(n, n))\r\n call info(':: Método de autovalores de Jacobi ::')\r\n if (.not. Jacobi_eigen(A, n, LL, XX)) then\r\n goto 81\r\n end if\r\n write(*, *) 'L:'\r\n call print_matrix(LL, n, n)\r\n write(*, *) 'X:'\r\n call print_matrix(XX, n, n)\r\n goto 85\r\n\r\n80 call error('O Método das potências não convergiu a tempo.')\r\n write(*, *) 'x:'\r\n call print_vector(x, n)\r\n goto 100\r\n\r\n81 call error('O Método de autovalores de Jacobi não convergiu a tempo.')\r\n write(*, *) 'L:'\r\n call print_matrix(LL, n, n)\r\n write(*, *) 'X:'\r\n call print_matrix(XX, n, n)\r\n goto 100\r\n\r\n85 call info('Sucesso!')\r\n deallocate(A)\r\n deallocate(b)\r\n goto 100\r\n\r\n90 call error('Essa matriz não é quadrada! Assim o programa não faz sentido.')\r\n goto 100\r\n91 call error('A matriz `A` e o vetor `b` não possuem a mesma dimensão. Não tem como fazer Ax = b!')\r\n goto 100\r\n92 call error('Parâmetros em excesso: O programa espera apenas o nome do arquivo da matriz.')\r\n goto 100\r\n\r\n100 stop\r\n\r\nend program main2", "meta": {"hexsha": "4d6f8b6e537076026d0ea08011c23ca9022898f9", "size": 2630, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/main2.f95", "max_stars_repo_name": "pedromxavier/COC473", "max_stars_repo_head_hexsha": "2bab0c45de6c13bba7ea7580992e1b8d090f3257", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/main2.f95", "max_issues_repo_name": "pedromxavier/COC473", "max_issues_repo_head_hexsha": "2bab0c45de6c13bba7ea7580992e1b8d090f3257", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/main2.f95", "max_forks_repo_name": "pedromxavier/COC473", "max_forks_repo_head_hexsha": "2bab0c45de6c13bba7ea7580992e1b8d090f3257", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.4821428571, "max_line_length": 102, "alphanum_fraction": 0.5699619772, "num_tokens": 770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7780053231820263}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! d_rot2_check\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine checks the generators for a real rotation represented\n! by 2 real numbers: a real cosine, C, and a real sine, S. \n!\n! To check that it is valid, a new rotation X, Y is computed. If\n! |C-X|, |S-Y|, |NRM-1| < 2*EISCOR_DBL_EPS the generators are \n! considered valid. Otherwise they are invalid.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! C REAL(8)\n! generators for cosine\n!\n! S REAL(8)\n! generator for sine\n!\n! OUTPUT VARIABLES:\n!\n! FLAG LOGICAL\n! .TRUE. implies valid generators\n! .FALSE. implies invalid generators\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine d_rot2_check(C,S,FLAG)\n\n implicit none\n \n ! input variables\n real(8), intent(in) :: C, S\n logical, intent(inout) :: FLAG\n \n ! compute variables\n real(8), parameter :: tol = 2d0*EISCOR_DBL_EPS\n real(8) :: X, Y, NRM\n\n ! initialize FLAG to .FALSE.\n FLAG = .FALSE.\n \n ! compute new rotation from input one\n call d_rot2_vec2gen(C,S,X,Y,NRM)\n \n ! check for equality\n if ((abs(C-X) a (cond 2) and a+b=c (cond 3)\n do c=1,cmax\n do a=1,c/2\n b = c-a\n ! if this is an abc-hit, then we'll check rad (a*b*c)\n if (abc_hit(a,b,c)) then\n if (rad(a*b*c) < c) total = total + c\n end if\n end do !- a\n end do !- c\n \n print *,total\ncontains\n !> returns true if gcd(a,b)=gcd(b,c)=gcd(a,c)=1; false otherwise\n logical function abc_hit(a,b,c) result(bool)\n integer(int64), intent(in) :: a,b,c\n \n logical :: ab,bc,ac\n \n ab = gcd(a,b) == one\n bc = gcd(b,c) == one\n ac = gcd(a,c) == one\n \n bool = ab .and. bc .and. ac\n end function abc_hit\n \n !> returns the product of the distinct prime factors\n integer(int64) function rad(n)\n integer(int64), intent(in) :: n\n integer(int64), dimension(50) :: dpf ! distinct prime factors\n integer(int64) :: k\n \n dpf = prime_factors(n)\n rad = one\n k = one\n do while (dpf(k) > 0)\n rad = rad*dpf(k)\n k = k + 1\n end do\n end function rad\n \n !> list of prime factors\n function prime_factors(nn) result(pf)\n integer(int64), intent(in) :: nn\n integer(int64), dimension(50) :: pf\n integer(int64) :: k, n, d\n \n k=zero\n pf = -one ! initialize all prime factors to -1\n n = nn\n ! remove factors of 2\n do\n if (iand(n,one)==zero .or. n==one) then\n n = n/two\n if (k == zero) then\n pf(k) = two\n k = k + one\n end if\n end if\n end do\n \n d = three\n do\n if (d > nn) exit\n do\n if (mod(n, d) /= zero .or. n == one) then\n n = n/d\n if (pf(k-1) /= d) then\n pf(k) = d\n k = k + one\n end if\n end if\n end do\n d = d + two\n end do\n end function prime_factors\n \n !> implements binary gcd with some bitshifting for speed\n recursive function gcd(u, v) result(g)\n integer(int64), intent(in) :: u, v\n integer(int64) :: g\n \n if (u==v .or. u==zero) then\n g = v\n return\n end if\n \n if (v==zero) then\n g = u\n return\n end if\n \n ! if a number is even, then the taking bitwise AND with 1 would return 0\n ! ISHFT returns the shift of a number, direction depends on the 2nd argument: pos num = RSHIFT, neg num = LSHIFT\n if (iand(u, one)==zero) then\n if (iand(v,one)==zero) then\n g = gcd(ishft(u,one), v)\n else\n g = gcd(ishft(u,one), ishft(v,one))\n g = ishft(g, -one)\n end if\n return\n end if\n \n if (iand(v,one)==zero) then\n g = gcd(u, ishft(v,one))\n return\n end if\n \n g = gcd(ishft(abs(u-v),one),min(v,u))\n end function gcd\nend program euler_127\n", "meta": {"hexsha": "28b99998083a943351f95d7f0d0eb414fa834184", "size": 3166, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "euler_127.f90", "max_stars_repo_name": "kylekanos/ProjectEuler", "max_stars_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-13T03:36:23.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-13T03:36:23.000Z", "max_issues_repo_path": "euler_127.f90", "max_issues_repo_name": "kylekanos/ProjectEuler", "max_issues_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "euler_127.f90", "max_forks_repo_name": "kylekanos/ProjectEuler", "max_forks_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.6050420168, "max_line_length": 118, "alphanum_fraction": 0.4911560328, "num_tokens": 948, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9626731158685837, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.7779045756276115}} {"text": " subroutine ktsol(n,ns,nv,a,b,x,ktilt,maxeq)\r\nc-----------------------------------------------------------------------\r\nc\r\nc Solution of a system of linear equations by gaussian elimination with\r\nc partial pivoting. Several right hand side matrices and several\r\nc variables are allowed.\r\nc\r\nc\r\nc NOTE: All input matrices must be in double precision\r\nc\r\nc\r\nc INPUT/OUTPUT VARIABLES:\r\nc\r\nc n Number of equations\r\nc ns Number of right hand side matrices\r\nc nv Number of variables.\r\nc a(n*n*nv) left hand side matrices versus columnwise.\r\nc b(n*ns*nv) input right hand side matrices.\r\nc x(n*ns*nv) solution matrices.\r\nc ktilt indicator of singularity\r\nc = 0 everything is ok.\r\nc = -1 n.le.1\r\nc = k a null pivot appeared at the kth iteration.\r\nc tol used in test for null pivot. depends on machine\r\nc precision and can also be set for the tolerance\r\nc of an ill-defined kriging system.\r\nc\r\nc\r\nc-----------------------------------------------------------------------\r\n implicit real*8 (a-h,o-z)\r\n real*8 x(maxeq),a(maxeq*maxeq),b(maxeq)\r\nc\r\nc Make sure there are equations to solve:\r\nc\r\n if(n.le.1) then\r\n ktilt = -1\r\n return\r\n endif\r\nc\r\nc Initialization:\r\nc\r\n tol = 0.1e-10\r\n ktilt = 0\r\n ntn = n*n\r\n nm1 = n-1\r\nc\r\nc Triangulation is done variable by variable:\r\nc\r\n do iv=1,nv\r\nc\r\nc Indices of location in vectors a and b:\r\nc\r\n nva = ntn*(iv-1)\r\n nvb = n*ns*(iv-1)\r\nc\r\nc Gaussian elimination with partial pivoting:\r\nc\r\n do k=1,nm1\r\n kp1 = k+1\r\nc\r\nc Indice of the diagonal element in the kth row:\r\nc\r\n kdiag = nva+(k-1)*n+k\r\nc\r\nc Find the pivot - interchange diagonal element/pivot:\r\nc\r\n npiv = kdiag\r\n ipiv = k\r\n i1 = kdiag\r\n do i=kp1,n\r\n i1 = i1+1\r\n if(abs(a(i1)).gt.abs(a(npiv))) then\r\n npiv = i1\r\n ipiv = i\r\n endif\r\n end do\r\n t = a(npiv)\r\n a(npiv) = a(kdiag)\r\n a(kdiag) = t\r\nc\r\nc Test for singularity:\r\nc\r\n if(abs(a(kdiag)).lt.tol) then\r\n ktilt=k\r\n return\r\n endif\r\nc\r\nc Compute multipliers:\r\nc\r\n i1 = kdiag\r\n do i=kp1,n\r\n i1 = i1+1\r\n a(i1) = -a(i1)/a(kdiag)\r\n end do\r\nc\r\nc Interchange and eliminate column per column:\r\nc\r\n j1 = kdiag\r\n j2 = npiv\r\n do j=kp1,n\r\n j1 = j1+n\r\n j2 = j2+n\r\n t = a(j2)\r\n a(j2) = a(j1)\r\n a(j1) = t\r\n i1 = j1\r\n i2 = kdiag\r\n do i=kp1,n\r\n i1 = i1+1\r\n i2 = i2+1\r\n a(i1) = a(i1)+a(i2)*a(j1)\r\n end do\r\n end do\r\nc\r\nc Interchange and modify the ns right hand matrices:\r\nc\r\n i1 = nvb+ipiv\r\n i2 = nvb+k\r\n do i=1,ns\r\n t = b(i1)\r\n b(i1) = b(i2)\r\n b(i2) = t\r\n j1 = i2\r\n j2 = kdiag\r\n do j=kp1,n\r\n j1 = j1+1\r\n j2 = j2+1\r\n b(j1) = b(j1)+b(i2)*a(j2)\r\n end do\r\n i1 = i1+n\r\n i2 = i2+n\r\n end do\r\n end do\r\nc\r\nc Test for singularity for the last pivot:\r\nc\r\n kdiag = ntn*iv\r\n if(abs(a(kdiag)).lt.tol) then\r\n ktilt = n\r\n return\r\n endif\r\n end do\r\nc\r\nc End of triangulation. Now, solve back variable per variable:\r\nc\r\n do iv=1,nv\r\nc\r\nc Indices of location in vectors a and b:\r\nc\r\n nva = ntn*iv\r\n nvb1 = n*ns*(iv-1)+1\r\n nvb2 = n*ns*iv\r\nc\r\nc Back substitution with the ns right hand matrices:\r\nc\r\n do il=1,ns\r\n do k=1,nm1\r\n nmk = n-k\r\nc\r\nc Indice of the diagonal element of the (n-k+1)th row and of\r\nc the (n-k+1)th element of the left hand side.\r\nc\r\n kdiag = nva-(n+1)*(k-1)\r\n kb = nvb2-(il-1)*n-k+1\r\n b(kb) = b(kb)/a(kdiag)\r\n t = -b(kb)\r\n i1 = kb\r\n i2 = kdiag\r\n do i=1,nmk\r\n i1 = i1-1\r\n i2 = i2-1\r\n b(i1) = b(i1)+a(i2)*t\r\n end do\r\n end do\r\n kdiag = kdiag-n-1\r\n kb = kb-1\r\n b(kb) = b(kb)/a(kdiag)\r\n end do\r\nc\r\nc End of back substitution:\r\nc\r\n end do\r\nc\r\nc Restitution of the solution:\r\nc\r\n itot = n*ns*nv\r\n do i=1,itot\r\n x(i) = b(i)\r\n end do\r\nc\r\nc Finished:\r\nc\r\n return\r\n end\r\n", "meta": {"hexsha": "a81ef2a4c8c45c510df1a96e6a61f681dc6a3e53", "size": 5638, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/original/gslib/ktsol.for", "max_stars_repo_name": "exepulveda/gslib2.0", "max_stars_repo_head_hexsha": "5c021000eb3da8703ced3ee9be145d6c0ecb2608", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-07-09T06:03:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T11:11:19.000Z", "max_issues_repo_path": "src/original/gslib/ktsol.for", "max_issues_repo_name": "exepulveda/gslib2.0", "max_issues_repo_head_hexsha": "5c021000eb3da8703ced3ee9be145d6c0ecb2608", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/original/gslib/ktsol.for", "max_forks_repo_name": "exepulveda/gslib2.0", "max_forks_repo_head_hexsha": "5c021000eb3da8703ced3ee9be145d6c0ecb2608", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.9128205128, "max_line_length": 73, "alphanum_fraction": 0.368570415, "num_tokens": 1424, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620596782468, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.7778669045144446}} {"text": "module gamma_funcs\n implicit none\n integer, parameter :: int32 = kind(1)\n integer, parameter :: float32 = kind(1.0)\n integer, parameter :: float64 = kind(1.d0)\ncontains\n elemental function digamma (x)\n\n !*****************************************************************************80\n !\n !! DIGAMMA calculates DIGAMMA ( X ) = d ( LOG ( GAMMA ( X ) ) ) / dX\n !\n ! Licensing:\n !\n ! This code is distributed under the GNU LGPL license.\n !\n ! Modified:\n !\n ! 20 March 2016\n !\n ! Author:\n !\n ! Original FORTRAN77 version by Jose Bernardo.\n ! FORTRAN90 version by John Burkardt.\n ! iso_fortran_env by Simone Marsili.\n !\n ! Reference:\n !\n ! Jose Bernardo,\n ! Algorithm AS 103:\n ! Psi ( Digamma ) Function,\n ! Applied Statistics,\n ! Volume 25, Number 3, 1976, pages 315-317.\n !\n ! Parameters:\n !\n ! Input, real(float64) X, the argument of the digamma function.\n ! 0 < X.\n !\n !\n ! Output, real(float64) DIGAMMA, the value of the digamma function at X.\n !\n implicit none\n\n real(float64) :: digamma\n real(float64), intent(in) :: x\n real(float64), parameter :: c = 8.5_float64\n real(float64), parameter :: euler_mascheroni = 0.57721566490153286060_float64\n real(float64) r\n real(float64) x2\n !\n ! Check the input.\n !\n if ( x <= 0.0_float64 ) then\n digamma = 0.0_float64\n return\n end if\n !\n ! Approximation for small argument.\n !\n if ( x <= 0.000001_float64 ) then\n digamma = - euler_mascheroni - 1.0_float64 / x + 1.6449340668482264365_float64 * x\n return\n end if\n !\n ! Reduce to DIGAMA(X + N).\n !\n digamma = 0.0_float64\n x2 = x\n\n do while ( x2 < c )\n digamma = digamma - 1.0_float64 / x2\n x2 = x2 + 1.0_float64\n end do\n !\n ! Use Stirling's (actually de Moivre's) expansion.\n !\n r = 1.0_float64 / x2\n\n digamma = digamma + log ( x2 ) - 0.5_float64 * r\n\n r = r * r\n\n digamma = digamma &\n - r * ( 1.0_float64 / 12.0_float64 &\n - r * ( 1.0_float64 / 120.0_float64 &\n - r * ( 1.0_float64 / 252.0_float64 &\n - r * ( 1.0_float64 / 240.0_float64 &\n - r * ( 1.0_float64 / 132.0_float64 ) ) ) ) )\n\n end function digamma\n\n elemental function trigamma (x)\n\n !*****************************************************************************80\n !\n !! TRIGAMMA calculates trigamma(x) = d^2 log(gamma(x)) / dx^2\n !\n ! Modified:\n !\n ! 19 January 2008\n !\n ! Author:\n !\n ! Original FORTRAN77 version by BE Schneider.\n ! FORTRAN90 version by John Burkardt.\n ! iso_fortran_env by Simone Marsili.\n !\n ! Reference:\n !\n ! BE Schneider,\n ! Algorithm AS 121:\n ! Trigamma Function,\n ! Applied Statistics,\n ! Volume 27, Number 1, pages 97-99, 1978.\n !\n ! Parameters:\n !\n ! Input, real(float64) X, the argument of the trigamma function.\n ! 0 < X.\n !\n !\n ! Output, real(float64) TRIGAMMA, the value of the trigamma function.\n !\n implicit none\n\n real(float64) :: trigamma\n real(float64), intent(in) :: x\n\n real(float64), parameter :: a = 0.0001_float64\n real(float64), parameter :: b = 5.0_float64\n real(float64), parameter :: b2 = 0.1666666667_float64\n real(float64), parameter :: b4 = -0.03333333333_float64\n real(float64), parameter :: b6 = 0.02380952381_float64\n real(float64), parameter :: b8 = -0.03333333333_float64\n\n real(float64) y\n real(float64) z\n !\n ! Check the input.\n !\n if ( x <= 0.0_float64 ) then\n trigamma = 0.0_float64\n return\n end if\n\n z = x\n !\n ! Use small value approximation if X <= A.\n !\n if ( x <= a ) then\n trigamma = 1.0_float64 / x / x\n return\n end if\n !\n ! Increase argument to ( X + I ) >= B.\n !\n trigamma = 0.0_float64\n\n do while ( z < b )\n trigamma = trigamma + 1.0_float64 / z / z\n z = z + 1.0_float64\n end do\n !\n ! Apply asymptotic formula if argument is B or greater.\n !\n y = 1.0_float64 / z / z\n\n trigamma = trigamma + 0.5_float64 * &\n y + ( 1.0_float64 &\n + y * ( b2 &\n + y * ( b4 &\n + y * ( b6 &\n + y * b8 )))) / z\n\n end function trigamma\n\n elemental function quadgamma (x)\n ! computes \\psi_2(x) = d^3 log(gamma(x)) / dx^3 = d^2 \\psi(x) / dx^2\n ! Simone Marsili\n implicit none\n\n real(float64) :: quadgamma\n real(float64), intent(in) :: x\n\n real(float64), parameter :: a = 0.0001_float64\n real(float64), parameter :: b = 5.0_float64\n real(float64) z\n ! Check the input.\n if ( x <= 0.0_float64 ) then\n quadgamma = 0.0_float64\n return\n end if\n\n ! Use small value approximation if X <= A.\n if ( x <= a ) then\n quadgamma = - gamma(3.0_float64) / x**3\n return\n end if\n\n ! Increase argument to ( X + I ) >= B.\n quadgamma = 0.0_float64\n z = x\n do while ( z < b )\n quadgamma = quadgamma - 2.0_float64 / z**3\n z = z + 1.0_float64\n end do\n\n ! Apply asymptotic formula if argument is B or greater.\n z = 1/z\n quadgamma = quadgamma - z**2 - z**3 - 0.5*z**4\n\n end function quadgamma\n\nend module gamma_funcs\n", "meta": {"hexsha": "80fb61b53a681ff566f8172955df6e526b5fd86f", "size": 5375, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ndd/exts/gamma.f90", "max_stars_repo_name": "simomarsili/ndd", "max_stars_repo_head_hexsha": "3a8f8f80116ddaf8666dd13b246a04c9806447a7", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-01-25T21:42:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-05T02:12:11.000Z", "max_issues_repo_path": "ndd/exts/gamma.f90", "max_issues_repo_name": "simomarsili/ndd", "max_issues_repo_head_hexsha": "3a8f8f80116ddaf8666dd13b246a04c9806447a7", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-06-22T19:15:33.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-06T12:37:24.000Z", "max_forks_repo_path": "ndd/exts/gamma.f90", "max_forks_repo_name": "simomarsili/ndd", "max_forks_repo_head_hexsha": "3a8f8f80116ddaf8666dd13b246a04c9806447a7", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-07-31T07:53:02.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-31T07:53:22.000Z", "avg_line_length": 24.8842592593, "max_line_length": 89, "alphanum_fraction": 0.5324651163, "num_tokens": 1732, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7778508501552718}} {"text": "program TrapezoidalMethod\n \n implicit none\n\n !------------Defining the variables ---------! \n real :: A,sumTotal = 0\n integer :: i,n \n real,allocatable, dimension(:) :: x1 \n real :: a1,b1,delX !integral bounds \n \n\n !------------End of defining the variables ---------! \n n = 300 !number of steps \n allocate(x1(n)) \n\n ! Solving this type of Integral \n ! a1 \n ! ___\n ! / '\n ! |\n ! | \n ! | f(x) dx \n ! |\n ! ___/\n ! b1 \n ! \n !\n a1 = -10\n b1 = 10\n delX = (b1-a1)/n\n call calculateLength(b1,a1,n,x1,delX) \n\n\n do i = 0, (n)\n\n call calculateArea(A,n,i,x1,delX)\n sumTotal = sumTotal+A\n end do \n\n print *, \"Area of the given integral is : \", sumTotal\n\nend program \n\n\n\nsubroutine calculateArea(A,n,i,x1,delX)\n real :: f,A,delX\n integer :: n,i\n real, dimension(n) :: x1 \n\n if((i == 0) .or.(i == (n))) then \n A = f(x1(i))*delX/2\n else \n\n A = f(x1(i))*delX\n\n end if \n\nend subroutine \n\n\nsubroutine calculateLength(b1,a1,n,x1,delX)\n integer :: j,n \n real :: a1,b1,delX\n real, dimension(n) :: x1 \n\n do j = 0,(n) \n\n if(j==0) then \n x1(j) = a1\n\n else if (j.NE.0 .or. j.NE.(n) ) then \n x1(j) = x1(j-1)+delX\n else \n x1(j) = b1\n end if \n\n end do \n\n\nend subroutine\n\nreal function f(x)\n implicit none \n real :: x \n f = exp(-(x**2))\n \nend function\n\n\n\n\n", "meta": {"hexsha": "d9214e170a65bfd2f35b18471b58bd5b2b2a51bb", "size": 1561, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "trapezoid.f90", "max_stars_repo_name": "amel123amel/Test1", "max_stars_repo_head_hexsha": "1b0611661bc8ac6ae969d7d3e8d22b06ae0d1f99", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "trapezoid.f90", "max_issues_repo_name": "amel123amel/Test1", "max_issues_repo_head_hexsha": "1b0611661bc8ac6ae969d7d3e8d22b06ae0d1f99", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "trapezoid.f90", "max_forks_repo_name": "amel123amel/Test1", "max_forks_repo_head_hexsha": "1b0611661bc8ac6ae969d7d3e8d22b06ae0d1f99", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.7849462366, "max_line_length": 58, "alphanum_fraction": 0.4433055734, "num_tokens": 501, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.777848702994097}} {"text": "program fibonnacci_goto\n\nimplicit none\ninteger:: n ! Declaration of iterator\ninteger:: i=2\ninteger:: x, y, z\nreal:: phi_est ! Approx phi\n\nprint*, 'Type the number upto which the fibonnacci sequence is to run'\n\nread*, n\n\n z = 0\n y = 1\n2 x = y + z\n phi_est = x/(real(y))\n\n print '(2i15 f10.5)', i, x, phi_est\n\n z = y\n y = x\n i = i + 1\n if (i < n+1) goto 2\n\nend program fibonnacci_goto\n", "meta": {"hexsha": "24592ad60229e8ad123ce28a6f7b0b02f1cb8580", "size": 420, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "practice/fibonnacci_goto.f95", "max_stars_repo_name": "adisen99/fortran_programs", "max_stars_repo_head_hexsha": "04d3a528200e27a25b109f5d3a0aff66b22f94a1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "practice/fibonnacci_goto.f95", "max_issues_repo_name": "adisen99/fortran_programs", "max_issues_repo_head_hexsha": "04d3a528200e27a25b109f5d3a0aff66b22f94a1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "practice/fibonnacci_goto.f95", "max_forks_repo_name": "adisen99/fortran_programs", "max_forks_repo_head_hexsha": "04d3a528200e27a25b109f5d3a0aff66b22f94a1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.1538461538, "max_line_length": 70, "alphanum_fraction": 0.5880952381, "num_tokens": 147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.7776952741155612}} {"text": "!##############################################################################\n! PROGRAM polynomials\n!\n! ## Polynomial interpolation using different kinds of nodes\n!\n! This code is published under the GNU General Public License v3\n! (https://www.gnu.org/licenses/gpl-3.0.en.html)\n!\n! Authors: Hans Fehr and Fabian Kindermann\n! contact@ce-fortran.com\n!\n! #VC# VERSION: 1.0 (23 January 2018)\n!\n!##############################################################################\nprogram polynomials\n\n use toolbox\n\n implicit none\n integer, parameter :: n = 10, nplot = 1000\n real*8 :: xi(0:n), yi(0:n)\n real*8 :: xplot(0:nplot), yplot(0:nplot), yreal(0:nplot)\n\n ! get equidistant plot nodes and Runge's function\n call grid_Cons_Equi(xplot, -1d0, 1d0)\n yreal = 1d0/(1d0+25*xplot**2)\n call plot(xplot, yreal, legend='Original')\n\n ! equidistant polynomial interpolation\n call grid_Cons_Equi(xi, -1d0, 1d0)\n yi = 1d0/(1d0+25*xi**2)\n yplot = poly_interpol(xplot, xi, yi)\n call plot(xplot, yplot, legend='Equidistant')\n\n ! Chebyshev polynomial interpolation\n call grid_Cons_Cheb(xi, -1d0, 1d0)\n yi = 1d0/(1d0+25*xi**2)\n yplot = poly_interpol(xplot, xi, yi)\n call plot(xplot, yplot, legend='Chebyshev')\n\n ! execute plot\n call execplot()\n\nend program\n", "meta": {"hexsha": "2b54e6e7ed37e71b14cdc779701ec029ba66d4f0", "size": 1333, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog02/prog02_17/prog02_17.f90", "max_stars_repo_name": "aswinvk28/modflow_fortran", "max_stars_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "complete/prog02/prog02_17/prog02_17.f90", "max_issues_repo_name": "aswinvk28/modflow_fortran", "max_issues_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "complete/prog02/prog02_17/prog02_17.f90", "max_forks_repo_name": "aswinvk28/modflow_fortran", "max_forks_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-07T12:27:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-07T12:27:47.000Z", "avg_line_length": 29.6222222222, "max_line_length": 79, "alphanum_fraction": 0.5753938485, "num_tokens": 397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554476, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7776537398346046}} {"text": "module roots\n\n use, intrinsic :: iso_fortran_env, only: wp => real64\n implicit none\n\n logical, private, parameter :: debug = .true.\n\n abstract interface\n real(wp) function func(x)\n import :: wp\n implicit none\n real(wp), intent(in) :: x\n end function func\n end interface\n\ncontains\n\n subroutine biseccion ( f, a, b, n, tol, raiz, clave )\n\n ! METODO DE BISECCION para encontrar una solución\n ! de f(x)=0 dada la función continua f en el intervalo\n ! [a,b] donde f(a) y f(b) tienen signos opuestos.\n\n ! Argumentos\n procedure(func) :: f ! Función que define la ecuación\n real(wp), intent(in) :: a ! Extremo izquierdo del intervalo inicial\n real(wp), intent(in) :: b ! Extremo derecho del intervalo inicial\n integer, intent(in out) :: n ! Límite de iteraciones/iteraciones realizadas\n real(wp), intent(in) :: tol ! Tolerancia para el error absoluto\n real(wp), intent(out) :: raiz ! Aproximación a la raiz\n integer, intent(out) :: clave ! Clave de éxito: \n ! 0 : éxito\n ! >0 : iteraciones excedidas\n ! <0 : no se puede proceder (f de \n ! igual signo en a y b)\n ! Variables locales\n integer :: i\n real(wp) :: xl, xr, error\n\n clave = 1\n xl = a\n xr = b \n if ( sign( 1.0_wp , f(xl) ) * sign ( 1.0_wp, f(xr) ) > 0.0_wp ) then\n clave = -1\n return\n endif\n\n if ( debug ) write(*,'(a)') ' i x_i'\n\n do i=1,n\n\n error = (xr-xl)*0.5_wp\n raiz = xl + error\n\n if ( debug ) write(*,'(i5,2x,g0)') i, raiz\n\n if ( error <= tol ) then\n clave = 0\n n = i\n exit\n endif\n\n if ( sign( 1.0_wp, f(xl) ) * sign( 1.0_wp, f(raiz) ) > 0.0_wp ) then\n xl = raiz\n else\n xr = raiz\n endif\n\n enddo\n\n end subroutine biseccion\n\n \n subroutine newton ( f, df, x0, n, tol, raiz, clave )\n\n ! Metodo DE NEWTON-RAPHSON para encontrar una \n ! solución de f(x)=0 dada la función derivable\n ! f y una aproximación inicial x0.\n\n ! Argumentos\n procedure(func) :: f ! Función que define la ecuación\n procedure(func) :: df ! Derivada de la función que define la ecuación\n real(wp), intent(in) :: x0 ! Aproximación inicial a la raíz\n integer, intent(in out) :: n ! Límite de iteraciones/iteraciones realizadas\n real(wp), intent(in) :: tol ! Tolerancia para el error relativo\n real(wp), intent(out) :: raiz ! Aproximación a la raiz\n integer, intent(out) :: clave ! Clave de éxito: \n ! 0 : éxito\n ! >0 : iteraciones excedidas\n ! Variables locales\n integer :: i\n real(wp) :: xx0\n\n clave = 1\n xx0 = x0\n\n if ( debug ) write(*,'(a)') ' i x_i'\n\n do i=1,n\n raiz = xx0 - f(xx0)/df(xx0)\n\n if ( debug ) write(*,'(i5,2x, g0)') i, raiz\n\n if ( abs( raiz-xx0 ) <= tol * abs( raiz ) ) then\n clave = 0\n n = i\n exit\n endif\n\n xx0 = raiz\n\n end do\n\n end subroutine newton\n\n \n subroutine secante ( f, x0, x1, n, tol, raiz, clave )\n\n ! ALGORITMO DE LA SECANTE para encontrar una solución\n ! de f(x)=0, siendo f una función continua, dada las\n ! aproximaciones iniciales x0 y x1.\n\n ! Argumentos\n procedure(func) :: f ! Función que define la ecuación\n real(wp), intent(in) :: x0,x1 ! Aproximaciones iniciales a la raíz\n integer, intent(in out) :: n ! Límite de iteraciones/iteraciones realizadas\n real(wp), intent(in) :: tol ! Tolerancia para el error relativo\n real(wp), intent(out) :: raiz ! Aproximación a la raiz\n integer, intent(out) :: clave ! Clave de éxito: \n ! 0 : éxito\n ! >0 : iteraciones excedidas\n\n ! Variables locales\n integer :: i\n real(wp):: xx0, xx1, fx0, fx1\n\n clave = 1\n xx0 = x0\n xx1 = x1 \n fx0 = f(x0)\n fx1 = f(x1)\n\n if ( debug ) write(*,'(a)') ' i x_i'\n\n do i= 1,n\n\n raiz = xx1 - fx1 * ( ( xx1-xx0 ) / ( fx1-fx0 ) )\n\n if ( debug ) write(*,'(i5,2x, g0)') i, raiz\n\n if ( abs( raiz-xx1 ) <= tol * abs( raiz ) ) then\n clave = 0\n n = i\n exit\n endif\n\n xx0 = xx1\n fx0 = fx1\n xx1 = raiz\n fx1 = f(raiz)\n\n end do\n\n end subroutine secante\n\n \n subroutine birge_vieta ( a, x0, n, tol, raiz, clave )\n \n ! METODO DE BIRGE-VIETA para resolver ECUACIONES ALGEBRAICAS:\n ! P(x) = 0 donde P es un polinomio de grado m de coeficientes reales.\n ! El método se basa en el método de Newton-Raphson implementando el\n ! esquema de Horner para la evaluación del polinomio y su derivada.\n\n ! Argumentos\n real(wp), intent(in) :: a(0:) ! Vector de m+1 elementos conteniendo\n ! los coeficientes del polinomio\n real(wp), intent(in) :: x0 ! Aproximación inicial a la raíz\n real(wp), intent(in) :: tol ! Tolerancia para el error relativo\n integer, intent(in out) :: n ! Límite de iteraciones/iteraciones realizadas\n real(wp), intent(out) :: raiz ! Aproximación a la raiz\n integer, intent(out) :: clave ! Clave de éxito: \n ! 0 : éxito\n ! >0 : iteraciones excedidas\n ! Variables locales\n integer :: m, i, j\n real(wp):: xx0,b,c\n\n clave = 1\n xx0 = x0\n m = size(a)-1\n\n if ( debug ) write(*,'(a)') ' i x_i'\n\n do i=1,n\n\n ! Esquema de Horner\n b = a(m)\n c = a(m) \n do j=m-1,1,-1\n b = b*xx0+a(j)\n c = c*xx0+b\n enddo\n b = b*xx0+a(0)\n\n ! Método de Newton\n raiz = xx0 - b/c\n\n if ( debug ) write(*,'(i5,2x,g0)') i, raiz\n\n if ( abs( raiz-xx0 ) <= tol * abs( raiz ) ) then\n clave = 0\n n = i\n exit\n end if\n xx0 = raiz\n end do\n\n end subroutine birge_vieta\n\n \n subroutine punto_fijo ( f, x0, n, tol, raiz, clave )\n\n ! ALGORITMO DE PUNTO FIJO o DE APROXIMACIONES SUCESIVAS\n ! para encontrar una solución de x=f(x) dada una\n ! aproximación inicial x0.\n\n ! Argumentos\n procedure(func) :: f ! Función que define la ecuación\n real(wp), intent(in) :: x0 ! Aproximación inicial a la raíz\n integer, intent(in out) :: n ! Límite de iteraciones/iteraciones realizadas\n real(wp), intent(in) :: tol ! Tolerancia para el error relativo\n real(wp), intent(out) :: raiz ! Aproximación a la raiz\n integer, intent(out) :: clave ! Clave de éxito:\n ! 0 : éxito\n ! >0 : iteraciones excedidas\n\n ! Variables locales\n integer :: i\n real(wp) :: xx0\n\n clave = 1\n xx0 = x0\n\n if ( debug ) write(*,'(a)') ' i x_i'\n\n do i=1,n\n raiz = f(xx0)\n\n if ( debug ) write(*,'(i5,2x,g0)') i, raiz\n\n if ( abs( raiz-xx0 ) <= tol * abs( raiz ) ) then\n clave = 0\n n = i\n exit\n endif\n xx0 = raiz\n end do\n\n end subroutine punto_fijo\n\n \n subroutine fzero( f, b, c, re, ae, iflag )\n\n ! Search for a zero of a function F(X) in a given interval\n ! (B,C). It is designed primarily for problems where F(B)\n ! and F(C) have opposite signs.\n !\n ! Original author:\n !\n ! Shampine, L. F., (SNLA)\n ! Watts, H. A., (SNLA)\n !\n ! Modified by\n !\n ! Pablo Santamaría\n !\n ! Description\n !\n ! FZERO searches for a root of the nonlinear equation F(X) = 0\n ! (when F(X) is a real function of a single real variable X),\n ! between the given values B and C until the width\n ! of the interval (B,C) has collapsed to within a tolerance\n ! specified by the stopping criterion,\n !\n ! ABS(B-C) <= 2*MAX(RW*ABS(B),AE).\n !\n ! The method used is an efficient combination of bisection and the\n ! secant rule and is due to T. J. Dekker.\n !\n ! Arguments\n !\n ! f :EXT - Name of the function subprogram defining F(X).\n ! This subprogram should have the form\n ! REAL(WP) FUNCTION F(X)\n ! USE iso_fortan_env, ONLY: WP => REAL64\n ! IMPLICIT NONE\n ! REAL(WP), INTENT(IN) :: X\n ! F = ...\n ! END FUNCTION F\n ! An explicit interface should be provided\n ! in the calling program.\n !\n ! b :INOUT - One end of the interval (B,C). The\n ! value returned for B usually is the better\n ! approximation to a zero of F.\n !\n ! c :INOUT - The other end of the interval (B,C)\n !\n !\n ! re :IN - Relative error used for RW in the stopping criterion.\n ! If the requested RE is less than machine precision,\n ! then RW is set to approximately machine precision.\n !\n ! ae :IN - Absolute error used in the stopping criterion. If\n ! the given interval (B,C) contains the origin, then a\n ! nonzero value should be chosen for AE.\n !\n ! iflag :OUT - A status code. User must check IFLAG after each\n ! call. Control returns to the user from FZERO in all\n ! cases.\n !\n ! 0 B is within the requested tolerance of a zero.\n ! The interval (B,C) collapsed to the requested\n ! tolerance, the function changes sign in (B,C), and\n ! F(X) decreased in magnitude as (B,C) collapsed.\n !\n ! 1 F(B) = 0. However, the interval (B,C) may not have\n ! collapsed to the requested tolerance.\n !\n ! -1 B may be near a singular point of F(X).\n ! The interval (B,C) collapsed to the requested tol-\n ! erance and the function changes sign in (B,C), but\n ! F(X) increased in magnitude as (B,C) collapsed, i.e.\n ! ABS(F(B out)) > MAX(ABS(F(B in)),ABS(F(C in)))\n !\n ! -2 No change in sign of F(X) was found although the\n ! interval (B,C) collapsed to the requested tolerance.\n ! The user must examine this case and decide whether\n ! B is near a local minimum of F(X), or B is near a\n ! zero of even multiplicity, or neither of these.\n !\n ! -3 Too many (> 500) function evaluations used.\n !\n ! References\n !\n ! L. F. Shampine and H. A. Watts, FZERO, a root-solving\n ! code, Report SC-TM-70-631, Sandia Laboratories,\n ! September 1970.\n ! T. J. Dekker, Finding a zero by means of successive\n ! linear interpolation, Constructive Aspects of the\n ! Fundamental Theorem of Algebra, edited by B. Dejon\n ! and P. Henrici, Wiley-Interscience, 1969.\n !\n ! Notes\n !\n ! This implementation is a Fortran 90 refactoring from the original\n ! dfzero.f subroutine:\n !\n ! * http://www.netlib.org/slatec/src/dfzero.f\n !\n ! with some changes from:\n !\n ! * ftp://ftp.wiley.com/public/college/math/sapcodes/f90code/saplib.f90\n !\n \n ! Arguments\n procedure(func) :: f\n real(wp), intent(in out) :: b\n real(wp), intent(in out) :: c\n real(wp), intent(in) :: re\n real(wp), intent(in) :: ae\n integer, intent(out) :: iflag\n\n ! Local variables\n real(wp) :: a, acbs, acmb, cmb\n real(wp) :: fa, fb, fc, fx\n real(wp) :: p, q\n real(wp) :: aw, rw, tol\n integer :: ic, kount, max_feval\n logical :: force_bisect\n character(7) :: method\n\n\n ! Set error tolerances\n rw = max( re, epsilon(1.0_wp) )\n aw = max( ae, 0.0_wp )\n\n ! Initialize\n max_feval = 500\n ic = 0\n\n fb = f( b )\n fc = f( c )\n kount = 2\n\n a = c\n fa = fc\n acbs = abs( b-c )\n fx = max( abs(fb), abs(fc) )\n\n if ( debug ) then\n write(*,'(a,1x,a,11x,a,19x,a,17x,a,15x,a)') 'F-count', &\n & 'method', 'b', 'c', 'f(b)', 'f(c)'\n method = 'initial'\n end if\n\n ! Iteration loop\n do\n\n ! Perform interchange such abs(f(b)) < abs(f(c))\n if ( abs( fc ) < abs( fb ) ) then\n a = b\n fa = fb\n b = c\n fb = fc\n c = a\n fc = fa\n end if\n\n if ( debug ) write(*,'(i5,*(2x,g0))') kount, method, b, c, fb, fc\n\n cmb = 0.5_wp * (c-b)\n acmb = abs( cmb )\n tol = max( rw*abs(b), aw ) ! or tol = rw*abs(b) + aw\n\n ! Test stopping criterion and function count\n ! Set iflag appropriately\n if ( acmb <= tol ) then\n if ( sign( 1.0_wp, fb ) * sign( 1.0_wp, fc ) > 0.0_wp ) then\n iflag = -2\n else if ( abs( fb ) > fx ) then\n iflag = -1\n else\n iflag = 0\n end if\n exit\n endif\n\n if ( abs( fb ) <= 0.0_wp ) then\n iflag = 1\n exit\n end if\n\n if ( kount >= max_feval ) then\n iflag = -3\n exit\n end if\n\n ! Calculate new iterate implicitly as b+p/q, where we arrange\n ! p >= 0. The implicit form is used to prevent overflow.\n p = (b-a) * fb\n q = fa - fb\n\n if ( p < 0.0_wp ) then\n p = -p\n q = -q\n end if\n\n ! Update a and check for satisfactory reduction in the size of the\n ! bracketing interval every four increments.\n ! If not, force bisection.\n a = b\n fa = fb\n ic = ic + 1\n force_bisect = .false.\n\n if ( ic >= 4 ) then\n\n if ( 8.0_wp * acmb >= acbs ) then\n force_bisect = .true.\n else\n ic = 0\n acbs = acmb\n end if\n\n end if\n\n ! Get new iterate b\n if ( force_bisect ) then\n b = b + cmb ! Use bisection (c+b)/2\n if (debug) method = 'bisect*'\n else if ( p <= abs(q) * tol ) then ! If to small, increment by tolerance\n b = b + sign( tol, cmb )\n if ( debug ) method = 'minimal'\n else if ( p < cmb * q ) then ! Root ought to be between b and (c+b)/2\n b = b + p/q ! Use secant rule\n if ( debug ) method = 'secant'\n else\n b = b + cmb ! Use bisection (c+b)/2\n if ( debug ) method = 'bisect'\n end if\n\n ! Have completed computation for new iterate b.\n fb = f( b )\n kount = kount + 1\n\n ! Decide whether next step is interpolation or extrapolation.\n if ( sign( 1.0_wp, fb ) * sign( 1.0_wp, fc ) > 0.0_wp ) then\n c = a\n fc = fa\n end if\n\n end do\n\n end subroutine fzero\n\nend module roots\n", "meta": {"hexsha": "ee492507930a4badc48e059b19e98f1e631ed6f4", "size": 15312, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/roots.f90", "max_stars_repo_name": "pjs-f/roots", "max_stars_repo_head_hexsha": "0cfdd5d314624dc03b3aaedd1b1b3a3604b8d86c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/roots.f90", "max_issues_repo_name": "pjs-f/roots", "max_issues_repo_head_hexsha": "0cfdd5d314624dc03b3aaedd1b1b3a3604b8d86c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/roots.f90", "max_forks_repo_name": "pjs-f/roots", "max_forks_repo_head_hexsha": "0cfdd5d314624dc03b3aaedd1b1b3a3604b8d86c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.1417322835, "max_line_length": 85, "alphanum_fraction": 0.4988244514, "num_tokens": 4557, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328286, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.7776416675745775}} {"text": "Program P11\n\n\n\n implicit none\n\n integer :: i, j, n\n\n integer , allocatable , dimension(:,:) :: a, b, v, aaa\n\n integer , allocatable , dimension(:) :: aa , c\n\n\n\n write(*,*) ' ingrese la dimensión de los arreglos .'\n\n read(*,*) n\n\n\n\n allocate (a(n,n), b(n,1), c(n), v(n,1), aa(n*n), aaa(n,n) )\n\n\n\n b(1:N:2,1) = 3 ! Notar que para fortran N = n\n\n b(2:N:2,1) = 2\n\n\n\n write (*,*) ''\n\n write (*,*) 'dimensión n =', n\n\n write (*,*) ''\n\n write (*,*) ' vector b =', b\n\n\n\n ! Otra manera de hacer la asignación. ( Array Constructors )\n\n ! Notar que 'c' es un arreglo unidimensional\n\n c = (/ (2+mod(i ,2),i=1,n) /)\n\n write (*,*) ''\n\n write (*,*) ' c =', c\n\n\n\n write (*,*) ''\n\n write (*,*) ' ---------------------------------------------------------- ' \n\n\nwrite (*,*) ''\n\n\n\n ! se define el vector aa\n\n aa = (/ 3, (0,i=2,n), ( (1,i=1,j-1) ,3,(0,i=j+1,n), j=2,n) /)\n\n write (*,*) ''\n\n write (*,*) ' vector aa =', aa\n\n write (*,*) ' --------------------------------------------------------- '\n\n ! se cambia el vector a arreglo\n\n aaa = reshape ((aa) ,(/ n , n /))\n\n write (*,*) ' arreglo aaa =', aaa\n\n \n \n write (*,*) ' --------------------------------------------------------------------- '\n \n do i=1,n\n\n write (*,*) aaa (i ,:)\n\n end do\n\n\n\n ! Otra manera de hacer la asignaci ón.\n\n a = 0\n\n forall (i =1:n, j=2:n, j>i) a(i,j) = 1\n\n forall (i =1:n) a(i,i) = 3\n\n\n\n write (*,*) ''\n\n write (*,*) ' ------------------------------------------------------------------------ '\n\n write (*,*) ''\n\n write (*,*) ' a(i,j) ='\n\n do i=1,n\n\n write (*,*) a(i,:)\n\n end do\n \n write (*,*) ' ------------------------------------------------------------------------ '\n \n \n write (*,*) ' vector b =', b\n\n \n \n write (*,*) ' --------------------------------------------------------------------------- ' \n \n v = a * b\n \n write (*,*) ' vector v = a * b :', v\n \nwrite (*,*) ' --------------------------------------------------------------------------- ' \n \n v = matmul(a,b)\n\n write (*,*) ''\n\n write (*,*) 'v = matmul (a,b)'\n\n write (*,*) ' vector v =', v\n\n\n\n ! ¾Qué pasa si se prueba lo siguiente ?\n\n ! v = matmul(a,c)\n\n ! write (*,*) ''\n\n ! write (*,*) 'matmul(a,c) =', v\n\n\n\n end program\n\n\n\n\n \n", "meta": {"hexsha": "a414c3a8658826e50ff07b38a19fe74575a7f427", "size": 2153, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "G1e11/Program11_old.f90", "max_stars_repo_name": "EdgardoBonzi/Fortran-Examples", "max_stars_repo_head_hexsha": "14795aa96e2499b1dfe248fdc59478566e476168", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "G1e11/Program11_old.f90", "max_issues_repo_name": "EdgardoBonzi/Fortran-Examples", "max_issues_repo_head_hexsha": "14795aa96e2499b1dfe248fdc59478566e476168", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "G1e11/Program11_old.f90", "max_forks_repo_name": "EdgardoBonzi/Fortran-Examples", "max_forks_repo_head_hexsha": "14795aa96e2499b1dfe248fdc59478566e476168", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.8903225806, "max_line_length": 94, "alphanum_fraction": 0.3497445425, "num_tokens": 627, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8499711794579722, "lm_q1q2_score": 0.7776394438026081}} {"text": "C\n SUBROUTINE FHIRES (N, X, Y, DY, RPAR, IPAR)\n INTEGER N\n DOUBLE PRECISION X, Y, DY\n DIMENSION Y (8), DY (8)\n DY (1) = -1.71D0*Y(1) + 0.43D0*Y(2) + 8.32D0*Y(3) + 0.0007D0\n DY (2) = 1.71D0*Y(1) - 8.75D0*Y(2)\n DY (3) = -10.03D0*Y(3) + 0.43D0*Y(4) + 0.035D0*Y(5)\n DY (4) = 8.32D0*Y(2) + 1.71D0*Y(3) - 1.12D0*Y(4)\n DY (5) = -1.745D0*Y(5) + 0.43D0*Y(6) + 0.43D0*Y(7)\n DY (6) = -280.0D0*Y(6)*Y(8) + 0.69D0*Y(4) + 1.71D0*Y(5) -\n & 0.43D0*Y(6) + 0.69D0*Y(7)\n DY (7) = 280.0D0*Y(6)*Y(8) - 1.81D0*Y(7)\n DY (8) = -DY (7)\n RETURN \n END\n\n\n SUBROUTINE JHIRES(N,X,Y,DFY,LDFY,RPAR,IPAR)\nC -------- JACOBIAN FOR HIRES PROBLEM --------\n IMPLICIT REAL*8 (A-H,O-Z)\n DIMENSION Y(N),DFY(LDFY,N)\nC------ METTRE A ZERO -------\n DO 1 I=1,N\n DO 1 J=1,N\n 1 DFY(I,J)=0.D0\nC\n DFY(1,1)= -1.71D0\n DFY(1,2)= 0.43D0\n DFY(1,3)= + 8.32D0\nC\n DFY(2,1)= 1.71D0\n DFY(2,2)= - 8.75D0\nC\n DFY(3,3)= -10.03D0\n DFY(3,4)= 0.43D0\n DFY(3,5)= + 0.035D0\nC\n DFY(4,2)= 8.32D0\n DFY(4,3)= + 1.71D0\n DFY(4,4)= - 1.12D0\nC\n DFY(5,5)= -1.745D0\n DFY(5,6)= + 0.43D0\n DFY(5,7)= + 0.43D0\nC\n DFY(6,4)= + 0.69D0\n DFY(6,5)= + 1.71D0\n DFY(6,6)= - 0.43D0 -280.0D0*Y(8)\n DFY(6,7)= + 0.69D0\n DFY(6,8)= -280.0D0*Y(6)\nC \n DFY(7,6)= 280.0D0*Y(8)\n DFY(7,7)= - 1.81D0\n DFY(7,8)= 280.0D0*Y(6)\nC\n DFY(8,6)= - 280.0D0*Y(8)\n DFY(8,7)= 1.81D0\n DFY(8,8)= - 280.0D0*Y(6)\n RETURN\n END\n\n\n", "meta": {"hexsha": "31f3ccf7ab69393b5cd4038167dd3c258ed416a3", "size": 1625, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/hir_equation.f", "max_stars_repo_name": "cpmech/hwode", "max_stars_repo_head_hexsha": "7a6c033ace96b8b8dcf564ba0f38dd501fe2f60d", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/hir_equation.f", "max_issues_repo_name": "cpmech/hwode", "max_issues_repo_head_hexsha": "7a6c033ace96b8b8dcf564ba0f38dd501fe2f60d", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/hir_equation.f", "max_forks_repo_name": "cpmech/hwode", "max_forks_repo_head_hexsha": "7a6c033ace96b8b8dcf564ba0f38dd501fe2f60d", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.390625, "max_line_length": 66, "alphanum_fraction": 0.4246153846, "num_tokens": 939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012732322215, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7776275306061396}} {"text": "\nOptionalNat = ;\nTable = Nat -> OptionalNat;\n\nletrec fib:Table = (\n letrec plus : Nat->Nat->Nat = \n λ m:Nat n:Nat.\n if iszero m\n then n \n else plus (pred m) (succ n) \n in\n let prd2 = λ n:Nat. pred (pred n) in\n let opt = λ n:OptionalNat. \n case n of => m | => 0 in \n λ n:Nat. \n if iszero (pred n) then as OptionalNat \n else as OptionalNat\n ) in\n let f = λn:Nat. {n=n, fibn=fib n} in \n {f 2, f 8, f 10};\n", "meta": {"hexsha": "bb48fea9fc5b46b67314d3cea373aa1ad4a7e20a", "size": 591, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fullsimple/examples/fibonacci.f", "max_stars_repo_name": "null-lambda/TAPL-hs", "max_stars_repo_head_hexsha": "369679bda5bb166304d5e14ca0f259f030f06358", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-05T11:52:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-05T11:52:48.000Z", "max_issues_repo_path": "fullsimple/examples/fibonacci.f", "max_issues_repo_name": "null-lambda/TAPL-hs", "max_issues_repo_head_hexsha": "369679bda5bb166304d5e14ca0f259f030f06358", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fullsimple/examples/fibonacci.f", "max_forks_repo_name": "null-lambda/TAPL-hs", "max_forks_repo_head_hexsha": "369679bda5bb166304d5e14ca0f259f030f06358", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1428571429, "max_line_length": 81, "alphanum_fraction": 0.5025380711, "num_tokens": 214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9566342037088041, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7776166836572177}} {"text": "! **\n! * Provides Tauchen (1986)'s method for discretization of AR(1) processes\n! **\nmodule tauchen\n use kinds, only: dp\n use normal_cdf, only: cdf_normal\n implicit none\n private\n public :: tauchen_discretize\n\n contains\n\n ! **\n ! * Discretizes an AR(1) process using Tauchen (1986)'s method.\n ! * This function calculates Tauchen points for AR(1) x=(1-rho)mu0 + rho*x_(-1) + u,\n ! * the transition matrix and the CDF of the transition matrix.\n ! *\n ! * Input:\n ! * - rho: AR(1) autoregressive coefficient\n ! * - mu0: AR(1) autoregressive coefficient\n ! * - sigma: AR(1) standard deviation of white noise process u\n ! * - n: number of grid points\n ! * - cover_tauchen: number of standard deviations to be covered by the grid\n ! *\n ! * Output:\n ! * - y: discretized grid for the AR(1) variable\n ! * - pi: transition matrix of Markov chain\n ! * - picum: cumulative distribution function of the transition matrix\n ! **\n subroutine tauchen_discretize(y,pi,picum,rho,mu0,sigma,n,cover_tauchen)\n ! Adapted from sub_tauchen by Jesus Fernandez-Villaverde (undated)\n ! cover_tauchen is the number of SD (each side) that one wants\n ! to cover.\n\n ! April 10, 2013: Adapted by Carlo Zanella to use Applied Statistics\n ! algorithm as66 for computation of the normal cumulative distribution\n ! function.\n\n implicit none\n\n integer, intent(in) :: n\n\n real(dp), intent(in) :: rho, mu0, sigma, cover_tauchen\n real(dp), dimension (n,n), intent(out) :: pi , picum\n real(dp), dimension (n), intent(out) :: y\n\n integer :: yc, tc, tcc\n\n real(dp) :: sigy, mu, upp, low\n\n ! Define the discrete states of the Markov chain\n sigy = sigma/sqrt(1.0-rho**2)\n\n y(n) = mu0 + cover_tauchen*sigy\n y(1) = mu0 - cover_tauchen*sigy\n\n do yc = 2, n-1\n\n y(yc) = y(1)+(y(n)-y(1))*(yc-1.0)/(n-1.0)\n\n end do\n\n ! Compute the transition matrix\n\n do tc = 1,n\n mu = (1-rho)*mu0 + rho*y(tc)\n upp = (y(2)+y(1))/2.0\n upp = (upp-mu)/sigma\n pi(tc,1) = cdf_normal(X=upp)\n low = (y(n)+y(n-1))/2.0\n low = (low-mu)/sigma\n pi(tc,n) = 1.d0-cdf_normal(X=low)\n\n do tcc = 2, n-1\n\n low = (y(tcc-1)+y(tcc))/2.0\n upp = (y(tcc+1)+y(tcc))/2.0\n low = (low-mu)/sigma\n upp = (upp-mu)/sigma\n pi(tc,tcc) = cdf_normal(X=upp)-cdf_normal(X=low)\n\n end do\n end do\n\n ! Compute the CDF of the transition matrix.\n picum(:,1)=pi(:,1)\n do tc = 2,n\n picum(:,tc)=picum(:,tc-1)+pi(:,tc)\n enddo\n\n end subroutine tauchen_discretize\n\n\nend module tauchen\n", "meta": {"hexsha": "be3ce939bd8b9aa48719523dccadf4c03710c6de", "size": 3094, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tauchen.f90", "max_stars_repo_name": "carlozanella/ncegm", "max_stars_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-03-14T23:31:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-14T23:31:35.000Z", "max_issues_repo_path": "tauchen.f90", "max_issues_repo_name": "carlozanella/ncegm", "max_issues_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tauchen.f90", "max_forks_repo_name": "carlozanella/ncegm", "max_forks_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.5684210526, "max_line_length": 92, "alphanum_fraction": 0.5071105365, "num_tokens": 861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392797, "lm_q2_score": 0.8311430499496095, "lm_q1q2_score": 0.7774067494514838}} {"text": "function func(x)\nreal*8::func,x\nfunc=sin(x)\nend \nprogram integracion\nimplicit none\nexternal func\n!REGLA TRAPECIO compuesta, necesito una func, un punto inicial 'a', uno final 'b', la cantidad de puntos 'n' incluyendo a y b\n!se necesita un vector x(i)\nREAL*8::h,a,b,func,U,suma,SUMA1,SUMA2,UU,UUU,UUUU,integral,con1,con2,con3,summa\nINTEGER*4::i,n,k,nn,mm,j \t\nREAL*8,ALLOCATABLE,DIMENSION(:)::P,xx,AC,BD,w,hh\nREAL*8,ALLOCATABLE,DIMENSION(:,:)::r\na=0d1\nb= acos(-1.0)\nn=5\n\nh=abs(b-a)/(n-1)\nsuma=0d1\nallocate(P(n))\ndo i=1,(n-2)\n P(i)=a+h*i\n suma=suma+func(P(i))\nend do\n\nU=h*(func(a)+func(b))/2+h*suma\nprint*, U, 'U'\n!regla de simsomp de 3 puntos,\n\nif (n==3) then\ndo i=1,(n-2)\n P(i)=a+h*i\n suma=suma+func(P(i))\nend do\nUU=(h/3)*(func(a)+4*func(P(1))+func(b))\nprint*, UU, '2U'\nelse if (n>3) then\n!regla de simpson 3/8\nUUU=((3*h)/8)*(func(a)+func(b)+ 3*(func(a+abs(b-a)/3)+func(a+2*abs(b-a)/3)))\n!REGLA DE SIMSOPS COMPUESTA\nSUMA1=0d1\nSUMA2=0d1\ndo i=1,INT(n/2)\nif (i==INT(n/2)) then\nSUMA1=SUMA1+func(P(i*2-1))\nelse\nSUMA2=SUMA2+func(P(i*2))\nSUMA1=SUMA1+func(P(i*2-1))\nend if\nend do\n\nUUUU=(h/3)*(func(a)+func(b)+4*SUMA1+2*SUMA2)\nprint*, UUU , '3U'\nelse \nprint*, 'se usa la del trapecio'\nend if\n!REGLA DE NEWTON CONTES 2DO ORDEN\n !determinacion de los w(k) en un intervalo b,a con tres puntos\n allocate(xx(3),AC(2),BD(2),w(3))\n \n xx(0)=0d1\n xx(1)=5d0\n xx(2)=1d1\n do k = 0,2\n \n do i = 0,2\n if (i.ne.k) then\n \tif (i>k) then\n \tAC(i) = (xx(k)-xx(i))\n \tBD(i)=(xx(i))/(xx(k)-xx(i)) \n \tELSE\n \tAC(i-1) = (xx(k)-xx(i))\n \tBD(i-1)=(xx(i))/(xx(k)-xx(i))\n \tend if\n else\n end if\n end do\n \n \n con1=AC(1)*AC(2)\n con2=(BD(2)/AC(1))+(BD(1)/AC(2))\n con3=BD(1)*BD(2)\n \n W(k)=((b-a)**3)/(3*con1)-(((b-a)**2)/2)*con2+(b-a)*con3\n \n end do\n \n integral=0\n do i=0,2\n integral=w(i)*func(xx(i))+integral\n end do\n print*, integral,'los w son',w(0),w(1),w(2)\n \n !------------------------------------------------\n !integracion romberg\n !obtenes una matriz R(nn,mm) donde necesito una funcion que se pueda derivar muhco, un valor inicial, uno final y la cantidad de nn y mm del romberg que quiero.\n nn=6\n mm=6\n allocate(r(nn,mm),hh(nn)) \n r(0,0)=(1./2.)*(b-a)*(func(a)+func(b))\n print*, 'a',(1./2.)*(b-a)*(func(a)-func(b)),b,a\n do j=1,6\n do k=1,6\n hh(k)=(b-a)/(2**k)\n summa=0\n do i=1,(2**(k-1))\n summa=summa+func(a+(2*i-1)*hh(k))\n end do\n r(k,0)=(1./2.)*r(k-1,0)+hh(k)*summa\n r(k,j)=(1./((4**j)-1))*((4**j)*(r(k,j-1))-r(k-1,j-1))\n end do\n end do\n print*, 'r'\n do i=1,nn\n print*,r(:,i)\n end do\n print*, 'el r(6,6) es ', r(6,6)\nend program\n", "meta": {"hexsha": "7ce323e782b89a66c5e78b8e954ec592ac6b3dfe", "size": 2494, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fedora/integracion.f90", "max_stars_repo_name": "patricio-c/fortran", "max_stars_repo_head_hexsha": "da11f9e06010399703e8d8e51f57c44a7663857f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fedora/integracion.f90", "max_issues_repo_name": "patricio-c/fortran", "max_issues_repo_head_hexsha": "da11f9e06010399703e8d8e51f57c44a7663857f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fedora/integracion.f90", "max_forks_repo_name": "patricio-c/fortran", "max_forks_repo_head_hexsha": "da11f9e06010399703e8d8e51f57c44a7663857f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.9579831933, "max_line_length": 161, "alphanum_fraction": 0.590617482, "num_tokens": 1120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545304202038, "lm_q2_score": 0.8198933293122507, "lm_q1q2_score": 0.7773855746487146}} {"text": "program secant\nimplicit none\ndouble precision p1,p0,p2,q1,q0,q2,tol,f\ninteger i,imax\nimax=20\ntol=1.d-7\nwrite(*,*) 'tol=',tol\np0=0.1\np1=0.3\nq0=f(p0)\nq1=f(p1)\nwrite(*,*) ' i p_i |p_i - p_i-1| '\ndo i=1,imax \n p2=p1-q1*(p1-p0)/(q1-q0)\n q2=f(p2)\n write(*,*) i,p2,dabs(p2-p1)\n if (q1*q2 .lt. 0.) then\n write(8,*) i,'-'\n else\n write(8,*) i,'+'\n endif\n if (dabs(p2-p1) .lt. tol) then\n stop\n endif\n p0=p1\n p1=p2\n q0=q1\n q1=q2\nenddo\nstop\nend program secant\n\nfunction f(x)\ndouble precision x,f\nf= x + 1- 2 * dsin(pi * x)\nreturn\nend function f\n", "meta": {"hexsha": "018ada58625f5be961996299426f69472dcfb2e7", "size": 585, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Secant.f90", "max_stars_repo_name": "whisker-rebellion/Fortran", "max_stars_repo_head_hexsha": "65c0e064bcc92f33bc78cc89220a0298b3ee96be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Secant.f90", "max_issues_repo_name": "whisker-rebellion/Fortran", "max_issues_repo_head_hexsha": "65c0e064bcc92f33bc78cc89220a0298b3ee96be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Secant.f90", "max_forks_repo_name": "whisker-rebellion/Fortran", "max_forks_repo_head_hexsha": "65c0e064bcc92f33bc78cc89220a0298b3ee96be", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.3947368421, "max_line_length": 63, "alphanum_fraction": 0.5623931624, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582574225517, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.7773825503212655}} {"text": " subroutine mapc2m_twisted_torus(blockno,xc,yc,xp,yp,zp,alpha)\n implicit none\n\n integer blockno\n double precision xc,yc,xp,yp,zp\n double precision alpha, r\n\n double precision pi, pi2\n\n common /compi/ pi\n\n pi2 = 2*pi\n\n r = 1.d0 + alpha*cos(pi2*(yc + xc))\n\n xp = r*cos(pi2*xc)\n yp = r*sin(pi2*xc)\n zp = alpha*sin(pi2*(yc + xc))\n\n end\n", "meta": {"hexsha": "357bb2df11aff87cd361368c13d2aa3f37522cb7", "size": 397, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/mappings/torus/mapc2m_twisted_torus.f", "max_stars_repo_name": "mattzett/forestclaw", "max_stars_repo_head_hexsha": "8c2d012c259e0d9121e44c1ee78dfe2ab4839ec8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "src/mappings/torus/mapc2m_twisted_torus.f", "max_issues_repo_name": "mattzett/forestclaw", "max_issues_repo_head_hexsha": "8c2d012c259e0d9121e44c1ee78dfe2ab4839ec8", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "src/mappings/torus/mapc2m_twisted_torus.f", "max_forks_repo_name": "mattzett/forestclaw", "max_forks_repo_head_hexsha": "8c2d012c259e0d9121e44c1ee78dfe2ab4839ec8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 18.9047619048, "max_line_length": 67, "alphanum_fraction": 0.564231738, "num_tokens": 130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9591542852576265, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7773743205574348}} {"text": "program ex3p4a\r\n implicit none\r\n integer, parameter:: ik=selected_int_kind(11), rk=selected_real_kind(11,100)\r\n integer(kind=ik)::j\r\n real(kind=rk) :: res\r\n\r\n print'(\"Seq. 501...510, base 7\")'\r\n do j=1, 10\r\n res=korput(int(500+j,ik), int(7,ik))\r\n print '(i3,\": \",f6.4)',500+j, res\r\n end do\r\n print*\r\n\r\n print'(\"Seq. 501...510, base 13\")'\r\n do j=1, 10\r\n res=korput(int(500+j,ik), int(13,ik))\r\n print '(i3,\": \",f6.4)',500+j, res\r\n end do\r\n \r\n\r\ncontains\r\nreal(kind=rk) function korput(index, base)\r\n implicit none\r\n integer(kind=ik), intent(in) :: index, base\r\n integer(kind=ik) :: i\r\n real(kind=rk) :: f\r\n i=index\r\n korput=0\r\n f=1\r\n do \r\n if(i<=0) exit\r\n f = f/real(base, rk)\r\n korput = korput + f*(mod(i,base))\r\n i=floor(i/real(base, rk))\r\n end do\r\nend function korput\r\nend program ex3p4a", "meta": {"hexsha": "d80085536d0135e1d64256f622feefcf3a73a4a7", "size": 906, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Nico_Toikka_ex3/p4/ex3p4a.f95", "max_stars_repo_name": "toicca/basics-of-mc", "max_stars_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Nico_Toikka_ex3/p4/ex3p4a.f95", "max_issues_repo_name": "toicca/basics-of-mc", "max_issues_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Nico_Toikka_ex3/p4/ex3p4a.f95", "max_forks_repo_name": "toicca/basics-of-mc", "max_forks_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.4864864865, "max_line_length": 81, "alphanum_fraction": 0.5342163355, "num_tokens": 313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750413739075, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7771407785973916}} {"text": "C$Procedure VTMV ( Vector transpose times matrix times vector, 3 dim )\n \n DOUBLE PRECISION FUNCTION VTMV ( V1, MATRIX, V2 )\n \nC$ Abstract\nC\nC Multiply the transpose of a 3-dimensional column vector,\nC a 3x3 matrix, and a 3-dimensional column vector.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC MATRIX, VECTOR\nC\nC$ Declarations\n \n DOUBLE PRECISION V1 ( 3 )\n DOUBLE PRECISION MATRIX ( 3,3 )\n DOUBLE PRECISION V2 ( 3 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC V1 I 3 dimensional double precision column vector.\nC MATRIX I 3x3 double precision matrix.\nC V2 I 3 dimensional double precision column vector.\nC\nC The function returns the result of (V1**T * MATRIX * V2 ).\nC\nC$ Detailed_Input\nC\nC V1 This may be any 3-dimensional, double precision\nC column vector.\nC\nC MATRIX This may be any 3x3, double precision matrix.\nC\nC V2 This may be any 3-dimensional, double precision\nC column vector.\nC\nC$ Detailed_Output\nC\nC The function returns the double precision value of the equation\nC (V1**T * MATRIX * V2 ).\nC\nC Notice that VTMV is actually the dot product of the vector\nC resulting from multiplying the transpose of V1 and MATRIX and the\nC vector V2.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Particulars\nC\nC This routine implements the following vector/matrix/vector\nC multiplication:\nC\nC T\nC VTMV = | V1 | | | | |\nC | MATRIX | |V2|\nC | | | |\nC\nC V1 is a column vector which becomes a row vector when transposed.\nC V2 is a column vector.\nC\nC No checking is performed to determine whether floating point\nC overflow has occurred.\nC\nC$ Examples\nC\nC If V1 = | 2.0D0 | MATRIX = | 0.0D0 1.0D0 0.0D0 |\nC | | | |\nC | 4.0D0 | | -1.0D0 0.0D0 0.0D0 |\nC | | | |\nC | 6.0D0 | | 0.0D0 0.0D0 1.0D0 |\nC\nC V2 = | 1.0D0 |\nC | |\nC | 1.0D0 |\nC | |\nC | 1.0D0 |\nC\nC then function value is equal to 4.0D0.\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.M. Owen (JPL)\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WMO)\nC\nC-&\n \nC$ Index_Entries\nC\nC 3-dimensional vector_transpose times matrix times vector\nC\nC-&\n \n INTEGER K,L\n \n VTMV = 0.D0\n DO K=1,3\n DO L=1,3\n VTMV = VTMV + V1(K) * MATRIX(K,L) * V2(L)\n END DO\n END DO\n \n RETURN\n END\n", "meta": {"hexsha": "1b8c17e000cfa4d69ceac1b6d737659fbc341346", "size": 4495, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/vtmv.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/vtmv.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/vtmv.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 27.7469135802, "max_line_length": 72, "alphanum_fraction": 0.5973303671, "num_tokens": 1328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9559813526452771, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.777086006695101}} {"text": "subroutine MatrixEigenValues(N,C,Eigenvalues)\n use typre\n implicit none\n integer(ip) :: N\n real(rp) :: C(N,N), Eigenvalues(N)\n \n real(rp) :: Caux(N,N)\n \n INTEGER INFO, LWORK\n integer(ip) :: LDA\n integer(ip) :: LWMAX\n real(rp) :: WORK(N*N*5)\n\n Caux = C\n \n LWMAX = N*N\n LWORK = -1\n CALL DSYEV( 'Vectors', 'Upper', N, Caux, N, Eigenvalues, WORK, LWORK, INFO )\n LWORK = MIN( LWMAX, INT( WORK( 1 ) ) )\n\n !Solve eingenvalue problem\n CALL DSYEV( 'Vectors', 'Upper', N, Caux, N, EigenValues, WORK, LWORK, INFO )\n\n! IF( INFO.GT.0 ) THEN\n! call runend('Failed to compute eigenvalues')\n! END IF\n\n\nend subroutine \n", "meta": {"hexsha": "9af10a8089e4591e54e9867e50b7e8229b110525", "size": 711, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/mathru/matrixEigenvalues.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/mathru/matrixEigenvalues.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/mathru/matrixEigenvalues.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.7, "max_line_length": 82, "alphanum_fraction": 0.547116737, "num_tokens": 226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.95598134762883, "lm_q2_score": 0.8128673155708976, "lm_q1q2_score": 0.7770859917828962}} {"text": "PROGRAM hilbert\r\n\r\n! Demonstration program 1 using the 'quad' package.\r\n! Inversion of 10x10 Hilbert matrix by Cholesky factorization.\r\n\r\n! Matrix A has elements a(i,j) = 1/(i+j-1).\r\n! To obtain full accuracy, the elements are all multiplied by\r\n! 9 x 5 x 7 x 11 x 13 x 17 x 19 to make them into integers so\r\n! that the input matrix is exact. The elements of the inverse\r\n! will be multiplied by this integer at the end.\r\n\r\n! The elements of the inverse should all be integers.\r\n\r\n! Programmer: Alan Miller\r\n\r\n! Latest Fortran 77 revision - 13 September 1986\r\n! Fortran 90 version - 3 December 1996\r\n! Latest revision - 3 October 1999\r\n\r\nUSE quadruple_precision\r\nIMPLICIT NONE\r\n\r\nTYPE (quad) :: a(55), total, exact_start, exact, relerr\r\nREAL (dp) :: det, scale_factor = 14549535.d0\r\nINTEGER :: i, j, nrows = 10, ier, ipos, ik, k, kj, kjstart\r\n\r\nINTERFACE\r\n SUBROUTINE qchol(a, nrows, ier)\r\n USE quadruple_precision\r\n IMPLICIT NONE\r\n TYPE (quad), DIMENSION(:), INTENT(IN OUT) :: a\r\n INTEGER, INTENT(IN) :: nrows\r\n INTEGER, INTENT(OUT) :: ier\r\n END SUBROUTINE qchol\r\nEND INTERFACE\r\n\r\n! Enter the elements of the Hilbert matrix, storing them in a\r\n! 1-dimensional array up to the diagonal in each row.\r\n\r\nipos = 1\r\nDO i = 1, nrows\r\n DO j = 1, i\r\n a(ipos) = quad(scale_factor/(i+j-1), 0._dp)\r\n ipos = ipos + 1\r\n END DO\r\nEND DO\r\n\r\n! Get the Cholesky factorization.\r\n\r\nCALL qchol(a, nrows, ier)\r\nIF (ier /= 0) THEN\r\n WRITE(*, *) 'Error in qchol, number:', ier\r\n STOP\r\nEND IF\r\n\r\n! Calculate the determinant by multiplying together the diagonal elements\r\n! of the Cholesky factor, squaring the result, and remembering that each\r\n! element was multiplied by scale_factor.\r\n\r\nipos = 1\r\ndet = 1.d0\r\nDO i = 1, nrows\r\n det = det * a(ipos)%hi\r\n ipos = ipos + i + 1\r\nEND DO\r\ndet = det * det / scale_factor**nrows\r\nWRITE(*, 900) det\r\n900 FORMAT(' Determinant = ', g20.12/)\r\n\r\n! Now invert the triangular matrix.\r\n\r\nipos = 1\r\nDO i = 1, nrows\r\n kjstart = 1\r\n DO j = 1, i\r\n kj = kjstart\r\n ik = ipos\r\n IF (j < i) THEN\r\n total = quad(0._dp, 0._dp)\r\n DO k = j, i-1\r\n total = total - a(ik) * a(kj)\r\n ik = ik + 1\r\n kj = kj + k\r\n END DO\r\n a(ipos) = total / a(ik)\r\n ipos = ipos + 1\r\n ELSE\r\n a(ipos) = quad(1._dp, 0._dp) / a(ipos)\r\n ipos = ipos + 1\r\n END IF\r\n kjstart = kjstart + j + 1\r\n END DO\r\nEND DO\r\n\r\n! We formed A = LL', so the inverse is L**(-T).L**(-1),\r\n! where L**(-T) denotes the transpose of the inverse.\r\n\r\nipos = 1\r\nkjstart = 1\r\nDO i = 1, nrows\r\n DO j = 1, i\r\n ik = ipos\r\n total = quad(0._dp, 0._dp)\r\n kj = kjstart\r\n DO k = i, nrows\r\n total = total + a(ik) * a(kj)\r\n ik = ik + k\r\n kj = kj + k\r\n END DO\r\n a(ipos) = total * scale_factor\r\n ipos = ipos + 1\r\n END DO\r\n kjstart = kjstart + i + 1\r\nEND DO\r\n\r\n! Output the result.\r\n! The exact values for an n x n matrix are:-\r\n\r\n! (-1)**(i+j).(n+i-1)!(n+j-1)!\r\n! -------------------------------------\r\n! (i+j-1)[(i-1)!(j-1)!]**2.(n-i)!(n-j)!\r\n\r\nWRITE(*, 910)\r\n910 FORMAT(' row col calculated exact Rel. error')\r\nipos = 1\r\nexact_start = quad(100._dp, 0._dp)\r\nDO i = 1, nrows\r\n exact = exact_start\r\n DO j = 1, i\r\n relerr = (a(ipos) - exact) / exact\r\n WRITE(*, 920) i, j, a(ipos)%hi, exact%hi, relerr%hi\r\n 920 FORMAT(2I4, 2F20.4, g14.5)\r\n exact = -exact * (10+j)*(10-j)*(i+j-1) / REAL((i+j)*j*j)\r\n ipos = ipos + 1\r\n END DO\r\n exact_start = -exact_start * (10+i)*(10-i) / REAL((i+1)*i)\r\nEND DO\r\n\r\nSTOP\r\nEND PROGRAM hilbert\r\n\r\n\r\n\r\nSUBROUTINE qchol(a, nrows, ier)\r\n\r\n! Quadruple-precision Cholesky factorization of a +ve definite symmetric\r\n! matrix, stored by rows up to the diagonal. The input matrix is\r\n! overwritten by the lower-triangular factor L, where A = LL'.\r\n\r\n! Arguments:\r\n! a(:) INPUT. Array containing the lower triangle of matrix A.\r\n! nrows INPUT. The number of rows (and columns) in A.\r\n! ier OUTPUT. Error indicator\r\n! = 0 if no error detected\r\n! = 1 if nrows < 1\r\n! = 2 if matrix not +ve definite\r\n\r\n! Programmer: Alan Miller\r\n\r\n! Latest revision - 12 September 1986\r\n! Fortran 90 version - 3 December 1996\r\n\r\nUSE quadruple_precision\r\nIMPLICIT NONE\r\n\r\nTYPE (quad), DIMENSION(:), INTENT(IN OUT) :: a\r\nINTEGER, INTENT(IN) :: nrows\r\nINTEGER, INTENT(OUT) :: ier\r\n\r\n! Local variables\r\n\r\nINTEGER :: i, j, ij, ikstart, jk, ik, k\r\nTYPE (quad) :: total\r\n\r\nIF (nrows <= 0) THEN\r\n ier = 1\r\n RETURN\r\nEND IF\r\n\r\nij = 1\r\nikstart = 1\r\nDO i = 1, nrows\r\n jk = 1\r\n DO j = 1, i\r\n ik = ikstart\r\n total = a(ij)\r\n\r\n! Form the sum a(i,j) - l(i,k).l(j,k)\r\n\r\n DO k = 1, j-1\r\n total = total - a(ik) * a(jk)\r\n ik = ik + 1\r\n jk = jk + 1\r\n END DO\r\n\r\n! On the diagonal l(i,i) = sqrt(total)\r\n! Off diagonal l(i,j) = total/l(j,j)\r\n\r\n IF (i == j) THEN\r\n IF (total%hi <= 0._dp) THEN\r\n ier = 2\r\n RETURN\r\n END IF\r\n a(ij) = SQRT(total)\r\n ELSE\r\n a(ij) = total / a(jk)\r\n jk = jk + 1\r\n END IF\r\n ij = ij + 1\r\n END DO\r\n\r\n! ikstart = location of first element in row i.\r\n\r\n ikstart = ij\r\nEND DO\r\nier = 0\r\n\r\nRETURN\r\nEND SUBROUTINE qchol\r\n", "meta": {"hexsha": "ceb29bd62e21391232412e48565c6aa6f82efcd8", "size": 5244, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/hilbert.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/hilbert.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/hilbert.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 23.8363636364, "max_line_length": 76, "alphanum_fraction": 0.5682684973, "num_tokens": 1763, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723468, "lm_q2_score": 0.8418256412990658, "lm_q1q2_score": 0.77703804356324}} {"text": "module wavelet\n private i4_wrap, i4_modp, i4_reflect, i4_periodic\n\n real(kind=4), parameter :: zero = 1.0E-05\n\n integer(kind=4), parameter :: p = 3\n\n real(kind=4), dimension(0:p) :: c = (/ &\n 0.4829629131445341E+00, &\n 0.8365163037378079E+00, &\n 0.2241438680420133E+00, &\n -0.1294095225512603E+00/)\ncontains\n subroutine daub4_transform(n, x, y)\n\n!*****************************************************************************80\n!\n!! DAUB4_TRANSFORM computes the DAUB4 transform of a vector.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 July 2011\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the dimension of the vector.\n! N must be a power of 2 and at least 4.\n!\n! Input, real ( kind = 4 ) X(N), the vector to be transformed.\n!\n! Output, real ( kind = 4 ) Y(N), the transformed vector.\n!\n implicit none\n\n integer(kind=4) n\n integer(kind=4), parameter :: p = 3\n\n real(kind=4), dimension(0:p) :: c = (/ &\n 0.4829629131445341E+00, &\n 0.8365163037378079E+00, &\n 0.2241438680420133E+00, &\n -0.1294095225512603E+00/)\n integer(kind=4) i\n integer(kind=4) j\n integer(kind=4) j0\n integer(kind=4) j1\n integer(kind=4) j2\n integer(kind=4) j3\n integer(kind=4) m\n real(kind=4) x(n)\n real(kind=4) y(n)\n real(kind=4) z(n)\n\n y(1:n) = x(1:n)\n z(1:n) = 0.0E+00\n\n m = n\n\n do while (4 <= m)\n\n i = 1\n\n do j = 1, m - 1, 2\n\n j0 = i4_periodic(j, 1, m)\n j1 = i4_periodic(j + 1, 1, m)\n j2 = i4_periodic(j + 2, 1, m)\n j3 = i4_periodic(j + 3, 1, m)\n\n z(i) = c(0)*y(j0) + c(1)*y(j1) &\n + c(2)*y(j2) + c(3)*y(j3)\n\n z(i + m/2) = c(3)*y(j0) - c(2)*y(j1) &\n + c(1)*y(j2) - c(0)*y(j3)\n\n i = i + 1\n\n end do\n\n y(1:m) = z(1:m)\n\n m = m/2\n\n end do\n\n return\n end subroutine daub4_transform\n\n subroutine daub4_transform_inverse(n, y, x)\n\n!*****************************************************************************80\n!\n!! DAUB4_TRANSFORM_INVERSE inverts the DAUB4 transform of a vector.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 July 2011\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the dimension of the vector.\n! N must be a power of 2 and at least 4.\n!\n! Input, real ( kind = 4 ) Y(N), the transformed vector.\n!\n! Output, real ( kind = 4 ) X(N), the original vector.\n!\n implicit none\n\n integer(kind=4) n\n integer(kind=4), parameter :: p = 3\n\n real(kind=4), dimension(0:p) :: c = (/ &\n 0.4829629131445341E+00, &\n 0.8365163037378079E+00, &\n 0.2241438680420133E+00, &\n -0.1294095225512603E+00/)\n integer(kind=4) i\n integer(kind=4) i0\n integer(kind=4) i1\n integer(kind=4) i2\n integer(kind=4) i3\n integer(kind=4) j\n integer(kind=4) m\n real(kind=4) x(n)\n real(kind=4) y(n)\n real(kind=4) z(n)\n\n x(1:n) = y(1:n)\n z(1:n) = 0.0E+00\n\n m = 4\n\n do while (m <= n)\n\n j = 1\n\n do i = 0, m/2 - 1\n\n i0 = i4_periodic(i, 1, m/2)\n i2 = i4_periodic(i + 1, 1, m/2)\n\n i1 = i4_periodic(i + m/2, m/2 + 1, m)\n i3 = i4_periodic(i + m/2 + 1, m/2 + 1, m)\n\n z(j) = c(2)*x(i0) + c(1)*x(i1) &\n + c(0)*x(i2) + c(3)*x(i3)\n\n z(j + 1) = c(3)*x(i0) - c(0)*x(i1) &\n + c(1)*x(i2) - c(2)*x(i3)\n\n j = j + 2\n\n end do\n\n x(1:m) = z(1:m)\n\n m = m*2\n\n end do\n\n return\n end subroutine daub4_transform_inverse\n\n function i4_modp(i, j)\n\n !*****************************************************************************80\n !\n !! I4_MODP returns the nonnegative remainder of I4 division.\n !\n ! Discussion:\n !\n ! If\n ! NREM = I4_MODP ( I, J )\n ! NMULT = ( I - NREM ) / J\n ! then\n ! I = J * NMULT + NREM\n ! where NREM is always nonnegative.\n !\n ! The MOD function computes a result with the same sign as the\n ! quantity being divided. Thus, suppose you had an angle A,\n ! and you wanted to ensure that it was between 0 and 360.\n ! Then mod(A,360) would do, if A was positive, but if A\n ! was negative, your result would be between -360 and 0.\n !\n ! On the other hand, I4_MODP(A,360) is between 0 and 360, always.\n !\n ! An I4 is an integer ( kind = 4 ) value.\n !\n ! Example:\n !\n ! I J MOD I4_MODP Factorization\n !\n ! 107 50 7 7 107 = 2 * 50 + 7\n ! 107 -50 7 7 107 = -2 * -50 + 7\n ! -107 50 -7 43 -107 = -3 * 50 + 43\n ! -107 -50 -7 43 -107 = 3 * -50 + 43\n !\n ! Licensing:\n !\n ! This code is distributed under the GNU LGPL license.\n !\n ! Modified:\n !\n ! 02 March 1999\n !\n ! Author:\n !\n ! John Burkardt\n !\n ! Parameters:\n !\n ! Input, integer ( kind = 4 ) I, the number to be divided.\n !\n ! Input, integer ( kind = 4 ) J, the number that divides I.\n !\n ! Output, integer ( kind = 4 ) I4_MODP, the nonnegative remainder when I is\n ! divided by J.\n !\n implicit none\n\n integer(kind=4), intent(in) :: i\n integer(kind=4) i4_modp\n integer(kind=4), intent(in) :: j\n integer(kind=4) value\n\n if (j == 0) then\n write (*, '(a)') ' '\n write (*, '(a)') 'I4_MODP - Fatal error!'\n write (*, '(a,i8)') ' Illegal divisor J = ', j\n stop\n end if\n\n value = mod(i, j)\n\n if (value < 0) then\n value = value + abs(j)\n end if\n\n i4_modp = value\n\n return\n end function i4_modp\n\n function i4_wrap(ival, ilo, ihi)\n\n !*****************************************************************************80\n !\n !! I4_WRAP forces an I4 to lie between given limits by wrapping.\n !\n ! Discussion:\n !\n ! An I4 is an integer ( kind = 4 ) value.\n !\n ! There appears to be a bug in the GFORTRAN compiler which can lead to\n ! erroneous results when the first argument of I4_WRAP is an expression.\n ! In particular:\n !\n ! do i = 1, 3\n ! if ( test ) then\n ! i4 = i4_wrap ( i + 1, 1, 3 )\n ! end if\n ! end do\n !\n ! was, when I = 3, returning I4 = 3. So I had to replace this with\n !\n ! do i = 1, 3\n ! if ( test ) then\n ! i4 = i + 1\n ! i4 = i4_wrap ( i4, 1, 3 )\n ! end if\n ! end do\n !\n ! Example:\n !\n ! ILO = 4, IHI = 8\n !\n ! I Value\n !\n ! -2 8\n ! -1 4\n ! 0 5\n ! 1 6\n ! 2 7\n ! 3 8\n ! 4 4\n ! 5 5\n ! 6 6\n ! 7 7\n ! 8 8\n ! 9 4\n ! 10 5\n ! 11 6\n ! 12 7\n ! 13 8\n ! 14 4\n !\n ! Licensing:\n !\n ! This code is distributed under the GNU LGPL license.\n !\n ! Modified:\n !\n ! 07 September 2009\n !\n ! Author:\n !\n ! John Burkardt\n !\n ! Parameters:\n !\n ! Input, integer ( kind = 4 ) IVAL, a value.\n !\n ! Input, integer ( kind = 4 ) ILO, IHI, the desired bounds.\n !\n ! Output, integer ( kind = 4 ) I4_WRAP, a \"wrapped\" version of the value.\n !\n implicit none\n\n integer(kind=4) i4_wrap\n integer(kind=4), intent(in) :: ihi\n integer(kind=4), intent(in) :: ilo\n integer(kind=4), intent(in) :: ival\n integer(kind=4) jhi\n integer(kind=4) jlo\n integer(kind=4) value\n integer(kind=4) wide\n\n jlo = min(ilo, ihi)\n jhi = max(ilo, ihi)\n\n wide = jhi - jlo + 1\n\n if (wide == 1) then\n value = jlo\n else\n value = jlo + i4_modp(ival - jlo, wide)\n end if\n\n i4_wrap = value\n\n return\n end function i4_wrap\n\n elemental function i4_reflect(ival, ilo, ihi)\n integer(kind=4) :: i4_reflect\n integer(kind=4), intent(in) :: ival, ilo, ihi\n integer(kind=4) :: value\n integer(kind=4) :: dist\n\n ! the default return value\n value = ival\n\n ! the upper boundary\n if (ival .gt. ihi) then\n dist = ival - ihi\n value = ihi - (dist - 1)\n end if\n\n ! the lower boundary\n if (ival .lt. ilo) then\n dist = ilo - ival\n value = ilo + (dist - 1)\n end if\n\n i4_reflect = value\n\n return\n end function i4_reflect\n\n elemental function i4_periodic(ival, ilo, ihi)\n integer(kind=4) :: i4_periodic\n integer(kind=4), intent(in) :: ival, ilo, ihi\n integer(kind=4) :: value\n integer(kind=4) :: dist\n\n ! the default return value\n value = ival\n\n ! the upper boundary\n if (ival .gt. ihi) then\n dist = ival - ihi\n value = ilo + (dist - 1)\n end if\n\n ! the lower boundary\n if (ival .lt. ilo) then\n dist = ilo - ival\n value = ihi - (dist - 1)\n end if\n\n i4_periodic = value\n\n return\n end function i4_periodic\n\n subroutine daub4_2Dtransform(n, x, y, mask, create_mask)\n!********************************\n! a 2D DAUB4 wavelet transform of a square floating-point matrix\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Author:\n!\n! Christopher Zapart, based on the 1D code by John Burkardt\n!\n! Input, integer (kind = 4) N, the dimension of the square block N x N\n! N must be a power of 2 and at least 4.\n!\n! Input, real (kind = 4) X(N,N), the original square matrix to be transformed\n!\n! Output, real (kind = 4) Y(N,N), the wavelet-transformed matrix\n!\n! Output, logical mask(N,N), a boolean matrix where .false. indicates NaN values in X\n!\n! Input: logical create_mask - whether or not to creater or re-use the given mask\n! instead of creating it from scratch\n!\n implicit none\n\n integer(kind=4) :: n\n integer(kind=4), parameter :: p = 3\n real(kind=4), parameter :: zero = 1.0E-05\n\n real(kind=4), dimension(0:p) :: c = (/ &\n 0.4829629131445341E+00, &\n 0.8365163037378079E+00, &\n 0.2241438680420133E+00, &\n -0.1294095225512603E+00/)\n integer(kind=4) i\n integer(kind=4) j\n integer(kind=4) j0\n integer(kind=4) j1\n integer(kind=4) j2\n integer(kind=4) j3\n\n integer(kind=4) m\n real(kind=4), dimension(n, n), intent(in) :: x\n real(kind=4), dimension(n, n), intent(out) :: y\n logical(kind=1), optional, dimension(n, n), intent(inout) :: mask\n logical, optional, intent(in) :: create_mask\n real(kind=4), dimension(n) :: z\n real(kind=4) average\n integer(kind=4) nvalid\n integer(kind=4) k\n\n y = x\n z = 0.0E+00\n\n if (present(mask)) then\n block\n logical need_mask\n\n if (present(create_mask)) then\n need_mask = create_mask\n else\n need_mask = .true.\n end if\n\n if (need_mask) then\n ! pick out all the NaN\n where (isnan(x))\n mask = .false.\n elsewhere\n mask = .true.\n end where\n end if\n\n ! calculate the mean of the input array\n nvalid = count(mask)\n\n ! all values might be NaN in which case set the array to 0.0\n if (nvalid .gt. 0) then\n average = sum(x, mask=mask)/nvalid\n else\n average = 0.0\n end if\n\n ! replace NaNs with the average value\n where (.not. mask) y = average\n end block\n end if\n\n m = n\n\n ! for each level\n do while (m .ge. 4)\n ! transform all the rows\n do k = 1, m\n i = 1\n\n do j = 1, m - 1, 2\n\n j0 = i4_periodic(j, 1, m)\n j1 = i4_periodic(j + 1, 1, m)\n j2 = i4_periodic(j + 2, 1, m)\n j3 = i4_periodic(j + 3, 1, m)\n\n z(i) = c(0)*y(k, j0) + c(1)*y(k, j1) &\n + c(2)*y(k, j2) + c(3)*y(k, j3)\n\n z(i + m/2) = c(3)*y(k, j0) - c(2)*y(k, j1) &\n + c(1)*y(k, j2) - c(0)*y(k, j3)\n\n i = i + 1\n\n end do\n\n y(k, 1:m) = z(1:m)\n end do\n\n ! then the columns\n do k = 1, m\n i = 1\n\n do j = 1, m - 1, 2\n\n j0 = i4_periodic(j, 1, m)\n j1 = i4_periodic(j + 1, 1, m)\n j2 = i4_periodic(j + 2, 1, m)\n j3 = i4_periodic(j + 3, 1, m)\n\n z(i) = c(0)*y(j0, k) + c(1)*y(j1, k) &\n + c(2)*y(j2, k) + c(3)*y(j3, k)\n\n z(i + m/2) = c(3)*y(j0, k) - c(2)*y(j1, k) &\n + c(1)*y(j2, k) - c(0)*y(j3, k)\n\n i = i + 1\n\n end do\n\n y(1:m, k) = z(1:m)\n end do\n\n m = m/2\n end do\n\n ! truncate values near zero\n where (abs(y) < zero) y = 0.0\n\n return\n end subroutine daub4_2Dtransform\n\n subroutine daub4_2Dtransform_inv(n, y, x, mask)\n !********************************\n ! a 2D DAUB4 inverse wavelet transform of a square floating-point matrix\n !\n ! Licensing:\n !\n ! This code is distributed under the GNU LGPL license.\n !\n ! Author:\n !\n ! Christopher Zapart, based on the 1D code by John Burkardt\n !\n ! Input, integer (kind = 4) N, the dimension of the square block N x N\n ! N must be a power of 2 and at least 4.\n !\n ! Input, real (kind = 4) Y(N,N), the wavelet-transformed square matrix\n !\n ! Output, real (kind = 4) X(N,N), the original matrix\n !\n use, intrinsic :: ieee_arithmetic\n implicit none\n\n integer(kind=4) n\n integer(kind=4), parameter :: p = 3\n\n real(kind=4), dimension(0:p) :: c = (/ &\n 0.4829629131445341E+00, &\n 0.8365163037378079E+00, &\n 0.2241438680420133E+00, &\n -0.1294095225512603E+00/)\n integer(kind=4) i\n integer(kind=4) i0\n integer(kind=4) i1\n integer(kind=4) i2\n integer(kind=4) i3\n integer(kind=4) j\n integer(kind=4) m\n logical(kind=1), optional, dimension(n, n), intent(in) :: mask\n real(kind=4), dimension(n, n), intent(out) :: x\n real(kind=4), dimension(n, n), intent(in) :: y\n real(kind=4), dimension(n) :: z\n\n integer(kind=4) k\n\n x = y\n z = 0.0E+00\n\n m = 4\n\n ! for each level\n do while (m .le. n)\n ! reverse all the columns\n do k = 1, m\n j = 1\n\n do i = 0, m/2 - 1\n\n i0 = i4_periodic(i, 1, m/2)\n i2 = i4_periodic(i + 1, 1, m/2)\n\n i1 = i4_periodic(i + m/2, m/2 + 1, m)\n i3 = i4_periodic(i + m/2 + 1, m/2 + 1, m)\n\n z(j) = c(2)*x(i0, k) + c(1)*x(i1, k) &\n + c(0)*x(i2, k) + c(3)*x(i3, k)\n\n z(j + 1) = c(3)*x(i0, k) - c(0)*x(i1, k) &\n + c(1)*x(i2, k) - c(2)*x(i3, k)\n\n j = j + 2\n\n end do\n\n x(1:m, k) = z(1:m)\n end do\n\n ! then the rows\n do k = 1, m\n j = 1\n\n do i = 0, m/2 - 1\n\n i0 = i4_periodic(i, 1, m/2)\n i2 = i4_periodic(i + 1, 1, m/2)\n\n i1 = i4_periodic(i + m/2, m/2 + 1, m)\n i3 = i4_periodic(i + m/2 + 1, m/2 + 1, m)\n\n z(j) = c(2)*x(k, i0) + c(1)*x(k, i1) &\n + c(0)*x(k, i2) + c(3)*x(k, i3)\n\n z(j + 1) = c(3)*x(k, i0) - c(0)*x(k, i1) &\n + c(1)*x(k, i2) - c(2)*x(k, i3)\n\n j = j + 2\n\n end do\n\n x(k, 1:m) = z(1:m)\n end do\n\n m = m*2\n end do\n\n ! insert back NaN values\n if (present(mask)) then\n where (.not. mask) x = ieee_value(0.0, ieee_quiet_nan)\n end if\n\n return\n end subroutine daub4_2Dtransform_inv\n\n! in-place versions\n subroutine daub4_2Dtransform_inpl(n, x, mask, create_mask)\n !********************************\n ! a 2D DAUB4 wavelet transform of a square floating-point matrix (in-place)\n !\n ! Licensing:\n !\n ! This code is distributed under the GNU LGPL license.\n !\n ! Author:\n !\n ! Christopher Zapart, based on the 1D code by John Burkardt\n !\n ! Input, integer (kind = 4) N, the dimension of the square block N x N\n ! N must be a power of 2 and at least 4.\n !\n ! Input and Output, real (kind = 4) X(N,N), the original square matrix to be transformed\n !\n ! Output, logical mask(N,N), a boolean matrix where .false. indicates NaN values in X\n !\n ! the output is stored in-place\n !\n ! Input: logical create_mask - whether or not to creater or re-use the given mask\n ! instead of creating it from scratch\n !\n implicit none\n\n integer(kind=4) :: n\n integer(kind=4), parameter :: p = 3\n real(kind=4), parameter :: zero = 1.0E-05\n\n real(kind=4), dimension(0:p) :: c = (/ &\n 0.4829629131445341E+00, &\n 0.8365163037378079E+00, &\n 0.2241438680420133E+00, &\n -0.1294095225512603E+00/)\n integer(kind=4) i\n integer(kind=4) j\n integer(kind=4) j0\n integer(kind=4) j1\n integer(kind=4) j2\n integer(kind=4) j3\n\n integer(kind=4) m\n real(kind=4), dimension(n, n), intent(inout) :: x\n logical(kind=1), optional, dimension(n, n), intent(inout) :: mask\n logical, optional, intent(in) :: create_mask\n real(kind=4), dimension(n) :: z\n real(kind=4) average\n integer(kind=4) nvalid\n integer(kind=4) k\n\n z = 0.0E+00\n\n if (present(mask)) then\n block\n logical need_mask\n\n if (present(create_mask)) then\n need_mask = create_mask\n else\n need_mask = .true.\n end if\n\n if (need_mask) then\n ! pick out all the NaN\n where (isnan(x))\n mask = .false.\n elsewhere\n mask = .true.\n end where\n end if\n\n ! calculate the mean of the input array\n nvalid = count(mask)\n\n ! all values might be NaN in which case set the array to 0.0\n if (nvalid .gt. 0) then\n average = sum(x, mask=mask)/nvalid\n else\n average = 0.0\n end if\n\n ! replace NaNs with the average value\n where (.not. mask) x = average\n end block\n end if\n\n m = n\n\n ! for each level\n do while (m .ge. 4)\n ! transform all the rows\n do k = 1, m\n i = 1\n\n do j = 1, m - 1, 2\n\n j0 = i4_periodic(j, 1, m)\n j1 = i4_periodic(j + 1, 1, m)\n j2 = i4_periodic(j + 2, 1, m)\n j3 = i4_periodic(j + 3, 1, m)\n\n z(i) = c(0)*x(k, j0) + c(1)*x(k, j1) &\n + c(2)*x(k, j2) + c(3)*x(k, j3)\n\n z(i + m/2) = c(3)*x(k, j0) - c(2)*x(k, j1) &\n + c(1)*x(k, j2) - c(0)*x(k, j3)\n\n i = i + 1\n\n end do\n\n x(k, 1:m) = z(1:m)\n end do\n\n ! then the columns\n do k = 1, m\n i = 1\n\n do j = 1, m - 1, 2\n\n j0 = i4_periodic(j, 1, m)\n j1 = i4_periodic(j + 1, 1, m)\n j2 = i4_periodic(j + 2, 1, m)\n j3 = i4_periodic(j + 3, 1, m)\n\n z(i) = c(0)*x(j0, k) + c(1)*x(j1, k) &\n + c(2)*x(j2, k) + c(3)*x(j3, k)\n\n z(i + m/2) = c(3)*x(j0, k) - c(2)*x(j1, k) &\n + c(1)*x(j2, k) - c(0)*x(j3, k)\n\n i = i + 1\n\n end do\n\n x(1:m, k) = z(1:m)\n end do\n\n m = m/2\n end do\n\n ! truncate values near zero\n where (abs(x) .lt. zero) x = 0.0\n\n return\n end subroutine daub4_2Dtransform_inpl\n\n subroutine daub4_2Dtransform_inv_inpl(n, x, mask)\n !********************************\n ! a 2D DAUB4 inverse wavelet transform of a square floating-point matrix (in-place)\n !\n ! Licensing:\n !\n ! This code is distributed under the GNU LGPL license.\n !\n ! Author:\n !\n ! Christopher Zapart, based on the 1D code by John Burkardt\n !\n ! Input, integer (kind = 4) N, the dimension of the square block N x N\n ! N must be a power of 2 and at least 4.\n !\n ! Input and Output, real (kind = 4) X(N,N), the wavelet-transformed square matrix\n !\n ! the output is stored in-place in x\n !\n use, intrinsic :: ieee_arithmetic\n implicit none\n\n integer(kind=4) n\n integer(kind=4), parameter :: p = 3\n\n real(kind=4), dimension(0:p) :: c = (/ &\n 0.4829629131445341E+00, &\n 0.8365163037378079E+00, &\n 0.2241438680420133E+00, &\n -0.1294095225512603E+00/)\n integer(kind=4) i\n integer(kind=4) i0\n integer(kind=4) i1\n integer(kind=4) i2\n integer(kind=4) i3\n integer(kind=4) j\n integer(kind=4) m\n real(kind=4), dimension(n, n), intent(inout) :: x\n logical(kind=1), optional, dimension(n, n), intent(in) :: mask\n real(kind=4), dimension(n) :: z\n\n integer(kind=4) k\n\n z = 0.0E+00\n\n m = 4\n\n ! for each level\n do while (m .le. n)\n ! reverse all the columns\n do k = 1, m\n j = 1\n\n do i = 0, m/2 - 1\n\n i0 = i4_periodic(i, 1, m/2)\n i2 = i4_periodic(i + 1, 1, m/2)\n\n i1 = i4_periodic(i + m/2, m/2 + 1, m)\n i3 = i4_periodic(i + m/2 + 1, m/2 + 1, m)\n\n z(j) = c(2)*x(i0, k) + c(1)*x(i1, k) &\n + c(0)*x(i2, k) + c(3)*x(i3, k)\n\n z(j + 1) = c(3)*x(i0, k) - c(0)*x(i1, k) &\n + c(1)*x(i2, k) - c(2)*x(i3, k)\n\n j = j + 2\n\n end do\n\n x(1:m, k) = z(1:m)\n end do\n\n ! then the rows\n do k = 1, m\n j = 1\n\n do i = 0, m/2 - 1\n\n i0 = i4_periodic(i, 1, m/2)\n i2 = i4_periodic(i + 1, 1, m/2)\n\n i1 = i4_periodic(i + m/2, m/2 + 1, m)\n i3 = i4_periodic(i + m/2 + 1, m/2 + 1, m)\n\n z(j) = c(2)*x(k, i0) + c(1)*x(k, i1) &\n + c(0)*x(k, i2) + c(3)*x(k, i3)\n\n z(j + 1) = c(3)*x(k, i0) - c(0)*x(k, i1) &\n + c(1)*x(k, i2) - c(2)*x(k, i3)\n\n j = j + 2\n\n end do\n\n x(k, 1:m) = z(1:m)\n end do\n\n m = m*2\n end do\n\n ! insert back NaN values\n if (present(mask)) then\n where (.not. mask) x = ieee_value(0.0, ieee_quiet_nan)\n end if\n\n return\n end subroutine daub4_2Dtransform_inv_inpl\n\n pure subroutine to_daub4_block(x, mask, create_mask)\n !********************************\n ! a 2D DAUB4 wavelet transform of a square floating-point matrix (in-place)\n !\n ! Licensing:\n !\n ! This code is distributed under the GNU LGPL license.\n !\n ! Author:\n !\n ! Christopher Zapart, based on the 1D code by John Burkardt\n !\n ! Fixed block dimension N = 4, the dimension of the square block 4 x 4\n !\n ! Input and Output, real (kind = 4) X(4,4), the original square matrix to be transformed\n !\n ! Output, logical mask(4,4), a boolean matrix where .false. indicates NaN values in X\n !\n ! the output is stored in-place\n !\n ! Input: logical create_mask - whether or not to creater or re-use the given mask\n ! instead of creating it from scratch\n !\n implicit none\n\n integer(kind=4) i\n integer(kind=4) j\n integer(kind=4) j0\n integer(kind=4) j1\n integer(kind=4) j2\n integer(kind=4) j3\n\n real(kind=4), dimension(4, 4), intent(inout) :: x\n logical(kind=1), optional, dimension(4, 4), intent(inout) :: mask\n logical, optional, intent(in) :: create_mask\n real(kind=4), dimension(4) :: z\n real(kind=4) average\n integer(kind=4) nvalid\n integer(kind=4) k\n\n z = 0.0E+00\n\n if (present(mask)) then\n block\n logical need_mask\n\n if (present(create_mask)) then\n need_mask = create_mask\n else\n need_mask = .true.\n end if\n\n if (need_mask) then\n ! pick out all the NaN\n where (isnan(x))\n mask = .false.\n elsewhere\n mask = .true.\n end where\n end if\n\n ! calculate the mean of the input array\n nvalid = count(mask)\n\n ! all values might be NaN in which case set the array to 0.0\n if (nvalid .gt. 0) then\n average = sum(x, mask=mask)/nvalid\n else\n average = 0.0\n end if\n\n ! replace NaNs with the average value\n where (.not. mask) x = average\n end block\n end if\n\n ! do only one iteration as n .eq. 4\n\n ! transform all the rows\n do k = 1, 4\n i = 1\n\n do j = 1, 4 - 1, 2\n\n j0 = i4_periodic(j, 1, 4)\n j1 = i4_periodic(j + 1, 1, 4)\n j2 = i4_periodic(j + 2, 1, 4)\n j3 = i4_periodic(j + 3, 1, 4)\n\n z(i) = c(0)*x(k, j0) + c(1)*x(k, j1) &\n + c(2)*x(k, j2) + c(3)*x(k, j3)\n\n z(i + 2) = c(3)*x(k, j0) - c(2)*x(k, j1) &\n + c(1)*x(k, j2) - c(0)*x(k, j3)\n\n i = i + 1\n\n end do\n\n x(k, 1:4) = z(1:4)\n end do\n\n ! then the columns\n do k = 1, 4\n i = 1\n\n do j = 1, 4 - 1, 2\n\n j0 = i4_periodic(j, 1, 4)\n j1 = i4_periodic(j + 1, 1, 4)\n j2 = i4_periodic(j + 2, 1, 4)\n j3 = i4_periodic(j + 3, 1, 4)\n\n z(i) = c(0)*x(j0, k) + c(1)*x(j1, k) &\n + c(2)*x(j2, k) + c(3)*x(j3, k)\n\n z(i + 2) = c(3)*x(j0, k) - c(2)*x(j1, k) &\n + c(1)*x(j2, k) - c(0)*x(j3, k)\n\n i = i + 1\n\n end do\n\n x(1:4, k) = z(1:4)\n end do\n\n ! truncate values near zero\n where (abs(x) .lt. zero) x = 0.0\n\n return\n end subroutine to_daub4_block\n\n pure subroutine from_daub4_block(x, mask)\n !********************************\n ! a 2D DAUB4 inverse wavelet transform of a square floating-point matrix (in-place)\n !\n ! Licensing:\n !\n ! This code is distributed under the GNU LGPL license.\n !\n ! Author:\n !\n ! Christopher Zapart, based on the 1D code by John Burkardt\n !\n ! Fixed block dimension N = 4, the dimension of the square block 4 x 4\n !\n ! Input and Output, real (kind = 4) X(4,4), the wavelet-transformed square matrix\n !\n ! the output is stored in-place in x\n !\n use, intrinsic :: ieee_arithmetic\n implicit none\n\n integer(kind=4) i\n integer(kind=4) i0\n integer(kind=4) i1\n integer(kind=4) i2\n integer(kind=4) i3\n integer(kind=4) j\n real(kind=4), dimension(4, 4), intent(inout) :: x\n logical(kind=1), optional, dimension(4, 4), intent(in) :: mask\n real(kind=4), dimension(4) :: z\n\n integer(kind=4) k\n\n z = 0.0E+00\n\n ! do only one iteration as n .eq. 4\n\n ! reverse all the columns\n do k = 1, 4\n j = 1\n\n do i = 0, 2 - 1\n\n i0 = i4_periodic(i, 1, 2)\n i2 = i4_periodic(i + 1, 1, 2)\n\n i1 = i4_periodic(i + 2, 2 + 1, 4)\n i3 = i4_periodic(i + 2 + 1, 2 + 1, 4)\n\n z(j) = c(2)*x(i0, k) + c(1)*x(i1, k) &\n + c(0)*x(i2, k) + c(3)*x(i3, k)\n\n z(j + 1) = c(3)*x(i0, k) - c(0)*x(i1, k) &\n + c(1)*x(i2, k) - c(2)*x(i3, k)\n\n j = j + 2\n\n end do\n\n x(1:4, k) = z(1:4)\n end do\n\n ! then the rows\n do k = 1, 4\n j = 1\n\n do i = 0, 2 - 1\n\n i0 = i4_periodic(i, 1, 2)\n i2 = i4_periodic(i + 1, 1, 2)\n\n i1 = i4_periodic(i + 2, 2 + 1, 4)\n i3 = i4_periodic(i + 2 + 1, 2 + 1, 4)\n\n z(j) = c(2)*x(k, i0) + c(1)*x(k, i1) &\n + c(0)*x(k, i2) + c(3)*x(k, i3)\n\n z(j + 1) = c(3)*x(k, i0) - c(0)*x(k, i1) &\n + c(1)*x(k, i2) - c(2)*x(k, i3)\n\n j = j + 2\n\n end do\n\n x(k, 1:4) = z(1:4)\n end do\n\n ! insert back NaN values\n if (present(mask)) then\n where (.not. mask) x = ieee_value(0.0, ieee_quiet_nan)\n end if\n\n return\n end subroutine from_daub4_block\n\n subroutine wave_shrink(n, x)\n implicit none\n\n integer(kind=4) :: n\n real(kind=4), dimension(n, n), intent(inout) :: x\n integer(kind=4) :: i, j, nvalid\n real(kind=4) mean, std, tmp\n\n if (n .lt. 4) return\n\n ! calculate the mean and standard deviation of\n ! absolute values of detail coefficients (skipping the coarse coeffs)\n\n mean = 0.0\n std = 0.0\n nvalid = 0\n\n ! the mean\n do j = 1, n\n do i = 1, n\n ! skip the coarse coefficients\n if ((i .le. 4/2) .and. (j .le. 4/2)) cycle\n\n tmp = abs(x(i, j))\n ! only process non-zero values\n if (tmp .gt. 0.0) then\n mean = mean + tmp\n nvalid = nvalid + 1\n end if\n end do\n end do\n\n if (nvalid .gt. 0) then\n mean = mean/nvalid\n else\n return\n end if\n\n ! do nothing if all values are 0.0\n if (mean .eq. 0.0) return\n\n ! the standard deviation\n do j = 1, n\n do i = 1, n\n ! skip the coarse coefficients\n if ((i .le. 2) .and. (j .le. 2)) cycle\n\n tmp = abs(x(i, j))\n ! only process non-zero values\n if (tmp .gt. 0.0) std = std + (tmp - mean)**2\n end do\n end do\n\n if ((nvalid - 1) .gt. 0) then\n std = sqrt(std/(nvalid - 1))\n else if (nvalid .gt. 0) then\n ! nvalid .eq. 1 at this point (there is no point in dividing by 1)\n std = sqrt(std/nvalid)\n else\n return\n end if\n\n print *, '[wave_shrink] mean:', mean, 'std:', std\n\n ! prune (shrink the coefficients)\n do j = 1, n\n do i = 1, n\n ! skip the coarse coefficients\n if ((i .le. 2) .and. (j .le. 2)) cycle\n\n ! set the small coefficients (one half to be precise) to 0.0\n if (abs(x(i, j)) .le. mean - 0.5*std) x(i, j) = 0.0\n end do\n end do\n\n end subroutine wave_shrink\n\n subroutine wave_shrink2(n, x)\n implicit none\n\n integer(kind=4) :: n\n real(kind=4), dimension(n, n), intent(inout) :: x\n integer(kind=4) :: i, j, nvalid\n real(kind=4) mean, std, tmp\n\n if (n .lt. 4) return\n\n ! calculate the mean and standard deviation of\n ! of detail coefficients (skipping the coarse coeffs)\n\n mean = 0.0\n std = 0.0\n\n ! the mean\n do j = 1, n\n do i = 1, n\n ! skip the coarse coefficients\n if ((i .le. 4/2) .and. (j .le. 4/2)) cycle\n\n mean = mean + x(i, j)\n nvalid = nvalid + 1\n end do\n end do\n\n if (nvalid .gt. 0) then\n mean = mean/nvalid\n else\n return\n end if\n\n ! do nothing if all values are 0.0\n if (mean .eq. 0.0) return\n\n ! the standard deviation\n do j = 1, n\n do i = 1, n\n ! skip the coarse coefficients\n if ((i .le. 2) .and. (j .le. 2)) cycle\n\n tmp = x(i, j)\n std = std + (tmp - mean)*(tmp - mean)\n end do\n end do\n\n if ((nvalid - 1) .gt. 0) then\n std = sqrt(std/(nvalid - 1))\n else if (nvalid .gt. 0) then\n ! I know nvalid .eq. 1 at this point (there is no point dividing by 1)\n std = sqrt(std/nvalid)\n else\n return\n end if\n\n print *, 'mean:', mean, 'std:', std\n\n ! prune (shrink the coefficients)\n do j = 1, n\n do i = 1, n\n ! skip the coarse coefficients\n if ((i .le. 2) .and. (j .le. 2)) cycle\n\n ! set the small coefficients to 0.0\n tmp = x(i, j)\n if ((tmp .gt. (mean - 0.25*std)) .and. (tmp .lt. (mean + 0.25*std))) x(i, j) = 0.0\n end do\n end do\n\n end subroutine wave_shrink2\nend module wavelet\n", "meta": {"hexsha": "c0b196c3ecbecb4b13f5ccf54fa2d5a681300dcb", "size": 36739, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src_bak/wavelet.f90", "max_stars_repo_name": "jvo203/FITSWEBQLSE", "max_stars_repo_head_hexsha": "3b2b3c74d623c3510cfa81a4e30ac5bd0af48cb0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src_bak/wavelet.f90", "max_issues_repo_name": "jvo203/FITSWEBQLSE", "max_issues_repo_head_hexsha": "3b2b3c74d623c3510cfa81a4e30ac5bd0af48cb0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src_bak/wavelet.f90", "max_forks_repo_name": "jvo203/FITSWEBQLSE", "max_forks_repo_head_hexsha": "3b2b3c74d623c3510cfa81a4e30ac5bd0af48cb0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0450381679, "max_line_length": 98, "alphanum_fraction": 0.4138381556, "num_tokens": 10994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7770380400972752}} {"text": "module gausslobatto_mod\n\ninteger, parameter :: RP = selected_real_kind(15)\nreal(rp), parameter :: PI = 4.0_rp * atan(1.0_rp)\nreal(rp), parameter :: TOL = 4.0e-16_rp\n\n!! CONTAINS\n\n!! SUBROUTINE LegendrePolynomialAndDerivativeAlbert(N,x,L_N,dL_N)\n!! IMPLICIT NONE\n!! INTEGER, INTENT(IN) :: N\n!! REAL(KIND=RP), INTENT(IN) :: x\n!! REAL(KIND=RP), INTENT(OUT) :: L_N,dL_N\n!! !\n!! ! lokale Variablen\n!! INTEGER :: k\n!! REAL(KIND=RP) :: L_N_1,L_N_2,dL_N_1,dL_N_2\n!! !\n!! ! Fuer den einfachsten Fall explizit vorgeben\n!! IF (N.EQ.0) THEN\n!! L_N = 0.0_RP\n!! dL_N = 0.0_RP\n!! !\n!! ! Ebenso fuer den zweit-einfachsten Fall\n!! ELSE IF (N.EQ.1) THEN\n!! L_N = x\n!! dL_N = 1.0_RP\n!! !\n!! ! Ansonsten auf die 3-Term-Rekursion zurueckgreifen\n!! ELSE\n!! ! Dazu wieder die beiden ersten Polynome vorgeben\n!! L_N_2 = 1.0_RP\n!! L_N_1 = x\n!! dL_N_2 = 0.0_RP\n!! dL_N_1 = 1.0_RP\n!! !\n!! DO k=2,N\n!! ! Rekursionsformel fuer die Legendre-Polynome verwenden\n!! L_N = ( (2.0_RP*REAL(k,RP)-1.0_RP) / REAL(k,RP) ) * x * L_N_1 - (REAL(k,RP)-1.0_RP) / REAL(k,RP) * L_N_2\n!! ! Rekursionsformel fuer die Ableitungen verwenden\n!! dL_N = dL_N_2 + ( 2.0_RP*REAL(k,RP) - 1.0_RP ) * L_N_1\n!! ! Werte fuer den naechsten Schritt updaten\n!! L_N_2 = L_N_1\n!! L_N_1 = L_N\n!! dL_N_2 = dL_N_1\n!! dL_N_1 = dL_N\n!! END DO\n!! !\n!! END IF\n!! !\n!! RETURN\n!! END SUBROUTINE\n!! \n!! ELEMENTAL SUBROUTINE LegendrePolynomialAndDerivative(N_in,x,L,Lder)\n!! IMPLICIT NONE\n!! !----------------------------------------------------------------------------------------------------------------------------------\n!! ! INPUT/OUTPUT VARIABLES\n!! INTEGER,INTENT(IN) :: N_in !< (IN) polynomial degree, (N+1) CLpoints\n!! REAL,INTENT(IN) :: x !< (IN) coordinate value in the interval [-1,1]\n!! REAL,INTENT(OUT) :: L !< (OUT) Legedre polynomial evaluated at \\f$ \\xi: L_N(\\xi), \\partial/\\partial\\xi L_N(\\xi) \\f$\n!! REAL,INTENT(OUT) :: Lder !< (OUT) Legedre polynomial deriv. evaluated at \\f$ \\xi: L_N(\\xi), \\partial/\\partial\\xi L_N(\\xi) \\f$\n!! !----------------------------------------------------------------------------------------------------------------------------------\n!! ! LOCAL VARIABLES\n!! INTEGER :: iLegendre\n!! REAL :: L_Nm1,L_Nm2 ! L_{N_in-2},L_{N_in-1}\n!! REAL :: Lder_Nm1,Lder_Nm2 ! Lder_{N_in-2},Lder_{N_in-1}\n!! !==================================================================================================================================\n!! IF(N_in .EQ. 0)THEN\n!! L=1.\n!! Lder=0.\n!! ELSEIF(N_in .EQ. 1) THEN\n!! L=x\n!! Lder=1.\n!! ELSE ! N_in > 1\n!! L_Nm2=1.\n!! L_Nm1=x\n!! Lder_Nm2=0.\n!! Lder_Nm1=1.\n!! DO iLegendre=2,N_in\n!! L=(REAL(2*iLegendre-1)*x*L_Nm1 - REAL(iLegendre-1)*L_Nm2)/REAL(iLegendre)\n!! Lder=Lder_Nm2 + REAL(2*iLegendre-1)*L_Nm1\n!! L_Nm2=L_Nm1\n!! L_Nm1=L\n!! Lder_Nm2=Lder_Nm1\n!! Lder_Nm1=Lder\n!! END DO !iLegendre=2,N_in\n!! END IF ! N_in\n!! !normalize\n!! L=L*SQRT(REAL(N_in)+0.5)\n!! Lder=Lder*SQRT(REAL(N_in)+0.5)\n!! END SUBROUTINE LegendrePolynomialAndDerivative\n!! \n!! \n!! \n!! !\n!! ! ------------------------------------------------------------------------------------------------------------- !\n!! !\n!! SUBROUTINE LegendreGaussNodesAndWeights(N,x,w)\n!! IMPLICIT NONE\n!! INTEGER, INTENT(IN) :: N\n!! REAL(KIND=RP), DIMENSION(0:N), INTENT(OUT) :: x,w\n!! !\n!! ! lokale Variablen\n!! INTEGER, PARAMETER :: n_it = 4\n!! INTEGER :: j,k\n!! REAL(KIND=RP), PARAMETER :: tol = 4.0E-16\n!! REAL(KIND=RP) :: L_N,dL_N,Delta\n!! \n!! L_N = 0.0\n!! dL_N = 0.0\n!! !\n!! ! Fuer den einfachsten Fall Knoten und Gewicht explizit angeben\n!! IF (N.EQ.0) THEN\n!! x(0) = 0.0_RP\n!! w(0) = 2.0_RP\n!! !\n!! ! Ebenso fuer den zweit-einfachsten Fall\n!! ELSE IF (N.EQ.1) THEN\n!! x(0) = -SQRT( 1.0_RP / 3.0_RP )\n!! w(0) = 1.0_RP\n!! x(1) = -x(0)\n!! w(1) = w(0)\n!! !\n!! ELSE\n!! ! Ansonsten: Symmetrie ausnutzen (nur fuer die erste Haelfte berechnen)\n!! DO j=0,((N+1)/2 - 1)\n!! ! Anfangsschaetzung mittels Nullstellen der Tschebyschow-Polynome:\n!! ! Setzte negatives Vorzeichen, um die Stuetzstellen aus dem Intervall (-1,0) zu erhalten.\n!! x(j) = -cos( (2.0_RP*REAL(j,RP)+1.0_RP) / (2.0_RP*REAL(N,RP)+2.0_RP) * pi )\n!! !\n!! ! Diese Schaetzung wird nun mithilfe des Newton-Verfahrens praezisiert\n!! DO k=0,n_it\n!! ! Dazu wird das (N+1)-ste Legendre-Polynom sowie dessen Ableitung benoetigt\n!! ! (ausgewertet an der entspr. Stuetzstelle)\n!! CALL LegendrePolynomialAndDerivative(N+1,x(j),L_N,dL_N)\n!! ! Newton-Korrektur berechnen und anwenden\n!! Delta = -L_N/dL_N\n!! x(j) = x(j) + Delta\n!! ! Falls vor Abarbeiten aller festgelegten Iterationen des Newton-Verfahrens der berechnete Wert\n!! ! schon nahe genug an der Nullstelle liegt, wird abgebrochen.\n!! IF ( ABS(Delta).LE.(tol * ABS(x(j))) ) THEN\n!! EXIT\n!! END IF\n!! !\n!! END DO\n!! !\n!! CALL LegendrePolynomialAndDerivative(N+1,x(j),L_N,dL_N)\n!! ! Nutze Symmetrie aus (Multiplikation mit -1)\n!! x(N-j) = -x(j)\n!! ! Gewichte berechnen\n!! w(j) = 2.0_RP / ( (1.0_RP-x(j)*x(j)) * dL_N*dL_N )\n!! ! Auch die Gewichte sind symmetrisch\n!! w(N-j) = w(j)\n!! !\n!! END DO\n!! !\n!! END IF\n!! !\n!! ! Falls eine ungerade Anzahl gefordert wird, noch die \"mittleren\" Werte angeben\n!! IF (MOD(N,2).EQ.0) THEN\n!! CALL LegendrePolynomialAndDerivative(N+1,0.0_RP,L_N,dL_N)\n!! ! Berechnung der Stuetzstellen und Gewichte analog\n!! x(N/2) = 0.0_RP\n!! w(N/2) = 2.0_RP / (dL_N*dL_N)\n!! END IF\n!! !\n!! RETURN\n!! END SUBROUTINE LegendreGaussNodesAndWeights\n!! !\n!! ! ------------------------------------------------------------------------------------------------------------- !\n!! !\n!! SUBROUTINE qAndLEvaluation(N,x,q,dq,L_N)\n!! IMPLICIT NONE\n!! INTEGER, INTENT(IN) :: N\n!! REAL(KIND=RP), INTENT(IN) :: x\n!! REAL(KIND=RP), INTENT(OUT) :: L_N,q,dq\n!! !\n!! ! lokale Variablen\n!! INTEGER :: k\n!! REAL(KIND=RP) :: L_N_1,L_N_2,L_k,dL_N,dL_N_1,dL_N_2,dL_k\n!! !\n!! ! NUR FUER N>=2 !\n!! !\n!! ! Initialisieren\n!! L_N_2 = 1.0_RP\n!! L_N_1 = x\n!! dL_N_2 = 0.0_RP\n!! dL_N_1 = 1.0_RP\n!! !\n!! DO k=2,N\n!! ! Rekursionsformel verwenden\n!! L_N = (2.0_RP*REAL(k,RP)-1.0_RP)/REAL(k,RP) * x * L_N_1 - (REAL(k,RP)-1.0_RP)/REAL(k,RP) * L_N_2\n!! ! Rekursionsformel fuer die Ableitungen verwenden\n!! dL_N = dL_N_2 + (2.0_RP*REAL(k,RP)-1.0_RP) * L_N_1\n!! ! Werte fuer den naechsten Schritt updaten\n!! L_N_2 = L_N_1\n!! L_N_1 = L_N\n!! dL_N_2 = dL_N_1\n!! dL_N_1 = dL_N\n!! END DO\n!! !\n!! ! Einen weiteren Schritt gehen\n!! k = N+1\n!! ! Rekursionsformel verwenden\n!! L_k = (2.0_RP*REAL(k,RP)-1.0_RP)/REAL(k,RP) * x * L_N - (REAL(k,RP)-1.0_RP)/REAL(k,RP) * L_N_2\n!! ! Rekursionsformel fuer die Ableitungen verwenden\n!! dL_k = dL_N_2 + (2.0_RP*REAL(k,RP)-1.0_RP) * L_N_1\n!! ! Benoetigtes Polynom und Ableitung bestimmen\n!! q = L_k - L_N_2\n!! dq = dL_k - dL_N_2\n!! !\n!! RETURN\n!! END SUBROUTINE qAndLEvaluation\n!! !\n!! ! ------------------------------------------------------------------------------------------------------------- !\n!! !\n!! SUBROUTINE LegendreGaussLobattoNodesAndWeights(N,x,w)\n!! IMPLICIT NONE\n!! INTEGER, INTENT(IN) :: N\n!! REAL(KIND=RP), DIMENSION(0:N), INTENT(OUT) :: x,w\n!! !\n!! ! lokale Variablen\n!! INTEGER, PARAMETER :: n_it = 4\n!! INTEGER :: j,k\n!! REAL(KIND=RP), PARAMETER :: tol = 4.0E-16\n!! REAL(KIND=RP) :: q,dq,L_N,Delta\n!! \n!! L_N = 0.0\n!! !\n!! ! Fuer den einfachsten Fall Knoten und Gewicht explizit angeben\n!! IF (N.EQ.1) THEN\n!! x(0) = -1.0_RP\n!! w(0) = 1.0_RP\n!! x(1) = 1.0_RP\n!! w(1) = w(0)\n!! !\n!! ELSE\n!! ! Randwerte explizit vorgeben\n!! x(0) = -1.0_RP\n!! w(0) = 2.0_RP / ( REAL(N,RP)*(REAL(N,RP)+1) )\n!! x(N) = 1.0_RP\n!! w(N) = w(0)\n!! ! Ansonsten: Symmetrie ausnutzen (nur fuer die erste Haelfte berechnen)\n!! DO j=1,((N+1)/2 - 1)\n!! ! Anfangsschaetzung mittels asymptotischer Relation nach Parter:\n!! ! Setzte negatives Vorzeichen, um die Stuetzstellen aus dem Intervall (-1,0) zu erhalten.\n!! x(j) = -cos( ((REAL(j,RP)+0.25_RP)*pi)/REAL(N,RP) - (3.0_RP/(8_RP*REAL(N,RP)*pi)) * (1/(REAL(j,RP)+0.25_RP)) )\n!! !\n!! ! Diese Schaetzung wird nun mithilfe des Newton-Verfahrens praezisiert\n!! DO k=0,n_it\n!! ! Dazu wird das (N+1)-ste Polynom sowie dessen Ableitung benoetigt\n!! ! (ausgewertet an der entspr. Stuetzstelle)\n!! CALL qAndLEvaluation(N,x(j),q,dq,L_N)\n!! ! Newton-Korrektur berechnen und anwenden\n!! Delta = -q/dq\n!! x(j) = x(j) + Delta\n!! ! Falls vor Abarbeiten aller festgelegten Iterationen des Newton-Verfahrens der berechnete Wert\n!! ! schon nahe genug an der Nullstelle liegt, wird abgebrochen.\n!! IF ( ABS(Delta).LE.(tol * ABS(x(j))) ) THEN\n!! EXIT\n!! END IF\n!! !\n!! END DO\n!! !\n!! CALL qAndLEvaluation(N,x(j),q,dq,L_N)\n!! ! Nutze Symmetrie aus (Multiplikation mit -1)\n!! x(N-j) = -x(j)\n!! ! Gewichte berechnen\n!! w(j) = 2.0_RP / ( REAL(N,RP)*(REAL(N,RP)+1.0_RP) * (L_N*L_N) )\n!! ! Auch die Gewichte sind symmetrisch\n!! w(N-j) = w(j)\n!! !\n!! END DO\n!! !\n!! END IF\n!! !\n!! ! Falls eine ungerade Anzahl gefordert wird, noch die \"mittleren\" Werte angeben\n!! IF (MOD(N,2).EQ.0) THEN\n!! CALL qAndLEvaluation(N,0.0_RP,q,dq,L_N)\n!! ! Berechnung der Stuetzstellen und Gewichte analog\n!! x(N/2) = 0.0_RP\n!! w(N/2) = 2.0_RP / ( REAL(N,RP) * (REAL(N,RP)+1.0_RP) * (L_N*L_N) )\n!! END IF\n!! !\n!! RETURN\n!! END SUBROUTINE LegendreGaussLobattoNodesAndWeights\n!! \n!! subroutine mkLegendreVanderMondeMatrix(n, nodes, Vdm, sVdm)\n!! \n!! use linalg_mod, only: invert\n!! \n!! integer, intent(in) :: n\n!! real, intent(in) :: nodes(:)\n!! real, intent(out) :: Vdm(:,:)\n!! real, intent(out) :: sVdm(:,:)\n!! real :: dummy\n!! integer :: i,j\n!! \n!! do i = 1,n; do j = 1,n\n!! call LegendrePolynomialAnDderivative(j-1, nodes(i), Vdm(i,j), dummy)\n!! end do; end do\n!! \n!! sVdm = invert(Vdm,n)\n!! \n!! end subroutine\n\nend module\n", "meta": {"hexsha": "3786a44f55bd3d9966a81ac092c1f9364b9f90f0", "size": 12055, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/utils/gausslobatto_mod.f90", "max_stars_repo_name": "jmark/nemo", "max_stars_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/utils/gausslobatto_mod.f90", "max_issues_repo_name": "jmark/nemo", "max_issues_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/utils/gausslobatto_mod.f90", "max_forks_repo_name": "jmark/nemo", "max_forks_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.1396103896, "max_line_length": 134, "alphanum_fraction": 0.4592285359, "num_tokens": 3954, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818985, "lm_q2_score": 0.8757869997529962, "lm_q1q2_score": 0.777002254522468}} {"text": "PROGRAM ls\n ! --------------------------------------\n ! Solve linear system of equations AX=B.\n ! --------------------------------------\n !\n ! Results compared with MATLAB(R)\n !\n ! --------------------------------------\n\n USE LA\n USE OUTPUT\n\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: d = 3\n\n REAL*8, dimension(d,d) :: A\n REAL*8, dimension(d) :: b\n REAL*8, dimension(d) :: x\n\n A(1,:) = (/1.0D0, 0.0D0, 0.0D0/)\n A(2,:) = (/0.0D0, 2.0D0, 0.0D0/)\n A(3,:) = (/0.0D0, 0.0D0, 3.0D0/)\n\n b = (/1.0D0,2.0D0,3.0D0/)\n\n CALL LINEAR_SYSTEM(d,A,b,x)\n\n CALL print_real_matrix(1,d,x)\n\n A(1,:) = (/1.0D0, 2.0D0, 3.0D0/)\n A(2,:) = (/-2.0D0, 3.0D0, -5.0D0/)\n A(3,:) = (/0.0D0, 7.0D0, -4.0D0/)\n\n b = (/-2.0D0,5.0D0,6.0D0/)\n\n CALL LINEAR_SYSTEM(d,A,b,x)\n\n CALL print_real_matrix(1,d,x)\n\n A(1,:) = (/-9.0D0, 2.0D0, 3.0D0/)\n A(2,:) = (/-2.0D0, -3.0D0, -5.0D0/)\n A(3,:) = (/0.0D0, 7.0D0, -4.0D0/)\n\n b = (/-2.0D0,-4.0D0,6.0D0/)\n\n CALL LINEAR_SYSTEM(d,A,b,x)\n\n CALL print_real_matrix(1,d,x)\n\nEND PROGRAM ls\n", "meta": {"hexsha": "8dcf555505dd7c51492964ca9c1cf0035dae7cb1", "size": 1073, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran90/tests/linearsystem_test.f90", "max_stars_repo_name": "RMeli/Hartree-Fock", "max_stars_repo_head_hexsha": "dda0102ab2a88f3f2f666c2479a858140505ea60", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2016-09-16T09:26:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T16:09:53.000Z", "max_issues_repo_path": "Fortran90/tests/linearsystem_test.f90", "max_issues_repo_name": "RMeli/Hartree-Fock", "max_issues_repo_head_hexsha": "dda0102ab2a88f3f2f666c2479a858140505ea60", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran90/tests/linearsystem_test.f90", "max_forks_repo_name": "RMeli/Hartree-Fock", "max_forks_repo_head_hexsha": "dda0102ab2a88f3f2f666c2479a858140505ea60", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2016-01-20T13:47:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-28T03:18:22.000Z", "avg_line_length": 20.6346153846, "max_line_length": 44, "alphanum_fraction": 0.4389561976, "num_tokens": 479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.8459424295406088, "lm_q1q2_score": 0.7769814166664343}} {"text": "! Rectangular waveguide module\n! This module contains all the specific calculations\n! related to rectangular waveguide\nmodule aloha2d_rectangularwaveguides\n use aloha2d_constants\n\n implicit none\n\n contains\n\n !\n ! Cut-off wavenumber kc of a rectangular waveguide\n !\n function rectwg_kc(a,b,m,n) result(kc)\n real, intent(in) :: a, b\n integer,intent(in) :: m, n\n real :: kc\n\n kc = sqrt((m*pi/a)**2 + (n*pi/b)**2);\n\n end function rectwg_kc\n\n !\n ! Guided wavenumber beta (kg) of a rectangular waveguide\n !\n function rectwg_beta(f,a,b,m,n) result(beta)\n real, intent(in) :: f, a, b\n integer,intent(in) :: m, n\n complex :: beta\n\n real :: kc, k0\n\n ! vacuum wavenumber (evaluated here, in order to avoid using a global parameter)\n k0 = 2*pi*f/c0\n ! Cutoff wavenumber\n kc = rectwg_kc(a,b,m,n)\n ! guided wavenumber\n ! TODO : shall we treat differently the case of complex valued (negative sqrt) ? Or do fortran do the thing correctly ?\n beta = sqrt(one*(k0**2 - kc**2))\n\n end function rectwg_beta\n\n !\n ! Complex propagation constant gamma=j*kg\n !\n function rectwg_gamma(f,a,b,m,n)\n real, intent(in) :: f, a, b\n integer,intent(in) :: m, n\n complex :: rectwg_gamma\n\n real :: kc, k0\n\n ! vacuum wavenumber (evaluated here, in order to avoid using a global parameter)\n k0 = 2*pi*f/c0\n ! Cutoff wavenumber\n kc = rectwg_kc(a,b,m,n)\n\n\n ! guided wavenumber\n ! TODO : shall we treat differently the case of complex valued (negative sqrt) ? Or do fortran do the thing correctly ?\n rectwg_gamma = sqrt(one*(kc**2 - k0**2))\n\n end function rectwg_gamma\n\n !\n ! Characteristic Impedance Zc of a rectangular waveguide\n !\n ! NB 22/8/12 : the sign of the real part of the complex square root is important for the .\n ! correct value determination. It seems that the calculation using gamma is better\n ! that the one using beta\n ! TODO ???\n !\n function rectwg_Zc(f,a,b,m,n,mode) result(Zc)\n real, intent(in) :: f, a, b\n integer,intent(in) :: m, n\n character(len=1), intent(in) :: mode\n complex :: Zc\n\n complex :: beta, gamma_mn\n real :: k0\n\n ! vacuum wavenumber (evaluated here, in order to avoid using a global parameter)\n k0 = 2*pi*f/c0\n ! guided wavenumber\n beta = rectwg_beta(f,a,b,m,n)\n\n gamma_mn = rectwg_gamma(f,a,b,m,n)\n\n select case (mode)\n\n case ('H')\n print*,'H mode (TE)'\n !Zc = k0*Z0/beta\n Zc = j*k0*Z0/gamma_mn\n\n case ('E')\n print*,'E mode (TM)'\n !print*,'beta=',rectwg_beta(f,a,b,m,n)\n !print*,'gamma=', rectwg_gamma(f,a,b,m,n)\n !Zc = beta*Z0/k0\n Zc = gamma_mn*Z0/(j*k0)\n\n end select\n\n end function rectwg_Zc\n\n\n !\n !\n ! Spectral eigenvector function\n !\n subroutine spectralEigenVector(ny, nz, aa, bb, m, n, yy, zz, mode, &\n Ey, Ez, Hy, Hz)\n use aloha2d_globalParameters, only : k0\n use aloha2d_plasma_admittance\n\n implicit none\n\n real, intent(in) :: nz, ny, aa, bb, yy, zz\n integer, intent(in) :: m, n\n character(len=1), intent(in) :: mode\n complex,intent(out) :: Ey, Ez, Hy, Hz\n\n real :: coeff_mode_y, coeff_mode_z\n complex :: TF_cos_m, TF_cos_n, TF_sin_m, TF_sin_n\n\n complex :: YYs_yy, YYs_yz, YYs_zy, YYs_zz, g_S_interp, g_F_interp\n\n ! Normalization factor\n select case (mode)\n case ('H')\n coeff_mode_y=(n/bb)/SQRT(m**2*bb/aa+n**2*aa/bb)\n coeff_mode_z=-(m/aa)/SQRT(m**2*bb/aa+n**2*aa/bb)\n\n If (m.GT.0) Then\n coeff_mode_y=coeff_mode_y*SQRT2\n coeff_mode_z=coeff_mode_z*SQRT2\n Endif\n\n If (n.GT.0) Then\n coeff_mode_y=coeff_mode_y*SQRT2\n coeff_mode_z=coeff_mode_z*SQRT2\n Endif\n\n case ('E')\n coeff_mode_y=-2.*(m/aa)/SQRT(m**2*bb/aa+n**2*aa/bb)\n coeff_mode_z=-2.*(n/bb)/SQRT(m**2*bb/aa+n**2*aa/bb)\n\n end select\n\n ! Fourier transform of the spatial eingenfunction cos and sin\n TF_sin_m = (-m*pi/(aa*k0**2))* &\n (1.-(-1.)**m*exp(-j*k0*ny*aa))* &\n 1.0/(ny**2-(m*pi/(k0*aa))**2)* &\n exp(-j*k0*ny*yy)\n\n TF_cos_m=(-j*ny/k0)*&\n (1.-(-1.)**m*exp(-j*k0*ny*aa))*&\n 1/(ny**2-(m*pi/(k0*aa))**2)*&\n exp(-j*k0*ny*yy)\n\n TF_sin_n=(-n*pi/(bb*k0**2))*&\n (1.-(-1.)**n*exp(-j*k0*nz*bb))*&\n 1/(nz**2-(n*pi/(k0*bb))**2)*&\n exp(-j*k0*nz*zz)\n\n TF_cos_n=(-j*nz/k0)*&\n (1.-(-1.)**n*exp(-j*k0*nz*bb))*&\n 1/(nz**2-(n*pi/(k0*bb))**2)*&\n exp(-j*k0*nz*zz)\n\n ! Spectral compoments\n Hy = -coeff_mode_z*TF_sin_m*TF_cos_n\n Hz = coeff_mode_y*TF_cos_m*TF_sin_n\n\n Ez = coeff_mode_z*TF_sin_m*TF_cos_n\n Ey = coeff_mode_y*TF_cos_m*TF_sin_n\n\n\n! call interpolate_gS_gF(ny, nz, g_S_interp,g_F_interp)\n!\n! ! Plasma admittance tensor elements\n! call eval_admittanceTensor(ny, nz, g_S_interp, g_F_interp, &\n! YYs_yy, YYs_yz, YYs_zy, YYs_zz)\n!\n! Hy = Y0*(YYs_yy*Ey + YYs_yz*Ez)\n! Hz = Y0*(YYs_zy*Ey + YYs_zz*Ez)\n\n end subroutine spectralEigenVector\n\n\nend module aloha2D_rectangularwaveguides\n", "meta": {"hexsha": "51e00cc106b32fb1c4c3824dd6930323c4bfb9b9", "size": 5252, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code_2D/couplage_2D/ALOHA2D_F90/libaloha2D/aloha2d_rectangularwaveguides.f90", "max_stars_repo_name": "IRFM/ALOHA", "max_stars_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-12T08:42:36.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-12T08:42:41.000Z", "max_issues_repo_path": "code_2D/couplage_2D/ALOHA2D_F90/libaloha2D/aloha2d_rectangularwaveguides.f90", "max_issues_repo_name": "IRFM/ALOHA", "max_issues_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T10:46:38.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-20T17:03:14.000Z", "max_forks_repo_path": "code_2D/couplage_2D/ALOHA2D_F90/libaloha2D/aloha2d_rectangularwaveguides.f90", "max_forks_repo_name": "IRFM/ALOHA", "max_forks_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-10-05T12:40:02.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-12T08:41:20.000Z", "avg_line_length": 27.2124352332, "max_line_length": 125, "alphanum_fraction": 0.5801599391, "num_tokens": 1752, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947179030094, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7769643916364185}} {"text": "!\n!...Subroutine: Get eigenvalues and eigenvectors for 2x2 symmetric matrix\n!\nsubroutine getEigensystem(matinp, eigenvect, eigenvalue,ielem)\nuse constant\nimplicit none\nreal*8, dimension(ndimn, ndimn), intent(in)::matinp\nreal*8, dimension(ndimn, ndimn), intent(out)::eigenvect\nreal*8, dimension(ndimn), intent(out)::eigenvalue\ninteger, intent(in)::ielem\n!\n!...Local real\nreal*8:: a,b,c,d\nreal*8:: lamda1,lamda2\nreal*8:: matz, matt,matc,mats\nreal*8:: eps\n!\neps = 1.d-6\n!\na = matinp(1, 1)\nb = matinp(1, 2)\nc = matinp(2, 1)\nd = matinp(2, 2)\n\nif(b.eq.0)then\n!\nlamda1 = a\nlamda2 = d\n!\nmatc = 1.d0\nmats = 0.d0\n!\n\nelse\n!\nmatz = (d-a)/(2.d0*b)\n\nif(abs(matz).lt.6.d7)then\nmatt = sign(1.d0/(abs(matz)+sqrt(1.d0+matz**2)) ,matz)\nelse\nmatt = sign(0.5d0/abs(matz), matz)\nendif\n!\nmatc = sqrt(1.d0/(1.d0+matt**2))\nmats = matc*matt\n!\n!if(ielem.eq.2.or.ielem.eq.31)then\n!print*,'ielem eigenvalue2',ielem,lamda1,lamda2,matz,matt,b\n!endif\n!\nmatt = matt*b\n!\nlamda1 = a - matt\nlamda2 = d + matt\n!\nendif\n!\n!\n!...Part II: Specify eigenvalues and eigenvectors in order\n!\nif(lamda1.le.lamda2)then\n!\neigenvalue(1) = lamda1\neigenvalue(2) = lamda2\n!\neigenvect(1,1) = matc\neigenvect(1,2) =-mats\n\neigenvect(2,1) = mats\neigenvect(2,2) = matc\n\nelse\n!\neigenvalue(1) = lamda2\neigenvalue(2) = lamda1\n!\neigenvect(1,1) = mats\neigenvect(1,2) = matc\n\neigenvect(2,1) = matc\neigenvect(2,2) =-mats\n\nendif\n\nend subroutine getEigensystem\n!\n!...Symmetric matrix\n!\nsubroutine matrix_sym(ni, nj, nq, mtlhs, rhs, mtsym, rhssym)\n!\nimplicit none\n!\ninteger*4, intent(in)::ni, nj, nq\nreal*8, dimension(ni,nj), intent(in):: mtlhs\nreal*8, dimension(nq,ni), intent(in):: rhs\nreal*8, dimension(nj,nj), intent(out):: mtsym\nreal*8, dimension(nq,nj), intent(out):: rhssym\n\n!...Local\n\ninteger:: im, jm,km, iq\n\n!...Zero out\nmtsym = 0.d0\nrhssym = 0.d0\n\n!...Symmetry matrix\ndo im = 1, nj\ndo jm = 1, nj\ndo km = 1, ni\nmtsym(im, jm) = mtsym(im, jm) + mtlhs(km, im)*mtlhs(km, jm)\nenddo\nenddo\nenddo\n\n!...Symmetry rhs\ndo iq = 1 ,nq\ndo im = 1, nj\ndo km = 1, ni\nrhssym(iq, im) = rhssym(iq, im) + mtlhs(km, im)*rhs(iq, km)\nenddo\nenddo\nenddo\n\nreturn\nend subroutine matrix_sym\n!\n!...Subroutine: Get inverse small matrix for n=2,,,5....\n!\nsubroutine Matinv225(a,b,n)\n\nimplicit none\ninteger, intent(in):: n\nreal*8, intent(in):: a(n,n)\nreal*8, intent(out):: b(n,n)\nreal*8:: bt(n,n)\nreal*8 det\nreal*8::a11, a12, a13, a14, a15, a21, a22, a23, a24, &\na25, a31, a32, a33, a34, a35, a41, a42, a43, a44, a45, &\na51, a52, a53, a54, a55\ninteger::i\n\n! step 0: initialization for matrices L and U and b\n! Fortran 90/95 aloows such operations on matrices\nif(n.eq.2)then\ndet = a(1, 1)*a(2, 2)-a(1, 2)*a(2, 1)\n\nb(1, 1) = a(2, 2)\nb(1, 2) =-a(1, 2)\nb(2, 1) =-a(2, 1)\nb(2, 2) = a(1, 1)\nelseif(n.eq.3)then\n!\ndet = a(1,1)*(a(2,2)*a(3,3)-a(2,3)*a(3,2)) &\n-a(1,2)*(a(2,1)*a(3,3)-a(2,3)*a(3,1)) &\n+a(1,3)*(a(2,1)*a(3,2)-a(2,2)*a(3,1))\n!\nb(1,1) = a(2,2)*a(3,3) - a(2,3)*a(3,2)\nb(2,1) = a(2,3)*a(3,1) - a(2,1)*a(3,3)\nb(3,1) = a(2,1)*a(3,2) - a(2,2)*a(3,1)\n\nb(1,2) = a(1,3)*a(3,2) - a(1,2)*a(3,3)\nb(2,2) = a(1,1)*a(3,3) - a(1,3)*a(3,1)\nb(3,2) = a(1,2)*a(3,1) - a(1,1)*a(3,2)\n\nb(1,3) = a(1,2)*a(2,3) - a(1,3)*a(2,2)\nb(2,3) = a(1,3)*a(2,1) - a(1,1)*a(2,3)\nb(3,3) = a(1,1)*a(2,2) - a(1,2)*a(2,1)\n\nelseif(n.eq.4)then\n!\ndet = a(1,1)*(a(2,2)*(a(3,3)*a(4,4)-a(3,4)*a(4,3)) &\n-a(2,3)*(a(3,2)*a(4,4)-a(3,4)*a(4,2)) &\n+a(2,4)*(a(3,2)*a(4,3)-a(3,3)*a(4,2))) &\n-a(1,2)*(a(2,1)*(a(3,3)*a(4,4)-a(3,4)*a(4,3)) &\n-a(2,3)*(a(3,1)*a(4,4)-a(3,4)*a(4,1)) &\n+a(2,4)*(a(3,1)*a(4,3)-a(3,3)*a(4,1))) &\n+a(1,3)*(a(2,1)*(a(3,2)*a(4,4)-a(3,4)*a(4,2)) &\n-a(2,2)*(a(3,1)*a(4,4)-a(3,4)*a(4,1)) &\n+a(2,4)*(a(3,1)*a(4,2)-a(3,2)*a(4,1))) &\n-a(1,4)*(a(2,1)*(a(3,2)*a(4,3)-a(3,3)*a(4,2)) &\n-a(2,2)*(a(3,1)*a(4,3)-a(3,3)*a(4,1)) &\n+a(2,3)*(a(3,1)*a(4,2)-a(3,2)*a(4,1)))\n\nb(1,1) = a(2,2)*(a(3,3)*a(4,4)-a(3,4)*a(4,3))-a(2,3)*(a(3,2)*a(4,4)-a(3,4)*a(4,2))+a(2,4)*(a(3,2)*a(4,3)-a(3,3)*a(4,2))\nb(2,1) = -a(2,1)*(a(3,3)*a(4,4)-a(3,4)*a(4,3))+a(2,3)*(a(3,1)*a(4,4)-a(3,4)*a(4,1))-a(2,4)*(a(3,1)*a(4,3)-a(3,3)*a(4,1))\nb(3,1) = a(2,1)*(a(3,2)*a(4,4)-a(3,4)*a(4,2))-a(2,2)*(a(3,1)*a(4,4)-a(3,4)*a(4,1))+a(2,4)*(a(3,1)*a(4,2)-a(3,2)*a(4,1))\nb(4,1) = -a(2,1)*(a(3,2)*a(4,3)-a(3,3)*a(4,2))+a(2,2)*(a(3,1)*a(4,3)-a(3,3)*a(4,1))-a(2,3)*(a(3,1)*a(4,2)-a(3,2)*a(4,1))\n\nb(1,2) = -a(1,2)*(a(3,3)*a(4,4)-a(3,4)*a(4,3))+a(1,3)*(a(3,2)*a(4,4)-a(3,4)*a(4,2))-a(1,4)*(a(3,2)*a(4,3)-a(3,3)*a(4,2))\nb(2,2) = a(1,1)*(a(3,3)*a(4,4)-a(3,4)*a(4,3))-a(1,3)*(a(3,1)*a(4,4)-a(3,4)*a(4,1))+a(1,4)*(a(3,1)*a(4,3)-a(3,3)*a(4,1))\nb(3,2) = -a(1,1)*(a(3,2)*a(4,4)-a(3,4)*a(4,2))+a(1,2)*(a(3,1)*a(4,4)-a(3,4)*a(4,1))-a(1,4)*(a(3,1)*a(4,2)-a(3,2)*a(4,1))\nb(4,2) = a(1,1)*(a(3,2)*a(4,3)-a(3,3)*a(4,2))-a(1,2)*(a(3,1)*a(4,3)-a(3,3)*a(4,1))+a(1,3)*(a(3,1)*a(4,2)-a(3,2)*a(4,1))\n\nb(1,3) = a(1,2)*(a(2,3)*a(4,4)-a(2,4)*a(4,3))-a(1,3)*(a(2,2)*a(4,4)-a(2,4)*a(4,2))+a(1,4)*(a(2,2)*a(4,3)-a(2,3)*a(4,2))\nb(2,3) = -a(1,1)*(a(2,3)*a(4,4)-a(2,4)*a(4,3))+a(1,3)*(a(2,1)*a(4,4)-a(2,4)*a(4,1))-a(1,4)*(a(2,1)*a(4,3)-a(2,3)*a(4,1))\nb(3,3) = a(1,1)*(a(2,2)*a(4,4)-a(2,4)*a(4,2))-a(1,2)*(a(2,1)*a(4,4)-a(2,4)*a(4,1))+a(1,4)*(a(2,1)*a(4,2)-a(2,2)*a(4,1))\nb(4,3) = -a(1,1)*(a(2,2)*a(4,3)-a(2,3)*a(4,2))+a(1,2)*(a(2,1)*a(4,3)-a(2,3)*a(4,1))-a(1,3)*(a(2,1)*a(4,2)-a(2,2)*a(4,1))\n\nb(1,4) = -a(1,2)*(a(2,3)*a(3,4)-a(2,4)*a(3,3))+a(1,3)*(a(2,2)*a(3,4)-a(2,4)*a(3,2))-a(1,4)*(a(2,2)*a(3,3)-a(2,3)*a(3,2))\nb(2,4) = a(1,1)*(a(2,3)*a(3,4)-a(2,4)*a(3,3))-a(1,3)*(a(2,1)*a(3,4)-a(2,4)*a(3,1))+a(1,4)*(a(2,1)*a(3,3)-a(2,3)*a(3,1))\nb(3,4) = -a(1,1)*(a(2,2)*a(3,4)-a(2,4)*a(3,2))+a(1,2)*(a(2,1)*a(3,4)-a(2,4)*a(3,1))-a(1,4)*(a(2,1)*a(3,2)-a(2,2)*a(3,1))\nb(4,4) = a(1,1)*(a(2,2)*a(3,3)-a(2,3)*a(3,2))-a(1,2)*(a(2,1)*a(3,3)-a(2,3)*a(3,1))+a(1,3)*(a(2,1)*a(3,2)-a(2,2)*a(3,1))\nelseif(n.eq.5)then\na11=a(1,1); a12=a(1,2); a13=a(1,3); a14=a(1,4); a15=a(1,5)\na21=a(2,1); a22=a(2,2); a23=a(2,3); a24=a(2,4); a25=a(2,5)\na31=a(3,1); a32=a(3,2); a33=a(3,3); a34=a(3,4); a35=a(3,5)\na41=a(4,1); a42=a(4,2); a43=a(4,3); a44=a(4,4); a45=a(4,5)\na51=a(5,1); a52=a(5,2); a53=a(5,3); a54=a(5,4); a55=a(5,5)\n\ndet = a15*a24*a33*a42*a51-a14*a25*a33*a42*a51-a15*a23*a34*a42*a51+ &\na13*a25*a34*a42*a51+a14*a23*a35*a42*a51-a13*a24*a35*a42*a51- &\na15*a24*a32*a43*a51+a14*a25*a32*a43*a51+a15*a22*a34*a43*a51- &\na12*a25*a34*a43*a51-a14*a22*a35*a43*a51+a12*a24*a35*a43*a51+ &\na15*a23*a32*a44*a51-a13*a25*a32*a44*a51-a15*a22*a33*a44*a51+ &\na12*a25*a33*a44*a51+a13*a22*a35*a44*a51-a12*a23*a35*a44*a51- &\na14*a23*a32*a45*a51+a13*a24*a32*a45*a51+a14*a22*a33*a45*a51- &\na12*a24*a33*a45*a51-a13*a22*a34*a45*a51+a12*a23*a34*a45*a51- &\na15*a24*a33*a41*a52+a14*a25*a33*a41*a52+a15*a23*a34*a41*a52- &\na13*a25*a34*a41*a52-a14*a23*a35*a41*a52+a13*a24*a35*a41*a52+ &\na15*a24*a31*a43*a52-a14*a25*a31*a43*a52-a15*a21*a34*a43*a52+ &\na11*a25*a34*a43*a52+a14*a21*a35*a43*a52-a11*a24*a35*a43*a52- &\na15*a23*a31*a44*a52+a13*a25*a31*a44*a52+a15*a21*a33*a44*a52- &\na11*a25*a33*a44*a52-a13*a21*a35*a44*a52+a11*a23*a35*a44*a52+ &\na14*a23*a31*a45*a52-a13*a24*a31*a45*a52-a14*a21*a33*a45*a52+ &\na11*a24*a33*a45*a52+a13*a21*a34*a45*a52-a11*a23*a34*a45*a52+ &\na15*a24*a32*a41*a53-a14*a25*a32*a41*a53-a15*a22*a34*a41*a53+ &\na12*a25*a34*a41*a53+a14*a22*a35*a41*a53-a12*a24*a35*a41*a53- &\na15*a24*a31*a42*a53+a14*a25*a31*a42*a53+a15*a21*a34*a42*a53- &\na11*a25*a34*a42*a53-a14*a21*a35*a42*a53+a11*a24*a35*a42*a53+ &\na15*a22*a31*a44*a53-a12*a25*a31*a44*a53-a15*a21*a32*a44*a53+ &\na11*a25*a32*a44*a53+a12*a21*a35*a44*a53-a11*a22*a35*a44*a53- &\na14*a22*a31*a45*a53+a12*a24*a31*a45*a53+a14*a21*a32*a45*a53- &\na11*a24*a32*a45*a53-a12*a21*a34*a45*a53+a11*a22*a34*a45*a53- &\na15*a23*a32*a41*a54+a13*a25*a32*a41*a54+a15*a22*a33*a41*a54- &\na12*a25*a33*a41*a54-a13*a22*a35*a41*a54+a12*a23*a35*a41*a54+ &\na15*a23*a31*a42*a54-a13*a25*a31*a42*a54-a15*a21*a33*a42*a54+ &\na11*a25*a33*a42*a54+a13*a21*a35*a42*a54-a11*a23*a35*a42*a54- &\na15*a22*a31*a43*a54+a12*a25*a31*a43*a54+a15*a21*a32*a43*a54- &\na11*a25*a32*a43*a54-a12*a21*a35*a43*a54+a11*a22*a35*a43*a54+ &\na13*a22*a31*a45*a54-a12*a23*a31*a45*a54-a13*a21*a32*a45*a54+ &\na11*a23*a32*a45*a54+a12*a21*a33*a45*a54-a11*a22*a33*a45*a54+ &\na14*a23*a32*a41*a55-a13*a24*a32*a41*a55-a14*a22*a33*a41*a55+ &\na12*a24*a33*a41*a55+a13*a22*a34*a41*a55-a12*a23*a34*a41*a55- &\na14*a23*a31*a42*a55+a13*a24*a31*a42*a55+a14*a21*a33*a42*a55- &\na11*a24*a33*a42*a55-a13*a21*a34*a42*a55+a11*a23*a34*a42*a55+ &\na14*a22*a31*a43*a55-a12*a24*a31*a43*a55-a14*a21*a32*a43*a55+ &\na11*a24*a32*a43*a55+a12*a21*a34*a43*a55-a11*a22*a34*a43*a55- &\na13*a22*a31*a44*a55+a12*a23*a31*a44*a55+a13*a21*a32*a44*a55- &\na11*a23*a32*a44*a55-a12*a21*a33*a44*a55+a11*a22*a33*a44*a55\n\nb(1,1) = a25*a34*a43*a52-a24*a35*a43*a52-a25*a33*a44*a52+ &\na23*a35*a44*a52+a24*a33*a45*a52-a23*a34*a45*a52-a25*a34*a42*a53+ &\na24*a35*a42*a53+a25*a32*a44*a53-a22*a35*a44*a53-a24*a32*a45*a53+ &\na22*a34*a45*a53+a25*a33*a42*a54-a23*a35*a42*a54-a25*a32*a43*a54+ &\na22*a35*a43*a54+a23*a32*a45*a54-a22*a33*a45*a54-a24*a33*a42*a55+ &\na23*a34*a42*a55+a24*a32*a43*a55-a22*a34*a43*a55-a23*a32*a44*a55+ &\na22*a33*a44*a55\n\nb(2,1) = -a15*a34*a43*a52+a14*a35*a43*a52+a15*a33*a44*a52- &\na13*a35*a44*a52-a14*a33*a45*a52+a13*a34*a45*a52+a15*a34*a42*a53- &\na14*a35*a42*a53-a15*a32*a44*a53+a12*a35*a44*a53+a14*a32*a45*a53- &\na12*a34*a45*a53-a15*a33*a42*a54+a13*a35*a42*a54+a15*a32*a43*a54- &\na12*a35*a43*a54-a13*a32*a45*a54+a12*a33*a45*a54+a14*a33*a42*a55- &\na13*a34*a42*a55-a14*a32*a43*a55+a12*a34*a43*a55+a13*a32*a44*a55- &\na12*a33*a44*a55\n\nb(3,1) = a15*a24*a43*a52-a14*a25*a43*a52-a15*a23*a44*a52+ &\na13*a25*a44*a52+a14*a23*a45*a52-a13*a24*a45*a52-a15*a24*a42*a53+ &\na14*a25*a42*a53+a15*a22*a44*a53-a12*a25*a44*a53-a14*a22*a45*a53+ &\na12*a24*a45*a53+a15*a23*a42*a54-a13*a25*a42*a54-a15*a22*a43*a54+ &\na12*a25*a43*a54+a13*a22*a45*a54-a12*a23*a45*a54-a14*a23*a42*a55+ &\na13*a24*a42*a55+a14*a22*a43*a55-a12*a24*a43*a55-a13*a22*a44*a55+ &\na12*a23*a44*a55\n\nb(4,1) = -a15*a24*a33*a52+a14*a25*a33*a52+a15*a23*a34*a52- &\na13*a25*a34*a52-a14*a23*a35*a52+a13*a24*a35*a52+a15*a24*a32*a53- &\na14*a25*a32*a53-a15*a22*a34*a53+a12*a25*a34*a53+a14*a22*a35*a53- &\na12*a24*a35*a53-a15*a23*a32*a54+a13*a25*a32*a54+a15*a22*a33*a54- &\na12*a25*a33*a54-a13*a22*a35*a54+a12*a23*a35*a54+a14*a23*a32*a55- &\na13*a24*a32*a55-a14*a22*a33*a55+a12*a24*a33*a55+a13*a22*a34*a55- &\na12*a23*a34*a55\n\nb(5,1) = a15*a24*a33*a42-a14*a25*a33*a42-a15*a23*a34*a42+ &\na13*a25*a34*a42+a14*a23*a35*a42-a13*a24*a35*a42-a15*a24*a32*a43+ &\na14*a25*a32*a43+a15*a22*a34*a43-a12*a25*a34*a43-a14*a22*a35*a43+ &\na12*a24*a35*a43+a15*a23*a32*a44-a13*a25*a32*a44-a15*a22*a33*a44+ &\na12*a25*a33*a44+a13*a22*a35*a44-a12*a23*a35*a44-a14*a23*a32*a45+ &\na13*a24*a32*a45+a14*a22*a33*a45-a12*a24*a33*a45-a13*a22*a34*a45+ &\na12*a23*a34*a45\n\nb(1,2) = -a25*a34*a43*a51+a24*a35*a43*a51+a25*a33*a44*a51- &\na23*a35*a44*a51-a24*a33*a45*a51+a23*a34*a45*a51+a25*a34*a41*a53- &\na24*a35*a41*a53-a25*a31*a44*a53+a21*a35*a44*a53+a24*a31*a45*a53- &\na21*a34*a45*a53-a25*a33*a41*a54+a23*a35*a41*a54+a25*a31*a43*a54- &\na21*a35*a43*a54-a23*a31*a45*a54+a21*a33*a45*a54+a24*a33*a41*a55- &\na23*a34*a41*a55-a24*a31*a43*a55+a21*a34*a43*a55+a23*a31*a44*a55- &\na21*a33*a44*a55\n\nb(2,2) = a15*a34*a43*a51-a14*a35*a43*a51-a15*a33*a44*a51+ &\na13*a35*a44*a51+a14*a33*a45*a51-a13*a34*a45*a51-a15*a34*a41*a53+ &\na14*a35*a41*a53+a15*a31*a44*a53-a11*a35*a44*a53-a14*a31*a45*a53+ &\na11*a34*a45*a53+a15*a33*a41*a54-a13*a35*a41*a54-a15*a31*a43*a54+ &\na11*a35*a43*a54+a13*a31*a45*a54-a11*a33*a45*a54-a14*a33*a41*a55+ &\na13*a34*a41*a55+a14*a31*a43*a55-a11*a34*a43*a55-a13*a31*a44*a55+ &\na11*a33*a44*a55\n\nb(3,2) = -a15*a24*a43*a51+a14*a25*a43*a51+a15*a23*a44*a51- &\na13*a25*a44*a51-a14*a23*a45*a51+a13*a24*a45*a51+a15*a24*a41*a53- &\na14*a25*a41*a53-a15*a21*a44*a53+a11*a25*a44*a53+a14*a21*a45*a53- &\na11*a24*a45*a53-a15*a23*a41*a54+a13*a25*a41*a54+a15*a21*a43*a54- &\na11*a25*a43*a54-a13*a21*a45*a54+a11*a23*a45*a54+a14*a23*a41*a55- &\na13*a24*a41*a55-a14*a21*a43*a55+a11*a24*a43*a55+a13*a21*a44*a55- &\na11*a23*a44*a55\n\nb(4,2) = a15*a24*a33*a51-a14*a25*a33*a51-a15*a23*a34*a51+ &\na13*a25*a34*a51+a14*a23*a35*a51-a13*a24*a35*a51-a15*a24*a31*a53+ &\na14*a25*a31*a53+a15*a21*a34*a53-a11*a25*a34*a53-a14*a21*a35*a53+ &\na11*a24*a35*a53+a15*a23*a31*a54-a13*a25*a31*a54-a15*a21*a33*a54+ &\na11*a25*a33*a54+a13*a21*a35*a54-a11*a23*a35*a54-a14*a23*a31*a55+ &\na13*a24*a31*a55+a14*a21*a33*a55-a11*a24*a33*a55-a13*a21*a34*a55+ &\na11*a23*a34*a55\n\nb(5,2) = -a15*a24*a33*a41+a14*a25*a33*a41+a15*a23*a34*a41- &\na13*a25*a34*a41-a14*a23*a35*a41+a13*a24*a35*a41+a15*a24*a31*a43- &\na14*a25*a31*a43-a15*a21*a34*a43+a11*a25*a34*a43+a14*a21*a35*a43- &\na11*a24*a35*a43-a15*a23*a31*a44+a13*a25*a31*a44+a15*a21*a33*a44- &\na11*a25*a33*a44-a13*a21*a35*a44+a11*a23*a35*a44+a14*a23*a31*a45- &\na13*a24*a31*a45-a14*a21*a33*a45+a11*a24*a33*a45+a13*a21*a34*a45- &\na11*a23*a34*a45\n\nb(1,3) = a25*a34*a42*a51-a24*a35*a42*a51-a25*a32*a44*a51+ &\na22*a35*a44*a51+a24*a32*a45*a51-a22*a34*a45*a51-a25*a34*a41*a52+ &\na24*a35*a41*a52+a25*a31*a44*a52-a21*a35*a44*a52-a24*a31*a45*a52+ &\na21*a34*a45*a52+a25*a32*a41*a54-a22*a35*a41*a54-a25*a31*a42*a54+ &\na21*a35*a42*a54+a22*a31*a45*a54-a21*a32*a45*a54-a24*a32*a41*a55+ &\na22*a34*a41*a55+a24*a31*a42*a55-a21*a34*a42*a55-a22*a31*a44*a55+ &\na21*a32*a44*a55\n\nb(2,3) = -a15*a34*a42*a51+a14*a35*a42*a51+a15*a32*a44*a51- &\na12*a35*a44*a51-a14*a32*a45*a51+a12*a34*a45*a51+a15*a34*a41*a52- &\na14*a35*a41*a52-a15*a31*a44*a52+a11*a35*a44*a52+a14*a31*a45*a52- &\na11*a34*a45*a52-a15*a32*a41*a54+a12*a35*a41*a54+a15*a31*a42*a54- &\na11*a35*a42*a54-a12*a31*a45*a54+a11*a32*a45*a54+a14*a32*a41*a55- &\na12*a34*a41*a55-a14*a31*a42*a55+a11*a34*a42*a55+a12*a31*a44*a55- &\na11*a32*a44*a55\n\nb(3,3) = a15*a24*a42*a51-a14*a25*a42*a51-a15*a22*a44*a51+ &\na12*a25*a44*a51+a14*a22*a45*a51-a12*a24*a45*a51-a15*a24*a41*a52+ &\na14*a25*a41*a52+a15*a21*a44*a52-a11*a25*a44*a52-a14*a21*a45*a52+ &\na11*a24*a45*a52+a15*a22*a41*a54-a12*a25*a41*a54-a15*a21*a42*a54+ &\na11*a25*a42*a54+a12*a21*a45*a54-a11*a22*a45*a54-a14*a22*a41*a55+ &\na12*a24*a41*a55+a14*a21*a42*a55-a11*a24*a42*a55-a12*a21*a44*a55+ &\na11*a22*a44*a55\n\nb(4,3) = -a15*a24*a32*a51+a14*a25*a32*a51+a15*a22*a34*a51- &\na12*a25*a34*a51-a14*a22*a35*a51+a12*a24*a35*a51+a15*a24*a31*a52- &\na14*a25*a31*a52-a15*a21*a34*a52+a11*a25*a34*a52+a14*a21*a35*a52- &\na11*a24*a35*a52-a15*a22*a31*a54+a12*a25*a31*a54+a15*a21*a32*a54- &\na11*a25*a32*a54-a12*a21*a35*a54+a11*a22*a35*a54+a14*a22*a31*a55- &\na12*a24*a31*a55-a14*a21*a32*a55+a11*a24*a32*a55+a12*a21*a34*a55- &\na11*a22*a34*a55\n\nb(5,3) = a15*a24*a32*a41-a14*a25*a32*a41-a15*a22*a34*a41+ &\na12*a25*a34*a41+a14*a22*a35*a41-a12*a24*a35*a41-a15*a24*a31*a42+ &\na14*a25*a31*a42+a15*a21*a34*a42-a11*a25*a34*a42-a14*a21*a35*a42+ &\na11*a24*a35*a42+a15*a22*a31*a44-a12*a25*a31*a44-a15*a21*a32*a44+ &\na11*a25*a32*a44+a12*a21*a35*a44-a11*a22*a35*a44-a14*a22*a31*a45+ &\na12*a24*a31*a45+a14*a21*a32*a45-a11*a24*a32*a45-a12*a21*a34*a45+ &\na11*a22*a34*a45\n\nb(1,4) = -a25*a33*a42*a51+a23*a35*a42*a51+a25*a32*a43*a51- &\na22*a35*a43*a51-a23*a32*a45*a51+a22*a33*a45*a51+a25*a33*a41*a52- &\na23*a35*a41*a52-a25*a31*a43*a52+a21*a35*a43*a52+a23*a31*a45*a52- &\na21*a33*a45*a52-a25*a32*a41*a53+a22*a35*a41*a53+a25*a31*a42*a53- &\na21*a35*a42*a53-a22*a31*a45*a53+a21*a32*a45*a53+a23*a32*a41*a55- &\na22*a33*a41*a55-a23*a31*a42*a55+a21*a33*a42*a55+a22*a31*a43*a55- &\na21*a32*a43*a55\n\nb(2,4) = a15*a33*a42*a51-a13*a35*a42*a51-a15*a32*a43*a51+ &\na12*a35*a43*a51+a13*a32*a45*a51-a12*a33*a45*a51-a15*a33*a41*a52+ &\na13*a35*a41*a52+a15*a31*a43*a52-a11*a35*a43*a52-a13*a31*a45*a52+ &\na11*a33*a45*a52+a15*a32*a41*a53-a12*a35*a41*a53-a15*a31*a42*a53+ &\na11*a35*a42*a53+a12*a31*a45*a53-a11*a32*a45*a53-a13*a32*a41*a55+ &\na12*a33*a41*a55+a13*a31*a42*a55-a11*a33*a42*a55-a12*a31*a43*a55+ &\na11*a32*a43*a55\n\nb(3,4) = -a15*a23*a42*a51+a13*a25*a42*a51+a15*a22*a43*a51- &\na12*a25*a43*a51-a13*a22*a45*a51+a12*a23*a45*a51+a15*a23*a41*a52- &\na13*a25*a41*a52-a15*a21*a43*a52+a11*a25*a43*a52+a13*a21*a45*a52- &\na11*a23*a45*a52-a15*a22*a41*a53+a12*a25*a41*a53+a15*a21*a42*a53- &\na11*a25*a42*a53-a12*a21*a45*a53+a11*a22*a45*a53+a13*a22*a41*a55- &\na12*a23*a41*a55-a13*a21*a42*a55+a11*a23*a42*a55+a12*a21*a43*a55- &\na11*a22*a43*a55\n\nb(4,4) = a15*a23*a32*a51-a13*a25*a32*a51-a15*a22*a33*a51+ &\na12*a25*a33*a51+a13*a22*a35*a51-a12*a23*a35*a51-a15*a23*a31*a52+ &\na13*a25*a31*a52+a15*a21*a33*a52-a11*a25*a33*a52-a13*a21*a35*a52+ &\na11*a23*a35*a52+a15*a22*a31*a53-a12*a25*a31*a53-a15*a21*a32*a53+ &\na11*a25*a32*a53+a12*a21*a35*a53-a11*a22*a35*a53-a13*a22*a31*a55+ &\na12*a23*a31*a55+a13*a21*a32*a55-a11*a23*a32*a55-a12*a21*a33*a55+ &\na11*a22*a33*a55\n\nb(5,4) = -a15*a23*a32*a41+a13*a25*a32*a41+a15*a22*a33*a41- &\na12*a25*a33*a41-a13*a22*a35*a41+a12*a23*a35*a41+a15*a23*a31*a42- &\na13*a25*a31*a42-a15*a21*a33*a42+a11*a25*a33*a42+a13*a21*a35*a42- &\na11*a23*a35*a42-a15*a22*a31*a43+a12*a25*a31*a43+a15*a21*a32*a43- &\na11*a25*a32*a43-a12*a21*a35*a43+a11*a22*a35*a43+a13*a22*a31*a45- &\na12*a23*a31*a45-a13*a21*a32*a45+a11*a23*a32*a45+a12*a21*a33*a45- &\na11*a22*a33*a45\n\nb(1,5) = a24*a33*a42*a51-a23*a34*a42*a51-a24*a32*a43*a51+ &\na22*a34*a43*a51+a23*a32*a44*a51-a22*a33*a44*a51-a24*a33*a41*a52+ &\na23*a34*a41*a52+a24*a31*a43*a52-a21*a34*a43*a52-a23*a31*a44*a52+ &\na21*a33*a44*a52+a24*a32*a41*a53-a22*a34*a41*a53-a24*a31*a42*a53+ &\na21*a34*a42*a53+a22*a31*a44*a53-a21*a32*a44*a53-a23*a32*a41*a54+ &\na22*a33*a41*a54+a23*a31*a42*a54-a21*a33*a42*a54-a22*a31*a43*a54+ &\na21*a32*a43*a54\n\nb(2,5) = -a14*a33*a42*a51+a13*a34*a42*a51+a14*a32*a43*a51- &\na12*a34*a43*a51-a13*a32*a44*a51+a12*a33*a44*a51+a14*a33*a41*a52- &\na13*a34*a41*a52-a14*a31*a43*a52+a11*a34*a43*a52+a13*a31*a44*a52- &\na11*a33*a44*a52-a14*a32*a41*a53+a12*a34*a41*a53+a14*a31*a42*a53- &\na11*a34*a42*a53-a12*a31*a44*a53+a11*a32*a44*a53+a13*a32*a41*a54- &\na12*a33*a41*a54-a13*a31*a42*a54+a11*a33*a42*a54+a12*a31*a43*a54- &\na11*a32*a43*a54\n\nb(3,5) = a14*a23*a42*a51-a13*a24*a42*a51-a14*a22*a43*a51+ &\na12*a24*a43*a51+a13*a22*a44*a51-a12*a23*a44*a51-a14*a23*a41*a52+ &\na13*a24*a41*a52+a14*a21*a43*a52-a11*a24*a43*a52-a13*a21*a44*a52+ &\na11*a23*a44*a52+a14*a22*a41*a53-a12*a24*a41*a53-a14*a21*a42*a53+ &\na11*a24*a42*a53+a12*a21*a44*a53-a11*a22*a44*a53-a13*a22*a41*a54+ &\na12*a23*a41*a54+a13*a21*a42*a54-a11*a23*a42*a54-a12*a21*a43*a54+ &\na11*a22*a43*a54\n\nb(4,5) = -a14*a23*a32*a51+a13*a24*a32*a51+a14*a22*a33*a51- &\na12*a24*a33*a51-a13*a22*a34*a51+a12*a23*a34*a51+a14*a23*a31*a52- &\na13*a24*a31*a52-a14*a21*a33*a52+a11*a24*a33*a52+a13*a21*a34*a52- &\na11*a23*a34*a52-a14*a22*a31*a53+a12*a24*a31*a53+a14*a21*a32*a53- &\na11*a24*a32*a53-a12*a21*a34*a53+a11*a22*a34*a53+a13*a22*a31*a54- &\na12*a23*a31*a54-a13*a21*a32*a54+a11*a23*a32*a54+a12*a21*a33*a54- &\na11*a22*a33*a54\n\nb(5,5) = a14*a23*a32*a41-a13*a24*a32*a41-a14*a22*a33*a41+ &\na12*a24*a33*a41+a13*a22*a34*a41-a12*a23*a34*a41-a14*a23*a31*a42+ &\na13*a24*a31*a42+a14*a21*a33*a42-a11*a24*a33*a42-a13*a21*a34*a42+ &\na11*a23*a34*a42+a14*a22*a31*a43-a12*a24*a31*a43-a14*a21*a32*a43+ &\na11*a24*a32*a43+a12*a21*a34*a43-a11*a22*a34*a43-a13*a22*a31*a44+ &\na12*a23*a31*a44+a13*a21*a32*a44-a11*a23*a32*a44-a12*a21*a33*a44+ &\na11*a22*a33*a44\n\n!...Transpose\nbt = transpose(b)\nendif\n\n!...Multiplying the factor\nif(n.lt.5)then\nb = b/det\nelse\nb = bt/det\nendif\n\n!...Output\n!if(abs(det).le.1d-12)then\n!print*,'The Matrix determinant is zero!',n,det\n!stop\n!endif\nend\n\n\n", "meta": {"hexsha": "e0bbdfb8f14aa9d01584b7a52f93d2479cd3e320", "size": 19698, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "srccurv-lag/LinearAlgebra.f90", "max_stars_repo_name": "liuspace/Lag2D", "max_stars_repo_head_hexsha": "25ab700cf449400f1b3db0d0b320c1aea672745c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-12-22T23:12:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T14:43:58.000Z", "max_issues_repo_path": "srccurv-lag/LinearAlgebra.f90", "max_issues_repo_name": "liuspace/Lag2D", "max_issues_repo_head_hexsha": "25ab700cf449400f1b3db0d0b320c1aea672745c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "srccurv-lag/LinearAlgebra.f90", "max_forks_repo_name": "liuspace/Lag2D", "max_forks_repo_head_hexsha": "25ab700cf449400f1b3db0d0b320c1aea672745c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.821656051, "max_line_length": 120, "alphanum_fraction": 0.6259011067, "num_tokens": 10676, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065459, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.7769643762485744}} {"text": "!\n! Example illustrating the use of the frand123 C interface for the generation\n! of double precision uniformly distributed random numbers.\n! The example uses a naive Monte-Carlo approach to approximate pi.\n!\n! It generates points within the unit square and computes the ratio of points\n! within the upper right quadrant of the unit circle.\n! This ratio approximates pi / 4\n!\n\nprogram piDouble\n use, intrinsic :: iso_c_binding, only: c_double\n use omp_lib, only: omp_get_wtime\n use frand123, only: frand123State_t, frand123Init, frand123Double\n implicit none\n\n ! integer kind for large integers\n integer, parameter :: ik = selected_int_kind( 10 )\n\n ! number of points used for the approximation\n integer( kind = ik ), parameter :: numberOfPoints = 1000 * 1000 * 100 \n\n ! state for frand123\n type( frand123State_t ) :: state\n\n ! timing variables\n real( kind = c_double ) :: startTime, endTime\n\n ! result variables\n real( kind = c_double ) :: varPiScalar, varPiTwo, varPi2000\n\n ! initialize state\n call frand123Init( state, 0, 0 )\n\n ! use piScalar\n startTime = omp_get_wtime()\n varPiScalar = piScalar( state )\n endTime = omp_get_wtime()\n write(*, '( \"Result generating one random number at a time: \", ES11.4, &\n & \" took \", ES11.4, \" seconds\" )' ) varPiScalar, endTime - startTime\n\n ! use piTwo\n startTime = omp_get_wtime()\n varPiTwo = piTwo( state )\n endTime = omp_get_wtime()\n write(*, '( \"Result generating two random number at a time: \", ES11.4, &\n & \" took \", ES11.4, \" seconds\" )' ) varPiTwo, endTime - startTime\n\n ! use pi2000\n startTime = omp_get_wtime()\n varPi2000 = pi2000( state )\n endTime = omp_get_wtime()\n write(*, '( \"Result generating 2000 random number at a time: \", ES11.4, &\n & \" took \", ES11.4, \" seconds\" )' ) varPiTwo, endTime - startTime\n\ncontains\n \n ! comput pi drawing a single double precision uniformly distributed random\n ! number at a time\n real( kind = c_double ) function piScalar( state )\n implicit none\n type( frand123State_t ), intent( inout ) :: state\n\n ! local variables\n integer( kind = ik ) :: inside ! counter for points inside unit circle\n integer( kind = ik ) :: i ! loop variable\n real( kind = c_double ) :: x, y ! coordinates of the point\n real( kind = c_double ) :: r2 ! square of the distance to (0,0)\n\n ! approximate pi\n inside = 0\n do i = 1, numberOfPoints\n ! generate point in the unit square\n call frand123Double( state, x )\n call frand123Double( state, y )\n ! compute square of radius and check whether inside unit circle\n r2 = x * x + y * y\n if( r2 .lt. 1.d0 ) then\n inside = inside + 1\n endif\n enddo\n ! pi = 4 * ratio between points inside unit circle and points generated\n piScalar = 4.d0 * real( inside, c_double ) / &\n real( numberOfPoints, c_double )\n end function piScalar\n \n ! comput pi drawing two double precision uniformly distributed random\n ! number at a time\n real( kind = c_double ) function piTwo( state )\n implicit none\n type( frand123State_t ), intent( inout ) :: state\n\n ! local variables\n integer( kind = ik ) :: inside ! counter for points inside unit circle\n integer( kind = ik ) :: i ! loop variable\n real( kind = c_double ), dimension( 2 ) :: pos ! coordinates of the point\n real( kind = c_double ) :: r2 ! square of the distance to (0,0)\n\n ! approximate pi\n inside = 0\n do i = 1, numberOfPoints\n ! generate point in the unit square\n call frand123Double( state, pos )\n ! compute square of radius and check whether inside unit circle\n r2 = sum( pos ** 2 )\n if( r2 .lt. 1.d0 ) then\n inside = inside + 1\n endif\n enddo\n ! pi = 4 * ratio between points inside unit circle and points generated\n piTwo = 4.d0 * real( inside, c_double ) / &\n real( numberOfPoints, c_double )\n end function piTwo\n \n ! comput pi drawing 2000 double precision uniformly distributed random\n ! number at a time\n real( kind = c_double ) function pi2000( state )\n implicit none\n type( frand123State_t ), intent( inout ) :: state\n\n ! local variables\n integer( kind = ik ) :: inside ! counter for points inside unit circle\n integer( kind = ik ) :: i, j ! loop variables\n real( kind = c_double ), dimension( 2000 ) :: buffer ! buffer for RNG\n real( kind = c_double ) :: r2 ! square of the distance to (0,0)\n\n ! approximate pi\n inside = 0\n do i = 1, numberOfPoints, 1000\n ! generate point in the unit square\n call frand123Double( state, buffer )\n do j = 1, 1000\n ! compute square of radius and check whether inside unit circle\n r2 = sum( buffer( 2 * j - 1:2 * j ) ** 2 )\n if( r2 .lt. 1.d0 ) then\n inside = inside + 1\n endif\n enddo\n enddo\n ! pi = 4 * ratio between points inside unit circle and points generated\n pi2000 = 4.d0 * real( inside, c_double ) / &\n real( numberOfPoints, c_double )\n end function pi2000\nend program piDouble\n", "meta": {"hexsha": "d8db6d6a6f9a3b408198750ba9ad6775449e5c76", "size": 5267, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/Fortran/piDouble.f90", "max_stars_repo_name": "maedoc/frand123", "max_stars_repo_head_hexsha": "81591c06d8d705b3fc87531da6c3681e2127b228", "max_stars_repo_licenses": ["Intel"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/Fortran/piDouble.f90", "max_issues_repo_name": "maedoc/frand123", "max_issues_repo_head_hexsha": "81591c06d8d705b3fc87531da6c3681e2127b228", "max_issues_repo_licenses": ["Intel"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/Fortran/piDouble.f90", "max_forks_repo_name": "maedoc/frand123", "max_forks_repo_head_hexsha": "81591c06d8d705b3fc87531da6c3681e2127b228", "max_forks_repo_licenses": ["Intel"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.324137931, "max_line_length": 79, "alphanum_fraction": 0.6223656731, "num_tokens": 1401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632856092016, "lm_q2_score": 0.8376199653600371, "lm_q1q2_score": 0.7767780031681496}} {"text": "program tarefaa\n implicit real(8) (a-h,o-z)\n parameter (pi = 4d0*atan(1d0))\n\n g = 9.8d0\n a_l = 9.8d0\n a_m = 1d0\n dt = 1d-3\n tmax = 120d0\n omega_i = 0d0\n theta_i = pi/15\n i = 0\n\n open(10, file='saida-a1-10407962.dat')\n\n do while ( i*dt.le.tmax )\n \n theta_i = mod(theta_i, 2*pi)\n\n omega_j = omega_i - g*theta_i*dt/a_l\n theta_j = theta_i + omega_i*dt\n\n omega_i = omega_j\n theta_i = theta_j\n\n Ec = 0.5*a_m*(omega_i*a_l)**2\n Ep = a_m*g*a_l*(1-cos(theta_i))\n\n write(10, '(F0.16,3(\" \",F0.16))') i*dt, theta_i, Ec+Ep\n i = i+1\n end do\n\n close(10)\n \n\n omega_i = 0d0\n theta_i = pi/15\n i = 0\n \n open(10, file='saida-a2-10407962.dat')\n \n do while ( i*dt.le.tmax )\n \n theta_i = mod(theta_i, 2*pi)\n\n omega_i = omega_i - g*theta_i*dt/a_l\n theta_i = theta_i + omega_i*dt\n\n Ec = 0.5*a_m*(omega_i*a_l)**2\n Ep = a_m*g*a_l*(1-cos(theta_i))\n\n write(10, '(F0.16,2(\" \",F0.16))') i*dt, theta_i, Ec+Ep\n i = i+1\n end do\n\n close(10)\nend program tarefaa\n", "meta": {"hexsha": "63ff6600ed857ab96e2cb215d838994b34a48476", "size": 1123, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "projeto-5/tarefa-a/tarefa-a-10407962.f90", "max_stars_repo_name": "ArexPrestes/introducao-fisica-computacional", "max_stars_repo_head_hexsha": "bf6e7a0134c11ddbaf9125c42eb0982250f970d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "projeto-5/tarefa-a/tarefa-a-10407962.f90", "max_issues_repo_name": "ArexPrestes/introducao-fisica-computacional", "max_issues_repo_head_hexsha": "bf6e7a0134c11ddbaf9125c42eb0982250f970d9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "projeto-5/tarefa-a/tarefa-a-10407962.f90", "max_forks_repo_name": "ArexPrestes/introducao-fisica-computacional", "max_forks_repo_head_hexsha": "bf6e7a0134c11ddbaf9125c42eb0982250f970d9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.3620689655, "max_line_length": 62, "alphanum_fraction": 0.5066785396, "num_tokens": 435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467157, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.776778002178113}} {"text": "PROGRAM Test_SVD\r\n\r\n! A simple test of the SVD module.\r\n\r\n! The matrix:\r\n\r\n! ( 1 2 3 )\r\n! ( 4 5 6 )\r\n! ( 7 8 9 )\r\n! (10 11 12 )\r\n\r\n! has singular values: 25.4624, 1.2907 and zero.\r\n\r\nUSE SVD\r\nIMPLICIT NONE\r\n\r\nREAL (dp) :: e(3), x(4,3), s(4), u(4,4), v(3,3), value\r\nINTEGER :: info, row, col\r\n\r\nvalue = 1.0_dp\r\nDO row = 1, 4\r\n DO col = 1, 3\r\n x(row,col) = value\r\n value = value + 1.0_dp\r\n END DO\r\nEND DO\r\n\r\nCALL dsvdc(x, 4, 3, s, e, u, v, 11, info)\r\n\r\n! Output the singular values\r\n\r\nWRITE(*, 900) s(1:4)\r\n900 FORMAT(' The calculated singular values = ', 4f10.4/)\r\n\r\n! Output the U matrix\r\n\r\nWRITE(*, *) ' The U-matrix'\r\nDO row = 1, 4\r\n WRITE(*, 910) u(row,1:4)\r\n 910 FORMAT(4f10.4)\r\nEND DO\r\n\r\n! Now the right-hand or V-matrix\r\n\r\nWRITE(*, *)\r\nWRITE(*, *) ' The V-matrix'\r\nDO row = 1, 3\r\n WRITE(*, 910) v(row,1:3)\r\nEND DO\r\n\r\nSTOP\r\nEND PROGRAM Test_SVD\r\n", "meta": {"hexsha": "42ca0c557fd426b19c6a0c03ae8d449ec3d87630", "size": 884, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/t_svd.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/t_svd.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/t_svd.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 16.679245283, "max_line_length": 58, "alphanum_fraction": 0.5418552036, "num_tokens": 361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810436809827, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.7767513980309156}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran77 Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n!\n! ... A test program illustrating the\n! use of subroutine vshifte (see documentation for vshifte)\n!\n!\n! Let the analytic vector field (u, v) in geophysical coordinates be\n! given by\n!\n! u = -exp(x)*sin(p) + exp(-z)*cos(p) + exp(y)*sin(t)*sin(p)\n!\n! v = exp(y)*cos(p) + exp(z)*cos(t) - exp(x)*sin(t)*cos(p)\n!\n! where t is the latitude coordinate, p is the longitude coordinate, \n! and x=cos(t)*cos(p), y=cos(t)*sin(p), z=sin(t) are the cartesian coordinates\n! restricted to the sphere.\n\n! The \"offset\" vector field (uoff, voff) is set equal to (u, v).\n! This is transferred to the \"regular\" grid in (ureg, vreg). (ureg, vreg)\n! is then compared with (u, v) on the regular grid. Finally (ureg, vreg)\n! is transferred back to (uoff, voff) which is again compared with (u, v).\n! The least squares error after each transformation with vshifte\n! is computed and printed. Results from running the program on\n! a 2.5 degree equally spaced regular and offset grid is given.\n! Output from runs on separate platforms with 32 bit and 64 bit\n! floating point arithmetic is listed.\n!\n! *********************************************\n! OUTPUT\n! *********************************************\n!\n! vshifte arguments\n! ioff = 0 nlon = 144 nlat = 72\n! lsave = 608 lwork = 21024\n! ier = 0\n! least squares error\n! *** 32 BIT ARITHMETIC\n! err2u = 0.377E-06 err2v = 0.328E-06\n! *** 64 BIT ARITHMETIC\n! err2u = 0.777E-13 err2v = 0.659E-13\n\n! vshifte arguments\n! ioff = 1 nlon = 144 nlat = 72\n! lsave = 608 lwork = 21024\n! ier = 0\n! least squares error\n! *** 32 BIT ARITHMETIC\n! err2u = 0.557E-06 err2v = 0.434E-06\n! *** 64 BIT AIRTHMETIC\n! err2u = 0.148E-12 err2v = 0.118E-12\n!\n! *********************************************\n! END OF OUTPUT (CODE FOLLOWS)\n! *********************************************\n!\nprogram testvshifte\n\n use, intrinsic :: ISO_Fortran_env, only: &\n stdout => OUTPUT_UNIT\n\n use spherepack\n\n ! Explicit typing only\n implicit none\n\n ! Dictionary\n integer(ip), parameter :: nlon = 144, nlat = 72\n integer(ip), parameter :: nlatp1 = nlat+1\n integer(ip) :: ioff, i, j, error_flag\n real(wp) :: dlat, dlon, half_dlat, half_dlon, lat, long, x, y, z, ex, ey, ez, emz\n real(wp) :: err2u, err2v, ue, ve, sint, sinp, cost, cosp\n real(wp) :: uoff(nlon, nlat), voff(nlon, nlat)\n real(wp) :: ureg(nlon, nlatp1), vreg(nlon, nlatp1)\n real(wp), allocatable :: wavetable(:)\n real(wp), parameter :: ZERO = 0.0_wp\n\n ! Set grid increments\n dlat = PI/nlat\n dlon = TWO_PI/nlon\n half_dlat = dlat/2\n half_dlon = dlon/2\n\n ! Set (uoff, voff) = (u, v) on offset grid\n do j=1, nlon\n long = half_dlon + real(j - 1, kind=wp) * dlon\n sinp = sin(long)\n cosp = cos(long)\n do i=1, nlat\n lat = -HALF_PI + half_dlat + real(i - 1, kind=wp) * dlat\n sint = sin(lat)\n cost = cos(lat)\n x = cost*cosp\n y = cost*sinp\n z = sint\n ex = exp(x)\n ey = exp(y)\n ez = exp(z)\n emz = exp(-z)\n uoff(j, i) =-ex*sinp+emz*cost+ey*sint*sinp\n voff(j, i) = ey*cosp+ez*cost-ex*sint*cosp\n end do\n end do\n\n ! Initialize wsav for offset to regular shift\n ioff = 0\n call initialize_vshifte(ioff, nlon, nlat, wavetable, error_flag)\n\n ! Write input arguments to vshifte\n write (stdout, 100) ioff, nlon, nlat\n100 format(' vshifte arguments', &\n /' ioff = ', i2, ' nlon = ', i3, ' nlat = ', i3)\n\n ! Shift offset to regular grid\n call vshifte(ioff, nlon, nlat, uoff, voff, ureg, vreg, wavetable, error_flag)\n\n write (stdout, 200) error_flag\n200 format(' ier = ', i2)\n\n if (error_flag == 0) then\n ! Compute error in ureg, vreg\n err2u = ZERO\n err2v = ZERO\n do j=1, nlon\n long = real(j - 1, kind=wp) * dlon\n sinp = sin(long)\n cosp = cos(long)\n do i=1, nlat+1\n lat = -HALF_PI + real(i - 1, kind=wp) * dlat\n sint = sin(lat)\n cost = cos(lat)\n x = cost*cosp\n y = cost*sinp\n z = sint\n ex = exp(x)\n ey = exp(y)\n ez = exp(z)\n emz = exp(-z)\n ue = -ex*sinp+emz*cost+ey*sint*sinp\n ve = ey*cosp+ez*cost-ex*sint*cosp\n err2u = err2u + (ureg(j, i)-ue)**2\n err2v = err2v + (vreg(j, i)-ve)**2\n end do\n end do\n err2u = sqrt(err2u/(nlon*(nlat + 1)))\n err2v = sqrt(err2v/(nlon*(nlat + 1)))\n write (stdout, 300) err2u, err2v\n300 format(' least squares error ', &\n /' err2u = ', e10.3, ' err2v = ', e10.3)\n end if\n\n ! Initialize wsav for regular to offset shift\n ioff = 1\n call initialize_vshifte(ioff, nlon, nlat, wavetable, error_flag)\n\n ! Transfer regular grid values in (ureg, vreg) to offset grid in (uoff, voff)\n uoff = ZERO\n voff = ZERO\n\n write (stdout, 100) ioff, nlon, nlat\n\n call vshifte(ioff, nlon, nlat, uoff, voff, ureg, vreg, wavetable, error_flag)\n\n write (stdout, 200) error_flag\n\n if (error_flag == 0) then\n ! compute error in uoff, voff\n err2u = ZERO\n err2v = ZERO\n do j=1, nlon\n long = half_dlon+(j-1)*dlon\n sinp = sin(long)\n cosp = cos(long)\n do i=1, nlat\n lat = -HALF_PI + half_dlat + real(i - 1, kind=wp) * dlat\n sint = sin(lat)\n cost = cos(lat)\n x = cost*cosp\n y = cost*sinp\n z = sint\n ex = exp(x)\n ey = exp(y)\n ez = exp(z)\n emz = exp(-z)\n ue = -ex*sinp+emz*cost+ey*sint*sinp\n ve = ey*cosp+ez*cost-ex*sint*cosp\n err2u = err2u + (uoff(j, i)-ue)**2\n err2v = err2v + (voff(j, i)-ve)**2\n end do\n end do\n err2u = sqrt(err2u/(nlon*(nlat + 1)))\n err2v = sqrt(err2v/(nlon*(nlat + 1)))\n write (stdout, 300) err2u, err2v\n end if\n\n ! Release memory\n deallocate (wavetable)\n\nend program testvshifte\n", "meta": {"hexsha": "53aa38f13e1f1c03622f62b00e0d5b05ece6f0d0", "size": 8484, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/testvshifte.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "test/testvshifte.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "test/testvshifte.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 37.0480349345, "max_line_length": 85, "alphanum_fraction": 0.4213814239, "num_tokens": 2385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953030553433, "lm_q2_score": 0.8652240825770432, "lm_q1q2_score": 0.7767075950197802}} {"text": "C PROGRAM FOR DIAGONALIZING A SYMMETRIC MATRIX USING JACOBI METHOD\nC GAURAV RUDRA MALIK R.NO:23\n\tDIMENSION A(5,5),U(5,5),UT(5,5),S1(5,5),S(5,5)\n\tWRITE(*,*)'ENTER THE MATRIX ORDER, MAX:5'\n\tREAD(*,*)N\n50\tWRITE(*,*)'ENTER THE MATRIX ELEMENTS FOR THE SYMMETRIC MATRIX'\n\tDO 2 I=1,N\n\tDO 1 J=1,N\n\tREAD(*,*)A(I,J)\n1\tCONTINUE\n2\tCONTINUE\n\tDO 4 I=1,N\n\tDO 3 J=1,N\n\tIF(I.NE.J)THEN\n\tIF(A(I,J).NE.A(J,I))THEN\n\tWRITE(*,*)'DIAGONALIZATION NOT POSSIBLE'\n\tGOTO 50\t\n\tENDIF\n\tENDIF\n3\tCONTINUE\n4\tCONTINUE\n\tWRITE(*,*)'ENTER THE NUMBER OF ITERATIONS'\n\tREAD(*,*)M\n\tDO 70 IJ=1,M\nC INITIALIZING THE TRANSFORMATION MATRIX AS IDENTITY\n\tDO 6 I=1,N\n\tU(I,I)=1.0\n\tDO 5 J=1,N\n\tIF(I.NE.J)THEN\n\tU(I,J)=0.0\n\tENDIF\n5\tCONTINUE\n6\tCONTINUE\nC LARGEST OFF DIAGONAL\n\tL=A(1,2)\n\tDO 8 I=2,N\n\tDO 7 J=2,I\n\tIF(A(I,J).GT.L)THEN\n\tL=A(I,J)\n\tII=I\n\tJJ=J\n\tENDIF\n7\tCONTINUE\n8\tCONTINUE\n\tTH=0.5*ATAN((2*L)/(A(II,II)-A(JJ,JJ)))\n\tU(II,II)=COS(TH)\n\tU(JJ,JJ)=COS(TH)\n\tU(II,JJ)=SIN(TH)\n\tU(JJ,II)=SIN(TH)*(-1)\nC TRANSPOSE\t\n\tDO 10 I=1,N\n\tDO 9 J=1,N\n\tUT(I,J)=U(J,I)\n9\tCONTINUE\n10\tCONTINUE\nC MULTIPLICATION\t\t\n\tDO 13 I=1,N\n\tDO 12 J=1,N\n\tS1(I,J)=0.0\n\tDO 11 K=1,N\n\tS1(I,J)=S1(I,J) + A(I,K)*U(K,J)\n11\tCONTINUE\n12\tCONTINUE\n13\tCONTINUE\n\tDO 16 I=1,N\n\tDO 15 J=1,N\n\tS(I,J)=0.0\n\tDO 14 K=1,N\n\tS(I,J)=S(I,J) + UT(I,K)*S1(K,J)\n14\tCONTINUE\n15\tCONTINUE\n16\tCONTINUE\n\tDO 19 I=1,N\n\tDO 18 J=1,N\n\tA(I,J)=S(I,J)\n18\tCONTINUE\n19\tCONTINUE\n70\tCONTINUE\nC RESULT DISPLAY\n\tWRITE(*,*)'THE DIAGONALIZED MATRIX IS:'\n\tDO 21 I=1,N\n\tWRITE(*,22)(A(I,J),j=1,n)\n21\tCONTINUE\n22\tFORMAT(3(F8.4,5X))\n\tSTOP\n\tEND\n\n\nRESULT:\n\n ENTER THE MATRIX ORDER, MAX:5\n3\n ENTER THE MATRIX ELEMENTS FOR THE SYMMETRIC MATRIX\n2\n1\n0\n1\n1\n2\n0\n2\n1\n ENTER THE NUMBER OF ITERATIONS\n50\n THE DIAGONALIZED MATRIX IS:\n 2.0000 .0002 .0007\n .0000 .7500 .0000\n .0000 .0000 -1.0000\n\n\n", "meta": {"hexsha": "7ee02075d9d6e5914bccc2ae116321772f7f6847", "size": 1786, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Jacobi.f", "max_stars_repo_name": "GauravR-Malik/ComputationPhysics_Fortran", "max_stars_repo_head_hexsha": "70ab4d6fe815538c23715799159e46e63dbbde3c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Jacobi.f", "max_issues_repo_name": "GauravR-Malik/ComputationPhysics_Fortran", "max_issues_repo_head_hexsha": "70ab4d6fe815538c23715799159e46e63dbbde3c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Jacobi.f", "max_forks_repo_name": "GauravR-Malik/ComputationPhysics_Fortran", "max_forks_repo_head_hexsha": "70ab4d6fe815538c23715799159e46e63dbbde3c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.0900900901, "max_line_length": 66, "alphanum_fraction": 0.6332586786, "num_tokens": 860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395168021653, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7766160517617884}} {"text": "program fibonacci\n implicit none\n\n integer(kind=16) get_fibo\n integer(kind=16) fibo_sum\n\n integer n\n\n print*, \"Qué termino de la serie de fibonacci quieres?(4 bytes max)\"\n read*, n\n\n print*, \"El \",n,\"-ésimo termino de la serie es: \",get_fibo(n)\n\n print*, \"La suma de todos es:\", fibo_sum(n)\n\nend program\n\nrecursive function get_fibo(limit) result(res)\n implicit none\n\n integer(kind=16) res\n integer, intent(in) :: limit\n\n if (limit <= 2) then\n res = 1\n else\n res = get_fibo(limit-1) + get_fibo(limit-2)\n end if\n\nend function get_fibo\n\ninteger(kind=16) function fibo_sum(limit)\n implicit none\n\n integer(kind=16) get_fibo\n\n integer(kind=16) :: ans = 0\n integer, intent(in) :: limit\n integer :: i\n\n do i=0, limit\n ans = get_fibo(i) + ans\n end do\n\n fibo_sum = ans-1\n\nend function fibo_sum\n", "meta": {"hexsha": "e5f2424b24129a3c7498ad24aab2f757f3c008a0", "size": 816, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Funciones y Subrutinas/Ejercicios/fibonacci.f90", "max_stars_repo_name": "kotoromo/Fortran-Intermedio", "max_stars_repo_head_hexsha": "1619dec69005ddef81e7cd7d39c85aacd98928ee", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Funciones y Subrutinas/Ejercicios/fibonacci.f90", "max_issues_repo_name": "kotoromo/Fortran-Intermedio", "max_issues_repo_head_hexsha": "1619dec69005ddef81e7cd7d39c85aacd98928ee", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Funciones y Subrutinas/Ejercicios/fibonacci.f90", "max_forks_repo_name": "kotoromo/Fortran-Intermedio", "max_forks_repo_head_hexsha": "1619dec69005ddef81e7cd7d39c85aacd98928ee", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.0, "max_line_length": 70, "alphanum_fraction": 0.6703431373, "num_tokens": 263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.7765987167683291}} {"text": "program mean_time_of_day\n implicit none\n integer(kind=4), parameter :: dp = kind(0.0d0)\n\n type time_t\n integer(kind=4) :: hours, minutes, seconds\n end type\n\n character(len=8), dimension(4), parameter :: times = &\n (/ '23:00:17', '23:40:20', '00:12:45', '00:17:19' /)\n real(kind=dp), dimension(size(times)) :: angles\n real(kind=dp) :: mean\n\n angles = time_to_angle(str_to_time(times))\n mean = mean_angle(angles)\n if (mean < 0) mean = 360 + mean\n\n write(*, fmt='(I2.2, '':'', I2.2, '':'', I2.2)') angle_to_time(mean)\ncontains\n real(kind=dp) function mean_angle(angles)\n real(kind=dp), dimension(:), intent (in) :: angles\n real(kind=dp) :: x, y\n\n x = sum(sin(radians(angles)))/size(angles)\n y = sum(cos(radians(angles)))/size(angles)\n\n mean_angle = degrees(atan2(x, y))\n end function\n\n elemental real(kind=dp) function radians(angle)\n real(kind=dp), intent (in) :: angle\n real(kind=dp), parameter :: pi = 4d0*atan(1d0)\n radians = angle/180*pi\n end function\n\n elemental real(kind=dp) function degrees(angle)\n real(kind=dp), intent (in) :: angle\n real(kind=dp), parameter :: pi = 4d0*atan(1d0)\n degrees = 180*angle/pi\n end function\n\n elemental type(time_t) function str_to_time(str)\n character(len=*), intent (in) :: str\n ! Assuming time in format hh:mm:ss\n read(str, fmt='(I2, 1X, I2, 1X, I2)') str_to_time\n end function\n\n elemental real(kind=dp) function time_to_angle(time) result (res)\n type(time_t), intent (in) :: time\n\n real(kind=dp) :: seconds\n real(kind=dp), parameter :: seconds_in_day = 24*60*60\n\n seconds = time%seconds + 60*time%minutes + 60*60*time%hours\n res = 360*seconds/seconds_in_day\n end function\n\n elemental type(time_t) function angle_to_time(angle)\n real(kind=dp), intent (in) :: angle\n\n real(kind=dp) :: seconds\n real(kind=dp), parameter :: seconds_in_day = 24*60*60\n\n seconds = seconds_in_day*angle/360d0\n angle_to_time%hours = int(seconds/60d0/60d0)\n seconds = mod(seconds, 60d0*60d0)\n angle_to_time%minutes = int(seconds/60d0)\n angle_to_time%seconds = mod(seconds, 60d0)\n end function\nend program\n", "meta": {"hexsha": "9928c2e53ea2f96f6900068bf1e6673cbae837b3", "size": 2129, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Averages-Mean-time-of-day/Fortran/averages-mean-time-of-day.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Averages-Mean-time-of-day/Fortran/averages-mean-time-of-day.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Averages-Mean-time-of-day/Fortran/averages-mean-time-of-day.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 29.985915493, "max_line_length": 70, "alphanum_fraction": 0.6594645373, "num_tokens": 685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741281688025, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7765693756612739}} {"text": "PROGRAM demo\r\n\r\n! Program to demonstrate the use of module LSQ for unconstrained\r\n! linear least-squares regression.\r\n! The data on fuel consumption are from:\r\n! Sanford Weisberg `Applied Linear Regression', 2nd edition, 1985,\r\n! pages 35-36. Publisher: Wiley\r\n\r\n! The program is designed so that users can easily edit it for their\r\n! problems. If you are likely to have more than 500 cases then increase\r\n! the value of maxcases below. Similarly, if you may have more than\r\n! 30 predictor variables, change maxvar below.\r\n\r\n! The subscript 0 is used to relate to the constant in the model.\r\n! Module LSQ treats the constant in the model, if there is one, just as\r\n! any other variable. The numbering of all arrays starts from 1 in LSQ.\r\n\r\nUSE lsq ! Must be the first declaration in the program\r\nIMPLICIT NONE\r\n\r\nINTEGER, PARAMETER :: maxcases = 500, maxvar = 30, &\r\n max_cdim = maxvar*(maxvar+1)/2, lout = 6\r\nINTEGER :: case, nvar, iostatus, nreq, ifault, i, list(maxvar), j, &\r\n in, i1, i2\r\nREAL (dp) :: xx(0:maxvar), yy, wt, one = 1.D0, beta(0:maxvar), &\r\n var, covmat(max_cdim), sterr(0:maxvar), hii, &\r\n cormat(max_cdim), ycorr(maxvar)\r\nREAL (KIND(0.E0)) :: x(maxcases, maxvar), y(maxcases), t(0:maxvar), tmin, &\r\n r2, resid(maxcases), std_resid(maxcases), std_err_pred, &\r\n fitted, stdev_res\r\nCHARACTER (LEN=80) :: heading, output\r\nCHARACTER (LEN= 2) :: state(50)\r\nCHARACTER (LEN= 8) :: vname(0:maxvar), y_name\r\nLOGICAL :: fit_const, lindep(0:maxvar)\r\n\r\n! Interfaces\r\n\r\nINTERFACE\r\n SUBROUTINE separate_text(heading, vname, nvar)\r\n IMPLICIT NONE\r\n CHARACTER (LEN = *), INTENT(IN OUT) :: heading\r\n CHARACTER (LEN = *), DIMENSION(:), INTENT(OUT) :: vname\r\n INTEGER, INTENT(OUT) :: nvar\r\n END SUBROUTINE separate_text\r\nEND INTERFACE\r\n\r\nINTERFACE\r\n SUBROUTINE printc(in, cormat, dimc, ycorr, vname, yname, iopt, lout, ier)\r\n USE lsq\r\n IMPLICIT NONE\r\n INTEGER, INTENT(IN) :: in, dimc, iopt, lout\r\n INTEGER, INTENT(OUT) :: ier\r\n REAL (dp), DIMENSION(:), INTENT(IN) :: cormat, ycorr\r\n CHARACTER (LEN=*), DIMENSION(0:), INTENT(IN) :: vname\r\n CHARACTER (LEN=*), INTENT(IN) :: yname\r\n END SUBROUTINE printc\r\nEND INTERFACE\r\n\r\n\r\nWRITE(*, *)'The data on fuel consumption are from:'\r\nWRITE(*, *)'Sanford Weisberg \"Applied Linear Regression\", 2nd edition, 1985,'\r\nWRITE(*, *)'pages 35-36. Publisher: Wiley ISBN: 0-471-87957-6'\r\nWRITE(*, *)\r\n\r\nOPEN(8, file='fuelcons.dat', status='old')\r\n\r\n! The first line of this file contains the names of the variables.\r\n\r\nREAD(8, '(a)') heading\r\n\r\nvname(0) = 'Constant'\r\n\r\n! Read the heading to get the variable names & the number of variables\r\n\r\nCALL separate_text(heading, vname, nvar)\r\n\r\nnvar = nvar - 2 ! nvar is the number of variables.\r\n ! 1 is subtracted as the first field in this\r\n ! file contains the abbreviated state name,\r\n ! & 1 is subtracted for the Y-variable.\r\nvname(1:nvar) = vname(2:nvar+1)\r\ny_name = vname(nvar+2)\r\n\r\nWRITE(*, *)'No. of variables =', nvar\r\nWRITE(*, *)'Predictor variables are:'\r\nWRITE(*, '(\" \", 9a9)') vname(1:nvar)\r\nWRITE(*, *)'Dependent variable is: ', y_name\r\n\r\nfit_const = .true. ! Change to .false. if fitting a model without\r\n ! a constant.\r\n\r\nCALL startup(nvar, fit_const) ! Initializes the QR-factorization\r\n\r\n! Read in the data, one line at a time, and progressively update the\r\n! QR-factorization.\r\n\r\nwt = one\r\ncase = 1\r\n\r\nDO\r\n READ(8, *, IOSTAT=iostatus) state(case), x(case, 1:nvar), y(case)\r\n IF (iostatus > 0) CYCLE ! Error in data\r\n IF (iostatus < 0) EXIT ! End of file\r\n\r\n xx(0) = one ! A one is inserted as the first\r\n ! variable if a constant is being fitted.\r\n xx(1:nvar) = x(case, 1:nvar) ! New variables and transformed variables\r\n ! will often be generated here.\r\n yy = y(case)\r\n CALL includ(wt, xx, yy)\r\n case = case + 1\r\nEND DO\r\n\r\nWRITE(*, *)'No. of observations =', nobs\r\n\r\nCALL sing(lindep, ifault) ! Checks for singularities\r\n\r\nIF (ifault == 0) THEN\r\n WRITE(*, *)'QR-factorization is not singular'\r\nELSE\r\n DO i = 1, nvar\r\n IF (lindep(i)) THEN\r\n WRITE(*, *) vname(i), ' is exactly linearly related to earlier variables'\r\n END IF\r\n END DO ! i = 1, nvar\r\nEND IF ! (ifault == 0)\r\nWRITE(*, *)\r\n\r\n! Show correlations (IN = 1 for `usual' correlations)\r\n\r\nin = 1\r\nCALL partial_corr(in, cormat, max_cdim, ycorr, ifault)\r\nCALL printc(in, cormat, max_cdim, ycorr, vname, y_name, 1, lout, ifault)\r\nWRITE(*, *)\r\nWRITE(*, *)'Press ENTER to continue'\r\nREAD(*, *)\r\n\r\n! Weisberg only uses variables TAX, INC, ROAD and DLIC. These are\r\n! currently in positions 2, 4, 5 & 7.\r\n! We could have set NVAR = 4 and copied only these variables from X to\r\n! XX, but we will show how regressions can be performed for a subset\r\n! of the variables in the QR-factorization. Routine REORDR will be used\r\n! to re-order the variables.\r\n\r\nlist(1:4) = (/ 2, 4, 5, 7/)\r\nCALL reordr(list, 4, 2, ifault) ! Re-order so that the first 4 variables\r\n ! appear in positions 2,3,4 & 5.\r\n ! N.B. Though variables # 2, 4, 5 & 7\r\n ! will occupy positions 2-5, they\r\n ! may be in any order.\r\n ! The constant remains in position 1.\r\nWRITE(*, 910) (vname(vorder(1:ncol)))\r\n910 FORMAT(' Current order of variables:'/' ', 8a9/)\r\n\r\n! Calculate regression coefficients of Y against the first variable, which\r\n! was just a constant = 1.0, and the next 4 predictors.\r\n\r\nCALL tolset() ! Calculate tolerances before calling\r\n ! subroutine regcf.\r\nnreq = 5 ! i.e. Const, TAX, INC, ROAD, DLIC\r\nCALL regcf(beta, nreq, ifault)\r\n\r\nCALL ss() ! Calculate residual sums of squares\r\n\r\n! Calculate covariance matrix of the regression coefficients & their\r\n! standard errors.\r\n\r\nvar = rss(nreq) / (nobs - nreq)\r\nCALL cov(nreq, var, covmat, max_cdim, sterr, ifault)\r\n\r\n! Calculate t-values\r\n\r\nt(0:nreq-1) = beta(0:nreq-1) / sterr(0:nreq-1)\r\n\r\n! Output regression table, residual sums of squares, and R-squared.\r\n\r\nWRITE(*, *)\r\nWRITE(*, *)'Variable Regn.coeff. Std.error t-value Res.sum of sq.'\r\nDO i = 0, nreq-1\r\n WRITE(*, 900) vname(vorder(i+1)), beta(i), sterr(i), t(i), rss(i+1)\r\n 900 FORMAT(' ', a8, ' ', g12.4, ' ', g11.4, ' ', f7.2, ' ', g14.6)\r\nEND DO\r\nWRITE(*, *)\r\n\r\n! Output correlations of the parameter estimates\r\n\r\nWRITE(*, *) 'Covariances of parameter estimates'\r\ni2 = nreq\r\nDO i = 1, nreq-1\r\n i1 = i2 + 1\r\n i2 = i2 + nreq - i\r\n WRITE(output, '(\" \", a8)') vname(vorder(i+1))\r\n WRITE(output(10*i:), '(7f10.3)') covmat(i1:i2)\r\n WRITE(*, '(a)') output\r\nEND DO\r\nWRITE(*, *)\r\n\r\n! Now delete the variable with the smallest t-value by moving it\r\n! to position 5 and then repeating the calculations for the constant\r\n! and the next 3 variables.\r\n\r\nj = 1\r\ntmin = ABS(t(1))\r\nDO i = 2, nreq-1\r\n IF (ABS(t(i)) < tmin) THEN\r\n j = i\r\n tmin = ABS(t(i))\r\n END IF\r\nEND DO\r\nj = j + 1 ! Add 1 as the t-array started at subscript 0\r\n\r\nWRITE(*, *)'Removing variable in position', j\r\nCALL vmove(j, nreq, ifault)\r\nnreq = nreq - 1\r\nCALL regcf(beta, nreq, ifault)\r\nCALL ss()\r\nCALL cov(nreq, var, covmat, max_cdim, sterr, ifault)\r\nt(0:nreq-1) = beta(0:nreq-1) / sterr(0:nreq-1)\r\n\r\n! Output regression table, residual sums of squares, and R-squared.\r\n\r\nWRITE(*, *)\r\nWRITE(*, *)'Variable Regn.coeff. Std.error t-value Res.sum of sq.'\r\nDO i = 0, nreq-1\r\n WRITE(*, 900) vname(vorder(i+1)), beta(i), sterr(i), t(i), rss(i+1)\r\nEND DO\r\nWRITE(*, *)\r\n\r\nvar = rss(nreq)/(nobs - nreq)\r\nstdev_res = SQRT( var )\r\nr2 = one - rss(nreq) / rss(1) ! RSS(1) is the rss if only the constant\r\n ! is fitted; RSS(nreq) is the rss after\r\n ! fitting the requested NREQ variables.\r\nWRITE(*, '(\" R^2 =\", f8.4, \" Std. devn. of residuals =\", g12.4/)') &\r\n r2, stdev_res\r\nWRITE(*, *)'N.B. Some statistical packages wrongly call the standard deviation'\r\nWRITE(*, *)' of the residuals the standard error of prediction'\r\nWRITE(*, *)\r\n\r\n! Calculate residuals, hii, standardized residuals & standard errors of\r\n! prediction.\r\n\r\nWRITE(*, *)'Press ENTER to continue'\r\nREAD(*, *)\r\n\r\nWRITE(*, *)'State Actual Fitted Residual Std.resid. SE(prediction)'\r\nDO i = 1, nobs\r\n xx(0) = one\r\n DO j = 1, nreq-1\r\n xx(j) = x(i, vorder(j+1)) ! N.B. Regression coefficient j is for\r\n ! the variable vorder(j+1)\r\n END DO\r\n fitted = DOT_PRODUCT( beta(0:nreq-1), xx(0:nreq-1) )\r\n resid(i) = y(i) - fitted\r\n CALL hdiag(xx, nreq, hii, ifault)\r\n std_resid(i) = resid(i) / SQRT(var*(one - hii))\r\n! The sqrt was omitted from the initial version of this demo in line below.\r\n std_err_pred = sqrt( varprd(xx, nreq) )\r\n WRITE(*, 920) state(i), y(i), fitted, resid(i), std_resid(i), std_err_pred\r\n 920 FORMAT(' ', a2, ' ', 3f10.1, f9.2, ' ', f10.0)\r\n\r\n IF (i .EQ. 24) THEN\r\n WRITE(*, *)'Press ENTER to continue'\r\n READ(*, *)\r\n WRITE(*, *)'State Actual Fitted Residual Std.resid. SE(prediction)'\r\n END IF\r\nEND DO ! i = 1, nobs\r\n\r\nSTOP\r\nEND PROGRAM demo\r\n\r\n\r\n\r\nSUBROUTINE separate_text(text, name, number)\r\n\r\n! Takes the character string in `text' and separates it into `names'.\r\n! This version only allows spaces as delimiters.\r\n\r\nIMPLICIT NONE\r\nCHARACTER (LEN = *), INTENT(IN OUT) :: text\r\nCHARACTER (LEN = *), DIMENSION(:), INTENT(OUT) :: name\r\nINTEGER, INTENT(OUT) :: number\r\n\r\n! Local variables\r\n\r\nINTEGER :: length, len_name, pos1, pos2, nchars\r\n\r\nlength = LEN_TRIM(text)\r\nnumber = 0\r\nIF (length == 0) RETURN\r\n\r\nlen_name = LEN(name(1))\r\nIF (len_name < 1) RETURN\r\n\r\npos1 = 1\r\nDO\r\n DO ! Remove any leading blanks\r\n IF (text(pos1:pos1) == ' ') THEN\r\n text(pos1:) = text(pos1+1:)\r\n length = length - 1\r\n CYCLE\r\n ELSE\r\n EXIT\r\n END IF\r\n END DO\r\n pos2 = INDEX(text(pos1:length), ' ') ! Find position of next blank\r\n IF (pos2 > 0) THEN\r\n pos2 = pos2 + pos1 - 1\r\n ELSE ! Last name, no blank found\r\n pos2 = length + 1\r\n END IF\r\n number = number + 1\r\n nchars = MIN(len_name, pos2-pos1)\r\n name(number) = text(pos1:pos1+nchars-1)\r\n pos1 = pos2 + 1 ! Move past the blank\r\n IF (pos1 > length) RETURN\r\nEND DO\r\n\r\nRETURN\r\nEND SUBROUTINE separate_text\r\n\r\n\r\n\r\nSUBROUTINE printc(in, cormat, dimc, ycorr, vname, yname, iopt, lout, ier)\r\n\r\n! Print (partial) correlations calculated using partial_corr to unit lout.\r\n! If IOPT = 0, print correlations with the Y-variable only.\r\n\r\nUSE lsq\r\n\r\nIMPLICIT NONE\r\nINTEGER, INTENT(IN) :: in, dimc, iopt, lout\r\nINTEGER, INTENT(OUT) :: ier\r\nREAL (dp), DIMENSION(:), INTENT(IN) :: cormat, ycorr\r\nCHARACTER (LEN=*), DIMENSION(0:), INTENT(IN) :: vname\r\nCHARACTER (LEN=*), INTENT(IN) :: yname\r\n\r\n! Local variables.\r\n\r\nINTEGER :: nrows, j1, j2, i1, i2, row, upos, tpos, last\r\nCHARACTER (LEN=74) :: text\r\nCHARACTER (LEN= 9) :: char1 = ' 1.0 '\r\n\r\n! Check validity of arguments\r\n\r\nier = 0\r\nIF (in .GE. ncol) ier = 1\r\nIF (ncol .LE. 1) ier = ier + 2\r\nnrows = ncol - in\r\nIF (dimc .LE. nrows*(nrows-1)/2) ier = ier + 4\r\nIF (ier .NE. 0) RETURN\r\n\r\n! If iopt.NE.0 output heading\r\n\r\nIF (iopt .EQ. 0) GO TO 30\r\nWRITE(lout, 900)\r\n900 FORMAT(/' ', 'Correlation matrix')\r\nj1 = in + 1\r\n\r\nDO\r\n j2 = MIN(j1+6, ncol)\r\n i1 = j1 - in\r\n i2 = j2 - in\r\n WRITE(lout, 910) vname(vorder(j1:j2))\r\n 910 FORMAT(' ', 7(a8, ' '))\r\n\r\n! Print correlations for rows 1 to i2, columns i1 to i2.\r\n\r\n DO row = 1, i2\r\n text = ' ' // vname(vorder(row+in))\r\n IF (i1 .GT. row) THEN\r\n upos = (row-1) * (nrows+nrows-row) /2 + (i1-row)\r\n last = upos + i2 - i1\r\n WRITE(text(12:74), '(7(F8.5, \" \"))') cormat(upos:last)\r\n ELSE\r\n upos = (row-1) * (nrows+nrows-row) /2 + 1\r\n tpos = 12 + 9*(row-i1)\r\n text(tpos:tpos+8) = char1\r\n last = upos + i2 - row - 1\r\n IF (row .LT. i2) WRITE(text(tpos+9:74), '(6(F8.5, \" \"))') cormat(upos:last)\r\n END IF\r\n WRITE(lout, '(a)') text\r\n END DO ! row = 1, i2\r\n\r\n! Move onto the next block of columns.\r\n\r\n j1 = j2 + 1\r\n IF (j1 .GT. ncol) EXIT\r\nEND DO\r\n\r\n! Correlations with the Y-variable.\r\n\r\n30 WRITE(lout, 920) yname\r\n 920 FORMAT(/' Correlations with the dependent variable: ', a)\r\n j1 = in + 1\r\nDO\r\n j2 = MIN(j1+7, ncol)\r\n WRITE(lout, 930) vname(vorder(j1:j2))\r\n 930 FORMAT(/' ', 8(A8, ' '))\r\n WRITE(lout, 940) ycorr(j1:j2)\r\n 940 FORMAT(' ', 8(F8.5, ' '))\r\n j1 = j2 + 1\r\n IF (j1 .GT. ncol) EXIT\r\nEND DO\r\n\r\nRETURN\r\nEND SUBROUTINE printc\r\n", "meta": {"hexsha": "3b4b688289f0cee7e7ab14b67fe6522fda05425e", "size": 13614, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/lsq_demo.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/lsq_demo.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/lsq_demo.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 33.3676470588, "max_line_length": 82, "alphanum_fraction": 0.5592772146, "num_tokens": 4169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942171172603, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.7765292912532287}} {"text": " integer function lcm(a,b)\n integer:: a,b\n lcm = a*b / gcd(a,b)\n end function lcm\n\n integer function gcd(a,b)\n integer :: a,b,t\n do while (b/=0)\n t = b\n b = mod(a,b)\n a = t\n end do\n gcd = abs(a)\n end function gcd\n", "meta": {"hexsha": "b9b5538147ed8f7a9d06014ff905dba163bd8ef7", "size": 292, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Least-common-multiple/Fortran/least-common-multiple.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Least-common-multiple/Fortran/least-common-multiple.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Least-common-multiple/Fortran/least-common-multiple.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 19.4666666667, "max_line_length": 29, "alphanum_fraction": 0.4383561644, "num_tokens": 82, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9637799430946808, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7764521497492836}} {"text": "subroutine elemdetjm(nnode,ndime,elcod,detjm)\n!-----------------------------------------------------------------------\n !****f* Domain/elmdel\n! NAME\n! elmdel\n! DESCRIPTION\n! This routine calculates the Cartesian derivatives cartd and detjm.\n! USES\n! invmtx\n! USED BY\n! nsm_elmope\n! tem_elmope\n! cdr_elmope\n! tem_exaerr\n! extnor\n! SOURCE\n!-----------------------------------------------------------------------\n use typre\n implicit none\n integer(ip), intent(in) :: nnode,ndime\n real(rp), intent(in) :: elcod(ndime,nnode)\n real(rp), intent(out) :: detjm\n real(rp) :: xjacm(ndime,ndime)\n real(rp) :: xjaci(ndime,ndime)\n \n if(ndime==2.and.nnode==3) then\n \n xjacm(1,1) = elcod(1,2)-elcod(1,1)\n xjacm(2,1) = elcod(2,2)-elcod(2,1)\n xjacm(1,2) = elcod(1,3)-elcod(1,1)\n xjacm(2,2) = elcod(2,3)-elcod(2,1)\n \n detjm=xjacm(1,1)*xjacm(2,2)-xjacm(2,1)*xjacm(1,2)\n\n\n elseif (ndime==3.and.nnode==4) then\n \n xjacm(1,1) = elcod(1,2)-elcod(1,1)\n xjacm(2,1) = elcod(2,2)-elcod(2,1)\n xjacm(3,1) = elcod(3,2)-elcod(3,1)\n xjacm(1,2) = elcod(1,3)-elcod(1,1)\n xjacm(2,2) = elcod(2,3)-elcod(2,1)\n xjacm(3,2) = elcod(3,3)-elcod(3,1)\n xjacm(1,3) = elcod(1,4)-elcod(1,1)\n xjacm(2,3) = elcod(2,4)-elcod(2,1)\n xjacm(3,3) = elcod(3,4)-elcod(3,1)\n \n xjaci(1,1) = xjacm(2,2)*xjacm(3,3) - xjacm(3,2)*xjacm(2,3)\n xjaci(2,1) =-xjacm(2,1)*xjacm(3,3) + xjacm(3,1)*xjacm(2,3)\n xjaci(3,1) = xjacm(2,1)*xjacm(3,2) - xjacm(3,1)*xjacm(2,2)\n xjaci(2,2) = xjacm(1,1)*xjacm(3,3) - xjacm(3,1)*xjacm(1,3)\n xjaci(3,2) = -xjacm(1,1)*xjacm(3,2) + xjacm(1,2)*xjacm(3,1)\n xjaci(3,3) = xjacm(1,1)*xjacm(2,2) - xjacm(2,1)*xjacm(1,2)\n xjaci(1,2) = -xjacm(1,2)*xjacm(3,3) + xjacm(3,2)*xjacm(1,3)\n xjaci(1,3) = xjacm(1,2)*xjacm(2,3) - xjacm(2,2)*xjacm(1,3)\n xjaci(2,3) = -xjacm(1,1)*xjacm(2,3) + xjacm(2,1)*xjacm(1,3)\n \n detjm = xjacm(1,1)*xjaci(1,1) + xjacm(1,2)*xjaci(2,1)+ xjacm(1,3)*xjaci(3,1)\n \n end if\n \nend subroutine elemdetjm\n!-----------------------------------------------------------------------\n! NOTES\n!\n! P1 Element in 2D\n! ----------------\n!\n! detjm=(-x1+x2)*(-y1+y3)-(-y1+y2)*(-x1+x3)\n! _ _ \n! | -y3+y2 -y1+y3 y1-y2 | \n! cartd=1/detjm | | \n! |_ x3-x2 x1-x3 -x1+x2 _|\n!\n!***\n!-----------------------------------------------------------------------\n", "meta": {"hexsha": "284ea3e6f0639f5be3741ec68c753e59b1d2f720", "size": 2516, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/domain/elemdetjm.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/domain/elemdetjm.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/domain/elemdetjm.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6753246753, "max_line_length": 81, "alphanum_fraction": 0.4590620032, "num_tokens": 1149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.949669371675949, "lm_q2_score": 0.8175744695262777, "lm_q1q2_score": 0.7764254327733174}} {"text": "module mod_activation\n\n ! A collection of activation functions and their derivatives.\n\n use mod_kinds, only: ik, rk\n\n implicit none\n\n private\n\n public :: activation_function\n public :: gaussian, gaussian_prime, gaussian_double\n public :: relu, relu_prime, relu_double\n public :: sigmoid, sigmoid_prime, sigmoid_double\n public :: step, step_prime, step_double\n public :: tanhf, tanh_prime, tanh_double\n public :: expf, exp_prime, exp_double\n\n interface\n pure function activation_function(x)\n import :: rk\n real(rk), intent(in) :: x(:)\n real(rk) :: activation_function(size(x))\n end function activation_function\n end interface\n\ncontains\n\n pure function gaussian(x) result(res)\n ! Gaussian activation function.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n res = exp(-x**2)\n end function gaussian\n\n pure function gaussian_prime(x) result(res)\n ! First derivative of the Gaussian activation function.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n res = -2 * x * gaussian(x)\n end function gaussian_prime\n\n pure function gaussian_double(x) result(res)\n ! Second derivative of the Gaussian activation function.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n res = -2 * gaussian(x) -2 * x * gaussian_prime(x)\n end function gaussian_double\n\n pure function relu(x) result(res)\n !! REctified Linear Unit (RELU) activation function.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n res = max(0., x)\n end function relu\n\n pure function relu_prime(x) result(res)\n ! First derivative of the REctified Linear Unit (RELU) activation function.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n where (x > 0)\n res = 1\n elsewhere\n res = 0\n end where\n end function relu_prime\n\n pure function relu_double(x) result(res)\n ! Second derivative of the REctified Linear Unit (RELU) activation function.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n res = 0\n end function relu_double\n\n pure function sigmoid(x) result(res)\n ! Sigmoid activation function.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n res = 1 / (1 + exp(-x))\n end function sigmoid\n\n pure function sigmoid_prime(x) result(res)\n ! First derivative of the sigmoid activation function.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n res = sigmoid(x) * (1 - sigmoid(x))\n end function sigmoid_prime\n\n pure function sigmoid_double(x) result(res)\n ! Second derivative of the sigmoid activation function.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n res = sigmoid(x) * (1 - sigmoid(x))**2 - sigmoid(x)**2 * (1 - sigmoid(x))\n end function sigmoid_double\n\n pure function step(x) result(res)\n ! Step activation function.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n where (x > 0)\n res = 1\n elsewhere\n res = 0\n end where\n end function step\n\n pure function step_prime(x) result(res)\n ! First derivative of the step activation function.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n res = 0\n end function step_prime\n\n pure function step_double(x) result(res)\n ! Second derivative of the step activation function.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n res = 0\n end function step_double\n\n pure function tanhf(x) result(res)\n ! Tangent hyperbolic activation function. \n ! Same as the intrinsic tanh, but must be \n ! defined here so that we can use procedure\n ! pointer with it.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n res = tanh(x)\n end function tanhf\n\n pure function tanh_prime(x) result(res)\n ! First derivative of the tanh activation function.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n res = 1 - tanh(x)**2\n end function tanh_prime\n\n pure function tanh_double(x) result(res)\n ! Second derivative of the tanh activation function.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n res = -2 * tanh(x) * ( 1 - tanh(x)**2 ) \n end function tanh_double\n\n pure function expf(x) result(res)\n ! Exponential activation function. \n ! Same as the intrinsic exp, but must be \n ! defined here so that we can use procedure\n ! pointer with it.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n res = exp(x)\n end function expf\n\n pure function exp_prime(x) result(res)\n ! First derivative of the exp activation function.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n res = exp(x)\n end function exp_prime\n\n pure function exp_double(x) result(res)\n ! Second derivative of the exp activation function.\n real(rk), intent(in) :: x(:)\n real(rk) :: res(size(x))\n res = exp(x)\n end function exp_double\n\nend module mod_activation\n", "meta": {"hexsha": "3a8f3df25051dd2b597563ea374b7a6bc9f88416", "size": 4850, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mod_activation.f90", "max_stars_repo_name": "freitas-esw/nn3dho", "max_stars_repo_head_hexsha": "80e3cc47e9bdb2c172aba1e745df35807429d599", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-22T03:21:08.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-22T03:21:08.000Z", "max_issues_repo_path": "src/mod_activation.f90", "max_issues_repo_name": "freitas-esw/nn3dho", "max_issues_repo_head_hexsha": "80e3cc47e9bdb2c172aba1e745df35807429d599", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mod_activation.f90", "max_forks_repo_name": "freitas-esw/nn3dho", "max_forks_repo_head_hexsha": "80e3cc47e9bdb2c172aba1e745df35807429d599", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.5294117647, "max_line_length": 80, "alphanum_fraction": 0.6424742268, "num_tokens": 1325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625012602593, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7762106157667126}} {"text": "!This is a simple test program\n!written to do I donot know what\nPROGRAM Triangle_Area\n\n IMPLICIT NONE\n\n TYPE triangle\n REAL :: a, b, c\n END TYPE triangle\n\n TYPE(triangle) :: t\n\n PRINT*, 'Welcome, please enter the lengths of the 3 sides.'\n READ*, t%a, t%b, t%c\n PRINT*,'Triangle''s area: ',Area(t)\n\nCONTAINS\n\n FUNCTION Area(tri)\n\n IMPLICIT NONE\n\n REAL :: Area ! function type\n TYPE(triangle), INTENT( IN ) :: tri\n REAL :: theta, height\n ! Is this comment recognized???\n\n theta = ACOS( (tri%a**2 + tri%b**2 - tri%c**2) / (2.0*tri%a*tri%b) )\n height = tri%a*SIN(theta); Area = 0.5*tri%b*height\n\n END FUNCTION Area\n\nEND PROGRAM Triangle_Area\n!This ends the program\n\n\n", "meta": {"hexsha": "0a634e5ee1d98227719eab8843f52961e5bfe421", "size": 704, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/triangle.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/triangle.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/triangle.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 19.027027027, "max_line_length": 73, "alphanum_fraction": 0.6321022727, "num_tokens": 227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7762106134965002}} {"text": "! Implemented by Anant Dixit (Nov. 2014)\nprogram circles\nimplicit none\ndouble precision :: P1(2), P2(2), R\n\nP1 = (/0.1234d0, 0.9876d0/)\nP2 = (/0.8765d0,0.2345d0/)\nR = 2.0d0\ncall print_centers(P1,P2,R)\n\nP1 = (/0.0d0, 2.0d0/)\nP2 = (/0.0d0,0.0d0/)\nR = 1.0d0\ncall print_centers(P1,P2,R)\n\nP1 = (/0.1234d0, 0.9876d0/)\nP2 = (/0.1234d0, 0.9876d0/)\nR = 2.0d0\ncall print_centers(P1,P2,R)\n\nP1 = (/0.1234d0, 0.9876d0/)\nP2 = (/0.8765d0, 0.2345d0/)\nR = 0.5d0\ncall print_centers(P1,P2,R)\n\nP1 = (/0.1234d0, 0.9876d0/)\nP2 = (/0.1234d0, 0.9876d0/)\nR = 0.0d0\ncall print_centers(P1,P2,R)\nend program circles\n\nsubroutine print_centers(P1,P2,R)\nimplicit none\ndouble precision :: P1(2), P2(2), R, Center(2,2)\ninteger :: Res\ncall test_inputs(P1,P2,R,Res)\nwrite(*,*)\nwrite(*,'(A10,F7.4,A1,F7.4)') 'Point1 : ', P1(1), ' ', P1(2)\nwrite(*,'(A10,F7.4,A1,F7.4)') 'Point2 : ', P2(1), ' ', P2(2)\nwrite(*,'(A10,F7.4)') 'Radius : ', R\nif(Res.eq.1) then\n write(*,*) 'Same point because P1=P2 and r=0.'\nelseif(Res.eq.2) then\n write(*,*) 'No circles can be drawn because r=0.'\nelseif(Res.eq.3) then\n write(*,*) 'Infinite circles because P1=P2 for non-zero radius.'\nelseif(Res.eq.4) then\n write(*,*) 'No circles with given r can be drawn because points are far apart.'\nelseif(Res.eq.0) then\n call find_center(P1,P2,R,Center)\n if(Center(1,1).eq.Center(2,1) .and. Center(1,2).eq.Center(2,2)) then\n write(*,*) 'Points lie on the diameter. A single circle can be drawn.'\n write(*,'(A10,F7.4,A1,F7.4)') 'Center : ', Center(1,1), ' ', Center(1,2)\n else\n write(*,*) 'Two distinct circles found.'\n write(*,'(A10,F7.4,A1,F7.4)') 'Center1 : ', Center(1,1), ' ', Center(1,2)\n write(*,'(A10,F7.4,A1,F7.4)') 'Center2 : ', Center(2,1), ' ', Center(2,2)\n end if\nelseif(Res.lt.0) then\n write(*,*) 'Incorrect value for r.'\nend if\nwrite(*,*)\nend subroutine print_centers\n\nsubroutine test_inputs(P1,P2,R,Res)\nimplicit none\ndouble precision :: P1(2), P2(2), R, dist\ninteger :: Res\nif(R.lt.0.0d0) then\n Res = -1\n return\nelseif(R.eq.0.0d0 .and. P1(1).eq.P2(1) .and. P1(2).eq.P2(2)) then\n Res = 1\n return\nelseif(R.eq.0.0d0) then\n Res = 2\n return\nelseif(P1(1).eq.P2(1) .and. P1(2).eq.P2(2)) then\n Res = 3\n return\nelse\n dist = sqrt( (P1(1)-P2(1))**2 + (P1(2)-P2(2))**2 )\n if(dist.gt.2.0d0*R) then\n Res = 4\n return\n else\n Res = 0\n return\n end if\nend if\nend subroutine test_inputs\n\nsubroutine find_center(P1,P2,R,Center)\nimplicit none\ndouble precision :: P1(2), P2(2), MP(2), Center(2,2), R, dm\nMP = (P1+P2)/2.0d0\ndm = sqrt( (P1(1)-P2(1))**2 + (P1(2)-P2(2))**2 )\n\nCenter(1,1) = MP(1) + sqrt(R**2 - (dm/2.0d0)**2)*(P2(2)-P1(2))/dm\nCenter(1,2) = MP(2) + sqrt(R**2 - (dm/2.0d0)**2)*(P2(1)-P1(1))/dm\n\nCenter(2,1) = MP(1) - sqrt(R**2 - (dm/2.0d0)**2)*(P2(2)-P1(2))/dm\nCenter(2,2) = MP(2) - sqrt(R**2 - (dm/2.0d0)**2)*(P2(1)-P1(1))/dm\nend subroutine find_center\n", "meta": {"hexsha": "074a02790722e6464f9e2523d454a4670a3a0c92", "size": 2843, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Circles-of-given-radius-through-two-points/Fortran/circles-of-given-radius-through-two-points.f", "max_stars_repo_name": "djgoku/RosettaCodeData", "max_stars_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Circles-of-given-radius-through-two-points/Fortran/circles-of-given-radius-through-two-points.f", "max_issues_repo_name": "djgoku/RosettaCodeData", "max_issues_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Circles-of-given-radius-through-two-points/Fortran/circles-of-given-radius-through-two-points.f", "max_forks_repo_name": "djgoku/RosettaCodeData", "max_forks_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 27.0761904762, "max_line_length": 81, "alphanum_fraction": 0.6085121351, "num_tokens": 1303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680097, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7762106108839164}} {"text": "module SanitizedStatistics\n implicit none\n \n integer,parameter,private :: dp = kind(1.d0) \n \n interface pcor\n procedure :: pcor1D\n procedure :: pcor2D\n end interface\n \n contains\n \n ! Normal distribution via\n ! Marsaglia polar method\n function normal(mean,std) result(x)\n implicit none\n \n real(dp),intent(in) :: mean,std\n real(dp) :: x\n \n real(dp) :: u,v,s\n real(dp) :: r1,r2\n \n logical :: cont\n \n cont = .true.\n do while(cont)\n call random_number(r1)\n call random_number(r2)\n u = r1*2.0 - 1.0\n v = r2*2.0 - 1.0\n s = u*u + v*v\n \n cont = (s .ge. 1.0) .or. (s .le. 0.0)\n end do\n \n s = u*sqrt(-2.0*log(s)/s)\n x = mean + std*s\n end function\n \n ! Welford's online algorithm\n ! xb = \n ! s = var(x)\n subroutine Welford(x,xb,s)\n implicit none\n \n real,intent(in) :: x(:)\n real,intent(out) :: xb\n real,intent(out) :: s\n \n real :: lxb,Delta\n integer :: n\n \n \n xb = 0\n Delta = 0\n do n = 1,size(x)\n lxb = xb\n xb = lxb + (x(n)-lxb)/n\n Delta = Delta + (x(n)-lxb)*(x(n)-xb)\n end do\n s = Delta/(n-1)\n end subroutine\n \n ! Draw random integer between mi and ma\n function randint(mi,ma) result(x)\n implicit none\n \n integer,intent(in) :: mi,ma\n integer :: x\n real :: r\n \n call random_number(r)\n x = mi + floor(r*(ma-mi+1))\n end function \n \n ! Pearson correlation coefficient between\n ! two matrices\n function pcor2D(X,Y) result(r)\n implicit none\n \n real,intent(in) :: X(:,:),Y(:,:)\n real :: r\n \n real :: x_av,y_av\n real :: xx,yy,xy\n integer :: Nx,Ny,N, i,j\n \n Ny = size(X,1)\n Nx = size(X,2)\n N = Nx*Ny\n \n x_av = 0.0\n y_av = 0.0\n do j = 1,Nx\n do i = 1,Ny\n x_av = x_av + x(i,j)\n y_av = y_av + y(i,j)\n end do\n end do\n x_av = x_av/N\n y_av = y_av/N\n \n xy = 0.0\n xx = 0.0\n yy = 0.0\n do j = 1,Nx\n do i = 1,Ny\n xy = xy + x(i,j)*y(i,j)\n xx = xx + x(i,j)*x(i,j)\n yy = yy + y(i,j)*y(i,j)\n end do\n end do\n \n r = (xy - N*x_av*y_av)/sqrt((xx-N*x_av*x_av)*(yy-N*y_av*y_av))\n end function\n \n ! Pearson correlation coefficient between\n ! two vectors\n function pcor1D(x,y) result(r)\n implicit none\n \n real,intent(in) :: x(:),y(:)\n real :: r\n \n real :: x_av,y_av\n real :: xx,yy,xy\n integer :: N, i\n \n N = size(x,1)\n \n x_av = 0.0\n y_av = 0.0\n do i = 1,N\n x_av = x_av + x(i)\n y_av = y_av + y(i)\n end do\n x_av = x_av/N\n y_av = y_av/N\n \n xy = 0.0\n xx = 0.0\n yy = 0.0\n do i = 1,N\n xy = xy + x(i)*y(i)\n xx = xx + x(i)*x(i)\n yy = yy + y(i)*y(i)\n end do\n \n r = (xy - N*x_av*y_av)/sqrt((xx-N*x_av*x_av)*(yy-N*y_av*y_av))\n end function\n \nend module\n", "meta": {"hexsha": "f894e4d042915975d1326dc2888e48b491684cfb", "size": 3606, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/stat.f90", "max_stars_repo_name": "StxGuy/SanitizedStatistics", "max_stars_repo_head_hexsha": "510c046747ffda142ad97f4af940c2ea17ff695a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/stat.f90", "max_issues_repo_name": "StxGuy/SanitizedStatistics", "max_issues_repo_head_hexsha": "510c046747ffda142ad97f4af940c2ea17ff695a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/stat.f90", "max_forks_repo_name": "StxGuy/SanitizedStatistics", "max_forks_repo_head_hexsha": "510c046747ffda142ad97f4af940c2ea17ff695a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.4155844156, "max_line_length": 70, "alphanum_fraction": 0.3874098724, "num_tokens": 1036, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314624993576759, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7762106045420379}} {"text": "SUBROUTINE vecuni(n,v,modul)\r\n!*****************************************************************************\r\n! This routine compute de length of the vector v and converts it to a unit one\r\n!*****************************************************************************\r\nIMPLICIT NONE\r\n\r\n !--- Dummy variables\r\n INTEGER(kind=4),INTENT(IN):: n !Vector dimension\r\n REAL(kind=8),INTENT(INOUT):: v(n) !Vector\r\n REAL(kind=8),INTENT(OUT):: modul !Module of input vector\r\n\r\n modul = SQRT(DOT_PRODUCT(v(1:n),v(1:n)))\r\n IF (modul > 0d0) v(1:n)=v(1:n)/modul\r\n\r\nRETURN\r\nEND SUBROUTINE vecuni\r\n", "meta": {"hexsha": "733fa820a989e587be956dfa70042ec385b77206", "size": 594, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/auxil/vecuni.f90", "max_stars_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_stars_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/auxil/vecuni.f90", "max_issues_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_issues_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/auxil/vecuni.f90", "max_forks_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_forks_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.9411764706, "max_line_length": 79, "alphanum_fraction": 0.4848484848, "num_tokens": 151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8688267745399465, "lm_q1q2_score": 0.7761311249927794}} {"text": "\n\nprogram main\n\n use ISO_FORTRAN_ENV\n\n integer (int64) :: primec, i\n\n i = 1\n primec = 0\n\n do\n if(isprime(i)) then\n primec = primec + 1\n endif\n\n if(primec == 10001) then\n exit\n endif\n\n i = i + 1\n\n end do\n\n print*, i\n\n\ncontains\n \n function isprime (s)\n logical :: isprime\n integer (kind=8) :: s, i, top\n\n isprime = .false. \n\n if(s <= 1) then\n return\n end if\n\n top = int(sqrt(real(s))) + 1\n\n do i = 2, top + 1, 1\n\n if (i == top) then\n isprime = .true.\n exit\n end if\n\n if(mod(s, i) == 0) then\n exit\n end if\n\n end do\n\n return\n\n end function isprime\n\n\nend program main\n\n", "meta": {"hexsha": "4c6dcc2fcc5b4c558bd5185110ea2bb4abc31d48", "size": 1099, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/10001st_prime.f95", "max_stars_repo_name": "guynan/project_euler", "max_stars_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-03-08T09:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T13:52:49.000Z", "max_issues_repo_path": "fortran/10001st_prime.f95", "max_issues_repo_name": "guynan/project_euler", "max_issues_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-11-03T01:20:46.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-24T22:54:59.000Z", "max_forks_repo_path": "fortran/10001st_prime.f95", "max_forks_repo_name": "guynan/project_euler", "max_forks_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-11-03T01:14:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T13:52:51.000Z", "avg_line_length": 17.7258064516, "max_line_length": 48, "alphanum_fraction": 0.3057324841, "num_tokens": 235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.82893881677331, "lm_q1q2_score": 0.7761229804061329}} {"text": "module quad_glegq\n \n ! precision specification\n use preci, wp => dp\n\n ! external functions and subroutines\n use funcs\n\n implicit none\n\n\n ! used for sharing between QUAD and GLEGQ\n real (wp) :: X,Y,C,VAR,NVAR\n\ncontains\n\n function QUAD(GLEGQ,N,FX,A,B)\n!*******************************************************************\n! THE DOUBLE PRECISION function SUBPROGRAM APPROXIMATES THE VALUE OF\n! AN INTEGRAL I(FX,A,B) OF A function FX(X) OVER THE INTERVAL (A,B) \n! USING A QUADRATURE RULE WHICH IS SPECIFIED BY THE PARAMETERS METHOD\n! AND N.\n!\n!\n! CALLING SEQUENCE: APPROX= QUAD(METHOD,N,FX,A,B)\n!\n!\n! PARAMETRS:\n! ON ENTRY:\n! METHOD-DOUBLE PRECISION subroutine METHOD(N,A,B,P,W)\n! USED TO SPECIFY THE TYPE OF QUADRATURE RULE TO BE\n! USED AND TO OBTAIN THE APPROPRIATE POINTS AND WEIGHTS \n! =NCQ- NEWTON-COTES RULES,\n! GLFGQ-GAUSS-LEGENDRE RULES,\n! GLAGQ-GAUSS-LAGUERRE RULES.E\n! N - INTEGER \n! THE NUMBER OF QUADRATURE POINTS TO BE USED. LIMITS \n! ON N WHEN METHOD= NCQ : 1 <= N <= 21,\n! GLEGQ: 2 <=N <=20,\n! GLAG : 2<= N <=10,\n! FX - DOUBLE PRECISION function FX(X) \n! USED FOR EVALUATING THE INTEGRAND.\n! A,B- REAL*8\n! THE LEFT AND RIGHT ENDPOINTS OF THE INTERVAL OF\n! INTEGRATION.\n! \n! ON RETURN:\n! QUAD - REAL*8\n! THE APPROXIMATE VALUE OF I(FX,A,B).\n! SAMPLE CALLING PROGRAM:\n! C********** THIS PROGRAM APPROXIMATES THE VALUE OF I(FX,A,B) USING A\n! C COMPOSITE 5-POINT GAUSS-LEGENDRE RULE. THE NUMBER OF \n! C SUBDIVISIONS OF (A,B) IS MDIV.\n! IMPLICIT REAL*8 (A-H,O-Z)\n! EXTERNAL FX,GLEGO\n! READ (5,*) A,B,MDIV\n! H=(B-A)/MDIV\n! XL=A\n! XR=A+H\n! APPROX=0.DO\n! do IDIV=1,MDIV\n! APPROX=APPROX+QUAD(GLEGQ,5,FX,XL,XR)\n! XL=XR \n! XR=XR +H\n! 10 CONTINUE \n! \n! write(6,*) 'APPROX. VALUE OF THE INTEGRAL=',APPROX\n! stop\n! end\n!\n! function FX(X)\n! IMPLICIT REAL*8 (A-H,O-Z)\n! FX = .... FORMULA TO EVALUATE THE INTEGRAND...\n! return\n! end\n! \n! REFERENCE : ELEMENTARY NUMERICAL ANALYSIS\n! BY CONTE AND DEBOOR\n! PAGE 299-306\n!*******************************************************************\n real (wp) :: A, B, D, DT2, FX, SU\n integer :: N, ND2, NJ, NSTART, NSTJ\n real (wp), dimension(20) :: P,W\n real (wp) :: QUAD\n external FX,GLEGQ\n\n ! local variable for indexing \n integer :: iq ! appended with \"q\", which is the first letter of QUAD\n!\n!\n! **********************************************************\n! *\n! * RETRIEVE POINT AND WEIGHTS, TRANSFORMED INTO THE SPECIFIED \n! * INTEPVAL (A,B), FROM THE subroutine METHOD, AND APPLY THE\n! * QUADRATURE FORMULA.\n! *\n! * \n! **********************************************************\n!\n call GLEGQ (N, A, B, P, W)\n SU = 0.D0\n do iq=1,N\n SU = SU + W(iq) * FX(P(iq))\n end do\n QUAD=SU\n return\n end function QUAD\n \n\n!**************************************************************************\n\n\n subroutine GLEGQ( N, A, B, P, W)\n!**************************************************************************\n! THIS DOUBLE PRECISION subroutine IS DESIGNED TO BE USED BY EITHER OF \n! THE ROUTINES QUAD OR ADQUAD FOR APPROXIMATING THE VALUE OF THE \n! DEFINITE INTEGRAL I(FX,A,B) OF FX(X) OVER THE INTERVAL (A,B) USING AN\n! N-POINT GAUSS-LEGENDRE FORMULA.\n! \n! THE PURPOSE OF GLEGQ IS TO SUPPLY, TO QUAD OR ADQUAD, THE N QUADRA-\n! TURE POINTS AND CORRESPONDING WEIGHTS FOR THE SPECIFIED N-POINT\n! FORMULA FOR THE GIVEN INTERVAL OF INTEGRATION. THIS IS DONE BY\n! TAKING THE POINTS AND WEIGHTS FOR THE \"NORMALIZED\" INTERVAL (-1,1)\n! AND TRANSFORMING THEM TO (A,B).\n!\n! THIS ROUTINE CAN ALSO BE USED BY THE ROUTINE QUADM TO GENERATE\n! ROUTINE GAUSS-LEGENDRE RULES FOR APPROXIMATING INTEGRALS IN M DIMEN-\n! SIONS, M=2, 3.\n!\n!\n! CALLING SEQUENCE: call GLEGQ(N,A,B,P,W)\n!\n! PARAMETERS:\n! ON ENTRY:\n! N -INTEGER\n! THE NUMBER OF QUADRATURE POINTS TO BE USED. 2<=N<=20\n! A, B -REAL*8\n! THE LEFT AND RIGHT ENDPOINTS OF THE INTERVAL OF\n! INTEGRATION.\n!\n! ON RETURN:\n! P -REAL*8(N)\n! THE POINTS FOR THE N-POINT GUASS-LEGENDRE QUADRATURE\n! RULE ON THE INTERVAL (A,B).\n! W -REAL*8(N)\n! THE WEIGHTS FOR THE N-POINT GAUSS-LEGENDRE QUADRATURE\n! RULE ON THE INTERVAL (A,B).\n!\n!\n! SAMPLE CALLING PROGRAM:\n! IMPLICIT REAL*8 (A-H,O-Z)\n! EXTERNAL FX,GLEGQ\n! read(5,*) A,B,N\n! APPROX=QUAD(GLEGQ,FX,N,A,B)\n! write(6,*) 'THE',N,'-POINT GAUSS-LEGENDRE QUADRATURE APPROX.='\n! + ,APPROX\n! stop\n! end\n!\n! function FX(X)\n! IMPLICIT REAL*8 (A-H,O-Z)\n! FX=... FORMULA TO EVALUATE THE INTEGRAND...\n! return\n! end\n!**************************************************************************\n real (wp) :: A, B, D, DT2\n integer :: N, ND2, NJ, NSTART, NSTJ\n real (wp), dimension(100) :: PT, WT\n real (wp), dimension(9) :: WZ\n real (wp), dimension(N) :: P, W\n\n ! local variable for indexing \n integer :: jg ! appended with \"g\", which is the first letter of GLEGQ\n\n! *******************\n! *\n! * THE VECTOR PT CONTAINS THE LOCATION OF THE NEGATIVE POINTS IN \n! * (-1,1) USED IN THE FORMULA. if N IS EVEN, THE ONLY OTHER POINTS\n! * ARE POSITIVE MIRROR IMAGES OF THE NEGATIVES. FOR N ODD, THERE IS AN\n! * ADDITIONAL POINT AT THE ORIGIN.\n! *\n! *******************\n\n DATA PT( 1),PT( 2),PT( 3),PT( 4),PT( 5),PT( 6),PT( 7),PT( 8), &\n PT( 9),PT( 10)/-5.773502691896259D-01,-7.745966692414834D-01, &\n -8.611363115940526D-01,-3.399810435848563D-01, &\n -9.061798459386640D-01,-5.384693101056832D-01, &\n -9.324695142031520D-01,-6.612093864662646D-01, &\n -2.386191860831969D-01,-9.491079123427586D-01/\n DATA PT(11),PT(12),PT(13),PT(14),PT(15),PT(16),PT(17),PT(18), &\n PT(19),PT( 20)/-7.415311855993942D-01,-4.058451513773972D-01, &\n -9.602898564975362D-01,-7.966664774136267D-01, &\n -5.255324099163290D-01,-1.834346424956498D-01, &\n -9.681602395076261D-01,-8.360311073266358D-01, &\n -6.133714327005905D-01,-3.242534234038089D-01/\n DATA PT(21),PT(22),PT(23),PT(24),PT(25),PT(26),PT(27),PT(28), &\n PT(29),PT( 30)/-9.739065285171717D-01,-8.650633666889845D-01, &\n -6.794095682990245D-01,-4.333953941292472D-01, &\n -1.488743389816312D-01,-9.782286581460570D-01, &\n -8.870625997680954D-01,-7.301520055740493D-01, &\n -5.190961292068119D-01,-2.695431559523450D-01/\n DATA PT(31),PT(32),PT(33),PT(34),PT(35),PT(36),PT(37),PT(38), &\n PT(39),PT( 40)/-9.815606342467190D-01,-9.041172563704749D-01, &\n -7.699026741943046D-01,-5.873179542866175D-01, &\n -3.678314989981802D-01,-1.252334085114689D-01, &\n -9.841830547185882D-01,-9.175983992229781D-01, &\n -8.015780907333099D-01,-6.423493394403403D-01/\n DATA PT(41),PT(42),PT(43),PT(44),PT(45),PT(46),PT(47),PT(48), &\n PT(49),PT( 50)/-4.484927510364468D-01,-2.304583159551348D-01, &\n -9.862838086968123D-01,-9.284348836635734D-01, &\n -8.272013150697650D-01,-6.872929048116856D-01, &\n -5.152486363581541D-01,-3.191123689278898D-01, &\n -1.080549487073437D-01,-9.879925180204854D-01/\n DATA PT(51),PT(52),PT(53),PT(54),PT(55),PT(56),PT(57),PT(58), &\n PT(59),PT( 60)/-9.372733924007058D-01,-8.482065834104270D-01, &\n -7.244177313601699D-01,-5.709721726085388D-01, &\n -3.941513470775634D-01,-2.011940939974345D-01, &\n -9.894009349916499D-01,-9.445750230732326D-01, &\n -8.656312023878317D-01,-7.554044083550030D-01/\n DATA PT(61),PT(62),PT(63),PT(64),PT(65),PT(66),PT(67),PT(68), &\n PT(69),PT( 70)/-6.178762444026438D-01,-4.580167776572274D-01, &\n -2.816035507792589D-01,-9.501250983763744D-02, &\n -9.905754753144173D-01,-9.506755217687678D-01, &\n -8.802391537269859D-01,-7.815140038968014D-01, &\n -6.576711592166909D-01,-5.126905370864771D-01/\n DATA PT(71),PT(72),PT(73),PT(74),PT(75),PT(76),PT(77),PT(78), &\n PT(79),PT( 80)/-3.512317634538763D-01,-1.784841814958478D-01, &\n -9.915651684209309D-01,-9.558239495713978D-01, &\n -8.926024664975557D-01,-8.037049589725230D-01, &\n -6.916870430603533D-01,-5.597708310739476D-01, &\n -4.11751161462826D-01,-2.518862256915055D-01/\n DATA PT(81),PT(82),PT(83),PT(84),PT(85),PT(86),PT(87),PT(88), &\n PT(89),PT(90)/-8.477501304173527D-02,-9.924068438435845D-01, &\n -9.602081521348301D-01,-9.031559036148179D-01, &\n -8.227146565371427D-01,-7.209661773352294D-01, &\n -6.005453046616811D-01,-4.645707413759609D-01, &\n -3.165640999636298D-01,-1.603586456402254D-01/\n DATA PT(91),PT(92),PT(93),PT(94),PT(95),PT(96),PT(97),PT(98), &\n PT(99),PT(100)/-9.931285991850949D-01,-9.639719272779138D-01, &\n -9.122344282513259D-01,-8.391169718222189D-01, &\n -7.463319064601507D-01,-6.360536807265151D-01, &\n -5.108670019508271D-01,-3.737060887154196D-01, &\n -2.277858511416451D-01,-7.652652113349732D-02/\n!\n! ***************\n! *\n! * WT CONTAINS THE WEIGHTS FOR THE VALUES IN PT; THE SAME WEIGHTS ARE\n! * ALSO USED FOR THE 'MIRROR IMAGE' POINTS.\n! *\n! ***************\n!\n DATA WT(1),WT(2),WT(3),WT(4),WT(5),WT(6),WT(7),WT(8), &\n WT(9),WT(10)/ 1.000000000000000D00,5.555555555555557D-01, &\n & 3.478548451374538D-01,6.521451548625462D-01, &\n & 2.369268850561891D-01,4.786286704993665D-01, &\n & 1.713244923791703D-01,3.607615730481386D-01, &\n & 4.679139345726910D-01,1.294849661688697D-01/\n DATA WT(11),WT(12),WT(13),WT(14),WT(15),WT(16),WT(17),WT(18), &\n WT(19),WT(20)/ 2.797053914892767D-01,3.8183005050501189D-01, &\n & 1.012285362903762D-01,2.223810344533745D-01, &\n & 3.137066458778873D-01,3.626837833783620D-01, &\n & 8.127438836157441D-02,1.806481606948574D-01, &\n & 2.606106964029355D-01,3.123470770400028D-01/\n DATA WT(21),WT(22),WT(23),WT(24),WT(25),WT(26),WT(27),WT(28), &\n WT(29),WT(30)/ 6.667134430868812D-02, 1.494513491505806D-01, &\n & 2.190863625159820D-01,2.692667193099964D-01, &\n & 2.955242247147529D-01,5.566856711617367D-02, &\n & 1.255803694649046D-01,1.862902109277342D-01, &\n & 2.331937645919905D-01,2.628045445102467D-01/\n DATA WT(31),WT(32),WT(33),WT(34),WT(35),WT(36),WT(37),WT(38), &\n WT(39),WT(40)/ 4.717533638751183D-02,1.069393259953184D-01, &\n & 1.600783285433462D-02,2.031674267230659D-01, &\n & 2.334925365383548D-01,2.491470458134028D-01, &\n & 4.048400476531588D-02,9.212149983772845D-02, &\n & 1.388735102197872D-02,1.781459807619457D-01/\n DATA WT(41),WT(42),WT(43),WT(44),WT(45),WT(46),WT(47),WT(48), &\n WT(49),WT(50)/ 2.078160475368885D-01,2.262831802628972D-01, &\n & 3.511946033175186D-02,8.015808715976020D-02, &\n & 1.215185706879032D-02,1.572031671581935D-01, &\n & 1.855383974779378D-01,2.051984637212956D-01, &\n & 2.152638534631578D-01,3.075324199611727D-02/\n DATA WT(51),WT(52),WT(53),WT(54),WT(55),WT(56),WT(57),WT(58), &\n WT(59),WT(60)/ 7.036604748810809D-02,1.071592204671719D-01, &\n & 1.395706779261543D-01,1.662692058169939D-01, &\n & 1.861610000155622D-01,1.984314853271116D-01, &\n & 2.715245941175409D-02,6.225352393864789D-02, &\n & 9.515851168249277D-02,1.246289712555339D-01/\n DATA WT(61),WT(62),WT(63),WT(64),WT(65),WT(66),WT(67),WT(68), &\n WT(69),WT(70)/ 1.495959888165767D-01, 1.691565193950025D-01, &\n & 1.826034150449236D-01, 1.894506104550685D-01, &\n & 2.414830286854793D-02, 5.545952937398720D-02, &\n & 8.503614831717917D-02, 1.118838471934040D-01, &\n & 1.351363684685255D-01, 1.540457610768103D-01/\n DATA WT(71),WT(72),WT(73),WT(74),WT(75),WT(76),WT(77),WT(78), &\n WT(79),WT(80)/ 1.680041021564500D-01, 1.765627053669926D-01, &\n & 2.161601352648331D-02, 4.971454889496981D-02, &\n & 7.642573025488905D-02, 1.009420441062872D-01, &\n & 1.225552067114785D-01, 1.406429146706506D-01, &\n & 1.546846751262652D-01, 1.642764837458327D-01/\n DATA WT(81),WT(82),WT(83),WT(84),WT(85),WT(86),WT(87),WT(88), &\n WT(89),WT(90)/ 1.691423829631436D-01, 1.946178822972648D-02, &\n & 4.481422676569960D-02, 6.904454273764122D-02, &\n & 9.149002162244999D-02, 1.115666455473340D-01, &\n & 1.287539625393362D-01, 1.426067021736066D-01, &\n & 1.527660420658597D-01, 1.589688433939543D-01/\n DATA WT(91),WT(92),WT(93),WT(94),WT(95),WT(96),WT(97),WT(98), &\n WT(99),WT(100)/ 1.761400713915212D-02, 4.060142980038694D-02, &\n & 6.267204833410905D-02, 8.327674157670474D-02, &\n & 1.019301198172404D-01, 1.181945319615184D-01, &\n & 1.316886384491766D-01, 1.420961093183820D-01, &\n & 1.491729864726037D-01, 1.527533871307258D-01/\n!\n! ***************\n! *\n! * WZ CONTAINS ALL THE WEIGHTS FOR THE ORIGIN.\n! *\n! ***************\n!\n DATA WZ/ 8.888888888888890D-01, 5.688888888888889D-01, &\n & 4.179591836734694D-01, 3.302393550012598D-01, &\n & 2.729250867779006D-01, 2.325515532308739D-01, &\n & 2.025782419255613D-01, 1.794464703562065D-01, &\n & 1.610544498487837D-01/\n!\n!\n! ***************\n! *\n! * NSTART INDICATES WHERE THE DESIRED POINTS AND WEIGHTS ARE LOCATED\n! * RETRIEVE THE POINTS AND WEIGHES. TRANSFORM THE POINTS TO (A,B).\n! *\n! ***************\n!\n NSTART = ((N/2)*((N-1)/2))\n ND2 = N/2\n C = (B - A)/2.0D0\n D = (B + A)/2.0D0\n DT2 = D*2\n do jg=1,ND2\n NJ = N-jg+1\n NSTJ = NSTART + jg\n P(jg) = PT(NSTJ)*C +D\n P(NJ) = -P(jg) + DT2\n W(jg) = WT(NSTJ)*C\n W(NJ) = W(jg)\n end do\n if ((ND2)*2 /= N) then\n P(ND2 + 1) = D\n W(ND2 + 1) = WZ(ND2)*C\n end if\n return\n end subroutine glegq\n\n\nend module quad_glegq\n", "meta": {"hexsha": "62a6dafbe8665feba3371d472ff67fddecacd217", "size": 14243, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/quad_glegq.f90", "max_stars_repo_name": "b1tank/DSM-f90", "max_stars_repo_head_hexsha": "5cab8c8e89d316828f41fc27fc9d603f6973f1bc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-06-26T18:36:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-06T00:35:49.000Z", "max_issues_repo_path": "src/quad_glegq.f90", "max_issues_repo_name": "b1tank/DSM-f90", "max_issues_repo_head_hexsha": "5cab8c8e89d316828f41fc27fc9d603f6973f1bc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-03-17T01:01:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-17T13:20:10.000Z", "max_forks_repo_path": "src/quad_glegq.f90", "max_forks_repo_name": "b1tank/DSM-f90", "max_forks_repo_head_hexsha": "5cab8c8e89d316828f41fc27fc9d603f6973f1bc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-08-08T14:45:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-22T01:07:42.000Z", "avg_line_length": 40.1211267606, "max_line_length": 78, "alphanum_fraction": 0.5784595942, "num_tokens": 5689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850128595114, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.7761229748955824}} {"text": "subroutine mbmatb(a,b,c,n1,n2,n3)\n\n!-----------------------------------------------------------------------\n!\n! This routine evaluates the matrix product A = Bt C, where\n! A -> Mat(n1,n2), B -> Mat(n3,n1), C -> Mat(n3,n2)\n!\n!-----------------------------------------------------------------------\n use typre\n implicit none\n integer(ip) :: n1,n2,n3,i,j,k\n real(rp) :: a(n1,n2), b(n3,n1), c(n3,n2) \n\n do i=1,n1\n do j=1,n2\n a(i,j)=0.0_rp\n do k=1,n3\n a(i,j)=a(i,j)+b(k,i)*c(k,j)\n end do\n end do\n end do\n\nend subroutine mbmatb\n\n", "meta": {"hexsha": "8a22b72ebe5359dea39f8caa97247356a2de7f2b", "size": 579, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/mathru/mbmatb.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/mathru/mbmatb.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/mathru/mbmatb.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.16, "max_line_length": 72, "alphanum_fraction": 0.3886010363, "num_tokens": 182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.8438951104066295, "lm_q1q2_score": 0.7760818353829158}} {"text": "c *********************************************************************\nc * *\nc * F U N C T I O N D A Y H O U R S *\nc * de 11/07/17 *\nc *********************************************************************\nc This function uses latitude, zenith angle, declination of the sun and\nc month, day and year to calculate the daylength for a day. The code was\nc was provided by Simon van Donk and the reference he used is found in\nc Keisling, T.C., 1982. Calculation of the length of day. Agron. J. \nc 74:758-759. \n\n! INPUTS: list variables here with C and R for each variable \n\n! OUTPUTS: list variables here with C and R for each variable\n \n \n FUNCTION dayhours(latitude, day, month, year)\n IMPLICIT NONE\n \n! Variable declarations\n REAL :: dayhours, latitude\n INTEGER :: year\n \n! Local variables\n REAL :: declin, degtorad, julday, lambda, sunanom, sunbelow \n REAL :: zenith\n REAL :: day, month \n \n!Initialize local variables \n declin = 0.0\n lambda = 0.0\n sunanom = 0.0\n sunbelow = 0.0\n zenith = 0.0\n julday = 0.0\n \n! end of declarations\n \n ! + + + purpose + + +\n ! This function calculates the length of the day, in hours, for a given day\n \n ! + + + argument definitions + + +\n ! many of these definitions came from the Keisling reference given above.\n ! day - the day of the year for which daylength is being calculated (1-31)\n ! dayhours - the hours of daylight calculated herein and returned from this function\n ! latitude - latitude of the site, degrees (north > 0, south < 0), in degrees\n ! mon - the month of the year (1-12)\n ! year - the year\n \n ! + + + local variable definitions + + +\n ! declin - the declination of the sun in degrees\n ! degtorad - parameter to convert values in degrees to radians. It is equal to pi/180\n ! lambda - ???\n ! sunanom - mean anomaly of the sun in degrees. This is M in Keisling ref.\n ! sunbelow - the angle of the sun below the horizon. This is variable B in Keisling ref.\n ! zenith - the zenithal distance of the sun at the event of interest in degrees\n\n ! calculate the Julian day\n julday = Day-32 + (Int(275*(Month/9))) + (2*Int(3/(Month+1))) + \n c (Int((Month/100)-(Mod(Year,4)/4)+0.975)) \n\n! Calculate M use variable sunanom for M \n sunanom = 0.985600 * julday - 3.251\n \n! Calculate the lambda value\n lambda = sunanom + 1.916 * sind(sunanom) + 0.020 *\n c sind(2*sunanom) + 282.565\n\n! Calculate the declination of the sun (degrees) \n declin = asind(0.39779 * sind(lambda))\n \n! Calculate zenith angle (degrees) sunbelow is used for B\n zenith = 90 - sunbelow\n \n! Calculate the daylength \n dayhours = (2.0/15.0) * acosd((cosd(zenith))*(1/(cosd(latitude)))*\n c (1/(cosd(declin)))- ((tand(latitude))*(tand(declin))))\n \n END FUNCTION dayhours\n \n \n \n \n ", "meta": {"hexsha": "7a1c5fef3b3fce1e6c387512469723b358fd28b6", "size": 3240, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "PhenologyMMS/dayhours.for", "max_stars_repo_name": "USDA-ARS-WMSRU/phenologymms-science", "max_stars_repo_head_hexsha": "e753a303f47ac6602d492d02399343dfe670b696", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "PhenologyMMS/dayhours.for", "max_issues_repo_name": "USDA-ARS-WMSRU/phenologymms-science", "max_issues_repo_head_hexsha": "e753a303f47ac6602d492d02399343dfe670b696", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PhenologyMMS/dayhours.for", "max_forks_repo_name": "USDA-ARS-WMSRU/phenologymms-science", "max_forks_repo_head_hexsha": "e753a303f47ac6602d492d02399343dfe670b696", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.5714285714, "max_line_length": 94, "alphanum_fraction": 0.5388888889, "num_tokens": 837, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611586300241, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7760363610195056}} {"text": "module dtwodq_mod\n \n use preci, wp => dp\n implicit none\n\ncontains\n\n subroutine DTWODQ(F,AA,BB,G,H,TOL,ERE,IR_0,RESULT,ERROR)\n \n!***BEGIN PROLOGUE TWODQ\n!***DATE WRITTEN 840518 (YYMMDD)\n!***REVISION DATE 840518 (YYMMDD)\n!***CATEGORY NO. D1I\n!***KEYWORDS QUADRATURE,TWO DIMENSIONAL,ADAPTIVE,CUBATURE\n!***AUTHOR KAHANER,D.K.,N.B.S.\n! RECHARD,O.W.,N.B.S.\n! BARNHILL,ROBERT,UNIV. OF UTAH\n!***PURPOSE To compute the two-dimensional integral of a function\n! F over a region consisting of N triangles.\n!***DESCRIPTION\n\n! This subroutine computes the two-dimensional integral of a\n! function F over a region consisting of N triangles.\n! A total error estimate is obtained and compared with a\n! tolerance - TOL - that is provided as input to the subroutine.\n! The error tolerance is treated as either relative or absolute\n! depending on the input value of IFLAG. A 'Local Quadrature\n! Module' is applied to each input triangle and estimates of the\n! total integral and the total error are computed. The local\n! quadrature module is either subroutine LQM0 or subroutine\n! LQM1 and the choice between them is determined by the\n! value of the input variable ICLOSE.\n\n! If the total error estimate exceeds the tolerance, the triangle\n! with the largest absolute error is divided into two triangles\n! by a median to its longest side. The local quadrature module\n! is then applied to each of the subtriangles to obtain new\n! estimates of the integral and the error. This process is\n! repeated until either (1) the error tolerance is satisfied,\n! (2) the number of triangles generated exceeds the input\n! parameter MAXTRI, (3) the number of integrand evaluations\n! exceeds the input parameter MEVALS, or (4) the subroutine\n! senses that roundoff error is beginning to contaminate\n! the result.\n\n! The user must specify MAXTRI, the maximum number of triangles\n! in the final triangulation of the region, and provide two\n! storage arrays - DATA and IWORK - whose sizes are at least\n! 9*MAXTRI and 2*MAXTRI respectively. The user must also\n! specify MEVALS, the maximum number of function evaluations\n! to be allowed. This number will be effective in limiting\n! the computation only if it is less than 94*MAXTRI when LQM1\n! is specified or 56*MAXTRI when LQM0 is specified.\n\n! After the subroutine has returned to the calling program\n! with output values, it can be called again with a smaller\n! value of TOL and/or a different value of MEVALS. The tolerance\n! can also be changed from relative to absolute\n! or vice-versa by changing IFLAG. Unless\n! the parameters NU and ND are reset to zero the subroutine\n! will restart with the final set of triangles and output\n! values from the previous call.\n\n! ARGUMENTS:\n\n! F function subprogram defining the integrand F(u,v);\n! the actual name for F needs to be declared EXTERNAL\n! by the calling program.\n\n! N the number of input triangles.\n\n! X a 3 by N array containing the abscissae of the vertices\n! of the N triangles.\n\n! Y a 3 by N array containing the ordinates of the vertices\n! of the N triangles\n\n! TOL the desired bound on the error. If IFLAG=0 on input,\n! TOL is interpreted as a bound on the relative error;\n! if IFLAG=1, the bound is on the absolute error.\n\n! ICLOSE an integer parameter that determines the selection\n! of LQM0 or LQM1. If ICLOSE=1 then LQM1 is used.\n! Any other value of ICLOSE causes LQM0 to be used.\n! LQM0 uses function values only at interior points of\n! the triangle. LQM1 is usually more accurate than LQM0\n! but involves evaluating the integrand at more points\n! including some on the boundary of the triangle. It\n! will usually be better to use LQM1 unless the integrand\n! has singularities on the boundary of the triangle.\n\n! MAXTRI The maximum number of triangles that are allowed\n! to be generated by the computation.\n\n! MEVALS The maximum number of function evaluations allowed.\n\n! RESULT output of the estimate of the integral.\n\n! ERROR output of the estimate of the absolute value of the\n! total error.\n\n! NU an integer variable used for both input and output. Must\n! be set to 0 on first call of the subroutine. Subsequent\n! calls to restart the subroutine should use the previous\n! output value.\n\n! ND an integer variable used for both input and output. Must\n! be set to 0 on first call of the subroutine. Subsequent\n! calls to restart the subroutine should use the previous\n! output value.\n\n! NEVALS The actual number of function evaluations performed.\n\n! IFLAG on input:\n! IFLAG=0 means TOL is a bound on the relative error;\n! IFLAG=1 means TOL is a bound on the absolute error;\n! any other input value for IFLAG causes the subroutine\n! to return immediately with IFLAG set equal to 9.\n\n! on output:\n! IFLAG=0 means normal termination;\n! IFLAG=1 means termination for lack of space to divide\n! another triangle;\n! IFLAG=2 means termination because of roundoff noise\n! IFLAG=3 means termination with relative error <=\n! 5.0* machine epsilon;\n! IFLAG=4 means termination because the number of function\n! evaluations has exceeded MEVALS.\n! IFLAG=9 means termination because of error in input flag\n\n! DATA a one dimensional array of length >= 9*MAXTRI\n! passed to the subroutine by the calling program. It is\n! used by the subroutine to store information\n! about triangles used in the quadrature.\n\n! IWORK a one dimensional integer array of length >= 2*MAXTRI\n! passed to the subroutine by the calling program.\n! It is used by the subroutine to store pointers\n! to the information in the DATA array.\n\n\n! The information for each triangle is contained in a nine word\n! record consisting of the error estimate, the estimate of the\n! integral, the coordinates of the three vertices, and the area.\n! These records are stored in the DATA array\n! that is passed to the subroutine. The storage is organized\n! into two heaps of length NU and ND respectively. The first heap\n! contains those triangles for which the error exceeds\n! epsabs*a/ATOT where epsabs is a bound on the absolute error\n! derived from the input tolerance (which may refer to relative\n! or absolute error), a is the area of the triangle, and ATOT\n! is the total area of all triangles. The second heap contains\n! those triangles for which the error is less than or equal to\n! epsabs*a/ATOT. At the top of each heap is the triangle with\n! the largest absolute error.\n\n! Pointers into the heaps are contained in the array IWORK.\n! Pointers to the first heap are contained\n! between IWORK(1) and IWORK(NU). Pointers to the second\n! heap are contained between IWORK(MAXTRI+1) and\n! IWORK(MAXTRI+ND). The user thus has access to the records\n! stored in the DATA array through the pointers in IWORK.\n! For example, the following two do loops will print out\n! the records for each triangle in the two heaps:\n\n! do 10 I=1,NU\n! PRINT*,(DATA(IWORK(I)+J),J=0,8)\n! 10 continue\n! do 20 I=1,ND\n! PRINT*,(DATA(IWORK(MAXTRI+I)+J),J=0,8\n! 20 continue\n\n! When the total number of triangles is equal to\n! MAXTRI, the program attempts to remove a triangle from the\n! bottom of the second heap and continue. If the second heap\n! is empty, the program returns with the current estimates of\n! the integral and the error and with IFLAG set equal to 1.\n! Note that in this case the actual number of triangles\n! processed may exceed MAXTRI and the triangles stored in\n! the DATA array may not constitute a complete triangulation\n! of the region.\n\n! The following sample program will calculate the integral of\n! cos(x+y) over the square (0.,0.),(1.,0.),(1.,1.),(0.,1.) and\n! print out the values of the estimated integral, the estimated\n! error, the number of function evaluations, and IFLAG.\n\n! real (wp) X(3,2),Y(3,2),DATA(450),RES,ERR\n! integer IWORK(100),NU,ND,NEVALS,IFLAG\n! EXTERNAL F\n! X(1,1)=0.\n! Y(1,1)=0.\n! X(2,1)=1.\n! Y(2,1)=0.\n! X(3,1)=1.\n! Y(3,1)=1.\n! X(1,2)=0.\n! Y(1,2)=0.\n! X(2,2)=1.\n! Y(2,2)=1.\n! X(3,2)=0.\n! Y(3,2)=1.\n! NU=0\n! ND=0\n! IFLAG=1\n! CALL TWODQ(F,2,X,Y,1.E-04,1,50,4000,RES,ERR,NU,ND,\n! * NEVALS,IFLAG,DATA,IWORK)\n! PRINT*,RES,ERR,NEVALS,IFLAG\n! END\n! FUNCTION F(X,Y)\n! F=COS(X+Y)\n! return \n! END\n\n!***REFERENCES (NONE)\n\n!***OUTINES CALLED HINITD,HINITU,HPACC,HPDEL,HPINS,LQM0,LQM1,\n! TRIDV,R1MACH\n!***END PROLOGUE TWODQ\n\n implicit none\n\n integer :: n,iflag,nevals,iclose,nu,nd,mevals,maxtri\n integer, dimension(200) :: iwork\n real (wp) :: F,tol,result,error\n real (wp), dimension(3,2) :: x,y\n real (wp), dimension(900) :: data\n real (wp) :: AA,BB,G,H,ERE\n integer :: IR_0\n integer :: rndcnt\n logical :: full\n !logical :: GREATR\n real (wp) :: dat05\n real (wp) :: a,r,e,epsabs,EMACH,ATOT,fadd,newres,newerr\n real (wp), dimension(3) :: u,v\n real (wp), dimension(9) :: node,node1,node2\n save ATOT\n !external F,GREATR\n external F\n external G,H\n integer :: i, j\n \n EMACH = R1MACH(4)\n \n N = 2\n X(1,1) = AA\n Y(1,1) = G(AA)\n X(2,1) = BB\n Y(2,1) = G(BB)\n X(3,1) = BB\n Y(3,1) = H(BB)\n X(1,2) = AA\n Y(1,2) = G(AA)\n X(2,2) = BB\n Y(2,2) = H(BB)\n X(3,2) = AA\n Y(3,2) = H(AA)\n NU = 0\n ND = 0\n IFLAG = 1\n ICLOSE = 1\n MAXTRI = 100\n MEVALS = 8000\n \n\n! If heaps are empty, apply LQM to each input triangle and\n! place all of the data on the second heap.\n\n if((nu+nd) == 0) then\n call HINITU(maxtri,9,nu,iwork)\n call HINITD(maxtri,9,nd,iwork(maxtri+1))\n ATOT=0.0\n result=0.0\n error=0.0\n rndcnt=0\n nevals=0\n do i=1,n\n do j=1,3\n u(j)=x(j,i)\n v(j)=y(j,i)\n end do\n a=0.5*abs(u(1)*v(2)+u(2)*v(3)+u(3)*v(1) &\n -u(1)*v(3)-u(2)*v(1)-u(3)*v(2))\n ATOT=ATOT+a\n if(iclose == 1) then\n call LQM1(f,u,v,r,e)\n nevals=nevals+47\n else\n call LQM0(f,u,v,r,e)\n nevals=nevals+28\n end if\n result=result+r\n error=error+e\n node(1)=e\n node(2)=r\n node(3)=x(1,i)\n node(4)=y(1,i)\n node(5)=x(2,i)\n node(6)=y(2,i)\n node(7)=x(3,i)\n node(8)=y(3,i)\n node(9)=a\n call HPINS(maxtri,9,data,nd,iwork(maxtri+1),node,GREATR)\n end do\n end if\n\n! Check that input tolerance is consistent with\n! machine epsilon.\n\n if(iflag == 0) then\n if(tol <= 5.0*EMACH) then\n tol=5.0*EMACH\n fadd=3\n else\n fadd=0\n end if\n epsabs=tol*abs(result)\n else if(iflag == 1) then\n if(tol <= 5.0*EMACH*abs(result)) then\n epsabs=5.0*EMACH*abs(result)\n else\n fadd=0\n epsabs=tol\n end if\n else\n iflag=9\n return\n end if\n\n! Adjust the second heap on the basis of the current\n! value of epsabs.\n\n 2 if(nd == 0) go to 40\n j=nd\n 3 if(j == 0) go to 40\n call HPACC(maxtri,9,data,nd,iwork(maxtri+1),node,j)\n if(node(1) > epsabs*node(9)/ATOT) then\n call HPINS(maxtri,9,data,nu,iwork,node,GREATR)\n call HPDEL(maxtri,9,data,nd,iwork(maxtri+1),GREATR,j)\n if(j > nd) j=j-1\n else\n j=j-1\n end if\n go to 3\n\n! Beginning of main loop from here to end\n\n 40 if(nevals >= mevals) then\n iflag=4\n return\n end if\n if(error <= epsabs) then\n if(iflag == 0) then\n if(error <= abs(result)*tol) then\n iflag=fadd\n return\n else\n epsabs=abs(result)*tol\n go to 2\n end if\n else\n if(error <= tol) then\n iflag=0\n return\n else if(error <= 5.0*EMACH*abs(result)) then\n iflag=3\n return\n else\n epsabs=5.0*EMACH*abs(result)\n go to 2\n end if\n end if\n end if\n\n! If there are too many triangles and second heap\n! is not empty remove bottom triangle from second\n! heap. If second heap is empty return with iflag\n! set to 1 or 4.\n\n if((nu+nd) >= maxtri) then\n full= .TRUE. \n if(nd > 0) then\n iwork(nu+1)=iwork(maxtri+nd)\n nd=nd-1\n else\n iflag=1\n return\n end if\n else\n full= .FALSE. \n end if\n\n! Find triangle with largest error, divide it in\n! two, and apply LQM to each half.\n\n if(nd == 0) then\n call HPACC(maxtri,9,data,nu,iwork,node,1)\n call HPDEL(maxtri,9,data,nu,iwork,GREATR,1)\n else if(nu == 0) then\n call HPACC(maxtri,9,data,nd,iwork(maxtri+1),node,1)\n call HPDEL(maxtri,9,data,nd,iwork(maxtri+1),GREATR,1)\n else if(data(iwork(1)) >= data(iwork(maxtri+1))) then\n if(full) iwork(maxtri+nd+2)=iwork(nu)\n call HPACC(maxtri,9,data,nu,iwork,node,1)\n call HPDEL(maxtri,9,data,nu,iwork,GREATR,1)\n else\n if(full) iwork(nu+2)=iwork(maxtri+nd)\n call HPACC(maxtri,9,data,nd,iwork(maxtri+1),node,1)\n call HPDEL(maxtri,9,data,nd,iwork(maxtri+1),GREATR,1)\n end if\n dat05 = 0.5\n call tridv(node,node1,node2,dat05,1)\n do 60 j=1,3\n u(j)=node1(2*j+1)\n v(j)=node1(2*j+2)\n 60 end do\n if(iclose == 1) then\n call LQM1(f,u,v,node1(2),node1(1))\n nevals=nevals+47\n else\n call LQM0(f,u,v,node1(2),node1(1))\n nevals=nevals+28\n end if\n do 70 j=1,3\n u(j)=node2(2*j+1)\n v(j)=node2(2*j+2)\n 70 end do\n if(iclose == 1) then\n call LQM1(f,u,v,node2(2),node2(1))\n nevals=nevals+47\n else\n call LQM0(f,u,v,node2(2),node2(1))\n nevals=nevals+28\n end if\n newerr=node1(1)+node2(1)\n newres=node1(2)+node2(2)\n if(newerr > 0.99*node(1)) then\n if(abs(node(2)-newres) <= 1.E-04*abs(newres)) rndcnt=rndcnt+1\n end if\n result=result-node(2)+newres\n error=error-node(1)+newerr\n if(node1(1) > node1(9)*epsabs/ATOT) then\n call HPINS(maxtri,9,data,nu,iwork,node1,GREATR)\n else\n call HPINS(maxtri,9,data,nd,iwork(maxtri+1),node1,GREATR)\n end if\n if(node2(1) > node2(9)*epsabs/ATOT) then\n call HPINS(maxtri,9,data,nu,iwork,node2,GREATR)\n else\n call HPINS(maxtri,9,data,nd,iwork(maxtri+1),node2,GREATR)\n end if\n if(rndcnt >= 20) then\n iflag=2\n return\n end if\n if(iflag == 0) then\n if(epsabs < 0.5*tol*abs(result)) then\n epsabs=tol*abs(result)\n j=nu\n 5 if(j == 0) go to 40\n call HPACC(maxtri,9,data,nu,iwork,node,j)\n if(node(1) <= epsabs*node(9)/ATOT) then\n call HPINS(maxtri,9,data,nd,iwork(maxtri+1),node,GREATR)\n call HPDEL(maxtri,9,data,nu,iwork,GREATR,j)\n if(j > nu) j=j-1\n else\n j=j-1\n end if\n go to 5\n end if\n end if\n go to 40\n\n\n end subroutine DTWODQ\n\n\n\n function GREATR(A,B,NWDS)\n \n implicit none\n\n logical :: GREATR\n integer :: NWDS\n real (wp), dimension(NWDS) :: A, B\n\n GREATR= A(1) > B(1)\n return\n\n end function GREATR\n\n\n subroutine HINITD(NMAX,NWDS,N,T)\n! PURPOSE\n! THIS ROUTINE INITIALIZES THE HEAP PROGRAMS WITH T(NMAX)\n! POINTING TO THE TOP OF THE HEAP.\n! IT IS CALLED ONCE AT THE START OF EACH NEW CALCULATION.\n! INPUT\n! NMAX=MAXIMUM NUMBER OF NODES ALLOWED BY USER\n! NWDS=NUMBER OF WORDS PER NODE\n! OUTPUT\n! N=CURRENT NUMBER OF NODES IN HEAP = 0.\n! T=INTEGER ARRAY OF POINTERS TO POTENTIAL HEAP NODES.\n\n implicit none\n\n integer, dimension(1) :: T\n integer :: NMAX, NWDS, N, I\n\n do I=1,NMAX\n T(I)=(NMAX-I)*NWDS+1\n end do\n N=0\n return\n\n end subroutine HINITD\n\n\n subroutine HINITU(NMAX,NWDS,N,T)\n! H E A P PACKAGE\n! A COLLECTION OF PROGRAMS WHICH MAINTAIN A HEAP DATA\n! STRUCTURE. BY CALLING THESE SUBROUTINES IT IS POSSIBLE TO\n! INSERT, DELETE, AND ACCESS AN EXISTING HEAP OR TO BUILD A\n! NEW HEAP FROM AN UNORDERED COLLECTION OF NODES. THE HEAP\n! FUNCTION IS AN ARGUMENT TO THE SUBROUTINES ALLOWING VERY\n! GENERAL ORGANIZATIONS.\n! THE USER MUST DECIDE ON THE MAXIMUM NUMBER OF NODES\n! ALLOWED AND DIMENSION THE real (wp) ARRAY DATA AND THE INTEGER\n! ARRAY T USED INTERNALLY BY THE PACKAGE. THESE VARIABLES ARE\n! THEN PASSED THROUGH THE CALL SEQUENCE BETWEEN THE HEAP\n! PROGRAMS BUT ARE NOT IN GENERAL ACCESSED BY THE USER. HE\n! MUST ALSO PROVIDE A HEAP FUNCTION WHOSE NAME MUST BE INCLUD-\n! ED IN AN EXTERNAL STATEMENT IN THE USER PROGRAM WHICH CALLS\n! THE HEAP SUBROUTINES. TWO SIMPLE HEAP FUNCTIONS ARE\n! PROVIDED WITH THE PACKAGE.\n\n\n! PURPOSE\n! THIS ROUTINE INITIALIZES THE HEAP PROGRAMS WITH T(1)\n! POINTING TO THE TOP OF THE HEAP.\n! IT IS CALLED ONCE AT THE START OF EACH NEW CALCULATION\n! INPUT\n! NMAX = MAXIMUM NUMBER OF NODES ALLOWED BY USER.\n! NWDS = NUMBER OF WORDS PER NODE\n! OUTPUT\n! N = CURRENT NUMBER OF NODES IN HEAP = 0.\n! T = integer ARRAY OF POINTERS TO POTENTIAL HEAP NODES.\n\n implicit none\n\n integer, dimension(1) :: T\n integer :: NMAX, NWDS, N, I\n\n do I=1,NMAX\n T(I)=(I-1)*NWDS+1\n end do\n N = 0\n return\n\n end subroutine HINITU\n\n\n subroutine HPACC(NMAX,NWDS,DATA,N,T,XNODE,K)\n\n! PURPOSE\n! TO ACCESS THE K-TH NODE OF THE HEAP,\n! 1 .LE. K .LE. N .LE. NMAX\n! INPUT\n! NMAX = MAXIMUM NUMBER OF NODES ALLOWED BY USER.\n! DATA = WORK AREA FOR STORING NODES.\n! N = CURRENT NUMBER OF NODES IN THE HEAP.\n! T = integer ARRAY OF POINTERS TO HEAP NODES.\n! XNODE = A real (wp) ARRAY, NWDS WORDS LONG, IN WHICH NODAL IN-\n! FORMATION WILL BE INSERTED.\n! K = THE INDEX OF THE NODE TO BE FOUND AND INSERTED INTO\n! XNODE.\n\n! OUTPUT\n! XNODE = A real (wp) ARRAY. CONTAINS IN XNODE(1),...,XNODE(NWDS)\n! THE ELEMENTS OF THE K-TH NODE.\n\n implicit none\n\n real (wp), dimension(1) :: DATA, XNODE\n integer, dimension(1) :: T\n integer :: NMAX, NWDS, N, K, I, IPJ, J\n\n if (K < 1 .OR. K > N .OR. N > NMAX) return\n J=T(K)-1\n do I=1,NWDS\n IPJ=I+J\n XNODE(I)=DATA(IPJ)\n end do\n return\n\n end subroutine HPACC\n\n\n subroutine HPBLD(NMAX,NWDS,DATA,N,T,HPFUN)\n\n! PURPOSE\n! BUILDS A HEAP, IN T , FROM AN ARRAY OF N ELEMENTS\n! IN DATA, WHICH ARE SPACED NWDS APART.\n! AT CONCLUSION OF CALCULATION THE TOP SATISFIES\n! HPFUN(TOP,SON) = .TRUE. FOR ANY SON.\n! USES subroutine HPGRO BY FEEDING IT ONE ELEMENT OF\n! THE ARRAY AT A TIME.\n\n! INPUT\n! NMAX = MAXIMUN NUMBER OF NODES ALLOWED BY USER.\n! NWDS = NUMBER OF WORDS PER NODE.\n! DATA = WORK AREA IN WHICH THE NODES ARE STORED.\n! N = CURRENT NUMBER OF NODES.\n! T = integer ARRAY OF POINTERS TO HEAP NODES.\n! HPFUN = NAME OF USER WRITTEN FUNCTION TO DETERMINE TOP NODE.\n! OUTPUT\n! DATA = WORK AREA IN WHICH THE NODES ARE STORED.\n! T = integer ARRAY OF POINTERS TO HEAP NODES.\n! IN PARTICULAR T(1) POINTS TO THE TOP.\n\n implicit none\n\n external HPFUN\n logical :: HPFUN\n real (wp), dimension(1) :: DATA\n integer, dimension(1) :: T\n integer :: NMAX, NWDS, N, INDEX\n\n if (NMAX < N) return \n INDEX = N/2\n 1 continue\n if ( INDEX == 0) return \n call HPGRO(NMAX,NWDS,DATA,N,T,HPFUN,INDEX)\n INDEX = INDEX-1\n GO TO 1\n\n end subroutine HPBLD\n\n\n subroutine HPDEL(NMAX,NWDS,DATA,N,T,HPFUN,K)\n\n! PURPOSE\n! DELETE K-TH ELEMENT OF HEAP. RESULTING TREE IS REHEAPED.\n! INPUT\n! NMAX = MAXIMUN NUMBER OF NODES ALLOWED BY USER.\n! NWDS = NUMBER OF WORDS PER NODE.\n! DATA = WORK AREA IN WHICH THE NODES ARE STORED.\n! N = CURRENT NUMBER OF NODES.\n! T = integer ARRAY OF POINTERS TO NODES.\n! HPFUN = NAME OF USER WRITTEN FUNCTION TO DETERMINE TOP NODE.\n! K = INDEX OF NODE TO BE DELETED\n! OUTPUT\n! N = UPDATED NUMBER OF NODES.\n! T = UPDATED integer POINTER ARRAY TO NODES.\n\n implicit none\n\n external HPFUN\n logical :: HPFUN\n real (wp), dimension(1) :: DATA\n integer, dimension(1) :: T\n integer :: NMAX, NWDS, N, K, IL, IR, JUNK, KDEL, KHALVE\n\n if (N == 0) return \n if (K == N) then\n N=N-1\n return \n end if\n KDEL=K\n JUNK=T(KDEL)\n T(KDEL)=T(N)\n T(N)=JUNK\n N=N-1\n 10 if (KDEL == 1) then\n CALL HPGRO(NMAX,NWDS,DATA,N,T,HPFUN,KDEL)\n return \n else\n KHALVE=KDEL/2\n IL=T(KHALVE)\n IR=T(KDEL)\n if (HPFUN(DATA(IL),DATA(IR),NWDS)) then\n CALL HPGRO(NMAX,NWDS,DATA,N,T,HPFUN,KDEL)\n return \n else\n T(KHALVE)=IR\n T(KDEL)=IL\n KDEL=KHALVE\n end if\n end if\n GO TO 10\n\n end subroutine HPDEL\n\n\n subroutine HPGRO(NMAX,NWDS,DATA,N,T,HPFUN,I)\n\n! PURPOSE\n! FORMS A HEAP OUT OF A TREE. USED PRIVATELY BY HPBLD.\n! THE TOP OF THE TREE IS STORED IN LOCATION T(I).\n! FIRST SON IS IN LOCATION T(2I), NEXT SON\n! IS IN LOCATION T(2I+1).\n! THIS PROGRAM ASSUMES EACH BRANCH OF THE TREE IS A HEAP.\n\n implicit none\n\n logical :: HPFUN\n real (wp), dimension(1) :: DATA\n integer, dimension(1) :: T\n integer :: NMAX, NWDS, N, I, IL, IR, ITEMP, J, K\n\n if (N > NMAX) return \n\n K=I\n 1 J=2*K\n\n! TEST IF ELEMENT IN J TH POSITION IS A LEAF.\n\n if ( J > N ) return \n\n! IF THERE IS MORE THAN ONE SON, FIND WHICH SON IS SMALLEST.\n\n if ( J == N ) GO TO 2\n IR=T(J)\n IL=T(J+1)\n if (HPFUN(DATA(IL),DATA(IR),NWDS)) J=J+1\n\n! IF A SON IS LARGER THAN FATHER, INTERCHANGE\n! THIS DESTROYS HEAP PROPERTY, SO MUST RE-HEAP REMAINING\n! ELEMENTS\n\n 2 continue\n IL=T(K)\n IR=T(J)\n if (HPFUN(DATA(IL),DATA(IR),NWDS)) return \n ITEMP=T(J)\n T(J)=T(K)\n T(K)=ITEMP\n K=J\n GO TO 1\n end subroutine HPGRO\n\n\n subroutine HPINS(NMAX,NWDS,DATA,N,T,XNODE,HPFUN)\n\n! PURPOSE\n! THIS ROUTINE INSERTS A NODE INTO AN ALREADY EXISTING HEAP.\n! THE RESULTING TREE IS RE-HEAPED.\n\n! INPUT\n! NMAX = MAXIMUM NUMBER OF NODES ALLOWED BY USER.\n! NWDS = NUMBER OF WORDS PER NODE.\n! DATA = WORK AREA FOR STORING NODES.\n! N = CURRENT NUMBER OF NODES IN THE TREE.\n! T = integer ARRAY OF POINTERS TO HEAP NODES.\n! XNODE = A real (wp) ARRAY, NWDS WORDS LONG, WHICH\n! CONTAINS THE NODAL INFORMATION TO BE INSERTED.\n! HPFUN = NAME OF USER WRITTEN FUNCTION TO DETERMINE\n! THE TOP NODE.\n! OUTPUT\n! DATA = WORK AREA WITH NEW NODE INSERTED.\n! N = UPDATED NUMBER OF NODES.\n! T = UPDATED integer POINTER ARRAY.\n\n implicit none\n\n logical :: HPFUN\n real (wp) :: XNODE(1),DATA(1)\n integer :: T(1)\n integer :: NMAX, NWDS, N, I, IPJ, J, J2, JL, JR\n\n if (N == NMAX) return \n N=N+1\n J= T(N)-1\n do 1 I= 1,NWDS\n IPJ=I+J\n DATA(IPJ) = XNODE(I)\n 1 end do\n J=N\n 2 continue\n if (J == 1) return \n JR=T(J)\n J2=J/2\n JL=T(J2)\n if (HPFUN(DATA(JL),DATA(JR),NWDS)) return \n T(J2)=T(J)\n T(J)=JL\n J=J2\n GO TO 2\n\n end subroutine HPINS\n\n\n function LESS(A,B,NWDS)\n\n implicit none\n\n logical :: LESS\n integer :: NWDS\n real (wp), dimension(NWDS) :: A, B\n\n LESS= A(1) < B(1)\n return \n\n end function LESS\n\n\n subroutine LQM0(F,U,V,RES8,EST)\n\n\n\n! PURPOSE\n! TO COMPUTE - IF = INTEGRAL OF F OVER THE TRIANGLE\n! WITH VERTICES (U(1),V(1)),(U(2),V(2)),(U(3),V(3)), AND\n! ESTIMATE THE ERROR,\n! - INTEGRAL OF ABS(F) OVER THIS TRIANGLE\n\n! CALLING SEQUENCE\n! CALL LQM0(F,U,V,RES11,EST)\n! PARAMETERS\n! F - FUNCTION SUBPROGRAM DEFINING THE INTEGRAND\n! F(X,Y); THE ACTUAL NAME FOR F NEEDS TO BE\n! DECLARED E X T E R N A L IN THE CALLING\n! PROGRAM\n! U(1),U(2),U(3)- ABSCISSAE OF VERTICES\n! V(1),V(2),V(3)- ORDINATES OF VERTICES\n! RES6 - APPROXIMATION TO THE INTEGRAL IF, OBTAINED BY THE\n! LYNESS AND JESPERSEN RULE OF DEGREE 6, USING\n! 12 POINTS\n! RES8 - APPROXIMATION TO THE INTEGRAL IF, OBTAINED BY THE\n! LYNESS AND JESPERSEN RULE OF DEGREE 8,\n! USING 16 POINTS\n! EST - ESTIMATE OF THE ABSOLUTE ERROR\n! DRESC - APPROXIMATION TO THE INTEGRAL OF ABS(F- IF/DJ),\n! OBTAINED BY THE RULE OF DEGREE 6, AND USED FOR\n! THE COMPUTATION OF EST\n\n! REMARKS\n! DATE OF LAST UPDATE : 10 APRIL 1984 O.W. RECHARD NBS\n\n! SUBROUTINES OR FUNCTIONS CALLED :\n! - F (USER-SUPPLIED INTEGRAND FUNCTION)\n! - R1MACH FOR MACHINE DEPENDENT INFORMATION\n\n! .....................................................................\n\n implicit none\n\n real (wp) :: DJ,DF0,DRESC,EMACH,EST,F,F0, &\n RES6,RES8,U1,U2,U3,UFLOW,V1,V2,V3,W60,W80, &\n Z1,Z2,Z3,RESAB6\n real (wp) :: AMAX1,AMIN1,SQRT\n real (wp), dimension(3) :: U,V,X,Y\n real (wp), dimension(9) :: W,ZETA1,ZETA2\n real (wp), dimension(19) :: FV\n integer :: J,KOUNT,L\n\n\n! FIRST HOMOGENEOUS COORDINATES OF POINTS IN DEGREE-6\n! AND DEGREE-8 FORMULA, TAKEN WITH MULTIPLICITY 3\n DATA ZETA1(1),ZETA1(2),ZETA1(3),ZETA1(4),ZETA1(5),ZETA1(6),ZETA1(7 &\n ),ZETA1(8),ZETA1(9)/0.5014265096581342E+00, &\n & 0.8738219710169965E+00,0.6365024991213939E+00, &\n & 0.5314504984483216E-01,0.8141482341455413E-01, &\n & 0.8989055433659379E+00,0.6588613844964797E+00, &\n & 0.8394777409957211E-02,0.7284923929554041E+00/\n! SECOND HOMOGENEOUS COORDINATES OF POINTS IN DEGREE-6\n! AND DEGREE-8 FORMULA, TAKEN WITH MUNLTIPLICITY 3\n DATA ZETA2(1),ZETA2(2),ZETA2(3),ZETA2(4),ZETA2(5),ZETA2(6),ZETA2(7 &\n ),ZETA2(8),ZETA2(9)/0.2492867451709329E+00, &\n & 0.6308901449150177E-01,0.5314504984483216E-01, &\n & 0.6365024991213939E+00,0.4592925882927229E+00, &\n & 0.5054722831703103E-01,0.1705693077517601E+00, &\n & 0.7284923929554041E+00,0.8394777409957211E-02/\n! WEIGHTS OF MID-POINT OF TRIANGLE IN DEGREE-6\n! RESP. DEGREE-8 FORMULAE\n DATA W60/0.0E+00/\n DATA W80/0.1443156076777862E+00/\n! WEIGHTS IN DEGREE-6 AND DEGREE-8 RULE\n DATA W(1),W(2),W(3),W(4),W(5),W(6),W(7),W(8),W(9)/ &\n & 0.1167862757263407E+00,0.5084490637020547E-01, &\n & 0.8285107561839291E-01,0.8285107561839291E-01, &\n & 0.9509163426728497E-01,0.3245849762319813E-01, &\n & 0.1032173705347184E+00,0.2723031417443487E-01, &\n & 0.2723031417443487E-01/\n\n! LIST OF MAJOR VARIABLES\n! ----------------------\n! DJ - AREA OF THE TRIANGLE\n! DRESC - APPROXIMATION TO INTEGRAL OF\n! ABS(F- IF/DJ) OVER THE TRIANGLE\n! RESAB6 - APPROXIMATION TO INTEGRAL OF\n! ABS(F) OVER THE TRIANGLE\n! X - CARTESIAN ABSCISSAE OF THE INTEGRATION\n! POINTS\n! Y - CARTESIAN ORDINATES OF THE INTEGRATION\n! POINTS\n! FV - FUNCTION VALUES\n\n! COMPUTE DEGREE-6 AND DEGREE-8 RESULTS FOR IF/DJ AND\n! DEGREE-6 APPROXIMATION FOR ABS(F)\n\n EMACH = R1MACH(4)\n UFLOW = R1MACH(1)\n U1=U(1)\n U2=U(2)\n U3=U(3)\n V1=V(1)\n V2=V(2)\n V3=V(3)\n DJ = ABS(U1*V2-U2*V1-U1*V3+V1*U3+U2*V3-V2*U3)*0.5E+00\n F0 = F((U1+U2+U3)/3.0E+00,(V1+V2+V3)/3.0E+00)\n RES6 = F0*W60\n RESAB6 = ABS(F0)*W60\n FV(1) = F0\n KOUNT = 1\n RES8 = F0*W80\n do 50 J=1,9\n Z1 = ZETA1(J)\n Z2 = ZETA2(J)\n Z3 = 1.0E+00-Z1-Z2\n X(1) = Z1*U1+Z2*U2+Z3*U3\n Y(1) = Z1*V1+Z2*V2+Z3*V3\n X(2) = Z2*U1+Z3*U2+Z1*U3\n Y(2) = Z2*V1+Z3*V2+Z1*V3\n X(3) = Z3*U1+Z1*U2+Z2*U3\n Y(3) = Z3*V1+Z1*V2+Z2*V3\n if (J <= 4) then\n F0 = 0.0E+00\n DF0 = 0.0E+00\n do 10 L=1,3\n KOUNT = KOUNT+1\n FV(KOUNT) = F(X(L),Y(L))\n F0 = F0+FV(KOUNT)\n DF0 = DF0+ABS(FV(KOUNT))\n 10 end do\n RES6 = RES6+F0*W(J)\n RESAB6 = RESAB6+DF0*W(J)\n else\n F0 = F(X(1),Y(1))+F(X(2),Y(2))+F(X(3),Y(3))\n RES8 = RES8+F0*W(J)\n end if\n 50 end do\n\n! COMPUTE DEGREE-6 APPROXIMATION FOR THE INTEGRAL OF\n! ABS(F-IF/DJ)\n\n DRESC = ABS(FV(1)-RES6)*W60\n KOUNT = 2\n do 60 J=1,4\n DRESC = DRESC+(ABS(FV(KOUNT)-RES6)+ABS(FV(KOUNT+1)-RES6)+ABS( &\n FV(KOUNT+2)-RES6))*W(J)\n KOUNT = KOUNT+3\n 60 end do\n\n! COMPUTE DEGREE-6 AND DEGREE-8 APPROXIMATIONS FOR IF,\n! AND ERROR ESTIMATE\n\n RES6 = RES6*DJ\n RES8 = RES8*DJ\n RESAB6 = RESAB6*DJ\n DRESC = DRESC*DJ\n EST = ABS(RES6-RES8)\n if (DRESC /= 0.0E+00) EST = AMAX1(EST,DRESC*AMIN1(1.0E+00,(20.0E+00 &\n *EST/DRESC)**1.5E+00))\n if (RESAB6 > UFLOW) EST = AMAX1(EMACH*RESAB6,EST)\n return \n\n end subroutine LQM0\n\n\n subroutine LQM1(F,U,V,RES11,EST)\n\n\n\n! PURPOSE\n! TO COMPUTE - IF = INTEGRAL OF F OVER THE TRIANGLE\n! WITH VERTICES (U(1),V(1)),(U(2),V(2)),(U(3),V(3)), AND\n! ESTIMATE THE ERROR,\n! - INTEGRAL OF ABS(F) OVER THIS TRIANGLE\n\n! CALLING SEQUENCE\n! CALL LQM1(F,U,V,RES11,EST)\n! PARAMETERS\n! F - FUNCTION SUBPROGRAM DEFINING THE INTEGRAND\n! F(X,Y); THE ACTUAL NAME FOR F NEEDS TO BE\n! DECLARED E X T E R N A L IN THE CALLING\n! PROGRAM\n! U(1),U(2),U(3)- ABSCISSAE OF VERTICES\n! V(1),V(2),V(3)- ORDINATES OF VERTICES\n! RES9 - APPROXIMATION TO THE INTEGRAL IF, OBTAINED BY THE\n! LYNESS AND JESPERSEN RULE OF DEGREE 9, USING\n! 19 POINTS\n! RES11 - APPROXIMATION TO THE INTEGRAL IF, OBTAINED BY THE\n! LYNESS AND JESPERSEN RULE OF DEGREE 11,\n! USING 28 POINTS\n! EST - ESTIMATE OF THE ABSOLUTE ERROR\n! DRESC - APPROXIMATION TO THE INTEGRAL OF ABS(F- IF/DJ),\n! OBTAINED BY THE RULE OF DEGREE 9, AND USED FOR\n! THE COMPUTATION OF EST\n\n! REMARKS\n! DATE OF LAST UPDATE : 18 JAN 1984 D. KAHANER NBS\n\n! SUBROUTINES OR FUNCTIONS CALLED :\n! - F (USER-SUPPLIED INTEGRAND FUNCTION)\n! - R1MACH FOR MACHINE DEPENDENT INFORMATION\n\n! .....................................................................\n\n implicit none\n\n real (wp) :: DJ,DF0,DRESC,EMACH,EST,F,F0, &\n RES9,RES11,U1,U2,U3,UFLOW,V1,V2,V3,W90,W110, &\n Z1,Z2,Z3\n real (wp) :: AMAX1,AMIN1,SQRT\n real (wp) :: RESAB9\n real (wp), dimension(3) :: U,V,X,Y\n real (wp), dimension(15) :: W,ZETA1,ZETA2\n real (wp), dimension(19) :: FV\n integer :: J,KOUNT,L\n\n\n! FIRST HOMOGENEOUS COORDINATES OF POINTS IN DEGREE-9\n! AND DEGREE-11 FORMULA, TAKEN WITH MULTIPLICITY 3\n DATA ZETA1(1),ZETA1(2),ZETA1(3),ZETA1(4),ZETA1(5),ZETA1(6),ZETA1(7 &\n ),ZETA1(8),ZETA1(9),ZETA1(10),ZETA1(11),ZETA1(12),ZETA1(13), &\n ZETA1(14),ZETA1(15)/0.2063496160252593E-01,0.1258208170141290E+00, &\n & 0.6235929287619356E+00,0.9105409732110941E+00, &\n & 0.3683841205473626E-01,0.7411985987844980E+00, &\n & 0.9480217181434233E+00,0.8114249947041546E+00, &\n & 0.1072644996557060E-01,0.5853132347709715E+00, &\n & 0.1221843885990187E+00,0.4484167758913055E-01, &\n & 0.6779376548825902E+00,0.0E+00,0.8588702812826364E+00/\n! SECOND HOMOGENEOUS COORDINATES OF POINTS IN DEGREE-9\n! AND DEGREE-11 FORMULA, TAKEN WITH MUNLTIPLICITY 3\n DATA ZETA2(1),ZETA2(2),ZETA2(3),ZETA2(4),ZETA2(5),ZETA2(6),ZETA2(7 &\n ),ZETA2(8),ZETA2(9),ZETA2(10),ZETA2(11),ZETA2(12),ZETA2(13), &\n ZETA2(14),ZETA2(15)/0.4896825191987370E+00,0.4370895914929355E+00, &\n & 0.1882035356190322E+00,0.4472951339445297E-01, &\n & 0.7411985987844980E+00,0.3683841205473626E-01, &\n & 0.2598914092828833E-01,0.9428750264792270E-01, &\n & 0.4946367750172147E+00,0.2073433826145142E+00, &\n & 0.4389078057004907E+00,0.6779376548825902E+00, &\n & 0.4484167758913055E-01,0.8588702812826364E+00,0.0E+00/\n! WEIGHTS OF MID-POINT OF TRIANGLE IN DEGREE-9\n! RESP. DEGREE-11 FORMULAE\n DATA W90/0.9713579628279610E-01/\n DATA W110/0.8797730116222190E-01/\n! WEIGHTS IN DEGREE-9 AND DEGREE-11 RULE\n DATA W(1),W(2),W(3),W(4),W(5),W(6),W(7),W(8),W(9),W(10),W(11),W(12 &\n ),W(13),W(14),W(15)/0.3133470022713983E-01,0.7782754100477543E-01, &\n & 0.7964773892720910E-01,0.2557767565869810E-01, &\n & 0.4328353937728940E-01,0.4328353937728940E-01, &\n & 0.8744311553736190E-02,0.3808157199393533E-01, &\n & 0.1885544805613125E-01,0.7215969754474100E-01, &\n & 0.6932913870553720E-01,0.4105631542928860E-01, &\n & 0.4105631542928860E-01,0.7362383783300573E-02, &\n & 0.7362383783300573E-02/\n\n! LIST OF MAJOR VARIABLES\n! ----------------------\n! DJ - AREA OF THE TRIANGLE\n! DRESC - APPROXIMATION TO INTEGRAL OF\n! ABS(F- IF/DJ) OVER THE TRIANGLE\n! RESAB9 - APPROXIMATION TO INTEGRAL OF\n! ABS(F) OVER THE TRIANGLE\n! X - CARTESIAN ABSCISSAE OF THE INTEGRATION\n! POINTS\n! Y - CARTESIAN ORDINATES OF THE INTEGRATION\n! POINTS\n! FV - FUNCTION VALUES\n\n! COMPUTE DEGREE-9 AND DEGREE-11 RESULTS FOR IF/DJ AND\n! DEGREE-9 APPROXIMATION FOR ABS(F)\n\n EMACH = R1MACH(4)\n UFLOW = R1MACH(1)\n U1=U(1)\n U2=U(2)\n U3=U(3)\n V1=V(1)\n V2=V(2)\n V3=V(3)\n DJ = ABS(U1*V2-U2*V1-U1*V3+V1*U3+U2*V3-V2*U3)*0.5E+00\n F0 = F((U1+U2+U3)/3.0E+00,(V1+V2+V3)/3.0E+00)\n RES9 = F0*W90\n RESAB9 = ABS(F0)*W90\n FV(1) = F0\n KOUNT = 1\n RES11 = F0*W110\n do 50 J=1,15\n Z1 = ZETA1(J)\n Z2 = ZETA2(J)\n Z3 = 1.0E+00-Z1-Z2\n X(1) = Z1*U1+Z2*U2+Z3*U3\n Y(1) = Z1*V1+Z2*V2+Z3*V3\n X(2) = Z2*U1+Z3*U2+Z1*U3\n Y(2) = Z2*V1+Z3*V2+Z1*V3\n X(3) = Z3*U1+Z1*U2+Z2*U3\n Y(3) = Z3*V1+Z1*V2+Z2*V3\n if (J <= 6) then\n F0 = 0.0E+00\n DF0 = 0.0E+00\n do 10 L=1,3\n KOUNT = KOUNT+1\n FV(KOUNT) = F(X(L),Y(L))\n F0 = F0+FV(KOUNT)\n DF0 = DF0+ABS(FV(KOUNT))\n 10 end do\n RES9 = RES9+F0*W(J)\n RESAB9 = RESAB9+DF0*W(J)\n else\n F0 = F(X(1),Y(1))+F(X(2),Y(2))+F(X(3),Y(3))\n RES11 = RES11+F0*W(J)\n end if\n 50 end do\n\n! COMPUTE DEGREE-9 APPROXIMATION FOR THE INTEGRAL OF\n! ABS(F-IF/DJ)\n\n DRESC = ABS(FV(1)-RES9)*W90\n KOUNT = 2\n do 60 J=1,6\n DRESC = DRESC+(ABS(FV(KOUNT)-RES9)+ABS(FV(KOUNT+1)-RES9)+ABS( &\n FV(KOUNT+2)-RES9))*W(J)\n KOUNT = KOUNT+3\n 60 end do\n\n! COMPUTE DEGREE-9 AND DEGREE-11 APPROXIMATIONS FOR IF,\n! AND ERROR ESTIMATE\n\n RES9 = RES9*DJ\n RES11 = RES11*DJ\n RESAB9 = RESAB9*DJ\n DRESC = DRESC*DJ\n EST = ABS(RES9-RES11)\n if (DRESC /= 0.0E+00) EST = AMAX1(EST,DRESC*AMIN1(1.0E+00,(20.0E+00 &\n *EST/DRESC)**1.5E+00))\n if (RESAB9 > UFLOW) EST = AMAX1(EMACH*RESAB9,EST)\n return \n\n end subroutine LQM1\n\n\n subroutine tridv(node,node1,node2,coef,rank)\n\n implicit none\n\n real (wp) :: coef,coef1,temp\n real (wp), dimension(*) :: node,node1,node2\n integer :: rank, i, j\n real (wp), dimension(3) :: s\n integer, dimension(3) :: t\n\n coef1=1.0-coef\n s(1)=(node(3)-node(5))**2+(node(4)-node(6))**2\n s(2)=(node(5)-node(7))**2+(node(6)-node(8))**2\n s(3)=(node(3)-node(7))**2+(node(4)-node(8))**2\n t(1)=1\n t(2)=2\n t(3)=3\n do 10 i=1,2\n do 10 j=i+1,3\n if(s(i) < s(j)) then\n temp=t(i)\n t(i)=t(j)\n t(j)=temp\n end if\n 10 end do\n if(t(rank) == 1)then\n node1(3)=coef*node(3)+coef1*node(5)\n node1(4)=coef*node(4)+coef1*node(6)\n node1(5)=node(5)\n node1(6)=node(6)\n node1(7)=node(7)\n node1(8)=node(8)\n node2(3)=node1(3)\n node2(4)=node1(4)\n node2(5)=node(7)\n node2(6)=node(8)\n node2(7)=node(3)\n node2(8)=node(4)\n else if(t(rank) == 2) then\n node1(3)=coef*node(5)+coef1*node(7)\n node1(4)=coef*node(6)+coef1*node(8)\n node1(5)=node(7)\n node1(6)=node(8)\n node1(7)=node(3)\n node1(8)=node(4)\n node2(3)=node1(3)\n node2(4)=node1(4)\n node2(5)=node(3)\n node2(6)=node(4)\n node2(7)=node(5)\n node2(8)=node(6)\n else\n node1(3)=coef*node(3)+coef1*node(7)\n node1(4)=coef*node(4)+coef1*node(8)\n node1(5)=node(3)\n node1(6)=node(4)\n node1(7)=node(5)\n node1(8)=node(6)\n node2(3)=node1(3)\n node2(4)=node1(4)\n node2(5)=node(5)\n node2(6)=node(6)\n node2(7)=node(7)\n node2(8)=node(8)\n end if\n node1(9)=coef*node(9)\n node2(9)=coef1*node(9)\n\n end subroutine tridv\n\n\n! ECK R1MACH\n function R1MACH(I)\n\n implicit none\n\n integer :: I\n real (wp) :: B, X, R1MACH\n!***BEGIN PROLOGUE R1MACH\n!***PURPOSE Return floating point machine dependent constants.\n!***LIBRARY SLATEC\n!***CATEGORY R1\n!***TYPE SINGLE PRECISION (R1MACH-S, D1MACH-D)\n!***KEYWORDS MACHINE CONSTANTS\n!***AUTHOR Fox, P. A., (Bell Labs)\n! Hall, A. D., (Bell Labs)\n! Schryer, N. L., (Bell Labs)\n!***DESCRIPTION\n!\n! R1MACH can be used to obtain machine-dependent parameters for the\n! local machine environment. It is a function subprogram with one\n! (input) argument, and can be referenced as follows:\n!\n! A = R1MACH(I)\n!\n! where I=1,...,5. The (output) value of A above is determined by\n! the (input) value of I. The results for various values of I are\n! discussed below.\n!\n! R1MACH(1) = B**(EMIN-1), the smallest positive magnitude.\n! R1MACH(2) = B**EMAX*(1 - B**(-T)), the largest magnitude.\n! R1MACH(3) = B**(-T), the smallest relative spacing.\n! R1MACH(4) = B**(1-T), the largest relative spacing.\n! R1MACH(5) = LOG10(B)\n!\n! Assume single precision numbers are represented in the T-digit,\n! base-B form\n!\n! sign (B**E)*( (X(1)/B) + ... + (X(T)/B**T) )\n!\n! where 0 .LE. X(I) .LT. B for I=1,...,T, 0 .LT. X(1), and\n! EMIN .LE. E .LE. EMAX.\n!\n! The values of B, T, EMIN and EMAX are provided in I1MACH as\n! follows:\n! I1MACH(10) = B, the base.\n! I1MACH(11) = T, the number of base-B digits.\n! I1MACH(12) = EMIN, the smallest exponent E.\n! I1MACH(13) = EMAX, the largest exponent E.\n!\n!\n!***REFERENCES P. A. Fox, A. D. Hall and N. L. Schryer, Framework for\n! a portable library, ACM Transactions on Mathematical\n! Software 4, 2 (June 1978), pp. 177-188.\n!***ROUTINES CALLED XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 790101 DATE WRITTEN\n! 960329 Modified for Fortran 90 (BE after suggestions by EG) \n!***END PROLOGUE R1MACH\n! \n X = 1.0\n B = RADIX(X)\n select case (I)\n case (1)\n R1MACH = B**(MINEXPONENT(X)-1) ! the smallest positive magnitude.\n case (2)\n R1MACH = HUGE(X) ! the largest magnitude.\n case (3)\n R1MACH = B**(-DIGITS(X)) ! the smallest relative spacing.\n case (4)\n R1MACH = B**(1-DIGITS(X)) ! the largest relative spacing.\n case (5)\n R1MACH = LOG10(B)\n case DEFAULT\n write (*, FMT = 9000)\n 9000 FORMAT ('1ERROR 1 IN R1MACH - I OUT OF BOUNDS')\n STOP\n end select\n return \n\n end function R1MACH\n\n\nend module dtwodq_mod\n", "meta": {"hexsha": "f12bce1975da8ac4a3c499b4c6879d6da1186d0b", "size": 41060, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/dtwodq_mod.f90", "max_stars_repo_name": "b1tank/DSM-f90", "max_stars_repo_head_hexsha": "5cab8c8e89d316828f41fc27fc9d603f6973f1bc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-06-26T18:36:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-06T00:35:49.000Z", "max_issues_repo_path": "src/dtwodq_mod.f90", "max_issues_repo_name": "b1tank/DSM-f90", "max_issues_repo_head_hexsha": "5cab8c8e89d316828f41fc27fc9d603f6973f1bc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-03-17T01:01:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-17T13:20:10.000Z", "max_forks_repo_path": "src/dtwodq_mod.f90", "max_forks_repo_name": "b1tank/DSM-f90", "max_forks_repo_head_hexsha": "5cab8c8e89d316828f41fc27fc9d603f6973f1bc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-08-08T14:45:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-22T01:07:42.000Z", "avg_line_length": 31.6089299461, "max_line_length": 77, "alphanum_fraction": 0.5732586459, "num_tokens": 14122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895028, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.776033279134756}} {"text": "!-------------------------------------------------------------------\n!..AN EXPLICIT FD SOLVER FOR THE 1-D LINEAR CONVECTION EQUATION \n!-------------------------------------------------------------------\nModule vars\n integer, parameter :: imax=401, ntout=1 \n integer :: ntmax, method\n real, dimension(imax) :: wave_n, wave_np1, wave_nm1\n real :: sigma, dx=0.1, x1 , pi= 3.1415926 !ACOS(-1.)\n real :: d, b=0.025\n End module\n \n program EXPLICIT_FDE\n use vars\n \n call INIT !..Read the input data, and initialize the wave\n DO nt = 1,ntmax !..Start the solution loop \n do i = 2,imax-1\n if(method .eq. 1) then\n wave_np1(i) = wave_n(i) - 0.5*sigma*(wave_n(i+1) - wave_n(i-1)) + d *(wave_n(i+1) - 2 * wave_n(i) + wave_n(i-1))\n elseif(method .eq. 2) then\n if(i.eq.2) then\n wave_np1(i) = wave_n(i) - 0.5*sigma*(wave_n(i+1) - wave_n(i-1)) + d *(wave_n(i+1) - 2 * wave_n(i) + wave_n(i-1))\n else\n wave_np1(i) = wave_n(i) - sigma*(wave_n(i) - wave_n(i-1)) + d *(wave_n(i) - 2 * wave_n(i-1) + wave_n(i-2))\n endif\n elseif(method .eq. 3) then\n if(nt .eq. 1) then\n wave_np1(i) = wave_n(i) - 0.5*sigma*(wave_n(i+1) - wave_n(i-1)) + d *(wave_n(i+1) - 2 * wave_n(i) + wave_n(i-1))\n else\n wave_np1(i) = 4*wave_n(i) - 3*wave_nm1(i) + sigma*(wave_n(i+1) - wave_n(i-1)) &\n - 2*d*(wave_n(i+1) - 2*wave_n(i) + wave_n(i-1))\n endif\n endif\n enddo\n wave_nm1(:) = wave_n(:)\n wave_n(:) = wave_np1(:)\n !..Output intermediate solutions\n if( MOD(nt,ntout) .eq. 0 .or. nt .eq. ntmax ) call IO(nt)\n ENDDO \n \n stop\n end program EXPLICIT_FDE\n \n !------------------------------------------------------------------------\n subroutine INIT\n use vars\n write(*,'(a)')'Select method'\n write(*,'(a)')' [1] Forward time central spatial'\n write(*,'(a)')' [2] Forward time backward spatial'\n write(*,'(a)')' [3] Question 4'\n read(*,*) method\n if((method .ne. 1) .and. (method .ne. 2) .and. (method .ne. 3)) then\n write(*,'(a)') \"Invalid selection\"\n stop\n endif\n \n write(*,'(/(a))',advance='no')' Enter sigma, d and ntmax : '\n read(*,*) sigma, d, ntmax\n x1=-imax*dx/2.\n x = x1\n do i = 1,imax !..Initialize the wave \n wave_n(i) = exp(-b * log(2.) * (x/dx)**2)\n x = x+dx\n enddo\n call IO(0)\n \n return \n end subroutine INIT\n \n !-------------------------------------------------------------------\n subroutine IO(nt)\n use vars\n character :: fname*32,string*6,ext*3\n write(string,'(f5.3)') float(nt)/1000\n read(string,'(2x,a3)') ext\n fname = 'wave-'//ext//'.dat' \n open(1,file=fname,form='formatted')\n !write(1,*)'ZONE'\n x = x1\n do i=1,imax\n write(1,'(2e14.6)')x, wave_n(i)\n x = x+dx\n enddo\n close(1)\n return \n end\n \n ", "meta": {"hexsha": "2a861b894de3079db0da18bbe0edb12ad344cc0d", "size": 2994, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Homework4/hw4.f90", "max_stars_repo_name": "Atknssl/AE305-Homeworks", "max_stars_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-06T18:42:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-04T13:27:27.000Z", "max_issues_repo_path": "Homework4/hw4.f90", "max_issues_repo_name": "Atknssl/AE305-Homeworks", "max_issues_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework4/hw4.f90", "max_forks_repo_name": "Atknssl/AE305-Homeworks", "max_forks_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.0227272727, "max_line_length": 131, "alphanum_fraction": 0.4652638611, "num_tokens": 987, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572635, "lm_q2_score": 0.8397339596505965, "lm_q1q2_score": 0.7760332732783042}} {"text": "subroutine ssrkf45(neqn,t0,u0,h,t,u,e)\n! \n! Subroutine ssrkf45 computes an ODE solution by the RK\n! Fehlberg 45 method for one step along the solution (by\n! calls to derv to define the ODE derivative vector).\n! It also estimates the truncation error of the solution,\n! and applies this estimate as a correction to the\n! solution vector.\n! \n! Argument list\n! \n! neqn number of first order ODEs\n! \n! t0 initial value of independent variable\n! \n! u0 initial condition vector of length neqn\n! \n! h integration step\n! \n! t independent variable\n! \n! u ODE solution vector of length neqn after\n! one rkf45 step\n! \n! e estimate of truncation error of the solu-\n! tion vector\n! \n! Double precision coding is used\nimplicit double precision(a-h,k,o-z)\n! \n! Size the arrays\nparameter(neq=500)\ndimension ut0(neq), ut(neq), u5(neq),k1(neq), k2(neq), k3(neq),k4(neq), k5(neq), k6(neq)\ndimension u0(neqn), u(neqn), e(neqn)\n! \n! Derivative vector at initial (base) point\ncall derv(neqn,t0,u0,ut0)\n! \n! k1, advance of dependent variable vector and\n! independent variable for calculation of k2\ndo i=1,neqn\nk1(i)=h*ut0(i)\nu(i)=u0(i)+0.25d0*k1(i)\nend do\nt=t0+0.25d0*h\n! \n! Derivative vector at new u, t\ncall derv(neqn,t,u,ut)\n! \n! k2, advance of dependent variable vector and\n! independent variable for calculation of k3\ndo i=1,neqn\nk2(i)=h*ut(i)\nu(i)=u0(i)+(3.0d0/32.0d0)*k1(i)+(9.0d0/32.0d0)*k2(i)\nend do\nt=t0+(3.0d0/8.0d0)*h\n! \n! Derivative vector at new u, t\ncall derv(neqn,t,u,ut)\n! \n! k3, advance of dependent variable vector and\n! independent variable for calculation of k4\ndo i=1,neqn\nk3(i)=h*ut(i)\nu(i)=u0(i)+(1932.0d0/2197.0d0)*k1(i)-(7200.0d0/2197.0d0)*k2(i)+(7296.0d0/2197.0d0)*k3(i)\nend do\nt=t0+(12.0d0/13.0d0)*h\n! \n! Derivative vector at new u, t\ncall derv(neqn,t,u,ut)\n! \n! k4, advance of dependent variable vector and\n! independent variable for calculation of k5\ndo i=1,neqn\nk4(i)=h*ut(i)\nu(i)=u0(i)+( 439.0d0/ 216.0d0)*k1(i)-( 8.0d0 )*k2(i)+(3680.0d0/ 513.0d0)*k3(i)-( 845.0d0/4104.0d0)*k4(i)\nend do\nt=t0+h\n! \n! Derivative vector at new u, t\ncall derv(neqn,t,u,ut)\n! \n! k5, advance of dependent variable vector and\n! independent variable for calculation of k6\ndo i=1,neqn\nk5(i)=h*ut(i)\nu(i)=u0(i)-( 8.0d0/ 27.0d0)*k1(i)+( 2.0d0 )*k2(i)-(3544.0d0/2565.0d0)*k3(i)+(1859.0d0/4104.0d0)*k4(i)-( 11.0d0/ 40.0d0)*k5(i)\nend do\nt=t0+0.5d0*h\n! \n! Derivative vector at new u, t\ncall derv(neqn,t,u,ut)\n! \n! k6, stepping\ndo i=1,neqn\nk6(i)=h*ut(i)\n! \n! Fourth order step\nu(i)=u0(i)+( 25.0d0 / 216.0d0)*k1(i)+(1408.0d0 / 2565.0d0)*k3(i)+(2197.0d0 / 4104.0d0)*k4(i)-( 1.0d0 / 5.0d0)*k5(i)\n! \n! Fifth order step\nu5(i)=u0(i)+( 16.0d0/ 135.0d0)*k1(i)+( 6656.0d0/12825.0d0)*k3(i)+(28561.0d0/56430.0d0)*k4(i)-( 9.0d0/ 50.0d0)*k5(i)+( 2.0d0/ 55.0d0)*k6(i)\nend do\ndo i=1,neqn\n! \n! Truncation error estimate\ne(i)=u5(i)-u(i)\n! \n! Fifth order solution vector (from (4,5) RK pair)\nu(i)=u(i)+e(i)\nend do\nt=t0+h\nreturn\n! \n! End of ssrkf45\nend", "meta": {"hexsha": "d69e53239f9b7087ee614ad70fe37ce92001d859", "size": 2909, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "PDE-Heat transfer/PDE-Heat transfer/ssrkf45.f90", "max_stars_repo_name": "cunyizju/Runge-Kutta-ODE-FORTRAN", "max_stars_repo_head_hexsha": "457151ea85dd5b0b04d3fb5a157049ef997f8f67", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-30T09:09:38.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-30T09:09:38.000Z", "max_issues_repo_path": "PDE-Heat transfer/PDE-Heat transfer/ssrkf45.f90", "max_issues_repo_name": "cunyizju/Runge-Kutta-ODE-FORTRAN", "max_issues_repo_head_hexsha": "457151ea85dd5b0b04d3fb5a157049ef997f8f67", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PDE-Heat transfer/PDE-Heat transfer/ssrkf45.f90", "max_forks_repo_name": "cunyizju/Runge-Kutta-ODE-FORTRAN", "max_forks_repo_head_hexsha": "457151ea85dd5b0b04d3fb5a157049ef997f8f67", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0775862069, "max_line_length": 138, "alphanum_fraction": 0.6761773805, "num_tokens": 1262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474220263198, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.776001693750841}} {"text": "! PROGRAM: Mandelbrot area\r\n!\r\n! PURPOSE: Program to compute the area of a Mandelbrot set.\r\n! Correct answer should be around 1.510659.\r\n!\r\n! USAGE: Program runs without input ... just run the executable\r\n! \r\n! HISTORY: Written: (Mark Bull, August 2011).\r\n! Changed \"comples\" to \"d_comples\" to avoid collsion with \r\n! math.h complex type (Tim Mattson, September 2011)\r\n! Converted to Fortran90 code (Helen He, September 2017)\r\n! Changed from \"atomic\" to \"critical\" to match Common Core (Helen He, November 2020)\r\n\r\n MODULE mandel_par_module\r\n implicit none\r\n\r\n INTEGER, PARAMETER :: DP = SELECTED_REAL_KIND(14)\r\n\r\n INTEGER, PARAMETER :: NPOINTS = 1000\r\n INTEGER, PARAMETER :: MAXITER = 1000\r\n INTEGER :: numoutside = 0\r\n\r\n TYPE d_complex\r\n REAL(KIND = DP) :: r\r\n REAL(KIND = DP) :: i\r\n END TYPE d_complex\r\n\r\n contains \r\n\r\n SUBROUTINE testpoint(c)\r\n\r\n! Does the iteration z=z*z+c, until |z| > 2 when point is known to be outside set\r\n! If loop count reaches MAXITER, point is considered to be inside the set\r\n\r\n implicit none\r\n TYPE(d_complex) :: z,c\r\n INTEGER :: iter\r\n REAL(KIND = DP) :: temp\r\n\r\n z = c\r\n\r\n DO iter = 1, MAXITER\r\n temp = (z%r*z%r) - (z%i*z%i) + c%r\r\n z%i = z%r*z%i*2 + c%i\r\n z%r = temp\r\n\r\n IF ((z%r*z%r + z%i*z%i) > 4.0) THEN \r\n !$OMP CRITICAL\r\n numoutside = numoutside + 1\r\n !$OMP END CRITICAL\r\n EXIT\r\n ENDIF\r\n ENDDO\r\n\r\n END SUBROUTINE\r\n\r\n END MODULE mandel_par_module\r\n\r\n\r\n PROGRAM mandel_par\r\n\r\n USE OMP_LIB\r\n USE mandel_par_module\r\n IMPLICIT NONE\r\n\r\n INTEGER :: i, j\r\n REAL(KIND = DP) :: area, error\r\n REAL(KIND = DP) :: eps = 1.0e-5\r\n\r\n TYPE(d_complex) :: c\r\n\r\n CALL OMP_SET_NUM_THREADS(4)\r\n\r\n! Loop over grid of points in the complex plane which contains the Mandelbrot set,\r\n! testing each point to see whether it is inside or outside the set.\r\n\r\n!$OMP PARALLEL DO DEFAULT(shared) FIRSTPRIVATE(eps) PRIVATE(c,j) \r\n\r\n DO i = 1, NPOINTS \r\n DO j = 1, NPOINTS \r\n c%r = -2.0 + 2.5 * DBLE(i-1) / DBLE(NPOINTS) + eps\r\n c%i = 1.125 * DBLE(j-1) / DBLE(NPOINTS) + eps\r\n CALL testpoint(c)\r\n ENDDO\r\n ENDDO\r\n!$OMP END PARALLEL DO\r\n\r\n! Calculate area of set and error estimate and output the results\r\n write(*,*)\"numoutside=\", numoutside\r\n \r\n area = 2.0*2.5*1.125 * DBLE(NPOINTS*NPOINTS - numoutside) &\r\n & / DBLE(NPOINTS*NPOINTS)\r\n error = area / DBLE(NPOINTS)\r\n\r\n WRITE(*,100) area, error\r\n100 FORMAT(\"Area of Mandlebrot set = \", f12.8, f12.8)\r\n WRITE(*,*)\"Correct answer should be around 1.510659\"\r\n\r\n END PROGRAM mandel_par\r\n", "meta": {"hexsha": "764a83dd07ac9c6a158e09dbcb32f9234e710ed3", "size": 2692, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Exercises/Fortran/solutions/mandel_par.f90", "max_stars_repo_name": "zafar-hussain/OmpCommonCore", "max_stars_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 37, "max_stars_repo_stars_event_min_datetime": "2020-04-21T18:05:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:10:18.000Z", "max_issues_repo_path": "Exercises/Fortran/solutions/mandel_par.f90", "max_issues_repo_name": "zafar-hussain/OmpCommonCore", "max_issues_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-12-09T19:42:54.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T21:27:04.000Z", "max_forks_repo_path": "Exercises/Fortran/solutions/mandel_par.f90", "max_forks_repo_name": "zafar-hussain/OmpCommonCore", "max_forks_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2020-09-05T18:54:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-23T02:19:12.000Z", "avg_line_length": 26.92, "max_line_length": 95, "alphanum_fraction": 0.5999257058, "num_tokens": 822, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632316144274, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.775989838241152}} {"text": "program exo4_2\n \n ! Calculate and print a defined number of the Fibonacci sequence\n implicit none\n integer :: limit, index\n\n write(6, '(a)', advance='no') \"Enter the limit of the Fibonacci sequence: \"\n read(5, '(i3)') limit\n write(6, '(a, i3, a)') 'The first ', limit, ' Fibonacci number(s) are: '\n\n do index = 0, limit-1\n write(6, '(a, i3, a, i3)') 'Fib(', index, ') = ', fibonacci(index)\n end do\n\ncontains\n recursive integer function fibonacci(n) result(fib)\n integer, intent(in) :: n\n if ( n .eq. 0 .or. n .eq. 1 ) then\n fib = 1\n else\n fib = fibonacci(n-2) + fibonacci(n-1)\n end if \n end function fibonacci\n\nend program exo4_2", "meta": {"hexsha": "c94ca357a49bb8253dabbcde7167038a0bf07276", "size": 719, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exo/exo4_2.f90", "max_stars_repo_name": "eusojk/fortran-programs", "max_stars_repo_head_hexsha": "60fe727a341615153e044e7ac7deabc435444e39", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exo/exo4_2.f90", "max_issues_repo_name": "eusojk/fortran-programs", "max_issues_repo_head_hexsha": "60fe727a341615153e044e7ac7deabc435444e39", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exo/exo4_2.f90", "max_forks_repo_name": "eusojk/fortran-programs", "max_forks_repo_head_hexsha": "60fe727a341615153e044e7ac7deabc435444e39", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.76, "max_line_length": 79, "alphanum_fraction": 0.5702364395, "num_tokens": 219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632288833652, "lm_q2_score": 0.8152324983301567, "lm_q1q2_score": 0.7759898381511955}} {"text": "SUBROUTINE ncr(n, r, ncomb, ier)\r\n \r\n! Code converted using TO_F90 by Alan Miller\r\n! Date: 2000-01-20 Time: 18:08:52\r\n\r\n! Calculate the number of different combinations of r objects out of n.\r\n\r\n! ier = 0 if no error is detected\r\n! = 1 if n < 1\r\n! = 2 if r < 0\r\n! = 3 if r > n\r\n! = 4 if nCr > 1.e+308, i.e. if it overflows. In this case, the\r\n! natural log of nCr is returned.\r\n\r\n! Programmer: Alan.Miller @ cmis.csiro.au\r\n! Latest revision - 28 July 1988 (Fortran 77 version)\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n\r\nINTEGER, INTENT(IN) :: n\r\nINTEGER, INTENT(IN) :: r\r\nREAL (dp), INTENT(OUT) :: ncomb\r\nINTEGER, INTENT(OUT) :: ier\r\n\r\nINTEGER :: rr, i, nn\r\n\r\nINTERFACE\r\n FUNCTION lngamma(x) RESULT(fn_val)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n REAL (dp), INTENT(IN) :: x\r\n REAL (dp) :: fn_val\r\n END FUNCTION lngamma\r\nEND INTERFACE\r\n\r\nIF (n < 1) THEN\r\n ier = 1\r\nELSE IF (r < 0) THEN\r\n ier = 2\r\nELSE IF (r > n) THEN\r\n ier = 3\r\nELSE\r\n ier = 0\r\nEND IF\r\nIF (ier /= 0) RETURN\r\n\r\nIF (r <= n-r) THEN\r\n rr = r\r\nELSE\r\n rr = n - r\r\nEND IF\r\n\r\nIF (rr == 0) THEN\r\n ncomb = 1.0_dp\r\n RETURN\r\nEND IF\r\n\r\nIF (rr > 25) THEN\r\n ncomb = lngamma(DBLE(n+1)) - lngamma(DBLE(r+1)) - lngamma(DBLE(n-r+1))\r\n IF (ncomb > 709._dp) THEN\r\n ier = 4\r\n ELSE\r\n ncomb = EXP(ncomb)\r\n END IF\r\n RETURN\r\nEND IF\r\n\r\nncomb = n\r\ni = 1\r\nnn = n\r\nDO\r\n IF (i == rr) RETURN\r\n nn = nn - 1\r\n i = i + 1\r\n ncomb = (ncomb * nn) / REAL(i)\r\nEND DO\r\n\r\nRETURN\r\nEND SUBROUTINE nCr\r\n\r\n\r\n\r\nPROGRAM test_nCr\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n\r\nINTERFACE\r\n SUBROUTINE ncr(n, r, ncomb, ier)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n INTEGER, INTENT(IN) :: n\r\n INTEGER, INTENT(IN) :: r\r\n REAL (dp), INTENT(OUT) :: ncomb\r\n INTEGER, INTENT(OUT) :: ier\r\n END SUBROUTINE ncr\r\nEND INTERFACE\r\n\r\nINTEGER :: n, r, ier\r\nREAL (dp) :: result\r\n\r\nDO\r\n WRITE(*, '(a)', ADVANCE='NO') ' Enter n, r : '\r\n READ(*, *) n, r\r\n CALL nCr(n, r, result, ier)\r\n IF (ier /= 0) THEN\r\n WRITE(*, *) ' Error, IER = ', ier\r\n IF (ier == 4) WRITE(*, '(a, f12.5)') ' Ln(nCr) = ', result\r\n ELSE\r\n WRITE(*, '(a, g16.8)') ' nCr = ', result\r\n END IF\r\nEND DO\r\n\r\nSTOP\r\nEND PROGRAM test_nCr\r\n\r\n\r\n\r\nFUNCTION lngamma(z) RESULT(lanczos)\r\n\r\n! Uses Lanczos-type approximation to ln(gamma) for z > 0.\r\n! Reference:\r\n! Lanczos, C. 'A precision approximation of the gamma\r\n! function', J. SIAM Numer. Anal., B, 1, 86-96, 1964.\r\n! Accuracy: About 14 significant digits except for small regions\r\n! in the vicinity of 1 and 2.\r\n\r\n! Programmer: Alan Miller\r\n! 1 Creswick Street, Brighton, Vic. 3187, Australia\r\n! Latest revision - 14 October 1996\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\nREAL(dp), INTENT(IN) :: z\r\nREAL(dp) :: lanczos\r\n\r\n! Local variables\r\n\r\nREAL(dp) :: a(9) = (/ 0.9999999999995183D0, 676.5203681218835D0, &\r\n -1259.139216722289D0, 771.3234287757674D0, &\r\n -176.6150291498386D0, 12.50734324009056D0, &\r\n -0.1385710331296526D0, 0.9934937113930748D-05, &\r\n 0.1659470187408462D-06 /), zero = 0.D0, &\r\n one = 1.d0, lnsqrt2pi = 0.9189385332046727D0, &\r\n half = 0.5d0, sixpt5 = 6.5d0, seven = 7.d0, tmp\r\nINTEGER :: j\r\n\r\nIF (z <= zero) THEN\r\n WRITE(*, *) 'Error: zero or -ve argument for lngamma'\r\n RETURN\r\nEND IF\r\n\r\nlanczos = zero\r\ntmp = z + seven\r\nDO j = 9, 2, -1\r\n lanczos = lanczos + a(j)/tmp\r\n tmp = tmp - one\r\nEND DO\r\nlanczos = lanczos + a(1)\r\nlanczos = LOG(lanczos) + lnsqrt2pi - (z + sixpt5) + (z - half)*LOG(z + sixpt5)\r\nRETURN\r\n\r\nEND FUNCTION lngamma\r\n\r\n\r\n", "meta": {"hexsha": "e632bd281e20d3c2fa4f1c4a13241dee66a54c35", "size": 3979, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/ncr.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/ncr.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/ncr.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 23.9698795181, "max_line_length": 79, "alphanum_fraction": 0.5518974617, "num_tokens": 1390, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249611, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.7759852456870547}} {"text": "C FILE: MBX_FORTRAN.F90\n\t SUBROUTINE GAUSSIAN(g, h, c_x, c_y, w_x, w_y, s, d)\n\t implicit none\nC\nC Make a gaussian without background\nC\n REAL*8 h, c_x, c_y, w_x, w_y\t\t\t\t\t\t\t\t\t\t! height, center (x and y), and widths\n\t REAL*8 expo\t\t\t\t\t\t\t\t\t\t\t\t\t\t! temporary save location of exponent\n\t INTEGER s, i, j\t\t\t\t\t\t\t\t\t\t\t\t\t! s = roi_size\n REAL*8 g(s*s)\t\t\t\t\t\t\t\t\t\t\t\t\t\t! g = gaussian result\n\t REAL*8 d(9,9)\t\t\t\t\t\t\t\t\t\t\t\t\t\t! d = data = pixel values\nCf2py intent(in) h, c_x, c_y, w_x, w_y, s, d\t\t\t\t\t\t\t! intent(in) means input\nCf2py intent(out) g\t\t\t\t\t\t\t\t\t\t\t\t\t\t! intent(out) means only this will be returned\nCf2py depend(c_x) g\n\t \n do i = 0, s - 1\n do j = 0, s - 1\n\t\t\texpo = h*exp(-(((c_x-i)/w_x)**2+((c_y-j)/w_y)**2)/2)\t\t! calculate exponential\n g(i*s+j+1) = expo-d(i+1,j+1)\t\t\t\t\t\t\t\t! subtract pixel value and store\n enddo\n enddo\n END\n\t \n\t SUBROUTINE GS_BG(g, h, c_x, c_y, w_x, w_y, b, s, d)\n\t implicit none\nC\nC Make a gaussian with background\nC\n REAL*8 h, c_x, c_y, w_x, w_y, b\t\t\t\t\t\t\t\t\t! height, center (x and y), widths, and background\n\t REAL*8 expo\t\t\t\t\t\t\t\t\t\t\t\t\t\t! temporary save location of exponent\n\t INTEGER s, i, j\t\t\t\t\t\t\t\t\t\t\t\t\t! s = roi_size\n REAL*8 g(s*s)\t\t\t\t\t\t\t\t\t\t\t\t\t\t! g = gaussian result\n\t REAL*8 d(9,9)\t\t\t\t\t\t\t\t\t\t\t\t\t\t! d = data = pixel values\nCf2py intent(in) h, c_x, c_y, w_x, w_y, s, d, b\t\t\t\t\t\t\t! intent(in) means input\nCf2py intent(out) g\t\t\t\t\t\t\t\t\t\t\t\t\t\t! intent(out) means only this will be returned\nCf2py depend(c_x) g\n do i = 0, s - 1\n do j = 0, s - 1\n\t\t\texpo = h*exp(-(((c_x-i)/w_x)**2+((c_y-j)/w_y)**2)/2)\t\t! calculate exponential\n g(i*s+j+1) = expo-d(i+1,j+1)+b\t\t\t\t\t\t\t\t! subtract pixel value and add background and store\n enddo\n enddo\n END\n\t \n\t SUBROUTINE DENSE_DIF(dif, x, stp, comp, s, s2, d)\n\t implicit none\nC\nC Dense difference calculation\nC\t \n\t INTEGER s, s2 \t\t\t\t\t\t\t\t\t\t\t\t\t! s = num of params (5 in this case), s2 = ROI size\n\t REAL*8 x(5), stp\t\t\t\t\t\t\t\t\t\t\t\t\t! x = params, stp = EPS^(1/3)\n\t REAL*8 d(9,9)\t\t\t\t\t\t\t\t\t\t\t\t\t\t! d = data = pixel values\n\t REAL*8 dif(s2*s2, 5)\t\t\t\t\t\t\t\t\t\t\t\t! dif = dense difference result\n\t REAL*8 h(5), comp(5)\t\t\t\t\t\t\t\t\t\t\t\t! comp = compare (all ones), h = h values (calculated first)\n\t REAL*8 x1(5), x2(5), dx\t\t\t\t\t\t\t\t\t\t\t! other params and difference\n\t REAL*8 f2(s2*s2), f1(s2*s2), df(s2*s2)\t\t\t\t\t\t\t! other function values and difference\n\t INTEGER i\n\t \nCf2py intent(in) x, stp, d, comp, s, s2\nCf2py intent(out) dif\nCf2py depend(x) dif\t \n\t \n\t h = ABS(MAX(comp, x)*stp)\n\t \n\t do i =1, s\t\t\t\t\t\t\t\t\t\t\t\t\t\t! based on scipy.optimize.least_squares (Python)\n x1 = x\n\t\t x1(i) = x1(i) - h(i)\n\t\t x2 = x\n\t\t x2(i) = x2(i) + h(i)\n\t\t dx = 2*h(i)\n\t\t call GAUSSIAN(f1, x1(1), x1(2), x1(3), x1(4), x1(5), s2, d)\n\t\t call GAUSSIAN(f2, x2(1), x2(2), x2(3), x2(4), x2(5), s2, d)\n\t\t df = f2 - f1\n\t\t dif(:,i) = df/dx\n\t enddo\n\t \n\t END\n\t \n\t SUBROUTINE DENSE_DIF_BG(dif, x, stp, comp, s, s2, d)\n\t implicit none\nC\nC Dense difference calculation\nC\t \n\t INTEGER s, s2 \t\t\t\t\t\t\t\t\t\t\t\t\t! s = num of params (6 in this case), s2 = ROI size\n\t REAL*8 x(6), stp\t\t\t\t\t\t\t\t\t\t\t\t\t! x = params, stp = EPS^(1/3)\n\t REAL*8 d(9,9)\t\t\t\t\t\t\t\t\t\t\t\t\t\t! d = data = pixel values\n\t REAL*8 dif(s2*s2, 6)\t\t\t\t\t\t\t\t\t\t\t\t! dif = dense difference result\n\t REAL*8 h(6), comp(6)\t\t\t\t\t\t\t\t\t\t\t\t! comp = compare (all ones), h = h values (calculated first)\n\t REAL*8 x1(6), x2(6), dx\t\t\t\t\t\t\t\t\t\t\t! other params and difference\n\t REAL*8 f2(s2*s2), f1(s2*s2), df(s2*s2)\t\t\t\t\t\t\t! other function values and difference\n\t INTEGER i\n\t \nCf2py intent(in) x, stp, d, comp\nCf2py intent(out) dif\nCf2py depend(x) dif\t \n\t \n\t h = ABS(MAX(comp, x)*stp)\n\t \n\t do i =1, s\t\t\t\t\t\t\t\t\t\t\t\t\t\t! based on scipy.optimize.least_squares (Python)\n x1 = x\n\t\t x1(i) = x1(i) - h(i)\n\t\t x2 = x\n\t\t x2(i) = x2(i) + h(i)\n\t\t dx = 2*h(i)\n\t\t call GS_BG(f1, x1(1), x1(2), x1(3), x1(4), x1(5), x1(6), s2, d)\n\t\t call GS_BG(f2, x2(1), x2(2), x2(3), x2(4), x2(5), x2(6), s2, d)\n\t\t df = f2 - f1\n\t\t dif(:,i) = df/dx\n\t enddo\n\t \n\t END\n\t \n\t SUBROUTINE GAUSSIAN7(g, h, c_x, c_y, w_x, w_y, s, d)\n\t implicit none\nC\nC Make a gaussian without background, ROI7\nC\n REAL*8 h, c_x, c_y, w_x, w_y\t\t\t\t\t\t\t\t\t\t! height, center (x and y), and widths\n\t REAL*8 expo\t\t\t\t\t\t\t\t\t\t\t\t\t\t! temporary save location of exponent\n\t INTEGER s, i, j\t\t\t\t\t\t\t\t\t\t\t\t\t! s = roi_size\n REAL*8 g(s*s)\t\t\t\t\t\t\t\t\t\t\t\t\t\t! g = gaussian result\n\t REAL*8 d(7,7)\t\t\t\t\t\t\t\t\t\t\t\t\t\t! d = data = pixel values\nCf2py intent(in) h, c_x, c_y, w_x, w_y, s, d\t\t\t\t\t\t\t! intent(in) means input\nCf2py intent(out) g\t\t\t\t\t\t\t\t\t\t\t\t\t\t! intent(out) means only this will be returned\nCf2py depend(c_x) g\n\t \n do i = 0, s - 1\n do j = 0, s - 1\n\t\t\texpo = h*exp(-(((c_x-i)/w_x)**2+((c_y-j)/w_y)**2)/2)\t\t! calculate exponential\n g(i*s+j+1) = expo-d(i+1,j+1)\t\t\t\t\t\t\t\t! subtract pixel value and store\n enddo\n enddo\n END\n\t \n\t SUBROUTINE GS_BG7(g, h, c_x, c_y, w_x, w_y, b, s, d)\n\t implicit none\nC\nC Make a gaussian with background\nC\n REAL*8 h, c_x, c_y, w_x, w_y, b\t\t\t\t\t\t\t\t\t! height, center (x and y), widths, and background\n\t REAL*8 expo\t\t\t\t\t\t\t\t\t\t\t\t\t\t! temporary save location of exponent\n\t INTEGER s, i, j\t\t\t\t\t\t\t\t\t\t\t\t\t! s = roi_size\n REAL*8 g(s*s)\t\t\t\t\t\t\t\t\t\t\t\t\t\t! g = gaussian result\n\t REAL*8 d(7,7)\t\t\t\t\t\t\t\t\t\t\t\t\t\t! d = data = pixel values\nCf2py intent(in) h, c_x, c_y, w_x, w_y, s, d, b\t\t\t\t\t\t\t! intent(in) means input\nCf2py intent(out) g\t\t\t\t\t\t\t\t\t\t\t\t\t\t! intent(out) means only this will be returned\nCf2py depend(c_x) g\n do i = 0, s - 1\n do j = 0, s - 1\n\t\t\texpo = h*exp(-(((c_x-i)/w_x)**2+((c_y-j)/w_y)**2)/2)\t\t! calculate exponential\n g(i*s+j+1) = expo-d(i+1,j+1)+b\t\t\t\t\t\t\t\t! subtract pixel value and add background and store\n enddo\n enddo\n END\n\t \n\t SUBROUTINE DENSE_DIF7(dif, x, stp, comp, s, s2, d)\n\t implicit none\nC\nC Dense difference calculation\nC\t \n\t INTEGER s, s2 \t\t\t\t\t\t\t\t\t\t\t\t\t! s = num of params (5 in this case), s2 = ROI size\n\t REAL*8 x(5), stp\t\t\t\t\t\t\t\t\t\t\t\t\t! x = params, stp = EPS^(1/3)\n\t REAL*8 d(7,7)\t\t\t\t\t\t\t\t\t\t\t\t\t\t! d = data = pixel values\n\t REAL*8 dif(s2*s2, 5)\t\t\t\t\t\t\t\t\t\t\t\t! dif = dense difference result\n\t REAL*8 h(5), comp(5)\t\t\t\t\t\t\t\t\t\t\t\t! comp = compare (all ones), h = h values (calculated first)\n\t REAL*8 x1(5), x2(5), dx\t\t\t\t\t\t\t\t\t\t\t! other params and difference\n\t REAL*8 f2(s2*s2), f1(s2*s2), df(s2*s2)\t\t\t\t\t\t\t! other function values and difference\n\t INTEGER i\n\t \nCf2py intent(in) x, stp, d, comp, s, s2\nCf2py intent(out) dif\nCf2py depend(x) dif\t \n\t \n\t h = ABS(MAX(comp, x)*stp)\n\t \n\t do i =1, s\t\t\t\t\t\t\t\t\t\t\t\t\t\t! based on scipy.optimize.least_squares (Python)\n x1 = x\n\t\t x1(i) = x1(i) - h(i)\n\t\t x2 = x\n\t\t x2(i) = x2(i) + h(i)\n\t\t dx = 2*h(i)\n\t\t call GAUSSIAN7(f1, x1(1), x1(2), x1(3), x1(4), x1(5), s2, d)\n\t\t call GAUSSIAN7(f2, x2(1), x2(2), x2(3), x2(4), x2(5), s2, d)\n\t\t df = f2 - f1\n\t\t dif(:,i) = df/dx\n\t enddo\n\t \n\t END\n\t \n\t SUBROUTINE DENSE_DIF_BG7(dif, x, stp, comp, s, s2, d)\n\t implicit none\nC\nC Dense difference calculation\nC\t \n\t INTEGER s, s2 \t\t\t\t\t\t\t\t\t\t\t\t\t! s = num of params (6 in this case), s2 = ROI size\n\t REAL*8 x(6), stp\t\t\t\t\t\t\t\t\t\t\t\t\t! x = params, stp = EPS^(1/3)\n\t REAL*8 d(7,7)\t\t\t\t\t\t\t\t\t\t\t\t\t\t! d = data = pixel values\n\t REAL*8 dif(s2*s2, 6)\t\t\t\t\t\t\t\t\t\t\t\t! dif = dense difference result\n\t REAL*8 h(6), comp(6)\t\t\t\t\t\t\t\t\t\t\t\t! comp = compare (all ones), h = h values (calculated first)\n\t REAL*8 x1(6), x2(6), dx\t\t\t\t\t\t\t\t\t\t\t! other params and difference\n\t REAL*8 f2(s2*s2), f1(s2*s2), df(s2*s2)\t\t\t\t\t\t\t! other function values and difference\n\t INTEGER i\n\t \nCf2py intent(in) x, stp, d, comp\nCf2py intent(out) dif\nCf2py depend(x) dif\t \n\t \n\t h = ABS(MAX(comp, x)*stp)\n\t \n\t do i =1, s\t\t\t\t\t\t\t\t\t\t\t\t\t\t! based on scipy.optimize.least_squares (Python)\n x1 = x\n\t\t x1(i) = x1(i) - h(i)\n\t\t x2 = x\n\t\t x2(i) = x2(i) + h(i)\n\t\t dx = 2*h(i)\n\t\t call GS_BG7(f1, x1(1), x1(2), x1(3), x1(4), x1(5), x1(6), s2, d)\n\t\t call GS_BG7(f2, x2(1), x2(2), x2(3), x2(4), x2(5), x2(6), s2, d)\n\t\t df = f2 - f1\n\t\t dif(:,i) = df/dx\n\t enddo\n\t \n\t END\n\t \t \nC END FILE MBX_FORTRAN.F90", "meta": {"hexsha": "78a4b07cbd56cf8845d797a08cbc6c329d10b88b", "size": 8021, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/MBx_FORTRAN.f90", "max_stars_repo_name": "DionEngels/MBxPython", "max_stars_repo_head_hexsha": "1f1bc7f3be86082a6f3f4dc0eaf162db00061b34", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/MBx_FORTRAN.f90", "max_issues_repo_name": "DionEngels/MBxPython", "max_issues_repo_head_hexsha": "1f1bc7f3be86082a6f3f4dc0eaf162db00061b34", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/MBx_FORTRAN.f90", "max_forks_repo_name": "DionEngels/MBxPython", "max_forks_repo_head_hexsha": "1f1bc7f3be86082a6f3f4dc0eaf162db00061b34", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.8080357143, "max_line_length": 101, "alphanum_fraction": 0.5292357561, "num_tokens": 3081, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037262250327, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7758904931961009}} {"text": "! Number F(46) is the highest allowed for integer(kind=4). The next number,\n! F(47) creates an integer overflow and produces a negative result.\n!\n! To test yourself, get the table of F(i) values from here:\n!\n! https://oeis.org/A000045/b000045.txt\n!\nprogram fibonacci_recursive\n implicit none\n integer :: i\n integer, parameter :: LI = kind(0_8) ! Long integer kind=8\n integer(kind=LI) :: counter = 0_LI\n\n print '(a)', \"Enter index `i` for the Fibonacci sequence\"\n read *, i\n print '(2(a, i0))', \"F(\", i, \") = \", fib_rec(i)\n print '(a, i0, a)', \"F(i) is called \", counter, \" times\"\ncontains\n recursive function fib_rec(i) result(rslt)\n integer :: rslt\n integer, intent(in) :: i\n\n counter = counter + 1_LI\n if (i == 0) then\n rslt = 0\n else if (i == 1) then\n rslt = 1\n else\n rslt = fib_rec(i - 1) + fib_rec(i - 2)\n end if\n return\n end function fib_rec\nend program fibonacci_recursive\n", "meta": {"hexsha": "8188971f20444790ea2764d249b3cf7258b1656e", "size": 1002, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Lecture_04/homework/fibonacci_recursive/fibonacci_recursive.f90", "max_stars_repo_name": "avsukhorukov/TdP2021-22", "max_stars_repo_head_hexsha": "dd3adf2ece93bcd685912614b848c5dddbcdf6de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture_04/homework/fibonacci_recursive/fibonacci_recursive.f90", "max_issues_repo_name": "avsukhorukov/TdP2021-22", "max_issues_repo_head_hexsha": "dd3adf2ece93bcd685912614b848c5dddbcdf6de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture_04/homework/fibonacci_recursive/fibonacci_recursive.f90", "max_forks_repo_name": "avsukhorukov/TdP2021-22", "max_forks_repo_head_hexsha": "dd3adf2ece93bcd685912614b848c5dddbcdf6de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.4705882353, "max_line_length": 76, "alphanum_fraction": 0.5878243513, "num_tokens": 295, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.908617906830944, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.775880413136255}} {"text": " FUNCTION chebev(a,b,c,m,x)\r\n INTEGER m\r\n REAL chebev,a,b,x,c(m)\r\n INTEGER j\r\n REAL d,dd,sv,y,y2\r\n if ((x-a)*(x-b).gt.0.) pause 'x not in range in chebev'\r\n d=0.\r\n dd=0.\r\n y=(2.*x-a-b)/(b-a)\r\n y2=2.*y\r\n do 11 j=m,2,-1\r\n sv=d\r\n d=y2*d-dd+c(j)\r\n dd=sv\r\n11 continue\r\n chebev=y*d-dd+0.5*c(1)\r\n return\r\n END\r\n", "meta": {"hexsha": "ed9e2b853d72c82d91ffd60173bc16d7643f52c7", "size": 398, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/chebev.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/chebev.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/chebev.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.9473684211, "max_line_length": 62, "alphanum_fraction": 0.4195979899, "num_tokens": 149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. Yes\n2. Yes", "lm_q1_score": 0.8615381952105441, "lm_q2_score": 0.9005297787765764, "lm_q1q2_score": 0.7758408003405222}} {"text": "! file tgenbun.f90\n!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 2005 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Fishpack *\n! * *\n! * A Package of Fortran *\n! * *\n! * Subroutines and Example Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams, Paul Swarztrauber and Roland Sweet *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n!\n! Purpose:\n!\n! To illustrate the usage of genbun to solve the equation\n!\n! (1+x)**2*(d/dx)(du/dx) - 2(1+x)(du/dx) + (d/dy)(du/dy)\n!\n! = 3(1+x)**4*sin(y) (1)\n!\n! on the rectangle 0 < x < 1 and -pi < y < pi\n! with the boundary conditions\n!\n! (du/dx)(0,y) = 4sin(y) (2)\n! -pi <= y <= pi\n! u(1,y) = 16sin(y) (3)\n!\n! and with u periodic in y using finite differences on a\n! grid with deltax (= dx) = 1/20 and deltay (= dy) = pi/20.\n! to set up the finite difference equations we define\n! the grid points\n!\n! x(i) = (i-1)dx i=1,2,...,21\n!\n! y(j) = -pi + (j-1)dy j=1,2,...,41\n!\n! and let v(i,j) be an approximation to u(x(i),y(j)).\n! numbering the grid points in this fashion gives the set\n! of unknowns as v(i,j) for i=1,2,...,20 and j=1,2,...,40.\n! hence, in the program m = 20 and n = 40. at the interior\n! grid point (x(i),y(j)), we replace all derivatives in\n! equation (1) by second order central finite differences,\n! multiply by dy**2, and collect coefficients of v(i,j) to\n! get the finite difference equation\n!\n! a(i)v(i-1,j) + b(i)v(i,j) + c(i)v(i+1,j)\n!\n! + v(i,j-1) - 2v(i,j) + v(i,j+1) = f(i,j) (4)\n!\n! where s = (dy/dx)**2, and for i=2,3,...,19\n!\n! a(i) = (1+x(i))**2*s + (1+x(i))*s*dx\n!\n! b(i) = -2(1+x(i))**2*s\n!\n! c(i) = (1+x(i))**2*s - (1+x(i))*s*dx\n!\n! f(i,j) = 3(1+x(i))**4*dy**2*sin(y(j)) for j=1,2,...,40.\n!\n! to obtain equations for i = 1, we replace the\n! derivative in equation (2) by a second order central\n! finite difference approximation, use this equation to\n! eliminate the virtual unknown v(0,j) in equation (4)\n! and arrive at the equation\n!\n! b(1)v(1,j) + c(1)v(2,j) + v(1,j-1) - 2v(1,j) + v(1,j+1)\n!\n! = f(1,j)\n!\n! where\n!\n! b(1) = -2s , c(1) = 2s\n!\n! f(1,j) = (11+8/dx)*dy**2*sin(y(j)), j=1,2,...,40.\n!\n! for completeness, we set a(1) = 0.\n! to obtain equations for i = 20, we incorporate\n! equation (3) into equation (4) by setting\n!\n! v(21,j) = 16sin(y(j))\n!\n! and arrive at the equation\n!\n! a(20)v(19,j) + b(20)v(20,j)\n!\n! + v(20,j-1) - 2v(20,j) + v(20,j+1) = f(20,j)\n!\n! where\n!\n! a(20) = (1+x(20))**2*s + (1+x(20))*s*dx\n!\n! b(20) = -2*(1+x(20))**2*s\n!\n! f(20,j) = (3(1+x(20))**4*dy**2 - 16(1+x(20))**2*s\n! + 16(1+x(20))*s*dx)*sin(y(j))\n!\n! for j=1,2,...,40.\n!\n! for completeness, we set c(20) = 0. hence, in the\n!\n! program mperod = 1.\n!\n! the periodicity condition on u gives the conditions\n!\n! v(i,0) = v(i,40) and v(i,41) = v(i,1) for i=1,2,...,20.\n!\n! hence, in the program nperod = 0.\n!\n! The exact solution to this problem is\n!\n! u(x,y) = ((1+x)**4) * sin(y).\n!\nprogram test_genbun\n\n use fishpack\n\n ! Explicit typing only\n implicit none\n\n ! Dictionary\n integer(ip), parameter :: M = 20, N = 40\n integer(ip), parameter :: mp1 = M + 1, np1 = N + 1\n integer(ip), parameter :: idimf = M + 2\n integer(ip) :: i, j, ierror, mperod, nperod\n real(wp) :: f(idimf,N), x(mp1), y(np1), dx, dy\n real(wp), dimension(M) :: a, b, c\n real(wp), parameter :: ZERO = 0.0_wp, ONE = 1.0_wp, TWO = 2.0_wp\n\n ! Set boundary conditions\n mperod = 1\n nperod = 0\n\n ! Set mesh sizes\n dx = ONE/M\n dy = TWO_PI/N\n\n ! Generate grid points for later use\n do i = 1, mp1\n x(i) = real(i - 1, kind=wp) * dx\n end do\n\n do j = 1, N\n y(j) = -PI + real(j - 1, kind=wp) * dy\n end do\n\n ! Generate coefficients\n block\n real(wp) :: s, t, t2\n\n s = (dy/dx)**2\n do i = 2, M - 1\n t = ONE + x(i)\n t2 = t**2\n a(i) = (t2 + t * dx) * s\n b(i) = -TWO * t2 * s\n c(i) = (t2 - t * dx) * s\n end do\n a(1) = ZERO\n b(1) = -TWO * s\n c(1) = -b(1)\n b(M) = -TWO * s * (ONE + x(M))**2\n a(M) = (-b(M)/TWO) + (ONE + x(M)) * dx * s\n c(M) = ZERO\n end block\n\n ! Generate right hand side\n block\n real(wp) :: s, dy2, t, t2, t4\n real(wp), parameter :: THREE = 3.0_wp, EIGHT = 8.0_wp\n real(wp), parameter :: ELEVEN = 11.0_wp, SIXTEEN = 16.0_wp\n\n s = (dy/dx)**2\n dy2 = dy**2\n do j = 1, N\n do i = 2, M - 1\n f(i, j) = THREE * (ONE + x(i))**4 * dy2 * sin(y(j))\n end do\n end do\n\n t = ONE + x(M)\n t2 = t**2\n t4 = t**4\n do j = 1, N\n f(1,j) = (ELEVEN + EIGHT/dx) * dy2 * sin(y(j))\n f(M,j) = (THREE * t4 * dy2 - SIXTEEN * t2 * s + SIXTEEN * t * s * dx) * sin(y(j))\n end do\n end block\n\n ! Solve real linear system on a centered grid\n call genbun(nperod, N, mperod, M, a, b, c, idimf, f, ierror)\n\n ! Compute discretization error. The exact solution is\n !\n ! u(x, y) = ((1+x)**4) * sin(y)\n block\n real(wp), parameter :: KNOWN_ERROR = 0.964062912725572e-2_wp\n real(wp) :: discretization_error\n real(wp) :: exact_solution(M,N)\n\n do i = 1, M\n do j = 1, N\n exact_solution(i,j) = ((ONE + x(i))**4) * sin(y(j))\n end do\n end do\n\n ! Set discretization error\n discretization_error = maxval(abs(exact_solution - f(:M,:N)))\n\n call check_output('genbun', ierror, KNOWN_ERROR, discretization_error)\n end block\n\nend program test_genbun\n", "meta": {"hexsha": "8da62365d02eec98a2ce03818f55c1bac1eaf3d3", "size": 7911, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/tgenbun.f90", "max_stars_repo_name": "jlokimlin/fishpack", "max_stars_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-03-12T11:31:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T07:58:23.000Z", "max_issues_repo_path": "examples/tgenbun.f90", "max_issues_repo_name": "jlokimlin/fishpack", "max_issues_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-05-07T22:42:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-15T17:44:58.000Z", "max_forks_repo_path": "examples/tgenbun.f90", "max_forks_repo_name": "jlokimlin/fishpack", "max_forks_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-09-07T15:43:32.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-16T21:30:13.000Z", "avg_line_length": 33.5211864407, "max_line_length": 93, "alphanum_fraction": 0.3755530274, "num_tokens": 2404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308091776495, "lm_q2_score": 0.8311430541321951, "lm_q1q2_score": 0.7758145335609978}} {"text": "function true_solution(x, t)\n\n! True solution for the thin film equation,\n! q_t + (qq_xxx)_x = 0.\n\n implicit none\n double precision, intent(in) :: x, t\n double precision :: true_solution\n\n true_solution = exp(-t) * sin(x)\n \nend function true_solution\n", "meta": {"hexsha": "6dd72611437caaa5efe389ff9d2f05cd0221a367", "size": 270, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/1d/Order4Linear/true_solution.f90", "max_stars_repo_name": "claridge/implicit_solvers", "max_stars_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-04-29T00:16:18.000Z", "max_stars_repo_stars_event_max_datetime": "2017-04-29T00:16:18.000Z", "max_issues_repo_path": "applications/1d/Order4Linear/true_solution.f90", "max_issues_repo_name": "claridge/implicit_solvers", "max_issues_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/1d/Order4Linear/true_solution.f90", "max_forks_repo_name": "claridge/implicit_solvers", "max_forks_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.7692307692, "max_line_length": 43, "alphanum_fraction": 0.662962963, "num_tokens": 72, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.7758145324347723}} {"text": "subroutine calculate_face_velocity(u, v, uf, vf, nx, ny, xi, xf)\nuse kind_parameters\nimplicit none\n\ninteger, intent(in):: nx, ny, xi, xf\nreal(kind=dp), intent(in), dimension(nx,xi-1:xf+1):: u, v\nreal(kind=dp), intent(out), dimension(nx-1,xi-1:xf+1):: uf\nreal(kind=dp), intent(out), dimension(nx,xi-1:xf+1):: vf\nreal(kind=dp):: phi\ninteger:: i, j\n\ndo j = xi,xf\n\n do i = 2,nx-2\n\n phi = (u(i,j)-u(i-1,j))/(u(i+1,j) - u(i-1,j))\n uf(i,j) = 0.50d0*(u(i,j)+u(i+1,j))*phi + 0.50d0*(3.0d0*u(i,j)-u(i-1,j))*(1.0d0-phi)\n\n end do\n\nend do\n\ndo j = xi,xf\n\n do i = 2,nx-1\n\n phi = (v(i,j)-v(i,j-1))/(v(i,j+1) - v(i,j-1))\n vf(i,j) = 0.50d0*(v(i,j)+v(i,j+1))*phi + 0.50d0*(3.0d0*v(i,j)-v(i,j-1))*(1.0d0-phi)\n\n end do\n\nend do\n\nif (xf .eq. ny-1) then\n\n do i = 2,nx-1\n\n vf(i,ny-1) = v(i,ny)\n\n end do\n\nend if\n\ncall exchange_data(uf, nx-1, xi, xf)\ncall exchange_data(vf, nx, xi, xf)\n\nend subroutine\n", "meta": {"hexsha": "b907b49e7217f0c3534db87076fe627178803d80", "size": 928, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "calculate_face_velocity.f90", "max_stars_repo_name": "pratanuroy/Multigrid_Cavity", "max_stars_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-11T12:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-11T12:01:52.000Z", "max_issues_repo_path": "calculate_face_velocity.f90", "max_issues_repo_name": "pratanuroy/Multigrid_Cavity", "max_issues_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calculate_face_velocity.f90", "max_forks_repo_name": "pratanuroy/Multigrid_Cavity", "max_forks_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.3333333333, "max_line_length": 91, "alphanum_fraction": 0.5474137931, "num_tokens": 408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172659321807, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7758105366456071}} {"text": "\tsubroutine bilinear(r_pnt1,r_pnt2,r_pnt3,r_pnt4,r_x,r_y,r_h)\n\nc****************************************************************\nc**\nc**\tFILE NAME: bilinear.for\nc**\nc** DATE WRITTEN: 2/16/91\nc**\nc** PROGRAMMER:Scott Hensley\nc**\nc** \tFUNCTIONAL DESCRIPTION:This routine will take four points\nc**\tand do a bilinear interpolation to get the value for a point\nc**\tassumed to lie in the interior of the 4 points.\nc**\nc** ROUTINES CALLED:none\nc** \nc** NOTES: none\nc**\nc** UPDATE LOG:\nc**\nc*****************************************************************\n\n \timplicit none\n\nc\tINPUT VARIABLES:\n\treal r_pnt1(3)\t\t!point in quadrant 1\n\treal r_pnt2(3)\t\t!point in quadrant 2\n\treal r_pnt3(3)\t\t!point in quadrant 3\n\treal r_pnt4(3)\t\t!point in quadrant 4\n\treal r_x\t\t!x coordinate of point\n\treal r_y\t\t!y coordinate of point\n \nc \tOUTPUT VARIABLES:\n real r_h\t\t\t!interpolated vaule\n\nc\tLOCAL VARIABLES:\n real r_t1,r_t2,r_h1b,r_h2b,r_y1b,r_y2b\n real r_diff\n\nc\tDATA STATEMENTS:none\n\nC\tFUNCTION STATEMENTS:none\n\nc \tPROCESSING STEPS:\n\nc\tfirst find interpolation points in x direction\n\n r_diff=(r_pnt2(1)-r_pnt1(1))\n if ( r_diff .ne. 0 ) then\n\t r_t1 = (r_x - r_pnt1(1))/r_diff\n else\n r_t1 = r_pnt1(1)\n endif\n r_diff=(r_pnt4(1)-r_pnt3(1))\n if ( r_diff .ne. 0 ) then\n\t r_t2 = (r_x - r_pnt3(1))/r_diff\n else\n r_t2 = r_pnt4(1)\n endif\n\tr_h1b = (1.-r_t1)*r_pnt1(3) + r_t1*r_pnt2(3)\n\tr_h2b = (1.-r_t2)*r_pnt3(3) + r_t2*r_pnt4(3)\n\nc\tnow interpolate in y direction\n\n\tr_y1b = r_t1*(r_pnt2(2)-r_pnt1(2)) + r_pnt1(2)\n\tr_y2b = r_t2*(r_pnt4(2)-r_pnt3(2)) + r_pnt3(2)\n\n r_diff=r_y2b-r_y1b\n if ( r_diff .ne. 0 ) then\n\t r_h = ((r_h2b-r_h1b)/r_diff)*(r_y-r_y1b) + r_h1b\n else\n r_h = r_y2b\n endif\n end \n", "meta": {"hexsha": "35156e2da485104ff5ff1bd9ba95c68feb7cd425", "size": 1832, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/alos2proc_f/src/bilinear.f", "max_stars_repo_name": "vincentschut/isce2", "max_stars_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_stars_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_stars_count": 1133, "max_stars_repo_stars_event_min_datetime": "2022-01-07T21:24:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T21:33:08.000Z", "max_issues_repo_path": "contrib/alos2proc_f/src/bilinear.f", "max_issues_repo_name": "vincentschut/isce2", "max_issues_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_issues_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_issues_count": 276, "max_issues_repo_issues_event_min_datetime": "2019-02-10T07:18:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:45:55.000Z", "max_forks_repo_path": "contrib/alos2proc_f/src/bilinear.f", "max_forks_repo_name": "vincentschut/isce2", "max_forks_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_forks_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_forks_count": 235, "max_forks_repo_forks_event_min_datetime": "2019-02-10T05:00:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T07:37:24.000Z", "avg_line_length": 24.4266666667, "max_line_length": 66, "alphanum_fraction": 0.576419214, "num_tokens": 677, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009457116781, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7758065093455532}} {"text": "program roots\n!Este programa resuelve las raices de una ecuacion cuadratica de la forma \n!A*x**2 + B*x + C = 0\nimplicit none\n!Declaracion de variables\nreal :: A,B,C,dis1,dis2,discri,real_part,imag_part\n\nwrite (*,*) 'Este programa resuelve para las raices de una cuadratica' \n \nprint *, 'Escribe el valor de A'\nread *, A\n\nprint *, 'Escribe el valor de B'\nread *, B\n\nprint *, 'Escribe el valor de C'\nread *, C\n\ndiscri=B**2-(4.*A*C)\n if (discri>0) then \n dis1= (-b +sqrt(discri))/(2.* A)\n print *, 'El valor de x1 =', dis1 \n dis2= (-b - sqrt(discri))/ (2.* A)\n print *, 'El valor de x2 =', dis2 \n \n else if (discri==0) then\n dis1=-b/(2.*a)\n print *, 'Esta ec. tiene dos raices reales iguales'\n print *, 'x1= x2 ', dis1\n\n else\n real_part = -b/(2.*A)\n imag_part = sqrt (abs(discri))/ (2. *A) \n print *, 'Esta ec. tiene raices complejas:'\n print *, 'x1= ',real_part, ' +i', imag_part\n print *, 'x1= ',real_part, ' -i', imag_part\n\n end if\nend program\n", "meta": {"hexsha": "1cbd91c3a3427bba4d12c341c31eb096e33b5132", "size": 1032, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "roots.f90", "max_stars_repo_name": "Itzel753/prueba", "max_stars_repo_head_hexsha": "a7c81bf96ac156f8888d46e131e4885fe6b606c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "roots.f90", "max_issues_repo_name": "Itzel753/prueba", "max_issues_repo_head_hexsha": "a7c81bf96ac156f8888d46e131e4885fe6b606c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "roots.f90", "max_forks_repo_name": "Itzel753/prueba", "max_forks_repo_head_hexsha": "a7c81bf96ac156f8888d46e131e4885fe6b606c9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.8, "max_line_length": 74, "alphanum_fraction": 0.5794573643, "num_tokens": 347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9658995782141545, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.7757852243078001}} {"text": "PROGRAM Assignment0\nIMPLICIT NONE\n\nREAL, Dimension(:), Allocatable:: X, V, T\nREAL:: h, dvdt, dxdt, XMid, Vmid, dxdtMid, dvdtmid, Tmid\nINTEGER:: i, npts\n\n!This program uses the modified euler method to numerically iterate an ODE between r=0 and t=50\n!The ODES model a mass m attached to a spring. The program calculates m's x position and velocity\n!It does this in 5E-3 steps of time and plots 10001 steps to a file called results.dat\n\nnpts=10001\n\nAllocate(T(0:npts), X(0:npts), V(0:npts))!Creating arrays to store the data\n\nX(0)=0; V(0)=2.0; T(0)=0; h=5.0E-3 !Setting intial boundary conditions\n\nOPEN(10, FILE='Results.dat')\n\nWRITE(10,*) 'set xrange [0:50.006]' !Limiting X axis to only required values, as it auto plots to 60s, leaving a lot of white space\nWRITE(10,*) 'set xlabel \"Time (s)\"' !Labelling X axis\nWRITE(10,*) 'p ''Results.dat'' u 1:2 w l t \"X Position\", '''' u 1:3 w l t \"Velocity\"' !Command plots time vs x and time vs v when file is loaded in gnuplot \n\nDO i=1,npts \n \n dxdt = v(i-1) !dxdt is the velocity of V at that point\n dvdt = -5.0*(x(i-1))+0.5*Cos(2*T(i-1)) !dvdt the velocity acceleration at that point\n \n XMid = x(i-1) + 0.5*h*dxdt !X mid = previous X value + half interval * velocity at the starting point\n VMid = V(i-1) + 0.5*h*dvdt !V mid = previous v value + half interval * acceleration at the starting point\n\n dxdtmid = VMid !gradient at X mid = V mid\n X(i) = X(i-1)+h*dxdtMid !Final X = X in the middle + interval * gradient at mid point\n Tmid = T(i-1)+0.5*h !Tmid is previous T + half interval\n dvdtMid = -5.0*XMid+0.5*Cos(2*Tmid) !Acceleration at mid point, means the use of X mid and T mid\n\n V(i) = V(i-1)+h*dvdtmid !Final V= previous V + interval * acceleration at mid point\n T(i) = T(i-1)+h !Final T is T plus interval\n\n WRITE(6,'(f6.3, f9.5, f9.5)') T(i), X(i), V(i) !Prints results to screen\n WRITE(10,'(f6.3, f9.5, f9.5)') T(i), X(i), V(i) !Prints results to file\n\nEND DO\n\nCLOSE(10)\n\nWRITE(6,*) 'Results written to file: ''Results.dat''. '\nWRITE(6,*) 'Results are recorded in three columns, in the order of Time, X value then Velocity'\n\nDEALLOCATE(T, X, V)\n\nEND PROGRAM \n", "meta": {"hexsha": "7b3230d37084a974a3554e5fcfd6123395362cd5", "size": 2331, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Modified Euler Spring/Modified Euler Spring.f90", "max_stars_repo_name": "DGrifferty/Fortran", "max_stars_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Modified Euler Spring/Modified Euler Spring.f90", "max_issues_repo_name": "DGrifferty/Fortran", "max_issues_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modified Euler Spring/Modified Euler Spring.f90", "max_forks_repo_name": "DGrifferty/Fortran", "max_forks_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.9811320755, "max_line_length": 211, "alphanum_fraction": 0.6173316173, "num_tokens": 757, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129328, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.7756702616996063}} {"text": "module loehner_mod\n\nuse constants_mod\n\ninterface calc_loehner\n procedure calc_loehner_1d\n procedure calc_loehner_2d\n procedure calc_loehner_3d\nend interface\n\nreal(dp), parameter :: eps = 0.01_dp\n\ncontains\n\npure function calc_loehner_1d(u) result(r)\n\n real(dp), intent(in) :: u(N_NODES)\n real(dp) :: r\n\n integer :: i\n\n real(dp) :: xtemp(2:N_NODES-1)\n\n do i = 2,N_NODES-1\n xtemp(i) = abs(u(i-1) - 2.0_dp*u(i) + u(i+1)) / &\n (abs(u(i+1)-u(i)) + abs(u(i)-u(i-1)) + &\n eps*(abs(u(i+1)) + 2.0_dp*abs(u(i)) + abs(u(i-1))))\n end do\n\n r = maxval(xtemp)\n\nend function\n\npure function calc_loehner_2d(u) result(r)\n\n real(dp), intent(in) :: u(N_NODES,N_NODES)\n real(dp) :: r\n\n integer :: i,j\n\n real(dp) :: xtemp(2:N_NODES-1,1:N_NODES)\n real(dp) :: ytemp(1:N_NODES,2:N_NODES-1)\n\n do j = 1,N_NODES; do i = 2,N_NODES-1;\n xtemp(i,j) = abs(u(i-1,j) - 2.0_dp*u(i,j) + u(i+1,j)) / &\n (abs(u(i+1,j)-u(i,j)) + abs(u(i,j)-u(i-1,j)) + &\n eps*(abs(u(i+1,j)) + 2.0_dp*abs(u(i,j)) + abs(u(i-1,j))))\n end do; end do;\n\n do j = 2,N_NODES-1; do i = 1,N_NODES;\n ytemp(i,j) = abs(u(i,j-1) - 2.0_dp*u(i,j) + u(i,j+1)) / &\n (abs(u(i,j+1)-u(i,j)) + abs(u(i,j)-u(i,j-1)) + &\n eps*(abs(u(i,j+1)) + 2.0_dp*abs(u(i,j)) + abs(u(i,j-1))))\n end do; end do;\n\n r = max(maxval(xtemp),maxval(ytemp))\n\nend function\n\npure function calc_loehner_3d(u) result(r)\n\n real(dp), intent(in) :: u(N_NODES,N_NODES,N_NODES)\n real(dp) :: r\n\n integer :: i,j,k\n\n real(dp) :: xtemp(2:N_NODES-1,1:N_NODES,1:N_NODES)\n real(dp) :: ytemp(1:N_NODES,2:N_NODES-1,1:N_NODES)\n real(dp) :: ztemp(1:N_NODES,1:N_NODES,2:N_NODES-1)\n\n do k = 1,N_NODES; do j = 1,N_NODES; do i = 2,N_NODES-1;\n xtemp(i,j,k) = abs(u(i-1,j,k) - 2.0_dp*u(i,j,k) + u(i+1,j,k)) / &\n (abs(u(i+1,j,k)-u(i,j,k)) + abs(u(i,j,k)-u(i-1,j,k)) + &\n eps*(abs(u(i+1,j,k)) + 2.0_dp*abs(u(i,j,k)) + abs(u(i-1,j,k))))\n end do; end do; end do;\n\n do k = 1,N_NODES; do j = 2,N_NODES-1; do i = 1,N_NODES;\n ytemp(i,j,k) = abs(u(i,j-1,k) - 2.0_dp*u(i,j,k) + u(i,j+1,k)) / &\n (abs(u(i,j+1,k)-u(i,j,k)) + abs(u(i,j,k)-u(i,j-1,k)) + &\n eps*(abs(u(i,j+1,k)) + 2.0_dp*abs(u(i,j,k)) + abs(u(i,j-1,k))))\n end do; end do; end do;\n\n do k = 2,N_NODES-1; do j = 1,N_NODES; do i = 1,N_NODES;\n ztemp(i,j,k) = abs(u(i,j,k-1) - 2.0_dp*u(i,j,k) + u(i,j,k+1)) / &\n (abs(u(i,j,k+1)-u(i,j,k)) + abs(u(i,j,k)-u(i,j,k-1)) + &\n eps*(abs(u(i,j,k+1)) + 2.0_dp*abs(u(i,j,k)) + abs(u(i,j,k-1))))\n end do; end do; end do;\n\n r = max(maxval(xtemp),maxval(ytemp),maxval(ztemp))\n\nend function\n\n!! Some experimental stuff.\n!! pure function calc_loehner(u)\n!! \n!! real(dp), intent(in) :: u(N_NODES,N_NODES)\n!! real(dp) :: calc_loehner\n!! \n!! real(dp), parameter :: eps = 0.2_dp\n!! \n!! real(dp) :: stencil(-1:1,-1:1)\n!! real(dp) :: xtemp(-1:1)\n!! real(dp) :: ytemp(-1:1)\n!! \n!! integer :: i,j\n!! \n!! stencil = matmul(fv8fv3Mat,matmul(u,fv8fv3Tam))\n!! \n!! forall (j = -1:1)\n!! xtemp(j) = abs(stencil(-1,j) - 2.0_dp*stencil(0,j) + stencil(1,j)) / &\n!! (abs(stencil(1,j)-stencil(0,j)) + abs(stencil(0,j)-stencil(-1,j)) + &\n!! eps*(abs(stencil(1,j)) + 2.0_dp*abs(stencil(0,j)) + abs(stencil(-1,j))))\n!! end forall\n!! \n!! forall (i = -1:1)\n!! ytemp(i) = abs(stencil(i,-1) - 2.0_dp*stencil(i,0) + stencil(i,1)) / &\n!! (abs(stencil(i,1)-stencil(i,0)) + abs(stencil(i,0)-stencil(i,-1)) + &\n!! eps*(abs(stencil(i,1)) + 2.0_dp*abs(stencil(i,0)) + abs(stencil(i,-1))))\n!! end forall\n!! \n!! ! calc_loehner = max(maxval(xtemp),maxval(ytemp))\n!! calc_loehner = max(sum(xtemp)/3,sum(ytemp)/3)\n!! \n!! end function\n\n\nend module\n", "meta": {"hexsha": "0a5f07afb1869cbc0aedd6b7b26e9038067b3b22", "size": 3935, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/utils/loehner_mod.f90", "max_stars_repo_name": "jmark/nemo", "max_stars_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/utils/loehner_mod.f90", "max_issues_repo_name": "jmark/nemo", "max_issues_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/utils/loehner_mod.f90", "max_forks_repo_name": "jmark/nemo", "max_forks_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.7421875, "max_line_length": 92, "alphanum_fraction": 0.5041931385, "num_tokens": 1523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.93812402119614, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.7755581946264982}} {"text": "\nsubmodule(forlab_math) forlab_math_angle\n implicit none\ncontains\n\n pure module function angle_2_sp(x, y) result(angle)\n real(sp), dimension(3), intent(in) :: x, y\n real(sp) :: angle\n\n angle = acos(dot_product(x, y)/(norm2(x)*norm2(y)))\n\n end function angle_2_sp\n pure module function angle_2_dp(x, y) result(angle)\n real(dp), dimension(3), intent(in) :: x, y\n real(dp) :: angle\n\n angle = acos(dot_product(x, y)/(norm2(x)*norm2(y)))\n\n end function angle_2_dp\n\nend submodule forlab_math_angle\n", "meta": {"hexsha": "04ba5685062d88d26a889b1a8dc1b40a132548dd", "size": 549, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_math_angle.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "src/forlab_math_angle.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "src/forlab_math_angle.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 24.9545454545, "max_line_length": 59, "alphanum_fraction": 0.6411657559, "num_tokens": 153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.865224073888819, "lm_q1q2_score": 0.7754582642911189}} {"text": " program numintgrl1\r\n implicit none\r\n integer , parameter :: rp = selected_real_kind(15)\r\n real (kind = rp) :: sum = 0.0_rp\r\n integer :: i, n\r\n real (kind = rp) :: a, b, deltaX \r\n real (kind = rp) :: x_i = 0.0_rp\r\n write (*,*) 'input the lower bound'\r\n read (*,*) a\r\n write (*,*) 'input the upper bound'\r\n read (*,*) b\r\n write (*,*) 'input the number of sections in the approx.'\r\n read (*,*) n\r\n deltaX = (b-a)/n\r\n do i = 1, n, 1\r\n x_i = a + i * deltaX \r\n!Right Riemann sum \r\n sum = sum + ((x_i ** 3)/2 * deltaX)\r\n end do\r\n print *, sum\r\n end program numintgrl1\r\n\r\n\r\n\r\n! compile attempt (for l8r): \r\nC $ cd \\R:\r\n\r\nC Kenneth Collins@DESKTOP-7A1A76L /cygdrive/r\r\nC $ pwd\r\nC /cygdrive/r\r\n\r\nC Kenneth Collins@DESKTOP-7A1A76L /cygdrive/r\r\nC $ gfortran R:/Fortran_wd/practiceNumIntegral1-09-12-18.f -o practiceNumIntegral1-09-12-18.exe\r\n", "meta": {"hexsha": "e0159150be7c9a52e3a2fe9154b9df54b5ee8a82", "size": 942, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "practiceNumIntegral1-09-12-18.f", "max_stars_repo_name": "DU-ds/Fortran", "max_stars_repo_head_hexsha": "7145bb0fa1a863e3c0800355767896ee6dc54e19", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "practiceNumIntegral1-09-12-18.f", "max_issues_repo_name": "DU-ds/Fortran", "max_issues_repo_head_hexsha": "7145bb0fa1a863e3c0800355767896ee6dc54e19", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "practiceNumIntegral1-09-12-18.f", "max_forks_repo_name": "DU-ds/Fortran", "max_forks_repo_head_hexsha": "7145bb0fa1a863e3c0800355767896ee6dc54e19", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.7058823529, "max_line_length": 96, "alphanum_fraction": 0.5445859873, "num_tokens": 314, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660962919971, "lm_q2_score": 0.8128673201042493, "lm_q1q2_score": 0.775447864163188}} {"text": "c\r\nc GCVSPL.FOR, 1986-05-12\r\nc (C) COPYRIGHT 1985, 1986: H.J. Woltring\r\nc This software is copyrighted, and may be copied for exercise,\r\nc study and use without authorization from the copyright owner(s), in\r\nc compliance with paragraph 16b of the Dutch Copyright Act of 1912\r\nc (\"Auteurswet 1912\"). Within the constraints of this legislation, all\r\nc forms of academic and research-oriented excercise, study, and use are\r\nc allowed, including any necessary modifications. Copying and use as\r\nc object for commercial exploitation are not allowed without permission\r\nc of the copyright owners, including those upon whose work the package\r\nc is based.\r\nc\r\nc Code initially published in:\r\nc Woltring, 1986, A FORTRAN package for generalized, cross-validatory spline smoothing and differentiation. Adv. Eng. Softw. 8:104-113. \r\nc ####\r\nc Note of Charles Le Losq: \r\nc Code available on www.netlib.org, other versions are available on https://isbweb.org/software/sigproc.html\r\nc This is a Fortran 77 version downloaded on https://isbweb.org/software/sigproc.html\r\nc***********************************************************************\r\nc\r\nc SUBROUTINE GCVSPL (REAL*8)\r\nc\r\nc Purpose:\r\nc *******\r\nc\r\nc Natural B-spline data smoothing subroutine, using the Generali-\r\nc zed Cross-Validation and Mean-Squared Prediction Error Criteria\r\nc of Craven & Wahba (1979). Alternatively, the amount of smoothing\r\nc can be given explicitly, or it can be based on the effective\r\nc number of degrees of freedom in the smoothing process as defined\r\nc by Wahba (1980). The model assumes uncorrelated, additive noise\r\nc and essentially smooth, underlying functions. The noise may be\r\nc non-stationary, and the independent co-ordinates may be spaced\r\nc non-equidistantly. Multiple datasets, with common independent\r\nc variables and weight factors are accomodated.\r\nc\r\nc\r\nc Calling convention:\r\nc ******************\r\nc\r\nc CALL GCVSPL ( X, Y, NY, WX, WY, M, N, K, MD, VAL, C, NC, WK, IER\r\nc )\r\nc\r\nc Meaning of parameters:\r\nc *********************\r\nc\r\nc X(N) ( I ) Independent variables: strictly increasing knot\r\nc sequence, with X(I-1).lt.X(I), I=2,...,N.\r\nc Y(NY,K) ( I ) Input data to be smoothed (or interpolated).\r\nc NY ( I ) First dimension of array Y(NY,K), with NY.ge.N.\r\nc WX(N) ( I ) Weight factor array; WX(I) corresponds with\r\nc the relative inverse variance of point Y(I,*).\r\nc If no relative weighting information is\r\nc available, the WX(I) should be set to ONE.\r\nc All WX(I).gt.ZERO, I=1,...,N.\r\nc WY(K) ( I ) Weight factor array; WY(J) corresponds with\r\nc the relative inverse variance of point Y(*,J).\r\nc If no relative weighting information is\r\nc available, the WY(J) should be set to ONE.\r\nc All WY(J).gt.ZERO, J=1,...,K.\r\nc NB: The effective weight for point Y(I,J) is\r\nc equal to WX(I)*WY(J).\r\nc M ( I ) Half order of the required B-splines (spline\r\nc degree 2*M-1), with M.gt.0. The values M =\r\nc 1,2,3,4 correspond to linear, cubic, quintic,\r\nc and heptic splines, respectively.\r\nc N ( I ) Number of observations per dataset, with N.ge.2*\r\ncM.\r\nc K ( I ) Number of datasets, with K.ge.1.\r\nc MD ( I ) Optimization mode switch:\r\nc |MD| = 1: Prior given value for p in VAL\r\nc (VAL.ge.ZERO). This is the fastest\r\nc use of GCVSPL, since no iteration\r\nc is performed in p.\r\nc |MD| = 2: Generalized cross validation.\r\nc |MD| = 3: True predicted mean-squared error,\r\nc with prior given variance in VAL.\r\nc |MD| = 4: Prior given number of degrees of\r\nc freedom in VAL (ZERO.le.VAL.le.N-M).\r\nc MD < 0: It is assumed that the contents of\r\nc X, W, M, N, and WK have not been\r\nc modified since the previous invoca-\r\nc tion of GCVSPL. If MD < -1, WK(4)\r\nc is used as an initial estimate for\r\nc the smoothing parameter p. At the\r\nc first call to GCVSPL, MD must be > 0.\r\nc Other values for |MD|, and inappropriate values\r\nc for VAL will result in an error condition, or\r\nc cause a default value for VAL to be selected.\r\nc After return from MD.ne.1, the same number of\r\nc degrees of freedom can be obtained, for identica\r\ncl\r\nc weight factors and knot positions, by selecting\r\nc |MD|=1, and by copying the value of p from WK(4)\r\nc into VAL. In this way, no iterative optimization\r\nc is required when processing other data in Y.\r\nc VAL ( I ) Mode value, as described above under MD.\r\nc C(NC,K) ( O ) Spline coefficients, to be used in conjunction\r\nc with function SPLDER. NB: the dimensions of C\r\nc in GCVSPL and in SPLDER are different! In SPLDER\r\nc,\r\nc only a single column of C(N,K) is needed, and th\r\nce\r\nc proper column C(1,J), with J=1...K should be use\r\ncd\r\nc when calling SPLDER.\r\nc NC ( I ) First dimension of array C(NC,K), NC.ge.N.\r\nc WK(IWK) (I/W/O) Work vector, with length IWK.ge.6*(N*M+1)+N.\r\nc On normal exit, the first 6 values of WK are\r\nc assigned as follows:\r\nc\r\nc WK(1) = Generalized Cross Validation value\r\nc WK(2) = Mean Squared Residual.\r\nc WK(3) = Estimate of the number of degrees of\r\nc freedom of the residual sum of squares\r\nc per dataset, with 0.lt.WK(3).lt.N-M.\r\nc WK(4) = Smoothing parameter p, multiplicative\r\nc with the splines' derivative constraint.\r\nc WK(5) = Estimate of the true mean squared error\r\nc (different formula for |MD| = 3).\r\nc WK(6) = Gauss-Markov error variance.\r\nc\r\nc If WK(4) --> 0 , WK(3) --> 0 , and an inter-\r\nc polating spline is fitted to the data (p --> 0).\r\nc A very small value > 0 is used for p, in order\r\nc to avoid division by zero in the GCV function.\r\nc\r\nc If WK(4) --> inf, WK(3) --> N-M, and a least-\r\nc squares polynomial of order M (degree M-1) is\r\nc fitted to the data (p --> inf). For numerical\r\nc reasons, a very high value is used for p.\r\nc\r\nc Upon return, the contents of WK can be used for\r\nc covariance propagation in terms of the matrices\r\nc B and WE: see the source listings. The variance\r\nc estimate for dataset J follows as WK(6)/WY(J).\r\nc\r\nc IER ( O ) Error parameter:\r\nc\r\nc IER = 0: Normal exit\r\nc IER = 1: M.le.0 .or. N.lt.2*M\r\nc IER = 2: Knot sequence is not strictly\r\nc increasing, or some weight\r\nc factor is not positive.\r\nc IER = 3: Wrong mode parameter or value.\r\nc\r\nc Remarks:\r\nc *******\r\nc\r\nc (1) GCVSPL calculates a natural spline of order 2*M (degree\r\nc 2*M-1) which smoothes or interpolates a given set of data\r\nc points, using statistical considerations to determine the\r\nc amount of smoothing required (Craven & Wahba, 1979). If the\r\nc error variance is a priori known, it should be supplied to\r\nc the routine in VAL, for |MD|=3. The degree of smoothing is\r\nc then determined to minimize an unbiased estimate of the true\r\nc mean squared error. On the other hand, if the error variance\r\nc is not known, one may select |MD|=2. The routine then deter-\r\nc mines the degree of smoothing to minimize the generalized\r\nc cross validation function. This is asymptotically the same\r\nc as minimizing the true predicted mean squared error (Craven &\r\nc Wahba, 1979). If the estimates from |MD|=2 or 3 do not appear\r\nc suitable to the user (as apparent from the smoothness of the\r\nc M-th derivative or from the effective number of degrees of\r\nc freedom returned in WK(3) ), the user may select an other\r\nc value for the noise variance if |MD|=3, or a reasonably large\r\nc number of degrees of freedom if |MD|=4. If |MD|=1, the proce-\r\nc dure is non-iterative, and returns a spline for the given\r\nc value of the smoothing parameter p as entered in VAL.\r\nc\r\nc (2) The number of arithmetic operations and the amount of\r\nc storage required are both proportional to N, so very large\r\nc datasets may be accomodated. The data points do not have\r\nc to be equidistant in the independant variable X or uniformly\r\nc weighted in the dependant variable Y. However, the data\r\nc points in X must be strictly increasing. Multiple dataset\r\nc processing (K.gt.1) is numerically more efficient dan\r\nc separate processing of the individual datasets (K.eq.1).\r\nc\r\nc (3) If |MD|=3 (a priori known noise variance), any value of\r\nc N.ge.2*M is acceptable. However, it is advisable for N-2*M\r\nc be rather large (at least 20) if |MD|=2 (GCV).\r\nc\r\nc (4) For |MD| > 1, GCVSPL tries to iteratively minimize the\r\nc selected criterion function. This minimum is unique for |MD|\r\nc = 4, but not necessarily for |MD| = 2 or 3. Consequently,\r\nc local optima rather that the global optimum might be found,\r\nc and some actual findings suggest that local optima might\r\nc yield more meaningful results than the global optimum if N\r\nc is small. Therefore, the user has some control over the\r\nc search procedure. If MD > 1, the iterative search starts\r\nc from a value which yields a number of degrees of freedom\r\nc which is approximately equal to N/2, until the first (local)\r\nc minimum is found via a golden section search procedure\r\nc (Utreras, 1980). If MD < -1, the value for p contained in\r\nc WK(4) is used instead. Thus, if MD = 2 or 3 yield too noisy\r\nc an estimate, the user might try |MD| = 1 or 4, for suitably\r\nc selected values for p or for the number of degrees of\r\nc freedom, and then run GCVSPL with MD = -2 or -3. The con-\r\nc tents of N, M, K, X, WX, WY, and WK are assumed unchanged\r\nc since the last call to GCVSPL if MD < 0.\r\nc\r\nc (5) GCVSPL calculates the spline coefficient array C(N,K);\r\nc this array can be used to calculate the spline function\r\nc value and any of its derivatives up to the degree 2*M-1\r\nc at any argument T within the knot range, using subrou-\r\nc tines SPLDER and SEARCH, and the knot array X(N). Since\r\nc the splines are constrained at their Mth derivative, only\r\nc the lower spline derivatives will tend to be reliable\r\nc estimates of the underlying, true signal derivatives.\r\nc\r\nc (6) GCVSPL combines elements of subroutine CRVO5 by Utre-\r\nc ras (1980), subroutine SMOOTH by Lyche et al. (1983), and\r\nc subroutine CUBGCV by Hutchinson (1985). The trace of the\r\nc influence matrix is assessed in a similar way as described\r\nc by Hutchinson & de Hoog (1985). The major difference is\r\nc that the present approach utilizes non-symmetrical B-spline\r\nc design matrices as described by Lyche et al. (1983); there-\r\nc fore, the original algorithm by Erisman & Tinney (1975) has\r\nc been used, rather than the symmetrical version adopted by\r\nc Hutchinson & de Hoog.\r\nc\r\nc References:\r\nc **********\r\nc\r\nc P. Craven & G. Wahba (1979), Smoothing noisy data with\r\nc spline functions. Numerische Mathematik 31, 377-403.\r\nc\r\nc A.M. Erisman & W.F. Tinney (1975), On computing certain\r\nc elements of the inverse of a sparse matrix. Communications\r\nc of the ACM 18(3), 177-179.\r\nc\r\nc M.F. Hutchinson & F.R. de Hoog (1985), Smoothing noisy data\r\nc with spline functions. Numerische Mathematik 47(1), 99-106.\r\nc\r\nc M.F. Hutchinson (1985), Subroutine CUBGCV. CSIRO Division of\r\nc Mathematics and Statistics, P.O. Box 1965, Canberra, ACT 2601,\r\nc Australia.\r\nc\r\nc T. Lyche, L.L. Schumaker, & K. Sepehrnoori (1983), Fortran\r\nc subroutines for computing smoothing and interpolating natural\r\nc splines. Advances in Engineering Software 5(1), 2-5.\r\nc\r\nc F. Utreras (1980), Un paquete de programas para ajustar curvas\r\nc mediante funciones spline. Informe Tecnico MA-80-B-209, Depar-\r\nc tamento de Matematicas, Faculdad de Ciencias Fisicas y Matema-\r\nc ticas, Universidad de Chile, Santiago.\r\nc\r\nc Wahba, G. (1980). Numerical and statistical methods for mildly,\r\nc moderately and severely ill-posed problems with noisy data.\r\nc Technical report nr. 595 (February 1980). Department of Statis-\r\nc tics, University of Madison (WI), U.S.A.\r\nc\r\nc Subprograms required:\r\nc ********************\r\nc\r\nc BASIS, PREP, SPLC, BANDET, BANSOL, TRINV\r\nc\r\nc***********************************************************************\r\nc\r\nc\r\n subroutine gcvspl(x, y, ny, wx, wy, m, n, k, md, val, c, nc, wk, \r\n &ier)\r\n implicit double precision (o-z, a-h)\r\n parameter (ratio = 2d0, tau = 1.618033983d0, ibwe = 7, zero = 0d0\r\n &, half = 5d-1, one = 1d0, tol = 1d-6, eps = 1d-15, epsinv = one / \r\n &eps)\r\n dimension x(n), y(ny, k), wx(n), wy(k), c(nc, k), wk(n + (6 * ((n\r\n & * m) + 1)))\r\n save el, nm1, m2\r\nc\r\nc*** Parameter check and work array initialization\r\nc\r\nc*** Check on mode parameter\r\n data m2 / 0 /\r\n data nm1 / 0 /\r\n data el / 0d0 /\r\n ier = 0\r\n if (((((iabs(md) .gt. 4) .or. (md .eq. 0)) .or. ((iabs(md) .eq. 1)\r\n & .and. (val .lt. zero))) .or. ((iabs(md) .eq. 3) .and. (val .lt. \r\n &zero))) .or. ((iabs(md) .eq. 4) .and. ((val .lt. zero) .or. (val\r\n & .gt. (n - m))))) then\r\ncWrong mode value \r\n ier = 3\r\n return \r\nc*** Check on M and N\r\n end if\r\n if (md .gt. 0) then\r\n m2 = 2 * m\r\n nm1 = n - 1\r\n else\r\n if ((m2 .ne. (2 * m)) .or. (nm1 .ne. (n - 1))) then\r\ncM or N modified since previous call \r\n ier = 3\r\n return \r\n end if\r\n end if\r\n if ((m .le. 0) .or. (n .lt. m2)) then\r\ncM or N invalid \r\n ier = 1\r\n return \r\nc*** Check on knot sequence and weights\r\n end if\r\n if (wx(1) .le. zero) ier = 2\r\n do 10 i = 2, n\r\n if ((wx(i) .le. zero) .or. (x(i - 1) .ge. x(i))) ier = 2\r\n if (ier .ne. 0) return \r\n 10 continue\r\n do 15 j = 1, k\r\n if (wy(j) .le. zero) ier = 2\r\n if (ier .ne. 0) return \r\nc\r\nc*** Work array parameters (address information for covariance\r\nc*** propagation by means of the matrices STAT, B, and WE). NB:\r\nc*** BWE cannot be used since it is modified by function TRINV.\r\nc\r\n 15 continue\r\n nm2p1 = n * (m2 + 1)\r\nc ISTAT = 1 !Statistics array STAT(6)\r\nc IBWE = ISTAT + 6 !Smoothing matrix BWE( -M:M ,N)\r\n nm2m1 = n * (m2 - 1)\r\ncDesign matrix B (1-M:M-1,N) \r\n ib = ibwe + nm2p1\r\nc IWK = IWE + NM2P1 !Total work array length N + 6*(N*M+1)\r\nc\r\nc*** Compute the design matrices B and WE, the ratio\r\nc*** of their L1-norms, and check for iterative mode.\r\nc\r\ncDesign matrix WE ( -M:M ,N) \r\n iwe = ib + nm2m1\r\n if (md .gt. 0) then\r\n call basis(m, n, x, wk(ib), r1, wk(ibwe))\r\n call prep(m, n, x, wx, wk(iwe), el)\r\ncL1-norms ratio (SAVEd upon RETURN) \r\n el = el / r1\r\n end if\r\nc*** Prior given value for p\r\n if (iabs(md) .ne. 1) goto 20\r\n r1 = val\r\nc\r\nc*** Iterate to minimize the GCV function (|MD|=2),\r\nc*** the MSE function (|MD|=3), or to obtain the prior\r\nc*** given number of degrees of freedom (|MD|=4).\r\nc\r\n goto 100\r\n 20 if (md .lt. (-1)) then\r\ncUser-determined starting value \r\n r1 = wk(4)\r\n else\r\ncDefault (DOF ~ 0.5) \r\n r1 = one / el\r\n end if\r\n r2 = r1 * ratio\r\n gf2 = splc(m,n,k,y,ny,wx,wy,md,val,r2,eps,c,nc,wk,wk(ib),wk(iwe),\r\n &el,wk(ibwe))\r\n 40 gf1 = splc(m,n,k,y,ny,wx,wy,md,val,r1,eps,c,nc,wk,wk(ib),wk(iwe),\r\n &el,wk(ibwe))\r\n if (gf1 .gt. gf2) goto 50\r\ncInterpolation \r\n if (wk(4) .le. zero) goto 100\r\n r2 = r1\r\n gf2 = gf1\r\n r1 = r1 / ratio\r\n goto 40\r\n 50 r3 = r2 * ratio\r\n 60 gf3 = splc(m,n,k,y,ny,wx,wy,md,val,r3,eps,c,nc,wk,wk(ib),wk(iwe),\r\n &el,wk(ibwe))\r\n if (gf3 .gt. gf2) goto 70\r\ncLeast-squares polynomial \r\n if (wk(4) .ge. epsinv) goto 100\r\n r2 = r3\r\n gf2 = gf3\r\n r3 = r3 * ratio\r\n goto 60\r\n 70 r2 = r3\r\n gf2 = gf3\r\n alpha = (r2 - r1) / tau\r\n r4 = r1 + alpha\r\n r3 = r2 - alpha\r\n gf3 = splc(m,n,k,y,ny,wx,wy,md,val,r3,eps,c,nc,wk,wk(ib),wk(iwe),\r\n &el,wk(ibwe))\r\n gf4 = splc(m,n,k,y,ny,wx,wy,md,val,r4,eps,c,nc,wk,wk(ib),wk(iwe),\r\n &el,wk(ibwe))\r\n 80 if (gf3 .le. gf4) then\r\n r2 = r4\r\n gf2 = gf4\r\n err = (r2 - r1) / (r1 + r2)\r\n if ((((err * err) + one) .eq. one) .or. (err .le. tol)) goto 90\r\n r4 = r3\r\n gf4 = gf3\r\n alpha = alpha / tau\r\n r3 = r2 - alpha\r\n gf3 = splc(m,n,k,y,ny,wx,wy,md,val,r3,eps,c,nc,wk,wk(ib),wk(iwe),\r\n &el,wk(ibwe))\r\n else\r\n r1 = r3\r\n gf1 = gf3\r\n err = (r2 - r1) / (r1 + r2)\r\n if ((((err * err) + one) .eq. one) .or. (err .le. tol)) goto 90\r\n r3 = r4\r\n gf3 = gf4\r\n alpha = alpha / tau\r\n r4 = r1 + alpha\r\n gf4 = splc(m,n,k,y,ny,wx,wy,md,val,r4,eps,c,nc,wk,wk(ib),wk(iwe),\r\n &el,wk(ibwe))\r\n end if\r\n goto 80\r\nc\r\nc*** Calculate final spline coefficients\r\nc\r\n 90 r1 = half * (r1 + r2)\r\nc\r\nc*** Ready\r\nc\r\n 100 gf1 = splc(m,n,k,y,ny,wx,wy,md,val,r1,eps,c,nc,wk,wk(ib),wk(iwe),\r\n &el,wk(ibwe))\r\n return \r\nc BASIS.FOR, 1985-06-03\r\nc\r\nc***********************************************************************\r\nc\r\nc SUBROUTINE BASIS (REAL*8)\r\nc\r\nc Purpose:\r\nc *******\r\nc\r\nc Subroutine to assess a B-spline tableau, stored in vectorized\r\nc form.\r\nc\r\nc Calling convention:\r\nc ******************\r\nc\r\nc CALL BASIS ( M, N, X, B, BL, Q )\r\nc\r\nc Meaning of parameters:\r\nc *********************\r\nc\r\nc M ( I ) Half order of the spline (degree 2*M-1),\r\nc M > 0.\r\nc N ( I ) Number of knots, N >= 2*M.\r\nc X(N) ( I ) Knot sequence, X(I-1) < X(I), I=2,N.\r\nc B(1-M:M-1,N) ( O ) Output tableau. Element B(J,I) of array\r\nc B corresponds with element b(i,i+j) of\r\nc the tableau matrix B.\r\nc BL ( O ) L1-norm of B.\r\nc Q(1-M:M) ( W ) Internal work array.\r\nc\r\nc Remark:\r\nc ******\r\nc\r\nc This subroutine is an adaptation of subroutine BASIS from the\r\nc paper by Lyche et al. (1983). No checking is performed on the\r\nc validity of M and N. If the knot sequence is not strictly in-\r\nc creasing, division by zero may occur.\r\nc\r\nc Reference:\r\nc *********\r\nc\r\nc T. Lyche, L.L. Schumaker, & K. Sepehrnoori, Fortran subroutines\r\nc for computing smoothing and interpolating natural splines.\r\nc Advances in Engineering Software 5(1983)1, pp. 2-5.\r\nc\r\nc***********************************************************************\r\nc\r\n end\r\nc\r\n subroutine basis(m, n, x, b, bl, q)\r\n implicit double precision (o-z, a-h)\r\n parameter (zero = 0d0, one = 1d0)\r\nc\r\n dimension x(n), b(1 - m:m - 1, n), q(1 - m:m)\r\nc*** Linear spline\r\n if (m .eq. 1) then\r\n do 3 i = 1, n\r\n b(0,i) = one\r\n 3 continue\r\n bl = one\r\n return \r\nc\r\nc*** General splines\r\nc\r\n end if\r\n mm1 = m - 1\r\n mp1 = m + 1\r\n m2 = 2 * m\r\nc*** 1st row\r\n do 15 l = 1, n\r\n do 5 j = - mm1, m\r\n q(j) = zero\r\n 5 continue\r\n q(mm1) = one\r\nc*** Successive rows\r\n if ((l .ne. 1) .and. (l .ne. n)) q(mm1) = one / (x(l + 1) - x(l - \r\n &1))\r\n arg = x(l)\r\n do 13 i = 3, m2\r\n ir = mp1 - i\r\n v = q(ir)\r\nc*** Left-hand B-splines\r\n if (l .lt. i) then\r\n do 6 j = l + 1, i\r\n u = v\r\n v = q(ir + 1)\r\n q(ir) = u + ((x(j) - arg) * v)\r\n ir = ir + 1\r\n 6 continue\r\n end if\r\n j1 = max0((l - i) + 1,1)\r\n j2 = min0(l - 1,n - i)\r\nc*** Ordinary B-splines\r\n if (j1 .le. j2) then\r\n if (i .lt. m2) then\r\n do 8 j = j1, j2\r\n y = x(i + j)\r\n u = v\r\n v = q(ir + 1)\r\n q(ir) = u + (((v - u) * (y - arg)) / (y - x(j)))\r\n ir = ir + 1\r\n 8 continue\r\n else\r\n do 10 j = j1, j2\r\n u = v\r\n v = q(ir + 1)\r\n q(ir) = ((arg - x(j)) * u) + ((x(i + j) - arg) * v)\r\n ir = ir + 1\r\n 10 continue\r\n end if\r\n end if\r\n nmip1 = (n - i) + 1\r\nc*** Right-hand B-splines\r\n if (nmip1 .lt. l) then\r\n do 12 j = nmip1, l - 1\r\n u = v\r\n v = q(ir + 1)\r\n q(ir) = ((arg - x(j)) * u) + v\r\n ir = ir + 1\r\n 12 continue\r\n end if\r\n 13 continue\r\n do 14 j = - mm1, mm1\r\n b(j,l) = q(j)\r\n 14 continue\r\nc\r\nc*** Zero unused parts of B\r\nc\r\n 15 continue\r\n do 17 i = 1, mm1\r\n do 16 k = i, mm1\r\n b(- k,i) = zero\r\n b(k,(n + 1) - i) = zero\r\n 16 continue\r\nc\r\nc*** Assess L1-norm of B\r\nc\r\n 17 continue\r\n bl = 0d0\r\n do 19 i = 1, n\r\n do 18 k = - mm1, mm1\r\n bl = bl + abs(b(k,i))\r\n 18 continue\r\n 19 continue\r\nc\r\nc*** Ready\r\nc\r\n bl = bl / n\r\n return \r\nc PREP.FOR, 1985-07-04\r\nc\r\nc***********************************************************************\r\nc\r\nc SUBROUTINE PREP (REAL*8)\r\nc\r\nc Purpose:\r\nc *******\r\nc\r\nc To compute the matrix WE of weighted divided difference coeffi-\r\nc cients needed to set up a linear system of equations for sol-\r\nc ving B-spline smoothing problems, and its L1-norm EL. The matrix\r\nc WE is stored in vectorized form.\r\nc\r\nc Calling convention:\r\nc ******************\r\nc\r\nc CALL PREP ( M, N, X, W, WE, EL )\r\nc\r\nc Meaning of parameters:\r\nc *********************\r\nc\r\nc M ( I ) Half order of the B-spline (degree\r\nc 2*M-1), with M > 0.\r\nc N ( I ) Number of knots, with N >= 2*M.\r\nc X(N) ( I ) Strictly increasing knot array, with\r\nc X(I-1) < X(I), I=2,N.\r\nc W(N) ( I ) Weight matrix (diagonal), with\r\nc W(I).gt.0.0, I=1,N.\r\nc WE(-M:M,N) ( O ) Array containing the weighted divided\r\nc difference terms in vectorized format.\r\nc Element WE(J,I) of array E corresponds\r\nc with element e(i,i+j) of the matrix\r\nc W**-1 * E.\r\nc EL ( O ) L1-norm of WE.\r\nc\r\nc Remark:\r\nc ******\r\nc\r\nc This subroutine is an adaptation of subroutine PREP from the pap\r\ncer\r\nc by Lyche et al. (1983). No checking is performed on the validity\r\nc of M and N. Division by zero may occur if the knot sequence is\r\nc not strictly increasing.\r\nc\r\nc Reference:\r\nc *********\r\nc\r\nc T. Lyche, L.L. Schumaker, & K. Sepehrnoori, Fortran subroutines\r\nc for computing smoothing and interpolating natural splines.\r\nc Advances in Engineering Software 5(1983)1, pp. 2-5.\r\nc\r\nc***********************************************************************\r\nc\r\n end\r\nc\r\n subroutine prep(m, n, x, w, we, el)\r\n implicit double precision (o-z, a-h)\r\n parameter (zero = 0d0, one = 1d0)\r\nc\r\nc*** Calculate the factor F1\r\nc\r\ncWE(-M:M,N) \r\n dimension x(n), w(n), we(((2 * m) + 1) * n)\r\n m2 = 2 * m\r\n mp1 = m + 1\r\n m2m1 = m2 - 1\r\n m2p1 = m2 + 1\r\n nm = n - m\r\n f1 = - one\r\n if (m .ne. 1) then\r\n do 5 i = 2, m\r\n f1 = - (f1 * i)\r\n 5 continue\r\n do 6 i = mp1, m2m1\r\n f1 = f1 * i\r\n 6 continue\r\nc\r\nc*** Columnwise evaluation of the unweighted design matrix E\r\nc\r\n end if\r\n i1 = 1\r\n i2 = m\r\n jm = mp1\r\n do 17 j = 1, n\r\n inc = m2p1\r\n if (j .gt. nm) then\r\n f1 = - f1\r\n f = f1\r\n else\r\n if (j .lt. mp1) then\r\n inc = 1\r\n f = f1\r\n else\r\n f = f1 * (x(j + m) - x(j - m))\r\n end if\r\n end if\r\n if (j .gt. mp1) i1 = i1 + 1\r\n if (i2 .lt. n) i2 = i2 + 1\r\nc*** Loop for divided difference coefficients\r\n jj = jm\r\n ff = f\r\n y = x(i1)\r\n i1p1 = i1 + 1\r\n do 11 i = i1p1, i2\r\n ff = ff / (y - x(i))\r\n 11 continue\r\n we(jj) = ff\r\n jj = jj + m2\r\n i2m1 = i2 - 1\r\n if (i1p1 .le. i2m1) then\r\n do 14 l = i1p1, i2m1\r\n ff = f\r\n y = x(l)\r\n do 12 i = i1, l - 1\r\n ff = ff / (y - x(i))\r\n 12 continue\r\n do 13 i = l + 1, i2\r\n ff = ff / (y - x(i))\r\n 13 continue\r\n we(jj) = ff\r\n jj = jj + m2\r\n 14 continue\r\n end if\r\n ff = f\r\n y = x(i2)\r\n do 16 i = i1, i2m1\r\n ff = ff / (y - x(i))\r\n 16 continue\r\n we(jj) = ff\r\n jj = jj + m2\r\n jm = jm + inc\r\nc\r\nc*** Zero the upper left and lower right corners of E\r\nc\r\n 17 continue\r\n kl = 1\r\n n2m = (m2p1 * n) + 1\r\n do 19 i = 1, m\r\n ku = (kl + m) - i\r\n do 18 k = kl, ku\r\n we(k) = zero\r\n we(n2m - k) = zero\r\n 18 continue\r\n kl = kl + m2p1\r\nc\r\nc*** Weighted matrix WE = W**-1 * E and its L1-norm\r\nc\r\n 19 continue\r\n 20 jj = 0\r\n el = 0d0\r\n do 22 i = 1, n\r\n wi = w(i)\r\n do 21 j = 1, m2p1\r\n jj = jj + 1\r\n we(jj) = we(jj) / wi\r\n el = el + abs(we(jj))\r\n 21 continue\r\n 22 continue\r\nc\r\nc*** Ready\r\nc\r\n el = el / n\r\n return \r\nc SPLC.FOR, 1985-12-12\r\nc\r\nc Author: H.J. Woltring\r\nc\r\nc Organizations: University of Nijmegen, and\r\nc Philips Medical Systems, Eindhoven\r\nc (The Netherlands)\r\nc\r\nc***********************************************************************\r\nc\r\nc FUNCTION SPLC (REAL*8)\r\nc\r\nc Purpose:\r\nc *******\r\nc\r\nc To assess the coefficients of a B-spline and various statistical\r\nc parameters, for a given value of the regularization parameter p.\r\nc\r\nc Calling convention:\r\nc ******************\r\nc\r\nc FV = SPLC ( M, N, K, Y, NY, WX, WY, MODE, VAL, P, EPS, C, NC,\r\nc 1 STAT, B, WE, EL, BWE)\r\nc\r\nc Meaning of parameters:\r\nc *********************\r\nc\r\nc SPLC ( O ) GCV function value if |MODE|.eq.2,\r\nc MSE value if |MODE|.eq.3, and absolute\r\nc difference with the prior given number o\r\ncf\r\nc degrees of freedom if |MODE|.eq.4.\r\nc M ( I ) Half order of the B-spline (degree 2*M-1\r\nc),\r\nc with M > 0.\r\nc N ( I ) Number of observations, with N >= 2*M.\r\nc K ( I ) Number of datasets, with K >= 1.\r\nc Y(NY,K) ( I ) Observed measurements.\r\nc NY ( I ) First dimension of Y(NY,K), with NY.ge.N\r\nc.\r\nc WX(N) ( I ) Weight factors, corresponding to the\r\nc relative inverse variance of each measur\r\nce-\r\nc ment, with WX(I) > 0.0.\r\nc WY(K) ( I ) Weight factors, corresponding to the\r\nc relative inverse variance of each datase\r\nct,\r\nc with WY(J) > 0.0.\r\nc MODE ( I ) Mode switch, as described in GCVSPL.\r\nc VAL ( I ) Prior variance if |MODE|.eq.3, and\r\nc prior number of degrees of freedom if\r\nc |MODE|.eq.4. For other values of MODE,\r\nc VAL is not used.\r\nc P ( I ) Smoothing parameter, with P >= 0.0. If\r\nc P.eq.0.0, an interpolating spline is\r\nc calculated.\r\nc EPS ( I ) Relative rounding tolerance*10.0. EPS is\r\nc the smallest positive number such that\r\nc EPS/10.0 + 1.0 .ne. 1.0.\r\nc C(NC,K) ( O ) Calculated spline coefficient arrays. NB\r\nc:\r\nc the dimensions of in GCVSPL and in SPLDE\r\ncR\r\nc are different! In SPLDER, only a single\r\nc column of C(N,K) is needed, and the prop\r\ncer\r\nc column C(1,J), with J=1...K, should be u\r\ncsed\r\nc when calling SPLDER.\r\nc NC ( I ) First dimension of C(NC,K), with NC.ge.N\r\nc.\r\nc STAT(6) ( O ) Statistics array. See the description in\r\nc subroutine GCVSPL.\r\nc B (1-M:M-1,N) ( I ) B-spline tableau as evaluated by subrout\r\ncine\r\nc BASIS.\r\nc WE( -M:M ,N) ( I ) Weighted B-spline tableau (W**-1 * E) as\r\nc evaluated by subroutine PREP.\r\nc EL ( I ) L1-norm of the matrix WE as evaluated by\r\nc subroutine PREP.\r\nc BWE(-M:M,N) ( O ) Central 2*M+1 bands of the inverted\r\nc matrix ( B + p * W**-1 * E )**-1\r\nc\r\nc Remarks:\r\nc *******\r\nc\r\nc This subroutine combines elements of subroutine SPLC0 from the\r\nc paper by Lyche et al. (1983), and of subroutine SPFIT1 by\r\nc Hutchinson (1985).\r\nc\r\nc References:\r\nc **********\r\nc\r\nc M.F. Hutchinson (1985), Subroutine CUBGCV. CSIRO division of\r\nc Mathematics and Statistics, P.O. Box 1965, Canberra, ACT 2601,\r\nc Australia.\r\nc\r\nc T. Lyche, L.L. Schumaker, & K. Sepehrnoori, Fortran subroutines\r\nc for computing smoothing and interpolating natural splines.\r\nc Advances in Engineering Software 5(1983)1, pp. 2-5.\r\nc\r\nc***********************************************************************\r\nc\r\n end\r\nc\r\n function splc(m, n, k, y, ny, wx, wy, mode, val, p, eps, c, nc, \r\n &stat, b, we, el, bwe)\r\n implicit double precision (o-z, a-h)\r\n parameter (zero = 0d0, one = 1d0, two = 2d0)\r\nc\r\nc*** Check on p-value\r\nc\r\n dimension y(ny, k), wx(n), wy(k), c(nc, k), stat(6), b(1 - m:m - 1\r\n &, n), we(- m:m, n), bwe(- m:m, n)\r\n dp = p\r\n stat(4) = p\r\nc*** Pseudo-interpolation if p is too small\r\n pel = p * el\r\n if (pel .lt. eps) then\r\n dp = eps / el\r\n stat(4) = zero\r\nc*** Pseudo least-squares polynomial if p is too large\r\n end if\r\n if ((pel * eps) .gt. one) then\r\n dp = one / (el * eps)\r\n stat(4) = dp\r\nc\r\nc*** Calculate BWE = B + p * W**-1 * E\r\nc\r\n end if\r\n do 40 i = 1, n\r\n km = - min0(m,i - 1)\r\n kp = min0(m,n - i)\r\n do 30 l = km, kp\r\n if (iabs(l) .eq. m) then\r\n bwe(l,i) = dp * we(l,i)\r\n else\r\n bwe(l,i) = b(l,i) + (dp * we(l,i))\r\n end if\r\n 30 continue\r\nc\r\nc*** Solve BWE * C = Y, and assess TRACE [ B * BWE**-1 ]\r\nc\r\n 40 continue\r\n call bandet(bwe, m, n)\r\n call bansol(bwe, y, ny, c, nc, m, n, k)\r\nctrace * p = res. d.o.\r\n stat(3) = trinv(we,bwe,m,n) * dp\r\nc\r\nc*** Compute mean-squared weighted residual\r\nc\r\n trn = stat(3) / n\r\n esn = zero\r\n do 70 j = 1, k\r\n do 60 i = 1, n\r\n dt = - y(i,j)\r\n km = - min0(m - 1,i - 1)\r\n kp = min0(m - 1,n - i)\r\n do 50 l = km, kp\r\n dt = dt + (b(l,i) * c(i + l,j))\r\n 50 continue\r\n esn = esn + (((dt * dt) * wx(i)) * wy(j))\r\n 60 continue\r\n 70 continue\r\nc\r\nc*** Calculate statistics and function value\r\nc\r\n esn = esn / (n * k)\r\ncEstimated variance \r\n stat(6) = esn / trn\r\ncGCV function value \r\n stat(1) = stat(6) / trn\r\nc STAT(3) = trace [p*B * BWE**-1] !Estimated residuals' d.o.f.\r\nc STAT(4) = P !Normalized smoothing factor\r\ncMean Squared Residual \r\n stat(2) = esn\r\nc*** Unknown variance: GCV\r\n if (iabs(mode) .ne. 3) then\r\n stat(5) = stat(6) - esn\r\n if (iabs(mode) .eq. 1) splc = zero\r\n if (iabs(mode) .eq. 2) splc = stat(1)\r\n if (iabs(mode) .eq. 4) splc = dabs(stat(3) - val)\r\nc*** Known variance: estimated mean squared error\r\n else\r\n stat(5) = esn - (val * ((two * trn) - one))\r\n splc = stat(5)\r\nc\r\n end if\r\n return \r\nc BANDET.FOR, 1985-06-03\r\nc\r\nc***********************************************************************\r\nc\r\nc SUBROUTINE BANDET (REAL*8)\r\nc\r\nc Purpose:\r\nc *******\r\nc\r\nc This subroutine computes the LU decomposition of an N*N matrix\r\nc E. It is assumed that E has M bands above and M bands below the\r\nc diagonal. The decomposition is returned in E. It is assumed that\r\nc E can be decomposed without pivoting. The matrix E is stored in\r\nc vectorized form in the array E(-M:M,N), where element E(J,I) of\r\nc the array E corresponds with element e(i,i+j) of the matrix E.\r\nc\r\nc Calling convention:\r\nc ******************\r\nc\r\nc CALL BANDET ( E, M, N )\r\nc\r\nc Meaning of parameters:\r\nc *********************\r\nc\r\nc E(-M:M,N) (I/O) Matrix to be decomposed.\r\nc M, N ( I ) Matrix dimensioning parameters,\r\nc M >= 0, N >= 2*M.\r\nc\r\nc Remark:\r\nc ******\r\nc\r\nc No checking on the validity of the input data is performed.\r\nc If (M.le.0), no action is taken.\r\nc\r\nc***********************************************************************\r\nc\r\n end\r\nc\r\n subroutine bandet(e, m, n)\r\n implicit double precision (o-z, a-h)\r\nc\r\n dimension e(- m:m, n)\r\n if (m .le. 0) return \r\n do 40 i = 1, n\r\n di = e(0,i)\r\n mi = min0(m,i - 1)\r\n if (mi .ge. 1) then\r\n do 10 k = 1, mi\r\n di = di - (e(- k,i) * e(k,i - k))\r\n 10 continue\r\n e(0,i) = di\r\n end if\r\n lm = min0(m,n - i)\r\n if (lm .ge. 1) then\r\n do 30 l = 1, lm\r\n dl = e(- l,i + l)\r\n km = min0(m - l,i - 1)\r\n if (km .ge. 1) then\r\n du = e(l,i)\r\n do 20 k = 1, km\r\n du = du - (e(- k,i) * e(l + k,i - k))\r\n dl = dl - (e((- l) - k,l + i) * e(k,i - k))\r\n 20 continue\r\n e(l,i) = du\r\n end if\r\n e(- l,i + l) = dl / di\r\n 30 continue\r\n end if\r\nc\r\nc*** Ready\r\nc\r\n 40 continue\r\n return \r\nc BANSOL.FOR, 1985-12-12\r\nc\r\nc***********************************************************************\r\nc\r\nc SUBROUTINE BANSOL (REAL*8)\r\nc\r\nc Purpose:\r\nc *******\r\nc\r\nc This subroutine solves systems of linear equations given an LU\r\nc decomposition of the design matrix. Such a decomposition is pro-\r\nc vided by subroutine BANDET, in vectorized form. It is assumed\r\nc that the design matrix is not singular.\r\nc\r\nc Calling convention:\r\nc ******************\r\nc\r\nc CALL BANSOL ( E, Y, NY, C, NC, M, N, K )\r\nc\r\nc Meaning of parameters:\r\nc *********************\r\nc\r\nc E(-M:M,N) ( I ) Input design matrix, in LU-decomposed,\r\nc vectorized form. Element E(J,I) of the\r\nc array E corresponds with element\r\nc e(i,i+j) of the N*N design matrix E.\r\nc Y(NY,K) ( I ) Right hand side vectors.\r\nc C(NC,K) ( O ) Solution vectors.\r\nc NY, NC, M, N, K ( I ) Dimensioning parameters, with M >= 0,\r\nc N > 2*M, and K >= 1.\r\nc\r\nc Remark:\r\nc ******\r\nc\r\nc This subroutine is an adaptation of subroutine BANSOL from the\r\nc paper by Lyche et al. (1983). No checking is performed on the\r\nc validity of the input parameters and data. Division by zero may\r\nc occur if the system is singular.\r\nc\r\nc Reference:\r\nc *********\r\nc\r\nc T. Lyche, L.L. Schumaker, & K. Sepehrnoori, Fortran subroutines\r\nc for computing smoothing and interpolating natural splines.\r\nc Advances in Engineering Software 5(1983)1, pp. 2-5.\r\nc\r\nc***********************************************************************\r\nc\r\n end\r\nc\r\n subroutine bansol(e, y, ny, c, nc, m, n, k)\r\n implicit double precision (o-z, a-h)\r\nc\r\nc*** Check on special cases: M=0, M=1, M>1\r\nc\r\n dimension e(- m:m, n), y(ny, k), c(nc, k)\r\n nm1 = n - 1\r\nc\r\nc*** M = 0: Diagonal system\r\nc\r\n if (m - 1) 10, 40, 80\r\n 10 do 30 i = 1, n\r\n do 20 j = 1, k\r\n c(i,j) = y(i,j) / e(0,i)\r\n 20 continue\r\n 30 continue\r\nc\r\nc*** M = 1: Tridiagonal system\r\nc\r\n return \r\n 40 do 70 j = 1, k\r\n c(1,j) = y(1,j)\r\ncForward sweep \r\n do 50 i = 2, n\r\n c(i,j) = y(i,j) - (e(-1,i) * c(i - 1,j))\r\n 50 continue\r\n c(n,j) = c(n,j) / e(0,n)\r\ncBackward sweep \r\n do 60 i = nm1, 1, -1\r\n c(i,j) = (c(i,j) - (e(1,i) * c(i + 1,j))) / e(0,i)\r\n 60 continue\r\n 70 continue\r\nc\r\nc*** M > 1: General system\r\nc\r\n return \r\n 80 do 130 j = 1, k\r\n c(1,j) = y(1,j)\r\ncForward sweep \r\n do 100 i = 2, n\r\n mi = min0(m,i - 1)\r\n d = y(i,j)\r\n do 90 l = 1, mi\r\n d = d - (e(- l,i) * c(i - l,j))\r\n 90 continue\r\n c(i,j) = d\r\n 100 continue\r\n c(n,j) = c(n,j) / e(0,n)\r\ncBackward sweep \r\n do 120 i = nm1, 1, -1\r\n mi = min0(m,n - i)\r\n d = c(i,j)\r\n do 110 l = 1, mi\r\n d = d - (e(l,i) * c(i + l,j))\r\n 110 continue\r\n c(i,j) = d / e(0,i)\r\n 120 continue\r\n 130 continue\r\nc\r\n return \r\nc TRINV.FOR, 1985-06-03\r\nc\r\nc***********************************************************************\r\nc\r\nc FUNCTION TRINV (REAL*8)\r\nc\r\nc Purpose:\r\nc *******\r\nc\r\nc To calculate TRACE [ B * E**-1 ], where B and E are N * N\r\nc matrices with bandwidth 2*M+1, and where E is a regular matrix\r\nc in LU-decomposed form. B and E are stored in vectorized form,\r\nc compatible with subroutines BANDET and BANSOL.\r\nc\r\nc Calling convention:\r\nc ******************\r\nc\r\nc TRACE = TRINV ( B, E, M, N )\r\nc\r\nc Meaning of parameters:\r\nc *********************\r\nc\r\nc B(-M:M,N) ( I ) Input array for matrix B. Element B(J,I)\r\nc corresponds with element b(i,i+j) of the\r\nc matrix B.\r\nc E(-M:M,N) (I/O) Input array for matrix E. Element E(J,I)\r\nc corresponds with element e(i,i+j) of the\r\nc matrix E. This matrix is stored in LU-\r\nc decomposed form, with L unit lower tri-\r\nc angular, and U upper triangular. The unit\r\nc diagonal of L is not stored. Upon return,\r\nc the array E holds the central 2*M+1 bands\r\nc of the inverse E**-1, in similar ordering.\r\nc M, N ( I ) Array and matrix dimensioning parameters\r\nc (M.gt.0, N.ge.2*M+1).\r\nc TRINV ( O ) Output function value TRACE [ B * E**-1 ]\r\nc\r\nc Reference:\r\nc *********\r\nc\r\nc A.M. Erisman & W.F. Tinney, On computing certain elements of the\r\nc inverse of a sparse matrix. Communications of the ACM 18(1975),\r\nc nr. 3, pp. 177-179.\r\nc\r\nc***********************************************************************\r\nc\r\n end\r\nc\r\n double precision function trinv(b, e, m, n)\r\n implicit double precision (o-z, a-h)\r\n parameter (zero = 0d0, one = 1d0)\r\nc\r\nc*** Assess central 2*M+1 bands of E**-1 and store in array E\r\nc\r\n dimension b(- m:m, n), e(- m:m, n)\r\ncNth pivot \r\n e(0,n) = one / e(0,n)\r\n do 40 i = n - 1, 1, -1\r\n mi = min0(m,n - i)\r\nc*** Save Ith column of L and Ith row of U, and normalize U row\r\ncIth pivot \r\n dd = one / e(0,i)\r\n do 10 k = 1, mi\r\ncIth row of U (normalized) \r\n e(k,n) = e(k,i) * dd\r\ncIth column of L \r\n e(- k,1) = e(- k,k + i)\r\n 10 continue\r\nc*** Invert around Ith pivot\r\n dd = dd + dd\r\n do 30 j = mi, 1, -1\r\n du = zero\r\n dl = zero\r\n do 20 k = 1, mi\r\n du = du - (e(k,n) * e(j - k,i + k))\r\n dl = dl - (e(- k,1) * e(k - j,i + j))\r\n 20 continue\r\n e(j,i) = du\r\n e(- j,j + i) = dl\r\n dd = dd - ((e(j,n) * dl) + (e(- j,1) * du))\r\n 30 continue\r\n e(0,i) = 5d-1 * dd\r\nc\r\nc*** Assess TRACE [ B * E**-1 ] and clear working storage\r\nc\r\n 40 continue\r\n dd = zero\r\n do 60 i = 1, n\r\n mn = - min0(m,i - 1)\r\n mp = min0(m,n - i)\r\n do 50 k = mn, mp\r\n dd = dd + (b(k,i) * e(- k,k + i))\r\n 50 continue\r\n 60 continue\r\n trinv = dd\r\n do 70 k = 1, m\r\n e(k,n) = zero\r\n e(- k,1) = zero\r\nc\r\nc*** Ready\r\nc\r\n 70 continue\r\n return \r\nc SPLDER.FOR, 1985-06-11\r\nc\r\nc***********************************************************************\r\nc\r\nc FUNCTION SPLDER (REAL*8)\r\nc\r\nc Purpose:\r\nc *******\r\nc\r\nc To produce the value of the function (IDER.eq.0) or of the\r\nc IDERth derivative (IDER.gt.0) of a 2M-th order B-spline at\r\nc the point T. The spline is described in terms of the half\r\nc order M, the knot sequence X(N), N.ge.2*M, and the spline\r\nc coefficients C(N).\r\nc\r\nc Calling convention:\r\nc ******************\r\nc\r\nc SVIDER = SPLDER ( IDER, M, N, T, X, C, L, Q )\r\nc\r\nc Meaning of parameters:\r\nc *********************\r\nc\r\nc SPLDER ( O ) Function or derivative value.\r\nc IDER ( I ) Derivative order required, with 0.le.IDER\r\nc and IDER.le.2*M. If IDER.eq.0, the function\r\nc value is returned; otherwise, the IDER-th\r\nc derivative of the spline is returned.\r\nc M ( I ) Half order of the spline, with M.gt.0.\r\nc N ( I ) Number of knots and spline coefficients,\r\nc with N.ge.2*M.\r\nc T ( I ) Argument at which the spline or its deri-\r\nc vative is to be evaluated, with X(1).le.T\r\nc and T.le.X(N).\r\nc X(N) ( I ) Strictly increasing knot sequence array,\r\nc X(I-1).lt.X(I), I=2,...,N.\r\nc C(N) ( I ) Spline coefficients, as evaluated by\r\nc subroutine GVCSPL.\r\nc L (I/O) L contains an integer such that:\r\nc X(L).le.T and T.lt.X(L+1) if T is within\r\nc the range X(1).le.T and T.lt.X(N). If\r\nc T.lt.X(1), L is set to 0, and if T.ge.X(N),\r\nc L is set to N. The search for L is facili-\r\nc tated if L has approximately the right\r\nc value on entry.\r\nc Q(2*M) ( W ) Internal work array.\r\nc\r\nc Remark:\r\nc ******\r\nc\r\nc This subroutine is an adaptation of subroutine SPLDER of\r\nc the paper by Lyche et al. (1983). No checking is performed\r\nc on the validity of the input parameters.\r\nc\r\nc Reference:\r\nc *********\r\nc\r\nc T. Lyche, L.L. Schumaker, & K. Sepehrnoori, Fortran subroutines\r\nc for computing smoothing and interpolating natural splines.\r\nc Advances in Engineering Software 5(1983)1, pp. 2-5.\r\nc\r\nc***********************************************************************\r\nc\r\n end\r\nc\r\n double precision function splder(ider, m, n, t, x, c, l, q)\r\n implicit double precision (o-z, a-h)\r\n parameter (zero = 0d0, one = 1d0)\r\ncf2py intent(out) :: splder\r\ncf2py intent(hide) :: q\r\nc\r\nc*** Derivatives of IDER.ge.2*M are alway zero\r\nc\r\n dimension x(n), c(n), q(2 * m)\r\n m2 = 2 * m\r\n k = m2 - ider\r\n if (k .lt. 1) then\r\n splder = zero\r\n return \r\nc\r\nc*** Search for the interval value L\r\nc\r\n end if\r\nc\r\nc*** Initialize parameters and the 1st row of the B-spline\r\nc*** coefficients tableau\r\nc\r\n call search(n, x, t, l)\r\n tt = t\r\n mp1 = m + 1\r\n npm = n + m\r\n m2m1 = m2 - 1\r\n k1 = k - 1\r\n nk = n - k\r\n lk = l - k\r\n lk1 = lk + 1\r\n lm = l - m\r\n jl = l + 1\r\n ju = l + m2\r\n ii = n - m2\r\n ml = - l\r\n do 2 j = jl, ju\r\n if ((j .ge. mp1) .and. (j .le. npm)) then\r\n q(j + ml) = c(j - m)\r\n else\r\n q(j + ml) = zero\r\n end if\r\nc\r\nc*** The following loop computes differences of the B-spline\r\nc*** coefficients. If the value of the spline is required,\r\nc*** differencing is not necessary.\r\nc\r\n 2 continue\r\n if (ider .gt. 0) then\r\n jl = jl - m2\r\n ml = ml + m2\r\n do 6 i = 1, ider\r\n jl = jl + 1\r\n ii = ii + 1\r\n j1 = max0(1,jl)\r\n j2 = min0(l,ii)\r\n mi = m2 - i\r\n j = j2 + 1\r\n if (j1 .le. j2) then\r\n do 3 jin = j1, j2\r\n j = j - 1\r\n jm = ml + j\r\n q(jm) = (q(jm) - q(jm - 1)) / (x(j + mi) - x(j))\r\n 3 continue\r\n end if\r\n if (jl .ge. 1) goto 6\r\n i1 = i + 1\r\n j = ml + 1\r\n if (i1 .le. ml) then\r\n do 5 jin = i1, ml\r\n j = j - 1\r\n q(j) = - q(j - 1)\r\n 5 continue\r\n end if\r\n 6 continue\r\n do 7 j = 1, k\r\n q(j) = q(j + ider)\r\n 7 continue\r\nc\r\nc*** Compute lower half of the evaluation tableau\r\nc\r\n end if\r\ncTableau ready if IDER.eq.2*M-1 \r\n if (k1 .ge. 1) then\r\n do 14 i = 1, k1\r\n nki = nk + i\r\n ir = k\r\n jj = l\r\n ki = k - i\r\nc*** Right-hand B-splines\r\n nki1 = nki + 1\r\n if (l .ge. nki1) then\r\n do 9 j = nki1, l\r\n q(ir) = q(ir - 1) + ((tt - x(jj)) * q(ir))\r\n jj = jj - 1\r\n ir = ir - 1\r\n 9 continue\r\nc*** Middle B-splines\r\n end if\r\n lk1i = lk1 + i\r\n j1 = max0(1,lk1i)\r\n j2 = min0(l,nki)\r\n if (j1 .le. j2) then\r\n do 11 j = j1, j2\r\n xjki = x(jj + ki)\r\n z = q(ir)\r\n q(ir) = z + (((xjki - tt) * (q(ir - 1) - z)) / (xjki - x(jj)))\r\n ir = ir - 1\r\n jj = jj - 1\r\n 11 continue\r\nc*** Left-hand B-splines\r\n end if\r\n if (lk1i .le. 0) then\r\n jj = ki\r\n lk1i1 = 1 - lk1i\r\n do 13 j = 1, lk1i1\r\n q(ir) = q(ir) + ((x(jj) - tt) * q(ir - 1))\r\n jj = jj - 1\r\n ir = ir - 1\r\n 13 continue\r\n end if\r\n 14 continue\r\nc\r\nc*** Compute the return value\r\nc\r\n end if\r\nc*** Multiply with factorial if IDER.gt.0\r\n z = q(k)\r\n if (ider .gt. 0) then\r\n do 16 j = k, m2m1\r\n z = z * j\r\n 16 continue\r\n end if\r\nc\r\nc*** Ready\r\nc\r\n splder = z\r\n return \r\nc SEARCH.FOR, 1985-06-03\r\nc\r\nc***********************************************************************\r\nc\r\nc SUBROUTINE SEARCH (REAL*8)\r\nc\r\nc Purpose:\r\nc *******\r\nc\r\nc Given a strictly increasing knot sequence X(1) < ... < X(N),\r\nc where N >= 1, and a real number T, this subroutine finds the\r\nc value L such that X(L) <= T < X(L+1). If T < X(1), L = 0;\r\nc if X(N) <= T, L = N.\r\nc\r\nc Calling convention:\r\nc ******************\r\nc\r\nc CALL SEARCH ( N, X, T, L )\r\nc\r\nc Meaning of parameters:\r\nc *********************\r\nc\r\nc N ( I ) Knot array dimensioning parameter.\r\nc X(N) ( I ) Stricly increasing knot array.\r\nc T ( I ) Input argument whose knot interval is to\r\nc be found.\r\nc L (I/O) Knot interval parameter. The search procedure\r\nc is facilitated if L has approximately the\r\nc right value on entry.\r\nc\r\nc Remark:\r\nc ******\r\nc\r\nc This subroutine is an adaptation of subroutine SEARCH from\r\nc the paper by Lyche et al. (1983). No checking is performed\r\nc on the input parameters and data; the algorithm may fail if\r\nc the input sequence is not strictly increasing.\r\nc\r\nc Reference:\r\nc *********\r\nc\r\nc T. Lyche, L.L. Schumaker, & K. Sepehrnoori, Fortran subroutines\r\nc for computing smoothing and interpolating natural splines.\r\nc Advances in Engineering Software 5(1983)1, pp. 2-5.\r\nc\r\nc***********************************************************************\r\nc\r\n end\r\nc\r\n subroutine search(n, x, t, l)\r\n implicit double precision (o-z, a-h)\r\nc\r\n dimension x(n)\r\nc*** Out of range to the left\r\n if (t .lt. x(1)) then\r\n l = 0\r\n return \r\n end if\r\nc*** Out of range to the right\r\n if (t .ge. x(n)) then\r\n l = n\r\n return \r\nc*** Validate input value of L\r\n end if\r\n l = max0(l,1)\r\nc\r\nc*** Often L will be in an interval adjoining the interval found\r\nc*** in a previous call to search\r\nc\r\n if (l .ge. n) l = n - 1\r\n if (t .ge. x(l)) goto 5\r\n l = l - 1\r\nc\r\nc*** Perform bisection\r\nc\r\n if (t .ge. x(l)) return \r\n il = 1\r\n 3 iu = l\r\n 4 l = (il + iu) / 2\r\n if ((iu - il) .le. 1) return \r\n if (t .lt. x(l)) goto 3\r\n il = l\r\n goto 4\r\n 5 if (t .lt. x(l + 1)) return \r\n l = l + 1\r\n if (t .lt. x(l + 1)) return \r\n il = l + 1\r\n iu = n\r\nc\r\n goto 4\r\n end\r\n", "meta": {"hexsha": "d3d27913012378a134534b3b9289fa849ba54d34", "size": 50333, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "deps/src/gcvspline/gcvspl.f", "max_stars_repo_name": "JuliaPackageMirrors/Spectra.jl", "max_stars_repo_head_hexsha": "9bc4b7c4d789605e6828365647c34e5861739b52", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "deps/src/gcvspline/gcvspl.f", "max_issues_repo_name": "JuliaPackageMirrors/Spectra.jl", "max_issues_repo_head_hexsha": "9bc4b7c4d789605e6828365647c34e5861739b52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-20T11:07:24.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-20T13:44:18.000Z", "max_forks_repo_path": "deps/src/gcvspline/gcvspl.f", "max_forks_repo_name": "JuliaPackageMirrors/Spectra.jl", "max_forks_repo_head_hexsha": "9bc4b7c4d789605e6828365647c34e5861739b52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.5329780147, "max_line_length": 137, "alphanum_fraction": 0.488844297, "num_tokens": 15258, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422241476943, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7754020409848468}} {"text": "REAL(KIND=8) FUNCTION D1MACH(I)\n\n INTEGER,INTENT(IN):: I\n !\n ! DOUBLE-PRECISION MACHINE CONSTANTS\n ! D1MACH( 1) = B**(EMIN-1), THE SMALLEST POSITIVE MAGNITUDE.\n ! D1MACH( 2) = B**EMAX*(1 - B**(-T)), THE LARGEST MAGNITUDE.\n ! D1MACH( 3) = B**(-T), THE SMALLEST RELATIVE SPACING.\n ! D1MACH( 4) = B**(1-T), THE LARGEST RELATIVE SPACING.\n ! D1MACH( 5) = LOG10(B)\n !\n REAL(KIND=8),DIMENSION(5),SAVE::X\n LOGICAL,SAVE:: ran = .false.\n\n IF(.NOT. ran)THEN\n\n X(1) = TINY(X(1))\n X(2) = HUGE(X(2))\n X(3) = EPSILON(X(3))/RADIX(X(3))\n X(4) = EPSILON(X(4))\n X(5) = LOG10(REAL(RADIX(X(5)),KIND=8))\n ran = .true.\n\n END IF\n\n IF (I < 1 .OR. I > 5) THEN\n\n WRITE(*,*) 'D1MACH(I): I =',I,' is out of bounds.'\n STOP\n\n END IF\n\n D1MACH = X(I)\n\n RETURN\n\nEND FUNCTION D1MACH\n", "meta": {"hexsha": "6f0d688a9d7d3b4822e076720c4bd9298253f692", "size": 803, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/d1mach.f90", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/d1mach.f90", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/d1mach.f90", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.1315789474, "max_line_length": 63, "alphanum_fraction": 0.5516811955, "num_tokens": 351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7753924279296223}} {"text": "! ---------------------------------------------------------------------------------------------------------------\n! ORIGINAL AUTHORS : MIKE BLASKIEWISC, RODERIK BRUCE, MICHAELA SCHAUMANN, TOM MERTENS\n! ---------------------------------------------------------------------------------------------------------------\n! VERSION 2.0 : UPDATE TO TRACK MULTIPLE BUNCHES AND HAVE DIFFERENT PARTICLE TYPES (P-PB) \n! AUTHOR : TOM MERTENS\n! DATE : 19/12/2016\n! COPYRIGHT : CERN\n! \n! DESCRIPTION : \n! FUNCTION TO CALCULATE FMOHL A HELPER FUNCTION IN THE NAGAITSEV IBS MODULE\n! ---------------------------------------------------------------------------------------------------------------\n\ndouble precision function fmohl(a,b,q,np)\ninteger, intent(in) ::np\ndouble precision, intent(in) :: a,b,q\ndouble precision :: du,u,cp,cq,dsum,sum\n\n! direct crib from page 126 in handbook\n ceuler = 0.577215\n pi = 3.14159265\n sum = 0\n du = 1/float(np)\n do k=0,np\n u = k*du\n cp = sqrt(a*a+(1-a*a)*u*u)\n cq = sqrt(b*b+(1-b*b)*u*u)\n dsum = 2*log(q*(1/cp+1/cq)/2) - ceuler\n dsum = dsum*(1-3*u*u)/(cp*cq)\n if(k.eq.0)dsum=dsum/2\n if(k.eq.np)dsum=dsum/2\n sum = sum + dsum\n enddo\n fmohl = 8*pi*du*sum\n! write(6,*)'a,b,q,fmohl',a,b,q,fmohl\n return\nend\n\n", "meta": {"hexsha": "c29771a03e5cf06ff7c5fbd3975bb4244e676b4e", "size": 1352, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ctef2py/f90_fmohl/fmohl.f90", "max_stars_repo_name": "tomerten/ctef2py", "max_stars_repo_head_hexsha": "190b83819e0ada830b76577e3f46d0d1cbbbacd7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ctef2py/f90_fmohl/fmohl.f90", "max_issues_repo_name": "tomerten/ctef2py", "max_issues_repo_head_hexsha": "190b83819e0ada830b76577e3f46d0d1cbbbacd7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ctef2py/f90_fmohl/fmohl.f90", "max_forks_repo_name": "tomerten/ctef2py", "max_forks_repo_head_hexsha": "190b83819e0ada830b76577e3f46d0d1cbbbacd7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.5789473684, "max_line_length": 113, "alphanum_fraction": 0.4363905325, "num_tokens": 377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342049451595, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.7753318551790643}} {"text": "!---------------------------------------------------------------*\n\n!\n! This subroutine finds the inverse of a 3x3 matrix and finds\n! its determinant\n!\n! Andrew Spakowitz\n! Written 9-1-04\n\n subroutine MinV(A,B,DET)\n\n real(dp) A(3,3) ! Original matrix\n real(dp) B(3,3) ! Inverse matrix\n real(dp) DET ! Determinant\n real(dp) COA(3,3) ! Cofactor of A\n\n\n! First find the determinant\n\n DET = A(1,1)*(A(2,2)*A(3,3)-A(2,3)*A(3,2)) + A(1,2)*(A(2,3)*A(3,1)-A(2,1)*A(3,3)) + A(1,3)*(A(2,1)*A(3,2)-A(2,2)*A(3,1))\n\n! Find the Cofactor of A\n\n COA(1,1) = A(2,2)*A(3,3)-A(2,3)*A(3,2)\n COA(1,2) = -(A(2,1)*A(3,3)-A(2,3)*A(3,1))\n COA(1,3) = A(2,1)*A(3,2)-A(2,2)*A(3,1)\n COA(2,1) = -(A(1,2)*A(3,3)-A(1,3)*A(3,2))\n COA(2,2) = A(1,1)*A(3,3)-A(1,3)*A(3,1)\n COA(2,3) = -(A(1,1)*A(3,2)-A(1,2)*A(3,1))\n COA(3,1) = A(1,2)*A(2,3)-A(1,3)*A(2,2)\n COA(3,2) = -(A(1,1)*A(2,3)-A(1,3)*A(2,1))\n COA(3,3) = A(1,1)*A(2,2)-A(1,2)*A(2,1)\n\n! Find the inverse of A\n\n B(1,1) = COA(1,1)/DET\n B(1,2) = COA(2,1)/DET\n B(1,3) = COA(3,1)/DET\n B(2,1) = COA(1,2)/DET\n B(2,2) = COA(2,2)/DET\n B(2,3) = COA(3,2)/DET\n B(3,1) = COA(1,3)/DET\n B(3,2) = COA(2,3)/DET\n B(3,3) = COA(3,3)/DET\n\n RETURN\n END\n\n!---------------------------------------------------------------*", "meta": {"hexsha": "ec12725c2d7f3838d4d384bb9d2f6b66638ad072", "size": 1371, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/legacy/MINV.f90", "max_stars_repo_name": "SpakowitzLab/BasicWLC", "max_stars_repo_head_hexsha": "13edbbc8e8cd36a3586571ff4d80880fc89d30e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-16T01:39:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-16T01:39:18.000Z", "max_issues_repo_path": "src/legacy/MINV.f90", "max_issues_repo_name": "riscalab/wlcsim", "max_issues_repo_head_hexsha": "e34877ef6c5dc83c6444380dbe624b371d70faf2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2016-07-08T21:17:40.000Z", "max_issues_repo_issues_event_max_datetime": "2017-01-24T09:05:25.000Z", "max_forks_repo_path": "src/legacy/MINV.f90", "max_forks_repo_name": "riscalab/wlcsim", "max_forks_repo_head_hexsha": "e34877ef6c5dc83c6444380dbe624b371d70faf2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2016-06-21T22:03:53.000Z", "max_forks_repo_forks_event_max_datetime": "2016-11-10T00:55:01.000Z", "avg_line_length": 27.9795918367, "max_line_length": 126, "alphanum_fraction": 0.4099197666, "num_tokens": 691, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.956634196290671, "lm_q2_score": 0.8104788995148791, "lm_q1q2_score": 0.7753318306479638}} {"text": "\n! The first two consecutive numbers to have two distinct prime factors are:\n!\n! 14 = 2 × 7\n! 15 = 3 × 5\n!\n! The first three consecutive numbers to have three distinct prime factors\n! are:\n!\n! 644 = 2² × 7 × 23\n! 645 = 3 × 5 × 43\n! 646 = 2 × 17 × 19.\n!\n! Find the first four consecutive integers to have four distinct prime factors\n! each. What is the first of these numbers?\n!\n! Project Euler: 47\n!\n! Answer: 134043\n\n\nprogram main\n\n use euler\n\nimplicit none\n\n ! This code starts by picking a number and then adding to it to see if\n ! the number of factors is equal to the number that we are looking for.\n ! If so, it checks the next consecutive number to see if it too has the\n ! same property. If in any event that it does not, but has passed the\n ! zero threshold, we can add the number that did pass the constraint\n ! and move one past that for we know that those integers have been\n ! check and will not contribute to a successful solution.\n\n integer (int32), parameter :: N_CONSEC = 4;\n integer (int32) :: c, i;\n\n c = 0; i = 0;\n\n do while (c /= N_CONSEC)\n\n call inc(i, (c + 1));\n c = 0;\n\n do while(count_factors(i + c) == N_CONSEC .AND. c < N_CONSEC)\n call inc(c, 1);\n end do\n\n end do\n\n call printint(i);\n\ncontains\n\n\n ! We remove all factors of two so that we can iterate via two, by only\n ! checking the odd numbers henceforth. We also divide by the number\n ! which is a factor such that we arrive at our upper limit sooner. If\n ! `n` is equal to one, then this means that we successfully got all the\n ! prime factors. If not, then it must in fact be a prime, and thus we\n ! must add this for we don't iterate up to the original number itself\n\n function count_factors(n)\n \n integer (int32) :: count_factors, n, i;\n\n count_factors = intbool(.NOT. BTEST(n, 0));\n\n do while (.NOT. BTEST(n, 0)); n = ISHFT(n, -1); end do;\n\n i = 3;\n\n do while ((i * i) < n)\n\n call inc(count_factors, intbool(mod(n, i) == 0));\n\n do while (mod(n, i) == 0)\n n = n / i;\n end do\n\n call inc(i, 2);\n end do \n\n call inc(count_factors, intbool(n > 1));\n\n end function count_factors\n\n\n ! This function directly replicates the integer equivalence of booleans\n ! in C. This is solid functionality that it turns out I can't live\n ! without.\n\n pure function intbool(logical)\n \n integer (int32) :: intbool;\n logical, intent(in) :: logical\n\n intbool = merge(1, 0, (logical));\n\n end function intbool\n\n\nend program main\n\n", "meta": {"hexsha": "310c222336bfcc181eb20cf29a6fb89bb670f632", "size": 2956, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/distinct_prime_factors.f95", "max_stars_repo_name": "guynan/project_euler", "max_stars_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-03-08T09:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T13:52:49.000Z", "max_issues_repo_path": "fortran/distinct_prime_factors.f95", "max_issues_repo_name": "guynan/project_euler", "max_issues_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-11-03T01:20:46.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-24T22:54:59.000Z", "max_forks_repo_path": "fortran/distinct_prime_factors.f95", "max_forks_repo_name": "guynan/project_euler", "max_forks_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-11-03T01:14:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T13:52:51.000Z", "avg_line_length": 27.8867924528, "max_line_length": 79, "alphanum_fraction": 0.552435724, "num_tokens": 725, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811307, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.7751978219858132}} {"text": "!> Utility and math functions\nmodule coneangle_util\n use coneangle_env, only: wp\n implicit none(type, external)\n\n private\n public :: binomial, cross_product, get_distances, solve_quadratic, vector_angle\n\ncontains\n pure function binomial(n, k)\n !! Returns binomial coefficient \\( \\binom{n}{k} \\)\n !> n\n integer, intent(in) :: n\n !> k\n integer, intent(in) :: k\n !> Binomial coefficient\n integer :: binomial\n\n binomial = nint(exp(log_gamma(n + 1.0_wp) - log_gamma(n - k + 1.0_wp) - log_gamma(k + 1.0_wp)))\n end function binomial\n\n pure function cross_product(a, b)\n !! Returns cross product between two vectors \\( a \\times b \\)\n !> First vector\n real(wp), intent(in) :: a(3)\n !> Second vector\n real(wp), intent(in) :: b(3)\n !> Cross product\n real(wp) :: cross_product(3)\n\n cross_product(1) = a(2)*b(3) - b(2)*a(3)\n cross_product(2) = a(3)*b(1) - b(3)*a(1)\n cross_product(3) = a(1)*b(2) - a(2)*b(1)\n end function cross_product\n\n pure function get_distances(a, b) result(distances)\n !! Calculate distance between point and group of points\n !> Point\n real(wp), intent(in) :: a(:)\n !> Group of points\n real(wp), intent(in) :: b(:, :)\n !> Distances\n real(wp) :: distances(size(b, 2))\n\n distances = norm2(spread(a, 2, size(b, 2)) - b, 1)\n end function get_distances\n\n pure function solve_quadratic(a, b, c) result(roots)\n !! Return roots for quadratic equation \\( ax^2 + bx + c = 0 \\)\n !> a*x**2\n real(wp), intent(in) :: a\n !> b*x\n real(wp), intent(in) :: b\n !> c\n real(wp), intent(in) :: c\n !> Roots\n complex(wp) :: roots(2)\n\n associate (delta => sqrt(cmplx(b**2 - 4*a*c, kind=wp)))\n roots(1) = (-b + delta)/(2*a)\n roots(2) = (-b - delta)/(2*a)\n end associate\n end function solve_quadratic\n\n pure function vector_angle(a, b) result(angle)\n !! Calculate angle between vectors\n !> First vector\n real(wp), intent(in) :: a(3)\n !> Second vector\n real(wp), intent(in) :: b(3)\n !> Angle (radians)\n real(wp) :: angle\n\n angle = atan2(norm2(cross_product(a, b)), dot_product(a, b))\n end function vector_angle\nend module coneangle_util\n", "meta": {"hexsha": "f9d2bd976833b354bb75c5c983d2fe9ac6e21126", "size": 2176, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/util.f90", "max_stars_repo_name": "kjelljorner/libconeangle", "max_stars_repo_head_hexsha": "52ef8f38d41a8d6feea0869f457a85598cf6e59b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2022-03-21T07:02:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T22:58:32.000Z", "max_issues_repo_path": "src/util.f90", "max_issues_repo_name": "kjelljorner/libconeangle", "max_issues_repo_head_hexsha": "52ef8f38d41a8d6feea0869f457a85598cf6e59b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-03-26T10:24:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T14:12:02.000Z", "max_forks_repo_path": "src/util.f90", "max_forks_repo_name": "kjelljorner/libconeangle", "max_forks_repo_head_hexsha": "52ef8f38d41a8d6feea0869f457a85598cf6e59b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2597402597, "max_line_length": 99, "alphanum_fraction": 0.6075367647, "num_tokens": 689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.948154531885212, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7751869426494505}} {"text": "!##############################################################################\n! PROGRAM oligopoly2\n!\n! ## Multi-dimensional rootfinding using the Gauss-Seidel iteration approach\n!\n! This code is published under the GNU General Public License v3\n! (https://www.gnu.org/licenses/gpl-3.0.en.html)\n!\n! Authors: Hans Fehr and Fabian Kindermann\n! contact@ce-fortran.com\n!\n! #VC# VERSION: 1.0 (23 January 2018)\n!\n!##############################################################################\nprogram oligopoly2\n\n implicit none\n real*8 :: eta = 1.6d0\n real*8 :: c(2) = (/ 0.6d0, 0.8d0 /)\n real*8 :: qold(2), q(2), QQ, damp\n integer :: iter\n\n ! initialize q\n qold = 0.1d0\n damp = 0.7d0\n\n do iter = 1, 100\n\n QQ = sum(qold)\n q = 1d0/c*(QQ**(-1d0/eta)-1d0/eta*QQ**(-1d0/eta-1d0)*qold)\n q = damp*q + (1d0-damp)*qold\n\n ! write to screen\n write(*, '(a, i5,2f10.4)')'Iter: ', iter, q(1), q(2)\n\n ! check for convergence\n if( all(abs(q-qold) < 1d-6))then\n write(*,'(/a, 2f10.4)')' Output', q(1), q(2)\n stop\n endif\n\n ! update q\n qold = q\n enddo\n\nend program\n\n\n", "meta": {"hexsha": "f76a4739bbc76b159c1c6f3f3f5d01e2575584d4", "size": 1202, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog02/prog02_09/prog02_09.f90", "max_stars_repo_name": "aswinvk28/modflow_fortran", "max_stars_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "complete/prog02/prog02_09/prog02_09.f90", "max_issues_repo_name": "aswinvk28/modflow_fortran", "max_issues_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "complete/prog02/prog02_09/prog02_09.f90", "max_forks_repo_name": "aswinvk28/modflow_fortran", "max_forks_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-07T12:27:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-07T12:27:47.000Z", "avg_line_length": 24.5306122449, "max_line_length": 79, "alphanum_fraction": 0.4642262895, "num_tokens": 385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624257, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7751009795658473}} {"text": "PROGRAM main\n!\n! Purpose:\n! Just for homework 8 in chapter6\n!\n! Record of revisions:\n! Date Programmer Description of change\n! ==== ========== =====================\n! 04/12/17 hopeful Original code\n!\nIMPLICIT NONE\nINTEGER :: I\nINTEGER :: countA, countB\n\ncountA = 1\ncountB = 1\nDO I = 0, 24, 6\n call CMA(1, I, countA)\n call CMB(1, I, countB)\n WRITE (*,*) 'After ', I, ' hours, culture medium A has ', countA, ' germs.' \n WRITE (*,*) 'After ', I, ' hours, culture medium B has ', countB, ' germs.'\nEND DO\n\nEND PROGRAM main\n\nSUBROUTINE CMA (icount, time, fcount)\nIMPLICIT NONE\n\nINTEGER :: icount ! 初始数目\nINTEGER :: time ! 培养时间(h)\nINTEGER :: fcount ! 最终数目\n\nfcount = icount * 2 ** (time * 60 / 90)\n\nEND SUBROUTINE CMA\n\nSUBROUTINE CMB (icount, time, fcount)\nIMPLICIT NONE\n \nINTEGER :: icount ! 初始数目\nINTEGER :: time ! 培养时间(h)\nINTEGER :: fcount ! 最终数目\n\nfcount = icount * 2 ** (time * 60 / 120)\n\nEND SUBROUTINE CMB\n", "meta": {"hexsha": "cb9d037a78388db12121b96e260c46adb3fc6ecd", "size": 950, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "homework/chapter6/6_8/main.f90", "max_stars_repo_name": "hopeful0/fortran-study", "max_stars_repo_head_hexsha": "7bd50580436e747f428cefeda2ba595893867503", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "homework/chapter6/6_8/main.f90", "max_issues_repo_name": "hopeful0/fortran-study", "max_issues_repo_head_hexsha": "7bd50580436e747f428cefeda2ba595893867503", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "homework/chapter6/6_8/main.f90", "max_forks_repo_name": "hopeful0/fortran-study", "max_forks_repo_head_hexsha": "7bd50580436e747f428cefeda2ba595893867503", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.2127659574, "max_line_length": 80, "alphanum_fraction": 0.6031578947, "num_tokens": 337, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.775062584303812}} {"text": "module d_pend\r\n integer, parameter :: dp2 = kind(1.0d0)\r\n real(dp2) :: l1, l2, m1, m2, ms\r\nend module d_pend\r\n\r\nprogram main\r\n use d_pend\r\n implicit none\r\n call d_pend_stat\r\n call d_pend_adapt\r\nend program main\r\n\r\nsubroutine d_pend_stat\r\n use d_pend\r\n use ode_int\r\n implicit none\r\n integer, parameter :: n = 4\r\n real(dp), parameter :: rad = atan(1._dp)/45._dp\r\n real(dp) :: t, dt, tmax, dtheta\r\n real(dp) :: yi(n)\r\n real(dp), dimension(size(yi)) :: yf, dydt, er\r\n real(dp) :: start, finish\r\n interface\r\n subroutine d_pend_deriv(t,y,dydt)\r\n implicit none\r\n real(dp), intent(in) :: t, y(:)\r\n real(dp), intent(out) :: dydt(:)\r\n end subroutine d_pend_deriv\r\n end interface\r\n\r\n open(unit=1, file = 'd_pend_stat.plt')\r\n ! Initial conditions.\r\n t = 0._dp\r\n tmax = 50._dp\r\n dt = 5.d-3\r\n l1 = 5._dp\r\n l2 = 9._dp\r\n m1 = 13._dp\r\n m2 = 50._dp\r\n yi(1) = 173._dp*rad\r\n yi(2) = -86._dp*rad\r\n dydt(1) = -3._dp*rad\r\n dydt(2) = 35._dp*rad\r\n ms = m1 + m2\r\n dtheta = yi(1) - yi(2)\r\n yi(3) = ms*l1*l1*dydt(1) + m2*l1*l2*dydt(2)*cos(dtheta)\r\n yi(4) = m2*l2*l2*dydt(2) + m2*l1*l2*dydt(1)*cos(dtheta)\r\n ! Print initial conditions.\r\n write(1,*) t,yi(1),yi(2),yi(3),yi(4),l1*sin(yi(1)),-l1*cos(yi(1)),l1*sin(yi(1))+l2*sin(yi(2)),-l1*cos(yi(1))-l2*cos(yi(2))\r\n\r\n call cpu_time(start)\r\n do while (t < tmax)\r\n call rkck(d_pend_deriv,t,yi,yf,er,dt)\r\n ! Preparing next step.\r\n t = t + dt\r\n yi(:) = yf(:)\r\n ! Writing current results.\r\n write(1,*) t,yf(1),yf(2),yf(3),yf(4),l1*sin(yf(1)),-l1*cos(yf(1)),l1*sin(yf(1))+l2*sin(yf(2)),-l1*cos(yf(1))-l2*cos(yf(2))\r\n end do\r\n call cpu_time(finish)\r\n print '(\"Time = \",f6.3,\" seconds.\")',finish-start\r\nend subroutine d_pend_stat\r\n\r\nsubroutine d_pend_adapt\r\n use d_pend\r\n use ode_int\r\n implicit none\r\n integer, parameter :: n = 4\r\n real(dp), parameter :: rad = atan(1.)/45.\r\n real(dp) t, dt, dtmin, tmax, dtheta, der\r\n real(dp) y(n)\r\n real(dp), dimension(size(y)) :: dydt, er\r\n real(dp) start, finish\r\n interface\r\n subroutine d_pend_deriv(t,y,dydt)\r\n implicit none\r\n real(dp), intent(in) :: t, y(:)\r\n real(dp), intent(out) :: dydt(:)\r\n end subroutine\r\n end interface\r\n\r\n open(unit=1, file = 'd_pend_adapt.plt')\r\n ! Initial conditions.\r\n t = 0._dp\r\n tmax = 50._dp\r\n dt = 5.d-3\r\n dtmin = 4.375d-3\r\n der = 1.3125d-7\r\n l1 = 5._dp\r\n l2 = 9._dp\r\n m1 = 13._dp\r\n m2 = 50._dp\r\n y(1) = 173._dp*rad\r\n y(2) = -86._dp*rad\r\n dydt(1) = -3._dp*rad\r\n dydt(2) = 35._dp*rad\r\n ms = m1 + m2\r\n dtheta = y(1) - y(2)\r\n y(3) = ms*l1*l1*dydt(1) + m2*l1*l2*dydt(2)*cos(dtheta)\r\n y(4) = m2*l2*l2*dydt(2) + m2*l1*l2*dydt(1)*cos(dtheta)\r\n ! Print initial conditions.\r\n write(1,*) t,y(1),y(2),y(3),y(4),l1*sin(y(1)),-l1*cos(y(1)),l1*sin(y(1))+l2*sin(y(2)),-l1*cos(y(1))-l2*cos(y(2))\r\n\r\n call cpu_time(start)\r\n do while (t < tmax)\r\n call rkcka(d_pend_deriv,t,y,der,dt,dtmin)\r\n ! Writing current results.\r\n write(1,*) t,y(1),y(2),y(3),y(4),l1*sin(y(1)),-l1*cos(y(1)),l1*sin(y(1))+l2*sin(y(2)),-l1*cos(y(1))-l2*cos(y(2))\r\n end do\r\n call cpu_time(finish)\r\n print '(\"Time = \",f6.3,\" seconds.\")',finish-start\r\nend subroutine d_pend_adapt\r\n\r\nsubroutine d_pend_deriv(t,y,dydt)\r\n! y(1) = theta1 dydt(1) = theta1'\r\n! y(2) = theta2 dydt(2) = theta2'\r\n! y(3) = p1 dydt(3) = p1'\r\n! y(4) = p2 dydt(4) = p2'\r\nuse d_pend\r\nimplicit none\r\nreal(dp2) :: dtheta, den, c1, c2\r\nreal(dp2), intent(in) :: t, y(:)\r\nreal(dp2), intent(out):: dydt(:)\r\nreal(dp2), parameter :: g = 9.81_dp2\r\ndtheta = y(1) - y(2)\r\nden = m1 + m2*sin(dtheta)*sin(dtheta)\r\nc1 = (y(3)*y(4)*sin(dtheta))/(l1*l2*den)\r\nc2 = (l2*l2*m2*y(3)*y(3) + l1*l1*ms*y(4)*y(4) - l1*l2*m2*y(3)*y(4)*cos(dtheta))/(2*l1*l1*l2*l2*den*den)*sin(2*dtheta)\r\ndydt(1) = (l2*y(3)-l1*y(4)*cos(dtheta))/(l1*l1*l2*den)\r\ndydt(2) = (l1*ms*y(4)-l2*m2*y(3)*cos(dtheta))/(l1*l2*l2*m2*den)\r\ndydt(3) = -ms*g*l1*sin(y(1)) - c1 + c2\r\ndydt(4) = -m2*g*l2*sin(y(2)) + c1 - c2\r\nend subroutine d_pend_deriv\r\n", "meta": {"hexsha": "56b0341a15a6373a2f66e00c5b942cec80ce1fba", "size": 4029, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "ode/double_pendulum.f08", "max_stars_repo_name": "dcelisgarza/applied_math", "max_stars_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2015-09-30T19:22:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T23:33:04.000Z", "max_issues_repo_path": "ode/double_pendulum.f08", "max_issues_repo_name": "dcelisgarza/applied_math", "max_issues_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ode/double_pendulum.f08", "max_forks_repo_name": "dcelisgarza/applied_math", "max_forks_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0671641791, "max_line_length": 127, "alphanum_fraction": 0.5626706379, "num_tokens": 1755, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7750020878416463}} {"text": "subroutine jacobi(a, b, u, eps, nmaxit, ier)\n implicit none\n\n real(8), dimension(:,:), intent(in) :: a\n real(8), dimension(:), intent(in) :: b\n real(8), dimension(:), intent(out) :: u\n real(8), intent(in) :: eps\n integer, intent(in) :: nmaxit\n integer, intent(out) :: ier\n\n real(8), dimension(:), allocatable :: v\n real(8) :: s, err\n integer :: n, i, j, k\n\n n = size(b)\n\n allocate(v(n))\n\n do k=1, nmaxit\n print*,\n print*,'Iterante',k\n print*,u(:)\n print*,\n err = 0\n do i=1,n\n s = 0\n do j = 1, i-1\n s = s + a(i,j)*u(j)\n end do\n\n do j = i+1, n\n s = s + a(i,j)*u(j)\n end do\n\n v(i) = (b(i) - s)/a(i,i)\n end do\n\n do i = 1, n\n err = err + abs(v(i))\n u(i) = v(i)\n end do\n\n if(err < eps) then\n ier = 0\n return\n end if\n end do\n ier = 1\nend subroutine\n", "meta": {"hexsha": "f982f771a5cf270d7a842b87c51222f103da57c9", "size": 860, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Practica4_jacobi/jacobi.f95", "max_stars_repo_name": "JP-Amboage/Matrix-Numerical-Analysis", "max_stars_repo_head_hexsha": "de2c069a651579b4d281f3e71db7d1635f148973", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-04-02T18:09:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-16T14:08:07.000Z", "max_issues_repo_path": "Practica4_jacobi/jacobi.f95", "max_issues_repo_name": "JP-Amboage/Matrix-Numerical-Analysis", "max_issues_repo_head_hexsha": "de2c069a651579b4d281f3e71db7d1635f148973", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practica4_jacobi/jacobi.f95", "max_forks_repo_name": "JP-Amboage/Matrix-Numerical-Analysis", "max_forks_repo_head_hexsha": "de2c069a651579b4d281f3e71db7d1635f148973", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-04-05T13:18:12.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-04T10:32:14.000Z", "avg_line_length": 17.2, "max_line_length": 44, "alphanum_fraction": 0.4709302326, "num_tokens": 333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7750020858916135}} {"text": "program prime_number_function\n implicit none\n integer, parameter :: n_min = 1, n_max = 40\n integer :: n\n\n do n = n_min, n_max\n if (is_prime(n)) then\n print *, n, 'prime'\n else\n print *, n, 'not prime'\n end if\n end do\n\ncontains\n\n logical function is_prime(n)\n implicit none\n integer, intent(in) :: n\n integer :: divisor\n\n if (n == 1) then\n is_prime = .false.\n else\n is_prime = .true.\n do divisor = 2, n/2\n if (mod(n, divisor) == 0) then\n is_prime = .false.\n exit\n end if\n end do\n end if\n end function is_prime\n\nend program prime_number_function\n", "meta": {"hexsha": "a9d2ef5e1df106b8c0628247b9a6f27ea9a07772", "size": 764, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "hands-on/session_02/exercise_03c.f90", "max_stars_repo_name": "gjbex/FortranForProgrammers", "max_stars_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-15T14:56:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-15T14:56:20.000Z", "max_issues_repo_path": "hands-on/session_02/exercise_03c.f90", "max_issues_repo_name": "gjbex/FortranForProgrammers", "max_issues_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hands-on/session_02/exercise_03c.f90", "max_forks_repo_name": "gjbex/FortranForProgrammers", "max_forks_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.8285714286, "max_line_length": 47, "alphanum_fraction": 0.4803664921, "num_tokens": 191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299570920387, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7749910864847102}} {"text": " program main\nc\nc compute zt and zw (layer mid points and boundaries) using\nc sin^2 stretching in BL, fixed dz above, increasing aloft \nc\n integer, parameter :: nz = 96\n\n real zt(nz)\n real zw(nz+1)\n\nc ... input parameters\n\nc ... top of domain (m)\n domain_H = 1500.\n\nc ... minimum dz (m)\n dzmin = 5.0 \n\nc ... thickness of layers in normalized (bar) units\n dz = domain_H / nz\n\nc ... heights of dz minimum aloft and overlying dz minimum (m)\n zi = 800.\n zf = 925.\n\nc ... possibly adjust dzmin to fit evenly between zi and zf\n if ( zi < zf ) then\n nzmin = nint((zf - zi)/dzmin)\n dzmin = (zf - zi)/nzmin\n endif\n\nc ... fraction of grid below zi\n fzi = 0.55\n\nc ... indices of zi and zf\n ki = nint(fzi*nz)\n kf = ki + (zf - zi)/dzmin\n\nc ... normalized zi and zf \n zibar = dz*ki\n zfbar = dz*kf\n\nc ... ratio of minimum dz to H/nz\n fmin = dzmin / dz\n\nc ... derived parameters\n const_PI = 2*acos(0.)\n\n b = (2.0)*( (zi/zibar) - fmin )\n d = (3.0/((domain_H - zfbar)**2) )*(\n & (domain_H - zf)/(domain_H - zfbar) - fmin )\n\nc ... impossible grids\n if ( kf < ki .or. kf > nz+1 ) then\n print *, 'Error :: ki, kf, nz = ', ki, kf, nz\n stop\n endif\n if ( b < 0 ) then\n print *, 'Error :: b less than zero, b = ', b\n stop\n endif\n if ( d < 0 ) then\n print *, 'Error :: d less than zero, d = ', d\n stop\n endif\n\nc ... vertical positions of cell boundaries\n do k = 1, nz+1\n zbar = dz*(k-1)\n if ( k <= ki+1 ) then\n u = const_PI*zbar/zibar\n zz = fmin*zbar+ (b*zibar/const_PI)*\n & (u/2 - sin( 2.0*u )/4.0 )\n elseif ( k <= kf+1 ) then\n zz = zz + dzmin\n else\n dd = zbar - zfbar\n zz = zf + fmin*dd + d*dd*dd*dd/3.0\n endif\n zw(k) = zz\n enddo\n\nc ... layer mid-points\n do k = nz, 1, -1\n zt(k) = 0.5*zw(k) + 0.5*zw(k+1)\n enddo\n\nc ... print them out\n write(*,'(\" k zw zt dz\")')\n write(*,'(i4,2f7.1)') nz+1, zw(nz+1)\n do k = nz, 1, -1\n write(*,'(i4,3f7.1)') k, zw(k), zt(k), zw(k+1) - zw(k)\n enddo\n write(*,'(\" k zw zt dz\")')\n\n\nc ... prepare files for the UCLA LES input\n open (1,file='zm_grid_in',status='new',form='formatted')\n do k = 1, nz+1\n write(1,'(f7.1)') zw(k)\n end do\n close (1)\n\n open (2,file='zt_grid_in',status='new',form='formatted')\n zt0 = zt(1) - (zt(2)-zt(1))\n write(2,'(f7.1)') zt0\n do k = 1, nz\n write(2,'(f7.1)') zt(k)\n end do\n close (2)\n\n end\n", "meta": {"hexsha": "8c2c4569508a77bad6c99faf794e8d8d935aafca", "size": 2765, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "testcode/10_sor/codeBase_Original/UCLA_LES2.0/misc/initfiles/zgrid.gcss9.f", "max_stars_repo_name": "waqarnabi/tybec", "max_stars_repo_head_hexsha": "b69157146a58a195dd7c1856833fcd8f91edfe9f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-09T13:11:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-09T13:11:07.000Z", "max_issues_repo_path": "testcode/10_sor/codeBase_Original/UCLA_LES2.0/misc/initfiles/zgrid.gcss9.f", "max_issues_repo_name": "waqarnabi/tybec", "max_issues_repo_head_hexsha": "b69157146a58a195dd7c1856833fcd8f91edfe9f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "testcode/10_sor/codeBase_Original/UCLA_LES2.0/misc/initfiles/zgrid.gcss9.f", "max_forks_repo_name": "waqarnabi/tybec", "max_forks_repo_head_hexsha": "b69157146a58a195dd7c1856833fcd8f91edfe9f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.4690265487, "max_line_length": 66, "alphanum_fraction": 0.4672694394, "num_tokens": 966, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067244294588, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7749187822165324}} {"text": "! Objetivo: Determinar o angulo que resulta no alcance maximo de um projetil\n! sujeito a resistencia do ar para k no intervalo de 0 a 0,1.\n\nMODULE arremesso_projetil\n\tREAL, PARAMETER :: precisao=1.e-5, g=9.8, v0=600.0\n\tREAL :: k, g_div_k, v0_sin_theta\n\tLOGICAL :: succes\nCONTAINS\n\tSUBROUTINE funcd(t,altura_funct,deriv_funct)\n\t\tUSE nrtype\n\t\tIMPLICIT none\n\t\tREAL, INTENT(IN) :: T\n\t\tREAL, INTENT(OUT) :: altura_funct,deriv_funct\n\t\tREAL :: exp_menoskt \n\t\texp_menoskt= EXP(-k*T)\n\t\taltura_funct=-g_div_k*T+(v0_sin_theta + g_div_k)/k*&\n\t\t\t\t\t\t(1.0-exp_menoskt)\n\t\tderiv_funct=-g_div_k+(v0_sin_theta + g_div_k)*exp_menoskt \n\tEND SUBROUTINE funcd\n\tFUNCTION altura_funct(t)\n\t\tUSE nrtype\n\t\tREAL, INTENT(IN) :: T\n\t\texp_menoskt= EXP(-k*T)\n\t\taltura_funct=-g_div_k*t+(v0_sin_theta+g_div_k)/k*&\n\t\t\t\t\t\t(1.0-exp_menoskt)\n\tEND FUNCTION\n\tFUNCTION alcance(theta)\n\t\tUSE nrtype\n\t\tUSE nr, ONLY:rtsafe\n\t\tIMPLICIT none\n\t\tREAL, INTENT(IN) :: theta\n\t\tREAL :: T, t_1, t_2, alcance\n\t\tv0_sin_theta=v0*sin(theta)\n\t\tg_div_k=g/k\n! A funcao altura_funct foi derivada e igualada a zero para encontrar o\n! ponto de maximo (t_1, f(t_1)). Desse modo, t_1 eh o ponto de altura maxima\n! para qualquer valor de k.\n\t\tt_1= REAL(-LOG(g/(k*v0_sin_theta+g))/k)\n\t\tt_2= REAL(1.0/k+v0_sin_theta/g)\n! Agora T estah entre t_1 e t_2, usando a rtsafe encontramos o valor de T\n\t\tT = rtsafe(funcd,t_1,t_2,precisao)\n\t\talcance=-(v0*cos(theta)*(1.0-exp(-k*T))/k)\n\tEND FUNCTION\nEND MODULE arremesso_projetil\nPROGRAM alcance_maximo\n\tUSE arremesso_projetil\n\tUSE nrtype\n\tUSE nr, ONLY: rtsafe, brent\n\tIMPLICIT none \n\tREAL :: R,v0_sob_k, R_max\n\tINTEGER :: contador_ponto\n\tINTEGER, PARAMETER :: r_theta_vs_k=8,pontos=300,pontos_menos1=pontos-1\n\tREAL :: theta_inicial=0.0,theta_intermed=0.5*PIO2\n\tREAL :: theta_final=PIO2,theta_max\n\tREAL, PARAMETER :: k_inicial=0.0,k_final=0.1\n\tREAL, PARAMETER :: v0_quad_g=(v0**2)/g\n\tREAL, PARAMETER :: variacao_k=(k_final-k_inicial)/REAL(pontos_menos1)\n\tOPEN(unit=r_theta_vs_k,file=\"R_theta_x_k.dat\")\n\tk=k_inicial\n\tR_max=v0_quad_g\n\ttheta_max = theta_intermed\n\tWRITE(unit=r_theta_vs_k,fmt=*) k, R_max, theta_max\n\tk=k+variacao_k\n! Para outros valores de k\n\tDO contador_ponto=1, pontos_menos1\n! Dada a funcao alcance e um trio de abscissas theta_inicial=0.0, theta_intermed\n! e theta_final=PIO2 que delimitam um minimo (tal que theta_intermed esta entre\n! theta_inicial e theta_final, e o alcance(theta_intermed) eh menor que o\n! alcance(0.0) e alcance(PIO2)). A funcao brent calcula o alcance minimo, \n! multiplicando por -1 encontramos os valores maximos do alcance.\n\t\tR_max = -brent(theta_inicial,theta_intermed,theta_final,alcance,&\n\t\t\t\t\t\t\tprecisao,theta_max)\n\t\tWRITE(unit=r_theta_vs_k, fmt=*) k, R_max, theta_max\n\t\tk=k+variacao_k\n\tEND DO \n\tCLOSE(unit=r_theta_vs_k)\nEND PROGRAM alcance_maximo\n", "meta": {"hexsha": "7a5054a6a4c6f8cf0357cd18bcfb664a0d37c605", "size": 2767, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "alcance_max.f90", "max_stars_repo_name": "GuilhermeMonteiroPeixoto/Computational-Physics-using-Fortran", "max_stars_repo_head_hexsha": "3d2b3dd87d99b451aed5fe1e9e99813390396485", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "alcance_max.f90", "max_issues_repo_name": "GuilhermeMonteiroPeixoto/Computational-Physics-using-Fortran", "max_issues_repo_head_hexsha": "3d2b3dd87d99b451aed5fe1e9e99813390396485", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "alcance_max.f90", "max_forks_repo_name": "GuilhermeMonteiroPeixoto/Computational-Physics-using-Fortran", "max_forks_repo_head_hexsha": "3d2b3dd87d99b451aed5fe1e9e99813390396485", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.4743589744, "max_line_length": 80, "alphanum_fraction": 0.7430430069, "num_tokens": 1024, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067147399245, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7749187763031185}} {"text": "PROGRAM stats_5\nIMPLICIT NONE\nREAL, ALLOCATABLE, DIMENSION(:) :: a\nCHARACTER(len=20) :: filename\nINTEGER :: i, iptr, j, status\nREAL :: median, std_dev, sum_x = 0., sum_x2 = 0., temp, x_bar\nCHARACTER(len=80) :: msg\nINTEGER :: nvals = 0\n\nWRITE(*, 1000)\n1000 FORMAT ('Enter the filename with the data to be sorted:')\nREAD(*, '(A20)') filename\n\nOPEN(UNIT=9, FILE=filename, STATUS='OLD', ACTION='READ', &\n IOSTAT=status, IOMSG=msg)\n\nfileopen: IF (status == 0) THEN\n DO\n READ(9, *, IOSTAT=status) temp\n IF (status /= 0) EXIT\n nvals = nvals + 1\n END DO\n\n WRITE(*, '(A,I12)') 'Allocating a: size = ', nvals\n ALLOCATE (a(nvals), STAT=status)\n\n allocate_ok: IF (status == 0) THEN\n REWIND(UNIT=9)\n READ(9, *) a\n outer: DO i = 1, nvals - 1\n iptr = i\n inner: DO j = i + 1, nvals\n minval: IF (a(j) < a(iptr)) THEN\n iptr = j\n END IF minval\n END DO inner\n\n swap: IF (i /= iptr) THEN\n temp = a(i)\n a(i) = a(iptr)\n a(iptr) = temp\n END IF swap\n END DO outer\n\n sums: DO i = 1, nvals\n sum_x = sum_x + a(i)\n sum_x2 = sum_x2 + a(i)**2\n END DO sums\n\n enough: IF (nvals < 2) THEN\n WRITE(*, *) 'At least 2 values must be entered.'\n ELSE\n x_bar = sum_x / REAL(nvals)\n std_dev = SQRT((REAL(nvals) * sum_x2 - sum_x**2) &\n / (REAL(nvals) * real(nvals - 1)))\n even: IF (MOD(nvals, 2) == 0) THEN\n median = (a(nvals/2) + a(nvals/2+1)) / 2.\n ELSE\n median = a(nvals/2+1)\n END IF even\n WRITE(*, '(A,F8.3)') 'MEAN: ', x_bar\n WRITE(*, '(A,F8.3)') 'MEDIAN: ', median\n WRITE(*, '(A,F8.3)') 'STD_DEV: ', std_dev\n WRITE(*, '(A,I8)') 'N: ', nvals\n END IF enough\n DEALLOCATE(a, STAT=status)\n END IF allocate_ok\nELSE fileopen\n WRITE(*, 1050) TRIM(msg)\n 1050 FORMAT ('File open failed. Status: ', A)\nEND IF fileopen\nEND PROGRAM stats_5\n", "meta": {"hexsha": "3fb20418461707655fadbb4fa4a615d135ffbd62", "size": 1909, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap8/stats_5.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap8/stats_5.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap8/stats_5.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.1506849315, "max_line_length": 62, "alphanum_fraction": 0.5500261917, "num_tokens": 696, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294209307224, "lm_q2_score": 0.8577681031721324, "lm_q1q2_score": 0.7748169605238286}} {"text": "c This file contains four two user-callable subroutines: \nc gammanew_eval, gammanew_eval_extend, gammanew_eval_log, \nc gammanew_eval_extend_log. The first calculates the Gamma \nc function of a real argument (either positive or negative) \nc to full double precision. The second calculates the Gamma \nc function of a real argument (either positive or negative) \nc to (almost) full extended precision, provided the variables \nc are re-declared to support such precision.\nc\nc The subroutines gammanew_eval_log, gammanew_eval_extend_log\nc are identical to the subroutines gammanew_eval, \nc gammanew_eval_extend, with the exception that instead of the\nc gamma function they return the said function's logarithm.\nc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc\nc\n subroutine gammanew_eval_log_extend(x,gam)\n implicit real *8 (a-h,o-z)\n save\nc\nc This subroutine evaluates the logarithm of the Gamma function \nc of a real argument; it produces (almost) full extended \nc precision results for both positive and negative values \nc of the argument, provided the variables are re-declared \nc to support such precision.\nc\nc PLEASE NOTE THAT IN THE REGIMES WHERE THE GAMMA FUNCTION IS\nC NEGATIVE, THE SUBROUTINE RETURNS THE LOGARITHM OF ITS \nC ABSOLUTE VALUE.\nc\nc Input parameters:\nc\nc x - the argument of which the Gamma function is to be computed\nc\nc Output parameters:\nc\nc gam - the logarithm of the Gamma function of x (how very appropriate!)\nc\nc\nc . . . evaluate the logarithm of the Gamma function \nc if the argument is on the interval [1,2]\nc\n if( (x .lt. 1) .or. (x.gt. 2) ) goto 2200\nc\n call gammanew_eval3_log(x,gam)\n return\nc\n 2200 continue\nc\nc\nc ... if x > 2\nc\n if(x .lt. 1.5) goto 3200\nc\nc find x0 on the interval [1,2] with which we start,\nc and evaluate gamma at it\nc\n n=x\n x0=x-n+1\n call gammanew_eval3_log(x0,gam)\nc\nc march!\nc\n do 2400 i=2,n\nc\n gam=gam+log(i+x0-2)\n 2400 continue\nc\n return\nc\n 3200 continue\nc\nc ... if 0 .leq. x .leq. 1\nc\n if(x .lt. 0) goto 4200\nc\n x0=x+1\n call gammanew_eval3_log(x0,gam)\n gam=gam-log(x)\n return\nc\n 4200 continue\nc\nc ... if x < 0\nc\n x1=-x\n n=x1\n x0=x1-n\n x0=1-x0+1\nc\n call gammanew_eval3_log(x0,gam)\nc\n xx=x0-1\n do 5200 i=1,n+2\nc\n gam=gam-log(abs(xx))\n xx=xx-1\n 5200 continue\nc\n return\n end \nc\nc\nc\nc\nc\n subroutine gammanew_eval_log(x,gam)\n implicit real *8 (a-h,o-z)\n save\nc\nc This subroutine evaluates the logarithm of the Gamma function \nc of a real argument; it produces full double precision results \nc for both positive and negative values of the argument.\nc\nC PLEASE NOTE THAT IN THE REGIMES WHERE THE GAMMA FUNCTION IS\nC NEGATIVE, THE SUBROUTINE RETURNS THE LOGARITHM OF ITS \nC ABSOLUTE VALUE.\nC\nc Input parameters:\nc\nc x - the argument of which the Gamma function is to be computed\nc\nc Output parameters:\nc\nc gam - the logarithm of the Gamma function of x (how very appropriate!)\nc\nc\nc . . . evaluate the logarithm of the Gamma function \nc if the argument is on the interval [1,2]\nc\n if( (x .lt. 1) .or. (x.gt. 2) ) goto 2200\nc\n call gammanew_eval2_log(x,gam)\n return\nc\n 2200 continue\nc\nc\nc ... if x > 2\nc\n if(x .lt. 1.5) goto 3200\nc\nc find x0 on the interval [1,2] with which we start,\nc and evaluate gamma at it\nc\n n=x\n x0=x-n+1\n call gammanew_eval2_log(x0,gam)\nc\nc march!\nc\n do 2400 i=2,n\nc\n gam=gam+log(i+x0-2)\n 2400 continue\nc\n return\nc\n 3200 continue\nc\nc ... if 0 .leq. x .leq. 1\nc\n if(x .lt. 0) goto 4200\nc\n x0=x+1\n call gammanew_eval2_log(x0,gam)\n gam=gam-log(x)\n return\nc\n 4200 continue\nc\nc ... if x < 0\nc\n x1=-x\n n=x1\n x0=x1-n\n x0=1-x0+1\nc\n call prin2('x0=*',x0,1)\n\n call gammanew_eval2_log(x0,gam)\nc\n xx=x0-1\n do 5200 i=1,n+2\nc\n gam=gam-log(abs(xx))\n xx=xx-1\n 5200 continue\nc\n return\n end \nc\nc \nc \nc \nc \n subroutine gammanew_eval3_log(x,gam)\n implicit real *8 (a-h,o-z)\n dimension coefs(42)\n data coefs/\n 1 -.120782237635245222345518445781646D+00,\n 2 0.182449869892882602795118335006149D-01,\n 3 0.116850275068084913677155687492027D+00,\n 4 -.172665967548816665749236304400537D-01,\n 5 0.366950790104801363656336640942244D-02,\n 6 -.904752559027923226702063033929312D-03,\n 7 0.241179440157020317746429313847828D-03,\n 8 -.673640931966506793016607029366479D-04,\n 9 0.193973781620149128734637856623748D-04,\n * -.570502042708584364645567397395294D-05,\n 1 0.170413630448254881730170850280867D-05,\n 2 -.515095553646304672163231216170731D-06,\n 3 0.157154048593298006175111322327474D-06,\n 4 -.483119555232553485171697583494630D-07,\n 5 0.149457513722498842477000858912645D-07,\n 6 -.464831354195249220547668790930112D-08,\n 7 0.145232233619810644923193813836471D-08,\n 8 -.455578791522056192987778762139738D-09,\n 9 0.143413197588172550414382835362441D-09,\n * -.452865323417441015573380473066286D-10,\n 1 0.143403848882077097551112487075603D-10,\n 2 -.455243644934763089569345512431042D-11,\n 3 0.144848973320723395282144093531243D-11,\n 4 -.461834869766318701759601704380834D-12,\n 5 0.147530229774684050616043905322468D-12,\n 6 -.472095899923600758417333684711329D-13,\n 7 0.151310521710013342466880922231033D-13,\n 8 -.485686801476166232271748203132829D-14,\n 9 0.156144198997796652518964422860473D-14,\n * -.502544804552392246881299973067650D-15,\n 1 0.161580172500207145883271023448381D-15,\n 2 -.521114590948289341160665737783119D-16,\n 3 0.171382083302691489326179629126128D-16,\n 4 -.554748821197081512427887357740726D-17,\n 5 0.158673415478853248945912441533215D-17,\n 6 -.509788453463554343682988517338423D-18,\n 7 0.267137492143822801798879951011477D-18,\n 8 -.880385756441013041066119183271692D-19,\n 9 -.586092705483764190954532218784502D-20,\n * 0.220231881515274593029003021427310D-20,\n 1 0.645061720132042199184763314365149D-20,\n 2 -.212720240682484916622372020931097D-20/\nc\n save\nc\n n=42\n done=1\n gam=0\nc\n t=(x-1-done/2)*2 \nc\n do 1200 i=1,n\nc\n gam=gam+coefs(i)*t**(i-1)\ncccc gam=gam+coefs(i)*x**(i-1)\n 1200 continue\nc\n return\n end\nc\nc \nc \nc \nc \n subroutine gammanew_eval2_log(x,gam)\n implicit real *8 (a-h,o-z)\n dimension coefs(22)\nc\n data coefs/\n 1 -.120782237635245221D+00,0.182449869892882600D-01,\n 2 0.116850275068084696D+00,-.172665967548815972D-01,\n 3 0.366950790105704649D-02,-.904752559030809163D-03,\n 4 0.241179440011251918D-03,-.673640931500792339D-04,\n 5 0.193973793625582700D-04,-.570502081063888534D-05,\n 6 0.170413056607272862D-05,-.515093720376700298D-06,\n 7 0.157171045376283400D-06,-.483173853131163447D-07,\n 8 0.149136746086145614D-07,-.463806694457011235D-08,\n 9 0.149074784822671166D-08,-.467852246675690637D-09,\n * 0.115448734319838611D-09,-.363558981433883658D-10,\n 1 0.252470225044276880D-10,-.803435452853097061D-11/\nc\n save\nc\n n=22\n done=1\n gam=0\nc\n t=(x-1-done/2)*2 \nc\n do 1200 i=1,n\nc\n gam=gam+coefs(i)*t**(i-1)\ncccc gam=gam+coefs(i)*x**(i-1)\n 1200 continue\nc\n return\n end\nc\nc\nc\nc\nc\n subroutine gammanew_eval(x,gam)\n implicit real *8 (a-h,o-z)\n save\nc\nc This subroutine evaluates the Gamma function of a real argument;\nc it produces full double precision results for both positive and \nc negative values of the argument.\nc\nc Input parameters:\nc\nc x - the argument of which the Gamma function is to be computed\nc\nc Output parameters:\nc\nc gam - the Gamma function of x (how very appropriate!)\nc\nc\nc . . . evaluate the Gamma function if the argument is\nc on the interval [1,2]\nc\n if( (x .lt. 1) .or. (x.gt. 2) ) goto 2200\nc\n call gammanew_eval2(x,gam)\n return\nc\n 2200 continue\nc\nc\nc ... if the x > 2\nc\n if(x .lt. 1.5) goto 3200\nc\nc find x0 on the interval [1,2] with which we start,\nc and evaluate gamma at it\nc\n n=x\n x0=x-n+1\n call gammanew_eval2(x0,gam)\nc\nc march!\nc\n do 2400 i=2,n\nc\n gam=gam*(i+x0-2)\n 2400 continue\nc\n return\nc\n 3200 continue\nc\nc ... if the 0 .leq. x .leq. 1\nc\n if(x .lt. 0) goto 4200\nc\n x0=x+1\n call gammanew_eval2(x0,gam)\n gam=gam/x\n return\nc\n 4200 continue\nc\nc ... if x < 0\nc\n x1=-x\n n=x1\n x0=x1-n\n x0=1-x0+1\nc\n call gammanew_eval2(x0,gam)\nc\n xx=x0-1\n do 5200 i=1,n+2\nc\n gam=gam/xx\n xx=xx-1\n 5200 continue\nc\n return\n end \nc\nc \nc \nc \nc \n subroutine gammanew_eval_extend(x,gam)\n implicit real *8 (a-h,o-z)\n save\nc\nc This subroutine evaluates the Gamma function of a real argument;\nc it produces (almost) full extended precision results for both \nc positive and negative values of the argument, provided the \nc variables are re-declared to support such precision.\nc\nc Input parameters:\nc\nc x - the argument of which the Gamma function is to be computed\nc\nc Output parameters:\nc\nc gam - the Gamma function of x (how very appropriate!)\nc\nc\nc\nc evaluate the Gamma function if the argument is\nc on the interval [1,2]\nc\n if( (x .lt. 1) .or. (x.gt. 2) ) goto 2200\nc\n call gammanew_eval3(x,gam)\n return\nc\n 2200 continue\nc\nc\nc ... if the x > 2\nc\n if(x .lt. 1.5) goto 3200\nc\nc find x0 on the interval [1,2] with which we start,\nc and evaluate gamma at it\nc\n n=x\n x0=x-n+1\n call gammanew_eval3(x0,gam)\nc\nc march!\nc\n do 2400 i=2,n\nc\n gam=gam*(i+x0-2)\n 2400 continue\nc\n return\nc\n 3200 continue\nc\nc ... if the 0 .leq. x .leq. 1\nc\n if(x .lt. 0) goto 4200\nc\n x0=x+1\n call gammanew_eval3(x0,gam)\n gam=gam/x\n return\nc\n 4200 continue\nc\nc ... if x < 0\nc\n x1=-x\n n=x1\n x0=x1-n\n x0=1-x0+1\nc\n call gammanew_eval3(x0,gam)\nc\n xx=x0-1\n do 5200 i=1,n+2\nc\n gam=gam/xx\n xx=xx-1\n 5200 continue\nc\n return\n end \nc\nc \nc \nc \nc \n subroutine gammanew_eval3(x,gam)\n implicit real *8 (a-h,o-z)\n dimension coefs(42)\nc\n data coefs/\n 1 0.886226925452758013649083741670623D+00,\n 2 0.161691987244425069144349421339960D-01,\n 3 0.103703363422075292057509405775161D+00,\n 4 -.134118505705965264609427444590074D-01,\n 5 0.904033494028884643989576361780254D-02,\n 6 -.242259538437044385764617259435110D-02,\n 7 0.915785997143379523502915231849406D-03,\n 8 -.296890121522383830093923366409561D-03,\n 9 0.100928150217797671460960524521708D-03,\n * -.336375842059855958365225717995453D-04,\n 1 0.112524564378898714084403565633111D-04,\n 2 -.375498601769608326351463199728310D-05,\n 3 0.125284265183407932726509306293675D-05,\n 4 -.417822570478480417873660426799984D-06,\n 5 0.139318222887586378078540067572924D-06,\n 6 -.464480612525716981485156868788579D-07,\n 7 0.154844321007218425984980044056116D-07,\n 8 -.516182587481302823323689251947993D-08,\n 9 0.172067842623297864468229367955008D-08,\n * -.573573438914607316487896043927398D-09,\n 1 0.191193940645124209184837634463979D-09,\n 2 -.637318726733661744876732845701618D-10,\n 3 0.212440679157787075404568786925963D-10,\n 4 -.708137779578620656802105580438353D-11,\n 5 0.236046717483456631493100121338592D-11,\n 6 -.786824290629355714996723594265115D-12,\n 7 0.262268505662015465618725444423847D-12,\n 8 -.874213989908817094617396890755866D-13,\n 9 0.291499417333710813797738200069174D-13,\n * -.971833531575606294591946449847318D-14,\n 1 0.322856823583449058974923602843996D-14,\n 2 -.107469659233788012193712173282348D-14,\n 3 0.367876256573690494365473260918666D-15,\n 4 -.123625276708537256683380049874862D-15,\n 5 0.347433987117776040343629749755013D-16,\n 6 -.110914923764776138469573598500169D-16,\n 7 0.686389384962107642842040168449156D-17,\n 8 -.245328327855757521477785550619204D-17,\n 9 -.251052453492112032869491235353891D-18,\n * 0.118067019426474278738319173650695D-18,\n 1 0.182746800335155441155764424855902D-18,\n 2 -.642344360403561579751828672744009D-19/\nc\n save\nc\n n=42\n done=1\n gam=0\nc\n t=(x-1-done/2)*2 \nc\n tt=1\n do 1200 i=1,n\nc\n gam=gam+coefs(i)*tt\n tt=tt*t\n 1200 continue\nc\n return\n end\nc\nc \nc \nc \nc \n subroutine gammanew_eval2(x,gam) \n implicit real *8 (a-h,o-z)\n dimension coefs(22)\nc\n data coefs/\n 1 0.886226925452758027D+00,0.161691987244425025D-01,\n 2 0.103703363422071934D+00,-.134118505705954070D-01,\n 3 0.904033494042846197D-02,-.242259538441698247D-02,\n 4 0.915785994891075934D-03,-.296890120771614378D-03,\n 5 0.100928168758020265D-03,-.336375903860729251D-04,\n 6 0.112523678860543027D-04,-.375495650035445620D-05,\n 7 0.125310464830949639D-05,-.417909902825316389D-06,\n 8 0.138824572934630909D-06,-.462835109086989667D-07,\n 9 0.160743202007499598D-07,-.535845567983428334D-08,\n * 0.129318662203785113D-08,-.431075842242065260D-09,\n 1 0.356478271052638709D-09,-.118826785520470270D-09/\n save\nc\n n=22\n done=1\n gam=0\nc\n t=(x-1-done/2)*2 \nc\n tt=1\n do 1200 i=1,n\nc\n gam=gam+coefs(i)*tt\n tt=tt*t\n 1200 continue\nc\n return\n end\n\n", "meta": {"hexsha": "1a0a33549214b8e0d866018db315dd95609b0655", "size": 14414, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/gammanew_eval.f", "max_stars_repo_name": "askhamwhat/biharm-evals", "max_stars_repo_head_hexsha": "d836302f544670b3d899bd91ea4cb49e9afb6a75", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/gammanew_eval.f", "max_issues_repo_name": "askhamwhat/biharm-evals", "max_issues_repo_head_hexsha": "d836302f544670b3d899bd91ea4cb49e9afb6a75", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/gammanew_eval.f", "max_forks_repo_name": "askhamwhat/biharm-evals", "max_forks_repo_head_hexsha": "d836302f544670b3d899bd91ea4cb49e9afb6a75", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.937716263, "max_line_length": 73, "alphanum_fraction": 0.6351463855, "num_tokens": 5337, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107984180243, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.774803214580493}} {"text": "subroutine DHaj(n, aj)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis subroutine will compute the weights a_j that are used to\n!\texpand an equally sampled grid into spherical harmonics by using\n!\tthe sampling theorem presented in Driscoll and Healy (1994).\n!\n!\tNote that the number of samples, n, must be even! Also, a_j(1) = 0\n!\n!\tCalling parameters:\n!\t\tIN\n!\t\t\tn\tNumber of samples in longitude and latitude.\n!\t\tOUT\n!\t\t\taj\tVector of length n containing the weights.\n!\n!\tDependencies:\tNone\n!\n!\tWritten by Mark Wieczorek (May, 2004)\n!\n!\tCopyright (c) 2005, 2006, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\tinteger, intent(in) ::\tn\n\treal*8, intent(out) ::\taj(:)\n\tinteger ::\t\tj, l\n\treal*8 ::\t\tsum1, pi\n\t\n\tpi = acos(-1.0d0)\n\t\n\taj = 0.0d0\n\t\n\tif (mod(n,2) /= 0) then\n\t\tprint*, \"Error --- DH_aj\"\n\t\tprint*, \"The number of samples in the equi-dimensional grid must be even for use with SHExpandDH\"\n\t\tprint*, \"Input value of N is \", n\n\t\tstop\n\telseif (size(aj) < n) then\n\t\tprint*, \"Error --- DH_aj\"\n\t\tprint*, \"The size of AJ must be greater than or equal to N where N is \", n\n\t\tprint*, \"Input array is dimensioned as \", size(aj)\n\t\tstop\n\tendif\n\t\n\tdo j=0, n-1\n\t\tsum1 = 0.0d0\n\t\t\n\t\tdo l=0, n/2 -1\n\t\t\tsum1 = sum1 + sin( dble(2*l+1) * pi * dble(j) / dble(n) ) / dble(2*l+1)\n\t\tenddo\n\t\n\t\taj(j+1) = sum1 * sin(pi * dble(j)/dble(n)) * sqrt(8.0d0) / dble(n)\n\t\n\tenddo\n\t\nend subroutine DHaj\n\n", "meta": {"hexsha": "a807277c6fe2bb3f7de32d7c799474cf2f9050e1", "size": 1502, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/DHaj.f95", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "spherical_splines/SHTOOLS/src/DHaj.f95", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "spherical_splines/SHTOOLS/src/DHaj.f95", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 25.4576271186, "max_line_length": 99, "alphanum_fraction": 0.5778961385, "num_tokens": 504, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107878954106, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.7748032138840977}} {"text": "\n! Code by: Jostein Brandshoi\n\nPROGRAM advection_solver\n IMPLICIT NONE\n ! ------------------------------- VARIABLE DECLARATIONS -------------------------------\n double precision :: upwind_scheme ! Function declaration for upwind scheme\n\n double precision, parameter :: L = 50000.0 ! Location (L/2) where initial bell is max [m]\n double precision, parameter :: sigma = L / 10.0 ! Measure of with of initial Gaussian bell [m]\n double precision, parameter :: theta_0 = 10.0 ! Max temperature value of initial bell [deg C]\n double precision, parameter :: u_0 = 1.0 ! Advection speed (constant here) [m/s]\n double precision, parameter :: epsilon = 1E-15\n\n double precision, parameter :: C = 0.50 ! Courant number [u_0 * delta_t / delta_x] [m/s]\n double precision, parameter :: delta_x = sigma / 10.0 ! Distance between spatial gridpoints [m]\n double precision, parameter :: delta_t = (C * delta_x) / u_0 ! Time between temporal gridpoints [s]\n double precision :: x_j ! Helper variable to increase readability in IC-loop\n\n integer :: j, n ! Counter variables (j: space, n: time)\n integer :: n_temp, n_curr = 1, n_next = 2 ! Indices to represent curr and next time stetp\n integer, parameter :: j_max = idint((L / delta_x) + 1) ! Max number of space points in [0: j = 1, L: j = j_max]\n integer, parameter :: n_max = idint((25 * L) / (u_0 * delta_t)) ! Max number of time points needed for 25 cycles\n integer, parameter :: n_05c = idint((5 * L) / (u_0 * delta_t)) ! Number of time points needed for 5 cycles\n integer, parameter :: n_10c = idint((10 * L) / (u_0 * delta_t)) ! Number of time points needed for 10 cycles\n integer, parameter :: n_15c = idint((15 * L) / (u_0 * delta_t)) ! Number of time points needed for 15 cycles\n integer, parameter :: n_20c = idint((20 * L) / (u_0 * delta_t)) ! Number of time points needed for 20 cycles\n\n double precision :: theta_jp2_star, theta_jp1_star, theta_j_star ! Helper variables for MPDATA method\n double precision :: theta_jm1_star, theta_jm2_star ! Helper variables for MPDATA method\n double precision :: u_jp1_star, u_j_star, u_jm1_star, F_j_star, F_jm1_star ! Helper variables for MPDATA method\n double precision, dimension(j_max, 2) :: theta = 0.0 ! 2D-array to store solution at time points n and n + 1\n\n character(len = 32) :: output_filename ! Variable to hold output filename for results\n character(len = 32) :: method_type ! String to specify which algorithm to use\n ! -------------------------------------------------------------------------------------\n\n ! -------- GETTING FILENAME FROM CMD-LINE AND OPEN .DAT FILE FOR RESULT OUTPUT --------\n CALL GET_COMMAND_ARGUMENT(1, output_filename) ! Get cmd-line arg for output file\n CALL GET_COMMAND_ARGUMENT(2, method_type) ! Get cmd-line arg for output file\n open(unit = 10, file = output_filename, form = \"formatted\") ! Open file that will store results\n ! -------------------------------------------------------------------------------------\n \n ! -------------------------------- INITIAL CONDITION ----------------------------------\n do j = 1, j_max ! Loop over all space points in the defined region [0, L]\n x_j = (j - 1) * delta_x ! x-value corresponding to the j'th gridpoint in space\n theta(j, n_curr) = theta_0 * dexp(-((2 * x_j - L) / sigma) ** 2) ! Initial condition\n end do\n ! -------------------------------------------------------------------------------------\n\n ! --------------------------- USING UPWIND SCHEME AND BC'S ----------------------------\n do n = 0, n_max ! Loop, in time as long as necessary to complete requested number of cycles\n theta(1, n_curr) = theta(j_max, n_curr) ! Cyclic boundary condition (theta(0, t) = theta(L, t))\n\n do j = 2, j_max ! Loop over all space points in the defined region [0, L]\n theta_j_star = upwind_scheme(theta, j, j - 1, n_curr, j_max, C) ! Upwind scheme\n F_j_star = 0.0; F_jm1_star = 0.0; ! Set to zero in case MPDATA is not used\n\n ! Employ MPDATA method when specified through cmd-line argument\n if (method_type == \"mpdata\" .and. theta(j, n_curr) > 0) then\n if (j == 2) then\n theta_jp2_star = upwind_scheme(theta, 4, 3, n_curr, j_max, C)\n theta_jp1_star = upwind_scheme(theta, 3, 2, n_curr, j_max, C)\n theta_jm1_star = upwind_scheme(theta, 1, j_max, n_curr, j_max, C)\n theta_jm2_star = upwind_scheme(theta, j_max, j_max - 1, n_curr, j_max, C)\n else if (j == 3) then\n theta_jp2_star = upwind_scheme(theta, 5, 4, n_curr, j_max, C)\n theta_jp1_star = upwind_scheme(theta, 4, 3, n_curr, j_max, C)\n theta_jm1_star = upwind_scheme(theta, 2, 1, n_curr, j_max, C)\n theta_jm2_star = upwind_scheme(theta, 1, j_max, n_curr, j_max, C)\n else if (j == j_max) then\n theta_jp2_star = upwind_scheme(theta, 2, 1, n_curr, j_max, C)\n theta_jp1_star = upwind_scheme(theta, 1, j_max, n_curr, j_max, C)\n theta_jm1_star = upwind_scheme(theta, j_max - 1, j_max - 2, n_curr, j_max, C)\n theta_jm2_star = upwind_scheme(theta, j_max - 2, j_max - 3, n_curr, j_max, C)\n else\n theta_jp2_star = upwind_scheme(theta, j + 2, j + 1, n_curr, j_max, C)\n theta_jp1_star = upwind_scheme(theta, j + 1, j, n_curr, j_max, C)\n theta_jm1_star = upwind_scheme(theta, j - 1, j - 2, n_curr, j_max, C)\n theta_jm2_star = upwind_scheme(theta, j - 2, j - 3, n_curr, j_max, C)\n end if\n\n u_jp1_star = 0.25 * (1 - C) * u_0 * ((theta_jp2_star - theta_j_star) / (theta_jp1_star + epsilon))\n u_j_star = 0.25 * (1 - C) * u_0 * ((theta_jp1_star - theta_jm1_star) / (theta_j_star + epsilon))\n u_jm1_star = 0.25 * (1 - C) * u_0 * ((theta_j_star - theta_jm2_star) / (theta_jm1_star + epsilon))\n\n F_j_star = 0.5 * ((u_j_star + dabs(u_j_star)) * theta_j_star + (u_jp1_star - &\n dabs(u_jp1_star)) * theta_jp1_star) * (delta_t / delta_x)\n F_jm1_star = 0.5 * ((u_jm1_star + dabs(u_jm1_star)) * theta_jm1_star + &\n (u_j_star - dabs(u_j_star)) * theta_j_star) * (delta_t / delta_x)\n end if\n\n theta(j, n_next) = theta_j_star - (F_j_star - F_jm1_star)\n end do\n\n ! Write theta to file for time steps corresponding to the requested cycles.\n if (n == 0 .or. n == n_05c .or. n == n_10c .or. n == n_15c .or. n == n_20c .or. n == n_max) then\n write(unit = 10, fmt = \"(102f20.14)\") float(n), theta(:, n_curr) / theta_0 ! Write line-wise\n end if\n\n n_temp = n_next ! Set help index to second theta column (2)\n n_next = n_curr ! Set next time step index to first theta column (1)\n n_curr = n_temp ! Set current time step index to second column (2)\n end do\n ! -------------------------------------------------------------------------------------\n\n close(unit = 10) ! Close file after writing\n\nEND PROGRAM advection_solver\n\ndouble precision function upwind_scheme(theta, j, jm1, n_curr, j_max, C)\n double precision, dimension (j_max, 2) :: theta ! 2D theta array\n double precision C ! Courant number\n integer j, jm1 ! j'th and (j - 1)'th point\n\n upwind_scheme = theta(j, n_curr) - C * (theta(j, n_curr) - theta(jm1, n_curr)) ! Upwind scheme\n return\nend\n\n\n", "meta": {"hexsha": "1badc34a9851184a59e34dd3bc88d99ef9cca93b", "size": 8117, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "project2/advection_mpdata_2.f90", "max_stars_repo_name": "jostbr/GEF4510-Projects", "max_stars_repo_head_hexsha": "1dc6d42b60672481ac6c0ea61268127a8c683e7b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-05T12:44:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-05T12:44:32.000Z", "max_issues_repo_path": "project2/advection_mpdata_2.f90", "max_issues_repo_name": "jostbr/GEF4510-Projects", "max_issues_repo_head_hexsha": "1dc6d42b60672481ac6c0ea61268127a8c683e7b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "project2/advection_mpdata_2.f90", "max_forks_repo_name": "jostbr/GEF4510-Projects", "max_forks_repo_head_hexsha": "1dc6d42b60672481ac6c0ea61268127a8c683e7b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.0826446281, "max_line_length": 124, "alphanum_fraction": 0.5428113835, "num_tokens": 2184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.7747682411763888}} {"text": "program seriallaplace\n implicit none\n integer, parameter :: n=200\n real(8), dimension(0:n+1, 0:n+1) :: u\n real(8), dimension(1:n, 1:n) :: unew\n real(8) :: error\n integer :: iter, i, j\n \n u = 0.0d0\n unew = 0.0d0\n u(:,n+1) = 10.0d0\n error = 1000.0d0\n iter = 0\n\n do while ( error > 1.0d-6 .and. iter < 1000)\n \n do j = 1,n\n do i = 1,n\n unew(i,j) = 0.25d0*( u(i+1,j) + u(i-1,j) + u(i,j+1) + u(i,j-1) )\n end do\n end do\n \n error = 0.0d0\n\n do j = 1,n\n do i = 1,n\n error = error + abs(unew(i,j)-u(i,j))\n u(i,j) = unew(i,j)\n end do\n end do\n \n iter = iter+1\n \n if (mod(iter,100) == 0) then\n write(*, *) \"Iteration \",iter,\", error = \",error\n end if\n end do\n \nend program seriallaplace\n\n\n\n", "meta": {"hexsha": "5eeb0caf9c736efe912bcb61eac4d1ae42b1df87", "size": 804, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lectures5and6/example/src/seriallaplace.f90", "max_stars_repo_name": "sdm900/fortran_course", "max_stars_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lectures5and6/example/src/seriallaplace.f90", "max_issues_repo_name": "sdm900/fortran_course", "max_issues_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures5and6/example/src/seriallaplace.f90", "max_forks_repo_name": "sdm900/fortran_course", "max_forks_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.6976744186, "max_line_length": 76, "alphanum_fraction": 0.4689054726, "num_tokens": 327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7747682241895735}} {"text": "PROGRAM grav_force\nIMPLICIT NONE\n REAL :: calc_grav\n WRITE(*, *) calc_grav(5.98E24, 1000., 38000000.)\n\nEND PROGRAM grav_force\n\nREAL FUNCTION calc_grav(m1, m2, r)\nIMPLICIT NONE\n REAL, INTENT(IN) :: m1, m2, r\n REAL, PARAMETER :: G = 6.672E-11\n calc_grav = (G * m1 * m2) / r**2\nEND FUNCTION calc_grav\n", "meta": {"hexsha": "460bea7c06d8ec5861f50db99a5e79ea0839bf57", "size": 303, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap7/grav_force.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap7/grav_force.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap7/grav_force.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.6428571429, "max_line_length": 50, "alphanum_fraction": 0.6798679868, "num_tokens": 118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338112885303, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.7746425846806638}} {"text": "program simulate_pi\r\nuse iso_fortran_env, only: compiler_version,compiler_options\r\nimplicit none\r\ninteger, parameter :: n = 10**8\r\ninteger :: pi_count, i, itime(8), jt1, jt2, itick\r\nreal :: x, y, t1, t2\r\ncharacter (len=100) :: exec, date, time\r\n! get initial times for cpu_time and system_clock\r\ncall cpu_time(t1)\r\ncall system_clock(count=jt1,count_rate=itick)\r\npi_count = 0\r\ncall random_seed()\r\ndo i = 1, n\r\n call random_number(x)\r\n call random_number(y)\r\n if (x**2 + y**2 < 1.0) pi_count = pi_count + 1\r\nend do\r\nprint*,\"pi =\",pi_count*4.0/n\r\n! get final times for cpu_time and system_clock\r\ncall cpu_time(t2) ; call system_clock(jt2)\r\ncall get_command_argument(0,exec)\r\nprint \"(a)\", \"executable: \" // trim(exec)\r\nprint \"(a)\", \"compiler: \" // compiler_version()\r\nprint \"(a)\", \"options: \" // compiler_options()\r\ncall date_and_time(date=date,time=time,values=itime)\r\nprint \"(3(a,1x))\", \"time:\", trim(date), trim(time)\r\nprint \"('time: ',i4.4,2('-',i2.2),1x,i2.2,2(':',i2.2))\", &\r\n itime([1,2,3,5,6,7]) ! custom formatting\r\nprint \"('cpu time (s): ',f0.2)\",t2-t1\r\nprint \"('wall time (s): ',f0.2)\",(jt2-jt1)/real(itick)\r\nend program simulate_pi\r\n! Windows output of ifort -O3 -stand:f18 xpi.f90 && xpi.exe:\r\n! pi = 3.141639 \r\n! executable: xpi.exe\r\n! compiler: Intel(R) Fortran Intel(R) 64 Compiler Classic \\\r\n! for applications running on Intel(R) 64, Version 2021.5.0 \\\r\n! Build 20211109_000000\r\n! options: /O3 /stand:f18\r\n! time: 20220205 081020.498\r\n! time: 2022-02-05 08:10:20\r\n! cpu time (s): 2.16\r\n! wall time (s): 2.15", "meta": {"hexsha": "0c291a40de2c517926de57fda1903df066ea342f", "size": 1530, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "xpi.f90", "max_stars_repo_name": "awvwgk/FortranTip", "max_stars_repo_head_hexsha": "3810038667e3d5d2ab33c39d4bd0f41870025420", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "xpi.f90", "max_issues_repo_name": "awvwgk/FortranTip", "max_issues_repo_head_hexsha": "3810038667e3d5d2ab33c39d4bd0f41870025420", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "xpi.f90", "max_forks_repo_name": "awvwgk/FortranTip", "max_forks_repo_head_hexsha": "3810038667e3d5d2ab33c39d4bd0f41870025420", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.4285714286, "max_line_length": 62, "alphanum_fraction": 0.6653594771, "num_tokens": 527, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951698485602, "lm_q2_score": 0.8289388083214155, "lm_q1q2_score": 0.7745564185955521}} {"text": "c\nc\nc\nc =====================================================\n double precision function p0(r)\nc =====================================================\nc\n implicit none\nc\nc # Initial variation in pressure with respect to r\n \n double precision r, width, pi\nc\n width = 0.1d0\n pi = 4.d0*atan(1.d0) \n if (r .lt. width) then\n p0 = 1.d0 + 0.5d0 * (cos(pi*r/width) - 1.d0)\n else\n p0 = 0.d0\n endif\n return\n end\n", "meta": {"hexsha": "3ba7fbe75c57aebd8c030e6001d0b90c0b4aaf2b", "size": 504, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/acoustics/2d/interface/p0.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/clawpack/acoustics/2d/interface/p0.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/clawpack/acoustics/2d/interface/p0.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 21.9130434783, "max_line_length": 59, "alphanum_fraction": 0.378968254, "num_tokens": 139, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7745564164866793}} {"text": "subroutine dday(yr, c, r, anchor, dd)\n implicit none\n real, intent(in) :: yr \n real, intent(out) :: c, r, dd, anchor\n\n c = floor(yr / 100)\n r = mod(c, 4.0)\n anchor = 5 * mod(r, 7.0) + 2 ! 2? Tuesday\n dd = mod(floor(yr/12) + mod(yr, 12.0) + floor(mod(yr, 12.0) / 4), 7.0) + anchor\n\nend subroutine dday\n\n", "meta": {"hexsha": "f689a97cbd3ccc2dec2fcd9c0b891403121bcaa4", "size": 313, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Subprograms/dday.f90", "max_stars_repo_name": "asnowmang/Calendar", "max_stars_repo_head_hexsha": "d11cf0c9a87069723e665c93360f94524bd442c9", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Subprograms/dday.f90", "max_issues_repo_name": "asnowmang/Calendar", "max_issues_repo_head_hexsha": "d11cf0c9a87069723e665c93360f94524bd442c9", "max_issues_repo_licenses": ["0BSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Subprograms/dday.f90", "max_forks_repo_name": "asnowmang/Calendar", "max_forks_repo_head_hexsha": "d11cf0c9a87069723e665c93360f94524bd442c9", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0769230769, "max_line_length": 81, "alphanum_fraction": 0.5623003195, "num_tokens": 137, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9473810466522862, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7745545650780408}} {"text": "program demo_stats_randn\n\n use forlab_stats, only: randn\n\n print *, \"running `demo_stats_randn`..\"\n\n print *, randn(mean=0.0, std=2.0)\n print *, randn(mean=0.0, std=2.0, ndim=3)\n print *, reshape(randn(0.0, 2.0, 2*2), [2,2])\n\n !> Chi-square distribution of 3 degrees of freedom\n print *, sum(randn(mean=0.0, std=1.0, ndim=3)**2)\n print *, sum(reshape(randn(mean=0.0, std=1.0, ndim=5*3), [5, 3])**2, dim=2)\n\n !> Possible output:\n\n !! -0.387298465 \n !! -1.37615824 -0.529266298 5.43095016\n !! -1.35311902 1.81701779 0.772518456 -0.269844353\n\n !! 9.45483303\n !! 0.962645471 0.698421597 0.687875450 4.75956964 1.71025097\n\nend program demo_stats_randn", "meta": {"hexsha": "e1c0c4a2b634126f00f198433f8d920792be750b", "size": 738, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/stats/demo_stats_randn.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "example/stats/demo_stats_randn.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "example/stats/demo_stats_randn.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 30.75, "max_line_length": 86, "alphanum_fraction": 0.5880758808, "num_tokens": 292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810421953309, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7745545614341479}} {"text": "program main\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n integer :: a, b, m\n common /group1/ a, b, m\n integer, allocatable :: seed(:)\n integer :: n\n integer :: i, l = 1\n real(dp) :: x(1000) ! 随机数列\n real(dp) :: C_l ! 自相关函数\n\n interface\n function Auto_correlaion(x, l)\n ! 间距为 l 的自相关函数\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n real(dp), intent(in) :: x(:)\n integer, intent(in) :: l\n real(dp) :: Auto_correlaion\n end function Auto_correlaion\n end interface\n\n call random_seed(size=n)\n allocate(seed(n))\n seed = 1\n call random_seed(put=seed)\n do i = 1, size(x)\n call random_number(x(i))\n end do\n C_l = Auto_correlaion(x, l)\n write(*,*) 'Auto-correlation function C_l(x) = ', C_l\nend program main\n\nfunction Auto_correlaion(x, l)\n ! 间距为 l 的自相关函数\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n real(dp), intent(in) :: x(:)\n integer, intent(in) :: l\n real(dp) :: Auto_correlaion\n\n if (size(x) < l + 1) then\n write(*,*) 'Interval l too large, correlation coeffiecient undefined.'\n Auto_correlaion = 0.d0\n return\n end if\n\n Auto_correlaion = (sum(x(:size(x) - l) * x(l + 1:)) / (size(x) - l) - (sum(x) / size(x))**2) /&\n ((sum(x**2) / size(x)) - (sum(x) / size(x))**2)\nend function Auto_correlaion", "meta": {"hexsha": "d9208a9532eea9ec659ff48a3ca5fdc057118da7", "size": 1448, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Chap1-Monte-Carlo-Method-Basic/1.1.2.1-Auto-Correlation-Function.f90", "max_stars_repo_name": "Chen-Jialin/Computational-Physics-Practice", "max_stars_repo_head_hexsha": "5bbb271123ee75727d266e6ca83d090ad8919abb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chap1-Monte-Carlo-Method-Basic/1.1.2.1-Auto-Correlation-Function.f90", "max_issues_repo_name": "Chen-Jialin/Computational-Physics-Practice", "max_issues_repo_head_hexsha": "5bbb271123ee75727d266e6ca83d090ad8919abb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chap1-Monte-Carlo-Method-Basic/1.1.2.1-Auto-Correlation-Function.f90", "max_forks_repo_name": "Chen-Jialin/Computational-Physics-Practice", "max_forks_repo_head_hexsha": "5bbb271123ee75727d266e6ca83d090ad8919abb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.320754717, "max_line_length": 99, "alphanum_fraction": 0.5669889503, "num_tokens": 465, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404116305639, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7745255529650241}} {"text": "!> Module for physical/mathematical parameters\nMODULE physical_params_mod\n USE kind_params_mod\n IMPLICIT none\n\n PUBLIC\n\n !> Pi\n REAL(go_wp), PARAMETER :: pi = 3.1415926535897932_go_wp \n !> Acceleration due to gravity (ms^-2)\n REAL(go_wp), PARAMETER :: g = 9.80665_go_wp\n !> earth rotation speed (s^(-1))\n REAL(go_wp), PARAMETER :: omega = 7.292116e-05_go_wp\n !> degree to radian\n REAL(go_wp), PARAMETER :: d2r = pi / 180._go_wp \n\nEND MODULE physical_params_mod\n", "meta": {"hexsha": "deac6e972a57b52c8b89bf42d8b745ee60ed295a", "size": 504, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "benchmarks/nemo/nemolite2d/common/physical_params_mod.f90", "max_stars_repo_name": "stfc/PSycloneBench", "max_stars_repo_head_hexsha": "f3c65c904eb286b4e3f63c43273a80d25e92cbe4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-03-30T23:33:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T13:32:01.000Z", "max_issues_repo_path": "benchmarks/nemo/nemolite2d/common/physical_params_mod.f90", "max_issues_repo_name": "stfc/PSycloneBench", "max_issues_repo_head_hexsha": "f3c65c904eb286b4e3f63c43273a80d25e92cbe4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 76, "max_issues_repo_issues_event_min_datetime": "2018-01-31T14:16:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T13:56:17.000Z", "max_forks_repo_path": "benchmarks/nemo/nemolite2d/common/physical_params_mod.f90", "max_forks_repo_name": "stfc/PSycloneBench", "max_forks_repo_head_hexsha": "f3c65c904eb286b4e3f63c43273a80d25e92cbe4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-08-01T10:23:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-28T13:23:01.000Z", "avg_line_length": 28.0, "max_line_length": 74, "alphanum_fraction": 0.6666666667, "num_tokens": 158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404038127071, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7745255522211794}} {"text": "PURE FUNCTION func_stddev(arr, dof) RESULT(ans)\n ! NOTE: See https://numpy.org/doc/stable/reference/generated/numpy.std.html\n\n USE ISO_FORTRAN_ENV\n\n IMPLICIT NONE\n\n ! Declare inputs/outputs ...\n INTEGER(kind = INT64), INTENT(in), OPTIONAL :: dof\n REAL(kind = REAL64) :: ans\n REAL(kind = REAL64), DIMENSION(:), INTENT(in) :: arr\n\n ! Calculate the standard deviation ...\n IF(PRESENT(dof))THEN\n ans = SQRT(func_var(arr, dof))\n ELSE\n ans = SQRT(func_var(arr, 0_INT64))\n END IF\nEND FUNCTION func_stddev\n", "meta": {"hexsha": "af54fd32ff7040989b13e5fe882c33f51e625228", "size": 663, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mod_safe/func_stddev.f90", "max_stars_repo_name": "Guymer/fortranlib", "max_stars_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-28T02:05:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-16T16:50:21.000Z", "max_issues_repo_path": "mod_safe/func_stddev.f90", "max_issues_repo_name": "Guymer/fortranlib", "max_issues_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-06-17T16:49:20.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-11T18:47:36.000Z", "max_forks_repo_path": "mod_safe/func_stddev.f90", "max_forks_repo_name": "Guymer/fortranlib", "max_forks_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-11T04:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-11T04:51:33.000Z", "avg_line_length": 33.15, "max_line_length": 86, "alphanum_fraction": 0.5354449472, "num_tokens": 151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111796979521252, "lm_q2_score": 0.84997116805678, "lm_q1q2_score": 0.7744764721779918}} {"text": "*DECK HW3CRT\n SUBROUTINE HW3CRT (XS, XF, L, LBDCND, BDXS, BDXF, YS, YF, M,\n + MBDCND, BDYS, BDYF, ZS, ZF, N, NBDCND, BDZS, BDZF, ELMBDA,\n + LDIMF, MDIMF, F, PERTRB, IERROR, W)\nC***BEGIN PROLOGUE HW3CRT\nC***PURPOSE Solve the standard seven-point finite difference\nC approximation to the Helmholtz equation in Cartesian\nC coordinates.\nC***LIBRARY SLATEC (FISHPACK)\nC***CATEGORY I2B1A1A\nC***TYPE SINGLE PRECISION (HW3CRT-S)\nC***KEYWORDS CARTESIAN, ELLIPTIC, FISHPACK, HELMHOLTZ, PDE\nC***AUTHOR Adams, J., (NCAR)\nC Swarztrauber, P. N., (NCAR)\nC Sweet, R., (NCAR)\nC***DESCRIPTION\nC\nC Subroutine HW3CRT solves the standard seven-point finite\nC difference approximation to the Helmholtz equation in Cartesian\nC coordinates:\nC\nC (d/dX)(dU/dX) + (d/dY)(dU/dY) + (d/dZ)(dU/dZ)\nC\nC + LAMBDA*U = F(X,Y,Z) .\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC\nC * * * * * * * * Parameter Description * * * * * * * * * *\nC\nC\nC * * * * * * On Input * * * * * *\nC\nC XS,XF\nC The range of X, i.e. XS .LE. X .LE. XF .\nC XS must be less than XF.\nC\nC L\nC The number of panels into which the interval (XS,XF) is\nC subdivided. Hence, there will be L+1 grid points in the\nC X-direction given by X(I) = XS+(I-1)DX for I=1,2,...,L+1,\nC where DX = (XF-XS)/L is the panel width. L must be at\nC least 5 .\nC\nC LBDCND\nC Indicates the type of boundary conditions at X = XS and X = XF.\nC\nC = 0 If the solution is periodic in X, i.e.\nC U(L+I,J,K) = U(I,J,K).\nC = 1 If the solution is specified at X = XS and X = XF.\nC = 2 If the solution is specified at X = XS and the derivative\nC of the solution with respect to X is specified at X = XF.\nC = 3 If the derivative of the solution with respect to X is\nC specified at X = XS and X = XF.\nC = 4 If the derivative of the solution with respect to X is\nC specified at X = XS and the solution is specified at X=XF.\nC\nC BDXS\nC A two-dimensional array that specifies the values of the\nC derivative of the solution with respect to X at X = XS.\nC when LBDCND = 3 or 4,\nC\nC BDXS(J,K) = (d/dX)U(XS,Y(J),Z(K)), J=1,2,...,M+1,\nC K=1,2,...,N+1.\nC\nC When LBDCND has any other value, BDXS is a dummy variable.\nC BDXS must be dimensioned at least (M+1)*(N+1).\nC\nC BDXF\nC A two-dimensional array that specifies the values of the\nC derivative of the solution with respect to X at X = XF.\nC When LBDCND = 2 or 3,\nC\nC BDXF(J,K) = (d/dX)U(XF,Y(J),Z(K)), J=1,2,...,M+1,\nC K=1,2,...,N+1.\nC\nC When LBDCND has any other value, BDXF is a dummy variable.\nC BDXF must be dimensioned at least (M+1)*(N+1).\nC\nC YS,YF\nC The range of Y, i.e. YS .LE. Y .LE. YF.\nC YS must be less than YF.\nC\nC M\nC The number of panels into which the interval (YS,YF) is\nC subdivided. Hence, there will be M+1 grid points in the\nC Y-direction given by Y(J) = YS+(J-1)DY for J=1,2,...,M+1,\nC where DY = (YF-YS)/M is the panel width. M must be at\nC least 5 .\nC\nC MBDCND\nC Indicates the type of boundary conditions at Y = YS and Y = YF.\nC\nC = 0 If the solution is periodic in Y, i.e.\nC U(I,M+J,K) = U(I,J,K).\nC = 1 If the solution is specified at Y = YS and Y = YF.\nC = 2 If the solution is specified at Y = YS and the derivative\nC of the solution with respect to Y is specified at Y = YF.\nC = 3 If the derivative of the solution with respect to Y is\nC specified at Y = YS and Y = YF.\nC = 4 If the derivative of the solution with respect to Y is\nC specified at Y = YS and the solution is specified at Y=YF.\nC\nC BDYS\nC A two-dimensional array that specifies the values of the\nC derivative of the solution with respect to Y at Y = YS.\nC When MBDCND = 3 or 4,\nC\nC BDYS(I,K) = (d/dY)U(X(I),YS,Z(K)), I=1,2,...,L+1,\nC K=1,2,...,N+1.\nC\nC When MBDCND has any other value, BDYS is a dummy variable.\nC BDYS must be dimensioned at least (L+1)*(N+1).\nC\nC BDYF\nC A two-dimensional array that specifies the values of the\nC derivative of the solution with respect to Y at Y = YF.\nC When MBDCND = 2 or 3,\nC\nC BDYF(I,K) = (d/dY)U(X(I),YF,Z(K)), I=1,2,...,L+1,\nC K=1,2,...,N+1.\nC\nC When MBDCND has any other value, BDYF is a dummy variable.\nC BDYF must be dimensioned at least (L+1)*(N+1).\nC\nC ZS,ZF\nC The range of Z, i.e. ZS .LE. Z .LE. ZF.\nC ZS must be less than ZF.\nC\nC N\nC The number of panels into which the interval (ZS,ZF) is\nC subdivided. Hence, there will be N+1 grid points in the\nC Z-direction given by Z(K) = ZS+(K-1)DZ for K=1,2,...,N+1,\nC where DZ = (ZF-ZS)/N is the panel width. N must be at least 5.\nC\nC NBDCND\nC Indicates the type of boundary conditions at Z = ZS and Z = ZF.\nC\nC = 0 If the solution is periodic in Z, i.e.\nC U(I,J,N+K) = U(I,J,K).\nC = 1 If the solution is specified at Z = ZS and Z = ZF.\nC = 2 If the solution is specified at Z = ZS and the derivative\nC of the solution with respect to Z is specified at Z = ZF.\nC = 3 If the derivative of the solution with respect to Z is\nC specified at Z = ZS and Z = ZF.\nC = 4 If the derivative of the solution with respect to Z is\nC specified at Z = ZS and the solution is specified at Z=ZF.\nC\nC BDZS\nC A two-dimensional array that specifies the values of the\nC derivative of the solution with respect to Z at Z = ZS.\nC When NBDCND = 3 or 4,\nC\nC BDZS(I,J) = (d/dZ)U(X(I),Y(J),ZS), I=1,2,...,L+1,\nC J=1,2,...,M+1.\nC\nC When NBDCND has any other value, BDZS is a dummy variable.\nC BDZS must be dimensioned at least (L+1)*(M+1).\nC\nC BDZF\nC A two-dimensional array that specifies the values of the\nC derivative of the solution with respect to Z at Z = ZF.\nC When NBDCND = 2 or 3,\nC\nC BDZF(I,J) = (d/dZ)U(X(I),Y(J),ZF), I=1,2,...,L+1,\nC J=1,2,...,M+1.\nC\nC When NBDCND has any other value, BDZF is a dummy variable.\nC BDZF must be dimensioned at least (L+1)*(M+1).\nC\nC ELMBDA\nC The constant LAMBDA in the Helmholtz equation. If\nC LAMBDA .GT. 0, a solution may not exist. However, HW3CRT will\nC attempt to find a solution.\nC\nC F\nC A three-dimensional array that specifies the values of the\nC right side of the Helmholtz equation and boundary values (if\nC any). For I=2,3,...,L, J=2,3,...,M, and K=2,3,...,N\nC\nC F(I,J,K) = F(X(I),Y(J),Z(K)).\nC\nC On the boundaries F is defined by\nC\nC LBDCND F(1,J,K) F(L+1,J,K)\nC ------ --------------- ---------------\nC\nC 0 F(XS,Y(J),Z(K)) F(XS,Y(J),Z(K))\nC 1 U(XS,Y(J),Z(K)) U(XF,Y(J),Z(K))\nC 2 U(XS,Y(J),Z(K)) F(XF,Y(J),Z(K)) J=1,2,...,M+1\nC 3 F(XS,Y(J),Z(K)) F(XF,Y(J),Z(K)) K=1,2,...,N+1\nC 4 F(XS,Y(J),Z(K)) U(XF,Y(J),Z(K))\nC\nC MBDCND F(I,1,K) F(I,M+1,K)\nC ------ --------------- ---------------\nC\nC 0 F(X(I),YS,Z(K)) F(X(I),YS,Z(K))\nC 1 U(X(I),YS,Z(K)) U(X(I),YF,Z(K))\nC 2 U(X(I),YS,Z(K)) F(X(I),YF,Z(K)) I=1,2,...,L+1\nC 3 F(X(I),YS,Z(K)) F(X(I),YF,Z(K)) K=1,2,...,N+1\nC 4 F(X(I),YS,Z(K)) U(X(I),YF,Z(K))\nC\nC NBDCND F(I,J,1) F(I,J,N+1)\nC ------ --------------- ---------------\nC\nC 0 F(X(I),Y(J),ZS) F(X(I),Y(J),ZS)\nC 1 U(X(I),Y(J),ZS) U(X(I),Y(J),ZF)\nC 2 U(X(I),Y(J),ZS) F(X(I),Y(J),ZF) I=1,2,...,L+1\nC 3 F(X(I),Y(J),ZS) F(X(I),Y(J),ZF) J=1,2,...,M+1\nC 4 F(X(I),Y(J),ZS) U(X(I),Y(J),ZF)\nC\nC F must be dimensioned at least (L+1)*(M+1)*(N+1).\nC\nC NOTE:\nC\nC If the table calls for both the solution U and the right side F\nC on a boundary, then the solution must be specified.\nC\nC LDIMF\nC The row (or first) dimension of the arrays F,BDYS,BDYF,BDZS,\nC and BDZF as it appears in the program calling HW3CRT. this\nC parameter is used to specify the variable dimension of these\nC arrays. LDIMF must be at least L+1.\nC\nC MDIMF\nC The column (or second) dimension of the array F and the row (or\nC first) dimension of the arrays BDXS and BDXF as it appears in\nC the program calling HW3CRT. This parameter is used to specify\nC the variable dimension of these arrays.\nC MDIMF must be at least M+1.\nC\nC W\nC A one-dimensional array that must be provided by the user for\nC work space. The length of W must be at least 30 + L + M + 5*N\nC + MAX(L,M,N) + 7*(INT((L+1)/2) + INT((M+1)/2))\nC\nC\nC * * * * * * On Output * * * * * *\nC\nC F\nC Contains the solution U(I,J,K) of the finite difference\nC approximation for the grid point (X(I),Y(J),Z(K)) for\nC I=1,2,...,L+1, J=1,2,...,M+1, and K=1,2,...,N+1.\nC\nC PERTRB\nC If a combination of periodic or derivative boundary conditions\nC is specified for a Poisson equation (LAMBDA = 0), a solution\nC may not exist. PERTRB is a constant, calculated and subtracted\nC from F, which ensures that a solution exists. PWSCRT then\nC computes this solution, which is a least squares solution to\nC the original approximation. This solution is not unique and is\nC unnormalized. The value of PERTRB should be small compared to\nC the right side F. Otherwise, a solution is obtained to an\nC essentially different problem. This comparison should always\nC be made to insure that a meaningful solution has been obtained.\nC\nC IERROR\nC An error flag that indicates invalid input parameters. Except\nC for numbers 0 and 12, a solution is not attempted.\nC\nC = 0 No error\nC = 1 XS .GE. XF\nC = 2 L .LT. 5\nC = 3 LBDCND .LT. 0 .OR. LBDCND .GT. 4\nC = 4 YS .GE. YF\nC = 5 M .LT. 5\nC = 6 MBDCND .LT. 0 .OR. MBDCND .GT. 4\nC = 7 ZS .GE. ZF\nC = 8 N .LT. 5\nC = 9 NBDCND .LT. 0 .OR. NBDCND .GT. 4\nC = 10 LDIMF .LT. L+1\nC = 11 MDIMF .LT. M+1\nC = 12 LAMBDA .GT. 0\nC\nC Since this is the only means of indicating a possibly incorrect\nC call to HW3CRT, the user should test IERROR after the call.\nC\nC *Long Description:\nC\nC * * * * * * * Program Specifications * * * * * * * * * * * *\nC\nC Dimension of BDXS(MDIMF,N+1),BDXF(MDIMF,N+1),BDYS(LDIMF,N+1),\nC Arguments BDYF(LDIMF,N+1),BDZS(LDIMF,M+1),BDZF(LDIMF,M+1),\nC F(LDIMF,MDIMF,N+1),W(see argument list)\nC\nC Latest December 1, 1978\nC Revision\nC\nC Subprograms HW3CRT,POIS3D,POS3D1,TRIDQ,RFFTI,RFFTF,RFFTF1,\nC Required RFFTB,RFFTB1,COSTI,COST,SINTI,SINT,COSQI,COSQF,\nC COSQF1,COSQB,COSQB1,SINQI,SINQF,SINQB,CFFTI,\nC CFFTI1,CFFTB,CFFTB1,PASSB2,PASSB3,PASSB4,PASSB,\nC CFFTF,CFFTF1,PASSF1,PASSF2,PASSF3,PASSF4,PASSF,\nC PIMACH\nC\nC Special NONE\nC Conditions\nC\nC Common NONE\nC Blocks\nC\nC I/O NONE\nC\nC Precision Single\nC\nC Specialist Roland Sweet\nC\nC Language FORTRAN\nC\nC History Written by Roland Sweet at NCAR in July 1977\nC\nC Algorithm This subroutine defines the finite difference\nC equations, incorporates boundary data, and\nC adjusts the right side of singular systems and\nC then calls POIS3D to solve the system.\nC\nC Space 7862(decimal) = 17300(octal) locations on the\nC Required NCAR Control Data 7600\nC\nC Timing and The execution time T on the NCAR Control Data\nC Accuracy 7600 for subroutine HW3CRT is roughly proportional\nC to L*M*N*(log2(L)+log2(M)+5), but also depends on\nC input parameters LBDCND and MBDCND. Some typical\nC values are listed in the table below.\nC The solution process employed results in a loss\nC of no more than three significant digits for L,M\nC and N as large as 32. More detailed information\nC about accuracy can be found in the documentation\nC for subroutine POIS3D which is the routine that\nC actually solves the finite difference equations.\nC\nC\nC L(=M=N) LBDCND(=MBDCND=NBDCND) T(MSECS)\nC ------- ---------------------- --------\nC\nC 16 0 300\nC 16 1 302\nC 16 3 348\nC 32 0 1925\nC 32 1 1929\nC 32 3 2109\nC\nC Portability American National Standards Institute FORTRAN.\nC The machine dependent constant PI is defined in\nC function PIMACH.\nC\nC Required COS,SIN,ATAN\nC Resident\nC Routines\nC\nC Reference NONE\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC***REFERENCES (NONE)\nC***ROUTINES CALLED POIS3D\nC***REVISION HISTORY (YYMMDD)\nC 801001 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC***END PROLOGUE HW3CRT\nC\nC\n DIMENSION BDXS(MDIMF,*) ,BDXF(MDIMF,*) ,\n 1 BDYS(LDIMF,*) ,BDYF(LDIMF,*) ,\n 2 BDZS(LDIMF,*) ,BDZF(LDIMF,*) ,\n 3 F(LDIMF,MDIMF,*) ,W(*)\nC***FIRST EXECUTABLE STATEMENT HW3CRT\n IERROR = 0\n IF (XF .LE. XS) IERROR = 1\n IF (L .LT. 5) IERROR = 2\n IF (LBDCND.LT.0 .OR. LBDCND.GT.4) IERROR = 3\n IF (YF .LE. YS) IERROR = 4\n IF (M .LT. 5) IERROR = 5\n IF (MBDCND.LT.0 .OR. MBDCND.GT.4) IERROR = 6\n IF (ZF .LE. ZS) IERROR = 7\n IF (N .LT. 5) IERROR = 8\n IF (NBDCND.LT.0 .OR. NBDCND.GT.4) IERROR = 9\n IF (LDIMF .LT. L+1) IERROR = 10\n IF (MDIMF .LT. M+1) IERROR = 11\n IF (IERROR .NE. 0) GO TO 188\n DY = (YF-YS)/M\n TWBYDY = 2./DY\n C2 = 1./(DY**2)\n MSTART = 1\n MSTOP = M\n MP1 = M+1\n MP = MBDCND+1\n GO TO (104,101,101,102,102),MP\n 101 MSTART = 2\n 102 GO TO (104,104,103,103,104),MP\n 103 MSTOP = MP1\n 104 MUNK = MSTOP-MSTART+1\n DZ = (ZF-ZS)/N\n TWBYDZ = 2./DZ\n NP = NBDCND+1\n C3 = 1./(DZ**2)\n NP1 = N+1\n NSTART = 1\n NSTOP = N\n GO TO (108,105,105,106,106),NP\n 105 NSTART = 2\n 106 GO TO (108,108,107,107,108),NP\n 107 NSTOP = NP1\n 108 NUNK = NSTOP-NSTART+1\n LP1 = L+1\n DX = (XF-XS)/L\n C1 = 1./(DX**2)\n TWBYDX = 2./DX\n LP = LBDCND+1\n LSTART = 1\n LSTOP = L\nC\nC ENTER BOUNDARY DATA FOR X-BOUNDARIES.\nC\n GO TO (122,109,109,112,112),LP\n 109 LSTART = 2\n DO 111 J=MSTART,MSTOP\n DO 110 K=NSTART,NSTOP\n F(2,J,K) = F(2,J,K)-C1*F(1,J,K)\n 110 CONTINUE\n 111 CONTINUE\n GO TO 115\n 112 DO 114 J=MSTART,MSTOP\n DO 113 K=NSTART,NSTOP\n F(1,J,K) = F(1,J,K)+TWBYDX*BDXS(J,K)\n 113 CONTINUE\n 114 CONTINUE\n 115 GO TO (122,116,119,119,116),LP\n 116 DO 118 J=MSTART,MSTOP\n DO 117 K=NSTART,NSTOP\n F(L,J,K) = F(L,J,K)-C1*F(LP1,J,K)\n 117 CONTINUE\n 118 CONTINUE\n GO TO 122\n 119 LSTOP = LP1\n DO 121 J=MSTART,MSTOP\n DO 120 K=NSTART,NSTOP\n F(LP1,J,K) = F(LP1,J,K)-TWBYDX*BDXF(J,K)\n 120 CONTINUE\n 121 CONTINUE\n 122 LUNK = LSTOP-LSTART+1\nC\nC ENTER BOUNDARY DATA FOR Y-BOUNDARIES.\nC\n GO TO (136,123,123,126,126),MP\n 123 DO 125 I=LSTART,LSTOP\n DO 124 K=NSTART,NSTOP\n F(I,2,K) = F(I,2,K)-C2*F(I,1,K)\n 124 CONTINUE\n 125 CONTINUE\n GO TO 129\n 126 DO 128 I=LSTART,LSTOP\n DO 127 K=NSTART,NSTOP\n F(I,1,K) = F(I,1,K)+TWBYDY*BDYS(I,K)\n 127 CONTINUE\n 128 CONTINUE\n 129 GO TO (136,130,133,133,130),MP\n 130 DO 132 I=LSTART,LSTOP\n DO 131 K=NSTART,NSTOP\n F(I,M,K) = F(I,M,K)-C2*F(I,MP1,K)\n 131 CONTINUE\n 132 CONTINUE\n GO TO 136\n 133 DO 135 I=LSTART,LSTOP\n DO 134 K=NSTART,NSTOP\n F(I,MP1,K) = F(I,MP1,K)-TWBYDY*BDYF(I,K)\n 134 CONTINUE\n 135 CONTINUE\n 136 CONTINUE\nC\nC ENTER BOUNDARY DATA FOR Z-BOUNDARIES.\nC\n GO TO (150,137,137,140,140),NP\n 137 DO 139 I=LSTART,LSTOP\n DO 138 J=MSTART,MSTOP\n F(I,J,2) = F(I,J,2)-C3*F(I,J,1)\n 138 CONTINUE\n 139 CONTINUE\n GO TO 143\n 140 DO 142 I=LSTART,LSTOP\n DO 141 J=MSTART,MSTOP\n F(I,J,1) = F(I,J,1)+TWBYDZ*BDZS(I,J)\n 141 CONTINUE\n 142 CONTINUE\n 143 GO TO (150,144,147,147,144),NP\n 144 DO 146 I=LSTART,LSTOP\n DO 145 J=MSTART,MSTOP\n F(I,J,N) = F(I,J,N)-C3*F(I,J,NP1)\n 145 CONTINUE\n 146 CONTINUE\n GO TO 150\n 147 DO 149 I=LSTART,LSTOP\n DO 148 J=MSTART,MSTOP\n F(I,J,NP1) = F(I,J,NP1)-TWBYDZ*BDZF(I,J)\n 148 CONTINUE\n 149 CONTINUE\nC\nC DEFINE A,B,C COEFFICIENTS IN W-ARRAY.\nC\n 150 CONTINUE\n IWB = NUNK+1\n IWC = IWB+NUNK\n IWW = IWC+NUNK\n DO 151 K=1,NUNK\n I = IWC+K-1\n W(K) = C3\n W(I) = C3\n I = IWB+K-1\n W(I) = -2.*C3+ELMBDA\n 151 CONTINUE\n GO TO (155,155,153,152,152),NP\n 152 W(IWC) = 2.*C3\n 153 GO TO (155,155,154,154,155),NP\n 154 W(IWB-1) = 2.*C3\n 155 CONTINUE\n PERTRB = 0.\nC\nC FOR SINGULAR PROBLEMS ADJUST DATA TO INSURE A SOLUTION WILL EXIST.\nC\n GO TO (156,172,172,156,172),LP\n 156 GO TO (157,172,172,157,172),MP\n 157 GO TO (158,172,172,158,172),NP\n 158 IF (ELMBDA) 172,160,159\n 159 IERROR = 12\n GO TO 172\n 160 CONTINUE\n MSTPM1 = MSTOP-1\n LSTPM1 = LSTOP-1\n NSTPM1 = NSTOP-1\n XLP = (2+LP)/3\n YLP = (2+MP)/3\n ZLP = (2+NP)/3\n S1 = 0.\n DO 164 K=2,NSTPM1\n DO 162 J=2,MSTPM1\n DO 161 I=2,LSTPM1\n S1 = S1+F(I,J,K)\n 161 CONTINUE\n S1 = S1+(F(1,J,K)+F(LSTOP,J,K))/XLP\n 162 CONTINUE\n S2 = 0.\n DO 163 I=2,LSTPM1\n S2 = S2+F(I,1,K)+F(I,MSTOP,K)\n 163 CONTINUE\n S2 = (S2+(F(1,1,K)+F(1,MSTOP,K)+F(LSTOP,1,K)+F(LSTOP,MSTOP,K))/\n 1 XLP)/YLP\n S1 = S1+S2\n 164 CONTINUE\n S = (F(1,1,1)+F(LSTOP,1,1)+F(1,1,NSTOP)+F(LSTOP,1,NSTOP)+\n 1 F(1,MSTOP,1)+F(LSTOP,MSTOP,1)+F(1,MSTOP,NSTOP)+\n 2 F(LSTOP,MSTOP,NSTOP))/(XLP*YLP)\n DO 166 J=2,MSTPM1\n DO 165 I=2,LSTPM1\n S = S+F(I,J,1)+F(I,J,NSTOP)\n 165 CONTINUE\n 166 CONTINUE\n S2 = 0.\n DO 167 I=2,LSTPM1\n S2 = S2+F(I,1,1)+F(I,1,NSTOP)+F(I,MSTOP,1)+F(I,MSTOP,NSTOP)\n 167 CONTINUE\n S = S2/YLP+S\n S2 = 0.\n DO 168 J=2,MSTPM1\n S2 = S2+F(1,J,1)+F(1,J,NSTOP)+F(LSTOP,J,1)+F(LSTOP,J,NSTOP)\n 168 CONTINUE\n S = S2/XLP+S\n PERTRB = (S/ZLP+S1)/((LUNK+1.-XLP)*(MUNK+1.-YLP)*\n 1 (NUNK+1.-ZLP))\n DO 171 I=1,LUNK\n DO 170 J=1,MUNK\n DO 169 K=1,NUNK\n F(I,J,K) = F(I,J,K)-PERTRB\n 169 CONTINUE\n 170 CONTINUE\n 171 CONTINUE\n 172 CONTINUE\n NPEROD = 0\n IF (NBDCND .EQ. 0) GO TO 173\n NPEROD = 1\n W(1) = 0.\n W(IWW-1) = 0.\n 173 CONTINUE\n CALL POIS3D (LBDCND,LUNK,C1,MBDCND,MUNK,C2,NPEROD,NUNK,W,W(IWB),\n 1 W(IWC),LDIMF,MDIMF,F(LSTART,MSTART,NSTART),IR,W(IWW))\nC\nC FILL IN SIDES FOR PERIODIC BOUNDARY CONDITIONS.\nC\n IF (LP .NE. 1) GO TO 180\n IF (MP .NE. 1) GO TO 175\n DO 174 K=NSTART,NSTOP\n F(1,MP1,K) = F(1,1,K)\n 174 CONTINUE\n MSTOP = MP1\n 175 IF (NP .NE. 1) GO TO 177\n DO 176 J=MSTART,MSTOP\n F(1,J,NP1) = F(1,J,1)\n 176 CONTINUE\n NSTOP = NP1\n 177 DO 179 J=MSTART,MSTOP\n DO 178 K=NSTART,NSTOP\n F(LP1,J,K) = F(1,J,K)\n 178 CONTINUE\n 179 CONTINUE\n 180 CONTINUE\n IF (MP .NE. 1) GO TO 185\n IF (NP .NE. 1) GO TO 182\n DO 181 I=LSTART,LSTOP\n F(I,1,NP1) = F(I,1,1)\n 181 CONTINUE\n NSTOP = NP1\n 182 DO 184 I=LSTART,LSTOP\n DO 183 K=NSTART,NSTOP\n F(I,MP1,K) = F(I,1,K)\n 183 CONTINUE\n 184 CONTINUE\n 185 CONTINUE\n IF (NP .NE. 1) GO TO 188\n DO 187 I=LSTART,LSTOP\n DO 186 J=MSTART,MSTOP\n F(I,J,NP1) = F(I,J,1)\n 186 CONTINUE\n 187 CONTINUE\n 188 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "043098d01bcc3e131047204ee8413a3ddb103bf5", "size": 21650, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/hw3crt.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/hw3crt.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/hw3crt.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.474522293, "max_line_length": 72, "alphanum_fraction": 0.5228637413, "num_tokens": 7781, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541577509315, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.774217817316335}} {"text": "module nth_prime\n implicit none\ncontains\n\n ! loop from 2 to n/2. If mod(i,n)==0 this is not prime\n logical pure function is_prime(n)\n\n integer, intent(in) :: n\n integer :: i\n\n is_prime=.true.\n do i=2,n/2\n if ( mod(n,i)==0 ) then\n is_prime = .false.\n return\n end if\n end do\n end function\n\n ! get nth prime\n integer pure function prime(n)\n integer, intent(in) :: n\n integer :: i,j \n prime = -1\n if (n<1) then\n return\n endif\n j=0\n i=1\n do while (j counter_max) then\n exit\n end if\n ! increment counter\n counter = counter + 1\n end do\n\n ! print out number of iterations and finally the sum\n print *, 'iterations: ', counter_max\n print *, 'calculated pi: ', sum\n\nend program", "meta": {"hexsha": "0944c0507929aa03817363a219ce950896eba4ee", "size": 1292, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pi.f90", "max_stars_repo_name": "yet-another-alex/basic-fortran-examples", "max_stars_repo_head_hexsha": "ceda57bba880558b230ed9bad994711c74513339", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pi.f90", "max_issues_repo_name": "yet-another-alex/basic-fortran-examples", "max_issues_repo_head_hexsha": "ceda57bba880558b230ed9bad994711c74513339", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pi.f90", "max_forks_repo_name": "yet-another-alex/basic-fortran-examples", "max_forks_repo_head_hexsha": "ceda57bba880558b230ed9bad994711c74513339", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.4893617021, "max_line_length": 116, "alphanum_fraction": 0.6099071207, "num_tokens": 305, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.949669363129097, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7742013253597725}} {"text": "module mod_inv\n#include \n use mod_kinds, only: rk,ik,rdouble,rsingle\n use mod_constants, only: ONE\n use mod_determinant, only: det_3x3\n\n implicit none\n ! External procedures defined in LAPACK\n external DGETRI\n external DGETRF\n external DGECON\n external DLANGE\n external SGETRI\n external SGETRF\n external SGECON\n external SLANGE\n real(rdouble) :: DLANGE\n real(rsingle) :: SLANGE\n\ncontains\n\n !> Compute and return the inverse of a 3x3 matrix.\n !!\n !! This implements an explicit formula for inverting a 3x3 matrix.\n !! See: http://mathworld.wolfram.com/MatrixInverse.html \n !!\n !! @author Nathan A. Wukie (AFRL)\n !! @date 8/14/2017\n !!\n !---------------------------------------------------------------------------\n function inv_3x3(A) result(Ainv)\n real(rk), intent(in) :: A(3,3)\n\n real(rk) :: Ainv(3,3), det\n\n det = det_3x3(A)\n\n Ainv(1,1) = ONE/det * (A(2,2)*A(3,3) - A(2,3)*A(3,2))\n Ainv(1,2) = ONE/det * (A(1,3)*A(3,2) - A(1,2)*A(3,3))\n Ainv(1,3) = ONE/det * (A(1,2)*A(2,3) - A(1,3)*A(2,2))\n\n Ainv(2,1) = ONE/det * (A(2,3)*A(3,1) - A(2,1)*A(3,3))\n Ainv(2,2) = ONE/det * (A(1,1)*A(3,3) - A(1,3)*A(3,1))\n Ainv(2,3) = ONE/det * (A(1,3)*A(2,1) - A(1,1)*A(2,3))\n\n Ainv(3,1) = ONE/det * (A(2,1)*A(3,2) - A(2,2)*A(3,1))\n Ainv(3,2) = ONE/det * (A(1,2)*A(3,1) - A(1,1)*A(3,2))\n Ainv(3,3) = ONE/det * (A(1,1)*A(2,2) - A(1,2)*A(2,1))\n\n\n end function inv_3x3\n !***************************************************************************\n\n\n\n !> Compute and return the derivative of the inverse of a 3x3 matrix A\n !! given an already differentiated matrix A.\n !!\n !! This uses a mathematical preposition for differentiating the inverse\n !! of a square matrix\n !! See: https://atmos.washington.edu/~dennis/MatrixCalculus.pdf \n !!\n !! @author Matteo Ugolotti\n !! @date 7/17/2018\n !!\n !---------------------------------------------------------------------------\n function dinv_3x3(A,dA) result(dAinv)\n real(rk), intent(in) :: A(3,3)\n real(rk), intent(in) :: dA(3,3)\n\n real(rk) :: Ainv(3,3), Ainv_n(3,3), Atemp(3,3), det, dAinv(3,3)\n\n ! Find inverse of A\n Ainv = inv_3x3(A)\n\n ! Negate Ainv\n Ainv_n = -Ainv\n\n Atemp = matmul(Ainv_n,dA)\n\n dAinv = matmul(Atemp,Ainv)\n\n\n end function dinv_3x3\n !***************************************************************************\n\n\n\n\n\n !> Returns the inverse of a matrix calculated by finding the LU\n !! decomposition. Depends on LAPACK.\n !!\n !!\n !!\n !!\n !!\n !---------------------------------------------------------------------------\n function inv(A) result(Ainv)\n real(rk), dimension(:,:), intent(inout) :: A\n real(rk), dimension(size(A,1),size(A,2)) :: Ainv\n\n real(rk), dimension(size(A,1)) :: work ! work array for LAPACK\n integer, dimension(size(A,1)) :: ipiv ! pivot indices\n integer :: n, info\n\n\n\n ! Store A in Ainv to prevent it from being overwritten by LAPACK\n Ainv = A\n n = size(A,1)\n\n\n !\n ! DGETRF computes an LU factorization of a general M-by-N matrix A\n ! using partial pivoting with row interchanges.\n !\n if ( rk == rdouble ) then\n call DGETRF(n, n, Ainv, n, ipiv, info)\n else if ( rk == rsingle ) then\n call SGETRF(n, n, Ainv, n, ipiv, info)\n else\n call chidg_signal(FATAL,\"inv: Invalid selected precision for matrix inversion.\")\n end if\n\n if (info /= 0) then\n call chidg_signal(FATAL,\"inv: Matrix is numerically singular!\")\n end if\n\n\n\n !\n ! DGETRI computes the inverse of a matrix using the LU factorization\n ! computed by DGETRF.\n !\n if ( rk == rdouble ) then\n call DGETRI(n, Ainv, n, ipiv, work, n, info)\n else if ( rk == rsingle ) then\n call SGETRI(n, Ainv, n, ipiv, work, n, info)\n else\n call chidg_signal(FATAL,\"inv: Invalid selected precision for matrix inversion.\")\n end if\n\n\n\n if (info /= 0) then\n call chidg_signal(FATAL,\"inv: matrix inversion failed!.\")\n end if\n\n end function inv\n !**************************************************************************************\n\n\n\n\n\n\n !> Compute and return the derivative of the inverse of a matrix A\n !! given an already differentiated matrix A.\n !!\n !! This uses a mathematical preposition for differentiating the inverse\n !! of a square matrix\n !! See: https://atmos.washington.edu/~dennis/MatrixCalculus.pdf \n !!\n !! @author Matteo Ugolotti\n !! @date 1/31/2019\n !!\n !---------------------------------------------------------------------------\n function dinv(A,dA) result(dAinv)\n real(rk), allocatable, intent(inout) :: A(:,:)\n real(rk), allocatable, intent(in) :: dA(:,:)\n\n real(rk), allocatable :: Ainv(:,:), Ainv_n(:,:), Atemp(:,:), det, dAinv(:,:)\n\n ! Find determinant of A\n !det = det(A)\n\n ! Find inverse of A\n Ainv = inv(A)\n\n ! Negate Ainv\n Ainv_n = -Ainv\n\n Atemp = matmul(Ainv_n,dA)\n\n dAinv = matmul(Atemp,Ainv)\n\n\n end function dinv\n !***************************************************************************\n\n\n\n\n\n\n\n !> Returns the inverse of a complex matrix calculated by finding the LU\n !! decomposition. Depends on LAPACK.\n !!\n !! @author Nathan A. Wukie\n !! @date 1/25/2018\n !!\n !---------------------------------------------------------------------------\n function zinv(A) result(Ainv)\n complex(kind=rk), dimension(:,:), intent(inout) :: A\n complex(kind=rk), dimension(size(A,1),size(A,2)) :: Ainv\n\n complex(kind=rk), dimension(size(A,1)) :: work ! work array for LAPACK\n integer, dimension(size(A,1)) :: ipiv ! pivot indices\n integer :: n, info\n\n\n\n ! Store A in Ainv to prevent it from being overwritten by LAPACK\n Ainv = A\n n = size(A,1)\n\n\n !\n ! ZGETRF computes an LU factorization of a general M-by-N complex matrix A\n ! using partial pivoting with row interchanges.\n !\n if ( rk == rdouble ) then\n call ZGETRF(n, n, Ainv, n, ipiv, info)\n else if ( rk == rsingle ) then\n call CGETRF(n, n, Ainv, n, ipiv, info)\n else\n call chidg_signal(FATAL,\"inv: Invalid selected precision for matrix inversion.\")\n end if\n\n if (info /= 0) then\n call chidg_signal(FATAL,\"inv: Matrix is numerically singular!\")\n end if\n\n\n\n !\n ! DGETRI computes the inverse of a matrix using the LU factorization\n ! computed by DGETRF.\n !\n if ( rk == rdouble ) then\n call ZGETRI(n, Ainv, n, ipiv, work, n, info)\n else if ( rk == rsingle ) then\n call CGETRI(n, Ainv, n, ipiv, work, n, info)\n else\n call chidg_signal(FATAL,\"inv: Invalid selected precision for matrix inversion.\")\n end if\n\n\n\n if (info /= 0) then\n call chidg_signal(FATAL,\"inv: matrix inversion failed!.\")\n end if\n\n end function zinv\n !**************************************************************************************\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nend module mod_inv\n", "meta": {"hexsha": "d3b2e49f42166d8d12a4a40dd0c41fa4cd48a59f", "size": 7614, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical_methods/mod_inv.f90", "max_stars_repo_name": "nwukie/ChiDG", "max_stars_repo_head_hexsha": "d096548ba3bd0a338a29f522fb00a669f0e33e9b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 36, "max_stars_repo_stars_event_min_datetime": "2016-10-05T15:12:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T02:08:23.000Z", "max_issues_repo_path": "src/numerical_methods/mod_inv.f90", "max_issues_repo_name": "nwukie/ChiDG", "max_issues_repo_head_hexsha": "d096548ba3bd0a338a29f522fb00a669f0e33e9b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2016-05-17T02:21:05.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-10T16:33:07.000Z", "max_forks_repo_path": "src/numerical_methods/mod_inv.f90", "max_forks_repo_name": "nwukie/ChiDG", "max_forks_repo_head_hexsha": "d096548ba3bd0a338a29f522fb00a669f0e33e9b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 20, "max_forks_repo_forks_event_min_datetime": "2016-07-18T16:20:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-27T19:26:12.000Z", "avg_line_length": 27.8901098901, "max_line_length": 92, "alphanum_fraction": 0.4847649068, "num_tokens": 2179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693688269984, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.7742013193470362}} {"text": "! HOW TO COMPILE THROUGH COMMAND LINE (CMD OR TERMINAL)\n! gfortran -c Bisection.f95\n! gfortran -o bisection Bisection.o\n!\n! The program is open source and can use to numeric study purpose.\n! The program was build by Aulia Khalqillah,S.Si.,M.Si\n!\n! email: auliakhalqillah.mail@gmail.com\n! ==============================================================================\nprogram bisection_method\n\nimplicit none\nreal :: xi,xf,xr,error,xrold,f,check,limitrange,limiterror\nreal :: start, finish\ninteger :: iter, condition\ncharacter(len=100) :: fmt\n\nwrite(*,*)\"\"\nwrite(*,*)\"---------------------------------\"\nwrite(*,*)\"BISECTION METHOD - FINDING ROOT\"\nwrite(*,*)\"---------------------------------\"\nwrite(*,*) \"\"\nwrite(*,\"(a)\",advance=\"no\") \"Insert Initial Boundary (XI):\"\nread*, xi\nwrite(*,\"(a)\",advance=\"no\") \"Insert Final Boundary (XF):\"\nread*, xf\n\nfmt = \"(a12,a13,a13,a20,a13,a17,a20,a17,a17,a20)\"\nwrite(*,*)\"\"\n\ncall cpu_time(start)\nlimitrange = 1e12\nlimiterror = 1e-10\nopen(20, file='bisection.txt', status='replace')\n check = f(xi)*f(xf)\n ! Automatic change boundary if the f(xi)*f(xf) > 0\n do while (check > 0)\n if (check > limitrange) then\n xi = xi + 1\n check = f(xi) * f(xf)\n else\n xf = xf - 1\n check = f(xi) * f(xf)\n end if\n print*, xi, xf\n end do\n ! Start root calculation\n iter = 1\n xrold = xi\n xr = (xi+xf)/2\n error = abs((xr-xrold)/xr) * 100\n condition = 0\n write(*,fmt)\"ITER\",\"Xi\",\"Xf\",\"F(Xi)\",\"F(Xf)\",\"XROLD\",\"XR[ROOT]\",\"F(XR)\",\"ERROR\",\"CONDITION\"\n do while (error > limiterror .or. isnan(error))\n ! write the result on terminal and save to the file\n write(*,*) iter,xi,xf,f(xi),f(xf),xrold,xr,f(xr),error,condition\n write(20,*) iter,xi,xf,f(xi),f(xf),xrold,xr,f(xr),error,condition \n ! Check first condition of bisection method\n if ((f(xi)*f(xr)) < 0) then\n xf = xr\n xrold = xr\n xr = (xi+xf)/2\n error = abs((xr-xrold)/xr) * 100\n condition = 1\n ! Check second condition of bisection method\n elseif ((f(xi)*f(xr)) > 0) then\n xi = xr\n xrold = xr\n xr = (xi+xf)/2\n error = abs((xr-xrold)/xr) * 100\n condition = 2\n ! Check third condition of bisection method\n elseif (f(xi)*f(xr) == 0) then\n xr = xr\n if (f(xr) == 0) then\n xr = xr\n else\n xr = xi\n endif\n xrold = xr\n error = abs((xr-xrold)/xr) * 100\n condition = 3\n end if\n ! Do the netx iteration\n iter = iter + 1\n end do\nclose(20)\ncall cpu_time(finish)\nprint '(\"Time = \",f12.8,\" seconds.\")',finish-start\nend program\n \nfunction f(x)\nimplicit none\nreal::x,f\n! f = (x**2)-16\nf = (x**2)-(2*x)+1\n! f = (x**3) - (x**2) - (10*x) + 2\nend\n \n", "meta": {"hexsha": "bcea3cd051ce8bd019368d72b3f30f3b03389d26", "size": 2905, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Bisection.f95", "max_stars_repo_name": "auliakhalqillah/Bisection-Method", "max_stars_repo_head_hexsha": "d34b185bd4dbbb719b4786edce3d252bd1504b31", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Bisection.f95", "max_issues_repo_name": "auliakhalqillah/Bisection-Method", "max_issues_repo_head_hexsha": "d34b185bd4dbbb719b4786edce3d252bd1504b31", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Bisection.f95", "max_forks_repo_name": "auliakhalqillah/Bisection-Method", "max_forks_repo_head_hexsha": "d34b185bd4dbbb719b4786edce3d252bd1504b31", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.05, "max_line_length": 95, "alphanum_fraction": 0.5149741824, "num_tokens": 915, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240964782012, "lm_q2_score": 0.8947894618940992, "lm_q1q2_score": 0.7741934037055379}} {"text": "\n\nprogram main\n\nuse euler\n\nimplicit none\n\n integer (kind=8), parameter :: MAXIMUM = 1000000\n integer (kind=8), parameter :: BASE = 10\n integer (kind=8) :: i, count;\n\n count = 1\n\n ! We iterate by adding two for we know it will be an odd number\n do i = 3, MAXIMUM, 2\n\n if(circular_prime(i)) then\n call inc(count, ONE);\n endif\n end do\n\n call printint(count);\n\n\ncontains\n\n\n ! Circulates each integer until it either isn't a prime or if\n ! it is equal to itself\n\n pure function circular_prime(i)\n\n integer (kind=8), intent(in) :: i;\n integer (kind=8) :: tmp;\n logical :: circular_prime;\n\n circular_prime = .false.\n\n if(.NOT.possibly_circular(i)) then\n return\n endif\n\n if(.NOT.isprime(i)) then\n return\n endif\n\n tmp = i\n\n do while(.true.)\n\n tmp = circulate(tmp)\n\n if(.NOT. isprime(tmp)) then\n return\n endif\n\n if(tmp == i) then\n exit\n endif\n end do\n\n circular_prime = .true.\n\n return\n\n end function circular_prime\n\n\n ! Simply puts the number which is at the end of the number to the front\n\n pure function circulate(i)\n\n integer (kind=8), intent(in) :: i;\n integer (kind=8) :: circulate;\n\n if(i < 10) then\n circulate = i;\n return\n endif\n\n circulate = (mod(i, BASE) * BASE ** (intlen(i)) + i) / BASE\n\n end function circulate\n\n\n ! For a number to be prime it must be odd, unless it is two. In this\n ! notion, we may reduce our search space by testing if any of the\n ! digits is even. If so, we know that this number is impossible to\n ! be a circular prime. This saves a lot of cycles as we don't need to\n ! expensively check if numbers are prime or not if they aren't even\n ! in the realms of probability of being true.\n\n pure function possibly_circular(i)\n\n integer (kind=8), intent(in) :: i;\n integer (kind=8) :: tmp;\n logical :: possibly_circular;\n\n possibly_circular = .false.\n tmp = i;\n\n do while(tmp /= 0)\n\n if(mod(mod(tmp, BASE), 2) == 0) then\n return\n endif\n\n tmp = tmp / BASE;\n end do\n \n possibly_circular = .true.\n\n end function possibly_circular\n\n\nend program main\n\n", "meta": {"hexsha": "a541278856b543fc6a658ac9ef27a0b57dd54a1a", "size": 2954, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/circular_primes.f95", "max_stars_repo_name": "guynan/project_euler", "max_stars_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-03-08T09:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T13:52:49.000Z", "max_issues_repo_path": "fortran/circular_primes.f95", "max_issues_repo_name": "guynan/project_euler", "max_issues_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-11-03T01:20:46.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-24T22:54:59.000Z", "max_forks_repo_path": "fortran/circular_primes.f95", "max_forks_repo_name": "guynan/project_euler", "max_forks_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-11-03T01:14:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T13:52:51.000Z", "avg_line_length": 24.8235294118, "max_line_length": 79, "alphanum_fraction": 0.4542992552, "num_tokens": 607, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222396, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7741902145609589}} {"text": "program underflow\n\n use, intrinsic :: iso_fortran_env, only : sp => REAL32, dp => REAL64\n implicit none\n integer, parameter :: n = 5\n real(kind=sp), dimension(n) :: x = [ 1.0e-31_sp, 1.0e-31_sp, 5.0_sp, &\n 1.0e31_sp, 1.0e31_sp ]\n integer :: i;\n real(kind=sp) :: prod\n real(kind=sp) :: log_prod\n real(kind=dp) :: dprod\n prod = 1.0_sp\n log_prod = 0.0_sp\n dprod = 1.0_dp\n do i = 1, n\n prod = prod*x(i)\n end do\n do i = 1, n\n dprod = dprod*x(i)\n end do\n do i = 1, n\n log_prod = log_prod + log(x(i))\n end do\n print '(A, F20.15)', 'REAL32 product = ', prod\n print '(A, F20.15)', 'REAL64 product = ', dprod\n print '(A, F20.15)', 'log REAL32 product = ', exp(log_prod)\n prod = 1.0_sp;\n do i = 1, n\n prod = prod*x(i)\n end do\n print '(A, F20.15)', 'REAL32 product (reverse) = ', prod\n\nend program underflow\n", "meta": {"hexsha": "a1005cb9a7ae9722a355f3f23b5ad9c9683eeb60", "size": 936, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Debugging/Arithmetic/underflow.f90", "max_stars_repo_name": "Gjacquenot/training-material", "max_stars_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 115, "max_stars_repo_stars_event_min_datetime": "2015-03-23T13:34:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T00:27:21.000Z", "max_issues_repo_path": "Debugging/Arithmetic/underflow.f90", "max_issues_repo_name": "Gjacquenot/training-material", "max_issues_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 56, "max_issues_repo_issues_event_min_datetime": "2015-02-25T15:04:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T07:42:48.000Z", "max_forks_repo_path": "Debugging/Arithmetic/underflow.f90", "max_forks_repo_name": "Gjacquenot/training-material", "max_forks_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 59, "max_forks_repo_forks_event_min_datetime": "2015-11-26T11:44:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T00:27:22.000Z", "avg_line_length": 27.5294117647, "max_line_length": 74, "alphanum_fraction": 0.5224358974, "num_tokens": 338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777928, "lm_q2_score": 0.8418256492357359, "lm_q1q2_score": 0.774178670873541}} {"text": "program rec_bisec\n implicit none\n\n interface\n function bisec_r(x_l, x_u, tol)\n real(8) :: bisec_r\n real(8), intent(in) :: x_l, x_u, tol\n end function bisec_r\n end interface\n\n integer, parameter :: r8=SELECTED_REAL_KIND(15)\n real(r8) :: x_r, a, b, tol=1.0e-12\n real(r8) :: func\n\n a=0.0\n b=30.0\n\n x_r=bisec_r(a, b, tol)\n\n print *, \"raiz=\", x_r\n print *, \"f(x)=\", func(x_r)\n\nend program rec_bisec\n\nrecursive function bisec_r(x_l, x_u, tol) result(root)\n implicit none\n !Declaro argumentos\n real(8), intent(in) :: x_l, x_u, tol\n real(8) :: root\n\n !Declaro variables internas\n real(8) :: x_m, func\n\n x_m = (x_l+x_u)/2._8\n print *, x_m, func(x_m)\n\n if ((abs(x_u-x_m)/2._8 < tol).AND.(func(x_m)= 0.5d0) then\n call eMsg('trimmedmean:alpha >= 50% does not make sense')\n endif\n ! Calculate the number of integers that make up the trimmed percentage\n tmp=idnint(alpha_*dble(N))\n\n ! Set the indices into the vector\n call allocate(i, N)\n call arange(i, 1, N)\n\n ! Sort the vector\n call argSort(this,i)\n\n call allocate(iTmp, N-(2*tmp))\n iTmp = this(i(tmp+1:N-tmp))\n res=mean(iTmp)\n call deallocate(i)\n call deallocate(iTmp)\n\n end procedure\n !====================================================================!\n !====================================================================!\n module procedure std_id1D\n !! Interfaced with std()\n !====================================================================!\n !integer(i64) :: this(:)\n !real(r64) :: res\n res=dsqrt(Variance(this))\n end procedure\n !====================================================================!\n !====================================================================!\n module procedure Variance_id1D\n !====================================================================!\n !integer(i64) :: this(:)\n !real(r64) :: res\n real(r64) :: tmp\n tmp=Mean(this)\n res=sum(dble(this-tmp)**2.d0)/dble(size(this)-1)\n end procedure\n !====================================================================!\n\nend submodule\n", "meta": {"hexsha": "c2abba808cca2326948868637fea4e0ba3a86c2e", "size": 5740, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/maths/sm_maths_id1D.f90", "max_stars_repo_name": "leonfoks/coretran", "max_stars_repo_head_hexsha": "bf998d4353badc91d3a12d23c78781c8377b9578", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 72, "max_stars_repo_stars_event_min_datetime": "2017-10-20T15:19:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T11:17:43.000Z", "max_issues_repo_path": "src/maths/sm_maths_id1D.f90", "max_issues_repo_name": "leonfoks/coretran", "max_issues_repo_head_hexsha": "bf998d4353badc91d3a12d23c78781c8377b9578", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2017-10-20T15:54:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T09:45:01.000Z", "max_forks_repo_path": "src/maths/sm_maths_id1D.f90", "max_forks_repo_name": "leonfoks/coretran", "max_forks_repo_head_hexsha": "bf998d4353badc91d3a12d23c78781c8377b9578", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-02-20T15:07:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-10T17:58:00.000Z", "avg_line_length": 33.1791907514, "max_line_length": 72, "alphanum_fraction": 0.4012195122, "num_tokens": 1326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.8596637451167995, "lm_q1q2_score": 0.7741528039334739}} {"text": "\n PROGRAM TEST\n USE FMZM\n IMPLICIT NONE\n\n! Examples and advice for using FM_INTEGRATE.\n\n TYPE (FM), SAVE :: A, B, CHECK, ERR, PI, R1, R2, RESULT, SEVEN, TOL\n TYPE (FM), EXTERNAL :: F\n INTEGER :: K, KPRT, N, N_ERRORS, NW\n CHARACTER(80) :: ST1\n\n N_ERRORS = 0\n\n\n\n! 1. Start with an integral without singularities on the interval of integration.\n\n! integrate log(t) * cos(t) from pi/4 to pi/2.\n\n! Set the tolerance to get at least 40 significant digits.\n! FM_INTEGRATE does a sequence of iterations using the tanh-sinh quadrature formula.\n! Each iteration uses more points until the last two iterates agree within the\n! specified tolerance. Since the next-to-last iterate satisfies the tolerance\n! and the last iterate (returned as RESULT) is even more accurate, the value\n! returned from FM_INTEGRATE is usually slightly more accurate than requested.\n! In this case, the error check below shows that RESULT is actually correct\n! to about 60 digits.\n\n! It is usually best to set FM's precision level to be slightly higher than the\n! number of digits requested with the tolerance. Here we set precision to 20\n! more digits.\n\n N = 1\n\n! Call FM_SET to define FM's precision level before any multiple precision variables\n! are defined. This sets 60-digit precision and TOL is 1.0e-40.\n\n K = 40\n CALL FM_SET(K+20)\n TOL = TO_FM(10) ** (-K)\n\n WRITE (*,\"(//)\")\n CALL FM_PI(PI)\n\n! A and B are the limits for the integral.\n\n A = PI / 4\n B = PI / 2\n\n! KPRT controls trace printing in FM_INTEGRATE. Setting it to 1 will print a summary\n! of the call, giving the result, number of function evaluations, and time.\n! NW is the unit number for this trace output.\n\n KPRT = 1\n NW = 6\n\n CALL FM_INTEGRATE(F,N,A,B,TOL,RESULT,KPRT,NW)\n\n! For these sample problems the integrals have known closed-form results, so\n! we can check the accuracy of FM_INTEGRATE.\n\n CHECK = LOG(PI/2) - LOG(PI/4)/SQRT(TO_FM(2)) + SIN_INTEGRAL(PI/4) - SIN_INTEGRAL(PI/2)\n\n ERR = ABS( RESULT - CHECK )\n CALL FM_FORM('ES12.4',ERR,ST1)\n WRITE (*,\"(/10X,A,I2,A,A)\") ' Error for case ',N,' = ',TRIM(ST1)\n IF (ERR > TOL) N_ERRORS = N_ERRORS + 1\n\n\n\n! 2. Next do an integral with a singularity at zero\n! (from \"Integrals of Powers of LogGamma\" by T. Amdeberhan, M. Coffey, O. Espinosa,\n! C. Koutschan, D. Manna, and V. Moll, in Proc. Amer. Math. Soc., #139, 2011)\n\n! integrate log( gamma(t) ) from 0 to 1.\n\n! Leave precision and tolerance the same as above.\n\n! The tanh-sinh algorithm is good at handling singularities at the endpoints,\n! so this case takes about the same number of function evaluations as case 1.\n\n N = 2\n WRITE (*,\"(//)\")\n A = 0\n B = 1\n TOL = TO_FM(10) ** (-K)\n KPRT = 1\n NW = 6\n\n CALL FM_INTEGRATE(F,N,A,B,TOL,RESULT,KPRT,NW)\n\n CHECK = LOG( SQRT( 2*PI ) )\n ERR = ABS( RESULT - CHECK )\n CALL FM_FORM('ES12.4',ERR,ST1)\n WRITE (*,\"(/10X,A,I2,A,A)\") ' Error for case ',N,' = ',TRIM(ST1)\n IF (ERR > TOL) N_ERRORS = N_ERRORS + 1\n\n\n\n! 3. This integral has a pole at pi/2 and a sqrt singularity at zero.\n! (from \"A Comparison of Three High-Precision Quadrature Schemes\" by D. H. Bailey,\n! K. Jeyabalan, and X. S. Li, in Experimental Mathematics, Vol 14 (2005), No. 3)\n\n! integrate sqrt( tan(t) ) from 0 to pi/2.\n\n! Set tolerance to give 100 digits.\n\n! Here the fact that the pi/2 endpoint is not exactly representable in floating\n! point form causes a problem. FM_INTEGRATE will increase precision above the\n! user's level while computing the integral. But the endpoints A and B are input\n! values that were defined at the user's precision, and their extra digits will be\n! zeros when precision is raised in FM_INTEGRATE.\n\n! That is fine for A = 0, but B = pi/2 will still be accurate only to the user's\n! precision, not to the higher intermediate precision. The fact that B is a\n! singularity for the function means that FM_INTEGRATE will need to know the\n! position of B to higher precision to evaluate the integral accurately.\n\n! The fix is to make a change of variables to get an equivalent integral where\n! both endpoints are exact in floating point. Leaving a singular endpoint inexact\n! will usually cause FM_INTEGRATE to run much slower, and sometimes fail.\n\n! Let u = t * 2 / pi. Then t = u * pi / 2 and dt = pi/2 du.\n! The new form of this integral becomes:\n\n! integrate sqrt( abs( tan( u * pi / 2 ) ) ) * pi / 2 from 0 to 1.\n\n! Now pi will be computed inside function F, so it will be done at whatever higher\n! precision FM_INTEGRATE uses.\n\n! When changing variables in this case, we also need to defend against rounding\n! errors when computing u * pi / 2. When u is very close to 1, rounding could\n! cause u * pi / 2 to round up, giving a value slightly greater than pi/2.\n! Then tan would return a negative value and then sqrt would return unknown,\n! causing the integration to fail. The fix is to take the absolute value before\n! doing the square root.\n\n N = 3\n K = 100\n CALL FM_SET(K+20)\n\n! Precision has increased, so we must get pi at the new precision.\n\n CALL FM_PI(PI)\n WRITE (*,\"(//)\")\n A = 0\n B = 1\n TOL = TO_FM(10) ** (-K)\n KPRT = 1\n NW = 6\n\n CALL FM_INTEGRATE(F,N,A,B,TOL,RESULT,KPRT,NW)\n\n CHECK = PI * SQRT( TO_FM(2) ) / 2\n ERR = ABS( RESULT - CHECK )\n CALL FM_FORM('ES12.4',ERR,ST1)\n WRITE (*,\"(/10X,A,I2,A,A)\") ' Error for case ',N,' = ',TRIM(ST1)\n IF (ERR > TOL) N_ERRORS = N_ERRORS + 1\n\n\n\n! 4. integrate exp( -t**2 / 2 ) from 0 to infinity.\n! (from \"A Comparison of Three High-Precision Quadrature Schemes\" by D. H. Bailey,\n! K. Jeyabalan, and X. S. Li, in Experimental Mathematics, Vol 14 (2005), No. 3)\n\n! Set tolerance to give 100 digits.\n\n! Infinite regions must be converted to finite ones. Let u = 1/(t+1) to get:\n\n! integrate exp( -(1/u - 1)**2 / 2 ) / u**2 from 0 to 1.\n\n! Exponential functions pose another problem for FM_INTEGRATE.\n! When u is very close to zero the exponential can underflow. FM does not flush\n! underflows to zero like most floating point systems, so when that value is\n! then divided by the small u**2 FM detects the possibility that this result\n! could be above the underflow threshold. Since FM can't be sure whether the\n! true function value is below the underflow threshold, unknown is returned.\n\n! The fix in this case is to see that whenever underflow occurs in this integration\n! the final function value is too small to change the integral. That is the usual\n! situation whenever F underflows and the final value of the integral is greater\n! than 10**(-10**6) in magnitude, because FM's underflow is less than 10**(-10**8).\n! So we check for underflow after doing the exponential in function F and replace\n! underflowed function values by zero.\n\n N = 4\n K = 100\n CALL FM_SET(K+20)\n CALL FM_PI(PI)\n WRITE (*,\"(//)\")\n A = 0\n B = 1\n TOL = TO_FM(10) ** (-K)\n KPRT = 1\n NW = 6\n\n CALL FM_INTEGRATE(F,N,A,B,TOL,RESULT,KPRT,NW)\n\n CHECK = SQRT( PI / 2 )\n ERR = ABS( RESULT - CHECK )\n CALL FM_FORM('ES12.4',ERR,ST1)\n WRITE (*,\"(/10X,A,I2,A,A)\") ' Error for case ',N,' = ',TRIM(ST1)\n IF (ERR > TOL) N_ERRORS = N_ERRORS + 1\n\n\n\n! 5. integrate log( abs( ( tan(t) + sqrt(7) ) / ( tan(t) - sqrt(7) ) ) )\n! from pi/3 to pi/2.\n! (from \"High-Precision Numerical Integration: Progress and Challenges\"\n! by D. H. Bailey and J. M. Borwein (2009))\n\n! Set tolerance to give 150 digits.\n\n! There is only one singularity, but it is atan(sqrt(7)), which is not an endpoint.\n! FM_INTEGRATE will initially have very slow convergence and then will try to\n! isolate the singularity and split into two integrals with the singularity at\n! endpoints.\n\n! This strategy works here, but it is slower and doesn't always succeed.\n! Case 6 shows a better way to handle interior singularities.\n\n N = 5\n K = 150\n CALL FM_SET(K+20)\n CALL FM_PI(PI)\n WRITE (*,\"(//)\")\n A = PI/3\n B = PI/2\n TOL = TO_FM(10) ** (-K)\n KPRT = 1\n NW = 6\n\n CALL FM_INTEGRATE(F,N,A,B,TOL,RESULT,KPRT,NW)\n\n SEVEN = 7\n CHECK = ( SQRT(SEVEN) / 168 ) * ( POLYGAMMA(1,1/SEVEN) + POLYGAMMA(1,2/SEVEN) - &\n POLYGAMMA(1,3/SEVEN) + POLYGAMMA(1,4/SEVEN) - &\n POLYGAMMA(1,5/SEVEN) - POLYGAMMA(1,6/SEVEN) )\n ERR = ABS( RESULT - CHECK )\n CALL FM_FORM('ES12.4',ERR,ST1)\n WRITE (*,\"(/10X,A,I2,A,A)\") ' Error for case ',N,' = ',TRIM(ST1)\n IF (ERR > TOL) N_ERRORS = N_ERRORS + 1\n\n\n\n! 6. Same integral as case 5.\n\n! integrate log( abs( ( tan(t) + sqrt(7) ) / ( tan(t) - sqrt(7) ) ) )\n! from pi/3 to pi/2.\n\n! Set tolerance to give 150 digits.\n\n! Split into two integrals and change variables to make the endpoints exact.\n! This will be faster than making FM_INTEGRATE search for the interior singularity\n! as in case 5.\n! Call the two function numbers 61 and 62.\n\n! 1. from pi/3 to atan(sqrt(7)).\n! Let u = ( t - pi/3 ) / ( atan( sqrt(7) ) - pi/3 )\n\n! 2. from atan(sqrt(7)) to pi/2.\n! Let v = ( t - atan(sqrt(7)) ) / ( pi/2 - atan( sqrt(7) ) )\n\n! This gives two integrals from 0 to 1, then we add the two results.\n\n N = 6\n K = 150\n CALL FM_SET(K+20)\n CALL FM_PI(PI)\n WRITE (*,\"(//)\")\n A = 0\n B = 1\n TOL = TO_FM(10) ** (-K)\n KPRT = 1\n NW = 6\n\n CALL FM_INTEGRATE(F,61,A,B,TOL,R1,KPRT,NW)\n CALL FM_INTEGRATE(F,62,A,B,TOL,R2,KPRT,NW)\n RESULT = R1 + R2\n\n WRITE (*,*) ' '\n WRITE (*,*) ' Adding these last two integrals gives the case 6 result:'\n WRITE (*,*) ' '\n CALL FM_PRINT(RESULT)\n\n SEVEN = 7\n CHECK = ( SQRT(SEVEN) / 168 ) * ( POLYGAMMA(1,1/SEVEN) + POLYGAMMA(1,2/SEVEN) - &\n POLYGAMMA(1,3/SEVEN) + POLYGAMMA(1,4/SEVEN) - &\n POLYGAMMA(1,5/SEVEN) - POLYGAMMA(1,6/SEVEN) )\n ERR = ABS( RESULT - CHECK )\n CALL FM_FORM('ES12.4',ERR,ST1)\n WRITE (*,\"(/10X,A,I2,A,A)\") ' Error for case ',N,' = ',TRIM(ST1)\n IF (ERR > TOL) N_ERRORS = N_ERRORS + 1\n\n\n\n! 7. Same integral as cases 5 and 6.\n! Combine these two integrals into one, so only one call to FM_INTEGRATE is needed.\n! This will be faster than doing two calls as in case 6.\n\n! integrate log( abs( ( tan(t) + sqrt(7) ) / ( tan(t) - sqrt(7) ) ) )\n! from pi/3 to pi/2.\n\n! Set tolerance to give 150 digits.\n\n! Split into two integrals and change variables to make the endpoints exact.\n! Both new integrals are from 0 to 1.\n\n! 1. from pi/3 to atan(sqrt(7)).\n! Let u = ( t - pi/3 ) / ( atan( sqrt(7) ) - pi/3 )\n\n! 2. from atan(sqrt(7)) to pi/2.\n! Let v = ( t - atan(sqrt(7)) ) / ( pi/2 - atan( sqrt(7) ) )\n\n N = 7\n K = 150\n CALL FM_SET(K+20)\n CALL FM_PI(PI)\n WRITE (*,\"(//)\")\n A = 0\n B = 1\n TOL = TO_FM(10) ** (-K)\n KPRT = 1\n NW = 6\n\n CALL FM_INTEGRATE(F,7,A,B,TOL,RESULT,KPRT,NW)\n\n SEVEN = 7\n CHECK = ( SQRT(SEVEN) / 168 ) * ( POLYGAMMA(1,1/SEVEN) + POLYGAMMA(1,2/SEVEN) - &\n POLYGAMMA(1,3/SEVEN) + POLYGAMMA(1,4/SEVEN) - &\n POLYGAMMA(1,5/SEVEN) - POLYGAMMA(1,6/SEVEN) )\n ERR = ABS( RESULT - CHECK )\n CALL FM_FORM('ES12.4',ERR,ST1)\n WRITE (*,\"(/10X,A,I2,A,A)\") ' Error for case ',N,' = ',TRIM(ST1)\n IF (ERR > TOL) N_ERRORS = N_ERRORS + 1\n\n\n\n WRITE (*,*) ' '\n WRITE (*,*) ' '\n IF (N_ERRORS == 0) THEN\n WRITE (*,*) ' All results were ok -- no errors were found.'\n ELSE\n WRITE (*,*) N_ERRORS,' error(s) were found.'\n ENDIF\n WRITE (*,*) ' '\n\n STOP\n END PROGRAM TEST\n\n FUNCTION F(X,N) RESULT (RETURN_VALUE)\n USE FMZM\n IMPLICIT NONE\n\n TYPE (FM) :: RETURN_VALUE, X\n TYPE (FM), SAVE :: C1, C2, PI, SQRT7, TANX\n INTEGER :: N\n\n IF (N == 1) THEN\n RETURN_VALUE = LOG(X) * COS(X)\n ELSE IF (N == 2) THEN\n RETURN_VALUE = LOG( GAMMA( X ) )\n ELSE IF (N == 3) THEN\n\n! The original limits from 0 to pi/2 have been changed to 0 to 1.\n\n CALL FM_PI(PI)\n RETURN_VALUE = PI * SQRT( ABS( TAN( PI * X / 2 ) ) ) / 2\n ELSE IF (N == 4) THEN\n\n! Exp could underflow and then make F unknown.\n! Check for the underflow and set F = 0 in that case.\n\n RETURN_VALUE = EXP( -(1 - 1/X)**2 / 2 )\n IF ( IS_UNDERFLOW(RETURN_VALUE) ) THEN\n RETURN_VALUE = 0\n ELSE\n RETURN_VALUE = RETURN_VALUE / X**2\n ENDIF\n ELSE IF (N == 5) THEN\n SQRT7 = SQRT(TO_FM(7))\n TANX = TAN(X)\n RETURN_VALUE = LOG( ABS( ( TANX + SQRT7 ) / ( TANX - SQRT7 ) ) )\n ELSE IF (N == 61) THEN\n CALL FM_PI(PI)\n\n! It is tempting to compute constants like C1, C2, SQRT7 once and then save them for\n! use in subsequent calls to F. That can be done, but it is trickier than it seems,\n! since FM_INTEGRATE may call F with different precision levels during one integration,\n! so it is easy to not have the right precision in a saved variable.\n! Here we just compute them each time, making the logic straightforward while the\n! function evaluations are somewhat slower.\n\n SQRT7 = SQRT(TO_FM(7))\n C1 = ATAN(SQRT7) - PI/3\n TANX = TAN( C1*X + PI/3 )\n RETURN_VALUE = C1 * LOG( ABS( ( TANX + SQRT7 ) / ( TANX - SQRT7 ) ) )\n ELSE IF (N == 62) THEN\n CALL FM_PI(PI)\n SQRT7 = SQRT(TO_FM(7))\n C2 = ATAN(SQRT7)\n C1 = PI/2 - C2\n TANX = TAN( C1*X + C2 )\n RETURN_VALUE = C1 * LOG( ABS( ( TANX + SQRT7 ) / ( TANX - SQRT7 ) ) )\n ELSE IF (N == 7) THEN\n\n! Combine the two integrals into one.\n\n CALL FM_PI(PI)\n SQRT7 = SQRT(TO_FM(7))\n C2 = ATAN(SQRT7)\n C1 = C2 - PI/3\n TANX = TAN( C1*X + PI/3 )\n RETURN_VALUE = C1 * LOG( ABS( ( TANX + SQRT7 ) / ( TANX - SQRT7 ) ) )\n\n C1 = PI/2 - C2\n TANX = TAN( C1*X + C2 )\n RETURN_VALUE = RETURN_VALUE + C1 * LOG( ABS( ( TANX + SQRT7 ) / ( TANX - SQRT7 ) ) )\n ENDIF\n\n END FUNCTION F\n", "meta": {"hexsha": "38e241a0fff3e63f3423f64a399961d474bfcbc7", "size": 16158, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Libraries/FM/FMsamples/SampleFMintegrate.f95", "max_stars_repo_name": "andreypudov/projecteuler", "max_stars_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2022-01-30T20:37:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T21:03:21.000Z", "max_issues_repo_path": "Libraries/FM/FMsamples/SampleFMintegrate.f95", "max_issues_repo_name": "andreypudov/projecteuler", "max_issues_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Libraries/FM/FMsamples/SampleFMintegrate.f95", "max_forks_repo_name": "andreypudov/projecteuler", "max_forks_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.1985815603, "max_line_length": 100, "alphanum_fraction": 0.5310063127, "num_tokens": 4661, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7740995624095567}} {"text": "recursive function ackermann (m, n) result (res)\n integer, intent(in) :: m, n\n integer :: res\n if (m == 0) then\n res = n + 1\n else if (n == 0) then\n res = ackermann(m - 1, 1)\n else\n res = ackermann(m - 1, ackermann(m, n - 1))\n end if\nend function ackermann\n", "meta": {"hexsha": "21a5f83024daf0b2bb57ce87eb3afa32d9e67a28", "size": 272, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ackermann.f95", "max_stars_repo_name": "yuul/ackermann_func", "max_stars_repo_head_hexsha": "ef0375087cae91a31049f66fda2236a39478c7ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-02-09T23:37:02.000Z", "max_stars_repo_stars_event_max_datetime": "2018-02-10T23:34:32.000Z", "max_issues_repo_path": "ackermann.f95", "max_issues_repo_name": "yuul/ackermann_func", "max_issues_repo_head_hexsha": "ef0375087cae91a31049f66fda2236a39478c7ba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ackermann.f95", "max_forks_repo_name": "yuul/ackermann_func", "max_forks_repo_head_hexsha": "ef0375087cae91a31049f66fda2236a39478c7ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-02-10T18:44:43.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-21T01:35:14.000Z", "avg_line_length": 22.6666666667, "max_line_length": 48, "alphanum_fraction": 0.5845588235, "num_tokens": 102, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7740796411113703}} {"text": "program intrinsics_06\nreal :: x\n\nx = asin(0.84147098)\nprint *, x\n\nx = acos(0.54030231)\nprint *, x\n\nx = atan(1.5574077)\nprint *, x\n\nx = asinh(1.1752012)\nprint *, x\n\nx = acosh(1.5430806)\nprint *, x\n\nx = atanh(0.76159416)\nprint *, x\n\nend\n", "meta": {"hexsha": "7c7a07de4626510af62763dd164556ffe1625179", "size": 235, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/intrinsics_06.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/intrinsics_06.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/intrinsics_06.f90", "max_forks_repo_name": "Thirumalai-Shaktivel/lfortran", "max_forks_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-03-28T19:40:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:28:55.000Z", "avg_line_length": 10.2173913043, "max_line_length": 21, "alphanum_fraction": 0.629787234, "num_tokens": 100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.924141826246517, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7740796369963583}} {"text": "!!\n!> @brief Random Number Generator\n!! \n!! Module to generate random numbers that follow a Gaussian distribution\n!! and the Box-Muller form. In addtion, there is a 100 number generator that\n!! writes the numbers in an external file and a subroutine to verify the\n!! Box-Muller number generator.\n!!\n!! @author Marielle Elizabeth Duran\n!!\n module random_num\n use precisions, only: dp\n use constants, only: pi\n IMPLICIT NONE\n PRIVATE \n PUBLIC box_muller_num, generator_100_num, verify_box_muller_num\n CONTAINS\n\n!!\n!> @brief Box-Muller random number generator\n!!\n!! Generates random numbers that fit a Gaussian distribution and the\n!! Box-Muller transform. Each value is saved so that a repeat value is\n!! rejected.\n!!\n!! @author Marielle Elizabeth Duran\n!!\n subroutine box_muller_num(z_1)\n IMPLICIT NONE\n REAL(dp), intent(out) :: z_1\n REAL(dp) :: x, y\n REAL(dp), save :: z_0 !< saved Box-Muller number\n LOGICAL, save :: not_available = .TRUE.\n IF (not_available) THEN\n not_available = .FALSE.\n call random_number(x)\n call random_number(y)\n z_0 = SQRT(-2.0*LOG(x)) * COS(2.0*pi*y)\n z_1 = SQRT(-2.0*LOG(x)) * SIN(2.0*pi*y)\n ELSE\n z_1 = z_0\n not_available = .TRUE.\n END IF \n end subroutine box_muller_num\n\n!!\n!> @brief Generates 100 numbers with Box-Muller form\n!!\n!! Calls a random number using the box_muller_num subroutine. This\n!! subroutine generates 100 of these numbers and writes them to the\n!! external file named 'generator_info.dat'.\n!!\n!! @author Marielle Elizabeth Duran\n!!\n subroutine generator_100_num\n IMPLICIT NONE\n real(dp) :: x\n integer :: i\n call box_muller_num(x)\n PRINT*, x\n open(7, file = 'generator_info.dat', status =&\n 'unknown')\n DO i = 1,100\n call box_muller_num(x)\n WRITE(7,*) x\n END DO\n close(7)\n end subroutine generator_100_num\n\n!!\n!> @brief Verifies the box_muller_num subroutine results\n!!\n!! Creates an array to put in random numbers from box_muller_num. This\n!! array is used to calculate the mean and standard deviation of the\n!! random numbers. These steps are completed to verify that the\n!! box_muller_num subroutine follows a Gaussian distribution.\n!!\n!! @author Marielle Elizabeth Duran\n!!\n subroutine verify_box_muller_num(n_samples)\n IMPLICIT NONE\n integer, intent(in) :: n_samples\n real(dp) :: mean, num, variance, stan_dev\n real(dp), dimension(n_samples) :: random_numbers \n integer :: i\n DO i = 1, n_samples\n call box_muller_num(num)\n random_numbers(i) = num\n END DO\n mean = 0.0_dp\n DO i = 1, n_samples\n mean = mean + random_numbers(i)\n END DO\n mean = mean/n_samples\n variance = 0.0_dp\n DO i = 1, n_samples\n variance = variance + (&\n random_numbers(i) - mean)&\n **2.0_dp\n END DO\n variance = variance / (n_samples - 1)\n stan_dev = SQRT(variance)\n print*, mean\n print*, stan_dev\n end subroutine verify_box_muller_num\n end module random_num\n", "meta": {"hexsha": "5018f5596bd3c6e5121d4ccdb13c4895c4b8c21d", "size": 4293, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/random_num.f90", "max_stars_repo_name": "rnavarroperez/nn-scattering-fit", "max_stars_repo_head_hexsha": "055d21574fc02159ad0e785fa137ddfa874f88da", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-30T02:41:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-30T02:41:03.000Z", "max_issues_repo_path": "src/random_num.f90", "max_issues_repo_name": "rnavarroperez/nn-scattering-fit", "max_issues_repo_head_hexsha": "055d21574fc02159ad0e785fa137ddfa874f88da", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2020-04-17T02:13:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-05T21:11:08.000Z", "max_forks_repo_path": "src/random_num.f90", "max_forks_repo_name": "rnavarroperez/nn-scattering-fit", "max_forks_repo_head_hexsha": "055d21574fc02159ad0e785fa137ddfa874f88da", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.1214953271, "max_line_length": 79, "alphanum_fraction": 0.4726298626, "num_tokens": 846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109956, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7740796358613686}} {"text": "!Autor: Claudio Iván Esparza Castañeda\n!Título: Pi\n!Descripción: Calcula Pi por medio de la serie de Leibinz\n!Fecha: 15/03/2020\n\nProgram CPi !Inicio del programa\n implicit none !Quitar variables implícitas\n REAL*16::pi, s !Declaración de variables reales de 16 bits\n INTEGER::i !Variable entera iterativa\n s=0.0 !inicializar memoria auxiliar\n do i=0, 1000000000 !Ciclo que contiene a la serie\n s=(-1.0)**i/(2.0*i+1.0)+s !Forma matemática de la serie\n end do \n pi=4.0*s !Valor de pi igual a cuatro veces el valor de la serie\n write(*, *) pi !Imprimir pi\nend Program CPi !Finalizar programa\n\n", "meta": {"hexsha": "61c6a102769c529811dd7e792cba534820c60eef", "size": 602, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "2.- Pi/Pi.f90", "max_stars_repo_name": "clivan/Fortran", "max_stars_repo_head_hexsha": "4f842c6433899cc36b8c27c71f7667ba0ed15312", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2.- Pi/Pi.f90", "max_issues_repo_name": "clivan/Fortran", "max_issues_repo_head_hexsha": "4f842c6433899cc36b8c27c71f7667ba0ed15312", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2.- Pi/Pi.f90", "max_forks_repo_name": "clivan/Fortran", "max_forks_repo_head_hexsha": "4f842c6433899cc36b8c27c71f7667ba0ed15312", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.4444444444, "max_line_length": 65, "alphanum_fraction": 0.7292358804, "num_tokens": 208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850039701655, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7740378613897941}} {"text": " subroutine watan(xr,xi,yr,yi)\nc\nc PURPOSE\nc watan compute the arctangent of a complex number\nc y = yr + i yi = atan(x), x = xr + i xi\nc\nc CALLING LIST / PARAMETERS\nc subroutine watan(xr,xi,yr,yi)\nc double precision xr,xi,yr,yi\nc\nc xr,xi: real and imaginary parts of the complex number\nc yr,yi: real and imaginary parts of the result\nc yr,yi may have the same memory cases than xr et xi\nc\nc COPYRIGHT (C) 2001 Bruno Pincon and Lydia van Dijk\nc Written by Bruno Pincon so\nc as to get more precision. Also to fix the\nc behavior at the singular points and at the branch cuts.\nc Polished by Lydia van Dijk \nc \nc \nc CHANGES : - (Bruno on 2001 May 22) for ysptrk use a \nc minimax polynome to enlarge the special\nc evaluation zone |s| < SLIM. Also rename\nc this function as lnp1m1.\nc - (Bruno on 2001 June 7) better handling\nc of spurious over/underflow ; remove\nc the call to pythag ; better accuracy\nc in the real part for z near +-i\nc\nc EXTERNALS FUNCTIONS\nc dlamch\nc lnp1m1 (at the end of this file)\nc\nc ALGORITHM : noting z = a + i*b, we have:\nc Z = yr + yi*b = arctan(z) = (i/2) * log( (i+z)/(i-z) )\nc \nc This function has two branch points at +i and -i and the\nc chosen branch cuts are the two half-straight lines\nc D1 = [i, i*oo) and D2 = (-i*oo, i]. The function is then\nc analytic in C \\ (D1 U D2)). \nc\nc From the definition it follows that:\nc\nc yr = 0.5 Arg ( (i+z)/(i-z) ) (1)\nc yi = 0.5 log (|(i+z)/(i-z)|) (2)\nc\nc so lim (z -> +- i) yr = undefined (and Nan is logical)\nc lim (z -> +i) yi = +oo\nc lim (z -> -i) yi = -oo\nc\nc The real part of arctan(z) is discontinuous across D1 and D2\nc and we impose the following definitions:\nc if imag(z) > 1 then\nc Arg(arctan(z)) = pi/2 (=lim real(z) -> 0+)\nc if imag(z) < 1 then\nc Arg(arctan(z)) = -pi/2 (=lim real(z) -> 0-)\nc \nc\nc Basic evaluation: if we write (i+z)/(i-z) using\nc z = a + i*b, we get:\nc\nc i+z 1-(a**2+b**2) + i*(2a)\nc --- = ---------------------- \nc i-z a**2 + (1-b)**2\nc\nc then, with r2 = |z|^2 = a**2 + b**2 :\nc \nc yr = 0.5 * Arg(1-r2 + (2*a)*i)\nc = 0.5 * atan2(2a, (1-r2)) (3)\nc\nc This formula is changed when r2 > RMAX (max pos float)\nc and also when |1-r2| and |a| are near 0 (see comments\nc in the code).\nc\nc After some math:\nc \nc yi = 0.25 * log( (a**2 + (b + 1)**2) /\nc (a**2 + (b - 1)**2) ) (4) \nc \nc Evaluation for \"big\" |z|\nc ------------------------\nc\nc If |z| is \"big\", the direct evaluation of yi by (4) may\nc suffer of innaccuracies and of spurious overflow. Noting \nc that s = 2 b / (1 + |z|**2), we have:\nc\nc yi = 0.25 log ( (1 + s)/(1 - s) ) (5)\nc\nc 3 5 \nc yi = 0.25*( 2 * ( s + 1/3 s + 1/5 s + ... ))\nc\nc yi = 0.25 * lnp1m1(s) if |s| < SLIM\nc\nc So if |s| is less than SLIM we switch to a special\nc evaluation done by the function lnp1m1. The \nc threshold value SLIM is choosen by experiment \nc (with the Pari-gp software). For |s| \nc \"very small\" we used a truncated taylor dvp, \nc else a minimax polynome (see lnp1m1).\nc\nc To avoid spurious overflows (which result in spurious\nc underflows for s) in computing s with s= 2 b / (1 + |z|**2)\nc when |z|^2 > RMAX (max positive float) we use :\nc\nc s = 2d0 / ( (a/b)*a + b )\nc \nc but if |b| = Inf this formula leads to NaN when\nc |a| is also Inf. As we have :\nc\nc |s| <= 2 / |b|\nc\nc we impose simply : s = 0 when |b| = Inf\nc\nc Evaluation for z very near to i or -i:\nc --------------------------------------\nc Floating point numbers of the form a+i or a-i with 0 <\nc a**2 < tiny (approximately 1d-308) may lead to underflow\nc (i.e., a**2 = 0) and the logarithm will break formula (4).\nc So we switch to the following formulas:\nc\nc If b = +-1 and |a| < sqrt(tiny) approximately 1d-150 (say)\nc then (by using that a**2 + 4 = 4 in machine for such a):\nc \nc yi = 0.5 * log( 2/|a| ) for b=1\nc \nc yi = 0.5 * log( |a|/2 ) for b=-1\nc\nc finally: yi = 0.5 * sign(b) * log( 2/|a| ) \nc yi = 0.5 * sign(b) * (log(2) - log(|a|)) (6)\nc\nc The last trick is to avoid overflow for |a|=tiny! In fact\nc this formula may be used until a**2 + 4 = 4 so that the\nc threshold value may be larger.\nc\n implicit none\nc\nc include '../stack.h'\nc\n double precision xr, xi, yr, yi\n\nc EXTERNAL\n external dlamch, lnp1m1\n double precision dlamch, lnp1m1\nc\n double precision a, b, r2, s, SLIM, ALIM, TOL, LN2\n parameter (SLIM = 0.2d0,\n $ ALIM = 1.d-150,\n $ TOL = 0.3d0,\n $ LN2 = 0.69314718055994531d0)\n\nc STATIC VAR\n logical first\r\n double precision RMAX, HALFPI\r\n save first\n data first /.true./\n save RMAX, HALFPI\n\n if (first) then\n RMAX = dlamch('O')\n first = .false.\n HALFPI = 2.d0*atan(1.d0)\n endif\n\nc Avoid problems due to sharing the same memory locations by\nc xr, yr and xi, yi.\n a = xr\n b = xi\nc\n if (b .eq. 0d0) then\nc z is real\n yr = atan(xr)\n yi = 0d0\n else\nc z is complex\nc (1) Compute the imaginary part of arctan(z)\n r2 = a*a + b*b\n if (r2 .gt. RMAX) then\n if ( abs(b) .gt. RMAX ) then\nc |b| is Inf => s = 0\n s = 0.d0\n else\nc try to avoid the spurious underflow in s when |b| is not\nc negligible with respect to |a|\n s = 1d0 / ( ((0.5d0*a)/b)*a + 0.5d0*b )\n endif\n else\n s = 2d0*b / (1d0 + r2)\n endif\n\n if (abs(s) .lt. SLIM) then\nc s is small: |s| < SLIM <=> |z| outside the following disks:\nc D+ = D(center = [0; 1/slim], radius = sqrt(1/slim**2 - 1)) if b > 0\nc D- = D(center = [0; -1/slim], radius = sqrt(1/slim**2 - 1)) if b < 0\nc use the special evaluation of log((1+s)/(1-s)) (5)\n yi = 0.25d0*lnp1m1(s)\n else\nc |s| >= SLIM => |z| is inside D+ or D-\n if ((abs(b) .eq. 1d0) .and. (abs(a) .le. ALIM)) then\nc z is very near +- i : use formula (6)\n yi = sign(0.5d0, b) * (LN2 - log(abs(a)))\n else\nc use formula (4)\n yi = 0.25d0 * log( (a*a + (b + 1d0)*(b + 1d0)) /\n $ (a*a + (b - 1d0)*(b - 1d0)) )\n endif\n endif\n\nc (2) Compute the real part of arctan(z)\n if (a .eq. 0d0) then\nc z is purely imaginary\n if (abs(b) .gt. 1d0) then\nc got sign(b) * pi/2\n yr = sign(1d0,b) * HALFPI\n elseif (abs(b) .eq. 1d0) then\nc got a Nan with 0/0\n yr = (a - a) / (a - a)\n else\n yr = 0d0\n endif\n elseif (r2 .gt. RMAX) then\nc yr is necessarily very near sign(a)* pi/2 \n yr = sign(1.d0, a) * HALFPI\n elseif ( abs(1.d0 - r2) + abs(a) .le.TOL ) then\nc |b| is very near 1 (and a is near 0) some\nc cancellation occur in the (next) generic formula \n yr = 0.5d0 * atan2(2d0*a, (1.d0-b)*(1.d0+b) - a*a)\n else\nc generic formula\n yr = 0.5d0 * atan2(2d0*a, 1d0 - r2)\n endif\n endif\n end\n\n\n double precision function lnp1m1(s)\n implicit none\n double precision s\nc\nc PURPOSE : Compute v = log ( (1 + s)/(1 - s) )\nc for small s, this is for |s| < SLIM = 0.20\nc\nc ALGORITHM : \nc 1/ if |s| is \"very small\" we use a truncated\nc taylor dvp (by keeping 3 terms) from : \nc 2 4 6\nc t = 2 * s * ( 1 + 1/3 s + 1/5 s + [ 1/7 s + ....] )\nc 2 4 \nc t = 2 * s * ( 1 + 1/3 s + 1/5 s + er)\nc \nc The limit E until we use this formula may be simply\nc gotten so that the negliged part er is such that :\nc 2 4\nc (#) er <= epsm * ( 1 + 1/3 s + 1/5 s ) for all |s|<= E\nc\nc As er = 1/7 s^6 + 1/9 s^8 + ... \nc er <= 1/7 * s^6 ( 1 + s^2 + s^4 + ...) = 1/7 s^6/(1-s^2)\nc\nc the inequality (#) is forced if :\nc\nc 1/7 s^6 / (1-s^2) <= epsm * ( 1 + 1/3 s^2 + 1/5 s^4 )\nc\nc s^6 <= 7 epsm * (1 - 2/3 s^2 - 3/15 s^4 - 1/5 s^6)\nc\nc So that E is very near (7 epsm)^(1/6) (approximately 3.032d-3):\nc\nc 2/ For larger |s| we used a minimax polynome :\nc\nc yi = s * (2 + d3 s^3 + d5 s^5 .... + d13 s^13 + d15 s^15)\nc\nc This polynome was computed (by some remes algorithm) following \nc (*) the sin(x) example (p 39) of the book :\nc \nc \"ELEMENTARY FUNCTIONS\"\nc \"Algorithms and implementation\"\nc J.M. Muller (Birkhauser)\nc\nc (*) without the additionnal raffinement to get the first coefs\nc very near floating point numbers)\nc\n double precision s2\n double precision E, C3, C5\n parameter (E = 3.032d-3, C3 = 2d0 / 3d0, C5 = 2d0 / 5d0)\n\nc minimax poly coefs\n double precision D3, D5, D7, D9, D11, D13, D15\n parameter (\n $ D3 = 0.66666666666672679472d0, D5 = 0.39999999996176889299d0,\n $ D7 = 0.28571429392829380980d0, D9 = 0.22222138684562683797d0,\n $ D11= 0.18186349187499222459d0, D13= 0.15250315884469364710d0,\n $ D15= 0.15367270224757008114d0 )\n\n s2 = s * s\n if (abs(s) .le. E) then\n lnp1m1 = s * (2d0 + s2*(C3 + C5*s2))\n else\n lnp1m1 = s * (2.d0 + s2*(D3 + s2*(D5 + s2*(\n $ D7 + s2*(D9 + s2*(D11 + s2*(D13 + s2*D15)))))))\n endif\n end\n\nc\nc a log(1+x) function for scilab .... \nc \nc\n double precision function logp1(x)\n implicit none\n double precision x\n\n double precision g\n double precision a, b\n parameter ( a = -1d0/3d0, \n $ b = 0.5d0 )\n\n double precision lnp1m1\n external lnp1m1\n \n if ( x .lt. -1.d0 ) then\nc got NaN\n logp1 = (x - x)/(x - x)\n elseif ( a .le. x .and. x .le. b ) then\nc use the function log((1+g)/(1-g)) with g = x/(x + 2)\n g = x/(x + 2.d0)\n logp1 = lnp1m1(g)\n else\nc use the standard formula\n logp1 = log(x + 1.d0)\n endif\n\n end\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "becdb9ba47b23cb096f1cfa90d1ce7f0a7dcc799", "size": 11096, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/calelm/watan.f", "max_stars_repo_name": "alpgodev/numx", "max_stars_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-07-25T20:28:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-10T18:52:08.000Z", "max_issues_repo_path": "src/math/calelm/watan.f", "max_issues_repo_name": "alpgodev/numx", "max_issues_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/math/calelm/watan.f", "max_forks_repo_name": "alpgodev/numx", "max_forks_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.3498542274, "max_line_length": 80, "alphanum_fraction": 0.4852198991, "num_tokens": 3915, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850021922959, "lm_q2_score": 0.8267118004748678, "lm_q1q2_score": 0.7740378599200085}} {"text": "!a wrapper for the example with Dijkstra's algorithm\r\nsubroutine exampleDijkstra(G,start,end)\r\n use iso_fortran_env, wp => real64\r\n use graphf\r\n implicit none\r\n type(graph) :: G\r\n integer :: start,end\r\n real(wp),allocatable :: dist(:)\r\n integer,allocatable :: prev(:)\r\n integer,allocatable :: path(:)\r\n real(wp) :: dummy\r\n integer :: lpath\r\n integer :: i\r\n\r\n !-- allocate space for the dist and prev vectors\r\n allocate(dist(G%V),prev(G%V))\r\n\r\n !-- run Dijkstra's algo, get distance and prev\r\n call Dijkstra(G, start, dist, prev)\r\n \r\n !-- allocate an array for analyzing the path\r\n allocate(path(G%V), source = 0)\r\n if(dist(end) == huge(dummy))then\r\n write(*,'(a,i0,a,i0)') 'There is no path from vertex ',start,' to vertex ',end\r\n else\r\n lpath = 0\r\n call getPathD(G%V,lpath,start,end,prev,path)\r\n write(*,'(a,i0,a,i0,a)') \"shortest path from vertex \", start, \" to vertex \", end, \":\"\r\n do i=1,lpath\r\n write(*,'(1x,i0)',advance='no') path(i)\r\n enddo\r\n write(*,*)\r\n write(*,'(a,f12.4)') 'with a total path length of ',dist(end)\r\n endif\r\n\r\n deallocate(path,prev,dist)\r\n return\r\nend subroutine\r\n\r\nsubroutine Dijkstra(G, start, dist, prev)\r\n use iso_fortran_env, wp => real64\r\n use graphf\r\n implicit none\r\n type(graph) :: G\r\n integer,intent(in) :: start\r\n real(wp),intent(inout) :: dist(*)\r\n integer,intent(inout) :: prev(*)\r\n real(wp) :: inf\r\n real(wp) :: newdist\r\n integer,allocatable :: Q(:)\r\n integer :: Qcount\r\n integer :: minQ !this is a function\r\n integer :: i,j,u,v\r\n\r\n inf = huge(inf)\r\n !-- allocate array of unvisited vertices,\r\n ! distances and previously visited nodes\r\n allocate(Q(G%V))\r\n Qcount=G%V\r\n do i=1,G%V\r\n Q(i)=i\r\n prev(i) = -1\r\n dist(i) = inf\r\n enddo\r\n prev(start) = start\r\n dist(start) = 0.0_wp\r\n\r\n !-- as long as there are unvisited vertices in Q\r\n do while (Qcount >= 1)\r\n !-- get vertix with smallest reference value in dist\r\n j = minQ(Q,dist,Qcount)\r\n v = Q(j) !track the vertex k\r\n Q(j) = Q(Qcount) !overwrite Q(j)\r\n Qcount = Qcount - 1 !\"resize\" Q\r\n !-- loop over the neighbours of vertex k\r\n do u=1,G%V\r\n if(G%nmat(v,u)==0) cycle\r\n if(prev(u).ne.v)then\r\n newdist = dist(v) + G%emat(v,u)\r\n !-- is the new dist value of u better than the previous one?\r\n if( newdist < dist(u) )then\r\n dist(u) = newdist\r\n prev(u) = v\r\n endif\r\n endif\r\n enddo\r\n enddo\r\n deallocate(Q)\r\n return\r\nend subroutine\r\n\r\nfunction minQ(Q,dist,Qcount)\r\n use iso_fortran_env, only: wp => real64, error_unit\r\n implicit none\r\n integer :: minQ\r\n integer :: Q(*)\r\n real(wp) :: dist(*)\r\n real(wp) :: dref,d\r\n integer :: Qcount\r\n integer :: i,j\r\n\r\n dref = huge(dref)\r\n do i=1,Qcount\r\n j = Q(i)\r\n d = dist(j)\r\n if(d < dref)then\r\n minQ = i !the position within Q has to be returned, not the vertex!\r\n dref = d\r\n endif\r\n enddo\r\n if(dref == huge(d))then\r\n write(error_unit,*) \"warning: disconnected graph!\"\r\n endif\r\n return\r\nend function\r\n\r\nrecursive subroutine getPathD(nmax, lpath, start, pos, prev, path)\r\n implicit none\r\n integer :: nmax\r\n integer :: lpath\r\n integer :: start\r\n integer :: pos\r\n integer :: prev(nmax)\r\n integer :: path(nmax)\r\n integer :: i,j,k\r\n lpath = lpath + 1\r\n if(pos == start)then !exit recursion\r\n path(lpath) = pos\r\n do i=1,lpath/2\r\n j=lpath - i + 1\r\n k=path(i)\r\n path(i) = path(j)\r\n path(j) = k\r\n enddo\r\n else\r\n path(lpath) = pos\r\n j = prev(pos)\r\n call getPathD(nmax, lpath, start, j, prev, path)\r\n endif\r\n return\r\nend subroutine getPathD\r\n", "meta": {"hexsha": "16ba24121b95bdb6b5b7d27f05bc6dc226880544", "size": 3972, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/dijkstra.f90", "max_stars_repo_name": "pprcht/shortestpaths", "max_stars_repo_head_hexsha": "5c832666bdca34517550f2064febaa4e14b7800e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-04-28T21:23:26.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-16T00:00:48.000Z", "max_issues_repo_path": "fortran/dijkstra.f90", "max_issues_repo_name": "pprcht/shortestpaths", "max_issues_repo_head_hexsha": "5c832666bdca34517550f2064febaa4e14b7800e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/dijkstra.f90", "max_forks_repo_name": "pprcht/shortestpaths", "max_forks_repo_head_hexsha": "5c832666bdca34517550f2064febaa4e14b7800e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.9718309859, "max_line_length": 94, "alphanum_fraction": 0.5385196375, "num_tokens": 1132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7739535473160809}} {"text": "module random_utils\n\nuse, intrinsic:: iso_fortran_env, only: wp=>real64\n\nimplicit none\n\nreal(wp),parameter :: pi = 4._wp*atan(1._wp)\n\ncontains\n\nimpure elemental subroutine randn(noise)\n! implements Box-Muller Transform\n! https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform\n!\n! Output:\n! noise: Gaussian noise vector\n\nreal(wp),intent(out) :: noise\nreal(wp) :: u1, u2\n\ncall random_number(u1)\ncall random_number(u2)\n\nnoise = sqrt(-2._wp * log(u1)) * cos(2._wp * pi * u2)\n\nend subroutine randn\n\n\nsubroutine init_random_seed()\n! don't call this function repeatedly in your program.\n! The time resolution of int32 clock isn't so high, and the seed only\n! accepts int32, despite nice clock performance with int64\ninteger :: n,i, clock\ninteger, allocatable :: seed(:)\n\n\ncall random_seed(size=n)\nallocate(seed(n))\ncall system_clock(count=clock)\nseed = clock + 37 * [ (i - 1, i = 1, n) ]\ncall random_seed(put=seed)\n\nend subroutine\n\nend module random_utils", "meta": {"hexsha": "250747ce4d20548aea5945bccf9fb0ca3d35b687", "size": 952, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/random_utils.f90", "max_stars_repo_name": "scienceopen/pyAIRtools", "max_stars_repo_head_hexsha": "655fb228cbe8e226c41d9c75d884ef25c27cc611", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2017-05-06T15:09:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T22:13:34.000Z", "max_issues_repo_path": "fortran/random_utils.f90", "max_issues_repo_name": "scienceopen/pyAIRtools", "max_issues_repo_head_hexsha": "655fb228cbe8e226c41d9c75d884ef25c27cc611", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-10-04T16:52:34.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-04T16:52:34.000Z", "max_forks_repo_path": "fortran/random_utils.f90", "max_forks_repo_name": "scienceopen/pyAIRtools", "max_forks_repo_head_hexsha": "655fb228cbe8e226c41d9c75d884ef25c27cc611", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-06T19:21:09.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-24T13:06:13.000Z", "avg_line_length": 21.1555555556, "max_line_length": 69, "alphanum_fraction": 0.7342436975, "num_tokens": 269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037384317888, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7739115238171277}} {"text": "! Objetivo: Calcular a integral da funcao f(x) = sin(x) no pontos\n! [0, pi] utilizando o metodo de monte carlo\n\nPROGRAM monte_carlo_8\n\n USE nrtype\n USE nrutil\n USE ran_state, ONLY: ran_seed\n USE nr, ONLY: ran1\n\n IMPLICIT none\n INTEGER :: iseed = 1234, pontos, amostras, x_valorexato\n REAL :: aleatorio, func, func_elev2, soma_func = 0., integral_func, N_chamadas\n REAL :: media_sin = 0., media_sin_elev2 = 0., erro, soma_func_elev2 = 0.\n INTEGER, PARAMETER :: dados_monte_carlo_8 = 7, quant_pontos = 1000, quant_amostras = 10\n INTEGER, PARAMETER :: valorexato_monte_carlo = 8\n\n CALL RAN_SEED(SEQUENCE = iseed)\n\n OPEN( dados_monte_carlo_8,file=\"dados_monte_carlo_8.dat\")\n DO pontos = 10, quant_pontos, 10\n DO amostras = 1, quant_amostras\n CALL ran1(aleatorio)\n func = sin(aleatorio*pi)\n func_elev2 = func**2\n soma_func = soma_func + func\n soma_func_elev2 = soma_func_elev2 + func_elev2\n END DO\n\n N_chamadas = real(pontos)\n media_sin = soma_func/N_chamadas\n media_sin_elev2 = soma_func_elev2/N_chamadas\n erro = pi*sqrt(((media_sin_elev2-(media_sin)**2))/N_chamadas)\n integral_func = pi*media_sin\n! O valor exato da integral está sendo escrito manualmente em um arquivo.dat \n! separado do programa\n WRITE(dados_monte_carlo_8, *) N_chamadas, integral_func, erro\n END DO\n CLOSE(dados_monte_carlo_8)\n OPEN(valorexato_monte_carlo, file=\"valorexato_monte_carlo.dat\")\n DO x_valorexato = 0, quant_pontos, 1000\n WRITE(valorexato_monte_carlo, *) x_valorexato, 2\n END DO\n CLOSE(valorexato_monte_carlo)\n\n PRINT *,\"O melhor resultado eh:\", integral_func,\"com erro de +-\", erro\nEND PROGRAM monte_carlo_8\n", "meta": {"hexsha": "83e94ef2cd616ad8de937967905e3dfa53f42bb8", "size": 1729, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Monte_Carlo/Monte_Carlo_8.f90", "max_stars_repo_name": "GuilhermeMonteiroPeixoto/Computational-Physics-using-Fortran", "max_stars_repo_head_hexsha": "3d2b3dd87d99b451aed5fe1e9e99813390396485", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Monte_Carlo/Monte_Carlo_8.f90", "max_issues_repo_name": "GuilhermeMonteiroPeixoto/Computational-Physics-using-Fortran", "max_issues_repo_head_hexsha": "3d2b3dd87d99b451aed5fe1e9e99813390396485", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Monte_Carlo/Monte_Carlo_8.f90", "max_forks_repo_name": "GuilhermeMonteiroPeixoto/Computational-Physics-using-Fortran", "max_forks_repo_head_hexsha": "3d2b3dd87d99b451aed5fe1e9e99813390396485", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.0208333333, "max_line_length": 90, "alphanum_fraction": 0.7009832273, "num_tokens": 567, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308165850443, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7737570267781778}} {"text": "************************************************************************\n* This file contains routines for the transformation and\n* back-transformation of points between a reference triangle\n* and the \"real\" element.\n************************************************************************\n\n************************************************************************\n* Explaination of the transformation:\n*\n* In contrast to quadrilaterals the linear transformation on triangles\n* is rather easy when using barycentric coordinates. Each point\n* (X,Y) in a triangle is identified by a 3-tuple of coordinates\n* (X1,X2,X3) giving the \"relative\" position of the point inside the\n* triangle:\n*\n* P3 (0,1)\n* / \\ Phi | \\\n* / \\ <-- | \\\n* / p \\ | R \\\n* P1------P2 (0,0)---(1,0)\n*\n* here: p = X1*P1 + X2*P2 + X3*P3\n*\n* The barycentric coordinates are \"independent\" of the triangle:\n* When a 3-tuple of barycentric coordinates for a point p is obtained,\n* this holds for both, the \"real\" triangle as well as the reference one.\n* Therefore the corresponting point R of p on the reference triangle\n* can be obtained by setting:\n*\n* R = Phi^{-1}(p) = X1*(0,0) + X2*(1,0) + X3*(0,1)\n*\n* So when the barycentric coordinates are known, the transformation\n* is trivial and can be included in the code directly. The only crucial\n* point is to calculate the barycentric coordinates from a set of\n* corners of a triangle. Routines for this purpose can be found in the\n* following.\n************************************************************************\n\n************************************************************************\n* Triangular back-transformation\n*\n* This subroutine is to find the barycentric coordinates for a given \n* point (x,y) in real coordinates.\n* \n* In:\n* DCOORD - array [1..2,1..3] of double\n* Coordinates of the three corners of the real triangle.\n* DCOORD(1,.) saves the X-, DCOORD(2,.) the Y-coordinates.\n* (DXREAL,DYREAL) - coordinates of a point in the real quadrilateral\n*\n* Out:\n* (X1,X2,X3) - Barycentric coordinates of the point\n* DET - Determinant of the transformation\n*\n* There is no check whether the point is really inside the triangle or\n* not. This can easily be checked as the point is inside\n* the triangle if 0 <= X1,X2,X3 <= 1.\n************************************************************************\n\n SUBROUTINE TBTRAF (DCOORD, X1, X2, X3, DET, DXREAL, DYREAL)\n \n IMPLICIT NONE\n \nC parameters\n \nC coordinates of the evaluation point\n DOUBLE PRECISION DXREAL,DYREAL\n\nC coordinates of the element vertices\n DOUBLE PRECISION DCOORD (2,3)\n \nC barycentric coordinates values of (x,y)\n DOUBLE PRECISION X1, X2, X3, DET\n\nC local variables\n DOUBLE PRECISION DAX, DAY, DBX, DBY, DCX, DCY, DDET\n\n\tDAX = DCOORD(1, 1) \n\tDAY = DCOORD(2, 1)\n\tDBX = DCOORD(1, 2)\n\tDBY = DCOORD(2, 2)\n\tDCX = DCOORD(1, 3)\n\tDCY = DCOORD(2, 3)\n\t\nC Example where to find this formula here:\nC http://home.t-online.de/home/nagel.klaus/matdir/bary.htm \n\t\n\tDET = DAX*(DBY-DCY) + DBX*(DCY-DAY) + DCX*(DAY-DBY)\n\tDDET = 1D0 / DET\n\tX1 = (DXREAL*(DBY-DCY)+DBX*(DCY-DYREAL)+DCX*(DYREAL-DBY)) * DDET \n\tX2 = (DAX*(DYREAL-DCY)+DXREAL*(DCY-DAY)+DCX*(DAY-DYREAL)) * DDET\n\tX3 = (DAX*(DBY-DYREAL)+DBX*(DYREAL-DAY)+DXREAL*(DAY-DBY)) * DDET\n\n END", "meta": {"hexsha": "fb19965234af20f055804b2ebdd759e3e692fa96", "size": 3444, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "area51/cc2d_movbc_structured_2/src/geometry/ttrafo.f", "max_stars_repo_name": "tudo-math-ls3/FeatFlow2", "max_stars_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_stars_repo_licenses": ["Intel", "Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-09T15:48:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-09T15:48:37.000Z", "max_issues_repo_path": "area51/cc2d_movbc_structured_2/src/geometry/ttrafo.f", "max_issues_repo_name": "tudo-math-ls3/FeatFlow2", "max_issues_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_issues_repo_licenses": ["Intel", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "area51/cc2d_movbc_structured_2/src/geometry/ttrafo.f", "max_forks_repo_name": "tudo-math-ls3/FeatFlow2", "max_forks_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_forks_repo_licenses": ["Intel", "Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.6382978723, "max_line_length": 72, "alphanum_fraction": 0.5659117305, "num_tokens": 955, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632329799585, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7737385174557508}} {"text": " SUBROUTINE jacob5(cartd,deriv,jac,elcod,nnode,ielem,istop)\r\n!*********************************************************************\r\n!\r\n!**** this SUBROUTINE evaluates the jacobian matrix and the cartesian\r\n! shape FUNCTION derivatives\r\n!\r\n!*********************************************************************\r\n USE lispa0, ONLY : lures\r\n IMPLICIT NONE\r\n\r\n INTEGER (kind=4), PARAMETER :: ndime = 3\r\n INTEGER (kind=4) nnode,ielem,istop\r\n REAL (kind=8) cartd(nnode,ndime),deriv(nnode,ndime),jac, &\r\n & elcod(ndime,nnode)\r\n\r\n INTEGER (kind=4) inode\r\n REAL (kind=8) jaci(ndime,ndime), jacm(ndime,ndime)\r\n\r\n! create jacobian matrix jacm\r\n\r\n jacm = MATMUL(elcod,deriv)\r\n\r\n! calculate determinant and inverse of jacobian matrix\r\n\r\n jac = jacm(1,1)*jacm(2,2)*jacm(3,3) &\r\n & +jacm(1,3)*jacm(2,1)*jacm(3,2) &\r\n & +jacm(3,1)*jacm(1,2)*jacm(2,3) &\r\n & -jacm(3,1)*jacm(2,2)*jacm(1,3) &\r\n & -jacm(3,3)*jacm(1,2)*jacm(2,1) &\r\n & -jacm(1,1)*jacm(2,3)*jacm(3,2)\r\n IF(jac <= 0) THEN\r\n WRITE(*,600,ERR=9999) ielem\r\n WRITE(*,900,ERR=9999)\r\n WRITE(*,910,ERR=9999) (inode,elcod(1:ndime,inode),inode=1,nnode)\r\n WRITE(lures,600,ERR=9999) ielem\r\n WRITE(lures,900,ERR=9999)\r\n WRITE(lures,910,ERR=9999) (inode,elcod(1:ndime,inode),inode=1,nnode)\r\n iSTOP = 1\r\n RETURN\r\n END IF\r\n\r\n jaci(1,1) = (jacm(2,2)*jacm(3,3)-jacm(2,3)*jacm(3,2))/jac\r\n jaci(2,1) = -(jacm(2,1)*jacm(3,3)-jacm(3,1)*jacm(2,3))/jac\r\n jaci(3,1) = (jacm(2,1)*jacm(3,2)-jacm(2,2)*jacm(3,1))/jac\r\n jaci(1,2) = -(jacm(1,2)*jacm(3,3)-jacm(1,3)*jacm(3,2))/jac\r\n jaci(2,2) = (jacm(1,1)*jacm(3,3)-jacm(3,1)*jacm(1,3))/jac\r\n jaci(3,2) = -(jacm(1,1)*jacm(3,2)-jacm(1,2)*jacm(3,1))/jac\r\n jaci(1,3) = (jacm(1,2)*jacm(2,3)-jacm(1,3)*jacm(2,2))/jac\r\n jaci(2,3) = -(jacm(1,1)*jacm(2,3)-jacm(1,3)*jacm(2,1))/jac\r\n jaci(3,3) = (jacm(1,1)*jacm(2,2)-jacm(2,1)*jacm(1,2))/jac\r\n\r\n! calculate cartesian derivatives\r\n\r\n cartd = MATMUL(deriv,jaci)\r\n\r\n RETURN\r\n 600 FORMAT(//,' PROGRAM halted in SUBROUTINE jacob5',/,11x, &\r\n &' zero or negative volume',/,10x,' element number ',i5)\r\n 900 FORMAT(//,5x,'coordinates of element nodes')\r\n 910 FORMAT(5x,i5,3e15.8)\r\n 9999 CALL runen2('')\r\n END SUBROUTINE jacob5\r\n", "meta": {"hexsha": "857f24c3a644df03a6c755450ee14decb8dbfb32", "size": 2563, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/auxil/jacob5.f90", "max_stars_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_stars_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/auxil/jacob5.f90", "max_issues_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_issues_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/auxil/jacob5.f90", "max_forks_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_forks_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.6825396825, "max_line_length": 77, "alphanum_fraction": 0.4877097152, "num_tokens": 983, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632261523027, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7737385140633379}} {"text": "MODULE alfas_functions\n IMPLICIT NONE\nCONTAINS\n FUNCTION alfa(alfa0,qsq )\n!-----------------------------------------------------------------------------\n!\n!\tThis function returns the 1-loop value of alpha.\n!\n!\tINPUT: \n!\t\tqsq = Q^2\n!\n!-----------------------------------------------------------------------------\n IMPLICIT NONE\n REAL(KIND(1d0))::alfa\n REAL(KIND(1d0)),INTENT(IN)::qsq,alfa0\n REAL(KIND(1d0)),PARAMETER::One=1d0, Three=3d0,&\n Pi=3.14159265358979323846d0,zmass=91.188d0\n alfa = alfa0 / ( 1.0d0 - alfa0*DLOG( qsq/zmass**2 ) /Three /Pi )\n RETURN\n END FUNCTION alfa\n\n FUNCTION alfaw(alfaw0,qsq,nh )\n!-----------------------------------------------------------------------------\n!\n!\tThis function returns the 1-loop value of alpha_w.\n!\n!\tINPUT: \n!\t\tqsq = Q^2\n! nh = # of Higgs doublets\n!\n!-----------------------------------------------------------------------------\n IMPLICIT NONE\n REAL(KIND(1d0))::alfaw\n REAL(KIND(1d0)),INTENT(IN)::alfaw0,qsq\n INTEGER,INTENT(IN)::nh\n REAL(KIND(1d0))::dum\n INTEGER::nq\n REAL(KIND(1d0)),PARAMETER::Two=2d0, Four=4d0, &\n Pi=3.14159265358979323846d0, &\n Twpi=37.69911184307752d0, &\n zmass=91.188d0,tmass=174d0\n IF(qsq.GE.tmass**2)THEN\n nq = 6\n ELSE\n nq = 5\n ENDIF\n dum = (22.0d0-Four*nq-nh/Two)/Twpi\n alfaw = alfaw0 / ( 1.0d0 + dum*alfaw0*DLOG( qsq/zmass**2 ) )\n RETURN\n END FUNCTION alfaw\n\n FUNCTION ALPHAS_MCFM(Q) RESULT(ALPHAS)\n!\n! Evaluation of strong coupling constant alpha_S\n! Author: R.K. Ellis\n!\n! q -- scale at which alpha_s is to be evaluated\n!\n!-- common block alfas.inc\n! alphaQCD2 -- value of alpha_s at the mass of the Z-boson\n! nloop -- the number of loops (1,2, or 3) at which beta \n!\n! function is evaluated to determine running.\n! the values of the cmass and the bmass should be set\n! in common block qmass.\n!-----------------------------------------------------------------------------\n USE ParamModule\n IMPLICIT NONE\n REAL(KIND(1d0))::ALPHAS\n REAL(KIND(1d0)),INTENT(IN)::Q\n REAL(KIND(1d0))::T,AMZ0=0D0,AMB,AMC\n REAL(KIND(1d0))::AS_OUT\n INTEGER::NLOOP0=0\n INTEGER,PARAMETER::NF3=3,NF4=4,NF5=5\n REAL(KIND(1d0))::CMASS=1.42D0,BMASS=4.7D0 ! HEAVY QUARK MASSES FOR THRESHOLDS\n REAL(KIND(1d0))::ZMASS=91.188D0\n SAVE AMZ0,NLOOP0,AMB,AMC\n IF(Q.LE.0D0)THEN \n WRITE(*,*) 'q .le. 0 in alphas'\n WRITE(*,*) 'q= ',Q\n STOP\n ENDIF\n IF(alphaQCD2.LE.0D0)THEN \n WRITE(*,*) 'alphaQCD2.LE.0 in alphas',alphaQCD2\n STOP\n ENDIF\n IF(CMASS.LE.0.3D0)THEN \n WRITE(*,*) 'cmass .le. 0.3GeV in alphas',CMASS\n STOP\n CMASS=1.42D0\n ENDIF\n IF(BMASS.LE.0D0)THEN \n WRITE(*,*) 'bmass .le. 0 in alphas',BMASS\n STOP\n ENDIF\n!--- establish value of coupling at b- and c-mass and save\n IF((alphaQCD2.NE.AMZ0).OR.(NLOOP.NE.NLOOP0))THEN\n AMZ0=alphaQCD2\n NLOOP0=NLOOP\n T=2D0*DLOG(BMASS/ZMASS)\n CALL NEWTON1(T,alphaQCD2,AMB,NLOOP,NF5)\n T=2D0*DLOG(CMASS/BMASS)\n CALL NEWTON1(T,AMB,AMC,NLOOP,NF4)\n ENDIF\n\n!--- evaluate strong coupling at scale q\n IF(Q.LT.BMASS)THEN\n IF (Q.LT.CMASS)THEN\n T=2D0*DLOG(Q/CMASS)\n CALL NEWTON1(T,AMC,AS_OUT,NLOOP,NF3)\n ELSE\n T=2D0*DLOG(Q/BMASS)\n CALL NEWTON1(T,AMB,AS_OUT,NLOOP,NF4)\n ENDIF\n ELSE\n T=2D0*DLOG(Q/ZMASS)\n CALL NEWTON1(T,alphaQCD2,AS_OUT,NLOOP,NF5)\n ENDIF\n ALPHAS=AS_OUT\n RETURN\n END FUNCTION ALPHAS_MCFM\n\n\n SUBROUTINE NEWTON1(T,A_IN,A_OUT,NLOOP,NF)\n! Author: R.K. Ellis\n\n!--- calculate a_out using nloop beta-function evolution \n!--- with nf flavours, given starting value as-in\n!--- given as_in and logarithmic separation between \n!--- input scale and output scale t.\n!--- Evolution is performed using Newton's method,\n!--- with a precision given by tol.\n \n IMPLICIT NONE\n INTEGER,INTENT(IN)::NLOOP,NF\n REAL(KIND(1d0)),INTENT(IN)::T,A_IN\n REAL(KIND(1d0)),INTENT(OUT)::A_OUT\n REAL(KIND(1d0))::AS,F,FP,DELTA\n REAL(KIND(1d0)),DIMENSION(3:5)::B0,C1,C2,DEL\n REAL(KIND(1d0)),PARAMETER::TOL=5.D-4\n! --- B0=(11.-2.*NF/3.)/4./PI\n B0(3:5)=(/0.716197243913527D0,0.66314559621623D0,0.61009394851893D0/)\n!--- C1=(102.D0-38.D0/3.D0*NF)/4.D0/PI/(11.D0-2.D0/3.D0*NF)\n C1(3:5)=(/.565884242104515D0,0.49019722472304D0,0.40134724779695D0/)\n!--- C2=(2857.D0/2.D0-5033*NF/18.D0+325*NF**2/54)\n!--- /16.D0/PI**2/(11.D0-2.D0/3.D0*NF)\n C2(3:5)=(/0.453013579178645D0,0.30879037953664D0,0.14942733137107D0/)\n!--- DEL=SQRT(4*C2-C1**2)\n DEL(3:5)=(/1.22140465909230D0,0.99743079911360D0,0.66077962451190D0/)\n! F2(AS)=1D0/AS+C1(NF)*DLOG((C1(NF)*AS)/(1D0+C1(NF)*AS))\n! F3(AS)=1D0/AS+0.5D0*C1(NF)&\n! *DLOG((C2(NF)*AS**2)/(1D0+C1(NF)*AS+C2(NF)*AS**2))&\n! -(C1(NF)**2-2D0*C2(NF))/DEL(NF)&\n! *DATAN((2D0*C2(NF)*AS+C1(NF))/DEL(NF))\n\n \n A_OUT=A_IN/(1D0+A_IN*B0(NF)*T)\n IF(NLOOP.EQ.1)RETURN\n A_OUT=A_IN/(1D0+B0(NF)*A_IN*T+C1(NF)*A_IN*DLOG(1D0+A_IN*B0(NF)*T))\n IF (A_OUT.LT.0D0)AS=0.3D0\n DO\n AS=A_OUT ! 30\n\n IF(NLOOP.EQ.2)THEN\n F=B0(NF)*T+F2(A_IN)-F2(AS)\n FP=1D0/(AS**2*(1D0+C1(NF)*AS))\n ENDIF\n IF(NLOOP.EQ.3)THEN\n F=B0(NF)*T+F3(A_IN)-F3(AS)\n FP=1D0/(AS**2*(1D0+C1(NF)*AS+C2(NF)*AS**2))\n ENDIF\n A_OUT=AS-F/FP\n DELTA=ABS(F/FP/AS)\n IF(DELTA.LE.TOL)EXIT ! GO TO 30\n ENDDO\n RETURN\n\n CONTAINS\n\n FUNCTION F2(AS)\n IMPLICIT NONE\n REAL(KIND(1d0)),INTENT(IN)::AS\n REAL(KIND(1d0))::F2\n F2=1D0/AS+C1(NF)*DLOG((C1(NF)*AS)/(1D0+C1(NF)*AS))\n END FUNCTION F2\n\n FUNCTION F3(AS)\n IMPLICIT NONE\n REAL(KIND(1d0)),INTENT(IN)::AS\n REAL(KIND(1d0))::F3\n F3=1D0/AS+0.5D0*C1(NF)&\n *DLOG((C2(NF)*AS**2)/(1D0+C1(NF)*AS+C2(NF)*AS**2))&\n -(C1(NF)**2-2D0*C2(NF))/DEL(NF)&\n *DATAN((2D0*C2(NF)*AS+C1(NF))/DEL(NF))\n END FUNCTION F3\n END SUBROUTINE NEWTON1\n\n\n FUNCTION mfrun(mf,scale,asmz,nloop)\n!-----------------------------------------------------------------------------\n!\n!\tThis function returns the 2-loop value of a MSbar fermion mass\n! at a given scale.\n!\n!\tINPUT: mf = MSbar mass of fermion at MSbar fermion mass scale \n!\t scale = scale at which the running mass is evaluated\n!\t asmz = AS(MZ) : this is passed to alphas(scale,asmz,nloop)\n! nloop = # of loops in the evolution\n! \n!\n!\n! \n!-----------------------------------------------------------------------------\n IMPLICIT NONE\n REAL(KIND(1d0))::mfrun\n REAL(KIND(1d0)),INTENT(IN)::mf,scale,asmz\n INTEGER,INTENT(IN)::nloop\n REAL(KIND(1d0))::beta0, beta1,gamma0,gamma1\n REAL(KIND(1d0))::A1,as,asmf,l2\n INTEGER::nf\n REAL(KIND(1d0)),PARAMETER::One=1d0,Two=2d0,Three=3d0,&\n Pi=3.14159265358979323846d0,tmass=174d0\n IF(mf.GT.tmass)THEN\n nf = 6\n ELSE\n nf = 5\n ENDIF\n\n beta0 = ( 11.0d0 - Two/Three *nf )/4d0\n beta1 = ( 102d0 - 38d0/Three*nf )/16d0\n gamma0= 1d0\n gamma1= ( 202d0/3d0 - 20d0/9d0*nf )/16d0\n A1 = -beta1*gamma0/beta0**2+gamma1/beta0\n as = alphas_MCFM(scale)\n asmf = alphas_MCFM(mf)\n l2 = (1+ A1*as/Pi)/(1+ A1*asmf/Pi)\n \n \n mfrun = mf * (as/asmf)**(gamma0/beta0)\n\n IF(nloop.EQ.2) mfrun =mfrun*l2\n RETURN\n END FUNCTION mfrun\nEND MODULE alfas_functions\n\n", "meta": {"hexsha": "c46ce336184bd116470d78bdc69c06a9b79c85a5", "size": 7494, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "vendor/SMWidth/alfas_functions.f90", "max_stars_repo_name": "khurtado/MG5_aMC", "max_stars_repo_head_hexsha": "9cde676b0a1097058c416983017af257385fa375", "max_stars_repo_licenses": ["NCSA"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-10-23T14:37:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T20:59:02.000Z", "max_issues_repo_path": "vendor/SMWidth/alfas_functions.f90", "max_issues_repo_name": "khurtado/MG5_aMC", "max_issues_repo_head_hexsha": "9cde676b0a1097058c416983017af257385fa375", "max_issues_repo_licenses": ["NCSA"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2018-10-08T15:49:32.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-15T13:33:36.000Z", "max_forks_repo_path": "vendor/SMWidth/alfas_functions.f90", "max_forks_repo_name": "khurtado/MG5_aMC", "max_forks_repo_head_hexsha": "9cde676b0a1097058c416983017af257385fa375", "max_forks_repo_licenses": ["NCSA"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-02-18T11:42:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T20:46:08.000Z", "avg_line_length": 30.4634146341, "max_line_length": 81, "alphanum_fraction": 0.5493728316, "num_tokens": 2933, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632234212403, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7737385096857812}} {"text": " FUNCTION plgndr(l,m,x)\r\n INTEGER l,m\r\n REAL plgndr,x\r\n INTEGER i,ll\r\n REAL fact,pll,pmm,pmmp1,somx2\r\n if(m.lt.0.or.m.gt.l.or.abs(x).gt.1.)pause\r\n *'bad arguments in plgndr'\r\n pmm=1.\r\n if(m.gt.0) then\r\n somx2=sqrt((1.-x)*(1.+x))\r\n fact=1.\r\n do 11 i=1,m\r\n pmm=-pmm*fact*somx2\r\n fact=fact+2.\r\n11 continue\r\n endif\r\n if(l.eq.m) then\r\n plgndr=pmm\r\n else\r\n pmmp1=x*(2*m+1)*pmm\r\n if(l.eq.m+1) then\r\n plgndr=pmmp1\r\n else\r\n do 12 ll=m+2,l\r\n pll=(x*(2*ll-1)*pmmp1-(ll+m-1)*pmm)/(ll-m)\r\n pmm=pmmp1\r\n pmmp1=pll\r\n12 continue\r\n plgndr=pll\r\n endif\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "8a313130521e8df2df1b4964a306d048ee20e2a0", "size": 777, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/plgndr.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/plgndr.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/plgndr.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.8529411765, "max_line_length": 55, "alphanum_fraction": 0.4401544402, "num_tokens": 277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474246069458, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7737215963052061}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran77 Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n! ... Contains a test program illustrating the\n! use of subroutine sshifte (see documentation for sshifte)\n!\n! The \"offset\" scalar field goff is set equal to exp(x+y+z) where\n! x, y, z are the cartesian coordinates restricted to the surface\n! of the unit sphere. This is transferred to the \"regular\" grid\n! in greg. greg is then compared with exp(x+y+z) on the regular grid.\n! Finally greg is transferred back to goff which is again compared\n! with exp(x+y+z). The least squares error after each transformation\n! with sshifte is computed and printed. Output from running the\n! program below on a 2.5 degree equally spaced regular and offset\n! grid is listed below.\n!\n! *** OUTPUT (from execution on 32 bit machine)\n!\n! sshifte arguments\n! ioff = 0 nlon = 144 nlat = 72\n! lsave = 608 lwork = 21024\n! ier = 0\n! least squares error = 0.500E-06\n! sshifte arguments\n! ioff = 1 nlon = 144 nlat = 72\n! lsave = 608 lwork = 21024\n! ier = 0\n! least squares error = 0.666E-06\n!\n! *** END OF OUTPUT\n!\nprogram testsshifte\n\n use, intrinsic :: ISO_Fortran_env, only: &\n stdout => OUTPUT_UNIT\n\n use spherepack\n\n ! Explicit typing only\n implicit none\n\n integer(ip), parameter :: nlon = 144, nlat = 72\n integer(ip), parameter :: nlatp1 = nlat + 1\n integer(ip) :: ioff, i, j, error_flag\n real(wp) :: dlat, dlon, half_dlat, half_dlon, lat, long\n real(wp) :: x, y, z, gexact, err2\n real(wp) :: goff(nlon, nlat), greg(nlon, nlatp1)\n real(wp), allocatable :: wavetable(:)\n real(wp), parameter :: ZERO = 0.0_wp\n\n ! Set grid increments\n dlat = PI/nlat\n dlon = TWO_PI/nlon\n half_dlat = dlat/2\n half_dlon = dlon/2\n\n ! Set offset grid values in goff\n do j=1, nlon\n long = half_dlon + real(j - 1, kind=wp) * dlon\n do i=1, nlat\n lat = -HALF_PI + half_dlat + real(i - 1, kind=wp) * dlat\n x = cos(lat) * cos(long)\n y = cos(lat) * sin(long)\n z = sin(lat)\n goff(j, i) = exp(x + y + z)\n end do\n end do\n\n ! Initialize wavetable for offset to regular shift\n ioff = 0\n call initialize_sshifte(ioff, nlon, nlat, wavetable, error_flag)\n\n ! Write input arguments to sshifte\n write (stdout, 100) ioff, nlon, nlat\n100 format(' sshifte arguments', &\n /' ioff = ', i2, ' nlon = ', i3, ' nlat = ', i3)\n\n ! Shift offset to regular grid\n call sshifte(ioff, nlon, nlat, goff, greg, wavetable, error_flag)\n\n write (stdout, 200) error_flag\n200 format(' ier = ', i2)\n\n if (error_flag == 0) then\n !\n ! compute error in greg\n !\n err2 = ZERO\n do j=1, nlon\n long = real(j - 1, kind=wp) * dlon\n do i=1, nlat + 1\n lat = -HALF_PI + real(i - 1, kind=wp) * dlat\n x = cos(lat)*cos(long)\n y = cos(lat)*sin(long)\n z = sin(lat)\n gexact = exp(x + y + z)\n err2 = err2 + (greg(j, i)-gexact)**2\n end do\n end do\n err2 = sqrt(err2/(nlon*(nlat + 1)))\n write (stdout, 300) err2\n300 format(' least squares error = ', e10.3)\n end if\n\n ! Initialize wsav for regular to offset shift\n ioff = 1\n call initialize_sshifte(ioff, nlon, nlat, wavetable, error_flag)\n\n ! Now transfer regular grid values in greg back to offset grid in goff\n goff = ZERO\n\n write (stdout, 100) ioff, nlon, nlat\n\n call sshifte(ioff, nlon, nlat, goff, greg, wavetable, error_flag)\n\n write (stdout, 200) error_flag\n\n if (error_flag == 0) then\n\n ! Compute error in goff by comparing with exp(x+y+z) on offset grid\n err2 = ZERO\n do j=1, nlon\n long = half_dlon + real(j - 1, kind=wp) * dlon\n do i=1, nlat\n lat = -HALF_PI + half_dlat + real(i - 1, kind=wp) * dlat\n x = cos(lat) * cos(long)\n y = cos(lat) * sin(long)\n z = sin(lat)\n gexact = exp(x + y + z)\n err2 = err2 + (goff(j, i) - gexact)**2\n end do\n end do\n err2 = sqrt(err2/(nlon*(nlat + 1)))\n write (stdout, 300) err2\n end if\n\n ! Release memory\n deallocate (wavetable)\n\nend program testsshifte\n", "meta": {"hexsha": "de04ace45652f8965c5c673ff15788f07e6d66e9", "size": 6455, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/testsshifte.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "test/testsshifte.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "test/testsshifte.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 38.1952662722, "max_line_length": 75, "alphanum_fraction": 0.4235476375, "num_tokens": 1659, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769414, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7737164456625022}} {"text": "FUNCTION ei_sp(x)\n\n USE mo_kind, ONLY : i4, sp\n USE mo_nrutil, ONLY : assert,nrerror\n USE mo_constants, ONLY : EULER\n\n IMPLICIT NONE\n\n REAL(SP), INTENT(IN) :: x\n REAL(SP) :: ei_sp\n INTEGER(i4), PARAMETER :: MAXIT=100_i4\n REAL(SP), PARAMETER :: EPS=epsilon(x),FPMIN=tiny(x)/EPS\n INTEGER(i4) :: k\n REAL(SP) :: fact,prev,sm,term\n\n call assert(x > 0.0_sp, 'ei_sp arg')\n\n if (x < FPMIN) then\n ei_sp=log(x)+EULER\n\n else if (x <= -log(EPS)) then\n sm=0.0_sp\n fact=1.0_sp\n\n do k=1_i4,MAXIT\n fact=fact*x/k\n term=fact/k\n sm=sm+term\n if (term < EPS*sm) exit\n end do\n\n if (k > MAXIT) call nrerror('series failed in ei_sp')\n ei_sp=sm+log(x)+EULER\n\n else\n sm=0.0_sp\n term=1.0_sp\n\n do k=1_i4,MAXIT\n prev=term\n term=term*k/x\n if (term < EPS) exit\n if (term < prev) then\n sm=sm+term\n else\n sm=sm-prev\n exit\n end if\n end do\n\n if (k > MAXIT) call nrerror('asymptotic failed in ei_sp')\n ei_sp=exp(x)*(1.0_sp+sm)/x\n\n end if\n\nEND FUNCTION ei_sp\n\nFUNCTION ei_dp(x)\n\n USE mo_kind, ONLY : i4, dp\n USE mo_nrutil, ONLY : assert,nrerror\n USE mo_constants, ONLY : EULER\n\n IMPLICIT NONE\n\n REAL(dp), INTENT(IN) :: x\n REAL(dp) :: ei_dp\n INTEGER(i4), PARAMETER :: MAXIT=100_i4\n REAL(dp), PARAMETER :: EPS=epsilon(x),FPMIN=tiny(x)/EPS\n INTEGER(i4) :: k\n REAL(dp) :: fact,prev,sm,term\n\n call assert(x > 0.0_dp, 'ei_dp arg')\n\n if (x < FPMIN) then\n ei_dp=log(x)+EULER\n\n else if (x <= -log(EPS)) then\n sm=0.0_dp\n fact=1.0_dp\n\n do k=1_i4,MAXIT\n fact=fact*x/k\n term=fact/k\n sm=sm+term\n if (term < EPS*sm) exit\n end do\n\n if (k > MAXIT) call nrerror('series failed in ei_dp')\n ei_dp=sm+log(x)+EULER\n\n else\n sm=0.0_dp\n term=1.0_dp\n\n do k=1_i4,MAXIT\n prev=term\n term=term*k/x\n if (term < EPS) exit\n if (term < prev) then\n sm=sm+term\n else\n sm=sm-prev\n exit\n end if\n end do\n\n if (k > MAXIT) call nrerror('asymptotic failed in ei_dp')\n ei_dp=exp(x)*(1.0_dp+sm)/x\n\n end if\n\nEND FUNCTION ei_dp\n", "meta": {"hexsha": "649aafc8e40a3e83c30875f8187b717d75ea930e", "size": 2579, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "nr_jams/ei.f90", "max_stars_repo_name": "mcuntz/jams_fortran", "max_stars_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2020-02-28T00:14:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-20T23:32:41.000Z", "max_issues_repo_path": "nr_jams/ei.f90", "max_issues_repo_name": "mcuntz/jams_fortran", "max_issues_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-09T15:33:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T16:16:09.000Z", "max_forks_repo_path": "nr_jams/ei.f90", "max_forks_repo_name": "mcuntz/jams_fortran", "max_forks_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-09T08:08:56.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-09T08:08:56.000Z", "avg_line_length": 22.6228070175, "max_line_length": 65, "alphanum_fraction": 0.4715005816, "num_tokens": 808, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.7737164421568594}} {"text": "program degtest\n implicit none\n intrinsic asin, acos, atan\n\n write(*,*) 'arcsin(0.5) : ', deg(ASIN, 0.5)\n write(*,*) 'arccos(0.5) : ', deg(ACOS, 0.5)\n write(*,*) 'arctan(1.0) : ', deg(ATAN, 1.0)\n\nCONTAINS\n REAL function deg(f,x)\n implicit none\n \n intrinsic atan\n REAL, EXTERNAL :: f\n REAL, INTENT(IN) :: x\n\n deg = 45*f(x) / ATAN(1.0)\n end function deg \nend program degtest\n", "meta": {"hexsha": "b90707d3899cfae0ea31df89e07ec0b497dcc6e1", "size": 398, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/modules/procedure_arguments.f90", "max_stars_repo_name": "annefou/Fortran", "max_stars_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2016-04-08T19:04:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-13T15:44:37.000Z", "max_issues_repo_path": "src/modules/procedure_arguments.f90", "max_issues_repo_name": "inandi2/Fortran-1", "max_issues_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/modules/procedure_arguments.f90", "max_forks_repo_name": "inandi2/Fortran-1", "max_forks_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2016-04-08T19:05:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-08T19:57:51.000Z", "avg_line_length": 19.9, "max_line_length": 45, "alphanum_fraction": 0.5854271357, "num_tokens": 156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.8577681031721324, "lm_q1q2_score": 0.7736387811344505}} {"text": "module euler_primes_m\n use iso_fortran_env, only: int64\n use euler_utils_m, only: sp, dp\n implicit none\n private\n\n public :: is_prime, sieve_of_Eratosthenes\n\n !> A generic interface that tells if an integer is prime\n interface is_prime\n module procedure is_prime_int32, is_prime_int64\n end interface is_prime\n\n !> An algorithm for finding all prime numbers within a limit\n interface sieve_of_Eratosthenes\n module procedure sieve_of_Eratosthenes_int32\n module procedure sieve_of_Eratosthenes_int64\n end interface sieve_of_Eratosthenes\n\ncontains\n\n logical function is_prime_int32(n)\n integer, intent(in) :: n\n integer :: limit, i\n\n is_prime_int32 = .false.\n limit = int(sqrt(real(n, sp)) + 1)\n if (n <= 1) then\n is_prime_int32 = .false.\n else if (n <= 3) then\n is_prime_int32 = .true.\n else if (mod(n, 2) == 0) then\n is_prime_int32 = .false.\n else\n loop_1: do i = 3, limit, 2\n if (mod(n, i) == 0) then\n is_prime_int32 = .false.\n exit loop_1\n else\n is_prime_int32 = .true.\n end if\n end do loop_1\n end if\n end function is_prime_int32\n\n logical function is_prime_int64(n)\n integer(int64), intent(in) :: n\n integer(int64) :: limit, i\n\n is_prime_int64 = .false.\n limit = int(sqrt(real(n, sp)) + 1_int64)\n if (n <= 1_int64) then\n is_prime_int64 = .false.\n else if (n <= 3_int64) then\n is_prime_int64 = .true.\n else if (mod(n, 2_int64) == 0_int64) then\n is_prime_int64 = .false.\n else\n loop_1: do i = 3_int64, limit, 2_int64\n if (mod(n, i) == 0_int64) then\n is_prime_int64 = .false.\n exit loop_1\n else\n is_prime_int64 = .true.\n end if\n end do loop_1\n end if\n end function is_prime_int64\n\n subroutine sieve_of_Eratosthenes_int32(n, prime_arr)\n integer, intent(in) :: n\n logical, allocatable, dimension(:) :: prime_arr\n integer :: i, j\n\n allocate (prime_arr(0:n))\n prime_arr = .true.\n prime_arr(0:1) = .false.\n do i = 2, floor(sqrt(real(n, dp)))\n if (prime_arr(i)) then\n j = i*i\n do while (j <= n)\n prime_arr(j) = .false.\n j = j + i\n end do\n end if\n end do\n end subroutine sieve_of_Eratosthenes_int32\n\n subroutine sieve_of_Eratosthenes_int64(n, prime_arr)\n integer(int64), intent(in) :: n\n logical, allocatable, dimension(:) :: prime_arr\n integer(int64) :: i, j\n\n allocate (prime_arr(0:n))\n prime_arr = .true.\n prime_arr(0:1) = .false.\n do i = 2_int64, floor(sqrt(real(n, dp)), int64)\n if (prime_arr(i)) then\n j = i*i\n do while (j <= n)\n prime_arr(j) = .false.\n j = j + i\n end do\n end if\n end do\n end subroutine sieve_of_Eratosthenes_int64\n\nend module euler_primes_m\n", "meta": {"hexsha": "0a30718dfccda0d73d1c95c146871d4df6955506", "size": 3296, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/euler_primes_m.f90", "max_stars_repo_name": "han190/PE-Fortran", "max_stars_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T07:07:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T07:45:48.000Z", "max_issues_repo_path": "docs/src/euler_primes_m.f90", "max_issues_repo_name": "han190/PE-Fortran", "max_issues_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-14T00:48:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T00:48:58.000Z", "max_forks_repo_path": "docs/src/euler_primes_m.f90", "max_forks_repo_name": "han190/PE-Fortran", "max_forks_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T21:29:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T21:29:45.000Z", "avg_line_length": 30.2385321101, "max_line_length": 64, "alphanum_fraction": 0.5297330097, "num_tokens": 883, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898305367525, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7736362669716759}} {"text": "PROGRAM mbernob\n \n! Code converted using TO_F90 by Alan Miller\n! Date: 2004-06-28 Time: 12:58:09\n\n! ===========================================================\n! Purpose: This program computes Bernoulli number Bn using\n! subroutine BERNOB\n! Example: Compute Bernouli number Bn for n = 0,1,...,10\n! Computed results:\n\n! n Bn\n! --------------------------\n! 0 .100000000000D+01\n! 1 -.500000000000D+00\n! 2 .166666666667D+00\n! 4 -.333333333333D-01\n! 6 .238095238095D-01\n! 8 -.333333333333D-01\n! 10 .757575757576D-01\n! ===========================================================\n\nDOUBLE PRECISION :: b\nDIMENSION b(0:200)\nWRITE(*,*)' Please enter Nmax'\n! READ(*,*)N\nn=10\nCALL bernob(n,b)\nWRITE(*,*)' n Bn'\nWRITE(*,*)' --------------------------'\nWRITE(*,20)0,b(0)\nWRITE(*,20)1,b(1)\nDO k=2,n,2\n WRITE(*,20)k,b(k)\nEND DO\n20 FORMAT(2X,i3,d22.12)\nEND PROGRAM mbernob\n\n\nSUBROUTINE bernob(n,bn)\n\n! ======================================\n! Purpose: Compute Bernoulli number Bn\n! Input : n --- Serial number\n! Output: BN(n) --- Bn\n! ======================================\n\n\nINTEGER, INTENT(IN) :: n\nDOUBLE PRECISION, INTENT(OUT) :: bn(0:n)\nIMPLICIT DOUBLE PRECISION (a-h,o-z)\n\n\ntpi=6.283185307179586D0\nbn(0)=1.0D0\nbn(1)=-0.5D0\nbn(2)=1.0D0/6.0D0\nr1=(2.0D0/tpi)**2\nDO m=4,n,2\n r1=-r1*(m-1)*m/(tpi*tpi)\n r2=1.0D0\n DO k=2,10000\n s=(1.0D0/k)**m\n r2=r2+s\n IF (s < 1.0D-15) EXIT\n END DO\n bn(m)=r1*r2\nEND DO\nRETURN\nEND SUBROUTINE bernob\n", "meta": {"hexsha": "0f0d20b1fefa3b4135466a124a5d1c82ad5b610c", "size": 1772, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MATLAB/f2matlab/comp_spec_func/mbernob.f90", "max_stars_repo_name": "vasaantk/bin", "max_stars_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATLAB/f2matlab/comp_spec_func/mbernob.f90", "max_issues_repo_name": "vasaantk/bin", "max_issues_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATLAB/f2matlab/comp_spec_func/mbernob.f90", "max_forks_repo_name": "vasaantk/bin", "max_forks_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.9577464789, "max_line_length": 67, "alphanum_fraction": 0.433972912, "num_tokens": 587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.8688267881258485, "lm_q1q2_score": 0.7735114780265615}} {"text": "! SUBROUTINE: mat2quater\r\n! ----------------------------------------------------------------------\r\n! PURPOSE:\r\n! This subroutine is an example of a possible algorithm to avoid\r\n! numerical instabilities when computing a quaternion of rotation\r\n! from the elements of the corresponding matrix of rotation.\r\n! The matrix given in entry have to be a rotation matrix (i.e.\r\n! having a determinant equal to 1). This is not checked here!\r\n!\r\n! INPUT : xmat (3,3) : matrix of rotation\r\n! OUTPUT : quater(4) : corresponding quaternion of rotation\r\n! (with a positive scalar part)\r\n! quater=(q0,q1,q2,q3) q0: scalar part\r\n! q1,q2,q3: vectorial part\r\n!\r\n! example:\r\n!\r\n! | 0.0000000000000000 -0.5000000000000001 -0.8660254037844386 |\r\n! xmat= | 0.9238795325112867 -0.3314135740355917 0.1913417161825449 |\r\n! | -0.3826834323650897 -0.8001031451912655 0.4619397662556435 |\r\n! gives:\r\n!\r\n! quater = ( 0.5316310262343734 ! q0\r\n! -0.4662278970042302 ! q1\r\n! -0.2272920256568435 ! q2\r\n! 0.6695807158758448 ) ! q3\r\n!\r\n! ----------------------------------------------------------------------\r\n\r\nsubroutine mat2quater(xmat,quater)\r\nimplicit none\r\ndouble precision , dimension(3,3) :: xmat\r\ndouble precision , dimension(4) :: quater , qsquare\r\ndouble precision :: xtr, xs , max , denominator\r\ninteger :: imax , i\r\n!\r\n! computation of the squares of the quadriplet:\r\nxtr = xmat(1,1)+xmat(2,2)+xmat(3,3)\r\nqsquare(1) = (xtr + 1.d0)/4.d0\r\nxs = 0.5d0 - qsquare(1)\r\nqsquare(2) = xs + xmat(1,1)/2.d0\r\nqsquare(3) = xs + xmat(2,2)/2.d0\r\nqsquare(4) = xs + xmat(3,3)/2.d0\r\n!\r\n! we cannot take as it is the square root of these squares since this\r\n! gives numerical errors for nearly vanishing values.\r\n!\r\n! selection of the max of the values (to be used like pivot):\r\n!\r\nmax = -1.d0\r\ndo i=1,4\r\nif (qsquare(i) > max ) then\r\nmax = qsquare(i)\r\nimax = i\r\nend if\r\nend do\r\nquater(imax) = sqrt(qsquare(imax))\r\ndenominator=4.d0*quater(imax)\r\n!\r\n! quaternion values now computed using extra diagonal terms\r\n! of the matrix\r\n!\r\nif (imax == 1) then\r\nquater(2)=(xmat(3,2)-xmat(2,3) )/denominator\r\nquater(3)=(xmat(1,3)-xmat(3,1) )/denominator\r\nquater(4)=(xmat(2,1)-xmat(1,2) )/denominator\r\nelse if (imax == 2) then\r\nquater(1)= (xmat(3,2)-xmat(2,3))/denominator\r\nquater(3)= (xmat(1,2)+xmat(2,1))/denominator\r\nquater(4)= (xmat(1,3)+xmat(3,1))/denominator\r\nelse if (imax == 3) then\r\nquater(1)= (xmat(1,3)-xmat(3,1))/denominator\r\nquater(2)= (xmat(1,2)+xmat(2,1))/denominator\r\nquater(4)= (xmat(2,3)+xmat(3,2))/denominator\r\nelse if (imax == 4) then\r\nquater(1)= (xmat(2,1)-xmat(1,2))/denominator\r\nquater(2)= (xmat(1,3)+xmat(3,1))/denominator\r\nquater(3)= (xmat(2,3)+xmat(3,2))/denominator\r\nend if\r\n!\r\n! as quater and -quater are equivalent this subroutine always return\r\n! the one of the two having a positive scalar part.\r\n! warning: this procedure does not imply that two successive call\r\n! will give two quaternions that can be interpolated.\r\n!\r\nif (quater(1)<0.d0) quater(1:4)=-quater(1:4)\r\n!\r\nreturn\r\nend\r\n", "meta": {"hexsha": "55df572db417d314f5356740799818860a7fd9f7", "size": 2960, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/mat2quater.f95", "max_stars_repo_name": "HiTMonitor/ginan", "max_stars_repo_head_hexsha": "f348e2683507cfeca65bb58880b3abc2f9c36bcf", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-31T15:16:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:16:19.000Z", "max_issues_repo_path": "src/fortran/mat2quater.f95", "max_issues_repo_name": "hqy123-cmyk/ginan", "max_issues_repo_head_hexsha": "b69593b584f75e03238c1c667796e2030391fbed", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/fortran/mat2quater.f95", "max_forks_repo_name": "hqy123-cmyk/ginan", "max_forks_repo_head_hexsha": "b69593b584f75e03238c1c667796e2030391fbed", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.8888888889, "max_line_length": 73, "alphanum_fraction": 0.6510135135, "num_tokens": 1039, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897459384733, "lm_q2_score": 0.8221891392358015, "lm_q1q2_score": 0.7735071114150217}} {"text": "subroutine grid_updator\n use systemparams\n implicit none\n real :: xhalf,xhalf1,Tplus1,T1,Tminus1,dx,Dplus,Dminus,dx1\n T_old(:) = T(:)\n do i=1,nx+1\n if(i==1) then\n Tminus1 = T_old(i)\n end if\n if(i/=1) then \n Tminus1 = T_old(i-1)\n end if\n if(i==nx+1) then\n Tplus1 = T_old(i)\n end if\n if(i/=nx+1) then\n Tplus1 = T_old(i+1)\n end if\n T1 = T_old(i)\n if(i==1) then\n Dminus = diff*(1.0-x(i)*x(i))\n end if\n if(i/=1) then\n Dminus = 0.5*diff*((1.0-x(i-1)*x(i-1)) + (1.0-x(i)*x(i)))\n end if\n if(i==nx+1) then\n Dplus = diff*(1.0-x(i)*x(i))\n end if\n if(i/=nx+1) then\n Dplus = 0.5*diff*((1.0-x(i+1)*x(i+1)) + (1.0-x(i)*x(i)))\n end if\n if(i==1) then\n dx1 = deltax(i)\n dx = 0.5*(deltax(i+1)+deltax(i))\n else if(i==nx+1) then \n dx1 = 0.5*(deltax(i-1)+deltax(i))\n dx = deltax(i)\n else \n dx = 0.5*(deltax(i) + deltax(i+1))\n dx1 = 0.5*(deltax(i-1)+ deltax(i))\n end if\n T(i) = T1 + (dt/C_tot(i))*(Q(i) + (Dplus*(Tplus1-T1)/dx - Dminus*(T1-Tminus1)/dx1)/(0.5*(dx1+dx)) )\n end do\nend subroutine grid_updator\n", "meta": {"hexsha": "1f32c2bf2397838e84ade31cd7e909fb63e095dd", "size": 1320, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/grid_updator.f90", "max_stars_repo_name": "mjdbahram/exoClimate", "max_stars_repo_head_hexsha": "48ae1ea333d8ca117dd736da575fd1f2a55012f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/grid_updator.f90", "max_issues_repo_name": "mjdbahram/exoClimate", "max_issues_repo_head_hexsha": "48ae1ea333d8ca117dd736da575fd1f2a55012f4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/grid_updator.f90", "max_forks_repo_name": "mjdbahram/exoClimate", "max_forks_repo_head_hexsha": "48ae1ea333d8ca117dd736da575fd1f2a55012f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.3333333333, "max_line_length": 107, "alphanum_fraction": 0.4348484848, "num_tokens": 496, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897558991953, "lm_q2_score": 0.822189121808099, "lm_q1q2_score": 0.7735071032088152}} {"text": "!--------------------------------------------------------------------------------\n! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany\n! This file is part of FLEUR and available as free software under the conditions\n! of the MIT license as expressed in the LICENSE file in more detail.\n!--------------------------------------------------------------------------------\n\nMODULE m_polangle\n !-----------------------------------------------------------------------------\n ! Calculates the polar angles theta and phi of a vector with components\n ! vx, vy and vz.\n ! Philipp Kurz 2000-02-08\n ! Modernised A.N. 2020\n !-----------------------------------------------------------------------------\nCONTAINS\n\n SUBROUTINE pol_angle(vx, vy, vz, theta, phi)\n USE m_constants, ONLY : pimach\n IMPLICIT NONE\n\n REAL, INTENT(IN) :: vx, vy, vz\n REAL, INTENT(OUT) :: theta, phi\n\n REAL :: eps, r, rho, pi\n\n pi = pimach()\n eps = 1.0e-9\n\n rho = SQRT(vx**2 + vy**2)\n r = SQRT(vx**2 + vy**2 + vz**2)\n\n ! Zero vector:\n IF ( (r.LT.eps) .AND. (rho.LT.eps) ) THEN\n theta = 0.0\n phi = 0.0\n ! v on positive z-axis:\n ELSE IF ( (rho.LT.eps) .AND. vz.GT.0) THEN\n theta = 0.0\n phi = 0.0\n ! v on negative z-axis:\n ELSE IF ( (rho.LT.eps) .AND. vz.LT.0) THEN\n theta = pi\n phi = 0.0\n ELSE\n ! v in xy-plane:\n IF (ABS(vz).LT.eps) THEN\n theta = pi/2\n ELSE\n theta = ASIN(rho/r)\n END IF\n\n IF ( vz.LT.0 ) THEN\n theta = pi - theta\n END IF\n\n ! v in yz-plane\n IF (ABS(vx).LT.eps) THEN\n phi = pi/2\n\n ELSE\n phi = ASIN(ABS(vy)/rho)\n END IF\n\n IF ( vx.LT.0 ) phi = pi - phi\n IF ( vy.LT.0 ) phi = -phi\n END IF\n\n\n\n END SUBROUTINE pol_angle\n\n SUBROUTINE sphericaltocart(r, theta, phi, x, y, z)\n IMPLICIT NONE\n\n REAL, INTENT(IN) :: r, theta, phi\n REAL, INTENT(OUT) :: x, y, z\n\n x=r*SIN(theta)*COS(phi)\n y=r*SIN(theta)*SIN(phi)\n z=r*COS(theta)\n END SUBROUTINE sphericaltocart\n\nEND MODULE m_polangle\n", "meta": {"hexsha": "c605107a604bc299d484a67325138f2c07323082", "size": 2302, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "math/pol_angle.f90", "max_stars_repo_name": "MRedies/FLEUR", "max_stars_repo_head_hexsha": "84234831c55459a7539e78600e764ff4ca2ec4b6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "math/pol_angle.f90", "max_issues_repo_name": "MRedies/FLEUR", "max_issues_repo_head_hexsha": "84234831c55459a7539e78600e764ff4ca2ec4b6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math/pol_angle.f90", "max_forks_repo_name": "MRedies/FLEUR", "max_forks_repo_head_hexsha": "84234831c55459a7539e78600e764ff4ca2ec4b6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.734939759, "max_line_length": 81, "alphanum_fraction": 0.4344048653, "num_tokens": 635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763574, "lm_q2_score": 0.8244619263765706, "lm_q1q2_score": 0.773447531990407}} {"text": " program test\n real*4 spherdist\n real lon1,lat1,lon2,lat2,sd\n integer i\nc\n do i= -180,180,5\n lon1 = i\n lon2 = i+1\n lat1 = 0.0d0\n lat2 = 0.0d0\n sd = spherdist(lon1,lat1,lon2,lat2)\n write(6,*) sd,i\n enddo\n do i= -89,89,5\n lon1 = 0.0d0\n lon2 = 0.0d0\n lat1 = i\n lat2 = i+1\n sd = spherdist(lon1,lat1,lon2,lat2)\n write(6,*) sd,i\n enddo\n end\n real*4 function spherdist(lon1,lat1,lon2,lat2)\n implicit none\n real, intent(in) :: lon1,lat1,lon2,lat2 ! Pos. in degrees\nc\nc --- -------------------------------------------\nc --- Computes the distance between geo. pos.\nc --- lon1,lat1 and lon2,lat2. \nc --- INPUT is in degrees.\nc\nc --- Based on m_spherdist.F90 from Geir Evanson.\nc --- -------------------------------------------\nc\n double precision, parameter :: invradian=0.017453292d0\n double precision, parameter :: rearth=6371001.0d0 ! Radius of earth\nc\n double precision rlon1,rlat1,rlon2,rlat2 ! Pos. in radians\n double precision x1,y1,z1,x2,y2,z2 ! Cartesian position\n double precision dx,dy,dz,dr ! Cartesian distances\nc\n rlon1=lon1*invradian !lon1 in rad\n rlat1=(90.d0-lat1)*invradian !90-lat1 in rad \nc\n rlon2=lon2*invradian !lon2 in rad\n rlat2=(90.d0-lat2)*invradian !90-lat2 in rad \nc\n x1= sin(rlat1)*cos(rlon1) !x,y,z of pos 1.\n y1= sin(rlat1)*sin(rlon1)\n z1= cos(rlat1) \nc\n x2= sin(rlat2)*cos(rlon2) !x,y,z of pos 2.\n y2= sin(rlat2)*sin(rlon2)\n z2= cos(rlat2) \nc\n dr=acos(x1*x2+y1*y2+z1*z2) ! Arc length\nc\n spherdist=dr*rearth\nc\n end function spherdist\n", "meta": {"hexsha": "dc2d5b0fc60fef87d0b3c81318fc379b67149f92", "size": 1803, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "topo/src/spherdist_test.f", "max_stars_repo_name": "TillRasmussen/HYCOM-tools", "max_stars_repo_head_hexsha": "7d26b60ce65ac9d785e0e36add36aca05c0f496d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2019-05-31T02:47:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T19:21:04.000Z", "max_issues_repo_path": "topo/src/spherdist_test.f", "max_issues_repo_name": "TillRasmussen/HYCOM-tools", "max_issues_repo_head_hexsha": "7d26b60ce65ac9d785e0e36add36aca05c0f496d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2019-09-27T08:20:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-18T16:50:53.000Z", "max_forks_repo_path": "topo/src/spherdist_test.f", "max_forks_repo_name": "TillRasmussen/HYCOM-tools", "max_forks_repo_head_hexsha": "7d26b60ce65ac9d785e0e36add36aca05c0f496d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-03-21T08:43:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T08:08:56.000Z", "avg_line_length": 29.5573770492, "max_line_length": 79, "alphanum_fraction": 0.5252357182, "num_tokens": 640, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475730993027, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.7734443927858632}} {"text": " FUNCTION BESSY1 (X)\n IMPLICIT NONE\n REAL *8 X,BESSY1,BESSJ1,FR,FS,Z,FP,FQ,XX\n! ----------------------------------------------------------------------\n! This subroutine calculates the Second Kind Bessel Function of\n! order 1, for any real number X. The polynomial approximation by\n! series of Chebyshev polynomials is used for 0 ABS(a1(ipeak,irow))) THEN\r\n ipeak = jrow\r\n END IF\r\n END DO max_pivot\r\n \r\n ! Check for singular equations. \r\n singular: IF ( ABS(a1(ipeak,irow)) < EPSILON ) THEN\r\n error = 1\r\n RETURN\r\n END IF singular\r\n \r\n ! Otherwise, if ipeak /= irow, swap rows irow & ipeak\r\n swap_eqn: IF ( ipeak /= irow ) THEN\r\n temp = a1(ipeak,1:n) \r\n a1(ipeak,1:n) = a1(irow,1:n) ! Swap rows in a\r\n a1(irow,1:n) = temp \r\n temp = b(ipeak,1:n) \r\n b(ipeak,1:n) = b(irow,1:n) ! Swap rows in b\r\n b(irow,1:n) = temp \r\n END IF swap_eqn\r\n \r\n ! Multiply equation irow by -a1(jrow,irow)/a1(irow,irow), \r\n ! and add it to Eqn jrow (for all eqns except irow itself).\r\n eliminate: DO jrow = 1, n\r\n IF ( jrow /= irow ) THEN\r\n factor = -a1(jrow,irow)/a1(irow,irow)\r\n a1(jrow,:) = a1(irow,1:n)*factor + a1(jrow,1:n)\r\n b(jrow,:) = b(irow,1:n)*factor + b(jrow,1:n)\r\n END IF\r\n END DO eliminate\r\nEND DO mainloop\r\n \r\n! End of main loop over all equations. All off-diagonal\r\n! terms are now zero. To get the final answer, we must\r\n! divide each equation by the coefficient of its on-diagonal\r\n! term.\r\ndivide: DO irow = 1, n\r\n b(irow,irow) = b(irow,irow) / a1(irow,irow)\r\nEND DO divide\r\n \r\n! Set error flag to 0 and return.\r\nerror = 0\r\n\r\nEND SUBROUTINE matinv\r\n\r\n", "meta": {"hexsha": "c2465b0e52f41813362dca1bdc8321f330f13e2c", "size": 3670, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap9/matinv.f90", "max_stars_repo_name": "yangyang14641/FortranLearning", "max_stars_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-03-12T02:18:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-05T07:58:56.000Z", "max_issues_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap9/matinv.f90", "max_issues_repo_name": "yangyang14641/FortranLearning", "max_issues_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap9/matinv.f90", "max_forks_repo_name": "yangyang14641/FortranLearning", "max_forks_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-05-11T02:36:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T06:36:55.000Z", "avg_line_length": 35.6310679612, "max_line_length": 72, "alphanum_fraction": 0.514986376, "num_tokens": 996, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941718, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7733439103763584}} {"text": "!Program to write the points satisfying the parabola equation in a file\r\n\r\nprogram outputdata\r\n implicit none\r\n\r\n real,dimension(100)::x,y\r\n real,dimension(100)::p,q\r\n integer :: i\r\n real::a\r\n\r\n print*,\"Enter the value of a(distance from origin to focus) : \"\r\n read*,a\r\n\r\n do i=1,100\r\n x(i)=i*0.1 !Taking 100 values of x as multiple of 0.1\r\n y(i)=sqrt(4*a*x(i))\n end do\r\n\r\n open(1,file=\"parabola.dat\",status=\"old\")\r\n do i=1,100\r\n write(1,*),x(i),y(i)\n end do\r\n\r\n close(1)\nend program\r\n", "meta": {"hexsha": "6762a530c491bb38b8c85db27865a8cf49831b9e", "size": 545, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "parabola_equation.f90", "max_stars_repo_name": "Official-Satyam-Tiwari/FORTRAN", "max_stars_repo_head_hexsha": "5f15194bc7a2bdf84ce4516fa291f49072f6b227", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "parabola_equation.f90", "max_issues_repo_name": "Official-Satyam-Tiwari/FORTRAN", "max_issues_repo_head_hexsha": "5f15194bc7a2bdf84ce4516fa291f49072f6b227", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "parabola_equation.f90", "max_forks_repo_name": "Official-Satyam-Tiwari/FORTRAN", "max_forks_repo_head_hexsha": "5f15194bc7a2bdf84ce4516fa291f49072f6b227", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.9615384615, "max_line_length": 72, "alphanum_fraction": 0.576146789, "num_tokens": 170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012701768145, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.773262978048092}} {"text": "\nMODULE precision\n ! dp = double precisiona\n INTEGER, PARAMETER:: dp = SELECTED_REAL_KIND(12)\nEND MODULE precision\n\nMODULE RxnConstant\n USE precision\n IMPLICIT NONE\n\n INTEGER, PARAMETER:: n = 4\n REAL(KIND = dp), PARAMETER:: kab = 1, kba = 3, kbc = 4.2, kcb = 7.3, kcd = 0.4\nEND MODULE RxnConstant\n\nPROGRAM Chemical_Kinetics_Rxn\n USE precision\n USE RxnConstant\n IMPLICIT NONE\n\n REAL(KIND = dp):: concentration(n)\n REAL(KIND = dp):: time, dt, tmax\n INTEGER:: nt, i\n\n time = 0;\n dt = 0.0001;\n tmax = 60;\n ! Number of iteration\n nt = int(tmax/dt);\n concentration = 0 ! Make all concentration = 0.0\n concentration(1) = 5.0 ! Now, [A] = 5.0\n\n OPEN(unit = 10, file = \"output.txt\")\n DO i = 1, nt\n time = time + dt;\n ! CALL Euler(concentration, dt)\n ! CALL RK2(concentration, dt)\n CALL RK4(concentration, dt)\n WRITE(10, *) time, concentration\n ENDDO\n CLOSE(10)\n\n CONTAINS\n SUBROUTINE Euler(concentration, dt)\n USE precision\n USE RxnConstant\n IMPLICIT NONE\n\n REAL(KIND = dp):: concentration(n), Func(n)\n REAL(KIND = dp):: dt\n\n ! Euler Propagation\n CALL DbyDT(concentration, Func)\n concentration = concentration + dt * Func\n END SUBROUTINE Euler\n\n SUBROUTINE RK2(concentration, dt)\n USE precision\n IMPLICIT NONE\n\n REAL(KIND = dp):: concentration(n), sl(n), sr(n)\n REAL(KIND = dp):: dt\n\n ! RK2 Propagation\n CALL DbyDT(concentration, sl)\n CALL DbyDT(concentration + dt * sl, sr)\n concentration = concentration + dt * (sl + sr)/2.0_dp\n END SUBROUTINE RK2\n\n SUBROUTINE RK4(concentration, dt)\n USE precision\n IMPLICIT NONE\n\n REAL(KIND = dp):: concentration(n), s1(n), s2(n), s3(n), s4(n)\n REAL(KIND = dp):: dt\n\n ! RK2 Propagation\n CALL DbyDT(concentration, s1)\n CALL DbyDT(concentration + dt * s1/2.0_dp, s2)\n CALL DbyDT(concentration + dt * s2/2.0_dp, s3)\n CALL DbyDT(concentration + dt * s3, s4)\n concentration = concentration + dt * (s1 + 2*s2 + 2*s3 + s4)/6.0_dp\n END SUBROUTINE RK4\n\n SUBROUTINE DbyDT(concentration, Func)\n USE precision\n USE RxnConstant\n IMPLICIT NONE\n\n REAL(KIND = dp):: concentration(n), Func(n)\n\n Func(1) = -kab * concentration(1) + kba * concentration(2)\n Func(2) = kab * concentration(1) - kba * concentration(2) - kbc * concentration(2) + kcb * concentration(3)**2\n Func(3) = 2 * kbc * concentration(2) - 2 * kcb * concentration(3)**2 - kcd * concentration(3)\n Func(4) = kcd * concentration(3)\n END SUBROUTINE DbyDT\n\nEND PROGRAM Chemical_Kinetics_Rxn\n", "meta": {"hexsha": "4a38ab4414e04f480d8dcb510e802930188dbab6", "size": 2749, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ODEs/Chemical Kinetics.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "ODEs/Chemical Kinetics.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ODEs/Chemical Kinetics.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 28.0510204082, "max_line_length": 118, "alphanum_fraction": 0.5936704256, "num_tokens": 833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119662, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.7732183789431458}} {"text": " PROGRAM xchebft\r\nC driver for routine chebft\r\n INTEGER NVAL\r\n REAL PIO2,EPS\r\n PARAMETER(NVAL=40, PIO2=1.5707963, EPS=1E-6)\r\n INTEGER i,j,mval\r\n REAL a,b,dum,f,func,t0,t1,term,x,y,c(NVAL)\r\n EXTERNAL func\r\n a=-PIO2\r\n b=PIO2\r\n call chebft(a,b,c,NVAL,func)\r\nC test result\r\n10 write(*,*) 'How many terms in Chebyshev evaluation?'\r\n write(*,'(1x,a,i2,a)') 'Enter n between 6 and ',NVAL,\r\n * '. Enter n=0 to END.'\r\n read(*,*) mval\r\n if ((mval.le.0).or.(mval.gt.NVAL)) goto 20\r\n write(*,'(1x,t10,a,t19,a,t28,a)') 'X','Actual','Chebyshev fit'\r\n do 12 i=-8,8,1\r\n x=i*PIO2/10.0\r\n y=(x-0.5*(b+a))/(0.5*(b-a))\r\nC evaluate Chebyshev polynomial without using routine CHEBEV\r\n t0=1.0\r\n t1=y\r\n f=c(2)*t1+c(1)*0.5\r\n do 11 j=3,mval\r\n dum=t1\r\n t1=2.0*y*t1-t0\r\n t0=dum\r\n term=c(j)*t1\r\n f=f+term\r\n11 continue\r\n write(*,'(1x,3f12.6)') x,func(x),f\r\n12 continue\r\n goto 10\r\n20 END\r\n REAL FUNCTION func(x)\r\n REAL x\r\n func=(x**2)*(x**2-2.0)*sin(x)\r\n END\r\n", "meta": {"hexsha": "cad4bff783937436b82a7b260b3ee51c29afeac1", "size": 1156, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xchebft.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xchebft.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xchebft.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1951219512, "max_line_length": 69, "alphanum_fraction": 0.4956747405, "num_tokens": 431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909757, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7732183679275643}} {"text": "MODULE m_inv3\n !-----------------------------------\n ! invert 3x3 matrix\n !-----------------------------------\n\n PRIVATE\n\n INTERFACE inv3\n MODULE PROCEDURE inv3i,inv3r\n END INTERFACE inv3\n\n PUBLIC :: inv3\n\nCONTAINS\n SUBROUTINE inv3r(a,b,d)\n\n IMPLICIT NONE\n ! ..\n ! .. Arguments ..\n REAL, INTENT (IN) :: a(3,3)\n REAL, INTENT (OUT) :: b(3,3) ! inverse matrix\n REAL, INTENT (OUT) :: d ! determinant\n ! ..\n d = a(1,1)*a(2,2)*a(3,3) + a(1,2)*a(2,3)*a(3,1) + &\n a(2,1)*a(3,2)*a(1,3) - a(1,3)*a(2,2)*a(3,1) - &\n a(2,3)*a(3,2)*a(1,1) - a(2,1)*a(1,2)*a(3,3)\n b(1,1) = (a(2,2)*a(3,3)-a(2,3)*a(3,2))/d\n b(1,2) = (a(1,3)*a(3,2)-a(1,2)*a(3,3))/d\n b(1,3) = (a(1,2)*a(2,3)-a(2,2)*a(1,3))/d\n b(2,1) = (a(2,3)*a(3,1)-a(2,1)*a(3,3))/d\n b(2,2) = (a(1,1)*a(3,3)-a(3,1)*a(1,3))/d\n b(2,3) = (a(1,3)*a(2,1)-a(1,1)*a(2,3))/d\n b(3,1) = (a(2,1)*a(3,2)-a(2,2)*a(3,1))/d\n b(3,2) = (a(1,2)*a(3,1)-a(1,1)*a(3,2))/d\n b(3,3) = (a(1,1)*a(2,2)-a(1,2)*a(2,1))/d\n\n END SUBROUTINE inv3r\n\n SUBROUTINE inv3i(a,b,d)\n\n IMPLICIT NONE\n ! ..\n ! .. Arguments ..\n INTEGER, INTENT (IN) :: a(3,3)\n INTEGER, INTENT (OUT) :: b(3,3) ! inverse matrix\n INTEGER, INTENT (OUT) :: d ! determinant\n ! ..\n d = a(1,1)*a(2,2)*a(3,3) + a(1,2)*a(2,3)*a(3,1) +&\n a(2,1)*a(3,2)*a(1,3) - a(1,3)*a(2,2)*a(3,1) -&\n a(2,3)*a(3,2)*a(1,1) - a(2,1)*a(1,2)*a(3,3)\n b(1,1) = (a(2,2)*a(3,3)-a(2,3)*a(3,2))/d\n b(1,2) = (a(1,3)*a(3,2)-a(1,2)*a(3,3))/d\n b(1,3) = (a(1,2)*a(2,3)-a(2,2)*a(1,3))/d\n b(2,1) = (a(2,3)*a(3,1)-a(2,1)*a(3,3))/d\n b(2,2) = (a(1,1)*a(3,3)-a(3,1)*a(1,3))/d\n b(2,3) = (a(1,3)*a(2,1)-a(1,1)*a(2,3))/d\n b(3,1) = (a(2,1)*a(3,2)-a(2,2)*a(3,1))/d\n b(3,2) = (a(1,2)*a(3,1)-a(1,1)*a(3,2))/d\n b(3,3) = (a(1,1)*a(2,2)-a(1,2)*a(2,1))/d\n\n END SUBROUTINE inv3i\nEND MODULE m_inv3\n", "meta": {"hexsha": "9ec3793a438a1a19bd5947eeb2c25c6f532d2671", "size": 1904, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "math/inv3.f90", "max_stars_repo_name": "MRedies/FLEUR", "max_stars_repo_head_hexsha": "84234831c55459a7539e78600e764ff4ca2ec4b6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "math/inv3.f90", "max_issues_repo_name": "MRedies/FLEUR", "max_issues_repo_head_hexsha": "84234831c55459a7539e78600e764ff4ca2ec4b6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math/inv3.f90", "max_forks_repo_name": "MRedies/FLEUR", "max_forks_repo_head_hexsha": "84234831c55459a7539e78600e764ff4ca2ec4b6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.2222222222, "max_line_length": 56, "alphanum_fraction": 0.4096638655, "num_tokens": 1112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620562254526, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7732151995396582}} {"text": "C PROGRAM FOR MONTE CARLO DETERMINATION OF PI\nC GAURAV RUDRA MALIK, R.NO:23\n\tDOUBLE PRECISION a,b\n\tF(L)=MOD(1956*L + 178592,67529)\n\tC=0\n\tD=0\n\tWRITE(*,*)'ENTER THE NUMBER OF HITS'\n\tREAD(*,*)N\n\tWRITE(*,*)'ENTER THE SEED'\n\tREAD(*,*)Q\n\tDO I=1,N\n\tQ=F(Q)\n\tP=F(Q)\n\tR=F(P)\n\tX=Q/67529\n\tY=P/67529\n\tZ=R/67529\n\tIF((X**2+Y**2).LT.1)THEN\n\tC=C+1\n\tENDIF\n\tIF((X**2+Y**2+Z**2).LT.1)THEN\n\tD=D+1\n\tENDIF\n\tENDDO\n\t A=4*(C/N)\n\t B=6*(D/N)\n\tWRITE(*,*)'THE VALUE OF PI IN 2D:',A\n\tWRITE(*,*)'THE VALUE OF PI IN 3D:',B\n\tSTOP\n\tEND\n\nRESULT\n\n ENTER THE NUMBER OF HITS\n100000\n ENTER THE SEED\n359\n THE VALUE OF PI IN 2D: 3.13072\n THE VALUE OF PI IN 3D: 3.14178\n\n", "meta": {"hexsha": "e542809cef92e835679e0fb325ca725a245dc9b0", "size": 632, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "montecarlo_pi.f", "max_stars_repo_name": "GauravR-Malik/ComputationPhysics_Fortran", "max_stars_repo_head_hexsha": "70ab4d6fe815538c23715799159e46e63dbbde3c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "montecarlo_pi.f", "max_issues_repo_name": "GauravR-Malik/ComputationPhysics_Fortran", "max_issues_repo_head_hexsha": "70ab4d6fe815538c23715799159e46e63dbbde3c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "montecarlo_pi.f", "max_forks_repo_name": "GauravR-Malik/ComputationPhysics_Fortran", "max_forks_repo_head_hexsha": "70ab4d6fe815538c23715799159e46e63dbbde3c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.4146341463, "max_line_length": 45, "alphanum_fraction": 0.6139240506, "num_tokens": 302, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.773200224091942}} {"text": " SUBROUTINE CELLVECT\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! Generates the vectors used to convert fractionals to\n!! Cartesians and cartesians to fractionals\n!! Using the cell parameters a,b \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n USE header_file\n IMPLICIT NONE\n \n REAL(kind = double) :: DET\n\n EFC(1,1) = ALEN\n EFC(1,2) = BLEN*COS(GAMMA) + DELTA \n EFC(2,1) = 0.0D0\n EFC(2,2) = BLEN*SIN(GAMMA) \n\n DET = ABS(EFC(1,1)*EFC(2,2) - EFC(1,2)*EFC(2,1))\n\n ECF(1,1) = EFC(2,2)/DET\n ECF(1,2) = -EFC(1,2)/DET\n ECF(2,1) = -EFC(2,1)/DET\n ECF(2,2) = EFC(1,1)/DET\n\n END SUBROUTINE\n\n", "meta": {"hexsha": "9e3313e4312250d257fa18bc7367fc9572d61c44", "size": 678, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "synthetic_NEMD/src/src_2dsllod/cellvect.f90", "max_stars_repo_name": "niallj/ImperialNESS-Sep14", "max_stars_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "synthetic_NEMD/src/src_2dsllod/cellvect.f90", "max_issues_repo_name": "niallj/ImperialNESS-Sep14", "max_issues_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "synthetic_NEMD/src/src_2dsllod/cellvect.f90", "max_forks_repo_name": "niallj/ImperialNESS-Sep14", "max_forks_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.1111111111, "max_line_length": 57, "alphanum_fraction": 0.4631268437, "num_tokens": 254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.962673109443157, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.7731938159621633}} {"text": "C$Procedure DACOSH ( Double precision arc hyperbolic cosine )\n \n DOUBLE PRECISION FUNCTION DACOSH ( X )\n \nC$ Abstract\nC\nC Return the inverse hyperbolic cosine of a double\nC precision argument.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC HYPERBOLIC, MATH\nC\nC$ Declarations\n \n DOUBLE PRECISION X\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC X I Number whose inverse hyperbolic cosine is desired.\nC X must be >= 1.\nC\nC$ Detailed_Input\nC\nC X is any double precision number greater than or equal to 1.\nC\nC$ Detailed_Output\nC\nC DACOSH is the inverse hyperbolic cosine of X.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Particulars\nC\nC This function simply implements the definition of the inverse\nC hyperbolic cosine as follows:\nC\nC DACOSH = DLOG (X + DSQRT (X*X-1.D0))\nC\nC If the input value is not valid, an error is signalled.\nC\nC$ Examples\nC\nC The following table gives a few values for X and the resulting\nC value of DACOSH.\nC\nC X DACOSH(X)\nC ----------------------------------------------\nC 1.000000000000000 0.0000000000000000E+00\nC 10.00000000000000 2.993222846126381\nC 100.0000000000000 5.298292365610485\nC 1000.000000000000 7.600902209541989\nC\nC$ Restrictions\nC\nC The value of the input variable X must be greater than or equal\nC to 1.0d0.\nC\nC$ Exceptions\nC\nC 1) If X is less than 1.0d0, the error SPICE(INVALIDARGUMENT) is\nC signalled.\nC\nC$ Files\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC H.A. Neilan (JPL)\nC W.M. Owen (JPL)\nC\nC$ Literature_References\nC\nC Any good book of mathematical tables and formulae, for example\nC the \"Standard Mathematical Tables\" published by the Chemical\nC Rubber Company.\nC\nC$ Version\nC\nC- SPICELIB Version 1.1.0, 17-MAY-1994 (HAN)\nC\nC Set the default function value to either 0, 0.0D0, .FALSE.,\nC or blank depending on the type of the function.\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WMO)\nC\nC-&\n \nC$ Index_Entries\nC\nC d.p. arc hyperbolic_cosine\nC\nC-&\n \n \nC\nC SPICELIB functions\nC\n \n LOGICAL RETURN\n \n \n \nC\nC Set up the error processing.\nC\n IF ( RETURN() ) THEN\n DACOSH = 0.0D0\n RETURN\n ELSE\n CALL CHKIN ( 'DACOSH' )\n DACOSH = 0.0D0\n END IF\n \nC\nC Check that X >= 1.\nC\n \n IF ( X .LT. 1.D0 ) THEN\n \n CALL SETMSG ( 'DACOSH: Invalid argument, X is less than one.' )\n CALL SIGERR ( 'SPICE(INVALIDARGUMENT)' )\n \n CALL CHKOUT ( 'DACOSH' )\n RETURN\n END IF\nC\nC Abiding by the order implied by the parentheses in the expression\nC (1.0D0/X)/X prevents floating point overflow that might occur for\nC large values of X if the equivalent expression, 1.0D0/(X*X), were\nC used.\nC\n DACOSH = DLOG (X + X * DSQRT (1.0D0 - (1.0D0/X)/X) )\n \n \n CALL CHKOUT ( 'DACOSH' )\n RETURN\n END\n", "meta": {"hexsha": "0a51457e70e935ca4bfc97fa1602f4942c985664", "size": 4594, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/dacosh.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/dacosh.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/dacosh.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 25.808988764, "max_line_length": 72, "alphanum_fraction": 0.6486721811, "num_tokens": 1386, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660962919971, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7731694006312256}} {"text": "\n!+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//\n! //\n! mc.f //\n! //\n! D. C. Groothuizen Dijkema - January, 2020 //\n!+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//\n\n! Approximating mathematical constants with Monte Carlo methods\n\n\nmodule monte_carlo\n implicit none\n ! please ignore the incongruity of having both an analytical definition of pi to use in one function, and another function to calculate\n ! the value of pi itself\n real(kind=8), parameter :: pi=4.*atan(1.)\ncontains\n\n function simulate_e() result(cnt)\n !\n ! Count the number of uniformly distributed random real numbers on [0,1] which are needed for their sum to become strictly greater than\n ! one.\n ! Euler's number is the expected value of this function.\n !\n ! returns\n ! -------\n ! cnt : integer\n ! - The count of random numbers.\n !\n\n integer :: cnt\n real(kind=8) :: sum,rand_num\n\n cnt=0\n sum=0.\n ! produce the count\n do while (sum.LE.1)\n call random_number(rand_num)\n sum=sum+rand_num\n cnt=cnt+1\n end do\n end function simulate_e\n\n function simulate_pi() result(within)\n !\n ! Randomly generate a point in the unit square and determine if it falls within the unit circle.\n !\n ! returns\n ! -------\n ! within : integer\n ! - 1 if the randomly generated point is within the unit circle, 0 otherwise. This should be a logical, but using an integer allows\n ! simple addition.\n !\n integer :: within\n\n real(kind=8) :: distance\n real(kind=8), dimension(2) :: point\n\n ! determine the point and its distance to the origin\n call random_number(point)\n distance=point(1)**2+point(2)**2\n\n if (distance.LE.1) then\n within=1\n else\n within=0\n end if\n end function simulate_pi\n\n function simulate_chord_length() result(distance)\n !\n ! Randomly generate a point on the radius of the unit circle, and determine its distance to the point (1,0). This is, \n ! effectively, the distance between any two random points, as those points could be rotated until one of them was (1,0)\n !\n ! returns\n ! -------\n ! distance : real(kind=8)\n ! - The chord length of two random points on the unit circle.\n !\n real(kind=8) :: distance,angle\n\n call random_number(angle)\n ! the range [0,1] to [0,2*pi]\n angle=angle*2.*pi\n distance=2.*sin(0.5*angle) ! formula derived simply from the definition of the sine function\n end function simulate_chord_length\n\n subroutine approximate_e(n_itr,means)\n !\n ! Use Monte Carlo simulations to produce successfully more accurate approximations of Euler's number.\n !\n ! parameters\n ! ----------\n ! n_itr : integer, intent(in)\n ! - The number of simulations to run.\n ! means : real(kind=8), intent(inout), dimension(n_itr)\n ! - The array in which to store the moving mean of the simulations.\n !\n integer, intent(in) :: n_itr\n real(kind=8), intent(inout), dimension(n_itr) :: means\n\n real(kind=8) :: mean\n integer :: itr,approx\n\n ! initialise the mean\n mean=simulate_e()\n means(1)=mean\n ! produce a sample, update the moving mean, and output\n do itr=2,n_itr\n approx=simulate_e()\n mean=mean+(approx-mean)/(itr+1)\n means(itr)=mean\n end do\n end subroutine approximate_e\n\n subroutine approximate_pi_integration(n_itr,means)\n !\n ! Use Monte Carlo simulations to produce successfully more accurate approximations of pi.\n !\n ! parameters\n ! ----------\n ! n_itr : integer, intent(in)\n ! - The number of simulations to run.\n ! means : real(kind=8), intent(inout), dimension(n_itr)\n ! - The array in which to store the moving mean of the simulations.\n !\n integer, intent(in) :: n_itr\n real(kind=8), intent(inout), dimension(n_itr) :: means\n\n integer :: itr,cnt\n\n ! initialise\n cnt=0\n ! produce a sample, update the moving mean, and output\n do itr=1,n_itr\n cnt=cnt+simulate_pi()\n means(itr)=4*real(cnt)/itr\n end do\n end subroutine approximate_pi_integration\n\n subroutine approximate_pi_chord_length(n_itr,means)\n !\n ! Use Monte Carlo simulations to produce successfully more accurate approximations of pi.\n !\n ! parameters\n ! ----------\n ! n_itr : integer, intent(in)\n ! - The number of simulations to run.\n ! means : real(kind=8), intent(inout), dimension(n_itr)\n ! - The array in which to store the moving mean of the simulations.\n !\n integer, intent(in) :: n_itr\n real(kind=8), intent(inout), dimension(n_itr) :: means\n\n real(kind=8) :: mean,approx\n integer :: itr\n\n ! initialise\n mean=4/simulate_chord_length()\n means(1)=mean\n ! produce a sample, update the moving mean, and output\n do itr=2,n_itr\n approx=simulate_chord_length()\n mean=mean+(approx-mean)/(itr+1)\n means(itr)=4/mean\n end do\n end subroutine approximate_pi_chord_length\n\nend module monte_carlo\n", "meta": {"hexsha": "916d52d2310fda5d2bafda2f71681d3bda8f00ce", "size": 5605, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/mc.f", "max_stars_repo_name": "DCGroothuizenDijkema/MonteCarloMathConstants", "max_stars_repo_head_hexsha": "4f8fed44e65b155171db3a682146370cbc7477d7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2022-03-08T22:07:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-08T22:08:15.000Z", "max_issues_repo_path": "src/mc.f", "max_issues_repo_name": "DCGroothuizenDijkema/MonteCarloMathConstants", "max_issues_repo_head_hexsha": "4f8fed44e65b155171db3a682146370cbc7477d7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mc.f", "max_forks_repo_name": "DCGroothuizenDijkema/MonteCarloMathConstants", "max_forks_repo_head_hexsha": "4f8fed44e65b155171db3a682146370cbc7477d7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.9705882353, "max_line_length": 139, "alphanum_fraction": 0.5636039251, "num_tokens": 1291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545348152282, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7729663753232957}} {"text": "module basic\n\n use, intrinsic :: iso_c_binding\n implicit none\n include \"fftw3.fi\"\n real(8), parameter :: PI = 3.141592653589793D0\n real(8), parameter :: TWO_PI = 6.283185307179586D0\n\n interface lstsq\n module procedure leastsqs, leastsqm\n end interface ! lstsq\n\n interface polyval\n module procedure polyvals, polyvalv\n end interface ! polyval\n\ncontains\n\nfunction mean(x,n) bind(c)\n! 平均值\n integer, intent(in) :: n\n real(8), intent(in) :: x(n)\n real(8) :: mean\n\n mean = sum(x)/dble(n)\nend function mean\n\nfunction rms(x,n) bind(c)\n! 均方根值\n integer, intent(in) :: n\n real(8), intent(in) :: x(n)\n real(8) :: rms\n\n rms = sqrt(sum(x*x)/dble(n))\nend function rms\n\nfunction peak(x,n) bind(c)\n! 峰值\n integer, intent(in) :: n\n real(8), intent(in) :: x(n)\n real(8) :: peak\n\n peak = maxval(abs(x),dim=1)\nend function peak\n\nfunction peakloc(x,n) bind(c)\n! 峰值所在位置\n integer, intent(in) :: n\n real(8), intent(in) :: x(n)\n integer :: peakloc\n\n peakloc = maxloc(abs(x),dim=1)\nend function peakloc\n\nsubroutine norm(a,n) bind(c)\n! 按峰值归一\n integer, intent(in) :: n\n real(8), intent(inout) :: a(n)\n\n integer :: i\n real(8) :: pk, ai\n\n pk = 0.d0\n\n do i = 1, n, 1\n ai = abs(a(i))\n if ( ai>pk ) pk = ai\n end do\n\n do i = 1, n, 1\n a(i) = a(i)/pk\n end do\n\n return\n\nend subroutine norm\n\nfunction nextpow2(n) bind(c)\n! 不小于n的2的整数次幂\n integer, intent(in) :: n\n integer :: nextpow2\n\n nextpow2 = 1\n\n do while ( nextpow2n ) then\n dpower = 0.d0\n return\n end if\n\n k = n\n l = m\n dpower = x**(n-m)\n\n do while ( l>0 )\n dpower = dpower*k\n l = l - 1\n k = k - 1\n end do\nend function dpower\n\nfunction trapz(y,n,dx,y0) bind(c)\n! 等间隔dx离散数据梯形法数值积分,初值为y0\n implicit none\n real*8, intent(in) :: dx, y0\n integer, intent(in) :: n\n real*8, intent(in) :: y(n)\n\n real*8 :: trapz\n\n integer :: i\n real*8 :: r\n\n r = 0.d0\n\n !$OMP PARALLEL PRIVATE(i), SHARED(y,dx,n)\n !$OMP DO REDUCTION(+:r)\n\n do i = 2, n, 1\n r = r + dx*(y(i)+y(i-1))\n end do\n \n !$OMP END DO\n !$OMP END PARALLEL\n\n trapz = y0+r*0.5\n return\n\nend function trapz\n\n\nsubroutine cumtrapz(y,z,n,dx,z0) bind(c)\n! 等间隔dx离散数据梯形法累积数值积分,结果保存在数组z中,初值为z0\n\n real*8, intent(in) :: dx, z0\n integer, intent(in) :: n\n real*8, intent(in) :: y(n)\n real*8, intent(out) :: z(n)\n\n integer :: i\n real*8 :: r\n\n z(1) = z0\n r = 0.D0\n do i = 2, n, 1\n r = r + dx*(y(i)+y(i-1))*0.5\n z(i) = z0 + r\n end do\n return\n\nend subroutine cumtrapz\n\nsubroutine ariasIntensity(a,Ia,n) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: ariasIntensity\n! 计算Arias强度,结果记录在数组Ia中\n integer, intent(in) :: n\n real*8, intent(in) :: a(n)\n real*8, intent(out) :: Ia(n)\n\n call cumtrapz(a*a,Ia,n,1.d0,0.d0)\n Ia = Ia/Ia(n)\n return\n\nend subroutine ariasIntensity\n\nsubroutine fftfreqs(Nfft,fs,freqs) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: fftfreqs\n! 离散傅里叶变换的频率轴刻度值,fs为采样频率,结果记录在数组freqs中\n integer, intent(in) :: Nfft\n real(8), intent(in) :: fs\n real(8), intent(out) :: freqs(Nfft)\n\n real(8) :: fn, df\n integer :: i, l\n\n fn = 0.5D0*fs\n df = fs/dble(Nfft)\n freqs = 0.0D0\n\n if ( mod(Nfft, 2) == 0 ) then\n l = Nfft/2-1\n freqs(2:Nfft/2) = [ ( (dble(i)*df), i=1,l ) ]\n freqs(Nfft/2+1:Nfft) = [ ( -fn+(dble(i-1)*df), i=1,l+1 ) ]\n else\n l = (Nfft+1)/2-1\n freqs(2:(Nfft+1)/2) = [ ( (dble(i)*df), i=1,l ) ]\n freqs((Nfft+1)/2+1:Nfft) = [ ( -(dble(l-i+1)*df), i=1,l ) ]\n end if\n\n return\nend subroutine fftfreqs\n\nsubroutine acc2vd(a,v,d,n,dt,v0,d0) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: acc2vd\n! 加速度积分为速度、位移\n real(8), intent(in) :: dt,v0,d0\n integer(4), intent(in) :: n\n real(8), intent(in) :: a(n)\n real(8), intent(out) :: v(n), d(n)\n\n integer(4) :: i\n real(8) :: vi, di\n\n v(1) = v0\n d(1) = d0\n\n vi = 0.D0\n di = 0.D0\n do i = 2, n, 1\n vi = vi + dt*(a(i)+a(i-1))*0.5\n v(i) = v0 + vi\n di = di + dt*(v(i)+v(i-1))*0.5\n d(i) = d0 + di\n end do\n return\nend subroutine acc2vd\n\nsubroutine ratacc2vd(a,v,d,n,dt,v0,d0) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: ratacc2vd\n! 加速度积分为速度、位移,采用预估的初速度和初位移\n real(8), intent(in) :: dt,v0,d0\n integer(4), intent(in) :: n\n real(8), intent(in) :: a(n)\n real(8), intent(out) :: v(n), d(n)\n\n real(8) :: vn, dn\n integer :: i\n\n call acc2vd(a,v,d,n,dt,v0,d0)\n vn = sum(v)/dble(n)\n dn = 0.0d0\n do i = 1, n, 1\n dn = dn + d(i) - vn*dble(i-1)*dt\n end do\n dn = dn/dble(n)\n\n call acc2vd(a,v,d,n,dt,v0-vn,d0-dn)\n\nend subroutine ratacc2vd\n\nsubroutine leastsqs(a,b,m,n) bind(c)\n! 最小二乘法解方程组 A*x = b, b为一维数组\n integer, intent(in) :: m, n\n real*8, intent(in) :: a(m,n)\n real*8, intent(inout) :: b(m)\n\n integer :: i, nrhs, lda, ldb, lwork\n integer :: rank, info\n real*8 :: twork(1)\n integer :: tiwork(1)\n real*8, allocatable :: s(:)\n real*8, allocatable :: work(:)\n integer, allocatable :: iwork(:)\n\n ! m = size(a, dim=1)\n ! n = size(a, dim=2)\n nrhs = 1\n\n lda = max(1,m)\n ldb = max(1,m,n)\n\n allocate(s(min(m,n)))\n\n lwork = -1\n\n call dgelsd(m, n, nrhs, a, lda, b, ldb, s, -1.d0, &\n rank, twork, lwork, tiwork, info)\n\n lwork = int(twork(1))\n allocate(work(lwork))\n allocate(iwork(tiwork(1)))\n\n call dgelsd(m, n, nrhs, a, lda, b, ldb, s, -1.d0, &\n rank, work, lwork, iwork, info)\n\n deallocate(s)\n deallocate(work)\n deallocate(iwork)\n\n return\n\nend subroutine leastsqs\n\nsubroutine leastsqm(a,b,m,n,nrhs) bind(c)\n! 最小二乘法解方程组 A*x = b, b为二维数组\n real*8, intent(in) :: a(m,n)\n real*8, intent(inout) :: b(m,nrhs)\n integer, intent(in) :: m, n, nrhs\n\n integer :: i, lda, ldb, lwork\n integer :: rank, info\n real*8 :: twork(1)\n integer :: tiwork(1)\n real*8, allocatable :: s(:)\n real*8, allocatable :: work(:)\n integer,allocatable :: iwork(:)\n\n ! m = size(a, dim=1)\n ! n = size(a, dim=2)\n ! nrhs = size(b, dim=2)\n\n lda = max(1,m)\n ldb = max(1,m,n)\n\n allocate(s(min(m,n)))\n\n lwork = -1\n\n call dgelsd(m, n, nrhs, a, lda, b, ldb, s, -1.d0, &\n rank, twork, lwork, tiwork, info)\n\n lwork = int(twork(1))\n allocate(work(lwork))\n allocate(iwork(tiwork(1)))\n\n call dgelsd(m, n, nrhs, a, lda, b, ldb, s, -1.d0, &\n rank, work, lwork, iwork, info)\n\n deallocate(s)\n deallocate(work)\n deallocate(iwork)\n\n return\n\nend subroutine leastsqm\n\nsubroutine error(y,y0,n,aerror,merror) bind(c)\n! 计算数组y和y0的相对误差(不包括首尾元素),aerror 为平均误差,merror 为最大误差\n integer, intent(in) :: n\n real(8), intent(in) :: y(n), y0(n)\n real(8), intent(out) :: aerror, merror\n\n real(8), allocatable :: e(:)\n\n allocate(e(n-2))\n\n e = (y(2:n-1) - y0(2:n-1))/y0(2:n-1)\n\n !aerror = sum(abs(e))/dble(n-2)\n aerror = sqrt(sum(e*e)/dble(n-2))\n merror = maxval(abs(e), dim=1)\n\n deallocate(e)\n\nend subroutine error\n\nsubroutine errora(y,y0,n,aerror,merror) bind(c)\n! 计算数组y和y0的相对误差(包括所有元素),aerror 为平均误差,merror 为最大误差\n integer, intent(in) :: n\n real(8), intent(in) :: y(n), y0(n)\n real(8), intent(out) :: aerror, merror\n\n real(8), allocatable :: e(:)\n\n allocate(e(n))\n\n e = (y - y0)/y0\n\n !aerror = sum(abs(e))/dble(n)\n aerror = sqrt(sum(e*e)/dble(n))\n merror = maxval(abs(e), dim=1)\n\n deallocate(e)\n\nend subroutine errora\n\nsubroutine errora_endur(y,y0,n,m,aerror,merror) bind(c)\n! 计算矩阵y和y0的相对误差(包括所有元素),aerror 为平均误差,merror 为最大误差\n integer, intent(in) :: n, m\n real(8), intent(in) :: y(n,m), y0(n,m)\n real(8), intent(out) :: aerror, merror\n\n real(8) :: eij\n\n integer :: i,j\n\n aerror = 0.D0\n merror = 0.D0\n do i = 1, n, 1\n do j = 1, m, 1\n eij = (y(i,j) - y0(i,j))/y0(i,j)\n !aerror = aerror + abs(eij)\n aerror = aerror + eij*eij\n if ( merror < abs(eij) ) merror = abs(eij)\n end do\n end do\n\n aerror = aerror/dble(n*m)\n\nend subroutine errora_endur\n\nsubroutine incrlininterp(x,y,n,xi,yi,ni) bind(c)\n! 线性插值(x, xi为递增数组)\n integer, intent(in) :: n, ni\n real(8), intent(in) :: x(n), y(n), xi(ni)\n real(8), intent(out) :: yi(ni)\n\n integer :: i, j\n real(8) :: xc, yc, xp, yp, slope\n\n xp = x(1)\n yp = y(1)\n j = 1\n do i = 2, n, 1\n xc = x(i)\n yc = y(i)\n slope = (yc - yp)/(xc - xp)\n do while (j<=ni)\n if (xi(j)>xc) exit\n yi(j) = yp + slope*(xi(j)-xp)\n j = j + 1\n end do\n xp = xc\n yp = yc\n end do\n\nend subroutine incrlininterp\n\nsubroutine incrfindfirst(a,n,x,i) bind(c)\n! 找到数组a从头开始第一个超过x的值的位置(a的包络线为递增趋势)\n integer, intent(in) :: n\n real(8), intent(in) :: a(n), x\n integer, intent(out) :: i\n\n i = 1\n do while ( a(i)x .and. i>=1 )\n i = i - 1\n end do\n\n return\n\nend subroutine incrfindlast\n\nsubroutine decrlininterp(x,y,n,xi,yi,ni) bind(c)\n! 线性插值(x, xi为递减数组)\n integer, intent(in) :: n, ni\n real(8), intent(in) :: x(n), y(n), xi(ni)\n real(8), intent(out) :: yi(ni)\n\n integer :: i, j\n real(8) :: xc, yc, xp, yp, slope\n\n xp = x(n)\n yp = y(n)\n j = 1\n do i = 1, n-1, 1\n xc = x(n-i)\n yc = y(n-i)\n slope = (yc - yp)/(xc - xp)\n do while (j<=ni)\n if (xi(j)x .and. i<=n-1 )\n i = i + 1\n end do\n\n return\n\nend subroutine decrfindfirst\n\nsubroutine decrfindlast(a,n,x,i) bind(c)\n! 找到数组a从尾开始第一个超过x的值的位置(a的包络线为递减趋势)\n integer, intent(in) :: n\n real(8), intent(in) :: a(n), x\n integer, intent(out) :: i\n\n i = n\n do while ( a(i)=1 )\n i = i - 1\n end do\n\n return\n\nend subroutine decrfindlast\n\nsubroutine targetdc(a,td,n,tp,ntp,ph,pl,dt,v0,d0) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: targetdc\n! 基线调整,以规定位移为目标\n integer(4), intent(in) :: n\n real(8), intent(in) :: dt,v0,d0\n real(8), intent(in) :: td(n)\n real(8), intent(out) :: a(n)\n integer(4), intent(in) :: ntp,ph,pl\n integer(4), intent(in) :: tp(ntp)\n\n integer :: i,j,k,pn\n real(8), allocatable :: M(:,:), b(:), tc(:)\n real(8), allocatable :: v(:), d(:), t(:)\n\n pn = ph - pl + 1\n if ( pn>ntp ) pn = ntp\n\n allocate(M(ntp,pn))\n allocate(b(ntp))\n allocate(tc(ntp))\n allocate(t(n))\n allocate(v(n))\n allocate(d(n))\n\n t = [ (((i-1)*dt),i=1,n) ]\n call acc2vd(a,v,d,n,dt,v0,d0)\n\n do k = 1, ntp, 1\n j = tp(k)\n tc(k) = t(j)\n b(k) = td(j)-d(j)\n do i = pl, pl+pn-1, 1\n M(k,i-pl+1) = dpower(tc(k),i,0)\n end do\n end do\n\n call leastsqs(M,b,ntp,pn)\n\n do k = 1, n, 1\n do i = pl, pl+pn-1, 1\n a(k) = a(k)+b(i-pl+1)*dpower(t(k),i,2)\n end do\n end do\n\n deallocate(M)\n deallocate(b)\n deallocate(tc)\n deallocate(t)\n deallocate(v)\n deallocate(d)\n\n return\n\nend subroutine targetdc\n\nsubroutine targetdvc(a,td,tv,n,tp,ntp,ph,pl,dt,v0,d0) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: targetdvc\n! 基线调整,以规定速度、位移为目标\n integer(4), intent(in) :: n\n real(8), intent(in) :: dt,v0,d0\n real(8), intent(in) :: td(n),tv(n)\n real(8), intent(out) :: a(n)\n integer(4), intent(in) :: ntp,ph,pl\n integer(4), intent(in) :: tp(ntp)\n\n integer :: i,j,k,pn\n real(8), allocatable :: M(:,:), b(:), tc(:)\n real(8), allocatable :: v(:), d(:), t(:)\n\n pn = (ph - pl + 1)*2\n if ( pn>2*ntp ) pn = 2*ntp\n\n allocate(M(2*ntp,pn))\n allocate(b(2*ntp))\n allocate(tc(ntp))\n allocate(t(n))\n allocate(v(n))\n allocate(d(n))\n\n t = [ (((i-1)*dt),i=1,n) ]\n call acc2vd(a,v,d,n,dt,v0,d0)\n\n do k = 1, ntp, 1\n j = tp(k)\n tc(k) = t(j)\n b(k) = td(j)-d(j)\n b(k+ntp) = tv(j)-v(j)\n do i = pl, pl+pn-1, 1\n M(k,i-pl+1) = dpower(tc(k),i,0)\n M(k+ntp,i-pl+1) = dpower(tc(k),i,1)\n end do\n end do\n\n call leastsqs(M,b,2*ntp,pn)\n\n do k = 1, n, 1\n do i = pl, pl+pn-1, 1\n a(k) = a(k)+b(i-pl+1)*dpower(t(k),i,2)\n end do\n end do\n\n deallocate(M)\n deallocate(b)\n deallocate(tc)\n deallocate(t)\n deallocate(v)\n deallocate(d)\n\n return\n\nend subroutine targetdvc\n\nsubroutine targetdvac(a,td,tv,ta,n,tp,ntp,ph,pl,dt,v0,d0) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: targetdvac\n! 基线调整,以规定加速度、速度、位移为目标\n integer(4), intent(in) :: n\n real(8), intent(in) :: dt,v0,d0\n real(8), intent(in) :: td(n),tv(n),ta(n)\n real(8), intent(out) :: a(n)\n integer(4), intent(in) :: ntp,ph,pl\n integer(4), intent(in) :: tp(ntp)\n\n integer :: i,j,k,pn\n real(8), allocatable :: M(:,:), b(:), tc(:)\n real(8), allocatable :: v(:), d(:), t(:)\n\n pn = (ph - pl + 1)*3\n if ( pn>3*ntp ) pn = 3*ntp\n\n allocate(M(3*ntp,pn))\n allocate(b(3*ntp))\n allocate(tc(ntp))\n allocate(t(n))\n allocate(v(n))\n allocate(d(n))\n\n t = [ (((i-1)*dt),i=1,n) ]\n call acc2vd(a,v,d,n,dt,v0,d0)\n\n do k = 1, ntp, 1\n j = tp(k)\n tc(k) = t(j)\n b(k) = td(j)-d(j)\n b(k+ntp) = tv(j)-v(j)\n b(k+2*ntp) = ta(j)-a(j)\n do i = pl, pl+pn-1, 1\n M(k,i-pl+1) = dpower(tc(k),i,0)\n M(k+ntp,i-pl+1) = dpower(tc(k),i,1)\n M(k+2*ntp,i-pl+1) = dpower(tc(k),i,2)\n end do\n end do\n\n call leastsqs(M,b,3*ntp,pn)\n\n do k = 1, n, 1\n do i = pl, pl+pn-1, 1\n a(k) = a(k)+b(i-pl+1)*dpower(t(k),i,2)\n end do\n end do\n\n deallocate(M)\n deallocate(b)\n deallocate(tc)\n deallocate(t)\n deallocate(v)\n deallocate(d)\n\n return\n\nend subroutine targetdvac\n\nsubroutine fft(in,out,n) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: fft\n! 快速离散傅里叶变换\n integer, intent(in) :: n\n real*8, intent(inout) :: in(n)\n complex*16, intent(inout) :: out(n)\n\n type(c_ptr) :: plan\n\n plan = fftw_plan_dft_r2c_1d(n, in, out, fftw_estimate)\n call fftw_execute_dft_r2c(plan, in, out)\n call fftw_destroy_plan(plan)\n\n return\nend subroutine fft\n\nsubroutine ifft(in,out,n) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: ifft\n! 快速离散傅里叶拟变换\n integer, intent(in) :: n\n complex*16, intent(inout) :: in(n)\n real*8, intent(inout) :: out(n)\n\n type(c_ptr) :: plan\n\n plan = fftw_plan_dft_c2r_1d(n, in, out, fftw_estimate)\n call fftw_execute_dft_c2r(plan, in, out)\n call fftw_destroy_plan(plan)\n out = out/dble(n)\n\n return\nend subroutine ifft\n\nsubroutine hann(w,n) bind(c)\n! hann窗函数\n integer(C_INT), intent(in) :: n\n real(C_DOUBLE), intent(inout) :: w(n)\n\n integer(C_INT) i\n\n do i = 1, n, 1\n w(i) = 2.d0*w(i)*(0.5d0 - 0.5d0 * cos(TWO_PI * dble(i - 1) / dble(n - 1)))\n end do\n\nend subroutine hann\n\nsubroutine welch(a,n,m,olr,psd,win) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: welch\n! Welch 法估计功率谱\n integer(C_INT), intent(in) :: n, m\n real(C_DOUBLE), intent(in) :: a(n)\n real(C_DOUBLE), intent(out) :: psd(m)\n real(C_DOUBLE), intent(in) :: olr\n integer(C_INT), intent(in) :: win\n\n integer(C_INT) :: nol, i, j, k, q, nsub\n real(C_DOUBLE) :: re, im\n real(C_DOUBLE), allocatable :: c(:)\n complex(C_DOUBLE_COMPLEX), allocatable :: cf(:)\n\n type(c_ptr) :: plan\n\n if ( mod(m,2) == 0 ) then\n q = m/2 + 1\n else\n q = (m+1)/2\n end if\n\n nol = int(m*olr)\n k = m\n nsub = 1\n do while ( k < n )\n k = k - nol + m\n nsub = nsub + 1\n end do\n\n allocate(c(m))\n allocate(cf(m))\n\n psd = 0.d0\n c = a(1:m)\n plan = fftw_plan_dft_r2c_1d(m, c, cf, fftw_estimate)\n if (win>0) then \n call hann(c,m)\n end if\n call fftw_execute_dft_r2c(plan, c, cf)\n\n do j = 1, q, 1\n re = dble(cf(j))\n im = aimag(cf(j))\n psd(j) = (re*re + im*im)/dble(m*nsub)\n end do\n\n k = m\n do i = 2, nsub-1, 1\n k = k - nol + m\n c = a((k-m+1):k)\n if (win>0) then \n call hann(c,m)\n end if\n call fftw_execute_dft_r2c(plan, c, cf)\n do j = 1, q, 1\n re = dble(cf(j))\n im = aimag(cf(j))\n psd(j) = psd(j) + (re*re + im*im)/dble(m*nsub)\n end do\n end do\n\n k = k - nol + m\n c(1:(n-k+m)) = a((k-m+1):n)\n c((n-k+m+1):m) = 0.d0\n if (win>0) then \n call hann(c,m)\n end if\n call fftw_execute_dft_r2c(plan, c, cf)\n \n do j = 1, q, 1\n re = dble(cf(j))\n im = aimag(cf(j))\n psd(j) = psd(j) + (re*re + im*im)/dble(m*nsub)\n end do\n\n call fftw_destroy_plan(plan)\n\n deallocate(c)\n deallocate(cf)\n\nend subroutine welch\n\nsubroutine fftpadding(in,out,n,nfft) bind(c)\n! 数据序列后补零\n integer, intent(in) :: n, nfft\n real*8, intent(in) :: in(n)\n real*8, intent(out) :: out(nfft)\n\n out(1:n) = in(1:n)\n out(n+1:nfft) = 0.d0\n\n return\nend subroutine fftpadding\n\nsubroutine fftresample(a,n,r,ar,nr) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: fftresample\n! 用FFT的方法进行数据重采样(降低采样频率)\n integer(C_INT), intent(in) :: n, r, nr\n real(C_DOUBLE), intent(in) :: a(n)\n real(C_DOUBLE), intent(out) :: ar(nr)\n\n integer(C_INT) :: Nfft, Nfftr\n real(C_DOUBLE), allocatable :: ap(:), apr(:)\n complex(C_DOUBLE_COMPLEX), allocatable :: af(:), afr(:)\n\n if ( r == 1 ) return\n\n Nfft = nextpow(r,n)\n\n allocate(ap(Nfft))\n allocate(af(Nfft))\n\n call fftpadding(a,ap,n,Nfft)\n call fft(ap,af,Nfft)\n\n Nfftr = Nfft/r\n allocate(apr(Nfft))\n allocate(afr(Nfft))\n\n if ( mod(Nfftr,2) == 0 ) then\n afr(1:Nfftr/2) = af(1:Nfftr/2)\n afr(Nfftr/2+1) = 1.0*af(Nfftr/2+1)\n else\n afr(1:(Nfftr-1)/2) = af(1:(Nfftr-1)/2)\n afr((Nfftr-1)/2+1) = 1.0*af((Nfftr-1)/2+1)\n end if\n\n call ifft(afr,apr,Nfftr)\n\n ar = (1.d0/dble(r))*apr(1:nr)\n\n deallocate(ap)\n deallocate(af)\n deallocate(apr)\n deallocate(afr)\n\n return\n \nend subroutine fftresample\n\nsubroutine polyvals(p,m,x,y) bind(c)\n! 多项式求值(单个值)\n integer, intent(in) :: m\n real*8, intent(in) :: p(m), x \n real*8, intent(out) :: y\n\n integer :: i, n\n\n n = idnz(p)\n\n y = 0.D0\n do i = n, m, 1\n y = x*y + p(i)\n end do\n\n return\n\nend subroutine polyvals\n\nsubroutine polyvalv(p,m,x,y,n) bind(c)\n! 多项式求值(数组)\n integer, intent(in) :: m, n\n real*8, intent(in) :: p(m), x(n)\n real*8, intent(out) :: y(n)\n integer :: i, j, k\n\n k = idnz(p)\n\n !$OMP PARALLEL DEFAULT(NONE), PRIVATE(i,j), SHARED(p,m,x,y,n,k)\n !$OMP DO\n do i = 1, n, 1\n y(i) = 0.d0\n do j = k, m, 1\n y(i) = x(i)*y(i) + p(j)\n end do\n end do\n !$OMP END PARALLEL\n\n return\nend subroutine polyvalv\n\nsubroutine polyder(p,m,n,r,l) bind(c)\n! 多项式求导,p, r为求导前后的多项式系数(阶次从高到低,最后为常数项)\n integer, intent(in) :: m,n\n real*8, intent(in) :: p(m)\n real*8, intent(inout) :: r(l)\n integer, intent(inout) :: l\n\n integer :: i, j, k\n\n if ( l<0 ) then\n l = m - n\n if ( l<=0 ) l = 1\n return\n end if\n\n if ( n>=m ) then\n r(1) = 0.d0\n return\n end if\n\n do i = 1, l, 1\n r(i) = p(i)\n k = m-i\n do j = 1, n, 1\n r(i) = r(i)*k\n k = k-1\n end do\n end do\n return\n\nend subroutine polyder\n\nsubroutine polyint(p,m,n,r,l) bind(c)\n! 多项式积分,p, r为积分前后的多项式系数\n integer, intent(in) :: m,n\n real*8, intent(in) :: p(m)\n real*8, intent(inout) :: r(l)\n integer, intent(inout) :: l\n\n integer :: i, j, k\n\n if ( l<0 ) then\n l = m + n\n return\n end if\n\n r(m+1:l) = 0.d0\n\n do i = 1, m, 1\n r(i) = p(i)\n k = m-i\n do j = 1, n, 1\n r(i) = r(i)/dble(k+1)\n k = k+1\n end do\n end do\n return\nend subroutine polyint\n\nsubroutine polymul(p,m,q,n,r,l) bind(c)\n! 多项式乘法,r = p * q\n integer, intent(in) :: m,n\n real*8, intent(in) :: p(m),q(n)\n real*8, intent(inout) :: r(l)\n integer, intent(inout) :: l\n\n integer :: i, j\n\n if ( l<0 ) then\n l = m + n - 1\n return\n end if\n\n do i = 1, l, 1\n r(i) = 0.d0\n do j = 1, m, 1\n if (i-j > -1 .and. i-j < n) &\n r(i) = r(i) + p(i-j+1)*q(j)\n end do\n end do\n\n return\n\nend subroutine polymul\n\nsubroutine polydiv(p,m,q,n,r,l) bind(c)\n! 多项式除法,r = p / q\n integer, intent(in) :: m,n\n real*8, intent(in) :: p(m),q(n)\n integer, intent(inout) :: l\n real*8, intent(inout) :: r(l)\n\n integer :: i, j\n\n if ( l<0 ) then\n l = m + n - 1\n return\n end if\n\n do i = 1, l, 1\n r(i) = 0.d0\n do j = 1, m, 1\n if (i-j > -1 .and. i-j < n) &\n r(i) = r(i) + p(i-j+1)*q(j)\n end do\n end do\n\n return\n\nend subroutine polydiv\n\nsubroutine polyadd(p,m,q,n,r,l) bind(c)\n! 多项式加法,r = p + q\n integer, intent(in) :: m,n\n real*8, intent(in) :: p(m),q(n)\n integer, intent(inout) :: l\n real*8, intent(inout) :: r(l)\n\n integer :: i, j\n\n if ( l<0 ) then\n l = max(m,n)\n return\n end if\n\n if ( m>=n ) then\n do i = 1, l, 1\n if ( i<=m-n ) then\n r(i) = p(i)\n else\n r(i) = p(i) + q(i-m+n)\n end if\n end do\n else\n do i = 1, l, 1\n if ( i<=n-m ) then\n r(i) = q(i)\n else\n r(i) = q(i) + p(i-n+m)\n end if\n end do\n end if\n\n return\n\nend subroutine polyadd\n\nsubroutine polyroots(p,m,r,l) bind(c)\n! 多项式求根\n! Find roots of the (m-1)-order polynomial by solving the eigen\n! problem of the coresponding companion matrix.\n! The roots are all in complex form.\n\n integer, intent(in) :: m\n real*8, intent(in) :: p(m)\n integer, intent(inout) :: l\n complex*16, intent(inout) :: r(l)\n\n real*8, allocatable :: A(:,:), work(:), wr(:), wi(:)\n real*8 :: temp(1)\n integer :: i, j, info, lwork\n\n if ( l<0 ) then\n l = m - 1\n if ( l<1 ) stop \"Error: no roots; order too low (<1)!\"\n return\n end if\n\n if ( m == 2 ) then\n r(1) = -p(2)/p(1)\n return\n end if\n\n allocate(A(l,l))\n allocate(wr(l))\n allocate(wi(l))\n\n A = 0.d0\n A(1,1) = -p(2)/p(1)\n do i = 2, l, 1\n A(i,i-1) = 1.d0\n A(1,i) = -p(i+1)/p(1)\n end do\n\n lwork = -1\n call dgeev( \"N\", \"N\", l, A, l, wr, wi, temp, l, temp, l, temp, lwork, info )\n lwork = int(temp(1))\n allocate(work(lwork))\n call dgeev( \"N\", \"N\", l, A, l, wr, wi, temp, l, temp, l, work, lwork, info )\n\n do i = 1, l, 1\n r(i) = cmplx(wr(i),wi(i))\n end do\n\n deallocate(A)\n deallocate(work)\n deallocate(wr)\n deallocate(wi)\n\n return\n\nend subroutine polyroots\n\nfunction idnz(p)\n! 多项式系数数组中第一个非零值的位置\n! Return the index of first non-zero element in the array\n real*8, intent(in) :: p(:)\n integer :: idnz\n\n idnz = 1\n do while ( abs(p(idnz)) < 1.0d-30 )\n idnz = idnz + 1\n end do\n return\nend function idnz\n\nsubroutine polyfit(a,t,n,c,oh,ol) bind(c)\n! 多项式拟合,a(n)为待拟合数据,t(n)为自变量\n! oh, ol为拟合所用多项式的最高与最低阶次, c为拟合多项式的系数\n integer, intent(in) :: n\n real(8), intent(in) :: a(n), t(n)\n integer, intent(in) :: oh,ol\n real(8), intent(out) :: c(oh-ol+1)\n\n integer :: i, j, k\n real(8), allocatable :: b(:)\n real(8), allocatable :: M(:,:)\n\n k = oh-ol+1\n allocate(M(n,k))\n allocate(b(n))\n\n c = 0.D0\n b = a\n\n !$OMP PARALLEL DEFAULT(NONE), PRIVATE(i,j), SHARED(M,t,n,k,oh)\n !$OMP DO\n do i = 1, n, 1\n do j = 1, k, 1\n M(i,j) = t(i)**(oh-j+1)\n end do\n end do\n !$OMP END PARALLEL\n\n call leastsqs(M,b,n,k)\n\n c(1:k) = b(1:k)\n\n deallocate(M)\n deallocate(b)\n\n return\n\nend subroutine polyfit\n\nsubroutine polydetrend(a,n,oh,ol) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: polydetrend\n! 消除多项式趋势,oh, ol为拟合所用多项式的最高与最低阶次\n integer(4), intent(in) :: n\n real(8), intent(inout) :: a(n)\n integer(4), intent(in) :: oh,ol\n\n integer :: i\n real(8), allocatable :: t(:), c(:), ac(:)\n\n if ( oh == 0 ) then\n a = a - sum(a)/dble(n)\n return\n end if\n\n allocate(t(n))\n allocate(ac(n))\n allocate(c(oh+1))\n\n t = [ (((i-1)*1.D0),i=1,n) ]\n call polyfit(a,t,n,c,oh,ol)\n call polyval(c,oh+1,t,ac,n)\n\n a = a - ac\n\n deallocate(t)\n deallocate(c)\n deallocate(ac)\n\n return\n\nend subroutine polydetrend\n\nsubroutine polyblc(a,n,oh,ol,dt,v0,d0) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: polyblc\n! 改进的基线校正算法:\n! 1. 先用多项式拟合速度时程,将拟合所得多项式求导得到第一次修正时程,\n! 修正后重新积分计算速度、位移;\n! 2. 然后用多项式拟合位移时程,将拟合所得多项式求导两次得到第二次修正时程;\n integer, intent(in) :: n\n real(8), intent(in) :: dt, v0, d0\n real(8), intent(inout) :: a(n)\n integer, intent(in) :: oh, ol\n\n integer :: i,l\n real(8), allocatable :: t(:), v(:), d(:), c(:), r(:), ac(:)\n\n allocate(t(n))\n allocate(v(n))\n allocate(d(n))\n allocate(ac(n))\n\n allocate(c(oh+2))\n l = oh+1\n allocate(r(l))\n\n t = [ (((i-1)*dt),i=1,n) ]\n\n call cumtrapz(a,v,n,dt,v0)\n call polyfit(v,t,n,c,oh+1,ol+1)\n call polyder(c,oh+2,1,r,l)\n call polyval(r,oh+1,t,ac,n)\n a = a - ac\n\n deallocate(c)\n allocate(c(oh+3))\n\n call acc2vd(a,v,d,n,dt,v0,d0)\n call polyfit(d,t,n,c,oh+2,ol+2)\n call polyder(c,oh+3,2,r,l)\n call polyval(r,oh+1,t,ac,n)\n\n a = a - ac\n\n deallocate(t)\n deallocate(ac)\n deallocate(v)\n deallocate(d)\n deallocate(c)\n deallocate(r)\n\n return\nend subroutine polyblc\n\nend module basic\n\nmodule eqs\n\n use, intrinsic :: iso_c_binding\n use basic\n use omp_lib\n implicit none\n ! 自动选择频域与时域求解方法时,SDOF周期与采样间隔之比的临界值\n integer, parameter :: MPR = 20\n ! 非线性分析参数\n integer, parameter :: NPARA = 33\n real(8) :: para(NPARA) = 0.D0\n\n ! 本模块中一些函数的命名规则:\n ! 1. SDOF响应求解函数:rXXX 以r开头,当仅输出加速度响应时后跟a,XXX可能为freq, nmk, mixed\n ! 2. SDOF反应谱求解函数:spXXX 以sp开头,当仅输出加速度谱时后跟a,XXX可能为freq, nmk, mixed\n\ncontains\n\nsubroutine spamixed(acc,n,dt,zeta,P,nP,SPA,SPI) bind(c)\n integer, intent(in) :: n, nP\n real(C_DOUBLE), intent(in) :: dt, zeta\n real(C_DOUBLE), intent(in) :: acc(n), P(nP)\n real(C_DOUBLE), intent(out) :: SPA(nP)\n integer, intent(out) :: SPI(nP)\n\n integer :: m\n\n m = 1\n do while ( P(m) P ) then\n r = ceiling(MPR*dt0/P)\n dt = dt0/r\n else\n r = 1\n dt = dt0\n end if\n\n b1 = 1.d0/(beta*dt*dt)\n b2 = 1.d0/(beta*dt)\n b3 = 1.d0/(beta*2.0d0)-1.d0\n b4 = gamma/(beta*dt)\n b5 = gamma/beta-1.d0\n b6 = 0.5d0*dt*(gamma/beta-2.0d0)\n b7 = dt*(1.0d0-gamma)\n b8 = dt*gamma\n\n w = TWO_PI/P\n k = w**2.d0\n c = 2.0d0*zeta*w\n keff = k+b1+b4*c\n kinv = 1.0d0/keff\n\n ! initiation\n rl = 0.d0\n rc = 0.d0\n SPA = 0.0d0\n SPV = 0.0d0\n SPD = 0.0d0\n SPI = 0\n ein = 0.0d0\n al = 0.d0\n rvl = 0.d0\n\n ! computation of response\n do i = 1,n,1\n\n ac = acc(i)\n da = (ac - al)/dble(r)\n\n do j = 1, r, 1\n ac = al + da*j\n feff = ac+(b1*rl(1)+b2*rl(2)+b3*rl(3))&\n +c*(b4*rl(1)+b5*rl(2)+b6*rl(3))\n rc(1) = feff*kinv\n rc(2) = b4*(rc(1)-rl(1))-b5*rl(2)-b6*rl(3)\n rc(3) = ac-k*rc(1)-c*rc(2)\n rl(1) = rc(1)\n rl(2) = rc(2)\n rl(3) = rc(3)\n end do\n\n ein = ein+0.5d0*dt0*(rvl*al+rc(2)*ac)\n aa = -rc(3)+ac\n\n if (abs(aa) > abs(SPA)) then\n SPA=aa\n SPI=i\n endif\n\n if (abs(rc(2)) > abs(SPV)) then\n SPV=rc(2)\n endif\n\n if (abs(rc(1)) > abs(SPD)) then\n SPD=rc(1)\n endif\n\n al = ac\n rvl = rc(2)\n\n end do\n SPE = sqrt(2.d0*ein)\n return\nend subroutine newmark\n\nsubroutine rnmk(acc,n,dt0,zeta,P,ra,rv,rd) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: rnmk\n integer, intent(in) :: n\n real(8), intent(in) :: dt0, zeta\n real(8), intent(in) :: acc(n), P\n real(8), intent(out) :: ra(n),rv(n),rd(n)\n\n real(8) :: rc(3),rl(3),ac,al,aa,da\n real(8) :: beta = 1.d0/4.d0, gamma = 0.5d0\n real(8) :: k,c,w,keff,kinv,feff,dt,rvl\n real(8) :: b1, b2, b3, b4, b5, b6, b7, b8\n integer :: i,j,r\n\n if ( dt0*MPR > P ) then\n r = ceiling(MPR*dt0/P)\n dt = dt0/r\n else\n r = 1\n dt = dt0\n end if\n\n b1 = 1.d0/(beta*dt*dt)\n b2 = 1.d0/(beta*dt)\n b3 = 1.d0/(beta*2.0d0)-1.d0\n b4 = gamma/(beta*dt)\n b5 = gamma/beta-1.d0\n b6 = 0.5d0*dt*(gamma/beta-2.0d0)\n b7 = dt*(1.0d0-gamma)\n b8 = dt*gamma\n\n w = TWO_PI/P\n k = w**2.d0\n c = 2.0d0*zeta*w\n keff = k+b1+b4*c\n kinv = 1.0d0/keff\n\n ! initiation\n rl = 0.d0\n rc = 0.d0\n ra = 0.d0\n rv = 0.d0\n rd = 0.d0\n al = 0.d0\n\n ! computation of response\n do i = 1, n, 1\n\n ac = acc(i)\n da = (ac - al)/dble(r)\n\n do j = 1, r, 1\n ac = al + da*j\n feff = ac+(b1*rl(1)+b2*rl(2)+b3*rl(3))&\n +c*(b4*rl(1)+b5*rl(2)+b6*rl(3))\n rc(1) = feff*kinv\n rc(2) = b4*(rc(1)-rl(1))-b5*rl(2)-b6*rl(3)\n rc(3) = ac-k*rc(1)-c*rc(2)\n rl(1) = rc(1)\n rl(2) = rc(2)\n rl(3) = rc(3)\n end do\n\n ra(i) = -rc(3)+ac\n rv(i) = -rc(2)\n rd(i) = -rc(1)\n\n al = ac\n\n end do\n return\nend subroutine rnmk\n\nsubroutine ranmk(acc,n,dt0,zeta,P,ra) bind(c)\n\n integer, intent(in) :: n\n real(8), intent(in) :: dt0, zeta\n real(8), intent(in) :: acc(n), P\n real(8), intent(out) :: ra(n)\n\n real(8), allocatable :: rv(:), rd(:)\n\n allocate(rv(n))\n allocate(rd(n))\n\n call rnmk(acc,n,dt0,zeta,P,ra,rv,rd)\n\n deallocate(rv)\n deallocate(rd)\n\n return\nend subroutine ranmk\n\nsubroutine energy(acc,n,dt,zeta,P,ra,rv,rd,Ek,Ez,Es,Eh,Ein,ku) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: energy\n integer, intent(in) :: n\n real(8), intent(in) :: acc(n), ra(n), rv(n), rd(n), ku(n)\n real(8), intent(in) :: dt, zeta, P\n real(8), intent(out) :: Ek(n),Ez(n),Es(n),Eh(n),Ein(n)\n\n integer :: i\n real(8) :: w, fs(2), Ea, c, ddsub(2)\n\n w = TWO_PI/P\n c = 2.d0*zeta*w\n\n Ek(1) = rv(1)*rv(1)*0.5D0\n Ez(1) = 0.5D0*dt*(0.d0+c*rv(1)*rv(1))\n fs = [0.D0, -ra(1)-c*rv(1)]\n Ea = 0.5D0*dt*(0.d0+fs(2)*rv(1))\n Es(1) = fs(2)*fs(2)*0.5D0/(ku(1))\n Eh(1) = Ea - Es(1)\n Ein(1) = 0.5D0*dt*(0.d0-acc(1)*rv(1))\n! BL(1) = Ein(1) - Ek(1) - Ez(1) - Ea\n\n do i = 2, n, 1\n Ek(i) = rv(i)*rv(i)*0.5D0\n Ez(i) = Ez(i-1) + 0.5D0*dt*c*(rv(i-1)*rv(i-1)+rv(i)*rv(i))\n\n fs(1) = - ra(i-1) - c*rv(i-1)\n fs(2) = - ra(i) - c*rv(i)\n \n if (fs(1)*fs(2)<0.D0) then\n ddsub(1) = (0.D0-fs(1))/ku(i-1)\n ddsub(2) = fs(2)/ku(i)\n Ea = Ea + 0.5D0*ddsub(1)*(fs(1)+0.D0) + 0.5D0*ddsub(2)*(0.D0+fs(2))\n else\n Ea = Ea + 0.5D0*(rd(i)-rd(i-1))*(fs(1)+fs(2))\n end if\n \n !Ea = Ea + 0.5D0*(rd(i)-rd(i-1))*(fs(1)+fs(2))\n !Ea = Ea + 0.5D0*dt*(fs(1)*rv(i-1)+fs(2)*rv(i))\n Es(i) = fs(2)*fs(2)*0.5D0/(ku(i))\n Eh(i) = Ea - Es(i)\n\n Ein(i) = Ein(i-1) - 0.5D0*dt*(acc(i-1)*rv(i-1)+acc(i)*rv(i))\n! BL(i) = Ein(i) - Ek(i) - Ez(i) - Ea\n\n end do\nend subroutine energy\n\nsubroutine rfreq(acc,n,dt,zeta,P,ra,rv,rd) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: rfreq\n integer, intent(in) :: n\n real(C_DOUBLE), intent(in) :: dt, zeta, P\n real(C_DOUBLE), intent(in) :: acc(n)\n real(C_DOUBLE), intent(out) :: ra(n),rv(n),rd(n)\n\n real(C_DOUBLE), allocatable :: rac(:), rvc(:), rdc(:)\n complex(C_DOUBLE_COMPLEX), allocatable :: af(:), raf(:), rvf(:), rdf(:)\n real(C_DOUBLE), allocatable :: a0(:), w(:)\n integer :: i, j, Nfft\n complex(C_DOUBLE_COMPLEX) :: IONE=cmplx(0.d0,1.d0)\n real(C_DOUBLE) :: w0i2, w0iwj, wj2, iNfft, w0\n type(C_PTR) :: plan, iplan\n\n Nfft = nextpow2(n)*2\n iNfft = 1.d0/dble(Nfft)\n\n allocate(a0(Nfft))\n allocate(af(Nfft))\n allocate(rac(Nfft))\n allocate(rvc(Nfft))\n allocate(rdc(Nfft))\n allocate(raf(Nfft))\n allocate(rvf(Nfft))\n allocate(rdf(Nfft))\n allocate(w(Nfft))\n\n call fftfreqs(Nfft,1.d0/dt,w)\n w = w*TWO_PI\n w0 = TWO_PI/P\n\n a0 = 0.d0\n a0(1:n) = acc\n \n plan = fftw_plan_dft_r2c_1d(Nfft, a0, af, FFTW_ESTIMATE)\n iplan = fftw_plan_dft_c2r_1d(Nfft, af, rac, FFTW_ESTIMATE)\n call fftw_execute_dft_r2c(plan, a0, af)\n\n w0i2 = w0*w0\n do j = 1, Nfft/2+1, 1\n w0iwj = w0*w(j)\n wj2 = w(j)*w(j)\n raf(j) = af(j)*(w0i2+2.D0*zeta*w0iwj*IONE)/&\n (w0i2-wj2+2.d0*zeta*w0iwj*IONE)*iNfft\n rvf(j) = af(j)*(-w(j)*IONE/(w0i2-wj2+2.d0*zeta*w0iwj*IONE))*iNfft\n rdf(j) = af(j)*(-1.d0/(w0i2-wj2+2.d0*zeta*w0iwj*IONE))*iNfft\n end do\n \n call fftw_execute_dft_c2r(iplan, raf, rac)\n call fftw_execute_dft_c2r(iplan, rvf, rvc)\n call fftw_execute_dft_c2r(iplan, rdf, rdc)\n\n do i = 1, n, 1\n ra(i) = rac(i)\n rv(i) = rvc(i)\n rd(i) = rdc(i)\n end do\n\n call fftw_destroy_plan(plan)\n call fftw_destroy_plan(iplan)\n\n deallocate( a0)\n deallocate( af)\n deallocate(raf)\n deallocate(rvf)\n deallocate(rdf)\n deallocate(rac)\n deallocate(rvc)\n deallocate(rdc)\n deallocate( w)\n\n return\nend subroutine rfreq\n\nsubroutine rafreq(acc,n,dt,zeta,P,ra) bind(c)\n\n integer, intent(in) :: n\n real(C_DOUBLE), intent(in) :: dt, zeta, P\n real(C_DOUBLE), intent(in) :: acc(n)\n real(C_DOUBLE), intent(out) :: ra(n)\n\n complex(C_DOUBLE_COMPLEX), allocatable :: af(:), raf(:)\n real(C_DOUBLE), allocatable :: a0(:), w(:), rac(:)\n integer :: i, j, Nfft\n complex(C_DOUBLE_COMPLEX) :: IONE=cmplx(0.d0,1.d0)\n real(C_DOUBLE) :: w0i2, w0iwj, wj2, iNfft, w0\n type(C_PTR) :: plan, iplan\n\n Nfft = nextpow2(n)*2\n iNfft = 1.d0/dble(Nfft)\n \n allocate(rac(Nfft))\n allocate(a0(Nfft))\n allocate(af(Nfft))\n allocate(raf(Nfft))\n allocate(w(Nfft))\n \n call fftfreqs(Nfft,1.d0/dt,w)\n w = w*TWO_PI\n w0 = TWO_PI/P\n \n rac = 0.d0\n a0 = 0.d0\n a0(1:n) = acc\n \n plan = fftw_plan_dft_r2c_1d(Nfft, a0, af, FFTW_ESTIMATE)\n iplan = fftw_plan_dft_c2r_1d(Nfft, af, rac, FFTW_ESTIMATE)\n call fftw_execute_dft_r2c(plan, a0, af)\n \n w0i2 = w0*w0\n do j = 1, Nfft/2+1, 1\n w0iwj = w0*w(j)\n wj2 = w(j)*w(j)\n raf(j) = af(j)*(w0i2+2.D0*zeta*w0iwj*IONE)/&\n (w0i2-wj2+2.d0*zeta*w0iwj*IONE)*iNfft\n end do\n call fftw_execute_dft_c2r(iplan, raf, rac)\n ra = rac(1:n)\n \n call fftw_destroy_plan(plan)\n call fftw_destroy_plan(iplan)\n \n deallocate(rac)\n deallocate( a0)\n deallocate( af)\n deallocate(raf)\n deallocate( w)\n\n return\n \nend subroutine rafreq\n\nsubroutine rmixed(acc,n,dt,zeta,P,ra,rv,rd) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: rmixed\n integer, intent(in) :: n\n real(C_DOUBLE), intent(in) :: dt, zeta, P\n real(C_DOUBLE), intent(in) :: acc(n)\n real(C_DOUBLE), intent(out) :: ra(n),rv(n),rd(n)\n\n if (Ptol .or. merror>3.0d0*tol) .and. iter<=mit )\n\n j = IPf2\n do i = 2, nP-1, 1\n p0 = p(i)\n t = dt*SPI(i)-dt\n dp = min(p0-P(i-1),P(i+1)-p0)\n\n do while ( Pf(j)IPf1)\n pe0 = Pf(j)\n phi = atan2(aimag(af(j)),real(af(j)))\n ra = rsimple(pe0,p0,phi,t,zeta)\n if ( sign(1.d0,ra)*sign(1.d0,SPA(i)) < 0.d0) then\n Rf(j) = 1.d0/Rf(j)\n end if\n j = j - 1\n end do\n end do\n\n af(IPf1:IPf2) = af(IPf1:IPf2)*Rf(IPf1:IPf2)\n afs = af\n call fftw_execute_dft_c2r(iplan, afs, a0)\n a = a0(1:n)*iNfft\n\n call adjustpeak(a,n,peak0)\n ! call adjustbaseline(a,n,dt)\n ! call adjustpeak(a,n,peak0)\n\n call spamixed(a,n,dt,zeta,P,nP,SPA,SPI)\n call error(abs(SPA),SPAT,nP,aerror,merror)\n R = SPAT/abs(SPA)\n call decrlininterp(P,R,nP,Pf(IPf1:IPf2),Rf(IPf1:IPf2),NPf)\n ! write(unit=*, fmt=\"(A11,I4,A14,2F8.4)\") \"Error After\",iter,\" Iterations: \",aerror,merror\n iter = iter + 1\n if (aerror < minerr) then\n minerr = aerror\n best = a*1.D0\n end if\n end do\n\n if (kpb>0) a = best*1.D0\n\n call fftw_destroy_plan(plan)\n call fftw_destroy_plan(iplan)\n\n deallocate(best)\n deallocate(SPA)\n deallocate(R)\n deallocate(Pf)\n deallocate(Rf)\n deallocate(SPI)\n deallocate(a0)\n deallocate(af)\n deallocate(afs)\n deallocate(f)\n\nend subroutine fitspectra\n\nsubroutine adjustpeak(a,n,peak0) bind(c)\n integer, intent(in) :: n\n real(C_DOUBLE), intent(inout) :: a(n)\n real(C_DOUBLE), intent(in) :: peak0\n\n integer :: pk, i\n real(C_DOUBLE) :: peak\n \n pk = 0\n peak = 0.D0\n\n do i = 1, n, 1\n if ( abs(a(i))>peak ) then\n peak = a(i)\n pk = i\n end if\n if ( a(i)>peak0 ) then\n a(i) = peak0\n elseif ( a(i)<-peak0 ) then\n a(i) = -peak0\n end if\n end do\n\n if ( peaktol .or. merror>3.0d0*tol) .and. iter<=mit )\n\n dR = SPA*(SPAT/abs(SPA)-1.d0)/SPAT\n\n !$OMP PARALLEL DO DEFAULT(SHARED), PRIVATE(i)\n do i = 1, nP, 1\n call wfunc( n,dt,SPI(i),P(i),zeta,W(:,i) )\n end do\n !$OMP END PARALLEL DO\n\n !$OMP PARALLEL DO DEFAULT(SHARED), PRIVATE(i, j)\n do i = 1, nP, 1\n do j = 1, nP, 1\n call ramixed(W(:,j),n,dt,zeta,P(i),ra(:,i,j))\n M(i,j) = ra(SPI(i),i,j)/SPAT(i)\n if ( i /= j ) then\n M(i,j) = M(i,j)*0.618D0\n end if\n end do\n end do\n !$OMP END PARALLEL DO\n\n call leastsqs(M,dR,nP,nP)\n\n do i = 1, nP, 1\n a = a + dR(i)*W(:,i)\n end do\n \n call adjustpeak(a,n,peak0)\n ! call adjustbaseline(a,n,dt)\n ! call adjustpeak(a,n,peak0)\n\n SPIp = SPI\n call spamixed(a,n,dt,zeta,P,nP,SPA,SPI)\n call errora(abs(SPA),SPAT,nP,aerror,merror)\n if (aerror0) a = best*1.D0\n\n deallocate(best)\n deallocate(SPA)\n deallocate(dR)\n deallocate(SPI)\n deallocate(SPIp)\n deallocate(ra)\n deallocate(M)\n deallocate(W)\nend subroutine adjustspectra\n\nsubroutine flat_double(A,n,m,af)\n\n integer, intent(in) :: n, m\n real(8), intent(in) :: A(n,m)\n real(8), intent(out) :: af(n*m)\n\n integer :: i, j\n\n do i = 1, n, 1\n do j = 1, m, 1\n af(n*(j-1)+i) = A(i,j)\n end do\n end do\n\nend subroutine flat_double\n\nsubroutine flat_int(A,n,m,af)\n\n integer, intent(in) :: n, m\n integer, intent(in) :: A(n,m)\n integer, intent(out) :: af(n*m)\n\n integer :: i, j\n\n do i = 1, n, 1\n do j = 1, m, 1\n af(n*(j-1)+i) = A(i,j)\n end do\n end do\n\nend subroutine flat_int\n\nsubroutine repeat_double(a,n,m,Ar)\n integer, intent(in) :: n,m\n real(8), intent(in) :: a(n)\n real(8), intent(out) :: Ar(n*m)\n\n integer :: i\n\n do i = 1, m, 1\n Ar((i-1)*n+1:(i-1)*n+n) = a\n end do\n \nend subroutine repeat_double\n\nsubroutine adjustspectra_endur(acc,n,dt,zeta,P,nP,DI,nD,SPAT0,a,tol,mit,kpb) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: adjustspectra_endur\n integer, intent(in) :: n, nP, mit, kpb, nD\n integer, intent(in) :: DI(nD)\n real(8), intent(in) :: dt, zeta, tol\n real(8), intent(in) :: acc(n), P(nP), SPAT0(nP)\n real(8), intent(out) :: a(n)\n\n real(8), allocatable :: SPA1(:), SPAT1(:), dR1(:), P1(:)\n real(8), allocatable :: SPA(:,:), dR(:,:), ra(:,:,:), best(:)\n real(8), allocatable :: M(:,:), W(:,:), SPAT(:,:)\n integer, allocatable :: SPI(:,:), SPI1(:)\n\n real(8) :: aerror, merror, peak0, minerr\n integer :: i,j,iter,nT\n\n nT = nP*nD\n\n allocate(best(n))\n allocate(SPA(nP,nD))\n allocate(SPAT(nP,nD))\n allocate(SPA1(nT))\n allocate(SPAT1(nT))\n allocate(dR(nP,nD))\n allocate(dR1(nT))\n allocate(SPI(nP,nD))\n allocate(SPI1(nT))\n allocate(P1(nT))\n allocate(ra(n,nT,nT))\n allocate(M(nT,nT))\n allocate(W(n,nT))\n\n call repeat_double(P,nP,nD,P1)\n\n peak0 = maxval(abs(acc), dim=1)\n a = acc\n\n do i = 1, nD, 1\n SPAT(:,i) = SPAT0*dble(DI(i))/dble(n)\n P1((i-1)*nP+1:(i-1)*nP+nP) = P\n end do\n \n call flat_double(SPAT,nP,nD,SPAT1)\n\n iter = 1\n\n call spamixed_endur(acc,n,dt,zeta,P,nP,DI,nD,SPA,SPI)\n call errora_endur(abs(SPA),SPAT,nP,nD,aerror,merror)\n\n if (aerror <= tol .and. merror<=3.0d0*tol) return\n !write(unit=*, fmt=\"(A29,2F8.4)\") \"Initial Error: \",aerror,merror\n minerr = aerror\n best = a\n\n do while ( (aerror>tol .or. merror>3.0d0*tol) .and. iter<=mit )\n\n dR = SPA*(SPAT/abs(SPA)-1.d0)!/SPAT\n\n call flat_double(dR,nP,nD,dR1)\n call flat_double(SPA,nP,nD,SPA1)\n call flat_int(SPI,nP,nD,SPI1)\n\n !$OMP PARALLEL DO DEFAULT(SHARED), PRIVATE(i)\n do i = 1, nT, 1\n call wfunc( n,dt,SPI1(i),P1(i),zeta,W(:,i) )\n end do\n !$OMP END PARALLEL DO\n\n !$OMP PARALLEL DO DEFAULT(SHARED), PRIVATE(i, j)\n do i = 1, nT, 1\n do j = 1, nT, 1\n call ramixed(W(:,j),n,dt,zeta,P1(i),ra(:,i,j))\n M(i,j) = ra(SPI1(i),i,j)!/SPAT1(i)\n if ( i /= j ) then\n M(i,j) = M(i,j)*0.7D0\n end if\n end do\n end do\n !$OMP END PARALLEL DO\n\n call leastsqs(M,dR1,nT,nT)\n\n do i = 1, nT, 1\n a = a + dR1(i)*W(:,i)\n end do\n\n ! call adjustpeak(a,n,peak0)\n ! call adjustbaseline(a,n,dt)\n ! call adjustpeak(a,n,peak0)\n\n call spamixed_endur(a,n,dt,zeta,P,nP,DI,nD,SPA,SPI)\n call errora_endur(abs(SPA),SPAT,nP,nD,aerror,merror)\n\n if (aerror0) a = best\n\n deallocate(best)\n deallocate(SPA)\n deallocate(SPAT)\n deallocate(SPA1)\n deallocate(dR)\n deallocate(dR1)\n deallocate(SPI)\n deallocate(ra)\n deallocate(M)\n deallocate(W)\n \nend subroutine adjustspectra_endur\n\nsubroutine adjustspectra_md(acc,n,dt,zeta,P,nP,nD,SPAT,nT,a,tol,mit,kpb) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: adjustspectra_md\n integer, intent(in) :: n, nP, mit, kpb, nD, nT\n real(8), intent(in) :: dt, zeta(nD), tol\n real(8), intent(in) :: acc(n), P(nP), SPAT(nT)\n real(8), intent(out) :: a(n)\n\n real(8), allocatable :: SPA1(:), SPAT1(:), dR1(:), P1(:), zeta1(:)\n real(8), allocatable :: SPA(:,:), dR(:,:), ra(:,:,:), best(:)\n real(8), allocatable :: M(:,:), W(:,:)\n integer, allocatable :: SPI(:,:), SPI1(:)\n\n real(8) :: aerror, merror, peak0, minerr\n integer :: i,j,iter,k\n\n allocate(best(n))\n allocate(SPA(nP,nD))\n allocate(SPA1(nT))\n allocate(SPAT1(nT))\n allocate(dR(nP,nD))\n allocate(dR1(nT))\n allocate(SPI(nP,nD))\n allocate(SPI1(nT))\n allocate(P1(nT))\n allocate(zeta1(nT))\n allocate(ra(n,nT,nT))\n allocate(M(nT,nT))\n allocate(W(n,nT))\n\n call repeat_double(P,nP,nD,P1)\n\n peak0 = maxval(abs(acc), dim=1)\n a = acc\n\n do i = 1, nD, 1\n P1((i-1)*nP+1:(i-1)*nP+nP) = P\n zeta1((i-1)*nP+1:(i-1)*nP+nP) = zeta(i)\n end do\n \n SPAT1 = SPAT\n \n iter = 1\n \n call spamixed_md(acc,n,dt,zeta,P,nP,nD,SPA,SPI)\n call flat_double(SPA,nP,nD,SPA1)\n call errora(abs(SPA1),SPAT1,nT,aerror,merror)\n \n if (aerror <= tol .and. merror<=3.0d0*tol) return\n !write(unit=*, fmt=\"(A29,2F8.4)\") \"Initial Error: \",aerror,merror\n minerr = aerror\n best = a\n \n do while ( (aerror>tol .or. merror>3.0d0*tol) .and. iter<=mit )\n \n !call flat_double(dR,nP,nD,dR1)\n call flat_double(SPA,nP,nD,SPA1)\n call flat_int(SPI,nP,nD,SPI1)\n \n dR1 = SPA1*(SPAT1/abs(SPA1)-1.d0)!/SPAT\n \n !$OMP PARALLEL DO DEFAULT(SHARED), PRIVATE(i, j)\n do i = 1, nT, 1\n call wfunc( n,dt,SPI1(i),P1(i),zeta1(i),W(:,i) )\n end do\n !$OMP END PARALLEL DO\n \n !$OMP PARALLEL DO DEFAULT(SHARED), PRIVATE(i, j)\n do i = 1, nT, 1\n do j = 1, nT, 1\n call ramixed(W(:,j),n,dt,zeta1(i),P1(i),ra(:,i,j))\n M(i,j) = ra(SPI1(i),i,j)!/SPAT1(i)\n if ( i /= j ) then\n M(i,j) = M(i,j)*0.7D0\n end if\n end do\n end do\n !$OMP END PARALLEL DO\n \n call leastsqs(M,dR1,nT,nT)\n \n do i = 1, nT, 1\n a = a + dR1(i)*W(:,i)\n end do\n \n call adjustpeak(a,n,peak0)\n ! call adjustbaseline(a,n,dt)\n ! call adjustpeak(a,n,peak0)\n \n call spamixed_md(a,n,dt,zeta,P,nP,nD,SPA,SPI)\n call flat_double(SPA,nP,nD,SPA1)\n call errora(abs(SPA1),SPAT1,nT,aerror,merror)\n \n if (aerror0) a = best\n\n deallocate(best)\n deallocate(SPA)\n deallocate(SPA1)\n deallocate(dR)\n deallocate(dR1)\n deallocate(SPI)\n deallocate(SPI1)\n deallocate(P1)\n deallocate(zeta1)\n deallocate(ra)\n deallocate(M)\n deallocate(W)\n \nend subroutine adjustspectra_md\n\nsubroutine wfunc(n,dt,itm,P,zeta,wf) bind(c)\n\n integer, intent(in) :: n, itm\n real(8), intent(in) :: dt, P, zeta\n real(8), intent(out) :: wf(n)\n\n real(8) :: tm, w, f, tmp1, gamma, deltaT\n real(8), allocatable :: tmp2(:)\n integer :: i\n\n allocate(tmp2(n))\n\n tm = dble(itm-1)*dt\n w = TWO_PI/P\n f = 1.d0/P\n\n tmp1 = sqrt(1.d0-zeta**2)\n gamma = 1.178d0*(f*tmp1)**(-0.93d0)\n deltaT = atan(tmp1/zeta)/(w*tmp1)\n\n tmp2 = [ ( ( dble(i-1)*dt-tm+deltaT ),i=1,n ) ]\n\n wf = cos(w*tmp1*tmp2)*exp(-(tmp2/gamma)**2)\n\n deallocate(tmp2)\n\n return\nend subroutine wfunc\n\nfunction rsimple(pe0,p0,phi,t,zeta) bind(c)\n\n real(C_DOUBLE), intent(in) :: pe0,p0,phi,t,zeta\n real(C_DOUBLE) :: rsimple\n\n real(C_DOUBLE) :: we, w\n real(C_DOUBLE) :: we2, w2, zeta2\n real(C_DOUBLE) :: we3, w3, zeta3\n real(C_DOUBLE) :: we4, w4, zeta4\n real(C_DOUBLE) :: sinphi, cosphi\n real(C_DOUBLE) :: two = 2.d0, three = 3.d0, four = 4.d0\n real(C_DOUBLE) :: eight = 8.d0, ten = 1.d1, twelve = 12.d0\n\n we = TWO_PI/pe0\n w = TWO_PI/p0\n we2 = we*we\n w2 = w*w\n we3 = we2*we\n w3 = w2*w\n we4 = we3*we\n w4 = w3*w\n\n zeta2 = zeta*zeta\n zeta3 = zeta2*zeta\n zeta4 = zeta3*zeta\n\n sinphi = sin(phi)\n cosphi = cos(phi)\n\n rsimple = cos(we*t+phi) - exp(-w*zeta*t)*((four*w*we3*zeta &\n -four*w*we3*zeta3)*exp(w*zeta*t)*sin(we*t+phi)+((two*we4 &\n -two*w2*we2)*zeta2-two*we4+two*w2*we2)*exp(w*zeta*t)*cos(we*t &\n +phi)+sqrt(four*w2-four*w2*zeta2)*(four*cosphi*w*we2*zeta3 &\n +two*sinphi*we3*zeta2+(cosphi*w3-three*cosphi*w*we2) &\n *zeta-sinphi*we3+sinphi*w2*we)*sin(sqrt(four*w2-four*w2 &\n *zeta2)*t/two)+(eight*cosphi*w2*we2*zeta4+four*sinphi*w &\n *we3*zeta3+(two*cosphi*w4-ten*cosphi*w2*we2)*zeta2-four &\n *sinphi*w*we3*zeta+two*cosphi*w2*we2-two*cosphi*w4) &\n *cos(sqrt(four*w2-four*w2*zeta2)*t/two))/(eight*w2*we2*zeta4 &\n +(two*we4-twelve*w2*we2+two*w4)*zeta2-two*we4+four*w2*we2 &\n -two*w4)\nend function rsimple\n\nsubroutine rnmknl(acc,n,dt0,zeta,P,ra,rv,rd,ku,model,tol,maxiter) bind(c)\n !\n ! SUBROUTINE FOR COMPUTATION OF RESPONSE OF SDOF UNDER EARTHQUAKE\n ! acc ----- GROUND ACC\n ! N ----- LENGTH OF acc\n ! DEL ----- ORIGINAL TIME INTERVAL\n ! zeta ---- DAMPING RATIO\n ! PARA ---- (/K0,FY,K1,XP,FP,KP,FEFF,KEFF/)\n ! K0 -- initial stiffness\n ! FY -- yielding force\n ! K1 -- post-yielding stiffness\n ! XP -- commited displacement of last step\n ! FP -- commited force of last step\n ! KP -- commited stiffness of last step\n ! FEFF -- right-hand-side \"force\" of the equivalent static balance equation\n ! KEFF -- left-hand-side \"stiffness\" of the equivalent static balance equation\n\n integer, intent(in) :: n\n real(8), intent(in) :: dt0, zeta, tol\n real(8), intent(in) :: acc(n), P\n real(8), intent(out) :: ra(n),rv(n),rd(n),ku(n)\n integer, intent(in) :: maxiter, model\n\n real(8) :: rc(3),rl(3),ac,al,da,x\n real(8) :: k,c,w,feff,keff,beta,gamma,dt\n real(8) :: b1, b2, b3, b4, b5, b6, b7, b8\n integer :: i,j,r\n\n if ( dt0*MPR > P ) then\n r = ceiling(MPR*dt0/P)\n dt = dt0/r\n else\n r = 1\n dt = dt0\n end if\n\n beta = 1.d0/4.d0\n gamma = 0.5d0\n\n b1 = 1.d0/(beta*dt*dt)\n b2 = 1.d0/(beta*dt)\n b3 = 1.d0/(beta*2.0d0)-1.d0\n b4 = gamma/(beta*dt)\n b5 = gamma/beta-1.d0\n b6 = 0.5d0*dt*(gamma/beta-2.0d0)\n b7 = dt*(1.0d0-gamma)\n b8 = dt*gamma\n\n w = 6.283185307179586d0/p\n k = w*w\n c = 2.0d0*zeta*w\n keff = b1+b4*c\n\n ! INITIATION\n para(8) = keff\n rl = [0.0d0,0.0d0,0.0d0]\n rc = [0.0d0,0.0d0,0.0d0]\n para(4:6) = [rl(1),0.0d0,k]\n al = 0.d0\n\n ! COMPUTATION OF RESPONSE\n do i = 1,n,1\n \n ac = acc(i)\n da = (ac - al)/dble(r)\n\n do j = 1, r, 1\n ac = al + da*j\n \n feff = ac+(b1*rl(1)+b2*rl(2)+b3*rl(3))&\n +c*(b4*rl(1)+b5*rl(2)+b6*rl(3))\n call solve_balance_equation(x,feff,model,tol,maxiter)\n\n rc(1) = x\n rc(2) = b4*(rc(1)-rl(1))-b5*rl(2)-b6*rl(3)\n rc(3) = ac-para(5)-c*rc(2)\n\n rl(1) = rc(1)\n rl(2) = rc(2)\n rl(3) = rc(3)\n end do\n\n ku(i) = para(13)\n ra(i) = -rc(3)+ac\n rv(i) = -rc(2)\n rd(i) = -rc(1)\n\n al = ac\n end do\n return\nend subroutine rnmknl\n\nsubroutine newmark_nl(acc,n,dt0,zeta,P,SPA,SPI,SPV,SPD,SPE,model,tol,maxiter) bind(c)\n ! SUBROUTINE FOR COMPUTATION OF RESPONSE OF SDOF UNDER EARTHQUAKE\n ! acc ----- GROUND ACC\n ! N ----- LENGTH OF acc\n ! DEL ----- ORIGINAL TIME INTERVAL\n ! zeta ---- DAMPING RATIO\n ! PARA ---- (/K0,FY,K1,XP,FP,KP,FEFF,KEFF/)\n ! K0 -- initial stiffness\n ! FY -- yielding force\n ! K1 -- post-yielding stiffness\n ! XP -- commited displacement of last step\n ! FP -- commited force of last step\n ! KP -- commited stiffness of last step\n ! FEFF -- right-hand-side \"force\" of the equivalent static balance equation\n ! KEFF -- left-hand-side \"stiffness\" of the equivalent static balance equation\n\n integer, intent(in) :: n\n real(8), intent(in) :: dt0, zeta, tol\n real(8), intent(in) :: acc(n), P\n real(8), intent(out) :: SPA,SPV,SPD,SPE\n integer, intent(out) :: SPI\n integer, intent(in) :: maxiter, model\n\n real(8) :: rc(3),rl(3),ac,al,da,x,aa,rvl,ein\n real(8) :: k,c,w,feff,keff,beta,gamma,dt\n real(8) :: b1, b2, b3, b4, b5, b6, b7, b8\n integer :: i,j,r\n\n\n if ( dt0*MPR > P ) then\n r = ceiling(MPR*dt0/P)\n dt = dt0/r\n else\n r = 1\n dt = dt0\n end if\n\n beta = 1.d0/4.d0\n gamma = 0.5d0\n\n b1 = 1.d0/(beta*dt*dt)\n b2 = 1.d0/(beta*dt)\n b3 = 1.d0/(beta*2.0d0)-1.d0\n b4 = gamma/(beta*dt)\n b5 = gamma/beta-1.d0\n b6 = 0.5d0*dt*(gamma/beta-2.0d0)\n b7 = dt*(1.0d0-gamma)\n b8 = dt*gamma\n\n w = 6.283185307179586d0/p\n k = w*w\n c = 2.0d0*zeta*w\n keff = b1+b4*c\n\n ! INITIATION\n para(8) = keff\n rl = [0.0d0,0.0d0,0.0d0]\n rc = [0.0d0,0.0d0,0.0d0]\n para(4:6) = [ rl(1),0.0d0,k ]\n al = 0.d0\n rvl = 0.d0\n\n SPA = 0.d0\n SPV = 0.d0\n SPD = 0.d0\n SPE = 0.d0\n SPI = 0\n\n ! COMPUTATION OF RESPONSE\n do i = 1,n,1\n \n ac = acc(i)\n da = (ac - al)/dble(r)\n\n do j = 1, r, 1\n ac = al + da*j\n \n feff = ac+(b1*rl(1)+b2*rl(2)+b3*rl(3))&\n +c*(b4*rl(1)+b5*rl(2)+b6*rl(3))\n call solve_balance_equation(x,feff,model,tol,maxiter)\n\n rc(1) = x\n rc(2) = b4*(rc(1)-rl(1))-b5*rl(2)-b6*rl(3)\n rc(3) = ac-para(5)-c*rc(2)\n\n rl(1) = rc(1)\n rl(2) = rc(2)\n rl(3) = rc(3)\n end do\n\n SPE = SPE+0.5d0*dt0*(rvl*al+rc(2)*ac)\n aa = -rc(3)+ac\n\n if (abs(aa) > abs(SPA)) then\n SPA=aa\n SPI=i\n endif\n\n if (abs(rc(2)) > abs(SPV)) then\n SPV=rc(2)\n endif\n\n if (abs(rc(1)) > abs(SPD)) then\n SPD=rc(1)\n endif\n\n al = ac\n rvl = rc(2)\n\n end do\n\n SPE = sqrt(2.d0*SPE)\n\n return\nend subroutine newmark_nl\n\nsubroutine solve_balance_equation(x,feff,model,tol,maxiter) bind(c)\n\n integer, intent(in) :: maxiter, model\n real(8), intent(in) :: feff, tol\n real(8), intent(out) :: x\n\n real(8) :: x0, fval, kc\n\n ! 估计变形值\n x0 = para(4)+(feff-para(7))/(para(6)+para(8))\n ! 施加荷载\n para(7) = feff\n ! 迭代求解变形\n call newton(x,x0,tol,maxiter,model)\n ! 更新状态变量(para(4:6))\n call balance_func(fval,kc,x,model,.true.)\n\n return\nend subroutine solve_balance_equation\n\nsubroutine newton(x,x0,tol,maxiter,model) bind(c)\n ! 牛顿-拉普森法求解非线性方程\n ! 输入参数:\n ! x0 : 解的初始估计值\n ! tol : 收敛容差(相对)\n ! maxiter : 最大迭代次数\n ! para : 一维数组, 包含非线性参数及历史状态变量, len(para)=np\n ! 输出:\n ! x : 方程的解\n\n integer, intent(in) :: maxiter,model\n real(8), intent(out) :: x0,x\n real(8), intent(in) :: tol\n \n real(8) :: fval, kc\n integer :: iter\n integer :: status\n\n ! newton-rapheson method\n\n kc = 0.0d0\n fval = 0.0d0\n x = x0\n do iter = 1,maxiter,1\n\n call balance_func(fval,kc,x,model,.false.)\n\n if (kc .ne. 0.d0) then\n x = x0 - fval/kc\n if (abs(x - x0) < tol) then\n exit\n endif\n x0 = x\n else\n write(*,*) \"Derivative was zero. Stop the Iteration.\"\n x = x0\n exit\n endif\n\n end do\nend subroutine newton\n\nsubroutine balance_func(fval,kc,x,model,update) bind(c)\n! 已知X, 计算方程F(X)=0中F(X)的值及F'(X)的值KC\n! 输入参数:\n! X ---- 变形值\n! PARA,NP ---- 一维数组, 包含非线性参数及历史状态变量,\n! LEN(PARA)=NP\n! MODEL ---- 非线性滞回模型\n! 0 ---- 双线性(DEFAULT)\n! 1 ---- 无残余变形双线性(卸载指向原点)\n! 2 ---- CLOUGH 退化双线性\n! 3 ---- 武田 退化三线性\n! 输入结果:\n! FVAL ---- 平衡力残差\n! KC ---- 当前变形对应的刚度值(切线斜率)\n!\n integer, intent(in) :: model\n real(8), intent(in) :: x\n logical, intent(in) :: update\n real(8), intent(out) :: fval, kc\n\n real(8) :: k0,fy,k1,xp,fp,kp,feff,dx,f,f_try,bup,bdn,uy\n real(8) :: alpha, dxp, xpeak, xmax, xmin, fmax, fmin, ku\n real(8) :: xu, k2, lpx, lpf, lux, luf, xl, xr, fl, fr\n integer :: status\n\n k0 = para(1)\n fy = para(2)\n k1 = para(3)\n\n xp = para(4)\n fp = para(5)\n kp = para(6)\n\n feff = para(7)\n\n alpha = para(9)\n dxp = para(12)\n ku = para(13)\n lpx = para(14)\n xmax = para(15)\n xmin = para(16)\n lpf = para(22)\n fmax = para(23)\n fmin = para(24)\n \n lux = para(29)\n luf = para(30)\n \n status = int(para(npara))\n \n uy = fy/k0\n dx = x-xp\n\n select case (model)\n case (1)\n if ( dx == 0.D0 ) then\n kc = kp\n f = fp\n elseif ( x == 0.D0 ) then\n f = 0.D0\n if ( dx > 0.D0 ) then\n ku = fmax/xmax\n else\n ku = fmin/xmin\n kc = ku\n end if\n else\n if ( x>0.D0 ) then\n if ( x <= xmax ) then\n ku = fmax/xmax\n f = ku*x\n kc = ku\n else\n kc = k1\n xmax = x\n f = fy + k1*(x-uy)\n fmax = f\n ku = fmax/xmax\n end if\n else\n if ( x >= xmin ) then\n ku = fmin/xmin\n f = ku*x\n kc = ku\n else\n kc = k1\n xmin = x\n f = -fy + k1*(x+uy)\n fmin = f\n ku = fmin/xmin\n end if\n end if\n end if\n case (2)\n if ( dx == 0.D0 ) then\n kc = kp\n f = fp\n else\n if ( status /= 0 .and. dx*dxp < 0.D0 ) then\n lux = xp\n luf = fp\n end if\n\n if ( x > xmax) then\n f = fy + ( x - uy ) * k1\n kc = k1\n status = 1\n xmax = x\n fmax = f\n ku = k0*(uy/xmax)**alpha\n lpx = x\n lpf = f\n lux = x\n luf = f\n elseif ( x < xmin) then\n f = -fy + ( x + uy ) * k1\n kc = k1\n status = 1\n xmin = x\n fmin = f\n ku = k0*(-uy/xmin)**alpha\n lpx = x\n lpf = f\n lux = x\n luf = f\n else if (status == 0) then\n ku = kp\n xu = lux - luf/ku\n\n if ( xu < lux ) then\n xl = xu\n xr = lux\n fl = 0.D0\n fr = luf\n else\n xl = lux\n xr = xu\n fl = luf\n fr = 0.D0\n end if\n\n if ( x >= xl .and. x<=xr ) then\n kc = ku\n f = kc*(x - xu)\n else if ( x > xr ) then\n if (abs(xmax - xr) < 1.0D-12) then\n k2 = kp\n else\n k2 = (fmax - fr)/(xmax - xr)\n end if\n kc = k2\n f = fr + kc*(x - xr)\n status = 2\n else\n if (abs(xmin - xl) < 1.0D-12) then\n k2 = kp\n else\n k2 = (fmin - fl)/(xmin - xl)\n end if\n kc = k2\n f = fl + kc*(x - xl)\n status = 2\n end if\n else if (status == 1) then\n if ( xp > 0.D0 ) then\n ku = k0*(uy/xmax)**alpha\n xu = xmax - fmax/ku\n\n if ( x >= xu ) then\n kc = ku\n f = kc*(x - xu)\n status = 0\n else\n k2 = fmin/(xmin - xu)\n kc = k2\n f = kc*(x - xu)\n status = 2\n end if\n\n !lux = xp\n !luf = fp\n else\n ku = k0*(-uy/xmin)**alpha\n xu = xmin - fmin/ku\n\n if ( x <= xu ) then\n kc = ku\n f = kc*(x - xu)\n status = 0\n else\n k2 = fmax/(xmax - xu)\n kc = k2\n f = kc*(x - xu)\n status = 2\n end if\n\n !lux = xp\n !luf = fp\n end if\n else if (status == 2) then\n if ( luf > 0.D0 ) then\n ku = k0*(uy/xmax)**alpha\n else\n ku = k0*(-uy/xmin)**alpha\n end if\n if ( dx*dxp > 0.D0 ) then\n kc = kp\n f = fp + kc*dx\n else\n kc = ku\n xu = lux - luf/ku\n f = kc*(x - xu)\n status = 0\n\n !lux = xp\n !luf = fp\n end if\n end if\n end if\n case default\n f_try = fp+dx*kp\n bup = fy+k1*(x-uy)\n bdn = -fy+k1*(x+uy)\n if ( dx == 0.D0 ) then\n kc = kp\n f = fp\n elseif (status == 0) then\n if (dx > 0.D0) then\n if ( f_try > bup ) then\n f = bup\n kc = k1\n status = 1\n else\n kc = k0\n f = f_try\n end if\n else\n if ( f_try < bdn ) then\n f = bdn\n kc = k1\n status = 1\n else\n kc = k0\n f = f_try\n end if\n end if\n elseif (status == 1) then\n if (dxp*dx>0) then\n f = f_try\n kc = k1\n else\n kc = k0\n f = fp + kc*dx\n status = 0\n if (f > bup) then\n f = bup\n kc = k1\n status = 1\n elseif (f < bdn) then\n f = bdn\n kc = k1\n status = 1\n end if\n end if\n end if\n end select\n \n ! 迭代求解收敛时更新历史变量\n if (update) then\n para(4) = x\n para(5) = f\n para(6) = kc\n para(12) = dx\n para(13) = ku\n para(14) = lpx\n para(15) = xmax\n para(16) = xmin\n para(22) = lpf\n para(23) = fmax\n para(24) = fmin\n para(29) = lux\n para(30) = luf\n para(npara) = dble(status)\n end if\n\n kc = kc+para(8)\n fval = f+para(8)*x-feff\n \n return\nend subroutine balance_func\n\nsubroutine spmu(acc,n,dt,zeta,P,nP,SPA,SPI,SPV,SPD,SPE,mu,model,uy,rk,alpha) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: spmu\n integer, intent(in) :: n, nP, model\n real(8), intent(in) :: mu, dt, zeta, P(nP), rk, alpha\n real(8), intent(in) :: acc(n)\n real(8), intent(out) :: SPA(nP), SPV(nP), SPD(nP), SPE(nP)\n integer, intent(out) :: SPI(nP)\n real(8), intent(out) :: uy(nP)\n\n real(8) :: w, k0, k1, fy, mu1, pkd, tol, rtol\n integer :: i, j, pki, maxiter\n \n maxiter = 1000\n rtol = 1.D-9\n\n !!$OMP PARALLEL DO PRIVATE(i,j,para,tol,mu1,w,k0,k1,fy)\n do i = 1, nP, 1\n call newmark(acc,n,dt,zeta,P(i),SPA(i),SPI(i),SPV(i),SPD(i),SPE(i))\n uy(i) = abs(SPD(i))/mu\n tol = rtol*abs(SPD(i))\n\n w = TWO_PI/P(i)\n k0 = w*w\n k1 = k0*rk\n fy = k0*uy(i)\n para = 0.D0 ! 非线性参数及历史变量清零\n para(1:3) = [ k0,fy,k1 ]\n para(6) = k0\n para(9) = alpha\n para(13) = k0\n para(15:16) = [ uy,-uy ]\n para(23:24) = [ fy,-fy ]\n\n do j = 1, 1000, 1\n call newmark_nl(acc,n,dt,zeta,P(i),SPA(i),SPI(i),SPV(i),SPD(i),SPE(i),model,tol,maxiter)\n mu1 = abs(SPD(i))/uy(i)\n\n if (abs(mu1-mu)<1.D-2) exit\n\n uy(i) = uy(i)*(mu1/mu)**0.5\n fy = k0*uy(i)\n para(2) = fy\n para(4:NPARA) = 0.D0\n para(6) = k0\n para(9) = alpha\n para(13) = k0\n para(15:16) = [ uy,-uy ]\n para(23:24) = [ fy,-fy ]\n end do\n\n SPA(i) = abs(SPA(i))\n SPV(i) = abs(SPV(i))\n SPD(i) = abs(SPD(i))\n end do\n !!$OMP END PARALLEL DO\n\n return\n \nend subroutine spmu\n\nsubroutine rnl(acc,n,dt,zeta,P,ra,rv,rd,ku,SM,cp) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: rnl\n integer, intent(in) :: n, SM\n real(8), intent(in) :: dt, zeta\n real(8), intent(inout) :: cp(8)\n real(8), intent(in) :: acc(n), P\n real(8), intent(out) :: ra(n),rv(n),rd(n),ku(n)\n\n integer :: i, model, maxiter\n real(8) :: w, k0, fy, uy, rk, k1, mu, muc, alpha\n real(8) :: pkd, pkf, tol\n\n mu = cp(1)\n rk = cp(2)\n alpha = cp(3)\n \n model = int(cp(8))\n\n maxiter = 1000\n tol = 1.D-9\n\n w = TWO_PI/P\n k0 = w*w\n k1 = k0*rk\n\n call r(acc,n,dt,zeta,P,ra,rv,rd,ku,2)\n pkd = abs(peak(rd,n))\n uy = pkd/mu\n pkf = pkd*k0\n para = 0.D0\n ! para(9) = alpha\n\n ! SM = 0 用迭代的方法求解目标延性下的响应\n if ( SM == 0 ) then\n fy = k0*uy\n para(1:3) = [ k0,fy,k1 ]\n para(6) = k0\n para(9) = alpha\n para(13) = k0\n para(15:16) = [ uy,-uy ]\n para(23:24) = [ fy,-fy ]\n do i = 1, 1000, 1\n call rnmknl(acc,n,dt,zeta,P,ra,rv,rd,ku,model,tol,maxiter)\n pkd = abs(peak(rd,n))\n muc = pkd/uy\n if ( abs(muc - mu) < 1.D-2 ) exit\n uy = uy*(muc/mu)**0.5\n fy = k0*uy\n para(2) = fy\n para(4:NPARA) = 0.D0\n para(6) = k0\n para(9) = alpha\n para(13) = k0\n para(15:16) = [ uy,-uy ]\n para(23:24) = [ fy,-fy ]\n end do\n ! SM = 1 根据预定的强度比(目标延性的倒数)确定屈服力计算响应\n else\n fy = pkf/mu\n para(1:3) = [ k0,fy,k1 ]\n para(6) = k0\n para(9) = alpha\n para(13) = k0\n para(15:16) = [ uy,-uy ]\n para(23:24) = [ fy,-fy ]\n call rnmknl(acc,n,dt,zeta,P,ra,rv,rd,ku,model,tol,maxiter)\n end if\n \n cp(6) = fy\n cp(7) = fy/k0\n\n return\nend subroutine rnl\n\nsubroutine r(acc,n,dt,zeta,P,ra,rv,rd,ku,SM) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: r\n integer, intent(in) :: n, SM\n real(8), intent(in) :: dt, zeta\n real(8), intent(in) :: acc(n), P\n real(8), intent(out) :: ra(n),rv(n),rd(n),ku(n)\n\n ku = TWO_PI*TWO_PI/(P*P)\n select case (SM)\n case (1)\n call rfreq(acc,n,dt,zeta,P,ra,rv,rd)\n case (2)\n call rnmk(acc,n,dt,zeta,P,ra,rv,rd)\n case (3)\n call rmixed(acc,n,dt,zeta,P,ra,rv,rd)\n case default\n call rmixed(acc,n,dt,zeta,P,ra,rv,rd)\n end select\nend subroutine r\n\nsubroutine spectrum(acc,n,dt,zeta,P,np,SPA,SPI,SM) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: spectrum\n integer, intent(in) :: n, np, SM\n real(8), intent(in) :: dt,zeta\n real(8), intent(in) :: acc(n), P(np)\n real(8), intent(out) :: SPA(np)\n integer, intent(out) :: SPI(np)\n\n select case (SM)\n case (1)\n call spafreq(acc,n,dt,zeta,P,nP,SPA,SPI)\n case (2)\n call spanmk(acc,n,dt,zeta,P,nP,SPA,SPI)\n case (3)\n call spamixed(acc,n,dt,zeta,P,nP,SPA,SPI)\n case (4)\n call pspafreq(acc,n,dt,zeta,P,nP,SPA,SPI)\n case (5)\n call pspanmk(acc,n,dt,zeta,P,nP,SPA,SPI)\n case (6)\n call pspamixed(acc,n,dt,zeta,P,nP,SPA,SPI)\n case default\n call spamixed(acc,n,dt,zeta,P,nP,SPA,SPI)\n end select\n\n SPA = abs(SPA)\n\n return\nend subroutine spectrum\n\nsubroutine spectrum_endur(acc,n,dt,zeta,P,np,DI,nD,SPA,SPI,SM) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: spectrum_endur\n integer, intent(in) :: n, np, SM, nD\n integer, intent(in) :: DI(nD)\n real(8), intent(in) :: dt,zeta\n real(8), intent(in) :: acc(n), P(np)\n real(8), intent(out) :: SPA(np*nD)\n integer, intent(out) :: SPI(np*nD)\n\n real(8), allocatable :: SPA1(:,:)\n integer, allocatable :: SPI1(:,:)\n\n allocate(SPA1(np,nD))\n allocate(SPI1(np,nD))\n\n select case (SM)\n case (1)\n call spafreq_endur(acc,n,dt,zeta,P,nP,DI,nD,SPA1,SPI1)\n case (2)\n call spanmk_endur(acc,n,dt,zeta,P,nP,DI,nD,SPA1,SPI1)\n case (3)\n call spamixed_endur(acc,n,dt,zeta,P,nP,DI,nD,SPA1,SPI1)\n case default\n call spamixed_endur(acc,n,dt,zeta,P,nP,DI,nD,SPA1,SPI1)\n end select\n\n SPA1 = abs(SPA1)\n\n call flat_double(SPA1,nP,nD,SPA)\n call flat_int(SPI1,nP,nD,SPI)\n\n deallocate(SPA1)\n deallocate(SPI1)\n\n return\nend subroutine spectrum_endur\n\nsubroutine spectrumavd(acc,n,dt,zeta,P,np,SPA,SPI,SPV,SPD,SPE,SM) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: spectrumavd\n integer, intent(in) :: n, np, SM\n real(8), intent(in) :: dt,zeta\n real(8), intent(in) :: acc(n), P(np)\n real(8), intent(out) :: SPA(np), SPV(np), SPD(np), SPE(np)\n integer, intent(out) :: SPI(np)\n\n select case (SM)\n case (1)\n call spavdfreq(acc,n,dt,zeta,P,nP,SPA,SPI,SPV,SPD,SPE)\n case (2)\n call spavdnmk(acc,n,dt,zeta,P,nP,SPA,SPI,SPV,SPD,SPE)\n case (3)\n call spavdmixed(acc,n,dt,zeta,P,nP,SPA,SPI,SPV,SPD,SPE)\n case default\n call spavdmixed(acc,n,dt,zeta,P,nP,SPA,SPI,SPV,SPD,SPE)\n end select\n\n SPA = abs(SPA)\n SPV = abs(SPV)\n SPD = abs(SPD)\n \nend subroutine spectrumavd\n\nsubroutine fitspectrum(acc,n,dt,zeta,P,nP,SPAT,a,tol,mit,fm,kpb) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: fitspectrum\n integer, intent(in) :: n, nP, mit, fm, kpb\n real(8), intent(in) :: dt, zeta, tol\n real(8), intent(in) :: acc(n), P(nP), SPAT(nP)\n real(8), intent(out) :: a(n)\n\n real(8), allocatable :: EP(:), ESPAT(:)\n\n if ( fm == 0 ) then\n allocate(EP(nP+2))\n allocate(ESPAT(nP+2))\n\n EP(2:nP+1) = P\n EP(1) = P(1)*0.5\n EP(nP+2) = P(nP)*1.5\n ESPAT(2:nP+1) = SPAT\n ESPAT(1) = SPAT(1)-(SPAT(2)-SPAT(1))/(P(2)-P(1))*P(1)*0.5d0\n ESPAT(nP+2) = SPAT(nP)+(SPAT(nP)-SPAT(nP-1))/(P(nP)-P(nP-1))*P(nP)*0.5d0\n\n call fitspectra(acc,n,dt,zeta,EP,nP+2,ESPAT,a,tol,mit,kpb)\n\n deallocate(EP)\n deallocate(ESPAT)\n else if ( fm == 1 ) then\n call adjustspectra(acc,n,dt,zeta,P,nP,SPAT,a,tol,mit,kpb)\n end if\nend subroutine fitspectrum\n\nsubroutine initArtWave(a,n,dt,zeta,P,nP,SPT) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: initartwave\n! 根据目标反应谱估计功率谱并生成随机的时域信号\n integer, intent(in) :: n, nP\n real(C_DOUBLE), intent(in) :: dt, zeta, P(nP), SPT(nP)\n real(C_DOUBLE), intent(out) :: a(n)\n\n integer :: Nfft, i, j, k, NPf, IPf1, IPf2\n real(C_DOUBLE) :: phi, Ak, Saw, wk\n real(C_DOUBLE), allocatable :: f(:), Pf(:), SPTf(:)\n complex(C_DOUBLE_COMPLEX), allocatable :: a0(:), af(:)\n \n type(C_PTR) :: plan\n\n Nfft = nextpow2(n)\n\n allocate(a0(Nfft))\n allocate(af(Nfft))\n allocate(f(Nfft))\n allocate(Pf(Nfft/2))\n allocate(SPTf(Nfft/2))\n\n af = (0.D0,0.D0)\n \n plan = fftw_plan_dft_1d(Nfft,af,a0,FFTW_BACKWARD,FFTW_ESTIMATE)\n\n call fftfreqs(Nfft,1.d0/dt,f)\n Pf(2:Nfft/2) = 1.d0/f(2:Nfft/2)\n Pf(1) = 100.d0*Pf(2)\n\n call decrfindfirst(Pf,Nfft/2,P(nP),IPf1)\n call decrfindlast(Pf,Nfft/2,P(1), IPf2)\n call decrlininterp(P,SPT,nP,Pf(IPf1:IPf2),SPTf(IPf1:IPf2),IPf2-IPf1+1)\n\n call random_seed()\n do k = IPf1, IPf2, 1\n call random_number(phi)\n phi = phi*TWO_PI\n wk = TWO_PI*f(k)\n !Saw = 2.0D0*zeta*SPTf(k)**2.0D0/(pi*2.0D0*pi*f(k)*&\n !(-2.0D0*log(-pi*log(0.85D0)/(2.0D0*pi*f(k)*(dt*n-dt)))))\n Saw = (zeta/PI/wk)*SPTf(k)*SPTf(k)/log(1.d0/((-PI/wk/dt/n)*log(1.d0-0.85d0)))\n Ak = 2.0D0*sqrt(Saw*2.0D0*pi*(1.D0/dt)*Nfft/2)\n af(k) = Ak*(cmplx(cos(phi),sin(phi)))\n af(Nfft+2-k) = Ak*(cmplx(cos(phi),-sin(phi)))\n end do\n\n call fftw_execute_dft(plan,af,a0)\n a = real(a0(1:n))/Nfft\n call fftw_destroy_plan(plan)\n call fftw_cleanup()\n \n deallocate(a0)\n deallocate(af)\n deallocate(f)\n deallocate(Pf)\n deallocate(SPTf)\n\nend subroutine initArtWave\n\nsubroutine whiteNoise(a,n,dt) bind(c)\n!DIR$ ATTRIBUTES DLLEXPORT :: whiteNoise\n! 生成随机白噪声信号\n integer, intent(in) :: n\n real(C_DOUBLE), intent(in) :: dt\n real(C_DOUBLE), intent(out) :: a(n)\n\n integer :: Nfft, k\n real(C_DOUBLE) :: phi, Ak\n real(C_DOUBLE), allocatable :: f(:)\n complex(C_DOUBLE_COMPLEX), allocatable :: a0(:), af(:)\n \n type(C_PTR) :: plan\n\n Nfft = nextpow2(n)\n\n allocate(a0(Nfft))\n allocate(af(Nfft))\n allocate(f(Nfft))\n\n af = (0.D0,0.D0)\n \n plan = fftw_plan_dft_1d(Nfft,af,a0,FFTW_BACKWARD,FFTW_ESTIMATE)\n\n call fftfreqs(Nfft,1.d0/dt,f)\n \n call random_seed()\n call random_number(phi)\n phi = phi*TWO_PI\n Ak = 2.0D0*sqrt(2.0D0*pi*(1.D0/dt))\n af(1) = Ak*(cmplx(cos(phi),sin(phi)))\n af(Nfft/2+1) = Ak*(cmplx(cos(phi),-sin(phi)))\n\n call random_seed()\n do k = 2, Nfft/2, 1\n call random_number(phi)\n phi = phi*TWO_PI\n Ak = 2.0D0*sqrt(2.0D0*pi*(1.D0/dt))\n af(k) = Ak*(cmplx(cos(phi),sin(phi)))\n af(Nfft+2-k) = Ak*(cmplx(cos(phi),-sin(phi)))\n end do\n\n call fftw_execute_dft(plan,af,a0)\n a = real(a0(1:n))/Nfft\n call fftw_destroy_plan(plan)\n call fftw_cleanup()\n \n deallocate(a0)\n deallocate(af)\n deallocate(f)\n\nend subroutine whiteNoise\n\nend module eqs\n", "meta": {"hexsha": "c4eb442c7afc6789e37898def8bf8268499f0dd7", "size": 90718, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "libeqs/eqs.f90", "max_stars_repo_name": "Panchatantra/EQSignal", "max_stars_repo_head_hexsha": "ac04d71a5b011bc3feb66562d6dda0b4e7e4e67b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-04-19T12:41:26.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-21T12:39:02.000Z", "max_issues_repo_path": "libeqs/eqs.f90", "max_issues_repo_name": "jiayingqi/EQSignal", "max_issues_repo_head_hexsha": "ac04d71a5b011bc3feb66562d6dda0b4e7e4e67b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "libeqs/eqs.f90", "max_forks_repo_name": "jiayingqi/EQSignal", "max_forks_repo_head_hexsha": "ac04d71a5b011bc3feb66562d6dda0b4e7e4e67b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-08-04T09:57:06.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-01T03:24:26.000Z", "avg_line_length": 24.4325343388, "max_line_length": 100, "alphanum_fraction": 0.5097114134, "num_tokens": 34350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7729177564165125}} {"text": "module fft_mod\nimplicit none\nreal*8, parameter :: pi=3.141592653589793238460\ncontains\n\nrecursive subroutine fft(x)\n complex, dimension(:), intent(inout) :: x\n complex :: t\n integer :: N\n integer :: i\n complex, dimension(:), allocatable :: even, odd\n \n N=size(x)\n \n if(N .le. 1) return\n \n allocate(odd((N+1)/2))\n allocate(even(N/2))\n\n odd =x(1:N:2)\n even=x(2:N:2)\n\n call fft(odd)\n call fft(even)\n\n do i=1,N/2\n t=exp( cmplx( 0.0, -2.0 * pi * real(i-1) / real(N) ) )*even(i)\n x(i) = odd(i) + t\n x(i+N/2) = odd(i) - t\n end do\n \n deallocate(odd)\n deallocate(even)\n \nend subroutine fft\n \nend module fft_mod\n", "meta": {"hexsha": "a5901c87c8e008f468eae386b16a7c841281c709", "size": 781, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fft_mod.f90", "max_stars_repo_name": "Ademishe/WEMRA", "max_stars_repo_head_hexsha": "0ac7674c30360deb0f8ebfb7e2ffebd1e771e2f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fft_mod.f90", "max_issues_repo_name": "Ademishe/WEMRA", "max_issues_repo_head_hexsha": "0ac7674c30360deb0f8ebfb7e2ffebd1e771e2f4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fft_mod.f90", "max_forks_repo_name": "Ademishe/WEMRA", "max_forks_repo_head_hexsha": "0ac7674c30360deb0f8ebfb7e2ffebd1e771e2f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.5526315789, "max_line_length": 70, "alphanum_fraction": 0.4852752881, "num_tokens": 240, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.8221891283434877, "lm_q1q2_score": 0.7727865378118403}} {"text": "!******************************************************************************\n!*\n!* INTEGRATION OF FUNCTIONS\n!*\n!******************************************************************************\n\n !==========================================================================\n ! 1) AUTHOR: F. Galliano\n !\n ! 2) HISTORY: \n ! - Created 08/2007 \n ! - Correct bug of INTEG_TABULATED, when there is not point inside the\n ! interval to integrate over.\n ! - On 05/2014: add the log-lin integration.\n ! - On 05/2014: allow zero values in the function in the log case.\n ! \n ! 3) DESCRIPTION: Various methods to integrate numerically a function.\n !==========================================================================\n\nMODULE integration\n\n USE utilities, ONLY:\n USE arrays, ONLY:\n USE interpolation, ONLY:\n IMPLICIT NONE\n PRIVATE\n\n PUBLIC :: dPrimitive, integ_tabulated, integ_romb\n\n\nCONTAINS\n\n\n !==========================================================================\n ! dF[N] = DPRIMITIVE(x,f,XLOG,YLOG,lnx,lnf)\n !\n ! Returns the differential primitive of a function on a given grid, for \n ! various function assumptions (lin/log).\n ! Log(x) and LOG(f) can eventually be passed as argument to avoid having\n ! to comput them twice.\n !==========================================================================\n\n PURE FUNCTION dPrimitive (x,f,xlog,ylog,lnx,lnf)\n\n USE utilities, ONLY: DP\n IMPLICIT NONE\n\n REAL(DP), INTENT(IN), DIMENSION(:) :: x, f\n LOGICAL, INTENT(IN) :: xlog, ylog\n REAL(DP), INTENT(IN), DIMENSION(:), OPTIONAL :: lnx, lnf\n REAL(DP), DIMENSION(SIZE(x)) :: dPrimitive\n \n INTEGER :: N\n REAL(DP), DIMENSION(SIZE(x)) :: logx, logf\n \n !------------------------------------------------------------------------\n\n N = SIZE(x(:))\n dPrimitive(1) = 0._DP\n linlog: IF (.NOT. xlog .AND. .NOT. ylog) THEN\n\n ! Linear: assumes f(x) ~ a*x + b \n dPrimitive(2:N) = DPRIMITIVE_LINLIN(x(:),f(:),N)\n\n ELSE IF (xlog .AND. .NOT. ylog) THEN\n\n ! Logarithm: assumes f(x) ~ ln(a*x+b)\n dPrimitive(2:N) = DPRIMITIVE_LOGLIN(x(:),f(:),N)\n\n ELSE IF (.NOT. xlog .AND. ylog) THEN\n\n ! Exponential: assumes f(x) ~ exp(a*x+b)\n IF (PRESENT(lnf)) THEN \n logf(:) = lnf(:) \n ELSE \n logf(:) = LOG(f(:))\n END IF\n dPrimitive(2:N) = DPRIMITIVE_LINLOG(x(:),f(:),N,lnf(:))\n \n ELSE IF (xlog .AND. ylog) THEN \n\n ! Power-law: assumes f(x) ~ a*x^b\n IF (PRESENT(lnx)) THEN \n logx(:) = lnx(:) \n ELSE \n logx(:) = LOG(x(:))\n END IF\n IF (PRESENT(lnf)) THEN \n logf(:) = lnf(:) \n ELSE \n logf(:) = LOG(f(:))\n END IF\n dPrimitive(2:N) = DPRIMITIVE_LOGLOG(x(:),f(:),N,lnx(:),lnf(:))\n \n END IF linlog\n\n !------------------------------------------------------------------------\n\n END FUNCTION dPrimitive\n\n \n ! Formula for each method\n !------------------------\n ! Linear: assumes f(x) ~ a*x + b \n ! => F(x1)-F(x0) = (f(x1)+f(x0)) / 2 * (x1-x0)\n PURE FUNCTION dPrimitive_linlin (x,f,N)\n \n USE utilities, ONLY: DP\n IMPLICIT NONE\n\n REAL(DP), DIMENSION(N), INTENT(IN) :: x, f\n INTEGER, INTENT(IN) :: N\n REAL(DP), DIMENSION(N-1) :: dPrimitive_linlin\n\n !------------------------------------------------------------------------\n\n dPrimitive_linlin(:) = 0.5_DP * ( f(2:N) + f(1:N-1) ) * ( x(2:N) - x(1:N-1) )\n\n !------------------------------------------------------------------------\n\n END FUNCTION dPrimitive_linlin\n \n ! Logarithm: assumes f(x) ~ ln(a*x+b)\n ! => F(x1)-F(x0) = ( (f(x1)-1)*EXP(f(x1)) - (f(x0)-1)*EXP(f(x0)) ) \n ! * (x1-x0) / ( EXP(f(x1)) - EXP(f(x0)) )\n PURE FUNCTION dPrimitive_loglin (x,f,N)\n \n USE utilities, ONLY: DP, epsDP\n IMPLICIT NONE\n\n REAL(DP), DIMENSION(N), INTENT(IN) :: x, f\n INTEGER, INTENT(IN) :: N\n REAL(DP), DIMENSION(N-1) :: dPrimitive_loglin\n REAL(DP), DIMENSION(N) :: expf, fm1\n REAL(DP), DIMENSION(N-1) :: dexpf\n \n !------------------------------------------------------------------------\n\n fm1 = f(:) - 1._DP\n expf = EXP(f(:))\n dexpf(:) = expf(2:N) - expf(1:N-1)\n WHERE (ABS(dexpf(:)) > epsDP*expf(2:N))\n dPrimitive_loglin(:) = ( fm1(2:N)*expf(2:N) - fm1(1:N-1)* expf(1:N-1) ) &\n * ( x(2:N) - x(1:N-1) ) / dexpf(:)\n ELSEWHERE\n dPrimitive_loglin(:) = 0.5_DP * ( f(2:N) + f(1:N-1) ) * (x(2:N)-x(1:N-1))\n END WHERE\n\n !------------------------------------------------------------------------\n\n END FUNCTION dPrimitive_loglin\n \n ! Exponential: assumes f(x) ~ exp(a*x+b)\n ! => F(x1)-F(x0) = ( f(x1) - f(x0) ) * (x1-x0) / ( ln(f(x1)) - ln(f(x0)) )\n PURE FUNCTION dPrimitive_linlog (x,f,N,lnf)\n \n USE utilities, ONLY: DP, epsDP\n IMPLICIT NONE\n\n REAL(DP), DIMENSION(N), INTENT(IN) :: x, f, lnf\n INTEGER, INTENT(IN) :: N\n REAL(DP), DIMENSION(N-1) :: dPrimitive_linlog\n REAL(DP), DIMENSION(N-1) :: dlnf\n \n !------------------------------------------------------------------------\n\n dlnf(:) = lnf(2:N) - lnf(1:N-1)\n WHERE (f(1:N-1) > 0._DP .AND. f(2:N) > 0._DP &\n .AND. ABS(dlnf(:)) > epsDP*ABS(lnf(2:N)) )\n dPrimitive_linlog(:) = ( f(2:N) - f(1:N-1) ) * ( x(2:N) - x(1:N-1) ) &\n / dlnf(:) \n ELSEWHERE\n dPrimitive_linlog(:) = 0.5_DP * ( f(2:N) + f(1:N-1) ) * (x(2:N)-x(1:N-1))\n END WHERE\n \n !------------------------------------------------------------------------\n\n END FUNCTION dPrimitive_linlog\n \n ! Power-law: assumes f(x) ~ a*x^b\n ! F(x1)-F(x0) = ( x1*f(x1) - x0*f(x0) ) / ( 1 + ( ln(f(x1)) - ln(f(x0) ) )\n ! / ( ln(x1) - ln(x0) ) )\n PURE FUNCTION dPrimitive_loglog (x,f,N,lnx,lnf)\n \n USE utilities, ONLY: DP, epsDP\n IMPLICIT NONE\n\n REAL(DP), DIMENSION(N), INTENT(IN) :: x, f, lnx, lnf\n INTEGER, INTENT(IN) :: N\n REAL(DP), DIMENSION(N-1) :: dPrimitive_loglog\n REAL(DP), DIMENSION(N-1) :: dlnx\n\n !------------------------------------------------------------------------\n\n dlnx(:) = lnx(2:N) - lnx(1:N-1)\n WHERE (f(1:N-1) > 0._DP .AND. f(2:N) > 0._DP &\n .AND. ABS(dlnx(:)) > epsDP*ABS(lnx(2:N)))\n dPrimitive_loglog(:) = ( x(2:N)*f(2:N) - x(1:N-1)*f(1:N-1) ) &\n / ( 1._DP + ( lnf(2:N) - lnf(1:N-1) ) / dlnx(:) )\n ELSEWHERE\n dPrimitive_loglog(:) = 0.5_DP * ( f(2:N) + f(1:N-1) ) * (x(2:N)-x(1:N-1))\n END WHERE\n \n !------------------------------------------------------------------------\n\n END FUNCTION dPrimitive_loglog\n \n\n !==========================================================================\n ! I = INTEG_TABULATED(x[N],f[N],[x0,x1],PRIMITIVE[N],LINEAR,LOGARITHM, &\n ! EXPONENTIAL,POWERLAW,XLOG,YLOG,FORCE,RESCALE)\n !\n ! Integration of tabulated functions. Returns the integration of f(x) from\n ! x0 to x1>x0, using the trapezium method. X must be SORTED without any \n ! duplicates. The boolean keywords select the integration method (lin-lin, \n ! log-lin, lin-log or log-log).\n !==========================================================================\n\n FUNCTION integ_tabulated (x,f,xrange,primitive,linear,logarithm,exponential, &\n powerlaw,xlog,ylog,force,rescale)\n\n USE utilities, ONLY: DP, strike, warning, isNaN\n USE arrays, ONLY: iwhere\n\n IMPLICIT NONE\n\n REAL(DP), INTENT(IN), DIMENSION(:) :: x, f\n REAL(DP), INTENT(IN), DIMENSION(2), OPTIONAL :: xrange\n REAL(DP), INTENT(OUT), DIMENSION(SIZE(x)), OPTIONAL :: primitive\n LOGICAL, INTENT(IN), OPTIONAL :: linear, logarithm, exponential, powerlaw\n LOGICAL, INTENT(IN), OPTIONAL :: xlog, ylog, force, rescale\n REAL(DP) :: integ_tabulated\n\n REAL(DP) :: x0, x1, min_x, max_x, x_inf, x_sup, f_inf, f_sup, logx2, logf2\n REAL(DP) :: scaling\n REAL(DP), DIMENSION(:), ALLOCATABLE :: xi, fi, dPrim, logx, logf\n INTEGER :: Nx, Nin, i, i0, i1, i2\n LOGICAL, DIMENSION(SIZE(x)) :: boolin\n LOGICAL, DIMENSION(2) :: interpol, extrapol\n LOGICAL :: xl, yl, forced, rescl\n \n !-----------------------------------------------------------------------\n\n ! Check the arguments\n !--------------------\n ! Size\n Nx = SIZE(x(:))\n IF (Nx <= 1) CALL STRIKE(\"INTEG_TABULATED\",\"x should have >=2 elements\")\n\n ! Integration range\n min_x = MINVAL(x(:))\n max_x = MAXVAL(x(:))\n range: IF (PRESENT(xrange)) THEN\n x0 = xrange(1)\n x1 = xrange(2)\n IF ((x0 > max_x) .OR. (x1 < min_x)) &\n CALL STRIKE(\"INTEG_TABULATED\",\"bad integration range.\")\n ELSE\n x0 = min_x\n x1 = max_x\n END IF range\n IF (x0 >= x1) CALL STRIKE(\"INTEG_TABULATED\",\"bad XRANGE.\")\n\n ! Type of integration (xlog and ylog have priority over powerlaw, \n ! exponential, linear, etc.)\n xl = .False.\n IF (PRESENT(xlog)) xl = xlog\n yl = .False.\n IF (PRESENT(ylog)) yl = ylog\n IF (PRESENT(linear)) THEN\n IF (linear) THEN\n xl = .False.\n yl = .False.\n END IF\n END IF\n IF (PRESENT(logarithm)) THEN\n IF (logarithm) THEN\n xl = .True.\n yl = .False.\n END IF\n END IF\n IF (PRESENT(exponential)) THEN\n IF (exponential) THEN\n xl = .False.\n yl = .True.\n END IF\n END IF\n IF (PRESENT(powerlaw)) THEN\n IF (powerlaw) THEN\n xl = .True.\n yl = .True.\n END IF\n END IF\n forced = .False.\n IF (PRESENT(force)) forced = force\n\n ! Rescale to avoid numerical problems\n rescl = .True.\n IF (PRESENT(rescale)) rescl = rescale\n\n\n ! Interpolation and extrapolation at the edges\n !---------------------------------------------\n ! Determine if extrapolation is necessary\n interpol(1) = ((.NOT. ANY(x(:) == x0)) .AND. (min_x < x0))\n interpol(2) = ((.NOT. ANY(x(:) == x1)) .AND. (max_x > x1))\n extrapol(1) = (min_x > x0)\n extrapol(2) = (max_x < x1)\n \n ! Logical mask of the points considered for integration\n boolin = (x(:) > x0 .AND. x(:) < x1)\n Nin = COUNT(boolin) + 2\n IF (rescl) THEN\n scaling = MERGE(MAXVAL(ABS(f(:)),MASK=( boolin(:) .AND. f(:) /= 0._DP &\n .AND. .NOT. isNaN(f(:)) )), &\n 1._DP,Nin > 2)\n ELSE\n scaling = 1._DP\n END IF\n ALLOCATE(xi(Nin),fi(Nin),dPrim(Nin),logx(Nin),logf(Nin))\n xi = [ x0, PACK(x(:),boolin), x1 ]\n IF (.NOT. rescl) THEN\n fi = [ 1._DP, PACK(f(:),boolin), 1._DP ] ! edges will be replaced later\n ELSE\n fi = [ 1._DP, PACK(f(:),boolin)/scaling, 1._DP ]\n END IF\n logx = MERGE(LOG(xi(:)),xi(:),xl)\n logf = MERGE(LOG(fi(:)),fi(:),yl)\n \n ! Inter/extrapolates at the boundaries\n lower_boundary: IF (extrapol(1)) THEN\n logf(1) = logf(2) &\n - (logf(3)-logf(2)) / (logx(3)-logx(2)) * (logx(2)-logx(1))\n ELSE IF (interpol(1)) THEN\n x_inf = MAXVAL(PACK(x(:),x(:) 2) THEN\n logf(1) = logf(2) - (logf(2)-f_inf)/(logx(2)-x_inf) * (logx(2)-logx(1))\n ELSE\n CALL IWHERE(MERGE(LOG(x(:)),x(:),xl) == x_inf,i2)\n logx2 = MERGE(LOG(x(i2+1)),x(i2+1),xl)\n IF (.NOT. rescl) THEN\n logf2 = MERGE(LOG(f(i2+1)),f(i2+1),yl)\n ELSE\n logf2 = MERGE(LOG(f(i2+1)/scaling),f(i2+1)/scaling,yl)\n END IF\n logf(1) = logf2 - (logf2-f_inf)/(logx2-x_inf) * (logx2-logx(1))\n END IF\n ELSE \n IF (.NOT. rescl) THEN\n logf(1) = MERGE(LOG(MINVAL(PACK(f(:),x(:)==x0))), &\n MINVAL(PACK(f(:),x(:)==x0)),yl)\n ELSE\n logf(1) = MERGE(LOG(MINVAL(PACK(f(:),x(:)==x0))/scaling), &\n MINVAL(PACK(f(:),x(:)==x0))/scaling,yl)\n END IF\n END IF lower_boundary\n fi(1) = MERGE(EXP(logf(1)),logf(1),yl)\n upper_boundary: IF (extrapol(2)) THEN\n logf(Nin) = logf(Nin-1) &\n + (logf(Nin-1)-logf(Nin-2)) / (logx(Nin-1)-logx(Nin-2)) &\n * (logx(Nin)-logx(Nin-1))\n ELSE IF (interpol(2)) THEN\n x_sup = MINVAL(PACK(x(:),x(:)>x1))\n IF (.NOT. rescl) THEN\n f_sup = MERGE(LOG(MINVAL(PACK(f(:),x(:)==x_sup))), &\n MINVAL(PACK(f(:),x(:)==x_sup)),yl)\n ELSE\n f_sup = MERGE(LOG(MINVAL(PACK(f(:),x(:)==x_sup))/scaling), &\n MINVAL(PACK(f(:),x(:)==x_sup))/scaling,yl)\n END IF\n x_sup = MERGE(LOG(x_sup),x_sup,xl)\n IF (Nin > 2) THEN\n logf(Nin) = logf(Nin-1) &\n + (f_sup-logf(Nin-1)) / (x_sup-logx(Nin-1)) &\n * (logx(Nin)-logx(Nin-1))\n ELSE\n CALL IWHERE(MERGE(LOG(x(:)),x(:),xl) == x_sup,i2)\n logx2 = MERGE(LOG(x(i2-1)),x(i2-1),xl)\n IF (.NOT. rescl) THEN\n logf2 = MERGE(LOG(f(i2-1)),f(i2-1),yl)\n ELSE\n logf2 = MERGE(LOG(f(i2-1)/scaling),f(i2-1)/scaling,yl)\n END IF\n logf(Nin) = logf2 &\n + (f_sup-logf2) / (x_sup-logx2) * (logx(Nin)-logx2)\n END IF\n ELSE \n IF (.NOT. rescl) THEN\n logf(Nin) = MERGE(LOG(MINVAL(PACK(f(:),x(:)==x1))), &\n MINVAL(PACK(f(:),x(:)==x1)),yl)\n ELSE\n logf(Nin) = MERGE(LOG(MINVAL(PACK(f(:),x(:)==x1))/scaling), &\n MINVAL(PACK(f(:),x(:)==x1))/scaling,yl)\n END IF\n END IF upper_boundary\n fi(Nin) = MERGE(EXP(logf(Nin)),logf(Nin),yl)\n\n\n ! Actual lin/log trapezium integration\n !-------------------------------------\n dPrim(:) = DPRIMITIVE(xi(:),fi(:),xl,yl,logx(:),logf(:))\n IF (rescl) dPrim(:) = dPrim(:) * scaling\n\n ! Remove the NaN\n IF (forced .AND. yl) THEN\n WHERE (ISNAN(dPrim(:))) dPrim(:) = 0._DP\n END IF\n\n ! Integral and primitive function if requested\n prim: IF (PRESENT(primitive)) THEN\n DO i=2,Nin ; dPrim(i) = dPrim(i) + dPrim(i-1) ; END DO\n integ_tabulated = dPrim(Nin)\n i0 = MERGE(2,1,(extrapol(1) .OR. interpol(1)))\n i1 = MERGE(Nin-1,Nin,(extrapol(2) .OR. interpol(2)))\n primitive(:) = UNPACK(dPrim(i0:i1),(x(:)>=x0 .AND. x(:)<=x1),FIELD=0._DP)\n primitive(:) = MERGE(integ_tabulated,primitive(:),x(:)>x1)\n ELSE \n integ_tabulated = SUM(dPrim(:))\n END IF prim\n\n DEALLOCATE(xi,fi,dPrim,logx,logf)\n\n !-----------------------------------------------------------------------\n\n END FUNCTION integ_tabulated \n\n\n !==========================================================================\n ! CALL TRAPEZ (func,a,b,s,n)\n !\n ! Returns the integration of f(x) from a to b>a, using the trapezium rule\n ! of order n.\n !==========================================================================\n\n SUBROUTINE trapez (func,a,b,s,n)\n \n USE utilities, ONLY: DP\n IMPLICIT NONE\n\n INTERFACE\n FUNCTION func (x)\n USE utilities, ONLY: DP\n REAL(DP), INTENT(IN), DIMENSION(:) :: x\n REAL(DP), DIMENSION(SIZE(x)) :: func \n END FUNCTION func\n END INTERFACE\n REAL(DP), INTENT(IN) :: a, b\n REAL(DP), INTENT(INOUT) :: s\n INTEGER, INTENT(IN) :: n\n\n REAL(DP) :: del, fsum\n REAL(DP), DIMENSION(:), ALLOCATABLE :: arth\n INTEGER :: it, i\n\n !-----------------------------------------------------------------------\n\n IF (n == 1) THEN\n s = 0.5_DP*(b-a) * SUM(func((/a,b/)))\n ELSE\n it = 2**(n-2)\n del = (b-a)/it\n ALLOCATE(arth(it))\n FORALL (i=1:it) arth(i) = a+0.5_DP*del + (i-1)*del\n fsum = SUM(func(arth))\n s = 0.5_DP*(s+del*fsum)\n DEALLOCATE (arth)\n END IF\n\n !-----------------------------------------------------------------------\n\n END SUBROUTINE trapez\n\n\n !==========================================================================\n ! I = INTEG_ROMB(func(x),a,b)\n !\n ! Returns the integration of f(x) from a to b>a, using the Romberg\n ! method of order k. \n !==========================================================================\n\n FUNCTION integ_romb (func,a,b)\n\n USE utilities, ONLY: DP, strike, NaN\n USE arrays, ONLY: reverse\n USE interpolation, ONLY: interp_poly\n IMPLICIT NONE\n\n REAL(DP), INTENT(IN) :: a, b\n INTERFACE\n FUNCTION func (x)\n USE utilities, ONLY: DP\n REAL(DP), INTENT(IN), DIMENSION(:) :: x\n REAL(DP), DIMENSION(SIZE(x)) :: func \n END FUNCTION func\n END INTERFACE\n REAL(DP) :: integ_romb\n \n INTEGER, PARAMETER :: jmax=20, jmaxp=jmax+1, k=5, km=k-1\n REAL(DP), PARAMETER :: eps=1.E-6_DP\n\n REAL(DP), DIMENSION(jmaxp) :: h, s\n REAL(DP) :: dqromb\n INTEGER :: j\n\n !-----------------------------------------------------------------------\n\n integ_romb = NaN()\n h(1) = 1.0_DP\n DO j=1,jmax\n CALL TRAPEZ (func,a,b,s(j),j)\n IF (j >= k) THEN\n integ_romb = INTERP_POLY(REVERSE(s(j-km:j)),REVERSE(h(j-km:j)), &\n 0._DP,ERR_NEW=dqromb,DEGREE=km-1)\n IF (ABS(dqromb) <= eps*ABS(integ_romb)) RETURN\n END IF\n s(j+1) = s(j)\n h(j+1) = 0.25_DP*h(j)\n END DO\n CALL STRIKE (\"INTEG_ROMB\",\"too many steps.\")\n\n !-----------------------------------------------------------------------\n\n END FUNCTION integ_romb\n\n\nEND MODULE integration\n", "meta": {"hexsha": "7d36ed5b9f4209500d6a8de65a8473f60f381dc1", "size": 17541, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MILES/swing/Math/integration.f90", "max_stars_repo_name": "kxxdhdn/MISSILE", "max_stars_repo_head_hexsha": "89dea38aa9247f20c444ccd0b832c674be275fbf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MILES/swing/Math/integration.f90", "max_issues_repo_name": "kxxdhdn/MISSILE", "max_issues_repo_head_hexsha": "89dea38aa9247f20c444ccd0b832c674be275fbf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MILES/swing/Math/integration.f90", "max_forks_repo_name": "kxxdhdn/MISSILE", "max_forks_repo_head_hexsha": "89dea38aa9247f20c444ccd0b832c674be275fbf", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.7869158879, "max_line_length": 81, "alphanum_fraction": 0.4628014366, "num_tokens": 5548, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133515091156, "lm_q2_score": 0.822189121808099, "lm_q1q2_score": 0.7727865330529868}} {"text": "! This program shows how to use selected_real_kind\n! SELECTED_REAL_KIND(P,R, RADIX) returns the kind value of \n! a real data type with decimal precision of at least \n! P digits, exponent range of at least R, and with\n! a radix of RADIX.\n!\n! Note the repeated kind type values for different precisions.\n! Not all real representations are available\n!\nprogram kind_real_all\n implicit none\n integer, parameter :: p1 = selected_real_kind(p=6, r=10, radix= 2)\n integer, parameter :: p2 = selected_real_kind(20, 140)\n integer, parameter :: p3 = selected_real_kind(p=10)\n\n real(kind = p1) :: v1\n real(kind = p2) :: v2\n real(kind = p3) :: v3\n\n print*,'selected_real_kind(p=6, r=10, radix=2)', p1\n print*,' p = ', precision(v1), ' r = ', & \n range(v1), ' radix = ', radix(v1)\n print*,'selected_real_kind(20, 40)', p2\n print*,' p = ', precision(v2), ' r = ', & \n range(v2), ' radix = ', radix(v2)\n print*,'selected_real_kind(p=10)', p3\n print*,' p = ', precision(v3), ' r = ', & \n range(v3), ' radix = ', radix(v3)\nend program kind_real_all\n", "meta": {"hexsha": "4f76228af91f59b2ba35ff4fd67a6a3837297be3", "size": 1088, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/gettingStarted/kind_real_all.f90", "max_stars_repo_name": "annefou/Fortran", "max_stars_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2016-04-08T19:04:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-13T15:44:37.000Z", "max_issues_repo_path": "src/gettingStarted/kind_real_all.f90", "max_issues_repo_name": "inandi2/Fortran-1", "max_issues_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/gettingStarted/kind_real_all.f90", "max_forks_repo_name": "inandi2/Fortran-1", "max_forks_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2016-04-08T19:05:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-08T19:57:51.000Z", "avg_line_length": 36.2666666667, "max_line_length": 71, "alphanum_fraction": 0.6341911765, "num_tokens": 338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107896491795, "lm_q2_score": 0.8244619242200081, "lm_q1q2_score": 0.7726946110339158}} {"text": "!Author: Anantha rao\nprogram harmonic0\n ! Solution of the 1D quantum harmonic oscillator\n ! Forward integration only, Numerov algorithm\n ! Eigenvalue search using shooting method (bisection method)\n ! Need to use asymptotic limits\n ! Adimensional units: x = (mK/hbar^2)^(1/4) X\n ! e = E/(hbar omega)\n\n\n implicit none\n integer, parameter :: dp=selected_real_kind(14,200)\n integer :: mesh, i, icl\n integer :: nodes, hnodes, ncross, kkk, n_iter\n real(dp) :: xmax, dx, ddx12, norm, arg\n real(dp) :: eup, elw, e\n real(dp), allocatable :: x(:), y(:), p(:), vpot(:), f(:)\n character(len=88) :: fileout\n\n ! Read input data\n print '(a,$)', 'Max value for x (typical value:10) ? '\n read(*,*) xmax\n print '(a,$)', 'Number of grid points (typically a few hundreds)?'\n read(*,*) mesh\n\n ! Allocate arrays, initialize grid\n allocate (x(0:mesh), y(0:mesh), p(0:mesh), vpot(0:mesh), f(0:mesh)) \n dx = xmax/mesh\n ddx12=dx*dx/12.0_dp\n\n ! Set up the potential (must be even wrt x=0)\n do i=0,mesh\n x(i) = float(i)*dx\n vpot(i) = 0.5_dp*x(i)*x(i)\n end do\n\n print'(a,$)', 'output file name = '\n read(*,'(a)') fileout\n open(7, file=fileout, status='unknown', form='formatted')\n\n ! Entry point for new eigenvalue search\n search_loop: do\n ! read number of nodes (stop if <0)\n print '(a,$)', 'nodes (type -1 to stop) >> '\n read(*,*) nodes\n if (nodes < 0) then\n close(7)\n deallocate( f, vpot, p,y,x)\n stop\n end if\n\n ! Set initial lower and upper bounds to the eigenvalue\n eup = maxval(vpot(:))\n elw = minval(vpot(:))\n\n ! Set trial energy\n print '(a,$)', 'Trial energy (0=search with bisection) ? '\n read (*,*) e\n if ( e == 0.0_dp) then\n ! search eigenvalues with bisection\n e = 0.5_dp * (elw + eup)\n n_iter = 1000\n else \n ! test a single energy value\n n_iter = 1\n endif\n\n iterate: do kkk=1, n_iter\n ! setup the f-function used by Numerov algorithm\n ! and determine the position of its last crossing,, ie change of\n ! sign\n ! f < 0 means classically allowed region\n ! f > 0 means classically forbidden region\n\n f(0)=ddx12*(2.0_dp*(vpot(0)-e))\n icl=-1\n do i=1,mesh\n f(i)=ddx12*2.0_dp*(vpot(i)-e)\n ! if(f(i) is exactly zero then the change f sign is not observed\n ! The following line is a trick to prevent missing a change of\n ! sign; in this unlikely but impossible case: \n if (f(i) == 0.0_dp) f(i)=1.d-20\n ! store the index 'icl' where the last change of sign has been found\n if ( f(i) /= sign(f(i), f(i-1))) icl = i\n end do\n\n if (icl >= mesh-2) then\n deallocate (f,vpot, p,y,x)\n stop 'last cahnge of sign too far'\n else if (icl <1) then\n deallocate(f, vpot, p, y, x)\n stop 'no classical turning point?'\n end if\n\n ! f(x) as required by Numerov algorithm\n\n f = 1.0_dp - f\n y = 0.0_dp\n \n ! Determination of the wave function in the first two points \n\n hnodes = nodes/2\n\n ! be careful of integer division: 1/2 = 0 !\n ! if nodes is even, there are 2*hnodes nodes\n ! if nodes is odd, there are 2*hnodes+1 nodes (one is in x=0)\n ! hnodes is thus the number of nodes in the x>0 semi-axis (x=0 excepted) \n\n if (2*hnodes == nodes) then\n ! even number of nodes: wavefunction is even)\n y(0) = 1.0_dp\n ! assume f(-1) = f(1)\n y(1) = 0.5_dp*(12.0_dp - 10.0_dp*f(0))*y(0)/f(1)\n else \n ! odd number of nodes: wave function is odd \n y(0) = 0.0_dp\n y(1) = dx\n end if\n\n\n ! outward integration and count number of crossings\n\n ncross=0\n do i=1, mesh-1\n y(i+1) = ((12.0_dp - 10.0_dp*f(i))*y(i) - f(i-1)*y(i-1))/f(i+1)\n if (y(i) /= sign(y(i), y(i+1))) ncross=ncross+1\n end do\n\n print *, kkk, e, ncross, hnodes\n\n ! if iterating on energy: check number of crossings\n \n if (n_iter > 1) then\n\n if (ncross > hnodes) then\n ! too many crossings: current energy is too high\n ! lower the upper bound\n eup = e\n else \n ! too few (or correct number of crossings\n ! current energy is too low, raise the lower bound \n elw = e\n\n end if\n ! New trial value\n e=0.5_dp*(eup+elw)\n ! Convergence criterion: \n if (eup-elw < 1.d-10) exit iterate\n end if\n\n end do iterate\n\n ! Convergence has been achieved (or it want required) \n ! Note that the eavefunction is not normalized: \n ! THe problem is the divergence at alrge |x|\n\n ! Calculation of the classical probability density for energy e:\n\n norm = 0.0_dp\n p(icl:) = 0.0_dp\n do i=0,icl\n arg = (e-x(i)**2/2.0_dp)\n if (arg > 0.0_dp) then\n p(i) = 1.0_dp/sqrt(arg)\n else\n p(i) = 0.0_dp\n end if\n norm = norm + 2.0_dp*dx*p(i)\n end do\n\n ! The point at x=0 must be counter once\n norm = norm - dx*p(0)\n ! Normalize p(x) so that Int p(x)dx=1\n p(:icl-1) = p(:icl-1)/norm\n !lines starting with # ignored by gnuplot\n write(7, '(\"# x y(x) y(x)^2 classical p(x) V\")')\n ! x,0 region:\n do i=mesh,1,-1\n write(7,'(f7.2, 3e16.8, f12.6)') &\n -x(i), (-1)**nodes*y(i), y(i)*y(i), p(i), vpot(i)\n end do\n\n ! x>0 region\n do i=0, mesh\n write(7,'(f7.2, 3e16.8, f12.6)') &\n x(i), y(i), y(i)*y(i), p(i), vpot(i)\n end do\n ! two blank lines separating blocks of data, useful for gnuplot\n ! plotting\n write(7, '(/)')\n\n end do search_loop\n\nend program harmonic0\n \n\n\n \n\n\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "cf73b9570cbee8cba1b1bf37127f4239e527bc79", "size": 6019, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/assgn07_solns/Assgn07_numerov_method/Assgn07_harmonic0.f90", "max_stars_repo_name": "Anantha-Rao12/ComPhys", "max_stars_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Solutions/assgn07_solns/Assgn07_numerov_method/Assgn07_harmonic0.f90", "max_issues_repo_name": "Anantha-Rao12/ComPhys", "max_issues_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Solutions/assgn07_solns/Assgn07_numerov_method/Assgn07_harmonic0.f90", "max_forks_repo_name": "Anantha-Rao12/ComPhys", "max_forks_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.3684210526, "max_line_length": 79, "alphanum_fraction": 0.5251702941, "num_tokens": 1882, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029486, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.772694610458678}} {"text": "program integration1\n\n !\n ! Perform a basic integration\n !\n\n implicit none\n\n integer :: i, j\n real(8) :: x, y, integ\n\n\n integ = 0.0d0\n\n open(unit=1, file='integration1.dat', action='write')\n\n write(1, *) integ\n\n do j = 1, 10\n\n y = dble(j) * 1.0d0\n\n do i = 1, 10\n\n x = dble(i) * 2.5d-1\n\n integ = integ + sin(x + y)\n\n if (ceiling(dble(j)/2.0d0)*2 == j .and. ceiling(dble(i)/2.0d0)*2 == i) then\n \n write(1, *) integ\n\n end if\n\n end do\n\n end do\n\n close(1)\n\n write(*,'(a,e20.10e3)') 'Integration value = ', integ\n\nend program integration1\n", "meta": {"hexsha": "a6621f6622675fc65c8398663334fa81e2fe7026", "size": 607, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lectures1and2/example/integration1.f90", "max_stars_repo_name": "sdm900/fortran_course", "max_stars_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lectures1and2/example/integration1.f90", "max_issues_repo_name": "sdm900/fortran_course", "max_issues_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures1and2/example/integration1.f90", "max_forks_repo_name": "sdm900/fortran_course", "max_forks_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.7954545455, "max_line_length": 83, "alphanum_fraction": 0.5189456343, "num_tokens": 224, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476385, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.7726510240642286}} {"text": "!> The problem is to determine the values of x(1), x(2), ..., x(9)\n!> which solve the system of tridiagonal equations\n!> (3-2*x(1))*x(1) -2*x(2) = -1\n!> -x(i-1) + (3-2*x(i))*x(i) -2*x(i+1) = -1, i=2-8\n!> -x(8) + (3-2*x(9))*x(9) = -1\nprogram example_hybrd\n\n use minpack_module, only: wp, hybrd, enorm, dpmpar\n use iso_fortran_env, only: nwrite => output_unit\n\n implicit none\n\n integer,parameter :: n = 9\n integer,parameter :: ldfjac = n\n integer,parameter :: lr = (n*(n+1))/2\n\n integer :: maxfev, ml, mu, mode, nprint, info, nfev\n real(wp) :: epsfcn, factor, fnorm, xtol\n real(wp) :: x(n), fvec(n), diag(n), fjac(n, n), r(lr), qtf(n), &\n wa1(n), wa2(n), wa3(n), wa4(n)\n\n xtol = sqrt(dpmpar(1)) ! square root of the machine precision.\n maxfev = 2000\n ml = 1\n mu = 1\n epsfcn = 0.0_wp\n mode = 2\n factor = 100.0_wp\n nprint = 0\n diag = 1.0_wp\n x = -1.0_wp ! starting values to provide a rough solution.\n\n call hybrd(fcn, n, x, fvec, xtol, maxfev, ml, mu, epsfcn, diag, &\n mode, factor, nprint, info, nfev, fjac, ldfjac, &\n r, lr, qtf, wa1, wa2, wa3, wa4)\n fnorm = enorm(n, fvec)\n\n write (nwrite, '(5x,a,d15.7//5x,a,i10//5x,a,16x,i10//5x,a//(5x,3d15.7))') &\n \"FINAL L2 NORM OF THE RESIDUALS\", fnorm, &\n \"NUMBER OF FUNCTION EVALUATIONS\", nfev, &\n \"EXIT PARAMETER\", info, &\n \"FINAL APPROXIMATE SOLUTION\", x\n\n !> Results obtained with different compilers or machines\n !> may be slightly different.\n !>\n !>> FINAL L2 NORM OF THE RESIDUALS 0.1192636D-07\n !>>\n !>> NUMBER OF FUNCTION EVALUATIONS 14\n !>>\n !>> EXIT PARAMETER 1\n !>>\n !>> FINAL APPROXIMATE SOLUTION\n !>>\n !>> -0.5706545D+00 -0.6816283D+00 -0.7017325D+00\n !>> -0.7042129D+00 -0.7013690D+00 -0.6918656D+00\n !>> -0.6657920D+00 -0.5960342D+00 -0.4164121D+00\n\ncontains\n\n !> Subroutine fcn for hybrd example.\n subroutine fcn(n, x, fvec, iflag)\n\n implicit none\n integer, intent(in) :: n\n integer, intent(inout) :: iflag\n real(wp), intent(in) :: x(n)\n real(wp), intent(out) :: fvec(n)\n\n integer :: k !! counter\n real(wp) :: temp, temp1, temp2\n\n real(wp),parameter :: zero = 0.0_wp\n real(wp),parameter :: one = 1.0_wp\n real(wp),parameter :: two = 2.0_wp\n real(wp),parameter :: three = 3.0_wp\n\n if (iflag == 0) then\n !! Insert print statements here when nprint is positive.\n else\n do k = 1, n\n temp = (three - two*x(k))*x(k)\n temp1 = zero\n if (k /= 1) temp1 = x(k - 1)\n temp2 = zero\n if (k /= n) temp2 = x(k + 1)\n fvec(k) = temp - temp1 - two*temp2 + one\n end do\n end if\n\n end subroutine fcn\n\nend program example_hybrd\n", "meta": {"hexsha": "0db4319e7bf24350d11b51c971a9743aebbf311a", "size": 3005, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/example_hybrd.f90", "max_stars_repo_name": "awvwgk/minpack", "max_stars_repo_head_hexsha": "dc14d611af8d9c16d08039d6e5a6d45b766b8022", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2022-02-02T14:46:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T21:34:09.000Z", "max_issues_repo_path": "examples/example_hybrd.f90", "max_issues_repo_name": "fortran-lang/minpack", "max_issues_repo_head_hexsha": "c0b5aea9fcd2b83865af921a7a7e881904f8d3c2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 58, "max_issues_repo_issues_event_min_datetime": "2022-02-02T14:43:38.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-18T02:18:48.000Z", "max_forks_repo_path": "examples/example_hybrd.f90", "max_forks_repo_name": "awvwgk/minpack", "max_forks_repo_head_hexsha": "dc14d611af8d9c16d08039d6e5a6d45b766b8022", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2022-02-02T14:58:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T17:17:47.000Z", "avg_line_length": 31.9680851064, "max_line_length": 79, "alphanum_fraction": 0.5158069884, "num_tokens": 1048, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.7726510065415263}} {"text": "subroutine sphere_distance(lat1, lon1, nlat, nlon, gridlat, gridlon, dist)\n\n implicit none\n\n integer, parameter :: RKIND = selected_real_kind(12)\n integer :: nlat, nlon\n real (kind=RKIND), intent(in) :: lat1, lon1\n real (kind=RKIND), dimension(nlat,nlon) :: gridlat, gridlon\n real (kind=RKIND), dimension(nlat,nlon) :: dist\n\n ! local\n real (kind=RKIND), dimension(nlat,nlon) :: arg1\n real (kind=RKIND), parameter :: radius=1.0_RKIND\n\n arg1 = sqrt( sin(0.5*(gridlat-lat1))**2 + &\n cos(lat1)*cos(gridlat)*sin(0.5*(gridlon-lon1))**2 )\n dist = 2.*radius*asin(arg1)\n\nend subroutine sphere_distance\n\nsubroutine grid2mpas(nlat, nlon, gridlat, gridlon, gridvar, &\n ncell, latcell, loncell, var)\n\n implicit none\n\n integer, parameter :: RKIND = selected_real_kind(12)\n integer :: nlat, nlon, ncell\n real(kind=RKIND), dimension(nlat, nlon) :: gridlat ! [90, -90]\n real(kind=RKIND), dimension(nlat, nlon) :: gridlon ! [0, 360]\n real(kind=RKIND), dimension(nlat, nlon) :: gridvar\n real(kind=RKIND), dimension(ncell) :: latcell, loncell, var\n\n !f2py intent(in) nlat, nlon, gridlat, gridlon, gridvar\n !f2py intent(in) ncell, latcell, loncell\n !f2py intent(out) var\n\n ! ----- local vars -----\n integer :: icell\n integer :: latloc1, latloc2, lonloc1, lonloc2\n integer, dimension(1) :: loc1d\n integer, dimension(2) :: shp\n real(kind=RKIND), dimension(nlat) :: lat1d\n real(kind=RKIND), dimension(nlon) :: lon1d\n\n where(loncell<0) latcell=loncell+360\n where(gridlon<0) gridlat=gridlat+360\n\n lat1d=gridlat(:,1)\n lon1d=gridlon(1,:)\n do icell=1, ncell\n\n loc1d=minloc(abs(latcell(icell)-lat1d))\n latloc1=loc1d(1)-1\n latloc2=loc1d(1)+1\n if(latloc1<1 ) latloc1=1\n if(latloc2>nlat) latloc2=nlat\n\n loc1d=minloc(abs(loncell(icell)-lon1d))\n lonloc1=loc1d(1)-1\n lonloc2=loc1d(1)+1\n if(lonloc1<1 ) lonloc1=1\n if(lonloc2>nlon) lonloc2=nlon\n\n shp=shape(gridvar(latloc1:latloc2,lonloc1:lonloc2)) \n var(icell)=SUM(gridvar(latloc1:latloc2,lonloc1:lonloc2))/(shp(1)*shp(2))\n\n end do\n\n return\nend subroutine grid2mpas\n \n \n", "meta": {"hexsha": "303f6562c3c0b9509433587aae7b9a09ad09b05b", "size": 2098, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/grid2mpas.f90", "max_stars_repo_name": "xtian15/MPAS-SW-TL-AD", "max_stars_repo_head_hexsha": "d6ac1597ac4a6c1ee3339e8384dd6bef42eccbfc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/grid2mpas.f90", "max_issues_repo_name": "xtian15/MPAS-SW-TL-AD", "max_issues_repo_head_hexsha": "d6ac1597ac4a6c1ee3339e8384dd6bef42eccbfc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/grid2mpas.f90", "max_forks_repo_name": "xtian15/MPAS-SW-TL-AD", "max_forks_repo_head_hexsha": "d6ac1597ac4a6c1ee3339e8384dd6bef42eccbfc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.7397260274, "max_line_length": 77, "alphanum_fraction": 0.6673021926, "num_tokens": 767, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947148047777, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7726035631626949}} {"text": "!Autor: Claudio Iván Esparza Castañeda\n!Título: División de dos polinomios\n!Descripción: Se encarga de dividir un polinomio de grado n entre uno de grado m, el resultado es un polinomio de grado (n-m) con un residuo (m-1)\n!Fecha: 19/02/2020\n\nprogram DivPoli\n !Inicio del programa\n implicit none !Sin variables implícitas\n REAL, allocatable, dimension(:)::a, b, c, d, e, f !Vector tipo REAL con dimensión dinámica\n INTEGER::i, j, m, n !Variables enteras\n WRITE(*, *) \"Grado del polinomio mayor\" !Preguntar por el grado del polinomio\n READ(*, *) m\n WRITE(*, *) \"Grado del polinomio menor\" !Preguntar por el grado del polinomio\n READ(*, *) n\n allocate(a(0:m), b(0:m), c(0:m), d(0:m), e(0:m)) !Asignar valor a variables dinámica\n WRITE(*, *) \"Coeficientes del polinomio mayor a0+a1x+a2x²+...amx^m\" !Pregunta coeficientes del polinomio\n do i=0, m \n READ(*, *) a(i)\n end do\n WRITE(*, *) \"Coeficientes del polinomio menor b0+b1x+b2x²+...bnx^n, con n= max(1,N) \n!\n! N (input) INTEGER\n! The number of linear equations, i.e., the order of the\n! matrix A. N > 0.\n!\n! NRHS (input) INTEGER\n! The number of right hand sides, i.e., the number of columns\n! of the matrix B. NRHS >= 0.\n!\n! B (input/output) array, dimension (LDB,NRHS)\n! On entry, the N-by-NRHS matrix of right hand side matrix B.\n! On exit, if INFO = 0, the N-by-NRHS solution matrix X.\n!\n! LDB (input) INTEGER\n! The leading dimension of the array B. LDB >= max(1,N). \n!\n! IPIV IPIV is INTEGER array, dimension (N)\n! The pivot indices that define the permutation matrix P;\n! row i of the matrix was interchanged with row IPIV(i).\n!\n! INFO INFO is INTEGER\n! = 0: successful exit\n! < 0: if INFO = -i, the i-th argument had an illegal value\n! > 0: if INFO = i, U(i,i) is exactly zero so the solution could not be computed. \n\n! .. Scalar Arguments ..\n INTEGER,INTENT(IN) :: LDA, LDB, N, NRHS\n INTEGER, INTENT(OUT) :: INFO \n! ..\n! .. Array Arguments ..\n REAL(wp),INTENT(INOUT) :: A( LDA, * ), B( LDB, * )\n \n! .. Work space .. \n INTEGER :: ipiv(N),icol(N),irow(N),i,j,k,ii,jj,index_row,index_col\n REAL(wp) :: largest,swap(N),temp,pivot,swap2(NRHS)\n \n info = 0\n IF( N.LT.0 ) THEN\n info = -1\n ELSE IF( NRHS.LT.0 ) THEN\n info = -2\n ELSE IF( LDA.LT.max( 1, N ) ) THEN\n info = -4\n ELSE IF( LDB.LT.max( 1, N ) ) THEN\n info = -6\n END IF\n IF( info.NE.0 ) THEN\n! CALL xerbla( 'GAUSSJ ', -info )\n RETURN\n END IF\n \n ipiv=0 \n do i=1,N\n largest=0 \n do j=1,N\n if(ipiv(j) == 1) then \n cycle\n endif \n do k=1,N\n if (ipiv(k) > 1) then\n info=ipiv(k)\n write(*,*) 'Singular matrix in GaussJordan' \n RETURN\n endif\n if(ipiv(k) == 1) then \n cycle\n endif \n if(largest >= ABS(A(j,k))) then \n exit\n endif \n index_row=j\n index_col=k\n largest=ABS(A(j,k))\n end do\n end do\n ipiv(index_col)=ipiv(index_col)+1\n irow(i)=index_row \n icol(i)=index_col\n if (index_row /= index_col) then \n swap(1:N)=A(index_row,1:N)\n A(index_row,1:N)=A(index_col,1:N)\n A(index_col,1:N)=swap(1:N)\n swap2(1:NRHS)=B(index_row,1:NRHS)\n B(index_row,1:NRHS)=B(index_col,1:NRHS)\n B(index_col,1:NRHS)=swap2(1:NRHS) \n endif\n pivot=A(index_col,index_col) \n A(index_col,index_col)=1\n A(index_col,1:N)=A(index_col,1:N)/pivot \n B(index_col,1:NRHS)=B(index_col,1:NRHS)/pivot\n do jj=1,N\n if (jj == index_col) then\n cycle\n endif\n temp=A(jj,index_col)\n A(jj,index_col)=0 \n A(jj,1:N)=A(jj,1:N)-A(index_col,1:N)*temp\n B(jj,1:NRHS)=B(jj,1:NRHS)-B(index_col,1:NRHS)*temp\n end do \n end do \n ii=1\n do i=1,N\n ii=N-i+1\n if (irow(ii) == icol(ii)) then\n cycle\n endif \n index_row=irow(ii) \n index_col=icol(ii) \n swap(1:N)=A(1:N,index_row)\n A(1:N,index_row)=A(1:N,index_col)\n A(1:N,index_col)=swap(1:N) \n end do \n \n END SUBROUTINE GaussJordan \n", "meta": {"hexsha": "1388d13563319f6437aa3b4af2d155399bfc1d0f", "size": 3877, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gauss-jordan.f90", "max_stars_repo_name": "mostlyharmlessone/cyclic-banded-matrix", "max_stars_repo_head_hexsha": "f1eef4a91d37cbf58301601f0ac0e5a4b126908d", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-08-13T11:04:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-17T11:50:21.000Z", "max_issues_repo_path": "gauss-jordan.f90", "max_issues_repo_name": "mostlyharmlessone/cyclic-banded-matrix", "max_issues_repo_head_hexsha": "f1eef4a91d37cbf58301601f0ac0e5a4b126908d", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gauss-jordan.f90", "max_forks_repo_name": "mostlyharmlessone/cyclic-banded-matrix", "max_forks_repo_head_hexsha": "f1eef4a91d37cbf58301601f0ac0e5a4b126908d", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.8230769231, "max_line_length": 92, "alphanum_fraction": 0.5395924684, "num_tokens": 1275, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.8539127510928477, "lm_q1q2_score": 0.7724926272056182}} {"text": " SUBROUTINE ROTAT ( THETA, I, R )\n IMPLICIT None\nC\nC 1. ROTAT\nC\nC 1.1 ROTAT PROGRAM SPECIFICATION\nC\nC 1.1.1 ROTAT is the matrix utility routine which creates a matrix 'R' which\nC performs a coordinate system rotation by an angle 'THETA' about \nC coordinate axis 'I' in the counterclockwise direction looking along the\nC axis towards the origin.\nC\nC 1.1.2 RESTRICTIONS - NONE\nC\nC 1.1.3 REFERENCES - NONE\nC\nC 1.2 ROTAT PROGRAM INTERFACE\nC\nC 1.2.1 CALLING SEQUENCE -\nC \nC INPUT VARIABLES:\nC 1. I - THE INTEGER FLAG WHICH DETERMINES THE ROTATION AXIS.\nC (I = 1, 2, 3 REFERS RESPECTIVELY TO ROTATIONS ABOUT\nC THE X, Y, AND Z AXES.) \nC 2. THETA - THE ANGLE THROUGH WHICH THE COORDINATE SYSTEM \nC ROTATION IS PERFORMED. (RAD)\nC \nC OUTPUT VARIABLES: \nC 1. R(3,3) - THE 3x3 ROTATION MATRIX WHICH PERFORMS THE \nC COORDINATE SYSTEM ROTATION. (UNITLESS)\nC \nC 1.2.2 COMMON BLOCKS USED -\nC \n INCLUDE 'ccon.i' \nC \nC VARIABLES 'FROM':\nC 1. KMATC - THE MATRIX UTILITY ROUTINE FLOW CONTROL FLAG.\nC 2. KMATD - THE MATRIX UTILITY ROUTINE DEBUG OUTPUT FLAG.\nC \nC VARIABLES 'TO': NONE \nC \nC 1.2.3 PROGRAM SPECIFICATIONS -\nC \n Real*8 R(3,3), THETA, C, S \n Integer*2 I\nC \nC 1.2.4 DATA BASE ACCESS - NONE \nC \nC 1.2.5 EXTERNAL INPUT/OUTPUT - NONE\nC \nC OUTPUT VARIABLES:\nC 1. POSSIBLE DEBUG OUTPUT\nC \nC 1.2.6 SUBROUTINE INTERFACE -\nC \nC CALLER SUBROUTINES: DIRNL, ETDG, NUTG, PREG, SITI, WOBG \nC CALLED SUBROUTINES: DCOS, DSIN\nC \nC 1.2.7 CONSTANTS USED - NONE \nC \nC 1.2.8 PROGRAM VARIABLES - \nC 1. C - THE COSINE OF THE ROTATION ANGLE THETA. (UNITLESS)\nC 2. S - THE SINE OF THE ROTATION ANGLE THETA. (UNITLESS)\nC\nC 1.2.9 PROGRAMMER - DALE MARKHAM 01/19/77\nC PETER DENATALE 07/18/77\nC SAVITA GOEL 06/04/87 (CDS FOR A900)\nC Jim Ryan 89.07.25 Documentation simplified.\nC David Gordon 94.04.15 Converted to Implicit None.\nC\nC ROTAT Program structure\nC\nC Compute the cosine and sine of the rotation angle THETA.\n C = DCOS ( THETA )\n S = DSIN ( THETA )\nC\nC Go to the right logic depending to the axix of rotation.\n IF ( I .EQ. 1 ) GO TO 300\n IF ( I .EQ. 2 ) GO TO 400\n IF ( I .EQ. 3 ) GO TO 500\nC\nC Rotation about the X-axis.\nC\nC ( 1 0 0 )\nC R(X) = ( 0 C S )\nC ( 0 -S C )\nC\n 300 R(1,1) = 1.D0\n R(2,1) = 0.D0\n R(3,1) = 0.D0\n R(1,2) = 0.D0\n R(2,2) = +C\n R(3,2) = -S\n R(1,3) = 0.D0\n R(2,3) = +S\n R(3,3) = +C\n GO TO 600\nC\nC Rotation about the Y-axis.\nC\nC ( C 0 -S )\nC R(Y) = ( 0 1 0 )\nC ( S 0 C )\nC\n 400 R(1,1) = +C\n R(2,1) = 0.D0\n R(3,1) = +S\n R(1,2) = 0.D0\n R(2,2) = 1.D0\n R(3,2) = 0.D0\n R(1,3) = -S\n R(2,3) = 0.D0\n R(3,3) = +C\n GO TO 600\nC\nC Rotation about the Z-axis.\nC\nC ( C S 0 )\nC R(Z) = (-S C 0 )\nC ( 0 0 1 )\nC\n 500 R(1,1) = +C\n R(2,1) = -S\n R(3,1) = 0.D0\n R(1,2) = +S\n R(2,2) = +C\n R(3,2) = 0.D0\n R(1,3) = 0.D0\n R(2,3) = 0.D0\n R(3,3) = 1.D0\n GO TO 600\nC\nC Check KMATD for debug output.\n 600 IF ( KMATD .EQ. 0 ) GO TO 700\n WRITE ( 6, 9)\n 9 FORMAT (1X, \"Debug output for utility ROTAT.\" )\n WRITE ( 6, 9200 ) C, S, I, THETA, R\n 9200 FORMAT (1X, \"C = \", D30.16, /, 1X,\n 1 'S = ', D30.16, /, 1X,\n 2 'I = ', I2, /, 1X,\n 3 'THETA = ', D30.16, /, 1X,\n 4 'R = ', 3 ( 3 ( D30.16, 10X ), /, 1X ) )\nC\nC Normal conclusion.\n 700 RETURN\n END\nC\nC******************************************************************************\n SUBROUTINE DROTT ( THETA, DTHETA, I, DR )\n IMPLICIT None\nC\nC 2. DROTT\nC\nC 2.1 DROTT PROGRAM SPECIFICATION\nC\nC 2.1.1 DROTT is the matrix utility routine which creates the partial derivative\nC of a rotation matrix with respect to a variable on which the rotation\nC matrix is functionally dependent.\nC\nC 2.1.2 RESTRICTIONS - NONE\nC\nC 2.1.3 REFERENCES - NONE\nC\nC 2.2 DROTT PROGRAM INTERFACE\nC\nC 2.2.1 CALLING SEQUENCE -\nC\nC INPUT VARIABLES:\nC 1. DTHETA - THE PARTIAL DERIVATIVE OF THE ROTATION ANGLE THETA\nC WITH RESPECT TO THE VARIABLE IN QUESTION.\nC 2. I - THE INTEGER FLAG WHICH DETERMINES THE ROTATION AXIS.\nC (I = 1, 2, 3 REFERS RESPECTIVELY TO ROTATIONS ABOUT\nC THE X, Y, AND Z AXES.)\nC 3. THETA - THE ANGLE THROUGH WHICH THE COORDINATE SYSTEM \nC ROTATION IS PERFORMED. (RAD) \nC \nC OUTPUT VARIABLES: \nC 1. DR(3,3) - THE PARTIAL DERIVATIVE OF THE ROTATION MATRIX IN\nC QUESTION WITH RESPECT TO THE VARIABLE IN QUESTION. \nC \nC 2.2.2 COMMON BLOCKS USED -\nC \n INCLUDE 'ccon.i' \nC \nC VARIABLES 'FROM':\nC 1. KMATC - THE MATRIX UTILITY ROUTINE FLOW CONTROL FLAG.\nC 2. KMATD - THE MATRIX UTILITY ROUTINE DEBUG OUTPUT FLAG.\nC \nC VARIABLES 'TO': NONE \nC \nC 2.2.3 PROGRAM SPECIFICATIONS -\nC \n Real*8 DR(3,3), THETA, DTHETA, DC, DS\n Integer*2 I\nC \nC 2.2.4 DATA BASE ACCESS - NONE \nC \nC 2.2.5 EXTERNAL INPUT/OUTPUT - \nC 1. POSSIBLE DEBUG OUTPUT\nC \nC 2.2.6 SUBROUTINE INTERFACE -\nC CALLER SUBROUTINES: DIRNL, NUTG, PREG, PREP, UT1P, WOBP \nC CALLED SUBROUTINES: DCOS, DSIN\nC \nC 2.2.7 CONSTANTS USED - NONE \nC \nC 2.2.8 PROGRAM VARIABLES - \nC \nC 1. DC - THE COSINE OF THE ROTATION ANGLE (THETA) MULTIPLIED BY\nC THE PARTIAL DERIVATIVE OF THE ROTATION ANGLE WITH\nC RESPECT TO THE VARIABLE IN QUESTION (DTHETA).\nC 2. DS - THE SINE OF THE ROTATION ANGLE (THETA) MULTIPLIED BY THE\nC PARTIAL DERIVATIVE OF THE ROTATION ANGLE WITH RESPECT TO\nC THE VARIABLE IN QUESTION (DTHETA).\nC\nC 2.2.9 PROGRAMMER - DALE MARKHAM 01/19/77\nC PETER DENATALE 07/18/77\nC Jim Ryan 89.07.25 Documentation simplified.\nC David Gordon 94.04.15 Converted to Implicit None.\nC\nC DROTT Program Structure\nC\nC Compute the program variables DC and DS.\n DC = DCOS ( THETA ) * DTHETA\n DS = DSIN ( THETA ) * DTHETA\nC\nC Go to the correct logic depending on the axis of rotation.\n IF ( I .EQ. 1 ) GO TO 300\n IF ( I .EQ. 2 ) GO TO 400\n IF ( I .EQ. 3 ) GO TO 500\nC\nC Rotation about the X-axis.\nC\nC ( 0 0 0 )\nC DR(X) = ( 0 -DS DC )\nC ( 0 -DC -DS )\nC\n 300 DR(1,1) = 0.D0\n DR(2,1) = 0.D0\n DR(3,1) = 0.D0\n DR(1,2) = 0.D0\n DR(2,2) = -DS\n DR(3,2) = -DC\n DR(1,3) = 0.D0\n DR(2,3) = +DC\n DR(3,3) = -DS\n GO TO 600\nC\nC Rotation about the Y-axis.\nC\nC (-DS 0 -DC )\nC DR(Y) = ( 0 0 0 )\nC ( DC 0 -DS )\nC\n 400 DR(1,1) = -DS\n DR(2,1) = 0.D0\n DR(3,1) = +DC\n DR(1,2) = 0.D0\n DR(2,2) = 0.D0\n DR(3,2) = 0.D0\n DR(1,3) = -DC\n DR(2,3) = 0.D0\n DR(3,3) = -DS\n GO TO 600\nC\nC Rotation about the Z-axis.\nC\nC (-DS DC 0 )\nC DR(Z) = (-DC -DS 0 )\nC ( 0 0 0 )\nC\n 500 DR(1,1) = -DS\n DR(2,1) = -DC\n DR(3,1) = 0.D0\n DR(1,2) = +DC\n DR(2,2) = -DS\n DR(3,2) = 0.D0\n DR(1,3) = 0.D0\n DR(2,3) = 0.D0\n DR(3,3) = 0.D0\n GO TO 600\nC\nC Check KMATD for debug output.\n 600 IF ( KMATD .EQ. 0 ) GO TO 700\n WRITE ( 6, 9)\n 9 FORMAT (1X, \"Debug output for utility DROTT.\" )\n WRITE ( 6, 9200 ) DC, DS, DTHETA, I, THETA, DR\n 9200 FORMAT (1X, \"DC = \", D30.16, /, 1X,\n 1 'DS = ', D30.16, /, 1X,\n 2 'DTHETA = ', D30.16, /, 1X,\n 3 'I = ', I2, /, 1X,\n 4 'THETA = ', D30.16, /, 1X,\n 5 'DR = ', 3 ( 3 ( D30.16, 10X ), /, 1X ) )\nC\nC 7. NORMAL PROGRAM CONCLUSION.\nC\n 700 RETURN\n END\nC\nC******************************************************************************\n SUBROUTINE DDROT ( THETA, DDTHTA, I, DDR )\n IMPLICIT None\nC\nC 3. DDROT\nC\nC 3.1 DDROT PROGRAM SPECIFICATION\nC\nC 3.1.1 DDROT is the matrix utility routine which creates the second\nC partial derivative of a rotation matrix with respect to a\nC variable on which the rotation matrix is functionally dependent.\nC\nC 3.1.2 RESTRICTIONS - THIS UTILITY ROUTINE ASSUMES THAT THE SECOND PARTIAL\nC DERIVATIVE OF THE FUNCTIONALLY DEPENDENT VARIABLE WITH\nC RESPECT TO THE PARAMETER IN QUESTION IS EQUAL TO ZERO.\nC THIS IS A VERY GOOD ASSUMPTION IN ALL CASES WHERE\nC SUBROUTINE DDROT IS USED IN THIS PROGRAM.\nC\nC 3.1.3 REFERENCES - NONE\nC\nC 3.2 DDROT PROGRAM INTERFACE\nC\nC 3.2.1 CALLING SEQUENCE -\nC\nC INPUT VARIABLES:\nC 1. DDTHTA - THE SECOND PARTIAL DERIVATIVE OF THE ROTATION ANGLE\nC THETA WITH RESPECT TO THE VARIABLE IN QUESTION.\nC 2. I - THE INTEGER FLAG WHICH DETERMINES THE ROTATION AXIS.\nC (I = 1, 2, 3 REFERS RESPECTIVELY TO ROTATIONS ABOUT\nC THE X, Y, AND Z AXES. )\nC 3. THETA - THE ANGLE THROUGH WHICH THE COORDINATE SYSTEM \nC ROTATION IS PERFORMED. (RAD) \nC \nC OUTPUT VARIABLES: \nC 1. DDR(3,3) - THE SECOND PARTIAL DERIVATIVE OF THE ROTATION \nC MATRIX IN QUESTION WITH RESPECT TO THE VARIABLE IN\nC QUESTION. \nC \nC 3.2.2 COMMON BLOCKS USED -\nC \n INCLUDE 'ccon.i' \nC \nC VARIABLES 'FROM':\nC 1. KMATC - THE MATRIX UTILITY ROUTINE FLOW CONTROL FLAG.\nC 2. KMATD - THE MATRIX UTILITY ROUTINE DEBUG OUTPUT FLAG.\nC \nC VARIABLES 'TO': NONE \nC \nC 3.2.3 PROGRAM SPECIFICATIONS -\nC \n Real*8 DDR(3,3), THETA, DDTHTA, DDC, DDS\n Integer*2 I \nC \nC 3.2.4 DATA BASE ACCESS - NONE \nC \nC 3.2.5 EXTERNAL INPUT/OUTPUT - \nC 1. POSSIBLE DEBUG OUTPUT\nC \nC 3.2.6 SUBROUTINE INTERFACE -\nC CALLER SUBROUTINES: DIRNL, UT1P \nC CALLED SUBROUTINES: DCOS, DSIN\nC \nC 3.2.7 CONSTANTS USED - NONE \nC \nC 3.2.8 PROGRAM VARIABLES -\nC 1. DDC - THE COSINE OF THE ROTATION ANGLE MULTIPLIED BY THE\nC SECOND PARTIAL DERIVATIVE OF THE ROTATION ANGLE WITH\nC RESPECT TO THE VARIABLE IN QUESTION.\nC 2. DDS - THE SINE OF THE ROTATION ANGLE MULTIPLIED BY THE SECOND\nC PARTIAL DERIVATIVE OF THE ROTATION ANGLE WITH RESPECT\nC TO THE VARIABLE IN QUESTION.\nC\nC 3.2.9 PROGRAMMER - DALE MARKHAM 01/19/77\nC PETER DENATALE 07/18/77\nC Jim Ryan 89.07.25 Documentation simplified.\nC David Gordon 94.04.15 Converted to Implicit None.\nC\nC DDROT Program Structure\nC\nC Compute the program variables DDC and DDS.\n DDC = DCOS ( THETA ) * DDTHTA\n DDS = DSIN ( THETA ) * DDTHTA\nC\nC Go to the correct logic depending of the axis of rotation.\n IF ( I .EQ. 1 ) GO TO 300\n IF ( I .EQ. 2 ) GO TO 400\n IF ( I .EQ. 3 ) GO TO 500\nC\nC Rotation ablut the X-axis.\nC\nC ( 0 0 0 )\nC DDR(X) = ( 0 -DDC -DDS )\nC ( 0 DDS -DDC )\nC\n 300 DDR(1,1) = 0.D0\n DDR(2,1) = 0.D0\n DDR(3,1) = 0.D0\n DDR(1,2) = 0.D0\n DDR(2,2) = -DDC\n DDR(3,2) = +DDS\n DDR(1,3) = 0.D0\n DDR(2,3) = -DDS\n DDR(3,3) = -DDC\n GO TO 600\nC\nC Rotation about the Y-axis.\nC\nC (-DDC 0 DDS )\nC DDR(Y) = ( 0 0 0 )\nC (-DDS 0 -DDC )\nC\n 400 DDR(1,1) = -DDC\n DDR(2,1) = 0.D0\n DDR(3,1) = -DDS\n DDR(1,2) = 0.D0\n DDR(2,2) = 0.D0\n DDR(3,2) = 0.D0\n DDR(1,3) = +DDS\n DDR(2,3) = 0.D0\n DDR(3,3) = -DDC\n GO TO 600\nC\nC Rotation about the Z-axis.\nC\nC (-DDC -DDS 0 )\nC DDR(Z) = ( DDS -DDC 0 )\nC ( 0 0 0 )\nC\n 500 DDR(1,1) = -DDC\n DDR(2,1) = +DDS\n DDR(3,1) = 0.D0\n DDR(1,2) = -DDS\n DDR(2,2) = -DDC\n DDR(3,2) = 0.D0\n DDR(1,3) = 0.D0\n DDR(2,3) = 0.D0\n DDR(3,3) = 0.D0\n GO TO 600\nC\nC Check KMATD for debug output.\n 600 IF ( KMATD .EQ. 0 ) GO TO 700\n WRITE ( 6, 9)\n 9 FORMAT (1X, \"Debug output for subroutine DDROT.\" )\n WRITE ( 6, 9200 ) THETA, I, DDTHTA, DDR\n 9200 FORMAT (1X, \"THETA = \", D30.16, /, 1X,\n 1 'I = ', I2, /, 1X,\n 2 'DDTHTA = ', D30.16, /, 1X,\n 3 'DDR = ', 3 ( 3 ( D30.16, 10X ), /, 1X ) )\nC\nC Normal Conclusion.\n 700 RETURN\n END\nC\nC*******************************************************************************\n SUBROUTINE D3ROT ( THETA, D3THET, I, D3R )\n IMPLICIT None\nC\nC 2. D3ROT\nC\nC 2.1 D3ROT PROGRAM SPECIFICATION\nC\nC 2.1.1 D3ROT is the matrix utility routine which creates the third partial\nC derivative of a rotation matrix with respect to a variable on which\nC the rotation matrix is functionally dependent.\nC\nC 2.1.2 RESTRICTIONS - NONE\nC\nC 2.1.3 REFERENCES - NONE\nC\nC 2.2 D3ROT PROGRAM INTERFACE\nC\nC 2.2.1 CALLING SEQUENCE - CALL D3ROT(THETA,D3THET,I,D3R)\nC\nC INPUT VARIABLES:\nC 1. D3THET - THE THIRD PARTIAL DERIVATIVE OF THE ROTATION ANGLE\nC THETA WITH RESPECT TO THE VARIABLE IN QUESTION. \nC 2. I - THE INTEGER FLAG WHICH DETERMINES THE ROTATION AXIS.\nC (I = 1, 2, 3 REFERS RESPECTIVELY TO ROTATIONS ABOUT\nC THE X, Y, AND Z AXES.)\nC 3. THETA - THE ANGLE THROUGH WHICH THE COORDINATE SYSTEM\nC ROTATION IS PERFORMED. (RAD) \nC \nC OUTPUT VARIABLES: \nC 1. D3R(3,3) - THE THIRD PARTIAL DERIVATIVE OF THE ROTATION MATRIX\nC IN QUESTION WITH RESPECT TO THE VARIABLE IN \nC QUESTION. \nC \nC 2.2.2 COMMON BLOCKS USED -\nC \n INCLUDE 'ccon.i' \nC \nC VARIABLES \"FROM\":\nC 1. KMATC - THE MATRIX UTILITY ROUTINE FLOW CONTROL FLAG.\nC 2. KMATD - THE MATRIX UTILITY ROUTINE DEBUG OUTPUT FLAG.\nC \nC VARIABLES 'TO': NONE \nC \nC 2.2.3 PROGRAM SPECIFICATIONS -\nC \n Real*8 D3R(3,3), THETA, D3THET, D3C, D3S\n Integer*2 I\nC \nC 2.2.4 DATA BASE ACCESS - NONE \nC \nC 2.2.5 EXTERNAL INPUT/OUTPUT - \nC 1. POSSIBLE DEBUG OUTPUT\nC \nC 2.2.6 SUBROUTINE INTERFACE -\nC CALLER SUBROUTINES: DIRNL, NUTG, PREG, PREP, UT1P, WOBP \nC CALLED SUBROUTINES: DCOS, DSIN\nC \nC 2.2.7 CONSTANTS USED - NONE \nC\nC 2.2.8 PROGRAM VARIABLES -\nC 1. D3C - THE COSINE OF THE ROTATION ANGLE (THETA) MULTIPLIED BY \nC THE SECOND PARTIAL DERIVATIVE OF THE ROTATION ANGLE WITH\nC RESPECT TO THE VARIABLE IN QUESTION (DTHETA).\nC 2. D3S - THE SINE OF THE ROTATION ANGLE (THETA) MULTIPLIED BY THE\nC SECOND PARTIAL DERIVATIVE OF THE ROTATION ANGLE WITH\nC RESPECT TO THE VARIABLE IN QUESTION (DTHETA).\nC\nC 2.2.9 PROGRAMMER - DALE MARKHAM 01/19/77\nC PETER DENATALE 07/18/77\nC BRUCE SCHUPLER 03/27/78\nC Jim Ryan 89.07.25 Documentation simplified.\nC David Gordon 94.04.15 Converted to Implicit None.\nC\nC D3ROT Program Structure\nC\nC Compute the program variables D3C and D3S.\n D3C = DCOS ( THETA ) * D3THET\n D3S = DSIN ( THETA ) * D3THET\nC\nC Go to the correct logic depending on the axis of rotation.\n IF ( I .EQ. 1 ) GO TO 300\n IF ( I .EQ. 2 ) GO TO 400\n IF ( I .EQ. 3 ) GO TO 500\nC\nC Rotation about the X-axis.\nC\nC ( 0 0 0 )\nC D3R(X) = ( 0 +D3S -D3C )\nC ( 0 +D3C +D3S )\nC\n 300 D3R(1,1) = 0.D0\n D3R(2,1) = 0.D0\n D3R(3,1) = 0.D0\n D3R(1,2) = 0.D0\n D3R(2,2) = +D3S\n D3R(3,2) = +D3C\n D3R(1,3) = 0.D0\n D3R(2,3) = -D3C\n D3R(3,3) = +D3S\n GO TO 600\nC\nC Rotation about the y-axis.\nC\nC (+D3S 0 +D3C )\nC D3R(Y) = ( 0 0 0 )\nC (-D3C 0 +D3S )\nC\n 400 D3R(1,1) = +D3S\n D3R(2,1) = 0.D0\n D3R(3,1) = -D3C\n D3R(1,2) = 0.D0\n D3R(2,2) = 0.D0\n D3R(3,2) = 0.D0\n D3R(1,3) = +D3C\n D3R(2,3) = 0.D0\n D3R(3,3) = +D3S\n GO TO 600\nC\nC Rotation about the Z-axis.\nC\nC (+D3S -D3C 0 )\nC D3R(Z) = (+D3C +D3S 0 )\nC ( 0 0 0 )\nC\n 500 D3R(1,1) = +D3S\n D3R(2,1) = +D3C\n D3R(3,1) = 0.D0\n D3R(1,2) = -D3C\n D3R(2,2) = +D3S\n D3R(3,2) = 0.D0\n D3R(1,3) = 0.D0\n D3R(2,3) = 0.D0\n D3R(3,3) = 0.D0\n GO TO 600\nC\nC Check KMATD for debug output.\n 600 IF ( KMATD .EQ. 0 ) GO TO 700\n WRITE ( 6, 9)\n 9 FORMAT (1X, \"Debug output for utility D3ROT.\" )\n WRITE ( 6, 9200 ) D3C, D3S, D3THET, I, THETA, D3R\n 9200 FORMAT (1X, \"D3C = \", D30.16, /, 1X,\n 1 'D3S = ', D30.16, /, 1X,\n 2 'D3THET = ', D30.16, /, 1X,\n 3 'I = ', I2, /, 1X,\n 4 'THETA = ', D30.16, /, 1X,\n 5 'D3R = ', 3 ( 3 ( D30.16, 10X ), /, 1X ) )\nC\nC Normal conclusion.\n 700 RETURN\n END\nC\nC******************************************************************************\n SUBROUTINE MMUL2 ( A, B, C )\n IMPLICIT None\nC\nC 4. MMUL2\nC\nC 4.1 MMUL2 PROGRAM SPECIFICATION\nC\nC 4.1.1 MMUL2 is the matrix utility which multiplies two rotation matrices\nC producing a product rotation matrix.\nC\nC 4.1.2 RESTRICTIONS - NONE\nC\nC 4.1.3 REFERENCES - NONE\nC \nC 4.2 MMUL2 PROGRAM INTERFACE \nC \nC 4.2.1 CALLING SEQUENCE -\nC \nC INPUT VARIABLES:\nC 1. A(3,3) - THE FIRST ROTATION MATRIX. \nC 2. B(3,3) - THE SECOND ROTATION MATRIX.\nC \nC OUTPUT VARIABLES: \nC 1. C(3,3) - THE PRODUCT OF ROTATION MATRICES A AND B.\nC \nC 4.2.2 COMMON BLOCKS USED -\nC \n INCLUDE 'ccon.i' \nC \nC VARIABLES 'FROM':\nC 1. KMATC - THE MATRIX UTILITY ROUTINE FLOW CONTROL FLAG.\nC 2. KMATD - THE MATRIX UTILITY ROUTINE DEBUG OUTPUT FLAG.\nC \nC VARIABLES 'TO': NONE \nC \nC 4.2.3 PROGRAM SPECIFICATIONS -\nC \n Real*8 A(3,3), B(3,3), C(3,3) \n Integer*2 I, J\nC \nC 4.2.4 DATA BASE ACCESS - NONE \nC \nC 4.2.5 EXTERNAL INPUT/OUTPUT - \nC 1. POSSIBLE DEBUG OUTPUT\nC\nC 4.2.6 SUBROUTINE INTERFACE -\nC CALLER SUBROUTINES: MMUL3, SITI, WOBG, WOBP\nC CALLED SUBROUTINES: NONE\nC\nC 4.2.7 CONSTANTS USED - NONE\nC\nC 4.2.8 PROGRAM VARIABLES - NONE\nC\nC 4.2.9 PROGRAMMER - DALE MARKHAM 01/19/77\nC PETER DENATALE 07/18/77\nC Jim Ryan 89.07.25 Documentation simplified.\nC David Gordon 94.04.15 Converted to Implicit None.\nC\nC MMUL2 Program Structure\nC\nC Perform the multiplication.\n DO 120 J = 1,3\n DO 110 I = 1,3\n C(I,J) = A(I,1) * B(1,J)\n 1 + A(I,2) * B(2,J)\n 2 + A(I,3) * B(3,J)\n 110 CONTINUE\n 120 CONTINUE\nC\nC Check KMATD for debug output.\n IF ( KMATD. EQ. 0 ) GO TO 300\n WRITE ( 6, 9)\n 9 FORMAT (1X, \"Debug output for utility MMUL2.\" )\n WRITE ( 6, 9200 ) A, B, C\n 9200 FORMAT (1X, \"A = \", 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 1 'B = ', 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 2 'C = ', 3 ( 3 ( D30.16, 10X ), /, 1X ) )\nC\n 300 RETURN\n END\nC\nC******************************************************************************\n SUBROUTINE MMUL3 ( A, B, C, D )\n IMPLICIT None\nC\nC 5. MMUL3\nC\nC 5.1 MMUL3 PROGRAM SPECIFICATION\nC\nC 5.1.1 MMUL3 is the matrix utility routine which multiplies together\nC three rotation matrices producing a product rotation matrix.\nC\nC 5.1.2 RESTRICTIONS - NONE\nC \nC 5.1.3 REFERENCES - NONE \nC \nC 5.2 MMUL3 PROGRAM INTERFACE \nC \nC 5.2.1 CALLING SEQUENCE -\nC \nC INPUT VARIABLES:\nC 1. A(3,3) - THE FIRST ROTATION MATRIX. \nC 2. B(3,3) - THE SECOND ROTATION MATRIX.\nC 3. C(3,3) - THE THIRD ROTATION MATRIX. \nC \nC OUTPUT VARIABLES: \nC 1. D(3,3) - THE PRODUCT OF ROTATION MATRICES A, B, AND C. \nC \nC 5.2.2 COMMON BLOCKS USED -\nC \n INCLUDE 'ccon.i' \nC \nC VARIABLES \"FROM\":\nC 1. KMATC - THE MATRIX UTILITY ROUTINE FLOW CONTROL FLAG.\nC 2. KMATD - THE MATRIX UTILITY ROUTINE DEBUG OUTPUT FLAG.\nC \nC VARIABLES 'TO': NONE \nC \nC 5.2.3 PROGRAM SPECIFICATIONS -\nC \n Real*8 A(3,3), AB(3,3), B(3,3), C(3,3), D(3,3)\nC \nC 5.2.4 DATA BASE ACCESS - NONE \nC \nC 5.2.5 EXTERNAL INPUT/OUTPUT - \nC 1. POSSIBLE DEBUG OUTPUT\nC \nC 5.2.6 SUBROUTINE INTERFACE -\nC CALLER SUBROUTINES: MMUL5, NUTG, PREG, PREP \nC CALLED SUBROUTINES: MMUL2 \nC \nC 5.2.7 CONSTANTS USED - NONE \nC\nC 5.2.8 PROGRAM VARIABLES -\nC 1. AB(3,3) - THE PRODUCT OF ROTATION MATRICES A AND B.\nC\nC 5.2.9 PROGRAMMER - DALE MARKHAM 01/19/77\nC PETER DENATALE 07/18/77\nC Jim Ryan 89.07.25 Documentation simplified.\nC David Gordon 94.04.15 Converted to Implicit None.\nC\nC MMUL3 Program Structure\nC\nC Perform the multiplications.\n CALL MMUL2 ( A, B, AB )\n CALL MMUL2 ( AB, C, D )\nC\nC Check KMATD to for debug output.\n IF ( KMATD .EQ. 0 ) GO TO 300\n WRITE ( 6, 9)\n 9 FORMAT (1X, \"Debug output for utility MMUL3.\" )\n WRITE ( 6, 9200 ) A, B, C\n 9200 FORMAT (1X, \"A = \", 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 1 'B = ', 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 2 'C = ', 3 ( 3 ( D30.16, 10X ), /, 1X ) )\nC\n 300 RETURN\n END\nC\nC******************************************************************************\n SUBROUTINE MMUL5 ( A, B, C, D, E, F )\n IMPLICIT None\nC\nC 6. MMUL5\nC\nC 6.1 MMUL5 PROGRAM SPECIFICATION\nC\nC 6.1.1 MMUL5 is the matrix utility routine which multiplies together\nC five rotation matrices producing a product rotation matrix.\nC \nC 6.1.2 RESTRICTIONS - NONE \nC \nC 6.1.3 REFERENCES - NONE \nC \nC 6.2 MMUL5 PROGRAM INTERFACE \nC \nC 6.2.1 CALLING SEQUENCE -\nC \nC INPUT VARIABLES:\nC 1. A(3,3) - THE FIRST ROTATION MATRIX. \nC 2. B(3,3) - THE SECOND ROTATION MATRIX.\nC 3. C(3,3) - THE THIRD ROTATION MATRIX. \nC 4. D(3,3) - THE FOURTH ROTATION MATRIX.\nC 5. E(3,3) - THE FIFTH ROTATION MATRIX. \nC \nC OUTPUT VARIABLES: \nC 1. F(3,3) - THE PRODUCT OF ROTATION MATRICES A, B, C, D, AND E.\nC \nC 6.2.2 COMMON BLOCKS USED -\nC \n INCLUDE 'ccon.i' \nC \nC VARIABLES 'FROM':\nC 1. KMATC - THE MATRIX UTILITY ROUTINE FLOW CONTROL FLAG.\nC 2. KMATD - THE MATRIX UTILITY ROUTINE DEBUG OUTPUT FLAG.\nC \nC VARIABLES 'TO': NONE \nC \nC 6.2.3 PROGRAM SPECIFICATIONS -\nC \n Real*8 A(3,3), ABC(3,3), B(3,3), C(3,3), D(3,3), E(3,3), F(3,3) \nC \nC 6.2.4 DATA BASE ACCESS - NONE \nC \nC 6.2.5 EXTERNAL INPUT/OUTPUT - \nC 1. POSSIBLE DEBUG OUTPUT\nC \nC 6.2.6 SUBROUTINE INTERFACE -\nC CALLER SUBROUTINES: M1950, PREP, UT1P, WOBP\nC CALLED SUBROUTINES: MMUL3\nC\nC 6.2.7 CONSTANTS USED - NONE\nC\nC 6.2.8 PROGRAM VARIABLES -\nC 1. ABC(3,3) - THE PRODUCT OF ROTATION MATRICES A, B, AND C.\nC\nC 6.2.9 PROGRAMMER - DALE MARKHAM 01/19/77\nC PETER DENATALE 07/18/77\nC Jim Ryan 89.07.25 Documentation simplified.\nC David Gordon 94.04.15 Converted to Implicit None.\nC\nC MMUL5 Program Structure\nC\nC Perform the multiplications\n CALL MMUL3 ( A, B, C, ABC )\n CALL MMUL3 ( ABC, D, E, F )\nC\nC Check KMATD for debug output.\n IF ( KMATD .EQ. 0 ) GO TO 300\n WRITE ( 6, 9)\n 9 FORMAT (1X, \"Debug output for utililty MMUL5.\" )\n WRITE ( 6, 9200 ) A, ABC, B, C, D, E, F\n 9200 FORMAT (1X, \"A = \", 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 1 'ABC = ', 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 2 'B = ', 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 3 'C = ', 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 4 'D = ', 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 5 'E = ', 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 6 'F = ', 3 ( 3 ( D30.16, 10X ), /, 1X ) )\nC\n 300 RETURN\n END\nC\nC******************************************************************************\n SUBROUTINE MADD2 ( A, B, C )\n IMPLICIT None\nC\nC 7. MADD2\nC\nC 7.1 MADD2 PROGRAM SPECIFICATION\nC\nC 7.1.1 MADD2 is the matrix utility which adds togeter two matrices.\nC\nC 7.1.2 RESTRICTIONS - NONE\nC\nC 7.1.3 REFERENCES - NONE\nC\nC 7.2 MADD2 PROGRAM INTERFACE\nC\nC 7.2.1 CALLING SEQUENCE -\nC \nC INPUT VARIABLES:\nC 1. A(3,3) - THE FIRST ROTATION MATRIX. \nC 2. B(3,3) - THE SECOND ROTATION MATRIX.\nC \nC OUTPUT VARIABLES: \nC 1. C(3,3) - THE SUM OF ROTATION MATRICES A AND B.\nC \nC 7.2.2 COMMON BLOCKS USED -\nC \n INCLUDE 'ccon.i' \nC \nC VARIABLES 'FROM':\nC 1. KMATC - THE MATRIX UTILITY ROUTINE FLOW CONTROL FLAG.\nC 2. KMATD - THE MATRIX UTILITY ROUTINE DEBUG OUTPUT FLAG.\nC \nC VARIABLES 'TO': NONE \nC \nC 7.2.3 PROGRAM SPECIFICATIONS -\nC \n Real*8 A(3,3), B(3,3), C(3,3) \n Integer*2 I, J\nC \nC 7.2.4 DATA BASE ACCESS - NONE \nC \nC 7.2.5 EXTERNAL INPUT/OUTPUT - \nC 1. POSSIBLE DEBUG OUTPUT\nC\nC 7.2.6 SUBROUTINE INTERFACE -\nC CALLER SUBROUTINES: NONE\nC CALLED SUBROUTINES: NONE\nC\nC 7.2.7 CONSTANTS USED - NONE\nC\nC 7.2.8 PROGRAM VARIABLES - NONE\nC\nC 7.2.9 PROGRAMMER - DALE MARKHAM 01/19/77\nC PETER DENATALE 07/18/77\nC Jim Ryan 89.07.25 Documentation simplified.\nC David Gordon 94.04.15 Converted to Implicit None.\nC\nC MADD2 Program Structure\nC\nC Do the addition.\n DO 120 J = 1,3\n DO 110 I = 1,3\n C(I,J) = A(I,J) + B(I,J)\n 110 CONTINUE\n 120 CONTINUE\nC\nC Check KMATD for debug output.\n IF ( KMATD .EQ. 0 ) GO TO 300\n WRITE ( 6, 9100 )\n 9100 FORMAT (1X, \"DEBUG OUTPUT FOR SUBROUTINE MADD2.\" )\n WRITE ( 6, 9200 ) A, B, C\n 9200 FORMAT (1X, \"A = \", 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 1 'B = ', 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 2 'C = ', 3 ( 3 ( D30.16, 10X ), /, 1X ) )\nC\n 300 RETURN\n END\nC\nC******************************************************************************\n SUBROUTINE MADD3 ( A, B, C, D )\n IMPLICIT None\nC\nC 8. MADD3\nC\nC 8.1 MADD3 PROGRAM SPECIFICATION\nC\nC 8.1.1 MADD3 adds together three matrices.\nC\nC 8.1.2 RESTRICTIONS - NONE\nC\nC 8.1.3 REFERENCES - NONE\nC\nC 8.2 MADD3 PROGRAM INTERFACE\nC\nC 8.2.1 CALLING SEQUENCE -\nC\nC INPUT VARIABLES:\nC 1. A(3,3) - THE FIRST ROTATION MATRIX.\nC 2. B(3,3) - THE SECOND ROTATION MATRIX.\nC 3. C(3,3) - THE THIRD ROTATION MATRIX.\nC \nC OUTPUT VARIABLES: \nC 1. D(3,3) - THE SUM OF ROTATION MATRICES A, B, AND C. \nC \nC 8.2.2 COMMON BLOCKS USED -\nC \n INCLUDE 'ccon.i' \nC \nC VARIABLES 'FROM':\nC 1. KMATC - THE MATRIX UTILITY ROUTINE FLOW CONTROL FLAG.\nC 2. KMATD - THE MATRIX UTILITY ROUTINE DEBUG OUTPUT FLAG.\nC \nC VARIABLES 'TO': NONE \nC \nC 8.2.3 PROGRAM SPECIFICATIONS -\nC \n Real*8 A(3,3), B(3,3), C(3,3), D(3,3) \n Integer*2 I, J\nC \nC 8.2.4 DATA BASE ACCESS - NONE \nC \nC 8.2.5 EXTERNAL INPUT/OUTPUT - \nC 1. POSSIBLE DEBUG OUTPUT\nC \nC 8.2.6 SUBROUTINE INTERFACE -\nC CALLER SUBROUTINES: M1950, NUTG, PREG, PREP\nC CALLED SUBROUTINES: NONE\nC\nC 8.2.7 CONSTANTS USED - NONE\nC\nC 8.2.8 PROGRAM VARIABLES - NONE\nC\nC 8.2.9 PROGRAMMER - DALE MARKHAM 01/19/77\nC PETER DENATALE 07/18/77\nC Jim Ryan 89.07.25 Documentation simplified.\nC David Gordon 94.04.15 Converted to Implicit None.\nC\nC MADD3 PROGRAM STRUCTURE\nC\nC Do the additions.\n DO 120 J = 1,3\n DO 110 I = 1,3\n D(I,J) = A(I,J) + B(I,J) + C(I,J)\n 110 CONTINUE\n 120 CONTINUE\nC\nC Check KMATD for debug output.\n IF ( KMATD .EQ. 0 ) GO TO 300\n WRITE ( 6, 9100 )\n 9100 FORMAT (1X, \"DEBUG OUTPUT FOR SUBROUTINE MADD3.\" )\n WRITE ( 6, 9200 ) A, B, C, D\n 9200 FORMAT (1X, \"A = \", 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 1 'B = ', 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 2 'C = ', 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 3 'D = ', 3 ( 3 ( D30.16, 10X ), /, 1X ) )\nC\n 300 RETURN\n END\nC\nC******************************************************************************\n SUBROUTINE MADD4 ( A, B, C, D, E )\n IMPLICIT None\nC\nC 8. MADD4\nC\nC 8.1 MADD4 PROGRAM SPECIFICATION\nC\nC 8.1.1 MADD4 adds together four matrices.\nC\nC 8.1.2 RESTRICTIONS - NONE\nC\nC 8.1.3 REFERENCES - NONE\nC\nC 8.2 MADD4 PROGRAM INTERFACE\nC\nC 8.2.1 CALLING SEQUENCE -\nC\nC INPUT VARIABLES:\nC 1. A(3,3) - THE FIRST ROTATION MATRIX.\nC 2. B(3,3) - THE SECOND ROTATION MATRIX.\nC 3. C(3,3) - THE THIRD ROTATION MATRIX.\nC 4. D(3,3) - THE FOURTH ROTATION MATRIX.\nC \nC OUTPUT VARIABLES: \nC 1. E(3,3) - THE SUM OF ROTATION MATRICES A, B, C, AND D. \nC \nC 8.2.2 COMMON BLOCKS USED -\nC \n INCLUDE 'ccon.i' \nC \nC VARIABLES 'FROM':\nC 1. KMATC - THE MATRIX UTILITY ROUTINE FLOW CONTROL FLAG.\nC 2. KMATD - THE MATRIX UTILITY ROUTINE DEBUG OUTPUT FLAG.\nC \nC VARIABLES 'TO': NONE \nC \nC 8.2.3 PROGRAM SPECIFICATIONS -\nC \n Real*8 A(3,3), B(3,3), C(3,3), D(3,3), E(3,3) \n Integer*2 I, J\nC \nC 8.2.4 DATA BASE ACCESS - NONE \nC \nC 8.2.5 EXTERNAL INPUT/OUTPUT - POSSIBLE DEBUG OUTPUT\nC \nC 8.2.6 SUBROUTINE INTERFACE -\nC CALLER SUBROUTINES: M2000, ?\nC CALLED SUBROUTINES: NONE\nC\nC 8.2.7 CONSTANTS USED - NONE\nC\nC 8.2.8 PROGRAM VARIABLES - NONE\nC\nC 8.2.9 PROGRAMMER - 95.12.11 David Gordon Created from MADD3\nC\nC MADD4 PROGRAM STRUCTURE\nC\nC Do the additions.\n DO 120 J = 1,3\n DO 110 I = 1,3\n E(I,J) = A(I,J) + B(I,J) + C(I,J) + D(I,J)\n 110 CONTINUE\n 120 CONTINUE\nC\nC Check KMATD for debug output.\n IF ( KMATD .EQ. 0 ) GO TO 300\n WRITE ( 6, 9100 )\n 9100 FORMAT (1X, \"DEBUG OUTPUT FOR SUBROUTINE MADD4.\" )\n WRITE ( 6, 9200 ) A, B, C, D, E\n 9200 FORMAT (1X, \"A = \", 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 1 'B = ', 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 2 'C = ', 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 3 'D = ', 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 4 'E = ', 3 ( 3 ( D30.16, 10X ), /, 1X ) )\nC\n 300 RETURN\n END\nC\nC******************************************************************************\n SUBROUTINE MADD5 ( A, B, C, D, E, F )\n IMPLICIT None\nC\nC 9. MADD5\nC\nC 9.1 MADD5 PROGRAM SPECIFICATION\nC\nC 9.1.1 MADD5 adds together five matrices.\nC\nC 9.1.2 RESTRICTIONS - NONE\nC\nC 9.1.3 REFERENCES - NONE\nC\nC 9.2 MADD5 PROGRAM INTERFACE\nC\nC 9.2.1 CALLING SEQUENCE -\nC\nC INPUT VARIABLES:\nC 1. A(3,3) - THE FIRST ROTATION MATRIX.\nC 2. B(3,3) - THE SECOND ROTATION MATRIX.\nC 3. C(3,3) - THE THIRD ROTATION MATRIX. \nC 4. D(3,3) - THE FOURTH ROTATION MATRIX.\nC 5. E(3,3) - THE FIFTH ROTATION MATRIX. \nC \nC OUTPUT VARIABLES: \nC 1. F(3,3) - THE SUM OF ROTATION MATRICES A, B, C, D, AND E. \nC \nC 9.2.2 COMMON BLOCKS USED -\nC \n INCLUDE 'ccon.i' \nC \nC VARIABLES 'FROM':\nC 1. KMATC - THE MATRIX UTILITY ROUTINE FLOW CONTROL FLAG.\nC 2. KMATD - THE MATRIX UTILITY ROUTINE DEBUG OUTPUT FLAG.\nC \nC VARIABLES 'TO': NONE \nC \nC 9.2.3 PROGRAM SPECIFICATIONS -\nC \n Real*8 A(3,3), B(3,3), C(3,3), D(3,3), E(3,3), F(3,3) \n Integer*2 I,J\nC \nC 9.2.4 DATA BASE ACCESS - NONE \nC \nC 9.2.5 EXTERNAL INPUT/OUTPUT - \nC 1. POSSIBLE DEBUG OUTPUT\nC\nC 9.2.6 SUBROUTINE INTERFACE -\nC CALLER SUBROUTINES: M1950\nC CALLED SUBROUTINES: NONE\nC\nC 9.2.7 CONSTANTS USED - NONE\nC\nC 9.2.8 PROGRAM VARIABLES - NONE\nC\nC 9.2.9 PROGRAMMER - DALE MARKHAM 01/19/77\nC PETER DENATALE 07/18/77\nC Jim Ryan 89.07.25 Documentation simplified.\nC David Gordon 94.04.15 Converted to Implicit None.\nC\nC MADD5 Program Structure\nC\nC Do the additons.\n DO 120 J = 1,3\n DO 110 I = 1,3\n F(I,J) = A(I,J) + B(I,J) + C(I,J) + D(I,J) + E(I,J)\n 110 CONTINUE\n 120 CONTINUE\nC\nC Check KMATD for debug output.\n IF ( KMATD .EQ. 0 ) GO TO 300\n WRITE ( 6, 9100 )\n 9100 FORMAT (1X, \"DEBUG OUTPUT FOR SUBROUTINE MADD5.\" )\n WRITE ( 6, 9200 ) A, B, C, D, E, F\n 9200 FORMAT (1X, \"A = \", 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 1 'B = ', 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 2 'C = ', 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 3 'D = ', 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 4 'E = ', 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 5 'F = ', 3 ( 3 ( D30.16, 10X ), /, 1X ) )\nC\n 300 RETURN\n END\nC\nC******************************************************************************\n SUBROUTINE MTRAN ( A, B )\n IMPLICIT None\nC\nC10. MTRAN\nC\nC10.1 MTRAN PROGRAM SPECIFICATION\nC\nC10.1.1 MTRAN constructs the transpose of a matrix.\nC\nC10.1.2 RESTRICTIONS - NONE\nC \nC10.1.3 REFERENCES - NONE \nC \nC10.2 MTRAN PROGRAM INTERFACE \nC \nC10.2.1 CALLING SEQUENCE -\nC \nC INPUT VARIABLES:\nC 1. A(3,3) - THE ROTATION MATRIX TO BE TRANSPOSED.\nC \nC OUTPUT VARIABLES: \nC 1. B(3,3) - THE TRANSPOSE OF THE ROTATION MATRIX A.\nC \nC10.2.2 COMMON BLOCKS USED -\nC \n INCLUDE 'ccon.i' \nC \nC VARIABLES 'FROM':\nC 1. KMATC - THE MATRIX UTILITY ROUTINE FLOW CONTROL FLAG.\nC 2. KMATD - THE MATRIX UTILITY ROUTINE DEBUG OUTPUT FLAG.\nC \nC VARIABLES 'TO': NONE \nC \nC10.2.3 PROGRAM SPECIFICATIONS -\nC \n Real*8 A(3,3), B(3,3) \n Integer*2 I, J\nC \nC10.2.4 DATA BASE ACCESS - NONE \nC \nC10.2.5 EXTERNAL INPUT/OUTPUT - \nC 1. POSSIBLE DEBUG OUTPUT\nC\nC10.2.6 SUBROUTINE INTERFACE -\nC CALLER SUBROUTINES: ATMG, AXOG\nC CALLED SUBROUTINES: NONE\nC\nC10.2.7 CONSTANTS USED - NONE\nC\nC10.2.8 PROGRAM VARIABLES - NONE\nC\nC10.2.9 PROGRAMMER - DALE MARKHAM 01/19/77\nC PETER DENATALE 07/18/77\nC Jim Ryan 89.07.25 Documentation simplified.\nC David Gordon 94.04.15 Converted to Implicit None.\nC\nC MTRAN Program Structure\nC\nC Do the transpostion.\n DO 120 J = 1,3\n DO 110 I = 1,3\n B(I,J) = A(J,I)\n 110 CONTINUE\n 120 CONTINUE\nC\nC Check KMATD for debug output.\n IF ( KMATD .EQ. 0 ) GO TO 300\n WRITE ( 6, 9100 )\n 9100 FORMAT (1X, \"Debug output for utility MTRAN.\" )\n WRITE ( 6, 9200 ) A, B\n 9200 FORMAT (1X, \"A = \", 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 1 'B = ', 3 ( 3 ( D30.16, 10X ), /, 1X ) )\nC\n 300 RETURN\n END\nC\nC*****************************************************************************\n SUBROUTINE VECRT ( A, V, RV )\n IMPLICIT None \nC\nC11. VECRT\nC\nC11.1 VECRT PROGRAM SPECIFICATION\nC\nC11.1.1 VECRT is the matrix utility which multiplies a vector by a rotation\nC matrix.\nC\nC11.1.2 RESTRICTIONS - NONE\nC\nC11.1.3 REFERENCES - NONE\nC\nC11.2 VECRT PROGRAM INTERFACE\nC\nC11.2.1 CALLING SEQUENCE -\nC\nC INPUT VARIABLES:\nC 1. A(3,3) - THE ROTATION MATRIX PERFORMING THE COORDINATE SYSTEM\nC ROTATION.\nC 2. V(3) - THE VECTOR BEING ROTATED BY THE ROTATION MATRIX. \nC \nC OUTPUT VARIABLES: \nC 1. RV(3) - THE ROTATED VECTOR.\nC \nC11.2.2 COMMON BLOCKS USED -\nC \n INCLUDE 'ccon.i' \nC \nC VARIABLES 'FROM':\nC 1. KMATC - THE MATRIX UTILITY ROUTINE FLOW CONTROL FLAG.\nC 2. KMATD - THE MATRIX UTILITY ROUTINE DEBUG OUTPUT FLAG.\nC \nC VARIABLES 'TO': NONE \nC \nC11.2.3 PROGRAM SPECIFICATIONS -\nC \n Real*8 A(3,3), V(3), RV(3)\n Integer*2 I\nC \nC11.2.4 DATA BASE ACCESS - NONE \nC \nC11.2.5 EXTERNAL INPUT/OUTPUT - \nC 1. POSSIBLE DEBUG OUTPUT\nC \nC11.2.6 SUBROUTINE INTERFACE -\nC CALLER SUBROUTINES: ATMG, AXOG, ETDG, ETDP, PREP, ROSIT, UT1P, WOBP\nC CALLED SUBROUTINES: NONE\nC\nC11.2.7 CONSTANTS USED - NONE\nC\nC11.2.8 PROGRAM VARIABLES - NONE\nC\nC11.2.9 PROGRAMMER - DALE MARKHAM 01/19/77\nC PETER DENATALE 07/18/77\nC Jim Ryan 89.07.25 Documentation simplified.\nC David Gordon 94.04.15 Converted to Implicit None.\nC\nC VECRT PROGRAM STRUCTURE\nC\nC Perform the rotation.\n DO 100 I = 1,3\n RV(I) = A(I,1) * V(1)\n 1 + A(I,2) * V(2)\n 2 + A(I,3) * V(3)\n 100 CONTINUE\nC\nC Check KMATD for debug output.\n IF ( KMATD .EQ. 0 ) GO TO 300\n WRITE ( 6, 9)\n 9 FORMAT (1X, \"Debug output for utility VECRT.\" )\n WRITE ( 6, 9200 ) A, V, RV\n 9200 FORMAT (1X, \"A = \", 3 ( 3 ( D30.16, 10X ), /, 1X ),\n 1 'V = ', 3 ( D30.16, 10X ), /, 1X,\n 2 'RV = ', 3 ( D30.16, 10X ) )\nC\n 300 RETURN\n END\n", "meta": {"hexsha": "a2fbc50e900ab1dc0307669fc25bdcb87fbc8577", "size": 38201, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "calc9.1/cmatu.f", "max_stars_repo_name": "liulei/VOLKS", "max_stars_repo_head_hexsha": "eb459cef8f10a8f27a37eb633c5d070fa39f5279", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc9.1/cmatu.f", "max_issues_repo_name": "liulei/VOLKS", "max_issues_repo_head_hexsha": "eb459cef8f10a8f27a37eb633c5d070fa39f5279", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc9.1/cmatu.f", "max_forks_repo_name": "liulei/VOLKS", "max_forks_repo_head_hexsha": "eb459cef8f10a8f27a37eb633c5d070fa39f5279", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-12-13T21:30:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-06T03:06:51.000Z", "avg_line_length": 28.722556391, "max_line_length": 80, "alphanum_fraction": 0.5169236407, "num_tokens": 14194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947456, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.772475506210506}} {"text": "! initial_field.f90\n! author: sunder\n\n!-----------------------------------------------------------------------\n! Definition of initial condition\n!-----------------------------------------------------------------------\n\nsubroutine initial_field(q0, xp)\n use ader_weno\n use constants, only : m_pi\n implicit none\n ! Argument list \n double precision, intent(out) :: q0(nVar)\n double precision, intent(in) :: xp\n ! Local variable declaration \n double precision :: F1, G1, F2, G2, F3, G3\n double precision, parameter :: alpha = 10.0, a = 0.5, z = -0.7, delta = 0.005, beta = log(2.0)/(36.0*delta*delta)\n\n \n if (ICType .eq. 1) then\n q0(1) = sin(m_pi*xp)\n else if (ICType .eq. 2) then\n q0(1) = sin(m_pi*xp + (1.0d0/m_pi)*SIN(m_pi*xp))\n else if (ICType .eq. 3) then\n q0(1) = sin(m_pi*xp)**4\n else if (ICType .eq. 4) then\n if ((-0.5d0 .lt. xp) .AND. (xp .LT. 0.5d0)) then\n q0(1) = 1.0d0\n else\n q0(1) = 0.0d0\n end if\n else if (ICType .eq. 5) then\n F1 = sqrt(max(1.0 - alpha*alpha*(xp-a)*(xp-a) , 0.0d0 ))\n G1 = exp(-beta*(xp-z)*(xp-z))\n F2 = sqrt(max(1.0 - alpha*alpha*(xp-(a-delta))*(xp-(a-delta)) , 0.0d0 ))\n G2 = exp(-beta*(xp-(z-delta))*(xp-(z-delta)))\n F3 = sqrt(max(1.0 - alpha*alpha*(xp-(a+delta))*(xp-(a+delta)) , 0.0d0 ))\n G3 = exp(-beta*(xp-(z+delta))*(xp-(z+delta)))\n\n if (xp .ge. -0.8d0 .and. xp .lt. -0.6d0) then\n q0(1) = (1.0d0/6.0d0)*(4.0d0*G1 + G2 + G3)\n else if (xp .ge. -0.4d0 .and. xp .lt. -0.2d0) then\n q0(1) = 1.0d0\n else if (xp .ge. 0.0d0 .and. xp .lt. 0.2d0) then\n q0(1) = 1.0d0 - abs(10.0d0*(xp - 0.1d0))\n else if (xp .ge. 0.4d0 .and. xp .lt. 0.6d0) then\n q0(1) = (1.0d0/6.0d0)*(4.0d0*F1 + F2 + F3)\n else\n q0(1) = 0.0d0\n end if\n\n \n end if\n \nend subroutine initial_field\n\n", "meta": {"hexsha": "3945e3a75aef04fe3b9cabf2e60730c793ab5e3b", "size": 1942, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ADER-WENO-1D-LINEAR-CONVECTION/initial_field.f90", "max_stars_repo_name": "dasikasunder/ADER-WENO", "max_stars_repo_head_hexsha": "8d40b341be7610ac89a144077a9f759a0154909a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-19T07:50:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-19T07:50:53.000Z", "max_issues_repo_path": "ADER-WENO-1D-LINEAR-CONVECTION/initial_field.f90", "max_issues_repo_name": "dasikasunder/ADER-WENO", "max_issues_repo_head_hexsha": "8d40b341be7610ac89a144077a9f759a0154909a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ADER-WENO-1D-LINEAR-CONVECTION/initial_field.f90", "max_forks_repo_name": "dasikasunder/ADER-WENO", "max_forks_repo_head_hexsha": "8d40b341be7610ac89a144077a9f759a0154909a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.0701754386, "max_line_length": 117, "alphanum_fraction": 0.4706488157, "num_tokens": 770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810451666345, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7723358099425288}} {"text": " FUNCTION JONSWAP_spectrum(FREQ, Hs, Tp, gamma)\n!\n! This function returns the value of the JONSWAP spectrum\n! for the frequency FREQ, significant wave height Hs, and peak period\n! Tp.\n\n IMPLICIT none\n integer, parameter :: long=selected_real_kind(12,99)\n REAL(kind=long) :: jonswap_spectrum, Hs, Tp, A, B, a_exp, alpha, gamma, &\n sigma, freq, f_p, four=4._long, pi, zero=0._long, one=1._long, &\n two=2._long, half=.5_long, five=5._long, grav=9.82_long\n pi = acos (-one)\n f_p=one/Tp\n alpha=3.32285_long * Hs**2 * f_p**4\n A=alpha*grav**2/(two*pi)**4\n B=five/four * f_p**4\n\n IF (freq.le.zero) then \n jonswap_spectrum = zero\n ELSEIF(freq<=f_p)THEN\n sigma=.07_long\n a_exp=exp(-half*((freq-f_p)/(sigma*f_p))**2)\n jonswap_spectrum = A/freq**5 * exp(-B/freq**4) * gamma**a_exp\n ELSE\n sigma=.09_long\n a_exp=exp(-half*((freq-f_p)/(sigma*f_p))**2)\n jonswap_spectrum = A/freq**5 * exp(-B/freq**4) * gamma**a_exp\n ENDIF\n RETURN\n END FUNCTION JONSWAP_spectrum\n", "meta": {"hexsha": "dbca06037fbbb0dea836ce13baa1d4b58eb172cb", "size": 1025, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utilities/JONSWAP_spectrum.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/utilities/JONSWAP_spectrum.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/utilities/JONSWAP_spectrum.f90", "max_forks_repo_name": "apengsigkarup/OceanWave3D", "max_forks_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-01T12:17:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T16:23:37.000Z", "avg_line_length": 33.064516129, "max_line_length": 76, "alphanum_fraction": 0.6390243902, "num_tokens": 361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377225508371, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7722288458763492}} {"text": "*dk solvsym3\n subroutine solvsym3(a11,a12,a13,a22,a23,a33,\n & b1,b2,b3,x1,x2,x3)\nC #####################################################################\nC\nC PURPOSE -\nC\nC Solve 3x3 linear system \"AX=B\" for symmetric A using\nC Cramer's Rule.\nC\nC INPUT ARGUMENTS -\nC\nC A11,A12,A13,A22,A23,A33 - Coefficients of a symmetric 3x3\nC matrix.\nC B1,B2,B3 - Righthand side vector.\nC\nC\nC OUTPUT ARGUMENTS -\nC\nC X1,X2,X3 - Solution vector.\nC\nC CHANGE HISTORY -\nC$Log: solvsym3.f,v $\nCRevision 2.00 2007/11/09 20:04:03 spchu\nCImport to CVS\nC\nCPVCS \nCPVCS Rev 1.2 Mon Apr 14 17:02:00 1997 pvcs\nCPVCS No change.\nCPVCS \nCPVCS Rev 1.1 06/02/95 23:45:38 kuprat\nCPVCS Commented out print statement\nCPVCS \nCPVCS Rev 1.0 02/15/95 13:37:56 dcg\nCPVCS Original version\nC\nC ######################################################################\n implicit none\n real*8 a11,a12,a13,a22,a23,a33,b1,b2,b3,x1,x2,x3\n real*8 c11,c12,c13,c22,c23,c33,det\n \n c11=a22*a33-a23**2\n c12=a13*a23-a12*a33\n c13=a12*a23-a22*a13\n c22=a11*a33-a13**2\n c23=a13*a12-a11*a23\n c33=a11*a22-a12**2\n \n det=a11*c11+a12*c12+a13*c13\n \n if (det.eq.0.) then\nccccc print*,'Solvsym3: Zero determinant!!'\n x1=0.\n x2=0.\n x3=0.\n else\n x1=(b1*c11+b2*c12+b3*c13)/det\n x2=(b1*c12+b2*c22+b3*c23)/det\n x3=(b1*c13+b2*c23+b3*c33)/det\n endif\n return\n end\n", "meta": {"hexsha": "b0f981b517d15a1fbf48bb4cd4b45d77dd002e93", "size": 1590, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/solvsym3.f", "max_stars_repo_name": "millerta/LaGriT-1", "max_stars_repo_head_hexsha": "511ef22f3b7e839c7e0484604cd7f6a2278ae6b9", "max_stars_repo_licenses": ["CNRI-Python"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2017-02-09T17:54:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T22:22:32.000Z", "max_issues_repo_path": "src/solvsym3.f", "max_issues_repo_name": "millerta/LaGriT-1", "max_issues_repo_head_hexsha": "511ef22f3b7e839c7e0484604cd7f6a2278ae6b9", "max_issues_repo_licenses": ["CNRI-Python"], "max_issues_count": 166, "max_issues_repo_issues_event_min_datetime": "2017-01-26T17:15:45.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T21:36:28.000Z", "max_forks_repo_path": "src/lg_core/solvsym3.f", "max_forks_repo_name": "daniellivingston/LaGriT", "max_forks_repo_head_hexsha": "decd0ce0e5dab068034ef382cabcd134562de832", "max_forks_repo_licenses": ["Intel"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2017-02-08T21:56:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T06:48:36.000Z", "avg_line_length": 25.2380952381, "max_line_length": 72, "alphanum_fraction": 0.5081761006, "num_tokens": 581, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.7722201391845706}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n!\n!\n! ... file sfvpgc.f\n!\n! this file includes documentation and code for\n! subroutine sfvpgc i\n!\n! ... files which must be loaded with sfvpgc.f\n!\n! type_SpherepackUtility.f, type_RealPeriodicFastFourierTransform.f, vhagc.f, shsgc.f, compute_gaussian_latitudes_and_weights.f\n!\n!\n! subroutine sfvpgc(nlat, nlon, isym, nt, sf, vp, idv, jdv, br, bi, cr, ci, \n! + mdb, ndb, wshsgc, lshsgc, work, lwork, ierror)\n!\n! given the vector spherical harmonic coefficients br, bi, cr, ci, \n! computed by subroutine vhagc for a vector field (v, w), sfvpgc\n! computes a scalar stream function sf and scalar velocity potential\n! vp for (v, w). (v, w) is expressed in terms of sf and vp by the\n! helmholtz relations (in mathematical spherical coordinates):\n!\n! v = -1/sint*d(vp)/dlambda + d(st)/dtheta\n!\n! w = 1/sint*d(st)/dlambda + d(vp)/dtheta\n!\n! where sint = sin(theta). w is the east longitudinal and v\n! is the colatitudinal component of the vector field from which\n! br, bi, cr, ci were precomputed. required associated legendre\n! polynomials are recomputed rather than stored as they are in\n! subroutine sfvpgs. sf(i, j) and vp(i, j) are given at the i(th)\n! gaussian colatitude point theta(i) (see nlat description below)\n! and east longitude lambda(j) = (j-1)*2*pi/nlon on the sphere.\n!\n! input parameters\n!\n! nlat the number of points in the gaussian colatitude grid on the\n! full sphere. these lie in the interval (0, pi) and are computed\n! in radians in theta(1) <...< theta(nlat) by subroutine compute_gaussian_latitudes_and_weights.\n! if nlat is odd the equator will be included as the grid point\n! theta((nlat + 1)/2). if nlat is even the equator will be\n! excluded as a grid point and will lie half way between\n! theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\n! note: on the half sphere, the number of grid points in the\n! colatitudinal direction is nlat/2 if nlat is even or\n! (nlat + 1)/2 if nlat is odd.\n!\n! nlon the number of distinct londitude points. nlon determines\n! the grid increment in longitude as 2*pi/nlon. for example\n! nlon = 72 for a five degree grid. nlon must be greater than\n! 3. the efficiency of the computation is improved when nlon\n! is a product of small prime numbers.\n!\n!\n! isym a parameter which determines whether the stream function and\n! velocity potential are computed on the full or half sphere\n! as follows:\n!\n! = 0\n!\n! the symmetries/antsymmetries described in isym=1, 2 below\n! do not exist in (v, w) about the equator. in this case st\n! and vp are not necessarily symmetric or antisymmetric about\n! the equator. sf and vp are computed on the entire sphere.\n! i.e., in arrays sf(i, j), vp(i, j) for i=1, ..., nlat and\n! j=1, ..., nlon.\n!\n! = 1\n!\n! w is antisymmetric and v is symmetric about the equator.\n! in this case sf is symmetric and vp antisymmetric about\n! the equator and are computed for the northern hemisphere\n! only. i.e., if nlat is odd the sf(i, j), vp(i, j) are computed\n! for i=1, ..., (nlat + 1)/2 and for j=1, ..., nlon. if nlat is\n! even then sf(i, j), vp(i, j) are computed for i=1, ..., nlat/2\n! and j=1, ..., nlon.\n!\n! = 2\n!\n! w is symmetric and v is antisymmetric about the equator.\n! in this case sf is antisymmetric and vp symmetric about\n! the equator and are computed for the northern hemisphere\n! only. i.e., if nlat is odd the sf(i, j), vp(i, j) are computed\n! for i=1, ..., (nlat + 1)/2 and for j=1, ..., nlon. if nlat is\n! even then sf(i, j), vp(i, j) are computed for i=1, ..., nlat/2\n! and j=1, ..., nlon.\n!\n! nt nt is the number of scalar and vector fields. some\n! computational efficiency is obtained for multiple fields. arrays\n! can be three dimensional corresponding to an indexed multiple\n! vector field. in this case multiple scalar synthesis will\n! be performed to compute sf, vp for each field. the\n! third index is the synthesis index which assumes the values\n! k=1, ..., nt. for a single synthesis set nt = 1. the\n! description of the remaining parameters is simplified by\n! assuming that nt=1 or that all the arrays are two dimensional.\n!\n! idv the first dimension of the arrays sf, vp as it appears in\n! the program that calls sfvpgc. if isym = 0 then idv\n! must be at least nlat. if isym = 1 or 2 and nlat is\n! even then idv must be at least nlat/2. if isym = 1 or 2\n! and nlat is odd then idv must be at least (nlat + 1)/2.\n!\n! jdv the second dimension of the arrays sf, vp as it appears in\n! the program that calls sfvpgc. jdv must be at least nlon.\n!\n! br, bi, two or three dimensional arrays (see input parameter nt)\n! cr, ci that contain vector spherical harmonic coefficients\n! of the vector field (v, w) as computed by subroutine vhagc.\n!\n! mdb the first dimension of the arrays br, bi, cr, ci as it\n! appears in the program that calls sfvpgc. mdb must be at\n! least min(nlat, nlon/2) if nlon is even or at least\n! min(nlat, (nlon + 1)/2) if nlon is odd.\n!\n! ndb the second dimension of the arrays br, bi, cr, ci as it\n! appears in the program that calls sfvpgc. ndb must be at\n! least nlat.\n!\n! wshsgc an array which must be initialized by subroutine shsgci.\n! once initialized, wshsgc can be used repeatedly by sfvpgc\n! as long as nlon and nlat remain unchanged. wshsgc must\n! not bel altered between calls of sfvpgc.\n!\n!\n! lshsgc the dimension of the array wshsgc as it appears in the\n! program that calls sfvpgc. define\n!\n! l1 = min(nlat, (nlon+2)/2) if nlon is even or\n! l1 = min(nlat, (nlon + 1)/2) if nlon is odd\n!\n! and\n!\n! l2 = nlat/2 if nlat is even or\n! l2 = (nlat + 1)/2 if nlat is odd\n!\n! then lshsgc must be at least\n!\n! nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15\n!\n!\n! work a work array that does not have to be saved.\n!\n! lwork the dimension of the array work as it appears in the\n! program that calls sfvpgc. define\n!\n! l1 = min(nlat, (nlon+2)/2) if nlon is even or\n! l1 = min(nlat, (nlon + 1)/2) if nlon is odd\n!\n! and\n!\n! l2 = nlat/2 if nlat is even or\n! l2 = (nlat + 1)/2 if nlat is odd\n!\n! if isym is zero then lwork must be at least\n!\n! nlat*((nt*nlon+max(3*l2, nlon)) + 2*l1*nt+1)\n!\n! if isym is not zero then lwork must be at least\n!\n! l2*(nt*nlon+max(3*nlat, nlon)) + nlat*(2*l1*nt+1)\n!\n! **************************************************************\n!\n! output parameters\n!\n! sf, vp two or three dimensional arrays (see input parameter nt)\n! that contains the stream function and velocity potential\n! of the vector field (v, w) whose coefficients br, bi, cr, ci\n! where precomputed by subroutine vhagc. sf(i, j), vp(i, j)\n! are given at the i(th) gaussian colatitude point theta(i)\n! and longitude point lambda(j) = (j-1)*2*pi/nlon. the index\n! ranges are defined above at the input parameter isym.\n!\n!\n! ierror = 0 no errors\n! = 1 error in the specification of nlat\n! = 2 error in the specification of nlon\n! = 3 error in the specification of isym\n! = 4 error in the specification of nt\n! = 5 error in the specification of idv\n! = 6 error in the specification of jdv\n! = 7 error in the specification of mdb\n! = 8 error in the specification of ndb\n! = 9 error in the specification of lshsgc\n! = 10 error in the specification of lwork\n! **********************************************************************\n!\nmodule module_sfvpgc\n\n use spherepack_precision, only: &\n wp, & ! working precision\n ip ! integer precision\n\n use scalar_synthesis_routines, only: &\n shsgc\n\n ! Explicit typing only\n implicit none\n\n ! Everything is private unless stated otherwise\n private\n public :: sfvpgc\n\ncontains\n\n subroutine sfvpgc(nlat, nlon, isym, nt, sf, vp, idv, jdv, br, bi, cr, ci, &\n mdb, ndb, wshsgc, lshsgc, work, lwork, ierror)\n\n integer(ip) :: nlat, nlon, isym, nt, idv, jdv, mdb, ndb, lshsgc, lwork, ierror\n real(wp) :: sf(idv, jdv, nt), vp(idv, jdv, nt)\n real(wp) :: br(mdb, ndb, nt), bi(mdb, ndb, nt)\n real(wp) :: cr(mdb, ndb, nt), ci(mdb, ndb, nt)\n real(wp) :: wshsgc(lshsgc), work(lwork)\n integer(ip) :: imid, mmax, lzz1, labc, ls, nln, mab, mn, ia, ib, is, lwk, iwk, lwmin\n integer(ip) :: l1, l2\n !\n ! Check calling arguments\n !\n ierror = 1\n if (nlat < 3) return\n ierror = 2\n if (nlon < 4) return\n ierror = 3\n if (isym < 0 .or. isym > 2) return\n ierror = 4\n if (nt < 0) return\n ierror = 5\n imid = (nlat + 1)/2\n if ((isym == 0 .and. idv0 .and. idv 0) ls = imid\n nln = nt*ls*nlon\n !\n ! set first dimension for a, b (as required by shsgc)\n !\n mab = min(nlat, nlon/2+1)\n mn = mab*nlat*nt\n if (lwork < nln+max(ls*nlon, 3*nlat*imid)+2*mn+nlat) return\n ierror = 0\n !\n ! Set workspace pointer indices\n !\n ia = 1\n ib = ia+mn\n is = ib+mn\n iwk = is+nlat\n lwk = lwork-2*mn-nlat\n call sfvpgc_lower_utility_routine(nlat, nlon, isym, nt, sf, vp, idv, jdv, br, bi, cr, ci, mdb, ndb, &\n work(ia), work(ib), mab, work(is), wshsgc, lshsgc, work(iwk), lwk, &\n ierror)\n\n contains\n\n subroutine sfvpgc_lower_utility_routine(nlat, nlon, isym, nt, sf, vp, idv, jdv, br, bi, cr, ci, &\n mdb, ndb, a, b, mab, fnn, wshsgc, lshsgc, wk, lwk, ierror)\n\n integer(ip) :: nlat, nlon, isym, nt, idv, jdv, mdb, ndb, mab, lshsgc, lwk, ierror\n real(wp) :: sf(idv, jdv, nt), vp(idv, jdv, nt)\n real(wp) :: br(mdb, ndb, nt), bi(mdb, ndb, nt), cr(mdb, ndb, nt), ci(mdb, ndb, nt)\n real(wp) :: a(mab, nlat, nt), b(mab, nlat, nt)\n real(wp) :: wshsgc(lshsgc), wk(lwk), fnn(nlat)\n integer(ip) :: n, m, mmax, k\n !\n ! set coefficient multiplyers\n !\n do n=2, nlat\n fnn(n) = 1.0/sqrt(real(n*(n-1)))\n end do\n mmax = min(nlat, (nlon + 1)/2)\n !\n ! compute sf scalar coefficients from cr, ci\n !\n do k=1, nt\n do n=1, nlat\n do m=1, mab\n a(m, n, k) = 0.0\n b(m, n, k) = 0.0\n end do\n end do\n !\n ! Compute m=0 coefficients\n !\n do n=2, nlat\n a(1, n, k) =-fnn(n)*cr(1, n, k)\n b(1, n, k) =-fnn(n)*ci(1, n, k)\n end do\n !\n ! compute m>0 coefficients using vector spherepack value for mmax\n !\n do m=2, mmax\n do n=m, nlat\n a(m, n, k) =-fnn(n)*cr(m, n, k)\n b(m, n, k) =-fnn(n)*ci(m, n, k)\n end do\n end do\n end do\n !\n ! synthesize a, b into st\n !\n call shsgc(nlat, nlon, isym, nt, sf, idv, jdv, a, b, mab, nlat, wshsgc, ierror)\n !\n ! set coefficients for vp from br, bi\n !\n do k=1, nt\n do n=1, nlat\n do m=1, mab\n a(m, n, k) = 0.0\n b(m, n, k) = 0.0\n end do\n end do\n !\n ! Compute m=0 coefficients\n !\n do n=2, nlat\n a(1, n, k) = fnn(n)*br(1, n, k)\n b(1, n, k) = fnn(n)*bi(1, n, k)\n end do\n !\n ! compute m>0 coefficients using vector spherepack value for mmax\n !\n mmax = min(nlat, (nlon + 1)/2)\n do m=2, mmax\n do n=m, nlat\n a(m, n, k) = fnn(n)*br(m, n, k)\n b(m, n, k) = fnn(n)*bi(m, n, k)\n end do\n end do\n end do\n !\n ! synthesize a, b into vp\n !\n call shsgc(nlat, nlon, isym, nt, vp, idv, jdv, a, b, mab, nlat, wshsgc, ierror)\n\n end subroutine sfvpgc_lower_utility_routine\n\n end subroutine sfvpgc\n\nend module module_sfvpgc\n", "meta": {"hexsha": "77c06a6c2264fe8ec6a8d7faea7c2e5de3690300", "size": 16285, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/sfvpgc.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "src/sfvpgc.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "src/sfvpgc.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 41.4376590331, "max_line_length": 131, "alphanum_fraction": 0.472029475, "num_tokens": 4590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002787, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7722201315673254}} {"text": "!7. Write a program that prints a multiplication table for numbers up to 12.\n \n program Exercises\n implicit none\n integer :: x\n integer :: y\n \n write (*, fmt='(A)', advance='no') ' '\n do x=1,12\n write(*, fmt='(I4)', advance='no') x\n end do\n print *, ''\n \n write (*, fmt='(A)', advance='no') ' --'\n do x=1,12\n write(*, fmt='(A)', advance='no') ' ---'\n end do\n print *, ''\n \n do y=1,12\n write (*, fmt='(I4, A)', advance='no') y, '|'\n do x=1,12\n write (*, fmt='(I4)', advance='no') x*y ! Implicit unit 6. Unit 6 is the one specially reserved for written output to the console.\n flush (unit=6) ! Same-line output doesn't appear right away unless you flush. Not strictly necessary it was useful to get visible output when debugging\n end do\n print *, '' !Newline\n end do\n \n end program Exercises", "meta": {"hexsha": "43f133496f3b7c4e1dd2914b7c9d670c214cc0c2", "size": 919, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "E07.f90", "max_stars_repo_name": "clandrew/problemsf90", "max_stars_repo_head_hexsha": "8dd561f9ab4cb7a880efda5d3c4a32bc458cac24", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "E07.f90", "max_issues_repo_name": "clandrew/problemsf90", "max_issues_repo_head_hexsha": "8dd561f9ab4cb7a880efda5d3c4a32bc458cac24", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "E07.f90", "max_forks_repo_name": "clandrew/problemsf90", "max_forks_repo_head_hexsha": "8dd561f9ab4cb7a880efda5d3c4a32bc458cac24", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.6896551724, "max_line_length": 163, "alphanum_fraction": 0.5408052231, "num_tokens": 262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642018, "lm_q2_score": 0.8418256393148982, "lm_q1q2_score": 0.7722088940446752}} {"text": "*\n* Program sortarr - Sort an array, computet the mean, median, max and mi\n*\n* Program can handle up to 100 values\n*\n* Written by - Charles Severance 18Mar92\n*\n REAL VALUES(100),MEAN,MEDIAN,MAX,MIN,TMP\n INTEGER I,J,COUNT\n*\n* Read in the values counting how many we got\n*\n COUNT = 0\n DO WHILE(COUNT.LT.100)\n READ(*,*,END=20)TMP\n COUNT = COUNT + 1\n VALUES(COUNT) = TMP\n ENDDO\n20 CONTINUE\n PRINT *,'Read in ',COUNT,' values'\n*\n IF ( COUNT.EQ. 0 ) THEN\n PRINT *,'Program has read no data...'\n STOP\n ENDIF\n*\n* Sort the array\n*\n DO I=1,COUNT-1\n DO J=I+1,COUNT\n IF ( VALUES(I).GT.VALUES(J) ) THEN\n TMP = VALUES(I)\n VALUES(I) = VALUES(J)\n VALUES(J) = TMP\n ENDIF\n ENDDO\n ENDDO\n*\n* Print out the sorted values\n* \n DO I=1,COUNT\n PRINT *,VALUES(I)\n ENDDO\n*\n* Find the maximum and minimum and total\n*\n MAX = VALUES(1)\n MIN = VALUES(1)\n TOTAL = 0.0\n DO I=1,COUNT\n IF ( VALUES(I) .GT. MAX ) MAX = VALUES(I)\n IF ( VALUES(I) .LT. MIN ) MIN = VALUES(I)\n TOTAL = TOTAL + VALUES(I)\n ENDDO\n MEAN = TOTAL/COUNT\n*\n* Find the median. The median is different whether the total number\n* is even or odd. We use the MOD function which gives us the remainder\n* of an integer division to determine if the value is even or odd.\n*\n IF ( MOD(COUNT,2) .EQ. 1 ) THEN\n MEDIAN = VALUES( COUNT/2 + 1 )\n ELSE\n MEDIAN = (VALUES(COUNT/2) + VALUES(COUNT/2+1)) / 2\n ENDIF\n*\n* Print everything out\n*\n PRINT *\n PRINT *,'Mean = ',MEAN\n PRINT *,'Median = ',MEDIAN\n PRINT *,'Minimum = ',MIN\n PRINT *,'Maximum = ',MAX\n END\n", "meta": {"hexsha": "23d49333a8761fe14c0f5e93806ebf3fc7f45c3f", "size": 1759, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "archive/2000-eecs280/examples/examples.ftn/programs/sortarr.f", "max_stars_repo_name": "yashajoshi/cc4e", "max_stars_repo_head_hexsha": "dd166f7e70d4111945054b8cb39483eb8dfb591b", "max_stars_repo_licenses": ["Apache-2.0", "CC-BY-4.0"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2020-01-05T04:46:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T09:36:02.000Z", "max_issues_repo_path": "archive/2000-eecs280/examples/examples.ftn/programs/sortarr.f", "max_issues_repo_name": "yashajoshi/cc4e", "max_issues_repo_head_hexsha": "dd166f7e70d4111945054b8cb39483eb8dfb591b", "max_issues_repo_licenses": ["Apache-2.0", "CC-BY-4.0"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2021-07-01T01:19:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-07T01:30:45.000Z", "max_forks_repo_path": "archive/2000-eecs280/examples/examples.ftn/programs/sortarr.f", "max_forks_repo_name": "yashajoshi/cc4e", "max_forks_repo_head_hexsha": "dd166f7e70d4111945054b8cb39483eb8dfb591b", "max_forks_repo_licenses": ["Apache-2.0", "CC-BY-4.0"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2020-12-27T19:57:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T13:01:36.000Z", "avg_line_length": 23.4533333333, "max_line_length": 72, "alphanum_fraction": 0.5503126777, "num_tokens": 540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.8887587964389112, "lm_q1q2_score": 0.7721774520379376}} {"text": "!******************************************************************************\n!*\n!* VARIOUS MATHEMATICAL DISTRIBUTIONS\n!*\n!******************************************************************************\n\n !==========================================================================\n ! 1) AUTHOR: F. Galliano\n !\n ! 2) HISTORY: \n ! - Created 09/2007\n ! - Updated 11/2012\n ! - 04/2016: remove ERF and ERFC (now intrinsic in F08).\n ! \n ! 3) DESCRIPTION: implements various commonly used mathematical functions,\n ! distributions, and operations to manipulate them.\n !==========================================================================\n\nMODULE special_functions\n\n USE utilities, ONLY:\n IMPLICIT NONE\n PRIVATE\n\n PUBLIC :: factorial_small, factorial, lngamma, igamma, igammac, ibeta\n PUBLIC :: expm1\n\n INTERFACE expm1\n MODULE PROCEDURE expm1_scl, expm1_1D\n END INTERFACE expm1\n\n INTERFACE lngamma\n MODULE PROCEDURE lngamma_scl, lngamma_1D\n END INTERFACE lngamma\n\n INTERFACE igamma\n MODULE PROCEDURE igamma_scl, igamma_1D\n END INTERFACE igamma\n\n INTERFACE igammac\n MODULE PROCEDURE igammac_scl, igammac_1D\n END INTERFACE igammac\n\n INTERFACE factorial\n MODULE PROCEDURE factorial_scl, factorial_1D\n END INTERFACE factorial\n\n INTERFACE betacf\n MODULE PROCEDURE betacf_scl, betacf_1D\n END INTERFACE betacf\n\n INTERFACE ibeta\n MODULE PROCEDURE ibeta_scl, ibeta_1D\n END INTERFACE ibeta\n\n\nCONTAINS\n\n\n !==========================================================================\n ! EXP(X) - 1 = EXPM1(x)\n !\n ! Numerically accurate development of exp(x)-1 around 0, using the \n ! expansion of Abramowitz & Stegun (4.2.45). It is suposed to be accurate\n ! at 2.E-10.\n !==========================================================================\n\n PURE FUNCTION expm1_1D (x)\n\n USE utilities, ONLY: DP\n IMPLICIT NONE\n REAL(DP), DIMENSION(:), INTENT(IN) :: x\n REAL(DP), DIMENSION(SIZE(x)) :: expm1_1D\n \n INTEGER, PARAMETER :: Ncoef = 7\n REAL(DP), PARAMETER :: xmax = 0.6931472_DP ! ln(2)\n REAL(DP), DIMENSION(Ncoef), PARAMETER :: &\n coef = [ 0.9999999995_DP, 0.4999999206_DP, 0.1666653019_DP, &\n 0.0416573475_DP, 0.0083013598_DP, 0.0013298820_DP, &\n 0.0001413161_DP ]\n\n !------------------------------------------------------------------------\n\n WHERE (ABS(x(:)) > xmax) \n expm1_1D(:) = EXP(x(:)) - 1._DP\n ELSEWHERE\n expm1_1D(:) = coef(7)*x(:)**7 \n expm1_1D(:) = coef(6)*x(:)**6 + expm1_1D(:)\n expm1_1D(:) = coef(5)*x(:)**5 + expm1_1D(:)\n expm1_1D(:) = coef(4)*x(:)**4 + expm1_1D(:)\n expm1_1D(:) = coef(3)*x(:)**3 + expm1_1D(:)\n expm1_1D(:) = coef(2)*x(:)**2 + expm1_1D(:)\n expm1_1D(:) = coef(1)*x(:)**1 + expm1_1D(:)\n END WHERE\n\n !------------------------------------------------------------------------\n\n END FUNCTION expm1_1D\n\n PURE FUNCTION expm1_scl (x)\n\n USE utilities, ONLY: DP\n IMPLICIT NONE\n REAL(DP), INTENT(IN) :: x\n REAL(DP) :: expm1_scl\n \n !------------------------------------------------------------------------\n\n expm1_scl = MAXVAL(EXPM1_1D([x]))\n\n !------------------------------------------------------------------------\n\n END FUNCTION expm1_scl\n\n\n !==========================================================================\n ! n! = FACTORIAL_SMALL(n)\n !\n ! Determines the factorial of a small integer as an integer.\n !==========================================================================\n\n RECURSIVE FUNCTION factorial_small (n) RESULT(fact)\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: n\n INTEGER :: fact\n\n !------------------------------------------------------------------------\n\n def: IF (n <= 1) THEN\n fact = 1\n ELSE\n fact = n*FACTORIAL_SMALL(n-1)\n END IF def\n\n !------------------------------------------------------------------------\n\n END FUNCTION factorial_small\n\n\n !==========================================================================\n ! n! = FACTORIAL(n)\n !\n ! Determines the factorial of an integer.\n !==========================================================================\n\n FUNCTION factorial_scl (n)\n\n USE utilities, ONLY: DP, cumprod, arth\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: n\n REAL(DP) :: factorial_scl\n\n INTEGER, PARAMETER :: nmax = 32\n\n INTEGER, SAVE :: ntop = 0\n REAL(DP), DIMENSION(nmax), SAVE :: a\n\n !------------------------------------------------------------------------\n\n IF (n < ntop) THEN\n factorial_scl = a(n+1)\n ELSE IF (n < nmax) THEN\n ntop = nmax\n a(1) = 1._DP\n a(2:nmax) = CUMPROD(ARTH(1._DP,1._DP,nmax-1))\n factorial_scl = a(n+1)\n ELSE \n factorial_scl = EXP(LNGAMMA(n+1._DP))\n END IF\n\n !------------------------------------------------------------------------\n\n END FUNCTION factorial_scl\n\n !------------------------------------------------------------------------\n\n FUNCTION factorial_1D (n)\n\n USE utilities, ONLY: DP, cumprod, arth\n IMPLICIT NONE\n INTEGER, DIMENSION(:), INTENT(IN) :: n\n REAL(DP), DIMENSION(SIZE(n)) :: factorial_1D\n\n INTEGER, PARAMETER :: nmax = 32\n\n LOGICAL, DIMENSION(SIZE(n)) :: mask\n INTEGER, SAVE :: ntop = 0\n REAL(DP), DIMENSION(nmax), SAVE :: a\n\n !------------------------------------------------------------------------\n\n IF (ntop == 0) THEN\n ntop = nmax\n a(1) = 1._DP\n a(2:nmax) = CUMPROD(ARTH(1._DP,1._DP,nmax-1))\n END IF\n mask = (n >= nmax)\n factorial_1D = UNPACK(EXP(LNGAMMA(PACK(n,mask)+1.0_DP)),mask,0._DP)\n WHERE (.NOT. mask) factorial_1D = a(n+1)\n\n !------------------------------------------------------------------------\n\n END FUNCTION factorial_1D\n\n\n !==========================================================================\n ! y = LN(GAMMA(x))\n !\n ! Log of gamma function for x > 0.\n !==========================================================================\n\n ELEMENTAL FUNCTION lngamma_scl (xx)\n\n USE utilities, ONLY: DP, arth\n IMPLICIT NONE\n REAL(DP), INTENT(IN) :: xx\n REAL(DP) :: lngamma_scl\n\n REAL(DP), PARAMETER :: stp = 2.5066282746310005_DP\n REAL(DP), DIMENSION(6), PARAMETER :: &\n coef = (/ 76.18009172947146_DP, -86.50532032941677_DP, &\n 24.01409824083091_DP, -1.231739572450155_DP, &\n 0.1208650973866179E-2_DP, -0.5395239384953E-5_DP /)\n\n REAL(DP) :: tmp, x\n\n !------------------------------------------------------------------------\n\n x = xx\n tmp = x + 5.5_DP\n tmp = (x+0.5_DP)*LOG(tmp) - tmp\n lngamma_scl = tmp + LOG(stp*(1.000000000190015_DP &\n +SUM(coef(:)/ARTH(x+1.0_DP,1.0_DP,SIZE(coef))))/x)\n\n !------------------------------------------------------------------------\n\n END FUNCTION lngamma_scl\n\n !------------------------------------------------------------------------\n\n PURE FUNCTION lngamma_1D (xx)\n\n USE utilities, ONLY: DP\n IMPLICIT NONE\n REAL(DP), DIMENSION(:), INTENT(IN) :: xx\n REAL(DP), DIMENSION(SIZE(xx)) :: lngamma_1D\n\n REAL(DP), PARAMETER :: stp = 2.5066282746310005_DP\n REAL(DP), DIMENSION(6), PARAMETER :: &\n coef = (/ 76.18009172947146_DP, -86.50532032941677_DP, &\n 24.01409824083091_DP, -1.231739572450155_DP, &\n 0.1208650973866179E-2_DP, -0.5395239384953E-5_DP /)\n\n INTEGER :: i\n REAL(DP), DIMENSION(SIZE(xx)) :: ser, tmp, x, y\n\n !------------------------------------------------------------------------\n\n x = xx\n tmp = x + 5.5_DP\n tmp = (x+0.5_DP)*LOG(tmp) - tmp\n ser = 1.000000000190015_DP\n y = x\n DO i=1,SIZE(coef)\n y = y + 1.0_DP\n ser = ser + coef(i)/y\n END DO\n lngamma_1D = tmp + LOG(stp*ser/x) \n\n !------------------------------------------------------------------------\n\n END FUNCTION lngamma_1D\n\n\n !==========================================================================\n ! IGAMMA(x) = 1/Gamma(a) * int(EXP(-t)*t^(a-1),{t=[0,x]}), a>0\n !\n ! Incomplete gamma function. We must have x >= 0 and a > 0. The preliminary\n ! functions GSER et GCF returns the two forms of the incomplete gamma function\n ! P(a,x) and Q(a,x) = 1 - P(a,x), with different numerical methods, depending\n ! on the parameter values.\n !==========================================================================\n\n ELEMENTAL FUNCTION gser_scl (a,x)\n\n USE utilities, ONLY: DP, epsDP\n IMPLICIT NONE\n\n REAL(DP), INTENT(IN) :: a, x\n REAL(DP) :: gser_scl\n\n INTEGER, PARAMETER :: itmax = 100\n\n INTEGER :: n\n REAL(DP) :: ap, del, summ\n\n !------------------------------------------------------------------------\n\n IF (x == 0._DP) THEN\n gser_scl = 0._DP\n RETURN\n END IF\n ap = a\n summ = 1._DP / a\n del = summ\n DO n=1,itmax\n ap = ap + 1._DP\n del = del * x / ap\n summ = summ + del\n IF (ABS(del) < ABS(summ)*epsDP) EXIT\n END DO\n gser_scl = summ * EXP( -x + a*LOG(x) - LNGAMMA(a) )\n\n !------------------------------------------------------------------------\n\n END FUNCTION gser_scl\n\n !------------------------------------------------------------------------\n\n PURE FUNCTION gser_1D(a,x)\n \n USE utilities, ONLY: DP, epsDP\n IMPLICIT NONE\n\n REAL(DP), DIMENSION(:), INTENT(IN) :: a, x\n REAL(DP), DIMENSION(SIZE(a)) :: gser_1D\n\n INTEGER, PARAMETER :: itmax = 100\n\n INTEGER :: i, N\n REAL(DP), DIMENSION(SIZE(a)) :: ap, del, summ\n LOGICAL, DIMENSION(SIZE(a)) :: converged, zero\n\n !------------------------------------------------------------------------\n\n N = SIZE(x(:))\n zero(:) = ( x(:) == 0._DP )\n WHERE (zero) gser_1D(:) = 0._DP\n ap(:) = a(:)\n summ(:) = 1._DP / a(:)\n del(:) = summ(:)\n converged(:) = zero(:)\n DO i=1,itmax\n WHERE (.NOT. converged(:))\n ap(:) = ap(:) + 1._DP\n del(:) = del(:) * x(:) / ap(:)\n summ(:) = summ(:) + del(:)\n converged(:) = (ABS(del(:)) < ABS(summ(:))*epsDP)\n END WHERE\n IF (ALL(converged(:))) EXIT\n END DO\n WHERE (.NOT. zero(:)) &\n gser_1D(:) = summ(:) * EXP( -x(:) + a(:)*LOG(x(:)) - LNGAMMA(a(:)) )\n\n !------------------------------------------------------------------------\n\n END FUNCTION gser_1D\n\n !------------------------------------------------------------------------\n\n ELEMENTAL FUNCTION gcf_scl(a,x)\n\n USE utilities, ONLY: DP, epsDP, tinyDP\n IMPLICIT NONE\n\n REAL(DP), INTENT(IN) :: a, x\n REAL(DP) :: gcf_scl\n\n INTEGER, PARAMETER :: itmax = 100\n REAL(DP), PARAMETER :: fpmin = tinyDP / epsDP\n\n INTEGER :: i\n REAL(DP) :: an, b, c, d, del, h\n\n !------------------------------------------------------------------------\n\n IF (x == 0._DP) THEN\n gcf_scl = 1._DP\n RETURN\n ENDIF\n b = x + 1._DP - a \n c = 1._DP / fpmin\n d = 1._DP / b\n h = d\n DO i=1,itmax\n an = -i * (i-a)\n b = b + 2._DP\n d = an*d + b\n IF (ABS(d) < fpmin) d = fpmin\n c = b + an/c\n IF (ABS(c) < fpmin) c = fpmin\n d = 1._DP / d\n del = d * c\n h = h * del\n IF (ABS(del-1._DP) <= epsDP) EXIT\n END DO\n gcf_scl = EXP( -x + a*LOG(x) - LNGAMMA(a) ) * h\n\n !------------------------------------------------------------------------\n\n END FUNCTION gcf_scl\n\n !------------------------------------------------------------------------\n\n PURE FUNCTION gcf_1D(a,x)\n\n USE utilities, ONLY: DP, epsDP, tinyDP\n IMPLICIT NONE\n\n REAL(DP), DIMENSION(:), INTENT(IN) :: a, x\n REAL(DP), DIMENSION(SIZE(a)) :: gcf_1D\n\n INTEGER, PARAMETER :: itmax = 100\n REAL(DP), PARAMETER :: fpmin = tinyDP / epsDP\n\n INTEGER :: i, N\n REAL(DP), DIMENSION(SIZE(a)) :: an, b, c, d, del, h\n LOGICAL, DIMENSION(SIZE(a)) :: converged, zero\n\n !------------------------------------------------------------------------\n\n N = SIZE(x(:))\n zero(:) = ( x(:) == 0._DP )\n WHERE (zero(:))\n gcf_1D(:) = 1._DP\n ELSEWHERE\n b(:) = x(:) + 1._DP - a(:)\n c(:) = 1._DP / fpmin\n d(:) = 1._DP / b(:)\n h(:) = d(:)\n END WHERE\n converged(:) = zero(:)\n DO i=1,itmax\n WHERE (.NOT. converged(:))\n an(:) = -i * (i-a(:))\n b(:) = b(:) + 2._DP\n d(:) = an(:)*d(:) + b(:)\n d(:) = MERGE( fpmin, d(:), ABS(d(:))0\n !\n ! Complementary incomplete gamma function, Q(a,x) = 1 - P(a,x). We must \n ! have x >= 0 and a > 0. \n !==========================================================================\n\n ELEMENTAL FUNCTION igammac_scl (a,x)\n\n USE utilities, ONLY: DP\n IMPLICIT NONE\n\n REAL(DP), INTENT(IN) :: a, x\n REAL(DP) :: igammac_scl\n\n !------------------------------------------------------------------------\n\n IF ( x < a+1._DP) THEN\n igammac_scl = 1._DP - GSER_SCL(a,x) \n ELSE\n igammac_scl = GCF_SCL(a,x)\n END IF\n\n !------------------------------------------------------------------------\n\n END FUNCTION igammac_scl\n\n !------------------------------------------------------------------------\n\n PURE FUNCTION igammac_1D(a,x)\n\n USE utilities, ONLY: DP\n IMPLICIT NONE\n\n REAL(DP), DIMENSION(:), INTENT(IN) :: a, x\n REAL(DP), DIMENSION(SIZE(a)) :: igammac_1D\n LOGICAL, DIMENSION(SIZE(x)) :: mask\n INTEGER :: N\n\n !------------------------------------------------------------------------\n\n N = SIZE(x(:))\n mask(:) = ( x(:) < a(:)+1._DP )\n igammac_1D = MERGE( 1._DP - GSER_1D(a(:),MERGE(x(:),0._DP,mask(:))), &\n GCF_1D(a(:),MERGE(x(:),0._DP,.NOT. mask(:))), &\n mask(:) )\n\n !------------------------------------------------------------------------\n\n END FUNCTION igammac_1D\n\n\n !==========================================================================\n ! y[N] = BETACF(a[N],b[N],x[N])\n !\n ! Evaluates continued fraction for incomplete beta function by modified \n ! Lenz's method.\n !==========================================================================\n\n ELEMENTAL FUNCTION betacf_scl (a,b,x)\n\n USE utilities, ONLY: DP, tinyDP, epsDP\n IMPLICIT NONE\n\n REAL(DP), INTENT(IN) :: a, b, x\n REAL(DP) :: betacf_scl\n \n INTEGER, PARAMETER :: maxit = 100\n REAL(DP), PARAMETER :: fpmin = tinyDP/epsDP\n\n INTEGER :: m, m2\n REAL(DP) :: aa, c, d, del, h, qab, qam, qap\n \n !------------------------------------------------------------------------\n\n qab = a + b\n qap = a + 1._DP\n qam = a - 1._DP\n c = 1._DP\n d = 1._DP - qab*x/qap\n IF (ABS(d) < fpmin) d = fpmin\n d = 1._DP/d\n h = d\n DO m=1,maxit\n m2 = 2*m\n aa = m * (b-m) * x / ((qam+m2)*(a+m2))\n d = 1._DP + aa*d\n IF (ABS(d) < fpmin) d = fpmin\n c = 1._DP + aa/c\n IF (ABS(c) < fpmin) c = fpmin\n d = 1._DP/d\n h = h*d*c\n aa = - (a+m) * (qab+m) * x / ((a+m2)*(qap+m2))\n d = 1._DP + aa*d\n IF (ABS(d) < fpmin) d = fpmin\n c = 1._DP + aa/c\n IF (ABS(c) < fpmin) c = fpmin\n d = 1._DP / d\n del = d*c\n h = h*del\n IF (ABS(del-1._DP) <= epsDP) EXIT\n END DO\n\n betacf_scl = h\n\n !------------------------------------------------------------------------\n\n END FUNCTION betacf_scl\n\n !------------------------------------------------------------------------\n\n PURE FUNCTION betacf_1D (a,b,x)\n\n USE utilities, ONLY: DP, tinyDP, epsDP\n IMPLICIT NONE\n\n REAL(DP), DIMENSION(:), INTENT(IN) :: a, b, x\n REAL(DP), DIMENSION(SIZE(x)) :: betacf_1D\n\n INTEGER, PARAMETER :: maxit = 100\n REAL(DP), PARAMETER :: fpmin = tinyDP/epsDP\n\n INTEGER :: m\n INTEGER, DIMENSION(SIZE(x)) :: m2\n REAL(DP), DIMENSION(SIZE(x)) :: aa, c, d, del, h, qab, qam, qap\n LOGICAL, DIMENSION(SIZE(x)) :: converged\n\n !------------------------------------------------------------------------\n\n m = SIZE(x)\n qab = a + b\n qap = a + 1._DP\n qam = a - 1._DP\n c = 1._DP\n d = 1._DP - qab*x/qap\n WHERE (ABS(d) < fpmin) d = fpmin\n d = 1._DP/d\n h = d\n converged = .FALSE.\n DO m=1,maxit\n WHERE (.NOT. converged)\n m2 = 2*m\n aa = m * (b-m) * x / ((qam+m2)*(a+m2))\n d = 1._DP + aa*d\n d = MERGE(fpmin,d,ABS(d) 1 if intpol = 1 or nx > 3 if intpol = 3 is required.\nc\nc ... x\nc\nc a real nx vector of strictly increasing values which defines the x\nc grid on which p is given.\nc\nc\nc ... p\nc\nc a real nx vector of values given on the x grid\nc\nc ... mx\nc\nc the integer dimension of the grid vector xx and the dimension of q.\nc mx > 0 is required.\nc\nc ... xx\nc\nc a real mx vector of increasing values which defines the\nc grid on which q is defined. xx(1) < x(1) or xx(mx) > x(nx)\nc is not allowed (see ier = 3)\nc\nc ... intpol\nc\nc an integer which sets linear or cubic\nc interpolation as follows:\nc\nc intpol = 1 sets linear interpolation\nc intpol = 3 sets cubic interpolation\nc\nc values other than 1 or 3 in intpol are not allowed (ier = 6).\nc\nc ... w\nc\nc a real work space of length at least lw which must be provided in the\nc routine calling rgrd1\nc\nc\nc ... lw\nc\nc the integer length of the real work space w. let\nc\nc lwmin = mx if intpol(1) = 1\nc lwmin = 4*mx if intpol(1) = 3\nc\nc then lw must be greater than or equal to lwmin\nc\nc ... iw\nc\nc an integer work space of length at least liw which must be provided in the\nc routine calling rgrd1\nc\nc ... liw\nc\nc tne length of the integer work space iw. liw must be greater than or equal to mx.\nc\nc\nc *** output arguments\nc\nc\nc ... q\nc\nc a real mx vector of values on the xx grid which are\nc interpolated from p on the x grid\nc\nc ... ier\nc\nc an integer error flag set as follows:\nc\nc ier = 0 if no errors in input arguments are detected\nc\nc ier = 1 if mx < 1\nc\nc ier = 2 if nx < 2 when intpol=1 or nx < 4 when intpol=3\nc\nc ier = 3 if xx(1) < x(1) or x(nx) < xx(mx)\nc\nc *** to avoid this flag when end points are intended to be the\nc same but may differ slightly due to roundoff error, they\nc should be set exactly in the calling routine (e.g., if both\nc grids have the same x boundaries then xx(1)=x(1) and xx(mx)=x(nx)\nc should be set before calling rgrd1)\nc\nc ier = 4 if the x grid is not strictly monotonically increasing\nc or if the xx grid is not montonically increasing. more\nc precisely if:\nc\nc x(i+1) <= x(i) for some i such that 1 <= i < nx (or)\nc\nc xx(ii+1) < xx(ii) for some ii such that 1 <= ii < mx\nc\nc ier = 5 if lw or liw is too small (insufficient work space)\nc\nc ier = 6 if intpol is not equal to 1 or 3\nc\nc ************************************************************************\nc\nc end of rgrd1 documentation, fortran code follows:\nc\nc ************************************************************************\nc\n subroutine rgrd1(nx,x,p,mx,xx,q,intpol,w,lw,iw,liw,ier)\nc dimension x(nx),p(nx),xx(mx),q(mx),w(lw)\n implicit none\n real x(*),p(*),xx(*),q(*),w(*)\n integer iw(*)\n integer nx,mx,ier,intpol,lw,liw,i,ii,i1,i2,i3,i4\nc\nc check arguments for errors\nc\n ier = 1\nc\nc check xx grid resolution\nc\n if (mx .lt. 1) return\nc\nc check intpol\nc\n ier = 6\n if (intpol.ne.1 .and. intpol.ne.3) return\nc\nc check x grid resolution\nc\n ier = 2\n if (intpol.eq.1 .and. nx.lt.2) return\n if (intpol.eq.3 .and. nx.lt.4) return\nc\nc check xx grid contained in x grid\nc\n ier = 3\n if (xx(1).lt.x(1) .or. xx(mx).gt.x(nx)) return\nc\nc check montonicity of grids\nc\n do i=2,nx\n\tif (x(i-1).ge.x(i)) then\n\t ier = 4\n\t return\n\tend if\n end do\n do ii=2,mx\n\tif (xx(ii-1).gt.xx(ii)) then\n\t ier = 4\n\t return\n\tend if\n end do\nc\nc check minimum work space lengths\nc\n if (intpol.eq.1) then\n\tif (lw .lt. mx) return\n else\n\tif (lw .lt. 4*mx) return\n end if\n if (liw .lt. mx) return\nc\nc arguments o.k.\nc\n ier = 0\n\n if (intpol.eq.1) then\nc\nc linear interpolation in x\nc\n i1 = 1\n i2 = i1+mx\n call linmx(nx,x,mx,xx,iw,w)\n call lint1(nx,p,mx,q,iw,w)\n return\n else\nc\nc cubic interpolation in x\nc\n i1 = 1\n i2 = i1+mx\n i3 = i2+mx\n i4 = i3+mx\n call cubnmx(nx,x,mx,xx,iw,w(i1),w(i2),w(i3),w(i4))\n call cubt1(nx,p,mx,q,iw,w(i1),w(i2),w(i3),w(i4))\n return\n end if\n end\n\n subroutine lint1(nx,p,mx,q,ix,dx)\nc dimension p(nx),q(mx),ix(mx),dx(mx)\n implicit none\n integer mx,ix(mx),nx,ii,i\n real p(nx),q(mx),dx(mx)\nc\nc linearly interpolate p on x onto q on xx\nc\n do ii=1,mx\n\ti = ix(ii)\n\tq(ii) = p(i)+dx(ii)*(p(i+1)-p(i))\n end do\n return\n end\n\n subroutine cubt1(nx,p,mx,q,ix,dxm,dx,dxp,dxpp)\n implicit none\n integer mx,ix(mx),nx,i,ii\n real p(nx),q(mx),dxm(mx),dx(mx),dxp(mx),dxpp(mx)\nc\nc cubically interpolate p on x to q on xx\nc\n do ii=1,mx\n\ti = ix(ii)\n\tq(ii) = dxm(ii)*p(i-1)+dx(ii)*p(i)+dxp(ii)*p(i+1)+dxpp(ii)*p(i+2)\n end do\n return\n end\n\n subroutine linmx(nx,x,mx,xx,ix,dx)\nc\nc set x grid pointers for xx grid and interpolation scale terms\nc\n implicit none\n real x(*),xx(*),dx(*)\n integer ix(*),isrt,ii,i,nx,mx\n isrt = 1\n do ii=1,mx\nc\nc find x(i) s.t. x(i) < xx(ii) <= x(i+1)\nc\n\tdo i=isrt,nx-1\n\t if (x(i+1) .ge. xx(ii)) then\n\t isrt = i\n\t ix(ii) = i\n\t go to 3\n\t end if\n\tend do\n 3 continue\n end do\nc\nc set linear scale term\nc\n do ii=1,mx\n\ti = ix(ii)\n\tdx(ii) = (xx(ii)-x(i))/(x(i+1)-x(i))\n end do\n return\n end\n\n subroutine cubnmx(nx,x,mx,xx,ix,dxm,dx,dxp,dxpp)\n implicit none\n real x(*),xx(*),dxm(*),dx(*),dxp(*),dxpp(*)\n integer ix(*),mx,nx,i,ii,isrt\n\n isrt = 1\n do ii=1,mx\nc\nc set i in [2,nx-2] closest s.t.\nc x(i-1),x(i),x(i+1),x(i+2) can interpolate xx(ii)\nc\n\tdo i=isrt,nx-1\n\t if (x(i+1) .ge. xx(ii)) then\n\t ix(ii) = min0(nx-2,max0(2,i))\n\t isrt = ix(ii)\n\t go to 3\n\t end if\n\tend do\n 3 continue\n end do\nc\nc set cubic scale terms\nc\n do ii=1,mx\n\ti = ix(ii)\n\tdxm(ii) = (xx(ii)-x(i))*(xx(ii)-x(i+1))*(xx(ii)-x(i+2))/\n + ((x(i-1)-x(i))*(x(i-1)-x(i+1))*(x(i-1)-x(i+2)))\n\tdx(ii) = (xx(ii)-x(i-1))*(xx(ii)-x(i+1))*(xx(ii)-x(i+2))/\n + ((x(i)-x(i-1))*(x(i)-x(i+1))*(x(i)-x(i+2)))\n\tdxp(ii) = (xx(ii)-x(i-1))*(xx(ii)-x(i))*(xx(ii)-x(i+2))/\n + ((x(i+1)-x(i-1))*(x(i+1)-x(i))*(x(i+1)-x(i+2)))\n\tdxpp(ii) = (xx(ii)-x(i-1))*(xx(ii)-x(i))*(xx(ii)-x(i+1))/\n + ((x(i+2)-x(i-1))*(x(i+2)-x(i))*(x(i+2)-x(i+1)))\n end do\n return\n end\n\n", "meta": {"hexsha": "a3bc5b08f959870f7e84a7a19be7d7f28a4f9256", "size": 8473, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/regridpack/Src/rgrd1.f", "max_stars_repo_name": "xylar/cdat", "max_stars_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2018-03-30T15:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T23:30:24.000Z", "max_issues_repo_path": "contrib/regridpack/Src/rgrd1.f", "max_issues_repo_name": "xylar/cdat", "max_issues_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 114, "max_issues_repo_issues_event_min_datetime": "2018-03-21T01:12:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-05T12:29:54.000Z", "max_forks_repo_path": "contrib/regridpack/Src/rgrd1.f", "max_forks_repo_name": "CDAT/uvcdat", "max_forks_repo_head_hexsha": "5133560c0c049b5c93ee321ba0af494253b44f91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2018-06-06T02:42:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-26T03:27:00.000Z", "avg_line_length": 23.5361111111, "max_line_length": 87, "alphanum_fraction": 0.5687477871, "num_tokens": 3062, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726545, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.7720804260990565}} {"text": "module aloha_constants\n ! Code working precision\n integer, parameter :: wp = kind(1.0D0)\n ! 10 decimals numbers and a dynamic of 10^60 \n! integer, parameter :: wp = selected_real_kind(10,60)\n ! mathematical constants\n real(kind=wp), parameter :: pi = 3.14159265358979323846264338327950288419716939937510\n complex, parameter :: ImU = (0.0,1.0) \t! Imaginary Unit\n ! physics constants\n real(kind=wp), parameter :: cl = 299792458.0 ! Vacuum light velocity\n real(kind=wp), parameter :: mu0= 4.0*pi*1.E-7 ! Vacuum permeability\n real(kind=wp), parameter :: Eps0=8.854187E-12 ! Vacuum permittivity\n real(kind=wp), parameter :: Z0 = mu0*cl ! Vacuum impedance\n real(kind=wp), parameter :: Y0 = 1.0/Z0 ! Vacuum inductance\n ! Electron properties\n real(kind=wp), parameter :: me = 9.10938215E-31 ! Electron mass\n real(kind=wp), parameter :: qe = 1.602176487E-19 ! Electron Electric charge (modulus)\n ! misc.\n real, parameter :: pc = 1.*1.E-3\n\nend module aloha_constants\n", "meta": {"hexsha": "d757c49d91bbd9750a2b874a92fa2931454b8e06", "size": 1056, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code_1D/couplage_1D/fortran90_source/libaloha/aloha_constants.f90", "max_stars_repo_name": "IRFM/ALOHA", "max_stars_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-12T08:42:36.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-12T08:42:41.000Z", "max_issues_repo_path": "code_1D/couplage_1D/fortran90_source/libaloha/aloha_constants.f90", "max_issues_repo_name": "IRFM/ALOHA", "max_issues_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T10:46:38.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-20T17:03:14.000Z", "max_forks_repo_path": "code_1D/couplage_1D/fortran90_source/libaloha/aloha_constants.f90", "max_forks_repo_name": "IRFM/ALOHA", "max_forks_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-10-05T12:40:02.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-12T08:41:20.000Z", "avg_line_length": 48.0, "max_line_length": 89, "alphanum_fraction": 0.6524621212, "num_tokens": 325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541610257062, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.772055967216143}} {"text": "\tFUNCTION PR_TMPK ( pres, thta )\nC************************************************************************\nC* PR_TMPK\t\t\t\t *\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes TMPK from PRES and THTA. The Poisson\t\t*\nC* equation is used:\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* TMPK = THTA * ( PRES / 1000 ) ** RKAPPA\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_TMPK ( PRES, THTA )\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tPRES\t\tREAL\t\tPressure in millibars\t\t*\nC*\tTHTA\t\tREAL \tPotential temperature in K\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_TMPK\t\tREAL\t\tTemperature in Kelvin\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* T. Roegner/CSC\t6/80\tOriginal source code\t\t\t*\nC* M. Goodman/RDS\t3/84\tModified prologue and KAPPA\t\t*\nC* I. Graffman/RDS\t12/87\tGEMPAK4\t\t\t\t\t*\nC* G. Huffman/GSC\t8/88\tDocumentation; check PRES .lt. 0\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tIF ( ERMISS ( pres ) .or. ERMISS ( thta )\n * .or. ( pres .lt. 0. ) ) THEN\n\t PR_TMPK = RMISSD\n\t ELSE\nC\nC*\t The Poisson equation.\nC\n\t PR_TMPK = thta * ( pres / 1000. ) ** RKAPPA \n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "230683132c0e324b595a29c7ac295d279c73a4fa", "size": 1290, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prtmpk.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/prmcnvlib/pr/prtmpk.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/prmcnvlib/pr/prtmpk.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 32.25, "max_line_length": 73, "alphanum_fraction": 0.4333333333, "num_tokens": 403, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693688269984, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7719551905183107}} {"text": "c program DRDUCOMP\nc>> 1994-10-19 DRDUCOMP Krogh Changes to use M77CON\nc>> 1994-08-04 DRDUCOMP CLL New subroutine: DUSETN\nc>> 1992-02-17 CLL\nc>> 1990-12-13 CLL Added demo of DUREV.\nc>> 1987-12-09 DRDUCOMP Lawson Initial Code.\nc Demo driver for the DUCOMP package, including DUREV.\nc The DUCOMP package computes partial derivatives.\nc DUREV does series reversion involving 1st and 2nd partial\nc derivatives of N functions of N variables.\nc ------------------------------------------------------------------\nc--D replaces \"?\": DR?UCOMP, ?UCOMP, ?UREV, ?USETN, ?USET, ?UATN2\nc-- & ?UPRO, ?USUM, ?USQRT, ?UQUO, ?UATAN, ?UCOS, ?USIN, ?COPY\nc ------------------------------------------------------------------\n integer I, LDIM, NMAX\n parameter(NMAX = 3, LDIM = ((NMAX+2)*(NMAX+1))/2)\n integer IWORK(NMAX)\n double precision X(LDIM), Y(LDIM), Z(LDIM)\n double precision R(LDIM), PHI(LDIM), THETA(LDIM)\n double precision SSQ(LDIM), S(LDIM), TEMP(LDIM)\n double precision X2(LDIM), Y2(LDIM), Z2(LDIM)\n double precision XSQ(LDIM), YSQ(LDIM), ZSQ(LDIM)\n double precision XVAL, YVAL, ZVAL, RSQ(LDIM), ZBYS(LDIM)\n double precision SP(LDIM), CP(LDIM), ST(LDIM), CT(LDIM)\n double precision WORK(NMAX,NMAX,3), RCOND\n double precision UT(LDIM,NMAX), TU(LDIM,NMAX)\n double precision X1(LDIM), X3(LDIM), T1(LDIM), T2(LDIM), T3(LDIM)\n parameter(XVAL = 0.1D0, YVAL = 0.2D0, ZVAL = 0.3D0)\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nc Set N, M1, and M2.\n call DUSETN(NMAX, 0, 2)\nc Initialize independent variables.\n call DUSET(XVAL,1,X)\n call DUSET(YVAL,2,Y)\n call DUSET(ZVAL,3,Z)\n print'(1x,a)',\n * 'DRDUCOMP.. Demo driver for the DUCOMP package.',\n * 'This demo first transforms (x,y,z) to (r,theta,phi),',\n * 'and then transforms back, including computation of',\n * '1st and 2nd partial derivatives.'\n write(*,'(1x/8x,10a)') ' VALUE',' D1',' D2',' D3',\n * ' D11',' D21',' D22',' D31',' D32',' D33'\n write(*,'(1x/(1x,a,10f7.3))')\n * ' X =',X,' Y =', Y,' Z =',Z\nc\nc Transform from (x,y,z) to (r,theta,phi)\n call DUATN2(Y, X, PHI)\n call DUPRO(X, X, XSQ)\n call DUPRO(Y, Y, YSQ)\n call DUPRO(Z, Z, ZSQ)\n call DUSUM(XSQ, YSQ, SSQ)\n call DUSUM(SSQ, ZSQ, RSQ)\n call DUSQRT(RSQ, R)\n call DUSQRT(SSQ, S)\n call DUQUO(Z, S, ZBYS)\n call DUATAN(ZBYS, THETA)\n write(*,'(1x/(1x,a,10f7.3))')\n * ' R =',R,' PHI =',PHI,'THETA =',THETA\nc\nc Transform back from (r,theta,phi) to (x,y,z)\n call DUCOS(PHI, CP)\n call DUCOS(THETA, CT)\n call DUPRO(CP, CT, TEMP)\n call DUPRO(TEMP, R, X2)\n call DUSIN(PHI, SP)\n call DUPRO(SP, CT, TEMP)\n call DUPRO(TEMP, R, Y2)\n call DUSIN(THETA, ST)\n call DUPRO(ST, R, Z2)\n write(*,'(1x/(1x,a,10f7.3))')\n * ' X =',X2,' Y =', Y2,' Z =',Z2\nc\nc Set data to call DUREV.\nc\n call DCOPY(LDIM, R,1, UT(1,1),1)\n call DCOPY(LDIM, PHI,1, UT(1,2),1)\n call DCOPY(LDIM, THETA,1, UT(1,3),1)\n TU(1,1) = X(1)\n TU(1,2) = Y(1)\n TU(1,3) = Z(1)\n call DUREV( UT, TU, LDIM, RCOND, IWORK, WORK)\n\n write(*,'(a)') ' ',\n * ' To demo DUREV we store (R, PHI, THETA) including',\n * ' the first and second derivatives w.r.t. (X,Y,Z) into UT(),',\n * ' and set TU() = (X, Y, Z).',\n * ' Then compute (TU1,TU2,TU3) using DUREV.',\n * ' For comparison compute (T1,T2,T3) using the known functional',\n * ' definition of (X, Y, Z) as a function of (R, PHI, THETA).'\n\n write(*,'(1x/(1x,a,10f7.3))')\n * ' TU1 =',(TU(I,1),I=1,LDIM),\n * ' TU2 =',(TU(I,2),I=1,LDIM),\n * ' TU3 =',(TU(I,3),I=1,LDIM)\nc\nc For comparison set X1, X2, X3, and transform them to\nc T1, T2, T3. These are the same operations as\nc transforming from (r,theta,phi) to (x,y,z).\nc\n call DUSET(R(1),1,X1)\n call DUSET(PHI(1),2,X2)\n call DUSET(THETA(1),3,X3)\nc\n call DUCOS(X2, CP)\n call DUCOS(X3, CT)\n call DUPRO(CP, CT, TEMP)\n call DUPRO(TEMP, X1, T1)\n call DUSIN(X2, SP)\n call DUPRO(SP, CT, TEMP)\n call DUPRO(TEMP, X1, T2)\n call DUSIN(X3, ST)\n call DUPRO(ST, X1, T3)\n write(*,'(1x/(1x,a,10f7.3))')\n * ' T1 =',T1,' T2 =', T2,' T3 =',T3\n end\n", "meta": {"hexsha": "45ff11775bccb4c223676a8db13de415d827afcc", "size": 4577, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drducomp.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drducomp.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drducomp.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 39.4568965517, "max_line_length": 72, "alphanum_fraction": 0.5092855582, "num_tokens": 1695, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768604361741, "lm_q2_score": 0.8175744850834648, "lm_q1q2_score": 0.7719349104988275}} {"text": "Module root_finder\n\n Implicit None\n\n Contains\n\n Subroutine lapack_root_finder(coefficients, real_part_root, img_part_root)\n\n ! Find roots of a polynomial using a companion matrix.\n\n ! Warning: The polynomial degree is different from the coefficient array size.\n ! Ex.:\n ! The polynomial: a + x + x^2 = 0, has a coefficient array of\n ! size 3, but its degree is 2.\n\n ! Parameters:\n ! coefficients: Real*8, Dimension(:)\n ! Stores the coefficients of a polynomial.\n ! Returns:\n ! real_part_root: Real*8, Allocatable, Dimension(:)\n ! The real part of a root.\n ! img_part_root: Real*8, Allocatable, Dimension(:)\n ! The imaginary part of a root. \n\n Implicit None\n \n Real*8, Allocatable, Dimension(:), intent(out) :: real_part_root, img_part_root\n Real*8, Dimension (:), intent(in) :: coefficients\n \n Integer*4, Parameter :: Nb = 64\n Integer*4 :: LWORK\n \n Integer*4 LDA, Info\n \n Real*8 Dummy(1,1)\n Real*8, Allocatable, Dimension (:,:) :: Companion_matrix\n Real*8, Allocatable, Dimension (:) :: WORK\n\n Integer*4 j\n Integer*4 pol_degree\n Real*8 normalization\n \n pol_degree = size(coefficients) - 1\n\n Allocate(real_part_root(pol_degree), img_part_root(pol_degree))\n\n LWORK = (2 + Nb) * 3 * (pol_degree + 1)\n \n LDA = pol_degree\n\n Allocate(Companion_matrix(LDA, pol_degree), WORK(LWORK))\n \n Companion_matrix = 0.0d0\n \n Do j = 2, pol_degree\n\n Companion_matrix(j - 1, j) = 1.0d0\n\n end do \n \n normalization = coefficients(pol_degree + 1)\n\n if( normalization == 0.0d0 )then\n print*,'Normalization is zero, this will cause infinity coefficients.'\n stop\n end if\n\n Do j = 1, pol_degree\n\n Companion_matrix(pol_degree, j) = ( -1.0d0 * coefficients(j) ) / normalization\n\n end do\n \n ! First the program find the best array size to work with.\n Call DGEEV('No left vectors', 'No right vectors', pol_degree, &\n Companion_matrix, LDA, real_part_root, &\n img_part_root, Dummy, 1, Dummy, 1, WORK, -1, Info)\n \n LWORK = min(int(LWORK), int(WORK(1)));\n\n Deallocate(WORK)\n\n Allocate(WORK(LWORK))\n\n ! Now it diagonalize the matrice.\n Call DGEEV('No left vectors', 'No right vectors', pol_degree, &\n Companion_matrix, LDA, real_part_root, &\n img_part_root, Dummy, 1, Dummy, 1, WORK, LWORK, Info)\n \n if( Info /= 0 )then \n print*,' '\n write(*,*)'INFO:', Info, LWORK\n write(*,*)'The algorithm had some problems finding the roots.'\n print*,' '\n end if\n \n End Subroutine lapack_root_finder\n\n Subroutine save_roots_arq(real_part_root, img_part_root, arq_name)\n \n ! Save in a file all the roots found.\n\n ! The first column will be the real part of the root and the second the\n ! imaginary part.\n\n ! Parameters:\n ! arq_name: Character(len=*)\n ! Name of the file where the roots will be recorded.\n\n ! Returns: \n ! real_part_root: Real*8\n ! The real part of a root.\n ! img_part_root: Real*8\n ! The imaginary part of a root.\n\n Real*8, Dimension (:), intent(in) :: real_part_root, img_part_root\n Character(len=*), intent(in) :: arq_name\n\n Integer*4 j\n\n Open(Unit = 100, file = arq_name)\n\n write(100,'(\"#\",6X,\"Real Part\",15X,\"Imaginary Part\")') \n \n if(size(real_part_root) /= size(img_part_root))then\n print*, 'Different sizes:'\n print*, 'real_part_root', size(real_part_root)\n print*, 'img_part_root', size(img_part_root)\n stop\n end if\n\n Do j = 1, size(real_part_root)\n\n If(img_part_root(j) .eq. 0.0d0)then\n\n write(100,*) real_part_root(j), 0.0d0 ! Write real roots.\n\n else\n\n write(100,*) real_part_root(j), img_part_root(j) ! Write imaginary roots.\n\n end if\n end do\n\n close(100)\n\n End Subroutine save_roots_arq\n\nEnd Module root_finder\n\nModule utils\n\n Implicit None\n\n Contains\n\n Subroutine number_of_rows_in_file(arq_name, rows_number)\n \n ! Return the number of rows of a file.\n\n ! Parameters:\n ! arq_name: Character(len=*)\n ! Name of the file to be checked.\n ! Returns:\n ! rows_number: Integer*4\n ! Number of rows in the file.\n\n Implicit None\n\n Character(len=*), intent(in) :: arq_name\n Integer*4, intent(out) :: rows_number\n\n Integer*4 end_of_file, err\n\n Open(100, file=Trim(arq_name), status='old', iostat=err)\n\n Call open_file_error(arq_name, err, 'number_of_rows_in_file')\n\n rows_number = 0\n\n Do\n\n Read(100, *, IOSTAT = end_of_file)\n\n if( IS_IOSTAT_END(end_of_file) ) exit\n\n rows_number = rows_number + 1\n\n end do\n\n Close(100)\n\n End Subroutine number_of_rows_in_file\n\n Subroutine open_file_error(arq_name, err, sub_name)\n\n ! Check if a file was open, if not print an error menssage and stop\n ! the program.\n\n ! Parameters:\n ! arq_name: Character(len=*)\n ! Name of the file to be checked.\n !\n ! err: Integer*4\n ! Error number identification.\n !\n ! sub_name: Character(len=*)\n ! Subroutine name.\n !\n ! Returns:\n ! Returns Returns nothing.\n\n Implicit None\n\n Integer*4, intent(in) :: err\n Character(len=*), intent(in) :: arq_name, sub_name\n\n if (err /= 0) then\n print*,'File (', Trim(arq_name), ') does not exist.'\n print*,'Subroutine name: ', sub_name\n print*,'Erro number:', err\n stop\n end if\n\n End Subroutine open_file_error\n\nEnd Module utils\n\nProgram Main\n\n Implicit None\n\n Call system('mkdir roots')\n\n !=====================================!\n ! Find the roots a simple polynomial. !\n !=====================================!\n Call simple_polynomial\n\n !==============================================!\n ! Find the roots of a high degree polynomial, !\n ! reading the polynomial coefficients from a !\n ! file. !\n !==============================================!\n Call high_degree_polynomial\n\nEnd Program Main\n\nSubroutine simple_polynomial\n\n Use root_finder\n Implicit None\n\n Real*8, Allocatable, Dimension (:) :: coefficients ! Polynomial coefficients.\n Real*8, Allocatable, Dimension (:) :: img_part_root, real_part_root ! Imaginary and real part of the roots.\n Integer*4 pol_degree ! Polynomial degree.\n\n Character*60 arq_name ! File name where roots values will be saved.\n\n !==========================================================!\n ! We will use the polynomial 4 - x^2 = 0 as an example !\n !==========================================================!\n\n pol_degree = 2 ! Polynomial degree\n\n Allocate(coefficients(pol_degree + 1)) ! The +1 is to count the constant term c. (c + x + x^2)\n\n coefficients(1) = 4 ! Constant (c)\n coefficients(2) = 0 ! First term (x^1)\n coefficients(3) = -1 ! Second term (x^2)\n\n ! Lapack root finder subroutine.\n Call lapack_root_finder(coefficients, real_part_root, img_part_root)\n\n ! File name where roots will be stored.\n arq_name = 'roots/simple_roots.dat'\n\n ! Save root in a file.\n Call save_roots_arq(real_part_root, img_part_root, arq_name)\n\n print*, ''\n print*, 'Solving: 4 - x^2 = 0'\n print*, 'Roots:', real_part_root(1), img_part_root(1)\n print*, 'Roots:', real_part_root(2), img_part_root(2)\n print*, ''\n\nEnd Subroutine simple_polynomial\n\nSubroutine high_degree_polynomial\n\n Use root_finder\n Use utils\n Implicit None\n\n Real*8, Allocatable, Dimension (:) :: coefficients ! Polynomial coefficients.\n Real*8, Allocatable, Dimension (:) :: img_part_root, real_part_root ! Imaginary and real part of the roots.\n Integer*4 rows_number, i, err\n\n Character(len=60) arq_name\n\n ! The name of the file name where the coefficients are stored.\n arq_name = 'HD_coefficients/HD_coefficients.dat'\n\n ! Get the number of rows in the file.\n Call number_of_rows_in_file(arq_name, rows_number)\n\n Allocate(coefficients(rows_number))\n\n Open(100, file=arq_name)\n Call open_file_error(arq_name, err, 'high_degree_polynomial')\n\n ! Read the file to get the coefficients.\n Do i = 1, rows_number\n read(100, *) coefficients(i)\n end do \n\n print*, ''\n print*, 'Solving a high degree polynomial.'\n\n ! Lapack root finder subroutine.\n Call lapack_root_finder(coefficients, real_part_root, img_part_root)\n\n arq_name = 'roots/HD_polynomial_roots.dat'\n \n ! Save root in a file.\n Call save_roots_arq(real_part_root, img_part_root, arq_name)\n\n print*,''\n print*,'Done.'\n print*,''\n \n print*,'See the roots in file: ', Trim(arq_name)\n print*, ''\n\nEnd Subroutine high_degree_polynomial\n", "meta": {"hexsha": "eff31386db84146d067751276207d45534808ebb", "size": 9153, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "root_finder_companion_matrix.f90", "max_stars_repo_name": "RGivisiez/Root-Finder-Companion-Matrix", "max_stars_repo_head_hexsha": "4b87fbe3a350060fd587dc7a6e024f876aaf530b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "root_finder_companion_matrix.f90", "max_issues_repo_name": "RGivisiez/Root-Finder-Companion-Matrix", "max_issues_repo_head_hexsha": "4b87fbe3a350060fd587dc7a6e024f876aaf530b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "root_finder_companion_matrix.f90", "max_forks_repo_name": "RGivisiez/Root-Finder-Companion-Matrix", "max_forks_repo_head_hexsha": "4b87fbe3a350060fd587dc7a6e024f876aaf530b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-03-28T22:40:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-28T22:40:59.000Z", "avg_line_length": 27.2410714286, "max_line_length": 111, "alphanum_fraction": 0.5904075167, "num_tokens": 2338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7718684707695301}} {"text": "!\telemental\n!\n!Pure procedures are procedures declared with the PURE keyword and which \n!satisfy certain constraints that ensure they have no side \n!effects. They can be used in specification expressions and \n!within FORALL constructs and statements. \n\n!Elemental procedures can be written in Fortran 95 using the ELEMENTAL \n!keyword. Elemental procedures are automatically ``pure''. \n\n!Example: \n\n\tPURE REAL FUNCTION pure_func(x,y) ! pure okay\n\t\tIMPLICIT NONE\n\t\tREAL, INTENT(IN) :: x, y\n\t\tpure_func = x*x + y*y + 2*x*y + ASIN(MIN(x/y,y/x))\n\tEND FUNCTION pure_func\n\n\tPURE REAL FUNCTION F(x,y) ! pure broken returns 'PURE REAL FU'\n\t\tIMPLICIT NONE\n\t\tREAL, INTENT(IN) :: x, y\n\t\tF = x*x + y*y + 2*x*y + ASIN(MIN(x/y,y/x))\n\tEND FUNCTION F\n\n\n\tELEMENTAL REAL FUNCTION elem_maxabs(a,b) ! elemental broke\n\t\tIMPLICIT NONE\n\t\tREAL,INTENT(IN) :: a,b\n\t\telem_maxabs = MAX(ABS(a),ABS(b))\n\tEND\n\n\tPURE REAL FUNCTION pure_maxabs2(a,b) ! pure okay\n\t\tIMPLICIT NONE\n\t\tREAL,INTENT(IN) :: a,b\n\t\tpure_maxabs2 = MAX(ABS(a),ABS(b))\n\tEND\n\n", "meta": {"hexsha": "e4f35f383dbc368362cb7e1ec1e09c54d1d3e7e6", "size": 1013, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "third_party/universal-ctags/ctags/Units/parser-fortran.r/pure_elem.f95.d/input.f95", "max_stars_repo_name": "f110/wing", "max_stars_repo_head_hexsha": "31b259f723b57a6481252a4b8b717fcee6b01ff4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-02-07T20:04:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-30T14:04:45.000Z", "max_issues_repo_path": "third_party/universal-ctags/ctags/Units/parser-fortran.r/pure_elem.f95.d/input.f95", "max_issues_repo_name": "f110/wing", "max_issues_repo_head_hexsha": "31b259f723b57a6481252a4b8b717fcee6b01ff4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-01-07T19:14:53.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-07T19:14:53.000Z", "max_forks_repo_path": "third_party/universal-ctags/ctags/Units/parser-fortran.r/pure_elem.f95.d/input.f95", "max_forks_repo_name": "f110/wing", "max_forks_repo_head_hexsha": "31b259f723b57a6481252a4b8b717fcee6b01ff4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-26T09:00:06.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-26T09:00:06.000Z", "avg_line_length": 26.6578947368, "max_line_length": 73, "alphanum_fraction": 0.7058242843, "num_tokens": 313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.7718605655706716}} {"text": " program gaussian_elimination\n integer :: i\n integer :: row, pivot_row\n real :: val, max_val, scaling_factor\n real, dimension(3, 3) :: A\n real, dimension(4, 3) :: Ay\n real, dimension(3) :: y\n real, dimension(4) :: tmp_row\n\n ! A(:, 1) = (/ 1, 3, 1 /)\n ! A(:, 2) = (/ 1, 1, -1 /)\n ! A(:, 3) = (/ 3, 11, 5 /)\n\n ! A(:, 1) = (/ 3, 1, 1 /)\n ! A(:, 2) = (/ 1, 2, 5 /)\n ! A(:, 3) = (/ 2, 5, -1 /)\n ! y = (/ 6, -4, 27 /)\n\n A(:, 1) = (/ 0, 2, 1 /)\n A(:, 2) = (/ 1, -2, -3 /)\n A(:, 3) = (/ -1, 1, 2 /)\n y = (/ -8, 0, 3 /)\n\n print \"(a)\", \"A:\"\n print \"(3f5.0)\", A\n print *\n\n print \"(a)\", \"y:\"\n print \"(3f5.0)\", y\n print *\n\n ! Augment\n Ay(1:3, :) = A\n Ay(4, :) = y\n\n print \"(a)\", \"Ay: \"\n print \"(4f6.1)\", Ay\n print *\n\n ! todo MxN matrices\n ! todo put inside function\n ! todo underdetermined systems (might require row, col pivots)\n\n print \"(a, /)\", \"Convert to Upper Triangular\"\n\n ! Convert to upper triangular form\n do row = 1, 3 ! while?\n ! Locate pivot via argmax . abs\n max_val = 0\n do i = row, 3\n val = abs(Ay(row, i))\n if (val > max_val) then\n max_val = val\n pivot_row = i\n endif\n enddo\n\n ! Swap rows\n tmp_row = Ay(:, row)\n Ay(:, row) = Ay(:, pivot_row)\n Ay(:, pivot_row) = tmp_row\n\n ! TODO assert first element is non-zero... otherwise, just skip?\n ! TODO optimizations like (row:, row)\n\n ! Normalize row\n scaling_factor = Ay(row, row)\n Ay(:, row) = Ay(:, row) / scaling_factor\n\n do i = row + 1, 3\n scaling_factor = Ay(row, i)\n Ay(:, i) = Ay(:, i) - scaling_factor * Ay(:, row)\n enddo\n\n print \"(4f6.1)\", Ay\n print *\n enddo\n\n print \"(a, /)\", \"Substitution\"\n\n do i = 3, 1, -1\n do j = i + 1, 3\n ! TODO a lot of redundant computation\n scaling_factor = Ay(j, i)\n Ay(:, i) = Ay(:, i) - scaling_factor * Ay(:, j)\n enddo\n\n print \"(4f6.1)\", Ay\n print *\n enddo\n\n print \"(a)\", \"Answer:\"\n print \"(3f6.1)\", Ay(4, :)\n print *\n\n print \"(a)\", \"Expected answer:\"\n print \"(3f6.1)\", (/ -4., -5., 2. /)\n print *\n end program gaussian_elimination\n\n! todo check that endif works in Fortran 77\n! todo check that enddo works in Fortran 77\n", "meta": {"hexsha": "12623ef72c4c52078c14beca8a8740a9b25374b4", "size": 2648, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fortran/misc/gaussian_elimination.f", "max_stars_repo_name": "YodaEmbedding/experiments", "max_stars_repo_head_hexsha": "567c6a1c18fac2d951fe2af54aaa4917b7d529d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/misc/gaussian_elimination.f", "max_issues_repo_name": "YodaEmbedding/experiments", "max_issues_repo_head_hexsha": "567c6a1c18fac2d951fe2af54aaa4917b7d529d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/misc/gaussian_elimination.f", "max_forks_repo_name": "YodaEmbedding/experiments", "max_forks_repo_head_hexsha": "567c6a1c18fac2d951fe2af54aaa4917b7d529d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.7087378641, "max_line_length": 74, "alphanum_fraction": 0.4150302115, "num_tokens": 833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.7718605635443746}} {"text": "\tFUNCTION PR_TLCL ( tmpc, dwpc )\nC************************************************************************\nC* PR_TLCL \t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes temperature at the Lifted Condensation\t*\nC* Level for a parcel of air given TMPC and DWPC. The following \t*\nC* equation is used:\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* TLCL = [ 1 / ( 1 / (DWPK-56) + ALOG (TMPK/DWPK) / 800 ) ] + 56\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Bolton.\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_TLCL ( TMPC, DWPC )\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tTMPC\t\tREAL \tTemperature in Celsius\t\t*\nC*\tDWPC\t\tREAL\t\tDewpoint in Celsius\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_TLCL\t\tREAL \tLCL temperature in Kelvin\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. Goodman/RDS\t8/84\tOriginal source\t\t\t\t*\nC* I. Graffman/RDS\t12/87\tGEMPAK4\t\t\t\t\t*\nC* G. Huffman/GSC\t8/88\tModified documentation, made -273 real *\nC* G. Krueger/EAI 4/96 Replaced C->K constant with TMCK\t*\nC* T. Lee/GSC\t\t 8/97\tRearranged equation\t\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\nC* Check for missing or out-of-bounds values.\nC\n\tIF ( ( ERMISS ( tmpc ) ) .or. ( ERMISS ( dwpc ) ) .or.\n + ( tmpc .lt. -TMCK ) .or. ( dwpc .lt. -TMCK ) ) THEN\n\t PR_TLCL = RMISSD\n\t ELSE\n\t tmpk = PR_TMCK ( tmpc )\n\t dwpk = PR_TMCK ( dwpc )\n\t PR_TLCL = ( 800. * ( dwpk - 56. ) / ( 800. + ( dwpk - 56. )*\n +\t\t\tALOG ( tmpk / dwpk ) ) ) + 56.\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "6d960a010a3659f59a1f6521fe6bf47cafd6515e", "size": 1587, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prtlcl.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/prmcnvlib/pr/prtlcl.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/prmcnvlib/pr/prtlcl.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 34.5, "max_line_length": 73, "alphanum_fraction": 0.4625078765, "num_tokens": 549, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.960951703918909, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.7718112281521833}} {"text": "! Subroutine SOLZEN\n\n! This software is part of the GLOW model. Use is governed by the Open Source\n! Academic Research License Agreement contained in the file glowlicense.txt.\n! For more information see the file glow.txt.\n\n! Stan Solomon, 1988.\n! Temporary Y2K fix-up, SCS, 2005.\n! Refactored to f90, SCC, 2016.\n\n! Returns Solar Zenith Angle SZA in degrees for specified date in form yyddd or yyyyddd,\n! universal time in seconds, geographic latitude and longitude in degrees.\n\nsubroutine solzen (idate, ut, glat, glong, sza)\n\n implicit none\n\n integer,intent(in) :: idate\n real,intent(in) :: ut, glat, glong\n real,intent(out) :: sza\n\n real,parameter :: pi=3.1415926536\n real :: rlat, rlong, sdec, srasn, gst, rh, cossza\n\n rlat = glat * pi/180.\n rlong = glong * pi/180.\n call suncor (idate, ut, sdec, srasn, gst)\n rh = srasn - (gst+rlong)\n cossza = sin(sdec)*sin(rlat) + cos(sdec)*cos(rlat)*cos(rh)\n sza = acos(cossza) * 180./pi\n return\n\nend subroutine solzen\n\n\n! Subroutine SUNCOR returns the declination SDEC and right ascension\n! SRASN of the sun in GEI coordinates, radians, for a given date IDATE\n! in yyddd or yyyyddd format, universal time UT in seconds, and Greenwich sidereal\n! time GST in radians. Reference: C.T. Russell, Geophysical Coordinate Transforms.\n\nsubroutine suncor (idate, ut, sdec, srasn, gst)\n\n implicit none\n\n integer,intent(in) :: idate\n real,intent(in) :: ut\n real,intent(out) :: sdec, srasn, gst\n\n real,parameter :: pi=3.1415926536\n real :: fday, dj, t, vl, g, slong, obliq, slp, sind, cosd\n integer :: iyr, iday\n\n fday=ut/86400.\n iyr=idate/1000\n iday=idate-iyr*1000\n\n! Temporary Y2K fix-up:\n! Should work with either yyddd or yyyyddd format from 1950 to 2050.\n! Note deteriorating accuracy after ~2050 anyway.\n! Won't work after 2100 due to lack of a leap year.\n\n if (iyr >= 1900) iyr=iyr-1900\n if (iyr < 50) iyr=iyr+100\n\n dj=365*iyr+(iyr-1)/4+iday+fday-0.5\n t=dj/36525.\n vl=amod(279.696678+.9856473354*dj,360.)\n gst=amod(279.696678+.9856473354*dj+360.*fday+180.,360.) * pi/180.\n g=amod(358.475845+.985600267*dj,360.) * pi/180.\n slong=vl+(1.91946-.004789*t)*sin(g)+.020094*sin(2.*g)\n obliq=(23.45229-0.0130125*t) *pi/180.\n slp=(slong-.005686) * pi/180.\n sind=sin(obliq)*sin(slp)\n cosd=sqrt(1.-sind**2)\n sdec=atan(sind/cosd)\n srasn=pi-atan2(1./tan(obliq)*sind/cosd,-cos(slp)/cosd)\n\n return\n\nend subroutine suncor\n", "meta": {"hexsha": "e78fccd5e0eb34fd79709a6c02d4fd4ec7379a3b", "size": 2381, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ncarglow/fortran/solzen.f90", "max_stars_repo_name": "scivision/NCAR-GLOW", "max_stars_repo_head_hexsha": "09cfd372ec6f87c24f0a5c2d63f916166c1c98fa", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-06-06T15:13:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-16T08:50:52.000Z", "max_issues_repo_path": "src/ncarglow/fortran/solzen.f90", "max_issues_repo_name": "space-physics/NCAR-GLOW", "max_issues_repo_head_hexsha": "09cfd372ec6f87c24f0a5c2d63f916166c1c98fa", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-09-29T17:03:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-14T15:38:15.000Z", "max_forks_repo_path": "src/ncarglow/fortran/solzen.f90", "max_forks_repo_name": "space-physics/NCAR-GLOW", "max_forks_repo_head_hexsha": "09cfd372ec6f87c24f0a5c2d63f916166c1c98fa", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-06-06T15:07:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-06T16:17:11.000Z", "avg_line_length": 29.3950617284, "max_line_length": 88, "alphanum_fraction": 0.6992860143, "num_tokens": 875, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517061554854, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7718112276848677}} {"text": " PROGRAM xtwofft\r\nC driver for routine twofft\r\n INTEGER N,N2\r\n REAL PER,PI\r\n PARAMETER(N=32,N2=2*N,PER=8.0,PI=3.14159)\r\n INTEGER i,isign\r\n REAL data1(N),data2(N),fft1(N2),fft2(N2),x\r\n do 11 i=1,N\r\n x=2.0*PI*i/PER\r\n data1(i)=nint(cos(x))\r\n data2(i)=nint(sin(x))\r\n11 continue\r\n call twofft(data1,data2,fft1,fft2,N)\r\n write(*,*) 'Fourier transform of first function:'\r\n call prntft(fft1,N2)\r\n write(*,*) 'Fourier transform of second function:'\r\n call prntft(fft2,N2)\r\nC invert transform\r\n isign=-1\r\n call four1(fft1,N,isign)\r\n write(*,*) 'Inverted transform = first function:'\r\n call prntft(fft1,N2)\r\n call four1(fft2,N,isign)\r\n write(*,*) 'Inverted transform = second function:'\r\n call prntft(fft2,N2)\r\n END\r\n SUBROUTINE prntft(data,n2)\r\n INTEGER i,n2,nn2,m\r\n REAL data(n2)\r\n write(*,'(1x,t7,a,t13,a,t24,a,t35,a,t47,a)')\r\n * 'n','Real(n)','Imag.(n)','Real(N-n)','Imag.(N-n)'\r\n write(*,'(1x,i6,4f12.6)') 0,data(1),data(2),data(1),data(2)\r\n do 11 i=3,(n2/2)+1,2\r\n m=(i-1)/2\r\n nn2=n2+2-i\r\n write(*,'(1x,i6,4f12.6)') m,data(i),data(i+1),\r\n * data(nn2),data(nn2+1)\r\n11 continue\r\n write(*,'(/1x,a)') ' press RETURN to continue ...'\r\n read(*,*)\r\n return\r\n END\r\n", "meta": {"hexsha": "2714f78ee1b8561f41ec5d5553a0001616f42852", "size": 1376, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xtwofft.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xtwofft.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xtwofft.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.0, "max_line_length": 66, "alphanum_fraction": 0.5276162791, "num_tokens": 493, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966686936261, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7716963607560886}} {"text": " SUBROUTINE MC01QD( DA, DB, A, B, RQ, IWARN, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute, for two given real polynomials A(x) and B(x), the\nC quotient polynomial Q(x) and the remainder polynomial R(x) of\nC A(x) divided by B(x).\nC\nC The polynomials Q(x) and R(x) satisfy the relationship\nC\nC A(x) = B(x) * Q(x) + R(x),\nC\nC where the degree of R(x) is less than the degree of B(x).\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC DA (input) INTEGER\nC The degree of the numerator polynomial A(x). DA >= -1.\nC\nC DB (input/output) INTEGER\nC On entry, the degree of the denominator polynomial B(x).\nC DB >= 0.\nC On exit, if B(DB+1) = 0.0 on entry, then DB contains the\nC index of the highest power of x for which B(DB+1) <> 0.0.\nC\nC A (input) DOUBLE PRECISION array, dimension (DA+1)\nC This array must contain the coefficients of the\nC numerator polynomial A(x) in increasing powers of x\nC unless DA = -1 on entry, in which case A(x) is taken\nC to be the zero polynomial.\nC\nC B (input) DOUBLE PRECISION array, dimension (DB+1)\nC This array must contain the coefficients of the\nC denominator polynomial B(x) in increasing powers of x.\nC\nC RQ (output) DOUBLE PRECISION array, dimension (DA+1)\nC If DA < DB on exit, then this array contains the\nC coefficients of the remainder polynomial R(x) in\nC increasing powers of x; Q(x) is the zero polynomial.\nC Otherwise, the leading DB elements of this array contain\nC the coefficients of R(x) in increasing powers of x, and\nC the next (DA-DB+1) elements contain the coefficients of\nC Q(x) in increasing powers of x.\nC\nC Warning Indicator\nC\nC IWARN INTEGER\nC = 0: no warning;\nC = k: if the degree of the denominator polynomial B(x) has\nC been reduced to (DB - k) because B(DB+1-j) = 0.0 on\nC entry for j = 0, 1, ..., k-1 and B(DB+1-k) <> 0.0.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = 1: if on entry, DB >= 0 and B(i) = 0.0, where\nC i = 1, 2, ..., DB+1.\nC\nC METHOD\nC\nC Given real polynomials\nC DA\nC A(x) = a(1) + a(2) * x + ... + a(DA+1) * x\nC\nC and\nC DB\nC B(x) = b(1) + b(2) * x + ... + b(DB+1) * x\nC\nC where b(DB+1) is non-zero, the routine computes the coeffcients of\nC the quotient polynomial\nC DA-DB\nC Q(x) = q(1) + q(2) * x + ... + q(DA-DB+1) * x\nC\nC and the remainder polynomial\nC DB-1\nC R(x) = r(1) + r(2) * x + ... + r(DB) * x\nC\nC such that A(x) = B(x) * Q(x) + R(x).\nC\nC The algorithm used is synthetic division of polynomials (see [1]),\nC which involves the following steps:\nC\nC (a) compute q(k+1) = a(DB+k+1) / b(DB+1)\nC\nC and\nC\nC (b) set a(j) = a(j) - q(k+1) * b(j-k) for j = k+1, ..., DB+k.\nC\nC Steps (a) and (b) are performed for k = DA-DB, DA-DB-1, ..., 0 and\nC the algorithm terminates with r(i) = a(i) for i = 1, 2, ..., DB.\nC\nC REFERENCES\nC\nC [1] Knuth, D.E.\nC The Art of Computer Programming, (Vol. 2, Seminumerical\nC Algorithms).\nC Addison-Wesley, Reading, Massachusetts (2nd Edition), 1981.\nC\nC NUMERICAL ASPECTS\nC\nC None.\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Mar. 1997.\nC Supersedes Release 2.0 routine MC01ED by A.J. Geurts.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Elementary polynomial operations, polynomial operations.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO\n PARAMETER ( ZERO = 0.0D0 )\nC .. Scalar Arguments ..\n INTEGER DA, DB, INFO, IWARN\nC .. Array Arguments ..\n DOUBLE PRECISION A(*), B(*), RQ(*)\nC .. Local Scalars ..\n INTEGER N\n DOUBLE PRECISION Q\nC .. External Subroutines ..\n EXTERNAL DAXPY, DCOPY, XERBLA\nC .. Executable Statements ..\nC\nC Test the input scalar arguments.\nC\n IWARN = 0\n INFO = 0\n IF( DA.LT.-1 ) THEN\n INFO = -1\n ELSE IF( DB.LT.0 ) THEN\n INFO = -2\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'MC01QD', -INFO )\n RETURN\n END IF\nC\nC WHILE ( DB >= 0 and B(DB+1) = 0 ) DO\n 20 IF ( DB.GE.0 ) THEN\n IF ( B(DB+1).EQ.ZERO ) THEN\n DB = DB - 1\n IWARN = IWARN + 1\n GO TO 20\n END IF\n END IF\nC END WHILE 20\n IF ( DB.EQ.-1 ) THEN\n INFO = 1\n RETURN\n END IF\nC\nC B(x) is non-zero.\nC\n IF ( DA.GE.0 ) THEN\n N = DA\n CALL DCOPY( N+1, A, 1, RQ, 1 )\nC WHILE ( N >= DB ) DO\n 40 IF ( N.GE.DB ) THEN\n IF ( RQ(N+1).NE.ZERO ) THEN\n Q = RQ(N+1)/B(DB+1)\n CALL DAXPY( DB, -Q, B, 1, RQ(N-DB+1), 1 )\n RQ(N+1) = Q\n END IF\n N = N - 1\n GO TO 40\n END IF\nC END WHILE 40\n END IF\nC\n RETURN\nC *** Last line of MC01QD ***\n END\n", "meta": {"hexsha": "cbae462003e1f5f056a24684959aefd161dac9ff", "size": 5695, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MC01QD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MC01QD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MC01QD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 29.3556701031, "max_line_length": 72, "alphanum_fraction": 0.5030728709, "num_tokens": 1783, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.933430812881347, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7716782659432336}} {"text": "!--------------------------------------------------\n!..Homework 1 Bonus\n!..Team 31\n!..AE305 - Numerical Methods\n!\n! This program uses RK2 method and Trapezoid method\n! to calculate ground roll distance of an aircraft\n!--------------------------------------------------\nModule data\n implicit none\n real,parameter:: WParea=29.24, takeoffweight=88250, TmaxSL=16256, nrofengines=2, friccoeff=0.02, grav=9.81\n real,parameter :: CL=1.792 ! CL is assumed constant\n real,parameter :: CD=0.2150 ! as CL is assumed constant, CD also became constant\n! Density obtained from the standart atmosphere table.\n real,parameter :: airdensitySL=1.225, airdensity1000m=1.112, airdensity2000m=1.007 \n \n real :: rho, thrust ! These variables will be set when altitude is selected\n\n \n contains\n Function Liftf(vel) ! Calculate Lift\n real :: vel, Liftf\n Liftf = CL*(1./2)*rho*(vel**2)*WParea\n return\n End Function Liftf\n \n Function Dragf(vel) ! Calculate Drag\n real :: vel, Dragf\n Dragf = CD*(1./2)*rho*(vel**2)*WParea\n return\n End Function Dragf\n \n Function Thrustf(dens) ! Calculate Thrust\n real :: dens, Thrustf\n Thrustf = TmaxSL*(dens/airdensitySL)\n return\n End Function Thrustf\n \n Function ODE(vel) ! Slope function for velocity\n real:: vel\n real :: ODE\n ODE = (thrust-Dragf(vel)-friccoeff*(takeoffweight-Liftf(vel)))*(grav/takeoffweight)\n return\n End\n End module\n \n PROGRAM HOMEWORK1_BONUS\n use data\n \n implicit none\n \n real :: stepsize, k1, k2, oldvelocity, velocity, velocityx, lift, time\n real :: integration = 0 ! Integration will be accumulated in this variable\n real, parameter:: a1 =1./4 , a2=3./4, p1=2./3 ! a1 and a2 are weights for RK2 Method\n integer :: selectedaltitude ! Altitude input is stored in this variable\n \n ! Initial values\n time=0.\n velocity=0.\n oldvelocity = 0.\n lift=0.\n\n\n ! Select altitude\n write(*,'(/,a)')'Select one of the available altitudes:'\n write(*,'(a)')' [1] 0 m (Sea Level)'\n write(*,'(a)')' [2] 1000 m '\n write(*,'(a)')' [3] 2000 m '\n write(*,'(a)',advance='no')'Input :> '\n read(*,*) selectedaltitude\n \n ! Set proper variables for selected altitude\n Select case(selectedaltitude)\n case(1)\n write(*,*) 'Selected Sea Level'\n ! Set density and thrust for sea level\n rho = airdensitySL\n thrust = TmaxSL*nrofengines\n case(2)\n write(*,*) 'Selected 1000 m'\n ! Set density and thrust for 1000 m\n rho = airdensity1000m\n thrust = Thrustf(rho)*nrofengines\n case(3)\n ! Set density and thrust 2000 m\n write(*,*) 'Selected 2000 m'\n rho = airdensity2000m\n thrust = Thrustf(rho)*nrofengines\n case default\n ! Validation check\n write(*,*) 'Unidentified input, stopping program...'\n stop\n end Select\n \n ! Select time step\n write(*,'(/,(a))',advance='no')'Enter Time Step :> '\n read(*,*) stepsize\n\n ! Use RK2 Method to find velocity and trapezoidal integration method to find distance \n do while ( lift .lt. takeoffweight ) ! Check if lift off occured\n oldvelocity = velocity; ! Current velocity is stored to be used in integration\n time = time + stepsize ! New time is defined\n k1 = ODE(velocity) ! k1 is calculated which is slope at previous velocity\n velocityx = velocity + k1*p1*stepsize ! velocityx is calculated\n k2 = ODE(velocityx) ! k2 is calculated which is slope at velocityx\n velocity = velocity + ( a1*k1 + a2*k2 )* stepsize ! New velocity is defined\n integration = integration + (1./2)*(oldvelocity + velocity)*stepsize ! Integral is calculated for every interval\n lift = Liftf(velocity) ! Calculate the lift to check if lift off occured\n enddo\n \n write(*,'(a,f12.3)') 'Minimum distance: ', integration ! Write result to terminal\n\n !..Close the output file\n close(1)\n \n stop\n END PROGRAM HOMEWORK1_BONUS\n ", "meta": {"hexsha": "f39f1efed2da647549dd84bd421850cbecb6b520", "size": 4318, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Homework1/homework1_bonus.f90", "max_stars_repo_name": "Atknssl/AE305-Homeworks", "max_stars_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-06T18:42:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-04T13:27:27.000Z", "max_issues_repo_path": "Homework1/homework1_bonus.f90", "max_issues_repo_name": "Atknssl/AE305-Homeworks", "max_issues_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework1/homework1_bonus.f90", "max_forks_repo_name": "Atknssl/AE305-Homeworks", "max_forks_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.593220339, "max_line_length": 123, "alphanum_fraction": 0.5805928671, "num_tokens": 1151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308073258007, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7716782573651498}} {"text": "!--------------------------------------------------\n!..Homework 2\n!..Team 31\n!..AE305 - Numerical Methods\n!\n!..This program calculates the chamber pressure, \n!..burn rate and specific impulse for given rocket\n!..using RK4 method with constant time step and\n!..outputs results to a file.\n!--------------------------------------------------\nModule rocket_params_vars\n Implicit none\n integer, parameter :: no_eqs = 2\n real*8, parameter :: p_a = 101325.d0, &\n rho_p = 1140.d0, &\n n = 0.305d0, &\n a = 0.0000555d0, &\n r_0 = 0.05d0, &\n r_f = 0.15d0, &\n L = 1.25d0, &\n T_c = 2810.d0, &\n R_cst = 365.d0, &\n gama = 1.25d0, &\n grav = 9.81d0, &\n pi = 4.*atan(1.d0)\n real*8 :: p_c, p_c_dot, &\n r, r_dot, &\n p_c_old, r_old, &\n A_star\n\n contains\n\n Function m_n_dot(p_c_) \n ! calculate m_n dot to use in ODE\n real*8 :: m_n_dot, p_c_\n m_n_dot = p_c_*A_star*sqrt(gama/(R_cst*T_c))*((gama+1)/2)**(-(gama+1)/(2*(gama-1)))\n return\n End Function m_n_dot \n\n Function rho_c(p_c_)\n ! calculate rho_c to use in ODE\n real*8 :: rho_c, p_c_\n rho_c = p_c_/(R_cst*T_c)\n return\n End Function rho_c\n\n Function f_cor(rad)\n ! perimeter factor\n Implicit none\n real*8 :: f_cor, eta, rad\n eta = (r_f-rad)/(r_f-r_0)\n f_cor = 1.d0\n if( eta < 0 )then\n f_cor = 0\n else if (eta <= 0.15)then\n f_cor = 1-exp(-7*eta)\n end if\n return\n End Function f_cor\n\n Function I_sp(p_c_)\n ! specific impulse\n Implicit none\n real*8 :: I_sp, p_c_\n ! Here, absolute of value inside square root is taken because\n ! there is really small error caused by numerical computing makes\n ! value inside of the square root negative for some intervals\n ! which results in runtime error. This negative value is so small\n ! that its practically zero. Therefore, absolute can be used without \n ! effecting accuracy of result. Using abs solved the runtime error.\n I_sp = (1/grav)*sqrt(abs(((2*gama*R_cst*T_c)/(gama-1))*(1-((p_a/p_c_)**((gama-1)/gama)))))\n return\n End function I_sp \n \n Function ODEs( p_c_ ) result ( k )\n Implicit none\n real*8 :: p_c_\n real*8, dimension( no_eqs ) :: k\n r_dot = a*p_c**n\n k( 1 ) = r_dot\n k( 2 ) = R_cst*T_c*(((f_cor(r)*2* a * p_c ** n)/r)*(rho_p-rho_c(p_c_))-m_n_dot(p_c_)/(pi*L*r**2))\n return\n End function\n\n Subroutine RK4( t, del_t )\n Implicit none\n integer, parameter :: no_stages = 4\n real*8 :: t, del_t\n real*8, dimension( no_eqs ) :: k( no_stages, no_eqs ), phi(no_eqs)\n p_c_old = p_c\n r_old = r\n k(1, : ) = ODEs( p_c ) !Slopes at the beginning of the interval are calculated\n \n !Slopes at p_1=0.5 fraction of the interval are calculated \n p_c = p_c_old + 0.5d0 * del_t * k(1, 2)\n r = r_old + 0.5d0 * del_t * k(1, 1)\n k(2, : ) = ODEs( p_c ) \n\n !Slopes at p_2=0.5 fraction of the interval are calculated \n p_c = p_c_old + 0.5d0 * del_t * k(2, 2)\n r = r_old + 0.5d0 * del_t * k(2, 1)\n k(3, : ) = ODEs( p_c ) \n\n !Slopes at p_3=1.0 fraction of the interval are calculated\n p_c = p_c_old + del_t * k(3, 2)\n r = r_old + del_t * k(3, 1)\n k(4, : ) = ODEs( p_c ) \n\n phi(:) = (1.0/6)* (k(1, : )+2*k(2, : )+2*k(3, : )+k(4, : )) !weighted slopes are calculated\n p_c = p_c_old + phi(2) * del_t ! p_c is updated\n r = r_old + phi(1) * del_t ! r is updated\n\n t = t + del_t ! time is updated\n return\n End subroutine\n\nEnd module\n\nProgram Rocket_Perf\n Use rocket_params_vars\n Implicit none\n character*40 :: fname\n real*8 :: dt, time, isp\n integer :: nstep = 0\n real*8 :: th_radius\n\n write(*,'(a)') 'Enter throat radius in centimeters :'\n write(*,'(a)',advance='no') ':>'\n read*, th_radius\n \n A_star = pi * (th_radius/100)**2\n\n print*,'enter time step size, dt [s] : '\n read*, dt\n\n!.. initial params\n p_c = p_a ! chamber pressure\n r = r_0 ! chamber radius\n isp = I_sp(p_c)\n\n write(*,'(a)',advance='no')' Enter the output file name [rocket.dat]:>'\n read(*,'(a)') fname\n if( fname .eq. ' ') fname = 'rocket.dat'\n open(1 ,file=fname, form='formatted')\n\n write(1,*)' \"t [s]\" \"p_c [MPa]\" \"I_sp[s]\" \"r_dot[m/s]\"'\n\n time = 0.d0\n nstep = 0\n\n do while( p_c >= p_a )\n nstep = nstep + 1\n\n ! update solution and time\n call RK4(time, dt)\n\n ! calculate isp\n isp = I_sp(p_c)\n\n ! print on screen and store soln\n if( nstep == 1 .or. mod(nstep,5)==0) &\n write(1,'(8(4x,e12.6))') time, p_c*1.d-6 ,isp, r_dot\n write(*,'(8(a,e9.3))')' t = ',time,' s, p_c = ', p_c*1d-6,' MPa, I_sp = ', isp, ' s r_dot = ',r_dot,' m/s'\n\n enddo\n\n ! Print the interval number for bonus part\n write(*,*) 'Number of time intervals needed = ', nstep\n\n close(1)\n\n stop\nEnd\n", "meta": {"hexsha": "9fc2d697faddf308275a315eac7f142914b89e69", "size": 4927, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Homework2/homework2.f90", "max_stars_repo_name": "Atknssl/AE305-Homeworks", "max_stars_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-06T18:42:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-04T13:27:27.000Z", "max_issues_repo_path": "Homework2/homework2.f90", "max_issues_repo_name": "Atknssl/AE305-Homeworks", "max_issues_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework2/homework2.f90", "max_forks_repo_name": "Atknssl/AE305-Homeworks", "max_forks_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.316091954, "max_line_length": 114, "alphanum_fraction": 0.550436371, "num_tokens": 1722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088064979618, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7716405289743674}} {"text": "! Mikayla Webber\r\n! 4670 Numerical Analysis \r\n! Homework Two Redo\r\n\r\n! From Notes on Bisection Method:\r\n! f needs to be continuous \r\n! 1. Start with a, b so that f(a), f(b) have opposite signs\r\n! 2. Find the middle M = (a+b)/2 and calculate f(M)\r\n! 3. If f(a) and f(M) have opposite signs \r\n! set b = M\r\n! else set a = M\r\n! end if\r\n! Loop back to #2\r\n\r\nmodule secret \r\n\r\nend module secret \r\n\r\n\r\nprogram WebberHomework2Question2\r\nuse secret\t\t\t\t\t\t\t! uses secret module\r\nimplicit none\r\n\r\ndouble precision :: a\r\ndouble precision :: b\r\ndouble precision :: f\r\ndouble precision :: m\r\ndouble precision :: mid\r\ndouble precision :: tolerance\r\n\r\ninteger :: i \r\ninteger :: findSign \t\t\t\t\t\t! I didn't realize \"sign\" was a\r\n\t\t\t\t\t\t\t\t! reserved word\r\na = -5.0d0\r\nb = 5.0d0\r\ntolerance = 1.0d0-10\r\n\r\ndo i = 1, 100\r\n\tm = mid(a, b)\t\t\t\t\t\t! find the middle and calculate f(M)\r\n\t\r\n\tif (((b - a) / 2) < tolerance) then \t\t\t! if m is less than tolerance then\r\n\t\tprint*, \"Middle = \", m\t\t\t\t! prints the middle\r\n\t\tstop\r\n\telse if (f(m) == 0) then\t\t\t\t! else if f(m) equals zero then\r\n\t\tprint*, \"Middle = \", m\t\t\t\t! prints the middle\r\n\t\tstop\r\n\telse \t\t\t\t\t\t\t! if neither case is true \r\n\t\tprint*, \"f(a, b) = (\", a, \",\", b, \") and m = \", m\r\n\tend if\r\n\t\r\n\tif ((findSign(f(a)) * findSign(f(m))) < 0) then\t\t! if f(a) && f(M) have opposite signs\r\n\t\tb = m\t\t\t\t\t\t! it sets b to M\r\n\telse \r\n\t\ta = m\t\t\t\t\t\t! else it sets a to b\r\n\tend if \r\nend do\r\n\r\nstop\r\nend program WebberHomework2Question2\r\n\r\n\r\n\r\ndouble precision function f(x)\t\t\t\t\t! main function for the problem\r\nimplicit none\r\n\r\ndouble precision :: x\r\n\r\nf = ((-32.17d0 / (2.0d0 * x ** 2.0d0)) * ((dsinh(x) - dsin(x)) - 1.7d0))\r\n\r\nreturn \r\nend\r\n\r\n\r\n\r\ndouble precision function mid(a,b)\t\t\t\t! function to find midpoint\r\nimplicit none\r\n\r\ndouble precision :: a\r\ndouble precision :: b\r\n\r\nmid = ((a + (b - a)) / 2.0d0)\t\t\t\t\t! midpoint formula\r\n\r\nreturn\r\nend\r\n\r\n\r\n\r\ndouble precision function findSign(x)\t\t\t\t! function to determine if negative\r\nimplicit none\t\t\t\t\t\t\t! or positive\r\n\r\ndouble precision :: x\r\n\r\nif (x < 0.0d0) then \t\t\t\t\t\t! if less than zero sign is -1\r\n\tfindSign = -1.0d0\r\nelse if (x == 0.0d0) then\t\t\t\t\t! else if x is zero sign is 0\r\n\tfindSign = 0.0d0\r\nelse\t\t\t\t\t\t\t\t! if x is greater than zero sign is 1\r\n\tfindSign = 1.0d0\r\nend if\r\n\r\nreturn\r\nend", "meta": {"hexsha": "9b10a47a04fd8008c4a76ed57091049305d62309", "size": 2251, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "4670 Numerical Analysis/Homework2/Test2Number2.f90", "max_stars_repo_name": "mwebber3/UnderGraduateCourses", "max_stars_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4670 Numerical Analysis/Homework2/Test2Number2.f90", "max_issues_repo_name": "mwebber3/UnderGraduateCourses", "max_issues_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4670 Numerical Analysis/Homework2/Test2Number2.f90", "max_forks_repo_name": "mwebber3/UnderGraduateCourses", "max_forks_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.068627451, "max_line_length": 88, "alphanum_fraction": 0.6006219458, "num_tokens": 721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8652240964782011, "lm_q1q2_score": 0.7716164109941305}} {"text": " SUBROUTINE ARCL2D (N,X,Y, T,IER)\n INTEGER N, IER\n DOUBLE PRECISION X(N), Y(N), T(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 06/10/92\nC\nC Given an ordered sequence of points (X,Y) defining a\nC polygonal curve in the plane, this subroutine computes the\nC sequence T of cumulative arc lengths along the curve:\nC T(1) = 0 and, for 2 .LE. K .LE. N, T(K) is the sum of\nC Euclidean distances between (X(I-1),Y(I-1)) and (X(I),Y(I))\nC for I = 2,...,K. A closed curve corresponds to X(1) =\nC X(N) and Y(1) = Y(N), and more generally, duplicate points\nC are permitted but must not be adjacent. Thus, T contains\nC a strictly increasing sequence of values which may be used\nC as parameters for fitting a smooth curve to the sequence\nC of points.\nC\nC On input:\nC\nC N = Number of points defining the curve. N .GE. 2.\nC\nC X,Y = Arrays of length N containing the coordinates\nC of the points.\nC\nC The above parameters are not altered by this routine.\nC\nC T = Array of length at least N.\nC\nC On output:\nC\nC T = Array containing cumulative arc lengths defined\nC above unless IER > 0.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered.\nC IER = 1 if N < 2.\nC IER = I if X(I-1) = X(I) and Y(I-1) = Y(I) for\nC some I in the range 2,...,N.\nC\nC Modules required by ARCL2D: None\nC\nC Intrinsic function called by ARCL2D: SQRT\nC\nC***********************************************************\nC\n INTEGER I, NN\n DOUBLE PRECISION DS\nC\n NN = N\n IF (NN .LT. 2) GO TO 2\n T(1) = 0.D0\n DO 1 I = 2,NN\n DS = (X(I)-X(I-1))**2 + (Y(I)-Y(I-1))**2\n IF (DS .EQ. 0.D0) GO TO 3\n T(I) = T(I-1) + SQRT(DS)\n 1 CONTINUE\n IER = 0\n RETURN\nC\nC N is outside its valid range.\nC\n 2 IER = 1\n RETURN\nC\nC Points I-1 and I coincide.\nC\n 3 IER = I\n RETURN\n END\n SUBROUTINE ARCL3D (N,X,Y,Z, T,IER)\n INTEGER N, IER\n DOUBLE PRECISION X(N), Y(N), Z(N), T(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 06/10/92\nC\nC Given an ordered sequence of points (X,Y,Z) defining a\nC polygonal curve in 3-space, this subroutine computes the\nC sequence T of cumulative arc lengths along the curve:\nC T(1) = 0 and, for 2 .LE. K .LE. N, T(K) is the sum of\nC Euclidean distances between (X(I-1),Y(I-1),Z(I-1)) and\nC (X(I),Y(I),Z(I)) for I = 2,...,K. A closed curve corre-\nC sponds to X(1) = X(N), Y(1) = Y(N), and Z(1) = Z(N). More\nC generally, duplicate points are permitted but must not be\nC adjacent. Thus, T contains a strictly increasing sequence\nC of values which may be used as parameters for fitting a\nC smooth curve to the sequence of points.\nC\nC On input:\nC\nC N = Number of points defining the curve. N .GE. 2.\nC\nC X,Y,Z = Arrays of length N containing the coordi-\nC nates of the points.\nC\nC The above parameters are not altered by this routine.\nC\nC T = Array of length at least N.\nC\nC On output:\nC\nC T = Array containing cumulative arc lengths defined\nC above unless IER > 0.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered.\nC IER = 1 if N < 2.\nC IER = I if X(I-1) = X(I), Y(I-1) = Y(I), and\nC Z(I-1) = Z(I) for some I in the range\nC 2,...,N.\nC\nC Modules required by ARCL3D: None\nC\nC Intrinsic function called by ARCL3D: SQRT\nC\nC***********************************************************\nC\n INTEGER I, NN\n DOUBLE PRECISION DS\nC\n NN = N\n IF (NN .LT. 2) GO TO 2\n T(1) = 0.D0\n DO 1 I = 2,NN\n DS = (X(I)-X(I-1))**2 + (Y(I)-Y(I-1))**2 +\n . (Z(I)-Z(I-1))**2\n IF (DS .EQ. 0.D0) GO TO 3\n T(I) = T(I-1) + SQRT(DS)\n 1 CONTINUE\n IER = 0\n RETURN\nC\nC N is outside its valid range.\nC\n 2 IER = 1\n RETURN\nC\nC Points I-1 and I coincide.\nC\n 3 IER = I\n RETURN\n END\n SUBROUTINE B2TRI (N,X,Y,W,P,D,SD,T11,T12,T21,T22, YS,\n . YP,IER)\n INTEGER N, IER\n DOUBLE PRECISION X(N), Y(N), W(N), P, D(N), SD(N),\n . T11(N), T12(N), T21(N), T22(N),\n . YS(N), YP(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 06/10/92\nC\nC This subroutine solves the order 2N symmetric positive-\nC definite block tridiagonal linear system associated with\nC minimizing the quadratic functional Q(YS,YP) described in\nC Subroutine SMCRV.\nC\nC On input:\nC\nC N = Number of data points. N .GE. 2.\nC\nC X,Y,W = Arrays of length N containing abscissae,\nC data values, and positive weights, respect-\nC ively. The abscissae must be strictly in-\nC creasing.\nC\nC P = Positive smoothing parameter defining Q.\nC\nC D,SD = Arrays of length N-1 containing positive ma-\nC trix entries. Letting DX and SIG denote the\nC width and tension factor associated with the\nC interval (X(I),X(I+1)), D(I) = SIG*(SIG*\nC COSHM(SIG) - SINHM(SIG))/(DX*E) and SD(I) =\nC SIG*SINHM(SIG)/(DX*E) where E = SIG*SINH(SIG)\nC - 2*COSHM(SIG).\nC\nC The above parameters are not altered by this routine.\nC\nC T11,T12,T21,T22 = Arrays of length N-1 used as\nC temporary work space.\nC\nC On output:\nC\nC YS,YP = Arrays of length N containing solution com-\nC ponents: function and derivative values,\nC respectively, at the abscissae.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered.\nC IER = 1 if N or P is outside its valid range\nC on input.\nC Note that no test is made for a nonpositive\nC value of X(I+1)-X(I), W(I), D(I), or SD(I).\nC\nC Modules required by B2TRI: None\nC\nC***********************************************************\nC\n INTEGER I, IM1, NM1, NN\n DOUBLE PRECISION D11I, D12I, D22I, DEN, DI, DIM1, DX,\n . PP, R1, R2, S11I, S11IM1, S12I,\n . S12IM1, S22I, S22IM1\nC\n NN = N\n NM1 = NN - 1\n PP = P\n IER = 1\n IF (NN .LT. 2 .OR. PP .LE. 0.D0) RETURN\nC\nC The forward elimination step consists of scaling a row by\nC the inverse of its diagonal block and eliminating the\nC subdiagonal block. The superdiagonal is stored in T and\nC the right hand side in YS,YP. For J = 11, 12, and 22,\nC SJI and SJIM1 denote the elements in position J of the\nC superdiagonal block in rows I and I-1, respectively.\nC Similarly, DJI denotes an element in the diagonal block\nC of row I.\nC\nC Initialize for I = 2.\nC\n DX = X(2) - X(1)\n DIM1 = D(1)\n S22IM1 = SD(1)\n S12IM1 = (DIM1 + S22IM1)/DX\n S11IM1 = -2.D0*S12IM1/DX\n R1 = PP*W(1)\n D11I = R1 - S11IM1\n D12I = S12IM1\n D22I = DIM1\n DEN = D11I*D22I - D12I*D12I\n T11(1) = (D22I*S11IM1 + D12I*S12IM1)/DEN\n T12(1) = (D22I*S12IM1 - D12I*S22IM1)/DEN\n T21(1) = -(D12I*S11IM1 + D11I*S12IM1)/DEN\n T22(1) = (D11I*S22IM1 - D12I*S12IM1)/DEN\n R1 = R1*Y(1)/DEN\n YS(1) = D22I*R1\n YP(1) = -D12I*R1\nC\nC I = 2,...,N-1:\nC\n DO 1 I = 2,NM1\n IM1 = I - 1\n DX = X(I+1) - X(I)\n DI = D(I)\n S22I = SD(I)\n S12I = (DI + S22I)/DX\n S11I = -2.D0*S12I/DX\n R1 = PP*W(I)\n D11I = R1 - S11IM1 - S11I - (S11IM1*T11(IM1) -\n . S12IM1*T21(IM1))\n D12I = S12I - S12IM1 - (S11IM1*T12(IM1) - S12IM1*\n . T22(IM1))\n D22I = DIM1 + DI - (S12IM1*T12(IM1)+S22IM1*T22(IM1))\n DEN = D11I*D22I - D12I*D12I\n T11(I) = (D22I*S11I + D12I*S12I)/DEN\n T12(I) = (D22I*S12I - D12I*S22I)/DEN\n T21(I) = -(D12I*S11I + D11I*S12I)/DEN\n T22(I) = (D11I*S22I - D12I*S12I)/DEN\n R1 = R1*Y(I) - S11IM1*YS(IM1) + S12IM1*YP(IM1)\n R2 = -S12IM1*YS(IM1) - S22IM1*YP(IM1)\n YS(I) = (D22I*R1 - D12I*R2)/DEN\n YP(I) = (D11I*R2 - D12I*R1)/DEN\n DIM1 = DI\n S22IM1 = S22I\n S12IM1 = S12I\n S11IM1 = S11I\n 1 CONTINUE\nC\nC I = N:\nC\n R1 = PP*W(NN)\n D11I = R1 - S11IM1 - (S11IM1*T11(NM1)-S12IM1*T21(NM1))\n D12I = -S12IM1 - (S11IM1*T12(NM1) - S12IM1*T22(NM1))\n D22I = DIM1 - (S12IM1*T12(NM1) + S22IM1*T22(NM1))\n DEN = D11I*D22I - D12I*D12I\n R1 = R1*Y(NN) - S11IM1*YS(NM1) + S12IM1*YP(NM1)\n R2 = -S12IM1*YS(NM1) - S22IM1*YP(NM1)\n YS(NN) = (D22I*R1 - D12I*R2)/DEN\n YP(NN) = (D11I*R2 - D12I*R1)/DEN\nC\nC Back solve the system.\nC\n DO 2 I = NM1,1,-1\n YS(I) = YS(I) - (T11(I)*YS(I+1) + T12(I)*YP(I+1))\n YP(I) = YP(I) - (T21(I)*YS(I+1) + T22(I)*YP(I+1))\n 2 CONTINUE\n IER = 0\n RETURN\n END\n SUBROUTINE B2TRIP (N,X,Y,W,P,D,SD,T11,T12,T21,T22,U11,\n . U12,U21,U22, YS,YP,IER)\n INTEGER N, IER\n DOUBLE PRECISION X(N), Y(N), W(N), P, D(N), SD(N),\n . T11(N), T12(N), T21(N), T22(N),\n . U11(N), U12(N), U21(N), U22(N),\n . YS(N), YP(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 06/10/92\nC\nC This subroutine solves the order 2(N-1) symmetric posi-\nC tive-definite linear system associated with minimizing the\nC quadratic functional Q(YS,YP) (described in Subroutine\nC SMCRV) with periodic end conditions. The matrix is block\nC tridiagonal except for nonzero blocks in the upper right\nC and lower left corners.\nC\nC On input:\nC\nC N = Number of data points. N .GE. 3.\nC\nC X = Array of length N containing a strictly in-\nC creasing sequence of abscissae.\nC\nC Y,W = Arrays of length N-1 containing data values\nC and positive weights, respectively, associated\nC with the first N-1 abscissae.\nC\nC P = Positive smoothing parameter defining Q.\nC\nC D,SD = Arrays of length N-1 containing positive ma-\nC trix elements. Letting DX and SIG denote the\nC width and tension factor associated with the\nC interval (X(I),X(I+1)), D(I) = SIG*(SIG*\nC COSHM(SIG) - SINHM(SIG))/(DX*E) and SD(I) =\nC SIG*SINHM(SIG)/(DX*E) where E = SIG*SINH(SIG)\nC - 2*COSHM(SIG).\nC\nC The above parameters are not altered by this routine.\nC\nC T11,T12,T21,T22,U11,U12,U21,U22 = Arrays of length\nC N-2 used as temp-\nC orary work space.\nC\nC On output:\nC\nC YS,YP = Arrays of length N containing solution com-\nC ponents: function and derivative values,\nC respectively, at the abscissae. YS(N) =\nC YS(1) and YP(N) = YP(1).\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered.\nC IER = 1 if N or P is outside its valid range\nC on input.\nC Note that no test is made for a nonpositive\nC value of X(I+1)-X(I), W(I), D(I), or SD(I).\nC\nC Modules required by B2TRIP: None\nC\nC***********************************************************\nC\n INTEGER I, IM1, IP1, NM1, NM2, NM3, NN\n DOUBLE PRECISION D11I, D12I, D22I, DEN, DI, DIM1,\n . DNM1, DX, PP, R1, R2, S11I, S11IM1,\n . S11NM1, S12I, S12IM1, S12NM1, S22I,\n . S22IM1, S22NM1, SU11, SU12, SU21,\n . SU22, YPNM1, YSNM1\nC\n NN = N\n NM1 = NN - 1\n NM2 = NN - 2\n NM3 = NN - 3\n PP = P\n IER = 1\n IF (NN .LT. 3 .OR. PP .LE. 0.D0) RETURN\nC\nC The forward elimination step consists of scaling a row by\nC the inverse of its diagonal block and eliminating the\nC subdiagonal block for the first N-2 rows. The super-\nC diagonal is stored in T, the negative of the last column\nC in U, and the right hand side in YS,YP. For J = 11, 12,\nC and 22, SJI and SJIM1 denote the elements in position J\nC of the superdiagonal block in rows I and I-1, respect-\nC ively. Similarly, DJI denotes an element in the diago-\nC nal block of row I.\nC\nC I = 1:\nC\n DX = X(NN) - X(NM1)\n DNM1 = D(NM1)\n S22NM1 = SD(NM1)\n S12NM1 = -(DNM1 + S22NM1)/DX\n S11NM1 = 2.D0*S12NM1/DX\n DX = X(2) - X(1)\n DI = D(1)\n S22I = SD(1)\n S12I = (DI + S22I)/DX\n S11I = -2.D0*S12I/DX\n R1 = PP*W(1)\n D11I = R1 - S11NM1 - S11I\n D12I = S12I + S12NM1\n D22I = DNM1 + DI\n DEN = D11I*D22I - D12I*D12I\n T11(1) = (D22I*S11I + D12I*S12I)/DEN\n T12(1) = (D22I*S12I - D12I*S22I)/DEN\n T21(1) = -(D12I*S11I + D11I*S12I)/DEN\n T22(1) = (D11I*S22I - D12I*S12I)/DEN\n U11(1) = -(D22I*S11NM1 + D12I*S12NM1)/DEN\n U12(1) = (D12I*S22NM1 - D22I*S12NM1)/DEN\n U21(1) = (D12I*S11NM1 + D11I*S12NM1)/DEN\n U22(1) = (D12I*S12NM1 - D11I*S22NM1)/DEN\n R1 = R1*Y(1)/DEN\n YS(1) = D22I*R1\n YP(1) = -D12I*R1\n IF (NN .EQ. 3) GO TO 2\nC\nC I = 2,...,N-2:\nC\n DO 1 I = 2,NM2\n IM1 = I - 1\n DIM1 = DI\n S22IM1 = S22I\n S12IM1 = S12I\n S11IM1 = S11I\n DX = X(I+1) - X(I)\n DI = D(I)\n S22I = SD(I)\n S12I = (DI + S22I)/DX\n S11I = -2.D0*S12I/DX\n R1 = PP*W(I)\n D11I = R1 - S11IM1 - S11I - (S11IM1*T11(IM1) -\n . S12IM1*T21(IM1))\n D12I = S12I - S12IM1 - (S11IM1*T12(IM1) - S12IM1*\n . T22(IM1))\n D22I = DIM1 + DI - (S12IM1*T12(IM1)+S22IM1*T22(IM1))\n DEN = D11I*D22I - D12I*D12I\n T11(I) = (D22I*S11I + D12I*S12I)/DEN\n T12(I) = (D22I*S12I - D12I*S22I)/DEN\n T21(I) = -(D12I*S11I + D11I*S12I)/DEN\n T22(I) = (D11I*S22I - D12I*S12I)/DEN\n SU11 = S11IM1*U11(IM1) - S12IM1*U21(IM1)\n SU12 = S11IM1*U12(IM1) - S12IM1*U22(IM1)\n SU21 = S12IM1*U11(IM1) + S22IM1*U21(IM1)\n SU22 = S12IM1*U12(IM1) + S22IM1*U22(IM1)\n U11(I) = (D12I*SU21 - D22I*SU11)/DEN\n U12(I) = (D12I*SU22 - D22I*SU12)/DEN\n U21(I) = (D12I*SU11 - D11I*SU21)/DEN\n U22(I) = (D12I*SU12 - D11I*SU22)/DEN\n R1 = R1*Y(I) - S11IM1*YS(IM1) + S12IM1*YP(IM1)\n R2 = -S12IM1*YS(IM1) - S22IM1*YP(IM1)\n YS(I) = (D22I*R1 - D12I*R2)/DEN\n YP(I) = (D11I*R2 - D12I*R1)/DEN\n 1 CONTINUE\nC\nC The backward elimination step zeros the first N-3 blocks\nC of the superdiagonal. For I = N-2,N-3,...,1, T(I) and\nC (YS(I),YP(I)) are overwritten with the negative of the\nC last column and the new right hand side, respectively.\nC\n 2 T11(NM2) = U11(NM2) - T11(NM2)\n T12(NM2) = U12(NM2) - T12(NM2)\n T21(NM2) = U21(NM2) - T21(NM2)\n T22(NM2) = U22(NM2) - T22(NM2)\n DO 3 I = NM3,1,-1\n IP1 = I + 1\n YS(I) = YS(I) - T11(I)*YS(IP1) - T12(I)*YP(IP1)\n YP(I) = YP(I) - T21(I)*YS(IP1) - T22(I)*YP(IP1)\n T11(I) = U11(I) - T11(I)*T11(IP1) - T12(I)*T21(IP1)\n T12(I) = U12(I) - T11(I)*T12(IP1) - T12(I)*T22(IP1)\n T21(I) = U21(I) - T21(I)*T11(IP1) - T22(I)*T21(IP1)\n T22(I) = U22(I) - T21(I)*T12(IP1) - T22(I)*T22(IP1)\n 3 CONTINUE\nC\nC Solve the last equation for YS(N-1),YP(N-1). SJI = SJNM2\nC and DJI = DJNM1.\nC\n R1 = PP*W(NM1)\n D11I = R1 - S11I - S11NM1 + S11NM1*T11(1) -\n . S12NM1*T21(1) + S11I*T11(NM2) - S12I*T21(NM2)\n D12I = -S12NM1 - S12I + S11NM1*T12(1) - S12NM1*T22(1)\n . + S11I*T12(NM2) - S12I*T22(NM2)\n D22I = DI + DNM1 + S12NM1*T12(1) + S22NM1*T22(1) +\n . S12I*T12(NM2) + S22I*T22(NM2)\n DEN = D11I*D22I - D12I*D12I\n R1 = R1*Y(NM1) - S11NM1*YS(1) + S12NM1*YP(1) -\n . S11I*YS(NM2) + S12I*YP(NM2)\n R2 = -S12NM1*YS(1) - S22NM1*YP(1) - S12I*YS(NM2) -\n . S22I*YP(NM2)\n YSNM1 = (D22I*R1 - D12I*R2)/DEN\n YPNM1 = (D11I*R2 - D12I*R1)/DEN\n YS(NM1) = YSNM1\n YP(NM1) = YPNM1\nC\nC Back substitute for the remainder of the solution\nC components.\nC\n DO 4 I = 1,NM2\n YS(I) = YS(I) + T11(I)*YSNM1 + T12(I)*YPNM1\n YP(I) = YP(I) + T21(I)*YSNM1 + T22(I)*YPNM1\n 4 CONTINUE\nC\nC YS(N) = YS(1) and YP(N) = YP(1).\nC\n YS(NN) = YS(1)\n YP(NN) = YP(1)\n IER = 0\n RETURN\n END\n DOUBLE PRECISION FUNCTION ENDSLP (X1,X2,X3,Y1,Y2,Y3,\n . SIGMA)\n DOUBLE PRECISION X1, X2, X3, Y1, Y2, Y3, SIGMA\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 11/17/96\nC\nC Given data values associated with a strictly increasing\nC or decreasing sequence of three abscissae X1, X2, and X3,\nC this function returns a derivative estimate at X1 based on\nC the tension spline H(x) which interpolates the data points\nC and has third derivative equal to zero at X1. Letting S1\nC denote the slope defined by the first two points, the est-\nC mate is obtained by constraining the derivative of H at X1\nC so that it has the same sign as S1 and its magnitude is\nC at most 3*abs(S1). If SIGMA = 0, H(x) is quadratic and\nC the derivative estimate is identical to the value computed\nC by Subroutine YPC1 at the first point (or the last point\nC if the abscissae are decreasing).\nC\nC On input:\nC\nC X1,X2,X3 = Abscissae satisfying either X1 < X2 < X3\nC or X1 > X2 > X3.\nC\nC Y1,Y2,Y3 = Data values associated with the abscis-\nC sae. H(X1) = Y1, H(X2) = Y2, and H(X3)\nC = Y3.\nC\nC SIGMA = Tension factor associated with H in inter-\nC val (X1,X2) or (X2,X1).\nC\nC Input parameters are not altered by this function.\nC\nC On output:\nC\nC ENDSLP = (Constrained) derivative of H at X1, or\nC zero if the abscissae are not strictly\nC monotonic.\nC\nC Module required by ENDSLP: SNHCSH\nC\nC Intrinsic functions called by ENDSLP: ABS, EXP, MAX, MIN\nC\nC***********************************************************\nC\n DOUBLE PRECISION COSHM1, COSHMS, DUMMY, DX1, DXS, S1,\n . SIG1, SIGS, T\nC\n DX1 = X2 - X1\n DXS = X3 - X1\n IF (DX1*(DXS-DX1) .LE. 0.D0) GO TO 2\n SIG1 = ABS(SIGMA)\n IF (SIG1 .LT. 1.D-9) THEN\nC\nC SIGMA = 0: H is the quadratic interpolant.\nC\n T = (DX1/DXS)**2\n GO TO 1\n ENDIF\n SIGS = SIG1*DXS/DX1\n IF (SIGS .LE. .5D0) THEN\nC\nC 0 < SIG1 < SIGS .LE. .5: compute approximations to\nC COSHM1 = COSH(SIG1)-1 and COSHMS = COSH(SIGS)-1.\nC\n CALL SNHCSH (SIG1, DUMMY,COSHM1,DUMMY)\n CALL SNHCSH (SIGS, DUMMY,COSHMS,DUMMY)\n T = COSHM1/COSHMS\n ELSE\nC\nC SIGS > .5: compute T = COSHM1/COSHMS.\nC\n T = EXP(SIG1-SIGS)*((1.D0-EXP(-SIG1))/\n . (1.D0-EXP(-SIGS)))**2\n ENDIF\nC\nC The derivative of H at X1 is\nC T = ((Y3-Y1)*COSHM1-(Y2-Y1)*COSHMS)/\nC (DXS*COSHM1-DX1*COSHMS).\nC\nC ENDSLP = T unless T*S1 < 0 or abs(T) > 3*abs(S1).\nC\n 1 T = ((Y3-Y1)*T-Y2+Y1)/(DXS*T-DX1)\n S1 = (Y2-Y1)/DX1\n IF (S1 .GE. 0.D0) THEN\n ENDSLP = MIN(MAX(0.D0,T), 3.D0*S1)\n ELSE\n ENDSLP = MAX(MIN(0.D0,T), 3.D0*S1)\n ENDIF\n RETURN\nC\nC Error in the abscissae.\nC\n 2 ENDSLP = 0.D0\n RETURN\n END\n DOUBLE PRECISION FUNCTION HPPVAL (T,N,X,Y,YP,\n . SIGMA, IER)\n INTEGER N, IER\n DOUBLE PRECISION T, X(N), Y(N), YP(N), SIGMA(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 11/17/96\nC\nC This function evaluates the second derivative HPP of a\nC Hermite interpolatory tension spline H at a point T.\nC\nC On input:\nC\nC T = Point at which HPP is to be evaluated. Extrap-\nC olation is performed if T < X(1) or T > X(N).\nC\nC N = Number of data points. N .GE. 2.\nC\nC X = Array of length N containing the abscissae.\nC These must be in strictly increasing order:\nC X(I) < X(I+1) for I = 1,...,N-1.\nC\nC Y = Array of length N containing data values.\nC H(X(I)) = Y(I) for I = 1,...,N.\nC\nC YP = Array of length N containing first deriva-\nC tives. HP(X(I)) = YP(I) for I = 1,...,N, where\nC HP denotes the derivative of H.\nC\nC SIGMA = Array of length N-1 containing tension fac-\nC tors whose absolute values determine the\nC balance between cubic and linear in each\nC interval. SIGMA(I) is associated with int-\nC erval (I,I+1) for I = 1,...,N-1.\nC\nC Input parameters are not altered by this function.\nC\nC On output:\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered and\nC X(1) .LE. T .LE. X(N).\nC IER = 1 if no errors were encountered and\nC extrapolation was necessary.\nC IER = -1 if N < 2.\nC IER = -2 if the abscissae are not in strictly\nC increasing order. (This error will\nC not necessarily be detected.)\nC\nC HPPVAL = Second derivative value HPP(T), or zero if\nC IER < 0.\nC\nC Modules required by HPPVAL: INTRVL, SNHCSH\nC\nC Intrinsic functions called by HPPVAL: ABS, EXP\nC\nC***********************************************************\nC\n INTEGER I, IP1\n DOUBLE PRECISION B1, B2, CM, CM2, CMM, COSH2, D1, D2,\n . DUMMY, DX, E, E1, E2, EMS, S, SB1,\n . SB2, SBIG, SIG, SINH2, SM, SM2, TM\n INTEGER INTRVL\nC\n DATA SBIG/85.D0/\n IF (N .LT. 2) GO TO 1\nC\nC Find the index of the left end of an interval containing\nC T. If T < X(1) or T > X(N), extrapolation is performed\nC using the leftmost or rightmost interval.\nC\n IF (T .LT. X(1)) THEN\n I = 1\n IER = 1\n ELSEIF (T .GT. X(N)) THEN\n I = N-1\n IER = 1\n ELSE\n I = INTRVL (T,N,X)\n IER = 0\n ENDIF\n IP1 = I + 1\nC\nC Compute interval width DX, local coordinates B1 and B2,\nC and second differences D1 and D2.\nC\n DX = X(IP1) - X(I)\n IF (DX .LE. 0.D0) GO TO 2\n B1 = (X(IP1) - T)/DX\n B2 = 1.D0 - B1\n S = (Y(IP1)-Y(I))/DX\n D1 = S - YP(I)\n D2 = YP(IP1) - S\n SIG = ABS(SIGMA(I))\n IF (SIG .LT. 1.D-9) THEN\nC\nC SIG = 0: H is the Hermite cubic interpolant.\nC\n HPPVAL = (D1 + D2 + 3.D0*(B2-B1)*(D2-D1))/DX\n ELSEIF (SIG .LE. .5D0) THEN\nC\nC 0 .LT. SIG .LE. .5: use approximations designed to avoid\nC cancellation error in the hyperbolic functions.\nC\n SB2 = SIG*B2\n CALL SNHCSH (SIG, SM,CM,CMM)\n CALL SNHCSH (SB2, SM2,CM2,DUMMY)\n SINH2 = SM2 + SB2\n COSH2 = CM2 + 1.D0\n E = SIG*SM - CMM - CMM\n HPPVAL = SIG*((CM*SINH2-SM*COSH2)*(D1+D2) +\n . SIG*(CM*COSH2-(SM+SIG)*SINH2)*D1)/(DX*E)\n ELSE\nC\nC SIG > .5: use negative exponentials in order to avoid\nC overflow. Note that EMS = EXP(-SIG). In the case of\nC extrapolation (negative B1 or B2), H is approximated by\nC a linear function if -SIG*B1 or -SIG*B2 is large.\nC\n SB1 = SIG*B1\n SB2 = SIG - SB1\n IF (-SB1 .GT. SBIG .OR. -SB2 .GT. SBIG) THEN\n HPPVAL = 0.D0\n ELSE\n E1 = EXP(-SB1)\n E2 = EXP(-SB2)\n EMS = E1*E2\n TM = 1.D0 - EMS\n E = TM*(SIG*(1.D0+EMS) - TM - TM)\n HPPVAL = SIG*(SIG*((E1*EMS+E2)*D1+(E1+E2*EMS)*D2)-\n . TM*(E1+E2)*(D1+D2))/(DX*E)\n ENDIF\n ENDIF\n RETURN\nC\nC N is outside its valid range.\nC\n 1 HPPVAL = 0.D0\n IER = -1\n RETURN\nC\nC X(I) .GE. X(I+1).\nC\n 2 HPPVAL = 0.D0\n IER = -2\n RETURN\n END\n DOUBLE PRECISION FUNCTION HPVAL (T,N,X,Y,YP,\n . SIGMA, IER)\n INTEGER N, IER\n DOUBLE PRECISION T, X(N), Y(N), YP(N), SIGMA(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 11/17/96\nC\nC This function evaluates the first derivative HP of a\nC Hermite interpolatory tension spline H at a point T.\nC\nC On input:\nC\nC T = Point at which HP is to be evaluated. Extrapo-\nC lation is performed if T < X(1) or T > X(N).\nC\nC N = Number of data points. N .GE. 2.\nC\nC X = Array of length N containing the abscissae.\nC These must be in strictly increasing order:\nC X(I) < X(I+1) for I = 1,...,N-1.\nC\nC Y = Array of length N containing data values.\nC H(X(I)) = Y(I) for I = 1,...,N.\nC\nC YP = Array of length N containing first deriva-\nC tives. HP(X(I)) = YP(I) for I = 1,...,N.\nC\nC SIGMA = Array of length N-1 containing tension fac-\nC tors whose absolute values determine the\nC balance between cubic and linear in each\nC interval. SIGMA(I) is associated with int-\nC erval (I,I+1) for I = 1,...,N-1.\nC\nC Input parameters are not altered by this function.\nC\nC On output:\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered and\nC X(1) .LE. T .LE. X(N).\nC IER = 1 if no errors were encountered and\nC extrapolation was necessary.\nC IER = -1 if N < 2.\nC IER = -2 if the abscissae are not in strictly\nC increasing order. (This error will\nC not necessarily be detected.)\nC\nC HPVAL = Derivative value HP(T), or zero if IER < 0.\nC\nC Modules required by HPVAL: INTRVL, SNHCSH\nC\nC Intrinsic functions called by HPVAL: ABS, EXP\nC\nC***********************************************************\nC\n INTEGER I, IP1\n DOUBLE PRECISION B1, B2, CM, CM2, CMM, D1, D2, DUMMY,\n . DX, E, E1, E2, EMS, S, S1, SB1, SB2,\n . SBIG, SIG, SINH2, SM, SM2, TM\n INTEGER INTRVL\nC\n DATA SBIG/85.D0/\n IF (N .LT. 2) GO TO 1\nC\nC Find the index of the left end of an interval containing\nC T. If T < X(1) or T > X(N), extrapolation is performed\nC using the leftmost or rightmost interval.\nC\n IF (T .LT. X(1)) THEN\n I = 1\n IER = 1\n ELSEIF (T .GT. X(N)) THEN\n I = N-1\n IER = 1\n ELSE\n I = INTRVL (T,N,X)\n IER = 0\n ENDIF\n IP1 = I + 1\nC\nC Compute interval width DX, local coordinates B1 and B2,\nC and second differences D1 and D2.\nC\n DX = X(IP1) - X(I)\n IF (DX .LE. 0.D0) GO TO 2\n B1 = (X(IP1) - T)/DX\n B2 = 1.D0 - B1\n S1 = YP(I)\n S = (Y(IP1)-Y(I))/DX\n D1 = S - S1\n D2 = YP(IP1) - S\n SIG = ABS(SIGMA(I))\n IF (SIG .LT. 1.D-9) THEN\nC\nC SIG = 0: H is the Hermite cubic interpolant.\nC\n HPVAL = S1 + B2*(D1 + D2 - 3.D0*B1*(D2-D1))\n ELSEIF (SIG .LE. .5D0) THEN\nC\nC 0 .LT. SIG .LE. .5: use approximations designed to avoid\nC cancellation error in the hyperbolic functions.\nC\n SB2 = SIG*B2\n CALL SNHCSH (SIG, SM,CM,CMM)\n CALL SNHCSH (SB2, SM2,CM2,DUMMY)\n SINH2 = SM2 + SB2\n E = SIG*SM - CMM - CMM\n HPVAL = S1 + ((CM*CM2-SM*SINH2)*(D1+D2) +\n . SIG*(CM*SINH2-(SM+SIG)*CM2)*D1)/E\n ELSE\nC\nC SIG > .5: use negative exponentials in order to avoid\nC overflow. Note that EMS = EXP(-SIG). In the case of\nC extrapolation (negative B1 or B2), H is approximated by\nC a linear function if -SIG*B1 or -SIG*B2 is large.\nC\n SB1 = SIG*B1\n SB2 = SIG - SB1\n IF (-SB1 .GT. SBIG .OR. -SB2 .GT. SBIG) THEN\n HPVAL = S\n ELSE\n E1 = EXP(-SB1)\n E2 = EXP(-SB2)\n EMS = E1*E2\n TM = 1.D0 - EMS\n E = TM*(SIG*(1.D0+EMS) - TM - TM)\n HPVAL = S + (TM*((E2-E1)*(D1+D2) + TM*(D1-D2)) +\n . SIG*((E1*EMS-E2)*D1 + (E1-E2*EMS)*D2))/E\n ENDIF\n ENDIF\n RETURN\nC\nC N is outside its valid range.\nC\n 1 HPVAL = 0.D0\n IER = -1\n RETURN\nC\nC X(I) .GE. X(I+1).\nC\n 2 HPVAL = 0.D0\n IER = -2\n RETURN\n END\n DOUBLE PRECISION FUNCTION HVAL (T,N,X,Y,YP,SIGMA, IER)\n INTEGER N, IER\n DOUBLE PRECISION T, X(N), Y(N), YP(N), SIGMA(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 11/17/96\nC\nC This function evaluates a Hermite interpolatory tension\nC spline H at a point T. Note that a large value of SIGMA\nC may cause underflow. The result is assumed to be zero.\nC\nC Given arrays X, Y, YP, and SIGMA of length NN, if T is\nC known to lie in the interval (X(I),X(J)) for some I < J,\nC a gain in efficiency can be achieved by calling this\nC function with N = J+1-I (rather than NN) and the I-th\nC components of the arrays (rather than the first) as par-\nC ameters.\nC\nC On input:\nC\nC T = Point at which H is to be evaluated. Extrapo-\nC lation is performed if T < X(1) or T > X(N).\nC\nC N = Number of data points. N .GE. 2.\nC\nC X = Array of length N containing the abscissae.\nC These must be in strictly increasing order:\nC X(I) < X(I+1) for I = 1,...,N-1.\nC\nC Y = Array of length N containing data values.\nC H(X(I)) = Y(I) for I = 1,...,N.\nC\nC YP = Array of length N containing first deriva-\nC tives. HP(X(I)) = YP(I) for I = 1,...,N, where\nC HP denotes the derivative of H.\nC\nC SIGMA = Array of length N-1 containing tension fac-\nC tors whose absolute values determine the\nC balance between cubic and linear in each\nC interval. SIGMA(I) is associated with int-\nC erval (I,I+1) for I = 1,...,N-1.\nC\nC Input parameters are not altered by this function.\nC\nC On output:\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered and\nC X(1) .LE. T .LE. X(N).\nC IER = 1 if no errors were encountered and\nC extrapolation was necessary.\nC IER = -1 if N < 2.\nC IER = -2 if the abscissae are not in strictly\nC increasing order. (This error will\nC not necessarily be detected.)\nC\nC HVAL = Function value H(T), or zero if IER < 0.\nC\nC Modules required by HVAL: INTRVL, SNHCSH\nC\nC Intrinsic functions called by HVAL: ABS, EXP\nC\nC***********************************************************\nC\n INTEGER I, IP1\n DOUBLE PRECISION B1, B2, CM, CM2, CMM, D1, D2, DUMMY,\n . DX, E, E1, E2, EMS, S, S1, SB1, SB2,\n . SBIG, SIG, SM, SM2, TM, TP, TS, U, Y1\n INTEGER INTRVL\nC\n DATA SBIG/85.D0/\n IF (N .LT. 2) GO TO 1\nC\nC Find the index of the left end of an interval containing\nC T. If T < X(1) or T > X(N), extrapolation is performed\nC using the leftmost or rightmost interval.\nC\n IF (T .LT. X(1)) THEN\n I = 1\n IER = 1\n ELSEIF (T .GT. X(N)) THEN\n I = N-1\n IER = 1\n ELSE\n I = INTRVL (T,N,X)\n IER = 0\n ENDIF\n IP1 = I + 1\nC\nC Compute interval width DX, local coordinates B1 and B2,\nC and second differences D1 and D2.\nC\n DX = X(IP1) - X(I)\n IF (DX .LE. 0.D0) GO TO 2\n U = T - X(I)\n B2 = U/DX\n B1 = 1.D0 - B2\n Y1 = Y(I)\n S1 = YP(I)\n S = (Y(IP1)-Y1)/DX\n D1 = S - S1\n D2 = YP(IP1) - S\n SIG = ABS(SIGMA(I))\n IF (SIG .LT. 1.D-9) THEN\nC\nC SIG = 0: H is the Hermite cubic interpolant.\nC\n HVAL = Y1 + U*(S1 + B2*(D1 + B1*(D1-D2)))\n ELSEIF (SIG .LE. .5D0) THEN\nC\nC 0 .LT. SIG .LE. .5: use approximations designed to avoid\nC cancellation error in the hyperbolic functions.\nC\n SB2 = SIG*B2\n CALL SNHCSH (SIG, SM,CM,CMM)\n CALL SNHCSH (SB2, SM2,CM2,DUMMY)\n E = SIG*SM - CMM - CMM\n HVAL = Y1 + S1*U + DX*((CM*SM2-SM*CM2)*(D1+D2) +\n . SIG*(CM*CM2-(SM+SIG)*SM2)*D1)\n . /(SIG*E)\n ELSE\nC\nC SIG > .5: use negative exponentials in order to avoid\nC overflow. Note that EMS = EXP(-SIG). In the case of\nC extrapolation (negative B1 or B2), H is approximated by\nC a linear function if -SIG*B1 or -SIG*B2 is large.\nC\n SB1 = SIG*B1\n SB2 = SIG - SB1\n IF (-SB1 .GT. SBIG .OR. -SB2 .GT. SBIG) THEN\n HVAL = Y1 + S*U\n ELSE\n E1 = EXP(-SB1)\n E2 = EXP(-SB2)\n EMS = E1*E2\n TM = 1.D0 - EMS\n TS = TM*TM\n TP = 1.D0 + EMS\n E = TM*(SIG*TP - TM - TM)\n HVAL = Y1 + S*U + DX*(TM*(TP-E1-E2)*(D1+D2) + SIG*\n . ((E2+EMS*(E1-2.D0)-B1*TS)*D1+\n . (E1+EMS*(E2-2.D0)-B2*TS)*D2))/\n . (SIG*E)\n ENDIF\n ENDIF\n RETURN\nC\nC N is outside its valid range.\nC\n 1 HVAL = 0.D0\n IER = -1\n RETURN\nC\nC X(I) .GE. X(I+1).\nC\n 2 HVAL = 0.D0\n IER = -2\n RETURN\n END\n INTEGER FUNCTION INTRVL (T,N,X)\n INTEGER N\n DOUBLE PRECISION T, X(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 06/10/92\nC\nC This function returns the index of the left end of an\nC interval (defined by an increasing sequence X) which\nC contains the value T. The method consists of first test-\nC ing the interval returned by a previous call, if any, and\nC then using a binary search if necessary.\nC\nC On input:\nC\nC T = Point to be located.\nC\nC N = Length of X. N .GE. 2.\nC\nC X = Array of length N assumed (without a test) to\nC contain a strictly increasing sequence of\nC values.\nC\nC Input parameters are not altered by this function.\nC\nC On output:\nC\nC INTRVL = Index I defined as follows:\nC\nC I = 1 if T .LT. X(2) or N .LE. 2,\nC I = N-1 if T .GE. X(N-1), and\nC X(I) .LE. T .LT. X(I+1) otherwise.\nC\nC Modules required by INTRVL: None\nC\nC***********************************************************\nC\n INTEGER IH, IL, K\n DOUBLE PRECISION TT\nC\n SAVE IL\n DATA IL/1/\n TT = T\n IF (IL .GE. 1 .AND. IL .LT. N) THEN\n IF (X(IL) .LE. TT .AND. TT .LT. X(IL+1)) GO TO 2\n ENDIF\nC\nC Initialize low and high indexes.\nC\n IL = 1\n IH = N\nC\nC Binary search:\nC\n 1 IF (IH .LE. IL+1) GO TO 2\n K = (IL+IH)/2\n IF (TT .LT. X(K)) THEN\n IH = K\n ELSE\n IL = K\n ENDIF\n GO TO 1\nC\nC X(IL) .LE. T .LT. X(IL+1) or (T .LT. X(1) and IL=1)\nC or (T .GE. X(N) and IL=N-1)\nC\n 2 INTRVL = IL\n RETURN\n END\n DOUBLE PRECISION FUNCTION SIG0 (X1,X2,Y1,Y2,Y1P,Y2P,\n . IFL,HBND,TOL, IER)\n INTEGER IFL, IER\n DOUBLE PRECISION X1, X2, Y1, Y2, Y1P, Y2P, HBND, TOL\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 11/18/96\nC\nC Given a pair of abscissae with associated ordinates and\nC slopes, this function determines the smallest (nonnega-\nC tive) tension factor SIGMA such that the Hermite interpo-\nC latory tension spline H(x), defined by SIGMA and the data,\nC is bounded (either above or below) by HBND for all x in\nC (X1,X2).\nC\nC On input:\nC\nC X1,X2 = Abscissae. X1 < X2.\nC\nC Y1,Y2 = Values of H at X1 and X2.\nC\nC Y1P,Y2P = Derivative values of H at X1 and X2.\nC\nC IFL = Option indicator:\nC IFL = -1 if HBND is a lower bound on H.\nC IFL = 1 if HBND is an upper bound on H.\nC\nC HBND = Bound on H. If IFL = -1, HBND .LE. min(Y1,\nC Y2). If IFL = 1, HBND .GE. max(Y1,Y2).\nC\nC TOL = Tolerance whose magnitude determines how close\nC SIGMA is to its optimal value when nonzero\nC finite tension is necessary and sufficient to\nC satisfy the constraint. For a lower bound,\nC SIGMA is chosen so that HBND .LE. HMIN .LE.\nC HBND + abs(TOL), where HMIN is the minimum\nC value of H in the interval, and for an upper\nC bound, the maximum of H satisfies HBND -\nC abs(TOL) .LE. HMAX .LE. HBND. Thus, the con-\nC straint is satisfied but possibly with more\nC tension than necessary.\nC\nC Input parameters are not altered by this function.\nC\nC On output:\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered and the\nC constraint can be satisfied with fin-\nC ite tension.\nC IER = 1 if no errors were encountered but in-\nC finite tension is required to satisfy\nC the constraint (e.g., IFL = -1, HBND\nC = Y1, and Y1P < 0.).\nC IER = -1 if X2 .LE. X1 or abs(IFL) .NE. 1.\nC IER = -2 if HBND is outside its valid range\nC on input.\nC\nC SIG0 = Minimum tension factor defined above unless\nC IER < 0, in which case SIG0 = -1. If IER =\nC 1, SIG0 = 85, resulting in an approximation\nC to the linear interpolant of the endpoint\nC values. Note, however, that SIG0 may be\nC larger than 85 if IER = 0.\nC\nC Modules required by SIG0: SNHCSH, STORE\nC\nC Intrinsic functions called by SIG0: ABS, DBLE, EXP, LOG,\nC MAX, MIN, SIGN,\nC SQRT\nC\nC***********************************************************\nC\n INTEGER LUN, NIT\n DOUBLE PRECISION A, A0, AA, B, B0, BND, C, C1, C2,\n . COSHM, COSHMM, D, D0, D1PD2, D2,\n . DMAX, DSIG, DX, E, EMS, F, F0, FMAX,\n . FNEG, FTOL, R, RF, RSIG, RTOL, S, S1,\n . S2, SBIG, SCM, SIG, SINHM, SNEG,\n . SSINH, SSM, STOL, T, T0, T1, T2, TM,\n . Y1L, Y2L\n DOUBLE PRECISION STORE\nC\n DATA SBIG/85.D0/, LUN/-1/\nC\nC Store local parameters and test for errors.\nC\n RF = DBLE(IFL)\n DX = X2 - X1\n IF (ABS(RF) .NE. 1.D0 .OR. DX .LE. 0.D0) GO TO 8\n Y1L = Y1\n Y2L = Y2\n BND = HBND\nC\nC Test for a valid constraint.\nC\n IF ((RF .LT. 0.D0 .AND. MIN(Y1L,Y2L) .LT. BND)\n . .OR. (RF .GT. 0.D0 .AND.\n . BND .LT. MAX(Y1L,Y2L))) GO TO 9\nC\nC Test for infinite tension required.\nC\n S1 = Y1P\n S2 = Y2P\n IF ((Y1L .EQ. BND .AND. RF*S1 .GT. 0.D0) .OR.\n . (Y2L .EQ. BND .AND. RF*S2 .LT. 0.D0)) GO TO 7\nC\nC Test for SIG = 0 sufficient.\nC\n SIG = 0.D0\n IF (RF*S1 .LE. 0.D0 .AND. RF*S2 .GE. 0.D0) GO TO 6\nC\nC Compute coefficients A0 and B0 of the Hermite cubic in-\nC terpolant H0(x) = Y2 - DX*(S2*R + B0*R**2 + A0*R**3/3)\nC where R = (X2-x)/DX.\nC\n S = (Y2L-Y1L)/DX\n T0 = 3.D0*S - S1 - S2\n A0 = 3.D0*(S-T0)\n B0 = T0 - S2\n D0 = T0*T0 - S1*S2\nC\nC H0 has local extrema in (X1,X2) iff S1*S2 < 0 or\nC (T0*(S1+S2) < 0 and D0 .GE. 0).\nC\n IF (S1*S2 .GE. 0.D0 .AND. (T0*(S1+S2) .GE. 0.D0\n . .OR. D0 .LT. 0.D0)) GO TO 6\n IF (A0 .EQ. 0.D0) THEN\nC\nC H0 is quadratic and has an extremum at R = -S2/(2*B0).\nC H0(R) = Y2 + DX*S2**2/(4*B0). Note that A0 = 0 im-\nC plies 2*B0 = S1-S2, and S1*S2 < 0 implies B0 .NE. 0.\nC Also, the extremum is a min iff HBND is a lower bound.\nC\n F0 = (BND - Y2L - DX*S2*S2/(4.D0*B0))*RF\n ELSE\nC\nC A0 .NE. 0 and H0 has extrema at R = (-B0 +/- SQRT(D0))/\nC A0 = S2/(-B0 -/+ SQRT(D0)), where the negative root\nC corresponds to a min. The expression for R is chosen\nC to avoid cancellation error. H0(R) = Y2 + DX*(S2*B0 +\nC 2*D0*R)/(3*A0).\nC\n T = -B0 - SIGN(SQRT(D0),B0)\n R = T/A0\n IF (RF*B0 .GT. 0.D0) R = S2/T\n F0 = (BND - Y2L - DX*(S2*B0+2.D0*D0*R)/(3.D0*A0))*RF\n ENDIF\nC\nC F0 .GE. 0 iff SIG = 0 is sufficient to satisfy the\nC constraint.\nC\n IF (F0 .GE. 0.D0) GO TO 6\nC\nC Find a zero of F(SIG) = (BND-H(R))*RF where the derivative\nC of H, HP, vanishes at R. F is a nondecreasing function,\nC F(0) < 0, and F = FMAX for SIG sufficiently large.\nC\nC Initialize parameters for the secant method. The method\nC uses three points: (SG0,F0), (SIG,F), and (SNEG,FNEG),\nC where SG0 and SNEG are defined implicitly by DSIG = SIG\nC - SG0 and DMAX = SIG - SNEG. SG0 is initially zero and\nC SNEG is initialized to a sufficiently large value that\nC FNEG > 0. This value is used only if the initial value\nC of F is negative.\nC\n FMAX = MAX(1.D-3,MIN(ABS(Y1L-BND),ABS(Y2L-BND)))\n T = MAX(ABS(Y1L-BND),ABS(Y2L-BND))\n SIG = DX*MAX(ABS(S1),ABS(S2))/T\n DMAX = SIG*(1.D0-T/FMAX)\n SNEG = SIG - DMAX\n IF (LUN .GE. 0 .AND. RF .LT. 0.D0)\n . WRITE (LUN,100) F0, FMAX, SNEG\n IF (LUN .GE. 0 .AND. RF .GT. 0.D0)\n . WRITE (LUN,110) F0, FMAX, SNEG\n 100 FORMAT (//1X,'SIG0 (LOWER BOUND) -- F(0) = ',D15.8,\n . ', FMAX = ',D15.8/1X,46X,'SNEG = ',D15.8/)\n 110 FORMAT (//1X,'SIG0 (UPPER BOUND) -- F(0) = ',D15.8,\n . ', FMAX = ',D15.8/1X,46X,'SNEG = ',D15.8/)\n DSIG = SIG\n FNEG = FMAX\n D2 = S2 - S\n D1PD2 = S2 - S1\n NIT = 0\nC\nC Compute an absolute tolerance FTOL = abs(TOL), and a\nC relative tolerance RTOL = 100*MACHEPS.\nC\n FTOL = ABS(TOL)\n RTOL = 1.D0\n 1 RTOL = RTOL/2.D0\n IF (STORE(RTOL+1.D0) .GT. 1.D0) GO TO 1\n RTOL = RTOL*200.D0\nC\nC Top of loop: compute F.\nC\n 2 EMS = EXP(-SIG)\n IF (SIG .LE. .5D0) THEN\nC\nC SIG .LE. .5: use approximations designed to avoid can-\nC cellation error (associated with small\nC SIG) in the modified hyperbolic functions.\nC\n CALL SNHCSH (SIG, SINHM,COSHM,COSHMM)\n C1 = SIG*COSHM*D2 - SINHM*D1PD2\n C2 = SIG*(SINHM+SIG)*D2 - COSHM*D1PD2\n A = C2 - C1\n AA = A/EMS\n E = SIG*SINHM - COSHMM - COSHMM\n ELSE\nC\nC SIG > .5: scale SINHM and COSHM by 2*EXP(-SIG) in order\nC to avoid overflow.\nC\n TM = 1.D0 - EMS\n SSINH = TM*(1.D0+EMS)\n SSM = SSINH - 2.D0*SIG*EMS\n SCM = TM*TM\n C1 = SIG*SCM*D2 - SSM*D1PD2\n C2 = SIG*SSINH*D2 - SCM*D1PD2\n AA = 2.D0*(SIG*TM*D2 + (TM-SIG)*D1PD2)\n A = EMS*AA\n E = SIG*SSINH - SCM - SCM\n ENDIF\nC\nC HP(R) = S2 - (C1*SINH(SIG*R) - C2*COSHM(SIG*R))/E = 0\nC for ESR = (-B +/- SQRT(D))/A = C/(-B -/+ SQRT(D)),\nC where ESR = EXP(SIG*R), A = C2-C1, D = B**2 - A*C, and\nC B and C are defined below.\nC\n B = E*S2 - C2\n C = C2 + C1\n D = B*B - A*C\n F = 0.D0\n IF (AA*C .EQ. 0.D0 .AND. B .EQ. 0.D0) GO TO 3\n F = FMAX\n IF (D .LT. 0.D0) GO TO 3\n T1 = SQRT(D)\n T = -B - SIGN(T1,B)\n RSIG = 0.D0\n IF (RF*B .LT. 0.D0 .AND. AA .NE. 0.) THEN\n IF (T/AA .GT. 0.D0) RSIG = SIG + LOG(T/AA)\n ENDIF\n IF ((RF*B .GT. 0.D0 .OR. AA .EQ. 0.D0) .AND.\n . C/T .GT. 0.D0) RSIG = LOG(C/T)\n IF ((RSIG .LE. 0.D0 .OR. RSIG .GE. SIG) .AND.\n . B .NE. 0.D0) GO TO 3\nC\nC H(R) = Y2 - DX*(B*SIG*R + C1 + RF*SQRT(D))/(SIG*E).\nC\n F = (BND - Y2L + DX*(B*RSIG+C1+RF*T1)/(SIG*E))*RF\nC\nC Update the number of iterations NIT.\nC\n 3 NIT = NIT + 1\n IF (LUN .GE. 0) WRITE (LUN,120) NIT, SIG, F\n 120 FORMAT (1X,3X,I2,' -- SIG = ',D15.8,', F = ',\n . D15.8)\n IF (F0*F .LT. 0.D0) THEN\nC\nC F0*F < 0. Update (SNEG,FNEG) to (SG0,F0) so that F\nC and FNEG always have opposite signs. If SIG is\nC closer to SNEG than SG0, then swap (SNEG,FNEG) with\nC (SG0,F0).\nC\n T1 = DMAX\n T2 = FNEG\n DMAX = DSIG\n FNEG = F0\n IF (ABS(DSIG) .GT. ABS(T1)) THEN\n DSIG = T1\n F0 = T2\n ENDIF\n ENDIF\nC\nC Test for convergence.\nC\n STOL = RTOL*SIG\n IF (ABS(DMAX) .LE. STOL .OR. (F .GE. 0.D0 .AND.\n . F .LE. FTOL) .OR. ABS(F) .LE. RTOL) GO TO 6\nC\nC Test for F0 = F = FMAX or F < 0 on the first iteration.\nC\n IF (F0 .NE. F .AND. (NIT .GT. 1 .OR. F .GT. 0.D0))\n . GO TO 5\nC\nC F*F0 > 0 and either the new estimate would be outside of\nC the bracketing interval of length abs(DMAX) or F < 0\nC on the first iteration. Reset (SG0,F0) to (SNEG,FNEG).\nC\n 4 DSIG = DMAX\n F0 = FNEG\nC\nC Compute the change in SIG by linear interpolation be-\nC tween (SG0,F0) and (SIG,F).\nC\n 5 DSIG = -F*DSIG/(F-F0)\n IF (LUN .GE. 0) WRITE (LUN,130) DSIG\n 130 FORMAT (1X,8X,'DSIG = ',D15.8)\n IF ( ABS(DSIG) .GT. ABS(DMAX) .OR.\n . DSIG*DMAX .GT. 0. ) GO TO 4\nC\nC Restrict the step-size such that abs(DSIG) .GE. STOL/2.\nC Note that DSIG and DMAX have opposite signs.\nC\n IF (ABS(DSIG) .LT. STOL/2.D0)\n . DSIG = -SIGN(STOL/2.D0,DMAX)\nC\nC Bottom of loop: update SIG, DMAX, and F0.\nC\n SIG = SIG + DSIG\n DMAX = DMAX + DSIG\n F0 = F\n GO TO 2\nC\nC No errors encountered and SIGMA finite.\nC\n 6 IER = 0\n SIG0 = SIG\n RETURN\nC\nC Infinite tension required.\nC\n 7 IER = 1\n SIG0 = SBIG\n RETURN\nC\nC Error in an input parameter.\nC\n 8 IER = -1\n SIG0 = -1.D0\n RETURN\nC\nC Invalid constraint.\nC\n 9 IER = -2\n SIG0 = -1.D0\n RETURN\n END\n DOUBLE PRECISION FUNCTION SIG1 (X1,X2,Y1,Y2,Y1P,Y2P,\n . IFL,HPBND,TOL, IER)\n INTEGER IFL, IER\n DOUBLE PRECISION X1, X2, Y1, Y2, Y1P, Y2P, HPBND, TOL\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 11/17/96\nC\nC Given a pair of abscissae with associated ordinates and\nC slopes, this function determines the smallest (nonnega-\nC tive) tension factor SIGMA such that the derivative HP(x)\nC of the Hermite interpolatory tension spline H(x), defined\nC by SIGMA and the data, is bounded (either above or below)\nC by HPBND for all x in (X1,X2).\nC\nC On input:\nC\nC X1,X2 = Abscissae. X1 < X2.\nC\nC Y1,Y2 = Values of H at X1 and X2.\nC\nC Y1P,Y2P = Values of HP at X1 and X2.\nC\nC IFL = Option indicator:\nC IFL = -1 if HPBND is a lower bound on HP.\nC IFL = 1 if HPBND is an upper bound on HP.\nC\nC HPBND = Bound on HP. If IFL = -1, HPBND .LE.\nC min(Y1P,Y2P,S) for S = (Y2-Y1)/(X2-X1). If\nC IFL = 1, HPBND .GE. max(Y1P,Y2P,S).\nC\nC TOL = Tolerance whose magnitude determines how close\nC SIGMA is to its optimal value when nonzero\nC finite tension is necessary and sufficient to\nC satisfy the constraint. For a lower bound,\nC SIGMA is chosen so that HPBND .LE. HPMIN .LE.\nC HPBND + abs(TOL), where HPMIN is the minimum\nC value of HP in the interval, and for an upper\nC bound, the maximum of HP satisfies HPBND -\nC abs(TOL) .LE. HPMAX .LE. HPBND. Thus, the\nC constraint is satisfied but possibly with more\nC tension than necessary.\nC\nC Input parameters are not altered by this function.\nC\nC On output:\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered and the\nC constraint can be satisfied with fin-\nC ite tension.\nC IER = 1 if no errors were encountered but in-\nC finite tension is required to satisfy\nC the constraint (e.g., IFL = -1, HPBND\nC = S, and Y1P > S).\nC IER = -1 if X2 .LE. X1 or abs(IFL) .NE. 1.\nC IER = -2 if HPBND is outside its valid range\nC on input.\nC\nC SIG1 = Minimum tension factor defined above unless\nC IER < 0, in which case SIG1 = -1. If IER =\nC 1, SIG1 = 85, resulting in an approximation\nC to the linear interpolant of the endpoint\nC values. Note, however, that SIG1 may be\nC larger than 85 if IER = 0.\nC\nC Modules required by SIG1: SNHCSH, STORE\nC\nC Intrinsic functions called by SIG1: ABS, DBLE, EXP, MAX,\nC MIN, SIGN, SQRT\nC\nC***********************************************************\nC\n INTEGER LUN, NIT\n DOUBLE PRECISION A, A0, B0, BND, C0, C1, C2, COSHM,\n . COSHMM, D0, D1, D1PD2, D2, DMAX,\n . DSIG, DX, E, EMS, EMS2, F, F0, FMAX,\n . FNEG, FTOL, RF, RTOL, S, S1, S2,\n . SBIG, SIG, SINH, SINHM, STOL, T0, T1,\n . T2, TM\n DOUBLE PRECISION STORE\nC\n DATA SBIG/85.D0/, LUN/-1/\nC\nC Store local parameters and test for errors.\nC\n RF = DBLE(IFL)\n DX = X2 - X1\n IF (ABS(RF) .NE. 1.D0 .OR. DX .LE. 0.D0) GO TO 7\n S1 = Y1P\n S2 = Y2P\n S = (Y2-Y1)/DX\n BND = HPBND\nC\nC Test for a valid constraint.\nC\n IF ((RF .LT. 0.D0 .AND. MIN(S1,S2,S) .LT. BND)\n . .OR. (RF .GT. 0.D0 .AND.\n . BND .LT. MAX(S1,S2,S))) GO TO 8\nC\nC Test for infinite tension required.\nC\n IF (S .EQ. BND .AND. (S1 .NE. S .OR. S2 .NE. S))\n . GO TO 6\nC\nC Test for SIG = 0 sufficient. The Hermite cubic interpo-\nC land H0 has derivative HP0(x) = S2 + 2*B0*R + A0*R**2,\nC where R = (X2-x)/DX.\nC\n SIG = 0.D0\n T0 = 3.D0*S - S1 - S2\n B0 = T0 - S2\n C0 = T0 - S1\n A0 = -B0 - C0\nC\nC HP0(R) has an extremum (at R = -B0/A0) in (0,1) iff\nC B0*C0 > 0 and the third derivative of H0 has the\nC sign of A0.\nC\n IF (B0*C0 .LE. 0.D0 .OR. A0*RF .GT. 0.D0) GO TO 5\nC\nC A0*RF < 0 and HP0(R) = -D0/A0 at R = -B0/A0.\nC\n D0 = T0*T0 - S1*S2\n F0 = (BND + D0/A0)*RF\n IF (F0 .GE. 0.D0) GO TO 5\nC\nC Find a zero of F(SIG) = (BND-HP(R))*RF, where HP has an\nC extremum at R. F has a unique zero, F(0) = F0 < 0, and\nC F = (BND-S)*RF > 0 for SIG sufficiently large.\nC\nC Initialize parameters for the secant method. The method\nC uses three points: (SG0,F0), (SIG,F), and (SNEG,FNEG),\nC where SG0 and SNEG are defined implicitly by DSIG = SIG\nC - SG0 and DMAX = SIG - SNEG. SG0 is initially zero and\nC SIG is initialized to the zero of (BND - (SIG*S-S1-S2)/\nC (SIG-2.))*RF -- a value for which F(SIG) .GE. 0 and\nC F(SIG) = 0 for SIG sufficiently large that 2*SIG is in-\nC significant relative to EXP(SIG).\nC\n FMAX = (BND-S)*RF\n IF (LUN .GE. 0 .AND. RF .LT. 0.D0)\n . WRITE (LUN,100) F0, FMAX\n IF (LUN .GE. 0 .AND. RF .GT. 0.D0)\n . WRITE (LUN,110) F0, FMAX\n 100 FORMAT (//1X,'SIG1 (LOWER BOUND) -- F(0) = ',D15.8,\n . ', FMAX = ',D15.8/)\n 110 FORMAT (//1X,'SIG1 (UPPER BOUND) -- F(0) = ',D15.8,\n . ', FMAX = ',D15.8/)\n SIG = 2.D0 - A0/(3.D0*(BND-S))\n IF (STORE(SIG*EXP(-SIG)+.5D0) .EQ. .5D0) GO TO 5\n DSIG = SIG\n DMAX = -2.D0*SIG\n FNEG = FMAX\n D1 = S - S1\n D2 = S2 - S\n D1PD2 = D1 + D2\n NIT = 0\nC\nC Compute an absolute tolerance FTOL = abs(TOL), and a\nC relative tolerance RTOL = 100*MACHEPS.\nC\n FTOL = ABS(TOL)\n RTOL = 1.D0\n 1 RTOL = RTOL/2.D0\n IF (STORE(RTOL+1.D0) .GT. 1.D0) GO TO 1\n RTOL = RTOL*200.D0\nC\nC Top of loop: compute F.\nC\n 2 IF (SIG .LE. .5D0) THEN\nC\nC Use approximations designed to avoid cancellation error\nC (associated with small SIG) in the modified hyperbolic\nC functions.\nC\n CALL SNHCSH (SIG, SINHM,COSHM,COSHMM)\n C1 = SIG*COSHM*D2 - SINHM*D1PD2\n C2 = SIG*(SINHM+SIG)*D2 - COSHM*D1PD2\n A = C2 - C1\n E = SIG*SINHM - COSHMM - COSHMM\n ELSE\nC\nC Scale SINHM and COSHM by 2*EXP(-SIG) in order to avoid\nC overflow.\nC\n EMS = EXP(-SIG)\n EMS2 = EMS + EMS\n TM = 1.D0 - EMS\n SINH = TM*(1.D0+EMS)\n SINHM = SINH - SIG*EMS2\n COSHM = TM*TM\n C1 = SIG*COSHM*D2 - SINHM*D1PD2\n C2 = SIG*SINH*D2 - COSHM*D1PD2\n A = EMS2*(SIG*TM*D2 + (TM-SIG)*D1PD2)\n E = SIG*SINH - COSHM - COSHM\n ENDIF\nC\nC The second derivative of H(R) has a zero at EXP(SIG*R) =\nC SQRT((C2+C1)/A) and R is in (0,1) and well-defined\nC iff HPP(X1)*HPP(X2) < 0.\nC\n F = FMAX\n T1 = A*(C2+C1)\n IF (T1 .GE. 0.D0) THEN\n IF (C1*(SIG*COSHM*D1 - SINHM*D1PD2) .LT. 0.D0) THEN\nC\nC HP(R) = (B+SIGN(A)*SQRT(A*C))/E at the critical value\nC of R, where A = C2-C1, B = E*S2-C2, and C = C2+C1.\nC NOTE THAT RF*A < 0.\nC\n F = (BND - (E*S2-C2 - RF*SQRT(T1))/E)*RF\n ENDIF\n ENDIF\nC\nC Update the number of iterations NIT.\nC\n NIT = NIT + 1\n IF (LUN .GE. 0) WRITE (LUN,120) NIT, SIG, F\n 120 FORMAT (1X,3X,I2,' -- SIG = ',D15.8,', F = ',\n . D15.8)\n IF (F0*F .LT. 0.D0) THEN\nC\nC F0*F < 0. Update (SNEG,FNEG) to (SG0,F0) so that F\nC and FNEG always have opposite signs. If SIG is closer\nC to SNEG than SG0 and abs(F) < abs(FNEG), then swap\nC (SNEG,FNEG) with (SG0,F0).\nC\n T1 = DMAX\n T2 = FNEG\n DMAX = DSIG\n FNEG = F0\n IF ( ABS(DSIG) .GT. ABS(T1) .AND.\n . ABS(F) .LT. ABS(T2) ) THEN\nC\n DSIG = T1\n F0 = T2\n ENDIF\n ENDIF\nC\nC Test for convergence.\nC\n STOL = RTOL*SIG\n IF (ABS(DMAX) .LE. STOL .OR. (F .GE. 0.D0 .AND.\n . F .LE. FTOL) .OR. ABS(F) .LE. RTOL) GO TO 5\n IF (F0*F .LT. 0 .OR. ABS(F) .LT. ABS(F0)) GO TO 4\nC\nC F*F0 > 0 and the new estimate would be outside of the\nC bracketing interval of length abs(DMAX). Reset\nC (SG0,F0) to (SNEG,FNEG).\nC\n 3 DSIG = DMAX\n F0 = FNEG\nC\nC Compute the change in SIG by linear interpolation be-\nC tween (SG0,F0) and (SIG,F).\nC\n 4 DSIG = -F*DSIG/(F-F0)\n IF (LUN .GE. 0) WRITE (LUN,130) DSIG\n 130 FORMAT (1X,8X,'DSIG = ',D15.8)\n IF ( ABS(DSIG) .GT. ABS(DMAX) .OR.\n . DSIG*DMAX .GT. 0. ) GO TO 3\nC\nC Restrict the step-size such that abs(DSIG) .GE. STOL/2.\nC Note that DSIG and DMAX have opposite signs.\nC\n IF (ABS(DSIG) .LT. STOL/2.D0)\n . DSIG = -SIGN(STOL/2.D0,DMAX)\nC\nC Bottom of loop: update SIG, DMAX, and F0.\nC\n SIG = SIG + DSIG\n DMAX = DMAX + DSIG\n F0 = F\n GO TO 2\nC\nC No errors encountered and SIGMA finite.\nC\n 5 IER = 0\n SIG1 = SIG\n RETURN\nC\nC Infinite tension required.\nC\n 6 IER = 1\n SIG1 = SBIG\n RETURN\nC\nC Error in an input parameter.\nC\n 7 IER = -1\n SIG1 = -1.D0\n RETURN\nC\nC Invalid constraint.\nC\n 8 IER = -2\n SIG1 = -1.D0\n RETURN\n END\n DOUBLE PRECISION FUNCTION SIG2 (X1,X2,Y1,Y2,Y1P,Y2P,\n . IFL,TOL, IER)\n INTEGER IFL, IER\n DOUBLE PRECISION X1, X2, Y1, Y2, Y1P, Y2P, TOL\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 07/08/92\nC\nC Given a pair of abscissae with associated ordinates and\nC slopes, this function determines the smallest (nonnega-\nC tive) tension factor SIGMA such that the Hermite interpo-\nC latory tension spline H(x) preserves convexity (or con-\nC cavity) of the data; i.e.,\nC\nC Y1P .LE. S .LE. Y2P implies HPP(x) .GE. 0 or\nC Y1P .GE. S .GE. Y2P implies HPP(x) .LE. 0\nC\nC for all x in the open interval (X1,X2), where S = (Y2-Y1)/\nC (X2-X1) and HPP denotes the second derivative of H. Note,\nC however, that infinite tension is required if Y1P = S or\nC Y2P = S (unless Y1P = Y2P = S).\nC\nC On input:\nC\nC X1,X2 = Abscissae. X1 < X2.\nC\nC Y1,Y2 = Values of H at X1 and X2.\nC\nC Y1P,Y2P = Derivative values of H at X1 and X2.\nC\nC IFL = Option indicator (sign of HPP):\nC IFL = -1 if HPP is to be bounded above by 0.\nC IFL = 1 if HPP is to be bounded below by 0\nC (preserve convexity of the data).\nC\nC TOL = Tolerance whose magnitude determines how close\nC SIGMA is to its optimal value when nonzero\nC finite tension is necessary and sufficient to\nC satisfy convexity or concavity. In the case\nC of convexity, SIGMA is chosen so that 0 .LE.\nC HPPMIN .LE. abs(TOL), where HPPMIN is the min-\nC imum value of HPP in the interval. In the\nC case of concavity, the maximum value of HPP\nC satisfies -abs(TOL) .LE. HPPMAX .LE. 0. Thus,\nC the constraint is satisfied but possibly with\nC more tension than necessary.\nC\nC Input parameters are not altered by this function.\nC\nC On output:\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered and fin-\nC ite tension is sufficient to satisfy\nC the constraint.\nC IER = 1 if no errors were encountered but in-\nC finite tension is required to satisfy\nC the constraint.\nC IER = -1 if X2 .LE. X1 or abs(IFL) .NE. 1.\nC IER = -2 if the constraint cannot be satis-\nC fied: the sign of S-Y1P or Y2P-S\nC does not agree with IFL.\nC\nC SIG2 = Tension factor defined above unless IER < 0,\nC in which case SIG2 = -1. If IER = 1, SIG2\nC is set to 85, resulting in an approximation\nC to the linear interpolant of the endpoint\nC values. Note, however, that SIG2 may be\nC larger than 85 if IER = 0.\nC\nC Modules required by SIG2: SNHCSH, STORE\nC\nC Intrinsic functions called by SIG2: ABS, EXP, MAX, MIN,\nC SQRT\nC\nC***********************************************************\nC\n INTEGER LUN, NIT\n DOUBLE PRECISION COSHM, D1, D2, DSIG, DUMMY, DX, EMS,\n . F, FP, FTOL, RTOL, S, SBIG, SIG,\n . SINHM, SSM, T, T1, TP1\n DOUBLE PRECISION STORE\nC\n DATA SBIG/85.D0/, LUN/-1/\nC\nC Test for an errors in the input parameters.\nC\n DX = X2 - X1\n IF (ABS(IFL) .NE. 1.D0 .OR. DX .LE. 0.D0) GO TO 5\nC\nC Compute the slope and second differences, and test for\nC an invalid constraint.\nC\n S = (Y2-Y1)/DX\n D1 = S - Y1P\n D2 = Y2P - S\n IF ((IFL .GT. 0.D0 .AND. MIN(D1,D2) .LT. 0.D0)\n . .OR. (IFL .LT. 0.D0 .AND.\n . MAX(D1,D2) .GT. 0.D0)) GO TO 6\nC\nC Test for infinite tension required.\nC\n IF (D1*D2 .EQ. 0.D0 .AND. D1 .NE. D2) GO TO 4\nC\nC Test for SIG = 0 sufficient.\nC\n SIG = 0.D0\n IF (D1*D2 .EQ. 0.D0) GO TO 3\n T = MAX(D1/D2,D2/D1)\n IF (T .LE. 2.D0) GO TO 3\nC\nC Find a zero of F(SIG) = SIG*COSHM(SIG)/SINHM(SIG) - (T+1).\nC Since the derivative of F vanishes at the origin, a\nC quadratic approximation is used to obtain an initial\nC estimate for the Newton method.\nC\n TP1 = T + 1.D0\n SIG = SQRT(10.D0*T-20.D0)\n NIT = 0\nC\nC Compute an absolute tolerance FTOL = abs(TOL) and a\nC relative tolerance RTOL = 100*MACHEPS.\nC\n FTOL = ABS(TOL)\n RTOL = 1.D0\n 1 RTOL = RTOL/2.D0\n IF (STORE(RTOL+1.D0) .GT. 1.D0) GO TO 1\n RTOL = RTOL*200.D0\nC\nC Evaluate F and its derivative FP.\nC\n 2 IF (SIG .LE. .5D0) THEN\nC\nC Use approximations designed to avoid cancellation error\nC in the hyperbolic functions.\nC\n CALL SNHCSH (SIG, SINHM,COSHM,DUMMY)\n T1 = COSHM/SINHM\n FP = T1 + SIG*(SIG/SINHM - T1*T1 + 1.D0)\n ELSE\nC\nC Scale SINHM and COSHM by 2*exp(-SIG) in order to avoid\nC overflow.\nC\n EMS = EXP(-SIG)\n SSM = 1.D0 - EMS*(EMS+SIG+SIG)\n T1 = (1.D0-EMS)*(1.D0-EMS)/SSM\n FP = T1 + SIG*(2.D0*SIG*EMS/SSM - T1*T1 + 1.D0)\n ENDIF\nC\n F = SIG*T1 - TP1\n IF (LUN .GE. 0) WRITE (LUN,100) SIG, F, FP\n 100 FORMAT (1X,'SIG2 -- SIG = ',D15.8,', F(SIG) = ',\n . D15.8/1X,29X,'FP(SIG) = ',D15.8)\n NIT = NIT + 1\nC\nC Test for convergence.\nC\n IF (FP .LE. 0.D0) GO TO 3\n DSIG = -F/FP\n IF (ABS(DSIG) .LE. RTOL*SIG .OR. (F .GE. 0.D0 .AND.\n . F .LE. FTOL) .OR. ABS(F) .LE. RTOL) GO TO 3\nC\nC Update SIG.\nC\n SIG = SIG + DSIG\n GO TO 2\nC\nC No errors encountered, and SIGMA is finite.\nC\n 3 IER = 0\n SIG2 = SIG\n RETURN\nC\nC Infinite tension required.\nC\n 4 IER = 1\n SIG2 = SBIG\n RETURN\nC\nC X2 .LE. X1 or abs(IFL) .NE. 1.\nC\n 5 IER = -1\n SIG2 = -1.D0\n RETURN\nC\nC The constraint cannot be satisfied.\nC\n 6 IER = -2\n SIG2 = -1.D0\n RETURN\n END\n SUBROUTINE SIGBI (N,X,Y,YP,TOL,B,BMAX, SIGMA, ICFLG,\n . DSMAX,IER)\n INTEGER N, ICFLG(N), IER\n DOUBLE PRECISION X(N), Y(N), YP(N), TOL, B(5,N), BMAX,\n . SIGMA(N), DSMAX\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 06/10/92\nC\nC Given a set of abscissae X with associated data values Y\nC and derivatives YP, this subroutine determines the small-\nC est (nonnegative) tension factors SIGMA such that the Her-\nC mite interpolatory tension spline H(x) satisfies a set of\nC user-specified constraints.\nC\nC SIGBI may be used in conjunction with Subroutine YPC2\nC (or YPC2P) in order to produce a C-2 interpolant which\nC satisfies the constraints. This is achieved by calling\nC YPC2 with SIGMA initialized to the zero vector, and then\nC alternating calls to SIGBI with calls to YPC2 until the\nC change in SIGMA is small (refer to the parameter descrip-\nC tions for SIGMA, DSMAX and IER), or the maximum relative\nC change in YP is bounded by a tolerance (a reasonable value\nC is .01). A similar procedure may be used to produce a C-2\nC shape-preserving smoothing curve (Subroutine SMCRV).\nC\nC Refer to Subroutine SIGS for a means of selecting mini-\nC mum tension factors to preserve shape properties of the\nC data.\nC\nC On input:\nC\nC N = Number of data points. N .GE. 2.\nC\nC X = Array of length N containing a strictly in-\nC creasing sequence of abscissae: X(I) < X(I+1)\nC for I = 1,...,N-1.\nC\nC Y = Array of length N containing data values (or\nC function values computed by SMCRV) associated\nC with the abscissae. H(X(I)) = Y(I) for I =\nC 1,...,N.\nC\nC YP = Array of length N containing first derivatives\nC of H at the abscissae. Refer to Subroutines\nC YPC1, YPC1P, YPC2, YPC2P, and SMCRV.\nC\nC TOL = Tolerance whose magnitude determines how close\nC each tension factor is to its optimal value\nC when nonzero finite tension is necessary and\nC sufficient to satisfy a constraint. Refer to\nC functions SIG0, SIG1, and SIG2. TOL should be\nC set to 0 for optimal tension.\nC\nC B = Array dimensioned 5 by N-1 containing bounds or\nC flags which define the constraints. For I = 1\nC to N-1, column I defines the constraints associ-\nC ated with interval I (X(I),X(I+1)) as follows:\nC\nC B(1,I) is an upper bound on H\nC B(2,I) is a lower bound on H\nC B(3,I) is an upper bound on HP\nC B(4,I) is a lower bound on HP\nC B(5,I) specifies the required sign of HPP\nC\nC where HP and HPP denote the first and second\nC derivatives of H, respectively. A null con-\nC straint is specified by abs(B(K,I)) .GE. BMAX\nC for K < 5, or B(5,I) = 0: B(1,I) .GE. BMAX,\nC B(2,I) .LE. -BMAX, B(3,I) .GE. BMAX, B(4,I) .LE.\nC -BMAX, or B(5,I) = 0. Any positive value of\nC B(5,I) specifies that H should be convex, a\nC negative values specifies that H should be con-\nC cave, and 0 specifies that no restriction be\nC placed on HPP. Refer to Functions SIG0, SIG1,\nC and SIG2 for definitions of valid constraints.\nC\nC BMAX = User-defined value of infinity which, when\nC used as an upper bound in B (or when its\nC negative is used as a lower bound), specifies\nC that no constraint is to be enforced.\nC\nC The above parameters are not altered by this routine.\nC\nC SIGMA = Array of length N-1 containing minimum val-\nC ues of the tension factors. SIGMA(I) is as-\nC sociated with interval (I,I+1) and SIGMA(I)\nC .GE. 0 for I = 1,...,N-1. SIGMA should be\nC set to the zero vector if minimal tension\nC is desired, and should be unchanged from a\nC previous call in order to ensure convergence\nC of the C-2 iterative procedure.\nC\nC ICFLG = Array of length .GE. N-1.\nC\nC On output:\nC\nC SIGMA = Array containing tension factors for which\nC H(x) satisfies the constraints defined by B,\nC with the restriction that SIGMA(I) .LE. 85\nC for all I (unless the input value is larger).\nC The factors are as small as possible (within\nC the tolerance), but not less than their\nC input values. If infinite tension is re-\nC quired in interval (X(I),X(I+1)), then\nC SIGMA(I) = 85 (and H is an approximation to\nC the linear interpolant on the interval),\nC and if no constraint is specified in the\nC interval, then SIGMA(I) = 0 (unless the\nC input value is positive), and thus H is\nC cubic. Invalid constraints are treated as\nC null constraints.\nC\nC ICFLG = Array of invalid constraint flags associated\nC with intervals. For I = 1 to N-1, ICFLG(I)\nC is a 5-bit value b5b4b3b2b1, where bK = 1 if\nC and only if constraint K cannot be satis-\nC fied. Thus, all constraints in interval I\nC are satisfied if and only if ICFLG(I) = 0\nC (and IER .GE. 0).\nC\nC DSMAX = Maximum increase in a component of SIGMA\nC from its input value. The increase is a\nC relative change if the input value is\nC positive, and an absolute change otherwise.\nC\nC IER = Error indicator and information flag:\nC IER = I if no errors (other than invalid con-\nC straints) were encountered and I\nC components of SIGMA were altered from\nC their input values for 0 .LE. I .LE.\nC N-1.\nC IER = -1 if N < 2. SIGMA and ICFLG are not\nC altered in this case.\nC IER = -I if X(I) .LE. X(I-1) for some I in the\nC range 2,...,N. SIGMA(J) and ICFLG(J)\nC are unaltered for J .GE. I-1 in this\nC case.\nC\nC Modules required by SIGBI: SIG0, SIG1, SIG2, SNHCSH,\nC STORE\nC\nC Intrinsic functions called by SIGBI: ABS, MAX, MIN\nC\nC***********************************************************\nC\n INTEGER I, ICFK, ICNT, IERR, IFL, K, NM1\n DOUBLE PRECISION BMX, BND, DSIG, DSM, S, SBIG, SIG,\n . SIGIN\n DOUBLE PRECISION SIG0, SIG1, SIG2\nC\n DATA SBIG/85.D0/\n NM1 = N - 1\n IF (NM1 .LT. 1) GO TO 4\n BMX = BMAX\nC\nC Initialize change counter ICNT and maximum change DSM for\nC loop on intervals.\nC\n ICNT = 0\n DSM = 0.D0\n DO 3 I = 1,NM1\n IF (X(I) .GE. X(I+1)) GO TO 5\n ICFLG(I) = 0\nC\nC Loop on constraints for interval I. SIG is set to the\nC largest tension factor required to satisfy all five\nC constraints. ICFK = 2**(K-1) is the increment for\nC ICFLG(I) when constraint K is invalid.\nC\n SIG = 0.D0\n ICFK = 1\n DO 2 K = 1,5\n BND = B(K,I)\n IF (K .LT. 5 .AND. ABS(BND) .GE. BMX) GO TO 1\n IF (K .LE. 2) THEN\n IFL = 3 - 2*K\n S = SIG0 (X(I),X(I+1),Y(I),Y(I+1),YP(I),YP(I+1),\n . IFL,BND,TOL, IERR)\n ELSEIF (K .LE. 4) THEN\n IFL = 7 - 2*K\n S = SIG1 (X(I),X(I+1),Y(I),Y(I+1),YP(I),YP(I+1),\n . IFL,BND,TOL, IERR)\n ELSE\n IF (BND .EQ. 0.D0) GO TO 1\n IFL = -1\n IF (BND .GT. 0.D0) IFL = 1\n S = SIG2 (X(I),X(I+1),Y(I),Y(I+1),YP(I),YP(I+1),\n . IFL,TOL, IERR)\n ENDIF\n IF (IERR .EQ. -2) THEN\nC\nC An invalid constraint was encountered. Increment\nC ICFLG(I).\nC\n ICFLG(I) = ICFLG(I) + ICFK\n ELSE\nC\nC Update SIG.\nC\n SIG = MAX(SIG,S)\n ENDIF\nC\nC Bottom of loop on constraints K: update ICFK.\nC\n 1 ICFK = 2*ICFK\n 2 CONTINUE\nC\nC Bottom of loop on intervals: update SIGMA(I), ICNT, and\nC DSM if necessary.\nC\n SIG = MIN(SIG,SBIG)\n SIGIN = SIGMA(I)\n IF (SIG .GT. SIGIN) THEN\n SIGMA(I) = SIG\n ICNT = ICNT + 1\n DSIG = SIG-SIGIN\n IF (SIGIN .GT. 0.D0) DSIG = DSIG/SIGIN\n DSM = MAX(DSM,DSIG)\n ENDIF\n 3 CONTINUE\nC\nC No errors (other than invalid constraints) encountered.\nC\n DSMAX = DSM\n IER = ICNT\n RETURN\nC\nC N < 2.\nC\n 4 DSMAX = 0.D0\n IER = -1\n RETURN\nC\nC X(I) .GE. X(I+1).\nC\n 5 DSMAX = DSM\n IER = -(I+1)\n RETURN\n END\n SUBROUTINE SIGBP (N,X,Y,XP,YP,TOL,BL,BU,\n . BMAX, SIGMA, DSMAX,IER)\n INTEGER N, IER\n DOUBLE PRECISION X(N), Y(N), XP(N), YP(N), TOL, BL(N),\n . BU(N), BMAX, SIGMA(N), DSMAX\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 11/18/96\nC\nC Given an ordered sequence of points C(I) = (X(I),Y(I))\nC with associated derivative vectors CP(I) = (XP(I),YP(I)),\nC this subroutine determines the smallest (nonnegative) ten-\nC sion factors SIGMA such that a parametric planar curve\nC C(t) satisfies a set of user-specified constraints. The\nC components x(t) and y(t) of C(t) are the Hermite interpo-\nC latory tension splines defined by the data and tension\nC factors: C(t(I)) = C(I) and C'(t(I)) = CP(I) for para-\nC meter values t(1), t(2), ..., t(N). In each subinterval\nC [t1,t2], the signed perpendicular distance from the\nC corresponding line segment C1-C2 to the curve C(t) is\nC given by the vector cross product\nC\nC d(t) = (C2-C1)/DC X (C(t)-C1)\nC\nC where DC = abs(C2-C1) is the length of the line segment.\nC The associated tension factor SIGMA is chosen to satisfy\nC an upper bound on the maximum of d(t) and a lower bound on\nC the minimum of d(t) over t in [t1,t2]. Thus, the upper\nC bound is associated with distance to the left of the line\nC segment as viewed from C1 toward C2. Note that the curve\nC is assumed to be parameterized by arc length (Subroutine\nC ARCL2D) so that t2-t1 = DC. If this is not the case, the\nC required bounds should be scaled by DC/(t2-t1) to obtain\nC the input parameters BL and BU.\nC\nC SIGBP may be used in conjunction with Subroutine YPC2\nC (or YPC2P) in order to produce a C-2 interpolant which\nC satisfies the constraints. This is achieved by calling\nC YPC2 with SIGMA initialized to the zero vector, and then\nC alternating calls to SIGBP with calls to YPC2 until the\nC change in SIGMA is small (refer to the parameter descrip-\nC tions for SIGMA, DSMAX and IER), or the maximum relative\nC change in YP is bounded by a tolerance (a reasonable value\nC is .01). A similar procedure may be used to produce a C-2\nC shape-preserving smoothing curve (Subroutine SMCRV).\nC\nC On input:\nC\nC N = Number of data points. N .GE. 2.\nC\nC X,Y = Arrays of length N containing the Cartesian\nC coordinates of the points C(I), I = 1 to N.\nC\nC XP,YP = Arrays of length N containing the components\nC of the derivative (velocity) vectors CP(I).\nC Refer to Subroutines YPC1, YPC1P, YPC2,\nC YPC2P, and SMCRV.\nC\nC TOL = Tolerance whose magnitude determines how close\nC each tension factor SIGMA is to its optimal\nC value when nonzero finite tension is necessary\nC and sufficient to satisfy a constraint.\nC SIGMA(I) is chosen so that BL(I) .LE. dmin\nC .LE. BL(I) + abs(TOL) and BU(I) - abs(TOL)\nC .LE. dmax .LE. BU(I), where dmin and dmax are\nC the minimum and maximum values of d(t) in the\nC interval [t(I),t(I+1)]. Thus, a large toler-\nC ance might increase execution efficiency but\nC may result in more tension than is necessary.\nC TOL may be set to 0 for optimal tension.\nC\nC BL,BU = Arrays of length N-1 containing lower and\nC upper bounds, respectively, which define\nC the constraints as described above. BL(I)\nC < 0 and BU(I) > 0 for I = 1 to N-1. A null\nC straint is specified by BL(I) .LE. -BMAX or\nC BU(I) .GE. BMAX.\nC\nC BMAX = User-defined value of infinity which, when\nC used as an upper bound in BU (or when its\nC negative is used as a lower bound in BL),\nC specifies that no constraint is to be en-\nC forced.\nC\nC The above parameters are not altered by this routine.\nC\nC SIGMA = Array of length N-1 containing minimum val-\nC ues of the tension factors. SIGMA(I) is as-\nC sociated with interval (I,I+1) and SIGMA(I)\nC .GE. 0 for I = 1,...,N-1. SIGMA should be\nC set to the zero vector if minimal tension\nC is desired, and should be unchanged from a\nC previous call in order to ensure convergence\nC of the C-2 iterative procedure.\nC\nC On output:\nC\nC SIGMA = Array containing tension factors for which\nC d(t) satisfies the constraints defined by\nC BL and BU, with the restriction that\nC SIGMA(I) .LE. 85 for all I (unless the input\nC value is larger). The factors are as small\nC as possible (within the tolerance), but not\nC less than their input values. If no con-\nC straint is specified in interval I, then\nC SIGMA(I) = 0 (unless the input value is\nC positive), and thus x(t) and y(t) are cubic\nC polynomials.\nC\nC DSMAX = Maximum increase in a component of SIGMA\nC from its input value. The increase is a\nC relative change if the input value is\nC positive, and an absolute change otherwise.\nC\nC IER = Error indicator and information flag:\nC IER = I if no errors were encountered and I\nC components of SIGMA were altered from\nC their input values for 0 .LE. I .LE.\nC N-1.\nC IER = -1 if N < 2. SIGMA is not altered in\nC this case.\nC IER = -I if BL(I-1) .GE. 0 or BU(I-1) .LE. 0\nC for some I in the range 2 to N.\nC SIGMA(J) is unaltered for J .GE. I-1\nC in this case.\nC\nC Modules required by SIGBP: SNHCSH, STORE\nC\nC Intrinsic functions called by SIGBP: ABS, EXP, LOG, MAX,\nC MIN, SIGN, SQRT\nC\nC***********************************************************\nC\n INTEGER I, ICNT, IP1, LUN, NIT, NM1\n DOUBLE PRECISION A, A1, A2, AA, B, B0, BHI, BLO, BMX,\n . C, COSHM, COSHMM, D, D0, DM, DMAX,\n . DP, DSIG, DSM, DX, DY, E, EB, EMS, F,\n . F0, FMAX, FNEG, FTOL, RM, RP, RSM,\n . RSP, RTOL, S, SBIG, SIG, SIGIN, SINH,\n . SINHM, SNEG, STOL, T, T1, T2, TM, V1,\n . V2, V2M1\n DOUBLE PRECISION STORE\nC\n DATA SBIG/85.D0/, LUN/-1/\n NM1 = N - 1\n IF (NM1 .LT. 1) GO TO 8\n BMX = BMAX\nC\nC Compute an absolute tolerance FTOL = abs(TOL), and a\nC relative tolerance RTOL = 100*MACHEPS.\nC\n FTOL = ABS(TOL)\n RTOL = 1.D0\n 1 RTOL = RTOL/2.D0\n IF (STORE(RTOL+1.D0) .GT. 1.D0) GO TO 1\n RTOL = RTOL*200.D0\nC\nC Initialize change counter ICNT and maximum change DSM for\nC loop on intervals.\nC\n ICNT = 0\n DSM = 0.D0\n DO 7 I = 1,NM1\n IP1 = I + 1\n BLO = BL(I)\n BHI = BU(I)\n SIGIN = SIGMA(I)\n IF (LUN .GE. 0) WRITE (LUN,100) I, BLO, BHI, SIGIN\n 100 FORMAT (//1X,'SIGBP -- INTERVAL',I4,', BL = ',D10.3,\n . ', BU = ',D10.3,', SIGIN = ',D15.8)\n IF (BLO .GE. 0.D0 .OR. BHI .LE. 0.D0) GO TO 9\n IF (SIGIN .GE. SBIG) GO TO 7\nC\nC Initialize SIG to 0 and test for a null constraint.\nC\n SIG = 0.D0\n IF (BLO .LE. -BMX .AND. BHI .GE. BMX) GO TO 6\nC\nC Test for SIG = 0 sufficient.\nC\nC The signed orthogonal distance is d(b) = b*(1-b)*\nC (b*V1 - (1-b)*V2), where b = (t2-t)/(t2-t1),\nC V1 = (C2-C1) X CP(1), and V2 = (C2-C1) X CP(2).\nC\n DX = X(IP1) - X(I)\n DY = Y(IP1) - Y(I)\n V1 = DX*YP(I) - DY*XP(I)\n V2 = DX*YP(IP1) - DY*XP(IP1)\nC\nC Set DP and DM to the maximum and minimum values of d(b)\nC for b in [0,1]. Note that DP .GE. 0 and DM .LE. 0.\nC\n S = V1 + V2\n IF (S .EQ. 0.D0) THEN\nC\nC The derivative d'(b) is zero at the midpoint b = .5.\nC\n IF (V1 .GE. 0.D0) THEN\n DP = V1/4.D0\n DM = 0.D0\n ELSE\n DP = 0.D0\n DM = V1/4.D0\n ENDIF\n ELSE\nC\nC Set RP/RM to the roots of the quadratic equation d'(b) =\nC (B0 +/- SQRT(D0))/(3*S) = V2/(B0 -/+ SQRT(D0)) = 0,\nC where B0 = V1 + 2*V2 and D0 = V1**2 + V1*V2 + V2**2.\nC The expression is chosen to avoid cancellation error.\nC\n B0 = S + V2\n D0 = S*S - V1*V2\n T = B0 + SIGN(SQRT(D0),B0)\n IF (B0 .GE. 0.D0) THEN\n RP = T/(3.D0*S)\n RM = V2/T\n ELSE\n RP = V2/T\n RM = T/(3.D0*S)\n ENDIF\n IF (V1 .LE. 0.D0 .AND. V2 .GE. 0.D0) THEN\nC\nC The maximum is DP = 0 at the endpoints.\nC\n DP = 0.D0\n ELSE\n DP = RP*(1.D0-RP)*(RP*S - V2)\n ENDIF\n IF (V1 .GE. 0.D0 .AND. V2 .LE. 0.D0) THEN\nC\nC The minimum is DM = 0 at the endpoints.\nC\n DM = 0.D0\n ELSE\n DM = RM*(1.D0-RM)*(RM*S - V2)\n ENDIF\n ENDIF\nC\nC SIG = 0 is sufficient to satisfy the constraints iff\nC DP .LE. BHI and DM .GE. BLO iff F0 .GE. 0.\nC\n F0 = MIN(BHI-DP,DM-BLO)\n IF (F0 .GE. 0.D0) GO TO 6\nC\nC Find a zero of F(SIG) = min(BHI-DP,DM-BLO), where DP and\nC DM are the maximum and minimum values of d(b). F is an\nC increasing function, F(0) = F0 < 0, and F = FMAX =\nC min(BHI,-BLO) for SIG sufficiently large. Note that F\nC has a discontinuity in its first derivative if the\nC curves BHI-DP and DM-BLO (as functions of SIG) inter-\nC sect, and the rate of convergence of the zero finder is\nC reduced to linear if such an intersection occurs near\nC the zero of F.\nC\nC Initialize parameters for the secant method. The method\nC uses three points: (SG0,F0), (SIG,F), and (SNEG,FNEG),\nC where SG0 and SNEG are defined implicitly by DSIG = SIG\nC - SG0 and DMAX = SIG - SNEG. SG0 is initially zero and\nC SNEG is initialized to a sufficiently large value that\nC FNEG > 0. This value is used only if the initial value\nC of F is negative.\nC\n T = MIN(BHI,-BLO)\n FMAX = MAX(1.D-3,T)\n SIG = MAX(ABS(V1),ABS(V2))/T\n DMAX = SIG*(1.D0-T/FMAX)\n SNEG = SIG - DMAX\n IF (LUN .GE. 0) WRITE (LUN,110) F0, FMAX, SNEG\n 110 FORMAT (//1X,'F(0) = ',D15.8,', FMAX = ',D15.8,\n . ', SNEG = ',D15.8/)\n DSIG = SIG\n FNEG = FMAX\n V2M1 = V2 - V1\n NIT = 0\nC\nC Top of loop: compute F.\nC\n 2 EMS = EXP(-SIG)\n IF (SIG .LE. .5D0) THEN\nC\nC SIG .LE. .5: use approximations designed to avoid can-\nC cellation error (associated with small\nC SIG) in the modified hyperbolic functions.\nC\n CALL SNHCSH (SIG, SINHM,COSHM,COSHMM)\n SINH = SINHM + SIG\n A1 = SIG*COSHM*V2 - SINHM*V2M1\n A2 = SIG*SINH*V2 - COSHM*V2M1\n A = A2 - A1\n AA = A/EMS\n E = SIG*SINHM - COSHMM - COSHMM\n ELSE\nC\nC SIG > .5: scale SINHM and COSHM by 2*EXP(-SIG) in order\nC to avoid overflow.\nC\n TM = 1.D0 - EMS\n SINH = TM*(1.D0+EMS)\n SINHM = SINH - 2.D0*SIG*EMS\n COSHM = TM*TM\n A1 = SIG*COSHM*V2 - SINHM*V2M1\n A2 = SIG*SINH*V2 - COSHM*V2M1\n AA = 2.D0*(SIG*TM*V2 + (TM-SIG)*V2M1)\n A = EMS*AA\n E = SIG*SINH - COSHM - COSHM\n ENDIF\n IF (S .EQ. 0.D0) THEN\nC\nC The derivative d'(b) is zero at the midpoint b = .5.\nC\n EB = SIG*COSHM - SINHM - SINHM\n IF (V1 .GE. 0.D0) THEN\n DP = E*V1/(SIG*(SQRT(EB*EB-E*E)+EB))\n DM = 0.D0\n ELSE\n DP = 0.D0\n DM = E*V1/(SIG*(SQRT(EB*EB-E*E)+EB))\n ENDIF\n ELSE\nC\nC d'(b)*DC = V2 - (A1*sinh(SIG*b) - A2*coshm(SIG*b))/E = 0\nC for ESB = (-B +/- sqrt(D))/A = C/(-B -/+ sqrt(D)),\nC where ESB = exp(SIG*b), A = A2-A1, D = B**2 - A*C, and\nC B and C are defined below.\nC\n B = -COSHM*S\n C = A2 + A1\n D = B*B - A*C\n F = FMAX\n IF (D .LT. 0.D0) GO TO 3\n T1 = SQRT(D)\n T = -B - SIGN(T1,B)\nC\n RSP = 0.D0\n IF (B .LT. 0.D0 .AND. AA .NE. 0.D0) THEN\n IF (T/AA .GT. 0.D0) RSP = SIG + LOG(T/AA)\n ENDIF\n IF ((B .GT. 0.D0 .OR. AA .EQ. 0.D0) .AND.\n . C/T .GT. 0.D0) RSP = LOG(C/T)\n IF ((RSP .LE. 0.D0 .OR. RSP .GE. SIG) .AND.\n . B .NE. 0.D0) THEN\nC\nC The maximum is DP = 0 at the endpoints.\nC\n DP = 0.D0\n ELSE\n DP = -(B*RSP+A1+T1)/(SIG*E)\n ENDIF\nC\n RSM = 0.D0\n IF (B .GT. 0.D0 .AND. AA .NE. 0.D0) THEN\n IF (T/AA .GT. 0.D0) RSM = SIG + LOG(T/AA)\n ENDIF\n IF ((B .LT. 0.D0 .OR. AA .EQ. 0.D0) .AND.\n . C/T .GT. 0.D0) RSM = LOG(C/T)\n IF ((RSM .LE. 0.D0 .OR. RSM .GE. SIG) .AND.\n . B .NE. 0.D0) THEN\nC\nC The minimum is DM = 0 at the endpoints.\nC\n DM = 0.D0\n ELSE\n DM = -(B*RSM+A1-T1)/(SIG*E)\n ENDIF\n ENDIF\nC\n F = MIN(BHI-DP,DM-BLO)\nC\nC Update the number of iterations NIT.\nC\n 3 NIT = NIT + 1\n IF (LUN .GE. 0) WRITE (LUN,120) NIT, SIG, F\n 120 FORMAT (1X,3X,I2,' -- SIG = ',D15.8,', F = ',\n . D15.8)\n IF (F0*F .LT. 0.D0) THEN\nC\nC F0*F < 0. Update (SNEG,FNEG) to (SG0,F0) so that F\nC and FNEG always have opposite signs. If SIG is\nC closer to SNEG than SG0, then swap (SNEG,FNEG) with\nC (SG0,F0).\nC\n T1 = DMAX\n T2 = FNEG\n DMAX = DSIG\n FNEG = F0\n IF (ABS(DSIG) .GT. ABS(T1)) THEN\n DSIG = T1\n F0 = T2\n ENDIF\n ENDIF\nC\nC Test for convergence.\nC\n STOL = RTOL*SIG\n IF (ABS(DMAX) .LE. STOL .OR. (F .GE. 0.D0 .AND.\n . F .LE. FTOL) .OR. ABS(F) .LE. RTOL) GO TO 6\nC\nC Test for F0 = F = FMAX or F < 0 on the first iteration.\nC\n IF (F0 .NE. F .AND. (NIT .GT. 1 .OR.\n . F .GT. 0.D0)) GO TO 5\nC\nC F*F0 > 0 and either the new estimate would be outside of\nC the bracketing interval of length abs(DMAX) or F < 0\nC on the first iteration. Reset (SG0,F0) to (SNEG,FNEG).\nC\n 4 DSIG = DMAX\n F0 = FNEG\nC\nC Compute the change in SIG by linear interpolation be-\nC tween (SG0,F0) and (SIG,F).\nC\n 5 DSIG = -F*DSIG/(F-F0)\n IF (LUN .GE. 0) WRITE (LUN,130) DSIG\n 130 FORMAT (1X,8X,'DSIG = ',D15.8)\n IF ( ABS(DSIG) .GT. ABS(DMAX) .OR.\n . DSIG*DMAX .GT. 0. ) GO TO 4\nC\nC Restrict the step-size such that abs(DSIG) .GE. STOL/2.\nC Note that DSIG and DMAX have opposite signs.\nC\n IF (ABS(DSIG) .LT. STOL/2.D0)\n . DSIG = -SIGN(STOL/2.D0,DMAX)\nC\nC Bottom of loop: update SIG, DMAX, and F0.\nC\n SIG = SIG + DSIG\n DMAX = DMAX + DSIG\n F0 = F\n GO TO 2\nC\nC Bottom of loop on intervals: update SIGMA(I), ICNT, and\nC DSM if necessary.\nC\n 6 SIG = MIN(SIG,SBIG)\n IF (SIG .GT. SIGIN) THEN\n SIGMA(I) = SIG\n ICNT = ICNT + 1\n DSIG = SIG-SIGIN\n IF (SIGIN .GT. 0.D0) DSIG = DSIG/SIGIN\n DSM = MAX(DSM,DSIG)\n ENDIF\n 7 CONTINUE\nC\nC No errors encountered.\nC\n DSMAX = DSM\n IER = ICNT\n RETURN\nC\nC N < 2.\nC\n 8 DSMAX = 0.D0\n IER = -1\n RETURN\nC\nC BL(I) .GE. 0 or BU(I) .LE. 0.\nC\n 9 DSMAX = DSM\n IER = -(IP1)\n RETURN\n END\n SUBROUTINE SIGS (N,X,Y,YP,TOL, SIGMA, DSMAX,IER)\n INTEGER N, IER\n DOUBLE PRECISION X(N), Y(N), YP(N), TOL, SIGMA(N),\n . DSMAX\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 11/17/96\nC\nC Given a set of abscissae X with associated data values Y\nC and derivatives YP, this subroutine determines the small-\nC est (nonnegative) tension factors SIGMA such that the Her-\nC mite interpolatory tension spline H(x) preserves local\nC shape properties of the data. In an interval (X1,X2) with\nC data values Y1,Y2 and derivatives YP1,YP2, the properties\nC of the data are\nC\nC Monotonicity: S, YP1, and YP2 are nonnegative or\nC nonpositive,\nC and\nC Convexity: YP1 .LE. S .LE. YP2 or YP1 .GE. S\nC .GE. YP2,\nC\nC where S = (Y2-Y1)/(X2-X1). The corresponding properties\nC of H are constant sign of the first and second deriva-\nC tives, respectively. Note that, unless YP1 = S = YP2, in-\nC finite tension is required (and H is linear on the inter-\nC val) if S = 0 in the case of monotonicity, or if YP1 = S\nC or YP2 = S in the case of convexity.\nC\nC SIGS may be used in conjunction with Subroutine YPC2\nC (or YPC2P) in order to produce a C-2 interpolant which\nC preserves the shape properties of the data. This is\nC achieved by calling YPC2 with SIGMA initialized to the\nC zero vector, and then alternating calls to SIGS with\nC calls to YPC2 until the change in SIGMA is small (refer to\nC the parameter descriptions for SIGMA, DSMAX and IER), or\nC the maximum relative change in YP is bounded by a toler-\nC ance (a reasonable value is .01). A similar procedure may\nC be used to produce a C-2 shape-preserving smoothing curve\nC (Subroutine SMCRV).\nC\nC Refer to Subroutine SIGBI for a means of selecting mini-\nC mum tension factors to satisfy more general constraints.\nC\nC On input:\nC\nC N = Number of data points. N .GE. 2.\nC\nC X = Array of length N containing a strictly in-\nC creasing sequence of abscissae: X(I) < X(I+1)\nC for I = 1,...,N-1.\nC\nC Y = Array of length N containing data values (or\nC function values computed by SMCRV) associated\nC with the abscissae. H(X(I)) = Y(I) for I =\nC 1,...,N.\nC\nC YP = Array of length N containing first derivatives\nC of H at the abscissae. Refer to Subroutines\nC YPC1, YPC1P, YPC2, YPC2P, and SMCRV.\nC\nC TOL = Tolerance whose magnitude determines how close\nC each tension factor is to its optimal value\nC when nonzero finite tension is necessary and\nC sufficient to satisfy the constraint:\nC abs(TOL) is an upper bound on the magnitude\nC of the smallest (nonnegative) or largest (non-\nC positive) value of the first or second deriva-\nC tive of H in the interval. Thus, the con-\nC straint is satisfied, but possibly with more\nC tension than necessary. TOL should be set to\nC 0 for optimal tension.\nC\nC The above parameters are not altered by this routine.\nC\nC SIGMA = Array of length N-1 containing minimum val-\nC ues of the tension factors. SIGMA(I) is as-\nC sociated with interval (I,I+1) and SIGMA(I)\nC .GE. 0 for I = 1,...,N-1. SIGMA should be\nC set to the zero vector if minimal tension\nC is desired, and should be unchanged from a\nC previous call in order to ensure convergence\nC of the C-2 iterative procedure.\nC\nC On output:\nC\nC SIGMA = Array containing tension factors for which\nC H(x) preserves the properties of the data,\nC with the restriction that SIGMA(I) .LE. 85\nC for all I (unless the input value is larger).\nC The factors are as small as possible (within\nC the tolerance), but not less than their\nC input values. If infinite tension is re-\nC quired in interval (X(I),X(I+1)), then\nC SIGMA(I) = 85 (and H is an approximation to\nC the linear interpolant on the interval),\nC and if neither property is satisfied by the\nC data, then SIGMA(I) = 0 (unless the input\nC value is positive), and thus H is cubic in\nC the interval.\nC\nC DSMAX = Maximum increase in a component of SIGMA\nC from its input value. The increase is a\nC relative change if the input value is\nC nonzero, and an absolute change otherwise.\nC\nC IER = Error indicator and information flag:\nC IER = I if no errors were encountered and I\nC components of SIGMA were altered from\nC their input values for 0 .LE. I .LE.\nC N-1.\nC IER = -1 if N < 2. SIGMA is not altered in\nC this case.\nC IER = -I if X(I) .LE. X(I-1) for some I in the\nC range 2,...,N. SIGMA(J-1) is unal-\nC tered for J = I,...,N in this case.\nC\nC Modules required by SIGS: SNHCSH, STORE\nC\nC Intrinsic functions called by SIGS: ABS, EXP, MAX, MIN,\nC SIGN, SQRT\nC\nC***********************************************************\nC\n INTEGER I, ICNT, IP1, LUN, NIT, NM1\n DOUBLE PRECISION A, C1, C2, COSHM, COSHMM, D0, D1,\n . D1D2, D1PD2, D2, DMAX, DSIG, DSM, DX,\n . E, EMS, EMS2, F, F0, FMAX, FNEG, FP,\n . FTOL, RTOL, S, S1, S2, SBIG, SCM,\n . SGN, SIG, SIGIN, SINHM, SSINH, SSM,\n . STOL, T, T0, T1, T2, TM, TP1\n DOUBLE PRECISION STORE\nC\n DATA SBIG/85.D0/, LUN/-1/\n NM1 = N - 1\n IF (NM1 .LT. 1) GO TO 9\nC\nC Compute an absolute tolerance FTOL = abs(TOL) and a\nC relative tolerance RTOL = 100*MACHEPS.\nC\n FTOL = ABS(TOL)\n RTOL = 1.D0\n 1 RTOL = RTOL/2.D0\n IF (STORE(RTOL+1.D0) .GT. 1.D0) GO TO 1\n RTOL = RTOL*200.D0\nC\nC Initialize change counter ICNT and maximum change DSM for\nC loop on intervals.\nC\n ICNT = 0\n DSM = 0.D0\n DO 8 I = 1,NM1\n IF (LUN .GE. 0) WRITE (LUN,100) I\n 100 FORMAT (//1X,'SIGS -- INTERVAL',I4)\n IP1 = I + 1\n DX = X(IP1) - X(I)\n IF (DX .LE. 0.D0) GO TO 10\n SIGIN = SIGMA(I)\n IF (SIGIN .GE. SBIG) GO TO 8\nC\nC Compute first and second differences.\nC\n S1 = YP(I)\n S2 = YP(IP1)\n S = (Y(IP1)-Y(I))/DX\n D1 = S - S1\n D2 = S2 - S\n D1D2 = D1*D2\nC\nC Test for infinite tension required to satisfy either\nC property.\nC\n SIG = SBIG\n IF ((D1D2 .EQ. 0.D0 .AND. S1 .NE. S2) .OR.\n . (S .EQ. 0.D0 .AND. S1*S2 .GT. 0.D0)) GO TO 7\nC\nC Test for SIGMA = 0 sufficient. The data satisfies convex-\nC ity iff D1D2 .GE. 0, and D1D2 = 0 implies S1 = S = S2.\nC\n SIG = 0.D0\n IF (D1D2 .LT. 0.D0) GO TO 3\n IF (D1D2 .EQ. 0.D0) GO TO 7\n T = MAX(D1/D2,D2/D1)\n IF (T .LE. 2.D0) GO TO 7\n TP1 = T + 1.D0\nC\nC Convexity: Find a zero of F(SIG) = SIG*COSHM(SIG)/\nC SINHM(SIG) - TP1.\nC\nC F(0) = 2-T < 0, F(TP1) .GE. 0, the derivative of F\nC vanishes at SIG = 0, and the second derivative of F is\nC .2 at SIG = 0. A quadratic approximation is used to\nC obtain a starting point for the Newton method.\nC\n SIG = SQRT(10.D0*T-20.D0)\n NIT = 0\nC\nC Top of loop:\nC\n 2 IF (SIG .LE. .5D0) THEN\n CALL SNHCSH (SIG, SINHM,COSHM,COSHMM)\n T1 = COSHM/SINHM\n FP = T1 + SIG*(SIG/SINHM - T1*T1 + 1.D0)\n ELSE\nC\nC Scale SINHM and COSHM by 2*EXP(-SIG) in order to avoid\nC overflow with large SIG.\nC\n EMS = EXP(-SIG)\n SSM = 1.D0 - EMS*(EMS+SIG+SIG)\n T1 = (1.D0-EMS)*(1.D0-EMS)/SSM\n FP = T1 + SIG*(2.D0*SIG*EMS/SSM - T1*T1 + 1.D0)\n ENDIF\nC\n F = SIG*T1 - TP1\n IF (LUN .GE. 0) WRITE (LUN,110) SIG, F, FP\n 110 FORMAT (5X,'CONVEXITY -- SIG = ',D15.8,\n . ', F(SIG) = ',D15.8/1X,35X,'FP(SIG) = ',\n . D15.8)\n NIT = NIT + 1\nC\nC Test for convergence.\nC\n IF (FP .LE. 0.D0) GO TO 7\n DSIG = -F/FP\n IF (ABS(DSIG) .LE. RTOL*SIG .OR. (F .GE. 0.D0\n . .AND. F .LE. FTOL) .OR. ABS(F) .LE. RTOL)\n . GO TO 7\n IF (NIT .GT. 500) GO TO 7\nC\nC Update SIG.\nC\n SIG = SIG + DSIG\n GO TO 2\nC\nC Convexity cannot be satisfied. Monotonicity can be satis-\nC fied iff S1*S .GE. 0 and S2*S .GE. 0 since S .NE. 0.\nC\n 3 IF (S1*S .LT. 0.D0 .OR. S2*S .LT. 0.D0) GO TO 7\n T0 = 3.D0*S - S1 - S2\n D0 = T0*T0 - S1*S2\nC\nC SIGMA = 0 is sufficient for monotonicity iff S*T0 .GE. 0\nC or D0 .LE. 0.\nC\n IF (D0 .LE. 0.D0 .OR. S*T0 .GE. 0.D0) GO TO 7\nC\nC Monotonicity: find a zero of F(SIG) = SIGN(S)*HP(R),\nC where HPP(R) = 0 and HP, HPP denote derivatives of H.\nC F has a unique zero, F(0) < 0, and F approaches abs(S)\nC as SIG increases.\nC\nC Initialize parameters for the secant method. The method\nC uses three points: (SG0,F0), (SIG,F), and\nC (SNEG,FNEG), where SG0 and SNEG are defined implicitly\nC by DSIG = SIG - SG0 and DMAX = SIG - SNEG.\nC\n SGN = SIGN(1.D0,S)\n SIG = SBIG\n FMAX = SGN*(SIG*S-S1-S2)/(SIG-2.D0)\n IF (FMAX .LE. 0.D0) GO TO 7\n STOL = RTOL*SIG\n F = FMAX\n F0 = SGN*D0/(3.D0*(D1-D2))\n FNEG = F0\n DSIG = SIG\n DMAX = SIG\n D1PD2 = D1 + D2\n NIT = 0\nC\nC Top of loop: compute the change in SIG by linear\nC interpolation.\nC\n 4 DSIG = -F*DSIG/(F-F0)\n IF (LUN .GE. 0) WRITE (LUN,120) DSIG\n 120 FORMAT (5X,'MONOTONICITY -- DSIG = ',D15.8)\n IF ( ABS(DSIG) .GT. ABS(DMAX) .OR.\n . DSIG*DMAX .GT. 0. ) GO TO 6\nC\nC Restrict the step-size such that abs(DSIG) .GE. STOL/2.\nC Note that DSIG and DMAX have opposite signs.\nC\n IF (ABS(DSIG) .LT. STOL/2.D0)\n . DSIG = -SIGN(STOL/2.D0,DMAX)\nC\nC Update SIG, F0, and F.\nC\n SIG = SIG + DSIG\n F0 = F\n IF (SIG .LE. .5D0) THEN\nC\nC Use approximations to the hyperbolic functions designed\nC to avoid cancellation error with small SIG.\nC\n CALL SNHCSH (SIG, SINHM,COSHM,COSHMM)\n C1 = SIG*COSHM*D2 - SINHM*D1PD2\n C2 = SIG*(SINHM+SIG)*D2 - COSHM*D1PD2\n A = C2 - C1\n E = SIG*SINHM - COSHMM - COSHMM\n ELSE\nC\nC Scale SINHM and COSHM by 2*EXP(-SIG) in order to avoid\nC overflow with large SIG.\nC\n EMS = EXP(-SIG)\n EMS2 = EMS + EMS\n TM = 1.D0 - EMS\n SSINH = TM*(1.D0+EMS)\n SSM = SSINH - SIG*EMS2\n SCM = TM*TM\n C1 = SIG*SCM*D2 - SSM*D1PD2\n C2 = SIG*SSINH*D2 - SCM*D1PD2\nC\nC R is in (0,1) and well-defined iff HPP(X1)*HPP(X2) < 0.\nC\n F = FMAX\n IF (C1*(SIG*SCM*D1 - SSM*D1PD2) .GE. 0.D0) GO TO 5\n A = EMS2*(SIG*TM*D2 + (TM-SIG)*D1PD2)\n IF (A*(C2+C1) .LT. 0.D0) GO TO 5\n E = SIG*SSINH - SCM - SCM\n ENDIF\nC\n F = (SGN*(E*S2-C2) + SQRT(A*(C2+C1)))/E\nC\nC Update number of iterations NIT.\nC\n 5 NIT = NIT + 1\n IF (LUN .GE. 0) WRITE (LUN,130) NIT, SIG, F\n 130 FORMAT (1X,10X,I2,' -- SIG = ',D15.8,', F = ',\n . D15.8)\nC\nC Test for convergence.\nC\n STOL = RTOL*SIG\n IF ( ABS(DMAX) .LE. STOL .OR. (F .GE. 0.D0 .AND.\n . F .LE. FTOL) .OR. ABS(F) .LE. RTOL ) GO TO 7\n DMAX = DMAX + DSIG\n IF ( F0*F .GT. 0.D0 .AND. ABS(F) .GE. ABS(F0) )\n . GO TO 6\n IF (F0*F .LE. 0.D0) THEN\nC\nC F and F0 have opposite signs. Update (SNEG,FNEG) to\nC (SG0,F0) so that F and FNEG always have opposite\nC signs. If SIG is closer to SNEG than SG0 and abs(F) <\nC abs(FNEG), then swap (SNEG,FNEG) with (SG0,F0).\nC\n T1 = DMAX\n T2 = FNEG\n DMAX = DSIG\n FNEG = F0\n IF ( ABS(DSIG) .GT. ABS(T1) .AND.\n . ABS(F) .LT. ABS(T2) ) THEN\nC\n DSIG = T1\n F0 = T2\n ENDIF\n ENDIF\n GO TO 4\nC\nC Bottom of loop: F0*F > 0 and the new estimate would\nC be outside of the bracketing interval of length\nC abs(DMAX). Reset (SG0,F0) to (SNEG,FNEG).\nC\n 6 DSIG = DMAX\n F0 = FNEG\n GO TO 4\nC\nC Update SIGMA(I), ICNT, and DSM if necessary.\nC\n 7 SIG = MIN(SIG,SBIG)\n IF (SIG .GT. SIGIN) THEN\n SIGMA(I) = SIG\n ICNT = ICNT + 1\n DSIG = SIG-SIGIN\n IF (SIGIN .GT. 0.D0) DSIG = DSIG/SIGIN\n DSM = MAX(DSM,DSIG)\n ENDIF\n 8 CONTINUE\nC\nC No errors encountered.\nC\n DSMAX = DSM\n IER = ICNT\n RETURN\nC\nC N < 2.\nC\n 9 DSMAX = 0.D0\n IER = -1\n RETURN\nC\nC X(I+1) .LE. X(I).\nC\n 10 DSMAX = DSM\n IER = -IP1\n RETURN\n END\n SUBROUTINE SMCRV (N,X,Y,SIGMA,PERIOD,W,SM,SMTOL,\n . WK, YS,YP,IER)\n LOGICAL PERIOD\n INTEGER N, IER\n DOUBLE PRECISION X(N), Y(N), SIGMA(N), W(N), SM,\n . SMTOL, WK(N,10), YS(N), YP(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 10/05/98\nC\nC Given a sequence of abscissae X with associated data\nC values Y and tension factors SIGMA, this routine deter-\nC mines a set of function values YS and first derivatives YP\nC associated with a Hermite interpolatory tension spline\nC H(x) which smoothes the data. H(x) has two continuous\nC derivatives for all x and satisfies either natural or per-\nC iodic end conditions. The values and derivatives are\nC chosen to minimize a quadratic functional Q1(YS,YP) sub-\nC ject to the constraint Q2(YS) .LE. SM for Q2(YS) =\nC (Y-YS)**T*W*(Y-YS), where **T denotes transpose and W is a\nC diagonal matrix of positive weights.\nC\nC Functions HVAL, HPVAL, HPPVAL, and TSINTL may be called\nC to compute values, derivatives, and integrals of H. The\nC function values YS must be used as data values in those\nC subprograms.\nC\nC The smoothing procedure is an extension of the method\nC for cubic spline smoothing due to C. Reinsch: Numer.\nC Math., 10 (1967) and 16 (1971). Q1 is defined as the sum\nC of integrals over the intervals (X(I),X(I+1)) of HPP**2 +\nC (SIGMA(I)/DX)**2*(HP-S)**2, where DX = X(I+1)-X(I), HP and\nC HPP denote first and second derivatives of H, and S =\nC (YS(I+1)-YS(I))/DX. Introducing a smoothing parameter P,\nC and assuming the constraint is active, the problem is\nC equivalent to minimizing Q(P,YS,YP) = Q1(YS,YP) +\nC P*(Q2(YS)-SM). The secant method is used to find a zero\nC of G(P) = 1/SQRT(Q2) - 1/SQRT(SM), where YS and YP satisfy\nC the order 2N symmetric positive-definite linear system\nC obtained by setting the gradient of Q (treated as a func-\nC tion of YS and YP) to zero.\nC\nC Note that the interpolation problem corresponding to\nC YS = Y, SM = 0, and P infinite is solved by Subroutine\nC YPC2 or YPC2P.\nC\nC On input:\nC\nC N = Number of data points. N .GE. 2 if PERIOD =\nC FALSE, and N .GE. 3 if PERIOD = TRUE.\nC\nC X = Array of length N containing a strictly in-\nC creasing sequence of abscissae: X(I) < X(I+1)\nC for I = 1,...,N-1.\nC\nC Y = Array of length N containing data values assoc-\nC iated with the abscissae. If PERIOD = TRUE, it\nC is assumed that Y(N) = Y(1).\nC\nC SIGMA = Array of length N-1 containing tension\nC factors. SIGMA(I) is associated with inter-\nC val (X(I),X(I+1)) for I = 1,...,N-1. If\nC SIGMA(I) = 0, H is cubic, and as SIGMA in-\nC creases, H approaches linear in the inter-\nC val.\nC\nC PERIOD = Periodic end condition flag:\nC PERIOD = .F. if H is to satisfy natural end\nC conditions: zero second der-\nC ivatives at X(1) and X(N).\nC PERIOD = .T. if H is to satisfy periodic\nC end conditions: the values\nC and first two derivatives at\nC X(1) agree with those at X(N),\nC and a period thus has length\nC X(N)-X(1).\nC\nC W = Array of length N containing positive weights\nC associated with the data values. The recommend-\nC ed value of W(I) is 1/DY**2, where DY is the\nC standard deviation associated with Y(I). If\nC nothing is known about the errors in Y, a con-\nC stant (estimated value) should be used for DY.\nC If PERIOD = TRUE, it is assumed that W(N) =\nC W(1).\nC\nC SM = Positive parameter specifying an upper bound on\nC Q2(YS). H(x) is linear (and Q2 is minimized)\nC if SM is sufficiently large that the constraint\nC is not active. It is recommended that SM sat-\nC isfy N-SQRT(2N) .LE. SM .LE. N+SQRT(2N) and\nC SM = N is reasonable if W(I) = 1/DY**2.\nC\nC SMTOL = Parameter in the range (0,1) specifying the\nC relative error allowed in satisfying the\nC constraint: the constraint is assumed to\nC be satisfied if SM*(1-SMTOL) .LE. Q2 .LE.\nC SM*(1+SMTOL). A reasonable value for SMTOL\nC is SQRT(2/N).\nC\nC The above parameters are not altered by this routine.\nC\nC WK = Work space of length at least 6N if PERIOD =\nC FALSE, and 10N if PERIOD = TRUE.\nC\nC On output:\nC\nC YS = Array of length N containing values of H at the\nC abscissae unless IER < 0. YS(N) = YS(1) if\nC PERIOD = TRUE.\nC\nC YP = Array of length N containing first derivative\nC values of H at the abscissae unless IER < 0.\nC YP(N) = YP(1) if PERIOD = TRUE.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered and the\nC constraint is active: Q2(YS) is ap-\nC proximately equal to SM.\nC IER = 1 if no errors were encountered but the\nC constraint is not active: YS and YP\nC are the values and derivatives of the\nC linear function (constant function if\nC PERIOD = TRUE) which minimizes Q2, and\nC Q1 = 0.\nC IER = -1 if N, W, SM, or SMTOL is outside its\nC valid range. YS and YP are unaltered\nC in this case.\nC IER = -I if X(I) .LE. X(I-1) for some I in the\nC range 2,...,N. YS and YP are unal-\nC tered in this case.\nC\nC Modules required by SMCRV: B2TRI or B2TRIP, SNHCSH,\nC YPCOEF\nC\nC Intrinsic functions called by SMCRV: ABS, SQRT\nC\nC***********************************************************\nC\n INTEGER I, IERR, ITER, LUN, NM1, NN\n LOGICAL PER\n DOUBLE PRECISION C11, C12, C22, D, DMAX, DP, DX, G,\n . G0, GNEG, H0, HP, P, P0, Q2, Q2MAX,\n . Q2MIN, R1, R2, S, SD, SIG, WI, WIXI,\n . XI, YI\nC\n DATA LUN/-1/\n NN = N\n PER = PERIOD\nC\nC Test for errors, and compute the components of the system\nC (normal equations) for the weighted least squares linear\nC fit.\nC\n IER = -1\n IF (NN .LT. 2 .OR. (NN .LT. 3 .AND. PER) .OR.\n . SM .LE. 0.D0 .OR. SMTOL .LE. 0.D0 .OR.\n . SMTOL .GE. 1.D0) RETURN\n C11 = 0.D0\n C12 = 0.D0\n C22 = 0.D0\n R1 = 0.D0\n R2 = 0.D0\n XI = X(1) - 1.D0\n DO 1 I = 1,NN\n WI = W(I)\n IF (WI .LE. 0.D0) RETURN\n IF (X(I) .LE. XI) THEN\n IER = -I\n RETURN\n ENDIF\n XI = X(I)\n YI = Y(I)\n C22 = C22 + WI\n R2 = R2 + WI*YI\n IF (.NOT. PER) THEN\n WIXI = WI*XI\n C11 = C11 + WIXI*XI\n C12 = C12 + WIXI\n R1 = R1 + WIXI*YI\n ENDIF\n 1 CONTINUE\nC\nC Solve the system for (HP,H0), where HP is the derivative\nC (constant) and H0 = H(0).\nC\n IF (PER) THEN\n H0 = R2/C22\n HP = 0.D0\n ELSE\n H0 = (C11*R2-C12*R1)/(C11*C22-C12*C12)\n HP = (R1 - C12*H0)/C11\n ENDIF\nC\nC Store function values and derivatives, and accumulate\nC Q2 = (Y-YS)**T*W*(Y-YS).\nC\n Q2 = 0.D0\n DO 2 I = 1,NN\n YS(I) = HP*X(I) + H0\n YP(I) = HP\n Q2 = Q2 + W(I)*(Y(I)-YS(I))**2\n 2 CONTINUE\nC\nC Compute bounds on Q2 defined by SMTOL, and test for the\nC constraint satisfied by the linear fit.\nC\n Q2MIN = SM*(1.D0 - SMTOL)\n Q2MAX = SM*(1.D0 + SMTOL)\n IF (Q2 .LE. Q2MAX) THEN\nC\nC The constraint is satisfied by a linear function.\nC\n IER = 1\n IF (LUN .GE. 0) WRITE (LUN,100)\n 100 FORMAT (///1X,'SMCRV -- THE CONSTRAINT IS NOT ',\n . 'ACTIVE AND THE FIT IS LINEAR.'/)\n RETURN\n ENDIF\nC\nC Compute the matrix components for the linear system.\nC\n IER = 0\n NM1 = NN - 1\n DO 3 I = 1,NM1\n DX = X(I+1) - X(I)\n SIG = ABS(SIGMA(I))\n CALL YPCOEF (SIG,DX, D,SD)\n WK(I,1) = D\n WK(I,2) = SD\n 3 CONTINUE\nC\nC Compute G0 = G(0), and print a heading.\nC\n S = 1.D0/SQRT(SM)\n G0 = 1.D0/SQRT(Q2) - S\n IF (LUN .GE. 0) WRITE (LUN,110) SM, SMTOL, G0\n 110 FORMAT (///1X,3X,'SMCRV -- SM = ',D10.4,', SMTOL = ',\n . D14.8,', G(0) = ',D15.8///)\nC\nC G(P) is strictly increasing and concave, and G(0) < 0.\nC\nC Initialize parameters for the secant method. The method\nC uses three points: (P0,G0), (P,G), and (PNEG,GNEG),\nC where P0 and PNEG are defined implicitly by DP = P - P0\nC and DMAX = P - PNEG.\nC\n P = 10.D0*SM\n DP = P\n DMAX = 0.D0\n ITER = 0\nC\nC Top of loop: compute G and print a message. For each\nC secant iteration, the following values are\nC printed: P, G(P), and DP, where DP is the\nC change in P computed by linear interpolation\nC between the current point (P,G) and a previ-\nC ous point.\nC\nC\n 4 IF (.NOT. PER) THEN\n CALL B2TRI (NN,X,Y,W,P,WK,WK(1,2),WK(1,3),WK(1,4),\n . WK(1,5),WK(1,6), YS,YP,IERR)\n ELSE\n CALL B2TRIP (NN,X,Y,W,P,WK,WK(1,2),WK(1,3),WK(1,4),\n . WK(1,5),WK(1,6),WK(1,7),WK(1,8),\n . WK(1,9),WK(1,10), YS,YP,IERR)\n ENDIF\n Q2 = 0.D0\n DO 5 I = 1,NN\n Q2 = Q2 + W(I)*(Y(I)-YS(I))**2\n 5 CONTINUE\n G = 1.D0/SQRT(Q2) - S\n ITER = ITER + 1\n IF (LUN .GE. 0) THEN\n P0 = P - DP\n IF (LUN .GE. 0) WRITE (LUN,120) ITER, P, G, P0, G0\n 120 FORMAT (/1X,I2,' -- P = ',D15.8,', G = ',D15.8/\n . 6X,'P0 = ',D15.8,', G0 = ',D15.8)\n ENDIF\nC\nC Test for convergence.\nC\n IF ( G .EQ. G0 .OR. (Q2MIN .LE. Q2 .AND.\n . Q2 .LE. Q2MAX) ) RETURN\n IF (DMAX .NE. 0.D0 .OR. G .GT. 0.D0) GO TO 6\nC\nC Increase P until G(P) > 0.\nC\n P = 10.D0*P\n DP = P\n GO TO 4\nC\nC A bracketing interval [P0,P] has been found.\nC\n 6 IF (G0*G .LE. 0.D0) THEN\nC\nC G0*G < 0. Update (PNEG,GNEG) to (P0,G0) so that G\nC and GNEG always have opposite signs.\nC\n DMAX = DP\n GNEG = G0\n ENDIF\nC\nC Compute the change in P by linear interpolation between\nC (P0,G0) and (P,G).\nC\n 7 DP = -G*DP/(G-G0)\n IF (LUN .GE. 0) WRITE (LUN,130) DP\n 130 FORMAT (1X ,5X,'DP = ',D15.8)\n IF (ABS(DP) .GT. ABS(DMAX)) THEN\nC\nC G0*G > 0, and the new estimate would be outside of the\nC bracketing interval of length abs(DMAX). Reset\nC (P0,G0) to (PNEG,GNEG).\nC\n DP = DMAX\n G0 = GNEG\n GO TO 7\n ENDIF\nC\nC Bottom of loop: update P, DMAX, and G0.\nC\n P = P + DP\n DMAX = DMAX + DP\n G0 = G\n GO TO 4\n END\n SUBROUTINE SNHCSH (X, SINHM,COSHM,COSHMM)\n DOUBLE PRECISION X, SINHM, COSHM, COSHMM\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 11/20/96\nC\nC This subroutine computes approximations to the modified\nC hyperbolic functions defined below with relative error\nC bounded by 3.4E-20 for a floating point number system with\nC sufficient precision.\nC\nC Note that the 21-digit constants in the data statements\nC below may not be acceptable to all compilers.\nC\nC On input:\nC\nC X = Point at which the functions are to be\nC evaluated.\nC\nC X is not altered by this routine.\nC\nC On output:\nC\nC SINHM = sinh(X) - X.\nC\nC COSHM = cosh(X) - 1.\nC\nC COSHMM = cosh(X) - 1 - X*X/2.\nC\nC Modules required by SNHCSH: None\nC\nC Intrinsic functions called by SNHCSH: ABS, EXP\nC\nC***********************************************************\nC\n DOUBLE PRECISION AX, EXPX, F, P, P1, P2, P3, P4, Q,\n . Q1, Q2, Q3, Q4, XC, XS, XSD2, XSD4\nC\n DATA P1/-3.51754964808151394800D5/,\n . P2/-1.15614435765005216044D4/,\n . P3/-1.63725857525983828727D2/,\n . P4/-7.89474443963537015605D-1/\n DATA Q1/-2.11052978884890840399D6/,\n . Q2/3.61578279834431989373D4/,\n . Q3/-2.77711081420602794433D2/,\n . Q4/1.D0/\n AX = ABS(X)\n XS = AX*AX\n IF (AX .LE. .5D0) THEN\nC\nC Approximations for small X:\nC\n XC = X*XS\n P = ((P4*XS+P3)*XS+P2)*XS+P1\n Q = ((Q4*XS+Q3)*XS+Q2)*XS+Q1\n SINHM = XC*(P/Q)\n XSD4 = .25D0*XS\n XSD2 = XSD4 + XSD4\n P = ((P4*XSD4+P3)*XSD4+P2)*XSD4+P1\n Q = ((Q4*XSD4+Q3)*XSD4+Q2)*XSD4+Q1\n F = XSD4*(P/Q)\n COSHMM = XSD2*F*(F+2.D0)\n COSHM = COSHMM + XSD2\n ELSE\nC\nC Approximations for large X:\nC\n EXPX = EXP(AX)\n SINHM = -(((1.D0/EXPX+AX)+AX)-EXPX)/2.D0\n IF (X .LT. 0.D0) SINHM = -SINHM\n COSHM = ((1.D0/EXPX-2.D0)+EXPX)/2.D0\n COSHMM = COSHM - XS/2.D0\n ENDIF\n RETURN\n END\n DOUBLE PRECISION FUNCTION STORE (X)\n DOUBLE PRECISION X\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 06/10/92\nC\nC This function forces its argument X to be stored in a\nC memory location, thus providing a means of determining\nC floating point number characteristics (such as the machine\nC precision) when it is necessary to avoid computation in\nC high precision registers.\nC\nC On input:\nC\nC X = Value to be stored.\nC\nC X is not altered by this function.\nC\nC On output:\nC\nC STORE = Value of X after it has been stored and\nC possibly truncated or rounded to the single\nC precision word length.\nC\nC Modules required by STORE: None\nC\nC***********************************************************\nC\n DOUBLE PRECISION Y\n COMMON/STCOM/Y\n Y = X\n STORE = Y\n RETURN\n END\n DOUBLE PRECISION FUNCTION TSINTL (A,B,N,X,Y,YP,\n . SIGMA, IER)\n INTEGER N, IER\n DOUBLE PRECISION A, B, X(N), Y(N), YP(N), SIGMA(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 11/17/96\nC\nC This function computes the integral from A to B of a\nC Hermite interpolatory tension spline H.\nC\nC On input:\nC\nC A,B = Lower and upper limits of integration, re-\nC spectively. Note that -TSINTL(B,A,...) =\nC TSINTL(A,B,...).\nC\nC N = Number of data points. N .GE. 2.\nC\nC X = Array of length N containing the abscissae.\nC These must be in strictly increasing order:\nC X(I) < X(I+1) for I = 1,...,N-1.\nC\nC Y = Array of length N containing data values.\nC H(X(I)) = Y(I) for I = 1,...,N.\nC\nC YP = Array of length N containing first deriva-\nC tives. HP(X(I)) = YP(I) for I = 1,...,N, where\nC HP denotes the derivative of H.\nC\nC SIGMA = Array of length N-1 containing tension fac-\nC tors whose absolute values determine the\nC balance between cubic and linear in each\nC interval. SIGMA(I) is associated with int-\nC erval (I,I+1) for I = 1,...,N-1.\nC\nC Input parameters are not altered by this function.\nC\nC On output:\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered and\nC X(1) .LE. T .LE. X(N) for T = A and\nC T = B, or A = B.\nC IER = 1 if no errors were encountered but\nC extrapolation was necessary: A or B\nC not in the interval (X(1),X(N)).\nC IER = -1 IF N < 2.\nC IER = -2 if the abscissae are not in strictly\nC increasing order. Only those in or\nC adjacent to the interval of integra-\nC tion are tested.\nC\nC TSINTL = Integral of H from A to B, or zero if\nC IER < 0.\nC\nC Modules required by TSINTL: INTRVL, SNHCSH\nC\nC Intrinsic functions called by TSINTL: ABS, EXP, MAX, MIN\nC\nC***********************************************************\nC\n INTEGER I, IL, ILP1, IMAX, IMIN, IP1, IU, IUP1\n DOUBLE PRECISION B1, B2, CM, CM1, CM2, CMM, CMM1,\n . CMM2, D1, D2, DX, E, E1, E2, EMS, S,\n . S1, S2, SB1, SB2, SBIG, SIG, SM, SM1,\n . SM2, SUM, T, TM, TP, U, XL, XU, Y1,\n . Y2\n INTEGER INTRVL\nC\n DATA SBIG/85.D0/\n IF (N .LT. 2) GO TO 7\nC\nC Accumulate the integral from XL to XU in SUM.\nC\n XL = MIN(A,B)\n XU = MAX(A,B)\n SUM = 0.D0\n IER = 0\n IF (XL .EQ. XU) GO TO 6\nC\nC Find left-end indexes of intervals containing XL and XU.\nC If XL < X(1) or XU > X(N), extrapolation is performed\nC using the leftmost or rightmost interval.\nC\n IL = INTRVL (XL,N,X)\n IU = INTRVL (XU,N,X)\n IF (XL .LT. X(1) .OR. XU .GT. X(N)) IER = 1\n ILP1 = IL + 1\n IMIN = IL\n IF (XL .EQ. X(IL)) GO TO 2\nC\nC Compute the integral from XL to X(IL+1).\nC\n DX = X(ILP1) - X(IL)\n IF (DX .LE. 0.D0) GO TO 8\n U = X(ILP1) - XL\n IF (U .EQ. 0.D0) GO TO 1\n B1 = U/DX\n Y2 = Y(ILP1)\n S = (Y2-Y(IL))/DX\n S2 = YP(ILP1)\n D1 = S - YP(IL)\n D2 = S2 - S\n SIG = ABS(SIGMA(IL))\n IF (SIG .LT. 1.D-9) THEN\nC\nC SIG = 0.\nC\n SUM = SUM + U*(Y2 - U*(6.D0*S2 - B1*(4.D0*D2 +\n . (3.D0*B1-4.D0)*(D1-D2)))/12.D0)\n ELSEIF (SIG .LE. .5D0) THEN\nC\nC 0 .LT. SIG .LE. .5.\nC\n SB1 = SIG*B1\n CALL SNHCSH (SIG, SM,CM,CMM)\n CALL SNHCSH (SB1, SM1,CM1,CMM1)\n E = SIG*SM - CMM - CMM\n SUM = SUM + U*(Y2 - S2*U/2.D0) + ((CM*CMM1-SM*SM1)*\n . (D1+D2) + SIG*(CM*SM1-(SM+SIG)*CMM1)*D2)/\n . ((SIG/DX)**2*E)\n ELSE\nC\nC SIG > .5.\nC\n SB1 = SIG*B1\n SB2 = SIG - SB1\n IF (-SB1 .GT. SBIG .OR. -SB2 .GT. SBIG) THEN\n SUM = SUM + U*(Y2 - S*U/2.D0)\n ELSE\n E1 = EXP(-SB1)\n E2 = EXP(-SB2)\n EMS = E1*E2\n TM = 1.D0 - EMS\n TP = 1.D0 + EMS\n T = SB1*SB1/2.D0 + 1.D0\n E = TM*(SIG*TP - TM - TM)\n SUM = SUM +U*(Y2 - S2*U/2.D0)+(SIG*TM*(TP*T-E1-E2-\n . TM*SB1)*D2 - (TM*(TM*T-E1+E2-TP*SB1) +\n . SIG*(E1*EMS-E2+2.D0*SB1*EMS))*(D1+D2))/\n . ((SIG/DX)**2*E)\n ENDIF\n ENDIF\nC\nC Test for XL and XU in the same interval.\nC\n 1 IMIN = ILP1\n IF (IL .EQ. IU) GO TO 5\nC\nC Add in the integral from X(IMIN) to X(J) for J =\nC Max(IL+1,IU).\nC\n 2 IMAX = MAX(IL,IU-1)\n DO 3 I = IMIN,IMAX\n IP1 = I + 1\n DX = X(IP1) - X(I)\n IF (DX .LE. 0.D0) GO TO 8\n SIG = ABS(SIGMA(I))\n IF (SIG .LT. 1.D-9) THEN\nC\nC SIG = 0.\nC\n SUM = SUM + DX*((Y(I)+Y(IP1))/2.D0 -\n . DX*(YP(IP1)-YP(I))/12.D0)\n ELSEIF (SIG .LE. .5D0) THEN\nC\nC 0 .LT. SIG .LE. .5.\nC\n CALL SNHCSH (SIG, SM,CM,CMM)\n E = SIG*SM - CMM - CMM\n SUM = SUM + DX*(Y(I)+Y(IP1) - DX*E*(YP(IP1)-YP(I))\n . /(SIG*SIG*CM))/2.D0\n ELSE\nC\nC SIG > .5.\nC\n EMS = EXP(-SIG)\n SUM = SUM + DX*(Y(I)+Y(IP1) - DX*(SIG*(1.D0+EMS)/\n . (1.D0-EMS)-2.D0)*(YP(IP1)-YP(I))/\n . (SIG*SIG))/2.D0\n ENDIF\n 3 CONTINUE\nC\nC Add in the integral from X(IU) to XU if IU > IL.\nC\n IF (IL .EQ. IU) GO TO 4\n IUP1 = IU + 1\n DX = X(IUP1) - X(IU)\n IF (DX .LE. 0.D0) GO TO 8\n U = XU - X(IU)\n IF (U .EQ. 0.D0) GO TO 6\n B2 = U/DX\n Y1 = Y(IU)\n S = (Y(IUP1)-Y1)/DX\n S1 = YP(IU)\n D1 = S - S1\n D2 = YP(IUP1) - S\n SIG = ABS(SIGMA(IU))\n IF (SIG .LT. 1.D-9) THEN\nC\nC SIG = 0.\nC\n SUM = SUM + U*(Y1 + U*(6.D0*S1 + B2*(4.D0*D1 +\n . (4.D0-3.D0*B2)*(D1-D2)))/12.D0)\n ELSEIF (SIG .LE. .5D0) THEN\nC\nC 0 .LT. SIG .LE. .5.\nC\n SB2 = SIG*B2\n CALL SNHCSH (SIG, SM,CM,CMM)\n CALL SNHCSH (SB2, SM2,CM2,CMM2)\n E = SIG*SM - CMM - CMM\n SUM = SUM + U*(Y1 + S1*U/2.D0) + ((CM*CMM2-SM*SM2)*\n . (D1+D2) + SIG*(CM*SM2-(SM+SIG)*CMM2)*D1)\n . /((SIG/DX)**2*E)\n ELSE\nC\nC SIG > .5.\nC\n SB2 = SIG*B2\n SB1 = SIG - SB2\n IF (-SB1 .GT. SBIG .OR. -SB2 .GT. SBIG) THEN\n SUM = SUM + U*(Y1 + S*U/2.D0)\n ELSE\n E1 = EXP(-SB1)\n E2 = EXP(-SB2)\n EMS = E1*E2\n TM = 1.D0 - EMS\n TP = 1.D0 + EMS\n T = SB2*SB2/2.D0 + 1.D0\n E = TM*(SIG*TP - TM - TM)\n SUM = SUM +U*(Y1 + S1*U/2.D0)+(SIG*TM*(TP*T-E1-E2-\n . TM*SB2)*D1 - (TM*(TM*T-E2+E1-TP*SB2) +\n . SIG*(E2*EMS-E1+2.D0*SB2*EMS))*(D1+D2))/\n . ((SIG/DX)**2*E)\n ENDIF\n ENDIF\n GO TO 6\nC\nC IL = IU and SUM contains the integral from XL to X(IL+1).\nC Subtract off the integral from XU to X(IL+1). DX and\nC SIG were computed above.\nC\n 4 Y2 = Y(ILP1)\n S = (Y2-Y(IL))/DX\n S2 = YP(ILP1)\n D1 = S - YP(IL)\n D2 = S2 - S\nC\n 5 U = X(ILP1) - XU\n IF (U .EQ. 0.D0) GO TO 6\n B1 = U/DX\n IF (SIG .LT. 1.D-9) THEN\nC\nC SIG = 0.\nC\n SUM = SUM - U*(Y2 - U*(6.D0*S2 - B1*(4.D0*D2 +\n . (3.D0*B1-4.D0)*(D1-D2)))/12.D0)\n ELSEIF (SIG .LE. .5D0) THEN\nC\nC 0 .LT. SIG .LE. .5.\nC\n SB1 = SIG*B1\n CALL SNHCSH (SIG, SM,CM,CMM)\n CALL SNHCSH (SB1, SM1,CM1,CMM1)\n E = SIG*SM - CMM - CMM\n SUM = SUM - U*(Y2 - S2*U/2.D0) - ((CM*CMM1-SM*SM1)*\n . (D1+D2) + SIG*(CM*SM1-(SM+SIG)*CMM1)*D2)\n . /((SIG/DX)**2*E)\n ELSE\nC\nC SIG > .5.\nC\n SB1 = SIG*B1\n SB2 = SIG - SB1\n IF (-SB1 .GT. SBIG .OR. -SB2 .GT. SBIG) THEN\n SUM = SUM - U*(Y2 - S*U/2.D0)\n ELSE\n E1 = EXP(-SB1)\n E2 = EXP(-SB2)\n EMS = E1*E2\n TM = 1.D0 - EMS\n TP = 1.D0 + EMS\n T = SB1*SB1/2.D0 + 1.D0\n E = TM*(SIG*TP - TM - TM)\n SUM = SUM -U*(Y2 - S2*U/2.D0)-(SIG*TM*(TP*T-E1-E2-\n . TM*SB1)*D2 - (TM*(TM*T-E1+E2-TP*SB1) +\n . SIG*(E1*EMS-E2+2.D0*SB1*EMS))*(D1+D2))/\n . ((SIG/DX)**2*E)\n ENDIF\n ENDIF\nC\nC No errors were encountered. Adjust the sign of SUM.\nC\n 6 IF (XL .EQ. B) SUM = -SUM\n TSINTL = SUM\n RETURN\nC\nC N < 2.\nC\n 7 IER = -1\n TSINTL = 0.D0\n RETURN\nC\nC Abscissae not strictly increasing.\nC\n 8 IER = -2\n TSINTL = 0.D0\n RETURN\n END\n SUBROUTINE TSPBI (N,X,Y,NCD,IENDC,PER,B,BMAX,LWK, WK,\n . YP, SIGMA,ICFLG,IER)\n INTEGER N, NCD, IENDC, LWK, ICFLG(N), IER\n LOGICAL PER\n DOUBLE PRECISION X(N), Y(N), B(5,N), BMAX, WK(LWK),\n . YP(N), SIGMA(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 07/08/92\nC\nC This subroutine computes a set of parameter values which\nC define a Hermite interpolatory tension spline H(x). The\nC parameters consist of knot derivative values YP computed\nC by Subroutine YPC1, YPC1P, YPC2, or YPC2P, and tension\nC factors SIGMA chosen to satisfy user-specified constraints\nC (by Subroutine SIGBI). Refer to Subroutine TSPSI for an\nC alternative method of computing tension factors.\nC\nC Refer to Subroutine TSPSS for a means of computing\nC parameters which define a smoothing curve rather than an\nC interpolatory curve.\nC\nC The tension spline may be evaluated by Subroutine TSVAL1\nC or Functions HVAL (values), HPVAL (first derivatives),\nC HPPVAL (second derivatives), and TSINTL (integrals).\nC\nC On input:\nC\nC N = Number of data points. N .GE. 2 and N .GE. 3 if\nC PER = TRUE.\nC\nC X = Array of length N containing a strictly in-\nC creasing sequence of abscissae: X(I) < X(I+1)\nC for I = 1,...,N-1.\nC\nC Y = Array of length N containing data values asso-\nC ciated with the abscissae. H(X(I)) = Y(I) for\nC I = 1,...,N. If NCD = 1 and PER = TRUE, Y(N)\nC is set to Y(1).\nC\nC NCD = Number of continuous derivatives at the knots.\nC NCD = 1 or NCD = 2. If NCD = 1, the YP values\nC are computed by local monotonicity-constrained\nC quadratic fits. Otherwise, a linear system is\nC solved for the derivative values which result\nC in second derivative continuity. This re-\nC quires iterating on calls to YPC2 or YPC2P and\nC calls to SIGBI, and generally results in more\nC nonzero tension factors (hence more expensive\nC evaluation).\nC\nC IENDC = End condition indicator for NCD = 2 and PER\nC = FALSE (or dummy parameter otherwise):\nC IENDC = 0 if YP(1) and YP(N) are to be com-\nC puted by monotonicity-constrained\nC parabolic fits to the first three\nC and last three points, respective-\nC ly. This is identical to the\nC values computed by YPC1.\nC IENDC = 1 if the first derivatives of H at\nC X(1) and X(N) are user-specified\nC in YP(1) and YP(N), respectively.\nC IENDC = 2 if the second derivatives of H at\nC X(1) and X(N) are user-specified\nC in YP(1) and YP(N), respectively.\nC IENDC = 3 if the end conditions are to be\nC computed by Subroutine ENDSLP and\nC vary with SIGMA(1) and SIGMA(N-1).\nC\nC PER = Logical variable with value TRUE if and only\nC H(x) is to be a periodic function with period\nC X(N)-X(1). It is assumed without a test that\nC Y(N) = Y(1) in this case. On output, YP(N) =\nC YP(1). If H(x) is one of the components of a\nC parametric curve, this option may be used to\nC obtained a closed curve.\nC\nC B = Array dimensioned 5 by N-1 containing bounds or\nC flags which define the constraints. For I = 1\nC to N-1, column I defines the constraints associ-\nC ated with interval (X(I),X(I+1)) as follows:\nC\nC B(1,I) is an upper bound on H\nC B(2,I) is a lower bound on H\nC B(3,I) is an upper bound on HP\nC B(4,I) is a lower bound on HP\nC B(5,I) specifies the required sign of HPP\nC\nC where HP and HPP denote the first and second\nC derivatives of H, respectively. A null con-\nC straint is specified by abs(B(K,I)) .GE. BMAX\nC for K < 5, or B(5,I) = 0: B(1,I) .GE. BMAX,\nC B(2,I) .LE. -BMAX, B(3,I) .GE. BMAX, B(4,I) .LE.\nC -BMAX, or B(5,I) = 0. Any positive value of\nC B(5,I) specifies that H should be convex, a\nC negative values specifies that H should be con-\nC cave, and 0 specifies that no restriction be\nC placed on HPP. Refer to Functions SIG0, SIG1,\nC and SIG2 for definitions of valid constraints.\nC\nC BMAX = User-defined value of infinity which, when\nC used as an upper bound in B (or when when\nC its negative is used as a lower bound),\nC specifies that no constraint is to be en-\nC forced.\nC\nC LWK = Length of work space WK:\nC LWK GE 2N-2 if NCD = 2 and PER = FALSE\nC LWK GE 3N-3 if NCD = 2 and PER = TRUE\nC\nC The above parameters, except possibly Y(N), are not\nC altered by this routine.\nC\nC WK = Array of length at least LWK to be used as\nC temporary work space.\nC\nC YP = Array of length .GE. N containing end condition\nC values in positions 1 and N if NCD = 2 and\nC IENDC = 1 or IENDC = 2.\nC\nC SIGMA = Array of length .GE. N-1.\nC\nC ICFLG = Array of length .GE. N-1.\nC\nC On output:\nC\nC WK = Array containing convergence parameters in the\nC first two locations if IER > 0 (NCD = 2 and\nC no error other than invalid constraints was\nC encountered):\nC WK(1) = Maximum relative change in a component\nC of YP on the last iteration.\nC WK(2) = Maximum relative change in a component\nC of SIGMA on the last iteration.\nC\nC YP = Array containing derivatives of H at the\nC abscissae. YP is not altered if -3 < IER < 0,\nC and YP is only partially defined if IER = -4.\nC\nC SIGMA = Array containing tension factors for which\nC H(x) satisfies the constraints defined by B.\nC SIGMA(I) is associated with interval (X(I),\nC X(I+1)) for I = 1,...,N-1. If infinite ten-\nC sion is required in interval I, then\nC SIGMA(I) = 85 (and H is an approximation to\nC the linear interpolant on the interval),\nC and if no constraint is specified in the\nC interval, then SIGMA(I) = 0, and thus H is\nC cubic. Invalid constraints are treated as\nC null constraints. SIGMA is not altered if\nC -3 < IER < 0 (unless IENDC is invalid), and\nC SIGMA is the zero vector if IER = -4 or\nC IENDC (if used) is invalid.\nC\nC ICFLG = Array of invalid constraint flags associated\nC with intervals. For I = 1 to N-1, ICFLG(I)\nC is a 5-bit value b5b4b3b2b1, where bK = 1 if\nC and only if constraint K cannot be satis-\nC fied. Thus, all constraints in interval I\nC are satisfied if and only if ICFLG(I) = 0\nC (and IER .GE. 0). ICFLG is not altered if\nC IER < 0.\nC\nC IER = Error indicator or iteration count:\nC IER = IC .GE. 0 if no errors were encountered\nC (other than invalid constraints) and\nC IC calls to SIGBI and IC+1 calls to\nC YPC1, YPC1P, YPC2 or YPC2P were\nC employed. (IC = 0 if NCD = 1).\nC IER = -1 if N, NCD, or IENDC is outside its\nC valid range.\nC IER = -2 if LWK is too small.\nC IER = -4 if the abscissae X are not strictly\nC increasing.\nC\nC Modules required by TSPBI: ENDSLP, SIG0, SIG1, SIG2,\nC SIGBI, SNHCSH, STORE,\nC YPCOEF, YPC1, YPC1P, YPC2,\nC YPC2P\nC\nC Intrinsic functions called by TSPBI: ABS, MAX\nC\nC***********************************************************\nC\n INTEGER I, ICNT, IERR, ITER, MAXIT, NM1, NN\n LOGICAL LOOP2\n DOUBLE PRECISION DSMAX, DYP, DYPTOL, E, STOL, YP1, YPN\nC\n DATA STOL/0.D0/, MAXIT/49/, DYPTOL/.01D0/\nC\nC Convergence parameters:\nC\nC STOL = Absolute tolerance for SIGBI.\nC MAXIT = Maximum number of YPC2/SIGBI iterations for\nC each loop if NCD = 2.\nC DYPTOL = Bound on the maximum relative change in a\nC component of YP defining convergence of\nC the YPC2/SIGBI iteration when NCD = 2.\nC\n NN = N\n NM1 = NN - 1\nC\nC Test for invalid input parameters N, NCD, or LWK.\nC\n IF (NN .LT. 2 .OR. (PER .AND. NN .LT. 3) .OR.\n . NCD .LT. 1 .OR. NCD .GT. 2) GO TO 11\n IF ( NCD .EQ. 2 .AND. (LWK .LT. 2*NM1 .OR.\n . (PER .AND. LWK .LT. 3*NM1)) ) GO TO 12\nC\nC Initialize iteration count ITER, and initialize SIGMA to\nC zeros.\nC\n ITER = 0\n DO 1 I = 1,NM1\n SIGMA(I) = 0.D0\n 1 CONTINUE\n IF (NCD .EQ. 1) THEN\nC\nC NCD = 1.\nC\n IF (.NOT. PER) THEN\n CALL YPC1 (NN,X,Y, YP,IERR)\n ELSE\n CALL YPC1P (NN,X,Y, YP,IERR)\n ENDIF\n IF (IERR .NE. 0) GO TO 14\nC\nC Compute tension factors.\nC\n CALL SIGBI (NN,X,Y,YP,STOL,B,BMAX, SIGMA, ICFLG,\n . DSMAX,IERR)\n GO TO 10\n ENDIF\nC\nC NCD = 2.\nC\n IF (.NOT. PER) THEN\nC\nC Nonperiodic case: call YPC2 and test for IENDC or X\nC invalid.\nC\n YP1 = YP(1)\n YPN = YP(NN)\n CALL YPC2 (NN,X,Y,SIGMA,IENDC,IENDC,YP1,YPN,\n . WK, YP,IERR)\n IF (IERR .EQ. 1) GO TO 11\n IF (IERR .GT. 1) GO TO 14\n ELSE\nC\nC Periodic fit: call YPC2P.\nC\n CALL YPC2P (NN,X,Y,SIGMA,WK, YP,IERR)\n IF (IERR .GT. 1) GO TO 14\n ENDIF\n LOOP2 = .FALSE.\nC\nC Iterate on calls to SIGBI and YPC2 (or YPC2P). The\nC first N-1 WK locations are used to store the deriva-\nC tive estimates YP from the previous iteration.\nC\nC LOOP2 is TRUE iff tension factors are not allowed to\nC decrease between iterations (loop 1 failed to\nC converge with MAXIT iterations).\nC DYP is the maximum relative change in a component of YP.\nC ICNT is the number of tension factors which were altered\nC by SIGBI.\nC DSMAX is the maximum relative change in a component of\nC SIGMA.\nC\n 2 DO 6 ITER = 1,MAXIT\n DYP = 0.D0\n DO 3 I = 2,NM1\n WK(I) = YP(I)\n 3 CONTINUE\n CALL SIGBI (NN,X,Y,YP,STOL,B,BMAX, SIGMA, ICFLG,\n . DSMAX,ICNT)\n IF (.NOT. PER) THEN\n CALL YPC2 (NN,X,Y,SIGMA,IENDC,IENDC,YP1,YPN,\n . WK(NN), YP,IERR)\n ELSE\n CALL YPC2P (NN,X,Y,SIGMA,WK(NN), YP,IERR)\n ENDIF\n DO 4 I = 2,NM1\n E = ABS(YP(I)-WK(I))\n IF (WK(I) .NE. 0.D0) E = E/ABS(WK(I))\n DYP = MAX(DYP,E)\n 4 CONTINUE\n IF (ICNT .EQ. 0 .OR. DYP .LE. DYPTOL) GO TO 7\n IF (.NOT. LOOP2) THEN\nC\nC Loop 1: reinitialize SIGMA to zeros.\nC\n DO 5 I = 1,NM1\n SIGMA(I) = 0.D0\n 5 CONTINUE\n ENDIF\n 6 CONTINUE\nC\nC The loop failed to converge within MAXIT iterations.\nC\n ITER = MAXIT\n IF (.NOT. LOOP2) THEN\n LOOP2 = .TRUE.\n GO TO 2\n ENDIF\nC\nC Store convergence parameters.\nC\n 7 WK(1) = DYP\n WK(2) = DSMAX\n IF (LOOP2) ITER = ITER + MAXIT\nC\nC No error encountered.\nC\n 10 IER = ITER\n RETURN\nC\nC Invalid input parameter N, NCD, or IENDC.\nC\n 11 IER = -1\n RETURN\nC\nC LWK too small.\nC\n 12 IER = -2\n RETURN\nC\nC Abscissae are not strictly increasing.\nC\n 14 IER = -4\n RETURN\n END\n SUBROUTINE TSPBP (N,X,Y,NCD,IENDC,PER,BL,BU,BMAX,\n . LWK, WK, T,XP,YP,SIGMA,IER)\n INTEGER N, NCD, IENDC, LWK, IER\n LOGICAL PER\n DOUBLE PRECISION X(N), Y(N), BL(N), BU(N), BMAX,\n . WK(LWK), T(N), XP(N), YP(N), SIGMA(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 07/08/92\nC\nC This subroutine computes a set of values which define a\nC parametric planar curve C(t) = (H1(t),H2(t)) whose compo-\nC nents are Hermite interpolatory tension splines. The\nC output values consist of parameters (knots) T computed by\nC ARCL2D, knot derivative values XP and YP computed by Sub-\nC routine YPC1, YPC1P, YPC2, or YPC2P, and tension factors\nC SIGMA chosen (by Subroutine SIGBP) to satisfy user-\nC specified bounds on the distance between C(t) and the\nC polygonal curve associated with the data points (refer to\nC BL and BU below).\nC\nC Refer to Subroutine TSPSP for an alternative method of\nC computing tension factors.\nC\nC The tension splines may be evaluated by Subroutine\nC TSVAL2 or Functions HVAL (values), HPVAL (first deriva-\nC tives), HPPVAL (second derivatives), and TSINTL\nC (integrals).\nC\nC On input:\nC\nC N = Number of knots and data points. N .GE. 2 and\nC N .GE. 3 if PER = TRUE.\nC\nC X,Y = Arrays of length N containing the Cartesian\nC coordinates of an ordered sequence of data\nC points C(I), I = 1 to N, such that C(I) .NE.\nC C(I+1). C(t) is constrained to pass through\nC these points. In the case of a closed curve\nC (PER = TRUE), the first and last points should\nC coincide. (X(N) and Y(N) are set to X(1) and\nC Y(1) if NCD = 1, but not altered if NCD = 2,\nC in this case.)\nC\nC NCD = Number of continuous derivatives at the knots.\nC NCD = 1 or NCD = 2. If NCD = 1, XP and YP are\nC computed by local monotonicity-constrained\nC quadratic fits. Otherwise, a linear system is\nC solved for the derivative values which result\nC in second derivative continuity. This re-\nC quires iterating on calls to YPC2 or YPC2P and\nC calls to SIGBP, and generally results in more\nC nonzero tension factors (hence more expensive\nC evaluation).\nC\nC IENDC = End condition indicator for NCD = 2 and PER\nC = FALSE (or dummy parameter otherwise):\nC IENDC = 0 if XP(1), XP(N), YP(1), and YP(N)\nC are to be computed by monotonicity-\nC constrained parabolic fits (YPC1).\nC IENDC = 1 if the first derivatives of H1 at\nC the left and right endpoints are\nC user-specified in XP(1) and XP(N),\nC respectively, and the first deriv-\nC atives of H2 at the ends are\nC specified in YP(1) and YP(N).\nC IENDC = 2 if the second derivatives of H1\nC and H2 at the endpoints are user-\nC specified in XP(1), XP(N), YP(1),\nC and YP(N).\nC IENDC = 3 if the end conditions are to be\nC computed by Subroutine ENDSLP and\nC vary with SIGMA(1) and SIGMA(N-1).\nC\nC PER = Logical variable with value TRUE if and only\nC a closed curve is to be constructed -- H1(t)\nC and H2(t) are to be periodic functions with\nC period T(N)-T(1), where T(1) and T(N) are the\nC parameter values associated with the first and\nC last data points. It is assumed that X(N) =\nC X(1) and Y(N) = Y(1) in this case, and, on\nC output, XP(N) = XP(1) and YP(N) = YP(1).\nC\nC BL,BU = Arrays of length N-1 containing (for each\nC knot subinterval) lower and upper bounds,\nC respectively, on the signed perpendicular\nC distance d(t) = (C2-C1)/DC X (C(t)-C1),\nC where C1 and C2 are the ordered data points\nC associated with the interval, and DC is the\nC interval length (and length of the line seg-\nC ment C1-C2). Note that d(t) > 0 iff C(t)\nC lies strictly to the left of the line seg-\nC ment as viewed from C1 toward C2. For I =\nC 1 to N-1, SIGMA(I) is chosen to be as small\nC as possible within the constraint that\nC BL(I) .LE. d(t) .LE. BU(I) for all t in the\nC interval. BL(I) < 0 and BU(I) > 0 for I = 1\nC to N-1. A null constraint is specified by\nC BL(I) .LE. -BMAX or BU(I) .GE. BMAX.\nC\nC BMAX = User-defined value of infinity which, when\nC used as an upper bound in BU (or when its\nC negative is used as a lower bound in BL),\nC specifies that no constraint is to be en-\nC forced.\nC\nC LWK = Length of work space WK:\nC LWK GE 3N-3 if NCD = 2 and PER = FALSE\nC LWK GE 4N-4 if NCD = 2 and PER = TRUE\nC\nC The above parameters, except possibly X(N) and Y(N), are\nC not altered by this routine.\nC\nC WK = Array of length .GE. LWK to be used as tempor-\nC ary work space.\nC\nC T = Array of length .GE. N.\nC\nC XP = Array of length .GE. N containing end condition\nC values in positions 1 and N if NCD = 2 and\nC IENDC = 1 or IENDC = 2.\nC\nC YP = Array of length .GE. N containing end condition\nC values in positions 1 and N if NCD = 2 and\nC IENDC = 1 or IENDC = 2.\nC\nC SIGMA = Array of length .GE. N-1.\nC\nC On output:\nC\nC WK = Array containing convergence parameters in the\nC first two locations if IER > 0 (NCD = 2 and\nC no error was encountered):\nC WK(1) = Maximum relative change in a component\nC of XP or YP on the last iteration.\nC WK(2) = Maximum relative change in a component\nC of SIGMA on the last iteration.\nC\nC T = Array containing parameter values computed by\nC Subroutine ARCL2D unless IER = -1 or IER = -2.\nC T is only partially defined if IER = -4.\nC\nC XP = Array containing derivatives of H1 at the\nC knots. XP is not altered if -5 < IER < 0,\nC and XP is only partially defined if IER = -6.\nC\nC YP = Array containing derivatives of H2 at the\nC knots. YP is not altered if -5 < IER < 0,\nC and YP is only partially defined if IER = -6.\nC\nC SIGMA = Array containing tension factors for which\nC C(t) satisfies the constraints defined by\nC BL and BU. SIGMA(I) is associated with\nC interval (T(I),T(I+1)) for I = 1,...,N-1.\nC SIGMA(I) is limited to 85 (in which case\nC C(t) is indistinguishable from the line\nC segment associated with the interval), and\nC if no constraint is specified in the\nC interval, then SIGMA(I) = 0, and thus H1 and\nC H2 are cubic functions of t. SIGMA is not\nC altered if -5 < IER < 0 (unless IENDC in\nC invalid), and SIGMA is the zero vector if\nC IER = -6 or IENDC (if used) is invalid.\nC\nC IER = Error indicator or iteration count:\nC IER = IC .GE. 0 if no errors were encountered\nC and IC calls to SIGBP and IC+1 calls\nC to YPC1, YPC1P, YPC2 or YPC2P were\nC employed. (IC = 0 if NCD = 1).\nC IER = -1 if N, NCD, or IENDC is outside its\nC valid range.\nC IER = -2 if LWK is too small.\nC IER = -4 if a pair of adjacent data points\nC coincide: X(I) = X(I+1) and Y(I) =\nC Y(I+1) for some I in the range 1 to\nC N-1.\nC IER = -5 if BL(I) .GE. 0 or BU(I) .LE. 0 for\nC some I in the range 1 to N-1.\nC SIGMA(J) = 0 for J .GE. I in this\nC case.\nC IER = -6 if invalid knots T were returned by\nC ARCL2D. This should not occur.\nC\nC Modules required by TSPBP: ARCL2D, ENDSLP, SIGBP, SNHCSH,\nC STORE, YPCOEF, YPC1, YPC1P,\nC YPC2, YPC2P\nC\nC Intrinsic functions called by TSPBP: ABS, MAX\nC\nC***********************************************************\nC\n INTEGER I, ICNT, IERR, ITER, MAXIT, N2M1, NM1, NN\n LOGICAL LOOP2\n DOUBLE PRECISION DSMAX, DYP, DYPTOL, EX, EY, STOL,\n . XP1, XPN, YP1, YPN\nC\n DATA STOL/0.D0/, MAXIT/49/, DYPTOL/.01D0/\nC\nC Convergence parameters:\nC\nC STOL = Absolute tolerance for SIGBP.\nC MAXIT = Maximum number of YPC2/SIGBP iterations for each\nC loop in NCD = 2.\nC DYPTOL = Bound on the maximum relative change in a\nC component of XP or YP defining convergence\nC of the YPC2/SIGBP iteration when NCD = 2.\nC\n NN = N\n NM1 = NN - 1\nC\nC Test for invalid input parameters N, NCD, or LWK.\nC\n N2M1 = 2*NN - 1\n IF (NN .LT. 2 .OR. (PER .AND. NN .LT. 3) .OR.\n . NCD .LT. 1 .OR. NCD .GT. 2) GO TO 11\n IF ( NCD .EQ. 2 .AND. (LWK .LT. 3*NM1 .OR.\n . (PER .AND. LWK .LT. 4*NM1)) ) GO TO 12\nC\nC Compute the sequence of parameter values T.\nC\n CALL ARCL2D (NN,X,Y, T,IERR)\n IF (IERR .GT. 0) GO TO 14\nC\nC Initialize iteration count ITER, and initialize SIGMA to\nC zeros.\nC\n ITER = 0\n DO 1 I = 1,NM1\n SIGMA(I) = 0.D0\n 1 CONTINUE\n IF (NCD .EQ. 1) THEN\nC\nC NCD = 1.\nC\n IF (.NOT. PER) THEN\n CALL YPC1 (NN,T,X, XP,IERR)\n CALL YPC1 (NN,T,Y, YP,IERR)\n ELSE\n CALL YPC1P (NN,T,X, XP,IERR)\n CALL YPC1P (NN,T,Y, YP,IERR)\n ENDIF\n IF (IERR .NE. 0) GO TO 16\nC\nC Compute tension factors.\nC\n CALL SIGBP (NN,X,Y,XP,YP,STOL,BL,BU,\n . BMAX, SIGMA, DSMAX,IERR)\n IF (IERR .LT. 0) GO TO 15\n GO TO 10\n ENDIF\nC\nC NCD = 2.\nC\n IF (.NOT. PER) THEN\nC\nC Nonperiodic case: call YPC2 and test for IENDC invalid.\nC\n XP1 = XP(1)\n XPN = XP(NN)\n CALL YPC2 (NN,T,X,SIGMA,IENDC,IENDC,XP1,XPN,\n . WK, XP,IERR)\n YP1 = YP(1)\n YPN = YP(NN)\n CALL YPC2 (NN,T,Y,SIGMA,IENDC,IENDC,YP1,YPN,\n . WK, YP,IERR)\n IF (IERR .EQ. 1) GO TO 11\n IF (IERR .GT. 1) GO TO 16\n ELSE\nC\nC Periodic fit: call YPC2P.\nC\n CALL YPC2P (NN,T,X,SIGMA,WK, XP,IERR)\n CALL YPC2P (NN,T,Y,SIGMA,WK, YP,IERR)\n IF (IERR .NE. 0) GO TO 16\n ENDIF\n LOOP2 = .FALSE.\nC\nC Iterate on calls to SIGBP and YPC2 (or YPC2P). The\nC first 2N-2 WK locations are used to store the deriva-\nC tive estimates XP and YP from the previous iteration.\nC\nC LOOP2 is TRUE iff tension factors are not allowed to\nC decrease between iterations (loop 1 failed to\nC converge with MAXIT iterations).\nC DYP is the maximum relative change in a component of XP\nC or YP.\nC ICNT is the number of tension factors which were altered\nC by SIGBP.\nC DSMAX is the maximum relative change in a component of\nC SIGMA.\nC\n 2 DO 6 ITER = 1,MAXIT\n DYP = 0.D0\n DO 3 I = 2,NM1\n WK(I) = XP(I)\n WK(NM1+I) = YP(I)\n 3 CONTINUE\n CALL SIGBP (NN,X,Y,XP,YP,STOL,BL,BU,\n . BMAX, SIGMA, DSMAX,ICNT)\n IF (ICNT .LT. 0) GO TO 15\n IF (.NOT. PER) THEN\n CALL YPC2 (NN,T,X,SIGMA,IENDC,IENDC,XP1,XPN,\n . WK(N2M1), XP,IERR)\n CALL YPC2 (NN,T,Y,SIGMA,IENDC,IENDC,YP1,YPN,\n . WK(N2M1), YP,IERR)\n ELSE\n CALL YPC2P (NN,T,X,SIGMA,WK(N2M1), XP,IERR)\n CALL YPC2P (NN,T,Y,SIGMA,WK(N2M1), YP,IERR)\n ENDIF\n DO 4 I = 2,NM1\n EX = ABS(XP(I)-WK(I))\n IF (WK(I) .NE. 0.D0) EX = EX/ABS(WK(I))\n EY = ABS(YP(I)-WK(NM1+I))\n IF (WK(NM1+I) .NE. 0.D0) EY = EY/ABS(WK(NM1+I))\n DYP = MAX(DYP,EX,EY)\n 4 CONTINUE\n IF (ICNT .EQ. 0 .OR. DYP .LE. DYPTOL) GO TO 7\n IF (.NOT. LOOP2) THEN\nC\nC Loop 1: reinitialize SIGMA to zeros.\nC\n DO 5 I = 1,NM1\n SIGMA(I) = 0.D0\n 5 CONTINUE\n ENDIF\n 6 CONTINUE\nC\nC The loop failed to converge within MAXIT iterations.\nC\n ITER = MAXIT\n IF (.NOT. LOOP2) THEN\n LOOP2 = .FALSE.\n GO TO 2\n ENDIF\nC\nC Store convergence parameters.\nC\n 7 WK(1) = DYP\n WK(2) = DSMAX\n IF (LOOP2) ITER = ITER + MAXIT\nC\nC No error encountered.\nC\n 10 IER = ITER\n RETURN\nC\nC Invalid input parameter N, NCD, or IENDC.\nC\n 11 IER = -1\n RETURN\nC\nC LWK too small.\nC\n 12 IER = -2\n RETURN\nC\nC Adjacent duplicate data points encountered.\nC\n 14 IER = -4\n RETURN\nC\nC Invalid constraint encountered by SIGBP.\nC\n 15 IER = -5\n RETURN\nC\nC Error flag returned by YPC1, YPC1P, YPC2, or YPC2P:\nC T is not strictly increasing.\nC\n 16 IER = -6\n RETURN\n END\n SUBROUTINE TSPSI (N,X,Y,NCD,IENDC,PER,UNIFRM,LWK, WK,\n . YP,SIGMA, IER)\n INTEGER N, NCD, IENDC, LWK, IER\n LOGICAL PER, UNIFRM\n DOUBLE PRECISION X(N), Y(N), WK(LWK), YP(N), SIGMA(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 07/08/92\nC\nC This subroutine computes a set of parameter values which\nC define a Hermite interpolatory tension spline H(x). The\nC parameters consist of knot derivative values YP computed\nC by Subroutine YPC1, YPC1P, YPC2, or YPC2P, and tension\nC factors SIGMA computed by Subroutine SIGS (unless UNIFRM =\nC TRUE). Alternative methods for computing SIGMA are pro-\nC vided by Subroutine TSPBI and Functions SIG0, SIG1, and\nC SIG2.\nC\nC Refer to Subroutine TSPSS for a means of computing\nC parameters which define a smoothing curve rather than an\nC interpolatory curve.\nC\nC The tension spline may be evaluated by Subroutine TSVAL1\nC or Functions HVAL (values), HPVAL (first derivatives),\nC HPPVAL (second derivatives), and TSINTL (integrals).\nC\nC On input:\nC\nC N = Number of data points. N .GE. 2 and N .GE. 3 if\nC PER = TRUE.\nC\nC X = Array of length N containing a strictly in-\nC creasing sequence of abscissae: X(I) < X(I+1)\nC for I = 1,...,N-1.\nC\nC Y = Array of length N containing data values asso-\nC ciated with the abscissae. H(X(I)) = Y(I) for\nC I = 1,...,N. If NCD = 1 and PER = TRUE, Y(N)\nC is set to Y(1).\nC\nC NCD = Number of continuous derivatives at the knots.\nC NCD = 1 or NCD = 2. If NCD = 1, the YP values\nC are computed by local monotonicity-constrained\nC quadratic fits. Otherwise, a linear system is\nC solved for the derivative values which result\nC in second derivative continuity. Unless\nC UNIFRM = TRUE, this requires iterating on\nC calls to YPC2 or YPC2P and calls to SIGS, and\nC generally results in more nonzero tension\nC factors (hence more expensive evaluation).\nC\nC IENDC = End condition indicator for NCD = 2 and PER\nC = FALSE (or dummy parameter otherwise):\nC IENDC = 0 if YP(1) and YP(N) are to be com-\nC puted by monotonicity-constrained\nC parabolic fits to the first three\nC and last three points, respective-\nC ly. This is identical to the\nC values computed by YPC1.\nC IENDC = 1 if the first derivatives of H at\nC X(1) and X(N) are user-specified\nC in YP(1) and YP(N), respectively.\nC IENDC = 2 if the second derivatives of H at\nC X(1) and X(N) are user-specified\nC in YP(1) and YP(N), respectively.\nC IENDC = 3 if the end conditions are to be\nC computed by Subroutine ENDSLP and\nC vary with SIGMA(1) and SIGMA(N-1).\nC\nC PER = Logical variable with value TRUE if and only\nC H(x) is to be a periodic function with period\nC X(N)-X(1). It is assumed without a test that\nC Y(N) = Y(1) in this case. On output, YP(N) =\nC YP(1). If H(x) is one of the components of a\nC parametric curve, this option may be used to\nC obtained a closed curve.\nC\nC UNIFRM = Logical variable with value TRUE if and\nC only if constant (uniform) tension is to be\nC used. The tension factor must be input in\nC SIGMA(1) in this case and must be in the\nC range 0 to 85. If SIGMA(1) = 0, H(x) is\nC piecewise cubic (a cubic spline if NCD =\nC 2), and as SIGMA increases, H(x) approaches\nC the piecewise linear interpolant. If\nC UNIFRM = FALSE, tension factors are chosen\nC (by SIGS) to preserve local monotonicity\nC and convexity of the data. This often\nC improves the appearance of the curve over\nC the piecewise cubic fit.\nC\nC LWK = Length of work space WK: no work space is\nC needed if NCD = 1; at least N-1 locations\nC are required if NCD = 2; another N-1 locations\nC are required if PER = TRUE; and an additional\nC N-1 locations are required for the convergence\nC test if SIGS is called (UNIFRM = FALSE):\nC\nC LWK GE 0 if NCD=1\nC LWK GE N-1 if NCD=2, PER=FALSE, UNIFRM=TRUE\nC LWK GE 2N-2 if NCD=2, PER=TRUE, UNIFRM=TRUE\nC LWK GE 2N-2 if NCD=2, PER=FALSE, UNIFRM=FALSE\nC LWK GE 3N-3 if NCD=2, PER=TRUE, UNIFRM=FALSE\nC\nC The above parameters, except possibly Y(N), are not\nC altered by this routine.\nC\nC WK = Array of length at least LWK to be used as\nC temporary work space.\nC\nC YP = Array of length .GE. N containing end condition\nC values in positions 1 and N if NCD = 2 and\nC IENDC = 1 or IENDC = 2.\nC\nC SIGMA = Array of length .GE. N-1 containing a ten-\nC sion factor (0 to 85) in the first position\nC if UNIFRM = TRUE.\nC\nC On output:\nC\nC WK = Array containing convergence parameters in the\nC first two locations if IER > 0 (NCD = 2 and\nC UNIFRM = FALSE):\nC WK(1) = Maximum relative change in a component\nC of YP on the last iteration.\nC WK(2) = Maximum relative change in a component\nC of SIGMA on the last iteration.\nC\nC YP = Array containing derivatives of H at the\nC abscissae. YP is not altered if -4 < IER < 0,\nC and YP is only partially defined if IER = -4.\nC\nC SIGMA = Array containing tension factors. SIGMA(I)\nC is associated with interval (X(I),X(I+1))\nC for I = 1,...,N-1. SIGMA is not altered if\nC -4 < IER < 0 (unless IENDC is invalid), and\nC SIGMA is constant (not optimal) if IER = -4\nC or IENDC (if used) is invalid.\nC\nC IER = Error indicator or iteration count:\nC IER = IC .GE. 0 if no errors were encountered\nC and IC calls to SIGS and IC+1 calls\nC to YPC1, YPC1P, YPC2 or YPC2P were\nC employed. (IC = 0 if NCD = 1).\nC IER = -1 if N, NCD, or IENDC is outside its\nC valid range.\nC IER = -2 if LWK is too small.\nC IER = -3 if UNIFRM = TRUE and SIGMA(1) is out-\nC side its valid range.\nC IER = -4 if the abscissae X are not strictly\nC increasing.\nC\nC Modules required by TSPSI: ENDSLP, SIGS, SNHCSH, STORE,\nC YPCOEF, YPC1, YPC1P, YPC2,\nC YPC2P\nC\nC Intrinsic functions called by TSPSI: ABS, MAX\nC\nC***********************************************************\nC\n INTEGER I, ICNT, IERR, ITER, MAXIT, NM1, NN\n DOUBLE PRECISION DSMAX, DYP, DYPTOL, E, SBIG, SIG,\n . STOL, YP1, YPN\nC\n DATA SBIG/85.D0/\nC\nC Convergence parameters:\nC\nC STOL = Absolute tolerance for SIGS\nC MAXIT = Maximum number of YPC2/SIGS iterations\nC DYPTOL = Bound on the maximum relative change in a\nC component of YP defining convergence of\nC the YPC2/SIGS iteration when NCD = 2 and\nC UNIFRM = FALSE\nC\n DATA STOL/0.D0/, MAXIT/99/, DYPTOL/.01D0/\nC\nC Test for invalid input parameters (other than X and\nC IENDC).\nC\n NN = N\n NM1 = NN - 1\n IF (NN .LT. 2 .OR. (PER .AND. NN .LT. 3) .OR.\n . NCD .LT. 1 .OR. NCD .GT. 2) GO TO 11\n IF (UNIFRM) THEN\n IF ( NCD .EQ. 2 .AND. (LWK .LT. NM1 .OR.\n . (PER .AND. LWK .LT. 2*NM1)) ) GO TO 12\n SIG = SIGMA(1)\n IF (SIG .LT. 0.D0 .OR. SIG .GT. SBIG) GO TO 13\n ELSE\n IF ( NCD .EQ. 2 .AND. (LWK .LT. 2*NM1 .OR.\n . (PER .AND. LWK .LT. 3*NM1)) ) GO TO 12\n SIG = 0.D0\n ENDIF\nC\nC Initialize iteration count ITER, and store uniform\nC tension factors, or initialize SIGMA to zeros.\nC\n ITER = 0\n DO 1 I = 1,NM1\n SIGMA(I) = SIG\n 1 CONTINUE\n IF (NCD .EQ. 1) THEN\nC\nC NCD = 1.\nC\n IF (.NOT. PER) THEN\n CALL YPC1 (NN,X,Y, YP,IERR)\n ELSE\n CALL YPC1P (NN,X,Y, YP,IERR)\n ENDIF\n IF (IERR .NE. 0) GO TO 14\n IF (.NOT. UNIFRM) THEN\nC\nC Call SIGS for UNIFRM = FALSE.\nC\n CALL SIGS (NN,X,Y,YP,STOL, SIGMA, DSMAX,IERR)\n ENDIF\n GO TO 10\n ENDIF\nC\nC NCD = 2.\nC\n IF (.NOT. PER) THEN\nC\nC Nonperiodic case: call YPC2 and test for IENDC or X\nC invalid.\nC\n YP1 = YP(1)\n YPN = YP(NN)\n CALL YPC2 (NN,X,Y,SIGMA,IENDC,IENDC,YP1,YPN,\n . WK, YP,IERR)\n IF (IERR .EQ. 1) GO TO 11\n IF (IERR .GT. 1) GO TO 14\n ELSE\nC\nC Periodic fit: call YPC2P.\nC\n CALL YPC2P (NN,X,Y,SIGMA,WK, YP,IERR)\n IF (IERR .GT. 1) GO TO 14\n ENDIF\n IF (UNIFRM) GO TO 10\nC\nC Iterate on calls to SIGS and YPC2 (or YPC2P). The first\nC N-1 WK locations are used to store the derivative\nC estimates YP from the previous iteration.\nC\nC DYP is the maximum relative change in a component of YP.\nC ICNT is the number of tension factors which were\nC increased by SIGS.\nC DSMAX is the maximum relative change in a component of\nC SIGMA.\nC\n DO 4 ITER = 1,MAXIT\n DYP = 0.D0\n DO 2 I = 2,NM1\n WK(I) = YP(I)\n 2 CONTINUE\n CALL SIGS (NN,X,Y,YP,STOL, SIGMA, DSMAX,ICNT)\n IF (.NOT. PER) THEN\n CALL YPC2 (NN,X,Y,SIGMA,IENDC,IENDC,YP1,YPN,\n . WK(NN), YP,IERR)\n ELSE\n CALL YPC2P (NN,X,Y,SIGMA,WK(NN), YP,IERR)\n ENDIF\n DO 3 I = 2,NM1\n E = ABS(YP(I)-WK(I))\n IF (WK(I) .NE. 0.D0) E = E/ABS(WK(I))\n DYP = MAX(DYP,E)\n 3 CONTINUE\n IF (ICNT .EQ. 0 .OR. DYP .LE. DYPTOL) GO TO 5\n 4 CONTINUE\n ITER = MAXIT\nC\nC Store convergence parameters in WK.\nC\n 5 WK(1) = DYP\n WK(2) = DSMAX\nC\nC No error encountered.\nC\n 10 IER = ITER\n RETURN\nC\nC Invalid input parameter N, NCD, or IENDC.\nC\n 11 IER = -1\n RETURN\nC\nC LWK too small.\nC\n 12 IER = -2\n RETURN\nC\nC UNIFRM = TRUE and SIGMA(1) outside its valid range.\nC\n 13 IER = -3\n RETURN\nC\nC Abscissae are not strictly increasing.\nC\n 14 IER = -4\n RETURN\n END\n SUBROUTINE TSPSP (N,ND,X,Y,Z,NCD,IENDC,PER,UNIFRM,\n . LWK, WK, T,XP,YP,ZP,SIGMA,IER)\n INTEGER N, ND, NCD, IENDC, LWK, IER\n LOGICAL PER, UNIFRM\n DOUBLE PRECISION X(N), Y(N), Z(N), WK(LWK), T(N),\n . XP(N), YP(N), ZP(N), SIGMA(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 07/08/92\nC\nC This subroutine computes a set of values which define a\nC parametric planar curve C(t) = (H1(t),H2(t)) or space\nC curve C(t) = (H1(t),H2(t),H3(t)) whose components are Her-\nC mite interpolatory tension splines. The output values\nC consist of parameters (knots) T computed by ARCL2D or\nC ARCL3D, knot derivative values XP, YP, (and ZP) computed\nC by Subroutine YPC1, YPC1P, YPC2, or YPC2P, and tension\nC factors SIGMA computed by Subroutine SIGS (unless UNIFRM =\nC TRUE).\nC\nC Refer to Subroutine TSPSP for an alternative method of\nC computing tension factors in the case of a planar curve.\nC\nC The tension splines may be evaluated by Subroutine\nC TSVAL2 (or TSVAL3) or Functions HVAL (values), HPVAL\nC (first derivatives), HPPVAL (second derivatives), and\nC TSINTL (integrals).\nC\nC On input:\nC\nC N = Number of knots and data points. N .GE. 2 and\nC N .GE. 3 if PER = TRUE.\nC\nC ND = Number of dimensions:\nC ND = 2 if a planar curve is to be constructed.\nC ND = 3 if a space curve is to be constructed.\nC\nC X,Y,Z = Arrays of length N containing the Cartesian\nC coordinates of an ordered sequence of data\nC points C(I), I = 1 to N, such that C(I) .NE.\nC C(I+1). C(t) is constrained to pass through\nC these points. Z is an unused dummy parame-\nC ter if ND = 2. In the case of a closed curve\nC (PER = TRUE), the first and last points\nC should coincide. In this case, X(N), Y(N),\nC (and Z(N)) are set to X(1), Y(1), (and Z(1))\nC if NCD = 1, but not altered if NCD = 2.\nC\nC NCD = Number of continuous derivatives at the knots.\nC NCD = 1 or NCD = 2. If NCD = 1, XP, YP, (and\nC ZP) are computed by local monotonicity-\nC constrained quadratic fits. Otherwise, a\nC linear system is solved for the derivative\nC values which result in second derivative con-\nC tinuity. Unless UNIFRM = FALSE, this requires\nC iterating on calls to YPC2 or YPC2P and calls\nC to SIGS, and generally results in more nonzero\nC tension factors (hence more expensive evalua-\nC tion).\nC\nC IENDC = End condition indicator for NCD = 2 and PER\nC = FALSE (or dummy parameter otherwise):\nC IENDC = 0 if XP(1), XP(N), YP(1), YP(N) (and\nC ZP(1) and ZP(N)) are to be com-\nC puted by monotonicity-constrained\nC parabolic fits (YPC1).\nC IENDC = 1 if the first derivatives of H1 at\nC the left and right endpoints are\nC user-specified in XP(1) and XP(N),\nC respectively, the first deriva-\nC tives of H2 at the ends are\nC specified in YP(1) and YP(N), and,\nC if ND = 3, the first derivatives\nC of H3 are specified in ZP(1) and\nC ZP(N).\nC IENDC = 2 if the second derivatives of H1,\nC H2, (and H3) at the endpoints are\nC user-specified in XP(1), XP(N),\nC YP(1), YP(N), (ZP(1), and ZP(N)).\nC IENDC = 3 if the end conditions are to be\nC computed by Subroutine ENDSLP and\nC vary with SIGMA(1) and SIGMA(N-1).\nC\nC PER = Logical variable with value TRUE if and only\nC a closed curve is to be constructed -- H1(t),\nC H2(t), (and H3(t)) are to be periodic func-\nC tions with period T(N)-T(1), where T(1) and\nC T(N) are the parameter values associated with\nC the first and last data points. It is assumed\nC in this case that X(N) = X(1), Y(N) = Y(1)\nC and, if ND = 3, Z(N) = Z(1), and, on output,\nC XP(N) = XP(1), YP(N) = YP(1), (and ZP(N) =\nC ZP(1) if ND = 3).\nC\nC UNIFRM = Logical variable with value TRUE if and\nC only if constant (uniform) tension is to be\nC used. The tension factor must be input in\nC SIGMA(1) in this case and must be in the\nC range 0 to 85. If SIGMA(1) = 0, H(t) is\nC piecewise cubic (a cubic spline if NCD =\nC 2), and as SIGMA increases, H(t) approaches\nC the piecewise linear interpolant, where H\nC is H1, H2, or H3. If UNIFRM = FALSE,\nC tension factors are chosen (by SIGS) to\nC preserve local monotonicity and convexity\nC of the data. This often improves the\nC appearance of the curve over the piecewise\nC cubic fitting functions.\nC\nC LWK = Length of work space WK: no work space is\nC needed if NCD = 1; at least N-1 locations\nC are required if NCD = 2; another N-1 locations\nC are required if PER = TRUE; and an additional\nC ND*(N-1) locations are required for the con-\nC vergence test if SIGS is called (UNIFRM =\nC FALSE):\nC If NCD=1 then LWK = 0 (not tested).\nC If NCD=2 then\nC\nC LWK GE N-1 if PER=FALSE, UNIFRM=TRUE\nC LWK GE 2N-2 if PER=TRUE, UNIFRM=TRUE\nC LWK GE (ND+1)*(N-1) if PER=FALSE, UNIFRM=FALSE\nC LWK GE (ND+2)*(N-1) if PER=TRUE, UNIFRM=FALSE\nC\nC The above parameters, except possibly X(N), Y(N), and\nC Z(N), are not altered by this routine.\nC\nC WK = Array of length .GE. LWK to be used as tempor-\nC ary work space.\nC\nC T = Array of length .GE. N.\nC\nC XP = Array of length .GE. N containing end condition\nC values in positions 1 and N if NCD = 2 and\nC IENDC = 1 or IENDC = 2.\nC\nC YP = Array of length .GE. N containing end condition\nC values in positions 1 and N if NCD = 2 and\nC IENDC = 1 or IENDC = 2.\nC\nC ZP = Dummy argument if ND=2, or, if ND=3, array of\nC length .GE. N containing end condition values\nC in positions 1 and N if NCD = 2 and IENDC = 1\nC or IENDC = 2.\nC\nC SIGMA = Array of length .GE. N-1 containing a ten-\nC sion factor (0 to 85) in the first position\nC if UNIFRM = TRUE.\nC\nC On output:\nC\nC WK = Array containing convergence parameters in the\nC first two locations if IER > 0 (NCD = 2 and\nC UNIFRM = FALSE):\nC WK(1) = Maximum relative change in a component\nC of XP, YP, or ZP on the last iteration.\nC WK(2) = Maximum relative change in a component\nC of SIGMA on the last iteration.\nC\nC T = Array containing parameter values computed by\nC Subroutine ARCL2D or ARCL3D unless -4 < IER < 0.\nC T is only partially defined if IER = -4.\nC\nC XP = Array containing derivatives of H1 at the\nC knots. XP is not altered if -5 < IER < 0,\nC and XP is only partially defined if IER = -6.\nC\nC YP = Array containing derivatives of H2 at the\nC knots. YP is not altered if -5 < IER < 0,\nC and YP is only partially defined if IER = -6.\nC\nC ZP = Array containing derivatives of H3 at the knots\nC if ND=3. ZP is not altered if -5 < IER < 0,\nC and ZP is only partially defined if IER = -6.\nC\nC SIGMA = Array containing tension factors. SIGMA(I)\nC is associated with interval (T(I),T(I+1))\nC for I = 1,...,N-1. SIGMA is not altered if\nC -5 < IER < 0 (unless IENDC is invalid), and\nC SIGMA is constant (not optimal) if IER = -6\nC or IENDC (if used) is invalid.\nC\nC IER = Error indicator or iteration count:\nC IER = IC .GE. 0 if no errors were encountered\nC and IC calls to SIGS and IC+1 calls\nC to YPC1, YPC1P, YPC2 or YPC2P were\nC employed. (IC = 0 if NCD = 1).\nC IER = -1 if N, NCD, or IENDC is outside its\nC valid range.\nC IER = -2 if LWK is too small.\nC IER = -3 if UNIFRM = TRUE and SIGMA(1) is out-\nC side its valid range.\nC IER = -4 if a pair of adjacent data points\nC coincide: X(I) = X(I+1), Y(I) =\nC Y(I+1), (and Z(I) = Z(I+1)) for some\nC I in the range 1 to N-1.\nC IER = -6 if invalid knots T were returned by\nC ARCL2D or ARCL3D. This should not\nC occur.\nC\nC Modules required by TSPSP: ARCL2D, ARCL3D, ENDSLP, SIGS,\nC SNHCSH, STORE, YPCOEF, YPC1,\nC YPC1P, YPC2, YPC2P\nC\nC Intrinsic functions called by TSPSP: ABS, MAX\nC\nC***********************************************************\nC\n INTEGER I, ICNT, IERR, ITER, IW1, MAXIT, N2M2, NM1, NN\n LOGICAL SCURV\n DOUBLE PRECISION DSMAX, DYP, DYPTOL, EX, EY, EZ, SBIG,\n . SIG, STOL, XP1, XPN, YP1, YPN, ZP1,\n . ZPN\nC\n DATA SBIG/85.D0/\nC\nC Convergence parameters:\nC\nC STOL = Absolute tolerance for SIGS\nC MAXIT = Maximum number of YPC2/SIGS iterations\nC DYPTOL = Bound on the maximum relative change in a com-\nC ponent of XP, YP, or ZP defining convergence\nC of the YPC2/SIGS iteration when NCD = 2 and\nC UNIFRM = FALSE\nC\n DATA STOL/0.D0/, MAXIT/99/, DYPTOL/.01D0/\nC\nC Test for invalid input parameters N, NCD, or LWK.\nC\n NN = N\n NM1 = NN - 1\n N2M2 = 2*NM1\n IF (NN .LT. 2 .OR. (PER .AND. NN .LT. 3) .OR.\n . NCD .LT. 1 .OR. NCD .GT. 2) GO TO 11\n IF (UNIFRM) THEN\n IF ( NCD .EQ. 2 .AND. (LWK .LT. NM1 .OR.\n . (PER .AND. LWK .LT. N2M2)) ) GO TO 12\n SIG = SIGMA(1)\n IF (SIG .LT. 0.D0 .OR. SIG .GT. SBIG) GO TO 13\n ELSE\n IF ( NCD .EQ. 2 .AND. (LWK .LT. (ND+1)*NM1 .OR.\n . (PER .AND. LWK .LT. (ND+2)*NM1)) ) GO TO 12\n SIG = 0.D0\n ENDIF\nC\nC Compute the sequence of parameter values T.\nC\n SCURV = ND .EQ. 3\n IF (.NOT. SCURV) THEN\n CALL ARCL2D (NN,X,Y, T,IERR)\n ELSE\n CALL ARCL3D (NN,X,Y,Z, T,IERR)\n ENDIF\n IF (IERR .GT. 0) GO TO 14\nC\nC Initialize iteration count ITER, and store uniform\nC tension factors, or initialize SIGMA to zeros.\nC\n ITER = 0\n DO 1 I = 1,NM1\n SIGMA(I) = SIG\n 1 CONTINUE\n IF (NCD .EQ. 1) THEN\nC\nC NCD = 1.\nC\n IF (.NOT. PER) THEN\n CALL YPC1 (NN,T,X, XP,IERR)\n CALL YPC1 (NN,T,Y, YP,IERR)\n IF (SCURV) CALL YPC1 (NN,T,Z, ZP,IERR)\n ELSE\n CALL YPC1P (NN,T,X, XP,IERR)\n CALL YPC1P (NN,T,Y, YP,IERR)\n IF (SCURV) CALL YPC1P (NN,T,Z, ZP,IERR)\n ENDIF\n IF (IERR .NE. 0) GO TO 16\n IF (.NOT. UNIFRM) THEN\nC\nC Call SIGS for UNIFRM = FALSE.\nC\n CALL SIGS (NN,T,X,XP,STOL, SIGMA, DSMAX,IERR)\n CALL SIGS (NN,T,Y,YP,STOL, SIGMA, DSMAX,IERR)\n IF (SCURV) CALL SIGS (NN,T,Z,ZP,STOL, SIGMA,\n . DSMAX,IERR)\n ENDIF\n GO TO 10\n ENDIF\nC\nC NCD = 2.\nC\n IF (.NOT. PER) THEN\nC\nC Nonperiodic case: call YPC2 and test for IENDC invalid.\nC\n XP1 = XP(1)\n XPN = XP(NN)\n CALL YPC2 (NN,T,X,SIGMA,IENDC,IENDC,XP1,XPN,\n . WK, XP,IERR)\n YP1 = YP(1)\n YPN = YP(NN)\n CALL YPC2 (NN,T,Y,SIGMA,IENDC,IENDC,YP1,YPN,\n . WK, YP,IERR)\n IF (SCURV) THEN\n ZP1 = ZP(1)\n ZPN = ZP(NN)\n CALL YPC2 (NN,T,Z,SIGMA,IENDC,IENDC,ZP1,ZPN,\n . WK, ZP,IERR)\n ENDIF\n IF (IERR .EQ. 1) GO TO 11\n IF (IERR .GT. 1) GO TO 16\n ELSE\nC\nC Periodic fit: call YPC2P.\nC\n CALL YPC2P (NN,T,X,SIGMA,WK, XP,IERR)\n CALL YPC2P (NN,T,Y,SIGMA,WK, YP,IERR)\n IF (SCURV) CALL YPC2P (NN,T,Z,SIGMA,WK, ZP,IERR)\n IF (IERR .NE. 0) GO TO 16\n ENDIF\n IF (UNIFRM) GO TO 10\nC\nC Iterate on calls to SIGS and YPC2 (or YPC2P). The\nC first ND*(N-1) WK locations are used to store the\nC derivative estimates XP, YP, (and ZP) from the\nC previous iteration. IW1 is the first free WK location\nC following the stored derivatives.\nC\nC DYP is the maximum relative change in a component of XP,\nC YP, or ZP.\nC ICNT is the number of tension factors which were\nC increased by SIGS.\nC DSMAX is the maximum relative change in a component of\nC SIGMA.\nC\n IW1 = ND*NM1 + 1\n DO 5 ITER = 1,MAXIT\n DYP = 0.D0\n DO 2 I = 2,NM1\n WK(I) = XP(I)\n WK(NM1+I) = YP(I)\n 2 CONTINUE\n IF (SCURV) THEN\n DO 3 I = 2,NM1\n WK(N2M2+I) = ZP(I)\n 3 CONTINUE\n ENDIF\n CALL SIGS (NN,T,X,XP,STOL, SIGMA, DSMAX,ICNT)\n CALL SIGS (NN,T,Y,YP,STOL, SIGMA, DSMAX,ICNT)\n IF (SCURV) CALL SIGS (NN,T,Z,ZP,STOL, SIGMA, DSMAX,\n . ICNT)\n IF (.NOT. PER) THEN\n CALL YPC2 (NN,T,X,SIGMA,IENDC,IENDC,XP1,XPN,\n . WK(IW1), XP,IERR)\n CALL YPC2 (NN,T,Y,SIGMA,IENDC,IENDC,YP1,YPN,\n . WK(IW1), YP,IERR)\n IF (SCURV) CALL YPC2 (NN,T,Z,SIGMA,IENDC,IENDC,\n . ZP1,ZPN,WK(IW1), ZP,IERR)\n ELSE\n CALL YPC2P (NN,T,X,SIGMA,WK(IW1), XP,IERR)\n CALL YPC2P (NN,T,Y,SIGMA,WK(IW1), YP,IERR)\n IF (SCURV) CALL YPC2P (NN,T,Z,SIGMA,WK(IW1), ZP,\n . IERR)\n ENDIF\n EZ = 0.D0\n DO 4 I = 2,NM1\n EX = ABS(XP(I)-WK(I))\n IF (WK(I) .NE. 0.D0) EX = EX/ABS(WK(I))\n EY = ABS(YP(I)-WK(NM1+I))\n IF (WK(NM1+I) .NE. 0.D0) EY = EY/ABS(WK(NM1+I))\n IF (SCURV) THEN\n EZ = ABS(ZP(I)-WK(N2M2+I))\n IF (WK(N2M2+I) .NE. 0.D0)\n . EZ = EZ/ABS(WK(N2M2+I))\n ENDIF\n DYP = MAX(DYP,EX,EY,EZ)\n 4 CONTINUE\n IF (ICNT .EQ. 0 .OR. DYP .LE. DYPTOL) GO TO 6\n 5 CONTINUE\n ITER = MAXIT\nC\nC Store convergence parameters in WK.\nC\n 6 WK(1) = DYP\n WK(2) = DSMAX\nC\nC No error encountered.\nC\n 10 IER = ITER\n RETURN\nC\nC Invalid input parameter N, NCD, or IENDC.\nC\n 11 IER = -1\n RETURN\nC\nC LWK too small.\nC\n 12 IER = -2\n RETURN\nC\nC UNIFRM = TRUE and SIGMA(1) outside its valid range.\nC\n 13 IER = -3\n RETURN\nC\nC Adjacent duplicate data points encountered.\nC\n 14 IER = -4\n RETURN\nC\nC Error flag returned by YPC1, YPC1P, YPC2, or YPC2P:\nC T is not strictly increasing.\nC\n 16 IER = -6\n RETURN\n END\n SUBROUTINE TSPSS (N,X,Y,PER,UNIFRM,W,SM,SMTOL,LWK, WK,\n . SIGMA,YS,YP, NIT,IER)\n INTEGER N, LWK, NIT, IER\n LOGICAL PER, UNIFRM\n DOUBLE PRECISION X(N), Y(N), W(N), SM, SMTOL, WK(LWK),\n . SIGMA(N), YS(N), YP(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 06/10/92\nC\nC This subroutine computes a set of parameter values which\nC define a smoothing tension spline H(x). The parameters\nC consist of knot values YS and derivatives YP computed\nC by Subroutine SMCRV, and tension factors SIGMA computed by\nC Subroutine SIGS (unless UNIFRM = TRUE). The Hermite\nC interpolatory tension spline H(x) defined by the knot\nC values and derivatives has two continuous derivatives and\nC satisfies either natural or periodic end conditions.\nC\nC The tension spline may be evaluated by Subroutine TSVAL1\nC or Functions HVAL (values), HPVAL (first derivatives),\nC HPPVAL (second derivatives), and TSINTL (integrals).\nC\nC On input:\nC\nC N = Number of data points. N .GE. 2 and N .GE. 3 if\nC PER = TRUE.\nC\nC X = Array of length N containing a strictly in-\nC creasing sequence of abscissae: X(I) < X(I+1)\nC for I = 1,...,N-1.\nC\nC Y = Array of length N containing data values asso-\nC ciated with the abscissae. If PER = TRUE, it is\nC assumed that Y(N) = Y(1).\nC\nC PER = Logical variable with value TRUE if and only\nC H(x) is to be a periodic function with period\nC X(N)-X(1). It is assumed without a test that\nC Y(N) = Y(1) in this case. On output, YP(N) =\nC YP(1) and, more generally, the values and\nC first two derivatives of H at X(1) agree with\nC those at X(N). If H(x) is one of the compo-\nC nents of a parametric curve, this option may\nC be used to obtained a closed curve. If PER =\nC FALSE, H satisfies natural end conditions:\nC zero second derivatives at X(1) and X(N).\nC\nC UNIFRM = Logical variable with value TRUE if and\nC only if constant (uniform) tension is to be\nC used. The tension factor must be input in\nC SIGMA(1) in this case and must be in the\nC range 0 to 85. If SIGMA(1) = 0, H(x) is\nC a cubic spline, and as SIGMA increases,\nC H(x) approaches piecewise linear. If\nC UNIFRM = FALSE, tension factors are chosen\nC (by SIGS) to preserve local monotonicity\nC and convexity of the data. This may re-\nC sult in a better fit than the case of\nC uniform tension, but requires an iteration\nC on calls to SMCRV and SIGS.\nC\nC W = Array of length N containing positive weights\nC associated with the data values. The recommend-\nC ed value of W(I) is 1/DY**2, where DY is the\nC standard deviation associated with Y(I). If\nC nothing is known about the errors in Y, a con-\nC stant (estimated value) should be used for DY.\nC If PER = TRUE, it is assumed that W(N) = W(1).\nC\nC SM = Positive parameter specifying an upper bound on\nC Q2(YS), where Q2(YS) is the weighted sum of\nC squares of deviations from the data (differ-\nC ences between YS and Y). H(x) is linear (and\nC Q2 is minimized) if SM is sufficiently large\nC that the constraint is not active. It is\nC recommended that SM satisfy N-SQRT(2N) .LE. SM\nC .LE. N+SQRT(2N) and SM = N is reasonable if\nC W(I) = 1/DY**2.\nC\nC SMTOL = Parameter in the range (0,1) specifying the\nC relative error allowed in satisfying the\nC constraint: the constraint is assumed to\nC be satisfied if SM*(1-SMTOL) .LE. Q2 .LE.\nC SM*(1+SMTOL). A reasonable value for SMTOL\nC is SQRT(2/N).\nC\nC LWK = Length of work space WK:\nC LWK .GE. 6N if PER=FALSE and UNIFRM=TRUE\nC LWK .GE. 7N if PER=FALSE and UNIFRM=FALSE\nC LWK .GE. 10N if PER=TRUE and UNIFRM=TRUE\nC LWK .GE. 11N if PER=TRUE and UNIFRM=FALSE\nC\nC The above parameters are not altered by this routine.\nC\nC WK = Array of length at least LWK to be used as\nC temporary work space.\nC\nC SIGMA = Array of length .GE. N-1 containing a ten-\nC sion factor (0 to 85) in the first position\nC if UNIFRM = TRUE.\nC\nC YS = Array of length .GE. N.\nC\nC YP = Array of length .GE. N.\nC\nC On output:\nC\nC WK = Array containing convergence parameters in the\nC first two locations if NIT > 0:\nC WK(1) = Maximum relative change in a component\nC of YS on the last iteration.\nC WK(2) = Maximum relative change in a component\nC of SIGMA on the last iteration.\nC\nC SIGMA = Array containing tension factors. SIGMA(I)\nC is associated with interval (X(I),X(I+1))\nC for I = 1,...,N-1. SIGMA is not altered if\nC N is invalid or -4 < IER < -1, and SIGMA is\nC constant if IER = -1 (and N is valid) or\nC IER = -4.\nC\nC YS = Array of length N containing values of H at the\nC abscissae. YS(N) = YS(1) if PER = TRUE. YS is\nC not altered if IER < 0.\nC\nC YP = Array of length N containing first derivative\nC values of H at the abscissae. YP(N) = YP(1)\nC if PER = TRUE. YP is not altered if IER < 0.\nC\nC NIT = Number of iterations (calls to SIGS). NIT = 0\nC if IER < 0 or UNIFRM = TRUE. If NIT > 0,\nC NIT+1 calls to SMCRV were employed.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered and the\nC constraint is active: Q2(YS) is ap-\nC proximately equal to SM.\nC IER = 1 if no errors were encountered but the\nC constraint is not active: YS and YP\nC are the values and derivatives of the\nC linear function (constant function if\nC PERIOD = TRUE) which minimizes Q2, and\nC Q1 = 0 (refer to SMCRV).\nC IER = -1 if N, W, SM, or SMTOL is outside its\nC valid range.\nC IER = -2 if LWK is too small.\nC IER = -3 if UNIFRM = TRUE and SIGMA(1) is out-\nC side its valid range.\nC IER = -4 if the abscissae X are not strictly\nC increasing.\nC\nC Modules required by TSPSS: B2TRI or B2TRIP, SIGS, SMCRV,\nC SNHCSH, STORE, YPCOEF\nC\nC Intrinsic functions called by TSPSS: ABS, MAX\nC\nC***********************************************************\nC\n INTEGER I, ICNT, IERR, ITER, MAXIT, NM1, NN\n DOUBLE PRECISION DSMAX, DYS, DYSTOL, E, SBIG, SIG,\n . STOL\nC\n DATA SBIG/85.D0/\nC\nC Convergence parameters:\nC\nC STOL = Absolute tolerance for SIGS\nC MAXIT = Maximum number of SMCRV/SIGS iterations\nC DYSTOL = Bound on the maximum relative change in a\nC component of YS defining convergence of\nC the SMCRV/SIGS iteration when UNIFRM = FALSE\nC\n DATA STOL/0.D0/, MAXIT/99/, DYSTOL/.01D0/\nC\nC Initialize NIT, and test for invalid input parameters LWK\nC and SIGMA(1).\nC\n NIT = 0\n NN = N\n NM1 = NN - 1\n IF (NN .LT. 2 .OR. (PER .AND. NN .LT. 3)) GO TO 11\n IF (UNIFRM) THEN\n IF ( LWK .LT. 6*NN .OR.\n . (PER .AND. LWK .LT. 10*NN) ) GO TO 12\n SIG = SIGMA(1)\n IF (SIG .LT. 0.D0 .OR. SIG .GT. SBIG) GO TO 13\n ELSE\n IF ( LWK .LT. 7*NN .OR.\n . (PER .AND. LWK .LT. 11*NN) ) GO TO 12\n SIG = 0.D0\n ENDIF\nC\nC Store uniform tension factors, or initialize SIGMA to\nC zeros.\nC\n DO 1 I = 1,NM1\n SIGMA(I) = SIG\n 1 CONTINUE\nC\nC Compute smoothing curve for uniform tension.\nC\n CALL SMCRV (NN,X,Y,SIGMA,PER,W,SM,SMTOL,WK, YS,YP,IER)\n IF (IER .LE. -2) IER = -4\n IF (IER .LT. 0 .OR. UNIFRM) RETURN\nC\nC Iterate on calls to SIGS and SMCRV. The first N-1 WK\nC locations are used to store the function values YS\nC from the previous iteration.\nC\nC DYS is the maximum relative change in a component of YS.\nC ICNT is the number of tension factors which were\nC increased by SIGS.\nC DSMAX is the maximum relative change in a component of\nC SIGMA.\nC\n DO 4 ITER = 1,MAXIT\n DYS = 0.D0\n DO 2 I = 2,NM1\n WK(I) = YS(I)\n 2 CONTINUE\n CALL SIGS (NN,X,Y,YP,STOL, SIGMA, DSMAX,ICNT)\n CALL SMCRV (NN,X,Y,SIGMA,PER,W,SM,SMTOL,WK(NN), YS,\n . YP,IERR)\n DO 3 I = 2,NM1\n E = ABS(YS(I)-WK(I))\n IF (WK(I) .NE. 0.D0) E = E/ABS(WK(I))\n DYS = MAX(DYS,E)\n 3 CONTINUE\n IF (ICNT .EQ. 0 .OR. DYS .LE. DYSTOL) GO TO 5\n 4 CONTINUE\n ITER = MAXIT\nC\nC No error encountered.\nC\n 5 WK(1) = DYS\n WK(2) = DSMAX\n NIT = ITER\n IER = IERR\n RETURN\nC\nC Invalid input parameter N, W, SM, or SMTOL.\nC\n 11 IER = -1\n RETURN\nC\nC LWK too small.\nC\n 12 IER = -2\n RETURN\nC\nC UNIFRM = TRUE and SIGMA(1) outside its valid range.\nC\n 13 IER = -3\n RETURN\n END\n SUBROUTINE TSVAL1 (N,X,Y,YP,SIGMA,IFLAG,NE,TE, V,\n . IER)\n INTEGER N, IFLAG, NE, IER\n DOUBLE PRECISION X(N), Y(N), YP(N), SIGMA(N), TE(NE),\n . V(NE)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 06/10/92\nC\nC This subroutine evaluates a Hermite interpolatory ten-\nC sion spline H or its first or second derivative at a set\nC of points TE.\nC\nC Note that a large tension factor in SIGMA may cause\nC underflow. The result is assumed to be zero. If not the\nC default, this may be specified by either a compiler option\nC or operating system option.\nC\nC On input:\nC\nC N = Number of data points. N .GE. 2.\nC\nC X = Array of length N containing the abscissae.\nC These must be in strictly increasing order:\nC X(I) < X(I+1) for I = 1,...,N-1.\nC\nC Y = Array of length N containing data values or\nC function values returned by Subroutine SMCRV.\nC Y(I) = H(X(I)) for I = 1,...,N.\nC\nC YP = Array of length N containing first deriva-\nC tives. YP(I) = HP(X(I)) for I = 1,...,N, where\nC HP denotes the derivative of H.\nC\nC SIGMA = Array of length N-1 containing tension fac-\nC tors whose absolute values determine the\nC balance between cubic and linear in each\nC interval. SIGMA(I) is associated with int-\nC erval (I,I+1) for I = 1,...,N-1.\nC\nC IFLAG = Output option indicator:\nC IFLAG = 0 if values of H are to be computed.\nC IFLAG = 1 if first derivative values are to\nC be computed.\nC IFLAG = 2 if second derivative values are to\nC be computed.\nC\nC NE = Number of evaluation points. NE > 0.\nC\nC TE = Array of length NE containing the evaluation\nC points. The sequence should be strictly in-\nC creasing for maximum efficiency. Extrapolation\nC is performed if a point is not in the interval\nC [X(1),X(N)].\nC\nC The above parameters are not altered by this routine.\nC\nC V = Array of length at least NE.\nC\nC On output:\nC\nC V = Array of function, first derivative, or second\nC derivative values at the evaluation points un-\nC less IER < 0. If IER = -1, V is not altered.\nC If IER = -2, V may be only partially defined.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered and\nC no extrapolation occurred.\nC IER > 0 if no errors were encountered but\nC extrapolation was required at IER\nC points.\nC IER = -1 if N < 2, IFLAG < 0, IFLAG > 2, or\nC NE < 1.\nC IER = -2 if the abscissae are not in strictly\nC increasing order. (This error will\nC not necessarily be detected.)\nC\nC Modules required by TSVAL1: HPPVAL, HPVAL, HVAL, INTRVL,\nC SNHCSH\nC\nC***********************************************************\nC\n INTEGER I, IERR, IFLG, NVAL, NX\n DOUBLE PRECISION HPPVAL, HPVAL, HVAL\nC\n IFLG = IFLAG\n NVAL = NE\nC\nC Test for invalid input.\nC\n IF (N .LT. 2 .OR. IFLG .LT. 0 .OR. IFLG .GT. 2\n . .OR. NVAL .LT. 1) GO TO 2\nC\nC Initialize the number of extrapolation points NX and\nC loop on evaluation points.\nC\n NX = 0\n DO 1 I = 1,NVAL\n IF (IFLG .EQ. 0) THEN\n V(I) = HVAL (TE(I),N,X,Y,YP,SIGMA, IERR)\n ELSEIF (IFLG .EQ. 1) THEN\n V(I) = HPVAL (TE(I),N,X,Y,YP,SIGMA, IERR)\n ELSE\n V(I) = HPPVAL (TE(I),N,X,Y,YP,SIGMA, IERR)\n ENDIF\n IF (IERR .LT. 0) GO TO 3\n NX = NX + IERR\n 1 CONTINUE\nC\nC No errors encountered.\nC\n IER = NX\n RETURN\nC\nC N, IFLAG, or NE is outside its valid range.\nC\n 2 IER = -1\n RETURN\nC\nC X is not strictly increasing.\nC\n 3 IER = -2\n RETURN\n END\n SUBROUTINE TSVAL2 (N,T,X,Y,XP,YP,SIGMA,IFLAG,NE,\n . TE, VX,VY,IER)\n INTEGER N, IFLAG, NE, IER\n DOUBLE PRECISION T(N), X(N), Y(N), XP(N), YP(N),\n . SIGMA(N), TE(NE), VX(NE), VY(NE)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 06/10/92\nC\nC This subroutine returns values or derivatives of a pair\nC of Hermite interpolatory tension splines H1 and H2 which\nC form the components of a parametric planar curve C(t) =\nC (H1(t),H2(t)). Refer to Subroutines TSPBP and TSPSP.\nC\nC Note that a large tension factor in SIGMA may cause\nC underflow. The result is assumed to be zero. If not the\nC default, this may be specified by either a compiler option\nC or operating system option.\nC\nC On input:\nC\nC N = Number of data points. N .GE. 2.\nC\nC T = Array of length N containing a strictly in-\nC creasing sequence of abscissae (parameter\nC values). Refer to Subroutine ARCL2D.\nC\nC X = Array of length N containing data values or\nC function values returned by Subroutine SMCRV.\nC X(I) = H1(T(I)) for I = 1,...,N.\nC\nC Y = Array of length N containing data values or\nC function values returned by Subroutine SMCRV.\nC Y(I) = H2(T(I)) for I = 1,...,N.\nC\nC XP = Array of length N containing first deriva-\nC tives. XP(I) = H1P(T(I)) for I = 1,...,N,\nC where H1P denotes the derivative of H1.\nC\nC YP = Array of length N containing first deriva-\nC tives. YP(I) = H2P(T(I)) for I = 1,...,N,\nC where H2P denotes the derivative of H2.\nC\nC Note that C(T(I)) = (X(I),Y(I)) and CP(T(I)) = (XP(I),\nC YP(I)), I = 1,...,N, are data (control) points and deriva-\nC tive (velocity) vectors, respectively.\nC\nC SIGMA = Array of length N-1 containing tension fac-\nC tors whose absolute values determine the\nC balance between cubic and linear in each\nC interval. SIGMA(I) is associated with int-\nC erval (I,I+1) for I = 1,...,N-1.\nC\nC IFLAG = Output option indicator:\nC IFLAG = 0 if values of H1 and H2 (points on\nC the curve) are to be computed.\nC IFLAG = 1 if first derivative vectors are to\nC be computed. Unit tangent vectors\nC can be obtained by normalizing\nC these to unit vectors.\nC IFLAG = 2 if second derivative (accelera-\nC tion) vectors are to be computed.\nC Given a unit tangent vector U and\nC a second derivative vector V, the\nC corresponding curvature vector\nC can be computed as the cross\nC product U X V X U.\nC\nC NE = Number of evaluation points. NE > 0.\nC\nC TE = Array of length NE containing the evaluation\nC points. The sequence should be strictly in-\nC creasing for maximum efficiency. Extrapolation\nC is performed if a point is not in the interval\nC [T(1),T(N)].\nC\nC The above parameters are not altered by this routine.\nC\nC VX,VY = Arrays of length at least NE.\nC\nC On output:\nC\nC VX,VY = Arrays containing values, first derivatives,\nC or second derivatives of H1 and H2, respec-\nC tively, at the evaluation points (unless\nC IER < 0). If IER = -1, VX and VY are not\nC altered. If IER = -2, VX and VY may be only\nC partially defined.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered and\nC no extrapolation occurred.\nC IER > 0 if no errors were encountered but\nC extrapolation was required at IER\nC points.\nC IER = -1 if N < 2, IFLAG < 0, IFLAG > 2, or\nC NE < 1.\nC IER = -2 if the abscissae are not in strictly\nC increasing order. (This error will\nC not necessarily be detected.)\nC\nC Modules required by TSVAL2: HPPVAL, HPVAL, HVAL, INTRVL,\nC SNHCSH\nC\nC***********************************************************\nC\n INTEGER I, IERR, IFLG, NVAL, NX\n DOUBLE PRECISION HPPVAL, HPVAL, HVAL\nC\n IFLG = IFLAG\n NVAL = NE\nC\nC Test for invalid input.\nC\n IF (N .LT. 2 .OR. IFLG .LT. 0 .OR. IFLG .GT. 2\n . .OR. NVAL .LT. 1) GO TO 2\nC\nC Initialize the number of extrapolation points NX and\nC loop on evaluation points.\nC\n NX = 0\n DO 1 I = 1,NVAL\n IF (IFLG .EQ. 0) THEN\n VX(I) = HVAL (TE(I),N,T,X,XP,SIGMA, IERR)\n VY(I) = HVAL (TE(I),N,T,Y,YP,SIGMA, IERR)\n ELSEIF (IFLG .EQ. 1) THEN\n VX(I) = HPVAL (TE(I),N,T,X,XP,SIGMA, IERR)\n VY(I) = HPVAL (TE(I),N,T,Y,YP,SIGMA, IERR)\n ELSE\n VX(I) = HPPVAL (TE(I),N,T,X,XP,SIGMA, IERR)\n VY(I) = HPPVAL (TE(I),N,T,Y,YP,SIGMA, IERR)\n ENDIF\n IF (IERR .LT. 0) GO TO 3\n NX = NX + IERR\n 1 CONTINUE\nC\nC No errors encountered.\nC\n IER = NX\n RETURN\nC\nC N, IFLAG, or NE is outside its valid range.\nC\n 2 IER = -1\n RETURN\nC\nC T is not strictly increasing.\nC\n 3 IER = -2\n RETURN\n END\n SUBROUTINE TSVAL3 (N,T,X,Y,Z,XP,YP,ZP,SIGMA,IFLAG,NE,\n . TE, VX,VY,VZ,IER)\n INTEGER N, IFLAG, NE, IER\n DOUBLE PRECISION T(N), X(N), Y(N), Z(N), XP(N), YP(N),\n . ZP(N), SIGMA(N), TE(NE), VX(NE),\n . VY(NE), VZ(NE)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 06/10/92\nC\nC This subroutine returns values or derivatives of three\nC Hermite interpolatory tension splines H1, H2, and H3 which\nC form the components of a parametric space curve C(t) =\nC (H1(t),H2(t),H3(t)). Refer to Subroutines TSPBP and\nC TSPSP.\nC\nC Note that a large tension factor in SIGMA may cause\nC underflow. The result is assumed to be zero. If not the\nC default, this may be specified by either a compiler option\nC or operating system option.\nC\nC On input:\nC\nC N = Number of data points. N .GE. 2.\nC\nC T = Array of length N containing a strictly in-\nC creasing sequence of abscissae (parameter\nC values). Refer to Subroutine ARCL3D.\nC\nC X = Array of length N containing data values or\nC function values returned by Subroutine SMCRV.\nC X(I) = H1(T(I)) for I = 1,...,N.\nC\nC Y = Array of length N containing data values or\nC function values returned by Subroutine SMCRV.\nC Y(I) = H2(T(I)) for I = 1,...,N.\nC\nC Z = Array of length N containing data values or\nC function values returned by Subroutine SMCRV.\nC Z(I) = H3(T(I)) for I = 1,...,N.\nC\nC XP = Array of length N containing first deriva-\nC tives. XP(I) = H1P(T(I)) for I = 1,...,N,\nC where H1P denotes the derivative of H1.\nC\nC YP = Array of length N containing first deriva-\nC tives. YP(I) = H2P(T(I)) for I = 1,...,N,\nC where H2P denotes the derivative of H2.\nC\nC ZP = Array of length N containing first deriva-\nC tives. ZP(I) = H3P(T(I)) for I = 1,...,N,\nC where H3P denotes the derivative of H3.\nC\nC Note that C(T(I)) = (X(I),Y(I),Z(I)) and CP(T(I)) =\nC (XP(I),YP(I),ZP(I)), I = 1,...,N, are data (control)\nC points and derivative (velocity) vectors, respectively.\nC\nC SIGMA = Array of length N-1 containing tension fac-\nC tors whose absolute values determine the\nC balance between cubic and linear in each\nC interval. SIGMA(I) is associated with int-\nC erval (I,I+1) for I = 1,...,N-1.\nC\nC IFLAG = Output option indicator:\nC IFLAG = 0 if values of H1, H2, and H3\nC (points on the curve) are to be\nC computed.\nC IFLAG = 1 if first derivative vectors are to\nC be computed. Unit tangent vectors\nC can be obtained by normalizing\nC these to unit vectors.\nC IFLAG = 2 if second derivative (accelera-\nC tion) vectors are to be computed.\nC Given a unit tangent vector U and\nC a second derivative vector V, the\nC corresponding curvature vector\nC can be computed as the cross\nC product U X V X U.\nC\nC NE = Number of evaluation points. NE > 0.\nC\nC TE = Array of length NE containing the evaluation\nC points. The sequence should be strictly in-\nC creasing for maximum efficiency. Extrapolation\nC is performed if a point is not in the interval\nC [T(1),T(N)].\nC\nC The above parameters are not altered by this routine.\nC\nC VX,VY,VZ = Arrays of length at least NE.\nC\nC On output:\nC\nC VX,VY,VZ = Arrays containing values, first deriva-\nC tives, or second derivatives of H1, H2,\nC and H3, respectively, at the evaluation\nC points (unless IER < 0). If IER = -1,\nC VX, VY, and VZ are not altered. If IER\nC = -2, VX, VY, and VZ may be only partial-\nC ly defined.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered and\nC no extrapolation occurred.\nC IER > 0 if no errors were encountered but\nC extrapolation was required at IER\nC points.\nC IER = -1 if N < 2, IFLAG < 0, IFLAG > 2, or\nC NE < 1.\nC IER = -2 if the abscissae are not in strictly\nC increasing order. (This error will\nC not necessarily be detected.)\nC\nC Modules required by TSVAL3: HPPVAL, HPVAL, HVAL, INTRVL,\nC SNHCSH\nC\nC***********************************************************\nC\n INTEGER I, IERR, IFLG, NVAL, NX\n DOUBLE PRECISION HPPVAL, HPVAL, HVAL\nC\n IFLG = IFLAG\n NVAL = NE\nC\nC Test for invalid input.\nC\n IF (N .LT. 2 .OR. IFLG .LT. 0 .OR. IFLG .GT. 2\n . .OR. NVAL .LT. 1) GO TO 2\nC\nC Initialize the number of extrapolation points NX and\nC loop on evaluation points.\nC\n NX = 0\n DO 1 I = 1,NVAL\n IF (IFLG .EQ. 0) THEN\n VX(I) = HVAL (TE(I),N,T,X,XP,SIGMA, IERR)\n VY(I) = HVAL (TE(I),N,T,Y,YP,SIGMA, IERR)\n VZ(I) = HVAL (TE(I),N,T,Z,ZP,SIGMA, IERR)\n ELSEIF (IFLG .EQ. 1) THEN\n VX(I) = HPVAL (TE(I),N,T,X,XP,SIGMA, IERR)\n VY(I) = HPVAL (TE(I),N,T,Y,YP,SIGMA, IERR)\n VZ(I) = HPVAL (TE(I),N,T,Z,ZP,SIGMA, IERR)\n ELSE\n VX(I) = HPPVAL (TE(I),N,T,X,XP,SIGMA, IERR)\n VY(I) = HPPVAL (TE(I),N,T,Y,YP,SIGMA, IERR)\n VZ(I) = HPPVAL (TE(I),N,T,Z,ZP,SIGMA, IERR)\n ENDIF\n IF (IERR .LT. 0) GO TO 3\n NX = NX + IERR\n 1 CONTINUE\nC\nC No errors encountered.\nC\n IER = NX\n RETURN\nC\nC N, IFLAG, or NE is outside its valid range.\nC\n 2 IER = -1\n RETURN\nC\nC T is not strictly increasing.\nC\n 3 IER = -2\n RETURN\n END\n SUBROUTINE YPC1 (N,X,Y, YP,IER)\n INTEGER N, IER\n DOUBLE PRECISION X(N), Y(N), YP(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 06/10/92\nC\nC This subroutine employs a three-point quadratic interpo-\nC lation method to compute local derivative estimates YP\nC associated with a set of data points. The interpolation\nC formula is the monotonicity-constrained parabolic method\nC described in the reference cited below. A Hermite int-\nC erpolant of the data values and derivative estimates pre-\nC serves monotonicity of the data. Linear interpolation is\nC used if N = 2. The method is invariant under a linear\nC scaling of the coordinates but is not additive.\nC\nC On input:\nC\nC N = Number of data points. N .GE. 2.\nC\nC X = Array of length N containing a strictly in-\nC creasing sequence of abscissae: X(I) < X(I+1)\nC for I = 1,...,N-1.\nC\nC Y = Array of length N containing data values asso-\nC ciated with the abscissae.\nC\nC Input parameters are not altered by this routine.\nC\nC On output:\nC\nC YP = Array of length N containing estimated deriv-\nC atives at the abscissae unless IER .NE. 0.\nC YP is not altered if IER = 1, and is only par-\nC tially defined if IER > 1.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered.\nC IER = 1 if N < 2.\nC IER = I if X(I) .LE. X(I-1) for some I in the\nC range 2,...,N.\nC\nC Reference: J. M. Hyman, \"Accurate Monotonicity-preserving\nC Cubic Interpolation\", LA-8796-MS, Los\nC Alamos National Lab, Feb. 1982.\nC\nC Modules required by YPC1: None\nC\nC Intrinsic functions called by YPC1: ABS, MAX, MIN, SIGN\nC\nC***********************************************************\nC\n INTEGER I, NM1\n DOUBLE PRECISION ASI, ASIM1, DX2, DXI, DXIM1, S2, SGN,\n . SI, SIM1, T\nC\n NM1 = N - 1\n IF (NM1 .LT. 1) GO TO 2\n I = 1\n DXI = X(2) - X(1)\n IF (DXI .LE. 0.D0) GO TO 3\n SI = (Y(2)-Y(1))/DXI\n IF (NM1 .EQ. 1) THEN\nC\nC Use linear interpolation for N = 2.\nC\n YP(1) = SI\n YP(2) = SI\n IER = 0\n RETURN\n ENDIF\nC\nC N .GE. 3. YP(1) = S1 + DX1*(S1-S2)/(DX1+DX2) unless this\nC results in YP(1)*S1 .LE. 0 or abs(YP(1)) > 3*abs(S1).\nC\n I = 2\n DX2 = X(3) - X(2)\n IF (DX2 .LE. 0.D0) GO TO 3\n S2 = (Y(3)-Y(2))/DX2\n T = SI + DXI*(SI-S2)/(DXI+DX2)\n IF (SI .GE. 0.D0) THEN\n YP(1) = MIN(MAX(0.D0,T), 3.D0*SI)\n ELSE\n YP(1) = MAX(MIN(0.D0,T), 3.D0*SI)\n ENDIF\nC\nC YP(I) = (DXIM1*SI+DXI*SIM1)/(DXIM1+DXI) subject to the\nC constraint that YP(I) has the sign of either SIM1 or\nC SI, whichever has larger magnitude, and abs(YP(I)) .LE.\nC 3*min(abs(SIM1),abs(SI)).\nC\n DO 1 I = 2,NM1\n DXIM1 = DXI\n DXI = X(I+1) - X(I)\n IF (DXI .LE. 0.D0) GO TO 3\n SIM1 = SI\n SI = (Y(I+1)-Y(I))/DXI\n T = (DXIM1*SI+DXI*SIM1)/(DXIM1+DXI)\n ASIM1 = ABS(SIM1)\n ASI = ABS(SI)\n SGN = SIGN(1.D0,SI)\n IF (ASIM1 .GT. ASI) SGN = SIGN(1.D0,SIM1)\n IF (SGN .GT. 0.D0) THEN\n YP(I) = MIN(MAX(0.D0,T),3.D0*MIN(ASIM1,ASI))\n ELSE\n YP(I) = MAX(MIN(0.D0,T),-3.D0*MIN(ASIM1,ASI))\n ENDIF\n 1 CONTINUE\nC\nC YP(N) = SNM1 + DXNM1*(SNM1-SNM2)/(DXNM2+DXNM1) subject to\nC the constraint that YP(N) has the sign of SNM1 and\nC abs(YP(N)) .LE. 3*abs(SNM1). Note that DXI = DXNM1 and\nC SI = SNM1.\nC\n T = SI + DXI*(SI-SIM1)/(DXIM1+DXI)\n IF (SI .GE. 0.D0) THEN\n YP(N) = MIN(MAX(0.D0,T), 3.D0*SI)\n ELSE\n YP(N) = MAX(MIN(0.D0,T), 3.D0*SI)\n ENDIF\n IER = 0\n RETURN\nC\nC N is outside its valid range.\nC\n 2 IER = 1\n RETURN\nC\nC X(I+1) .LE. X(I).\nC\n 3 IER = I + 1\n RETURN\n END\n SUBROUTINE YPC1P (N,X,Y, YP,IER)\n INTEGER N, IER\n DOUBLE PRECISION X(N), Y(N), YP(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 06/10/92\nC\nC This subroutine employs a three-point quadratic interpo-\nC lation method to compute local derivative estimates YP\nC associated with a set of N data points (X(I),Y(I)). It\nC is assumed that Y(N) = Y(1), and YP(N) = YP(1) on output.\nC Thus, a Hermite interpolant H(x) defined by the data\nC points and derivative estimates is periodic with period\nC X(N)-X(1). The derivative-estimation formula is the\nC monotonicity-constrained parabolic fit described in the\nC reference cited below: H(x) is monotonic in intervals in\nC which the data is monotonic. The method is invariant\nC under a linear scaling of the coordinates but is not\nC additive.\nC\nC On input:\nC\nC N = Number of data points. N .GE. 3.\nC\nC X = Array of length N containing a strictly in-\nC creasing sequence of abscissae: X(I) < X(I+1)\nC for I = 1,...,N-1.\nC\nC Y = Array of length N containing data values asso-\nC ciated with the abscissae. Y(N) is set to Y(1)\nC on output unless IER = 1.\nC\nC Input parameters, other than Y(N), are not altered by\nC this routine.\nC\nC On output:\nC\nC YP = Array of length N containing estimated deriv-\nC atives at the abscissae unless IER .NE. 0.\nC YP is not altered if IER = 1, and is only par-\nC tially defined if IER > 1.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered.\nC IER = 1 if N < 3.\nC IER = I if X(I) .LE. X(I-1) for some I in the\nC range 2,...,N.\nC\nC Reference: J. M. Hyman, \"Accurate Monotonicity-preserving\nC Cubic Interpolation\", LA-8796-MS, Los\nC Alamos National Lab, Feb. 1982.\nC\nC Modules required by YPC1P: None\nC\nC Intrinsic functions called by YPC1P: ABS, MAX, MIN, SIGN\nC\nC***********************************************************\nC\n INTEGER I, NM1\n DOUBLE PRECISION ASI, ASIM1, DXI, DXIM1, SGN, SI,\n . SIM1, T\nC\n NM1 = N - 1\n IF (NM1 .LT. 2) GO TO 2\n Y(N) = Y(1)\nC\nC Initialize for loop on interior points.\nC\n I = 1\n DXI = X(2) - X(1)\n IF (DXI .LE. 0.D0) GO TO 3\n SI = (Y(2)-Y(1))/DXI\nC\nC YP(I) = (DXIM1*SI+DXI*SIM1)/(DXIM1+DXI) subject to the\nC constraint that YP(I) has the sign of either SIM1 or\nC SI, whichever has larger magnitude, and abs(YP(I)) .LE.\nC 3*min(abs(SIM1),abs(SI)).\nC\n DO 1 I = 2,NM1\n DXIM1 = DXI\n DXI = X(I+1) - X(I)\n IF (DXI .LE. 0.D0) GO TO 3\n SIM1 = SI\n SI = (Y(I+1)-Y(I))/DXI\n T = (DXIM1*SI+DXI*SIM1)/(DXIM1+DXI)\n ASIM1 = ABS(SIM1)\n ASI = ABS(SI)\n SGN = SIGN(1.D0,SI)\n IF (ASIM1 .GT. ASI) SGN = SIGN(1.D0,SIM1)\n IF (SGN .GT. 0.D0) THEN\n YP(I) = MIN(MAX(0.D0,T),3.D0*MIN(ASIM1,ASI))\n ELSE\n YP(I) = MAX(MIN(0.D0,T),-3.D0*MIN(ASIM1,ASI))\n ENDIF\n 1 CONTINUE\nC\nC YP(N) = YP(1), I = 1, and IM1 = N-1.\nC\n DXIM1 = DXI\n DXI = X(2) - X(1)\n SIM1 = SI\n SI = (Y(2) - Y(1))/DXI\n T = (DXIM1*SI + DXI*SIM1)/(DXIM1+DXI)\n ASIM1 = ABS(SIM1)\n ASI = ABS(SI)\n SGN = SIGN(1.D0,SI)\n IF (ASIM1 .GT. ASI) SGN = SIGN(1.D0,SIM1)\n IF (SGN .GT. 0.D0) THEN\n YP(1) = MIN(MAX(0.D0,T), 3.D0*MIN(ASIM1,ASI))\n ELSE\n YP(1) = MAX(MIN(0.D0,T), -3.D0*MIN(ASIM1,ASI))\n ENDIF\n YP(N) = YP(1)\nC\nC No error encountered.\nC\n IER = 0\n RETURN\nC\nC N is outside its valid range.\nC\n 2 IER = 1\n RETURN\nC\nC X(I+1) .LE. X(I).\nC\n 3 IER = I + 1\n RETURN\n END\n SUBROUTINE YPC2 (N,X,Y,SIGMA,ISL1,ISLN,BV1,BVN,\n . WK, YP,IER)\n INTEGER N, ISL1, ISLN, IER\n DOUBLE PRECISION X(N), Y(N), SIGMA(N), BV1, BVN,\n . WK(N), YP(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 06/10/92\nC\nC This subroutine solves a linear system for a set of\nC first derivatives YP associated with a Hermite interpola-\nC tory tension spline H(x). The derivatives are chosen so\nC that H(x) has two continuous derivatives for all x and H\nC satisfies user-specified end conditions.\nC\nC On input:\nC\nC N = Number of data points. N .GE. 2.\nC\nC X = Array of length N containing a strictly in-\nC creasing sequence of abscissae: X(I) < X(I+1)\nC for I = 1,...,N-1.\nC\nC Y = Array of length N containing data values asso-\nC ciated with the abscissae. H(X(I)) = Y(I) for\nC I = 1,...,N.\nC\nC SIGMA = Array of length N-1 containing tension\nC factors. SIGMA(I) is associated with inter-\nC val (X(I),X(I+1)) for I = 1,...,N-1. If\nC SIGMA(I) = 0, H is the Hermite cubic interp-\nC olant of the data values and computed deriv-\nC atives at X(I) and X(I+1), and if all\nC tension factors are zero, H is the C-2 cubic\nC spline interpolant which satisfies the end\nC conditions.\nC\nC ISL1 = Option indicator for the condition at X(1):\nC ISL1 = 0 if YP(1) is to be estimated inter-\nC nally by a constrained parabolic\nC fit to the first three points.\nC This is identical to the method used\nC by Subroutine YPC1. BV1 is not used\nC in this case.\nC ISL1 = 1 if the first derivative of H at X(1)\nC is specified by BV1.\nC ISL1 = 2 if the second derivative of H at\nC X(1) is specified by BV1.\nC ISL1 = 3 if YP(1) is to be estimated inter-\nC nally from the derivative of the\nC tension spline (using SIGMA(1))\nC which interpolates the first three\nC data points and has third derivative\nC equal to zero at X(1). Refer to\nC ENDSLP. BV1 is not used in this\nC case.\nC\nC ISLN = Option indicator for the condition at X(N):\nC ISLN = 0 if YP(N) is to be estimated inter-\nC nally by a constrained parabolic\nC fit to the last three data points.\nC This is identical to the method used\nC by Subroutine YPC1. BVN is not used\nC in this case.\nC ISLN = 1 if the first derivative of H at X(N)\nC is specified by BVN.\nC ISLN = 2 if the second derivative of H at\nC X(N) is specified by BVN.\nC ISLN = 3 if YP(N) is to be estimated inter-\nC nally from the derivative of the\nC tension spline (using SIGMA(N-1))\nC which interpolates the last three\nC data points and has third derivative\nC equal to zero at X(N). Refer to\nC ENDSLP. BVN is not used in this\nC case.\nC\nC BV1,BVN = Boundary values or dummy parameters as\nC defined by ISL1 and ISLN.\nC\nC The above parameters are not altered by this routine.\nC\nC WK = Array of length at least N-1 to be used as\nC temporary work space.\nC\nC YP = Array of length .GE. N.\nC\nC On output:\nC\nC YP = Array containing derivatives of H at the\nC abscissae. YP is not defined if IER .NE. 0.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered.\nC IER = 1 if N, ISL1, or ISLN is outside its\nC valid range.\nC IER = I if X(I) .LE. X(I-1) for some I in the\nC range 2,...,N.\nC\nC Modules required by YPC2: ENDSLP, SNHCSH, YPCOEF\nC\nC Intrinsic function called by YPC2: ABS\nC\nC***********************************************************\nC\n INTEGER I, NM1, NN\n DOUBLE PRECISION D, D1, D2, DX, R1, R2, S, SD1, SD2,\n . SIG, YP1, YPN\n DOUBLE PRECISION ENDSLP\nC\n NN = N\n IF (NN .LT. 2 .OR. ISL1 .LT. 0 .OR. ISL1 .GT. 3\n . .OR. ISLN .LT. 0 .OR. ISLN .GT. 3) GO TO 3\n NM1 = NN - 1\nC\nC Set YP1 and YPN to the endpoint values.\nC\n IF (ISL1 .EQ. 0) THEN\n IF (NN .GT. 2) YP1 = ENDSLP (X(1),X(2),X(3),Y(1),\n . Y(2),Y(3),0.D0)\n ELSEIF (ISL1 .NE. 3) THEN\n YP1 = BV1\n ELSE\n IF (NN .GT. 2) YP1 = ENDSLP (X(1),X(2),X(3),Y(1),\n . Y(2),Y(3),SIGMA(1))\n ENDIF\n IF (ISLN .EQ. 0) THEN\n IF (NN .GT. 2) YPN = ENDSLP (X(NN),X(NM1),X(NN-2),\n . Y(NN),Y(NM1),Y(NN-2),0.D0)\n ELSEIF (ISLN .NE. 3) THEN\n YPN = BVN\n ELSE\n IF (NN .GT. 2) YPN = ENDSLP (X(NN),X(NM1),X(NN-2),\n . Y(NN),Y(NM1),Y(NN-2),SIGMA(NM1))\n ENDIF\nC\nC Solve the symmetric positive-definite tridiagonal linear\nC system. The forward elimination step consists of div-\nC iding each row by its diagonal entry, then introducing a\nC zero below the diagonal. This requires saving only the\nC superdiagonal (in WK) and the right hand side (in YP).\nC\n I = 1\n DX = X(2) - X(1)\n IF (DX .LE. 0.D0) GO TO 4\n S = (Y(2)-Y(1))/DX\n IF (NN .EQ. 2) THEN\n IF (ISL1 .EQ. 0 .OR. ISL1 .EQ. 3) YP1 = S\n IF (ISLN .EQ. 0 .OR. ISLN .EQ. 3) YPN = S\n ENDIF\nC\nC Begin forward elimination.\nC\n SIG = ABS(SIGMA(1))\n CALL YPCOEF (SIG,DX, D1,SD1)\n R1 = (SD1+D1)*S\n WK(1) = 0.D0\n YP(1) = YP1\n IF (ISL1 .EQ. 2) THEN\n WK(1) = SD1/D1\n YP(1) = (R1-YP1)/D1\n ENDIF\n DO 1 I = 2,NM1\n DX = X(I+1) - X(I)\n IF (DX .LE. 0.D0) GO TO 4\n S = (Y(I+1)-Y(I))/DX\n SIG = ABS(SIGMA(I))\n CALL YPCOEF (SIG,DX, D2,SD2)\n R2 = (SD2+D2)*S\n D = D1 + D2 - SD1*WK(I-1)\n WK(I) = SD2/D\n YP(I) = (R1 + R2 - SD1*YP(I-1))/D\n D1 = D2\n SD1 = SD2\n R1 = R2\n 1 CONTINUE\n D = D1 - SD1*WK(NM1)\n YP(NN) = YPN\n IF (ISLN .EQ. 2) YP(NN) = (R1 + YPN - SD1*YP(NM1))/D\nC\nC Back substitution:\nC\n DO 2 I = NM1,1,-1\n YP(I) = YP(I) - WK(I)*YP(I+1)\n 2 CONTINUE\n IER = 0\n RETURN\nC\nC Invalid integer input parameter.\nC\n 3 IER = 1\n RETURN\nC\nC Abscissae out of order or duplicate points.\nC\n 4 IER = I + 1\n RETURN\n END\n SUBROUTINE YPC2P (N,X,Y,SIGMA,WK, YP,IER)\n INTEGER N, IER\n DOUBLE PRECISION X(N), Y(N), SIGMA(N), WK(*), YP(N)\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 06/10/92\nC\nC This subroutine solves a linear system for a set of\nC first derivatives YP associated with a Hermite interpola-\nC tory tension spline H(x). The derivatives are chosen so\nC that H(x) has two continuous derivatives for all x, and H\nC satisfies periodic end conditions: first and second der-\nC ivatives of H at X(1) agree with those at X(N), and thus\nC the length of a period is X(N) - X(1). It is assumed that\nC Y(N) = Y(1), and Y(N) is not referenced.\nC\nC On input:\nC\nC N = Number of data points. N .GE. 3.\nC\nC X = Array of length N containing a strictly in-\nC creasing sequence of abscissae: X(I) < X(I+1)\nC for I = 1,...,N-1.\nC\nC Y = Array of length N containing data values asso-\nC ciated with the abscissae. H(X(I)) = Y(I) for\nC I = 1,...,N.\nC\nC SIGMA = Array of length N-1 containing tension\nC factors. SIGMA(I) is associated with inter-\nC val (X(I),X(I+1)) for I = 1,...,N-1. If\nC SIGMA(I) = 0, H is the Hermite cubic interp-\nC olant of the data values and computed deriv-\nC atives at X(I) and X(I+1), and if all\nC tension factors are zero, H is the C-2 cubic\nC spline interpolant which satisfies the end\nC conditions.\nC\nC The above parameters are not altered by this routine.\nC\nC WK = Array of length at least 2N-2 to be used as\nC temporary work space.\nC\nC YP = Array of length .GE. N.\nC\nC On output:\nC\nC YP = Array containing derivatives of H at the\nC abscissae. YP is not defined if IER .NE. 0.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered.\nC IER = 1 if N is outside its valid range.\nC IER = I if X(I) .LE. X(I-1) for some I in the\nC range 2,...,N.\nC\nC Modules required by YPC2P: SNHCSH, YPCOEF\nC\nC Intrinsic function called by YPC2P: ABS\nC\nC***********************************************************\nC\n INTEGER I, NM1, NM2, NM3, NN, NP1, NPI\n DOUBLE PRECISION D, D1, D2, DIN, DNM1, DX, R1, R2,\n . RNM1, S, SD1, SD2, SDNM1, SIG, YPNM1\nC\n NN = N\n IF (NN .LT. 3) GO TO 4\n NM1 = NN - 1\n NM2 = NN - 2\n NM3 = NN - 3\n NP1 = NN + 1\nC\nC The system is order N-1, symmetric, positive-definite, and\nC tridiagonal except for nonzero elements in the upper\nC right and lower left corners. The forward elimination\nC step zeros the subdiagonal and divides each row by its\nC diagonal entry for the first N-2 rows. The superdiago-\nC nal is stored in WK(I), the negative of the last column\nC (fill-in) in WK(N+I), and the right hand side in YP(I)\nC for I = 1,...,N-2.\nC\n I = NM1\n DX = X(NN) - X(NM1)\n IF (DX .LE. 0.D0) GO TO 5\n S = (Y(1)-Y(NM1))/DX\n SIG = ABS(SIGMA(NM1))\n CALL YPCOEF (SIG,DX, DNM1,SDNM1)\n RNM1 = (SDNM1+DNM1)*S\n I = 1\n DX = X(2) - X(1)\n IF (DX .LE. 0.D0) GO TO 5\n S = (Y(2)-Y(1))/DX\n SIG = ABS(SIGMA(1))\n CALL YPCOEF (SIG,DX, D1,SD1)\n R1 = (SD1+D1)*S\n D = DNM1 + D1\n WK(1) = SD1/D\n WK(NP1) = -SDNM1/D\n YP(1) = (RNM1+R1)/D\n DO 1 I = 2,NM2\n DX = X(I+1) - X(I)\n IF (DX .LE. 0.D0) GO TO 5\n S = (Y(I+1)-Y(I))/DX\n SIG = ABS(SIGMA(I))\n CALL YPCOEF (SIG,DX, D2,SD2)\n R2 = (SD2+D2)*S\n D = D1 + D2 - SD1*WK(I-1)\n DIN = 1.D0/D\n WK(I) = SD2*DIN\n NPI = NN + I\n WK(NPI) = -SD1*WK(NPI-1)*DIN\n YP(I) = (R1 + R2 - SD1*YP(I-1))*DIN\n SD1 = SD2\n D1 = D2\n R1 = R2\n 1 CONTINUE\nC\nC The backward elimination step zeros the superdiagonal\nC (first N-3 elements). WK(I) and YP(I) are overwritten\nC with the negative of the last column and the new right\nC hand side, respectively, for I = N-2, N-3, ..., 1.\nC\n NPI = NN + NM2\n WK(NM2) = WK(NPI) - WK(NM2)\n DO 2 I = NM3,1,-1\n YP(I) = YP(I) - WK(I)*YP(I+1)\n NPI = NN + I\n WK(I) = WK(NPI) - WK(I)*WK(I+1)\n 2 CONTINUE\nC\nC Solve the last equation for YP(N-1).\nC\n YPNM1 = (R1 + RNM1 - SDNM1*YP(1) - SD1*YP(NM2))/\n . (D1 + DNM1 + SDNM1*WK(1) + SD1*WK(NM2))\nC\nC Back substitute for the remainder of the solution\nC components.\nC\n YP(NM1) = YPNM1\n DO 3 I = 1,NM2\n YP(I) = YP(I) + WK(I)*YPNM1\n 3 CONTINUE\nC\nC YP(N) = YP(1).\nC\n YP(N) = YP(1)\n IER = 0\n RETURN\nC\nC N is outside its valid range.\nC\n 4 IER = 1\n RETURN\nC\nC Abscissae out of order or duplicate points.\nC\n 5 IER = I + 1\n RETURN\n END\n SUBROUTINE YPCOEF (SIGMA,DX, D,SD)\n DOUBLE PRECISION SIGMA, DX, D, SD\nC\nC***********************************************************\nC\nC From TSPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 11/17/96\nC\nC This subroutine computes the coefficients of the deriva-\nC tives in the symmetric diagonally dominant tridiagonal\nC system associated with the C-2 derivative estimation pro-\nC cedure for a Hermite interpolatory tension spline.\nC\nC On input:\nC\nC SIGMA = Nonnegative tension factor associated with\nC an interval.\nC\nC DX = Positive interval width.\nC\nC Input parameters are not altered by this routine.\nC\nC On output:\nC\nC D = Component of the diagonal term associated with\nC the interval. D = SIG*(SIG*COSHM(SIG) -\nC SINHM(SIG))/(DX*E), where SIG = SIGMA and E =\nC SIG*SINH(SIG) - 2*COSHM(SIG).\nC\nC SD = Subdiagonal (superdiagonal) term. SD = SIG*\nC SINHM(SIG)/E.\nC\nC Module required by YPCOEF: SNHCSH\nC\nC Intrinsic function called by YPCOEF: EXP\nC\nC***********************************************************\nC\n DOUBLE PRECISION COSHM, COSHMM, E, EMS, SCM, SIG,\n . SINHM, SSINH, SSM\nC\n SIG = SIGMA\n IF (SIG .LT. 1.D-9) THEN\nC\nC SIG = 0: cubic interpolant.\nC\n D = 4.D0/DX\n SD = 2.D0/DX\n ELSEIF (SIG .LE. .5D0) THEN\nC\nC 0 .LT. SIG .LE. .5: use approximations designed to avoid\nC cancellation error in the hyperbolic\nC functions when SIGMA is small.\nC\n CALL SNHCSH (SIG, SINHM,COSHM,COSHMM)\n E = (SIG*SINHM - COSHMM - COSHMM)*DX\n D = SIG*(SIG*COSHM-SINHM)/E\n SD = SIG*SINHM/E\n ELSE\nC\nC SIG > .5: scale SINHM and COSHM by 2*EXP(-SIG) in order\nC to avoid overflow when SIGMA is large.\nC\n EMS = EXP(-SIG)\n SSINH = 1.D0 - EMS*EMS\n SSM = SSINH - 2.D0*SIG*EMS\n SCM = (1.D0-EMS)*(1.D0-EMS)\n E = (SIG*SSINH - SCM - SCM)*DX\n D = SIG*(SIG*SCM-SSM)/E\n SD = SIG*SSM/E\n ENDIF\n RETURN\n END\n\n", "meta": {"hexsha": "73e74c3e88acfae437d8b5c323fb1f134464f012", "size": 228864, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "snpy/tspack/tspack.f", "max_stars_repo_name": "emirkmo/snpy", "max_stars_repo_head_hexsha": "2a0153c84477ba8a30310d7dbca3d5a8f24de3c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-01-14T19:40:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-05T12:19:39.000Z", "max_issues_repo_path": "snpy/tspack/tspack.f", "max_issues_repo_name": "emirkmo/snpy", "max_issues_repo_head_hexsha": "2a0153c84477ba8a30310d7dbca3d5a8f24de3c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-04-25T20:06:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-09T20:46:41.000Z", "max_forks_repo_path": "snpy/tspack/tspack.f", "max_forks_repo_name": "emirkmo/snpy", "max_forks_repo_head_hexsha": "2a0153c84477ba8a30310d7dbca3d5a8f24de3c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2017-04-25T19:57:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-12T11:54:19.000Z", "avg_line_length": 33.6317413666, "max_line_length": 61, "alphanum_fraction": 0.5187840814, "num_tokens": 75332, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811306, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7715718010701295}} {"text": "\n! create a gaussian profile for bathymetry\n\n program create_gaussian_profile\n\n implicit none\n\n integer, parameter :: N = 200\n\n double precision, parameter :: horiz_size = 20000.d0, x0 = horiz_size / 2.d0, sigma = horiz_size / 40.d0, height = 300.d0\n\n double precision :: deltax,x\n\n integer :: i\n\n deltax = horiz_size / dble(N-1)\n\n do i = 1,N\n x = (i-1) * deltax\n print *,x, -3000.d0 + height * exp(-(x-x0)**2/(2*sigma**2))\n enddo\n\n end program create_gaussian_profile\n\n", "meta": {"hexsha": "2c8fbe0ce8ae960637b5639f068319caf5857705", "size": 485, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "specfem2d/utils/create_gaussian_profile.f90", "max_stars_repo_name": "PanIGGCAS/SeisElastic2D_1.1", "max_stars_repo_head_hexsha": "2872dc514b638237771f4071195f7b8f90e0ce3d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2020-10-04T01:55:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T05:20:50.000Z", "max_issues_repo_path": "specfem2d/utils/create_gaussian_profile.f90", "max_issues_repo_name": "PanIGGCAS/SeisElastic2D_1.1", "max_issues_repo_head_hexsha": "2872dc514b638237771f4071195f7b8f90e0ce3d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-10-31T03:36:34.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-27T09:36:13.000Z", "max_forks_repo_path": "specfem2d/utils/create_gaussian_profile.f90", "max_forks_repo_name": "PanIGGCAS/SeisElastic2D_1.1", "max_forks_repo_head_hexsha": "2872dc514b638237771f4071195f7b8f90e0ce3d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-12-15T02:04:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T21:48:35.000Z", "avg_line_length": 19.4, "max_line_length": 123, "alphanum_fraction": 0.6577319588, "num_tokens": 163, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9407897542390751, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.7713472541366321}} {"text": "!***********************************************************************\n! *\n SUBROUTINE Y_K(K,KM,GTheta,Phi,VAL_REAL,VAL_IM)\n! *\n! Calculates the spheric function Y^k _q by its algebraic formulae *\n! (see subsection 5.2.2 Eq. (9) page 134 in *\n! D.A. Varshalovich, A.N. Moskalev and V.K. Khersonskii, *\n! Quantum Theory of Angular Momentum; Berkeley, CA, 1981). *\n! *\n! Written by G. Gaigalas and E. Gaidamauskas *\n! Last revision: 08 Sep 2008 *\n! *\n!***********************************************************************\n!\n!-----------------------------------------------\n! M o d u l e s\n!-----------------------------------------------\n USE vast_kind_param, ONLY: DOUBLE\n USE CONS_C, ONLY: ZERO, ONE\n USE FACTS_C\n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n INTEGER, INTENT(IN) :: K, KM\n REAL(DOUBLE), INTENT(IN) :: GTheta, Phi\n REAL(DOUBLE), INTENT(OUT) :: VAL_REAL, VAL_IM\n!-----------------------------------------------\n! L o c a l P a r a m e t e r s\n!-----------------------------------------------\n! INTEGER, PARAMETER :: MFACT = 500\n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!----------------------------------------------\n INTEGER :: I, MAX_REZIS, MIN_REZIS\n REAL(DOUBLE) :: PI, SUM, COEF\n!----------------------------------------------\n!\n IF (K >= IABS(KM)) THEN\n PI = 4.0D00*DATAN (ONE)\n IF(KM < 0) THEN\n MAX_REZIS = K\n MIN_REZIS = -KM\n ELSE\n MAX_REZIS = K\n MIN_REZIS = 0\n END IF\n SUM = ZERO\n DO I = MIN_REZIS, MAX_REZIS\n IF((2*I+KM) == 0) THEN\n SUM = (-1)**I * DEXP(GAM(K+I+1))/DEXP(GAM(K-I+1)) &\n / (DEXP(GAM(I+1))*DEXP(GAM(I+KM+1))) &\n + SUM\n ELSE\n SUM = (-1)**I * DEXP(GAM(K+I+1))/DEXP(GAM(K-I+1)) &\n * DSIN(GTheta*0.5)**(2*I+KM) &\n / (DEXP(GAM(I+1))*DEXP(GAM(I+KM+1))) &\n + SUM\n END IF\n END DO\n COEF = (-1)**KM*DSQRT((2.0*K+1.0)*DEXP(GAM(K+KM+1))/ &\n (4.0*PI*DEXP(GAM(K-KM+1))))\n IF(KM == 0) THEN\n COEF = COEF\n ELSE\n COEF = COEF/(DCOS(GTheta*0.5))**KM\n END IF\n VAL_REAL = DCOS(KM*Phi)*COEF*SUM\n VAL_IM = DSIN(KM*Phi)*COEF*SUM\n ELSE\n VAL_REAL = ZERO\n VAL_IM = ZERO\n END IF\n RETURN\n END SUBROUTINE Y_K\n", "meta": {"hexsha": "62d3c3920c7f43a91c226e2016151e72581a5d5f", "size": 3097, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Y_k.f90", "max_stars_repo_name": "compas/cf_hamiltonian", "max_stars_repo_head_hexsha": "1f092bea271ed43829890466fa17f064a58082c7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Y_k.f90", "max_issues_repo_name": "compas/cf_hamiltonian", "max_issues_repo_head_hexsha": "1f092bea271ed43829890466fa17f064a58082c7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-01-11T16:42:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-11T16:42:53.000Z", "max_forks_repo_path": "Y_k.f90", "max_forks_repo_name": "compas/cf_hamiltonian", "max_forks_repo_head_hexsha": "1f092bea271ed43829890466fa17f064a58082c7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.75, "max_line_length": 72, "alphanum_fraction": 0.3128834356, "num_tokens": 788, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897442783527, "lm_q2_score": 0.8198933447152498, "lm_q1q2_score": 0.7713472501101831}} {"text": "MODULE FDLIB\n IMPLICIT NONE\n CONTAINS\n!-----------------------------------------------------------\n INTEGER FUNCTION FCTL(N)\n IMPLICIT NONE\n INTEGER :: I, N\n IF (N == 0) THEN\n FCTL = 1\n ELSE\n FCTL = 1\n DO I = 1,N\n FCTL = FCTL*I\n END DO\n END IF\n END FUNCTION FCTL\n!----------------------------------------------------------- \n FUNCTION COMB(K,N) RESULT(KCN)\n IMPLICIT NONE\n INTEGER :: K, N\n INTEGER :: NUM, DENOM\n REAL :: KCN\n NUM = FCTL(N)\n DENOM = FCTL(K)*FCTL(N-K)\n KCN = NUM/DENOM\n END FUNCTION COMB\n!-----------------------------------------------------------\n FUNCTION FD(I) RESULT(COEFFS)\n IMPLICIT NONE\r\n INTEGER, INTENT(IN) :: I\n INTEGER, DIMENSION(0:I) :: COEFFS\n INTEGER :: J, Q, R\n R = MOD(I,2)\n IF (R == 0) THEN\n Q = I/2\n ELSE\n Q = (I-1)/2\n ENDIF\n DO J = 0,I\n COEFFS(J) = ((-1)**(Q-J))*COMB(J,I)\n END DO\n END FUNCTION FD\n!-----------------------------------------------------------\nEND MODULE FDLIB\n\n", "meta": {"hexsha": "5e55b92ddfe775c63750a6b2f6a8bad0266ae0dd", "size": 951, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Parabolic_Equation/2DPE/.archives/fdlib.f03", "max_stars_repo_name": "codorkh/AcousticPE", "max_stars_repo_head_hexsha": "a787496a7800d56743fc606a43acbe9e32de35e0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-03-30T14:02:10.000Z", "max_stars_repo_stars_event_max_datetime": "2017-03-30T14:02:10.000Z", "max_issues_repo_path": "Parabolic_Equation/2DPE/.archives/fdlib.f03", "max_issues_repo_name": "codorkh/infratopo", "max_issues_repo_head_hexsha": "a787496a7800d56743fc606a43acbe9e32de35e0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Parabolic_Equation/2DPE/.archives/fdlib.f03", "max_forks_repo_name": "codorkh/infratopo", "max_forks_repo_head_hexsha": "a787496a7800d56743fc606a43acbe9e32de35e0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.6739130435, "max_line_length": 61, "alphanum_fraction": 0.4384858044, "num_tokens": 301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897558991953, "lm_q2_score": 0.8198933293122507, "lm_q1q2_score": 0.7713472451470509}} {"text": " SUBROUTINE MAPLL (X,Y,ALAT,ALONG,SLAT,SGN,E,RE)\nC$*****************************************************************************\nC$ *\nC$ *\nC$ DESCRIPTION: *\nC$ *\nC$ This subroutine converts from geodetic latitude and longitude to Polar *\nC$ Stereographic (X,Y) coordinates for the polar regions. The equations *\nC$ are from Snyder, J. P., 1982, Map Projections Used by the U.S. *\nC$ Geological Survey, Geological Survey Bulletin 1532, U.S. Government *\nC$ Printing Office. See JPL Technical Memorandum 3349-85-101 for further *\nC$ details. *\nC$ *\nC$ *\nC$ ARGUMENTS: *\nC$ *\nC$ Variable Type I/O Description *\nC$ *\nC$ ALAT REAL*4 I Geodetic Latitude (degrees, +90 to -90) *\nC$ ALONG REAL*4 I Geodetic Longitude (degrees, 0 to 360) *\nC$ X REAL*4 O Polar Stereographic X Coordinate (km) *\nC$ Y REAL*4 O Polar Stereographic Y Coordinate (km) *\nC$ *\nC$ *\nC$ Written by C. S. Morris - April 29, 1985 *\nC$ Revised by C. S. Morris - December 11, 1985 *\nC$ \t *\nC$ Revised by V. J. Troisi - January 1990 *\nC$ SGN - provides hemisphere dependency (+/- 1) *\nC$\t\t Revised by Xiaoming Li - October 1996 *\nC$\t\t Corrected equation for RHO *\nC$*****************************************************************************\n REAL*4 X,Y,ALAT,ALONG,E,E2,CDR,PI,SLAT,MC\nC$*****************************************************************************\nC$ *\nC$ DEFINITION OF CONSTANTS: *\nC$ *\nC$ Conversion constant from degrees to radians = 57.29577951. *\n CDR=57.29577951\n E2=E*E\nC$ Pi=3.141592654. *\n PI=3.141592654\nC$ *\nC$*****************************************************************************\nC Compute X and Y in grid coordinates.\n IF (ABS(ALAT).LT.PI/2.) GOTO 250\n X=0.0\n Y=0.0\n GOTO 999\n 250 CONTINUE\n T=TAN(PI/4.-ALAT/2.)/((1.-E*SIN(ALAT))/(1.+E*SIN(ALAT)))**(E/2.)\n IF (ABS(90.-SLAT).LT.1.E-5) THEN\n RHO=2.*RE*T/((1.+E)**(1.+E)*(1.-E)**(1.-E))**(1/2.)\n ELSE\n SL=SLAT*PI/180.\n TC=TAN(PI/4.-SL/2.)/((1.-E*SIN(SL))/(1.+E*SIN(SL)))**(E/2.)\n MC=COS(SL)/SQRT(1.0-E2*(SIN(SL)**2))\n RHO=RE*MC*T/TC\n END IF\n Y=-RHO*SGN*COS(SGN*ALONG)\n X= RHO*SGN*SIN(SGN*ALONG)\n 999 CONTINUE\n END\n", "meta": {"hexsha": "b2f7dd038be411e45654c83d5bd8945676d02855", "size": 3823, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "locate/mapll.for", "max_stars_repo_name": "nsidc/polarstereo-latlon-convert-fortran", "max_stars_repo_head_hexsha": "27de036844ab50f4ea5a950e8d1498f79d6783f0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "locate/mapll.for", "max_issues_repo_name": "nsidc/polarstereo-latlon-convert-fortran", "max_issues_repo_head_hexsha": "27de036844ab50f4ea5a950e8d1498f79d6783f0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "locate/mapll.for", "max_forks_repo_name": "nsidc/polarstereo-latlon-convert-fortran", "max_forks_repo_head_hexsha": "27de036844ab50f4ea5a950e8d1498f79d6783f0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.734375, "max_line_length": 79, "alphanum_fraction": 0.2987182841, "num_tokens": 800, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172601537141, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7713438345635919}} {"text": "module module_rk\n\nuse module_types, only: dp\n\nimplicit none\n\ncontains\n! ...\n! =====================================================================\n! =====================================================================\n! ...\nfunction rk4(y,x,h,derivs) result(yout)\n\n! Given values for the variables y(1:n) and their derivatives dydx(1:n)\n! known at x, use the fourth-order Runge-Kutta method to advance the\n! solution over an interval h and return the incremented variable as\n! yout(1:n), which neet not be a distinct array from y. The user supplies\n! the subroutine derivs(x,y,dydx), which returns derivatives dydx at x.\n! Numerical Recipes\n\nreal(dp), dimension(:), intent(in) :: y\nreal(dp), intent(in) :: x,h\nreal(dp), dimension(size(y)) :: yout\nexternal derivs\n\n! ... Local variables\n! ...\nreal(dp) h6,hh,xh\nreal(dp), dimension(size(y)) :: dydx,dym,dyt,yt\n\nhh = h*0.5d0\nh6 = h/6.d0\nxh = x + hh\n\nCALL derivs (x,y,dydx)\nyt(:) = y(:) + hh*dydx(:) ! First step\n\nCALL derivs(xh,yt,dyt) ! Second step\nyt(:) = y(:) + hh*dyt(:)\n\nCALL derivs(xh,yt,dym) ! Third step\nyt(:) = y(:) + h*dym(:)\ndym(:) = dyt(:) + dym(:)\n\nCALL derivs(x+h,yt,dyt) ! Fourth step\n\n ! Accumulate increments with proper weights\nyout(:) = y(:) + h6*(dydx(:)+dyt(:)+2.d0*dym(:))\n\nreturn\nend function rk4\n! ...\n! =====================================================================\n! ...\nfunction rk5 (x,t,h,RHS) result(xn)\n\n! ... Given values for the variables x(1:n) and a function, RHS, returning\n! ... its derivatives dxdt(1:n), a fifth-order Runge-Kutta\n! ... method is used to advance the solution over an interval h and return\n! ... the incremented variable as xn(1:n).\n! ... The user must supply the subroutine RHS(t,x,dxdt) returning\n! ... derivatives dxdt at t.\n! ... Coefficients as in Butcher's Fifth Order\n! ... Quim Ballabrera, March 2017.\n\nreal(dp), intent(in) :: t,h\nreal(dp), dimension(:), intent(in) :: x\nreal(dp), dimension(size(x)) :: xn\nexternal :: RHS\n\n! ... Local variables\n! ...\nreal(dp), dimension(size(x)) :: k1,k2,k3,k4,k5,k6\n\nCALL RHS(t,x,k1)\nk1 = h*k1\n\nCALL RHS(t+0.25D0*h, x+0.25D0*k1, k2)\nk2 = h*k2\n\nCALL RHS(t+0.25D0*h, x+(k1+k2)/8.0D0, k3)\nk3 = h*k3\n\nCALL RHS(t+0.5D0*h, x-0.5D0*k2+k3, k4)\nk4 = h*k4\n\nCALL RHS(t+0.75D0*h, x+(3D0*k1+9D0*k4)/16.0D0, k5)\nk5 = h*k5\n\nCALL RHS(t+h, x+(-3.0D0*k1+2D0*k2+12.0D0*k3-12D0*k4+8D0*k5)/7.0D0, k6)\nk6 = h*k6\n\nxn(:) = x(:) + (7.0D0*k1(:) + 32.0D0*k3(:) + 12.0D0*k4(:) + &\n 32.0D0*k5(:) + 7.0D0*k6(:))/90.0D0\n\nreturn\nend function rk5\n! ...\n! ====================================================================\n\nend module module_rk\n", "meta": {"hexsha": "7b8d558924c3b5b7ae871d7d39f1de620b608716", "size": 2753, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/rungekutta.f90", "max_stars_repo_name": "quimbp/cosmo", "max_stars_repo_head_hexsha": "d0ca43fcb493c9f630719b8015be095d775a781f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-26T15:02:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-25T23:11:04.000Z", "max_issues_repo_path": "src/lib/rungekutta.f90", "max_issues_repo_name": "quimbp/cosmo", "max_issues_repo_head_hexsha": "d0ca43fcb493c9f630719b8015be095d775a781f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2018-06-25T10:13:31.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-16T11:15:20.000Z", "max_forks_repo_path": "src/lib/rungekutta.f90", "max_forks_repo_name": "quimbp/cosmo", "max_forks_repo_head_hexsha": "d0ca43fcb493c9f630719b8015be095d775a781f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-02T16:21:42.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-02T16:21:42.000Z", "avg_line_length": 26.9901960784, "max_line_length": 78, "alphanum_fraction": 0.5296040683, "num_tokens": 909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240090865197, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7713153613089436}} {"text": "!------------------------------------------------------------------------\n!EV The subroutines SPLINE and SPLINT can be used for interpolating a\n! function of one independent variable.\n!------------------------------------------------------------------------\n\nSUBROUTINE spline(x, y, n, yp1, ypn, y2)\n !\n ! Given arrays y(1:n) and x(1:n) containing a tabulated function and its\n ! independent variable, respectively, with x(1) < x(2) < ... < x(n), and given\n ! values yp1 and ypn for the 1st derivative of the interpolating function at\n ! the points 1 and n, respectively, this routine returns an array y2(1:n) of\n ! length n which contains the 2nd derivative of the interpolating function at\n ! the tabulated points x(i). If yp1 and/or ypn are equal to 10^30 or larger,\n ! the routine is signaled to set the corresponding boundary condition for a\n ! natural spline, with zero 2nd derivative on that boundary. From \"Numerical\n ! Recipes\", Ch. 3.3, p. 109.\n IMPLICIT NONE\n ! Passed variables:\n INTEGER n\n REAL x(n), y(n), yp1, ypn, y2(n)\n ! Local variables:\n INTEGER i, j, NMAX\n PARAMETER (NMAX = 500) ! Maximum expected value of n\n REAL p, qn, sig, un, u(NMAX)\n !\n if (yp1.gt..99e30) then\n ! Natural lower boundary condition:\n y2(1) = 0.e0\n u(1) = 0.e0\n else\n ! Specified 1st derivative yp1:\n y2(1) = -.5e0\n u(1) = (3.e0 / (x(2) - x(1))) * ((y(2) - y(1)) / (x(2) - x(1)) - yp1)\n endif\n ! We need at least N+1 points to construct an interpolating polynomial\n ! of degree N:\n if (n.lt.4) stop ' Too few points for cubic spline'\n !\n ! Decomposition loop of the tridiagonal algorithm.\n ! y2,u: temporary storage of the decomposed factors.\n do i = 2, n - 1\n sig = (x(i) - x(i - 1)) / (x(i + 1) - x(i - 1))\n p = sig * y2(i - 1) + 2.e0\n y2(i) = (sig - 1.e0) / p\n u(i) = (6.e0 * ((y(i + 1) - y(i)) / (x(i + 1) - x(i)) - (y(i) - y(i - 1))&\n / (x(i) - x(i - 1))) / (x(i + 1) - x(i - 1)) - sig * u(i - 1)) / p\n enddo\n if (ypn.gt..99e30) then\n ! Natural upper boundary condition:\n qn = 0.e0\n un = 0.e0\n else\n ! Specified 1st derivative ypn:\n qn = .5e0\n un = (3.e0 / (x(n) - x(n - 1))) * (ypn - (y(n) - y(n - 1)) / (x(n) - x(n - 1)))\n endif\n y2(n) = (un - qn * u(n - 1)) / (qn * y2(n - 1) + 1.e0)\n !\n ! Backsubstitution loop of the tridiagonal algorithm.\n do j = n - 1, 1, -1\n y2(j) = y2(j) * y2(j + 1) + u(j)\n enddo\n !\n return\nEND", "meta": {"hexsha": "f44af76ae6390c93b8398e4b54867cd2a533daa4", "size": 2582, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/spline.f90", "max_stars_repo_name": "tylern4/aao_rad_lund", "max_stars_repo_head_hexsha": "f82728b0958ed8d61d15b9f345a248a2e1e814b8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/spline.f90", "max_issues_repo_name": "tylern4/aao_rad_lund", "max_issues_repo_head_hexsha": "f82728b0958ed8d61d15b9f345a248a2e1e814b8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/spline.f90", "max_forks_repo_name": "tylern4/aao_rad_lund", "max_forks_repo_head_hexsha": "f82728b0958ed8d61d15b9f345a248a2e1e814b8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.7230769231, "max_line_length": 87, "alphanum_fraction": 0.5147172734, "num_tokens": 886, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646393, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.771271818244383}} {"text": "PROGRAM BENCHMARK\n USE ROOT\n\n REAL :: a = 0, b = 1\n REAL :: x, x_0 = 0.25, x_1 = 0.5, x_2 = 0.75\n REAL, EXTERNAL :: f, df\n\n INTEGER :: nroot \n INTEGER :: debug = 1\n\n nroot = BRACKET(f, a, b)\n PRINT 1000, nroot\n PRINT *\n\n PRINT 2000, a, b\n x = BISECTION(f, a, b, debug)\n PRINT *\n\n PRINT 3000, a, b \n x = FALSE_POSITION(f, a, b, debug)\n PRINT *\n \n PRINT 4000, x_0\n x = NEWTON_RAPHSON(f, df, x_0, debug)\n PRINT *\n\n PRINT 5000, x_0, x_1\n x = SECANT(f, x_0, x_1, debug)\n PRINT *\n\n PRINT 6000, x_0, x_1, x_2\n x = MUELLER(f, x_0, x_1, x_2, debug)\n\n ! format\n 1000 FORMAT ('There is ', I2, ' root(s)')\n 2000 FORMAT ('Bisection method: a = ', F7.3, ', b = ', F7.3)\n 3000 FORMAT ('False position method: a = ', F7.3, ', b = ', F7.3)\n 4000 FORMAT ('Newton-Raphson method: x_0 = ', F7.3)\n 5000 FORMAT ('Secant method: x_0 = ', F7.3, ', x_1 = ', F7.3)\n 6000 FORMAT ('Mueller method: x_0 = ', F7.3, ', x_1 = ', F7.3, ', x_2 = ', F7.3)\nEND PROGRAM BENCHMARK \n\nREAL FUNCTION f(x) \n IMPLICIT NONE \n\n REAL, INTENT(IN) :: x \n\n f = COS(x) - x * SIN(x) \nEND FUNCTION f\n\nREAL FUNCTION df(x) \n IMPLICIT NONE \n\n REAL, INTENT(IN) :: x \n\n df = -2 * SIN(x) - x * COS(x) \nEND FUNCTION df\n", "meta": {"hexsha": "df85ffa01cd375ed973bcd1b16d86fff2807c4bf", "size": 1306, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "drivers/fsolve.f90", "max_stars_repo_name": "vitduck/numerical-recipe", "max_stars_repo_head_hexsha": "0d025bd6c9a5b45af72c7691fb01cbfecf075ca6", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "drivers/fsolve.f90", "max_issues_repo_name": "vitduck/numerical-recipe", "max_issues_repo_head_hexsha": "0d025bd6c9a5b45af72c7691fb01cbfecf075ca6", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "drivers/fsolve.f90", "max_forks_repo_name": "vitduck/numerical-recipe", "max_forks_repo_head_hexsha": "0d025bd6c9a5b45af72c7691fb01cbfecf075ca6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.5172413793, "max_line_length": 84, "alphanum_fraction": 0.5191424196, "num_tokens": 520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669026, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.7711892376086399}} {"text": "! perfect_number.f90\n! Calculate Perfect numbers\n!\n! vim: set ft=fortran sw=2 ts=2 :\n\nmodule perfect_number\n implicit none\n private\n public :: perfect_numbers, perfect_numbers_realloc, to_string\n\ncontains\n\n pure logical function is_perfect (n)\n\n implicit none\n integer, intent( in ) :: n\n integer :: i, s, limit\n\n s = 0\n limit = int(sqrt(real(n)))\n do i = 1, (n-1)\n ! do i = 2, limit\n if (modulo(n, i) == 0) then\n s = s + i\n end if\n end do\n\n is_perfect = (s == n)\n\n end function is_perfect\n\n\n subroutine perfect_numbers_realloc (n, res)\n !use ISO_FORTRAN_ENV, only: ERROR_UNIT\n implicit none\n\n integer, intent( in ) :: n\n integer, dimension(:), allocatable, intent( out ) :: res\n integer :: i\n\n do i = 1, n\n if (is_perfect(i)) then\n if (allocated(res)) then\n res = [res, i]\n else\n res = [i]\n end if\n end if\n end do\n\n end subroutine perfect_numbers_realloc\n\n\n subroutine perfect_numbers (n, res)\n use ISO_FORTRAN_ENV, only: ERROR_UNIT\n implicit none\n\n integer, intent( in ) :: n\n integer, dimension(:), allocatable, intent( out ) :: res\n\n logical, dimension(:), allocatable :: flags\n integer :: s, i, c, idx\n\n ! flag perfect numbers\n allocate(flags(1:n), stat=s)\n if (s /= 0) then\n write (ERROR_UNIT,*) \"Error allocating data\"\n stop -1\n end if\n flags = .false.\n c = 0\n\n !$omp parallel do private(i), schedule(dynamic)\n do i = 1, n\n if (is_perfect(i)) then\n flags(i) = .true.\n c = c + 1\n end if\n end do\n !$omp end parallel do\n\n ! copy perfect numbers to output array\n allocate(res(1:c), stat=s)\n if (s /= 0) then\n write (ERROR_UNIT,*) \"Error allocating data\"\n stop -1\n end if\n\n idx = 1\n do i = 1, n\n if (flags(i)) then\n res(idx) = i\n idx = idx + 1\n end if\n end do\n\n end subroutine perfect_numbers\n\n subroutine to_string(ary, str)\n use ISO_FORTRAN_ENV, only: ERROR_UNIT\n implicit none\n\n integer, dimension(:), intent( in ) :: ary\n character(:), allocatable, intent( out ) :: str\n character(5) :: num_str\n\n integer :: len, s, i\n\n len = size(ary)\n\n allocate(character(8*len) :: str, stat=s)\n if (s /= 0) then\n write (ERROR_UNIT,*) \"Error allocating data\"\n stop -1\n end if\n\n ! fill-in output string\n str = \"\"\n do i = 1, (len-1)\n write(num_str, '(I5)') ary(i)\n str = str // num_str // \", \"\n end do\n write(num_str, '(I5)') ary(len)\n str = str // num_str\n\n end subroutine to_string\n\nend module perfect_number\n", "meta": {"hexsha": "da4d53277e726d24f6b47db4f7407e9aafcc53aa", "size": 2631, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/Benchmark/src/perfect_number.f90", "max_stars_repo_name": "kkirstein/proglang-playground", "max_stars_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fortran/Benchmark/src/perfect_number.f90", "max_issues_repo_name": "kkirstein/proglang-playground", "max_issues_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran/Benchmark/src/perfect_number.f90", "max_forks_repo_name": "kkirstein/proglang-playground", "max_forks_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.3953488372, "max_line_length": 63, "alphanum_fraction": 0.5758266819, "num_tokens": 791, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355092, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.7711892235091699}} {"text": "!Matric Multiplication\nprogram Intrinsic_FUnction\n implicit none\n\n INTEGER :: i, j\n INTEGER, DIMENSION(2, 2) :: matA, matB, matC\n\n data matA(1, :)/1, 2/\n data matA(2, :)/2, 1/\n\n matB = reshape((/5, 6, 7, 8/), (/2, 2/))\n\n matC = MATMUL(matA, matB)\n\n print *, \"Matric Multiplication of MAtA and MAtb is\"\n\n do i = 1, 2\n print *, (matC(i, j), j=1, 2)\n end do\n\nend program Intrinsic_FUnction\n", "meta": {"hexsha": "9d6e602364635727fcc064d8ca58addcc47f2586", "size": 425, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Matric_Multiplication.f95", "max_stars_repo_name": "SusheelThapa/Code-With-FORTRAN", "max_stars_repo_head_hexsha": "4956fc1db5a0ce7e88883fdd787a3fd13a3b7fda", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Matric_Multiplication.f95", "max_issues_repo_name": "SusheelThapa/Code-With-FORTRAN", "max_issues_repo_head_hexsha": "4956fc1db5a0ce7e88883fdd787a3fd13a3b7fda", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Matric_Multiplication.f95", "max_forks_repo_name": "SusheelThapa/Code-With-FORTRAN", "max_forks_repo_head_hexsha": "4956fc1db5a0ce7e88883fdd787a3fd13a3b7fda", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.3181818182, "max_line_length": 56, "alphanum_fraction": 0.5764705882, "num_tokens": 169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7711840280117322}} {"text": "SUBROUTINE LUDCMPX (A , INDX , D , N , NP , ERROR )\r\nIMPLICIT NONE\r\n!PARAMETER DECLARATION\r\nINTEGER, PARAMETER:: NMAX=50\r\n!DATA DECLARATION\r\nREAL(8) R0 /0.0D0/\r\nREAL(8) R1 /1.0D0/\r\nREAL(8) TINY /1.0D-19/\r\nCHARACTER\t NAME*6\r\nDATA NAME/'LUDCMP'/\r\n!SCALAR VARIABLES FROM ARGUMENTS\r\nINTEGER N, NP\r\nLOGICAL ERROR\r\nREAL(8) D\r\n!ARRAYS FROM ARGUMENTS\r\nREAL(8), DIMENSION(NP,NP):: A\r\nINTEGER, DIMENSION(N):: INDX\r\n!LOCAL SCALAR VARIABLES\r\nINTEGER I, J, K, IMAX\r\nREAL(8) AAMAX, SUM, DUM\r\n!LOCAL ARRAYS\r\nREAL(8), DIMENSION(N):: VV\r\n!INTIALIZE LOCAL SCALAR VARIABLES\r\nI=0 ; J=0 ; K=0 ; IMAX=0\r\nAAMAX=R0 ; SUM=R0 ; DUM=R0 ; VV=R0\r\n!***********************************************************************\r\n! Routine to do LU decomposition\r\n! See NUMERICAL RECIPES p35.\r\n!*ACRONYM\r\n! LU_DeCOmPosition\r\n!*DESCRIPTION\r\n!*EXTERNAL\r\n! Arrays\r\n!=A - LU decomposed matrix\r\n!=INDX - Permutation vector\r\n! Variables\r\n!=D - Row interchange indicator\r\n! N - Size of the problem\r\n! NP - Physical size of A matrix ( NP >= N )\r\n! ERROR - Error flag\r\n!*INTERNAL\r\n! Arrays\r\n! VV - store the implicit scalling of each rows\r\n!***********************************************************************\r\n! Loop over each rows to get the implicit scalling factors\r\n! --------------------------------------------------------\r\nDO 12 I=1,N\r\n\tAAMAX=R0\r\n DO 11 J=1,N\r\n \tIF (ABS(A(I,J)).GT.AAMAX) AAMAX=ABS(A(I,J))\r\n \t11 CONTINUE\r\n IF(AAMAX.EQ.R0)THEN\r\n\t\tERROR=.TRUE.\r\n \tGOTO 999\r\n ENDIF\r\n VV(I)=R1/AAMAX\r\n12 CONTINUE\r\n! Loop over columns of Crout's methods\r\n! ------------------------------------\r\nDO 19 J=1,N\r\n\tIF (J.GT.1) THEN\r\n! Calculate upper triangle components Bij see equation(2.3.12), except i=j\r\n \tDO 14 I=1,J-1\r\n \t\tSUM=A(I,J)\r\n \t\tIF (I.GT.1)THEN\r\n \t\t\tDO 13 K=1,I-1\r\n \t\t\tIF(ABS(A(I,K)).LT.TINY.AND.ABS(A(K,J)).LT.TINY)GOTO 13\r\n! If A(I,K) and A(K,J) are very small, skip the following line\r\n \t\t\tSUM=SUM-A(I,K)*A(K,J)\r\n \t\t\t\t13 CONTINUE\r\n \t\t\tA(I,J)=SUM\r\n \t\tENDIF\r\n \t\t14 CONTINUE\r\n\tENDIF\r\n! Initialize for the search for largest pivot element\r\n AAMAX=R0\r\n! Calculate diagonal components Bij see equation(2.3.12) ,i=j, and\r\n! lower triangle components aij see equation 2.3.13, i=j+1,..N\r\n DO 16 I=J,N\r\n \tSUM=A(I,J)\r\n \tIF (J.GT.1)THEN\r\n \t\tDO 15 K=1,J-1\r\n \t\t\tIF(ABS(A(I,K)).LT.TINY.AND.ABS(A(K,J)).LT.TINY)GOTO 15\r\n! If A(I,K) and A(K,J) are very small, skip the following line.\r\n \t\t\tSUM=SUM-A(I,K)*A(K,J)\r\n \t\t\t15 CONTINUE\r\n \t\tA(I,J)=SUM\r\n \tENDIF\r\n! Find largest pivot element\r\n \tDUM=VV(I)*ABS(SUM)\r\n \tIF (DUM.GE.AAMAX) THEN\r\n \t\tIMAX=I\r\n \t\tAAMAX=DUM\r\n \tENDIF\r\n \t16 CONTINUE\r\n! Interchange rows\r\n IF(J.NE.IMAX)THEN\r\n \tDO 17 K=1,N\r\n \t\tDUM=A(IMAX,K)\r\n \t\tA(IMAX,K)=A(J,K)\r\n \t\tA(J,K)=DUM\r\n \t\t17 CONTINUE\r\n! Change sign of row channge indicator and interchange scale factor\r\n \tD=-D\r\n \tVV(IMAX)=VV(J)\r\n\tENDIF\r\n! record interchange row number\r\n INDX(J)=IMAX\r\n! Divided by the pivot element and get final aij values, see equation 2.3.13,\r\n! i=j+1,..N\r\n IF(J.NE.N)THEN\r\n \tIF(ABS(A(J,J)).LT.TINY)A(J,J)=TINY\r\n \tDUM=R1/A(J,J)\r\n \tDO 18 I=J+1,N\r\n \t\tA(I,J)=A(I,J)*DUM\r\n \t\t18 CONTINUE\r\n\tENDIF\r\n! Go back for next column\r\n19 CONTINUE\r\nIF(ABS(A(N,N)).LT.TINY)A(N,N)=TINY\r\n999 CONTINUE\r\nRETURN\r\nEND\r\n", "meta": {"hexsha": "3cb48025a85c9f2e6511c3d5f9a3d67e79d69429", "size": 3622, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utils/LUDCMPX.f90", "max_stars_repo_name": "iarlopes/GPROPT", "max_stars_repo_head_hexsha": "e5571ef610198283909cd489d5945edde4ae9906", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-03T18:22:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-26T15:37:06.000Z", "max_issues_repo_path": "src/utils/LUDCMPX.f90", "max_issues_repo_name": "iarlopes/GPROPT", "max_issues_repo_head_hexsha": "e5571ef610198283909cd489d5945edde4ae9906", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/utils/LUDCMPX.f90", "max_forks_repo_name": "iarlopes/GPROPT", "max_forks_repo_head_hexsha": "e5571ef610198283909cd489d5945edde4ae9906", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2096774194, "max_line_length": 78, "alphanum_fraction": 0.5146327996, "num_tokens": 1160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391600697869, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7711840242306381}} {"text": "module gamma_funcs\n use iso_fortran_env\n implicit none\ncontains\n elemental function digamma (x)\n\n !*****************************************************************************80\n !\n !! DIGAMMA calculates DIGAMMA ( X ) = d ( LOG ( GAMMA ( X ) ) ) / dX\n !\n ! Licensing:\n !\n ! This code is distributed under the GNU LGPL license.\n !\n ! Modified:\n !\n ! 20 March 2016\n !\n ! Author:\n !\n ! Original FORTRAN77 version by Jose Bernardo.\n ! FORTRAN90 version by John Burkardt.\n ! iso_fortran_env by Simone Marsili.\n !\n ! Reference:\n !\n ! Jose Bernardo,\n ! Algorithm AS 103:\n ! Psi ( Digamma ) Function,\n ! Applied Statistics,\n ! Volume 25, Number 3, 1976, pages 315-317.\n !\n ! Parameters:\n !\n ! Input, real(real64) X, the argument of the digamma function.\n ! 0 < X.\n !\n !\n ! Output, real(real64) DIGAMMA, the value of the digamma function at X.\n !\n implicit none\n\n real(real64) :: digamma\n real(real64), intent(in) :: x\n real(real64), parameter :: c = 8.5_real64\n real(real64), parameter :: euler_mascheroni = 0.57721566490153286060_real64\n real(real64) r\n real(real64) x2\n !\n ! Check the input.\n !\n if ( x <= 0.0_real64 ) then\n digamma = 0.0_real64\n return\n end if\n !\n ! Approximation for small argument.\n !\n if ( x <= 0.000001_real64 ) then\n digamma = - euler_mascheroni - 1.0_real64 / x + 1.6449340668482264365_real64 * x\n return\n end if\n !\n ! Reduce to DIGAMA(X + N).\n !\n digamma = 0.0_real64\n x2 = x\n\n do while ( x2 < c )\n digamma = digamma - 1.0_real64 / x2\n x2 = x2 + 1.0_real64\n end do\n !\n ! Use Stirling's (actually de Moivre's) expansion.\n !\n r = 1.0_real64 / x2\n\n digamma = digamma + log ( x2 ) - 0.5_real64 * r\n\n r = r * r\n\n digamma = digamma &\n - r * ( 1.0_real64 / 12.0_real64 &\n - r * ( 1.0_real64 / 120.0_real64 &\n - r * ( 1.0_real64 / 252.0_real64 &\n - r * ( 1.0_real64 / 240.0_real64 &\n - r * ( 1.0_real64 / 132.0_real64 ) ) ) ) )\n\n end function digamma\n\n elemental function trigamma (x)\n\n !*****************************************************************************80\n !\n !! TRIGAMMA calculates trigamma(x) = d^2 log(gamma(x)) / dx^2\n !\n ! Modified:\n !\n ! 19 January 2008\n !\n ! Author:\n !\n ! Original FORTRAN77 version by BE Schneider.\n ! FORTRAN90 version by John Burkardt.\n ! iso_fortran_env by Simone Marsili.\n !\n ! Reference:\n !\n ! BE Schneider,\n ! Algorithm AS 121:\n ! Trigamma Function,\n ! Applied Statistics,\n ! Volume 27, Number 1, pages 97-99, 1978.\n !\n ! Parameters:\n !\n ! Input, real(real64) X, the argument of the trigamma function.\n ! 0 < X.\n !\n !\n ! Output, real(real64) TRIGAMMA, the value of the trigamma function.\n !\n implicit none\n\n real(real64) :: trigamma\n real(real64), intent(in) :: x\n\n real(real64), parameter :: a = 0.0001_real64\n real(real64), parameter :: b = 5.0_real64\n real(real64), parameter :: b2 = 0.1666666667_real64\n real(real64), parameter :: b4 = -0.03333333333_real64\n real(real64), parameter :: b6 = 0.02380952381_real64\n real(real64), parameter :: b8 = -0.03333333333_real64\n\n real(real64) y\n real(real64) z\n !\n ! Check the input.\n !\n if ( x <= 0.0_real64 ) then\n trigamma = 0.0_real64\n return\n end if\n\n z = x\n !\n ! Use small value approximation if X <= A.\n !\n if ( x <= a ) then\n trigamma = 1.0_real64 / x / x\n return\n end if\n !\n ! Increase argument to ( X + I ) >= B.\n !\n trigamma = 0.0_real64\n\n do while ( z < b )\n trigamma = trigamma + 1.0_real64 / z / z\n z = z + 1.0_real64\n end do\n !\n ! Apply asymptotic formula if argument is B or greater.\n !\n y = 1.0_real64 / z / z\n\n trigamma = trigamma + 0.5_real64 * &\n y + ( 1.0_real64 &\n + y * ( b2 &\n + y * ( b4 &\n + y * ( b6 &\n + y * b8 )))) / z\n\n end function trigamma\n\n elemental function quadgamma (x)\n ! computes \\psi_2(x) = d^3 log(gamma(x)) / dx^3 = d^2 \\psi(x) / dx^2\n ! Simone Marsili\n implicit none\n\n real(real64) :: quadgamma\n real(real64), intent(in) :: x\n\n real(real64), parameter :: a = 0.0001_real64\n real(real64), parameter :: b = 5.0_real64\n real(real64) z\n ! Check the input.\n if ( x <= 0.0_real64 ) then\n quadgamma = 0.0_real64\n return\n end if\n\n ! Use small value approximation if X <= A.\n if ( x <= a ) then\n quadgamma = - gamma(3.0_real64) / x**3\n return\n end if\n\n ! Increase argument to ( X + I ) >= B.\n quadgamma = 0.0_real64\n z = x\n do while ( z < b )\n quadgamma = quadgamma - 2.0_real64 / z**3\n z = z + 1.0_real64\n end do\n\n ! Apply asymptotic formula if argument is B or greater.\n z = 1/z\n quadgamma = quadgamma - z**2 - z**3 - 0.5*z**4\n\n end function quadgamma\n\nend module gamma_funcs\n", "meta": {"hexsha": "1c6ec100f7e9a8e4e534e1f9fcabeefb3407ca93", "size": 5198, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ndd/exts/gamma.f90", "max_stars_repo_name": "ccattuto/ndd", "max_stars_repo_head_hexsha": "de9864f79e0b4ad026f117e78f977bf8d6235f99", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ndd/exts/gamma.f90", "max_issues_repo_name": "ccattuto/ndd", "max_issues_repo_head_hexsha": "de9864f79e0b4ad026f117e78f977bf8d6235f99", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ndd/exts/gamma.f90", "max_forks_repo_name": "ccattuto/ndd", "max_forks_repo_head_hexsha": "de9864f79e0b4ad026f117e78f977bf8d6235f99", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.2897196262, "max_line_length": 87, "alphanum_fraction": 0.5242400923, "num_tokens": 1700, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482723, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7711575837398033}} {"text": "! --------------------------------------------------------------------\n!\n! Copyright (C) 2015 Rocco Meli\n!\n! This program is free software: you can redistribute it and/or modify\n! it under the terms of the GNU General Public License as published by\n! the Free Software Foundation, either version 3 of the License, or\n! (at your option) any later version.\n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n! GNU General Public License for more details.\n!\n! You should have received a copy of the GNU General Public License\n! along with this program. If not, see .\n!\n! ---------------------------------------------------------------------\n\nMODULE OVERLAP\n\n USE CONSTANTS\n USE FACT\n USE GAUSSIAN\n USE LA\n\n CONTAINS\n\n FUNCTION Si(a,b,aa,bb,Rai,Rbi,Ri)\n ! ------------------------------------------------------------------------------------------------\n ! Compute overlap integral between two unnormalized Cartesian Gaussian functions along direction i\n ! ------------------------------------------------------------------------------------------------\n\n IMPLICIT NONE\n\n ! INPUT\n INTEGER, intent(in) :: a,b ! Angular momentum coefficients of the Gaussians along direction i\n REAL*8, intent(in) :: aa, bb ! Exponential coefficients of the Gaussians\n REAL*8, intent(in) :: Rai, Rbi ! Centers of the Gaussians\n REAL*8, intent(in) :: Ri ! Center of the Gaussians product\n\n ! INTERMEDIATE VARIABLE\n REAL*8 :: tmp\n INTEGER :: i ! Loop index\n INTEGER :: j ! Loop index\n\n ! OUTPUT\n REAL*8 :: Si\n\n Si = 0.0D0\n\n DO i = 0, a\n DO j = 0, b\n IF (MOD(i+j,2) == 0) THEN\n tmp = binom(a,i) * binom(b,j) * factorial2(i + j - 1)\n tmp = tmp * (Ri-Rai)**(a-i)\n tmp = tmp * (Ri-Rbi)**(b-j)\n tmp = tmp / (2.0D0 * (aa + bb))**((i + j) / 2.0D0)\n\n Si = Si + tmp\n END IF\n END DO\n END DO\n END FUNCTION Si\n\n\n\n FUNCTION overlap_coeff(ax,ay,az,bx,by,bz,aa,bb,Ra,Rb) result(S)\n ! -----------------------------------------------------------------\n ! Compute overlap integral between two Cartesian Gaussian functions\n ! -----------------------------------------------------------------\n !\n ! Source:\n ! The Mathematica Journal\n ! Evaluation of Gaussian Molecular Integrals\n ! I. Overlap Integrals\n ! Minhhuy Hô and Julio Manuel Hernández-Pérez\n !\n ! -----------------------------------------------------------------\n\n IMPLICIT NONE\n\n ! INPUT\n INTEGER, intent(in) :: ax, ay, az, bx, by, bz ! Angular momentum coefficients\n REAL*8, intent(in) :: aa, bb ! Exponential Gaussian coefficients\n REAL*8, dimension(3), intent(in) :: Ra, Rb ! Gaussian centers\n\n ! INTERMEDIATE VARIABLES\n REAL*8 :: pp ! Gaussian produc exponential coefficient\n REAL*8, dimension(3) :: Rp ! Gaussian produc center\n REAL*8 :: cp ! Gaussian product multiplicative constant\n\n ! OUTPUT\n REAL*8 :: S\n\n CALL gaussian_product(aa,bb,Ra,Rb,pp,Rp,cp) ! Compute PP, RP and CP\n\n S = 1\n S = S * Si(ax,bx,aa,bb,Ra(1),Rb(1),Rp(1)) ! Overlap along x\n S = S * Si(ay,by,aa,bb,Ra(2),Rb(2),Rp(2)) ! Overlap along y\n S = S * Si(az,bz,aa,bb,Ra(3),Rb(3),Rp(3)) ! Overlap along z\n S = S * norm(ax,ay,az,aa) * norm(bx,by,bz,bb) ! Normalization of Gaussian functions\n S = S * cp ! Gaussian product factor\n S = S * (PI / pp)**(3./2.) ! Solution of Gaussian integral\n\n END FUNCTION overlap_coeff\n\n ! ------------------\n ! OBARA-SAIKA SCHEME\n ! ------------------\n\n FUNCTION S00(aa,bb,Rai,Rbi)\n ! -----------------------------------------------------------\n ! Compute overlap between Gaussian with zero angular momentum\n ! -----------------------------------------------------------\n !\n ! Source:\n ! T. Helgaker, P. Jørgensen and J. Olsen\n ! Molecular Electronic-Structure Theory\n ! Wiley\n ! 2000\n !\n ! -----------------------------------------------------------\n\n IMPLICIT NONE\n\n ! INPUT\n REAL*8, intent(in) :: aa, bb ! Exponential coefficients of the Gaussians\n REAL*8, intent(in) :: Rai, Rbi ! Centers of the Gaussians\n\n ! OUTPUT\n REAL*8 :: S00\n\n S00 = DSQRT(PI / (aa + bb)) * DEXP(-(aa * bb) / (aa + bb) * (Rai - Rbi)**2.0D0)\n\n END FUNCTION S00\n\n\n\n FUNCTION Sij(a,b,aa,bb,Rai,Rbi,Rpi)\n ! ------------------------------------------------------------------------\n ! Compute overlap between Gaussian along one direction using OS recursion.\n ! ------------------------------------------------------------------------\n !\n ! Source:\n ! T. Helgaker, P. Jørgensen and J. Olsen\n ! Molecular Electronic-Structure Theory\n ! Wiley\n ! 2000\n !\n ! ------------------------------------------------------------------------\n\n IMPLICIT NONE\n\n ! INPUT\n INTEGER, intent(in) :: a,b ! Angular momentum coefficients of the Gaussians along direction i\n REAL*8, intent(in) :: aa, bb ! Exponential coefficients of the Gaussians\n REAL*8, intent(in) :: Rai, Rbi ! Centers of the Gaussians\n REAL*8, intent(in) :: Rpi ! Center of Gaussian product\n\n ! INTERMEDIATE VARIABLE\n REAL*8, dimension(-1:a+1,-1:b+1) :: S ! Vector of overlap coefficients\n INTEGER :: i, j\n\n ! OUTPUT\n REAL*8 :: Sij ! Overlap integral\n\n S(-1,:) = 0.0D0\n S(:,-1) = 0.0D0\n\n S(0,0) = S00(aa,bb,Rai,Rbi)\n\n DO i = 0, a\n DO j = 0, b\n S(i+1,j) = (Rpi - Rai) * S(i,j) + 1.0D0 / (2 * (aa+bb)) * (i * S(i-1,j) + j * S(i,j-1))\n S(i,j+1) = (Rpi - Rbi) * S(i,j) + 1.0D0 / (2 * (aa+bb)) * (i * S(i-1,j) + j * S(i,j-1))\n END DO\n END DO\n\n Sij = S(a,b)\n\n END FUNCTION Sij\n\n FUNCTION overlap_coeff_OS(ax,ay,az,bx,by,bz,aa,bb,Ra,Rb) result(S)\n ! ------------------------------------------------------------------------------------\n ! Compute overlap integral between two Cartesian Gaussian functions using OS recursion\n ! ------------------------------------------------------------------------------------\n\n IMPLICIT NONE\n\n ! INPUT\n INTEGER, intent(in) :: ax, ay, az, bx, by, bz ! Angular momentum coefficients\n REAL*8, intent(in) :: aa, bb ! Exponential Gaussian coefficients\n REAL*8, dimension(3), intent(in) :: Ra, Rb ! Gaussian centers\n\n ! INTERMEDIATE VARIABLES\n REAL*8 :: pp ! Gaussian produc exponential coefficient\n REAL*8, dimension(3) :: Rp ! Gaussian produc center\n REAL*8 :: cp ! Gaussian product multiplicative constant\n\n ! OUTPUT\n REAL*8 :: S\n\n CALL gaussian_product(aa,bb,Ra,Rb,pp,Rp,cp) ! Compute PP, RP and CP\n\n S = 1\n S = S * Sij(ax,bx,aa,bb,Ra(1),Rb(1),Rp(1)) ! Overlap along x\n S = S * Sij(ay,by,aa,bb,Ra(2),Rb(2),Rp(2)) ! Overlap along y\n S = S * Sij(az,bz,aa,bb,Ra(3),Rb(3),Rp(3)) ! Overlap along z\n S = S * norm(ax,ay,az,aa) * norm(bx,by,bz,bb) ! Normalization of Gaussian functions\n\n END FUNCTION overlap_coeff_OS\n\n\n\n ! -------------\n ! OVERLAP MARIX\n ! -------------\n SUBROUTINE S_overlap(Kf,c,basis_D,basis_A,basis_L,basis_R,S)\n ! ----------------------------------------------\n ! Compute overlap matrix between basis function.\n ! ----------------------------------------------\n\n IMPLICIT NONE\n\n ! TODO Allow flexibility for basis sets other than STO-3G\n INTEGER, intent(in) :: c ! Number of contractions per basis function\n\n ! INPUT\n INTEGER, intent(in) :: Kf ! Number of basis functions\n REAL*8, dimension(Kf,3), intent(in) :: basis_R ! Basis set niclear positions\n INTEGER, dimension(Kf,3), intent(in) :: basis_L ! Basis set angular momenta\n REAL*8, dimension(Kf,3), intent(in) :: basis_D ! Basis set contraction coefficients\n REAL*8, dimension(Kf,3), intent(in) :: basis_A ! Basis set exponential contraction coefficients\n\n ! INTERMEDIATE VARIABLES\n INTEGER :: i,j,k,l\n REAL*8 :: tmp\n\n ! OUTPUT\n REAL*8, dimension(Kf,Kf), intent(out) :: S\n\n S(:,:) = 0.0D0\n\n DO i = 1,Kf\n DO j = 1,Kf\n DO k = 1,c\n DO l = 1,c\n tmp = basis_D(i,k) * basis_D(j,l)\n tmp = tmp * overlap_coeff_OS( basis_L(i,1),& ! lx for basis function i\n basis_L(i,2),& ! ly for basis function i\n basis_L(i,3),& ! lz for basis function i\n basis_L(j,1),& ! lx for basis function j\n basis_L(j,2),& ! ly for basis function j\n basis_L(j,3),& ! lz for basis function j\n basis_A(i,k),& ! Exponential coefficient for basis function i, contraction k\n basis_A(j,l),& ! Exponential coefficient for basis function j, contraction l\n basis_R(i,:),& ! Center of basis function i\n basis_R(j,:)) ! Center of basis function j\n\n S(i,j) = S(i,j) + tmp\n END DO ! l\n END DO ! k\n END DO ! j\n END DO ! i\n\n END SUBROUTINE S_overlap\n\n\n SUBROUTINE X_transform(Kf,SS,X)\n\n IMPLICIT NONE\n\n ! INPUT\n INTEGER, intent(in) :: Kf ! Basis set size\n REAl*8, dimension(Kf,Kf), intent(in) :: SS ! Overlap matrix S\n\n ! INTERMEDIATE VARIABLES\n REAL*8, dimension(Kf) :: sss ! Temporal storage of eigenvalues\n REAL*8, dimension(Kf,Kf) :: S_sqrt ! Inverse square root of S\n REAL*8, dimension(Kf,Kf) :: U ! Temporal storage of eigenvectors\n INTEGER :: i\n\n ! OUTPUT\n REAL*8, dimension(Kf,Kf), intent(out) :: X ! Basi set orthogonalization matrix\n\n CALL EIGS(Kf,SS,U,sss)\n\n S_sqrt(:,:) = 0.0D0 ! Initialize U\n\n ! Store square of eigenvectors as a diagonal matrix in U\n DO i = 0, Kf\n S_sqrt(i,i) = (sss(i))**(-0.5D0)\n END DO\n\n X = MATMUL(U,S_sqrt)\n\n END SUBROUTINE\n\n\n\n\nEND MODULE OVERLAP\n", "meta": {"hexsha": "854315ba9d4640b8fa2c41bb70b1d42bae35b82a", "size": 12024, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran90/overlap.f90", "max_stars_repo_name": "RMeli/Hartree-Fock", "max_stars_repo_head_hexsha": "dda0102ab2a88f3f2f666c2479a858140505ea60", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2016-09-16T09:26:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T16:09:53.000Z", "max_issues_repo_path": "Fortran90/overlap.f90", "max_issues_repo_name": "RMeli/Hartree-Fock", "max_issues_repo_head_hexsha": "dda0102ab2a88f3f2f666c2479a858140505ea60", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran90/overlap.f90", "max_forks_repo_name": "RMeli/Hartree-Fock", "max_forks_repo_head_hexsha": "dda0102ab2a88f3f2f666c2479a858140505ea60", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2016-01-20T13:47:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-28T03:18:22.000Z", "avg_line_length": 39.5526315789, "max_line_length": 137, "alphanum_fraction": 0.4288090486, "num_tokens": 2758, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346504434783, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7711575808758928}} {"text": " PROGRAM PROG_91\n\nC Code from Kayode\nC *******************************************************************\nC * THIS PROGRAM CALCULATES THE YEARLY CASH FLOWS, THE CUMULATIVE *\nC * CASH FLOWS, DISCOUNT FACTORS AT A GIVEN RATE AND PRESENT *\nC * VALUES. THE PROGRAM FURTHER CALCULATES THE NET PRESENT VALUE, *\nC * PRESENT VALUE RATIO, THE AVERAGE RATE OF RETURN, THE NET *\nC * RETURN RATE, AND THE PAYBACK PERIOD. *\nC *******************************************************************\nC ARR = AVERAGE RATE OF RETURN\nC YCF = YEARLY CASH FLOW\nC DF = DISCOUNT FACTOR\nC CUCF = CUMULATIVE CASH FLOW\nC NPV = NET PRESENT VALUE\nC NOCF = NUMBER OF PROJECT LIFE EXCLUDING YEAR 0\nC NRR = NET RETURN RATE\nC PV = PRESENT VALUE\nC PVR = PRESENT VALUE RATIO\nC TIME = PAYBACK PERIOD\nC *******************************************************************\n\n REAL*8 YCF, DF, PV, NPV, CUCF\n EXTERNAL XNPV\n REAL NRR\n\n INTEGER TIME, TIME1\n\n DIMENSION YCF(0:100), DF(0:100), PV(0:100), CUCF(0:100)\nC\n OPEN (UNIT = 3, FILE = 'DATA91_B.DAT', STATUS ='OLD', ERR=18)\n OPEN (UNIT = 1, FILE = 'PRN_ECO_B')\nC READ THE NUMBER OF YEARLY CASH FLOWS EXCLUDING YEAR 0: NOCF\n READ (3, *, ERR=19) NOCF\nC READ THE ANNUAL DISCOUNT RATE IN PERCENTAGE: DISC\nC READ THE YEARLY CASH FLOW: YCF\n READ (3, *, ERR=19) DISC\n READ (3, *, ERR=19) (YCF(K), K = 0, NOCF)\n\n GO TO 10\n\n 18 WRITE (*, 21)\n 21 FORMAT (6X,'DATA FILE DOES NOT EXIST')\n\n GO TO 999\n\n 19 WRITE (*, 23)\n 23 FORMAT(6X,'ERROR MESSAGE IN THE DATA VALUE')\n\n GO TO 999\n\n 10 WRITE (1, 100)\n 100 FORMAT (//,25X,'NET PRESENT VALUE CALCULATION',/1H, 78(1H*))\n\n NOCF1 = NOCF + 1\n\n WRITE (1, 110) NOCF1\n 110 FORMAT(/,20X,I4,3X,'YEARLY CASH FLOWS INCLUDING YEAR 0')\n\n WRITE (1, 120) DISC\n 120 FORMAT (/,20X,F8.2,3X,'PERCENTAGE ANNUAL DISCOUNT RATE ',/,\n + 1H, 78(1H-))\n\n WRITE (1, 130)\n 130 FORMAT (//, 7X,'YEAR', 5X, 'CASH FLOWS ($)', 4X, 'CUMULATIVE',\n + 10X, 'DISCOUNT', 8X, 'PRESENT')\n\n WRITE (1, 140)\n 140 FORMAT (34X,'CASH FLOWS ($)', 6X, 'FACTOR', 10X, 'VALUE ($)',\n + /,1H, 78(1H-))\n\nC CALCULATE THE CUMULATIVE CASH FLOW\n\n\n CUCF(0) = YCF(0)\n DO I = 1, NOCF\n CUCF(I) = CUCF(I-1) + YCF(I)\n END DO\n\n R1 = DISC/100.0\n PV(0) = YCF(0)*1.0\n\n DO 15 I1 = 0, 0\n IF (I1 .EQ. 0) THEN\n R1 = 0.0\n DF(I1) = 1.0/((1.0+R1)**I1)\n PV(I1) = YCF(I1)*DF(I1)\n ELSE\n ENDIF\n 15 CONTINUE\n\n R1 = DISC/100.0\n\n DO 20 I1 = 1, NOCF\n DF(I1) = 1.0/((1.0+R1)**I1)\n PV(I1) = YCF(I1)*DF(I1)\n 20 CONTINUE\n\n DO K = 0, NOCF\n WRITE (1, 150) K, YCF(K), CUCF(K), DF(K), PV(K)\n 150 FORMAT (5X,I3,5X,F14.2,5X,F14.2,5X,F9.4,5X,F14.2)\n END DO\n\n WRITE (1, 160)\n 160 FORMAT (78(1H-))\n\nC CALCULATE THE NET PRESENT VALUE FROM THE PRESENT VALUE\n\n NPV = 0.0\n DO J = 0, NOCF\n NPV = NPV + PV(J)\n END DO\n\n WRITE (1, 170) NPV\n 170 FORMAT (1H0, 6X,'THE NET PRESENT VALUE ($):', 3X, T40, F14.2)\n\nC CALCULATE THE PRESENT VALUE RATIO, PVR\nC PVR = PRESENT VALUE OF ALL POSITIVE CASH FLOWS/\nC PRESENT VALUE OF ALL NEGATIVE CASH FLOWS\n SUM1 = 0.0\n\n DO K = 1, NOCF\n SUM1 = SUM1 + PV(K)\n END DO\n\n PVR = SUM1 /ABS(YCF(0))\n\n WRITE (1, 180) PVR\n 180 FORMAT (1H0, 6X, 'PRESENT VALUE RATIO:', 3X, T40, F8.3)\n\nC CALCULATE THE NET RETURN RATE (NRR) i.e. THE NET PRESENT VALUE\nC DIVIDED BY THE PRODUCT OF INITIAL INVESTMENT AND THE PROJECT LIFE\nC (EXCLUDING YEAR 0).\n\n NRR = ABS(NPV/(ABS(PV(0))*NOCF))*100\n\n WRITE(1, 190) NRR\n 190 FORMAT (1H0, 6X, 'THE NET RETURN RATE:', 3X, T40, F8.2, 3X, '%')\n\nC CALCULATE THE AVERAGE RATE OF RETURN (ARR) i.e THE AVERAGE\nC CASH FLOW DURING THE LIFE OF THE PROJECT (EXCLUDING YEAR 0).\n\n SUM = 0.0\n DO I = 1, NOCF\n SUM = SUM + YCF(I)\n END DO\n\n AVSUM = SUM/NOCF\n ARR = (AVSUM/ABS(YCF(0)))*100.0\n\n WRITE (1, 200) ARR\n 200 FORMAT(1H0, 6X, 'THE AVERAGE RATE OF RETURN:', 3X, T40, F8.2,\n + 3X,'%')\n\nC CALCULATE THE PAYBACK TIME FROM THE CUMULATIVE CASH FLOW, TIME: YEARS\n\n DO I=0, NOCF\n IF ( CUCF(I+1) .GT. CUCF(I) .AND. CUCF(I+1) .GE. 0.0) THEN\n TEMP = CUCF(I+1)\n CUCF(I+1) = CUCF(I)\n CUCF(I) = TEMP\n TIME = I\n TIME1 = TIME + 1\n GO TO 40\n ELSE\n ENDIF\n END DO\n\n 40 WRITE (1, 210) TIME, TIME1\n 210 FORMAT (1H0,6X,'THE PAYBACK PERIOD IS BETWEEN:',\n + 3X,T45,I2,2X,'AND',2X,I2,3X,'YEARS')\n\nC FORM FEED THE PRINTING PAPER TO TOP OF THE NEXT PAGE.\n\n WRITE(1, *) CHAR(12)\n\n CLOSE (3, STATUS = 'KEEP')\n CLOSE (1)\n\n 999 STOP\n END\n", "meta": {"hexsha": "17f1e9f66f0f22c22341977e22da9d2d88c5904f", "size": 4923, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "code/prog91_eco.f", "max_stars_repo_name": "HaoZeke/gasSweetening-Report", "max_stars_repo_head_hexsha": "6a0804b49877df71163dd5471bd86a37b6f6e823", "max_stars_repo_licenses": ["Artistic-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "code/prog91_eco.f", "max_issues_repo_name": "HaoZeke/gasSweetening-Report", "max_issues_repo_head_hexsha": "6a0804b49877df71163dd5471bd86a37b6f6e823", "max_issues_repo_licenses": ["Artistic-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "code/prog91_eco.f", "max_forks_repo_name": "HaoZeke/gasSweetening-Report", "max_forks_repo_head_hexsha": "6a0804b49877df71163dd5471bd86a37b6f6e823", "max_forks_repo_licenses": ["Artistic-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0494505495, "max_line_length": 75, "alphanum_fraction": 0.5214300223, "num_tokens": 1856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392795, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7711575798133965}} {"text": "!=================================================\n! SUBROUTINE\n!\tBSPLINE(px,bx,ndeg)\n!\n!\tno common\n!=================================================\n\nmodule func_bspline\n\n\timplicit none\n\ncontains\n\nfunction b21(xx)\n\timplicit none\n\treal(8), intent(in) :: xx\n\treal(8) :: b21\n\t\tb21 = xx\n\treturn\nend function\n\nfunction b31(xx)\n\timplicit none\n\treal(8), intent(in) :: xx\n\treal(8) :: b31\n\t\tb31 = xx * xx /2.d0\n\treturn\nend function\n\nfunction b32(xx)\n\timplicit none\n\treal(8), intent(in) :: xx\n\treal(8) :: b32\n\t\tb32 = ((-2.d0 * xx +2.d0) * xx +1.d0) / 2.d0\n\treturn\nend function\n\nfunction b41(xx)\n\timplicit none\n\treal(8), intent(in) :: xx\n\treal(8) :: b41\n\t\tb41 = xx * xx * xx / 6.d0\n\treturn\nend function\n\nfunction b42(xx)\n\timplicit none\n\treal(8), intent(in) :: xx\n\treal(8) :: b42\n\t\tb42 = (((-3.d0 * xx + 3.d0) * xx + 3.d0) * xx + 1.d0) / 6.0d0\n\treturn\nend function\n\nend module func_bspline\n\n!***************************************\n\nmodule mod_bspline\n\n\timplicit none\n\ncontains\n!==========\nsubroutine BSPLINE(px,bx,ndeg)\n\n\tuse func_bspline\n\timplicit none\n\n\tinteger, intent(in) :: ndeg\n\treal(8), intent(in) :: px\n\treal(8), intent(out) :: bx(4)\n\n\treal(8) :: pr\n\n\tpr = 1.d0 - px\n\n\tif(ndeg == 0) then\n\t\tbx(1) = 1.d0\n\telse if(ndeg == 1) then\n\t\tbx(1) = b21(px)\n\t\tbx(2) = b21(pr)\n\telse if(ndeg == 2) then\n\t\tbx(1) = b31(px)\n\t\tbx(2) = b32(px)\n\t\tbx(3) = b31(pr)\n\telse if(ndeg == 3) then\n\t\tbx(1) = b41(px)\n\t\tbx(2) = b42(px)\n\t\tbx(3) = b42(pr)\n\t\tbx(4) = b41(pr)\n\tend if\n\nreturn\nend subroutine BSPLINE\n\nend module mod_bspline\n\n", "meta": {"hexsha": "154a07cbbc7123350e2c3e64cdca500983478ffb", "size": 1503, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fort/m_bspline.f90", "max_stars_repo_name": "s-watanabe-jhod/YM1992", "max_stars_repo_head_hexsha": "85793cba6a81aeded1569dd0c61566e4c934e050", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fort/m_bspline.f90", "max_issues_repo_name": "s-watanabe-jhod/YM1992", "max_issues_repo_head_hexsha": "85793cba6a81aeded1569dd0c61566e4c934e050", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fort/m_bspline.f90", "max_forks_repo_name": "s-watanabe-jhod/YM1992", "max_forks_repo_head_hexsha": "85793cba6a81aeded1569dd0c61566e4c934e050", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-27T07:38:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-27T07:38:59.000Z", "avg_line_length": 15.3367346939, "max_line_length": 63, "alphanum_fraction": 0.5502328676, "num_tokens": 561, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370312, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7711575763103782}} {"text": "MODULE mod_thermodynamics\n\n USE mod_constants\n\n IMPLICIT NONE\n\nCONTAINS\n\n ELEMENTAL FUNCTION specific_energy(P, rho) RESULT(e)\n\n IMPLICIT NONE\n\n REAL(dp_kind), INTENT(IN) :: P, rho\n REAL(dp_kind) :: e\n\n e = P / ((gamma - 1) * rho)\n\n END FUNCTION specific_energy\n\n ELEMENTAL FUNCTION pressure(e, rho) RESULT(P)\n\n IMPLICIT NONE\n\n REAL(dp_kind), INTENT(IN) :: e, rho\n REAL(dp_kind) :: P\n\n P = (gamma - 1) * rho * e\n\n END FUNCTION pressure\n\n ELEMENTAL FUNCTION sound_speed(e, rho) RESULT(c)\n\n IMPLICIT NONE\n\n REAL(dp_kind), INTENT(IN) :: e\n REAL(dp_kind), INTENT(IN), OPTIONAL :: rho\n REAL(dp_kind) :: c\n\n c = SQRT(gamma * (gamma - 1) * e)\n\n END FUNCTION sound_speed\n\n\n FUNCTION pressure_RAR(P_, v_, v, dP_dv) RESULT(P)\n\n IMPLICIT NONE\n\n REAL(dp_kind), INTENT(IN) :: P_, v_, v\n REAL(dp_kind), INTENT(OUT), OPTIONAL :: dP_dv\n REAL(dp_kind) :: P\n\n P = P_ * (v_ / v)**gamma\n\n IF (PRESENT(dP_dv)) dP_dv = - gamma * P/v\n\n END FUNCTION pressure_RAR\n\n FUNCTION integral_c_v_isentropic(P_, v_, v) RESULT(integ)\n\n ! calcolo di int_{v_}^v c(s_, v)/v dv\n\n IMPLICIT NONE\n\n REAL(dp_kind), INTENT(IN) :: P_, v_, v\n REAL(dp_kind) :: integ\n\n integ = (2*SQRT(gamma*P_*v_)/(gamma-1)) * (1 - (v_/v)**((gamma-1)/2))\n\n END FUNCTION integral_c_v_isentropic\n\n\n\n FUNCTION sound_speed_isentropic(P_, v_, v) RESULT(c_isent)\n\n IMPLICIT NONE\n\n REAL(dp_kind), INTENT(IN) :: P_, v_, v\n REAL(dp_kind) :: c_isent\n\n c_isent = SQRT(gamma*P_*v_) * (v_/v)**((gamma-1)/2)\n\n END FUNCTION sound_speed_isentropic\n\n\n\n FUNCTION pressure_RH(P_, v_, v, dP_dv) RESULT(P)\n\n IMPLICIT NONE\n\n REAL(dp_kind), INTENT(IN) :: P_, v_, v\n REAL(dp_kind), INTENT(OUT), OPTIONAL :: dP_dv\n REAL(dp_kind) :: P\n\n REAL(dp_kind) :: NUM, DEN\n\n ! Controllo che v non sia inferiore all'asintoto (Vedi testo)\n\n NUM = (gamma + 1) * v_ - (gamma - 1) * v\n DEN = (gamma + 1) * v - (gamma - 1) * v_\n\n P = P_ * NUM/DEN\n\n IF (PRESENT(dP_dv)) dP_dv = -4 * gamma * P_ * v_/DEN**2\n\n END FUNCTION pressure_RH\n\nEND MODULE mod_thermodynamics\n", "meta": {"hexsha": "36f957642d48df9f0958aeffcba66dc193f6e041", "size": 2281, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mod_thermodynamics.f90", "max_stars_repo_name": "Ccaccia73/Riemann2D", "max_stars_repo_head_hexsha": "c4eedd68e8bcdad5916d44c2bc671541fb4b9994", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/mod_thermodynamics.f90", "max_issues_repo_name": "Ccaccia73/Riemann2D", "max_issues_repo_head_hexsha": "c4eedd68e8bcdad5916d44c2bc671541fb4b9994", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mod_thermodynamics.f90", "max_forks_repo_name": "Ccaccia73/Riemann2D", "max_forks_repo_head_hexsha": "c4eedd68e8bcdad5916d44c2bc671541fb4b9994", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.1203703704, "max_line_length": 78, "alphanum_fraction": 0.5681718544, "num_tokens": 716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012747599251, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.7710479234090526}} {"text": "subroutine median(xin,n,xmed)\r\n\r\n! Find the median of X(1), ... , X(N), using as much of the quicksort\r\n! algorithm as is needed to isolate it.\r\n\r\n\r\n! Latest revision - 26 November 1996\r\nimplicit none\r\n\r\ninteger :: n\r\ndouble precision :: xin(n),x(n),xmed\r\n\r\n! Local variables\r\n\r\ninteger :: hi, lo, nby2, nby2p1, mid, i, j, k\r\ndouble precision :: temp, xhi, xlo, xmax, xmin\r\nlogical :: odd\r\n\r\n\r\nx = xin\r\n\r\nnby2 = n / 2\r\nnby2p1 = nby2 + 1\r\nodd = .true.\r\n\r\n! HI & LO are position limits encompassing the median.\r\n\r\nif (n == 2 * nby2) odd = .false.\r\nlo = 1\r\nhi = n\r\nif (n < 3) then\r\n if (n < 1) then\r\n xmed = 0.d0\r\n return\r\n end if\r\n xmed = x(1)\r\n if (n == 1) return\r\n xmed = 0.d5*(xmed + x(2))\r\n return\r\nend if\r\n\r\n! Find median of 1st, middle & last values.\r\n\r\n10 mid = (lo + hi)/2\r\nxmed = x(mid)\r\nxlo = x(lo)\r\nxhi = x(hi)\r\nif (xhi < xlo) then ! Swap xhi & xlo\r\n temp = xhi\r\n xhi = xlo\r\n xlo = temp\r\nend if\r\nif (xmed > xhi) then\r\n xmed = xhi\r\nelse if (xmed < xlo) then\r\n xmed = xlo\r\nend if\r\n\r\n! The basic quicksort algorithm to move all values <= the sort key (XMED)\r\n! to the left-hand end, and all higher values to the other end.\r\n\r\ni = lo\r\nj = hi\r\n50 do\r\n if (x(i) >= xmed) exit\r\n i = i + 1\r\nend do\r\ndo\r\n if (x(j) <= xmed) exit\r\n j = j - 1\r\nend do\r\nif (i < j) then\r\n temp = x(i)\r\n x(i) = x(j)\r\n x(j) = temp\r\n i = i + 1\r\n j = j - 1\r\n\r\n! Decide which half the median is in.\r\n\r\n if (i <= j) go to 50\r\nend if\r\n\r\nif (.not. odd) then\r\n if (j == nby2 .and. i == nby2p1) go to 130\r\n if (j < nby2) lo = i\r\n if (i > nby2p1) hi = j\r\n if (i /= j) go to 100\r\n if (i == nby2) lo = nby2\r\n if (j == nby2p1) hi = nby2p1\r\nelse\r\n if (j < nby2p1) lo = i\r\n if (i > nby2p1) hi = j\r\n if (i /= j) go to 100\r\n\r\n! Test whether median has been isolated.\r\n\r\n if (i == nby2p1) return\r\nend if\r\n100 if (lo < hi - 1) go to 10\r\n\r\nif (.not. odd) then\r\n xmed = 0.5d0*(x(nby2) + x(nby2p1))\r\n return\r\nend if\r\ntemp = x(lo)\r\nif (temp > x(hi)) then\r\n x(lo) = x(hi)\r\n x(hi) = temp\r\nend if\r\nxmed = x(nby2p1)\r\nreturn\r\n\r\n! Special case, N even, J = N/2 & I = J + 1, so the median is\r\n! between the two halves of the series. Find max. of the first\r\n! half & min. of the second half, then average.\r\n\r\n130 xmax = x(1)\r\ndo k = lo, j\r\n xmax = max(xmax, x(k))\r\nend do\r\nxmin = x(n)\r\ndo k = i, hi\r\n xmin = min(xmin, x(k))\r\nend do\r\nxmed = 0.5d0*(xmin + xmax)\r\n\r\nend subroutine median\r\n", "meta": {"hexsha": "70068ef6ebe25a19ef5798b39792981dabe6b91c", "size": 2420, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/Smooth_Gapfill_LAI/median.f90", "max_stars_repo_name": "bucricket/projectMASpreprocess", "max_stars_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-28T20:26:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T20:26:59.000Z", "max_issues_repo_path": "source/Smooth_Gapfill_LAI/median.f90", "max_issues_repo_name": "bucricket/projectMASpreprocess", "max_issues_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/Smooth_Gapfill_LAI/median.f90", "max_forks_repo_name": "bucricket/projectMASpreprocess", "max_forks_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-04-20T21:04:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-16T08:05:44.000Z", "avg_line_length": 18.7596899225, "max_line_length": 74, "alphanum_fraction": 0.5462809917, "num_tokens": 950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7710471380472067}} {"text": "MODULE MathKernel\n\n!=======================================================================================\n! Common Math Operation Collections\n! Includes:\n! Det : Detting determinant of a matrix\n! InvMat : General purpose matrix inversion\n! InvMat3 : Matrix inversion for 3x3 Matrix\n! InvMat2 : Matrix inversion for 2x2 Matrix\n! Cross : Vector cross product\n! IsPlanar : Judging if 4 points are on the same plane\n! GaussianMask : Generating gaussian points and weights for caritsian coordinates\n! AxialRotate : Rotate a group of points along a given axis for given angle\n! LeastSquare : Return the least-square coefficients for a given series of data\n! \n! Author: Haoguang Yang\n! \n!=======================================================================================\n\n \n implicit none\n\nCONTAINS\n \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! Function to find the determinant of a square matrix !!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nREAL(8) FUNCTION Det(matrix, n)\n!Description: The subroutine is based on two key points:\n!1] A determinant is unaltered when row operations are performed: Hence, using this principle,\n!row operations (column operations would work as well) are used\n!to convert the matrix into upper traingular form\n!2]The determinant of a triangular matrix is obtained by finding the product of the diagonal elements\n IMPLICIT NONE\n REAL(8), DIMENSION(n,n) :: matrix\n INTEGER, INTENT(IN) :: n\n REAL(8) :: m, temp\n INTEGER :: i, j, k, l\n LOGICAL :: DetExists = .TRUE.\n \n select case (n)\n case (2)\n Det = matrix(1,1)*matrix(2,2)-matrix(1,2)*matrix(2,1)\n case (3)\n Det = matrix(1,1)*matrix(2,2)*matrix(3,3)+ &\n matrix(1,2)*matrix(2,3)*matrix(3,1)+ &\n matrix(1,3)*matrix(2,1)*matrix(3,2)- &\n matrix(1,1)*matrix(2,3)*matrix(3,2)- &\n matrix(1,2)*matrix(2,1)*matrix(3,3)- &\n matrix(1,3)*matrix(2,2)*matrix(3,1)\n case (4:)\n l = 1\n !Convert to upper triangular form\n DO k = 1, n-1\n IF (matrix(k,k) == 0) THEN\n DetExists = .FALSE.\n DO i = k+1, n\n IF (matrix(i,k) /= 0) THEN\n DO j = 1, n\n temp = matrix(i,j)\n matrix(i,j)= matrix(k,j)\n matrix(k,j) = temp\n END DO\n DetExists = .TRUE.\n l=-l\n EXIT\n ENDIF\n END DO\n IF (DetExists .EQV. .FALSE.) THEN\n Det = 0\n return\n END IF\n ENDIF\n DO j = k+1, n\n m = matrix(j,k)/matrix(k,k)\n DO i = k+1, n\n matrix(j,i) = matrix(j,i) - m*matrix(k,i)\n END DO\n END DO\n END DO\n !Calculate determinant by finding product of diagonal elements\n Det = l\n DO i = 1, n\n Det = Det * matrix(i,i)\n END DO\n END select\nEND FUNCTION Det\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! Functions To Calculate The Inverse Of A Small Matrix !!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!2x2\nSUBROUTINE InvMat2 (A, AINV, OK_FLAG)\n\n IMPLICIT NONE\n\n DOUBLE PRECISION, DIMENSION(2,2), INTENT(IN) :: A\n DOUBLE PRECISION, DIMENSION(2,2), INTENT(OUT) :: AINV\n LOGICAL, INTENT(OUT) :: OK_FLAG\n\n DOUBLE PRECISION, PARAMETER :: EPS = 1.0D-10\n DOUBLE PRECISION :: DET\n DOUBLE PRECISION, DIMENSION(2,2) :: COFACTOR\n\n\n DET = A(1,1)*A(2,2) - A(1,2)*A(2,1)\n\n IF (ABS(DET) .LE. EPS) THEN\n AINV = 0.0D0\n OK_FLAG = .FALSE.\n RETURN\n END IF\n\n COFACTOR(1,1) = +A(2,2)\n COFACTOR(1,2) = -A(2,1)\n COFACTOR(2,1) = -A(1,2)\n COFACTOR(2,2) = +A(1,1)\n\n AINV = TRANSPOSE(COFACTOR) / DET\n\n OK_FLAG = .TRUE.\n\n RETURN\n\nEND SUBROUTINE InvMat2\n \n!3x3\nSUBROUTINE InvMat3 (A, AINV, OK_FLAG)\n\n IMPLICIT NONE\n\n DOUBLE PRECISION, DIMENSION(3,3), INTENT(IN) :: A\n DOUBLE PRECISION, DIMENSION(3,3), INTENT(OUT) :: AINV\n LOGICAL, INTENT(OUT) :: OK_FLAG\n\n DOUBLE PRECISION, PARAMETER :: EPS = 1.0D-10\n DOUBLE PRECISION :: DET\n DOUBLE PRECISION, DIMENSION(3,3) :: COFACTOR\n\n\n DET = A(1,1)*A(2,2)*A(3,3) &\n - A(1,1)*A(2,3)*A(3,2) &\n - A(1,2)*A(2,1)*A(3,3) &\n + A(1,2)*A(2,3)*A(3,1) &\n + A(1,3)*A(2,1)*A(3,2) &\n - A(1,3)*A(2,2)*A(3,1)\n\n IF (ABS(DET) .LE. EPS) THEN\n AINV = 0.0D0\n OK_FLAG = .FALSE.\n RETURN\n END IF\n\n COFACTOR(1,1) = +(A(2,2)*A(3,3)-A(2,3)*A(3,2))\n COFACTOR(1,2) = -(A(2,1)*A(3,3)-A(2,3)*A(3,1))\n COFACTOR(1,3) = +(A(2,1)*A(3,2)-A(2,2)*A(3,1))\n COFACTOR(2,1) = -(A(1,2)*A(3,3)-A(1,3)*A(3,2))\n COFACTOR(2,2) = +(A(1,1)*A(3,3)-A(1,3)*A(3,1))\n COFACTOR(2,3) = -(A(1,1)*A(3,2)-A(1,2)*A(3,1))\n COFACTOR(3,1) = +(A(1,2)*A(2,3)-A(1,3)*A(2,2))\n COFACTOR(3,2) = -(A(1,1)*A(2,3)-A(1,3)*A(2,1))\n COFACTOR(3,3) = +(A(1,1)*A(2,2)-A(1,2)*A(2,1))\n\n AINV = TRANSPOSE(COFACTOR) / DET\n\n OK_FLAG = .TRUE.\n\n RETURN\n\nEND SUBROUTINE InvMat3\n\n!General inverse\nsubroutine InvMat(MatIn,MatOut,n)\n!============================================================\n! Inverse matrix\n! Method: Based on Doolittle LU factorization for Ax=b\n!-----------------------------------------------------------\n! input ...\n! a(n,n) - array of coefficients for matrix A\n! n - dimension\n! output ...\n! c(n,n) - inverse matrix of A\n! comments ...\n! the original matrix a(n,n) will be destroyed \n! during the calculation\n!===========================================================\nimplicit none \ninteger n\ndouble precision MatIn(n,n), MatOut(n,n)\ndouble precision L(n,n), U(n,n), b(n), d(n), x(n)\ndouble precision coeff\ninteger i, j, k\n\n! step 0: initialization for matrices L and U and b\n! Fortran 90/95 aloows such operations on matrices\nL=0.0\nU=0.0\nb=0.0\n\n! step 1: forward elimination\ndo k=1, n-1\n do i=k+1,n\n coeff=MatIn(i,k)/MatIn(k,k)\n L(i,k) = coeff\n do j=k+1,n\n MatIn(i,j) = MatIn(i,j)-coeff*MatIn(k,j)\n end do\n end do\nend do\n\n! Step 2: prepare L and U matrices \n! L matrix is a matrix of the elimination coefficient\n! + the diagonal elements are 1.0\ndo i=1,n\n L(i,i) = 1.0\nend do\n! U matrix is the upper triangular part of A\ndo j=1,n\n do i=1,j\n U(i,j) = MatIn(i,j)\n end do\nend do\n\n! Step 3: compute columns of the inverse matrix C\ndo k=1,n\n b(k)=1.0\n d(1) = b(1)\n! Step 3a: Solve Ld=b using the forward substitution\n do i=2,n\n d(i)=b(i)\n do j=1,i-1\n d(i) = d(i) - L(i,j)*d(j)\n end do\n end do\n! Step 3b: Solve Ux=d using the back substitution\n x(n)=d(n)/U(n,n)\n do i = n-1,1,-1\n x(i) = d(i)\n do j=n,i+1,-1\n x(i)=x(i)-U(i,j)*x(j)\n end do\n x(i) = x(i)/u(i,i)\n end do\n! Step 3c: fill the solutions x(n) into column k of C\n do i=1,n\n MatOut(i,k) = x(i)\n end do\n b(k)=0.0\nend do\nend subroutine InvMat\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! Function calculating cross product of 3D vectors !!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nFUNCTION cross(a, b)\n implicit none\n real(8), DIMENSION(3) :: cross\n real(8), DIMENSION(3), INTENT(IN) :: a, b\n\n cross(1) = a(2) * b(3) - a(3) * b(2)\n cross(2) = a(3) * b(1) - a(1) * b(3)\n cross(3) = a(1) * b(2) - a(2) * b(1)\nEND FUNCTION cross\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! Subroutine Judging if four points are in the same place !!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine IsPlanar(Judge, NormalVec, NPoints, PositionData)\n implicit none\n integer :: NPoints\n real(8) :: PositionData(NPoints*3), NormalVec(3), V(3,3), Criteria\n logical :: Judge\n \n Judge = .False.\n if (NPoints == 4) then\n V=reshape((/PositionData(4:11:3)-PositionData(1)*(/1,1,1/), &\n PositionData(5:12:3)-PositionData(2)*(/1,1,1/), &\n PositionData(6:13:3)-PositionData(3)*(/1,1,1/)/),shape(V)) !problematic expression\n NormalVec = cross(V(2,:),V(3,:)-V(1,:))\n Criteria = dot_product(NormalVec,V(1,:))\n \n if (abs(Criteria) .LT. 1.0D-10) then\n Judge = .True.\n return\n endif\n endif\nend subroutine IsPlanar\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! Function Returning Weight Masks for Gaussian Quadrature !!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine GaussianMask (GaussianPoints, Weights, QuadratureOrder)\n implicit none\n !integer :: EdgesPerNode, NumberOfEdges\n integer :: QuadratureOrder\n real(8) :: GaussianPoints (QuadratureOrder), Weights(QuadratureOrder)\n \n select case (QuadratureOrder)\n case (1)\n GaussianPoints=0.\n Weights=2.\n case (2)\n GaussianPoints=(/1./sqrt(3.), -1./sqrt(3.)/)\n Weights=(/1.,1./)\n case (3)\n GaussianPoints=(/sqrt(3./5.), 0., -sqrt(3./5.)/)\n Weights=(/5./9., 8./9., 5./9./)\n !case (4)\n !Other Higher Orders\n \n end select\nend subroutine GaussianMask\n\n!subroutine GaussianMaskSimplex (GaussianPts, Weights, QuadratureOrder)\n! implicit none\n! integer :: QuadratureOrder\n! real(8) :: GaussianPts(npg)\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! Subroutine performing spacial rotations along a given axis !!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine AxialRotate(PtIn, PtOut, Axis, Theta)\n\timplicit none\n\treal(8) :: PtIn(3), PtOut(3), Axis(3), Theta\n\treal(8) :: C, S, R(3,3)\n\t\n\tC = cos(Theta)\n\tS = sin(Theta)\n\tAxis = Axis/sqrt(dot_product(Axis, Axis))\n\tR = reshape((/Axis(1)**2+(1-Axis(1)**2)*C, Axis(1)*Axis(2)*(1-C)-Axis(3)*S, Axis(1)*Axis(3)*(1-C)+Axis(2)*S, &\n\t\t\t\t Axis(1)*Axis(2)*(1-C)+Axis(3)*S, Axis(2)**2+(1-Axis(2)**2)*C, Axis(2)*Axis(3)*(1-C)-Axis(1)*S, &\n\t\t\t\t Axis(1)*Axis(3)*(1-C)-Axis(2)*S, Axis(2)*Axis(3)*(1-C)+Axis(1)*S, Axis(3)**2+(1-Axis(3)**2)*C/),(/3,3/))\n\tPtOut = matmul(R,PtIn)\nend subroutine AxialRotate\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! Perform least-square approoximation !!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine LeastSquare (coeff, value, Ncoeff, Nval, sets)\n implicit none\n integer :: Ncoeff, Nval, sets, i\n real(8) :: coeff (Ncoeff, sets), value (Nval, Ncoeff+sets)\n real(8) :: ATA (Ncoeff, Ncoeff), ATY (Ncoeff)\n \n ATA = matmul(transpose(value(:,1:Ncoeff)),value(:,1:Ncoeff)) !May waste a lot of calcullatons here...\n call InvMat(ATA, ATA, Ncoeff)\n \n do i = 1,sets\n ATY = matmul(transpose(value(:,1:Ncoeff)),value(:,Ncoeff+i))\n coeff(:,i) = matmul(ATA,ATY)\n end do\n \nend subroutine LeastSquare\n END MODULE MathKernel\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! Calculate Stiffness Matrix !!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine GetDMat (Young, Poisson, DMatrix)\n implicit none\n real(8),dimension(6,6) :: DMatrix\n real(8), intent(in) :: Young, Poisson\n real(8) :: G, lambda\n integer :: i\n \n DMatrix(:,:) = 0\n G = Young/(2*(1+Poisson))\n lambda = Poisson*Young/(1+Poisson)/(1-2*Poisson)\n DMatrix(1:3,1:3) = lambda\n do i = 1,6\n DMatrix(i,i) = DMatrix(i,i) + 2*G\n end do\n return\nend subroutine GetDMat\n\n", "meta": {"hexsha": "4af46e3f1b9b8350e508eaee50361045372b01a4", "size": 11871, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/module/mathkernel.f90", "max_stars_repo_name": "JAMMIASHOK/OpenSTAP", "max_stars_repo_head_hexsha": "b5f26d42de483d87025a9da050a6fb51b7134729", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2017-02-16T01:01:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:27:36.000Z", "max_issues_repo_path": "src/module/mathkernel.f90", "max_issues_repo_name": "ming91915/OpenSTAP", "max_issues_repo_head_hexsha": "b5f26d42de483d87025a9da050a6fb51b7134729", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/module/mathkernel.f90", "max_forks_repo_name": "ming91915/OpenSTAP", "max_forks_repo_head_hexsha": "b5f26d42de483d87025a9da050a6fb51b7134729", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2017-04-24T02:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T12:42:08.000Z", "avg_line_length": 30.9947780679, "max_line_length": 112, "alphanum_fraction": 0.4870693286, "num_tokens": 3768, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660976007597, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7708687219026471}} {"text": "PROGRAM decibels\nIMPLICIT NONE\n REAL :: ratio ! In decibels\n REAL :: power_level, reference = 1.0 ! Power levels in mW\n WRITE(*, *) \"Enter a power level in mW\"\n READ(*, *) power_level\n ratio = 10 * LOG(power_level / reference) / LOG(10.0)\n WRITE(*, *) power_level, \" mW against \", reference, \" mW reference is \", ratio, \" decibels\"\n\n\nEND PROGRAM decibels\n", "meta": {"hexsha": "0fea4eb2e8132a25dc75f1cf286065f5a0de2a7f", "size": 361, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap2/decibels.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap2/decibels.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap2/decibels.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0833333333, "max_line_length": 93, "alphanum_fraction": 0.6675900277, "num_tokens": 113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273633016692236, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7707715668394747}} {"text": "program FD\n implicit none\n\n! Sun 15 Apr 2018 12:44:36\n!\n! Compile with: \"gfortran FD.f95 -o FD\"\n! Run with: \"./FD\"\n \n integer, dimension(:),allocatable :: a_seed\n integer :: i_seed\n integer, dimension(1:8) :: dt_seed\n\n real :: pi, x1, x2, z1, z2, ds, s, dw, t\n integer, parameter :: num_trading_days = 250, s_0 = 100\n real, parameter :: drift = 0.16, r = 0.04, k = 0.2!, volatility = 0.2\n! Change volatility from 0.2 to 0.6 for section 2 (g)\n real, parameter :: dt = 1.0/float(num_trading_days)\n real, dimension(:,:), allocatable :: portfolio_value\n integer, dimension(4) :: indx = [1, 2, 5, 20]\n real, dimension(2) :: volatility_array = [0.2, 0.6]\n real, dimension(:), allocatable :: prob_loss\n integer :: num_years, itter_per_simulation, i, j, h, l, m, f, q\n real :: mean, variance, volatility\n\n pi = acos(-1.0)\n\n! Question 2. (b)\n call random_seed(size=i_seed)\n allocate(a_seed(1:i_seed))\n call random_seed(get=a_seed)\n call date_and_time(values=dt_seed)\n a_seed(i_seed)=dt_seed(8); a_seed(1)=dt_seed(8)*dt_seed(7)*dt_seed(6)\n call random_seed(put=a_seed)\n deallocate(a_seed)\n\n! Question 2. (c)\n s = float(s_0)\n t = 0.0\n open(10 , file = \"s_price_1yr.dat\")\n do i = 1, num_trading_days\n call random_number(x1)\n call random_number(x2)\n! write(6,*) \"The random number x1 is: \", x1\n! write(6,*) \"The random number x2 is: \", x2\n z1 = sqrt(-2.0*log(x1))*cos(2.0*pi*x2)\n z2 = sqrt(-2.0*log(x2))*sin(2.0*pi*x2)\n! write(6,*) \"The value of z1 is: \", z1\n! write(6,*) \"The value of z2 is: \", z2\n\n! Question 2. (c)\n dw = sqrt(dt)*z1\n ds = s*(drift*dt + volatility_array(1)*dw )\n s = s + ds\n write(10,*) s , t\n t = t+dt\n end do\n close(10)\n\n\n! Question 2. (d)\n\n open(11, file = \"portfolio_value_1yr.dat\")\n open(12, file = \"portfolio_value_2yr.dat\")\n open(13, file = \"portfolio_value_5yr.dat\")\n open(14, file = \"portfolio_value_20yr.dat\")\n do q=1,size(volatility_array)\n volatility = volatility_array(q)\n do i=1,size(indx)\n num_years = indx(i)\n itter_per_simulation = num_trading_days*num_years\n! write(6,*) itter_per_simulation\n allocate(portfolio_value(itter_per_simulation,1000))\n m = 0\n portfolio_value(:,:) = 0.0\n allocate(prob_loss(itter_per_simulation))\n prob_loss = 0\n do j = 1, 1000\n s = float(s_0)\n t = 0.0\n do h = 1, itter_per_simulation\n\n call random_number(x1)\n call random_number(x2)\n\n z1 = sqrt(-2.0*log(x1))*cos(2.0*pi*x2)\n z2 = sqrt(-2.0*log(x2))*sin(2.0*pi*x2)\n\n dw = sqrt(dt)*z1\n ds = s*(drift*dt + volatility*dw )\n s = s + ds\n t = t+dt\n\n portfolio_value(h,j) = s*exp(-r*t)-s_0\n\n if (s .ge. (s_0*(1.0+k)*exp(r*t))) then\n portfolio_value(h,j) = s_0*k\n exit\n end if\n\n if (volatility .eq. 0.2) then\n if (num_years .eq. 1) then\n write(11,*) portfolio_value(h,j), t\n else if (num_years .eq. 2) then\n write(12,*) portfolio_value(h,j), t\n else if (num_years .eq. 5) then\n write(13,*) portfolio_value(h,j), t\n else if (num_years .eq. 20) then\n write(14,*) portfolio_value(h,j), t\n end if\n end if\n\n if (portfolio_value(h,j) .le. 0) then\n prob_loss(h) = (prob_loss(h) + 1)\n end if\n end do\n\n do l = 1 , int(itter_per_simulation-h)\n t = t+dt\n f = h + l\n portfolio_value(f,j) = s_0*k\n if (volatility .eq. 0.2) then\n if (num_years .eq. 1) then\n write(11,*) portfolio_value(f,j), t\n else if (num_years .eq. 2) then\n write(12,*) portfolio_value(f,j), t\n else if (num_years .eq. 5) then\n write(13,*) portfolio_value(f,j), t\n else if (num_years .eq. 20) then\n write(14,*) portfolio_value(f,j), t\n end if\n end if\n! p = p + 1\n end do\n\n end do\n\n! prob_loss = prob_loss(h)/1000\n\n if (indx(i) .eq. 20) then\n t = 0.0\n open(15, file = \"statistics.dat\")\n open(16, file = \"prob_loss.dat\")\n open(17, file = \"prob_loss_06.dat\")\n open(18, file = \"statistics_06.dat\")\n do h = 1, itter_per_simulation\n t = t+dt\n if (volatility .eq. 0.2) then\n write(16,*) prob_loss(h)/1000, t\n else if (volatility .eq. 0.6) then\n write(17,*) prob_loss(h)/1000, t\n end if\n mean = sum(portfolio_value(h,:))/1000\n !WORK OUT HOW VARIANCE CHANGES OVER PORTFOLIO TIMEFRAME\n variance = 0.0\n do j = 1, 1000\n variance=variance+(portfolio_value(h,j)-mean)**2.0\n end do\n variance = variance/real(j-1)\n if (volatility .eq. 0.2) then\n write(15,*) mean, variance, t\n else if (volatility .eq. 0.6) then\n write(18,*) mean, variance, t\n end if\n end do\n close(15)\n close(16)\n close(17)\n close(18)\n end if\n! write(6,*) \"m_count\", m\n deallocate (portfolio_value)\n deallocate(prob_loss)\n end do\n end do\n close(11)\n close(12)\n close(13)\n close(14)\nend program FD\n", "meta": {"hexsha": "484bcdb986c2a193fda7abd072fa33f155d160fe", "size": 6880, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "portfolio-value-calculations.f95", "max_stars_repo_name": "WilliamHoltam/Financial-Derivatives-Coursework", "max_stars_repo_head_hexsha": "898efc791fbc8c534ec379268954b7b264bc1551", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "portfolio-value-calculations.f95", "max_issues_repo_name": "WilliamHoltam/Financial-Derivatives-Coursework", "max_issues_repo_head_hexsha": "898efc791fbc8c534ec379268954b7b264bc1551", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "portfolio-value-calculations.f95", "max_forks_repo_name": "WilliamHoltam/Financial-Derivatives-Coursework", "max_forks_repo_head_hexsha": "898efc791fbc8c534ec379268954b7b264bc1551", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.2222222222, "max_line_length": 83, "alphanum_fraction": 0.4223837209, "num_tokens": 1766, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542184, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7707715596236547}} {"text": "SUBROUTINE eta_linear_3D_standing(H,angle,Lx,Ly,xc,yc,omega,time,eta,etax,etay,etaxx,etayy,etat)\n!\n! By Allan P. Engsig-Karup.\nUSE Precision\nUSE Constants\nIMPLICIT NONE\nREAL(KIND=long), INTENT(IN) :: H,Lx,Ly,xc,yc,omega,time\nREAL(KIND=long), INTENT(OUT) :: eta,etax,etay\nREAL(KIND=long), INTENT(OUT) :: etaxx,etayy,etat\n! REAL(KIND=long), OPTIONAL :: y,etay,etayy !Boundary fitted ?\n! Local variables\nREAL(KIND=long) :: kx, ky, half_H, k_omegat, sink_omegat\n!\nREAL(KIND=long) :: HH,k,w,angle,tmp,x,y\n!\nx = xc*COS(-angle)-yc*SIN(-angle)\ny = xc*SIN(-angle)+yc*COS(-angle)\n!\nkx = two*pi/Lx; ky = two*pi/Ly\nk = SQRT(kx**2+ky**2)\nw = omega\nHH = H\n!\neta = half*HH*COS(w*time)*COS(kx*X)*COS(ky*Y)\netax = -kx*half*HH*COS(w*time)*SIN(kx*X)*COS(ky*Y)\netaxx = -kx**2*half*HH*COS(w*time)*COS(kx*X)*COS(ky*Y)\netay = -ky*half*HH*COS(w*time)*SIN(kx*X)*COS(ky*Y)\netayy = -ky**2*half*HH*COS(w*time)*COS(kx*X)*COS(ky*Y)\netat = -half*w*HH*SIN(w*time)*COS(kx*X)*COS(ky*Y)\n!\ntmp = etax\netax = tmp*COS(angle)-etay*SIN(angle)\netay = tmp*SIN(angle)+etay*COS(angle)\n!\ntmp = etaxx\netaxx = tmp*COS(angle)-etayy*SIN(angle)\netayy = tmp*SIN(angle)+etayy*COS(angle)\n!\n!xc = x*COS(angle)-y*SIN(angle)\n!yc = x*SIN(angle)+y*COS(angle)\n\n\nEND SUBROUTINE eta_linear_3D_standing\n", "meta": {"hexsha": "f9d0e156bc800165ee844e206623283c7f4c2ddb", "size": 1251, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/functions/eta_linear_3D_standing.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/functions/eta_linear_3D_standing.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/functions/eta_linear_3D_standing.f90", "max_forks_repo_name": "apengsigkarup/OceanWave3D", "max_forks_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-01T12:17:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T16:23:37.000Z", "avg_line_length": 28.4318181818, "max_line_length": 96, "alphanum_fraction": 0.6706634692, "num_tokens": 550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.948154530420204, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.770723834336533}} {"text": "Subroutine Parab_interp(n, x, y, nn, xx, yy)\n! This routine interpolates a vector x,y to another vector xx,yy\n! Note: It doesn't check that xx is within x\n!\n Implicit None\n Integer :: n, nn\n Real, dimension(n) :: x, y\n Real, dimension(3) :: x3, y3\n Real, dimension(nn) :: xx, yy\n Integer, dimension(1) :: imin1\n Integer :: ii, i1, i3\n Real :: pend\n!\n If (n .eq. 1) then ! 1-point (absurd)\n yy=y\n Else if (n .eq. 2) then ! 2-point (linear interpolation)\n pend=(y(2)-y(1))/(x(2)-x(1))\n yy(1:nn)=pend*(xx(1:nn)-x(1)) + y(1)\n Else if (n .eq. 3) then ! 3-point (parabolic interpolation)\n Call ThreePt_Parab_interp(nn, x, y, xx, yy)\n Else ! More than 3 points (parabolic)\n Do ii=1, nn\n imin1=MinLoc(Abs( xx(ii)-x(:) ))\n i1=imin1(1)-1\n i3=imin1(1)+1\n If (i1 .le. 0) then\n i1=1\n i3=3\n Else if (i3 .gt. n) then\n i1=n-2\n i3=n\n End if\n x3(1:3)=x(i1:i3)\n y3(1:3)=y(i1:i3)\n Call ThreePt_parab_interp(1, x3, y3, xx(ii), yy(ii))\n End do\n End if\n Return\nEnd Subroutine Parab_interp\n! This routine performs a parabolic interpolation of the parabola that\n! passes through 3 points x,y to a vector xx,yy\n!\nSubroutine ThreePt_Parab_interp(nn, x, y, xx, yy)\n Implicit None\n Integer :: nn\n Real, dimension (3) :: x, y\n Real, dimension (nn) :: xx, yy\n Real :: den, a, b, c, x1, x2, x3, y1, y2, y3\n!\n x1=x(1)\n x2=x(2)\n x3=x(3)\n y1=y(1)\n y2=y(2)\n y3=y(3)\n den = (x1 - x2)*(x1 - x3)*(x2 - x3)\n a = (x3*(y2-y1)+x2*(y1-y3)+x1*(y3-y2))/den\n b = (x3*x3*(y1-y2)+x1*x1*(y2-y3)+x2*x2*(y3-y1))/den\n c = (x1*x3*y2*(x3-x1)+x2*x2*(x3*y1-x1*y3)+ &\n x2*(x1*x1*y3-x3*x3*y1))/den\n yy = a*xx*xx + b*xx + c\n Return\nEnd Subroutine ThreePt_Parab_interp\n", "meta": {"hexsha": "fd996dad995d28397c86cb778fe3e46a4640e588", "size": 1772, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "inversor/database/NICOLE/misc/parab_interp.f90", "max_stars_repo_name": "aasensio/DeepLearning", "max_stars_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inversor/database/NICOLE/misc/parab_interp.f90", "max_issues_repo_name": "aasensio/DeepLearning", "max_issues_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inversor/database/NICOLE/misc/parab_interp.f90", "max_forks_repo_name": "aasensio/DeepLearning", "max_forks_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.6875, "max_line_length": 70, "alphanum_fraction": 0.5648984199, "num_tokens": 749, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.770719567662339}} {"text": "! $UWHPSC/codes/adaptive_quadrature/openmp2/functions_mod.f90\n\nmodule functions_mod\n\n ! Define the function we want to integrate.\n ! Also define the indefinite integral (anti-derivative) of g for\n ! use in computing the true solution to compute the error.\n\n ! The counter gcounter can be initialized to 0 in the main program\n ! and then will count how many times the function g is called.\n\n implicit none\n integer :: gcounter \n real(kind=8), parameter :: beta = 10.d0\n save\n\ncontains\n\nreal(kind=8) function g(x)\n ! Test function to integrate\n implicit none\n real(kind=8), intent(in) :: x\n g = exp(-beta**2 * x**2) + sin(x)\n gcounter = gcounter + 1\nend function g\n\nreal(kind=8) function gint(x)\n ! Anti-derivative of g\n implicit none\n real(kind=8), parameter :: pi = 3.141592653589793d0\n real(kind=8), intent(in) :: x\n gint = sqrt(pi)/(2.d0*beta) * erf(beta*x) - cos(x)\nend function gint\n\nend module functions_mod\n", "meta": {"hexsha": "b8eceace2990f508b31dc1d95707c700e2423eca", "size": 971, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/codes/adaptive_quadrature/openmp2/functions_mod.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/codes/adaptive_quadrature/openmp2/functions_mod.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/codes/adaptive_quadrature/openmp2/functions_mod.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.9722222222, "max_line_length": 70, "alphanum_fraction": 0.6776519053, "num_tokens": 275, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7707195593917615}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran77 Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n! Contains a test program for subroutine trssph\n!\n! ... author\n!\n! John C Adams (1996, NCAR)\n!\n! Subroutine trssph is used to demonstrate data transfer between a coarse\n! ten degree equally spaced grid and a higher resolution T64 Global Spectral\n! Gaussian grid. The equally spaced data is stored in a 19 X 36 colatitude-\n! longitude array data_reg which runs north to south with increasing subscript\n! values. The Gaussian grid data is stored in a 192 X 94 longitude-latitude\n! array data_gau which runs south to north with increasing latitude subscript.\n! First trssph is used to transfer data_reg to data_gau. Then trssph is used to\n! transfer data_gau back to data_reg.\n!\n! For testing purposes, data_reg is set equal the analytic function\n!\n! x*y*z\n! f(x, y, z) = e\n!\n! in Cartesian coordinates x, y, z restricted to the surface of the sphere.\n! The same function is used to compute error in data_gau after the data transfer\n! with trssph. Finally this is used to compute error in data_reg after the transfer\n! back with trssph. Output from executing the test program on machines with\n! 32 bit and 64 bit arithmetic is listed below. The minimum required saved\n! and unsaved workspace lengths were predetermined by an earlier call to\n! trssph with nlon_reg=36, nlat_reg=19, nlon_gau=192, nlat_gau=94, lsave=1, lwork=1 and printout\n! of lsvmin and lwkmin.\n!\n!\n! **********************************************************************\n!\n! OUTPUT FROM EXECUTING CODE IN THIS FILE\n!\n! **********************************************************************\n!\n! EQUALLY SPACED TO GAUSSIAN GRID TRANSFER\n!\n! trssph input parameters:\n! intl = 0\n! igrid_reg(1) = -1 igrid_reg(2) = 1\n! nlon_reg = 36 nlat_reg = 19\n! igrid_gau(1) = 2 igrid_gau(2) = 0\n! nlon_gau = 194 nlat_gau = 92\n! lsave = 22213 lwork = 53347\n!\n! trssph output:\n! ier = 0 lsvmin = 22213 lwkmin = 53347\n! *** 32 BIT ARITHMETIC\n! least squares error = 0.201E-06\n! *** 64 BIT ARITHMETIC\n! least squares error = 0.763E-11\n!\n!\n! GAUSSIAN TO EQUALLY SPACED GRID TRANSFER\n!\n! trssph input parameters:\n! intl = 0\n! igrid_gau(1) = 2 igrid_gau(2) = 0\n! nlon_gau = 194 nlat_gau = 92\n! igrid_reg(1) = -1 igrid_reg(2) = 1\n! nlon_reg = 36 nlat_reg = 19\n! lsave = 22213 lwork = 53347\n!\n! trssph output:\n! ier = 0 lsvmin = 22213 lwkmin = 53347\n! *** 32 BIT ARITHMETIC\n! least squares error = 0.618E-06\n! *** 64 BIT ARITHMETIC\n! least squares error = 0.547E-11\n!\n! **********************************************************************\n!\n! END OF OUTPUT ... CODE FOLLOWS\n!\n! **********************************************************************\n!\nprogram test_trssph\n\n use, intrinsic :: ISO_Fortran_env, only: &\n stdout => OUTPUT_UNIT\n\n use spherepack\n\n ! Explicit typing only\n implicit none\n\n !Set grid sizes with parameter statements\n integer(ip), parameter :: NLAT_GAU = 92, NLON_GAU = 194\n integer(ip), parameter :: NLAT_REG = 19, NLON_REG = 36\n real(wp) :: data_reg(NLAT_REG, NLON_REG), data_gau(NLON_GAU, NLAT_GAU)\n real(wp), dimension(NLAT_GAU) :: colatitudes, gaussian_latitudes, gaussian_weights\n integer(ip) :: igrid_reg(2), igrid_gau(2)\n real(wp) :: dlat_reg, dlon_reg, dlon_gau\n real(wp) :: cosp, sinp, cost, sint, xyz, err2, theta, phi, dif\n integer(ip) :: i, j, intl, error_flag\n\n ! Set equally spaced grid increments\n dlat_reg = PI/(NLAT_REG-1)\n dlon_reg = TWO_PI/NLON_REG\n dlon_gau = TWO_PI/NLON_GAU\n\n ! Set given data in data_reg from f(x, y, z)= exp(x*y*z) restricted\n ! to nlat_reg by nlon_reg equally spaced grid on the sphere\n do j=1, NLON_REG\n phi = real(j-1, kind=wp)*dlon_reg\n cosp = cos(phi)\n sinp = sin(phi)\n do i=1, NLAT_REG\n ! Set north to south oriented colatitude point\n theta = real(i-1, kind=wp)*dlat_reg\n cost = cos(theta)\n sint = sin(theta)\n xyz = (sint*(sint*cost*sinp*cosp))\n data_reg(i, j) = exp(xyz)\n end do\n end do\n\n ! Set initial call flag\n intl = 0\n\n ! Flag data_reg grid as north to south equally spaced\n igrid_reg(1) = -1\n\n ! Flag data_reg grid as colatitude by longitude\n igrid_reg(2) = 1\n\n ! Flag data_gau grid as south to north Gaussian\n igrid_gau(1) = 2\n\n ! Flag data_gau grid as longitude by latitude\n igrid_gau(2) = 0\n\n ! Print trssph input parameters\n write (stdout, 100) intl, igrid_reg(1), igrid_reg(2), NLON_REG, NLAT_REG, &\n igrid_gau(1), igrid_gau(2), NLON_GAU, NLAT_GAU\n100 format(//' EQUALLY SPACED TO GAUSSIAN GRID TRANSFER ' , &\n /' trssph input arguments: ' , &\n /' intl = ', i2, &\n /' igrid_reg(1) = ', i2, 2x, ' igrid_reg(2) = ', i2, &\n /' nlon_reg = ', i3, 2x, ' nlat_reg = ', i3, &\n /' igrid_gau(1) = ', i2, 2x, ' igrid_gau(2) = ', i2, &\n /' nlon_gau = ', i3, 2x, ' nlat_gau = ', i3)\n\n ! Transfer data from data_reg to data_gau\n call trssph(intl, igrid_reg, NLON_REG, NLAT_REG, data_reg, igrid_gau, NLON_GAU, &\n NLAT_GAU, data_gau, error_flag)\n\n if (error_flag == 0) then\n !\n ! Compute nlat_gau gaussian colatitudinal points\n ! and set in colatitudes with south to north orientation\n ! for computing error in data_gau\n call compute_gaussian_latitudes_and_weights( &\n NLAT_GAU, gaussian_latitudes, gaussian_weights, error_flag)\n\n colatitudes = PI - gaussian_latitudes\n\n ! Compute the least squares error in data_gau\n err2 = 0.0_wp\n do j=1, NLON_GAU\n phi = real(j - 1, kind=wp) * dlon_gau\n cosp = cos(phi)\n sinp = sin(phi)\n do i=1, NLAT_GAU\n theta = colatitudes(i)\n cost = cos(theta)\n sint = sin(theta)\n xyz = (sint*(sint*cost*sinp*cosp))\n dif = abs(data_gau(j, i)-exp(xyz))\n err2 = err2 + dif**2\n end do\n end do\n err2 = sqrt(err2/(NLON_GAU*NLAT_GAU))\n write (stdout, 300) err2\n300 format(' least squares error = ', e10.3)\n end if\n\n ! Set data_reg to zero\n data_reg = 0.0_wp\n\n write (stdout, 400) intl, igrid_gau(1), igrid_gau(2), NLON_GAU, NLAT_GAU, igrid_reg(1), &\n igrid_reg(2), NLON_REG, NLAT_REG\n400 format(/' GAUSSIAN TO EQUALLY SPACED GRID TRANSFER ' , &\n /' trssph input arguments: ' , &\n /' intl = ', i2, &\n /' igrid_gau(1) = ', i2, 2x, ' igrid_gau(2) = ', i2, &\n /' nlon_gau = ', i3, 2x, ' nlat_gau = ', i3, &\n /' igrid_reg(1) = ', i2, 2x, ' igrid_reg(2) = ', i2, &\n /' nlon_reg = ', i3, 2x, ' nlat_reg = ', i3)\n\n ! Transfer data_gau back to data_reg\n call trssph(intl, igrid_gau, NLON_GAU, NLAT_GAU, data_gau, igrid_reg, NLON_REG, &\n NLAT_REG, data_reg, error_flag)\n\n if (error_flag == 0) then\n\n ! Compute the least squares error in data_reg\n err2 = 0.0\n do j=1, NLON_REG\n phi = real(j-1, kind=wp)*dlon_reg\n cosp = cos(phi)\n sinp = sin(phi)\n do i=1, NLAT_REG\n theta = real(i - 1, kind=wp)*dlat_reg\n cost = cos(theta)\n sint = sin(theta)\n xyz = (sint*(sint*cost*sinp*cosp))\n dif = abs(data_reg(i, j)-exp(xyz))\n err2 = err2+dif**2\n end do\n end do\n err2 = sqrt(err2/(NLAT_REG*NLON_REG))\n write (stdout, 300) err2\n end if\n\nend program test_trssph\n", "meta": {"hexsha": "f921f08efe2b38c53faba55022f5b9d7d88bfc36", "size": 9834, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/testrssph.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "test/testrssph.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "test/testrssph.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 39.4939759036, "max_line_length": 100, "alphanum_fraction": 0.4820012203, "num_tokens": 2768, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529786117893, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.7707194486716855}} {"text": "program NthRootTest\n implicit none\n\n print *, nthroot(10, 7131.5**10)\n print *, nthroot(5, 34.0)\n\ncontains\n\n function nthroot(n, A, p)\n real :: nthroot\n integer, intent(in) :: n\n real, intent(in) :: A\n real, intent(in), optional :: p\n\n real :: rp, x(2)\n\n if ( A < 0 ) then\n stop \"A < 0\" ! we handle only real positive numbers\n elseif ( A == 0 ) then\n nthroot = 0\n return\n end if\n\n if ( present(p) ) then\n rp = p\n else\n rp = 0.001\n end if\n\n x(1) = A\n x(2) = A/n ! starting \"guessed\" value...\n\n do while ( abs(x(2) - x(1)) > rp )\n x(1) = x(2)\n x(2) = ((n-1.0)*x(2) + A/(x(2) ** (n-1.0)))/real(n)\n end do\n\n nthroot = x(2)\n\n end function nthroot\n\nend program NthRootTest\n", "meta": {"hexsha": "881957d030888cb15022a93ea037f080d50482f1", "size": 787, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Nth-root/Fortran/nth-root.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Nth-root/Fortran/nth-root.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Nth-root/Fortran/nth-root.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 18.3023255814, "max_line_length": 64, "alphanum_fraction": 0.4930114358, "num_tokens": 289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922388, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7706286925502501}} {"text": "module routines\nimplicit none\ncontains\n\nfunction cross (A, B)\n real(kind=8), dimension(3), intent(in) :: A, B\n real(kind=8), dimension(3) :: cross\n integer :: i\n\n cross(1) = A(2)*B(3) - A(3)*B(2)\n cross(2) = A(3)*B(1) - A(1)*B(3)\n cross(3) = A(1)*B(2) - A(2)*B(1)\n\nend function cross\n\nend module routines\n", "meta": {"hexsha": "e6935225d4129e0a35558546bb1717deaba9b396", "size": 317, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ME_Numerical_Methods/HW2/ex3/mod.f95", "max_stars_repo_name": "ElenaKusevska/Fortran_exercises", "max_stars_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ME_Numerical_Methods/HW2/ex3/mod.f95", "max_issues_repo_name": "ElenaKusevska/Fortran_exercises", "max_issues_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ME_Numerical_Methods/HW2/ex3/mod.f95", "max_forks_repo_name": "ElenaKusevska/Fortran_exercises", "max_forks_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.6470588235, "max_line_length": 49, "alphanum_fraction": 0.5835962145, "num_tokens": 128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8887588052782736, "lm_q2_score": 0.8670357598021707, "lm_q1q2_score": 0.7705856660153174}} {"text": "! ====================================================================\n! File: vectorUtils.f90\n! Author: C.A.(Sandy) Mader\n! Date Started: July 14, 2014\n! Date Modified:\n\nsubroutine cross_product_3d(v1, v2, cross)\n use constants\n implicit none\n\n real(kind=realType), dimension(3), intent(in) :: v1, v2\n real(kind=realType), dimension(3), intent(out) :: cross\n cross(1) = (v1(2)*v2(3) - v1(3)*v2(2))\n cross(2) = (v1(3)*v2(1) - v1(1)*v2(3))\n cross(3) = (v1(1)*v2(2) - v1(2)*v2(1))\n\nend subroutine cross_product_3d\n\nsubroutine getMag(V, mag)\n\n use constants\n implicit none\n\n ! Subroutine Variables\n real(kind=realType), dimension(3), intent(in) :: V\n real(kind=realType), intent(out) :: mag\n mag = sqrt(v(1)**2 + v(2)**2 + v(3)**2 + 1e-30)\n \nend subroutine getMag\n\nsubroutine getRotationMatrix3d(v1, v2, Mi)\n use precision\n use constants\n implicit none\n\n ! Subroutine Variables\n real(kind=realType), dimension(3), intent(in) :: v1, v2\n real(kind=realType), dimension(3, 3), intent(out) :: Mi\n\n ! Local Variables\n real(kind=realType), dimension(3) :: axis, vv1, vv2\n real(kind=realType):: magV1, magV2, axisMag, angle, arg\n real(kind=realType), dimension(3, 3):: A, C\n real(kind=realType), parameter :: tol= 1.4901161193847656e-08\n\n call getMag(v1, magV1)\n call getMag(v2, magV2)\n \n ! Start by determining the rotation axis by getting the \n ! cross product between v1, v2\n\n call cross_product_3d(v1,v2,axis)\n ! Now Normalize\n call getMag(axis,axisMag)\n \n ! When axisMag is less that sqrt(eps), the acos 'arg' value will be\n ! exactly one which will give a nan in complex mode. \n if (axisMag < tol) then \n ! no rotation at this point, angle is 0\n angle = zero\n ! the axis doesn't matter so set to x\n axis = zero\n axis(1) = one\n else\n axis = axis/axisMag\n ! Now compute the rotation angle about that axis\n vv1 = v1/magv1\n vv2 = v2/magv2\n arg = min(one, vv1(1)*vv2(1) + vv1(2)*vv2(2) + vv1(3)*vv2(3))\n angle = acos(arg)\n end if\n ! Now that we have an axis and an angle,build the rotation Matrix\n ! A skew symmetric representation of the normalized axis \n A(1,1) = zero\n A(1,2) = -axis(3)\n A(1,3) = axis(2)\n A(2,1) = axis(3)\n A(2,2) = zero\n A(2,3) = -axis(1)\n A(3,1) = -axis(2)\n A(3,2) = axis(1)\n A(3,3) = zero\n\n !C = A*A\n C(1,1)= A(1,1)*A(1,1)+A(1,2)*A(2,1)+A(1,3)*A(3,1)\n C(1,2)= A(1,1)*A(1,2)+A(1,2)*A(2,2)+A(1,3)*A(3,2)\n C(1,3)= A(1,1)*A(1,3)+A(1,2)*A(2,3)+A(1,3)*A(3,3)\n C(2,1)= A(2,1)*A(1,1)+A(2,2)*A(2,1)+A(2,3)*A(3,1)\n C(2,2)= A(2,1)*A(1,2)+A(2,2)*A(2,2)+A(2,3)*A(3,2)\n C(2,3)= A(2,1)*A(1,3)+A(2,2)*A(2,3)+A(2,3)*A(3,3)\n C(3,1)= A(3,1)*A(1,1)+A(3,2)*A(2,1)+A(3,3)*A(3,1)\n C(3,2)= A(3,1)*A(1,2)+A(3,2)*A(2,2)+A(3,3)*A(3,2)\n C(3,3)= A(3,1)*A(1,3)+A(3,2)*A(2,3)+A(3,3)*A(3,3)\n \n ! Rodrigues formula for the rotation matrix \n Mi = zero\n Mi(1, 1) = one\n Mi(2, 2) = one\n Mi(3, 3) = one\n \n Mi = Mi + sin(angle)*A + (one-cos(angle))*C\n\nend subroutine getRotationMatrix3d\n", "meta": {"hexsha": "d08b3ca66465b8935061dee342062691748d0c89", "size": 2975, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utils/vectorUtils.f90", "max_stars_repo_name": "marcomangano/idwarp", "max_stars_repo_head_hexsha": "3e0d4837a9b926b1cd227654365ca4adfbc08cbe", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-04-18T00:49:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T10:06:49.000Z", "max_issues_repo_path": "src/utils/vectorUtils.f90", "max_issues_repo_name": "marcomangano/idwarp", "max_issues_repo_head_hexsha": "3e0d4837a9b926b1cd227654365ca4adfbc08cbe", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 39, "max_issues_repo_issues_event_min_datetime": "2019-07-12T07:46:12.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T14:34:53.000Z", "max_forks_repo_path": "src/utils/vectorUtils.f90", "max_forks_repo_name": "marcomangano/idwarp", "max_forks_repo_head_hexsha": "3e0d4837a9b926b1cd227654365ca4adfbc08cbe", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2019-05-19T18:07:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-19T05:39:05.000Z", "avg_line_length": 28.6057692308, "max_line_length": 70, "alphanum_fraction": 0.5862184874, "num_tokens": 1296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107984180243, "lm_q2_score": 0.8221891392358015, "lm_q1q2_score": 0.7705645396338137}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! BenchIT - Performance Measurement for Scientific Applications\n! Contact: developer@benchit.org\n!\n! $Id: gauss.f90 1 2009-09-11 12:26:19Z william $\n! $URL: svn+ssh://william@rupert.zih.tu-dresden.de/svn-base/benchit-root/BenchITv6/kernel/numerical/gauss/F95/0/0/double/gauss.f90 $\n! For license details see COPYING in the package base directory\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! Kernel: Gaussian Linear Equation System Solver\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n! seriell Gauss\nsubroutine entry(A,b,x,n)\n implicit none\n\n integer(kind=4) :: i, i1, i2, j0, j1, j2, j, k, n, m\n real(kind=8) :: A(n,n), mi, b(n), t, x(n), bi, mt, t1\n!****************************************************************\n do i=1,n-1,1\n t=1.0D0/A(i,i)\n do j=i+1,n\n b(j)=b(j)-b(i)*(A(j,i)*t)\n do k=i+1,n\n A(k,j)=A(k,j)-(A(i,j)*t)*A(k,i)\n end do\n end do\n end do\n\n x(n)=b(n)/A(n,n)\n do i=n-1,1,-1\n x(i)=b(i)\n do j=i+1,n\n x(i)=x(i)-A(i,j)*x(j)\n end do\n x(i)=x(i)/A(i,i)\n end do\n!****************************************************************\nend subroutine\n\n", "meta": {"hexsha": "1f82ed6bacfd3f179adfdab62d7f4d1185854083", "size": 1270, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "kernel/numerical/gauss/F95/0/0/double/gauss.f90", "max_stars_repo_name": "Arka2009/x86_64-ubench-ecolab", "max_stars_repo_head_hexsha": "38461e73617c92449f85a84176cd108fb82434b2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "kernel/numerical/gauss/F95/0/0/double/gauss.f90", "max_issues_repo_name": "Arka2009/x86_64-ubench-ecolab", "max_issues_repo_head_hexsha": "38461e73617c92449f85a84176cd108fb82434b2", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "kernel/numerical/gauss/F95/0/0/double/gauss.f90", "max_forks_repo_name": "Arka2009/x86_64-ubench-ecolab", "max_forks_repo_head_hexsha": "38461e73617c92449f85a84176cd108fb82434b2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.75, "max_line_length": 132, "alphanum_fraction": 0.4173228346, "num_tokens": 391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104865, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7705645347082755}} {"text": "module conjugate_gradient\n\n ! import dependencies\n use iso_fortran_env, only : dp => REAL64\n\n implicit none\n\ncontains\n\n !-------------------------------------------------------------------!\n ! Solve the linear system using preconditioned conjugate gradient\n ! method\n !-------------------------------------------------------------------!\n \n subroutine dpparcg(A, M, b, max_it, max_tol, x, iter, tol, flag)\n\n use clock_class, only : clock\n\n real(dp), intent(in) :: A(:,:)\n real(dp), intent(in) :: M(:,:)\n real(dp), intent(in) :: b(:)\n integer , intent(in) :: max_it\n real(dp), intent(in) :: max_tol\n\n real(dp), intent(inout) :: x(:)\n integer , intent(out) :: iter\n real(dp), intent(out) :: tol\n integer , intent(out) :: flag\n\n ! create local data\n real(dp), allocatable :: p(:), r(:), w(:), z(:)\n real(dp), allocatable :: rho(:), tau(:)\n real(dp) :: alpha, beta\n real(dp) :: bnorm, rnorm\n type(clock) :: timer\n\n ! Memory allocations\n allocate(r, p, w, z, mold=x)\n allocate(rho(max_it))\n allocate(tau(max_it))\n\n ! Start the iteration counter\n iter = 1\n\n ! Norm of the right hand side\n bnorm = co_norm2(b)\n\n ! Norm of the initial residual\n r = b - co_matmul(A, x)\n rnorm = co_norm2(r)\n tol = rnorm/bnorm\n rho(iter) = rnorm*rnorm\n\n \n if (this_image() .eq. 1) then\n open(10, file='pcg.log', action='write', position='append')\n end if\n \n ! Apply Iterative scheme until tolerance is achieved\n do while ((tol .gt. max_tol) .and. (iter .lt. max_it))\n\n call timer % start()\n\n ! step (a)\n z = co_matmul(M,r)\n\n ! step (b)\n tau(iter) = co_dot_product(z,r)\n\n ! step (c) compute the descent direction\n if ( iter .eq. 1) then\n ! steepest descent direction p\n beta = 0.0d0\n p = z\n else\n ! take a conjugate direction\n beta = tau(iter)/tau(iter-1)\n p = z + beta*p\n end if\n\n ! step (b) compute the solution update\n w = co_matmul(A,p)\n\n ! step (c) compute the step size for update\n alpha = tau(iter)/co_dot_product(p, w)\n\n ! step (d) Add dx to the old solution\n x = x + alpha*p\n\n ! step (e) compute the new residual\n r = r - alpha*w\n !r = b - matmul(A, x)\n\n ! step(f) update values before next iteration\n rnorm = co_norm2(r)\n tol = rnorm/bnorm\n\n call timer % stop()\n \n if (this_image() .eq. 1) then\n write(10,*) iter, tol, timer % getelapsed()\n print *, iter, tol, timer % getelapsed()\n end if\n \n call timer % reset()\n \n iter = iter + 1\n\n rho(iter) = rnorm*rnorm\n\n end do\n\n close(10)\n\n deallocate(r, p, w, rho, tau)\n\n flag = 0\n\n end subroutine dpparcg\n \n subroutine dparcg(A, b, max_it, max_tol, x, iter, tol, flag)\n\n use clock_class, only : clock\n\n real(dp), intent(in) :: A(:,:)\n real(dp), intent(in) :: b(:)\n integer , intent(in) :: max_it\n real(dp), intent(in) :: max_tol\n\n real(dp), intent(inout) :: x(:)\n integer , intent(out) :: iter\n real(dp), intent(out) :: tol\n integer , intent(out) :: flag\n\n ! create local data\n real(dp), allocatable :: p(:), r(:), w(:)\n real(dp), allocatable :: rho(:)\n real(dp) :: alpha, beta\n real(dp) :: bnorm, rnorm\n \n type(clock) :: timer\n \n ! Memory allocations\n allocate(r, p, w, mold=x)\n allocate(rho(max_it))\n\n ! Start the iteration counter\n iter = 1\n\n ! Norm of the right hand side\n bnorm = co_norm2(b)\n\n ! Norm of the initial residual\n r = b - co_matmul(A, x)\n rnorm = co_norm2(r)\n tol = rnorm/bnorm\n rho(iter) = rnorm*rnorm\n\n if (this_image() .eq. 1) then\n open(10, file='cg.log', action='write', position='append')\n end if\n\n ! Apply Iterative scheme until tolerance is achieved\n do while ((tol .gt. max_tol) .and. (iter .lt. max_it))\n\n call timer % start()\n \n ! step (a) compute the descent direction\n if ( iter .eq. 1) then\n ! steepest descent direction p\n p = r\n else\n ! take a conjugate direction\n beta = rho(iter)/rho(iter-1)\n p = r + beta*p\n end if\n\n ! step (b) compute the solution update\n w = co_matmul(A,p)\n\n ! step (c) compute the step size for update\n alpha = rho(iter)/co_dot_product(p, w)\n\n ! step (d) Add dx to the old solution\n x = x + alpha*p\n\n ! step (e) compute the new residual\n r = r - alpha*w\n !r = b - matmul(A, x)\n\n ! step(f) update values before next iteration\n rnorm = co_norm2(r)\n tol = rnorm/bnorm\n\n call timer % stop()\n\n \n if (this_image() .eq. 1) then\n write(10,*) iter, tol, timer % getelapsed()\n print *, iter, tol, timer % getelapsed()\n end if\n \n call timer % reset()\n \n iter = iter + 1\n\n rho(iter) = rnorm*rnorm\n\n end do\n\n close(10)\n\n deallocate(r, p, w, rho)\n\n flag = 0\n\n end subroutine dparcg\n\n !===================================================================!\n ! Function to compute the dot product of two distributed vector\n !===================================================================!\n\n function co_dot_product(a, b) result(dot)\n\n real(8), intent(in) :: a(:), b(:) \n real(8) :: dot\n\n ! find dot product, sum over processors, take sqrt and return\n dot = dot_product(a, b) \n call co_sum (dot)\n\n end function co_dot_product\n\n !===================================================================!\n ! Function to compute the norm of a distributed vector\n !===================================================================!\n\n function co_norm2(x) result(norm)\n\n real(8), intent(in) :: x(:) \n real(8) :: xdot, norm\n\n ! find dot product, sum over processors, take sqrt and return\n xdot = dot_product(x,x) \n call co_sum (xdot)\n norm = sqrt(xdot)\n\n end function co_norm2\n\n !===================================================================!\n ! Function that computes the matrix vector product in a distributed\n ! fashion for columnwise decomposition of matrix\n ! ===================================================================!\n\n function co_matmul(A, x) result(b)\n\n ! Arguments\n real(8), intent(in) :: A(:,:)\n real(8), intent(in) :: x(:)\n real(8) :: b(size(x))\n\n ! Local variables\n integer :: nimages\n integer :: me, local_size\n integer :: stat\n character(10) :: msg\n\n ! Create a local vector of global sizse (optimize this!)\n real(8), allocatable :: work(:)\n allocate(work, mold=A(:,1))\n\n ! Determine partition\n nimages = num_images()\n me = this_image()\n local_size = size(x)\n\n ! Multiply, sum and distrbute\n work = matmul(A,x)\n call co_sum(work, stat=stat, errmsg=msg)\n b = work((me-1)*local_size+1:me*local_size)\n\n deallocate(work)\n\n end function co_matmul\n\nend module conjugate_gradient\n\nmodule system\n\n implicit none\n\ncontains\n\n !-------------------------------------------------------------------!\n ! Assemble -U_xx = 2x - 0.5, U(0) = 1; U(1)= 0, x in [0,1]\n !-------------------------------------------------------------------!\n\n subroutine assemble_system_dirichlet(a, b, npts, V, rhs, u, P, ispreconditioned)\n\n implicit none\n\n real(8), intent(in) :: a, b ! bounds of the domain\n integer, intent(in) :: npts ! number of interior points\n real(8), intent(out) :: V(npts,npts) ! banded matrix\n real(8), intent(out) :: rhs(npts)\n real(8), intent(out) :: u(npts)\n real(8), intent(out) :: P(npts,npts)\n real(8) :: S(npts,npts), D(npts, npts)\n\n real(8), parameter :: PI = 3.141592653589793d0\n real(8) :: h, alpha\n integer :: M, N\n integer :: i, j, k\n\n logical, intent(in) :: ispreconditioned\n \n ! h = width / num_interior_pts + 1\n h = (b-a)/dble(npts+1)\n V = 0.0d0\n\n ! Size of the linear system = unknowns (interior nodes)\n M = npts ! nrows\n N = npts ! ncols\n\n ! Set the inner block\n rows: do i = 1, M\n cols: do j = 1, N\n if (j .eq. i-1) then\n ! lower triangle\n V(j,i) = -1.0d0\n else if (j .eq. i+1) then \n ! upper triangle\n V(j,i) = -1.0d0\n else if (j .eq. i) then \n ! diagonal\n V(j,i) = 2.0d0\n else\n ! skip\n end if\n end do cols\n end do rows\n\n ! Assemble the RHS\n do i = 1, M\n rhs(i) = h*h*(2.0d0*dble(i)*h - 0.5d0)\n end do\n rhs(1) = rhs(1) + 1.0d0\n rhs(M) = rhs(M)\n\n ! Initial solution profile use sin function as a first guess\n do i = 1, M\n u(i) = sin(dble(i)*h*PI)\n end do\n\n if (ispreconditioned .eqv. .true.) then\n ! Find the sine transform matrix\n alpha = sqrt(2.0d0/dble(npts+1))\n do j = 1, M\n do k = 1, N\n S(k,j) = alpha*sin(PI*dble(j*k)/dble(npts+1))\n end do\n end do\n\n ! Find the diagonal matrix\n D = matmul(S, matmul(V, S))\n\n ! Invert the digonal matrix easily\n do j = 1, M\n D(j,j) = 1.0d0/D(j,j)\n end do\n\n ! Define the preconditioner\n p = matmul(S, matmul(D, S))\n end if\n\nend subroutine assemble_system_dirichlet\n\nend module system\n\nprogram main\n\n use conjugate_gradient, only: dparcg, dpparcg\n use system, only : assemble_system_dirichlet\n use clock_class, only : clock\n\n!!$ serial : block\n!!$ \n!!$ integer, parameter :: npts = 64\n!!$ real(8), parameter :: max_tol = 1.0d-8\n!!$ integer, parameter :: max_it = 100000\n!!$ real(8) :: x(npts,3), b(npts), A(npts,npts), P(npts, npts)\n!!$ integer :: iter, flag, i, j\n!!$ real(8) :: tol\n!!$\n!!$ ! solve using CG\n!!$ call assemble_system_dirichlet(0.0d0, 1.0d0, npts, A, b, x(:,2), P) \n!!$ call dparcg(A, b, max_it, max_tol, x(:,2), iter, tol, flag)\n!!$ print *, 'cg', tol, iter\n!!$\n!!$ end block serial\n\n parallel : block\n\n integer, parameter :: npts = 25000\n integer, parameter :: max_it = 1000\n real(8), parameter :: max_tol = 1.0d-8\n\n real(8), allocatable :: x(:)[:], b(:)[:], A(:,:)[:], P(:,:)[:]\n real(8), allocatable :: xtmp(:), btmp(:), Atmp(:,:), Ptmp(:,:)\n\n integer :: iter, flag, i, j\n real(8) :: tol \n integer :: nimages\n integer :: me, local_size\n type(clock) :: timer\n logical , parameter :: precon = .false.\n \n allocate(A(npts,npts)[*])\n allocate(P(npts,npts)[*])\n allocate(x(npts)[*])\n allocate(b(npts)[*])\n\n ! Determine partition\n nimages = num_images()\n me = this_image()\n local_size = npts/nimages\n\n ! Assemble system on master\n if (me .eq. 1) then\n call assemble_system_dirichlet(0.0d0, 1.0d0, npts, A, b, x, P, precon)\n end if\n\n !sync all\n \n call timer % start()\n\n ! Split A, b, x into pieces\n allocate(Atmp(npts,local_size))\n allocate(Ptmp(npts,local_size))\n allocate(xtmp(local_size))\n allocate(btmp(local_size))\n\n \n ! Copy from proc 1\n Atmp = A(1:npts,(me-1)*local_size+1:me*local_size)[1]\n Ptmp = P(1:npts,(me-1)*local_size+1:me*local_size)[1]\n xtmp = x((me-1)*local_size+1:me*local_size)[1]\n btmp = b((me-1)*local_size+1:me*local_size)[1]\n\n ! clearup memory\n deallocate(A,b,x,P)\n\n ! Distribute the work to processors\n\n if (precon .eqv. .false.) then\n call dparcg(Atmp, btmp, max_it, max_tol, xtmp, iter, tol, flag)\n else\n call dpparcg(Atmp, Ptmp, btmp, max_it, max_tol, xtmp, iter, tol, flag)\n end if\n \n call timer % stop()\n\n if (this_image() .eq. 1) then\n write(*, '(\"Model run time:\",F8.3,\" seconds\")') timer % getelapsed()\n end if\n\n !if (me .eq. 1) then\n print *, 'cg', tol, iter\n \n !end if\n\n end block parallel\n\nend program main\n", "meta": {"hexsha": "5346eaaf2c745918bc4b7679557eecef0986c52d", "size": 11931, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/coarray_cg.f90", "max_stars_repo_name": "komahanb/coarray-fortran", "max_stars_repo_head_hexsha": "9af9cab1c1e1083ca63cd024af16632cca17b617", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-07-04T19:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-12T08:05:41.000Z", "max_issues_repo_path": "src/coarray_cg.f90", "max_issues_repo_name": "komahanb/coarray-fortran", "max_issues_repo_head_hexsha": "9af9cab1c1e1083ca63cd024af16632cca17b617", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/coarray_cg.f90", "max_forks_repo_name": "komahanb/coarray-fortran", "max_forks_repo_head_hexsha": "9af9cab1c1e1083ca63cd024af16632cca17b617", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-07-04T19:57:48.000Z", "max_forks_repo_forks_event_max_datetime": "2018-07-04T19:57:48.000Z", "avg_line_length": 25.1178947368, "max_line_length": 82, "alphanum_fraction": 0.5220015087, "num_tokens": 3552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029487, "lm_q2_score": 0.8221891392358015, "lm_q1q2_score": 0.7705645338660947}} {"text": "\tSUBROUTINE getgrid(Nx,Lx,pi,name_config,x,kx)\n\t!--------------------------------------------------------------------\n\t!\n\t!\n\t! PURPOSE\n\t!\n\t! This subroutine gets grid points and fourier frequencies for a\n\t! pseudospectral simulation of the 1D nonlinear Klein-Gordon equation\n\t!\n\t! u_{tt}-u_{xx}+u=Es*u^3\n\t!\n\t! The boundary conditions are u(x=0)=u(2*Lx*\\pi) \n\t!\n\t! INPUT\n\t!\n\t! .. Scalars ..\n\t! Nx\t\t\t\t= number of modes in x - power of 2 for FFT\n\t! pi\t\t\t\t= 3.142....\n\t! Lx\t\t\t\t= width of box in x direction\n\t! OUTPUT\n\t!\n\t! .. Vectors ..\n\t! kx\t\t\t\t= fourier frequencies in x direction\n\t! x\t\t\t\t= x locations\n\t!\n\t! LOCAL VARIABLES\n\t!\n\t! .. Scalars ..\n\t! i\t\t\t\t= loop counter in x direction\n\t!\n\t! REFERENCES\n\t!\n\t! ACKNOWLEDGEMENTS\n\t!\n\t! ACCURACY\n\t!\t\t\n\t! ERROR INDICATORS AND WARNINGS\n\t!\n\t! FURTHER COMMENTS\n\t! Check that the initial iterate is consistent with the \n\t! boundary conditions for the domain specified\n\t!--------------------------------------------------------------------\n\t! External routines required\n\t! \n\t! External libraries required\n IMPLICIT NONE\n\t! Declare variables\n\tINTEGER(KIND=4), INTENT(IN)\t\t\t :: Nx\n\tREAL(kind=8), INTENT(IN)\t\t\t :: Lx,pi\n\tREAL(KIND=8), DIMENSION(1:NX), INTENT(OUT) \t :: x\n\tCOMPLEX(KIND=8), DIMENSION(1:NX/2 + 1), INTENT(OUT)\t:: kx\n\tCHARACTER*100, INTENT(OUT)\t\t\t :: name_config\n\tINTEGER(kind=4)\t\t\t\t\t :: i\n\t\t\n\tDO i=1,1+Nx/2\n\t\tkx(i)= cmplx(0.0d0,1.0d0,kind(0d0))*REAL(i-1,kind(0d0))/Lx \t\t\t\n\tEND DO\n\tkx(1+Nx/2)=0.0d0\n\t\t\n\tDO i=1,Nx\n\t\tx(i)=(-1.0d0 + 2.0d0*REAL(i-1,kind(0d0))/REAL(Nx,kind(0d0)))*pi*Lx\n\tEND DO\n\t! Save x grid points in text format\n\tname_config = 'xcoord.dat' \n\tOPEN(unit=11,FILE=name_config,status=\"UNKNOWN\") \t\n\tREWIND(11)\n\tDO i=1,Nx\n\t\tWRITE(11,*) x(i)\n\tEND DO\n\tCLOSE(11)\n\t\n\tEND SUBROUTINE getgrid\n", "meta": {"hexsha": "3146f8278de91b628c15a4f857692c4d8b32367e", "size": 1787, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Codes/Fortran1DFourierCompactR2C/getgrid.f90", "max_stars_repo_name": "bkmgit/KleinGordon1D", "max_stars_repo_head_hexsha": "ce6ba332e542d74b72069ae253cca5e0a2ade425", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-01-21T03:57:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-21T03:57:51.000Z", "max_issues_repo_path": "Codes/Fortran1DFourierR2C/getgrid.f90", "max_issues_repo_name": "bkmgit/KleinGordon1D", "max_issues_repo_head_hexsha": "ce6ba332e542d74b72069ae253cca5e0a2ade425", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Codes/Fortran1DFourierR2C/getgrid.f90", "max_forks_repo_name": "bkmgit/KleinGordon1D", "max_forks_repo_head_hexsha": "ce6ba332e542d74b72069ae253cca5e0a2ade425", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.4794520548, "max_line_length": 70, "alphanum_fraction": 0.571348629, "num_tokens": 640, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.7704786711453351}} {"text": "real(kind=8) function burger (t, x ,nu) result(burg)\n implicit none\n \n real(kind=8), intent(in) :: t, x, nu\n real(kind=8) :: pi = 4 * atan(1.0_8)\n \n burg = -2 * nu * (-(-8 * t + 2 * x) * exp(-(-4 * t + x)** 2 / &\n\t\t(4 * nu * (t + 1))) / (4 * nu * (t + 1)) - &\n\t\t(-8 * t + 2 * x - 4 * pi) * exp(-(-4 * t + x - 2 * pi)** 2 / &\n\t\t(4 * nu * (t + 1))) / (4 * nu * (t + 1))) / &\n\t\t\t(exp(-(-4 * t + x - 2 * pi)** 2 / (4 * nu * (t + 1))) + &\n\t\t\t\texp(-(-4 * t + x)** 2 / (4 * nu * (t + 1)))) + 4\n\nend function burger\n\nsubroutine spaceevenly(start, finish, number, arrayout)\n implicit none\n \n integer, intent(in) :: start, finish\n real(kind=8), intent(in) :: number\n real(kind=8) :: div\n real(kind=8), dimension(0:finish), intent(out) :: arrayout\n integer :: i\n \n div = number / ((finish-1) - (start-1))\n \n do i=start, finish\n arrayout(i) = div * i\n end do\n\nend subroutine spaceevenly\n \n!subroutine copy_real_array(source, destination, size)\n !implicit none\n ", "meta": {"hexsha": "0c32d8b5bbdba0f526fd3584dd53e47c6746dd7f", "size": 1019, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "l3/functions.f90", "max_stars_repo_name": "dominique120/12-steps-navier-stokes", "max_stars_repo_head_hexsha": "3e195bf7f7895f83f5f2248ef48dc13b76e8b5de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "l3/functions.f90", "max_issues_repo_name": "dominique120/12-steps-navier-stokes", "max_issues_repo_head_hexsha": "3e195bf7f7895f83f5f2248ef48dc13b76e8b5de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "l3/functions.f90", "max_forks_repo_name": "dominique120/12-steps-navier-stokes", "max_forks_repo_head_hexsha": "3e195bf7f7895f83f5f2248ef48dc13b76e8b5de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.1142857143, "max_line_length": 67, "alphanum_fraction": 0.4857703631, "num_tokens": 382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425289753969, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7703109451278727}} {"text": "! This program will numerically compute the integral of\r\n! 4/(1+x*x) \r\n! from 0 to 1. The value of this integral is pi -- which \r\n! is great since it gives us an easy way to check the answer.\r\n\r\n! The program was parallelized using OpenMP by adding just\r\n! four lines \r\n\r\n! (1) A line to include omp.h -- the include file that \r\n! contains OpenMP's function prototypes and constants.\r\n\r\n! (2) A pragma that tells OpenMP to create a team of threads\r\n\r\n! (3) A pragma to cause one of the threads to print the\r\n! number of threads being used by the program.\r\n\r\n! (4) A pragma to split up loop iterations among the team\r\n! of threads. This pragma includes 2 clauses to (1) create a \r\n! private variable and (2) to cause the threads to compute their\r\n! sums locally and then combine their local sums into a \r\n! single global value.\r\n\r\n! History: C Code written by Tim Mattson, 11/1999\r\n! Adapted to Fortran code by Helen He, 09/2017 \r\n! Changed to Fortran90 code by Helen He, 11/2020 \r\n\r\n PROGRAM MAIN\r\n USE OMP_LIB\r\n IMPLICIT NONE\r\n\r\n INTEGER :: i, id, nthreads\r\n INTEGER, PARAMETER :: num_steps = 100000000\r\n REAL*8 :: x, pi, sum, step\r\n REAL*8 :: start_time, run_time\r\n\r\n DO id = 1, 4\r\n sum = 0.0\r\n\r\n step = 1.0 / num_steps\r\n\r\n CALL OMP_SET_NUM_THREADS(id)\r\n start_time = OMP_GET_WTIME()\r\n\r\n!$OMP PARALLEL PRIVATE(i,x) \r\n!$OMP SINGLE\r\n nthreads = OMP_GET_NUM_THREADS()\r\n!$OMP END SINGLE NOWAIT\r\n!$OMP DO REDUCTION(+:sum)\r\n DO i = 1, num_steps\r\n x = (i - 0.5) * step\r\n sum = sum + 4.0 / (1.0 + x * x)\r\n ENDDO\r\n!$OMP END DO\r\n!$OMP END PARALLEL \r\n\r\n pi = step * sum\r\n run_time = OMP_GET_WTIME() - start_time\r\n WRITE(*,100) pi, run_time, nthreads\r\n100 FORMAT('pi is ',f15.8,' in ',f8.3,'secs and ',i3,' threads')\r\n\r\n ENDDO\r\n\r\n END PROGRAM MAIN\r\n", "meta": {"hexsha": "35cab8da4b2095ad372ad12e0c4799efbffc01c0", "size": 1842, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Exercises/Fortran/solutions/pi_loop.f90", "max_stars_repo_name": "zafar-hussain/OmpCommonCore", "max_stars_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 37, "max_stars_repo_stars_event_min_datetime": "2020-04-21T18:05:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:10:18.000Z", "max_issues_repo_path": "Exercises/Fortran/solutions/pi_loop.f90", "max_issues_repo_name": "zafar-hussain/OmpCommonCore", "max_issues_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-12-09T19:42:54.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T21:27:04.000Z", "max_forks_repo_path": "Exercises/Fortran/solutions/pi_loop.f90", "max_forks_repo_name": "zafar-hussain/OmpCommonCore", "max_forks_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2020-09-05T18:54:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-23T02:19:12.000Z", "avg_line_length": 28.78125, "max_line_length": 66, "alphanum_fraction": 0.6373507058, "num_tokens": 547, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.7702901981522096}} {"text": "PROGRAM main\n\n IMPLICIT NONE\n\n REAL :: sd1, sd2, av, scale_fac\n REAL :: x_min, x_max, dx, x\n REAL :: sum_of_diffs, sum_of_vals, sum_of_sqs\n REAL :: offset\n INTEGER :: i, n_bins\n\n n_bins = 1000\n\n ! Using a variable for this is clearer, and slightly more efficient\n scale_fac = 2.0 * 3.14159\n ! I use a variable here too for clarity and ease of changing\n offset = 0.0\n\n\n ! We can make the x-axis several ways.\n ! Finding dx and incrementing x in the loop is one.\n ! Another is to use the loop index itself and do e.g. REAL(i)/REAL(n_bins-1)\n\n x_min = 0.0\n x_max = 2.0\n dx = (x_max - x_min) / REAL(n_bins + 1)\n\n\n ! Initialise all the running sums to 0\n sum_of_diffs = 0.0\n sum_of_vals = 0.0\n sum_of_sqs = 0.0\n\n x = x_min\n\n !Calculate average, and 1-pass SD running vals\n DO i = 1, n_bins\n\n sum_of_vals = sum_of_vals + (offset + sin(scale_fac * x))\n\n sum_of_sqs = sum_of_sqs + (offset + sin(scale_fac * x))**2\n\n x = x + dx\n\n END DO\n\n !Finish calc of average as it is needed for the 2-pass SD\n av = sum_of_vals / REAL(n_bins)\n\n\n x = x_min\n\n ! Calculate 2-pass SD running val\n DO i = 1, n_bins\n\n sum_of_diffs = sum_of_diffs + (offset + sin(scale_fac * x) - av)**2\n\n x = x + dx\n\n END DO\n\n !Finish calcs and print\n\n sd2 = sqrt(1.0/REAL(n_bins -1) * sum_of_diffs)\n\n sd1 = sqrt(1.0/REAL(n_bins -1) * (sum_of_sqs - REAL(n_bins) * av*av))\n\n PRINT'(A, I5, A, F8.3, A, F8.3)', \"Number of bins: \", n_bins, \" Offset: \", &\n offset, \" Average Value: \", av\n PRINT'(A, F8.3, A, F8.3)', \"Two-pass SD: \", sd2, \" One-pass SD: \", sd1\n\n\nEND PROGRAM\n", "meta": {"hexsha": "9dcc23ff65467fb88eb50612693a8fdf6672268e", "size": 1583, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ModelSolutions/StdDev_and_Average.f90", "max_stars_repo_name": "WarwickRSE/Fortran4Researchers", "max_stars_repo_head_hexsha": "14467a32a516fdc0cf33341aea8d5b26f4501b51", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-10-03T08:28:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-28T02:59:38.000Z", "max_issues_repo_path": "ModelSolutions/StdDev_and_Average.f90", "max_issues_repo_name": "WarwickRSE/Fortran4Researchers", "max_issues_repo_head_hexsha": "14467a32a516fdc0cf33341aea8d5b26f4501b51", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ModelSolutions/StdDev_and_Average.f90", "max_forks_repo_name": "WarwickRSE/Fortran4Researchers", "max_forks_repo_head_hexsha": "14467a32a516fdc0cf33341aea8d5b26f4501b51", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.6849315068, "max_line_length": 79, "alphanum_fraction": 0.6285533797, "num_tokens": 573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218434359675, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.7702505207985445}} {"text": "\nsubroutine compute_flux (lo, hi, domlo, domhi, phi, philo, phihi, &\n fluxx, fxlo, fxhi, fluxy, fylo, fyhi, &\n dx, bc) bind(C, name=\"compute_flux\")\n\n use amrex_fort_module, only : amrex_real\n use amrex_bc_types_module\n implicit none\n\n integer lo(2), hi(2), domlo(2), domhi(2)\n integer philo(2), phihi(2), fxlo(2), fxhi(2), fylo(2), fyhi(2)\n real(amrex_real), intent(in) :: phi (philo(1):phihi(1),philo(2):phihi(2))\n real(amrex_real), intent(inout) :: fluxx( fxlo(1): fxhi(1), fxlo(2): fxhi(2))\n real(amrex_real), intent(inout) :: fluxy( fylo(1): fyhi(1), fylo(2): fyhi(2))\n real(amrex_real), intent(in) :: dx(2)\n integer, intent(in) :: bc(2,2,1) ! (dim,lohi,ncomp)\n\n ! local variables\n integer i,j\n\n ! x-fluxes\n do j = lo(2), hi(2)\n do i = lo(1), hi(1)+1\n fluxx(i,j) = ( phi(i,j) - phi(i-1,j) ) / dx(1)\n end do\n end do\n\n ! y-fluxes\n do j = lo(2), hi(2)+1\n do i = lo(1), hi(1)\n fluxy(i,j) = ( phi(i,j) - phi(i,j-1) ) / dx(2)\n end do\n end do\n\n ! lo-x boundary, ghost cell contains value on boundary\n if (domlo(1) .eq. lo(1) .and. &\n (bc(1,1,1) .eq. amrex_bc_foextrap .or. bc(1,1,1) .eq. amrex_bc_ext_dir) ) then\n i = lo(1)\n do j = lo(2), hi(2)\n fluxx(i,j) = ( phi(i,j) - phi(i-1,j) ) / (0.5d0*dx(1))\n end do\n end if\n\n ! hi-x boundary, ghost cell contains value on boundary\n if (domhi(1) .eq. hi(1) .and. &\n (bc(1,2,1) .eq. amrex_bc_foextrap .or. bc(1,2,1) .eq. amrex_bc_ext_dir) ) then\n i = hi(1)+1\n do j = lo(2), hi(2)\n fluxx(i,j) = ( phi(i,j) - phi(i-1,j) ) / (0.5d0*dx(1))\n end do\n end if\n\n ! lo-y boundary, ghost cell contains value on boundary\n if (domlo(2) .eq. lo(2) .and. &\n (bc(2,1,1) .eq. amrex_bc_foextrap .or. bc(2,1,1) .eq. amrex_bc_ext_dir) ) then\n j = lo(2)\n do i = lo(1), hi(1)\n fluxy(i,j) = ( phi(i,j) - phi(i,j-1) ) / (0.5d0*dx(2))\n end do\n end if\n\n ! lo-y boundary, ghost cell contains value on boundary\n if (domhi(2) .eq. hi(2) .and. &\n (bc(2,2,1) .eq. amrex_bc_foextrap .or. bc(2,2,1) .eq. amrex_bc_ext_dir) ) then\n j = hi(2)+1\n do i = lo(1), hi(1)\n fluxy(i,j) = ( phi(i,j) - phi(i,j-1) ) / (0.5d0*dx(2))\n end do\n end if\n\nend subroutine compute_flux\n\n\nsubroutine update_phi (lo, hi, phiold, polo, pohi, phinew, pnlo, pnhi, &\n fluxx, fxlo, fxhi, fluxy, fylo, fyhi, &\n dx, dt) bind(C, name=\"update_phi\")\n\n use amrex_fort_module, only : amrex_real\n implicit none\n\n integer lo(2), hi(2), polo(2), pohi(2), pnlo(2), pnhi(2), fxlo(2), fxhi(2), fylo(2), fyhi(2)\n real(amrex_real), intent(in) :: phiold(polo(1):pohi(1),polo(2):pohi(2))\n real(amrex_real), intent(inout) :: phinew(pnlo(1):pnhi(1),pnlo(2):pnhi(2))\n real(amrex_real), intent(in ) :: fluxx (fxlo(1):fxhi(1),fxlo(2):fxhi(2))\n real(amrex_real), intent(in ) :: fluxy (fylo(1):fyhi(1),fylo(2):fyhi(2))\n real(amrex_real), intent(in) :: dx(2)\n real(amrex_real), intent(in) :: dt\n\n ! local variables\n integer i,j\n real(amrex_real) :: dtdx(2)\n\n dtdx = dt/dx\n\n do j = lo(2), hi(2)\n do i = lo(1), hi(1)\n\n phinew(i,j) = phiold(i,j) &\n + dtdx(1) * (fluxx(i+1,j ) - fluxx(i,j)) &\n + dtdx(2) * (fluxy(i ,j+1) - fluxy(i,j))\n\n end do\n end do\n\nend subroutine update_phi\n", "meta": {"hexsha": "30a04a4c76b00c2a337a262fda537daf9d0d754b", "size": 3333, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorials/Basic/HeatEquation_EX2_C/Source/advance_2d.f90", "max_stars_repo_name": "ylunalin/amrex", "max_stars_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-20T13:04:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-20T13:04:05.000Z", "max_issues_repo_path": "Tutorials/Basic/HeatEquation_EX2_C/Source/advance_2d.f90", "max_issues_repo_name": "ylunalin/amrex", "max_issues_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorials/Basic/HeatEquation_EX2_C/Source/advance_2d.f90", "max_forks_repo_name": "ylunalin/amrex", "max_forks_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-01-17T05:00:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-17T05:00:26.000Z", "avg_line_length": 31.4433962264, "max_line_length": 94, "alphanum_fraction": 0.5529552955, "num_tokens": 1390, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009457116781, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7701870771641719}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! z_poly_roots \n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine computes the roots of a polynomial expressed in the monomial \n! basis. The vector of COEFFS is in descending order by degree:\n!\n! p(x) = COEFFS(1)*x^N + COEFFS(2)*x^N-1 + ... + COEFFS(N)*x + COEFFS(N+1)\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! N INTEGER\n! degree of the polynomial\n!\n! COEFFS COMPLEX(8) array of dimension (N+1)\n! coefficients of polynomial ordered from highest\n! degree coefficient to lowest degree\n!\n! OUTPUT VARIABLES:\n!\n! ROOTS COMPLEX(8) array of dimension (N)\n! computed roots\n!\n! RESIDUALS COMPLEX(8) array of dimension (N)\n! residuals of the computed roots\n!\n! INFO INTEGER \n! INFO = 1 implies companion QZ algorithm failed\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine z_poly_roots(N,COEFFS,ROOTS,RESIDUALS,INFO)\n\n implicit none\n \n ! input variables\n integer, intent(in) :: N\n integer, intent(inout) :: INFO\n complex(8), intent(in) :: COEFFS(N+1)\n complex(8), intent(inout) :: ROOTS(N)\n real(8), intent(inout) :: RESIDUALS(N)\n \n ! compute variables\n integer :: ii\n real(8) :: scl\n logical, allocatable :: P(:)\n integer, allocatable :: ITS(:)\n real(8), allocatable :: Q(:),D1(:),C1(:),B1(:)\n real(8), allocatable :: D2(:),C2(:),B2(:)\n real(8) :: normc\n complex(8) :: sclc\n complex(8), allocatable :: V(:),W(:)\n interface\n function l_upr1fact_hess(m,flags)\n logical :: l_upr1fact_hess\n integer, intent(in) :: m\n logical, dimension(m-2), intent(in) :: flags\n end function l_upr1fact_hess\n end interface\n interface\n function l_upr1fact_inversehess(m,flags)\n logical :: l_upr1fact_inversehess\n integer, intent(in) :: m\n logical, dimension(m-2), intent(in) :: flags\n end function l_upr1fact_inversehess\n end interface\n interface\n function l_upr1fact_cmv(m,flags)\n logical :: l_upr1fact_cmv\n integer, intent(in) :: m\n logical, dimension(m-2), intent(in) :: flags\n end function l_upr1fact_cmv\n end interface\n interface\n function l_upr1fact_random(m,flags)\n logical :: l_upr1fact_random\n integer, intent(in) :: m\n logical, dimension(m-2), intent(in) :: flags\n end function l_upr1fact_random\n end interface\n \n ! allocate memory\n allocate(P(N-2),ITS(N-1),Q(3*(N-1)),D1(2*(N+1)),C1(3*N),B1(3*N)) \n allocate(V(N),W(N),D2(2*(N+1)),C2(3*N),B2(3*N)) \n\n ! initialize INFO\n INFO = 0\n\n ! fill P\n P = .FALSE.\n\n ! compute the norm of the monic polynomial\n normc = 0d0\n do ii=1,N\n normc = normc + abs(COEFFS(ii+1)/COEFFS(1))**2\n end do\n normc = sqrt(normc)\n\n ! our latest analysis shows that using QR (on the equivalent monic polynomial)\n ! is as accurate as using QZ with abs(COEFFS(1)) < 1, but faster\n ! for very large normc the QZ is still advantegous, hence\n ! we choose conservatievly 1e4\n if (normc.LT.1e8) then\n ! use QR\n \n ! fill V \n sclc = COEFFS(1)\n V(N) = ((-1d0)**(N))*COEFFS(N+1)/sclc\n do ii=1,(N-1)\n V(ii) = -COEFFS(N+1-ii)/sclc\n end do\n \n ! factor companion matrix\n call z_compmat_compress(N,P,V,Q,D1,C1,B1)\n \n ! call z_upr1fpen_qz\n call z_upr1fact_qr(.FALSE.,.FALSE.,l_upr1fact_hess,N,P,Q,D1,C1,B1,N,V,ITS,INFO)\n \n if (INFO.NE.0) then\n INFO = 1\n end if\n\n ! extract roots\n call z_upr1utri_decompress(.TRUE.,N,D1,C1,B1,ROOTS)\n \n else\n ! use QZ\n\n ! fill V and W\n scl = maxval(abs(COEFFS))\n V(N) = ((-1d0)**(N))*COEFFS(N+1)/scl\n do ii=1,(N-1)\n V(ii) = -COEFFS(N+1-ii)/scl\n end do\n W = cmplx(0d0,0d0,kind=8)\n W(N) = COEFFS(1)/scl\n \n ! factor companion matrix\n call z_comppen_compress(N,P,V,W,Q,D1,C1,B1,D2,C2,B2)\n \n ! call z_upr1fpen_qz\n call z_upr1fpen_qz(.FALSE.,.FALSE.,l_upr1fact_hess,N,P,Q,D1,C1,B1,D2,C2,B2,N,V,W,ITS,INFO)\n \n if (INFO.NE.0) then\n INFO = 1\n end if\n\n ! extract roots\n call z_upr1utri_decompress(.TRUE.,N,D1,C1,B1,V)\n call z_upr1utri_decompress(.TRUE.,N,D2,C2,B2,W)\n do ii=1,N\n ROOTS(ii) = V(ii)/W(ii)\n end do\n \n end if\n \n ! compute residuals\n call z_poly_residuals(N,COEFFS,ROOTS,0,RESIDUALS)\n \n ! free memory\n deallocate(P,ITS,Q,D1,C1,B1,D2,C2,B2,V,W)\n\nend subroutine z_poly_roots\n", "meta": {"hexsha": "9996a553a12a610daac57e0e5258f36cd5d73aac", "size": 4610, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/AMVW/src/complex_double/z_poly_roots.f90", "max_stars_repo_name": "trcameron/FPML", "max_stars_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/AMVW/src/complex_double/z_poly_roots.f90", "max_issues_repo_name": "trcameron/FPML", "max_issues_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/AMVW/src/complex_double/z_poly_roots.f90", "max_forks_repo_name": "trcameron/FPML", "max_forks_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.6047904192, "max_line_length": 94, "alphanum_fraction": 0.5657266811, "num_tokens": 1545, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898305367525, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.7700652379520092}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran77 Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n!\n!\n! ... file helmsph.f\n!\n! this file contains a program for solving the Helmholtz\n! equation with constant 1.0 on a ten degree grid on the full sphere\n!\n! ... required spherepack files\n!\n! islapec.f, shaec.f, shsec.f, sphcom.f, hrfft.f\n!\n! ... description\n!\n! let theta be latitude and phi be east longitude in radians.\n! and let\n!\n!\n! x = cos(theta)*sin(phi)\n! y = cos(theta)*cos(phi)\n! z = sint(theta)\n!\n! be the cartesian coordinates corresponding to theta and phi.\n! on the unit sphere. The exact solution\n!\n! ue(theta, phi) = (1.+x*y)*exp(z)\n!\n! is used to set the right hand side and compute error.\n!\n!\n! **********************************************************************\n!\n! OUTPUT FROM EXECUTING THE PROGRAM BELOW\n! WITH 32 AND 64 BIT FLOATING POINT ARITHMETIC\n!\n! Helmholtz approximation on a ten degree grid\n! nlat = 19 nlon = 36\n! xlmbda = 1.00 pertrb = 0.000E+00\n! maximum error = 0.715E-06 *** (32 BIT)\n! maximum error = 0.114E-12 *** (64 BIT)\n!\n! ***********************************************\n! ***********************************************\nprogram helmsph\nuse spherepack\n !\n ! set grid size with parameter statements\n !\n implicit none\n integer nnlat, nnlon, nn15, llsave, llwork, lldwork\n parameter (nnlat=19, nnlon=36)\n !\n ! set saved and unsaved workspace lengths in terms of nnlat, nnlon\n ! (see documentation for shaec, shsec, islapec)\n !\n parameter (nn15=nnlon+15)\n parameter (llsave=nnlat*(nnlat+1)+3*((nnlat-2)*(nnlat-1)+nn15))\n parameter (llwork=nnlat*(2*nnlon+3*(nnlat+1)+2*nnlat+1))\n !\n ! set real workspace length for initializations\n !\n parameter (lldwork = nnlat+1)\n !\n ! dimension arrays\n !\n real u(nnlat, nnlon), r(nnlat, nnlon)\n real sint(nnlat), cost(nnlat), sinp(nnlon), cosp(nnlon)\n real work(llwork), wshaec(llsave), wshsec(llsave)\n \n real a(nnlat, nnlat), b(nnlat, nnlat)\n integer nlat, nlon, i, j, lshaec, lshsec, lwork, ierror, isym, nt\n integer ldwork\n real x, y, z, dlat, dlon, theta, phi, xlmbda(1), pertrb(1), ez, ue, errm\n\n !\n ! set helmholtz constant\n !\n xlmbda = 1.0\n !\n ! set workspace length arguments\n !\n lwork = llwork\n ldwork = lldwork\n lshaec = llsave\n lshsec = llsave\n !\n ! set grid size arguments\n !\n nlat = nnlat\n nlon = nnlon\n !\n ! set sine and cosine vectors\n !\n dlat = pi/(nlat-1)\n dlon = (pi+pi)/nlon\n do i=1, nlat\n theta = -0.5*pi+(i-1)*dlat\n sint(i) = sin(theta)\n cost(i) = cos(theta)\n end do\n\n do j=1, nlon\n phi = (j-1)*dlon\n sinp(j) = sin(phi)\n cosp(j) = cos(phi)\n end do\n !\n ! set right hand side as helmholtz operator\n ! applied to ue = (1.+x*y)*exp(z)\n !\n do j=1, nlon\n do i=1, nlat\n x = cost(i)*cosp(j)\n y = cost(i)*sinp(j)\n z = sint(i)\n r(i, j) = -(x*y*(z*z+6.*(z+1.))+z*(z+2.))*exp(z)\n end do\n end do\n !\n ! initialize saved workspace arrays for scalar harmonic\n ! analysis and Helmholtz inversion of r\n !\n call shaeci(nlat, nlon, wshaec, ierror)\n if (ierror > 0) then\n write (6, 200) ierror\n200 format(' shaeci, ierror = ', i2)\n call exit(0)\n end if\n call shseci(nlat, nlon, wshsec, ierror)\n if (ierror > 0) then\n write (6, 201) ierror\n201 format(' shseci, ierror = ', i2)\n call exit(0)\n end if\n !\n ! set no symmetry and one array\n !\n isym = 0\n nt = 1\n !\n ! compute coefficients of r for input to islapec\n !\n call shaec(nlat, nlon, isym, nt, r, nlat, nlon, a, b, nlat, nlat, &\n wshaec, ierror)\n if (ierror > 0) then\n write (*, 202) ierror\n202 format(' shaec , ierror = ', i2)\n call exit(0)\n end if\n !\n ! solve Helmholtz equation on the sphere in u\n !\n write (6, 100) nlat, nlon\n100 format(' helmholtz approximation on a ten degree grid' &\n /' nlat = ', i3, 2x, ' nlon = ', i3)\n call islapec(nlat, nlon, isym, nt, xlmbda, u, nlat, nlon, a, b, nlat, nlat, &\n wshsec, pertrb, ierror)\n if (ierror /= 0) then\n write (6, 103) ierror\n103 format(' islapec, ierror = ', i2)\n if (ierror > 0) call exit(0)\n end if\n !\n ! compute and print maximum error in u\n !\n errm = 0.0\n do j=1, nlon\n do i=1, nlat\n x = cost(i)*cosp(j)\n y = cost(i)*sinp(j)\n z = sint(i)\n ez = exp(z)\n ue = (1.+x*y)*ez\n errm = max(errm, abs(u(i, j)-ue))\n end do\n end do\n write (*, 204) xlmbda, pertrb, errm\n204 format(' xlmbda = ', f5.2, 2x, ' pertrb = ' , e10.3, &\n /' maximum error = ', e10.3)\nend program helmsph\n", "meta": {"hexsha": "c0d72031430779db6f1c508245759ceadab8d60f", "size": 6942, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/helmsph.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "test/helmsph.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "test/helmsph.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 32.9004739336, "max_line_length": 81, "alphanum_fraction": 0.4144338807, "num_tokens": 1930, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436153333645, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.7700004047742327}} {"text": "module m\r\nimplicit none\r\ncontains\r\npure function twice(vec) result(vec2)\r\n! result size depends on argument size\r\ninteger, intent(in) :: vec(:)\r\ninteger :: vec2(size(vec))\r\nvec2 = 2*vec\r\nend function twice \r\n!\r\npure function fibonacci(n) result(vec)\r\n! result size is an argument\r\ninteger, intent(in) :: n\r\ninteger :: vec(n)\r\ninteger :: i\r\nif (n < 1) return\r\nvec(1) = 0\r\nif (n < 2) return\r\nvec(2) = 1\r\ndo i=3,n\r\n vec(i) = vec(i-1) + vec(i-2)\r\nend do\r\nend function fibonacci\r\n!\r\npure function even(vec) result(even_num)\r\n! If the size of the function RESULT depends on the input\r\n! in a more complicated way, it can be an allocatable array \r\n! return the even elements in vec(:)\r\ninteger, intent(in) :: vec(:)\r\ninteger, allocatable :: even_num(:)\r\neven_num = pack(vec, mod(vec,2)==0) ! allocation on assignment\r\nend function even\r\nend module m\r\n!\r\nprogram array_func\r\nuse m, only: twice, fibonacci, even\r\nimplicit none\r\ncharacter (len=*), parameter :: fmt=\"(*(i0,:,1x))\"\r\nprint fmt,twice([1,4]) ! 2 8\r\nprint fmt,fibonacci(6) ! 0 1 1 2 3 5\r\nprint fmt,even([1,4,9,16]) ! 4 16\r\nend program array_func\r\n", "meta": {"hexsha": "e4f2f26d1475e3000a9b21d07b1cf454bec7cdcf", "size": 1137, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "array_func.f90", "max_stars_repo_name": "awvwgk/FortranTip", "max_stars_repo_head_hexsha": "3810038667e3d5d2ab33c39d4bd0f41870025420", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "array_func.f90", "max_issues_repo_name": "awvwgk/FortranTip", "max_issues_repo_head_hexsha": "3810038667e3d5d2ab33c39d4bd0f41870025420", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "array_func.f90", "max_forks_repo_name": "awvwgk/FortranTip", "max_forks_repo_head_hexsha": "3810038667e3d5d2ab33c39d4bd0f41870025420", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.4418604651, "max_line_length": 63, "alphanum_fraction": 0.6490765172, "num_tokens": 343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.7699821711782666}} {"text": "! Las variables de tipo real son aquellas que almacenan numeros de punto flotante, como 0.2, 1222.22222, -123.45\n! Anteriormente sólo habían dos tipos de números reales: el tipo por defecto y el tipo de doble precisión\n\n! Las versiones más modernas de Fortran (90/95) nos permiten tener mayor control sobre la precisión de\n! datos de tipo real e integer mediante el especificador kind.\n\nprogram tipos_reales\n! Declaración de variables\nreal :: var_real\nreal(kind=4) :: real_4bytes\nreal(kind=8) :: real_8bytes\nreal(kind=16) :: real_16bytes\n\ninteger :: int\ninteger(kind=2) :: int_2bytes\ninteger(kind=4) :: int_4bytes\ninteger(kind=8) :: int_8bytes\ninteger(kind=16) :: int_16bytes\n\nvar_real = 12.5\n\n!En la programación científica, uno usualmente necesita saber el rango y precisión de los datos\n!del hardware en el que se está trabajando.\n\n!La función intrinseca kind() nos permite consultar los detalles de la representación de datos del hardware\n!en el que se está trabajando.\n\nprint *, \"¿Cuántos bytes puede almacenar una variable de tipo real por defecto?: \", kind(var_real)\nprint *, \"Hasta qué número positivo llega?: \", huge(var_real)\n\nprint *, \"¿Cuántos bytes almacena real_4bytes?: \", kind(real_4bytes)\nprint *, \"Hasta qué número positivo llega?: \", huge(real_4bytes)\n\nprint *, \"¿Cuántos bytes almacena real_8bytes?: \", kind(real_8bytes)\nprint *, \"Hasta qué número positivo llega?: \", huge(real_8bytes)\n\nprint *, \"¿Cuántos bytes almacena real_16bytes?: \", kind(real_16bytes)\nprint *, \"Hasta qué número positivo llega?: \", huge(real_16bytes)\n\n\n\nprint *, \"¿Cuántos bytes almacena int?: \", kind(int)\nprint *, \"Hasta qué número positivo llega?: \", huge(int)\n\nprint *, \"¿Cuántos bytes almacena int_2bytes?: \", kind(int_2bytes)\nprint *, \"Hasta qué número positivo llega?: \", huge(int_2bytes)\n\nprint *, \"¿Cuántos bytes almacena int_4bytes?: \", kind(int_4bytes)\nprint *, \"Hasta qué número positivo llega?: \", huge(int_4bytes)\n\nprint *, \"¿Cuántos bytes almacena int_8bytes?: \", kind(int_8bytes)\nprint *, \"Hasta qué número positivo llega?: \", huge(int_8bytes)\n\nprint *, \"¿Cuántos bytes almacena int_16bytes?: \", kind(int_16bytes)\nprint *, \"Hasta qué número positivo llega?: \", huge(int_16bytes)\n!El tipo real cumple con todas las operaciones posibles en el conjunto de los números reales.\n\n\nend program tipos_reales\n\n", "meta": {"hexsha": "031760747dfea0fbafa9dc29a28da8334405633d", "size": 2311, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Constantes, variables y tipos de datos/tipos_reales.f90", "max_stars_repo_name": "kotoromo/Fortran-Basico", "max_stars_repo_head_hexsha": "1d37a82754acd1c231981adc3dea2d606e76d6c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Constantes, variables y tipos de datos/tipos_reales.f90", "max_issues_repo_name": "kotoromo/Fortran-Basico", "max_issues_repo_head_hexsha": "1d37a82754acd1c231981adc3dea2d606e76d6c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Constantes, variables y tipos de datos/tipos_reales.f90", "max_forks_repo_name": "kotoromo/Fortran-Basico", "max_forks_repo_head_hexsha": "1d37a82754acd1c231981adc3dea2d606e76d6c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.8852459016, "max_line_length": 112, "alphanum_fraction": 0.7464301168, "num_tokens": 677, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059267, "lm_q2_score": 0.879146761176671, "lm_q1q2_score": 0.7699452943377412}} {"text": "module mandelbrot\n\nuse, intrinsic :: iso_fortran_env, only : dp=>real64,i64=>int64, stderr=>error_unit\nuse perf, only: sysclock2ms\nImplicit None\ninteger, parameter :: wp=dp\n\ncontains\n\nelemental integer function mandel(z0) result(r)\n\ncomplex(wp), intent(in) :: z0\ncomplex(wp) :: c, z\ninteger :: n\ninteger, parameter :: maxiter = 80\n\nz = z0\nc = z0\n\ndo n = 1, maxiter\n if (abs(z) > 2) then\n r = n-1\n return\n end if\n z = z**2 + c\nend do\n\nr = maxiter\n\nend function mandel\n\n\npure integer function mandelperf() result(mandel_sum)\n\ninteger :: re, im, img, Nimg,msum\n!integer :: msum[*] = 0\n\nmandel_sum = 0\nmsum=0 ! must have this line!\n\n! img = this_image()\n! Nimg = num_images()\nNimg=1\nimg=1\n\ndo re=img-21, 5, Nimg !re=-20,5\n do im = -10,10\n msum = msum + mandel(cmplx(re/10.0_wp, im/10.0_wp, wp))\n end do\nend do\n\n! call co_sum(msum)\n\nmandel_sum = msum\n\nend function mandelperf\n\n\nReal(dp) function mandeltest(N,Nrun) result(t)\ninteger, intent(in) :: N,Nrun\ninteger(i64) :: tic,toc,tmin\ninteger :: i,k,f\nf = 0\ntmin = huge(0_i64)\n\ndo i = 1, Nrun\n call system_clock(tic)\n do k = 1, N\n f = mandelperf()\n end do\n call system_clock(toc)\n if (toc-tic < tmin) tmin = toc-tic\nend do\n\nif (f /= 14791) error stop 'mandelbrot: unexpected final value'\n\nt = sysclock2ms(tmin) / 1000\n\nend function mandeltest\n\nend module mandelbrot\n\n\nprogram m\n\nuse mandelbrot, only: mandeltest, dp\nimplicit none\n\ninteger :: N=1000, Nrun=10, argc, Ni\ncharacter(16) :: argv\n\nreal(dp) :: t\n\n! Ni = num_images()\nNi=1\n\nargc = command_argument_count()\nif (argc>0) then\n call get_command_argument(1,argv)\n read(argv,*) N\nendif\n\nif (argc>1) then\n call get_command_argument(2,argv)\n read(argv,*) Nrun\nendif\n\nt = mandeltest(N,Nrun)\n\nprint '(A,ES12.4,A)', 'Mandelbrot:',t,' sec.'\n\n\nend program\n", "meta": {"hexsha": "43531100bc3995defb018f8672039dec802c80b8", "size": 1777, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mandelbrot/mandel.f90", "max_stars_repo_name": "scienceopen/numba-examples", "max_stars_repo_head_hexsha": "1331ac4ef4a723d3d8353cd3ce90c9bf127fe547", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2017-03-10T07:41:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-17T16:35:46.000Z", "max_issues_repo_path": "mandelbrot/mandel.f90", "max_issues_repo_name": "scienceopen/numba-examples", "max_issues_repo_head_hexsha": "1331ac4ef4a723d3d8353cd3ce90c9bf127fe547", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-03-22T22:04:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-22T22:04:51.000Z", "max_forks_repo_path": "mandelbrot/mandel.f90", "max_forks_repo_name": "scienceopen/numba-examples", "max_forks_repo_head_hexsha": "1331ac4ef4a723d3d8353cd3ce90c9bf127fe547", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-10-16T04:37:17.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-08T12:35:54.000Z", "avg_line_length": 15.5877192982, "max_line_length": 83, "alphanum_fraction": 0.6696679797, "num_tokens": 646, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037384317887, "lm_q2_score": 0.8311430457670241, "lm_q1q2_score": 0.7698909104655777}} {"text": "program prog01\nimplicit none\n\ndouble precision :: pi, r, area, volume\ncharacter (len = 1) :: c\n\npi = 3.14\n\nwrite(*,*) \"O que vc deseja calcular? Digite (a) para calcular a área e (v) para calcular o volume\"\nread(*,*)c\n\nif (c .eq. \"a\") then\n write(*,*)\"Digite o valor do raio da circunferencia\"\n read(*,*)r\n area = pi*(r**2)\n write(*,*)\"A área da circunferência é\",area\nelse if (c .eq. \"v\") then\n write(*,*)\"Digite o valor do raio da esfera\"\n read(*,*)r\n volume = (4d0/3d0)*pi*r**3\n write(*,*)\"O volume da esfera é\",volume\nelse\n write(*,*) \"Você não digitou um caractér válido\"\nend if\n\nend program prog01\n", "meta": {"hexsha": "b26cb1410689bf4d3966fa766431fddd0c7cfd15", "size": 631, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "aula03/prog1.f90", "max_stars_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_stars_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aula03/prog1.f90", "max_issues_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_issues_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aula03/prog1.f90", "max_forks_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_forks_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.3703703704, "max_line_length": 99, "alphanum_fraction": 0.6228209192, "num_tokens": 223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480346, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.7698033507173918}} {"text": "************************************************************************\n! Collections of Subroutines related to Table operations\n!\n! Author: Zhi Qiu (qiu@mps.ohio-state.edu)\n! -- For changes, see ChangeLogsInputFun.txt\n************************************************************************\n\n************************************************************************\n Subroutine interpCubic(table,tableSize,var0,dVar,varX,varResult)\n! Purpose:\n! Return the interpolated value at varX from table, using cubic polynomial interpolation.\n! -- table: 1d array, stores values corresponding to var0+index*dVar\n! -- tableSize: size of the talbe\n! -- var0: start of the independent variable\n! -- dVar: step of the independent variable\n! -- varX: the value of the varibale to be interpolated at\n! -- varResult: the return interpolated value\n\n Implicit None\n\n! declare input parameters\n Integer tableSize\n Double Precision table(0:tableSize-1)\n Double Precision var0, dVar, varX, varResult\n\n! declare local variables\n Integer idx ! varX is between var0+idx*dVar and var0+(idx+1)*dVar\n Double Precision A0,A1,A2,A3,varD ! varD=delta-var\n\n If ((varX-var0)tableSize-1) Then\n Print *, \"Subroutine interpCubic: varX out of bounds\"\n Print *, \"varX=\",varX,\"var0=\",var0,\"dVar=\",dVar,\"idx=\",idx\n call exit(1)\n End If\n\n If (idx==0) Then ! use quadratic interpolation\n A0 = table(0)\n A1 = table(1)\n A2 = table(2)\n varD = varX - var0\n varResult =\n & (A0-2*A1+A2)/(2*dVar*dVar)*varD*varD\n & - (3*A0-4*A1+A2)/(2*dVar)*varD\n & + A0\n Return\n Else If (idx==tableSize-2) Then ! use quadratic interpolation\n A0 = table(tableSize-3)\n A1 = table(tableSize-2)\n A2 = table(tableSize-1)\n varD = varX - (var0 + (idx-1)*dVar)\n varResult =\n & (A0-2*A1+A2)/(2*dVar*dVar)*varD*varD\n & - (3*A0-4*A1+A2)/(2*dVar)*varD\n & + A0\n Return\n Else ! use cubic interpolation\n A0 = table(idx-1)\n A1 = table(idx)\n A2 = table(idx+1)\n A3 = table(idx+2)\n varD = varX - (var0 + idx*dVar)\n varResult =\n & (-A0+3*A1-3*A2+A3)/(6*dVar*dVar*dVar)*varD*varD*varD\n & + (A0-2*A1+A2)/(2*dVar*dVar)*varD*varD\n & - (2*A0+3*A1-6*A2+A3)/(6*dVar)*varD\n & + A1\n Return\n End If\n\n End Subroutine\n!-----------------------------------------------------------------------\n\n\n\n\n************************************************************************\n Subroutine interpLinear(table,tableSize,var0,dVar,varX,varResult)\n! Purpose:\n! Return the interpolated value at varX from table, using linear interpolation.\n! -- table: 1d array, stores values corresponding to var0+index*dVar\n! -- tableSize: size of the talbe\n! -- var0: start of the independent variable\n! -- dVar: step of the independent variable\n! -- varX: the value of the varibale to be interpolated at\n! -- varResult: the return interpolated value\n\n Implicit None\n\n! declare input parameters\n Integer tableSize\n Double Precision table(0:tableSize-1)\n Double Precision var0, dVar, varX, varResult\n\n! declare local variables\n Integer idx ! varX is between var0+idx*dVar and var0+(idx+1)*dVar\n Double Precision varD ! varD=delta-var\n\n If ((varX-var0)tableSize-1) Then\n Print *, \"Subroutine interpLinear: varX out of bounds\"\n Print *, \"varX=\",varX,\"var0=\",var0,\"dVar=\",dVar,\"idx=\",idx\n call exit(1)\n End If\n\n varD = varX - (var0 + idx*dVar)\n varResult = (table(idx)*(dVar-varD) + table(idx+1)*varD)/dVar\n\n End Subroutine\n!-----------------------------------------------------------------------\n\n\n************************************************************************\n Subroutine invertFunction_binary(\n & func,varL,varR,absacc,relacc,varY,varResult)\n! Purpose:\n! Return the varResult=func^-1(varY) using binary search when either\n! absolute error or relative error is reached\n! -- func: double precision 1-argument function to be inverted\n! -- varL: left boundary\n! -- varR: right boundary\n! -- absacc: absolute error\n! -- relacc: relative error\n! -- varY: the value of the variable to be inverted\n! -- varResult: the return inverted value\n!\n! Solve: f(x)=0 with f(x)=table(x)-varY => f'(x)=table'(x)\n!\n Implicit None\n\n! declare input parameters\n Double Precision func\n Double Precision varL, varR, varM, absacc, relacc\n Double Precision xL, xR\n Double Precision yL, yR, yM\n double precision varY, varResult\n\n! pre-fixed parameters\n Integer tolerance, itol\n\n! initialize parameters\n varM = (varR + varL)/2.\n xL = varL\n xR = varR\n tolerance = 60\n\n yL = func(xL)\n yR = func(xR)\n if(abs(yL - varY) < 1d-15) then\n varResult = varL\n return\n endif\n if(abs(yR - varY) < 1d-15) then\n varResult = varR\n return\n endif\n\n if((yL - varY)*(yR - varY) .gt. 0) then\n Print*, \"Error: Invertfunction_binary: no unique solution!\"\n Print*, \"yL = \", yL, \", yR = \", yR\n Print*, \"varL = \", varL, \", varR = \", varR, \", varY = \", varY\n call exit(1)\n endif\n\n itol = 0\n Do While ((abs(xR - xL) > absacc .and.\n & abs(xR - xL)/((xR + xL)/2.) > relacc)\n & .and. itol < tolerance)\n yM = func(varM)\n if((yL - varY)*(yM - varY) .lt. 0) then\n xR = varM\n yR = yM\n else\n xL = varM\n yL = yM\n endif\n varM = (xL + xR)/2.\n itol = itol + 1\n enddo\n\n varResult = varM\n End Subroutine\n!-----------------------------------------------------------------------\n\n************************************************************************\n Subroutine invertFunctionD(func,varL,varR,acc,varI,varX,varResult)\n! Purpose:\n! Return the varResult=func^-1(varX) using Newton method.\n! -- func: double precision 1-argument function to be inverted\n! -- varL: left boundary (for numeric derivative)\n! -- varR: right boundary (for numeric derivative)\n! -- dd: step (for numeric derivative)\n! -- varI: initial value\n! -- varX: the value of the varibale to be inverted\n! -- varResult: the return inverted value\n!\n! Solve: f(x)=0 with f(x)=table(x)-varX => f'(x)=table'(x)\n!\n Implicit None\n\n! declare input parameters\n Double Precision func\n Double Precision varL, varR, acc, varI, varX, varResult\n Double precision dd\n\n! pre-fixed parameters\n Double Precision accuracy\n Integer tolerance\n\n! declare local variables\n Double Precision XX1, XX2 ! used in iterations\n Double Precision F0, F1, F2, F3, X1, X2 ! intermediate variables\n Integer impatience ! number of iterations\n\n! initialize parameters\n accuracy = acc\n dd = DMAX1(1D-6,1D-3*abs(varR - varL))\n\n tolerance = 60\n impatience = 0\n\n! initial value, left point and middle point\n XX2 = varI\n XX1 = XX2-10*accuracy ! this value 10*accuracy is meanless, just to make sure the check in the while statement goes through\n\n Do While (abs(XX2-XX1)>accuracy)\n XX1 = XX2 ! copy values\n\n! value of function at XX!\n F0 = func(XX1) - varX ! the value of the function at this point\n\n! decide X1 and X2 for differentiation\n If (XX1>varL+dd) Then\n X1 = XX1 - dd\n Else\n X1 = varL\n End If\n\n If (XX1tolerance) Then\n Print *, \"Subroutine invertFunctionD: \",\n & \"max number of iterations reached!\"\n call exit(1)\n !Print*, XX1, XX2\n End If\n dd = abs(XX2 - XX1)*0.05\n End Do ! <=> abs(XX2-XX1)>accuracy\n\n if(XX2 .lt. varL) then\n varResult = varL\n else if(XX2 .gt. varR) then\n varResult = varR\n else\n varResult = XX2\n endif\n\n End Subroutine\n!-----------------------------------------------------------------------\n\n\n\n************************************************************************\n Subroutine invertFunctionH(func,varL,varR,yy,acc,varResult)\n! Newton/Bisect hybrid root search algorithm.\n! Adapted from W.Press et.al. Numerical Recipies in C.\n! Purpose:\n! Return the varResult=func^-1(varX) using Newton method and Bisection.\n!\n! -- func: double precision 1-argument function to be inverted\n! -- varL: left boundary (for numeric derivative)\n! -- varR: right boundary (for numeric derivative)\n! -- varResult: the return inverted value\n!\n! Solve: f(x)=yy with f(x)=table(x)-varX => f'(x)=table'(x)\n!\n Implicit None\n\n! declare input parameters\n Double Precision func\n Double Precision varL, varR, acc, varResult, yy\n Double Precision dd ! step size of numerical derivative\n\n! pre-fixed parameters\n Double Precision accuracy\n Integer tolerance\n\n! declare local variables\n Double Precision df, dx, dxold, f, fh, fl\n Double Precision temp, xh, xl, rts ! intermedia variables\n Integer impatience ! number of iterations\n Double Precision numericalZero\n\n! initialize parameters\n accuracy = acc\n tolerance = 60\n impatience = 0\n numericalZero = 1D-18\n dd = DMAX1(1D-6,1D-3*abs(varR - varL))\n\n! initial value, left and right point\n fl = func(varL) - yy\n fh = func(varR) - yy\n if(fl*fh>0) then\n print*, \"invertFunctionH error!\"\n print*, \"No solution at given boundary!\"\n call exit(1)\n EndIf\n\n! Check initial value is solution\n if(abs(fl) abs(dxold*df))) then\n dxold = dx\n dx = 0.5*(xh-xl)\n rts= xl+dx\n if(abs(xl-rts)maxRecursionDepth) Then\n Print*, \"Warning: maximum recursion depth reached!\"\n Exit\n EndIf\n currentRecursionDepth = currentRecursionDepth+1\n If (abs(sum_current-sum_previous) np) then\n polynom=0.d0\n return\n end if\n x1=xa(1)\n ! find the polynomial coefficients in divided differences form\n c(:)=ya(:)\n do i=2,np\n do j=np,i,-1\n c(j)=(c(j)-c(j-1))/(xa(j)-xa(j+1-i))\n end do\n end do\n ! special case m=0\n if (m.eq.0) then\n sum=c(1)\n t1=1.d0\n do i=2,np\n t1=t1*(x-xa(i-1))\n sum=sum+c(i)*t1\n end do\n polynom=sum\n return\n end if\n ! convert to standard form\n do j=1,np-1\n do i=1,np-j\n c(np-i)=c(np-i)-(xa(np-i-j+1)-x1)*c(np-i+1)\n end do\n end do\n if (m.gt.0) then\n ! take the m'th derivative\n do j=1,m\n do i=m+1,np\n c(i)=c(i)*dble(i-j)\n end do\n end do\n t1=c(np)\n do i=np-1,m+1,-1\n t1=t1*(x-x1)+c(i)\n end do\n polynom=t1\n else\n ! find the integral\n t1=c(np)/dble(np)\n do i=np-1,1,-1\n t1=t1*(x-x1)+c(i)/dble(i)\n end do\n polynom=t1*(x-x1)\n end if\n return\nend function polynom\n\nsubroutine derv(ucpl,ucl,rr,npt,np)\n REAL*8, intent(out):: ucpl(npt)\n REAL*8, intent(in) :: ucl(npt), rr(npt)\n INTEGER, intent(in):: npt\n INTEGER, intent(in):: np ! default np=4\n !f2py integer optional, intent(in) :: np=4\n real(8), external :: polynom\n ! locals\n INTEGER :: ir, ir0\n INTEGER :: np_2\n REAL*8 :: c(np)\n np_2 = np/2\n ucpl(1)=0.0d0\n do ir=2,npt\n if(ir <= np_2) then\n ir0 = 1\n elseif(ir > npt-np_2)then\n ir0 = npt-np+1\n else\n ir0 = ir-np_2\n endif\n ucpl(ir) = polynom(1,np,rr(ir0),ucl(ir0),c,rr(ir))\n enddo\nend subroutine derv\n\n", "meta": {"hexsha": "414132c3c3bd2b5706513adb42a3e5deea3f72e8", "size": 2169, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "radd.f90", "max_stars_repo_name": "kunyuan/PyGW", "max_stars_repo_head_hexsha": "7b32065586f7d7cc221d051b5254397fdf0a3076", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-07-06T01:56:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-13T13:07:06.000Z", "max_issues_repo_path": "radd.f90", "max_issues_repo_name": "kunyuan/PyGW", "max_issues_repo_head_hexsha": "7b32065586f7d7cc221d051b5254397fdf0a3076", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "radd.f90", "max_forks_repo_name": "kunyuan/PyGW", "max_forks_repo_head_hexsha": "7b32065586f7d7cc221d051b5254397fdf0a3076", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-06T01:56:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-06T01:56:59.000Z", "avg_line_length": 22.8315789474, "max_line_length": 80, "alphanum_fraction": 0.5435684647, "num_tokens": 842, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966686936261, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.7694574951549701}} {"text": "program test_choose\n \n implicit none\n \n write (*, '(i0)') choose (5, 3)\n \ncontains\n \n function factorial (n) result (res)\n \n implicit none\n integer, intent (in) :: n\n integer :: res\n integer :: i\n \n res = product ((/(i, i = 1, n)/))\n \n end function factorial\n \n function choose (n, k) result (res)\n \n implicit none\n integer, intent (in) :: n\n integer, intent (in) :: k\n integer :: res\n \n res = factorial (n) / (factorial (k) * factorial (n - k))\n \n end function choose\n \nend program test_choose\n", "meta": {"hexsha": "5a8316791d813e3a5c8700be730b915bc28a9fa1", "size": 531, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "languages/fortran/test_choose.f90", "max_stars_repo_name": "octonion/examples", "max_stars_repo_head_hexsha": "5d142697b9f781e37c61f32217fdb6d661902d42", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-12-14T04:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-31T07:12:13.000Z", "max_issues_repo_path": "languages/fortran/test_choose.f90", "max_issues_repo_name": "octonion/examples", "max_issues_repo_head_hexsha": "5d142697b9f781e37c61f32217fdb6d661902d42", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "languages/fortran/test_choose.f90", "max_forks_repo_name": "octonion/examples", "max_forks_repo_head_hexsha": "5d142697b9f781e37c61f32217fdb6d661902d42", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.59375, "max_line_length": 61, "alphanum_fraction": 0.5856873823, "num_tokens": 158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.7693715182324167}} {"text": "use FEMSolverClass\nimplicit none\n\nreal(real64),allocatable :: K(:,:), M(:,:),eigen_vector(:),eigen_value(:),&\nx(:,:),eigen_vectors(:,:),lambda_mins(:),sample_mat(:,:),lambda(:),K_sp_val(:),&\nbvec(:),new_vector(:),new_matrix(:,:)\nreal(real64)::lambda_min\ninteger(int32),allocatable :: K_sp_col(:),K_sp_rowptr(:)\ninteger(int32) :: i\ntype(FEMSolver_) :: FEMSolver\ntype(Random_) :: random\n\nK = zeros(5,5)\nM = eye(5,5)\n\nK(1,:) = [2.0d0, 2.0d0, 0.0d0,0.0d0,0.0d0]\nK(2,:) = [2.0d0, 4.0d0, 2.0d0,0.0d0,0.0d0]\nK(3,:) = [0.0d0, 2.0d0, 4.0d0,2.0d0,0.0d0]\nK(4,:) = [0.0d0, 0.0d0, 2.0d0,4.0d0,2.0d0]\nK(5,:) = [0.0d0, 0.0d0, 0.0d0,2.0d0,1.0d0]\n\ncall to_CRS(K,K_sp_val,K_sp_col,K_sp_rowptr)\n\n\nlambda_mins = zeros(1)\neigen_vectors = LOBPCG_sparse(K_sp_val,K_sp_col,K_sp_rowptr,lambda_mins)\n\n!eigen_vector = LOBPCG_dense_single(K,M,lambda_min)\n\nprint *, \"eigen_value\",lambda_mins\n\nprint *, \"eigen_vector\"\ncall print(eigen_vectors)\n\n!> Ans.\n! eigen_value -0.35521847100475296 \n!eigen_vector\n!-0.22020298528984170 \n! 0.25931306916251190 \n!-0.34447954900490979 \n! 0.49082877819227444 \n!-0.72435373143693627 \n\n!> Ans@ Scipy\n! [-0.35521838 0.47871512 2.549596 5.122324 7.2045794 ]\n\n! [[ 0.22020283 0.6878815 -0.537812 -0.38525033 0.20166838]\n! [-0.25931296 -0.5232321 -0.1477898 -0.6014385 0.52479976]\n! [ 0.3444794 0.23334298 0.64498943 0.0477451 0.6392136 ]\n! [-0.49082875 0.11239842 -0.3199573 0.6282312 0.49940613]\n! [ 0.72435385 -0.43123636 -0.4129556 0.3047946 0.16097984]]\n\n!Theoretical solution:\\lambda_1 = −0.35521847100475...\n! plantFEM solution: \\lambda_1 = -0.35521847100475296\n! scipy solution: \\lambda_1 = -0.35521838\n\nend\n", "meta": {"hexsha": "bbf392fadae8df5aedfdddac51f1acfcc2401918", "size": 1680, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/fem/LOBPCG_sparse_example.f90", "max_stars_repo_name": "kazulagi/plantFEM_binary", "max_stars_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-10T11:49:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T11:49:34.000Z", "max_issues_repo_path": "Tutorial/fem/LOBPCG_sparse_example.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorial/fem/LOBPCG_sparse_example.f90", "max_forks_repo_name": "kazulagi/plantFEM_binary", "max_forks_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.9655172414, "max_line_length": 80, "alphanum_fraction": 0.6702380952, "num_tokens": 777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543454, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7693715135996645}} {"text": "program main\n\n use iso_fortran_env , only : dp => REAL64\n use matrix_utils , only : toepliz, print\n use direct_linear_solve , only : mgs_qrfactor, cgs_qrfactor, &\n & householder, banded_householder, householder_factorization\n use direct_linear_solve , only : givens_factorization, givens, qriteration\n use linear_algebra , only : eigvals, svdvals\n \n implicit none\n\n real(dp), parameter :: lambda = 2.0d0 \n integer , parameter :: npts = 5\n real(8) , allocatable, dimension(:,:) :: A, Q, R, D, U\n\n integer :: i\n real(dp) :: h\n\n allocate(A(npts,npts))\n allocate(Q(npts,npts))\n allocate(R(npts,npts))\n allocate(D(npts,npts))\n allocate(U(npts,npts))\n\n call assemble_matrix(0.0d0, 1.0d0, npts, lambda, A)\n call qriteration(A, R, Q, 100, 1.0d-3)\n\n stop\n \n print *, 'Performing Givens Transformation'\n Q = 0\n R = 0\n call givens_factorization(A, Q, R)\n print *, 'matrix'\n call print(A)\n\n print *, 'Q'\n call print(Q)\n \n print *, 'R'\n call print(R)\n\n ! Check similarity with A\n print *, 'consistency A' \n D = matmul(Q, R)\n print *, norm2(A - D)\n\n ! Check Orthogonality\n D = matmul(Q,transpose(Q))\n print *, 'orthogonality Q'\n do i = 1, npts \n D(i,i) = 1.0d0 - D(i,i)\n end do\n print *, norm2(D)\n\n deallocate(A,Q,R,D)\n\ncontains\n \n ! Model problem to solve\n subroutine assemble_matrix(a, b, npts, lambda, V)\n\n real(8), intent(in) :: a, b ! bound of domain\n integer :: npts ! number of points\n real(8), intent(out) :: V(npts,npts)\n real(8), intent(in) :: lambda\n real(8), parameter :: PI = 3.141592653589793d0\n integer :: m, n, i, j\n\n h = (b-a)/dble(npts+1)\n V = 0.0d0\n\n m = npts\n n = npts\n do i = 1, m\n do j = 1, n\n if (i .eq. j-1) then\n V(i,j) = -1.0d0\n else if (i .eq. j+1) then \n V(i,j) = -1.0d0\n else if (i .eq. j) then \n V(i,i) = 2.0d0 + lambda*h*h\n else\n ! skip zeros\n end if\n end do\n end do\n\n end subroutine assemble_matrix\n\nend program main\n", "meta": {"hexsha": "9da857fcbceb3556652bdd83595a0be4fd2791c4", "size": 2107, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/eigen/test.f90", "max_stars_repo_name": "komahanb/math6644-iterative-methods", "max_stars_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-03-19T16:36:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-14T21:29:38.000Z", "max_issues_repo_path": "test/eigen/test.f90", "max_issues_repo_name": "komahanb/math6644-iterative-methods", "max_issues_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/eigen/test.f90", "max_forks_repo_name": "komahanb/math6644-iterative-methods", "max_forks_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-23T02:14:36.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-23T02:14:36.000Z", "avg_line_length": 22.902173913, "max_line_length": 76, "alphanum_fraction": 0.5647840532, "num_tokens": 720, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480668, "lm_q2_score": 0.8479677526147222, "lm_q1q2_score": 0.7693715010165528}} {"text": "module stress_routines\n\t! module containing various routines for computation of stresses and stress invariants\n\n\t! load additional modules\n\tuse constants\n\tuse math_routines, only: calc_rot_matrix_zyz\n\n\timplicit none\n\n\n\t! definition and initialization of constant arrays\n\n\t! deviatoric operator\n\treal(kind=dbl), dimension(6,6), parameter :: I_dev = &\n\t\t\t reshape( (/ 2._dbl/3._dbl, -1._dbl/3._dbl, -1._dbl/3._dbl, 0._dbl, 0._dbl, 0._dbl, &\n\t\t\t\t\t\t-1._dbl/3._dbl, 2._dbl/3._dbl, -1._dbl/3._dbl, 0._dbl, 0._dbl, 0._dbl, &\n\t\t\t\t\t\t-1._dbl/3._dbl, -1._dbl/3._dbl, 2._dbl/3._dbl, 0._dbl, 0._dbl, 0._dbl, &\n\t\t\t\t\t\t0._dbl, 0._dbl, 0._dbl, 1._dbl, 0._dbl, 0._dbl, &\n\t\t\t\t\t\t0._dbl, 0._dbl, 0._dbl, 0._dbl, 1._dbl, 0._dbl, &\n\t\t\t\t\t\t0._dbl, 0._dbl, 0._dbl, 0._dbl, 0._dbl, 1._dbl /), (/ 6, 6 /) )\n\n\t! dsigma_m/dsigma\n\treal(kind=dbl), dimension(6), parameter :: Dsigma_mDsigma = (/ 1._dbl/3._dbl, 1._dbl/3._dbl, 1._dbl/3._dbl, &\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t 0._dbl, 0._dbl, 0._dbl /)\n\n\t! numerical zero\n\treal(kind=dbl), parameter :: num_zero = 1.0d-10\n\n\treal(kind=dbl), dimension(6), parameter :: eps_eng_scale = (/ 1._dbl, 1._dbl, 1._dbl, 0.5_dbl, 0.5_dbl, 0.5_dbl /)\t! scaling vector for strain vector to convert engineering shear strain components\n\ncontains\n\n\n\tfunction calc_I1(sigma)\n\t\timplicit none\n\t\t! computes first invariant of stress tensor\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl) :: calc_I1\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of first invariant\n\t\tcalc_I1 = sum(sigma(1:3))\n\n\tend function calc_I1\n\n\n\n\n\tfunction calc_I2(sigma)\n\t\timplicit none\n\t\t! computes second invariant of stress tensor\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl) :: calc_I2\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: s11\n\t\treal(kind=dbl) :: s22\n\t\treal(kind=dbl) :: s33\n\t\treal(kind=dbl) :: s12\n\t\treal(kind=dbl) :: s13\n\t\treal(kind=dbl) :: s23\n\t\t! --------------------------------------------------------------------------\n\n\t\t! unpacking of stress vector\n\t\ts11 = sigma(1)\n\t\ts22 = sigma(2)\n\t\ts33 = sigma(3)\n\t\ts12 = sigma(4)\n\t\ts13 = sigma(5)\n\t\ts23 = sigma(6)\n\n\t\t! compuation of second invariant\n\t\tcalc_I2 = s11*s22 + s22*s33 + s11*s33 - s12**2 - s13**2 - s23**2\n\n\tend function calc_I2\n\n\n\n\n\tfunction calc_I3(sigma)\n\t\timplicit none\n\t\t! computes third invariant of stress tensor\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl) :: calc_I3\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: s11\n\t\treal(kind=dbl) :: s22\n\t\treal(kind=dbl) :: s33\n\t\treal(kind=dbl) :: s12\n\t\treal(kind=dbl) :: s13\n\t\treal(kind=dbl) :: s23\n\t\t! --------------------------------------------------------------------------\n\n\t\t! unpacking of stress vector\n\t\ts11 = sigma(1)\n\t\ts22 = sigma(2)\n\t\ts33 = sigma(3)\n\t\ts12 = sigma(4)\n\t\ts13 = sigma(5)\n\t\ts23 = sigma(6)\n\n\t\t! compuation of second invariant\n\t\tcalc_I3 = s11*s22*s33 + 2._dbl*s12*s23*s13 - s12**2*s33 - s23**2*s11 - s13**2*s22\n\n\tend function calc_I3\n\n\n\n\n\tfunction calc_s_mean(sigma)\n\t\timplicit none\n\t\t! computes mean stress\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl) :: calc_s_mean\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of mean stress\n\t\tcalc_s_mean = 1._dbl/3._dbl * sum( sigma(1:3) )\n\n\tend function calc_s_mean\n\n\n\n\n\tfunction calc_s_dev(sigma)\n\t\timplicit none\n\t\t! computes deviatoric stress vector\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), dimension(6) :: calc_s_dev\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n\n\t\t! internal variable\n\t\treal(kind=dbl) :: s_mean\t\t\t\t\t\t\t\t! mean stress\n\t\t! --------------------------------------------------------------------------\n\n\t\t! compuation of s_mean\n\t\ts_mean = calc_s_mean(sigma)\n\n\t\t! computation of s_dev\n\t\tcalc_s_dev = sigma - (/ s_mean, s_mean, s_mean, 0._dbl, 0._dbl, 0._dbl /)\n\n\tend function calc_s_dev\n\n\n\n\n\tfunction calc_J1(s_dev)\n\t\timplicit none\n\t\t! computes first invariant of deviatoric stress vector\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl) :: calc_J1\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: s_dev\t\t! deviatoric stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of J1\n\t\tcalc_J1 = sum( s_dev(1:3) )\n\n\tend function calc_J1\n\n\n\n\n\tfunction calc_J2(sigma)\n\t\timplicit none\n\t\t! computes second invariant of deviatoric stress vector\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl) :: calc_J2\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation J2\n\t\tcalc_J2 = 1._dbl/3._dbl*calc_I1(sigma)**2 - calc_I2(sigma)\n\n\t\t! test if J2 < 0 (J2 must be positive)\n\t\tif (calc_J2 < 0._dbl) then\n\t\t\tcalc_J2 = 0._dbl\n\t\tend if\n\n\tend function calc_J2\n\n\n\n\n\tfunction calc_J3(sigma)\n\t\timplicit none\n\t\t! computes third invariant of deviatoric stress vector\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl) :: calc_J3\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation J3\n\t\tcalc_J3 = 2._dbl/27._dbl*calc_I1(sigma)**3 - 1._dbl/3._dbl*calc_I1(sigma)*calc_I2(sigma) + calc_I3(sigma)\n\n\tend function calc_J3\n\n\n\n\tfunction calc_DI1Dsigma(sigma)\n\t\timplicit none\n\t ! computes the gradient of the first invariant of the stress vector with respect to sigma\n\t ! dI1/dsigma\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), dimension(6) :: calc_DI1Dsigma\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! dI1/dsigma\n\t\tcalc_DI1Dsigma = (/ 1._dbl, 1._dbl, 1._dbl, 0._dbl, 0._dbl, 0._dbl /)\n\n\tend function calc_DI1Dsigma\n\n\n\n\tfunction calc_DI2Dsigma(sigma)\n\t\timplicit none\n\t ! computes the gradient of the second invariant of the stress vector with respect to sigma\n\t ! dI2/dsigma\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), dimension(6) :: calc_DI2Dsigma\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! dI2/dsigma\n\t\tcalc_DI2Dsigma = (/ sigma(2) + sigma(3), &\n\t\t\t\t\t\tsigma(1) + sigma(3), &\n\t\t\t\t\t\tsigma(2) + sigma(1), &\n\t\t\t\t\t\t-2._dbl*sigma(4), &\n\t\t\t\t\t\t-2._dbl*sigma(5), &\n\t\t\t\t\t\t-2._dbl*sigma(6) /)\n\n\tend function calc_DI2Dsigma\n\n\n\n\tfunction calc_DI3Dsigma(sigma)\n\t\timplicit none\n\t ! computes the gradient of the third invariant of the stress vector with respect to sigma\n\t ! dI3/dsigma\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), dimension(6) :: calc_DI3Dsigma\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: s11\n\t\treal(kind=dbl) :: s22\n\t\treal(kind=dbl) :: s33\n\t\treal(kind=dbl) :: s12\n\t\treal(kind=dbl) :: s13\n\t\treal(kind=dbl) :: s23\n\t\t! --------------------------------------------------------------------------\n\n\t\t! unpacking of stress vector\n\t\ts11 = sigma(1)\n\t\ts22 = sigma(2)\n\t\ts33 = sigma(3)\n\t\ts12 = sigma(4)\n\t\ts13 = sigma(5)\n\t\ts23 = sigma(6)\n\n\t\t! dI3/dsigma\n\t\tcalc_DI3Dsigma = (/ s22*s33 - s23**2, &\n\t\t\t\t\t\ts11*s33 - s13**2, &\n\t\t\t\t\t\ts11*s22 - s12**2, &\n\t\t\t\t\t\t2._dbl*(s23*s13 - s12*s33), &\n\t\t\t\t\t\t2._dbl*(s12*s23 - s13*s22), &\n\t\t\t\t\t\t2._dbl*(s12*s13 - s23*s11) /)\n\n\tend function calc_DI3Dsigma\n\n\n\n\tfunction calc_DJ2Dsigma(sigma)\n\t\timplicit none\n\t ! computes the gradient of the second invariant of the deviatoric stress vector with respect to sigma\n\t ! dJ2/dsigma\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), dimension(6) :: calc_DJ2Dsigma\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: I1\n\t\t! --------------------------------------------------------------------------\n\n\t\t!return s_dev\n\t\t!calc_DJ2Dsigma = calc_s_dev(sigma)\n\n\t\tcalc_DJ2Dsigma = 2._dbl/3._dbl*calc_I1(sigma)*calc_DI1Dsigma(sigma) - calc_DI2Dsigma(sigma)\n\n\tend function calc_DJ2Dsigma\n\n\n\n\tfunction calc_DJ3Dsigma(sigma)\n\t\timplicit none\n\t ! computes the gradient if the third invariant of the deviatoric stress vector with respect to sigma\n\t ! dJ3/dsigma\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), dimension(6) :: calc_DJ3Dsigma\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: dJ3dI1\t\t! dJ3/dI1\n\t\treal(kind=dbl) :: dJ3dI2\t\t! dJ3/dI2\n\t\treal(kind=dbl) :: dJ3dI3\t\t! dJ3/dI3\n\t\t! --------------------------------------------------------------------------\n\n\t\t! dJ3/dI1\n\t\tdJ3dI1 = 6._dbl/27._dbl*calc_I1(sigma)**2 - 1._dbl/3._dbl*calc_I2(sigma)\n\n\t\t! dJ3/dI2\n\t\tdJ3dI2 = -1._dbl/3._dbl*calc_I1(sigma)\n\n\t\t! dJ3/dI2\n\t\tdJ3dI3 = 1._dbl\n\n\t ! dJ3/dsigma\n\t calc_DJ3Dsigma = dJ3dI1*calc_DI1Dsigma(sigma) + dJ3dI2*calc_DI2Dsigma(sigma) + dJ3dI3*calc_DI3Dsigma(sigma)\n\n\tend function calc_DJ3Dsigma\n\n\n\n\tfunction calc_rho(sigma)\n\t\timplicit none\n\t\t! computes the Haigh Westergaard coordinate rho\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl) :: calc_rho\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: J2\t\t\t\t\t\t\t\t\t! second invariant of deviatoric stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of J2\n\t\tJ2 = calc_J2(sigma)\n\n\t\t! computation of rho\n\t\tcalc_rho = sqrt(2._dbl*J2)\n\n\tend function calc_rho\n\n\n\n\tfunction calc_theta(sigma)\n\t\timplicit none\n\t\t! computes the Haigh Westergaard coordinate theta\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl) :: calc_theta\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: J2\t\t\t\t\t\t\t\t\t! second invariant of deviatoric stress vector\n\t\treal(kind=dbl) :: J3\t\t\t\t\t\t\t\t\t! third invariant of deviatoric stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of J2 and J3\n\t\tJ2 = calc_J2(sigma)\n\t\tJ3 = calc_J3(sigma)\n\n\t\t! computation of theta\n\t\t! test if both J2 and J3 are zero, or J2 is negative, i.e a stress state on the hydrostatic axis\n\t\tif ( (abs(J3) < epsilon(1._dbl) .and. sqrt(J2)**3 < epsilon(1._dbl) ) .or. &\n\n\t\t\t\t(J2 <= 0._dbl) ) then\n\n\t\t\t! set theta to zero\n\t\t\tcalc_theta = 0._dbl\n\n\t\telse if ( 3._dbl*sqrt(3._dbl)/2._dbl * J3/sqrt(J2)**3 > 1._dbl ) then\n\n\t\t\t! set theta to zero\n\t\t\tcalc_theta = 0._dbl\n\n\t\telse if ( 3._dbl*sqrt(3._dbl)/2._dbl * J3/sqrt(J2)**3 < -1._dbl ) then\n\n\t\t\tcalc_theta = Pi/3._dbl\n\n\t\telse\n\n\t\t\tcalc_theta = 1._dbl/3._dbl * acos( 3._dbl*sqrt(3._dbl)/2._dbl * J3/sqrt(J2)**3 )\n\n\t\tend if\n\n\tend function calc_theta\n\n\n\n\tfunction calc_DrhoDsigma(sigma)\n\t\timplicit none\n\t ! computes the gradient of the Haigh Weestergaard coordinate rho with respect to sigma ( drho/dsigma )\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), dimension(6) :: calc_DrhoDsigma\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: rho\n\t\t! --------------------------------------------------------------------------\n\n\t\t! compute rho\n\t\trho = calc_rho(sigma)\n\n\t\t! droh/dsigma\n\t\tif (rho < epsilon(rho)) then\t! numerically equivalent to zero\n\t\t\tcalc_DrhoDsigma = huge(rho)*1.0D-10\n\t\telse\n\t\t calc_DrhoDsigma = 1._dbl/rho * calc_DJ2Dsigma(sigma)\n\t\tend if\n\n\tend function calc_DrhoDsigma\n\n\n\n\tfunction calc_DthetaDsigma(sigma)\n\t\timplicit none\n\t ! computes the gradient of the Haigh Weestergaard coordinate theta with respect to sigma ( dtheta/dsigma )\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), dimension(6) :: calc_DthetaDsigma\n\n\t\t! passed variable\n\t\treal(kind=dbl), dimension(6), intent(in) :: sigma\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: dtheta_dJ2\t\t\t\t! dtheta/dJ2\n\t\treal(kind=dbl) :: dtheta_dJ3\t\t\t\t! dtheta/dJ3\n\t\t! --------------------------------------------------------------------------\n\n\t\t! check if cos(3*theta) is outside the interval ]-1,1[\n\t\tif ( .not. (cos(3._dbl*calc_theta(sigma)) < 1._dbl) .or. &\n\t\t\t .not. (cos(3._dbl*calc_theta(sigma)) > -1._dbl) ) then\n\n\t\t\t! cos(3*theta) is on the borders of or outside the interval,\n\t\t\t! set dtheta/dJ2 and dtheta/dJ3 to zero\n\t\t\tdtheta_dJ2 = 0.0_dbl\n\t\t\tdtheta_dJ3 = 0.0_dbl\n\n\t\telse\n\n\t\t\t! dtheta/dJ2\n\t\t\tdtheta_dJ2 = sqrt(27._dbl)/4._dbl * calc_J3(sigma)/ &\n\t\t\t\t\t\t\t( sqrt(calc_J2(sigma))**5 * sqrt(1._dbl - cos(3._dbl*calc_theta(sigma))**2) )\n\n\t\t\t! dtheta/dJ3\n\t\t\tdtheta_dJ3 = -sqrt(3._dbl)/2._dbl * 1._dbl/ &\n\t\t\t\t\t\t\t( sqrt(calc_J2(sigma))**3 * sqrt(1._dbl - cos(3._dbl*calc_theta(sigma))**2) )\n\n\t\tend if\n\n\t ! DthetaDsigma\n\t calc_DthetaDsigma = dtheta_dJ2*calc_DJ2Dsigma(sigma) + dtheta_dJ3*calc_DJ3Dsigma(sigma)\n\n\tend function calc_DthetaDsigma\n\n\n\n\tfunction calc_C_elastic(E,nu)\n\t\timplicit none\n\t\t! computes elasticity matrix according to the generalized hooke's law\n\t\t! sigma = C * epsilon\n\t ! see \"Concepts and Application of Finite Element Analysis\" p. 79, Cook R. et al, 2002, John Wiley & Sons\n\t ! engineering shear strains are assumed -> tau_xy = 2*epsilon_xy\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), dimension(6,6) :: calc_C_elastic\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in) :: E\t\t! elasticity module\n\t\treal(kind=dbl), intent(in) :: nu\t\t! poisson ratio\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: a\n\t\treal(kind=dbl) :: b\n\t\treal(kind=dbl) :: c\n\t\t! --------------------------------------------------------------------------\n\n\t\t! initialization of internal variables\n\t\ta = E*(1._dbl-nu)/( (1._dbl+nu)*(1._dbl-2._dbl*nu) )\n\t\tb = nu/(1._dbl-nu)\n\t\tc = (1._dbl-2._dbl*nu)/( 2._dbl*(1._dbl-nu) )\n\n\t\t! initialization of C_el with zeros\n\t\tcalc_C_elastic = 0._dbl\n\n\t\t! initialization of non zero components of C_el\n\t\tcalc_C_elastic(1,1) = a\n\t\tcalc_C_elastic(2,2) = a\n\t\tcalc_C_elastic(3,3) = a\n\t\tcalc_C_elastic(4,4) = a*c\n\t\tcalc_C_elastic(5,5) = a*c\n\t\tcalc_C_elastic(6,6) = a*c\n\t\tcalc_C_elastic(1,2) = a*b\n\t\tcalc_C_elastic(1,3) = a*b\n\t\tcalc_C_elastic(2,1) = a*b\n\t\tcalc_C_elastic(2,3) = a*b\n\t\tcalc_C_elastic(3,1) = a*b\n\t\tcalc_C_elastic(3,2) = a*b\n\n\tend function calc_C_elastic\n\n\n\n\n\tfunction calc_inverse_C_elastic(E,nu)\n\t\timplicit none\n\t ! computes inverse elasticity matrix C^(-1) according to the generalized hooke's law\n\t ! epsilon = C^(-1) * sigma\n\t ! see \"Festigkeitslehre\" p. 86; Mang H. and G. Hofstetter; 2004, SpringerWienNewYork\n\t ! engineering shear strains are assumed -> tau_xy = 2*epsilon_xy\n\n\t\t! --------------------------------------------------------------------------\n\t\t! type declaration of return variable\n\t\treal(kind=dbl), dimension(6,6) :: calc_inverse_C_elastic\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in) :: E\t\t! elasticity module\n\t\treal(kind=dbl), intent(in) :: nu\t\t! poisson ratio\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: c\n\t\treal(kind=dbl) :: G\n\t\t! --------------------------------------------------------------------------\n\n\t\t! initialization of internal variables\n\t\tc = -nu/E\n\t\tG = E/( 2._dbl*(1._dbl+nu) )\n\n\t\t! initialization of C_el with zeros\n\t\tcalc_inverse_C_elastic = 0._dbl\n\n\t\t! initialization of non zero components of C_el\n\t\tcalc_inverse_C_elastic(1,1) = 1._dbl/E\n\t\tcalc_inverse_C_elastic(2,2) = 1._dbl/E\n\t\tcalc_inverse_C_elastic(3,3) = 1._dbl/E\n\t\tcalc_inverse_C_elastic(4,4) = 1._dbl/G\n\t\tcalc_inverse_C_elastic(5,5) = 1._dbl/G\n\t\tcalc_inverse_C_elastic(6,6) = 1._dbl/G\n\t\tcalc_inverse_C_elastic(1,2) = c\n\t\tcalc_inverse_C_elastic(1,3) = c\n\t\tcalc_inverse_C_elastic(2,1) = c\n\t\tcalc_inverse_C_elastic(2,3) = c\n\t\tcalc_inverse_C_elastic(3,1) = c\n\t\tcalc_inverse_C_elastic(3,2) = c\n\n\tend function calc_inverse_C_elastic\n\n\n! CORRECTED TRANSVERSE ELASTICITY MATRIX, ERROR IN WITTKE'S BOOK !!!!!!\n\tfunction calc_transv_istr_C_elastic(E1, E2, G2, nu1, nu2)\n\t\t! computes transverse isotropic elasticity matrix,\n\t\t! defined according to 'Rock Mechanics Based on an Anisotropic Jointed Rock Model' by Walter Wittke, p. 42 ff\n\t\t! C_el(1,2) = C_el(2,1) is wrong in the book, here the corrected expressions are implemented\n\t\t! C_el(3,3) is wrong in the book, here the corrected expressions are implemented\n\t\t! sigma = C_el * epsilon\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in) :: E1\t\t! elasticity constant parallel to the structure (isotropic) plane\n\t\treal(kind=dbl), intent(in) :: E2\t\t! elasticity constant perpendicular to the structure (isotropic) plane\n\t\treal(kind=dbl), intent(in) :: G2\t\t! shear modulus for shear loading in/parallel to the structure (isotropic) plane\n\t\treal(kind=dbl), intent(in) :: nu1\t\t! poisson ration perpendicular to the structure (isotropic) plane\n\t\treal(kind=dbl), intent(in) :: nu2\t\t! poisson ration in the structure (isotropic) plane\n\n\t\t! return variable\n\t\treal(kind=dbl), dimension(6,6) :: calc_transv_istr_C_elastic\t\t! return variable\n!f2py\tintent(out) :: calc_transv_istr_C_elastic\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: n\t\t! auxiliary variable\n\t\treal(kind=dbl) :: m\t\t! auxiliary variable\n\t\t! --------------------------------------------------------------------------\n\n\t\t! initialize auxiliary variables\n\t\tn = E1/E2\n\t\tm = 1._dbl-nu1-2._dbl*n*nu2**2\n\n\t\t! initialize elasticity matrix with zeros\n\t\tcalc_transv_istr_C_elastic = 0._dbl\n\n\t\t! compute nonzero components of elasticity matrix\n\t\tcalc_transv_istr_C_elastic(1,1) = E1*(1._dbl-n*nu2**2)/((1._dbl+nu1)*m)\n\t\tcalc_transv_istr_C_elastic(1,2) = E1*(nu1+n*nu2**2)/((1._dbl+nu1)*m)\t\t! E1*(1._dbl+n*nu2**2)/((1._dbl+nu1)*m) in Wittke's book which is wrong\n\t\tcalc_transv_istr_C_elastic(2,1) = E1*(nu1+n*nu2**2)/((1._dbl+nu1)*m)\t\t! E1*(1._dbl+n*nu2**2)/((1._dbl+nu1)*m) in Wittke's book which is wrong\n\t\tcalc_transv_istr_C_elastic(2,2) = E1*(1._dbl-n*nu2**2)/((1._dbl+nu1)*m)\n\t\tcalc_transv_istr_C_elastic(1:2,3) = E1*nu2/m\n\t\tcalc_transv_istr_C_elastic(3,1:2) = E1*nu2/m\n\t\tcalc_transv_istr_C_elastic(3,3) = E2*(1._dbl-nu1)/m\t\t\t\t\t\t\t! E1*(1._dbl-nu1)/m in Wittke's book which is wrong\n\t\tcalc_transv_istr_C_elastic(4,4) = E1/(2._dbl*(1._dbl+nu1))\n\t\tcalc_transv_istr_C_elastic(5,5) = G2\n\t\tcalc_transv_istr_C_elastic(6,6) = G2\n\n\tend function calc_transv_istr_C_elastic\n\n\n\n!\tfunction calc_transv_istr_C_elastic(E1, E2, G2, nu1, nu2)\n!\t\t! computes transverse isotropic elasticity matrix,\n!\t\t! defined according to Maple Computation\n!\t\t! sigma = C_el * epsilon\n!\t\timplicit none\n!\n!\t\t! --------------------------------------------------------------------------\n!\t\t! passed variables\n!\t\treal(kind=dbl), intent(in) :: E1\t\t! elasticity constant parallel to the structure (isotropic) plane\n!\t\treal(kind=dbl), intent(in) :: E2\t\t! elasticity constant perpendicular to the structure (isotropic) plane\n!\t\treal(kind=dbl), intent(in) :: G2\t\t! shear modulus for shear loading in/parallel to the structure (isotropic) plane\n!\t\treal(kind=dbl), intent(in) :: nu1\t\t! poisson ration perpendicular to the structure (isotropic) plane\n!\t\treal(kind=dbl), intent(in) :: nu2\t\t! poisson ration in the structure (isotropic) plane\n!\n!\t\t! return variable\n!\t\treal(kind=dbl), dimension(6,6) :: calc_transv_istr_C_elastic\t\t! return variable\n!\n!\t\t! internal variables\n!\t\t! --------------------------------------------------------------------------\n!\n!\t\t! initialize elasticity matrix with zeros\n!\t\tcalc_transv_istr_C_elastic = 0._dbl\n!\n!\t\t! compute nonzero components of elasticity matrix\n!\t\tcalc_transv_istr_C_elastic(1,1) = E1*(-E2+nu2**2*E1)/((E2*nu1-E2+2._dbl*nu2**2*E1)*(1._dbl+nu1))\n!\t\tcalc_transv_istr_C_elastic(1,2) = -E1*(E2*nu1+nu2**2*E1)/((E2*nu1-E2+2._dbl*nu2**2*E1)*(1._dbl+nu1))\n!\t\tcalc_transv_istr_C_elastic(1,3) = -nu2*E1*E2/(E2*nu1-E2+2*nu2**2*E1)\n!\t\tcalc_transv_istr_C_elastic(2,1) = -E1*(E2*nu1+nu2**2*E1)/((E2*nu1-E2+2._dbl*nu2**2*E1)*(1._dbl+nu1))\n!\t\tcalc_transv_istr_C_elastic(2,2) = E1*(-E2+nu2**2*E1)/((E2*nu1-E2+2._dbl*nu2**2*E1)*(1._dbl+nu1))\n!\t\tcalc_transv_istr_C_elastic(2,3) = -nu2*E1*E2/(E2*nu1-E2+2._dbl*nu2**2*E1)\n!\t\tcalc_transv_istr_C_elastic(3,1) = -nu2*E1*E2/(E2*nu1-E2+2._dbl*nu2**2*E1)\n!\t\tcalc_transv_istr_C_elastic(3,2) = -nu2*E1*E2/(E2*nu1-E2+2._dbl*nu2**2*E1)\n!\t\tcalc_transv_istr_C_elastic(3,3) = (nu1-1._dbl)*E2**2/(E2*nu1-E2+2._dbl*nu2**2*E1)\n!\t\tcalc_transv_istr_C_elastic(4,4) = 1._dbl/2._dbl*E1/(1._dbl+nu1)\n!\t\tcalc_transv_istr_C_elastic(5,5) = G2\n!\t\tcalc_transv_istr_C_elastic(6,6) = G2\n!\n!\tend function calc_transv_istr_C_elastic\n\n\n\n\tfunction calc_inv_transv_istr_C_elastic(E1, E2, G2, nu1, nu2)\n\t\t! computes transverse isotropic elasticity matrix,\n\t\t! defined according to 'Rock Mechanics Based on an Anisotropic Jointed Rock Model' by Walter Wittke, p. 42 ff\n\t\t! epsilon = C_el^(⁻1) * sigma\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in) :: E1\t\t! elasticity constant parallel to the structure (isotropic) plane\n\t\treal(kind=dbl), intent(in) :: E2\t\t! elasticity constant perpendicular to the structure (isotropic) plane\n\t\treal(kind=dbl), intent(in) :: G2\t\t! shear modulus for shear loading in/parallel to the structure (isotropic) plane\n\t\treal(kind=dbl), intent(in) :: nu1\t\t! poisson ration perpendicular to the structure (isotropic) plane\n\t\treal(kind=dbl), intent(in) :: nu2\t\t! poisson ration in the structure (isotropic) plane\n\n\t\t! return variable\n\t\treal(kind=dbl), dimension(6,6) :: calc_inv_transv_istr_C_elastic\t\t! return variable\n\n\t\t! internal variables\n\t\t! --------------------------------------------------------------------------\n\n\t\t! initialize elasticity matrix with zeros\n\t\tcalc_inv_transv_istr_C_elastic = 0._dbl\n\n\t\t! compute nonzero components of elasticity matrix\n\t\tcalc_inv_transv_istr_C_elastic(1,1) = 1._dbl/E1\n\t\tcalc_inv_transv_istr_C_elastic(1,2) = -nu1/E1\n\t\tcalc_inv_transv_istr_C_elastic(2,1) = -nu1/E1\n\t\tcalc_inv_transv_istr_C_elastic(2,2) = 1._dbl/E1\n\t\tcalc_inv_transv_istr_C_elastic(1:2,3) = -nu2/E2\n\t\tcalc_inv_transv_istr_C_elastic(3,1:2) = -nu2/E2\n\t\tcalc_inv_transv_istr_C_elastic(3,3) = 1._dbl/E2\n\t\tcalc_inv_transv_istr_C_elastic(4,4) = 2._dbl*(1._dbl+nu1)/E1\n\t\tcalc_inv_transv_istr_C_elastic(5,5) = 1._dbl/G2\n\t\tcalc_inv_transv_istr_C_elastic(6,6) = 1._dbl/G2\n\n\tend function calc_inv_transv_istr_C_elastic\n\n\n\n\tfunction calc_sig_princ_hw(s_mean, rho, theta)\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! return variable\n\t\treal(kind=dbl), dimension(3) :: calc_sig_princ_hw\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in) :: s_mean\n\t\treal(kind=dbl), intent(in) :: rho\n\t\treal(kind=dbl), intent(in) :: theta\n\n\t\t! internal variables\n\t\treal(kind=dbl), dimension(3) :: s_mean_vec\n\t\treal(kind=dbl), dimension(3) :: theta_vec\n\t\t! --------------------------------------------------------------------------\n\n\t\ts_mean_vec = (/ s_mean, s_mean, s_mean /)\n\n\t\ttheta_vec = (/ cos(theta), -sin(Pi/6._dbl-theta), -sin(Pi/6._dbl+theta) /)\n\n\t\tcalc_sig_princ_hw = s_mean_vec + sqrt(2._dbl/3._dbl)*rho*theta_vec\n\n\tend function calc_sig_princ_hw\n\n\n\n\tfunction calc_sig_princ_hw_sig(sigma)\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! return variable\n\t\treal(kind=dbl), dimension(3) :: calc_sig_princ_hw_sig\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: s_mean\n\t\treal(kind=dbl) :: rho\n\t\treal(kind=dbl) :: theta\n\t\treal(kind=dbl), dimension(3) :: s_mean_vec\n\t\treal(kind=dbl), dimension(3) :: theta_vec\n\t\t! --------------------------------------------------------------------------\n\n\t\t! test if shear stress components are zero\n\t\tif ( (abs(sigma(4)) < epsilon(1._dbl)) .and. &\n\t\t\t\t(abs(sigma(5)) < epsilon(1._dbl)) .and. &\n\t\t\t\t(abs(sigma(6)) < epsilon(1._dbl)) ) then\n\n\t\t\t! shear stresses are zero and therefore\n\t\t\t! the components of sigma already resemble\n\t\t\t! the principal stresses\n\t\t\tcalc_sig_princ_hw_sig = sort_sig_princ(sigma(1:3))\n\t\t\treturn\n\n\t\tend if\n\n\t\ts_mean = calc_s_mean(sigma)\n\t\trho = calc_rho(sigma)\n\t\ttheta = calc_theta(sigma)\n\n\t\ts_mean_vec = (/ s_mean, s_mean, s_mean /)\n\n\t\ttheta_vec = (/ cos(theta), -sin(Pi/6._dbl-theta), -sin(Pi/6._dbl+theta) /)\n\n\t\tcalc_sig_princ_hw_sig = s_mean_vec + sqrt(2._dbl/3._dbl)*rho*theta_vec\n\n\tend function calc_sig_princ_hw_sig\n\n\n\n\tfunction calc_Dsigma_princDsigma(sigma)\n\t\t! computes derivatives of principal stress vector\n\t\t! with respect to the stress vector via HW-coordinates\n\t\t! dsigma_princ/dsigma\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! return variable\n\t\treal(kind=dbl), dimension(3,6) :: calc_Dsigma_princDsigma\t! dsigma_princ/dsigma\n\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t\t! stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl) :: s_mean\t\t\t\t\t\t\t\t\t! HW-coordinate\n\t\treal(kind=dbl) :: rho\t\t\t\t\t\t\t\t\t\t! HW-coordinate\n\t\treal(kind=dbl) :: theta\t\t\t\t\t\t\t\t\t\t! HW-coordinate\n\t\treal(kind=dbl), dimension(3,1) :: Dsig_princDs_mean\t\t\t! dsigma_princ/ds_mean initialized as rank 2 variable (matrix with 1 column),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! so that it can be transposed and used in matrix multiplications\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! (not possible with rank 1 arrays, i.e. vectors)\n\n\t\treal(kind=dbl), dimension(3,1) :: Dsig_princDrho\t\t\t! dsigma_princ/drho initialized as rank 2 variable (matrix with 1 column),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! so that it can be transposed and used in matrix multiplications\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! (not possible with rank 1 arrays, i.e. vectors)\n\n\t\treal(kind=dbl), dimension(3,1) :: Dsig_princDtheta\t\t\t! dsigma_princ/dtheta initialized as rank 2 variable (matrix with 1 column),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! so that it can be transposed and used in matrix multiplications\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! (not possible with rank 1 arrays, i.e. vectors)\n\n\t\treal(kind=dbl), dimension(6,1) :: Ds_meanDsig\t\t\t\t! ds_mean/dsigma initialized as rank 2 variable (matrix with 1 column),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! so that it can be transposed and used in matrix multiplications\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! (not possible with rank 1 arrays, i.e. vectors)\n\n\t\treal(kind=dbl), dimension(6,1) :: DrhoDsig\t\t\t\t\t! drho/dsigma initialized as rank 2 variable (matrix with 1 column),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! so that it can be transposed and used in matrix multiplications\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! (not possible with rank 1 arrays, i.e. vectors)\n\n\t\treal(kind=dbl), dimension(6,1) :: dthetaDsig\t\t\t\t! dtheta/dsigma initialized as rank 2 variable (matrix with 1 column),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! so that it can be transposed and used in matrix multiplications\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t! (not possible with rank 1 arrays, i.e. vectors)\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of HW-coordinates\n\t\ts_mean = calc_s_mean(sigma)\n\t\trho = calc_rho(sigma)\n\t\ttheta = calc_theta(sigma)\n\n\t\t! computation of dsigma_princ/ds_mean\n\t\tDsig_princDs_mean = reshape( (/ 1._dbl, 1._dbl, 1._dbl /), (/3,1/) )\n\n\t\t! computation of dsigma_princ/drho\n\t\tDsig_princDrho = sqrt(2._dbl/3._dbl) * &\n\t\t\t\t\t\t\treshape( (/ cos(theta), -sin(Pi/6._dbl-theta), -sin(Pi/6._dbl+theta) /), &\n\t\t\t\t\t\t\t\t\t(/3,1/) )\n\n\t\t! computation of dsigma_princ/dtheta\n\t\tDsig_princDtheta = sqrt(2._dbl/3._dbl) * rho * &\n\t\t\t\t\t\t\treshape( (/ -sin(theta), cos(Pi/6._dbl-theta), -cos(Pi/6._dbl+theta) /), &\n\t\t\t\t\t\t\t\t\t(/3,1/) )\n\n\t\t! computation of ds_mean/dsigma and assignment to\n\t\t! rank 2 (matrix) variable Ds_meanDsig\n\t\tDs_meanDsig = reshape( Dsigma_mDsigma, (/6,1/) )\n\n\t\t! computation of drho/dsigma and assignment to\n\t\t! rank 2 (matrix) variable DrhoDsig\n\t\tDrhoDsig = reshape( calc_DrhoDsigma(sigma), (/6,1/) )\n\n\t\t! computation of dtheta/dsigma and assignment to\n\t\t! rank 2 (matrix) variable DthetaDsig\n\t\tDthetaDsig = reshape( calc_DthetaDsigma(sigma), (/6,1/) )\n\n\t\t! computation of dsigma_princ/dsigma with chain rule\n\t\t! dsigma_princ/dsigma = (dsigma_princ/ds_mean * ds_mean/dsigma) +\n\t\t! \t\t\t\t\t\t+ (dsigma_princ/drho * drho/dsigma) +\n\t\t! \t\t\t\t\t\t+ (dsigma_princ/dtheta * dtheta/dsigma)\n\t\tcalc_Dsigma_princDsigma = matmul( Dsig_princDs_mean, transpose(Ds_meanDsig) ) + &\n\t\t\t\t\t\t\t\t\tmatmul( Dsig_princDrho, transpose(DrhoDsig) ) + &\n\t\t\t\t\t\t\t\t\tmatmul( Dsig_princDtheta, transpose(DthetaDsig) )\n\n\tend function calc_Dsigma_princDsigma\n\n\n\n\tfunction sort_sig_princ(sig_princ)\n\t\t! sorts the entries of the principal stress vector,\n\t\t! depending on their size in descending order\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! return variable\n\t\treal(kind=dbl), dimension(3) :: sort_sig_princ\n\n\t\t! input variable\n\t\treal(kind=dbl), intent(in), dimension(3) :: sig_princ\n\n\t\t! internal variables\n\t\tinteger, dimension(1) :: ind_max\t! index of maximum sigma component\n\t\tinteger, dimension(1) :: ind_min\t! index of minimum sigma component\n\t\tinteger, dimension(1) :: ind_mid\t! index of intermediate sigma component\n\t\t! --------------------------------------------------------------------------\n\n\t\t! find index of maximum value\n\t\tind_max = maxloc(sig_princ)\n\t\t! find index of minimum value\n\t\tind_min = minloc(sig_princ)\n\n\t\tif (ind_max(1) == ind_min(1)) then\n\t\t\t! all components have the same size\n\t\t\t! return principal stress vector in unchanged order\n\t\t\tsort_sig_princ = sig_princ\n\t\t\treturn\n\t\telse\n\t\t\t! find index of intermediate value\n\t\t\tind_mid = 6 - ind_max - ind_min\n\n\t\t\t! assign maximum value to first entry of array\n\t\t\tsort_sig_princ(1) = sig_princ(ind_max(1))\n\t\t\t! assign intermediate value to second entry of array\n\t\t\tsort_sig_princ(2) = sig_princ(ind_mid(1))\n\t\t\t! assign minimum value to third(last) entry of array\n\t\t\tsort_sig_princ(3) = sig_princ(ind_min(1))\n\t\tend if\n\n\tend function sort_sig_princ\n\n\n\n\tfunction calc_rot_matrix_epsilon(alpha, beta, gam)\n\t\t! computes rotation matrix for coordinate transformation of the strain vector,\n\t\t! with shear strains in engineering notation\n\t\t! according to 'Concepts and Applications of Finite Element Analysis' by Robert D. Cook et al, p. 274, ff\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in) :: alpha\t\t! rotation around z axis\n\t\treal(kind=dbl), intent(in) :: beta\t\t! rotation around rotated y axis\n\t\treal(kind=dbl), intent(in) :: gam\t\t! rotation around rotated z axis, in case if transverse isotropy zero\n\n\t\t! output variable\n\t\treal(kind=dbl), dimension(6,6) :: calc_rot_matrix_epsilon\t! output rotation matrix\n\n\t\t! internal variables\n\t\treal(kind=dbl), dimension(3,3) :: T\t\t\t\t\t\t! rotation matrix with direction cosines of angles between original and rotated coordinate axes\n\t\treal(kind=dbl) :: lx, mx, nx\t\t\t\t\t\t\t! components of rotated x-base vector (first line of T)\n\t\treal(kind=dbl) :: ly, my, ny\t\t\t\t\t\t\t! components of rotated y-base vector (second line of T)\n\t\treal(kind=dbl) :: lz, mz, nz\t\t\t\t\t\t\t! components of rotated z-base vector (third line of T)\n\t\treal(kind=dbl), dimension(3,3) :: T11, T12, T21, T22\t! submatrices of rotation matrix\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of rotation matrix out of the three euler rotation angle defined by zyz convention\n\t\tT = calc_rot_matrix_zyz(alpha, beta, gam)\n\n\t\t! assign values of T to components\n\t\tlx = T(1,1)\n\t\tmx = T(1,2)\n\t\tnx = T(1,3)\n\t\tly = T(2,1)\n\t\tmy = T(2,2)\n\t\tny = T(2,3)\n\t\tlz = T(3,1)\n\t\tmz = T(3,2)\n\t\tnz = T(3,3)\n\n\t\t! fill submatrices\n\t\tT11 = T**2\n\t\tT12(:,1) = T(:,1)*T(:,2)\n\t\tT12(:,2) = T(:,1)*T(:,3)\n\t\tT12(:,3) = T(:,2)*T(:,3)\n\t\tT21(1,:) = 2._dbl*T(1,:)*T(2,:)\n\t\tT21(2,:) = 2._dbl*T(1,:)*T(3,:)\n\t\tT21(3,:) = 2._dbl*T(2,:)*T(3,:)\n\t\tT22 = reshape((/ (lx*my+mx*ly), (lx*mz+mx*lz), (ly*mz+my*lz), &\n\t\t\t\t\t\t\t(lx*ny+nx*ly), (lx*nz+nx*lz), (ly*nz+ny*lz), &\n\t\t\t\t\t\t\t(mx*ny+nx*my), (mx*nz+nx*mz), (my*nz+ny*mz) /), (/3,3/))\n\n\t\t! fill rotation matrix with submatrices\n\t\tcalc_rot_matrix_epsilon(1:3,1:3) = T11\n\t\tcalc_rot_matrix_epsilon(1:3,4:6) = T12\n\t\tcalc_rot_matrix_epsilon(4:6,1:3) = T21\n\t\tcalc_rot_matrix_epsilon(4:6,4:6) = T22\n\n\tend function calc_rot_matrix_epsilon\n\n\n\n\tfunction calc_rot_matrix_sigma(alpha, beta, gam)\n\t\t! computes rotation matrix for coordinate transformation of the stress vector,\n\t\t! according to 'Concepts and Applications of Finite Element Analysis' by Robert D. Cook et al, p. 274, ff\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in) :: alpha\t\t! rotation around z axis\n\t\treal(kind=dbl), intent(in) :: beta\t\t! rotation around rotated y axis\n\t\treal(kind=dbl), intent(in) :: gam\t\t! rotation around rotated z axis, in case if transverse isotropy zero\n\n\t\t!output variable\n\t\treal(kind=dbl), dimension(6,6) :: calc_rot_matrix_sigma\t\t! output stress rotation matrix\n\n\t\t! internal variables\n\t\treal(kind=dbl), dimension(6,6) :: T_epsilon\t\t! rotation matrix for strain vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! compute rotation matrix for strain vector\n\t\tT_epsilon = calc_rot_matrix_epsilon(alpha, beta, gam)\n\n\t\t! change submatrices of T_epsilon and assign them to output stress rotation matrix\n\t\tcalc_rot_matrix_sigma(1:3,1:3) = T_epsilon(1:3,1:3)\n\t\tcalc_rot_matrix_sigma(1:3,4:6) = 2._dbl*T_epsilon(1:3,4:6)\n\t\tcalc_rot_matrix_sigma(4:6,1:3) = 0.5_dbl*T_epsilon(4:6,1:3)\n\t\tcalc_rot_matrix_sigma(4:6,4:6) = T_epsilon(4:6,4:6)\n\n\tend function calc_rot_matrix_sigma\n\n\n\n\tfunction rotate_sigma(sigma, alpha, beta, gam)\n\t\t! computes and returns rotated stress vector\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! input variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n\t\treal(kind=dbl), intent(in) :: alpha\t\t\t\t\t\t! first euler rotation angle, around z-axis, eastwards positive (zyz convention)\n\t\treal(kind=dbl), intent(in) :: beta\t\t\t\t\t\t! second euler rotation angle, around rotated y-axis, downwards positive (zyz convention)\n\t\treal(kind=dbl), intent(in) :: gam\t\t\t\t\t\t! third euler rotation angle, around rotated z-axis, eastwards positive (zyz convention)\n\n\t\t! return variable\n\t\treal(kind=dbl), dimension(6) :: rotate_sigma\t\t\t! rotated stress vector\n\n\t\t! internal variables\n\t\treal(kind=dbl), dimension(6,6) :: T_sig\t\t\t\t\t! rotation matrix for rotation of stress vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of stress rotation matrix with the three euler rotation angle defined by zyz convention\n\t\tT_sig = calc_rot_matrix_sigma(alpha, beta, gam)\n\n\t\t! compute rotated stress vector\n\t\trotate_sigma = matmul(T_sig, sigma)\n\n\tend function rotate_sigma\n\n\n\n\tfunction rotate_epsilon(eps, alpha, beta, gam)\n\t\t! computes and returns rotated strain vector\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! input variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: eps\t\t\t! strain vector\n\t\treal(kind=dbl), intent(in) :: alpha\t\t\t\t\t\t! first euler rotation angle, around z-axis, eastwards positive (zyz convention)\n\t\treal(kind=dbl), intent(in) :: beta\t\t\t\t\t\t! second euler rotation angle, around rotated y-axis, downwards positive (zyz convention)\n\t\treal(kind=dbl), intent(in) :: gam\t\t\t\t\t\t! third euler rotation angle, around rotated z-axis, eastwards positive (zyz convention)\n\n\t\t! return variable\n\t\treal(kind=dbl), dimension(6) :: rotate_epsilon\t\t\t! rotated strain vector\n\n\t\t! internal variables\n\t\treal(kind=dbl), dimension(6,6) :: T_eps\t\t\t\t\t! rotation matrix for rotation of strain vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of strain rotation matrix with the three euler rotation angle defined by zyz convention\n\t\tT_eps = calc_rot_matrix_epsilon(alpha, beta, gam)\n\n\t\t! compute rotated stress vector\n\t\trotate_epsilon = matmul(T_eps, eps)\n\n\tend function rotate_epsilon\n\n\n\n\tfunction rotate_material_matrix(C, alpha, beta, gam)\n\t\t! computes and returns rotated material tensor/matrix (C_elastic or C_elastoplastic),\n\t\t! according to: 'Rock Mechanics Based on an Anisotropic Jointed Rock Model' by Walter Wittke, p. 45 ff\n\t\t!\t\t\t\t'Concepts and Applications of Finite Element Analysis' by Robert D. Cook et al, p. 275, ff\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! input variables\n\t\treal(kind=dbl), intent(in), dimension(6,6) :: C\t\t\t! material matrix\n\t\treal(kind=dbl), intent(in) :: alpha\t\t\t\t\t\t! first euler rotation angle, around z-axis, eastwards positive (zyz convention)\n\t\treal(kind=dbl), intent(in) :: beta\t\t\t\t\t\t! second euler rotation angle, around rotated y-axis, downwards positive (zyz convention)\n\t\treal(kind=dbl), intent(in) :: gam\t\t\t\t\t\t! third euler rotation angle, around rotated z-axis, eastwards positive (zyz convention)\n\n\t\t! return variable\n\t\treal(kind=dbl), dimension(6,6) :: rotate_material_matrix\t\t\t! rotated material matrix\n!f2py\tintent(out) :: rotate_material_matrix\n\n\t\t! internal variables\n\t\treal(kind=dbl), dimension(6,6) :: T_eps\t\t\t\t\t! strain rotation matrix for rotation of material matrix\n\t\treal(kind=dbl), dimension(6,6) :: T_sigma\t\t\t\t! stress rotation matrix for rotation of material matrix\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of strain rotation matrix\n\t\tT_eps = calc_rot_matrix_epsilon(-alpha, -beta, -gam)\n\n\t\t! computation of stress rotation matrix\n\t\tT_sigma = calc_rot_matrix_sigma(alpha, beta, gam)\n\n\t\t! compute rotated material matrix\n\t\trotate_material_matrix = matmul(T_sigma, matmul(C,T_eps))\n\n\tend function rotate_material_matrix\n\n\n\n\tfunction rotate_inv_material_matrix(C_inv, alpha, beta, gam)\n\t\t! computes and returns rotated material tensor/matrix (inverse C_elastic or inverse C_elastoplastic),\n\t\t! according to: 'Rock Mechanics Based on an Anisotropic Jointed Rock Model' by Walter Wittke, p. 45 ff\n\t\t!\t\t\t\t'Concepts and Applications of Finite Element Analysis' by Robert D. Cook et al, p. 275, ff\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! input variables\n\t\treal(kind=dbl), intent(in), dimension(6,6) :: C_inv\t\t\t! material matrix\n\t\treal(kind=dbl), intent(in) :: alpha\t\t\t\t\t\t! first euler rotation angle, around z-axis, eastwards positive (zyz convention)\n\t\treal(kind=dbl), intent(in) :: beta\t\t\t\t\t\t! second euler rotation angle, around rotated y-axis, downwards positive (zyz convention)\n\t\treal(kind=dbl), intent(in) :: gam\t\t\t\t\t\t! third euler rotation angle, around rotated z-axis, eastwards positive (zyz convention)\n\n\t\t! return variable\n\t\treal(kind=dbl), dimension(6,6) :: rotate_inv_material_matrix\t\t\t! rotated inverse material matrix\n\n\t\t! internal variables\n\t\treal(kind=dbl), dimension(6,6) :: T_sig\t\t\t\t\t! rotation matrix for rotation of inverse material matrix\n\t\treal(kind=dbl), dimension(6,6) :: T_eps\t\t\t\t\t! rotation matrix for rotation of inverse material matrix\n\t\t! --------------------------------------------------------------------------\n\n\t\t! computation of rotation matrix\n\t\t!T_sig = calc_rot_matrix_sigma(alpha, beta, gam)\n\t\tT_eps = calc_rot_matrix_epsilon(alpha,beta, gam)\n\n\t\t! compute rotated inverse material matrix\n\t\t!rotate_inv_material_matrix = matmul(transpose(T_sig), matmul(C_inv,T_sig))\n\t\trotate_inv_material_matrix = matmul(T_eps, matmul(C_inv,transpose(T_eps)))\n\n\tend function rotate_inv_material_matrix\n\n\n\n\tfunction calc_gen_l_vec(sigma)\n\t\t! computes the normed generalized loading vector l\n\t\t! according to \"On failure criteria for anisotropic cohesive-frictional materials\" by S. Pietruszczak and Z. Mroz, 2000\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! input variables\n\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t\t! stress vector\n\n\t\t! return variable\n\t\treal(kind=dbl), dimension(3) :: calc_gen_l_vec\t\t! generalized loading vector\n!f2py\tintent(out) :: calc_gen_loading_vec\n\n\t\t! internal variables\n\t\treal(kind=dbl), dimension(3) :: L\t\t! loading vector\n\t\t! --------------------------------------------------------------------------\n\n\t\t! compute L\n!\t\tL(1) = sqrt(sigma(1)**2+sigma(4)**2+sigma(5)**2)\t\t! s11, s12, s13\n!\t\tL(2) = sqrt(sigma(2)**2+sigma(4)**2+sigma(6)**2)\t\t! s22, s12, s23\n!\t\tL(3) = sqrt(sigma(3)**2+sigma(5)**2+sigma(6)**2)\t\t! s33, s13, s23\n\t\tif (.not. all(sigma .eq. 0._dbl)) then\n\t\t\tL = calc_gen_l_vec_unnormed(sigma)\t\t\t! not all stress components are zero, proceed to compute L\n\n\t\t\t! compute generalized loading vector\n\t\t\tcalc_gen_l_vec = 1._dbl/norm2(L) * L\n\t\telse\n\n\t\t\tcalc_gen_l_vec = 0._dbl\t\t! all stress components are zero, set l to zero and return\n\n\t\tend if\n\n\tend function calc_gen_l_vec\n\n\n\n\tfunction calc_gen_l_vec_unnormed(sigma)\n\t ! computes unnormed generalized loading vector L\n\t implicit none\n\n\t ! --------------------------------------------------------------------------\n\t ! passed variables\n\t\t\treal(kind=dbl), intent(in), dimension(6) :: sigma\t\t! stress vector\n\n\t ! return variable\n\t real(kind=dbl), dimension(3) :: calc_gen_l_vec_unnormed\t! L\n! f2py\t\tintent(out) :: calc_gen_loading_vec_unnormed\n\n\t ! internal variables\n\t ! --------------------------------------------------------------------------\n\n\t\t! compute L\n\t\tcalc_gen_l_vec_unnormed(1) = sqrt(sigma(1)**2+sigma(4)**2+sigma(5)**2)\t\t! s11, s12, s13\n\t\tcalc_gen_l_vec_unnormed(2) = sqrt(sigma(2)**2+sigma(4)**2+sigma(6)**2)\t\t! s22, s12, s23\n\t\tcalc_gen_l_vec_unnormed(3) = sqrt(sigma(3)**2+sigma(5)**2+sigma(6)**2)\t\t! s33, s13, s23\n\n\t end function calc_gen_l_vec_unnormed\n\n\nend module stress_routines\n", "meta": {"hexsha": "b2afc97ae733f7925925eeb0b0b3df067a1fae56", "size": 43160, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "return_mapping/stress_routines.f90", "max_stars_repo_name": "yuyong1990/TsaiWu-Fortran", "max_stars_repo_head_hexsha": "a111ca1717adfbbaf3e9e34f4189a441e16441b8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2017-11-19T15:12:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T15:34:59.000Z", "max_issues_repo_path": "return_mapping/stress_routines.f90", "max_issues_repo_name": "OVGULIU/TsaiWu-Fortran", "max_issues_repo_head_hexsha": "a111ca1717adfbbaf3e9e34f4189a441e16441b8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "return_mapping/stress_routines.f90", "max_forks_repo_name": "OVGULIU/TsaiWu-Fortran", "max_forks_repo_head_hexsha": "a111ca1717adfbbaf3e9e34f4189a441e16441b8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2017-02-11T12:56:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-01T11:29:18.000Z", "avg_line_length": 35.3191489362, "max_line_length": 198, "alphanum_fraction": 0.6081788693, "num_tokens": 12875, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7692883683354038}} {"text": "!**********************************************************************\r\n! ROUTINE: FUZZY FORTRAN OPERATORS\r\n! PURPOSE: Illustrate Hindmarsh's computation of EPS, and APL\r\n! tolerant comparisons, tolerant CEIL/FLOOR, and Tolerant\r\n! ROUND functions - implemented in Fortran.\r\n! PLATFORM: PC Windows Fortran, Compaq-Digital CVF 6.1a, AIX XLF90\r\n! TO RUN: Windows: DF EPS.F90\r\n! AIX: XLF90 eps.f -o eps.exe -qfloat=nomaf\r\n! CALLS: none\r\n! AUTHOR: H. D. Knoble 22 September 1978\r\n! REVISIONS:\r\n!**********************************************************************\r\n!\r\n DOUBLE PRECISION EPS,EPS3, X,Y,Z, D1MACH,TFLOOR,TCEIL,EPSF90\r\n LOGICAL TEQ,TNE,TGT,TGE,TLT,TLE\r\n!---Following are Fuzzy Comparison (arithmetic statement) Functions.\r\n!\r\n TEQ(X,Y)=DABS(X-Y).LE.DMAX1(DABS(X),DABS(Y))*EPS3\r\n TNE(X,Y)=.NOT.TEQ(X,Y)\r\n TGT(X,Y)=(X-Y).GT.DMAX1(DABS(X),DABS(Y))*EPS3\r\n TLE(X,Y)=.NOT.TGT(X,Y)\r\n TLT(X,Y)=TLE(X,Y).AND.TNE(X,Y)\r\n TGE(X,Y)=TGT(X,Y).OR.TEQ(X,Y)\r\n!\r\n!---Compute EPS for this computer. EPS is the smallest real number on\r\n! this architecture such that 1+EPS>1 and 1-EPS<1.\r\n! EPSILON(X) is a Fortran 90 built-in Intrinsic function. They should\r\n! be identically equal.\r\n!\r\n EPS=D1MACH(NULL)\r\n EPSF90=EPSILON(X)\r\n IF(EPS.NE.EPSF90) THEN\r\n WRITE(*,2)'EPS=',EPS,' .NE. EPSF90=',EPSF90\r\n2 FORMAT(A,Z16,A,Z16)\r\n ENDIF\r\n!---Accept a representation if exact, or one bit on either side.\r\n EPS3=3.D0*EPS\r\n WRITE(*,1) EPS,EPS, EPS3,EPS3\r\n1 FORMAT(' EPS=',D16.8,2X,Z16, ', EPS3=',D16.8,2X,Z16)\r\n!---Illustrate Fuzzy Comparisons using EPS3. Any other magnitudes will\r\n! behave similarly.\r\n Z=1.D0\r\n I=49\r\n X=1.D0/I\r\n Y=X*I\r\n WRITE(*,*) 'X=1.D0/',I,', Y=X*',I,', Z=1.D0'\r\n WRITE(*,*) 'Y=',Y,' Z=',Z\r\n WRITE(*,3) X,Y,Z\r\n3 FORMAT(' X=',Z16,' Y=',Z16,' Z=',Z16)\r\n!---Floating-point Y is not identical (.EQ.) to floating-point Z.\r\n IF(Y.EQ.Z) WRITE(*,*) 'Fuzzy Comparisons: Y=Z'\r\n IF(Y.NE.Z) WRITE(*,*) 'Fuzzy Comparisons: Y<>Z'\r\n!---But Y is tolerantly (and algebraically) equal to Z.\r\n IF(TEQ(Y,Z)) THEN\r\n WRITE(*,*) 'but TEQ(Y,Z) is .TRUE.'\r\n WRITE(*,*) 'That is, Y is computationally equal to Z.'\r\n ENDIF\r\n IF(TNE(Y,Z)) WRITE(*,*) 'and TNE(Y,Z) is .TRUE.'\r\n WRITE(*,*) ' '\r\n!---Evaluate Fuzzy FLOOR and CEILing Function values using a Comparison\r\n! Tolerance, CT, of EPS3.\r\n X=0.11D0\r\n Y=((X*11.D0)-X)-0.1D0\r\n YFLOOR=TFLOOR(Y,EPS3)\r\n YCEIL=TCEIL(Y,EPS3)\r\n55 Z=1.D0\r\n WRITE(*,*) 'X=0.11D0, Y=X*11.D0-X-0.1D0, Z=1.D0'\r\n WRITE(*,*) 'X=',X,' Y=',Y,' Z=',Z\r\n WRITE(*,3) X,Y,Z\r\n!---Floating-point Y is not identical (.EQ.) to floating-point Z.\r\n IF(Y.EQ.Z) WRITE(*,*) 'Fuzzy FLOOR/CEIL: Y=Z'\r\n IF(Y.NE.Z) WRITE(*,*) 'Fuzzy FLOOR/CEIL: Y<>Z'\r\n IF(TFLOOR(Y,EPS3).EQ.TCEIL(Y,EPS3).AND.TFLOOR(Y,EPS3).EQ.Z) THEN\r\n!---But Tolerant Floor/Ceil of Y is identical (and algebraically equal)\r\n! to Z.\r\n WRITE(*,*) 'but TFLOOR(Y,EPS3)=TCEIL(Y,EPS3)=Z.'\r\n WRITE(*,*) 'That is, TFLOOR/TCEIL return exact whole numbers.'\r\n ENDIF\r\n STOP\r\n END\r\n DOUBLE PRECISION FUNCTION D1MACH (IDUM)\r\n INTEGER IDUM\r\n!=======================================================================\r\n! This routine computes the unit roundoff of the machine in double\r\n! precision. This is defined as the smallest positive machine real\r\n! number, EPS, such that (1.0D0+EPS > 1.0D0) & (1.D0-EPS < 1.D0).\r\n! This computation of EPS is the work of Alan C. Hindmarsh.\r\n! For computation of Machine Parameters also see:\r\n! W. J. Cody, \"MACHAR: A subroutine to dynamically determine machine\r\n! parameters, \" TOMS 14, December, 1988; or\r\n! Alan C. Hindmarsh at http://www.netlib.org/lapack/util/dlamch.f\r\n! or Werner W. Schulz at http://www.ozemail.com.au/~milleraj/ .\r\n!\r\n! This routine appears to give bit-for-bit the same results as\r\n! the Intrinsic function EPSILON(x) for x single or double precision.\r\n! hdk - 25 August 1999.\r\n!-----------------------------------------------------------------------\r\n DOUBLE PRECISION EPS, COMP\r\n! EPS = 1.0D0\r\n!10 EPS = EPS*0.5D0\r\n! COMP = 1.0D0 + EPS\r\n! IF (COMP .NE. 1.0D0) GO TO 10\r\n! D1MACH = EPS*2.0D0\r\n EPS = 1.0D0\r\n COMP = 2.0D0\r\n DO WHILE ( COMP .NE. 1.0D0 )\r\n EPS = EPS*0.5D0\r\n COMP = 1.0D0 + EPS\r\n ENDDO\r\n D1MACH = EPS*2.0D0\r\n RETURN\r\n END\r\n DOUBLE PRECISION FUNCTION TFLOOR(X,CT)\r\n!===========Tolerant FLOOR Function.\r\n!\r\n! C - is given as a double precision argument to be operated on.\r\n! it is assumed that X is represented with m mantissa bits.\r\n! CT - is given as a Comparison Tolerance such that\r\n! 0.lt.CT.le.3-Sqrt(5)/2. If the relative difference between\r\n! X and a whole number is less than CT, then TFLOOR is\r\n! returned as this whole number. By treating the\r\n! floating-point numbers as a finite ordered set note that\r\n! the heuristic eps=2.**(-(m-1)) and CT=3*eps causes\r\n! arguments of TFLOOR/TCEIL to be treated as whole numbers\r\n! if they are exactly whole numbers or are immediately\r\n! adjacent to whole number representations. Since EPS, the\r\n! \"distance\" between floating-point numbers on the unit\r\n! interval, and m, the number of bits in X's mantissa, exist\r\n! on every floating-point computer, TFLOOR/TCEIL are\r\n! consistently definable on every floating-point computer.\r\n!\r\n! For more information see the following references:\r\n! {1} P. E. Hagerty, \"More on Fuzzy Floor and Ceiling,\" APL QUOTE\r\n! QUAD 8(4):20-24, June 1978. Note that TFLOOR=FL5 took five\r\n! years of refereed evolution (publication).\r\n!\r\n! {2} L. M. Breed, \"Definitions for Fuzzy Floor and Ceiling\", APL\r\n! QUOTE QUAD 8(3):16-23, March 1978.\r\n!\r\n! H. D. KNOBLE, Penn State University.\r\n!=====================================================================\r\n DOUBLE PRECISION X,Q,RMAX,EPS5,CT,FLOOR,DINT\r\n!---------FLOOR(X) is the largest integer algegraically less than\r\n! or equal to X; that is, the unfuzzy Floor Function.\r\n DINT(X)=X-DMOD(X,1.D0)\r\n FLOOR(X)=DINT(X)-DMOD(2.D0+DSIGN(1.D0,X),3.D0)\r\n!---------Hagerty's FL5 Function follows...\r\n Q=1.D0\r\n IF(X.LT.0)Q=1.D0-CT\r\n RMAX=Q/(2.D0-CT)\r\n EPS5=CT/Q\r\n TFLOOR=FLOOR(X+DMAX1(CT,DMIN1(RMAX,EPS5*DABS(1.D0+FLOOR(X)))))\r\n IF(X.LE.0 .OR. (TFLOOR-X).LT.RMAX)RETURN\r\n TFLOOR=TFLOOR-1.D0\r\n RETURN\r\n END\r\n DOUBLE PRECISION FUNCTION TCEIL(X,CT)\r\n!==========Tolerant Ceiling Function.\r\n! See TFLOOR.\r\n DOUBLE PRECISION X,CT,TFLOOR\r\n TCEIL= -TFLOOR(-X,CT)\r\n RETURN\r\n END\r\n DOUBLE PRECISION FUNCTION ROUND(X,CT)\r\n!=========Tolerant Round Function\r\n! See Knuth, Art of Computer Programming, Vol. 1, Problem 1.2.4-5.\r\n DOUBLE PRECISION TFLOOR,X,CT\r\n ROUND=TFLOOR(X+0.5D0,CT)\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "7127ba9ff1840ea9e43bd2a20ae9eb638eaf5cf8", "size": 7225, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lib/lib-tcllib/math/fuzzy.eps.f90", "max_stars_repo_name": "rashidkpc/rattlecad", "max_stars_repo_head_hexsha": "1eab9fc4be926ab28d825764929f356f03d31968", "max_stars_repo_licenses": ["TCL"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-27T16:18:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-27T16:18:53.000Z", "max_issues_repo_path": "lib/lib-tcllib/math/fuzzy.eps.f90", "max_issues_repo_name": "rashidkpc/rattlecad", "max_issues_repo_head_hexsha": "1eab9fc4be926ab28d825764929f356f03d31968", "max_issues_repo_licenses": ["TCL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/lib-tcllib/math/fuzzy.eps.f90", "max_forks_repo_name": "rashidkpc/rattlecad", "max_forks_repo_head_hexsha": "1eab9fc4be926ab28d825764929f356f03d31968", "max_forks_repo_licenses": ["TCL"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-27T16:18:55.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-27T16:18:55.000Z", "avg_line_length": 42.2514619883, "max_line_length": 73, "alphanum_fraction": 0.5616608997, "num_tokens": 2330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.8670357529306639, "lm_q1q2_score": 0.7692381080887432}} {"text": "C ************************************************************************\nC FILE: ser_pi_calc.f \nC DESCRIPTION: \nC Serial pi Calculation - Fortran Version \nC This program calculates pi using a \"dartboard\" algorithm. See\nC Fox et al.(1988) Solving Problems on Concurrent Processors, vol.1\nC page 207. \nC Note: Requires Fortran90 compiler due to random_number() function\nC AUTHOR: unknown\nC LAST REVISED: 02/23/12 Blaise Barney \nC ************************************************************************\nC Explanation of constants and variables used in this program:\nC DARTS = number of throws at dartboard\nC ROUNDS = number of times \"DARTS\" is iterated\nC pi = average of pi for this iteration\nC avepi = average pi value for all iterations\nC ************************************************************************\n\n\tprogram pi_calc\n\n\tinteger DARTS, ROUNDS\n\tparameter(DARTS = 10000)\n\tparameter(ROUNDS = 100)\n real*4 seednum\n real*8 pi, avepi, dboard\n\n print *,'Starting serial version of pi calculation...'\n\n \tavepi = 0\n\tdo 40 i = 1, ROUNDS\n\t pi = dboard(DARTS)\n avepi = ((avepi*(i-1)) + pi)/ i \n write(*,32) DARTS*i, avepi\n 32 format(' After',i8,' throws, average value of pi = ',\n & f10.8,$)\n 40\tcontinue\n print *, ' '\n print *,'Real value of PI: 3.1415926535897'\n print *, ' '\n\tend\n\nC ************************************************************************\nC dboard.f\nC ************************************************************************\nC Explanation of constants and variables used in this function:\nC darts = number of throws at dartboard\nC score = number of darts that hit circle\nC n = index variable\nC r = random number between 0 and 1\nC x_coord = x coordinate, between -1 and 1\nC x_sqr = square of x coordinate\nC y_coord = y coordinate, between -1 and 1\nC y_sqr = square of y coordinate\nC pi = computed value of pi\nC ************************************************************************\n real*8 function dboard(darts)\n\n integer darts, score, n\n real*4 r\n real*8 x_coord, x_sqr, y_coord, y_sqr, pi\n\n score = 0\n\nC Throw darts at board. Done by generating random numbers\nC between 0 and 1 and converting them to values for x and y\nC coordinates and then testing to see if they \"land\" in\nC the circle.\" If so, score is incremented. After throwing the\nC specified number of darts, pi is calculated. The computed value\nC of pi is returned as the value of this function, dboard.\nC Note: the seed value for rand() is set in pi_calc.\n\nC Note: Requires Fortran90 compiler due to random_number() function\n print *, ' '\n do 10 n = 1, darts\n call random_number(r)\n x_coord = (2.0 * r) - 1.0\n x_sqr = x_coord * x_coord\n\n call random_number(r)\n y_coord = (2.0 * r) - 1.0\n y_sqr = y_coord * y_coord\n\n if ((x_sqr + y_sqr) .le. 1.0) then\n score = score + 1\n endif\n\n 10 continue\n\n pi = 4.0 * score / darts\n dboard = pi\n end\n\n", "meta": {"hexsha": "ef37755f4fb3521c591fee5f8df35c99f4d9f42e", "size": 3226, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mpi/examples/ser_pi_calc.f", "max_stars_repo_name": "hixio-mh/HPC-Tutorials", "max_stars_repo_head_hexsha": "dc2b381cc83c9d1a23e3356d89b3cc791ff50f2c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 93, "max_stars_repo_stars_event_min_datetime": "2021-03-15T20:40:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T08:57:40.000Z", "max_issues_repo_path": "mpi/examples/ser_pi_calc.f", "max_issues_repo_name": "hixio-mh/HPC-Tutorials", "max_issues_repo_head_hexsha": "dc2b381cc83c9d1a23e3356d89b3cc791ff50f2c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-05-14T04:55:45.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:33:20.000Z", "max_forks_repo_path": "mpi/examples/ser_pi_calc.f", "max_forks_repo_name": "hixio-mh/HPC-Tutorials", "max_forks_repo_head_hexsha": "dc2b381cc83c9d1a23e3356d89b3cc791ff50f2c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2021-03-10T00:31:09.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T13:48:30.000Z", "avg_line_length": 34.688172043, "max_line_length": 74, "alphanum_fraction": 0.5294482331, "num_tokens": 844, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7692208085327485}} {"text": "Program TaskOne\nIMPLICIT NONE \n\n real :: X, Y, InsideCircCheck, PiEstimate\n integer :: i,iseed, first, n, ncirc\n real, external :: RandNum\n\n first=0; iseed=971739; nCirc=0\n write(6,'(a,i9)')'seed value that generates this sequence is ',iseed\n WRITE(6,*) 'Please enter number of points, n'\n READ(5,*) n\nX = (RandNum(iseed,first)*2.0)-1\nY = (RandNum(iseed,first)*2.0)-1\n\nDO i=1,n\n X = (RandNum(iseed,first)*2.0)-1\n Y = (RandNum(iseed,first)*2.0)-1\n InsideCircCheck = X**2+Y**2\n\n IF ( InsideCircCheck <= 1) then\n nCirc = nCirc + 1\n END IF\n\nEND DO\n\nPiEstimate = 4.0*(REAL(nCirc)/REAL(n))\nWRITE(6,*) PiEstimate\n \nEND PROGRAM\n\nfunction RandNum(iseed,first) \n implicit none\n REAL:: RandNum\n integer, parameter :: MPLIER=16807\n integer, parameter :: MODLUS=2147483647\n integer, parameter :: MOBYMP=127773\n integer, parameter :: MOMDMP=2836\n integer :: hvlue,lvlue,testv,nextn,first,iseed\n save nextn\n \n\n if(first == 0) THEN\n nextn=iseed\n first=1\n end if\n hvlue=nextn/mobymp\n lvlue=mod(nextn,mobymp)\n testv=mplier*lvlue-momdmp*hvlue\n \n if(testv > 0)then\n nextn=testv\n else\n nextn=testv+modlus\n endif\n RandNum = real(nextn)/real(modlus)\n\nend function RandNum", "meta": {"hexsha": "d97e050dafa3d8b3e9c995da3897b23dc389eba4", "size": 1194, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Monte Carlo Method and Bayesian Statistics/Task1.f95", "max_stars_repo_name": "DGrifferty/Fortran", "max_stars_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Monte Carlo Method and Bayesian Statistics/Task1.f95", "max_issues_repo_name": "DGrifferty/Fortran", "max_issues_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Monte Carlo Method and Bayesian Statistics/Task1.f95", "max_forks_repo_name": "DGrifferty/Fortran", "max_forks_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.9473684211, "max_line_length": 70, "alphanum_fraction": 0.675879397, "num_tokens": 465, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.7692180595041267}} {"text": "module MC_randoms\r\n implicit none\r\n integer,parameter:: ik=selected_int_kind(11)\r\n integer,parameter:: rk=selected_real_kind(11,100)\r\n !QCG parameters\r\n integer(kind=ik),parameter:: qcg_m=11, qcg_a=11, qcg_b=1, qcg_c=3\r\n integer(kind=ik):: qcg_seed\r\n !LCG parameters.\r\n integer(kind=ik),parameter::lcg_m=113829760, lcg_a=10671541, lcg_c=3\r\n integer(kind=ik)::lcg_seed\r\n !Park-Miller parameters\r\n integer(kind=ik),parameter::pm_m=2147483647, pm_a=16807,pm_q=127773,pm_r=2836\r\n integer(kind=ik)::pm_seed\r\n\r\ncontains\r\n !QCG routines\r\n subroutine seed_qcg(seed)\r\n implicit none\r\n integer(kind=ik), intent(in):: seed\r\n qcg_seed=seed\r\n end subroutine seed_qcg\r\n\r\n real(kind=rk) function rand_qcg()\r\n implicit none\r\n qcg_seed=mod(qcg_a*qcg_seed**2+qcg_b*qcg_seed+qcg_c, qcg_m)\r\n rand_qcg=real(qcg_seed, rk)/real(qcg_m, rk)\r\n end function rand_qcg \r\n\r\n !LCG routines\r\n subroutine seed_lcg(seed)\r\n implicit none\r\n integer(kind=ik),intent(in)::seed\r\n lcg_seed=seed\r\n end subroutine seed_lcg\r\n\r\n real(rk) function rand_lcg()\r\n implicit none\r\n integer(kind=ik)::lcg_r\r\n lcg_r=mod(int(lcg_a*lcg_seed+lcg_c,ik),int(lcg_m,ik))\r\n !Return value between [0,1)\r\n rand_lcg=real(lcg_r,rk)/lcg_m\r\n !Change the value for I\r\n lcg_seed=lcg_r\r\n end function rand_lcg\r\n\r\n !Park-Miller routines\r\n subroutine seed_pm(seed)\r\n implicit none\r\n integer(kind=ik),intent(in)::seed\r\n pm_seed=seed\r\n end subroutine seed_pm\r\n\r\n real(rk) function rand_pm()\r\n implicit none\r\n integer(kind=ik)::k\r\n !Schrage approximations with the xor stuff from course material\r\n pm_seed=xor(pm_seed,123459876)\r\n k=pm_seed/pm_q\r\n pm_seed=pm_a*(pm_seed-k*pm_q)-pm_r*k\r\n !Adjust to correct interval\r\n if (pm_seed<0) then\r\n pm_seed=pm_seed + pm_m\r\n end if\r\n !Set the seed and result interval\r\n rand_pm=real(pm_seed,rk)/pm_m\r\n pm_seed=xor(pm_seed,123459876)\r\n end function rand_pm\r\nend module MC_randoms\r\n", "meta": {"hexsha": "23e845ae856e2de5c5b5571d4884aab3a02d7d7a", "size": 2153, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Nico_Toikka_ex2/p04/mc_randoms.f95", "max_stars_repo_name": "toicca/basics-of-mc", "max_stars_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Nico_Toikka_ex2/p04/mc_randoms.f95", "max_issues_repo_name": "toicca/basics-of-mc", "max_issues_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Nico_Toikka_ex2/p04/mc_randoms.f95", "max_forks_repo_name": "toicca/basics-of-mc", "max_forks_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.2028985507, "max_line_length": 82, "alphanum_fraction": 0.6349280074, "num_tokens": 631, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7692180514612862}} {"text": "PROGRAM FU_example3\n ! Example program for FU_Prec, FU_Files and FU_Statistics modules of ecasglez's FortranUtilities,\n ! showing how to load data from a file and how to perform different types of regressions.\n ! The dataset can be downloaded from: https://ecasglez.github.io/FortranUtilities/page/Examples/Example03/example3.dat\n ! compile using: gfortran example3.f90 -o example3 -I/path/to/include/ -lFortranUtilities -L/path/to/lib/ -O2\n ! before running: export LD_LIBRARY_PATH=/path/to/lib:${LD_LIBRARY_PATH}\n ! run using: ./example3\n ! license: MIT.\n\n USE FU_Prec , ONLY: dp\n USE FU_Files , ONLY: readMatrix\n USE FU_statistics, ONLY: linreg, logreg, expreg, potreg\n\n IMPLICIT NONE\n\n LOGICAL :: exists\n REAL(KIND=dp), DIMENSION(:,:), ALLOCATABLE :: matrix\n REAL(KIND=dp) :: a, b, r2\n\n !First check if the dataset exists.\n INQUIRE(FILE='example3.dat', EXIST=exists)\n IF (.NOT.exists) THEN\n WRITE(*,*) 'ERROR: Dataset named \"example03.dat\" not found.'\n STOP\n END IF\n\n !Load the data in the file.\n CALL readMatrix('example3.dat',matrix)\n\n !Calculate regression parameters and print the results.\n CALL linreg(matrix(:,1),matrix(:,2),a,b,r2)\n WRITE(*,'(A,F6.4,A,F6.4,A,F6.4)') 'Linear regression: f(x) = ',a,' x + ',b,'. Determination coefficient R2 = ',r2\n CALL logreg(matrix(:,1),matrix(:,3),a,b,r2)\n WRITE(*,'(A,F6.4,A,F6.4,A,F6.4)') 'Logarithmic regression: f(x) = ',a,' ln(x) + ',b,'. Determination coefficient R2 = ',r2\n CALL expreg(matrix(:,1),matrix(:,4),a,b,r2)\n WRITE(*,'(A,F6.4,A,F6.4,A,F6.4)') 'Exponential regression: f(x) = ',b,' exp(',a,'x). Determination coefficient R2 = ',r2\n CALL potreg(matrix(:,1),matrix(:,5),a,b,r2)\n WRITE(*,'(A,F6.4,A,F6.4,A,F6.4)') 'Potential regression: f(x) = ',b,' x^',a,'. Determination coefficient R2 = ',r2\n\n DEALLOCATE(matrix)\n\nEND PROGRAM FU_example3\n", "meta": {"hexsha": "e76698e3526a1e0e7970f8559528d364d5a090ae", "size": 1903, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "documentation/Examples/Example03/example3.f90", "max_stars_repo_name": "ecasglez/FortranUtilities", "max_stars_repo_head_hexsha": "a4c88fc190102524f0c669ac20489c5b85a754c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "documentation/Examples/Example03/example3.f90", "max_issues_repo_name": "ecasglez/FortranUtilities", "max_issues_repo_head_hexsha": "a4c88fc190102524f0c669ac20489c5b85a754c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "documentation/Examples/Example03/example3.f90", "max_forks_repo_name": "ecasglez/FortranUtilities", "max_forks_repo_head_hexsha": "a4c88fc190102524f0c669ac20489c5b85a754c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-16T08:04:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-16T08:04:24.000Z", "avg_line_length": 44.2558139535, "max_line_length": 126, "alphanum_fraction": 0.6579085654, "num_tokens": 612, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7691912402535268}} {"text": "! Modified to add f_int and fprime_int for the intersections problem.\n\nmodule functions\n\n implicit none\n real(kind=8) :: epsilon\n save\n\ncontains\n\nreal(kind=8) function f_sqrt(x)\n implicit none\n real(kind=8), intent(in) :: x\n\n f_sqrt = x**2 - 4.d0\n\nend function f_sqrt\n\n\nreal(kind=8) function fprime_sqrt(x)\n implicit none\n real(kind=8), intent(in) :: x\n \n fprime_sqrt = 2.d0 * x\n\nend function fprime_sqrt\n\nreal(kind=8) function f_int(x)\n implicit none\n real(kind=8), intent(in) :: x\n real(kind=8) :: pi\n pi = acos(-1.d0)\n\n f_int = x*cos(pi*x) - (1.d0 - 0.6d0*x**2)\n\nend function f_int\n\n\nreal(kind=8) function fprime_int(x)\n implicit none\n real(kind=8), intent(in) :: x\n real(kind=8) :: pi\n pi = acos(-1.d0)\n \n fprime_int = (cos(pi*x) - x*pi*sin(pi*x)) + 1.2d0*x\n\nend function fprime_int\n\nend module functions\n", "meta": {"hexsha": "e032975c9cb7433289c106795d5bc7c446e3c855", "size": 872, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/2013/solutions/homework3/functions.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/2013/solutions/homework3/functions.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/2013/solutions/homework3/functions.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.44, "max_line_length": 69, "alphanum_fraction": 0.627293578, "num_tokens": 281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7691912358479872}} {"text": " SUBROUTINE ZCOEF(N,ZRT,ZC)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1995-11-29 ZCOEF Krogh Converted from SFTRAN to Fortran 77\nC>> 1987-09-16 ZCOEF Lawson Initial code.\nc Conversion should only be done from \"Z\" to \"C\" for processing to C.\nc--Z replaces \"?\": ?COEF\nC\nc Given N complex numbers, this subr computes the (complex)\nc coefficients of the Nth degree monic polynomial having these\nc numbers as its roots.\nc C. L. Lawson, JPL, 1987 Feb 13.\nc\nc N [In, Integer] Number of given roots and degree of poly.\nc ZRT() [In, DP] The given ith complex root is (ZRT(1,i), ZRT(2,i))\nc ZC() [Out, DP] The (complex) coefficient of z**j will be stored\nc in (ZC(1,N+1-j), ZC(2,N+1-j)) for j = 0, ...,N+1. The high\nc order coeff will be one, i.e.\nc (ZC(1,1), ZC(2,1)) = (1.0, 0.0).\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n INTEGER N, I, J\n DOUBLE PRECISION ZRT(2,N),ZC(2,N+1),FAC(2)\n DOUBLE PRECISION ZCR,ZCI,RTR,RTI,TEM\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n ZC(1,1) = 1.D0\n ZC(2,1) = 0.D0\n ZC(1,2) = -ZRT(1,1)\n ZC(2,2) = -ZRT(2,1)\n DO 20 I = 2,N\n ZCR = ZC(1,I)\n ZCI = ZC(2,I)\n RTR = ZRT(1,I)\n RTI = ZRT(2,I)\n TEM = ZCR*RTR - ZCI*RTI\n ZCI = ZCR*RTI + ZCI*RTR\n ZCR = TEM\n ZC(1,I+1) = -ZCR\n ZC(2,I+1) = -ZCI\n DO 10 J = I,2,-1\n ZCR = ZC(1,J-1)\n ZCI = ZC(2,J-1)\n FAC(1) = ZCR*RTR - ZCI*RTI\n FAC(2) = ZCR*RTI + ZCI*RTR\n ZC(1,J) = ZC(1,J) - FAC(1)\n ZC(2,J) = ZC(2,J) - FAC(2)\n 10 continue\n 20 continue\n RETURN\n END\n", "meta": {"hexsha": "59d199a87712aa901b45d5415fa6edd249f6bb79", "size": 1840, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/zcoef.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/zcoef.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/zcoef.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 36.0784313725, "max_line_length": 72, "alphanum_fraction": 0.5005434783, "num_tokens": 745, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039739, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7691912323195353}} {"text": "COMPUTE ROOTS OF A QUADRATIC FUNCTION - 1956\n READ 100,A,B,C\n 100 FORMAT(3F8.3)\n PRINT 100,A,B,C\n DISC=B**2-4.*A*C\n IF(DISC),1,2,3\n 1 XR=-B/(2.*A)\n XI=SQRT(-DISC)/(2.*A)\n XJ=-XI\n PRINT 311\n PRINT 312,XR,XI,XR,XJ\n 311 FORMAT(13HCOMPLEX ROOTS)\n 312 FORMAT(4HX1=(,2E12.4,6H),X2=(,2E12.4,1H))\n GO TO 999\n 2 X1=-B/(2.*A)\n X2=X1\n PRINT 321\n PRINT 332,X1,X2\n 321 FORMAT(16HEQUAL REAL ROOTS)\n GO TO 999\n 3 X1= (-B+SQRT(DISC)) / (2.*A)\n X2= (-B-SQRT(DISC)) / (2.*A)\n PRINT 331\n PRINT 332,X1,X2\n 331 FORMAT(10HREAL ROOTS)\n 332 FORMAT(3HX1=,E12.5,4H,X2=,E12.5)\n 999 STOP\n", "meta": {"hexsha": "bd3a25fa2daa8bfaee8b761983b931302a25c61a", "size": 656, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Roots-of-a-quadratic-function/Fortran/roots-of-a-quadratic-function-2.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Roots-of-a-quadratic-function/Fortran/roots-of-a-quadratic-function-2.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Roots-of-a-quadratic-function/Fortran/roots-of-a-quadratic-function-2.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 23.4285714286, "max_line_length": 47, "alphanum_fraction": 0.5442073171, "num_tokens": 307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632343454895, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.7691694626615158}} {"text": "!-----------------------------------------------------------------------\r\n \r\n! Code converted using TO_F90 by Alan Miller\r\n! Date: 2000-07-14 Time: 11:42:45\r\n \r\n! PRMFAC\r\n\r\n! DECOMPOSE A NUMBER INTO ITS PRIME FACTORS.\r\n\r\n! CODED AT MADISON ACADEMIC COMPUTING CENTER,\r\n! UNIVERSITY OF WISCONSIN, MADISON\r\n\r\n! FORTRAN 77 VERSION 88.09\r\n\r\n!-----------------------------------------------------------------------\r\n\r\n!--------CALLING SEQUENCE\r\n\r\n! CALL PRMFAC (NUMBER, IOPT, NPRM, IPRM, IEXP, *ERR)\r\n\r\n! NUMBER - INTEGER CONSTANT OR VARIABLE, NUMBER TO BE DECOMPOSED\r\n! INTO PRIME FACTORS. NUMBER .GE. 2.\r\n\r\n! IOPT - INTEGER CONSTANT OR VARIABLE, CONTROLS PRINTING OF RESULTS.\r\n! IOPT .EQ. 0 - RESULTS ARE NOT PRINTED.\r\n! IOPT .NE. 0 - RESULTS ARE PRINTED.\r\n\r\n! NPRM - INTEGER VARIABLE, WILL CONTAIN THE NO. OF DISTINCT PRIME\r\n! FACTORS OF THE NUMBER.\r\n\r\n! IPRM - INTEGER ARRAY OF SIZE AT LEAST 9, WILL CONTAIN THE PRIME\r\n! FACTORS OF THE NUMBER.\r\n\r\n! IEXP - INTEGER ARRAY OF SIZE AT LEAST 9, WILL CONTAIN THE\r\n! EXPONENTS OF THE CORRESPONDING PRIME FACTORS.\r\n\r\n! *ERR - STATEMENT NUMBER PRECEDED WITH AN ASTERISK (*).\r\n! IF AN ERROR CONDITION IS DETECTED, CONTROL IS RETURNED\r\n! TO THAT STATEMENT IN THE CALLING PROGRAM.\r\n! This has been deleted below.\r\n\r\n!--------NOTES\r\n\r\n! (1) UPON RETURN FROM PRMFAC,\r\n! NUMBER = IPRM(1)**IEXP(1) * IPRM(2)**IEXP(2) * ... *\r\n! IPRM(NPRM)**IEXP(NPRM)\r\n\r\n! (2) A NUMBER REPRESENTED BY A (SINGLE-PRECISION) INTEGER\r\n! VALUE ON THE VMS VAX CLUSTER CAN HAVE AT MOST 9 DISTINCT\r\n! PRIME FACTORS. ON MACHINES WHERE THE MAXIMUM INTEGER IS\r\n! LARGER THAN 2**31 - 1, IPRM AND IEXP WOULD, IN GENERAL,\r\n! HAVE TO BE DIMENSIONED LARGER SINCE LARGER NUMBERS MAY\r\n! HAVE MORE THAN 9 DISTINCT PRIME FACTORS.\r\n\r\n!-----------------------------------------------------------------------\r\n\r\nSUBROUTINE prmfac (NUMBER, iopt, nprm, iprm, iexp)\r\n\r\n!--------PARAMETERS\r\n\r\nIMPLICIT NONE\r\n\r\nINTEGER, INTENT(IN) :: NUMBER\r\nINTEGER, INTENT(IN) :: iopt\r\nINTEGER, INTENT(OUT) :: nprm\r\nINTEGER, INTENT(OUT) :: iprm(:)\r\nINTEGER, INTENT(OUT) :: iexp(:)\r\n\r\n!--------LOCAL VARIABLES\r\nINTEGER :: div, indx, isize, j, n, offset, olddiv, quo, rem\r\n\r\n!---------DATA TO OBTAIN TRIAL DIVISORS 2, 3, 5, 7 AND ALL\r\n! HIGHER NUMBERS NOT DIVISIBLE BY 2, 3, 5, 7.\r\nINTEGER, PARAMETER :: base(52) = (/ &\r\n 211, 209, 199, 197, 193, 191, 187, 181, 179, 173, 169, 167, 163, &\r\n 157, 151, 149, 143, 139, 137, 131, 127, 121, 113, 109, 107, 103, &\r\n 101, 97, 89, 83, 79, 73, 71, 67, 61, 59, 53, 47, 43, &\r\n 41, 37, 31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2 /)\r\n\r\n!--------FORMAT TEMPLATE\r\nCHARACTER (LEN=16) :: i4mat = '(1X,A8,1X,--I--)'\r\nCHARACTER (LEN=8) :: txtlst(2) = (/ 'PRIME ', 'EXPONENT' /)\r\n\r\n!--------LOGICAL UNIT FOR STANDARD OUTPUT\r\nINTEGER, PARAMETER :: prn = 6\r\n\r\n\r\n!--------CHECK NUMBER. MUST BE .GE. 2\r\nIF (NUMBER < 2) GO TO 140\r\n\r\n!--------INITIALIZATIONS.\r\nj = 0\r\nn = NUMBER\r\nolddiv = 0\r\noffset = 0\r\nindx = 53\r\n\r\n!--------GET NEXT TRIAL DIVISOR.\r\nDO\r\n indx = indx - 1\r\n IF (indx <= 0) THEN\r\n indx = 48\r\n offset = offset + 210\r\n END IF\r\n div = offset + base(indx)\r\n\r\n!--------TEST TRIAL DIVISOR.\r\n DO\r\n quo = n / div\r\n rem = n - quo*div\r\n IF (rem /= 0) EXIT\r\n\r\n!--------FACTOR FOUND, ZERO REMAINDER.\r\n n = quo\r\n IF (div <= olddiv) THEN\r\n\r\n!--------MULTIPLE FACTOR.\r\n iexp(j) = iexp(j) + 1\r\n CYCLE\r\n END IF\r\n\r\n!--------NEW FACTOR.\r\n j = j + 1\r\n iprm(j) = div\r\n iexp(j) = 1\r\n olddiv = div\r\n END DO\r\n\r\n!--------NOT A FACTOR, POSITIVE REMAINDER. CHECK DIVISOR SIZE.\r\n IF (div >= quo) EXIT\r\nEND DO\r\n\r\n!--------FINISHED, WHAT ISN'T FACTORED IS A PRIME (OR 1).\r\nIF (n > 1) THEN\r\n j = j + 1\r\n iexp(j) = 1\r\n iprm(j) = n\r\nEND IF\r\nnprm = j\r\n\r\n!--------PRINT RESULTS IF REQUESTED.\r\nIF (iopt == 0) GO TO 130\r\nWRITE (prn,70)\r\n70 FORMAT ( / ' ', 7('----------') )\r\nIF (nprm /= 1 .OR. iexp(1) /= 1) GO TO 90\r\n\r\n!--------NUMBER IS PRIME\r\nWRITE (prn,80) NUMBER\r\n80 FORMAT ( / t3, i12, ' IS PRIME' )\r\nGO TO 120\r\n\r\n!--------NUMBER IS COMPOSITE\r\n90 WRITE (prn,100) NUMBER\r\n100 FORMAT ( / t3, i12, ' FACTORS AS FOLLOWS' / )\r\n\r\n!--------DETERMINE SUITABLE FORMAT FOR FACTORS AND EXPONENTS AND PRINT.\r\nisize = LOG10 (REAL(iprm(nprm)) + 0.5D0)\r\nisize = MAX (6,isize+3)\r\nWRITE (i4mat(11:12), 110) nprm\r\n110 FORMAT (i2.2)\r\nWRITE (i4mat(14:15), 110) isize\r\nWRITE (prn, i4mat) txtlst(1), iprm(1:nprm)\r\nWRITE (prn, i4mat) txtlst(2), iexp(1:nprm)\r\n\r\n120 WRITE (prn,70)\r\n\r\n!--------NORMAL EXIT\r\n130 RETURN\r\n\r\n!--------ERROR, ISSUE MESSAGE AND TAKE ERROR EXIT.\r\n140 WRITE (prn,150) NUMBER\r\n150 FORMAT (' *** ERROR IN PRMFAC, NUMBER =', i12, ', NUMBER MUST BE >= 2')\r\n\r\n!--------ERROR EXIT\r\nRETURN\r\n\r\n!--------END OF PRMFAC\r\nEND SUBROUTINE prmfac\r\n\r\n\r\n\r\nPROGRAM find_prime_factors\r\nIMPLICIT NONE\r\n\r\nINTERFACE\r\n SUBROUTINE prmfac (NUMBER, iopt, nprm, iprm, iexp)\r\n IMPLICIT NONE\r\n INTEGER, INTENT(IN) :: NUMBER\r\n INTEGER, INTENT(IN) :: iopt\r\n INTEGER, INTENT(OUT) :: nprm\r\n INTEGER, INTENT(OUT) :: iprm(:)\r\n INTEGER, INTENT(OUT) :: iexp(:)\r\n END SUBROUTINE prmfac\r\nEND INTERFACE\r\n\r\nINTEGER :: iexp(10), iopt, iprm(10), nprm, NUMBER\r\n\r\nDO\r\n iopt = 1\r\n WRITE(*, '(a)', ADVANCE='NO') ' Enter number to be factored: '\r\n READ(*, *) NUMBER\r\n CALL prmfac (NUMBER, iopt, nprm, iprm, iexp)\r\n WRITE(*, *)\r\nEND DO\r\n\r\nSTOP\r\nEND PROGRAM find_prime_factors\r\n", "meta": {"hexsha": "9571ba27c13fbb385a2662fcbb3b4c32e5ee538e", "size": 5536, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/primefac.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/primefac.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/primefac.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 26.6153846154, "max_line_length": 76, "alphanum_fraction": 0.5543713873, "num_tokens": 1896, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897426182321, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7691656831203171}} {"text": "! Runga-Kutta method\n\nprogram RK4\nimplicit none\ndouble precision h,w,exact,diff,f,a,b,alpha,t,k1,k2,k3,k4\ninteger i,N\nwrite(*,*) 'enter a,b'\nread(*,*) a,b\nwrite(*,*) 'enter N'\nread(*,*) N\nwrite(*,*) 'enter alpha'\nread(*,*) alpha\nh=(b-a)/dfloat(N)\nt=a\nw=alpha\ndo i=1,n\n k1=h*f(t,w)\n k2=h*f(t+h/2.d0,w+k1/2.d0)\n k3=h*f(t+h/2.d0,w+k2/2.d0)\n k4=h*f(t+h,w+k3)\n w=w+(k1+2.d0*(k2+k3)+k4)/6.d0\n t=a+dfloat(i)*h\n diff=dabs(exact(t)-w)\n write(8,*) t,diff\n write(10,*) t,w,exact(t),diff\nenddo\nwrite(9,*) h,diff\nstop\nend program RK4\n\nfunction exact(t)\ndouble precision t,exact,x\nx=2.d0*t\nexact=(.5d0)*(1/(t**2.d0))*(4+dcos(2.d0)-dcos(x))\nreturn\nend function exact\n\nfunction f(t,y)\ndouble precision t,y,f,z,x\nx=2*t\nz=x*y\nf=(1/(t**2))*(dsin(x) - z)\nreturn\nend function f\n\n\n", "meta": {"hexsha": "5b512f87abe306bc550af466e95f0e46a19764c6", "size": 768, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "RungaKutta.f90", "max_stars_repo_name": "whisker-rebellion/Fortran", "max_stars_repo_head_hexsha": "65c0e064bcc92f33bc78cc89220a0298b3ee96be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "RungaKutta.f90", "max_issues_repo_name": "whisker-rebellion/Fortran", "max_issues_repo_head_hexsha": "65c0e064bcc92f33bc78cc89220a0298b3ee96be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "RungaKutta.f90", "max_forks_repo_name": "whisker-rebellion/Fortran", "max_forks_repo_head_hexsha": "65c0e064bcc92f33bc78cc89220a0298b3ee96be", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.3404255319, "max_line_length": 57, "alphanum_fraction": 0.6171875, "num_tokens": 344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763573, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7691616234370907}} {"text": "SUBROUTINE BeachGen3Dver2(h,h0,h1,lx,ly,x,y,Nx,Ny)\n! By Allan P. Engsig-Karup.\nUSE Precision\nUSE Constants\nIMPLICIT NONE\nINTEGER :: Nx,Ny,i,j\nREAL(KIND=long) :: h(Nx,Ny), h0, h1, l, x(Nx), y(Ny), xi, lx, ly\n\nIF (lx /= ly .OR. ABS(lx-one)>1e-10) THEN\n\tPRINT*,'Error: Lx and Ly have to be equal to size 1 for the chosen test case.'\n\tSTOP\nELSE\n\tl = lx\nENDIF\n\n! Initialize:\nh = zero\nDO j = 1,Ny\n\tDO i = 1,Nx\n IF (SQRT(x(i)**2 + y(j)**2) > one) THEN\n xi = one\n ELSE\n xi = SQRT(x(i)**2 + y(j)**2)\n ENDIF\n\t IF (xi > zero .AND. xi < l) THEN\n\t h(i,j) = h0 - (h0-h1)/two*(one+TANH(SIN(pi*(xi-l/two)/l)/(one-(two*(xi-l/two)/l)**2)))\n\t\tELSE IF (xi>=l) THEN\n\t\t\th(i,j) = h1\n\t\tELSE\n\t\t h(i,j) = h0\n\t\tENDIF\n END DO\nEND DO\nEND SUBROUTINE BeachGen3Dver2\n", "meta": {"hexsha": "d258c0cb80b1625dc2414182c53e8a7e0b3a3911", "size": 798, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/analyticalsolutions/beachgen3D.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/analyticalsolutions/beachgen3D.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/analyticalsolutions/beachgen3D.f90", "max_forks_repo_name": "apengsigkarup/OceanWave3D", "max_forks_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-01T12:17:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T16:23:37.000Z", "avg_line_length": 22.8, "max_line_length": 97, "alphanum_fraction": 0.5538847118, "num_tokens": 333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474220263198, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.769094687857309}} {"text": " SUBROUTINE CHEBFT(A,B,C,N,FUNC)\n REAL*8 PI\n PARAMETER (NMAX=50, PI=3.141592653589793D0)\n REAL*8 SUM\n DIMENSION C(N),F(NMAX)\n BMA=0.5*(B-A)\n BPA=0.5*(B+A)\n DO 11 K=1,N\n Y=COS(PI*(K-0.5)/N)\n F(K)=FUNC(Y*BMA+BPA)\n11 CONTINUE\n FAC=2./N\n DO 13 J=1,N\n SUM=0.D0\n DO 12 K=1,N\n SUM=SUM+F(K)*COS((PI*(J-1))*((K-0.5D0)/N))\n12 CONTINUE\n C(J)=FAC*SUM\n13 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "a23b58eff1a637971684cb02697b269e3d620dfa", "size": 479, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/source/chebft.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/source/chebft.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/source/chebft.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.7727272727, "max_line_length": 52, "alphanum_fraction": 0.4739039666, "num_tokens": 203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172601537141, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7690774297716937}} {"text": "\tFUNCTION PR_MIXR ( dwpc, pres )\nC************************************************************************\nC* PR_MIXR\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes MIXR from DWPC and PRES. The following\t*\nC* equation is used:\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* MIXR = .62197 * ( e / ( PRES - e ) ) * 1000.\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* e = VAPR * corr\t\t\t\t\t*\nC* corr = (1.001 + ( ( PRES - 100. ) / 900. ) * .0034)\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* University of Wisconsin green sheet.\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function can also be used for the following computations:\t*\nC* MIXS from TMPC and PRES\t\t\t\t\t*\nC* SMXR from DWPC and PALT\t\t\t\t\t*\nC* SMXS from TMPC and PALT\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_MIXR ( DWPC, PRES )\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tDWPC\t\tREAL \t\tDewpoint in Celsius\t\t*\nC*\tPRES\t\tREAL \t\tPressure in millibars\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_MIXR\t\tREAL\t\tMixing ratio in g/kg\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* P. Kocin/914\t\t1980\tOriginal source code\t\t\t*\nC* M. Goodman/RDS\t3/84\tAdded PR_TMCK\t\t\t\t*\nC* I. Graffman/RDS\t12/84\tChanged .622 to .62197\t\t\t*\nC* I. Graffman/RDS\t12/87\tGEMPAK4\t\t\t\t\t*\nC* G. Huffman/GSC\t7/88\tDocumentation; check missing VAPR,\t*\nC*\t\t\t\tlarge E at low PRES\t\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\nC*\tCheck for missing data.\nC\n\tIF ( ERMISS ( dwpc ) .or. ERMISS ( pres ) ) THEN\n\t PR_MIXR = RMISSD\n\t ELSE\nC\nC*\t Calculate vapor pressure.\nC\n\t vapr = PR_VAPR ( dwpc )\n\t IF ( ERMISS ( vapr ) ) THEN\n\t PR_MIXR = RMISSD\n\t\tRETURN\n\t END IF\nC\nC*\t CORR is a correction to the vapor pressure\nC*\t since the atmosphere is not an ideal gas.\nC\n\t corr = (1.001 + (( pres - 100.) / 900.) * .0034)\n\t e = corr * vapr\nC\nC*\t Test for unphysical case of large E at low PRES.\nC\n\t IF ( e .gt. ( .5 * pres ) ) THEN\n PR_MIXR = RMISSD\n\t ELSE\nC\nC*\t Calculate mixing ratio.\nC\n\t PR_MIXR = .62197 * (e / (pres - e)) * 1000.\n\t END IF\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "7a0d784d3bf803bd81d7d228614d444775ebecd5", "size": 2193, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prmixr.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/prmcnvlib/pr/prmixr.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/prmcnvlib/pr/prmixr.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 29.6351351351, "max_line_length": 73, "alphanum_fraction": 0.4751481988, "num_tokens": 726, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172587090974, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7690774242569833}} {"text": "program intrinsics_19\n! Test intrinsics both declarations and executable statements.\n! Single and double precision, real only.\ninteger, parameter :: dp = kind(0.d0)\n\nreal, parameter :: &\n s1 = abs(-0.5), &\n s2 = exp(0.5), &\n s3 = log(0.5), &\n s4 = erf(0.5), &\n s5 = erfc(0.5), &\n s6 = sqrt(0.5), &\n s7 = gamma(0.5), &\n s8 = atan2(0.5, 0.5), &\n s9 = log_gamma(0.5), &\n s10 = log10(0.5)\n\ninteger, parameter :: &\n s11 = nint(3.6), &\n s12 = floor(3.6), &\n s13 = nint(-3.6), &\n s14 = floor(-3.6)\n\nreal(dp), parameter :: &\n d1 = abs(-0.5_dp), &\n d2 = exp(0.5_dp), &\n d3 = log(0.5_dp), &\n d4 = erf(0.5_dp), &\n d5 = erfc(0.5_dp), &\n d6 = sqrt(0.5_dp), &\n d7 = gamma(0.5_dp), &\n d8 = atan2(0.5_dp, 0.5_dp), &\n d9 = log_gamma(0.5_dp), &\n d10 = log10(0.5_dp)\n\ninteger, parameter :: &\n d11 = nint(3.6_dp), &\n d12 = floor(3.6_dp), &\n d13 = nint(-3.6_dp), &\n d14 = floor(-3.6_dp)\n\nreal :: x, x2\nreal(dp) :: y, y2\n\nx = 0.5\ny = 0.5_dp\nx2 = 3.6\ny2 = 3.6_dp\n\nprint *, abs(-0.5), abs(-0.5_dp), s1, d1, abs(-x), abs(-y)\nprint *, exp(0.5), exp(0.5_dp), s2, d2, exp(x), exp(y)\nprint *, log(0.5), log(0.5_dp), s3, d3, log(x), log(y)\nprint *, erf(0.5), erf(0.5_dp), s4, d4, erf(x), erf(y)\nprint *, erfc(0.5), erfc(0.5_dp), s5, d5, erfc(x), erfc(y)\nprint *, sqrt(0.5), sqrt(0.5_dp), s6, d6, sqrt(x), sqrt(y)\nprint *, gamma(0.5), gamma(0.5_dp), s7, d7, gamma(x), gamma(y)\nprint *, atan2(0.5, 0.5), atan2(0.5_dp, 0.5_dp), s8, d8, atan2(x,x), atan2(y,y)\nprint *, log_gamma(0.5), log_gamma(0.5_dp), s9, d9, log_gamma(x), log_gamma(y)\nprint *, log10(0.5), log10(0.5_dp), s10, d10, log10(x), log10(y)\nprint *, nint(3.6), nint(3.6_dp), s11, d11, nint(x2), nint(y2)\nprint *, floor(3.6), floor(3.6_dp), s12, d12, floor(x2), floor(y2)\nprint *, nint(-3.6), nint(-3.6_dp), s13, d13, nint(-x2), nint(-y2)\nprint *, floor(-3.6), floor(-3.6_dp), s14, d14, floor(-x2), floor(-y2)\n\nend\n", "meta": {"hexsha": "ab61f0924b40848ddcacb37ada5344d2e657c6aa", "size": 1927, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/intrinsics_19.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/intrinsics_19.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/intrinsics_19.f90", "max_forks_repo_name": "Thirumalai-Shaktivel/lfortran", "max_forks_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-03-28T19:40:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:28:55.000Z", "avg_line_length": 29.196969697, "max_line_length": 79, "alphanum_fraction": 0.545407369, "num_tokens": 878, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392797, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.769031736256793}} {"text": "ELEMENTAL FUNCTION func_rising_factorial(x, n) result(ans)\n ! NOTE: See https://en.wikipedia.org/wiki/Falling_and_rising_factorials\n\n USE ISO_FORTRAN_ENV\n\n IMPLICIT NONE\n\n ! Declare inputs/outputs ...\n REAL(kind = REAL64) :: ans\n REAL(kind = REAL64), INTENT(in) :: n\n REAL(kind = REAL64), INTENT(in) :: x\n\n ! Set value ...\n ans = GAMMA(x + n) / GAMMA(x)\nEND FUNCTION func_rising_factorial\n", "meta": {"hexsha": "0aaa9853a459c9eedc8a0ed26e12ac8f5075ffad", "size": 560, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mod_safe/func_rising_factorial.f90", "max_stars_repo_name": "Guymer/fortranlib", "max_stars_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-28T02:05:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-16T16:50:21.000Z", "max_issues_repo_path": "mod_safe/func_rising_factorial.f90", "max_issues_repo_name": "Guymer/fortranlib", "max_issues_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-06-17T16:49:20.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-11T18:47:36.000Z", "max_forks_repo_path": "mod_safe/func_rising_factorial.f90", "max_forks_repo_name": "Guymer/fortranlib", "max_forks_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-11T04:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-11T04:51:33.000Z", "avg_line_length": 35.0, "max_line_length": 86, "alphanum_fraction": 0.4946428571, "num_tokens": 121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392797, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.7690317281063227}} {"text": " real function SCSHMM (X)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1994-10-20 SCSHMM Krogh Changes to use M77CON\nc>> 1993-05-07 SCSHMM WVSnyder JPL Initial code\nc\nc Compute cosh(x) - 1 - x**2 using a rational approximation when\nc abs(x) is less than 2.7, else use the Fortran intrinsic function.\nc\nc--S replaces \"?\": ?CSHMM\n real ZP3, ZP2, ZP1, ZQ4, ZQ3, ZQ2, ZQ1, X, XS\n parameter ( ZP3 = 5.59297116264720E-07 )\n parameter ( ZP2 = 1.77943488030894E-04 )\n parameter ( ZP1 = 1.69800461894792E-02 )\n parameter ( ZQ4 = 1.33412535492375E-09 * 24.0e0 )\n parameter ( ZQ3 = -5.80858944138663E-07 * 24.0e0 )\n parameter ( ZQ2 = 1.27814964403863E-04 * 24.0e0 )\n parameter ( ZQ1 = -1.63532871439181E-02 * 24.0e0 )\nc DATA ZP3/5.59297116264720E-07/,\nc * ZP2/1.77943488030894E-04/,\nc * ZP1/1.69800461894792E-02/,\nc * ZQ4/1.33412535492375E-09/,\nc * ZQ3/-5.80858944138663E-07/,\nc * ZQ2/1.27814964403863E-04/,\nc * ZQ1/-1.63532871439181E-02/\n xs = x * x\n if (xs .lt. 7.29e0) then\n scshmm = ((((zp3*xs+zp2)*xs+zp1)*xs+1.0e0)*xs*xs)/\n * ((((zq4*xs+zq3)*xs+zq2)*xs+zq1)*xs+24.0e0)\n else\n scshmm = cosh(x) - 1.0e0 - 0.5e0*xs\n end if\n return\n end\n", "meta": {"hexsha": "cc21891cbb8e957b44b1995acb28e55eeeb8b753", "size": 1419, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/scshmm.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/scshmm.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/scshmm.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 39.4166666667, "max_line_length": 71, "alphanum_fraction": 0.6025369979, "num_tokens": 598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370313, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.7690317266245336}} {"text": "module rationals_mod\n use, intrinsic :: iso_fortran_env\n implicit none\n\n private\n type, public :: rational\n private\n integer :: num = 1, denom = 1, sign = 1\n end type rational\n\n interface rational\n module procedure rat_create\n end interface rational\n\n interface operator(+)\n module procedure rat_add\n end interface\n\n interface operator(*)\n module procedure rat_mul, int_rat_mul\n end interface\n\n public :: rat_print, operator(+), operator(*)\n\ncontains\n\n type(rational) function rat_create(n, d)\n implicit none\n integer, value :: n, d\n integer :: n_act, d_act, g\n if (d == 0) then\n write (unit=error_unit, fmt='(A)') &\n \"# error: denominator must be non-zero\"\n stop\n end if\n if (n*d < 0) then\n rat_create%sign = -1\n else\n rat_create%sign = 1\n end if\n n = abs(n)\n d = abs(d)\n g = gcd(n, d)\n rat_create%num = n/g\n rat_create%denom = d/g\n end function rat_create\n\n type(rational) function rat_add(a, b)\n implicit none\n type(rational), intent(in) :: a, b\n rat_add = rat_create(a%sign*a%num*b%denom + b%sign*b%num*a%denom, &\n a%denom*b%denom)\n end function rat_add\n\n type(rational) function rat_mul(a, b)\n implicit none\n type(rational), intent(in) :: a, b\n rat_mul = rat_create(a%sign*a%num*b%sign*b%num, a%denom*b%denom)\n end function rat_mul\n\n type(rational) function int_rat_mul(a, b)\n implicit none\n integer, intent(in) :: a\n type(rational), intent(in) :: b\n int_rat_mul = rat_create(a*b%sign*b%num, b%denom)\n end function int_rat_mul\n\n subroutine rat_print(a)\n implicit none\n type(rational), intent(in) :: a\n if (a%sign > 0) then\n write (*, \"(I0, '/', I0)\") a%num, a%denom\n else\n write (*, \"('-', I0, '/', I0)\") a%num, a%denom\n end if\n end subroutine rat_print\n\n integer function gcd(x, y)\n implicit none\n integer, value :: x, y\n x = abs(x)\n y = abs(y)\n do while (x /= y)\n if (x > y) then\n x = x - y\n else if (y > x) then\n y = y - x\n end if\n end do\n gcd = x\n end function gcd\n\nend module rationals_mod\n", "meta": {"hexsha": "66315f2d0b53b82f07835cd0181c2f2170cbe94a", "size": 2424, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/OOProgramming/rationals_mod.f90", "max_stars_repo_name": "stijnvanhoey/training-material", "max_stars_repo_head_hexsha": "d8e23c2aefaaafbd6a6d5e059147831c651f21ec", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fortran/OOProgramming/rationals_mod.f90", "max_issues_repo_name": "stijnvanhoey/training-material", "max_issues_repo_head_hexsha": "d8e23c2aefaaafbd6a6d5e059147831c651f21ec", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran/OOProgramming/rationals_mod.f90", "max_forks_repo_name": "stijnvanhoey/training-material", "max_forks_repo_head_hexsha": "d8e23c2aefaaafbd6a6d5e059147831c651f21ec", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-07T22:45:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-07T22:45:34.000Z", "avg_line_length": 25.7872340426, "max_line_length": 75, "alphanum_fraction": 0.5309405941, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771661, "lm_q2_score": 0.8311430562234878, "lm_q1q2_score": 0.7689984593877293}} {"text": "module plotter_functions\n!USE Plotter\n\timplicit none\n\tcontains\n\t!Здесь хранятся функции.\n\tfunction first_function(first_input) result (first_output)\n\t\timplicit none\n\t\treal, intent(in) :: first_input\n\t\treal :: first_output\n\t\tfirst_output=sin(first_input)\n\tend function first_function\n\t\t\n\tfunction second_function(second_input) result (second_output)\n\t\timplicit none\n\t\treal, intent(in) :: second_input\n\t\treal :: second_output\n\t\tsecond_output = cos(second_input)\n\tend function second_function\n\t\n\tfunction third_function(third_input) result(third_output)\n\t\timplicit none\n\t\treal,intent(in) :: third_input\n\t\treal :: third_output\n\t\tthird_output=third_input\n\tend function third_function\n\t\n\tfunction fourth_function(fourth_input) result(fourth_output)\n\t\timplicit none\n\t\treal,intent(in) :: fourth_input\n\t\treal :: fourth_output\n\t\tfourth_output = fourth_input**2\n\tend function fourth_function\n\t\n\tfunction afourth_function(fourth_input) result(fourth_output)\n\t\timplicit none\n\t\treal,intent(in) :: fourth_input\n\t\treal :: fourth_output\n\t\tfourth_output = -fourth_input**2\n\tend function afourth_function\n\t\n\tfunction fifth_function(fifth_input) result (fifth_output)\n\t\timplicit none\n\t\treal, intent(in) :: fifth_input\n\t\treal :: fifth_output\n\t\tfifth_output=1/fifth_input\n\tend function fifth_function\n\t\n\tfunction first_surface(a,b) result(c)\n\t\timplicit none\n\t\treal,intent(in) :: a,b\n\t\treal :: c\n\t\tc = a*a+b*b\n\tend function first_surface\n\t\n\tfunction second_surface(a,b) result(c)\n\t\timplicit none\n\t\treal,intent(in) :: a,b\n\t\treal :: c\n\t\tc = (a*a-b*b)/4\n\tend function second_surface\nend module plotter_functions\n", "meta": {"hexsha": "186f2359196f2fb4cd6e8ff2f998d95cfd85b278", "size": 1586, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Plotter/tst/plotter_functions.f90", "max_stars_repo_name": "LibPlotter/Plotter", "max_stars_repo_head_hexsha": "b47ee424af82dacda82456e695b8716f96cd09c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Plotter/tst/plotter_functions.f90", "max_issues_repo_name": "LibPlotter/Plotter", "max_issues_repo_head_hexsha": "b47ee424af82dacda82456e695b8716f96cd09c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Plotter/tst/plotter_functions.f90", "max_forks_repo_name": "LibPlotter/Plotter", "max_forks_repo_head_hexsha": "b47ee424af82dacda82456e695b8716f96cd09c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.5806451613, "max_line_length": 62, "alphanum_fraction": 0.7673392182, "num_tokens": 416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299591537478, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7689984443510185}} {"text": "*\n* Program quad - calculate the quadratic formula roots\n*\n* Written by - C. Severance 12Mar92\n*\n REAL A,B,C,DET,ROOT1,ROOT2\n*\n PRINT *,'Enter A,B,C -'\n READ *,A,B,C\n*\n DET = SQRT( B*B - 4 * A * C )\n ROOT1 = ( -1.0*B + DET ) / ( 2 * A )\n ROOT2 = ( -1.0*B - DET ) / ( 2 * A )\n*\n PRINT *,'ROOT1 = ',ROOT1\n PRINT *,'ROOT2 = ',ROOT2\n*\n END\n", "meta": {"hexsha": "b3ba7fac58106508f8e03df19381f4c4b9f5d8c9", "size": 383, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "archive/2000-eecs280/examples/examples.ftn/programs/quad.f", "max_stars_repo_name": "yashajoshi/cc4e", "max_stars_repo_head_hexsha": "dd166f7e70d4111945054b8cb39483eb8dfb591b", "max_stars_repo_licenses": ["Apache-2.0", "CC-BY-4.0"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2020-01-05T04:46:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T09:36:02.000Z", "max_issues_repo_path": "archive/2000-eecs280/examples/examples.ftn/programs/quad.f", "max_issues_repo_name": "yashajoshi/cc4e", "max_issues_repo_head_hexsha": "dd166f7e70d4111945054b8cb39483eb8dfb591b", "max_issues_repo_licenses": ["Apache-2.0", "CC-BY-4.0"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2021-07-01T01:19:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-07T01:30:45.000Z", "max_forks_repo_path": "archive/2000-eecs280/examples/examples.ftn/programs/quad.f", "max_forks_repo_name": "yashajoshi/cc4e", "max_forks_repo_head_hexsha": "dd166f7e70d4111945054b8cb39483eb8dfb591b", "max_forks_repo_licenses": ["Apache-2.0", "CC-BY-4.0"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2020-12-27T19:57:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T13:01:36.000Z", "avg_line_length": 20.1578947368, "max_line_length": 54, "alphanum_fraction": 0.4725848564, "num_tokens": 144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920387, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7689984407025164}} {"text": "MODULE EIGEN \n\nCONTAINS \n FUNCTION OUTER(A, B) \n IMPLICIT NONE \n\n REAL, DIMENSION(:) :: A, B \n REAL, DIMENSION(SIZE(A), SIZE(B)) :: OUTER\n\n ! c_ij = a_i * b_j \n OUTER = SPREAD(A, DIM=2, NCOPIES=SIZE(B)) * SPREAD(B, DIM=1, NCOPIES=SIZE(A))\n END FUNCTION OUTER\n\n SUBROUTINE TRIDIAGONAL(A, B, C, X, R) \n IMPLICIT NONE \n\n REAL, DIMENSION(:), INTENT(IN) :: A, B, C, R\n REAL, DIMENSION(:), INTENT(OUT) :: X \n\n REAL, DIMENSION(:), ALLOCATABLE :: beta\n INTEGER :: i, NSIZE\n\n ! initialization \n NSIZE = SIZE(B)\n ALLOCATE(beta(NSIZE))\n\n beta(1) = B(1) \n X(1) = R(1) \n\n ! Forward elimination of x_i \n DO i = 2, NSIZE \n beta(i) = B(i) - A(i) * C(i-1) / beta(i-1)\n X(i) = R(i) - A(i) * X(i-1) / beta(i-1)\n END DO \n\n ! Backward substitution \n X(NSIZE) = X(NSIZE) / beta(NSIZE) \n DO i = NSIZE - 1, 1, -1 \n X(i) = (X(i) - C(i) * X(i+1)) / beta(i)\n END DO \n\n DEALLOCATE(beta)\n END SUBROUTINE TRIDIAGONAL \n\nEND MODULE EIGEN \n", "meta": {"hexsha": "a504a8db1dbd0cadb8fa1ed9ff01d53ec7239315", "size": 1160, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "eigen.f90", "max_stars_repo_name": "vitduck/numerical-recipe", "max_stars_repo_head_hexsha": "0d025bd6c9a5b45af72c7691fb01cbfecf075ca6", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "eigen.f90", "max_issues_repo_name": "vitduck/numerical-recipe", "max_issues_repo_head_hexsha": "0d025bd6c9a5b45af72c7691fb01cbfecf075ca6", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "eigen.f90", "max_forks_repo_name": "vitduck/numerical-recipe", "max_forks_repo_head_hexsha": "0d025bd6c9a5b45af72c7691fb01cbfecf075ca6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.2173913043, "max_line_length": 85, "alphanum_fraction": 0.4637931034, "num_tokens": 384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.7689268727899224}} {"text": "program solve3x3\n implicit none\n real a(3,3),b(3),det,num,x1,x2,x3\n a(1,1)=6;a(1,2)=4;a(1,3)=-5;b(1)=9;\n a(2,1)=1;a(2,2)=-8;a(2,3)=2;b(2)=-3;\n a(3,1)=4;a(3,2)=1;a(3,3)=-10;b(3)=12;\n\n call determinant33(a(1,1),a(1,2),a(1,3),det)\n call determinant33(b,a(1,2),a(1,3),num)\n x1=num/det\n call determinant33(a(1,1),b,a(1,3),num)\n x2=num/det\n call determinant33(a(1,1),a(1,2),b,num)\n x3=num/det\n print *,'X1,X2,X3=',x1,x2,x3\nend program solve3x3\n\nsubroutine determinant33(u,v,w,det)\n implicit none\n real :: u(3),v(3),w(3),det\n det=u(1)*v(2)*w(3)+u(2)*v(3)*w(1)+u(3)*v(1)*w(2) &\n -w(1)*v(2)*u(3)-w(2)*v(3)*u(1)-w(3)*v(1)*u(2)\nend subroutine determinant33", "meta": {"hexsha": "500bdeaa1556faeb8f0714ef39edc80d63b149c4", "size": 699, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "90and95/solveLinear/solve3x3.f95", "max_stars_repo_name": "terasakisatoshi/Fortran", "max_stars_repo_head_hexsha": "f2d7c94ad7a7efcd6545800b54674452d45a98f3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "90and95/solveLinear/solve3x3.f95", "max_issues_repo_name": "terasakisatoshi/Fortran", "max_issues_repo_head_hexsha": "f2d7c94ad7a7efcd6545800b54674452d45a98f3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "90and95/solveLinear/solve3x3.f95", "max_forks_repo_name": "terasakisatoshi/Fortran", "max_forks_repo_head_hexsha": "f2d7c94ad7a7efcd6545800b54674452d45a98f3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.3913043478, "max_line_length": 54, "alphanum_fraction": 0.547925608, "num_tokens": 358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778073288128, "lm_q2_score": 0.8031738034238806, "lm_q1q2_score": 0.7688604574455553}} {"text": "module loglikelihood_module\n use utils_module, only: dp\n\n real(dp) :: normalisation\n\n ! Parameters of the rosenbrock function\n real(dp), parameter :: a = 1d0\n real(dp), parameter :: b = 1d2\n real(dp), parameter :: pi = 4d0*atan(1d0) ! \\pi in double precision\n\n ! number of dimensions\n integer :: nDims\n\n contains\n\n !> Upside down [Rosenbrock function](http://en.wikipedia.org/wiki/Rosenbrock_function).\n !!\n !! \\f[ -\\log\\mathcal{L}(\\theta) = \\sum_{i=1}^{N-1} (a-\\theta_i)^2+ b (\\theta_{i+1} -\\theta_i^2 )^2 \\f]\n !!\n !! This is the industry standard 'Banana'. It is useful for testing whether the\n !! algorithm is capable of navigating a curving degenerate space and able to\n !! find the global maximum. As is conventional, we choose \\f$a=1\\f$ and\n !! \\f$b=100\\f$\n !!\n !! It is only valid in nDims>2.\n !!\n !! To be precise, we choose our log likelihood as the negative of the 'true'\n !! Rosenbrock function, as our algorithm is a maximiser.\n !!\n !! In addition, we add an offset to normalise the loglikelihood so that in\n !! 2D it should integrate to 1. (There is no analytic formula for ND).\n !! \n !! The global maximum is atop a long, narrow, parabolic shaped ridge.\n !!\n !! dimension | extrema\n !! ----------|------\n !! \\f$ 2 \\f$ | One maximum at \\f$(1,1)\\f$\n !! \\f$ 3 \\f$ | One maximum at \\f$(1,1,1)\\f$ \n !! \\f$4-7\\f$ | One global maximum at \\f$(1,\\ldots,1)\\f$, one local near \\f$(-1,1,\\ldots,1)\\f$\n !!\n !! \\f$(1,\\ldots,1)\\f$ is always the\n !! global maximum, but it is unclear analytically how many (if any) local maxima there\n !! are elsewhere in dimensions higher than 7.\n !!\n function loglikelihood(theta,phi)\n implicit none\n real(dp), intent(in), dimension(:) :: theta !> Input parameters\n real(dp), intent(out), dimension(:) :: phi !> Output derived parameters\n real(dp) :: loglikelihood ! loglikelihood value to output\n\n\n ! Normalisation for 2D\n loglikelihood = normalisation\n\n ! Sum expressed with fortran intrinsics\n loglikelihood = loglikelihood - sum( (a-theta(1:nDims-1))**2 + b*(theta(2:nDims) - theta(1:nDims-1)**2)**2 )\n\n end function loglikelihood\n\n subroutine setup_loglikelihood(settings)\n use settings_module, only: program_settings\n implicit none\n type(program_settings), intent(in) :: settings\n\n ! Get the number of dimensions from the settings variable\n nDims = settings%nDims\n\n ! \n normalisation = -0.5d0 * log( pi**nDims / det(nDims) )\n\n end subroutine setup_loglikelihood\n\n function det(n)\n integer,intent(in) :: n\n real(dp) :: det\n\n det = abs(-2d0*b*recur(n-1) - 16*b*b*recur(n-2))\n\n end function\n\n recursive function recur(n) result(ans)\n integer,intent(in) :: n\n real(dp) :: ans\n\n if(n<=0) then\n ans = 0d0\n return\n else if(n==1) then\n ans = 1d0\n return\n else\n ans = (-2d0-10d0*b) * recur(n-1) - 16d0*b*b * recur(n-2)\n end if\n\n end function recur\n\nend module loglikelihood_module\n", "meta": {"hexsha": "b21552839267c138b435838cf1c639f70aa91552", "size": 3227, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Externals/PolyChord/likelihoods/examples/rosenbrock.f90", "max_stars_repo_name": "yuanfangtardis/vscode_project", "max_stars_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Externals/PolyChord/likelihoods/examples/rosenbrock.f90", "max_issues_repo_name": "yuanfangtardis/vscode_project", "max_issues_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Externals/PolyChord/likelihoods/examples/rosenbrock.f90", "max_forks_repo_name": "yuanfangtardis/vscode_project", "max_forks_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-15T12:22:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T12:22:30.000Z", "avg_line_length": 32.9285714286, "max_line_length": 118, "alphanum_fraction": 0.5897118066, "num_tokens": 935, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012701768145, "lm_q2_score": 0.8128673155708976, "lm_q1q2_score": 0.7688109395521725}} {"text": "module loglikelihood_module\n use utils_module, only: dp\n\n contains\n\n !> Twin gaussian peaks likelihood with mean mu(:) and an uncorrelated covariance sigma(:).\n !! \n !! It is normalised so that it should output an evidence of 1.0 for\n !! effectively infinite priors.\n !!\n !! The mean is set at 0.5 by default, apart from the x and y directions, where\n !! they are separated by 20sqrt(2) sigma widths and all sigmas at 0.01\n\n function loglikelihood(theta,phi)\n use utils_module, only: logaddexp,logTwoPi\n implicit none\n real(dp), intent(in), dimension(:) :: theta !> Input parameters\n real(dp), intent(out), dimension(:) :: phi !> Output derived parameters\n real(dp) :: loglikelihood ! loglikelihood value to output\n\n real(dp) :: loglikelihood1\n real(dp) :: loglikelihood2\n\n real(dp), dimension(size(theta)) :: sigma ! Standard deviation (uncorrelated) \n real(dp), dimension(size(theta)) :: mu1 ! Mean\n real(dp), dimension(size(theta)) :: mu2 ! Mean\n\n\n ! Initialise the mean and standard deviation\n sigma = 1d-1 ! all sigma set relatively small\n mu1 = 0d0 ! mean in the center\n mu1(1) = -5d-1\n mu1(2) = -5d-1\n mu2 = 0d0 ! mean in the center\n mu2(1) = +5d-1\n mu2(2) = +5d-1\n\n ! Gaussian normalisation\n loglikelihood1 = - sum( log( sigma ) + logTwoPi/2d0 ) \n loglikelihood2 = loglikelihood1\n\n ! theta dependence\n loglikelihood1 = loglikelihood1 - sum( ( ( theta - mu1 ) / sigma ) ** 2d0 ) / 2d0\n loglikelihood2 = loglikelihood2 - sum( ( ( theta - mu2 ) / sigma ) ** 2d0 ) / 2d0\n\n loglikelihood = logaddexp(loglikelihood1,loglikelihood2) - log(2d0)\n\n ! One derived parameter, which is +1 if its in the right hand cluster,\n ! or -1 if its in the left hand cluster\n if(theta(1) >0.5d0) then\n phi(1)=1d0\n else\n phi(1)=-1d0\n end if\n\n end function loglikelihood\n\n subroutine setup_loglikelihood(settings)\n use settings_module, only: program_settings\n implicit none\n type(program_settings), intent(in) :: settings\n\n end subroutine setup_loglikelihood\n\nend module loglikelihood_module\n", "meta": {"hexsha": "c4608641da908e61d2bbe48ded3054895c70417e", "size": 2327, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Externals/PolyChord/likelihoods/examples/twin_gaussian.f90", "max_stars_repo_name": "yuanfangtardis/vscode_project", "max_stars_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Externals/PolyChord/likelihoods/examples/twin_gaussian.f90", "max_issues_repo_name": "yuanfangtardis/vscode_project", "max_issues_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Externals/PolyChord/likelihoods/examples/twin_gaussian.f90", "max_forks_repo_name": "yuanfangtardis/vscode_project", "max_forks_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-15T12:22:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T12:22:30.000Z", "avg_line_length": 35.2575757576, "max_line_length": 94, "alphanum_fraction": 0.6059303825, "num_tokens": 629, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012686491108, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7688109383103521}} {"text": "!----------------------------------------------------------\n! TRIAL FUNCTION\n!----------------------------------------------------------\nsubroutine calbvec( l,theta,phi,plm,bvec )\n!----------------------------------------------------------\n! Evaluating the value of toroidal harmonics (fully normalized)\n! at each station whose latitude and longitude are theta and phi.\n!----------------------------------------------------------\n use parameters\n implicit none\n integer,intent(in):: l\n integer:: m,i\n double precision:: theta,phi,x,plm(3,0:3),fact,coef\n complex(dp):: bvec(3,-2:2),expimp\n\n x = dcos( theta )\n do m=0,min0(l,3)\n call calplm( l,m,x,plm(1,m) )\n enddo\n do m=0,min0(l,2)\n fact = 1\n if ( m/=0 ) then\n do i=l-m+1,l+m\n fact = fact * dble(i)\n enddo\n endif\n coef = dsqrt( (2*l+1)/(4.d0*pi) / fact )\n expimp = cdexp( dcmplx( 0, m*phi ) )\n bvec(1,m) = coef * plm(1,m) * expimp\n bvec(1,-m) = dconjg( bvec(1,m) )\n bvec(2,m) = coef *( m*x / dsin( theta ) * plm(1,m) + plm(1,m+1) ) * expimp\n bvec(2,-m) = dconjg( bvec(2,m) )\n bvec(3,m) = dcmplx( 0, m ) / dsin( theta ) * coef * plm(1,m) * expimp\n bvec(3,-m) = dconjg( bvec(3,m) )\n if ( mod(m,2)==1 ) bvec(1:3,-m) = - bvec(1:3,-m)\n enddo\n return\nend\n\n!----------------------------------------------------------\nsubroutine calplm( l,m,x,plm )\n!----------------------------------------------------------\n implicit none\n integer:: l,m,i\n double precision:: x,plm(3),pmm,somx2,fact\n\n if ( m<0 .or. m>l .or. dabs(x)>1.d0 ) stop 'bad arguments'\n if ( l==m ) then\n pmm = 1\n if ( m>0 ) then\n somx2 = dsqrt( (1.d0-x)*(1.d0+x) )\n fact = 1\n do i=1,m\n pmm = -pmm * fact * somx2\n fact = fact + 2\n enddo\n endif\n plm(2:3) = 0\n plm(1) = pmm\n else\n plm(3) = plm(2)\n plm(2) = plm(1)\n if ( l==m+1 ) then\n plm(1) = x * (2*m+1) * plm(2)\n else\n plm(1) = ( x * (2*l-1) * plm(2) - (l+m-1) * plm(3) ) / (l-m)\n endif\n endif\n return\nend\n\n\n\n", "meta": {"hexsha": "1f8c5f5975ed185c7d04babad9f609174953f68a", "size": 2244, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "dsmpy/src_f90/tipsv/trialf.f90", "max_stars_repo_name": "seismobassoon/dsmpy", "max_stars_repo_head_hexsha": "4290269ff0998549a2eec25ed090417f8cf1bad7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "dsmpy/src_f90/tipsv/trialf.f90", "max_issues_repo_name": "seismobassoon/dsmpy", "max_issues_repo_head_hexsha": "4290269ff0998549a2eec25ed090417f8cf1bad7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dsmpy/src_f90/tipsv/trialf.f90", "max_forks_repo_name": "seismobassoon/dsmpy", "max_forks_repo_head_hexsha": "4290269ff0998549a2eec25ed090417f8cf1bad7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.3243243243, "max_line_length": 82, "alphanum_fraction": 0.3908199643, "num_tokens": 750, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533107374443, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7687722588594857}} {"text": "module spline_dlg\n\ncontains\n\n\n! See Burden and Faires pg 133.\n!\n! NOTE: allocate the \"spline\" variable prior to \n! function call. Does not work otherwise. Not\n! sure as to the cause, perhaps compiler bug?\n\n\nfunction spline ( x, a, fp0, fpn )\n\n implicit none\n\n real, intent(in) :: x(:), a(:), fp0, fpn\n real, allocatable :: spline(:,:)\n\n integer :: n, i\n real, allocatable :: b(:), c(:), d(:), h(:), alpha(:)\n real, allocatable :: u(:), l(:), z(:)\n\n n = size ( x ) - 1\n\n allocate ( b(n+1),c(n+1),d(n+1),h(n), alpha(n+1) )\n if(.not.allocated(spline)) allocate ( spline(n+1,4) )\n allocate ( u(n+1), l(n+1), z(n+1) )\n\n do i=1,n\n h(i) = x(i+1)-x(i)\n enddo \n\n alpha(1) = 3 * ( a(2)-a(1) ) / h(1) - 3 * fp0\n alpha(n+1) = 3 * fpn - 3 * ( a(n+1)-a(n) ) / h(n)\n\n do i=2,n\n alpha(i) = &\n 3 * (a(i+1)*h(i-1) - a(i) * ( x(i+1)-x(i-1) ) + a(i-1)*h(i) ) &\n / (h(i-1)*h(i))\n enddo\n\n l(1) = 2 * h(1)\n u(1) = 0.5\n z(1) = alpha(1) / l(1)\n\n do i=2,n\n l(i) = 2 * ( x(i+1)-x(i-1) ) - h(i-1)*u(i-1)\n u(i) = h(i) / l(i)\n z(i) = ( alpha(i) - h(i-1)*z(i-1) ) / l(i)\n enddo\n\n l(n+1) = h(n) * ( 2-u(n) )\n z(n+1) = ( alpha(n+1)-h(n)*z(n) ) / l(n+1)\n\n c(n+1) = z(n+1)\n\n do i=n,1,-1\n\n c(i) = z(i) - u(i)*c(i+1)\n b(i) = (a(i+1)-a(i))/h(i) - h(i)*(c(i+1)+2*c(i))/3\n d(i) = (c(i+1)-c(i))/(3*h(i))\n\n enddo\n\n spline(:,1) = a\n spline(:,2) = b\n spline(:,3) = c\n spline(:,4) = d\n\nend function spline\n\nend module spline_dlg\n", "meta": {"hexsha": "3296a34e1f39fd908c40ebc2da0d39d42f3822c6", "size": 1559, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/spline_dlg.f90", "max_stars_repo_name": "efdazedo/aorsa2d", "max_stars_repo_head_hexsha": "ce0b8c930715277eeb4d23e60cc88434ffdaa583", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-02-13T21:57:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-10T16:47:51.000Z", "max_issues_repo_path": "src/spline_dlg.f90", "max_issues_repo_name": "efdazedo/aorsa2d", "max_issues_repo_head_hexsha": "ce0b8c930715277eeb4d23e60cc88434ffdaa583", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-02-23T20:33:30.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-23T20:34:31.000Z", "max_forks_repo_path": "src/spline_dlg.f90", "max_forks_repo_name": "efdazedo/aorsa2d", "max_forks_repo_head_hexsha": "ce0b8c930715277eeb4d23e60cc88434ffdaa583", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-02-15T16:50:58.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-23T14:07:59.000Z", "avg_line_length": 21.0675675676, "max_line_length": 75, "alphanum_fraction": 0.431045542, "num_tokens": 673, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832974, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7687722436989717}} {"text": "MODULE constants\nIMPLICIT NONE\nREAL, PARAMETER :: E = 2.71828\nEND MODULE constants\n\nCOMPLEX FUNCTION euler(theta)\nUSE constants\nIMPLICIT NONE\nREAL, INTENT(IN) :: theta\neuler = COS(theta) + CMPLX(0.,1.) * SIN(theta)\nEND FUNCTION euler\n\nPROGRAM test_euler\nUSE constants\nIMPLICIT NONE\nREAL :: theta\nCOMPLEX :: euler\nWRITE(*, *) \"Enter a value for theta: \"\nREAD(*, *) theta\nWRITE(*, 100) \"euler(\", theta, \") =\", euler(theta)\nWRITE(*, 100) \"CEXP(e^i *\", theta, \") =\", CEXP(CMPLX(0,1.) * theta)\n100 FORMAT (A,F8.5,A,\"(\",F16.12,\", \",F16.12,\")\")\nEND PROGRAM test_euler\n", "meta": {"hexsha": "51a0f5dcbc2c9df6c03ba7bfef598e06aace248f", "size": 565, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap11/test_euler.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap11/test_euler.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap11/test_euler.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5416666667, "max_line_length": 67, "alphanum_fraction": 0.6672566372, "num_tokens": 188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632896242073, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7687274241011066}} {"text": "! ==================================================================================================================================\n! NAME\n!\n! rot [ rot ] - Rotation Module\n!\n! SYNOPSIS\n!\n! USE :: ROT\n!\n! DESCRIPTION \n!\n! ROT is a custom Fortran module written to compute the elemental rotation matrices of a Cartesian coordinate system.\n!\n! OPTIONS\n!\n! SEE ALSO\n!\n! BUGS\n!\n! HISTORY\n!\n! AUTHOR\n!\n! Marty Kandes, Ph.D.\n! Computational & Data Science Research Specialist\n! High-Performance Computing User Services Group\n! San Diego Supercomputer Center\n! University of California, San Diego\n!\n! COPYRIGHT\n! \n! Copyright (c) 2014, 2015, 2016, 2017, 2018, 2019, 2020 Martin Charles Kandes\n!\n! LAST UPDATED\n!\n! Tuesday, April 2nd, 2019\n!\n! ----------------------------------------------------------------------------------------------------------------------------------\n\n MODULE rot\n\n! --- MODULE DECLARATIONS ----------------------------------------------------------------------------------------------------------\n\n USE, INTRINSIC :: ISO_FORTRAN_ENV\n\n! --- MODULE DEFINITIONS -----------------------------------------------------------------------------------------------------------\n!\n! ISO_FORTRAN_ENV is the intrinsic Fortran module that provides information about the run-time environment.\n!\n! ----------------------------------------------------------------------------------------------------------------------------------\n\n IMPLICIT NONE\n PRIVATE\n\n! --- VARIABLE DECLARATIONS --------------------------------------------------------------------------------------------------------\n\n REAL, PUBLIC :: thetaX\n REAL, PUBLIC :: thetaY\n REAL, PUBLIC :: thetaZ\n\n! --- VARIABLE DEFINITIONS ---------------------------------------------------------------------------------------------------------\n!\n! thetaX is a PUBLIC, REAL-valued variable that stores the rotation angle about the x-axis.\n!\n! thetaY is a PUBLIC, REAL-valued variable that stores the rotation angle about the y-axis.\n!\n! thetaZ is a PUBLIC, REAL-valued variable that stores the rotation angle about the z-axis.\n! \n! --- ARRAY DECLARATIONS -----------------------------------------------------------------------------------------------------------\n\n REAL, DIMENSION ( 3 , 3 ), PUBLIC :: R\n\n! --- ARRAY DEFINITIONS ------------------------------------------------------------------------------------------------------------\n!\n! R is a PUBLIC, REAL-valued rank-two array that stores the 3-by-3 rotation matrix.\n!\n! --- FUNCTION DECLARATIONS --------------------------------------------------------------------------------------------------------\n\n PUBLIC :: rot_rx\n PUBLIC :: rot_ry\n PUBLIC :: rot_rz\n\n! --- FUNCTION DEFINITIONS ---------------------------------------------------------------------------------------------------------\n!\n! rot_rx is a PUBLIC FUNCTION that computes the elemental rotation matrix about the x-axis of a Cartesian coordinate system.\n!\n! rot_ry is a PUBLIC FUNCTION that computes the elemental rotation matrix about the y-axis of a Cartesian coordinate system.\n!\n! rot_rz is a PUBLIC FUNCTION that computes the elemental rotation matrix about the z-axis of a Cartesian coordinate system.\n!\n! ----------------------------------------------------------------------------------------------------------------------------------\n\n CONTAINS\n\n! ----------------------------------------------------------------------------------------------------------------------------------\n\n FUNCTION rot_rx ( theta )\n\n IMPLICIT NONE\n\n REAL, INTENT ( IN ) :: theta\n\n REAL, DIMENSION ( 3 , 3 ) :: rot_rx\n\n rot_rx ( 1 , 1 ) = 1.0\n rot_rx ( 2 , 1 ) = 0.0\n rot_rx ( 3 , 1 ) = 0.0\n rot_rx ( 1 , 2 ) = 0.0\n rot_rx ( 2 , 2 ) = COS ( theta )\n rot_rx ( 3 , 2 ) = SIN ( theta )\n rot_rx ( 1 , 3 ) = 0.0 \n rot_rx ( 2 , 3 ) = -SIN ( theta )\n rot_rx ( 3 , 3 ) = COS ( theta )\n\n RETURN\n\n END FUNCTION\n\n! ----------------------------------------------------------------------------------------------------------------------------------\n\n FUNCTION rot_ry ( theta )\n\n IMPLICIT NONE\n\n REAL, INTENT ( IN ) :: theta\n\n REAL, DIMENSION ( 3, 3 ) :: rot_ry\n\n rot_ry ( 1 , 1 ) = COS ( theta ) \n rot_ry ( 2 , 1 ) = 0.0\n rot_ry ( 3 , 1 ) = -SIN ( theta )\n rot_ry ( 1 , 2 ) = 0.0\n rot_ry ( 2 , 2 ) = 1.0\n rot_ry ( 3 , 2 ) = 0.0\n rot_ry ( 1 , 3 ) = SIN ( theta )\n rot_ry ( 2 , 3 ) = 0.0\n rot_ry ( 3 , 3 ) = COS ( theta )\n\n RETURN\n\n END FUNCTION\n\n! ----------------------------------------------------------------------------------------------------------------------------------\n\n FUNCTION rot_rz ( theta )\n\n IMPLICIT NONE\n\n REAL, INTENT ( IN ) :: theta\n\n REAL, DIMENSION ( 3 , 3 ) :: rot_rz\n\n rot_rz ( 1 , 1 ) = COS ( theta )\n rot_rz ( 2 , 1 ) = SIN ( theta )\n rot_rz ( 3 , 1 ) = 0.0\n rot_rz ( 1 , 2 ) = -SIN ( theta )\n rot_rz ( 2 , 2 ) = COS ( theta )\n rot_rz ( 3 , 2 ) = 0.0\n rot_rz ( 1 , 3 ) = 0.0\n rot_rz ( 2 , 3 ) = 0.0\n rot_rz ( 3 , 3 ) = 1.0\n\n RETURN\n\n END FUNCTION\n\n! ----------------------------------------------------------------------------------------------------------------------------------\n\n END MODULE\n\n! ==================================================================================================================================\n", "meta": {"hexsha": "b7bc1033a04b3fe492695d9f11cc43f2f055a265", "size": 5567, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/rot.f90", "max_stars_repo_name": "mkandes/gpse", "max_stars_repo_head_hexsha": "53e82cd5b5b9b2caa4219517d5fd89dda3fe99c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/rot.f90", "max_issues_repo_name": "mkandes/gpse", "max_issues_repo_head_hexsha": "53e82cd5b5b9b2caa4219517d5fd89dda3fe99c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/rot.f90", "max_forks_repo_name": "mkandes/gpse", "max_forks_repo_head_hexsha": "53e82cd5b5b9b2caa4219517d5fd89dda3fe99c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.3662790698, "max_line_length": 132, "alphanum_fraction": 0.3641099335, "num_tokens": 1159, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7686384442646264}} {"text": "module cholesky\n implicit none\ncontains\n ! Calcula o fator de Cholesky pelo método do produto externo,\n ! orientado a colunas.\n ! Guarda o fator na parte triangular inferior da matriz A e\n ! retorna:\n ! 0: se o fator foi calculado com sucesso\n ! -1: se a matriz A não é positiva definida e não foi\n ! possível calcular seu fator\n function cholcol(n, A) result(status)\n integer, intent(in) :: n\n double precision, intent(inout) :: A(:, :)\n\n double precision :: akk\n integer :: status\n integer :: i, j, k\n\n status = -1\n do k = 1, n\n akk = A(k, k)\n if (akk <= 0) then\n return\n end if\n\n akk = sqrt(akk)\n A(k, k) = akk\n do i = k+1, n\n A(i, k) = A(i, k)/akk\n end do\n\n do j = k+1, n\n do i = j, n\n A(i, j) = A(i, j) - A(i, k)*A(j, k)\n end do\n end do\n end do\n\n status = 0\n end function cholcol\n\n ! Calcula o fator de Cholesky pelo método do produto externo,\n ! orientado a linhas.\n ! Guarda o fator na parte triangular inferior da matriz A e\n ! retorna:\n ! 0: se o fator foi calculado com sucesso\n ! -1: se a matriz A não é positiva definida e não foi\n ! possível calcular seu fator\n function cholrow(n, A) result(status)\n integer, intent(in) :: n\n double precision, intent(inout) :: A(:, :)\n\n double precision :: akk\n integer :: status\n integer :: i, j, k\n\n status = -1\n do k = 1, n\n akk = A(k, k)\n if (akk <= 0) then\n return\n end if\n\n akk = sqrt(akk)\n A(k, k) = akk\n do i = k+1, n\n A(i, k) = A(i, k)/akk\n end do\n\n do i = k+1, n\n do j = k+1, i\n A(i, j) = A(i, j) - A(i, k)*A(j, k)\n end do\n end do\n end do\n\n status = 0\n end function cholrow\n\nend module cholesky\n", "meta": {"hexsha": "869c71deaa8a9ff0a1f4821ba6d740e9cbf0bc96", "size": 2180, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "EP/src/cholesky.f08", "max_stars_repo_name": "lmagno/MAC0427", "max_stars_repo_head_hexsha": "81229a5ad2ff8d8c2e89f0211df5fb9eee2a1836", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-01-24T22:57:33.000Z", "max_stars_repo_stars_event_max_datetime": "2018-01-24T22:57:33.000Z", "max_issues_repo_path": "EP/src/cholesky.f08", "max_issues_repo_name": "lmagno/MAC0427", "max_issues_repo_head_hexsha": "81229a5ad2ff8d8c2e89f0211df5fb9eee2a1836", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "EP/src/cholesky.f08", "max_forks_repo_name": "lmagno/MAC0427", "max_forks_repo_head_hexsha": "81229a5ad2ff8d8c2e89f0211df5fb9eee2a1836", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.9135802469, "max_line_length": 65, "alphanum_fraction": 0.4490825688, "num_tokens": 619, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7686384400780083}} {"text": "\n integer function julian_day(yr,mo,da)\n\n implicit none\n\n integer yr,mo,da\n\n integer mon(12)\n integer lpyr\n data mon /0,31,59,90,120,151,181,212,243,273,304,334/\n\n julian_day = da + mon(mo)\n if(mo>2) julian_day = julian_day + lpyr(yr)\n\n end function julian_day\n\n! ------------------------------------------------------------------\n\n integer function lpyr(yr)\n\n implicit none\n\n integer yr\n!\n!---- returns 1 if leap year\n!\n lpyr=0\n if(mod(yr,400) == 0) then\n lpyr=1\n else if(mod(yr,4) == 0) then\n lpyr=1\n if(mod(yr,100) == 0) lpyr=0\n endif\n\n end function lpyr\n\n! ------------------------------------------------------------------\n\n! function to determine if year is a leap year\n logical function is_leap_year(yr)\n\n implicit none\n\n integer yr\n\n integer, external :: lpyr\n\n!---- function lpyr above returns 1 if leap year\n if(lpyr(yr) == 1) then\n is_leap_year = .true.\n else\n is_leap_year = .false.\n endif\n\n end function is_leap_year\n\n\n!----------------------------------------------------------------------------------------------\n! open-source subroutines below taken from ftp://ftp.met.fsu.edu/pub/ahlquist/calendar_software\n!----------------------------------------------------------------------------------------------\n\n integer function idaywk(jdayno)\n\n! IDAYWK = compute the DAY of the WeeK given the Julian Day number,\n! version 1.0.\n\n implicit none\n\n! Input variable\n integer, intent(in) :: jdayno\n! jdayno = Julian Day number starting at noon of the day in question.\n\n! Output of the function:\n! idaywk = day of the week, where 0=Sunday, 1=Monday, ..., 6=Saturday.\n\n!----------\n! Compute the day of the week given the Julian Day number.\n! You can find the Julian Day number given (day,month,year)\n! using subroutine calndr below.\n! Example: For the first day of the Gregorian calendar,\n! Friday 15 October 1582, compute the Julian day number (option 3 of\n! subroutine calndr) and compute the day of the week.\n! call calndr (3, 15, 10, 1582, jdayno)\n! write(*,*) jdayno, idaywk(jdayno)\n! The numbers printed should be 2299161 and 5, where 5 refers to Friday.\n!\n! Copyright (C) 1999 Jon Ahlquist.\n! Issued under the second GNU General Public License.\n! See www.gnu.org for details.\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n! If you find any errors, please notify:\n! Jon Ahlquist \n! Dept of Meteorology\n! Florida State University\n! Tallahassee, FL 32306-4520\n! 15 March 1999.\n!\n!-----\n\n! converted to Fortran90 by Dimitri Komatitsch,\n! University of Pau, France, January 2008.\n\n! jdSun is the Julian Day number starting at noon on any Sunday.\n! I arbitrarily chose the first Sunday after Julian Day 1,\n! which is Julian Day 6.\n integer, parameter :: jdSun = 6\n\n idaywk = mod(jdayno-jdSun,7)\n\n! If jdayno-jdSun < 0, then we are taking the modulus of a negative\n! number. Fortran's built-in mod function returns a negative value\n! when the argument is negative. In that case, we adjust the result\n! to a positive value.\n if (idaywk < 0) idaywk = idaywk + 7\n\n end function idaywk\n\n!\n!----\n!\n\n subroutine calndr(iday,month,iyear,idayct)\n\n! CALNDR = CALeNDaR conversions, version 1.0\n\n implicit none\n\n! specify the desired calendar conversion option.\n! in order to return the julian day number, compatible with function idaywk from above,\n! we choose option 3\n! (tested with dates: Feb, 23 2010 -> idaywk = Tue\n! Dec, 24 2009 -> idaywk = Thu\n! Oct, 15 1582 -> idaywk = Fri ...which all look o.k. )\n integer, parameter :: ioptn = 3\n\n! Input/Output variables\n integer, intent(inout) :: iday,month,iyear,idayct\n\n!----------\n!\n! Subroutine calndr() performs calendar calculations using either\n! the standard Gregorian calendar or the old Julian calendar.\n! This subroutine extends the definitions of these calendar systems\n! to any arbitrary year. The algorithms in this subroutine\n! will work with any date in the past or future,\n! but overflows will occur if the numbers are sufficiently large.\n! For a computer using a 32-bit integer, this routine can handle\n! any date between roughly 5.8 million BC and 5.8 million AD\n! without experiencing overflow during calculations.\n!\n! No external functions or subroutines are called.\n!\n!----------\n!\n! INPUT/OUTPUT ARGUMENTS FOR SUBROUTINE CALNDR()\n!\n! \"ioptn\" is the desired calendar conversion option explained below.\n! Positive option values use the standard modern Gregorian calendar.\n! Negative option values use the old Julian calendar which was the\n! standard in Europe from its institution by Julius Caesar in 45 BC\n! until at least 4 October 1582. The Gregorian and Julian calendars\n! are explained further below.\n!\n! (iday,month,iyear) is a calendar date where \"iday\" is the day of\n! the month, \"month\" is 1 for January, 2 for February, etc.,\n! and \"iyear\" is the year. If the year is 1968 AD, enter iyear=1968,\n! since iyear=68 would refer to 68 AD.\n! For BC years, iyear should be negative, so 45 BC would be iyear=-45.\n! By convention, there is no year 0 under the BC/AD year numbering\n! scheme. That is, years proceed as 2 BC, 1 BC, 1 AD, 2 AD, etc.,\n! without including 0. Subroutine calndr() will print an error message\n! and stop if you specify iyear=0.\n!\n! \"idayct\" is a day count. It is either the day number during the\n! specified year or the Julian Day number, depending on the value\n! of ioptn. By day number during the specified year, we mean\n! idayct=1 on 1 January, idayct=32 on 1 February, etc., to idayct=365\n! or 366 on 31 December, depending on whether the specified year\n! is a leap year.\n!\n! The values of input variables are not changed by this subroutine.\n!\n!\n! ALLOWABLE VALUES FOR \"IOPTN\" and the conversions they invoke.\n! Positive option values ( 1 to 5) use the standard Gregorian calendar.\n! Negative option values (-1 to -5) use the old Julian calendar.\n!\n! Absolute\n! value\n! of ioptn Input variable(s) Output variable(s)\n!\n! 1 iday,month,iyear idayct\n! Given a calendar date (iday,month,iyear), compute the day number\n! (idayct) during the year, where 1 January is day number 1 and\n! 31 December is day number 365 or 366, depending on whether it is\n! a leap year.\n!\n! 2 idayct,iyear iday,month\n! Given the day number of the year (idayct) and the year (iyear),\n! compute the day of the month (iday) and the month (month).\n!\n! 3 iday,month,iyear idayct\n! Given a calendar date (iday,month,iyear), compute the Julian Day\n! number (idayct) that starts at noon of the calendar date specified.\n!\n! 4 idayct iday,month,iyear\n! Given the Julian Day number (idayct) that starts at noon,\n! compute the corresponding calendar date (iday,month,iyear).\n!\n! 5 idayct iday,month,iyear\n! Given the Julian Day number (idayct) that starts at noon,\n! compute the corresponding day number for the year (iday)\n! and year (iyear). On return from calndr(), \"month\" will always\n! be set equal to 1 when ioptn=5.\n!\n! No inverse function is needed for ioptn=5 because it is\n! available through option 3. One simply calls calndr() with:\n! ioptn = 3,\n! iday = day number of the year instead of day of the month,\n! month = 1, and\n! iyear = whatever the desired year is.\n!\n!----------\n!\n! EXAMPLES\n! The first 6 examples are for the standard Gregorian calendar.\n! All the examples deal with 15 October 1582, which was the first day\n! of the Gregorian calendar. 15 October is the 288-th day of the year.\n! Julian Day number 2299161 began at noon on 15 October 1582.\n!\n! Find the day number during the year on 15 October 1582\n! ioptn = 1\n! call calndr (ioptn, 15, 10, 1582, idayct)\n! calndr() should return idayct=288\n!\n! Find the day of the month and month for day 288 in year 1582.\n! ioptn = 2\n! call calndr (ioptn, iday, month, 1582, 288)\n! calndr() should return iday=15 and month=10.\n!\n! Find the Julian Day number for 15 October 1582.\n! ioptn = 3\n! call calndr (ioptn, 15, 10, 1582, julian)\n! calndr() should return julian=2299161\n!\n! Find the Julian Day number for day 288 during 1582 AD.\n! When the input is day number of the year, one should specify month=1\n! ioptn = 3\n! call calndr (ioptn, 288, 1, 1582, julian)\n! calndr() should return dayct=2299161\n!\n! Find the date for Julian Day number 2299161.\n! ioptn = 4\n! call calndr (ioptn, iday, month, iyear, 2299161)\n! calndr() should return iday=15, month=10, and iyear=1582\n!\n! Find the day number during the year (iday) and year\n! for Julian Day number 2299161.\n! ioptn = 5\n! call calndr (ioptn, iday, month, iyear, 2299161)\n! calndr() should return iday=288, month=1, iyear=1582\n!\n! Given 15 October 1582 under the Gregorian calendar,\n! find the date (idayJ,imonthJ,iyearJ) under the Julian calendar.\n! To do this, we call calndr() twice, using the Julian Day number\n! as the intermediate value.\n! call calndr ( 3, 15, 10, 1582, julian)\n! call calndr (-4, idayJ, monthJ, iyearJ, julian)\n! The first call to calndr() should return julian=2299161, and\n! the second should return idayJ=5, monthJ=10, iyearJ=1582\n!\n!----------\n!\n! BASIC CALENDAR INFORMATION\n!\n! The Julian calendar was instituted by Julius Caesar in 45 BC.\n! Every fourth year is a leap year in which February has 29 days.\n! That is, the Julian calendar assumes that the year is exactly\n! 365.25 days long. Actually, the year is not quite this long.\n! The modern Gregorian calendar remedies this by omitting leap years\n! in years divisible by 100 except when the year is divisible by 400.\n! Thus, 1700, 1800, and 1900 are leap years under the Julian calendar\n! but not under the Gregorian calendar. The years 1600 and 2000 are\n! leap years under both the Julian and the Gregorian calendars.\n! Other years divisible by 4 are leap years under both calendars,\n! such as 1992, 1996, 2004, 2008, 2012, etc. For BC years, we recall\n! that year 0 was omitted, so 1 BC, 5 BC, 9 BC, 13 BC, etc., and 401 BC,\n! 801 BC, 1201 BC, etc., are leap years under both calendars, while\n! 101 BC, 201 BC, 301 BC, 501 BC, 601 BC, 701 BC, 901 BC, 1001 BC,\n! 1101 BC, etc., are leap years under the Julian calendar but not\n! the Gregorian calendar.\n!\n! The Gregorian calendar is named after Pope Gregory XIII. He declared\n! that the last day of the old Julian calendar would be Thursday,\n! 4 October 1582 and that the following day, Friday, would be reckoned\n! under the new calendar as 15 October 1582. The jump of 10 days was\n! included to make 21 March closer to the spring equinox.\n!\n! Only a few Catholic countries (Italy, Poland, Portugal, and Spain)\n! switched to the Gregorian calendar on the day after 4 October 1582.\n! It took other countries months to centuries to change to the\n! Gregorian calendar. For example, England's first day under the\n! Gregorian calendar was 14 September 1752. The same date applied to\n! the entire British empire, including America. Japan, Russia, and many\n! eastern European countries did not change to the Gregorian calendar\n! until the 20th century. The last country to change was Turkey,\n! which began using the Gregorian calendar on 1 January 1927.\n!\n! Therefore, between the years 1582 and 1926 AD, you must know\n! the country in which an event was dated to interpret the date\n! correctly. In Sweden, there was even a year (1712) when February\n! had 30 days. Consult a book on calendars for more details\n! about when various countries changed their calendars.\n!\n! DAY NUMBER DURING THE YEAR\n! The day number during the year is simply a counter equal to 1 on\n! 1 January, 32 on 1 February, etc., thorugh 365 or 366 on 31 December,\n! depending on whether the year is a leap year. Sometimes this is\n! called the Julian Day, but that term is better reserved for the\n! day counter explained below.\n!\n! JULIAN DAY NUMBER\n! The Julian Day numbering system was designed by Joseph Scaliger\n! in 1582 to remove ambiguity caused by varying calendar systems.\n! The name \"Julian Day\" was chosen to honor Scaliger's father,\n! Julius Caesar Scaliger (1484-1558), an Italian scholar and physician\n! who lived in France. Because Julian Day numbering was especially\n! designed for astronomers, Julian Days begin at noon so that the day\n! counter does not change in the middle of an astronmer's observing\n! period. Julian Day 0 began at noon on 1 January 4713 BC under the\n! Julian calendar. A modern reference point is that 23 May 1968\n! (Gregorian calendar) was Julian Day 2,440,000.\n!\n! JULIAN DAY NUMBER EXAMPLES\n!\n! The table below shows a few Julian Day numbers and their corresponding\n! dates, depending on which calendar is used. A negative 'iyear' refers\n! to BC (Before Christ).\n!\n! Julian Day under calendar:\n! iday month iyear Gregorian Julian\n! 24 11 -4714 0 -38\n! 1 1 -4713 38 0\n! 1 1 1 1721426 1721424\n! 4 10 1582 2299150 2299160\n! 15 10 1582 2299161 2299171\n! 1 3 1600 2305508 2305518\n! 23 5 1968 2440000 2440013\n! 5 7 1998 2451000 2451013\n! 1 3 2000 2451605 2451618\n! 1 1 2001 2451911 2451924\n!\n! From this table, we can see that the 10 day difference between the\n! two calendars in 1582 grew to 13 days by 1 March 1900, since 1900 was\n! a leap year under the Julian calendar but not under the Gregorian\n! calendar. The gap will widen to 14 days after 1 March 2100 for the\n! same reason.\n!\n!----------\n!\n! PORTABILITY\n!\n! This subroutine is written in standard FORTRAN 90.\n! It calls no external functions or subroutines and should run\n! without problem on any computer having a 32-bit word or longer.\n!\n!----------\n!\n! ALGORITHM\n!\n! The goal in coding calndr() was clear, clean code, not efficiency.\n! Calendar calculations usually take a trivial fraction of the time\n! in any program in which dates conversions are involved.\n! Data analysis usually takes the most time.\n!\n! Standard algorithms are followed in this subroutine. Internal to\n! this subroutine, we use a year counter \"jyear\" such that\n! jyear=iyear when iyear is positive\n! =iyear+1 when iyear is negative.\n! Thus, jyear does not experience a 1 year jump like iyear does\n! when going from BC to AD. Specifically, jyear=0 when iyear=-1,\n! i.e., when the year is 1 BC.\n!\n! For simplicity in dealing with February, inside this subroutine,\n! we let the year begin on 1 March so that the adjustable month,\n! February is the last month of the year.\n! It is clear that the calendar used to work this way because the\n! months September, October, November, and December refer to\n! 7, 8, 9, and 10. For consistency, jyear is incremented on 1 March\n! rather than on 1 January. Of course, everything is adjusted back to\n! standard practice of years beginning on 1 January before answers\n! are returned to the routine that calls calndr().\n!\n! Lastly, we use a trick to calculate the number of days from 1 March\n! until the end of the month that precedes the specified month.\n! That number of days is int(30.6001*(month+1))-122,\n! where 30.6001 is used to avoid the possibility of round-off and\n! truncation error. For example, if 30.6 were used instead,\n! 30.6*5 should be 153, but round-off error could make it 152.99999,\n! which would then truncated to 152, causing an error of 1 day.\n!\n! Algorithm reference:\n! Dershowitz, Nachum and Edward M. Reingold, 1990: Calendrical\n! Calculations. Software-Practice and Experience, vol. 20, number 9\n! (September 1990), pp. 899-928.\n!\n! Copyright (C) 1999 Jon Ahlquist.\n! Issued under the second GNU General Public License.\n! See www.gnu.org for details.\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n! If you find any errors, please notify:\n! Jon Ahlquist \n! Dept of Meteorology\n! Florida State University\n! Tallahassee, FL 32306-4520\n! 15 March 1999.\n!\n!-----\n\n! converted to Fortran90 by Dimitri Komatitsch,\n! University of Pau, France, January 2008.\n\n! Declare internal variables.\n integer jdref, jmonth, jyear, leap, n1yr, n4yr, n100yr, n400yr, ndays, ndy400, ndy100, nyrs, yr400, yrref\n!\n! Explanation of all internal variables.\n! jdref Julian Day on which 1 March begins in the reference year.\n! jmonth Month counter which equals month+1 if month > 2\n! or month+13 if month <= 2.\n! jyear Year index, jyear=iyear if iyear > 0, jyear=iyear+1\n! if iyear < 0. Thus, jyear does not skip year 0\n! like iyear does between BC and AD years.\n! leap =1 if the year is a leap year, =0 if not.\n! n1yr Number of complete individual years between iyear and\n! the reference year after all 4, 100,\n! and 400 year periods have been removed.\n! n4yr Number of complete 4 year cycles between iyear and\n! the reference year after all 100 and 400 year periods\n! have been removed.\n! n100yr Number of complete 100 year periods between iyear and\n! the reference year after all 400 year periods\n! have been removed.\n! n400yr Number of complete 400 year periods between iyear and\n! the reference year.\n! ndays Number of days since 1 March during iyear. (In intermediate\n! steps, it holds other day counts as well.)\n! ndy400 Number of days in 400 years. Under the Gregorian calendar,\n! this is 400*365 + 100 - 3 = 146097. Under the Julian\n! calendar, this is 400*365 + 100 = 146100.\n! ndy100 Number of days in 100 years, Under the Gregorian calendar,\n! this is 100*365 + 24 = 36524. Under the Julian calendar,\n! this is 100*365 + 25 = 36525.\n! nyrs Number of years from the beginning of yr400\n! to the beginning of jyear. (Used for option +/-3).\n! yr400 The largest multiple of 400 years that is <= jyear.\n!\n!\n!----------------------------------------------------------------\n! Do preparation work.\n!\n! Look for out-of-range option values.\n if ((ioptn == 0) .or. (abs(ioptn) >= 6)) then\n write(*,*)'For calndr(), you specified ioptn = ', ioptn\n write(*,*) 'Allowable values are 1 to 5 for the Gregorian calendar'\n write(*,*) 'and -1 to -5 for the Julian calendar.'\n stop\n endif\n!\n! Options 1-3 have \"iyear\" as an input value.\n! Internally, we use variable \"jyear\" that does not have a jump\n! from -1 (for 1 BC) to +1 (for 1 AD).\n if (abs(ioptn) <= 3) then\n if (iyear > 0) then\n jyear = iyear\n else if (iyear == 0) then\n write(*,*) 'For calndr(), you specified the nonexistent year 0'\n stop\n else\n jyear = iyear + 1\n endif\n!\n! Set \"leap\" equal to 0 if \"jyear\" is not a leap year\n! and equal to 1 if it is a leap year.\n leap = 0\n if ((jyear/4)*4 == jyear) then\n leap = 1\n endif\n if ((ioptn > 0) .and. &\n ((jyear/100)*100 == jyear) .and. &\n ((jyear/400)*400 /= jyear) ) then\n leap = 0\n endif\n endif\n!\n! Options 3-5 involve Julian Day numbers, which need a reference year\n! and the Julian Days that began at noon on 1 March of the reference\n! year under the Gregorian and Julian calendars. Any year for which\n! \"jyear\" is divisible by 400 can be used as a reference year.\n! We chose 1600 AD as the reference year because it is the closest\n! multiple of 400 to the institution of the Gregorian calendar, making\n! it relatively easy to compute the Julian Day for 1 March 1600\n! given that, on 15 October 1582 under the Gregorian calendar,\n! the Julian Day was 2299161. Similarly, we need to do the same\n! calculation for the Julian calendar. We can compute this Julian\n! Day knwoing that on 4 October 1582 under the Julian calendar,\n! the Julian Day number was 2299160. The details of these calculations\n! is next.\n! From 15 October until 1 March, the number of days is the remainder\n! of October plus the days in November, December, January, and February:\n! 17+30+31+31+28 = 137, so 1 March 1583 under the Gregorian calendar\n! was Julian Day 2,299,298. Because of the 10 day jump ahead at the\n! switch from the Julian calendar to the Gregorian calendar, 1 March\n! 1583 under the Julian calendar was Julian Day 2,299,308. Making use\n! of the rules for the two calendar systems, 1 March 1600 was Julian\n! Day 2,299,298 + (1600-1583)*365 + 5 (due to leap years) =\n! 2,305,508 under the Gregorian calendar and day 2,305,518 under the\n! Julian calendar.\n! We also set the number of days in 400 years and 100 years.\n! For reference, 400 years is 146097 days under the Gregorian calendar\n! and 146100 days under the Julian calendar. 100 years is 36524 days\n! under the Gregorian calendar and 36525 days under the Julian calendar.\n if (abs(ioptn) >= 3) then\n!\n! Julian calendar values.\n yrref = 1600\n jdref = 2305518\n! = Julian Day reference value for the day that begins\n! at noon on 1 March of the reference year \"yrref\".\n ndy400 = 400*365 + 100\n ndy100 = 100*365 + 25\n!\n! Adjust for Gregorian calendar values.\n if (ioptn > 0) then\n jdref = jdref - 10\n ndy400 = ndy400 - 3\n ndy100 = ndy100 - 1\n endif\n endif\n!\n!----------------------------------------------------------------\n! OPTIONS -1 and +1:\n! Given a calendar date (iday,month,iyear), compute the day number\n! of the year (idayct), where 1 January is day number 1 and 31 December\n! is day number 365 or 366, depending on whether it is a leap year.\n if (abs(ioptn) == 1) then\n!\n! Compute the day number during the year.\n if (month <= 2) then\n idayct = iday + (month-1)*31\n else\n idayct = iday + int(30.6001 * (month+1)) - 63 + leap\n endif\n!\n!----------------------------------------------------------------\n! OPTIONS -2 and +2:\n! Given the day number of the year (idayct) and the year (iyear),\n! compute the day of the month (iday) and the month (month).\n else if (abs(ioptn) == 2) then\n!\n if (idayct < 60+leap) then\n month = (idayct-1)/31\n iday = idayct - month*31\n month = month + 1\n else\n ndays = idayct - (60+leap)\n! = number of days past 1 March of the current year.\n jmonth = (10*(ndays+31))/306 + 3\n! = month counter, =4 for March, =5 for April, etc.\n iday = (ndays+123) - int(30.6001*jmonth)\n month = jmonth - 1\n endif\n!\n!----------------------------------------------------------------\n! OPTIONS -3 and +3:\n! Given a calendar date (iday,month,iyear), compute the Julian Day\n! number (idayct) that starts at noon.\n else if (abs(ioptn) == 3) then\n!\n! Shift to a system where the year starts on 1 March, so January\n! and February belong to the preceding year.\n! Define jmonth=4 for March, =5 for April, ..., =15 for February.\n if (month <= 2) then\n jyear = jyear - 1\n jmonth = month + 13\n else\n jmonth = month + 1\n endif\n!\n! Find the closest multiple of 400 years that is <= jyear.\n yr400 = (jyear/400)*400\n! = multiple of 400 years at or less than jyear.\n if (jyear < yr400) then\n yr400 = yr400 - 400\n endif\n!\n n400yr = (yr400 - yrref)/400\n! = number of 400-year periods from yrref to yr400.\n nyrs = jyear - yr400\n! = number of years from the beginning of yr400\n! to the beginning of jyear.\n!\n! Compute the Julian Day number.\n idayct = iday + int(30.6001*jmonth) - 123 + 365*nyrs + nyrs/4 &\n + jdref + n400yr*ndy400\n!\n! If we are using the Gregorian calendar, we must not count\n! every 100-th year as a leap year. nyrs is less than 400 years,\n! so we do not need to consider the leap year that would occur if\n! nyrs were divisible by 400, i.e., we do not add nyrs/400.\n if (ioptn > 0) then\n idayct = idayct - nyrs/100\n endif\n!\n!----------------------------------------------------------------\n! OPTIONS -5, -4, +4, and +5:\n! Given the Julian Day number (idayct) that starts at noon,\n! compute the corresponding calendar date (iday,month,iyear)\n! (abs(ioptn)=4) or day number during the year (abs(ioptn)=5).\n else\n!\n! Create a new reference date which begins on the nearest\n! 400-year cycle less than or equal to the Julian Day for 1 March\n! in the year in which the given Julian Day number (idayct) occurs.\n ndays = idayct - jdref\n n400yr = ndays / ndy400\n! = integral number of 400-year periods separating\n! idayct and the reference date, jdref.\n jdref = jdref + n400yr*ndy400\n if (jdref > idayct) then\n n400yr = n400yr - 1\n jdref = jdref - ndy400\n endif\n!\n ndays = idayct - jdref\n! = number from the reference date to idayct.\n!\n n100yr = min(ndays/ndy100, 3)\n! = number of complete 100-year periods\n! from the reference year to the current year.\n! The min() function is necessary to avoid n100yr=4\n! on 29 February of the last year in the 400-year cycle.\n!\n ndays = ndays - n100yr*ndy100\n! = remainder after removing an integral number of\n! 100-year periods.\n!\n n4yr = ndays / 1461\n! = number of complete 4-year periods in the current century.\n! 4 years consists of 4*365 + 1 = 1461 days.\n!\n ndays = ndays - n4yr*1461\n! = remainder after removing an integral number\n! of 4-year periods.\n!\n n1yr = min(ndays/365, 3)\n! = number of complete years since the last leap year.\n! The min() function is necessary to avoid n1yr=4\n! when the date is 29 February on a leap year,\n! in which case ndays=1460, and 1460/365 = 4.\n!\n ndays = ndays - 365*n1yr\n! = number of days so far in the current year,\n! where ndays=0 on 1 March.\n!\n iyear = n1yr + 4*n4yr + 100*n100yr + 400*n400yr + yrref\n! = year, as counted in the standard way,\n! but relative to 1 March.\n!\n! At this point, we need to separate ioptn=abs(4), which seeks a\n! calendar date, and ioptn=abs(5), which seeks the day number during\n! the year. First compute the calendar date if desired (abs(ioptn)=4).\n if (abs(ioptn) == 4) then\n jmonth = (10*(ndays+31))/306 + 3\n! = offset month counter. jmonth=4 for March, =13 for\n! December, =14 for January, =15 for February.\n iday = (ndays+123) - int(30.6001*jmonth)\n! = day of the month, starting with 1 on the first day\n! of the month.\n!\n! Now adjust for the fact that the year actually begins\n! on 1 January.\n if (jmonth <= 13) then\n month = jmonth - 1\n else\n month = jmonth - 13\n iyear = iyear + 1\n endif\n!\n! This code handles abs(ioptn)=5, finding the day number during the year.\n else\n! ioptn=5 always returns month=1, which we set now.\n month = 1\n!\n! We need to determine whether this is a leap year.\n leap = 0\n if ((jyear/4)*4 == jyear) then\n leap = 1\n endif\n if ((ioptn > 0) .and. &\n ((jyear/100)*100 == jyear) .and. &\n ((jyear/400)*400 /= jyear) ) then\n leap = 0\n endif\n!\n! Now find the day number \"iday\".\n! ndays is the number of days since the most recent 1 March,\n! so ndays=0 on 1 March.\n if (ndays <=305) then\n iday = ndays + 60 + leap\n else\n iday = ndays - 305\n iyear = iyear + 1\n endif\n endif\n!\n! Adjust the year if it is <= 0, and hence BC (Before Christ).\n if (iyear <= 0) then\n iyear = iyear - 1\n endif\n!\n! End the code for the last option, ioptn.\n endif\n\n end subroutine calndr\n\n", "meta": {"hexsha": "1d46dd89f84bc520d260a3225248046739501918", "size": 27844, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "specfem2d/src/specfem2D/calendar.f90", "max_stars_repo_name": "PanIGGCAS/SeisElastic2D_1.1", "max_stars_repo_head_hexsha": "2872dc514b638237771f4071195f7b8f90e0ce3d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2020-10-04T01:55:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T05:20:50.000Z", "max_issues_repo_path": "specfem2d/src/specfem2D/calendar.f90", "max_issues_repo_name": "PanIGGCAS/SeisElastic2D_1.1", "max_issues_repo_head_hexsha": "2872dc514b638237771f4071195f7b8f90e0ce3d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-10-31T03:36:34.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-27T09:36:13.000Z", "max_forks_repo_path": "specfem2d/src/specfem2D/calendar.f90", "max_forks_repo_name": "PanIGGCAS/SeisElastic2D_1.1", "max_forks_repo_head_hexsha": "2872dc514b638237771f4071195f7b8f90e0ce3d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-12-15T02:04:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T21:48:35.000Z", "avg_line_length": 38.1424657534, "max_line_length": 107, "alphanum_fraction": 0.66251257, "num_tokens": 8192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.768638439420419}} {"text": "PROGRAM mlegzo\n \n! Code converted using TO_F90 by Alan Miller\n! Date: 2004-06-28 Time: 12:58:12\n\n! ============================================================\n! Purpose : This program computes the zeros of Legendre\n! polynomial Pn(x) in the interval [-1,1] and the\n! corresponding weighting coefficients for Gauss-\n! Legendre integration using subroutine LEGZO\n! Input : n --- Order of the Legendre polynomial\n! Output: X(n) --- Zeros of the Legendre polynomial\n! W(n) --- Corresponding weighting coefficients\n! ============================================================\n\nIMPLICIT DOUBLE PRECISION (a-h,o-z)\nDIMENSION x(120),w(120)\nWRITE(*,*)'Please enter the order of Pn(x), n '\n! READ(*,*)N\nn=5\nWRITE(*,15)n\nCALL legzo(n,x,w)\nWRITE(*,*)' Nodes and weights for Gauss-Legendre integration'\nWRITE(*,*)\nWRITE(*,*)' i xi Wi'\nWRITE(*,*)' ------------------------------------------------'\nDO i=1,n\n WRITE(*,20)i,x(i),w(i)\nEND DO\n15 FORMAT(1X,'n =',i3)\n20 FORMAT(1X,i3,1X,f22.13,d22.13)\nEND PROGRAM mlegzo\n\n\nSUBROUTINE legzo(n,x,w)\n\n! =========================================================\n! Purpose : Compute the zeros of Legendre polynomial Pn(x)\n! in the interval [-1,1], and the corresponding\n! weighting coefficients for Gauss-Legendre\n! integration\n! Input : n --- Order of the Legendre polynomial\n! Output: X(n) --- Zeros of the Legendre polynomial\n! W(n) --- Corresponding weighting coefficients\n! =========================================================\n\n\nINTEGER, INTENT(IN) :: n\nDOUBLE PRECISION, INTENT(IN OUT) :: x(n)\nDOUBLE PRECISION, INTENT(OUT) :: w(n)\nIMPLICIT DOUBLE PRECISION (a-h,o-z)\n\n\nn0=(n+1)/2\nDO nr=1,n0\n z=DCOS(3.1415926D0*(nr-0.25D0)/n)\n DO\n 10 z0=z\n p=1.0D0\n DO i=1,nr-1\n p=p*(z-x(i))\n END DO\n f0=1.0D0\n IF (nr == n0.AND.n /= 2*INT(n/2)) z=0.0D0\n f1=z\n DO k=2,n\n pf=(2.0D0-1.0D0/k)*z*f1-(1.0D0-1.0D0/k)*f0\n pd=k*(f1-z*pf)/(1.0D0-z*z)\n f0=f1\n f1=pf\n END DO\n IF (z == 0.0) EXIT\n fd=pf/p\n q=0.0D0\n DO i=1,nr-1\n wp=1.0D0\n DO j=1,nr-1\n IF (j /= i) wp=wp*(z-x(j))\n END DO\n q=q+wp\n END DO\n gd=(pd-q*fd)/p\n z=z-fd/gd\n IF (.NOT.(DABS(z-z0) > DABS(z)*1.0D-15)) EXIT\n END DO\n 40 x(nr)=z\n x(n+1-nr)=-z\n w(nr)=2.0D0/((1.0D0-z*z)*pd*pd)\n w(n+1-nr)=w(nr)\nEND DO\nRETURN\nEND SUBROUTINE legzo\n", "meta": {"hexsha": "f43bacb7c96aae5471c2a6b32950a95137d559d2", "size": 2625, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MATLAB/f2matlab/comp_spec_func/mlegzo.f90", "max_stars_repo_name": "vasaantk/bin", "max_stars_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATLAB/f2matlab/comp_spec_func/mlegzo.f90", "max_issues_repo_name": "vasaantk/bin", "max_issues_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATLAB/f2matlab/comp_spec_func/mlegzo.f90", "max_forks_repo_name": "vasaantk/bin", "max_forks_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2258064516, "max_line_length": 68, "alphanum_fraction": 0.4773333333, "num_tokens": 856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582995, "lm_q2_score": 0.8459424373085145, "lm_q1q2_score": 0.7686384362201845}} {"text": "\n! Code by: Jostein Brandshoi\n\nPROGRAM advection_solver\n IMPLICIT NONE\n ! ------------------------------- VARIABLE DECLARATIONS -------------------------------\n double precision, parameter :: L = 50000.0 ! Location (L/2) where initial bell is max [m]\n double precision, parameter :: sigma = L / 10.0 ! Measure of with of initial Gaussian bell [m]\n double precision, parameter :: theta_0 = 10.0 ! Max temperature value of initial bell [deg C]\n double precision, parameter :: u_0 = 1.0 ! Advection speed (constant here) [m/s]\n double precision, parameter :: epsilon = 1E-5\n\n double precision, parameter :: C = 0.50 ! Courant number [u_0 * delta_t / delta_x] [m/s]\n double precision, parameter :: delta_x = sigma / 10.0 ! Distance between spatial gridpoints [m]\n double precision, parameter :: delta_t = C * delta_x / u_0 ! Time between temporal gridpoints [s]\n double precision :: x_j\n\n integer :: j, n ! Counter variables (j: space, n: time)\n integer :: n_temp, n_curr = 1, n_next = 2 ! Indices to represent curr and next time stetp\n integer, parameter :: j_max = idint(L / delta_x + 1) ! Max number of space points in [0: j = 1, L: j = j_max]\n integer, parameter :: n_max = idint((25 * L) / (u_0 * delta_t)) ! Max number of time points needed for 25 cycles\n integer, parameter :: n_05c = idint((5 * L) / (u_0 * delta_t)) ! Number of time points needed for 5 cycles\n integer, parameter :: n_10c = idint((10 * L) / (u_0 * delta_t)) ! Number of time points needed for 10 cycles\n integer, parameter :: n_15c = idint((15 * L) / (u_0 * delta_t)) ! Number of time points needed for 15 cycles\n integer, parameter :: n_20c = idint((20 * L) / (u_0 * delta_t)) ! Number of time points needed for 20 cycles\n\n double precision :: theta_j_star, theta_jp1_star\n double precision :: theta_jm1_star, theta_jm2_star\n double precision :: u_j_star, u_jm1_star, F_j_star, F_jm1_star\n double precision, dimension(j_max, 2) :: theta = 0.0 ! 2D-array to store solution at time points n and n + 1\n\n character(len = 32) :: output_filename ! Variable to hold output filename for results\n ! -------------------------------------------------------------------------------------\n\n ! -------------------------------- INITIAL CONDITION ----------------------------------\n do j = 1, j_max ! Loop over all space points in the defined region [0, L]\n x_j = (j - 1) * delta_x ! x-value corresponding to the j'th gridpoint in space\n theta(j, n_curr) = theta_0 * dexp(-((2 * x_j - L) / sigma) ** 2) ! Init. con.\n end do\n ! -------------------------------------------------------------------------------------\n\n ! -------- GETTING FILENAME FROM CMD-LINE AND OPEN .DAT FILE FOR RESULT OUTPUT --------\n CALL GET_COMMAND_ARGUMENT(1, output_filename) ! Get cmd-line arg for output file\n open(unit = 10, file = output_filename, form = \"formatted\") ! Open file that will store results\n ! -------------------------------------------------------------------------------------\n\n ! --------------------------- USING UPWIND SCHEME AND BC'S ----------------------------\n do n = 0, n_max ! Loop, in time as long as necessary to complete requested number of cycles\n theta(1, n_curr) = theta(j_max, n_curr) ! Cyclic boundary condition (theta(0, t) = theta(L, t))\n\n do j = 2, j_max ! Loop over all space points in the defined region [0, L]\n theta_j_star = theta(j, n_curr) - C * (theta(j, n_curr) - theta(j - 1, n_curr)) ! Upwind scheme\n F_j_star = 0.0\n F_jm1_star = 0.0\n\n if (j >= 4 .and. j <= j_max - 3) then\n theta_jp1_star = theta(j + 1, n_curr) - C * (theta(j + 1, n_curr) - theta(j, n_curr))\n theta_jm1_star = theta(j - 1, n_curr) - C * (theta(j - 1, n_curr) - theta(j - 2, n_curr))\n theta_jm2_star = theta(j - 2, n_curr) - C * (theta(j - 2, n_curr) - theta(j - 3, n_curr))\n u_j_star = 1.3 * 0.25 * (1 - C) * u_0 * ((theta_jp1_star - theta_jm1_star) / (theta_j_star + epsilon))\n u_jm1_star = 1.3 * 0.25 * (1 - C) * u_0 * ((theta_j_star - theta_jm2_star) / (theta_jm1_star + epsilon))\n F_j_star = 0.5 * ((u_j_star + dabs(u_j_star)) * theta_j_star + (u_j_star - &\n dabs(u_j_star)) * theta_jp1_star) * (delta_t / delta_x)\n F_jm1_star = 0.5 * ((u_jm1_star + dabs(u_jm1_star)) * theta_jm1_star + &\n (u_jm1_star - dabs(u_jm1_star)) * theta_j_star) * (delta_t / delta_x)\n end if\n\n theta(j, n_next) = theta_j_star - (F_j_star - F_jm1_star)\n end do\n\n ! Write theta to file for time steps corresponding to the requested cycles.\n if (n == 0 .or. n == n_05c .or. n == n_10c .or. n == n_15c .or. n == n_20c .or. n == n_max) then\n write(unit = 10, fmt = \"(102f20.14)\") float(n), theta(:, n_curr) / theta_0 ! Write line-wise\n end if\n\n n_temp = n_next ! Set help index to second theta column (2)\n n_next = n_curr ! Set next time step index to first theta column (1)\n n_curr = n_temp ! Set current time step index to second column (2)\n end do\n ! -------------------------------------------------------------------------------------\n\n close(unit = 10) ! Close file after writing\n\nEND PROGRAM advection_solver\n", "meta": {"hexsha": "4f954e5f1b5abb8b24a71ddbb43a44c537fd6819", "size": 5654, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "project2/advection.f90", "max_stars_repo_name": "jostbr/GEF4510-Projects", "max_stars_repo_head_hexsha": "1dc6d42b60672481ac6c0ea61268127a8c683e7b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-05T12:44:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-05T12:44:32.000Z", "max_issues_repo_path": "project2/advection.f90", "max_issues_repo_name": "jostbr/GEF4510-Projects", "max_issues_repo_head_hexsha": "1dc6d42b60672481ac6c0ea61268127a8c683e7b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "project2/advection.f90", "max_forks_repo_name": "jostbr/GEF4510-Projects", "max_forks_repo_head_hexsha": "1dc6d42b60672481ac6c0ea61268127a8c683e7b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 66.5176470588, "max_line_length": 124, "alphanum_fraction": 0.5298903431, "num_tokens": 1537, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422227627597, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7685868522348092}} {"text": " Program Main\n!====================================================================\n! eigenvalues and eigenvectors of a real symmetric matrix\n! Method: calls Jacobi\n!====================================================================\nimplicit none\ninteger, parameter :: n=3\ndouble precision :: a(n,n), x(n,n)\ndouble precision, parameter:: abserr=1.0e-09\ninteger i, j\n\n! matrix A\n data (a(1,i), i=1,3) / 1.0, 2.0, 3.0 /\n data (a(2,i), i=1,3) / 2.0, 2.0, -2.0 /\n data (a(3,i), i=1,3) / 3.0, -2.0, 4.0 /\n\n! print a header and the original matrix\n write (*,200)\n do i=1,n\n write (*,201) (a(i,j),j=1,n)\n end do\n\n call Jacobi(a,x,abserr,n)\n\n! print solutions\n write (*,202)\n write (*,201) (a(i,i),i=1,n)\n write (*,203)\n do i = 1,n\n write (*,201) (x(i,j),j=1,n)\n end do\n\n200 format (' Eigenvalues and eigenvectors (Jacobi method) ',/, &\n ' Matrix A')\n201 format (6f12.6)\n202 format (/,' Eigenvalues')\n203 format (/,' Eigenvectors')\nend program main\n\nsubroutine Jacobi(a,x,abserr,n)\n!===========================================================\n! Evaluate eigenvalues and eigenvectors\n! of a real symmetric matrix a(n,n): a*x = lambda*x \n! method: Jacoby method for symmetric matrices \n! Alex G. (December 2009)\n!-----------------------------------------------------------\n! input ...\n! a(n,n) - array of coefficients for matrix A\n! n - number of equations\n! abserr - abs tolerance [sum of (off-diagonal elements)^2]\n! output ...\n! a(i,i) - eigenvalues\n! x(i,j) - eigenvectors\n! comments ...\n!===========================================================\nimplicit none\ninteger i, j, k, n\ndouble precision a(n,n),x(n,n)\ndouble precision abserr, b2, bar\ndouble precision beta, coeff, c, s, cs, sc\n\n! initialize x(i,j)=0, x(i,i)=1\n! *** the array operation x=0.0 is specific for Fortran 90/95\nx = 0.0\ndo i=1,n\n x(i,i) = 1.0\nend do\n\n! find the sum of all off-diagonal elements (squared)\nb2 = 0.0\ndo i=1,n\n do j=1,n\n if (i.ne.j) b2 = b2 + a(i,j)**2\n end do\nend do\n\nif (b2 <= abserr) return\n\n! average for off-diagonal elements /2\nbar = 0.5*b2/float(n*n)\n\ndo while (b2.gt.abserr)\n do i=1,n-1\n do j=i+1,n\n if (a(j,i)**2 <= bar) cycle ! do not touch small elements\n b2 = b2 - 2.0*a(j,i)**2\n bar = 0.5*b2/float(n*n)\n! calculate coefficient c and s for Givens matrix\n beta = (a(j,j)-a(i,i))/(2.0*a(j,i))\n coeff = 0.5*beta/sqrt(1.0+beta**2)\n s = sqrt(max(0.5+coeff,0.0))\n c = sqrt(max(0.5-coeff,0.0))\n! recalculate rows i and j\n do k=1,n\n cs = c*a(i,k)+s*a(j,k)\n sc = -s*a(i,k)+c*a(j,k)\n a(i,k) = cs\n a(j,k) = sc\n end do\n! new matrix a_{k+1} from a_{k}, and eigenvectors \n do k=1,n\n cs = c*a(k,i)+s*a(k,j)\n sc = -s*a(k,i)+c*a(k,j)\n a(k,i) = cs\n a(k,j) = sc\n cs = c*x(k,i)+s*x(k,j)\n sc = -s*x(k,i)+c*x(k,j)\n x(k,i) = cs\n x(k,j) = sc\n end do\n end do\n end do\nend do\nreturn\nend\n", "meta": {"hexsha": "5ea4dda8a78746a6f0ea28661330999d0bfd6f17", "size": 2960, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "OMP_Fortran.f90", "max_stars_repo_name": "minar09/parallel-computing", "max_stars_repo_head_hexsha": "658f8adbc6920ac7e368e68034a2ebf035d56737", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-04-12T15:15:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-05T16:24:03.000Z", "max_issues_repo_path": "OMP_Fortran.f90", "max_issues_repo_name": "minar09/parallel-computing", "max_issues_repo_head_hexsha": "658f8adbc6920ac7e368e68034a2ebf035d56737", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "OMP_Fortran.f90", "max_forks_repo_name": "minar09/parallel-computing", "max_forks_repo_head_hexsha": "658f8adbc6920ac7e368e68034a2ebf035d56737", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.5172413793, "max_line_length": 69, "alphanum_fraction": 0.5060810811, "num_tokens": 1027, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.951142221377825, "lm_q2_score": 0.808067208930584, "lm_q1q2_score": 0.7685868401248147}} {"text": " SUBROUTINE DF01MD( SICO, N, DT, A, DWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the sine transform or cosine transform of a real\nC signal.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC SICO CHARACTER*1\nC Indicates whether the sine transform or cosine transform\nC is to be computed as follows:\nC = 'S': The sine transform is computed;\nC = 'C': The cosine transform is computed.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The number of samples. N must be a power of 2 plus 1.\nC N >= 5.\nC\nC DT (input) DOUBLE PRECISION\nC The sampling time of the signal.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (N)\nC On entry, this array must contain the signal to be\nC processed.\nC On exit, this array contains either the sine transform, if\nC SICO = 'S', or the cosine transform, if SICO = 'C', of the\nC given signal.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (N+1)\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC Let A(1), A(2),..., A(N) be a real signal of N samples.\nC\nC If SICO = 'S', the routine computes the sine transform of A as\nC follows. First, transform A(i), i = 1,2,...,N, into the complex\nC signal B(i), i = 1,2,...,(N+1)/2, where\nC\nC B(1) = -2*A(2),\nC B(i) = {A(2i-2) - A(2i)} - j*A(2i-1) for i = 2,3,...,(N-1)/2,\nC B((N+1)/2) = 2*A(N-1) and j**2 = -1.\nC\nC Next, perform a discrete inverse Fourier transform on B(i) by\nC calling SLICOT Library Routine DG01ND, to give the complex signal\nC Z(i), i = 1,2,...,(N-1)/2, from which the real signal C(i) may be\nC obtained as follows:\nC\nC C(2i-1) = Re(Z(i)), C(2i) = Im(Z(i)) for i = 1,2,...,(N-1)/2.\nC\nC Finally, compute the sine transform coefficients S ,S ,...,S\nC 1 2 N\nC given by\nC\nC S = 0,\nC 1\nC { [C(k) + C(N+1-k)] }\nC S = DT*{[C(k) - C(N+1-k)] - -----------------------},\nC k { [2*sin(pi*(k-1)/(N-1))]}\nC\nC for k = 2,3,...,N-1, and\nC\nC S = 0.\nC N\nC\nC If SICO = 'C', the routine computes the cosine transform of A as\nC follows. First, transform A(i), i = 1,2,...,N, into the complex\nC signal B(i), i = 1,2,...,(N+1)/2, where\nC\nC B(1) = 2*A(1),\nC B(i) = 2*A(2i-1) + 2*j*{[A(2i-2) - A(2i)]}\nC for i = 2,3,...,(N-1)/2 and B((N+1)/2) = 2*A(N).\nC\nC Next, perform a discrete inverse Fourier transform on B(i) by\nC calling SLICOT Library Routine DG01ND, to give the complex signal\nC Z(i), i = 1,2,...,(N-1)/2, from which the real signal D(i) may be\nC obtained as follows:\nC\nC D(2i-1) = Re(Z(i)), D(2i) = Im(Z(i)) for i = 1,2,...,(N-1)/2.\nC\nC Finally, compute the cosine transform coefficients S ,S ,...,S\nC 1 2 N\nC given by\nC\nC S = 2*DT*[D(1) + A0],\nC 1\nC { [D(k) - D(N+1-k)] }\nC S = DT*{[D(k) + D(N+1-k)] - -----------------------},\nC k { [2*sin(pi*(k-1)/(N-1))]}\nC\nC\nC for k = 2,3,...,N-1, and\nC\nC S = 2*DT*[D(1) - A0],\nC N\nC (N-1)/2\nC where A0 = 2*SUM A(2i).\nC i=1\nC\nC REFERENCES\nC\nC [1] Rabiner, L.R. and Rader, C.M.\nC Digital Signal Processing.\nC IEEE Press, 1972.\nC\nC [2] Oppenheim, A.V. and Schafer, R.W.\nC Discrete-Time Signal Processing.\nC Prentice-Hall Signal Processing Series, 1989.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm requires 0( N*log(N) ) operations.\nC\nC CONTRIBUTORS\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Feb. 1997.\nC Supersedes Release 2.0 routine DF01AD by F. Dumortier, and\nC R.M.C. Dekeyser, State University of Gent, Belgium.\nC\nC REVISIONS\nC\nC V. Sima, Jan. 2003.\nC\nC KEYWORDS\nC\nC Digital signal processing, fast Fourier transform, complex\nC signals.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE, TWO, FOUR\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0,\n $ FOUR = 4.0D0 )\nC .. Scalar Arguments ..\n CHARACTER SICO\n INTEGER INFO, N\n DOUBLE PRECISION DT\nC .. Array Arguments ..\n DOUBLE PRECISION A(*), DWORK(*)\nC .. Local Scalars ..\n LOGICAL LSICO, LSIG\n INTEGER I, I2, IND1, IND2, M, MD2\n DOUBLE PRECISION A0, PIBYM, W1, W2, W3\nC .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nC .. External Subroutines ..\n EXTERNAL DG01ND, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC ATAN, DBLE, MOD, SIN\nC .. Executable Statements ..\nC\n INFO = 0\n LSICO = LSAME( SICO, 'S' )\nC\nC Test the input scalar arguments.\nC\n IF( .NOT.LSICO .AND. .NOT.LSAME( SICO, 'C' ) ) THEN\n INFO = -1\n ELSE\n M = 0\n IF( N.GT.4 ) THEN\n M = N - 1\nC WHILE ( MOD( M, 2 ).EQ.0 ) DO\n 10 CONTINUE\n IF ( MOD( M, 2 ).EQ.0 ) THEN\n M = M/2\n GO TO 10\n END IF\nC END WHILE 10\n END IF\n IF ( M.NE.1 ) INFO = -2\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'DF01MD', -INFO )\n RETURN\n END IF\nC\nC Initialisation.\nC\n M = N - 1\n MD2 = ( N + 1 )/2\n PIBYM = FOUR*ATAN( ONE )/DBLE( M )\n I2 = 1\n DWORK(MD2+1) = ZERO\n DWORK(2*MD2) = ZERO\nC\n IF ( LSICO ) THEN\nC\nC Sine transform.\nC\n LSIG = .TRUE.\n DWORK(1) = -TWO*A(2)\n DWORK(MD2) = TWO*A(M)\nC\n DO 20 I = 4, M, 2\n I2 = I2 + 1\n DWORK(I2) = A(I-2) - A(I)\n DWORK(MD2+I2) = -A(I-1)\n 20 CONTINUE\nC\n ELSE\nC\nC Cosine transform.\nC\n LSIG = .FALSE.\n DWORK(1) = TWO*A(1)\n DWORK(MD2) = TWO*A(N)\n A0 = A(2)\nC\n DO 30 I = 4, M, 2\n I2 = I2 + 1\n DWORK(I2) = TWO*A(I-1)\n DWORK(MD2+I2) = TWO*( A(I-2) - A(I) )\n A0 = A0 + A(I)\n 30 CONTINUE\nC\n A0 = TWO*A0\n END IF\nC\nC Inverse Fourier transform.\nC\n CALL DG01ND( 'Inverse', MD2-1, DWORK(1), DWORK(MD2+1), INFO )\nC\nC Sine or cosine coefficients.\nC\n IF ( LSICO ) THEN\n A(1) = ZERO\n A(N) = ZERO\n ELSE\n A(1) = TWO*DT*( DWORK(1) + A0 )\n A(N) = TWO*DT*( DWORK(1) - A0 )\n END IF\nC\n IND1 = MD2 + 1\n IND2 = N\nC\n DO 40 I = 1, M - 1, 2\n W1 = DWORK(IND1)\n W2 = DWORK(IND2)\n IF ( LSIG ) W2 = -W2\n W3 = TWO*SIN( PIBYM*DBLE( I ) )\n A(I+1) = DT*( W1 + W2 - ( W1 - W2 )/W3 )\n IND1 = IND1 + 1\n IND2 = IND2 - 1\n 40 CONTINUE\nC\n IND1 = 2\n IND2 = MD2 - 1\nC\n DO 50 I = 2, M - 2, 2\n W1 = DWORK(IND1)\n W2 = DWORK(IND2)\n IF ( LSIG ) W2 = -W2\n W3 = TWO*SIN( PIBYM*DBLE( I ) )\n A(I+1) = DT*( W1 + W2 - ( W1 - W2 )/W3 )\n IND1 = IND1 + 1\n IND2 = IND2 - 1\n 50 CONTINUE\nC\n RETURN\nC *** Last line of DF01MD ***\n END\n", "meta": {"hexsha": "3596540a9d802b1509b50b05052915fc61f153f4", "size": 7739, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/DF01MD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/DF01MD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/DF01MD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 27.0594405594, "max_line_length": 72, "alphanum_fraction": 0.4691820649, "num_tokens": 2738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422186079557, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.7685868356883994}} {"text": "SUBROUTINE tridiag(a,b,c,r,u,N)\n! solves a tridiagonal linear system Au = r\n\n! algorithm comes from Numerical Recipes book\n\n! a,b,c are vectors of length N giving the non-zero elements of matrix A\n! a(2:N) are the entries to the left of the main diagonal (a(1) is ignored)\n! b(1:N) are main diagonal elements\n! c(1:N-1) are to the right of main diagonal (c(N) is ignored)\n! r is a vector of length N giving RHS of matrix equation\n! u is the unknown vector we are solving for\n\tINTEGER N,j\n\tREAL*8, DIMENSION(N) :: a,b,c,r,u\n\tREAL*8, DIMENSION(N) :: gam\n\tREAL*8 bet\n\t\n\tbet = b(1)\n\tIF (bet == 0.) THEN\n\t\tPRINT *, 'First diagonal element is zero'\n\t\tSTOP\n\tEND IF\n\tu(1) = r(1)/bet\n\tDO j=2,N\n\t\tgam(j) = c(j-1)/bet\n\t\tbet = b(j)-a(j)*gam(j)\n\t\tIF (bet == 0.) THEN\n\t\t\tPRINT *, 'tridiag trying to divide by zero'\n\t\t\tSTOP\n\t\tEND IF\n\t\tu(j) = (r(j)-a(j)*u(j-1))/bet\n\tEND DO\n\tDO j=N-1,1,-1\n\t\tu(j) = u(j) - gam(j+1)*u(j+1)\n\tEND DO\n\tRETURN\nEND SUBROUTINE tridiag\t\n\nsubroutine polyfit(n,X,Y,m,coeffs)\n\ninteger n, m ! number of points and degree of polynomial\n\ninteger i,ij,j,k,n1,m1,m2\nreal*8 C(m+2,m+2), A(m+2), B(m+2), Xc(m+2), Yx(m+2)\nreal*8 p,xx,s,yc\nreal*8 X(n), Y(n), coeffs(m+1)\n\ncoeffs = 0.d0\n n1=n; m1=m+1; m2=m+2\n do k=1, m2\n Xc(k)=0.d0\n do i=1, n1\n\t Xc(k) = Xc(k) + X(i)**k\n end do\n end do\n yc=0.d0\n do i=1, n1 \n yc = yc + Y(i)\n end do\n do k=1, m\n Yx(k)=0.d0\n do i=1, n1\n\t Yx(k) = Yx(k) + Y(i)*X(i)**k\n end do \n end do\n do i=1, m1\n\tdo j=1, m1\n ij=i+j-2\n if (i==1.and.j==1) then\n\t C(1,1) = n1\n else \n\t C(i,j)=Xc(ij)\n end if \n end do\n end do\n B(1)=yc; \n do i=2,m1\n B(i)=Yx(i-1)\n end do \n do k=1, m\n do i=k+1, m1\n B(i) = B(i) - C(i,k)/C(k,k)*B(k)\n do j=k+1, m1\n C(i,j) = C(i,j) - C(i,k)/C(k,k)*C(k,j)\n end do\n end do\n end do\n coeffs(m1)=B(m1)/C(m1,m1)\n do i=m, 1, -1\n s=0.d0\n do k=i+1, m1 \n\t s = s + C(i,k)*coeffs(k)\n end do \n coeffs(i) = (B(i)-s)/C(i,i)\n end do\nend subroutine polyfit", "meta": {"hexsha": "c4acfd7b20357a959f072ab61abc8b6f0266414e", "size": 2004, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran_code/tridiag.f95", "max_stars_repo_name": "brian-rose/EMomBM", "max_stars_repo_head_hexsha": "06e23e5b9370ef92ff33a901a06013de9463bc1d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran_code/tridiag.f95", "max_issues_repo_name": "brian-rose/EMomBM", "max_issues_repo_head_hexsha": "06e23e5b9370ef92ff33a901a06013de9463bc1d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran_code/tridiag.f95", "max_forks_repo_name": "brian-rose/EMomBM", "max_forks_repo_head_hexsha": "06e23e5b9370ef92ff33a901a06013de9463bc1d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.0947368421, "max_line_length": 76, "alphanum_fraction": 0.5479041916, "num_tokens": 890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.8175744784160989, "lm_q1q2_score": 0.768449166740314}} {"text": "program insertion\nimplicit none\n!-----------------------------------------------------------------\n! This programme sorts a series of values in increasing order,\n! using insertion sort, implemented with one working array\n!\n! It works like this:\n! unsorted: A = [5, 3, 4, 1, 2, 6]\n! sorting:\n! pass 1: A = [3, 5, 4, 1, 2, 6]\n! pass 2: A = [3, 4, 5, 1, 2, 6]\n! pass 3: A = [1, 3, 4, 5, 2, 6]\n! pass 4: A = [1, 2, 3, 4, 5, 6]\n! pass 5: B = [1, 2, 3, 4, 5, 6]\n!------------------------------------------------------\n\nreal(kind=8), allocatable, dimension(:) :: A\nreal :: temp\ninteger :: i, j, k, n\n\n!------------------------------------------------------------\n! Make some random array of size n:\n!------------------------------------------------------------\nwrite(*,*) 'size od array?'\nread(*,*) n\nallocate (A(n))\n\ncall random_seed()\ndo i = 1, n\n call random_number(A(i))\n A(i) = (A(i) * 100.0)\n A(i) = real(nint(A(i)*1000)) / 1000.0 !rounding off to 3 decimal places\nend do\nwrite(*,'(A3,10F7.3)') ' A ', A\n\n!------------------------------------------------------------\n! The actual sorting:\n!------------------------------------------------------------\ndo i = 2, n\n do j = 1, i-1 \n if (A(j) .ge. A(i)) then\n temp = A(i)\n do k = i-1, j, -1 !from the first smaller than i to j\n A(k+1) = A(k) !move every element by one\n end do\n A(j) = temp\n exit\n end if\n end do\nend do\nwrite(*,'(A3,10F7.3)') ' A ', A\nend program insertion\n", "meta": {"hexsha": "18c1b94efabce5ad1af141aeb6d867ed7bc1668d", "size": 1489, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "insertion_sort/insertion1array_no_writes.f95", "max_stars_repo_name": "ElenaKusevska/Fortran_exercises", "max_stars_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "insertion_sort/insertion1array_no_writes.f95", "max_issues_repo_name": "ElenaKusevska/Fortran_exercises", "max_issues_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "insertion_sort/insertion1array_no_writes.f95", "max_forks_repo_name": "ElenaKusevska/Fortran_exercises", "max_forks_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0943396226, "max_line_length": 74, "alphanum_fraction": 0.4103425118, "num_tokens": 481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.8519528019683106, "lm_q1q2_score": 0.7683938430304782}} {"text": "MODULE m_trapz\n !General Purpose trapezian method integration\n !Used in green's function calculations because the\n !integrands are very spiky\n\n IMPLICIT NONE\n\n INTERFACE trapz\n PROCEDURE :: trapzr, trapzc\n END INTERFACE\n\n CONTAINS\n\n PURE REAL FUNCTION trapzr(y,h,n)\n\n REAL, INTENT(IN) :: y(:)\n\n INTEGER, INTENT(IN) :: n\n REAL, INTENT(IN) :: h\n\n INTEGER i\n\n trapzr = y(1)\n DO i = 2, n-1\n trapzr = trapzr + 2*y(i)\n ENDDO\n trapzr = trapzr + y(n)\n\n trapzr = trapzr*h/2.0\n\n END FUNCTION trapzr\n\n PURE COMPLEX FUNCTION trapzc(y,h,n)\n\n COMPLEX, INTENT(IN) :: y(:)\n\n INTEGER, INTENT(IN) :: n\n REAL, INTENT(IN) :: h\n\n INTEGER i\n\n trapzc = y(1)\n DO i = 2, n-1\n trapzc = trapzc + 2*y(i)\n ENDDO\n trapzc = trapzc + y(n)\n\n trapzc = trapzc*h/2.0\n\n END FUNCTION trapzc\n\n\nEND MODULE m_trapz", "meta": {"hexsha": "4872e2d2e70aefc853fdc14c0d4292b1b1cfa3b2", "size": 975, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "math/trapz.f90", "max_stars_repo_name": "MRedies/FLEUR", "max_stars_repo_head_hexsha": "84234831c55459a7539e78600e764ff4ca2ec4b6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "math/trapz.f90", "max_issues_repo_name": "MRedies/FLEUR", "max_issues_repo_head_hexsha": "84234831c55459a7539e78600e764ff4ca2ec4b6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math/trapz.f90", "max_forks_repo_name": "MRedies/FLEUR", "max_forks_repo_head_hexsha": "84234831c55459a7539e78600e764ff4ca2ec4b6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.3962264151, "max_line_length": 53, "alphanum_fraction": 0.5292307692, "num_tokens": 312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067211996142, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.7683620920925794}} {"text": "! -*- Mode: Fortran90; -*-\n!-----------------------------------------------------------------\n! Daniel R. Reynolds\n! SMU, Mathematics\n! Math 6370\n! 9 January 2009\n!=================================================================\n\n\nsubroutine chem_solver(T,u,v,w,lam,eps,maxit,its,res)\n !-----------------------------------------------------------------\n ! Description: \n ! Computes the equilibrium chemical concentrations, given a \n ! background temperature field, of a simple reaction network:\n ! u + x -> v with rate k1\n ! u + x <- v with rate k2\n ! v -> w with rate k3\n ! v <- w with rate k4,\n ! where we have assumed that the total concentration \n ! (x+u+v+w) = 1, and where k1(T), k2(T), k3(T), and k4(T) are \n ! the temperature-dependent coefficient functions,\n ! k1(T) = exp(-5*T),\n ! k2(T) = atan(5*(T-1/2))/3 + 1/2,\n ! k3(T) = 1/cosh(5*(T-1/2)),\n ! k4(T) = tanh(5*(T-1/2)^2).\n ! Using the conservation relation, we write the constrained \n ! ODE system\n ! x = 1 - u - v - w,\n ! u_t = k2*v - k1*u*x,\n ! v_t = k1*u*x - (k2+k3)*v + k4*w,\n ! w_t = k3*v - k4*w.\n ! Inserting the constraint equation into the rate equations, \n ! and setting the time derivatives equal to zero (to find \n ! equilibrium concentrations), we have the system\n ! 0 = k2*v + k1*u*(u+v+w-1) = fu(u,v,w),\n ! 0 = k1*u*(1-u-v-w) - (k2+k3)*v + k4*w = fv(u,v,w),\n ! 0 = k3*v - k4*w = fw(u,v,w),\n ! where each of the rate coefficients are frozen at the fixed \n ! temperature T. \n !\n ! To solve this system, we call a simple damped fixed-point \n ! iteration: given an initial guess X0, compute iterates\n ! Xn = X{n-1} + lambda*f, \n ! where 0 < lambda <= 1 is the damping parameter. We compute \n ! these iterates Xn until |f(Xn)| < epsilon.\n ! \n ! Arguments:\n ! T - double (input), temperature\n ! u - double (in/out), concentration (in: guess, out: solution)\n ! v - double (in/out), concentration (in: guess, out: solution)\n ! w - double (in/out), concentration (in: guess, out: solution)\n ! lam - double (in), damping parameter (lambda)\n ! eps - double (in), nonlinear solver tolerance (epsilon)\n ! maxit - integer (in), maximum allowed iterations\n ! its - integer (out), # of iterations required for convergence\n ! res - double (out), final nonlinear residual (max norm)\n !-----------------------------------------------------------------\n !======= Inclusions ===========\n\n !======= Declarations =========\n implicit none\n integer, intent(in) :: maxit\n integer, intent(out) :: its\n double precision, intent(in) :: T, lam, eps\n double precision, intent(out) :: res\n double precision, intent(inout) :: u, v, w\n\n double precision :: k1, k2, k3, k4, f(3)\n\n !======= Internals ============\n\n ! compute chemical rate coefficients\n k1 = exp(-5.d0*T)\n k2 = atan(5.d0*(T-0.5d0))/3.d0 + 0.5d0\n k3 = 1.d0/cosh(5.d0*(T-0.5d0))\n k4 = tanh(5.d0*(T-0.5d0)**2)\n\n ! compute initial residual function\n f = chem_residual()\n res = maxval(abs(f))\n\n ! loop\n do its = 0,maxit\n\n if (res < eps) exit\n\n ! fixed-point iteration solution update\n u = u + lam*f(1)\n v = v + lam*f(2)\n w = w + lam*f(3)\n\n ! compute residuals\n f = chem_residual()\n res = maxval(abs(f))\n\n enddo\n\ncontains\n\n function chem_residual()\n double precision :: chem_residual(3)\n chem_residual(1) = k2*v + k1*u*(u+v+w-1.d0)\n chem_residual(2) = k1*u*(1.d0-u-v-w) - (k2+k3)*v + k4*w\n chem_residual(3) = k3*v - k4*w\n end function chem_residual\n\nend subroutine chem_solver\n!=================================================================\n", "meta": {"hexsha": "ccf410474d2bc659441c9fb31999e168ad6802ad", "size": 3792, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "chemistry/chem_solver.f90", "max_stars_repo_name": "drreynolds/Math6370-codes", "max_stars_repo_head_hexsha": "5fbc413204c64dabf9a262f308314da3d372f98e", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-05T01:11:31.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-05T01:11:31.000Z", "max_issues_repo_path": "chemistry/chem_solver.f90", "max_issues_repo_name": "drreynolds/Math6370-codes", "max_issues_repo_head_hexsha": "5fbc413204c64dabf9a262f308314da3d372f98e", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chemistry/chem_solver.f90", "max_forks_repo_name": "drreynolds/Math6370-codes", "max_forks_repo_head_hexsha": "5fbc413204c64dabf9a262f308314da3d372f98e", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.7889908257, "max_line_length": 68, "alphanum_fraction": 0.5176687764, "num_tokens": 1155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7683510294524577}} {"text": "\n! Program by: Jostein Brandshoi\n\nPROGRAM exercise_2d\n ! This program solves the diffusion equation numerically for the oceanic boundary layer with the initial- and\n ! boundary conditions given in the exercise. After execution a file (with filename specified as a command line\n ! argument) will be outputed with the results for specific time-values. Thi program can be compiled and executed\n ! by itself just fine, but the script visualize_results.py automates the process and provides plot of the results.\n IMPLICIT NONE\n\n ! ------------------------------- VARIABLE DECLARATIONS -------------------------------\n integer :: j, n ! Counter variables used in loops below (j: space, n: time)\n integer, parameter :: j_max = 27, n_max = 1201 ! Maximum number of gridpoints in space and time\n\n double precision, parameter :: D = 30.0 ! Hight of the oceanic boundary layer [m]\n double precision, parameter :: psi_0 = 10.0 ! Steady max temperature at top of ocean [deg C]\n double precision, parameter :: K = 0.45 ! K = (kappa * delta_t) / delta_z [dim-less]\n double precision, parameter :: kappa_O = 30.0 * 1E-4 ! Diffusion coefficient for the ocean [m^2/s]\n double precision, parameter :: delta_z = D / (j_max - 1.0) ! Increment in space (j_max points implies (j_max - 1) steps) [m]\n double precision, parameter :: delta_t = (K * delta_z ** 2) / kappa_O ! Increment in time [s]\n double precision, parameter :: gmma = 1.5, t_c = 6.0 * 24 * 3600 ! Gamma parameter [dim-less], Reference time of 6 days [s]\n\n double precision, dimension(1 : j_max) :: psi_n, psi_np1, psi_temp\n double precision :: t_n ! t-value in [0, H] to represent time. Used in boundary con. [m]\n\n character(len = 32) :: output_filename ! Variable to hold output filename specified by cmd-line arg\n ! -------------------------------------------------------------------------------------\n\n ! -------------------------- INITIAL AND BOUNDARY CONDITIONS --------------------------\n psi_n(:) = 0.0 ! Initially the water column n has 0 deg C for all the z-values\n ! -------------------------------------------------------------------------------------\n\n ! ------- GETTING FILENAME FROM CMD-LINE AND WRITE RESULTS TO .DAT-FILE. EACH LINE CORRESPONDS TO ONE N-VALUES -------\n CALL GET_COMMAND_ARGUMENT(1, output_filename) ! Get command line argument that specifies output file\n open(unit = 10, file = output_filename, form = \"formatted\") ! Open file that will store results based on cmd-line arg\n ! -------------------------------------------------------------------------------------\n\n ! ------------------------ SOLVING THE EQUATION WITH FTCS-SCHEME ----------------------\n do n = 0, n_max - 2\n do j = 2, j_max - 1\n t_n = n * delta_t ! Compute t-value at n'th time point\n psi_np1(1) = 0.0 ! The bottom (z = -D) is held at 0 deg C for all times\n psi_np1(j_max) = psi_0 * tanh((gmma * t_n) / t_c) ! Compute psi at top (z = 0) for each t_n according to BC.\n psi_np1(j) = psi_n(j) + K * (psi_n(j + 1) - 2 * psi_n(j) + psi_n(j - 1))\n end do\n\n ! Write psi for the requested n-values (plus some more) to a .dat file where each line is on the form \"n psi(1) psi(2) ...\"\n if (n == 0 .or. n == 100 .or. n == 200 .or. n == 400 .or. n == 600 .or. n == 800 .or. n == 1000 .or. n == 1199) then\n write(unit = 10, fmt = \"(28f20.14)\") float(n), psi_n(:) / psi_0\n end if\n\n psi_n = psi_np1 ! Update psi_n to be the value of the newly computed timestep\n end do\n ! -------------------------------------------------------------------------------------\n\n close(unit = 10)! Close file after writing\n\nEND PROGRAM exercise_2d\n", "meta": {"hexsha": "db0b173b137eae14716daa9ae6aad5438ce97a0c", "size": 4199, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "project1/ocean_application.f90", "max_stars_repo_name": "jostbr/GEF4510-Projects", "max_stars_repo_head_hexsha": "1dc6d42b60672481ac6c0ea61268127a8c683e7b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-05T12:44:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-05T12:44:32.000Z", "max_issues_repo_path": "project1/ocean_application.f90", "max_issues_repo_name": "jostbr/GEF4510-Projects", "max_issues_repo_head_hexsha": "1dc6d42b60672481ac6c0ea61268127a8c683e7b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "project1/ocean_application.f90", "max_forks_repo_name": "jostbr/GEF4510-Projects", "max_forks_repo_head_hexsha": "1dc6d42b60672481ac6c0ea61268127a8c683e7b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 71.1694915254, "max_line_length": 149, "alphanum_fraction": 0.504167659, "num_tokens": 983, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8376199572530449, "lm_q1q2_score": 0.7683510182976094}} {"text": "module robertson_rate\n\n use stiff3_solver, only: wp => stiff3_wp\n\n implicit none\n\ncontains\n\n !\n ! Robertson rate equations\n !\n subroutine fun(n,y,f)\n integer, intent(in) :: n\n real(wp), intent(in) :: y(n)\n real(wp), intent(inout) :: f(n)\n f(1) = -4.e-2_wp*y(1)+1.e4_wp*y(2)*y(3)\n f(2) = -f(1)-3.e7_wp*y(2)**2\n f(3) = 3.e7_wp*y(2)**2\n end subroutine\n\n !\n ! Robertson rate equations - Jacobian\n !\n subroutine dfun(n,y,df)\n integer, intent(in) :: n\n real(wp), intent(in) :: y(n)\n real(wp), intent(inout) :: df(n,n)\n df(1,1) = -4.e-2_wp\n df(1,2) = 1.e4_wp*y(3)\n df(1,3) = 1.e4_wp*y(2)\n df(2,1) = 4.e-2_wp\n df(2,2) = -1.e4_wp*y(3)-6.e7_wp*y(2)\n df(2,3) = -1.e4_wp*y(2)\n df(3,1) = 0.0_wp\n df(3,2) = 6.e7_wp*y(2)\n df(3,3) = 0.0_wp\n end subroutine\n\nend module\n\nprogram main\n\n use stiff3_solver, only: wp => stiff3_wp, stiff3\n use robertson_rate, only: fun, dfun\n\n implicit none\n\n integer, parameter :: n = 3\n real(wp) :: y(n), w(n)\n real(wp) :: h0, eps, x0, x1\n\n integer, parameter :: nprint = 1\n\n! initial value\n y = [1.0_wp, 0.0_wp, 0.0_wp]\n\n! initial step size\n h0 = 0.0001_wp\n\n! tolerance parameters\n eps = 1.e-5_wp\n w = 1\n w(2) = 1.e-4_wp\n\n! time interval\n x0 = 0.0_wp\n x1 = 10.0_wp\n\n call output(x0,y,0,0.0_wp)\n call stiff3(n,fun,dfun,output,nprint,x0,x1,h0,eps,w,y)\n\ncontains\n\n subroutine output(x,y,iha,qa)\n real(wp), intent(in) :: x\n real(wp), intent(in) :: y(:)\n integer, intent(in) :: iha\n real(wp), intent(in) :: qa\n real(wp) :: y2\n y2 = 1.e4_wp*y(2)\n print '(4(E19.12,2X),I4,2X,E19.12)', x, y(1), y2, y(3), iha, qa\n end subroutine\n\nend program", "meta": {"hexsha": "4cfba3396d0f56774a02da67ca93c94c0a9d6961", "size": 1653, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/robertson.f90", "max_stars_repo_name": "awvwgk/stiff3", "max_stars_repo_head_hexsha": "7ed7379e1a20d229848fddec62453602216c2074", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2021-08-12T01:46:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-08T09:04:21.000Z", "max_issues_repo_path": "example/robertson.f90", "max_issues_repo_name": "awvwgk/stiff3", "max_issues_repo_head_hexsha": "7ed7379e1a20d229848fddec62453602216c2074", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-08-13T02:47:51.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-14T09:52:37.000Z", "max_forks_repo_path": "example/robertson.f90", "max_forks_repo_name": "awvwgk/stiff3", "max_forks_repo_head_hexsha": "7ed7379e1a20d229848fddec62453602216c2074", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-08-12T16:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-13T06:32:42.000Z", "avg_line_length": 19.6785714286, "max_line_length": 67, "alphanum_fraction": 0.5735027223, "num_tokens": 698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7683461910519997}} {"text": "\n module initialisation\n \n use custom_precision\n\n implicit none\n \n private\n\n interface initialise_to_random\n procedure initialise_to_random_1D\n procedure initialise_to_random_2D\n procedure initialise_to_random_1D_dp\n procedure initialise_to_random_2D_dp\n end interface \n \n interface initialise_tridiagonal\n procedure initialise_tridiagonal_sp\n procedure initialise_tridiagonal_dp\n end interface \n \n public initialise_tridiagonal\n public initialise_to_random\n \n contains\n\n !#############################################\n subroutine initialise_to_random_2D(mat, nrows, ncols, start, last)\n real, allocatable, intent(inout) :: mat(:,:)\n integer, intent(in) :: nrows, ncols\n real, intent(in) :: start, last\n\n real :: r, temp\n integer :: irow, icol\n\n r = last - start\n\n do icol = 1, ncols\n do irow = 1, nrows\n call random_number(temp)\n mat(irow, icol) = start + temp * r\n end do\n end do\n end subroutine initialise_to_random_2D\n\n !#############################################\n subroutine initialise_to_random_1D(vec, ncols, start, last)\n real, allocatable, intent(inout) :: vec(:)\n integer, intent(in) :: ncols\n real, intent(in) :: start, last\n\n real :: r, temp\n integer :: icol\n\n r = last - start\n\n do icol = 1, ncols\n call random_number(temp)\n vec(icol) = start + temp * r\n end do\n end subroutine initialise_to_random_1D\n\n !#############################################\n subroutine initialise_tridiagonal_sp(mat, n, upper, diag, lower)\n real, allocatable, intent(inout) :: mat(:,:)\n integer, intent(in) :: n\n real, intent(in) :: upper, diag, lower\n\n integer :: irow, icol\n\n do icol = 1, n\n do irow = 1, n\n if (irow == icol) then\n mat(irow, icol) = diag\n else\n if (irow == icol + 1) then\n mat(irow, icol) = lower\n else if (irow == icol - 1) then\n mat(irow, icol) = upper\n else\n mat(irow, icol) = 0.\n end if\n end if\n end do\n end do\n end subroutine initialise_tridiagonal_sp\n \n !#############################################\n subroutine initialise_to_random_2D_dp(mat, nrows, ncols, start, last)\n real(DP), allocatable, intent(inout) :: mat(:,:)\n integer, intent(in) :: nrows, ncols\n real(DP), intent(in) :: start, last\n\n real(DP) :: r, temp\n integer :: irow, icol\n\n r = last - start\n\n do icol = 1, ncols\n do irow = 1, nrows\n call random_number(temp)\n mat(irow, icol) = start + temp * r\n end do\n end do\n end subroutine initialise_to_random_2D_dp\n\n !#############################################\n subroutine initialise_to_random_1D_dp(vec, ncols, start, last)\n real(DP), allocatable, intent(inout) :: vec(:)\n integer, intent(in) :: ncols\n real(DP), intent(in) :: start, last\n\n real(DP) :: r, temp\n integer :: icol\n\n r = last - start\n\n do icol = 1, ncols\n call random_number(temp)\n vec(icol) = start + temp * r\n end do\n end subroutine initialise_to_random_1D_dp\n\n !#############################################\n subroutine initialise_tridiagonal_dp(mat, n, upper, diag, lower)\n real(DP), allocatable, intent(inout) :: mat(:,:)\n integer, intent(in) :: n\n real(DP), intent(in) :: upper, diag, lower\n\n integer :: irow, icol\n\n do icol = 1, n\n do irow = 1, n\n if (irow == icol) then\n mat(irow, icol) = diag\n else\n if (irow == icol + 1) then\n mat(irow, icol) = lower\n else if (irow == icol - 1) then\n mat(irow, icol) = upper\n else\n mat(irow, icol) = 0.\n end if\n end if\n end do\n end do\n end subroutine initialise_tridiagonal_dp\n \n\n end module initialisation\n", "meta": {"hexsha": "b41931e73ad91e414e72e357f4d42a740857cd10", "size": 4606, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "LinearSolver/Utilities/src/initialisation_module.f90", "max_stars_repo_name": "aliakatas/LinearSolver", "max_stars_repo_head_hexsha": "aa02a87561bd49423f97b79be3d6e1e08eb413de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "LinearSolver/Utilities/src/initialisation_module.f90", "max_issues_repo_name": "aliakatas/LinearSolver", "max_issues_repo_head_hexsha": "aa02a87561bd49423f97b79be3d6e1e08eb413de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LinearSolver/Utilities/src/initialisation_module.f90", "max_forks_repo_name": "aliakatas/LinearSolver", "max_forks_repo_head_hexsha": "aa02a87561bd49423f97b79be3d6e1e08eb413de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.5033112583, "max_line_length": 73, "alphanum_fraction": 0.4661311333, "num_tokens": 1095, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8918110526265554, "lm_q1q2_score": 0.7683292910896939}} {"text": "!\n! lab1_2.f90\n!\n! Copyright 2016 Bruno S \n!\n! This program is free software; you can redistribute it and/or modify\n! it under the terms of the GNU General Public License as published by\n! the Free Software Foundation; either version 2 of the License, or\n! (at your option) any later version.\n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n! GNU General Public License for more details.\n!\n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,\n! MA 02110-1301, USA.\n!\n!\nPROGRAM lab1_2\n\nUSE precision, pr => dp\nIMPLICIT NONE\nINTEGER :: i, j, k\nREAL(pr) :: h, x, e, er, cal\n\nopen(unit=10, file='salida_ej2.dat', status='UNKNOWN', action='WRITE')\nwrite(10, *) \"# h Fp er\"\n\nx = 1._pr\ne = exp(x)\nh = 1._pr\n\ndo i=1, 15, 1\n h = h * 0.1_pr\n cal = fp(h, x)\n er = cal - e\n\n write(10, *) h, cal, abs(er)\nend do\n\n\nCONTAINS\n\nFUNCTION f(x)\nREAL (pr) :: f\nREAL (pr), INTENT(IN) :: x\n\n f = exp(x)\n\nEND FUNCTION f\n\nFUNCTION fp(h, x)\nREAL (pr) :: fp\nREAL (pr), INTENT(IN) :: h, x\n\n fp = f(x + h) - f(x - h)\n fp = fp/(2._pr*h)\n\nEND FUNCTION fp\n\nEND PROGRAM lab1_2\n", "meta": {"hexsha": "45f49ef87364b6cd3df57183973d794f571dcb12", "size": 1374, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lab1/2/lab1_2.f90", "max_stars_repo_name": "BrunoSanchez/fisicaComp", "max_stars_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lab1/2/lab1_2.f90", "max_issues_repo_name": "BrunoSanchez/fisicaComp", "max_issues_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lab1/2/lab1_2.f90", "max_forks_repo_name": "BrunoSanchez/fisicaComp", "max_forks_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.1384615385, "max_line_length": 70, "alphanum_fraction": 0.6673944687, "num_tokens": 433, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7682935420766154}} {"text": "#include \"../defines.inc\"\nmodule vector_utils\n use precision, only: dp, eps, pi\n implicit none\n\ncontains\n\n function distance(a, b)\n implicit none\n real(dp), dimension(3), intent(in) :: a, b\n real(dp) distance\n distance = sqrt((a(1) - b(1))**2 + (a(2) - b(2))**2 + (a(3) - b(3))**2)\n end function distance\n\n function angle(a, b, c)\n implicit none\n real(dp) angle\n real(dp), dimension(3), intent(in) :: a, b, c\n angle = acos(dot_product(a - b, c - b)/(norm2(a - b)*norm2(c - b)))\n\n end function angle\n\n function cross(a, b)\n implicit none\n real(dp), dimension(3) :: cross\n real(dp), dimension(3), intent(in) :: a, b\n\n cross(1) = a(2)*b(3) - a(3)*b(2)\n cross(2) = a(3)*b(1) - a(1)*b(3)\n cross(3) = a(1)*b(2) - a(2)*b(1)\n\n end function cross\n\n function angle_between(a, b)\n implicit none\n real(dp) angle_between\n real(dp), dimension(3), intent(in) :: a, b\n\n real(dp) amag, bmag\n amag = norm2(a)\n bmag = norm2(b)\n angle_between = 2.0*atan2(norm2(amag*b - bmag*a), norm2(amag*b + bmag*a))\n ! algorithm from https://www.jwwalker.com/pages/angle-between-vectors.html\n end function angle_between\n\n function rotateR(ROT, R)\n use, intrinsic :: iso_fortran_env, only: ERROR_UNIT\n implicit none\n real(dp), intent(in) :: ROT(3, 4) ! Rotation matrix\n real(dp), intent(in) :: R(3)\n real(dp) rotateR(3)\n rotateR(1) = ROT(1, 4) + ROT(1, 1)*R(1) + ROT(1, 2)*R(2) + ROT(1, 3)*R(3)\n rotateR(2) = ROT(2, 4) + ROT(2, 1)*R(1) + ROT(2, 2)*R(2) + ROT(2, 3)*R(3)\n rotateR(3) = ROT(3, 4) + ROT(3, 1)*R(1) + ROT(3, 2)*R(2) + ROT(3, 3)*R(3)\n if (WLC_P__WARNING_LEVEL >= 1) then\n if (isnan(rotateR(1)) .or. isnan(rotateR(2)) .or. isnan(rotateR(3))) then\n write (ERROR_UNIT, *) \"NAN detected in ROT\"\n write (ERROR_UNIT, *) \"R\", R\n write (ERROR_UNIT, *) \"ROT\", ROT\n endif\n endif\n end function rotateR\n\n function rotateU(ROT, U)\n implicit none\n real(dp), intent(in) :: ROT(3, 4) ! Rotation matrix\n real(dp), intent(in) :: U(3)\n real(dp) rotateU(3)\n rotateU(1) = ROT(1, 1)*U(1) + ROT(1, 2)*U(2) + ROT(1, 3)*U(3)\n rotateU(2) = ROT(2, 1)*U(1) + ROT(2, 2)*U(2) + ROT(2, 3)*U(3)\n rotateU(3) = ROT(3, 1)*U(1) + ROT(3, 2)*U(2) + ROT(3, 3)*U(3)\n end function rotateU\n\n function angle_of_triangle(a, b, c)\n implicit none\n real(dp), intent(in) :: a, b, c\n real(dp) angle_of_triangle\n angle_of_triangle = acos((a**2 - b**2 - c**2)/(-2.0_dp*b*c))\n end function angle_of_triangle\n\n function round_into_pm1(x)\n implicit none\n real(dp), intent(in) :: x\n real(dp) round_into_pm1\n round_into_pm1 = min(x, 1.0_dp)\n round_into_pm1 = max(x, -1.0_dp)\n end function round_into_pm1\n\n!! ---------------------------------------------------------------\n!\n! Generates random unit vector\n!\n!------------------------------------------------------------\n subroutine randomUnitVec(U, rand_stat)\n use mersenne_twister\n\n implicit none\n type(random_stat), intent(inout) :: rand_stat ! status of random number generator\n real(dp), intent(out) :: U(3)\n real(dp) z\n real(dp) theta\n real(dp) temp\n real(dp) urand(2)\n\n call random_number(urand, rand_stat)\n theta = urand(1)*2.0_dp*PI\n z = urand(2)*2.0_dp - 1.0_dp\n temp = sqrt(1.0_dp - z**2)\n U(1) = temp*cos(theta)\n U(2) = temp*sin(theta)\n U(3) = z\n\n ! Alturnative algorithem\n !call random_number(urand,rand_stat)\n !ALPHA = 2.0_dp*PI*urand(1)\n !BETA = acos(2.0_dp*urand(2)-1.0_dp)\n !U(1) = sin(BETA)*cos(ALPHA)\n !U(2) = sin(BETA)*sin(ALPHA)\n !U(3) = cos(BETA)\n\n ! Alturnative algorithem\n !real(dp) urand(3)\n !call random_gauss(urand, rand_stat)\n !U = urand\n !U = U/norm2(U)\n end subroutine\n\n!--------------------------------------------------------------*\n!\n! Calculates random perpendicular vectors\n!\n! Quinn Made Changes to this file starting on 12/15/15\n! Quinn made this an independent file on 6/20/18\n!\n!---------------------------------------------------------------\n\n subroutine random_perp(u, p, t, rand_stat)\n ! The subroutine generates the second two vectors in a unit triad\n ! The output vectors, p and t, are perpendicular to eachother and u\n ! The triad is randomly left or right handed\n use mersenne_twister\n implicit none\n !real(dp), PARAMETER :: PI = 3.141592654 ! Value of pi\n type(random_stat) rand_stat ! status of random number generator\n real(dp) urnd(1) ! single random number\n\n real(dp) v(2) ! random 2-vec\n real(dp), intent(in) :: u(3) ! input\n real(dp), intent(out) :: p(3) ! output: random perpendicular to u\n real(dp), intent(out) :: t(3) ! orthogonal to p and u\n real(dp) f\n\n if (abs(u(1)**2 + u(2)**2 + u(3)**2 - 1.0_dp) .gt. eps) then\n print *, u\n print *, \"Error in random_perp, please give me a unit vector\"\n stop 1\n endif\n\n call random_number(urnd, rand_stat)\n v(1) = cos(2.0_dp*PI*urnd(1))\n v(2) = sin(2.0_dp*PI*urnd(1))\n\n if (u(3) .gt. 0.0) then\n f = 1.0_dp/(1.0_dp + u(3))\n p(1) = (u(3) + f*u(2)**2)*v(1) - u(2)*u(1)*v(2)*f\n p(2) = (u(3) + f*u(1)**2)*v(2) - u(2)*u(1)*v(1)*f\n p(3) = -1.0_dp*(u(2)*v(2) + u(1)*v(1))\n else\n f = 1.0_dp/(1.0_dp - u(3))\n p(1) = (-u(3) + f*u(2)**2)*v(1) - u(2)*u(1)*v(2)*f\n p(2) = (-u(3) + f*u(1)**2)*v(2) - u(2)*u(1)*v(1)*f\n p(3) = (u(2)*v(2) + u(1)*v(1))\n\n endif\n\n t(1) = u(2)*p(3) - u(3)*p(2)\n t(2) = u(3)*p(1) - u(1)*p(3)\n t(3) = u(1)*p(2) - u(2)*p(1)\n\n ! random sign\n call random_number(urnd, rand_stat)\n if (urnd(1) .lt. 0.5_dp) then\n t(1) = -1.0_dp*t(1)\n t(2) = -1.0_dp*t(2)\n t(3) = -1.0_dp*t(3)\n endif\n\n ! Testing\n !if (abs(dot_product(p,u)) > 0.000001_dp) then\n ! print*, \"Error in random_perp, 1\"\n ! stop 1\n !endif\n !if (abs(p(1)**2 + p(2)**2 + p(3)**2-1) .gt. 0.0000001_dp) then\n ! print*, \"Error in random_perp, 2\"\n ! stop 1\n !endif\n !if (abs(t(1)**2 + t(2)**2 + t(3)**2 -1).gt.0.000001_dp) then\n ! print*, \"Error in random_perp, 3\"\n ! stop 1\n !endif\n !if (abs(dot_product(t,p)) > 0.0000001_dp) then\n ! print*, \"Error in random_perp, 4\"\n ! stop 1\n !endif\n !if (abs(dot_product(t,u)) > 0.0000001_dp) then\n ! print*, \"Error in random_perp, 5\"\n ! stop 1\n !endif\n ! END Testing\n\n return\n end subroutine\n\n!--------------------------------------------------------------*\n!\n! Calculates axis angle rotation matrix\n! Calculates the rotation in the right handed sense by angle alpha\n! in the TA direction.\n! The magnitude of TA is disreguarded.\n! The forth column is the offset\n!\n! Quinn split out this file on 6/20/18\n!\n!---------------------------------------------------------------\n\n subroutine axisAngle(ROT, alpha, TAin, P1)\n use, intrinsic :: iso_fortran_env, only: ERROR_UNIT\n implicit none\n real(dp), intent(in) :: TAin(3) ! Axis of rotation (Need not be unit vector!!)\n real(dp), intent(in) :: P1(3) ! Point on rotation line\n real(dp), intent(in) :: ALPHA ! Angle of move\n real(dp), intent(out) :: ROT(3, 4) ! Rotation matrix\n real(dp) MAG ! Magnitude of vector\n real(dp) TA(3) ! Normalized vector\n integer i\n\n!print*, \"PA\", P1\n MAG = sqrt(TAin(1)**2 + TAin(2)**2 + TAin(3)**2)\n TA(1) = TAin(1)/MAG\n TA(2) = TAin(2)/MAG\n TA(3) = TAin(3)/MAG\n\n ROT(1, 1) = TA(1)**2 + (TA(2)**2 + TA(3)**2)*cos(ALPHA)\n ROT(1, 2) = TA(1)*TA(2)*(1.0_dp - cos(ALPHA)) - TA(3)*sin(ALPHA)\n ROT(1, 3) = TA(1)*TA(3)*(1.0_dp - cos(ALPHA)) + TA(2)*sin(ALPHA)\n ROT(1, 4) = (P1(1)*(1.0_dp - TA(1)**2) &\n - TA(1)*(P1(2)*TA(2) + P1(3)*TA(3)))*(1.-cos(ALPHA)) + (P1(2)*TA(3) - P1(3)*TA(2))*sin(ALPHA)\n\n ROT(2, 1) = TA(1)*TA(2)*(1.0_dp - cos(ALPHA)) + TA(3)*sin(ALPHA)\n ROT(2, 2) = TA(2)**2 + (TA(1)**2 + TA(3)**2)*cos(ALPHA)\n ROT(2, 3) = TA(2)*TA(3)*(1.0_dp - cos(ALPHA)) - TA(1)*sin(ALPHA)\n ROT(2, 4) = (P1(2)*(1.0_dp - TA(2)**2) &\n - TA(2)*(P1(1)*TA(1) + P1(3)*TA(3)))*(1.-cos(ALPHA)) + (P1(3)*TA(1) - P1(1)*TA(3))*sin(ALPHA)\n\n ROT(3, 1) = TA(1)*TA(3)*(1.-cos(ALPHA)) - TA(2)*sin(ALPHA)\n ROT(3, 2) = TA(2)*TA(3)*(1.-cos(ALPHA)) + TA(1)*sin(ALPHA)\n ROT(3, 3) = TA(3)**2 + (TA(1)**2 + TA(2)**2)*cos(ALPHA)\n ROT(3, 4) = (P1(3)*(1.0_dp - TA(3)**2) &\n - TA(3)*(P1(1)*TA(1) + P1(2)*TA(2)))*(1.0_dp - cos(ALPHA)) + (P1(1)*TA(2) - P1(2)*TA(1))*sin(ALPHA)\n\n if (WLC_P__WARNING_LEVEL >= 1) then\n do i = 1, 3\n if (isnan(ROT(1, i)) .or. isnan(ROT(2, i)) .or. isnan(ROT(3, i))) then\n write (ERROR_UNIT, *) \"NAN detected in axisAngle\"\n write (ERROR_UNIT, *) \"alpha\", alpha\n write (ERROR_UNIT, *) \"TAin\", TAin\n write (ERROR_UNIT, *) \"P1\", P1\n write (ERROR_UNIT, *) \"ROT\", ROT\n stop\n endif\n enddo\n endif\n end subroutine\n\n subroutine rotateAIntoB(A, B, P1, ROT)\n use, intrinsic :: iso_fortran_env, only: ERROR_UNIT\n implicit none\n real(dp), intent(in) :: A(3)\n real(dp), intent(in) :: B(3)\n real(dp), intent(in) :: P1(3) ! Point on rotation line\n real(dp), intent(out) :: ROT(3, 4) ! Rotation matrix\n real(dp) ALPHA ! Angle of move\n real(dp) TA(3) ! Normalized vector\n\n TA = cross(A, B)\n alpha = asin(norm2(TA)/(norm2(A)*norm2(B)))\n if (norm2(A) < 10**(-10) .or. norm2(B) < 10**(-10)) then\n ROT = 0.0_dp\n ROT(1, 1) = 1.0_dp\n ROT(2, 2) = 1.0_dp\n ROT(3, 3) = 1.0_dp\n write (ERROR_UNIT, *) \"Tried to rotate\", A, \" into \", B\n return\n endif\n\n call axisAngle(ROT, alpha, TA, P1)\n end subroutine rotateAIntoB\nend module\n", "meta": {"hexsha": "3af1084e4b2a039fa1fbc9e105de40836ad3c5d0", "size": 10183, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/util/vector_utils.f03", "max_stars_repo_name": "SpakowitzLab/BasicWLC", "max_stars_repo_head_hexsha": "13edbbc8e8cd36a3586571ff4d80880fc89d30e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-16T01:39:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-16T01:39:18.000Z", "max_issues_repo_path": "src/util/vector_utils.f03", "max_issues_repo_name": "riscalab/wlcsim", "max_issues_repo_head_hexsha": "e34877ef6c5dc83c6444380dbe624b371d70faf2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2016-07-08T21:17:40.000Z", "max_issues_repo_issues_event_max_datetime": "2017-01-24T09:05:25.000Z", "max_forks_repo_path": "src/util/vector_utils.f03", "max_forks_repo_name": "riscalab/wlcsim", "max_forks_repo_head_hexsha": "e34877ef6c5dc83c6444380dbe624b371d70faf2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-02-19T06:28:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-05T22:28:08.000Z", "avg_line_length": 34.0568561873, "max_line_length": 118, "alphanum_fraction": 0.5066286949, "num_tokens": 3723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.768273409304487}} {"text": "*-----------------------------------------------------------------------\n* MR - multiple regression using the SLATEC library routine DHFTI\n*\n* Finds the nearest approximation to BETA in the system of linear equations:\n*\n* X(j,i) . BETA(i) = Y(j)\n* where\n* 1 ... j ... N\n* 1 ... i ... K\n* and\n* K .LE. N\n*\n* INPUT ARRAYS ARE DESTROYED!\n*\n*___Name_________Type_______________In/Out____Description________________________\n* X(N,K) Double precision In Predictors\n* Y(N) Double precision Both On input: N Observations\n* On output: K beta weights\n* N Integer In Number of observations\n* K Integer In Number of predictor variables\n* DWORK(3*K) Double precision Neither Workspace\n* IWORK(K) Integer Neither Workspace\n*-----------------------------------------------------------------------\n SUBROUTINE MR (X, Y, N, K, DWORK, IWORK)\n IMPLICIT NONE\n INTEGER K, N, IWORK\n DOUBLE PRECISION X, Y, DWORK\n DIMENSION X(N,K), Y(N), DWORK(3*K), IWORK(K)\n\n* local variables\n INTEGER I, J\n DOUBLE PRECISION TAU, TOT\n\n* maximum of all column sums of magnitudes\n TAU = 0.\n DO J = 1, K\n TOT = 0.\n DO I = 1, N\n TOT = TOT + ABS(X(I,J))\n END DO\n IF (TOT > TAU) TAU = TOT\n END DO\n TAU = TAU * EPSILON(TAU) ! tolerance argument\n\n* call function\n CALL DHFTI (X, N, N, K, Y, N, 1, TAU,\n $ J, DWORK(1), DWORK(K+1), DWORK(2*K+1), IWORK)\n IF (J < K) PRINT *, 'mr: solution is rank deficient!'\n RETURN\n END ! of MR\n\n*-----------------------------------------------------------------------\n PROGRAM t_mr ! polynomial regression example\n IMPLICIT NONE\n INTEGER N, K\n PARAMETER (N=15, K=3)\n INTEGER IWORK(K), I, J\n DOUBLE PRECISION XIN(N), X(N,K), Y(N), DWORK(3*K)\n\n DATA XIN / 1.47, 1.50, 1.52, 1.55, 1.57, 1.60, 1.63, 1.65, 1.68,\n $ 1.70, 1.73, 1.75, 1.78, 1.80, 1.83 /\n DATA Y / 52.21, 53.12, 54.48, 55.84, 57.20, 58.57, 59.93, 61.29,\n $ 63.11, 64.47, 66.28, 68.10, 69.92, 72.19, 74.46 /\n\n* make coefficient matrix\n DO J = 1, K\n DO I = 1, N\n X(I,J) = XIN(I) **(J-1)\n END DO\n END DO\n\n* solve\n CALL MR (X, Y, N, K, DWORK, IWORK)\n\n* print result\n 10 FORMAT ('beta: ', $)\n 20 FORMAT (F12.4, $)\n 30 FORMAT ()\n PRINT 10\n DO J = 1, K\n PRINT 20, Y(J)\n END DO\n PRINT 30\n STOP 'program complete'\n END\n", "meta": {"hexsha": "b7e06c9d48b3df65c9e848e0214c6582c403bb62", "size": 2779, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Multiple-regression/Fortran/multiple-regression.f", "max_stars_repo_name": "mbirabhadra/RosettaCodeData", "max_stars_repo_head_hexsha": "ba8067c3b7e68156d666c9a802c07cdacecc14ea", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Multiple-regression/Fortran/multiple-regression.f", "max_issues_repo_name": "p0l4r/RosettaCodeData", "max_issues_repo_head_hexsha": "ba8067c3b7e68156d666c9a802c07cdacecc14ea", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Multiple-regression/Fortran/multiple-regression.f", "max_forks_repo_name": "p0l4r/RosettaCodeData", "max_forks_repo_head_hexsha": "ba8067c3b7e68156d666c9a802c07cdacecc14ea", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 32.3139534884, "max_line_length": 81, "alphanum_fraction": 0.4494422454, "num_tokens": 851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455085, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7682601396990576}} {"text": "subroutine itemwise_calc(input, output)\n\n implicit none\n\n real*8, dimension(:), intent(in) :: input\n real*8, dimension(size(input)), intent(out) :: output\n integer :: n\n\n !$omp parallel do\n do n = 1, size(input)\n output(n) = (input(n) - 3) * (input(n) - 2) * (input(n) - 1) * input(n) * (input(n) + 1) * (input(n) + 2) * (input(n) + 3)\n end do\n !$omp end parallel do\n\n return\n\nend subroutine\n", "meta": {"hexsha": "8e873b6bb4fca18e1bb98989189024ee5b888904", "size": 404, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/examples/f95/itemwise_calc_openmp.f90", "max_stars_repo_name": "EraYaN/transpyle", "max_stars_repo_head_hexsha": "e7f5a021e7e6ab13fc21906b5a785dd24606cccc", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 107, "max_stars_repo_stars_event_min_datetime": "2018-01-12T05:19:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T20:56:52.000Z", "max_issues_repo_path": "test/examples/f95/itemwise_calc_openmp.f90", "max_issues_repo_name": "EraYaN/transpyle", "max_issues_repo_head_hexsha": "e7f5a021e7e6ab13fc21906b5a785dd24606cccc", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2018-01-24T08:08:12.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-29T23:36:11.000Z", "max_forks_repo_path": "test/examples/f95/itemwise_calc_openmp.f90", "max_forks_repo_name": "EraYaN/transpyle", "max_forks_repo_head_hexsha": "e7f5a021e7e6ab13fc21906b5a785dd24606cccc", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 20, "max_forks_repo_forks_event_min_datetime": "2018-12-05T13:21:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-11T11:48:33.000Z", "avg_line_length": 22.4444444444, "max_line_length": 126, "alphanum_fraction": 0.5940594059, "num_tokens": 142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898305367525, "lm_q2_score": 0.8479677583778257, "lm_q1q2_score": 0.7682501657133562}} {"text": "! triangle - ASS configuration\n! Copyright 2021 by Eric Conrad.\n! License - MIT License - see: https://opensource.org/licenses/MIT\n!\n! input - the measure of an angle the length of a pair of sides\n! that don't contain the angle (NB: one of the two sides will\n! be opposite the given angle)\n! remarks - there may be 0, 1 or 2 solutions\n! output -\n! the sides and angles\n! the semiperimeter and the area\n! type of triangle\n!\n! Corrections:\n! 14 Jan 2021 -\n!\t\t- added copyright and license statement\n!\t\t- corrected text of second error message under \"Remaining error checks\",\n!\t\t changing \"given angles\" (plural) to \"given angle\" (singular).\n\n! When I took geometry in high school, this was called the ASS\n! configuration. In today's more puritannical times, it's called\n! the SSA configuration.\n\n program triangle\n print*,\"ASS Configuration\"\n\n! Notes:\n! 100 grad = 90 degrees = pi/2 (rad) = 1 rt angle = 1/4 rev\n! 200 grad = 180 degrees = pi (rad) = 2 rt angles = 1/2 rev\n\n print*,\"Angle measure units (1-radian, 2-degree, 3-grad, 4-rev):\"\n read(*,*) imeas\n if(imeas .lt. 1 .or. imeas .gt. 4) then\n print*,\"ERROR: unsupported angle measure\"\n stop 1\n end if\n\n print*,\"Enter the measure of the given angle (A):\"\n read(*,*) alpha\n print*,\"Enter the length of the side opposite A (a):\"\n read(*,*) a\n print*,\"Enter the length of a side adjacent to A (b):\"\n read(*,*) b\n\n! First error condition:\n! the given sides must be positive in length\n if(a.le.0.0 .or. b.le.0.0) then\n print*,\"ERROR: The given sides must be positive in length\"\n stop 1\n end if\n\n! Convert the angle measures\n pi = 4*atan(1.d0)\n if(imeas.eq.1) then ! input in radians\n dalpha = 180 * alpha / pi\n galpha = 200 * alpha / pi\n ralpha = alpha / (2 * pi)\n else if(imeas.eq.2) then ! input in degrees\n dalpha = alpha\n alpha = pi * dalpha / 180\n galpha = 200 * dalpha / 180\n ralpha = dalpha / 360\n else if(imeas.eq.3) then ! input in grads\n galpha = alpha\n alpha = pi * galpha / 200\n dalpha = 180 * galpha / 200\n ralpha = dalpha / 400\n else ! input in revolutions\n ralpha = alpha\n alpha = 2 * pi * galpha\n dalpha = 360 * galpha\n galpha = 400 * ralpha\n end if\n\n! Remaining error checks:\n! (1) the given angle should positive\n if(alpha.le.0) then\n print*, \"ERROR: the given angle must be positive\"\n stop 1\n end if\n! (2) the given angle must be less than a straight angle\n if(alpha.ge.pi) then\n print*, \"ERROR: the given angle must be less\" // &\n \"than a straight angle\"\n stop 1\n end if\n\n! law of sines\n! it's safe for finding sides (apart from numerical errors), but\n! must be used carefully when used to find angles...\n! there will be either no solutions or two solutions (the principal\n! acute angle and its obtuse counterpart) or a double solution (a\n! right angle)...\n\n! Step 1) Find angle B using the law of sines\n! sin(B) / B = sin(A) / A\n\n sinB = b * sin(alpha) / a\n print*, \"sin(B) =\", sinB\n if(sinB .gt. 1) then\n print*, \"There is no triangle satifying these constraints.\"\n stop 1\n end if\n\n! we have reduced the confirguration to AAS (A, B, a), but there\n! are two values of B to consider... and there are still some\n! landmines...\n\n! the principal solution\n print*, \"Principal solution\"\n beta = asin(sinB)\n print*, \"a =\", a, \", b =\", b\n print*, \"A =\", alpha, \", B =\", beta\n if((alpha + beta) .ge. pi) then\n print*, \"The two known angles exceed a straight angle.\"\n print*, \"No solution.\"\n stop 1\n end if\n\n dbeta = 180 * beta / pi\n gbeta = 200 * beta / pi\n rbeta = beta / (2 * pi)\n\n! the principal solution B gives a real triangle...\n\n gamm = pi - alpha - beta ! third angle\n dgamma = 180 * gamm / pi\n ggamma = 200 * gamm / pi\n rgamma = gamm / (2 * pi)\n\n c = sin(gamm) * a / sin(alpha)\n\n! output solution of triangle\n print*, \"------- PRINCIPAL SOLUTION --------------------------\"\n print*, \"a =\", a, \" (given)\"\n print*, \"b =\", b, \" (given)\"\n print*, \"c =\", c\n print*, \"A =\", alpha, \"degrees:\", dalpha, \" (given)\"\n print*, \"B =\", beta, \"degrees:\", dbeta, \" (principal)\"\n print*, \"C =\", gamm, \"degrees:\", dgamma\n print*, \"-----------------------------------------------------\"\n print*, \"Angles in grads:\"\n print*, \" \", galpha, gbeta, ggamma\n print*, \" sum:\", galpha + gbeta + ggamma, \" (exp: 200)\"\n print*, \"Angles in revolutions:\"\n print*, \" \", ralpha, rbeta, rgamma\n print*, \" sum:\", ralpha + rbeta + rgamma, \" (exp: 0.5)\"\n print*, \"-----------------------------------------------------\"\n\n! output semiperimeter and area\n s = (a + b + c) / 2\n print*, \"semiperimeter:\", s\n area = sqrt(s * (s-a) * (s-b) * (s-c)) ! Heron's formula\n print*, \"area:\", area\n\n! angle sum\n sum1 = alpha + beta + gamm\n err1 = sum1 - pi\n sum2 = dalpha + dbeta + dgamma\n err2 = sum2 - 180.0\n print*, \"angle sum (radians):\", sum1, \" error:\", err1\n print*, \"angle sum (degrees):\", sum2, \" error:\", err2\n\n! triangle inequality check:\n! a + b < c; b + c < a; c + a < c\n! A sufficient and necessary condition is that no side may\n! exceed the semiperimeter.\n if (max(a,b,c) .ge. s) then\n print*,\"ERROR: (triangle inequality) max(a,b,c) < s\"\n end if\n\n! Nesbitt's inequality\n symsum = a/(b+c) + b/(a+c) + c/(a+b)\n print*,\"Nesbitt's symmetric sum:\", symsum\n if (symsum.lt.1.5) then\n print*,\" Error: sum < 1.5\"\n end if\n if (symsum.ge.2) then\n print*,\" Error: sum > 2\"\n end if\n\n! the secondary solution\n print*, \"=====================================================\"\n print*, \"Secondary solution\"\n beta2 = pi - beta\n print*, \"a =\", a, \", b =\", b\n print*, \"A =\", alpha, \", B =\", beta2\n if(beta2 .eq. beta) then\n print*, \"Angle B is a right angle.\"\n print*, \"The solution is unique.\"\n stop 0\n end if\n beta = beta2\n if((alpha + beta) .ge. pi) then\n print*, \"The two known angles exceed a straight angle.\"\n print*, \"No secondary solution.\"\n stop 0\n end if\n\n dbeta = 180 * beta / pi\n gbeta = 200 * beta / pi\n rbeta = beta / (2 * pi)\n\n! the secondary (obtuse) solution B gives a real triangle...\n\n gamm = pi - alpha - beta ! third angle\n dgamma = 180 * gamm / pi\n ggamma = 200 * gamm / pi\n rgamma = gamm / (2 * pi)\n\n c = sin(gamm) * a / sin(alpha)\n\n! output solution of triangle\n print*, \"------- SECONDARY SOLUTION --------------------------\"\n print*, \"a =\", a, \" (given)\"\n print*, \"b =\", b, \" (given)\"\n print*, \"c =\", c\n print*, \"A =\", alpha, \"degrees:\", dalpha, \" (given)\"\n print*, \"B =\", beta, \"degrees:\", dbeta, \" (secondary)\"\n print*, \"C =\", gamm, \"degrees:\", dgamma\n print*, \"-----------------------------------------------------\"\n print*, \"Angles in grads:\"\n print*, \" \", galpha, gbeta, ggamma\n print*, \" sum:\", galpha + gbeta + ggamma, \" (exp: 200)\"\n print*, \"Angles in revolutions:\"\n print*, \" \", ralpha, rbeta, rgamma\n print*, \" sum:\", ralpha + rbeta + rgamma, \" (exp: 0.5)\"\n print*, \"-----------------------------------------------------\"\n\n! output semiperimeter and area\n s = (a + b + c) / 2\n print*, \"semiperimeter:\", s\n area = sqrt(s * (s-a) * (s-b) * (s-c)) ! Heron's formula\n print*, \"area:\", area\n\n! angle sum\n sum1 = alpha + beta + gamm\n err1 = sum1 - pi\n sum2 = dalpha + dbeta + dgamma\n err2 = sum2 - 180.0\n print*, \"angle sum (radians):\", sum1, \" error:\", err1\n print*, \"angle sum (degrees):\", sum2, \" error:\", err2\n\n! triangle inequality check:\n! a + b < c; b + c < a; c + a < c\n! A sufficient and necessary condition is that no side may\n! exceed the semiperimeter.\n if (max(a,b,c) .ge. s) then\n print*,\"ERROR: (triangle inequality) max(a,b,c) < s\"\n end if\n\n! Nesbitt's inequality\n symsum = a/(b+c) + b/(a+c) + c/(a+b)\n print*,\"Nesbitt's symmetric sum:\", symsum\n if (symsum.lt.1.5) then\n print*,\" Error: sum < 1.5\"\n end if\n if (symsum.ge.2) then\n print*,\" Error: sum > 2\"\n end if\n\n end program\n", "meta": {"hexsha": "53df49d5867fdd700ae92ee6c2b29d104abfba49", "size": 8729, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ass.f90", "max_stars_repo_name": "econrad003/fortran-examples", "max_stars_repo_head_hexsha": "c323474b6eb9abc16305ec2bb6e95851311df146", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ass.f90", "max_issues_repo_name": "econrad003/fortran-examples", "max_issues_repo_head_hexsha": "c323474b6eb9abc16305ec2bb6e95851311df146", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ass.f90", "max_forks_repo_name": "econrad003/fortran-examples", "max_forks_repo_head_hexsha": "c323474b6eb9abc16305ec2bb6e95851311df146", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.1901140684, "max_line_length": 75, "alphanum_fraction": 0.5222820483, "num_tokens": 2572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140233, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7682495488224711}} {"text": "module binomialtree\nimplicit none\nprivate\npublic tree_stockprice, eurocall, europut, amcall, amput\n\ncontains\n\nreal function tree_stockprice(S0, u, d, i, j) result(price)\n real, intent(in) :: S0, u, d\n integer, intent(in) :: i, j\n ! using Python array indexing (start from 0)\n price = S0 * u**(i-j) * d**j\nend function\n\nreal function eurocall(S0, X, rdt, p, u, d, nbsteps) result(price)\n real, intent(in) :: S0, X, rdt, p, u, d\n integer, intent(in) :: nbsteps\n real, dimension(nbsteps+1) :: pricearr\n integer :: i, j\n do j = 0, nbsteps\n pricearr(j+1) = max(tree_stockprice(S0, u, d, nbsteps, j)-X, 0.0)\n end do\n do i = nbsteps-1, 0, -1\n do j = 0, i\n pricearr(j+1) = exp(-rdt)*(p*pricearr(j+1)+(1-p)*pricearr(j+2))\n end do\n end do\n price = pricearr(1)\nend function\n\nreal function europut(S0, X, rdt, p, u, d, nbsteps) result(price)\n real, intent(in) :: S0, X, rdt, p, u, d\n integer, intent(in) :: nbsteps\n real, dimension(nbsteps+1) :: pricearr\n integer :: i, j\n do j = 0, nbsteps\n pricearr(j+1) = max(X-tree_stockprice(S0, u, d, nbsteps, j), 0.0)\n end do\n do i = nbsteps-1, 0, -1\n do j = 0, i\n pricearr(j+1) = exp(-rdt)*(p*pricearr(j+1)+(1-p)*pricearr(j+2))\n end do\n end do\n price = pricearr(1)\nend function\n\nreal function amcall(S0, X, rdt, p, u, d, nbsteps) result(price)\n real, intent(in) :: S0, X, rdt, p, u, d\n integer, intent(in) :: nbsteps\n real, dimension(nbsteps+1) :: pricearr\n real, dimension(nbsteps) :: temp_euroval\n real :: imvalue\n integer :: i, j\n do j = 0, nbsteps\n pricearr(j+1) = max(tree_stockprice(S0, u, d, nbsteps, j)-X, 0.0)\n end do\n do i = nbsteps-1, 0, -1\n do j = 0, i\n temp_euroval(j+1) = exp(-rdt)*(p*pricearr(j+1)+(1-p)*pricearr(j+2))\n end do\n do j = 0, i\n imvalue = tree_stockprice(S0, u, d, i, j)-X\n pricearr(j+1) = max(imvalue, temp_euroval(j+1))\n end do\n end do\n price = pricearr(1)\nend function\n\nreal function amput(S0, X, rdt, p, u, d, nbsteps) result(price)\n real, intent(in) :: S0, X, rdt, p, u, d\n integer, intent(in) :: nbsteps\n real, dimension(nbsteps+1) :: pricearr\n real, dimension(nbsteps) :: temp_euroval\n real :: imvalue\n integer :: i, j\n do j = 0, nbsteps\n pricearr(j+1) = max(X-tree_stockprice(S0, u, d, nbsteps, j), 0.0)\n end do\n do i = nbsteps-1, 0, -1\n do j = 0, i\n temp_euroval(j+1) = exp(-rdt)*(p*pricearr(j+1)+(1-p)*pricearr(j+2))\n end do\n do j = 0, i\n imvalue = X-tree_stockprice(S0, u, d, i, j)\n pricearr(j+1) = max(imvalue, temp_euroval(j+1))\n end do\n end do\n price = pricearr(1)\nend function\n\nend module\n\n! compiling\n! > f2py -h binomialtree.pyf -m binomialtree binomialtree.f90\n! > f2py -c binomialtree.pyf binomialtree.f90\n\n", "meta": {"hexsha": "76af880cfff0cb83aa9ee44197acd230c8c2841b", "size": 2746, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mogu/finance/binomial/binomialtree.f90", "max_stars_repo_name": "vishalbelsare/MoguNumerics", "max_stars_repo_head_hexsha": "4b6b55b562c3fe318552dd48f6b630d618bbbfc2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2017-08-10T18:30:54.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-05T10:18:20.000Z", "max_issues_repo_path": "mogu/finance/binomial/binomialtree.f90", "max_issues_repo_name": "vishalbelsare/MoguNumerics", "max_issues_repo_head_hexsha": "4b6b55b562c3fe318552dd48f6b630d618bbbfc2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-06-21T22:18:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-21T23:17:08.000Z", "max_forks_repo_path": "mogu/finance/binomial/binomialtree.f90", "max_forks_repo_name": "vishalbelsare/MoguNumerics", "max_forks_repo_head_hexsha": "4b6b55b562c3fe318552dd48f6b630d618bbbfc2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-05-21T16:54:52.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-05T10:18:57.000Z", "avg_line_length": 28.3092783505, "max_line_length": 75, "alphanum_fraction": 0.6107064822, "num_tokens": 1068, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.7682495482889895}} {"text": "program midpoint\n implicit none\n integer :: i, N\n real :: t, h, pi = 4. * atan(1.)\n real, dimension(2) :: x, k1\n\n h = 0.1\n N = 2. * pi / h\n\n ! Midpoint method\n x(1) = 1.\n x(2) = 0.\n write(*,*)0., x\n do i=1,N\n t = (i - 1) * h\n k1 = f(x, t)\n x = x + h * f(x + k1 * h / 2, t + h / 2)\n write(*,*)i * h, x\n end do\n\ncontains\n\n function f(x, t)\n implicit none\n real, intent(in) :: t\n real, dimension(2), intent(in) :: x\n real, dimension(2) :: f\n\n f(1) = x(2) \n f(2) = -x(1) \n end function\nend program\n\n", "meta": {"hexsha": "d3103f7cdd1d35ed3c468babfecfcbf6d9d8acde", "size": 607, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lec05/midpoint.f90", "max_stars_repo_name": "rekka/intro-fortran-2016", "max_stars_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-05T01:54:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T01:54:57.000Z", "max_issues_repo_path": "lec05/midpoint.f90", "max_issues_repo_name": "rekka/intro-fortran-2016", "max_issues_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lec05/midpoint.f90", "max_forks_repo_name": "rekka/intro-fortran-2016", "max_forks_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-06-22T12:39:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-25T04:45:37.000Z", "avg_line_length": 17.8529411765, "max_line_length": 48, "alphanum_fraction": 0.4151565074, "num_tokens": 239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947070591979, "lm_q2_score": 0.8128673246376008, "lm_q1q2_score": 0.7681553193239035}} {"text": " subroutine krnlcolumnannihilate( n, A, ldA, cvec, svec )\n\n implicit none\n\n*\n* PURPOSE\n* =======\n*\n* Reduces an upper Hessenberg n-by-n matrix A to upper triangular\n* form by constructing and applying a decreasing sequence of column\n* n - 1 column rotations. \n*\n* More specifically, the following update of A is performed:\n*\n* A := A * G(k) * G(k-1) * ... * G(2)\n*\n* where G(k) for k = 2, 3, ..., n affects only columns k - 1 and k\n* in the following way. Let x denote column k - 1 and y denote\n* column k. Furthermore, define c = cvec(k) and s = svec(k). Then\n* the effect of A * G(k) is equivalent to the update\n*\n* [ x y ] := [ x y ] * [ c -s ]\n* [ s c ].\n*\n* The transformation G(k) is chosen such that it annihilates the\n* subdiagonal element A(k,k-1) using the diagonal element A(k,k) as\n* a pivot.\n*\n*\n* ARGUMENTS\n* =========\n*\n* n (input) INTEGER\n*\n* The number of rows and columns in A.\n*\n* A (input/output) DOUBLE PRECISION array\n* dimension ldA-by-n\n*\n* The matrix A.\n*\n* ldA (input) INTEGER\n*\n* The column stride of A.\n*\n* cvec (output) DOUBLE PRECISION array\n* dimension n\n* \n* cvec(k) is the c-parameter of G(k).\n*\n* svec (output) DOUBLE PRECISION array\n* dimension m\n*\n* svec(k) is the s-parameter of G(k).\n* \n\n* \n* Scalar arguments.\n* \n integer n, ldA\n\n*\n* Array arguments.\n* \n double precision A( ldA, * ), cvec( * ), svec( * )\n\n*\n* Externals.\n*\n external dlartg\n\n*\n* Local scalars.\n* \n integer i, j\n double precision c, s, x, y, tmp\n\n do j = n, 2, -1\n tmp = A( j, j )\n call dlartg( tmp, A( j, j - 1 ), c, s, A( j, j ) )\n cvec( j ) = c\n svec( j ) = s\n A( j, j - 1 ) = 0.0D+0\n do i = 1, j - 1\n x = A( i, j - 1 )\n y = A( i, j )\n A( i, j - 1 ) = c * x - s * y\n A( i, j ) = s * x + c * y\n end do\n end do\n\n end subroutine\n\n", "meta": {"hexsha": "465f8a87e80f7f4bc00b6eb3973b51ddd70dac6f", "size": 2249, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/3rdparty/pdgghrd/KRNLCOLUMNANNIHILATE.f", "max_stars_repo_name": "NLAFET/StarNEig", "max_stars_repo_head_hexsha": "d47ed4dfbcdaec52e44f0b02d14a6e0cde64d286", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-04-28T17:13:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-24T12:30:19.000Z", "max_issues_repo_path": "src/3rdparty/pdgghrd/KRNLCOLUMNANNIHILATE.f", "max_issues_repo_name": "NLAFET/StarNEig", "max_issues_repo_head_hexsha": "d47ed4dfbcdaec52e44f0b02d14a6e0cde64d286", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/3rdparty/pdgghrd/KRNLCOLUMNANNIHILATE.f", "max_forks_repo_name": "NLAFET/StarNEig", "max_forks_repo_head_hexsha": "d47ed4dfbcdaec52e44f0b02d14a6e0cde64d286", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-04-30T12:14:12.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-14T09:41:23.000Z", "avg_line_length": 23.9255319149, "max_line_length": 71, "alphanum_fraction": 0.457981325, "num_tokens": 678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418262465169, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7680940560525322}} {"text": "program main\n ! Default\n implicit none\n\n ! Parameters\n integer(4), parameter :: max_int = 100\n\n ! Variables\n integer(4) :: i,sum_sq,sq_sum,diff\n\n ! Do work\n sum_sq = 0\n sq_sum = 0\n do i=1,max_int\n sum_sq = sum_sq + i**2\n sq_sum = sq_sum + i\n enddo\n\n sq_sum = sq_sum**2\n diff = sq_sum - sum_sq\n\n ! Write out answer\n write(*,*) 'Difference between sum of squares and square of sums up to ',&\n max_int,': ',diff\n\nend program main\n", "meta": {"hexsha": "1c4b5171e26ecf3de745567483f90551a6b9f893", "size": 458, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/problem6/problem6.f90", "max_stars_repo_name": "plaplant/Project_Euler", "max_stars_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/problem6/problem6.f90", "max_issues_repo_name": "plaplant/Project_Euler", "max_issues_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/problem6/problem6.f90", "max_forks_repo_name": "plaplant/Project_Euler", "max_forks_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-01-07T21:43:45.000Z", "max_forks_repo_forks_event_max_datetime": "2017-01-07T21:43:45.000Z", "avg_line_length": 16.962962963, "max_line_length": 76, "alphanum_fraction": 0.6222707424, "num_tokens": 154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7680940508431268}} {"text": "subroutine gcd_iter(value, u, v)\n integer, intent(out) :: value\n integer, intent(inout) :: u, v\n integer :: t\n\n do while( v /= 0 )\n t = u\n u = v\n v = mod(t, v)\n enddo\n value = abs(u)\nend subroutine gcd_iter\n", "meta": {"hexsha": "39cdafacc9f6bff18636e9600fb191a680560459", "size": 225, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Greatest-common-divisor/Fortran/greatest-common-divisor-2.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Greatest-common-divisor/Fortran/greatest-common-divisor-2.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Greatest-common-divisor/Fortran/greatest-common-divisor-2.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 17.3076923077, "max_line_length": 32, "alphanum_fraction": 0.5688888889, "num_tokens": 78, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.931462514578343, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7679553831343393}} {"text": "\n ! It was proposed by Christian Goldbach that every odd composite number can be\n ! written as the sum of a prime and twice a square.\n !\n ! 9 = 7 + 2×1^2\n ! 15 = 7 + 2×2^2\n ! 21 = 3 + 2×3^2\n ! 25 = 7 + 2×3^2\n ! 27 = 19 + 2×2^2\n ! 33 = 31 + 2×1^2\n !\n ! It turns out that the conjecture was false.\n !\n ! What is the smallest odd composite that cannot be written as the sum of a\n ! prime and twice a square?\n !\n ! Answer: 5777\n !\n ! Project Euler: 46\n\nprogram main\n\n use euler\n\nimplicit none\n\n integer (int32) :: i = 1;\n\n24 &\n i = i + 2;\n\n if(isprime(i) .OR. satisfies_goldbach(i)) goto 24;\n\n print*, i\n\ncontains\n\n ! This function generates twice squares and subtracts this from the\n ! test number. If the number, once subtracted, is a prime, then this\n ! satisfies Goldbach's conjecture. Otherwise the function terminates\n ! when there exists no twice square that may be subtracted positively.\n\n pure logical function satisfies_goldbach(n)\n\n integer (int32), intent(in) :: n\n integer (int32) :: i, sqr;\n\n satisfies_goldbach = .FALSE.\n i = 1; sqr = 2;\n\n do while (sqr < n .AND. .NOT. satisfies_goldbach)\n\n satisfies_goldbach = isprime(n - sqr);\n i = i + 1\n sqr = 2 * (i**2);\n\n end do\n\n end function satisfies_goldbach\n\nend program main\n\n", "meta": {"hexsha": "7162479af66984958fc5ab6a7a0c609840ee25d0", "size": 1470, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/goldbach_conjecture.f95", "max_stars_repo_name": "guynan/project_euler", "max_stars_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-03-08T09:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T13:52:49.000Z", "max_issues_repo_path": "fortran/goldbach_conjecture.f95", "max_issues_repo_name": "guynan/project_euler", "max_issues_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-11-03T01:20:46.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-24T22:54:59.000Z", "max_forks_repo_path": "fortran/goldbach_conjecture.f95", "max_forks_repo_name": "guynan/project_euler", "max_forks_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-11-03T01:14:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T13:52:51.000Z", "avg_line_length": 23.3333333333, "max_line_length": 79, "alphanum_fraction": 0.5612244898, "num_tokens": 402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731764, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.767955371962096}} {"text": "*----------------------------------------------------------------------*\n* follows: exp and log of matrices\n*----------------------------------------------------------------------*\n subroutine expgmat(ndim,expx,xmat,xscr1,xscr2,thrsh)\n*----------------------------------------------------------------------*\n* calculate exp(X), returned on expx, of (ndim,ndim)-matrix X,\n* input on xmat, by Taylor expansion (threshold thrsh)\n* xscr is a scratch matrix of the same dimensions as xmat, expx\n*\n* any quadratic matrix may be supplied\n*\n* andreas, aug 2004\n*\n*----------------------------------------------------------------------*\n\n implicit none\n\n include 'stdunit.h'\n\n integer, parameter :: ntest = 00, maxn = 100\n\n integer, intent(in) ::\n & ndim\n real(8), intent(in) ::\n & thrsh\n real(8), intent(inout) ::\n & expx(ndim,ndim), xmat(ndim,ndim),\n & xscr1(ndim,ndim), xscr2(ndim,ndim)\n\n logical ::\n & conv\n integer ::\n & n, ndim2, ii\n real(8) ::\n & xnrm, fac\n\n real(8), external ::\n & inprod\n\n expx(1:ndim,1:ndim) = xmat(1:ndim,1:ndim)\n xscr2(1:ndim,1:ndim) = xmat(1:ndim,1:ndim)\n\n do ii = 1, ndim\n expx(ii,ii) = expx(ii,ii) + 1d0\n end do\n\n ndim2 = ndim*ndim\n n = 1\n conv = .false.\n\n do while (.not.conv)\n n = n+1\n if (n.gt.maxn) exit\n\n fac = 1d0/dble(n)\n\n ! Xscr = 1/N Xscr * X\nc call matml7(xscr1,xscr2,xmat,\nc & ndim,ndim,\nc & ndim,ndim,\nc & ndim,ndim,0d0,fac,0)\n call dgemm('n','n',ndim,ndim,ndim,\n & fac,xscr2,ndim,\n & xmat,ndim,\n & 0d0,xscr1,ndim)\n\n\n xnrm = sqrt(inprod(xscr1,xscr1,ndim2))\n if (xnrm.lt.thrsh) conv = .true.\n\n if (ntest.ge.10)\n & write(lulog,*) ' N = ',n,' |1/N! X^N| = ',xnrm\n\n expx(1:ndim,1:ndim) = expx(1:ndim,1:ndim) + xscr1(1:ndim,1:ndim)\n\n xscr2(1:ndim,1:ndim) = xscr1(1:ndim,1:ndim)\n\n end do\n\n if (.not.conv) then\n write(lulog,*) ' Taylor expansion of exp(X) did not converge!'\n call quit(1,'expgmat','no convergence')\n end if\n\n return\n end\n", "meta": {"hexsha": "2b5246b79332b7a337b1c8c2d14e6e304842138f", "size": 2287, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "baserout/expgmat.f", "max_stars_repo_name": "ak-ustutt/GeCCo-public", "max_stars_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "baserout/expgmat.f", "max_issues_repo_name": "ak-ustutt/GeCCo-public", "max_issues_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baserout/expgmat.f", "max_forks_repo_name": "ak-ustutt/GeCCo-public", "max_forks_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.2873563218, "max_line_length": 72, "alphanum_fraction": 0.4403148229, "num_tokens": 743, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625012602594, "lm_q2_score": 0.8244619242200081, "lm_q1q2_score": 0.7679553661278152}} {"text": "! Created by EverLookNeverSee@GitHub on 5/28/20\n! For more information see FCS/img/Exercise_02.png\n\nprogram main\n implicit none\n ! P = earth pressure on a retaining structure\n ! w --> wieght per unit volume of filled up earth\n ! h --> height of earth fill\n ! phi --> angle of repose of filled material\n ! declaring variables\n real :: w = 513.0, h = 3.0, phi = 30.0, P, radian_phi\n ! the argument of trigonometric functions must be in radians\n radian_phi = phi * 3.1415 / 180.0\n ! calculating P\n P = ((w * h ** 2.0) / 2.0) * ((1.0 - sin(radian_phi)) / (1.0 + sin(radian_phi)))\n ! formated print statement\n print \"(a3,f10.6)\", \"P: \", P\nend program main\n", "meta": {"hexsha": "9d0072544a45f04c21a83ce1612edb687ae8c89b", "size": 690, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical methods/Exercise_02.f90", "max_stars_repo_name": "EverLookNeverSee/FCS", "max_stars_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-14T10:30:25.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-17T13:03:15.000Z", "max_issues_repo_path": "src/numerical methods/Exercise_02.f90", "max_issues_repo_name": "EverLookNeverSee/FCS", "max_issues_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-06-06T13:54:45.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-25T20:32:23.000Z", "max_forks_repo_path": "src/numerical methods/Exercise_02.f90", "max_forks_repo_name": "EverLookNeverSee/FCS", "max_forks_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-08T12:57:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T12:57:46.000Z", "avg_line_length": 36.3157894737, "max_line_length": 84, "alphanum_fraction": 0.6362318841, "num_tokens": 224, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037241905732, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.767849105274223}} {"text": "program data_types\n\n! This program prints the maximum values for intrinsic integer data types,\n! and minimum and maximum values for intrinsic real data types.\n\n use iso_fortran_env, only: int8, int16, int32, int64, real32, real64, real128\n\n implicit none\n\n integer(int8) :: i8\n integer(int16) :: i16\n integer(int32) :: i32\n integer(int64) :: i64\n\n real(real32) :: r32\n real(real64) :: r64\n real(real128) :: r128\n\n print *, 'This program prints the range of standard integer &\n and real kinds available in iso_fortran_env'\n\n print *, 'Largest int8: ', huge(i8)\n print *, 'Largest int16: ', huge(i16)\n print *, 'Largest int32: ', huge(i32)\n print *, 'Largest int64: ', huge(i64)\n\n print *, 'Smallest/largest real32: ', tiny(r32), huge(r32)\n print *, 'Smallest/largest real64: ', tiny(r64), huge(r64)\n print *, 'Smallest/largest real128: ', tiny(r128), huge(r128)\n\nend program data_types\n", "meta": {"hexsha": "1259acb0fce285ae37ab068071df9d7f9c3a3f28", "size": 913, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortify/mf/listings/src/ch02/data_types.f90", "max_stars_repo_name": "wilsonify/c-consumer", "max_stars_repo_head_hexsha": "e19a1baf4efb68436bbec50395f2a3a2c6e3c078", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2018-03-29T13:23:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-01T19:47:30.000Z", "max_issues_repo_path": "src/fortify/mf/listings/src/ch02/data_types.f90", "max_issues_repo_name": "wilsonify/c-consumer", "max_issues_repo_head_hexsha": "e19a1baf4efb68436bbec50395f2a3a2c6e3c078", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-11-01T15:03:32.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-12T21:01:01.000Z", "max_forks_repo_path": "src/fortify/mf/listings/src/ch02/data_types.f90", "max_forks_repo_name": "wilsonify/c-consumer", "max_forks_repo_head_hexsha": "e19a1baf4efb68436bbec50395f2a3a2c6e3c078", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2018-04-01T19:53:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-30T23:33:14.000Z", "avg_line_length": 28.53125, "max_line_length": 79, "alphanum_fraction": 0.6812705367, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105696, "lm_q2_score": 0.84997116805678, "lm_q1q2_score": 0.7677740363965554}} {"text": "! \n! CalculiX - A 3-dimensional finite element program\n! Copyright (C) 1998-2021 Guido Dhondt\n! \n! This program is free software; you can redistribute it and/or\n! modify it under the terms of the GNU General Public License as\n! published by the Free Software Foundation(version 2);\n! \n! \n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of \n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n! GNU General Public License for more details.\n! \n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n! \n! Subroutine plane_eq.f\n!\n! Creates the plane equation from three known points. \n! Gives the z-coordinate of the fourth point as an output.\n!\n! x1,y1,z1: The coordinates of the first point\n! x2,y2,z2: The coordinates of the second point\n! x3,y3,z3: The coordinates of the third point\n! x0,y0: The x and y-coordinates for the fourth point\n! output: The z-coordinate according to the x0 and y0\n!\n! by: Jaro Hokkanen\n!\n subroutine plane_eq(x1,y1,z1,x2,y2,z2,x3,y3,z3,x0,y0,output)\n!\n implicit none\n!\n real*8 x1,y1,z1,x2,y2,z2,x3,y3,z3,x0,y0,output,\n & a,b,c,d\n!\n d=x1*y2*z3+y1*z2*x3+z1*x2*y3-x1*z2*y3-y1*x2*z3-z1*y2*x3\n if(d.ne.0.d0) then\n a=1.d0/d*(y2*z3+y1*z2+z1*y3-z2*y3-y1*z3-z1*y2)\n endif \n if(d.ne.0.d0) then\n b=1.d0/d*(x1*z3+z2*x3+z1*x2-x1*z2-x2*z3-z1*x3)\n endif \n if(d.ne.0.d0) then\n c=1.d0/d*(x1*y2+y1*x3+x2*y3-x1*y3-y1*x2-y2*x3)\n endif \n if(d.ne.0.d0) then\n output=1.d0/c*(1.d0-a*x0-b*y0)\n else\n output=0.d0\n endif\n return\n end\n", "meta": {"hexsha": "2415cf16054a25aaa1b693c91ead883a4686e292", "size": 1891, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ccx_prool/CalculiX/ccx_2.19/src/plane_eq.f", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/CalculiX/ccx_2.19/src/plane_eq.f", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ccx_prool/CalculiX/ccx_2.19/src/plane_eq.f", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.7678571429, "max_line_length": 71, "alphanum_fraction": 0.6266525648, "num_tokens": 618, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248225478307, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7677227295143126}} {"text": "real*8 function SHConfidence(l_conf, r)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis subroutine will calculate the probability that two sets of spherical\n!\tharmonic coefficients, which possess a correlation coefficients r, are \n!\tlinearly correlated at a given degree. This is calucated according to\n!\tequation A7 in Pauer et al. (2007), which is from Eckhard 1984, and MathWorld \n!\thttp://mathworld.wolfram.com/CorrelationCoefficientBivariateNormalDistribution.html.\n!\n!\tCALLING PARAMETERS\n!\t\tINPUT\n!\t\t\tl_conf\t\tdegree to calculate confidence levels.\n!\t\t\tr\t\tthe correlation coefficient of two sets\n!\t\t\t\t\tof spherical harmonic coeficients at degree l_conf.\n!\t\tOUTPUT\n!\t\t\tcl\t\tThe confidence level.\n!\n!\tWritten by Mark Wieczorek (April 18, 2007)\n!\n!\tCopyright (c) 2007, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\treal*8, intent(in) :: r\n\tinteger, intent(in) :: l_conf\n\treal*8 :: prod\n\tinteger:: l, i\n\n\tSHConfidence = abs(r)\n\tprod = 1.0d0\n\t\n\tdo l=2, l_conf, 1\n\t\ti = l-1\n\t\tprod = prod * dble(2*i-1) / dble(2*i)\n\t\tSHConfidence = SHConfidence + prod * abs(r) * (1.0d0 - r**2)**(l-1)\n\tenddo\n\nend function SHConfidence\n", "meta": {"hexsha": "4c37142e571f2ac64edc94c13c4370326e0d9fd3", "size": 1279, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/SHConfidence.f95", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "spherical_splines/SHTOOLS/src/SHConfidence.f95", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "spherical_splines/SHTOOLS/src/SHConfidence.f95", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 31.975, "max_line_length": 95, "alphanum_fraction": 0.6129788898, "num_tokens": 372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480346, "lm_q2_score": 0.8198933271118222, "lm_q1q2_score": 0.7676538284876676}} {"text": "program main\n use timers\n type(TimerType) :: seriesTime,monteTime,totalTime\n \n integer npoints,i,numinside\n parameter (npoints=300000)\n complex*16 c(npoints)\n real*8 r1,r2,halfpi,err1,area,err2\n real rand\n\n call TimerCreate(seriesTime,\"series\")\n call TimerCreate(monteTime,\"monte\")\n call TimerCreate(totalTime,\"Series+monte\") \n\n! GENERATE RANDOM NUMBERS\n\n call srand(54321)\n do i=1,npoints\n r1=rand()\n r2=rand()\n c(i)=CMPLX(-2.0+2.5*r1,1.125*r2)\n end do\n\n call TimerOn(totalTime)\n\n! CALCULATE PI/2 FROM GREGORY'S FORMULA\n\t\t\n call TimerOn(seriesTime)\n call series(halfpi,err1)\n call TimerOff(seriesTime)\n\n! CALCULATE AREA OF MANDELBROT SET BY MONTE CARLO SAMPLING \n\t\n call TimerOn(monteTime)\n call monte(c,numinside)\n call TimerOff(monteTime)\n\n call TimerOff(totalTime)\n\n! OUTPUT RESULTS \n\n area = 2.0*2.5*1.125 * real(numinside)/real(npoints)\n err2 = area/sqrt(real(npoints))\n print *, \"Pi/2 = \", halfpi,\" +/- \",err1\n print *, \"Area of Mandelbrot set = \",area,\" +/- \",err2\n\n! OUTPUT TIMING DATA \n \n call TimerPrint(seriesTime)\n call TimerPrint(monteTime)\n call TimerPrint(totalTime)\n\n stop\nend program main\n\nsubroutine series(halfpi,err)\n\n real*8 halfpi,err,sum\n integer sign,terms,denom,i\n parameter (terms = 100000000)\n\n sum=0.0d0\n sign=1\n denom=1\n\n do i=1,terms\n sum=sum + sign*(1.0d0/denom)\n sign=(-sign)\n denom=denom + 2\n end do\n\n halfpi = 2.0d0 * sum \n err = 2.0d0/terms\n return\nend subroutine series\n\t\nsubroutine monte(c,numinside)\n\n integer npoints,npoints_p,maxiter,maxiter_p,numinside,i,j\n parameter (npoints_p=300000,maxiter_p=10000)\n complex*16 c(npoints_p),z\n\n maxiter=maxiter_p\n npoints=npoints_p\n numinside=0\n!$omp parallel do default (none) private(i,j,z) &\n!$omp shared (c,maxiter,npoints) reduction(+:numinside)\n\n do i=1,npoints\n z=(0.0,0.0)\n do j=1,maxiter\n z = z*z +c(i)\t \n if (abs(z).gt.2.0) goto 10\n end do\n numinside = numinside +1\n10 continue\n end do\n\n \n return\nend subroutine monte\n\n", "meta": {"hexsha": "e8f0212f838cf74c399728d46e07049aee9c9802", "size": 2020, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/lab2/mandel_par2.f90", "max_stars_repo_name": "arturocastro/SOR", "max_stars_repo_head_hexsha": "eb63341ca4082cb8f79f256d71c706912bc2852c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-24T18:13:05.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-24T18:13:05.000Z", "max_issues_repo_path": "source/lab2/mandel_par2.f90", "max_issues_repo_name": "arturocastro/SOR", "max_issues_repo_head_hexsha": "eb63341ca4082cb8f79f256d71c706912bc2852c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/lab2/mandel_par2.f90", "max_forks_repo_name": "arturocastro/SOR", "max_forks_repo_head_hexsha": "eb63341ca4082cb8f79f256d71c706912bc2852c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.6116504854, "max_line_length": 60, "alphanum_fraction": 0.6801980198, "num_tokens": 686, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937712, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7675265018630315}} {"text": "program Automorphic_check\n implicit none\n Integer(kind=16) :: a,sq\n print*, \"Give an integer to check whether it is automorphic or not\"\n read *, a\n sq = a*a\n print *, \"Square is:\", sq\n do while (a>0)\n if (mod(a,10) .ne. mod(sq,10)) then\n print*, \"Non-automorphic\"\n stop\n end if\n a= a/10\n sq = sq/10\n end do\n print *, \"Automorphic\"\nend program Automorphic_check", "meta": {"hexsha": "4d7ad0ffb9d0256cd2696ddfc1b7af37a1855419", "size": 437, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Automorphiccheck.f90", "max_stars_repo_name": "sciencyboi/smallfortran90programs", "max_stars_repo_head_hexsha": "9d79d9d27ebe229bae1dd2d6c131217fef71c1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Automorphiccheck.f90", "max_issues_repo_name": "sciencyboi/smallfortran90programs", "max_issues_repo_head_hexsha": "9d79d9d27ebe229bae1dd2d6c131217fef71c1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Automorphiccheck.f90", "max_forks_repo_name": "sciencyboi/smallfortran90programs", "max_forks_repo_head_hexsha": "9d79d9d27ebe229bae1dd2d6c131217fef71c1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.7058823529, "max_line_length": 71, "alphanum_fraction": 0.5583524027, "num_tokens": 129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7675264998811279}} {"text": "PROGRAM factorial\nIMPLICIT NONE\n INTEGER :: index, n, result = 1 ! User input n and output result for factorial function\n WRITE(*, *) \"Enter a non-negative integer to compute its factorial:\"\n READ(*, *) n\n IF (n .lt. 0) THEN\n WRITE(*, *) \"You must enter a non-negative integer.\"\n ELSE\n DO index = 0, n - 1\n result = result * (n - index)\n END DO\n WRITE(*, *) \"Factorial of \", n, \" = \", result\n END IF\nEND PROGRAM factorial\n", "meta": {"hexsha": "90a7ddd6db3f95cd1a6e01073ad6c3cf4e697338", "size": 445, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap4/factorial.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap4/factorial.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap4/factorial.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.6666666667, "max_line_length": 89, "alphanum_fraction": 0.6247191011, "num_tokens": 132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.7675218671104631}} {"text": "! **\n! * Provides functions to compute the derivative of a function numerically\n! **\nmodule nderiv\n use kinds, only: dp\n implicit none\n private\n public :: linderiv\n\n contains\n\n ! **\n ! * Calculates the derivative of the function y = f(x) using the method of finite differences.\n ! *\n ! * Input:\n ! * - x: array representing the x-values of the function f\n ! * - y: array representing the y-values of the function f (same size as array x)\n ! *\n ! * Return value: array for the right derivatives df(x)/dx.\n ! *\n ! * Note: the last two values are equal\n ! **\n function linderiv(x,y) result(dxy)\n real(dp),dimension(:), intent(in) :: x,y\n real(dp),dimension(size(x)) :: dxy\n integer :: dx_size\n\n dx_size = size(x)\n dxy = (eoshift(y,1)-y) / (eoshift(x,1)-x)\n dxy(dx_size)=dxy(dx_size-1)\n end function\n\nend module nderiv\n", "meta": {"hexsha": "2a71bb792fdc2241fb8a311fb684ccfa5fda59dd", "size": 1048, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "nderiv.f90", "max_stars_repo_name": "carlozanella/ncegm", "max_stars_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-03-14T23:31:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-14T23:31:35.000Z", "max_issues_repo_path": "nderiv.f90", "max_issues_repo_name": "carlozanella/ncegm", "max_issues_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "nderiv.f90", "max_forks_repo_name": "carlozanella/ncegm", "max_forks_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.8235294118, "max_line_length": 102, "alphanum_fraction": 0.5219465649, "num_tokens": 259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308073258007, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.7674566577772693}} {"text": "!===--- Jacobi.f90 ----- Jacobi Iterative Method ----*- Fortran -*-===!\n!\n! This file implements Jacobi iterative method which is an iterative\n! method used to solve partial differential equations.\n!\n!===---------------------------------------------------------------===!\n\nprogram Jacobi\n parameter (L = 8, ITMAX = 10)\n real A(L,L), Eps, Maxeps, B(L, L)\n MAXEPS = 0.5\n do J = 1, L\n do I = 1, L\n A(I, J) = 0.\n if (I == 1 .or. J == 1 .or. I == L .or. J == L) then\n B(I, J) = 0.\n else\n B(I, J) = 1. + I + J\n endif\n enddo\n enddo\n do It = 1, ITMAX\n Eps = 0.\n do J = 2, L - 1\n do I = 2, L - 1\n Eps = max(Eps, abs(B(I, J) - A(I, J)))\n A(I, J) = B(I, J)\n enddo\n enddo\n do J = 2, L - 1\n do I = 2, l - 1\n B(I, J) = (A(I, J-1) + A(I-1, J) + A(I+1, J) + A(I, J+1) ) / 4.\n enddo\n enddo\n print 200, It, Eps\n200 format (' It = ', i4, ' Eps = ', e14.7)\n if (Eps < MAXEPS) exit\n enddo\nend\n", "meta": {"hexsha": "d7fe6c7f6b808ad8828642f52398098b93e99a1b", "size": 996, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/instrumentation/Jacobi.f90", "max_stars_repo_name": "yukatan1701/tsar", "max_stars_repo_head_hexsha": "a6f95cdaeb117ccd5fcb775b471b1aa17c45f4e8", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2019-11-04T15:03:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-07T17:29:40.000Z", "max_issues_repo_path": "test/instrumentation/Jacobi.f90", "max_issues_repo_name": "yukatan1701/tsar", "max_issues_repo_head_hexsha": "a6f95cdaeb117ccd5fcb775b471b1aa17c45f4e8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2019-11-29T21:18:12.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-22T21:36:40.000Z", "max_forks_repo_path": "test/instrumentation/Jacobi.f90", "max_forks_repo_name": "yukatan1701/tsar", "max_forks_repo_head_hexsha": "a6f95cdaeb117ccd5fcb775b471b1aa17c45f4e8", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2019-10-15T13:56:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-20T17:21:14.000Z", "avg_line_length": 24.9, "max_line_length": 72, "alphanum_fraction": 0.4196787149, "num_tokens": 395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7673517066377226}} {"text": "!=====================================================\nSUBROUTINE eva2d_sd(nx,ny,ix,iy,dx,dy,spl,spval)\n\n! Evaluates the second derivatives of 2-dimensional cubic spline of function f(x,y)\n!\n! Input: nx, ny number of values in x and y\n! ix, iy pointer into the spline array spl\n! dx, dy distance from x(ix) and y(iy)\n! spl array with spline data\n! Output: spval(3) evaluated function values\n! spval(1) = d^2f/dx^2\n! spval(2) = d^2f/(dxdy)\n! spval(3) = d^2f/dy^2\n\n USE neo_precision\n\n IMPLICIT NONE\n\n INTEGER, INTENT(in) :: nx, ny, ix, iy\n REAL(kind=dp), INTENT(in) :: dx, dy\n REAL(kind=dp), DIMENSION(4,4,nx,ny), INTENT(in) :: spl\n REAL(kind=dp), DIMENSION(3), INTENT(out) :: spval\n\n INTEGER :: i,j\n REAL(kind=dp) :: muli, mulj\n\n spval = 0\n\n! d^2f/dx^2\n DO i=3,4\n IF (i == 3) THEN\n muli = 1\n ELSE\n muli = dx**(i-3)\n END IF\n muli = muli * (i-1) * (i-2)\n DO j=1,4\n IF (j == 1) THEN\n mulj = 1\n ELSE\n mulj = dy**(j-1)\n END IF\n spval(1) = spval(1) + spl(i,j,ix,iy) * muli * mulj\n END DO\n END DO\n\n! d^2f/(dxdy)\n DO i=2,4\n IF (i == 2) THEN\n muli = 1\n ELSE\n muli = dx**(i-2)\n END IF\n muli = muli * (i-1)\n DO j=2,4\n IF (j == 2) THEN\n mulj = 1\n ELSE\n mulj = dy**(j-2)\n END IF\n mulj = mulj * (j-1)\n spval(2) = spval(2) + spl(i,j,ix,iy) * muli * mulj\n END DO\n END DO\n\n! d^2f/dy^2\n DO i=1,4\n IF (i == 1) THEN\n muli = 1\n ELSE\n muli = dx**(i-1)\n END IF\n DO j=3,4\n IF (j == 3) THEN\n mulj = 1\n ELSE\n mulj = dy**(j-3)\n END IF\n mulj = mulj * (j-1) * (j-2)\n spval(3) = spval(3) + spl(i,j,ix,iy) * muli * mulj\n END DO\n END DO\n\n RETURN\nEND SUBROUTINE eva2d_sd\n", "meta": {"hexsha": "22eb22a0e663ef529cf821ab4c6680e65063d809", "size": 2134, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "NEO/Sources/eva2d_sd.f90", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "NEO/Sources/eva2d_sd.f90", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "NEO/Sources/eva2d_sd.f90", "max_forks_repo_name": "joseluisvelasco/STELLOPT", "max_forks_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 24.8139534884, "max_line_length": 83, "alphanum_fraction": 0.4119025305, "num_tokens": 746, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.837619959279793, "lm_q1q2_score": 0.7673516933936414}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! DARCG22 (Double Auxiliary Routine Compute Givens generators 2->2)\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine computes the generator for A Givens rotation represented\n! by 2 real numbers: A strictly real cosine and A scrictly real sine. \n! The first column is constructed to be parallel with the real vector \n! [A,B]^T. The (2->2) refers to the 2 double inputs and 2 double outputs \n! (excluding the norm).\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! A REAL(8) \n! the first component of the real vector [A,B]^T\n!\n! B REAL(8) \n! the second component of the real vector [A,B]^T\n!\n! OUTPUT VARIABLES:\n!\n! C REAL(8)\n! on exit contains the generator for the cosine\n! component of the Givens rotation\n!\n! S REAL(8)\n! on exit contains the generator for the sine\n! component of the Givens rotation\n!\n! NRM REAL(8)\n! on exit contains the norm of the vector [A,B]^T\n!\n! INFO INTEGER\n! INFO = 0 implies successful computation\n! INFO = -1 implies A is invalid\n! INFO = -2 implies B is invalid\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine DARCG22(A,B,C,S,NRM,INFO)\n\n implicit none\n \n ! input variables\n integer, intent(inout) :: INFO\n real(8), intent(in) :: A,B\n real(8), intent(inout) :: C,S,NRM\n \n ! compute variables\n real(8), parameter :: tol = epsilon(1d0)\n\n ! initialize INFO\n INFO = 0\n\n ! check input in debug mode\n if (DEBUG) then \n \n ! Check A\n call DARACH1(1,A,INFO)\n call UARERR(__FILE__,__LINE__,\"A is invalid\",INFO,-1)\n if (INFO.NE.0) then \n return \n end if \n \n ! Check B\n call DARACH1(1,B,INFO)\n call UARERR(__FILE__,__LINE__,\"B is invalid\",INFO,-2)\n if (INFO.NE.0) then \n return \n end if \n \n end if \n \n ! construct rotation\n NRM = 1d0 \n if (B == 0) then\n if (A<0) then \n C = -1d0\n S = 0d0\n NRM = -A\n else\n C = 1d0\n S = 0d0\n NRM = A\n endif\n else if (abs(A) >= abs(B)) then\n S = B/A\n NRM = sqrt(1.d0 + S**2)\n if (A<0) then\n C = -1.d0/NRM\n S = S*C\n NRM = -A*NRM\n else\n C = 1.d0/NRM\n S = S*C\n NRM = A*NRM\n end if\n else\n C = A/B;\n NRM = sqrt(1.d0 + C**2)\n if (B<0) then\n S = -1.d0/NRM\n C = C*S\n NRM = -B*NRM\n else\n S = 1.d0/NRM\n C = C*S\n NRM = B*NRM\n end if\n end if\n \nend subroutine DARCG22\n", "meta": {"hexsha": "416e3c45b72e5f6237e214a00fba1298a802b01d", "size": 2866, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "deps/eiscor-master/src/double/DARCG22.f90", "max_stars_repo_name": "andreasnoack/EiSCor.jl", "max_stars_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "deps/eiscor-master/src/double/DARCG22.f90", "max_issues_repo_name": "andreasnoack/EiSCor.jl", "max_issues_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "deps/eiscor-master/src/double/DARCG22.f90", "max_forks_repo_name": "andreasnoack/EiSCor.jl", "max_forks_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.7068965517, "max_line_length": 73, "alphanum_fraction": 0.4623168179, "num_tokens": 841, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119663, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7673166951806928}} {"text": "! Copyright (C) 2012 The SPEED FOUNDATION\n! Author: Ilario Mazzieri\n!\n! This file is part of SPEED.\n!\n! SPEED is free software; you can redistribute it and/or modify it\n! under the terms of the GNU Affero General Public License as\n! published by the Free Software Foundation, either version 3 of the\n! License, or (at your option) any later version.\n!\n! SPEED is distributed in the hope that it will be useful, but\n! WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n! Affero General Public License for more details.\n!\n! You should have received a copy of the GNU Affero General Public License\n! along with SPEED. If not, see .\n\n!> @brief Computes derivative of Legendre basis function.\n!! @author Ilario Mazzieri\n!> @date September, 2013 \n!> @version 1.0\n!> @param[in] ng polynomial degree\n!> @param[in] csii GLL node\n!> @param[in] csij GLL node identifying the basis function\n!> @param[out] DPHI derivative of the j-th (csij) basis function of degree ng at node csii \n!! DPHI(ng,csii,csij) = DPHI_csij/dcsi (csii) \n\n function DPHI(ng,csii,csij)\n \n implicit real*8 (a-h,o-z) \n\n integer*4 :: ng \n \n call GET_LEGENDRE_VALUE_2DER(p2der2,p2,p2der,p1,p1der,ng,csii) \n call GET_LEGENDRE_VALUE_2DER(q2der2,q2,q2der,q1,q1der,ng,csij) \n\n if(abs(csij + 1.d0).le. 1.e-8 .and. abs(csii + 1.d0).le. 1.e-8) then\n DPHI = -(ng+1.d0)*ng/4.d0 \n elseif(abs(csij - 1.d0).le. 1.e-8 .and. abs(csii - 1.d0).le. 1.e-8) then\n DPHI = (ng+1.d0)*ng/4.d0\n elseif(abs(csii - csij).le. 1.e-8) then\n DPHI = 0.d0 \n else\n anum = (csij-csii)*ng*(ng+1.d0)*q2 + (1.d0-csij**2.d0)*q2der\n aden = p2*ng*(ng+1.d0)*(csii - csij)**2.d0\n DPHI = anum/aden\n endif\n \n if(abs(DPHI) .lt. 1.e-10) then\n DPHI = 0.d0\n endif\n\n return \n end function DPHI\n\n", "meta": {"hexsha": "029624dc8ed9c0eca0d64b34e7d85aa75da4b520", "size": 2096, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SRC/SPEED-MDOF190510/DPHI.f90", "max_stars_repo_name": "research-group-of-Xinzheng-Lu/SCI-effects-simulation", "max_stars_repo_head_hexsha": "6f91a4afce51303ac33d9dce005247290679b428", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-05-11T17:26:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-31T12:41:29.000Z", "max_issues_repo_path": "SRC/SPEED-MDOF190510/DPHI.f90", "max_issues_repo_name": "research-group-of-Xinzheng-Lu/SCI-effects-simulation", "max_issues_repo_head_hexsha": "6f91a4afce51303ac33d9dce005247290679b428", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SRC/SPEED-MDOF190510/DPHI.f90", "max_forks_repo_name": "research-group-of-Xinzheng-Lu/SCI-effects-simulation", "max_forks_repo_head_hexsha": "6f91a4afce51303ac33d9dce005247290679b428", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-05-15T06:26:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-10T07:22:41.000Z", "avg_line_length": 36.7719298246, "max_line_length": 91, "alphanum_fraction": 0.6049618321, "num_tokens": 684, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.76731667850085}} {"text": "!> @brief This function returns the integral of the supplied 2D tabulated data.\n!>\n!> @param[in] x1 The first variable of integration.\n!>\n!> @param[in] x2 The second variable of integration.\n!>\n!> @param[in] arr The integrand.\n!>\n!> @note \"x1\" and \"x2\" do not have to be uniform.\n!>\n!> @warning \"x1\" must be the same as the first dimension of \"arr\".\n!>\n!> @warning \"x2\" must be the same as the second dimension of \"arr\".\n!>\n\nPURE FUNCTION func_integrate_2D_REAL64_real_array(x1, x2, arr) RESULT(ans)\n USE ISO_FORTRAN_ENV\n\n IMPLICIT NONE\n\n ! Declare input variables ...\n REAL(kind = REAL64), DIMENSION(:), INTENT(in) :: x1\n REAL(kind = REAL64), DIMENSION(:), INTENT(in) :: x2\n REAL(kind = REAL64), DIMENSION(:, :), INTENT(in) :: arr\n\n ! Declare output variables ...\n REAL(kind = REAL64) :: ans\n\n ! Declare internal variables ...\n INTEGER(kind = INT64) :: i1\n INTEGER(kind = INT64) :: i2\n INTEGER(kind = INT64) :: n1\n INTEGER(kind = INT64) :: n2\n\n ! Find size of input arrays ...\n n1 = SIZE(x1, kind = INT64)\n n2 = SIZE(x2, kind = INT64)\n\n ! Set starting value ...\n ans = 0.0e0_REAL64\n\n ! Loop over x ...\n DO i1 = 1_INT64, n1 - 1_INT64\n ! Loop over y ...\n DO i2 = 1_INT64, n2 - 1_INT64\n ! Integrate via the trapezium rule ...\n ans = ans + (x1(i1 + 1_INT64) - x1(i1)) * (x2(i2 + 1_INT64) - x2(i2)) * 0.25e0_REAL64 * (arr(i1, i2) + arr(i1 + 1_INT64, i2) + arr(i1, i2 + 1_INT64) + arr(i1 + 1_INT64, i2 + 1_INT64))\n END DO\n END DO\nEND FUNCTION func_integrate_2D_REAL64_real_array\n", "meta": {"hexsha": "de5f215b683c7eac37bda55f1dc51d9e1aea3c41", "size": 1939, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mod_safe/func_integrate_array/func_integrate_2D_REAL64_real_array.f90", "max_stars_repo_name": "Guymer/fortranlib", "max_stars_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-28T02:05:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-16T16:50:21.000Z", "max_issues_repo_path": "mod_safe/func_integrate_array/func_integrate_2D_REAL64_real_array.f90", "max_issues_repo_name": "Guymer/fortranlib", "max_issues_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-06-17T16:49:20.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-11T18:47:36.000Z", "max_forks_repo_path": "mod_safe/func_integrate_array/func_integrate_2D_REAL64_real_array.f90", "max_forks_repo_name": "Guymer/fortranlib", "max_forks_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-11T04:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-11T04:51:33.000Z", "avg_line_length": 38.0196078431, "max_line_length": 195, "alphanum_fraction": 0.4981949458, "num_tokens": 539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148512, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.7672452197874736}} {"text": "module dyn_sys\n use nrtype\n implicit none\n real(dp) :: a, b, c, u, d, alpha, beta\n\ncontains\n\n subroutine Chen(x,y,dydx)\n ! https://en.wikipedia.org/wiki/Multiscroll_attractor\n ! x := t\n ! y(1:3) := x, y, z\n ! dydx(1:3) := dx/dt, dy/dt, dz/dt\n implicit none\n real(dp), intent(in) :: x, y(:)\n real(dp), intent(out) :: dydx(:)\n\n dydx(1) = a * (y(2) - y(1))\n dydx(2) = (c-a) * y(1) - y(1) * y(3) + c * y(2)\n dydx(3) = y(1) * y(2) - b * y(3)\n end subroutine Chen\n\n subroutine Lu_Chen(x,y,dydx)\n ! https://en.wikipedia.org/wiki/Multiscroll_attractor\n ! x := t\n ! y(1:3) := x, y, z\n ! dydx(1:3) := dx/dt, dy/dt, dz/dt\n implicit none\n real(dp), intent(in) :: x, y(:)\n real(dp), intent(out) :: dydx(:)\n\n dydx(1) = a * (y(2) - y(1))\n dydx(2) = y(1) - y(1) * y(3) + c * y(2) + u\n dydx(3) = y(1) * y(2) - b * y(3)\n end subroutine Lu_Chen\n\n subroutine mc_Chua(x,y,dydx)\n implicit none\n real(dp), intent(in) :: x, y(:)\n real(dp), intent(out) :: dydx(:)\n\n dydx(1) = alpha * (y(2) - b * sin(pi*y(1))/(2.*a) + d)\n dydx(2) = y(1) - y(2) + y(3)\n dydx(3) = -beta * y(2)\n end subroutine mc_Chua\n\nend module dyn_sys\n", "meta": {"hexsha": "a4bf1a85302da147833acf94cc5aba0faa7d934e", "size": 1184, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "dynamical_systems/dyn_sys.f08", "max_stars_repo_name": "dcelisgarza/applied_math", "max_stars_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2015-09-30T19:22:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T23:33:04.000Z", "max_issues_repo_path": "dynamical_systems/dyn_sys.f08", "max_issues_repo_name": "dcelisgarza/applied_math", "max_issues_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dynamical_systems/dyn_sys.f08", "max_forks_repo_name": "dcelisgarza/applied_math", "max_forks_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.1914893617, "max_line_length": 58, "alphanum_fraction": 0.5084459459, "num_tokens": 508, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148512, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.7672452197874735}} {"text": "! Módulo para juntar funções que resolvem sistemas\n! lineares cuja matriz de coeficientes é triangular\n! inferior ou superior\nmodule trisys\n implicit none\ncontains\n ! Resolve um sistema linear\n ! Ax = b\n ! com\n ! A ∈ ℝⁿˣⁿ, triangular inferior\n ! b ∈ ℝⁿ\n ! com orientação a colunas, gravando\n ! a solução (x ∈ ℝⁿ) sobre o vetor b.\n ! Opcionalmente resolve para A triangular\n ! inferior unitária, não acessando os elementos\n ! da diagonal principal neste caso.\n ! Retorna\n ! 0: caso tenha resolvido o sistema com sucesso\n ! -1: caso a matriz A seja singular e sistema\n ! não possa ser resolvido\n !\n function forwcol(n, A, b, unit) result(status)\n integer, intent(in) :: n\n double precision, intent(in) :: A(:, :)\n double precision, intent(inout) :: b(:)\n logical, intent(in) :: unit\n\n integer :: i, j\n integer :: status\n\n status = -1\n\n do j = 1, n\n if (.not. unit) then\n if (A(j, j) == 0) then\n return\n end if\n\n b(j) = b(j)/A(j, j)\n end if\n\n do i = j+1, n\n b(i) = b(i) - b(j)*A(i, j)\n end do\n end do\n\n status = 0\n end function forwcol\n\n ! Resolve um sistema linear\n ! Ax = b\n ! com\n ! A ∈ ℝⁿˣⁿ, triangular inferior\n ! b ∈ ℝⁿ\n ! com orientação a linhas, gravando\n ! a solução (x ∈ ℝⁿ) sobre o vetor b.\n ! Opcionalmente resolve para A triangular\n ! inferior unitária, não acessando os elementos\n ! da diagonal principal neste caso.\n ! Retorna\n ! 0: caso tenha resolvido o sistema com sucesso\n ! -1: caso a matriz A seja singular e sistema\n ! não possa ser resolvido\n !\n function forwrow(n, A, b, unit) result(status)\n integer, intent(in) :: n\n double precision, intent(in) :: A(:, :)\n double precision, intent(inout) :: b(:)\n logical, intent(in) :: unit\n\n integer :: i, j\n integer :: status\n\n status = -1\n\n do i = 1, n\n if (.not. unit) then\n if (A(i, i) == 0) then\n return\n end if\n end if\n\n do j = 1, i-1\n b(i) = b(i) - b(j)*A(i, j)\n end do\n\n if (.not. unit) b(i) = b(i)/A(i, i)\n end do\n\n status = 0\n end function forwrow\n\n\n ! Resolve um sistema linear\n ! Ax = b\n ! com\n ! A ∈ ℝⁿˣⁿ, triangular superior\n ! b ∈ ℝⁿ\n ! com orientação a colunas, gravando\n ! a solução (x ∈ ℝⁿ) sobre o vetor b.\n ! Além disso, pode receber no lugar de A,\n ! sua transposta, fato indicado pela variável\n ! trans.\n ! Retorna\n ! 0: caso tenha resolvido o sistema com sucesso\n ! -1: caso a matriz A seja singular e sistema\n ! não possa ser resolvido\n function backcol(n, A, b, trans) result(status)\n integer, intent(in) :: n\n double precision, intent(in) :: A(:, :)\n double precision, intent(inout) :: b(:)\n logical, intent(in) :: trans\n\n integer :: i, j\n integer :: status\n\n status = -1\n if (trans) then\n do j = n, 1, -1\n if (A(j, j) == 0) then\n return\n end if\n\n do i = j+1, n\n b(j) = b(j) - b(i)*A(i, j)\n end do\n\n b(j) = b(j)/A(j, j)\n end do\n status = 0\n return\n else\n do j = n, 1, -1\n if (A(j, j) == 0) then\n return\n end if\n\n b(j) = b(j)/A(j, j)\n\n do i = 1, j-1\n b(i) = b(i) - b(j)*A(i, j)\n end do\n end do\n\n status = 0\n return\n end if\n end function backcol\n\n ! Resolve um sistema linear\n ! Ax = b\n ! com\n ! A ∈ ℝⁿˣⁿ, triangular superior\n ! b ∈ ℝⁿ\n ! com orientação a linhas, gravando\n ! a solução (x ∈ ℝⁿ) sobre o vetor b.\n ! Além disso, pode receber no lugar de A,\n ! sua transposta, fato indicado pela variável\n ! trans.\n ! Retorna\n ! 0: caso tenha resolvido o sistema com sucesso\n ! -1: caso a matriz A seja singular e sistema\n ! não possa ser resolvido\n function backrow(n, A, b, trans) result(status)\n integer, intent(in) :: n\n double precision, intent(in) :: A(:, :)\n double precision, intent(inout) :: b(:)\n logical, intent(in) :: trans\n\n integer :: i, j\n integer :: status\n\n status = -1\n if (trans) then\n do i = n, 1, -1\n if (A(i, i) == 0) then\n return\n end if\n\n b(i) = b(i)/A(i, i)\n\n do j = 1, i-1\n b(j) = b(j) - b(i)*A(i, j)\n end do\n end do\n\n status = 0\n return\n else\n do i = n, 1, -1\n if (A(i, i) == 0) then\n return\n end if\n\n do j = i+1, n\n b(i) = b(i) - b(j)*A(i, j)\n end do\n\n b(i) = b(i)/A(i, i)\n end do\n status = 0\n return\n end if\n end function backrow\nend module trisys\n", "meta": {"hexsha": "17c0b63163c0eeaf8d08ec703ddb4b93ea2c8dcd", "size": 5473, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "EP/src/trisys.f08", "max_stars_repo_name": "lmagno/MAC0427", "max_stars_repo_head_hexsha": "81229a5ad2ff8d8c2e89f0211df5fb9eee2a1836", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-01-24T22:57:33.000Z", "max_stars_repo_stars_event_max_datetime": "2018-01-24T22:57:33.000Z", "max_issues_repo_path": "EP/src/trisys.f08", "max_issues_repo_name": "lmagno/MAC0427", "max_issues_repo_head_hexsha": "81229a5ad2ff8d8c2e89f0211df5fb9eee2a1836", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "EP/src/trisys.f08", "max_forks_repo_name": "lmagno/MAC0427", "max_forks_repo_head_hexsha": "81229a5ad2ff8d8c2e89f0211df5fb9eee2a1836", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.567961165, "max_line_length": 55, "alphanum_fraction": 0.4536817102, "num_tokens": 1596, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642905, "lm_q2_score": 0.8397339676722394, "lm_q1q2_score": 0.7672452141490347}} {"text": "Program Task3\n IMPLICIT NONE\n\n REAL :: h,xdash_s,xdash_mid,x_mid,vdash_s,vdash_mid,v_mid,k\n INTEGER :: i\n\n REAL, DIMENSION(1:1001) :: t\n REAL, DIMENSION(1:1001) :: x\n REAL, DIMENSION(1:1001) :: v\n REAL, DIMENSION(1:1001) :: error_x\n REAL, DIMENSION(1:1001) :: error_v\n\n !Open Files to store data\n\n OPEN(unit=12,file='Task3.dat')\n\n !k=spring_constant h=step v=velocity x=position\n\n h=0.01 \n\n !Define initial BCs\n\n t(1)=0\n v(1)=0\n x(1)=0.1\n k=5\n error_x(1)=x(1)-0.1*cos((5**0.5)*t(1))\n error_v(1)=v(1)+0.1*(5**0.5)*sin((5**0.5)*t(1))\n\n WRITE(12,'(5f9.5)') t(1),x(1),v(1),error_x(1),error_v(1)\n\n !Euler method for integrating two coupled ODEs simultaneously\n \n DO i=1,1000\n\n !Use these values at the midpoint\n\n vdash_s=-k*x(i)\n xdash_s=v(i)\n\n x_mid=x(i)+0.5*h*xdash_s\n v_mid=v(i)+0.5*h*vdash_s\n\n xdash_mid=v_mid\n vdash_mid=-k*x_mid\n\n !Input these values into the formulae below\n\n t(i+1)=t(i)+h\n x(i+1)=x(i)+h*xdash_mid\n v(i+1)=v(i)+h*vdash_mid\n\n error_x(i+1)=x(i+1)-0.1*cos((5**0.5)*t(i+1))\n error_v(i+1)=v(i+1)+0.1*(5**0.5)*sin((5**0.5)*t(i+1))\n\n !Write the values in the array to Task3.dat\n\n WRITE(12,'(5f9.5)') t(i+1),x(i+1),v(i+1),error_x(i+1),error_v(i+1)\n END DO\n\n!Run Program\n!Run gnuplot\n!Write \"plot \"Task3.dat\" using 1:2 with lines\n!,0.1*cos(sqrt(5)*x)\" in the terminal\n\nEND PROGRAM Task3\n", "meta": {"hexsha": "149e21e5fdbd0267448cdd137b0dc583ccf3c352", "size": 1369, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "assignment-0/Task3.f90", "max_stars_repo_name": "WilliamHoltam/numerical-physics", "max_stars_repo_head_hexsha": "00e51192872a8581df4f9556f2565cf14a01e70d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment-0/Task3.f90", "max_issues_repo_name": "WilliamHoltam/numerical-physics", "max_issues_repo_head_hexsha": "00e51192872a8581df4f9556f2565cf14a01e70d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-07-18T13:37:07.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-18T13:37:07.000Z", "max_forks_repo_path": "assignment-0/Task3.f90", "max_forks_repo_name": "WilliamHoltam/energy-entropy-and-numerical-physics", "max_forks_repo_head_hexsha": "00e51192872a8581df4f9556f2565cf14a01e70d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.4328358209, "max_line_length": 70, "alphanum_fraction": 0.6106647188, "num_tokens": 595, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836383, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7671144950842413}} {"text": " subroutine idd_house(n,x,rss,vn,scal)\nc\nc constructs the vector vn with vn(1) = 1\nc and the scalar scal such that\nc H := identity_matrix - scal * vn * transpose(vn) is orthogonal\nc and Hx = +/- e_1 * the root-sum-square of the entries of x\nc (H is the Householder matrix corresponding to x).\nc\nc input:\nc n -- size of x and vn, though the indexing on vn goes\nc from 2 to n\nc x -- vector to reflect into its first component\nc\nc output:\nc rss -- first entry of the vector resulting from the application\nc of the Householder matrix to x;\nc its absolute value is the root-sum-square\nc of the entries of x\nc vn -- entries 2 to n of the Householder vector vn;\nc vn(1) is assumed to be 1\nc scal -- scalar multiplying vn * transpose(vn);\nc\nc scal = 2/(1 + vn(2)^2 + ... + vn(n)^2)\nc when vn(2), ..., vn(n) don't all vanish;\nc\nc scal = 0\nc when vn(2), ..., vn(n) do all vanish\nc (including when n = 1)\nc\nc reference:\nc Golub and Van Loan, \"Matrix Computations,\" 3rd edition,\nc Johns Hopkins University Press, 1996, Chapter 5.\nc\n implicit none\n save\n integer n,k\n real*8 x(n),rss,sum,v1,scal,vn(2:*),x1\nc\nc\n x1 = x(1)\nc\nc\nc Get out of this routine if n = 1.\nc\n if(n .eq. 1) then\n rss = x1\n scal = 0\n return\n endif\nc\nc\nc Calculate (x(2))^2 + ... (x(n))^2\nc and the root-sum-square value of the entries in x.\nc\nc\n sum = 0\n do k = 2,n\n sum = sum+x(k)**2\n enddo ! k\nc\nc\nc Get out of this routine if sum = 0;\nc flag this case as such by setting v(2), ..., v(n) all to 0.\nc\n if(sum .eq. 0) then\nc\n rss = x1\n do k = 2,n\n vn(k) = 0\n enddo ! k\n scal = 0\nc\n return\nc\n endif\nc\nc\n rss = x1**2 + sum\n rss = sqrt(rss)\nc\nc\nc Determine the first component v1\nc of the unnormalized Householder vector\nc v = x - rss * (1 0 0 ... 0 0)^T.\nc\nc If x1 <= 0, then form x1-rss directly,\nc since that expression cannot involve any cancellation.\nc\n if(x1 .le. 0) v1 = x1-rss\nc\nc If x1 > 0, then use the fact that\nc x1-rss = -sum / (x1+rss),\nc in order to avoid potential cancellation.\nc\n if(x1 .gt. 0) v1 = -sum / (x1+rss)\nc\nc\nc Compute the vector vn and the scalar scal such that vn(1) = 1\nc in the Householder transformation\nc identity_matrix - scal * vn * transpose(vn).\nc\n do k = 2,n\n vn(k) = x(k)/v1\n enddo ! k\nc\nc scal = 2\nc / ( vn(1)^2 + vn(2)^2 + ... + vn(n)^2 )\nc\nc = 2\nc / ( 1 + vn(2)^2 + ... + vn(n)^2 )\nc\nc = 2*v(1)^2\nc / ( v(1)^2 + (v(1)*vn(2))^2 + ... + (v(1)*vn(n))^2 )\nc\nc = 2*v(1)^2\nc / ( v(1)^2 + (v(2)^2 + ... + v(n)^2) )\nc\n scal = 2*v1**2 / (v1**2+sum)\nc\nc\n return\n end\nc\nc\nc\nc\n", "meta": {"hexsha": "ea1ae7fa6a081095cb13258ba8c8ed1c72c807f4", "size": 3123, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/python/scipy/scipy/linalg/src/id_dist/src/idd_house_subr_1.f", "max_stars_repo_name": "ZhekehZ/catboost", "max_stars_repo_head_hexsha": "3f774da539b8e57cca25686b89c473cbd1f61a6c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6989, "max_stars_repo_stars_event_min_datetime": "2017-07-18T06:23:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:58:36.000Z", "max_issues_repo_path": "contrib/python/scipy/scipy/linalg/src/id_dist/src/idd_house_subr_1.f", "max_issues_repo_name": "birichie/catboost", "max_issues_repo_head_hexsha": "de75c6af12cf490700e76c22072fbdc15b35d679", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1978, "max_issues_repo_issues_event_min_datetime": "2017-07-18T09:17:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T14:28:43.000Z", "max_forks_repo_path": "contrib/python/scipy/scipy/linalg/src/id_dist/src/idd_house_subr_1.f", "max_forks_repo_name": "birichie/catboost", "max_forks_repo_head_hexsha": "de75c6af12cf490700e76c22072fbdc15b35d679", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1228, "max_forks_repo_forks_event_min_datetime": "2017-07-18T09:03:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T05:57:40.000Z", "avg_line_length": 24.5905511811, "max_line_length": 71, "alphanum_fraction": 0.4947166186, "num_tokens": 1035, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302033, "lm_q2_score": 0.8479677545357569, "lm_q1q2_score": 0.7671144807092132}} {"text": "program main\n use utils\n use gauss\n implicit none\n real(kind = iKIND), allocatable, dimension(:,:) :: A\n real(kind = iKIND), allocatable, dimension(:) :: X, RES\n real(kind = 16), allocatable, dimension(:) :: IDEAL, ERROR\n real(kind = iKIND) :: h\n integer(kind=8) :: i, n, parse_result\n character(len=10) :: arg\n\n if (command_argument_count() .NE. 1) then\n print *, \"Elements count should be given as program argument, exiting\"\n error stop\n else \n call get_command_argument(1, arg)\n end if\n\n\n read(arg, *, iostat=parse_result) n\n if (parse_result .NE. 0) then\n print *, \"Invalid size argument format!\"\n error stop\n end if\n \n\n allocate(A(0:n, 0:n))\n allocate(X(0:n))\n allocate(RES(0:n))\n allocate(IDEAL(0:n))\n allocate(ERROR(0:n))\n h = real(1.0/n, kind=iKIND)\n\n IDEAL(0) = 0\n do i = 1, n\n IDEAL(i) = real(1, kind=16) / real(n, kind=16) * i\n end do\n\n call init_matrices(A, X, n, h)\n call eliminate(A, X, n)\n\n do i = 1, n-1\n ! for the sake of completeness, although A(i,i) == 1\n X(i) = X(i) / A(i,i)\n end do\n\n do i = 0, n\n print *, i, X(i)\n end do\n\n ERROR(:) = X - IDEAL\n print *, iKIND, N, (SUM(ABS(ERROR)) / size(ERROR))\n\n contains\n\n subroutine init_matrices(A, X, n, h)\n use utils\n integer(kind=8), intent(in) :: n\n integer(kind=8) :: i\n real(kind = iKIND), intent(inout) :: A(0:n, 0:n)\n real(kind = iKIND), intent(inout) :: X(0:n)\n real(kind = iKIND), intent(in) :: h\n real(kind = iKIND) :: diag, side\n ! values to be set on the diagonal and one colument left/right\n side = 1/(h**2)\n diag = -2 * side\n\n X(:) = real(0, kind=iKIND)\n X(n) = real(1, kind=iKIND)\n A(:,:) = real(0, kind=iKIND)\n\n do i = 1,n-1\n A(i - 1, i) = side\n A(i + 1, i) = side\n A(i, i) = diag\n end do\n\n A(0, 0) = 1\n A(n, n) = 1\n end subroutine init_matrices\n\nend program main\n", "meta": {"hexsha": "79abed787a2f2b4fccc0fa4e4b67013c3c6a25de", "size": 1915, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/main.f90", "max_stars_repo_name": "wgslr/agh-fortran", "max_stars_repo_head_hexsha": "7c47400a54ebf5802b64eee8c1c719603807f371", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/main.f90", "max_issues_repo_name": "wgslr/agh-fortran", "max_issues_repo_head_hexsha": "7c47400a54ebf5802b64eee8c1c719603807f371", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/main.f90", "max_forks_repo_name": "wgslr/agh-fortran", "max_forks_repo_head_hexsha": "7c47400a54ebf5802b64eee8c1c719603807f371", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.0722891566, "max_line_length": 74, "alphanum_fraction": 0.5639686684, "num_tokens": 683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.7670544545669974}} {"text": "program main\n\n!*****************************************************************************80\n!\n!! MAIN runs an example of Dijkstra's minimum distance algorithm.\n!\n! Discussion:\n!\n! Given the distance matrix that defines a graph, we seek a list\n! of the minimum distances between node 0 and all other nodes.\n!\n! This program sets up a small example problem and solves it.\n!\n! The correct minimum distances are:\n!\n! 0 35 15 45 49 41\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 02 July 2010\n!\n! Author:\n!\n! Original C version by Norm Matloff, CS Dept, UC Davis.\n! FORTRAN90 version by John Burkardt.\n!\n use omp_lib\n\n implicit none\n\n integer ( kind = 4 ), parameter :: nv = 6\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) :: i4_huge = 2147483647\n integer ( kind = 4 ) j\n integer ( kind = 4 ) mind(nv)\n integer ( kind = 4 ) ohd(nv,nv)\n\n call timestamp ( )\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DIJKSTRA_OPENMP:'\n write ( *, '(a)' ) ' FORTRAN90 version'\n write ( *, '(a)' ) ' Use Dijkstra''s algorithm to determine the minimum'\n write ( *, '(a)' ) ' distance from node 1 to each node in a graph,'\n write ( *, '(a)' ) ' given the distances between each pair of nodes.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Although a very small example is considered, we'\n write ( *, '(a)' ) ' demonstrate the use of OpenMP directives for'\n write ( *, '(a)' ) ' parallel execution.'\n!\n! Initialize the problem data.\n!\n call init ( nv, ohd )\n!\n! Print the distance matrix.\n!\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Distance matrix:'\n write ( *, '(a)' ) ' '\n do i = 1, nv\n do j = 1, nv\n if ( ohd(i,j) == i4_huge ) then\n write ( *, '(2x,a)', advance = 'NO' ) 'Inf'\n else\n write ( *, '(2x,i3)', advance = 'NO' ) ohd(i,j)\n end if\n end do\n write ( *, '(a)', advance = 'yes' )\n end do\n!\n! Carry out the algorithm.\n!\n call dijkstra_distance ( nv, ohd, mind )\n!\n! Print the results.\n!\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Minimum distances from node 1:'\n write ( *, '(a)' ) ' '\n do i = 1, nv\n write ( *, '(2x,i2,2x,i2)' ) i, mind(i)\n end do\n!\n! Terminate.\n!\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DIJKSTRA_OPENMP:'\n write ( *, '(a)' ) ' Normal end of execution.'\n\n write ( *, '(a)' ) ' '\n call timestamp ( )\n\n stop\nend\nsubroutine dijkstra_distance ( nv, ohd, mind )\n\n!*****************************************************************************80\n!\n!! DIJKSTRA_DISTANCE uses Dijkstra's minimum distance algorithm.\n!\n! Discussion:\n!\n! We essentially build a tree. We start with only node 0 connected\n! to the tree, and this is indicated by setting CONNECTED(0) = TRUE.\n!\n! We initialize MIND(I) to the one step distance from node 0 to node I.\n! \n! Now we search among the unconnected nodes for the node MV whose minimum\n! distance is smallest, and connect it to the tree. For each remaining\n! unconnected node I, we check to see whether the distance from 0 to MV\n! to I is less than that recorded in MIND(I), and if so, we can reduce\n! the distance.\n!\n! After NV-1 steps, we have connected all the nodes to 0, and computed\n! the correct minimum distances.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 02 July 2010\n!\n! Author:\n!\n! Original C version by Norm Matloff, CS Dept, UC Davis.\n! This FORTRAN90 version by John Burkardt.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NV, the number of nodes.\n!\n! Input, integer ( kind = 4 ) OHD(NV,NV), the distance of the direct\n! link between nodes I and J.\n!\n! Output, integer ( kind = 4 ) MIND(NV), the minimum \n! distance from node 1 to each node.\n!\n use omp_lib\n\n implicit none\n\n integer ( kind = 4 ) nv\n\n logical connected(nv)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) :: i4_huge = 2147483647\n integer ( kind = 4 ) md\n integer ( kind = 4 ) mind(nv)\n integer ( kind = 4 ) mv\n integer ( kind = 4 ) my_first\n integer ( kind = 4 ) my_id\n integer ( kind = 4 ) my_last\n integer ( kind = 4 ) my_md\n integer ( kind = 4 ) my_mv\n integer ( kind = 4 ) my_step\n integer ( kind = 4 ) nth\n integer ( kind = 4 ) ohd(nv,nv)\n!\n! Start out with only node 1 connected to the tree.\n!\n connected(1) = .true.\n connected(2:nv) = .false.\n!\n! Initialize the minimum distance to the one-step distance.\n!\n mind(1:nv) = ohd(1,1:nv)\n!\n! Begin the parallel region.\n!\n!$omp parallel private ( my_first, my_id, my_last, my_md, my_mv, my_step ) &\n!$omp shared ( connected, md, mind, mv, nth, ohd )\n\n my_id = omp_get_thread_num ( )\n nth = omp_get_num_threads ( ) \n my_first = ( my_id * nv ) / nth + 1\n my_last = ( ( my_id + 1 ) * nv ) / nth\n!\n! The SINGLE directive means that the block is to be executed by only\n! one thread, and that thread will be whichever one gets here first.\n!\n!$omp single\n write ( *, '(a)' ) ' '\n write ( *, * ) ' P', my_id, &\n ': Parallel region begins with ', nth, ' threads.'\n write ( *, '(a)' ) ' '\n!$omp end single\n write ( *, * ) ' P', my_id, ': First=', my_first, ' Last=', my_last\n!\n! Attach one more node on each iteration.\n!\n do my_step = 2, nv\n!\n! Before we compare the results of each thread, set the shared variable \n! MD to a big value. Only one thread needs to do this.\n!\n!$omp single \n md = i4_huge\n mv = -1\n!$omp end single\n!\n! Each thread finds the nearest unconnected node in its part of the graph.\n! Some threads might have no unconnected nodes left.\n!\n call find_nearest ( my_first, my_last, nv, mind, connected, my_md, my_mv )\n!\n! In order to determine the minimum of all the MY_MD's, we must insist\n! that only one thread at a time execute this block!\n!\n!$omp critical\n if ( my_md < md ) then\n md = my_md\n mv = my_mv\n end if\n!$omp end critical\n!\n! This barrier means that ALL threads have executed the critical\n! block, and therefore MD and MV have the correct value. Only then\n! can we proceed.\n!\n!$omp barrier\n!\n! If MV is -1, then NO thread found an unconnected node, so we're done early. \n! OpenMP does not like to BREAK out of a parallel region, so we'll just have \n! to let the iteration run to the end, while we avoid doing any more updates.\n!\n! Otherwise, we connect the nearest node.\n!\n!$omp single\n if ( mv /= - 1 ) then\n connected(mv) = .true.\n write ( *, * ) ' P', my_id, ': Connecting node ', mv\n else\n write ( *, * ) ' P', my_id, ': No connecting node on step ', my_step\n end if\n!$omp end single\n!\n! Again, we don't want any thread to proceed until the value of\n! CONNECTED is updated.\n!\n!$omp barrier\n!\n! Now each thread should update its portion of the MIND vector,\n! by checking to see whether the trip from 0 to MV plus the step\n! from MV to a node is closer than the current record.\n!\n if ( mv /= -1 ) then\n call update_mind ( my_first, my_last, nv, connected, ohd, mv, mind )\n end if\n!\n! Before starting the next step of the iteration, we need all threads \n! to complete the updating, so we set a BARRIER here.\n!\n!$omp barrier\n\n end do\n!\n! Once all the nodes have been connected, we can exit.\n!\n!$omp single\n write ( *, * ) ' '\n write ( *, * ) ' P', my_id, ': Exiting parallel region.'\n!$omp end single\n\n!$omp end parallel\n\n return\nend\nsubroutine find_nearest ( s, e, nv, mind, connected, d, v )\n\n!*****************************************************************************80\n!\n!! FIND_NEAREST finds the nearest unconnected node.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 02 July 2010\n!\n! Author:\n!\n! Original C version by Norm Matloff, CS Dept, UC Davis.\n! This FORTRAN90 version by John Burkardt.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) S, E, the first and last nodes that \n! are to be checked.\n!\n! Input, integer ( kind = 4 ) NV, the number of nodes.\n!\n! Input, integer ( kind = 4 ) MIND(NV), the currently computed minimum \n! distance from node 1 to each node.\n!\n! Input, logical CONNECTED(NV), is true for each connected node, whose \n! minimum distance to node 1 has been determined.\n!\n! Output, integer ( kind = 4 ) D, the distance from node 1 to the nearest \n! unconnected node in the range S to E.\n!\n! Output, integer ( kind = 4 ) V, the index of the nearest unconnected node\n! in the range S to E.\n!\n implicit none\n\n integer ( kind = 4 ) nv\n\n logical connected(nv)\n integer ( kind = 4 ) d\n integer ( kind = 4 ) e\n integer ( kind = 4 ) i\n integer ( kind = 4 ) :: i4_huge = 2147483647\n integer ( kind = 4 ) mind(nv)\n integer ( kind = 4 ) s\n integer ( kind = 4 ) v\n\n d = i4_huge\n v = -1\n\n do i = s, e\n if ( .not. connected(i) .and. mind(i) < d ) then\n d = mind(i)\n v = i\n end if\n end do\n\n return\nend\nsubroutine init ( nv, ohd )\n\n!*****************************************************************************80\n!\n!! INIT initializes the problem data.\n!\n! Discussion:\n!\n! The graph uses 6 nodes, and has the following diagram and\n! distance matrix:\n!\n! N0--15--N2-100--N3 0 40 15 Inf Inf Inf\n! \\ | / 40 0 20 10 25 6\n! \\ | / 15 20 0 100 Inf Inf\n! 40 20 10 Inf 10 100 0 Inf Inf\n! \\ | / Inf 25 Inf Inf 0 8\n! \\ | / Inf 6 Inf Inf 8 0\n! N1\n! / \\\n! / \\\n! 6 25\n! / \\\n! / \\\n! N5----8-----N4\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 02 July 2010\n!\n! Author:\n!\n! Original C version by Norm Matloff, CS Dept, UC Davis.\n! This FORTRAN90 version by John Burkardt.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NV, the number of nodes.\n!\n! Output, integer ( kind = 4 ) OHD(NV,NV), the distance of the direct\n! link between nodes I and J.\n!\n implicit none\n\n integer ( kind = 4 ) nv\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) :: i4_huge = 2147483647\n integer ( kind = 4 ) ohd(nv,nv)\n\n ohd(1:nv,1:nv) = i4_huge\n\n do i = 1, nv\n ohd(i,i) = 0\n end do\n\n ohd(1,2) = 40\n ohd(1,3) = 15\n ohd(2,3) = 20\n ohd(2,4) = 10\n ohd(2,5) = 25\n ohd(3,4) = 100\n ohd(2,6) = 6\n ohd(5,6) = 8\n\n ohd(2,1) = 40\n ohd(3,1) = 15\n ohd(3,2) = 20\n ohd(4,2) = 10\n ohd(5,2) = 25\n ohd(4,3) = 100\n ohd(6,2) = 6\n ohd(6,5) = 8\n\n return\nend\nsubroutine timestamp ( )\n\n!*****************************************************************************80\n!\n!! TIMESTAMP prints the current YMDHMS date as a time stamp.\n!\n! Example:\n!\n! 31 May 2001 9:45:54.872 AM\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 May 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! None\n!\n implicit none\n\n character ( len = 8 ) ampm\n integer ( kind = 4 ) d\n integer ( kind = 4 ) h\n integer ( kind = 4 ) m\n integer ( kind = 4 ) mm\n character ( len = 9 ), parameter, dimension(12) :: month = (/ &\n 'January ', 'February ', 'March ', 'April ', &\n 'May ', 'June ', 'July ', 'August ', &\n 'September', 'October ', 'November ', 'December ' /)\n integer ( kind = 4 ) n\n integer ( kind = 4 ) s\n integer ( kind = 4 ) values(8)\n integer ( kind = 4 ) y\n\n call date_and_time ( values = values )\n\n y = values(1)\n m = values(2)\n d = values(3)\n h = values(5)\n n = values(6)\n s = values(7)\n mm = values(8)\n\n if ( h < 12 ) then\n ampm = 'AM'\n else if ( h == 12 ) then\n if ( n == 0 .and. s == 0 ) then\n ampm = 'Noon'\n else\n ampm = 'PM'\n end if\n else\n h = h - 12\n if ( h < 12 ) then\n ampm = 'PM'\n else if ( h == 12 ) then\n if ( n == 0 .and. s == 0 ) then\n ampm = 'Midnight'\n else\n ampm = 'AM'\n end if\n end if\n end if\n\n write ( *, '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) &\n d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm )\n\n return\nend\nsubroutine update_mind ( s, e, nv, connected, ohd, mv, mind )\n\n!*****************************************************************************80\n!\n!! UPDATE_MIND updates the minimum distance vector.\n!\n! Discussion:\n!\n! We've just determined the minimum distance to node MV.\n!\n! For each node I which is not connected yet,\n! check whether the route from node 0 to MV to I is shorter\n! than the currently known minimum distance.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 01 July 2010\n!\n! Author:\n!\n! Original C version by Norm Matloff, CS Dept, UC Davis.\n! This FORTRAN90 version by John Burkardt.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) S, E, the first and last nodes that are \n! to be checked.\n!\n! Input, integer ( kind = 4 ) NV, the number of nodes.\n!\n! Input, logical CONNECTED(NV), is true for each connected node, whose \n! minimum distance to node 0 has been determined.\n!\n! Input, integer ( kind = 4 ) OHD(NV,NV), the distance of the direct link \n! between nodes I and J.\n!\n! Input, integer ( kind = 4 ) MV, the node whose minimum distance to node 20\n! has just been determined.\n!\n! Input/output, integer ( kind = 4 ) MIND(NV), the currently computed\n! minimum distances from node 1 to each node. On output, the values for \n! nodes S through E have been updated.\n!\n implicit none\n\n integer ( kind = 4 ) nv\n\n logical connected(nv)\n integer ( kind = 4 ) e\n integer ( kind = 4 ) i\n integer ( kind = 4 ) :: i4_huge = 2147483647\n integer ( kind = 4 ) mind(nv)\n integer ( kind = 4 ) mv\n integer ( kind = 4 ) ohd(nv,nv)\n integer ( kind = 4 ) s\n\n do i = s, e\n if ( .not. connected(i) ) then\n if ( ohd(mv,i) < i4_huge ) then\n if ( mind(mv) + ohd(mv,i) < mind(i) ) then\n mind(i) = mind(mv) + ohd(mv,i)\n end if\n end if\n end if\n end do\n\n return\nend\n", "meta": {"hexsha": "9d35c09a26769fe01469a6e9594087e2f32646a6", "size": 14071, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "share/ukernels/dijkstra.f90", "max_stars_repo_name": "vivek224/vSched", "max_stars_repo_head_hexsha": "5ecf2cdf553277571490665b42e00a0b61b2a8c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-06-11T17:16:02.000Z", "max_stars_repo_stars_event_max_datetime": "2018-10-01T18:37:28.000Z", "max_issues_repo_path": "share/ukernels/dijkstra.f90", "max_issues_repo_name": "vivek224/vSched", "max_issues_repo_head_hexsha": "5ecf2cdf553277571490665b42e00a0b61b2a8c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-08-09T00:12:11.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-09T00:12:51.000Z", "max_forks_repo_path": "share/ukernels/dijkstra.f90", "max_forks_repo_name": "vlkale/lw-sched", "max_forks_repo_head_hexsha": "5ecf2cdf553277571490665b42e00a0b61b2a8c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.8604240283, "max_line_length": 80, "alphanum_fraction": 0.5664131902, "num_tokens": 4530, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7670544466677673}} {"text": " subroutine get_growth_rate(doubling_time, growth_rate)\n real doubling_time, growth_rate\n\n if (doubling_time .eq. 0.0) then\n growth_rate = 0.0\n else\n growth_rate = 2.0 ** (1.0 / doubling_time) - 1.0\n endif\n end subroutine get_growth_rate\n\n subroutine get_beta(gamma, doubling_time, s_c, relative_contact_rate, beta)\n real growth_rate, s_c, relative_contact_rate, doubling_time\n real inv_contact_rate, updated_growth_rate, gamma, beta\n\n call get_growth_rate(doubling_time, growth_rate)\n\n inv_contact_rate = 1.0 - relative_contact_rate\n updated_growth_rate = growth_rate + gamma\n beta = updated_growth_rate / s_c * inv_contact_rate\n end subroutine get_beta\n\n\n subroutine sir(s_c, i_c, r_c, doubling_time,\n & relative_contact_rate, gamma, n)\n real relative_contact_rate, doubling_time\n real s_c, i_c, r_c, n, s_n, i_n, r_n, beta, gamma, scale\n\n call get_beta(gamma, doubling_time, s_c, relative_contact_rate, beta)\n\n s_n = (-beta * s_c * i_c) + s_c\n i_n = (beta * s_c * i_c - gamma * i_c) + i_c\n r_n = gamma * i_c + r_c\n\n scale = n / (s_n + i_n + r_n)\n\n s_c = s_n * scale\n i_c = i_n * scale\n r_c = r_n * scale\n end subroutine sir\n", "meta": {"hexsha": "3a50be69c587a5b4f3779c944208eaadf1bdef5e", "size": 1335, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/CHIME-SIR-model.for", "max_stars_repo_name": "rsulli55/automates", "max_stars_repo_head_hexsha": "1647a8eef85c4f03086a10fa72db3b547f1a0455", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2018-12-19T16:32:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-05T07:58:15.000Z", "max_issues_repo_path": "tests/data/program_analysis/CHIME-SIR-model.for", "max_issues_repo_name": "rsulli55/automates", "max_issues_repo_head_hexsha": "1647a8eef85c4f03086a10fa72db3b547f1a0455", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 183, "max_issues_repo_issues_event_min_datetime": "2018-12-20T17:03:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-23T22:21:42.000Z", "max_forks_repo_path": "tests/data/program_analysis/CHIME-SIR-model.for", "max_forks_repo_name": "rsulli55/automates", "max_forks_repo_head_hexsha": "1647a8eef85c4f03086a10fa72db3b547f1a0455", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-01-04T22:37:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T17:34:16.000Z", "avg_line_length": 33.375, "max_line_length": 81, "alphanum_fraction": 0.6269662921, "num_tokens": 368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122744874229, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7669926923358091}} {"text": "C \nC FFTPACK\nC \nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC \nC VERSION 4 APRIL 1985\nC \nC A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE FAST FOURIER\nC TRANSFORM OF PERIODIC AND OTHER SYMMETRIC SEQUENCES\nC \nC BY\nC \nC PAUL N SWARZTRAUBER\nC \nC NATIONAL CENTER FOR ATMOSPHERIC RESEARCH BOULDER,COLORADO 80307\nC \nC WHICH IS SPONSORED BY THE NATIONAL SCIENCE FOUNDATION\nC \nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC \nC \nC THIS PACKAGE CONSISTS OF PROGRAMS WHICH PERFORM FAST FOURIER\nC TRANSFORMS FOR BOTH COMPLEX AND REAL PERIODIC SEQUENCES AND\nC CERTAIN OTHER SYMMETRIC SEQUENCES THAT ARE LISTED BELOW.\nC \nC 1. DFFTI INITIALIZE DFFTF AND DFFTB\nC 2. DFFTF FORWARD TRANSFORM OF A REAL PERIODIC SEQUENCE\nC 3. DFFTB BACKWARD TRANSFORM OF A REAL COEFFICIENT ARRAY\nC \nC 4. DZFFTI INITIALIZE DZFFTF AND DZFFTB\nC 5. DZFFTF A SIMPLIFIED REAL PERIODIC FORWARD TRANSFORM\nC 6. DZFFTB A SIMPLIFIED REAL PERIODIC BACKWARD TRANSFORM\nC \nC 7. DSINTI INITIALIZE DSINT\nC 8. DSINT SINE TRANSFORM OF A REAL ODD SEQUENCE\nC \nC 9. DCOSTI INITIALIZE DCOST\nC 10. DCOST COSINE TRANSFORM OF A REAL EVEN SEQUENCE\nC \nC 11. DSINQI INITIALIZE DSINQF AND DSINQB\nC 12. DSINQF FORWARD SINE TRANSFORM WITH ODD WAVE NUMBERS\nC 13. DSINQB UNNORMALIZED INVERSE OF DSINQF\nC \nC 14. DCOSQI INITIALIZE DCOSQF AND DCOSQB\nC 15. DCOSQF FORWARD COSINE TRANSFORM WITH ODD WAVE NUMBERS\nC 16. DCOSQB UNNORMALIZED INVERSE OF DCOSQF\nC \nC 17. ZFFTI INITIALIZE ZFFTF AND ZFFTB\nC 18. ZFFTF FORWARD TRANSFORM OF A COMPLEX PERIODIC SEQUENCE\nC 19. ZFFTB UNNORMALIZED INVERSE OF ZFFTF\nC \nC \nC ******************************************************************\nC \nC SUBROUTINE DFFTI(N,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE DFFTI INITIALIZES THE ARRAY WSAVE WHICH IS USED IN\nC BOTH DFFTF AND DFFTB. THE PRIME FACTORIZATION OF N TOGETHER WITH\nC A TABULATION OF THE TRIGONOMETRIC FUNCTIONS ARE COMPUTED AND\nC STORED IN WSAVE.\nC \nC INPUT PARAMETER\nC \nC N THE LENGTH OF THE SEQUENCE TO BE TRANSFORMED.\nC \nC OUTPUT PARAMETER\nC \nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 2*N+15.\nC THE SAME WORK ARRAY CAN BE USED FOR BOTH DFFTF AND DFFTB\nC AS LONG AS N REMAINS UNCHANGED. DIFFERENT WSAVE ARRAYS\nC ARE REQUIRED FOR DIFFERENT VALUES OF N. THE CONTENTS OF\nC WSAVE MUST NOT BE CHANGED BETWEEN CALLS OF DFFTF OR DFFTB.\nC \nC ******************************************************************\nC \nC SUBROUTINE DFFTF(N,R,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE DFFTF COMPUTES THE FOURIER COEFFICIENTS OF A REAL\nC PERODIC SEQUENCE (FOURIER ANALYSIS). THE TRANSFORM IS DEFINED\nC BELOW AT OUTPUT PARAMETER R.\nC \nC INPUT PARAMETERS\nC \nC N THE LENGTH OF THE ARRAY R TO BE TRANSFORMED. THE METHOD\nC IS MOST EFFICIENT WHEN N IS A PRODUCT OF SMALL PRIMES.\nC N MAY CHANGE SO LONG AS DIFFERENT WORK ARRAYS ARE PROVIDED\nC \nC R A REAL ARRAY OF LENGTH N WHICH CONTAINS THE SEQUENCE\nC TO BE TRANSFORMED\nC \nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 2*N+15.\nC IN THE PROGRAM THAT CALLS DFFTF. THE WSAVE ARRAY MUST BE\nC INITIALIZED BY CALLING SUBROUTINE DFFTI(N,WSAVE) AND A\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\nC THE SAME WSAVE ARRAY CAN BE USED BY DFFTF AND DFFTB.\nC \nC \nC OUTPUT PARAMETERS\nC \nC R R(1) = THE SUM FROM I=1 TO I=N OF R(I)\nC \nC IF N IS EVEN SET L =N/2 , IF N IS ODD SET L = (N+1)/2\nC \nC THEN FOR K = 2,...,L\nC \nC R(2*K-2) = THE SUM FROM I = 1 TO I = N OF\nC \nC R(I)*COS((K-1)*(I-1)*2*PI/N)\nC \nC R(2*K-1) = THE SUM FROM I = 1 TO I = N OF\nC \nC -R(I)*SIN((K-1)*(I-1)*2*PI/N)\nC \nC IF N IS EVEN\nC \nC R(N) = THE SUM FROM I = 1 TO I = N OF\nC \nC (-1)**(I-1)*R(I)\nC \nC ***** NOTE\nC THIS TRANSFORM IS UNNORMALIZED SINCE A CALL OF DFFTF\nC FOLLOWED BY A CALL OF DFFTB WILL MULTIPLY THE INPUT\nC SEQUENCE BY N.\nC \nC WSAVE CONTAINS RESULTS WHICH MUST NOT BE DESTROYED BETWEEN\nC CALLS OF DFFTF OR DFFTB.\nC \nC \nC ******************************************************************\nC \nC SUBROUTINE DFFTB(N,R,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE DFFTB COMPUTES THE REAL PERODIC SEQUENCE FROM ITS\nC FOURIER COEFFICIENTS (FOURIER SYNTHESIS). THE TRANSFORM IS DEFINED\nC BELOW AT OUTPUT PARAMETER R.\nC \nC INPUT PARAMETERS\nC \nC N THE LENGTH OF THE ARRAY R TO BE TRANSFORMED. THE METHOD\nC IS MOST EFFICIENT WHEN N IS A PRODUCT OF SMALL PRIMES.\nC N MAY CHANGE SO LONG AS DIFFERENT WORK ARRAYS ARE PROVIDED\nC \nC R A REAL ARRAY OF LENGTH N WHICH CONTAINS THE SEQUENCE\nC TO BE TRANSFORMED\nC \nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 2*N+15.\nC IN THE PROGRAM THAT CALLS DFFTB. THE WSAVE ARRAY MUST BE\nC INITIALIZED BY CALLING SUBROUTINE DFFTI(N,WSAVE) AND A\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\nC THE SAME WSAVE ARRAY CAN BE USED BY DFFTF AND DFFTB.\nC \nC \nC OUTPUT PARAMETERS\nC \nC R FOR N EVEN AND FOR I = 1,...,N\nC \nC R(I) = R(1)+(-1)**(I-1)*R(N)\nC \nC PLUS THE SUM FROM K=2 TO K=N/2 OF\nC \nC 2.*R(2*K-2)*COS((K-1)*(I-1)*2*PI/N)\nC \nC -2.*R(2*K-1)*SIN((K-1)*(I-1)*2*PI/N)\nC \nC FOR N ODD AND FOR I = 1,...,N\nC \nC R(I) = R(1) PLUS THE SUM FROM K=2 TO K=(N+1)/2 OF\nC \nC 2.*R(2*K-2)*COS((K-1)*(I-1)*2*PI/N)\nC \nC -2.*R(2*K-1)*SIN((K-1)*(I-1)*2*PI/N)\nC \nC ***** NOTE\nC THIS TRANSFORM IS UNNORMALIZED SINCE A CALL OF DFFTF\nC FOLLOWED BY A CALL OF DFFTB WILL MULTIPLY THE INPUT\nC SEQUENCE BY N.\nC \nC WSAVE CONTAINS RESULTS WHICH MUST NOT BE DESTROYED BETWEEN\nC CALLS OF DFFTB OR DFFTF.\nC \nC \nC ******************************************************************\nC \nC SUBROUTINE DZFFTI(N,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE DZFFTI INITIALIZES THE ARRAY WSAVE WHICH IS USED IN\nC BOTH DZFFTF AND DZFFTB. THE PRIME FACTORIZATION OF N TOGETHER WITH\nC A TABULATION OF THE TRIGONOMETRIC FUNCTIONS ARE COMPUTED AND\nC STORED IN WSAVE.\nC \nC INPUT PARAMETER\nC \nC N THE LENGTH OF THE SEQUENCE TO BE TRANSFORMED.\nC \nC OUTPUT PARAMETER\nC \nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 3*N+15.\nC THE SAME WORK ARRAY CAN BE USED FOR BOTH DZFFTF AND DZFFTB\nC AS LONG AS N REMAINS UNCHANGED. DIFFERENT WSAVE ARRAYS\nC ARE REQUIRED FOR DIFFERENT VALUES OF N.\nC \nC \nC ******************************************************************\nC \nC SUBROUTINE DZFFTF(N,R,AZERO,A,B,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE DZFFTF COMPUTES THE FOURIER COEFFICIENTS OF A REAL\nC PERODIC SEQUENCE (FOURIER ANALYSIS). THE TRANSFORM IS DEFINED\nC BELOW AT OUTPUT PARAMETERS AZERO,A AND B. DZFFTF IS A SIMPLIFIED\nC BUT SLOWER VERSION OF DFFTF.\nC \nC INPUT PARAMETERS\nC \nC N THE LENGTH OF THE ARRAY R TO BE TRANSFORMED. THE METHOD\nC IS MUST EFFICIENT WHEN N IS THE PRODUCT OF SMALL PRIMES.\nC \nC R A REAL ARRAY OF LENGTH N WHICH CONTAINS THE SEQUENCE\nC TO BE TRANSFORMED. R IS NOT DESTROYED.\nC \nC \nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 3*N+15.\nC IN THE PROGRAM THAT CALLS DZFFTF. THE WSAVE ARRAY MUST BE\nC INITIALIZED BY CALLING SUBROUTINE DZFFTI(N,WSAVE) AND A\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\nC THE SAME WSAVE ARRAY CAN BE USED BY DZFFTF AND DZFFTB.\nC \nC OUTPUT PARAMETERS\nC \nC AZERO THE SUM FROM I=1 TO I=N OF R(I)/N\nC \nC A,B FOR N EVEN B(N/2)=0. AND A(N/2) IS THE SUM FROM I=1 TO\nC I=N OF (-1)**(I-1)*R(I)/N\nC \nC FOR N EVEN DEFINE KMAX=N/2-1\nC FOR N ODD DEFINE KMAX=(N-1)/2\nC \nC THEN FOR K=1,...,KMAX\nC \nC A(K) EQUALS THE SUM FROM I=1 TO I=N OF\nC \nC 2./N*R(I)*COS(K*(I-1)*2*PI/N)\nC \nC B(K) EQUALS THE SUM FROM I=1 TO I=N OF\nC \nC 2./N*R(I)*SIN(K*(I-1)*2*PI/N)\nC \nC \nC ******************************************************************\nC \nC SUBROUTINE DZFFTB(N,R,AZERO,A,B,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE DZFFTB COMPUTES A REAL PERODIC SEQUENCE FROM ITS\nC FOURIER COEFFICIENTS (FOURIER SYNTHESIS). THE TRANSFORM IS\nC DEFINED BELOW AT OUTPUT PARAMETER R. DZFFTB IS A SIMPLIFIED\nC BUT SLOWER VERSION OF DFFTB.\nC \nC INPUT PARAMETERS\nC \nC N THE LENGTH OF THE OUTPUT ARRAY R. THE METHOD IS MOST\nC EFFICIENT WHEN N IS THE PRODUCT OF SMALL PRIMES.\nC \nC AZERO THE CONSTANT FOURIER COEFFICIENT\nC \nC A,B ARRAYS WHICH CONTAIN THE REMAINING FOURIER COEFFICIENTS\nC THESE ARRAYS ARE NOT DESTROYED.\nC \nC THE LENGTH OF THESE ARRAYS DEPENDS ON WHETHER N IS EVEN OR\nC ODD.\nC \nC IF N IS EVEN N/2 LOCATIONS ARE REQUIRED\nC IF N IS ODD (N-1)/2 LOCATIONS ARE REQUIRED\nC \nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 3*N+15.\nC IN THE PROGRAM THAT CALLS DZFFTB. THE WSAVE ARRAY MUST BE\nC INITIALIZED BY CALLING SUBROUTINE DZFFTI(N,WSAVE) AND A\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\nC THE SAME WSAVE ARRAY CAN BE USED BY DZFFTF AND DZFFTB.\nC \nC \nC OUTPUT PARAMETERS\nC \nC R IF N IS EVEN DEFINE KMAX=N/2\nC IF N IS ODD DEFINE KMAX=(N-1)/2\nC \nC THEN FOR I=1,...,N\nC \nC R(I)=AZERO PLUS THE SUM FROM K=1 TO K=KMAX OF\nC \nC A(K)*COS(K*(I-1)*2*PI/N)+B(K)*SIN(K*(I-1)*2*PI/N)\nC \nC ********************* COMPLEX NOTATION **************************\nC \nC FOR J=1,...,N\nC \nC R(J) EQUALS THE SUM FROM K=-KMAX TO K=KMAX OF\nC \nC C(K)*EXP(I*K*(J-1)*2*PI/N)\nC \nC WHERE\nC \nC C(K) = .5*CMPLX(A(K),-B(K)) FOR K=1,...,KMAX\nC \nC C(-K) = CONJG(C(K))\nC \nC C(0) = AZERO\nC \nC AND I=SQRT(-1)\nC \nC *************** AMPLITUDE - PHASE NOTATION ***********************\nC \nC FOR I=1,...,N\nC \nC R(I) EQUALS AZERO PLUS THE SUM FROM K=1 TO K=KMAX OF\nC \nC ALPHA(K)*COS(K*(I-1)*2*PI/N+BETA(K))\nC \nC WHERE\nC \nC ALPHA(K) = SQRT(A(K)*A(K)+B(K)*B(K))\nC \nC COS(BETA(K))=A(K)/ALPHA(K)\nC \nC SIN(BETA(K))=-B(K)/ALPHA(K)\nC \nC ******************************************************************\nC \nC SUBROUTINE DSINTI(N,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE DSINTI INITIALIZES THE ARRAY WSAVE WHICH IS USED IN\nC SUBROUTINE DSINT. THE PRIME FACTORIZATION OF N TOGETHER WITH\nC A TABULATION OF THE TRIGONOMETRIC FUNCTIONS ARE COMPUTED AND\nC STORED IN WSAVE.\nC \nC INPUT PARAMETER\nC \nC N THE LENGTH OF THE SEQUENCE TO BE TRANSFORMED. THE METHOD\nC IS MOST EFFICIENT WHEN N+1 IS A PRODUCT OF SMALL PRIMES.\nC \nC OUTPUT PARAMETER\nC \nC WSAVE A WORK ARRAY WITH AT LEAST INT(2.5*N+15) LOCATIONS.\nC DIFFERENT WSAVE ARRAYS ARE REQUIRED FOR DIFFERENT VALUES\nC OF N. THE CONTENTS OF WSAVE MUST NOT BE CHANGED BETWEEN\nC CALLS OF DSINT.\nC \nC ******************************************************************\nC \nC SUBROUTINE DSINT(N,X,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE DSINT COMPUTES THE DISCRETE FOURIER SINE TRANSFORM\nC OF AN ODD SEQUENCE X(I). THE TRANSFORM IS DEFINED BELOW AT\nC OUTPUT PARAMETER X.\nC \nC DSINT IS THE UNNORMALIZED INVERSE OF ITSELF SINCE A CALL OF DSINT\nC FOLLOWED BY ANOTHER CALL OF DSINT WILL MULTIPLY THE INPUT SEQUENCE\nC X BY 2*(N+1).\nC \nC THE ARRAY WSAVE WHICH IS USED BY SUBROUTINE DSINT MUST BE\nC INITIALIZED BY CALLING SUBROUTINE DSINTI(N,WSAVE).\nC \nC INPUT PARAMETERS\nC \nC N THE LENGTH OF THE SEQUENCE TO BE TRANSFORMED. THE METHOD\nC IS MOST EFFICIENT WHEN N+1 IS THE PRODUCT OF SMALL PRIMES.\nC \nC X AN ARRAY WHICH CONTAINS THE SEQUENCE TO BE TRANSFORMED\nC \nC \nC WSAVE A WORK ARRAY WITH DIMENSION AT LEAST INT(2.5*N+15)\nC IN THE PROGRAM THAT CALLS DSINT. THE WSAVE ARRAY MUST BE\nC INITIALIZED BY CALLING SUBROUTINE DSINTI(N,WSAVE) AND A\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\nC \nC OUTPUT PARAMETERS\nC \nC X FOR I=1,...,N\nC \nC X(I)= THE SUM FROM K=1 TO K=N\nC \nC 2*X(K)*SIN(K*I*PI/(N+1))\nC \nC A CALL OF DSINT FOLLOWED BY ANOTHER CALL OF\nC DSINT WILL MULTIPLY THE SEQUENCE X BY 2*(N+1).\nC HENCE DSINT IS THE UNNORMALIZED INVERSE\nC OF ITSELF.\nC \nC WSAVE CONTAINS INITIALIZATION CALCULATIONS WHICH MUST NOT BE\nC DESTROYED BETWEEN CALLS OF DSINT.\nC \nC ******************************************************************\nC \nC SUBROUTINE DCOSTI(N,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE DCOSTI INITIALIZES THE ARRAY WSAVE WHICH IS USED IN\nC SUBROUTINE DCOST. THE PRIME FACTORIZATION OF N TOGETHER WITH\nC A TABULATION OF THE TRIGONOMETRIC FUNCTIONS ARE COMPUTED AND\nC STORED IN WSAVE.\nC \nC INPUT PARAMETER\nC \nC N THE LENGTH OF THE SEQUENCE TO BE TRANSFORMED. THE METHOD\nC IS MOST EFFICIENT WHEN N-1 IS A PRODUCT OF SMALL PRIMES.\nC \nC OUTPUT PARAMETER\nC \nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 3*N+15.\nC DIFFERENT WSAVE ARRAYS ARE REQUIRED FOR DIFFERENT VALUES\nC OF N. THE CONTENTS OF WSAVE MUST NOT BE CHANGED BETWEEN\nC CALLS OF DCOST.\nC \nC ******************************************************************\nC \nC SUBROUTINE DCOST(N,X,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE DCOST COMPUTES THE DISCRETE FOURIER COSINE TRANSFORM\nC OF AN EVEN SEQUENCE X(I). THE TRANSFORM IS DEFINED BELOW AT OUTPUT\nC PARAMETER X.\nC \nC DCOST IS THE UNNORMALIZED INVERSE OF ITSELF SINCE A CALL OF DCOST\nC FOLLOWED BY ANOTHER CALL OF DCOST WILL MULTIPLY THE INPUT SEQUENCE\nC X BY 2*(N-1). THE TRANSFORM IS DEFINED BELOW AT OUTPUT PARAMETER X\nC \nC THE ARRAY WSAVE WHICH IS USED BY SUBROUTINE DCOST MUST BE\nC INITIALIZED BY CALLING SUBROUTINE DCOSTI(N,WSAVE).\nC \nC INPUT PARAMETERS\nC \nC N THE LENGTH OF THE SEQUENCE X. N MUST BE GREATER THAN 1.\nC THE METHOD IS MOST EFFICIENT WHEN N-1 IS A PRODUCT OF\nC SMALL PRIMES.\nC \nC X AN ARRAY WHICH CONTAINS THE SEQUENCE TO BE TRANSFORMED\nC \nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 3*N+15\nC IN THE PROGRAM THAT CALLS DCOST. THE WSAVE ARRAY MUST BE\nC INITIALIZED BY CALLING SUBROUTINE DCOSTI(N,WSAVE) AND A\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\nC \nC OUTPUT PARAMETERS\nC \nC X FOR I=1,...,N\nC \nC X(I) = X(1)+(-1)**(I-1)*X(N)\nC \nC + THE SUM FROM K=2 TO K=N-1\nC \nC 2*X(K)*COS((K-1)*(I-1)*PI/(N-1))\nC \nC A CALL OF DCOST FOLLOWED BY ANOTHER CALL OF\nC DCOST WILL MULTIPLY THE SEQUENCE X BY 2*(N-1)\nC HENCE DCOST IS THE UNNORMALIZED INVERSE\nC OF ITSELF.\nC \nC WSAVE CONTAINS INITIALIZATION CALCULATIONS WHICH MUST NOT BE\nC DESTROYED BETWEEN CALLS OF DCOST.\nC \nC ******************************************************************\nC \nC SUBROUTINE DSINQI(N,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE DSINQI INITIALIZES THE ARRAY WSAVE WHICH IS USED IN\nC BOTH DSINQF AND DSINQB. THE PRIME FACTORIZATION OF N TOGETHER WITH\nC A TABULATION OF THE TRIGONOMETRIC FUNCTIONS ARE COMPUTED AND\nC STORED IN WSAVE.\nC \nC INPUT PARAMETER\nC \nC N THE LENGTH OF THE SEQUENCE TO BE TRANSFORMED. THE METHOD\nC IS MOST EFFICIENT WHEN N IS A PRODUCT OF SMALL PRIMES.\nC \nC OUTPUT PARAMETER\nC \nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 3*N+15.\nC THE SAME WORK ARRAY CAN BE USED FOR BOTH DSINQF AND DSINQB\nC AS LONG AS N REMAINS UNCHANGED. DIFFERENT WSAVE ARRAYS\nC ARE REQUIRED FOR DIFFERENT VALUES OF N. THE CONTENTS OF\nC WSAVE MUST NOT BE CHANGED BETWEEN CALLS OF DSINQF OR DSINQB.\nC \nC ******************************************************************\nC \nC SUBROUTINE DSINQF(N,X,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE DSINQF COMPUTES THE FAST FOURIER TRANSFORM OF QUARTER\nC WAVE DATA. THAT IS , DSINQF COMPUTES THE COEFFICIENTS IN A SINE\nC SERIES REPRESENTATION WITH ONLY ODD WAVE NUMBERS. THE TRANSFORM\nC IS DEFINED BELOW AT OUTPUT PARAMETER X.\nC \nC DSINQB IS THE UNNORMALIZED INVERSE OF DSINQF SINCE A CALL OF DSINQF\nC FOLLOWED BY A CALL OF DSINQB WILL MULTIPLY THE INPUT SEQUENCE X\nC BY 4*N.\nC \nC THE ARRAY WSAVE WHICH IS USED BY SUBROUTINE DSINQF MUST BE\nC INITIALIZED BY CALLING SUBROUTINE DSINQI(N,WSAVE).\nC \nC \nC INPUT PARAMETERS\nC \nC N THE LENGTH OF THE ARRAY X TO BE TRANSFORMED. THE METHOD\nC IS MOST EFFICIENT WHEN N IS A PRODUCT OF SMALL PRIMES.\nC \nC X AN ARRAY WHICH CONTAINS THE SEQUENCE TO BE TRANSFORMED\nC \nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 3*N+15.\nC IN THE PROGRAM THAT CALLS DSINQF. THE WSAVE ARRAY MUST BE\nC INITIALIZED BY CALLING SUBROUTINE DSINQI(N,WSAVE) AND A\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\nC \nC OUTPUT PARAMETERS\nC \nC X FOR I=1,...,N\nC \nC X(I) = (-1)**(I-1)*X(N)\nC \nC + THE SUM FROM K=1 TO K=N-1 OF\nC \nC 2*X(K)*SIN((2*I-1)*K*PI/(2*N))\nC \nC A CALL OF DSINQF FOLLOWED BY A CALL OF\nC DSINQB WILL MULTIPLY THE SEQUENCE X BY 4*N.\nC THEREFORE DSINQB IS THE UNNORMALIZED INVERSE\nC OF DSINQF.\nC \nC WSAVE CONTAINS INITIALIZATION CALCULATIONS WHICH MUST NOT\nC BE DESTROYED BETWEEN CALLS OF DSINQF OR DSINQB.\nC \nC ******************************************************************\nC \nC SUBROUTINE DSINQB(N,X,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE DSINQB COMPUTES THE FAST FOURIER TRANSFORM OF QUARTER\nC WAVE DATA. THAT IS , DSINQB COMPUTES A SEQUENCE FROM ITS\nC REPRESENTATION IN TERMS OF A SINE SERIES WITH ODD WAVE NUMBERS.\nC THE TRANSFORM IS DEFINED BELOW AT OUTPUT PARAMETER X.\nC \nC DSINQF IS THE UNNORMALIZED INVERSE OF DSINQB SINCE A CALL OF DSINQB\nC FOLLOWED BY A CALL OF DSINQF WILL MULTIPLY THE INPUT SEQUENCE X\nC BY 4*N.\nC \nC THE ARRAY WSAVE WHICH IS USED BY SUBROUTINE DSINQB MUST BE\nC INITIALIZED BY CALLING SUBROUTINE DSINQI(N,WSAVE).\nC \nC \nC INPUT PARAMETERS\nC \nC N THE LENGTH OF THE ARRAY X TO BE TRANSFORMED. THE METHOD\nC IS MOST EFFICIENT WHEN N IS A PRODUCT OF SMALL PRIMES.\nC \nC X AN ARRAY WHICH CONTAINS THE SEQUENCE TO BE TRANSFORMED\nC \nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 3*N+15.\nC IN THE PROGRAM THAT CALLS DSINQB. THE WSAVE ARRAY MUST BE\nC INITIALIZED BY CALLING SUBROUTINE DSINQI(N,WSAVE) AND A\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\nC \nC OUTPUT PARAMETERS\nC \nC X FOR I=1,...,N\nC \nC X(I)= THE SUM FROM K=1 TO K=N OF\nC \nC 4*X(K)*SIN((2K-1)*I*PI/(2*N))\nC \nC A CALL OF DSINQB FOLLOWED BY A CALL OF\nC DSINQF WILL MULTIPLY THE SEQUENCE X BY 4*N.\nC THEREFORE DSINQF IS THE UNNORMALIZED INVERSE\nC OF DSINQB.\nC \nC WSAVE CONTAINS INITIALIZATION CALCULATIONS WHICH MUST NOT\nC BE DESTROYED BETWEEN CALLS OF DSINQB OR DSINQF.\nC \nC ******************************************************************\nC \nC SUBROUTINE DCOSQI(N,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE DCOSQI INITIALIZES THE ARRAY WSAVE WHICH IS USED IN\nC BOTH DCOSQF AND DCOSQB. THE PRIME FACTORIZATION OF N TOGETHER WITH\nC A TABULATION OF THE TRIGONOMETRIC FUNCTIONS ARE COMPUTED AND\nC STORED IN WSAVE.\nC \nC INPUT PARAMETER\nC \nC N THE LENGTH OF THE ARRAY TO BE TRANSFORMED. THE METHOD\nC IS MOST EFFICIENT WHEN N IS A PRODUCT OF SMALL PRIMES.\nC \nC OUTPUT PARAMETER\nC \nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 3*N+15.\nC THE SAME WORK ARRAY CAN BE USED FOR BOTH DCOSQF AND DCOSQB\nC AS LONG AS N REMAINS UNCHANGED. DIFFERENT WSAVE ARRAYS\nC ARE REQUIRED FOR DIFFERENT VALUES OF N. THE CONTENTS OF\nC WSAVE MUST NOT BE CHANGED BETWEEN CALLS OF DCOSQF OR DCOSQB.\nC \nC ******************************************************************\nC \nC SUBROUTINE DCOSQF(N,X,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE DCOSQF COMPUTES THE FAST FOURIER TRANSFORM OF QUARTER\nC WAVE DATA. THAT IS , DCOSQF COMPUTES THE COEFFICIENTS IN A COSINE\nC SERIES REPRESENTATION WITH ONLY ODD WAVE NUMBERS. THE TRANSFORM\nC IS DEFINED BELOW AT OUTPUT PARAMETER X\nC \nC DCOSQF IS THE UNNORMALIZED INVERSE OF DCOSQB SINCE A CALL OF DCOSQF\nC FOLLOWED BY A CALL OF DCOSQB WILL MULTIPLY THE INPUT SEQUENCE X\nC BY 4*N.\nC \nC THE ARRAY WSAVE WHICH IS USED BY SUBROUTINE DCOSQF MUST BE\nC INITIALIZED BY CALLING SUBROUTINE DCOSQI(N,WSAVE).\nC \nC \nC INPUT PARAMETERS\nC \nC N THE LENGTH OF THE ARRAY X TO BE TRANSFORMED. THE METHOD\nC IS MOST EFFICIENT WHEN N IS A PRODUCT OF SMALL PRIMES.\nC \nC X AN ARRAY WHICH CONTAINS THE SEQUENCE TO BE TRANSFORMED\nC \nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 3*N+15\nC IN THE PROGRAM THAT CALLS DCOSQF. THE WSAVE ARRAY MUST BE\nC INITIALIZED BY CALLING SUBROUTINE DCOSQI(N,WSAVE) AND A\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\nC \nC OUTPUT PARAMETERS\nC \nC X FOR I=1,...,N\nC \nC X(I) = X(1) PLUS THE SUM FROM K=2 TO K=N OF\nC \nC 2*X(K)*COS((2*I-1)*(K-1)*PI/(2*N))\nC \nC A CALL OF DCOSQF FOLLOWED BY A CALL OF\nC DCOSQB WILL MULTIPLY THE SEQUENCE X BY 4*N.\nC THEREFORE DCOSQB IS THE UNNORMALIZED INVERSE\nC OF DCOSQF.\nC \nC WSAVE CONTAINS INITIALIZATION CALCULATIONS WHICH MUST NOT\nC BE DESTROYED BETWEEN CALLS OF DCOSQF OR DCOSQB.\nC \nC ******************************************************************\nC \nC SUBROUTINE DCOSQB(N,X,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE DCOSQB COMPUTES THE FAST FOURIER TRANSFORM OF QUARTER\nC WAVE DATA. THAT IS , DCOSQB COMPUTES A SEQUENCE FROM ITS\nC REPRESENTATION IN TERMS OF A COSINE SERIES WITH ODD WAVE NUMBERS.\nC THE TRANSFORM IS DEFINED BELOW AT OUTPUT PARAMETER X.\nC \nC DCOSQB IS THE UNNORMALIZED INVERSE OF DCOSQF SINCE A CALL OF DCOSQB\nC FOLLOWED BY A CALL OF DCOSQF WILL MULTIPLY THE INPUT SEQUENCE X\nC BY 4*N.\nC \nC THE ARRAY WSAVE WHICH IS USED BY SUBROUTINE DCOSQB MUST BE\nC INITIALIZED BY CALLING SUBROUTINE DCOSQI(N,WSAVE).\nC \nC \nC INPUT PARAMETERS\nC \nC N THE LENGTH OF THE ARRAY X TO BE TRANSFORMED. THE METHOD\nC IS MOST EFFICIENT WHEN N IS A PRODUCT OF SMALL PRIMES.\nC \nC X AN ARRAY WHICH CONTAINS THE SEQUENCE TO BE TRANSFORMED\nC \nC WSAVE A WORK ARRAY THAT MUST BE DIMENSIONED AT LEAST 3*N+15\nC IN THE PROGRAM THAT CALLS DCOSQB. THE WSAVE ARRAY MUST BE\nC INITIALIZED BY CALLING SUBROUTINE DCOSQI(N,WSAVE) AND A\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\nC \nC OUTPUT PARAMETERS\nC \nC X FOR I=1,...,N\nC \nC X(I)= THE SUM FROM K=1 TO K=N OF\nC \nC 4*X(K)*COS((2*K-1)*(I-1)*PI/(2*N))\nC \nC A CALL OF DCOSQB FOLLOWED BY A CALL OF\nC DCOSQF WILL MULTIPLY THE SEQUENCE X BY 4*N.\nC THEREFORE DCOSQF IS THE UNNORMALIZED INVERSE\nC OF DCOSQB.\nC \nC WSAVE CONTAINS INITIALIZATION CALCULATIONS WHICH MUST NOT\nC BE DESTROYED BETWEEN CALLS OF DCOSQB OR DCOSQF.\nC \nC ******************************************************************\nC \nC SUBROUTINE ZFFTI(N,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE ZFFTI INITIALIZES THE ARRAY WSAVE WHICH IS USED IN\nC BOTH ZFFTF AND ZFFTB. THE PRIME FACTORIZATION OF N TOGETHER WITH\nC A TABULATION OF THE TRIGONOMETRIC FUNCTIONS ARE COMPUTED AND\nC STORED IN WSAVE.\nC \nC INPUT PARAMETER\nC \nC N THE LENGTH OF THE SEQUENCE TO BE TRANSFORMED\nC \nC OUTPUT PARAMETER\nC \nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 4*N+15\nC THE SAME WORK ARRAY CAN BE USED FOR BOTH ZFFTF AND ZFFTB\nC AS LONG AS N REMAINS UNCHANGED. DIFFERENT WSAVE ARRAYS\nC ARE REQUIRED FOR DIFFERENT VALUES OF N. THE CONTENTS OF\nC WSAVE MUST NOT BE CHANGED BETWEEN CALLS OF ZFFTF OR ZFFTB.\nC \nC ******************************************************************\nC \nC SUBROUTINE ZFFTF(N,C,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE ZFFTF COMPUTES THE FORWARD COMPLEX DISCRETE FOURIER\nC TRANSFORM (THE FOURIER ANALYSIS). EQUIVALENTLY , ZFFTF COMPUTES\nC THE FOURIER COEFFICIENTS OF A COMPLEX PERIODIC SEQUENCE.\nC THE TRANSFORM IS DEFINED BELOW AT OUTPUT PARAMETER C.\nC \nC THE TRANSFORM IS NOT NORMALIZED. TO OBTAIN A NORMALIZED TRANSFORM\nC THE OUTPUT MUST BE DIVIDED BY N. OTHERWISE A CALL OF ZFFTF\nC FOLLOWED BY A CALL OF ZFFTB WILL MULTIPLY THE SEQUENCE BY N.\nC \nC THE ARRAY WSAVE WHICH IS USED BY SUBROUTINE ZFFTF MUST BE\nC INITIALIZED BY CALLING SUBROUTINE ZFFTI(N,WSAVE).\nC \nC INPUT PARAMETERS\nC \nC \nC N THE LENGTH OF THE COMPLEX SEQUENCE C. THE METHOD IS\nC MORE EFFICIENT WHEN N IS THE PRODUCT OF SMALL PRIMES. N\nC \nC C A COMPLEX ARRAY OF LENGTH N WHICH CONTAINS THE SEQUENCE\nC \nC WSAVE A REAL WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 4N+15\nC IN THE PROGRAM THAT CALLS ZFFTF. THE WSAVE ARRAY MUST BE\nC INITIALIZED BY CALLING SUBROUTINE ZFFTI(N,WSAVE) AND A\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\nC THE SAME WSAVE ARRAY CAN BE USED BY ZFFTF AND ZFFTB.\nC \nC OUTPUT PARAMETERS\nC \nC C FOR J=1,...,N\nC \nC C(J)=THE SUM FROM K=1,...,N OF\nC \nC C(K)*EXP(-I*(J-1)*(K-1)*2*PI/N)\nC \nC WHERE I=SQRT(-1)\nC \nC WSAVE CONTAINS INITIALIZATION CALCULATIONS WHICH MUST NOT BE\nC DESTROYED BETWEEN CALLS OF SUBROUTINE ZFFTF OR ZFFTB\nC \nC ******************************************************************\nC \nC SUBROUTINE ZFFTB(N,C,WSAVE)\nC \nC ******************************************************************\nC \nC SUBROUTINE ZFFTB COMPUTES THE BACKWARD COMPLEX DISCRETE FOURIER\nC TRANSFORM (THE FOURIER SYNTHESIS). EQUIVALENTLY , ZFFTB COMPUTES\nC A COMPLEX PERIODIC SEQUENCE FROM ITS FOURIER COEFFICIENTS.\nC THE TRANSFORM IS DEFINED BELOW AT OUTPUT PARAMETER C.\nC \nC A CALL OF ZFFTF FOLLOWED BY A CALL OF ZFFTB WILL MULTIPLY THE\nC SEQUENCE BY N.\nC \nC THE ARRAY WSAVE WHICH IS USED BY SUBROUTINE ZFFTB MUST BE\nC INITIALIZED BY CALLING SUBROUTINE ZFFTI(N,WSAVE).\nC \nC INPUT PARAMETERS\nC \nC \nC N THE LENGTH OF THE COMPLEX SEQUENCE C. THE METHOD IS\nC MORE EFFICIENT WHEN N IS THE PRODUCT OF SMALL PRIMES.\nC \nC C A COMPLEX ARRAY OF LENGTH N WHICH CONTAINS THE SEQUENCE\nC \nC WSAVE A REAL WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 4N+15\nC IN THE PROGRAM THAT CALLS ZFFTB. THE WSAVE ARRAY MUST BE\nC INITIALIZED BY CALLING SUBROUTINE ZFFTI(N,WSAVE) AND A\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\nC THE SAME WSAVE ARRAY CAN BE USED BY ZFFTF AND ZFFTB.\nC \nC OUTPUT PARAMETERS\nC \nC C FOR J=1,...,N\nC \nC C(J)=THE SUM FROM K=1,...,N OF\nC \nC C(K)*EXP(I*(J-1)*(K-1)*2*PI/N)\nC \nC WHERE I=SQRT(-1)\nC \nC WSAVE CONTAINS INITIALIZATION CALCULATIONS WHICH MUST NOT BE\nC DESTROYED BETWEEN CALLS OF SUBROUTINE ZFFTF OR ZFFTB\nC \nC \nC \nC [\"SEND INDEX FOR VFFTPK\" DESCRIBES A VECTORIZED VERSION OF FFTPACK]\nC \nC \nC \n\n\n SUBROUTINE ZFFTB (N,C,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION C(1) ,WSAVE(1)\n IF (N .EQ. 1) RETURN\n IW1 = N+N+1\n IW2 = IW1+N+N\n CALL ZFFTB1 (N,C,WSAVE,WSAVE(IW1),WSAVE(IW2))\n RETURN\n END\n SUBROUTINE ZFFTB1 (N,C,CH,WA,IFAC)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CH(1) ,C(1) ,WA(1) ,IFAC(*)\n NF = IFAC(2)\n NA = 0\n L1 = 1\n IW = 1\n DO 116 K1=1,NF\n IP = IFAC(K1+2)\n L2 = IP*L1\n IDO = N/L2\n IDOT = IDO+IDO\n IDL1 = IDOT*L1\n IF (IP .NE. 4) GO TO 103\n IX2 = IW+IDOT\n IX3 = IX2+IDOT\n IF (NA .NE. 0) GO TO 101\n CALL DPASSB4 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3))\n GO TO 102\n 101 CALL DPASSB4 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3))\n 102 NA = 1-NA\n GO TO 115\n 103 IF (IP .NE. 2) GO TO 106\n IF (NA .NE. 0) GO TO 104\n CALL DPASSB2 (IDOT,L1,C,CH,WA(IW))\n GO TO 105\n 104 CALL DPASSB2 (IDOT,L1,CH,C,WA(IW))\n 105 NA = 1-NA\n GO TO 115\n 106 IF (IP .NE. 3) GO TO 109\n IX2 = IW+IDOT\n IF (NA .NE. 0) GO TO 107\n CALL DPASSB3 (IDOT,L1,C,CH,WA(IW),WA(IX2))\n GO TO 108\n 107 CALL DPASSB3 (IDOT,L1,CH,C,WA(IW),WA(IX2))\n 108 NA = 1-NA\n GO TO 115\n 109 IF (IP .NE. 5) GO TO 112\n IX2 = IW+IDOT\n IX3 = IX2+IDOT\n IX4 = IX3+IDOT\n IF (NA .NE. 0) GO TO 110\n CALL DPASSB5 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3),WA(IX4))\n GO TO 111\n 110 CALL DPASSB5 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3),WA(IX4))\n 111 NA = 1-NA\n GO TO 115\n 112 IF (NA .NE. 0) GO TO 113\n CALL DPASSB (NAC,IDOT,IP,L1,IDL1,C,C,C,CH,CH,WA(IW))\n GO TO 114\n 113 CALL DPASSB (NAC,IDOT,IP,L1,IDL1,CH,CH,CH,C,C,WA(IW))\n 114 IF (NAC .NE. 0) NA = 1-NA\n 115 L1 = L2\n IW = IW+(IP-1)*IDOT\n 116 CONTINUE\n IF (NA .EQ. 0) RETURN\n N2 = N+N\n DO 117 I=1,N2\n C(I) = CH(I)\n 117 CONTINUE\n RETURN\n END\n SUBROUTINE ZFFTF (N,C,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION C(1) ,WSAVE(1)\n IF (N .EQ. 1) RETURN\n IW1 = N+N+1\n IW2 = IW1+N+N\n CALL ZFFTF1 (N,C,WSAVE,WSAVE(IW1),WSAVE(IW2))\n RETURN\n END\n SUBROUTINE ZFFTF1 (N,C,CH,WA,IFAC)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CH(1) ,C(1) ,WA(1) ,IFAC(*)\n NF = IFAC(2)\n NA = 0\n L1 = 1\n IW = 1\n DO 116 K1=1,NF\n IP = IFAC(K1+2)\n L2 = IP*L1\n IDO = N/L2\n IDOT = IDO+IDO\n IDL1 = IDOT*L1\n IF (IP .NE. 4) GO TO 103\n IX2 = IW+IDOT\n IX3 = IX2+IDOT\n IF (NA .NE. 0) GO TO 101\n CALL DPASSF4 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3))\n GO TO 102\n 101 CALL DPASSF4 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3))\n 102 NA = 1-NA\n GO TO 115\n 103 IF (IP .NE. 2) GO TO 106\n IF (NA .NE. 0) GO TO 104\n CALL DPASSF2 (IDOT,L1,C,CH,WA(IW))\n GO TO 105\n 104 CALL DPASSF2 (IDOT,L1,CH,C,WA(IW))\n 105 NA = 1-NA\n GO TO 115\n 106 IF (IP .NE. 3) GO TO 109\n IX2 = IW+IDOT\n IF (NA .NE. 0) GO TO 107\n CALL DPASSF3 (IDOT,L1,C,CH,WA(IW),WA(IX2))\n GO TO 108\n 107 CALL DPASSF3 (IDOT,L1,CH,C,WA(IW),WA(IX2))\n 108 NA = 1-NA\n GO TO 115\n 109 IF (IP .NE. 5) GO TO 112\n IX2 = IW+IDOT\n IX3 = IX2+IDOT\n IX4 = IX3+IDOT\n IF (NA .NE. 0) GO TO 110\n CALL DPASSF5 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3),WA(IX4))\n GO TO 111\n 110 CALL DPASSF5 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3),WA(IX4))\n 111 NA = 1-NA\n GO TO 115\n 112 IF (NA .NE. 0) GO TO 113\n CALL DPASSF (NAC,IDOT,IP,L1,IDL1,C,C,C,CH,CH,WA(IW))\n GO TO 114\n 113 CALL DPASSF (NAC,IDOT,IP,L1,IDL1,CH,CH,CH,C,C,WA(IW))\n 114 IF (NAC .NE. 0) NA = 1-NA\n 115 L1 = L2\n IW = IW+(IP-1)*IDOT\n 116 CONTINUE\n IF (NA .EQ. 0) RETURN\n N2 = N+N\n DO 117 I=1,N2\n C(I) = CH(I)\n 117 CONTINUE\n RETURN\n END\n SUBROUTINE ZFFTI (N,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION WSAVE(1)\n IF (N .EQ. 1) RETURN\n IW1 = N+N+1\n IW2 = IW1+N+N\n CALL ZFFTI1 (N,WSAVE(IW1),WSAVE(IW2))\n RETURN\n END\n SUBROUTINE ZFFTI1 (N,WA,IFAC)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION WA(1) ,IFAC(*) ,NTRYH(4)\n DATA NTRYH(1),NTRYH(2),NTRYH(3),NTRYH(4)/3,4,2,5/\n NL = N\n NF = 0\n J = 0\n 101 J = J+1\n IF (J-4) 102,102,103\n 102 NTRY = NTRYH(J)\n GO TO 104\n 103 NTRY = NTRY+2\n 104 NQ = NL/NTRY\n NR = NL-NTRY*NQ\n IF (NR) 101,105,101\n 105 NF = NF+1\n IFAC(NF+2) = NTRY\n NL = NQ\n IF (NTRY .NE. 2) GO TO 107\n IF (NF .EQ. 1) GO TO 107\n DO 106 I=2,NF\n IB = NF-I+2\n IFAC(IB+2) = IFAC(IB+1)\n 106 CONTINUE\n IFAC(3) = 2\n 107 IF (NL .NE. 1) GO TO 104\n IFAC(1) = N\n IFAC(2) = NF\n TPI = 6.2831853071795864769252867665590057D0\n ARGH = TPI/DBLE(N)\n I = 2\n L1 = 1\n DO 110 K1=1,NF\n IP = IFAC(K1+2)\n LD = 0\n L2 = L1*IP\n IDO = N/L2\n IDOT = IDO+IDO+2\n IPM = IP-1\n DO 109 J=1,IPM\n I1 = I\n WA(I-1) = 1.0D0\n WA(I) = 0.0D0\n LD = LD+L1\n FI = 0.0D0\n ARGLD = DBLE(LD)*ARGH\n DO 108 II=4,IDOT,2\n I = I+2\n FI = FI+1.0D0\n ARG = FI*ARGLD\n WA(I-1) = DCOS(ARG)\n WA(I) = DSIN(ARG)\n 108 CONTINUE\n IF (IP .LE. 5) GO TO 109\n WA(I1-1) = WA(I-1)\n WA(I1) = WA(I)\n 109 CONTINUE\n L1 = L2\n 110 CONTINUE\n RETURN\n END\n SUBROUTINE DCOSQB (N,X,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION X(*) ,WSAVE(1)\n DATA TSQRT2 /2.8284271247461900976033774484193961D0/\n IF (N-2) 101,102,103\n 101 X(1) = 4.0D0*X(1)\n RETURN\n 102 X1 = 4.0D0*(X(1)+X(2))\n X(2) = TSQRT2*(X(1)-X(2))\n X(1) = X1\n RETURN\n 103 CALL DCOSQB1 (N,X,WSAVE,WSAVE(N+1))\n RETURN\n END\n SUBROUTINE DCOSQB1 (N,X,W,XH)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION X(*) ,W(1) ,XH(*)\n NS2 = (N+1)/2\n NP2 = N+2\n DO 101 I=3,N,2\n XIM1 = X(I-1)+X(I)\n X(I) = X(I)-X(I-1)\n X(I-1) = XIM1\n 101 CONTINUE\n X(1) = X(1)+X(1)\n MODN = MOD(N,2)\n IF (MODN .EQ. 0) X(N) = X(N)+X(N)\n CALL DFFTB (N,X,XH)\n DO 102 K=2,NS2\n KC = NP2-K\n XH(K) = W(K-1)*X(KC)+W(KC-1)*X(K)\n XH(KC) = W(K-1)*X(K)-W(KC-1)*X(KC)\n 102 CONTINUE\n IF (MODN .EQ. 0) X(NS2+1) = W(NS2)*(X(NS2+1)+X(NS2+1))\n DO 103 K=2,NS2\n KC = NP2-K\n X(K) = XH(K)+XH(KC)\n X(KC) = XH(K)-XH(KC)\n 103 CONTINUE\n X(1) = X(1)+X(1)\n RETURN\n END\n SUBROUTINE DCOSQF (N,X,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION X(*) ,WSAVE(1)\n DATA SQRT2 /1.4142135623730950488016887242096980D0/\n IF (N-2) 102,101,103\n 101 TSQX = SQRT2*X(2)\n X(2) = X(1)-TSQX\n X(1) = X(1)+TSQX\n 102 RETURN\n 103 CALL DCOSQF1 (N,X,WSAVE,WSAVE(N+1))\n RETURN\n END\n SUBROUTINE DCOSQF1 (N,X,W,XH)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION X(*) ,W(1) ,XH(*)\n NS2 = (N+1)/2\n NP2 = N+2\n DO 101 K=2,NS2\n KC = NP2-K\n XH(K) = X(K)+X(KC)\n XH(KC) = X(K)-X(KC)\n 101 CONTINUE\n MODN = MOD(N,2)\n IF (MODN .EQ. 0) XH(NS2+1) = X(NS2+1)+X(NS2+1)\n DO 102 K=2,NS2\n KC = NP2-K\n X(K) = W(K-1)*XH(KC)+W(KC-1)*XH(K)\n X(KC) = W(K-1)*XH(K)-W(KC-1)*XH(KC)\n 102 CONTINUE\n IF (MODN .EQ. 0) X(NS2+1) = W(NS2)*XH(NS2+1)\n CALL DFFTF (N,X,XH)\n DO 103 I=3,N,2\n XIM1 = X(I-1)-X(I)\n X(I) = X(I-1)+X(I)\n X(I-1) = XIM1\n 103 CONTINUE\n RETURN\n END\n SUBROUTINE DCOSQI (N,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION WSAVE(1)\n DATA PIH /1.5707963267948966192313216916397514D0/\n DT = PIH/DBLE(N)\n FK = 0.0D0\n DO 101 K=1,N\n FK = FK+1.0D0\n WSAVE(K) = DCOS(FK*DT)\n 101 CONTINUE\n CALL DFFTI (N,WSAVE(N+1))\n RETURN\n END\n SUBROUTINE DCOST (N,X,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION X(*) ,WSAVE(1)\n NM1 = N-1\n NP1 = N+1\n NS2 = N/2\n IF (N-2) 106,101,102\n 101 X1H = X(1)+X(2)\n X(2) = X(1)-X(2)\n X(1) = X1H\n RETURN\n 102 IF (N .GT. 3) GO TO 103\n X1P3 = X(1)+X(3)\n TX2 = X(2)+X(2)\n X(2) = X(1)-X(3)\n X(1) = X1P3+TX2\n X(3) = X1P3-TX2\n RETURN\n 103 C1 = X(1)-X(N)\n X(1) = X(1)+X(N)\n DO 104 K=2,NS2\n KC = NP1-K\n T1 = X(K)+X(KC)\n T2 = X(K)-X(KC)\n C1 = C1+WSAVE(KC)*T2\n T2 = WSAVE(K)*T2\n X(K) = T1-T2\n X(KC) = T1+T2\n 104 CONTINUE\n MODN = MOD(N,2)\n IF (MODN .NE. 0) X(NS2+1) = X(NS2+1)+X(NS2+1)\n CALL DFFTF (NM1,X,WSAVE(N+1))\n XIM2 = X(2)\n X(2) = C1\n DO 105 I=4,N,2\n XI = X(I)\n X(I) = X(I-2)-X(I-1)\n X(I-1) = XIM2\n XIM2 = XI\n 105 CONTINUE\n IF (MODN .NE. 0) X(N) = XIM2\n 106 RETURN\n END\n SUBROUTINE DCOSTI (N,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION WSAVE(1)\n DATA PI /3.1415926535897932384626433832795028D0/\n IF (N .LE. 3) RETURN\n NM1 = N-1\n NP1 = N+1\n NS2 = N/2\n DT = PI/DBLE(NM1)\n FK = 0.0D0\n DO 101 K=2,NS2\n KC = NP1-K\n FK = FK+1.0D0\n WSAVE(K) = 2.0D0*DSIN(FK*DT)\n WSAVE(KC) = 2.0D0*DCOS(FK*DT)\n 101 CONTINUE\n CALL DFFTI (NM1,WSAVE(N+1))\n RETURN\n END\n SUBROUTINE DZFFT1 (N,WA,IFAC)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION WA(1) ,IFAC(*) ,NTRYH(4)\n DATA NTRYH(1),NTRYH(2),NTRYH(3),NTRYH(4)/4,2,3,5/\n 1 ,TPI/6.2831853071795864769252867665590057D0/\n NL = N\n NF = 0\n J = 0\n 101 J = J+1\n IF (J-4) 102,102,103\n 102 NTRY = NTRYH(J)\n GO TO 104\n 103 NTRY = NTRY+2\n 104 NQ = NL/NTRY\n NR = NL-NTRY*NQ\n IF (NR) 101,105,101\n 105 NF = NF+1\n IFAC(NF+2) = NTRY\n NL = NQ\n IF (NTRY .NE. 2) GO TO 107\n IF (NF .EQ. 1) GO TO 107\n DO 106 I=2,NF\n IB = NF-I+2\n IFAC(IB+2) = IFAC(IB+1)\n 106 CONTINUE\n IFAC(3) = 2\n 107 IF (NL .NE. 1) GO TO 104\n IFAC(1) = N\n IFAC(2) = NF\n ARGH = TPI/DBLE(N)\n IS = 0\n NFM1 = NF-1\n L1 = 1\n IF (NFM1 .EQ. 0) RETURN\n DO 111 K1=1,NFM1\n IP = IFAC(K1+2)\n L2 = L1*IP\n IDO = N/L2\n IPM = IP-1\n ARG1 = DBLE(L1)*ARGH\n CH1 = 1.0D0\n SH1 = 0.0D0\n DCH1 = DCOS(ARG1)\n DSH1 = DSIN(ARG1)\n DO 110 J=1,IPM\n CH1H = DCH1*CH1-DSH1*SH1\n SH1 = DCH1*SH1+DSH1*CH1\n CH1 = CH1H\n I = IS+2\n WA(I-1) = CH1\n WA(I) = SH1\n IF (IDO .LT. 5) GO TO 109\n DO 108 II=5,IDO,2\n I = I+2\n WA(I-1) = CH1*WA(I-3)-SH1*WA(I-2)\n WA(I) = CH1*WA(I-2)+SH1*WA(I-3)\n 108 CONTINUE\n 109 IS = IS+IDO\n 110 CONTINUE\n L1 = L2\n 111 CONTINUE\n RETURN\n END\n SUBROUTINE DZFFTB (N,R,AZERO,A,B,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION R(*) ,A(1) ,B(1) ,WSAVE(1)\n IF (N-2) 101,102,103\n 101 R(1) = AZERO\n RETURN\n 102 R(1) = AZERO+A(1)\n R(2) = AZERO-A(1)\n RETURN\n 103 NS2 = (N-1)/2\n DO 104 I=1,NS2\n R(2*I) = .5D0*A(I)\n R(2*I+1) = -.5D0*B(I)\n 104 CONTINUE\n R(1) = AZERO\n IF (MOD(N,2) .EQ. 0) R(N) = A(NS2+1)\n CALL DFFTB (N,R,WSAVE(N+1))\n RETURN\n END\n SUBROUTINE DZFFTF (N,R,AZERO,A,B,WSAVE)\nC\nC VERSION 3 JUNE 1979\nC\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION R(*) ,A(1) ,B(1) ,WSAVE(1)\n IF (N-2) 101,102,103\n 101 AZERO = R(1)\n RETURN\n 102 AZERO = .5D0*(R(1)+R(2))\n A(1) = .5D0*(R(1)-R(2))\n RETURN\n 103 DO 104 I=1,N\n WSAVE(I) = R(I)\n 104 CONTINUE\n CALL DFFTF (N,WSAVE,WSAVE(N+1))\n CF = 2.0D0/DBLE(N)\n CFM = -CF\n AZERO = .5D0*CF*WSAVE(1)\n NS2 = (N+1)/2\n NS2M = NS2-1\n DO 105 I=1,NS2M\n A(I) = CF*WSAVE(2*I)\n B(I) = CFM*WSAVE(2*I+1)\n 105 CONTINUE\n IF (MOD(N,2) .EQ. 1) RETURN\n A(NS2) = .5D0*CF*WSAVE(N)\n B(NS2) = 0.0D0\n RETURN\n END\n SUBROUTINE DZFFTI (N,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION WSAVE(1)\n IF (N .EQ. 1) RETURN\n CALL DZFFT1 (N,WSAVE(2*N+1),WSAVE(3*N+1))\n RETURN\n END\n SUBROUTINE DPASSB (NAC,IDO,IP,L1,IDL1,CC,C1,C2,CH,CH2,WA)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CH(IDO,L1,IP) ,CC(IDO,IP,L1) ,\n 1 C1(IDO,L1,IP) ,WA(1) ,C2(IDL1,IP),\n 2 CH2(IDL1,IP)\n IDOT = IDO/2\n NT = IP*IDL1\n IPP2 = IP+2\n IPPH = (IP+1)/2\n IDP = IP*IDO\nC\n IF (IDO .LT. L1) GO TO 106\n DO 103 J=2,IPPH\n JC = IPP2-J\n DO 102 K=1,L1\n DO 101 I=1,IDO\n CH(I,K,J) = CC(I,J,K)+CC(I,JC,K)\n CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K)\n 101 CONTINUE\n 102 CONTINUE\n 103 CONTINUE\n DO 105 K=1,L1\n DO 104 I=1,IDO\n CH(I,K,1) = CC(I,1,K)\n 104 CONTINUE\n 105 CONTINUE\n GO TO 112\n 106 DO 109 J=2,IPPH\n JC = IPP2-J\n DO 108 I=1,IDO\n DO 107 K=1,L1\n CH(I,K,J) = CC(I,J,K)+CC(I,JC,K)\n CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K)\n 107 CONTINUE\n 108 CONTINUE\n 109 CONTINUE\n DO 111 I=1,IDO\n DO 110 K=1,L1\n CH(I,K,1) = CC(I,1,K)\n 110 CONTINUE\n 111 CONTINUE\n 112 IDL = 2-IDO\n INC = 0\n DO 116 L=2,IPPH\n LC = IPP2-L\n IDL = IDL+IDO\n DO 113 IK=1,IDL1\n C2(IK,L) = CH2(IK,1)+WA(IDL-1)*CH2(IK,2)\n C2(IK,LC) = WA(IDL)*CH2(IK,IP)\n 113 CONTINUE\n IDLJ = IDL\n INC = INC+IDO\n DO 115 J=3,IPPH\n JC = IPP2-J\n IDLJ = IDLJ+INC\n IF (IDLJ .GT. IDP) IDLJ = IDLJ-IDP\n WAR = WA(IDLJ-1)\n WAI = WA(IDLJ)\n DO 114 IK=1,IDL1\n C2(IK,L) = C2(IK,L)+WAR*CH2(IK,J)\n C2(IK,LC) = C2(IK,LC)+WAI*CH2(IK,JC)\n 114 CONTINUE\n 115 CONTINUE\n 116 CONTINUE\n DO 118 J=2,IPPH\n DO 117 IK=1,IDL1\n CH2(IK,1) = CH2(IK,1)+CH2(IK,J)\n 117 CONTINUE\n 118 CONTINUE\n DO 120 J=2,IPPH\n JC = IPP2-J\n DO 119 IK=2,IDL1,2\n CH2(IK-1,J) = C2(IK-1,J)-C2(IK,JC)\n CH2(IK-1,JC) = C2(IK-1,J)+C2(IK,JC)\n CH2(IK,J) = C2(IK,J)+C2(IK-1,JC)\n CH2(IK,JC) = C2(IK,J)-C2(IK-1,JC)\n 119 CONTINUE\n 120 CONTINUE\n NAC = 1\n IF (IDO .EQ. 2) RETURN\n NAC = 0\n DO 121 IK=1,IDL1\n C2(IK,1) = CH2(IK,1)\n 121 CONTINUE\n DO 123 J=2,IP\n DO 122 K=1,L1\n C1(1,K,J) = CH(1,K,J)\n C1(2,K,J) = CH(2,K,J)\n 122 CONTINUE\n 123 CONTINUE\n IF (IDOT .GT. L1) GO TO 127\n IDIJ = 0\n DO 126 J=2,IP\n IDIJ = IDIJ+2\n DO 125 I=4,IDO,2\n IDIJ = IDIJ+2\n DO 124 K=1,L1\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)-WA(IDIJ)*CH(I,K,J)\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)+WA(IDIJ)*CH(I-1,K,J)\n 124 CONTINUE\n 125 CONTINUE\n 126 CONTINUE\n RETURN\n 127 IDJ = 2-IDO\n DO 130 J=2,IP\n IDJ = IDJ+IDO\n DO 129 K=1,L1\n IDIJ = IDJ\n DO 128 I=4,IDO,2\n IDIJ = IDIJ+2\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)-WA(IDIJ)*CH(I,K,J)\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)+WA(IDIJ)*CH(I-1,K,J)\n 128 CONTINUE\n 129 CONTINUE\n 130 CONTINUE\n RETURN\n END\n SUBROUTINE DPASSB2 (IDO,L1,CC,CH,WA1)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CC(IDO,2,L1) ,CH(IDO,L1,2) ,\n 1 WA1(1)\n IF (IDO .GT. 2) GO TO 102\n DO 101 K=1,L1\n CH(1,K,1) = CC(1,1,K)+CC(1,2,K)\n CH(1,K,2) = CC(1,1,K)-CC(1,2,K)\n CH(2,K,1) = CC(2,1,K)+CC(2,2,K)\n CH(2,K,2) = CC(2,1,K)-CC(2,2,K)\n 101 CONTINUE\n RETURN\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n CH(I-1,K,1) = CC(I-1,1,K)+CC(I-1,2,K)\n TR2 = CC(I-1,1,K)-CC(I-1,2,K)\n CH(I,K,1) = CC(I,1,K)+CC(I,2,K)\n TI2 = CC(I,1,K)-CC(I,2,K)\n CH(I,K,2) = WA1(I-1)*TI2+WA1(I)*TR2\n CH(I-1,K,2) = WA1(I-1)*TR2-WA1(I)*TI2\n 103 CONTINUE\n 104 CONTINUE\n RETURN\n END\n SUBROUTINE DPASSB3 (IDO,L1,CC,CH,WA1,WA2)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CC(IDO,3,L1) ,CH(IDO,L1,3) ,\n 1 WA1(1) ,WA2(1)\n DATA TAUR,TAUI /-.5D0,.86602540378443864676372317075293618D0/\n IF (IDO .NE. 2) GO TO 102\n DO 101 K=1,L1\n TR2 = CC(1,2,K)+CC(1,3,K)\n CR2 = CC(1,1,K)+TAUR*TR2\n CH(1,K,1) = CC(1,1,K)+TR2\n TI2 = CC(2,2,K)+CC(2,3,K)\n CI2 = CC(2,1,K)+TAUR*TI2\n CH(2,K,1) = CC(2,1,K)+TI2\n CR3 = TAUI*(CC(1,2,K)-CC(1,3,K))\n CI3 = TAUI*(CC(2,2,K)-CC(2,3,K))\n CH(1,K,2) = CR2-CI3\n CH(1,K,3) = CR2+CI3\n CH(2,K,2) = CI2+CR3\n CH(2,K,3) = CI2-CR3\n 101 CONTINUE\n RETURN\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TR2 = CC(I-1,2,K)+CC(I-1,3,K)\n CR2 = CC(I-1,1,K)+TAUR*TR2\n CH(I-1,K,1) = CC(I-1,1,K)+TR2\n TI2 = CC(I,2,K)+CC(I,3,K)\n CI2 = CC(I,1,K)+TAUR*TI2\n CH(I,K,1) = CC(I,1,K)+TI2\n CR3 = TAUI*(CC(I-1,2,K)-CC(I-1,3,K))\n CI3 = TAUI*(CC(I,2,K)-CC(I,3,K))\n DR2 = CR2-CI3\n DR3 = CR2+CI3\n DI2 = CI2+CR3\n DI3 = CI2-CR3\n CH(I,K,2) = WA1(I-1)*DI2+WA1(I)*DR2\n CH(I-1,K,2) = WA1(I-1)*DR2-WA1(I)*DI2\n CH(I,K,3) = WA2(I-1)*DI3+WA2(I)*DR3\n CH(I-1,K,3) = WA2(I-1)*DR3-WA2(I)*DI3\n 103 CONTINUE\n 104 CONTINUE\n RETURN\n END\n SUBROUTINE DPASSB4 (IDO,L1,CC,CH,WA1,WA2,WA3)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CC(IDO,4,L1) ,CH(IDO,L1,4) ,\n 1 WA1(1) ,WA2(1) ,WA3(1)\n IF (IDO .NE. 2) GO TO 102\n DO 101 K=1,L1\n TI1 = CC(2,1,K)-CC(2,3,K)\n TI2 = CC(2,1,K)+CC(2,3,K)\n TR4 = CC(2,4,K)-CC(2,2,K)\n TI3 = CC(2,2,K)+CC(2,4,K)\n TR1 = CC(1,1,K)-CC(1,3,K)\n TR2 = CC(1,1,K)+CC(1,3,K)\n TI4 = CC(1,2,K)-CC(1,4,K)\n TR3 = CC(1,2,K)+CC(1,4,K)\n CH(1,K,1) = TR2+TR3\n CH(1,K,3) = TR2-TR3\n CH(2,K,1) = TI2+TI3\n CH(2,K,3) = TI2-TI3\n CH(1,K,2) = TR1+TR4\n CH(1,K,4) = TR1-TR4\n CH(2,K,2) = TI1+TI4\n CH(2,K,4) = TI1-TI4\n 101 CONTINUE\n RETURN\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TI1 = CC(I,1,K)-CC(I,3,K)\n TI2 = CC(I,1,K)+CC(I,3,K)\n TI3 = CC(I,2,K)+CC(I,4,K)\n TR4 = CC(I,4,K)-CC(I,2,K)\n TR1 = CC(I-1,1,K)-CC(I-1,3,K)\n TR2 = CC(I-1,1,K)+CC(I-1,3,K)\n TI4 = CC(I-1,2,K)-CC(I-1,4,K)\n TR3 = CC(I-1,2,K)+CC(I-1,4,K)\n CH(I-1,K,1) = TR2+TR3\n CR3 = TR2-TR3\n CH(I,K,1) = TI2+TI3\n CI3 = TI2-TI3\n CR2 = TR1+TR4\n CR4 = TR1-TR4\n CI2 = TI1+TI4\n CI4 = TI1-TI4\n CH(I-1,K,2) = WA1(I-1)*CR2-WA1(I)*CI2\n CH(I,K,2) = WA1(I-1)*CI2+WA1(I)*CR2\n CH(I-1,K,3) = WA2(I-1)*CR3-WA2(I)*CI3\n CH(I,K,3) = WA2(I-1)*CI3+WA2(I)*CR3\n CH(I-1,K,4) = WA3(I-1)*CR4-WA3(I)*CI4\n CH(I,K,4) = WA3(I-1)*CI4+WA3(I)*CR4\n 103 CONTINUE\n 104 CONTINUE\n RETURN\n END\n SUBROUTINE DPASSB5 (IDO,L1,CC,CH,WA1,WA2,WA3,WA4)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CC(IDO,5,L1) ,CH(IDO,L1,5) ,\n 1 WA1(1) ,WA2(1) ,WA3(1) ,WA4(1)\n DATA TR11,TI11,TR12,TI12 /\n 1 .30901699437494742410229341718281905D0,\n 2 .95105651629515357211643933337938214D0,\n 3 -.80901699437494742410229341718281906D0,\n 4 .58778525229247312916870595463907276D0/\n IF (IDO .NE. 2) GO TO 102\n DO 101 K=1,L1\n TI5 = CC(2,2,K)-CC(2,5,K)\n TI2 = CC(2,2,K)+CC(2,5,K)\n TI4 = CC(2,3,K)-CC(2,4,K)\n TI3 = CC(2,3,K)+CC(2,4,K)\n TR5 = CC(1,2,K)-CC(1,5,K)\n TR2 = CC(1,2,K)+CC(1,5,K)\n TR4 = CC(1,3,K)-CC(1,4,K)\n TR3 = CC(1,3,K)+CC(1,4,K)\n CH(1,K,1) = CC(1,1,K)+TR2+TR3\n CH(2,K,1) = CC(2,1,K)+TI2+TI3\n CR2 = CC(1,1,K)+TR11*TR2+TR12*TR3\n CI2 = CC(2,1,K)+TR11*TI2+TR12*TI3\n CR3 = CC(1,1,K)+TR12*TR2+TR11*TR3\n CI3 = CC(2,1,K)+TR12*TI2+TR11*TI3\n CR5 = TI11*TR5+TI12*TR4\n CI5 = TI11*TI5+TI12*TI4\n CR4 = TI12*TR5-TI11*TR4\n CI4 = TI12*TI5-TI11*TI4\n CH(1,K,2) = CR2-CI5\n CH(1,K,5) = CR2+CI5\n CH(2,K,2) = CI2+CR5\n CH(2,K,3) = CI3+CR4\n CH(1,K,3) = CR3-CI4\n CH(1,K,4) = CR3+CI4\n CH(2,K,4) = CI3-CR4\n CH(2,K,5) = CI2-CR5\n 101 CONTINUE\n RETURN\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TI5 = CC(I,2,K)-CC(I,5,K)\n TI2 = CC(I,2,K)+CC(I,5,K)\n TI4 = CC(I,3,K)-CC(I,4,K)\n TI3 = CC(I,3,K)+CC(I,4,K)\n TR5 = CC(I-1,2,K)-CC(I-1,5,K)\n TR2 = CC(I-1,2,K)+CC(I-1,5,K)\n TR4 = CC(I-1,3,K)-CC(I-1,4,K)\n TR3 = CC(I-1,3,K)+CC(I-1,4,K)\n CH(I-1,K,1) = CC(I-1,1,K)+TR2+TR3\n CH(I,K,1) = CC(I,1,K)+TI2+TI3\n CR2 = CC(I-1,1,K)+TR11*TR2+TR12*TR3\n CI2 = CC(I,1,K)+TR11*TI2+TR12*TI3\n CR3 = CC(I-1,1,K)+TR12*TR2+TR11*TR3\n CI3 = CC(I,1,K)+TR12*TI2+TR11*TI3\n CR5 = TI11*TR5+TI12*TR4\n CI5 = TI11*TI5+TI12*TI4\n CR4 = TI12*TR5-TI11*TR4\n CI4 = TI12*TI5-TI11*TI4\n DR3 = CR3-CI4\n DR4 = CR3+CI4\n DI3 = CI3+CR4\n DI4 = CI3-CR4\n DR5 = CR2+CI5\n DR2 = CR2-CI5\n DI5 = CI2-CR5\n DI2 = CI2+CR5\n CH(I-1,K,2) = WA1(I-1)*DR2-WA1(I)*DI2\n CH(I,K,2) = WA1(I-1)*DI2+WA1(I)*DR2\n CH(I-1,K,3) = WA2(I-1)*DR3-WA2(I)*DI3\n CH(I,K,3) = WA2(I-1)*DI3+WA2(I)*DR3\n CH(I-1,K,4) = WA3(I-1)*DR4-WA3(I)*DI4\n CH(I,K,4) = WA3(I-1)*DI4+WA3(I)*DR4\n CH(I-1,K,5) = WA4(I-1)*DR5-WA4(I)*DI5\n CH(I,K,5) = WA4(I-1)*DI5+WA4(I)*DR5\n 103 CONTINUE\n 104 CONTINUE\n RETURN\n END\n SUBROUTINE DPASSF (NAC,IDO,IP,L1,IDL1,CC,C1,C2,CH,CH2,WA)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CH(IDO,L1,IP) ,CC(IDO,IP,L1) ,\n 1 C1(IDO,L1,IP) ,WA(1) ,C2(IDL1,IP),\n 2 CH2(IDL1,IP)\n IDOT = IDO/2\n NT = IP*IDL1\n IPP2 = IP+2\n IPPH = (IP+1)/2\n IDP = IP*IDO\nC\n IF (IDO .LT. L1) GO TO 106\n DO 103 J=2,IPPH\n JC = IPP2-J\n DO 102 K=1,L1\n DO 101 I=1,IDO\n CH(I,K,J) = CC(I,J,K)+CC(I,JC,K)\n CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K)\n 101 CONTINUE\n 102 CONTINUE\n 103 CONTINUE\n DO 105 K=1,L1\n DO 104 I=1,IDO\n CH(I,K,1) = CC(I,1,K)\n 104 CONTINUE\n 105 CONTINUE\n GO TO 112\n 106 DO 109 J=2,IPPH\n JC = IPP2-J\n DO 108 I=1,IDO\n DO 107 K=1,L1\n CH(I,K,J) = CC(I,J,K)+CC(I,JC,K)\n CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K)\n 107 CONTINUE\n 108 CONTINUE\n 109 CONTINUE\n DO 111 I=1,IDO\n DO 110 K=1,L1\n CH(I,K,1) = CC(I,1,K)\n 110 CONTINUE\n 111 CONTINUE\n 112 IDL = 2-IDO\n INC = 0\n DO 116 L=2,IPPH\n LC = IPP2-L\n IDL = IDL+IDO\n DO 113 IK=1,IDL1\n C2(IK,L) = CH2(IK,1)+WA(IDL-1)*CH2(IK,2)\n C2(IK,LC) = -WA(IDL)*CH2(IK,IP)\n 113 CONTINUE\n IDLJ = IDL\n INC = INC+IDO\n DO 115 J=3,IPPH\n JC = IPP2-J\n IDLJ = IDLJ+INC\n IF (IDLJ .GT. IDP) IDLJ = IDLJ-IDP\n WAR = WA(IDLJ-1)\n WAI = WA(IDLJ)\n DO 114 IK=1,IDL1\n C2(IK,L) = C2(IK,L)+WAR*CH2(IK,J)\n C2(IK,LC) = C2(IK,LC)-WAI*CH2(IK,JC)\n 114 CONTINUE\n 115 CONTINUE\n 116 CONTINUE\n DO 118 J=2,IPPH\n DO 117 IK=1,IDL1\n CH2(IK,1) = CH2(IK,1)+CH2(IK,J)\n 117 CONTINUE\n 118 CONTINUE\n DO 120 J=2,IPPH\n JC = IPP2-J\n DO 119 IK=2,IDL1,2\n CH2(IK-1,J) = C2(IK-1,J)-C2(IK,JC)\n CH2(IK-1,JC) = C2(IK-1,J)+C2(IK,JC)\n CH2(IK,J) = C2(IK,J)+C2(IK-1,JC)\n CH2(IK,JC) = C2(IK,J)-C2(IK-1,JC)\n 119 CONTINUE\n 120 CONTINUE\n NAC = 1\n IF (IDO .EQ. 2) RETURN\n NAC = 0\n DO 121 IK=1,IDL1\n C2(IK,1) = CH2(IK,1)\n 121 CONTINUE\n DO 123 J=2,IP\n DO 122 K=1,L1\n C1(1,K,J) = CH(1,K,J)\n C1(2,K,J) = CH(2,K,J)\n 122 CONTINUE\n 123 CONTINUE\n IF (IDOT .GT. L1) GO TO 127\n IDIJ = 0\n DO 126 J=2,IP\n IDIJ = IDIJ+2\n DO 125 I=4,IDO,2\n IDIJ = IDIJ+2\n DO 124 K=1,L1\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)+WA(IDIJ)*CH(I,K,J)\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)-WA(IDIJ)*CH(I-1,K,J)\n 124 CONTINUE\n 125 CONTINUE\n 126 CONTINUE\n RETURN\n 127 IDJ = 2-IDO\n DO 130 J=2,IP\n IDJ = IDJ+IDO\n DO 129 K=1,L1\n IDIJ = IDJ\n DO 128 I=4,IDO,2\n IDIJ = IDIJ+2\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)+WA(IDIJ)*CH(I,K,J)\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)-WA(IDIJ)*CH(I-1,K,J)\n 128 CONTINUE\n 129 CONTINUE\n 130 CONTINUE\n RETURN\n END\n SUBROUTINE DPASSF2 (IDO,L1,CC,CH,WA1)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CC(IDO,2,L1) ,CH(IDO,L1,2) ,\n 1 WA1(1)\n IF (IDO .GT. 2) GO TO 102\n DO 101 K=1,L1\n CH(1,K,1) = CC(1,1,K)+CC(1,2,K)\n CH(1,K,2) = CC(1,1,K)-CC(1,2,K)\n CH(2,K,1) = CC(2,1,K)+CC(2,2,K)\n CH(2,K,2) = CC(2,1,K)-CC(2,2,K)\n 101 CONTINUE\n RETURN\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n CH(I-1,K,1) = CC(I-1,1,K)+CC(I-1,2,K)\n TR2 = CC(I-1,1,K)-CC(I-1,2,K)\n CH(I,K,1) = CC(I,1,K)+CC(I,2,K)\n TI2 = CC(I,1,K)-CC(I,2,K)\n CH(I,K,2) = WA1(I-1)*TI2-WA1(I)*TR2\n CH(I-1,K,2) = WA1(I-1)*TR2+WA1(I)*TI2\n 103 CONTINUE\n 104 CONTINUE\n RETURN\n END\n SUBROUTINE DPASSF3 (IDO,L1,CC,CH,WA1,WA2)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CC(IDO,3,L1) ,CH(IDO,L1,3) ,\n 1 WA1(1) ,WA2(1)\n DATA TAUR,TAUI /-.5D0,-.86602540378443864676372317075293618D0/\n IF (IDO .NE. 2) GO TO 102\n DO 101 K=1,L1\n TR2 = CC(1,2,K)+CC(1,3,K)\n CR2 = CC(1,1,K)+TAUR*TR2\n CH(1,K,1) = CC(1,1,K)+TR2\n TI2 = CC(2,2,K)+CC(2,3,K)\n CI2 = CC(2,1,K)+TAUR*TI2\n CH(2,K,1) = CC(2,1,K)+TI2\n CR3 = TAUI*(CC(1,2,K)-CC(1,3,K))\n CI3 = TAUI*(CC(2,2,K)-CC(2,3,K))\n CH(1,K,2) = CR2-CI3\n CH(1,K,3) = CR2+CI3\n CH(2,K,2) = CI2+CR3\n CH(2,K,3) = CI2-CR3\n 101 CONTINUE\n RETURN\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TR2 = CC(I-1,2,K)+CC(I-1,3,K)\n CR2 = CC(I-1,1,K)+TAUR*TR2\n CH(I-1,K,1) = CC(I-1,1,K)+TR2\n TI2 = CC(I,2,K)+CC(I,3,K)\n CI2 = CC(I,1,K)+TAUR*TI2\n CH(I,K,1) = CC(I,1,K)+TI2\n CR3 = TAUI*(CC(I-1,2,K)-CC(I-1,3,K))\n CI3 = TAUI*(CC(I,2,K)-CC(I,3,K))\n DR2 = CR2-CI3\n DR3 = CR2+CI3\n DI2 = CI2+CR3\n DI3 = CI2-CR3\n CH(I,K,2) = WA1(I-1)*DI2-WA1(I)*DR2\n CH(I-1,K,2) = WA1(I-1)*DR2+WA1(I)*DI2\n CH(I,K,3) = WA2(I-1)*DI3-WA2(I)*DR3\n CH(I-1,K,3) = WA2(I-1)*DR3+WA2(I)*DI3\n 103 CONTINUE\n 104 CONTINUE\n RETURN\n END\n SUBROUTINE DPASSF4 (IDO,L1,CC,CH,WA1,WA2,WA3)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CC(IDO,4,L1) ,CH(IDO,L1,4) ,\n 1 WA1(1) ,WA2(1) ,WA3(1)\n IF (IDO .NE. 2) GO TO 102\n DO 101 K=1,L1\n TI1 = CC(2,1,K)-CC(2,3,K)\n TI2 = CC(2,1,K)+CC(2,3,K)\n TR4 = CC(2,2,K)-CC(2,4,K)\n TI3 = CC(2,2,K)+CC(2,4,K)\n TR1 = CC(1,1,K)-CC(1,3,K)\n TR2 = CC(1,1,K)+CC(1,3,K)\n TI4 = CC(1,4,K)-CC(1,2,K)\n TR3 = CC(1,2,K)+CC(1,4,K)\n CH(1,K,1) = TR2+TR3\n CH(1,K,3) = TR2-TR3\n CH(2,K,1) = TI2+TI3\n CH(2,K,3) = TI2-TI3\n CH(1,K,2) = TR1+TR4\n CH(1,K,4) = TR1-TR4\n CH(2,K,2) = TI1+TI4\n CH(2,K,4) = TI1-TI4\n 101 CONTINUE\n RETURN\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TI1 = CC(I,1,K)-CC(I,3,K)\n TI2 = CC(I,1,K)+CC(I,3,K)\n TI3 = CC(I,2,K)+CC(I,4,K)\n TR4 = CC(I,2,K)-CC(I,4,K)\n TR1 = CC(I-1,1,K)-CC(I-1,3,K)\n TR2 = CC(I-1,1,K)+CC(I-1,3,K)\n TI4 = CC(I-1,4,K)-CC(I-1,2,K)\n TR3 = CC(I-1,2,K)+CC(I-1,4,K)\n CH(I-1,K,1) = TR2+TR3\n CR3 = TR2-TR3\n CH(I,K,1) = TI2+TI3\n CI3 = TI2-TI3\n CR2 = TR1+TR4\n CR4 = TR1-TR4\n CI2 = TI1+TI4\n CI4 = TI1-TI4\n CH(I-1,K,2) = WA1(I-1)*CR2+WA1(I)*CI2\n CH(I,K,2) = WA1(I-1)*CI2-WA1(I)*CR2\n CH(I-1,K,3) = WA2(I-1)*CR3+WA2(I)*CI3\n CH(I,K,3) = WA2(I-1)*CI3-WA2(I)*CR3\n CH(I-1,K,4) = WA3(I-1)*CR4+WA3(I)*CI4\n CH(I,K,4) = WA3(I-1)*CI4-WA3(I)*CR4\n 103 CONTINUE\n 104 CONTINUE\n RETURN\n END\n SUBROUTINE DPASSF5 (IDO,L1,CC,CH,WA1,WA2,WA3,WA4)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CC(IDO,5,L1) ,CH(IDO,L1,5) ,\n 1 WA1(1) ,WA2(1) ,WA3(1) ,WA4(1)\n DATA TR11,TI11,TR12,TI12 /\n 1 .30901699437494742410229341718281905D0,\n 2 -.95105651629515357211643933337938214D0,\n 3 -.80901699437494742410229341718281906D0,\n 4 -.58778525229247312916870595463907276D0/\n IF (IDO .NE. 2) GO TO 102\n DO 101 K=1,L1\n TI5 = CC(2,2,K)-CC(2,5,K)\n TI2 = CC(2,2,K)+CC(2,5,K)\n TI4 = CC(2,3,K)-CC(2,4,K)\n TI3 = CC(2,3,K)+CC(2,4,K)\n TR5 = CC(1,2,K)-CC(1,5,K)\n TR2 = CC(1,2,K)+CC(1,5,K)\n TR4 = CC(1,3,K)-CC(1,4,K)\n TR3 = CC(1,3,K)+CC(1,4,K)\n CH(1,K,1) = CC(1,1,K)+TR2+TR3\n CH(2,K,1) = CC(2,1,K)+TI2+TI3\n CR2 = CC(1,1,K)+TR11*TR2+TR12*TR3\n CI2 = CC(2,1,K)+TR11*TI2+TR12*TI3\n CR3 = CC(1,1,K)+TR12*TR2+TR11*TR3\n CI3 = CC(2,1,K)+TR12*TI2+TR11*TI3\n CR5 = TI11*TR5+TI12*TR4\n CI5 = TI11*TI5+TI12*TI4\n CR4 = TI12*TR5-TI11*TR4\n CI4 = TI12*TI5-TI11*TI4\n CH(1,K,2) = CR2-CI5\n CH(1,K,5) = CR2+CI5\n CH(2,K,2) = CI2+CR5\n CH(2,K,3) = CI3+CR4\n CH(1,K,3) = CR3-CI4\n CH(1,K,4) = CR3+CI4\n CH(2,K,4) = CI3-CR4\n CH(2,K,5) = CI2-CR5\n 101 CONTINUE\n RETURN\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TI5 = CC(I,2,K)-CC(I,5,K)\n TI2 = CC(I,2,K)+CC(I,5,K)\n TI4 = CC(I,3,K)-CC(I,4,K)\n TI3 = CC(I,3,K)+CC(I,4,K)\n TR5 = CC(I-1,2,K)-CC(I-1,5,K)\n TR2 = CC(I-1,2,K)+CC(I-1,5,K)\n TR4 = CC(I-1,3,K)-CC(I-1,4,K)\n TR3 = CC(I-1,3,K)+CC(I-1,4,K)\n CH(I-1,K,1) = CC(I-1,1,K)+TR2+TR3\n CH(I,K,1) = CC(I,1,K)+TI2+TI3\n CR2 = CC(I-1,1,K)+TR11*TR2+TR12*TR3\n CI2 = CC(I,1,K)+TR11*TI2+TR12*TI3\n CR3 = CC(I-1,1,K)+TR12*TR2+TR11*TR3\n CI3 = CC(I,1,K)+TR12*TI2+TR11*TI3\n CR5 = TI11*TR5+TI12*TR4\n CI5 = TI11*TI5+TI12*TI4\n CR4 = TI12*TR5-TI11*TR4\n CI4 = TI12*TI5-TI11*TI4\n DR3 = CR3-CI4\n DR4 = CR3+CI4\n DI3 = CI3+CR4\n DI4 = CI3-CR4\n DR5 = CR2+CI5\n DR2 = CR2-CI5\n DI5 = CI2-CR5\n DI2 = CI2+CR5\n CH(I-1,K,2) = WA1(I-1)*DR2+WA1(I)*DI2\n CH(I,K,2) = WA1(I-1)*DI2-WA1(I)*DR2\n CH(I-1,K,3) = WA2(I-1)*DR3+WA2(I)*DI3\n CH(I,K,3) = WA2(I-1)*DI3-WA2(I)*DR3\n CH(I-1,K,4) = WA3(I-1)*DR4+WA3(I)*DI4\n CH(I,K,4) = WA3(I-1)*DI4-WA3(I)*DR4\n CH(I-1,K,5) = WA4(I-1)*DR5+WA4(I)*DI5\n CH(I,K,5) = WA4(I-1)*DI5-WA4(I)*DR5\n 103 CONTINUE\n 104 CONTINUE\n RETURN\n END\n SUBROUTINE DRADB2 (IDO,L1,CC,CH,WA1)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CC(IDO,2,L1) ,CH(IDO,L1,2) ,\n 1 WA1(1)\n DO 101 K=1,L1\n CH(1,K,1) = CC(1,1,K)+CC(IDO,2,K)\n CH(1,K,2) = CC(1,1,K)-CC(IDO,2,K)\n 101 CONTINUE\n IF (IDO-2) 107,105,102\n 102 IDP2 = IDO+2\n DO 104 K=1,L1\n DO 103 I=3,IDO,2\n IC = IDP2-I\n CH(I-1,K,1) = CC(I-1,1,K)+CC(IC-1,2,K)\n TR2 = CC(I-1,1,K)-CC(IC-1,2,K)\n CH(I,K,1) = CC(I,1,K)-CC(IC,2,K)\n TI2 = CC(I,1,K)+CC(IC,2,K)\n CH(I-1,K,2) = WA1(I-2)*TR2-WA1(I-1)*TI2\n CH(I,K,2) = WA1(I-2)*TI2+WA1(I-1)*TR2\n 103 CONTINUE\n 104 CONTINUE\n IF (MOD(IDO,2) .EQ. 1) RETURN\n 105 DO 106 K=1,L1\n CH(IDO,K,1) = CC(IDO,1,K)+CC(IDO,1,K)\n CH(IDO,K,2) = -(CC(1,2,K)+CC(1,2,K))\n 106 CONTINUE\n 107 RETURN\n END\n SUBROUTINE DRADB3 (IDO,L1,CC,CH,WA1,WA2)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CC(IDO,3,L1) ,CH(IDO,L1,3) ,\n 1 WA1(1) ,WA2(1)\n DATA TAUR,TAUI /-.5D0,.86602540378443864676372317075293618D0/\n DO 101 K=1,L1\n TR2 = CC(IDO,2,K)+CC(IDO,2,K)\n CR2 = CC(1,1,K)+TAUR*TR2\n CH(1,K,1) = CC(1,1,K)+TR2\n CI3 = TAUI*(CC(1,3,K)+CC(1,3,K))\n CH(1,K,2) = CR2-CI3\n CH(1,K,3) = CR2+CI3\n 101 CONTINUE\n IF (IDO .EQ. 1) RETURN\n IDP2 = IDO+2\n DO 103 K=1,L1\n DO 102 I=3,IDO,2\n IC = IDP2-I\n TR2 = CC(I-1,3,K)+CC(IC-1,2,K)\n CR2 = CC(I-1,1,K)+TAUR*TR2\n CH(I-1,K,1) = CC(I-1,1,K)+TR2\n TI2 = CC(I,3,K)-CC(IC,2,K)\n CI2 = CC(I,1,K)+TAUR*TI2\n CH(I,K,1) = CC(I,1,K)+TI2\n CR3 = TAUI*(CC(I-1,3,K)-CC(IC-1,2,K))\n CI3 = TAUI*(CC(I,3,K)+CC(IC,2,K))\n DR2 = CR2-CI3\n DR3 = CR2+CI3\n DI2 = CI2+CR3\n DI3 = CI2-CR3\n CH(I-1,K,2) = WA1(I-2)*DR2-WA1(I-1)*DI2\n CH(I,K,2) = WA1(I-2)*DI2+WA1(I-1)*DR2\n CH(I-1,K,3) = WA2(I-2)*DR3-WA2(I-1)*DI3\n CH(I,K,3) = WA2(I-2)*DI3+WA2(I-1)*DR3\n 102 CONTINUE\n 103 CONTINUE\n RETURN\n END\n SUBROUTINE DRADB4 (IDO,L1,CC,CH,WA1,WA2,WA3)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CC(IDO,4,L1) ,CH(IDO,L1,4) ,\n 1 WA1(1) ,WA2(1) ,WA3(1)\n DATA SQRT2 /1.4142135623730950488016887242096980D0/\n DO 101 K=1,L1\n TR1 = CC(1,1,K)-CC(IDO,4,K)\n TR2 = CC(1,1,K)+CC(IDO,4,K)\n TR3 = CC(IDO,2,K)+CC(IDO,2,K)\n TR4 = CC(1,3,K)+CC(1,3,K)\n CH(1,K,1) = TR2+TR3\n CH(1,K,2) = TR1-TR4\n CH(1,K,3) = TR2-TR3\n CH(1,K,4) = TR1+TR4\n 101 CONTINUE\n IF (IDO-2) 107,105,102\n 102 IDP2 = IDO+2\n DO 104 K=1,L1\n DO 103 I=3,IDO,2\n IC = IDP2-I\n TI1 = CC(I,1,K)+CC(IC,4,K)\n TI2 = CC(I,1,K)-CC(IC,4,K)\n TI3 = CC(I,3,K)-CC(IC,2,K)\n TR4 = CC(I,3,K)+CC(IC,2,K)\n TR1 = CC(I-1,1,K)-CC(IC-1,4,K)\n TR2 = CC(I-1,1,K)+CC(IC-1,4,K)\n TI4 = CC(I-1,3,K)-CC(IC-1,2,K)\n TR3 = CC(I-1,3,K)+CC(IC-1,2,K)\n CH(I-1,K,1) = TR2+TR3\n CR3 = TR2-TR3\n CH(I,K,1) = TI2+TI3\n CI3 = TI2-TI3\n CR2 = TR1-TR4\n CR4 = TR1+TR4\n CI2 = TI1+TI4\n CI4 = TI1-TI4\n CH(I-1,K,2) = WA1(I-2)*CR2-WA1(I-1)*CI2\n CH(I,K,2) = WA1(I-2)*CI2+WA1(I-1)*CR2\n CH(I-1,K,3) = WA2(I-2)*CR3-WA2(I-1)*CI3\n CH(I,K,3) = WA2(I-2)*CI3+WA2(I-1)*CR3\n CH(I-1,K,4) = WA3(I-2)*CR4-WA3(I-1)*CI4\n CH(I,K,4) = WA3(I-2)*CI4+WA3(I-1)*CR4\n 103 CONTINUE\n 104 CONTINUE\n IF (MOD(IDO,2) .EQ. 1) RETURN\n 105 CONTINUE\n DO 106 K=1,L1\n TI1 = CC(1,2,K)+CC(1,4,K)\n TI2 = CC(1,4,K)-CC(1,2,K)\n TR1 = CC(IDO,1,K)-CC(IDO,3,K)\n TR2 = CC(IDO,1,K)+CC(IDO,3,K)\n CH(IDO,K,1) = TR2+TR2\n CH(IDO,K,2) = SQRT2*(TR1-TI1)\n CH(IDO,K,3) = TI2+TI2\n CH(IDO,K,4) = -SQRT2*(TR1+TI1)\n 106 CONTINUE\n 107 RETURN\n END\n SUBROUTINE DRADB5 (IDO,L1,CC,CH,WA1,WA2,WA3,WA4)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CC(IDO,5,L1) ,CH(IDO,L1,5) ,\n 1 WA1(1) ,WA2(1) ,WA3(1) ,WA4(1)\n DATA TR11,TI11,TR12,TI12 /\n 1 .30901699437494742410229341718281905D0,\n 2 .95105651629515357211643933337938214D0,\n 3 -.80901699437494742410229341718281906D0,\n 4 .58778525229247312916870595463907276D0/\n DO 101 K=1,L1\n TI5 = CC(1,3,K)+CC(1,3,K)\n TI4 = CC(1,5,K)+CC(1,5,K)\n TR2 = CC(IDO,2,K)+CC(IDO,2,K)\n TR3 = CC(IDO,4,K)+CC(IDO,4,K)\n CH(1,K,1) = CC(1,1,K)+TR2+TR3\n CR2 = CC(1,1,K)+TR11*TR2+TR12*TR3\n CR3 = CC(1,1,K)+TR12*TR2+TR11*TR3\n CI5 = TI11*TI5+TI12*TI4\n CI4 = TI12*TI5-TI11*TI4\n CH(1,K,2) = CR2-CI5\n CH(1,K,3) = CR3-CI4\n CH(1,K,4) = CR3+CI4\n CH(1,K,5) = CR2+CI5\n 101 CONTINUE\n IF (IDO .EQ. 1) RETURN\n IDP2 = IDO+2\n DO 103 K=1,L1\n DO 102 I=3,IDO,2\n IC = IDP2-I\n TI5 = CC(I,3,K)+CC(IC,2,K)\n TI2 = CC(I,3,K)-CC(IC,2,K)\n TI4 = CC(I,5,K)+CC(IC,4,K)\n TI3 = CC(I,5,K)-CC(IC,4,K)\n TR5 = CC(I-1,3,K)-CC(IC-1,2,K)\n TR2 = CC(I-1,3,K)+CC(IC-1,2,K)\n TR4 = CC(I-1,5,K)-CC(IC-1,4,K)\n TR3 = CC(I-1,5,K)+CC(IC-1,4,K)\n CH(I-1,K,1) = CC(I-1,1,K)+TR2+TR3\n CH(I,K,1) = CC(I,1,K)+TI2+TI3\n CR2 = CC(I-1,1,K)+TR11*TR2+TR12*TR3\n CI2 = CC(I,1,K)+TR11*TI2+TR12*TI3\n CR3 = CC(I-1,1,K)+TR12*TR2+TR11*TR3\n CI3 = CC(I,1,K)+TR12*TI2+TR11*TI3\n CR5 = TI11*TR5+TI12*TR4\n CI5 = TI11*TI5+TI12*TI4\n CR4 = TI12*TR5-TI11*TR4\n CI4 = TI12*TI5-TI11*TI4\n DR3 = CR3-CI4\n DR4 = CR3+CI4\n DI3 = CI3+CR4\n DI4 = CI3-CR4\n DR5 = CR2+CI5\n DR2 = CR2-CI5\n DI5 = CI2-CR5\n DI2 = CI2+CR5\n CH(I-1,K,2) = WA1(I-2)*DR2-WA1(I-1)*DI2\n CH(I,K,2) = WA1(I-2)*DI2+WA1(I-1)*DR2\n CH(I-1,K,3) = WA2(I-2)*DR3-WA2(I-1)*DI3\n CH(I,K,3) = WA2(I-2)*DI3+WA2(I-1)*DR3\n CH(I-1,K,4) = WA3(I-2)*DR4-WA3(I-1)*DI4\n CH(I,K,4) = WA3(I-2)*DI4+WA3(I-1)*DR4\n CH(I-1,K,5) = WA4(I-2)*DR5-WA4(I-1)*DI5\n CH(I,K,5) = WA4(I-2)*DI5+WA4(I-1)*DR5\n 102 CONTINUE\n 103 CONTINUE\n RETURN\n END\n SUBROUTINE DRADBG (IDO,IP,L1,IDL1,CC,C1,C2,CH,CH2,WA)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CH(IDO,L1,IP) ,CC(IDO,IP,L1) ,\n 1 C1(IDO,L1,IP) ,C2(IDL1,IP),\n 2 CH2(IDL1,IP) ,WA(1)\n DATA TPI/6.2831853071795864769252867665590057D0/\n ARG = TPI/DBLE(IP)\n DCP = DCOS(ARG)\n DSP = DSIN(ARG)\n IDP2 = IDO+2\n NBD = (IDO-1)/2\n IPP2 = IP+2\n IPPH = (IP+1)/2\n IF (IDO .LT. L1) GO TO 103\n DO 102 K=1,L1\n DO 101 I=1,IDO\n CH(I,K,1) = CC(I,1,K)\n 101 CONTINUE\n 102 CONTINUE\n GO TO 106\n 103 DO 105 I=1,IDO\n DO 104 K=1,L1\n CH(I,K,1) = CC(I,1,K)\n 104 CONTINUE\n 105 CONTINUE\n 106 DO 108 J=2,IPPH\n JC = IPP2-J\n J2 = J+J\n DO 107 K=1,L1\n CH(1,K,J) = CC(IDO,J2-2,K)+CC(IDO,J2-2,K)\n CH(1,K,JC) = CC(1,J2-1,K)+CC(1,J2-1,K)\n 107 CONTINUE\n 108 CONTINUE\n IF (IDO .EQ. 1) GO TO 116\n IF (NBD .LT. L1) GO TO 112\n DO 111 J=2,IPPH\n JC = IPP2-J\n DO 110 K=1,L1\n DO 109 I=3,IDO,2\n IC = IDP2-I\n CH(I-1,K,J) = CC(I-1,2*J-1,K)+CC(IC-1,2*J-2,K)\n CH(I-1,K,JC) = CC(I-1,2*J-1,K)-CC(IC-1,2*J-2,K)\n CH(I,K,J) = CC(I,2*J-1,K)-CC(IC,2*J-2,K)\n CH(I,K,JC) = CC(I,2*J-1,K)+CC(IC,2*J-2,K)\n 109 CONTINUE\n 110 CONTINUE\n 111 CONTINUE\n GO TO 116\n 112 DO 115 J=2,IPPH\n JC = IPP2-J\n DO 114 I=3,IDO,2\n IC = IDP2-I\n DO 113 K=1,L1\n CH(I-1,K,J) = CC(I-1,2*J-1,K)+CC(IC-1,2*J-2,K)\n CH(I-1,K,JC) = CC(I-1,2*J-1,K)-CC(IC-1,2*J-2,K)\n CH(I,K,J) = CC(I,2*J-1,K)-CC(IC,2*J-2,K)\n CH(I,K,JC) = CC(I,2*J-1,K)+CC(IC,2*J-2,K)\n 113 CONTINUE\n 114 CONTINUE\n 115 CONTINUE\n 116 AR1 = 1.0D0\n AI1 = 0.0D0\n DO 120 L=2,IPPH\n LC = IPP2-L\n AR1H = DCP*AR1-DSP*AI1\n AI1 = DCP*AI1+DSP*AR1\n AR1 = AR1H\n DO 117 IK=1,IDL1\n C2(IK,L) = CH2(IK,1)+AR1*CH2(IK,2)\n C2(IK,LC) = AI1*CH2(IK,IP)\n 117 CONTINUE\n DC2 = AR1\n DS2 = AI1\n AR2 = AR1\n AI2 = AI1\n DO 119 J=3,IPPH\n JC = IPP2-J\n AR2H = DC2*AR2-DS2*AI2\n AI2 = DC2*AI2+DS2*AR2\n AR2 = AR2H\n DO 118 IK=1,IDL1\n C2(IK,L) = C2(IK,L)+AR2*CH2(IK,J)\n C2(IK,LC) = C2(IK,LC)+AI2*CH2(IK,JC)\n 118 CONTINUE\n 119 CONTINUE\n 120 CONTINUE\n DO 122 J=2,IPPH\n DO 121 IK=1,IDL1\n CH2(IK,1) = CH2(IK,1)+CH2(IK,J)\n 121 CONTINUE\n 122 CONTINUE\n DO 124 J=2,IPPH\n JC = IPP2-J\n DO 123 K=1,L1\n CH(1,K,J) = C1(1,K,J)-C1(1,K,JC)\n CH(1,K,JC) = C1(1,K,J)+C1(1,K,JC)\n 123 CONTINUE\n 124 CONTINUE\n IF (IDO .EQ. 1) GO TO 132\n IF (NBD .LT. L1) GO TO 128\n DO 127 J=2,IPPH\n JC = IPP2-J\n DO 126 K=1,L1\n DO 125 I=3,IDO,2\n CH(I-1,K,J) = C1(I-1,K,J)-C1(I,K,JC)\n CH(I-1,K,JC) = C1(I-1,K,J)+C1(I,K,JC)\n CH(I,K,J) = C1(I,K,J)+C1(I-1,K,JC)\n CH(I,K,JC) = C1(I,K,J)-C1(I-1,K,JC)\n 125 CONTINUE\n 126 CONTINUE\n 127 CONTINUE\n GO TO 132\n 128 DO 131 J=2,IPPH\n JC = IPP2-J\n DO 130 I=3,IDO,2\n DO 129 K=1,L1\n CH(I-1,K,J) = C1(I-1,K,J)-C1(I,K,JC)\n CH(I-1,K,JC) = C1(I-1,K,J)+C1(I,K,JC)\n CH(I,K,J) = C1(I,K,J)+C1(I-1,K,JC)\n CH(I,K,JC) = C1(I,K,J)-C1(I-1,K,JC)\n 129 CONTINUE\n 130 CONTINUE\n 131 CONTINUE\n 132 CONTINUE\n IF (IDO .EQ. 1) RETURN\n DO 133 IK=1,IDL1\n C2(IK,1) = CH2(IK,1)\n 133 CONTINUE\n DO 135 J=2,IP\n DO 134 K=1,L1\n C1(1,K,J) = CH(1,K,J)\n 134 CONTINUE\n 135 CONTINUE\n IF (NBD .GT. L1) GO TO 139\n IS = -IDO\n DO 138 J=2,IP\n IS = IS+IDO\n IDIJ = IS\n DO 137 I=3,IDO,2\n IDIJ = IDIJ+2\n DO 136 K=1,L1\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)-WA(IDIJ)*CH(I,K,J)\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)+WA(IDIJ)*CH(I-1,K,J)\n 136 CONTINUE\n 137 CONTINUE\n 138 CONTINUE\n GO TO 143\n 139 IS = -IDO\n DO 142 J=2,IP\n IS = IS+IDO\n DO 141 K=1,L1\n IDIJ = IS\n DO 140 I=3,IDO,2\n IDIJ = IDIJ+2\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)-WA(IDIJ)*CH(I,K,J)\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)+WA(IDIJ)*CH(I-1,K,J)\n 140 CONTINUE\n 141 CONTINUE\n 142 CONTINUE\n 143 RETURN\n END\n SUBROUTINE DRADF2 (IDO,L1,CC,CH,WA1)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CH(IDO,2,L1) ,CC(IDO,L1,2) ,\n 1 WA1(1)\n DO 101 K=1,L1\n CH(1,1,K) = CC(1,K,1)+CC(1,K,2)\n CH(IDO,2,K) = CC(1,K,1)-CC(1,K,2)\n 101 CONTINUE\n IF (IDO-2) 107,105,102\n 102 IDP2 = IDO+2\n DO 104 K=1,L1\n DO 103 I=3,IDO,2\n IC = IDP2-I\n TR2 = WA1(I-2)*CC(I-1,K,2)+WA1(I-1)*CC(I,K,2)\n TI2 = WA1(I-2)*CC(I,K,2)-WA1(I-1)*CC(I-1,K,2)\n CH(I,1,K) = CC(I,K,1)+TI2\n CH(IC,2,K) = TI2-CC(I,K,1)\n CH(I-1,1,K) = CC(I-1,K,1)+TR2\n CH(IC-1,2,K) = CC(I-1,K,1)-TR2\n 103 CONTINUE\n 104 CONTINUE\n IF (MOD(IDO,2) .EQ. 1) RETURN\n 105 DO 106 K=1,L1\n CH(1,2,K) = -CC(IDO,K,2)\n CH(IDO,1,K) = CC(IDO,K,1)\n 106 CONTINUE\n 107 RETURN\n END\n SUBROUTINE DRADF3 (IDO,L1,CC,CH,WA1,WA2)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CH(IDO,3,L1) ,CC(IDO,L1,3) ,\n 1 WA1(1) ,WA2(1)\n DATA TAUR,TAUI /-.5D0,.86602540378443864676372317075293618D0/\n DO 101 K=1,L1\n CR2 = CC(1,K,2)+CC(1,K,3)\n CH(1,1,K) = CC(1,K,1)+CR2\n CH(1,3,K) = TAUI*(CC(1,K,3)-CC(1,K,2))\n CH(IDO,2,K) = CC(1,K,1)+TAUR*CR2\n 101 CONTINUE\n IF (IDO .EQ. 1) RETURN\n IDP2 = IDO+2\n DO 103 K=1,L1\n DO 102 I=3,IDO,2\n IC = IDP2-I\n DR2 = WA1(I-2)*CC(I-1,K,2)+WA1(I-1)*CC(I,K,2)\n DI2 = WA1(I-2)*CC(I,K,2)-WA1(I-1)*CC(I-1,K,2)\n DR3 = WA2(I-2)*CC(I-1,K,3)+WA2(I-1)*CC(I,K,3)\n DI3 = WA2(I-2)*CC(I,K,3)-WA2(I-1)*CC(I-1,K,3)\n CR2 = DR2+DR3\n CI2 = DI2+DI3\n CH(I-1,1,K) = CC(I-1,K,1)+CR2\n CH(I,1,K) = CC(I,K,1)+CI2\n TR2 = CC(I-1,K,1)+TAUR*CR2\n TI2 = CC(I,K,1)+TAUR*CI2\n TR3 = TAUI*(DI2-DI3)\n TI3 = TAUI*(DR3-DR2)\n CH(I-1,3,K) = TR2+TR3\n CH(IC-1,2,K) = TR2-TR3\n CH(I,3,K) = TI2+TI3\n CH(IC,2,K) = TI3-TI2\n 102 CONTINUE\n 103 CONTINUE\n RETURN\n END\n SUBROUTINE DRADF4 (IDO,L1,CC,CH,WA1,WA2,WA3)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CC(IDO,L1,4) ,CH(IDO,4,L1) ,\n 1 WA1(1) ,WA2(1) ,WA3(1)\n DATA HSQT2 /0.70710678118654752440084436210484904D0/\n DO 101 K=1,L1\n TR1 = CC(1,K,2)+CC(1,K,4)\n TR2 = CC(1,K,1)+CC(1,K,3)\n CH(1,1,K) = TR1+TR2\n CH(IDO,4,K) = TR2-TR1\n CH(IDO,2,K) = CC(1,K,1)-CC(1,K,3)\n CH(1,3,K) = CC(1,K,4)-CC(1,K,2)\n 101 CONTINUE\n IF (IDO-2) 107,105,102\n 102 IDP2 = IDO+2\n DO 104 K=1,L1\n DO 103 I=3,IDO,2\n IC = IDP2-I\n CR2 = WA1(I-2)*CC(I-1,K,2)+WA1(I-1)*CC(I,K,2)\n CI2 = WA1(I-2)*CC(I,K,2)-WA1(I-1)*CC(I-1,K,2)\n CR3 = WA2(I-2)*CC(I-1,K,3)+WA2(I-1)*CC(I,K,3)\n CI3 = WA2(I-2)*CC(I,K,3)-WA2(I-1)*CC(I-1,K,3)\n CR4 = WA3(I-2)*CC(I-1,K,4)+WA3(I-1)*CC(I,K,4)\n CI4 = WA3(I-2)*CC(I,K,4)-WA3(I-1)*CC(I-1,K,4)\n TR1 = CR2+CR4\n TR4 = CR4-CR2\n TI1 = CI2+CI4\n TI4 = CI2-CI4\n TI2 = CC(I,K,1)+CI3\n TI3 = CC(I,K,1)-CI3\n TR2 = CC(I-1,K,1)+CR3\n TR3 = CC(I-1,K,1)-CR3\n CH(I-1,1,K) = TR1+TR2\n CH(IC-1,4,K) = TR2-TR1\n CH(I,1,K) = TI1+TI2\n CH(IC,4,K) = TI1-TI2\n CH(I-1,3,K) = TI4+TR3\n CH(IC-1,2,K) = TR3-TI4\n CH(I,3,K) = TR4+TI3\n CH(IC,2,K) = TR4-TI3\n 103 CONTINUE\n 104 CONTINUE\n IF (MOD(IDO,2) .EQ. 1) RETURN\n 105 CONTINUE\n DO 106 K=1,L1\n TI1 = -HSQT2*(CC(IDO,K,2)+CC(IDO,K,4))\n TR1 = HSQT2*(CC(IDO,K,2)-CC(IDO,K,4))\n CH(IDO,1,K) = TR1+CC(IDO,K,1)\n CH(IDO,3,K) = CC(IDO,K,1)-TR1\n CH(1,2,K) = TI1-CC(IDO,K,3)\n CH(1,4,K) = TI1+CC(IDO,K,3)\n 106 CONTINUE\n 107 RETURN\n END\n SUBROUTINE DRADF5 (IDO,L1,CC,CH,WA1,WA2,WA3,WA4)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CC(IDO,L1,5) ,CH(IDO,5,L1) ,\n 1 WA1(1) ,WA2(1) ,WA3(1) ,WA4(1)\n DATA TR11,TI11,TR12,TI12 /\n 1 .30901699437494742410229341718281905D0,\n 2 .95105651629515357211643933337938214D0,\n 3 -.80901699437494742410229341718281906D0,\n 4 .58778525229247312916870595463907276D0/\n DO 101 K=1,L1\n CR2 = CC(1,K,5)+CC(1,K,2)\n CI5 = CC(1,K,5)-CC(1,K,2)\n CR3 = CC(1,K,4)+CC(1,K,3)\n CI4 = CC(1,K,4)-CC(1,K,3)\n CH(1,1,K) = CC(1,K,1)+CR2+CR3\n CH(IDO,2,K) = CC(1,K,1)+TR11*CR2+TR12*CR3\n CH(1,3,K) = TI11*CI5+TI12*CI4\n CH(IDO,4,K) = CC(1,K,1)+TR12*CR2+TR11*CR3\n CH(1,5,K) = TI12*CI5-TI11*CI4\n 101 CONTINUE\n IF (IDO .EQ. 1) RETURN\n IDP2 = IDO+2\n DO 103 K=1,L1\n DO 102 I=3,IDO,2\n IC = IDP2-I\n DR2 = WA1(I-2)*CC(I-1,K,2)+WA1(I-1)*CC(I,K,2)\n DI2 = WA1(I-2)*CC(I,K,2)-WA1(I-1)*CC(I-1,K,2)\n DR3 = WA2(I-2)*CC(I-1,K,3)+WA2(I-1)*CC(I,K,3)\n DI3 = WA2(I-2)*CC(I,K,3)-WA2(I-1)*CC(I-1,K,3)\n DR4 = WA3(I-2)*CC(I-1,K,4)+WA3(I-1)*CC(I,K,4)\n DI4 = WA3(I-2)*CC(I,K,4)-WA3(I-1)*CC(I-1,K,4)\n DR5 = WA4(I-2)*CC(I-1,K,5)+WA4(I-1)*CC(I,K,5)\n DI5 = WA4(I-2)*CC(I,K,5)-WA4(I-1)*CC(I-1,K,5)\n CR2 = DR2+DR5\n CI5 = DR5-DR2\n CR5 = DI2-DI5\n CI2 = DI2+DI5\n CR3 = DR3+DR4\n CI4 = DR4-DR3\n CR4 = DI3-DI4\n CI3 = DI3+DI4\n CH(I-1,1,K) = CC(I-1,K,1)+CR2+CR3\n CH(I,1,K) = CC(I,K,1)+CI2+CI3\n TR2 = CC(I-1,K,1)+TR11*CR2+TR12*CR3\n TI2 = CC(I,K,1)+TR11*CI2+TR12*CI3\n TR3 = CC(I-1,K,1)+TR12*CR2+TR11*CR3\n TI3 = CC(I,K,1)+TR12*CI2+TR11*CI3\n TR5 = TI11*CR5+TI12*CR4\n TI5 = TI11*CI5+TI12*CI4\n TR4 = TI12*CR5-TI11*CR4\n TI4 = TI12*CI5-TI11*CI4\n CH(I-1,3,K) = TR2+TR5\n CH(IC-1,2,K) = TR2-TR5\n CH(I,3,K) = TI2+TI5\n CH(IC,2,K) = TI5-TI2\n CH(I-1,5,K) = TR3+TR4\n CH(IC-1,4,K) = TR3-TR4\n CH(I,5,K) = TI3+TI4\n CH(IC,4,K) = TI4-TI3\n 102 CONTINUE\n 103 CONTINUE\n RETURN\n END\n SUBROUTINE DRADFG (IDO,IP,L1,IDL1,CC,C1,C2,CH,CH2,WA)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CH(IDO,L1,IP) ,CC(IDO,IP,L1) ,\n 1 C1(IDO,L1,IP) ,C2(IDL1,IP),\n 2 CH2(IDL1,IP) ,WA(1)\n DATA TPI/6.2831853071795864769252867665590057D0/\n ARG = TPI/DBLE(IP)\n DCP = DCOS(ARG)\n DSP = DSIN(ARG)\n IPPH = (IP+1)/2\n IPP2 = IP+2\n IDP2 = IDO+2\n NBD = (IDO-1)/2\n IF (IDO .EQ. 1) GO TO 119\n DO 101 IK=1,IDL1\n CH2(IK,1) = C2(IK,1)\n 101 CONTINUE\n DO 103 J=2,IP\n DO 102 K=1,L1\n CH(1,K,J) = C1(1,K,J)\n 102 CONTINUE\n 103 CONTINUE\n IF (NBD .GT. L1) GO TO 107\n IS = -IDO\n DO 106 J=2,IP\n IS = IS+IDO\n IDIJ = IS\n DO 105 I=3,IDO,2\n IDIJ = IDIJ+2\n DO 104 K=1,L1\n CH(I-1,K,J) = WA(IDIJ-1)*C1(I-1,K,J)+WA(IDIJ)*C1(I,K,J)\n CH(I,K,J) = WA(IDIJ-1)*C1(I,K,J)-WA(IDIJ)*C1(I-1,K,J)\n 104 CONTINUE\n 105 CONTINUE\n 106 CONTINUE\n GO TO 111\n 107 IS = -IDO\n DO 110 J=2,IP\n IS = IS+IDO\n DO 109 K=1,L1\n IDIJ = IS\n DO 108 I=3,IDO,2\n IDIJ = IDIJ+2\n CH(I-1,K,J) = WA(IDIJ-1)*C1(I-1,K,J)+WA(IDIJ)*C1(I,K,J)\n CH(I,K,J) = WA(IDIJ-1)*C1(I,K,J)-WA(IDIJ)*C1(I-1,K,J)\n 108 CONTINUE\n 109 CONTINUE\n 110 CONTINUE\n 111 IF (NBD .LT. L1) GO TO 115\n DO 114 J=2,IPPH\n JC = IPP2-J\n DO 113 K=1,L1\n DO 112 I=3,IDO,2\n C1(I-1,K,J) = CH(I-1,K,J)+CH(I-1,K,JC)\n C1(I-1,K,JC) = CH(I,K,J)-CH(I,K,JC)\n C1(I,K,J) = CH(I,K,J)+CH(I,K,JC)\n C1(I,K,JC) = CH(I-1,K,JC)-CH(I-1,K,J)\n 112 CONTINUE\n 113 CONTINUE\n 114 CONTINUE\n GO TO 121\n 115 DO 118 J=2,IPPH\n JC = IPP2-J\n DO 117 I=3,IDO,2\n DO 116 K=1,L1\n C1(I-1,K,J) = CH(I-1,K,J)+CH(I-1,K,JC)\n C1(I-1,K,JC) = CH(I,K,J)-CH(I,K,JC)\n C1(I,K,J) = CH(I,K,J)+CH(I,K,JC)\n C1(I,K,JC) = CH(I-1,K,JC)-CH(I-1,K,J)\n 116 CONTINUE\n 117 CONTINUE\n 118 CONTINUE\n GO TO 121\n 119 DO 120 IK=1,IDL1\n C2(IK,1) = CH2(IK,1)\n 120 CONTINUE\n 121 DO 123 J=2,IPPH\n JC = IPP2-J\n DO 122 K=1,L1\n C1(1,K,J) = CH(1,K,J)+CH(1,K,JC)\n C1(1,K,JC) = CH(1,K,JC)-CH(1,K,J)\n 122 CONTINUE\n 123 CONTINUE\nC\n AR1 = 1.0D0\n AI1 = 0.0D0\n DO 127 L=2,IPPH\n LC = IPP2-L\n AR1H = DCP*AR1-DSP*AI1\n AI1 = DCP*AI1+DSP*AR1\n AR1 = AR1H\n DO 124 IK=1,IDL1\n CH2(IK,L) = C2(IK,1)+AR1*C2(IK,2)\n CH2(IK,LC) = AI1*C2(IK,IP)\n 124 CONTINUE\n DC2 = AR1\n DS2 = AI1\n AR2 = AR1\n AI2 = AI1\n DO 126 J=3,IPPH\n JC = IPP2-J\n AR2H = DC2*AR2-DS2*AI2\n AI2 = DC2*AI2+DS2*AR2\n AR2 = AR2H\n DO 125 IK=1,IDL1\n CH2(IK,L) = CH2(IK,L)+AR2*C2(IK,J)\n CH2(IK,LC) = CH2(IK,LC)+AI2*C2(IK,JC)\n 125 CONTINUE\n 126 CONTINUE\n 127 CONTINUE\n DO 129 J=2,IPPH\n DO 128 IK=1,IDL1\n CH2(IK,1) = CH2(IK,1)+C2(IK,J)\n 128 CONTINUE\n 129 CONTINUE\nC\n IF (IDO .LT. L1) GO TO 132\n DO 131 K=1,L1\n DO 130 I=1,IDO\n CC(I,1,K) = CH(I,K,1)\n 130 CONTINUE\n 131 CONTINUE\n GO TO 135\n 132 DO 134 I=1,IDO\n DO 133 K=1,L1\n CC(I,1,K) = CH(I,K,1)\n 133 CONTINUE\n 134 CONTINUE\n 135 DO 137 J=2,IPPH\n JC = IPP2-J\n J2 = J+J\n DO 136 K=1,L1\n CC(IDO,J2-2,K) = CH(1,K,J)\n CC(1,J2-1,K) = CH(1,K,JC)\n 136 CONTINUE\n 137 CONTINUE\n IF (IDO .EQ. 1) RETURN\n IF (NBD .LT. L1) GO TO 141\n DO 140 J=2,IPPH\n JC = IPP2-J\n J2 = J+J\n DO 139 K=1,L1\n DO 138 I=3,IDO,2\n IC = IDP2-I\n CC(I-1,J2-1,K) = CH(I-1,K,J)+CH(I-1,K,JC)\n CC(IC-1,J2-2,K) = CH(I-1,K,J)-CH(I-1,K,JC)\n CC(I,J2-1,K) = CH(I,K,J)+CH(I,K,JC)\n CC(IC,J2-2,K) = CH(I,K,JC)-CH(I,K,J)\n 138 CONTINUE\n 139 CONTINUE\n 140 CONTINUE\n RETURN\n 141 DO 144 J=2,IPPH\n JC = IPP2-J\n J2 = J+J\n DO 143 I=3,IDO,2\n IC = IDP2-I\n DO 142 K=1,L1\n CC(I-1,J2-1,K) = CH(I-1,K,J)+CH(I-1,K,JC)\n CC(IC-1,J2-2,K) = CH(I-1,K,J)-CH(I-1,K,JC)\n CC(I,J2-1,K) = CH(I,K,J)+CH(I,K,JC)\n CC(IC,J2-2,K) = CH(I,K,JC)-CH(I,K,J)\n 142 CONTINUE\n 143 CONTINUE\n 144 CONTINUE\n RETURN\n END\n SUBROUTINE DFFTB (N,R,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION R(*) ,WSAVE(1)\n IF (N .EQ. 1) RETURN\n CALL DFFTB1 (N,R,WSAVE,WSAVE(N+1),WSAVE(2*N+1))\n RETURN\n END\n SUBROUTINE DFFTB1 (N,C,CH,WA,IFAC)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CH(1) ,C(1) ,WA(1) ,IFAC(*)\n NF = IFAC(2)\n NA = 0\n L1 = 1\n IW = 1\n DO 116 K1=1,NF\n IP = IFAC(K1+2)\n L2 = IP*L1\n IDO = N/L2\n IDL1 = IDO*L1\n IF (IP .NE. 4) GO TO 103\n IX2 = IW+IDO\n IX3 = IX2+IDO\n IF (NA .NE. 0) GO TO 101\n CALL DRADB4 (IDO,L1,C,CH,WA(IW),WA(IX2),WA(IX3))\n GO TO 102\n 101 CALL DRADB4 (IDO,L1,CH,C,WA(IW),WA(IX2),WA(IX3))\n 102 NA = 1-NA\n GO TO 115\n 103 IF (IP .NE. 2) GO TO 106\n IF (NA .NE. 0) GO TO 104\n CALL DRADB2 (IDO,L1,C,CH,WA(IW))\n GO TO 105\n 104 CALL DRADB2 (IDO,L1,CH,C,WA(IW))\n 105 NA = 1-NA\n GO TO 115\n 106 IF (IP .NE. 3) GO TO 109\n IX2 = IW+IDO\n IF (NA .NE. 0) GO TO 107\n CALL DRADB3 (IDO,L1,C,CH,WA(IW),WA(IX2))\n GO TO 108\n 107 CALL DRADB3 (IDO,L1,CH,C,WA(IW),WA(IX2))\n 108 NA = 1-NA\n GO TO 115\n 109 IF (IP .NE. 5) GO TO 112\n IX2 = IW+IDO\n IX3 = IX2+IDO\n IX4 = IX3+IDO\n IF (NA .NE. 0) GO TO 110\n CALL DRADB5 (IDO,L1,C,CH,WA(IW),WA(IX2),WA(IX3),WA(IX4))\n GO TO 111\n 110 CALL DRADB5 (IDO,L1,CH,C,WA(IW),WA(IX2),WA(IX3),WA(IX4))\n 111 NA = 1-NA\n GO TO 115\n 112 IF (NA .NE. 0) GO TO 113\n CALL DRADBG (IDO,IP,L1,IDL1,C,C,C,CH,CH,WA(IW))\n GO TO 114\n 113 CALL DRADBG (IDO,IP,L1,IDL1,CH,CH,CH,C,C,WA(IW))\n 114 IF (IDO .EQ. 1) NA = 1-NA\n 115 L1 = L2\n IW = IW+(IP-1)*IDO\n 116 CONTINUE\n IF (NA .EQ. 0) RETURN\n DO 117 I=1,N\n C(I) = CH(I)\n 117 CONTINUE\n RETURN\n END\n SUBROUTINE DFFTF (N,R,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION R(*) ,WSAVE(1)\n IF (N .EQ. 1) RETURN\n CALL DFFTF1 (N,R,WSAVE,WSAVE(N+1),WSAVE(2*N+1))\n RETURN\n END\n SUBROUTINE DFFTF1 (N,C,CH,WA,IFAC)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CH(1) ,C(1) ,WA(1) ,IFAC(*)\n NF = IFAC(2)\n NA = 1\n L2 = N\n IW = N\n DO 111 K1=1,NF\n KH = NF-K1\n IP = IFAC(KH+3)\n L1 = L2/IP\n IDO = N/L2\n IDL1 = IDO*L1\n IW = IW-(IP-1)*IDO\n NA = 1-NA\n IF (IP .NE. 4) GO TO 102\n IX2 = IW+IDO\n IX3 = IX2+IDO\n IF (NA .NE. 0) GO TO 101\n CALL DRADF4 (IDO,L1,C,CH,WA(IW),WA(IX2),WA(IX3))\n GO TO 110\n 101 CALL DRADF4 (IDO,L1,CH,C,WA(IW),WA(IX2),WA(IX3))\n GO TO 110\n 102 IF (IP .NE. 2) GO TO 104\n IF (NA .NE. 0) GO TO 103\n CALL DRADF2 (IDO,L1,C,CH,WA(IW))\n GO TO 110\n 103 CALL DRADF2 (IDO,L1,CH,C,WA(IW))\n GO TO 110\n 104 IF (IP .NE. 3) GO TO 106\n IX2 = IW+IDO\n IF (NA .NE. 0) GO TO 105\n CALL DRADF3 (IDO,L1,C,CH,WA(IW),WA(IX2))\n GO TO 110\n 105 CALL DRADF3 (IDO,L1,CH,C,WA(IW),WA(IX2))\n GO TO 110\n 106 IF (IP .NE. 5) GO TO 108\n IX2 = IW+IDO\n IX3 = IX2+IDO\n IX4 = IX3+IDO\n IF (NA .NE. 0) GO TO 107\n CALL DRADF5 (IDO,L1,C,CH,WA(IW),WA(IX2),WA(IX3),WA(IX4))\n GO TO 110\n 107 CALL DRADF5 (IDO,L1,CH,C,WA(IW),WA(IX2),WA(IX3),WA(IX4))\n GO TO 110\n 108 IF (IDO .EQ. 1) NA = 1-NA\n IF (NA .NE. 0) GO TO 109\n CALL DRADFG (IDO,IP,L1,IDL1,C,C,C,CH,CH,WA(IW))\n NA = 1\n GO TO 110\n 109 CALL DRADFG (IDO,IP,L1,IDL1,CH,CH,CH,C,C,WA(IW))\n NA = 0\n 110 L2 = L1\n 111 CONTINUE\n IF (NA .EQ. 1) RETURN\n DO 112 I=1,N\n C(I) = CH(I)\n 112 CONTINUE\n RETURN\n END\n SUBROUTINE DFFTI (N,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION WSAVE(1)\n IF (N .EQ. 1) RETURN\n CALL DFFTI1 (N,WSAVE(N+1),WSAVE(2*N+1))\n RETURN\n END\n SUBROUTINE DFFTI1 (N,WA,IFAC)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION WA(1) ,IFAC(*) ,NTRYH(4)\n DATA NTRYH(1),NTRYH(2),NTRYH(3),NTRYH(4)/4,2,3,5/\n NL = N\n NF = 0\n J = 0\n 101 J = J+1\n IF (J-4) 102,102,103\n 102 NTRY = NTRYH(J)\n GO TO 104\n 103 NTRY = NTRY+2\n 104 NQ = NL/NTRY\n NR = NL-NTRY*NQ\n IF (NR) 101,105,101\n 105 NF = NF+1\n IFAC(NF+2) = NTRY\n NL = NQ\n IF (NTRY .NE. 2) GO TO 107\n IF (NF .EQ. 1) GO TO 107\n DO 106 I=2,NF\n IB = NF-I+2\n IFAC(IB+2) = IFAC(IB+1)\n 106 CONTINUE\n IFAC(3) = 2\n 107 IF (NL .NE. 1) GO TO 104\n IFAC(1) = N\n IFAC(2) = NF\n TPI = 6.2831853071795864769252867665590057D0\n ARGH = TPI/DBLE(N)\n IS = 0\n NFM1 = NF-1\n L1 = 1\n IF (NFM1 .EQ. 0) RETURN\n DO 110 K1=1,NFM1\n IP = IFAC(K1+2)\n LD = 0\n L2 = L1*IP\n IDO = N/L2\n IPM = IP-1\n DO 109 J=1,IPM\n LD = LD+L1\n I = IS\n ARGLD = DBLE(LD)*ARGH\n FI = 0.0D0\n DO 108 II=3,IDO,2\n I = I+2\n FI = FI+1.0D0\n ARG = FI*ARGLD\n WA(I-1) = DCOS(ARG)\n WA(I) = DSIN(ARG)\n 108 CONTINUE\n IS = IS+IDO\n 109 CONTINUE\n L1 = L2\n 110 CONTINUE\n RETURN\n END\n SUBROUTINE DSINQB (N,X,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION X(*) ,WSAVE(1)\n IF (N .GT. 1) GO TO 101\n X(1) = 4.0D0*X(1)\n RETURN\n 101 NS2 = N/2\n DO 102 K=2,N,2\n X(K) = -X(K)\n 102 CONTINUE\n CALL DCOSQB (N,X,WSAVE)\n DO 103 K=1,NS2\n KC = N-K\n XHOLD = X(K)\n X(K) = X(KC+1)\n X(KC+1) = XHOLD\n 103 CONTINUE\n RETURN\n END\n SUBROUTINE DSINQF (N,X,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION X(*) ,WSAVE(1)\n IF (N .EQ. 1) RETURN\n NS2 = N/2\n DO 101 K=1,NS2\n KC = N-K\n XHOLD = X(K)\n X(K) = X(KC+1)\n X(KC+1) = XHOLD\n 101 CONTINUE\n CALL DCOSQF (N,X,WSAVE)\n DO 102 K=2,N,2\n X(K) = -X(K)\n 102 CONTINUE\n RETURN\n END\n SUBROUTINE DSINQI (N,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION WSAVE(1)\n CALL DCOSQI (N,WSAVE)\n RETURN\n END\n SUBROUTINE DSINT (N,X,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION X(*) ,WSAVE(1)\n NP1 = N+1\n IW1 = N/2+1\n IW2 = IW1+NP1\n IW3 = IW2+NP1\n CALL DSINT1(N,X,WSAVE,WSAVE(IW1),WSAVE(IW2),WSAVE(IW3))\n RETURN\n END\n SUBROUTINE DSINT1(N,WAR,WAS,XH,X,IFAC)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION WAR(1),WAS(1),X(*),XH(*),IFAC(*)\n DATA SQRT3 /1.7320508075688772935274463415058723D0/\n DO 100 I=1,N\n XH(I) = WAR(I)\n WAR(I) = X(I)\n 100 CONTINUE\n IF (N-2) 101,102,103\n 101 XH(1) = XH(1)+XH(1)\n GO TO 106\n 102 XHOLD = SQRT3*(XH(1)+XH(2))\n XH(2) = SQRT3*(XH(1)-XH(2))\n XH(1) = XHOLD\n GO TO 106\n 103 NP1 = N+1\n NS2 = N/2\n X(1) = 0.0D0\n DO 104 K=1,NS2\n KC = NP1-K\n T1 = XH(K)-XH(KC)\n T2 = WAS(K)*(XH(K)+XH(KC))\n X(K+1) = T1+T2\n X(KC+1) = T2-T1\n 104 CONTINUE\n MODN = MOD(N,2)\n IF (MODN .NE. 0) X(NS2+2) = 4.0D0*XH(NS2+1)\n CALL DFFTF1 (NP1,X,XH,WAR,IFAC)\n XH(1) = .5D0*X(1)\n DO 105 I=3,N,2\n XH(I-1) = -X(I)\n XH(I) = XH(I-2)+X(I-1)\n 105 CONTINUE\n IF (MODN .NE. 0) GO TO 106\n XH(N) = -X(N+1)\n 106 DO 107 I=1,N\n X(I) = WAR(I)\n WAR(I) = XH(I)\n 107 CONTINUE\n RETURN\n END\n SUBROUTINE DSINTI (N,WSAVE)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION WSAVE(1)\n DATA PI /3.1415926535897932384626433832795028D0/\n IF (N .LE. 1) RETURN\n NS2 = N/2\n NP1 = N+1\n DT = PI/DBLE(NP1)\n DO 101 K=1,NS2\n WSAVE(K) = 2.0D0*DSIN(K*DT)\n 101 CONTINUE\n CALL DFFTI (NP1,WSAVE(NS2+1))\n RETURN\n END\n\n", "meta": {"hexsha": "ce57fcfc3c65f925063f2b09794d5302b54ac57f", "size": 94283, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/common/dfft.f", "max_stars_repo_name": "askhamwhat/fmm2d", "max_stars_repo_head_hexsha": "6521bf126719985830b2251f8b0742811df8a30c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 31, "max_stars_repo_stars_event_min_datetime": "2015-07-10T08:25:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-15T12:39:49.000Z", "max_issues_repo_path": "src/common/dfft.f", "max_issues_repo_name": "askhamwhat/fmm2d", "max_issues_repo_head_hexsha": "6521bf126719985830b2251f8b0742811df8a30c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-12-27T19:04:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-13T22:07:01.000Z", "max_forks_repo_path": "src/common/dfft.f", "max_forks_repo_name": "askhamwhat/fmm2d", "max_forks_repo_head_hexsha": "6521bf126719985830b2251f8b0742811df8a30c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2017-03-28T02:50:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-11T14:12:16.000Z", "avg_line_length": 31.4906479626, "max_line_length": 70, "alphanum_fraction": 0.5015008008, "num_tokens": 37660, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122720843812, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7669926904117129}} {"text": "\tDOUBLE PRECISION FUNCTION PHI(Z)\r\n\tUSE MSIMSL\r\nC\r\nC-Description-----------------------------------------------------------\r\n\tIMPLICIT NONE\r\nC\r\nC Function:\r\nC\tCalculate the integral from -infinity to Z of\r\nC\t\texp(-z**2/2)/sqrt(2*PI)\r\nC Arguments:\r\nC i\tZ\tDOUBLE PRECISION\r\nC\tUpper range of integration\r\nC Notes:\r\nC .\tThis routine was written by Dale Plummer\r\nC .\tThis routine was designed by William Dupont\r\nC .\tThis routine calls ERF and ERFC from IMSL\r\nC\r\nC-Declarations----------------------------------------------------------\r\nC\r\nC\r\nC Arguments\r\nC\r\n\tREAL Z\r\nC\r\nC Locals\r\nC\r\n\tDOUBLE PRECISION ZZ\r\nC\r\nC-Code------------------------------------------------------------------\r\nC\r\nC Copy argument to double precision local storage.\r\nC\r\n\tZZ=Z\r\nC\r\n\tIF (ZZ.GE.0) THEN\r\nC\r\nC Case of ZZ >= 0\r\nC\r\n\t PHI=(1.+DERF(ZZ/SQRT(2.)))/2.\r\n\tELSE\r\nC\r\nC Case of ZZ < 0\r\nC\r\n\t PHI=DERFC(-ZZ/SQRT(2.))/2.\r\n\tEND IF\r\nC\r\nC Finished.\r\nC\r\n\tRETURN\r\n\tEND", "meta": {"hexsha": "5b26fd109a6c13f4664c56cde6712937e5790a09", "size": 960, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "misc/old_ps/ps-development-version/psDll/phi.for", "max_stars_repo_name": "vubiostat/ps", "max_stars_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-12-29T14:19:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-06T15:08:46.000Z", "max_issues_repo_path": "misc/old_ps/ps-development-version/psDll/phi.for", "max_issues_repo_name": "vubiostat/ps", "max_issues_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-04-30T16:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T00:26:02.000Z", "max_forks_repo_path": "misc/old_ps/ps-development-version/psDll/phi.for", "max_forks_repo_name": "vubiostat/ps", "max_forks_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-07T20:11:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-11T19:18:59.000Z", "avg_line_length": 19.2, "max_line_length": 73, "alphanum_fraction": 0.5177083333, "num_tokens": 279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362489, "lm_q2_score": 0.8175744850834649, "lm_q1q2_score": 0.766986260745145}} {"text": "program main\n ! solve the Schrodinger equation of a 1-dimension harmonic oscillator with Numerov's method\n\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n real(dp), parameter :: eps = 1.d-5, dE = 1.d-2\n\n ! local vars\n real(dp) :: Xmax\n integer :: Nx, i\n real(dp) :: E ! trial energy\n real(dp) :: dx, ySquareSum\n real(dp), allocatable :: x(:), Vpot(:), y(:), g(:), f(:)\n logical :: yNSignChange = .false., yNSign\n integer :: looptime = 1\n real(dp) :: Eprev1, Eprev2, yprev1, yprev2\n\n ! executable\n Xmax = -1.d0\n do while (Xmax < 0.d0)\n write(*,*) 'Please indicate the range of x, [-Xmax, Xmax]; Xmax ='\n read(*,*) Xmax\n end do\n\n Nx = -1\n do while (Nx <= 0)\n write(*,*) 'Please specify the # of slices between [0,Xmax], Nx ='\n read(*,*) Nx\n end do\n\n write(*,*) \"Please give a trial energy E0, the first allowed state with E>E0 will be calculated! E0 =\"\n read(*,*) E\n\n write(*, '(a10,a20,a20)') 'Iteration', 'Energy', 'Boundary value'\n\n ! memory dynamical allocation\n allocate(x(-Nx:Nx))\n allocate(Vpot(-Nx:Nx))\n allocate(y(-Nx:Nx))\n allocate(g(-Nx:Nx))\n allocate(f(-Nx:Nx))\n\n dx = Xmax / dble(Nx)\n Vpot = 0.d0\n do i = -Nx, Nx\n x(i) = dx * i\n Vpot(i) = .5d0 * ((x(i)**2 - 1.d0)**2 / 4.d0 - x(i)**2)\n end do\n\n do while (.true.)\n ! set boundary condition at y(-Nx) and y(-Nx+1)\n y(-Nx) = 0.d0\n y(-Nx + 1) = 1.d-4\n\n do i = -Nx, Nx\n g(i) = 2.d0 * (E - Vpot(i))\n f(i) = 1.d0 + g(i) / 12.d0 * dx**2\n end do\n\n ! Numerov's method\n do i = -Nx + 1, Nx - 1\n y(i + 1) = ((12.d0 - 10.d0 * f(i)) * y(i) - f(i - 1) * y(i - 1)) / f(i + 1)\n end do\n\n ! renormalize y(x)\n call Simpson(2 * Nx + 1, y(-Nx:Nx), dx, ySquareSum)\n y = y / sqrt(ySquareSum)\n\n ! output to screen\n write(*,'(i10,2f20.8)') looptime, E, y(Nx)\n\n ! change E\n if (abs(y(Nx)) < eps) then ! if precision requirement is satisfied\n ! output to file\n open(1, file = '4-wavefunction-Numerov.txt', status = 'unknown')\n do i = -Nx, Nx\n write(1, '(2f20.8)') x(i), y(i)\n end do\n close(1)\n open(2, file = '4-energy-Numerov.txt', status = 'unknown')\n write(2, *) E\n close(2)\n exit\n else\n if (.not. yNSignChange) then ! if the sign of yN has not changed\n E = E + dE\n if (looptime == 1) then ! if this is the first loop\n yNSign = (y(Nx) >= 0)\n yprev1 = y(Nx)\n else\n if ((y(Nx) >=0) .neqv. (yNSign)) then ! if the sign of yN changed this time\n yNSignChange = .true.\n E = E - dE\n Eprev1 = E\n Eprev2 = E - dE\n E = E - dE / 2.d0\n end if\n yprev2 = yprev1\n yprev1 = y(Nx)\n end if\n else ! once the sign of yN has changed\n if (abs(yprev1) <= abs(yprev2)) then\n Eprev2 = E\n ! Eprev1 = Eprev1\n E = (Eprev1 + Eprev2) / 2.d0\n yprev2 = y(Nx)\n ! yprev1 = yprev1\n else\n ! Eprev2 = Eprev2\n Eprev1 = E\n E = (Eprev1 + Eprev2) / 2.d0\n ! yprev2 = yprev2\n yprev1 = y(Nx)\n end if\n end if\n end if\n\n looptime = looptime + 1\n end do\nend program main\n\nsubroutine Simpson(N, y, dx, ySquareSum)\n ! calculate the integral of the square of the wavefunction from -Xmax to Xmax with compound simpson formula\n\n implicit none\n integer :: N\n real(8), intent(in) :: y(N), dx\n real(8), intent(out) :: ySquareSum\n\n ! local vars\n integer :: i\n real(8) :: Work(N)\n\n if (mod(N,2) == 0) then\n ! Simpson does not work for integral of array with even number of elements\n write(*, *) 'Array with even elements, Simpson does not know how to work!'\n end if\n\n do i = 1,N\n Work(i) = y(i)**2\n end do\n\n ySquareSum = Work(1) + Work(N)\n do i = 2, N - 1, 2\n ySquareSum = ySquareSum + 4.d0 * Work(i)\n end do\n do i = 3, N - 2, 2\n ySquareSum = ySquareSum + 2.d0 * Work(i)\n end do\n ySquareSum = ySquareSum * dx / 3.d0\n\nend subroutine Simpson\n", "meta": {"hexsha": "7c155a4cc743433fbb00e08d5f361169b72d0f5d", "size": 4615, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Week-2-Assignment-1/Assignment/4-DoubleWell-Numerov.f90", "max_stars_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_stars_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-15T10:30:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T08:22:51.000Z", "max_issues_repo_path": "Week-2-Assignment-1/Assignment/4-DoubleWell-Numerov.f90", "max_issues_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_issues_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Week-2-Assignment-1/Assignment/4-DoubleWell-Numerov.f90", "max_forks_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_forks_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.1633986928, "max_line_length": 111, "alphanum_fraction": 0.4665222102, "num_tokens": 1471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771661, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7669590251372277}} {"text": "! This program will numerically compute the integral of\r\n! 4/(1+x*x) \r\n! from 0 to 1. The value of this integral is pi -- which \r\n! is great since it gives us an easy way to check the answer.\r\n\r\n! The program was parallelized using OpenMP by adding just\r\n! four lines \r\n\r\n! (1) A line to include omp.h -- the include file that \r\n! contains OpenMP's function prototypes and constants.\r\n \r\n! (2) A pragma that tells OpenMP to create a team of threads\r\n\r\n! (3) A pragma to cause one of the threads to print the\r\n! number of threads being used by the program.\r\n\r\n! (4) A pragma to split up loop iterations among the team\r\n! of threads. This pragma includes 2 clauses to (1) create a \r\n! private variable and (2) to cause the threads to compute their\r\n! sums locally and then combine their local sums into a \r\n! single global value.\r\n\r\n! History: C Code written by Tim Mattson, 11/1999.\r\n! Adapted to Fortran code by Helen He, 09/2017. \r\n! Changed to Fortran90 code by Helen He, 11/2020. \r\n\r\n PROGRAM MAIN\r\n USE OMP_LIB\r\n IMPLICIT NONE\r\n\r\n INTEGER :: i\r\n INTEGER*8 :: num_steps\r\n REAL*8 :: error \r\n INTEGER, PARAMETER :: NSTEPS=100000000\r\n REAL*8, PARAMETER :: REAL_PI = 3.1415926535897932\r\n REAL*8 :: x, pi, sum, step\r\n REAL*8 :: start_time, run_time\r\n\r\n CALL OMP_SET_NUM_THREADS(4)\r\n\r\n num_steps = 1\r\n DO WHILE (num_steps < NSTEPS) \r\n step = 1.0 / num_steps\r\n\r\n sum = 0.0\r\n!$OMP PARALLEL DO REDUCTION(+:sum) PRIVATE(x)\r\n DO i = 1, num_steps\r\n x = (i - 0.5) * step\r\n sum = sum + 4.0 / (1.0 + x*x)\r\n ENDDO\r\n!$OMP END PARALLEL DO\r\n\r\n pi = step * sum\r\n error = ABS(pi - REAL_PI)\r\n \r\n WRITE(*,100) 1.0*num_steps, pi, error\r\n100 FORMAT(f20.6, f15.8, e15.7)\r\n\r\n num_steps = 10 * num_steps\r\n ENDDO\r\n\r\n END PROGRAM MAIN\r\n", "meta": {"hexsha": "84357b5e21a9975a5d4e8868387ba38f47fd542f", "size": 1825, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Exercises/Fortran/solutions/pi_temp.f90", "max_stars_repo_name": "zafar-hussain/OmpCommonCore", "max_stars_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 37, "max_stars_repo_stars_event_min_datetime": "2020-04-21T18:05:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:10:18.000Z", "max_issues_repo_path": "Exercises/Fortran/solutions/pi_temp.f90", "max_issues_repo_name": "zafar-hussain/OmpCommonCore", "max_issues_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-12-09T19:42:54.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T21:27:04.000Z", "max_forks_repo_path": "Exercises/Fortran/solutions/pi_temp.f90", "max_forks_repo_name": "zafar-hussain/OmpCommonCore", "max_forks_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2020-09-05T18:54:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-23T02:19:12.000Z", "avg_line_length": 28.9682539683, "max_line_length": 65, "alphanum_fraction": 0.6317808219, "num_tokens": 547, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.8289388062084421, "lm_q1q2_score": 0.7669590161001626}} {"text": "! $UWHPSC/codes/fortran/circles/circle_mod.f90\n\nmodule circle_mod\n\n implicit none\n real(kind=8), parameter :: pi = 3.141592653589793d0\n\ncontains\n\n real(kind=8) function area(r)\n real(kind=8), intent(in) :: r\n area = pi * r**2\n end function area\n\n real(kind=8) function circumference(r)\n real(kind=8), intent(in) :: r\n circumference = 2.d0 * pi * r\n end function circumference\n\nend module circle_mod\n", "meta": {"hexsha": "5350a278150e9349c3bc949dd63a452f5516d157", "size": 445, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/codes/fortran/circles/circle_mod.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/codes/fortran/circles/circle_mod.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/codes/fortran/circles/circle_mod.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.1904761905, "max_line_length": 55, "alphanum_fraction": 0.6426966292, "num_tokens": 130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.7668843828546593}} {"text": "program poisson1D\n implicit none\n integer :: x, t, tMax, old, new, temp\n integer, parameter :: nx = 100\n real :: w0(0:2), w1(0:2), k, tau, omega, alpha, D, dx, c, uA, dt\n real :: u(0:nx), f(0:nx,0:2,2), feq(0:nx,0:2)\n old = 1\n new = 2\n\n ! weighting factors\n w0(0:2) = (/2./3.,1./6.,1./6./)\n w1(0:2) = (/0.0,0.5,0.5/)\n\n ! number of nodes and timesteps\n dx = 1.0/real(nx)\n c = 1.0\n dt = dx/c\n tMax = 1000000\n\n ! coefficient\n k = 27.79\n\n ! relaxation time\n tau = 1.0\n omega = 1.0/tau\n\n ! artificial diffusion coefficient\n alpha = 1./3.\n D = alpha*c**2*(0.5-tau)*dt\n\n !----------------------------------------------------\n\n ! initial condition\n u(0:nx) = 0.0\n u(0) = 1.0\n u(nx) = 1.0\n\n ! initialize to equilibrium\n f(0:nx,0,old) = (w0(0)-1.0)*u(0:nx)\n f(0:nx,1,old) = w0(1)*u(0:nx)\n f(0:nx,2,old) = w0(2)*u(0:nx)\n\n do t = 1, tMax\n\n ! macroscopic variable\n u(0:nx) = (f(0:nx,1,old)+f(0:nx,2,old))/(1.0-w0(0))\n\n ! equilibrium-\n feq(0:nx,0) = (w0(0)-1.0)*u(0:nx)\n feq(0:nx,1) = w0(1)*u(0:nx)\n feq(0:nx,2) = w0(2)*u(0:nx)\n\n ! streaming + collision\n f(0:nx,0,new) = (1-omega)*f(0:nx,0,old) + omega*feq(0:nx,0)\n f(1:nx,1,new) = (1-omega)*f(0:nx-1,1,old) + omega*feq(0:nx-1,1) + dt*D*w1(1)*k**2*u(0:nx-1)\n f(0:nx-1,2,new) = (1-omega)*f(1:nx,2,old) + omega*feq(1:nx,2) + dt*D*w1(2)*k**2*u(1:nx)\n\n ! boundaries\n f(0,1,new) = w0(1)*1.0 + (1-omega)*(f(1,1,new) - feq(1,1))\n f(nx,2,new) = w0(2)*1.0 + (1-omega)*(f(nx-1,2,new) - feq(nx-1,2))\n\n temp = old\n old = new\n new = temp\n\n end do\n\n open(10,file=\"results.dat\")\n\n do x = 0, nx\n write(10,*) x*dx, u(x), uA(real(x)*dx,k)\n end do\n\n close(10)\n\nend program\n\nfunction uA(x,k)\n implicit none\n real:: uA, x, k\n\n uA = (exp(k)-1.0)/(exp(k)-exp(-k))*exp(-k*x) + &\n & (1.0-exp(-k))/(exp(k)-exp(-k))*exp(k*x)\n\nend function uA\n", "meta": {"hexsha": "82d6f71e5ead1fab6006904efcb31b584c5a303a", "size": 2010, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "poisson_old.f90", "max_stars_repo_name": "myousefi2016/poisson_lbm", "max_stars_repo_head_hexsha": "de1e09893c5b257cc0bfe17912c4f1fe1f3d821b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-12-23T19:11:55.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-23T19:11:55.000Z", "max_issues_repo_path": "poisson_old.f90", "max_issues_repo_name": "myousefi2016/poisson_lbm", "max_issues_repo_head_hexsha": "de1e09893c5b257cc0bfe17912c4f1fe1f3d821b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "poisson_old.f90", "max_forks_repo_name": "myousefi2016/poisson_lbm", "max_forks_repo_head_hexsha": "de1e09893c5b257cc0bfe17912c4f1fe1f3d821b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.3720930233, "max_line_length": 101, "alphanum_fraction": 0.4631840796, "num_tokens": 916, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.766884370505681}} {"text": "program average\n\n! Read in some numbers and take the average\n! As written, if there are no data points, an average of zero is returned\n! While this may not be desired behavior, it keeps this example simple\n\n implicit none\n integer :: number_of_points\n real, dimension(:), allocatable :: points\n real :: average_points=0., positive_average=0., negative_average=0.\n\n write (*,*) \"Input number of points to average:\"\n read (*,*) number_of_points\n\n allocate (points(number_of_points))\n\n write (*,*) \"Enter the points to average:\"\n read (*,*) points\n\n! Take the average by summing points and dividing by number_of_points\n if (number_of_points > 0) average_points = sum(points)/number_of_points\n\n! Now form average over positive and negative points only\n if (count(points > 0.) > 0) positive_average = sum(points, points > 0.) &\n /count(points > 0.)\n if (count(points < 0.) > 0) negative_average = sum(points, points < 0.) &\n /count(points < 0.)\n\n deallocate (points)\n\n! Print result to terminal\n write (*,'(''Average = '', 1g12.4)') average_points\n write (*,'(''Average of positive points = '', 1g12.4)') positive_average\n write (*,'(''Average of negative points = '', 1g12.4)') negative_average\n\nend program average", "meta": {"hexsha": "e51d36b1d32d6eb45b49c3c1b0330dfe0a325160", "size": 1241, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/data/Fortran-2003/average.f90", "max_stars_repo_name": "jfitz/code-stat", "max_stars_repo_head_hexsha": "dd2a13177f3ef03ab42123ef3cfcbbd062a2ae26", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/data/Fortran-2003/average.f90", "max_issues_repo_name": "jfitz/code-stat", "max_issues_repo_head_hexsha": "dd2a13177f3ef03ab42123ef3cfcbbd062a2ae26", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/data/Fortran-2003/average.f90", "max_forks_repo_name": "jfitz/code-stat", "max_forks_repo_head_hexsha": "dd2a13177f3ef03ab42123ef3cfcbbd062a2ae26", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.4722222222, "max_line_length": 75, "alphanum_fraction": 0.6954069299, "num_tokens": 328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346511643776, "lm_q2_score": 0.8198933337131077, "lm_q1q2_score": 0.7668843696085417}} {"text": " FUNCTION dawson(x)\r\n INTEGER NMAX\r\n REAL dawson,x,H,A1,A2,A3\r\n PARAMETER (NMAX=6,H=0.4,A1=2./3.,A2=0.4,A3=2./7.)\r\n INTEGER i,init,n0\r\n REAL d1,d2,e1,e2,sum,x2,xp,xx,c(NMAX)\r\n SAVE init,c\r\n DATA init/0/\r\n if(init.eq.0)then\r\n init=1\r\n do 11 i=1,NMAX\r\n c(i)=exp(-((2.*float(i)-1.)*H)**2)\r\n11 continue\r\n endif\r\n if(abs(x).lt.0.2)then\r\n x2=x**2\r\n dawson=x*(1.-A1*x2*(1.-A2*x2*(1.-A3*x2)))\r\n else\r\n xx=abs(x)\r\n n0=2*nint(0.5*xx/H)\r\n xp=xx-float(n0)*H\r\n e1=exp(2.*xp*H)\r\n e2=e1**2\r\n d1=float(n0+1)\r\n d2=d1-2.\r\n sum=0.\r\n do 12 i=1,NMAX\r\n sum=sum+c(i)*(e1/d1+1./(d2*e1))\r\n d1=d1+2.\r\n d2=d2-2.\r\n e1=e2*e1\r\n12 continue\r\n dawson=0.5641895835*sign(exp(-xp**2),x)*sum\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "e30c72625f2133fb1646624ce46c80b5fbb393b3", "size": 907, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/dawson.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/dawson.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/dawson.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.5135135135, "max_line_length": 56, "alphanum_fraction": 0.434399118, "num_tokens": 362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632343454895, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7668516633175714}} {"text": "\r\n\r\nsubroutine CalcEnergy(Pos, PEnergy, Dim, NAtom)\r\n implicit none\r\n integer, intent(in) :: Dim, NAtom\r\n real(8), intent(in), dimension(0:NAtom-1, 0:Dim-1) :: Pos\r\n real(8), intent(out) :: PEnergy\r\n real(8), dimension(Dim) :: rij, Posi\r\n real(8) :: d2, id2, id6, id12\r\n real(8) :: alpha\r\n integer :: i, j\r\n !alpha varies with system size\r\n alpha = 0.0001 * dble(NAtom)**(-2./3.)\r\n PEnergy = 0.\r\n do i = 0, NAtom - 1\r\n !store Pos(i,:) in a temporary array for faster access in j loop\r\n Posi = Pos(i,:)\r\n do j = i + 1, NAtom - 1\r\n rij = Pos(j,:) - Posi\r\n d2 = sum(rij * rij)\r\n id2 = 1. / d2 !inverse squared distance\r\n id6 = id2 * id2 * id2 !inverse sixth distance\r\n id12 = id6 * id6 !inverse twelvth distance\r\n PEnergy = PEnergy + 4. * (id12 - id6)\r\n enddo\r\n !compute the single-body term\r\n PEnergy = PEnergy + alpha * sum(Posi * Posi)\r\n enddo\r\nend subroutine\r\n\r\n\r\nsubroutine CalcForces(Pos, Forces, Dim, NAtom)\r\n implicit none\r\n integer, intent(in) :: Dim, NAtom\r\n real(8), intent(in), dimension(0:NAtom-1, 0:Dim-1) :: Pos\r\n real(8), intent(out), dimension(0:NAtom-1, 0:Dim-1) :: Forces\r\n real(8), dimension(Dim) :: rij, Fij, Posi\r\n real(8) :: d2, id2, id6, id12\r\n real(8) :: alpha \r\n integer :: i, j\r\n !alpha varies with system size\r\n alpha = 0.0001 * dble(NAtom)**(-2./3.)\r\n Forces = 0.\r\n do i = 0, NAtom - 1\r\n !store Pos(i,:) in a temporary array for faster access in j loop\r\n Posi = Pos(i,:)\r\n do j = i + 1, NAtom - 1\r\n rij = Pos(j,:) - Posi\r\n d2 = sum(rij * rij)\r\n id2 = 1. / d2 !inverse squared distance\r\n id6 = id2 * id2 * id2 !inverse sixth distance\r\n id12 = id6 * id6 !inverse twelvth distance\r\n Fij = rij * ((-48. * id12 + 24. * id6) * id2)\r\n Forces(i,:) = Forces(i,:) + Fij\r\n Forces(j,:) = Forces(j,:) - Fij\r\n enddo\r\n !compute the single-body term\r\n Forces(i,:) = Forces(i,:) - 2. * alpha *Posi \r\n enddo\r\nend subroutine\r\n\r\n\r\nsubroutine CalcEnergyForces(Pos, PEnergy, Forces, Dim, NAtom)\r\n implicit none\r\n integer, intent(in) :: Dim, NAtom\r\n real(8), intent(in), dimension(0:NAtom-1, 0:Dim-1) :: Pos\r\n real(8), intent(out) :: PEnergy\r\n real(8), intent(out), dimension(0:NAtom-1, 0:Dim-1) :: Forces\r\n real(8), dimension(Dim) :: rij, Fij, Posi\r\n real(8) :: d2, id2, id6, id12\r\n real(8) :: alpha\r\n integer :: i, j\r\n !alpha varies with system size\r\n alpha = 0.0001 * dble(NAtom)**(-2./3.)\r\n PEnergy = 0.\r\n Forces = 0.\r\n do i = 0, NAtom - 1\r\n !store Pos(i,:) in a temporary array for faster access in j loop\r\n Posi = Pos(i,:)\r\n do j = i + 1, NAtom - 1\r\n rij = Pos(j,:) - Posi\r\n d2 = sum(rij * rij)\r\n id2 = 1. / d2 !inverse squared distance\r\n id6 = id2 * id2 * id2 !inverse sixth distance\r\n id12 = id6 * id6 !inverse twelvth distance\r\n PEnergy = PEnergy + 4. * (id12 - id6)\r\n Fij = rij * ((-48. * id12 + 24. * id6) * id2)\r\n Forces(i,:) = Forces(i,:) + Fij\r\n Forces(j,:) = Forces(j,:) - Fij\r\n enddo\r\n !compute the single-body term\r\n PEnergy = PEnergy + alpha * sum(Posi * Posi)\r\n Forces(i,:) = Forces(i,:) - 2. * alpha *Posi\r\n enddo\r\nend subroutine\r\n\r\n", "meta": {"hexsha": "0aa9160dd7af439926b7ed670df742e903eb7ede", "size": 3531, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uci-pharmsci/assignments/energy_minimization/emlib.f90", "max_stars_repo_name": "inferential/drug-computing", "max_stars_repo_head_hexsha": "25ff2f04b2a1f7cb71c552f62e722edb26cc297f", "max_stars_repo_licenses": ["CC-BY-4.0", "MIT"], "max_stars_count": 103, "max_stars_repo_stars_event_min_datetime": "2017-10-21T18:49:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T22:05:21.000Z", "max_issues_repo_path": "uci-pharmsci/assignments/energy_minimization/emlib.f90", "max_issues_repo_name": "inferential/drug-computing", "max_issues_repo_head_hexsha": "25ff2f04b2a1f7cb71c552f62e722edb26cc297f", "max_issues_repo_licenses": ["CC-BY-4.0", "MIT"], "max_issues_count": 29, "max_issues_repo_issues_event_min_datetime": "2017-10-23T20:57:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-15T21:57:09.000Z", "max_forks_repo_path": "uci-pharmsci/assignments/energy_minimization/emlib.f90", "max_forks_repo_name": "inferential/drug-computing", "max_forks_repo_head_hexsha": "25ff2f04b2a1f7cb71c552f62e722edb26cc297f", "max_forks_repo_licenses": ["CC-BY-4.0", "MIT"], "max_forks_count": 36, "max_forks_repo_forks_event_min_datetime": "2018-01-18T20:22:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T13:08:09.000Z", "avg_line_length": 36.4020618557, "max_line_length": 73, "alphanum_fraction": 0.507788162, "num_tokens": 1143, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632343454896, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7668516588754972}} {"text": "implicit real*4(a-h, o-z) ! The pppack is in single precision\r\n\r\nreal tau(201), c(4, 201)\r\nf(x) = exp(x)*sin(x)\r\nfderiv(x) = exp(x) * (sin(x) + cos(x))\r\nibcbeg = 2 ! Natural Cubic Spline\r\nibcend = 2\r\na = 0.0 ! Starting point\r\nb = 2.0 ! End point\r\n\r\nwrite(*,*) '-- Enter Number of SubIntervals --' ! ’ -- Enter Number of SubIntervals --’\r\n\r\nread(*,*) N\r\nh = (b-a)/N ! h is the length of the subinterval\r\n\r\ndo i = 1, N+1\r\n tau(i) = a + (i-1)*h\r\n c(1, i) = f(tau(i))\r\nenddo\r\n\r\nc(2,1) = 0.0 ! Natural Cubic Spline\r\nc(2,N+1) = 0.0 ! Natural Cubic Spline\r\ncall cubspl(tau, c, N, ibcbeg, ibcend)\r\n\r\n! Using the coefficient computed above, we actually\r\n! evaluate function values\r\n! at mid-points and compare with the exact values.\r\nk = 4\r\njderiv = 0 ! Compute the 0-th derivative, i.e,\r\n! The function values.\r\n\r\ndo i= 1, N-1\r\n x = a + (i+0.5)*h ! At the mid-point of the subintervals.\r\n y = f(x) ! The Exact Value\r\n y2 = ppvalu(tau, c, N, k, x, jderiv) ! Cubic Spline Value\r\n d = ABS(y2 - y)\r\n write(*,*) ' Value at x = ', x, y, y2 , d !’ Value at x = ’, x, y, y2\r\nenddo\r\n\r\nwrite(*,*) '-- Derivatives --' ! ’ -- Derivatives --’\r\n\r\nk = 4\r\njderiv = 1 ! Compute the 1-th derivative, i.e,\r\n! The first-derivative values.\r\ndo i= 1, N-1\r\n x = a + (i+0.5)*h ! At the mid-point of the subintervals.\r\n y = fderiv(x) ! The Exact Value\r\n y2 = ppvalu(tau, c, N, k, x, jderiv) ! Cubic Spline Value\r\n d = ABS(y2 - y)\r\n write(*,*) ' Value at x = ', x, y, y2 ,d !\r\nenddo\r\n\r\n\r\nread(*,*)\r\n\r\nstop\r\nend", "meta": {"hexsha": "f9e0fe6111c27664778eda92bfccb282dafaa526", "size": 1512, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Numerial_Analysis/3rd/a/3-1.f90", "max_stars_repo_name": "RDCPP/Numerial_Analysis_Backup", "max_stars_repo_head_hexsha": "a28501ec3505584cb3dce41404f28d357ba8039d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Numerial_Analysis/3rd/a/3-1.f90", "max_issues_repo_name": "RDCPP/Numerial_Analysis_Backup", "max_issues_repo_head_hexsha": "a28501ec3505584cb3dce41404f28d357ba8039d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Numerial_Analysis/3rd/a/3-1.f90", "max_forks_repo_name": "RDCPP/Numerial_Analysis_Backup", "max_forks_repo_head_hexsha": "a28501ec3505584cb3dce41404f28d357ba8039d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.5263157895, "max_line_length": 88, "alphanum_fraction": 0.5674603175, "num_tokens": 575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632247867717, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7668516511746865}} {"text": "*\n* squares - Print a table of squares from 1 to 10\n*\n* Written by: C. Severance 16Mar92\n*\n* Declare the variables:\n*\n INTEGER I\n REAL X,XSQ\n*\n* Generate the table using a DO LOOP\n*\n PRINT *,'The first table'\n DO I=1,10\n X = I\n XSQ = X ** 2\n PRINT *,I,XSQ\n ENDDO\n*\n* Print out the table a different way - Use a real number for the index\n*\n PRINT *,'The second table'\n DO X=1.0,10.0\n XSQ = X ** 2\n PRINT *,X,XSQ\n ENDDO\n END\n", "meta": {"hexsha": "2ebb9afc4f8bff72a5bf1e59ee74354e078511de", "size": 504, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "archive/2000-eecs280/examples/examples.ftn/programs/squares.f", "max_stars_repo_name": "yashajoshi/cc4e", "max_stars_repo_head_hexsha": "dd166f7e70d4111945054b8cb39483eb8dfb591b", "max_stars_repo_licenses": ["Apache-2.0", "CC-BY-4.0"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2020-01-05T04:46:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T09:36:02.000Z", "max_issues_repo_path": "archive/2000-eecs280/examples/examples.ftn/programs/squares.f", "max_issues_repo_name": "yashajoshi/cc4e", "max_issues_repo_head_hexsha": "dd166f7e70d4111945054b8cb39483eb8dfb591b", "max_issues_repo_licenses": ["Apache-2.0", "CC-BY-4.0"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2021-07-01T01:19:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-07T01:30:45.000Z", "max_forks_repo_path": "archive/2000-eecs280/examples/examples.ftn/programs/squares.f", "max_forks_repo_name": "yashajoshi/cc4e", "max_forks_repo_head_hexsha": "dd166f7e70d4111945054b8cb39483eb8dfb591b", "max_forks_repo_licenses": ["Apache-2.0", "CC-BY-4.0"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2020-12-27T19:57:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T13:01:36.000Z", "avg_line_length": 18.0, "max_line_length": 71, "alphanum_fraction": 0.5416666667, "num_tokens": 164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970904940926, "lm_q2_score": 0.8705972801594706, "lm_q1q2_score": 0.7668195513565321}} {"text": "subroutine poisson(n)\n! solves the poisson equation nabla^2 psi = -vort using the Jacobi method with successive over-relaxation (SOR)\n\n!Jacobi method: psi(i,j,n+1) = 1/4( psi(i-1,j,n) + psi(i+1,j,n) + psi(i,j-1,n) + psi(i,j+1,n) + vort(i,j) )\n! SOR: psi(n+1) = (1-w)*psi(n) + w*JacobiRHS\n\n! First, the grid is split up into a chessboard, depending on whether i+j is even or odd\n! Next the Jacobi SOR method is applied to even squares (using the odd squares to update even squares)\n! Then the Jacobi SOR method is applied to odd squares (using the updated values of the even squares)\n\n use vars\n use parallel\n implicit none\n\n integer :: n, it\n integer :: i, j\n\n real :: w !successive over-relaxation parameter\n\n w=1./(1+pi/nx_global) !optimal value of w\n\n\n\n do it=1,n\n !! old Jacobi method\n ! !$OMP DO PRIVATE(j)\n ! do j=0,ny+1\n ! psidum(:,j) = psi(:,j)\n ! enddo\n ! !$OMP END DO\n\n ! !$OMP DO PRIVATE(i,j)\n ! do j=1,ny\n ! do i=1,nx\n ! if (mask(i,j) .eq. 0) then\n ! psi(i,j) = (psidum(i-1,j) + psidum(i+1,j))*dy*dy &\n ! + (psidum(i,j-1)+psidum(i,j+1))*dx*dx +dx*dx*dy*dy*vort(i,j)\n ! psi(i,j) = psi(i,j)/2./(dx*dx+dy*dy)\n ! endif\n ! enddo\n ! enddo\n ! !$OMP END DO\n\n !update even squares\n !$OMP DO PRIVATE(i,j)\n do j=1,ny\n do i=1,nx\n if (mask(i,j) .eq. 0) then\n if (mod(i+j,2) .eq. 0) then\n psi(i,j) = (1-w)*psi(i,j) +w*( (psi(i-1,j) + psi(i+1,j))*dy*dy &\n + (psi(i,j-1)+psi(i,j+1))*dx*dx +dx*dx*dy*dy*vort(i,j) ) &\n /2./(dx*dx+dy*dy)\n endif\n endif\n enddo\n enddo\n !$OMP END DO\n\n !$OMP SINGLE\n call haloswap(psi)\n !$OMP END SINGLE\n !$OMP BARRIER\n\n !update odd squares\n !$OMP DO PRIVATE(i,j)\n do j=1,ny\n do i=1,nx\n if (mask(i,j) .eq. 0) then\n if (mod(i+j,2) .eq. 1) then\n psi(i,j) = (1-w)*psi(i,j) +w*( (psi(i-1,j) + psi(i+1,j))*dy*dy &\n + (psi(i,j-1)+psi(i,j+1))*dx*dx +dx*dx*dy*dy*vort(i,j) ) &\n /2./(dx*dx+dy*dy)\n endif\n endif\n enddo\n enddo\n !$OMP END DO\n\n !apply right boundary condition\n !$OMP DO PRIVATE(j)\n do j=1,ny\n psi(nx+1,j) = 2.*psi(nx,j) - psi(nx-1,j)\n enddo\n !$OMP END DO\n\n !$OMP SINGLE\n call haloswap(psi)\n !apply top/bottom boundary conditions\n if (down .eq. MPI_PROC_NULL) psi(:,0) = 2*psi(:,1) - psi(:,2)\n if (up .eq. MPI_PROC_NULL) psi(:,ny+1) = 2*psi(:,ny) - psi(:,ny-1)\n !$OMP END SINGLE\n !$OMP BARRIER\n\n enddo\n\n\nend subroutine\n", "meta": {"hexsha": "2d319b31534a455f8454913ee2c442ea9d5211ea", "size": 2994, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "windtunnel/simulation/poisson.f90", "max_stars_repo_name": "otbrown/wee_archie", "max_stars_repo_head_hexsha": "9dc86c74f54ce05ef2195e92dd914514bda8306b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-01-29T11:14:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-29T18:32:01.000Z", "max_issues_repo_path": "windtunnel/simulation/poisson.f90", "max_issues_repo_name": "otbrown/wee_archie", "max_issues_repo_head_hexsha": "9dc86c74f54ce05ef2195e92dd914514bda8306b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2019-02-18T15:18:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-11T23:57:45.000Z", "max_forks_repo_path": "windtunnel/simulation/poisson.f90", "max_forks_repo_name": "otbrown/wee_archie", "max_forks_repo_head_hexsha": "9dc86c74f54ce05ef2195e92dd914514bda8306b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-03-02T23:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-09T10:17:37.000Z", "avg_line_length": 30.5510204082, "max_line_length": 111, "alphanum_fraction": 0.4575818303, "num_tokens": 954, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475810629193, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7668164137306517}} {"text": "\nprogram multipole_moment\n use special_functions\n use numerical_integration\n integer, parameter :: num_theta_pts = 101, num_phi_pts = 101, num_r_pts = 101, lmax=4\n real(kind=dp) :: alp(num_theta_pts, 0:lmax,-lmax:lmax), theta_pts(num_theta_pts), dtheta, dphi\n real(kind=dp) :: fac, phi, r_pts(num_r_pts), rho_pts(num_r_pts), r_cutoff, dr, phi_pts(num_phi_pts)\n real(kind=dp) :: re_integral, im_integ, re_phi_integ(num_r_pts, num_theta_pts), re_theta_integ(num_r_pts)\n integer :: i, j, k, l, m, fact(2*lmax)\n complex(kind=dp) :: spha_ylm(num_theta_pts, num_phi_pts), integrand(num_r_pts, num_theta_pts, num_phi_pts)\n complex(kind=dp) :: integral\n\n\n dtheta = pi/(num_theta_pts-1)\n dphi = 2*pi/(num_phi_pts-1)\n theta_pts = [ (-pi/2 + i*dtheta, i=0, num_theta_pts-1) ]\n r_cutoff = 10.0d0\n dr = r_cutoff/(num_r_pts-1)\n r_pts = [ (i*dr, i=0, num_r_pts-1) ]\n phi_pts = [(i*dphi, i=0, num_phi_pts-1)]\n rho_pts= 1.0d0\n l=2\n m=0\n\n\n call calc_factorials(2*lmax, fact)\n call gen_assoc_legendre_pol(cos(theta_pts), num_theta_pts, lmax, alp)\n\n do i=0,num_phi_pts-1\n phi = i*dphi\n fac=dsqrt((2*l+1)*fact(l-m)/(4.0d0*pi*fact(l+m)))\n spha_ylm(:,i)=fac*alp(:,l,m)*cmplx(cos(m*phi),sin(m*phi))\n end do\n\n do i=1,num_r_pts\n do j=1,num_theta_pts\n do k=1,num_phi_pts\n integrand(i, j, k) = r_pts(i)**(l+2)*conjg(spha_ylm(j,k))*rho_pts(i)*sin(theta_pts(j))*dr*dtheta*dphi\n end do\n end do\n end do\n\n\n do i=1,num_r_pts\n do j=1,num_theta_pts\n re_phi_integ(i,j) = simpson(phi_pts, real(integrand(i,j,:)), num_phi_pts)\n end do\n re_theta_integ(i) = simpson(theta_pts, re_phi_integ(i, :), num_theta_pts)\n end do\n re_integral = simpson(r_pts, re_theta_integ(:), num_r_pts)\n\n print*, re_integral\n\n ! do i=1,num_theta_pts\n ! do j=1,num_phi_pts\n ! print '(5f10.4)', theta_pts(i), (j-1)*dphi, spha_ylm(i,j)%re, spha_ylm(i,j)%im, abs(spha_ylm(i, j))\n ! end do\n ! end do\nend program multipole_moment\n", "meta": {"hexsha": "70fdec12d73920b36aab179793c96ab69745d697", "size": 1961, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exercises/multipole_moment.f90", "max_stars_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_stars_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exercises/multipole_moment.f90", "max_issues_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_issues_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exercises/multipole_moment.f90", "max_forks_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_forks_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6833333333, "max_line_length": 113, "alphanum_fraction": 0.6690464049, "num_tokens": 736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475715065794, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7668164059626154}} {"text": "!=====================================================================!\n! Module that contains handy linear algebra operations using LAPACK.\n!=====================================================================!\n\nmodule linear_algebra\n \n ! import dependencies\n use iso_fortran_env, only : dp => REAL64\n \n use lapack, only: dsyevd, dsygvd, ilaenv, zgetri, zgetrf, zheevd, &\n dgeev , zgeev , zhegvd, dgesv , zgesv , dgetrf, &\n dgetri, dgelsy, zgelsy, dgesvd, zgesvd\n \n ! disable implicit datatypes\n implicit none\n\n ! restrict access to all functions\n private\n\n ! expose only a required functions\n public :: eig, eigvals, eigh ! eigenvals and vec\n public :: inv, solve, lstsq, svdvals, svd ! linear system\n public :: det, eye, diag, trace, triu !, tril ! matrix utils\n public :: assert, stop_error ! misc\n\n public :: fwdsub, backsub\n\n ! Classical Iterative solvers\n public :: dsor, djacobi, dseidel\n\n ! Sophisticated Iterative solvers\n public :: dcg, dpcg, dsd\n\n ! Solvers for non-symmetric systems\n public :: dcgnr, dcgne\n\n ! Module parameters \n complex(dp), parameter :: i_ = (0, 1)\n \n !===================================================================!\n ! Eigen interfaces\n !===================================================================!\n\n ! eigenvalue/-vector problem for general matrices:\n interface eig\n module procedure deig\n module procedure zeig\n end interface eig\n\n ! eigenvalue/-vector problem for real symmetric/complex hermitian\n ! matrices:\n interface eigh\n module procedure deigh_generalized\n module procedure deigh_simple\n module procedure zeigh_generalized\n module procedure zeigh_simple\n end interface eigh\n\n ! eigenvalues for general matrices:\n interface eigvals\n module procedure deigvals\n module procedure zeigvals\n end interface eigvals\n\n !===================================================================!\n ! Linear solve interfaces\n !===================================================================!\n\n ! matrix inversion for real/complex matrices:\n interface inv\n module procedure dinv\n module procedure zinv\n end interface inv\n\n ! solution to linear systems of equation with real/complex\n ! coefficients:\n interface solve\n module procedure dsolve\n module procedure zsolve\n end interface solve\n\n ! least square solutions the real/complex systems of equations of\n ! possibly non-square shape:\n interface lstsq\n module procedure dlstsq\n module procedure zlstsq\n end interface lstsq\n\n ! singular values of real/complex matrices:\n interface svdvals\n module procedure dsvdvals\n module procedure zsvdvals\n end interface svdvals\n\n ! singular value decomposition of real/complex matrices:\n interface svd\n module procedure dsvd\n module procedure zsvd\n end interface svd\n\n !===================================================================!\n ! Utility interfaces\n !===================================================================!\n \n ! determinants of real/complex square matrices:\n interface det\n module procedure ddet\n module procedure zdet\n end interface det\n\n ! construction of square matrices from the diagonal elements:\n interface diag\n module procedure ddiag\n module procedure zdiag\n !module procedure ddiagfrommat\n !module procedure zdiagfrommat\n end interface diag\n\n ! trace of real/complex matrices:\n interface trace\n module procedure dtrace\n module procedure ztrace\n end interface trace\n\n ! Upper triangular matrix\n interface triu\n module procedure dtriu \n end interface triu\n\n ! assert shape of matrices:\n interface assert_shape\n module procedure dassert_shape\n module procedure zassert_shape\n end interface assert_shape\n\ncontains\n\n !-------------------------------------------------------------------!\n ! Solve the linear system using conjugate gradient for minimum\n ! error\n ! -------------------------------------------------------------------!\n \n subroutine dcgne(A, b, max_it, max_tol, x, iter, tol, flag)\n\n real(dp), intent(in) :: A(:,:)\n real(dp), intent(in) :: b(:)\n integer , intent(in) :: max_it\n real(dp), intent(in) :: max_tol\n\n real(dp), intent(inout) :: x(:)\n integer , intent(out) :: iter\n real(dp), intent(out) :: tol\n integer , intent(out) :: flag\n\n ! Solve the new system AA^T y = b ; x = A^T y\n call dcg(matmul(A, transpose(A)), b, max_it, &\n & max_tol, x, iter, tol, flag)\n x = matmul(transpose(A), x)\n \n end subroutine dcgne\n \n !-------------------------------------------------------------------!\n ! Solve the linear system using conjugate gradient for minimum\n ! residual\n ! -------------------------------------------------------------------!\n \n subroutine dcgnr(A, b, max_it, max_tol, x, iter, tol, flag)\n\n real(dp), intent(in) :: A(:,:)\n real(dp), intent(in) :: b(:)\n integer , intent(in) :: max_it\n real(dp), intent(in) :: max_tol\n\n real(dp), intent(inout) :: x(:)\n integer , intent(out) :: iter\n real(dp), intent(out) :: tol\n integer , intent(out) :: flag\n\n ! Solve the new system A^T A x = A^T b\n call dcg(matmul(transpose(A),A), matmul(transpose(A),b), max_it, &\n & max_tol, x, iter, tol, flag)\n \n end subroutine dcgnr\n\n !-------------------------------------------------------------------!\n ! Solve the linear system using conjugate gradient method A A^T y = b\n !-------------------------------------------------------------------!\n \n subroutine dcg(A, b, max_it, max_tol, x, iter, tol, flag)\n\n real(dp), intent(in) :: A(:,:)\n real(dp), intent(in) :: b(:)\n integer , intent(in) :: max_it\n real(dp), intent(in) :: max_tol\n\n real(dp), intent(inout) :: x(:)\n integer , intent(out) :: iter\n real(dp), intent(out) :: tol\n integer , intent(out) :: flag\n\n ! create local data\n real(dp), allocatable :: p(:), r(:), w(:)\n real(dp), allocatable :: rho(:)\n real(dp) :: alpha, beta\n real(dp) :: bnorm, rnorm\n\n ! Memory allocations\n allocate(r, p, w, mold=x)\n allocate(rho(max_it))\n\n ! Start the iteration counter\n iter = 1\n\n ! Norm of the right hand side\n bnorm = norm2(b)\n\n ! Norm of the initial residual\n r = b - matmul(A, x)\n rnorm = norm2(r)\n tol = rnorm/bnorm\n rho(iter) = rnorm*rnorm\n\n open(10, file='cg.log', action='write', position='append')\n\n ! Apply Iterative scheme until tolerance is achieved\n do while ((tol .gt. max_tol) .and. (iter .lt. max_it))\n\n ! step (a) compute the descent direction\n if ( iter .eq. 1) then\n ! steepest descent direction p\n p = r\n else\n ! take a conjugate direction\n beta = rho(iter)/rho(iter-1)\n p = r + beta*p\n end if\n\n ! step (b) compute the solution update\n w = matmul(A,p)\n\n ! step (c) compute the step size for update\n alpha = rho(iter)/dot_product(p, w)\n\n ! step (d) Add dx to the old solution\n x = x + alpha*p\n\n ! step (e) compute the new residual\n r = r - alpha*w\n !r = b - matmul(A, x)\n\n ! step(f) update values before next iteration\n rnorm = norm2(r)\n tol = rnorm/bnorm\n\n write(10,*) iter, tol\n print *, iter, tol\n\n iter = iter + 1\n\n rho(iter) = rnorm*rnorm\n\n end do\n\n close(10)\n\n deallocate(r, p, w, rho)\n\n flag = 0\n\n end subroutine dcg\n\n !-------------------------------------------------------------------!\n ! Solve the linear system using preconditioned conjugate gradient\n ! method\n !-------------------------------------------------------------------!\n \n subroutine dpcg(A, M, b, max_it, max_tol, x, iter, tol, flag)\n\n real(dp), intent(in) :: A(:,:)\n real(dp), intent(in) :: M(:,:)\n real(dp), intent(in) :: b(:)\n integer , intent(in) :: max_it\n real(dp), intent(in) :: max_tol\n\n real(dp), intent(inout) :: x(:)\n integer , intent(out) :: iter\n real(dp), intent(out) :: tol\n integer , intent(out) :: flag\n\n ! create local data\n real(dp), allocatable :: p(:), r(:), w(:), z(:)\n real(dp), allocatable :: rho(:), tau(:)\n real(dp) :: alpha, beta\n real(dp) :: bnorm, rnorm\n\n ! Memory allocations\n allocate(r, p, w, z, mold=x)\n allocate(rho(max_it))\n allocate(tau(max_it))\n\n ! Start the iteration counter\n iter = 1\n\n ! Norm of the right hand side\n bnorm = norm2(b)\n\n ! Norm of the initial residual\n r = b - matmul(A, x)\n rnorm = norm2(r)\n tol = rnorm/bnorm\n rho(iter) = rnorm*rnorm\n\n open(10, file='pcg.log', action='write', position='append')\n\n ! Apply Iterative scheme until tolerance is achieved\n do while ((tol .gt. max_tol) .and. (iter .lt. max_it))\n ! step (a)\n z = matmul(M,r)\n\n ! step (b)\n tau(iter) = dot_product(z,r)\n\n ! step (c) compute the descent direction\n if ( iter .eq. 1) then\n ! steepest descent direction p\n beta = 0.0d0\n p = z\n else\n ! take a conjugate direction\n beta = tau(iter)/tau(iter-1)\n p = z + beta*p\n end if\n\n ! step (b) compute the solution update\n w = matmul(A,p)\n\n ! step (c) compute the step size for update\n alpha = tau(iter)/dot_product(p, w)\n\n ! step (d) Add dx to the old solution\n x = x + alpha*p\n\n ! step (e) compute the new residual\n r = r - alpha*w\n !r = b - matmul(A, x)\n\n ! step(f) update values before next iteration\n rnorm = norm2(r)\n tol = rnorm/bnorm\n\n write(10,*) iter, tol\n print *, iter, tol\n\n iter = iter + 1\n\n rho(iter) = rnorm*rnorm\n\n end do\n\n close(10)\n\n deallocate(r, p, w, rho, tau)\n\n flag = 0\n\n end subroutine dpcg\n\n\n !-------------------------------------------------------------------!\n ! Solve the linear system using conjugate gradient method\n !-------------------------------------------------------------------!\n \n subroutine dsd(A, b, max_it, max_tol, x, iter, tol, flag)\n\n real(dp), intent(in) :: A(:,:)\n real(dp), intent(in) :: b(:)\n integer , intent(in) :: max_it\n real(dp), intent(in) :: max_tol\n\n real(dp), intent(inout) :: x(:)\n integer , intent(out) :: iter\n real(dp), intent(out) :: tol\n integer , intent(out) :: flag\n\n ! create local data\n real(dp), allocatable :: r(:), w(:)\n real(dp), allocatable :: rho(:)\n real(dp) :: alpha, beta\n real(dp) :: bnorm, rnorm\n\n stop\n \n ! Memory allocations\n allocate(r, w, mold=x)\n allocate(rho(max_it))\n\n ! Start the iteration counter\n iter = 1\n\n ! Norm of the right hand side\n bnorm = norm2(b)\n\n ! Norm of the initial residual\n r = b - matmul(A, x)\n rnorm = norm2(r)\n tol = rnorm/bnorm\n rho(iter) = rnorm*rnorm\n\n open(10, file='sd.log', action='write', position='append')\n\n ! Apply Iterative scheme until tolerance is achieved\n do while ((tol .gt. max_tol) .and. (iter .lt. max_it))\n\n ! step (b) compute the solution update\n w = matmul(A,r)\n\n ! step (c) compute the step size for update using A-norm of the residual\n alpha = rho(iter)/dot_product(r, w)\n\n ! step (d) Add dx to the old solution\n x = x + alpha*w\n\n ! step (e) compute the new residual\n r = r - alpha*w\n !r = b - matmul(A, x)\n\n ! step(f) update values before next iteration\n rnorm = norm2(r)\n tol = rnorm/bnorm\n\n write(10,*) iter, tol\n print *, iter, tol\n\n iter = iter + 1\n\n rho(iter) = rnorm*rnorm\n\n end do\n\n close(10)\n\n deallocate(r, w, rho)\n\n flag = 0\n\n end subroutine dsd\n\n !-------------------------------------------------------------------!\n ! Solve the linear system using classical Jacobi iterations\n !-------------------------------------------------------------------!\n \n subroutine djacobi(A, b, max_it, max_tol, x, iter, tol, flag)\n\n real(dp), intent(in) :: A(:,:)\n real(dp), intent(in) :: b(:)\n integer , intent(in) :: max_it\n real(dp), intent(in) :: max_tol\n\n real(dp), intent(inout) :: x(:)\n integer , intent(out) :: iter\n real(dp), intent(out) :: tol\n integer , intent(out) :: flag\n\n real(dp), allocatable :: D(:,:), L(:,:), U(:,:)\n real(dp), allocatable :: c(:), xnew(:)\n real(dp):: init_norm\n integer :: nrows, ncols, i, j\n\n nrows = size(A(:,1))\n ncols = size(A(1,:))\n\n allocate(D, L, U, source=A)\n D = 0.0d0\n L = 0.0d0\n U = 0.0d0\n\n allocate(c(nrows),xnew(nrows))\n c = 0.0d0\n xnew = 0.0d0\n\n ! Split matrix A = D-L-U\n do j = 1, ncols\n do i = 1, nrows\n if (i .eq. j) then\n D(i,j) = A(i,j)\n else if (i .gt. j) then\n L(i,j) = -A(i,j)\n else\n U(i,j) = -A(i,j)\n end if\n end do\n end do\n\n ! Apply Iterative scheme until tolerance is achieved\n tol = huge(0.0d0)\n iter = 0\n\n open(10, file='jacobi.log', action='write',position='append')\n \n do while ((tol .gt. max_tol) .and. (iter .lt. max_it))\n \n !xnew = solve(D, b + matmul(L+U, x))\n ! Gauss Jacobi\n c = b + matmul(L+U, x)\n do i = 1, nrows\n xnew(i) = c(i)/D(i,i)\n end do\n !call backsub(D, c, xnew, flag)\n \n ! Compute norms and increment iteration\n tol = norm2(xnew-x)\n\n x = xnew\n\n write(10,*) iter, tol\n !print *, iter, tol\n \n iter = iter + 1\n \n end do\n \n close(10)\n \n flag = 0\n\n deallocate(D, L, U, c)\n\n end subroutine djacobi\n \n subroutine dseidel(A, b, omega, max_it, max_tol, x, iter, tol, flag)\n\n real(dp), intent(in) :: A(:,:)\n real(dp), intent(in) :: b(:)\n real(dp), intent(in) :: omega\n integer , intent(in) :: max_it\n real(dp), intent(in) :: max_tol\n\n real(dp), intent(inout) :: x(:)\n integer , intent(out) :: iter\n real(dp), intent(out) :: tol\n integer , intent(out) :: flag\n\n real(dp), allocatable :: D(:,:), L(:,:), U(:,:)\n real(dp), allocatable :: c(:), xnew(:)\n\n integer :: nrows, ncols, i, j\n\n nrows = size(A(:,1))\n ncols = size(A(1,:))\n\n allocate(D, L, U, source=A)\n D = 0.0d0\n L = 0.0d0\n U = 0.0d0\n\n allocate(c(nrows),xnew(nrows))\n c = 0.0d0\n xnew = 0.0d0\n\n ! Split matrix A = D - L - U\n do j = 1, ncols\n do i = 1, nrows\n if (i .eq. j) then\n D(i,j) = A(i,j)\n else if (i .gt. j) then\n L(i,j) = -A(i,j)\n else\n U(i,j) = -A(i,j)\n end if\n end do\n end do\n\n ! Apply Iterative scheme until tolerance is achieved\n tol = huge(0.0d0)\n iter = 0\n \n open(10, file='seidel.log', action='write',position='append')\n \n do while ((tol .gt. max_tol) .and. (iter .lt. max_it))\n\n ! Gauss Seidel/SOR Iteration\n c = b + matmul(U, x)\n call fwdsub(D-L, c, xnew, flag)\n\n ! Compute norms and increment iteration\n tol = norm2(xnew-x)\n\n x = xnew\n\n write(10,*) iter, tol\n \n !print *, iter, tol\n\n iter = iter + 1\n\n end do\n\n close(10)\n\n flag = 0\n\n deallocate(D, L, U, c)\n\n end subroutine dseidel\n\n subroutine dsor(A, b, omega, max_it, max_tol, x, iter, tol, flag)\n\n real(dp), intent(in) :: A(:,:)\n real(dp), intent(in) :: b(:)\n real(dp), intent(in) :: omega\n integer , intent(in) :: max_it\n real(dp), intent(in) :: max_tol\n\n real(dp), intent(inout) :: x(:)\n integer , intent(out) :: iter\n real(dp), intent(out) :: tol\n integer , intent(out) :: flag\n\n real(dp), allocatable :: D(:,:), L(:,:), U(:,:)\n real(dp), allocatable :: c(:), xnew(:)\n \n integer :: nrows, ncols, i, j\n\n nrows = size(A(:,1))\n ncols = size(A(1,:))\n\n allocate(D, L, U, source=A)\n D = 0.0d0\n L = 0.0d0\n U = 0.0d0\n\n allocate(c(nrows),xnew(nrows))\n c = 0.0d0\n xnew = 0.0d0\n\n ! Split matrix A = D - L - U\n do j = 1, ncols\n do i = 1, nrows\n if (i .eq. j) then\n D(i,j) = A(i,j)\n else if (i .gt. j) then\n L(i,j) = -A(i,j)\n else\n U(i,j) = -A(i,j)\n end if\n end do\n end do\n\n ! Apply Iterative scheme until tolerance is achieved\n tol = huge(0.0d0)\n iter = 0\n\n open(10, file='sor.log', action='write',position='append')\n \n do while ((tol .gt. max_tol) .and. (iter .lt. max_it))\n \n ! Gauss Seidel/SOR Iteration \n c = omega*b + matmul((1.0d0-omega)*D + omega*U, x)\n call fwdsub(D-omega*L, c, xnew, flag)\n\n ! Compute norms and increment iteration\n tol = norm2(xnew-x)\n\n x = xnew\n\n write(10, *) iter, tol\n !print *, iter, tol\n \n iter = iter + 1\n \n end do\n\n close(10)\n \n flag = 0\n\n deallocate(D, L, U, c)\n\n end subroutine dsor\n\n !-------------------------------------------------------------------!\n ! Get the eigenvalues and eigenvectors of a real matrix.\n !\n ! TODO: add optional switch for left or right eigenvectors in deig()\n ! and zeig()?\n ! -------------------------------------------------------------------!\n \n subroutine deig(A, lam, c)\n\n real(dp), intent(in) :: A(:,:) ! matrix for eigenvalue compuation\n complex(dp), intent(out) :: lam(:) ! eigenvalues: A c = lam c\n complex(dp), intent(out) :: c(:,:) ! eigenvectors: A c = lam c; c(i,j) = ith component of jth vec.\n\n ! LAPACK variables for DGEEV:\n real(dp), allocatable :: At(:,:), vl(:,: ), vr(:,:)\n real(dp), allocatable :: wi(:), work(:), wr(:)\n integer :: info, lda, ldvl, ldvr, lwork, n, i\n \n preprocess: block\n\n ! Determine the size of the linear system\n lda = size(A(:,1))\n n = size(A(1,:))\n call assert_shape(A, [n, n], \"solve\", \"A\")\n call assert_shape(c, [n, n], \"solve\", \"c\")\n ldvl = n\n ldvr = n\n lwork = 8*n ! TODO: can this size be optimized? query first?\n allocate(At(lda,n), wr(n), wi(n), vl(ldvl,n), vr(ldvr,n), work(lwork))\n At = A\n\n end block preprocess\n\n solve: block\n\n ! Call LAPACK to find the eigen values and vectors\n call dgeev('N', 'V', n, At, lda, wr, wi, vl, ldvl, vr, ldvr, &\n work, lwork, info)\n\n end block solve\n\n postprocess: block\n\n if (info .ne. 0) then\n print *, \"dgeev returned info = \", info\n if (info .lt. 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"the QR algorithm failed to compute all the\"\n print *, \"eigenvalues, and no eigenvectors have been computed;\"\n print *, \"elements \", info+1, \":\", n, \"of WR and WI contain eigenvalues which\"\n print *, \"have converged.\"\n end if\n call stop_error('eig: dgeev error')\n end if\n\n lam = wr + i_*wi\n ! As DGEEV has a rather complicated way of returning the\n ! eigenvectors, it is necessary to build the complex array of\n ! eigenvectors from two real arrays:\n do concurrent (i = 1: n)\n if (wi(i) > 0.0) then \n ! first of two conjugate eigenvalues\n c(:, i) = vr(:, i) + i_*vr(:, i+1)\n elseif (wi(i) < 0.0_dp) then\n ! second of two conjugate eigenvalues\n c(:, i) = vr(:, i-1) - i_*vr(:, i)\n else\n c(:, i) = vr(:, i)\n end if\n end do\n\n end block postprocess\n\n end subroutine deig\n\n !-------------------------------------------------------------------!\n ! Get the eigenvalues and eigenvectors of a complex matrix.\n !\n ! TODO: add optional switch for left or right eigenvectors in deig()\n ! and zeig()?\n !-------------------------------------------------------------------!\n \n subroutine zeig(A, lam, c)\n\n complex(dp), intent(in) :: A(:, :) ! matrix to solve eigenproblem for\n complex(dp), intent(out) :: lam(:) ! eigenvalues: A c = lam c\n complex(dp), intent(out) :: c(:,:) ! eigenvectors: A c = lam c;\n ! c(i,j) = ith component of\n ! jth vec.\n\n ! LAPACK variables: \n integer :: info, lda, ldvl, ldvr, lwork, n, lrwork \n real(dp), allocatable :: rwork(:) \n complex(dp), allocatable :: vl(:,:), vr(:,:), work(:)\n \n preprocess: block\n\n ! Determine the size of matrix\n lda = size(A(:,1))\n n = size(A(1,:))\n call assert_shape(A, [n, n], \"solve\", \"A\")\n call assert_shape(c, [n, n], \"solve\", \"c\")\n ldvl = n\n ldvr = n\n lwork = 8*n ! TODO: can this size be optimized? query first?\n lrwork = 2*n\n allocate(vl(ldvl,n), vr(ldvr,n), work(lwork), rwork(lrwork))\n c = A\n\n end block preprocess\n\n solve: block\n\n ! Find the eigen values\n call zgeev('N', 'V', n, c, lda, lam, vl, ldvl, vr, ldvr, work, &\n lwork, rwork, info)\n\n end block solve\n\n postprocess: block\n\n if (info .ne. 0) then\n print *, \"zgeev returned info = \", info\n if (info .lt. 0) then\n print *, \"the \",-info, \"-th argument had an illegal value.\"\n else\n print *, \"the QR algorithm failed to compute all the\"\n print *, \"eigenvalues, and no eigenvectors have been computed;\"\n print *, \"elements and \", info+1, \":\", n, \" of W contain eigenvalues which have\"\n print *, \"converged.\"\n end if\n call stop_error('eig: zgeev error')\n end if\n\n c = vr\n\n end block postprocess\n\n end subroutine zeig\n\n !-------------------------------------------------------------------!\n ! Returns the eigen values of the matrix\n !-------------------------------------------------------------------!\n \n function deigvals(A) result(lam)\n\n real(dp), intent(in) :: A(:, :) ! matrix for eigenvalue compuation\n complex(dp), allocatable :: lam(:) ! eigenvalues: A c = lam c\n \n ! LAPACK variables for DGEEV:\n real(dp), allocatable :: At(:,:), vl(:,: ), vr(:,:)\n real(dp), allocatable :: wi(:), work(:), wr(:)\n integer :: info, lda, ldvl, ldvr, lwork, n\n\n\n preprocess: block\n\n ! Determine the size of the matrix\n lda = size(A(:,1))\n n = size(A(1,:))\n call assert_shape(A, [n, n], \"solve\", \"A\")\n ldvl = n\n ldvr = n\n lwork = 8*n ! TODO: can this size be optimized? query first?\n allocate(At(lda,n), wr(n), wi(n), vl(ldvl,n), vr(ldvr,n), work(lwork), lam(n))\n At = A\n\n end block preprocess\n\n solve: block\n\n ! Determine the eigenvalues\n call dgeev('N', 'N', n, At, lda, wr, wi, vl, ldvl, vr, ldvr, &\n work, lwork, info)\n\n end block solve\n\n postprocess: block\n\n ! Post process\n if (info .ne. 0) then\n print *, \"dgeev returned info = \", info\n if (info .lt. 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"the QR algorithm failed to compute all the\"\n print *, \"eigenvalues, and no eigenvectors have been computed;\"\n print *, \"elements \", info+1, \":\", n, \"of WR and WI contain eigenvalues which\"\n print *, \"have converged.\"\n end if\n call stop_error('eigvals: dgeev error')\n end if\n\n lam = wr + i_*wi\n\n end block postprocess\n\n end function deigvals\n\n !===================================================================!\n ! Eigenvalues of a complex matrix\n !===================================================================!\n\n function zeigvals(A) result(lam)\n\n complex(dp), intent(in) :: A(:, :) ! matrix to solve eigenproblem for\n complex(dp), allocatable :: lam(:) ! eigenvalues: A c = lam c\n\n ! LAPACK variables:\n integer :: info, lda, ldvl, ldvr, lwork, n, lrwork\n real(dp), allocatable :: rwork(:)\n complex(dp), allocatable :: At(:,:), vl(:,:), vr(:,:), work(:)\n\n preprocess: block\n\n ! Determine the size of the matrix\n lda = size(A(:,1))\n n = size(A(1,:))\n call assert_shape(A, [n, n], \"solve\", \"A\")\n ldvl = n\n ldvr = n\n lwork = 8*n ! TODO: can this size be optimized? query first?\n lrwork = 2*n\n allocate(At(lda,n), &\n & vl(ldvl,n), vr(ldvr,n), &\n & work(lwork), rwork(lrwork), lam(n))\n At = A\n\n end block preprocess\n\n solve: block\n\n ! Determine the eigen values\n call zgeev('N', 'N', n, At, lda, lam, vl, ldvl, vr, ldvr, work, &\n lwork, rwork, info)\n\n end block solve\n\n postprocess: block\n\n ! Post process\n if (info .ne. 0) then\n print *, \"zgeev returned info = \", info\n if (info .lt. 0) then\n print *, \"the \",-info, \"-th argument had an illegal value.\"\n else\n print *, \"the QR algorithm failed to compute all the\"\n print *, \"eigenvalues, and no eigenvectors have been computed;\"\n print *, \"elements and \", info+1, \":\", n, \" of W contain eigenvalues which have\"\n print *, \"converged.\"\n end if\n call stop_error('eig: zgeev error')\n end if\n\n end block postprocess\n\n end function zeigvals\n\n !-------------------------------------------------------------------!\n ! Solves generalized eigen value problem for all eigenvalues and\n ! eigenvectors. Am must be symmetric and Bm symmetric positive\n ! definite. Only the lower triangular part of Am and Bm is used in\n ! computations.\n !-------------------------------------------------------------------!\n \n subroutine deigh_generalized(Am, Bm, lam, c)\n\n real(dp), intent(in) :: Am(:,:) ! LHS matrix: Am c = lam Bm c\n real(dp), intent(in) :: Bm(:,:) ! RHS matrix: Am c = lam Bm c\n real(dp), intent(out) :: lam(:) ! eigenvalues: Am c = lam Bm c\n real(dp), intent(out) :: c(:,:) ! eigenvectors: Am c = lam Bm c;\n ! c(i,j) = ith component of jth\n ! vec.\n integer :: n\n \n ! LLAPACK variables\n integer :: lwork, liwork, info\n integer, allocatable :: iwork(:)\n real(dp), allocatable :: Bmt(:,:), work(:)\n\n preprocess: block\n \n ! Matrix size\n n = size(Am,1)\n call assert_shape(Am, [n, n], \"eigh\", \"Am\")\n call assert_shape(Bm, [n, n], \"eigh\", \"B\")\n call assert_shape(c, [n, n], \"eigh\", \"c\")\n\n ! Determine the work size arrays\n lwork = 1 + 6*n + 2*n**2\n liwork = 3 + 5*n\n allocate(Bmt(n,n), work(lwork), iwork(liwork))\n c = Am; Bmt = Bm ! Bmt temporaries overwritten by dsygvd\n\n end block preprocess\n\n solve: block\n \n call dsygvd(1,'V','L',n,c,n,Bmt,n,lam,work,lwork,iwork,liwork,info)\n\n end block solve\n\n postprocess: block\n \n ! Post process\n if (info .ne. 0) then\n print *, \"dsygvd returned info =\", info\n if (info .lt. 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else if (info .le. n) then\n print *, \"the algorithm failed to compute an eigenvalue while working\"\n print *, \"on the submatrix lying in rows and columns\", 1.0_dp*info/(n+1)\n print *, \"through\", mod(info, n+1)\n else\n print *, \"The leading minor of order \", info-n, &\n \"of B is not positive definite. The factorization of B could \", &\n \"not be completed and no eigenvalues or eigenvectors were computed.\"\n end if\n call stop_error('eigh: dsygvd error')\n end if\n\n end block postprocess\n\n end subroutine deigh_generalized\n\n !-------------------------------------------------------------------!\n ! Solves eigenvalue problem for all eigenvalues and eigenvectors. Am\n ! must by symmetric. Only the lower triangular part of Am is used.\n !-------------------------------------------------------------------!\n \n subroutine deigh_simple(Am, lam, c)\n\n real(dp), intent(in) :: Am(:,:) ! LHS matrix: Am c = lam c\n real(dp), intent(out) :: lam(:) ! eigenvalues: Am c = lam c\n real(dp), intent(out) :: c(:,:) ! eigenvectors: Am c = lam c;\n ! c(i,j) = ith component of jth\n ! vec.\n integer :: n\n\n ! Lapack variables\n integer :: lwork, liwork, info\n integer, allocatable :: iwork(:)\n real(dp), allocatable :: work(:)\n \n preprocess: block\n\n ! Determine space\n n = size(Am,1)\n call assert_shape(Am, [n, n], \"eigh\", \"Am\")\n call assert_shape(c, [n, n], \"eigh\", \"c\")\n lwork = 1 + 6*n + 2*n**2\n liwork = 3 + 5*n\n allocate(work(lwork), iwork(liwork))\n c = Am\n\n end block preprocess\n\n solve: block\n\n ! Solve\n call dsyevd('V','L',n,c,n,lam,work,lwork,iwork,liwork,info)\n\n end block solve\n\n postprocess: block\n\n ! Post process\n if (info .ne. 0) then\n print *, \"dsyevd returned info =\", info\n if (info .lt. 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"the algorithm failed to compute an eigenvalue while working\"\n print *, \"on the submatrix lying in rows and columns\", 1.0_dp*info/(n+1)\n print *, \"through\", mod(info, n+1)\n end if\n call stop_error('eigh: dsyevd error')\n end if\n\n end block postprocess\n\n end subroutine deigh_simple\n\n !-------------------------------------------------------------------!\n ! Solves generalized eigen value problem for all eigenvalues and\n ! eigenvectors Am must by hermitian, Bm hermitian positive definite.\n ! Only the lower triangular part of Am and Bm is used.\n !-------------------------------------------------------------------!\n \n subroutine zeigh_generalized(Am, Bm, lam, c)\n\n complex(dp), intent(in) :: Am(:,:) ! LHS matrix: Am c = lam Bm c\n complex(dp), intent(in) :: Bm(:,:) ! RHS matrix: Am c = lam Bm c\n real(dp), intent(out) :: lam(:) ! eigenvalues: Am c = lam Bm c\n complex(dp), intent(out) :: c(:,:) ! eigenvectors: Am c = lam Bm c; c(i,j) = ith component of jth vec.\n\n ! LAPACK variables\n integer :: info, liwork, lrwork, lwork, n\n integer, allocatable :: iwork(:)\n real(dp), allocatable :: rwork(:)\n complex(dp), allocatable :: Bmt(:,:), work(:)\n\n preprocess: block\n \n ! Determine shape\n n = size(Am,1)\n call assert_shape(Am, [n, n], \"eigh\", \"Am\")\n call assert_shape(Bm, [n, n], \"eigh\", \"Bm\")\n call assert_shape(c, [n, n], \"eigh\", \"c\")\n lwork = 2*n + n**2\n lrwork = 1 + 5*N + 2*n**2\n liwork = 3 + 5*n\n allocate(Bmt(n,n), work(lwork), rwork(lrwork), iwork(liwork))\n c = Am; Bmt = Bm ! Bmt temporary overwritten by zhegvd\n\n end block preprocess\n \n solve: block\n \n ! Solve using lapack\n call zhegvd(1,'V','L',n,c,n,Bmt,n,lam,work,lwork,rwork,lrwork,iwork,liwork,info)\n\n end block solve\n\n postprocess: block\n\n ! Post process\n if (info .ne. 0) then\n print *, \"zhegvd returned info =\", info\n if (info .lt. 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else if (info .le. n) then\n print *, \"the algorithm failed to compute an eigenvalue while working\"\n print *, \"on the submatrix lying in rows and columns\", 1.0_dp*info/(n+1)\n print *, \"through\", mod(info, n+1)\n else\n print *, \"The leading minor of order \", info-n, &\n \"of B is not positive definite. The factorization of B could \", &\n \"not be completed and no eigenvalues or eigenvectors were computed.\"\n end if\n call stop_error('eigh: zhegvd error')\n end if\n \n end block postprocess\n\n end subroutine zeigh_generalized\n\n !-------------------------------------------------------------------!\n ! Solves eigenvalue problem for all eigenvalues and eigenvectors. Am\n ! must by symmetric Only the lower triangular part of Am is used.\n !-------------------------------------------------------------------!\n \n subroutine zeigh_simple(Am, lam, c)\n\n complex(dp), intent(in) :: Am(:,:) ! LHS matrix: Am c = lam c\n real(dp), intent(out) :: lam(:) ! eigenvalues: Am c = lam c\n complex(dp), intent(out) :: c(:,:) ! eigenvectors: Am c = lam c; c(i,j) = ith component of jth vec.\n\n ! LAPACK variables:\n integer :: info, lda, liwork, lrwork, lwork, n\n integer, allocatable :: iwork(:)\n real(dp), allocatable :: rwork(:)\n complex(dp), allocatable :: work(:)\n\n\n preprocess: block\n\n ! use LAPACK's zheevd routine\n n = size(Am, 1)\n call assert_shape(Am, [n, n], \"eigh\", \"Am\")\n call assert_shape(c, [n, n], \"eigh\", \"c\")\n lda = max(1, n)\n lwork = 2*n + n**2\n lrwork = 1 + 5*n + 2*n**2\n liwork = 3 + 5*n\n allocate(work(lwork), rwork(lrwork), iwork(liwork))\n c = Am\n\n end block preprocess\n\n solve: block\n\n ! Solve\n call zheevd(\"V\", \"L\", n, c, lda, lam, work, lwork, rwork, lrwork, &\n iwork, liwork, info)\n \n end block solve\n \n postprocess: block\n\n ! Post process\n if (info .ne. 0) then\n print *, \"zheevd returned info =\", info\n if (info .lt. 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"the algorithm failed to compute an eigenvalue while working\"\n print *, \"through the submatrix lying in rows and columns through\"\n print *, info/(n+1), \" through \", mod(info, n+1)\n end if\n call stop_error('eigh: zheevd error')\n end if\n\n end block postprocess\n\n end subroutine zeigh_simple\n\n !-------------------------------------------------------------------!\n ! Return the inverse of a real matrix\n !-------------------------------------------------------------------!\n \n function dinv(Am) result(Bm)\n \n real(dp), intent(in) :: Am(:,:) ! matrix to be inverted\n real(dp) :: Bm(size(Am, 1), size(Am, 2)) ! Bm = inv(Am)\n real(dp), allocatable :: Amt(:,:), work(:) ! temporary work arrays\n\n ! LAPACK variables:\n integer :: info, lda, n, lwork, nb\n integer, allocatable :: ipiv(:)\n\n ! use LAPACK's dgetrf and dgetri\n n = size(Am(1, :))\n call assert_shape(Am, [n, n], \"inv\", \"Am\")\n lda = n\n nb = ilaenv(1, 'DGETRI', \"UN\", n, -1, -1, -1) ! TODO: check UN param\n lwork = n*nb\n if (nb .lt. 1) nb = max(1, n)\n allocate(Amt(n,n), work(lwork), ipiv(n))\n Amt = Am\n\n ! Solve \n call dgetrf(n, n, Amt, lda, ipiv, info)\n\n ! Post process\n if (info .ne. 0) then\n print *, \"dgetrf returned info =\", info\n if (info .lt. 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"U(\", info, \",\", info, \") is exactly zero; The factorization\"\n print *, \"has been completed, but the factor U is exactly\"\n print *, \"singular, and division by zero will occur if it is used\"\n print *, \"to solve a system of equations.\"\n end if\n call stop_error('inv: dgetrf error')\n end if\n\n ! Solve\n call dgetri(n, Amt, n, ipiv, work, lwork, info)\n\n ! Post process\n if (info .ne. 0) then\n print *, \"dgetri returned info =\", info\n if (info .lt. 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"U(\", info, \",\", info, \") is exactly zero; the matrix is\"\n print *, \"singular and its inverse could not be computed.\"\n end if\n call stop_error('inv: dgetri error')\n end if\n\n ! Result\n Bm = Amt\n\n end function dinv\n\n !-------------------------------------------------------------------!\n ! Inverse of a complex matrix\n !-------------------------------------------------------------------!\n \n function zinv(Am) result(Bm)\n\n ! Inverts the general complex matrix Am\n complex(dp), intent(in) :: Am(:,:) ! Matrix to be inverted\n complex(dp) :: Bm(size(Am, 1), size(Am, 2)) ! Bm = inv(Am)\n integer :: n, nb\n\n ! LAPACK variables\n integer :: lwork, info\n complex(dp), allocatable :: Amt(:,:), work(:)\n integer, allocatable :: ipiv(:)\n\n ! Determine size\n n = size(Am, 1)\n call assert_shape(Am, [n, n], \"inv\", \"Am\")\n nb = ilaenv(1, 'ZGETRI', \"UN\", n, -1, -1, -1) ! TODO: check UN param\n if (nb .lt. 1) nb = max(1, n)\n lwork = n*nb\n allocate(Amt(n,n), ipiv(n), work(lwork))\n Amt = Am\n\n ! Solve\n call zgetrf(n, n, Amt, n, ipiv, info)\n\n ! Post process\n if (info .ne. 0) then\n print *, \"zgetrf returned info =\", info\n if (info .lt. 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"U(\", info, \",\", info, \") is exactly zero; The factorization\"\n print *, \"has been completed, but the factor U is exactly\"\n print *, \"singular, and division by zero will occur if it is used\"\n print *, \"to solve a system of equations.\"\n end if\n call stop_error('inv: zgetrf error')\n end if\n\n ! Solve\n call zgetri(n, Amt, n, ipiv, work, lwork, info)\n if (info .ne. 0) then\n print *, \"zgetri returned info =\", info\n if (info .lt. 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"U(\", info, \",\", info, \") is exactly zero; the matrix is\"\n print *, \"singular and its inverse could not be computed.\"\n end if\n call stop_error('inv: zgetri error')\n end if\n\n Bm = Amt\n\n end function zinv\n\n !-------------------------------------------------------------------!\n ! Solves a system of equations A x = b with one right hand side\n !-------------------------------------------------------------------!\n\n function dsolve(A, b) result(x)\n \n real(dp), intent(in) :: A(:,:) ! coefficient matrix A\n real(dp), intent(in) :: b(:) ! right-hand-side A x = b\n real(dp), allocatable :: x(:)\n\n ! LAPACK variables:\n real(dp), allocatable :: At(:,:), bt(:,:)\n integer :: n, info, lda\n integer, allocatable :: ipiv(:)\n \n preprocess: block\n\n ! Determine size\n n = size(A(1,:))\n lda = size(A(:, 1)) ! TODO: remove lda (which is = n!)\n call assert_shape(A, [n, n], \"solve\", \"A\")\n allocate(At(lda,n), bt(n,1), ipiv(n), x(n))\n At = A\n bt(:,1) = b(:)\n\n end block preprocess\n\n solve: block\n \n ! Solve the linear system\n call dgesv(n, 1, At, lda, ipiv, bt, n, info)\n\n end block solve\n\n postprocess: block\n\n ! Post process\n if (info .ne. 0) then\n print *, \"dgesv returned info =\", info\n if (info .lt. 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"U(\", info, \",\", info, \") is exactly zero; The factorization\"\n print *, \"has been completed, but the factor U is exactly\"\n print *, \"singular, so the solution could not be computed.\"\n end if\n call stop_error('inv: dgesv error')\n end if\n\n ! Store the result\n x = bt(:,1)\n\n end block postprocess\n\n end function dsolve\n\n !-------------------------------------------------------------------!\n ! Solves a system of equations A x = b with one right hand side\n !-------------------------------------------------------------------!\n \n function zsolve(A, b) result(x)\n \n complex(dp), intent(in) :: A(:,:) ! coefficient matrix A\n complex(dp), intent(in) :: b(:) ! right-hand-side A x = b\n complex(dp), allocatable :: x(:)\n\n ! LAPACK variables:\n complex(dp), allocatable :: At(:,:), bt(:,:)\n integer :: n, info, lda\n integer, allocatable :: ipiv(:)\n\n preprocess: block\n ! Determine size\n n = size(A(1,:))\n lda = size(A(:, 1)) ! TODO: remove lda here, too\n call assert_shape(A, [n, n], \"solve\", \"A\")\n allocate(At(lda,n), bt(n,1), ipiv(n), x(n))\n At = A\n bt(:,1) = b(:)\n end block preprocess\n \n solve: block\n ! Solve using LAPACK\n call zgesv(n, 1, At, lda, ipiv, bt, n, info)\n end block solve\n \n postprocess: block\n ! Post process\n if (info .ne. 0) then\n print *, \"zgesv returned info =\", info\n if (info .lt. 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"U(\", info, \",\", info, \") is exactly zero; The factorization\"\n print *, \"has been completed, but the factor U is exactly\"\n print *, \"singular, so the solution could not be computed.\"\n end if\n call stop_error('inv: zgesv error')\n end if\n\n ! Store the result\n x = bt(:,1)\n end block postprocess\n\n end function zsolve\n \n !-------------------------------------------------------------------!\n ! Generates a nxn identity matrix\n !-------------------------------------------------------------------!\n\n pure function eye(n)\n\n integer, intent(in) :: n\n real(dp) :: eye(n,n)\n integer :: i, j\n\n ! generate a zero matrix\n eye = 0.0_dp\n \n ! replace the diagonals with one\n forall(i=1:n)\n eye(i,i) = 1.0_dp\n end forall\n\n end function eye\n\n !-------------------------------------------------------------------!\n ! A function that returns the determinant value of the matrix. This\n ! computes the determinant of a REAL matrix using an LU\n ! factorization.\n !-------------------------------------------------------------------!\n \n real(dp) function ddet(A) result(x)\n \n real(dp), intent(in) :: A(:, :) \n integer :: i\n\n ! LAPACK variables:\n integer :: info, n\n integer, allocatable :: ipiv(:)\n real(dp), allocatable :: At(:,:)\n\n preprocess: block\n \n ! Determine the size of the linear system\n n = size(A(1,:))\n call assert_shape(A, [n, n], \"det\", \"A\")\n\n !allocate(At, source=A) ! not supported by compiler yet\n\n ! Make a copy of the matrix as the input is modified in LU\n ! decomposition\n allocate(At(n,n), ipiv(n))\n At = A\n\n end block preprocess\n\n solve: block\n \n ! LU decomposition on the temp matrix\n call dgetrf(n, n, At, n, ipiv, info)\n\n end block solve\n\n postprocess: block\n \n ! Check the LAPACK output flag for potential issues in solution\n if (info .ne. 0) then\n print *, \"dgetrf returned info =\", info\n if (info .lt. 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"U(\", info, \",\", info, \") is exactly zero; The factorization\"\n print *, \"has been completed, but the factor U is exactly\"\n print *, \"singular, and division by zero will occur if it is used\"\n print *, \"to solve a system of equations.\"\n end if\n call stop_error('det: dgetrf error')\n end if\n\n ! At now contains the LU of the factorization A = PLU as L has\n ! unit diagonal entries, the determinant can be computed from the\n ! product of U's diagonal entries. Additional sign changes\n ! stemming from the permutations P have to be taken into account\n ! as well.\n x = 1.0_dp\n do i = 1, n\n if (ipiv(i) .ne. i) then ! additional sign change\n x = -x*At(i,i)\n else\n x = x*At(i,i)\n end if\n end do\n\n end block postprocess\n\n end function ddet\n \n !-------------------------------------------------------------------!\n ! A function that returns the determinant value of the matrix. This\n ! computes the determinant of a COMPLEX matrix using an LU\n ! factorization.\n !-------------------------------------------------------------------!\n \n complex(dp) function zdet(A) result(x)\n \n complex(dp), intent(in) :: A(:, :)\n integer :: i\n\n ! LAPACK variables:\n integer :: info, n\n integer, allocatable :: ipiv(:)\n complex(dp), allocatable :: At(:,:)\n\n preprocess: block\n \n ! Determine the size of the linear system\n n = size(A(1,:))\n call assert_shape(A, [n, n], \"det\", \"A\")\n\n ! Make a copy of the matrix as the input is modified in LU\n ! decomposition\n allocate(At(n,n), ipiv(n))\n At = A\n\n end block preprocess\n\n solve: block\n \n ! LU decomposition on the temp matrix\n call zgetrf(n, n, At, n, ipiv, info)\n\n end block solve\n\n postprocess: block\n\n ! Check the LAPACK output flag for potential issues in solution\n if (info .ne. 0) then\n print *, \"zgetrf returned info =\", info\n if (info .lt. 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"U(\", info, \",\", info, \") is exactly zero; The factorization\"\n print *, \"has been completed, but the factor U is exactly\"\n print *, \"singular, and division by zero will occur if it is used\"\n print *, \"to solve a system of equations.\"\n end if\n call stop_error('inv: zgetrf error')\n end if\n\n ! Compute the determinant (see ddet for details)\n x = 1.0_dp + 0*i_\n do i = 1, n\n if (ipiv(i) .ne. i) then ! additional sign change\n x = -x*At(i,i)\n else\n x = x*At(i,i)\n end if\n end do\n\n end block postprocess\n\n end function zdet\n\n !-------------------------------------------------------------------!\n ! Compute least square solution to A x = b for real A, b\n !-------------------------------------------------------------------!\n\n function dlstsq(A, b) result(x)\n \n real(dp), intent(in) :: A(:,:), b(:)\n real(dp), allocatable :: x(:)\n\n ! LAPACK variables:\n integer :: info, ldb, lwork, m, n, rank\n real(dp) :: rcond\n real(dp), allocatable :: work(:), At(:,:), Bt(:,:)\n integer, allocatable :: jpvt(:)\n\n ! Handle allocations\n preprocess: block\n \n ! Determine the matrix size\n m = size(A(:,1)) ! = lda\n n = size(A(1,:))\n ldb = size(b)\n \n ! Determine the optimal workspace size\n allocate(x(n), At(m,n), Bt(ldb,1), jpvt(n), work(1))\n call dgelsy(m, n, 1, At, m, Bt, ldb, jpvt, rcond, rank, work, &\n -1, info) ! query optimal workspace size\n lwork = int(real(work(1)))\n deallocate(work)\n \n ! Allocate with optimal size\n allocate(work(lwork)) ! allocate with ideal size\n rcond = 0.0_dp\n jpvt(:) = 0\n Bt(:,1) = b(:) ! only one right-hand side\n At(:,:) = A(:,:)\n\n end block preprocess\n\n solve: block\n\n ! Call LAPACK for lease squares solution\n call dgelsy(m, n, 1, At, m, Bt, ldb, jpvt, rcond, rank, work, &\n lwork, info)\n\n end block solve\n\n postprocess: block\n \n ! Find any error code\n if (info .ne. 0) then\n print *, \"dgelsy returned info = \", info\n print *, \"the \", -info, \"-th argument had an illegal value\"\n call stop_error('lstsq: dgelsy error')\n end if\n \n ! Store the solution\n x(:) = Bt(1:n,1)\n\n end block postprocess\n\n end function dlstsq\n\n !-------------------------------------------------------------------!\n ! Compute least square solution to A x = b for complex A, b\n !-------------------------------------------------------------------!\n\n function zlstsq(A, b) result(x)\n\n complex(dp), intent(in) :: A(:,:), b(:)\n complex(dp), allocatable :: x(:)\n\n ! LAPACK variables:\n integer :: info, ldb, lwork, m, n, rank\n real(dp) :: rcond\n complex(dp), allocatable :: At(:,:), Bt(:,:), work(:)\n real(dp), allocatable :: rwork(:)\n integer, allocatable :: jpvt(:)\n\n preprocess: block\n \n ! Determine the matrix size\n m = size(A(:,1)) ! = lda\n n = size(A(1,:))\n ldb = size(b)\n\n ! Query optimal workspace size\n allocate(x(n), At(m,n), Bt(ldb,1), jpvt(n), work(1), rwork(2*n))\n call zgelsy(m, n, 1, At, m, Bt, ldb, jpvt, rcond, rank, work, &\n -1, rwork, info)\n lwork = int(real(work(1)))\n deallocate(work)\n\n ! Allocate the optimal (ideal) workspace size\n allocate(work(lwork)) \n rcond = 0.0_dp\n jpvt(:) = 0\n Bt(:,1) = b(:) ! only one right-hand side\n At(:,:) = A(:,:)\n\n end block preprocess\n\n solve: block\n \n ! Call LAPACK to solve the system\n call zgelsy(m, n, 1, At, m, Bt, ldb, jpvt, rcond, rank, work, &\n lwork, rwork, info)\n\n end block solve\n \n ! Post process\n postprocess: block\n\n if (info /= 0) then\n print *, \"zgelsy returned info = \", info\n print *, \"the \", -info, \"-th argument had an illegal value\"\n call stop_error('lstsq: zgelsy error')\n end if\n \n ! Store the results\n x(:) = Bt(1:n,1)\n\n end block postprocess\n\n end function zlstsq\n\n !-------------------------------------------------------------------!\n ! Construct real matrix from diagonal elements\n !-------------------------------------------------------------------!\n \n pure function ddiag(x) result(A)\n\n real(dp), intent(in) :: x(:)\n real(dp), allocatable :: A(:,:)\n integer :: i, n\n\n n = size(x)\n\n allocate(A(n,n))\n A = 0.0_dp\n\n forall(i=1:n) A(i,i) = x(i)\n\n end function ddiag\n\n !-------------------------------------------------------------------!\n ! Construct complex matrix from diagonal elements\n !-------------------------------------------------------------------!\n\n pure function zdiag(x) result(A)\n\n\n complex(dp), intent(in) :: x(:)\n complex(dp), allocatable :: A(:,:)\n integer :: i, n\n\n n = size(x)\n\n allocate(A(n,n))\n\n A = 0*i_\n\n forall(i=1:n) A(i,i) = x(i)\n\n end function zdiag\n\n !-------------------------------------------------------------------!\n ! Construct real matrix from upper triangular elements\n !-------------------------------------------------------------------!\n \n pure function dtriu(A) result(U)\n\n real(dp), intent(in) :: A(:,:)\n real(dp), allocatable :: U(:,:)\n integer :: i, j, n\n\n n = size(A(1,:))\n\n allocate(U(n,n))\n U = 0.0_dp\n\n do concurrent (i=1:n)\n U(i+1:n,i) = A(:,i)\n end do\n\n do i = 1, n\n do j = i, n\n U(j,i) = A(j,i)\n end do\n end do\n\n end function dtriu\n\n !-------------------------------------------------------------------!\n ! Return trace along the main diagonal of a real matrix\n !-------------------------------------------------------------------!\n\n pure real(dp) function dtrace(A) result(t)\n \n real(dp), intent(in) :: A(:,:)\n integer :: i\n\n t = 0.0_dp\n do i = 1, minval(shape(A))\n t = t + A(i,i)\n end do\n\n end function dtrace\n\n !-------------------------------------------------------------------!\n ! Return trace along the main diagonal of a real matrix\n !-------------------------------------------------------------------!\n\n pure complex(dp) function ztrace(A) result(t)\n\n complex(dp), intent(in) :: A(:,:)\n integer :: i\n\n t = 0*i_\n do i = 1, minval(shape(A))\n t = t + A(i,i)\n end do\n\n end function ztrace\n\n !-------------------------------------------------------------------!\n ! Find the singular values s_i of a real m x n matrix\n !-------------------------------------------------------------------!\n\n function dsvdvals(A) result(s)\n\n real(dp), intent(in) :: A(:,:)\n real(dp), allocatable :: s(:)\n\n ! LAPACK related:\n integer :: info, lwork, m, n\n real(dp), allocatable :: work(:), At(:,:)\n real(dp) :: u(1,1), vt(1,1) ! not used if only s is\n ! to be computed\n preprocess: block\n \n m = size(A(:,1)) ! = lda\n n = size(A(1,:))\n allocate(At(m,n), s(min(m,n)))\n At(:,:) = A(:, :) ! A is overwritten in dgesvd\n\n ! Query optimal lwork and allocate workspace: \n allocate(work(1))\n call dgesvd('N', 'N', m, n, At, m, s, u, 1, vt, 1, work, -1, info)\n lwork = int(real(work(1)))\n deallocate(work)\n allocate(work(lwork))\n\n end block preprocess\n\n solve: block\n \n ! Compute the singular value decomposition\n call dgesvd('N', 'N', m, n, At, m, s, u, 1, vt, 1, work, lwork, info)\n\n end block solve\n\n postprocess: block\n \n if (info .ne. 0) then\n print *, \"dgesvd returned info = \", info\n if (info .lt. 0) then\n print *, \"the \", -info, \"-th argument had an illegal value\"\n else\n print *, \"DBDSQR did not converge, there are \", info\n print *, \"superdiagonals of an intermediate bidiagonal form B\"\n print *, \"did not converge to zero. See the description of WORK\"\n print *, \"in DGESVD's man page for details.\"\n end if\n call stop_error('svdvals: dgesvd error')\n end if\n \n end block postprocess\n\n end function dsvdvals\n\n !-------------------------------------------------------------------!\n ! Find the singular values s_i of a complex m x n matrix\n !-------------------------------------------------------------------!\n \n function zsvdvals(A) result(s)\n\n complex(dp), intent(in) :: A(:,:)\n real(dp), allocatable :: s(:)\n\n ! LAPACK related:\n integer :: info, lwork, m, n, lrwork\n complex(dp), allocatable :: work(:), At(:,:)\n real(dp), allocatable :: rwork(:)\n complex(dp) :: u(1,1), vt(1,1) ! not used if only s is to be computed\n \n preprocess: block\n \n ! Determine size and allocate space\n m = size(A(:,1)) ! = lda\n n = size(A(1,:))\n lrwork = 5*min(m,n)\n allocate(At(m,n), s(min(m,n)), rwork(lrwork))\n At(:,:) = A(:,:) ! A is overwritten in zgesvd!\n \n ! Query optimal lwork and allocate workspace\n allocate(work(1))\n call zgesvd('N', 'N', m, n, At, m, s, u, 1, vt, 1, work, -1, rwork, info)\n lwork = int(real(work(1)))\n deallocate(work)\n allocate(work(lwork))\n\n end block preprocess\n\n solve: block\n\n ! Compute the singular value decomposition\n call zgesvd('N', 'N', m, n, At, m, s, u, 1, vt, 1, work, lwork, rwork, info)\n\n end block solve\n\n postprocess: block\n \n if (info .ne. 0) then\n print *, \"zgesvd returned info = \", info\n if (info .lt. 0) then\n print *, \"the \", -info, \"-th argument had an illegal value\"\n else\n print *, \"ZBDSQR did not converge, there are \", info\n print *, \"superdiagonals of an intermediate bidiagonal form B\"\n print *, \"did not converge to zero. See the description of RWORK\"\n print *, \"in ZGESVD's man page for details.\"\n end if\n call stop_error('svdvals: zgesvd error')\n end if\n\n end block postprocess\n\n end function zsvdvals\n\n !-------------------------------------------------------------------!\n ! compute the singular value decomposition A = U sigma V^T of a real\n ! m x n matrix A. U is m x m. V^T is n x n. s has size min(m, n) -->\n ! sigma matrix is (n x m) with sigma_ii = s_i\n ! -------------------------------------------------------------------!\n \n subroutine dsvd(A, s, U, Vtransp)\n\n real(dp), intent(in) :: A(:,:)\n real(dp), intent(out) :: s(:), U(:,:), Vtransp(:,:)\n\n ! LAPACK related:\n integer :: info, lwork, m, n, ldu\n real(dp), allocatable :: work(:), At(:,:)\n\n preallocate: block\n\n m = size(A(:,1)) ! = lda\n n = size(A(1,:))\n ldu = m\n allocate(At(m,n))\n At(:,:) = A(:,:) ! use a temporary as dgesvd destroys its input\n\n call assert_shape(U, [m, m], \"svd\", \"U\")\n call assert_shape(Vtransp, [n, n], \"svd\", \"Vtransp\")\n\n ! query optimal lwork and allocate workspace:\n allocate(work(1))\n call dgesvd('A', 'A', m, n, At, m, s, U, ldu, Vtransp, n, work, -1, info)\n lwork = int(real(work(1)))\n deallocate(work)\n allocate(work(lwork))\n\n end block preallocate\n\n solve: block\n\n call dgesvd('A', 'A', m, n, At, m, s, U, ldu, Vtransp, n, work, lwork, info)\n\n end block solve\n\n postprocess: block\n\n if (info /= 0) then\n print *, \"dgesvd returned info = \", info\n if (info < 0) then\n print *, \"the \", -info, \"-th argument had an illegal value\"\n else\n print *, \"DBDSQR did not converge, there are \", info\n print *, \"superdiagonals of an intermediate bidiagonal form B\"\n print *, \"did not converge to zero. See the description of WORK\"\n print *, \"in DGESVD's man page for details.\"\n end if\n call stop_error('svd: dgesvd error')\n end if\n\n end block postprocess\n\n end subroutine dsvd\n\n !-------------------------------------------------------------------!\n ! compute the singular value decomposition A = U sigma V^H of a\n ! complex m x m matrix A\n ! U is m x min(m, n)\n ! Vtransp is n x n\n ! sigma is m x n with with sigma_ii = s_i\n ! note that this routine returns V^H, not V!\n !-------------------------------------------------------------------!\n \n subroutine zsvd(A, s, U, Vtransp)\n\n complex(dp), intent(in) :: A(:,:)\n real(dp), intent(out) :: s(:)\n complex(dp), intent(out) :: U(:,:), Vtransp(:,:)\n\n ! LAPACK related:\n integer :: info, lwork, m, n, ldu, lrwork\n real(dp), allocatable :: rwork(:)\n complex(dp), allocatable :: work(:), At(:,:)\n\n ! TODO: check shapes here and in other routines?\n\n preprocess: block\n\n m = size(A(:,1)) ! = lda\n n = size(A(1,:))\n ldu = m\n lrwork = 5*min(m,n)\n allocate(rwork(lrwork), At(m,n))\n At(:,:) = A(:,:) ! use a temporary as zgesvd destroys its input\n\n call assert_shape(U, [m, m], \"svd\", \"U\")\n call assert_shape(Vtransp, [n, n], \"svd\", \"Vtransp\")\n\n ! query optimal lwork and allocate workspace:\n allocate(work(1))\n call zgesvd('A', 'A', m, n, At, m, s, U, ldu, Vtransp, n, work, -1,&\n rwork, info)\n lwork = int(real(work(1)))\n deallocate(work)\n allocate(work(lwork))\n\n end block preprocess\n\n solve: block\n\n call zgesvd('A', 'A', m, n, At, m, s, U, ldu, Vtransp, n, work, &\n lwork, rwork, info)\n\n end block solve\n\n postprocess: block\n\n if (info /= 0) then\n print *, \"zgesvd returned info = \", info\n if (info < 0) then\n print *, \"the \", -info, \"-th argument had an illegal value\"\n else\n print *, \"ZBDSQR did not converge, there are \", info\n print *, \"superdiagonals of an intermediate bidiagonal form B\"\n print *, \"did not converge to zero. See the description of WORK\"\n print *, \"in DGESVD's man page for details.\"\n end if\n call stop_error('svd: zgesvd error')\n end if\n\n end block postprocess\n\n end subroutine zsvd\n \n !-------------------------------------------------------------------!\n ! Make sure a given real matrix has a given shape\n !-------------------------------------------------------------------!\n\n subroutine dassert_shape(A, shap, routine, matname)\n\n real(dp), intent(in) :: A(:,:)\n integer, intent(in) :: shap(:)\n character(len=*) :: routine, matname\n\n if (any(shape(A) .ne. shap)) then\n print *, \"In routine \" // routine // \" matrix \" // matname // \" has illegal shape \", shape(A)\n print *, \"Shape should be \", shap\n call stop_error(\"Aborting due to illegal matrix operation\")\n end if\n\n end subroutine dassert_shape\n \n !-------------------------------------------------------------------!\n ! Make sure a given real matrix has a given shape\n !-------------------------------------------------------------------!\n \n subroutine zassert_shape(A, shap, routine, matname)\n \n complex(dp), intent(in) :: A(:,:)\n integer, intent(in) :: shap(:)\n character(len=*) :: routine, matname\n \n if (any(shape(A) .ne. shap)) then\n print *, \"In routine \" // routine // \" matrix \" // matname // \" has illegal shape \", shape(A)\n print *, \"Shape should be \", shap\n call stop_error(\"Aborting due to illegal matrix operation\")\n end if\n\n end subroutine zassert_shape\n \n !-------------------------------------------------------------------!\n ! Stop with an error message\n !-------------------------------------------------------------------!\n\n subroutine stop_error( message )\n\n character(len=*) :: message\n\n print *, message\n stop \n\n end subroutine stop_error\n\n !-------------------------------------------------------------------!\n ! Assert if the condition is not met (i.e. condition .eq. false)\n !-------------------------------------------------------------------!\n\n subroutine assert(condition)\n\n logical, intent(in) :: condition\n\n if (.not. condition) call stop_error(\"Assert failed.\")\n\n end subroutine assert\n \n !-------------------------------------------------------------------!\n ! Solve an upper triangular linear system using backward\n ! substitution procedure starting from the last equation.\n ! ------------------------------------------------------------------!\n \n subroutine backsub(U, b, x, flag)\n\n ! inputs and outputs\n real(dp), intent(in) :: U(:,:)\n real(dp), intent(in) :: b(:) \n real(dp), intent(inout) :: x(:)\n integer , intent(inout) :: flag \n\n ! local variables\n integer :: i, j, m, n\n\n ! zero result vector for safety\n x = 0.0d0\n\n ! Size of the system\n m = size(U(:,1))\n n = size(U(1,:))\n\n ! find the last variable\n if (abs(U(m,m)) .le. tiny(1.0d0)) then\n flag = -1\n return\n end if\n \n x(m) = b(m)/U(m,m)\n\n ! find the other unknowns\n rows: do i = m-1, 1, -1\n if (abs(U(i,i)) .le. tiny(1.0d0)) then\n flag = -1\n return\n else\n ! RHS - take the known values to RHS (columnwise sum)\n x(i) = b(i) - sum(U(i,i+1:n)*x(i+1:n))\n x(i) = x(i)/U(i,i)\n end if\n end do rows\n\n flag = 0\n\n end subroutine backsub\n\n !-------------------------------------------------------------------!\n ! Solve a lower triangular linear system using forward substitution\n ! procedure starting from the first equation.\n ! ------------------------------------------------------------------!\n \n pure subroutine fwdsub(L, b, x, flag)\n\n ! inputs and outputs\n real(dp), intent(in) :: L(:,:)\n real(dp), intent(in) :: b(:)\n real(dp), intent(inout) :: x(:)\n integer , intent(inout) :: flag \n\n ! local variables\n integer :: i, j, m, n\n\n ! zero result vector for safety\n x = 0.0d0\n\n ! Size of the system\n m = size(L(:,1))\n n = size(L(1,:))\n\n ! find the last variable\n if (abs(L(1,1)) .le. tiny(1.0d0)) then\n flag = -1\n return\n end if\n x(1) = b(1)/L(1,1)\n\n ! find the other unknowns\n rows: do i = 2, m\n if (abs(L(i,i)) .le. tiny(1.0d0)) then\n flag = -1\n return\n else\n ! RHS - take the known values to RHS (columnwise sum)\n x(i) = b(i) - sum(L(i,1:i-1)*x(1:i-1))\n x(i) = x(i)/L(i,i)\n end if\n end do rows\n\n flag = 0\n\n end subroutine fwdsub\n \nend module linear_algebra\n", "meta": {"hexsha": "cd244e66b427cb9ad22a80296f1ecaf5151b8951", "size": 63720, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/linear_algebra.f90", "max_stars_repo_name": "komahanb/math6644-iterative-methods", "max_stars_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-03-19T16:36:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-14T21:29:38.000Z", "max_issues_repo_path": "src/linear_algebra.f90", "max_issues_repo_name": "komahanb/math6644-iterative-methods", "max_issues_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/linear_algebra.f90", "max_forks_repo_name": "komahanb/math6644-iterative-methods", "max_forks_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-23T02:14:36.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-23T02:14:36.000Z", "avg_line_length": 28.9899909008, "max_line_length": 108, "alphanum_fraction": 0.4986974262, "num_tokens": 17384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475730993027, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.7668164051190248}} {"text": "subroutine f(u, r)\nimplicit none\n real(kind(0.d0)), intent(out) :: r\n real(kind(0.d0)), intent(in) :: u\n r = u*(1.d0-u)\nend subroutine f\n\nsubroutine fortran_logistic(N, dt, u)\n integer, intent(in) :: N\n real(kind(0.d0)), intent(in) :: dt\n real(kind(0.d0)), intent(out) :: u(N)\n \n integer :: i\n real(kind(0.d0)) :: temp\n \n u(1) = 1.d-5\n do i=1, N-1\n call f(u(i), temp)\n u(i+1) = u(i) + dt*temp\n end do\nend subroutine fortran_logistic\n\nprogram main\n\nreal(kind(0.d0)) :: start, finish, u(1000), dt\ninteger :: i, N\n\nN = 1000\ndt = 25.d0/1000.d0\n\ncall cpu_time(start)\n\ndo i = 1, 100000\n call fortran_logistic(N, dt, u)\nend do\n\ncall cpu_time(finish)\nprint '(f6.3)', (finish-start)*1000000/100000\nprint *, u(1000)\nend program\n", "meta": {"hexsha": "79ee91284900a5d5f5ba34066c46ccaeaa1c763e", "size": 740, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "61_dgl/dgl.f90", "max_stars_repo_name": "HackyHour/Wuerzburg", "max_stars_repo_head_hexsha": "cc331e37d1803e1a85f5a4ee9cc051d9481f996b", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2016-02-26T18:35:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-28T19:50:07.000Z", "max_issues_repo_path": "61_dgl/dgl.f90", "max_issues_repo_name": "HackyHour/Wuerzburg", "max_issues_repo_head_hexsha": "cc331e37d1803e1a85f5a4ee9cc051d9481f996b", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 34, "max_issues_repo_issues_event_min_datetime": "2015-10-28T19:10:48.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-26T14:50:14.000Z", "max_forks_repo_path": "61_dgl/dgl.f90", "max_forks_repo_name": "HackyHour/Wuerzburg", "max_forks_repo_head_hexsha": "cc331e37d1803e1a85f5a4ee9cc051d9481f996b", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2015-10-28T18:49:03.000Z", "max_forks_repo_forks_event_max_datetime": "2017-12-05T08:40:11.000Z", "avg_line_length": 18.0487804878, "max_line_length": 46, "alphanum_fraction": 0.6175675676, "num_tokens": 287, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273633016692236, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7666621729392521}} {"text": " SUBROUTINE shape1 (nnode ,deriv ,shape ,exisp,etasp )\r\n!********************************************************************\r\n!\r\n!*** calculates shape functions and their derivatives for 2d elements\r\n!\r\n!********************************************************************\r\n IMPLICIT NONE\r\n\r\n INTEGER (kind=4) nnode\r\n REAL (kind=8) deriv(nnode,2),shape(nnode),exisp,etasp\r\n\r\n REAL (kind=8) s,t,s2,t2,ss,tt,st,sst,stt,st2,stq,q2\r\n\r\n s = exisp\r\n t = etasp\r\n st = s*t\r\n\r\n\r\n IF(nnode == 4) THEN\r\n !*** shape functions for 4 noded element\r\n shape(1) = (1d0-s-t+st)/4d0\r\n shape(2) = (1d0+s-t-st)/4d0\r\n shape(3) = (1d0+s+t+st)/4d0\r\n shape(4) = (1d0-s+t-st)/4d0\r\n\r\n !*** and derivatives\r\n\r\n deriv(1,1) = (-1d0+t)/4d0\r\n deriv(2,1) = -deriv(1,1)\r\n deriv(3,1) = (1d0+t)/4d0\r\n deriv(4,1) = -deriv(3,1)\r\n deriv(1,2) = (-1d0+s)/4d0\r\n deriv(2,2) = (-1d0-s)/4d0\r\n deriv(3,2) = -deriv(2,2)\r\n deriv(4,2) = -deriv(1,2)\r\n\r\n ELSE\r\n\r\n s2 = s*2d0\r\n t2 = t*2d0\r\n ss = s*s\r\n tt = t*t\r\n sst = ss*t\r\n stt = st*t\r\n st2 = st*2d0\r\n\r\n\r\n IF (nnode == 8) THEN\r\n !*** shape functions for 8 noded element\r\n shape(1) = (-1d0+st+ss+tt-sst-stt)/4d0\r\n shape(2) = (-1d0-st+ss+tt-sst+stt)/4d0\r\n shape(3) = (-1d0+st+ss+tt+sst+stt)/4d0\r\n shape(4) = (-1d0-st+ss+tt+sst-stt)/4d0\r\n shape(5) = (1d0-t-ss+sst)/2d0\r\n shape(6) = (1d0+s-tt-stt)/2d0\r\n shape(7) = (1d0+t-ss-sst)/2d0\r\n shape(8) = (1d0-s-tt+stt)/2d0\r\n\r\n !*** and derivatives\r\n\r\n deriv(1,1) = (t+s2-st2-tt)/4d0\r\n deriv(2,1) = (-t+s2-st2+tt)/4d0\r\n deriv(3,1) = (t+s2+st2+tt)/4d0\r\n deriv(4,1) = (-t+s2+st2-tt)/4d0\r\n deriv(5,1) = -s+st\r\n deriv(6,1) = (1d0-tt)/2d0\r\n deriv(7,1) = -s-st\r\n deriv(8,1) = (-1d0+tt)/2d0\r\n deriv(1,2) = (s+t2-ss-st2)/4d0\r\n deriv(2,2) = (-s+t2-ss+st2)/4d0\r\n deriv(3,2) = (s+t2+ss+st2)/4d0\r\n deriv(4,2) = (-s+t2+ss-st2)/4d0\r\n deriv(5,2) = (-1d0+ss)/2d0\r\n deriv(6,2) = -t-st\r\n deriv(7,2) = (1d0-ss)/2d0\r\n deriv(8,2) = -t+st\r\n\r\n ELSE IF (nnode == 9) THEN\r\n\r\n ! *** shape functions for 9 noded element\r\n\r\n stq = st*st\r\n shape(1) = (st-stt-sst+stq)/4d0\r\n shape(2) = (-st+stt-sst+stq)/4d0\r\n shape(3) = (st+stt+sst+stq)/4d0\r\n shape(4) = (-st-stt+sst+stq)/4d0\r\n shape(5) = (-t+tt+sst-stq)/2d0\r\n shape(6) = (s-stt+ss-stq)/2d0\r\n shape(7) = (t+tt-sst-stq)/2d0\r\n shape(8) = (-s+stt+ss-stq)/2d0\r\n shape(9) = 1d0-tt-ss+stq\r\n\r\n ! *** and derivatives\r\n\r\n q2 = stt*2d0\r\n deriv(1,1) = (t-tt-st2+q2)/4d0\r\n deriv(2,1) = (-t+tt-st2+q2)/4d0\r\n deriv(3,1) = (t+tt+st2+q2)/4d0\r\n deriv(4,1) = (-t-tt+st2+q2)/4d0\r\n deriv(5,1) = st-stt\r\n deriv(6,1) = (1d0-tt+2d0*s-q2)/2d0\r\n deriv(7,1) = -st-stt\r\n deriv(8,1) = (-1d0+tt+2d0*s-q2)/2d0\r\n deriv(9,1) = -2.0*s+q2\r\n q2=sst*2.0\r\n deriv(1,2) = (s-st2-ss+q2)/4d0\r\n deriv(2,2) = (-s+st2-ss+q2)/4d0\r\n deriv(3,2) = (s+st2+ss+q2)/4d0\r\n deriv(4,2) = (-s-st2+ss+q2)/4d0\r\n deriv(5,2) = (-1d0+2d0*t+ss-q2)/2d0\r\n deriv(6,2) = -st-sst\r\n deriv(7,2) = (1d0+2d0*t-ss-q2)/2d0\r\n deriv(8,2) = st-sst\r\n deriv(9,2) = -2d0*t+q2\r\n\r\n END IF\r\n END IF\r\n RETURN\r\n END SUBROUTINE shape1\r\n", "meta": {"hexsha": "e79ae911001606e7e4591a6ba564d4533f3c0a0e", "size": 3694, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/auxil/shape1.f90", "max_stars_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_stars_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/auxil/shape1.f90", "max_issues_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_issues_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/auxil/shape1.f90", "max_forks_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_forks_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.7833333333, "max_line_length": 71, "alphanum_fraction": 0.4187872225, "num_tokens": 1559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915912, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7666529859880967}} {"text": "! *********************************************************************\r\n! * *\r\n! * function gamln *\r\n! * *\r\n! *********************************************************************\r\n! Single Precision Version 1.0\r\n! Written by Gordon A. Fenton, TUNS, Apr. 13, 1993\r\n!\r\n! PURPOSE returns the natural logarithm of the gamma function of the\r\n! supplied argument, z >= 0.\r\n!\r\n! This routine calculates the definite integral\r\n!\r\n! inf\r\n! gamma(z) = int t**(z-1)*exp(-t) dt\r\n! 0\r\n!\r\n! which is the Gamma function, for argument z >= 0, and returns ln(gamma(z)).\r\n! The method used is an approximation derived by Lanczos as presented by\r\n! Press etal. in \"Numerical Recipes in C\", page 167. This algorithm supposedly\r\n! has a error of less than 2.E-10. See also GAMMA.f which has a relative\r\n! error of less than 1.E-14 and is based on a series expansion and can handle\r\n! negative arguments.\r\n! Arguments are as follows;\r\n!\r\n! z non-negative real value for which the gamma function is desired.\r\n! (input)\r\n!\r\n! NOTES: 1) (MXFAC-1)! is the maximum integer factorial we can find without\r\n! overflowing\r\n! 2) the integer factorial values are stored in fac(i) for later\r\n! (efficient) use. The first 7 are set explicitly, ie fac(1-7) = \r\n! 0!, 1!, ..., 6!.\r\n! 3) set IDEBUG to 1 if you want overflow errors reported.\r\n!--------------------------------------------------------------------------\r\n real function gamln(z)\r\n parameter (IDEBUG = 1, MXFAC = 34)\r\n dimension cof(6), fac(MXFAC)\r\n data cof/76.180091730,-86.50532033,24.01409822, &\r\n -1.231739516, .120858003e-2,-.536382e-5/\r\n data stp/2.50662827465/, eps/0.119209e-06/\r\n data zero,half,one,fpf/0.,0.5,1.0,5.5/\r\n data nfac/7/\r\n data (fac(i),i=1,7)/1.,1.,2.,6.,24.,120.,720./\r\n\r\n 1 format(a,e13.6,a)\r\n\r\n if( z .lt. zero ) then\r\n if( IDEBUG .eq. 1 ) &\r\n write(0,1)'Negative argument (',z,') in GAMLN.'\r\n gamln = zero\r\n return\r\n endif\r\n!\t\t\t\t\tis z an integer?\r\n q = z*(one + eps)\r\n n = int( q )\r\n f = z - float(n)\r\n if( f .lt. q*eps .and. n .le. MXFAC ) then\r\n if( n .gt. nfac ) then\r\n do 10 i = nfac, n-1\r\n fac(i+1) = float(i)*fac(i)\r\n 10 continue\r\n nfac = n\r\n endif\r\n gamln = alog(fac(n))\r\n return\r\n endif\r\n!\t\t\t\t\tz is non-integer (or is a big integer)\r\n if( z .lt. one ) then\r\n x = z\r\n az = alog(z)\r\n else\r\n x = z - one\r\n az = zero\r\n endif\r\n tmp = x + fpf\r\n tmp = (x+half)*alog(tmp) - tmp\r\n ser = one\r\n do 20 j = 1, 6\r\n x = x + one\r\n ser = ser + cof(j)/x\r\n 20 continue\r\n gamln = tmp + alog(stp*ser) - az\r\n return\r\n end\r\n", "meta": {"hexsha": "0e3282c7ff3f32292250568ac8b380d81ee6b7e1", "size": 3151, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/gaf95/gamln.f95", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/gaf95/gamln.f95", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/gaf95/gamln.f95", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.6395348837, "max_line_length": 80, "alphanum_fraction": 0.4458901936, "num_tokens": 872, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533013520765, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7666529629970414}} {"text": "! Name: ARPIT KUMAR JAIN, Roll No: 180122009\nPROGRAM ChebyshevInterpolationExp\n IMPLICIT NONE\n REAL, PARAMETER :: pi = acos(-1.0)\n INTEGER:: n, k, j\n REAL:: Xk, TnX, X, Px\n REAL, DIMENSION(:), ALLOCATABLE:: C\n\n WRITE(*, fmt = '(/A)', ADVANCE = \"NO\") \"Enter Order of Interpolation Polynomial: \"\n READ(*, *) n\n ALLOCATE(C(0:n));\n\n WRITE(*, 10, ADVANCE = \"NO\") n\n 10 FORMAT(/, \"Enter the X value to find P\", i0, \"(X): \")\n READ(*, *) X\n\n Px = 0.0\n ! Calculating the coefficients and calculation of polynomial \n DO j = 0, n\n C(j) = 0.0\n DO k = 0, n\n Xk = cos(((2*k+1 )*pi)/(2*n+2))\n C(j) = C(j) + EXP(Xk) * TnX(xk, j)\n ENDDO\n IF(j .EQ. 0) THEN\n C(j) = C(j) * (1./(N+1))\n ELSE\n C(j) = C(j) * (2./(N+1))\n ENDIF\n Px = Px + C(j) * TnX(X, j)\n ENDDO\n\n WRITE(*, 11) X, Px\n 11 FORMAT(/,\"P(\", f0.3, \") = \", f0.8/)\n\nEND PROGRAM ChebyshevInterpolationExp\n\nFUNCTION TnX(x, n) \n IMPLICIT NONE\n REAL, PARAMETER :: pi = acos(-1.0) \n REAL:: x, TnX \n INTEGER:: n, i\n REAL, DIMENSION(0:n):: vector\n vector(0) = 1\n vector(1) = x \n IF(n .LE. 1) THEN \n TnX = vector(n)\n ELSE\n DO i = 1, n-1 \n vector(i+1) = 2.0*x*vector(i) - vector(i-1) \n ENDDO\n TnX = vector(n)\n ENDIF\n RETURN\nEND FUNCTION TnX", "meta": {"hexsha": "6adfcd95f99a9db092912248715c4c232b1398b8", "size": 1382, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Chebyshev/1.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Chebyshev/1.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chebyshev/1.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 25.1272727273, "max_line_length": 86, "alphanum_fraction": 0.489146165, "num_tokens": 529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658466, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7666065748789875}} {"text": " program fortran_newtons\n\n REAL :: x,v2,Psi,phi0,functionPhi\n REAL functionPhiF\n REAL functionPhiDeri\n\n x = 0.3\n v2 = 0.1\n Psi = 1.5\n phi0 = 3.0\n call functionPhiEval(x, v2, Psi, phi0, functionPhi)\n print *, functionPhi\n print *, 'function : ', functionPhiF(x, v2, Psi, phi0)\n end\n\n ! phi = phi0 - v2 * sin[2(phi-Psi)]\n ! we need y = x + v2 * sin[2(x-Psi)] - phi0 = 0, where x is phi.\n subroutine functionPhiEval(x, v2, Psi, phi0, functionPhi)\n implicit none\n real, intent(IN) :: x, v2, Psi, phi0\n real, intent(OUT) :: functionPhi\n\n functionPhi = ( x + v2*SIN(2*(x-Psi)) - phi0 ) \n\n end subroutine functionPhiEval\n\n FUNCTION functionPhiF(x, v2, Psi, phi0)\n REAL x, v2, Psi, phi0\n functionPhiF = ( x + v2*SIN(2*(x-Psi)) - phi0 )\n RETURN\n END FUNCTION\n\n FUNCTION functionPhiDeri(x, v2, Psi)\n REAL x, v2, Psi\n functionPhiDeri = ( 1 + v2*cos(2*(x-Psi))*2 )\n RETURN\n END FUNCTION\n\n\n\n\n", "meta": {"hexsha": "dbdedbd4364a896da6630f18e90c268408daaf13", "size": 1038, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "newtonsMethod/fortran/bk_fortran_newtons.f", "max_stars_repo_name": "tuos/ampt", "max_stars_repo_head_hexsha": "01ef59c55b7368b3dc34394312ec415e16a64f80", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-01-10T03:13:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-17T16:05:57.000Z", "max_issues_repo_path": "newtonsMethod/fortran/bk_fortran_newtons.f", "max_issues_repo_name": "tuos/ampt", "max_issues_repo_head_hexsha": "01ef59c55b7368b3dc34394312ec415e16a64f80", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-07-16T17:20:34.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-22T20:51:10.000Z", "max_forks_repo_path": "newtonsMethod/fortran/bk_fortran_newtons.f", "max_forks_repo_name": "tuos/ampt", "max_forks_repo_head_hexsha": "01ef59c55b7368b3dc34394312ec415e16a64f80", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-04-09T21:34:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T22:04:56.000Z", "avg_line_length": 24.7142857143, "max_line_length": 70, "alphanum_fraction": 0.5549132948, "num_tokens": 351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012762876286, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7665519905542102}} {"text": "!********************************************************************************\r\n!>\r\n! simulated annealing is a global optimization method that distinguishes\r\n! between different local optima. starting from an initial point, the\r\n! algorithm takes a step and the function is evaluated. when minimizing a\r\n! function, any downhill step is accepted and the process repeats from this\r\n! new point. an uphill step may be accepted. thus, it can escape from local\r\n! optima. this uphill decision is made by the metropolis criteria. as the\r\n! optimization process proceeds, the length of the steps decline and the\r\n! algorithm closes in on the global optimum. since the algorithm makes very\r\n! few assumptions regarding the function to be optimized, it is quite\r\n! robust with respect to non-quadratic surfaces. the degree of robustness\r\n! can be adjusted by the user. in fact, simulated annealing can be used as\r\n! a local optimizer for difficult functions.\r\n!\r\n!### Reference\r\n!\r\n! * corana et al., \"minimizing multimodal functions of continuous variables\r\n! with the \"simulated annealing\" algorithm\", september 1987\r\n! (vol. 13, no. 3, pp. 262-280),\r\n! acm transactions on mathematical software.\r\n! * goffe, ferrier and rogers, \"global optimization of statistical functions\r\n! with simulated annealing\", journal of econometrics, vol. 60, no. 1/2,\r\n! jan./feb. 1994, pp. 65-100.\r\n!\r\n!### History\r\n!\r\n! * based on reference by bill goffe : 1/22/94, version: 3.2\r\n! See: https://www.netlib.org/opt/simann.f\r\n! * modifications by alan miller : fortran 90 version - 2 october 2013\r\n! * Jacob Williams, 8/26/2019 : modernized Fortran\r\n!\r\n!### TODO\r\n! * input rand distributation option\r\n! * a way to specify that some variables are not to be changed... this could be part of the distributation\r\n! selection (a constant option). each variable can have a different distribution.\r\n! * get ideas from: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.basinhopping.html\r\n\r\n module simulated_annealing_module\r\n\r\n use iso_fortran_env, only: dp => real64, output_unit\r\n\r\n implicit none\r\n\r\n private\r\n\r\n !*******************************************************\r\n type,public :: simulated_annealing_type\r\n\r\n private\r\n\r\n integer :: n = 0 !! number of variables in the function to be optimized.\r\n logical :: maximize = .false. !! denotes whether the function should be maximized or minimized.\r\n !! a true value denotes maximization while a false value denotes\r\n !! minimization. intermediate output (see iprint) takes this into\r\n !! account.\r\n real(dp) :: eps = 1.0e-9_dp !! error tolerance for termination. if the final function\r\n !! values from the last neps temperatures differ from the\r\n !! corresponding value at the current temperature by less than\r\n !! eps and the final function value at the current temperature\r\n !! differs from the current optimal function value by less than\r\n !! eps, execution terminates and ier = 0 is returned.\r\n integer :: ns = 20 !! number of cycles. after ns function evaluations, each element of\r\n !! vm is adjusted according to the input `step_mode`\r\n !! the suggested value is 20.\r\n integer :: nt = 100 !! number of iterations before temperature reduction. after\r\n !! nt*ns function evaluations, temperature (t) is changed\r\n !! by the factor rt. value suggested by corana et al. is\r\n !! max(100, 5*n). see goffe et al. for further advice.\r\n integer :: neps = 4 !! number of final function values used to decide upon\r\n !! termination. see eps. suggested value is 4.\r\n integer :: maxevl = 10000 !! the maximum number of function evaluations. if it is\r\n !! exceeded, ier = 1.\r\n\r\n logical :: use_initial_guess = .true. !! if false, the initial guess is ignored and a\r\n !! random point in the bounds is used for the first\r\n !! function evaluation\r\n\r\n integer :: n_resets = 2 !! number of times to run the main loop (must be >=1)\r\n\r\n real(dp), dimension(:),allocatable :: lb !! the lower bound for the allowable solution variables.\r\n real(dp), dimension(:),allocatable :: ub !! the upper bound for the allowable solution variables.\r\n !! if the algorithm chooses x(i) < lb(i) or x(i) > ub(i),\r\n !! i = 1, n, a point is from inside is randomly selected. this\r\n !! this focuses the algorithm on the region inside ub and lb.\r\n !! unless the user wishes to concentrate the search to a particular\r\n !! region, ub and lb should be set to very large positive\r\n !! and negative values, respectively. note that the starting\r\n !! vector x should be inside this region. also note that lb and\r\n !! ub are fixed in position, while vm is centered on the last\r\n !! accepted trial set of variables that optimizes the function.\r\n real(dp), dimension(:),allocatable :: c !! vector that controls the step length adjustment. the suggested\r\n !! value for all elements is 2.0.\r\n integer :: iprint = 1 !! controls printing inside [[sa]]:\r\n !!\r\n !! * 0 - nothing printed.\r\n !! * 1 - function value for the starting value and\r\n !! summary results before each temperature\r\n !! reduction. this includes the optimal\r\n !! function value found so far, the total\r\n !! number of moves (broken up into uphill,\r\n !! downhill, accepted and rejected), the\r\n !! number of out of bounds trials, the\r\n !! number of new optima found at this\r\n !! temperature, the current optimal x and\r\n !! the step length vm. note that there are\r\n !! n*ns*nt function evalutations before each\r\n !! temperature reduction. finally, notice is\r\n !! is also given upon achieveing the termination\r\n !! criteria.\r\n !! * 2 - each new step length (vm), the current optimal\r\n !! x (xopt) and the current trial x (x). this\r\n !! gives the user some idea about how far x\r\n !! strays from xopt as well as how vm is adapting\r\n !! to the function.\r\n !! * 3 - each function evaluation, its acceptance or\r\n !! rejection and new optima. for many problems,\r\n !! this option will likely require a small tree\r\n !! if hard copy is used. this option is best\r\n !! used to learn about the algorithm. a small\r\n !! value for maxevl is thus recommended when\r\n !! using iprint = 3.\r\n !!\r\n !! suggested value: 1\r\n !! note: for a given value of iprint, the lower valued\r\n !! options (other than 0) are utilized.\r\n integer :: iseed1 = 1234 !! the first seed for the random number generator.\r\n integer :: iseed2 = 5678 !! the second seed for the random number generator.\r\n !! different values for iseed1 and iseed2 will lead\r\n !! to an entirely different sequence of trial points\r\n !! and decisions on downhill moves (when maximizing).\r\n !! see goffe et al. on how this can be used to test\r\n !! the results of [[sa]].\r\n integer :: step_mode = 1 !! how to vary `vm` after `ns` cycles.\r\n !!\r\n !! * 1 : original method: adjust vm so that approximately\r\n !! half of all evaluations are accepted\r\n !! * 2 : keep vm constant\r\n !! * 3 : adjust by a constant `vms` factor\r\n real(dp) :: vms = 0.1_dp !! for `step_mode=3`, the factor to adjust `vm`\r\n integer :: iunit = output_unit !! unit number for prints.\r\n\r\n procedure(sa_func),pointer :: fcn => null() !! the user's function\r\n\r\n contains\r\n\r\n private\r\n\r\n procedure,public :: initialize => initialize_sa\r\n procedure,public :: optimize => sa\r\n procedure,public :: destroy => destroy_sa\r\n\r\n procedure :: func\r\n procedure :: perturb_and_evaluate\r\n\r\n end type simulated_annealing_type\r\n !*******************************************************\r\n\r\n !*******************************************************\r\n abstract interface\r\n subroutine sa_func(me, x, f, istat)\r\n !! interface to function to be maximized/minimized\r\n import :: dp, simulated_annealing_type\r\n implicit none\r\n class(simulated_annealing_type),intent(inout) :: me\r\n real(dp),dimension(:),intent(in) :: x\r\n real(dp), intent(out) :: f\r\n integer, intent(out) :: istat !! status flag:\r\n !!\r\n !! * 0 : valid function evaluation\r\n !! * -1 : invalid function evaluation.\r\n !! try a different input vector.\r\n !! * -2 : stop the optimization process\r\n\r\n end subroutine sa_func\r\n end interface\r\n !*******************************************************\r\n\r\n public :: print_vector\r\n public :: dp\r\n\r\n contains\r\n!********************************************************************************\r\n\r\n!********************************************************************************\r\n!>\r\n! Destructor.\r\n\r\n subroutine destroy_sa(me)\r\n\r\n implicit none\r\n\r\n class(simulated_annealing_type),intent(out) :: me\r\n\r\n end subroutine destroy_sa\r\n!********************************************************************************\r\n\r\n!********************************************************************************\r\n!>\r\n! Initialize the class.\r\n!\r\n! See the definition of [[simulated_annealing_type]] for the options.\r\n! Any options not set here will use the default values in the type.\r\n\r\n subroutine initialize_sa(me,fcn,n,lb,ub,c,&\r\n maximize,eps,ns,nt,neps,maxevl,&\r\n iprint,iseed1,iseed2,step_mode,vms,iunit,&\r\n use_initial_guess,n_resets)\r\n\r\n implicit none\r\n\r\n class(simulated_annealing_type),intent(inout) :: me\r\n procedure(sa_func) :: fcn\r\n integer, intent(in) :: n\r\n real(dp), dimension(n), intent(in) :: lb\r\n real(dp), dimension(n), intent(in) :: ub\r\n real(dp), dimension(n), intent(in),optional :: c\r\n logical, intent(in),optional :: maximize\r\n real(dp), intent(in),optional :: eps\r\n integer, intent(in),optional :: ns\r\n integer, intent(in),optional :: nt\r\n integer, intent(in),optional :: neps\r\n integer, intent(in),optional :: maxevl\r\n integer, intent(in),optional :: iprint\r\n integer, intent(in),optional :: iseed1\r\n integer, intent(in),optional :: iseed2\r\n integer,intent(in),optional :: step_mode\r\n real(dp), intent(in), optional :: vms\r\n integer, intent(in), optional :: iunit\r\n logical, intent(in), optional :: use_initial_guess\r\n integer, intent(in), optional :: n_resets\r\n\r\n call me%destroy()\r\n\r\n me%fcn => fcn\r\n me%n = n\r\n me%lb = lb\r\n me%ub = ub\r\n\r\n ! check validity of bounds:\r\n if (any(me%lb > me%ub)) then\r\n error stop 'Error: at least one LB > UB.'\r\n end if\r\n\r\n allocate(me%c(n))\r\n if (present(c)) then\r\n me%c = c\r\n else\r\n me%c = 2.0_dp\r\n end if\r\n\r\n if (present(maximize) ) me%maximize = maximize\r\n if (present(eps) ) me%eps = eps\r\n if (present(ns) ) me%ns = ns\r\n if (present(nt) ) me%nt = nt\r\n if (present(neps) ) me%neps = neps\r\n if (present(maxevl) ) me%maxevl = maxevl\r\n if (present(iprint) ) me%iprint = iprint\r\n if (present(iseed1) ) me%iseed1 = iseed1\r\n if (present(iseed2) ) me%iseed2 = iseed2\r\n if (present(step_mode) ) me%step_mode = step_mode\r\n if (present(vms) ) me%vms = vms\r\n if (present(iunit) ) me%iunit = iunit\r\n if (present(use_initial_guess) ) me%use_initial_guess = use_initial_guess\r\n if (present(n_resets) ) me%n_resets = n_resets\r\n\r\n end subroutine initialize_sa\r\n!********************************************************************************\r\n\r\n!********************************************************************************\r\n!>\r\n! Continuous simulated annealing global optimization algorithm\r\n!\r\n!### Brief Overview\r\n!\r\n! sa tries to find the global optimum of an n dimensional function.\r\n! it moves both up and downhill and as the optimization process\r\n! proceeds, it focuses on the most promising area.\r\n!\r\n! to start, it randomly chooses a trial point within the step length\r\n! vm (a vector of length n) of the user selected starting point. the\r\n! function is evaluated at this trial point and its value is compared\r\n! to its value at the initial point.\r\n!\r\n! in a maximization problem, all uphill moves are accepted and the\r\n! algorithm continues from that trial point. downhill moves may be\r\n! accepted; the decision is made by the metropolis criteria. it uses t\r\n! (temperature) and the size of the downhill move in a probabilistic\r\n! manner. the smaller t and the size of the downhill move are, the more\r\n! likely that move will be accepted. if the trial is accepted, the\r\n! algorithm moves on from that point. if it is rejected, another point\r\n! is chosen instead for a trial evaluation.\r\n!\r\n! each element of vm periodically adjusted so that half of all\r\n! function evaluations in that direction are accepted.\r\n!\r\n! a fall in t is imposed upon the system with the rt variable by\r\n! t(i+1) = rt*t(i) where i is the ith iteration. thus, as t declines,\r\n! downhill moves are less likely to be accepted and the percentage of\r\n! rejections rise. given the scheme for the selection for vm, vm falls.\r\n! thus, as t declines, vm falls and sa focuses upon the most promising\r\n! area for optimization.\r\n!\r\n! the parameter t is crucial in using sa successfully. it influences\r\n! vm, the step length over which the algorithm searches for optima. for\r\n! a small initial t, the step length may be too small; thus not enough\r\n! of the function might be evaluated to find the global optima. the user\r\n! should carefully examine vm in the intermediate output (set iprint =\r\n! 1) to make sure that vm is appropriate. the relationship between the\r\n! initial temperature and the resulting step length is function\r\n! dependent.\r\n!\r\n! to determine the starting temperature that is consistent with\r\n! optimizing a function, it is worthwhile to run a trial run first. set\r\n! rt = 1.5 and t = 1.0. with rt > 1.0, the temperature increases and vm\r\n! rises as well. then select the t that produces a large enough vm.\r\n!\r\n!### Notes\r\n! * as far as possible, the parameters here have the same name as in\r\n! the description of the algorithm on pp. 266-8 of corana et al.\r\n! * the suggested input values generally come from corana et al. to\r\n! drastically reduce runtime, see goffe et al., pp. 90-1 for\r\n! suggestions on choosing the appropriate rt and nt.\r\n!\r\n!### History\r\n! * differences compared to version 2.0:\r\n! 1. if a trial is out of bounds, a point is randomly selected\r\n! from lb(i) to ub(i). unlike in version 2.0, this trial is\r\n! evaluated and is counted in acceptances and rejections.\r\n! all corresponding documentation was changed as well.\r\n! * differences compared to version 3.0:\r\n! 1. if vm(i) > (ub(i) - lb(i)), vm is set to ub(i) - lb(i).\r\n! the idea is that if t is high relative to lb & ub, most\r\n! points will be accepted, causing vm to rise. but, in this\r\n! situation, vm has little meaning; particularly if vm is\r\n! larger than the acceptable region. setting vm to this size\r\n! still allows all parts of the allowable region to be selected.\r\n! * differences compared to version 3.1:\r\n! 1. test made to see if the initial temperature is positive.\r\n! 2. write statements prettied up.\r\n! 3. references to paper updated.\r\n\r\n subroutine sa(me, x, rt, t, vm, xopt, fopt, nacc, nfcnev, ier)\r\n\r\n implicit none\r\n\r\n class(simulated_annealing_type),intent(inout) :: me\r\n real(dp), dimension(me%n), intent(inout) :: x !! on input: the starting values for the variables of the\r\n !! function to be optimized. [Will be replaced by final point]\r\n real(dp), intent(in) :: rt !! the temperature reduction factor. the value suggested by\r\n !! corana et al. is .85. see goffe et al. for more advice.\r\n real(dp), intent(inout) :: t !! on input, the initial temperature. see goffe et al. for advice.\r\n !! on output, the final temperature. Note that if `t=0`, then\r\n !! all downhill steps will be rejected\r\n real(dp), dimension(me%n), intent(inout) :: vm !! the step length vector. on input it should encompass the region of\r\n !! interest given the starting value x. for point x(i), the next\r\n !! trial point is selected is from x(i) - vm(i) to x(i) + vm(i).\r\n !! since vm is adjusted so that about half of all points are accepted,\r\n !! the input value is not very important (i.e. is the value is off,\r\n !! sa adjusts vm to the correct value).\r\n real(dp), dimension(me%n), intent(out) :: xopt !! the variables that optimize the function.\r\n real(dp), intent(out) :: fopt !! the optimal value of the function.\r\n integer, intent(out) :: nacc !! the number of accepted function evaluations.\r\n integer, intent(out) :: nfcnev !! the total number of function evaluations. in a minor\r\n !! point, note that the first evaluation is not used in the\r\n !! core of the algorithm; it simply initializes the\r\n !! algorithm.\r\n integer, intent(out) :: ier !! the error return number:\r\n !!\r\n !! * 0 - normal return; termination criteria achieved.\r\n !! * 1 - number of function evaluations (nfcnev) is\r\n !! greater than the maximum number (maxevl).\r\n !! * 3 - the initial temperature is not positive.\r\n !! * 4 - user stop in problem function.\r\n !! * 99 - should not be seen; only used internally.\r\n\r\n real(dp),dimension(me%n) :: xp !! perturbed `x` vector\r\n real(dp),dimension(me%neps) :: fstar !! array of optimals found so far\r\n real(dp) :: f !! function value\r\n real(dp) :: fp !! function value\r\n real(dp) :: p !! for metropolis criteria\r\n real(dp) :: pp !! for metropolis criteria\r\n real(dp) :: ratio !! ratio of `nacp` to `ns`\r\n integer :: nup !! number of uphill steps\r\n integer :: ndown !! number of accepted downhill steps\r\n integer :: nrej !! number of rejected downhill steps\r\n integer :: nnew !! new optimal for this temperature\r\n integer :: i, j, m, k !! counter\r\n integer :: totmov !! total moves\r\n integer :: nacp !! number of accepts steps in a complete `ns` cycle\r\n logical :: quit !! if the termination criteria was achieved\r\n integer :: unit !! unit for printing\r\n real(dp) :: t_original !! original input value of `t`\r\n real(dp),dimension(me%n) :: vm_original !! original input value of `vm`\r\n logical :: first\r\n\r\n ! initialize:\r\n unit = me%iunit\r\n nfcnev = 0\r\n ier = 99\r\n xopt = x\r\n fopt = huge(1.0_dp)\r\n vm = abs(vm)\r\n t_original = t\r\n vm_original = vm\r\n\r\n ! if the initial temperature is not positive, notify the user and\r\n ! return to the calling routine.\r\n if (t < 0.0_dp) then\r\n if (me%iprint>0) write(unit,'(A)') 'Error: The initial temperature must be non-negative.'\r\n ier = 3\r\n return\r\n end if\r\n\r\n ! if the initial value is out of bounds, then just put\r\n ! the violated ones on the nearest bound.\r\n where (x > me%ub)\r\n x = me%ub\r\n else where (x < me%lb)\r\n x = me%lb\r\n end where\r\n\r\n ! initialize the random number generator\r\n call rand_init(me%iseed1,me%iseed2)\r\n\r\n ! evaluate the function with input x and return value as f.\r\n ! keep trying if necessary until there is a valid function\r\n ! evaluation.\r\n call me%perturb_and_evaluate(x,vm,xp,f,nfcnev,ier,first=.true.)\r\n select case (ier)\r\n case(1,4)\r\n return\r\n end select\r\n\r\n f = me%func(f)\r\n xopt = xp ! it may have been perturbed above\r\n fopt = f\r\n if (me%iprint >= 1) then\r\n write(unit, '(A)') ' '\r\n call print_vector(unit,xp,me%n,'initial x')\r\n write(unit, '(A,1X,G25.18)') ' initial f: ', me%func(f)\r\n end if\r\n\r\n reset: do k = 1, me%n_resets\r\n\r\n if (me%iprint >= 1) then\r\n write(unit,'(A)') ''\r\n write(unit,'(A)') '=========================================='\r\n write(unit,'(A,1X,I5)') ' main loop ', k\r\n write(unit,'(A)') '=========================================='\r\n write(unit,'(A)') ''\r\n end if\r\n\r\n ! restart the main loop\r\n fstar = huge(1.0_dp)\r\n t = t_original\r\n vm = vm_original\r\n nacc = 0\r\n nacp = 0\r\n\r\n ! the first function eval for a new main cycle\r\n first = k > 1\r\n\r\n main : do\r\n ! start the main loop. note that it terminates if (i) the algorithm\r\n ! succesfully optimizes the function or (ii) there are too many\r\n ! function evaluations (more than maxevl).\r\n nup = 0\r\n nrej = 0\r\n nnew = 0\r\n ndown = 0\r\n\r\n nt_loop : do m = 1, me%nt\r\n ns_loop : do j = 1, me%ns\r\n\r\n ! evaluate the function with the trial point xp and return as fp.\r\n call me%perturb_and_evaluate(x,vm,xp,fp,nfcnev,ier,first=first)\r\n first = .false.\r\n select case (ier)\r\n case(1,4)\r\n x = xopt\r\n fopt = me%func(fopt)\r\n return\r\n end select\r\n\r\n fp = me%func(fp)\r\n if (me%iprint >= 3) then\r\n write(unit,'(A)') ' '\r\n call print_vector(unit,x,me%n,'current x')\r\n write(unit,'(A,G25.18)') ' current f: ', me%func(f)\r\n call print_vector(unit,xp,me%n,'trial x')\r\n write(unit,'(A,G25.18)') ' resulting f: ', me%func(fp)\r\n end if\r\n\r\n if (fp >= f) then\r\n ! function value increased: accept the new point\r\n\r\n if (me%iprint >= 3) write(unit,'(A)') ' point accepted'\r\n x = xp\r\n f = fp\r\n nacc = nacc + 1\r\n nacp = nacp + 1\r\n nup = nup + 1\r\n\r\n ! if greater than any other point, record as new optimum.\r\n if (fp > fopt) then\r\n if (me%iprint >= 3) write(unit,'(A)') ' new optimum'\r\n xopt = xp\r\n fopt = fp\r\n nnew = nnew + 1\r\n end if\r\n\r\n else\r\n ! if the point is lower, use the metropolis criteria to decide on\r\n ! acceptance or rejection.\r\n ! NOTE: if t=0, all downhill steps are rejected (monotonic)\r\n\r\n if (t/=0.0_dp) then\r\n p = exprep((fp - f)/t)\r\n pp = uniform_random_number()\r\n if (pp < p) then\r\n if (me%iprint >= 3) then\r\n if (me%maximize) then\r\n write(unit,'(A)') ' though lower, point accepted'\r\n else\r\n write(unit,'(A)') ' though higher, point accepted'\r\n end if\r\n end if\r\n x = xp\r\n f = fp\r\n nacc = nacc + 1\r\n nacp = nacp + 1\r\n ndown = ndown + 1\r\n cycle ! accepted\r\n end if\r\n end if\r\n\r\n ! rejected:\r\n nrej = nrej + 1\r\n if (me%iprint >= 3) then\r\n if (me%maximize) then\r\n write(unit,'(A)') ' lower point rejected'\r\n else\r\n write(unit,'(A)') ' higher point rejected'\r\n end if\r\n end if\r\n\r\n end if\r\n\r\n end do ns_loop ! j - ns loop\r\n\r\n select case (me%step_mode)\r\n case(1)\r\n ! adjust vm so that approximately half of all evaluations are accepted.\r\n ratio = real(nacp,dp) /real(me%ns,dp)\r\n do i = 1, me%n\r\n if (ratio > 0.6_dp) then\r\n vm(i) = vm(i)*(1.0_dp + me%c(i)*(ratio - 0.6_dp)/0.4_dp)\r\n else if (ratio < 0.4_dp) then\r\n vm(i) = vm(i)/(1.0_dp + me%c(i)*((0.4_dp - ratio)/0.4_dp))\r\n end if\r\n if (vm(i) > (me%ub(i)-me%lb(i))) then\r\n vm(i) = me%ub(i) - me%lb(i)\r\n end if\r\n end do\r\n if (me%iprint >= 2) then\r\n write(unit,'(/A)') '---------------------------------------------------'\r\n write(unit,'(A)') ' intermediate results after step length adjustment '\r\n write(unit,'(A/)') '---------------------------------------------------'\r\n call print_vector(unit, vm, me%n, 'new step length (vm)')\r\n call print_vector(unit, xopt, me%n, 'current optimal x')\r\n call print_vector(unit, x, me%n, 'current x')\r\n write(unit,'(A)') ' '\r\n end if\r\n case (2)\r\n ! keep vm as is\r\n case (3)\r\n ! use the constant factor:\r\n vm = abs(me%vms) * vm\r\n case default\r\n error stop ' invalid value of step_mode'\r\n end select\r\n\r\n nacp = 0\r\n\r\n end do nt_loop ! m - nt loop\r\n\r\n if (me%iprint >= 1) then\r\n totmov = nup + ndown + nrej\r\n write(unit,'(/A)') '--------------------------------------------------------'\r\n write(unit,'(A)') ' intermediate results before next temperature reduction '\r\n write(unit,'(A/)') '--------------------------------------------------------'\r\n write(unit,'(A,G12.5)') ' current temperature: ', t\r\n if (me%maximize) then\r\n write(unit,'(A,G25.18)') ' max function value so far: ', fopt\r\n write(unit,'(A,I8)') ' total moves: ', totmov\r\n write(unit,'(A,I8)') ' uphill: ', nup\r\n write(unit,'(A,I8)') ' accepted downhill: ', ndown\r\n write(unit,'(A,I8)') ' rejected downhill: ', nrej\r\n write(unit,'(A,I8)') ' new maxima this temperature:', nnew\r\n else\r\n write(unit,'(A,G25.18)') ' min function value so far: ', -fopt\r\n write(unit,'(A,I8)') ' total moves: ', totmov\r\n write(unit,'(A,I8)') ' downhill: ', nup\r\n write(unit,'(A,I8)') ' accepted uphill: ', ndown\r\n write(unit,'(A,I8)') ' rejected uphill: ', nrej\r\n write(unit,'(A,I8)') ' new minima this temperature:', nnew\r\n end if\r\n call print_vector(unit,xopt, me%n, 'current optimal x')\r\n call print_vector(unit,vm, me%n, 'step length (vm)')\r\n write(unit, '(A)') ' '\r\n end if\r\n\r\n ! check termination criteria.\r\n fstar(1) = f\r\n quit = ((fopt-f)<=me%eps) .and. (all(abs(f-fstar)<=me%eps))\r\n\r\n ! terminate sa if appropriate.\r\n if (quit) then\r\n x = xopt\r\n ier = 0\r\n fopt = me%func(fopt)\r\n if (me%iprint >= 1) then\r\n write(unit,'(/A)') '----------------------------------------------'\r\n write(unit,'(A)') ' sa achieved termination criteria. ier = 0. '\r\n write(unit,'(A/)') '----------------------------------------------'\r\n end if\r\n exit\r\n end if\r\n\r\n ! if termination criteria is not met, prepare for another loop.\r\n t = abs(rt)*t\r\n do i = me%neps, 2, -1\r\n fstar(i) = fstar(i-1)\r\n end do\r\n f = fopt\r\n x = xopt\r\n\r\n end do main\r\n\r\n end do reset\r\n\r\n end subroutine sa\r\n!********************************************************************************\r\n\r\n!********************************************************************************\r\n!>\r\n! Perturb the `x` vector and evaluate the function.\r\n!\r\n! If the function evaluation is not valid, it will perturb\r\n! and try again. Until a valid function is obtained or the\r\n! maximum number of function evaluations is reached.\r\n\r\n subroutine perturb_and_evaluate(me,x,vm,xp,fp,nfcnev,ier,first)\r\n\r\n implicit none\r\n\r\n class(simulated_annealing_type),intent(inout) :: me\r\n real(dp),dimension(:),intent(in) :: x !! input optimization variable vector to perturb\r\n real(dp),dimension(:),intent(in) :: vm !! step length vector\r\n real(dp),dimension(:),intent(out) :: xp !! the perturbed `x` value\r\n real(dp),intent(out) :: fp !! the value of the user function at `xp`\r\n integer,intent(inout) :: nfcnev !! total number of function evaluations\r\n integer,intent(inout) :: ier !! status output code\r\n logical,intent(in),optional :: first !! to use the input `x` the first time\r\n\r\n integer :: i !! counter\r\n integer :: istat !! user function status code\r\n logical :: first_try !! local copy of `first`\r\n real(dp) :: lower !! lower bound to use for random interval\r\n real(dp) :: upper !! upper bound to use for random interval\r\n\r\n if (present(first)) then\r\n first_try = first\r\n else\r\n first_try = .false.\r\n end if\r\n\r\n do\r\n\r\n if (first_try) then\r\n if (me%use_initial_guess) then\r\n ! use the initial guess\r\n ! [note if this evauation fails, the subsequent ones\r\n ! are perturbed from this one]\r\n xp = x\r\n first_try = .false.\r\n else\r\n ! a random point in the bounds:\r\n ! [if it fails, a new random one is tried next time]\r\n do i = 1, me%n\r\n xp(i) = uniform(me%lb(i),me%ub(i))\r\n !xp(i) = me%lb(i) + (me%ub(i)-me%lb(i))*uniform_random_number()\r\n end do\r\n end if\r\n else\r\n ! perturb all of them:\r\n do i = 1, me%n\r\n lower = max( me%lb(i), x(i) - vm(i) )\r\n upper = min( me%ub(i), x(i) + vm(i) )\r\n xp(i) = uniform(lower,upper)\r\n !xp(i) = lower + (upper-lower)*uniform_random_number()\r\n end do\r\n end if\r\n\r\n ! evaluate the function with the trial\r\n ! point xp and return as fp.\r\n call me%fcn(xp, fp, istat)\r\n\r\n ! function eval counter:\r\n nfcnev = nfcnev + 1\r\n\r\n ! if too many function evaluations occur, terminate the algorithm.\r\n if (nfcnev > me%maxevl) then\r\n if (me%iprint>0) then\r\n write(me%iunit, '(A)') ' too many function evaluations; consider'\r\n write(me%iunit, '(A)') ' increasing maxevl or eps, or decreasing'\r\n write(me%iunit, '(A)') ' nt or rt. these results are likely to be'\r\n write(me%iunit, '(A)') ' poor.'\r\n end if\r\n ier = 1\r\n return\r\n end if\r\n\r\n select case (istat)\r\n case(-2)\r\n ! user stop\r\n write(me%iunit, '(A)') ' user stopped in function.'\r\n ier = 4\r\n exit\r\n case(-1)\r\n ! try another one until we get a valid evaluation\r\n cycle\r\n case default\r\n ! continue\r\n end select\r\n\r\n exit ! finished\r\n\r\n end do\r\n\r\n end subroutine perturb_and_evaluate\r\n!********************************************************************************\r\n\r\n!********************************************************************************\r\n!>\r\n! if the function is to be minimized, switch the sign of the function.\r\n! note that all intermediate and final output switches the sign back\r\n! to eliminate any possible confusion for the user.\r\n\r\n pure function func(me,f)\r\n\r\n implicit none\r\n\r\n class(simulated_annealing_type),intent(in) :: me\r\n real(dp),intent(in) :: f\r\n real(dp) :: func\r\n\r\n if (me%maximize) then\r\n func = f\r\n else\r\n func = -f\r\n end if\r\n\r\n end function func\r\n!********************************************************************************\r\n\r\n!********************************************************************************\r\n!>\r\n! this function replaces `exp()` to avoid underflow and overflow.\r\n!\r\n! note that the maximum and minimum values of\r\n! exprep are such that they has no effect on the algorithm.\r\n!\r\n!### History\r\n! * Jacob Williams, 8/30/2019 : new version of this routine that uses IEEE flags.\r\n\r\n pure function exprep(x) result(f)\r\n\r\n use, intrinsic :: ieee_exceptions\r\n\r\n implicit none\r\n\r\n logical,dimension(2) :: flags\r\n type(ieee_flag_type),parameter,dimension(2) :: out_of_range = &\r\n [ieee_overflow,ieee_underflow]\r\n\r\n real(dp), intent(in) :: x\r\n real(dp) :: f\r\n\r\n call ieee_set_halting_mode(out_of_range,.false.)\r\n\r\n f = exp(x)\r\n\r\n call ieee_get_flag(out_of_range,flags)\r\n if (any(flags)) then\r\n call ieee_set_flag(out_of_range,.false.)\r\n if (flags(1)) then\r\n f = huge(1.0_dp)\r\n else\r\n f = 0.0_dp\r\n end if\r\n end if\r\n\r\n end function exprep\r\n!********************************************************************************\r\n\r\n!********************************************************************************\r\n!>\r\n! Initialize the intrinsic random number generator.\r\n!\r\n!### Author\r\n! * Jacob Williams, 8/30/2019\r\n\r\n subroutine rand_init(seed1,seed2)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: seed1 !! the first seed for the random number generator.\r\n integer,intent(in) :: seed2 !! the second seed for the random number generator.\r\n\r\n integer,dimension(:),allocatable :: s\r\n integer :: n\r\n integer :: i\r\n\r\n if (seed1==0 .and. seed2==0) then\r\n call random_seed()\r\n else\r\n call random_seed(size = n)\r\n allocate(s(n))\r\n s(1) = seed1\r\n if (n>1) then\r\n s(2) = seed2\r\n do i = 3, n ! just in case\r\n s(i) = seed1 + seed2 + i\r\n end do\r\n end if\r\n call random_seed(put=s)\r\n end if\r\n\r\n end subroutine rand_init\r\n!********************************************************************************\r\n\r\n!********************************************************************************\r\n!>\r\n! Get a new uniform random number from [0,1].\r\n!\r\n!### Author\r\n! * Jacob Williams, 8/30/2019\r\n\r\n function uniform_random_number() result(f)\r\n\r\n implicit none\r\n\r\n real(dp) :: f\r\n\r\n call random_number(f)\r\n\r\n end function uniform_random_number\r\n!********************************************************************************\r\n\r\n!********************************************************************************\r\n!>\r\n! Uniform random number on the interval `[xl,xu]`.\r\n\r\n function uniform(xl,xu)\r\n\r\n implicit none\r\n\r\n real(dp),intent(in) :: xl !! lower bound\r\n real(dp),intent(in) :: xu !! upper bound\r\n real(dp) :: uniform\r\n\r\n uniform = xl + (xu-xl)*uniform_random_number()\r\n\r\n end function uniform\r\n!********************************************************************************\r\n\r\n!********************************************************************************\r\n!>\r\n! this subroutine prints the double precision vector named vector.\r\n! elements 1 thru ncols will be printed. name is a character variable\r\n! that describes vector. note that if name is given in the call to\r\n! print_vector, it must be enclosed in quotes. if there are more than 10\r\n! elements in vector, 10 elements will be printed on each line.\r\n\r\n subroutine print_vector(iunit, vector, ncols, name)\r\n\r\n implicit none\r\n\r\n integer, intent(in) :: iunit\r\n integer, intent(in) :: ncols\r\n real(dp), dimension(ncols), intent(in) :: vector\r\n character(len=*), intent(in) :: name\r\n\r\n integer :: i, lines, ll\r\n\r\n write(iunit,'(/,25X,A)') trim(name)\r\n\r\n if (ncols > 10) then\r\n lines = int(ncols/10.0_dp)\r\n do i = 1, lines\r\n ll = 10*(i - 1)\r\n write(iunit,'(10(G12.5,1X))') vector(1+ll:10+ll)\r\n end do\r\n write(iunit,'(10(G12.5,1X))') vector(11+ll:ncols)\r\n else\r\n write(iunit,'(10(G12.5,1X))') vector(1:ncols)\r\n end if\r\n\r\n end subroutine print_vector\r\n!********************************************************************************\r\n\r\n!********************************************************************************\r\n end module simulated_annealing_module\r\n!********************************************************************************", "meta": {"hexsha": "0991f5cd1837d66768407fc3ef0323bb1afbd0ad", "size": 42853, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/simulated_annealing.f90", "max_stars_repo_name": "jacobwilliams/simulated-annealing", "max_stars_repo_head_hexsha": "cb5e549d161759b2e72161c67ce945a8285bcbe6", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2020-10-10T19:07:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T02:27:42.000Z", "max_issues_repo_path": "src/simulated_annealing.f90", "max_issues_repo_name": "jacobwilliams/simulated-annealing", "max_issues_repo_head_hexsha": "cb5e549d161759b2e72161c67ce945a8285bcbe6", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-03-21T19:42:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T04:10:44.000Z", "max_forks_repo_path": "src/simulated_annealing.f90", "max_forks_repo_name": "jacobwilliams/simulated-annealing", "max_forks_repo_head_hexsha": "cb5e549d161759b2e72161c67ce945a8285bcbe6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-10-13T15:38:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-07T10:35:19.000Z", "avg_line_length": 46.7827510917, "max_line_length": 128, "alphanum_fraction": 0.4567008144, "num_tokens": 8924, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898305367525, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7664152436615776}} {"text": "\n!\n! Project Euler Problem 2: Even Fibonacci numbers\n!\n! D. C. Groothuizen Dijkema - November, 2019\n!\n\nsubroutine run\n implicit none\n integer :: fib_0,fib_1,sum,tmp\n integer, parameter :: limit=4000000\n\n fib_0=1\n fib_1=1\n sum=0\n\n do while (fib_0.lt.limit)\n if (mod(fib_0,2).eq.0) then\n sum=sum+fib_0\n end if\n tmp=fib_0\n fib_0=fib_1\n fib_1=fib_0+tmp\n end do\n\n print *,\"The sum of all even Fibonacci numbers less than four million is:\",sum\n\nend subroutine run\n\nprogram fibonacci\n implicit none\n integer :: beginning,end,rate\n\n call system_clock(beginning,rate)\n call run\n call system_clock(end)\n print *,\"Elapsed time:\",real(end-beginning)/real(rate)\n\nend program\n", "meta": {"hexsha": "55988e63bf16ab181256a0aa7f6a506993072e6c", "size": 697, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "problem_2/fibonacci.f", "max_stars_repo_name": "DCGroothuizenDijkema/ProjectEuler", "max_stars_repo_head_hexsha": "52911a1c2609a963277497e1342828c6a2c4f1dc", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "problem_2/fibonacci.f", "max_issues_repo_name": "DCGroothuizenDijkema/ProjectEuler", "max_issues_repo_head_hexsha": "52911a1c2609a963277497e1342828c6a2c4f1dc", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "problem_2/fibonacci.f", "max_forks_repo_name": "DCGroothuizenDijkema/ProjectEuler", "max_forks_repo_head_hexsha": "52911a1c2609a963277497e1342828c6a2c4f1dc", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.425, "max_line_length": 80, "alphanum_fraction": 0.6958393113, "num_tokens": 230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002789, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7662489254915501}} {"text": "module hyper\nuse, intrinsic:: ieee_arithmetic\nuse, intrinsic:: iso_fortran_env, only: stderr=>error_unit\nuse assert, only: wp\nuse rat, only: SWITCH_RAT_TO_REAL\nuse global\n\nimplicit none (type, external)\n\ninterface sech\nprocedure sech_r, sech_c\nend interface sech\n\ninterface asech\nprocedure asech_r, asech_c\nend interface asech\n\ninterface csch\nprocedure csch_r, csch_c\nend interface csch\n\ninterface acsch\nprocedure acsch_r, acsch_c\nend interface acsch\n\ninterface coth\nprocedure coth_r, coth_c\nend interface coth\n\ninterface acoth\nprocedure acoth_r, acoth_c\nend interface acoth\n\ncontains\n\n!***********************************************************************************************************************************\n! SECH\n!\n! Hyperbolic secant.\n!***********************************************************************************************************************************\n\nelemental real(wp) FUNCTION SECH_r(X) result(sech)\nreal(wp), INTENT (IN) :: X\n\nsech = 1._wp/COSH(X)\nEND FUNCTION SECH_r\n\n\nelemental complex(wp) FUNCTION SECH_c(Z) RESULT(sech)\nCOMPLEX(wp), INTENT (IN) :: Z\n\nsech = 1._wp/cosh(Z)\nEND FUNCTION SECH_c\n\n\n\n!***********************************************************************************************************************************\n! ASECH\n!\n! Inverse hyperbolic secant.\n!***********************************************************************************************************************************\n\nelemental real(wp) FUNCTION ASECH_r(y) result(asech)\nreal(wp), INTENT (IN) :: Y\n\nasech = ACOSH(1._wp/Y)\nEND FUNCTION ASECH_r\n\n\nelemental complex(wp) FUNCTION ASECH_c(Y) result(asech)\nCOMPLEX(wp), INTENT (IN) :: Y\n\nasech = ACOSH(1._wp/Y)\n\nEND FUNCTION ASECH_c\n\n!***********************************************************************************************************************************\n! CSCH\n!\n! Hyperbolic cosecant.\n!***********************************************************************************************************************************\n\nelemental real(wp) FUNCTION CSCH_r(X) RESULT (Y)\nreal(wp), INTENT (IN) :: X\n\nY = 1._wp/SINH(X)\nEND FUNCTION CSCH_r\n\n\nelemental complex(wp) FUNCTION CSCH_c(Z) RESULT (Y)\nCOMPLEX(wp), INTENT (IN) :: Z\n\nY = 1._wp / SINH(Z)\nEND FUNCTION CSCH_c\n\n!***********************************************************************************************************************************\n! ACSCH\n!\n! Inverse hyperbolic cosecant.\n!***********************************************************************************************************************************\n\nelemental real(wp) FUNCTION ACSCH_r(Y) RESULT (X)\nreal(wp), INTENT (IN) :: Y\n\nX = ASINH(1._wp/Y)\nEND FUNCTION ACSCH_r\n\n\nelemental complex(wp) FUNCTION ACSCH_c(Y) RESULT (X)\nCOMPLEX(wp), INTENT (IN) :: Y\n\nX = ASINH(1._wp/Y)\n\nEND FUNCTION ACSCH_c\n\n\n!***********************************************************************************************************************************\n! COTH\n!\n! Hyperbolic cotangent.\n!***********************************************************************************************************************************\n\nelemental real(wp) FUNCTION COTH_r(X) result(coth)\nreal(wp), INTENT (IN) :: X\n\ncoth = 1._wp/TANH(X)\nEND FUNCTION COTH_r\n\n\nelemental complex(wp) FUNCTION COTH_c(Z) result(coth)\nCOMPLEX(wp), INTENT (IN) :: Z\n\nCOTH = 1._wp / tanh(Z)\nEND FUNCTION COTH_c\n\n\n\n!***********************************************************************************************************************************\n! ACOTH\n!\n! Inverse hyperbolic cotangent.\n!***********************************************************************************************************************************\n\nelemental real(wp) FUNCTION ACOTH_r(Y) result(acoth)\nreal(wp), INTENT (IN) :: Y\n\nACOTH = ATANH(1._wp/Y)\nEND FUNCTION ACOTH_r\n\n\nelemental complex(wp) FUNCTION ACOTH_c(Z) result(acoth)\nCOMPLEX(wp), INTENT(IN) :: Z\n\nacoth = 0.5_wp*LOG((Z+1._wp)/(Z-1._wp))\nEND FUNCTION ACOTH_c\n\n!-------------------------------------------------\nsubroutine hasin(domain_mode)\ninteger, intent(in) :: domain_mode\n\nSELECT CASE (DOMAIN_MODE)\n CASE (1)\n LASTX = STACK(1)\n STACK(1) = ASINH(STACK(1))\n CASE (2)\n CLASTX = CSTACK(1)\n CSTACK(1) = ASINH(CSTACK(1))\n CASE (3)\n CALL SWITCH_RAT_TO_REAL\n LASTX = STACK(1)\n STACK(1) = ASINH(STACK(1))\nEND SELECT\n\nend subroutine hasin\n\n\nsubroutine hacos(domain_mode)\ninteger, intent(in) :: domain_mode\n\n SELECT CASE (DOMAIN_MODE)\n CASE (1)\n IF (STACK(1) < 1._wp) THEN\n write(stderr, *) ' ACOSH Error'\n ELSE\n LASTX = STACK(1)\n STACK(1) = ACOSH(STACK(1))\n END IF\n CASE (2)\n CLASTX = CSTACK(1)\n CSTACK(1) = ACOSH(CSTACK(1))\n CASE (3)\n IF (RNSTACK(1) < RDSTACK(1)) THEN\n write(stderr, *) ' ACOSH Error'\n ELSE\n CALL SWITCH_RAT_TO_REAL\n LASTX = STACK(1)\n STACK(1) = ACOSH(STACK(1))\n END IF\n END SELECT\nend subroutine hacos\n\n\nsubroutine hatan(domain_mode)\ninteger, intent(in) :: domain_mode\n\nSELECT CASE (DOMAIN_MODE)\n CASE (1)\n IF (ABS(STACK(1)) >= 1._wp) THEN\n write(stderr, *) ' ATANH Error'\n ELSE\n LASTX = STACK(1)\n STACK(1) = ATANH(STACK(1))\n END IF\n CASE (2)\n CLASTX = CSTACK(1)\n CSTACK(1) = ATANH(CSTACK(1))\n CASE (3)\n IF (ABS(RNSTACK(1)) >= ABS(RDSTACK(1))) THEN\n write(stderr, *) ' ATANH Error'\n ELSE\n CALL SWITCH_RAT_TO_REAL\n LASTX = STACK(1)\n STACK(1) = ATANH(STACK(1))\n END IF\nEND SELECT\n\nend subroutine hatan\n\nend module hyper\n", "meta": {"hexsha": "5e064f63cc4aa611e4ed3ca87b64f4fa8ec667e3", "size": 5594, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/hyper.f90", "max_stars_repo_name": "majacQ/rpn-calc-fortran", "max_stars_repo_head_hexsha": "de34bf485d09e94c2bb0c81639fa901dd16be42a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-06-28T12:59:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-09T19:58:47.000Z", "max_issues_repo_path": "src/hyper.f90", "max_issues_repo_name": "majacQ/rpn-calc-fortran", "max_issues_repo_head_hexsha": "de34bf485d09e94c2bb0c81639fa901dd16be42a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-30T22:09:22.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-16T00:37:17.000Z", "max_forks_repo_path": "src/hyper.f90", "max_forks_repo_name": "majacQ/rpn-calc-fortran", "max_forks_repo_head_hexsha": "de34bf485d09e94c2bb0c81639fa901dd16be42a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-12T01:36:48.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-12T01:36:48.000Z", "avg_line_length": 24.3217391304, "max_line_length": 132, "alphanum_fraction": 0.463889882, "num_tokens": 1364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013355, "lm_q2_score": 0.83973396967765, "lm_q1q2_score": 0.7662036471126925}} {"text": "! leggaus.f90\n! author: sunder\n\n! ---------------------------------------------------------------------------------------------------------\n! Gauss-Legendre quadrature points (x) and weights (w) in interval (x1, x2) for n points \n! ---------------------------------------------------------------------------------------------------------\n\npure subroutine gauleg(x1, x2, x, w, n)\n use constants, only : m_pi\n implicit none\n ! Argument list\n integer, intent(in) :: n\n double precision, intent (in) :: x1, x2\n double precision, intent(out) :: x(n), w(n)\n ! Local variables\n double precision :: EPS\n integer :: i,j,m\n double precision :: p1, p2, p3, pp, xl, xm, z, z1\n\n parameter (EPS=1.0D-15)\n\n m = (n+1)/2\n xm = 0.5*(x2+x1)\n xl = 0.5*(x2-x1)\n do i=1,m\n z = COS(m_pi*(i-0.25d0)/(n+0.5d0))\n 1 continue\n p1 = 1.0d0\n p2 = 0.0d0\n do j = 1,n\n p3 = p2\n p2 = p1\n p1 = ((2.0d0*j-1.0d0)*z*p2-(j-1.0d0)*p3)/dble(j)\n end do\n pp = dble(n)*(z*p1-p2)/(z*z-1.0d0)\n z1 = z\n z = z1-p1/pp\n if(abs(z-z1).GT.EPS)goto 1\n x(i) = xm-xl*z\n x(n+1-i)= xm+xl*z\n w(i) = 2.0d0*xl/((1.-z*z)*pp*pp)\n w(n+1-i)= w(i)\n end do\n return\nend subroutine gauleg\n", "meta": {"hexsha": "9f97ed43188cd4c8c344c915dbe3c3ee297bf7bb", "size": 1322, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ADER-WENO-1D-LINEAR-CONVECTION/leggauss.f90", "max_stars_repo_name": "dasikasunder/ADER-WENO", "max_stars_repo_head_hexsha": "8d40b341be7610ac89a144077a9f759a0154909a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-19T07:50:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-19T07:50:53.000Z", "max_issues_repo_path": "ADER-WENO-1D-LINEAR-CONVECTION/leggauss.f90", "max_issues_repo_name": "dasikasunder/ADER-WENO", "max_issues_repo_head_hexsha": "8d40b341be7610ac89a144077a9f759a0154909a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ADER-WENO-1D-LINEAR-CONVECTION/leggauss.f90", "max_forks_repo_name": "dasikasunder/ADER-WENO", "max_forks_repo_head_hexsha": "8d40b341be7610ac89a144077a9f759a0154909a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.7391304348, "max_line_length": 107, "alphanum_fraction": 0.4084720121, "num_tokens": 459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7662036416232649}} {"text": "! Computes an approximation of Pi with a Monte Carlo algorithm\n! OpenMP version\n! Vincent Magnin, 2021-04-22\n! Last modification: 2021-05-09\n! MIT license\n! $ gfortran -Wall -Wextra -std=f2018 -pedantic -O3 -fopenmp m_xoroshiro128plus.f90 pi_monte_carlo_openmp.f90\n! $ ifort -O3 -qopenmp m_xoroshiro128plus.f90 pi_monte_carlo_openmp.f90\n\nprogram pi_monte_carlo_openmp\n use, intrinsic :: iso_fortran_env, only: wp=>real64, int64\n use m_xoroshiro128plus\n use omp_lib, only: omp_get_thread_num\n implicit none\n type(rng_t) :: rng ! xoroshiro128+ pseudo-random number generator\n real(wp) :: x, y ! Coordinates of a point\n integer(int64) :: n ! Total number of points\n integer(int64) :: k = 0 ! Points into the quarter disk\n integer(int64) :: i ! Loop counter\n integer :: t1, t2 ! Clock ticks\n real :: count_rate ! Clock ticks per second\n integer :: thread ! OpenMP thread number\n\n n = 1000000000\n\n call system_clock(t1, count_rate)\n\n !$OMP PARALLEL DEFAULT(NONE) SHARED(n) PRIVATE(thread, i, x, y, rng) REDUCTION(+: k)\n thread = omp_get_thread_num()\n ! Each thread will have its own RNG seed:\n call rng%seed([ -1337_i8, 9812374_i8 ] + 10*thread)\n x = rng%U01()\n\n !$OMP DO SCHEDULE(STATIC) \n do i = 1, n\n ! Computing a random point (x,y) into the square 0<=x<1, 0<=y<1:\n x = rng%U01()\n y = rng%U01()\n\n ! Is it in the quarter disk (R=1, center=origin) ?\n if ((x**2 + y**2) < 1.0_wp) k = k + 1\n end do\n !$OMP END DO\n print '(a, i0, a, i0)', \"k\", thread, \" = \", k\n !$OMP END PARALLEL\n\n write(*,*)\n write(*, '(a, i0, a, i0)', advance='no') \"4 * \", k, \" / \", n\n write(*, '(a, f17.15)') \" = \", (4.0_wp * k) / n\n\n call system_clock(t2)\n write(*,'(a, f6.3, a)') \"Execution time: \", (t2 - t1) / count_rate, \" s\"\n write(*,'(a)') \"---------------------------------------------------\"\nend program pi_monte_carlo_openmp\n", "meta": {"hexsha": "e7d96e177275d9346f05e77f05617425dfcd56da", "size": 2030, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pi_monte_carlo_openmp.f90", "max_stars_repo_name": "vmagnin/exploring_coarrays", "max_stars_repo_head_hexsha": "66b9ee5483b81bdc11c67642e918068b6e1bb821", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-05-03T20:28:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-08T22:56:34.000Z", "max_issues_repo_path": "pi_monte_carlo_openmp.f90", "max_issues_repo_name": "vmagnin/exploring_coarrays", "max_issues_repo_head_hexsha": "66b9ee5483b81bdc11c67642e918068b6e1bb821", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pi_monte_carlo_openmp.f90", "max_forks_repo_name": "vmagnin/exploring_coarrays", "max_forks_repo_head_hexsha": "66b9ee5483b81bdc11c67642e918068b6e1bb821", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-04T00:35:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-04T00:35:11.000Z", "avg_line_length": 37.5925925926, "max_line_length": 109, "alphanum_fraction": 0.5753694581, "num_tokens": 667, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391386, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7662036357944771}} {"text": "program problem_1\n integer i\n integer total\n total = 0\n do i=0,999\n if (MODULO(i, 3) == 0 .OR. MODULO(i, 5) == 0) then\n total = total + i\n end if\n end do\n print *,\"Problem 1:\", total\nend program problem_1", "meta": {"hexsha": "3ed04c94300b74395162b898fee086a25cd7b2c7", "size": 249, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/problem_1.f90", "max_stars_repo_name": "deidyomega/project_euler", "max_stars_repo_head_hexsha": "2e160c8c379f083cc233c985c1d3a0d65621bf15", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/problem_1.f90", "max_issues_repo_name": "deidyomega/project_euler", "max_issues_repo_head_hexsha": "2e160c8c379f083cc233c985c1d3a0d65621bf15", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/problem_1.f90", "max_forks_repo_name": "deidyomega/project_euler", "max_forks_repo_head_hexsha": "2e160c8c379f083cc233c985c1d3a0d65621bf15", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.6363636364, "max_line_length": 58, "alphanum_fraction": 0.5341365462, "num_tokens": 88, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951552333004, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.7661043670538861}} {"text": "module optimize\n\n! Optimization algorithms\n\nuse types, only: dp\nuse utils, only: stop_error\nimplicit none\nprivate\npublic bisect,secant\n\ninterface\n real(dp) function func(x)\n import :: dp\n implicit none\n real(dp), intent(in) :: x\n end function\nend interface\n\ncontains\n\nreal(dp) function bisect(f, a, b, tol) result(c)\n! Solves f(x) = 0 on the interval [a, b] using the bisection method\nprocedure(func) :: f\nreal(dp), intent(in) :: a, b, tol\nreal(dp) :: a_, b_, fa, fb, fc\na_ = a; b_ = b\nfa = f(a_)\nfb = f(b_)\nif (fa * fb >= 0) then\n call stop_error(\"bisect: f(a) and f(b) must have opposite signs\")\nend if\ndo while (b_ - a_ > tol)\n c = (a_ + b_) / 2\n fc = f(c)\n if (abs(fc) < tiny(1.0_dp)) return ! We need to make sure f(c) is not zero below\n if (fa * fc < 0) then\n b_ = c\n fb = fc\n else\n a_ = c\n fa = fc\n end if\nend do\nc = (a_ + b_)/2\nend function\n\nreal(dp) function secant(f, a,b,tol, maxiter) result (c)\n!Solves f(x) = 0 on using the a and b as starting values\nprocedure(func) :: f\nreal(dp),intent(in) :: a,b,tol\ninteger,optional :: maxiter\n\ninteger :: maxiter_\nreal(dp) :: xstart, xnext\nreal(dp) :: fstart, fnext\ninteger :: i\n\nif(present(maxiter)) then\n maxiter_ = maxiter\nelse\n maxiter_ = 100\nendif\n\n\nxstart = a\nxnext = b\nfstart = f(xstart)\nif(abs(fstart ) < tiny(1.0_dp)) then\n c = xstart\n return\nendif\nfnext = f(xnext)\nif(abs(fnext ) < tiny(1.0_dp)) then\n c = xnext\n return\nendif\n\ndo i = 1, maxiter_\n \n if( abs(fnext - fstart) < tiny(1.0_dp)) then\n call stop_error(\"secant: division by zero\")\n endif\n c = (xstart*fnext - xnext*fstart)/(fnext - fstart)\n if (abs(c - xnext) < tol) return ! root found \n !update variables\n xstart = xnext\n fstart = fnext\n xnext = c\n fnext = f(c)\nenddo\n!max iterations number reached\ncall stop_error(\"secant: method did not converge\")\nend function secant\n \n\nend module\n", "meta": {"hexsha": "d83c7801c11e937212d3607237a7cf123358a94d", "size": 1929, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/optimize.f90", "max_stars_repo_name": "shelvon/fortran-utils", "max_stars_repo_head_hexsha": "464982bfc96359c7d37d9fd0185c6722e9a70046", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 163, "max_stars_repo_stars_event_min_datetime": "2015-02-12T09:55:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T23:08:58.000Z", "max_issues_repo_path": "src/optimize.f90", "max_issues_repo_name": "wu2meng3/fortran-utils", "max_issues_repo_head_hexsha": "b43bd24cd421509a5bc6d3b9c3eeae8ce856ed88", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2016-10-08T21:18:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-24T15:11:50.000Z", "max_forks_repo_path": "src/optimize.f90", "max_forks_repo_name": "wu2meng3/fortran-utils", "max_forks_repo_head_hexsha": "b43bd24cd421509a5bc6d3b9c3eeae8ce856ed88", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 48, "max_forks_repo_forks_event_min_datetime": "2015-03-20T10:26:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T11:09:47.000Z", "avg_line_length": 19.8865979381, "max_line_length": 86, "alphanum_fraction": 0.623120788, "num_tokens": 659, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.766057028294963}} {"text": " SUBROUTINE RECCEL(CELL,RCELL)\n IMPLICIT NONE\nC***********************************************************************\nC-----------------------------------------------------------------------\nC PURPOSE: ESTABLISH RECIPROCAL CELL PARAMETERS FROM REAL CELL PARAMS\nC ======= USING FORMULAE OF STOUT+JENSEN - \"X-RAY STRUCTURE ANALYSIS\",\nC MACMILLAN CO. (1968), P.31, OR INT. TABLES VOL I P.13.\nC-----------------------------------------------------------------------\nC CALLS : 0\nC =====\nC-----------------------------------------------------------------------\nC ARGUMENTS:\nC =========\nC CELL(I) - Real array containing real space lattice parameters\nC RCELL(O) - Real array containing derived reciprocal space lattice \nC parameters\nC-----------------------------------------------------------------------\n REAL CELL(6),RCELL(6)\n DOUBLE PRECISION DC1,DC2,DC3,DC4,DC5,DC6\n DOUBLE PRECISION CASQ,CBSQ,CCSQ,CBA,ALBTGM,VOLUME,XNUM,DEN,TEMP\nC-----------------------------------------------------------------------\nC\nC-- Convert cell parameters to double precision\nC\n DC1 = DBLE(CELL(1))\n DC2 = DBLE(CELL(2))\n DC3 = DBLE(CELL(3))\n DC4 = DBLE(CELL(4))\n DC5 = DBLE(CELL(5))\n DC6 = DBLE(CELL(6))\nC\nC-- Calculate real cell volume. Remember all angles should already be\nC in radians.\nC\n CASQ = COS(DC4)**2\n CBSQ = COS(DC5)**2\n CCSQ = COS(DC6)**2\n CBA = DC1*DC2*DC3\n ALBTGM = COS(DC4)*COS(DC5)*COS(DC6)\n VOLUME = CBA*(SQRT(1.0D0-CASQ-CBSQ-CCSQ+2.0D0*ALBTGM))\nC\nC-- Calculate reciprocal cell sides\nC\n RCELL(1) = SNGL(DC2*DC3*SIN(DC4)/VOLUME)\n RCELL(2) = SNGL(DC1*DC3*SIN(DC5)/VOLUME)\n RCELL(3) = SNGL(DC1*DC2*SIN(DC6)/VOLUME)\nC\nC-- Calculate reciprocal cell angles\nC\n XNUM = COS(DC5)*COS(DC6) - COS(DC4)\n DEN = SIN(DC5)*SIN(DC6)\n TEMP = XNUM/DEN\n RCELL(4) = SNGL(ACOS(TEMP))\n \n XNUM = COS(DC4)*COS(DC6) - COS(DC5)\n DEN = SIN(DC4)*SIN(DC6)\n TEMP = XNUM/DEN\n RCELL(5) = SNGL(ACOS(TEMP))\n \n XNUM = COS(DC4)*COS(DC5) - COS(DC6)\n DEN = SIN(DC4)*SIN(DC5)\n TEMP = XNUM/DEN\n RCELL(6) = SNGL(ACOS(TEMP))\n \n RETURN\n END\n", "meta": {"hexsha": "3adbf9fee2ff293ee4f810c4ef3b26cce0603f2e", "size": 2194, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "software/lsqint/RECCEL.f", "max_stars_repo_name": "scattering-central/CCP13", "max_stars_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "software/lsqint/RECCEL.f", "max_issues_repo_name": "scattering-central/CCP13", "max_issues_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "software/lsqint/RECCEL.f", "max_forks_repo_name": "scattering-central/CCP13", "max_forks_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-09-05T15:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T11:13:45.000Z", "avg_line_length": 32.7462686567, "max_line_length": 72, "alphanum_fraction": 0.4863263446, "num_tokens": 699, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418283357703, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7660570259006277}} {"text": "!##############################################################################\n! PROGRAM GaussLegendre\n!\n! ## Numerical integration with Gauss-Legendre quadrature\n!\n! This code is published under the GNU General Public License v3\n! (https://www.gnu.org/licenses/gpl-3.0.en.html)\n!\n! Authors: Hans Fehr and Fabian Kindermann\n! contact@ce-fortran.com\n!\n! #VC# VERSION: 1.0 (23 January 2018)\n!\n!##############################################################################\nprogram GaussLegendre\n\n use toolbox\n\n implicit none\n integer, parameter :: n = 10\n real*8, parameter :: a = 0d0, b = 2d0\n real*8 :: x(0:n), w(0:n), f(0:n)\n\n ! calculate nodes and weights\n call legendre(0d0, 2d0, x, w)\n\n ! calculate function values at nodes\n f = cos(x)\n\n ! Output numerical and analytical solution\n write(*,'(a,f10.6)')' Numerical: ',sum(w*f, 1)\n write(*,'(a,f10.6)')' Analytical: ',sin(2d0)-sin(0d0)\n\nend program\n", "meta": {"hexsha": "57b6f76a7df24e366eec587499d06d025dd2ca96", "size": 973, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog02/prog02_13/prog02_13.f90", "max_stars_repo_name": "aswinvk28/modflow_fortran", "max_stars_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "complete/prog02/prog02_13/prog02_13.f90", "max_issues_repo_name": "aswinvk28/modflow_fortran", "max_issues_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "complete/prog02/prog02_13/prog02_13.f90", "max_forks_repo_name": "aswinvk28/modflow_fortran", "max_forks_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-07T12:27:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-07T12:27:47.000Z", "avg_line_length": 27.8, "max_line_length": 79, "alphanum_fraction": 0.5220966084, "num_tokens": 269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8289388104343893, "lm_q1q2_score": 0.7660570209258619}} {"text": "! A[r,s] * B[s,t] = C[r,t]\nsubroutine matrix_multiply2(A,r,s,B,t,C)\n\tinteger :: r, s, t\n\treal, intent(in) :: A(r,s)\n\treal, intent(in) :: B(s,t)\n\treal, intent(inout) :: C(r,t)\n\n\tC = matmul(A,B)\nend subroutine matrix_multiply2\n\t\n\t", "meta": {"hexsha": "b9b50d7eb0cf466cec2627458eea976402bbf5c7", "size": 228, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "f2py/arr2.f90", "max_stars_repo_name": "jonaslindemann/compute-course-public", "max_stars_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-09-12T12:07:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-29T17:38:34.000Z", "max_issues_repo_path": "f2py/arr2.f90", "max_issues_repo_name": "jonaslindemann/compute-course-public", "max_issues_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "f2py/arr2.f90", "max_forks_repo_name": "jonaslindemann/compute-course-public", "max_forks_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-10-24T16:02:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-28T20:57:46.000Z", "avg_line_length": 20.7272727273, "max_line_length": 40, "alphanum_fraction": 0.600877193, "num_tokens": 81, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002492, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7660570194148224}} {"text": "\tSUBROUTINE initialdata(Nx,dt,c,x,u,uold)\n\t!--------------------------------------------------------------------\n\t!\n\t!\n\t! PURPOSE\n\t!\n\t! This subroutine gets initial data for nonlinear Klein-Gordon equation\n\t! in 1 dimensions\n\t! u_{tt}-u_{xx}+u=Es*u^3\n\t!\n\t! The boundary conditions are u(x=-Lx*\\pi)=u(x=Lx*\\pi), \n\t! The initial condition is u=sqrt(2)*sech((x(i)-c*t)/sqrt(1-c**2)\n\t!\n\t! INPUT\n\t!\n\t! .. Parameters ..\n\t! Nx\t= number of modes in x - power of 2 for FFT\n ! dt = timestep\n ! c = wavespeed\n\t! .. Vectors ..\n\t! x\t= x locations\n\t!\n\t! OUTPUT\n\t!\n\t! .. Arrays ..\n\t! u \t= initial solution\n\t! uold = approximate solution at previous timestep\n\t!\n\t! LOCAL VARIABLES\n\t!\n\t! .. Scalars ..\n\t! i\t= loop counter in x direction\n\t!\n\t! REFERENCES\n\t!\n\t! ACKNOWLEDGEMENTS\n\t!\n\t! ACCURACY\n\t!\t\t\n\t! ERROR INDICATORS AND WARNINGS\n\t!\n\t! FURTHER COMMENTS\n\t! Check that the initial iterate is consistent with the \n\t! boundary conditions for the domain specified\n\t!--------------------------------------------------------------------\n\t! External routines required\n\t! \n\t! External libraries required\n\t! OpenMP library\n\t!USE omp_lib\t\t \t \n\tIMPLICIT NONE\t\t\t\t\t \n\t! Declare variables\n\tINTEGER(KIND=4), INTENT(IN)\t\t\t\t:: Nx\n\tREAL(KIND=8), DIMENSION(1:NX), INTENT(IN) \t\t:: x\n\tREAL(KIND=8), DIMENSION(1:NX), INTENT(OUT)\t\t:: u,uold\n\tINTEGER(kind=4)\t\t\t\t\t\t:: i\n REAL(KIND=8), INTENT(IN) :: c,dt\n REAL(KIND=8) :: t=0.0d0\n\tDO i=1,Nx\n\t\tu(i)=sqrt(2.0d0)/(cosh((x(i)-c*t)/sqrt(1.0d0-c**2)))\n !u(i)=sqrt(2.0d0)/cosh(x(i)+t)\n\tEND DO\n t=-1.0d0*dt;\n\tDO i=1,Nx\n\t\tuold(i)=sqrt(2.0d0)/(cosh((x(i)-c*t)/sqrt(1.0d0-c**2)))\n !uold(i)=sqrt(2.0d0)/cosh(x(i)+t)\n\tEND DO\n\t\n\tEND SUBROUTINE initialdata\n", "meta": {"hexsha": "d1ef07cbe0faf79af391892e8e7df1cee98a4c4e", "size": 1801, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Codes/Fortran1DFourierCompactR2C/initialdata.f90", "max_stars_repo_name": "bkmgit/KleinGordon1D", "max_stars_repo_head_hexsha": "ce6ba332e542d74b72069ae253cca5e0a2ade425", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-01-21T03:57:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-21T03:57:51.000Z", "max_issues_repo_path": "Codes/Fortran1DFourierCompactR2C/initialdata.f90", "max_issues_repo_name": "bkmgit/KleinGordon1D", "max_issues_repo_head_hexsha": "ce6ba332e542d74b72069ae253cca5e0a2ade425", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Codes/Fortran1DFourierCompactR2C/initialdata.f90", "max_forks_repo_name": "bkmgit/KleinGordon1D", "max_forks_repo_head_hexsha": "ce6ba332e542d74b72069ae253cca5e0a2ade425", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.7285714286, "max_line_length": 74, "alphanum_fraction": 0.5241532482, "num_tokens": 614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762114, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7660089863502401}} {"text": "!> Contains procedures for creating positions of molecules on a periodic\n!! crystal lattice.\nmodule m_crystal\nimplicit none\n\ncontains\n\n!> Returns positions @p xs, @p ys, @p zs for a hexagonally close-packed\n!! crystal with @p nx, @p ny and @p nz particles in x-, y- and\n!! z-directions, respectively. The distance between particles in the\n!! hexagonal layers is @p a and the distance between layers is @p d.\n!! If @p center is .true. the coordinates are transformed so that the\n!! origin is in the middle of the crystal. Otherwise all coordinates are\n!! non-negative.\n!! \n!! @post xs(i), ys(i), zs(i) is the position of the i:th point (or\n!! particle) in the crystal.\n!!\nsubroutine hexagonally_close_packed(nx, ny, nz, a, d, center, xs, ys, zs)\n integer, intent(in) :: nx, ny, nz\n real(8), intent(in) :: a, d\n logical, intent(in) :: center\n real(8), intent(out) :: xs(nx, ny, nz), ys(nx, ny, nz), zs(nx, ny, nz)\n integer :: i\n real(8) :: h !< The distance between adjacent rows in the same layer\n real(8) :: m !< The distance between corresponding rows in adjacent\n !< layers.\n xs = 0.0\n ys = 0.0\n zs = 0.0\n !! First create coordinates, then center.\n !! Create first row in first layer\n xs(:, 1, 1) = [(i * a, i = 0, nx - 1)]\n !! Create other rows in the first layer\n do i = 3, ny, 2\n xs(:, i, 1) = xs(:, 1, 1)\n end do\n do i = 2, ny, 2\n xs(:, i, 1) = xs(:, 1, 1) + 0.5 * a\n end do\n\n h = sqrt(3.0) / 2 * a\n do i = 1, ny\n ys(:, i, 1) = (i - 1) * h\n end do\n\n !! Add distances between layers\n do i = 1, nz\n zs(:, :, i) = (i - 1) * d\n end do\n\n !! For every other layer, x and y are the same.\n !! Odd layers:\n do i = 1, nz, 2\n xs(:, :, i) = xs(:, :, 1)\n ys(:, :, i) = ys(:, :, 1)\n end do\n m = a / (2 * sqrt(3.0))\n !! Even layers:\n do i = 2, nz, 2\n xs(:, :, i) = xs(:, :, 1) + 0.5 * a\n ys(:, :, i) = ys(:, :, 1) + m\n end do\n if (center) then\n xs = xs - maxval(xs) / 2.0\n ys = ys - maxval(ys) / 2.0\n zs = zs - maxval(zs) / 2.0\n end if\nend subroutine hexagonally_close_packed\n\nend module m_crystal\n\n\n", "meta": {"hexsha": "1e0c10d4d962aa4b9452c6ac692f876fd0c03c09", "size": 2083, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/crystal.f90", "max_stars_repo_name": "jonekoo/CoarseMC", "max_stars_repo_head_hexsha": "7f9d032fe8f7e45a3cab857cd38de33c05f4b7c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/crystal.f90", "max_issues_repo_name": "jonekoo/CoarseMC", "max_issues_repo_head_hexsha": "7f9d032fe8f7e45a3cab857cd38de33c05f4b7c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/crystal.f90", "max_forks_repo_name": "jonekoo/CoarseMC", "max_forks_repo_head_hexsha": "7f9d032fe8f7e45a3cab857cd38de33c05f4b7c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1486486486, "max_line_length": 73, "alphanum_fraction": 0.5756120979, "num_tokens": 750, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793453, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.7660089852734356}} {"text": "\nprogram era_sieve\n\nimplicit none\ninteger*4 :: N ! The natural number up to which prime numbers will be calculated\ninteger*4 :: ii, jj ! indexing variables\ninteger*4 :: allocate_status\nlogical, allocatable :: is_prime(:)\nlogical :: true = 1.gt.0, false = 0.gt.1\n\nwrite(*,*) \"Up to which number do you wish to get primes? Enter an integer N>=2.\"\nread(*,*) N\n\n! N should be at least 2\nif (N.lt.2) stop \"***The upper limit should be at least 2***\"\n\nallocate(is_prime(2:N),stat = allocate_status)\nif (allocate_status .ne. 0) stop \"***Not enough memory to allocate sieve vector***\"\nis_prime = (/(true, ii =2, N)/)\n\nii = 2\n\n! Eratosthenes Sieve\ndo while (ii .le. sqrt(real(N,4))) ! Casting N as real to calculate sqrt(N)\n\tif (is_prime(ii)) then\n\t\tjj = ii**2\n\t\tdo while (jj .le. N) ! Spotting multiples of ii starting from ii**2\n\t\t\tis_prime(jj) = false\n\t\t\tjj = jj + ii\n\t\tend do\n\tend if\n\tii = ii + 1\nend do\n\n\ndo ii = 2,N\n\tif (is_prime(ii)) then\n\t\twrite(*,*) ii\n\tend if\nend do\n\nwrite(*,*) \"Enter any number to normally exit the program.\"\nread(*,*) N\n\nend program era_sieve\n", "meta": {"hexsha": "d0543d4debf97395b0c81582dabffef95405dcf3", "size": 1064, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "week_1/setup/first_program.f90", "max_stars_repo_name": "eigen-carmona/quantum-computation-unipd", "max_stars_repo_head_hexsha": "f53b40bd83cb85119ce4b494e10e01b256917659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-01-11T19:41:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-05T19:22:24.000Z", "max_issues_repo_path": "week_1/setup/first_program.f90", "max_issues_repo_name": "eigen-carmona/quantum-computation-unipd", "max_issues_repo_head_hexsha": "f53b40bd83cb85119ce4b494e10e01b256917659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week_1/setup/first_program.f90", "max_forks_repo_name": "eigen-carmona/quantum-computation-unipd", "max_forks_repo_head_hexsha": "f53b40bd83cb85119ce4b494e10e01b256917659", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.1304347826, "max_line_length": 83, "alphanum_fraction": 0.6663533835, "num_tokens": 340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.7659643653496234}} {"text": " subroutine mapc2m_bilinear(blockno,xc,yc,xp,yp,zp,center)\n implicit none\n\n double precision xc,yc,xp,yp,zp\n integer blockno\n double precision center(2)\n\n double precision quad(0:1,0:1,2)\n double precision a00(2), a01(2),a10(2), a11(2)\n double precision ll(2), lr(2), ul(2), ur(2)\n double precision shiftx(0:3), shifty(0:3)\n integer m, i, j\n\n data ll/0,0/, ul/0, 1/, lr/1, 0/, ur/1,1/\n data shiftx/-1,0,-1,0/, shifty/-1,-1,0,0/\n\nc # Maps [0,1]x[0,1] to a bilinear map with physical \nc # corners at [quad(0,0,:), quad(0,1,:), quad(1,0,:), quad(1,1,:)]\n \n\n do m = 1,2\n quad(0,0,m) = ll(m)\n quad(1,0,m) = lr(m)\n quad(0,1,m) = ul(m)\n quad(1,1,m) = ur(m)\n enddo\n\n do i = 0,1\n do j = 0,1\n quad(i,j,1) = quad(i,j,1) + shiftx(blockno)\n quad(i,j,2) = quad(i,j,2) + shifty(blockno)\n enddo\n enddo\n\n do m = 1,2\n if (blockno .eq. 0) then \n quad(1,1,m) = center(m)\n elseif (blockno .eq. 1) then\n quad(0,1,m) = center(m)\n elseif (blockno .eq. 2) then\n quad(1,0,m) = center(m)\n elseif (blockno .eq. 3) then\n quad(0,0,m) = center(m)\n endif\n enddo\n\n do m = 1,2\n a00(m) = quad(0,0,m)\n a01(m) = quad(1,0,m) - quad(0,0,m)\n a10(m) = quad(0,1,m) - quad(0,0,m)\n a11(m) = quad(1,1,m) - quad(1,0,m) -\n & quad(0,1,m) + quad(0,0,m)\n enddo\n\nc # T(xi,eta) = a00 + a01*xi + a10*eta + a11*xi*eta\n\n xp = a00(1) + a01(1)*xc + a10(1)*yc + a11(1)*xc*yc\n yp = a00(2) + a01(2)*xc + a10(2)*yc + a11(2)*xc*yc\n zp = 0\n\n\n end\n", "meta": {"hexsha": "dcd5ca72620df232f3e1e8d9dccd40572a66e390", "size": 1728, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/mappings/bilinear/mapc2m_bilinear.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "src/mappings/bilinear/mapc2m_bilinear.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "src/mappings/bilinear/mapc2m_bilinear.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 27.4285714286, "max_line_length": 71, "alphanum_fraction": 0.4658564815, "num_tokens": 696, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947070591979, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7658982832024924}} {"text": "program test\n\n use stochoptim, only: Evolutionary\n\n implicit none\n\n real(kind = 8), parameter :: pi = 3.141592653589793238460d0\n integer(kind = 4), parameter :: n_dim = 5, popsize = 10, max_iter = 500\n real(kind = 8), dimension(:), allocatable :: lower, upper\n type(Evolutionary) :: ea\n\n ! Define search boundaries\n allocate(lower(n_dim), upper(n_dim))\n lower = -5.12\n upper = 5.12\n\n ! Initialize evolutionary optimizer\n ea = Evolutionary(rastrigin, lower, upper, &\n popsize = popsize, max_iter = max_iter)\n\n ! Optimize\n call ea % optimize(solver = \"cpso\")\n\n ! Display results\n call ea % print()\n\ncontains\n\n function rastrigin(x) result(f)\n real(kind = 8), dimension(:), intent(in) :: x\n integer(kind = 4) :: n_dim\n real(kind = 8) :: f, sum1\n\n n_dim = size(x)\n sum1 = sum( x**2 - 10.0d0 * cos( 2.0d0 * pi * x ) )\n f = 10.0d0 * n_dim + sum1\n return\n end function rastrigin\n\nend program test\n", "meta": {"hexsha": "34b550ad2e9e7fbd8779b224e7340662ad843792", "size": 948, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/test.f90", "max_stars_repo_name": "keurfonluu/StochOptim", "max_stars_repo_head_hexsha": "3c80a7aa86c950187fa5c78e849688043930e01c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2018-11-10T14:48:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-02T10:10:13.000Z", "max_issues_repo_path": "src/tests/test.f90", "max_issues_repo_name": "eachonly/StochOptim", "max_issues_repo_head_hexsha": "3c80a7aa86c950187fa5c78e849688043930e01c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/tests/test.f90", "max_forks_repo_name": "eachonly/StochOptim", "max_forks_repo_head_hexsha": "3c80a7aa86c950187fa5c78e849688043930e01c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-11-10T14:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-17T16:04:25.000Z", "avg_line_length": 23.1219512195, "max_line_length": 73, "alphanum_fraction": 0.6297468354, "num_tokens": 309, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314624993576758, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7658383424606903}} {"text": "SUBROUTINE rmax ( a, n, real_max, imax )\r\n!\r\n! Purpose:\r\n! To find the maximum value in an array, and the location\r\n! of that value in the array.\r\n!\r\nIMPLICIT NONE\r\n\r\n! Data dictionary: declare calling parameter types & definitions\r\nINTEGER, INTENT(IN) :: n ! No. of vals in array a.\r\nREAL, INTENT(IN), DIMENSION(n) :: a ! Input data.\r\nREAL, INTENT(OUT) :: real_max ! Maximum value in a.\r\nINTEGER, INTENT(OUT) :: imax ! Location of max value.\r\n\r\n! Data dictionary: declare local variable types & definitions\r\nINTEGER :: i ! Index variable\r\n\r\n! Initialize the maximum value to first value in array.\r\nreal_max = a(1)\r\nimax = 1\r\n \r\n! Find the maximum value.\r\nDO i = 2, n\r\n IF ( a(i) > real_max ) THEN\r\n real_max = a(i)\r\n imax = i\r\n END IF\r\nEND DO\r\n\r\nEND SUBROUTINE rmax\r\n\r\n\r\nSUBROUTINE rmin ( a, n, real_min, imin )\r\n!\r\n! Purpose:\r\n! To find the minimum value in an array, and the location\r\n! of that value in the array.\r\n!\r\nIMPLICIT NONE\r\n\r\n! Data dictionary: declare calling parameter types & definitions\r\nINTEGER, INTENT(IN) :: n ! No. of vals in array a.\r\nREAL, INTENT(IN), DIMENSION(n) :: a ! Input data.\r\nREAL, INTENT(OUT) :: real_min ! Minimum value in a.\r\nINTEGER, INTENT(OUT) :: imin ! Location of min value.\r\n\r\n! Data dictionary: declare local variable types & definitions\r\nINTEGER :: i ! Index variable\r\n\r\n! Initialize the minimum value to first value in array.\r\nreal_min = a(1)\r\nimin = 1\r\n \r\n! Find the minimum value.\r\nDO I = 2, n\r\n IF ( a(i) < real_min ) THEN\r\n real_min = a(i)\r\n imin = i\r\n END IF\r\nEND DO\r\n\r\nEND SUBROUTINE rmin\r\n\r\n\r\nSUBROUTINE ave_sd ( a, n, ave, std_dev, error )\r\n!\r\n! Purpose:\r\n! To calculate the average and standard deviation of an array.\r\n!\r\nIMPLICIT NONE\r\n\r\n! Data dictionary: declare calling parameter types & definitions\r\nINTEGER, INTENT(IN) :: n ! No. of vals in array a.\r\nREAL, INTENT(IN), DIMENSION(n) :: a ! Input data.\r\nREAL, INTENT(OUT) :: ave ! Average of a.\r\nREAL, INTENT(OUT) :: std_dev ! Standard deviation.\r\nINTEGER, INTENT(OUT) :: error ! Flag: 0 -- no error\r\n ! 1 -- sd invalid\r\n ! 2 -- ave & sd invalid\r\n\r\n! Data dictionary: declare local variable types & definitions\r\nINTEGER :: i ! Loop index\r\nREAL :: sum_x ! Sum of input values\r\nREAL :: sum_x2 ! Sum of input values squared\r\n\r\n! Initialize the sums to zero.\r\nsum_x = 0.\r\nsum_x2 = 0.\r\n \r\n! Accumulate sums.\r\nDO I = 1, n\r\n sum_x = sum_x + a(i)\r\n sum_x2 = sum_x2 + a(i)**2\r\nEND DO\r\n \r\n! Check to see if we have enough input data.\r\nIF ( n >= 2 ) THEN ! we have enough data\r\n \r\n ! Calculate the mean and standard deviation\r\n ave = sum_x / REAL(n)\r\n std_dev = SQRT( (REAL(n) * sum_x2 - sum_x**2) &\r\n / (REAL(n) * REAL(n-1)) )\r\n error = 0\r\n \r\nELSE IF ( n == 1 ) THEN ! no valid std_dev\r\n \r\n ave = sum_x \r\n std_dev = 0. ! std_dev invalid\r\n error = 1\r\n \r\nELSE\r\n \r\n ave = 0. ! ave invalid\r\n std_dev = 0. ! std_dev invalid\r\n error = 2\r\n\r\nEND IF\r\nEND SUBROUTINE ave_sd\r\n\r\n\r\nSUBROUTINE median ( a, n, med )\r\n!\r\n! Purpose:\r\n! To calculate the median value of an array.\r\n!\r\nIMPLICIT NONE\r\n\r\n! Data dictionary: declare calling parameter types & definitions\r\nINTEGER, INTENT(IN) :: n ! No. of vals in array a.\r\nREAL, INTENT(IN), DIMENSION(n) :: a ! Input data.\r\nREAL, INTENT(OUT) :: med ! Median value of a.\r\n\r\n! Sort the data into ascending order.\r\nCALL sort ( a, n )\r\n \r\n! Get median.\r\nIF ( MOD(n,2) == 0 ) THEN\r\n med = ( a(n/2) + a(n/2+1) ) / 2.\r\nELSE\r\n med = a(n/2+1)\r\nEND IF\r\nEND SUBROUTINE median\r\n", "meta": {"hexsha": "03f4b62c48cd9c9c12b8ce19bf3196c1d7888249", "size": 3865, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap7/fig6-7.f90", "max_stars_repo_name": "yangyang14641/FortranLearning", "max_stars_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-03-12T02:18:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-05T07:58:56.000Z", "max_issues_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap7/fig6-7.f90", "max_issues_repo_name": "yangyang14641/FortranLearning", "max_issues_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap7/fig6-7.f90", "max_forks_repo_name": "yangyang14641/FortranLearning", "max_forks_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-05-11T02:36:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T06:36:55.000Z", "avg_line_length": 27.027972028, "max_line_length": 67, "alphanum_fraction": 0.5666235446, "num_tokens": 1059, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.8947894696095783, "lm_q1q2_score": 0.7658066004393483}} {"text": "\nmodule gamma_dist\n use gamma\n implicit none\n private p_gamma, q_gamma\ncontains\n\n function logpdf_gamma(shape, rate, x, lgamshape) result(result)\n double precision, intent(in) :: shape, rate, x, lgamshape\n double precision :: result\n result = shape * log(rate) + (shape-1.0d0) * log(x) - rate * x - lgamshape\n end function logpdf_gamma\n\n function pdf_gamma(shape, rate, x, lgamshape) result(result)\n double precision, intent(in) :: shape, rate, x, lgamshape\n double precision :: result\n result = exp(logpdf_gamma(shape, rate, x, lgamshape))\n end function pdf_gamma\n\n function p_gamma(a, x, loggamma_a)\n double precision, intent(in) :: a, x, loggamma_a\n double precision :: p_gamma\n integer :: k\n double precision :: res, term, previous\n if (x >= 1.0d0 + a) then\n p_gamma = 1.0d0 - q_gamma(a, x, loggamma_a)\n return\n end if\n if (x == 0.0d0) then\n p_gamma = 0.0d0\n return\n end if\n term = exp(a * log(x) - x - loggamma_a) / a\n res = term\n do k = 1, 1000\n term = term * x / (a+k)\n previous = res\n res = res + term\n if (res == previous) then\n p_gamma = res\n return\n end if\n end do\n p_gamma = res\n end function p_gamma\n\n function q_gamma(a, x, loggamma_a)\n double precision, intent(in) :: a, x, loggamma_a\n double precision :: q_gamma\n integer :: k\n double precision :: res, w, temp, previous, la, lb\n la = 1.0d0\n lb = 1.0d0 + x - a\n if (x < 1.0d0 + a) then\n q_gamma = 1.0d0 - p_gamma(a, x, loggamma_a)\n return\n end if\n w = exp(a * log(x) - x - loggamma_a)\n res = w / lb\n do k = 2, 1000\n temp = ((k-1.0d0-a)*(lb-la) + (x+k)*lb)/k\n la = lb\n lb = temp\n w = w * (k-1.0d0-a)/k\n temp = w / (la * lb)\n previous = res\n res = res + temp\n if (res == previous) then\n q_gamma = res\n return\n end if\n end do\n q_gamma = res\n end function q_gamma\n\n function cdf_gamma(shape, rate, x, lgamshape) result(result)\n double precision, intent(in) :: shape, rate, x, lgamshape\n double precision :: result\n result = p_gamma(shape, rate*x, lgamshape)\n end function cdf_gamma\n\n function ccdf_gamma(shape, rate, x, lgamshape) result(result)\n double precision, intent(in) :: shape, rate, x, lgamshape\n double precision :: result\n result = q_gamma(shape, rate*x, lgamshape)\n end function ccdf_gamma\n\nend module gamma_dist\n\n\n", "meta": {"hexsha": "cd689ad365a858f81eb67d11c33ade2edfb83ad7", "size": 2474, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "math/gamma_dist_mod.f90", "max_stars_repo_name": "okamumu/Markov.core", "max_stars_repo_head_hexsha": "3de31b2f7e02da6a2da71183154bd7c6fac0752c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "math/gamma_dist_mod.f90", "max_issues_repo_name": "okamumu/Markov.core", "max_issues_repo_head_hexsha": "3de31b2f7e02da6a2da71183154bd7c6fac0752c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math/gamma_dist_mod.f90", "max_forks_repo_name": "okamumu/Markov.core", "max_forks_repo_head_hexsha": "3de31b2f7e02da6a2da71183154bd7c6fac0752c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.1868131868, "max_line_length": 78, "alphanum_fraction": 0.5990299111, "num_tokens": 790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.926303732328411, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7657862204075815}} {"text": "MODULE MULTIPOLE\n\n USE CONSTANTS\n USE FACT\n USE GAUSSIAN\n USE OVERLAP\n\n IMPLICIT NONE\n\n CONTAINS\n\n\n FUNCTION Sije(e,a,b,aa,bb,Rai,Rbi,Rpi,Rci)\n ! --------------------------------------------------\n ! Compute dipole moment of order E along direction I\n ! --------------------------------------------------\n !\n ! Source:\n ! T. Helgaker, P. Jørgensen and J. Olsen\n ! Molecular Electronic-Structure Theory\n ! Wiley\n ! 2000\n !\n ! ---------------------------------------------------\n\n IMPLICIT NONE\n\n ! INPUT\n INTEGER, intent(in) :: e ! Dipole order\n INTEGER, intent(in) :: a,b ! Angular momentum coefficients of the Gaussians along direction i\n REAL*8, intent(in) :: aa, bb ! Exponential coefficients of the Gaussians\n REAL*8, intent(in) :: Rai, Rbi ! Centers of the Gaussians\n REAL*8, intent(in) :: Rpi ! Center of Gaussian product\n REAL*8, intent(in) :: Rci ! Center of the multipole\n\n ! INTERMEDIATE VARIABLE\n REAL*8, dimension(-1:a+1,-1:b+1,-1:e+1) :: S ! Vector of overlap coefficients\n INTEGER :: i, j, k\n REAL*8 :: factor\n\n ! OUTPUT\n REAL*8 :: Sije ! Dipole integral\n\n S(-1,:,:) = 0.0D0\n S(:,-1,:) = 0.0D0\n S(:,:,-1) = 0.0D0\n\n S(0,0,0) = S00(aa,bb,Rai,Rbi)\n\n DO i = 0, a\n DO j = 0, b\n DO k = 0, e\n factor = 1.0D0 / (2 * (aa+bb)) * (i * S(i-1,j,k) + j * S(i,j-1,k) + k * S(i,j,k-1))\n\n S(i+1,j,k) = (Rpi - Rai) * S(i,j,k) + factor\n S(i,j+1,k) = (Rpi - Rbi) * S(i,j,k) + factor\n S(i,j,k+1) = (Rpi - Rci) * S(i,j,k) + factor\n END DO\n END DO\n END DO\n\n Sije = S(a,b,e)\n\n END FUNCTION Sije\n\n FUNCTION multipole_coeff_OS(ax,ay,az,bx,by,bz,aa,bb,Ra,Rb,e,f,g,Rc) result(S)\n ! -------------------------------------------------------------------\n ! Compute multipole integral between two Cartesian Gaussian functions\n ! -------------------------------------------------------------------\n !\n ! Source:\n ! T. Helgaker, P. Jørgensen and J. Olsen\n ! Molecular Electronic-Structure Theory\n ! Wiley\n ! 2000\n !\n ! -------------------------------------------------------------------\n\n IMPLICIT NONE\n\n ! INPUT\n INTEGER, intent(in) :: ax, ay, az, bx, by, bz ! Angular momentum coefficients\n REAL*8, intent(in) :: aa, bb ! Exponential Gaussian coefficients\n REAL*8, dimension(3), intent(in) :: Ra, Rb ! Gaussian centers\n INTEGER , intent(in) :: e, f, g ! Multipole order along x, y and z\n REAL*8, dimension(3), intent(in) :: Rc ! Multipole center\n\n ! INTERMEDIATE VARIABLES\n REAL*8 :: pp ! Gaussian produc exponential coefficient\n REAL*8, dimension(3) :: Rp ! Gaussian produc center\n REAL*8 :: cp ! Gaussian product multiplicative constant\n\n ! OUTPUT\n REAL*8 :: S\n\n CALL gaussian_product(aa,bb,Ra,Rb,pp,Rp,cp) ! Compute PP, RP and CP\n\n S = 1\n S = S * Sije(e,ax,bx,aa,bb,Ra(1),Rb(1),Rp(1),Rc(1)) ! Overlap along x\n S = S * Sije(f,ay,by,aa,bb,Ra(2),Rb(2),Rp(2),Rc(2)) ! Overlap along y\n S = S * Sije(g,az,bz,aa,bb,Ra(3),Rb(3),Rp(3),Rc(3)) ! Overlap along z\n S = S * norm(ax,ay,az,aa) * norm(bx,by,bz,bb) ! Normalization of Gaussian functions\n\n END FUNCTION multipole_coeff_OS\n\n SUBROUTINE S_multipole_i(Kf,c,basis_D,basis_A,basis_L,basis_R,dir,e,R,S)\n ! ----------------------------------------------\n ! Compute overlap matrix between basis function.\n ! ----------------------------------------------\n\n IMPLICIT NONE\n\n ! TODO Allow flexibility for basis sets other than STO-3G\n INTEGER, intent(in) :: c ! Number of contractions per basis function\n\n ! INPUT\n INTEGER, intent(in) :: Kf ! Number of basis functions\n REAL*8, dimension(Kf,3), intent(in) :: basis_R ! Basis set niclear positions\n INTEGER, dimension(Kf,3), intent(in) :: basis_L ! Basis set angular momenta\n REAL*8, dimension(Kf,3), intent(in) :: basis_D ! Basis set contraction coefficients\n REAL*8, dimension(Kf,3), intent(in) :: basis_A ! Basis set exponential contraction coefficients\n REAL*8, dimension(3), intent(in) :: R ! Multipole center\n INTEGER, intent(in) :: dir ! Multipole direction\n INTEGER, intent(in) :: e ! Multipole exponent along direction DIR\n\n ! INTERMEDIATE VARIABLES\n INTEGER :: i,j,k,l\n REAL*8 :: tmp\n INTEGER, dimension(3) :: multi_dir ! Mulrtipole exponent along direction DIR\n\n ! OUTPUT\n REAL*8, dimension(Kf,Kf), intent(out) :: S\n\n IF (dir .EQ. 1) THEN\n\n multi_dir = (/e, 0, 0/)\n\n ELSE IF (dir .EQ. 2) THEN\n\n multi_dir = (/0, e, 0/)\n\n ELSE IF (dir .EQ. 3) THEN\n\n multi_dir = (/0, 0, e/)\n\n END IF\n\n S(:,:) = 0.0D0\n\n DO i = 1,Kf\n DO j = 1,Kf\n DO k = 1,c\n DO l = 1,c\n tmp = basis_D(i,k) * basis_D(j,l)\n tmp = tmp * multipole_coeff_OS( basis_L(i,1),& ! lx for basis function i\n basis_L(i,2),& ! ly for basis function i\n basis_L(i,3),& ! lz for basis function i\n basis_L(j,1),& ! lx for basis function j\n basis_L(j,2),& ! ly for basis function j\n basis_L(j,3),& ! lz for basis function j\n basis_A(i,k),& ! Exponential coefficient for basis function i, contraction k\n basis_A(j,l),& ! Exponential coefficient for basis function j, contraction l\n basis_R(i,:),& ! Center of basis function i\n basis_R(j,:),& ! Center of basis function j\n multi_dir(1),& ! Multipole exponent along x\n multi_dir(2),& ! Multipole exponent along y\n multi_dir(3),& ! Multipole exponent along z\n R) ! Multipole center\n\n S(i,j) = S(i,j) + tmp\n END DO ! l\n END DO ! k\n END DO ! j\n END DO ! i\n\n END SUBROUTINE S_multipole_i\n\n SUBROUTINE dipole(Kf,c,Nn,basis_D,basis_A,basis_L,basis_R,P,Rn,Zn,mu)\n ! ----------------------------\n ! Compute multipole vector\n ! ----------------------------\n !\n ! Source:\n ! A. Szabo and N. S. Ostlund\n ! Modern Quantum Chemistry\n ! Dover\n ! 1996\n !\n ! ----------------------------\n\n ! TODO Allow flexibility for basis sets other than STO-3G\n INTEGER, intent(in) :: c ! Number of contractions per basis function\n\n ! INPUT\n INTEGER, intent(in) :: Kf ! Number of basis functions\n INTEGER, intent(in) :: Nn ! Number of nuclei\n REAL*8, dimension(Kf,3), intent(in) :: basis_R ! Basis set niclear positions\n INTEGER, dimension(Kf,3), intent(in) :: basis_L ! Basis set angular momenta\n REAL*8, dimension(Kf,3), intent(in) :: basis_D ! Basis set contraction coefficients\n REAL*8, dimension(Kf,3), intent(in) :: basis_A ! Basis set exponential contraction coefficients\n REAL*8, dimension(Kf,Kf), intent(in) :: P ! Density matrix\n REAL*8, dimension(Nn,3), intent(in) :: Rn ! Nuclear positions\n INTEGER, dimension(Nn), intent(in) :: Zn\n\n ! INTERMEDIATE VARIABLES\n REAL*8, dimension(Kf,Kf) :: S\n REAL*8, dimension(3) :: R\n INTEGER :: i, j, k\n\n ! OUTPUT\n REAL*8, dimension(3), intent(out) :: mu\n\n mu(:) = 0.0D0\n\n R(:) = 0.0D0\n\n ! -----------\n ! X component\n ! -----------\n CALL S_multipole_i(Kf,c,basis_D,basis_A,basis_L,basis_R,1,1,R,S)\n\n DO i = 1, Kf\n DO j = 1, Kf\n mu(1) = mu(1) - P(i,j) * S(j,i)\n END DO\n END DO\n\n ! -----------\n ! Y component\n ! -----------\n CALL S_multipole_i(Kf,c,basis_D,basis_A,basis_L,basis_R,2,1,R,S)\n\n DO i = 1, Kf\n DO j = 1, Kf\n mu(2) = mu(2) - P(i,j) * S(j,i)\n END DO\n END DO\n\n ! -----------\n ! Z component\n ! -----------\n CALL S_multipole_i(Kf,c,basis_D,basis_A,basis_L,basis_R,3,1,R,S)\n\n DO i = 1, Kf\n DO j = 1, Kf\n mu(3) = mu(3) - P(i,j) * S(j,i)\n END DO\n END DO\n\n ! Take into account nuclear charges\n DO k = 1, Nn\n mu = mu + Zn(k) * Rn(k,:)\n END DO\n\n END SUBROUTINE\n\n\nEND MODULE MULTIPOLE\n", "meta": {"hexsha": "fd89028b950cd2b9c5250899b94af944c23f7219", "size": 9754, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran90/multipole.f90", "max_stars_repo_name": "RMeli/Hartree-Fock", "max_stars_repo_head_hexsha": "dda0102ab2a88f3f2f666c2479a858140505ea60", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2016-09-16T09:26:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T16:09:53.000Z", "max_issues_repo_path": "Fortran90/multipole.f90", "max_issues_repo_name": "RMeli/Hartree-Fock", "max_issues_repo_head_hexsha": "dda0102ab2a88f3f2f666c2479a858140505ea60", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran90/multipole.f90", "max_forks_repo_name": "RMeli/Hartree-Fock", "max_forks_repo_head_hexsha": "dda0102ab2a88f3f2f666c2479a858140505ea60", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2016-01-20T13:47:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-28T03:18:22.000Z", "avg_line_length": 37.6602316602, "max_line_length": 133, "alphanum_fraction": 0.4364363338, "num_tokens": 2500, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7657862170437583}} {"text": "\r\nSUBROUTINE decsf(x,y,zz,fi0,tet0,FI,TET,h)\r\n! this program calculates fi and tet of a point in global coordinates from\r\n! given x, y, z coordinates relatively the point fi0, tet0\r\nREAL PI/3.1415926/, rz/6371./\r\nPER=PI/180.\r\n\r\n\r\nsqr=(rz-zz)*(rz-zz)-x*x-y*y\r\n\r\n!write(*,*)' dz=',rz-sqrt(sqr)\r\n\r\nif(sqr.lt.0.) then\t\r\n\twrite(*,*)' problem in DECSF:'\r\n\twrite(*,*)' x=',x,' y=',y,' zz=',zz\r\n\tpause\r\nend if\r\n\r\nz=sqrt(sqr)\r\n!write(*,*)' z=',z,'sqr=',sqr\r\nX1=x\r\nY1=-Y*SIN(tet0*PER)+Z*COS(tet0*PER)\r\nZ1=Y*COS(tet0*PER)+Z*SIN(tet0*PER)\r\n!write(*,*)' x1=',x1,' y1=',y1,' z1=',z1\r\nif(x1.eq.0.) then\r\n\tfi=fi0\r\nelse\r\n\tIF(X1.GT.0..AND.Y1.GT.0.)PA=0.\r\n\tIF(X1.LT.0.)PA=-PI\r\n\tIF(X1.GT.0..AND.Y1.LT.0.)PA=2.*PI\r\n\tff=atan(y1/x1)/per\r\n\tFI=fi0-(ff+PA/PER)+90.\r\nend if\r\n!write(*,*)' fi=',fi\r\nif(fi.gt.360.)fi=fi-360.\r\n\r\nif(abs(fi-fi0).gt.abs(fi-fi0-360)) fi=fi-360\r\nif(abs(fi-fi0).gt.abs(fi-fi0+360)) fi=fi+360\r\n\r\nr=sqrt(x1*x1+y1*y1+z1*z1)\r\nTET=ASIN(Z1/r)/PER\r\nh=rz-r\r\nRETURN\r\nEND\r\n\r\n", "meta": {"hexsha": "28aa7cf552a92809b035fa02b2c9dadf3b5c5d58", "size": 962, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "PROGRAMS/subr/convers/decsf.f90", "max_stars_repo_name": "ilyasnsk/colima_lotos_2019", "max_stars_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-28T06:16:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-16T02:52:23.000Z", "max_issues_repo_path": "PROGRAMS/subr/convers/decsf.f90", "max_issues_repo_name": "ilyasnsk/colima_lotos_2019", "max_issues_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PROGRAMS/subr/convers/decsf.f90", "max_forks_repo_name": "ilyasnsk/colima_lotos_2019", "max_forks_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.9130434783, "max_line_length": 75, "alphanum_fraction": 0.5893970894, "num_tokens": 439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9783846640860381, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.7657449665631156}} {"text": " SUBROUTINE GAULEG(X1,X2,X,W,N)\n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*4 X1,X2,X(N),W(N)\nC given the lower and upper limits of the integration, X1 and X2, and N (n-points Gaussian),\nC this routine returns arrays X(1:N) and W(1:N), the adscissas and weights of \nC the Gauss-Legendre n-point quadrature formula.\n PARAMETER (EPS=3.D-14)\n M=(N+1)/2\n XM=0.5D0*(X2+X1)\n XL=0.5D0*(X2-X1)\n DO 12 I=1,M\n Z=COS(3.141592654D0*(I-.25D0)/(N+.5D0))\n1 CONTINUE\n P1=1.D0\n P2=0.D0\n DO 11 J=1,N\n P3=P2\n P2=P1\n P1=((2.D0*J-1.D0)*Z*P2-(J-1.D0)*P3)/J\n11 CONTINUE\n PP=N*(Z*P1-P2)/(Z*Z-1.D0)\n Z1=Z\n Z=Z1-P1/PP\n IF(ABS(Z-Z1).GT.EPS)GO TO 1\n X(I)=XM-XL*Z\n X(N+1-I)=XM+XL*Z\n W(I)=2.D0*XL/((1.D0-Z*Z)*PP*PP)\n W(N+1-I)=W(I)\n12 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "2b02b35472f9af7cf92a4958cdfbd19b982e1b7e", "size": 910, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/source/gauleg.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/source/gauleg.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/source/gauleg.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.4375, "max_line_length": 92, "alphanum_fraction": 0.4989010989, "num_tokens": 380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750400464604, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7656455351319845}} {"text": "C The actual YPRIME subroutine in FORTRAN\nC\nC Copyright 1984-2000 The MathWorks, Inc.\nC \nC\n\n SUBROUTINE YPRIME(YP, T, Y)\n REAL*8 YP(4), T, Y(4)\n\n REAL*8 MU, MUS, R1, R2\n \n MU = 1.0/82.45\n MUS = 1.0 - MU\n\n R1 = SQRT((Y(1)+MU)**2 + Y(3)**2)\n R2 = SQRT((Y(1)-MUS)**2 + Y(3)**2)\n\n YP(1) = Y(2)\n YP(2) = 2*Y(4) + Y(1) - MUS*(Y(1)+MU)/(R1**3) - \n & MU*(Y(1)-MUS)/(R2**3)\n\n YP(3) = Y(4)\n YP(4) = -2*Y(2) + Y(3) - MUS*Y(3)/(R1**3) - \n & MU*Y(3)/(R2**3)\n\n RETURN\n END\n\n", "meta": {"hexsha": "4124975b6397bc326fc2af7fd15e5d44c520ee4e", "size": 538, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "matlab/matlab_mex/src_mex/matlab_examples/yprimef.f", "max_stars_repo_name": "shadialameddin/numerical_tools_and_friends", "max_stars_repo_head_hexsha": "cc9f10f58886ee286ed89080e38ebd303d3c72a5", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "matlab/matlab_mex/src_mex/matlab_examples/yprimef.f", "max_issues_repo_name": "shadialameddin/numerical_tools_and_friends", "max_issues_repo_head_hexsha": "cc9f10f58886ee286ed89080e38ebd303d3c72a5", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "matlab/matlab_mex/src_mex/matlab_examples/yprimef.f", "max_forks_repo_name": "shadialameddin/numerical_tools_and_friends", "max_forks_repo_head_hexsha": "cc9f10f58886ee286ed89080e38ebd303d3c72a5", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.5517241379, "max_line_length": 54, "alphanum_fraction": 0.4275092937, "num_tokens": 268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810407096791, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7655475599284697}} {"text": "! Modified to add f_quartic and fprime_quartic for quartic function,\n! and to add epsilon as a module variable.\n\nmodule functions\n\n implicit none\n real(kind=8) :: epsilon\n save\n\ncontains\n\nreal(kind=8) function f_sqrt(x)\n implicit none\n real(kind=8), intent(in) :: x\n\n f_sqrt = x**2 - 4.d0\n\nend function f_sqrt\n\n\nreal(kind=8) function fprime_sqrt(x)\n implicit none\n real(kind=8), intent(in) :: x\n \n fprime_sqrt = 2.d0 * x\n\nend function fprime_sqrt\n\nreal(kind=8) function f_quartic(x)\n implicit none\n real(kind=8), intent(in) :: x\n\n f_quartic = (x - 1.d0)**4 - epsilon\n\nend function f_quartic\n\n\nreal(kind=8) function fprime_quartic(x)\n implicit none\n real(kind=8), intent(in) :: x\n \n fprime_quartic = 4.d0 * (x - 1.d0)**3\n\nend function fprime_quartic\n\nend module functions\n", "meta": {"hexsha": "8fb59b2b393f9184899c5c0e31fb34e7f9165a8a", "size": 822, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/2013/solutions/homework3/problem7/functions.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/2013/solutions/homework3/problem7/functions.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/2013/solutions/homework3/problem7/functions.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.4893617021, "max_line_length": 68, "alphanum_fraction": 0.6654501217, "num_tokens": 247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222395, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.7655235422999003}} {"text": "C Polynomial Interpolation subroutine\nC Taken from \"Numerical Recipes\", 2nd Edition by Press, Teukolsky, Vetterling & Flannery.\n\n SUBROUTINE polint(xa,ya,n,x,y,dy)\n\n INTEGER n,NMAX\n REAL dy,x,y,xa(n),ya(n)\nC\tNMAX is the maximum anticipated polynomial order\n PARAMETER (NMAX=10)\n INTEGER i,m,ns\n REAL den,dif,dift,ho,hp,w,c(NMAX),d(NMAX)\n\n ns=1\n dif=abs(x-xa(1))\n do 11 i=1,n\n dift=abs(x-xa(i))\n if (dift.lt.dif) then\n ns=i\n dif=dift\n endif\n c(i)=ya(i)\n d(i)=ya(i)\n11 continue\n y=ya(ns)\n ns=ns-1\n do 13 m=1,n-1\n do 12 i=1,n-m\n ho=xa(i)-x\n hp=xa(i+m)-x\n w=c(i+1)-d(i)\n den=ho-hp\n if(den.eq.0.)write(6,*)'WARNING: polint failed'\n den=w/den\n d(i)=hp*den\n c(i)=ho*den\n12 continue\n if (2*ns.lt.n-m)then\n dy=c(ns+1)\n else\n dy=d(ns)\n ns=ns-1\n endif\n y=y+dy\n13 continue\n return\n END\n", "meta": {"hexsha": "dc9a22c2d82a5232b494846e3a449be0db8db051", "size": 1050, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "corfunc/linux_fortran/tropus/polint.f", "max_stars_repo_name": "scattering-central/CCP13", "max_stars_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corfunc/linux_fortran/tropus/polint.f", "max_issues_repo_name": "scattering-central/CCP13", "max_issues_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corfunc/linux_fortran/tropus/polint.f", "max_forks_repo_name": "scattering-central/CCP13", "max_forks_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-09-05T15:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T11:13:45.000Z", "avg_line_length": 22.3404255319, "max_line_length": 93, "alphanum_fraction": 0.4866666667, "num_tokens": 358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248225478307, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7655235415413101}} {"text": "ccccccccccccccccccccccccccccccccccccccccccccccccccc\nc PROGRAM Quartic\n SUBROUTINE Quartic(q)\nccccccccccccccccccccccccccccccccccccccccccccccccccc\nc Finds the roots of the quartic polynomial c\nc a*q**4 + b*q**2 + c*q + d c\nccccccccccccccccccccccccccccccccccccccccccccccccccc\n IMPLICIT NONE\n\nc Variables\n COMPLEX*16 a, b, c, d, A1, B1, D1, D2, P, QPlus, QMin, q(4), F, G\n\nc PARAMETERS\n DOUBLE PRECISION One, Two, Four, Eight, Twelve, Twnt7, Sevnt2,\n $ Tto1O3, Tto2O3, Root6, amp\nc Integer-double Parameters\n PARAMETER(One = 1.d0, Two = 2.d0, Four = 4.d0, Eight = 8.d0)\n PARAMETER(Twelve = 12.d0, Twnt7 = 27.d0, Sevnt2 = 72.d0)\nc Irrational Parameters - Tto1O3 = 2**(1/3)\nc - Tto1O3 = 2**(2/3)\nc - Root6 = Sqrt(6)\n PARAMETER(Tto1O3 = 1.259921049894873, Tto2O3 = 1.587401051968199)\n PARAMETER(Root6 = 2.449489742783178)\n\n a = q(1)\n b = q(2)\n c = q(3)\n d = q(4)\n\nc a = 1.d0\nc b = 2.d0\nc c = 3.d0\nc d = 4.d0\n\n F = b**2+ Twelve*a*d\n G = Two*b**3 + Twnt7*a*c**2 - Sevnt2*a*b*d\n\n A1 = (G + SQRT(-Four*F**3 + G**2))**(1.d0/3.d0)\n B1 = Two*Tto1O3*F\n\n P = SQRT( (-Four*b + B1/A1 + Tto2O3*A1)/a )\n\n D1 = Eight*b + B1/A1 + Tto2O3*A1\n D2 = Twelve*Root6*c/P\n\n QPlus = SQRT( -(D1 + D2)/a )\n QMin = SQRT( -(D1 - D2)/a )\n\n amp = 1.d0/(Two*Root6)\n\n q(1) = amp*(P - QPlus)\n q(2) = amp*(P + QPlus)\n q(3) = -amp*(P + QMin)\n q(4) = amp*(-P + QMin)\n\nc PRINT*, q(1)\nc PRINT*, q(2)\nc PRINT*, q(3)\nc PRINT*, q(4)\n\n RETURN\n END\n", "meta": {"hexsha": "807a373be775f311b738e3d95f84396c936fa69b", "size": 1694, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH/quartc.f", "max_stars_repo_name": "xraypy/feff85exafs", "max_stars_repo_head_hexsha": "ec8dcb07ca8ee034d0fa7431782074f0f65357a5", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2016-01-05T21:29:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:59:17.000Z", "max_issues_repo_path": "src/MATH/quartc.f", "max_issues_repo_name": "bruceravel/feff85exafs", "max_issues_repo_head_hexsha": "9698ce3703a73def4c1a965f276708d689ea5acb", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2015-01-04T18:37:30.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T12:06:12.000Z", "max_forks_repo_path": "src/MATH/quartc.f", "max_forks_repo_name": "bruceravel/feff85exafs", "max_forks_repo_head_hexsha": "9698ce3703a73def4c1a965f276708d689ea5acb", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2016-01-05T21:29:26.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T13:11:01.000Z", "avg_line_length": 26.8888888889, "max_line_length": 71, "alphanum_fraction": 0.520661157, "num_tokens": 687, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075711974104, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.7655086868171506}} {"text": "program sieve\n use iso_fortran_env\n implicit none\n\n integer(kind=int64), parameter:: i_max = 7812500\n integer(kind=int64), parameter:: b_max = 64*i_max\n integer(kind=int64), parameter:: n_max = 2*b_max+1\n integer(kind=int64), parameter:: n_up = sqrt(real(n_max))+1\n integer(kind=int64), parameter:: b_up = n_up/2\n\n integer(kind=int64):: i, j, b\n integer(kind=int64), dimension(i_max):: is_prime\n\n ! the b-th bit (0-63) of is_prime(i) contains whether\n ! 2*(64*(i-1)+b)+3 is a prime number or not.\n ! The sieve is done on odd numbers from 3 to\n ! 2*b_max+1.\n\n do b = 0, 63\n is_prime(1) = ibset(is_prime(1), b)\n enddo\n is_prime(2:i_max) = is_prime(1)\n\n do b = 1, b_up\n if (.not. btest(is_prime(1+(b-1)/64), mod(b-1, 64))) cycle\n do j = ((2*b+1)**2-1)/2, b_max, 2*b+1\n i = 1 + (j-1)/64\n is_prime(i) = ibclr(is_prime(i), mod(j-1, 64))\n end do\n end do\n\n open(unit=11, file='sieve.out')\n do b = 0, b_max-1\n if (btest(is_prime(1+b/64), mod(b, 64))) write(11, '(I10)') 2*b+3\n end do\n close(11)\nend program sieve\n", "meta": {"hexsha": "c90577fb6927f1a1078a0f6da6cfc035b8903af5", "size": 1127, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sieve.f90", "max_stars_repo_name": "amorison/sieve", "max_stars_repo_head_hexsha": "cff1b6d1b66ad090f3175e212ab6a9b727ef1361", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sieve.f90", "max_issues_repo_name": "amorison/sieve", "max_issues_repo_head_hexsha": "cff1b6d1b66ad090f3175e212ab6a9b727ef1361", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sieve.f90", "max_forks_repo_name": "amorison/sieve", "max_forks_repo_head_hexsha": "cff1b6d1b66ad090f3175e212ab6a9b727ef1361", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.6578947368, "max_line_length": 73, "alphanum_fraction": 0.578527063, "num_tokens": 406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362849986365571, "lm_q2_score": 0.8175744850834648, "lm_q1q2_score": 0.7654827256516556}} {"text": "PROGRAM trajectoire\n\tIMPLICIT NONE\n\t\n\tREAL :: t=0.\n\tINTEGER ::i, n !nombre d'itération\n\tREAL, PARAMETER :: xa=0., ya=10., u0=2., v0=0., deltat=0.1\n\tINTEGER, PARAMETER :: nmax=100000\n\tREAL, PARAMETER :: g=9.81\n\tREAL, DIMENSION(0:nmax) ::u, v, y, x\n\t\n\tu(0)=u0\n\tv(0)=v0\n\tx(0)=xa\n\ty(0)=ya\n\t\n\ti=0\n\tDO WHILE(y(i)>0.)\n\t\ti=i+1 \n\t\tu(i)=u(i-1)\n\t\tv(i)=-g*deltat+v(i-1)\n\t\tx(i) = deltat*u(i)+x(i-1)\n\t\ty(i) = deltat*v(i)+y(i-1) \n\tEND DO \n\tn = i \n\t\n\tPRINT*, \"ti xi yi\"\n\tDO i=0,n\n\t\tPRINT*, i*deltat, x(i), y(i)\n\tEND DO \n\n\tPRINT*, \"Le temps de chute est\", n*deltat, \"et la portée est\", x(n)\t\t\nEND PROGRAM trajectoire\n\t\t\n\t\t\n\t\n", "meta": {"hexsha": "fb5b9b35ad4a1ac4a3e080e3d8a05dce467c8845", "size": 616, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "trajectoire/trajectoire.f90", "max_stars_repo_name": "psekercioglu/fortran90", "max_stars_repo_head_hexsha": "10a3c7fff3dd52ba6e2247bde18f25f8e81bf50d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "trajectoire/trajectoire.f90", "max_issues_repo_name": "psekercioglu/fortran90", "max_issues_repo_head_hexsha": "10a3c7fff3dd52ba6e2247bde18f25f8e81bf50d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "trajectoire/trajectoire.f90", "max_forks_repo_name": "psekercioglu/fortran90", "max_forks_repo_head_hexsha": "10a3c7fff3dd52ba6e2247bde18f25f8e81bf50d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.1111111111, "max_line_length": 70, "alphanum_fraction": 0.5568181818, "num_tokens": 280, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541610257063, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.7654398858002821}} {"text": "MODULE mc_toolbox\r\n\r\n ! Here one can specify parameters to be used by the functions\r\n INTEGER(KIND=4), PARAMETER :: GSEED=12345\r\n REAL(KIND=8), PARAMETER :: MEANVAL=0.00\r\n REAL(KIND=8), PARAMETER :: SDEV=2.00\r\n\r\n CONTAINS\r\n FUNCTION rgamma(a)\r\n ! This function returns a random number with a Gamma PDF using\r\n ! the method described by Marsaglia and Tsang 2000.\r\n IMPLICIT NONE\r\n\r\n ! Data dictionary: Calling parameters\r\n REAL(KIND=8), INTENT(IN) :: a\r\n REAL(KIND=8) :: rgamma\r\n\r\n ! Data dictionary: Local variables\r\n REAL(KIND=8) :: d,c,v\r\n REAL(KIND=8) :: x,u\r\n\r\n d = a-1./3.\r\n c = 1./SQRT(9.*d)\r\n rgamma = 0.\r\n DO\r\n v = 0.\r\n DO WHILE ( v .LE. 0. )\r\n x = R8_NORMAL_AB(MEANVAL,SDEV)\r\n v = 1. + c*x\r\n END DO\r\n! PRINT *, 'x=',x,'and v=',v\r\n v = v*v*v\r\n! u = RANDOM()\r\n CALL RANDOM_NUMBER(u)\r\n IF ( u .LT. 1.-0.331*(x*x)*(x*x) ) THEN\r\n! PRINT *, 'Success-1!'\r\n rgamma = (d*v)\r\n GOTO 10\r\n ELSE IF ( DLOG(u) .LT. 0.5*x*x+d*(1.-v+DLOG(v)) ) THEN\r\n! PRINT *, 'Success-2!'\r\n rgamma = (d*v)\r\n GOTO 10\r\n END IF\r\n END DO\r\n10 RETURN\r\n END FUNCTION rgamma\r\n\r\nFUNCTION r8_normal_01 ()\r\n!*****************************************************************************80\r\n!\r\n!! R8_NORMAL_01 returns a unit pseudonormal R8.\r\n!\r\n! Discussion:\r\n!\r\n! The standard normal probability distribution function (PDF) has\r\n! mean 0 and standard deviation 1.\r\n!\r\n! Licensing:\r\n!\r\n! This code is distributed under the GNU LGPL license.\r\n!\r\n! Modified:\r\n!\r\n! 06 August 2013\r\n!\r\n! Author:\r\n!\r\n! John Burkardt\r\n!\r\n! Parameters:\r\n!\r\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\r\n! number generator.\r\n!\r\n! Output, real ( kind = 8 ) R8_NORMAL_01, a normally distributed\r\n! random value.\r\n!\r\n implicit none\r\n\r\n real ( kind = 8 ) r1\r\n real ( kind = 8 ) r2\r\n real ( kind = 8 ) r8_normal_01\r\n real ( kind = 8 ), parameter :: r8_pi = 3.141592653589793D+00\r\n real ( kind = 8 ) x\r\n\r\n! r1 = RANDOM()\r\n! r2 = RAND()\r\n ! Here we'll use a couple of random numbers generated using the built in\r\n ! RNG of the compiler and previously defined seed\r\n CALL RANDOM_NUMBER(r1)\r\n CALL RANDOM_NUMBER(r2)\r\n x = sqrt( - 2.0D+00 * DLOG( r1 ) ) * cos( 2.0D+00 * r8_pi * r2 )\r\n\r\n r8_normal_01 = x\r\n\r\n return\r\nEND FUNCTION r8_normal_01\r\n\r\nFUNCTION r8_uniform_01 ( seedy )\r\n\r\n!*****************************************************************************80\r\n!\r\n!! R8_UNIFORM_01 returns a unit pseudorandom R8.\r\n!\r\n! Discussion:\r\n!\r\n! This routine implements the recursion\r\n!\r\n! seed = 16807 * seed mod ( 2^31 - 1 )\r\n! r8_uniform_01 = seed / ( 2^31 - 1 )\r\n!\r\n! The integer arithmetic never requires more than 32 bits,\r\n! including a sign bit.\r\n!\r\n! If the initial seed is 12345, then the first three computations are\r\n!\r\n! Input Output R8_UNIFORM_01\r\n! SEED SEED\r\n!\r\n! 12345 207482415 0.096616\r\n! 207482415 1790989824 0.833995\r\n! 1790989824 2035175616 0.947702\r\n!\r\n! Licensing:\r\n!\r\n! This code is distributed under the GNU LGPL license.\r\n!\r\n! Modified:\r\n!\r\n! 31 May 2007\r\n!\r\n! Author:\r\n!\r\n! John Burkardt\r\n!\r\n! Reference:\r\n!\r\n! Paul Bratley, Bennett Fox, Linus Schrage,\r\n! A Guide to Simulation,\r\n! Second Edition,\r\n! Springer, 1987,\r\n! ISBN: 0387964673,\r\n! LC: QA76.9.C65.B73.\r\n!\r\n! Bennett Fox,\r\n! Algorithm 647:\r\n! Implementation and Relative Efficiency of Quasirandom\r\n! Sequence Generators,\r\n! ACM Transactions on Mathematical Software,\r\n! Volume 12, Number 4, December 1986, pages 362-376.\r\n!\r\n! Pierre L'Ecuyer,\r\n! Random Number Generation,\r\n! in Handbook of Simulation,\r\n! edited by Jerry Banks,\r\n! Wiley, 1998,\r\n! ISBN: 0471134031,\r\n! LC: T57.62.H37.\r\n!\r\n! Peter Lewis, Allen Goodman, James Miller,\r\n! A Pseudo-Random Number Generator for the System/360,\r\n! IBM Systems Journal,\r\n! Volume 8, 1969, pages 136-143.\r\n!\r\n! Parameters:\r\n!\r\n! Input/output, integer ( kind = 4 ) SEED, the \"seed\" value, which\r\n! should NOT be 0.\r\n! On output, SEED has been updated.\r\n!\r\n! Output, real ( kind = 8 ) R8_UNIFORM_01, a new pseudorandom variate,\r\n! strictly between 0 and 1.\r\n!\r\n implicit none\r\n\r\n integer ( kind = 4 ) k\r\n real ( kind = 8 ) r8_uniform_01\r\n integer ( kind = 4 ) seedy\r\n\r\n PRINT *, '*******/Now in R8_UNIFORM_01/*******'\r\n PRINT *, 'Seed is:',seedy\r\n k = seedy / 127773\r\n PRINT *, 'k=',k\r\n seedy = 16807 * ( seedy - k * 127773 ) - k * 2836\r\n PRINT *, 'seedy now =',seedy\r\n\r\n\r\n if ( seedy < 0 ) then\r\n seedy = seedy + 2147483647\r\n end if\r\n!\r\n! Although SEED can be represented exactly as a 32 bit integer,\r\n! it generally cannot be represented exactly as a 32 bit real number!\r\n!\r\n r8_uniform_01 = real ( seedy, kind = 8 ) * 4.656612875D-10\r\n PRINT *, 'The uniform RN is:',r8_uniform_01\r\n return\r\nEND FUNCTION r8_uniform_01\r\n\r\nFUNCTION r8_normal_ab ( a, b)\r\n!*****************************************************************************80\r\n!\r\n!! R8_NORMAL_AB returns a scaled pseudonormal R8.\r\n!\r\n! Discussion:\r\n!\r\n! The normal probability distribution function (PDF) is sampled,\r\n! with mean A and standard deviation B.\r\n!\r\n! Licensing:\r\n!\r\n! This code is distributed under the GNU LGPL license.\r\n!\r\n! Modified:\r\n!\r\n! 06 August 2013\r\n!\r\n! Author:\r\n!\r\n! John Burkardt\r\n!\r\n! Parameters:\r\n!\r\n! Input, real ( kind = 8 ) A, the mean of the PDF.\r\n!\r\n! Input, real ( kind = 8 ) B, the standard deviation of the PDF.\r\n!\r\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\r\n! number generator.\r\n!\r\n! Output, real ( kind = 8 ) R8_NORMAL_AB, a sample of the normal PDF.\r\n!\r\n implicit none\r\n\r\n real ( kind = 8 ) a\r\n real ( kind = 8 ) b\r\n real ( kind = 8 ) r1\r\n real ( kind = 8 ) r2\r\n real ( kind = 8 ) r8_normal_ab\r\n real ( kind = 8 ), parameter :: r8_pi = 3.141592653589793D+00\r\n real ( kind = 8 ) x\r\n\r\n! r1 = RANDOM()\r\n CALL RANDOM_NUMBER(r1)\r\n CALL RANDOM_NUMBER(r2)\r\n! r2 = RANDOM()\r\n x = sqrt ( - 2.0D+00 * log ( r1 ) ) * cos ( 2.0D+00 * r8_pi * r2 )\r\n\r\n r8_normal_ab = a + b * x\r\n\r\n return\r\nEND FUNCTION r8_normal_ab\r\n\r\nEND MODULE mc_toolbox\r\n", "meta": {"hexsha": "bb27eba3be0fbdc893d5d5226c41dc2e6f9564d8", "size": 6367, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mc_toolbox.f90", "max_stars_repo_name": "cnshingledecker/kmc-spin", "max_stars_repo_head_hexsha": "219a0d19dd1f9853053c5628e74f72e4683c0d6c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mc_toolbox.f90", "max_issues_repo_name": "cnshingledecker/kmc-spin", "max_issues_repo_head_hexsha": "219a0d19dd1f9853053c5628e74f72e4683c0d6c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mc_toolbox.f90", "max_forks_repo_name": "cnshingledecker/kmc-spin", "max_forks_repo_head_hexsha": "219a0d19dd1f9853053c5628e74f72e4683c0d6c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.968627451, "max_line_length": 81, "alphanum_fraction": 0.5614889273, "num_tokens": 1962, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554476, "lm_q2_score": 0.8244619328462579, "lm_q1q2_score": 0.7654377141774203}} {"text": "program demo_draw2\n use M_draw, only : prefsize, vinit, ortho2, clear, getkey\n use M_draw, only : move2, draw2, vexit, color,linewidth\n use M_draw, only : D_BLACK, D_WHITE\n use M_draw, only : D_RED, D_GREEN, D_BLUE\n use M_draw, only : D_YELLOW, D_MAGENTA, D_CYAN\n !\n ! The Archimedean spiral is the locus of points corresponding\n ! to the locations over time of a point moving away from a\n ! fixed point with a constant speed along a line which rotates\n ! with constant angular velocity.\n ! r=A+B*theta\n ! Changing the parameter A will turn the spiral,\n ! while B controls the distance between successive turnings.\n !\n implicit none\n integer :: i\n real :: x,y,radius,theta\n real,parameter :: rotate=0.0, gap=2.0\n integer :: ipaws\n\n call prefsize(400,400)\n call vinit(' ') ! start graphics using device $M_draw_DEVICE\n call ortho2(-150.0,150.0,-150.0,150.0)\n call color(D_MAGENTA)\n call clear()\n call move2(0.0,0.0)\n call color(D_BLACK)\n call linewidth(40)\n do i=0,360*10,5\n theta=d2r(real(i))\n ! equation in polar coordinates\n radius=rotate+gap*theta\n ! convert polar coordinates to cartesian\n call polar_to_cartesian(radius,theta,x,y)\n ! draw from current position to end of next segment\n call draw2(x,y)\n enddo\n ipaws=getkey()\n ! exit graphics mode\n call vexit()\ncontains\n elemental real function d2r(degrees)\n\n character(len=*),parameter::ident_6=\"@(#)M_units::d2r(3f): Convert degrees to radians\"\n\n doubleprecision,parameter :: RADIAN=57.2957795131d0 ! degrees\n real,intent(in) :: degrees ! input degrees to convert to radians\n d2r=dble(degrees)/RADIAN ! do the unit conversion\n end function d2r\n subroutine polar_to_cartesian(radius,inclination,x,y)\n implicit none\n character(len=*),parameter::ident_21=\"@(#)M_units::polar_to_cartesian(3f): convert polar coordinates to cartesian coordinates\"\n real,intent(in) :: radius,inclination\n real,intent(out) :: x,y\n if(radius.eq.0)then\n x=0.0\n y=0.0\n else\n x=radius*cos(inclination)\n y=radius*sin(inclination)\n endif\n end subroutine polar_to_cartesian\nend program demo_draw2\n", "meta": {"hexsha": "1ae0732ddee96bdf2820c1c209c98e8db8a42bd9", "size": 2320, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo_draw2.f90", "max_stars_repo_name": "urbanjost/M_draw", "max_stars_repo_head_hexsha": "e82fb2dc669d324847a97f0620687b39aea6a53b", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-25T05:43:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T05:43:49.000Z", "max_issues_repo_path": "example/demo_draw2.f90", "max_issues_repo_name": "urbanjost/M_draw", "max_issues_repo_head_hexsha": "e82fb2dc669d324847a97f0620687b39aea6a53b", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/demo_draw2.f90", "max_forks_repo_name": "urbanjost/M_draw", "max_forks_repo_head_hexsha": "e82fb2dc669d324847a97f0620687b39aea6a53b", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-25T05:43:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-25T05:43:44.000Z", "avg_line_length": 35.6923076923, "max_line_length": 132, "alphanum_fraction": 0.6525862069, "num_tokens": 651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7653944945953977}} {"text": "module mod_diff\n\n ! Module that provides finite difference functions.\n \n use iso_fortran_env, only: real32\n \n implicit none\n \n private\n public :: diffc, diffu\n \n contains\n \n pure function diffc(x) result(dx)\n ! Returns a centered difference of a 1-d array,\n ! with periodic boundary condition.\n real(real32), dimension(:), intent(in) :: x\n real(real32), dimension(:), allocatable :: dx\n integer :: i, idm\n \n idm = size(x)\n allocate(dx(idm))\n \n ! periodic boundary condition\n dx(1) = 0.5*(x(2)-x(idm))\n dx(idm) = 0.5*(x(1)-x(idm-1))\n \n do concurrent(i = 2:idm-1)\n dx(i) = 0.5 * (x(i+1) - x(i-1))\n end do\n \n end function diffc\n\n pure function diffu(x) result(dx)\n ! Returns an upstream difference of a 1-d array,\n ! with periodic boundary condition.\n real(real32), dimension(:), intent(in) :: x\n real(real32), dimension(:), allocatable :: dx\n integer :: i, idm\n\n idm = size(x)\n allocate(dx(idm))\n\n dx(1) = x(1) - x(idm)\n\n do concurrent(i = 2:idm)\n dx(2:idm) = x(2:idm) - x(1:idm-1)\n end do\n\n end function diffu\n\nend module mod_diff\n\n", "meta": {"hexsha": "15a79aa514c57e55e94b91e6c36de4a54fe44f9e", "size": 1168, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/ModernFortran/tsunami/mod_diff.f90", "max_stars_repo_name": "kkirstein/proglang-playground", "max_stars_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fortran/ModernFortran/tsunami/mod_diff.f90", "max_issues_repo_name": "kkirstein/proglang-playground", "max_issues_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran/ModernFortran/tsunami/mod_diff.f90", "max_forks_repo_name": "kkirstein/proglang-playground", "max_forks_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.6296296296, "max_line_length": 55, "alphanum_fraction": 0.5787671233, "num_tokens": 357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.870597268408361, "lm_q2_score": 0.8791467643431002, "lm_q1q2_score": 0.7653827715671522}} {"text": "module derivatives\n\nimplicit none\n\ncontains\n\n subroutine deriv_x ( x, f, i, j, dfdx, d2fdx2 )\n \n implicit none\n \n integer, intent(in) :: i, j\n real, intent(in) :: f(:,:), x(:)\n real, intent(out), optional :: dfdx, d2fdx2\n real :: dx\n \n integer :: nx, ny\n \n nx = size ( f, dim = 1 )\n ny = size ( f, dim = 2 )\n\n ! 2D\n if(nx/=1)then\n\n if(i .ne. 1 .and. i .ne. nx)then\n\n dx = ( (x(i)-x(i-1)) + (x(i+1)-x(i)) ) / 2\n dfdx = (f(i+1, j) - f(i-1, j)) / (2.0 * dx)\n d2fdx2 = (f(i+1, j) - 2.0 * f(i,j) + f(i-1, j)) / dx**2\n\n endif\n \n if(i .eq. 1)then\n\n dx = ( (x(i+2)-x(i+1)) + (x(i+1)-x(i)) ) / 2\n dfdx = (f(i+1, j) - f(i, j)) / dx\n d2fdx2 = (f(i+2, j) - 2.0 * f(i+1,j) + f(i, j)) / dx**2\n\n endif\n \n if(i .eq. nx)then\n\n dx = ( (x(i)-x(i-1)) + (x(i-1)-x(i-2)) ) / 2\n dfdx = (f(i, j) - f(i-1, j)) / dx\n d2fdx2 = (f(i, j) - 2.0 * f(i-1,j) + f(i-2, j)) / dx**2\n\n endif\n !1D\n else\n\n dfdx = 0 \n d2fdx2 = 0 \n\n endif\n \n end subroutine deriv_x\n\n \n subroutine deriv_y ( y, f, i, j, dfdy, d2fdy2 )\n\n implicit none\n\n integer, intent(in) :: i, j\n real, intent(in) :: f(:,:), y(:)\n real, intent(out), optional :: dfdy, d2fdy2\n\n real :: dy\n integer :: nx, ny\n\n nx = size ( f, dim = 1 )\n ny = size ( f, dim = 2 )\n\n !2D\n if(ny/=1)then\n if(j .ne. 1 .and. j .ne. ny)then\n\n dy = ( (y(j)-y(j-1)) + (y(j+1)-y(j)) ) / 2\n dfdy = (f(i, j+1) - f(i, j-1)) / (2.0 * dy)\n d2fdy2 = (f(i, j+1) - 2.0 * f(i,j) + f(i, j-1)) / dy**2\n endif\n\n if(j .eq. 1)then\n dy = ( (y(j+2)-y(j+1)) + (y(j+1)-y(j)) ) / 2\n dfdy = (f(i, j+1) - f(i, j)) / dy\n d2fdy2 = (f(i, j+2) - 2.0 * f(i,j+1) + f(i, j)) / dy**2\n endif\n\n\n if(j .eq. ny)then\n dy = ( (y(j)-y(j-1)) + (y(j-1)-y(j-2)) ) / 2\n dfdy = (f(i, j) - f(i, j-1)) / dy\n d2fdy2 = (f(i, j) - 2.0 * f(i,j-1) + f(i, j-2)) / dy**2\n endif\n\n !1D\n else\n\n dfdy = 0 \n d2fdy2 = 0 \n\n endif\n\n end subroutine deriv_y\n\n\n subroutine deriv_xy ( x, y, f, i, j, d2fdxy)\n\n implicit none\n\n integer, intent(in) :: i, j\n real, intent(in) :: f(:,:), x(:), y(:)\n real, intent(out), optional :: d2fdxy\n\n real :: dx, dy\n integer :: nx, ny\n\n nx = size ( f, dim = 1 )\n ny = size ( f, dim = 2 )\n\n d2fdxy = 0.0\n\n if(nx/=1 .and. ny/=1)then\n\n if (i /= 1 .and. i /= nx .and. &\n j /= 1 .and. j /= ny) then\n\n dx = ( (x(i)-x(i-1)) + (x(i+1)-x(i)) ) / 2\n dy = ( (y(j)-y(j-1)) + (y(j+1)-y(j)) ) / 2\n\n d2fdxy = (f(i+1,j+1) - f(i-1,j+1) - f(i+1,j-1) + f(i-1,j-1) ) &\n / (4.0 * dx * dy)\n\n endif\n\n endif\n\n\n end subroutine deriv_xy\n\nend module derivatives\n", "meta": {"hexsha": "b954b931042d34f3600aa0f8ee87324e4888bfe6", "size": 3244, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/derivatives.f90", "max_stars_repo_name": "efdazedo/aorsa2d", "max_stars_repo_head_hexsha": "ce0b8c930715277eeb4d23e60cc88434ffdaa583", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-02-13T21:57:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-10T16:47:51.000Z", "max_issues_repo_path": "src/derivatives.f90", "max_issues_repo_name": "efdazedo/aorsa2d", "max_issues_repo_head_hexsha": "ce0b8c930715277eeb4d23e60cc88434ffdaa583", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-02-23T20:33:30.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-23T20:34:31.000Z", "max_forks_repo_path": "src/derivatives.f90", "max_forks_repo_name": "efdazedo/aorsa2d", "max_forks_repo_head_hexsha": "ce0b8c930715277eeb4d23e60cc88434ffdaa583", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-02-15T16:50:58.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-23T14:07:59.000Z", "avg_line_length": 23.1714285714, "max_line_length": 74, "alphanum_fraction": 0.3504932182, "num_tokens": 1244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7653137065900373}} {"text": " program main\n\n use timers\n type(TimerType) :: seriesTime,monteTime,totalTime\n\n integer npoints,i,numinside\n parameter (npoints=300000)\n complex*16 c(npoints)\n real*8 r1,r2,halfpi,err1,area,err2\n real rand\nC\n call TimerCreate(seriesTime,\"series\")\n call TimerCreate(monteTime,\"monte\")\n call TimerCreate(totalTime,\"Series+monte\") \nC\nC GENERATE RANDOM NUMBERS\nc\n call srand(54321)\n do i=1,npoints\n \t r1=rand()\n r2=rand()\n c(i)=CMPLX(-2.0+2.5*r1,1.125*r2)\n end do\nC\n call TimerOn(totalTime)\nC\nC CALCULATE PI/2 FROM GREGORY'S FORMULA\nC\t\t\n call TimerOn(seriesTime)\n call series(halfpi,err1)\n call TimerOff(seriesTime)\n\nC\nC CALCULATE AREA OF MANDELBROT SET BY MONTE CARLO SAMPLING \nC\t\n call TimerOn(monteTime)\n call monte(c,numinside)\n call TimerOff(monteTime)\nC\n call TimerOff(totalTime)\nC\nC OUTPUT RESULTS \nC\n area = 2.0*2.5*1.125 * real(numinside)/real(npoints)\n err2 = area/sqrt(real(npoints))\n print *, \"Pi/2 = \", halfpi,\" +/- \",err1\n print *, \"Area of Mandelbrot set = \",area,\" +/- \",err2\nC\nC OUTPUT TIMING DATA \nC\n call TimerPrint(seriesTime)\n call TimerPrint(monteTime)\n call TimerPrint(totalTime)\nC\n stop\n end\nC\n subroutine series(halfpi,err)\nc\n real*8 halfpi,err,sum\n integer sign,terms,denom,i\n parameter (terms = 100000000)\nc\n sum=0.0d0\n sign=1\n denom=1\nc\n do i=1,terms\n sum=sum + sign*(1.0d0/denom)\n sign=(-sign)\n denom=denom + 2\n end do\nc\n halfpi = 2.0d0 * sum \n err = 2.0d0/terms\n return\n end \n\t\n subroutine monte(c,numinside)\nc\n integer npoints,maxiter,numinside,i,j\n parameter (npoints=300000,maxiter=10000)\n complex*16 c(npoints),z\nc\n numinside=0\n do i=1,npoints\n z=(0.0,0.0)\n do j=1,maxiter\n z = z*z +c(i)\t \n if (abs(z).gt.2.0) goto 10\n end do\n numinside = numinside +1\n 10 continue\n end do \nC\nC\n return\n end\t\n\n", "meta": {"hexsha": "8ce5f38a7607e767508e66affc2668c4b1f88ded", "size": 2097, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/labs-f77/lab2/mandel.f", "max_stars_repo_name": "arturocastro/SOR", "max_stars_repo_head_hexsha": "eb63341ca4082cb8f79f256d71c706912bc2852c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-24T18:13:05.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-24T18:13:05.000Z", "max_issues_repo_path": "source/labs-f77/lab2/mandel.f", "max_issues_repo_name": "arturocastro/SOR", "max_issues_repo_head_hexsha": "eb63341ca4082cb8f79f256d71c706912bc2852c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/labs-f77/lab2/mandel.f", "max_forks_repo_name": "arturocastro/SOR", "max_forks_repo_head_hexsha": "eb63341ca4082cb8f79f256d71c706912bc2852c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.97, "max_line_length": 60, "alphanum_fraction": 0.585598474, "num_tokens": 674, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7653136962744643}} {"text": " program demo_log10\n use, intrinsic :: iso_fortran_env, only : real_kinds, &\n & real32, real64, real128\n implicit none\n real(kind=real64) :: x = 10.0_real64\n\n x = log10(x)\n write(*,'(*(g0))')'log10(',x,') is ',log10(x)\n\n ! elemental\n write(*, *)log10([1.0, 10.0, 100.0, 1000.0, 10000.0, &\n & 100000.0, 1000000.0, 10000000.0])\n\n end program demo_log10\n", "meta": {"hexsha": "0c81304694333ffd6e0506ec76d0c836974dd827", "size": 418, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/log10.f90", "max_stars_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_stars_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-12-31T17:21:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T15:56:29.000Z", "max_issues_repo_path": "example/log10.f90", "max_issues_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_issues_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/log10.f90", "max_forks_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_forks_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-06T15:56:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-06T15:56:31.000Z", "avg_line_length": 27.8666666667, "max_line_length": 61, "alphanum_fraction": 0.538277512, "num_tokens": 153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.8459424295406088, "lm_q1q2_score": 0.7652822715484591}} {"text": "PROGRAM Main\n\n! *** Solution of Laplace's Equation.\n! ***\n! *** Uxx + Uyy = 0\n! *** 0 <= x <= pi, 0 <= y <= pi\n! *** U(x,pi) = sin(x), U(x,0) = U(0,y) = U(pi,y) = 0\n! ***\n! *** then U(x,y) = (sinh(y)*sin(x)) / sinh(pi)\n! ***\n! *** Should converge with\n! *** tol = 0.001 and M = 20 in 42 iterations.\n! *** and with tol = 0.001 and M = 100 in 198 iterations.\n! *** \n\n use timers\n\n type(TimerType) :: Total\n\n INTEGER M\n PARAMETER (M = 100)\n\n REAL*8 PI\n REAL*8 DATAN\n REAL*8 unew(0:M+1,0:M+1), uold(0:M+1,0:M+1)\n REAL*8 solution(0:M+1,0:M+1)\n REAL*8 omega, tol, h\n INTEGER i, j, iters\n\n call TimerCreate(Total,\"total\");\n\n call TimerOn(Total)\n\n PI = 4.0D0*DATAN(1.0D0)\n\n h = PI/FLOAT(M+1)\n\n DO i=0,M+1\n uold(i,M+1) = SIN(FLOAT(i)*h)\n END DO\n\n DO i=0,M+1\n DO j=0,M\n uold(i,j) = FLOAT(j)*h*uold(i,M+1)\n END DO\n END DO\n\n DO i=0,M+1\n DO j=0,M+1\n solution(i,j) = SINH(FLOAT(j)*h)*SIN(FLOAT(i)*h)/SINH(PI)\n END DO\n END DO\n\n omega = 2.0/(1.0+SIN(PI/FLOAT(M+1)))\n tol = 0.001\n\n CALL SOR (unew, uold, solution, omega, tol, m, iters)\n\n call TimerOff(Total)\n\n PRINT *, \" \"\n PRINT *, \" Omega = \", omega\n PRINT *, \" It took \", iters, \" iterations.\"\n\n call TimerPrint(Total)\n\n STOP\nEND PROGRAM Main\n\n\nREAL*8 FUNCTION ComputeError (solution, u, m, iters)\n \n INTEGER m, iters\n REAL*8 u(0:m+1,0:m+1)\n REAL*8 solution(0:m+1,0:m+1)\n\n! *** Local variables\n\n REAL*8 error\n INTEGER i, j\n\n error = 0.0\n\n DO j=1,m\n DO i=1,m\n error = MAX(error, ABS(solution(i,j)-u(i,j)))\n END DO\n END DO\n\n! PRINT *, \"On iteration \", iters, \" error = \", error\n\n ComputeError = error\n\n RETURN\nEND FUNCTION ComputeError\n\nSUBROUTINE SOR (unew, uold, solution, omega, tol, m, iters)\n\n INTEGER m, iters\n REAL*8 unew(0:m+1,0:m+1), uold(0:m+1,0:m+1)\n REAL*8 solution(0:m+1,0:m+1)\n REAL*8 omega, tol\n\n! *** Local variables\n\n REAL*8 error\n INTEGER i, j\n\n! *** External function.\n\n REAL*8 ComputeError\n EXTERNAL ComputeError\n\n! *** Copy bonudary conditions.\n\n DO i=0,m+1\n unew(i,m+1) = uold(i,m+1)\n unew(m+1,i) = uold(m+1,i)\n unew(i, 0) = uold(i, 0)\n unew(0, i) = uold(0, i)\n END DO\n\n! *** Do SOR until 'tol' satisfied.\n\n iters = 0\n error = ComputeError (solution, uold, m, iters)\n\n DO WHILE (error .GE. tol)\n\n! *** Do one iteration of SOR\n\n !$OMP PARALLEL DO PRIVATE(i, j) SCHEDULE(STATIC,25)\n DO j=1,m\n DO i=1,m\n unew(i,j) = 0.25 * (uold(i - 1, j) + uold(i + 1, j) + uold(i, j - 1) + uold(i, j + 1))\n END DO\n END DO\n\n! *** Copy new to old.\n\n DO j=1,m\n DO i=1,m\n uold(i,j) = unew(i,j)\n END DO\n END DO\n\n! *** Check error every 20 iterations.\n\n iters = iters + 1\n\n IF (MOD(iters,20) .EQ. 0) THEN\n error = ComputeError (solution, uold, m, iters)\n END IF\n\n END DO\n\n RETURN\nEND SUBROUTINE SOR\n", "meta": {"hexsha": "893aa4def23b22375cd76f4cf20df266beb33816", "size": 2887, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/lab6/sorf.f90", "max_stars_repo_name": "arturocastro/SOR", "max_stars_repo_head_hexsha": "eb63341ca4082cb8f79f256d71c706912bc2852c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-24T18:13:05.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-24T18:13:05.000Z", "max_issues_repo_path": "source/lab6/sorf.f90", "max_issues_repo_name": "arturocastro/SOR", "max_issues_repo_head_hexsha": "eb63341ca4082cb8f79f256d71c706912bc2852c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/lab6/sorf.f90", "max_forks_repo_name": "arturocastro/SOR", "max_forks_repo_head_hexsha": "eb63341ca4082cb8f79f256d71c706912bc2852c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.1572327044, "max_line_length": 97, "alphanum_fraction": 0.5424315899, "num_tokens": 1154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8688267898240861, "lm_q1q2_score": 0.7652601031831684}} {"text": "! advect_1d_FD.f90\n!\n! Solve a_t + u a_x = 0 with finite-difference\n! with either FTCS or upwinding. \n!\n! https://github.com/JOThurgood/SimpleCFD/wiki\n\nmodule shared_data\n\n implicit none\n\n integer, parameter :: num=selected_real_kind(p=15)\n integer (num) :: nx, ix\n integer (num) :: step = 0,nsteps\n real(num) :: u\n real (num) :: x_min, x_max, dxb\n real (num), dimension(:), allocatable :: a\n real(num), dimension(:), allocatable :: xb\n real (num) :: t_end, time = 0.0_num, dt, cfl \n logical :: ftcs,upwind, verbose\n !anticipating staggered grid in later codes\n !so 'c' for cell center, 'b' for boundary \n\n contains\n\nend module shared_data\n\nmodule setup\n\n use shared_data\n\n implicit none\n\n contains\n\n subroutine user_control\n nx = 64 \n x_min = 0.0_num \n x_max = 1.0_num\n t_end = 1.0_num\n u = 1.0_num !char speed of linear advection equation\n cfl = 1.0_num !cfl number\n nsteps = -1 !<0 to run to t_end \n ftcs = .false.\n upwind = .true.\n verbose = .true.\n end subroutine user_control \n\n subroutine initial_conditions\n ! step function\n a = 0.0_num\n do ix = -1,nx+1 \n if ((xb(ix) >= 1.0_num/3.0_num) .and. (xb(ix) <= 2.0_num / 3.0_num)) then\n a(ix) = 1.0_num\n endif\n end do \n endsubroutine initial_conditions\n\n subroutine setup_1d_fd_grid\n ! setup 1d finite difference grid for var a of size nx \n ! plus one ghost either side\n ! here 0 is leftmost, nx is right, -1 and nx+1 are ghosts\n ! and allocate \"a\" etc\n\n allocate(xb (-1:nx+1) )\n allocate(a (-1:nx+1) )\n\n dxb = (x_max - x_min) / real(nx,num) \n do ix = -1,nx+1 \n xb(ix) = x_min + real(ix,num) * dxb\n end do \n endsubroutine setup_1d_fd_grid \n\n subroutine init\n call user_control\n call setup_1d_fd_grid\n call initial_conditions\n end subroutine init\n\nend module setup\n\nmodule solver\n\n use shared_data\n\n implicit none\n\n contains\n\n subroutine update\n dt = cfl * dxb / u\n call periodic_bc\n\n if (ftcs) then\n! do ix=0,nx \n! a(ix) = a(ix) - cfl * (a(ix+1) - a(ix-1)) / 2.0_num\n! enddo\n! NB: above will not work - need previous state so any direction will break it\n a = a - cfl * ( cshift(a,1) - cshift(a,-1)) / 2.0_num\n endif \n\n if (upwind) then\n ! upwind - must either store old solution separately,\n ! or fill from right to left\n do ix=nx,0,-1\n a(ix) = a(ix) - cfl * (a(ix) - a(ix-1)) \n enddo\n endif\n time = time + dt \n end subroutine update\n\n subroutine periodic_bc\n a(-1) = a(nx) \n a(nx+1) = a(0)\n endsubroutine periodic_bc\n\nend module solver\n\nmodule diagnostics\n\n use shared_data\n\n implicit none\n\n contains\n\n subroutine do_io\n integer :: out_unit =10\n open(out_unit, file=\"xb.dat\", access=\"stream\")\n write(out_unit) xb\n close(out_unit)\n open(out_unit, file=\"a.dat\", access=\"stream\")\n write(out_unit) a\n close(out_unit)\n call execute_command_line(\"python plot_advect_1d_FD.py\")\n end subroutine do_io\n\nend module diagnostics\n\nprogram advect_1d_FD\n\n use shared_data\n use setup\n use solver\n use diagnostics\n\n implicit none\n\n call init\n\n do \n if ((step >= nsteps .and. nsteps >= 0) .or. (time >= t_end)) exit\n step = step + 1\n call update\n if (verbose) print *,'step',step, 'time',time,'dt',dt\n end do \n\n call do_io\n\n print *, 'done in',step,'steps', 'with cfl',cfl\n\nend program advect_1d_FD\n", "meta": {"hexsha": "74c0946e7e7dd93d4746c16e66464bbf8aa24737", "size": 3394, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "linear_advection/1D/FD/advect_1d_FD.f90", "max_stars_repo_name": "JOThurgood/SimpleCFD", "max_stars_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-23T05:31:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-04T23:21:11.000Z", "max_issues_repo_path": "linear_advection/1D/FD/advect_1d_FD.f90", "max_issues_repo_name": "JOThurgood/SimpleCFD", "max_issues_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 39, "max_issues_repo_issues_event_min_datetime": "2018-08-31T23:48:02.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-07T10:03:11.000Z", "max_forks_repo_path": "linear_advection/1D/FD/advect_1d_FD.f90", "max_forks_repo_name": "JOThurgood/SimpleCFD", "max_forks_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-11-14T20:42:54.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-18T09:16:27.000Z", "avg_line_length": 20.8220858896, "max_line_length": 80, "alphanum_fraction": 0.6337654685, "num_tokens": 1122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.8807970732843033, "lm_q1q2_score": 0.7652600817016291}} {"text": "program NwtnFwdDiffForm\n! Computes the value of the interpolating\n! polynomial using Newton's forward difference formula \n! The numbers x_0, h, x \n! and values f(x_0),...f(x_n)\n! are read from the first two lines of the file named NwtnFwdInput \nimplicit none\ninteger, parameter :: real8 = selected_real_kind(13,300)\nreal(kind=real8) tol,xx,s,h,x0,P,prod\ninteger, parameter :: n=2\nreal(kind=real8), dimension(0:n,0:n)::F\nreal(kind=real8), dimension(0:n):: x\ninteger i,j\nopen(unit=7,file='NwtnFwdInput')\nread(7,*) x0,h,xx\nread(7,*) (F(i,0),i=0,n)\ns=(xx-x0)/h\ndo i=1,n\n do j=1,i\n F(i,j)=F(i,j-1)-F(i-1,j-1)\n enddo\nenddo\nprod=1.d0\nP=F(0,0)\ni=0\nwrite(*,*) i,prod,P\ndo i=1,n\n prod=prod*(s-dfloat(i-1))/dfloat(i)\n P=P+prod*F(i,i)\n write(*,*) i,prod,P\nenddo\nwrite(*,*) 'P(x)=',P\nend program NwtnFwdDiffForm\n\n\n", "meta": {"hexsha": "b95648b0dc534d11ef7a4c82c5b2cbe6c9562242", "size": 813, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "NwtnFwdDiffForm.f90", "max_stars_repo_name": "whisker-rebellion/Fortran", "max_stars_repo_head_hexsha": "65c0e064bcc92f33bc78cc89220a0298b3ee96be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NwtnFwdDiffForm.f90", "max_issues_repo_name": "whisker-rebellion/Fortran", "max_issues_repo_head_hexsha": "65c0e064bcc92f33bc78cc89220a0298b3ee96be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NwtnFwdDiffForm.f90", "max_forks_repo_name": "whisker-rebellion/Fortran", "max_forks_repo_head_hexsha": "65c0e064bcc92f33bc78cc89220a0298b3ee96be", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.5833333333, "max_line_length": 67, "alphanum_fraction": 0.6691266913, "num_tokens": 327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.944176857294597, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7652354310529891}} {"text": "subroutine fitline(xdata, ydata, n, a, b)\n real(rk), allocatable :: xdata(:)\n real(rk), allocatable :: ydata(:)\n\n integer :: n, i\n real(rk) :: a, b, d, sx2, sx, sy, sxy\n\n d = 0.0\n sx2 = 0.0\n sx = 0.0\n sy = 0.0\n sxy = 0.0\n\n i = 1\n do while (i <= n)\n sx2 = sx2 + xdata(i)**2\n\n sx = sx + xdata(i)\n sy = sy + ydata(i)\n sxy = sxy + xdata(i) * ydata(i)\n\n i = i + 1\n end do\n\n d = n*sx2 - sx**2\n\n a = (sx2 * sy - sx * sxy) / d\n b = (n * sxy - sx * sy) / d\nend subroutine fitline\n", "meta": {"hexsha": "b2e4cae195e6710a96ab5e0ef068ae8c753eacb4", "size": 506, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fit.f90", "max_stars_repo_name": "Roninkoi/Scicodes", "max_stars_repo_head_hexsha": "97eb4dc017ad4cd494b545aecaa9fdd7c501a9b7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fit.f90", "max_issues_repo_name": "Roninkoi/Scicodes", "max_issues_repo_head_hexsha": "97eb4dc017ad4cd494b545aecaa9fdd7c501a9b7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fit.f90", "max_forks_repo_name": "Roninkoi/Scicodes", "max_forks_repo_head_hexsha": "97eb4dc017ad4cd494b545aecaa9fdd7c501a9b7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.8666666667, "max_line_length": 41, "alphanum_fraction": 0.4802371542, "num_tokens": 234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768557238083, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.765235429779898}} {"text": "!a wrapper for the example with the Floyd-Warshall algorithm\r\nsubroutine exampleFloydWarshall(G,start,end)\r\n use iso_fortran_env, wp => real64\r\n use graphf\r\n implicit none\r\n type(graph) :: G\r\n integer :: start,end\r\n real(wp),allocatable :: dist(:,:)\r\n integer,allocatable :: prev(:,:)\r\n integer,allocatable :: path(:)\r\n real(wp) :: dummy\r\n integer :: lpath\r\n integer :: i\r\n\r\n !-- allocate space for the dist and prev vectors\r\n allocate(dist(G%V,G%V),prev(G%V,G%V))\r\n\r\n !-- run the Floy-Warshall algo, get distance and prev\r\n call FloydWarshall(G, dist, prev)\r\n \r\n !-- allocate an array for analyzing the path\r\n allocate(path(G%V), source = 0)\r\n if(dist(start,end) == huge(dummy))then\r\n write(*,'(a,i0,a,i0)') 'There is no path from vertex ',start,' to vertex ',end\r\n else\r\n call getPathFW(G%V,prev,start,end,path,lpath)\r\n write(*,'(a,i0,a,i0,a)') \"shortest path from vertex \", start, \" to vertex \", end, \":\"\r\n do i=1,lpath\r\n write(*,'(1x,i0)',advance='no') path(i)\r\n enddo\r\n write(*,*)\r\n write(*,'(a,f12.4)') 'with a total path length of ',dist(start,end)\r\n endif\r\n\r\n deallocate(path,prev,dist)\r\n return\r\nend subroutine\r\n\r\n!-- implementation of the algorithm including setup of \"dist\" and \"prev\"\r\nsubroutine FloydWarshall(G, dist, prev)\r\n use iso_fortran_env, wp => real64\r\n use graphf\r\n implicit none\r\n type(graph) :: G\r\n real(wp),intent(inout) :: dist(G%V,G%V)\r\n integer,intent(inout) :: prev(G%V,G%V)\r\n real(wp) :: inf\r\n real(wp) :: kdist\r\n integer :: i,j,k\r\n\r\n inf = huge(inf)\r\n !-- set distances and previously visited nodes\r\n dist=inf\r\n prev=-1\r\n do i=1,G%V\r\n do j=1,G%V\r\n if(G%nmat(i,j)==1)then\r\n dist(i,j) = G%emat(i,j)\r\n prev(i,j) = j\r\n endif\r\n enddo\r\n enddo\r\n\r\n !-- The algorithm is based on the following assumption:\r\n\t! If a shortest path from vertex u to vertex v runns through a thrid\r\n\t! vertex w, then the paths u-to-w and w-to-v are already minimal.\r\n\t! Hence, the shorest paths are constructed by searching all path\r\n ! that run over an additional intermediate point k\r\n ! The following loop is the actual algorithm\r\n do k=1,G%V\r\n do i=1,G%V\r\n do j=1,G%V\r\n kdist = dist(i,k) + dist(k,j)\r\n !-- if the path ij runs over k, update\r\n if(dist(i,j) > kdist)then\r\n dist(i,j) = kdist\r\n prev(i,j) = prev(i,k)\r\n endif\r\n enddo\r\n enddo\r\n enddo\r\n \r\n return\r\nend subroutine\r\n\r\n!-- reconstruct the path start to end for the Floyd-Warshall algorithm\r\nsubroutine getPathFW(nmax,prev,start,end,path,lpath)\r\n implicit none\r\n integer :: nmax\r\n integer :: start\r\n integer :: end\r\n integer :: prev(nmax,nmax)\r\n integer :: path(nmax)\r\n integer :: lpath\r\n integer :: i,k\r\n if(prev(start,end) == -1)then\r\n path(1)=-1\r\n return\r\n endif\r\n k=1\r\n path(k) = start\r\n i=start\r\n do while ( i .ne. end )\r\n i = prev(i,end)\r\n k=k+1\r\n path(k) = i\r\n enddo\r\n lpath=k\r\n return\r\nend subroutine getPathFW\r\n", "meta": {"hexsha": "cb7ec808c6041d28ac67d1e1b0143e9970309f3f", "size": 3269, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/floyd-warshall.f90", "max_stars_repo_name": "pprcht/shortestpaths", "max_stars_repo_head_hexsha": "5c832666bdca34517550f2064febaa4e14b7800e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-04-28T21:23:26.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-16T00:00:48.000Z", "max_issues_repo_path": "fortran/floyd-warshall.f90", "max_issues_repo_name": "pprcht/shortestpaths", "max_issues_repo_head_hexsha": "5c832666bdca34517550f2064febaa4e14b7800e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/floyd-warshall.f90", "max_forks_repo_name": "pprcht/shortestpaths", "max_forks_repo_head_hexsha": "5c832666bdca34517550f2064febaa4e14b7800e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.4504504505, "max_line_length": 94, "alphanum_fraction": 0.5564392781, "num_tokens": 917, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7651485624852122}} {"text": "\r\n! Calculates the 6j symbol using the Racah formula in Messiah, page 1065\r\n! @TODO: Read the note on the ThreeJSymbol function.\r\n!WHY WERE THE ARGUMENTS SWAPPED? IANGULAR HAS THEM SWAPPED. ANYWHERE ELSE?\r\nreal*8 function SixJSymbol(rj1, rj2, rj3, J1, J2, J3)\r\n\timplicit none\r\n\tinteger J1, J2, J3, rj1, rj2, rj3\r\n\tinteger iterm\r\n\tinteger CheckTriad, Terms6j, t\r\n\treal*8 FactorialGeneral\r\n\treal*8 TriSym, r_6j, temp\r\n\r\n\tr_6j = 0.0_8\r\n\tt = 0; iterm = 0\r\n\r\n\t! Checks for the values based on information from http://mathworld.wolfram.com/Wigner6j-Symbol.html\r\n\tif (CheckTriad(rj1,rj2,rj3) /= 1 .OR. CheckTriad(rj1,J2,J3) /= 1 .OR. &\r\n\t\tCheckTriad(J1,rj2,J3) /= 1 .OR. CheckTriad(J1,J2,rj3) /= 1) then\r\n\t\t!write (iwrite,*) 'Each triad must sum together to an integer and satisfy the triangular inequalities.'\r\n\t\t!write (*,*) 'Each triad must sum together to an integer and satisfy the triangular inequalities.'\r\n\t\tSixJSymbol = 0.0d0\r\n\t\treturn\r\n\tendif\r\n\r\n\t! TODO: Change this to use a do loop. Also implement an upper limit to this summation like in ThreeJSymbol.\r\n\t! Again, we do the sum first\r\n10\tif (iterm < Terms6j(rj1,rj2,rj3,J1,J2,J3)) then ! Have to determine how many terms we have\r\n\t\t! The only valid terms are those where the arguments to the factorials are non-negative.\r\n\t\ttemp = (FactorialGeneral(int(t-rj1-rj2-rj3)) * FactorialGeneral(int(t-rj1-J2-J3)) * FactorialGeneral(int(t-J1-rj2-J3)) &\r\n\t\t\t\t* FactorialGeneral(int(t-J1-J2-rj3))) * FactorialGeneral(int(rj1+rj2+J1+J2-t)) * FactorialGeneral(int(rj2+rj3+J2+J3-t)) &\r\n\t\t\t\t* FactorialGeneral(int(rj3+rj1+J3+J1-t))\r\n\t\t! If temp is 0, then \r\n\t\tif (temp /= 0.0d0) then\r\n\t\t\titerm = iterm + 1 ! This is one of our terms that Terms6j returned.\r\n\t\t\tr_6j = r_6j + (-1)**t * FactorialGeneral(t+1) / temp\r\n\t\tendif\r\n\r\n\t\tt = t + 1\r\n\t\tgoto 10\r\n\tendif\r\n\r\n\tr_6j = r_6j * Sqrt(TriSym(rj1,rj2,rj3) * TriSym(rj1,J2,J3) * TriSym(J1,rj2,J3) * TriSym(J1,J2,rj3))\r\n\tSixJSymbol = r_6j\r\n\treturn\r\nend\t\r\n\r\n\r\n! Each triad has to add to an integer and must satisfy the the triangular inequalities.\r\n! Returns 1 if the conditions are satisfied and 0 if they are not.\r\ninteger function CheckTriad(a, b, c)\r\n\tinteger a, b, c\r\n\t\r\n\t!if (a+b+c /= dble(int(a+b+c))) then\r\n\t!\tCheckTriad = 0\r\n\t!\treturn\r\n\t!endif\r\n\t\r\n\t! Triangular inequalities\r\n\tif (c > a + b .OR. c < abs(a - b)) then\r\n\t\tCheckTriad = 0\r\n\t\treturn\r\n\tendif\r\n\t\r\n\tCheckTriad = 1\r\n\treturn\r\nend\r\n\r\n\r\n! Calculates the number of terms in the 6j sum.\r\n! The list comes from page 1065 of Messiah, volume 2.\r\ninteger function Terms6j(rj1, rj2, rj3, J1, J2, J3)\r\n\tinteger rj1, rj2, rj3, J1, J2, J3\r\n\tinteger s\r\n\t\r\n\t! Initialize the smallest value\r\n\ts = rj1 + rj2 - rj3\r\n\r\n! TODO: Rewrite in terms of min function.\r\n\tif (rj1+J2-J3 < s) then\r\n\t\ts = rj1+J2-J3\r\n\tendif\r\n\tif (J1+rj2-J3 < s) then\r\n\t\ts = J1+rj2-J3\r\n\tendif\r\n\tif (J1+J2-rj3 < s) then\r\n\t\ts = J1+J2-rj3\r\n\tendif\r\n\tif (rj2+rj3-rj1 < s) then\r\n\t\ts = rj2+rj3-rj1\r\n\tendif\r\n\tif (J2+J3-rj1 < s) then\r\n\t\ts = J2+J3-rj1\r\n\tendif\r\n\tif (rj2+J3-J1 < s) then\r\n\t\ts = rj2+J3-J1\r\n\tendif\r\n\tif (J2+rj3-J1 < s) then\r\n\t\ts = J2+rj3-J1\r\n\tendif\r\n\tif (rj3+rj1-rj2 < s) then\r\n\t\ts = rj3+rj1-rj2\r\n\tendif\r\n\tif (J3+rj1-J2 < s) then\r\n\t\ts = J3+rj1-J2\r\n\tendif\r\n\tif (J3+J1-rj2 < s) then\r\n\t\ts = J3+J1-rj2\r\n\tendif\r\n\tif (rj3+J1-J2 < s) then\r\n\t\ts = rj3+J1-J2\r\n\tendif\r\n\t\r\n\t! Is this completely correct?\r\n\tTerms6j = s + 1\r\nreturn\r\nend\r\n", "meta": {"hexsha": "8d75b6caf04f18ad5748789c072b4d7f01791fda", "size": 3331, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "General Code/Short-Range/Double Precision/GeneralAsymptotic/6j.f90", "max_stars_repo_name": "DentonW/Ps-H-Scattering", "max_stars_repo_head_hexsha": "943846d1deadbe99a98d2c2e26bcebf55986d8e7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-08-02T03:50:06.000Z", "max_stars_repo_stars_event_max_datetime": "2017-08-02T03:50:06.000Z", "max_issues_repo_path": "General Code/Short-Range/Double Precision/GeneralAsymptotic/6j.f90", "max_issues_repo_name": "DentonW/Ps-H-Scattering", "max_issues_repo_head_hexsha": "943846d1deadbe99a98d2c2e26bcebf55986d8e7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "General Code/Short-Range/Double Precision/GeneralAsymptotic/6j.f90", "max_forks_repo_name": "DentonW/Ps-H-Scattering", "max_forks_repo_head_hexsha": "943846d1deadbe99a98d2c2e26bcebf55986d8e7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-28T22:09:05.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-28T22:09:05.000Z", "avg_line_length": 28.4700854701, "max_line_length": 126, "alphanum_fraction": 0.6517562294, "num_tokens": 1320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760038, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.7651485507290844}} {"text": "program main\n implicit none\n integer(4), parameter :: N_max = 28123\n integer(4) :: i,j,ia,s,n,Nabundants\n logical :: writable\n integer(4), dimension(N_max) :: temp_abundants\n integer(4), dimension(:), allocatable :: abundants\n\n\n ! build list of abundant numbers\n ia = 1\n do i=1,N_max\n if (sum_div(i) > i) then\n temp_abundants(ia) = i\n ia = ia + 1\n endif\n enddo\n\n Nabundants = ia - 1\n write(*,*) \"Nabundants: \",Nabundants\n allocate(abundants(Nabundants))\n abundants = temp_abundants(:Nabundants)\n\n ! test to see if a number can be written as the sum of two abundant numbers\n s = 0\n !$omp parallel do &\n !$omp default(shared) &\n !$omp private(i,j,n,writable) &\n !$omp reduction(+:s)\n do i=1,N_max\n writable = .false.\n do j=1,Nabundants\n n = i - abundants(j)\n if (any(abundants==n)) then\n ! we can write it as the sum of 2 abundants\n writable = .true.\n exit\n endif\n enddo\n if (.not. writable) then\n s = s + i\n endif\n enddo\n !$omp end parallel do\n\n write(*,*) \"sum of all numbers which cannot be written as the sum of two abundant numbers: \",s\n\n\ncontains\n\n\n pure function sum_div(n)\n ! Default\n implicit none\n\n ! Function arguments\n integer(4), intent(in) :: n\n integer(4) :: sum_div\n\n ! Local variables\n integer(4) :: i1,i2,nmax\n\n ! Figure out max number to try\n nmax = int(sqrt(1D0*n))\n\n ! 1 is always a divisor\n sum_div = 1\n do i1=2,nmax\n if (mod(n,i1)==0) then\n ! work out if a perfect square\n i2 = n/i1\n if (i2 /= i1) then\n sum_div = sum_div + i1 + i2\n else\n sum_div = sum_div + i1\n endif\n endif\n enddo\n\n return\n end function sum_div\n\n\nend program main\n", "meta": {"hexsha": "5629e0acee0e281f33117e8dbb0bdff3b5b97399", "size": 1838, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/problem23/problem23.f90", "max_stars_repo_name": "plaplant/Project_Euler", "max_stars_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/problem23/problem23.f90", "max_issues_repo_name": "plaplant/Project_Euler", "max_issues_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/problem23/problem23.f90", "max_forks_repo_name": "plaplant/Project_Euler", "max_forks_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-01-07T21:43:45.000Z", "max_forks_repo_forks_event_max_datetime": "2017-01-07T21:43:45.000Z", "avg_line_length": 21.6235294118, "max_line_length": 96, "alphanum_fraction": 0.5701849837, "num_tokens": 570, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7651485434199264}} {"text": "module MathClass\r\n\tuse fMathClass\r\n\timplicit none\r\n\t\r\n\r\n interface fstring\r\n module procedure fstring_Int, fstring_Real, fstring_Int_len, fstring_Real_len\r\n\tend interface fstring\r\n\r\n\tinterface input\r\n\t\tmodule procedure input_Int,input_Real,input_IntVec,input_RealVec,input_IntArray,input_RealArray,input_String,input_logical\r\n\tend interface input\r\n\t\r\n\tinterface zeroif\r\n\t\tmodule procedure zeroif_Int,zeroif_Real\r\n\tend interface zeroif\r\n\r\n\tinterface removeWord\r\n\t\tmodule procedure removeWord_String \r\n\tend interface \r\n\r\ncontains\r\n\r\n\r\n!########################################\r\nfunction norm(vec) result(a)\r\n\treal(8),intent(in)::vec(:)\r\n\tinteger :: n\r\n\treal(8) :: a\r\n\r\n\tn=size(vec)\r\n\ta=dsqrt(dot_product(vec,vec) )\r\n\r\nend function\r\n!########################################\r\n\r\n\r\n\r\n!########################################\r\nfunction SearchNearestCoord(Array,x) result(id)\r\n\treal(8),intent(in) :: Array(:,:)\r\n\treal(8),intent(in) :: x(:)\r\n\tinteger,allocatable::xr(:)\r\n\r\n\tinteger :: i,id,n,m,norm,tr_norm\r\n\r\n\tn=size(Array,1)\r\n\tm=size(Array,2)\r\n\tif(m/=size(x) )then\r\n\t\tstop \"ERROR :: SearchNearestCoord >> size(Array,2) should be =size(x)\"\r\n\tendif\r\n\r\n\tallocate(xr(m) )\r\n\tdo i=1,n\r\n\t\txr(:)=Array(i,:)\r\n\t\ttr_norm=dot_product(xr-x,xr-x)\r\n\t\tif(i==1)then\r\n\t\t\tnorm=tr_norm\r\n\t\t\tid =i\r\n\t\telse\r\n\t\t\tif(norm > tr_norm)then\r\n\t\t\t\tnorm=tr_norm\r\n\t\t\t\tid =i\r\n\t\t\telse\r\n\t\t\t\tcycle\r\n\t\t\tendif\r\n\t\tendif\r\n\tenddo\r\n\r\n\r\n\t\r\nend function\r\n!########################################\r\n\r\n!##################################################\r\nfunction SearchIDIntVec(Vec,val) result(id_)\r\n\tinteger,intent(in) :: Vec(:)\r\n\tinteger,intent(in) :: val\r\n\r\n\tinteger :: i,id_\r\n\r\n\tdo i=1,size(Vec)\r\n\t\tif(Vec(i)==val )then\r\n\t\t\tid_=i\r\n\t\t\treturn\r\n\t\tendif\r\n\tenddo\r\n\r\nend function\r\n!##################################################\r\nsubroutine heapsort(n,array)\r\n \tinteger,intent(in) :: n\r\n \tinteger,intent(inout) :: array(1:n)\r\n \r\n \tinteger ::i,k,j,l\r\n \tinteger :: t\r\n \r\n \tif(n.le.0)then\r\n \t\twrite(6,*)\"Error, at heapsort\"; stop\r\n \tendif\r\n \tif(n.eq.1)return\r\n\r\n\tl=n/2+1\r\n\tk=n\r\n\tdo while(k.ne.1)\r\n\t if(l.gt.1)then\r\n\t l=l-1\r\n\t t=array(L)\r\n\t else\r\n\t t=array(k)\r\n\t array(k)=array(1)\r\n\t k=k-1\r\n\t if(k.eq.1) then\r\n\t \tarray(1)=t\r\n\t \texit\r\n\t endif\r\n\t endif\r\n\t i=l\r\n\t j=l+l\r\n\t do while(j.le.k)\r\n\t if(j.lt.k)then\r\n\t \tif(array(j).lt.array(j+1))j=j+1\r\n\t endif\r\n\t if (t.lt.array(j))then\r\n\t \tarray(i)=array(j)\r\n\t \ti=j\r\n\t \tj=j+j\r\n\t else\r\n\t \tj=k+1\r\n\t endif\r\n\t enddo\r\n\t \tarray(i)=t\r\n \tenddo\r\n\r\n\treturn\r\nend subroutine heapsort\r\n\r\n\r\n!==========================================================\r\n!calculate cross product\r\n!---------------------------\r\nfunction cross_product(a,b) result (c)\r\n\treal(8), intent(in) :: a(:),b(:)\r\n\treal(8), allocatable :: c(:)\r\n \r\n if(size(a) /= size(b)) then\r\n stop \"wrong number on size a, b\"\r\n endif\r\n \r\n allocate(c(size(a,1)))\r\n \tif(size(c,1)==3) then\r\n \tc(1) = a(2)*b(3) - a(3)*b(2)\r\n \tc(2) = a(3)*b(1) - a(1)*b(3)\r\n \tc(3) = a(1)*b(2) - a(2)*b(1)\r\n \telse\r\n \tstop \"wrong number at cross_product\"\r\n \tendif\r\n \r\nend function cross_product\r\n!=========================================================\r\n!calculate diadic\r\n!----------------------\r\nfunction diadic(a,b) result(c)\r\n real(8), intent(in) :: a(:), b(:)\r\n\treal(8), allocatable :: c(:,:)\r\n\t\r\n\tinteger n,i,j\r\n\t \r\n\tallocate(c(size(a),size(b) ) )\r\n\tdo i=1,size(a)\r\n\t\tdo j=1,size(b)\r\n\t\t\tc(i,j)=a(i)*b(j)\t\t\r\n\t\tenddo\r\n\tenddo\r\n\r\nend function diadic\t\r\n!==========================================================\r\n!calculate gz\r\n!--------------\r\nsubroutine calcgz(x2,x11,x12,nod_coord,gzi)\r\n\treal(8), intent(in) :: nod_coord(:,:)\r\n\treal(8),intent(out) :: gzi\r\n\tinteger,intent(in):: x2,x11,x12\r\n\t\treal(8) l\r\n\t\treal(8),allocatable::avec(:)\r\n\r\n\t\tallocate(avec(2))\r\n\t\tl = dot_product( nod_coord(x12,1:2) - nod_coord(x11,1:2), &\r\n\t\t\tnod_coord(x12,1:2) - nod_coord(x11,1:2) ) \r\n\t\tl=l**(1.0d0/2.0d0)\r\n\t \r\n\t\tavec(1:2) = ( nod_coord(x12,1:2) - nod_coord(x11,1:2) )/l\r\n\t\t\r\n\t\tif(l==0.0d0)then\r\n\t\t\tprint *, \"calcgz l=0\"\r\n\t\t\tgzi=0.0d0\r\n\t\telse\r\n\t\t\tgzi=1.0d0/l*dot_product( nod_coord(x2,1:2) -nod_coord(x11,1:2),avec(1:2) )\r\n\t\tendif\r\n\r\n\t deallocate(avec)\r\n\t \r\nend subroutine calcgz\r\n!==========================================================\r\nsubroutine eigen_2d(Amat,eigenvector)\r\n\treal(8),intent(in)::Amat(:,:)\r\n\treal(8),intent(inout)::eigenvector(:,:)\r\n\r\n\treal(8)::b,c,phy,eigenvalue(2)\r\n\tinteger i,j\r\n\t\r\n\teigenvalue(:)=0.0d0\r\n\teigenvector(:,:)=0.0d0\r\n\t\r\n\tb=-1.0d0*(Amat(1,1)+Amat(2,2))\r\n\tc=Amat(1,1)*Amat(2,2)-Amat(1,2)*Amat(1,2)\r\n\t\r\n\tif(Amat(1,2)/=Amat(2,1) )then\r\n\t\t stop \"input matrice is not symmetric\"\r\n\tendif\r\n\t\r\n\tdo i=1,2\r\n\t\teigenvalue(i)=(-1.0d0*b+((-1.0d0)**dble(i))*(b*b-4.0d0*c)**(1.0d0/2.0d0))*(0.50d0)\r\n\tenddo\r\n\t\r\n\tdo i=1,2\r\n\t\tif(Amat(1,2)==0 )then\r\n\t\t\tcycle\r\n\t\telseif(Amat(1,2)/=0 )then\r\n\t\t\tphy=atan( (eigenvalue(i)-Amat(1,1))/Amat(1,2) ) \r\n\t\t\t\r\n\t\t\tdo j=1,2\r\n\t\t\t\teigenvector(i,1:2)=(/cos(phy),sin(phy)/)\r\n\t\t\tenddo\r\n\t\tendif\r\n\tenddo\r\n\t\r\n\tdo i=1,2\r\n\t\teigenvector(i,:)=eigenvalue(i)*eigenvector(i,:)\r\n\tenddo\r\nend subroutine eigen_2d\r\n!==========================================================\r\nfunction signmm(a) result(b)\r\n\treal(8),intent(in)::a\r\n\treal(8) b\r\n\t\r\n\tif(a>0)then\r\n\t\tb=1.0d0\r\n\telseif(a<0)then\r\n\t\tb=-1.0d0\r\n\telseif(a==0)then\r\n\t\tb=0.0d0\r\n\telse\r\n\t\tstop \"ERROR: Invalid Real(8) in function_signm\"\r\n\tendif\r\n\t\r\nend function signmm \r\n!==========================================================\r\nrecursive function det_mat(a,n) result(det)\r\n \tinteger, intent(in) :: n\r\n \treal(8), intent(in) :: a(n, n)\r\n \treal(8) det, b(n-1, n-1)\r\n \tinteger i\r\n\tif (n > 1) then\r\n\t\tdet = 0.0d0\r\n\t\tdo i = 1, n\r\n\t\t \tb(1:i-1, 1:n-1) = a(1:i-1, 2:n)\r\n\t\t \tb(i:n-1, 1:n-1) = a(i+1:n, 2:n)\r\n\t\t \tdet = det + (-1.0d0) ** (i + 1) &\r\n\t\t\t* a(i, 1) * det_mat(b, n-1)\r\n\t\t\r\n\t\tenddo\r\n\telse\r\n\t\tdet = a(1,1)\r\n\tendif\r\nend function det_mat\r\n!=====================================================================================\r\nsubroutine trans_rank_2(A,A_T)\r\n\treal(8),intent(in)::A(:,:)\r\n\treal(8),allocatable,intent(out)::A_T(:,:)\r\n\tinteger n,m,i,j\r\n\t\r\n\tn=size(A,1)\r\n\tm=size(A,2)\r\n\tif(.not. allocated(A_T) )allocate(A_T(m,n))\r\n\t\r\n\tdo i=1,n\r\n\t \tdo j=1, m\r\n\t\t \tA_T(j,i)=A(i,j)\r\n\t \tenddo\r\n\tenddo\r\n\t\r\n end subroutine trans_rank_2\r\n!================================================================================== \r\nfunction trans1(A) result(A_T)\r\n\treal(8),intent(in)::A(:)\r\n\treal(8),allocatable::A_T(:,:)\r\n\tinteger n,m,i,j\r\n\t\r\n\tn=size(A)\r\n\tif(.not. allocated(A_T) )allocate(A_T(1,n))\r\n\t\r\n\tdo i=1,n\r\n\t\tA_T(1,i)=A(i)\r\n\tenddo\r\n\t\r\n end function trans1\r\n!================================================================================== \r\nfunction trans2(A) result(A_T)\r\n\treal(8),intent(in)::A(:,:)\r\n\treal(8),allocatable::A_T(:,:)\r\n\tinteger n,m,i,j\r\n\t\r\n\tn=size(A,1)\r\n\tm=size(A,2)\r\n\tif(.not. allocated(A_T) )allocate(A_T(m,n))\r\n\t\r\n\tdo i=1,n\r\n\t \tdo j=1, m\r\n\t\t \tA_T(j,i)=A(i,j)\r\n\t \tenddo\r\n\tenddo\r\n\t\r\n end function trans2\r\n!================================================================================== \r\nsubroutine inverse_rank_2(A,A_inv)\r\n\treal(8),intent(in)::A(:,:)\r\n\treal(8),allocatable::A_inv(:,:)\r\n\treal(8) detA,detA_1\r\n\tinteger m,n\r\n\t\r\n\tm=size(A,1)\r\n\tn=size(A,2)\r\n\tif(.not. allocated(A_inv) )allocate(A_inv(m,n))\r\n\tdetA=det_mat(A,n)\r\n\tif(detA==0.0d0) stop \"ERROR: inverse, detA=0\"\r\n\tdetA_1=1.0d0/detA\r\n\tif(n==2)then\r\n\t \tA_inv(1,1)=detA_1*A(2,2)\r\n\t \tA_inv(1,2)=-detA_1*A(1,2)\r\n\t \tA_inv(2,1)=-detA_1*A(2,1)\r\n\t \tA_inv(2,2)=detA_1*A(1,1)\r\n\telseif(n==3)then\r\n\t \tA_inv(1,1)=detA_1*(A(2,2)*A(3,3)-A(2,3)*A(3,2))\r\n\t \tA_inv(1,2)=detA_1*(A(1,3)*A(3,2)-A(1,2)*A(3,3))\r\n\t \tA_inv(1,3)=detA_1*(A(1,2)*A(2,3)-A(1,3)*A(2,2))\r\n\t \tA_inv(2,1)=detA_1*(A(2,3)*A(3,1)-A(2,1)*A(3,3))\r\n\t \tA_inv(2,2)=detA_1*(A(1,1)*A(3,3)-A(1,3)*A(3,1))\r\n\t \tA_inv(2,3)=detA_1*(A(1,3)*A(2,1)-A(1,1)*A(2,3))\r\n\t \tA_inv(3,1)=detA_1*(A(2,1)*A(3,2)-A(2,2)*A(3,1))\r\n\t \tA_inv(3,2)=detA_1*(A(1,2)*A(3,1)-A(1,1)*A(3,2))\r\n\t \tA_inv(3,3)=detA_1*(A(1,1)*A(2,2)-A(1,2)*A(2,1))\r\n\telse\r\n\t \tprint *, \"ERROR: Aij with i=j=\",n,\"/=2or3\"\r\n\tendif\r\n\t\r\n end subroutine inverse_rank_2\r\n!================================================================================== \r\nsubroutine tensor_exponential(A,expA,TOL,itr_tol)\r\n \treal(8),intent(in)::A(:,:),TOL\r\n \treal(8),allocatable,intent(inout)::expA(:,:)\r\n \tinteger, intent(in)::itr_tol\r\n \treal(8),allocatable::increA(:,:)\r\n \treal(8) increment,NN\r\n \tinteger i,j,n\r\n\t\r\n \tif(.not. allocated(expA) )allocate(expA(size(A,1),size(A,2) ))\r\n \tallocate(increA(size(A,1),size(A,2) ))\r\n \tif(size(A,1)/=size(A,2)) stop \"ERROR:tensor exp is not a square matrix\"\r\n\t\r\n \texpA(:,:)=0.0d0\r\n \tdo n=1,size(expA,1)\r\n\t \texpA(n,n)=1.0d0\r\n \tenddo\r\n \tNN=1.0d0\r\n \tincreA(:,:)=expA(:,:)\r\n \tdo n=1,itr_tol\r\n\t \tif(n>1)then\r\n\t\t \tNN = NN*(NN+1.0d0)\r\n\t \tendif\r\n\t \tincreA(:,:)=matmul(increA,A)\r\n\t \texpA(:,:)= expA(:,:)+1.0d0/NN*increA(:,:)\r\n\t \r\n\t \tincrement=0.0d0\r\n\t \tdo i=1,size(A,1)\r\n\t\t \tdo j=1,size(A,2)\r\n\t\t\t \tincrement=increment+1.0d0/NN*increA(i,j)*increA(i,j)\r\n\t\t \tenddo\r\n\t \tenddo\r\n\t \r\n\t \tif(increment<=TOL)then\r\n\t\t \texit\r\n\t \telse\r\n\t\t \tif(n>=itr_tol)then\r\n\t\t\t \tstop \"tensor exponential is not converged\"\r\n\t\t \tendif\r\n\t\t\tcycle\r\n\t \tendif\r\n \tenddo\r\n \r\n \tdeallocate(increA)\r\n \r\nend subroutine tensor_exponential\r\n!================================================================================== \r\nsubroutine tensor_expo_der(A,expA_A,TOL,itr_tol)\r\n \treal(8),intent(in)::A(:,:),TOL\r\n \treal(8),allocatable,intent(inout)::expA_A(:,:,:,:)\r\n \tinteger, intent(in)::itr_tol\r\n \treal(8),allocatable::increA_1(:,:),increA_2(:,:),increA_3(:,:,:,:),I_ij(:,:),A_inv(:,:)\r\n \treal(8) increment,NN\r\n \tinteger i,j,k,l,n,m,o\r\n\t\r\n \tif(.not. allocated(expA_A) )allocate(expA_A(size(A,1),size(A,1),size(A,1),size(A,1) ))\r\n \tallocate(I_ij(size(A,1),size(A,1) ))\r\n \tallocate(increA_1(size(A,1),size(A,1) ))\r\n \tallocate(increA_2(size(A,1),size(A,1) ))\r\n \tallocate(increA_3(size(A,1),size(A,1),size(A,1),size(A,1) ) )\r\n \tif(size(A,1)/=size(A,2)) stop \"ERROR:tensor exp is not a square matrix\"\r\n \r\n \tcall inverse_rank_2(A,A_inv)\r\n\r\n \tI_ij(:,:)=0.0d0\r\n \tdo n=1,size(expA_A,1)\r\n\t\tI_ij(n,n)=1.0d0\r\n \tenddo\r\n \tNN=1.0d0\r\n \r\n \tdo i=1,size(A,1)\r\n\t \tdo j=1,size(A,1)\r\n\t\t \tdo k=1, size(A,1)\r\n\t\t\t \tdo l=1, size(A,1)\r\n\t\t\t\t \texpA_A(i,j,k,l)=I_ij(i,k)*I_ij(l,j)\r\n\t\t\t \tenddo\r\n\t\t \tenddo\r\n\t \tenddo\r\n \tenddo\r\n \r\n \tincreA_1(:,:)=I_ij(:,:)\r\n \tincreA_2(:,:)=I_ij(:,:)\r\n \tdo n=1,itr_tol\r\n\t\tif(n>2)then\r\n\t\t\tNN = NN*(NN+1.0d0)\r\n\t\tendif\r\n\t\tincreA_1(:,:)=A_inv(:,:)\r\n\t\tincreA_2(:,:)=matmul(increA_2,A)\r\n\t \r\n\t \tincreA_3(:,:,:,:)=0.0d0\r\n\t \tdo m=1,n\r\n\t\t\tincreA_1(:,:)=matmul(increA_1,A )\r\n\t\t \r\n\t\t \tincreA_2(:,:)=matmul(increA_2,A_inv)\r\n\r\n\t\t \tdo i=1,size(A,1)\r\n\t\t\t\tdo j=1,size(A,1)\r\n\t\t\t\t \tdo k=1, size(A,1)\r\n\t\t\t\t\t \tdo l=1, size(A,1)\r\n\t\t\t\t\t\t \tincreA_3(i,j,k,l)=increA_3(i,j,k,l)+increA_1(i,k)*increA_2(l,j)\r\n\t\t\t\t\t\t \texpA_A(i,j,k,l)=expA_A(i,j,k,l)+1.0d0/NN*increA_3(i,j,k,l)\r\n\t\t\t\t\t \tenddo\r\n\t\t\t\t\tenddo\r\n\t\t\t \tenddo\r\n\t\t \tenddo\t\t\t\r\n\t \tenddo\r\n\r\n\t \tdo i=1,size(A,1)\r\n\t\t \tdo j=1,size(A,1)\r\n\t\t\t \tdo k=1, size(A,1)\r\n\t\t\t\t \tdo l=1, size(A,1)\r\n\t\t\t\t\t \tincrement=increment+1.0d0/NN*increA_3(i,j,k,l)&\r\n\t\t\t\t\t\t \t*increA_3(i,j,k,l)&\r\n\t\t\t\t\t\t \t*increA_3(i,j,k,l)&\r\n\t\t\t\t\t\t \t*increA_3(i,j,k,l)\r\n\t\t\t\t \tenddo\r\n\t\t\t \tenddo\r\n\t\t \tenddo\r\n\t \tenddo\t\t\t\r\n\r\n\t \tif(increment<=TOL)then\r\n\t\t\texit\r\n\t \telse\r\n\t\t \tif(n>=itr_tol)then\r\n\t\t\t \tstop \"tensor exponential is not converged\"\r\n\t\t \tendif\r\n\t\t \tcycle\r\n\t \tendif\r\n \tenddo\r\n \r\n \tdeallocate(increA_1,increA_2,increA_3,I_ij,A_inv)\r\n \r\nend subroutine tensor_expo_der\r\n!================================================================================== \r\n\r\nfunction GetNormRe(a) result(b)\r\n\treal(8),intent(in)::a(:)\r\n\treal(8) :: b\r\n\tb=dot_product(a,a)\r\nend function\r\n!================================================================================== \r\n\r\nfunction GetNormMatRe(a) result(b)\r\n\treal(8),intent(in)::a(:,:)\r\n\treal(8) :: b\r\n\tinteger :: i,j\r\n\tb=0\r\n\tdo i=1,size(a,1)\r\n\t\tdo j=1,size(a,2)\r\n\t\t\tb=b+a(i,j)*a(i,j)\r\n\t\tenddo\r\n\tenddo\r\nend function\r\n!================================================================================== \r\n\r\nfunction trace(a) result(b)\r\n\treal(8),intent(in)::a(:,:)\r\n\treal(8) :: b\r\n\tinteger :: i,j\r\n\tb=0\r\n\tdo i=1,size(a,1)\r\n\t\tb=b+a(i,i)\r\n\tenddo\r\nend function\r\n!================================================================================== \r\n\r\n!================================================================================== \r\nfunction pi(n) result(res)\r\n\tinteger,intent(in)::n\r\n\treal(8) :: ptr\r\n\treal(8) :: an,bn,tn,pn\r\n\treal(8) :: atr,btr,ttr\r\n\treal(8) :: res\r\n\r\n\tinteger :: i\r\n\r\n\tan=1.0d0\r\n\tbn=1.0d0/sqrt(2.0d0)\r\n\ttn=0.250d0\r\n\tpn=1.00d0\r\n\tdo i=1,n\r\n\t\tatr=0.50d0*(an+bn)\r\n\t\tbtr=dsqrt(an*bn)\r\n\t\tttr=tn-pn*(atr-an)*(atr-an)\r\n\t\tptr=2.0d0*pn\r\n\r\n\t\tan=atr\r\n\t\tbn=btr\r\n\t\ttn=ttr\r\n\t\tpn=ptr\r\n\r\n\t\tres=(atr+btr)*(atr+btr)/4.0d0/ttr\r\n\tenddo\r\n\r\nend function\r\n!================================================================================== \r\n\r\n\r\n\r\n\r\n!================================================================================== \r\nfunction fstring_int(x) result(a)\r\n\tinteger,intent(in) :: x\r\n\tcharacter(len=20)\t:: a\r\n\r\n\twrite(a,*) x\r\n\r\nend function\r\n!================================================================================== \r\n\r\n\r\n\r\n\r\n!================================================================================== \r\nfunction fstring_int_len(x,length) result(a)\r\n\tinteger,intent(in) :: x\r\n\tinteger,intent(in) :: length\r\n\tcharacter(len=length)\t:: a\r\n\r\n\twrite(a,*) x\r\n\r\nend function\r\n!================================================================================== \r\n\r\n\r\n\r\n!================================================================================== \r\nfunction fstring_real(x) result(a)\r\n\treal(8),intent(in) :: x\r\n\tcharacter(len=20)\t:: a\r\n\r\n\r\n\twrite(a,'(f0.8)') x\r\n\r\nend function\r\n!================================================================================== \r\n\r\n\r\n\r\n!================================================================================== \r\nfunction fstring_real_len(x,length) result(a)\r\n\treal(8),intent(in) :: x\r\n\tinteger,intent(in) :: length\r\n\tcharacter(len=60)\t:: a\r\n\tcharacter*40\t\t\t\t\t\t:: form\r\n\r\n\t\r\n\twrite(a,'(f0.10)') x\r\n\r\nend function\r\n!================================================================================== \r\n\r\n\r\n\r\n!================================================================================== \r\nfunction fint(ch)\tresult(a)\r\n\tcharacter(*),intent(in)\t\t\t:: ch\r\n\tinteger\t\t\t\t:: a\r\n\r\n\tread(ch,*) a\r\n\r\nend function\r\n!================================================================================== \r\n\r\n\r\n!================================================================================== \r\nfunction freal(ch)\tresult(a)\r\n\tcharacter(*),intent(in)\t\t\t:: ch\r\n\treal(8)\t\t\t\t:: a\r\n\r\n\tread(ch,*) a\r\n\r\nend function\r\n!================================================================================== \r\n\r\n\r\n\r\n!================================================================================== \r\nfunction input_Int(default,option) result(val)\r\n\tinteger,intent(in) :: default\r\n\tinteger,optional,intent(in)::option\r\n\tinteger :: val\r\n\r\n\tif(present(option) )then\r\n\t\tval=option\r\n\telse\r\n\t\tval=default\r\n\tendif\r\n\r\nend function\r\n!================================================================================== \r\n\r\n\r\n\r\n\r\n!================================================================================== \r\nfunction input_Real(default,option) result(val)\r\n\treal(8),intent(in) :: default\r\n\treal(8),optional,intent(in)::option\r\n\treal(8) :: val\r\n\r\n\tif(present(option) )then\r\n\t\tval=option\r\n\telse\r\n\t\tval=default\r\n\tendif\r\n\r\nend function\r\n!================================================================================== \r\n\r\n\r\n\r\n\r\n\r\n!================================================================================== \r\nfunction input_IntVec(default,option) result(val)\r\n\tinteger,intent(in) :: default(:)\r\n\tinteger,optional,intent(in)::option(:)\r\n\tinteger,allocatable :: val(:)\r\n\tinteger :: n,m\r\n\r\n\tif(present(option) )then\r\n\t\tn=size(option,1)\r\n\t\tallocate(val(n) )\r\n\t\tval(:)=option(:)\r\n\telse\r\n\t\tn=size(default,1)\r\n\t\tallocate(val(n) )\r\n\t\tval(:)=default(:)\r\n\tendif\r\n\r\nend function\r\n!================================================================================== \r\n\r\n!================================================================================== \r\nfunction input_Realvec(default,option) result(val)\r\n\treal(8),intent(in) :: default(:)\r\n\treal(8),optional,intent(in)::option(:)\r\n\treal(8),allocatable :: val(:)\r\n\tinteger :: n,m\r\n\r\n\tif(present(option) )then\r\n\t\tn=size(option,1)\r\n\t\tallocate(val(n) )\r\n\t\tval(:)=option(:)\r\n\telse\r\n\t\tn=size(default,1)\r\n\t\tallocate(val(n) )\r\n\t\tval(:)=default(:)\r\n\tendif\r\n\r\nend function\r\n!================================================================================== \r\n\r\n\r\n\r\n\r\n!================================================================================== \r\nfunction input_IntArray(default,option) result(val)\r\n\tinteger,intent(in) :: default(:,:)\r\n\tinteger,optional,intent(in)::option(:,:)\r\n\tinteger,allocatable :: val(:,:)\r\n\tinteger :: n,m\r\n\r\n\tif(present(option) )then\r\n\t\tn=size(option,1)\r\n\t\tm=size(option,2)\r\n\t\tallocate(val(n,m) )\r\n\t\tval(:,:)=option(:,:)\r\n\telse\r\n\t\tn=size(default,1)\r\n\t\tm=size(default,2)\r\n\t\tallocate(val(n,m) )\r\n\t\tval(:,:)=default(:,:)\r\n\tendif\r\n\r\nend function\r\n!================================================================================== \r\n\r\n!================================================================================== \r\nfunction input_RealArray(default,option) result(val)\r\n\treal(8),intent(in) :: default(:,:)\r\n\treal(8),optional,intent(in)::option(:,:)\r\n\treal(8),allocatable :: val(:,:)\r\n\tinteger :: n,m\r\n\r\n\tif(present(option) )then\r\n\t\tn=size(option,1)\r\n\t\tm=size(option,2)\r\n\t\tallocate(val(n,m) )\r\n\t\tval(:,:)=option(:,:)\r\n\telse\r\n\t\tn=size(default,1)\r\n\t\tm=size(default,2)\r\n\t\tallocate(val(n,m) )\r\n\t\tval(:,:)=default(:,:)\r\n\tendif\r\n\r\nend function\r\n!================================================================================== \r\n\r\n\r\n!================================================================================== \r\nfunction input_String(default,option) result(val)\r\n\tcharacter(*),intent(in) :: default\r\n\tcharacter(*),optional,intent(in)::option\r\n\tcharacter(len(default) ) :: val\r\n\r\n\tif(present(option) )then\r\n\t\tval=option\r\n\telse\r\n\t\tval=default\r\n\tendif\r\n\r\nend function\r\n!================================================================================== \r\n\r\n!================================================================================== \r\nfunction input_logical(default,option) result(val)\r\n\tlogical,intent(in) :: default\r\n\tlogical,optional,intent(in)::option\r\n\tlogical :: val\r\n\r\n\tif(present(option) )then\r\n\t\tval=option\r\n\telse\r\n\t\tval=default\r\n\tendif\r\n\r\nend function\r\n!================================================================================== \r\n\r\nfunction zeroif_Int(val,negative,positive) result(retval)\r\n\tinteger,intent(in)::val\r\n\tinteger :: retval\r\n\tlogical,optional,intent(in) :: negative,positive\r\n\r\n\tif(val/=val)then\r\n\t\tprint *, \"ERROR :: MAthClass >> zeroif_Int is invalid\"\r\n\tendif\r\n\tretval=val\r\n\tif(present(negative) )then\r\n\t\tif(negative .eqv. .true.)then\r\n\t\t\tif(val<0)then\r\n\t\t\t\tretval=0\r\n\t\t\tendif\r\n\t\tendif\r\n\tendif\r\n\t\r\n\tif(present(positive) )then\r\n\t\tif(positive .eqv. .true.)then\r\n\t\t\tif(val>0)then\r\n\t\t\t\tretval=0\r\n\t\t\tendif\r\n\t\tendif\r\n\tendif\r\n\r\nend function\r\n\t\r\n\r\nfunction zeroif_Real(val,negative,positive) result(retval)\r\n\treal(8),intent(in)::val\r\n\treal(8) :: retval\r\n\tlogical,optional,intent(in) :: negative,positive\r\n\r\n\tif(val/=val)then\r\n\t\tprint *, \"ERROR :: MAthClass >> zeroif_Int is invalid\"\r\n\tendif\r\n\tretval=val\r\n\tif(present(negative) )then\r\n\t\tif(negative .eqv. .true.)then\r\n\t\t\tif(val<0.0d0)then\r\n\t\t\t\tretval=0.0d0\r\n\t\t\tendif\r\n\t\tendif\r\n\tendif\r\n\t\r\n\tif(present(positive) )then\r\n\t\tif(positive .eqv. .true.)then\r\n\t\t\tif(val>0.0d0)then\r\n\t\t\t\tretval=0.0d0\r\n\t\t\tendif\r\n\t\tendif\r\n\tendif\r\n\r\nend function\r\n\r\n! ########################################################\r\nsubroutine removeWord_String(str,keyword,itr,Compare)\r\n\tcharacter(*),intent(inout)::str\r\n\tcharacter(*),intent(in )::keyword\r\n\t\r\n\tinteger :: len_total,len_kw,i,j,n,itr_max\r\n\tinteger,optional,intent(in)::itr\r\n\tlogical,optional,intent(in)::Compare\r\n\tlogical :: bk\r\n\t\r\n\r\n\tif(present(Compare))then\r\n\t\tif(Compare .eqv. .true.)then\r\n\t\t\tprint *, \"Before :: \",str\t\r\n\t\tendif\r\n\tendif\r\n\r\n\titr_max=input(default=1,option=itr)\r\n\tbk=.false.\r\n\tlen_total=len(str)\r\n\tlen_kw\t =len(keyword)\r\n\r\n\tdo i=1,itr_max\r\n\t\tn=index(str,keyword)\r\n\t\tdo j=n,n+len_kw\r\n\t\t\tstr(j:j)=\" \"\r\n\t\tenddo\r\n\t\tif(n==0)then\r\n\t\t\texit\r\n\t\tendif\t\r\n\tenddo\r\n\r\n\tif(present(Compare))then\r\n\t\tif(Compare .eqv. .true.)then\r\n\t\t\tprint *, \"After :: \",str\t\r\n\t\tendif\r\n\tendif\r\n\r\n\r\n\t\r\nend subroutine\r\n! ########################################################\r\n\r\nend module MathClass\r\n", "meta": {"hexsha": "57766618b101ab41419520eec4f0640a22460318", "size": 20790, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/TreeClass/MathClass.f90", "max_stars_repo_name": "kazulagi/plantfem_min", "max_stars_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2020-06-21T08:21:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:28:30.000Z", "max_issues_repo_path": "src/TreeClass/MathClass.f90", "max_issues_repo_name": "kazulagi/plantfem_min", "max_issues_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-08T05:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:39:29.000Z", "max_forks_repo_path": "src/TreeClass/MathClass.f90", "max_forks_repo_name": "kazulagi/plantfem_min", "max_forks_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-10-20T18:28:59.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-15T08:35:25.000Z", "avg_line_length": 23.3858267717, "max_line_length": 125, "alphanum_fraction": 0.4632515633, "num_tokens": 6245, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.8289388104343893, "lm_q1q2_score": 0.7651429868424889}} {"text": "program area_triangle\nimplicit none\n\nREAL :: area_9, s_9, sqrt, x11, y11, x22, y22, x33, y33, p_1, a_1, b_1, c_1\n\nprint*,'enter the value of three sides of triangle x1,y1'\nread*,x11,y11\n\nprint*,'enter the value of three sides of triangle x2,y2'\nread*,x22,y22\n\nprint*,'enter the value of three sides of triangle x3,y3'\nread*,x33,y33\n\na_1=sqrt((x22-x11)**2+(y22-y11)**2)\nb_1=sqrt((x33-x22)**2+(y33-y22)**2)\nc_1=sqrt((x11-x33)**2+(y11-y33)**2)\n\nIF (a_1+b_1>c_1 .and. b_1+c_1>a_1 .and. c_1+a_1>b_1) THEN\n s_9=(a_1+b_1+c_1)/2\n area_9=sqrt(s_9*(s_9-a_1)*(s_9-b_1)*(s_9-c_1))\n print*,'[+] Area of the triangle |-> ',area_9\n p_1=2*s_9\n print*,'[+] Perimiter of the triangle is |-> ',p_1\n print*,\"\"\n print*,\"\"\n print*,\"---------------------------Variable TABLE------------------------------\"\n print*,\"[^] Variable X1 and Y2 -> | X variable => \", x11, \" Y Variable -> \", y11\n print*,\"[^] Variable X2 and Y2 -> | X variable => \", x22, \" Y Variable -> \", y22\n print*,\"[^] Variable X3 and Y3 -> | X variable => \", x33, \" Y Variable -> \", y33\nELSE \n print*,'[!] These points do not seem to validate a triangle'\n print*,\"\"\n print*,\"\"\n print*,\"---------------------------Variable TABLE------------------------------\"\n print*,\"[^] Variable X1 and Y2 -> | X variable => \", x11, \" Y Variable -> \", y11\n print*,\"[^] Variable X2 and Y2 -> | X variable => \", x22, \" Y Variable -> \", y22\n print*,\"[^] Variable X3 and Y3 -> | X variable => \", x33, \" Y Variable -> \", y33\nEND IF\n\nend program area_triangle", "meta": {"hexsha": "f4a8f842a90571d17a257a0f322c9c53b8901af1", "size": 1542, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "trig.f90", "max_stars_repo_name": "ArkAngeL43/tron95", "max_stars_repo_head_hexsha": "154d72613536ba35c9ef611006003c5fd529eb00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "trig.f90", "max_issues_repo_name": "ArkAngeL43/tron95", "max_issues_repo_head_hexsha": "154d72613536ba35c9ef611006003c5fd529eb00", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "trig.f90", "max_forks_repo_name": "ArkAngeL43/tron95", "max_forks_repo_head_hexsha": "154d72613536ba35c9ef611006003c5fd529eb00", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.6097560976, "max_line_length": 84, "alphanum_fraction": 0.551232166, "num_tokens": 554, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377272885904, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.765092135284691}} {"text": " function inv_2(T)\n implicit none\n \n type(Tensor2), intent(in) :: T\n type(Tensor2) :: inv_2\n real(kind=8) :: idetT\n \n idetT = 1.d0/det(T)\n \n inv_2%ab(1,1)=+idetT*(T%ab(2,2)*T%ab(3,3)-T%ab(2,3)*T%ab(3,2))\n inv_2%ab(2,1)=-idetT*(T%ab(2,1)*T%ab(3,3)-T%ab(2,3)*T%ab(3,1))\n inv_2%ab(3,1)=+idetT*(T%ab(2,1)*T%ab(3,2)-T%ab(2,2)*T%ab(3,1))\n inv_2%ab(1,2)=-idetT*(T%ab(1,2)*T%ab(3,3)-T%ab(1,3)*T%ab(3,2))\n inv_2%ab(2,2)=+idetT*(T%ab(1,1)*T%ab(3,3)-T%ab(1,3)*T%ab(3,1))\n inv_2%ab(3,2)=-idetT*(T%ab(1,1)*T%ab(3,2)-T%ab(1,2)*T%ab(3,1))\n inv_2%ab(1,3)=+idetT*(T%ab(1,2)*T%ab(2,3)-T%ab(1,3)*T%ab(2,2))\n inv_2%ab(2,3)=-idetT*(T%ab(1,1)*T%ab(2,3)-T%ab(1,3)*T%ab(2,1))\n inv_2%ab(3,3)=+idetT*(T%ab(1,1)*T%ab(2,2)-T%ab(1,2)*T%ab(2,1))\n \n end function inv_2\n \n function inv_2s(T)\n implicit none\n \n type(Tensor2s), intent(in) :: T\n type(Tensor2s) :: inv_2s\n real(kind=8) :: idetT\n \n idetT = 1.d0/det(T)\n \n inv_2s%a6(1)=+idetT*(T%a6(2)*T%a6(3) -T%a6(5)*T%a6(5))\n inv_2s%a6(4)=-idetT*(T%a6(4)*T%a6(3) -T%a6(5)*T%a6(6))\n inv_2s%a6(6)=+idetT*(T%a6(4)*T%a6(5) -T%a6(2)*T%a6(6))\n inv_2s%a6(2)=+idetT*(T%a6(1)*T%a6(3) -T%a6(6)*T%a6(6))\n inv_2s%a6(5)=-idetT*(T%a6(1)*T%a6(5) -T%a6(4)*T%a6(6))\n inv_2s%a6(3)=+idetT*(T%a6(1)*T%a6(2) -T%a6(4)*T%a6(4))\n \n end function inv_2s\n \n function inv2d(T,detT)\n implicit none\n \n type(Tensor2), intent(in) :: T\n type(Tensor2) :: inv2d\n real(kind=8) :: detT, idetT\n \n idetT = 1.d0/detT\n \n inv2d%ab(1,1)=+idetT*(T%ab(2,2)*T%ab(3,3)-T%ab(2,3)*T%ab(3,2))\n inv2d%ab(2,1)=-idetT*(T%ab(2,1)*T%ab(3,3)-T%ab(2,3)*T%ab(3,1))\n inv2d%ab(3,1)=+idetT*(T%ab(2,1)*T%ab(3,2)-T%ab(2,2)*T%ab(3,1))\n inv2d%ab(1,2)=-idetT*(T%ab(1,2)*T%ab(3,3)-T%ab(1,3)*T%ab(3,2))\n inv2d%ab(2,2)=+idetT*(T%ab(1,1)*T%ab(3,3)-T%ab(1,3)*T%ab(3,1))\n inv2d%ab(3,2)=-idetT*(T%ab(1,1)*T%ab(3,2)-T%ab(1,2)*T%ab(3,1))\n inv2d%ab(1,3)=+idetT*(T%ab(1,2)*T%ab(2,3)-T%ab(1,3)*T%ab(2,2))\n inv2d%ab(2,3)=-idetT*(T%ab(1,1)*T%ab(2,3)-T%ab(1,3)*T%ab(2,1))\n inv2d%ab(3,3)=+idetT*(T%ab(1,1)*T%ab(2,2)-T%ab(1,2)*T%ab(2,1))\n \n end function inv2d\n \n function inv2sd(T,detT)\n implicit none\n \n type(Tensor2s), intent(in) :: T\n type(Tensor2s) :: inv2sd\n real(kind=8):: detT, idetT\n \n idetT = 1.d0/detT\n \n inv2sd%a6(1)=+idetT*(T%a6(2)*T%a6(3) -T%a6(5)*T%a6(5))\n inv2sd%a6(4)=-idetT*(T%a6(4)*T%a6(3) -T%a6(5)*T%a6(6))\n inv2sd%a6(6)=+idetT*(T%a6(4)*T%a6(5) -T%a6(2)*T%a6(6))\n inv2sd%a6(2)=+idetT*(T%a6(1)*T%a6(3) -T%a6(6)*T%a6(6))\n inv2sd%a6(5)=-idetT*(T%a6(1)*T%a6(5) -T%a6(4)*T%a6(6))\n inv2sd%a6(3)=+idetT*(T%a6(1)*T%a6(2) -T%a6(4)*T%a6(4))\n \n end function inv2sd", "meta": {"hexsha": "b2d1c95f003674f98d89324a1f27b59dd5db9b1c", "size": 3044, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ttb/libinv.f", "max_stars_repo_name": "kengwit/ttb", "max_stars_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 41, "max_stars_repo_stars_event_min_datetime": "2018-02-27T06:31:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-30T07:58:45.000Z", "max_issues_repo_path": "ttb/libinv.f", "max_issues_repo_name": "kengwit/ttb", "max_issues_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-12-01T07:47:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-16T05:42:06.000Z", "max_forks_repo_path": "ttb/libinv.f", "max_forks_repo_name": "kengwit/ttb", "max_forks_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-07-12T01:45:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-25T08:03:13.000Z", "avg_line_length": 39.5324675325, "max_line_length": 70, "alphanum_fraction": 0.4645203679, "num_tokens": 1696, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693688269984, "lm_q2_score": 0.8056321889812554, "lm_q1q2_score": 0.7650842124165419}} {"text": "C-----------------------------------------------------------------------\n FUNCTION GCDIST(RLAT1,RLON1,RLAT2,RLON2)\nC$$$ SUBPROGRAM DOCUMENTATION BLOCK\nC\nC SUBPROGRAM: GCDIST COMPUTE GREAT CIRCLE DISTANCE\nC PRGMMR: IREDELL ORG: W/NMC23 DATE: 96-04-10\nC\nC ABSTRACT: THIS SUBPROGRAM COMPUTES GREAT CIRCLE DISTANCE\nC BETWEEN TWO POINTS ON THE EARTH.\nC\nC PROGRAM HISTORY LOG:\nC 96-04-10 IREDELL\nC\nC USAGE: ...GCDIST(RLAT1,RLON1,RLAT2,RLON2)\nC\nC INPUT ARGUMENT LIST:\nC RLAT1 - REAL LATITUDE OF POINT 1 IN DEGREES\nC RLON1 - REAL LONGITUDE OF POINT 1 IN DEGREES\nC RLAT2 - REAL LATITUDE OF POINT 2 IN DEGREES\nC RLON2 - REAL LONGITUDE OF POINT 2 IN DEGREES\nC\nC OUTPUT ARGUMENT LIST:\nC GCDIST - REAL GREAT CIRCLE DISTANCE IN METERS\nC\nC ATTRIBUTES:\nC LANGUAGE: FORTRAN 77\nC\nC$$$\n PARAMETER(RERTH=6.3712E6)\n PARAMETER(PI=3.14159265358979,DPR=180./PI)\nC - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n CLAT1=COS(RLAT1/DPR)\n SLAT1=SIN(RLAT1/DPR)\n CLAT2=COS(RLAT2/DPR)\n SLAT2=SIN(RLAT2/DPR)\n CDLON=COS((RLON1-RLON2)/DPR)\n CRD=SLAT1*SLAT2+CLAT1*CLAT2*CDLON\n GCDIST=RERTH*ACOS(CRD)\nC - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n END\n", "meta": {"hexsha": "76206fcb44a3847e5e7cbe9de38130e45926083c", "size": 1295, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "grib2/iplib_hwrf/gcdist.f", "max_stars_repo_name": "AerodyneLabs/Stratocast", "max_stars_repo_head_hexsha": "5e635a6cc199d10a9f5f01db3eb4db541f8bd3d2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2015-06-11T00:07:56.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-16T10:56:31.000Z", "max_issues_repo_path": "grib2/iplib_hwrf/gcdist.f", "max_issues_repo_name": "AerodyneLabs/Stratocast", "max_issues_repo_head_hexsha": "5e635a6cc199d10a9f5f01db3eb4db541f8bd3d2", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-11-09T06:08:49.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-15T10:49:19.000Z", "max_forks_repo_path": "grib2/iplib_hwrf/gcdist.f", "max_forks_repo_name": "AerodyneLabs/Stratocast", "max_forks_repo_head_hexsha": "5e635a6cc199d10a9f5f01db3eb4db541f8bd3d2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-06-12T10:37:02.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-19T10:26:32.000Z", "avg_line_length": 31.5853658537, "max_line_length": 72, "alphanum_fraction": 0.5613899614, "num_tokens": 499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338046748209, "lm_q2_score": 0.795658090372256, "lm_q1q2_score": 0.7650521508559378}} {"text": "*DECK DSUDS\n SUBROUTINE DSUDS (A, X, B, NEQ, NUK, NRDA, IFLAG, MLSO, WORK,\n + IWORK)\nC***BEGIN PROLOGUE DSUDS\nC***SUBSIDIARY\nC***PURPOSE Subsidiary to DBVSUP\nC***LIBRARY SLATEC\nC***TYPE DOUBLE PRECISION (SUDS-S, DSUDS-D)\nC***AUTHOR Watts, H. A., (SNLA)\nC***DESCRIPTION\nC\nC DSUDS solves the underdetermined system of linear equations A Z =\nC B where A is NEQ by NUK and NEQ .LE. NUK. in particular, if rank\nC A equals IRA, a vector X and a matrix U are determined such that\nC X is the UNIQUE solution of smallest length, satisfying A X = B,\nC and the columns of U form an orthonormal basis for the null\nC space of A, satisfying A U = 0 . Then all solutions Z are\nC given by\nC Z = X + C(1)*U(1) + ..... + C(NUK-IRA)*U(NUK-IRA)\nC where U(J) represents the J-th column of U and the C(J) are\nC arbitrary constants.\nC If the system of equations are not compatible, only the least\nC squares solution of minimal length is computed.\nC DSUDS is an interfacing routine which calls subroutine DLSSUD\nC for the solution. DLSSUD in turn calls subroutine DORTHR and\nC possibly subroutine DOHTRL for the decomposition of A by\nC orthogonal transformations. In the process, DORTHR calls upon\nC subroutine DCSCAL for scaling.\nC\nC ********************************************************************\nC INPUT\nC ********************************************************************\nC\nC A -- Contains the matrix of NEQ equations in NUK unknowns and must\nC be dimensioned NRDA by NUK. The original A is destroyed.\nC X -- Solution array of length at least NUK.\nC B -- Given constant vector of length NEQ, B is destroyed.\nC NEQ -- Number of equations, NEQ greater or equal to 1.\nC NUK -- Number of columns in the matrix (which is also the number\nC of unknowns), NUK not smaller than NEQ.\nC NRDA -- Row dimension of A, NRDA greater or equal to NEQ.\nC IFLAG -- Status indicator\nC =0 for the first call (and for each new problem defined by\nC a new matrix A) when the matrix data is treated as exact\nC =-K for the first call (and for each new problem defined by\nC a new matrix A) when the matrix data is assumed to be\nC accurate to about K digits.\nC =1 for subsequent calls whenever the matrix A has already\nC been decomposed (problems with new vectors B but\nC same matrix A can be handled efficiently).\nC MLSO -- =0 if only the minimal length solution is wanted.\nC =1 if the complete solution is wanted, includes the\nC linear space defined by the matrix U in the abstract.\nC WORK(*),IWORK(*) -- Arrays for storage of internal information,\nC WORK must be dimensioned at least\nC NUK + 3*NEQ + MLSO*NUK*(NUK-RANK A)\nC where it is possible for 0 .LE. RANK A .LE. NEQ\nC IWORK must be dimensioned at least 3 + NEQ\nC IWORK(2) -- Scaling indicator\nC =-1 if the matrix is to be pre-scaled by\nC columns when appropriate.\nC If the scaling indicator is not equal to -1\nC no scaling will be attempted.\nC For most problems scaling will probably not be necessary\nC\nC *********************************************************************\nC OUTPUT\nC *********************************************************************\nC\nC IFLAG -- Status indicator\nC =1 if solution was obtained.\nC =2 if improper input is detected.\nC =3 if rank of matrix is less than NEQ.\nC to continue simply reset IFLAG=1 and call DSUDS again.\nC =4 if the system of equations appears to be inconsistent.\nC However, the least squares solution of minimal length\nC was obtained.\nC X -- Minimal length least squares solution of A X = B.\nC A -- Contains the strictly upper triangular part of the reduced\nC matrix and transformation information.\nC WORK(*),IWORK(*) -- Contains information needed on subsequent\nC calls (IFLAG=1 case on input) which must not\nC be altered.\nC The matrix U described in the abstract is\nC stored in the NUK*(NUK-rank A) elements of\nC the WORK array beginning at WORK(1+NUK+3*NEQ).\nC However U is not defined when MLSO=0 or\nC IFLAG=4.\nC IWORK(1) contains the numerically determined\nC rank of the matrix A\nC\nC *********************************************************************\nC\nC***SEE ALSO DBVSUP\nC***REFERENCES H. A. Watts, Solving linear least squares problems\nC using SODS/SUDS/CODS, Sandia Report SAND77-0683,\nC Sandia Laboratories, 1977.\nC***ROUTINES CALLED DLSSUD\nC***REVISION HISTORY (YYMMDD)\nC 750601 DATE WRITTEN\nC 890831 Modified array declarations. (WRB)\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900328 Added TYPE section. (WRB)\nC 910408 Updated the AUTHOR and REFERENCES sections. (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE DSUDS\n INTEGER IFLAG, IL, IP, IS, IWORK(*), KS, KT, KU, KV, MLSO, NEQ,\n 1 NRDA, NUK\n DOUBLE PRECISION A(NRDA,*), B(*), WORK(*), X(*)\nC\nC***FIRST EXECUTABLE STATEMENT DSUDS\n IS = 2\n IP = 3\n IL = IP + NEQ\n KV = 1 + NEQ\n KT = KV + NEQ\n KS = KT + NEQ\n KU = KS + NUK\nC\n CALL DLSSUD(A,X,B,NEQ,NUK,NRDA,WORK(KU),NUK,IFLAG,MLSO,IWORK(1),\n 1 IWORK(IS),A,WORK(1),IWORK(IP),B,WORK(KV),WORK(KT),\n 2 IWORK(IL),WORK(KS))\nC\n RETURN\n END\n", "meta": {"hexsha": "74455bb02474d55fdbef29df8f48aba6ead087df", "size": 5888, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/dsuds.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/dsuds.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/dsuds.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.7301587302, "max_line_length": 72, "alphanum_fraction": 0.5789741848, "num_tokens": 1542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7650126701526301}} {"text": "program poisson \n\tuse poisson_module\n\t\n\timplicit none\n\n\tinteger, parameter :: N=256\n\treal, parameter :: eps=.005\n\treal, parameter :: M_PI = 2.D0*DASIN(1.D0)\n\n\n\tinteger :: i,j,k,ret\n\treal, allocatable, dimension(:,:) :: u,u0,f\n\treal :: h, l2\n\n\th = 1. / (N+1)\n\n\tallocate(u(N+1,N+1),u0(N+1,N+1),f(N+1,N+1))\n\t\n\tu0 = 0.\n\tdo i = 2, N\n\t\tdo j = 2, N\n\t\t\tf(i,j) = -2.*100. * M_PI * M_PI * sin(10.*M_PI*(i-1)*h) * sin(10.*M_PI*(j-1)*h)\n\t\tenddo\n\tenddo\n\n\tk = 0\n\tl2 = 1.\n\tdo while (l2 > eps)\n\t\tl2 = 0.\n\n\t\tdo i = 2, N\n\t\t\tdo j = 2, N\n\t\t\t\tu(i,j) = 0.25 * ( u0(i-1,j) + u0(i+1,j) + u0(i,j-1) + u0(i,j+1) - f(i,j)*h*h);\n\t\t\t\t! L2 norm\n\t\t\t\tl2 = l2 + (u0(i,j) - u(i,j))*(u0(i,j) - u(i,j));\n\t\t\tenddo\n\t\tenddo\n\n\t\tu0 = u\n\t\t! output\t\n\t\twrite(*,*) 'iteration',k,sqrt(l2)\n\t\tret=write_to_file_binary(N,c_loc(u(1,1)),k,-1.,1.)\n\t\tk = k + 1\n\tenddo\t\n\tdeallocate(u,u0,f)\n\nend program poisson\n", "meta": {"hexsha": "6cb3306f0440ee2d482e038fbe9d6bbe308bc028", "size": 858, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Exos/old/codes_fortran/poisson.f90", "max_stars_repo_name": "vkeller/math-454", "max_stars_repo_head_hexsha": "0bf3a81214f094dbddec868d3d133986b31f4b01", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-19T13:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-19T13:31:49.000Z", "max_issues_repo_path": "Exos/old/codes_fortran/poisson.f90", "max_issues_repo_name": "vkeller/math-454", "max_issues_repo_head_hexsha": "0bf3a81214f094dbddec868d3d133986b31f4b01", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Exos/old/codes_fortran/poisson.f90", "max_forks_repo_name": "vkeller/math-454", "max_forks_repo_head_hexsha": "0bf3a81214f094dbddec868d3d133986b31f4b01", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.875, "max_line_length": 82, "alphanum_fraction": 0.520979021, "num_tokens": 402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458251637412, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.7650126568468005}} {"text": "C NCLFORTSTART\n SUBROUTINE DAAMOM1(U,DP,LAT,WGT,MLON,NLAT,KLVL,UMSG,AAM)\n IMPLICIT NONE\n\nc NCL: aam = angmom_atm (u,dp,lat,wgt)\n\nc INPUT\n INTEGER MLON,NLAT,KLVL\n DOUBLE PRECISION U(MLON,NLAT,KLVL),LAT(NLAT),WGT(NLAT),UMSG,\n + DP(KLVL)\nc OUTPUT\n DOUBLE PRECISION AAM\nC NCLEND\n\nc Compute the atmosphere's relative angular momentum\n\nc nomenclature:\nc . u - zonal wind component (m/s)\nc . dp - pressure thickness (Pa)\nc. a 1D array\nc . lat - latitudes\nc . wgt - wgts associated with each latitude\nc . These could be gaussian weights or cos(lat)*dlat\nc . where \"dlat\" is the latitudinal spacing in radians\nc . mlon - number of longitudes\nc . nlat - number of latitudes\nc . klvl - number of levels\nc . umsg - missing code for \"u\"\nc . aam - atmospheric angular momentum [relative]\nc . units: kg*m2/s\n\nc LOCAL\n INTEGER ML,NL,KL\n DOUBLE PRECISION PI,TWOPI,RAD,RE,RE3,G,DLAT,UDP\n\n PI = 4.0D0*ATAN(1.0D0)\n RAD = PI/180.D0\n TWOPI = 2.0D0*PI\n\n RE = 6.37122D06\n RE3 = RE**3\n G = 9.81D0\n AAM = 0.0D0\n\n DO NL = 1,NLAT\nc at each latitude\nc sum u*dp over all longitudes\n UDP = 0.0D0\n DO ML = 1,MLON\n DO KL = 1,KLVL\n IF (U(ML,NL,KL).NE.UMSG) THEN\n UDP = UDP + U(ML,NL,KL)*DP(KL)\n END IF\n END DO\n END DO\nc 'zonal average' udp\n UDP = UDP/MLON\nc latitudinal contribution to aam\n AAM = AAM + UDP*COS(LAT(NL)*RAD)*WGT(NL)*TWOPI\n END DO\n\n AAM = (RE3/G)*AAM\n\n RETURN\n END\nc ---------------------------------------------------------\nc The ONLY difference between the aamom1 and aamom3 is that\nc in the the former \"dp\" is 1D while in the latter it is 3D\nc ---------------------------------------------------------\nC NCLFORTSTART\n SUBROUTINE DAAMOM3(U,DP,LAT,WGT,MLON,NLAT,KLVL,UMSG,AAM)\n IMPLICIT NONE\n\nc NCL: aam = angmom_atm (u,dp,lat,wgt)\n\nc INPUT\n INTEGER MLON,NLAT,KLVL\n DOUBLE PRECISION U(MLON,NLAT,KLVL),LAT(NLAT),WGT(NLAT),UMSG,\n + DP(MLON,NLAT,KLVL)\nc OUTPUT\n DOUBLE PRECISION AAM\nC NCLEND\n\nc nomenclature: [same as above BUT\nc . dp - pressure thickness (Pa)\nc. a 3D array\n\nc LOCAL\n INTEGER ML,NL,KL\n DOUBLE PRECISION PI,TWOPI,RAD,RE,RE3,G,DLAT,UDP\n\n PI = 4.0D0*ATAN(1.0D0)\n RAD = PI/180.D0\n TWOPI = 2.0D0*PI\n\n RE = 6.37122D06\n RE3 = RE**3\n G = 9.81D0\n AAM = 0.0D0\nc latitude\n DO NL = 1,NLAT\nc at each latitude\nc sum u*dp over all longitudes\n UDP = 0.0D0\n DO ML = 1,MLON\n DO KL = 1,KLVL\n IF (U(ML,NL,KL).NE.UMSG) THEN\n UDP = UDP + U(ML,NL,KL)*DP(ML,NL,KL)\n END IF\n END DO\n END DO\nc 'zonal average' udp\n UDP = UDP/MLON\nc point contribution to aam\n AAM = AAM + UDP*COS(LAT(NL)*RAD)*WGT(NL)*TWOPI\n END DO\n\n AAM = (RE3/G)*AAM\n\n RETURN\n END\nc -----------------------------------------------------------\nc if a scalar \"wgt\" is passed from NCL to the angmom_atm\nc . function, it means that the interface will calculate\nc . the weights. This assumes constant latitudinal spacing.\nc . cos(theta)*dlambda\nc -----------------------------------------------------------\n SUBROUTINE DCOSWEIGHT(LAT,NLAT,WGT)\n IMPLICIT NONE\nc INPUT\n INTEGER NLAT\n DOUBLE PRECISION LAT(NLAT)\nc OUTPUT\n DOUBLE PRECISION WGT(NLAT)\nc LOCAL\n DOUBLE PRECISION RAD,DLATR\n INTEGER NL\n\n RAD = 4.0D0*ATAN(1.0D0)/180.D0\nc latitudinal spacing (radians)\n DLATR = ABS(LAT(2)-LAT(1))*RAD\nc assume constant lat spacing\nc want exact zero at poles\n DO NL = 1,NLAT\n IF (ABS(LAT(NL)).EQ.90.D0) THEN\n WGT(NL) = 0.0D0\n ELSE\n WGT(NL) = COS(LAT(NL)*RAD)*DLATR\n END IF\n END DO\n\n RETURN\n END\n", "meta": {"hexsha": "7c2584490dda5f5f1ab46e591b075222793a3e53", "size": 4838, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/aam.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ni/src/lib/nfpfort/aam.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/aam.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 31.4155844156, "max_line_length": 69, "alphanum_fraction": 0.4454319967, "num_tokens": 1371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.7649670753874753}} {"text": "subroutine SHExpandDHC(grid, n, cilm, lmax, norm, sampling, csphase, lmax_calc)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis routine will expand a grid containing N samples in both longitude \n!\tand latitude (or N x 2N, see below) into spherical harmonics. This routine \n!\tmakes use of the sampling theorem presented in Driscoll and Healy (1994) \n!\tand employs FFTs when calculating the exponential terms. The number of \n!\tsamples, N, must be EVEN for this routine to work, and the spherical \n!\tharmonic expansion is exact if the function is bandlimited to degree N/2-1.\n!\tLegendre functions are computed on the fly using the scaling methodolgy \n!\tpresented in Holmes and Featherston (2002). When NORM is 1,2 or 4, these are \n!\taccurate to about degree 2800. When NORM is 3, the routine is only stable \n!\tto about degree 15. If the optional parameter LMAX_CALC is specified, the \n!\tspherical harmonic coefficients will only be calculated up to this degree. \n!\t\n!\tIf SAMPLING is 1 (default), the input grid contains N samples in latitude from \n!\t90 to -90+interval, and N samples in longitude from 0 to 360-2*interval, where \n!\tinterval is the latitudinal sampling interval 180/N. Note that the datum at \n!\t90 degees North latitude is ultimately downweighted to zero, so this point \n!\tdoes not contribute to the spherical harmonic coefficients. If SAMPLING is 2,\n!\tthe input grid must contain N samples in latitude and 2N samples in longitude.\n!\tIn this case, the sampling intervals in latitude and longitude are 180/N and \n!\t360/N respectively. When performing the FFTs in longitude, the frequencies greater\n!\tthan N/2-1 are simply discarded to prevent aliasing.\n!\n!\tThe complex spherical harmonics are output in the array cilm. Cilm(1,,) contains the\n!\tpositive m term, wheras cilm(2,,) contains the negative m term. The negative order \n!\tLegendre functions are calculated making use of the identity Y_{lm}^* = (-1)^m Y_{l,-m}.\n!\n!\tCalling Parameters:\n!\t\tIN\n!\t\t\tgrid\t\tEqually sampled grid in latitude and longitude of dimension\n!\t\t\t\t\t(1:N, 1:N) or and equally spaced grid of dimension (1:N,2N).\n!\t\t\tN\t\tNumber of samples in latitude and longitude (for SAMPLING=1),\n!\t\t\t\t\tor the number of samples in latitude (for SAMPLING=2).\n!\t\tOUT\n!\t\t\tcilm\t\tArray of spherical harmonic coefficients with dimension\n!\t\t\t\t\t(2, LMAX+1, LMAX+1), or, if LMAX_CALC is present \n!\t\t\t\t\t(2, LMAX_CALC+1, LMAX_CALC+1).\n!\t\t\tlmax\t\tSpherical harmonic bandwidth of the grid. This corresponds\n!\t\t\t\t\tto the maximum spherical harmonic degree of the expansion\n!\t\t\t\t\tif the optional parameter LMAX_CALC is not specified.\n!\t\tOPTIONAL (IN)\n!\t\t\tnorm\t\tNormalization to be used when calculating Legendre functions\n!\t\t\t\t\t\t(1) \"geodesy\" (default)\n!\t\t\t\t\t\t(2) Schmidt\n!\t\t\t\t\t\t(3) unnormalized\n!\t\t\t\t\t\t(4) orthonormalized\n!\t\t\tsampling\t(1) Grid is N latitudes by N longitudes (default).\n!\t\t\t\t\t(2) Grid is N by 2N. The higher frequencies resulting\n!\t\t\t\t\tfrom this oversampling are discarded, and hence not\n!\t\t\t\t\taliased into lower frequencies.\n!\t\t\tcsphase\t\t1: Do not include the Condon-Shortley phase factor of (-1)^m.\n!\t\t\t\t\t-1: Apply the Condon-Shortley phase factor of (-1)^m.\n!\t\t\tlmax_calc\tThe maximum spherical harmonic degree calculated in the \n!\t\t\t\t\tspherical harmonic expansion.\n!\n!\tNotes:\n!\t\t1.\tThis routine does not use the fast legendre transforms that\n!\t\t \tare presented in Driscoll and Heally (1994).\n!\t\t2. \tUse of a N by 2N grid is implemented because many geographic grids are \n!\t\t\tsampled this way. When taking the Fourier transforms in longitude, all of the \n!\t\t\thigher frequencies are ultimately discarded. If, instead, every other column of the \n!\t\t\tgrid were discarded to form a NxN grid, higher frequencies could be aliased \n!\t\t\tinto lower frequencies.\n!\n!\tDependencies:\t\tDHaj, FFTW3, CSPHASE_DEFAULT\n!\t\n!\n!\tWritten by Mark Wieczorek (May 2008).\n!\n!\tAugust 18, 2009.\tFixed memory issue that could have given rise to errors when\n!\t\t\t\tcalled with LMAX_CALC = 0.\n!\tNovember 21, 2011\tFixed problem where saved variables used in Plm recursion were not recalculated\n!\t\t\t\tif NORM changed from one call to the next (with the same value of N).\n!\t\n!\n!\tCopyright (c) 2008-2011, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\tuse FFTW3\n\tuse SHTOOLS, only: DHaj, CSPHASE_DEFAULT\n\t\t\n\timplicit none\n\t\n\tcomplex*16, intent(in) ::\tgrid(:,:)\n\tcomplex*16, intent(out) ::\tcilm(:,:,:)\n\tinteger, intent(in) ::\tn\n\tinteger, intent(out) ::\tlmax\n\tinteger, intent(in), optional :: norm, sampling, csphase, lmax_calc\n\tcomplex*16 ::\t\tcc(2*n), gridl(2*n), fcoef1(2*n), fcoef2(2*n)\n\tinteger ::\t\tl, m, k, kstart, i, l1, m1, i_eq, i_s, phase, lnorm, astat(5), &\n\t\t\t\tlmax_comp, nlong\n\tinteger*8 ::\t\tplan\n\treal*8 ::\t\tpi, aj(n), theta, prod, scalef, rescalem, u, p, pmm, pm1, pm2, z\n\treal*8, save, allocatable ::\tf1(:), f2(:), sqr(:), symsign(:)\n\tinteger, save ::\tlmax_old=0, norm_old = 0\n\t\n\tlmax = n/2 - 1\t\n\t\n\tif (present(lmax_calc)) then\n\t\tlmax_comp = min(lmax, lmax_calc)\n\telse\n\t\tlmax_comp = lmax\n\tendif\n\t\n\tif (present(lmax_calc)) then\n\t\tif (lmax_calc > lmax) then\n\t\t\tprint*, \"Error --- SHExpandDHC\"\n\t\t\tprint*, \"LMAX_CALC must be less than or equal to the effective bandwidth of GRID.\"\n\t\t\tprint*, \"Effective bandwidth of GRID = N/2 - 1 = \", lmax\n\t\t\tprint*, \"LMAX_CALC = \", lmax_calc\n\t\t\tstop\n\t\tendif\n\tendif\n\t\t\t\n\tif (present(sampling)) then\n\t\tif (sampling /= 1 .and. sampling /=2) then\n\t\t\tprint*, \"Error --- SHExpandDHC\"\n\t\t\tprint*, \"Optional parameter SAMPLING must be 1 (N by N) or 2 (N by 2N).\"\n\t\t\tprint*, \"Input value is \", sampling\n\t\t\tstop\n\t\tendif\n\tendif\n\t\n\tif (mod(n,2) /=0) then\n\t\tprint*, \"Error --- SHExpandDHC\"\n\t\tprint*, \"The number of samples in latitude and longitude, n, must be even.\"\n\t\tprint*, \"Input value is \", n\n\t\tstop\n\telseif (size(cilm(:,1,1)) < 2 .or. size(cilm(1,:,1)) < lmax_comp+1 .or. &\n\t\t\tsize(cilm(1,1,:)) < lmax_comp+1) then\n\t\tprint*, \"Error --- SHExpandDHC\"\n\t\tprint*, \"CILM must be dimensioned as (2, LMAX_COMP+1, LMAX_COMP+1) where\"\n\t\tprint*, \"LMAX_COMP = MIN(N/2, LMAX_CALC+1)\"\n\t\tprint*, \"N = \", n\n\t\tif (present(lmax_calc)) print*, \"LMAX_CALC = \", lmax_calc\n\t\tprint*, \"Input dimension is \", size(cilm(:,1,1)), size(cilm(1,:,1)), size(cilm(1,1,:))\n\t\tstop\n\tendif\n\t\n\tif (present(sampling)) then\n\t\tif (sampling == 1) then\n\t\t\tif (size(grid(:,1)) < n .or. size(grid(1,:)) < n) then\n\t\t\t\tprint*, \"Error --- SHExpandDHC\"\n\t\t\t\tprint*, \"GRIDDH must be dimensioned as (N, N) where N is \", n\n\t\t\t\tprint*, \"Input dimension is \", size(grid(:,1)), size(grid(1,:))\n\t\t\t\tstop\n\t\t\tendif\n\t\telseif (sampling ==2) then\n\t\t\tif (size(grid(:,1)) < n .or. size(grid(1,:)) < 2*n) then\n\t\t\t\tprint*, \"Error --- SHExpandDHC\"\n\t\t\t\tprint*, \"GRIDDH must be dimensioned as (N, 2*N) where N is \", n\n\t\t\t\tprint*, \"Input dimension is \", size(grid(:,1)), size(grid(1,:))\n\t\t\t\tstop\n\t\t\tendif\n\t\tendif\n\telse\n\t\t\n\t\tif (size(grid(:,1)) < n .or. size(grid(1,:)) < n) then\n\t\t\tprint*, \"Error --- SHExpandDHC\"\n\t\t\tprint*, \"GRIDDH must be dimensioned as (N, N) where N is \", n\n\t\t\tprint*, \"Input dimension is \", size(grid(:,1)), size(grid(1,:))\n\t\t\tstop\n\t\tendif\n\n\tendif\n\t\t\t\n\t\t\n\tif (present(csphase)) then\n \t\tif (csphase /= -1 .and. csphase /= 1) then\n \t\t\tprint*, \"SHExpandDHC --- Error\"\n \t\t\tprint*, \"CSPHASE must be 1 (exclude) or -1 (include).\"\n \t\t\tprint*, \"Input value is \", csphase\n \t\t\tstop\n \t\telse\n \t\t\tphase = csphase\n \t\tendif\n \telse\n \t\tphase = CSPHASE_DEFAULT\n \tendif\n \t\n \t\n \tif (present(norm)) then\n\t\tif (norm > 4 .or. norm < 1) then\n\t\t\tprint*, \"Error --- SHExpandDHC\"\n\t\t\tprint*, \"Parameter NORM must be 1 (geodesy), 2 (Schmidt), 3 (unnormalized), or 4 (orthonormalized).\"\n\t\t\tprint*, \"Input value is \", norm\n\t\t\tstop\n\t\tendif\n\t\t\n\t\tlnorm = norm\n\t\t\n\telse\n\t\tlnorm = 1\n\tendif\n\t\n\n\tpi = acos(-1.0d0)\n\t\n\tcilm = (0.0d0, 0.0d0)\n\t\n\tscalef = 1.0d-280\n\t\n\tcall DHaj(n, aj)\n\taj(1:n) = aj(1:n)*sqrt(4.0d0*pi) \t! Driscoll and Heally use unity normalized spherical harmonics\n\t\n\tif (present(sampling)) then\n\t\tif (sampling == 1) then\n\t\t\tnlong = n\n\t\telse\n\t\t\tnlong = 2*n\n\t\tendif\n\telse\n\t\tnlong = n\n\tendif\n\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t!\tCalculate recursion constants used in computing the Legendre polynomials\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\tif (lmax_comp /= lmax_old .or. lnorm /= norm_old) then\n\n\t\tif (allocated(sqr)) deallocate(sqr)\n\t\tif (allocated(f1)) deallocate(f1)\n\t\tif (allocated(f2)) deallocate(f2)\n\t\tif (allocated(symsign)) deallocate(symsign)\n\t\t\n\t\tallocate(sqr(2*lmax_comp+1), stat=astat(1))\n\t\tallocate(f1((lmax_comp+1)*(lmax_comp+2)/2), stat=astat(2))\n\t\tallocate(f2((lmax_comp+1)*(lmax_comp+2)/2), stat=astat(3))\n\t\tallocate(symsign((lmax_comp+1)*(lmax_comp+2)/2), stat=astat(4))\n\t\t\n\t\tif (astat(1) /= 0 .or. astat(2) /= 0 .or. astat(3) /= 0 .or. astat(4) /= 0) then\n\t\t\tprint*, \"Error --- SHExpandDHC\"\n\t\t\tprint*, \"Problem allocating arrays SQR, F1, F2, or SYMSIGN\", astat(1), astat(2), astat(3), astat(4)\n\t\t\tstop\n\t\tendif\n\t\t\n\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\t!\n\t\t! \tCalculate signs used for symmetry of Legendre functions about equator\n\t\t!\n\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\t\n\t\tk = 0\n\t\tdo l = 0, lmax_comp, 1\n\t\t\tdo m = 0, l, 1\n\t\t\t\tk = k + 1\n\t\t\t\tif (mod(l-m,2) == 0) then\n\t\t\t\t\tsymsign(k) = 1.0d0\n\t\t\t\telse\n\t\t\t\t\tsymsign(k) = -1.0d0\n\t\t\t\tendif\n\t\t\tenddo\n\t\tenddo\n\t\t\n\t\t\t\n\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\t!\n\t\t!\tPrecompute square roots of integers that are used several times.\n\t\t!\n\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\t\tdo l=1, 2*lmax_comp+1\n\t\t\tsqr(l) = sqrt(dble(l))\n\t\tenddo\n\n\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\t!\n\t\t! \tPrecompute multiplicative factors used in recursion relationships\n\t\t! \t\tP(l,m) = x*f1(l,m)*P(l-1,m) - P(l-2,m)*f2(l,m)\n\t\t!\t\tk = l*(l+1)/2 + m + 1\n\t\t!\tNote that prefactors are not used for the case when m=l as a different \n\t\t!\trecursion is used. Furthermore, for m=l-1, Plmbar(l-2,m) is assumed to be zero.\n\t\t!\n\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\t\tk = 1\n\t\t\n\t\tselect case(lnorm)\n\t\t\n\t\t\tcase(1,4)\n\t\n\t\t\t\tif (lmax_comp /= 0) then \n\t\t\t\t\tk = k + 1\n\t\t\t\t\tf1(k) = sqr(3)\n\t\t\t\t\tf2(k) = 0.0d0\n\t\t\t\t\tk = k + 1\n\t\t\t\tendif \n\t\t\t\t\n\t\t\t\tdo l=2, lmax_comp, 1\n\t\t\t\t\tk = k + 1\n\t\t\t\t\tf1(k) = sqr(2*l-1) * sqr(2*l+1) / dble(l)\n\t\t\t\t\tf2(k) = dble(l-1) * sqr(2*l+1) / sqr(2*l-3) / dble(l)\n\t\t\t\t\tdo m=1, l-2, 1\n\t\t\t\t\t\tk = k+1\n\t\t\t\t\t\tf1(k) = sqr(2*l+1) * sqr(2*l-1) / sqr(l+m) / sqr(l-m)\n \t\t\t\tf2(k) = sqr(2*l+1) * sqr(l-m-1) * sqr(l+m-1) &\n \t\t\t\t \t/ sqr(2*l-3) / sqr(l+m) / sqr(l-m) \n\t\t\t\t\tenddo\n\t\t\t\t\tk = k+1\n\t\t\t\t\tf1(k) = sqr(2*l+1) * sqr(2*l-1) / sqr(l+m) / sqr(l-m)\n \t\t\tf2(k) = 0.0d0\n\t\t\t\t\tk = k + 1\n\t\t\t\tenddo\n\t\t\t\n\t\t\tcase(2)\n\t\t\t\n\t\t\t\tif (lmax_comp /= 0) then\n\t\t\t\t\tk = k + 1\n\t\t\t\t\tf1(k) = 1.0d0\n\t\t\t\t\tf2(k) = 0.0d0\n\t\t\t\t\tk = k + 1\n\t\t\t\tendif\n\t\t\t\t\n\t\t\t\tdo l=2, lmax_comp, 1\n\t\t\t\t\tk = k + 1\n\t\t\t\t\tf1(k) = dble(2*l-1) /dble(l)\n\t\t\t\t\tf2(k) = dble(l-1) /dble(l)\n\t\t\t\t\tdo m=1, l-2, 1\n\t\t\t\t\t\tk = k+1\n\t\t\t\t\t\tf1(k) = dble(2*l-1) / sqr(l+m) / sqr(l-m)\n \t\t\t\tf2(k) = sqr(l-m-1) * sqr(l+m-1) / sqr(l+m) / sqr(l-m)\n\t\t\t\t\tenddo\n\t\t\t\t\tk = k+1\n\t\t\t\t\tf1(k) = dble(2*l-1) / sqr(l+m) / sqr(l-m)\n \t\t\tf2(k) = 0.0d0\n\t\t\t\t\tk = k + 1\n\t\t\t\tenddo\n\t\t\t\n\t\t\tcase(3)\n\t\t\n\t\t\t\tdo l=1, lmax_comp, 1\n\t\t\t\t\tk = k + 1\n\t\t\t\t\tf1(k) = dble(2*l-1) /dble(l)\n\t\t\t\t\tf2(k) = dble(l-1) /dble(l)\n\t\t\t\t\tdo m=1, l-1, 1\n\t\t\t\t\t\tk = k+1\n\t\t\t\t\t\tf1(k) = dble(2*l-1) / dble(l-m)\n \t\t\t\tf2(k) = dble(l+m-1) / dble(l-m)\n\t\t\t\t\tenddo\n\t\t\t\t\tk = k + 1\n\t\t\t\tenddo\n\n\t\tend select\n\t\n\t\tlmax_old = lmax_comp\n\t\tnorm_old = lnorm\n\t\n\tendif\t\n\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t! \tCreate generic plan for gridl\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\tcall dfftw_plan_dft_1d_(plan, nlong, gridl(1:nlong), cc(1:nlong), FFTW_FORWARD, FFTW_MEASURE)\n\n\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\t\t\n\t! \tIntegrate over all latitudes. Take into account symmetry of the \n\t!\tPlms about the equator.\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\ti_eq = n/2 + 1\t! Index correspondong to the equator\n\t\n\tdo i=2, i_eq - 1, 1\n\t\n\t\ttheta = pi * dble(i-1)/dble(n)\n\t\tz = cos(theta)\n\t\tu = sqrt( (1.0d0-z) * (1.0d0+z) )\n\t\t\n\t\tgridl(1:nlong) = grid(i,1:nlong)\n\t\tcall dfftw_execute_(plan)\t! take fourier transform\n\t\tfcoef1(1:nlong) = cc(1:nlong) * sqrt(2.0d0*pi) * aj(i) / dble(nlong) \t! positive frequencies up to n/2, \n\t\t\t\t\t\t\t\t\t\t\t! negative frequencies beyond in oposite order\n\t\t\n\t\ti_s = 2*i_eq -i\n\t\t\n\t\tgridl(1:nlong) = grid(i_s,1:nlong)\n\t\tcall dfftw_execute_(plan)\t! take fourier transform\n\t\tfcoef2(1:nlong) = cc(1:nlong) * sqrt(2.0d0*pi) * aj(i_s) / dble(nlong)\n\t\t\n\t\tselect case(lnorm)\n\t\t\tcase(1,2,3);\tpm2 = 1.0d0\n\t\t\tcase(4);\tpm2 = 1.0d0 / sqrt(4.0d0*pi)\n\t\tend select\n\n\t\tcilm(1,1,1) = cilm(1,1,1) + pm2 * (fcoef1(1) + fcoef2(1) )\n\t\t! symsign(1) = 1\n\t\t\n\t\tif (lmax_comp == 0) cycle\n\t\t\t\t\n\t\tk = 2\n\t\tpm1 = f1(k) * z * pm2\n\t\tcilm(1,2,1) = cilm(1,2,1) + pm1 * ( fcoef1(1) - fcoef2(1) )\n\t\t! symsign(2) = -1\n\t\t\t\t\n\t\tdo l=2, lmax_comp, 1\n\t\t\tl1 = l+1\n\t\t\tk = k+l\n\t\t\tp = f1(k) * z * pm1 - f2(k) * pm2\n\t\t\tpm2 = pm1\n\t\t\tpm1 = p\n\t\t\tcilm(1,l1,1) = cilm(1,l1,1) + p * ( fcoef1(1) + fcoef2(1) * symsign(k) )\n\t\tenddo\n\t\t\t\t\n\t\tselect case(lnorm)\n\t\t\tcase(1,2,3);\tpmm = scalef\n\t\t\tcase(4);\tpmm = scalef / sqrt(4.0d0*pi)\n\t\tend select\n\t\t\t\t\n\t\trescalem = 1.0d0/scalef\n\t\tkstart = 1\n\t\n\t\tdo m = 1, lmax_comp-1, 1\n\t\t\t\t\n\t\t\tm1 = m+1\n\t\t\trescalem = rescalem * u\n\t\t\tkstart = kstart+m+1\n\t\t\t\t\t\n\t\t\tselect case(lnorm)\n\t\t\t\tcase(1,4)\n\t\t\t\t\tpmm = phase * pmm * sqr(2*m+1) / sqr(2*m)\n\t\t\t\t\tpm2 = pmm\n\t\t\t\tcase(2)\n\t\t\t\t\tpmm = phase * pmm * sqr(2*m+1) / sqr(2*m)\n\t\t\t\t\tpm2 = pmm / sqr(2*m+1)\n\t\t\t\tcase(3)\n\t\t\t\t\tpmm = phase * pmm * dble(2*m-1)\n\t\t\t\t\tpm2 = pmm\n\t\t\tend select\n\t\t\t\t\t\n\t\t\tfcoef1(m1) = fcoef1(m1) * rescalem\n\t\t\tfcoef1(nlong-(m-1)) = fcoef1(nlong-(m-1)) * rescalem * dble((-1)**mod(m,2)) ! multiply by (-1)^m for P_{l,-m}\n\t\t\tfcoef2(m1) = fcoef2(m1) * rescalem\n\t\t\tfcoef2(nlong-(m-1)) = fcoef2(nlong-(m-1)) * rescalem * dble((-1)**mod(m,2))\n\t\t\t\t\t\n\t\t\tcilm(1,m1,m1) = cilm(1,m1,m1) + pm2 * ( fcoef1(m1) + fcoef2(m1) )\n\t\t\tcilm(2,m1,m1) = cilm(2,m1,m1) + pm2 * ( fcoef1(nlong-(m-1)) + fcoef2(nlong-(m-1)) ) \n\t\t\t! symsign(kstart) = 1\n\t\t\t\t\t\n\t\t\tk = kstart+m+1\n\t \t\tpm1 = z * f1(k) * pm2\n\t \t\t\t\n\t \t\tcilm(1,m1+1,m1) = cilm(1,m1+1,m1) + pm1 * ( fcoef1(m1) - fcoef2(m1) )\n \t\tcilm(2,m1+1,m1) = cilm(2,m1+1,m1) + pm1 * ( fcoef1(nlong-(m-1)) - fcoef2(nlong-(m-1)) ) \n \t\t! symsign(k) = -1\n\t\t\t\t\t\n\t\t\tdo l = m+2, lmax_comp, 1\n\t\t\t\tl1 = l+1\n\t\t\t\tk = k+l\n \t\tp = z * f1(k) * pm1-f2(k) * pm2\n \t\tpm2 = pm1\n \t\tpm1 = p\n\t\t\t\tcilm(1,l1,m1) = cilm(1,l1,m1) + p * ( fcoef1(m1) + fcoef2(m1) * symsign(k) )\n\t\t\t\tcilm(2,l1,m1) = cilm(2,l1,m1) + p * &\n\t\t\t\t\t\t( fcoef1(nlong-(m-1)) + fcoef2(nlong-(m-1)) * symsign(k) )\n\t\t\tenddo\n \t\t\t\t\n\t\tenddo\n\t\t\t\t\n\t\trescalem = rescalem * u\n\t\t\t\n \tselect case(lnorm)\n \t\tcase(1,4);\tpmm = phase * pmm * sqr(2*lmax_comp+1) / sqr(2*lmax_comp) * rescalem\n \t\tcase(2);\tpmm = phase * pmm / sqr(2*lmax_comp) * rescalem\n \t\tcase(3);\tpmm = phase * pmm * dble(2*lmax_comp-1) * rescalem\n \tend select\n \t\t\t\n \tcilm(1,lmax_comp+1,lmax_comp+1) = cilm(1,lmax_comp+1,lmax_comp+1) + pmm * &\n \t\t\t( fcoef1(lmax_comp+1) + fcoef2(lmax_comp+1) )\n \tcilm(2,lmax_comp+1,lmax_comp+1) = cilm(2,lmax_comp+1,lmax_comp+1) + pmm * &\n \t\t\t( fcoef1(nlong-(lmax_comp-1)) + fcoef2(nlong-(lmax_comp-1)) )\t\n \t\t\t! symsign = 1\n \n\tenddo\n\t\n\t! Finally, do equator\n\t\n\ti = i_eq\n\t\n\tz = 0.0d0\n\tu = 1.0d0\n\t\n\tgridl(1:nlong) = grid(i,1:nlong)\n\tcall dfftw_execute_(plan)\t! take fourier transform\n\tfcoef1(1:nlong) = cc(1:nlong) * sqrt(2.0d0*pi) * aj(i) / dble(nlong)\n\n\tselect case(lnorm)\n\t\tcase(1,2,3);\tpm2 = 1.0d0\n\t\tcase(4);\tpm2 = 1.0d0 / sqrt(4.0d0*pi)\n\tend select\n\n\tcilm(1,1,1) = cilm(1,1,1) + pm2 * fcoef1(1)\n\t\n\tif (lmax_comp /= 0) then\n\t\t\n\t\tk = 2\n\t\t\t\t\n\t\tdo l=2, lmax_comp, 2\n\t\t\tl1 = l+1\n\t\t\tk = k+l\n\t\t\tp = - f2(k) * pm2\n\t\t\tpm2 = p\n\t\t\tcilm(1,l1,1) = cilm(1,l1,1) + p * fcoef1(1)\n\t\t\tk = k + l + 1\n\t\tenddo\n\t\t\t\t\n\t\tselect case(lnorm)\n\t\t\tcase(1,2,3);\tpmm = scalef\n\t\t\tcase(4);\tpmm = scalef / sqrt(4.0d0*pi)\n\t\tend select\n\t\t\t\t\n\t\trescalem = 1.0d0/scalef\n\t\tkstart = 1\n\t\n\t\tdo m = 1, lmax_comp-1, 1\n\t\t\t\t\n\t\t\tm1 = m+1\n\t\t\tkstart = kstart+m+1\n\t\t\t\t\t\n\t\t\tselect case(lnorm)\n\t\t\t\tcase(1,4)\n\t\t\t\t\tpmm = phase * pmm * sqr(2*m+1) / sqr(2*m)\n\t\t\t\t\tpm2 = pmm\n\t\t\t\tcase(2)\n\t\t\t\t\tpmm = phase * pmm * sqr(2*m+1) / sqr(2*m)\n\t\t\t\t\tpm2 = pmm / sqr(2*m+1)\n\t\t\t\tcase(3)\n\t\t\t\t\tpmm = phase * pmm * dble(2*m-1)\n\t\t\t\t\tpm2 = pmm\n\t\t\tend select\n\t\t\n\t\t\tfcoef1(m1) = fcoef1(m1) * rescalem\n\t\t\tfcoef1(nlong-(m-1)) = fcoef1(nlong-(m-1)) * rescalem * dble((-1)**mod(m,2))\n\t\t\t\t\t\n\t\t\tcilm(1,m1,m1) = cilm(1,m1,m1) + pm2 * fcoef1(m1)\n\t\t\tcilm(2,m1,m1) = cilm(2,m1,m1) + pm2 * fcoef1(nlong-(m-1))\n\t\t\t\n\t\t\tk = kstart+m+1\n\t \t\t\t\t\t\t\n\t\t\tdo l = m+2, lmax_comp, 2\n\t\t\t\tl1 = l+1\n\t\t\t\tk = k+l\n \t\tp = - f2(k) * pm2\n \t\tpm2 = p\n\t\t\t\tcilm(1,l1,m1) = cilm(1,l1,m1) + p * fcoef1(m1)\n\t\t\t\tcilm(2,l1,m1) = cilm(2,l1,m1) + p * fcoef1(nlong-(m-1))\n\t\t\t\tk = k + l + 1\n\t\t\tenddo\n\n\t\tenddo\n \t\t\t\n \tselect case(lnorm)\n \t\tcase(1,4);\tpmm = phase * pmm * sqr(2*lmax_comp+1) / sqr(2*lmax_comp) * rescalem\n \t\tcase(2);\tpmm = phase * pmm / sqr(2*lmax_comp) * rescalem\n \t\tcase(3);\tpmm = phase * pmm * dble(2*lmax_comp-1) * rescalem\n \tend select\n \t\t\t\n \tcilm(1,lmax_comp+1,lmax_comp+1) = cilm(1,lmax_comp+1,lmax_comp+1) + pmm * fcoef1(lmax_comp+1)\n \tcilm(2,lmax_comp+1,lmax_comp+1) = cilm(2,lmax_comp+1,lmax_comp+1) + dble((-1)**mod(lmax_comp,2)) * &\n \t\tpmm * fcoef1(nlong-(lmax_comp-1)) \n \t\t\n endif\n\n\tcall dfftw_destroy_plan_(plan) \n\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t! \tDivide by integral of Ylm*Ylm \n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\tselect case(lnorm)\n\t\n\t\tcase(1)\n\t\n\t\t\tdo l=0, lmax_comp, 1\n\t\t\t\tcilm(1:2,l+1, 1:l+1) = cilm(1:2,l+1, 1:l+1) / (4.0d0*pi)\n\t\t\tenddo\n\t\t\n\t\tcase(2)\n\t\n\t\t\tdo l=0, lmax_comp, 1\n\t\t\t\tcilm(1:2,l+1, 1:l+1) = cilm(1:2,l+1, 1:l+1) * dble(2*l+1) / (4.0d0*pi)\n\t\t\tenddo\n\t\n\t\tcase(3)\n\t\t \n\t\t\tdo l=0, lmax_comp, 1\n\t\t\t\tprod = 4.0d0*pi/dble(2*l+1)\n\t\t\t\tcilm(1,l+1,1) = cilm(1,l+1,1) / prod\n\t\t\t\tdo m=1, l-1, 1\n\t\t\t\t\tprod = prod * dble(l+m) * dble(l-m+1)\n\t\t\t\t\tcilm(1:2,l+1,m+1) = cilm(1:2,l+1,m+1) / prod\n\t\t\t\tenddo\n\t\t\t\t!do m=l case\n\t\t\t\tif (l /= 0) cilm(1:2,l+1,l+1) = cilm(1:2,l+1, l+1)/(prod*dble(2*l))\n\t\t\tenddo\n\t\t\t\n\tend select\n\t\t\nend subroutine SHExpandDHC\n\n", "meta": {"hexsha": "95b763fd36763dff36a202b0fb64a18aa7ecb0a5", "size": 18965, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/SHExpandDHC2.f95", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "spherical_splines/SHTOOLS/src/SHExpandDHC2.f95", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "spherical_splines/SHTOOLS/src/SHExpandDHC2.f95", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 30.9380097879, "max_line_length": 112, "alphanum_fraction": 0.5418929607, "num_tokens": 7068, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966732132748, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7649137426447753}} {"text": "program fibonacci_recursive\n integer, parameter :: n_min = 0, n_max = 20\n integer :: n\n\n do n = n_min, n_max\n print *, n, fibonacci(n)\n end do\n\ncontains\n\n recursive function fibonacci(n) result(fib)\n implicit none\n integer, intent(in) :: n\n integer :: fib\n if (n == 0 .or. n == 1) then\n fib = 1\n else\n fib = fibonacci(n - 1) + fibonacci(n - 2)\n end if\n end function fibonacci\nend program fibonacci_recursive\n", "meta": {"hexsha": "a33533d91f4dfa1e82b645b19d8fceea9b48f4f5", "size": 497, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "hands-on/session_02/exercise_04a.f90", "max_stars_repo_name": "gjbex/FortranForProgrammers", "max_stars_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-15T14:56:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-15T14:56:20.000Z", "max_issues_repo_path": "hands-on/session_02/exercise_04a.f90", "max_issues_repo_name": "gjbex/FortranForProgrammers", "max_issues_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hands-on/session_02/exercise_04a.f90", "max_forks_repo_name": "gjbex/FortranForProgrammers", "max_forks_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.5909090909, "max_line_length": 53, "alphanum_fraction": 0.5593561368, "num_tokens": 134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.8267118004748678, "lm_q1q2_score": 0.7648985202719651}} {"text": "!-------------------------------------------------------------------\n! class-hpc-smoke-ring: A simple sample field solver.\n!\n! by Akira Kageyama, Kobe University, Japan.\n! email: sgks@mac.com\n!\n! Copyright 2018 Akira Kageyama\n!\n! This software is released under the MIT License.\n!\n!-------------------------------------------------------------------\n! src/constants.f90\n!-------------------------------------------------------------------\n\nmodule constants_m\n implicit none\n\n ! << f90 constants >>\n integer, parameter :: SI = selected_int_kind(8)\n integer, parameter :: DI = selected_int_kind(16)\n integer, parameter :: SR = selected_real_kind(6)\n integer, parameter :: DR = selected_real_kind(12)\n\n ! << Mathematical constants >>\n real(DR), parameter :: PI = 3.1415926535897932_DR\n real(DR), parameter :: TWOPI = PI*2\n\n ! << Grid Size >>\n integer(SI), parameter :: NX = 92\n integer(SI), parameter :: NY = 32\n integer(SI), parameter :: NZ = 32\n ! integer(SI), parameter :: NX = 152\n ! integer(SI), parameter :: NY = 52\n ! integer(SI), parameter :: NZ = 52\n\n ! << Box Size >>\n real(DR), parameter :: XMIN = -1.5_DR\n real(DR), parameter :: XMAX = +1.5_DR\n real(DR), parameter :: YMIN = -0.5_DR\n real(DR), parameter :: YMAX = +0.5_DR\n real(DR), parameter :: ZMIN = -0.5_DR\n real(DR), parameter :: ZMAX = +0.5_DR\nend module constants_m\n", "meta": {"hexsha": "568021ad6c7ca877a96b3a3b64388438d4f00c4e", "size": 1378, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "slice_grapher/constants.f90", "max_stars_repo_name": "TZWizard/smrs", "max_stars_repo_head_hexsha": "f99746accbcf97a1d3b075dbc02b08abafde96ea", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slice_grapher/constants.f90", "max_issues_repo_name": "TZWizard/smrs", "max_issues_repo_head_hexsha": "f99746accbcf97a1d3b075dbc02b08abafde96ea", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slice_grapher/constants.f90", "max_forks_repo_name": "TZWizard/smrs", "max_forks_repo_head_hexsha": "f99746accbcf97a1d3b075dbc02b08abafde96ea", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.3181818182, "max_line_length": 68, "alphanum_fraction": 0.5464441219, "num_tokens": 387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953030553434, "lm_q2_score": 0.8519528019683106, "lm_q1q2_score": 0.7647940287517915}} {"text": " MODULE MATH\n\n IMPLICIT NONE\n\n PRIVATE\n\n PUBLIC :: EXPINT\n PUBLIC :: DSQ, ISQ\n PUBLIC :: DCUBE, ICUBE\n\n CONTAINS\n\n RECURSIVE FUNCTION EXPINT(n, x) RESULT (Enx)\n\n! Calculates the exponential integral of order n\n\n! Using formulas 5.1.14, 5.1.53 and 5.1.56 from Handbook of Mathematical Functions,\n! Applied mathematics series 55 (1964) (ed. Abramovitz and Stegun)\n\n INTEGER, INTENT(IN) :: n\n\n REAL*8, INTENT(IN) :: x\n\n REAL*8 :: Enx\n\n IF (n .EQ. 0) THEN\n\n Enx = DEXP(-x) / x\n\n ELSEIF (n .EQ. 1) THEN\n\n Enx = E1(x) ! 5.1.53 and 5.1.56\n\n ELSE\n\n Enx = (DEXP(-x) - x * EXPINT(n - 1, x)) / (n - 1) ! 5.1.14\n\n ENDIF\n\n RETURN\n\n END FUNCTION EXPINT\n\n\n REAL*8 FUNCTION E1(x)\n\n! Calculates the exponential integral of order 1\n\n REAL*8, INTENT(IN) :: x\n\n REAL*8, DIMENSION(6) :: a\n\n REAL*8, DIMENSION(4) :: b, c\n\n DATA a /-0.57721566D0, 0.99999193D0, -0.24991055D0, 0.05519968D0, -0.00976004D0, 0.00107857D0/\n\n DATA b /8.5733287401D0, 18.0590169730D0, 8.6347608925D0, 0.2677737343D0/\n\n DATA c /9.5733223454D0, 25.6329561486D0, 21.0996530827D0, 3.9584969228D0/\n\n IF (x .GE. 0.0D0 .AND. x .LE. 1.0D0) THEN ! 5.1.53\n\n E1 = -DLOG(x) + a(1) + a(2) * x + a(3) * x**2.0D0 + \n $ a(4) * x**3.0D0 + a(5) * x**4.0D0 + a(6) * x**5.0D0\n\n ELSEIF (x .GE. 1.0D0) THEN ! 5.1.56\n\n E1 = x**4.0D0 + b(1) * x**3.0D0 + b(2) * x**2.0D0 + b(3) * x + b(4)\n\n E1 = E1 / (x**4.0D0 + c(1) * x**3.0D0 + c(2) * x**2.0D0 + c(3) * x + c(4))\n\n E1 = E1 / x / DEXP(x)\n\n ENDIF\n\n RETURN\n\n END FUNCTION E1\n\n\n REAL*8 FUNCTION DSQ(x)\n\n REAL*8, INTENT(IN) :: x\n\n DSQ = x * x\n\n RETURN\n\n END FUNCTION DSQ\n\n\n REAL*8 FUNCTION ISQ(m)\n\n INTEGER, INTENT(IN) :: m\n\n ISQ = DBLE(m * m)\n\n RETURN\n\n END FUNCTION ISQ\n\n\n REAL*8 FUNCTION DCUBE(x)\n\n REAL*8, INTENT(IN) :: x\n\n DCUBE = x * x * x\n\n RETURN\n\n END FUNCTION DCUBE\n\n\n REAL*8 FUNCTION ICUBE(m)\n\n INTEGER, INTENT(IN) :: m\n\n ICUBE = DBLE(m * m * m)\n\n RETURN\n\n END FUNCTION ICUBE\n\n END MODULE MATH\n", "meta": {"hexsha": "c26cbfda2d92f89fe908cf270211396512f75451", "size": 2228, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/math.for", "max_stars_repo_name": "rtagirov/nessy", "max_stars_repo_head_hexsha": "aa6c26243e6231f267b42763e020866da962fdfb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/math.for", "max_issues_repo_name": "rtagirov/nessy", "max_issues_repo_head_hexsha": "aa6c26243e6231f267b42763e020866da962fdfb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2016-11-21T10:53:14.000Z", "max_issues_repo_issues_event_max_datetime": "2017-03-17T18:31:42.000Z", "max_forks_repo_path": "src/math.for", "max_forks_repo_name": "rtagirov/nessy-src", "max_forks_repo_head_hexsha": "aa6c26243e6231f267b42763e020866da962fdfb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-15T03:13:57.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-15T03:13:57.000Z", "avg_line_length": 17.824, "max_line_length": 100, "alphanum_fraction": 0.5112208259, "num_tokens": 894, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661945, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7647891860272982}} {"text": "subroutine NPZDPhy_size(PMU, NO3, tC, par_, muNet, SI, Lno3, QN, theta)\nuse bio_MOD\nimplicit none\n\n!INPUT PARAMETERS:\nreal, intent(in) :: PMU, NO3, tC, par_\n\n!Output parameters:\nreal, intent(out) :: muNet, SI, Lno3\n\n!Local variable:\nreal :: Kn, mu0hat, aI, cff, cff1\nreal :: Qmax, fN, QN, theta\nreal, parameter :: alphaK = 0.27\nreal, parameter :: Qmin = 0.06\n\ntf_p = TEMPBOL(Ep,tC)\nmu0hat = dtdays*tf_p * params(imu0) * exp(alphamu*PMU + betamu * PMU**2)\n\nKn = params(iKN) * exp( alphaK * PMU)\n\n! Effect of light limitation\naI = params(iaI0) * exp(params(ialphaI)*PMU)\nSI = 1d0 - max(exp(-params(iaI0) * par_ ),0d0)\nLno3 = NO3/(NO3+Kn)\nmuNet = mu0hat * Lno3 * SI\n\nQmax = 3.*Qmin\ncff1 = 1d0-Qmin/Qmax\ncff = 1d0-cff1*fN\n!N:C ratio\nQN = Qmin/cff\n\n!Chl:C ratio \ncff = (thetamax - thetamin)/PAR_\ntheta = thetamin+muNet/aI*cff !Unit: gChl/molC\n\nreturn\nend subroutine NPZDPhy_size\n\n", "meta": {"hexsha": "4669152b6128148a7fd5fcdaedd49fea1a74288c", "size": 967, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "DRAM/src/NPZDPhy_size.f90", "max_stars_repo_name": "BingzhangChen/NPZDFeCONT", "max_stars_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "DRAM/src/NPZDPhy_size.f90", "max_issues_repo_name": "BingzhangChen/NPZDFeCONT", "max_issues_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DRAM/src/NPZDPhy_size.f90", "max_forks_repo_name": "BingzhangChen/NPZDFeCONT", "max_forks_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5853658537, "max_line_length": 73, "alphanum_fraction": 0.6142709411, "num_tokens": 390, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9736446448596305, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7646114992358976}} {"text": "! Copyright (C) 2012 The SPEED FOUNDATION\n! Author: Ilario Mazzieri\n!\n! This file is part of SPEED.\n!\n! SPEED is free software; you can redistribute it and/or modify it\n! under the terms of the GNU Affero General Public License as\n! published by the Free Software Foundation, either version 3 of the\n! License, or (at your option) any later version.\n!\n! SPEED is distributed in the hope that it will be useful, but\n! WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n! Affero General Public License for more details.\n!\n! You should have received a copy of the GNU Affero General Public License\n! along with SPEED. If not, see .\n\n!> @brief Computes area of a face (quad).\n!! @author Ilario Mazzieri\n!> @date September, 2013 \n!> @version 1.0\n!> @param[in] x1 vertex x-coordinate defining a face of the element ielem\n!> @param[in] x2 vertex x-coordinate defining a face of the element ielem\n!> @param[in] x3 vertex x-coordinate defining a face of the element ielem\n!> @param[in] x4 vertex x-coordinate defining a face of the element ielem\n!> @param[in] y1 vertex y-coordinate defining a face of the element ielem\n!> @param[in] y2 vertex y-coordinate defining a face of the element ielem\n!> @param[in] y3 vertex y-coordinate defining a face of the element ielem\n!> @param[in] y4 vertex y-coordinate defining a face of the element ielem\n!> @param[in] z1 vertex z-coordinate defining a face of the element ielem\n!> @param[in] z2 vertex z-coordinate defining a face of the element ielem\n!> @param[in] z3 vertex z-coordinate defining a face of the element ielem\n!> @param[in] z4 vertex z-coordinate defining a face of the element ielem\n!> @param[in] index of the element\n!> @param[out] surf area of a face of the hex ielem \n\n subroutine GET_AREA_FACE(x1,x2,x3,x4,y1,y2,y3,y4,z1,z2,z3,z4,surf,ielem)\n \n implicit none\n\n integer*4, intent(in) :: ielem\n\n real*8 :: a,b,c,vx,vy,vz,wx,wy,wz,xbar,ybar,zbar\n real*8, intent(in) :: x1,x2,x3,x4,y1,y2,y3,y4,z1,z2,z3,z4\n real*8, intent(out) :: surf\n \n surf = 0.d0\n \n xbar = (x1 + x2 + x3 + x4)/4.d0\n ybar = (y1 + y2 + y3 + y4)/4.d0\n zbar = (z1 + z2 + z3 + z4)/4.d0\n \n vx = x4 - x1\n vy = y4 - y1 \n vz = z4 - z1\n \n wx = xbar - x1\n wy = ybar - y1\n wz = zbar - z1 \n \n \n a = vy*wz - vz*wy\n b = -vx*wz + vz*wx\n c = vx*wy - vy*wx\n \n\n \n surf = surf + 0.5d0*dsqrt(a**2.d0 + b**2.d0 + c**2.d0) \n \n vx = x2 - x1\n vy = y2 - y1 \n vz = z2 - z1\n \n wx = xbar - x1\n wy = ybar - y1\n wz = zbar - z1 \n \n \n a = vy*wz - vz*wy\n b = -vx*wz + vz*wx\n c = vx*wy - vy*wx\n \n surf = surf + 0.5d0*dsqrt(a**2.d0 + b**2.d0 + c**2.d0) \n \n vx = x2 - x3\n vy = y2 - y3 \n vz = z2 - z3\n \n wx = xbar - x3\n wy = ybar - y3\n wz = zbar - z3 \n \n \n a = vy*wz - vz*wy\n b = -vx*wz + vz*wx\n c = vx*wy - vy*wx\n \n surf = surf + 0.5d0*dsqrt(a**2.d0 + b**2.d0 + c**2.d0) \n \n vx = x4 - x3\n vy = y4 - y3 \n vz = z4 - z3\n \n wx = xbar - x3\n wy = ybar - y3\n wz = zbar - z3 \n \n \n a = vy*wz - vz*wy\n b = -vx*wz + vz*wx\n c = vx*wy - vy*wx\n \n surf = surf + 0.5d0*dsqrt(a**2.d0 + b**2.d0 + c**2.d0) \n \n end subroutine GET_AREA_FACE\n", "meta": {"hexsha": "c5195a1da9772f877a514699d845e89c075ae862", "size": 3546, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SRC/SPEED-MDOF190510/GET_AREA_FACE.f90", "max_stars_repo_name": "research-group-of-Xinzheng-Lu/SCI-effects-simulation", "max_stars_repo_head_hexsha": "6f91a4afce51303ac33d9dce005247290679b428", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-05-11T17:26:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-31T12:41:29.000Z", "max_issues_repo_path": "SRC/SPEED-MDOF190510/GET_AREA_FACE.f90", "max_issues_repo_name": "research-group-of-Xinzheng-Lu/SCI-effects-simulation", "max_issues_repo_head_hexsha": "6f91a4afce51303ac33d9dce005247290679b428", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SRC/SPEED-MDOF190510/GET_AREA_FACE.f90", "max_forks_repo_name": "research-group-of-Xinzheng-Lu/SCI-effects-simulation", "max_forks_repo_head_hexsha": "6f91a4afce51303ac33d9dce005247290679b428", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-05-15T06:26:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-10T07:22:41.000Z", "avg_line_length": 30.3076923077, "max_line_length": 77, "alphanum_fraction": 0.5671178793, "num_tokens": 1203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475746920261, "lm_q2_score": 0.8104789086703224, "lm_q1q2_score": 0.7645633128331887}} {"text": "! =============================================================================\n! Permutation module implemented according to\n! the non-recursive Heap algorithm\n! (https://en.wikipedia.org/wiki/Heap%27s_algorithm)\n! =============================================================================\nmodule permute\n implicit none\n\n integer, allocatable :: permutes(:, :)\n integer :: n_permutes = 0\n\n contains\n\n subroutine permute_alloc(n)\n integer, intent(in) :: n\n integer :: i, p\n\n p = 1\n do i = 1, n\n p = p * i\n enddo\n\n allocate(permutes(p, n))\n\n n_permutes = p\n\n end subroutine permute_alloc\n\n subroutine permute_dealloc\n if (allocated(permutes)) then\n deallocate(permutes)\n endif\n end subroutine\n\n ! non-recursive Heap algorithm\n ! Implemented according to\n ! https://en.wikipedia.org/wiki/Heap%27s_algorithm\n ! (visited 10 August 2021)\n subroutine permute_generate(n)\n integer, intent(in) :: n\n integer :: array(0:n-1)\n integer :: tmp, i, k, c(n)\n\n call permute_alloc(n)\n\n do i = 0, n-1\n array(i) = i + 1\n enddo\n\n c = 0\n\n k = 1\n permutes(1, :) = array\n\n i = 1\n do while (i < n)\n if (c(i) < i) then\n if (mod(i, 2) == 0) then\n tmp = array(0)\n array(0) = array(i)\n array(i) = tmp\n else\n tmp = array(c(i))\n array(c(i)) = array(i)\n array(i) = tmp\n endif\n k = k + 1\n permutes(k, :) = array\n\n c(i) = c(i) + 1\n i = 1\n else\n c(i) = 0\n i = i + 1\n endif\n enddo\n end subroutine permute_generate\nend module permute\n", "meta": {"hexsha": "1e6ea3b1ba352100b2296642b1d085dae5abf372", "size": 2192, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unit-tests/permute.f90", "max_stars_repo_name": "matt-frey/epic", "max_stars_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-11-11T10:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:11:41.000Z", "max_issues_repo_path": "unit-tests/permute.f90", "max_issues_repo_name": "matt-frey/epic", "max_issues_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2021-11-12T17:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T16:50:58.000Z", "max_forks_repo_path": "unit-tests/permute.f90", "max_forks_repo_name": "matt-frey/epic", "max_forks_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.746835443, "max_line_length": 79, "alphanum_fraction": 0.3704379562, "num_tokens": 472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138366, "lm_q2_score": 0.8933094103149355, "lm_q1q2_score": 0.7645398768458019}} {"text": "*DECK RF\n REAL FUNCTION RF (X, Y, Z, IER)\nC***BEGIN PROLOGUE RF\nC***PURPOSE Compute the incomplete or complete elliptic integral of the\nC 1st kind. For X, Y, and Z non-negative and at most one of\nC them zero, RF(X,Y,Z) = Integral from zero to infinity of\nC -1/2 -1/2 -1/2\nC (1/2)(t+X) (t+Y) (t+Z) dt.\nC If X, Y or Z is zero, the integral is complete.\nC***LIBRARY SLATEC\nC***CATEGORY C14\nC***TYPE SINGLE PRECISION (RF-S, DRF-D)\nC***KEYWORDS COMPLETE ELLIPTIC INTEGRAL, DUPLICATION THEOREM,\nC INCOMPLETE ELLIPTIC INTEGRAL, INTEGRAL OF THE FIRST KIND,\nC TAYLOR SERIES\nC***AUTHOR Carlson, B. C.\nC Ames Laboratory-DOE\nC Iowa State University\nC Ames, IA 50011\nC Notis, E. M.\nC Ames Laboratory-DOE\nC Iowa State University\nC Ames, IA 50011\nC Pexton, R. L.\nC Lawrence Livermore National Laboratory\nC Livermore, CA 94550\nC***DESCRIPTION\nC\nC 1. RF\nC Evaluate an INCOMPLETE (or COMPLETE) ELLIPTIC INTEGRAL\nC of the first kind\nC Standard FORTRAN function routine\nC Single precision version\nC The routine calculates an approximation result to\nC RF(X,Y,Z) = Integral from zero to infinity of\nC\nC -1/2 -1/2 -1/2\nC (1/2)(t+X) (t+Y) (t+Z) dt,\nC\nC where X, Y, and Z are nonnegative and at most one of them\nC is zero. If one of them is zero, the integral is COMPLETE.\nC The duplication theorem is iterated until the variables are\nC nearly equal, and the function is then expanded in Taylor\nC series to fifth order.\nC\nC 2. Calling Sequence\nC RF( X, Y, Z, IER )\nC\nC Parameters on Entry\nC Values assigned by the calling routine\nC\nC X - Single precision, nonnegative variable\nC\nC Y - Single precision, nonnegative variable\nC\nC Z - Single precision, nonnegative variable\nC\nC\nC\nC On Return (values assigned by the RF routine)\nC\nC RF - Single precision approximation to the integral\nC\nC IER - Integer\nC\nC IER = 0 Normal and reliable termination of the\nC routine. It is assumed that the requested\nC accuracy has been achieved.\nC\nC IER > 0 Abnormal termination of the routine\nC\nC X, Y, Z are unaltered.\nC\nC\nC 3. Error Messages\nC\nC Value of IER assigned by the RF routine\nC\nC Value assigned Error Message Printed\nC IER = 1 MIN(X,Y,Z) .LT. 0.0E0\nC = 2 MIN(X+Y,X+Z,Y+Z) .LT. LOLIM\nC = 3 MAX(X,Y,Z) .GT. UPLIM\nC\nC\nC\nC 4. Control Parameters\nC\nC Values of LOLIM, UPLIM, and ERRTOL are set by the\nC routine.\nC\nC LOLIM and UPLIM determine the valid range of X, Y and Z\nC\nC LOLIM - Lower limit of valid arguments\nC\nC Not less than 5 * (machine minimum).\nC\nC UPLIM - Upper limit of valid arguments\nC\nC Not greater than (machine maximum) / 5.\nC\nC\nC Acceptable Values For: LOLIM UPLIM\nC IBM 360/370 SERIES : 3.0E-78 1.0E+75\nC CDC 6000/7000 SERIES : 1.0E-292 1.0E+321\nC UNIVAC 1100 SERIES : 1.0E-37 1.0E+37\nC CRAY : 2.3E-2466 1.09E+2465\nC VAX 11 SERIES : 1.5E-38 3.0E+37\nC\nC\nC\nC ERRTOL determines the accuracy of the answer\nC\nC The value assigned by the routine will result\nC in solution precision within 1-2 decimals of\nC \"machine precision\".\nC\nC\nC\nC ERRTOL - Relative error due to truncation is less than\nC ERRTOL ** 6 / (4 * (1-ERRTOL) .\nC\nC\nC\nC The accuracy of the computed approximation to the inte-\nC gral can be controlled by choosing the value of ERRTOL.\nC Truncation of a Taylor series after terms of fifth order\nC introduces an error less than the amount shown in the\nC second column of the following table for each value of\nC ERRTOL in the first column. In addition to the trunca-\nC tion error there will be round-off error, but in prac-\nC tice the total error from both sources is usually less\nC than the amount given in the table.\nC\nC\nC\nC\nC\nC Sample Choices: ERRTOL Relative Truncation\nC error less than\nC 1.0E-3 3.0E-19\nC 3.0E-3 2.0E-16\nC 1.0E-2 3.0E-13\nC 3.0E-2 2.0E-10\nC 1.0E-1 3.0E-7\nC\nC\nC Decreasing ERRTOL by a factor of 10 yields six more\nC decimal digits of accuracy at the expense of one or\nC two more iterations of the duplication theorem.\nC\nC *Long Description:\nC\nC RF Special Comments\nC\nC\nC\nC Check by addition theorem: RF(X,X+Z,X+W) + RF(Y,Y+Z,Y+W)\nC = RF(0,Z,W), where X,Y,Z,W are positive and X * Y = Z * W.\nC\nC\nC On Input:\nC\nC X, Y, and Z are the variables in the integral RF(X,Y,Z).\nC\nC\nC On Output:\nC\nC\nC X, Y, and Z are unaltered.\nC\nC\nC\nC ********************************************************\nC\nC Warning: Changes in the program may improve speed at the\nC expense of robustness.\nC\nC\nC\nC Special Functions via RF\nC\nC\nC Legendre form of ELLIPTIC INTEGRAL of 1st kind\nC ----------------------------------------------\nC\nC\nC 2 2 2\nC F(PHI,K) = SIN(PHI) RF(COS (PHI),1-K SIN (PHI),1)\nC\nC\nC 2\nC K(K) = RF(0,1-K ,1)\nC\nC PI/2 2 2 -1/2\nC = INT (1-K SIN (PHI) ) D PHI\nC 0\nC\nC\nC\nC\nC\nC Bulirsch form of ELLIPTIC INTEGRAL of 1st kind\nC ----------------------------------------------\nC\nC\nC 2 2 2\nC EL1(X,KC) = X RF(1,1+KC X ,1+X )\nC\nC\nC\nC\nC Lemniscate constant A\nC ---------------------\nC\nC\nC 1 4 -1/2\nC A = INT (1-S ) DS = RF(0,1,2) = RF(0,2,1)\nC 0\nC\nC\nC -------------------------------------------------------------------\nC\nC***REFERENCES B. C. Carlson and E. M. Notis, Algorithms for incomplete\nC elliptic integrals, ACM Transactions on Mathematical\nC Software 7, 3 (September 1981), pp. 398-403.\nC B. C. Carlson, Computing elliptic integrals by\nC duplication, Numerische Mathematik 33, (1979),\nC pp. 1-16.\nC B. C. Carlson, Elliptic integrals of the first kind,\nC SIAM Journal of Mathematical Analysis 8, (1977),\nC pp. 231-242.\nC***ROUTINES CALLED R1MACH, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 790801 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 891009 Removed unreferenced statement labels. (WRB)\nC 891009 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 900510 Changed calls to XERMSG to standard form, and some\nC editorial changes. (RWC))\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE RF\n CHARACTER*16 XERN3, XERN4, XERN5, XERN6\n INTEGER IER\n REAL LOLIM, UPLIM, EPSLON, ERRTOL\n REAL C1, C2, C3, E2, E3, LAMDA\n REAL MU, S, X, XN, XNDEV\n REAL XNROOT, Y, YN, YNDEV, YNROOT, Z, ZN, ZNDEV,\n * ZNROOT\n LOGICAL FIRST\n SAVE ERRTOL,LOLIM,UPLIM,C1,C2,C3,FIRST\n DATA FIRST /.TRUE./\nC\nC***FIRST EXECUTABLE STATEMENT RF\nC\n IF (FIRST) THEN\n ERRTOL = (4.0E0*R1MACH(3))**(1.0E0/6.0E0)\n LOLIM = 5.0E0 * R1MACH(1)\n UPLIM = R1MACH(2)/5.0E0\nC\n C1 = 1.0E0/24.0E0\n C2 = 3.0E0/44.0E0\n C3 = 1.0E0/14.0E0\n ENDIF\n FIRST = .FALSE.\nC\nC CALL ERROR HANDLER IF NECESSARY.\nC\n RF = 0.0E0\n IF (MIN(X,Y,Z).LT.0.0E0) THEN\n IER = 1\n WRITE (XERN3, '(1PE15.6)') X\n WRITE (XERN4, '(1PE15.6)') Y\n WRITE (XERN5, '(1PE15.6)') Z\n CALL XERMSG ('SLATEC', 'RF',\n * 'MIN(X,Y,Z).LT.0 WHERE X = ' // XERN3 // ' Y = ' // XERN4 //\n * ' AND Z = ' // XERN5, 1, 1)\n RETURN\n ENDIF\nC\n IF (MAX(X,Y,Z).GT.UPLIM) THEN\n IER = 3\n WRITE (XERN3, '(1PE15.6)') X\n WRITE (XERN4, '(1PE15.6)') Y\n WRITE (XERN5, '(1PE15.6)') Z\n WRITE (XERN6, '(1PE15.6)') UPLIM\n CALL XERMSG ('SLATEC', 'RF',\n * 'MAX(X,Y,Z).GT.UPLIM WHERE X = ' // XERN3 // ' Y = ' //\n * XERN4 // ' Z = ' // XERN5 // ' AND UPLIM = ' // XERN6, 3, 1)\n RETURN\n ENDIF\nC\n IF (MIN(X+Y,X+Z,Y+Z).LT.LOLIM) THEN\n IER = 2\n WRITE (XERN3, '(1PE15.6)') X\n WRITE (XERN4, '(1PE15.6)') Y\n WRITE (XERN5, '(1PE15.6)') Z\n WRITE (XERN6, '(1PE15.6)') LOLIM\n CALL XERMSG ('SLATEC', 'RF',\n * 'MIN(X+Y,X+Z,Y+Z).LT.LOLIM WHERE X = ' // XERN3 //\n * ' Y = ' // XERN4 // ' Z = ' // XERN5 // ' AND LOLIM = ' //\n * XERN6, 2, 1)\n RETURN\n ENDIF\nC\n IER = 0\n XN = X\n YN = Y\n ZN = Z\nC\n 30 MU = (XN+YN+ZN)/3.0E0\n XNDEV = 2.0E0 - (MU+XN)/MU\n YNDEV = 2.0E0 - (MU+YN)/MU\n ZNDEV = 2.0E0 - (MU+ZN)/MU\n EPSLON = MAX(ABS(XNDEV), ABS(YNDEV), ABS(ZNDEV))\n IF (EPSLON.LT.ERRTOL) GO TO 40\n XNROOT = SQRT(XN)\n YNROOT = SQRT(YN)\n ZNROOT = SQRT(ZN)\n LAMDA = XNROOT*(YNROOT+ZNROOT) + YNROOT*ZNROOT\n XN = (XN+LAMDA)*0.250E0\n YN = (YN+LAMDA)*0.250E0\n ZN = (ZN+LAMDA)*0.250E0\n GO TO 30\nC\n 40 E2 = XNDEV*YNDEV - ZNDEV*ZNDEV\n E3 = XNDEV*YNDEV*ZNDEV\n S = 1.0E0 + (C1*E2-0.10E0-C2*E3)*E2 + C3*E3\n RF = S/SQRT(MU)\nC\n RETURN\n END\n", "meta": {"hexsha": "1efabfa201d934fc344874b197bd02c1572a107c", "size": 10715, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/rf.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/rf.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/rf.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.8898809524, "max_line_length": 72, "alphanum_fraction": 0.4985534298, "num_tokens": 3469, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.764512259114941}} {"text": " SUBROUTINE V_SPLINE(k_bc1,k_bcn,n,x,f,wk)\n!***********************************************************************\n!V_SPLINE evaluates the coefficients for a 1d cubic interpolating spline\n!References:\n! Forsythe, Malcolm, Moler, Computer Methods for Mathematical\n! Computations, Prentice-Hall, 1977, p.76\n! Engeln-Muellges, Uhlig, Numerical Algorithms with Fortran, Springer,\n! 1996, p.251\n! W.A.Houlberg, D.McCune 3/2000\n!Input:\n! k_bc1-option for BC at x1 = x(1)\n! =-1 periodic, ignore k_bcn\n! =0 not-a-knot\n! =1 s'(x1) = input value of f(2,1)\n! =2 s''(x1) = input value of f(3,1)\n! =3 s'(x1) = 0.0\n! =4 s''(x1) = 0.0\n! =5 match first derivative to first 2 points\n! =6 match second derivative to first 3 points\n! =7 match third derivative to first 4 points\n! =else use not-a-knot\n! k_bcn-option for boundary condition at xn = x(n)\n! =0 not-a-knot\n! =1 s'(xn) = input value of f(2,n)\n! =2 s''(xn) = input value of f(3,n)\n! =3 s'(xn) = 0.0\n! =4 s''(xn) = 0.0\n! =5 match first derivative to last 2 points\n! =6 match second derivative to lasst 3 points\n! =7 match third derivative to last 4 points\n! =else use knot-a-knot\n! n-number of data points or knots-(n.ge.2)\n! x(n)-abscissas of the knots in strictly increasing order\n! f(1,i)-ordinates of the knots\n! f(2,1)-input value of s'(x1) for k_bc1=1\n! f(2,n)-input value of s'(xn) for k_bcn=1\n! f(3,1)-input value of s''(x1) for k_bc1=2\n! f(3,n)-input value of s''(xn) for k_bcn=2\n! wk(n)-scratch work area for periodic BC\n!Output:\n! f(2,i)=s'(x(i))\n! f(3,i)=s''(x(i))\n! f(4,i)=s'''(x(i))\n!Comments:\n! s(x)=f(1,i)+f(2,i)*(x-x(i))+f(3,i)*(x-x(i))**2/2!\n! +f(4,i)*(x-x(i))**3/3! for x(i).le.x.le.x(i+1)\n! W_SPLINE can be used to evaluate the spline and its derivatives\n! The cubic spline is twice differentiable (C2)\n!\n! modifications -- dmc 18 Feb 2010:\n! Deal with n.lt.4 -- the general tridiagonal spline method \n! does not have the right formulation for n.eq.3 \"not a knot\" or periodic\n! boundary conditions, nor for n.eq.2 with any boundary conditions.\n!\n! Apply boundary conditions even for n=2, when the \"spline\" is really\n! just a single cubic polynomial.\n! In this case, several boundary condition (BC) options are mapped to \n! BC option 5, 1st divided difference. If 5 is used on both sides\n! of an n=2 \"spline\" you get a linear piece which is what the old\n! code always gave, regardless of BC option settings. The following\n! BC controls are mapped to 5: \n! periodic (-1)\n! not a knot (0) (for n=2 no grid point exists for knot location).\n! option (5) is preserved\n! options 6 and 7 -- mapped to (5); higher divided differences \n! need n>2; in fact 7 needs n>3; for n=3 option 6 is substituted.\n!\n! The boundary condition screening is done at the start of the code;\n! passed controls k_bc1 and k_bcn are mapped to i_bc1 and i_bcn.\n!\n! ALSO: for n=3, \"not a knot\" from both left and right needs special\n! interpretation, since the 2 boundary conditions overlap. The\n! chosen interpretation is a parabolic fit to the 3 given data points.\n! and so f''' = 0 and f'' = constant. If \"not a knot\" is used on \n! one side only, the solution is a single cubic piece and special \n! code is also needed.\n! ALSO: for n=3, \"periodic\" boundary condition needs special code; this\n! is added.\n!\n! bugfixes -- dmc 24 Feb 2004:\n! (a) fixed logic for not-a-knot:\n! ! Set f(3,1) for not-a-knot\n! IF(k_bc1.le.0.or.k_bc1.gt.7) THEN ...\n! instead of\n! ! Set f(3,1) for not-a-knot\n! IF(k_bc1.le.0.or.k_bc1.gt.5) THEN ...\n! and similarly for logic after cmt\n! ! Set f(3,n) for not-a-knot\n! as required since k_bc*=6 and k_bc*=7 are NOT not-a-knot BCs.\n!\n! (b) the BCs to fix 2nd derivative at end points did not work if that\n! 2nd derivative were non-zero. The reason is that in those cases\n! the off-diagonal matrix elements nearest the corners are not\n! symmetric; i.e. elem(1,2).ne.elem(2,1) and \n! elem(n-1,n).ne.elem(n,n-1) where I use \"elem\" to refer to\n! the tridiagonal matrix elements. The correct values for the\n! elements is: elem(1,2)=0, elem(2,1)=x(2)-x(1)\n! elem(n,n-1)=0, elem(n-1,n)=x(n)-x(n-1)\n! the old code in effect had these as all zeroes. Since this\n! meant the wrong set of linear equations was solved, the\n! resulting spline had a discontinuity in its 1st derivative\n! at x(2) and x(n-1). Fixed by introducing elem21 and elemnn1\n! to represent the non-symmetric lower-diagonal values. Since\n! elem21 & elemnn1 are both on the lower diagonals, logic to \n! use them occurs in the non-periodic forward elimination loop\n! only. DMC 24 Feb 2004.\n!***********************************************************************\n IMPLICIT NONE\n!Declaration of input variables\n INTEGER k_bc1, k_bcn,\n & n\n REAL x(*), wk(*),\n & f(4,*)\n!Declaration in local variables\n INTEGER i, ib,\n & imax, imin\n REAL a1, an,\n & b1, bn,\n & q, t,\n & hn\n REAL elem21, elemnn1 ! (dmc)\n\n integer :: i_bc1,i_bcn ! screened BC controls\n\n integer :: iord1,iord2 ! used for n=2 only\n real :: h,f0,fh ! used for n=2,3 only\n real :: h1,h2,h3,dels ! used for n=3 special cases\n real :: f1,f2,f3,aa,bb ! used for n=3\n\n integer :: i3knots ! for n=3, number of not-a-knot BCs\n integer :: i3perio ! for n=3, periodic BC\n\n!------------------------------------------------------------\n! screen the BC options (DMC Feb. 2010...)\n\n i_bc1=k_bc1\n i_bcn=k_bcn\n\n if((i_bc1.lt.-1).or.(i_bc1.gt.7)) i_bc1=0 ! outside [-1:7] -> not-a-knot\n if((i_bcn.lt.0).or.(i_bcn.gt.7)) i_bcn=0 ! outside [0:7] -> not-a-knot\n\n if(i_bc1.eq.-1) i_bcn=-1 ! periodic BC\n\n i3knots=0\n i3perio=0\n if(n.eq.3) then\n i_bc1=min(6,i_bc1)\n i_bcn=min(6,i_bcn)\n if(i_bc1.eq.0) i3knots = i3knots + 1\n if(i_bcn.eq.0) i3knots = i3knots + 1\n if(i_bc1.eq.-1) i3perio = 1\n endif\n\n if(n.eq.2) then\n if(i_bc1.eq.-1) then\n i_bc1=5\n i_bcn=5\n endif\n if((i_bc1.eq.0).or.(i_bc1.gt.5)) i_bc1=5\n if((i_bcn.eq.0).or.(i_bcn.gt.5)) i_bcn=5\n\n if((i_bc1.eq.1).or.(i_bc1.eq.3).or.(i_bc1.eq.5)) then\n iord1=1 ! 1st derivative match on LHS\n else\n iord1=2 ! 2nd derivative match on LHS\n endif\n\n if((i_bcn.eq.1).or.(i_bcn.eq.3).or.(i_bcn.eq.5)) then\n iord2=1 ! 1st derivative match on RHS\n else\n iord2=2 ! 2nd derivative match on RHS\n endif\n endif\n\n!Set default range\n imin=1\n imax=n\n!Set first and second BC values\n a1=0.0\n b1=0.0\n an=0.0\n bn=0.0\n IF(i_bc1.eq.1) THEN\n a1=f(2,1)\n ELSEIF(i_bc1.eq.2) THEN\n b1=f(3,1)\n ELSEIF(i_bc1.eq.5) THEN\n a1=(f(1,2)-f(1,1))/(x(2)-x(1))\n ELSEIF(i_bc1.eq.6) THEN\n b1=2.0*((f(1,3)-f(1,2))/(x(3)-x(2))\n & -(f(1,2)-f(1,1))/(x(2)-x(1)))/(x(3)-x(1))\n ENDIF\n IF(i_bcn.eq.1) THEN\n an=f(2,n)\n ELSEIF(i_bcn.eq.2) THEN\n bn=f(3,n)\n ELSEIF(i_bcn.eq.5) THEN\n an=(f(1,n)-f(1,n-1))/(x(n)-x(n-1))\n ELSEIF(i_bcn.eq.6) THEN\n bn=2.0*((f(1,n)-f(1,n-1))/(x(n)-x(n-1))\n & -(f(1,n-1)-f(1,n-2))/(x(n-1)-x(n-2)))/(x(n)-x(n-2))\n ENDIF\n!Clear f(2:4,n)\n f(2,n)=0.0\n f(3,n)=0.0\n f(4,n)=0.0\n IF(n.eq.2) THEN\n if((i_bc1.eq.5).and.(i_bcn.eq.5)) then\n!Coefficients for n=2 (this was the original code)\n f(2,1)=(f(1,2)-f(1,1))/(x(2)-x(1))\n f(3,1)=0.0\n f(4,1)=0.0\n f(2,2)=f(2,1)\n f(3,2)=0.0\n f(4,2)=0.0\n else if((iord1.eq.1).and.(iord2.eq.1)) then\n ! LHS: match a1 for 1st deriv; RHS: match an for 1st deriv.\n f(2,1)=a1\n f(2,2)=an\n h = (x(2)-x(1))\n f0 = f(1,1)\n fh = f(1,2)\n\n ! setting xx = x-x(1),\n ! f = c1*xx**3 + c2*xx**2 + a1*xx + f0\n ! --> c1*h**3 + c2*h**2 = fh - f0 - a1*h\n ! and 3*c1*h**2 + 2*c2*h = an - a1\n ! f' = 3*c1*xx*2 + 2*c2*xx + a1\n ! f'' = 6*c1*xx + 2*c2\n ! f''' = 6*c1\n\n ! solve 2x2 system for c1 -> f(4,1)/6 and c2 -> f(3,1)/2\n\n f(3,1) = (3*(fh-f0)/(h*h) - (2*a1 + an)/h)*2 ! 2*c2\n f(4,1) = (-2*(fh-f0)/(h*h*h) + (a1 + an)/(h*h))*6 ! 6*c1\n\n f(4,2) = f(4,1)\n f(3,2) = f(4,1)*h + f(3,1)\n\n else if((iord1.eq.1).and.(iord2.eq.2)) then\n ! LHS: match a1 for 1st deriv; RHS: match bn for 2nd deriv.\n f(2,1)=a1\n f(3,2)=bn\n h = (x(2)-x(1))\n f0 = f(1,1)\n fh = f(1,2)\n\n ! setting xx = x-x(1),\n ! f = c1*xx**3 + c2*xx**2 + a1*xx + f0\n ! --> c1*h**3 + c2*h**2 = fh - f0 - a1*h\n ! and 6*c1*h + 2*c2 = bn\n ! f' = 3*c1*xx*2 + 2*c2*xx + a1\n ! f'' = 6*c1*xx + 2*c2\n ! f''' = 6*c1\n\n ! solve 2x2 system for c1 -> f(4,1)/6 and c2 -> f(3,1)/2\n\n f(3,1) = (-bn/4 + 3*(fh-f0)/(2*h*h) - 3*a1/(2*h))*2 ! 2*c2\n f(4,1) = (bn/(4*h) - (fh-f0)/(2*h*h*h) + a1/(2*h*h))*6 ! 6*c1\n\n f(4,2) = f(4,1)\n f(2,2) = f(4,1)*h*h/2 + f(3,1)*h + a1\n else if((iord1.eq.2).and.(iord2.eq.1)) then\n ! LHS: match b1 for 2nd deriv; RHS: match an for 1st deriv.\n f(3,1)=b1\n f(2,2)=an\n h = (x(2)-x(1))\n f0 = f(1,1)\n fh = f(1,2)\n\n ! setting xx = x-x(1), \n ! f = c1*xx**3 + (b1/2)*xx**2 + c3*xx + f0\n ! --> c1*h**3 + c3*h = fh - f0 - b1*h**2/2\n ! and 3*c1*h**2 + c3 = an - b1*h\n ! f' = 3*c1*xx*2 + b1*xx + c3\n ! f'' = 6*c1*xx + b1\n ! f''' = 6*c1\n\n ! solve 2x2 system for c1 -> f(4,1)/6 and c2 -> f(3,1)/2\n\n f(2,1) = 3*(fh-f0)/(2*h) - b1*h/4 - an/2 ! c3\n f(4,1) = (an/(2*h*h) - (fh-f0)/(2*h*h*h) - b1/(4*h))*6 ! 6*c1\n\n f(4,2) = f(4,1)\n f(3,2) = f(4,1)*h + f(3,1)\n else if((iord1.eq.2).and.(iord2.eq.2)) then\n ! LHS: match b1 for 2nd deriv; RHS: match bn for 2nd deriv.\n f(3,1)=b1\n f(3,2)=bn\n h = (x(2)-x(1))\n f0 = f(1,1)\n fh = f(1,2)\n\n ! setting xx = x-x(1), \n ! f = c1*xx**3 + (b1/2)*xx**2 + c3*xx + f0\n ! --> c1*h**3 + c3*h = fh - f0 - b1*h**2/2\n ! and 6*c1*h = bn - b1\n ! f' = 3*c1*xx*2 + b1*xx + c3\n ! f'' = 6*c1*xx + b1\n ! f''' = 6*c1\n\n ! solve 2x2 system for c1 -> f(4,1)/6 and c2 -> f(3,1)/2\n\n f(2,1) = (fh-f0)/h -b1*h/3 -bn*h/6 ! c3\n f(4,1) = (bn-b1)/h ! 6*c1\n\n f(4,2) = f(4,1)\n f(2,2) = f(4,1)*h*h/2 + b1*h + f(2,1)\n endif\n\n ELSE IF(i3perio.eq.1) then\n!Special case: nx=3 periodic spline\n h1=x(2)-x(1)\n h2=x(3)-x(2)\n h=h1+h2\n\n dels=(f(1,3)-f(1,2))/h2 - (f(1,2)-f(1,1))/h1\n\n f(2,1)= (f(1,2)-f(1,1))/h1 + (h1*dels)/h\n f(3,1)= -6*dels/h\n f(4,1)= 12*dels/(h1*h)\n\n f(2,2)= (f(1,3)-f(1,2))/h2 - (h2*dels)/h\n f(3,2)= 6*dels/h\n f(4,2)= -12*dels/(h2*h)\n\n f(2,3)=f(2,1)\n f(3,3)=f(3,1)\n f(4,3)=f(4,1)\n\n\n ELSE IF(i3knots.eq.2) then\n!Special case: nx=3, not-a-knot on both sides\n h1=x(2)-x(1)\n h2=x(3)-x(2)\n h=h1+h2\n ! this is just a quadratic fit through 3 pts\n f1=f(1,1)-f(1,2)\n f2=f(1,3)-f(1,2)\n\n! quadratic around origin at (x(2),f(1,2))\n! aa*h1**2 - bb*h1 = f1\n! aa*h2**2 + bb*h2 = f2\n\n aa = (f2*h1 + f1*h2)/(h1*h2*h)\n bb = (f2*h1*h1 - f1*h2*h2)/(h1*h2*h)\n\n f(4,1:3)=0.0 ! f''' = 0 (quadratic polynomial)\n f(3,1:3)=2*aa ! f'' = const\n\n f(2,1)=bb-2*aa*h1\n f(2,2)=bb\n f(2,3)=bb+2*aa*h2\n\n ELSE IF(i3knots.eq.1) then\n!Special cases: nx=3, not-a-knot on single side\n if((i_bc1.eq.1).or.(i_bc1.eq.3).or.(i_bc1.eq.5)) then\n ! f' LHS condition; not-a-knot RHS\n! a1 = f' LHS BC\n h2=x(2)-x(1)\n h3=x(3)-x(1)\n\n f2=f(1,2)-f(1,1)\n f3=f(1,3)-f(1,1)\n\n! find cubic aa*xx**3 + bb*xx**2 + a1*xx\n! satisfying aa*h2**3 + bb*h2**2 + a1*h2 = f2\n! and aa*h3**3 + bb*h3**2 + a1*h3 = f3\n\n aa=a1/(h2*h3) + f3/(h3*h3*(h3-h2)) - f2/(h2*h2*(h3-h2))\n bb=-a1*(h3*h3-h2*h2)/(h2*h3*(h3-h2)) \n > + f2*h3/(h2*h2*(h3-h2)) - f3*h2/(h3*h3*(h3-h2))\n\n f(2,1)=a1\n f(3,1)=2*bb\n f(4,1)=6*aa\n\n f(2,2)=3*aa*h2*h2 + 2*bb*h2 + a1\n f(3,2)=6*aa*h2 + 2*bb\n f(4,2)=6*aa\n\n f(2,3)=3*aa*h3*h3 + 2*bb*h3 + a1\n f(3,3)=6*aa*h3 + 2*bb\n f(4,3)=6*aa\n\n else if((i_bc1.eq.2).or.(i_bc1.eq.4).or.(i_bc1.eq.6)) then\n ! f'' LHS condition; not-a-knot RHS\n! b1 = f'' LHS BC\n h2=x(2)-x(1)\n h3=x(3)-x(1)\n\n f2=f(1,2)-f(1,1)\n f3=f(1,3)-f(1,1)\n\n! find cubic aa*xx**3 + (b1/2)*xx**2 + bb*xx\n! satisfying aa*h2**3 + bb*h2 = f2 -(b1/2)*h2**2\n! and aa*h3**3 + bb*h3 = f3 -(b1/2)*h3**2\n\n aa= -(b1/2)*(h3-h2)/(h3*h3-h2*h2) \n > -f2/(h2*(h3*h3-h2*h2)) + f3/(h3*(h3*h3-h2*h2))\n bb= -(b1/2)*h2*h3*(h3-h2)/(h3*h3-h2*h2) \n > +f2*h3*h3/(h2*(h3*h3-h2*h2)) \n > -f3*h2*h2/(h3*(h3*h3-h2*h2))\n\n f(2,1)=bb\n f(3,1)=b1\n f(4,1)=6*aa\n\n f(2,2)=3*aa*h2*h2 + b1*h2 + bb\n f(3,2)=6*aa*h2 + b1\n f(4,2)=6*aa\n\n f(2,3)=3*aa*h3*h3 + b1*h3 + bb\n f(3,3)=6*aa*h3 + b1\n f(4,3)=6*aa\n\n else if((i_bcn.eq.1).or.(i_bcn.eq.3).or.(i_bcn.eq.5)) then\n ! f' RHS condition; not-a-knot LHS\n! an = f' RHS BC\n h2=x(2)-x(3)\n h3=x(1)-x(3)\n\n f2=f(1,2)-f(1,3)\n f3=f(1,1)-f(1,3)\n\n! find cubic aa*xx**3 + bb*xx**2 + an*xx\n! satisfying aa*h2**3 + bb*h2**2 + an*h2 = f2\n! and aa*h3**3 + bb*h3**2 + an*h3 = f3\n\n aa=an/(h2*h3) + f3/(h3*h3*(h3-h2)) - f2/(h2*h2*(h3-h2))\n bb=-an*(h3*h3-h2*h2)/(h2*h3*(h3-h2)) \n > + f2*h3/(h2*h2*(h3-h2)) - f3*h2/(h3*h3*(h3-h2))\n\n f(2,3)=an\n f(3,3)=2*bb\n f(4,3)=6*aa\n\n f(2,2)=3*aa*h2*h2 + 2*bb*h2 + an\n f(3,2)=6*aa*h2 + 2*bb\n f(4,2)=6*aa\n\n f(2,1)=3*aa*h3*h3 + 2*bb*h3 + an\n f(3,1)=6*aa*h3 + 2*bb\n f(4,1)=6*aa\n\n else if((i_bcn.eq.2).or.(i_bcn.eq.4).or.(i_bcn.eq.6)) then\n ! f'' RHS condition; not-a-knot LHS\n! bn = f'' RHS BC\n h2=x(2)-x(3)\n h3=x(1)-x(3)\n\n f2=f(1,2)-f(1,3)\n f3=f(1,1)-f(1,3)\n\n! find cubic aa*xx**3 + (bn/2)*xx**2 + bb*xx\n! satisfying aa*h2**3 + bb*h2 = f2 -(bn/2)*h2**2\n! and aa*h3**3 + bb*h3 = f3 -(bn/2)*h3**2\n\n aa= -(bn/2)*(h3-h2)/(h3*h3-h2*h2) \n > -f2/(h2*(h3*h3-h2*h2)) + f3/(h3*(h3*h3-h2*h2))\n bb= -(bn/2)*h2*h3*(h3-h2)/(h3*h3-h2*h2) \n > +f2*h3*h3/(h2*(h3*h3-h2*h2)) \n > -f3*h2*h2/(h3*(h3*h3-h2*h2))\n\n f(2,3)=bb\n f(3,3)=bn\n f(4,3)=6*aa\n\n f(2,2)=3*aa*h2*h2 + bn*h2 + bb\n f(3,2)=6*aa*h2 + bn\n f(4,2)=6*aa\n\n f(2,1)=3*aa*h3*h3 + bn*h3 + bb\n f(3,1)=6*aa*h3 + bn\n f(4,1)=6*aa\n\n endif\n ELSE IF(n.gt.2) THEN\n!Set up tridiagonal system for A*y=B where y(i) are the second\n! derivatives at the knots\n! f(2,i) are the diagonal elements of A\n! f(4,i) are the off-diagonal elements of A\n! f(3,i) are the B elements/3, and will become c/3 upon solution\n f(4,1)=x(2)-x(1)\n f(3,2)=(f(1,2)-f(1,1))/f(4,1)\n DO i=2,n-1\n f(4,i)=x(i+1)-x(i)\n f(2,i)=2.0*(f(4,i-1)+f(4,i))\n f(3,i+1)=(f(1,i+1)-f(1,i))/f(4,i)\n f(3,i)=f(3,i+1)-f(3,i)\n ENDDO\n!\n! (dmc): save now:\n!\n elem21=f(4,1)\n elemnn1=f(4,n-1)\n!\n! BC's\n! Left\n IF(i_bc1.eq.-1) THEN\n f(2,1)=2.0*(f(4,1)+f(4,n-1))\n f(3,1)=(f(1,2)-f(1,1))/f(4,1)-(f(1,n)-f(1,n-1))/f(4,n-1)\n wk(1)=f(4,n-1)\n DO i=2,n-3\n wk(i)=0.0\n ENDDO\n wk(n-2)=f(4,n-2)\n wk(n-1)=f(4,n-1)\n ELSEIF(i_bc1.eq.1.or.i_bc1.eq.3.or.i_bc1.eq.5) THEN\n f(2,1)=2.0*f(4,1)\n f(3,1)=(f(1,2)-f(1,1))/f(4,1)-a1\n ELSEIF(i_bc1.eq.2.or.i_bc1.eq.4.or.i_bc1.eq.6) THEN\n f(2,1)=2.0*f(4,1)\n f(3,1)=f(4,1)*b1/3.0\n f(4,1)=0.0 ! upper diagonal only (dmc: cf elem21)\n ELSEIF(i_bc1.eq.7) THEN\n f(2,1)=-f(4,1)\n f(3,1)=f(3,3)/(x(4)-x(2))-f(3,2)/(x(3)-x(1))\n f(3,1)=f(3,1)*f(4,1)**2/(x(4)-x(1))\n ELSE ! not a knot:\n imin=2\n f(2,2)=f(4,1)+2.0*f(4,2)\n f(3,2)=f(3,2)*f(4,2)/(f(4,1)+f(4,2))\n ENDIF\n! Right\n IF(i_bcn.eq.1.or.i_bcn.eq.3.or.i_bcn.eq.5) THEN\n f(2,n)=2.0*f(4,n-1)\n f(3,n)=-(f(1,n)-f(1,n-1))/f(4,n-1)+an\n ELSEIF(i_bcn.eq.2.or.i_bcn.eq.4.or.i_bcn.eq.6) THEN\n f(2,n)=2.0*f(4,n-1)\n f(3,n)=f(4,n-1)*bn/3.0\n!xxx f(4,n-1)=0.0 ! dmc: preserve f(4,n-1) for back subst.\n elemnn1=0.0 ! lower diaganol only (dmc)\n ELSEIF(i_bcn.eq.7) THEN\n f(2,n)=-f(4,n-1)\n f(3,n)=f(3,n-1)/(x(n)-x(n-2))-f(3,n-2)/(x(n-1)-x(n-3))\n f(3,n)=-f(3,n)*f(4,n-1)**2/(x(n)-x(n-3))\n ELSEIF(i_bc1.ne.-1) THEN ! not a knot:\n imax=n-1\n f(2,n-1)=2.0*f(4,n-2)+f(4,n-1)\n f(3,n-1)=f(3,n-1)*f(4,n-2)/(f(4,n-1)+f(4,n-2))\n ENDIF\n IF(i_bc1.eq.-1) THEN\n!Solve system of equations for second derivatives at the knots\n! Periodic BC\n! Forward elimination\n DO i=2,n-2\n t=f(4,i-1)/f(2,i-1)\n f(2,i)=f(2,i)-t*f(4,i-1)\n f(3,i)=f(3,i)-t*f(3,i-1)\n wk(i)=wk(i)-t*wk(i-1)\n q=wk(n-1)/f(2,i-1)\n wk(n-1)=-q*f(4,i-1)\n f(2,n-1)=f(2,n-1)-q*wk(i-1)\n f(3,n-1)=f(3,n-1)-q*f(3,i-1)\n ENDDO\n! Correct the n-1 element\n wk(n-1)=wk(n-1)+f(4,n-2)\n! Complete the forward elimination\n! wk(n-1) and wk(n-2) are the off-diag elements of the lower corner\n t=wk(n-1)/f(2,n-2)\n f(2,n-1)=f(2,n-1)-t*wk(n-2)\n f(3,n-1)=f(3,n-1)-t*f(3,n-2)\n! Back substitution\n f(3,n-1)=f(3,n-1)/f(2,n-1)\n f(3,n-2)=(f(3,n-2)-wk(n-2)*f(3,n-1))/f(2,n-2)\n DO ib=3,n-1\n i=n-ib\n f(3,i)=(f(3,i)-f(4,i)*f(3,i+1)-wk(i)*f(3,n-1))/f(2,i)\n ENDDO\n f(3,n)=f(3,1)\n ELSE\n! Non-periodic BC\n! Forward elimination\n! For Not-A-Knot BC the off-diagonal end elements are not equal\n DO i=imin+1,imax\n IF((i.eq.n-1).and.(imax.eq.n-1)) THEN\n t=(f(4,i-1)-f(4,i))/f(2,i-1)\n ELSE\n if(i.eq.2) then\n t=elem21/f(2,i-1)\n else if(i.eq.n) then\n t=elemnn1/f(2,i-1)\n else\n t=f(4,i-1)/f(2,i-1)\n endif\n ENDIF\n IF((i.eq.imin+1).and.(imin.eq.2)) THEN\n f(2,i)=f(2,i)-t*(f(4,i-1)-f(4,i-2))\n ELSE\n f(2,i)=f(2,i)-t*f(4,i-1)\n ENDIF\n f(3,i)=f(3,i)-t*f(3,i-1)\n ENDDO\n! Back substitution\n f(3,imax)=f(3,imax)/f(2,imax)\n DO ib=1,imax-imin\n i=imax-ib\n IF((i.eq.2).and.(imin.eq.2)) THEN\n f(3,i)=(f(3,i)-(f(4,i)-f(4,i-1))*f(3,i+1))/f(2,i)\n ELSE\n f(3,i)=(f(3,i)-f(4,i)*f(3,i+1))/f(2,i)\n ENDIF\n ENDDO\n! Reset d array to step size\n f(4,1)=x(2)-x(1)\n f(4,n-1)=x(n)-x(n-1)\n! Set f(3,1) for not-a-knot\n IF(i_bc1.le.0.or.i_bc1.gt.7) THEN\n f(3,1)=(f(3,2)*(f(4,1)+f(4,2))-f(3,3)*f(4,1))/f(4,2)\n ENDIF\n! Set f(3,n) for not-a-knot\n IF(i_bcn.le.0.or.i_bcn.gt.7) THEN\n f(3,n)=f(3,n-1)+(f(3,n-1)-f(3,n-2))*f(4,n-1)/f(4,n-2)\n ENDIF\n ENDIF\n!f(3,i) is now the sigma(i) of the text and f(4,i) is the step size\n!Compute polynomial coefficients\n DO i=1,n-1\n f(2,i)=\n > (f(1,i+1)-f(1,i))/f(4,i)-f(4,i)*(f(3,i+1)+2.0*f(3,i))\n f(4,i)=(f(3,i+1)-f(3,i))/f(4,i)\n f(3,i)=6.0*f(3,i)\n f(4,i)=6.0*f(4,i)\n ENDDO\n IF(i_bc1.eq.-1) THEN\n f(2,n)=f(2,1)\n f(3,n)=f(3,1)\n f(4,n)=f(4,1)\n ELSE\n hn=x(n)-x(n-1)\n f(2,n)=f(2,n-1)+hn*(f(3,n-1)+0.5*hn*f(4,n-1))\n f(3,n)=f(3,n-1)+hn*f(4,n-1)\n f(4,n)=f(4,n-1)\n IF(i_bcn.eq.1.or.i_bcn.eq.3.or.i_bcn.eq.5) THEN\n f(2,n)=an\n ELSE IF(i_bcn.eq.2.or.i_bcn.eq.4.or.i_bcn.eq.6) THEN\n f(3,n)=bn\n ENDIF\n ENDIF\n ENDIF\n RETURN\n END\n", "meta": {"hexsha": "9760e8c9b9d3507c026ba2fe0c50988fb2141721", "size": 21997, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gfile_Bfield/PSPLINE/Pspline/v_spline.f", "max_stars_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_stars_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "gfile_Bfield/PSPLINE/Pspline/v_spline.f", "max_issues_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_issues_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "gfile_Bfield/PSPLINE/Pspline/v_spline.f", "max_forks_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_forks_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 34.1568322981, "max_line_length": 79, "alphanum_fraction": 0.4411056053, "num_tokens": 9072, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533107374444, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7645122555241444}} {"text": "subroutine solve_cubic(a,b,c,lambda)\n!***********************************************************************\n! Copyright 2011 Los Alamos National Security, LLC All rights reserved\n! Unless otherwise indicated, this information has been authored by an\n! employee or employees of the Los Alamos National Security, LLC (LANS),\n! operator of the Los Alamos National Laboratory under Contract No.\n! DE-AC52-06NA25396 with the U. S. Department of Energy. The U. S.\n! Government has rights to use, reproduce, and distribute this\n! information. The public may copy and use this information without\n! charge, provided that this Notice and any statement of authorship are\n! reproduced on all copies. Neither the Government nor LANS makes any\n! warranty, express or implied, or assumes any liability or\n! responsibility for the use of this information. \n!***********************************************************************\n!********************************************************************\n! SUBROUTINE solve_cubic(a,b,c,lambda) *\n! *\n! Accepts the coefficients a,b and c of the monic cubic polynomial *\n! x**3 + a*x**2 + b*x + c = 0 and returns its three roots in the *\n! vector lambda. It is assumed that the roots are real. The *\n! intended application is the computation of eigenvalues of real, *\n! symmetric tensors - which justifies the assumption. *\n! *\n! Author : Sai Rapaka *\n! *\n!********************************************************************\n\n\nimplicit none\ninteger ii,j\ndouble precision, dimension(3) :: lambda\ndouble precision :: a,b,c, tmp\ndouble precision :: aa, bb\ndouble precision :: P, Q, D\ncomplex :: i, zeta, t1, t2\n\naa = a/3.0d0\nbb = b/3.0d0\n\nP = bb - aa*aa\nQ = c/2.0d0 + aa**3 - 1.5d0*aa*bb\nD = Q**2 + P**3\n\ni = cmplx(0.0d0, 1.0d0)\nzeta = -0.5d0 + i*sqrt(3.0d0)/2.0d0\nt1 = (Q - i*sqrt(abs(D)))**(1.0d0/3.0d0)\nt2 = (Q + i*sqrt(abs(D)))**(1.0d0/3.0d0)\n\nlambda(1) = -real(aa + t1 + t2)\nlambda(2) = -real(aa + zeta*t1 + zeta*zeta*t2)\nlambda(3) = -real(aa + zeta*zeta*t1 + zeta*t2)\n\n! First sort the eigenvectors into increasing order\ndo ii=1,3\n do j=ii+1,3\n if(lambda(ii).gt.lambda(j)) then\n tmp = lambda(ii)\n lambda(ii) = lambda(j)\n lambda(j) = tmp\n endif\n enddo\nenddo\n\nend subroutine solve_cubic\n", "meta": {"hexsha": "402a9614f06e41cfafdc57998a1037f5353df779", "size": 2708, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/solve_cubic.f90", "max_stars_repo_name": "satkarra/FEHM", "max_stars_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2018-08-09T04:55:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T21:46:32.000Z", "max_issues_repo_path": "src/solve_cubic.f90", "max_issues_repo_name": "satkarra/FEHM", "max_issues_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2018-04-06T16:17:14.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T04:40:14.000Z", "max_forks_repo_path": "src/solve_cubic.f90", "max_forks_repo_name": "satkarra/FEHM", "max_forks_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2018-06-07T21:11:55.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-11T13:48:22.000Z", "avg_line_length": 41.6615384615, "max_line_length": 72, "alphanum_fraction": 0.5025849335, "num_tokens": 692, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603709, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.7645122478297538}} {"text": "PROGRAM NumericalDifferentiation\n IMPLICIT NONE \n REAL:: x, h \n READ(*, *) x \n \n h = 0.1\n WRITE(*, *) h, f(x+h), (f(x+h) - f(x))/h, h/(2*x*x)\n\n h = 0.05\n WRITE(*, *) h, f(x+h), (f(x+h) - f(x))/h, h/(2*x*x)\n\n h = 0.01\n WRITE(*, *) h, f(x+h), (f(x+h) - f(x))/h, h/(2*x*x)\n\n h = 0.001\n WRITE(*, *) h, f(x+h), (f(x+h) - f(x))/h, h/(2*x*x)\n\n\n CONTAINS \n REAL FUNCTION f(x)\n IMPLICIT NONE \n REAL:: x\n f = log(x)\n RETURN \n END FUNCTION f\nEND PROGRAM NumericalDifferentiation", "meta": {"hexsha": "1c9b675a7e8937646988d143b8dfcd11794c4b33", "size": 541, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Numerical Differentiation and Jacobi Method of Diagonalization/1.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Numerical Differentiation and Jacobi Method of Diagonalization/1.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Numerical Differentiation and Jacobi Method of Diagonalization/1.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 20.8076923077, "max_line_length": 55, "alphanum_fraction": 0.4473197782, "num_tokens": 209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632261523028, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7645116054458045}} {"text": "SUBROUTINE phi_linear_3D(H,k,angle,x,y,z,d,omega,time,grav,phix,phiy,phiz,phi,phit)\n!\nUSE Precision\nIMPLICIT NONE\n!\nREAL(KIND=long), INTENT(IN) :: H,k,angle,x,y,z,d,omega,time,grav\nREAL(KIND=long), INTENT(OUT) :: phix,phiy,phiz\nREAL(KIND=long), INTENT(OUT), OPTIONAL :: phi,phit\n! REAL(KIND=long), OPTIONAL :: y,phi,phiyy !Boundary fitted ?\n! Local variables\nREAL(KIND=long) :: kx, ky, k_omegat, sink_omegat, cosk_omegat, temp1, temp2\n!\n!\nkx=k*cos(angle)\nky=k*sin(angle)\n!\nk_omegat=kx*x+ky*y-omega*time\nsink_omegat = sin(k_omegat)\ncosk_omegat = cos(k_omegat)\n!\ntemp1 = COSH(k*(z+d))/COSH(k*d)\ntemp2 = H*0.5d0*grav/omega\n!\nphiz = temp2*sink_omegat*temp1*k*tanh(k*(z+d))\nphix = temp2*kx*cosk_omegat*temp1\nphiy = temp2*ky*cosk_omegat*temp1\n!\nIF(present(phit)) THEN\n phit = -temp2*omega*cosk_omegat*temp1\nENDIF\nIF(present(phi)) THEN\n phi = temp2*sink_omegat*temp1\nENDIF\n\nEND SUBROUTINE phi_linear_3D\n", "meta": {"hexsha": "4baf8815835bdb66b1fcc147c04626db654445ee", "size": 905, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/functions/phi_linear_3D.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/functions/phi_linear_3D.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/functions/phi_linear_3D.f90", "max_forks_repo_name": "apengsigkarup/OceanWave3D", "max_forks_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-01T12:17:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T16:23:37.000Z", "avg_line_length": 25.1388888889, "max_line_length": 83, "alphanum_fraction": 0.720441989, "num_tokens": 380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172601537141, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.764478287245569}} {"text": "MODULE QuadratureModule\n\n USE KindModule, ONLY: &\n DP\n\n IMPLICIT NONE\n PRIVATE\n\n REAL(DP), PUBLIC, DIMENSION(1:1) :: xG1, wG1 ! 1-Point Gauss\n REAL(DP), PUBLIC, DIMENSION(1:2) :: xG2, wG2 ! 2-Point Gauss\n REAL(DP), PUBLIC, DIMENSION(1:3) :: xG3, wG3 ! 3-Point Gauss\n REAL(DP), PUBLIC, DIMENSION(1:4) :: xG4, wG4 ! 4-Point Gauss\n REAL(DP), PUBLIC, DIMENSION(1:5) :: xG5, wG5 ! 5-Point Gauss\n\n REAL(DP), PUBLIC, DIMENSION(1:1) :: xL1, wL1 ! 1-Point Lobatto (Gauss)\n REAL(DP), PUBLIC, DIMENSION(1:2) :: xL2, wL2 ! 2-Point Lobatto\n REAL(DP), PUBLIC, DIMENSION(1:3) :: xL3, wL3 ! 3-Point Lobatto\n REAL(DP), PUBLIC, DIMENSION(1:4) :: xL4, wL4 ! 4-Point Lobatto\n REAL(DP), PUBLIC, DIMENSION(1:5) :: xL5, wL5 ! 5-Point Lobatto\n\n PUBLIC :: &\n InitializeQuadratures, &\n GetQuadrature\n\nCONTAINS\n\n\n SUBROUTINE InitializeQuadratures\n\n ! Quadratures Defined on [-0.5, 0.5]\n\n !**********************************************\n ! 1-Point Gaussian Quadrature\n !**********************************************\n\n xG1(1) = 0.0_DP\n\n wG1(1) = 1.0_DP\n\n !**********************************************\n ! 2-Point Gaussian Quadrature\n !**********************************************\n\n xG2(1) = - SQRT( 1.0_DP / 12.0_DP )\n xG2(2) = + SQRT( 1.0_DP / 12.0_DP )\n\n wG2(1) = 0.5_DP\n wG2(2) = 0.5_DP\n\n !**********************************************\n ! 3-Point Gaussian Quadrature\n !**********************************************\n\n xG3(1) = - SQRT( 15.0_DP ) / 10.0_DP\n xG3(2) = 0.0_DP\n xG3(3) = + SQRT( 15.0_DP ) / 10.0_DP\n\n wG3(1) = 5.0_DP / 18.0_DP\n wG3(2) = 8.0_DP / 18.0_DP\n wG3(3) = 5.0_DP / 18.0_DP\n\n !**********************************************\n ! 4-Point Gaussian Quadrature\n !**********************************************\n\n xG4(1) = - SQRT( (3.0_DP+2.0_DP*SQRT(6.0_DP/5.0_DP)) / 7.0_DP ) / 2.0_DP\n xG4(2) = - SQRT( (3.0_DP-2.0_DP*SQRT(6.0_DP/5.0_DP)) / 7.0_DP ) / 2.0_DP\n xG4(3) = + SQRT( (3.0_DP-2.0_DP*SQRT(6.0_DP/5.0_DP)) / 7.0_DP ) / 2.0_DP\n xG4(4) = + SQRT( (3.0_DP+2.0_DP*SQRT(6.0_DP/5.0_DP)) / 7.0_DP ) / 2.0_DP\n\n wG4(1) = ( 18.0_DP - SQRT( 30.0_DP ) ) / 72.0_DP\n wG4(2) = ( 18.0_DP + SQRT( 30.0_DP ) ) / 72.0_DP\n wG4(3) = ( 18.0_DP + SQRT( 30.0_DP ) ) / 72.0_DP\n wG4(4) = ( 18.0_DP - SQRT( 30.0_DP ) ) / 72.0_DP\n\n !**********************************************\n ! 5-Point Gaussian Quadrature\n !**********************************************\n\n xG5(1) = - SQRT( 245.0_DP + 14.0_DP * SQRT( 70.0_DP ) ) / 21.0_DP / 2.0_DP\n xG5(2) = - SQRT( 245.0_DP - 14.0_DP * SQRT( 70.0_DP ) ) / 21.0_DP / 2.0_DP\n xG5(3) = 0.0_DP\n xG5(4) = - xG5(2)\n xG5(5) = - xG5(1)\n\n wG5(1) = ( 322.0_DP - 13.0_DP * SQRT( 70.0_DP ) ) / 900.0_DP / 2.0_DP\n wG5(2) = ( 322.0_DP + 13.0_DP * SQRT( 70.0_DP ) ) / 900.0_DP / 2.0_DP\n wG5(3) = 128.0_DP / 225.0_DP / 2.0_DP\n wG5(4) = wG5(2)\n wG5(5) = wG5(1)\n\n !**********************************************\n ! 1-Point Gauss-Lobatto Quadrature\n !**********************************************\n\n xL1(1) = 0.0_DP\n\n wL1(1) = 1.0_DP\n\n !*************************************************\n ! 2-Point Gauss-Lobatto Quadrature\n !*************************************************\n\n xL2(1) = - 0.5_DP\n xL2(2) = + 0.5_DP\n\n wL2(1) = 0.5_DP\n wL2(2) = 0.5_DP\n\n !*************************************************\n ! 3-Point Gauss-Lobatto Quadrature\n !*************************************************\n\n xL3(1) = - 0.5_DP\n xL3(2) = 0.0_DP\n xL3(3) = 0.5_DP\n\n wL3(1) = 1.0_DP / 6.0_DP\n wL3(2) = 2.0_DP / 3.0_DP\n wL3(3) = 1.0_DP / 6.0_DP\n\n !*************************************************\n ! 4-Point Gauss-Lobatto Quadrature\n !*************************************************\n\n xL4(1) = - 0.5_DP\n xL4(2) = - SQRT( 5.0_DP ) / 10.0_DP\n xL4(3) = SQRT( 5.0_DP ) / 10.0_DP\n xL4(4) = 0.5_DP\n\n wL4(1) = 1.0_DP / 12.0_DP\n wL4(2) = 5.0_DP / 12.0_DP\n wL4(3) = 5.0_DP / 12.0_DP\n wL4(4) = 1.0_DP / 12.0_DP\n\n !*************************************************\n ! 5-Point Gauss-Lobatto Quadrature\n !*************************************************\n\n xL5(1) = - 0.5_DP\n xL5(2) = - SQRT( 21.0_DP ) / 14.0_DP\n xL5(3) = 0.0_DP\n xL5(4) = SQRT( 21.0_DP ) / 14.0_DP\n xL5(5) = 0.5_DP\n\n wL5(1) = 1.0_DP / 20.0_DP\n wL5(2) = 49.0_DP / 180.0_DP\n wL5(3) = 32.0_DP / 90.0_DP\n wL5(4) = 49.0_DP / 180.0_DP\n wL5(5) = 1.0_DP / 20.0_DP\n\n END SUBROUTINE InitializeQuadratures\n\n\n SUBROUTINE GetQuadrature( nQ, xQ, wQ, QuadratureName_Option )\n\n INTEGER, INTENT(in) :: nQ\n REAL(DP), DIMENSION(nQ), INTENT(inout) :: xQ, wQ\n CHARACTER(LEN=*), INTENT(in), OPTIONAL :: QuadratureName_Option\n\n CHARACTER(32) :: QuadratureName\n\n CALL InitializeQuadratures\n\n IF( PRESENT( QuadratureName_Option ) )THEN\n QuadratureName = TRIM( QuadratureName_Option )\n ELSE\n QuadratureName = 'Gaussian'\n END IF\n\n SELECT CASE ( TRIM( QuadratureName ) )\n CASE ( 'Gaussian' )\n SELECT CASE ( nQ )\n CASE ( 1 )\n xQ = xG1; wQ = wG1\n CASE ( 2 )\n xQ = xG2; wQ = wG2\n CASE ( 3 )\n xQ = xG3; wQ = wG3\n CASE ( 4 )\n xQ = xG4; wQ = wG4\n CASE ( 5 )\n xQ = xG5; wQ = wG5\n CASE DEFAULT\n WRITE(*,*)\n WRITE(*,'(A5,A45,I2.2)') &\n '', 'Gaussian Quadrature Not Implemented for nQ = ', nQ\n STOP\n END SELECT\n CASE ( 'Lobatto' )\n SELECT CASE ( nQ )\n CASE ( 1 )\n xQ = xL1; wQ = wL1\n CASE ( 2 )\n xQ = xL2; wQ = wL2\n CASE ( 3 )\n xQ = xL3; wQ = wL3\n CASE ( 4 )\n xQ = xL4; wQ = wL4\n CASE ( 5 )\n xQ = xL5; wQ = wL5\n CASE DEFAULT\n WRITE(*,*)\n WRITE(*,'(A5,A44,I2.2)') &\n '', 'Lobatto Quadrature Not Implemented for nQ = ', nQ\n STOP\n END SELECT\n CASE DEFAULT\n WRITE(*,*)\n WRITE(*,'(A5,A28,A)') &\n '', 'Quadrature Not Implemented: ', TRIM( QuadratureName )\n END SELECT\n\n END SUBROUTINE GetQuadrature\n\n\nEND MODULE QuadratureModule\n", "meta": {"hexsha": "d828e5c2699900c59c5e620f2645b915dd6abf22", "size": 6269, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Modules/Library/QuadratureModule.f90", "max_stars_repo_name": "srichers/thornado", "max_stars_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-12-08T16:16:55.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-24T19:31:21.000Z", "max_issues_repo_path": "Modules/Library/QuadratureModule.f90", "max_issues_repo_name": "srichers/thornado", "max_issues_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2019-07-10T20:13:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-11T13:21:00.000Z", "max_forks_repo_path": "Modules/Library/QuadratureModule.f90", "max_forks_repo_name": "srichers/thornado", "max_forks_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2018-11-14T01:13:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T02:08:20.000Z", "avg_line_length": 28.7568807339, "max_line_length": 78, "alphanum_fraction": 0.4372308183, "num_tokens": 2509, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929799, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7643846915984828}} {"text": "cc Copyright (C) 2009: Zydrunas Gimbutas and Hong Xiao\ncc Contact: Zydrunas Gimbutas \ncc Hong Xiao \ncc \ncc This software is being released under a modified FreeBSD license\ncc (see COPYING in home directory). \nccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc\nc \nc D_4 symmetric quadratures for smooth functions on a square\nc\nc All weights are positive and inside the square\nc\nc Input:\nc\nc n - the degree of the quadrature (must not exceed 21)\nc\nc Output:\nc\nc fort.11 - quadrature nodes and weights\nc fort.12 - quadrature nodes in gnuplot compatible format\nc fort.14 - square as contructed in gnuplot compatible format\nc \nc in gnuplot:\nc\nc plot 'fort.14' w l, 'fort.12'\nc\nc\nc\n implicit real *8 (a-h,o-z)\n real *8 rnodes(2,1000),weights(1000)\n real *8 rints(1000),z(2),pols(1000)\n real *8 work(100000)\nc\nc\n call prini(6,13)\nc\nc SET ALL PARAMETERS\nc\n PRINT *, 'ENTER mmax (1..21)'\n READ *, mmax\nc\n call prinf('mmax=*',mmax,1)\nc\nc\n\nc\nc ... retrieve the quadrature rule \nc\n call squaresymq(mmax,rnodes,weights,numnodes)\nc\n call prinf('nummodes=*',numnodes,1)\n call prin2('rnodes=*',rnodes,2*numnodes) \n call prin2('weights=*',weights,numnodes) \nc\n d=0\n do i=1,numnodes\n d=d+weights(i)\n enddo\nc\n call prin2('sum of weights=*',d,1)\nc \nc ... plot the square\nc\n write(14,*) -1,-1\n write(14,*) +1,-1\n write(14,*) +1,+1\n write(14,*) -1,+1\n write(14,*) -1,-1\n write(14,*)\nc\nc\nc ... dump the nodes into a file\nc \n write(11,*) numnodes\n do i=1,numnodes\n write(11,1020) rnodes(1,i),rnodes(2,i),weights(i)\n write(12,*) rnodes(1,i),rnodes(2,i)\n enddo\n 1010 format(i2)\n 1020 format(4(e21.15,2x))\nc\n\nc\nc construct the matrix of values of the orthogonal polynomials\nc at the user-provided nodes \nc\n npols=(mmax+1)*(mmax+2)/2\nc\nc\n do 1200 j=1,npols\n rints(j)=0\n 1200 continue\nc\nc\n do 2400 i=1,numnodes\nc\n z(1)=rnodes(1,i)\n z(2)=rnodes(2,i)\nc \n call lege2eva(mmax,z,pols,work)\nc\n do 2200 j=1,npols\nc\n rints(j)=rints(j)+weights(i)*pols(j)\n\n 2200 continue\n\n 2400 continue\nc\nc\n call prin2('rints=*',rints,npols)\nc\n area=4.0d0\nc\n d=0\n d=(rints(1)-sqrt(area))**2\n do i=2,npols\n d=d+rints(i)**2\n enddo\nc\n d=sqrt(d)/npols\nc\n call prin2('error=*',d,1)\nc\n stop\n end\nc\nc\nc\n", "meta": {"hexsha": "1eb7ec1aef1a9aac1da5dc60b5d5f90e1244a931", "size": 2706, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "squaresymq_dr.f", "max_stars_repo_name": "zgimbutas/triasymq", "max_stars_repo_head_hexsha": "940a83c2f3cbbc0295fb87f0a4d411b9435c6678", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-12-16T15:55:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T00:06:27.000Z", "max_issues_repo_path": "squaresymq_dr.f", "max_issues_repo_name": "zgimbutas/triasymq", "max_issues_repo_head_hexsha": "940a83c2f3cbbc0295fb87f0a4d411b9435c6678", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "squaresymq_dr.f", "max_forks_repo_name": "zgimbutas/triasymq", "max_forks_repo_head_hexsha": "940a83c2f3cbbc0295fb87f0a4d411b9435c6678", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.6564885496, "max_line_length": 75, "alphanum_fraction": 0.571322986, "num_tokens": 923, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425333801888, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7643545039034791}} {"text": "program test_ieee_arithmetic\r\nuse, intrinsic :: ieee_arithmetic\r\nimplicit none\r\ncharacter (len=20) :: fmt = \"(a16,*(l9))\"\r\ninteger, parameter :: wp = kind(1.0) ! same output for wp = kind(1.0d0)\r\nreal(kind=wp) :: z,vec(6),NaN,t\r\nz = 0.0_wp\r\nt = tiny(z)\r\nvec = [z/z,z/1.0_wp,-z/1.0_wp,1.0_wp/z,-1.0_wp/z,t/10]\r\nprint*,ieee_value(0.0,ieee_positive_inf),1.0/z ! 2 ways of geting +Inf\r\nNaN = ieee_value(0.0,ieee_quiet_nan) ! get NaN\r\nprint*,\"NaN == NaN?\",NaN == NaN ! demonstrate that NaN /= NaN\r\nprint*\r\nprint \"(19x,*(a9))\",\"0.0/0.0\",\"0.0/1.0\",\"-0.0/1.0\",\"1.0/0.0\",\"-1.0/0.0\",\"tiny/10\"\r\nprint fmt,\"ieee_is_nan\" ,ieee_is_nan(vec)\r\nprint fmt,\"ieee_is_negative\",ieee_is_negative(vec)\r\nprint fmt,\"ieee_is_finite\" ,ieee_is_finite(vec)\r\nprint fmt,\"ieee_is_normal\" ,ieee_is_normal(vec) \r\nend program test_ieee_arithmetic\r\n! gfortran output:\r\n! Infinity Infinity\r\n! NaN == NaN? F\r\n!\r\n! 0.0/0.0 0.0/1.0 -0.0/1.0 1.0/0.0 -1.0/0.0 tiny/10\r\n! ieee_is_nan T F F F F F\r\n! ieee_is_negative F F T F T F\r\n! ieee_is_finite F T T F F T\r\n! ieee_is_normal F T T F F F\r\n", "meta": {"hexsha": "da6e6848c352936bdd07af83bd2375011fed98a3", "size": 1273, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ieee_arithmetic.f90", "max_stars_repo_name": "awvwgk/FortranTip", "max_stars_repo_head_hexsha": "3810038667e3d5d2ab33c39d4bd0f41870025420", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ieee_arithmetic.f90", "max_issues_repo_name": "awvwgk/FortranTip", "max_issues_repo_head_hexsha": "3810038667e3d5d2ab33c39d4bd0f41870025420", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ieee_arithmetic.f90", "max_forks_repo_name": "awvwgk/FortranTip", "max_forks_repo_head_hexsha": "3810038667e3d5d2ab33c39d4bd0f41870025420", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.8965517241, "max_line_length": 82, "alphanum_fraction": 0.5428122545, "num_tokens": 451, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769414, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.764274737734828}} {"text": "program prod_escalar\n\nimplicit none\n\ninteger:: n, i\nreal, allocatable:: v(:), w(:)\nreal:: pe1, pe2, pe3\n\nprint*, 'Dame o tamano dos vectores'\nread*, n\n\nprint*, 'O orde do sistema e '\nprint*, n\n\nallocate(v(n), w(n))\n\nprint*,\nprint*, 'Introduce o vector v'\nread*, v\n\nprint*, 'O vector v e:'\nprint*, v\n\nprint*,\nprint*, 'Introduce o vector w'\nread*, w\n\nprint*, 'O vector w e:'\nprint*, w\n\npe1 = dot_product(v,w)\n\npe2 = 0\ndo i=1,n\n pe2 = pe2 + v(i)*w(i)\nend do\n\npe3 = sum(v*w)\n\nprint*, \nprint*, 'Produto escalar 1: ', pe1\nprint*, 'Produto escalar 2: ', pe2\nprint*, 'Produto escalar 3: ', pe3\n\nend program\n", "meta": {"hexsha": "372ef5ab532cae6b277bfe060e17b704be431da6", "size": 600, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Practica1_dotproduct/prod_esc_vec.f95", "max_stars_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_stars_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-04-02T18:09:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-16T14:08:07.000Z", "max_issues_repo_path": "Practica1_dotproduct/prod_esc_vec.f95", "max_issues_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_issues_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practica1_dotproduct/prod_esc_vec.f95", "max_forks_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_forks_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-04-05T13:18:12.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-04T10:32:14.000Z", "avg_line_length": 13.0434782609, "max_line_length": 36, "alphanum_fraction": 0.6266666667, "num_tokens": 217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645895, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7642167855417054}} {"text": "\nfunction compute_pi(segments)\n implicit none\n\n integer, intent(in) :: segments\n real*8 :: compute_pi\n\n real*8 :: polygon_edge_length_squared\n integer :: polygon_sides\n integer :: i\n\n polygon_edge_length_squared = 2.0\n polygon_sides = 2\n do i = 1, segments\n polygon_edge_length_squared = -sqrt(1 - polygon_edge_length_squared / 4) * 2 + 2\n polygon_sides = polygon_sides * 2\n end do\n compute_pi = sqrt(polygon_edge_length_squared) * polygon_sides\n return\nend function\n", "meta": {"hexsha": "60e19edddcd386616b6c28ac3c834e314fd6be32", "size": 485, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/examples/f95/compute_pi.f90", "max_stars_repo_name": "EraYaN/transpyle", "max_stars_repo_head_hexsha": "e7f5a021e7e6ab13fc21906b5a785dd24606cccc", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 107, "max_stars_repo_stars_event_min_datetime": "2018-01-12T05:19:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T20:56:52.000Z", "max_issues_repo_path": "test/examples/f95/compute_pi.f90", "max_issues_repo_name": "EraYaN/transpyle", "max_issues_repo_head_hexsha": "e7f5a021e7e6ab13fc21906b5a785dd24606cccc", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2018-01-24T08:08:12.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-29T23:36:11.000Z", "max_forks_repo_path": "test/examples/f95/compute_pi.f90", "max_forks_repo_name": "EraYaN/transpyle", "max_forks_repo_head_hexsha": "e7f5a021e7e6ab13fc21906b5a785dd24606cccc", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 20, "max_forks_repo_forks_event_min_datetime": "2018-12-05T13:21:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-11T11:48:33.000Z", "avg_line_length": 23.0952380952, "max_line_length": 84, "alphanum_fraction": 0.7340206186, "num_tokens": 142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7641758006966186}} {"text": "!===============================================================================\nprogram spherical_mean\n!===============================================================================\n! Reads in (lon, colat) angles from stdin and computes the mean direction.\n! Input and output in degrees\n\nuse statistical\n\nimplicit none\n\ninteger, parameter :: rs = 8\ninteger, parameter :: nmax = 100000\nreal(rs), parameter :: pi = 4._rs*atan2(1._rs, 1._rs)\nreal(rs), parameter :: rad = pi/180._rs, deg = 180._rs/pi\nreal(rs), dimension(nmax) :: lon, colat\nreal(rs), allocatable, dimension(:) :: x, y, z\nreal(rs) :: mean(3), meanlon, meancolat\ninteger :: n, i, iostat = 0\n\ni = 1\ndo while (iostat == 0)\n read(*,*,iostat=iostat) lon(i), colat(i)\n if (iostat < 0) then\n n = i - 1\n exit\n else if (iostat > 0) then\n write(0,'(a)') 'sph_mean: Problem reading lon,colat from stdin'\n stop\n endif\n if (colat(i) < 0._rs .or. colat(i) > 180._rs) then\n write(0,'(a)') 'sph_mean: Error: colat is outside range (0, 180) degrees'\n stop\n endif\n i = i + 1\n if (i > nmax) then\n write(0,'(a,i0)') 'sph_mean: Reached compiled nmax limit of ',nmax\n write(0,'(a)') 'Skipping remaining points...'\n endif\nenddo\n\nwrite(*,'(a,i0,a)') 'Got ',n,' pairs from stdin'\n\nallocate(x(n), y(n), z(n))\n\n! Convert to x,y,z\nlon(1:n) = rad*lon(1:n)\ncolat(1:n) = rad*colat(1:n)\nx(1:n) = sin(colat(1:n))*cos(lon(1:n))\ny(1:n) = sin(colat(1:n))*sin(lon(1:n))\nz(1:n) = cos(colat(1:n))\n\nmean = sph_mean(x, y, z)\n\n! Convert back to lon, colat\nmeancolat = deg*acos(mean(3))\nmeanlon = deg*atan2(mean(2),mean(1))\n\nwrite(*,*) meanlon, meancolat\n\nend program spherical_mean\n!-------------------------------------------------------------------------------", "meta": {"hexsha": "462c0033de659fb4b6ccc51608748a4e7ff6c730", "size": 1743, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test_statistical/sph_mean.f90", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "test_statistical/sph_mean.f90", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "test_statistical/sph_mean.f90", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 28.5737704918, "max_line_length": 80, "alphanum_fraction": 0.5341365462, "num_tokens": 569, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404018582427, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7641757958758008}} {"text": "C monte carlo estimate Pi\nC always double precision for R \nC compile using R CMD SHLIB mc_pi_r.f\nC23456789\n subroutine mc_pi_r(pi)\n double precision pi\n k = 0\n do 10 i=1,1000000\n x = rand()\n y = rand()\n if(x**2 + y**2 .lt. 1.0) k=k+1\n 10 continue\n pi = real(k) / 1000000 * 4\n end subroutine mc_pi_r\n", "meta": {"hexsha": "169ae8934c649490bb03f7c0078ad1e509b9017c", "size": 368, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mc_pi_r.f", "max_stars_repo_name": "MikeXL/Quest-of-FORTRAN", "max_stars_repo_head_hexsha": "fe9c71f36964adf7fb6b2434da91b7ffee0aae31", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mc_pi_r.f", "max_issues_repo_name": "MikeXL/Quest-of-FORTRAN", "max_issues_repo_head_hexsha": "fe9c71f36964adf7fb6b2434da91b7ffee0aae31", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-10T20:47:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-10T20:47:52.000Z", "max_forks_repo_path": "mc_pi_r.f", "max_forks_repo_name": "MikeXL/Quest-of-FORTRAN", "max_forks_repo_head_hexsha": "fe9c71f36964adf7fb6b2434da91b7ffee0aae31", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.5333333333, "max_line_length": 40, "alphanum_fraction": 0.5570652174, "num_tokens": 121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611631680357, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.7641191384607201}} {"text": "SUBROUTINE eta_nonlinear_3D(k,angle,x,y,omega,time,n_four_modes,yy,eta,etax,etay,etaxx,etayy,etat)\n!\n! By Allan P. Engsig-Karup.\nUSE Precision\nUSE Constants\nIMPLICIT NONE\nINTEGER :: n_four_modes\nREAL(KIND=long), INTENT(IN) :: k,angle,x,y,omega,time,yy(n_four_modes)\nREAL(KIND=long), INTENT(OUT) :: eta,etax,etay\nREAL(KIND=long), INTENT(OUT) :: etaxx,etayy,etat\n! REAL(KIND=long), OPTIONAL :: y,etay,etayy !Boundary fitted ?\n! Local variables\nREAL(KIND=long) :: kx, ky, k_omegat, cosk_omegat, sink_omegat, km\nINTEGER :: m\n!\n!\nkx=cos(angle)\nky=sin(angle)\n!\n!kx = k*x-omega*time\nk_omegat=kx*k*x+ky*k*y-omega*time\nkm=DBLE(n_four_modes)\ncosk_omegat=half*yy(n_four_modes)*cos(km*k_omegat)\nsink_omegat=half*yy(n_four_modes)*sin(km*k_omegat)\n!\neta = cosk_omegat\n!\netax = -km*kx*sink_omegat\netaxx = -(km*kx)**2*cosk_omegat\netay = -km*ky*sink_omegat\netayy = -(km*ky)**2*cosk_omegat\n!\netat = omega*km*sink_omegat\n!FIXME optimizaton of loops (GD)\nDO m=1,n_four_modes-1\n km=DBLE(m)\n cosk_omegat=yy(m)*cos(km*k_omegat)\n sink_omegat=yy(m)*sin(km*k_omegat)\n ! Non-dimensional eta and derivatives\n eta = eta + cosk_omegat\n !\n etax = etax - km*kx*sink_omegat\n etaxx= etaxx - (km*kx)**2*cosk_omegat\n etay = etay - km*ky*sink_omegat\n etayy= etayy - (km*ky)**2*cosk_omegat\n !\n etat = etat + omega*km*sink_omegat\nENDDO\n\nEND SUBROUTINE eta_nonlinear_3D\n", "meta": {"hexsha": "ff23beaa42349c8e37b7d5d7c6634b2e1046a2f2", "size": 1370, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/functions/eta_nonlinear_3D.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/functions/eta_nonlinear_3D.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/functions/eta_nonlinear_3D.f90", "max_forks_repo_name": "apengsigkarup/OceanWave3D", "max_forks_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-01T12:17:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T16:23:37.000Z", "avg_line_length": 26.862745098, "max_line_length": 98, "alphanum_fraction": 0.7102189781, "num_tokens": 588, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778048911612, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7640864795943333}} {"text": "C***BEGIN PROLOGUE DWEB\nC***REFER TO DDASPK\nC***DATE WRITTEN 950914 (YYMMDD)\nC\nC***AUTHORS A. C. Hindmarsh, P. N. Brown\nC Lawrence Livermore National Laboratory\nC L-316, P.O. Box 808\nC Livermore, CA 94551, USA\nC\nC***DESCRIPTION\nC\nC-----------------------------------------------------------------------\nC Example program for DDASPK.\nC DAE system derived from ns-species interaction PDE in 2 dimensions.\nC\nC This is the double precision version.\nC-----------------------------------------------------------------------\nC\nC This program solves a DAE system that arises from a system\nC of partial differential equations. The PDE system is a food web\nC population model, with predator-prey interaction and diffusion on\nC the unit square in two dimensions. The dependent variable vector is\nC\nC 1 2 ns\nC c = (c , c , ..., c )\nC\nC and the PDEs are as follows..\nC\nC i i i\nC dc /dt = d(i)*(c + c ) + R (x,y,c) (i=1,...,ns/2)\nC xx yy i\nC\nC i i\nC 0 = d(i)*(c + c ) + R (x,y,c) (i=(ns/2)+1,...,ns)\nC xx yy i\nC\nC where\nC i ns j\nC R (x,y,c) = c *(b(i) + sum a(i,j)*c )\nC i j=1\nC\nC The number of species is ns = 2*np, with the first np being prey and\nC the last np being predators. The coefficients a(i,j), b(i), d(i) are\nC\nC a(i,i) = -a (all i)\nC a(i,j) = -g (i .le. np, j .gt. np)\nC a(i,j) = e (i .gt. np, j .le. np)\nC b(i) = b*(1 + alpha*x*y + beta*sin(4*pi*x)*sin(4*pi*y)) (i .le. np)\nC b(i) = -b*(1 + alpha*x*y + beta*sin(4*pi*x)*sin(4*pi*y)) (i .gt. np)\nC d(i) = dprey (i .le. np)\nC d(i) = dpred (i .gt. np)\nC\nC The various scalar parameters are set in subroutine setpar.\nC\nC The boundary conditions are.. normal derivative = 0.\nC A polynomial in x and y is used to set the initial conditions.\nC\nC The PDEs are discretized by central differencing on a MX by MY mesh.\nC\nC The DAE system is solved by DDASPK with three different method options:\nC (1) direct band method for the linear systems (internal Jacobian),\nC (2) preconditioned Krylov method for the linear systems, without\nC block-grouping in the reaction-based factor, and\nC (3) preconditioned Krylov method for the linear systems, with\nC block-grouping in the reaction-based factor.\nC\nC In the Krylov cases, the preconditioner is the product of two factors:\nC (a) The spatial factor uses a fixed number of Gauss-Seidel iterations\nC based on the diffusion terms only.\nC (b) The reaction-based factor is a block-diagonal matrix based on\nC the partial derivatives of the interaction terms R only.\nC With block-grouping, only a subset of the ns by ns blocks are computed.\nC An integer flag, JPRE, is set in the main program to specify whether\nC the preconditioner is to use only one of the two factors or both,\nC and in which order.\nC\nC The reaction-based preconditioner factor is set up and solved in\nC seven subroutines -- \nC DMSET2, DRBDJA, DRBDPS in the case of no block-grouping, and\nC DGSET2, GSET1, DRBGJA, DRBGPS in the case of block-grouping.\nC These routines are provided separately for general use on problems\nC arising from reaction-transport systems.\nC\nC Two output files are written.. one with the problem description and\nC performance statistics on unit LOUT = 9, and one with solution \nC profiles at selected output times on unit LCOUT = 10.\nC The solution file is written only in the case of the direct method.\nC-----------------------------------------------------------------------\nC Note.. in addition to the main program and subroutines given below,\nC this program requires the BLAS routine DAXPY.\nC-----------------------------------------------------------------------\nC References\nC [1] Peter N. Brown and Alan C. Hindmarsh,\nC Reduced Storage Matrix Methods in Stiff ODE Systems,\nC J. Appl. Math. & Comp., 31 (1989), pp. 40-91.\nC [2] Peter N. Brown, Alan C. Hindmarsh, and Linda R. Petzold,\nC Using Krylov Methods in the Solution of Large-Scale Differential-\nC Algebraic Systems, SIAM J. Sci. Comput., 15 (1994), pp. 1467-1488.\nC [3] Peter N. Brown, Alan C. Hindmarsh, and Linda R. Petzold,\nC Consistent Initial Condition Calculation for Differential-\nC Algebraic Systems, LLNL Report UCRL-JC-122175, August 1995;\nC submitted to SIAM J. Sci. Comp.\nC-----------------------------------------------------------------------\nC***ROUTINES CALLED\nC SETPAR, DGSET2, CINIT, DDASPK, OUTWEB\nC\nC***END PROLOGUE DWEB\nC\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n EXTERNAL RESWEB, JACRS, PSOLRS\nC\nC Set output unit numbers for main output and tabulated solution.\n DATA LOUT/9/, LCOUT/10/\nC\nC Dimension solution arrays and work arrays.\nC\nC When INFO(12) = 0, with INFO(5) = 0, INFO(6) = 1:\nC The length required for RWORK is\nC 50 + (2*ML+MU+11)*NEQ + 2*(NEQ/(ML+MU+1) + 1) .\nC For MX = MY = (even number) and ML = MU = NS*MX, this length is\nC 50 + (3*NS*MX + 11)*NEQ + MY .\nC The length required for IWORK is 40 + 2*NEQ .\nC\nC When INFO(12) = 1:\nC The length required for RWORK is \nC 91 + 19*NEQ + LENWP = 91 + 19*NEQ + NS*NS*NGRP .\nC The length required for IWORK is\nC 40 + NEQ + LENIWP = 40 + NEQ + NS*NGRP .\nC\nC The dimensions for the various arrays are set below using parameters\nC MAXN which must be .ge. NEQ = NS*MX*MY,\nC MAXS which must be .ge. NS,\nC MAXM which must be .ge. MAX(MX,MY).\nC\n PARAMETER (MAXS = 2, MAXM = 20, MAXN = 800,\n 1 LRW = 50 + (3*MAXS*MAXM + 11)*MAXN + MAXM,\n 2 LIW = 40 + 2*MAXN)\nC\n DIMENSION CC(MAXN), CCPRIME(MAXN), RWORK(LRW), IWORK(LIW),\n 1 INFO(20), RPAR(MAXN), IPAR(2)\nC\nC The COMMON blocks /PPAR1/ and /PPAR2/ contain problem parameters.\nC\n COMMON /PPAR1/ AA, EE, GG, BB, DPREY, DPRED\n COMMON /PPAR2/ NP, NS, AX, AY, ACOEF(MAXS,MAXS), BCOEF(MAXS),\n 1 DX, DY, ALPH, BETA, FPI, DIFF(MAXS),\n 2 COX(MAXS), COY(MAXS), MX, MY, MXNS\nC\nC Open output files.\n OPEN(UNIT=LOUT,FILE='wdout',STATUS='unknown')\n OPEN(UNIT=LCOUT,FILE='wccout',STATUS='unknown')\nC\nC Call SETPAR to set basic problem parameters.\n CALL SETPAR\nC\nC Set remaining problem parameters.\n NEQ = NS*MX*MY\n MXNS = MX*NS\n DX = AX/REAL(MX-1)\n DY = AY/REAL(MY-1)\n DO 10 I = 1,NS\n COX(I) = DIFF(I)/DX**2\n 10 COY(I) = DIFF(I)/DY**2\nC\n WRITE(LOUT,20)NS\n 20 FORMAT(//' Example program for DDASPK package'//\n 1 ' Food web problem with NS species, NS =',I4/\n 2 ' Predator-prey interaction and diffusion on a 2-D square'/)\n WRITE(LOUT,30) AA,EE,GG,BB,DPREY,DPRED, ALPH,BETA\n 30 FORMAT(' Matrix parameters.. a =',E12.4,' e =',E12.4,\n 1 ' g =',E12.4/21x,' b parameter =',E12.4//\n 2 ' Diffusion coefficients.. dprey =',E12.4,' dpred =',E12.4//\n 3 ' Rate parameters alpha =',E12.4,' and beta =',E12.4/)\n WRITE(LOUT,40) MX,MY,NEQ\n 40 FORMAT(' Mesh dimensions (MX,MY) =',2I4,\n 1 5x,' Total system size is NEQ =',I7/)\nC\nC Here set the flat initial guess for the predators.\n PREDIC = 1.0D5\nC\nC Set remaining method parameters for DDASPK.\nC These include the INFO array and tolerances.\nC \n DO 50 I = 1,20\n 50 INFO(I) = 0\nC\nC Here set INFO(11) = 1, indicating I.C. calculation requested.\n INFO(11) = 1\nC\nC Here set INFO(14) = 1 to get the computed initial values.\n INFO(14) = 1\nC\nC Here set INFO(15) = 1 to signal that a preconditioner setup routine\nC is to be called in the Krylov case.\n INFO(15) = 1\nC\nC Here set INFO(16) = 1 to get alternative error test (on the\nC differential variables only).\n INFO(16) = 1\nC\nC Here set the tolerances.\n RTOL = 1.0D-5\n ATOL = RTOL\nC\n WRITE(LOUT,70)RTOL,ATOL,INFO(11),PREDIC,INFO(16)\n 70 FORMAT(' Tolerance parameters.. RTOL =',E10.2,' ATOL =',E10.2//\n 1 ' Internal I.C. calculation flag INFO(11) =',I2,\n 2 ' (0 = off, 1 = on)'/\n 3 ' Predator I.C. guess =',E10.2//\n 4 ' Alternate error test flag INFO(16) =',I2,\n 5 ' (0 = off, 1 = on)')\nC\nC Set NOUT = number of output times.\n NOUT = 18\nC\nC Loop over method options: \nC METH = 0 means use INFO(12) = 0 (direct)\nC METH = 1 means use INFO(12) = 1 (Krylov) without block-grouping in\nC the reaction-based factor in the preconditioner.\nC METH = 2 means use INFO(12) = 1 (Krylov) with block-grouping in\nC the reaction-based factor in the preconditioner.\nC A block-grouping flag JBG, communicated through IPAR, is set to\nC 0 (no block-grouping) or 1 (use block-grouping) with METH = 1 or 2.\nC Reset INFO(1) = 0 and INFO(11) = 1.\nC\n DO 300 METH = 0,2\n INFO(12) = MIN(METH,1)\n INFO(1) = 0\n INFO(11) = 1\n JBG = METH - 1\n IPAR(2) = JBG\nC\n WRITE(LOUT,80)INFO(12)\n 80 FORMAT(//80('.')//\n 1 ' Linear solver method flag INFO(12) =',I2,\n 2 ' (0 = direct, 1 = Krylov)'/)\nC\nC In the case of the direct method, set INFO(6) = 1 to signal a banded \nC Jacobian, set IWORK(1) = IWORK(2) = MX*NS, the half-bandwidth, and\nC call SETID to set the IWORK segment ID indicating the differential\nC and algebraic components.\n IF (INFO(12) .EQ. 0) THEN\n INFO(6) = 1\n IWORK(1) = MXNS\n IWORK(2) = MXNS\n CALL SETID (MX, MY, NS, NP, 40, IWORK)\n WRITE(LOUT,90)MXNS\n 90 FORMAT(' Difference-quotient banded Jacobian,'\n 1 ' half-bandwidths =',I4)\n ENDIF\nC\nC In the case of the Krylov method, set and print various\nC preconditioner parameters.\n IF (INFO(12) .EQ. 1) THEN\nC First set the preconditioner choice JPRE.\nC JPRE = 1 means reaction-only (block-diagonal) factor A_R\nC JPRE = 2 means spatial factor (Gauss-Seidel) A_S\nC JPRE = 3 means A_S * A_R\nC JPRE = 4 means A_R * A_S\nC Use IPAR to communicate JPRE to the preconditioner solve routine.\n JPRE = 3\n IPAR(1) = JPRE\n WRITE(LOUT,100)JPRE\n 100 FORMAT(' Preconditioner flag is JPRE =',I3/\n 1 ' (1 = reaction factor A_R, 2 = spatial factor A_S,',\n 2 ' 3 = A_S*A_R, 4 = A_R*A_S )'/)\nC Here call DMSET2 if JBG = 0, or DGSET2 if JBG = 1, to set the 2-D\nC mesh parameters and block-grouping data, and the IWORK segment ID\nC indicating the differential and algebraic components.\n IF (JBG .EQ. 0) THEN\n CALL DMSET2 (MX, MY, NS, NP, 40, IWORK)\n WRITE(LOUT,110)\n 110 FORMAT(' No block-grouping in reaction factor')\n ENDIF\n IF (JBG .EQ. 1) THEN\n NXG = 5\n NYG = 5\n NG = NXG*NYG\n CALL DGSET2 (MX, MY, NS, NP, NXG, NYG, 40, IWORK)\n WRITE(LOUT,120)NG,NXG,NYG\n 120 FORMAT(' Block-grouping in reaction factor'/\n 1 ' Number of groups =',I5,\n 2 ' (NGX by NGY, NGX =',I3,', NGY =',I3,')')\n ENDIF\n ENDIF\nC\nC Set the initial T and TOUT, and call CINIT to set initial values.\n T = 0.0D0\n TOUT = 1.0D-8\n CALL CINIT (CC, CCPRIME, PREDIC, RPAR)\nC\n NLI = 0\n NNI = 0\nC\n WRITE(LOUT,140)\n 140 FORMAT(//' t',7X,'NSTEP NRE NNI NLI NPE NQ',4X,\n 1 'H',10X,'AVLIN')\nC\nC Loop over output times, call DDASPK, and print performance data.\nC The first call, with IOUT = 0, is to calculate initial values only.\nC After the first call, reset INFO(11) = 0 and the initial TOUT.\nC\n DO 200 IOUT = 0,NOUT\nC\n CALL DDASPK (RESWEB, NEQ, T, CC, CCPRIME, TOUT, INFO, RTOL, ATOL,\n 1 IDID, RWORK,LRW, IWORK,LIW, RPAR, IPAR, JACRS, PSOLRS)\nC\n NST = IWORK(11)\n NRE = IWORK(12)\n NPE = IWORK(13)\n NNIDIF = IWORK(19) - NNI\n NNI = IWORK(19)\n NLIDIF = IWORK(20) - NLI\n NLI = IWORK(20)\n NQU = IWORK(8)\n HU = RWORK(7)\n AVLIN = 0.0D0\n IF (NNIDIF .GT. 0) AVLIN = REAL(NLIDIF)/REAL(NNIDIF)\nC\n IF (METH .EQ. 0) THEN\n IMOD3 = IOUT - 3*(IOUT/3)\n IF (IMOD3 .EQ. 0) CALL OUTWEB (T, CC, NS, MX, MY, LCOUT)\n ENDIF\nC\n WRITE(LOUT,150)T,NST,NRE,NNI,NLI,NPE,NQU,HU,AVLIN\n 150 FORMAT(E10.2,I5,I6,3I5,I4,E11.2,F9.4)\nC\n IF (IDID .LT. 0) THEN\n WRITE(LOUT,160)T\n 160 FORMAT(//' Final time reached =',E12.4//)\n GO TO 210\n ENDIF\nC\n IF (TOUT .GT. 0.9D0) TOUT = TOUT + 1.0D0\n IF (TOUT .LT. 0.9D0) TOUT = TOUT*10.0D0\n IF (IOUT .EQ. 0) THEN\n INFO(11) = 0\n TOUT = 1.0D-8\n NLI = 0\n NNI = 0\n ENDIF\n 200 CONTINUE\nC\n 210 CONTINUE\n LENRW = IWORK(18)\n LENIW = IWORK(17)\n NST = IWORK(11)\n NRE = IWORK(12)\n NPE = IWORK(13)\n NNI = IWORK(19)\n NLI = IWORK(20)\n NPS = IWORK(21)\n IF (NNI .GT. 0) AVLIN = REAL(NLI)/REAL(NNI)\n NCFN = IWORK(15)\n NCFL = IWORK(16)\n WRITE(LOUT,220) LENRW,LENIW,NST,NRE,NPE,NPS,NNI,NLI,AVLIN,\n 1 NCFN,NCFL\n 220 FORMAT(//' Final statistics for this run..'/\n 1 ' RWORK size =',I8,' IWORK size =',I6/\n 2 ' Number of time steps =',I5/\n 3 ' Number of residual evaluations =',I5/\n 4 ' Number of Jac. or prec. evals. =',I5/\n 5 ' Number of preconditioner solves =',I5/\n 6 ' Number of nonlinear iterations =',I5/\n 7 ' Number of linear iterations =',I5/\n 8 ' Average Krylov subspace dimension =',F8.4/\n 9 I3,' nonlinear conv. failures,',i5,' linear conv. failures')\nC\n 300 CONTINUE\n\n STOP\nC------ End of main program for DWEB example program ------------------\n END\n\n SUBROUTINE SETPAR\nC-----------------------------------------------------------------------\nC This routine sets the basic problem parameters, namely\nC AX, AY, NS, MX, MY, problem coefficients ACOEF, BCOEF, DIFF,\nC ALPH, BETA, using parameters NP, AA, EE, GG, BB, DPREY, DPRED.\nC-----------------------------------------------------------------------\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n PARAMETER (MAXS = 2)\n COMMON /PPAR1/ AA, EE, GG, BB, DPREY, DPRED\n COMMON /PPAR2/ NP, NS, AX, AY, ACOEF(MAXS,MAXS), BCOEF(MAXS),\n 1 DX, DY, ALPH, BETA, FPI, DIFF(MAXS),\n 2 COX(MAXS), COY(MAXS), MX, MY, MXNS\nC\n AX = 1.0D0\n AY = 1.0D0\n NP = 1\n MX = 20\n MY = 20\n AA = 1.0D0\n EE = 1.0D4\n GG = 0.5D-6\n BB = 1.0D0\n DPREY = 1.0D0\n DPRED = 0.05D0\n ALPH = 50.0D0\n BETA = 100.0D0\n NS = 2*NP\n DO 20 J = 1,NP\n DO 10 I = 1,NP\n ACOEF(NP+I,J) = EE\n ACOEF(I,NP+J) = -GG\n 10 CONTINUE\n ACOEF(J,J) = -AA\n ACOEF(NP+J,NP+J) = -AA\n BCOEF(J) = BB\n BCOEF(NP+J) = -BB\n DIFF(J) = DPREY\n DIFF(NP+J) = DPRED\n 20 CONTINUE\n PI = 3.141592653589793D0\n FPI = 4.0D0*PI\nC\n RETURN\nC------------ End of Subroutine SETPAR -------------------------------\n END\n\n SUBROUTINE SETID (MX, MY, NS, NSD, LID, IWORK)\nC-----------------------------------------------------------------------\nC This routine sets the ID array in IWORK, indicating which components\nC are differential and which are algebraic.\nC-----------------------------------------------------------------------\n DIMENSION IWORK(*)\nC\n NSDP1 = NSD + 1\n DO 40 JY = 1,MY\n I00 = MX*NS*(JY-1) + LID\n DO 30 JX = 1,MX\n I0 = I00 + NS*(JX-1) \n DO 10 I = 1,NSD\n 10 IWORK(I0+I) = 1\n DO 20 I = NSDP1,NS\n 20 IWORK(I0+I) = -1\n 30 CONTINUE\n 40 CONTINUE\nC\n RETURN\nC------------ End of Subroutine SETID --------------------------------\n END\n\n SUBROUTINE CINIT (CC, CCPRIME, PREDIC, RPAR)\nC-----------------------------------------------------------------------\nC This routine computes and loads the vectors of initial values.\nC-----------------------------------------------------------------------\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CC(*), CCPRIME(*), RPAR(*)\n PARAMETER (MAXS = 2)\n COMMON /PPAR2/ NP, NS, AX, AY, ACOEF(MAXS,MAXS), BCOEF(MAXS),\n 1 DX, DY, ALPH, BETA, FPI, DIFF(MAXS),\n 2 COX(MAXS), COY(MAXS), MX, MY, MXNS\nC\nC Load CC.\n NPP1 = NP + 1\n DO 30 JY = 1,MY\n Y = REAL(JY-1)*DY\n ARGY = 16.0D0*Y*Y*(AY-Y)*(AY-Y)\n IYOFF = MXNS*(JY-1)\n DO 20 JX = 1,MX\n X = REAL(JX-1)*DX\n ARGX = 16.0D0*X*X*(AX-X)*(AX-X)\n IOFF = IYOFF + NS*(JX-1)\n FAC = 1.0D0 + ALPH*X*Y + BETA*SIN(FPI*X)*SIN(FPI*Y)\n DO 10 I = 1,NP\n 10 CC(IOFF + I) = 10.0D0 + REAL(I)*ARGX*ARGY\n DO 15 I = NPP1,NS\n 15 CC(IOFF + I) = PREDIC\n 20 CONTINUE\n 30 CONTINUE\nC\nC Load CCPRIME.\n T = 0.0D0\n CALL FWEB (T, CC, CCPRIME, RPAR)\n DO 60 JY = 1,MY\n IYOFF = MXNS*(JY-1)\n DO 50 JX = 1,MX\n IOFF = IYOFF + NS*(JX-1)\n DO 40 I = NPP1,NS\n 40 CCPRIME(IOFF+I) = 0.0D0\n 50 CONTINUE\n 60 CONTINUE\nC\n RETURN\nC------------ End of Subroutine CINIT --------------------------------\n END\n\n SUBROUTINE OUTWEB (T, C, NS, MX, MY, LUN)\nC-----------------------------------------------------------------------\nC This routine prints the values of the individual species densities\nC at the current time T, to logical unit LUN.\nC-----------------------------------------------------------------------\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION C(NS,MX,MY)\nC\n WRITE(LUN,10) T\n 10 FORMAT(/1X,79('-')/30X,'At time t = ',E16.8/1X,79('-') )\nC\n DO 40 I = 1,NS\n WRITE(LUN,20) I\n 20 FORMAT(' the species c(',i2,') values are ')\n DO 30 JY = MY,1,-1\n WRITE(LUN,25) (C(I,JX,JY),JX=1,MX)\n 25 FORMAT(6(1X,G12.6))\n 30 CONTINUE\n WRITE(LUN,35)\n 35 FORMAT(1X,79('-'),/)\n 40 CONTINUE\nC\n RETURN\nC------------ End of Subroutine OUTWEB -------------------------------\n END\n\n SUBROUTINE RESWEB (T, U, UPRIME, CJ, DELTA, IRES, RPAR, IPAR)\nC-----------------------------------------------------------------------\nC This routine computes the residual vector, using Subroutine FWEB\nC for the right-hand sides.\nC-----------------------------------------------------------------------\nC\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION U(*),UPRIME(*),DELTA(*),RPAR(*),IPAR(*)\n PARAMETER (MAXS = 2)\n COMMON /PPAR2/ NP, NS, AX, AY, ACOEF(MAXS,MAXS), BCOEF(MAXS),\n 1 DX, DY, ALPH, BETA, FPI, DIFF(MAXS),\n 2 COX(MAXS), COY(MAXS), MX, MY, MXNS\nC\n CALL FWEB (T, U, DELTA, RPAR)\nC\n DO 30 JY = 1,MY\n IYOFF = MXNS*(JY-1)\n DO 20 JX = 1,MX\n IC0 = IYOFF + NS*(JX-1)\n DO 10 I = 1,NS\n ICI = IC0 + I\n IF (I .GT. NP) THEN\n DELTA(ICI) = -DELTA(ICI)\n ELSE\n DELTA(ICI) = UPRIME(ICI) - DELTA(ICI)\n ENDIF\n 10 CONTINUE\n 20 CONTINUE\n 30 CONTINUE\nC\n RETURN\nC------------ End of Subroutine RESWEB -------------------------------\n END\n\n SUBROUTINE FWEB (T, CC, CRATE, RPAR)\nC-----------------------------------------------------------------------\nC This routine computes the right-hand sides of all the equations\nC and returns them in the array CRATE.\nC The interaction rates are computed by calls to WEBR, and these are\nC saved in RPAR(1),...,RPAR(NEQ) for use later in preconditioning.\nC-----------------------------------------------------------------------\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CC(*), CRATE(*), RPAR(*)\n PARAMETER (MAXS = 2)\n COMMON /PPAR2/ NP, NS, AX, AY, ACOEF(MAXS,MAXS), BCOEF(MAXS),\n 1 DX, DY, ALPH, BETA, FPI, DIFF(MAXS),\n 2 COX(MAXS), COY(MAXS), MX, MY, MXNS\nC\n DO 60 JY = 1,MY\n IYOFF = MXNS*(JY-1)\n IDYU = MXNS\n IF (JY .EQ. MY) IDYU = -MXNS\n IDYL = MXNS\n IF (JY .EQ. 1) IDYL = -MXNS\n DO 40 JX = 1,MX\n IC = IYOFF + NS*(JX-1) + 1\nC Get interaction rates at one point (X,Y).\n CALL WEBR (T, JX, JY, CC(IC), RPAR(IC))\n IDXU = NS\n IF (JX .EQ. MX) IDXU = -NS\n IDXL = NS\n IF (JX .EQ. 1) IDXL = -NS\n DO 20 I = 1,NS\n ICI = IC + I - 1\nC Do differencing in Y.\n DCYLI = CC(ICI) - CC(ICI-IDYL)\n DCYUI = CC(ICI+IDYU) - CC(ICI)\nC Do differencing in X.\n DCXLI = CC(ICI) - CC(ICI-IDXL)\n DCXUI = CC(ICI+IDXU) - CC(ICI)\nC Collect terms and load CRATE elements.\n CRATE(ICI) = COY(I)*(DCYUI - DCYLI) + COX(I)*(DCXUI - DCXLI)\n 1 + RPAR(ICI)\n 20 CONTINUE\n 40 CONTINUE\n 60 CONTINUE\n RETURN\nC------------ End of Subroutine FWEB ---------------------------------\n END\n\n SUBROUTINE WEBR (T, JX, JY, C, CRATE)\nC-----------------------------------------------------------------------\nC This routine computes one block of the interaction term R of the \nC system, namely block (JX,JY), for use in preconditioning.\nC-----------------------------------------------------------------------\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION C(*), CRATE(*)\n PARAMETER (MAXS = 2)\n COMMON /PPAR2/ NP, NS, AX, AY, ACOEF(MAXS,MAXS), BCOEF(MAXS),\n 1 DX, DY, ALPH, BETA, FPI, DIFF(MAXS),\n 2 COX(MAXS), COY(MAXS), MX, MY, MXNS\nC\n Y = REAL(JY-1)*DY\n X = REAL(JX-1)*DX\n DO 10 I = 1,NS\n 10 CRATE(I) = 0.0D0\n DO 15 J = 1,NS\n CALL DAXPY (NS, C(J), ACOEF(1,J), 1, CRATE, 1)\n 15 CONTINUE\n FAC = 1.0D0 + ALPH*X*Y + BETA*SIN(FPI*X)*SIN(FPI*Y)\n DO 20 I = 1,NS\n 20 CRATE(I) = C(I)*(BCOEF(I)*FAC + CRATE(I))\n RETURN\nC------------ End of Subroutine WEBR ---------------------------------\n END\n\n SUBROUTINE JACRS(RES, IRES, NEQ, T, CC, CCPRIME, REWT, SAVR, WK,\n 1 H, CJ, WP, IWP, IER, RPAR, IPAR)\nC-----------------------------------------------------------------------\nC This routine interfaces to Subroutine DRBGJA or Subroutine DRBGJA,\nC depending on the flag JBG = IPAR(2), to generate and preprocess the\nC block-diagonal Jacobian corresponding to the reaction term R.\nC If JBG = 0, we call DRBDJA, with no block-grouping.\nC If JBG = 1, we call DRBGJA, and use block-grouping.\nC Array RPAR, containing the current R vector, is passed to DRBDJA and\nC DRBGJA as argument R0, consistent with the loading of RPAR in FWEB.\nC The external name WEBR is passed, as the routine which computes the\nC individual blocks of the R vector. \nC-----------------------------------------------------------------------\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n EXTERNAL WEBR\n DIMENSION CC(*), CCPRIME(*), REWT(*), SAVR(*), WK(*), WP(*),\n 1 IWP(*), RPAR(*), IPAR(*)\nC\n JBG = IPAR(2)\n IF (JBG .EQ. 0) THEN\n CALL DRBDJA (T, CC, RPAR, WEBR, WK, REWT, CJ, WP, IWP, IER)\n ELSE\n CALL DRBGJA (T, CC, RPAR, WEBR, WK, REWT, CJ, WP, IWP, IER)\n ENDIF\nC\n RETURN\nC------------ End of Subroutine JACRS --------------------------------\n END\n\n SUBROUTINE PSOLRS (NEQ, T, CC, CCPRIME, SAVR, WK, CJ, WT, WP, IWP,\n 1 B, EPLIN, IER, RPAR, IPAR)\nC-----------------------------------------------------------------------\nC This routine applies the inverse of a product preconditioner matrix \nC to the vector in the array B. Depending on the flag JPRE, this \nC involves a call to GS, for the inverse of the spatial factor, and/or\nC a call to DRBDPS or DRBGPS for the inverse of the reaction-based\nC factor (CJ*I_d - dR/dy). The latter factor uses block-grouping\nC (with a call to DRBGPS) if JBG = 1, and does not (with a call to\nC DRBDPS) if JBG = 0. JBG is communicated as IPAR(2).\nC The array B is overwritten with the solution.\nC-----------------------------------------------------------------------\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CC(*), CCPRIME(*), SAVR(*), WK(*), WP(*), IWP(*), B(*),\n 1 RPAR(*), IPAR(*)\nC\n JPRE = IPAR(1)\n IER = 0\n HL0 = 1.0D0/CJ\nC\n JBG = IPAR(2)\nC\n IF (JPRE .EQ. 2 .OR. JPRE .EQ. 3) CALL GS (NEQ, HL0, B, WK)\nC\n IF (JPRE .NE. 2 ) THEN\n IF (JBG .EQ. 0) CALL DRBDPS (B, WP, IWP)\n IF (JBG .EQ. 1) CALL DRBGPS (B, WP, IWP)\n ENDIF\nC\n IF (JPRE .EQ. 4) CALL GS (NEQ, HL0, B, WK)\nC\n RETURN\nC------------ End of Subroutine PSOLRS -------------------------------\n END\n\n SUBROUTINE GS (N, HL0, Z, X)\nC-----------------------------------------------------------------------\nC This routine provides the inverse of the spatial factor for a \nC product preconditoner in an NS-species reaction-diffusion problem.\nC It performs ITMAX = 5 Gauss-Seidel iterations to compute an\nC approximation to (A_S)-inverse * Z, where A_S = I - hl0*Jd, and Jd \nC represents the diffusion contributions to the Jacobian. \nC The solution is vector returned in Z.\nC-----------------------------------------------------------------------\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION Z(*), X(*)\n PARAMETER (MAXS = 2)\n COMMON /PPAR2/ NP, NS, AX, AY, ACOEF(MAXS,MAXS), BCOEF(MAXS),\n 1 DX, DY, ALPH, BETA, FPI, DIFF(MAXS),\n 2 COX(MAXS), COY(MAXS), MX, MY, MXNS\n DATA ITMAX/5/\nC\n DIMENSION BETA1(MAXS), GAMMA1(MAXS), BETA2(MAXS), GAMMA2(MAXS), \n 1 DINV(MAXS)\nC\nC-----------------------------------------------------------------------\nC Write matrix as A = D - L - U.\nC Load local arrays BETA, BETA2, GAMMA1, GAMMA2, and DINV.\nC-----------------------------------------------------------------------\n DO 10 I = 1,NS\n ELAMDA = 1.0D0/(1.0D0 + 2.0D0*HL0*(COX(I) + COY(I)))\n BETA1(I) = HL0*COX(I)*ELAMDA\n BETA2(I) = 2.0D0*BETA1(I)\n GAMMA1(I) = HL0*COY(I)*ELAMDA\n GAMMA2(I) = 2.0D0*GAMMA1(I)\n DINV(I) = ELAMDA\n 10 CONTINUE\nC-----------------------------------------------------------------------\nC Begin iteration loop.\nC Load array X with (D-inverse)*Z for first iteration.\nC-----------------------------------------------------------------------\n ITER = 1\nC Zero X in all its components, since X is added to Z at the end.\n DO 15 II = 1,N\n 15 X(II) = 0.0d0\nC\n DO 50 JY = 1,MY\n IYOFF = MXNS*(JY-1)\n DO 40 JX = 1,MX\n IC = IYOFF + NS*(JX-1)\n DO 30 I = 1,NS\n ICI = IC + I\n X(ICI) = DINV(I)*Z(ICI)\n Z(ICI) = 0.0D0\n 30 CONTINUE\n 40 CONTINUE\n 50 CONTINUE\n GO TO 160\nC-----------------------------------------------------------------------\nC Calculate (D-inverse)*U*X.\nC-----------------------------------------------------------------------\n 70 CONTINUE\n ITER = ITER + 1\n JY = 1\n JX = 1\n IC = NS*(JX-1)\n DO 75 I = 1,NS\n ICI = IC + I\n 75 X(ICI) = BETA2(I)*X(ICI+NS) + GAMMA2(I)*X(ICI+MXNS)\n DO 85 JX = 2,MX-1\n IC = NS*(JX-1)\n DO 80 I = 1,NS\n ICI = IC + I\n 80 X(ICI) = BETA1(I)*X(ICI+NS) + GAMMA2(I)*X(ICI+MXNS)\n 85 CONTINUE\n JX = MX\n IC = NS*(JX-1)\n DO 90 I = 1,NS\n ICI = IC + I\n 90 X(ICI) = GAMMA2(I)*X(ICI+MXNS)\n DO 115 JY = 2,MY-1\n IYOFF = MXNS*(JY-1)\n JX = 1\n IC = IYOFF\n DO 95 I = 1,NS\n ICI = IC + I\n 95 X(ICI) = BETA2(I)*X(ICI+NS) + GAMMA1(I)*X(ICI+MXNS)\n DO 105 JX = 2,MX-1\n IC = IYOFF + NS*(JX-1)\n DO 100 I = 1,NS\n ICI = IC + I\n 100 X(ICI) = BETA1(I)*X(ICI+NS) + GAMMA1(I)*X(ICI+MXNS)\n 105 CONTINUE\n JX = MX\n IC = IYOFF + NS*(JX-1)\n DO 110 I = 1,NS\n ICI = IC + I\n 110 X(ICI) = GAMMA1(I)*X(ICI+MXNS)\n 115 CONTINUE\n JY = MY\n IYOFF = MXNS*(JY-1)\n JX = 1\n IC = IYOFF\n DO 120 I = 1,NS\n ICI = IC + I\n 120 X(ICI) = BETA2(I)*X(ICI+NS)\n DO 130 JX = 2,MX-1\n IC = IYOFF + NS*(JX-1)\n DO 125 I = 1,NS\n ICI = IC + I\n 125 X(ICI) = BETA1(I)*X(ICI+NS)\n 130 CONTINUE\n JX = MX\n IC = IYOFF + NS*(JX-1)\n DO 135 I = 1,NS\n ICI = IC + I\n 135 X(ICI) = 0.0D0\nC-----------------------------------------------------------------------\nC Calculate (I - (D-inverse)*L)*X.\nC-----------------------------------------------------------------------\n 160 CONTINUE\n JY = 1\n DO 175 JX = 2,MX-1\n IC = NS*(JX-1)\n DO 170 I = 1,NS\n ICI = IC + I\n 170 X(ICI) = X(ICI) + BETA1(I)*X(ICI-NS)\n 175 CONTINUE\n JX = MX\n IC = NS*(JX-1)\n DO 180 I = 1,NS\n ICI = IC + I\n 180 X(ICI) = X(ICI) + BETA2(I)*X(ICI-NS)\n DO 210 JY = 2,MY-1\n IYOFF = MXNS*(JY-1)\n JX = 1\n IC = IYOFF\n DO 185 I = 1,NS\n ICI = IC + I\n 185 X(ICI) = X(ICI) + GAMMA1(I)*X(ICI-MXNS)\n DO 200 JX = 2,MX-1\n IC = IYOFF + NS*(JX-1)\n DO 195 I = 1,NS\n ICI = IC + I\n X(ICI) = (X(ICI) + BETA1(I)*X(ICI-NS))\n 1 + GAMMA1(I)*X(ICI-MXNS)\n 195 CONTINUE\n 200 CONTINUE\n JX = MX\n IC = IYOFF + NS*(JX-1)\n DO 205 I = 1,NS\n ICI = IC + I\n X(ICI) = (X(ICI) + BETA2(I)*X(ICI-NS))\n 1 + GAMMA1(I)*X(ICI-MXNS)\n 205 CONTINUE\n 210 CONTINUE\n JY = MY\n IYOFF = MXNS*(JY-1)\n JX = 1\n IC = IYOFF\n DO 215 I = 1,NS\n ICI = IC + I\n 215 X(ICI) = X(ICI) + GAMMA2(I)*X(ICI-MXNS)\n DO 225 JX = 2,MX-1\n IC = IYOFF + NS*(JX-1)\n DO 220 I = 1,NS\n ICI = IC + I\n X(ICI) = (X(ICI) + BETA1(I)*X(ICI-NS))\n 1 + GAMMA2(I)*X(ICI-MXNS)\n 220 CONTINUE\n 225 CONTINUE\n JX = MX\n IC = IYOFF + NS*(JX-1)\n DO 230 I = 1,NS\n ICI = IC + I\n X(ICI) = (X(ICI) + BETA2(I)*X(ICI-NS))\n 1 + GAMMA2(I)*X(ICI-MXNS)\n 230 CONTINUE\nC-----------------------------------------------------------------------\nC Add increment X to Z.\nC-----------------------------------------------------------------------\n DO 300 I = 1,N\n 300 Z(I) = Z(I) + X(I)\nC\n IF (ITER .LT. ITMAX) GO TO 70\n RETURN\nC------------ End of Subroutine GS -----------------------------------\n END\n", "meta": {"hexsha": "c58afe5c63998090a4a04950216d00d0bf22684c", "size": 30583, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "daspk/examples/dweb.f", "max_stars_repo_name": "faribas/PyDAS", "max_stars_repo_head_hexsha": "fe9e6080af6e8dd09e9fcba00bb06c98bc2766de", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2015-01-03T21:58:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-20T15:25:57.000Z", "max_issues_repo_path": "daspk/examples/dweb.f", "max_issues_repo_name": "faribas/PyDAS", "max_issues_repo_head_hexsha": "fe9e6080af6e8dd09e9fcba00bb06c98bc2766de", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-02-11T04:24:05.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-01T16:41:02.000Z", "max_forks_repo_path": "daspk/examples/dweb.f", "max_forks_repo_name": "faribas/PyDAS", "max_forks_repo_head_hexsha": "fe9e6080af6e8dd09e9fcba00bb06c98bc2766de", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2015-02-11T00:47:28.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-27T01:46:34.000Z", "avg_line_length": 35.2338709677, "max_line_length": 73, "alphanum_fraction": 0.5034823268, "num_tokens": 10361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939913343093499, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.7640248382001595}} {"text": "program Sierpinski_carpet\n implicit none\n\n call carpet(4)\n\ncontains\n\nfunction In_carpet(a, b)\n logical :: in_carpet\n integer, intent(in) :: a, b\n integer :: x, y\n\n x = a ; y = b\n do\n if(x == 0 .or. y == 0) then\n In_carpet = .true.\n return\n else if(mod(x, 3) == 1 .and. mod(y, 3) == 1) then\n In_carpet = .false.\n return\n end if\n x = x / 3\n y = y / 3\n end do\nend function\n\nsubroutine Carpet(n)\n integer, intent(in) :: n\n integer :: i, j\n\n do i = 0, 3**n - 1\n do j = 0, 3**n - 1\n if(In_carpet(i, j)) then\n write(*, \"(a)\", advance=\"no\") \"#\"\n else\n write(*, \"(a)\", advance=\"no\") \" \"\n end if\n end do\n write(*,*)\n end do\nend subroutine Carpet\nend program Sierpinski_carpet\n", "meta": {"hexsha": "20560eb811568fad59574690ee335ec7b1a600ea", "size": 751, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Sierpinski-carpet/Fortran/sierpinski-carpet.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Sierpinski-carpet/Fortran/sierpinski-carpet.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Sierpinski-carpet/Fortran/sierpinski-carpet.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 17.4651162791, "max_line_length": 53, "alphanum_fraction": 0.5299600533, "num_tokens": 278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.7639989439431697}} {"text": "program factorial_function\n use, intrinsic :: iso_fortran_env, only : i8 => INT64\n implicit none\n integer(kind=i8), parameter :: n_min = 0_i8, n_max = 10_i8\n integer(kind=i8) :: n\n\n do n = n_min, n_max\n print *, n, factorial(n)\n end do\n\ncontains\n\n integer(kind=i8) function factorial(n)\n use, intrinsic :: iso_fortran_env, only : i8 => INT64\n implicit none\n integer(kind=i8), intent(in) :: n\n integer(kind=i8) :: factor\n factorial = 1_i8\n do factor = 2_i8, n\n factorial = factorial*factor\n end do\n end function factorial\n\nend program factorial_function\n", "meta": {"hexsha": "bb05fe3518c2dd3794ddd677c24cebfc1bedd47a", "size": 645, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "hands-on/session_02/exercise_03a.f90", "max_stars_repo_name": "gjbex/FortranForProgrammers", "max_stars_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-15T14:56:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-15T14:56:20.000Z", "max_issues_repo_path": "hands-on/session_02/exercise_03a.f90", "max_issues_repo_name": "gjbex/FortranForProgrammers", "max_issues_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hands-on/session_02/exercise_03a.f90", "max_forks_repo_name": "gjbex/FortranForProgrammers", "max_forks_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.8, "max_line_length": 62, "alphanum_fraction": 0.615503876, "num_tokens": 179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.8175744717487329, "lm_q1q2_score": 0.7639376284317069}} {"text": " SUBROUTINE RK4(NEQ,YY,YYP,DT)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!! fourth order Runge-Kutta algorithm from Hoover's SPAM book\n!!!! YYN hold intermediate positions and velocities\n!!!! YPN hold derivatives at intermediate times\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n IMPLICIT NONE\n INTEGER :: I,NEQ\n INTEGER, PARAMETER :: double = SELECTED_REAL_KIND(15,99)\n REAL(kind = double) :: DT\n REAL(kind = double), DIMENSION(NEQ) :: YY,YYP\n REAL(kind = double), DIMENSION(NEQ) :: YY1,YY2,YY3,YY4\n REAL(kind = double), DIMENSION(NEQ) :: YP1,YP2,YP3,YP4\n\n DO I = 1,NEQ\n YY1(I) = YY(I)\n END DO\n CALL RHS(YY1,YP1)\n\n DO I = 1,NEQ\n YY2(I) = YY(I) + 0.5D00*DT*YP1(I)\n END DO\n CALL RHS(YY2,YP2)\n\n DO I = 1,NEQ\n YY3(I) = YY(I) + 0.5D00*DT*YP2(I)\n END DO\n CALL RHS(YY3,YP3)\n\n DO I = 1,NEQ\n YY4(I) = YY(I) + DT*YP3(I)\n END DO\n CALL RHS(YY4,YP4)\n\n DO I = 1,NEQ\n YYP(I) = (YP1(I) + 2.0D00*(YP2(I)+YP3(I))+YP4(I))/6.0D00\n END DO\n\n DO I = 1,NEQ\n YY(I) = YY(I) + DT*YYP(I)\n END DO\n \n END SUBROUTINE\n\n", "meta": {"hexsha": "48f598cd712e29b34eeb583ededa0b70ae77f4fb", "size": 1202, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "synthetic_NEMD/src/src_3dsllod/rk4.f90", "max_stars_repo_name": "niallj/ImperialNESS-Sep14", "max_stars_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "synthetic_NEMD/src/src_3dsllod/rk4.f90", "max_issues_repo_name": "niallj/ImperialNESS-Sep14", "max_issues_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "synthetic_NEMD/src/src_3dsllod/rk4.f90", "max_forks_repo_name": "niallj/ImperialNESS-Sep14", "max_forks_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.7111111111, "max_line_length": 64, "alphanum_fraction": 0.4783693844, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545304202038, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7638638098349231}} {"text": " subroutine solve_rs(f,b)\nc\nc solve 4x4 system b*x = f\nc replaces x in place of f\nc\n implicit none\n integer :: i,j\n real, dimension(4,4) :: b\n real, dimension(4) :: f\nc\n real :: d1,d2,d3,d4\n\n b(1,1) = 1./b(1,1)\n b(1,2) = b(1,2)*b(1,1)\n b(1,3) = b(1,3)*b(1,1)\n b(1,4) = b(1,4)*b(1,1)\nc\n b(2,2) = 1./(b(2,2) -b(2,1)*b(1,2))\n b(2,3) = (b(2,3)-b(2,1)*b(1,3))*b(2,2)\n b(2,4) = (b(2,4)-b(2,1)*b(1,4))*b(2,2)\n b(3,2) = b(3,2)-b(3,1)*b(1,2)\n b(3,3) = 1./(b(3,3) -b(3,1)*b(1,3) - b(3,2)*b(2,3))\n b(3,4) = (b(3,4) -b(3,1)*b(1,4) -b(3,2)*b(2,4))*b(3,3)\n b(4,2) = b(4,2) -b(4,1)*b(1,2)\n b(4,3) = b(4,3) -b(4,1)*b(1,3) -b(4,2)*b(2,3)\n b(4,4) = 1./(b(4,4)-b(4,1)*b(1,4)-b(4,2)*b(2,4)-b(4,3)*b(3,4))\nc\nc fwd substitution\nc\n d1 = f(1)*b(1,1)\n d2 = (f(2) -b(2,1)*d1)*b(2,2)\n d3 = (f(3) -b(3,1)*d1-b(3,2)*d2)*b(3,3)\n d4 = (f(4) -b(4,1)*d1-b(4,2)*d2-b(4,3)*d3)*b(4,4)\nc\nc bwd substitution\nc\n f(4) = d4\n f(3) = d3 -b(3,4) *f(4)\n f(2) = d2 -b(2,3)*f(3)-b(2,4)*f(4)\n f(1) = d1-b(1,2)*f(2)-b(1,3)*f(3)- b(1,4)*f(4)\nc\n return\nc\n end\n", "meta": {"hexsha": "3e1eea47433bc814795fa19c5d63cf33466d2ac9", "size": 1323, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "flo103-rksgs-mar20/solve_rs.f", "max_stars_repo_name": "AlexT-L/RANS", "max_stars_repo_head_hexsha": "f4f477b30429e5028f9a0a53d59787f9f3821a00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "flo103-rksgs-mar20/solve_rs.f", "max_issues_repo_name": "AlexT-L/RANS", "max_issues_repo_head_hexsha": "f4f477b30429e5028f9a0a53d59787f9f3821a00", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2021-11-12T19:39:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-20T19:45:09.000Z", "max_forks_repo_path": "flo103-rksgs-mar20/solve_rs.f", "max_forks_repo_name": "AlexT-L/RANS", "max_forks_repo_head_hexsha": "f4f477b30429e5028f9a0a53d59787f9f3821a00", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-23T02:26:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T02:26:34.000Z", "avg_line_length": 29.4, "max_line_length": 72, "alphanum_fraction": 0.3484504913, "num_tokens": 753, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545348152282, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7638638045261623}} {"text": "Subroutine inv(A, n, ans, ierr)\n\tImplicit None\n\t\n\tInteger, Intent(In) :: n\n\tDouble Precision, Dimension(n, n), Intent(InOut) :: A\n\tDouble Precision, Dimension(n, n), Intent(Out) :: ans\n\tInteger, Intent(Out) :: ierr\n\tDouble Precision, Dimension(n, n) :: tmp, tmp2\n\tDouble Precision :: tmp_det\n\t\n\tInteger :: i, j, p, q\n\t\n\tierr = 0\n\t\n\tCall det(A, n, tmp_det)\n\tIf (tmp_det .EQ. 0.0) Then\n\t\tierr = 1\n\t\tans = 0.0\n\t\tReturn\n\tEnd If\n\t\n\tCall minors(A, n, tmp)\n\tCall trans(tmp, n, tmp2)\t\t\n\t\n\tDo i = 1, n\n\t\tDo j = 1, n\n\t\t\tans(i, j) = (-1) ** (i+j) * tmp2(i, j) / tmp_det\n\t\tEnd Do\n\tEnd Do\nEnd Subroutine inv", "meta": {"hexsha": "87551dc86aee5c9e8a60eebf1c3b89629e0bc5f7", "size": 594, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Matrices/inv.f90", "max_stars_repo_name": "sajazaerica/FTools", "max_stars_repo_head_hexsha": "6d6342d9758752924290dd061beca85b655397f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Matrices/inv.f90", "max_issues_repo_name": "sajazaerica/FTools", "max_issues_repo_head_hexsha": "6d6342d9758752924290dd061beca85b655397f4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Matrices/inv.f90", "max_forks_repo_name": "sajazaerica/FTools", "max_forks_repo_head_hexsha": "6d6342d9758752924290dd061beca85b655397f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.8, "max_line_length": 54, "alphanum_fraction": 0.6060606061, "num_tokens": 220, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660949832345, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.763833031597879}} {"text": "* This program calculate the solution for the\r\n* diferintial equation:\r\n* dy/dx=-xy< y(x=0)=1\r\n* the solution is : y= exp(-x^2/2)\r\n\r\n Func(x,y)=-x*y\r\n20 write(*,*)'Enter step size (.le.0 to stop )'\r\n Read(*,*)H\r\n if(H.LE.0)stop\r\n Nstep=3.0/H\r\n Y=1.0\r\n do 10 IX=0,Nstep-1\r\n X=IX*H\r\n Y=Y+H*func(x,y)\r\n Diff=exp(-0.5*(x+H)**2)-y\r\n Write(*,*)IX,X+H,Y,Diff\r\n10 continue\r\n go to 20\r\n End\r\n \r\n \r\n\r\n", "meta": {"hexsha": "e03394c417ad0fcdebf8896b1f8cbb7b7c726271", "size": 526, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "last28-52009/Example/solution od differintial equation- example 1/solution od differintial equation- example 1.f", "max_stars_repo_name": "Melhabbash/Computational-Physics-", "max_stars_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "last28-52009/Example/solution od differintial equation- example 1/solution od differintial equation- example 1.f", "max_issues_repo_name": "Melhabbash/Computational-Physics-", "max_issues_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "last28-52009/Example/solution od differintial equation- example 1/solution od differintial equation- example 1.f", "max_forks_repo_name": "Melhabbash/Computational-Physics-", "max_forks_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.8695652174, "max_line_length": 53, "alphanum_fraction": 0.4201520913, "num_tokens": 181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539661028358093, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7638330242742323}} {"text": "submodule (mod_integration) smod_integration\n implicit none\n\ncontains\n\n module subroutine gaussquad(N, x, w)\n integer, intent(in) :: N\n real(wp), intent(out), dimension(N) :: x, w\n\n select case (N)\n case (1)\n x = [ 0._wp ]\n w = [ 2._wp ]\n\n case (2)\n x = [ -0.5773502691896257_wp, &\n 0.5773502691896257_wp ]\n w = [ 1._wp, &\n 1._wp ]\n\n case (3)\n x = [ -0.7745966692414834_wp, &\n 0._wp, &\n 0.7745966692414834_wp ]\n w = [ 0.5555555555555556_wp, &\n 0.8888888888888888_wp, &\n 0.5555555555555556_wp ]\n\n case (4)\n x = [ -0.8611363115940526_wp, &\n -0.3399810435848563_wp, &\n 0.3399810435848563_wp, &\n 0.8611363115940526_wp ]\n w = [ 0.3478548451374538_wp, &\n 0.6521451548625461_wp, &\n 0.6521451548625461_wp, &\n 0.3478548451374538_wp ]\n\n case (5)\n x = [ -0.9061798459386640_wp, &\n -0.5384693101056831_wp, &\n 0._wp, &\n 0.5384693101056831_wp, &\n 0.9061798459386640_wp ]\n w = [ 0.2369268850561891_wp, &\n 0.4786286704993665_wp, &\n 0.5688888888888889_wp, &\n 0.4786286704993665_wp, &\n 0.2369268850561891_wp ]\n\n case default\n\n ! call lgwt(-1._wp, 1._wp, N, x, w)\n ! call cgwt(N, x, w)\n call gaussquad_rosetta(N, x, w)\n\n end select\n\n return\n end subroutine gaussquad\n\n subroutine lgwt(a, b, num_pts, x, w)\n\n !* This function is a fortran90 port of the matlab function,\n ! lgwt.m The source code of lgwt.m was originally found at:\n ! http://www.mathworks.com/matlabcentral/fileexchange/4540\n\n ! Variables in/out\n integer, intent(in) :: num_pts\n real(wp), intent(in) :: a, b\n real(wp), intent(out) :: x(:), w(:)\n\n ! Local variables\n integer:: ii, jj, N, N1, N2\n ! real(wp), parameter:: eps=sqrt(epsilon(1.0_wp))\n real(wp), parameter :: eps=1d-10\n real(wp), dimension(:), allocatable :: xu, array1, y, y0, Lpp\n real(wp), dimension(:, :), allocatable :: L, Lp\n real(wp), parameter :: pi = 4.0_wp*datan(1.0_wp)\n\n N = num_pts - 1\n N1 = N + 1\n N2 = N + 2\n\n ! Allocate and initialize arrays\n allocate(xu(N1), array1(N1), y(N1), y0(N1))\n allocate(L(N1, N2), Lp(N1, N2), Lpp(N1))\n\n L = 0.0_wp\n Lp = 0.0_wp\n\n call linspace(-1.0_wp, 1.0_wp, xu)\n\n array1 = [ (ii, ii = 0, N) ]\n ! Initial guess of the roots of the Legendre polynomial of order N\n y = cos((2.0_wp * dble(array1) + 1.0_wp) * &\n pi / (2.0_wp * dble(N) + 2.0_wp)) + &\n (0.27_wp/dble(N1)) * sin(pi*xu*dble(N)/dble(N2))\n\n y0 = 2.0_wp\n\n outer: do\n L(:, 1) = 1.0_wp\n Lp(:, 1) = 0.0_wp\n\n L(:, 2) = y\n Lp(:, 2) = 1.0_wp\n\n inner: do jj = 2, N1\n L(:, jj+1) = ( &\n (2.0_wp*dble(jj)-1.0_wp) * y * L(:, jj) - &\n dble(jj-1) * L(:, jj-1)) &\n / dble(jj)\n enddo inner\n\n Lpp = dble(N2) * (L(:,N1) - y * L(:,N2)) &\n / (1.0_wp - y**2.0_wp)\n\n y0 = y\n y = y0 - L(:,N2)/Lpp\n\n if ( norm2(y-y0) < eps ) then\n exit outer\n endif\n enddo outer\n\n x = ( a*(1.0_wp-y) + b*(1.0_wp+y) ) / 2.0_wp\n w = ( b-a ) / ((1.0_wp - y**2.0_wp)*Lpp**2.0_wp) * &\n (dble(N2) / dble(N1))**2.0_wp\n\n return\n end subroutine lgwt\n\n subroutine cgwt(num_pts, x, w)\n\n ! This function determines the points and weights associated\n ! with Chebyshev-Gauss quadrature\n\n ! Variables in/out\n integer, intent(in) :: num_pts\n real(wp), intent(out), dimension(:) :: x, w\n\n ! Local variables\n integer:: ii\n real(wp), parameter:: pi = 4._wp*datan(1._wp)\n\n x = cos( (dble(2*[( ii, ii=1,num_pts )]-1) )/dble(2*num_pts) * pi)\n\n w = pi/dble(num_pts) / ((1.0_wp - x**2._wp)**(-0.5_wp))\n\n ! print*, x\n ! print*, w\n ! stop\n return\n end subroutine cgwt\n\n subroutine gaussquad_rosetta(n, r1, r2)\n\n ! This code was originally found at the following website:\n ! http://rosettacode.org/wiki/Numerical_integration/Gauss-Legendre_Quadrature#Fortran\n\n integer, intent(in) :: n\n real(wp), intent(out) :: r1(n), r2(n)\n\n\n integer :: k\n real(wp), parameter :: pi = 4._wp*atan(1._wp)\n real(wp) :: x, f, df, dx\n integer :: i, iter\n real(wp), allocatable :: p0(:), p1(:), tmp(:)\n\n p0 = [1._wp]\n p1 = [1._wp, 0._wp]\n\n do k = 2, n\n tmp = ((2*k-1)*[p1,0._wp]-(k-1)*[0._wp, 0._wp,p0])/k\n p0 = p1; p1 = tmp\n enddo\n\n outer: do i = 1, n\n x = cos(pi*(i-0.25_wp)/(n+0.5_wp))\n inner: do iter = 1, 10\n f = p1(1); df = 0._wp\n deep: do k = 2, size(p1)\n df = f + x*df\n f = p1(k) + x * f\n enddo deep\n dx = f / df\n x = x - dx\n if (abs(dx)<10*epsilon(dx)) exit\n enddo inner\n r1(i) = x\n r2(i) = 2/((1-x**2)*df**2)\n enddo outer\n return\n end subroutine gaussquad_rosetta\n\nend submodule\n", "meta": {"hexsha": "3fd7ce67857f9a195c2df068ce739972d10966b4", "size": 5791, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/integration/smod_integration.f90", "max_stars_repo_name": "cbcoutinho/learn_dg", "max_stars_repo_head_hexsha": "b22bf91d1a0daedb6b48590c7361c3a9c3c7f371", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-03-08T09:26:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-25T01:25:12.000Z", "max_issues_repo_path": "src/integration/smod_integration.f90", "max_issues_repo_name": "cbcoutinho/learn_dg", "max_issues_repo_head_hexsha": "b22bf91d1a0daedb6b48590c7361c3a9c3c7f371", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/integration/smod_integration.f90", "max_forks_repo_name": "cbcoutinho/learn_dg", "max_forks_repo_head_hexsha": "b22bf91d1a0daedb6b48590c7361c3a9c3c7f371", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-01-03T05:51:10.000Z", "max_forks_repo_forks_event_max_datetime": "2018-01-03T05:51:10.000Z", "avg_line_length": 29.1005025126, "max_line_length": 94, "alphanum_fraction": 0.4479364531, "num_tokens": 1873, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267728417087, "lm_q2_score": 0.8791467785920306, "lm_q1q2_score": 0.7638262584982982}} {"text": "!\n! ej9a.f90\n!\n! Copyright 2016 Bruno S \n!\n! This program is free software; you can redistribute it and/or modify\n! it under the terms of the GNU General Public License as published by\n! the Free Software Foundation; either version 2 of the License, or\n! (at your option) any later version.\n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n! GNU General Public License for more details.\n!\nprogram ej9a\nuse precision, pr => dp\n\nimplicit none\ninteger :: i, j, k, n\nreal(pr), parameter :: h = 0.001_pr\nreal(pr) :: alpha, t0, tf, t, e\nreal(pr), dimension(:) :: xi(4), xi_1(4), k1(4), k2(4), k3(4), k4(4), x0(4)\n\n\nopen(unit=10, file='ej9a_e100.dat', status='UNKNOWN', action='WRITE')\nwrite(10, *) \"# t q1 q2 p1 p2 e\"\n\ne = 100._pr\nx0 = (/ 2._pr, 0._pr, 0._pr, sqrt(2._pr*e - 4._pr) /)\nalpha = 0.05_pr\nt0 = 0._pr\ntf = 200._pr\nn = int((tf-t0)/h)\nprint *, n\nt = 0._pr\nxi = x0\ndo i =1, n\n xi_1 = xi\n k1 = h * f(xi_1, alpha)\n k2 = h * f(xi_1 + k1*0.5_pr, alpha)\n k3 = h * f(xi_1 + k2*0.5_pr, alpha)\n k4 = h * f(xi_1 + k3, alpha)\n\n xi = xi_1 + (k1 + 2._pr * k2 + 2._pr * k3 + k4) / 6._pr\n t = t0 + i * h\n\n e = 0.5_pr*(xi(1)*xi(1) + xi(2)*xi(2) + xi(3)*xi(3) + xi(4)*xi(4)) + &\n & alpha * xi(1)*xi(1)*xi(2)*xi(2)\n\n write(10, *) t, xi(1), xi(2), xi(3), xi(4), e\nend do\n\ncontains\n\nfunction f(x, alpha)\ninteger(pr), parameter :: n = 4\nreal (pr) :: f(n)\nreal (pr), intent(in) :: x(n), alpha\n\n f(1) = x(3)\n f(2) = x(4)\n f(3) = -x(1) - alpha*x(1)*x(2)*x(2)\n f(4) = -x(2) - alpha*x(1)*x(1)*x(2)\n\nend function f\n\n\nend program ej9a\n", "meta": {"hexsha": "43a23680b741f93ddabfc6de362df913f86d06e6", "size": 1773, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lab1/9/ej9a.f90", "max_stars_repo_name": "BrunoSanchez/fisicaComp", "max_stars_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lab1/9/ej9a.f90", "max_issues_repo_name": "BrunoSanchez/fisicaComp", "max_issues_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lab1/9/ej9a.f90", "max_forks_repo_name": "BrunoSanchez/fisicaComp", "max_forks_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.3285714286, "max_line_length": 76, "alphanum_fraction": 0.5764241399, "num_tokens": 713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122138417878, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7637986934768758}} {"text": "program factorial_recursive_function\n use, intrinsic :: iso_fortran_env, only : i8 => INT64\n implicit none\n integer(kind=i8), parameter :: n_min = 0_i8, n_max = 10_i8\n integer(kind=i8) :: n\n\n do n = n_min, n_max\n print *, n, factorial(n)\n end do\n\ncontains\n\n recursive function factorial(n) result(fac)\n use, intrinsic :: iso_fortran_env, only : i8 => INT64\n implicit none\n integer(kind=i8), intent(in) :: n\n integer(kind=i8) :: fac\n if (n == 0) then\n fac = 1_i8\n else\n fac = n*factorial(n - 1)\n end if\n end function factorial\n\nend program factorial_recursive_function\n", "meta": {"hexsha": "2b00f6259210240fc40009e6398127a16461ec93", "size": 671, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "hands-on/session_02/exercise_03b.f90", "max_stars_repo_name": "gjbex/FortranForProgrammers", "max_stars_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-15T14:56:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-15T14:56:20.000Z", "max_issues_repo_path": "hands-on/session_02/exercise_03b.f90", "max_issues_repo_name": "gjbex/FortranForProgrammers", "max_issues_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hands-on/session_02/exercise_03b.f90", "max_forks_repo_name": "gjbex/FortranForProgrammers", "max_forks_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.8076923077, "max_line_length": 62, "alphanum_fraction": 0.6005961252, "num_tokens": 188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037384317887, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7637021685925552}} {"text": "subroutine iterate(a, s, pi)\n integer, parameter :: dp=kind(0.d0)\n real(dp), intent(inout) :: a, s, pi\n\n pi = pi + (s * (4_dp / (a * (2_dp + (a *(a + 3_dp))))))\n s = -s\n a = a + 2\nend subroutine iterate\n\nfunction calculate(iters) result(res)\n external iterate\n integer, intent(in) :: iters\n integer, parameter :: dp=kind(0.d0)\n real(dp) :: res\n real(dp) :: a, s, pi\n integer :: v\n\n pi = 3_dp\n a = 2_dp\n s = 1_dp\n do v = 1, iters\n call iterate(a, s, pi)\n end do\n\n res = pi\nend function calculate\n\nprogram nilakanthaPi\n implicit none\n integer, parameter :: dp=kind(0.d0)\n real(dp) :: pi\n real(dp), external :: calculate\n\n pi = calculate(150000)\n\n print *, \"pi =\", pi\nend program nilakanthaPi\n", "meta": {"hexsha": "b0f446f956d7b836a4f2466764ddb6641a156932", "size": 861, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/redone/main.f90", "max_stars_repo_name": "amazinigmech2418/Pi-in-Many-Languages", "max_stars_repo_head_hexsha": "233fda961a90ad4f81926df1735a244c012f9766", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-19T04:45:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-16T22:31:58.000Z", "max_issues_repo_path": "fortran/redone/main.f90", "max_issues_repo_name": "amazinigmech2418/Pi-in-Many-Languages", "max_issues_repo_head_hexsha": "233fda961a90ad4f81926df1735a244c012f9766", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-23T16:19:45.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-23T16:19:45.000Z", "max_forks_repo_path": "fortran/redone/main.f90", "max_forks_repo_name": "amazinigmech2418/Pi-in-Many-Languages", "max_forks_repo_head_hexsha": "233fda961a90ad4f81926df1735a244c012f9766", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-08T12:37:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-08T12:37:44.000Z", "avg_line_length": 22.6578947368, "max_line_length": 59, "alphanum_fraction": 0.5052264808, "num_tokens": 266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037384317887, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7637021606020277}} {"text": "program Trapezoidal_Rule\r\n\r\n implicit none\r\n\r\n real :: a,b,h,s,Integration\r\n integer :: n,i\r\n real,parameter :: pi=3.14\r\n\r\n print*,\"TRAPEZOIDAL RULE\"\r\n print*,\"Function : y=sin(x)\"\r\n\r\n print*,\"Enter lower limit(in degrees) :\"\r\n read*,a\r\n a=a*pi/180 !Converting degrees to radians\r\n\r\n print*,\"Enter upper limit(in degrees) :\"\r\n read*,b\r\n b=b*pi/180 !Converting degrees to radians\r\n\r\n print*,\"Enter number of iterations :\"\r\n read*,n\r\n\r\n h=(b-a)/n\r\n s=0.5*(f(a)+f(b))\r\n\r\n do i=1,(n-1)\r\n s=s+f(a+i*h)\n end do\r\n\r\n Integration=h*s\r\n print*,\"Answer of Integration : \",Integration\r\n\nend program\r\n\r\nfunction f(x)\r\n implicit none\r\n real :: f ! Dummy Variable\r\n real :: x ! Local Variable\r\n f=sin(x)\nend function\r\n", "meta": {"hexsha": "8969eb2306c9aff25ea27703729a2c2fad7e3e08", "size": 788, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "4_Trapezoidal_Rule.f90", "max_stars_repo_name": "Official-Satyam-Tiwari/FORTRAN", "max_stars_repo_head_hexsha": "5f15194bc7a2bdf84ce4516fa291f49072f6b227", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4_Trapezoidal_Rule.f90", "max_issues_repo_name": "Official-Satyam-Tiwari/FORTRAN", "max_issues_repo_head_hexsha": "5f15194bc7a2bdf84ce4516fa291f49072f6b227", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4_Trapezoidal_Rule.f90", "max_forks_repo_name": "Official-Satyam-Tiwari/FORTRAN", "max_forks_repo_head_hexsha": "5f15194bc7a2bdf84ce4516fa291f49072f6b227", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.2195121951, "max_line_length": 50, "alphanum_fraction": 0.5659898477, "num_tokens": 235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7636999010461725}} {"text": "!---------------------------------------------------------------------------\n! This is a fortran90 program to evaluate the 2 dimension laplace equation:\n! Fxx + Fyy = 0\n! {F(Xi+1,Yj)-2*(Fxi,Yj)+F(Xi-1,Yj)}/dX^2 + \n! {F(Xi,Yj+1)-2*F(Xi,Yj)+F(Xi,Yj-1)}/dY^2 = 0\n! for 1/2 >= {x,y} >= 0\n!\n! The boundary conditions are:\n! f(x=0,y) = 0\n! f(x,y=0) = 0\n! f(x=1/2,y) = 200y\n! f(x,y=1/2) = 200x\n! In this example the boundary condition represents temperature in degC.\n! \n! Mapping:\n! i,j goes from 1 to N-1\n! i,j at the edges (0 and N) are constrained by the boundary conditions\n!\n! 2017-03-15\n! - working now, 171 iterations needed\n!\n! 2017-03-06\n! - Initial try.\n! - jacobi method:\n! 1. fill f square with boundary conditions,\n! 2. iterate through each interior square, where:\n! U(i,j) = (1/4)*{(U(i-1,j)+U(i+1,j)+U(i,j-1)+U(i,j+1)}\n! 3. how many iterations does it take to converge?\n! 4. compare error.\n! - based on professor xxx's code,\n! - written by xxx.\n!---------------------------------------------------------------------------\n\nprogram part3_jacobi_10\n implicit none\n\n integer, parameter :: N=10,NM1=N-1,M=NM1*NM1\n\n real ALX,ALY,dx,dy\n real tolerance, error2, error\n\n real, dimension (0:N,0:N) :: F,Fold,Fexact\n real, dimension (0:N) :: X,Y\n \n integer i,j,k,iter\n \n open (2, file = 'part3_jacobi_10.out')\n\n tolerance = 1.0e-4\n error=0; error2=0\n\n ALX = 0.5 ! boundary\n ALY = 0.5 \n dx = ALX/N ! discretize\n dy = ALY/N\n do i=0,N,1\n X(i) = i*dx\n Y(i) = i*dy\n enddo\n\n ! setup Fexact matrix\n do i=0,N,1\n do j=0,N,1\n Fexact(i,j) = 400*X(i)*Y(j) ! exact solution\n enddo \n enddo\n\n ! setup F matrix, boundary conditions\n F=0\n do i=0,N,1\n F(i,0) = 0\n F(0,i) = 0\n F(N,i) = 200*Y(i)\n F(i,N) = 200*X(i)\n enddo\n\n ! iterate using Jacobi method\n Fold = F\n do iter=1,200,1\n do i=1,NM1,1\n do j=1,N-1,1\n F(i,j) = 0.25*( &\n Fold(i-1,j) + Fold(i+1,j) + &\n Fold(i,j-1) + Fold(i,j+1) &\n )\n enddo\n enddo\n\n ! calculate error\n error2 = 0 \n do i=1,NM1,1\n do j=1,NM1,i\n error2 = error2 + (F(i,j) - Fold(i,j))**2 \n enddo\n enddo\n error = sqrt(error2)/NM1 ! this calculates the L2 norm error / #elements\n write(2,*), iter, 'l2 norm error / #elements:', error\n \n Fold = F\n if (error.le.tolerance) goto 1000\n enddo\n1000 continue\n\n ! write F and Fexact to output\n write(2,*), 'F:'\n do i=0,N,1\n write(2,*) (F(i,j),j=0,N)\n enddo\n write(2,*), 'Fexact:'\n do i=0,N,1\n write(2,*) (Fexact(i,j),j=0,N)\n enddo\n \nend program\n", "meta": {"hexsha": "070ab807ac63fc681fcf39e4bc3b472b1bf0b5b4", "size": 2751, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "heat_transfer_2D.f90", "max_stars_repo_name": "scientificprogrammer123/heat-transfer_2D", "max_stars_repo_head_hexsha": "c33522862160b8c3be02bc23b789628e347705ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "heat_transfer_2D.f90", "max_issues_repo_name": "scientificprogrammer123/heat-transfer_2D", "max_issues_repo_head_hexsha": "c33522862160b8c3be02bc23b789628e347705ba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "heat_transfer_2D.f90", "max_forks_repo_name": "scientificprogrammer123/heat-transfer_2D", "max_forks_repo_head_hexsha": "c33522862160b8c3be02bc23b789628e347705ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.9217391304, "max_line_length": 77, "alphanum_fraction": 0.4983642312, "num_tokens": 1017, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.8198933293122507, "lm_q1q2_score": 0.7636998959675371}} {"text": "\nprogram laplace_mc\n\n use problem_description, only: utrue,nx,ny,ax,ay,dx,dy\n use random_util, only: init_random_seed\n use mc_walk, only: random_walk, many_walks, nwalks\n\n implicit none\n integer :: i,i0,j0,max_steps,seed1,n_mc,n_success,n_total\n real(kind=8) :: x0,y0,u_true,u_mc,u_sum_old,u_sum_new, u_mc_total,error\n\n open(unit=25, file='mc_laplace_error.txt', status='unknown')\n\n x0 = 0.9d0\n y0 = 0.6d0\n i0 = nint((x0-ax)/dx)\n j0 = nint((y0-ay)/dy)\n\n ! shift (x0,y0) to a grid point if it wasn't already:\n x0 = ax + i0*dx\n y0 = ay + j0*dy\n\n max_steps = 100*max(nx,ny)\n !max_steps = 10\n\n nwalks = 0 ! to keep track of calls to random_walk\n\n u_true = utrue(x0, y0)\n\n seed1 = 12345 ! or set to 0 for random seed\n call init_random_seed(seed1)\n\n n_mc = 10\n call many_walks(i0, j0, max_steps, n_mc, u_mc, n_success)\n\n ! start accumulating totals:\n u_mc_total = u_mc\n n_total = n_success\n\n ! relative error gives estimate of number of correct digits:\n error = abs(u_mc_total - u_true) / abs(u_true)\n write(25,'(i10,e23.15,e15.6)') n_total, u_mc_total, error\n print '(i10,e23.15,e15.6)', n_total, u_mc_total, error\n\n\t\n ! loop to add successively double the number of points used:\n\n do i=1,12\n ! compute approximation with new chunk of points\n call many_walks(i0, j0, max_steps, n_mc, u_mc, n_success)\n\n ! update estimate of u based on doubling number:\n ! but not that not all were successful:\n u_sum_old = u_mc_total * n_total\n u_sum_new = u_mc * n_success\n n_total = n_total + n_success\n u_mc_total = (u_sum_old + u_sum_new) / n_total\n\n ! relative error:\n error = abs(u_mc_total - u_true) / abs(u_true)\n\n write(25,'(i10,e23.15,e15.6)') n_total, u_mc_total, error\n print '(i10,e23.15,e15.6)', n_total, u_mc_total, error\n\n n_mc = 2*n_mc\n enddo\n\n print '(\"Final approximation to u(x0,y0): \",es22.14)',u_mc_total\n print '(\"Total number of random walks: \",i10)',nwalks\n \n\nend program laplace_mc\n", "meta": {"hexsha": "bcc2e0e049474aa6407433832ce5c7e11d3dd7f2", "size": 2090, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/2013/solutions/project/part3/laplace_mc.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/2013/solutions/project/part3/laplace_mc.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/2013/solutions/project/part3/laplace_mc.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.6301369863, "max_line_length": 75, "alphanum_fraction": 0.643062201, "num_tokens": 683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451835, "lm_q2_score": 0.8807970701552504, "lm_q1q2_score": 0.7636825690583888}} {"text": "! Program to perform a random walk in 1 dimension\n! Only one walker present\n\nPROGRAM random_walk_1dim\n USE constants\n USE f90library\n IMPLICIT NONE\n INTEGER:: max_trials, number_walks\n REAL(dp):: move_probability\n INTEGER, ALLOCATABLE, DIMENSION(:) :: x_cum, x2_cum\n\n ! get max trials, number of walks and the probability to move\n CALL initialise(max_trials, number_walks, move_probability) \n ! allocate memory\n ALLOCATE (x_cum(number_walks), x2_cum(number_walks))\n x_cum = 0; x2_cum = 0\n ! do the Monte Carlo move\n CALL mc_sampling(max_trials, number_walks, move_probability,x_cum, x2_cum)\n ! Print out results \n CALL output(max_trials, number_walks, x_cum, x2_cum) \n ! free memory\n DEALLOCATE(x_cum, x2_cum) \nEND PROGRAM random_walk_1dim\n\n! Read in data from screen\n\nSUBROUTINE initialise(max_trials, number_walks, move_probability) \n USE constants\n IMPLICIT NONE\n INTEGER, INTENT(inout) ::max_trials, number_walks\n REAL(DP) :: move_probability\n WRITE(*,*)'Number of Monte Carlo trials =' \n READ(*,*) max_trials\n WRITE(*,*) 'Number of attempted walks='\n READ(*,*) number_walks\n WRITE(*,*) 'Move probability='\n READ(*,*) move_probability\nEND SUBROUTINE initialise\n\n! Output of expectation values, , and their variances\n! - ^2 and - ^2\n\nSUBROUTINE output(max_trials, number_walks, x_cum, x2_cum)\n USE constants\n IMPLICIT NONE\n INTEGER :: i\n INTEGER, INTENT(in) :: max_trials, number_walks\n INTEGER, INTENT(in) :: x_cum(number_walks), x2_cum(number_walks)\n REAL(dp) :: xaverage, x2average, y2average, xvariance\n\n OPEN(UNIT=6, FILE='out.dat')\n DO i =1, number_walks \n xaverage = x_cum(i)/FLOAT(max_trials)\n x2average = x2_cum(i)/FLOAT(max_trials)\n xvariance = x2average - xaverage*xaverage\n WRITE(6,'(I3,2X,3F12.6)') i, xaverage, x2average ,xvariance\n ENDDO\nEND SUBROUTINE output\n\n! Here we perform the Monte Carlo samplings and moves in 2 dim\n\nSUBROUTINE mc_sampling(max_trials,number_walks, move_probability, x_cum, x2_cum)\n USE constants\n USE f90library\n IMPLICIT NONE\n INTEGER, INTENT(in) :: max_trials,number_walks\n INTEGER, INTENT(inout) :: x_cum(number_walks), x2_cum(number_walks)\n INTEGER :: idum, x, trial, walks\n REAL(dp) :: rantest\n REAL(dp), INTENT(in) :: move_probability\n idum=-1 \n ! loop over Monte Carlo trials\n DO trial = 1, max_trials\n x = 0\n ! loop over attempted walks in 2 dimensions\n DO walks = 1, number_walks\n rantest = ran0(idum)\n IF (rantest <= move_probability) THEN\n x = x+1\n ELSE\n x = x-1\n ENDIF\n x_cum(walks) = x_cum(walks)+x\n x2_cum(walks) = x2_cum(walks)+x*x\n ENDDO\n ENDDO\nEND SUBROUTINE mc_sampling\n\n\n", "meta": {"hexsha": "1985cdc10fd82d916dd20204cf9fa90a93e11130", "size": 2709, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/Programs/LecturePrograms/programs/RandomWalks/Fortran/program1.f90", "max_stars_repo_name": "kimrojas/ComputationalPhysicsMSU", "max_stars_repo_head_hexsha": "a47cfc18b3ad6adb23045b3f49fab18c0333f556", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 220, "max_stars_repo_stars_event_min_datetime": "2016-08-25T09:18:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T14:09:16.000Z", "max_issues_repo_path": "doc/Programs/LecturePrograms/programs/RandomWalks/Fortran/program1.f90", "max_issues_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_issues_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-01-18T10:43:38.000Z", "max_issues_repo_issues_event_max_datetime": "2020-02-08T13:15:42.000Z", "max_forks_repo_path": "doc/Programs/LecturePrograms/programs/RandomWalks/Fortran/program1.f90", "max_forks_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_forks_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 136, "max_forks_repo_forks_event_min_datetime": "2016-08-25T09:04:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T09:54:21.000Z", "avg_line_length": 30.1, "max_line_length": 80, "alphanum_fraction": 0.7017349575, "num_tokens": 851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8670357477770336, "lm_q1q2_score": 0.7636825585703805}} {"text": "! Created by EverLookNeverSee@GitHub on 5/31/20\n! For more information see FCS/img/Exercise_07.png\n\n\nprogram main\n implicit none\n ! declaring variables\n integer :: i, degree\n real :: x, result = 0.0\n real, allocatable, dimension(:) :: P ! to store polynomial coefficients\n ! specifying polynomial degree using user input\n do\n print *, \"Enter degree of the polynomial:\"\n read *, degree\n if (degree < 0) then\n print *, \"Degree should not be negative!\"\n cycle\n end if\n exit\n end do\n ! creating array blocks based on polynomial degree\n allocate(P(degree + 1))\n ! when we have constant(degree of zero) equation\n if (degree == 0) then\n print *, \"Please enyter your single value(intercept):\"\n read *, P(1)\n result = P(1)\n else ! for upper degrres of equations\n print *, \"Please enter the value of x:\"\n read *, x\n print *, \"Please enter polynomial coeffs using the form below:\"\n print *, \"ax**0 +- bx**1 +- cx**2 +- ... +- dx**n\"\n do i = 1, size(P)\n print *, \"Enter cefficient of x**\", i - 1, \":\"\n read *, P(i)\n end do\n do i = size(P), 1, -1\n result = result * x + P(i)\n end do\n end if\n ! printing the result\n print *, \"Result:\", result\nend program main", "meta": {"hexsha": "87a8af08d9525dab23bad9d3d05d5e11c213b8b7", "size": 1366, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical methods/Exercise_07.f90", "max_stars_repo_name": "EverLookNeverSee/FCS", "max_stars_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-14T10:30:25.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-17T13:03:15.000Z", "max_issues_repo_path": "src/numerical methods/Exercise_07.f90", "max_issues_repo_name": "EverLookNeverSee/FCS", "max_issues_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-06-06T13:54:45.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-25T20:32:23.000Z", "max_forks_repo_path": "src/numerical methods/Exercise_07.f90", "max_forks_repo_name": "EverLookNeverSee/FCS", "max_forks_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-08T12:57:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T12:57:46.000Z", "avg_line_length": 31.7674418605, "max_line_length": 78, "alphanum_fraction": 0.560761347, "num_tokens": 362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787536, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.7636202212893831}} {"text": " program demo_modulo\n implicit none\n print *, modulo(17,3) ! yields 2\n print *, modulo(17.5,5.5) ! yields 1.0\n\n print *, modulo(-17,3) ! yields 1\n print *, modulo(-17.5,5.5) ! yields 4.5\n\n print *, modulo(17,-3) ! yields -1\n print *, modulo(17.5,-5.5) ! yields -4.5\n end program demo_modulo\n", "meta": {"hexsha": "460d4d9362f9bd8e776bdb12489d5ff3c30fcfd1", "size": 374, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/modulo.f90", "max_stars_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_stars_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-12-31T17:21:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T15:56:29.000Z", "max_issues_repo_path": "example/modulo.f90", "max_issues_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_issues_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/modulo.f90", "max_forks_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_forks_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-06T15:56:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-06T15:56:31.000Z", "avg_line_length": 31.1666666667, "max_line_length": 51, "alphanum_fraction": 0.4973262032, "num_tokens": 125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.7636202207556229}} {"text": "module array_functions\n implicit none\n\ncontains\n function sumVector(vector) result(vecSum)\n intrinsic :: size\n integer, intent(in) :: vector(:)\n integer vecSum, i\n\n vecSum = 0\n do i = 1, size(vector)\n vecSum = vecSum + vector(i)\n end do\n end function sumVector\n\n subroutine sumVectorSub(vector, vecSum)\n integer, intent(in) :: vector(:)\n integer, intent(out) :: vecSum\n integer :: i\n\n vecSum = 0\n do i = 1, size(vector)\n vecSum = vecSum + vector(i)\n end do\n end subroutine sumVectorSub\n\n function prodVector(vector) result(vecprod)\n intrinsic :: size\n integer, intent(in) :: vector(:)\n integer vecprod, i\n\n vecprod = 1\n do i = 1, size(vector)\n vecprod = vecprod*vector(i)\n end do\n end function prodVector\n\n function minVector(vector) result(vecMin)\n intrinsic :: size\n integer, intent(in) :: vector(:)\n integer vecMin, i\n\n vecMin = vector(1)\n do i = 2, size(vector)\n if (vecMin > vector(i)) then\n vecMin = vector(i)\n end if\n end do\n end function minVector\n\n function maxVector(vector) result(vecMax)\n intrinsic :: size\n integer, intent(in) :: vector(:)\n integer vecMax, i\n\n vecMax = vector(1)\n do i = 2, size(vector)\n if (vecMax < vector(i)) then\n vecMax = vector(i)\n end if\n end do\n end function maxVector\n\n function dotProd(v, w) result(res)\n intrinsic :: size\n integer, intent(in) :: v(:), w(:)\n integer :: res, i\n\n res = 0\n do i = 1, size(v)\n res = res + v(i)*w(i)\n end do\n end function dotProd\n\nend module array_functions\n\nprogram main\n use array_functions\n implicit none\n intrinsic :: dot_product\n\n ! interface way to write functions\n ! interface\n ! function sumVector(vector) result(vecSum)\n ! integer, intent(in) :: vector(:)\n ! integer :: vecSum\n ! end function sumVector\n ! end interface\n\n integer, allocatable :: vec(:)\n integer :: status\n integer :: i, ndim, vecSum\n\n read (*, *) ndim\n allocate (vec(ndim), stat=status)\n write (*, *) \"Status \", status\n\n do i = 1, ndim\n vec(i) = i\n end do\n\n write (*, *) \"Sum of all elements (func)\", sumVector(vec)\n call sumVectorSub(vec, vecSum)\n write (*, *) \"Sum of all elements (sub)\", vecSum\n write (*, *) \"Product of all elements \", prodVector(vec)\n write (*, *) \"Minimal: \", minVector(vec), \"Maximal value: \", maxVector(vec)\n write (*, *) \"Dot product \", dotProd(vec, vec), dot_product(vec, vec)\n\n deallocate(vec, stat=status)\nend program main\n\n! interface way to write functions\n! function sumVector(vector) result (vecSum)\n! implicit none\n! intrinsic :: size\n! integer, intent(in) :: vector(:)\n! integer vecSum, i\n\n! vecSum = 0\n! do i = 1, size(vector)\n! vecSum = vecSum + vector(i)\n! end do\n! end function sumVector", "meta": {"hexsha": "a3cf83609d664f446d6b47447981235362ec8846", "size": 2804, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exercises/fortran-exercises/ex10-functions/app/main.f90", "max_stars_repo_name": "marvinfriede/projects", "max_stars_repo_head_hexsha": "7050cd76880c8ff0d9de17b8676e82f1929a68e0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exercises/fortran-exercises/ex10-functions/app/main.f90", "max_issues_repo_name": "marvinfriede/projects", "max_issues_repo_head_hexsha": "7050cd76880c8ff0d9de17b8676e82f1929a68e0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-04-14T20:15:26.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-14T20:20:54.000Z", "max_forks_repo_path": "exercises/fortran-exercises/ex10-functions/app/main.f90", "max_forks_repo_name": "marvinfriede/projects", "max_forks_repo_head_hexsha": "7050cd76880c8ff0d9de17b8676e82f1929a68e0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.7967479675, "max_line_length": 77, "alphanum_fraction": 0.6230385164, "num_tokens": 814, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759492, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.7635638750154154}} {"text": "!======================================================================================\n! Realiza un calculo aproximado del valor de pi mediante la generacion aleatoria\n! de puntos que se localizan dentro de un circulo unitario\n! Autor: Martin Alejandro Paredes Sosa\n!\n!======================================================================================\nModule Cte\n Implicit None\n Integer :: m , n !Acertados : Intentos\n Real, Parameter :: Pi = 3.1415\n Integer,Parameter :: Sav = 5 !DEBUG\n Integer, Parameter :: Seed1 = 3321, seed2 = 1815 !Semillas Posibles\nEnd Module Cte\n\n!==========================================\nSubroutine InOutCircle(x, y ,nNew) !CHECAR SE ESTA DENTRO DEL CIRCULO UNITARIO\n Use Cte\n Implicit None\n Real, Dimension(n) :: x , y\n Logical :: logic\n Integer :: i, nNew !indice\n\n RunPos: Do i = 1, nNew\n\n logic = x(i)*x(i) + y(i)*y(i) < 1 !CONDICION A CUMPILR\n ContIn:If (logic) Then !CUMPLIR CONDICION\n m = m+1 !AVANZAR CONTADOR DE EXITO\n End If ContIn\n \n End Do RunPos\n \nEnd Subroutine InOutCircle\n\n!=========================================\nSubroutine RPosc(x,y) !GENERAR POSICIONES ALEATORIAS EN \"X\" Y \"Y\"\n\n Use Cte\n Implicit None\n Integer :: i\n Real, Dimension(n) :: x , y\n\n Call Random_Number(x) !NUM ALEATORIO X\n Call Random_Number(y) !NUM ALEATORIO Y\n\n !Debug Probando Generador de las posiciones\n !Writedo : Do i=1,n\n ! Write(*,*) x(i),y(i)\n !End Do Writedo\n \nEnd Subroutine RPosc\n\n!==================================================\n\nProgram PiCalculation\n\n Use Cte\n Implicit None\n Integer :: l !INDICE DE CONTADOR\n Integer, Allocatable, Dimension(:) :: mm\n Real, Allocatable, Dimension (:) :: x , y, PiCalc, DelPi, ErrRel\n\n Write(*,*) \"Cuantos Intentos\" !INGRESANDO N\n Read(*,*) N\n\n Allocate( x(n),y(n) ) !ALOJANDO ESPACIO EN MEMORIA\n\n Call RPosc(x,y) !LLAMANDO SUBRUITNA PARA OBTENER POSICIONES\n Allocate( mm(n) ) !ALOJANDO ESPACIO EN MEMORIA\n \n Check: Do l = 1, n !CONSIDERACION DE DIFERENTES N (L, EVOLUCION DE N)\n \n Call InOutCircle(x,y,l) !LLAMANDO SUBRUTINA PARA CONDICION DEL CIRCULO\n mm(l) = m !GUARDANDO VALOR M PARA DIFERENTES N (ESTE CASO L)\n m=0 !REINICIANDO LA M\n End Do Check\n\n Deallocate (x,y) !DESALOJAR ESPCIO EN MEMORIA (SE BORRO LO GUARDADO)\n\n Allocate( PiCalc(n) )\n PiC: Do l=1, n !CALCULO DE PI EN SU EVOLUCION DE N\n PiCalc(l) = ( 4*real( mm(l) ) )/real(l) !CALCULANDO PI\n End Do PiC\n\n !CALCULANDO DELTA PI DESVIACION, ERROR RELATIVA\n ALLOCATE( DelPi(n), ErrRel(n) )\n DelPi = Pi - PiCalc\n ErrRel = DelPi / Pi\n\n Open(1,File= \"Table.dat\")\n \n WriteDo: Do l=1 , n\n Write(1,*) l,PiCalc(l), DelPi(l), ErrRel(l)\n End Do WriteDo\n\n DEALLOCATE(mm,PiCalc,DelPi,ErrRel) !DESALOJAR ESPACIO EN MEMORIA\n\nEnd Program PiCalculation\n\n\n", "meta": {"hexsha": "c8c94c6cbbb7a5d7e63313870581545a2e7fc7ad", "size": 3075, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Portafolio_I/Tarea_II/Act_1/Act1.f03", "max_stars_repo_name": "maps16/DesExpII", "max_stars_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Portafolio_I/Tarea_II/Act_1/Act1.f03", "max_issues_repo_name": "maps16/DesExpII", "max_issues_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Portafolio_I/Tarea_II/Act_1/Act1.f03", "max_forks_repo_name": "maps16/DesExpII", "max_forks_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.75, "max_line_length": 87, "alphanum_fraction": 0.5388617886, "num_tokens": 944, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91610961358942, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7634166711097923}} {"text": " \n real*8 FUNCTION FINTRP ( MODE, X, X1, F1, X2, F2 )\n\n\treal*8 X,X1, F1, X2, F2\nC\nC *FINTRP* INTERPOLATES BETWEEN X1 AND X2 USING A FUNCTIONAL\nC FORM THAT DEPENDS UPON THE SPECIFIED MODE. MODES - -\nC 1 = LINEAR - - A * X + B\nC 2 = EXPONENTIAL - - A * EXP( B * X )\nC 3 = POWER LAW - - A * X**B\nC\n\nc write(*,*)'X, X1, F1, X2, F2',X, X1, F1, X2, F2\n\n GO TO ( 10, 20, 30 ), MODE\nC\nC LINEAR INTERPOLATION\nC\n 10 F = F1 + ( F1 - F2 ) * ( X - X1 ) / ( X1 - X2 )\n GO TO 40\nC\nC EXPONENTIAL INTERPOLATION\nC\n 20 F = F1 * ( F1 / F2 )**( ( X - X1 ) / ( X1 - X2 ) )\n GO TO 40\nC\nC POWER LAW INTERPOLATION\nC\n 30 IF ( X1 .LE. 0. ) GO TO 20\n F = F1 * ( X / X1 )**( DLOG( F1 / F2 ) / DLOG( X1 / X2 ) )\nC\n 40 FINTRP = F\nc\twrite(*,*)'FINTRP',FINTRP\nC\n RETURN\n END\n", "meta": {"hexsha": "2da1a634c213b58535b8862deeccf9c15341f302", "size": 845, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/fintrp.f", "max_stars_repo_name": "phaustin/empm", "max_stars_repo_head_hexsha": "13bbb7c6568e374c973ea570b064f34a48c6cd8e", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/fintrp.f", "max_issues_repo_name": "phaustin/empm", "max_issues_repo_head_hexsha": "13bbb7c6568e374c973ea570b064f34a48c6cd8e", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/fintrp.f", "max_forks_repo_name": "phaustin/empm", "max_forks_repo_head_hexsha": "13bbb7c6568e374c973ea570b064f34a48c6cd8e", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2015-08-24T14:59:46.000Z", "max_forks_repo_forks_event_max_datetime": "2015-08-24T14:59:46.000Z", "avg_line_length": 22.8378378378, "max_line_length": 68, "alphanum_fraction": 0.4863905325, "num_tokens": 382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9688561694652215, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.7633919951879803}} {"text": " SUBROUTINE DK01MD( TYPE, N, A, INFO )\r\nC\r\nC SLICOT RELEASE 5.5.\r\nC\r\nC Copyright (c) 2002-2012 NICONET e.V.\r\nC\r\nC PURPOSE\r\nC\r\nC To apply an anti-aliasing window to a real signal.\r\nC\r\nC ARGUMENTS\r\nC\r\nC Mode Parameters\r\nC\r\nC TYPE CHARACTER*1\r\nC Indicates the type of window to be applied to the signal\r\nC as follows:\r\nC = 'M': Hamming window;\r\nC = 'N': Hann window;\r\nC = 'Q': Quadratic window.\r\nC\r\nC Input/Output Parameters\r\nC\r\nC N (input) INTEGER\r\nC The number of samples. N >= 1.\r\nC\r\nC A (input/output) DOUBLE PRECISION array, dimension (N)\r\nC On entry, this array must contain the signal to be\r\nC processed.\r\nC On exit, this array contains the windowing function.\r\nC\r\nC Error Indicator\r\nC\r\nC INFO INTEGER\r\nC = 0: successful exit;\r\nC < 0: if INFO = -i, the i-th argument had an illegal\r\nC value.\r\nC\r\nC METHOD\r\nC\r\nC If TYPE = 'M', then a Hamming window is applied to A(1),...,A(N),\r\nC which yields\r\nC _\r\nC A(i) = (0.54 + 0.46*cos(pi*(i-1)/(N-1)))*A(i), i = 1,2,...,N.\r\nC\r\nC If TYPE = 'N', then a Hann window is applied to A(1),...,A(N),\r\nC which yields\r\nC _\r\nC A(i) = 0.5*(1 + cos(pi*(i-1)/(N-1)))*A(i), i = 1,2,...,N.\r\nC\r\nC If TYPE = 'Q', then a quadratic window is applied to A(1),...,\r\nC A(N), which yields\r\nC _\r\nC A(i) = (1 - 2*((i-1)/(N-1))**2)*(1 - (i-1)/(N-1))*A(i),\r\nC i = 1,2,...,(N-1)/2+1;\r\nC _\r\nC A(i) = 2*(1 - ((i-1)/(N-1))**3)*A(i), i = (N-1)/2+2,...,N.\r\nC\r\nC REFERENCES\r\nC\r\nC [1] Rabiner, L.R. and Rader, C.M.\r\nC Digital Signal Processing.\r\nC IEEE Press, 1972.\r\nC\r\nC NUMERICAL ASPECTS\r\nC\r\nC The algorithm requires 0( N ) operations.\r\nC\r\nC CONTRIBUTOR\r\nC\r\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Feb. 1997.\r\nC Supersedes Release 2.0 routine DK01AD by R. Dekeyser, State\r\nC University of Gent, Belgium.\r\nC\r\nC REVISIONS\r\nC\r\nC -\r\nC\r\nC KEYWORDS\r\nC\r\nC Digital signal processing, Hamming window, Hann window, real\r\nC signals, windowing.\r\nC\r\nC ******************************************************************\r\nC\r\nC .. Parameters ..\r\n DOUBLE PRECISION PT46, HALF, PT54, ONE, TWO, FOUR\r\n PARAMETER ( PT46=0.46D0, HALF=0.5D0, PT54=0.54D0,\r\n $ ONE = 1.0D0, TWO=2.0D0, FOUR=4.0D0 )\r\nC .. Scalar Arguments ..\r\n CHARACTER TYPE\r\n INTEGER INFO, N\r\nC .. Array Arguments ..\r\n DOUBLE PRECISION A(*)\r\nC .. Local Scalars ..\r\n LOGICAL MTYPE, MNTYPE, NTYPE\r\n INTEGER I, N1\r\n DOUBLE PRECISION BUF, FN, TEMP\r\nC .. External Functions ..\r\n LOGICAL LSAME\r\n EXTERNAL LSAME\r\nC .. External Subroutines ..\r\n EXTERNAL XERBLA\r\nC .. Intrinsic Functions ..\r\n INTRINSIC ATAN, COS, DBLE\r\nC .. Executable Statements ..\r\nC\r\n INFO = 0\r\n MTYPE = LSAME( TYPE, 'M' )\r\n NTYPE = LSAME( TYPE, 'N' )\r\n MNTYPE = MTYPE.OR.NTYPE\r\nC\r\nC Test the input scalar arguments.\r\nC\r\n IF( .NOT.MNTYPE .AND. .NOT.LSAME( TYPE, 'Q' ) )\r\n $ THEN\r\n INFO = -1\r\n ELSE IF( N.LE.0 ) THEN\r\n INFO = -2\r\n END IF\r\nC\r\n IF ( INFO.NE.0 ) THEN\r\nC\r\nC Error return.\r\nC\r\n CALL XERBLA( 'DK01MD', -INFO )\r\n RETURN\r\n END IF\r\nC\r\n FN = DBLE( N-1 )\r\n IF( MNTYPE ) TEMP = FOUR*ATAN( ONE )/FN\r\nC\r\n IF ( MTYPE ) THEN\r\nC\r\nC Hamming window.\r\nC\r\n DO 10 I = 1, N\r\n A(I) = A(I)*( PT54 + PT46*COS( TEMP*DBLE( I-1 ) ) )\r\n 10 CONTINUE\r\nC\r\n ELSE IF ( NTYPE ) THEN\r\nC\r\nC Hann window.\r\nC\r\n DO 20 I = 1, N\r\n A(I) = A(I)*HALF*( ONE + COS( TEMP*DBLE( I-1 ) ) )\r\n 20 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Quadratic window.\r\nC\r\n N1 = ( N-1 )/2 + 1\r\nC\r\n DO 30 I = 1, N\r\n BUF = DBLE( I-1 )/FN\r\n TEMP = BUF**2\r\n IF ( I.LE.N1 ) THEN\r\n A(I) = A(I)*( ONE - TWO*TEMP )*( ONE - BUF )\r\n ELSE\r\n A(I) = A(I)*TWO*( ONE - BUF*TEMP )\r\n END IF\r\n 30 CONTINUE\r\nC\r\n END IF\r\nC\r\n RETURN\r\nC *** Last line of DK01MD ***\r\n END\r\n", "meta": {"hexsha": "79088623d50ecb64eadd39b97de6a6cee6c3f0d4", "size": 4442, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/DK01MD.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/DK01MD.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/DK01MD.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 26.1294117647, "max_line_length": 73, "alphanum_fraction": 0.4700585322, "num_tokens": 1444, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802529509909, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.7633884691521198}} {"text": "SUBROUTINE removal (num)\n IMPLICIT NONE\n integer(kind=8) num\n integer i\n integer, parameter :: ARR_SIZE = 2000000\n COMMON primes\n integer(kind=8), DIMENSION(ARR_SIZE) :: primes\n\n if (num /= 0) then\n do i=num+num, ARR_SIZE, num\n primes(i) = 0\n end do\n end if\nEND SUBROUTINE removal\n\nprogram problem_10\n integer(kind=8) i\n integer, parameter :: ARR_SIZE = 2000000\n integer(kind=8), DIMENSION(ARR_SIZE) :: primes\n integer(kind=8) total\n integer(kind=8) rez\n integer(kind=8) lg_sum\n COMMON primes\n total = 0\n\n ! Set primes to 1, 2, .. ARR_SIZE\n primes = (/ (i, i = 1, ARR_SIZE) /)\n primes(1) = 0\n ! Using: Sieve of Eratosthenes\n do i=1, ARR_SIZE\n CALL removal(primes(i))\n total = total + primes(i)\n end do\n\n print *,\"Problem 10:\", total\n\n\nend program problem_10\n\n", "meta": {"hexsha": "b46a45a9bbc7c399e13d01d8b966eb1d99e29f9a", "size": 869, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/problem_10.f90", "max_stars_repo_name": "deidyomega/project_euler", "max_stars_repo_head_hexsha": "2e160c8c379f083cc233c985c1d3a0d65621bf15", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/problem_10.f90", "max_issues_repo_name": "deidyomega/project_euler", "max_issues_repo_head_hexsha": "2e160c8c379f083cc233c985c1d3a0d65621bf15", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/problem_10.f90", "max_forks_repo_name": "deidyomega/project_euler", "max_forks_repo_head_hexsha": "2e160c8c379f083cc233c985c1d3a0d65621bf15", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.725, "max_line_length": 50, "alphanum_fraction": 0.6052934407, "num_tokens": 276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148512, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7633616956064129}} {"text": "program main\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n integer, allocatable :: seed(:)\n integer :: n\n integer :: i\n interface\n function Discrete_varible()\n ! 离散随机变量产生器\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n real(dp) :: Discrete_varible\n end function Discrete_varible\n\n function Poisson(lambda)\n ! Poisson 分布\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n integer, intent(in) :: lambda\n real(dp) :: Poisson\n end function Poisson\n end interface\n\n call random_seed(size=n)\n allocate(seed(n))\n seed = 1\n call random_seed(put=seed)\n do i = 1, 100\n write(*,*) Discrete_varible()\n end do\n\n do i = 1, 100\n write(*,*) Poisson(1)\n end do\nend program main\n\nfunction Discrete_varible()\n ! 离散随机变量产生器\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n real(dp) :: Discrete_varible\n\n real(dp) :: xi\n integer :: i\n real(dp), parameter :: p(3) = [1 / 4.d0, 5 / 8.d0, 1 / 8.d0]\n real(dp), parameter :: x(3) = [1.d0, 2.d0, 3.d0]\n\n call random_number(xi)\n i = 1\n do while (xi >= sum(p(:i)))\n i = i + 1\n end do\n Discrete_varible = x(i)\nend function Discrete_varible\n\nfunction Poisson(lambda)\n ! Poisson 分布\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n integer, intent(in) :: lambda\n real(dp) :: Poisson\n\n real(dp) :: xi\n integer :: i\n real(dp) :: sum_of_p_n\n\n call random_number(xi)\n xi = xi * exp(dble(lambda))\n i = 0\n sum_of_p_n = lambda**i / dble(factorial(i))\n do while (xi >= sum_of_p_n)\n i = i + 1\n sum_of_p_n = sum_of_p_n + lambda**i / dble(factorial(i))\n end do\n Poisson = i\n\n contains\n function factorial(n)\n implicit none\n\n integer, intent(in) :: n\n integer :: factorial\n\n integer :: i\n\n factorial = 1\n do i = 1, n\n factorial = factorial * i\n end do\n end function factorial\nend function Poisson", "meta": {"hexsha": "0b5f157566b38807fd8166163da745955e7054b6", "size": 2193, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Chap1-Monte-Carlo-Method-Basic/1.2.1.1-Discrete-Variable-Distribution.f90", "max_stars_repo_name": "Chen-Jialin/Computational-Physics-Practice", "max_stars_repo_head_hexsha": "5bbb271123ee75727d266e6ca83d090ad8919abb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chap1-Monte-Carlo-Method-Basic/1.2.1.1-Discrete-Variable-Distribution.f90", "max_issues_repo_name": "Chen-Jialin/Computational-Physics-Practice", "max_issues_repo_head_hexsha": "5bbb271123ee75727d266e6ca83d090ad8919abb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chap1-Monte-Carlo-Method-Basic/1.2.1.1-Discrete-Variable-Distribution.f90", "max_forks_repo_name": "Chen-Jialin/Computational-Physics-Practice", "max_forks_repo_head_hexsha": "5bbb271123ee75727d266e6ca83d090ad8919abb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.84375, "max_line_length": 64, "alphanum_fraction": 0.5567715458, "num_tokens": 631, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642905, "lm_q2_score": 0.8354835330070838, "lm_q1q2_score": 0.7633616917711872}} {"text": "*DECK ALBETA\n FUNCTION ALBETA (A, B)\nC***BEGIN PROLOGUE ALBETA\nC***PURPOSE Compute the natural logarithm of the complete Beta\nC function.\nC***LIBRARY SLATEC (FNLIB)\nC***CATEGORY C7B\nC***TYPE SINGLE PRECISION (ALBETA-S, DLBETA-D, CLBETA-C)\nC***KEYWORDS FNLIB, LOGARITHM OF THE COMPLETE BETA FUNCTION,\nC SPECIAL FUNCTIONS\nC***AUTHOR Fullerton, W., (LANL)\nC***DESCRIPTION\nC\nC ALBETA computes the natural log of the complete beta function.\nC\nC Input Parameters:\nC A real and positive\nC B real and positive\nC\nC***REFERENCES (NONE)\nC***ROUTINES CALLED ALNGAM, ALNREL, GAMMA, R9LGMC, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 770701 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 900727 Added EXTERNAL statement. (WRB)\nC***END PROLOGUE ALBETA\n EXTERNAL GAMMA\n SAVE SQ2PIL\n DATA SQ2PIL / 0.9189385332 0467274 E0 /\nC***FIRST EXECUTABLE STATEMENT ALBETA\n P = MIN (A, B)\n Q = MAX (A, B)\nC\n IF (P .LE. 0.0) CALL XERMSG ('SLATEC', 'ALBETA',\n + 'BOTH ARGUMENTS MUST BE GT ZERO', 1, 2)\n IF (P.GE.10.0) GO TO 30\n IF (Q.GE.10.0) GO TO 20\nC\nC P AND Q ARE SMALL.\nC\n ALBETA = LOG(GAMMA(P) * (GAMMA(Q)/GAMMA(P+Q)) )\n RETURN\nC\nC P IS SMALL, BUT Q IS BIG.\nC\n 20 CORR = R9LGMC(Q) - R9LGMC(P+Q)\n ALBETA = ALNGAM(P) + CORR + P - P*LOG(P+Q) +\n 1 (Q-0.5)*ALNREL(-P/(P+Q))\n RETURN\nC\nC P AND Q ARE BIG.\nC\n 30 CORR = R9LGMC(P) + R9LGMC(Q) - R9LGMC(P+Q)\n ALBETA = -0.5*LOG(Q) + SQ2PIL + CORR + (P-0.5)*LOG(P/(P+Q))\n 1 + Q*ALNREL(-P/(P+Q))\n RETURN\nC\n END\n", "meta": {"hexsha": "4ed6aca97a041c45ea9d496e8e18f6129dc5ba7c", "size": 1866, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/albeta.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/albeta.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/albeta.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.15625, "max_line_length": 67, "alphanum_fraction": 0.6259378349, "num_tokens": 723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7632899651822606}} {"text": "! jacobian calculation\nsubroutine r_jacob(x,xj,xji,det)\n use solid_variables, only:nsd_solid,nen_solid\n use r_common\n implicit none\n\n real(8) :: x(nsd_solid,nen_solid),xj(nsd_solid,nsd_solid),xji(nsd_solid,nsd_solid),cf(nsd_solid,nsd_solid)\n real(8),intent(out) :: det\n real(8) :: dum\n integer :: i,j,k\n\n !...compute the jacobians\n do i=1,nsd_solid\n do j=1,nsd_solid\n dum = 0.0d0\n do k=1,nen_solid\n dum = dum + r_p(j,k)*x(i,k)\n enddo\n xj(i,j) = dum\n enddo\n enddo\n !...compute the determinant of the jacobian matrix\n\n threedim: if (nsd_solid .eq. 3) then \n !...3-D determinant\n cf(1,1) = + (xj(2,2)*xj(3,3) - xj(2,3)*xj(3,2))\n cf(1,2) = - (xj(2,1)*xj(3,3) - xj(2,3)*xj(3,1))\n cf(1,3) = + (xj(2,1)*xj(3,2) - xj(2,2)*xj(3,1))\n cf(2,1) = - (xj(1,2)*xj(3,3) - xj(1,3)*xj(3,2))\n cf(2,2) = + (xj(1,1)*xj(3,3) - xj(1,3)*xj(3,1))\n cf(2,3) = - (xj(1,1)*xj(3,2) - xj(1,2)*xj(3,1))\n cf(3,1) = + (xj(1,2)*xj(2,3) - xj(1,3)*xj(2,2))\n cf(3,2) = - (xj(1,1)*xj(2,3) - xj(1,3)*xj(2,1))\n cf(3,3) = + (xj(1,1)*xj(2,2) - xj(1,2)*xj(2,1))\n\n det = - ( xj(1,1) * cf(1,1) + &\n xj(1,2) * cf(1,2) + &\n xj(1,3) * cf(1,3) )\n! write(*,*) 'jacobi in r_jacobian', det\n if (det .lt. 1.0d-15) then\n write(*,100) \n stop\n!\tdet=-det\n endif\n100 format(6x, 'error, zero or negative jacobian determinant')\n\n\n!...compute the inverse of the jacobian matrix\n xji(1,1) = cf(1,1)/det\n xji(1,2) = cf(2,1)/det\n xji(1,3) = cf(3,1)/det\n xji(2,1) = cf(1,2)/det\n xji(2,2) = cf(2,2)/det\n xji(2,3) = cf(3,2)/det\n xji(3,1) = cf(1,3)/det\n xji(3,2) = cf(2,3)/det\n xji(3,3) = cf(3,3)/det\n\n endif threedim\n\n twodim: if (nsd_solid .eq. 2) then \n !...2-D determinant\n det = ( xj(1,1) * xj(2,2) - &\n xj(1,2) * xj(2,1) )\n\n if (det .lt. 1.0d-15) then\n write(*,100) \n stop\n endif\n\t\n!...compute the inverse of the jacobian matrix\n xji(1,1) = xj(2,2)/det\n xji(1,2) = -xj(1,2)/det\n xji(2,1) = -xj(2,1)/det\n xji(2,2) = xj(1,1)/det\n\n\tendif twodim\n\n return\nend subroutine r_jacob\n", "meta": {"hexsha": "38b25e59d2025620bccb4a71f3335b2f224cc6c2", "size": 2043, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "r_jacob.f90", "max_stars_repo_name": "biofluids/IFEM-archive", "max_stars_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-15T11:40:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-15T11:40:16.000Z", "max_issues_repo_path": "r_jacob.f90", "max_issues_repo_name": "biofluids/IFEM-archive", "max_issues_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "r_jacob.f90", "max_forks_repo_name": "biofluids/IFEM-archive", "max_forks_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-11T16:50:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T07:24:59.000Z", "avg_line_length": 25.2222222222, "max_line_length": 108, "alphanum_fraction": 0.5364659814, "num_tokens": 1078, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7632899588776755}} {"text": "!******************************************************************************\n!** GETTING INVERS OF A MATRIX **\n!******************************************************************************\nsubroutine inverse(a,n,ainv)\n implicit none\n!dummy arguments\n integer :: n\n REAL(8) :: A(N,N)\n REAL(8) :: AINV(N,N)\n!local arguments\n INTEGER :: I,J,K,L\n REAL(KIND=8) :: M,MAUM(N,2*N)\n!sE CREA LA MATRIZ AUMENTADA\n DO I=1,N\n DO J=1,2*N\n IF (J<=N) THEN\n MAUM(I,J)=A(I,J)\n ELSE IF ((I+N)==J) THEN\n MAUM(I,J)=1.D0\n ELSE\n MAUM(I,J)=0.D0\n END IF\n END DO\n END DO\n!SE REDUCE LA MATRIZ A UNA TRIANGULAR superior por eliminacion\n DO K=1,N-1\n DO J=K+1,N\n M=MAUM(J,K)/MAUM(K,K)\n DO I=K,2*N\n MAUM(J,I)=MAUM(J,I)-M*MAUM(K,I)\n END DO\n END DO\n END DO\n!elementos de la diagonal iguales a 1\n DO I=1,N\n M=MAUM(I,I)\n DO J=I,2*N\n MAUM(I,J)=MAUM(I,J)/M\n END DO\n END DO\n!DIAGONALIZACION\n DO K=N-1,1,-1\n DO I=1,K\n M=MAUM(I,K+1)\n DO J=K,2*N\n MAUM(I,J)=MAUM(I,J)-MAUM(K+1,J)*M\n END DO\n END DO\n END DO\n!ALMACENAMIENTO\n DO I=1,N\n DO J=1,N\n AINV(I,J)=MAUM(I,J+N)\n END DO\n END DO\nend subroutine inverse\n", "meta": {"hexsha": "b577e02632a2510a182b5d4abe5fc3f1f54eeef0", "size": 1213, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/inverse.f90", "max_stars_repo_name": "jdlaubrie/shell-elem", "max_stars_repo_head_hexsha": "f87cb9ca9179533d3a645a494e7ef4d39666ddc6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/inverse.f90", "max_issues_repo_name": "jdlaubrie/shell-elem", "max_issues_repo_head_hexsha": "f87cb9ca9179533d3a645a494e7ef4d39666ddc6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/inverse.f90", "max_forks_repo_name": "jdlaubrie/shell-elem", "max_forks_repo_head_hexsha": "f87cb9ca9179533d3a645a494e7ef4d39666ddc6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.2807017544, "max_line_length": 79, "alphanum_fraction": 0.4715581204, "num_tokens": 436, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.8289388104343893, "lm_q1q2_score": 0.7632782949896638}} {"text": "PROGRAM gravity\nIMPLICIT NONE\n REAL, PARAMETER :: G = 6.672E-11 ! Gravitational constant in N m**2/kg**2\n REAL, PARAMETER :: M = 5.98E+24 ! Mass of the Earth in kg\n REAL, PARAMETER :: R = 6371.0 ! Mean radius of the Earth in km\n REAL :: h ! Height in km\n REAL :: start_height = 40000.0 ! Starting height\n REAL :: inc = 500.0 ! Height increment in km\n REAL :: result ! Acceleration due to gravity at height h\n INTEGER :: index\n\n h = start_height\n WRITE(*, 100) \"Height (km)\",\"Accel (m/s^2)\"\n WRITE(*, 100) \"-----------\",\"-------------\"\n 100 FORMAT (1X,A11,2X,A13)\n DO index = 0, INT(start_height / inc)\n result = -G * (M / (R + h)**2)\n WRITE(*,'(F12.1,2X,ES13.3)') h, result\n h = h - inc\n END DO\n\nEND PROGRAM gravity\n", "meta": {"hexsha": "7c34c6ca89852e47530d4e490be180af6d816d9f", "size": 739, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap5/gravity.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap5/gravity.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap5/gravity.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.1304347826, "max_line_length": 75, "alphanum_fraction": 0.600811908, "num_tokens": 259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810496235896, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.7632406643864545}} {"text": "C$Procedure MXV ( Matrix times vector, 3x3 )\n \n SUBROUTINE MXV ( MATRIX, VIN, VOUT )\n \nC$ Abstract\nC\nC Multiply a 3x3 double precision matrix with a 3-dimensional\nC double precision vector.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC MATRIX\nC VECTOR\nC\nC$ Declarations\n \n DOUBLE PRECISION MATRIX ( 3,3 )\n DOUBLE PRECISION VIN ( 3 )\n DOUBLE PRECISION VOUT ( 3 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC MATRIX I 3x3 double precision matrix.\nC VIN I 3-dimensional double precision vector.\nC VOUT O 3-dimensinoal double precision vector. VOUT is\nC the product MATRIX*VIN.\nC\nC$ Detailed_Input\nC\nC MATRIX is an arbitrary 3x3 double precision matrix.\nC\nC VIN is an arbitrary 3-dimensional double precision vector.\nC\nC$ Detailed_Output\nC\nC VOUT is a 3-dimensional double precision vector. VOUT is\nC the product MATRIX * V.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC The code reflects precisely the following mathematical expression\nC\nC For each value of the subscript I from 1 to 3:\nC\nC VOUT(I) = Summation from K=1 to 3 of ( MATRIX(I,K) * VIN(K) )\nC\nC$ Examples\nC\nC Let\nC\nC MATRIX = | 0.0D0 1.0D0 0.0D0 | and VIN = | 1.0D0 |\nC | | | |\nC | -1.0D0 0.0D0 0.0D0 | | 2.0D0 |\nC | | | |\nC | 0.0D0 0.0D0 1.0D0 | | 3.0D0 |\nC\nC Then the call,\nC\nC CALL MXV ( MATRIX, VIN, VOUT )\nC\nC produces the vector\nC\nC VOUT = | 2.0D0 |\nC | |\nC | -1.0D0 |\nC | |\nC | 3.0D0 |\nC\nC\nC$ Restrictions\nC\nC The user is responsible for checking the magnitudes of the\nC elements of MATRIX and VIN so that a floating point overflow does\nC not occur.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.M. Owen (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.2, 22-APR-2010 (NJB)\nC\nC Header correction: assertions that the output\nC can overwrite the input have been removed.\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WMO)\nC\nC-&\n \nC$ Index_Entries\nC\nC matrix times 3-dimensional vector\nC\nC-&\n \n \n DOUBLE PRECISION PRODV(3)\n INTEGER I\n\nC\nC Perform the matrix-vector multiplication\nC\n DO I = 1, 3\n PRODV(I) = MATRIX(I,1)*VIN(1) +\n . MATRIX(I,2)*VIN(2) +\n . MATRIX(I,3)*VIN(3)\n END DO\nC\nC Move the buffered vector into the output vector VOUT.\nC\n VOUT(1) = PRODV(1)\n VOUT(2) = PRODV(2)\n VOUT(3) = PRODV(3)\n \n RETURN\n END\n", "meta": {"hexsha": "72195bfbc28614a5216a25fb97bcb420c5a0a15c", "size": 4481, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/mxv.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/mxv.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/mxv.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 26.3588235294, "max_line_length": 71, "alphanum_fraction": 0.6052220486, "num_tokens": 1358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810451666346, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7632406563746309}} {"text": "! Created by EverLookNeverSee@GitHub on 4/23/20.\n! This program calculates the GCD betwen two numbers.\n\nprogram gcd\n implicit none\n ! declaring variables\n integer :: num_1, num_2, temp\n ! gettig user input\n print *, \"Enter two positive integers:\"\n read *, num_1, num_2\n temp = mod(num_1, num_2)\n if (temp == 0) then\n print *, \"The gcd of\", num_1, \"and\", num_2, \"is\", num_2\n stop\n end if\n do while (temp /= 0)\n num_1 = num_2\n num_2 = temp\n temp = mod(num_1, num_2)\n end do\n print *, \"The gcd is\", num_2\nend program gcd", "meta": {"hexsha": "b166ae5c5251cc2779501fd31427a8acf38e1c1d", "size": 588, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/other/gcd.f90", "max_stars_repo_name": "EverLookNeverSee/FCS", "max_stars_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-14T10:30:25.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-17T13:03:15.000Z", "max_issues_repo_path": "src/other/gcd.f90", "max_issues_repo_name": "EverLookNeverSee/FCS", "max_issues_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-06-06T13:54:45.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-25T20:32:23.000Z", "max_forks_repo_path": "src/other/gcd.f90", "max_forks_repo_name": "EverLookNeverSee/FCS", "max_forks_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-08T12:57:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T12:57:46.000Z", "avg_line_length": 26.7272727273, "max_line_length": 63, "alphanum_fraction": 0.6020408163, "num_tokens": 193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237604, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7632223173104271}} {"text": "! Solve \n! phi_t = k phi_xx \n! using explicit method\n! 2nd order centred in space, 1st order fwd in time\n\nprogram explicit1d\n\n implicit none\n\n integer, parameter :: num=selected_real_kind(p=15) !p=6 or 15\n real(num) :: x_min, x_max, x_c, dx\n real(num) :: time, t_end , dt, dtk\n integer :: step, nsteps\n integer :: ix\n integer :: nx \n real(num) :: C, k, phi1, phi2, t0\n real(num), allocatable, dimension(:) :: phi, x, phi_new, phi_analytic\n integer :: out_unit = 10 \n\n !user control\n t_end = 0.008_num\n nx = 16 \n x_min = 0.0_num\n x_max = 1.0_num\n x_c = (x_max - x_min) / 2.0_num\n nsteps = 100 !max number of steps\n C = 0.8_num ! CFL-like factor in time step, le 1 required\n\n !initial condition optin\n\n k = 1.0 ! diffusion coefficient\n t0 = 0.001_num !constant in initial condition, NOT the initial time\n time = 0.0_num !initial time\n phi2 = 2.0_num \n phi1 = 1.0_num\n\n\n ! initialise the arrays and fill grid, 1 ghost cell needed\n\n allocate(x(0:nx+1))\n allocate(phi(0:nx+1))\n allocate(phi_new(0:nx+1))\n\n dx = (x_max - x_min) / REAL(nx-1,num) \n x(0) = x_min - dx\n do ix = 1, nx+1\n x(ix) = x(ix-1) + dx\n enddo\n\n ! set the initial condition on phi\n phi = 0.0_num\n do ix = 1, nx \n phi(ix) = (phi2-phi1) * (t0/(time + t0))**0.5_num * &\n & exp(-(x(ix)-x_c)**2 / 4.0_num / k / (time+t0)) + phi1\n enddo \n\n\n !main loop \n\n step = 0\n dt = 0.5_num * C * dx**2 / k \n dtk = dt * k \n do\n if ((step >= nsteps .and. nsteps >= 0) .or. (time >= t_end)) exit\n\n step = step+1\n time = time + dt\n print *, step,time\n\n !set bc (simple Dirichlet)\n phi(0) = phi1\n phi(nx+1) = phi1\n\n !loop through domain\n do ix = 1, nx \n phi_new(ix) = phi(ix) + & \n & dtk * (phi(ix+1) - 2.0_num * phi(ix) + phi(ix-1))/dx**2 \n enddo !ix = 1, nx\n\n phi = phi_new\n\n enddo\n\n ! Output\n\n call execute_command_line(\"rm -rf x*.dat phi*.dat\")\n !^ dont stream to existing *dat files\n\n ! output numerical solution\n open(out_unit, file=\"x.dat\", access=\"stream\")\n write(out_unit) x(1:nx)\n close(out_unit)\n open(out_unit, file=\"phi.dat\", access=\"stream\")\n write(out_unit) phi(1:nx)\n close(out_unit)\n\n ! calculate and output analytical sln and corresponding grid,\n ! at several times the resolution to better-sample the continuous sln \n\n if (nx <= 2**14) then\n deallocate(x)\n nx = nx * 16 \n allocate(x(0:nx+1))\n dx = (x_max - x_min) / REAL(nx-1,num) \n x(0) = x_min - dx\n do ix = 1, nx+1\n x(ix) = x(ix-1) + dx\n enddo\n endif \n\n allocate(phi_analytic(0:nx+1))\n do ix = 0,nx+1\n phi_analytic(ix) = (phi2-phi1) * (t0/(time + t0))**0.5_num * &\n & exp(-(x(ix)-x_c)**2 / 4.0_num / k / (time+t0)) + phi1\n enddo\n\n open(out_unit, file=\"x_analytic.dat\", access=\"stream\")\n write(out_unit) x(1:nx)\n close(out_unit)\n\n open(out_unit, file=\"phi_analytic.dat\", access=\"stream\")\n write(out_unit) phi_analytic(1:nx)\n close(out_unit)\n \n call execute_command_line(\"python plot1.py\")\n\n\nend program explicit1d\n\n\n", "meta": {"hexsha": "8234e3d4d464655e0e633d5881b588f4e375fd1a", "size": 2987, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "diffusion/explicit1d.f90", "max_stars_repo_name": "JOThurgood/SimpleCFD", "max_stars_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-23T05:31:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-04T23:21:11.000Z", "max_issues_repo_path": "diffusion/explicit1d.f90", "max_issues_repo_name": "JOThurgood/SimpleCFD", "max_issues_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 39, "max_issues_repo_issues_event_min_datetime": "2018-08-31T23:48:02.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-07T10:03:11.000Z", "max_forks_repo_path": "diffusion/explicit1d.f90", "max_forks_repo_name": "JOThurgood/SimpleCFD", "max_forks_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-11-14T20:42:54.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-18T09:16:27.000Z", "avg_line_length": 22.8015267176, "max_line_length": 72, "alphanum_fraction": 0.6059591563, "num_tokens": 1109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7632223132698506}} {"text": "!***********************************************************************\n\n program depth_profile\n\n!-----------------------------------------------------------------------\n!\n! computes layer thicknesses for each level for POP ocean code\n!\n!-----------------------------------------------------------------------\n\n implicit none\n\n integer, parameter :: \n & km = 20 ! number of vertical levels\n\n real, parameter ::\n & zmax = 5500.0, ! max depth in meters\n & dz_sfc = 25.0, ! thickness of surface layer\n & dz_deep = 400.0, ! thickness of deep ocean layers\n & eps = 1.e-6 ! convergence criterion \n\n real, dimension(km) :: \n & z, ! depth at bottom of layer\n & dz ! layer thickness of each layer\n\n real ::\n & depth, ! depth based on integrated thicknesses\n & zlength, ! adjustable parameter for thickness\n & d0, d1, ! depths used by midpoint search\n & zl0, zl1, ! parameter used by midpoint search\n & dzl ! zl1-zl0\n\n integer k\n\n!-----------------------------------------------------------------------\n!\n! initialize bisection search to find best value of zlength\n! parameter such that integrated depth = zmax\n!\n!-----------------------------------------------------------------------\n\n zl0 = eps\n zl1 = zmax\n dzl = zl1 - zl0\n\n call compute_dz(dz,d0,zl0,dz_sfc,dz_deep,km)\n call compute_dz(dz,d1,zl1,dz_sfc,dz_deep,km)\n\n if ((d0-zmax)*(d1-zmax) > 0.0) then\n print *,d0,d1,zmax\n stop 'zero point not in initial interval'\n endif\n\n!-----------------------------------------------------------------------\n!\n! do bisection search\n!\n!-----------------------------------------------------------------------\n\n do while ( (dzl/zmax) > eps)\n\n !***\n !*** compute profile at midpoint\n !***\n\n zlength = zl0 + 0.5*dzl\n\n call compute_dz(dz,depth,zlength,dz_sfc,dz_deep,km)\n\n !***\n !*** find interval to use for continuing search\n !***\n\n if ((d0-zmax)*(depth-zmax) < 0.0) then\n d1 = depth\n zl1 = zlength\n else if ((d1-zmax)*(depth-zmax) < 0.0) then\n d0 = depth\n zl0 = zlength\n else\n print *,d0,d1,depth,zmax\n stop 'zero point not in interval'\n endif\n\n dzl = zl1 - zl0\n\n end do\n\n!-----------------------------------------------------------------------\n!\n! presumably, we have converged, but check to make sure\n!\n!-----------------------------------------------------------------------\n\n print *,'Integrated depth = ',depth,' zmax = ',zmax\n\n!-----------------------------------------------------------------------\n!\n! write results to file and stdout\n!\n!-----------------------------------------------------------------------\n\n open(12,file='in_depths.dat',form='formatted',status='unknown')\n\n depth = 0.0\n do k =1,km\n depth = depth + dz(k)\n\n print *,k,dz(k),depth\n write(12,*) dz(k)*100.,' ! ',depth\n end do\n\n close(12)\n\n!-----------------------------------------------------------------------\n\n end program depth_profile\n\n!***********************************************************************\n\n subroutine compute_dz(dz,depth,zlength,dz_sfc,dz_deep,km)\n\n!-----------------------------------------------------------------------\n!\n! computes a thickness profile and total depth given the \n! parameters for the thickness function\n!\n!-----------------------------------------------------------------------\n!-----------------------------------------------------------------------\n!\n! input variables\n!\n!-----------------------------------------------------------------------\n\n integer, intent(in) ::\n & km ! number of vertical levels\n\n real, intent(in) ::\n & zlength, ! gaussian parameter for thickness func\n & dz_sfc, ! thickness of surface layer\n & dz_deep ! thickness of deep ocean layers\n\n!-----------------------------------------------------------------------\n!\n! output variables\n!\n!-----------------------------------------------------------------------\n\n real, dimension(km), intent(out) :: \n & dz ! layer thickness of each layer\n\n real, intent(out) ::\n & depth ! depth based on integrated thicknesses\n\n!-----------------------------------------------------------------------\n!\n! local variables\n!\n!-----------------------------------------------------------------------\n\n integer k\n\n!-----------------------------------------------------------------------\n\n depth = 0.0\n\n do k=1,km\n\n dz(k) = dz_deep - (dz_deep - dz_sfc)*exp(-(depth/zlength)**2)\n depth = depth + dz(k)\n\n end do\n\n!-----------------------------------------------------------------------\n\n end subroutine compute_dz\n\n!***********************************************************************\n", "meta": {"hexsha": "a173dcb1fe3316fb590aba0361c5896c576782cb", "size": 5143, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/RunTests/FortranTests/LANL_POP/pop-distro/tools/grid/depths.f", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/RunTests/FortranTests/LANL_POP/pop-distro/tools/grid/depths.f", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/RunTests/FortranTests/LANL_POP/pop-distro/tools/grid/depths.f", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 28.7318435754, "max_line_length": 72, "alphanum_fraction": 0.3513513514, "num_tokens": 1030, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541544761565, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7631908249987647}} {"text": "INCLUDE 'pib_mod.f03'\n program pib_02\n USE pib_mod\n!\n! USAGE:\n! ./pib_02.exe \n!\n! ABOUT:\n! This program builds and prints the Hamiltonian for the modified Particle-\n! in-a-Box (mPIB) problem. In this problem, the standard PIB potential is\n! modified to include a linear potential within the box (0 < x < L) given by\n! V(x) = bx.\n!\n! This program accepts command line arguments for the mass, box length,\n! slope parameter b, and the number of basis functions to use (nBasis; taken\n! to mean the first nBasis PIB eigenfunctions). The program reports kinetic\n! energy, potential energy, and Hamiltonian matrices.\n!\n! All input and results are taken to be in atomic units.\n!\n!\n! H. P. Hratchian, 2020.\n!\n!\n! Variable Declarations\n!\n implicit none\n integer::i,j,k,nArguments,nBasis,lapackInfo\n real::mass,boxLength,slope\n real,dimension(:),allocatable::hamiltonianEVals,lapackWork\n real,dimension(:,:),allocatable::kineticEnergyMatrix, &\n potentialEnergyMatrix,hamiltonianMatrix,hamiltonianEVecs\n character(len=256)::commandLineArg\n logical::fail=.false.\n!\n! Format Statements\n!\n 1000 Format('Modified Particle-in-a-Box Program.'/,'Unit Test 2.',/,/, &\n 'Input Parameters:',/, &\n 2x,'mass = ',F10.3,/, &\n 2x,'boxLength = ',F10.3,/, &\n 2x,'slope = ',F10.3,/, &\n 2x,'nBasis = ',I4,/)\n 2000 Format('< i | T | j > = ')\n 2010 Format('< i | V | j > = ')\n 2020 Format('< i | H | j > = ')\n 9000 Format('Incorrect number of command line arguments.',/, &\n 'Expected 5 but found ',I2,'.'/, &\n 'The list of arguments is:',/, &\n 3x,' ')\n 9100 Format('Input parameter ',A,' must be greater than 0.')\n 9200 Format('Failure solving for Hamiltonian eigensystem.')\n 9999 Format(/,'PROGRAM FAILED!')\n!\n! Find out how many command line arguments there are, ensure it's the right\n! number, read-in the values, and echo the input as output.\n!\n nArguments = COMMAND_ARGUMENT_COUNT()\n if(nArguments.ne.4) then\n write(iOut,9000) nArguments\n fail = .true.\n goto 999\n endIf\n call GET_COMMAND_ARGUMENT(1,commandLineArg)\n read(commandLineArg,*) mass\n call GET_COMMAND_ARGUMENT(2,commandLineArg)\n read(commandLineArg,*) boxLength\n call GET_COMMAND_ARGUMENT(3,commandLineArg)\n read(commandLineArg,*) slope\n call GET_COMMAND_ARGUMENT(4,commandLineArg)\n read(commandLineArg,*) nBasis\n write(iOut,1000) mass,boxLength,slope,nBasis\n if(mass.le.0) then\n write(iOut,9100) 'mass'\n fail = .true.\n endIf\n if(boxLength.le.0) then\n write(iOut,9100) 'boxLength'\n fail = .true.\n endIf\n if(slope.le.0) then\n write(iOut,9100) 'slope'\n fail = .true.\n endIf\n if(fail) goto 999\n!\n! Allocate memory for the kinetic, potential, and Hamiltonian matrices.\n!\n Allocate(kineticEnergyMatrix(nBasis,nBasis), &\n potentialEnergyMatrix(nBasis,nBasis), &\n hamiltonianMatrix(nBasis,nBasis))\n!\n! Calculate the kinetic energy matrix element.\n!\n do i = 1,nBasis\n do j = 1,nBasis\n kineticEnergyMatrix(i,j) = kineticEnergy(mass,boxLength,i,j)\n potentialEnergyMatrix(i,j) = potentialEnergy(mass,boxLength,slope,i,j)\n endDo\n endDo\n hamiltonianMatrix = kineticEnergyMatrix + potentialEnergyMatrix\n!\n! Print out the kinetic energy, potential energy, and Hamiltonian matrices.\n!\n write(iOut,2000)\n call print_matrix(kineticEnergyMatrix)\n write(iOut,2010)\n call print_matrix(potentialEnergyMatrix)\n write(iOut,2020)\n call print_matrix(hamiltonianMatrix)\n!\n! Diagonalize the Hamiltonian and report eigenvectors and eigenvalues.\n!\n allocate(hamiltonianEVecs(nbasis,nBasis))\n allocate(hamiltonianEVals(nBasis),lapackWork(3*nBasis))\n write(iOut,*)' Hrant - here is the linearized hamiltonian...'\n hamiltonianEVecs = hamiltonianMatrix\n call SSYEV('V','L',nBasis,hamiltonianEVecs,nBasis,hamiltonianEVals, &\n lapackWork,3*nBasis,lapackInfo)\n write(iOut,*)' lapackInfo = ',lapackInfo\n if(lapackInfo.ne.0) then\n write(iOut,9200)\n fail = .true.\n goto 999\n endIf\n call print_matrix(RESHAPE(hamiltonianEVecs,[ nBasis,nBasis ]))\n call print_matrix(RESHAPE(hamiltonianEVals,[ 1,nBasis ]))\n!\n! Complete the program...\n!\n 999 if(fail) write(iOut,9999)\n end program pib_02\n", "meta": {"hexsha": "064e480f40db7ebbf6184ab19a204660a9014c86", "size": 4607, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Exercises_Workshop2/ProblemSet01-ModifiedPIB/SolutionCodes/pib_02.f03", "max_stars_repo_name": "MQCPack/summerCodingWorkshop", "max_stars_repo_head_hexsha": "77989f555497c14711c4aa1817540fdc3131eee4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-29T16:24:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-29T16:24:28.000Z", "max_issues_repo_path": "Exercises_Workshop2/ProblemSet01-ModifiedPIB/SolutionCodes/pib_02.f03", "max_issues_repo_name": "MQCPack/summerCodingWorkshop", "max_issues_repo_head_hexsha": "77989f555497c14711c4aa1817540fdc3131eee4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Exercises_Workshop2/ProblemSet01-ModifiedPIB/SolutionCodes/pib_02.f03", "max_forks_repo_name": "MQCPack/summerCodingWorkshop", "max_forks_repo_head_hexsha": "77989f555497c14711c4aa1817540fdc3131eee4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-26T21:05:45.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-26T21:05:45.000Z", "avg_line_length": 34.6390977444, "max_line_length": 80, "alphanum_fraction": 0.6472758845, "num_tokens": 1342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308073258007, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7631491992133849}} {"text": "module lin_alg\n use nrtype\n ! Module for numerical linear algebra.\ncontains\n subroutine tridiag(c, a, b, y, x)\n implicit none\n ! Tridiagonal matrix\n !\n ! a_(1,1) a_(2,1) 0 0 ... 0 |\n ! a_(2,1) a_(2,2) a_(2,3) 0 ... 0 |\n ! 0 a_(3,2) a_(3,3) a_(3,4) ... 0 |\n ! 0 0 a_(4,3) a_(4,4) ... 0\n ! ... ... ... ... ... a_(n-1,n)\n ! 0 0 0 ... a_(n,n-1) a_(n,n)\n !\n ! Inputs:\n ! c(:) = Lower Diagonal.\n ! a(:) = Main Diagonal.\n ! b(:) = Upper Diagonal.\n ! y(:) = Image.\n ! Outputs:\n ! x(:) = Solution vector.\n ! Locals:\n ! i, j = Counters.\n ! w(:) = Dummy Vector.\n ! c = Dummy Variable.\n real(dp), intent(in) :: c(:), a(:), b(:), y(:)\n real(dp), intent(out) :: x(:)\n real(dp) :: w(size(a)), den\n integer :: n, i\n\n ! Set the value of n to be the number of entries in the main diagonal.\n n = size(a)\n ! Check that the sizes of the lower, main and upper diagonals make sense.\n check_size: if( n /= size(c) + 1 .or. &\n n /= size(b) + 1 .or. &\n n /= size(y) ) then\n write(*,*) \" Error: lin_alg: tridiag: check_size: Sizes of the upper and lower diagonals must be one smaller than the main &\n diagonal; size(lower_diagonal) = \", size(c), \"; size(upper_diagonal) = \", size(b), &\n \"; size(main_diagonal) = \", size(a)\n end if check_size\n\n ! Calculate the First Denominator.\n den = a(1)\n fd: if ( den == 0._dp ) then\n write(*,*) \" Error: lin_alg: tridiag: Next iteration will divide by zero. den = \", den\n stop\n end if fd\n ! Calculate preliminary value of x(1).\n x(1) = y(1) / den\n\n ! Decomposition and Forward Substitution.\n dfs: do i = 2, n\n w(i) = b(i - 1) / den\n den = a(i) - c(i - 1) * w(i)\n ! Error if Next Iteration will Divide by 0.\n nid0: if ( den == 0._dp ) then\n write(*,*) \" Error: lin_alg: tridiag: dfs: Next iteration will divide by zero. den = \", den\n stop\n end if nid0\n ! x(2) = ( y(2) - c(1) * x(1) ) /\n ! Solution vector.\n x(i) = ( y(i) - c(i - 1) * x(i - 1) ) / den\n end do dfs\n\n ! Back Substitution.\n bs: do i = n - 1, 1, -1\n x(i) = x(i) - w(i + 1) * x(i + 1)\n end do bs\n\n end subroutine tridiag\nend module lin_alg\n", "meta": {"hexsha": "b4cbf03a6a4eceddc3ed136a23a64d88e95675e7", "size": 2501, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "lin_alg/lin_alg.f08", "max_stars_repo_name": "dcelisgarza/applied_math", "max_stars_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2015-09-30T19:22:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T23:33:04.000Z", "max_issues_repo_path": "lin_alg/lin_alg.f08", "max_issues_repo_name": "dcelisgarza/applied_math", "max_issues_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lin_alg/lin_alg.f08", "max_forks_repo_name": "dcelisgarza/applied_math", "max_forks_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.2602739726, "max_line_length": 130, "alphanum_fraction": 0.4618152739, "num_tokens": 839, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308091776496, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.7631491965783926}} {"text": "program main\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n integer :: i\n interface\n function Load_subtraction_generator(seed_)\n implicit none\n integer, parameter :: li = selected_int_kind(10)\n integer, parameter :: dp = selected_real_kind(8)\n\n integer(li), intent(in), optional :: seed_\n real(dp) :: Load_subtraction_generator\n end function Load_subtraction_generator\n end interface\n\n do i = 1, 100\n write(*,*) Load_subtraction_generator()\n end do\nend program main\n\nfunction Load_subtraction_generator(seed_)\n ! 带载减法产生器\n implicit none\n integer, parameter :: li = selected_int_kind(10)\n integer, parameter :: dp = selected_real_kind(8)\n\n integer(li), intent(in), optional :: seed_\n real(dp) :: Load_subtraction_generator\n\n integer :: i\n integer(li), save :: I_list(44) = [(-1, i = 1, 44)]\n logical :: initialized = .false.\n integer(li), parameter :: m = 16807\n integer :: C = 0\n\n if (present(seed_)) then\n I_list(1) = seed_\n initialized = .false.\n else if (I_list(1) == -1) then\n I_list(1) = 1\n initialized = .false.\n end if\n\n if (initialized) then\n I_list(1:43) = I_list(2:44)\n else\n I_list(2) = Congruential_16807(I_list(1))\n do i = 2, 43\n I_list(i + 1) = Congruential_16807()\n end do\n initialized = .true.\n end if\n I_list(44) = I_list(22) - I_list(1) - C\n if (I_list(44) >= 0) then\n C = 0\n else\n C = 1\n I_list(44) = I_list(44) + (2**32 - 5)\n end if\n Load_subtraction_generator = mod(I_list(44), m) / dble(m)\n\n contains\n function Congruential_16807(seed_)\n ! Schrage 方法产生 16807 产生器中的随机整数\n implicit none\n integer, parameter :: li = selected_int_kind(10)\n\n integer(li), intent(in), optional :: seed_\n integer :: Congruential_16807\n\n integer, parameter :: a = 7**5, m = 2**31 - 1\n integer, parameter :: q = 12773, r = 2836\n integer, save :: z\n\n if (present(seed_)) then\n z = seed_\n else if (z == -1) then\n z = 1\n end if\n z = a * mod(z, q) - r * (z / q)\n if (z < 0) then\n z = z + m\n end if\n Congruential_16807 = z\n end function Congruential_16807\nend function Load_subtraction_generator\n", "meta": {"hexsha": "55b466cfa6433e770c59ee0ba2aa6b039240e2c6", "size": 2490, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Chap1-Monte-Carlo-Method-Basic/1.1.1.6-Load-Subtraction-Generator.f90", "max_stars_repo_name": "Chen-Jialin/Computational-Physics-Practice", "max_stars_repo_head_hexsha": "5bbb271123ee75727d266e6ca83d090ad8919abb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chap1-Monte-Carlo-Method-Basic/1.1.1.6-Load-Subtraction-Generator.f90", "max_issues_repo_name": "Chen-Jialin/Computational-Physics-Practice", "max_issues_repo_head_hexsha": "5bbb271123ee75727d266e6ca83d090ad8919abb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chap1-Monte-Carlo-Method-Basic/1.1.1.6-Load-Subtraction-Generator.f90", "max_forks_repo_name": "Chen-Jialin/Computational-Physics-Practice", "max_forks_repo_head_hexsha": "5bbb271123ee75727d266e6ca83d090ad8919abb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2954545455, "max_line_length": 61, "alphanum_fraction": 0.5522088353, "num_tokens": 712, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314858927011, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7630053645717453}} {"text": "! { dg-do run }\n! { dg-options \"-fdump-tree-original\" }\n!\n! PR fortran/56318\n!\n! Contributed by Alberto Luaces\n!\nSUBROUTINE mass_matrix \n DOUBLE PRECISION,PARAMETER::m1=1.d0\n DOUBLE PRECISION,DIMENSION(3,2),PARAMETER::A1=reshape([1.d0,0.d0, 0.d0, &\n 0.d0,1.d0, 0.d0],[3,2])\n DOUBLE PRECISION,DIMENSION(2,2),PARAMETER::Mel=reshape([1.d0/3.d0, 0.d0, &\n 0.d0, 1.d0/3.d0],[2,2])\n\n DOUBLE PRECISION,DIMENSION(3,3)::MM1\n\n MM1=m1*matmul(A1,matmul(Mel,transpose(A1)))\n !print '(3f8.3)', MM1\n if (any (abs (MM1 &\n - reshape ([1.d0/3.d0, 0.d0, 0.d0, &\n 0.d0, 1.d0/3.d0, 0.d0, &\n 0.d0, 0.d0, 0.d0], &\n [3,3])) > epsilon(1.0d0))) &\n STOP 1\nEND SUBROUTINE mass_matrix\n\nprogram name\n implicit none\n integer, parameter :: A(3,2) = reshape([1,2,3,4,5,6],[3,2])\n integer, parameter :: B(2,3) = reshape([3,17,23,31,43,71],[2,3])\n integer, parameter :: C(3) = [-5,-7,-21]\n integer, parameter :: m1 = 1\n\n! print *, matmul(B,C)\n if (any (matmul(B,C) /= [-1079, -1793])) STOP 2\n! print *, matmul(C,A)\n if (any (matmul(C,A) /= [-82, -181])) STOP 3\n! print '(3i5)', m1*matmul(A,B)\n if (any (m1*matmul(A,B) /= reshape([71,91,111, 147,201,255, 327,441,555],&\n [3,3]))) &\n STOP 4\n call mass_matrix\nend program name\n\n! { dg-final { scan-tree-dump-times \"matmul\" 0 \"original\" } }\n\n", "meta": {"hexsha": "10670bffd418c286202ec38a35a88a43d86538e4", "size": 1454, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/matmul_9.f90", "max_stars_repo_name": "brugger1/testsuite", "max_stars_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-02-12T18:20:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-09T19:46:19.000Z", "max_issues_repo_path": "validation_tests/llvm/f18/gfortran.dg/matmul_9.f90", "max_issues_repo_name": "brugger1/testsuite", "max_issues_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 24, "max_issues_repo_issues_event_min_datetime": "2020-08-31T22:05:07.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T18:30:03.000Z", "max_forks_repo_path": "validation_tests/llvm/f18/gfortran.dg/matmul_9.f90", "max_forks_repo_name": "brugger1/testsuite", "max_forks_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2020-08-31T21:59:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-23T22:06:46.000Z", "avg_line_length": 30.9361702128, "max_line_length": 76, "alphanum_fraction": 0.530261348, "num_tokens": 568, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382129861583, "lm_q2_score": 0.8856314813647587, "lm_q1q2_score": 0.7630053638192783}} {"text": "program Verifying_Goldbach_Conjecture_With_Subroutine\r\nimplicit none\r\n integer::x,y,n,W\r\n\r\n do n=6,100,2\r\n do x = 2 , n/2\r\n call Judge_Prime(x,W)\r\n if (W==0) then\r\n y = n - x\r\n call Judge_Prime(y,W)\r\n if (W==0) then\r\n write(*,*) n,'=',x,'+',y\n end if\n end if\r\n end do\n end do\nend program\r\n\r\nsubroutine Judge_Prime(x,W)\r\n integer,intent(in)::x\r\n integer,intent(out)::W\r\n integer::i,j\r\n\r\n i = sqrt(real(x))\r\n j = 2\r\n do while(j<=i .and. mod(x,j)/=0)\r\n j = j + 1\n end do\r\n\r\n if (j>i) then\r\n W=0\r\n else\r\n W=1\n end if\r\n\nend subroutine\r\n", "meta": {"hexsha": "d65517f6e5903af2e739b56f8c66008835a19b0f", "size": 753, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "GitHub_FortranHomework/B20211219.f90", "max_stars_repo_name": "MikasaMumei/Freshman_year", "max_stars_repo_head_hexsha": "c7b94d7726b170119fca40c6f87ebf79433444de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-12-02T13:32:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-02T13:32:17.000Z", "max_issues_repo_path": "GitHub_FortranHomework/B20211219.f90", "max_issues_repo_name": "MikasaMumei/Freshman_year", "max_issues_repo_head_hexsha": "c7b94d7726b170119fca40c6f87ebf79433444de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "GitHub_FortranHomework/B20211219.f90", "max_forks_repo_name": "MikasaMumei/Freshman_year", "max_forks_repo_head_hexsha": "c7b94d7726b170119fca40c6f87ebf79433444de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.3513513514, "max_line_length": 54, "alphanum_fraction": 0.4209827357, "num_tokens": 218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.8615382023207901, "lm_q1q2_score": 0.7630053530733607}} {"text": "\nmodule stdlib_math\n use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, xdp, qp\n use stdlib_optval, only: optval\n\n implicit none\n private\n public :: clip, gcd, linspace, logspace\n public :: EULERS_NUMBER_SP, EULERS_NUMBER_DP\n public :: DEFAULT_LINSPACE_LENGTH, DEFAULT_LOGSPACE_BASE, DEFAULT_LOGSPACE_LENGTH\n public :: arange\n\n integer, parameter :: DEFAULT_LINSPACE_LENGTH = 100\n integer, parameter :: DEFAULT_LOGSPACE_LENGTH = 50\n integer, parameter :: DEFAULT_LOGSPACE_BASE = 10\n\n ! Useful constants for lnspace\n real(sp), parameter :: EULERS_NUMBER_SP = exp(1.0_sp)\n real(dp), parameter :: EULERS_NUMBER_DP = exp(1.0_dp)\n\n interface clip\n module procedure clip_int32\n module procedure clip_dp\n end interface clip\n\n !> Returns the greatest common divisor of two integers\n !> ([Specification](../page/specs/stdlib_math.html#gcd))\n !>\n !> Version: experimental\n interface gcd\n module procedure gcd_int32\n end interface gcd\n\n interface linspace\n !! Version: Experimental\n !!\n !! Create rank 1 array of linearly spaced elements\n !! If the number of elements is not specified, create an array with size 100. If n is a negative value,\n !! return an array with size 0. If n = 1, return an array whose only element is end\n !!([Specification](../page/specs/stdlib_math.html#linspace-create-a-linearly-spaced-rank-one-array))\n pure module function linspace_default_1_rdp_rdp(start, end) result(res)\n real(dp), intent(in) :: start\n real(dp), intent(in) :: end\n\n real(dp) :: res(DEFAULT_LINSPACE_LENGTH)\n end function linspace_default_1_rdp_rdp\n pure module function linspace_default_1_cdp_cdp(start, end) result(res)\n complex(dp), intent(in) :: start\n complex(dp), intent(in) :: end\n\n complex(dp) :: res(DEFAULT_LINSPACE_LENGTH)\n end function linspace_default_1_cdp_cdp\n\n pure module function linspace_n_1_rdp_rdp(start, end, n) result(res)\n real(dp), intent(in) :: start\n real(dp), intent(in) :: end\n integer, intent(in) :: n\n\n real(dp) :: res(max(n, 0))\n end function linspace_n_1_rdp_rdp\n pure module function linspace_n_1_cdp_cdp(start, end, n) result(res)\n complex(dp), intent(in) :: start\n complex(dp), intent(in) :: end\n integer, intent(in) :: n\n\n complex(dp) :: res(max(n, 0))\n end function linspace_n_1_cdp_cdp\n\n\n ! Add support for integer linspace\n !!\n !! When dealing with integers as the `start` and `end` parameters, the return type is always a `real(dp)`.\n pure module function linspace_default_1_iint32_iint32(start, end) result(res)\n integer(int32), intent(in) :: start\n integer(int32), intent(in) :: end\n\n real(dp) :: res(DEFAULT_LINSPACE_LENGTH)\n end function linspace_default_1_iint32_iint32\n\n pure module function linspace_n_1_iint32_iint32(start, end, n) result(res)\n integer(int32), intent(in) :: start\n integer(int32), intent(in) :: end\n integer, intent(in) :: n\n\n real(dp) :: res(max(n, 0))\n end function linspace_n_1_iint32_iint32\n\n end interface\n\n interface logspace\n !! Version: Experimental\n !!\n !! Create rank 1 array of logarithmically spaced elements from base**start to base**end.\n !! If the number of elements is not specified, create an array with size 50. If n is a negative value,\n !! return an array with size 0. If n = 1, return an array whose only element is base**end. If no base\n !! is specified, logspace will default to using a base of 10\n !!\n !!([Specification](../page/specs/stdlib_math.html#logspace-create-a-logarithmically-spaced-rank-one-array))\n pure module function logspace_1_rdp_default(start, end) result(res)\n\n real(dp), intent(in) :: start\n real(dp), intent(in) :: end\n\n real(dp) :: res(DEFAULT_LOGSPACE_LENGTH)\n\n end function logspace_1_rdp_default\n pure module function logspace_1_cdp_default(start, end) result(res)\n\n complex(dp), intent(in) :: start\n complex(dp), intent(in) :: end\n\n complex(dp) :: res(DEFAULT_LOGSPACE_LENGTH)\n\n end function logspace_1_cdp_default\n pure module function logspace_1_iint32_default(start, end) result(res)\n\n integer, intent(in) :: start\n integer, intent(in) :: end\n\n real(dp) :: res(DEFAULT_LOGSPACE_LENGTH)\n\n end function logspace_1_iint32_default\n\n pure module function logspace_1_rdp_n(start, end, n) result(res)\n real(dp), intent(in) :: start\n real(dp), intent(in) :: end\n integer, intent(in) :: n\n\n real(dp) :: res(max(n, 0))\n end function logspace_1_rdp_n\n pure module function logspace_1_cdp_n(start, end, n) result(res)\n complex(dp), intent(in) :: start\n complex(dp), intent(in) :: end\n integer, intent(in) :: n\n\n complex(dp) :: res(max(n, 0))\n end function logspace_1_cdp_n\n pure module function logspace_1_iint32_n(start, end, n) result(res)\n integer, intent(in) :: start\n integer, intent(in) :: end\n integer, intent(in) :: n\n\n real(dp) :: res(n)\n end function logspace_1_iint32_n\n\n ! Generate logarithmically spaced sequence from dp base to the powers\n ! of dp start and end. [base^start, ... , base^end]\n ! Different combinations of parameter types will lead to different result types.\n ! Those combinations are indicated in the body of each function.\n pure module function logspace_1_rdp_n_rbase(start, end, n, base) result(res)\n real(dp), intent(in) :: start\n real(dp), intent(in) :: end\n integer, intent(in) :: n\n real(dp), intent(in) :: base\n ! real(dp) endpoints + real(dp) base = real(dp) result\n real(dp) :: res(max(n, 0))\n end function logspace_1_rdp_n_rbase\n\n pure module function logspace_1_rdp_n_cbase(start, end, n, base) result(res)\n real(dp), intent(in) :: start\n real(dp), intent(in) :: end\n integer, intent(in) :: n\n complex(dp), intent(in) :: base\n ! real(dp) endpoints + complex(dp) base = complex(dp) result\n real(dp) :: res(max(n, 0))\n end function logspace_1_rdp_n_cbase\n\n pure module function logspace_1_rdp_n_ibase(start, end, n, base) result(res)\n real(dp), intent(in) :: start\n real(dp), intent(in) :: end\n integer, intent(in) :: n\n integer, intent(in) :: base\n ! real(dp) endpoints + integer base = real(dp) result\n real(dp) :: res(max(n, 0))\n end function logspace_1_rdp_n_ibase\n ! Generate logarithmically spaced sequence from dp base to the powers\n ! of dp start and end. [base^start, ... , base^end]\n ! Different combinations of parameter types will lead to different result types.\n ! Those combinations are indicated in the body of each function.\n pure module function logspace_1_cdp_n_rbase(start, end, n, base) result(res)\n complex(dp), intent(in) :: start\n complex(dp), intent(in) :: end\n integer, intent(in) :: n\n real(dp), intent(in) :: base\n ! complex(dp) endpoints + real(dp) base = complex(dp) result\n complex(dp) :: res(max(n, 0))\n end function logspace_1_cdp_n_rbase\n\n pure module function logspace_1_cdp_n_cbase(start, end, n, base) result(res)\n complex(dp), intent(in) :: start\n complex(dp), intent(in) :: end\n integer, intent(in) :: n\n complex(dp), intent(in) :: base\n ! complex(dp) endpoints + complex(dp) base = complex(dp) result\n complex(dp) :: res(max(n, 0))\n end function logspace_1_cdp_n_cbase\n\n pure module function logspace_1_cdp_n_ibase(start, end, n, base) result(res)\n complex(dp), intent(in) :: start\n complex(dp), intent(in) :: end\n integer, intent(in) :: n\n integer, intent(in) :: base\n ! complex(dp) endpoints + integer base = complex(dp) result\n complex(dp) :: res(max(n, 0))\n end function logspace_1_cdp_n_ibase\n ! Generate logarithmically spaced sequence from dp base to the powers\n ! of dp start and end. [base^start, ... , base^end]\n ! Different combinations of parameter types will lead to different result types.\n ! Those combinations are indicated in the body of each function.\n pure module function logspace_1_iint32_n_rdpbase(start, end, n, base) result(res)\n integer, intent(in) :: start\n integer, intent(in) :: end\n integer, intent(in) :: n\n real(dp), intent(in) :: base\n ! integer endpoints + real(dp) base = real(dp) result\n real(dp) :: res(max(n, 0))\n end function logspace_1_iint32_n_rdpbase\n\n pure module function logspace_1_iint32_n_cdpbase(start, end, n, base) result(res)\n integer, intent(in) :: start\n integer, intent(in) :: end\n integer, intent(in) :: n\n complex(dp), intent(in) :: base\n ! integer endpoints + complex(dp) base = complex(dp) result\n complex(dp) :: res(max(n, 0))\n end function logspace_1_iint32_n_cdpbase\n\n pure module function logspace_1_iint32_n_ibase(start, end, n, base) result(res)\n integer, intent(in) :: start\n integer, intent(in) :: end\n integer, intent(in) :: n\n integer, intent(in) :: base\n ! integer endpoints + integer base = integer result\n integer :: res(max(n, 0))\n end function logspace_1_iint32_n_ibase\n\n\n end interface\n\n !> Version: experimental\n !>\n !> `arange` creates a one-dimensional `array` of the `integer/real` type \n !> with fixed-spaced values of given spacing, within a given interval.\n !> ([Specification](../page/specs/stdlib_math.html#arange))\n interface arange\n pure module function arange_r_dp(start, end, step) result(result)\n real(dp), intent(in) :: start\n real(dp), intent(in), optional :: end, step\n real(dp), allocatable :: result(:)\n end function arange_r_dp\n pure module function arange_i_int32(start, end, step) result(result)\n integer(int32), intent(in) :: start\n integer(int32), intent(in), optional :: end, step\n integer(int32), allocatable :: result(:)\n end function arange_i_int32\n end interface arange\n\ncontains\n\n elemental function clip_int32(x, xmin, xmax) result(res)\n integer(int32), intent(in) :: x\n integer(int32), intent(in) :: xmin\n integer(int32), intent(in) :: xmax\n integer(int32) :: res\n\n res = max(min(x, xmax), xmin)\n end function clip_int32\n\n elemental function clip_dp(x, xmin, xmax) result(res)\n real(dp), intent(in) :: x\n real(dp), intent(in) :: xmin\n real(dp), intent(in) :: xmax\n real(dp) :: res\n\n res = max(min(x, xmax), xmin)\n end function clip_dp\n\n\n !> Returns the greatest common divisor of two integers of kind int32\n !> using the Euclidean algorithm.\n elemental function gcd_int32(a, b) result(res)\n integer(int32), intent(in) :: a\n integer(int32), intent(in) :: b\n integer(int32) :: res\n\n integer(int32) :: rem, tmp\n\n rem = min(abs(a), abs(b))\n res = max(abs(a), abs(b))\n do while (rem /= 0_int32)\n tmp = rem\n rem = mod(res, rem)\n res = tmp\n end do\n end function gcd_int32\n\nend module stdlib_math\n", "meta": {"hexsha": "cd3ea0265de2b9c79e94ba3cf494b4872c28d661", "size": 11201, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stdlib_math.f90", "max_stars_repo_name": "zoziha/dp-stdlib", "max_stars_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-12-08T04:45:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-09T11:42:41.000Z", "max_issues_repo_path": "src/stdlib_math.f90", "max_issues_repo_name": "zoziha/dp-stdlib", "max_issues_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-12-08T12:35:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-17T02:33:12.000Z", "max_forks_repo_path": "src/stdlib_math.f90", "max_forks_repo_name": "zoziha/dp-stdlib", "max_forks_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-09T01:54:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T01:54:34.000Z", "avg_line_length": 37.5872483221, "max_line_length": 110, "alphanum_fraction": 0.6523524685, "num_tokens": 2981, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.908617906830944, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.7629973254676496}} {"text": "C$Procedure VPERP ( Perpendicular component of a 3-vector )\n\n SUBROUTINE VPERP ( A, B, P )\n\nC$ Abstract\nC\nC Find the component of a vector that is perpendicular to a second\nC vector. All vectors are 3-dimensional.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC VECTOR\nC\nC$ Declarations\n\n DOUBLE PRECISION A ( 3 )\n DOUBLE PRECISION B ( 3 )\n DOUBLE PRECISION P ( 3 )\n\nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC A I The vector whose orthogonal component is sought.\nC B I The vector used as the orthogonal reference.\nC P O The component of A orthogonal to B.\nC\nC$ Detailed_Input\nC\nC A is a double precision, 3-dimensional vector. It the vector\nC whose component orthogonal to B is sought. (There is a\nC unique decomposition of A into a sum V + P, where V is\nC parallel to B and P is orthogonal to B. We want the\nC component P.)\nC\nC B is a double precision, 3-dimensional vector. This\nC vector is the vector used as a reference for the\nC decomposition of A.\nC\nC\nC$ Detailed_Output\nC\nC P is a double precision, 3-dimensional vector containing\nC the component of A that is orthogonal to B.\nC P may overwrite either A or B.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC Given and non-zero vector B and a vector A, there is a unique\nC decomposition of A as a sum V + P such that P is orthogonal\nC to B and V is parallel to B. This routine finds the vector P.\nC\nC If B is a zero vector, P will be identical to A.\nC\nC$ Examples\nC\nC The following table gives sample inputs and results from calling\nC VPERP.\nC\nC A B P\nC ------------------------------------------\nC (6, 6, 6) ( 2, 0, 0) (0, 6, 6)\nC (6, 6, 6) (-3, 0, 0) (0, 6, 6)\nC (6, 6, 0) ( 0, 7, 0) (6, 0, 0)\nC (6, 0, 0) ( 0, 0, 9) (6, 0, 0)\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC Any reasonable calculus text (for example Thomas)\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC W.L. Taber (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.1.1, 11-MAY-2010 (EDW)\nC\nC Minor edit to code comments eliminating typo.\nC\nC Reordered header sections to proper NAIF convention.\nC Removed Revision section, it listed a duplication of a\nC Version section entry.\nC\nC- SPICELIB Version 1.1.0, 09-SEP-2005 (NJB)\nC\nC Updated to remove non-standard use of duplicate arguments\nC in VSCL call.\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WLT)\nC\nC-&\n\nC$ Index_Entries\nC\nC perpendicular component of a 3-vector\nC\nC-&\n\nC\nC Local variables\nC\n DOUBLE PRECISION BIGA\n DOUBLE PRECISION BIGB\n DOUBLE PRECISION R(3)\n DOUBLE PRECISION T(3)\n DOUBLE PRECISION V(3)\n\n\nC\nC Error free routine: no check-in.\nC\n BIGA = MAX ( DABS(A(1)), DABS(A(2)), DABS(A(3)) )\n BIGB = MAX ( DABS(B(1)), DABS(B(2)), DABS(B(3)) )\n\nC\nC If A is the zero vector, just set P to zero and return.\nC\n IF ( BIGA .EQ. 0.0D0 ) THEN\n\n P(1) = 0.0D0\n P(2) = 0.0D0\n P(3) = 0.0D0\n RETURN\n\n END IF\n\nC\nC If B is the zero vector, then set P equal to A.\nC\n IF ( BIGB .EQ. 0.0D0 ) THEN\n\n P(1) = A(1)\n P(2) = A(2)\n P(3) = A(3)\n RETURN\n\n END IF\n\n T(1) = A(1) / BIGA\n T(2) = A(2) / BIGA\n T(3) = A(3) / BIGA\n\n R(1) = B(1) / BIGB\n R(2) = B(2) / BIGB\n R(3) = B(3) / BIGB\n\n CALL VPROJ ( T, R, V )\n CALL VSUB ( T, V, P )\n CALL VSCLIP ( BIGA, P )\n\n RETURN\n END\n", "meta": {"hexsha": "f1d904473700a86071c427897f670a7d374690ac", "size": 5442, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/vperp.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/vperp.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/vperp.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 26.5463414634, "max_line_length": 71, "alphanum_fraction": 0.6027195884, "num_tokens": 1711, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7629729815741793}} {"text": "! 6.2a в учебнике\n\nprogram ex_6_2a\n implicit none\n\n integer, parameter :: R_ = 16\n real(R_), parameter :: PI = 4*ATAN(1.0)\n real(R_) :: x = 0, numerator = 0, currentElement = 0, currentSum = 0, newSum = 0, numeratorDiff = 0\n integer :: In = 0, Out = 0, denominator = 0, i = 0, denominator_fact = 0, denominator_mul = 0\n character(*), parameter :: output_file = \"output.txt\", input_file = \"../data/input.txt\"\n\n open (file=input_file, newunit=In)\n read(In,*) x\n close (In)\n\n currentElement = 1\n numerator = 1\n denominator = 1\n denominator_fact = 1\n numeratorDiff = x**2\n\n do while (denominator > 0)\n i = i + 1\n\n newSum = currentSum + currentElement\n currentSum = newSum\n\n numerator = - numerator * numeratorDiff\n\n denominator_fact = denominator_fact * i\n denominator_mul = (2 * i) + 1\n denominator = denominator_fact * denominator_mul\n\n currentElement = numerator / denominator\n enddo\n\n open (file=output_file, newunit=Out)\n write(Out, '(f5.2,a,f5.2)') (2 * x) / sqrt(PI) * currentSum, ' ~' , erf(x)\n close (Out)\n\nend program ex_6_2a\n", "meta": {"hexsha": "4a8a710f0cc48697df238281bfb478fbfbcbb5c2", "size": 1177, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ex_6_2a/src/ex_6_2a.f90", "max_stars_repo_name": "taxnuke/algorithm-exercises", "max_stars_repo_head_hexsha": "5dae749093489d0e66a74bd8bc3b2040496449bf", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-06-01T06:06:44.000Z", "max_stars_repo_stars_event_max_datetime": "2017-06-01T09:16:17.000Z", "max_issues_repo_path": "ex_6_2a/src/ex_6_2a.f90", "max_issues_repo_name": "taxnuke/algorithm-exercises", "max_issues_repo_head_hexsha": "5dae749093489d0e66a74bd8bc3b2040496449bf", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ex_6_2a/src/ex_6_2a.f90", "max_forks_repo_name": "taxnuke/algorithm-exercises", "max_forks_repo_head_hexsha": "5dae749093489d0e66a74bd8bc3b2040496449bf", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0238095238, "max_line_length": 117, "alphanum_fraction": 0.5947323704, "num_tokens": 366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653856, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7629583699905843}} {"text": "C******************** START FILE SPLAAN.FOR ; GROUP TRKRLIB ******************\nC-------------------------------------------\nC derived from Forsyth/Malcolm/Moler SPLINE.FOR -- different BC:\nC y'=0 at LHS of data interval (low index side)\nC\nCCCCCCCCCCCCCCC\n SUBROUTINE r8splaan (N, X, Y, B, C, D)\n IMPLICIT NONE\n INTEGER, PARAMETER :: R8=SELECTED_REAL_KIND(12,100)\n INTEGER N\n REAL*8 X(N), Y(N), B(N), C(N), D(N)\nC\nC THE COEFFICIENTS B(I), C(I), AND D(I), I=1,2,...,N ARE COMPUTED\nC FOR A CUBIC INTERPOLATING SPLINE FOR WHICH S'(X1)=0.\nC\nC S(X) = Y(I) + B(I)*(X-X(I)) + C(I)*(X-X(I))**2 + D(I)*(X-X(I))**3\nC\nC FOR X(I) .LE. X .LE. X(I+1)\nC\nC INPUT..\nC\nC N = THE NUMBER OF DATA POINTS OR KNOTS (N.GE.2)\nC X = THE ABSCISSAS OF THE KNOTS IN STRICTLY INCREASING ORDER\nC Y = THE ORDINATES OF THE KNOTS\nC\nC OUTPUT..\nC\nC B, C, D = ARRAYS OF SPLINE COEFFICIENTS AS DEFINED ABOVE.\nC\nC USING P TO DENOTE DIFFERENTIATION,\nC\nC Y(I) = S(X(I))\nC B(I) = SP(X(I))\nC C(I) = SPP(X(I))/2\nC D(I) = SPPP(X(I))/6 (DERIVATIVE FROM THE RIGHT)\nC\nCCCCCCCCCCCCCCC\nC THE ACCOMPANYING FUNCTION SUBPROGRAM SEVAL CAN BE USED\nC TO EVALUATE THE SPLINE.\nC\nC\n INTEGER NM1, IB, I\n REAL*8 T\nC\n NM1 = N-1\n IF ( N .LT. 2 ) RETURN\n IF ( N .LT. 3 ) GO TO 50\nC\nC SET UP TRIDIAGONAL SYSTEM\nC\nC B = DIAGONAL, D = OFFDIAGONAL, C = RIGHT HAND SIDE.\nC\n D(1) = X(2) - X(1)\n C(2) = (Y(2) - Y(1))/D(1)\n DO 10 I = 2, NM1\n D(I) = X(I+1) - X(I)\n B(I) = 2._r8*(D(I-1) + D(I))\n C(I+1) = (Y(I+1) - Y(I))/D(I)\n C(I) = C(I+1) - C(I)\n 10 CONTINUE\nC\nC END CONDITIONS. THIRD DERIVATIVES AT X(1) AND X(N)\nC OBTAINED FROM DIVIDED DIFFERENCES\nC\n B(1)=2._r8*D(1)\n B(N) = -D(N-1)\n C(1) = 0._r8\n C(N) = 0._r8\n IF ( N .EQ. 3 ) GO TO 15\n C(1) = (Y(2)-Y(1))/D(1)\n C(N) = C(N-1)/(X(N)-X(N-2)) - C(N-2)/(X(N-1)-X(N-3))\n C(N) = -C(N)*D(N-1)**2/(X(N)-X(N-3))\nC\nC FORWARD ELIMINATION\nC\n 15 DO 20 I = 2, N\n T = D(I-1)/B(I-1)\n B(I) = B(I) - T*D(I-1)\n C(I) = C(I) - T*C(I-1)\n 20 CONTINUE\nC\nC BACK SUBSTITUTION\nC\n C(N) = C(N)/B(N)\n DO 30 IB = 1, NM1\n I = N-IB\n C(I) = (C(I) - D(I)*C(I+1))/B(I)\n 30 CONTINUE\nC\nC C(I) IS NOW THE SIGMA(I) OF THE TEXT\nC\nC COMPUTE POLYNOMIAL COEFFICIENTS\nC\n B(N) = (Y(N) - Y(NM1))/D(NM1) + D(NM1)*(C(NM1) + 2._r8*C(N))\n DO 40 I = 1, NM1\n B(I) = (Y(I+1) - Y(I))/D(I) - D(I)*(C(I+1) + 2._r8*C(I))\n D(I) = (C(I+1) - C(I))/D(I)\n C(I) = 3._r8*C(I)\n 40 CONTINUE\n C(N) = 3._r8*C(N)\n D(N) = D(N-1)\n RETURN\nC\n 50 B(1) = (Y(2)-Y(1))/(X(2)-X(1))\n C(1) = 0._r8\n D(1) = 0._r8\n B(2) = B(1)\n C(2) = 0._r8\n D(2) = 0._r8\n RETURN\n END\nC******************** END FILE SPLAAN.FOR ; GROUP TRKRLIB ******************\n", "meta": {"hexsha": "17d142512309801c39efb6f47a026ab30b89e20e", "size": 2883, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gfile_Bfield/PSPLINE/Pspline/r8splaan.f", "max_stars_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_stars_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "gfile_Bfield/PSPLINE/Pspline/r8splaan.f", "max_issues_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_issues_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "gfile_Bfield/PSPLINE/Pspline/r8splaan.f", "max_forks_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_forks_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 25.5132743363, "max_line_length": 78, "alphanum_fraction": 0.4797086368, "num_tokens": 1275, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509314, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.7628765200453167}} {"text": "subroutine Wigner3j(w3j, jmin, jmax, j2, j3, m1, m2, m3)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis subroutine will calculate the Wigner 3j symbols\n!\n!\t\tj j2 j3\n!\t\tm1 m2 m3\n!\n!\tfor all allowable values of j. The returned values in the array j are \n!\tcalculated only for the limits\n!\n!\t\tjmin = max(|j2-j3|, |m1|)\n!\t\tjmax = j2 + j3\n!\n!\tTo be non-zero, m1 + m2 + m3 = 0. In addition, it is assumed that all j and m are \n!\tintegers. Returned values have a relative error less than ~1.d-8 when j2 and j3 \n!\tare less than 103 (see below). In practice, this routine is probably usable up to 165.\n!\n!\tThis routine is based upon the stable non-linear recurence relations of Luscombe and \n!\tLuban (1998) for the \"non classical\" regions near jmin and jmax. For the classical \n!\tregion, the standard three term recursion relationship is used (Schulten and Gordon 1975). \n!\tNote that this three term recursion can be unstable and can also lead to overflows. Thus \n!\tthe values are rescaled by a factor \"scalef\" whenever the absolute value of the 3j coefficient \n!\tbecomes greater than unity. Also, the direction of the iteration starts from low values of j\n!\tto high values, but when abs(w3j(j+2)/w3j(j)) is less than one, the iteration will restart \n!\tfrom high to low values. More efficient algorithms might be found for specific cases \n!\t(for instance, when all m's are zero).\n!\n!\tVerification: \n!\n!\tThe results have been verified against this routine run in quadruple precision.\n!\tFor 1.e7 acceptable random values of j2, j3, m2, and m3 between -200 and 200, the relative error\n!\twas calculated only for those 3j coefficients that had an absolute value greater than \n!\t1.d-17 (values smaller than this are for all practical purposed zero, and can be heavily \n!\taffected by machine roundoff errors or underflow). 853 combinations of parameters were found\n!\tto have relative errors greater than 1.d-8. Here I list the minimum value of max(j2,j3) for\n!\tdifferent ranges of error, as well as the number of times this occured\n!\t\n!\t1.d-7 < error <=1.d-8 = 103\t# = 483\n!\t1.d-6 < error <= 1.d-7 = 116\t# = 240\n!\t1.d-5 < error <= 1.d-6 = 165\t# = 93\n!\t1.d-4 < error <= 1.d-5 = 167\t# = 36\n!\n!\tMany times (maybe always), the large relative errors occur when the 3j coefficient \n!\tchanges sign and is close to zero. (I.e., adjacent values are about 10.e7 times greater \n!\tin magnitude.) Thus, if one does not need to know highly accurate values of the 3j coefficients\n!\twhen they are almost zero (i.e., ~1.d-10) then this routine is probably usable up to about 160.\n!\n!\tThese results have also been verified for parameter values less than 100 using a code\n!\tbased on the algorith of de Blanc (1987), which was originally coded by Olav van Genabeek, \n!\tand modified by M. Fang (note that this code was run in quadruple precision, and\n!\tonly calculates one coefficient for each call. I also have no idea if this code\n!\twas verified.) Maximum relative errors in this case were less than 1.d-8 for a large number\n!\tof values (again, only 3j coefficients greater than 1.d-17 were considered here).\n!\t\n!\tThe biggest improvement that could be made in this routine is to determine when one should\n!\tstop iterating in the forward direction, and start iterating from high to low values. \n!\n!\tCalling parameters\n!\t\tIN\t\n!\t\t\tj2, j3, m1, m2, m3 \tInteger values.\n!\t\tOUT\t\n!\t\t\tw3j\t\t\tArray of length jmax - jmin + 1.\n!\t\t\tjmin, jmax\t\tMinimum and maximum values\n!\t\t\t\t\t\tout output array.\n!\tDependencies: None\n!\t\n!\tWritten by Mark Wieczorek August (2004)\n!\n!\tAugust 2009: Based on the suggestions of Roelof Rietbroek, the calculation of RS has been slightly\n!\tmodified so that division by zero will not cause a run time crash (this behavior depends on how the \n!\tcompiler treats IEEE floating point exceptions). These values were never used in the original code \n!\twhen this did occur.\n!\n!\tCopyright (c) 2005-2009, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\tinteger, intent(in) ::\tj2, j3, m1, m2, m3\n\tinteger, intent(out) ::\tjmin, jmax\n\treal*8, intent(out) ::\tw3j(:)\n\treal*8 ::\t\twnmid, wpmid, scalef, denom, rs(j2+j3+1), &\n\t\t\t\twl(j2+j3+1), wu(j2+j3+1), xjmin, yjmin, yjmax, zjmax, xj, zj\n\tinteger :: \t\tj, jnum, jp, jn, k, flag1, flag2, jmid\n\t\n\t\n\tif (size(w3j) < j2+j3+1) then\n\t\tprint*, \"Error --- Wigner3j\"\n\t\tprint*, \"W3J must be dimensioned (J2+J3+1) where J2 and J3 are \", j2, j3\n\t\tprint*, \"Input array is dimensioned \", size(w3j)\n\t\tstop\n\tendif\n\t\n\tw3j = 0.0d0\n\t\n\tflag1 = 0\n\tflag2 = 0\n\t\n\tscalef = 1.0d3\n\t\n\tjmin = max(abs(j2-j3), abs(m1))\n\tjmax = j2 + j3\n\tjnum = jmax - jmin + 1\n\t\n\tif (abs(m2) > j2 .or. abs(m3) > j3) then\n\t\treturn\n\telseif (m1 + m2 + m3 /= 0) then\n\t\treturn\n\telseif (jmax < jmin) then\n\t\treturn\n\tendif\n\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t!\tOnly one term is present\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\tif (jnum == 1) then\n\t\tw3j(1) = 1.0d0 / sqrt(2.0d0*jmin+1.0d0)\n\t\tif ( (w3j(1) < 0.0d0 .and. (-1)**(j2-j3+m2+m3) > 0) .or. &\n\t\t\t(w3j(1) > 0.0d0 .and. (-1)**(j2-j3+m2+m3) < 0) ) &\n\t\t\tw3j(1) = -w3j(1)\n\t\treturn\t\n\tendif\n\t\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t! \tCalculate lower non-classical values for [jmin, jn]. If the second term\n\t!\tcan not be calculated because the recursion relationsips give rise to a\n\t!\t1/0, then set flag1 to 1. If all m's are zero, then this is not a problem \n\t!\tas all odd terms must be zero.\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\trs = 0.0d0\n\twl = 0.0d0\n\t\n\txjmin = x(jmin)\n\tyjmin = y(jmin)\n\t\n\tif (m1 == 0 .and. m2 == 0 .and. m3 == 0) then\t\t! All m's are zero\n\t\n\t\twl(jindex(jmin)) = 1.0d0\n\t\twl(jindex(jmin+1)) = 0.0d0\n\t\tjn = jmin+1\n\t\t\n\telseif (yjmin == 0.0d0) then\t\t\t\t! The second terms is either zero\n\t\n\t\tif (xjmin == 0.0d0) then\t\t\t! or undefined\n\t\t\tflag1 = 1\n\t\t\tjn = jmin\n\t\telse\n\t\t\twl(jindex(jmin)) = 1.0d0\n\t\t\twl(jindex(jmin+1)) = 0.0d0\n\t\t\tjn = jmin+1\n\t\tendif\n\t\t\n\telseif ( xjmin * yjmin >= 0.0d0) then\t\t\t! The second term is outside of the \n\t\t\t\t\t\t\t\t! non-classical region \n\t\twl(jindex(jmin)) = 1.0d0\n\t\twl(jindex(jmin+1)) = -yjmin / xjmin\n\t\tjn = jmin+1\n\t\t\n\telse\t\t\t\t\t\t\t! Calculate terms in the non-classical region\n\t\n\t\trs(jindex(jmin)) = -xjmin / yjmin\n\t\t\n\t\tjn = jmax\n\t\tdo j=jmin + 1, jmax-1, 1\n\t\t\tdenom = y(j) + z(j)*rs(jindex(j-1))\n\t\t\txj = x(j)\n\t\t\tif (abs(xj) > abs(denom) .or. xj * denom >= 0.0d0 .or. denom == 0.0d0) then\n\t\t\t\tjn = j-1\n\t\t\t\texit\n\t\t\telse\n\t\t\t\trs(jindex(j)) = -xj / denom\n\t\t\tendif\n\t\t\t\t\n\t\tenddo\n\t\t\n\t\twl(jindex(jn)) = 1.0d0\n\t\t\n\t\tdo k=1, jn - jmin, 1\n\t\t\twl(jindex(jn-k)) = wl(jindex(jn-k+1)) * rs(jindex(jn-k))\n\t\tenddo\n\t\t\n\t\tif (jn == jmin) then\t\t\t\t\t! Calculate at least two terms so that\n\t\t\twl(jindex(jmin+1)) = -yjmin / xjmin\t\t! these can be used in three term\n\t\t\tjn = jmin+1\t\t\t\t\t! recursion\n\t\t\t\n\t\tendif\n\n\tendif\n\t\n\tif (jn == jmax) then\t\t\t\t\t! All terms are calculated\n\t\n\t\tw3j(1:jnum) = wl(1:jnum)\n\t\tcall normw3j\n\t\tcall fixsign\n\t\t\n\t\treturn\n\n\tendif\n\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t! \tCalculate upper non-classical values for [jp, jmax].\n\t!\tIf the second last term can not be calculated because the\n\t!\trecursion relations give a 1/0, then set flag2 to 1. \n\t!\t(Note, I don't think that this ever happens).\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\twu = 0.0d0\n\t\n\tyjmax = y(jmax)\n\tzjmax = z(jmax)\n\t\n\tif (m1 == 0 .and. m2 == 0 .and. m3 == 0) then\n\t\n\t\twu(jindex(jmax)) = 1.0d0\n\t\twu(jindex(jmax-1)) = 0.0d0\n\t\tjp = jmax-1\n\t\t\n\telseif (yjmax == 0.0d0) then\n\t\n\t\tif (zjmax == 0.0d0) then\n\t\t\tflag2 = 1\n\t\t\tjp = jmax\n\t\telse\n\t\t\twu(jindex(jmax)) = 1.0d0\n\t\t\twu(jindex(jmax-1)) = - yjmax / zjmax\n\t\t\tjp = jmax-1\n\t\tendif\n\t\t\n\telseif (yjmax * zjmax >= 0.0d0) then\n\t\n\t\twu(jindex(jmax)) = 1.0d0\n\t\twu(jindex(jmax-1)) = - yjmax / zjmax\n\t\tjp = jmax-1\n\n\telse\n\t\trs(jindex(jmax)) = -zjmax / yjmax\n\n\t\tjp = jmin\n\t\tdo j=jmax-1, jn, -1\n\t\t\tdenom = y(j) + x(j)*rs(jindex(j+1))\n\t\t\tzj = z(j)\n\t\t\tif (abs(zj) > abs(denom) .or. zj * denom >= 0.0d0 .or. denom == 0.0d0) then\n\t\t\t\tjp = j+1\n\t\t\t\texit\n\t\t\telse\n\t\t\t\trs(jindex(j)) = -zj / denom\n\t\t\tendif\n\t\tenddo\t\n\t\t\n\t\twu(jindex(jp)) = 1.0d0\n\t\t\n\t\tdo k=1, jmax - jp, 1\n\t\t\twu(jindex(jp+k)) = wu(jindex(jp+k-1))*rs(jindex(jp+k))\n\t\tenddo\n\t\t\n\t\tif (jp == jmax) then\n\t\t\twu(jindex(jmax-1)) = - yjmax / zjmax\n\t\t\tjp = jmax-1\n\t\tendif\n\t\t\n\tendif\n\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t! \tCalculate classical terms for [jn+1, jp-1] using standard three\n\t! \tterm rercusion relationship. Start from both jn and jp and stop at the\n\t! \tmidpoint. If flag1 is set, then perform the recursion solely from high to\n\t! \tlow values. If flag2 is set, then perform the recursion solely from low to high.\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\tif (flag1 == 0) then\n\t\n\t\tjmid = (jn + jp)/2\n\t\t\n\t\tdo j=jn, jmid - 1, 1\t\t\t\n\t\t\twl(jindex(j+1)) = - (z(j)*wl(jindex(j-1)) +y(j)*wl(jindex(j))) / x(j)\n\t\t\t\n\t\t\tif (abs(wl(jindex(j+1))) > 1.0d0) then\t\t\t\t! watch out for overflows.\n\t\t\t\twl(jindex(jmin):jindex(j+1)) = wl(jindex(jmin):jindex(j+1)) / scalef\n\t\t\tendif\n\t\t\t\n\t\t\tif (abs(wl(jindex(j+1)) / wl(jindex(j-1))) < 1.0d0 .and. &\t! if values are decreasing\n\t\t\t\twl(jindex(j+1)) /= 0.0d0) then\t\t\t\t! then stop upward iteration\n\t\t\t\tjmid = j+1\t\t\t\t\t\t! and start with the downward\n\t\t\t\texit\t\t\t\t\t\t\t! iteration.\n\t\t\tendif\n\t\tenddo\n\t\t\n\t\twnmid = wl(jindex(jmid))\n\t\t\n\t\tif (abs(wnmid/wl(jindex(jmid-1))) < 1.d-6 .and. &\n\t\t\twl(jindex(jmid-1)) /= 0.0d0) then\t\t\t\t! Make sure that the stopping\n\t\t\twnmid = wl(jindex(jmid-1))\t\t\t\t\t! midpoint value is not a zero,\n\t\t\tjmid = jmid - 1\t\t\t\t\t\t\t! or close to it!\n\t\tendif\n\t\t\n\t\t\n\t\tdo j=jp, jmid+1, -1\n\t\t\twu(jindex(j-1)) = - (x(j)*wu(jindex(j+1)) + y(j)*wu(jindex(j)) ) / z(j)\n\t\t\tif (abs(wu(jindex(j-1))) > 1.0d0) then\n\t\t\t\twu(jindex(j-1):jindex(jmax)) = wu(jindex(j-1):jindex(jmax)) / scalef\n\t\t\tendif\n\t\n\t\tenddo\n\t\t\n\t\twpmid = wu(jindex(jmid))\n\t\t\n\t\t! rescale two sequences to common midpoint\n\t\t\n\t\tif (jmid == jmax) then\n\t\t\tw3j(1:jnum) = wl(1:jnum)\n\t\telseif (jmid == jmin) then\n\t\t\tw3j(1:jnum) = wu(1:jnum)\n\t\telse\n\t\t\tw3j(1:jindex(jmid)) = wl(1:jindex(jmid)) * wpmid / wnmid \n\t\t\tw3j(jindex(jmid+1):jindex(jmax)) = wu(jindex(jmid+1):jindex(jmax))\n\t\tendif\n\t\t\n\telseif (flag1 == 1 .and. flag2 == 0) then\t! iterature in downward direction only\n\t\t\n\t\tdo j=jp, jmin+1, -1\n\t\t\twu(jindex(j-1)) = - (x(j)*wu(jindex(j+1)) + y(j)*wu(jindex(j)) ) / z(j)\n\t\t\tif (abs(wu(jindex(j-1))) > 1) then\n\t\t\t\twu(jindex(j-1):jindex(jmax)) = wu(jindex(j-1):jindex(jmax)) / scalef\n\t\t\tendif\n\t\tenddo\n\t\t\n\t\tw3j(1:jnum) = wu(1:jnum)\n\t\t\n\telseif (flag2 == 1 .and. flag1 == 0) then\t! iterature in upward direction only\n\t\t\n\t\tdo j=jn, jp-1, 1\n\t\t\twl(jindex(j+1)) = - (z(j)*wl(jindex(j-1)) +y(j)*wl(jindex(j))) / x(j)\n\t\t\tif (abs(wl(jindex(j+1))) > 1) then\n\t\t\t\twl(jindex(jmin):jindex(j+1)) = wl(jindex(jmin):jindex(j+1))/ scalef\n\t\t\tendif\n\t\tenddo\n\t\t\n\t\tw3j(1:jnum) = wl(1:jnum)\n\t\t\n\telseif (flag1 == 1 .and. flag2 == 1) then\n\n\t\tprint*, \"Fatal Error --- Wigner3j\"\n\t\tprint*, \"Can not calculate function for input values, both flag1 and flag 2 are set.\"\n\t\tstop\n\tendif\n\n\t\n\tcall normw3j\n\tcall fixsign\n\t\t\n\t\n\tcontains\n\t\n\t\tinteger function jindex(j)\n\t\t\tinteger :: j\n\t\t\tjindex = j-jmin+1\n\t\tend function jindex\n\t\n\t\treal*8 function a(j)\n\t\t\tinteger :: j\n\t\t\ta = (dble(j)**2 - dble(j2-j3)**2) * (dble(j2+j3+1)**2 - dble(j)**2) * (dble(j)**2-dble(m1)**2)\n\t\t\ta = sqrt(a)\n\t\tend function a\n\t\t\n\t\treal*8 function y(j)\n\t\t\tinteger :: j\n\t\t\ty = -dble(2*j+1) * &\n\t\t\t\t( dble(m1) * (dble(j2)*dble(j2+1) - dble(j3)*dble(j3+1) ) - dble(m3-m2)*dble(j)*dble(j+1) )\n\t\tend function y\n\n\t\treal*8 function x(j)\t\n\t\t\tinteger :: j\n\t\t\tx = dble(j) * a(j+1)\n\t\tend function x\n\t\t\n\t\treal*8 function z(j)\n\t\t\tinteger :: j\n\t\t\tz = dble(j+1)*a(j)\n\t\tend function z\n\t\t\n\t\tsubroutine normw3j\n\t\t\treal*8:: norm\n\t\t\tinteger j\n\t\t\t\n\t\t\tnorm = 0.0d0\n\t\t\tdo j = jmin, jmax\n\t\t\t\tnorm = norm + dble(2*j+1) * w3j(jindex(j))**2\n\t\t\tenddo\n\t\t\t\n\t\t\tw3j(1:jnum) = w3j(1:jnum) / sqrt(norm)\n\t\t\t\n\t\tend subroutine normw3j\n\t\t\n\t\tsubroutine fixsign\n\t\t\n\t\t\tif ( (w3j(jindex(jmax)) < 0.0d0 .and. (-1)**(j2-j3+m2+m3) > 0) .or. &\n\t\t\t\t(w3j(jindex(jmax)) > 0.0d0 .and. (-1)**(j2-j3+m2+m3) < 0) ) then\n\t\t\t\tw3j(1:jnum) = -w3j(1:jnum)\n\t\t\tendif\n\t\t\t\n\t\tend subroutine fixsign\n\n\t\t\nend subroutine Wigner3j\n\n\n", "meta": {"hexsha": "72ab59cd547758100244d75f260f1e1fc56a2187", "size": 12405, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/Wigner3j.f95", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "spherical_splines/SHTOOLS/src/Wigner3j.f95", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "spherical_splines/SHTOOLS/src/Wigner3j.f95", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 29.6770334928, "max_line_length": 102, "alphanum_fraction": 0.5848448206, "num_tokens": 4588, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7628765198632742}} {"text": "! This program demonstrates the usage of selected_int_kind\n! SELECTED_INT_KIND(R) return the kind value of the smallest integer \n! type that can represent all values ranging from \n! -10^R (exclusive) to 10^R (exclusive).\n! If there is no integer kind that accommodates this range, \n! SELECT_INT_KIND returns -1. \n!\nprogram kind_int_types\n implicit none\n print*, 'SELECTED_INT_KIND(1) = ', selected_int_kind(1)\n print*, 'SELECTED_INT_KIND(2) = ', selected_int_kind(2)\n print*, 'SELECTED_INT_KIND(3) = ', selected_int_kind(3)\n print*, 'SELECTED_INT_KIND(4) = ', selected_int_kind(4)\n print*, 'SELECTED_INT_KIND(5) = ', selected_int_kind(5)\n print*, 'SELECTED_INT_KIND(6) = ', selected_int_kind(6)\n print*, 'SELECTED_INT_KIND(7) = ', selected_int_kind(7)\n print*, 'SELECTED_INT_KIND(8) = ', selected_int_kind(8)\n print*, 'SELECTED_INT_KIND(9) = ', selected_int_kind(9)\n print*, 'SELECTED_INT_KIND(10) = ', selected_int_kind(10)\nend program kind_int_types\n", "meta": {"hexsha": "ce4cc989749ed7ad41d0d2f929237942bace89e3", "size": 963, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/gettingStarted/kind_int_types.f90", "max_stars_repo_name": "annefou/Fortran", "max_stars_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2016-04-08T19:04:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-13T15:44:37.000Z", "max_issues_repo_path": "src/gettingStarted/kind_int_types.f90", "max_issues_repo_name": "inandi2/Fortran-1", "max_issues_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/gettingStarted/kind_int_types.f90", "max_forks_repo_name": "inandi2/Fortran-1", "max_forks_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2016-04-08T19:05:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-08T19:57:51.000Z", "avg_line_length": 45.8571428571, "max_line_length": 69, "alphanum_fraction": 0.738317757, "num_tokens": 282, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771662, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7628168798601325}} {"text": "!******************************************************************************\n!*\n!* VARIOUS DISTRIBUTIONS OF RANDOM VARIABLES\n!*\n!******************************************************************************\n\n !==========================================================================\n ! 1) AUTHOR: F. Galliano\n !\n ! 2) HISTORY: \n ! - Created 10/2007 \n ! - 03/2015: add multivariate distributions\n ! - 03/2015: add GENERATE_NEWSEED\n ! - 04/2016: add the skew-normal generator\n ! \n ! 3) DESCRIPTION: provides random generators of various well-known\n ! probability distributions.\n !==========================================================================\n\nMODULE random\n\n USE utilities, ONLY: DP\n USE arrays, ONLY:\n USE inout, ONLY:\n USE linear_system, ONLY:\n USE interpolation, ONLY:\n USE adaptative_grid, ONLY:\n PRIVATE\n\n PUBLIC :: rand_exp, rand_norm, rand_skewnorm, rand_splitnorm, rand_student\n PUBLIC :: rand_poisson, rand_general, rand_multinorm, rand_multistudent\n PUBLIC :: generate_newseed\n\n INTERFACE rand_exp\n MODULE PROCEDURE rand_exp_v, rand_exp_s\n END INTERFACE rand_exp\n\n INTERFACE rand_norm\n MODULE PROCEDURE rand_norm_m, rand_norm_v, rand_norm_s\n END INTERFACE rand_norm\n\n INTERFACE rand_skewnorm\n MODULE PROCEDURE rand_skewnorm_m, rand_skewnorm_v, rand_skewnorm_s\n END INTERFACE rand_skewnorm\n\n INTERFACE rand_splitnorm\n MODULE PROCEDURE rand_splitnorm_m, rand_splitnorm_v, rand_splitnorm_s\n END INTERFACE rand_splitnorm\n\n INTERFACE rand_student\n MODULE PROCEDURE rand_student_m, rand_student_v, rand_student_s\n END INTERFACE rand_student\n\n INTERFACE rand_multinorm\n MODULE PROCEDURE rand_multinorm_v, rand_multinorm_s\n END INTERFACE rand_multinorm\n\n INTERFACE rand_multistudent\n MODULE PROCEDURE rand_multistudent_v, rand_multistudent_s\n END INTERFACE rand_multistudent\n\n INTERFACE rand_general\n MODULE PROCEDURE rand_general_vec, rand_general_scl\n END INTERFACE rand_general\n \n\nCONTAINS\n\n\n !==========================================================================\n ! CALL GENERATE_NEWSEED(fileIN,fileOUT)\n ! \n ! IF FILEIN and/or FILEOUT are set, then the sequence of integers \n ! constituing the seed is read/written. To ensure the seed is different at\n ! each run, we initialize it with date and time.\n !==========================================================================\n\n SUBROUTINE generate_newseed (fileIN,fileOUT)\n\n USE utilities, ONLY: verbatim, trimlr\n USE inout, ONLY: lenpath, ascext\n IMPLICIT NONE\n CHARACTER(*), INTENT(IN), OPTIONAL :: fileIN\n CHARACTER(lenpath), INTENT(OUT), OPTIONAL :: fileOUT\n\n INTEGER, PARAMETER :: unitIN = 1, unitOUT = 2\n\n INTEGER :: i, Nseed\n INTEGER, DIMENSION(8) :: values\n INTEGER, DIMENSION(:), ALLOCATABLE :: seed\n\n !-----------------------------------------------------------------------\n\n ! Get the new seed\n genseed: IF (PRESENT(fileIN)) THEN \n OPEN(unitIN,FILE=fileIN,ACTION=\"READ\")\n READ(unitIN,\"(I20)\") Nseed\n ALLOCATE (seed(Nseed))\n DO i=1,Nseed\n READ(unitIN,\"(I20)\") seed(i)\n END DO\n CLOSE(unitIN)\n IF (verbatim) PRINT*, \" - File \"//TRIMLR(fileIN)//\" has been written.\"\n ELSE \n CALL RANDOM_SEED(SIZE=Nseed)\n ALLOCATE (seed(Nseed))\n CALL RANDOM_SEED(GET=seed)\n CALL DATE_AND_TIME(VALUES=values)\n seed(:) = seed(:)*SUM(values)\n END IF genseed\n\n ! Writes the seed to a file\n IF (PRESENT(fileOUT)) THEN\n OPEN(unitOUT,FILE=fileOUT,STATUS=\"REPLACE\",ACTION=\"WRITE\")\n WRITE(unitOUT,\"(I20)\") Nseed\n DO i=1,Nseed\n WRITE(unitOUT,\"(I20)\") seed(i)\n END DO\n CLOSE(unitOUT)\n END IF\n\n ! Initialize the random sequence\n CALL RANDOM_SEED(PUT=seed)\n DEALLOCATE (seed)\n\n !-----------------------------------------------------------------------\n\n END SUBROUTINE generate_newseed\n\n\n !==========================================================================\n ! x = RAND_EXP (N,tau)\n !\n ! Returns an array[N] of random variables following an exponential law \n ! with a timescale of TAU. Taken from http://users.bigpond.net.au/amiller/ .\n !==========================================================================\n\n FUNCTION rand_exp_v (N,tau)\n\n USE utilities, ONLY: DP\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: N\n REAL(DP), INTENT(IN), OPTIONAL :: tau\n REAL(DP), DIMENSION(N) :: rand_exp_v\n\n INTEGER :: i\n REAL(DP), DIMENSION(N) :: r\n\n !-----------------------------------------------------------------------\n\n varN: DO i=1,N\n randgen: DO \n CALL RANDOM_NUMBER (r(i))\n IF (r(i) > 0._DP) EXIT\n END DO randgen\n END DO varN\n \n ! p(t) = EXP(-t/tau)\n rand_exp_v(:) = - LOG(r(:)) \n IF (PRESENT(tau)) rand_exp_v(:) = rand_exp_v(:) * tau\n\n !-----------------------------------------------------------------------\n\n END FUNCTION rand_exp_v\n\n ! Interface shell\n FUNCTION rand_exp_s(tau)\n USE utilities, ONLY: DP\n IMPLICIT NONE\n REAL(DP), INTENT(IN), OPTIONAL :: tau\n REAL(DP) :: rand_exp_s\n rand_exp_s = MAXVAL(RAND_EXP_V(1,tau))\n END FUNCTION rand_exp_s\n\n\n !==========================================================================\n ! x = RAND_NORM (N,M,center,sigma)\n !\n ! Returns an array[N] of random variables following a normal distribution\n ! of mean CENTER and standard deviation SIGMA. Taken from \n ! http://people.sc.fsu.edu/~jburkardt/f_src/normal/normal.f90, tested and \n ! vectorized.\n !==========================================================================\n\n FUNCTION rand_norm_m (N,M,center,sigma)\n\n USE utilities, ONLY: DP\n USE constants, ONLY: pi\n USE arrays, ONLY: reallocate\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: N, M\n REAL(DP), INTENT(IN), OPTIONAL :: center, sigma\n REAL(DP), DIMENSION(N,M) :: rand_norm_m\n\n REAL(DP), DIMENSION(N,M) :: r1, r2, x\n\n !-----------------------------------------------------------------------\n\n CALL RANDOM_NUMBER(r1(:,:))\n CALL RANDOM_NUMBER(r2(:,:))\n x(:,:) = SQRT( - 2._DP * LOG(r1(:,:)) ) * COS( 2._DP * pi * r2(:,:) )\n rand_norm_m(:,:) = x(:,:)\n IF (PRESENT(sigma)) rand_norm_m(:,:) = rand_norm_m(:,:) * sigma\n IF (PRESENT(center)) rand_norm_m(:,:) = rand_norm_m(:,:) + center \n\n !-----------------------------------------------------------------------\n\n END FUNCTION rand_norm_m\n\n ! Interface shells\n FUNCTION rand_norm_v (N,center,sigma)\n USE utilities, ONLY: DP\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: N\n REAL(DP), INTENT(IN), OPTIONAL :: center, sigma\n REAL(DP), DIMENSION(N) :: rand_norm_v\n rand_norm_v(:) = RESHAPE(RAND_NORM_M(N,1,CENTER=center,SIGMA=sigma),[N])\n END FUNCTION rand_norm_v\n FUNCTION rand_norm_s (center,sigma)\n USE utilities, ONLY: DP\n IMPLICIT NONE\n REAL(DP), INTENT(IN), OPTIONAL :: center, sigma\n REAL(DP) :: rand_norm_s\n rand_norm_s = MAXVAL(RAND_NORM_M(1,1,CENTER=center,SIGMA=sigma))\n END FUNCTION rand_norm_s\n\n\n !==========================================================================\n ! x = RAND_SKEWNORM (N,M,ksi,omega,alpha)\n !\n ! Returns an array[N] of random variables following a skew-normal\n ! distribution of position parameter KSI, scale parameter OMEGA, and shape\n ! parameter ALPHA. Extracted from the MATLAB library.\n !==========================================================================\n\n FUNCTION rand_skewnorm_m (N,M,ksi,omega,alpha)\n\n USE utilities, ONLY: DP\n USE arrays, ONLY: reallocate\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: N, M\n REAL(DP), INTENT(IN), OPTIONAL :: ksi, omega, alpha\n REAL(DP), DIMENSION(N,M) :: rand_skewnorm_m\n\n REAL(DP), DIMENSION(N,M) :: r1, r2, x\n REAL(DP) :: delta, ksi0, omega0, alpha0\n\n !-----------------------------------------------------------------------\n\n IF (PRESENT(ksi)) THEN ; ksi0 = ksi ; ELSE ; ksi0 = 0._DP ; END IF\n IF (PRESENT(omega)) THEN ; omega0 = omega ; ELSE ; omega0 = 1._DP ; END IF\n IF (PRESENT(alpha)) THEN ; alpha0 = alpha ; ELSE ; alpha0 = 0._DP ; END IF\n r1(:,:) = RAND_NORM_M(N,M)\n r2(:,:) = RAND_NORM_M(N,M)\n delta = alpha0 / SQRT(1+alpha0**2)\n x(:,:) = delta * r1(:,:) + SQRT(1-delta**2)*r2(:,:)\n rand_skewnorm_m(:,:) = SIGN(1._DP,r1(:,:))*x(:,:)*omega0 + ksi0\n \n !-----------------------------------------------------------------------\n\n END FUNCTION rand_skewnorm_m\n\n ! Interface shells\n FUNCTION rand_skewnorm_v (N,ksi,omega,alpha)\n USE utilities, ONLY: DP\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: N\n REAL(DP), INTENT(IN), OPTIONAL :: ksi, omega, alpha\n REAL(DP), DIMENSION(N) :: rand_skewnorm_v\n rand_skewnorm_v(:) &\n = RESHAPE(RAND_SKEWNORM_M(N,1,KSI=ksi,OMEGA=omega,ALPHA=alpha),[N])\n END FUNCTION rand_skewnorm_v\n FUNCTION rand_skewnorm_s (ksi,omega,alpha)\n USE utilities, ONLY: DP\n IMPLICIT NONE\n REAL(DP), INTENT(IN), OPTIONAL :: ksi, omega, alpha\n REAL(DP) :: rand_skewnorm_s\n rand_skewnorm_s &\n = MAXVAL(RAND_SKEWNORM_M(1,1,KSI=ksi,OMEGA=omega,ALPHA=alpha))\n END FUNCTION rand_skewnorm_s\n\n\n !==========================================================================\n ! x = RAND_SPLITNORM (N,M,mu,lambda,tau)\n !\n ! Returns an array[N] of random variables following a split-normal\n ! distribution of position parameter MU, scale parameter LAMBDA, and shape\n ! parameter TAU. \n !==========================================================================\n\n FUNCTION rand_splitnorm_m (N,M,mu,lambda,tau)\n\n USE utilities, ONLY: DP\n USE arrays, ONLY: reallocate\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: N, M\n REAL(DP), INTENT(IN), OPTIONAL :: mu, lambda, tau\n REAL(DP), DIMENSION(N,M) :: rand_splitnorm_m\n\n REAL(DP), DIMENSION(N,M) :: r1, r2\n REAL(DP) :: mu0, lambda0, tau0\n\n !-----------------------------------------------------------------------\n\n IF (PRESENT(mu)) THEN ; mu0 = mu ; ELSE ; mu0 = 0._DP ; END IF\n IF (PRESENT(lambda)) THEN ; lambda0 = lambda\n ELSE ; lambda0 = 1._DP ; END IF\n IF (PRESENT(tau)) THEN ; tau0 = tau ; ELSE ; tau0 = 0._DP ; END IF\n r1(:,:) = RAND_NORM_M(N,M)\n CALL RANDOM_NUMBER(r2(:,:))\n WHERE (r2(:,:) < 1._DP/(1._DP+tau))\n rand_splitnorm_m(:,:) = - ABS(r1(:,:)) * lambda + mu\n ELSEWHERE\n rand_splitnorm_m(:,:) = ABS(r1(:,:)) * lambda * tau + mu\n END WHERE\n \n !-----------------------------------------------------------------------\n\n END FUNCTION rand_splitnorm_m\n\n ! Interface shells\n FUNCTION rand_splitnorm_v (N,mu,lambda,tau)\n USE utilities, ONLY: DP\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: N\n REAL(DP), INTENT(IN), OPTIONAL :: mu, lambda, tau\n REAL(DP), DIMENSION(N) :: rand_splitnorm_v\n rand_splitnorm_v(:) &\n = RESHAPE(RAND_SPLITNORM_M(N,1,MU=mu,LAMBDA=lambda,TAU=tau),[N])\n END FUNCTION rand_splitnorm_v\n FUNCTION rand_splitnorm_s (mu,lambda,tau)\n USE utilities, ONLY: DP\n IMPLICIT NONE\n REAL(DP), INTENT(IN), OPTIONAL :: mu, lambda, tau\n REAL(DP) :: rand_splitnorm_s\n rand_splitnorm_s = MAXVAL(RAND_SPLITNORM_M(1,1,MU=mu,LAMBDA=lambda,TAU=tau))\n END FUNCTION rand_splitnorm_s\n\n\n !==========================================================================\n ! x = RAND_MULTINORM(N,covar[M,M],mu)\n !\n ! Returns an array[M,N] of random variables following a multivariate normal\n ! distribution with covariance matrix COVAR. \n !==========================================================================\n\n FUNCTION rand_multinorm_v (N,covar,mu) \n\n USE utilities, ONLY: DP, strike\n USE linear_system, ONLY: cholesky_decomp\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: N\n REAL(DP), DIMENSION(:,:), INTENT(IN) :: covar\n REAL(DP), DIMENSION(:), INTENT(IN), OPTIONAL :: mu\n REAL(DP), DIMENSION(SIZE(covar,1),N) :: rand_multinorm_v\n\n INTEGER :: i, M\n REAL(DP), DIMENSION(SIZE(covar,1),N) :: theta\n REAL(DP), DIMENSION(SIZE(covar,1),SIZE(covar,2)) :: L\n\n !-----------------------------------------------------------------------\n \n ! Covariance size\n M = SIZE(covar(:,:),1)\n IF (SIZE(covar(:,:),2) /= M) &\n CALL STRIKE(\"RAN_MULTINORM\",\"wrong size for COVAR\")\n \n ! Draw independent normal variables\n theta(:,:) = RAND_NORM(M,N)\n\n ! Perform Cholesky decompsition\n L(:,:) = CHOLESKY_DECOMP(covar(:,:)) \n rand_multinorm_v(:,:) = MATMUL(L(:,:),theta(:,:))\n IF (PRESENT(mu)) THEN\n FORALL (i=1:N) rand_multinorm_v(:,i) = rand_multinorm_v(:,i) + mu(:)\n END IF\n\n !-----------------------------------------------------------------------\n \n END FUNCTION rand_multinorm_v\n\n ! Interface shell\n FUNCTION rand_multinorm_s (covar,mu) \n USE utilities, ONLY: DP\n IMPLICIT NONE\n REAL(DP), DIMENSION(:,:), INTENT(IN) :: covar\n REAL(DP), DIMENSION(:), INTENT(IN), OPTIONAL :: mu\n REAL(DP), DIMENSION(SIZE(covar,1)) :: rand_multinorm_s\n rand_multinorm_s(:) = RESHAPE(RAND_MULTINORM_V(1,covar,mu),[SIZE(covar,1)])\n END FUNCTION rand_multinorm_s\n\n\n !==========================================================================\n ! x = RAND_STUDENT (N,M,Df,center,sigma)\n !\n ! Returns an array[N] of random variables following a Student's t \n ! distribution of mean CENTER and standard deviation SIGMA, with Df degrees\n ! of freedom. Taken from http://www.netlib.org/random/.\n !==========================================================================\n\n ! Scalar function for a reduced random variable\n !----------------------------------------------\n FUNCTION rand_student_m(N,M,Df,center,sigma)\n\n USE utilities, ONLY: DP, strike, NaN\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: N, M, Df\n REAL(DP), INTENT(IN), OPTIONAL :: center, sigma\n REAL(DP), DIMENSION(N,M) :: rand_student_m\n\n REAL(DP), PARAMETER :: zero = 0.0_DP, quart = 0.25_DP, half = 0.5_DP\n REAL(DP), PARAMETER :: one = 1.0_DP, two = 2.0_DP, three = 3.0_DP \n REAL(DP), PARAMETER :: four = 4.0_DP, five = 5.0_DP, sixteen = 16.0_DP\n\n INTEGER :: mm, i, j\n REAL(DP), SAVE :: s, c, a, f, g\n REAL(DP) :: r, x, v\n\n !-----------------------------------------------------------------------\n\n IF (Df < 1) THEN\n rand_student_m(:,:) = NaN()\n RETURN\n END IF\n \n mm = 0\n DO i=1,N\n DO j=1,M\n IF (Df /= mm) THEN ! Initialization, if necessary\n s = Df\n c = - quart * (s + one)\n a = four / (one + one/s)**c\n f = sixteen / a\n IF (Df > 1) THEN\n g = s - one\n g = ((s + one)/g)**c * SQRT((s+s)/g)\n ELSE\n g = one\n END IF\n mm = Df\n END IF\n\n DO\n CALL RANDOM_NUMBER(r)\n IF (r <= zero) CYCLE\n CALL RANDOM_NUMBER(v)\n x = (two*v - one)*g/r\n v = x*x\n IF (v > five - a*r) THEN\n IF (Df >= 1 .AND. r*(v + three) > f) CYCLE\n IF (r > (one + v/s)**c) CYCLE\n END IF\n EXIT\n END DO\n rand_student_m(i,j) = x\n END DO\n END DO\n\n IF (PRESENT(sigma)) rand_student_m(:,:) = rand_student_m(:,:) * sigma\n IF (PRESENT(center)) rand_student_m(:,:) = rand_student_m(:,:) + center\n\n !-----------------------------------------------------------------------\n\n END FUNCTION rand_student_m\n\n ! Interface shell\n FUNCTION rand_student_v(N,Df,center,sigma)\n USE utilities, ONLY: DP\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: N, Df\n REAL(DP), INTENT(IN), OPTIONAL :: center, sigma\n REAL(DP), DIMENSION(N) :: rand_student_v\n rand_student_v(:) &\n = RESHAPE(RAND_STUDENT_M(N,1,Df,CENTER=center,SIGMA=sigma),[N])\n END FUNCTION rand_student_v\n FUNCTION rand_student_s(Df,center,sigma)\n USE utilities, ONLY: DP\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: Df\n REAL(DP), INTENT(IN), OPTIONAL :: center, sigma\n REAL(DP) :: rand_student_s\n rand_student_s = MAXVAL(RAND_STUDENT_M(1,1,Df,CENTER=center,SIGMA=sigma))\n END FUNCTION rand_student_s\n\n\n !==========================================================================\n ! x = RAND_MULTISTUDENT (N,Df,covar[M,M],mu)\n !\n ! Returns an array[M,N] of random variables following a multivariate t\n ! distribution with covariance matrix COVAR. \n !==========================================================================\n\n FUNCTION rand_multistudent_v (N,Df,covar,mu) \n\n USE utilities, ONLY: DP, strike\n USE linear_system, ONLY: cholesky_decomp\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: N, Df\n REAL(DP), DIMENSION(:,:), INTENT(IN) :: covar\n REAL(DP), DIMENSION(:), INTENT(IN), OPTIONAL :: mu\n REAL(DP), DIMENSION(SIZE(covar,1),N) :: rand_multistudent_v\n\n INTEGER :: i, M\n REAL(DP), DIMENSION(SIZE(covar,1),N) :: theta\n REAL(DP), DIMENSION(SIZE(covar,1),SIZE(covar,2)) :: L\n\n !-----------------------------------------------------------------------\n \n ! Covariance size\n M = SIZE(covar(:,:),1)\n IF (SIZE(covar(:,:),2) /= M) &\n CALL STRIKE(\"RAN_MULTISTUDENT\",\"wrong size for COVAR\")\n \n ! Draw independent normal variables\n theta(:,:) = RAND_STUDENT(M,N,Df)\n\n ! Perform Cholesky decompsition\n L(:,:) = CHOLESKY_DECOMP(covar(:,:)) \n rand_multistudent_v(:,:) = MATMUL(L(:,:),theta(:,:))\n IF (PRESENT(mu)) THEN\n FORALL (i=1:N) rand_multistudent_v(:,i) = rand_multistudent_v(:,i) + mu(:)\n END IF\n\n !-----------------------------------------------------------------------\n \n END FUNCTION rand_multistudent_v\n\n ! Interface shell\n FUNCTION rand_multistudent_s (Df,covar,mu) \n USE utilities, ONLY: DP\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: Df\n REAL(DP), DIMENSION(:,:), INTENT(IN) :: covar\n REAL(DP), DIMENSION(:), INTENT(IN), OPTIONAL :: mu\n REAL(DP), DIMENSION(SIZE(covar,1)) :: rand_multistudent_s\n rand_multistudent_s(:) = RESHAPE(RAND_MULTISTUDENT_V(1,Df,covar,mu), &\n [SIZE(covar,1)])\n END FUNCTION rand_multistudent_s\n\n\n !==========================================================================\n ! x = GEN_POISSON (mu,first)\n !\n ! Returns a random poissonian deviate of average MU. FIRST for initiating\n ! the serie. Taken from http://users.bigpond.net.au/amiller/.\n !==========================================================================\n\n FUNCTION gen_poisson (mu,first) RESULT(ival)\n\n USE utilities, ONLY: DP\n IMPLICIT NONE\n\n REAL(DP), INTENT(IN) :: mu\n LOGICAL, INTENT(IN) :: first\n INTEGER :: ival\n\n REAL(DP), PARAMETER :: a0 = -0.5_DP, a1 = 0.3333333_DP, a2 = -0.2500068_DP\n REAL(DP), PARAMETER :: a3 = 0.2000118_DP, a4 = -0.1661269_DP\n REAL(DP), PARAMETER :: a5 = 0.1421878_DP, a6 = -0.1384794_DP\n REAL(DP), PARAMETER :: a7 = 0.1250060_DP\n REAL(DP), DIMENSION(10), PARAMETER :: &\n fact(10) = [ 1._DP, 1._DP, 2._DP, 6._DP, 24._DP, 120._DP, 720._DP, &\n 5040._DP, 40320._DP, 362880._DP ]\n\n INTEGER :: j, k, kflag\n INTEGER, SAVE :: l, m\n REAL(DP) :: b1, b2, c, c0, c1, c2, c3, del, difmuk, e, fk, fx, fy, g\n REAL(DP) :: omega, px, py, t, u, v, x, xx\n REAL(DP), SAVE :: s, d, p, q, p0\n LOGICAL, SAVE :: full_init\n REAL(DP), SAVE :: pp(35)\n\n !-----------------------------------------------------------------------\n\n fk = 0._DP\n difmuk = 0._DP\n ival = 0\n\n valofmu: IF (mu > 10.0) THEN\n ! CASE A. (Recalculation OF S, D, L if MU has changed)\n !--------\n\n IF (first) THEN\n s = SQRT(mu)\n d = 6._DP*mu*mu\n ! The Poisson probabilities Pk exceed the discrete normal\n ! probabilities Fk whenever K >= M(MU). L=IFIX(MU-1.1484)\n ! is an upper bound to M(MU) for all MU >= 10 .\n l = INT(mu - 1.1484_DP)\n full_init = .False.\n END IF\n\n ! STEP N. Normal sample - random_normal() for standard normal deviate\n g = mu + s*MAXVAL(rand_norm(1))\n IF (g > 0.0) THEN\n ival = INT(g)\n ! STEP I. Immediate acceptance if IVAL is large enough\n IF (ival>=l) RETURN\n ! STEP S. Squeeze acceptance - Sample U\n fk = ival\n difmuk = mu - fk\n CALL RANDOM_NUMBER(u)\n IF (d*u >= difmuk*difmuk*difmuk) RETURN\n END IF\n\n ! STEP P. Preparations for steps Q and H.\n ! (Recpitulations of parameters if necessary)\n ! .3989423=(2*PI)**(-.5) .416667E-1=1./24. .1428571=1./7.\n ! The quantities B1, B2, C3, C2, C1, C0 are for the Hermite\n ! Aproximations to the discrete normal probabilities Fk.\n ! C=.1069/MU guarantees majorization by the 'Hat'-function.\n IF (.NOT. full_init) THEN\n omega = 0.3989423_DP / s\n b1 = 0.4166667E-1/mu\n b2 = 0.3*b1*b1\n c3 = 0.1428571*b1*b2\n c2 = b2 - 15.*c3\n c1 = b1 - 6.*b2 + 45.*c3\n c0 = 1. - b1 + 3.*b2 - 15.*c3\n c = 0.1069/mu\n full_init = .True.\n ELSE \n omega = 0._DP\n c3 = 0._DP\n c2 = 0._DP\n c1 = 0._DP\n c0 = 0._DP\n c = 0._DP\n END IF\n\n IF (g < 0.0) GOTO 50\n\n ! 'Subroutine' F is called (KFLAG=0 for correct return)\n kflag = 0\n GOTO 70\n\n ! STEP Q. Quotient acceptance (rare case)\n 40 IF (fy-u*fy <= py*EXP(px-fx)) RETURN\n\n ! STEP E. Exponential sample - rand_exp() for standard exponential\n ! Deviate E and sample T from the Laplace 'Hat'\n ! (If T <= -.6744 then Pk < Fk for all MU >= 10.)\n 50 e = MAXVAL(rand_exp(1))\n CALL RANDOM_NUMBER(u)\n u = u + u - 1.\n t = 1.8 + SIGN(e, u)\n IF (t <= (-.6744)) GOTO 50\n ival = INT(mu + s*t)\n fk = ival\n difmuk = mu - fk\n\n ! 'Subroutine' F is called (KFLAG=1 for correct return)\n kflag = 1\n GOTO 70\n\n ! STEP H. Hat acceptance (E is repeated on rejection)\n 60 IF (c*ABS(u) > py*EXP(px+e) - fy*EXP(fx+e)) GOTO 50\n RETURN\n\n ! STEP F. 'Subroutine' F. Calculation of Px, Py, Fx, Fy.\n ! Case IVAL < 10 uses factorials from table fact\n 70 IF (ival>=10) GOTO 80\n px = -mu\n py = mu**ival/fact(ival+1)\n GOTO 110\n\n ! Case IVAL >= 10 uses polynomial aproximation\n ! A0-A7 for accuracy when advisable\n ! .8333333E-1=1./12. .3989423=(2*PI)**(-.5)\n 80 del = .8333333E-1/fk\n del = del - 4.8*del*del*del\n v = difmuk/fk\n IF (ABS(v)>0.25) THEN\n px = fk*LOG(1. + v) - difmuk - del\n ELSE\n px = fk*v*v* (((((((a7*v+a6)*v+a5)*v+a4)*v+a3)*v+a2)*v+a1)*v+a0) - del\n END IF\n py = .3989423/SQRT(fk)\n 110 x = (0.5 - difmuk)/s\n xx = x*x\n fx = -0.5*xx\n fy = omega * (((c3*xx + c2)*xx + c1)*xx + c0)\n IF (kflag <= 0) GOTO 40\n GOTO 60\n\n ELSE\n ! CASE B. mu < 10\n !-------\n ! Start new table and calculate P0 if necessary\n\n IF (first) THEN\n m = MAX(1,INT(mu))\n l = 0\n p = EXP(-mu)\n q = p\n p0 = p\n END IF\n\n ! STEP U. Uniform sample for inversion method\n DO\n CALL RANDOM_NUMBER(u)\n ival = 0\n IF (u <= p0) RETURN\n\n ! STEP T. Table comparison until the end PP(L) of the\n ! PP-Table of cumulative Poisson probabilities\n ! (0.458=PP(9) for MU=10)\n IF (l == 0) GOTO 150\n j = 1\n IF (u > 0.458) j = MIN(l, m)\n DO k=j,l\n IF (u <= pp(k)) GOTO 180\n END DO\n IF (l == 35) CYCLE\n\n ! STEP C. Creation of new Poisson probabilities P\n ! and their cumulatives Q=PP(K)\n 150 l = l + 1\n DO k=l,35\n p = p*mu / k\n q = q + p\n pp(k) = q\n IF (u <= q) GOTO 170\n END DO\n l = 35\n END DO\n\n 170 l = k\n 180 ival = k\n RETURN\n\n END IF valofmu\n\n RETURN\n\n !-----------------------------------------------------------------------\n\n END FUNCTION gen_poisson\n\n\n !==========================================================================\n ! x = RAND_POISSON (N,tau,first)\n !\n ! Returns an array[N] of random poissonian variables with a timescale of \n ! TAU. Taken from http://users.bigpond.net.au/amiller/ .\n !==========================================================================\n\n FUNCTION rand_poisson (N,tau,first)\n\n USE utilities, ONLY: DP\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: N\n REAL(DP), INTENT(IN) :: tau\n INTEGER, DIMENSION(N) :: rand_poisson\n LOGICAL, INTENT(IN), OPTIONAL :: first\n\n INTEGER :: i\n LOGICAL :: prem\n\n !-----------------------------------------------------------------------\n\n IF (PRESENT(first)) THEN ; prem = first ; ELSE ; prem = .True. ; END IF\n\n rand_poisson(1) = GEN_POISSON(1._DP/tau,FIRST=prem)\n rand_poisson(2:N) = (/(GEN_POISSON(1._DP/tau,FIRST=.False.),i=2,N)/)\n\n !-----------------------------------------------------------------------\n\n END FUNCTION rand_poisson\n\n\n !==========================================================================\n ! x[N] = RAND_GENERAL(N,func,limits,xlog,ylog,limited,accmax)\n !\n ! Draw random sample from a user defined distribution.\n !==========================================================================\n\n FUNCTION rand_general_vec (N,func,limits,xlog,ylog,lnfunc,verbose,limited, &\n accuracy,Nmax,Nsamp,xgrid,pgrid,Fgrid,proper)\n\n USE utilities, ONLY: DP \n USE arrays, ONLY: ramp, uniq_sorted\n USE interpolation, ONLY: interp_lin_sorted\n USE adaptative_grid, ONLY: gridadapt1D\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: N\n INTERFACE\n FUNCTION func (x)\n USE utilities, ONLY: DP\n IMPLICIT NONE\n REAL(DP), DIMENSION(:), INTENT(IN) :: x\n REAL(DP), DIMENSION(SIZE(x)) :: func\n END FUNCTION func\n END INTERFACE\n REAL(DP), DIMENSION(2), INTENT(IN) :: limits\n LOGICAL, INTENT(IN), OPTIONAL :: xlog, ylog, lnfunc, verbose\n LOGICAL, DIMENSION(2), INTENT(IN), OPTIONAL :: limited\n REAL(DP), INTENT(IN), OPTIONAL :: accuracy\n INTEGER, INTENT(IN), OPTIONAL :: Nmax\n INTEGER, INTENT(OUT), OPTIONAL :: Nsamp\n REAL(DP), INTENT(OUT), DIMENSION(:), ALLOCATABLE, OPTIONAL :: xgrid, pgrid\n REAL(DP), INTENT(OUT), DIMENSION(:), ALLOCATABLE, OPTIONAL :: Fgrid\n LOGICAL, INTENT(OUT), DIMENSION(N), OPTIONAL :: proper\n REAL(DP), DIMENSION(N) :: rand_general_vec\n\n INTEGER, PARAMETER :: Ncoarse = 10\n REAL(DP), PARAMETER :: accmax0 = 1.E-3_DP\n\n INTEGER :: Nfine, Ncdf\n REAL(DP) :: acc, xinf0, xsup1, accmax\n REAL(DP), DIMENSION(Ncoarse) :: xcoarse\n REAL(DP), DIMENSION(N) :: rand\n REAL(DP), DIMENSION(2) :: lim\n REAL(DP), DIMENSION(:), ALLOCATABLE :: xfine, yfine, prim, xuniq, Funiq\n LOGICAL :: xl, yl, lnfn, verb\n LOGICAL, DIMENSION(2) :: adjxlim\n LOGICAL, DIMENSION(N) :: prop\n LOGICAL, DIMENSION(:), ALLOCATABLE :: keepinf, keepsup, keep\n\n !-----------------------------------------------------------------------\n\n ! Log axes\n xl = .False.\n IF (PRESENT(xlog)) xl = xlog\n yl = .False.\n IF (PRESENT(ylog)) yl = ylog\n\n ! User defined function\n lnfn = .False.\n IF (PRESENT(lnfunc)) lnfn = lnfunc\n\n ! Limited or not\n adjxlim(:) = .False.\n IF (PRESENT(limited)) adjxlim(:) = ( .NOT. limited(:) )\n\n ! Random drawing\n IF (PRESENT(accuracy)) THEN ; accmax = accuracy \n ELSE ; accmax = accmax0 ; END IF\n CALL RANDOM_NUMBER(rand(:))\n acc = MIN( accmax*ABS(MINVAL(rand(:))), accmax*ABS(1._DP-MAXVAL(rand(:))) )\n \n ! Coarse grid\n xcoarse(:) = RAMP(Ncoarse,limits(1),limits(2),XLOG=xl)\n\n ! Adpatative grid\n IF (PRESENT(verbose)) THEN ; verb = verbose ; ELSE ; verb = .False. ; END IF\n CALL GRIDADAPT1D(xcoarse,xfine,yfine,func,acc,NMAX=Nmax,INTEG=.True., &\n PRIMITIVE=prim,XLOG=xl,YLOG=yl,VERBOSE=verb,LNFUNC=lnfn, &\n RESCALE=.True.,SLIM=.False.,ADJUSTXLIM=adjxlim(:))\n Nfine = SIZE(xfine(:))\n IF (PRESENT(Nsamp)) Nsamp = Nfine\n prim(:) = prim(:) / prim(Nfine)\n \n ! Ensure the most compact support: if there are several CDF=0, take the \n ! largest x, if there are several CDF=1 take the smaller x.\n ALLOCATE (keepinf(Nfine),keepsup(Nfine),keep(Nfine))\n keepinf(:) = UNIQ_SORTED(prim(:),LAST=.True.)\n keepsup(:) = UNIQ_SORTED(prim(:),FIRST=.True.)\n keep(:) = MERGE(keepinf(:),keepsup(:),prim(:) < 0.5_DP)\n \n ! Remove values outside of support\n xinf0 = MAXVAL(PACK(xfine(:),prim(:) == 0._DP))\n xsup1 = MINVAL(PACK(xfine(:),prim(:) == 1._DP))\n keep(:) = MERGE(keep(:),.False.,xfine(:) >= xinf0)\n keep(:) = MERGE(keep(:),.False.,xfine(:) <= xsup1)\n \n ! Pack the CDF\n Ncdf = COUNT(keep)\n ALLOCATE (Funiq(Ncdf),xuniq(Ncdf))\n Funiq(:) = PACK(prim(:),keep(:))\n xuniq(:) = PACK(xfine(:),keep(:))\n \n ! Interpolate the values (y->x)\n rand_general_vec(:) = INTERP_LIN_SORTED(xuniq(:),Funiq(:),rand(:),YLOG=xl)\n \n ! Make sure the value does not get out of the range\n lim(1) = MAX( xuniq(1), INTERP_LIN_SORTED(xuniq(:),Funiq(:),0._DP) )\n lim(2) = MIN( xuniq(Ncdf), INTERP_LIN_SORTED(xuniq(:),Funiq(:),1._DP) )\n prop(:) = .True.\n WHERE (rand_general_vec(:) < lim(1))\n rand_general_vec(:) = lim(1)\n prop(:) = .False.\n END WHERE\n WHERE (rand_general_vec(:) > lim(2))\n rand_general_vec(:) = lim(2)\n prop(:) = .False.\n END WHERE\n IF (PRESENT(proper)) proper(:) = prop(:)\n \n ! For debugging\n IF (PRESENT(xgrid)) THEN\n ALLOCATE (xgrid(Ncdf))\n xgrid(:) = xuniq(:)\n END IF\n IF (PRESENT(pgrid)) THEN\n ALLOCATE (pgrid(Ncdf))\n pgrid(:) = PACK(yfine(:),keep(:))\n END IF\n IF (PRESENT(Fgrid)) THEN\n ALLOCATE (Fgrid(Ncdf))\n Fgrid(:) = Funiq(:)\n END IF\n\n ! Clean memory space\n DEALLOCATE (xfine,yfine,prim,xuniq,Funiq,keepinf,keepsup,keep)\n \n !-----------------------------------------------------------------------\n\n END FUNCTION rand_general_vec\n\n ! Interface shell\n FUNCTION rand_general_scl (func,limits,xlog,ylog,lnfunc,verbose,limited, &\n accuracy,Nmax,Nsamp,xgrid,pgrid,Fgrid,proper)\n USE utilities, ONLY: DP\n IMPLICIT NONE\n INTERFACE\n FUNCTION func (x)\n USE utilities, ONLY: DP\n IMPLICIT NONE\n REAL(DP), DIMENSION(:), INTENT(IN) :: x\n REAL(DP), DIMENSION(SIZE(x)) :: func\n END FUNCTION func\n END INTERFACE\n REAL(DP), DIMENSION(2), INTENT(IN) :: limits\n LOGICAL, INTENT(IN), OPTIONAL :: xlog, ylog, lnfunc, verbose\n LOGICAL, DIMENSION(2), INTENT(IN), OPTIONAL :: limited\n REAL(DP), INTENT(IN), OPTIONAL :: accuracy\n INTEGER, INTENT(IN), OPTIONAL :: Nmax\n INTEGER, INTENT(OUT), OPTIONAL :: Nsamp\n REAL(DP), DIMENSION(:), ALLOCATABLE, INTENT(OUT), OPTIONAL :: xgrid, pgrid\n REAL(DP), DIMENSION(:), ALLOCATABLE, INTENT(OUT), OPTIONAL :: Fgrid\n LOGICAL, INTENT(OUT), OPTIONAL :: proper\n REAL(DP) :: rand_general_scl\n LOGICAL, DIMENSION(1) :: prop\n rand_general_scl = MINVAL(RAND_GENERAL_VEC(1,func,limits,XLOG=xlog, &\n YLOG=ylog,VERBOSE=verbose, &\n LNFUNC=lnfunc,LIMITED=limited, &\n ACCURACY=accuracy,NMAX=Nmax, &\n NSAMP=Nsamp,XGRID=xgrid, & \n PGRID=pgrid,FGRID=Fgrid, &\n PROPER=prop))\n IF (PRESENT(proper)) proper = prop(1)\n END FUNCTION rand_general_scl\n\n !-------------------------------------------------------------------------\n\nEND MODULE random\n", "meta": {"hexsha": "feefb70c073318238a2a2fd7c1f572de3211bdba", "size": 31581, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MILES/swing/Math/random.f90", "max_stars_repo_name": "kxxdhdn/MISSILE", "max_stars_repo_head_hexsha": "89dea38aa9247f20c444ccd0b832c674be275fbf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MILES/swing/Math/random.f90", "max_issues_repo_name": "kxxdhdn/MISSILE", "max_issues_repo_head_hexsha": "89dea38aa9247f20c444ccd0b832c674be275fbf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MILES/swing/Math/random.f90", "max_forks_repo_name": "kxxdhdn/MISSILE", "max_forks_repo_head_hexsha": "89dea38aa9247f20c444ccd0b832c674be275fbf", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.0, "max_line_length": 80, "alphanum_fraction": 0.5270574079, "num_tokens": 9175, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299591537478, "lm_q2_score": 0.8244619306896956, "lm_q1q2_score": 0.7628168784558472}} {"text": "program minval_maxval_mask\n\nimplicit none (type, external)\n\ninteger :: A(5) = [0, 5, 1, 2, 3]\ninteger :: L\n\nlogical :: mask(size(A))\n\n\nif(maxval(A, dim=1) /= 5) error stop \"maxval sanity\"\nif(minval(A, dim=1) /= 0) error stop \"minval sanity\"\n\nif(maxval(A, dim=1, mask=[.true., .false., .true., .true., .true.]) /= 3) error stop \"maxval mask sanity\"\nif(minval(A, dim=1, mask=[.false., .true., .true., .true., .true.]) /= 1) error stop \"minval mask sanity\"\n\nmask = .false.\nif (maxval(A, dim=1, mask=mask) /= -huge(0)-1) error stop \"maxval mask = .false.\"\nif (minval(A, dim=1, mask=mask) /= huge(0)) error stop \"minval mask = .false.\"\n\nprint *, \"OK: minval_maxval_mask\"\n\nend program\n\n\n\n! if (maxval(A, dim=1, mask=mask) /= huge(0)) error stop \"maxval mask = .false.\"\n", "meta": {"hexsha": "d6fda146ca2d20a7e04bd00c523c989817f94fcc", "size": 763, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "standard/minval_maxval_mask.f90", "max_stars_repo_name": "hbayraktaroglu/fortran2018-examples", "max_stars_repo_head_hexsha": "87407c9aecbdefd1862a5f0c962ec8e335394032", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2016-05-17T10:01:06.000Z", "max_stars_repo_stars_event_max_datetime": "2016-10-11T09:28:21.000Z", "max_issues_repo_path": "src/standard/minval_maxval_mask.f90", "max_issues_repo_name": "scivision/fortran2015-examples", "max_issues_repo_head_hexsha": "23fc7090997ecb4b838ebc1f09b86e2872d7141c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/standard/minval_maxval_mask.f90", "max_forks_repo_name": "scivision/fortran2015-examples", "max_forks_repo_head_hexsha": "23fc7090997ecb4b838ebc1f09b86e2872d7141c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.25, "max_line_length": 105, "alphanum_fraction": 0.629095675, "num_tokens": 274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299488452012, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7628168599802618}} {"text": "\t!>@author\r\n\t!>Paul Connolly, The University of Manchester\r\n\t!>@brief\r\n\t!>code to find position in an array\r\n\t!>param[in] xarr: array of xs \r\n\t!>param[inout] x: value where position wanted\r\n\t!>@return find_pos: integer pointing to the position in the array\r\n\tfunction find_pos(xarr,x)\r\n\t use numerics_type\r\n implicit none\r\n real(wp), dimension(:), intent(in) :: xarr\r\n real(wp), intent(in) :: x\r\n integer(i4b) :: find_pos\r\n integer(i4b) :: n,ilow,imid,iupp\r\n logical(lgt) :: ascnd\r\n n=size(xarr)\r\n ascnd = (xarr(n) >= xarr(1))\r\n ilow=0\r\n iupp=n+1\r\n do\r\n if (iupp-ilow <= 1) exit\r\n imid=(iupp+ilow)/2 ! just bisects array until it finds position \r\n if (ascnd .eqv. (x >= xarr(imid))) then\r\n ilow=imid\r\n else\r\n iupp=imid\r\n end if\r\n end do\r\n if (x == xarr(1)) then\r\n find_pos=1\r\n else if (x == xarr(n)) then\r\n find_pos=n-1\r\n else\r\n find_pos=ilow\r\n end if\r\n\tend function find_pos\r\n", "meta": {"hexsha": "add65e1035ff216b4a69d87022332391bd51a915", "size": 1110, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "find_pos.f90", "max_stars_repo_name": "UoM-maul1609/open-source-numerical-functions", "max_stars_repo_head_hexsha": "35201f021bbdcc41fcda8cccfd0639b8d1f6445f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "find_pos.f90", "max_issues_repo_name": "UoM-maul1609/open-source-numerical-functions", "max_issues_repo_head_hexsha": "35201f021bbdcc41fcda8cccfd0639b8d1f6445f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "find_pos.f90", "max_forks_repo_name": "UoM-maul1609/open-source-numerical-functions", "max_forks_repo_head_hexsha": "35201f021bbdcc41fcda8cccfd0639b8d1f6445f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0, "max_line_length": 77, "alphanum_fraction": 0.5135135135, "num_tokens": 322, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7628082958220551}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc\nc ... file slapec.f\nc\nc this file includes documentation and code for\nc subroutine slapec i\nc\nc ... files which must be loaded with slapec.f\nc\nc sphcom.f, hrfft.f, shaec.f, shsec.f\nc\nc\nc\nc subroutine slapec(nlat,nlon,isym,nt,slap,ids,jds,a,b,mdab,ndab,\nc + wshsec,lshsec,work,lwork,ierror)\nc\nc\nC*PL*ERROR* Comment line too long\nc given the scalar spherical harmonic coefficients a and b, precomputed\nC*PL*ERROR* Comment line too long\nc by subroutine shaec for a scalar field sf, subroutine slapec computes\nc the laplacian of sf in the scalar array slap. slap(i,j) is the\nc laplacian of sf at the colatitude\nc\nc theta(i) = (i-1)*pi/(nlat-1)\nc\nc and east longitude\nc\nc lambda(j) = (j-1)*2*pi/nlon\nc\nc on the sphere. i.e.\nc\nc slap(i,j) =\nc\nc 2 2\nC*PL*ERROR* Comment line too long\nc [1/sint*d (sf(i,j)/dlambda + d(sint*d(sf(i,j))/dtheta)/dtheta]/sint\nc\nc\nc where sint = sin(theta(i)). the scalar laplacian in slap has the\nC*PL*ERROR* Comment line too long\nc same symmetry or absence of symmetry about the equator as the scalar\nc field sf. the input parameters isym,nt,mdab,ndab must have the\nC*PL*ERROR* Comment line too long\nc same values used by shaec to compute a and b for sf. the associated\nc legendre functions are recomputed rather than stored as they are\nc in subroutine slapes.\n\nc\nc input parameters\nc\nc nlat the number of colatitudes on the full sphere including the\nc poles. for example, nlat = 37 for a five degree grid.\nc nlat determines the grid increment in colatitude as\nc pi/(nlat-1). if nlat is odd the equator is located at\nc grid point i=(nlat+1)/2. if nlat is even the equator is\nc located half way between points i=nlat/2 and i=nlat/2+1.\nc nlat must be at least 3. note: on the half sphere, the\nc number of grid points in the colatitudinal direction is\nc nlat/2 if nlat is even or (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct longitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than zero. the axisymmetric case corresponds to nlon=1.\nc the efficiency of the computation is improved when nlon\nc is a product of small prime numbers.\nc\nC*PL*ERROR* Comment line too long\nc isym this parameter should have the same value input to subroutine\nC*PL*ERROR* Comment line too long\nc shaec to compute the coefficients a and b for the scalar field\nc sf. isym is set as follows:\nc\nc = 0 no symmetries exist in sf about the equator. scalar\nC*PL*ERROR* Comment line too long\nc synthesis is used to compute slap on the entire sphere.\nc i.e., in the array slap(i,j) for i=1,...,nlat and\nc j=1,...,nlon.\nc\nc = 1 sf and slap are antisymmetric about the equator. the\nc synthesis used to compute slap is performed on the\nc northern hemisphere only. if nlat is odd, slap(i,j) is\nc computed for i=1,...,(nlat+1)/2 and j=1,...,nlon. if\nc nlat is even, slap(i,j) is computed for i=1,...,nlat/2\nc and j=1,...,nlon.\nc\nc\nc = 2 sf and slap are symmetric about the equator. the\nc synthesis used to compute slap is performed on the\nc northern hemisphere only. if nlat is odd, slap(i,j) is\nc computed for i=1,...,(nlat+1)/2 and j=1,...,nlon. if\nc nlat is even, slap(i,j) is computed for i=1,...,nlat/2\nc and j=1,...,nlon.\nc\nc\nc nt the number of analyses. in the program that calls slapec\nc the arrays slap,a, and b can be three dimensional in which\nc case multiple synthesis will be performed. the third index\nc is the synthesis index which assumes the values k=1,...,nt.\nc for a single analysis set nt=1. the description of the\nc remaining parameters is simplified by assuming that nt=1\nc or that all the arrays are two dimensional.\nc\nc ids the first dimension of the array slap as it appears in the\nc program that calls slapec. if isym = 0 then ids must be at\nc least nlat. if isym > 0 and nlat is even then ids must be\nc at least nlat/2. if isym > 0 and nlat is odd then ids must\nc be at least (nlat+1)/2.\nc\nc jds the second dimension of the array slap as it appears in the\nc program that calls slapec. jds must be at least nlon.\nc\nc\nc a,b two or three dimensional arrays (see input parameter nt)\nc that contain scalar spherical harmonic coefficients\nc of the scalar field sf as computed by subroutine shaec.\nc *** a,b must be computed by shaec prior to calling slapec.\nc\nc\nc mdab the first dimension of the arrays a and b as it appears\nc in the program that calls slapec. mdab must be at\nc least min0(nlat,(nlon+2)/2) if nlon is even or at least\nc min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc ndab the second dimension of the arrays a and b as it appears\nc in the program that calls slapec. ndbc must be at least\nc least nlat.\nc\nc mdab,ndab should have the same values input to shaec to\nc compute the coefficients a and b.\nc\nc\nc wshsec an array which must be initialized by subroutine shseci\nc before calling slapec. once initialized, wshsec\nc can be used repeatedly by slapec as long as nlat and nlon\nc remain unchanged. wshsec must not be altered between calls\nc of slapec.\nc\nc lshsec the dimension of the array wshsec as it appears in the\nc program that calls slapec. let\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lshsec must be greater than or equal to\nc\nc 2*nlat*l2+3*((l1-2)*(nlat+nlat-l1-1))/2+nlon+15\nc\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls slapec. define\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc if isym = 0 let\nc\nc lwkmin = nlat*(2*nt*nlon+max0(6*l2,nlon)+2*nt*l1+1.\nc\nc if isym > 0 let\nc\nC*PL*ERROR* Comment line too long\nc lwkmin = l2*(2*nt*nlon+max0(6*nlat,nlon))+nlat*(2*nt*l1+1)\nc\nc\nc then lwork must be greater than or equal to lwkmin (see ierror=10)\nc\nc **************************************************************\nc\nc output parameters\nc\nc\nC*PL*ERROR* Comment line too long\nc slap a two or three dimensional arrays (see input parameter nt) that\nC*PL*ERROR* Comment line too long\nc contain the scalar laplacian of the scalar field sf. slap(i,j)\nc is the scalar laplacian at the colatitude\nc\nc theta(i) = (i-1)*pi/(nlat-1)\nc\nc and longitude\nc\nc lambda(j) = (j-1)*2*pi/nlon\nc\nc for i=1,...,nlat and j=1,...,nlon.\nc\nc\nC*PL*ERROR* Comment line too long\nc ierror a parameter which flags errors in input parameters as follows:\nc\nc = 0 no errors detected\nc\nc = 1 error in the specification of nlat\nc\nc = 2 error in the specification of nlon\nc\nc = 3 error in the specification of ityp\nc\nc = 4 error in the specification of nt\nc\nc = 5 error in the specification of ids\nc\nc = 6 error in the specification of jds\nc\nc = 7 error in the specification of mdbc\nc\nc = 8 error in the specification of ndbc\nc\nc = 9 error in the specification of lshsec\nc\nc = 10 error in the specification of lwork\nc\nc\nc **********************************************************************\nc\nc end of documentation for slapec\nc\nc **********************************************************************\nc\nc\n SUBROUTINE DSLAPEC(NLAT,NLON,ISYM,NT,SLAP,IDS,JDS,A,B,MDAB,NDAB,\n + WSHSEC,LSHSEC,WORK,LWORK,IERROR)\n DOUBLE PRECISION SLAP\n DOUBLE PRECISION A\n DOUBLE PRECISION B\n DOUBLE PRECISION WSHSEC\n DOUBLE PRECISION WORK\n DIMENSION SLAP(IDS,JDS,NT),A(MDAB,NDAB,NT),B(MDAB,NDAB,NT)\n DIMENSION WSHSEC(LSHSEC),WORK(LWORK)\nc\nc check input parameters\nc\n IERROR = 1\n IF (NLAT.LT.3) RETURN\n IERROR = 2\n IF (NLON.LT.4) RETURN\n IERROR = 3\n IF (ISYM.LT.0 .OR. ISYM.GT.2) RETURN\n IERROR = 4\n IF (NT.LT.0) RETURN\n IERROR = 5\n IMID = (NLAT+1)/2\n IF ((ISYM.EQ.0.AND.IDS.LT.NLAT) .OR.\n + (ISYM.GT.0.AND.IDS.LT.IMID)) RETURN\n IERROR = 6\n IF (JDS.LT.NLON) RETURN\n IERROR = 7\n MMAX = MIN0(NLAT,NLON/2+1)\n IF (MDAB.LT.MMAX) RETURN\n IERROR = 8\n IF (NDAB.LT.NLAT) RETURN\n IERROR = 9\nc\nc set and verify saved work space length\nc\nc\n L1 = MIN0(NLAT, (NLON+2)/2)\n L2 = (NLAT+1)/2\n LWMIN = 2*NLAT*L2 + 3* ((L1-2)* (NLAT+NLAT-L1-1))/2 + NLON + 15\n IF (LSHSEC.LT.LWMIN) RETURN\n IERROR = 10\nc\nc set and verify unsaved work space length\nc\n LS = NLAT\n IF (ISYM.GT.0) LS = IMID\n NLN = NT*LS*NLON\n MN = MMAX*NLAT*NT\nc lwmin = nln+ls*nlon+2*mn+nlat\nc if (lwork .lt. lwmin) return\n L2 = (NLAT+1)/2\n L1 = MIN0(NLAT,NLON/2+1)\n IF (ISYM.EQ.0) THEN\n LWKMIN = NLAT* (2*NT*NLON+MAX0(6*L2,NLON)+2*NT*L1+1)\n ELSE\n LWKMIN = L2* (2*NT*NLON+MAX0(6*NLAT,NLON)) + NLAT* (2*NT*L1+1)\n END IF\n IF (LWORK.LT.LWKMIN) RETURN\n\n\n IERROR = 0\nc\nc set work space pointers\nc\n IA = 1\n IB = IA + MN\n IFN = IB + MN\n IWK = IFN + NLAT\n LWK = LWORK - 2*MN - NLAT\n CALL DSLAPEC1(NLAT,NLON,ISYM,NT,SLAP,IDS,JDS,A,B,MDAB,NDAB,\n + WORK(IA),WORK(IB),MMAX,WORK(IFN),WSHSEC,LSHSEC,\n + WORK(IWK),LWK,IERROR)\n RETURN\n END\n\n SUBROUTINE DSLAPEC1(NLAT,NLON,ISYM,NT,SLAP,IDS,JDS,A,B,MDAB,NDAB,\n + ALAP,BLAP,MMAX,FNN,WSHSEC,LSHSEC,WK,LWK,IERROR)\n DOUBLE PRECISION SLAP\n DOUBLE PRECISION A\n DOUBLE PRECISION B\n DOUBLE PRECISION ALAP\n DOUBLE PRECISION BLAP\n DOUBLE PRECISION FNN\n DOUBLE PRECISION WSHSEC\n DOUBLE PRECISION WK\n DOUBLE PRECISION FN\n DIMENSION SLAP(IDS,JDS,NT),A(MDAB,NDAB,NT),B(MDAB,NDAB,NT)\n DIMENSION ALAP(MMAX,NLAT,NT),BLAP(MMAX,NLAT,NT),FNN(NLAT)\n DIMENSION WSHSEC(LSHSEC),WK(LWK)\nc\nc set coefficient multiplyers\nc\n DO 1 N = 2,NLAT\n FN = DBLE(N-1)\n FNN(N) = FN* (FN+1.D0)\n 1 CONTINUE\nc\nc compute scalar laplacian coefficients for each vector field\nc\n DO 2 K = 1,NT\n DO 3 N = 1,NLAT\n DO 4 M = 1,MMAX\n ALAP(M,N,K) = 0.0D0\n BLAP(M,N,K) = 0.0D0\n 4 CONTINUE\n 3 CONTINUE\nc\nc compute m=0 coefficients\nc\n DO 5 N = 2,NLAT\n ALAP(1,N,K) = -FNN(N)*A(1,N,K)\n BLAP(1,N,K) = -FNN(N)*B(1,N,K)\n 5 CONTINUE\nc\nc compute m>0 coefficients\nc\n DO 6 M = 2,MMAX\n DO 7 N = M,NLAT\n ALAP(M,N,K) = -FNN(N)*A(M,N,K)\n BLAP(M,N,K) = -FNN(N)*B(M,N,K)\n 7 CONTINUE\n 6 CONTINUE\n 2 CONTINUE\nc\nc synthesize alap,blap into slap\nc\n CALL DSHSEC(NLAT,NLON,ISYM,NT,SLAP,IDS,JDS,ALAP,BLAP,MMAX,NLAT,\n + WSHSEC,LSHSEC,WK,LWK,IERROR)\n RETURN\n END\n", "meta": {"hexsha": "3f1c7a6293406aafc1e1147079c7fe336caf0eda", "size": 12934, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/sphere3.1_dp/slapec.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "external/sphere3.1_dp/slapec.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "external/sphere3.1_dp/slapec.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 34.3989361702, "max_line_length": 77, "alphanum_fraction": 0.553657028, "num_tokens": 4029, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693702514737, "lm_q2_score": 0.8031737940012417, "lm_q1q2_score": 0.762749551151646}} {"text": "subroutine GLQGridCoord(latglq, longlq, lmax, nlat, nlong)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tGiven a maximum spherical harmonic degree lmax, this routine \n!\twill determine the latitude and longitude coordinates associated with \n!\tgrids that are used in the Gauss-Legendre quadratue spherical harmonic \n!\texpansion routines. The coordinates are output in DEGREES.\n!\n!\tCalling Parameters\n!\t\tIN\t\n!\t\t\tlmax\t\tMaximum spherical harmonic degree of the expansion.\n!\t\tOUT\t\n!\t\t\tlatglq\t\tArray of latitude points used in Gauss-Legendre grids, in degrees.\n!\t\t\tlonglq\t\tArray of longitude points used in Gauss-Legendre grids, in degrees.\n!\t\t\tnlat, nlong\tNumber of latidude and longitude points.\n!\n!\tDependencies:\t\tNGLQSH, PreGLQ\n!\n!\tWritten by Mark Wieczorek, 2004\n!\tCompletely rewritten June 6, 2006.\n!\n!\tCopyright (c) 2005-2006 Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\tuse SHTOOLS, only: NGLQSH, PreGLQ\n\n\timplicit none\n\tinteger, intent(in) ::\tlmax\n\tinteger, intent(out) ::\tnlat, nlong\n\treal*8, intent(out) ::\tlatglq(:), longlq(:)\n\treal*8 ::\t\tpi, upper, lower, zero(lmax+1), w(lmax+1)\n\tinteger ::\t\ti\n\t\n\tif (size(latglq) < lmax+1) then\n\t\tprint*, \"Error --- GLQGridCoord\"\n\t\tprint*, \"LATGLQ must be dimensioned as (LMAX+1) where LMAX is \", lmax\n\t\tprint*, \"Input array is dimensioned as \", size(latglq)\n\t\tstop\n\telseif (size(longlq) < 2*lmax+1) then\n\t\tprint*, \"Error --- GLQGridCoord\"\n\t\tprint*, \"LONGLQ must be dimensioned as (2*LMAX+1) where LMAX is \", lmax\n\t\tprint*, \"Input array is dimensioned as \", size(longlq)\n\t\tstop\n\tendif\n\n\tpi = acos(-1.0d0)\n\n\tnlat = NGLQSH(lmax)\n\tnlong = 2*lmax +1\n\t\n\tupper = 1.0d0\n\tlower = -1.0d0\t\n\t\t\t\t\t\t\n\tcall PreGLQ(lower, upper, nlat, zero, w)\t! Determine Gauss Points and Weights.\n\n\tdo i=1, nlong\n\t\tlonglq(i) = 360.0d0*(i-1)/nlong\n\tenddo\n\n\tdo i=1, nlat\n\t\tlatglq(i) = asin(zero(i))*180.0d0/pi\n\tenddo\n\nend subroutine GLQGridCoord\n\n", "meta": {"hexsha": "0a5ee1477e20444c4404d6eea32eae2d1516b9bc", "size": 1964, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/GLQGridCoord.f95", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "spherical_splines/SHTOOLS/src/GLQGridCoord.f95", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "spherical_splines/SHTOOLS/src/GLQGridCoord.f95", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 29.3134328358, "max_line_length": 79, "alphanum_fraction": 0.6466395112, "num_tokens": 649, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7626854615547043}} {"text": "\tFUNCTION PR_ZALT ( altm, pres )\nC************************************************************************\nC* PR_ZALT\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes station elevation from altimeter and station\t*\nC* pressure. It is also used to estimate height at various pressure\t*\nC* levels from the altimeter in millibars. The PC library computes\t*\nC* ZMSL, Z000, Z950, Z850, Z800 by calling this function with PRES\t*\nC* equal to PMSL, 1000, 950, 850 and 800 respectively. The following\t*\nC* equation is used:\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* ZALT = [ To * ( 1 - ( ( PRES/ALTM ) ** expo ) ] / GAMMA\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* GAMMA = GAMUSD / 1000\t\t\t\t\t*\nC* To = US Std. Atmos. sea level temp in Kelvin\t\t*\nC* = TMCK + 15\t\t\t\t\t\t*\nC* expo = ( GAMMA * RDGAS ) / GRAVTY\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_ZALT ( ALTM, PRES )\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tALTM\t\tREAL\t \tAltimeter in millibars\t\t*\nC*\tPRES\t\tREAL\t \tPressure in millibars\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_ZALT\t\tREAL\t \tHeight in meters\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* I. Graffman/RDS\t11/84\toriginal source\t\t\t\t*\nC* I. Graffman/RDS\t12/87\tGEMPAK4\t\t\t\t\t*\nC* G. Huffman/GSC\t 8/88\tDocumentation; check ALTM, PRES .le. 0\t*\nC* T. Lee/GSC\t\t12/99\tUsed TMCK\t\t\t\t*\nC************************************************************************\n INCLUDE \t'GEMPRM.PRM'\n INCLUDE \t'ERMISS.FNC'\nC------------------------------------------------------------------------\nC*\tCheck for bad data.\nC\n\tIF ( ERMISS ( altm ) .or. ERMISS ( pres )\n + .or. ( altm .le. 0. ) .or. ( pres .le. 0. ) ) THEN\n\t PR_ZALT = RMISSD\n\t RETURN\n\tEND IF\nC\nC*\tSet constants.\nC\n\tto = TMCK + 15.\n\tgamma = GAMUSD / 1000.\nC\nC*\tCalculate the exponent and pressure ratio.\nC\n\texpo = ( gamma * RDGAS ) / GRAVTY \n\tprat = pres / altm\nC\nC*\tCalculate.\nC\n\tPR_ZALT = ( to * ( 1. - prat ** expo ) ) / gamma\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "315fd3984a50124887747cf988b4aed8e671f9f7", "size": 1935, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/przalt.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/prmcnvlib/pr/przalt.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/prmcnvlib/pr/przalt.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 31.7213114754, "max_line_length": 73, "alphanum_fraction": 0.496124031, "num_tokens": 655, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966702001758, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.76260875412198}} {"text": "\tFUNCTION PR_RHDP ( tmpc, relh )\nC************************************************************************\nC* PR_RHDP\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes DWPC from TMPC and RELH. The following\t*\nC* equation is used:\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* DWPC = 243.5 * LN (6.112) - 243.5 * LN (VAPR) /\t\t*\nC* ( LN (VAPR) - LN (6.112) - 17.67 )\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* VAPR = VAPS * RELH\t\t\t\t\t*\nC* VAPS = saturation vapor pressure\t\t\t*\nC* = PR_VAPR ( TMPC )\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Note: If DWPC is less than -190 degrees C, it is treated as\t\t*\nC* missing data.\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_RHDP ( TMPC, RELH )\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tTMPC\t\tREAL\t\tTemperature in Celsius\t\t*\nC*\tRELH\t\tREAL\t\tRelative humidity in percent\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_RHDP\t\tREAL\t\tDewpoint in Celsius\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* I. Graffman/RDS\t7/86\t\t\t\t\t\t*\nC* I. Graffman/RDS\t12/87\tGEMPAK4\t\t\t\t\t*\nC* M. desJardins/GSFC\t3/88\tFixed log of 0 problem\t\t\t*\nC* G. Huffman/GSC\t7/88\tDocumentation; refixed log of 0\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\nC*\tMissing values.\nC\n\tIF ( ERMISS ( tmpc ) .or. ERMISS ( relh ) ) THEN\n\t PR_RHDP = RMISSD\n\t ELSE\nC\nC*\t Calculate saturation vapor pressure; test for existence.\nC\n\t vaps = PR_VAPR ( tmpc )\n\t IF ( ERMISS ( vaps ) ) THEN\n\t\tPR_RHDP = RMISSD\n\t\tRETURN\n\t END IF\nC\nC*\t Calculate vapor pressure.\nC\n\t vapr = relh * vaps / 100.\nC\nC*\t Calculate dewpoint. The VAPR test prevents LOG blowups.\nC\n\t IF ( vapr .lt. 1.E-30 ) THEN\n\t PR_RHDP = RMISSD\n\t ELSE\n\t PR_RHDP = 243.5 * ( LOG (6.112) - LOG (vapr) ) /\n * (LOG (vapr) - LOG (6.112) - 17.67)\n\t END IF\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "65afefc3c9dcee5fa3cc9fc5fabf119f3d0bcd4c", "size": 1962, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prrhdp.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/prmcnvlib/pr/prrhdp.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/prmcnvlib/pr/prrhdp.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 29.7272727273, "max_line_length": 73, "alphanum_fraction": 0.4643221203, "num_tokens": 672, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966686936261, "lm_q2_score": 0.8056321819811829, "lm_q1q2_score": 0.7626087396557649}} {"text": "C$Procedure VLCOM ( Vector linear combination, 3 dimensions )\n \n SUBROUTINE VLCOM ( A, V1, B, V2, SUM )\n \nC$ Abstract\nC\nC Compute a vector linear combination of two double precision,\nC 3-dimensional vectors.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC VECTOR\nC\nC$ Declarations\n \n DOUBLE PRECISION A\n DOUBLE PRECISION V1 ( 3 )\n DOUBLE PRECISION B\n DOUBLE PRECISION V2 ( 3 )\n DOUBLE PRECISION SUM ( 3 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC A I Coefficient of V1\nC V1 I Vector in 3-space\nC B I Coefficient of V2\nC V2 I Vector in 3-space\nC SUM O Linear Vector Combination A*V1 + B*V2\nC\nC$ Detailed_Input\nC\nC A This double precision variable multiplies V1.\nC V1 This is an arbitrary, double precision 3-dimensional\nC vector.\nC B This double precision variable multiplies V2.\nC V2 This is an arbitrary, double precision 3-dimensional\nC vector.\nC\nC$ Detailed_Output\nC\nC SUM is an arbitrary, double precision 3-dimensional vector\nC which contains the linear combination A*V1 + B*V2.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Particulars\nC\nC For each index from 1 to 3, this routine implements in FORTRAN\nC code the expression:\nC\nC SUM(I) = A*V1(I) + B*V2(I)\nC\nC No error checking is performed to guard against numeric overflow.\nC\nC$ Examples\nC\nC To generate a sequence of points on an ellipse with major\nC and minor axis vectors MAJOR and MINOR, one could use the\nC following code fragment\nC\nC STEP = TWOPI()/ N\nC ANG = 0.0D0\nC\nC DO I = 0,N\nC\nC CALL VLCOM ( DCOS(ANG),MAJOR, DSIN(ANG),MINOR, POINT )\nC\nC do something with the ellipse point just constructed\nC\nC ANG = ANG + STEP\nC\nC END DO\nC\nC As a second example, suppose that U and V are orthonormal vectors\nC that form a basis of a plane. Moreover suppose that we wish to\nC project a vector X onto this plane, we could use the following\nC call inserts this projection into PROJ.\nC\nC CALL VLCOM ( VDOT(X,V),V, VDOT(X,U),U, PROJ )\nC\nC\nC$ Restrictions\nC\nC No error checking is performed to guard against numeric overflow\nC or underflow. The user is responsible for insuring that the\nC input values are reasonable.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC\nC$ Literature_References\nC\nC None\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WLT)\nC\nC-&\n \nC$ Index_Entries\nC\nC linear combination of two 3-dimensional vectors\nC\nC-&\n \n \nC$ Revisions\nC\nC- Beta Version 1.0.1, 1-Feb-1989 (WLT)\nC\nC Example section of header upgraded.\nC\nC-&\n \n \n SUM(1) = A*V1(1) + B*V2(1)\n SUM(2) = A*V1(2) + B*V2(2)\n SUM(3) = A*V1(3) + B*V2(3)\n \n RETURN\n END\n", "meta": {"hexsha": "df963b7c54aa12ce05693414fa08f00193059bee", "size": 4590, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/vlcom.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/vlcom.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/vlcom.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 27.0, "max_line_length": 72, "alphanum_fraction": 0.651416122, "num_tokens": 1362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240125464115, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7625703541304697}} {"text": "\tSUBROUTINE AXISPTS(XMIN,XMAX,BOT,TOP,NTIC)\nC\nC\t\t\t\t\t\t\t\tscale axis\n\tX = ALOG10(XMAX-XMIN)\n\tIF (X.GE.0.0) THEN\t\t\t\t! span between tic-marks\n\t DIV = 10.0**INT(X)\n\tELSE\n\t DIV = 10.0**INT(X-1.0)\n\tEND IF\n\tIF (XMIN.GE.0.0) THEN\t\t\t\t! lower limit of graph\n\t BOT = DIV*INT(XMIN/DIV)\n\tELSE\n\t BOT = DIV*INT((XMIN/DIV)-1.0)\n\tEND IF\n\tNTIC = 1+(XMAX-BOT)/DIV\t\t\t\t! # of tic-marks\n\tTOP = BOT+NTIC*DIV\t\t\t\t! upper limit of graph\nC\n\tIF (NTIC.LE.3) THEN\t\t\t\t! adjust # of tic-marks\n\t NTIC = 5*NTIC\n\t DIV = DIV/5.0\n\tEND IF\n\tIF (NTIC.LE.7) THEN\n\t NTIC = 2*NTIC\n\t DIV = DIV/2.0\n\tEND IF\n\tDO WHILE (XMIN .GE. BOT+0.999999*DIV)\n\t BOT = BOT+DIV\n\t NTIC = NTIC-1\n\tEND DO\n\tDO WHILE (XMAX .LE. TOP-0.999999*DIV)\n\t TOP = TOP-DIV\n\t NTIC = NTIC-1\n\tEND DO\n\tRETURN\n\tEND\n", "meta": {"hexsha": "628b8e3844a0101a3f4d0935ed989117a7768a21", "size": 767, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vos/p3/sub/axispts/axispts.f", "max_stars_repo_name": "NASA-AMMOS/VICAR", "max_stars_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-10-21T05:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T10:02:01.000Z", "max_issues_repo_path": "vos/p3/sub/axispts/axispts.f", "max_issues_repo_name": "NASA-AMMOS/VICAR", "max_issues_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vos/p3/sub/axispts/axispts.f", "max_forks_repo_name": "NASA-AMMOS/VICAR", "max_forks_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-09T01:51:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T00:23:24.000Z", "avg_line_length": 21.3055555556, "max_line_length": 48, "alphanum_fraction": 0.5801825293, "num_tokens": 342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763574, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.76257035128384}} {"text": " MODULE random_negative_binomial_mod\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n CONTAINS\n\n!*********************************************************************\n\n FUNCTION random_negative_binomial(n,p)\n! .. Use Statements ..\n USE random_standard_gamma_mod\n USE random_poisson_mod\n! ..\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n! .. Function Return Value ..\n INTEGER :: random_negative_binomial\n! ..\n! .. Scalar Arguments ..\n REAL, INTENT (IN) :: p\n INTEGER, INTENT (IN) :: n\n! ..\n! .. Local Scalars ..\n REAL :: a, r, y\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC REAL\n! ..\n! .. Executable Statements ..\n\n!**********************************************************************\n! INTEGER FUNCTION IGNNBN( N, P )\n! GENerate Negative BiNomial random deviate\n! Function\n! Generates a single random deviate from a negative binomial\n! distribution.\n! Arguments\n! N --> Required number of events.\n! INTEGER N\n! JJV (N > 0)\n! P --> The probability of an event during a Bernoulli trial.\n! REAL P\n! JJV (0.0 < P < 1.0)\n! Method\n! Algorithm from page 480 of\n! Devroye, Luc\n! Non-Uniform Random Variate Generation. Springer-Verlag,\n! New York, 1986.\n!**********************************************************************\n! JJV changed to call SGAMMA directly\n! REAL random_gamma\n! EXTERNAL random_gamma,random_poisson\n! Check Arguments\n! JJV changed argumnet checker to abort if N <= 0\n IF (n<=0) STOP 'N <= 0 in IGNNBN'\n IF (p<=0.0) STOP 'P <= 0.0 in IGNNBN'\n IF (p>=1.0) STOP 'P >= 1.0 in IGNNBN'\n\n! Generate Y, a random gamma (n,(1-p)/p) variable\n! JJV Note: the above parametrization is consistent with Devroye,\n! JJV but gamma (p/(1-p),n) is the equivalent in our code\n r = REAL(n)\n a = p/(1.0-p)\n! y = random_gamma(a,r)\n y = random_standard_gamma(r)/a\n\n! Generate a random Poisson(y) variable\n random_negative_binomial = random_poisson(y)\n RETURN\n\n END FUNCTION random_negative_binomial\n\n!*********************************************************************\n\n END MODULE random_negative_binomial_mod\n", "meta": {"hexsha": "1c73d8170ad0dbfca73b6bfc6877a6c320b2d26e", "size": 2448, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/random_negative_binomial_mod.f90", "max_stars_repo_name": "urbanjost/fpm_tools", "max_stars_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/random_negative_binomial_mod.f90", "max_issues_repo_name": "urbanjost/fpm_tools", "max_issues_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/random_negative_binomial_mod.f90", "max_forks_repo_name": "urbanjost/fpm_tools", "max_forks_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-14T11:36:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-14T11:36:01.000Z", "avg_line_length": 31.7922077922, "max_line_length": 71, "alphanum_fraction": 0.4934640523, "num_tokens": 574, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465134460243, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7625248686627383}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc file alf.f contains subroutines alfk,lfim,lfim1,lfin,lfin1,lfpt\nc for computing normalized associated legendre polynomials\nc\nc subroutine alfk (n,m,cp)\nc\nc dimension of real cp(n/2 + 1)\nc arguments\nc\nc purpose routine alfk computes single precision fourier\nc coefficients in the trigonometric series\nc representation of the normalized associated\nc legendre function pbar(n,m,theta) for use by\nc routines lfp and lfpt in calculating single\nc precision pbar(n,m,theta).\nc\nc first define the normalized associated\nc legendre functions\nc\nc pbar(m,n,theta) = sqrt((2*n+1)*factorial(n-m)\nc /(2*factorial(n+m)))*sin(theta)**m/(2**n*\nc factorial(n)) times the (n+m)th derivative of\nc (x**2-1)**n with respect to x=cos(theta)\nc\nc where theta is colatitude.\nc\nc then subroutine alfk computes the coefficients\nc cp(k) in the following trigonometric\nc expansion of pbar(m,n,theta).\nc\nc 1) for n even and m even, pbar(m,n,theta) =\nc .5*cp(1) plus the sum from k=1 to k=n/2\nc of cp(k+1)*cos(2*k*th)\nc\nc 2) for n even and m odd, pbar(m,n,theta) =\nc the sum from k=1 to k=n/2 of\nc cp(k)*sin(2*k*th)\nc\nc 3) for n odd and m even, pbar(m,n,theta) =\nc the sum from k=1 to k=(n+1)/2 of\nc cp(k)*cos((2*k-1)*th)\nc\nc 4) for n odd and m odd, pbar(m,n,theta) =\nc the sum from k=1 to k=(n+1)/2 of\nc cp(k)*sin((2*k-1)*th)\nc\nc\nc usage call alfk(n,m,cp)\nc\nc arguments\nc\nc on input n\nc nonnegative integer specifying the degree of\nc pbar(n,m,theta)\nc\nc m\nc is the order of pbar(n,m,theta). m can be\nc any integer however cp is computed such that\nc pbar(n,m,theta) = 0 if abs(m) is greater\nc than n and pbar(n,m,theta) = (-1)**m*\nc pbar(n,-m,theta) for negative m.\nc\nc on output cp\nc single precision array of length (n/2)+1\nc which contains the fourier coefficients in\nc the trigonometric series representation of\nc pbar(n,m,theta)\nc\nc\nc special conditions none\nc\nc precision single\nc\nc algorithm the highest order coefficient is determined in\nc closed form and the remainig coefficients are\nc determined as the solution of a backward\nc recurrence relation.\nc\nc accuracy comparison between routines alfk and double\nc precision dalfk on the cray1 indicates\nc greater accuracy for smaller values\nc of input parameter n. agreement to 14\nc places was obtained for n=10 and to 13\nc places for n=100.\nc\n subroutine alfk (n,m,cp)\n dimension cp(n/2+1)\n parameter (sc10=1024.)\n parameter (sc20=sc10*sc10)\n parameter (sc40=sc20*sc20)\nc\n cp(1) = 0.\n ma = iabs(m)\n if(ma .gt. n) return\n if(n-1) 2,3,5\n 2 cp(1) = sqrt(2.)\n return\n 3 if(ma .ne. 0) go to 4\n cp(1) = sqrt(1.5)\n return\n 4 cp(1) = sqrt(.75)\n if(m .eq. -1) cp(1) = -cp(1)\n return\n 5 if(mod(n+ma,2) .ne. 0) go to 10\n nmms2 = (n-ma)/2\n fnum = n+ma+1\n fnmh = n-ma+1\n pm1 = 1.\n go to 15\n 10 nmms2 = (n-ma-1)/2\n fnum = n+ma+2\n fnmh = n-ma+2\n pm1 = -1.\n 15 t1 = 1./sc20\n nex = 20\n fden = 2.\n if(nmms2 .lt. 1) go to 20\n do 18 i=1,nmms2\n t1 = fnum*t1/fden\n if(t1 .gt. sc20) then\n t1 = t1/sc40\n nex = nex+40\n end if\n fnum = fnum+2.\n fden = fden+2.\n 18 continue\n 20 t1 = t1/2.**(n-1-nex)\n if(mod(ma/2,2) .ne. 0) t1 = -t1\n t2 = 1. \n if(ma .eq. 0) go to 26\n do 25 i=1,ma\n t2 = fnmh*t2/(fnmh+pm1)\n fnmh = fnmh+2.\n 25 continue\n 26 cp2 = t1*sqrt((n+.5)*t2)\n fnnp1 = n*(n+1)\n fnmsq = fnnp1-2.*ma*ma\n l = (n+1)/2\n if(mod(n,2) .eq. 0 .and. mod(ma,2) .eq. 0) l = l+1\n cp(l) = cp2\n if(m .ge. 0) go to 29\n if(mod(ma,2) .ne. 0) cp(l) = -cp(l)\n 29 if(l .le. 1) return\n fk = n\n a1 = (fk-2.)*(fk-1.)-fnnp1\n b1 = 2.*(fk*fk-fnmsq)\n cp(l-1) = b1*cp(l)/a1\n 30 l = l-1\n if(l .le. 1) return\n fk = fk-2.\n a1 = (fk-2.)*(fk-1.)-fnnp1\n b1 = -2.*(fk*fk-fnmsq)\n c1 = (fk+1.)*(fk+2.)-fnnp1\n cp(l-1) = -(b1*cp(l)+c1*cp(l+1))/a1\n go to 30\n end\nc subroutine lfim (init,theta,l,n,nm,pb,id,wlfim)\nc\nc dimension of theta(l), pb(id,nm+1), wlfim(4*l*(nm+1))\nc arguments\nc\nc purpose given n and l, routine lfim calculates\nc the normalized associated legendre functions\nc pbar(n,m,theta) for m=0,...,n and theta(i)\nc for i=1,...,l where\nc\nc pbar(m,n,theta) = sqrt((2*n+1)*factorial(n-m)\nc /(2*factorial(n+m)))*sin(theta)**m/(2**n*\nc factorial(n)) times the (n+m)th derivative of\nc (x**2-1)**n with respect to x=cos(theta)\nc\nc usage call lfim (init,theta,l,n,nm,pb,id,wlfim)\nc\nc arguments\nc on input init\nc = 0\nc initialization only - using parameters\nc l, nm and array theta, subroutine lfim\nc initializes array wlfim for subsequent\nc use in the computation of the associated\nc legendre functions pb. initialization\nc does not have to be repeated unless\nc l, nm, or array theta are changed.\nc = 1\nc subroutine lfim uses the array wlfim that\nc was computed with init = 0 to compute pb.\nc\nc theta\nc an array that contains the colatitudes\nc at which the associated legendre functions\nc will be computed. the colatitudes must be\nc specified in radians.\nc\nc l\nc the length of the theta array. lfim is\nc vectorized with vector length l.\nc\nc n\nc nonnegative integer, less than nm, specifying\nc degree of pbar(n,m,theta). subroutine lfim\nc must be called starting with n=0. n must be\nc incremented by one in subsequent calls and\nc must not exceed nm.\nc\nc nm\nc the maximum value of n and m\nc\nc id\nc the first dimension of the two dimensional\nc array pb as it appears in the program that\nc calls lfim. (see output parameter pb)\nc\nc wlfim\nc an array with length 4*l*(nm+1) which\nc must be initialized by calling lfim\nc with init=0 (see parameter init) it\nc must not be altered between calls to\nc lfim.\nc\nc\nc on output pb\nc a two dimensional array with first\nc dimension id in the program that calls\nc lfim. the second dimension of pb must\nc be at least nm+1. starting with n=0\nc lfim is called repeatedly with n being\nc increased by one between calls. on each\nc call, subroutine lfim computes\nc = pbar(m,n,theta(i)) for m=0,...,n and\nc i=1,...l.\nc\nc wlfim\nc array containing values which must not\nc be altered unless l, nm or the array theta\nc are changed in which case lfim must be\nc called with init=0 to reinitialize the\nc wlfim array.\nc\nc special conditions n must be increased by one between calls\nc of lfim in which n is not zero.\nc\nc precision single\nc\nc\nc algorithm routine lfim calculates pbar(n,m,theta) using\nc a four term recurrence relation. (unpublished\nc notes by paul n. swarztrauber)\nc\n subroutine lfim (init,theta,l,n,nm,pb,id,wlfim)\n dimension pb(1) ,wlfim(1)\nc\nc total length of wlfim is 4*l*(nm+1)\nc\n lnx = l*(nm+1)\n iw1 = lnx+1\n iw2 = iw1+lnx\n iw3 = iw2+lnx\n call lfim1(init,theta,l,n,nm,id,pb,wlfim,wlfim(iw1),\n 1 wlfim(iw2),wlfim(iw3),wlfim(iw2))\n return\n end\n subroutine lfim1(init,theta,l,n,nm,id,p3,phz,ph1,p1,p2,cp)\n dimension p1(l,1) ,p2(l,1) ,p3(id,1) ,phz(l,1) ,\n 1 ph1(l,1) ,cp(1) ,theta(1)\n nmp1 = nm+1\n if(init .ne. 0) go to 5\n ssqrt2 = 1./sqrt(2.)\n do 10 i=1,l\n phz(i,1) = ssqrt2\n 10 continue\n do 15 np1=2,nmp1\n nh = np1-1\n call alfk(nh,0,cp)\n do 16 i=1,l\n call lfpt(nh,0,theta(i),cp,phz(i,np1))\n 16 continue\n call alfk(nh,1,cp)\n do 17 i=1,l\n call lfpt(nh,1,theta(i),cp,ph1(i,np1))\n 17 continue\n 15 continue\n return\n 5 if(n .gt. 2) go to 60\n if(n-1)25,30,35\n 25 do 45 i=1,l\n p3(i,1)=phz(i,1)\n 45 continue\n return\n 30 do 50 i=1,l\n p3(i,1) = phz(i,2)\n p3(i,2) = ph1(i,2)\n 50 continue\n return\n 35 sq5s6 = sqrt(5./6.)\n sq1s6 = sqrt(1./6.)\n do 55 i=1,l\n p3(i,1) = phz(i,3)\n p3(i,2) = ph1(i,3)\n p3(i,3) = sq5s6*phz(i,1)-sq1s6*p3(i,1)\n p1(i,1) = phz(i,2)\n p1(i,2) = ph1(i,2)\n p2(i,1) = phz(i,3)\n p2(i,2) = ph1(i,3)\n p2(i,3) = p3(i,3)\n 55 continue\n return\n 60 nm1 = n-1\n np1 = n+1\n fn = float(n)\n tn = fn+fn\n cn = (tn+1.)/(tn-3.)\n do 65 i=1,l\n p3(i,1) = phz(i,np1)\n p3(i,2) = ph1(i,np1)\n 65 continue\n if(nm1 .lt. 3) go to 71\n do 70 mp1=3,nm1\n m = mp1-1\n fm = float(m)\n fnpm = fn+fm\n fnmm = fn-fm\n temp = fnpm*(fnpm-1.)\n cc = sqrt(cn*(fnpm-3.)*(fnpm-2.)/temp)\n dd = sqrt(cn*fnmm*(fnmm-1.)/temp)\n ee = sqrt((fnmm+1.)*(fnmm+2.)/temp)\n do 70 i=1,l\n p3(i,mp1) = cc*p1(i,mp1-2)+dd*p1(i,mp1)-ee*p3(i,mp1-2)\n 70 continue\n 71 fnpm = fn+fn-1.\n temp = fnpm*(fnpm-1.)\n cc = sqrt(cn*(fnpm-3.)*(fnpm-2.)/temp)\n ee = sqrt(6./temp)\n do 75 i=1,l\n p3(i,n) = cc*p1(i,n-2)-ee*p3(i,n-2)\n 75 continue\n fnpm = fn+fn\n temp = fnpm*(fnpm-1.)\n cc = sqrt(cn*(fnpm-3.)*(fnpm-2.)/temp)\n ee = sqrt(2./temp)\n do 80 i=1,l\n p3(i,n+1) = cc*p1(i,n-1)-ee*p3(i,n-1)\n 80 continue\n do 90 mp1=1,np1\n do 90 i=1,l\n p1(i,mp1) = p2(i,mp1)\n p2(i,mp1) = p3(i,mp1)\n 90 continue\n return\n end\nc subroutine lfin (init,theta,l,m,nm,pb,id,wlfin)\nc\nc dimension of theta(l), pb(id,nm+1), wlfin(4*l*(nm+1))\nc arguments\nc\nc purpose given m and l, routine lfin calculates\nc the normalized associated legendre functions\nc pbar(n,m,theta) for n=m,...,nm and theta(i)\nc for i=1,...,l where\nc\nc pbar(m,n,theta) = sqrt((2*n+1)*factorial(n-m)\nc /(2*factorial(n+m)))*sin(theta)**m/(2**n*\nc factorial(n)) times the (n+m)th derivative of\nc (x**2-1)**n with respect to x=cos(theta)\nc\nc usage call lfin (init,theta,l,m,nm,pb,id,wlfin)\nc\nc arguments\nc on input init\nc = 0\nc initialization only - using parameters\nc l, nm and the array theta, subroutine lfin\nc initializes the array wlfin for subsequent\nc use in the computation of the associated\nc legendre functions pb. initialization does\nc not have to be repeated unless l, nm or\nc the array theta are changed.\nc = 1\nc subroutine lfin uses the array wlfin that\nc was computed with init = 0 to compute pb\nc\nc theta\nc an array that contains the colatitudes\nc at which the associated legendre functions\nc will be computed. the colatitudes must be\nc specified in radians.\nc\nc l\nc the length of the theta array. lfin is\nc vectorized with vector length l.\nc\nc m\nc nonnegative integer, less than nm, specifying\nc degree of pbar(n,m,theta). subroutine lfin\nc must be called starting with n=0. n must be\nc incremented by one in subsequent calls and\nc must not exceed nm.\nc\nc nm\nc the maximum value of n and m\nc\nc id\nc the first dimension of the two dimensional\nc array pb as it appears in the program that\nc calls lfin. (see output parameter pb)\nc\nc wlfin\nc an array with length 4*l*(nm+1) which\nc must be initialized by calling lfin\nc with init=0 (see parameter init) it\nc must not be altered between calls to\nc lfin.\nc\nc\nc on output pb\nc a two dimensional array with first\nc dimension id in the program that calls\nc lfin. the second dimension of pb must\nc be at least nm+1. starting with m=0\nc lfin is called repeatedly with m being\nc increased by one between calls. on each\nc call, subroutine lfin computes pb(i,n+1)\nc = pbar(m,n,theta(i)) for n=m,...,nm and\nc i=1,...l.\nc\nc wlfin\nc array containing values which must not\nc be altered unless l, nm or the array theta\nc are changed in which case lfin must be\nc called with init=0 to reinitialize the\nc wlfin array.\nc\nc special conditions m must be increased by one between calls\nc of lfin in which m is not zero.\nc\nc precision single\nc\nc algorithm routine lfin calculates pbar(n,m,theta) using\nc a four term recurrence relation. (unpublished\nc notes by paul n. swarztrauber)\nc\n subroutine lfin (init,theta,l,m,nm,pb,id,wlfin)\n dimension pb(1) ,wlfin(1)\nc\nc total length of wlfin is 4*l*(nm+1)\nc\n lnx = l*(nm+1)\n iw1 = lnx+1\n iw2 = iw1+lnx\n iw3 = iw2+lnx\n call lfin1(init,theta,l,m,nm,id,pb,wlfin,wlfin(iw1),\n 1 wlfin(iw2),wlfin(iw3),wlfin(iw2))\n return\n end\n subroutine lfin1(init,theta,l,m,nm,id,p3,phz,ph1,p1,p2,cp)\n dimension p1(l,1) ,p2(l,1) ,p3(id,1) ,phz(l,1) ,\n 1 ph1(l,1) ,cp(1) ,theta(1)\n nmp1 = nm+1\n if(init .ne. 0) go to 5\n ssqrt2 = 1./sqrt(2.)\n do 10 i=1,l\n phz(i,1) = ssqrt2\n 10 continue\n do 15 np1=2,nmp1\n nh = np1-1\n call alfk(nh,0,cp)\n do 16 i=1,l\n call lfpt(nh,0,theta(i),cp,phz(i,np1))\n 16 continue\n call alfk(nh,1,cp)\n do 17 i=1,l\n call lfpt(nh,1,theta(i),cp,ph1(i,np1))\n 17 continue\n 15 continue\n return\n 5 mp1 = m+1\n fm = float(m)\n tm = fm+fm\n if(m-1)25,30,35\n 25 do 45 np1=1,nmp1\n do 45 i=1,l\n p3(i,np1) = phz(i,np1)\n p1(i,np1) = phz(i,np1)\n 45 continue\n return\n 30 do 50 np1=2,nmp1\n do 50 i=1,l\n p3(i,np1) = ph1(i,np1)\n p2(i,np1) = ph1(i,np1)\n 50 continue\n return\n 35 temp = tm*(tm-1.)\n cc = sqrt((tm+1.)*(tm-2.)/temp)\n ee = sqrt(2./temp)\n do 85 i=1,l\n p3(i,m+1) = cc*p1(i,m-1)-ee*p1(i,m+1)\n 85 continue\n if(m .eq. nm) return\n temp = tm*(tm+1.)\n cc = sqrt((tm+3.)*(tm-2.)/temp)\n ee = sqrt(6./temp)\n do 70 i=1,l\n p3(i,m+2) = cc*p1(i,m)-ee*p1(i,m+2)\n 70 continue\n mp3 = m+3\n if(nmp1 .lt. mp3) go to 80\n do 75 np1=mp3,nmp1\n n = np1-1\n fn = float(n)\n tn = fn+fn\n cn = (tn+1.)/(tn-3.)\n fnpm = fn+fm\n fnmm = fn-fm\n temp = fnpm*(fnpm-1.)\n cc = sqrt(cn*(fnpm-3.)*(fnpm-2.)/temp)\n dd = sqrt(cn*fnmm*(fnmm-1.)/temp)\n ee = sqrt((fnmm+1.)*(fnmm+2.)/temp)\n do 75 i=1,l\n p3(i,np1) = cc*p1(i,np1-2)+dd*p3(i,np1-2)-ee*p1(i,np1)\n 75 continue\n 80 do 90 np1=m,nmp1\n do 90 i=1,l\n p1(i,np1) = p2(i,np1)\n p2(i,np1) = p3(i,np1)\n 90 continue\n return\n end\nc subroutine lfpt (n,m,theta,cp,pb)\nc\nc dimension of\nc arguments\nc cp((n/2)+1)\nc\nc purpose routine lfpt uses coefficients computed by\nc routine alfk to compute the single precision\nc normalized associated legendre function pbar(n,\nc m,theta) at colatitude theta.\nc\nc usage call lfpt(n,m,theta,cp,pb)\nc\nc arguments\nc\nc on input n\nc nonnegative integer specifying the degree of\nc pbar(n,m,theta)\nc m\nc is the order of pbar(n,m,theta). m can be\nc any integer however pbar(n,m,theta) = 0\nc if abs(m) is greater than n and\nc pbar(n,m,theta) = (-1)**m*pbar(n,-m,theta)\nc for negative m.\nc\nc theta\nc single precision colatitude in radians\nc\nc cp\nc single precision array of length (n/2)+1\nc containing coefficients computed by routine\nc alfk\nc\nc on output pb\nc single precision variable containing\nc pbar(n,m,theta)\nc\nc special conditions calls to routine lfpt must be preceded by an\nc appropriate call to routine alfk.\nc\nc precision single\nc\nc algorithm the trigonometric series formula used by\nc routine lfpt to calculate pbar(n,m,th) at\nc colatitude th depends on m and n as follows:\nc\nc 1) for n even and m even, the formula is\nc .5*cp(1) plus the sum from k=1 to k=n/2\nc of cp(k)*cos(2*k*th)\nc 2) for n even and m odd. the formula is\nc the sum from k=1 to k=n/2 of\nc cp(k)*sin(2*k*th)\nc 3) for n odd and m even, the formula is\nc the sum from k=1 to k=(n+1)/2 of\nc cp(k)*cos((2*k-1)*th)\nc 4) for n odd and m odd, the formula is\nc the sum from k=1 to k=(n+1)/2 of\nc cp(k)*sin((2*k-1)*th)\nc\nc accuracy comparison between routines lfpt and double\nc precision dlfpt on the cray1 indicates greater\nc accuracy for greater values on input parameter\nc n. agreement to 13 places was obtained for\nc n=10 and to 12 places for n=100.\nc\nc timing time per call to routine lfpt is dependent on\nc the input parameter n.\nc\n subroutine lfpt (n,m,theta,cp,pb)\n dimension cp(1)\nc\n pb = 0.\n ma = iabs(m)\n if(ma .gt. n) return\n if (n) 10, 10, 30\n 10 if (ma) 20, 20, 30\n 20 pb= sqrt(.5)\n go to 140\n 30 np1 = n+1\n nmod = mod(n,2)\n mmod = mod(ma,2)\n if (nmod) 40, 40, 90\n 40 if (mmod) 50, 50, 70\n 50 kdo = n/2+1\n cdt = cos(theta+theta)\n sdt = sin(theta+theta)\n ct = 1.\n st = 0.\n sum = .5*cp(1)\n do 60 kp1=2,kdo\n cth = cdt*ct-sdt*st\n st = sdt*ct+cdt*st\n ct = cth\n sum = sum+cp(kp1)*ct\n 60 continue\n pb= sum\n go to 140\n 70 kdo = n/2\n cdt = cos(theta+theta)\n sdt = sin(theta+theta)\n ct = 1.\n st = 0.\n sum = 0.\n do 80 k=1,kdo\n cth = cdt*ct-sdt*st\n st = sdt*ct+cdt*st\n ct = cth\n sum = sum+cp(k)*st\n 80 continue\n pb= sum\n go to 140\n 90 kdo = (n+1)/2\n if (mmod) 100,100,120\n 100 cdt = cos(theta+theta)\n sdt = sin(theta+theta)\n ct = cos(theta)\n st = -sin(theta)\n sum = 0.\n do 110 k=1,kdo\n cth = cdt*ct-sdt*st\n st = sdt*ct+cdt*st\n ct = cth\n sum = sum+cp(k)*ct\n 110 continue\n pb= sum\n go to 140\n 120 cdt = cos(theta+theta)\n sdt = sin(theta+theta)\n ct = cos(theta)\n st = -sin(theta)\n sum = 0.\n do 130 k=1,kdo\n cth = cdt*ct-sdt*st\n st = sdt*ct+cdt*st\n ct = cth\n sum = sum+cp(k)*st\n 130 continue\n pb= sum\n 140 return\n end\n", "meta": {"hexsha": "33acc7aa99fd0e02bd905774d9f3fef3b5488e22", "size": 23637, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/alf.f", "max_stars_repo_name": "jprules321/colas", "max_stars_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/alf.f", "max_issues_repo_name": "jprules321/colas", "max_issues_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/alf.f", "max_forks_repo_name": "jprules321/colas", "max_forks_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.6583577713, "max_line_length": 72, "alphanum_fraction": 0.4499725007, "num_tokens": 6889, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465134460243, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7625248602650504}} {"text": "\tFUNCTION PR_DWPT ( rmix, pres )\nC************************************************************************\nC* PR_DWPT\t\t\t\t\t\t\t\t*\nC* \t\t\t\t\t\t\t\t\t*\nC* This function computes DWPT from MIXR and PRES. The following\t*\nC* equation is used:\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* DWPT = ALOG (E / 6.112) * 243.5 / ( 17.67 - ALOG (E / 6.112) )\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* E = vapor pressure\t\t\t\t\t\t*\nC* = e / ( 1.001 + ( (PRES - 100.) / 900. ) * .0034 ) \t\t*\nC* e = ( PRES * MIXR ) / ( .62197 + MIXR ) \t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Bolton.\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function also computes TMPC from MIXS and PRES.\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_DWPT ( RMIX, PRES )\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tRMIX\t\tREAL\t\tMixing ratio in g/kg\t\t*\nC*\tPRES \t\tREAL \tPressure in millibars\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_DWPT\t\tREAL\t\tDewpoint in Celsius\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* P. Kocin/914\t\t1980\tOriginal source code\t\t\t*\nC* M. Goodman/RDS \t8/84\tCleaned code\t\t\t\t*\nC* G.Huffman/GSC\t7/88\tConstant .62197, p .le. 0\t\t*\nC* J. Nielsen/SUNYA\t8/90\tAssume mixing ratio is in g/kg\t\t*\nC* T. Piper/GSC\t\t11/98\tUpdated prolog\t\t\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tIF ( ERMISS ( rmix ) .or. ( rmix .le. 0. ) .or. \n +\t ERMISS ( pres ) .or. ( pres .le. 0. ) ) THEN\t\n\t PR_DWPT = RMISSD\n\t ELSE\nC\nC*\t Convert G/KG to G/G.\nC\n\t ratio = rmix / 1000.\nC\nC*\t Calculate vapor pressure from mixing ratio and pressure.\nC\n\t e = (pres * ratio) / (.62197 + ratio)\nC\nC*\t Correct vapor pressure.\nC\n\t e = e / (1.001 + ((pres - 100.) / 900.) * .0034)\nC\nC*\t Calculate dewpoint.\nC\n\t PR_DWPT = ALOG (e/6.112) * 243.5 / (17.67 - ALOG(e/6.112))\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "9d14bba437a098a48150e043c4839a3917795439", "size": 1865, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prdwpt.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/prmcnvlib/pr/prdwpt.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/prmcnvlib/pr/prdwpt.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 30.5737704918, "max_line_length": 73, "alphanum_fraction": 0.4557640751, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191297273499, "lm_q2_score": 0.7981867729389245, "lm_q1q2_score": 0.7625230932838951}} {"text": "\nSUBROUTINE WEIGHT(PTS, PT, WTS)\n USE ISO_FORTRAN_ENV, ONLY: REAL64\n ! Inputs and outputs\n REAL(KIND=REAL64), INTENT(IN), DIMENSION(:,:) :: PTS\n REAL(KIND=REAL64), INTENT(IN), DIMENSION(SIZE(PTS,1)) :: PT\n REAL(KIND=REAL64), INTENT(OUT), DIMENSION(SIZE(PTS,2)) :: WTS\n ! Local variables\n REAL(KIND=REAL64), DIMENSION(SIZE(WTS)) :: DISTS\n REAL(KIND=REAL64) :: MAX_DIST, MIN_DIST, EPS\n INTEGER :: I\n !$omp parallel do\n DO I = 1, SIZE(PTS, 2)\n DISTS(I) = NORM2(PTS(:,I) - PT(:))\n END DO\n ! Compute the epsilon (for checking \"zero\" values).\n EPS = SQRT(EPSILON(WTS(1)))\n ! Compute the maximum and minimum distance to points.\n MIN_DIST = MINVAL(DISTS)\n MAX_DIST = MAXVAL(DISTS)\n ! Make sure that the maximum distance is positive.\n IF (MAX_DIST .LT. EPS) THEN\n ! Set all weights to be equal.\n WTS(:) = 1._REAL64\n ELSE IF (MIN_DIST .LT. EPS) THEN\n ! Share the weights equally across those close values.\n WTS(:) = 0._REAL64\n WHERE (DISTS .LT. EPS) WTS = 1._REAL64\n ELSE\n ! Compute the weights based on inverse distances.\n WTS(:) = 1._REAL64 / DISTS(:)**2\n END IF\n ! Convexify the weights.\n WTS = WTS / SUM(WTS)\nEND SUBROUTINE WEIGHT\n", "meta": {"hexsha": "7733d7433bc697927c62d0fbc08db6b1a3bde5df", "size": 1181, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "util/approximate/shepard/weight.f90", "max_stars_repo_name": "tchlux/util", "max_stars_repo_head_hexsha": "eff37464c7e913377398025adf76b057f9630b35", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-04-22T20:19:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-30T18:57:23.000Z", "max_issues_repo_path": "util/approximate/shepard/weight.f90", "max_issues_repo_name": "tchlux/util", "max_issues_repo_head_hexsha": "eff37464c7e913377398025adf76b057f9630b35", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-24T14:10:27.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-30T16:42:53.000Z", "max_forks_repo_path": "util/approximate/shepard/weight.f90", "max_forks_repo_name": "tchlux/util", "max_forks_repo_head_hexsha": "eff37464c7e913377398025adf76b057f9630b35", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-05-19T07:44:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-22T20:20:40.000Z", "avg_line_length": 32.8055555556, "max_line_length": 63, "alphanum_fraction": 0.6536833192, "num_tokens": 402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026663679977, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7624097358520069}} {"text": "recursive subroutine factorial(i,f)\n implicit none\n integer f,i,j\n intent(in) i\n intent(out) f\n if (i.le.0) then\n stop 'argument must be > 0'\n else if (i.eq.1) then\n f=i\n else\n call factorial(i-1,j)\n f=i*j\n end if\nend subroutine factorial\n", "meta": {"hexsha": "151e2bafb070831a8d0963be986e4ee0a0dbab19", "size": 259, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/t0216r/include/factorial.f90", "max_stars_repo_name": "maddenp/ppp", "max_stars_repo_head_hexsha": "81956c0fc66ff742531817ac9028c4df940cc13e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-08-13T16:32:02.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-21T12:37:58.000Z", "max_issues_repo_path": "tests/t0216r/include/factorial.f90", "max_issues_repo_name": "maddenp/ppp", "max_issues_repo_head_hexsha": "81956c0fc66ff742531817ac9028c4df940cc13e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/t0216r/include/factorial.f90", "max_forks_repo_name": "maddenp/ppp", "max_forks_repo_head_hexsha": "81956c0fc66ff742531817ac9028c4df940cc13e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2015-07-30T17:02:27.000Z", "max_forks_repo_forks_event_max_datetime": "2015-08-03T16:29:41.000Z", "avg_line_length": 17.2666666667, "max_line_length": 35, "alphanum_fraction": 0.6409266409, "num_tokens": 87, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7624094660965037}} {"text": "\nsubmodule(forlab) forlab_inv\n use forlab_kinds\n\ncontains\n module procedure inv_rsp\n !! inv0 computes the real matrix inverse.\n integer :: i, j, k, m\n real(sp) :: D\n real(sp), dimension(:), allocatable :: x, y, e\n real(sp), dimension(:, :), allocatable :: L, U\n real(sp) :: flag\n if (issquare(A)) then\n m = size(A, 1)\n if (m .le. 3) then\n D = det(A)\n else\n D = det(A, L, U)\n end if\n if (D .ne. 0.) then\n inv_rsp = zeros(m, m, flag)\n if (m .eq. 2) then\n inv_rsp (1, 1) = A(2, 2)\n inv_rsp (1, 2) = -A(1, 2)\n inv_rsp (2, 1) = -A(2, 1)\n inv_rsp (2, 2) = A(1, 1)\n inv_rsp = inv_rsp/D\n elseif (m .eq. 3) then\n inv_rsp (1, 1) = A(2, 2)*A(3, 3) - A(2, 3)*A(3, 2)\n inv_rsp (1, 2) = A(1, 3)*A(3, 2) - A(1, 2)*A(3, 3)\n inv_rsp (1, 3) = A(1, 2)*A(2, 3) - A(1, 3)*A(2, 2)\n inv_rsp (2, 1) = A(2, 3)*A(3, 1) - A(2, 1)*A(3, 3)\n inv_rsp (2, 2) = A(1, 1)*A(3, 3) - A(1, 3)*A(3, 1)\n inv_rsp (2, 3) = A(1, 3)*A(2, 1) - A(1, 1)*A(2, 3)\n inv_rsp (3, 1) = A(2, 1)*A(3, 2) - A(2, 2)*A(3, 1)\n inv_rsp (3, 2) = A(1, 2)*A(3, 1) - A(1, 1)*A(3, 2)\n inv_rsp (3, 3) = A(1, 1)*A(2, 2) - A(1, 2)*A(2, 1)\n inv_rsp = inv_rsp/D\n else\n do k = 1, m\n x = zeros(m, flag)\n y = zeros(m, flag)\n e = zeros(m, flag)\n e(k) = 1.\n y(1) = e(1)\n\n ! Forward substitution: Ly = e\n !==============================\n do i = 2, m\n y(i) = e(i)\n do j = 1, i - 1\n y(i) = y(i) - y(j)*L(i, j)\n end do\n end do\n\n ! Back substitution: Ux = y\n !===========================\n x(m) = y(m)/U(m, m)\n do i = m - 1, 1, -1\n x(i) = y(i)\n do j = m, i + 1, -1\n x(i) = x(i) - x(j)*U(i, j)\n end do\n x(i) = x(i)/U(i, i)\n end do\n\n ! The column k of the inverse is x\n !==================================\n inv_rsp (:, k) = x\n end do\n end if\n else\n stop \"Error: in det(A), A is not inversible (= 0).\"\n end if\n else\n stop \"Error: in inv(A), A should be square.\"\n end if\n return\n end procedure\n\n module procedure inv_rdp\n !! inv0 computes the real matrix inverse.\n integer :: i, j, k, m\n real(dp) :: D\n real(dp), dimension(:), allocatable :: x, y, e\n real(dp), dimension(:, :), allocatable :: L, U\n real(dp) :: flag\n if (issquare(A)) then\n m = size(A, 1)\n if (m .le. 3) then\n D = det(A)\n else\n D = det(A, L, U)\n end if\n if (D .ne. 0.) then\n inv_rdp = zeros(m, m, flag)\n if (m .eq. 2) then\n inv_rdp (1, 1) = A(2, 2)\n inv_rdp (1, 2) = -A(1, 2)\n inv_rdp (2, 1) = -A(2, 1)\n inv_rdp (2, 2) = A(1, 1)\n inv_rdp = inv_rdp/D\n elseif (m .eq. 3) then\n inv_rdp (1, 1) = A(2, 2)*A(3, 3) - A(2, 3)*A(3, 2)\n inv_rdp (1, 2) = A(1, 3)*A(3, 2) - A(1, 2)*A(3, 3)\n inv_rdp (1, 3) = A(1, 2)*A(2, 3) - A(1, 3)*A(2, 2)\n inv_rdp (2, 1) = A(2, 3)*A(3, 1) - A(2, 1)*A(3, 3)\n inv_rdp (2, 2) = A(1, 1)*A(3, 3) - A(1, 3)*A(3, 1)\n inv_rdp (2, 3) = A(1, 3)*A(2, 1) - A(1, 1)*A(2, 3)\n inv_rdp (3, 1) = A(2, 1)*A(3, 2) - A(2, 2)*A(3, 1)\n inv_rdp (3, 2) = A(1, 2)*A(3, 1) - A(1, 1)*A(3, 2)\n inv_rdp (3, 3) = A(1, 1)*A(2, 2) - A(1, 2)*A(2, 1)\n inv_rdp = inv_rdp/D\n else\n do k = 1, m\n x = zeros(m, flag)\n y = zeros(m, flag)\n e = zeros(m, flag)\n e(k) = 1.\n y(1) = e(1)\n\n ! Forward substitution: Ly = e\n !==============================\n do i = 2, m\n y(i) = e(i)\n do j = 1, i - 1\n y(i) = y(i) - y(j)*L(i, j)\n end do\n end do\n\n ! Back substitution: Ux = y\n !===========================\n x(m) = y(m)/U(m, m)\n do i = m - 1, 1, -1\n x(i) = y(i)\n do j = m, i + 1, -1\n x(i) = x(i) - x(j)*U(i, j)\n end do\n x(i) = x(i)/U(i, i)\n end do\n\n ! The column k of the inverse is x\n !==================================\n inv_rdp (:, k) = x\n end do\n end if\n else\n stop \"Error: in det(A), A is not inversible (= 0).\"\n end if\n else\n stop \"Error: in inv(A), A should be square.\"\n end if\n return\n end procedure\n\n module procedure inv_rqp\n !! inv0 computes the real matrix inverse.\n integer :: i, j, k, m\n real(qp) :: D\n real(qp), dimension(:), allocatable :: x, y, e\n real(qp), dimension(:, :), allocatable :: L, U\n real(qp) :: flag\n if (issquare(A)) then\n m = size(A, 1)\n if (m .le. 3) then\n D = det(A)\n else\n D = det(A, L, U)\n end if\n if (D .ne. 0.) then\n inv_rqp = zeros(m, m, flag)\n if (m .eq. 2) then\n inv_rqp (1, 1) = A(2, 2)\n inv_rqp (1, 2) = -A(1, 2)\n inv_rqp (2, 1) = -A(2, 1)\n inv_rqp (2, 2) = A(1, 1)\n inv_rqp = inv_rqp/D\n elseif (m .eq. 3) then\n inv_rqp (1, 1) = A(2, 2)*A(3, 3) - A(2, 3)*A(3, 2)\n inv_rqp (1, 2) = A(1, 3)*A(3, 2) - A(1, 2)*A(3, 3)\n inv_rqp (1, 3) = A(1, 2)*A(2, 3) - A(1, 3)*A(2, 2)\n inv_rqp (2, 1) = A(2, 3)*A(3, 1) - A(2, 1)*A(3, 3)\n inv_rqp (2, 2) = A(1, 1)*A(3, 3) - A(1, 3)*A(3, 1)\n inv_rqp (2, 3) = A(1, 3)*A(2, 1) - A(1, 1)*A(2, 3)\n inv_rqp (3, 1) = A(2, 1)*A(3, 2) - A(2, 2)*A(3, 1)\n inv_rqp (3, 2) = A(1, 2)*A(3, 1) - A(1, 1)*A(3, 2)\n inv_rqp (3, 3) = A(1, 1)*A(2, 2) - A(1, 2)*A(2, 1)\n inv_rqp = inv_rqp/D\n else\n do k = 1, m\n x = zeros(m, flag)\n y = zeros(m, flag)\n e = zeros(m, flag)\n e(k) = 1.\n y(1) = e(1)\n\n ! Forward substitution: Ly = e\n !==============================\n do i = 2, m\n y(i) = e(i)\n do j = 1, i - 1\n y(i) = y(i) - y(j)*L(i, j)\n end do\n end do\n\n ! Back substitution: Ux = y\n !===========================\n x(m) = y(m)/U(m, m)\n do i = m - 1, 1, -1\n x(i) = y(i)\n do j = m, i + 1, -1\n x(i) = x(i) - x(j)*U(i, j)\n end do\n x(i) = x(i)/U(i, i)\n end do\n\n ! The column k of the inverse is x\n !==================================\n inv_rqp (:, k) = x\n end do\n end if\n else\n stop \"Error: in det(A), A is not inversible (= 0).\"\n end if\n else\n stop \"Error: in inv(A), A should be square.\"\n end if\n return\n end procedure\n\n\n\n module procedure inv_csp\n !! inv computes the complex matrix inverse.\n real(sp), dimension(:, :), allocatable :: ar, ai\n !! AR stores the real part, AI stores the imaginary part\n integer :: flag, n\n real(sp) :: d, p, t, q, s, b\n integer, dimension(:), allocatable :: is, js\n integer :: i, j, k\n real(sp) :: flag\n\n if (issquare(A)) then\n n = size(A, 1)\n inv_csp = zeros(n, n, flag)\n ar = zeros(n, n, flag)\n ai = zeros(n, n, flag)\n allocate(is(n),js(n))\n is = 0\n js = 0\n forall (i=1:n, j=1:n)\n ar(i, j) = real(A(i, j)); ai(i, j) = imag(A(i, j))\n end forall\n flag = 1\n do k = 1, n\n d = 0.0\n do i = k, n\n do j = k, n\n p = ar(i, j)*ar(i, j) + ai(i, j)*ai(i, j)\n if (p .gt. d) then\n d = p\n is(k) = i\n js(k) = j\n end if\n end do\n end do\n if (d + 1.0 .eq. 1.0) then\n flag = 0\n stop 'ERROR: A is not inversible (= 0)'\n end if\n do j = 1, n\n t = ar(k, j)\n ar(k, j) = ar(is(k), j)\n ar(is(k), j) = t\n t = ai(k, j)\n ai(k, j) = ai(is(k), j)\n ai(is(k), j) = t\n end do\n do i = 1, n\n t = ar(i, k)\n ar(i, k) = ar(i, js(k))\n ar(i, js(k)) = t\n t = ai(i, k)\n ai(i, k) = ai(i, js(k))\n ai(i, js(k)) = t\n end do\n ar(k, k) = ar(k, k)/d\n ai(k, k) = -ai(k, k)/d\n do j = 1, n\n if (j .ne. k) then\n p = ar(k, j)*ar(k, k)\n q = ai(k, j)*ai(k, k)\n s = (ar(k, j) + ai(k, j))*(ar(k, k) + ai(k, k))\n ar(k, j) = p - q\n ai(k, j) = s - p - q\n end if\n end do\n do i = 1, n\n if (i .ne. k) then\n do j = 1, n\n if (j .ne. k) then\n p = ar(k, j)*ar(i, k)\n q = ai(k, j)*ai(i, k)\n s = (ar(k, j) + ai(k, j))*(ar(i, k) + ai(i, k))\n t = p - q\n b = s - p - q\n ar(i, j) = ar(i, j) - t\n ai(i, j) = ai(i, j) - b\n end if\n end do\n end if\n end do\n do i = 1, n\n if (i .ne. k) then\n p = ar(i, k)*ar(k, k)\n q = ai(i, k)*ai(k, k)\n s = (ar(i, k) + ai(i, k))*(ar(k, k) + ai(k, k))\n ar(i, k) = q - p\n ai(i, k) = p + q - s\n end if\n end do\n end do\n do k = n, 1, -1\n do j = 1, n\n t = ar(k, j)\n ar(k, j) = ar(js(k), j)\n ar(js(k), j) = t\n t = ai(k, j)\n ai(k, j) = ai(js(k), j)\n ai(js(k), j) = t\n end do\n do i = 1, n\n t = ar(i, k)\n ar(i, k) = ar(i, is(k))\n ar(i, is(k)) = t\n t = ai(i, k)\n ai(i, k) = ai(i, is(k))\n ai(i, is(k)) = t\n end do\n end do\n forall (i=1:n, j=1:n)\n inv_csp (i, j) = dcmplx(ar(i, j), ai(i, j))\n end forall\n else\n stop 'Error: in inv(A), A should be square.'\n end if\n return\n end procedure\n\n module procedure inv_cdp\n !! inv computes the complex matrix inverse.\n real(dp), dimension(:, :), allocatable :: ar, ai\n !! AR stores the real part, AI stores the imaginary part\n integer :: flag, n\n real(dp) :: d, p, t, q, s, b\n integer, dimension(:), allocatable :: is, js\n integer :: i, j, k\n real(dp) :: flag\n\n if (issquare(A)) then\n n = size(A, 1)\n inv_cdp = zeros(n, n, flag)\n ar = zeros(n, n, flag)\n ai = zeros(n, n, flag)\n allocate(is(n),js(n))\n is = 0\n js = 0\n forall (i=1:n, j=1:n)\n ar(i, j) = real(A(i, j)); ai(i, j) = imag(A(i, j))\n end forall\n flag = 1\n do k = 1, n\n d = 0.0\n do i = k, n\n do j = k, n\n p = ar(i, j)*ar(i, j) + ai(i, j)*ai(i, j)\n if (p .gt. d) then\n d = p\n is(k) = i\n js(k) = j\n end if\n end do\n end do\n if (d + 1.0 .eq. 1.0) then\n flag = 0\n stop 'ERROR: A is not inversible (= 0)'\n end if\n do j = 1, n\n t = ar(k, j)\n ar(k, j) = ar(is(k), j)\n ar(is(k), j) = t\n t = ai(k, j)\n ai(k, j) = ai(is(k), j)\n ai(is(k), j) = t\n end do\n do i = 1, n\n t = ar(i, k)\n ar(i, k) = ar(i, js(k))\n ar(i, js(k)) = t\n t = ai(i, k)\n ai(i, k) = ai(i, js(k))\n ai(i, js(k)) = t\n end do\n ar(k, k) = ar(k, k)/d\n ai(k, k) = -ai(k, k)/d\n do j = 1, n\n if (j .ne. k) then\n p = ar(k, j)*ar(k, k)\n q = ai(k, j)*ai(k, k)\n s = (ar(k, j) + ai(k, j))*(ar(k, k) + ai(k, k))\n ar(k, j) = p - q\n ai(k, j) = s - p - q\n end if\n end do\n do i = 1, n\n if (i .ne. k) then\n do j = 1, n\n if (j .ne. k) then\n p = ar(k, j)*ar(i, k)\n q = ai(k, j)*ai(i, k)\n s = (ar(k, j) + ai(k, j))*(ar(i, k) + ai(i, k))\n t = p - q\n b = s - p - q\n ar(i, j) = ar(i, j) - t\n ai(i, j) = ai(i, j) - b\n end if\n end do\n end if\n end do\n do i = 1, n\n if (i .ne. k) then\n p = ar(i, k)*ar(k, k)\n q = ai(i, k)*ai(k, k)\n s = (ar(i, k) + ai(i, k))*(ar(k, k) + ai(k, k))\n ar(i, k) = q - p\n ai(i, k) = p + q - s\n end if\n end do\n end do\n do k = n, 1, -1\n do j = 1, n\n t = ar(k, j)\n ar(k, j) = ar(js(k), j)\n ar(js(k), j) = t\n t = ai(k, j)\n ai(k, j) = ai(js(k), j)\n ai(js(k), j) = t\n end do\n do i = 1, n\n t = ar(i, k)\n ar(i, k) = ar(i, is(k))\n ar(i, is(k)) = t\n t = ai(i, k)\n ai(i, k) = ai(i, is(k))\n ai(i, is(k)) = t\n end do\n end do\n forall (i=1:n, j=1:n)\n inv_cdp (i, j) = dcmplx(ar(i, j), ai(i, j))\n end forall\n else\n stop 'Error: in inv(A), A should be square.'\n end if\n return\n end procedure\n\n module procedure inv_cqp\n !! inv computes the complex matrix inverse.\n real(qp), dimension(:, :), allocatable :: ar, ai\n !! AR stores the real part, AI stores the imaginary part\n integer :: flag, n\n real(qp) :: d, p, t, q, s, b\n integer, dimension(:), allocatable :: is, js\n integer :: i, j, k\n real(qp) :: flag\n\n if (issquare(A)) then\n n = size(A, 1)\n inv_cqp = zeros(n, n, flag)\n ar = zeros(n, n, flag)\n ai = zeros(n, n, flag)\n allocate(is(n),js(n))\n is = 0\n js = 0\n forall (i=1:n, j=1:n)\n ar(i, j) = real(A(i, j)); ai(i, j) = imag(A(i, j))\n end forall\n flag = 1\n do k = 1, n\n d = 0.0\n do i = k, n\n do j = k, n\n p = ar(i, j)*ar(i, j) + ai(i, j)*ai(i, j)\n if (p .gt. d) then\n d = p\n is(k) = i\n js(k) = j\n end if\n end do\n end do\n if (d + 1.0 .eq. 1.0) then\n flag = 0\n stop 'ERROR: A is not inversible (= 0)'\n end if\n do j = 1, n\n t = ar(k, j)\n ar(k, j) = ar(is(k), j)\n ar(is(k), j) = t\n t = ai(k, j)\n ai(k, j) = ai(is(k), j)\n ai(is(k), j) = t\n end do\n do i = 1, n\n t = ar(i, k)\n ar(i, k) = ar(i, js(k))\n ar(i, js(k)) = t\n t = ai(i, k)\n ai(i, k) = ai(i, js(k))\n ai(i, js(k)) = t\n end do\n ar(k, k) = ar(k, k)/d\n ai(k, k) = -ai(k, k)/d\n do j = 1, n\n if (j .ne. k) then\n p = ar(k, j)*ar(k, k)\n q = ai(k, j)*ai(k, k)\n s = (ar(k, j) + ai(k, j))*(ar(k, k) + ai(k, k))\n ar(k, j) = p - q\n ai(k, j) = s - p - q\n end if\n end do\n do i = 1, n\n if (i .ne. k) then\n do j = 1, n\n if (j .ne. k) then\n p = ar(k, j)*ar(i, k)\n q = ai(k, j)*ai(i, k)\n s = (ar(k, j) + ai(k, j))*(ar(i, k) + ai(i, k))\n t = p - q\n b = s - p - q\n ar(i, j) = ar(i, j) - t\n ai(i, j) = ai(i, j) - b\n end if\n end do\n end if\n end do\n do i = 1, n\n if (i .ne. k) then\n p = ar(i, k)*ar(k, k)\n q = ai(i, k)*ai(k, k)\n s = (ar(i, k) + ai(i, k))*(ar(k, k) + ai(k, k))\n ar(i, k) = q - p\n ai(i, k) = p + q - s\n end if\n end do\n end do\n do k = n, 1, -1\n do j = 1, n\n t = ar(k, j)\n ar(k, j) = ar(js(k), j)\n ar(js(k), j) = t\n t = ai(k, j)\n ai(k, j) = ai(js(k), j)\n ai(js(k), j) = t\n end do\n do i = 1, n\n t = ar(i, k)\n ar(i, k) = ar(i, is(k))\n ar(i, is(k)) = t\n t = ai(i, k)\n ai(i, k) = ai(i, is(k))\n ai(i, is(k)) = t\n end do\n end do\n forall (i=1:n, j=1:n)\n inv_cqp (i, j) = dcmplx(ar(i, j), ai(i, j))\n end forall\n else\n stop 'Error: in inv(A), A should be square.'\n end if\n return\n end procedure\nend submodule\n", "meta": {"hexsha": "35d316fd83e602a7bd40da9c1f97fcd73bb1b1e3", "size": 23884, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_inv.f90", "max_stars_repo_name": "Euler-37/forlab", "max_stars_repo_head_hexsha": "070c96a20ac4d3d41c41cbf4b9a198284c5cea50", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-05T14:04:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-05T14:04:50.000Z", "max_issues_repo_path": "src/forlab_inv.f90", "max_issues_repo_name": "Euler-37/forlab", "max_issues_repo_head_hexsha": "070c96a20ac4d3d41c41cbf4b9a198284c5cea50", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/forlab_inv.f90", "max_forks_repo_name": "Euler-37/forlab", "max_forks_repo_head_hexsha": "070c96a20ac4d3d41c41cbf4b9a198284c5cea50", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.897260274, "max_line_length": 83, "alphanum_fraction": 0.2401607771, "num_tokens": 6237, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533163686645, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7623500358498084}} {"text": "Program Main\n !====================================================================\n ! eigenvalues and eigenvectors of a real symmetric matrix\n ! Method: calls Jacobi\n !====================================================================\n implicit none\n integer, parameter :: n=3\n double precision :: a(n,n), x(n,n)\n double precision, parameter:: abserr=1.0e-09\n integer i, j\n \n ! matrix A\n data (a(1,i), i=1,3) / 2.0, -1.0, 0.0 /\n data (a(2,i), i=1,3) / -1.0, 2.0, -1.0 /\n data (a(3,i), i=1,3) / 0.0, -1.0, 2.0 /\n \n ! print a header and the original matrix\n write (*,200)\n do i=1,n\n write (*,201) (a(i,j),j=1,n)\n end do\n \n call Jacobi(a,x,abserr,n)\n \n ! print solutions\n write (*,202)\n write (*,201) (a(i,i),i=1,n)\n write (*,203)\n do i = 1,n\n write (*,201) (x(i,j),j=1,n)\n end do\n \n 200 format (' Eigenvalues and eigenvectors (Jacobi method) ',/, &\n ' Matrix A')\n 201 format (6f12.6)\n 202 format (/,' Eigenvalues')\n 203 format (/,' Eigenvectors')\nend program main\n \nsubroutine Jacobi(a,x,abserr,n)\n !===========================================================\n ! Evaluate eigenvalues and eigenvectors\n ! of a real symmetric matrix a(n,n): a*x = lambda*x \n ! method: Jacobi method for symmetric matrices \n ! Alex G. (December 2009)\n !-----------------------------------------------------------\n ! input ...\n ! a(n,n) - array of coefficients for matrix A\n ! n - number of equations\n ! abserr - abs tolerance [sum of (off-diagonal elements)^2]\n ! output ...\n ! a(i,i) - eigenvalues\n ! x(i,j) - eigenvectors\n ! comments ...\n !===========================================================\n implicit none\n integer i, j, k, n\n double precision a(n,n),x(n,n)\n double precision abserr, b2, bar\n double precision beta, coeff, c, s, cs, sc\n \n ! initialize x(i,j)=0, x(i,i)=1\n ! *** the array operation x=0.0 is specific for Fortran 90/95\n x = 0.0\n do i=1,n\n x(i,i) = 1.0\n end do\n \n ! find the sum of all off-diagonal elements (squared)\n b2 = 0.0\n do i=1,n\n do j=1,n\n if (i.ne.j) b2 = b2 + a(i,j)**2\n end do\n end do\n \n if (b2 <= abserr) return\n \n ! average for off-diagonal elements /2\n bar = 0.5*b2/float(n*n)\n \n do while (b2.gt.abserr)\n do i=1,n-1\n do j=i+1,n\n if (a(j,i)**2 <= bar) cycle ! do not touch small elements\n b2 = b2 - 2.0*a(j,i)**2\n bar = 0.5*b2/float(n*n)\n ! calculate coefficient c and s for Givens matrix\n beta = (a(j,j)-a(i,i))/(2.0*a(j,i))\n coeff = 0.5*beta/sqrt(1.0+beta**2)\n s = sqrt(max(0.5+coeff,0.0))\n c = sqrt(max(0.5-coeff,0.0))\n ! recalculate rows i and j\n do k=1,n\n cs = c*a(i,k)+s*a(j,k)\n sc = -s*a(i,k)+c*a(j,k)\n a(i,k) = cs\n a(j,k) = sc\n end do\n ! new matrix a_{k+1} from a_{k}, and eigenvectors \n do k=1,n\n cs = c*a(k,i)+s*a(k,j)\n sc = -s*a(k,i)+c*a(k,j)\n a(k,i) = cs\n a(k,j) = sc\n cs = c*x(k,i)+s*x(k,j)\n sc = -s*x(k,i)+c*x(k,j)\n x(k,i) = cs\n x(k,j) = sc\n end do\n end do\n end do\n end do\n return\nend", "meta": {"hexsha": "02970445b3548851fe93ecc3e2075b219d44b538", "size": 3398, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Numerical Differentiation and Jacobi Method of Diagonalization/Find Eigenvalue, Diagonalize.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Numerical Differentiation and Jacobi Method of Diagonalization/Find Eigenvalue, Diagonalize.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Numerical Differentiation and Jacobi Method of Diagonalization/Find Eigenvalue, Diagonalize.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 29.547826087, "max_line_length": 73, "alphanum_fraction": 0.4408475574, "num_tokens": 1084, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145179, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.762350032780514}} {"text": "-- Empty, the type with no constructors\ndata Empty : Type\n\n-- Unit, the type with one constructor\ndata Unit : Type\n| void : Unit\n\n-- Bool, the type with two constructors\ndata Bool : Type\n| true : Bool\n| false : Bool\n\n-- Natural numbers\ndata Nat : Type\n| succ : (n : Nat) -> Nat\n| zero : Nat\n\n-- Simple pairs\ndata Pair : (A : Type) -> Type\n| new : (A : Type, x : A, y : A) -> Pair(A)\n\n-- Polymorphic lists\ndata List : (A : Type) -> Type\n| cons : (A : Type, x : A, xs : List(A)) -> List(A)\n| nil : (A : Type) -> List(A)\n\n-- Vectors, i.e., lists with statically known lengths\ndata Vect : (A : Type, n : Nat) -> Type\n| cons : (A : Type, n : Nat, x : A, xs : Vect(A, n)) -> Vect(A, Nat.succ(n))\n| nil : (A : Type) -> Vect(A, Nat.zero)\n\n-- Equality type: holds a proof that two values are identical\ndata Eq : (A : Type, x : A, y : A) -> Type\n| refl : (A : Type, x : A) -> Eq(A, x, x)\n\n-- Polymorphic identity function for a type P\nlet the(P : Type, x : P) =>\n x\n\n-- Boolean negation\nlet not(b : Bool) =>\n case b\n | true => Bool.false\n | false => Bool.true\n : Bool\n\n-- Predecessor of a natural number\nlet pred(a : Nat) =>\n case a\n | succ(pred) => pred\n | zero => Nat.zero\n : Nat\n\n-- Double of a number: the keyword `fold` is used for recursion\nlet double(a : Nat) =>\n case a\n | succ(pred) => Nat.succ(Nat.succ(fold(pred)))\n | zero => Nat.zero\n : Nat\n\n-- Addition of natural numbers\nlet add(a : Nat, b : Nat) =>\n (case a\n | succ(pred) => (b : Nat) => Nat.succ(fold(pred, b))\n | zero => (b : Nat) => b\n : () => (a : Nat) -> Nat)(b)\n\n-- First element of a pair\nlet fst(A : Type, pair : Pair(A)) =>\n case pair\n | new(A, x, y) => x\n : (A) => A\n\n-- Second element of a pair\nlet snd(A : Type, pair : Pair(A)) =>\n case pair\n | new(A, x, y) => y\n : (A) => A\n\n-- Principle of explosion: from falsehood, everything follows\nlet EFQ(P : Type, f : Empty) =>\n case f : P\n\n-- Returns the first element of a vector which is *statically*\n-- asserted to be non-empty, preventing runtime errors.\nlet head(A : Type, n : Nat, vect : Vect(A, Nat.succ(n))) =>\n case vect\n | cons(A, n, x, xs) => x\n | nil(A) => Unit.void\n : (A, n) => case n\n | succ(m) => A\n | zero => Unit\n : Type\n \n-- Returns a vector without its first element\nlet tail(A : Type, n : Nat, vect : Vect(A, Nat.succ(n))) =>\n case vect\n | cons(A0, n0, x, xs) => xs\n | nil(A) => Vect.nil(A)\n : (A, n) => Vect(A, pred(n))\n \n-- The induction principle on natural numbers\n-- can be obtained from total pattern-matching\n-- This function gets somewhat bloated by type\n-- sigs; could be improved with bidirectional?\nlet induction(n : Nat) =>\n case n\n | succ(pred) => \n ( P : (n : Nat) -> Type\n , s : (n : Nat, p : P(n)) -> P(Nat.succ(n))\n , z : P(Nat.zero))\n => s(pred, fold(pred, P, s, z))\n | zero => \n ( P : (n : Nat) -> Type\n , s : (n : Nat, p : P(n)) -> P(Nat.succ(n))\n , z : P(Nat.zero))\n => z\n : () =>\n ( P : (n : Nat) -> Type\n , s : (n : Nat, p : P(n)) -> P(Nat.succ(n))\n , z : P(Nat.zero))\n -> P(self)\n\n-- The number 2\nlet two\n Nat.succ(Nat.succ(Nat.zero))\n\n-- The number 4\nlet four\n add(two, two)\n\n-- Proof that `2 + 2 == 4`\nlet two-plus-two-is-four\n the(Eq(Nat,add(two,two),four), Eq.refl(Nat,four))\n\n-- Congruence of equality: a proof that `a == b` implies `f(a) == f(b)`\nlet cong\n ( A : Type\n , B : Type\n , a : A\n , b : A\n , e : Eq(A, a, b)) =>\n case e\n | refl(A, x) => (f : (x : A) -> B) => Eq.refl(B, f(x))\n : (A, a, b) => (f : (x : A) -> B) -> Eq(B, f(a), f(b))\n\n-- Symmetry of equality: a proof that `a == b` implies `b == a`\nlet sym\n ( A : Type\n , a : A\n , b : A\n , e : Eq(A, a, b)) =>\n case e\n | refl(A, x) => Eq.refl(A, x)\n : (A, a, b) => Eq(A, b, a)\n\n-- Substitution of equality: if `a == b`, then `a` can be replaced by `b` in a proof `P`\nlet subst\n ( A : Type\n , x : A\n , y : A\n , e : Eq(A, x, y)) =>\n case e\n | refl(A, x) => (P : (x : A) -> Type, px : P(x)) => px\n : (A, x, y) => (P : (x : A) -> Type, px : P(x)) -> P(y)\n\n-- Proof that `a + 0 == a`\nlet add-n-zero(n : Nat) =>\n case n\n | succ(a) => cong(Nat, Nat, add(a, Nat.zero), a, fold(a), Nat.succ)\n | zero => Eq.refl(Nat, Nat.zero)\n : Eq(Nat, add(self, Nat.zero), self)\n\n-- Proof that `a + (1 + b) == 1 + (a + b)`\nlet add-n-succ-m(n : Nat) =>\n case n\n | succ(n) => (m : Nat) => cong(Nat, Nat, add(n, Nat.succ(m)), Nat.succ(add(n,m)), fold(n,m), Nat.succ)\n | zero => (m : Nat) => Eq.refl(Nat, Nat.succ(m))\n : () => (m : Nat) -> Eq(Nat, add(self, Nat.succ(m)), Nat.succ(add(self, m)))\n\n-- Proof that `a + b = b + a`\nlet add-comm(n : Nat) =>\n case n\n | succ(n) => (m : Nat) =>\n subst(Nat, add(m,n), add(n,m), fold(m,n), (x : Nat) => Eq(Nat, Nat.succ(x), add(m, Nat.succ(n))),\n sym(Nat, add(m, Nat.succ(n)), Nat.succ(add(m, n)), add-n-succ-m(m, n)))\n | zero => (m : Nat) => sym(Nat, add(m, Nat.zero), m, add-n-zero(m))\n : () => (m : Nat) -> Eq(Nat, add(self, m), add(m, self))\n\n\nlet main (a : Nat, b : Nat, e : Eq(Nat, a, b)) => sym(Nat, a, b, e)\n", "meta": {"hexsha": "546afc7fdf2bd4db8e768b68c4f4eed74f935f72", "size": 5337, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "examples/main.for", "max_stars_repo_name": "rinor/Formality", "max_stars_repo_head_hexsha": "58dc8d4009a4d909a4f1a05cc7ef9e91997ff106", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/main.for", "max_issues_repo_name": "rinor/Formality", "max_issues_repo_head_hexsha": "58dc8d4009a4d909a4f1a05cc7ef9e91997ff106", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/main.for", "max_forks_repo_name": "rinor/Formality", "max_forks_repo_head_hexsha": "58dc8d4009a4d909a4f1a05cc7ef9e91997ff106", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.796875, "max_line_length": 106, "alphanum_fraction": 0.4890387858, "num_tokens": 1866, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533107374443, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7623500312458665}} {"text": "module sub\r\n\tcontains\r\n\t\r\n\t\tsubroutine subm(N)\r\n\t\tinteger::N\r\n\t\treal*8 a(N,N),B(N,N),x\r\n\t\t\r\n\t\twrite(*,*)\"input the Matrix\"\r\n\t\tread(*,*)((A(i,j),j=1,N),i=1,N)\r\n\t\tdo i=1,N\r\n\t\t\tdo j=1,N\r\n\t\t\t\tif(i==j) then\r\n\t\t\t\tB(i,j)=1\r\n\t\t\t\telse\r\n\t\t\t\tB(i,j)=0\r\n\t\t\t\tend if\r\n\t\t\tend do\r\n\t\tend do\r\n\t\tdo j=1,N\r\n\t\t\tx=A(j,j)\r\n\t\t\tdo k=1,N\r\n\t\t\t\tA(j,k)=A(j,k)/x\r\n\t\t\t\tB(j,k)=B(j,k)/x\r\n\t\t\t\t\r\n\t\t\tend do\r\n\t\t\tdo i=1,N\r\n\t\t\t\tif(i/=j)then\r\n\t\t\t\tx=A(i,j)\r\n\t\t\t\tdo k=1,N\r\n\t\t\t\tA(i,k)=A(i,k)-A(j,k)*x\r\n\t\t\t\tB(i,k)=B(i,k)-x*B(j,k)\r\n\t\t\t\tend do\r\n\t\t\t\tend if\r\n\t\t\tend do\r\n\t\tend do\r\n\t\twrite(*,'(f22.6)')((B(i,j),j=1,N),i=1,N)\r\n\t\t\r\n\t\tend subroutine subm\r\n\r\nend module\r\n", "meta": {"hexsha": "de75dd8b80d87c6792811c350e32ec99b2c2ad49", "size": 616, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "inverse_matrix/sub.f90", "max_stars_repo_name": "DearDon/Matrix", "max_stars_repo_head_hexsha": "b76477860e673f9c124ad7a9bc83f9b0eaca1661", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inverse_matrix/sub.f90", "max_issues_repo_name": "DearDon/Matrix", "max_issues_repo_head_hexsha": "b76477860e673f9c124ad7a9bc83f9b0eaca1661", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inverse_matrix/sub.f90", "max_forks_repo_name": "DearDon/Matrix", "max_forks_repo_head_hexsha": "b76477860e673f9c124ad7a9bc83f9b0eaca1661", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.0243902439, "max_line_length": 43, "alphanum_fraction": 0.4350649351, "num_tokens": 268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603708, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7623500234942117}} {"text": "!Factorial Function\nreal*8 function factorial(n)\n implicit none\n integer, intent(in) :: n\n real*8 :: Ans\n integer :: i\n\n Ans = 1\n do i=1,n\n Ans = Ans * dble(i)\n end do\n\n factorial = Ans\nend function factorial\n\n!Function to compute radial Zernike polynomial at radius rho of order n,m\nreal*8 function radialpoly(rho,n,m)\n !Declarations\n implicit none\n real*8, intent(in) :: rho\n integer, intent(in) :: n,m\n real*8 :: output\n real*8 :: const, factorial\n integer :: j\n\n !n,m are assumed to be valid (m>=n, n-abs(m) is even)\n !Following Python module convention, negative m indicates sinusoidal Zernike\n output = 0.\n if (rho<=1) then\n do j = 0,(n-abs(m))/2\n const = (-1)**j*factorial(n-j)/factorial(j)/factorial((n+m)/2-j)/factorial((n-m)/2-j)\n output = output + const*rho**(n-2*j)\n end do\n end if\n\n radialpoly = output\n\nend function radialpoly\n\n!This function makes use of the q recursive method to compute a Zernike\n!Radial polynomial\nrecursive function fastradpoly(rho,n,m) result(output)\n !Declarations\n implicit none\n real*8, intent(in) :: rho,n,m\n !integer, intent(in) :: n,m\n real*8 :: output,r2,r4,h1,h2,h3,tempm\n\n !Handle rho=0\n if (rho==0) then\n if (m==0) then\n output = (-1.)**(n/2)\n return\n else\n output = 0.\n return\n end if\n end if\n\n !Three possibilities, m=n, m=n-2, m= m)\n h3 = -4*(tempm+2)*(tempm+1)/(n+tempm+2)/(n-tempm)\n h2 = h3*(n+tempm+4)*(n-tempm-2)/4./(tempm+3) + (tempm+2)\n h1 = .5*(tempm+4)*(tempm+3) - (tempm+4)*h2 + h3*(n+tempm+6)*(n-tempm-4)/8.\n output = h1*r4 + (h2 + h3/rho**2)*r2\n if (tempm == m) then\n return\n end if\n r4 = r2\n r2 = output\n tempm = tempm - 2\n end do\n end if\n\nend function fastradpoly\n\n!This function makes use of the q recursive method to compute a Zernike\n!Radial polynomial DERIVATIVE\nrecursive function fastradder(rho,n,m) result(output)\n !Declarations\n implicit none\n real*8, intent(in) :: rho\n real*8, intent(in) :: n,m\n real*8 :: output,r2,r4,h1,h2,h3,fastradpoly,tempm\n\n !Handle rho=0\n if (rho==0) then\n if (m==1) then\n output = (-1.)**((n-1)/2)*(n+1)/2\n return\n else\n output = 0.\n return\n end if\n end if \n\n !Three possibilities, m=n, m=n-2, m= m)\n h3 = -4*(tempm+2)*(tempm+1)/(n+tempm+2)/(n-tempm)\n h2 = h3*(n+tempm+4)*(n-tempm-2)/4./(tempm+3) + (tempm+2)\n h1 = .5*(tempm+4)*(tempm+3) - (tempm+4)*h2 + h3*(n+tempm+6)*(n-tempm-4)/8.\n !Might need to literally copy and paste fastradpoly here to save on function call...\n output = h1*r4 + (h2 + h3/rho**2)*r2 - 2*h3*fastradpoly(rho,n,tempm+2)/rho**3\n if (tempm == m) then\n return\n end if\n r4 = r2\n r2 = output\n tempm = tempm - 2\n end do\n end if\n\nend function fastradder\n\n!This function will return a vector of Zernike polynomial evaluations for\n!a point (rho,theta) and a number N of standard Zernike polynomials\n!Start at n=0, and loop up in radial order\n!For each radial order, start at Znn, and recursively calculate down\n!Adding azimuthal dependence is easy, just note what overall index you're at\n!and add sinmt if odd and cosmt if even, where Z1 = 1, so Z2=2rcost\n!Still need special handling of rho=0\nsubroutine zernset(rho,theta,rorder,aorder,znum,polyout,derrho,dertheta)\n !Declarations\n implicit none\n integer, intent(in) :: znum\n integer, intent(in) :: rorder(znum),aorder(znum)\n real*8, intent(in) :: rho,theta\n real*8, intent(out) :: polyout(znum),derrho(znum),dertheta(znum)\n real*8, allocatable :: rnm(:,:),rprime(:,:)\n integer :: i,j,radnum,tznum\n real*8 :: n,m,mm,h1,h2,h3,norm\n real*8 :: fastradpoly,fastradder,zernthetader,zernrhoder,zernike\n\n !Allocate temp output array for full sets of radial polynomials\n !Will slice off unused terms at the end\n tznum = 1\n radnum = 1\n do while(tznum < znum)\n tznum = tznum + (radnum + 1)\n radnum = radnum + 1\n end do\n !print *, tznum, \" \", radnum\n !Allocate radnum by radnum arrays for radial polynomials\n !This is much larger than necessary, but for practical purposes this should be ok\n allocate(rnm(radnum,radnum))\n allocate(rprime(radnum,radnum))\n\n !Compute radial polynomials and derivatives\n do i=1,radnum\n n = dble(i)-1\n do j=int(n)+1,1,-2\n m = dble(j)-1\n !Handle case rho=0\n if (rho==0) then\n if (m==1) then\n rprime(i,j) = (-1.)**((n-1)/2)*(n+1)/2\n rnm(i,j) = 0.\n else if (m==0) then\n rprime(i,j) = 0.\n rnm(i,j) = (-1.)**(n/2)\n else\n rprime(i,j) = 0.\n rnm(i,j) = 0.\n end if\n !Handle general case\n else\n if (n==m) then\n rnm(i,j) = rho**n\n rprime(i,j) = n*rho**(n-1)\n else if (m==n-2) then\n rnm(i,j) = n*rnm(i,i) - (n-1)*rnm(i-2,i-2)\n rprime(i,j) = n*rprime(i,i) - (n-1)*rprime(i-2,i-2)\n else\n h3 = -4*(m+2)*(m+1)/(n+m+2)/(n-m)\n h2 = h3*(n+m+4)*(n-m-2)/4./(m+3) + (m+2)\n h1 = .5*(m+4)*(m+3) - (m+4)*h2 + h3*(n+m+6)*(n-m-4)/8.\n rnm(i,j) = h1*rnm(i,j+4) + (h2+h3/rho**2)*rnm(i,j+2)\n rprime(i,j) = h1*rprime(i,j+4) + (h2+h3/rho**2)*rprime(i,j+2) - 2*h3/rho**3*rnm(i,j+2)\n end if\n end if\n !print *, i-1, \" \", j-1\n !print *, rnm(i,j), \" \", fastradpoly(rho,dble(i-1),dble(j-1))\n !print *, rprime(i,j), \" \", fastradder(rho,dble(i-1),dble(j-1))\n end do\n end do\n\n !Radial terms are computed. Now construct Zernike, Zernderrho, and Zerndertheta\n !Use standard order up to znum\n do i=1,znum\n !Rorder and Aorder are passed to this function\n !Simply construct if statement on m, and compute all three!\n n = rorder(i)\n mm = aorder(i)\n m = abs(mm)\n norm = sqrt(2*(n+1))\n if (mm<0) then\n polyout(i) = norm * rnm(int(n)+1,int(m)+1) * sin(m*theta)\n derrho(i) = norm * rprime(int(n)+1,int(m)+1) * sin(m*theta)\n dertheta(i) = norm * rnm(int(n)+1,int(m)+1) * cos(m*theta) * m\n else if (mm>0) then\n polyout(i) = norm * rnm(int(n)+1,int(m)+1) * cos(m*theta)\n derrho(i) = norm * rprime(int(n)+1,int(m)+1) * cos(m*theta)\n dertheta(i) = -norm * rnm(int(n)+1,int(m)+1) * sin(m*theta) * m\n else\n polyout(i) = norm*sqrt(0.5)*rnm(int(n)+1,int(m)+1)\n derrho(i) = norm*sqrt(0.5)*rprime(int(n)+1,int(m)+1)\n dertheta(i) = 0.\n end if\n !print *, dertheta(i), \" \",zernthetader(rho,theta,int(n),int(mm))\n end do\n\nend subroutine zernset\n\n!Function to compute full Zernike polynomial at radius rho and angle theta of order n,m\n!Following Python Zernike mod conventions\nreal*8 function zernike(rho,theta,n,m)\n !Declarations\n implicit none\n real*8, intent(in) :: rho,theta\n integer, intent(in) :: n,m\n real*8 :: fastradpoly,rnm,znm,norm\n\n !Compute radial polynomial\n rnm = fastradpoly(rho,dble(n),abs(dble(m)))\n\n !Compute full Zernike polynomial\n norm = sqrt(2*(dble(n)+1))\n if (m<0) then\n znm = norm * rnm * sin(m*theta)\n else if (m>0) then\n znm = norm * rnm * cos(m*theta)\n else\n znm = norm*sqrt(0.5)*rnm\n end if\n\n !Return Zernike polynomial\n zernike = znm\n\nend function zernike\n\n!Function to compute radial polynomial derivative\nreal*8 function radialder(rho,n,m)\n !Declarations\n implicit none\n real*8, intent(in) :: rho\n integer, intent(in) :: n,m\n real*8 :: output\n real*8 :: const, factorial\n integer :: j\n !n,m are assumed to be valid (m>=n, n-abs(m) is even)\n !Following Python module convention, negative m indicates sinusoidal Zernike\n output = 0.\n if (rho<=1) then\n do j = 0,(n-abs(m))/2\n const = (-1)**j*factorial(n-j)/factorial(j)/factorial((n+m)/2-j)/factorial((n-m)/2-j)\n output = output + const*(n-2*j)*rho**(n-2*j-1)\n end do\n end if\n\n radialder = output\n\nend function radialder\n\n!Function to compute partial Zernike derivative wrt rho\nreal*8 function zernrhoder(rho,theta,n,m)\n !Declarations\n implicit none\n real*8, intent(in) :: rho,theta\n integer, intent(in) :: n,m\n real*8 :: fastradder, rnm, norm, znm\n\n !Compute radial polynomial\n rnm = fastradder(rho,dble(n),abs(dble(m)))\n\n !Compute full Zernike polynomial\n norm = sqrt(2*(dble(n)+1))\n if (m<0) then\n znm = norm * rnm * sin(abs(m)*theta)\n else if (m>0) then\n znm = norm * rnm * cos(m*theta)\n else\n znm = norm*sqrt(0.5)*rnm\n end if\n\n !Return Zernike polynomial\n zernrhoder = znm\n\nend function zernrhoder\n\n!Function to compute partial Zernike derivative wrt theta\nreal*8 function zernthetader(rho,theta,n,m)\n !Declarations\n implicit none\n real*8, intent(in) :: rho,theta\n integer, intent(in) :: n,m\n real*8 :: rnm, znm, fastradpoly, norm\n\n !Compute radial polynomial\n rnm = fastradpoly(rho,dble(n),abs(dble(m)))\n\n !Compute full Zernike polynomial\n norm = sqrt(2*(dble(n)+1))\n if (m<0) then\n znm = norm * rnm * abs(m) * cos(abs(m)*theta)\n else if (m>0) then\n znm = -norm * rnm * m * sin(m*theta)\n else\n znm = 0.\n end if\n\n !Return Zernike polynomial\n zernthetader = znm\n\nend function zernthetader\n\n!This function computes a Legendre polynomial of order n\nreal*8 function legendre(x,n)\n !Declarations\n implicit none\n real*8, intent(in) :: x\n integer, intent(in) :: n\n integer :: i\n real*8 :: factorial,x2\n\n if (abs(x) > 1.) then\n x2 = x/abs(x)\n else\n x2 = x\n end if\n\n legendre = 0.\n if (n==0) then\n legendre = 1.\n else\n do i=0,floor(real(n)/2)\n legendre = legendre + (-1)**(i)*factorial(2*n-2*i)/factorial(i)/factorial(n-i)/factorial(n-2*i)/2**n*x2**(n-2*i)\n end do\n end if\n\nend function legendre\n\n!This function computes a Legendre polynomial first derivative of order n\nreal*8 function legendrep(x,n)\n !Declarations\n implicit none\n real*8, intent(in) :: x\n integer, intent(in) :: n\n integer :: i\n real*8 :: factorial\n\n legendrep = 0.\n if (n==0) then\n legendrep = 0.\n else if (n==1) then\n legendrep = 1.\n else if (x==0. .and. mod(n,2)==0) then\n legendrep = 0.\n else\n do i=0,floor(real(n)/2)\n legendrep = legendrep + (-1)**(i)*factorial(2*n-2*i)/factorial(i)/factorial(n-i)/factorial(n-2*i)/2**n*(n-2*i)*x**(n-2*i-1)\n end do\n end if \n\n if (abs(x) > 1.) then\n legendrep = 0.\n end if\n\nend function legendrep\n", "meta": {"hexsha": "3acc3c486ddd7de1ccc0e075a47ce3fc5fe40007", "size": 10903, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "specialFunctions.f95", "max_stars_repo_name": "bddonovan/PyXFocus", "max_stars_repo_head_hexsha": "2d6722f0db28c045df35075487f9d4fdfed8b284", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-04-20T15:32:24.000Z", "max_stars_repo_stars_event_max_datetime": "2018-04-20T15:32:24.000Z", "max_issues_repo_path": "specialFunctions.f95", "max_issues_repo_name": "bddonovan/PyXFocus", "max_issues_repo_head_hexsha": "2d6722f0db28c045df35075487f9d4fdfed8b284", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-11-03T16:13:46.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-26T11:13:03.000Z", "max_forks_repo_path": "specialFunctions.f95", "max_forks_repo_name": "bddonovan/PyXFocus", "max_forks_repo_head_hexsha": "2d6722f0db28c045df35075487f9d4fdfed8b284", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-04-13T17:24:54.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-08T15:27:29.000Z", "avg_line_length": 28.028277635, "max_line_length": 129, "alphanum_fraction": 0.5894707879, "num_tokens": 3943, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603709, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.7623500172772042}} {"text": " MODULE random_normal_mod\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n CONTAINS\n\n!*********************************************************************\n\n FUNCTION random_normal(mean,sd)\n! .. Use Statements ..\n USE random_standard_normal_mod\n! ..\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n! .. Function Return Value ..\n REAL :: random_normal\n! ..\n! .. Scalar Arguments ..\n REAL, INTENT (IN) :: mean, sd\n! ..\n! .. Executable Statements ..\n\n!**********************************************************************\n! REAL FUNCTION GENNOR( MEAN, SD )\n! GENerate random deviate from a NORmal distribution\n! Function\n! Generates a single random deviate from a normal distribution\n! with mean, MEAN, and standard deviation, SD.\n! Arguments\n! MEAN --> Mean of the normal distribution.\n! REAL MEAN\n! SD --> Standard deviation of the normal distribution.\n! REAL SD\n! JJV (SD >= 0)\n! GENNOR <-- Generated normal deviate.\n! REAL GENNOR\n! Method\n! Renames SNORM from TOMS as slightly modified by BWB to use RANF\n! instead of SUNIF.\n! For details see:\n! Ahrens, J.H. and Dieter, U.\n! Extensions of Forsythe's Method for Random\n! Sampling from the Normal Distribution.\n! Math. Comput., 27,124 (Oct. 1973), 927 - 937.\n!**********************************************************************\n! JJV added check to ensure SD >= 0.0\n IF (sd<0.0) THEN\n WRITE (*,*) 'SD < 0.0 in GENNOR - ABORT'\n WRITE (*,*) 'Value of SD: ', sd\n STOP 'SD < 0.0 in GENNOR - ABORT'\n END IF\n\n random_normal = sd*random_standard_normal() + mean\n RETURN\n\n END FUNCTION random_normal\n\n!*********************************************************************\n\n END MODULE random_normal_mod\n", "meta": {"hexsha": "7f7bb2bea58b62c143f8fb9e303d1aa4e71cb628", "size": 2067, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/random_normal_mod.f90", "max_stars_repo_name": "urbanjost/fpm_tools", "max_stars_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/random_normal_mod.f90", "max_issues_repo_name": "urbanjost/fpm_tools", "max_issues_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/random_normal_mod.f90", "max_forks_repo_name": "urbanjost/fpm_tools", "max_forks_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-14T11:36:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-14T11:36:01.000Z", "avg_line_length": 33.3387096774, "max_line_length": 71, "alphanum_fraction": 0.4610546686, "num_tokens": 436, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7623273877625708}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n!\n!\n! this program tests subroutine compute_gaussian_latitudes_and_weights for computing \n! the Gauss Legendre points and weights in file compute_gaussian_latitudes_and_weights.f\n! It tests only the april 2002 version and not the\n! older version in file compute_gaussian_latitudes_and_weights.old.f\n! gauss points and weights are computed using newtons method\n! with equally spaced points as first guess. Points are\n! computed as theta_i where x_i = cos(theta_i)\n! the method is discussed in \"On computing the Gauss_Legendre\n! points and weights\" by Paul N Swarztrauber, accepted for \n! publication in the SIAM journal of scientific computing.\n! April 2002\n!\nprogram test_gaussian_latitudes_and_weights_routines\n\n use, intrinsic :: ISO_Fortran_env, only: &\n sp => REAL32, &\n stdout => OUTPUT_UNIT\n\n use spherepack, only: &\n ip, & ! Integer precision\n wp, & ! Working precision\n compute_gaussian_latitudes_and_weights, pi\n\n ! Explicit typing only\n implicit none\n\n real(wp) :: dmax\n real(wp) :: hold\n integer(ip) :: i\n integer(ip) :: ido\n integer(ip) :: ierror\n integer(ip) :: irm\n integer(ip) :: ldw\n integer(ip) :: lwork\n integer(ip), parameter :: NLAT = 63\n real(wp) :: pmax\n real(wp) :: rerr\n real(wp) :: rmax\n\n real(wp) :: sums\n\n real(wp) :: tdoub\n real(wp) :: tsing\n real(wp) :: wmax\n\n real(wp) :: theta(NLAT), wts(NLAT), work(NLAT+2)\n real(wp) :: dtheta(NLAT), dwts(NLAT)\n real(wp) :: dwmx, tmax, dwmax, dtmax\n real :: theta_sp(NLAT), wts_sp(NLAT), work_sp(nlat + 1)\n real :: diff(NLAT)\n real(sp) :: t1(2), t2(2)\n real :: sumw\n \n ! Description\n write (stdout, '(/a/)') &\n ' gaussian_latitudes_and_weights_routines *** TEST RUN *** '\n\n lwork = NLAT+1\n hold = etime(t1)\n hold = t1(1)\n call gsqd(NLAT, theta, wts, work, lwork, ierror)\n tdoub = etime(t1)\n tdoub = t1(1)-hold\n\n ! Check error flag\n if (ierror /= 0) write (stdout, '(a, i5)') ' ierror = ', ierror\n\n write (stdout, '(a, 1pe15.6)') ' tdoub ', tdoub\n\n ! Compare double with double\n ldw = NLAT+2\n hold = etime(t1)\n hold = t1(1)\n call compute_gaussian_latitudes_and_weights(NLAT, dtheta, dwts, ierror)\n tdoub = etime(t1)\n tdoub = t1(1)-hold\n\n if (ierror /= 0) write (stdout, '(a, i5)') ' ierror = ', ierror\n\n write (stdout, '(a, 1pe15.6)') &\n ' tdoub compute_gaussian_latitudes_and_weights', tdoub\n\n dwmx = 0.0\n tmax = 0.0\n dwmax = 0.0\n dtmax = 0.0\n ido = (nlat + 1)/2\n\n do i=1, ido\n dtmax = max(dtmax, abs(theta(i)-dtheta(i)))\n dwmax = max(dwmax, abs(wts(i)-dwts(i)))\n tmax = max(tmax, abs(theta(i)))\n dwmx = max(dwmx, abs(wts(i)))\n end do\n\n dtmax = dtmax/tmax\n dwmax = dwmax/dwmx\n write (stdout, 33) NLAT, dtmax, dwmax\n33 format(' nlat', i6, ' points ', 1pd15.6, ' weights ', d15.6)\n\n sumw = sum(wts)\n\n write (stdout, 638) sumw\n638 format(' sumw ', 1pd39.30)\n\n hold = etime(t2)\n hold = t2(1)\n lwork = NLAT+2\n call sgaqd(NLAT, theta_sp, wts_sp, work_sp, lwork, ierror)\n tsing = etime(t2)\n tsing = t2(1)-hold\n if (ierror /= 0) write (stdout, 5) ierror\n5 format(' iserror=', i5)\n\n sums =sum(wts_sp)\n\n write (stdout, 636) sums\n636 format(' sums ', 1pe24.15)\n dmax = 0.0\n wmax = 0.0\n rmax = 0.0\n ido = (nlat + 1)/2\n do i=1, ido\n diff(i) = wts(i)-wts_sp(i)\n dmax = max(dmax, abs(diff(i)))\n wmax = max(wmax, abs(wts_sp(i)))\n rerr = abs(diff(i)/wts_sp(i))\n if (rerr>rmax) then\n rmax = rerr\n irm = i\n end if\n6 format(' wts ', 1pd15.6, ' swts ', e15.6, ' rpter ', e15.6)\n end do\n\n ! write (stdout, 7) (diff(i), i=nlat-25, nlat)\n7 format(' diff in weights'/(1p8e10.03))\n dmax = dmax/wmax\n write (stdout, 9) NLAT, irm, dmax, rmax\n9 format(' weights: nlat ', i6, ' irele ', i6, &\n ' dmax ', 1pe15.6, ' rmax ', 1pe15.6)\n dmax = 0.0\n pmax = 0.0\n rmax = 0.0\n do i=1, ido\n diff(i) = theta(i)-theta_sp(i)\n dmax = max(dmax, abs(diff(i)))\n pmax = max(pmax, abs(theta_sp(i)))\n rerr = abs(diff(i)/theta_sp(i))\n if (rerr>rmax) then\n rmax = rerr\n irm = i\n end if\n end do\n ! write (stdout, 11) (diff(i), i=nlat-25, nlat)\n11 format(' diff in points'/(1p8e10.03))\n dmax = dmax/pmax\n write (stdout, 12) NLAT, irm, dmax, rmax\n12 format(' points: nlat ', i6, ' irele ', i6, &\n ' dmax ', 1pe15.6, ' rmax ', 1pe15.6)\n\n dmax = 0.0\n do i=1, NLAT\n diff(i) = cos(theta(i))-cos(theta_sp(i))\n dmax = max(dmax, abs(diff(i)))\n end do\n\n ! format(' diff in points'/(1p8e10.03))\n write (stdout, 112) dmax\n112 format(' max difference in mu', 1pe15.6)\n write (stdout, 1) NLAT, tsing, tdoub\n1 format(' nlat', i6, ' tsing', 1pe15.6, ' tdoub', e15.6)\n\ncontains\n !\n ! subroutine gsqd is a single precision version of compute_gaussian_latitudes_and_weights.\n ! gauss points and weights are computed using newtons method\n ! with equally spaced points as first guess. Points are\n ! computed as theta_i where x_i = cos(theta_i)\n ! the method is discussed in \"On computing the Gauss_Legendre\n ! points and weights\" by Paul N Swarztrauber, accepted for \n ! publication in the SIAM journal of scientific computing.\n ! April 2002\n !\n subroutine gsqd(nlat, theta, wts, dwork, ldwork, ierror)\n\n integer(ip) :: i\n integer(ip) :: ierror\n integer(ip) :: ldwork\n integer(ip) :: nlat\n integer(ip) :: ns2\n !\n !\n ! subroutine gsqd computes the nlat gaussian colatitudes and weights\n ! in real. The colatitudes are in radians and lie in the\n ! in the interval (0, pi).\n !\n ! input parameters\n !\n ! nlat the number of gaussian colatitudes in the interval (0, pi)\n ! (between the two poles). nlat must be greater than zero.\n !\n ! dwork a real temporary workspace.\n !\n ! ldwork the length of the workspace in the routine calling gsqd\n ! ldwork must be at least nlat+1.\n !\n ! output parameters\n !\n ! theta a real vector of length nlat containing the\n ! nlat gaussian colatitudes on the sphere in increasing radians\n ! in the interval (0, pi).\n !\n ! wts a real vector of length nlat containing the\n ! nlat gaussian weights.\n !\n ! ierror = 0 no errors\n ! = 1 if ldwork.lt.nlat+1\n ! = 2 if nlat<=0\n !\n ! *****************************************************************\n !\n dimension dwork(nlat + 1), theta(nlat), wts(nlat)\n real HALF_PI, x, theta, wts, dwork\n ierror = 1\n !\n ! check workspace length\n !\n if (ldworkeps*abs(zero)) goto 10\n theta(nix) = zero\n nix = nix-1\n if (nix==0) goto 30\n if (nix==nhalf-1) zero = 3.0*zero-pi\n if (nix n) return\n if (n-1< 0) then\n goto 2\n else if (n-1 == 0) then\n goto 3\n else\n goto 5\n end if\n2 cp(1) = sqrt(2.0)\n return\n3 if (ma /= 0) goto 4\n cp(1) = sqrt(1.5)\n return\n4 cp(1) = sqrt(.75)\n if (m == -1) cp(1) = -cp(1)\n return\n5 if (mod(n+ma, 2) /= 0) goto 10\n nmms2 = (n-ma)/2\n fnum = n+ma+1\n fnmh = n-ma+1\n pm1 = 1.0\n goto 15\n10 nmms2 = (n-ma-1)/2\n fnum = n+ma+2\n fnmh = n-ma+2\n pm1 = -1.0\n ! t1 = 1.\n ! t1 = 2.0**(n-1)\n ! t1 = 1.0/t1\n15 t1 = 1.0/sc20\n nex = 20\n fden = 2.0\n if (nmms2 < 1) goto 20\n do 18 i=1, nmms2\n t1 = fnum*t1/fden\n if (t1 > sc20) then\n t1 = t1/sc40\n nex = nex+40\n end if\n fnum = fnum+2.\n fden = fden+2.\n18 continue\n20 t1 = t1/2.0**(n-1-nex)\n if (mod(ma/2, 2) /= 0) t1 = -t1\n t2 = 1.\n if (ma == 0) goto 26\n do 25 i=1, ma\n t2 = fnmh*t2/(fnmh+pm1)\n fnmh = fnmh+2.\n25 continue\n26 cp2 = t1*sqrt((n+.5)*t2)\n fnnp1 = n*(n+1)\n fnmsq = fnnp1-2.0*ma*ma\n l = (n+1)/2\n if (mod(n, 2) == 0 .and. mod(ma, 2) == 0) l = l+1\n cp(l) = cp2\n if (m >= 0) goto 29\n if (mod(ma, 2) /= 0) cp(l) = -cp(l)\n29 if (l <= 1) return\n fk = n\n a1 = (fk-2.)*(fk-1.)-fnnp1\n b1 = 2.*(fk*fk-fnmsq)\n cp(l-1) = b1*cp(l)/a1\n30 l = l-1\n if (l <= 1) return\n fk = fk-2.\n a1 = (fk-2.)*(fk-1.)-fnnp1\n b1 = -2.*(fk*fk-fnmsq)\n c1 = (fk+1.)*(fk+2.)-fnnp1\n cp(l-1) = -(b1*cp(l)+c1*cp(l+1))/a1\n goto 30\n end subroutine lfc\n subroutine lft (m, n, theta, cp, pb)\n\n integer(ip) :: k\n integer(ip) :: kdo\n integer(ip) :: m\n integer(ip) :: mmod\n integer(ip) :: n\n integer(ip) :: nmod\n real cp(*), pb, theta, cdt, sdt, cth, sth, chh\n cdt = cos(2.0*theta)\n sdt = sin(2.0*theta)\n nmod=mod(n, 2)\n mmod=mod(m, 2)\n if (nmod< 0) then\n goto 1\n else if (nmod == 0) then\n goto 1\n else\n goto 2\n end if\n1 if (mmod< 0) then\n goto 3\n else if (mmod == 0) then\n goto 3\n else\n goto 4\n end if\n !\n ! n even, m even\n !\n3 kdo=n/2\n pb = .5*cp(1)\n if (n == 0) return\n cth = cdt\n sth = sdt\n do 170 k=1, kdo\n ! pb = pb+cp(k+1)*cos(2*k*theta)\n pb = pb+cp(k+1)*cth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n170 continue\n return\n !\n ! n even, m odd\n !\n4 kdo = n/2\n pb = 0.0\n cth = cdt\n sth = sdt\n do 180 k=1, kdo\n ! pb = pb+cp(k)*sin(2*k*theta)\n pb = pb+cp(k)*sth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n180 continue\n return\n2 if (mmod< 0) then\n goto 13\n else if (mmod == 0) then\n goto 13\n else\n goto 14\n end if\n !\n ! n odd, m even\n !\n13 kdo = (n+1)/2\n pb = 0.0\n cth = cos(theta)\n sth = sin(theta)\n do 190 k=1, kdo\n ! pb = pb+cp(k)*cos((2*k-1)*theta)\n pb = pb+cp(k)*cth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n190 continue\n return\n !\n ! n odd, m odd\n !\n14 kdo = (n+1)/2\n pb = 0.0\n cth = cos(theta)\n sth = sin(theta)\n do 200 k=1, kdo\n ! pb = pb+cp(k)*sin((2*k-1)*theta)\n pb = pb+cp(k)*sth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n200 continue\n return\n end subroutine lft\n subroutine dlft (m, n, theta, cp, pb)\n\n integer(ip) :: k\n integer(ip) :: kdo\n integer(ip) :: m\n integer(ip) :: mmod\n integer(ip) :: n\n integer(ip) :: nmod\n !\n ! computes the derivative of pmn(theta) with respect to theta\n !\n dimension cp(1)\n real cp, pb, theta, cdt, sdt, cth, sth, chh\n cdt = cos(2.0*theta)\n sdt = sin(2.0*theta)\n nmod=mod(n, 2)\n mmod=mod(abs(m), 2)\n if (nmod< 0) then\n goto 1\n else if (nmod == 0) then\n goto 1\n else\n goto 2\n end if\n1 if (mmod< 0) then\n goto 3\n else if (mmod == 0) then\n goto 3\n else\n goto 4\n end if\n !\n ! n even, m even\n !\n3 kdo=n/2\n pb = 0.0\n if (n == 0) return\n cth = cdt\n sth = sdt\n do 170 k=1, kdo\n ! pb = pb+cp(k+1)*cos(2*k*theta)\n pb = pb-2.0*k*cp(k+1)*sth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n170 continue\n return\n !\n ! n even, m odd\n !\n4 kdo = n/2\n pb = 0.0\n cth = cdt\n sth = sdt\n do 180 k=1, kdo\n ! pb = pb+cp(k)*sin(2*k*theta)\n pb = pb+2.0*k*cp(k)*cth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n180 continue\n return\n2 if (mmod< 0) then\n goto 13\n else if (mmod == 0) then\n goto 13\n else\n goto 14\n end if\n !\n ! n odd, m even\n !\n13 kdo = (n+1)/2\n pb = 0.0\n cth = cos(theta)\n sth = sin(theta)\n do 190 k=1, kdo\n ! pb = pb+cp(k)*cos((2*k-1)*theta)\n pb = pb-(2.0*k-1)*cp(k)*sth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n190 continue\n return\n !\n ! n odd, m odd\n !\n14 kdo = (n+1)/2\n pb = 0.0\n cth = cos(theta)\n sth = sin(theta)\n do 200 k=1, kdo\n ! pb = pb+cp(k)*sin((2*k-1)*theta)\n pb = pb+(2.0*k-1)*cp(k)*cth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n200 continue\n\n end subroutine dlft\n\n subroutine dlfcz(n, cp)\n\n integer(ip) :: i\n integer(ip) :: ic\n integer(ip) :: j\n integer(ip) :: n\n integer(ip) :: ncp\n !\n ! computes the fourier coefficients of the legendre\n ! polynomials. n is the degree and integer(n/2+1)\n ! coefficients are returned in cp\n !\n real cp(n/2+1)\n real cn, t1, t2, t3, t4, coef, fi\n !\n cn = 2.0\n write (stdout, 9) cn\n9 format(' check1 on dble cn ', 1pd20.011)\n if (n>0) then\n ic = 0\n fi = 0.0\n do i=1, n\n fi = fi+2.0\n cn = (1.0-1.0/fi**2)*cn\n if (abs(cn) > 5.0 .and. ic == 0) then\n ic = 1\n write (stdout, 7) i, cn\n7 format(' i ', i7, ' check3 on cn', 1pd15.6)\n end if\n end do\n end if\n write (stdout, 8) cn\n8 format(' check2 on dble cn ', 1pd20.011)\n cn = sqrt(cn)\n ncp = n/2+1\n t1 = -1.0\n t2 = n+1.0\n t3 = 0.0\n t4 = n+n+1.0\n cp(ncp) = cn\n coef = 1.0\n write (stdout, 11) cn\n11 format(' check on dble cn ', 1pd20.011)\n ! do j = ncp-1, 1, -1\n j = ncp\n10 j = j-1\n t1 = t1+2.0\n t2 = t2-1.0\n t3 = t3+1.0\n t4 = t4-2.0\n coef = (t1*t2)/(t3*t4)*coef\n cp(j) = coef*cn\n if (j>1) goto 10\n ! end do\n return\n end subroutine dlfcz\n !\n subroutine sgaqd(nlat, theta, wts, w, lwork, ierror)\n\n real(wp) :: cmax\n real(wp) :: cz\n real(wp) :: dcor\n real(wp) :: dpb\n real(wp) :: dthalf\n real(wp) :: dtheta\n real(wp) :: eps\n integer(ip) :: i\n integer(ip) :: idx\n integer(ip) :: ierror\n integer(ip) :: it\n integer(ip) :: itmax\n integer(ip) :: lwork\n integer(ip) :: mnlat\n integer(ip) :: nhalf\n integer(ip) :: nix\n integer(ip) :: nlat\n integer(ip) :: ns2\n real(wp) :: pb\n real(wp) :: pi\n real(wp) :: HALF_PI\n real(wp) :: sgnd\n real(wp) :: theta\n real(wp) :: w\n real(wp) :: wts\n real(wp) :: x\n real(wp) :: zero\n real(wp) :: zhold\n real(wp) :: zlast\n real(wp) :: zprev\n !\n ! February 2002\n !\n ! gauss points and weights are computed using the fourier-newton\n ! described in \"on computing the points and weights for \n ! gauss-legendre quadrature\", paul n. swarztrauber, siam journal \n ! on scientific computing that has been accepted for publication.\n ! This routine is faster and more accurate than older program\n ! with the same name.\n !\n ! subroutine sgaqd computes the nlat gaussian colatitudes and\n ! weights in single precision. the colatitudes are in radians\n ! and lie in the interval (0, pi).\n !\n ! input parameters\n !\n ! nlat the number of gaussian colatitudes in the interval (0, pi)\n ! (between the two poles). nlat must be greater than zero.\n !\n ! w unused variable that permits a simple exchange with the\n ! old routine with the same name in spherepack.\n !\n ! lwork unused variable that permits a simple exchange with the\n ! old routine with the same name in spherepack.\n !\n ! output parameters\n !\n ! theta a vector of length nlat containing the nlat gaussian\n ! colatitudes on the sphere in increasing radians\n ! in the interval (0, pi).\n !\n ! wts a vector of length nlat containing the\n ! nlat gaussian weights.\n !\n ! ierror = 0 no errors\n ! = 1 if nlat<=0\n !\n ! *****************************************************************\n !\n dimension theta(nlat), wts(nlat), w(*)\n real(wp) :: summation\n !\n ! check workspace length\n !\n ierror = 1\n if (nlat<=0) return\n ierror = 0\n !\n ! compute weights and points analytically when nlat=1, 2\n !\n if (nlat==1) then\n theta(1) = acos(0.0)\n wts(1) = 2.0\n return\n end if\n if (nlat==2) then\n x = sqrt(1.0/3.0)\n theta(1) = acos(x)\n theta(2) = acos(-x)\n wts(1) = 1.0\n wts(2) = 1.0\n return\n end if\n eps = sqrt(epsilon(1.0))\n eps = eps*sqrt(eps)\n HALF_PI = acos(0.0)\n pi = HALF_PI+HALF_PI\n mnlat = mod(nlat, 2)\n ns2 = nlat/2\n nhalf = (nlat + 1)/2\n idx = ns2+2\n !\n call lfcz (nlat, cz, theta(ns2+1), wts(ns2+1))\n !\n dtheta = HALF_PI/nhalf\n dthalf = dtheta/2.0\n cmax = .2*dtheta\n !\n ! estimate first point next to theta = pi/2\n !\n if (mnlat/=0) then\n zprev = HALF_PI\n zero = HALF_PI-dtheta\n nix = nhalf-1\n else\n zero = HALF_PI-dthalf\n nix = nhalf\n end if\n itmax = 0\n9 it = 0\n10 it = it+1\n zlast = zero\n !\n ! newton iterations\n !\n call slpdp (nlat, zero, cz, theta(ns2+1), wts(ns2+1), pb, dpb)\n dcor = pb/dpb\n sgnd = 1.0\n if (dcor /= 0.0) sgnd = dcor/abs(dcor)\n dcor = sgnd*min(abs(dcor), cmax)\n zero = zero-dcor\n if (abs(zero-zlast)>eps*abs(zero)) goto 10\n theta(nix) = zero\n zhold = zero\n ! wts(nix) = (nlat+nlat+1)/(dpb*dpb)\n !\n ! yakimiw's formula permits using old pb and dpb\n !\n wts(nix) = (nlat+nlat+1)/(dpb+pb*cos(zlast)/sin(zlast))**2\n nix = nix-1\n if (nix==0) goto 30\n if (nix==nhalf-1) zero = 3.0*zero-pi\n if (nix 0) then\n cost = cdt\n sint = sdt\n do k=1, kdo\n ! pb = pb+cp(k)*cos(2*k*theta)\n pb = pb+cp(k)*cost\n ! dpb = dpb-(k+k)*cp(k)*sin(2*k*theta)\n dpb = dpb-dcp(k)*sint\n chh = cdt*cost-sdt*sint\n sint = sdt*cost+cdt*sint\n cost = chh\n end do\n end if\n else\n !\n ! n odd\n !\n kdo = (n+1)/2\n pb = 0.0\n dpb = 0.0\n cost = cos(theta)\n sint = sin(theta)\n do k=1, kdo\n ! pb = pb+cp(k)*cos((2*k-1)*theta)\n pb = pb+cp(k)*cost\n ! dpb = dpb-(k+k-1)*cp(k)*sin((2*k-1)*theta)\n dpb = dpb-dcp(k)*sint\n chh = cdt*cost-sdt*sint\n sint = sdt*cost+cdt*sint\n cost = chh\n end do\n end if\n\n end subroutine slpdp\n\nend program test_gaussian_latitudes_and_weights_routines\n", "meta": {"hexsha": "b8672e3b423c81d370799ccf3179c88e901bd161", "size": 30565, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_gaussian_latitudes_and_weights_routines.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "test/test_gaussian_latitudes_and_weights_routines.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "test/test_gaussian_latitudes_and_weights_routines.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 29.3048897411, "max_line_length": 98, "alphanum_fraction": 0.430034353, "num_tokens": 9703, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425289753969, "lm_q2_score": 0.8289388062084421, "lm_q1q2_score": 0.7623273801073781}} {"text": "!> Test rkf45 demo1,\n!> solve a Bernoulli differential equation using rkf45:\n!> y' = y - 2*x/y\nprogram rkf45_demo1\n\n use rkf45_module, only: rkf45, rk\n\n integer, parameter :: neqn = 1\n real(rk) :: t = 0.0_rk, t_out = 0.0_rk, y(neqn)\n real(rk) :: relerr = epsilon(1.0), abserr = epsilon(1.0)\n integer :: flag = 1\n integer :: iwork(5), i, n_step = 5\n real(rk) :: work(3 + 6*neqn)\n real(rk) :: t_start = 0.0_rk, t_end = 1.0_rk\n\n print \"(A/)\", \"rkf45 demo1: solve a Bernoulli differential equation, y' = y - 2*x/y\"\n print \"(A6, *(A18))\", \"T\", \"Y\", \"Y_Exact\", \"Error\"\n\n y = 1.0\n do i = 1, n_step\n\n t = t_start + (i - 1)*(t_end - t_start)/n_step\n t_out = t_start + i*(t_end - t_start)/n_step\n call rkf45(fcn, neqn, y, t, t_out, relerr, abserr, flag, work, iwork)\n\n print \"(F6.2, 3ES18.10)\", t, y(1), fx(t), fx(t) - y(1)\n\n end do\n\ncontains\n\n !> Evaluates the derivative for the ODE\n subroutine fcn(t, y, yp)\n real(rk), intent(in) :: t\n real(rk), intent(in) :: y(:)\n real(rk), intent(out) :: yp(:)\n\n yp(1) = y(1) - 2.0_rk*t/y(1)\n\n end subroutine fcn\n\n !> Exact solution\n real(rk) function fx(t)\n real(rk), intent(in) :: t\n\n fx = sqrt(1.0_rk + 2.0_rk*t)\n\n end function fx\n\nend program rkf45_demo1\n", "meta": {"hexsha": "f500d7292ad716eb4c746240b0879a2c05da99ce", "size": 1315, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo1.f90", "max_stars_repo_name": "zoziha/rkf45", "max_stars_repo_head_hexsha": "c0e0075c9713592cfd452c318e887c08ac64ae05", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-02T09:38:31.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-02T09:38:31.000Z", "max_issues_repo_path": "example/demo1.f90", "max_issues_repo_name": "zoziha/rkf45", "max_issues_repo_head_hexsha": "c0e0075c9713592cfd452c318e887c08ac64ae05", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/demo1.f90", "max_forks_repo_name": "zoziha/rkf45", "max_forks_repo_head_hexsha": "c0e0075c9713592cfd452c318e887c08ac64ae05", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.7843137255, "max_line_length": 88, "alphanum_fraction": 0.5536121673, "num_tokens": 512, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942093072239, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7622855594002442}} {"text": " Subroutine gravity(lat,g)\r\nc calculates g as a funciton of latitude using the 1980 IUGG formula\r\nc \r\nc Bulletin Geodesique, Vol 62, No 3, 1988 (Geodesist's Handbook)\r\nc p 356, 1980 Gravity Formula (IUGG, H. Moritz)\r\nc units are in m/sec^2 and have a relative precision of 1 part\r\nc in 10^10 (0.1 microGal)\r\nc code by M. Zumberge.\r\nc\r\nc check values are:\r\nc\r\nc g = 9.780326772 at latitude 0.0\r\nc g = 9.806199203 at latitude 45.0\r\nc g = 9.832186368 at latitude 90.0\r\nc\r\n real*8 gamma, c1, c2, c3, c4, phi, lat, g\r\n \r\n gamma = 9.7803267715\r\n c1 = 0.0052790414\r\n c2 = 0.0000232718\r\n c3 = 0.0000001262\r\n c4 = 0.0000000007\r\n phi = lat * 3.14159265358979 / 180.0\r\n g = gamma * (1.0 \r\n $ + c1 * ((sin(phi))**2)\r\n $ + c2 * ((sin(phi))**4)\r\n $ + c3 * ((sin(phi))**6)\r\n $ + c4 * ((sin(phi))**8))\r\nc\r\n return\r\n end\r\n", "meta": {"hexsha": "f135cb9de44ec074b406d0833fc5e74fe19fa2b7", "size": 948, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "subroutines/gravity.f", "max_stars_repo_name": "cgentemann/posh_diurnal_model_fortran", "max_stars_repo_head_hexsha": "227fbea81016da29c3925a65fc2b3dcb5958e822", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-05T12:34:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-05T12:34:07.000Z", "max_issues_repo_path": "subroutines/gravity.f", "max_issues_repo_name": "cgentemann/posh_diurnal_model_fortran", "max_issues_repo_head_hexsha": "227fbea81016da29c3925a65fc2b3dcb5958e822", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "subroutines/gravity.f", "max_forks_repo_name": "cgentemann/posh_diurnal_model_fortran", "max_forks_repo_head_hexsha": "227fbea81016da29c3925a65fc2b3dcb5958e822", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.625, "max_line_length": 75, "alphanum_fraction": 0.5337552743, "num_tokens": 355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9674102514755852, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.7622527113048051}} {"text": " SUBROUTINE moment(data,n,ave,adev,sdev,var,skew,curt)\n!**** From Numerical Recipes\n! Given an array of DATA of length N, this routine returns its mean AVE, \n! average deviation ADEV, standard deviation SDEV, variance VAR,\n! skewness SKEW, and kurtosis CURT.\n INTEGER n\n REAL adev,ave,curt,sdev,skew,var,data(n)\n INTEGER j\n REAL p,s,ep\n\n IF(n.le.1) PRINT*,' n must be at least 2 in moment'\n s=0.\n do 11 j=1,n\n s=s+data(j)\n11 continue\n ave=s/n\n adev=0.\n var=0.\n skew=0.\n curt=0.\n ep=0.\n do 12 j=1,n\n s=data(j)-ave\n ep=ep+s\n adev=adev+abs(s)\n p=s*s\n var=var+p\n p=p*s\n skew=skew+p\n p=p*s\n curt=curt+p\n12 continue\n adev=adev/n\n var=(var-ep**2/n)/(n-1)\n sdev=sqrt(var)\n if(var.ne.0.)then\n skew=skew/(n*sdev**3)\n curt=curt/(n*var**2)-3.\n else\n PRINT*,' no skew or kurtosis when zero variance in moment'\n endif\n return\n END\n", "meta": {"hexsha": "33954542b963e18ad175bbcd91393ab9083e0b8d", "size": 1034, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "moment.f", "max_stars_repo_name": "henkart/sioseis-2020.5.0", "max_stars_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "moment.f", "max_issues_repo_name": "henkart/sioseis-2020.5.0", "max_issues_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "moment.f", "max_forks_repo_name": "henkart/sioseis-2020.5.0", "max_forks_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5, "max_line_length": 74, "alphanum_fraction": 0.5328820116, "num_tokens": 351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172630429475, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7621454761161522}} {"text": " program demo_norm2\n implicit none\n integer :: i\n\n real :: x(3,3) = reshape([ &\n 1, 2, 3, &\n 4, 5 ,6, &\n 7, 8, 9 &\n ],shape(x),order=[2,1])\n\n write(*,*) 'x='\n write(*,'(4x,3f4.0)')transpose(x)\n\n write(*,*) 'norm2(x)=',norm2(x)\n\n write(*,*) 'x**2='\n write(*,'(4x,3f4.0)')transpose(x**2)\n write(*,*)'sqrt(sum(x**2))=',sqrt(sum(x**2))\n\n end program demo_norm2\n", "meta": {"hexsha": "3f3407a9592e4eb5f2f8490698141f6739384730", "size": 412, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/norm2.f90", "max_stars_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_stars_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-12-31T17:21:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T15:56:29.000Z", "max_issues_repo_path": "example/norm2.f90", "max_issues_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_issues_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/norm2.f90", "max_forks_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_forks_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-06T15:56:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-06T15:56:31.000Z", "avg_line_length": 19.619047619, "max_line_length": 48, "alphanum_fraction": 0.4587378641, "num_tokens": 170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8652240791017536, "lm_q1q2_score": 0.7620868406689287}} {"text": " double precision function DPVAL(KORDER, NPC, XI, PC, X, IDERIV)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1994-10-20 DPVAL Krogh Changes to use M77CON\nc>> 1992-10-27 DPVAL C. L. Lawson, JPL Saving LEFTI\nc>> 1988-03-16 C. L. Lawson, JPL\nc\nc Computes value at X of the derivative of order IDERIV of a\nc piecewise polynomial given by coeffs relative to the Power basis.\nc The piecewise polynomial is specified by the arguments\nc XI, PC, NPC, KORDER.\nc The \"proper interpolation interval\" for X is from XI(1) to\nc XI(NPC+1), but extrapolation will be used outside this interval.\nc Based on subroutine PPVALU given on pp. 89-90 of\nc A PRACTICAL GUIDE TO SPLINES by Carl De Boor, Springer-Verlag,\nc 1978, however PPVALU uses the Taylor basis and this subr uses\nc the Power basis.\nc The cases of IDERIV = 0, 1, or 2 are coded individually for\nc best efficiency. The cases of 3 .le. IDERIV .lt. KORDER are\nc treated in a general way.\nc The result is zero when IDERIV .ge. KORDER.\nc ------------------------------------------------------------------\nc KORDER [in] Order of the polynomial pieces. This is one\nc greater than the degree of the pieces. KORDER is also the\nc leading dimension of the array PC(,).\nc NPC [in] Number of polynomial pieces.\nc (XI(j), j = 1, ..., NPC+1) [in] Breakpoints defining the\nc subintervals over which the polynomial pieces are defined.\nc ((PC(i,j), i = 1, ..., KORDER), j = 1, ..., NPC) [in]\nc PC(*,j) contains the coefficients to be used to evaluate\nc the polynomial piece between XI(j) and XI(j+1).\nc PC(i,j) is the coefficient to be multiplied times\nc (X - X(j))**(i-1).\nc X [in] Abcissa at which function is to be evaluated.\nc IDERIV [in] Order of derivative to be evaluated.\nc Require IDERIV .ge. 0. IDERIV = 0 means to evaluate the\nc function itself. Derivatives of order .ge. KORDER will\nc be zero.\nc DPVAL [out] The computed value or derivative value.\nc ------------------------------------------------------------------\nc--D replaces \"?\": ?PVAL, ?SFIND\nc ------------------------------------------------------------------\n integer I, IDERIV, LEFTI, KORDER, MODE, NPC\n double precision DX, FAC, FAC1, FAC2\n double precision ONE, X, XI(NPC+1), PC(KORDER,NPC), VAL, ZERO\n parameter(ONE=1.0D0, ZERO=0.0D0)\n save LEFTI\n data LEFTI / 1/\nc ------------------------------------------------------------------\n call DSFIND ( XI, 1, NPC+1, X, LEFTI, MODE )\n DX = X - XI(LEFTI)\n\n if(IDERIV .eq. 0) then\n VAL = PC(KORDER,LEFTI)\n do 10 I = KORDER-1, 1, -1\n VAL = VAL * DX + PC(I,LEFTI)\n 10 continue\n elseif(IDERIV .eq. 1) then\n FAC1 = dble(KORDER-1)\n VAL = FAC1 * PC(KORDER,LEFTI)\n do 20 I = KORDER-1, 2, -1\n FAC1 = FAC1 - ONE\n VAL = VAL * DX + FAC1 * PC(I,LEFTI)\n 20 continue\n elseif(IDERIV .eq. 2) then\n FAC1 = dble(KORDER-1)\n FAC2 = FAC1 - ONE\n VAL = FAC1 * FAC2 * PC(KORDER,LEFTI)\n do 30 I = KORDER-1, 3, -1\n FAC1 = FAC2\n FAC2 = FAC2 - ONE\n VAL = VAL * DX + FAC1 * FAC2 * PC(I,LEFTI)\n 30 continue\n elseif(IDERIV .ge. KORDER) then\n VAL = ZERO\n else\nc Here when 3 .le. IDERIV .lt. KORDER\nc\n FAC1 = dble(KORDER-1)\n FAC2 = FAC1\n FAC = FAC1\n do 40 I = 2, IDERIV\n FAC2 = FAC2 - ONE\n FAC = FAC * FAC2\n 40 continue\n VAL = FAC * PC(KORDER,LEFTI)\n do 60 I = KORDER-1, IDERIV+1, -1\n FAC2 = FAC2 - ONE\n FAC = (FAC / FAC1) * FAC2\n FAC1 = FAC1 - ONE\n VAL = VAL * DX + FAC * PC(I,LEFTI)\n 60 continue\n endif\n DPVAL = VAL\n return\n end\n", "meta": {"hexsha": "627feff88319bf8e4421ba0b0ca049a0fe0dbb68", "size": 4077, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dpval.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/dpval.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/dpval.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 41.6020408163, "max_line_length": 72, "alphanum_fraction": 0.5408388521, "num_tokens": 1232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037784, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.7620419941002541}} {"text": "! Exercise 2, p. 68\n!\n! Calculating the temperature due to cold front passage\n\nprogram ex_2\n\n use iso_fortran_env, only: real32, int32, output_unit\n\n implicit none\n\n real(real32), parameter :: temp1 = 12. ! temperature in Atlanta (°C)\n real(real32), parameter :: temp2 = 24. ! temperature in Miami (°C)\n\n real(real32), parameter :: dx = 960. ! distance between Atlanta & Miami (km)\n real(real32), parameter :: c = 20. ! speed in km/h\n\n real(real32), parameter :: dt = 1. ! time increment (h)\n\n real(real32), dimension(8) :: timestamps = [6, 12, 18, 24, 30, 36, 42, 48]\n real(real32), dimension(8) :: result\n\n integer(int32) :: i\n\n ! update temperature in Miami\n result = update_temp(temp1, temp2, c, dx, timestamps)\n\n ! print result to screen\n do i = 1, 8\n write(output_unit, *) \"Temperature after\", timestamps(i), \" hours is\" , result(i), \"degrees.\"\n end do\n\n contains\n\n real(real32) pure elemental function update_temp(temp1, temp2, c, dx, dt)\n real(real32), intent(in) :: temp1, temp2, c, dx, dt\n\n update_temp = temp2 - c * (temp2 - temp1) / dx * dt\n end function update_temp\n \n\nend program ex_2\n", "meta": {"hexsha": "b3615f7acca5cf9b67fd5ee28ab22653e530421b", "size": 1216, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/ModernFortran/exercises/ex_3.f95", "max_stars_repo_name": "kkirstein/proglang-playground", "max_stars_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fortran/ModernFortran/exercises/ex_3.f95", "max_issues_repo_name": "kkirstein/proglang-playground", "max_issues_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran/ModernFortran/exercises/ex_3.f95", "max_forks_repo_name": "kkirstein/proglang-playground", "max_forks_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.9523809524, "max_line_length": 101, "alphanum_fraction": 0.6118421053, "num_tokens": 359, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012701768145, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7619679410131215}} {"text": " program atmos_gaussian\n implicit none\nc\nc --- Usage: echo JH | atmos_gaussian\nc --- print the 2*JH latitudes of the specified gaussian grid\nc\nc --- A \"Gaussian\" grid, is regular in longitude and\nc --- almost regular in latitude (Hortal and Simmons, 1991). \nc --- https://en.wikipedia.org/wiki/Gaussian_grid\nc\n integer :: jh,j\n real*8 :: pscale\n real*4, allocatable :: plat(:)\n real*8, allocatable :: slat(:)\nc\n read(5,*) jh\nc\n allocate( plat(2*jh) )\n allocate( slat( jh) )\nc\n call glat8(jh,slat)\n pscale = 180.d0/acos(-1.d0)\n do j= 1,jh\n plat(2*jh+1-j) = pscale*asin(slat(j))\n plat( j) = -plat(2*jh+1-j)\n enddo !j\n do j= 1,2*jh\n write(6,'(f10.5)') plat(j)\n enddo\n end\n SUBROUTINE GLAT8(JH,SLAT)\n IMPLICIT NONE\nC\n INTEGER JH\n REAL*8 SLAT(JH)\nC\nC$$$ SUBPROGRAM DOCUMENTATION BLOCK\nC\nC SUBPROGRAM: GLAT COMPUTE GAUSSIAN LATITUDE FUNCTIONS\nC PRGMMR: IREDELL ORG: W/NMC23 DATE: 92-10-31\nC\nC ABSTRACT: COMPUTES SINES OF GAUSSIAN LATITUDE BY ITERATION.\nC\nC PROGRAM HISTORY LOG:\nC 91-10-31 MARK IREDELL\nC\nC USAGE: CALL GLAT(JH,SLAT)\nC\nC INPUT ARGUMENT LIST:\nC JH - INTEGER NUMBER OF GAUSSIAN LATITUDES IN A HEMISPHERE\nC\nC OUTPUT ARGUMENT LIST:\nC SLAT - REAL (JH) SINES OF (POSITIVE) GAUSSIAN LATITUDE\nC\nC ATTRIBUTES:\nC LANGUAGE: CRAY FORTRAN\nC\nC$$$\nC\n INTEGER JBZ\n PARAMETER(JBZ=50)\n REAL*8 PI,C,EPS\n PARAMETER(PI=3.14159265358979,C=(1.-(2./PI)**2)*0.25,EPS=1.E-14)\nC\n INTEGER ITS,J,N\n REAL*8 PKM2,R,SP,SPMAX\n REAL*8 PK(JH),PKM1(JH)\nC\n REAL*8 BZ(JBZ)\n DATA BZ / 2.4048255577, 5.5200781103,\n $ 8.6537279129, 11.7915344391, 14.9309177086, 18.0710639679,\n $ 21.2116366299, 24.3524715308, 27.4934791320, 30.6346064684,\n $ 33.7758202136, 36.9170983537, 40.0584257646, 43.1997917132,\n $ 46.3411883717, 49.4826098974, 52.6240518411, 55.7655107550,\n $ 58.9069839261, 62.0484691902, 65.1899648002, 68.3314693299,\n $ 71.4729816036, 74.6145006437, 77.7560256304, 80.8975558711,\n $ 84.0390907769, 87.1806298436, 90.3221726372, 93.4637187819,\n $ 96.6052679510, 99.7468198587, 102.888374254, 106.029930916,\n $ 109.171489649, 112.313050280, 115.454612653, 118.596176630,\n $ 121.737742088, 124.879308913, 128.020877005, 131.162446275,\n $ 134.304016638, 137.445588020, 140.587160352, 143.728733573,\n $ 146.870307625, 150.011882457, 153.153458019, 156.295034268 /\nC - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nC ESTIMATE LATITUDES USING BESSEL FUNCTION\n R=1./SQRT((2*JH+0.5)**2+C)\n DO J=1,MIN(JH,JBZ)\n SLAT(J)=COS(BZ(J)*R)\n ENDDO\n DO J=JBZ+1,JH\n SLAT(J)=COS((BZ(JBZ)+(J-JBZ)*PI)*R)\n ENDDO\nC - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nC CONVERGE UNTIL ALL SINES OF GAUSSIAN LATITUDE ARE WITHIN EPS\n DO 110 ITS= 1,999\n SPMAX=0.\n DO J=1,JH\n PKM1(J)=1.\n PK(J)=SLAT(J)\n ENDDO\n DO N=2,2*JH\n DO J=1,JH\n PKM2=PKM1(J)\n PKM1(J)=PK(J)\n PK(J)=((2*N-1)*SLAT(J)*PKM1(J)-(N-1)*PKM2)/N\n ENDDO\n ENDDO\n DO J=1,JH\n SP=PK(J)*(1.-SLAT(J)**2)/(2*JH*(PKM1(J)-SLAT(J)*PK(J)))\n SLAT(J)=SLAT(J)-SP\n SPMAX=MAX(SPMAX,ABS(SP))\n ENDDO\n IF (SPMAX.LE.EPS) THEN\n GOTO 1110\n ENDIF\n 110 CONTINUE\n 1110 CONTINUE\n RETURN\nC END OF GLAT8.\n END\n", "meta": {"hexsha": "1c09f9142b4314680dadb5a76a10e860857235e0", "size": 3595, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "bin/atmos_gaussian.f", "max_stars_repo_name": "TillRasmussen/HYCOM-tools", "max_stars_repo_head_hexsha": "7d26b60ce65ac9d785e0e36add36aca05c0f496d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2019-05-31T02:47:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T19:21:04.000Z", "max_issues_repo_path": "bin/atmos_gaussian.f", "max_issues_repo_name": "TillRasmussen/HYCOM-tools", "max_issues_repo_head_hexsha": "7d26b60ce65ac9d785e0e36add36aca05c0f496d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2019-09-27T08:20:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-18T16:50:53.000Z", "max_forks_repo_path": "bin/atmos_gaussian.f", "max_forks_repo_name": "TillRasmussen/HYCOM-tools", "max_forks_repo_head_hexsha": "7d26b60ce65ac9d785e0e36add36aca05c0f496d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-03-21T08:43:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T08:08:56.000Z", "avg_line_length": 29.9583333333, "max_line_length": 71, "alphanum_fraction": 0.564394993, "num_tokens": 1485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002492, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7619197476787241}} {"text": "! contain math_mod\n ! mod_pow(b,exp,m)\n ! solve:: ret = mod( b**exp, m )繰り返し二乗法で高速化\n ! input:: b, exp, m\n ! output:: ret\n ! mod_inv(a,m)\n ! solve:: mod(ax, m) = 1\n ! => ax + my = 1\n ! input:: a,m\n ! output:: x <- inverse of a at mod m\n ! lcm(a,b)\n ! solve:: ret = lcm(a,b)\n ! input:: a, b\n ! output:: ret\n ! gcd(a,b)\n ! solve:: ret = gcd(a,b)\n ! input:: a, b\n ! output:: ret\n ! extgcd(a,b,x,y)\n ! solve:: ax + by = gcd(a,b) (拡張ユークリッドの互除法)\n ! input:: a, b\n ! output:: x, y, gcd(a,b)\n ! chineserem(b,m,md) \n ! solve:: mod(b_1*k_1, m_1) = x (-> b_1の倍数をm_1で割ったあまりがx)\n ! :\n ! mod(b_n*k_n, m_n) = x を満たす最小のx\n ! input:: b(1:n), m(1:n)\n ! output:: x (< md)\n! combination_mod\n ! make_fraction(n,md)\n ! solve:: generate frac, ifrac (frac(i) = i! % md, ifrac(i) = mod_inv(i!))\n ! input:: n, md\n ! output:: none\n ! perm(n,p,md)\n ! solve:: ret = nPp % md (n個のものをp個選んで並べる並べ方。をmdで割った値)\n ! input:: n, p, md\n ! output:: ret\n ! comb(n,p,md)\n ! solve:: ret = nCp % md (n個のものをp個選ぶ選び方。をmdで割った値)\n ! input:: n, p, md\n ! output:: ret\n\n\n\n\n\nmodule math_mod\n use,intrinsic :: iso_fortran_env\n implicit none\ncontains\n function mod_pow(base, exponent, m) result(ret)\n integer(int64),intent(in):: m\n integer(int64),value:: base, exponent\n integer(int64):: ret\n\n ret = 1\n do while(exponent > 0)\n if (btest(exponent, 0)) ret=mod(ret*base,m)\n base=mod(base*base,m)\n exponent=shiftr(exponent,1)\n end do\n end function\n\n\n recursive function mod_inv(a,m) result(ret)\n integer(int64),intent(in):: a,m\n integer(int64):: ret, gcd_ma, x, y\n\n gcd_ma = extgcd(a,m,x,y)\n \n if (gcd_ma /= 1_int64) then\n ret = -1_int64\n else\n ret = modulo(x,m)\n end if\n end function\n\n\n function lcm(a, b) result(ret)\n integer(int64),intent(in):: a,b\n integer(int64):: ret\n\n ret = a*b/gcd(a,b)\n end function\n\n\n recursive function gcd(a, b) result(ret)\n integer(int64),intent(in):: a,b\n integer(int64):: ret\n\n if (b == 0_int64) then\n ret = a\n else\n ret = gcd(b, mod(a,b))\n end if\n end function\n\n\n recursive function extgcd(a, b, x, y) result(ret)\n integer(int64),value:: a,b\n integer(int64),intent(out):: x,y\n integer(int64):: ret ! gcd(a,b)\n\n if (b==0_int64) then\n ret = a\n x = 1_int64\n y = 0_int64\n else\n ret = extgcd(b, mod(a,b), y, x)\n y = y - a/b * x\n end if\n end function\n\n\n function chineserem(b, m, md) result(ret)\n integer(int64),allocatable:: b(:),m(:)\n integer(int64):: md\n integer(int64),allocatable:: x0(:), mmul(:)\n integer(int64):: ret, i, j, g, gi, gj\n integer(int64):: t\n\n do i=1_int64,size(b)\n do j=1_int64, i-1_int64\n g = gcd(m(i),m(j))\n if (mod(b(i)-b(j), g) /= 0_int64) then\n ret = -1_int64\n return\n end if\n m(i) = m(i) / g\n m(j) = m(j) / g\n gi = gcd(m(i),g)\n gj = g/gi\n do while(g /= 1)\n g = gcd(gi,gj)\n gi = gi*g\n gj = gj/g\n end do\n m(i) = m(i)*gi\n m(j) = m(j)*gj\n b(i) = mod(b(i), m(i))\n b(j) = mod(b(j), m(j))\n end do\n end do\n\n m = [m,md]\n allocate(x0(size(m)), source=0_int64)\n allocate(mmul(size(m)), source=1_int64)\n\n do i=1_int64,size(b)\n t = modulo((b(i)-x0(i)) * mod_inv(mmul(i), m(i)), m(i))\n do j=i+1,size(m)\n x0(j) = modulo(x0(j) + t * mmul(j), m(j))\n mmul(j) = modulo(mmul(j)*m(i), m(j))\n end do\n end do\n ret = modulo(x0(size(x0)), md)\n end function\nend module\n\n\nmodule combination_mod\n use,intrinsic :: iso_fortran_env\n use math_mod\n implicit none\n public\n integer(int64), allocatable, private:: frac(:), ifrac(:)\ncontains\n subroutine make_fraction(n,md)\n integer(int64),intent(in):: n, md\n integer(int64):: i\n\n allocate(frac(0:n), ifrac(0:n))\n frac(0) = 1; ifrac(0) = 1\n do i=1,n\n frac(i) = mod(frac(i-1)*i, md)\n ifrac(i) = mod_inv(frac(i),md)\n end do\n end subroutine\n\n\n function perm(n,p,md) result(ret)\n integer(int64),intent(in):: n,p,md\n integer(int64):: ret\n \n ret = mod(frac(n)*ifrac(n-p), md)\n end function\n\n \n function comb(n,p,md) result(ret)\n integer(int64),intent(in):: n,p,md\n integer(int64):: ret\n \n ret = mod(mod(frac(n)*ifrac(p),md)*ifrac(n-p),md)\n end function\nend module\n\n\nmodule algorithm_mod \n use math_mod\n use combination_mod\n implicit none\nend module", "meta": {"hexsha": "02d540c1f5a229a5151abe7d4051354b51b78ac7", "size": 5198, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/algorithm.f90", "max_stars_repo_name": "ohtorilab/fortran_lib", "max_stars_repo_head_hexsha": "e3551a0730a91f79e8e09796f147f761b2df6fc1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-03T16:05:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-03T16:05:57.000Z", "max_issues_repo_path": "src/algorithm.f90", "max_issues_repo_name": "ohtorilab/fortran_lib", "max_issues_repo_head_hexsha": "e3551a0730a91f79e8e09796f147f761b2df6fc1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-18T11:40:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-18T11:40:03.000Z", "max_forks_repo_path": "src/algorithm.f90", "max_forks_repo_name": "ohtorilab/fortran_lib", "max_forks_repo_head_hexsha": "e3551a0730a91f79e8e09796f147f761b2df6fc1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-12T01:06:14.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-12T01:06:14.000Z", "avg_line_length": 25.7326732673, "max_line_length": 82, "alphanum_fraction": 0.4680646402, "num_tokens": 1654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.963779943094681, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7618972655420791}} {"text": "! test_diff.f90 --\n! Test (not exhausitvely, alas) the module for automatic\n! differentation\n!\n! Define a non-trivial function and show that we can\n! evaluate both the value and the first derivative without having to\n! go through mathematics ourselves.\n!\n! Also find a root of some equation via Newton-Raphson\n!\n\nmodule find_a_root\n use automatic_differentiation\n\ncontains\n!\n! g may not be an internal routine, hence the module\n!\ntype(AUTODERIV) function g( x )\n type(AUTODERIV), intent(in) :: x\n\n g = x ** 2 - 2.0\nend function g\n\nend module\n\nprogram test_diff\n use automatic_differentiation\n use find_a_root\n\n implicit none\n\n type(AUTODERIV) :: x, root\n integer :: i\n logical :: found\n\n do i = 1,20\n x = derivvar( 0.2 * (i-1) )\n write( *, * ) f(x), df(x%v)\n enddo\n\n x = derivvar( 3.0 )\n call find_root( g, x, 1.0e-6_wp, root, found )\n write(*,*) 'Equation: x**2 - 2 = 0'\n write(*,*) 'Root: ', root%v, ' - expected: ', sqrt(2.0_wp)\n\n write(*,*) 'Elementary functions: '\n x = derivvar(0.0)\n write(*,*) 'x = ', x\n write(*,*) 'exp(x) = ', exp(x)\n write(*,*) 'sin(x) = ', sin(x)\n write(*,*) 'asin(x) = ', asin(x)\n write(*,*) 'sinh(x) = ', sinh(x)\n write(*,*) 'cos(x) = ', cos(x)\n write(*,*) 'acos(x) = ', acos(x)\n write(*,*) 'cosh(x) = ', cosh(x)\n write(*,*) 'tan(x) = ', tan(x)\n write(*,*) 'atan(x) = ', atan(x)\n write(*,*) 'tanh(x) = ', tanh(x)\n\n x = derivvar(1.0)\n write(*,*) 'x = ', x\n write(*,*) 'log(x) = ', log(x)\n write(*,*) 'exp(x) = ', exp(x)\n\ncontains\n!\n! The AUTODERIV function and a function that implements the\n! first derivative directly.\n!\ntype(AUTODERIV) function f( x )\n type(AUTODERIV), intent(in) :: x\n\n f = x ** 3 + 2.0 * x ** 2 - x + 3.0\nend function f\n\nreal(wp) function df( x )\n real(wp) :: x\n\n df = 3.0 * x ** 2 + 4.0 * x - 1.0\nend function df\n\nend program\n\n\n", "meta": {"hexsha": "fdb0b75885730a34283c88826461e9868100659f", "size": 1954, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/computing/test_diff.f90", "max_stars_repo_name": "timcera/flibs_from_svn", "max_stars_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 828, "max_stars_repo_stars_event_min_datetime": "2016-06-20T15:08:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:32:10.000Z", "max_issues_repo_path": "flibs-0.9/flibs/tests/computing/test_diff.f90", "max_issues_repo_name": "TerribleDev/Fortran-docker-mvc", "max_issues_repo_head_hexsha": "0f44d444d9bcc6f4a6c6c59cc53b684c7b9a8e1a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2016-06-27T05:52:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-29T20:08:05.000Z", "max_forks_repo_path": "flibs-0.9/flibs/tests/computing/test_diff.f90", "max_forks_repo_name": "TerribleDev/Fortran-docker-mvc", "max_forks_repo_head_hexsha": "0f44d444d9bcc6f4a6c6c59cc53b684c7b9a8e1a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2016-06-21T02:15:50.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T06:32:39.000Z", "avg_line_length": 22.7209302326, "max_line_length": 72, "alphanum_fraction": 0.5470829069, "num_tokens": 683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297834483234, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7617963651256061}} {"text": "! Name = ARPIT KUMAR JAIN ROLL No = 180122009\n! Code for Question 1 Radial Schrodinger Equation --> Second Order ODEs (R\" = -2R'/d - 2ER - 2R/d)\n\nMODULE precision\n IMPLICIT NONE\n\n ! dp = double precisiona\n INTEGER, PARAMETER:: dp = SELECTED_REAL_KIND(12)\nEND MODULE precision\n\n! h --> step size = 0.0005\nMODULE constants\n USE precision\n IMPLICIT NONE\n \n REAL(KIND = dp):: h = 0.0005\n REAL(KIND = dp):: dinitial = 0.0005, Rinitial = 0.000001, vinitial = -1000.0\nEND MODULE constants\n\nPROGRAM Radial_Schrodinger_Equation\n USE precision\n USE constants\n IMPLICIT NONE\n \n ! d --> Distance from center ==> basically small r (radius)\n ! R0 --> value at starting point\n ! v0 --> value of R' at starting point\n ! Enrg --> Energy\n ! R1 --> new value of R\n ! v1 --> new value of v\n REAL(KIND = dp):: d, R0, v0, Enrg, R1, v1\n\n ! i --> iterator,, Nt --> number of iteration or Grid Points\n INTEGER:: i, j, Nt\n\n Nt = 10000\n Enrg = -0.52_dp ! Initial value of energy\n\n ! ****************Propagating Runge-Kutta 4 Method Solution*******************\n\n ! Take energy from -0.52 to -0.48 ==> 5 energy levels with ΔE = 0.01\n OPEN(UNIT = 21, FILE = 'E-0.52.txt')\n OPEN(UNIT = 22, FILE = 'E-0.51.txt')\n OPEN(UNIT = 23, FILE = 'E-0.50.txt')\n OPEN(UNIT = 24, FILE = 'E-0.49.txt')\n OPEN(UNIT = 25, FILE = 'E-0.48.txt')\n DO j = 1, 5\n d = dinitial\n R0 = Rinitial\n v0 = vinitial\n DO i = 1, Nt\n CALL RK4_Method(d, R0, v0, R1, v1, Enrg)\n WRITE(20+j, 5) d, R1, abs(d*R1)**2.0_dp\n 5 FORMAT(f9.6, 3x, f9.6, 3x, f9.6)\n \n ! Update values for next itration\n R0 = R1\n v0 = v1\n d = d + h\n ENDDO\n Enrg = Enrg + 0.01_dp\n ENDDO\n CLOSE(21)\n CLOSE(22)\n CLOSE(23)\n CLOSE(24)\n CLOSE(25)\n\n CONTAINS\n SUBROUTINE RK4_Method(d, R0, v0, R1, v1, Enrg)\n USE precision\n USE constants\n IMPLICIT NONE\n\n REAL(KIND = dp):: d, R0, v0, R1, v1, Enrg\n REAL(KIND = dp):: s1R, s2R, s3R, s4R, s1v, s2v, s3v, s4v\n\n s1R = h * dR_by_dd(d, R0, v0)\n s1v = h * dv_by_dd(d, R0, v0, Enrg)\n\n s2R = h * dR_by_dd(d + h/2.0_dp, R0 + s1R/2.0_dp, v0 + s1v/2.0_dp)\n s2v = h * dv_by_dd(d + h/2.0_dp, R0 + s1R/2.0_dp, v0 + s1v/2.0_dp, Enrg)\n\n s3R = h * dR_by_dd(d + h/2.0_dp, R0 + s2R/2.0_dp, v0 + s2v/2.0_dp)\n s3v = h * dv_by_dd(d + h/2.0_dp, R0 + s2R/2.0_dp, v0 + s2v/2.0_dp, Enrg)\n\n s4R = h * dR_by_dd(d + h, R0 + s3R, v0 + s3v)\n s4v = h * dv_by_dd(d + h, R0 + s3R, v0 + s3v, Enrg)\n\n R1 = R0 + (s1R + 2.0_dp * s2R + 2.0_dp * s3R + s4R)/6.0_dp\n v1 = v0 + (s1v + 2.0_dp * s2v + 2.0_dp * s3v + s4v)/6.0_dp\n END SUBROUTINE RK4_Method\n\n FUNCTION dR_by_dd(d, R, v)\n IMPLICIT NONE\n\n REAL(KIND = dp):: dR_by_dd, d, R, v\n\n ! No change in d and R\n d = d\n R = R\n\n ! R' = v\n dR_by_dd = v\n RETURN\n END FUNCTION dR_by_dd\n\n FUNCTION dv_by_dd(d, R, v, Enrg)\n IMPLICIT NONE\n\n REAL(KIND = dp):: dv_by_dd, d, R, v, Enrg\n\n ! v' = -2v/d - 2ER - 2R/d\n dv_by_dd = (-2.0_dp*v)/d - 2.0_dp * Enrg * R - 2.0_dp*R/d\n RETURN\n END FUNCTION dv_by_dd\n\nEND PROGRAM Radial_Schrodinger_Equation\n", "meta": {"hexsha": "a4252c025738d48d62ae459b262d372cdcb07954", "size": 3342, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "7. HA7 - ODEs/Arpit_Q1.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "7. HA7 - ODEs/Arpit_Q1.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "7. HA7 - ODEs/Arpit_Q1.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 28.0840336134, "max_line_length": 98, "alphanum_fraction": 0.5320167564, "num_tokens": 1325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.7617963646161114}} {"text": "MODULE trend_line\nIMPLICIT NONE\nREAL :: x_sum = 0., x2_sum = 0., x3_sum = 0., x4_sum = 0., y_sum = 0., &\n xy_sum = 0., x2y_sum = 0.\nCONTAINS\n SUBROUTINE cumul_trend_sums(x, y)\n IMPLICIT NONE\n REAL, INTENT(IN) :: x, y\n x_sum = x_sum + x\n x2_sum = x2_sum + x**2\n x3_sum = x3_sum + x**3\n x4_sum = x4_sum + x**4\n y_sum = y_sum + y\n xy_sum = xy_sum + x * y\n x2y_sum = x2y_sum + y * x**2\n END SUBROUTINE cumul_trend_sums\n\n SUBROUTINE build_matrix(n, a, b)\n REAL, DIMENSION(3,3), INTENT(OUT) :: a\n REAL, DIMENSION(3), INTENT(OUT) :: b\n INTEGER, INTENT(IN) :: n\n a(1,1) = REAL(n)\n a(1,2) = x_sum\n a(1,3) = x2_sum\n a(2,1) = x_sum\n a(2,2) = x2_sum\n a(2,3) = x3_sum\n a(3,1) = x2_sum\n a(3,2) = x3_sum\n a(3,3) = x4_sum\n\n b(1) = y_sum\n b(2) = xy_sum\n b(3) = x2y_sum\n END SUBROUTINE build_matrix\n\nEND MODULE trend_line\n\nSUBROUTINE simul(a, b, ndim, n, error)\nIMPLICIT NONE\nINTEGER, INTENT(IN) :: ndim\nREAL, INTENT(INOUT), DIMENSION(ndim, ndim) :: a\nREAL, INTENT(INOUT), DIMENSION(ndim) :: b\nINTEGER, INTENT(IN) :: n\nINTEGER, INTENT(OUT) :: error\nREAL, PARAMETER :: EPSILON = 1.0E-6\nREAL :: factor, temp\nINTEGER :: irow, ipeak, jrow, kcol\n\n! Process n times to get all equations...\nmainloop: DO irow = 1, n\n ! Find peak pivot for column irow in rows irow to n\n ipeak = irow\n max_pivot: DO jrow = irow + 1, n\n IF (ABS(a(jrow,irow)) > ABS(a(ipeak,irow))) THEN\n ipeak = jrow\n END IF\n END DO max_pivot\n\n ! Check for singular equations.\n singular: IF(ABS(a(ipeak,irow)) < EPSILON) THEN\n error = 1\n RETURN\n END IF singular\n\n ! Otherwise, if ipeak /= irow, swap equations irow & ipeak\n swap_eqn: IF (ipeak /= irow) THEN\n DO kcol = 1, n\n temp = a(ipeak, kcol)\n a(ipeak, kcol) = a(irow, kcol)\n a(irow, kcol) = temp\n END DO\n temp = b(ipeak)\n b(ipeak) = b(irow)\n b(irow) = temp\n END IF swap_eqn\n\n ! Multiply equation irow by -a(jrow, irow)/a(irow, irow)\n ! and add it to eqn jrow (for all eqns except irow itself).\n eliminate: DO jrow = 1, n\n IF (jrow /= irow) THEN\n factor = -a(jrow, irow) / a(irow, irow)\n DO kcol = 1, n\n a(jrow, kcol) = a(irow, kcol) * factor + a(jrow, kcol)\n END DO\n b(jrow) = b(irow) * factor + b(jrow)\n END IF\n END DO eliminate\nEND DO mainloop\n\ndivide: DO irow = 1, n\n b(irow) = b(irow) / a(irow, irow)\n a(irow, irow) = 1\nEND DO divide\n\n! Set error flag to 0 and return\nerror = 0\nEND SUBROUTINE simul\n\nPROGRAM least_squares_2nd_ord\nUSE trend_line\nIMPLICIT NONE\nINTEGER, PARAMETER :: MAX_SIZE = 1000\nREAL, DIMENSION(3, 3) :: a\nREAL, DIMENSION(3) :: b\nREAL :: x, y\nINTEGER :: error\nCHARACTER(len=20) :: file_name\nINTEGER :: i, j, n, istat\nCHARACTER(len=80) :: msg\n\nWRITE(*, \"('Enter the file name containing the data:')\")\nREAD(*, '(A20)') file_name\n\n! Open input data file. Status is OLD because the input data must\n! already exist.\nOPEN (UNIT=1, FILE=file_name, STATUS='OLD', ACTION='READ', &\n IOSTAT=istat, IOMSG=msg)\n\n! Was the OPEN successful?\nfileopen: IF(istat == 0) THEN\n ! The file was opened successfully, so read the number of\n ! measurements in the file.\n READ(1, *) n\n ! If the number of equ is <= MAX_SIZE, read them in\n ! and process them.\n size_ok: IF (n <= MAX_SIZE) THEN\n DO i = 1, n\n x = 0.\n y = 0.\n READ(1, *) x, y\n CALL cumul_trend_sums(x, y)\n END DO\n CALL build_matrix(n, a, b)\n ! Display coefficients.\n WRITE(*, \"(/,'Coefficients before call:')\")\n DO i = 1, 3\n WRITE(*, \"(1X,7F11.4)\") (a(i, j), j = 1, 3), b(i)\n END DO\n\n ! Solve equations\n CALL simul(a, b, 3, 3, error)\n\n ! Check for error.\n error_check: IF (error /= 0) THEN\n WRITE(*, 1010)\n 1010 FORMAT(/'Zero pivot encountered!', &\n //'There is no unique solution to this system.')\n ELSE error_check\n ! No errors. Display coefficients.\n WRITE(*, \"(/,'Coefficients after call:')\")\n DO i = 1, 3\n WRITE(*, \"(1X,7F11.4)\") (a(i, j), j = 1, 3), b(i)\n END DO\n ! Write the final answer.\n WRITE(*, \"(/,'The solutions are:')\")\n DO i = 1, 3\n WRITE(*,\"(2X,'X(',I2,') = ',F16.6)\") i, b(i)\n END DO\n END IF error_check\n END IF size_ok\nELSE fileopen\n ! Else file open failed. Tell user.\n WRITE(*, 1020) msg\n 1020 FORMAT('File open failed: ', A)\nEND IF fileopen\n\nEND PROGRAM least_squares_2nd_ord\n", "meta": {"hexsha": "6b44ddab22eb3d1ed592667031c042e76b2e2378", "size": 4364, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap9/least_squares_2nd_ord.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap9/least_squares_2nd_ord.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap9/least_squares_2nd_ord.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.8224852071, "max_line_length": 72, "alphanum_fraction": 0.6008249313, "num_tokens": 1631, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396142, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.761796351355469}} {"text": "! Sets up integration points for\n! Gaussian quadrature using Laguerre polynomials\nSUBROUTINE gauss_laguerre(x,w,n,alf)\n IMPLICIT NONE\n INTEGER :: MAXIT\n INTEGER, INTENT(IN) :: n\n REAL(KIND=8) :: EPS\n REAL(KIND=8), INTENT(IN) :: alf\n REAL(KIND=8), INTENT(INOUT) :: w(n),x(n)\n INTEGER :: i,its,j\n REAL(KIND=8) :: ai,gammln, nn\n REAL(KIND=8) :: p1,p2,p3,pp,z,z1\n\n maxit = 10; eps = 3.E-14\n nn = n\n DO i=1,n\n IF(i == 1)THEN\n z=(1.+alf)*(3.+.92*alf)/(1.+2.4*n+1.8*alf)\n ELSE IF(i == 2)THEN\n z=z+(15.+6.25*alf)/(1.+9.0*alf+2.5*n)\n ELSE\n ai=i-2\n z=z+((1.+2.55*ai)/(1.9*ai)+1.26*ai*alf/(1.+3.5*ai))* &\n (z-x(i-2))/(1.+.3*alf)\n ENDIF\n DO its=1,MAXIT\n p1=1.d0\n p2=0.d0\n DO j=1,n\n p3=p2\n p2=p1\n p1=((2*j-1+alf-z)*p2-(j-1+alf)*p3)/j\n ENDDO\n pp=(n*p1-(n+alf)*p2)/z\n z1=z\n z=z1-p1/pp\n IF(ABS(z-z1) <= eps) GOTO 1\n ENDDO\n PAUSE 'too many iterations in gaulag'\n1 x(i)=z\n w(i)=-EXP(gammln(alf+nn)-gammln(nn))/(pp*n*p2)\n write(*,*) x(i), w(i)\n ENDDO\n\nEND SUBROUTINE gauss_laguerre\n\n\nREAL(KIND =8) FUNCTION gammln(xx)\n REAL(KIND=8), INTENT(IN) :: xx\n INTEGER :: j\n REAL(KIND=8) :: ser,tmp,x,y\n REAL(KIND=8), DIMENSION(6) :: cof(6)\n cof(1)=76.18009172947146; cof(2)=-86.50532032941677 \n cof(3)=24.01409824083091; cof(4)=-1.231739572450155\n cof(5)= .1208650973866179E-2; cof(6) = -.5395239384953E-5\n x=xx\n y=x\n tmp=x+5.5\n tmp=(x+0.5)*LOG(tmp)-tmp\n ser=1.000000000190015\n DO j=1,6\n y=y+1.0\n ser=ser+cof(j)/y\n ENDDO\n gammln = tmp+LOG(2.5066282746310005*ser/x)\n\nEND FUNCTION gammln\n\n", "meta": {"hexsha": "9deb639f4e4fd20d946e20560b95bb576bff97bb", "size": 1660, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/Projects/2015/Project3/gauss-laguerre.f90", "max_stars_repo_name": "kimrojas/ComputationalPhysicsMSU", "max_stars_repo_head_hexsha": "a47cfc18b3ad6adb23045b3f49fab18c0333f556", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 220, "max_stars_repo_stars_event_min_datetime": "2016-08-25T09:18:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T14:09:16.000Z", "max_issues_repo_path": "doc/Projects/2015/Project3/gauss-laguerre.f90", "max_issues_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_issues_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-04T12:55:10.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-04T12:55:10.000Z", "max_forks_repo_path": "doc/Projects/2015/Project3/gauss-laguerre.f90", "max_forks_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_forks_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 136, "max_forks_repo_forks_event_min_datetime": "2016-08-25T09:04:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T09:54:21.000Z", "avg_line_length": 24.0579710145, "max_line_length": 62, "alphanum_fraction": 0.5487951807, "num_tokens": 745, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7617799481629681}} {"text": "! This routine calculates if there is an intersection point or segment\n! between two linear segments, given by 4 x:y coordinates\n! \n! The code was written by means of the Algorithm proposed in\n! http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/\n! By Paul Bourke\n!\n! Basically you have four outcomes:\n!\n! 0) Segments do not cross, ergo no intersection\n! 1) Segments are parallel, but not coinciding, ergo no intersection\n! 2) Segments cross eachother, indicating an intersection point\n! 3) Segments are parallel and coinciding, which has four separate cases:\n!\n! a b c d\n! ------ ------- no intersection\n!\n! a b c d\n! ------.------- one intersection point if b=c\n!\n! a cb d\n! ----==---- one intersection Segment(!) (c,b)\n!\n! a c d b\n! ___________ one intersection Segment(!) (c,d)\n! ------\n!\n! Input: the four coordinates of the two segments: a and b define the first,\n! and c and d define the second segment.\n!\n! Output: sect, which is (0=no intersection), (1=parallel), (2=intersection point)\n! and (3=intersection segment)\n! cross(2,2) array:\n! if sect is 0 or 1 cross(2,2) equals 0.0d0\n! if sect is 2, cross(1,1:2) contains the intersection point\n! if sect is 3, cross(1,1:2) and cross(2,1:2) contains the intersection segment\n!\n! 20081114: Frank Everdij, Delft University of Technology\n!\n\nsubroutine intersect(a,b,c,d,sect,cross)\n\nimplicit none\n\nreal(8),parameter :: epsilon = 1.0d-10\nreal(8),dimension(2),intent(in) :: a,b,c,d\n\ninteger,intent(out) :: sect\nreal(8),intent(out) :: cross(2,2)\n!--\nreal(8),dimension(2) :: aa, bb, cc, dd, sw\nreal(8) :: denom, ua, ub\ninteger :: first, second\n\ncross=0.0d0\nsect=0\n\n! Compute denominator and line numerators for the two segments\n!\ndenom = ( d(2)-c(2) )*( b(1)-a(1) )-( d(1)-c(1) )*( b(2)-a(2) )\nua = ( d(1)-c(1) )*( a(2)-c(2) )-( d(2)-c(2) )*( a(1)-c(1) )\nub = ( b(1)-a(1) )*( a(2)-c(2) )-( b(2)-a(2) )*( a(1)-c(1) )\n\n\n! If denom is zero, then the segments are Parallel (sect=1)\n!\nif (abs(denom) < epsilon) then\n\n sect=1\n\n! If the numerators are both zero the segments coincide\n!\n if ((abs(ua) < epsilon) .and. (abs(ub) < epsilon)) then\n ua=abs(b(1)-a(1))\n ub=abs(b(2)-a(2))\n \n! Determine whether we will be looking at x or y coordinates to avoid\n! pure vertical/horizontal degenerate cases\n!\n if (ua>ub) then\n first=1\n second=2\n else\n first=2\n second=1\n endif\n aa=a\n bb=b\n cc=c\n dd=d\n \n! Some sorting needed \n!\n if (aa(first)>bb(first)) then\n sw=aa\n aa=bb\n bb=sw\n endif\n if (cc(first)>dd(first)) then\n sw=cc\n cc=dd\n dd=sw\n endif\n if (aa(first)>cc(first)) then\n sw=aa\n aa=cc\n cc=sw\n sw=bb\n bb=dd\n dd=sw\n endif\n\n! Decision time, handle each coinciding case separately\n!\n if (bb(first)bb(first)) then\n sect=3\n cross(1,1:2)=cc(1:2)\n cross(2,1:2)=bb(1:2)\n else\n sect=3\n cross(1,1:2)=cc(1:2)\n cross(2,1:2)=dd(1:2)\n endif\n end if\n\nelse\n\n! The segments are not parallel/coinciding so compute the (virtual) intersection point\n!\n ua=ua/denom\n ub=ub/denom\n \n! Final check: if the segment numerators both lie in the interval [0...1] then\n! the intersection point is real and we compute its coordinates.\n! \n if((ua >= 0.0d0) .and. (ua <= 1.0d0) .and. (ub >= 0.0d0) .and. (ub <= 1.0d0)) then\n sect=2\n cross(1,1:2)=a(1:2)+ua*(b(1:2)-a(1:2))\n endif\nendif\n\nreturn\n\nend subroutine intersect\n", "meta": {"hexsha": "96284d25c20e0ebe8f9a016a3ae919fea2010840", "size": 3706, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "intersect.f90", "max_stars_repo_name": "frankeverdij/intersect", "max_stars_repo_head_hexsha": "9c8b98f1e02263e4057d46f80d1f93fb12638d8c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "intersect.f90", "max_issues_repo_name": "frankeverdij/intersect", "max_issues_repo_head_hexsha": "9c8b98f1e02263e4057d46f80d1f93fb12638d8c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "intersect.f90", "max_forks_repo_name": "frankeverdij/intersect", "max_forks_repo_head_hexsha": "9c8b98f1e02263e4057d46f80d1f93fb12638d8c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.7066666667, "max_line_length": 88, "alphanum_fraction": 0.5955207771, "num_tokens": 1275, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7617492935152874}} {"text": "PROGRAM Trig\n\n REAL pi, dtor, rtod, radians, degrees\n\n pi = 4.0 * ATAN(1.0)\n dtor = pi / 180.0\n rtod = 180.0 / pi\n radians = pi / 4.0\n degrees = 45.0\n\n WRITE(*,*) SIN(radians), SIN(degrees*dtor)\n WRITE(*,*) COS(radians), COS(degrees*dtor)\n WRITE(*,*) TAN(radians), TAN(degrees*dtor)\n WRITE(*,*) ASIN(SIN(radians)), ASIN(SIN(degrees*dtor))*rtod\n WRITE(*,*) ACOS(COS(radians)), ACOS(COS(degrees*dtor))*rtod\n WRITE(*,*) ATAN(TAN(radians)), ATAN(TAN(degrees*dtor))*rtod\n\nEND PROGRAM Trig\n", "meta": {"hexsha": "d90995f082bcbca669864adcd25eb64fe60e5717", "size": 496, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Trigonometric-functions/Fortran/trigonometric-functions-1.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Trigonometric-functions/Fortran/trigonometric-functions-1.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Trigonometric-functions/Fortran/trigonometric-functions-1.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 26.1052631579, "max_line_length": 61, "alphanum_fraction": 0.6330645161, "num_tokens": 197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.957277806109987, "lm_q2_score": 0.795658090372256, "lm_q1q2_score": 0.761665831165215}} {"text": " SUBROUTINE slCS2C (A, B, V)\n*+\n* - - - - -\n* C S 2 C\n* - - - - -\n*\n* Spherical coordinates to direction cosines (single precision)\n*\n* Given:\n* A,B real spherical coordinates in radians\n* (RA,Dec), (long,lat) etc.\n*\n* Returned:\n* V real(3) x,y,z unit vector\n*\n* The spherical coordinates are longitude (+ve anticlockwise looking\n* from the +ve latitude pole) and latitude. The Cartesian coordinates\n* are right handed, with the x axis at zero longitude and latitude, and\n* the z axis at the +ve latitude pole.\n*\n* Last revision: 22 July 2004\n*\n* Copyright P.T.Wallace. All rights reserved.\n*\n* License:\n* This program is free software; you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation; either version 2 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program (see SLA_CONDITIONS); if not, write to the\n* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n* Boston, MA 02110-1301 USA\n*\n* Copyright (C) 1995 Association of Universities for Research in Astronomy Inc.\n*-\n\n IMPLICIT NONE\n\n REAL A,B,V(3)\n\n REAL COSB\n\n\n\n COSB = COS(B)\n\n V(1) = COS(A)*COSB\n V(2) = SIN(A)*COSB\n V(3) = SIN(B)\n\n END\n", "meta": {"hexsha": "a74ac4bd2daa0d9c667e5c74dc798a01d993e124", "size": 1703, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/slalib/cs2c.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/slalib/cs2c.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/slalib/cs2c.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.8644067797, "max_line_length": 80, "alphanum_fraction": 0.6488549618, "num_tokens": 464, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067163548471, "lm_q2_score": 0.8080672158638528, "lm_q1q2_score": 0.7616087782178432}} {"text": "! Preprocessor definitions\n! Centered, backward and forward index for the x-dimension\n#define ix 2:(x_dim-1)\n#define ix_m 1:(x_dim-2)\n#define ix_p 3:x_dim\n! Centered, backward and forward index for the y-dimension\n#define iy 2:(y_dim-1)\n#define iy_m 1:(y_dim-2)\n#define iy_p 3:y_dim\n\n! Usage from Python:\n! step_upwind(dx, dy, dt, u, v, C)\nsubroutine step_upwind(dx, dy, dt, u, v, C, C_new, x_dim, y_dim)\n implicit none\n ! Arguments\n integer :: x_dim, y_dim\n real, intent(in) :: dx, dy, dt\n real, intent(in) :: C(x_dim, y_dim), u(x_dim, y_dim), v(x_dim, y_dim)\n real, intent(out) :: C_new(x_dim, y_dim)\n\n ! Local variables\n real, dimension(x_dim - 2, y_dim - 2) :: x_term, y_term\n\n !---------------\n ! Begin program\n !---------------\n\n x_term(:,:) = (&\n MAX(u(ix,iy), 0.) * (C(ix,iy) - C(ix_m,iy)) +&\n MIN(u(ix,iy), 0.) * (C(ix_p,iy) - C(ix,iy)) &\n )/dx\n\n y_term(:,:) = (&\n MAX(v(ix,iy), 0.) * (C(ix,iy) - C(ix,iy_m)) +&\n MIN(v(ix,iy), 0.) * (C(ix,iy_p) - C(ix,iy)) &\n )/dy\n\n C_new(ix,iy) = -(x_term + y_term)*dt + C(ix,iy)\n\nend subroutine\n\n! Usage from Python:\n! step_leapfrog(dx, dy, dt, u, v, C)\nsubroutine step_leapfrog(dx, dy, dt, u, v, C, x_dim, y_dim)\n implicit none\n ! Arguments\n integer :: x_dim, y_dim\n real, intent(in) :: dx, dy, dt\n real, intent(in) :: u(x_dim, y_dim), v(x_dim, y_dim)\n real, intent(inout) :: C(x_dim, y_dim, 2)\n !f2py intent(in,out) :: C\n\n ! Local variabless\n real :: C_new(x_dim, y_dim)\n\n !---------------\n ! Begin program !\n !---------------\n\n ! Initialize only the boundaries\n C_new(:,1) = 0.\n C_new(:,y_dim) = 0.\n C_new(1,:) = 0.\n C_new(x_dim,:) = 0.\n\n ! Step\n C_new(ix,iy) = ( &\n - u(ix,iy) * ( C(ix_p,iy,2) - C(ix_m,iy,2) ) / (2 * dx) &\n - v(ix,iy) * ( C(ix,iy_p,2) - C(ix,iy_m,2) ) / (2 * dy) &\n ) * 2 *dt + C(ix,iy,1)\n\n ! Switch out the old result\n C(:,:,1) = C(:,:,2)\n C(:,:,2) = C_new\n\nend subroutine\n", "meta": {"hexsha": "861b005eedded8ed666774c165ff4992328e5e57", "size": 2214, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Numerical_Schemes_Two_Dim.f95", "max_stars_repo_name": "asura6/Fortran-Python-Advection-and-Diffusion-Models", "max_stars_repo_head_hexsha": "5fbdaba9acc69b3d21e83d9cc208bc551b72ba9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Numerical_Schemes_Two_Dim.f95", "max_issues_repo_name": "asura6/Fortran-Python-Advection-and-Diffusion-Models", "max_issues_repo_head_hexsha": "5fbdaba9acc69b3d21e83d9cc208bc551b72ba9e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Numerical_Schemes_Two_Dim.f95", "max_forks_repo_name": "asura6/Fortran-Python-Advection-and-Diffusion-Models", "max_forks_repo_head_hexsha": "5fbdaba9acc69b3d21e83d9cc208bc551b72ba9e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.7532467532, "max_line_length": 80, "alphanum_fraction": 0.4796747967, "num_tokens": 754, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7615580164937581}} {"text": " ! ==============================================================\r\n ! Copyright © 2020 Intel Corporation\r\n !\r\n ! SPDX-License-Identifier: MIT\r\n ! =============================================================\r\n !\r\n ! [DESCRIPTION]\r\n ! This program computes the integral (area under the curve) of a user-supplied\r\n ! function over an interval in a stepwise fashion. The interval is split into \r\n ! segments, and at each segment position the area of a rectangle is computed \r\n ! whose height is the value of sine at that point and the width is the segment\r\n ! width. The areas of the rectangles are then summed.\r\n !\r\n ! The process is repeated with smaller and smaller width rectangles, more \r\n ! closely approximating the true value.\r\n !\r\n ! The source for this program also demonstrates recommended Fortran\r\n ! coding practices.\r\n !\r\n ! Compile the sample several times using different optimization options.\r\n !\r\n ! Read the Intel(R) Fortran Compiler Documentation for more information about these options.\r\n ! \r\n ! Some of these automatic optimizations use features and options\r\n ! that can restrict program execution to specific architectures. \r\n ! \r\n ! [COMPILE] \r\n ! Use the one of the following compiler options: \r\n !\r\n ! Windows*: /O1, /O2, /O3\r\n !\r\n ! Linux* and macOS*: -O1, -O2, -O3\r\n !\r\n\r\nprogram int_sin\r\nimplicit none\r\n\r\n! Create a value DP that is the \"kind\" number of a double precision value\r\n! We will use this value in our declarations and constants.\r\ninteger, parameter :: DP = kind(0.0D0)\r\n\r\n! Declare a named constant for pi, specifying the kind type\r\nreal(DP), parameter :: pi = 3.141592653589793238_DP \r\n\r\n! Declare interval begin and end\r\nreal(DP), parameter :: interval_begin = 0.0_DP\r\nreal(DP), parameter :: interval_end = 2.0_DP * pi\r\n\r\nreal(DP) :: step, sum, x_i\r\ninteger :: N, i, j\r\nreal clock_start, clock_finish\r\n\r\nwrite (*,'(A)') \" \"\r\nwrite (*,'(A)') \" Number of | Computed Integral |\"\r\nwrite (*,'(A)') \" Interior Points | |\"\r\ncall cpu_time (clock_start)\r\n\r\ndo j=2,26\r\n write (*,'(A)') \"--------------------------------------\"\r\n N = 2**j\r\n ! Compute stepsize for N-1 internal rectangles \r\n step = (interval_end - interval_begin) / real(N,DP);\r\n \r\n ! Approximate 1/2 area in first rectangle: f(x0) * (step/2) \r\n sum = INTEG_FUNC(interval_begin) * (step / 2.0_DP)\r\n \r\n do i=1,N-1\r\n x_i = real(i,DP) * step\r\n ! Apply midpoint rule:\r\n ! Given length = f(x), compute the area of the\r\n ! rectangle of width step\r\n sum = sum + (INTEG_FUNC(x_i) * step)\r\n end do\r\n \r\n ! Add approximate area in last rectangle for f(xN) * (step/2) \r\n sum = sum + (INTEG_FUNC(interval_end) * (step / 2.0_DP))\r\n \r\n write (*,'(T5,I10,T18,\"|\",2X,1P,E14.7,T38,\"|\")') N, sum\r\n end do\r\n\r\ncall cpu_time(clock_finish)\r\nwrite (*,'(A)') \"--------------------------------------\"\r\nwrite (*,'(A)') \" \"\r\nwrite (*,*) \"CPU Time = \",(clock_finish - clock_start), \" seconds\"\r\n\r\ncontains\r\n\r\n! Function to integrate\r\nreal(DP) function INTEG_FUNC (x)\r\n real(DP), intent(IN) :: x\r\n\r\n INTEG_FUNC = abs(sin(x))\r\n return\r\nend function INTEG_FUNC\r\n\r\nend program int_sin\r\n", "meta": {"hexsha": "d1519820f3444edac395988e803ea6818c53229b", "size": 3114, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "DirectProgramming/Fortran/DenseLinearAlgebra/optimize-integral/src/int_sin.f90", "max_stars_repo_name": "tiwaria1/oneAPI-samples", "max_stars_repo_head_hexsha": "18310adf63c7780715f24034acfb0bf01d15521f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 310, "max_stars_repo_stars_event_min_datetime": "2020-07-09T01:00:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T17:52:14.000Z", "max_issues_repo_path": "DirectProgramming/Fortran/DenseLinearAlgebra/optimize-integral/src/int_sin.f90", "max_issues_repo_name": "tiwaria1/oneAPI-samples", "max_issues_repo_head_hexsha": "18310adf63c7780715f24034acfb0bf01d15521f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 438, "max_issues_repo_issues_event_min_datetime": "2020-06-30T23:25:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T00:37:13.000Z", "max_forks_repo_path": "DirectProgramming/Fortran/DenseLinearAlgebra/optimize-integral/src/int_sin.f90", "max_forks_repo_name": "junxnone/oneAPI-samples", "max_forks_repo_head_hexsha": "f414747b5676688d690655c6043b71577027fc19", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 375, "max_forks_repo_forks_event_min_datetime": "2020-06-04T22:58:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T11:04:18.000Z", "avg_line_length": 32.1030927835, "max_line_length": 94, "alphanum_fraction": 0.612716763, "num_tokens": 819, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7615580161246658}} {"text": " FUNCTION golden(ax,bx,cx,f,tol,xmin)\r\n REAL golden,ax,bx,cx,tol,xmin,f,R,C\r\n EXTERNAL f\r\n PARAMETER (R=.61803399,C=1.-R)\r\n REAL f1,f2,x0,x1,x2,x3\r\n x0=ax\r\n x3=cx\r\n if(abs(cx-bx).gt.abs(bx-ax))then\r\n x1=bx\r\n x2=bx+C*(cx-bx)\r\n else\r\n x2=bx\r\n x1=bx-C*(bx-ax)\r\n endif\r\n f1=f(x1)\r\n f2=f(x2)\r\n1 if(abs(x3-x0).gt.tol*(abs(x1)+abs(x2)))then\r\n if(f2.lt.f1)then\r\n x0=x1\r\n x1=x2\r\n x2=R*x1+C*x3\r\n f1=f2\r\n f2=f(x2)\r\n else\r\n x3=x2\r\n x2=x1\r\n x1=R*x2+C*x0\r\n f2=f1\r\n f1=f(x1)\r\n endif\r\n goto 1\r\n endif\r\n if(f1.lt.f2)then\r\n golden=f1\r\n xmin=x1\r\n else\r\n golden=f2\r\n xmin=x2\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "c89d54f267881dcd949240f32f9bd5cb5b64a0d6", "size": 845, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/golden.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/golden.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/golden.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.119047619, "max_line_length": 50, "alphanum_fraction": 0.4059171598, "num_tokens": 306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.7615399598368461}} {"text": "! $UWHPSC/codes/openmp/pisum2.f90\n! Computes pi using OpenMP. \n! Compare to $UWHPSC/codes/mpi/pisum1.f90\n\nprogram pisum2\n \n use omp_lib\n implicit none\n real(kind=8) :: pi,pisum,pisum_thread,x,dx\n integer :: n, nthreads, points_per_thread,thread_num\n integer :: i,istart,iend\n\n ! Specify number of threads to use:\n nthreads = 1 ! need this value in serial mode\n !$ nthreads = 8 \n !$ call omp_set_num_threads(nthreads)\n !$ print \"('Using OpenMP with ',i3,' threads')\", nthreads\n\n print *, \"Input n ... \"\n read *, n\n\n\n ! First do with parallel do loop ...\n ! ----------------------------------\n\n print *, \"WITH OMP PARALLEL DO LOOP:\"\n dx = 1.d0 / n\n pisum = 0.d0\n !$omp parallel do reduction(+: pisum) &\n !$omp private(x)\n do i=1,n\n x = (i-0.5d0) * dx\n pisum = pisum + 1.d0 / (1.d0 + x**2)\n enddo\n pi = 4.d0 * dx * pisum\n print *, 'The approximation to pi = ', pi\n\n\n ! Now do with parallel blocks of code...\n ! --------------------------------------\n\n print *, \"WITH OMP PARALLEL:\"\n\n ! Determine how many points to handle with each thread.\n ! Note that dividing two integers and assigning to an integer will\n ! round down if the result is not an integer. \n ! This, together with the min(...) in the definition of iend below,\n ! insures that all points will get distributed to some thread.\n points_per_thread = (n + nthreads - 1) / nthreads\n print *, \"points_per_thread = \",points_per_thread\n\n dx = 1.d0 / real(n, kind=8)\n pisum = 0.d0\n\n !$omp parallel private(i,pisum_thread,x, &\n !$omp istart,iend,thread_num) \n\n thread_num = 0 ! needed in serial mode\n !$ thread_num = omp_get_thread_num() ! unique for each thread\n\n ! Determine start and end index for the set of points to be \n ! handled by this thread:\n istart = thread_num * points_per_thread + 1\n iend = min((thread_num+1) * points_per_thread, n)\n\n !$omp critical\n print 201, thread_num, istart, iend\n !$omp end critical\n201 format(\"Thread \",i2,\" will take i = \",i6,\" through i = \",i6)\n\n pisum_thread = 0.d0\n do i=istart,iend\n x = (i-0.5d0)*dx\n pisum_thread = pisum_thread + 1.d0 / (1.d0 + x**2)\n enddo\n\n ! update global pisum with value from each thread:\n !$omp critical\n pisum = pisum + pisum_thread\n !$omp end critical\n\n !$omp end parallel \n\n pi = 4.d0 * dx * pisum\n\n print *, 'The approximation to pi = ', pi\n\nend program pisum2\n\n", "meta": {"hexsha": "157f977d249c6227d19e1425d86fa4fd087c4845", "size": 2542, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/codes/openmp/pisum2.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/codes/openmp/pisum2.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/codes/openmp/pisum2.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2444444444, "max_line_length": 71, "alphanum_fraction": 0.590086546, "num_tokens": 749, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127603871312, "lm_q2_score": 0.891811053345418, "lm_q1q2_score": 0.761528838305941}} {"text": "!==============================================================\n! Uniform circular motion in polar coordinates\n! Author: Devansh Shukla\n!--------------------------------------------------------------\nprogram CircularMotion_Polar\n ! Program to compute motion of a particle moving in a circle with uniform velocity in polar coordinates.\n\n implicit none\n real*8, parameter :: PI = 3.141593\n real*8 :: R=0.0, omega=0.0, theta0=0.0, theta, x, y\n real*8 :: t0=0.0, tf=0.0, dt=0.0, t=0.0\n character(len=*), parameter :: fmt1 = \"(F10.6, x, F10.6, x, F10.6, x, F10.6, x, F10.6)\"\n \n theta(t) = theta0 + omega*(t-t0)\n x(t) = R*cos(theta(t))\n y(t) = R*sin(theta(t))\n\n open(UNIT=8, FILE=\"CirclePolar.dat\") \n\n ! Input\n print *, \"Enter angular velocity(omega) and radius (R)\"\n read *, omega, R\n if (omega .le. 0.0) stop \"Illegal value of omega\"\n if (R .le. 0.0) stop \"Illegal value of R\"\n\n print *, \"Enter the value of theta0\"\n read *, theta0\n\n print *, \"Enter t0, tf, dt\"\n read *, t0, tf, dt\n if (dt .le. 0.0) stop \"Illegal value of dt\"\n\n print *, \"----------------------------------------------------------\"\n print \"(x,A,F10.4)\", \"omega =\", omega\n print \"(x,A,F10.4)\", \"T =\", 2.0*PI / omega\n print \"(x,A,F10.4,F10.4,F10.4)\", \"theta0 =\", theta0\n print \"(x,A,F10.4)\", \"R =\", R\n print \"(x,A,F10.4,F10.4,F10.4)\", \"t0, tf, dt =\", t0, tf, dt\n print *, \"----------------------------------------------------------\"\n\n write (8, *) \"# t0=\", t0\n write (8, *) \"# t R theta x y\"\n print \"(xA10,A10,xA10,A10,A10)\", \"time\", \"R\", \"theta(t)\", \"x(t)\", \"y(t)\"\n ! Computing\n t = t0\n do while (t <= tf)\n write (*, fmt1) t, R, theta(t), x(t), y(t)\n write (8, fmt1) t, R, theta(t), x(t), y(t) \n t = t + dt\n enddo\n print *, \"----------------------------------------------------------\"\n close(8)\n\nend program CircularMotion_Polar\n", "meta": {"hexsha": "b33ed819a95ca731f7686cccd2f3b3a899e39be3", "size": 1926, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "M3/m2_ii.f90", "max_stars_repo_name": "devanshshukla99/MP409-Computational-Physics-Lab", "max_stars_repo_head_hexsha": "938318cb62f1b89a7bc57e07f9b5ac6f2b689fe4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "M3/m2_ii.f90", "max_issues_repo_name": "devanshshukla99/MP409-Computational-Physics-Lab", "max_issues_repo_head_hexsha": "938318cb62f1b89a7bc57e07f9b5ac6f2b689fe4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "M3/m2_ii.f90", "max_forks_repo_name": "devanshshukla99/MP409-Computational-Physics-Lab", "max_forks_repo_head_hexsha": "938318cb62f1b89a7bc57e07f9b5ac6f2b689fe4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.0181818182, "max_line_length": 108, "alphanum_fraction": 0.4589823468, "num_tokens": 619, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397307, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7615288330864256}} {"text": "! Define types for Cartesian geometry, and define functions for distance and\n! calculating slope and intercept.\nMODULE cartesian_tools\nIMPLICIT NONE\n\nTYPE :: point\n REAL :: x\n REAL :: y\nEND TYPE point\n\nTYPE :: line\n REAL :: m\n REAL :: b\nEND TYPE line\nCONTAINS\n REAL FUNCTION dist(p1, p2)\n IMPLICIT NONE\n TYPE (point), INTENT(IN) :: p1, p2\n dist = SQRT((p2%x - p1%x)**2 + (p2%y - p1%y)**2)\n END FUNCTION dist\n\n TYPE (line) FUNCTION connect(p1, p2)\n IMPLICIT NONE\n TYPE (point), INTENT(IN) :: p1, p2\n REAL :: m, b\n IF (p1%x == p2%x .AND. p1%y == p2%y) THEN\n connect = line(0, 0)\n ELSE\n m = (p2%y - p1%y) / (p2%x - p1%x)\n b = p1%y - m * p1%x\n connect = line(m, b)\n END IF\n END FUNCTION\nEND MODULE cartesian_tools\n\nPROGRAM cartesian\nUSE cartesian_tools\nIMPLICIT NONE\nTYPE (point) :: p1, p2, p3\nTYPE (line) :: p_line\n\np1 = point(0.,0.)\np2 = point(1.,2.)\np3 = p2\nWRITE(*, *) dist(p1, p2)\nWRITE(*, *) dist(p2, p3)\nWRITE(*, *) connect(p1, p2)\nWRITE(*, *) connect(p2, p3)\n\nEND PROGRAM cartesian\n", "meta": {"hexsha": "2a58b918882b53171b360ca6156b1e7869c5d406", "size": 1015, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap12/cartesian.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap12/cartesian.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap12/cartesian.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.9019607843, "max_line_length": 76, "alphanum_fraction": 0.6246305419, "num_tokens": 375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9632305318133554, "lm_q2_score": 0.7905303112671294, "lm_q1q2_score": 0.7614629321364144}} {"text": " PROGRAM xspline\r\nC driver for routine spline\r\n INTEGER N\r\n REAL PI\r\n PARAMETER(N=20,PI=3.141593)\r\n INTEGER i\r\n REAL yp1,ypn,x(N),y(N),y2(N)\r\n write(*,*) 'Second-derivatives for sin(x) from 0 to PI'\r\nC generate array for interpolation\r\n do 11 i=1,20\r\n x(i)=i*PI/N\r\n y(i)=sin(x(i))\r\n11 continue\r\nC calculate 2nd derivative with SPLINE\r\n yp1=cos(x(1))\r\n ypn=cos(x(N))\r\n call spline(x,y,N,yp1,ypn,y2)\r\nC test result\r\n write(*,'(t19,a,t35,a)') 'spline','actual'\r\n write(*,'(t6,a,t17,a,t33,a)') 'angle','2nd deriv','2nd deriv'\r\n do 12 i=1,N\r\n write(*,'(1x,f8.2,2f16.6)') x(i),y2(i),-sin(x(i))\r\n12 continue\r\n END\r\n", "meta": {"hexsha": "314573f54b737b8f109ff935bfb735ab232ea575", "size": 726, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xspline.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xspline.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xspline.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.04, "max_line_length": 68, "alphanum_fraction": 0.5289256198, "num_tokens": 254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702031, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7614181440500083}} {"text": "program test\n\n implicit none\n\n integer :: year, golden_number, epacts\n\n year = 2018\n\n print *, golden_number(year)\n\n print *, epacts(year)\n\nend program test\n\nfunction golden_number(year)\n\n implicit none\n\n integer :: year, golden_number\n\n golden_number = modulo(year + 1, 19)\n\nend function golden_number\n\nfunction epacts(year)\n\n implicit none\n\n integer :: year, golden_number, epacts, arg\n\n arg = 11 * golden_number(year) + 18\n\n epacts = modulo(arg, 30)\n\nend function epacts\n\n\n", "meta": {"hexsha": "cb536475aedd488c822c0f3426a01b503e5af14b", "size": 544, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/yearcalculations.f95", "max_stars_repo_name": "mkschu/liturgical-calculations", "max_stars_repo_head_hexsha": "c016cb1fdb60171a23fe6add4edd1bd6a40e28c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/yearcalculations.f95", "max_issues_repo_name": "mkschu/liturgical-calculations", "max_issues_repo_head_hexsha": "c016cb1fdb60171a23fe6add4edd1bd6a40e28c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/yearcalculations.f95", "max_forks_repo_name": "mkschu/liturgical-calculations", "max_forks_repo_head_hexsha": "c016cb1fdb60171a23fe6add4edd1bd6a40e28c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.3157894737, "max_line_length": 51, "alphanum_fraction": 0.6323529412, "num_tokens": 129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.8311430499496095, "lm_q1q2_score": 0.7614181421341549}} {"text": "subroutine ComputeDG82(DG82, lmax, m, theta0)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis routine will compute the kernel of Grunbaum et al. 1982\n!\tthat commutes with the space concentration kernel. This \n!\tkernel is tridiagonal and has simple expressions for \n!\tits elements. Note that this kernel is multiplied by -1 in\n!\tcomparison to Grunbaum et al. in order that the eigenvectors \n!\twill be listed in the same order as the eigenvectors of the\n!\tequivalent space concentration matrix Dllm. While the eigenfunctions\n!\tof this kernel correspond to the eigenvalues of Dllm, the eigenvalues\n!\tdo NOT!\n!\n!\tCalling Parameters\n!\t\tIN\n!\t\t\tlmax:\t\tMaximum spherical harmonic degree.\n!\t\t\ttheta0:\t\tAngular radius of spherical cap IN RADIANS.\n!\t\t\tm:\t\tAngular order to concentration problem.\n!\t\tOUT\n!\t\t\tD0G82:\t\tSymmetric tridiagonal kernel with a maximum size of lmax+1 by lmax+1.\n!\n!\tDependencies:\tnone\n!\n!\tWritten by Mark Wieczorek (June 2004)\n!\n!\tCopyright (c) 2005, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\n\treal*8, intent(out) ::\tDG82(:,:)\n\treal*8, intent(in) ::\ttheta0\n\tinteger, intent(in) :: \tlmax, m\n\treal*8 ::\t\tx\n\tinteger ::\t\ti, n\n\n\n\tn = lmax + 1 - abs(m)\n\t\n\tif(n<1) then\n\t\tprint*, \"Error --- ComputeDG82\"\n\t\tprint*, \"abs(M) must be less than or equal to LMAX\"\n\t\tprint*, \"Input values of l and m are \", lmax, m\n\t\tstop\n\telseif (size(DG82(1,:)) < n .or. size(DG82(:,1)) < n) then\n\t\tprint*, \"Error --- ComputeDG82\"\n\t\tprint*, \"DG82 must be dimensioned as (LMAX-abs(M)+1,LMAX-abs(M)+1) where LMAX and M are \", lmax, m\n\t\tprint*, \"Input array is dimensioned as \", size(DG82(1,:)), size(DG82(:,1))\n\t\tstop\n\tendif\n\n\tDG82 = 0.0d0\n\n\tx = cos(theta0)\n\t\n\t\t\n\tDG82(1,1) = x * dble(1+m) * dble(m)\n\t\n\tdo i=2, n, 1\n\t\tDG82(i,i) = x * dble(i+m) * dble(i+m-1)\n\t\tDG82(i,i-1) = - sqrt(dble(i-1+m)**2 - dble(m)**2) * &\n\t\t\t( dble(i-1+m)**2 - dble(lmax+1)**2 ) / &\n\t\t\tsqrt(4.0d0*dble(i-1+m)**2 - 1.0d0)\n\t\tDG82(i-1,i) = DG82(i,i-1)\n\tenddo\n\t\t\nend subroutine ComputeDG82\n\n", "meta": {"hexsha": "c4df6fd4a38422648c3ba7d8a487548827fac373", "size": 2080, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/ComputeDG82.f95", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "spherical_splines/SHTOOLS/src/ComputeDG82.f95", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "spherical_splines/SHTOOLS/src/ComputeDG82.f95", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 29.7142857143, "max_line_length": 100, "alphanum_fraction": 0.6096153846, "num_tokens": 713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.7614181211330292}} {"text": "SUBROUTINE random_Zipf(a, r, setup)\r\n! Generate a random deviate (r) from the Zipf (or Zeta) distribution.\r\n! If setup = .TRUE. (or local variable b < 0), two local variables (b and\r\n! const) are set/reset for future calls, otherwise it is assumed that\r\n! the value of a is unchanged since the last call.\r\n\r\n! The value of a must be > 1.0 (NOT CHECKED)\r\n\r\n! Algorithm from page 551 of:\r\n! Devroye, Luc (1986) `Non-uniform random variate generation',\r\n! Springer-Verlag: Berlin. ISBN 3-540-96305-7 (also 0-387-96305-7)\r\n\r\n! Programmer: Alan Miller (amiller @ users,bigpond.net.au)\r\n! Latest revision - 3 February 1998\r\n\r\nIMPLICIT NONE\r\nREAL, INTENT(IN) :: a\r\nINTEGER, INTENT(OUT) :: r\r\nLOGICAL, INTENT(IN OUT) :: setup\r\n\r\n! Local variables\r\nREAL, SAVE :: b = -1.0, const\r\nREAL :: t, u, v\r\nREAL, PARAMETER :: one = 1.0\r\n\r\nIF (b < 0.0 .OR. setup) THEN\r\n b = 2.0**(a - one)\r\n const = -one/(a - one)\r\n setup = .FALSE.\r\nEND IF\r\n\r\nDO\r\n CALL RANDOM_NUMBER(u)\r\n CALL RANDOM_NUMBER(v)\r\n r = FLOOR(u**const)\r\n t = (one + one/r)**(a - one)\r\n IF (v*r*(t - one)/(b - one) <= t/b) EXIT\r\nEND DO\r\n\r\nRETURN\r\nEND SUBROUTINE random_Zipf\r\n\r\n\r\n\r\nPROGRAM t_random_Zipf\r\nIMPLICIT NONE\r\nINTEGER :: r, i, nfreq, count, i1\r\nINTEGER, ALLOCATABLE :: freq(:)\r\nREAL, ALLOCATABLE :: expctd(:)\r\nREAL :: a, total\r\nREAL, PARAMETER :: one = 1.0\r\nLOGICAL :: setup\r\n\r\nINTERFACE\r\n SUBROUTINE random_Zipf(a, r, setup)\r\n IMPLICIT NONE\r\n REAL, INTENT(IN) :: a\r\n INTEGER, INTENT(OUT) :: r\r\n LOGICAL, INTENT(IN OUT) :: setup\r\n END SUBROUTINE random_Zipf\r\nEND INTERFACE\r\n\r\nWRITE(*, *) 'Enter a (> 1.0): '\r\nREAD(*, *) a\r\nsetup = .TRUE.\r\n! 1/20 = 5% Store individual frequencies up to last 5%\r\nnfreq = NINT( (20.0/(a - one))**(one/(a-one)) )\r\nALLOCATE( freq(nfreq), expctd(nfreq) )\r\nfreq = 0\r\n\r\n! Generate 1000 random deviates from the Zipf distribution\r\n\r\nDO i = 1, 1000\r\n CALL random_Zipf(a, r, setup)\r\n r = MIN(r, nfreq)\r\n freq(r) = freq(r) + 1\r\nEND DO\r\n\r\n! Calculate approximate expected frequencies\r\ntotal = 0.0\r\nDO i = 1, nfreq-1\r\n expctd(i) = REAL(i)**(-a)\r\n total = total + expctd(i)\r\nEND DO\r\nexpctd(nfreq) = one / ( (a-one)*(nfreq - 0.5)**(a-one) )\r\ntotal = total + expctd(nfreq)\r\nexpctd = expctd * (1000. / total)\r\n\r\nWRITE(*, *) ' Range Obs.freq. Expctd.freq.'\r\ni = 1\r\nDO\r\n count = 0\r\n total = 0\r\n i1 = i\r\n DO\r\n count = count + freq(i)\r\n total = total + expctd(i)\r\n IF (total > 25. .OR. i >= nfreq) EXIT\r\n i = i + 1\r\n END DO\r\n IF (i == nfreq) i = 999999\r\n WRITE(*, '(i6, \" - \", i6, i7, \" \", f9.2)') i1, i, count, total\r\n IF (i == 999999) EXIT\r\n i = i + 1\r\nEND DO\r\n\r\nSTOP\r\nEND PROGRAM t_random_Zipf\r\n", "meta": {"hexsha": "eec05218fac92ac46d80105b7c2f812319e1cecc", "size": 2712, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/zipf.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/zipf.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/zipf.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 24.880733945, "max_line_length": 74, "alphanum_fraction": 0.584439528, "num_tokens": 944, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881363, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7613639245892379}} {"text": "module geomutils\n\n ! module geomutils : functions for querying 2-D and 3-D geometries\n\n implicit none\n\n private\n public dist_point_to_segment_2d, is_point_in_quad\n\ncontains\n\n function dist_point_to_segment_2d(x,y,x1,y1,x2,y2)\n\n ! dist_point_to_segment_2d() : returns the shortest distance from a point p to a line segment.\n ! Based on the method of http://paulbourke.net/geometry/pointlineplane/\n !\n ! Inputs:\n ! =======\n ! x,y : the coordinates of the point\n !\n ! Output:\n ! =======\n ! x1,y1,x2,y2 : the start and end points of the line segment\n !\n\n real, intent(in) :: x,y,x1,y1,x2,y2\n real :: dist_point_to_segment_2d\n\n real :: u, dx, dy\n real :: x_closest, y_closest\n\n ! check if points are coincident\n if (x1==x2 .and. y1==y2) then\n write(*,*) 'Error in dist_point_to_segment_2d : Points are coincident!'\n stop\n end if\n\n dx = x2-x1\n dy = y2-y1\n\n u = ((x-x1)*dx + (y-y1)*dy) / abs(dx**2 - dy**2)\n\n if (u < 0) then\n x_closest = x1\n y_closest = y1\n else if (u > 1) then\n x_closest = x2\n y_closest = y2\n else\n x_closest = x1+u*dx\n y_closest = y1+u*dy\n end if\n\n dist_point_to_segment_2d = ((x_closest-x)**2 + (y_closest-y)**2)**0.5\n\n end function dist_point_to_segment_2d\n\n\n function is_point_in_quad(p_list, p)\n\n ! is_point_in_quad() : For a quadrilateral whose corners are given in p_list, returns\n ! True if the point p lies within the polygon and False if the point p lies outside of it.\n ! Based on the method of http://paulbourke.net/geometry/polygonmesh/\n !\n ! Inputs:\n ! =======\n ! p_list : a (4,3) array of points. expects that p(:,3) = 0 (the z-coordinate is zero)\n !\n ! Outputs:\n ! ========\n ! is_point_in_quad (logical) : .True. if point is inside the quadrilateral, .False. otherwise\n\n real, intent(in) :: p_list(4,3)\n real, intent(in) :: p(3)\n logical :: is_point_in_quad\n\n integer, parameter :: nsides = 4\n real :: p1(3), p2(3)\n real :: xinters\n\n integer :: i, counter\n\n counter = 0\n\n p1 = p_list(1,1:3)\n\n do i=1,nsides\n p2 = p_list(mod(i,nsides)+1,1:3)\n if (p(2) > min(p1(2),p2(2))) then\n if (p(2) <= max(p1(2),p2(2))) then\n if (p(1) <= max(p1(1),p2(1))) then\n if (p1(2) /= p2(2)) then\n xinters = (p(2)-p1(2))*(p2(1)-p1(1))/(p2(2)-p1(2)) + p1(1)\n if (p1(1) == p2(1) .or. p(1) <= xinters) then\n counter = counter + 1\n end if\n end if\n end if\n end if\n end if\n p1 = p2\n end do\n\n if (mod(counter,2) == 0) then\n is_point_in_quad = .False.\n else\n is_point_in_quad = .True.\n end if\n\n end function is_point_in_quad\n\n\nend module geomutils", "meta": {"hexsha": "6192ceac2d2fa376b15a68036cd5dcffd9d80924", "size": 3319, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/mod/util/geomutils.f95", "max_stars_repo_name": "ebranlard/CACTUS", "max_stars_repo_head_hexsha": "6d89b48759fe78d1890a77656bafdbd1e703bbb2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2020-03-04T18:49:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T23:03:37.000Z", "max_issues_repo_path": "src/mod/util/geomutils.f95", "max_issues_repo_name": "ebranlard/CACTUS", "max_issues_repo_head_hexsha": "6d89b48759fe78d1890a77656bafdbd1e703bbb2", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 40, "max_issues_repo_issues_event_min_datetime": "2020-03-12T21:21:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-27T01:56:25.000Z", "max_forks_repo_path": "src/mod/util/geomutils.f95", "max_forks_repo_name": "ebranlard/CACTUS", "max_forks_repo_head_hexsha": "6d89b48759fe78d1890a77656bafdbd1e703bbb2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2020-03-04T03:51:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T08:52:49.000Z", "avg_line_length": 29.3716814159, "max_line_length": 116, "alphanum_fraction": 0.4832780958, "num_tokens": 965, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7613639170083549}} {"text": "program matsum\n implicit none\n\n ! Variable declarations\n integer :: a_rows, a_cols, b_rows, b_cols, c_rows, c_cols\n integer :: i, j, k\n integer :: a_io, b_io, c_io, fa_stat, fb_stat, fc_stat\n real *8, allocatable :: a(:), b(:), c(:)\n character *32 :: fa, fb, fc\n logical :: fa_exists, fb_exists, fc_exists\n\n ! Ask user for matrix dimensions and filename\n print *, \"Matrix A filename?\"\n read *, fa\n print *, \"Matrix B filename?\"\n read *, fb\n print *, \"Matrix C filename?\"\n read *, fc\n\n ! Check if files exist\n inquire(file = fa, exist = fa_exists)\n inquire(file = fb, exist = fb_exists)\n inquire(file = fc, exist = fc_exists)\n if (.not. fa_exists .or. .not. fb_exists) then\n call exit\n end if\n\n ! Open files\n open(newunit = a_io, file = fa, action = \"read\", iostat = fa_stat)\n open(newunit = b_io, file = fb, action = \"read\", iostat = fb_stat)\n if (fc_exists) then\n open(newunit = c_io, file = fc, status = \"replace\", action = \"write\", iostat = fc_stat)\n else\n open(newunit = c_io, file = fc, status = \"new\", action = \"write\", iostat = fc_stat)\n end if\n\n ! Check if files opened correctly\n if (fa_stat /= 0 .or. fb_stat /= 0 .or. fc_stat /= 0) then\n call exit\n end if\n\n ! Read matrix A\n read(a_io, '(I1, X, I1)') a_rows, a_cols\n allocate(a(a_rows * a_cols))\n read(a_io, *) (a(i), i = 1, a_rows * a_cols)\n\n ! Read matrix B\n read(b_io, '(I1, X, I1)') b_rows, b_cols\n allocate(b(b_rows * b_cols))\n read(b_io, *) (b(i), i = 1, b_rows * b_cols)\n\n ! Initialize C matrix\n c_rows = a_rows\n c_cols = b_cols\n allocate(c(c_rows * c_cols))\n\n ! Compute product\n do i = 0, a_rows - 1\n do j = 0, b_cols - 1\n do k = 0, b_rows - 1\n c(i * c_cols + j + 1) = c(i * c_cols + j + 1) + a(i * a_cols + k + 1) * b(k * b_cols + j + 1)\n end do\n end do\n end do\n\n ! Write values to file\n write(c_io, '(I1, X, I1)') c_rows, c_cols\n do i = 1, c_rows * c_cols\n write(c_io, '(F17.15, X)', advance = 'no') c(i)\n end do\n\n ! Close files\n close(a_io)\n close(b_io)\n close(c_io)\n\n ! Deallocate arrays\n deallocate(a)\n deallocate(b)\n deallocate(c)\nend program matsum\n", "meta": {"hexsha": "b25b31f0342c8b0a5b3e642400be58f91f440f0b", "size": 2123, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lab2/src/matmul.f90", "max_stars_repo_name": "dssgabriel/obhpc", "max_stars_repo_head_hexsha": "6358dffc85b18e1e65cb80f8e9b11b191b86463d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lab2/src/matmul.f90", "max_issues_repo_name": "dssgabriel/obhpc", "max_issues_repo_head_hexsha": "6358dffc85b18e1e65cb80f8e9b11b191b86463d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lab2/src/matmul.f90", "max_forks_repo_name": "dssgabriel/obhpc", "max_forks_repo_head_hexsha": "6358dffc85b18e1e65cb80f8e9b11b191b86463d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.8902439024, "max_line_length": 101, "alphanum_fraction": 0.6081017428, "num_tokens": 750, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554445, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.7613452779500745}} {"text": "module ElementMod\n ! -------------------------------------------------------------------------------------------------------------------\n ! Mai 2018\n ! Maxime Tousignant\n ! maxime.tousignant@polymtl.ca\n ! -------------------------------------------------------------------------------------------------------------------\n ! Description :\n ! Quadrature de Gauss-Legendre de degree 4 pour integrer parfaitement des polynomes de Legendre d'ordre 2.\n ! Notes :\n ! La modification de l'ordre de la quadrature de Gauss ou des fonctions de bases va entrainer des erreurs.\n ! -------------------------------------------------------------------------------------------------------------------\n \n ! Quadrature de Gauss d'ordre 4 (hard coded)\n integer, parameter :: nGauss = 4\n double precision, dimension(nGauss), parameter &\n :: xiGauss = (/ -0.3399810435848563d0, 0.3399810435848563d0, -0.8611363115940526d0, 0.8611363115940526d0 /)\n double precision, dimension(nGauss), parameter &\n :: wGauss = (/ 0.6521451548625461d0, 0.6521451548625461d0, 0.3478548451374538d0, 0.3478548451374538d0\t/) \n \n ! Fonctions de bases aux pts de gauss (hard coded)\n integer, parameter :: degPsi = 2\n double precision, dimension(nGauss) :: Psi1 = 0.5d0*xiGauss*(xiGauss-1.0d0)\n double precision, dimension(nGauss) :: Psi2 = 1.0d0-xiGauss*xiGauss\n double precision, dimension(nGauss) :: Psi3 = 0.5d0*xiGauss*(xiGauss+1.0d0)\n double precision, dimension(nGauss) :: dPsi1dxi = xiGauss-0.5d0\n double precision, dimension(nGauss) :: dPsi2dxi = -2.0d0*xiGauss\n double precision, dimension(nGauss) :: dPsi3dxi = xiGauss+0.5d0\n \n ! Derivees des fonctions de base aux noeuds\n double precision, dimension(1+degPsi) :: dPsi1dxi_node = (/-1.5d0 ,-0.5d0 , 0.5d0 /)\n double precision, dimension(1+degPsi) :: dPsi2dxi_node = (/ 2.0d0 , 0.0d0 ,-2.0d0 /)\n double precision, dimension(1+degPsi) :: dPsi3dxi_node = (/-0.5d0 , 0.5d0 , 1.5d0 /)\n \nend module ElementMod\n ", "meta": {"hexsha": "09031c03e35d17faa2f35a86d1e89639a2f14583", "size": 2414, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "FEM_transitoire_fortran/Sources/Element.f90", "max_stars_repo_name": "giardg/PowerEquivalentModel", "max_stars_repo_head_hexsha": "d37f32bffc0a0a2ccbc8fbdbe2d89b4b398d6b9a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "FEM_transitoire_fortran/Sources/Element.f90", "max_issues_repo_name": "giardg/PowerEquivalentModel", "max_issues_repo_head_hexsha": "d37f32bffc0a0a2ccbc8fbdbe2d89b4b398d6b9a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "FEM_transitoire_fortran/Sources/Element.f90", "max_forks_repo_name": "giardg/PowerEquivalentModel", "max_forks_repo_head_hexsha": "d37f32bffc0a0a2ccbc8fbdbe2d89b4b398d6b9a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.9714285714, "max_line_length": 121, "alphanum_fraction": 0.4743164872, "num_tokens": 653, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947132556619, "lm_q2_score": 0.8056321959813274, "lm_q1q2_score": 0.7613181660309036}} {"text": "PROGRAM mfcs\n \n! Code converted using TO_F90 by Alan Miller\n! Date: 2004-06-28 Time: 12:58:11\n\n! =======================================================\n! Purpose: This program computes the Fresnel integrals\n! C(x) and S(x) using subroutine FCS\n! Input : x --- Argument of C(x) and S(x)\n! Output: C --- C(x)\n! S --- S(x)\n! Example:\n! x C(x) S(x)\n! -----------------------------------\n! 0.0 .00000000 .00000000\n! 0.5 .49234423 .06473243\n! 1.0 .77989340 .43825915\n! 1.5 .44526118 .69750496\n! 2.0 .48825341 .34341568\n! 2.5 .45741301 .61918176\n! =======================================================\n\nIMPLICIT DOUBLE PRECISION (a-h,o-z)\nWRITE(*,*)'Please enter x '\n! READ(*,*) X\nx=2.5\nWRITE(*,*)' x C(x) S(x)'\nWRITE(*,*)' -----------------------------------'\nCALL fcs(x,c,s)\nWRITE(*,10)x,c,s\n10 FORMAT(1X,f5.1,2F15.8)\nEND PROGRAM mfcs\n\n\nSUBROUTINE fcs(x,c,s)\n\n! =================================================\n! Purpose: Compute Fresnel integrals C(x) and S(x)\n! Input : x --- Argument of C(x) and S(x)\n! Output: C --- C(x)\n! S --- S(x)\n! =================================================\n\n\n\nDOUBLE PRECISION, INTENT(IN OUT) :: x\nDOUBLE PRECISION, INTENT(OUT) :: c\nDOUBLE PRECISION, INTENT(OUT) :: s\nIMPLICIT DOUBLE PRECISION (a-h,o-z)\neps=1.0D-15\npi=3.141592653589793D0\nxa=DABS(x)\npx=pi*xa\nt=.5D0*px*xa\nt2=t*t\nIF (xa == 0.0) THEN\n c=0.0D0\n s=0.0D0\nELSE IF (xa < 2.5D0) THEN\n r=xa\n c=r\n DO k=1,50\n r=-.5D0*r*(4.0D0*k-3.0D0)/k/(2.0D0*k-1.0D0) /(4.0D0*k+1.0D0)*t2\n c=c+r\n IF (DABS(r) < DABS(c)*eps) EXIT\n END DO\n 15 s=xa*t/3.0D0\n r=s\n DO k=1,50\n r=-.5D0*r*(4.0D0*k-1.0D0)/k/(2.0D0*k+1.0D0) /(4.0D0*k+3.0D0)*t2\n s=s+r\n IF (DABS(r) < DABS(s)*eps) EXIT\n END DO\nELSE IF (xa < 4.5D0) THEN\n m=INT(42.0+1.75*t)\n su=0.0D0\n c=0.0D0\n s=0.0D0\n f1=0.0D0\n f0=1.0D-100\n DO k=m,0,-1\n f=(2.0D0*k+3.0D0)*f0/t-f1\n IF (k == INT(k/2)*2) THEN\n c=c+f\n ELSE\n s=s+f\n END IF\n su=su+(2.0D0*k+1.0D0)*f*f\n f1=f0\n f0=f\n END DO\n q=DSQRT(su)\n c=c*xa/q\n s=s*xa/q\nELSE\n r=1.0D0\n f=1.0D0\n DO k=1,20\n r=-.25D0*r*(4.0D0*k-1.0D0)*(4.0D0*k-3.0D0)/t2\n f=f+r\n END DO\n r=1.0D0/(px*xa)\n g=r\n DO k=1,12\n r=-.25D0*r*(4.0D0*k+1.0D0)*(4.0D0*k-1.0D0)/t2\n g=g+r\n END DO\n t0=t-INT(t/(2.0D0*pi))*2.0D0*pi\n c=.5D0+(f*DSIN(t0)-g*DCOS(t0))/px\n s=.5D0-(f*DCOS(t0)+g*DSIN(t0))/px\nEND IF\n40 IF (x < 0.0D0) THEN\n c=-c\n s=-s\nEND IF\nRETURN\nEND SUBROUTINE fcs\n", "meta": {"hexsha": "5100a6daa41b39402b63ea739bc777492fad3cdf", "size": 2630, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MATLAB/f2matlab/comp_spec_func/mfcs.f90", "max_stars_repo_name": "vasaantk/bin", "max_stars_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATLAB/f2matlab/comp_spec_func/mfcs.f90", "max_issues_repo_name": "vasaantk/bin", "max_issues_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATLAB/f2matlab/comp_spec_func/mfcs.f90", "max_forks_repo_name": "vasaantk/bin", "max_forks_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.2881355932, "max_line_length": 67, "alphanum_fraction": 0.4604562738, "num_tokens": 1184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356994, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.761275652954088}} {"text": "! -*- f90 -*-\n\n!###############################################################\n!! SUBROUTINE TO COMPUTE THE KURTOSIS OF AN ARRAY\n!###############################################################\nsubroutine kurtosis(a,nx,ny,nz,krt)\n integer, intent(in) :: nx, ny, nz\n double precision, intent(out):: krt\n double precision, dimension(nx,ny,nz), intent(in) :: a\n!f2py intent (in) nx,ny,nz\n!f2py intent (in) a\n!f2py intent (out) krt\n double precision, dimension(nx,ny,nz) :: temp\n double precision :: tmp, NORM\n NORM=nx*ny*nz\n tmp=sum(a)/NORM; temp=a-tmp\n tmp=sum(temp**2)/NORM\n krt=sum(temp**4)/(NORM*tmp**2)\nend subroutine kurtosis\n\n!###############################################################\n!! SUBROUTINE TO COMPUTE SCALE DEPENDENT KURTOSIS OF AN ARRAY\n!###############################################################\nsubroutine sdk(a,axis,nsd,nx,ny,nz,sdkrt)\n integer, intent(in) :: nx,ny,nz,axis,nsd\n double precision, dimension(nx,ny,nz), intent(in) :: a\n double precision, dimension(nsd), intent(out) ::sdkrt\n!f2py intent (in) a\n!f2py intent (in) nx, ny, nz, axis, nsd\n!f2py intent (out) sdkrt\n double precision, dimension(nx,ny,nz) :: tmp\n integer :: ii\n double precision :: rmsval\n!\n do ii=1,nsd\n call rollarr(a,axis,ii,tmp,nx,ny,nz)\n rmsval=dsqrt(sum(tmp**2)/(nx*ny*nz))\n if (rmsval .ne. 0) tmp=tmp/rmsval\n call kurtosis(tmp,nx,ny,nz,sdkrt(ii))\n enddo\nend subroutine sdk\n\n!###############################################################\n!! FORTRAN EQUIVALENT OF CSHIFT BUT FASTER AS IT DOES NOT\n!! CREATE EXTRA COPIES\n!###############################################################\nsubroutine rollarr(a,axis,inc,ar,nx,ny,nz)\n double precision, dimension(nx,ny,nz), intent(in) :: a\n integer, intent(in) :: nx,ny,nz,axis,inc\n double precision, dimension(nx,ny,nz), intent(out):: ar\n!f2py intent (in) a\n!f2py intent (in) nx,ny,nz,axis,inc\n!f2py intent (out) ar\n integer :: x,y,z,xx,yy,zz\n!\n do z=1,nz; do y=1,ny; do x=1,nx\n SELECT CASE (axis+1)\n CASE (1)\n call roll_idx(x,nx,inc,xx); yy=y; zz=z\n CASE (2)\n xx=x; call roll_idx(y,ny,inc,yy); zz=z\n CASE(3)\n xx=x; yy=y; call roll_idx(z,nz,inc,zz)\n END SELECT\n ar(x,y,z) = a(xx,yy,zz) \n enddo; enddo; enddo\nend subroutine rollarr\n\n!###############################################################\n!! SUBROUTINE TO ROLL AN INDEX ON PERIODIC GRID\n!###############################################################\nsubroutine roll_idx(x,nx,inc,xx)\n integer, intent(in) :: x,nx,inc\n integer, intent(out):: xx\n!f2py intent (in) x,nx,inc\n!f2py intent (out) xx\n xx = merge(x+inc, x-nx+inc+1, (x .lt. nx-inc))\n! if (x .lt. nx-inc) then \n! xx=x+inc \n! else \n! xx=x-nx+inc+1\n! endif\nend subroutine roll_idx\n\n", "meta": {"hexsha": "6e698a94093f385f13b12cc900584528a1bb93d3", "size": 2816, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Analysis/Simulations/OLLibs/F90/kurtosis.f90", "max_stars_repo_name": "ahmadryan/TurbAn", "max_stars_repo_head_hexsha": "b8866d103a2ca2f5fbad73bcd4416f19299f22b2", "max_stars_repo_licenses": ["BSD-2-Clause-Patent"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Analysis/Simulations/OLLibs/F90/kurtosis.f90", "max_issues_repo_name": "ahmadryan/TurbAn", "max_issues_repo_head_hexsha": "b8866d103a2ca2f5fbad73bcd4416f19299f22b2", "max_issues_repo_licenses": ["BSD-2-Clause-Patent"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Analysis/Simulations/OLLibs/F90/kurtosis.f90", "max_forks_repo_name": "ahmadryan/TurbAn", "max_forks_repo_head_hexsha": "b8866d103a2ca2f5fbad73bcd4416f19299f22b2", "max_forks_repo_licenses": ["BSD-2-Clause-Patent"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-03-22T15:30:12.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-10T02:55:50.000Z", "avg_line_length": 33.1294117647, "max_line_length": 64, "alphanum_fraction": 0.5177556818, "num_tokens": 869, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.8354835330070838, "lm_q1q2_score": 0.761275645340182}} {"text": "PROGRAM me1xa\n \n! Code converted using TO_F90 by Alan Miller\n! Date: 2004-06-28 Time: 12:58:10\n\n! =========================================================\n! Purpose: This program computes the exponential integral\n! E1(x) using subroutine E1XA\n! Input : x --- Argument of E1(x) ( x > 0 )\n! Output: E1 --- E1(x)\n! Example:\n! x E1(x)\n! ----------------------\n! 0.0 .1000000+301\n! 1.0 .2193839E+00\n! 2.0 .4890051E-01\n! 3.0 .1304838E-01\n! 4.0 .3779352E-02\n! 5.0 .1148296E-02\n! =========================================================\n\nDOUBLE PRECISION :: e1,x\nWRITE(*,*)'Please enter x '\n! READ(*,*) X\nx=5.0\nWRITE(*,*)' x E1(x)'\nWRITE(*,*)' ----------------------'\nCALL e1xa(x,e1)\nWRITE(*,10)x,e1\n10 FORMAT(1X,f5.1,e17.7)\nEND PROGRAM me1xa\n\n\nSUBROUTINE e1xa(x,e1)\n\n! ============================================\n! Purpose: Compute exponential integral E1(x)\n! Input : x --- Argument of E1(x)\n! Output: E1 --- E1(x) ( x > 0 )\n! ============================================\n\n\n\nDOUBLE PRECISION, INTENT(IN) :: x\nDOUBLE PRECISION, INTENT(OUT) :: e1\nIMPLICIT DOUBLE PRECISION (a-h,o-z)\nIF (x == 0.0) THEN\n e1=1.0D+300\nELSE IF (x <= 1.0) THEN\n e1=-DLOG(x)+((((1.07857D-3*x-9.76004D-3)*x+5.519968D-2)*x &\n -0.24991055D0)*x+0.99999193D0)*x-0.57721566D0\nELSE\n es1=(((x+8.5733287401D0)*x+18.059016973D0)*x &\n +8.6347608925D0)*x+0.2677737343D0\n es2=(((x+9.5733223454D0)*x+25.6329561486D0)*x &\n +21.0996530827D0)*x+3.9584969228D0\n e1=DEXP(-x)/x*es1/es2\nEND IF\nRETURN\nEND SUBROUTINE e1xa\n", "meta": {"hexsha": "041c5aa4031afc3c9a37b57c22822e2764de136d", "size": 1787, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MATLAB/f2matlab/comp_spec_func/me1xa.f90", "max_stars_repo_name": "vasaantk/bin", "max_stars_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATLAB/f2matlab/comp_spec_func/me1xa.f90", "max_issues_repo_name": "vasaantk/bin", "max_issues_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATLAB/f2matlab/comp_spec_func/me1xa.f90", "max_forks_repo_name": "vasaantk/bin", "max_forks_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2950819672, "max_line_length": 65, "alphanum_fraction": 0.4437604924, "num_tokens": 630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.7612166714526086}} {"text": "!----------------------------------------------------------------------*\r\n! SUBROUTINE SVPS1 (Subroutine Vapour Pressure Saturated no. 1) *\r\n! Authors: Daniel van Kraalingen *\r\n! Date : 3-Feb-1991, Version: 1.0 *\r\n! Purpose: This subroutine calculates saturated vapour pressure and *\r\n! slope of saturated vapour pressure. Parameters of the *\r\n! formula were fitted on the Goff-Gratch formula used in the *\r\n! Smithsonian Handbook of Meteorological Tables. The *\r\n! saturated vapour following the Goff-Gratch formula is also *\r\n! available as a subroutine. (Note that 1kPa = 10 mbar) *\r\n! *\r\n! FORMAL PARAMETERS: (I=input,O=output,C=control,IN=init,T=time) *\r\n! name type meaning units class *\r\n! ---- ---- ------- ----- ----- *\r\n! TMA R4 Temperature at which to calculate pressure C I *\r\n! VPS R4 Saturated vapour pressure kPa O *\r\n! VPSL R4 Slope of VPS at TMA kPa/C O *\r\n! *\r\n! Fatal error checks: none *\r\n! Warnings : TMA < -20, TMA > 50 *\r\n! Subprograms called: none *\r\n! File usage : none *\r\n!----------------------------------------------------------------------*\r\n\r\n SUBROUTINE SVPS1 (TMA,VPS,VPSL)\r\n IMPLICIT NONE\r\n REAL TMA,VPS,VPSL\r\n SAVE\r\n\r\n IF (TMA.LT.-20..OR.TMA.GT.50.) WRITE (*,'(A,G12.5,A)') &\r\n ' WARNING from SVPS1: extreme temperature:',TMA,' d. Celsius'\r\n\r\n VPS = 0.1*6.10588*EXP (17.32491*TMA/(TMA+238.102))\r\n VPSL = 238.102*17.32491*VPS/(TMA+238.102)**2\r\n\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "82bf65091f6e32ef45fb758c0ffc035b54bd2d60", "size": 2079, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/DSSAT/CSM/SVPS1.f90", "max_stars_repo_name": "mikiec84/delphi", "max_stars_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-03-03T11:57:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T21:19:54.000Z", "max_issues_repo_path": "tests/data/program_analysis/DSSAT/CSM/SVPS1.f90", "max_issues_repo_name": "mikiec84/delphi", "max_issues_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 385, "max_issues_repo_issues_event_min_datetime": "2018-02-21T16:52:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T07:44:56.000Z", "max_forks_repo_path": "tests/data/program_analysis/DSSAT/CSM/SVPS1.f90", "max_forks_repo_name": "mikiec84/delphi", "max_forks_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-03-20T01:08:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-29T01:04:49.000Z", "avg_line_length": 54.7105263158, "max_line_length": 73, "alphanum_fraction": 0.3992303992, "num_tokens": 456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620619801095, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7611929983837017}} {"text": "module quadglobal\nuse qdmodule\nimplicit none\ninteger ndebug, ndigits, nerror, nquadl\nend module\n\n! program tquadgsq\nsubroutine f_main\n\n! David H. Bailey 2004-12-16\n! This is Quad-Double Fortran-90 version.\n\n! This work was supported by the Director, Office of Science, Division\n! of Mathematical, Information, and Computational Sciences of the\n! U.S. Department of Energy under contract number DE-AC03-76SF00098.\n\n! This program demonstrates the quadrature routine 'quadgsq', which employs\n! Gaussian quadrature. The function quadgsq is suitable to integrate\n! a function that is continuous, infinitely differentiable and integrable on a\n! finite open interval. It can also be used for certain integrals on infinite\n! intervals, by making a suitable change of variable -- see below. While\n! this routine is usually more efficient than quaderf or quadts for functions\n! that are regular on a closed interval, it is not very effective for \n! functions with a singularity at one or both of the endpoints.\n\n! The function(s) to be integrated is(are) defined in external function\n! subprogram(s) -- see the sample function subprograms below. The name(s) of\n! the function subprogram(s) must be included in appropriate type and external\n! statements in the main program.\n\n! Note that an integral of a function on an infinite interval can be\n! converted to an integral on a finite interval by means of a suitable\n! change of variable. Example (here the notation \"inf\" means infinity):\n\n! Int_0^inf f(t) dt = Int_0^1 f(t) dt + Int_1^inf f(t) dt\n! = Int_0^1 f(t) dt + Int_0^1 f(1/t)/t^2 dt\n\n! See examples below.\n\n! Inputs set in parameter statement below:\n! kdebug Debug level setting. Default = 2.\n! ndp Digits of precision. May not exceed mpipl in file mpmod90.f.\n! In some cases, ndp must be significantly greater than the desired\n! tolerance in the result-- see the examples below.\n! neps Log10 of the desired tolerance in the result (negative integer).\n! nq1 Max number of phases in quadrature routine; adding 1 increases\n! (possibly doubles) the number of accurate digits in the result,\n! but also roughly doubles the run time and memory. nq1 > 2.\n! nq2 Space parameter for wk and xk arrays in the calling program. By\n! default it is set to 8 * 2^nq1. Increase nq2 if directed by a \n! message produced in initqerf. Note that the dimension of the\n! wk and xk arrays starts with -1, so the length of these arrays is\n! (nq2+2) * 4 eight-byte words.\n\nuse qdmodule\nuse quadglobal\nimplicit none\ninteger i, kdebug, ndp, neps, nq1, nq2, n1\nparameter (kdebug = 2, ndp = 64, neps = -64, nq1 = 8, nq2 = 8 * 2 ** nq1 +100)\ndouble precision dplog10q, d1, d2, second, tm0, tm1\ntype (qd_real) err, quadgsq, fun01, fun02, fun03, fun04, fun05, fun06, fun07, &\n fun08, fun09, fun10, fun11, fun12, fun13, fun14, fun15a, fun15b, &\n t1, t2, t3, t4, wk(-1:nq2), xk(-1:nq2), x1, x2\nexternal quadgsq, fun01, fun02, fun03, fun04, fun05, fun06, fun07, fun08, &\n fun09, fun10, fun11, fun12, fun13, fun14, fun15a, fun15b, second\ninteger*4 old_cw\n\ncall f_fpu_fix_start (old_cw)\n\nndebug = kdebug\nndigits = ndp\nnerror = 0\nnquadl = nq1\nwrite (6, 1) ndigits, neps, nquadl\n1 format ('Quadgsq test'/'Digits =',i6,' Epsilon =',i6,' Quadlevel =',i6)\n\n! Initialize quadrature tables wk and xk (weights and abscissas).\n\ntm0 = second ()\ncall initqgsq (nq1, nq2, wk, xk)\ntm1 = second ()\nif (nerror > 0) stop\nwrite (6, 2) tm1 - tm0\n2 format ('Quadrature initialization completed: cpu time =',f12.6)\n\n! Begin quadrature tests.\n\nwrite (6, 11)\n11 format (/'Continuous functions on finite itervals:'//&\n 'Problem 1: Int_0^1 t*log(1+t) dt = 1/4')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgsq (fun01, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\n3 format ('Quadrature completed: CPU time =',f12.6/'Result =')\ncall qdwrite (6, t1)\nt2 = 0.25d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n4 format ('Actual error =',f10.6,'x10^',i5)\n\nwrite (6, 12)\n12 format (/'Problem 2: Int_0^1 t^2*arctan(t) dt = (pi - 2 + 2*log(2))/12')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgsq (fun02, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall qdwrite (6, t1)\nt2 = (qdpi() - 2.d0 + 2.d0 * log (qdreal (2.d0))) / 12.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 13)\n13 format (/'Problem 3: Int_0^(pi/2) e^t*cos(t) dt = 1/2*(e^(pi/2) - 1)')\nx1 = 0.d0\nx2 = 0.5d0 * qdpi()\ntm0 = second ()\nt1 = quadgsq (fun03, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall qdwrite (6, t1)\nt2 = 0.5d0 * (exp (0.5d0 * qdpi()) - 1.d0)\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 14)\n14 format (/ &\n 'Problem 4: Int_0^1 arctan(sqrt(2+t^2))/((1+t^2)sqrt(2+t^2)) dt = 5*Pi^2/96')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgsq (fun04, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall qdwrite (6, t1)\nt2 = 5.d0 * qdpi()**2 / 96.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 15)\n15 format (/&\n 'Continuous functions on finite itervals, but non-diff at an endpoint'// &\n 'Problem 5: Int_0^1 sqrt(t)*log(t) dt = -4/9')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgsq (fun05, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall qdwrite (6, t1)\nt2 = qdreal (-4.d0) / 9.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 16)\n16 format (/'Problem 6: Int_0^1 sqrt(1-t^2) dt = pi/4')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgsq (fun06, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall qdwrite (6, t1)\nt2 = 0.25d0 * qdpi()\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 17)\n17 format (/&\n 'Functions on finite intervals with integrable singularity at an endpoint.'//&\n 'Problem 7: Int_0^1 t/sqrt(1-t^2) dt = 1')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgsq (fun07, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall qdwrite (6, t1)\nt2 = 1.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 18)\n18 format (/'Problem 8: Int_0^1 log(t)^2 dt = 2')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgsq (fun08, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall qdwrite (6, t1)\nt2 = 2.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 19)\n19 format (/'Problem 9: Int_0^(pi/2) log(cos(t)) dt = -pi*log(2)/2')\nx1 = 0.d0\nx2 = 0.5d0 * qdpi()\ntm0 = second ()\nt1 = quadgsq (fun09, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall qdwrite (6, t1)\nt2 = -0.5d0 * qdpi() * log (qdreal (2.d0))\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 20)\n20 format (/'Problem 10: Int_0^(pi/2) sqrt(tan(t)) dt = pi*sqrt(2)/2')\nx1 = 0.d0\nx2 = 0.5d0 * qdpi()\ntm0 = second ()\nt1 = quadgsq (fun10, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall qdwrite (6, t1)\nt2 = 0.5d0 * qdpi() * sqrt (qdreal (2.d0))\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 21)\n21 format (/&\n 'Functions on an infinite interval (requiring a two-step solution'//&\n 'Problem 11: Int_0^inf 1/(1+t^2) dt = pi/2')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgsq (fun11, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall qdwrite (6, t1)\nt2 = 0.5d0 * qdpi()\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 22)\n22 format (/'Problem 12: Int_0^inf e^(-t)/sqrt(t) dt = sqrt(pi)')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgsq (fun12, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall qdwrite (6, t1)\nt2 = sqrt (qdpi())\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 23)\n23 format (/'Problem 13: Int_0^inf e^(-t^2/2) dt = sqrt(pi/2)')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgsq (fun13, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall qdwrite (6, t1)\nt2 = sqrt (0.5d0 * qdpi())\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 24)\n24 format (/&\n 'Oscillatory functions on an infinite interval.'//&\n 'Problem 14: Int_0^inf e^(-t)*cos(t) dt = 1/2')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgsq (fun14, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall qdwrite (6, t1)\nt2 = 0.5d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 25)\n25 format (/'Problem 15: Int_0^inf sin(t)/t = pi/2')\nx1 = 0.d0\nx2 = qdpi()\ntm0 = second ()\nt1 = quadgsq (fun15a, x1, x2, nq1, nq2, wk, xk)\nx2 = 1.d0 / qdpi()\nt2 = quadgsq (fun15b, x1, x2, nq1, nq2, wk, xk)\nt3 = t1 + 40320.d0 * t2 - 1.d0 / qdpi() + 2.d0 / qdpi() ** 3 &\n - 24.d0 / qdpi() ** 5 + 720.d0 / qdpi() ** 7\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\nt4 = 0.5d0 * qdpi()\ncall decmdq (t4 - t3, d1, n1)\nwrite (6, 4) d1, n1\nwrite (6, 26)\n26 format ('Prob 15 error may be 40,000 X higher than estimated error.')\n\ncall f_fpu_fix_end (old_cw)\nstop\nend\n\nfunction fun01 (t)\n\n! fun01(t) = t * log(1+t)\n\nuse qdmodule\nimplicit none\ntype (qd_real) fun01, t\n\nfun01 = t * log (1.d0 + t)\nreturn\nend\n\nfunction fun02 (t)\n\n! fun02(t) = t^2 * arctan(t)\n\nuse qdmodule\nimplicit none\ntype (qd_real) fun02, t\n\nfun02 = t ** 2 * atan (t)\nreturn\nend\n\nfunction fun03 (t)\n\n! fun03(t) = e^t * cos(t)\n\nuse qdmodule\nimplicit none\ntype (qd_real) fun03, t\n\nfun03 = exp(t) * cos(t)\nreturn\nend\n\nfunction fun04 (t)\n\n! fun04(t) = arctan(sqrt(2+t^2))/((1+t^2)sqrt(2+t^2))\n\nuse qdmodule\nimplicit none\ntype (qd_real) fun04, t, t1\n\nt1 = sqrt (2.d0 + t**2)\nfun04 = atan(t1)/((1.d0 + t**2)*t1)\nreturn\nend\n\nfunction fun05 (t)\n\n! fun05(t) = sqrt(t)*log(t)\n\nuse qdmodule\nimplicit none\ntype (qd_real) fun05, t\n\nfun05 = sqrt (t) * log (t)\nreturn\nend\n\nfunction fun06 (t)\n\n! fun06(t) = sqrt(1-t^2)\n\nuse qdmodule\nimplicit none\ntype (qd_real) fun06, t\n\nfun06 = sqrt (1.d0 - t**2)\nreturn\nend\n\nfunction fun07 (t)\n\n! fun07(t) = t / sqrt(1-t^2)\n\nuse qdmodule\nimplicit none\ntype (qd_real) fun07, t\n\nfun07 = t / sqrt (1.d0 - t**2)\nreturn\nend\n\nfunction fun08 (t)\n\n! fun08(t) = log(t)^2\n\nuse qdmodule\nimplicit none\ntype (qd_real) fun08, t\n\nfun08 = log (t) ** 2\nreturn\nend\n\nfunction fun09 (t)\n\n! fun09(t) = log (cos (t))\n\nuse qdmodule\nimplicit none\ntype (qd_real) fun09, t\n\nfun09 = log (cos (t))\nreturn\nend\n\nfunction fun10 (t)\n\n! fun10(t) = sqrt(tan(t))\n\nuse qdmodule\nimplicit none\ntype (qd_real) fun10, t\n\nfun10 = sqrt (tan (t))\nreturn\nend\n\nfunction fun11 (t)\n\n! fun11(t) = 1/(u^2(1+(1/u-1)^2)) = 1/(1 - 2*u + u^2)\n\nuse qdmodule\nimplicit none\ntype (qd_real) fun11, t\n\nfun11 = 1.d0 / (1.d0 - 2.d0 * t + 2.d0 * t ** 2)\nreturn\nend\n\nfunction fun12 (t)\n\n! fun12(t) = e^(-(1/t-1)) / sqrt(t^3 - t^4)\n\nuse qdmodule\nimplicit none\ntype (qd_real) fun12, t, t1\n\nt1 = 1.d0 / t - 1.d0\nfun12 = exp (-t1) / sqrt (t ** 3 - t ** 4)\nreturn\nend\n\nfunction fun13 (t)\n\n! fun13(t) = e^(-(1/t-1)^2/2) / t^2\n\nuse qdmodule\nimplicit none\ntype (qd_real) fun13, t, t1\n\nt1 = 1.d0 / t - 1.d0\nfun13 = exp (-0.5d0 * t1 ** 2) / t ** 2\nreturn\nend\n\nfunction fun14 (t)\n\n! fun14(t) = e^(-(1/t-1)) * cos (1/t-1) / t^2\n\nuse qdmodule\nimplicit none\ntype (qd_real) fun14, t, t1\n\nt1 = 1.d0 / t - 1.d0\nfun14 = exp (-t1) * cos (t1) / t ** 2\nreturn\nend\n\nfunction fun15a (t)\n\n! fun15a(t) = sin(t)/t\n\nuse qdmodule\nuse quadglobal\nimplicit none\ntype (qd_real) fun15a, t\n\nfun15a = sin (t) / t\nreturn\nend\n\nfunction fun15b (t)\n\n! fun15b(t) = t^7 * sin(1/t)\n\nuse qdmodule\nuse quadglobal\nimplicit none\ntype (qd_real) fun15b, t\n\nif (abs (t) > 1.d-10) then\n fun15b = t**7 * sin (1.d0 / t)\nelse\n fun15b = 0.d0\nendif\nreturn\nend\n\nsubroutine initqgsq (nq1, nq2, wk, xk)\n\n! This subroutine initializes the quadrature arays xk and wk for Gaussian\n! quadrature. It employs a Newton iteration scheme with a dynamic precision\n! level. The argument nq2, which is the space allocated for wk and xk in\n! the calling program, should be at least 8 * 2^nq1 + 100, although a higher\n! value may be required, depending on precision level. Monitor the space\n! figure given in the message below during initialization to be certain.\n! David H Bailey 2002-11-04\n\nuse qdmodule\nuse quadglobal\nimplicit none\ninteger i, ierror, ik0, is, j, j1, k, n, nq1, nq2, nwp, nws\ndouble precision pi\nparameter (pi = 3.141592653589793238d0)\ntype (qd_real) eps, r, t1, t2, t3, t4, t5, wk(-1:nq2), xk(-1:nq2)\nparameter (ik0 = 100)\n\nif (ndebug >= 1) then\n write (6, 1)\n1 format ('initqgsq: Gaussian quadrature initialization')\nendif\n\neps = 1.d-64\nwk(-1) = dble (nq1)\nwk(0) = 0.d0\nxk(0) = 0.d0\nwk(1) = dble (nq1)\nxk(1) = dble (ik0)\ni = ik0\n\ndo j = 2, ik0\n wk(j) = 0.d0\n xk(j) = 0.d0\nenddo\n\ndo k = 1, nq1\n if (ndebug >= 2) write (6, *) k, i, nq2\n n = 3 * 2 ** (k + 1)\n\n do j = 1, n / 2\n\n! Compute a double precision estimate of the root.\n\n is = 0\n r = cos ((pi * (j - 0.25d0)) / (n + 0.5d0))\n\n! Compute the j-th root of the n-degree Legendre polynomial using Newton's\n! iteration.\n\n100 continue\n\n t1 = 1.d0\n t2 = 0.d0\n\n do j1 = 1, n\n t3 = t2\n t2 = t1\n t1 = (dble (2 * j1 - 1) * r * t2 - dble (j1 - 1) * t3) / dble (j1)\n enddo\n\n t4 = dble (n) * (r * t1 - t2) / (r ** 2 - 1.d0)\n t5 = r\n r = r - t1 / t4\n\n! Once convergence is achieved at nwp = 3, then start doubling (almost) the\n! working precision level at each iteration until full precision is reached.\n\n if (abs (r - t5) > eps) goto 100\n\n i = i + 1\n if (i > nq2) goto 110\n xk(i) = r\n t4 = dble (n) * (r * t1 - t2) / (r ** 2 - 1.d0)\n wk(i) = 2.d0 / ((1.d0 - r ** 2) * t4 ** 2)\n enddo\n\n xk(k+1) = dble (i)\nenddo\n\nxk(-1) = dble (i)\nif (ndebug >= 2) then\n write (6, 2) i\n2 format ('initqerf: Table spaced used =',i8)\nendif\ngoto 130\n\n110 continue\n\nwrite (6, 3) nq2\n3 format ('initqgsq: Table space parameter is too small; value =',i8)\nnerror = 92\ngoto 130\n\n120 continue\n\nnerror = ierror + 100\nwrite (6, 4) nerror\n4 format ('initqgsq: Error in quadrature initialization; code =',i5)\n\n130 continue\n\nreturn\nend\n\nfunction quadgsq (fun, x1, x2, nq1, nq2, wk, xk)\n\n! This routine computes the integral of the function fun on the interval\n! [0, 1], with up to nq1 iterations, with a target tolerance of eps.\n! wk and xk are precomputed tables of weights and abscissas, each of size\n! nq2 and of type qd_real. The function fun is not evaluated at x1 or x2.\n! David H. Bailey 2002-11-04\n\nuse qdmodule\nuse quadglobal\nimplicit none\ninteger i, ierror, ik0, k, j, n, nds, nq1, nq2\ndouble precision d1, d2, d3, d4, dplog10q\ntype (qd_real) a, b, c10, quadgsq, eps, eps1, eps2, err, fmx, fun, h, sum, &\n s1, s2, s3, t1, t2, t3, wk(-1:nq2), xk(-1:nq2), x1, x2, xx1, xx2\nexternal fun, dplog10q\nparameter (ik0 = 100)\n\na = 0.5d0 * (x2 - x1)\nb = 0.5d0 * (x2 + x1)\ns1 = 0.d0\ns2 = 0.d0\nc10 = 10.d0\neps = 1.d-64\neps1 = 1.d-61\n if (wk(-1) < dble (nq1)) then\n write (6, 1) nq1\n1 format ('quadgsq: quadrature arrays have not been initialized; nq1 =',i6)\n nerror = 70\n goto 130\nendif\n\ndo k = 1, nq1\n n = 3 * 2 ** (k + 1)\n s3 = s2\n s2 = s1\n fmx = 0.d0\n sum = 0.d0\n i = dble (xk(k))\n\n do j = 1, n / 2\n i = i + 1\n xx1 = - a * xk(i) + b\n xx2 = a * xk(i) + b\n if (xx1 > x1) then\n t1 = fun (xx1)\n else\n t1 = 0.d0\n endif\n if (xx2 < x2 .and. j + k > 2) then\n t2 = fun (xx2)\n else\n t2 = 0.d0\n endif\n sum = sum + wk(i) * (t1 + t2)\n fmx = max (fmx, abs (t1), abs (t2))\n enddo\n\n s1 = a * sum\n eps2 = fmx * eps\n d1 = dplog10q (abs (s1 - s2))\n d2 = dplog10q (abs (s1 - s3))\n d3 = dplog10q (eps2) - 1.d0\n\n if (k <= 2) then\n err = 1.d0\n elseif (d1 .eq. -9999.d0) then\n err = 0.d0\n else\n d4 = min (0.d0, max (d1 ** 2 / d2, 2.d0 * d1, d3))\n err = c10 ** nint (d4)\n endif\n\n! Output current integral approximation and error estimate, to 56 dp.\n\n if (ndebug >= 2) then\n write (6, 2) k, nq1, nint (dplog10q (abs (err)))\n2 format ('quadgsq: Iteration',i3,' of',i3,'; est error = 10^',i5, &\n '; approx value =')\n call qdwrite (6, s1)\n endif\n if (k >= 3 .and. err < eps1) goto 130\n if (k >= 3 .and. err < eps2) goto 110\nenddo\n\nwrite (6, 3) nint (dplog10q (abs (err))), nquadl\n3 format ('quadgsq: Estimated error = 10^',i5/&\n 'Increase Quadlevel for greater accuracy. Current Quadlevel =',i4)\nif (err > 1.d-20) then\n write (6, 4)\n4 format ('quadgsq: Poor results may be due to singularities at endpoints.'/&\n 'If so, try the erf or tanh-sinh quadrature routines (Quadtype = 2 or 3).')\nendif\ngoto 130\n\n110 continue\n\nwrite (6, 5) nint (dplog10q (abs (err))), ndigits\n5 format ('quadgsq: Estimated error = 10^',i5/&\n 'Increase working prec (Digits) for greater accuracy. Current Digits =',i4)\ngoto 130\n\n120 continue\n\nnerror = ierror + 100\nwrite (6, 6) nerror\n6 format ('quadgsq: Error in quadrature calculation; code =',i5)\ns1 = 0.d0\n\n130 continue\n\nquadgsq = s1\nreturn\nend\n\nfunction dplog10q (a)\n\n! For input MP value a, this routine returns a DP approximation to log10 (a).\n\nuse qdmodule\nimplicit none\ninteger ia\ndouble precision da, dplog10q, t1\ntype (qd_real) a\n\nda = a\nif (da .eq. 0.d0) then\n dplog10q = -9999.d0\nelse\n dplog10q = log10 (abs (da))\nendif\n\n100 continue\nreturn\nend\n\nsubroutine decmdq (a, b, ib)\n\n! For input MP value a, this routine returns DP b and integer ib such that \n! a = b * 10^ib, with 1 <= abs (b) < 10 for nonzero a.\n\nuse qdmodule\nimplicit none\ninteger ia, ib\ndouble precision da, b, t1, xlt\nparameter (xlt = 0.3010299956639812d0)\ntype (qd_real) a\n\nda = a\nif (da .ne. 0.d0) then\n t1 = log10 (abs (da))\n ib = t1\n if (t1 .lt. 0.d0) ib = ib - 1\n b = sign (10.d0 ** (t1 - ib), da)\nelse\n b = 0.d0\n ib = 0\nendif\n\nreturn\nend\n", "meta": {"hexsha": "8e9bd65d46ab113cc8bff767b42e2c891d1f7273", "size": 17534, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fortran/tquadgsq.f", "max_stars_repo_name": "t-hishinuma/QD", "max_stars_repo_head_hexsha": "97ed6742a15eaf74e248158927ff8c20edc8ab6b", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-11-08T22:44:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T06:41:47.000Z", "max_issues_repo_path": "fortran/tquadgsq.f", "max_issues_repo_name": "t-hishinuma/QD", "max_issues_repo_head_hexsha": "97ed6742a15eaf74e248158927ff8c20edc8ab6b", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-09-04T19:46:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-04T19:46:45.000Z", "max_forks_repo_path": "fortran/tquadgsq.f", "max_forks_repo_name": "t-hishinuma/QD", "max_forks_repo_head_hexsha": "97ed6742a15eaf74e248158927ff8c20edc8ab6b", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-01-03T16:08:55.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-06T20:47:22.000Z", "avg_line_length": 22.6830530401, "max_line_length": 80, "alphanum_fraction": 0.6218774952, "num_tokens": 7418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.7610764885881444}} {"text": " subroutine GETPHIPOINT(\n & phi\n & ,freq\n & ,x\n & )\n implicit none\n integer*8 ch_flops\n COMMON/ch_timer/ ch_flops\n REAL*8 phi\n REAL*8 freq(0:1)\n REAL*8 x(0:1)\n phi = sin(freq(0)*x(0))\n & * sin(freq(1)*x(1))\n return\n end\n subroutine GETLOFPHI(\n & lofphi\n & ,ilofphilo0,ilofphilo1\n & ,ilofphihi0,ilofphihi1\n & ,freq\n & ,dx\n & ,problo\n & ,probhi\n & ,aCoef\n & ,bCoef\n & ,iboxlo0,iboxlo1\n & ,iboxhi0,iboxhi1\n & )\n implicit none\n integer*8 ch_flops\n COMMON/ch_timer/ ch_flops\n integer ilofphilo0,ilofphilo1\n integer ilofphihi0,ilofphihi1\n REAL*8 lofphi(\n & ilofphilo0:ilofphihi0,\n & ilofphilo1:ilofphihi1)\n REAL*8 freq(0:1)\n REAL*8 dx(0:1)\n REAL*8 problo(0:1)\n REAL*8 probhi(0:1)\n REAL*8 aCoef\n REAL*8 bCoef\n integer iboxlo0,iboxlo1\n integer iboxhi0,iboxhi1\n integer i,j\n REAL*8 x(0:2 -1)\n do j = iboxlo1,iboxhi1\n do i = iboxlo0,iboxhi0\n x(0) = (i+(0.500d0))*dx(0) + problo(0)\n x(1) = (j+(0.500d0))*dx(1) + problo(1)\n call getlofphipoint(lofphi(i,j),freq,x,aCoef,bCoef)\n enddo\n enddo\n return\n end\n subroutine GETLOFPHIPOINT(\n & lofphi\n & ,freq\n & ,x\n & ,aCoefmult\n & ,bCoefmult\n & )\n implicit none\n integer*8 ch_flops\n COMMON/ch_timer/ ch_flops\n REAL*8 lofphi\n REAL*8 freq(0:1)\n REAL*8 x(0:1)\n REAL*8 aCoefmult\n REAL*8 bCoefmult\n integer dir\n REAL*8 fac,phi, temp\n fac = -(freq(0)**2\n & + freq(1)**2)\n fac = fac *(x(0) +x(1))\n phi = (sin(freq(0)*x(0))\n & * sin(freq(1)*x(1)))\n lofphi = fac*phi\n temp = 0.0\n do dir=0, 2 -1\n if (dir.eq.0) then\n temp = freq(0)*cos(freq(0)*x(0))\n & *sin(freq(1)*x(1))\n else if (dir.eq.1) then\n temp = freq(1)*sin(freq(0)*x(0))\n & *cos(freq(1)*x(1))\n endif\n lofphi = lofphi + temp\n enddo\n lofphi = aCoefmult*x(0)*phi + bCoefmult*lofphi\n return\n end\n subroutine GETGRADPHIPOINT(\n & gradphi\n & ,freq\n & ,x\n & )\n implicit none\n integer*8 ch_flops\n COMMON/ch_timer/ ch_flops\n REAL*8 gradphi(0:1)\n REAL*8 freq(0:1)\n REAL*8 x(0:1)\n gradphi(0) = freq(0) * cos(freq(0)*x(0)) * sin(freq(1)*x(1))\n gradphi(1) = freq(1) * sin(freq(0)*x(0)) * cos(freq(1)*x(1)) \n return\n end\n", "meta": {"hexsha": "6e135949b9095164b77514652fcd5db788995949", "size": 2983, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "releasedExamples/AMRPoisson/execVariableCoefficientMultigrid/f/2d.Darwin.64.clang++.gfortran.DEBUG.OPTHIGH/functionsF.f", "max_stars_repo_name": "88Sasha88/Chombo_3.2", "max_stars_repo_head_hexsha": "b2a17351a1ec71995408d4f1a6079d1247a8a9e6", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "releasedExamples/AMRPoisson/execVariableCoefficientMultigrid/f/2d.Darwin.64.clang++.gfortran.DEBUG.OPTHIGH/functionsF.f", "max_issues_repo_name": "88Sasha88/Chombo_3.2", "max_issues_repo_head_hexsha": "b2a17351a1ec71995408d4f1a6079d1247a8a9e6", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "releasedExamples/AMRPoisson/execVariableCoefficientMultigrid/f/2d.Darwin.64.clang++.gfortran.DEBUG.OPTHIGH/functionsF.f", "max_forks_repo_name": "88Sasha88/Chombo_3.2", "max_forks_repo_head_hexsha": "b2a17351a1ec71995408d4f1a6079d1247a8a9e6", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.6203703704, "max_line_length": 72, "alphanum_fraction": 0.4301039222, "num_tokens": 1018, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7610764775389072}} {"text": " \tProgram P3\r\n \tImplicit none\r\n\tReal*8 dt, min, max, t, y(5)\r\nc n: number of equations (the 'dimension' of the standard form)\r\nC starting and end points\r\n min=0.0D0\r\n max=10.0D0\r\nC time step\r\n dt=0.1D0\r\nC initial position\r\n y(1)=1.0D0\r\nC initial velocity\r\n y(2)=0.0D0\r\nc open file to output\r\n Open(6, File='p3.dat')\r\nc do n steps of Runga-Kutta algorithm\r\n\tDo t=min, max, dt\r\n\t Call rk4(t, dt, y, 2)\r\n Write (6,*) t, y(1)\r\n\tenddo\r\nc\r\n\tClose(6)\r\n\tStop \r\n End\r\nc------------------------end of main program------------------------\r\nc\r\n\tSubroutine rk4(t, dt, y, n)\r\n\tImplicit none\r\n\tReal*8 df, dg, h, t, dt, y(5)\r\n Real*8 k0, k1, k2, k3\r\n Real*8 l0, l1, l2, l3\r\n integer n\r\n h=dt/2.0D0\r\n k0 = dt * df(y(1),y(n))\r\n l0 = dt * dg(y(1),y(n))\r\n k1 = dt * df(y(1)+h, y(n)+0.5d0*l0)\r\n l1 = dt * dg(y(1)+0.5d0*k0,y(n)+0.5d0*l0)\r\n k2 = dt * df(y(1)+0.5d0*k1,y(n)+0.5d0*l1)\r\n l2 = dt * dg(y(1)+0.5d0*k1,y(n)+0.5d0*l1)\r\n k3 = dt * df(y(1)+k2,y(n)+l2)\r\n l3 = dt * dg(y(1)+k2,y(n)+l2)\r\n y(1) = y(1) + (k0+2*k1+2*k2+k3)/6.0d0\r\n y(n) = y(n) + (l0+2*l1+2*l2+l3)/6.0d0\r\n\tReturn\r\n\tEnd\r\n\r\nc function which returns the derivatives (RHS)\r\n\tFunction df(y,z)\r\nC 2 function components: dx/dt = v(t), dv/dt = -w**2*x(t) -a*v\r\nC the second term is damping term\r\n\tImplicit none\r\nc declarations\r\n\tReal*8 df, y, z\r\n\tdf=z\r\n\tReturn\r\n\tEnd\r\n\r\n\tFunction dg(y,z)\r\nC 2 function components: dx/dt = v(t), dv/dt = -w**2*x(t) -a*v\r\nC the second term is damping term\r\n\timplicit none\r\nc declarations\r\n\tReal*8 dg, y, z, omega, alpha\r\n\tdata omega /3.0d0/\r\n\tdata alpha /0.5d0/\r\nc\r\n\tdg= - omega**2.0d0 * y - alpha * z\r\n\tReturn\r\n\tEnd", "meta": {"hexsha": "d098fef51baad4f690699e49da9cd4e62fd04631", "size": 1744, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "HW4f7/P3.f", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW4f7/P3.f", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW4f7/P3.f", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.2753623188, "max_line_length": 69, "alphanum_fraction": 0.5183486239, "num_tokens": 705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037732, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7610754842442856}} {"text": "C$Procedure VNORMG ( Vector norm, general dimension )\n \n DOUBLE PRECISION FUNCTION VNORMG ( V1, NDIM )\n \nC$ Abstract\nC\nC Compute the magnitude of a double precision vector of arbitrary\nC dimension.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC VECTOR\nC\nC$ Declarations\n \n INTEGER NDIM\n DOUBLE PRECISION V1 ( NDIM )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC V1 I Vector whose magnitude is to be found.\nC NDIM I Dimension of V1.\nC\nC$ Detailed_Input\nC\nC V1 This may be any double precision vector or arbitrary\nC size.\nC\nC$ Detailed_Output\nC\nC VNORMG is the magnitude of V1 calculated in a numerically stable\nC way.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Particulars\nC\nC VNORMG finds the component of V1 whose magnitude is the largest.\nC If the absolute magnitude of that component indicates that a\nC numeric overflow would occur when it is squared, or if it\nC indicates that an underflow would occur when squared (falsely\nC giving a magnitude of zero) then the following expression is\nC used:\nC\nC VNORMG = V1MAX * MAGNITUDE OF [ (1/V1MAX)*V1 ]\nC\nC Otherwise a simpler expression is used:\nC\nC VNORMG = MAGNITUDE OF [ V1 ]\nC\nC Beyond the logic described above, no further checking of the\nC validity of the input is performed.\nC\nC$ Examples\nC\nC The following table show the correlation between various input\nC vectors V1 and VNORMG:\nC\nC NDIM V1(NDIM) VNORMG\nC -----------------------------------------------------------------\nC 1 (-7.0D20) 7.D20\nC 3 (1.D0, 2.D0, 2.D0) 3.D0\nC 4 (3.D0, 3.D0, 3.D0, 3.D0) 6.D0\nC 5 (5.D0, 12.D0, 0.D0, 0.D0, 0.D0) 13.D0\nC 3 (-5.D-17, 0.0D0, 12.D-17) 13.D-17\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.M. Owen (JPL)\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WMO)\nC\nC-&\n \nC$ Index_Entries\nC\nC norm of n-dimensional vector\nC\nC-&\n \n INTEGER I\n DOUBLE PRECISION V1MAX\n DOUBLE PRECISION A\n \nC\nC Determine the maximum component of the vector.\nC\n V1MAX = 0.D0\n \n DO I=1,NDIM\n \n IF ( DABS(V1(I)) .GT. V1MAX )\n . V1MAX = DABS(V1(I))\n \n END DO\nC\nC If the vector is zero, return zero; otherwise normalize first.\nC Normalizing helps in the cases where squaring would cause overflow\nC or underflow. In the cases where such is not a problem it not worth\nC it to optimize further.\nC\n IF ( V1MAX .EQ. 0.D0 ) THEN\n \n VNORMG = 0.D0\n \n ELSE\n \n VNORMG = 0.D0\n \n DO I = 1, NDIM\n A = V1(I) / V1MAX\n VNORMG = VNORMG + A*A\n END DO\n \n VNORMG = V1MAX * DSQRT (VNORMG)\n \n END IF\nC\n RETURN\n END\n", "meta": {"hexsha": "660eaf3545fa704351916e8abad76855c5f03673", "size": 4664, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/vnormg.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/vnormg.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/vnormg.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 26.3502824859, "max_line_length": 72, "alphanum_fraction": 0.6177101201, "num_tokens": 1389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248140158416, "lm_q2_score": 0.8104789155369048, "lm_q1q2_score": 0.7610598129258029}} {"text": "\n PROGRAM TEST\n\n! This is a sample program using 14th order Runge Kutta to solve ordinary differential\n! equations (initial value problems) to high precision.\n\n! Subroutine FM_RK14 uses a starting point A, stopping point B, and tolerance TOL.\n! FM_RK14 calls FM_RK14_STEP for the individual steps, adjusting the step size along the\n! way to try to keep the distance between the approximate solution vector S1 and the true\n! solution less than TOL. TOL should be no smaller than 1.0e-75.\n\n! Subroutine FM_RK14_COEFFS is called by FM_RK14_STEP to initialize the many coefficients\n! used to define the 14th order Runge Kutta formula. They are defined with 85-digit\n! accuracy, so accuracy up to about 75 digits can be achieved by these routines.\n\n! The speed of FM_RK14 drops quickly as the requested precision increases, since more\n! steps (with smaller stepsize) are needed to get from A to B, and also because higher\n! FM precision must be used.\n\n! For a typical 2014 computer, here are the times for the third-order equation in case 3:\n\n! TOL FM precision time (seconds)\n! 1e-20 30 0.18\n! 1e-30 40 1.13\n! 1e-40 50 7.06\n! 1e-50 60 43.91\n\n! Since RK14 has error O(h^14), the stepsize h needed for a given tol is of order tol^(1/14).\n! That gives a total number of steps proportional to tol^(-1/14) and means that decreasing\n! tol by a factor of 1e+10 will multiply the total number of steps required by about\n! 1e-10^(-1/14) = 5.2.\n\n! The actual time ratios in the table above are 6.3, 6.2, 6.2, slightly more than 5.2,\n! because the time for each step increases as FM precision goes up.\n\n\n USE FMZM\n IMPLICIT NONE\n\n! Set MAXIMUM_ORDER here and in the subroutines to the highest order\n! differential equation to be solved.\n\n INTEGER, PARAMETER :: MAXIMUM_ORDER = 3\n INTEGER :: N_FUNCTION, N_ORDER\n TYPE (FM) :: A, B, ERR, S(MAXIMUM_ORDER), S1(MAXIMUM_ORDER), TOL\n EXTERNAL :: FM_RK14_F\n REAL :: T1, T2\n\n! Set the FM precision level to 40 significant digits for cases 1 through 3.\n\n CALL FM_SET(40)\n\n\n! We will use differential equations with known analytic solutions so we can check\n! the accuracy of the result.\n\n\n\n! 1. First-order equation.\n\n! y' = -y + 2*sin(x), y(0) = 0\n\n! The right-hand-side function is defined as function number 1\n! in subroutine FM_RK14_F (at the end of this file).\n\n! Since this is a first-order equation, the \"state\" vector S is just y.\n\n! Set tol = 1e-30 and find y(5).\n\n\n CALL CPU_TIME(T1)\n\n N_ORDER = 1\n N_FUNCTION = 1\n A = 0\n B = 5\n S(1) = 0\n TOL = TO_FM(' 1.0e-30 ')\n\n CALL FM_RK14( A, B, N_ORDER, FM_RK14_F, N_FUNCTION, S, TOL, S1 )\n\n WRITE (*,*) ' '\n WRITE (*,*) ' Case 1. y(5) ='\n CALL FM_PRINT(S1(1))\n WRITE (*,*) ' '\n ERR = ABS( (SIN(B) - COS(B) + EXP(-B)) - S1(1) )\n WRITE (*,\"(A,ES16.7)\") ' Error in the computed solution = ',TO_DP(ERR)\n\n\n CALL CPU_TIME(T2)\n WRITE (*,*) ' '\n WRITE (*,\"(5X,A,ES12.4,A,F8.2,A)\") ' For tolerance = ',TO_DP(TOL),' time = ',T2-T1,' sec.'\n WRITE (*,*) ' '\n WRITE (*,*) ' '\n\n\n\n! 2. Second-order equation.\n\n! y'' = -y' - exp(x)*y + sin(x) - exp(-x)*(sin(x) + cos(x)),\n! y(0) = 0, y'(0) = 1.\n\n! The right-hand-side function is defined as function number 2\n! in subroutine FM_RK14_F (at the end of this file).\n\n! First reduce this equation to a system of first-order equations.\n\n! Let u = y'. Then u' = y''. Now for s = ( y, u ) the vector\n! differential equation is\n\n! s' = ( y', u' ) = ( u, -u + exp(x)*y + sin(x) - exp(-x)*(sin(x) + cos(x)) )\n! s(0) = ( y(0), u(0) ) = ( 0, 1 ).\n\n! Find y(2).\n\n\n CALL CPU_TIME(T1)\n\n N_ORDER = 2\n N_FUNCTION = 2\n A = 0\n B = 2\n S(1:2) = (/ 0, 1 /)\n TOL = TO_FM(' 1.0e-30 ')\n\n CALL FM_RK14( A, B, N_ORDER, FM_RK14_F, N_FUNCTION, S, TOL, S1 )\n\n WRITE (*,*) ' '\n WRITE (*,*) ' Case 2. y(2) ='\n CALL FM_PRINT(S1(1))\n WRITE (*,*) \" y'(2) =\"\n CALL FM_PRINT(S1(2))\n WRITE (*,*) ' '\n ERR = ABS( (SIN(B)*EXP(-B)) - S1(1) )\n WRITE (*,\"(A,ES16.7)\") ' Error in the computed y(2) solution = ',TO_DP(ERR)\n\n\n CALL CPU_TIME(T2)\n WRITE (*,*) ' '\n WRITE (*,\"(5X,A,ES12.4,A,F8.2,A)\") ' For tolerance = ',TO_DP(TOL),' time = ',T2-T1,' sec.'\n WRITE (*,*) ' '\n WRITE (*,*) ' '\n\n\n! 3. Third-order equation.\n\n! y''' = -y'' -y' - y + ( ( -35x**3 + 2x**2 + 111x + 68 )*cos(6x) +\n! ( 210x**3 + 642x**2 + 618x + 186 )*sin(6x) ) / (1+x)**4\n! y(0) = 1, y'(0) = -1, y''(0) = -34.\n\n! The right-hand-side function is defined as function number 3\n! in subroutine FM_RK14_F (at the end of this file).\n\n! First reduce this equation to a system of first-order equations.\n\n! let u = y' and v = y''. Then v' = y'''. Now for s = ( y, u, v ) the vector\n! differential equation is\n\n! s' = ( y', u', v' ) =\n! ( u , v , -v - u - y +\n! ( ( -35x**3 + 2x**2 + 111x + 68 )*cos(6x) +\n! ( 210x**3 + 642x**2 + 618x + 186 )*sin(6x) ) / (1+x)**4 )\n! s(0) = ( y(0), u(0), v(0) ) = ( 1, -1, -34 ).\n\n! Find y(2).\n\n\n CALL CPU_TIME(T1)\n\n N_ORDER = 3\n N_FUNCTION = 3\n A = 0\n B = 2\n S(1:3) = (/ 1, -1, -34 /)\n TOL = TO_FM(' 1.0e-30 ')\n\n CALL FM_RK14( A, B, N_ORDER, FM_RK14_F, N_FUNCTION, S, TOL, S1 )\n\n WRITE (*,*) ' '\n WRITE (*,*) ' Case 3. y(2) ='\n CALL FM_PRINT(S1(1))\n WRITE (*,*) \" y'(2) =\"\n CALL FM_PRINT(S1(2))\n WRITE (*,*) \" y''(2) =\"\n CALL FM_PRINT(S1(3))\n WRITE (*,*) ' '\n ERR = ABS( (COS(6*B)/(B+1)) - S1(1) )\n WRITE (*,\"(A,ES16.7)\") ' Error in the computed y(2) solution = ',TO_DP(ERR)\n\n\n CALL CPU_TIME(T2)\n WRITE (*,*) ' '\n WRITE (*,\"(5X,A,ES12.4,A,F8.2,A)\") ' For tolerance = ',TO_DP(TOL),' time = ',T2-T1,' sec.'\n WRITE (*,*) ' '\n WRITE (*,*) ' '\n\n\n\n\n! 4. Solve case 3 again, this time asking for 20 digit accuracy.\n! For this case we can lower the FM precision level to 30 digits.\n\n CALL FM_SET(30)\n\n CALL CPU_TIME(T1)\n\n N_ORDER = 3\n N_FUNCTION = 3\n A = 0\n B = 2\n S(1:3) = (/ 1, -1, -34 /)\n TOL = TO_FM(' 1.0e-20 ')\n\n CALL FM_RK14( A, B, N_ORDER, FM_RK14_F, N_FUNCTION, S, TOL, S1 )\n\n WRITE (*,*) ' '\n WRITE (*,*) ' Case 4. y(2) ='\n CALL FM_PRINT(S1(1))\n WRITE (*,*) \" y'(2) =\"\n CALL FM_PRINT(S1(2))\n WRITE (*,*) \" y''(2) =\"\n CALL FM_PRINT(S1(3))\n WRITE (*,*) ' '\n ERR = ABS( (COS(6*B)/(B+1)) - S1(1) )\n WRITE (*,\"(A,ES16.7)\") ' Error in the computed y(2) solution = ',TO_DP(ERR)\n\n\n CALL CPU_TIME(T2)\n WRITE (*,*) ' '\n WRITE (*,\"(5X,A,ES12.4,A,F8.2,A)\") ' For tolerance = ',TO_DP(TOL),' time = ',T2-T1,' sec.'\n WRITE (*,*) ' '\n WRITE (*,*) ' '\n\n\n\n! 5. Same as case 4, but use TOL = 1.0e-40.\n! The FM precision level should be set to at least 10 digits more than TOL.\n\n CALL FM_SET(50)\n\n CALL CPU_TIME(T1)\n\n N_ORDER = 3\n N_FUNCTION = 3\n A = 0\n B = 2\n S(1:3) = (/ 1, -1, -34 /)\n TOL = TO_FM(' 1.0e-40 ')\n\n CALL FM_RK14( A, B, N_ORDER, FM_RK14_F, N_FUNCTION, S, TOL, S1 )\n\n WRITE (*,*) ' '\n WRITE (*,*) ' Case 5. y(2) ='\n CALL FM_PRINT(S1(1))\n WRITE (*,*) \" y'(2) =\"\n CALL FM_PRINT(S1(2))\n WRITE (*,*) \" y''(2) =\"\n CALL FM_PRINT(S1(3))\n WRITE (*,*) ' '\n ERR = ABS( (COS(6*B)/(B+1)) - S1(1) )\n WRITE (*,\"(A,ES16.7)\") ' Error in the computed y(2) solution = ',TO_DP(ERR)\n\n\n CALL CPU_TIME(T2)\n WRITE (*,*) ' '\n WRITE (*,\"(5X,A,ES12.4,A,F8.2,A)\") ' For tolerance = ',TO_DP(TOL),' time = ',T2-T1,' sec.'\n WRITE (*,*) ' '\n WRITE (*,*) ' '\n\n\n\n! 6. Same as case 4, but use TOL = 1.0e-50.\n\n! The FM precision level should be set to at least 10 digits more than TOL.\n\n\n CALL FM_SET(60)\n\n CALL CPU_TIME(T1)\n\n N_ORDER = 3\n N_FUNCTION = 3\n A = 0\n B = 2\n S(1:3) = (/ 1, -1, -34 /)\n TOL = TO_FM(' 1.0e-50 ')\n\n CALL FM_RK14( A, B, N_ORDER, FM_RK14_F, N_FUNCTION, S, TOL, S1 )\n\n WRITE (*,*) ' '\n WRITE (*,*) ' Case 6. y(2) ='\n CALL FM_PRINT(S1(1))\n WRITE (*,*) \" y'(2) =\"\n CALL FM_PRINT(S1(2))\n WRITE (*,*) \" y''(2) =\"\n CALL FM_PRINT(S1(3))\n WRITE (*,*) ' '\n ERR = ABS( (COS(6*B)/(B+1)) - S1(1) )\n WRITE (*,\"(A,ES16.7)\") ' Error in the computed y(2) solution = ',TO_DP(ERR)\n\n CALL CPU_TIME(T2)\n WRITE (*,*) ' '\n WRITE (*,\"(5X,A,ES12.4,A,F8.2,A)\") ' For tolerance = ',TO_DP(TOL),' time = ',T2-T1,' sec.'\n WRITE (*,*) ' '\n WRITE (*,*) ' '\n\n STOP\n END PROGRAM TEST\n\n\n SUBROUTINE FM_RK14_F(N_ORDER, N_FUNCTION, X, S, RHS)\n\n! Compute the right-hand-side function for the vector first-order differential equation\n! s' = f(x,s).\n\n! N_ORDER is the order of the differential equation. After reducing the equation to\n! a first-order vector D.E., N_ORDER is the length of vectors S and RHS.\n! (N_ORDER is unused in this sample version)\n\n! RHS is returned as the right-hand-side vector function of the differential equation,\n! with S as the input vector: RHS = F(X,S).\n\n! N_FUNCTION is the function to be evaluated, for cases where a program may solve\n! several different differential equations.\n\n\n USE FMZM\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: MAXIMUM_ORDER = 3\n INTEGER :: N_ORDER, N_FUNCTION\n TYPE (FM) :: X, S(MAXIMUM_ORDER), RHS(MAXIMUM_ORDER)\n TYPE (FM), SAVE :: T1, T2, T3\n\n IF (N_FUNCTION == 1) THEN\n\n! y' = -y + 2*sin(x)\n\n RHS(1) = -S(1) + 2*SIN(X)\n ELSE IF (N_FUNCTION == 2) THEN\n\n! y'' = -y' - exp(x)*y + sin(x) - exp(-x)*(sin(x) + cos(x))\n\n RHS(1) = S(2)\n\n! Note about code-tuning.\n! This is the straight-forward way of coding RHS(2) from the differential equation:\n\n! RHS(2) = -S(2) - EXP(X)*S(1) + SIN(X) - EXP(-X)*(SIN(X) + COS(X))\n\n! Using the code above, case 2 in the main program ran in 1.22 seconds.\n\n! We can speed this up by computing sin(x) once instead of twice for each function\n! evaluation. Also, doing exp(-x) as 1/exp(x) can save an exponential.\n! More time can be saved by using subroutine FM_COS_SIN, which returns both\n! cos(x) and sin(x) in one call. FM_COS_SIN computes one of the trig functions,\n! and then gets the other quickly using an identity.\n\n! Three local variables, T1, T2, T3, are used to save exp(x), cos(x), sin(x).\n! The code below then ran case 2 in 0.75 seconds.\n\n T1 = EXP(X)\n CALL FM_COS_SIN(X,T2,T3)\n RHS(2) = -S(2) - T1*S(1) + T3 - (T3 + T2) / T1\n ELSE IF (N_FUNCTION == 3) THEN\n\n! y''' = -y'' -y' - y + ( ( -35x**3 + 2x**2 + 111x + 68 )*cos(6x) +\n! ( 210x**3 + 642x**2 + 618x + 186 )*sin(6x) ) / (1+x)**4\n\n RHS(1) = S(2)\n RHS(2) = S(3)\n\n! More code-tuning.\n! Original code in case 3: 1.65 seconds.\n\n! RHS(3) = -S(3) - S(2) - S(1) + &\n! ( ( -35*X**3 + 2*X**2 + 111*X + 68 )*COS(6*X) + &\n! ( 210*X**3 + 642*X**2 + 618*X + 186 )*SIN(6*X) ) / (1+X)**4\n\n! Use FM_COS_SIN as in function 2 above for the trig functions: 1.38 seconds.\n\n! CALL FM_COS_SIN(6*X,T2,T3)\n! RHS(3) = -S(3) - S(2) - S(1) + &\n! ( ( -35*X**3 + 2*X**2 + 111*X + 68 )*T2 + &\n! ( 210*X**3 + 642*X**2 + 618*X + 186 )*T3 ) / (1+X)**4\n\n! Use Horner's rule for the polynomials: 1.30 seconds.\n\n CALL FM_COS_SIN(6*X,T2,T3)\n RHS(3) = -S(3) - S(2) - S(1) + &\n ( ((( -35*X + 2)*X + 111)*X + 68 )*T2 + &\n ((( 210*X + 642)*X + 618)*X + 186 )*T3 ) / (1+X)**4\n\n ELSE\n RHS = S(1)\n ENDIF\n\n END SUBROUTINE FM_RK14_F\n", "meta": {"hexsha": "89d233ca067a1ec1c413551c09eae8a328af8c92", "size": 12993, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Libraries/FM/FMsamples/DiffEqFM.f95", "max_stars_repo_name": "andreypudov/projecteuler", "max_stars_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2022-01-30T20:37:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T21:03:21.000Z", "max_issues_repo_path": "Libraries/FM/FMsamples/DiffEqFM.f95", "max_issues_repo_name": "andreypudov/projecteuler", "max_issues_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Libraries/FM/FMsamples/DiffEqFM.f95", "max_forks_repo_name": "andreypudov/projecteuler", "max_forks_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.5639097744, "max_line_length": 98, "alphanum_fraction": 0.4848764719, "num_tokens": 4292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7609631288279307}} {"text": "! Name: Anantha Rao\n! Reg no: 20181044\n! This program provides the Runge-Kutta4 Method to solve the differential equation y' = f(x,y)\n\nprogram rungekutta\n implicit none\n real:: x,y,xwant,h,m1,m2,m3,m4,f\n integer:: niter,i\n\n x=0.0; y=0.0; xwant=1.57; h=0.01; \n niter=int((xwant-x)/h)\n open(unit=21, file=\"q1_rk4.dat\")\n\n do i=1,niter\n m1=h*f(x,y)\n m2=h*f(x+0.5*h,y+0.5*m1)\n m3=h*f(x+0.5*h,y+0.5*m2)\n m4=h*f(x+h,y+m3)\n x=x+h\n y=y+(m1+2.0*m2+2.0*m3+m4)*(1/6.0)\n write(21,*) dfloat(i)*h,y\n end do\nend program\n\n!define your function here\nreal function f(x,y)\nreal:: x,y\nf=1+y**2\n\nend function\n", "meta": {"hexsha": "08aad4c00ca4eaa0d39be42776d74bad6b9ffcb2", "size": 660, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/assgn05_solns/Assgn05_Solutions/Assgn05_solutions_Q1/q1_rk4.f90", "max_stars_repo_name": "Anantha-Rao12/ComPhys", "max_stars_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Solutions/assgn05_solns/Assgn05_Solutions/Assgn05_solutions_Q1/q1_rk4.f90", "max_issues_repo_name": "Anantha-Rao12/ComPhys", "max_issues_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Solutions/assgn05_solns/Assgn05_Solutions/Assgn05_solutions_Q1/q1_rk4.f90", "max_forks_repo_name": "Anantha-Rao12/ComPhys", "max_forks_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.2903225806, "max_line_length": 94, "alphanum_fraction": 0.5727272727, "num_tokens": 271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308091776495, "lm_q2_score": 0.8152324915965391, "lm_q1q2_score": 0.7609631242988689}} {"text": "module maptran\n\nuse, intrinsic:: ieee_arithmetic, only: ieee_quiet_nan, ieee_value\n\nimplicit none (type, external)\nprivate\npublic :: pi, ecef2geodetic, geodetic2ecef, aer2enu, enu2aer, aer2ecef, ecef2aer, &\n enu2ecef, ecef2enu, ecef2enuv, aer2geodetic, geodetic2enu, enu2uvw,&\n geodetic2aer,enu2geodetic,degrees,radians, anglesep, &\n lookAtSpheroid, Ellipsoid, &\n haversine\n\ntype :: Ellipsoid\n real :: SemimajorAxis, Flattening, SemiminorAxis\nend type\n\nreal, parameter :: pi = 4 * atan(1.)\n\ntype(Ellipsoid), parameter, public :: wgs84Ellipsoid = &\n Ellipsoid(SemimajorAxis=6378137., &\n SemiminorAxis=6378137. * (1 - 1. / 298.2572235630), &\n Flattening = 1. / 298.2572235630)\n\ninterface ! aer\nmodule elemental subroutine ecef2aer(x, y, z, lat0, lon0, alt0, az, el, slantRange, spheroid, deg)\nreal, intent(in) :: x,y,z, lat0, lon0, alt0\ntype(Ellipsoid), intent(in), optional :: spheroid\nlogical, intent(in), optional :: deg\nreal, intent(out) :: az,el, slantRange\nend subroutine ecef2aer\n\nmodule elemental subroutine aer2ecef(az, el, slantRange, lat0, lon0, alt0, x,y,z, spheroid, deg)\nreal, intent(in) :: az,el, slantRange, lat0, lon0, alt0\ntype(Ellipsoid), intent(in), optional :: spheroid\nlogical, intent(in), optional :: deg\nreal, intent(out) :: x,y,z\nend subroutine aer2ecef\n\nmodule elemental subroutine geodetic2aer(lat, lon, alt, lat0, lon0, alt0, az, el, slantRange, spheroid, deg)\nreal, intent(in) :: lat,lon,alt, lat0, lon0, alt0\ntype(Ellipsoid), intent(in), optional :: spheroid\nlogical, intent(in), optional :: deg\nreal, intent(out) :: az, el, slantRange\nend subroutine geodetic2aer\n\nmodule elemental subroutine aer2geodetic(az, el, slantRange, lat0, lon0, alt0, lat1, lon1, alt1, spheroid, deg)\nreal, intent(in) :: az, el, slantRange, lat0, lon0, alt0\ntype(Ellipsoid), intent(in), optional :: spheroid\nlogical, intent(in), optional :: deg\nreal, intent(out) :: lat1,lon1,alt1\nend subroutine aer2geodetic\n\nend interface\n\ninterface ! ecef\n\nmodule elemental subroutine ecef2geodetic(x, y, z, lat, lon, alt, spheroid, deg)\nreal, intent(in) :: x,y,z\ntype(Ellipsoid), intent(in), optional :: spheroid\nlogical, intent(in), optional :: deg\nreal, intent(out) :: lat, lon\nreal, intent(out), optional :: alt\nend subroutine ecef2geodetic\n\nmodule elemental subroutine geodetic2ecef(llat,llon,alt, x,y,z, spheroid, deg)\nreal, intent(in) :: llat,llon, alt\nreal, intent(out) :: x,y,z\ntype(Ellipsoid), intent(in), optional :: spheroid\nlogical, intent(in), optional :: deg\nend subroutine geodetic2ecef\n\nmodule elemental subroutine enu2ecef(e, n, u, lat0, lon0, alt0, x, y, z, spheroid, deg)\nreal, intent(in) :: e,n,u,lat0,lon0,alt0\ntype(Ellipsoid), intent(in), optional :: spheroid\nlogical, intent(in), optional :: deg\nreal, intent(out) :: x,y,z\nend subroutine enu2ecef\n\nmodule elemental subroutine ecef2enu(x, y, z, lat0, lon0, alt0, east, north, up, spheroid, deg)\nreal, intent(in) :: x,y,z,lat0,lon0,alt0\ntype(Ellipsoid), intent(in), optional :: spheroid\nlogical, intent(in), optional :: deg\nreal, intent(out) :: east,north,up\nend subroutine ecef2enu\n\nmodule elemental subroutine ecef2enuv(u, v, w, llat0, llon0, east, north, up, deg)\nreal, intent(in) :: u,v,w\nreal, intent(in) :: llat0,llon0\nlogical, intent(in), optional :: deg\nreal, intent(out) :: east, north, up\nend subroutine ecef2enuv\n\nend interface\n\ninterface ! enu\n\nmodule elemental subroutine geodetic2enu(lat, lon, alt, lat0, lon0, alt0, east, north, up, spheroid, deg)\nreal, intent(in) :: lat, lon, alt, lat0, lon0, alt0\ntype(Ellipsoid), intent(in), optional :: spheroid\nlogical, intent(in), optional :: deg\nreal, intent(out) :: east, north, up\nend subroutine geodetic2enu\n\nmodule elemental subroutine enu2geodetic(east, north, up, lat0, lon0, alt0, lat, lon, alt, spheroid, deg)\nreal, intent(in) :: east, north, up, lat0, lon0, alt0\ntype(Ellipsoid), intent(in), optional :: spheroid\nlogical, intent(in), optional :: deg\nreal, intent(out) :: lat, lon, alt\nend subroutine enu2geodetic\n\nmodule elemental subroutine aer2enu(az, el, slantRange, east, north, up, deg)\nreal, intent(in) :: az,el !< not value due to ifort segfault bug\nreal, intent(in) :: slantRange\nlogical, intent(in), optional :: deg\nreal,intent(out) :: east, north,up\nend subroutine aer2enu\n\nmodule elemental subroutine enu2aer(east, north, up, az, elev, slantRange, deg)\nreal,intent(in) :: east, north, up\nlogical, intent(in), optional :: deg\nreal, intent(out) :: az, elev, slantRange\nend subroutine enu2aer\n\n\nmodule elemental subroutine lookAtSpheroid(lat0, lon0, h0, az, tilt, lat, lon, srange, spheroid, deg)\nreal, intent(in) :: lat0, lon0, h0, az, tilt\ntype(Ellipsoid), intent(in), optional :: spheroid\nlogical, intent(in), optional :: deg\nreal, intent(out) :: lat, lon, srange\nend subroutine lookAtSpheroid\n\nend interface\n\ninterface ! utils.f90\nmodule elemental subroutine enu2uvw(east,north,up, llat0,llon0, u,v,w, deg)\nreal, intent(in) :: east,north,up\nreal, intent(in) :: llat0,llon0\nreal, intent(out) :: u,v,w\nlogical, intent(in), optional :: deg\nend subroutine enu2uvw\n\nmodule elemental real function anglesep(lon0,lat0,lon1,lat1)\nreal, intent(in) :: lat0,lon0,lat1,lon1\nend function anglesep\nend interface\n\ncontains\n\n\nelemental real function haversine(theta)\n!! theta: angle in RADIANS\nreal, intent(in) :: theta\n\nhaversine = (1 - cos(theta)) / 2\n\nend function haversine\n\n\nelemental real function degrees(rad)\nreal, intent(in) :: rad\n\ndegrees = 180 / pi * rad\nend function degrees\n\n\nelemental real function radians(deg)\nreal, intent(in) :: deg\n\nradians = pi / 180 * deg\nend function radians\n\nend module maptran\n", "meta": {"hexsha": "ac6db8ebe0ccfb162e50323b7f860671ce09e822", "size": 5603, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/maptran.f90", "max_stars_repo_name": "scivision/maptran", "max_stars_repo_head_hexsha": "e7e6f05ad6585dc61569068aa2766797d5b39e12", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-07-11T12:07:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-11T07:45:17.000Z", "max_issues_repo_path": "src/maptran.f90", "max_issues_repo_name": "scivision/maptran3d", "max_issues_repo_head_hexsha": "463becf1efc23721cc6f0340d786ece9f5f8729e", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/maptran.f90", "max_forks_repo_name": "scivision/maptran3d", "max_forks_repo_head_hexsha": "463becf1efc23721cc6f0340d786ece9f5f8729e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.387283237, "max_line_length": 111, "alphanum_fraction": 0.7222916295, "num_tokens": 1817, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541544761566, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7609198509141781}} {"text": "\tFUNCTION PR_WNML ( drct, sped, dcmp )\nC************************************************************************\nC* PR_WNML \t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes the wind component toward a direction 90\t*\nC* degrees counterclockwise of a specified direction. If no\t\t*\nC* direction is specified, the component toward north is returned.\t*\nC* The following equation is used:\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* WNML = -COS ( DRCT - ( DCMP-90 ) ) * SPED\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* WNML = component of wind in meters/second\t\t\t*\nC* DRCT = wind direction in degrees\t\t\t\t*\nC* DCMP = specified direction\t\t\t\t\t*\nC* SPED = wind speed in meters/second\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_WNML ( DRCT, SPED, DCMP )\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tDRCT\t\tREAL\t\tWind direction in degrees\t*\nC*\tSPED\t\tREAL\t\tWind speed in meters/sec\t*\nC*\tDCMP\t\tREAL\t\tInput direction in degrees\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_WNML\t\tREAL\t\tComponent of wind in m/s\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* John Nielsen/MIT\t9/88\t\t\t\t\t\t*\nC* John Nielsen/SUNYA\t8/90\tGEMPAK 5\t\t\t\t*\nC* J. Whistler/SSAI\t7/91\tChanged COSD to COS and converted to rad*\nC* T. Piper/GSC\t\t11/98\tUpdated prolog\t\t\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\n\tINCLUDE\t\t'ERMISS.FNC'\nC------------------------------------------------------------------------\nC* \tCheck for missing input parameters.\nC\n\tIF ( ERMISS ( sped ) .or. ERMISS ( drct ) ) THEN\n\t PR_WNML = RMISSD\n\t ELSE IF ( ( dcmp .lt. 0. ) .or. ( dcmp .gt. 360. ) ) THEN\n\t\tPR_WNML = RMISSD\n\t ELSE\nC\nC*\t Calculate wind speed 90 degrees to left of given direction.\nC\n\t PR_WNML = (-COS( ( drct - dcmp - 90. ) * DTR )) * sped\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "fb68c985c9324ee6b5b2fedd4320ca10e3810ec0", "size": 1756, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prwnml.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/prmcnvlib/pr/prwnml.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/prmcnvlib/pr/prwnml.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 34.431372549, "max_line_length": 73, "alphanum_fraction": 0.520501139, "num_tokens": 565, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750427013548, "lm_q2_score": 0.798186784940666, "lm_q1q2_score": 0.7608915414979704}} {"text": "!-----------------------------------------------------------------------\n function power2(number)\n! Returns TRUE if the number is a power of 2, if not it returns FALSE \n implicit none\n integer :: number,x\n logical :: power2\n x = number\n ! write(*,*) x\n if (x .eq. 0)then \n power2 = .false.\n return\n endif\n \n do while(MOD(x,2) .eq. 0)\n x = x / 2\n end do\n if (x .gt. 1) then\n power2 =.false.\n return\n else\n power2 = .true.\n endif\n \n end function power2\n!-----------------------------------------------------------------------\n", "meta": {"hexsha": "6b0264cef1c5725817922bce3245fc86a87c770b", "size": 695, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "subroutines/power2.f90", "max_stars_repo_name": "mgullik/data_analysis", "max_stars_repo_head_hexsha": "b91ae014bfa280ba7e7fa3a48600b18eeb74eafe", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "subroutines/power2.f90", "max_issues_repo_name": "mgullik/data_analysis", "max_issues_repo_head_hexsha": "b91ae014bfa280ba7e7fa3a48600b18eeb74eafe", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "subroutines/power2.f90", "max_forks_repo_name": "mgullik/data_analysis", "max_forks_repo_head_hexsha": "b91ae014bfa280ba7e7fa3a48600b18eeb74eafe", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.7307692308, "max_line_length": 72, "alphanum_fraction": 0.3482014388, "num_tokens": 153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8670357615200474, "lm_q1q2_score": 0.7608037546504826}} {"text": "double precision function true_solution(x, t)\n\n! True solution for the porous medium equation,\n! q_t = (q**2)_xx.\n\n double precision :: x, t\n double precision :: mass, tau, t0\n parameter(mass = 1.d0)\n parameter(t0 = .3d0)\n\n tau = t + t0\n true_solution = (mass - 1.d0/12.d0 * x**2 / tau**(2.d0/3.d0)) / tau**(1.d0/3.d0)\n if (true_solution < 0.d0) true_solution = 0.d0\nend function true_solution\n", "meta": {"hexsha": "e7253b33f2e73cb11cf4342b74cd08a7951a2141", "size": 419, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/1d/Order2Nonlinear/true_solution.f90", "max_stars_repo_name": "claridge/implicit_solvers", "max_stars_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-04-29T00:16:18.000Z", "max_stars_repo_stars_event_max_datetime": "2017-04-29T00:16:18.000Z", "max_issues_repo_path": "applications/1d/Order2Nonlinear/true_solution.f90", "max_issues_repo_name": "claridge/implicit_solvers", "max_issues_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/1d/Order2Nonlinear/true_solution.f90", "max_forks_repo_name": "claridge/implicit_solvers", "max_forks_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.9333333333, "max_line_length": 84, "alphanum_fraction": 0.6276849642, "num_tokens": 142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9719924777713886, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7607420471036132}} {"text": "\n PROGRAM TEST\n\n! One use for FM involves programs that don't need multiple precision results but do need some\n! of the special functions available in FM but not in the Fortran standard. These include:\n\n! BERNOULLI(N)\n! BETA(X,Y)\n! BINOMIAL(N,K) or BINOMIAL(X,Y)\n! COS_INTEGRAL(X)\n! COSH_INTEGRAL(X)\n! EXP_INTEGRAL_EI(X)\n! EXP_INTEGRAL_EN(N,X)\n! FRESNEL_C(X)\n! FRESNEL_S(X)\n! INCOMPLETE_BETA(X,A,B)\n! INCOMPLETE_GAMMA1(X,Y)\n! INCOMPLETE_GAMMA2(X,Y)\n! LOG_INTEGRAL(X)\n! POCHHAMMER(X,N)\n! POLYGAMMA(N,X)\n! PSI(X)\n! SIN_INTEGRAL(X)\n! SINH_INTEGRAL(X)\n\n! See the complete list of FM functions in FM_User_Manual.txt.\n\n! For this application, no TYPE(FM) variables need to be declared. Just add USE FMZM at the top\n! and compile and link the program like SampleFM.f95.\n\n USE FMZM\n IMPLICIT NONE\n\n INTEGER :: J\n DOUBLE PRECISION :: A, B, C, C_FM, ERR, MAX_ERR\n\n! To use with 53-bit double precision, having about 16 significant digits of accuracy,\n! set the FM precision to 16 digits.\n\n CALL FM_SET(16)\n\n\n! 1. Check to see if Fortran's intrinsic gamma function is correctly rounded.\n\n! A is the double precision variable, so GAMMA(A) uses Fortran's intrinsic gamma.\n\n! TO_FM(A) converts A to an FM number, so GAMMA( TO_FM(A) ) uses FM's gamma,\n! then the \"=\" rounds the result back to double precision variable C_FM.\n\n! It is possible that different compilers might give different results for this\n! test. Some compilers may not give results that are correctly rounded to full\n! double precision accuray when A is large, but C_FM should be correctly rounded.\n\n MAX_ERR = 0\n DO J = 10, 150, 10\n A = J + 0.5D0\n C = GAMMA(A)\n C_FM = GAMMA( TO_FM(A) )\n ERR = ABS( (C - C_FM) / C_FM )\n IF (ERR > MAX_ERR) THEN\n MAX_ERR = ERR\n B = A\n ENDIF\n ENDDO\n\n WRITE (*,\"(///A/)\") \" Sample 1. Compare Fortran's built-in gamma function to FM's\"\n IF (MAX_ERR > 0) THEN\n A = B\n WRITE (*,\"(A,ES13.7,A,F7.3)\") ' Maximum relative error in Fortran gamma was ', &\n MAX_ERR, ' for A = ', A\n C = GAMMA(A)\n WRITE (*,\"(ES25.15,A)\") C, ' = GAMMA(A)'\n C_FM = GAMMA( TO_FM(A) )\n WRITE (*,\"(ES25.15,A)\") C_FM, ' = GAMMA( TO_FM(A) )'\n ELSE\n WRITE (*,\"(A)\") ' All Fortran gamma results were correctly rounded.'\n ENDIF\n\n\n! 2. Binomial coefficients.\n\n! Find the probability of getting exactly 10,000 heads in 20,000 tosses\n! of a fair coin.\n\n! Here we could not store the results of the binomial and power separately in\n! double precision, since BINOMIAL( 20000, 10000 ) = 2.2e+6018 and\n! 2**20000 = 4.0e+6020 would both overflow in double precision.\n\n WRITE (*,\"(//A)\") \" Sample 2. Binomial coefficients\"\n WRITE (*,\"(A)\") \" Find the probability of getting exactly 10,000 heads\"\n WRITE (*,\"(A/)\") \" in 20,000 tosses of a fair coin.\"\n\n C_FM = BINOMIAL( TO_FM(20000), TO_FM(10000) ) / TO_FM(2)**20000\n\n WRITE (*,\"(A,F20.16)\") \" BINOMIAL( TO_FM(20000), TO_FM(10000) ) / TO_FM(2)**20000 =\", C_FM\n\n\n! 3. Log Integral function.\n\n! Estimate the number of primes less than 10**30.\n\n WRITE (*,\"(//A)\") \" Sample 3. Log integral\"\n WRITE (*,\"(A/)\") \" Estimate the number of primes less than 10**30.\"\n\n C_FM = LOG_INTEGRAL( TO_FM('1.0E+30') )\n\n WRITE (*,\"(A,ES23.15)\") \" LOG_INTEGRAL(TO_FM('1.0E+30')) =\", C_FM\n\n\n! 4. Psi and polygamma functions.\n\n! Rational series can often be summed using these functions.\n! Sum (n=1 to infinity) 1/(n**2 * (8n+1)**2) =\n! 16*(psi(1) - psi(9/8)) + polygamma(1,1) + polygamma(1,9/8)\n! Reference: Abramowitz & Stegun, Handbook of Mathematical Functions,\n! chapter 6, Example 10.\n\n WRITE (*,\"(//A)\") \" Sample 4. Psi and polygamma functions.\"\n WRITE (*,\"(A)\") \" Sum (n=1 to infinity) 1/(n**2 * (8n+1)**2) =\"\n WRITE (*,\"(A/)\") \" 16*(psi(1) - psi(9/8)) + polygamma(1,1) + polygamma(1,9/8)\"\n\n C_FM = 16*( PSI( TO_FM(1) ) - PSI( TO_FM(9)/8 ) ) + &\n POLYGAMMA( 1, TO_FM(1) ) + POLYGAMMA( 1, TO_FM(9)/8 )\n\n WRITE (*,\"(A,F19.16)\") \" Sum =\", C_FM\n\n\n! 5. Incomplete gamma and gamma functions.\n\n! Find the probability that an observed chi-square for a correct model should be\n! less that 2.3 when the number of degrees of freedom is 5.\n! Reference: Knuth, Volume 2, 3rd ed., Page 56, and Press, Flannery, Teukolsky,\n! Vetterling, Numerical Recipes, 1st ed., Page 165.\n\n WRITE (*,\"(//A/)\") \" Sample 5. Incomplete gamma and gamma functions.\"\n\n C_FM = INCOMPLETE_GAMMA1( TO_FM(5)/2, TO_FM('2.3')/2 ) / GAMMA( TO_FM(5)/2 )\n\n WRITE (*,\"(A,F19.16/)\") \" Probability =\", C_FM\n\n\n END PROGRAM TEST\n", "meta": {"hexsha": "7169a4a166319d516cb36462e235e3dc1f907f7c", "size": 5225, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Libraries/FM/FMsamples/SampleDPfunctions.f95", "max_stars_repo_name": "andreypudov/projecteuler", "max_stars_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2022-01-30T20:37:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T21:03:21.000Z", "max_issues_repo_path": "Libraries/FM/FMsamples/SampleDPfunctions.f95", "max_issues_repo_name": "andreypudov/projecteuler", "max_issues_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Libraries/FM/FMsamples/SampleDPfunctions.f95", "max_forks_repo_name": "andreypudov/projecteuler", "max_forks_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.5384615385, "max_line_length": 98, "alphanum_fraction": 0.5573205742, "num_tokens": 1569, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.8221891348788759, "lm_q1q2_score": 0.7607140162904077}} {"text": "!> Discrete Fourier (Inverse)Transform utilities.\n!!\n!! Procedures\n!! --------------------------------------\n!! dft Compute the discrete Fourier transform of a signal.\n!! idft Compute the inverse discrete Fourier transform of a frequency spectrum.\n!! idft_eval Compute the inverse discrete Fourier transform evaluated at user-specified points.\n!!\n!! @author Nathan A. Wukie\n!! @date 2/26/2018\n!!\n!----------------------------------------------------------------------\nmodule mod_dft\n#include \n use mod_kinds, only: ik, rk\n use mod_constants, only: PI, ZERO, ONE, TWO\n use mod_gridspace, only: linspace\n use DNAD_D\n implicit none\n\n\ncontains\n\n\n\n !> Computes the discrete Fourier transform of an input data set.\n !!\n !! ADAPTED FROM:\n !! www.nayuki.io/res/how-to-implement-the-discrete-fourier-transform/dft.py\n !!\n !! LICENCE: \n !! Public Domain\n !!\n !! Computes X[i] = (1/N)sum[ x(i)e^(-j*2pi*n*k*/N) ]\n !!\n !! NOTE: The normalization convention used here, (1/N), defines\n !! the DC part of the transform X[0] to be the average.\n !!\n !! The transform result is in 'standard' order:\n !! [ DC, omega_1, omega_2,..., omega_n, -omega_n, ... -omega_2, -omega_1]\n !!\n !! [DC| positive frequencies | negative frequencies ]\n !!\n !! @author Nathan A. Wukie\n !! @date 2/26/2018\n !!\n !! @param[in] input periodic signal\n !! @param[inout] outreal real part of DFT\n !! @param[inout] outimag imag part of DFT\n !!\n !-----------------------------------------------------------------\n subroutine dft(inreal,inimag,outreal,outimag,negate)\n type(AD_D), intent(in) :: inreal(:)\n type(AD_D), intent(in) :: inimag(:)\n type(AD_D), intent(inout), allocatable :: outreal(:)\n type(AD_D), intent(inout), allocatable :: outimag(:)\n logical, intent(in), optional :: negate\n\n real(rk) :: theta, freq, change\n integer :: n, imode, itheta\n\n ! Check odd-count input\n if (mod(size(inreal),2) == 0) call chidg_signal(FATAL,\"dft: expecting odd-count of input values.\")\n\n ! Initialize derivative arrays\n outreal = inreal\n outimag = inreal\n\n outreal = ZERO\n outimag = ZERO\n\n change = ONE\n if (present(negate)) then\n if (negate) change = -ONE\n end if\n\n ! Loop over output modes\n n = size(inreal)\n do imode = 1,n\n do itheta = 1,n\n if (imode <= ((size(inreal)-1)/2 + 1)) then\n freq = change*TWO*PI*real(imode-1,rk) ! positive frequencies\n else\n freq = -change*TWO*PI*real(size(inreal)-imode+1,rk) ! negative frequencies\n end if\n theta = real(itheta-1,rk) / real(n,rk)\n outreal(imode) = outreal(imode) + inreal(itheta)*cos(freq*theta) + inimag(itheta)*sin(freq*theta)\n outimag(imode) = outimag(imode) - inreal(itheta)*sin(freq*theta) + inimag(itheta)*cos(freq*theta)\n end do !itheta\n end do !imode\n\n ! Normalize\n outreal = outreal / real(n,rk)\n outimag = outimag / real(n,rk)\n\n end subroutine dft\n !******************************************************************\n\n\n\n !> Computes the partial discrete Fourier transform of an input data set.\n !!\n !! Here, we wish to compute the dft of a signal defined from 0 to 2pi.\n !! However, the incoming signal is defined only on a section of that \n !! range 0 to 2pi/T, where T is some integer indicating the number of\n !! sections the original range has been broken into.\n !!\n !! For mode numbers that are multiples of T, their dft can be computed \n !! as\n !!\n !! F[k] = (T/N)sum[ f(i) e^(-j k 2pi n/N) ]\n !!\n !! ADAPTED FROM:\n !! www.nayuki.io/res/how-to-implement-the-discrete-fourier-transform/dft.py\n !!\n !! LICENCE: \n !! Public Domain\n !!\n !! NOTE: The normalization convention used here, (1/N), defines\n !! the DC part of the transform X[0] to be the average.\n !!\n !! The transform result is in 'standard' order:\n !! [ DC, omega_1, omega_2,..., omega_n, -omega_n, ... -omega_2, -omega_1]\n !!\n !! [DC| positive frequencies | negative frequencies ]\n !!\n !! @author Nathan A. Wukie\n !! @date 2/26/2018\n !!\n !! @param[in] input periodic signal\n !! @param[inout] outreal real part of DFT\n !! @param[inout] outimag imag part of DFT\n !! @param[in] factor number of 'passages' in periodic signal \n !! that the dft of the input signal will \n !! have to be multiplied by.\n !! @param[in] modes 'm' in e^i m theta. Starting from 0.\n !!\n !-----------------------------------------------------------------\n subroutine pdft(inreal,inimag,outreal,outimag,factor,modes)\n type(AD_D), intent(in) :: inreal(:)\n type(AD_D), intent(in) :: inimag(:)\n type(AD_D), intent(inout), allocatable :: outreal(:)\n type(AD_D), intent(inout), allocatable :: outimag(:)\n integer(ik), intent(in) :: factor\n integer(ik), intent(in) :: modes(:)\n\n real(rk) :: theta, mode\n integer :: n, imode, itheta, ierr\n\n ! Check odd-count input\n if (mod(size(inreal),2) == 0) call chidg_signal(FATAL,\"pdft: expecting odd-count of input values.\")\n\n ! Initialize derivative arrays\n allocate(outreal(size(modes)), outimag(size(modes)), stat=ierr)\n if (ierr/=0) call AllocationError\n outreal = ZERO*inreal(1)\n outimag = ZERO*inreal(1)\n\n ! Loop over output modes\n n = size(inreal)\n do imode = 1,size(modes)\n mode = real(modes(imode),rk)\n do itheta = 1,n\n theta = TWO*PI*real(itheta-1,rk)/real(n*factor,rk)\n outreal(imode) = outreal(imode) + inreal(itheta)*cos(mode*theta) + inimag(itheta)*sin(mode*theta)\n outimag(imode) = outimag(imode) - inreal(itheta)*sin(mode*theta) + inimag(itheta)*cos(mode*theta)\n end do !itheta\n end do !imode\n\n ! Normalize\n outreal = real(factor,rk)*outreal/real(n*factor,rk)\n outimag = real(factor,rk)*outimag/real(n*factor,rk)\n\n end subroutine pdft\n !******************************************************************\n\n\n\n\n\n\n\n !> Computes the inverse discrete Fourier transform of an input data set.\n !!\n !! Computes x[i] = sum[ X(i)e^(j*2pi*n*k*/N) ]\n !!\n !! @author Nathan A. Wukie\n !! @date 2/26/2018\n !!\n !-----------------------------------------------------------------\n function idft(inreal,inimag) result(output)\n type(AD_D), intent(in) :: inreal(:)\n type(AD_D), intent(in) :: inimag(:)\n\n type(AD_D), allocatable :: output(:)\n real(rk), allocatable :: theta(:)\n real(rk) :: freq\n integer :: itheta, imode, ierr\n\n ! Check odd-count input\n if (mod(size(inreal),2) == 0) call chidg_signal(FATAL,\"idft: expecting odd-count of input values.\")\n\n ! Allocate and initialize derivatives\n allocate(output(size(inreal)), stat=ierr)\n if (ierr /= 0) call AllocationError\n output(:) = inreal(1)\n output = ZERO\n\n ! Theta at equispaced nodes\n theta = linspace(0._rk, real((size(inreal)-1),rk)/real(size(inreal)),size(inreal))\n\n ! Loop over output points\n do itheta = 1,size(theta)\n do imode = 1,size(inreal)\n freq = TWO*PI*real(imode-1,rk)\n output(itheta) = output(itheta) + inreal(imode)*cos(freq*theta(itheta)) - inimag(imode)*sin(freq*theta(itheta))\n end do !imode\n end do !itheta\n\n end function idft\n !******************************************************************\n\n\n\n\n !> Computes the inverse discrete Fourier transform evaluated\n !! at user-specified locations, instead of the traditional\n !! equi-spaced grid.\n !!\n !! @author Nathan A. Wukie\n !! @date 2/26/2018\n !!\n !! @param[in] inreal Real part of DFT. (could be directly from 'dft')\n !! @param[in] inimag Imag part of DFT. (could be directly from 'dft')\n !! @param[in] theta Array of locations where the idft will be evaluated \n !! normalized by the period.\n !! @param[in] theta location T normalized by the periodicity. T=t/P\n !!\n !! For example, if the original dft was computed over a period P=2.5, then\n !! say we want to evaluate the transform at a location t=0.7. The incoming\n !! value for theta would be T=0.7/2.5\n !!\n !---------------------------------------------------------------------------\n subroutine idft_eval(inreal,inimag,theta,outreal,outimag,negate,symmetric)\n type(AD_D), intent(in) :: inreal(:)\n type(AD_D), intent(in) :: inimag(:)\n type(AD_D), intent(in) :: theta(:)\n type(AD_D), intent(inout) :: outreal(:)\n type(AD_D), intent(inout) :: outimag(:)\n logical, intent(in), optional :: negate\n logical, intent(in), optional :: symmetric\n\n real(rk) :: freq, change\n integer :: itheta, imode, ierr\n logical :: compute_symmetric\n\n ! Allocate and initialize derivatives\n outreal(:) = inreal(1)\n outimag(:) = inreal(1)\n outreal = ZERO\n outimag = ZERO\n\n change = ONE\n if (present(negate)) then\n if (negate) change = -ONE\n end if\n\n compute_symmetric = .false.\n if (present(symmetric)) then\n if (symmetric) then\n compute_symmetric = .true.\n end if\n end if\n\n\n if (compute_symmetric) then\n do itheta = 1,size(theta)\n do imode = 1,size(inreal)\n if (imode <= ((size(inreal)-1)/2 + 1)) then\n freq = change*TWO*PI*real(imode-1,rk) ! positive frequencies\n if (imode > 1) then\n outreal(itheta) = outreal(itheta) + TWO*(inreal(imode)*cos(freq*theta(itheta)) - inimag(imode)*sin(freq*theta(itheta)))\n else\n outreal(itheta) = outreal(itheta) + inreal(imode)*cos(freq*theta(itheta)) - inimag(imode)*sin(freq*theta(itheta))\n end if\n outimag(itheta) = ZERO\n end if\n end do\n end do \n else\n do itheta = 1,size(theta)\n do imode = 1,size(inreal)\n if (imode <= ((size(inreal)-1)/2 + 1)) then\n freq = change*TWO*PI*real(imode-1,rk) ! positive frequencies\n else\n freq = -change*TWO*PI*real(size(inreal)-imode+1,rk) ! negative frequencies\n end if\n outreal(itheta) = outreal(itheta) + inreal(imode)*cos(freq*theta(itheta)) - inimag(imode)*sin(freq*theta(itheta))\n outimag(itheta) = outimag(itheta) + inreal(imode)*sin(freq*theta(itheta)) + inimag(imode)*cos(freq*theta(itheta))\n end do\n end do \n\n end if\n\n\n end subroutine idft_eval\n !******************************************************************\n\n\n\n\n !> Computes the inverse discrete Fourier transform of a partial DFT\n !! evaluated with pdft at user-specified locations, instead of the \n !! traditional equi-spaced grid.\n !!\n !! @author Nathan A. Wukie\n !! @date 4/15/2018\n !!\n !! @param[in] inreal Real part of DFT. (could be directly from 'dft')\n !! @param[in] inimag Imag part of DFT. (could be directly from 'dft')\n !! @param[in] theta Array of locations where the idft will be evaluated \n !! normalized by the period.\n !! @param[in] period Period, which will be used to normalize the 'theta' \n !! inputs with respect to the Fourier transform.\n !!\n !! For example, if the original dft was computed over a period 2.5, then\n !! say we want to evaluate the transform at a location 0.7. The incoming\n !! value for theta would be 0.7/2.5\n !!\n !---------------------------------------------------------------------------\n subroutine ipdft_eval(inreal,inimag,theta,factor,modes,outreal,outimag) \n type(AD_D), intent(in) :: inreal(:)\n type(AD_D), intent(in) :: inimag(:)\n real(rk), intent(in) :: theta(:)\n integer(ik), intent(in) :: factor\n integer(ik), intent(in) :: modes(:)\n type(AD_D), intent(inout) :: outreal(:)\n type(AD_D), intent(inout) :: outimag(:)\n\n real(rk) :: mode\n integer :: itheta, imode, ierr\n\n ! Allocate and initialize derivatives\n outreal(:) = inreal(1)\n outimag(:) = inreal(1)\n outreal = ZERO\n outimag = ZERO\n\n do itheta = 1,size(theta)\n do imode = 1,size(inreal)\n mode = real(modes(imode),rk)\n outreal(itheta) = outreal(itheta) + inreal(imode)*cos(mode*TWO*PI*theta(itheta)) - inimag(imode)*sin(mode*TWO*PI*theta(itheta))\n outimag(itheta) = outimag(itheta) + inreal(imode)*sin(mode*TWO*PI*theta(itheta)) + inimag(imode)*cos(mode*TWO*PI*theta(itheta))\n end do !imode\n end do !itheta\n\n end subroutine ipdft_eval\n !******************************************************************\n\n\n\n\n\n\n\n\nend module mod_dft\n", "meta": {"hexsha": "7eb9fd0170ac6136bb30e959682946de5c88fe57", "size": 14019, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical_methods/mod_dft.f90", "max_stars_repo_name": "nwukie/ChiDG", "max_stars_repo_head_hexsha": "d096548ba3bd0a338a29f522fb00a669f0e33e9b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 36, "max_stars_repo_stars_event_min_datetime": "2016-10-05T15:12:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T02:08:23.000Z", "max_issues_repo_path": "src/numerical_methods/mod_dft.f90", "max_issues_repo_name": "nwukie/ChiDG", "max_issues_repo_head_hexsha": "d096548ba3bd0a338a29f522fb00a669f0e33e9b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2016-05-17T02:21:05.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-10T16:33:07.000Z", "max_forks_repo_path": "src/numerical_methods/mod_dft.f90", "max_forks_repo_name": "nwukie/ChiDG", "max_forks_repo_head_hexsha": "d096548ba3bd0a338a29f522fb00a669f0e33e9b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 20, "max_forks_repo_forks_event_min_datetime": "2016-07-18T16:20:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-27T19:26:12.000Z", "avg_line_length": 38.0951086957, "max_line_length": 147, "alphanum_fraction": 0.5145873457, "num_tokens": 3776, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542829224748, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7607109745800296}} {"text": " REAL FUNCTION ZCRVALUE(ALPH)\r\nC*****************************ZCRVALUE********************************** \r\nC \r\n\tIMPLICIT NONE\r\nC\tCALCULATE THE CRITICAL VALUE Z SUCH THAT PR[X > Z] = ALPH\r\nC\tWHERE X IS A STANDARD NORMAL R.V.\r\nC\r\nC REF: SEE KENNEDY & GENTLE. STATISTICAL COMPUTING P.95 \r\nC*********************************************************************** \r\nC\r\nC Arguments:\r\nC\r\n\tREAL ALPH\r\nC\r\nC Locals:\r\nC\r\n\tREAL C0,C1,C2,D1,D2,D3,T,CALPH\r\n DATA C0,C1,C2,D1,D2,D3 / 2.515517,.802853,.010328\r\n + , 1.432788,.189269,.001308/\r\nC\r\nC Code:\r\nC\r\n\tIF (ALPH.LE.0.5) THEN\r\n\t T =SQRT(ALOG(1./ALPH**2) )\r\n\t ZCRVALUE = C0 +C1*T + C2*T**2\r\n\t ZCRVALUE = ZCRVALUE/(1. + D1*T + D2*T**2 + D3*T**3)\r\n\t ZCRVALUE = T-ZCRVALUE\r\n\tELSE\r\n\t CALPH=1.-ALPH\r\n\t T =SQRT(ALOG(1./CALPH**2) )\r\n\t ZCRVALUE = C0 +C1*T + C2*T**2\r\n\t ZCRVALUE = ZCRVALUE/(1. + D1*T + D2*T**2 + D3*T**3)\r\n\t ZCRVALUE = T-ZCRVALUE\r\n\t ZCRVALUE = -ZCRVALUE\r\n\tEND IF\r\nC\r\nC Finished.\r\nC\r\n\tRETURN\r\n\tEND\r\n", "meta": {"hexsha": "93ecf61f4960a4dff08a0482ac9098763b2d64f2", "size": 1125, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "misc/fortran-tests/zcrvalue.for", "max_stars_repo_name": "vubiostat/ps", "max_stars_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-12-29T14:19:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-06T15:08:46.000Z", "max_issues_repo_path": "misc/fortran-tests/zcrvalue.for", "max_issues_repo_name": "vubiostat/ps", "max_issues_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-04-30T16:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T00:26:02.000Z", "max_forks_repo_path": "misc/old_ps/ps-development-version/psDll/zcrvalue.for", "max_forks_repo_name": "vubiostat/ps", "max_forks_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-07T20:11:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-11T19:18:59.000Z", "avg_line_length": 27.4390243902, "max_line_length": 80, "alphanum_fraction": 0.4408888889, "num_tokens": 377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542794197472, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7607109718019953}} {"text": "program arrayops\n implicit none\n integer :: i, j\n integer, parameter :: M = 5\n real, dimension(M) :: x\n real :: s, t\n\n ! initialize the array\n do i=1, M\n x(i) = i\n end do\n\n ! sum\n s = 0.\n do i=1,M\n s = s + x(i)\n end do\n write(*,*)\"sum = \",s\n\n ! average (mean)\n write(*,*)\"average = \",s/M\n\n ! product\n s = 1.\n do i=1,M\n s = s * x(i)\n end do\n write(*,*)\"product = \",s\n\n ! maximum value\n s = x(1)\n do i=2,M\n if (x(i) > s) then\n s = x(i)\n end if\n end do\n write(*,*)\"max = \",s\n\n ! minimum value\n s = x(1)\n do i=2,M\n if (x(i) < s) then\n s = x(i)\n end if\n end do\n write(*,*)\"min = \",s\n\n ! norm\n s = 0.\n do i=1,M\n s = s + x(i) * x(i)\n end do\n write(*,*)\"norm = \",sqrt(s)\n\n ! second largest value\n if (x(1) > x(2)) then\n s = x(2)\n t = x(1)\n else\n s = x(2)\n t = x(1)\n end if\n do i=3,M\n if (x(i) > s) then\n if (x(i) > t) then\n s = t\n t = x(i)\n else\n s =x(i)\n end if\n end if\n end do\n write(*,*)\"second largest value = \", s\n\nend program\n\n", "meta": {"hexsha": "4b88a01e09a253d1dad4d6f22391e6420bdbdc8e", "size": 1247, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lec08/arrayops.f90", "max_stars_repo_name": "rekka/intro-fortran-2016", "max_stars_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-05T01:54:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T01:54:57.000Z", "max_issues_repo_path": "lec08/arrayops.f90", "max_issues_repo_name": "rekka/intro-fortran-2016", "max_issues_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lec08/arrayops.f90", "max_forks_repo_name": "rekka/intro-fortran-2016", "max_forks_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-06-22T12:39:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-25T04:45:37.000Z", "avg_line_length": 16.1948051948, "max_line_length": 42, "alphanum_fraction": 0.3736968725, "num_tokens": 444, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768651485395, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7606592680457711}} {"text": " MODULE random_standard_exponential_mod\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n CONTAINS\n\n!*********************************************************************\n\n FUNCTION random_standard_exponential()\n!**********************************************************************C\n! C\n! C\n! (STANDARD-) E X P O N E N T I A L DISTRIBUTION C\n! C\n! C\n!**********************************************************************C\n!**********************************************************************C\n! C\n! FOR DETAILS SEE: C\n! C\n! AHRENS, J.H. AND DIETER, U. C\n! COMPUTER METHODS FOR SAMPLING FROM THE C\n! EXPONENTIAL AND NORMAL DISTRIBUTIONS. C\n! COMM. ACM, 15,10 (OCT. 1972), 873 - 882. C\n! C\n! ALL STATEMENT NUMBERS CORRESPOND TO THE STEPS OF ALGORITHM C\n! 'SA' IN THE ABOVE PAPER (SLIGHTLY MODIFIED IMPLEMENTATION) C\n! C\n! Modified by Barry W. Brown, Feb 3, 1988 to use RANF instead of C\n! SUNIF. The argument IR thus goes away. C\n! C\n!**********************************************************************C\n! Q(N) = SUM(ALOG(2.0)**K/K!) K=1,..,N , THE HIGHEST N\n! (HERE 8) IS DETERMINED BY Q(N)=1.0 WITHIN STANDARD PRECISION\n! JJV added a Save statement for q (in Data statement)\n! .. Use Statements ..\n USE random_standard_uniform_mod\n! ..\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n! .. Function Return Value ..\n REAL :: random_standard_exponential\n! ..\n! .. Local Scalars ..\n REAL :: a, q1, u, umin, ustar\n INTEGER :: i\n! ..\n! .. Local Arrays ..\n REAL, SAVE :: q(8)\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC AMIN1\n! ..\n! .. Equivalences ..\n EQUIVALENCE (q(1),q1)\n! ..\n! .. Data Statements ..\n DATA q/0.6931472, 0.9333737, 0.9888778, 0.9984959, 0.9998293, &\n 0.9999833, 0.9999986, 0.9999999/\n! ..\n! .. Executable Statements ..\n\n a = 0.0\n u = random_standard_uniform()\n GO TO 20\n\n10 CONTINUE\n a = a + q1\n20 CONTINUE\n u = u + u\n! JJV changed the following to reflect the true algorithm and\n! JJV prevent unpredictable behavior if U is initially 0.5.\n! IF (u.LE.1.0) GO TO 20\n IF (u<1.0) GO TO 10\n u = u - 1.0\n IF (u<=q1) THEN\n random_standard_exponential = a + u\n RETURN\n END IF\n\n i = 1\n ustar = random_standard_uniform()\n umin = ustar\n ustar = random_standard_uniform()\n umin = AMIN1(ustar,umin)\n i = i + 1\n DO WHILE (u>q(i))\n ustar = random_standard_uniform()\n umin = AMIN1(ustar,umin)\n i = i + 1\n END DO\n random_standard_exponential = a + umin*q1\n RETURN\n\n END FUNCTION random_standard_exponential\n\n!*********************************************************************\n\n END MODULE random_standard_exponential_mod\n", "meta": {"hexsha": "bc109a1347c1e7993e05bd68053a0018854ba845", "size": 3733, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/random_standard_exponential_mod.f90", "max_stars_repo_name": "urbanjost/fpm_tools", "max_stars_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/random_standard_exponential_mod.f90", "max_issues_repo_name": "urbanjost/fpm_tools", "max_issues_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/random_standard_exponential_mod.f90", "max_forks_repo_name": "urbanjost/fpm_tools", "max_forks_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-14T11:36:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-14T11:36:01.000Z", "avg_line_length": 36.9603960396, "max_line_length": 72, "alphanum_fraction": 0.3819983927, "num_tokens": 822, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793452, "lm_q2_score": 0.8459424314825852, "lm_q1q2_score": 0.7606049309457937}} {"text": "module slf_integrate\n\n use iso_fortran_env, only: r32 => real32, r64 => real64\n implicit none\n\n interface integrate\n module procedure integrate32\n module procedure integrate64\n end interface integrate\n\ncontains\n\n pure real(r32) function integrate32(y,x) result(intg)\n real(r32), dimension(:), intent(in) :: x, y\n integer :: n\n\n if (size(x) /= size(y)) error stop \"size(x) /= size(y)\"\n\n n = size(x)\n intg = sum((y(2:n) + y(1:n-1)) * (x(2:n) - x(1:n-1))) / 2\n end function\n\n pure real(r64) function integrate64(y,x) result(intg)\n real(r64), dimension(:), intent(in) :: x, y\n integer :: n\n\n if (size(x) /= size(y)) error stop \"size(x) /= size(y)\"\n\n n = size(x)\n intg = sum((y(2:n) + y(1:n-1)) * (x(2:n) - x(1:n-1))) / 2\n end function\n\nend module slf_integrate\n", "meta": {"hexsha": "0681c91a55efec6b7faa47b01ae800c01842d29b", "size": 801, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/math/integrate.f90", "max_stars_repo_name": "gronki/pydiskvert", "max_stars_repo_head_hexsha": "da9fc71acbdaf48b67a372c51481b30f30c88d29", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/math/integrate.f90", "max_issues_repo_name": "gronki/pydiskvert", "max_issues_repo_head_hexsha": "da9fc71acbdaf48b67a372c51481b30f30c88d29", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/math/integrate.f90", "max_forks_repo_name": "gronki/pydiskvert", "max_forks_repo_head_hexsha": "da9fc71acbdaf48b67a372c51481b30f30c88d29", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5588235294, "max_line_length": 61, "alphanum_fraction": 0.6042446941, "num_tokens": 272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.7604162355939452}} {"text": "! quadrature.f90\n! author: sunder\n\n!-----------------------------------------------------------------------\n! Various quadrature routines\n!-----------------------------------------------------------------------\n\npure subroutine gauleg(x1, x2, x, w, n)\n implicit none\n ! Argument list\n integer, intent(in) :: n\n real, intent (in) :: x1, x2\n real, intent(out) :: x(n), w(n)\n ! Local variables\n real, parameter :: EPS = 1.0e-15\n real, parameter :: m_pi = 4.0*atan(1.0)\n integer :: i,j,m\n real :: p1, p2, p3, pp, xl, xm, z, z1\n\n\n m = (n+1)/2\n xm = 0.5*(x2+x1)\n xl = 0.5*(x2-x1)\n do i=1,m\n z = COS(M_PI*(i-0.25)/(n+0.5))\n 1 continue\n p1 = 1.0\n p2 = 0.0\n do j = 1,n\n p3 = p2\n p2 = p1\n p1 = ((2.0*j-1.0)*z*p2-(j-1.0)*p3)/real(j)\n end do\n pp = real(n)*(z*p1-p2)/(z*z-1.0)\n z1 = z\n z = z1-p1/pp\n if (abs(z-z1) .gt. EPS) goto 1\n x(i) = xm-xl*z\n x(n+1-i)= xm+xl*z\n w(i) = 2.0*xl/((1.0-z*z)*pp*pp)\n w(n+1-i)= w(i)\n end do\n return\nend subroutine gauleg\n\n\npure subroutine gaulob(x1,x2,x,w,n1)\n\n !--------------------------------------------------------------------------\n implicit none\n !--------------------------------------------------------------------------\n ! Argument list\n integer :: n1\n real :: x1,x2,x(n1),w(n1)\n ! Local variables\n real, parameter :: EPS = 1.0e-15\n real, parameter :: m_pi = 4.0*atan(1.0)\n integer :: i,k\n real :: xold(n1)\n real :: P(n1,n1)\n integer :: n, iter, maxiter\n !--------------------------------------------------------------------------\n intent(IN) :: x1,x2,n1\n intent(OUT) :: x,w\n !--------------------------------------------------------------------------\n \n !\n n = N1-1;\n\n ! Use the Chebyshev-Gauss-Lobatto nodes as the first guess\n\n do i = 0, N\n x(i+1) = cos(m_pi*real(i)/real(N))\n end do\n ! The Legendre Vandermonde Matrix\n P=0.0\n !\n ! Compute P_(N) using the recursion relation\n ! Compute its first and second derivatives and\n ! update x using the Newton-Raphson method.\n !\n xold=2.0\n !\n maxiter = 100000\n do iter = 1, maxiter\n xold=x\n P(:,1)=1.0\n P(:,2)=x\n do k = 2, N\n P(:,k+1)=( (2*k-1)*x*P(:,k)-(k-1)*P(:,k-1) )/real(k)\n end do\n x=xold-( x*P(:,N1)-P(:,N) )/( N1*P(:,N1) )\n IF(maxval(abs(x-xold)) .le. eps) then\n exit\n end if\n end do\n w = 2.0/(real(N*N1)*P(:,N1)**2)\n w = 0.5*w*(x2-x1)\n x = x1 + 0.5*(x+1.0)*(x2-x1)\n !\nend subroutine gaulob\n", "meta": {"hexsha": "74335ea120d57ca71dc12a150868216a97a6ef38", "size": 2581, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Baer-Nunziato/quadrature.f90", "max_stars_repo_name": "dasikasunder/ADER-DG", "max_stars_repo_head_hexsha": "aa2265e3b221066dc1ff5596784e2323bb38cde0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-12T01:03:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-12T01:03:51.000Z", "max_issues_repo_path": "Euler/quadrature.f90", "max_issues_repo_name": "dasikasunder/ADER-DG", "max_issues_repo_head_hexsha": "aa2265e3b221066dc1ff5596784e2323bb38cde0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Euler/quadrature.f90", "max_forks_repo_name": "dasikasunder/ADER-DG", "max_forks_repo_head_hexsha": "aa2265e3b221066dc1ff5596784e2323bb38cde0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.3039215686, "max_line_length": 77, "alphanum_fraction": 0.4075939558, "num_tokens": 908, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7603877753168777}} {"text": "!---------------------------------------------------------------------------------------------------\n!\n!\tfilename = consts.f90\n!\tauthors = Edison Salazar\n!\t\t Pedro Guarderas\n!\tdate = 18/10/2013\n!\n!---------------------------------------------------------------------------------------------------\n\n\n!---------------------------------------------------------------------------------------------------\n! Module of constants\nmodule consts\n implicit none\n ! Constants definition\n double precision :: pi_ = 4.0D0 * atan( 1.0D0 )\n double precision :: pi2_ = 8.0D0 * atan( 1.0D0 )\n double precision :: pi4_ = 16.0D0 * atan( 1.0D0 )\n\nend module consts\n", "meta": {"hexsha": "e1e15916b5a94118a71e87bb69700f70b46659a7", "size": 650, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/consts.f90", "max_stars_repo_name": "PaulChern/DFT", "max_stars_repo_head_hexsha": "85210a46964fd81104dea44fcfe43561fab2d8eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/consts.f90", "max_issues_repo_name": "PaulChern/DFT", "max_issues_repo_head_hexsha": "85210a46964fd81104dea44fcfe43561fab2d8eb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/consts.f90", "max_forks_repo_name": "PaulChern/DFT", "max_forks_repo_head_hexsha": "85210a46964fd81104dea44fcfe43561fab2d8eb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-22T14:23:11.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-22T14:23:11.000Z", "avg_line_length": 30.9523809524, "max_line_length": 100, "alphanum_fraction": 0.3553846154, "num_tokens": 136, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026550642018, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7603877658825173}} {"text": " !!Contains scripts used to correct or 'delint' a POSCAR.\n\nModule delinter\n\n use num_types\n use numerical_utilities\n use vector_matrix_utilities, only: matrix_inverse, norm\n \n implicit none\n private\n public delint\n\nCONTAINS\n\n !!Converts cell parameters into a matrix of basis\n !!vectors.\n !!The cell parameters, a, b,\n !!c, alpha, beta, gamma.\n !!The basis vectors of the\n !!cell.\n SUBROUTINE cell2basis(params, basis)\n real(dp), intent(in) :: params(6)\n real(dp), intent(out) :: basis(3,3)\n\n real(dp) :: a, b, c, alpha, beta, gamma, temp\n\n a = params(1)\n b = params(2)\n c = params(3)\n alpha = params(4)\n beta = params(5)\n gamma = params(6)\n\n temp = (cos(alpha)-cos(beta)*cos(gamma))/sin(gamma)\n\n basis(1,1) = a\n basis(1,2) = b*cos(gamma)\n basis(1,3) = c*cos(beta)\n basis(2,1) = 0.0_dp\n basis(2,2) = b*sin(gamma)\n basis(2,3) = c*temp\n basis(3,1) = 0.0_dp\n basis(3,2) = 0.0_dp\n basis(3,3) = c*sqrt(1-cos(beta)**2 -temp**2)\n end SUBROUTINE cell2basis\n\n !!Returns the cosine of the angle between two\n !!vectors.\n !!Vector 1.\n !!Vecotr 2.\n !!The cosine of the angle\n !!between vecs 1 and 2.\n SUBROUTINE cosangs(vec1, vec2, ang)\n real(dp), intent(in) :: vec1(3), vec2(3)\n real(dp), intent(out) :: ang\n\n ang = dot_product(vec1, vec2)/(sqrt(dot_product(vec1,vec1))*sqrt(dot_product(vec2,vec2)))\n end SUBROUTINE cosangs\n \n !!Converts crystall basis to cell parameters.\n !!The input basis\n !!vectors.\n !!The output cell\n !!parameters.\n SUBROUTINE basis2cell(vecs, params)\n real(dp), intent(in) :: vecs(3,3)\n real(dp), intent(out) :: params(6)\n\n integer :: i\n real(dp) :: alpha, beta, gamma\n\n do i=1,3\n params(i) = sqrt(dot_product(vecs(:,i),vecs(:,i)))\n end do\n\n call cosangs(vecs(:,2), vecs(:,3), alpha)\n call cosangs(vecs(:,1), vecs(:,3), beta)\n call cosangs(vecs(:,1), vecs(:,2), gamma)\n params(4) = acos(alpha)\n params(5) = acos(beta)\n params(6) = acos(gamma) \n end SUBROUTINE basis2cell\n\n !!Enforces the symmetries of the niggli case onto the\n !!cell parameters.\n !!The input cell\n !!parameters.\n !!The niggli case\n !!number.\n !!The output symmetrized\n !!parameters.\n !!Floating point tolerance.\n SUBROUTINE symmetrize(in_params, case, out_params, eps)\n real(dp), intent(in) :: in_params(6)\n integer, intent(in) :: case\n real(dp), intent(out) :: out_params(6)\n real(dp), intent(in) :: eps\n\n real(dp) :: a0, b0, c0, alpha0, beta0, gamma0\n real(dp) :: a, b, c, alpha, beta, gamma\n real(dp) :: temp, pi\n\n pi = 3.1415926535897931_dp\n\n a0 = in_params(1)\n b0 = in_params(2)\n c0 = in_params(3)\n alpha0 = in_params(4)\n beta0 = in_params(5)\n gamma0 = in_params(6)\n \n if (case==1) then\n temp = (a0+b0+c0)/3.0_dp\n a = temp\n b = temp\n c = temp\n alpha = pi/3.0_dp\n beta= pi/3.0_dp\n gamma = pi/3.0_dp\n else if ((case==2) .or. (case==4)) then\n temp = (a0+b0+c0)/3.0_dp\n a = temp\n b = temp\n c = temp\n temp = (alpha0+beta0+gamma0)/3.0_dp\n alpha = temp\n beta = temp\n gamma = temp\n else if (case==3) then\n temp = (a0+b0+c0)/3.0_dp\n a = temp\n b = temp\n c = temp\n alpha = pi/2.0_dp\n beta = pi/2.0_dp\n gamma= pi/2.0_dp\n else if (case==5) then\n temp = (a0+b0+c0)/3.0_dp\n a = temp\n b = temp\n c = temp\n alpha = 1.910633236249019_dp\n beta = 1.910633236249019_dp\n gamma = 1.910633236249019_dp\n else if (case==6) then\n temp = (a0+b0+c0)/3.0_dp\n a = temp\n b = temp\n c = temp\n temp = acos(((((a**2+b**2)/2.0_dp)-cos(gamma0)*a*c)/2.0_dp)/(b+c))\n alpha = temp\n beta = temp\n gamma = gamma0\n else if (case==7) then\n temp = (a0+b0+c0)/3.0_dp\n a = temp\n b = temp\n c = temp\n alpha = acos(((((a**2+b**2)/2.0_dp)-2*cos(gamma0)*a*c))/(b+c))\n temp = (beta0+gamma0)/2.0_dp\n beta = temp\n gamma = temp\n else if (case==8) then\n temp = (a0+b0+c0)/3.0_dp\n a = temp\n b = temp\n c = temp\n alpha = acos((((a**2+b**2)/2.0_dp)-cos(gamma0)*a*c-cos(beta0)*a*b)/(b*c))\n beta = beta0\n gamma = gamma0\n else if (case==9) then\n temp = (a0+b0)/2.0_dp\n a = temp\n b = temp\n c = c0\n alpha = acos((a*a)/(2*b*c))\n beta = acos((a*a)/(2*a*c))\n gamma = pi/3.0_dp\n else if (case==10) then\n temp = (a0+b0)/2.0_dp\n a = temp\n b = temp\n c = c0\n temp = (alpha0+beta0)/2.0_dp\n alpha = temp\n beta = temp\n gamma = gamma0\n else if (case==11) then\n temp = (a0+b0)/2.0_dp\n a = temp\n b = temp\n c = c0\n alpha = pi/2.0_dp\n beta = pi/2.0_dp\n gamma = pi/2.0_dp\n else if (case==12) then\n temp = (a0+b0)/2.0_dp\n a = temp\n b = temp\n c = c0\n alpha = pi/2.0_dp\n beta = pi/2.0_dp\n gamma = pi/3.0_dp\n else if (case==13) then\n temp = (a0+b0)/2.0_dp\n a = temp\n b = temp\n c = c0\n alpha = pi/2.0_dp\n beta = pi/2.0_dp\n gamma = gamma0\n else if (case==15) then\n temp = (a0+b0)/2.0_dp\n a = temp\n b = temp\n c = c0\n alpha = acos(-(a*a)/(2*b*c))\n beta = acos(-(a*a)/(2*a*c))\n gamma = pi/2.0_dp\n else if (case==16) then\n temp = (a0+b0)/2.0_dp\n a = temp\n b = temp\n c = c0\n gamma = pi/2.0_dp\n alpha = acos((((a*a+b*b)/2.0_dp-cos(gamma)*a*c)/2.0_dp)/(b*c))\n beta = acos((((a*a+b*b)/2.0_dp-cos(gamma)*a*c)/2.0_dp)/(a*c))\n else if (case==14) then\n temp = (a0+b0)/2.0_dp\n a = temp\n b = temp\n c = c0\n gamma = gamma0\n temp = (alpha0+beta0)/2.0_dp\n alpha = temp\n beta = temp\n else if (case==17) then\n temp = (a0+b0)/2.0_dp\n a = temp\n b = temp\n c = c0\n gamma = gamma0\n beta= beta0\n alpha = acos(((a*a+b*b)/2.0_dp-cos(gamma)*a*c-cos(beta)*a*b)/(b*c))\n else if (case==18) then\n temp = (c0+b0)/2.0_dp\n a = a0\n b = temp\n c = temp\n alpha = acos((a*a)/(4*b*c))\n beta = acos((a*a)/(2*a*c))\n gamma = acos((a*a)/(2*a*b))\n else if (case==19) then\n temp = (c0+b0)/2.0_dp\n a = a0\n b = temp\n c = temp\n alpha = alpha0\n beta = acos((a*a)/(2*a*c))\n gamma = acos((a*a)/(2*a*b))\n else if ((case==20) .or. (case==25)) then\n temp = (c0+b0)/2.0_dp\n a = a0\n b = temp\n c = temp\n alpha = alpha0\n temp = (beta0+gamma0)/2.0_dp\n beta = temp\n gamma = temp\n else if (case==21) then\n temp = (c0+b0)/2.0_dp\n a = a0\n b = temp\n c = temp\n alpha = pi/2.0_dp\n beta = pi/2.0_dp\n gamma = pi/2.0_dp\n else if (case==22) then\n temp = (c0+b0)/2.0_dp\n a = a0\n b = temp\n c = temp\n alpha = acos(-(b*b)/(2*b*c))\n beta = pi/2.0_dp\n gamma = pi/2.0_dp\n else if (case==23) then\n temp = (c0+b0)/2.0_dp\n a = a0\n b = temp\n c = temp\n alpha = alpha0\n beta = pi/2.0_dp\n gamma = pi/2.0_dp\n else if (case==24) then\n temp = (c0+b0)/2.0_dp\n a = a0\n b = temp\n c = temp\n beta = acos(-(a*a)/(3*a*c))\n gamma = acos(-(a*a)/(3*a*b))\n alpha = acos(((a*a+b*b)*2.0_dp -cos(gamma)*a*c-cos(beta)*a*b)/(b*c))\n else if (case==26) then\n a = a0\n b = b0\n c = c0\n alpha = acos((a*a)/(4*b*c))\n beta = acos(-(a*a)/(2*a*c))\n gamma = acos(-(a*a)/(2*a*b))\n else if (case==27) then\n a = a0\n b = b0\n c = c0\n alpha = alpha0\n beta = acos(-(a*a)/(2*a*c))\n gamma = acos(-(a*a)/(2*a*b))\n else if (case==28) then\n a = a0\n b = b0\n c = c0\n alpha = alpha0\n beta = acos(-(a*a)/(2*a*c))\n gamma = acos((2*cos(alpha)*b*c)/(a*b))\n else if (case==29) then\n a = a0\n b = b0\n c = c0\n alpha = alpha0\n beta = acos((2*cos(alpha)*b*c)/(a*c))\n gamma = acos((a*a)/(2*a*b))\n else if (case==30) then\n a = a0\n b = b0\n c = c0\n alpha = acos((b*b)/(2*b*c))\n beta = beta0\n gamma = acos(2*cos(beta)*a*c/(a*b))\n else if ((case==31) .or. (case==44)) then\n a = a0\n b = b0\n c = c0\n alpha = alpha0\n beta = beta0\n gamma = gamma0\n else if (case==32) then\n a = a0\n b = b0\n c = c0\n alpha = pi/2.0_dp\n beta = pi/2.0_dp\n gamma = pi/2.0_dp\n else if (case==40) then\n a = a0\n b = b0\n c = c0\n alpha = acos(-(b*b)/(2*b*c))\n beta = pi/2.0_dp\n gamma = pi/2.0_dp\n else if (case==35) then\n a = a0\n b = b0\n c = c0\n alpha = alpha0\n beta = pi/2.0_dp\n gamma = pi/2.0_dp\n else if (case==36) then\n a = a0\n b = b0\n c = c0\n alpha = pi/2.0_dp\n beta = acos(-(a*a)/(2*a*c))\n gamma = pi/2.0_dp\n else if (case==33) then\n a = a0\n b = b0\n c = c0\n alpha = pi/2.0_dp\n beta = beta0\n gamma = pi/2.0_dp\n else if (case==38) then\n a = a0\n b = b0\n c = c0\n alpha = pi/2.0_dp\n beta = pi/2.0_dp\n gamma = acos(-(a*a)/(2*a*b))\n else if (case==34) then\n a = a0\n b = b0\n c = c0\n alpha = pi/2.0_dp\n beta = pi/2.0_dp\n gamma = gamma0\n else if (case==42) then\n a = a0\n b = b0\n c = c0\n alpha = acos(-(b*b)/(2*b*c))\n beta = acos(-(a*a)/(2*a*c))\n gamma = pi/2.0_dp\n \n else if (case==41) then\n a = a0\n b = b0\n c = c0\n alpha = acos(-(b*b)/(2*b*c))\n beta = beta0\n gamma = pi/2.0_dp\n else if (case==37) then\n a = a0\n b = b0\n c = c0\n alpha = alpha0\n beta = acos(-(a*a)/(2*a*c))\n gamma = pi/2.0_dp\n else if (case==39) then\n a = a0\n b = b0\n c = c0\n alpha = alpha0\n beta = pi/2.0_dp\n gamma = acos(-(a*a)/(2*a*b))\n else if (case==43) then\n a = a0\n b = b0\n c = c0\n gamma = gamma0\n beta = beta0\n temp = ((a*a+b*b)/2.0_dp)-cos(gamma)*a*c-cos(beta)*a*b\n if (equal(2*temp*cos(gamma)*a*b,b*b,eps)) then\n alpha = acos(temp/(b*c))\n else\n temp = (-(a*a+b*b)/2.0_dp)-cos(gamma)*a*c-cos(beta)*a*b\n alpha = acos(temp/(b*c))\n end if\n end if\n\n out_params(1) = a\n out_params(2) = b\n out_params(3) = c\n out_params(4) = alpha\n out_params(5) = beta\n out_params(6) = gamma\n end SUBROUTINE symmetrize\n \n !!Fixes a POSCAR so that it perfectly matches the expected\n !!symmetries.\n !!The original lattice\n !!vectors.\n !!The niggli id for this\n !!lattice.\n !!The corrected lattice\n !!vectors.\n !!The floating point\n !!tollerance.\n SUBROUTINE delint(in_vecs, case, out_vecs, eps_)\n real(dp), intent(in) :: in_vecs(3,3)\n integer, intent(in) :: case\n real(dp), intent(out) :: out_vecs(3,3)\n real(dp), optional, intent(in) :: eps_\n\n real(dp) :: eps\n real(dp) :: in_params(6), canonical_basis(3,3), rot_mat(3,3)\n real(dp) :: rot_test(3,3), cb_inv(3,3), ident(3,3), c_params(6)\n real(dp) :: fixed_basis(3,3)\n integer :: i\n\n ident = reshape((/1.0_dp,0.0_dp,0.0_dp, 0.0_dp,1.0_dp,0.0_dp, 0.0_dp,0.0_dp,1.0_dp/),(/3,3/))\n\n if (present(eps_)) then\n eps = eps_\n else\n eps = 1E-3\n end if\n\n call basis2cell(in_vecs, in_params)\n call cell2basis(in_params, canonical_basis)\n call matrix_inverse(canonical_basis, cb_inv)\n \n rot_mat = matmul(in_vecs, cb_inv)\n rot_test = matmul(rot_mat, transpose(rot_mat))\n if (.not. equal(rot_test, ident, eps)) then\n write(*,*) \"Error generating rotation matrix in delinter.\"\n stop\n end if\n\n call symmetrize(in_params, case, c_params, eps)\n call cell2basis(c_params, fixed_basis)\n out_vecs = matmul(rot_mat, fixed_basis)\n \n end SUBROUTINE delint\n \n \nend Module delinter \n", "meta": {"hexsha": "4cc0f5e273c1baee474eb7947c56cc76dc81e7c4", "size": 13017, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/delinter.f90", "max_stars_repo_name": "braydenbekker/autoGR", "max_stars_repo_head_hexsha": "7dcb9315437d760f2f60cb7c38311f964ae15954", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/delinter.f90", "max_issues_repo_name": "braydenbekker/autoGR", "max_issues_repo_head_hexsha": "7dcb9315437d760f2f60cb7c38311f964ae15954", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/delinter.f90", "max_forks_repo_name": "braydenbekker/autoGR", "max_forks_repo_head_hexsha": "7dcb9315437d760f2f60cb7c38311f964ae15954", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.3502024291, "max_line_length": 97, "alphanum_fraction": 0.5162479834, "num_tokens": 4603, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034425, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.7603877620702498}} {"text": "module m_stream\n ! no variables in this module\ncontains\n\n subroutine compute_stream_function(nx, ny, hx, hy, xmin, xmax, ymin, ymax, B, S)\n implicit none\n ! arguments\n integer, intent(in) :: nx, ny\n real, intent(in) :: hx, hy\n real, intent(in) :: xmin, xmax, ymin, ymax\n real, intent(in) :: B\n real, intent(out) :: S(:, :)\n ! local variables\n real, parameter :: pi = 3.141592653589793238462643383279502884\n real :: x = 0.0, y = 0.0\n integer :: i = 0, j = 0\n\n do concurrent (i=1:nx, j=1:ny)\n x = xmin + (i-1) * hx\n y = ymin + (j-1) * hy\n S(i, j) = B * sin((pi * x) / xmax) * sin((pi * y) / ymax)\n end do\n\n end subroutine compute_stream_function\n\n subroutine compute_velocity(S, hx, hy, vx, vy)\n implicit none\n ! arguments\n real, intent(in) :: hx, hy\n real, intent(in) :: S(:, :)\n real, intent(out) :: vx(:, :)\n real, intent(out) :: vy(:, :)\n ! local variables\n integer :: nx, ny\n nx = size(S, 1)\n ny = size(S, 2)\n\n ! Initialize vx and vy\n vx = 0.0\n vy = 0.0\n\n ! Compute velocity at each interior point using centered finite differences\n vx(2:nx-1, 2:ny-1) = (S(2:nx-1, 3:ny) - S(2:nx-1, 1:ny-2)) / (2 * hy)\n vy(2:nx-1, 2:ny-1) = -(S(3:nx, 2:ny-1) - S(1:nx-2, 2:ny-1)) / (2 * hx)\n\n end subroutine compute_velocity\n\nend module m_stream\n", "meta": {"hexsha": "60fb8bfc95d5cb97db7b96d944161b0cd33b0a8c", "size": 1341, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "m_stream.f90", "max_stars_repo_name": "ntselepidis/FDM-Navier-Stokes", "max_stars_repo_head_hexsha": "fbb9a1741b1d8e3e550db0c2e756d25780c48ed6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-21T15:16:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-21T15:16:04.000Z", "max_issues_repo_path": "m_stream.f90", "max_issues_repo_name": "ntselepidis/FDM-Navier-Stokes", "max_issues_repo_head_hexsha": "fbb9a1741b1d8e3e550db0c2e756d25780c48ed6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "m_stream.f90", "max_forks_repo_name": "ntselepidis/FDM-Navier-Stokes", "max_forks_repo_head_hexsha": "fbb9a1741b1d8e3e550db0c2e756d25780c48ed6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.3673469388, "max_line_length": 82, "alphanum_fraction": 0.5637583893, "num_tokens": 489, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632996617212, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.7603389852822395}} {"text": "! Sum square difference\n!\n! The sum of the squares of the first ten natural numbers is,\n! 1^2 + 2^2 + ... + 10^2 = 385\n!\n! The square of the sum of the first ten natural numbers is,\n! (1 + 2 + ... + 10)^2 = 55^2 = 3025\n!\n! Hence the difference between the sum of the squares of the first ten natural\n! numbers and the square of the sum is 3025 - 385 = 2640.\n!\n! Find the difference between the sum of the squares of the first one hundred\n! natural numbers and the square of the sum.\nmodule Problem6\n\n implicit none\n private\n\n public :: solve\ncontains\n subroutine solve\n write (*, '(A)') 'Problem 6. Sum square difference.'\n\n write (*, '(A, I)') 'Difference 1: ', difference1()\n end subroutine\n\n function difference1()\n integer difference1\n integer sum\n integer square\n integer index\n\n ! initial values\n sum = 0\n square = 0\n\n do concurrent (index = 1:100)\n ! the sum of the squares\n sum = sum + index ** 2\n\n ! the square of the sum\n square = square + index\n end do\n\n square = square ** 2\n\n difference1 = square - sum\n end function\nend module\n", "meta": {"hexsha": "38a4370a6aae2fa90f06a566520ccea0f9cde6ff", "size": 1200, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Problem6.f", "max_stars_repo_name": "andreypudov/projecteuler", "max_stars_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Problem6.f", "max_issues_repo_name": "andreypudov/projecteuler", "max_issues_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Problem6.f", "max_forks_repo_name": "andreypudov/projecteuler", "max_forks_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0, "max_line_length": 78, "alphanum_fraction": 0.595, "num_tokens": 316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741322079104, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7603320702856188}} {"text": "PROGRAM temp_conversion\r\n \r\n! Purpose: \r\n! To convert an input temperature from degrees Fahrenheit to\r\n! an output temperature in kelvins. \r\n!\r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 11/03/06 -- S. J. Chapman Original code \r\n!\r\n\r\nIMPLICIT NONE ! Force explicit declaration of variables\r\n\r\n! Data dictionary: declare variable types, definitions, & units \r\nREAL :: temp_f ! Temperature in degrees Fahrenheit\r\nREAL :: temp_k ! Temperature in kelvins\r\n\r\n! Prompt the user for the input temperature.\r\nWRITE (*,*) 'Enter the temperature in degrees Fahrenheit: '\r\nREAD (*,*) temp_f \r\n \r\n! Convert to kelvins.\r\ntemp_k = (5. / 9.) * (temp_f - 32.) + 273.15 \r\n \r\n! Write out the result.\r\nWRITE (*,*) temp_f, ' degrees Fahrenheit = ', temp_k, ' kelvins'\r\n \r\n! Finish up.\r\nEND PROGRAM temp_conversion\r\n", "meta": {"hexsha": "bfa71951999b0b938fd776fc8a9dcb964cf39d6e", "size": 939, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap2/temp_conversion.f90", "max_stars_repo_name": "yangyang14641/FortranLearning", "max_stars_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-03-12T02:18:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-05T07:58:56.000Z", "max_issues_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap2/temp_conversion.f90", "max_issues_repo_name": "yangyang14641/FortranLearning", "max_issues_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap2/temp_conversion.f90", "max_forks_repo_name": "yangyang14641/FortranLearning", "max_forks_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-05-11T02:36:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T06:36:55.000Z", "avg_line_length": 30.2903225806, "max_line_length": 66, "alphanum_fraction": 0.6038338658, "num_tokens": 224, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741268224333, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7603320682735119}} {"text": " SUBROUTINE resid(res,u,rhs,n)\r\n INTEGER n\r\n DOUBLE PRECISION res(n,n),rhs(n,n),u(n,n)\r\n INTEGER i,j\r\n DOUBLE PRECISION h,h2i\r\n h=1.d0/(n-1)\r\n h2i=1.d0/(h*h)\r\n do 12 j=2,n-1\r\n do 11 i=2,n-1\r\n res(i,j)=-h2i*(u(i+1,j)+u(i-1,j)+u(i,j+1)+u(i,j-1)-4.d0*u(i,\r\n *j))+rhs(i,j)\r\n11 continue\r\n12 continue\r\n do 13 i=1,n\r\n res(i,1)=0.d0\r\n res(i,n)=0.d0\r\n res(1,i)=0.d0\r\n res(n,i)=0.d0\r\n13 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "cc5ae3fc0f41cad06a87a7c9e33184669a3a81b8", "size": 516, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/resid.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/resid.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/resid.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.4545454545, "max_line_length": 71, "alphanum_fraction": 0.4457364341, "num_tokens": 203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741295151718, "lm_q2_score": 0.798186768138228, "lm_q1q2_score": 0.7603320658498008}} {"text": "Module rocket_params_vars\n Implicit none\n integer, parameter :: no_eqs = 2\n real*8, parameter :: p_a = 101325.d0, &\n n = ... , &\n\n ......\n\n grav = 9.81d0, &\n pi = 4.*atan(1.d0), &\n A_star = ...\n\n real :: p_c, p_c_dot, &\n r, r_dot, &\n p_c_old, r_old, &\n eta_crit\n\n contains\n\n Function f_cor()\n ! perimeter factor\n Implicit none\n real*8 :: f_cor, eta\n eta = ...\n f_cor = 1.d0\n if( eta < ... )then\n f_cor = ...\n endif\n return\n End\n\n\n Function I_sp()\n ! specific impulse\n Implicit none\n real*8 :: I_sp\n I_sp = ...\n return\n End function \n \n Function ODEs( t ) result ( k )\n Implicit none\n real*8 :: t\n real*8, dimension( no_eqs ) :: k\n r_dot = a * p_c**n\n k( 1 ) = ...\n k( 2 ) = ...\n return\n End function\n\n Subroutine RK4( t, del_t )\n Implicit none\n integer, parameter :: no_stages = 4\n real*8 :: t, del_t\n real*8, dimension( no_eqs ) :: k( no_stages, no_eqs )\n!.. soln and slopes at interval beg\n p_c_old = p_c\n ...\n k( 1, : ) = ODEs( t )\n!.. slopes at p_1 = 0.5\n p_c = p_c_old + 0.5d0 * ...\n ...\n!.. slopes at p_2 = 0.5\n ...\n!.. slopes at p_3 = 1.0\n ...\n!.. update for end of interval\n ...\n!.. update time\n ...\n return\n End subroutine\n\nEnd module\n\nProgram Rocket_Perf\n Use rocket_params_vars\n Implicit none\n real*8 :: V_c, ...\n real*8 :: dt, time\n integer :: nstep = 0\n\n print*,'enter eta (fraction of effective propellant thickness beyond wich burn diminishes) : '\n read*, eta_crit\n \n print*,'enter time step size, dt [s] : '\n read*, dt\n\n!.. initial params\n p_c = ... ! chamber pressure\n r = ... ! chamber radius\n V_c = ... ! chamber volume\n V_p = ... ! propellant volume\n m_p = ... ! propellant mass\n m_p_init = ...\n\n open( 1, file = 'rocket.dat',form='formatted') \n write(1,*)' \"t [s]\" \"p_c [MPa]\" ... '\n time = 0.d0\n nstep = 0\n\n do while( m_p / m_p_init > 0.05d0 )\n\n nstep = nstep + 1\n\n ! update solution and time\n call RK4( ... )\n\n ! check chamber pressure... abort if p_c < p_a\n ...\n\n ! compute mass of propellant left\n ...\n\n ! print on screen and store soln\n if( nstep == 1 .or. mod(nstep,5)==0) &\n write(1,'(8(2x,e12.6))') time, p_c*1.d-6, ...\n write(*,'(8(a,e9.3))')' t = ',time,' s, p_c = ', p_c*1d-6, ...\n\n enddo\n\n close(1)\n\n stop\nEnd\n\n\n", "meta": {"hexsha": "8aee0e060eccd5658a02b46ff5c51d4edcd2f057", "size": 2508, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Homework2/hw2-option1.f90", "max_stars_repo_name": "Atknssl/AE305-Homeworks", "max_stars_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-06T18:42:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-04T13:27:27.000Z", "max_issues_repo_path": "Homework2/hw2-option1.f90", "max_issues_repo_name": "Atknssl/AE305-Homeworks", "max_issues_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework2/hw2-option1.f90", "max_forks_repo_name": "Atknssl/AE305-Homeworks", "max_forks_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.59375, "max_line_length": 95, "alphanum_fraction": 0.504784689, "num_tokens": 841, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362486, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7603297257978224}} {"text": "!\n!*******************************************************************************\n!\nsubroutine gauss_quad(nt,kind,alpha,beta,x,w)\n!\n!*******************************************************************************\n!\n! Discussion:\n!\n! FORTRAN 90 subroutine to calculate abscissas and weights for Gauss-quadruature\n! for a wide range of orthogonal polynomials ortogonalized over a given range\n! [a,b] and weight function w(x).\n!\n! Inputs:\n! nt = Number of Gauss-quadruature points, [integer(kind = 4)]\n! kind = Type of Quadrature rule, [integer(kind = 4)]\n!\n! = 1, Legendre, [-1,1], w(x) = 1.0\n! = 2, Associated Laguerre, [0,inf], w(x) = exp(-x)*x^alpha\n! = 3, Hermite, [-inf,inf], w(x) = exp(-x^2)\n! = 4, Jacobi, [-1,1], w(x) = (1-x)^alpha*(1+x)^beta\n! = 5, Chebyshev (Type I), [-1,1], w(x) = (1-x^2)^(-0.5)\n! = 6, Chebyshev (type II), [-1,1], w(x) = (1-x^2)^(0.5)\n! = 7, Gegenbauer, [-1,1], w(x) = (1-x^2)^(alpha-0.5)\n!\n! alpha = Value of alpha, if needed, [real(kind = 8)]\n! beta = Value of beta, if needed, [real(kind = 8)]\n!\n! Outputs:\n! x(1:nt) = abscissas for Gauss-quadrature rule, [real(kind=8)]\n! w(1:nt) = weights for Gauss-quadrature rule, [real(kind=8)]\n!\n! Note that Chebyshev Type II is a special case of Gegenbauer with alpha = 1\n!\n! The algorithm is based on the three-term recurrence relation for each\n! polynomial. The terms are found for the normalized polynonmials, i.e.,\n!\n! F(n,alpha,beta,x) = p(n,alpha,beta,x)/sqrt(N(n,alpha,beta)),\n!\n! where n is the order of the polynomial, and p(n,alpha,beta) denotes \n! the standard textbook definition with p(0,alpha,beta) = 1.0, and \n! N(n,alpha,beta) is the norm integral defined as\n!\n! N(n,alpha,beta) = int[a,b] dx w(x)*[p(n,alpha,beta,x)]^2.\n!\n! The three-term recurrence relations can be written as (with fixed \n! alpha and beta)\n!\n! a(n-1)*F(n-1,x) + b(n)*F(n,x) + a(n)*F(n+1,x) = x*F(n,x)\n!\n! Using the notation\n! = int[a,b] dx w(x)*g(x)*F(n,x).\n!\n! b(n) = \n!\n! The coefficients a(n) = k(n)/k(n+1)\n!\n! where k(n) is the leading coefficient for F(n), that is\n!\n! F(n) = k(n)*x^n + k(n-1)*x^(n-1) + ...\n!\n! The abscicca x(k) is the kth eigenvalue of the tridigonal matrix\n!\n! b(0) a(0) 0 0 0 0 0\n! a(0) b(1) a(1) 0 0 0 0\n! 0 a(1) b(2) a(2) 0 0 0\n! 0 0 a(2) b(3) a(3) 0 0\n! \n! b(n-1) a(n-1)\n! 0 0 0 0 0 a(n-1) b(n)\n!\n! The weights are obtained from the 1st component of the kth eigenvector, \n! vec(1,k), via:\n!\n! w(k) = N(0,alpha,beta)*vec(1,k)^2/(sum_k vec(1,k)^2)\n!\n! The eigenvalues and eigenvectors are obtained from a modified version of \n! the EISPACK routine tql2, named tri_eig\n!\n! Dependencies:\n!\n! Modules:\n!\n! None\n!\n! Subroutines:\n!\n! jacobi_norm\n! tri_eig\n!\n! External functions:\n!\n! real(kind=8) :: poly_a\n! real(kind=8) :: poly_b\n! real(kind=8) :: poly_norm\n!\n! MPI routines:\n!\n! None\n!\n! Licensing:\n!\n! SPDX-License-Identifier: MIT \n!\n! Date:\n!\n! 11 May 2021\n!\n! Author:\n!\n! Erich Ormand, LLNL\n!\n!*******************************************************************************\n!\n implicit none\n integer(kind=4), intent(in) :: nt, kind\n real(kind=8), intent(in) :: alpha, beta\n real(kind=8), intent(out) :: x(nt), w(nt)\n\n integer(kind=4) :: i, n\n real(kind=8) :: pi\n\n real(kind=8) :: xn, two_xn\n\n real(kind=8), allocatable :: d(:), e(:), z(:,:)\n real(kind=8) :: norm, int_norm\n integer(kind=4) :: ierror\n!\n!----- External functions\n!\n real(kind=8) :: poly_a\n real(kind=8) :: poly_b \n real(kind=8) :: poly_norm\n!\n!*******************************************************************************\n!\n pi = 2.0d0*asin(1.0d0)\n!\n!---- Allocate and initalize arrays for the tri-diagonal matrix\n!\n if(.not.allocated(d))allocate(d(nt))\n if(.not.allocated(e))allocate(e(nt))\n if(.not.allocated(z))allocate(z(nt,nt))\n d(1:nt) = 0.0d0\n e(1:nt) = 0.0d0\n z(1:nt,1:nt) = 0.0d0\n!\n!---- Set up tridiagonal matrix to be diagonalized for each integration type\n!\n do i = 1, nt\n n = i - 1 ! integer order of the polynomial, p(n,alpha,beta)\n xn = real(n,kind=8)\n two_xn = 2.0d0*xn\n d(i) = poly_b(n, kind, alpha, beta)\n if(i < nt)e(i+1)= poly_a(n, kind, alpha, beta)\n z(i,i) = 1.0d0\n end do\n!\n! Find eigenvalues and eigenvectors of the tri-diagonal matrix\n!\n call tri_eig(nt, nt, d, e, z, ierror)\n!\n!---- Find norm to set the weights\n!\n norm = 0.0d0\n do i = 1, nt\n norm = norm + z(1,i)**2\n end do\n!\n!---- Set norm for the weights - integral with w(x)*[p(0,alpha,beta)]^2*dx\n!\n int_norm = poly_norm(0,kind,alpha,beta)\n!\n!---- Put abscissas and weights into output arrays\n! \n do i = 1, nt\n x(i) = d(i)\n w(i) = int_norm*z(1,i)**2/norm\n end do\n!\n!---- Delete temporary data \n!\n if(allocated(d))deallocate(d)\n if(allocated(e))deallocate(e)\n if(allocated(z))deallocate(z)\n!\n!---- All done\n!\n return\n! \nend subroutine gauss_quad\n!\n!*******************************************************************************\n!\nreal(kind=8) function poly_b(n, kind, alpha, beta)\n!\n!*******************************************************************************\n!\n! Discussion:\n!\n! FORTRAN 90 function to calculate recurssion coefficient b(n), where \n! the three-term recurrence relations are written as (with fixed \n! alpha and beta) for the normalized orthogonal polynomials as:\n!\n! a(n-1)*F(n-1,x) + b(n)*F(n,x) + a(n)*F(n+1,x) = x*F(n,x)\n!\n! Inputs:\n! n = order of the polynomial, [integer(kind = 4)]\n! kind = Type of polynomial, [integer(kind = 4)]\n!\n! = 1, Legendre, [-1,1], w(x) = 1.0\n! = 2, Associated Laguerre, [0,inf], w(x) = exp(-x)*x^alpha\n! = 3, Hermite, [-inf,inf], w(x) = exp(-x^2)\n! = 4, Jacobi, [-1,1], w(x) = (1-x)^alpha*(1+x)^beta\n! = 5, Chebyshev (Type I), [-1,1], w(x) = (1-x^2)^(-0.5)\n! = 6, Chebyshev (type II), [-1,1], w(x) = (1-x^2)^(0.5)\n! = 7, Gegenbauer, [-1,1], w(x) = (1-x^2)^(alpha-0.5)\n!\n! alpha = Value of alpha, if needed, [real(kind = 8)]\n! beta = Value of beta, if needed, [real(kind = 8)]\n!\n! Dependencies:\n!\n! Modules:\n!\n! None\n!\n! Subroutines:\n!\n! None\n!\n! External functions:\n!\n! None\n!\n! MPI routines:\n!\n! None\n!\n! Licensing:\n!\n! SPDX-License-Identifier: MIT \n!\n! Date:\n!\n! 11 May 2021\n!\n! Author:\n!\n! Erich Ormand, LLNL\n!\n!*******************************************************************************\n!\n implicit none\n integer(kind=4), intent(in) :: n, kind\n real(kind=8), intent(in) :: alpha, beta\n!--------------------------------------------------------------------\n real(kind=8) :: xn, two_xn, xLn\n!*************************************************************************\n poly_b = 0.0d0\n xn = real(n,kind=8)\n two_xn = 2.0d0*xn\n if(kind == 1)then ! Legendre\n poly_b = 0.0d0\n elseif(kind == 2)then ! Associated Laguerre\n poly_b = two_xn + alpha + 1.0d0\n elseif(kind == 3)then ! Hermite\n poly_b = 0.0d0\n elseif(kind == 4)then ! Jacobi\n poly_b = 0.0d0\n if(n == 0 .and. abs(beta**2 - alpha**2) < 1.0d-10)return\n xLn = two_xn + alpha + beta\n poly_b = (beta**2 - alpha**2)/(xLn*(xLn+2.0d0))\n elseif(kind == 5)then ! Chebyshev (Type I)\n poly_b = 0.0d0\n elseif(kind == 6)then ! Chebyshev (Type II)\n poly_b = 0.0d0\n elseif(kind == 7)then ! Gegenbauer\n if(alpha < 1.0d0)stop 'Error in Gengenbauer polynomilas, alpha < 1'\n poly_b = 0.0d0\n end if\n return\nend function poly_b\n!\n!*******************************************************************************\n!\nreal(kind=8) function poly_a(n, kind, alpha, beta)\n!\n!*******************************************************************************\n!\n! Discussion:\n!\n! FORTRAN 90 function to calculate recurssion coefficient a(n), where \n! the three-term recurrence relations are written as (with fixed \n! alpha and beta) for the normalized orthogonal polynomials as:\n!\n! a(n-1)*F(n-1,x) + b(n)*F(n,x) + a(n)*F(n+1,x) = x*F(n,x)\n!\n! Inputs:\n! n = order of the polynomial, [integer(kind = 4)]\n! kind = Type of polynomial, [integer(kind = 4)]\n!\n! = 1, Legendre, [-1,1], w(x) = 1.0\n! = 2, Associated Laguerre, [0,inf], w(x) = exp(-x)*x^alpha\n! = 3, Hermite, [-inf,inf], w(x) = exp(-x^2)\n! = 4, Jacobi, [-1,1], w(x) = (1-x)^alpha*(1+x)^beta\n! = 5, Chebyshev (Type I), [-1,1], w(x) = (1-x^2)^(-0.5)\n! = 6, Chebyshev (type II), [-1,1], w(x) = (1-x^2)^(0.5)\n! = 7, Gegenbauer, [-1,1], w(x) = (1-x^2)^(alpha-0.5)\n!\n! alpha = Value of alpha, if needed, [real(kind = 8)]\n! beta = Value of beta, if needed, [real(kind = 8)]\n!\n! Dependencies:\n!\n! Modules:\n!\n! None\n!\n! Subroutines:\n!\n! jacobi_norm\n! tri_eig\n!\n! External functions:\n!\n! real(kind=8) :: poly_norm\n!\n! MPI routines:\n!\n! None\n!\n! Licensing:\n!\n! SPDX-License-Identifier: MIT \n!\n! Date:\n!\n! 11 May 2021\n!\n! Author:\n!\n! Erich Ormand, LLNL\n!\n!*******************************************************************************\n!\n implicit none\n integer(kind=4), intent(in) :: n, kind\n real(kind=8), intent(in) :: alpha, beta\n!--------------------------------------------------------------------\n real(kind=8) :: xn, two_xn, XLn, temp\n!--------- External functions\n real(kind=8) :: poly_norm\n!*************************************************************************\n!\n poly_a = 0.0d0\n xn = real(n,kind=8)\n two_xn = 2.0d0*xn\n if(kind == 1)then ! Legendre\n poly_a = (xn + 1.0d0)/sqrt((two_xn + 3.0d0)*(two_xn + 1.0d0))\n elseif(kind == 2)then ! Associated Laguerre\n poly_a = -sqrt((xn+1.0d0)*(xn+alpha+1.0d0))\n elseif(kind == 3)then ! Hermite\n poly_a = sqrt((xn + 1.0d0)/2.0d0)\n elseif(kind == 4)then ! Jacobi\n xLn = two_xn + alpha + beta\n temp = log_gamma(alpha + beta + two_xn + 1.0d0) + log_gamma(alpha + beta + xn + 2.0d0) - &\n log_gamma(alpha + beta + xn + 1.0d0) - log_gamma(alpha + beta + two_xn + 3.0d0)\n temp = exp(temp)*2.0d0*(xn + 1.0d0)*sqrt(poly_norm(n+1,kind,alpha,beta)/poly_norm(n,kind,alpha,beta))\n poly_a = temp\n elseif(kind == 5)then ! Chebyshev (Type I)\n if(n == 0)then\n poly_a = 1.0d0/sqrt(2.0d0)\n else\n poly_a = 0.5d0\n end if\n elseif(kind == 6)then ! Chebyshev (Type II)\n poly_a = 0.5d0\n elseif(kind == 7)then ! Gegenbauer\n if(alpha < 1.0d0)stop 'Error in Gengenbauer polynomilas, alpha < 1'\n poly_a = 0.5d0*sqrt((xn+1.0d0)*(xn+2.0d0*alpha)/((xn+alpha)*(xn+alpha+1.0d0)))\n end if\n return\nend function poly_a\n!\n!*******************************************************************************\n!\nreal(kind=8) function poly_norm(n, kind, alpha, beta)\n!\n!*******************************************************************************\n!\n! Discussion:\n!\n! FORTRAN 90 function to calculate the normalization of orthogonal Polynomials\n!\n! int[-1,1] w(x) [P(n,alpha,beta)]^2 dx\n! Inputs:\n! n = order of the polynomial, [integer(kind = 4)]\n! kind = Type of polynomial, [integer(kind = 4)]\n!\n! = 1, Legendre, [-1,1], w(x) = 1.0\n! = 2, Associated Laguerre, [0,inf], w(x) = exp(-x)*x^alpha\n! = 3, Hermite, [-inf,inf], w(x) = exp(-x^2)\n! = 4, Jacobi, [-1,1], w(x) = (1-x)^alpha*(1+x)^beta\n! = 5, Chebyshev (Type I), [-1,1], w(x) = (1-x^2)^(-0.5)\n! = 6, Chebyshev (type II), [-1,1], w(x) = (1-x^2)^(0.5)\n! = 7, Gegenbauer, [-1,1], w(x) = (1-x^2)^(alpha-0.5)\n!\n! alpha = Value of alpha, if needed, [real(kind = 8)]\n! beta = Value of beta, if needed, [real(kind = 8)]\n!\n! Dependencies:\n!\n! Modules:\n!\n! None\n!\n! Subroutines:\n!\n! None\n!\n! External functions:\n!\n! None\n!\n! MPI routines:\n!\n! None\n!\n! Licensing:\n!\n! SPDX-License-Identifier: MIT \n!\n! Date:\n!\n! 11 May 2021\n!\n! Author:\n!\n! Erich Ormand, LLNL\n!\n!*******************************************************************************\n!\n implicit none\n integer(kind=4), intent(in) :: n, kind\n real(kind=8), intent(in) :: alpha, beta\n!--------------------------------------------------------------------\n real(kind=8) :: factor, xn, two_xn, pi\n!*************************************************************************\n!\n pi = 2.0d0*asin(1.0d0)\n poly_norm = 0.0d0\n xn = real(n,kind=8)\n two_xn = 2.0d0*xn\n if(kind == 1)then ! Legendre\n poly_norm = 2.0d0/(two_xn + 1.0d0)\n elseif(kind == 2)then ! Associated Laguerre\n poly_norm = exp(log_gamma(xn + alpha + 1.0d0) - log_gamma(xn + 1.0d0))\n elseif(kind == 3)then ! Hermite\n poly_norm = 2.0d0**xn*sqrt(pi)*exp(log_gamma(xn + 1.0d0))\n elseif(kind == 4)then ! Jacobi\n factor = log_gamma(xn + alpha + 1.0d0) + log_gamma(xn + beta + 1.0d0) - &\n log_gamma(xn + 1.0d0) - log_gamma(xn + alpha + beta + 1.0d0)\n factor = factor + (alpha + beta + 1.0d0)*log(2.0d0) - &\n log(2.0d0*xn + alpha + beta + 1.0d0)\n poly_norm = exp(factor)\n elseif(kind == 5)then ! Chebyshev (Type I)\n if(n == 0)then\n poly_norm = pi\n else\n poly_norm = 0.5d0*pi\n end if\n elseif(kind == 6)then ! Chebyshev (Type II)\n poly_norm = 0.5d0*pi\n elseif(kind == 7)then ! Gegenbauer\n factor = log_gamma(xn + 2.0d0*alpha) - log_gamma(xn + 1.0d0) - 2.0d0*log_gamma(alpha)\n poly_norm = pi*2.0d0**(1.0d0 - 2.0d0*alpha)*exp(factor)/(xn + alpha)\n end if\n return\nend function poly_norm\n!\n!*******************************************************************************\n!\nreal(kind=8) function poly(n, kind, alpha, beta, x)\n!\n!*******************************************************************************\n!\n! Discussion:\n!\n! FORTRAN 90 function to calculate values at a given value of x for the \n! orthogonal polynomial p(n,alpha,beta,x). \n! Uses the three-term recurrence relation (with fixed \n! alpha and beta) for the normalized orthogonal polynomials F(n,alpha,beta,x) as:\n!\n! a(n-1)*F(n-1,x) + b(n)*F(n,x) + a(n)*F(n+1,x) = x*F(n,x)\n!\n! or\n!\n! F(n) = ((x - b(n-1)*F(n-1)) - a(n-2)*F(n-2))/a(n-1) \n!\n! with\n!\n! F(n,alpha,beta,x) = p(n,alpha,beta,x)/sqrt(N(n,alpha,beta)),\n!\n! Inputs:\n! n = order of the polynomial, [integer(kind = 4)]\n! kind = Type of polynomial, [integer(kind = 4)]\n!\n! = 1, Legendre, [-1,1], w(x) = 1.0\n! = 2, Associated Laguerre, [0,inf], w(x) = exp(-x)*x^alpha\n! = 3, Hermite, [-inf,inf], w(x) = exp(-x^2)\n! = 4, Jacobi, [-1,1], w(x) = (1-x)^alpha*(1+x)^beta\n! = 5, Chebyshev (Type I), [-1,1], w(x) = (1-x^2)^(-0.5)\n! = 6, Chebyshev (type II), [-1,1], w(x) = (1-x^2)^(0.5)\n! = 7, Gegenbauer, [-1,1], w(x) = (1-x^2)^(alpha-0.5)\n!\n! alpha = Value of alpha, if needed, [real(kind = 8)]\n! beta = Value of beta, if needed, [real(kind = 8)]\n!\n! Dependencies:\n!\n! Modules:\n!\n! None\n!\n! Subroutines:\n!\n! None\n!\n! External functions:\n!\n! real(kind=8) :: poly_a\n! real(kind=8) :: poly_b\n! real(kind=8) :: poly_norm\n!\n! MPI routines:\n!\n! None\n!\n! Licensing:\n!\n! SPDX-License-Identifier: MIT \n!\n! Date:\n!\n! 11 May 2021\n!\n! Author:\n!\n! Erich Ormand, LLNL\n!\n!*******************************************************************************\n!\n implicit none\n integer(kind=4), intent(in) :: n, kind\n real(kind=8), intent(in) :: alpha, beta\n real(kind=8), intent(in) :: x\n!----------------------------------------------------------------\n integer(kind=4) :: nn\n real(kind=8) :: p0, p1, p2\n!\n!----- External functions\n!\n real(kind=8) :: poly_a\n real(kind=8) :: poly_b\n real(kind=8) :: poly_norm\n!\n!*******************************************************************************\n!\n p0 = 1.0d0\n p1 = 0.0d0\n!--- If n=1, trivial, and exit\n poly = p0\n if(n == 0)return\n if(kind == 1)then\n p1 = x\n elseif(kind == 2)then\n p1 = (-x + alpha + 1.0d0)\n elseif(kind == 3)then\n p1 = 2.0d0*x\n elseif(kind == 4)then\n p1 = (alpha + 1.0d0) + (alpha + beta + 2.0d0)*0.5d0*(x-1.0d0)\n elseif(kind == 5)then\n p1 = x\n elseif(kind == 6)then\n p1 = 2.0d0*x\n elseif(kind == 7)then\n p1 = 2.0d0*alpha*x\n end if\n!--- If n=1, trivial, and exit\n poly = p1\n if(n == 1)return\n!--- First and second normalized polynomials\n p0 = p0/sqrt(poly_norm(0,kind,alpha,beta))\n p1 = p1/sqrt(poly_norm(1,kind,alpha,beta))\n p2 = 0.0d0\n!--- Build up to n via recurrence relation\n do nn = 2, n\n p2 = (x - poly_b(nn-1,kind,alpha,beta))*p1 - &\n poly_a(nn-2,kind,alpha,beta)*p0\n p2 = p2/poly_a(nn-1,kind,alpha,beta)\n p0 = p1\n p1 = p2\n end do\n!--- Undo normalization and return\n poly = p2*sqrt(poly_norm(n,kind,alpha,beta))\n return\nend function poly\n\n", "meta": {"hexsha": "f35c4eb7ea0123358ef56de69fe49df2e0774749", "size": 18598, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Src/Gauss-quadrature.f90", "max_stars_repo_name": "LLNL/Yet-Another-Hauser-Feshbach-Code", "max_stars_repo_head_hexsha": "18af2fea77d0263986648b057c06bd96f87ae8e0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-11-05T23:37:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-05T23:37:53.000Z", "max_issues_repo_path": "Src/Gauss-quadrature.f90", "max_issues_repo_name": "LLNL/Yet-Another-Hauser-Feshbach-Code", "max_issues_repo_head_hexsha": "18af2fea77d0263986648b057c06bd96f87ae8e0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Src/Gauss-quadrature.f90", "max_forks_repo_name": "LLNL/Yet-Another-Hauser-Feshbach-Code", "max_forks_repo_head_hexsha": "18af2fea77d0263986648b057c06bd96f87ae8e0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-05T23:38:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-10T21:34:37.000Z", "avg_line_length": 30.4885245902, "max_line_length": 108, "alphanum_fraction": 0.4506398537, "num_tokens": 6091, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240160063031, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7603297243957381}} {"text": "C BACKWARD SUBSTITUTION\r\n \r\n SUBROUTINE SOLVE(N,A,IA,L,B,X) \r\n DIMENSION A(IA,N),L(N),B(N),X(N) \r\n DO 3 K = 1,N-1\r\n DO 2 I = K+1,N \r\n B(L(I)) = B(L(I)) - A(L(I),K)*B(L(K)) \r\n 2 CONTINUE\r\n 3 CONTINUE \r\n X(N) = B(L(N))/A(L(N),N)\r\n DO 5 I = N-1,1,-1 \r\n SUM = B(L(I)) \r\n DO 4 J = I+1,N \r\n SUM = SUM - A(L(I),J)*X(J) \r\n 4 CONTINUE \r\n X(I) = SUM/A(L(I),I)\r\n 5 CONTINUE \r\n RETURN \r\n END \r\n", "meta": {"hexsha": "655a6c0dc6d4c8062cdf44ed2dd2a5901e34448c", "size": 519, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "04-Nonlinear-System/fortran_source_files/solve.f", "max_stars_repo_name": "0x00000024/numerical-analysis", "max_stars_repo_head_hexsha": "a0af414675241fe3b1ed02687981c7a3a4d790f6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2022-01-05T01:49:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-19T04:15:53.000Z", "max_issues_repo_path": "04-Nonlinear-System/fortran_source_files/solve.f", "max_issues_repo_name": "0x00000024/numerical-analysis", "max_issues_repo_head_hexsha": "a0af414675241fe3b1ed02687981c7a3a4d790f6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "04-Nonlinear-System/fortran_source_files/solve.f", "max_forks_repo_name": "0x00000024/numerical-analysis", "max_forks_repo_head_hexsha": "a0af414675241fe3b1ed02687981c7a3a4d790f6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.95, "max_line_length": 49, "alphanum_fraction": 0.3564547206, "num_tokens": 196, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392797, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7603126135990116}} {"text": " DOUBLE PRECISION FUNCTION WNORM(N,Z,XW)\n INTEGER N\n DOUBLE PRECISION Z(N), XW(N)\nC ------------------------------------------------------------\nC\nC* Summary :\nC\nC E N O R M : Return the norm to be used in exit (termination)\nC criteria\nC\nC* Input parameters\nC ================\nC\nC N Int Number of equations/unknowns\nC Z(N) Dble The vector, of which the norm is to be computed\nC XW(N) Dble The scaling values of Z(N)\nC\nC* Output\nC ======\nC\nC WNORM(N,Z,XW) Dble The mean square root norm of Z(N) subject\nC to the scaling values in XW(N):\nC = Sqrt( Sum(1,...N)((Z(I)/XW(I))**2) / N )\nC\nC ------------------------------------------------------------\nC* End Prologue\n INTEGER I\n DOUBLE PRECISION S\nC* Begin\n S = 0.0D0\n DO 10 I=1,N\n S = S + ( Z(I)/XW(I) ) ** 2\n10 CONTINUE\n WNORM = DSQRT( S / DBLE(FLOAT(N)) )\nC End of function WNORM\n RETURN\n END\n", "meta": {"hexsha": "78a2c6aa042d5826cc0ed39f2b3414ca8cea6797", "size": 1041, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "pysces/nleq2/wnorm.f", "max_stars_repo_name": "katrinleinweber/pysces", "max_stars_repo_head_hexsha": "197e666b9d48b9dd2db8ca572041bacf8b84efc3", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2015-02-11T22:59:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T15:36:41.000Z", "max_issues_repo_path": "pysces/nleq2/wnorm.f", "max_issues_repo_name": "katrinleinweber/pysces", "max_issues_repo_head_hexsha": "197e666b9d48b9dd2db8ca572041bacf8b84efc3", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 63, "max_issues_repo_issues_event_min_datetime": "2015-03-26T11:58:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-25T18:44:15.000Z", "max_forks_repo_path": "pysces/nleq2/wnorm.f", "max_forks_repo_name": "katrinleinweber/pysces", "max_forks_repo_head_hexsha": "197e666b9d48b9dd2db8ca572041bacf8b84efc3", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2015-05-01T09:28:56.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-25T14:38:14.000Z", "avg_line_length": 27.3947368421, "max_line_length": 69, "alphanum_fraction": 0.446685879, "num_tokens": 301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966732132748, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.7602816436435191}} {"text": "REAL*8 function kern_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\nkern_num = cos(sqrt((y_a - y_b)**2/ly**2 + (x_a - x_b)**2/lx**2))\nend function\nREAL*8 function dkdx_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\ndkdx_num = -(x_a - x_b)*sin(sqrt((lx**2*(y_a - y_b)**2 + ly**2*(x_a - &\n x_b)**2)/(lx**2*ly**2)))/(lx**2*sqrt((lx**2*(y_a - y_b)**2 + ly** &\n 2*(x_a - x_b)**2)/(lx**2*ly**2)))\nend function\nREAL*8 function dkdy_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\ndkdy_num = -(y_a - y_b)*sin(sqrt((lx**2*(y_a - y_b)**2 + ly**2*(x_a - &\n x_b)**2)/(lx**2*ly**2)))/(ly**2*sqrt((lx**2*(y_a - y_b)**2 + ly** &\n 2*(x_a - x_b)**2)/(lx**2*ly**2)))\nend function\nREAL*8 function dkdx0_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\ndkdx0_num = (x_a - x_b)*sin(sqrt((lx**2*(y_a - y_b)**2 + ly**2*(x_a - &\n x_b)**2)/(lx**2*ly**2)))/(lx**2*sqrt((lx**2*(y_a - y_b)**2 + ly** &\n 2*(x_a - x_b)**2)/(lx**2*ly**2)))\nend function\nREAL*8 function dkdy0_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\ndkdy0_num = (y_a - y_b)*sin(sqrt((lx**2*(y_a - y_b)**2 + ly**2*(x_a - &\n x_b)**2)/(lx**2*ly**2)))/(ly**2*sqrt((lx**2*(y_a - y_b)**2 + ly** &\n 2*(x_a - x_b)**2)/(lx**2*ly**2)))\nend function\nREAL*8 function d2kdxdx0_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\nd2kdxdx0_num = ly**2*(lx**2*ly**2*sqrt((lx**2*(y_a - y_b)**2 + ly**2*( &\n x_a - x_b)**2)/(lx**2*ly**2))*(-(x_a - x_b)**2 + (lx**2*(y_a - &\n y_b)**2 + ly**2*(x_a - x_b)**2)/ly**2)*sin(sqrt((lx**2*(y_a - y_b &\n )**2 + ly**2*(x_a - x_b)**2)/(lx**2*ly**2))) + (x_a - x_b)**2*(lx &\n **2*(y_a - y_b)**2 + ly**2*(x_a - x_b)**2)*cos(sqrt((lx**2*(y_a - &\n y_b)**2 + ly**2*(x_a - x_b)**2)/(lx**2*ly**2))))/(lx**2*(lx**2*( &\n y_a - y_b)**2 + ly**2*(x_a - x_b)**2)**2)\nend function\nREAL*8 function d2kdydy0_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\nd2kdydy0_num = lx**2*(lx**2*ly**2*sqrt((lx**2*(y_a - y_b)**2 + ly**2*( &\n x_a - x_b)**2)/(lx**2*ly**2))*(-(y_a - y_b)**2 + (lx**2*(y_a - &\n y_b)**2 + ly**2*(x_a - x_b)**2)/lx**2)*sin(sqrt((lx**2*(y_a - y_b &\n )**2 + ly**2*(x_a - x_b)**2)/(lx**2*ly**2))) + (y_a - y_b)**2*(lx &\n **2*(y_a - y_b)**2 + ly**2*(x_a - x_b)**2)*cos(sqrt((lx**2*(y_a - &\n y_b)**2 + ly**2*(x_a - x_b)**2)/(lx**2*ly**2))))/(ly**2*(lx**2*( &\n y_a - y_b)**2 + ly**2*(x_a - x_b)**2)**2)\nend function\nREAL*8 function d2kdxdy0_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\nd2kdxdy0_num = (x_a - x_b)*(y_a - y_b)*(cos(sqrt((y_a - y_b)**2/ly**2 + &\n (x_a - x_b)**2/lx**2))/((y_a - y_b)**2/ly**2 + (x_a - x_b)**2/lx &\n **2) - sin(sqrt((y_a - y_b)**2/ly**2 + (x_a - x_b)**2/lx**2))/(( &\n y_a - y_b)**2/ly**2 + (x_a - x_b)**2/lx**2)**(3.0d0/2.0d0))/(lx** &\n 2*ly**2)\nend function\n", "meta": {"hexsha": "f2d184ec3dc28bcddefd496658b4be9cfe8f1f4a", "size": 3979, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "draft/pendulum/cosine/kernels.f90", "max_stars_repo_name": "krystophny/profit", "max_stars_repo_head_hexsha": "c6316c9df7cfaa7b30332fdbbf85ad27175eaf92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2019-12-03T14:11:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T13:44:06.000Z", "max_issues_repo_path": "draft/pendulum/cosine/kernels.f90", "max_issues_repo_name": "krystophny/profit", "max_issues_repo_head_hexsha": "c6316c9df7cfaa7b30332fdbbf85ad27175eaf92", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 118, "max_issues_repo_issues_event_min_datetime": "2019-11-16T19:51:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T13:52:00.000Z", "max_forks_repo_path": "draft/pendulum/cosine/kernels.f90", "max_forks_repo_name": "krystophny/profit", "max_forks_repo_head_hexsha": "c6316c9df7cfaa7b30332fdbbf85ad27175eaf92", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2020-06-08T07:22:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-21T14:12:21.000Z", "avg_line_length": 37.8952380952, "max_line_length": 73, "alphanum_fraction": 0.5355616989, "num_tokens": 1791, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966671870767, "lm_q2_score": 0.8031737916455819, "lm_q1q2_score": 0.7602816343437153}} {"text": "SUBROUTINE calc_hypotenuse ( side_1, side_2, hypotenuse )\r\n!\r\n! Purpose:\r\n! To calculate the hypotenuse of a right triangle from the two \r\n! other sides.\r\n!\r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 11/18/06 S. J. Chapman Original code\r\n!\r\nIMPLICIT NONE\r\n\r\n! Data dictionary: declare calling parameter types & definitions\r\nREAL, INTENT(IN) :: side_1 ! Length of side 1 \r\nREAL, INTENT(IN) :: side_2 ! Length of side 2 \r\nREAL, INTENT(OUT) :: hypotenuse ! Length of hypotenuse\r\n\r\n! Data dictionary: declare local variable types & definitions\r\nREAL :: temp ! Temporary variable\r\n\r\n! Calculate hypotenuse\r\ntemp = side_1**2 + side_2**2\r\nhypotenuse = SQRT ( temp )\r\n\r\nEND SUBROUTINE calc_hypotenuse\r\n", "meta": {"hexsha": "df5276627f3ee1bcc1b2717d8b41bcff298ceaa7", "size": 858, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap7/calc_hypotenuse.f90", "max_stars_repo_name": "yangyang14641/FortranLearning", "max_stars_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-03-12T02:18:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-05T07:58:56.000Z", "max_issues_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap7/calc_hypotenuse.f90", "max_issues_repo_name": "yangyang14641/FortranLearning", "max_issues_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap7/calc_hypotenuse.f90", "max_forks_repo_name": "yangyang14641/FortranLearning", "max_forks_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-05-11T02:36:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T06:36:55.000Z", "avg_line_length": 31.7777777778, "max_line_length": 67, "alphanum_fraction": 0.6025641026, "num_tokens": 220, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966702001758, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.7602816323040382}} {"text": "*=======================================================================\n* RSORT - sort a list of integers by the Radix Sort algorithm\n* Public domain. This program may be used by any person for any purpose.\n* Origin: Herman Hollerith, 1887\n*\n*___Name____Type______In/Out____Description_____________________________\n* IX(N) Integer Both Array to be sorted in increasing order\n* IW(N) Integer Neither Workspace\n* N Integer In Length of array\n*\n* ASSUMPTIONS: Bits in an INTEGER is an even number.\n* Integers are represented by twos complement.\n*\n* NOTE THAT: Radix sorting has an advantage when the input is known\n* to be less than some value, so that only a few bits need\n* to be compared. This routine looks at all the bits,\n* and is thus slower than Quicksort.\n*=======================================================================\n SUBROUTINE RSORT (IX, IW, N)\n IMPLICIT NONE\n INTEGER IX, IW, N\n DIMENSION IX(N), IW(N)\n\n INTEGER I, ! count bits\n $ ILIM, ! bits in an integer\n $ J, ! count array elements\n $ P1OLD, P0OLD, P1, P0, ! indices to ones and zeros\n $ SWAP\n LOGICAL ODD ! even or odd bit position\n\n* IF (N < 2) RETURN ! validate\n*\n ILIM = Bit_size(i) !Get the fixed number of bits\n*=======================================================================\n* Alternate between putting data into IW and into IX\n*=======================================================================\n P1 = N+1\n P0 = N ! read from 1, N on first pass thru\n ODD = .FALSE.\n DO I = 0, ILIM-2\n P1OLD = P1\n P0OLD = P0 ! save the value from previous bit\n P1 = N+1\n P0 = 0 ! start a fresh count for next bit\n\n IF (ODD) THEN\n DO J = 1, P0OLD, +1 ! copy data from the zeros\n IF ( BTEST(IW(J), I) ) THEN\n P1 = P1 - 1\n IX(P1) = IW(J)\n ELSE\n P0 = P0 + 1\n IX(P0) = IW(J)\n END IF\n END DO\n DO J = N, P1OLD, -1 ! copy data from the ones\n IF ( BTEST(IW(J), I) ) THEN\n P1 = P1 - 1\n IX(P1) = IW(J)\n ELSE\n P0 = P0 + 1\n IX(P0) = IW(J)\n END IF\n END DO\n\n ELSE\n DO J = 1, P0OLD, +1 ! copy data from the zeros\n IF ( BTEST(IX(J), I) ) THEN\n P1 = P1 - 1\n IW(P1) = IX(J)\n ELSE\n P0 = P0 + 1\n IW(P0) = IX(J)\n END IF\n END DO\n DO J = N, P1OLD, -1 ! copy data from the ones\n IF ( BTEST(IX(J), I) ) THEN\n P1 = P1 - 1\n IW(P1) = IX(J)\n ELSE\n P0 = P0 + 1\n IW(P0) = IX(J)\n END IF\n END DO\n END IF ! even or odd i\n\n ODD = .NOT. ODD\n END DO ! next i\n\n*=======================================================================\n* the sign bit\n*=======================================================================\n P1OLD = P1\n P0OLD = P0\n P1 = N+1\n P0 = 0\n\n* if sign bit is set, send to the zero end\n DO J = 1, P0OLD, +1\n IF ( BTEST(IW(J), ILIM-1) ) THEN\n P0 = P0 + 1\n IX(P0) = IW(J)\n ELSE\n P1 = P1 - 1\n IX(P1) = IW(J)\n END IF\n END DO\n DO J = N, P1OLD, -1\n IF ( BTEST(IW(J), ILIM-1) ) THEN\n P0 = P0 + 1\n IX(P0) = IW(J)\n ELSE\n P1 = P1 - 1\n IX(P1) = IW(J)\n END IF\n END DO\n\n*=======================================================================\n* Reverse the order of the greater value partition\n*=======================================================================\n P1OLD = P1\n DO J = N, (P1OLD+N)/2+1, -1\n SWAP = IX(J)\n IX(J) = IX(P1)\n IX(P1) = SWAP\n P1 = P1 + 1\n END DO\n RETURN\n END ! of RSORT\n\n\n***********************************************************************\n* test program\n***********************************************************************\n PROGRAM t_sort\n IMPLICIT NONE\n INTEGER I, N\n PARAMETER (N = 11)\n INTEGER IX(N), IW(N)\n LOGICAL OK\n\n DATA IX / 2, 24, 45, 0, 66, 75, 170, -802, -90, 1066, 666 /\n\n PRINT *, 'before: ', IX\n CALL RSORT (IX, IW, N)\n PRINT *, 'after: ', IX\n\n* compare\n OK = .TRUE.\n DO I = 1, N-1\n IF (IX(I) > IX(I+1)) OK = .FALSE.\n END DO\n IF (OK) THEN\n PRINT *, 't_sort: successful test'\n ELSE\n PRINT *, 't_sort: failure!'\n END IF\n END ! of test program\n", "meta": {"hexsha": "87085acffd1b33534c6238ae07a8a920eb615997", "size": 5060, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Sorting-algorithms-Radix-sort/Fortran/sorting-algorithms-radix-sort.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-05T13:42:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T13:42:20.000Z", "max_issues_repo_path": "Task/Sorting-algorithms-Radix-sort/Fortran/sorting-algorithms-radix-sort.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Sorting-algorithms-Radix-sort/Fortran/sorting-algorithms-radix-sort.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.8238993711, "max_line_length": 73, "alphanum_fraction": 0.3721343874, "num_tokens": 1331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.760233589424366}} {"text": "\n subroutine great_circle(alat1,alon1,alat2,alon2,gcdist,gcbearing)\n\n! http://www.dtcenter.org/met/users/docs/write_ups/gc_simple.pdf\n\n! solve for bearing of location 2 as seen from location 1\n! north/up is zero bearing with angles counted clockwise\n! angles are in radians\n\n hav(x) = sin(x/2.)**2\n hav_inv(x) = 2. * asin(sqrt(x))\n\n pi = 3.14159265\n rpd = pi / 180.\n\n phia = alat1 * rpd\n phib = alat2 * rpd\n deltal = (alon1 - alon2) * rpd\n\n s = cos(phib) * sin(deltal)\n c = cos(phia) * sin(phib) - sin(phia) * cos(phib) * cos(deltal) \n \n beta = atan2(s,c)\n gcbearing = beta / rpd\n\n hav_theta = hav(phia-phib) + cos(phia) * cos(phib) * hav(deltal)\n theta = hav_inv(hav_theta)\n gcdist = theta / rpd\n\n return\n end\n", "meta": {"hexsha": "5ed0f936f6d115a155f31a3da7a0e651658b47db", "size": 812, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/cloud/greatcircle.f90", "max_stars_repo_name": "maxinye/laps-mirror", "max_stars_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_stars_repo_licenses": ["Intel", "Unlicense", "OLDAP-2.2.1", "NetCDF"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-04-05T12:28:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-29T06:37:29.000Z", "max_issues_repo_path": "src/lib/cloud/greatcircle.f90", "max_issues_repo_name": "longwosion/laps-mirror", "max_issues_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_issues_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lib/cloud/greatcircle.f90", "max_forks_repo_name": "longwosion/laps-mirror", "max_forks_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_forks_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-04-27T12:51:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T13:57:44.000Z", "avg_line_length": 25.375, "max_line_length": 71, "alphanum_fraction": 0.5862068966, "num_tokens": 274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377296574668, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.7602219801695794}} {"text": "SUBROUTINE loc_to_glob(local,global,gamma,coord)\n!\n! This subroutine transforms the local end reactions and\n! moments into the global system (3-d).\n!\n IMPLICIT NONE\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n REAL(iwp),INTENT(IN)::local(:),gamma,coord(:,:)\n REAL(iwp),INTENT(OUT)::global(:)\n REAL(iwp)::t(12,12),r0(3,3),x1,x2,y1,y2,z1,z2,xl,yl,zl,pi,gamrad,cg,sg, &\n den,ell,x,sum,zero=0.0_iwp,one=1.0_iwp,d180=180.0_iwp\n INTEGER::i,j,k\n x1=coord(1,1)\n y1=coord(1,2)\n z1=coord(1,3)\n x2=coord(2,1)\n y2=coord(2,2)\n z2=coord(2,3)\n xl=x2-x1\n yl=y2-y1\n zl=z2-z1\n ell=SQRT(xl*xl+yl*yl+zl*zl)\n t=zero\n pi=ACOS(-one)\n gamrad=gamma*pi/d180\n cg=COS(gamrad)\n sg=SIN(gamrad)\n den=ell*SQRT(xl*xl+zl*zl)\n IF(den/=zero)THEN\n r0(1,1)=xl/ell\n r0(2,1)=yl/ell\n r0(3,1)=zl/ell\n r0(1,2)=(-xl*yl*cg-ell*zl*sg)/den\n r0(2,2)=den*cg/(ell*ell)\n r0(3,2)=(-yl*zl*cg+ell*xl*sg)/den\n r0(1,3)=(xl*yl*sg-ell*zl*cg)/den\n r0(2,3)=-den*sg/(ell*ell)\n r0(3,3)=(yl*zl*sg+ell*xl*cg)/den\n ELSE\n r0(1,1)=zero\n r0(3,1)=zero\n r0(2,2)=zero\n r0(2,3)=zero\n r0(2,1)=one\n r0(1,2)=-cg\n r0(3,3)=cg\n r0(3,2)=sg\n r0(1,3)=sg\n END IF\n DO i=1,3\n DO j=1,3 \n x=r0(i,j)\n DO k=0,9,3\n t(i+k,j+k)=x\n END DO\n END DO\n END DO\n DO i=1,12\n sum=zero\n DO j=1,12\n sum=sum+t(i,j)*local(j)\n END DO\n global(i)=sum\n END DO\nRETURN\nEND SUBROUTINE loc_to_glob \n", "meta": {"hexsha": "aa821a9e444d0dda379e59959dae3c528cd1eb52", "size": 1365, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main/loc_to_glob.f90", "max_stars_repo_name": "cunyizju/Programming-FEM-5th-Fortran", "max_stars_repo_head_hexsha": "7740d381c0871c7e860aee8a19c467bd97a4cf45", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 20, "max_stars_repo_stars_event_min_datetime": "2019-12-22T11:44:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T12:19:06.000Z", "max_issues_repo_path": "main/loc_to_glob.f90", "max_issues_repo_name": "cunyizju/Programming-FEM-5th-Fortran", "max_issues_repo_head_hexsha": "7740d381c0871c7e860aee8a19c467bd97a4cf45", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-03-13T06:51:33.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-13T06:51:33.000Z", "max_forks_repo_path": "main/loc_to_glob.f90", "max_forks_repo_name": "cunyizju/Programming-FEM-5th-Fortran", "max_forks_repo_head_hexsha": "7740d381c0871c7e860aee8a19c467bd97a4cf45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-06-03T12:47:06.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-30T13:35:28.000Z", "avg_line_length": 20.3731343284, "max_line_length": 75, "alphanum_fraction": 0.6058608059, "num_tokens": 675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897542390751, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7602213508984595}} {"text": "module loglikelihood_module\n use utils_module, only: dp\n\n contains\n\n !> Upside down [Himmelblau function](http://en.wikipedia.org/wiki/Himmelblaus_function).\n !!\n !! \\f[ -\\log L(x, y) = (x^2+y-11)^2 + (x+y^2-7)^2 \\f]\n !!\n !! Himmelblau's function is a multi-modal function, used to test the performance of \n !! optimization algorithms. \n !! It has one local maximum at x = -0.270845 \\, and y =\n !! -0.923039 \\, where f(x,y) = 181.617 \\,, and four\n !! identical local minima:\n !! * \\f$ f(3.0, 2.0) = 0.0, \\f$\n !! * \\f$ f(-2.805118, 3.131312) = 0.0, \\f$\n !! * \\f$ f(-3.779310, -3.283186) = 0.0,\\f$\n !! * \\f$ f(3.584428, -1.848126) = 0.0. \\f$\n !!\n !! The locations of all the Maxima and minima can be found\n !! analytically. However, because they are roots of cubic polynomials, when\n !! written in terms of radicals, the expressions are somewhat\n !! complicated.\n !!\n !! The function is named after David Mautner Himmelblau (1924-2011), who\n !! introduced it. \n !! \n !! Note that this is a 2D function, and should hence only be used for settings%nDims=2\n !!\n function loglikelihood(theta,phi)\n implicit none\n real(dp), intent(in), dimension(:) :: theta !> Input parameters\n real(dp), intent(out), dimension(:) :: phi !> Output derived parameters\n real(dp) :: loglikelihood ! loglikelihood value to output\n\n ! Normalisation\n loglikelihood = -log(0.4071069421432255d0) \n\n ! Evaluate\n loglikelihood = loglikelihood - (theta(1)**2 + theta(2)- 11d0)**2 - (theta(1)+theta(2)**2-7d0)**2 \n\n end function loglikelihood\n\n subroutine setup_loglikelihood(settings)\n use settings_module, only: program_settings\n implicit none\n type(program_settings), intent(in) :: settings\n\n end subroutine setup_loglikelihood\n\nend module loglikelihood_module\n", "meta": {"hexsha": "77b55904367cf1c191bf533df2fffddbb71f1598", "size": 2003, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Externals/PolyChord/likelihoods/examples/himmelblau.f90", "max_stars_repo_name": "yuanfangtardis/vscode_project", "max_stars_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Externals/PolyChord/likelihoods/examples/himmelblau.f90", "max_issues_repo_name": "yuanfangtardis/vscode_project", "max_issues_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Externals/PolyChord/likelihoods/examples/himmelblau.f90", "max_forks_repo_name": "yuanfangtardis/vscode_project", "max_forks_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-15T12:22:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T12:22:30.000Z", "avg_line_length": 38.5192307692, "max_line_length": 114, "alphanum_fraction": 0.6025961058, "num_tokens": 596, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338101862455, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7601216341233975}} {"text": "!--------------------------------------------------\n!..Homework 2 Bonus\n!..Team 31\n!..AE305 - Numerical Methods\n!\n!..This program calculates the chamber pressure, \n!..burn rate and specific impulse for given rocket\n!..using RK4 method with adaptive time step and\n!..outputs results to a file.\n!--------------------------------------------------\nModule rocket_params_vars_bonus\n Implicit none\n integer, parameter :: no_eqs = 2\n real*8, parameter :: p_a = 101325.d0, &\n rho_p = 1140.d0, &\n n = 0.305d0, &\n a = 0.0000555d0, &\n r_0 = 0.05d0, &\n r_f = 0.15d0, &\n L = 1.25d0, &\n T_c = 2810.d0, &\n R_cst = 365.d0, &\n gama = 1.25d0, &\n grav = 9.81d0, &\n pi = 4.*atan(1.d0)\n real*8 :: p_c, p_c_dot, &\n r, r_dot, &\n A_star\n\n contains\n\n Function m_n_dot(p_c_) \n ! calculate m_n dot to use in ODE\n real*8 :: m_n_dot, p_c_\n m_n_dot = p_c_*A_star*sqrt(gama/(R_cst*T_c))*((gama+1)/2)**(-(gama+1)/(2*(gama-1)))\n return\n End Function m_n_dot \n\n Function rho_c(p_c_)\n ! calculate rho_c to use in ODE\n real*8 :: rho_c, p_c_\n rho_c = p_c_/(R_cst*T_c)\n return\n End Function rho_c\n\n Function f_cor(rad)\n ! perimeter factor\n Implicit none\n real*8 :: f_cor, eta, rad\n eta = (r_f-rad)/(r_f-r_0)\n f_cor = 1.d0\n if( eta < 0 )then\n f_cor = 0\n else if (eta <= 0.15)then\n f_cor = 1-exp(-7*eta)\n end if\n return\n End Function f_cor\n\n Function I_sp(p_c_)\n ! specific impulse\n Implicit none\n real*8 :: I_sp, p_c_\n ! Here, absolute of value inside square root is taken because\n ! there is really small error caused by numerical computing makes\n ! value inside of the square root negative for some intervals\n ! which results in runtime error. This negative value is so small\n ! that its practically zero. Therefore, absolute can be used without \n ! effecting accuracy of result. Using abs solved the runtime error.\n I_sp = (1/grav)*sqrt(abs(((2*gama*R_cst*T_c)/(gama-1))*(1-((p_a/p_c_)**((gama-1)/gama)))))\n return\n End function I_sp \n \n Function ODEs( p_c_ , r_) result ( k )\n Implicit none\n real*8 :: p_c_, r_\n real*8, dimension( no_eqs ) :: k\n r_dot = a*p_c_**n\n k( 1 ) = r_dot\n k( 2 ) = R_cst*T_c*(((f_cor(r_)*2* a * p_c_ ** n)/r_)*(rho_p-rho_c(p_c_))-m_n_dot(p_c_)/(pi*L*r_**2))\n return\n End function\n\n Subroutine RK4( t, del_t )\n Implicit none\n integer, parameter :: no_stages = 4\n real*8 :: t, del_t\n real*8, dimension( no_eqs ) :: result(no_eqs)\n\n ! RK4 has to be calculated such that after the calculation\n ! p_c shouldn't change. Because rk4 is used first while trying\n ! to determine the step size. If p_c changes while calculating \n ! step size, calculation will be wrong. Therefore, in the bonus\n ! part, RK4 must be calculated in a different function, which\n ! does not change the inputs value. This is why this part of \n ! code is different than the main code.\n result = RK4_(p_c,r,del_t)\n\n r = result(1) ! r is updated\n p_c = result(2) ! p_c is updated\n\n t = t + del_t !time is updated\n return\n End subroutine\n\n function RK2(p_c_,r_,del_t) result(res)\n implicit none\n integer, parameter :: no_stages = 2\n real*8 :: p_c_, del_t ,r_\n real*8, dimension( no_eqs ) :: k( no_stages, no_eqs ) , res(no_eqs)\n k(1,:) = ODEs(p_c_ , r_)\n\n res(1) = r_ + 0.5d0 * del_t * k(1,1)\n res(2) = p_c_ + 0.5d0 * del_t * k(1,2)\n \n k(2,:) = ODEs(res(2), res(1))\n res(1) = r_ + k(2,1) * del_t\n res(2) = p_c_ + k(2,2) * del_t\n return\n end function\n\n function RK4_(p_c_, r_, del_t) result(res)\n implicit none\n integer, parameter :: no_stages = 4\n real*8 :: p_c_, del_t ,r_\n real*8, dimension( no_eqs ) :: k( no_stages, no_eqs ), phi(no_eqs), res(no_eqs)\n \n k(1,:) = ODEs(p_c_, r_)\n\n res(2) = p_c_ + 0.5d0 * del_t *k(1,2)\n res(1) = r_ + 0.5d0 * del_t * k(1,1)\n \n k(2,:) = ODEs(res(2), res(1))\n\n res(2) = p_c_ + 0.5d0 * del_t * k(2,2)\n res(1) = r_ + 0.5d0 * del_t * k(2,1)\n\n k(3,:) = ODEs(res(2), res(1))\n\n res(2) = p_c_ + del_t * k(3,2)\n res(1) = r_ + del_t * k(3,1)\n\n k(4,:) = ODEs(res(2), res(1))\n\n phi(:) = (1.0/6)* (k(1, : )+2*k(2, : )+2*k(3, : )+k(4, : )) \n \n res(2) = p_c_ + phi(2) * del_t\n res(1) = r_ + phi(1) * del_t\n \n return\n end function\nEnd module\n\nProgram Rocket_Perf\n Use rocket_params_vars_bonus\n Implicit none\n character*40 :: fname\n real*8 :: dt, time, isp\n integer :: nstep = 0\n real*8 :: th_radius\n\n ! Variables for the bonus part\n real*8, parameter :: E_allowed = 0.0001 ! Allowed error for adaptive stepsize\n real*8 :: E_o\n real*8, dimension(no_eqs) :: dummyRK4(no_eqs), dummyRK2(no_eqs)\n\n write(*,'(a)') 'Enter throat radius in centimeters :'\n write(*,'(a)',advance='no') ':> '\n read*, th_radius\n \nA_star = pi * (th_radius/100)**2\n\n print*,'enter the initial time step size, dt [s] : '\n read*, dt\n\n!.. initial params\n p_c = p_a ! chamber pressure\n r = r_0 ! chamber radius\n isp = I_sp(p_c) ! Specific Impulse\n\n write(*,'(a)',advance='no')' Enter the output file name [rocket.dat]:>'\n read(*,'(a)') fname\n if( fname .eq. ' ') fname = 'rocket.dat'\n open(1 ,file=fname, form='formatted')\n write(1,*)' \"t [s]\" \"p_c [MPa]\" \"I_sp[s]\" \"r_dot[m/s]\"'\n\n time = 0.d0\n nstep = 0\n\n do while( p_c >= p_a )\n nstep = nstep + 1\n\n ! Dummy variables to hold temporary solutions for step size calculation\n dummyRK4 = RK4_(p_c,r,dt)\n dummyRK2 = RK2(p_c,r,dt)\n \n ! Calculate local truncation error\n E_o = (dummyRK4(2) - dummyRK2(2))/dummyRK4(2)\n\n ! Step size is updated\n dt = dt * (abs(E_allowed / E_o))**0.20d0 \n \n ! update solution and time\n call RK4(time, dt)\n\n ! calculate isp\n isp = I_sp(p_c)\n\n ! print on screen and store soln\n if( nstep == 1 .or. mod(nstep,5)==0) &\n write(1,'(8(4x,e12.6))') time, p_c*1.d-6 ,isp, r_dot\n write(*,'(8(a,e9.3))')' t = ',time,' s, p_c = ', p_c*1d-6,' MPa, I_sp = ', isp, ' s r_dot = ',r_dot,' m/s'\n enddo\n \n ! Print the interval number for bonus part\n write(*,*) 'Number of time intervals needed = ', nstep\n close(1)\n\n stop\nEnd\n\n\n", "meta": {"hexsha": "de25dcb805ac9f3ed37a23817d8e713e5b8a7c03", "size": 6372, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Homework2/homework2_bonus.f90", "max_stars_repo_name": "Atknssl/AE305-Homeworks", "max_stars_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-06T18:42:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-04T13:27:27.000Z", "max_issues_repo_path": "Homework2/homework2_bonus.f90", "max_issues_repo_name": "Atknssl/AE305-Homeworks", "max_issues_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework2/homework2_bonus.f90", "max_forks_repo_name": "Atknssl/AE305-Homeworks", "max_forks_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.5739910314, "max_line_length": 114, "alphanum_fraction": 0.565913371, "num_tokens": 2225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193595, "lm_q2_score": 0.8244619263765706, "lm_q1q2_score": 0.7600894466272353}} {"text": "module spline\n !\n ! Spline implementation according to Sormann, \n ! https://itp.tugraz.at/LV/sormann/NumPhysik/\n \n implicit none\n save\n\ncontains\n\n function spline_coeff(x, y)\n !\n ! returns spline coefficients\n !\n !! Input\n real(8) :: x(:), y(:)\n !! Output\n real(8) :: spline_coeff(size(x)-1,5)\n !! Variables\n integer :: n, info\n real(8) :: r(size(x)-1), h(size(x)-1),&\n dl(size(x)-3), d(size(x)-2), c(size(x)-2)\n\n n = size(x)\n\n h = x(2:) - x(1:n-1)\n r = y(2:) - y(1:n-1)\n \n dl = h(2:n-2)\n d = 2d0*(h(1:n-2)+h(2:))\n\n !print *,dl\n !print *,d\n\n c = 3d0*(r(2:)/h(2:)-r(1:n-2)/h(1:n-2))\n \n call dptsv(n-2, 1, d, dl, c, n-2, info)\n \n spline_coeff = 0d0\n spline_coeff(:,1) = x(1:n-1)\n spline_coeff(:,2) = y(1:n-1)\n spline_coeff(1,3) = r(1)/h(1) - h(1)/3d0*c(1)\n spline_coeff(2:n-2,3) = r(2:n-2)/h(2:n-2)-h(2:n-2)/3d0*(c(2:n-2)+2*c(1:n-3))\n spline_coeff(n-1,3) = r(n-1)/h(n-1)-h(n-1)/3d0*(2*c(n-2))\n spline_coeff(1,4) = 0\n spline_coeff(2:,4) = c\n spline_coeff(1,5) = 1/(3*h(1))*c(1)\n spline_coeff(2:n-2,5) = 1/(3*h(2:n-2))*(c(2:n-2)-c(1:n-3))\n spline_coeff(n-1,5) = 1/(3*h(n-1))*(-c(n-2))\n end function spline_coeff\n\n function spline_val_0(coeff, x)\n !\n ! returns spline values\n !\n !! Input\n real(8) :: x, coeff(:,:)\n !! Output\n real(8) :: spline_val_0(3)\n !! Variables\n real(8) :: z\n integer :: n, ju, jl, jm, j\n\n n = size(coeff,1)+1\n jl = 0\n ju = n\n\n do while (ju-jl > 1)\n jm = (jl+ju)/2\n if (x > coeff(jm,1)) then\n jl = jm\n else\n ju = jm\n end if\n end do\n\n j = jl\n if (j==0) j=1\n if (j==n) j=n-1\n\n z = x - coeff(j,1)\n spline_val_0(1) = ((coeff(j,5)*z+coeff(j,4))*z+coeff(j,3))*z+coeff(j,2)\n spline_val_0(2) = (3d0*coeff(j,5)*z+2d0*coeff(j,4))*z+coeff(j,3)\n spline_val_0(3) = 6d0*coeff(j,5)*z+2d0*coeff(j,4)\n end function spline_val_0\n \n function spline_val(coeff, x)\n !\n ! returns spline coefficients\n !\n !! Input\n real(8) :: x(:), coeff(:,:)\n !! Output\n real(8) :: spline_val(size(x),3)\n !! Variables\n integer :: k\n\n ! TODO: make this more efficient\n do k=1,size(x)\n spline_val(k,:) = spline_val_0(coeff, x(k))\n end do\n\n end function spline_val\n\nend module spline\n", "meta": {"hexsha": "6da53f5a343cb750a0f3b5146a5628ee67fa3f7e", "size": 2358, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "spline.f90", "max_stars_repo_name": "itpplasma/spline", "max_stars_repo_head_hexsha": "748f3012d18c637d9a94848610a3097b880185e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-30T16:47:45.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-30T16:47:45.000Z", "max_issues_repo_path": "spline.f90", "max_issues_repo_name": "itpplasma/spline", "max_issues_repo_head_hexsha": "748f3012d18c637d9a94848610a3097b880185e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "spline.f90", "max_forks_repo_name": "itpplasma/spline", "max_forks_repo_head_hexsha": "748f3012d18c637d9a94848610a3097b880185e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.2452830189, "max_line_length": 80, "alphanum_fraction": 0.5038167939, "num_tokens": 969, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.8244619177503206, "lm_q1q2_score": 0.7600894439804882}} {"text": "module distributions\n use nrtype\ncontains\n pure function radial_sine_dist(radius,angle)\n implicit none\n real(dp), intent(in), optional :: radius\n real(dp), intent(in), optional :: angle\n real(dp) radial_sine_dist\n radial_sine_dist = sin(radius)**2./radius**3.\n end function radial_sine_dist\n\n pure function radial_sine_cos_dist(radius,angle)\n implicit none\n real(dp), intent(in), optional :: radius\n real(dp), intent(in), optional :: angle\n real(dp) radial_sine_cos_dist\n radial_sine_cos_dist = sin(radius)**2.*cos(radius)**2./radius**3.\n end function radial_sine_cos_dist\n\n pure function radial_exp_decay_cos(radius,angle)\n implicit none\n real(dp), intent(in), optional :: radius\n real(dp), intent(in), optional :: angle\n real(dp) radial_exp_decay_cos\n radial_exp_decay_cos = cos(radius)**2.*exp(-radius)\n end function radial_exp_decay_cos\n\n pure function bivariate_gaussian(x, aux)\n implicit none\n real(dp), intent(in), optional :: x(:), aux(:)\n\n real(dp) :: bivariate_gaussian\n real(dp) :: sig_x_y, rho_fact, d_x_mu_x, d_y_mu_y\n\n ! Equivalence.\n ! x = x(1)\n ! y = x(2)\n ! rho = aux(1)\n ! mu_x = aux(2)\n ! mu_y = aux(3)\n ! sig_x = aux(4)\n ! sig_y = aux(5)\n\n sig_x_y = 1./aux(4)*aux(5)\n rho_fact = 1./(1-aux(1)**2.)\n d_x_mu_x = x(1)-aux(2)\n d_y_mu_y = x(2)-aux(3)\n\n bivariate_gaussian = 1./tau * sig_x_y * sqrt(rho_fact) * &\n exp( &\n - 0.5 * rho_fact * &\n ( &\n d_x_mu_x ** 2. / aux(4) ** 2. &\n + d_y_mu_y ** 2. / aux(5) ** 2. &\n - 2. * aux(1) * d_x_mu_x * d_y_mu_y / ( aux(4) * aux(5) ) &\n ) &\n )\n end function bivariate_gaussian\nend module distributions\n", "meta": {"hexsha": "0c3193fb3f3c0076576fd77d9dab4311bbf3b9ff", "size": 1687, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "prob_stats/distributions.f08", "max_stars_repo_name": "dcelisgarza/applied_math", "max_stars_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2015-09-30T19:22:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T23:33:04.000Z", "max_issues_repo_path": "prob_stats/distributions.f08", "max_issues_repo_name": "dcelisgarza/applied_math", "max_issues_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "prob_stats/distributions.f08", "max_forks_repo_name": "dcelisgarza/applied_math", "max_forks_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1166666667, "max_line_length": 69, "alphanum_fraction": 0.6259632484, "num_tokens": 541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047847, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.7599922736124818}} {"text": "module math_m\r\n#ifdef dnad\r\n use dnadmod\r\n#define real type(dual)\r\n#endif\r\n\r\n implicit none\r\n REAL, parameter :: pi = 3.1415926535897932\r\ncontains\r\n\r\nsubroutine math_plane_normal(p1,p2,p3,ans)\r\n implicit none\r\n real,dimension(3) :: p1,p2,p3,a,b,ans\r\n\r\n a = p2 - p1\r\n b = p3 - p1\r\n call math_cross_product(a,b,ans)\r\nend subroutine math_plane_normal\r\n\r\nreal function math_max(dim,vec)\r\n implicit none\r\n integer :: dim,i\r\n real :: vec(dim)\r\n math_max = vec(1)\r\n do i=1,dim\r\n if(vec(i) > math_max) math_max = vec(i)\r\n end do\r\nend function math_max\r\n\r\nreal function math_length(dim,p1,p2)\r\n implicit none\r\n integer :: dim,i\r\n real,dimension(dim) :: p1,p2\r\n math_length = 0.0\r\n do i=1,dim\r\n math_length = math_length + (p2(i)-p1(i))**2\r\n end do\r\n math_length = sqrt(math_length)\r\nend function math_length\r\n\r\n\r\nsubroutine math_reflect_point(A,B,C,D,P,ans)\r\n implicit none\r\n real :: A,B,C,D,P(3),ans(3),mult\r\n mult = 2.0*(A*P(1) + B*P(2) + C*P(3) + D)/(A**2 + B**2 + C**2)\r\n ans(1) = P(1) - mult*A\r\n ans(2) = P(2) - mult*B\r\n ans(3) = P(3) - mult*C\r\nend subroutine math_reflect_point\r\n\r\n\r\nreal function math_mag(n,vec)\r\n implicit none\r\n integer :: n\r\n real :: vec(n)\r\n math_mag = sqrt(dot_product(vec,vec))\r\nend function math_mag\r\n\r\nsubroutine math_cross_product(a,b,c)\r\n implicit none\r\n real :: a(3),b(3),c(3)\r\n c(1) = a(2)*b(3)-a(3)*b(2);\r\n c(2) = a(3)*b(1)-a(1)*b(3);\r\n c(3) = a(1)*b(2)-a(2)*b(1);\r\nend subroutine math_cross_product\r\n\r\nsubroutine math_rot_x(vec,th)\r\n implicit none\r\n real :: vec(3),th,rm(3,3),ans(3)\r\n\r\n rm(1,1) = 1.0;\r\n rm(1,2) = 0.0;\r\n rm(1,3) = 0.0;\r\n rm(2,1) = 0.0;\r\n rm(2,2) = cos(th);\r\n rm(2,3) = -sin(th);\r\n rm(3,1) = 0.0;\r\n rm(3,2) = sin(th);\r\n rm(3,3) = cos(th);\r\n ans = matmul(rm,vec)\r\n vec = ans\r\nend subroutine math_rot_x\r\n\r\nsubroutine math_rot_y(vec,th)\r\n implicit none\r\n real :: vec(3),th,rm(3,3),ans(3)\r\n\r\n rm(1,1) = cos(th);\r\n rm(1,2) = 0.0;\r\n rm(1,3) = sin(th);\r\n rm(2,1) = 0.0;\r\n rm(2,2) = 1.0;\r\n rm(2,3) = 0.0;\r\n rm(3,1) = -sin(th);\r\n rm(3,2) = 0.0;\r\n rm(3,3) = cos(th);\r\n ans = matmul(rm,vec)\r\n vec = ans\r\nend subroutine math_rot_y\r\n\r\nsubroutine math_rot_z(vec,th)\r\n implicit none\r\n real :: vec(3),th,rm(3,3),ans(3)\r\n\r\n rm(1,1) = cos(th);\r\n rm(1,2) = -sin(th);\r\n rm(1,3) = 0.0;\r\n rm(2,1) = sin(th);\r\n rm(2,2) = cos(th);\r\n rm(2,3) = 0.0;\r\n rm(3,1) = 0.0;\r\n rm(3,2) = 0.0;\r\n rm(3,3) = 1.0;\r\n ans = matmul(rm,vec)\r\n vec = ans\r\nend subroutine math_rot_z\r\n\r\n\r\n!-----------------------------------------------------------------------------------------------------------\r\n subroutine math_matinv(n,a,ai)\r\n implicit none\r\n!\r\n! This sobroutine inverts a matrix \"a\" and returns the inverse in \"ai\"\r\n! n - Input by user, an integer specifying the size of the matrix to be inverted.\r\n! a - Input by user, an n by n real array containing the matrix to be inverted.\r\n! ai - Returned by subroutine, an n by n real array containing the inverted matrix.\r\n! d - Work array, an n by 2n real array used by the subroutine.\r\n! io - Work array, a 1-dimensional integer array of length n used by the subroutine.\r\n!\r\n integer :: n,i,j,k,m,itmp\r\n real :: a(n,n),ai(n,n),tmp,r !,d(n,2*n)\r\n! integer :: io(n)\r\n real,allocatable,dimension(:,:) :: d\r\n integer,allocatable,dimension(:) :: io\r\n\r\n allocate(d(n,2*n))\r\n allocate(io(n))\r\n\r\n d(:,:) = 0.0\r\n io(:) = 0\r\n\r\n! write(6,*)'Inverting vortex panel matrix. Please wait.'\r\n! itime1=mclock()\r\n! Fill in the \"io\" and \"d\" matrix.\r\n! ********************************\r\n do i=1,n\r\n io(i)=i\r\n end do\r\n do i=1,n\r\n do j=1,n\r\n d(i,j)=a(i,j)\r\n if(i.eq.j)then\r\n d(i,n+j)=1.\r\n else\r\n d(i,n+j)=0.\r\n endif\r\n end do\r\n end do\r\n! Scaling\r\n! *******\r\n do i=1,n\r\n m=1\r\n do k=2,n\r\n if(abs(d(i,k)).gt.abs(d(i,m))) m=k\r\n end do\r\n tmp=d(i,m)\r\n do k=1,2*n\r\n d(i,k)=d(i,k)/tmp\r\n end do\r\n end do\r\n! Lower Elimination\r\n! *****************\r\n do i=1,n-1\r\n! Pivoting\r\n! ********\r\n m=i\r\n do j=i+1,n\r\n if(abs(d(io(j),i)).gt.abs(d(io(m),i))) m=j\r\n end do\r\n itmp=io(m)\r\n io(m)=io(i)\r\n io(i)=itmp\r\n! Scale the Pivot element to unity\r\n! ********************************\r\n r=d(io(i),i)\r\n do k=1,2*n\r\n d(io(i),k)=d(io(i),k)/r\r\n end do\r\n! ********************************\r\n do j=i+1,n\r\n r=d(io(j),i)\r\n do k=1,2*n\r\n d(io(j),k)=d(io(j),k)-r*d(io(i),k)\r\n end do\r\n end do\r\n end do\r\n! Upper Elimination\r\n! *****************\r\n r=d(io(n),n)\r\n do k=1,2*n\r\n d(io(n),k)=d(io(n),k)/r\r\n end do\r\n do i=n-1,1,-1\r\n do j=i+1,n\r\n r=d(io(i),j)\r\n do k=1,2*n\r\n d(io(i),k)=d(io(i),k)-r*d(io(j),k)\r\n end do\r\n end do\r\n end do\r\n! Fill Out \"ai\" matrix\r\n! ********************\r\n do i=1,n\r\n do j=1,n\r\n ai(i,j)=d(io(i),n+j)\r\n end do\r\n end do\r\n! itime2=mclock()\r\n! rtime=real(itime2-itime1)/1000.\r\n! write(6,'(a,f7.2,a)')' Matrix inversion time =',rtime,' sec'\r\n deallocate(d)\r\n deallocate(io)\r\n return\r\n end subroutine math_matinv\r\n\r\n\r\nSUBROUTINE math_AXB_LUD(n,A,B,X)\r\n!Solves a general [A]*X=B on an nxn matrix\r\n IMPLICIT NONE\r\n INTEGER::n,D,info\r\n real,DIMENSION(n)::B,X\r\n real,DIMENSION(n,n)::A\r\n\r\n INTEGER,allocatable,DIMENSION(:) :: INDX\r\n\r\n allocate(INDX(n))\r\n\r\n CALL math_LUDCMP(A,n,INDX,D,info)\r\n if(info.eq.0) then\r\n CALL math_LUBKSB(A,n,INDX,B)\r\n end if\r\n if(info.eq.1) then\r\n write(*,*) ' The system matrix is singular. No solution.'\r\n end if\r\n X = B\r\n deallocate(INDX)\r\n RETURN\r\nEND SUBROUTINE math_AXB_LUD\r\n\r\n!*******************************************************\r\n!* LU decomposition routines used by test_lu.f90 *\r\n!* *\r\n!* F90 version by J-P Moreau, Paris *\r\n!* --------------------------------------------------- *\r\n!* Reference: *\r\n!* *\r\n!* \"Numerical Recipes By W.H. Press, B. P. Flannery, *\r\n!* S.A. Teukolsky and W.T. Vetterling, Cambridge *\r\n!* University Press, 1986\" [BIBLI 08]. *\r\n!* *\r\n!*******************************************************\r\n!MODULE LU\r\n\r\n!CONTAINS\r\n\r\n! ***************************************************************\r\n! * Given an N x N matrix A, this routine replaces it by the LU *\r\n! * decomposition of a rowwise permutation of itself. A and N *\r\n! * are input. INDX is an output vector which records the row *\r\n! * permutation effected by the partial pivoting; D is output *\r\n! * as -1 or 1, depending on whether the number of row inter- *\r\n! * changes was even or odd, respectively. This routine is used *\r\n! * in combination with LUBKSB to solve linear equations or to *\r\n! * invert a matrix. Return code is 1, if matrix is singular. *\r\n! ***************************************************************\r\n Subroutine math_LUDCMP(A,N,INDX,D,CODE)\r\n implicit none\r\n integer, PARAMETER :: NMAX=100\r\n REAL, parameter :: TINY=1.5D-16\r\n real AMAX,DUM, SUM, A(N,N)!,VV(N)\r\n real,allocatable,dimension(:) :: VV\r\n INTEGER N, CODE, D, INDX(N)\r\n integer :: I,J,K,IMAX\r\n\r\n allocate(VV(N))\r\n\r\n D=1; CODE=0; IMAX = 0\r\n\r\n DO I=1,N\r\n AMAX=0.0\r\n DO J=1,N\r\n IF (ABS(A(I,J)).GT.AMAX) AMAX=ABS(A(I,J))\r\n END DO ! j loop\r\n IF(AMAX.LT.TINY) THEN\r\n CODE = 1\r\n RETURN\r\n END IF\r\n VV(I) = 1.0 / AMAX\r\n END DO ! i loop\r\n\r\n DO J=1,N\r\n DO I=1,J-1\r\n SUM = A(I,J)\r\n DO K=1,I-1\r\n SUM = SUM - A(I,K)*A(K,J)\r\n END DO ! k loop\r\n A(I,J) = SUM\r\n END DO ! i loop\r\n AMAX = 0.0\r\n DO I=J,N\r\n SUM = A(I,J)\r\n DO K=1,J-1\r\n SUM = SUM - A(I,K)*A(K,J)\r\n END DO ! k loop\r\n A(I,J) = SUM\r\n DUM = VV(I)*ABS(SUM)\r\n IF(DUM.GE.AMAX) THEN\r\n IMAX = I\r\n AMAX = DUM\r\n END IF\r\n END DO ! i loop\r\n\r\n IF(J.NE.IMAX) THEN\r\n DO K=1,N\r\n DUM = A(IMAX,K)\r\n A(IMAX,K) = A(J,K)\r\n A(J,K) = DUM\r\n END DO ! k loop\r\n D = -D\r\n VV(IMAX) = VV(J)\r\n END IF\r\n\r\n INDX(J) = IMAX\r\n IF(ABS(A(J,J)) < TINY) A(J,J) = TINY\r\n\r\n IF(J.NE.N) THEN\r\n DUM = 1.0 / A(J,J)\r\n DO I=J+1,N\r\n A(I,J) = A(I,J)*DUM\r\n END DO ! i loop\r\n END IF\r\n END DO ! j loop\r\n\r\n deallocate(VV)\r\n RETURN\r\n END subroutine math_LUDCMP\r\n\r\n\r\n! ******************************************************************\r\n! * Solves the set of N linear equations A . X = B. Here A is *\r\n! * input, not as the matrix A but rather as its LU decomposition, *\r\n! * determined by the routine LUDCMP. INDX is input as the permuta-*\r\n! * tion vector returned by LUDCMP. B is input as the right-hand *\r\n! * side vector B, and returns with the solution vector X. A, N and*\r\n! * INDX are not modified by this routine and can be used for suc- *\r\n! * cessive calls with different right-hand sides. This routine is *\r\n! * also efficient for plain matrix inversion. *\r\n! ******************************************************************\r\n Subroutine math_LUBKSB(A,N,INDX,B)\r\n implicit none\r\n integer :: N\r\n real SUM, A(N,N),B(N)\r\n INTEGER INDX(N)\r\n integer :: II,I,J,LL\r\n\r\n II = 0\r\n\r\n DO I=1,N\r\n LL = INDX(I)\r\n SUM = B(LL)\r\n B(LL) = B(I)\r\n IF(II.NE.0) THEN\r\n DO J=II,I-1\r\n SUM = SUM - A(I,J)*B(J)\r\n END DO ! j loop\r\n ELSE IF(SUM.NE.0.0) THEN\r\n II = I\r\n END IF\r\n B(I) = SUM\r\n END DO ! i loop\r\n\r\n DO I=N,1,-1\r\n SUM = B(I)\r\n IF(I < N) THEN\r\n DO J=I+1,N\r\n SUM = SUM - A(I,J)*B(J)\r\n END DO ! j loop\r\n END IF\r\n B(I) = SUM / A(I,I)\r\n END DO ! i loop\r\n\r\n RETURN\r\n END subroutine math_LUBKSB\r\n\r\n\r\n!C\r\n!C--------------------------------------------------------------------C\r\n!C The following subroutine computes the LU decomposition for a C\r\n!C diagonally dominant matrix (no pivoting is done). C\r\n!C Inputs: n = number of equations/unknowns C\r\n!C a = nxn coefficient matrix C\r\n!C Outputs: a = nxn matrix containing the LU matrices C\r\n!C C\r\n!C Deryl Snyder, 10-16-98 C\r\n!C--------------------------------------------------------------------C\r\n subroutine math_snyder_ludcmp(a,n)\r\n implicit none\r\n integer :: n,i,j,k\r\n real a(n,n),z\r\n\r\n do k=1,n-1\r\n do i=k+1,n\r\n z=a(i,k)/a(k,k) !compute gauss factor\r\n a(i,k)=z !store gauss factor in matrix\r\n do j=k+1,n\r\n a(i,j)=a(i,j)-z*a(k,j) !apply row operation\r\n enddo\r\n enddo\r\n enddo\r\n return\r\n end subroutine math_snyder_ludcmp\r\n!C--------------------------------------------------------------------C\r\n!C The following subroutine solves for the unknowns (x) given the LU C\r\n!C matrix and the right hand side. C\r\n!C Inputs: n = number of equations/unknowns C\r\n!C a = nxn matrix containing the L and U values C\r\n!C b = n vector containing right hand side values C\r\n!C Outputs: x = n vector containing solution C\r\n!C C\r\n!C Deryl Snyder, 10-16-98 C\r\n!C--------------------------------------------------------------------C\r\n subroutine math_snyder_lusolv(a,b,x,n)\r\n implicit none\r\n integer :: n,i,j,k\r\n real a(n,n),b(n),x(n)\r\n do i=1,n\r\n x(i)=b(i)\r\n end do\r\n do k=1,n-1 !do forward substitution\r\n do i=k+1,n\r\n x(i)=x(i)-a(i,k)*x(k)\r\n enddo\r\n enddo\r\n do i=n,1,-1 !do back subsitution\r\n do j=i+1,n\r\n x(i)=x(i)-a(i,j)*x(j)\r\n enddo\r\n x(i)=x(i)/a(i,i)\r\n enddo\r\n return\r\n end subroutine math_snyder_lusolv\r\n\r\n\r\n!C--------------------------------------------------------------------C\r\n!C The following subroutine fits a parabola through three specified C\r\n!C points and returns the coefficients a, b, c defining this parabola C\r\n!C according to the equation y = a * x**2 + b * x + c C\r\n!C pts = list of three (x, y) points C\r\n!C Outputs: a, b, c = quadratic coefficients C\r\n!C C\r\n!C--------------------------------------------------------------------C\r\n subroutine quadratic_fit(pts, a, b, c)\r\n implicit none\r\n real, dimension(3, 2), intent(in) :: pts\r\n real, intent(out) :: a, b, c\r\n\r\n integer :: i\r\n real, dimension(3, 3) :: m, m_inv\r\n real, dimension(3) :: v, coeff\r\n\r\n do i = 1, 3\r\n m(i, 1) = pts(i, 1)**2\r\n m(i, 2) = pts(i, 1)\r\n m(i, 3) = 1.0\n end do\r\n call math_matinv(3, m, m_inv)\r\n\r\n v(:) = pts(:, 2)\r\n coeff = matmul(m_inv, v)\r\n\r\n a = coeff(1)\r\n b = coeff(2)\r\n c = coeff(3)\r\n\r\n end subroutine quadratic_fit\r\n\r\n\r\nend module math_m\r\n", "meta": {"hexsha": "7dc5a5e0e56399647cb974c8846224c88a977f56", "size": 13905, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "common/math.f90", "max_stars_repo_name": "usuaero/machup", "max_stars_repo_head_hexsha": "a83b90218d1557b68640bab9458f045939bef2cc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2016-02-24T05:04:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T07:40:44.000Z", "max_issues_repo_path": "common/math.f90", "max_issues_repo_name": "usuaero/machup", "max_issues_repo_head_hexsha": "a83b90218d1557b68640bab9458f045939bef2cc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-07-01T10:32:42.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-25T09:45:12.000Z", "max_forks_repo_path": "common/math.f90", "max_forks_repo_name": "usuaero/machup", "max_forks_repo_head_hexsha": "a83b90218d1557b68640bab9458f045939bef2cc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2016-02-23T19:32:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T10:57:02.000Z", "avg_line_length": 28.4355828221, "max_line_length": 109, "alphanum_fraction": 0.4443725279, "num_tokens": 4122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475746920261, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7599911627646269}} {"text": "subroutine dot_sum (result, x, w, length) bind(c)\n use iso_c_binding\n integer(c_int), intent(in) :: length\n real(c_double), dimension(length),intent(in) :: x\n real(c_double), dimension(length),intent(in) :: w \n real(c_double), intent(out) :: result\n real(c_double) temp(length)\n\n temp = x * w\n result = sum(temp)\n return\nend subroutine\n\n", "meta": {"hexsha": "85a20a32c6c269116b1e6562263a5de3563870e6", "size": 364, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "mlearn/functional/CC_FUNC/src/fortran_F.f95", "max_stars_repo_name": "EequalsMCsquare/mlearn", "max_stars_repo_head_hexsha": "bee79618fb80568b99bc2eefcd97dab33967ee12", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-13T16:06:24.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-04T13:44:08.000Z", "max_issues_repo_path": "mlearn/functional/CC_FUNC/src/fortran_F.f95", "max_issues_repo_name": "EequalsMCsquare/mlearn", "max_issues_repo_head_hexsha": "bee79618fb80568b99bc2eefcd97dab33967ee12", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mlearn/functional/CC_FUNC/src/fortran_F.f95", "max_forks_repo_name": "EequalsMCsquare/mlearn", "max_forks_repo_head_hexsha": "bee79618fb80568b99bc2eefcd97dab33967ee12", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.0, "max_line_length": 54, "alphanum_fraction": 0.6510989011, "num_tokens": 99, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7599828290670995}} {"text": "c c c c\n program trig\nc\nc John Mahaffy, Penn State University, CmpSc 201 Example\nc 1/26/96\nc\nC\nC Program to Calculate SIN and COS of ANGLE\nC Given in Degrees\nc\nC angdeg - angle in degrees (INPUT)\n* angrad - angle in radians\nc pi - 3.14159....\nc sinang - sin ( angrad ) OUTPUT\nc cosang - cos ( angrad ) OUTPUT\nc \n implicit none\nc \n real angrad, angdeg, pi, sinang, cosang\n print *, 'Angle in Degrees?'\n read *, angdeg\nc\nc Convert the Angle to Radians\nc \n pi=asin(1.0)*2.0\nc \n angrad=angdeg*pi/180.0\nc\nc Calculate Trig Functions\nc \n sinang=sin(angrad)\nc \n cosang=cos(angrad)\nc\n print *, 'ANGLE =',angdeg,' degrees =',angrad,' radians'\n print *, 'SIN(ANGLE) = ', sinang\n print *, 'COS(ANGLE) = ', cosang\nc\n stop\n end\nc\nc c ", "meta": {"hexsha": "1faca1807bcb3582095a1475ed8df223953da5cd", "size": 874, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "extra/Fortran/trig.f90", "max_stars_repo_name": "jfitz/code-stat", "max_stars_repo_head_hexsha": "dd2a13177f3ef03ab42123ef3cfcbbd062a2ae26", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "extra/Fortran/trig.f90", "max_issues_repo_name": "jfitz/code-stat", "max_issues_repo_head_hexsha": "dd2a13177f3ef03ab42123ef3cfcbbd062a2ae26", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "extra/Fortran/trig.f90", "max_forks_repo_name": "jfitz/code-stat", "max_forks_repo_head_hexsha": "dd2a13177f3ef03ab42123ef3cfcbbd062a2ae26", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.8095238095, "max_line_length": 63, "alphanum_fraction": 0.561784897, "num_tokens": 291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.759886760693142}} {"text": "module m_mg\n use m_bc\n ! no variables in this module\ncontains\n\n ! solves $(\\nabla^2 - c) u = f$ using V-cycle multigrid\n function MGsolve_2DPoisson(u, f, h, c, tol, niters, apply_BCs) result(r_rms)\n implicit none\n ! arguments\n real, intent(inout) :: u(:, :)\n real, intent(in) :: f(:, :)\n real, intent(in) :: h\n real, intent(in) :: c\n real, intent(in) :: tol\n integer, intent(in) :: niters\n logical, intent(in) :: apply_BCs\n ! local variables\n real :: r_rms, f_rms, tolf\n integer :: nx, ny, iter, i, j\n\n ! set nx, ny\n nx = size(u, 1)\n ny = size(u, 2)\n\n ! compute f_rms\n f_rms = 0.0\n do j = 1, ny\n do i = 1, nx\n f_rms = f_rms + f(i, j)**2\n end do\n end do\n f_rms = sqrt(f_rms / (nx * ny))\n\n tolf = tol * f_rms\n\n r_rms = 0.0\n do iter = 1, niters\n ! apply Dirichlet and Neumann BCs for temperature T\n if (apply_BCs) then\n call apply_boundary_conditions(u)\n end if\n ! execute V-cycle iteration\n r_rms = Vcycle_2DPoisson(u, f, h, c, apply_BCs)\n ! print*, iter, r_rms / f_rms\n if (r_rms < tolf) then\n ! print*, 'V-cycle multigrid converged in', iter, 'iterations.'\n exit\n end if\n end do\n\n if (r_rms > tolf) then\n print*, 'V-cycle multigrid failed to converge within', niters, 'iterations.'\n end if\n\n end function MGsolve_2DPoisson\n\n ! performs one Gauss-Seidel iteration on field u\n ! returns rms residual\n function iteration_2DPoisson(u, f, h, c, alpha) result(r_rms)\n implicit none\n ! arguments\n real, intent(inout) :: u(:, :)\n real, intent(in) :: f(:, :)\n real, intent(in) :: h\n real, intent(in) :: c\n real, intent(in) :: alpha\n ! local variables\n real :: r, r_rms\n integer :: nx, ny, i, j\n\n nx = size(u, 1)\n ny = size(u, 2)\n\n ! Gauss-Seidel iteration\n r_rms = 0.0\n do j = 2, ny - 1\n do i = 2, nx - 1\n\n ! compute residual\n r = ( u(i+1, j) &\n + u(i-1, j) &\n + u(i, j+1) &\n + u(i, j-1) &\n - (4.0 + c * h**2) * u(i, j) ) / h**2 - f(i, j)\n\n ! update u\n u(i, j) = u(i, j) + alpha * (h**2 / (4.0 + c * h**2)) * r\n\n ! update r_rms\n r_rms = r_rms + r**2\n\n end do\n end do\n\n r_rms = sqrt(r_rms / (nx * ny))\n\n end function iteration_2DPoisson\n\n ! computes the residual $R = (\\nabla^2 - c) u - f$ in array res\n subroutine residual_2DPoisson(u, f, h, c, res)\n implicit none\n ! arguments\n real, intent(in) :: u(:, :)\n real, intent(in) :: f(:, :)\n real, intent(in) :: h\n real, intent(in) :: c\n real, intent(out) :: res(:, :)\n ! local variables\n integer :: nx, ny\n\n nx = size(u, 1)\n ny = size(u, 2)\n\n res(2:nx-1, 2:ny-1) = ( u(3:nx, 2:ny-1) &\n + u(1:nx-2, 2:ny-1) &\n + u(2:nx-1, 3:ny ) &\n + u(2:nx-1, 1:ny-2) &\n - (4.0 + c * h**2) * u(2:nx-1, 2:ny-1) ) / h**2 &\n - f(2:nx-1, 2:ny-1)\n\n end subroutine\n\n ! copies every other point in fine into coarse\n subroutine restrict(fine, coarse, apply_BCs)\n implicit none\n ! arguments\n real, intent(in) :: fine(:, :)\n real, intent(out) :: coarse(:, :)\n logical, intent(in) :: apply_BCs\n ! local variables\n integer :: nx, ny\n integer :: i, j, ic, jc\n real, parameter :: a4 = 1.0 / 4.0\n real, parameter :: a8 = 1.0 / 8.0\n real, parameter :: a16 = 1.0 / 16.0\n\n nx = size(fine, 1)\n ny = size(fine, 2)\n\n ! initalize coarse to zero (+ Dirichlet(0) BCs)\n coarse = 0.0\n\n ! apply restriction stencil\n jc = 2\n do j = 3, ny-2, 2\n ic = 2\n do i = 3, nx-2, 2\n coarse(ic, jc) = fine(i, j)\n ! coarse(ic, jc) = a4 * fine(i, j) &\n ! + a8 * fine(i+1, j) &\n ! + a8 * fine(i-1, j) &\n ! + a8 * fine(i, j+1) &\n ! + a8 * fine(i, j-1) &\n ! + a16 * fine(i+1, j+1) &\n ! + a16 * fine(i+1, j-1) &\n ! + a16 * fine(i-1, j+1) &\n ! + a16 * fine(i-1, j-1)\n ic = ic + 1\n end do\n jc = jc + 1\n end do\n\n ! apply Neumann BCs for temperature T\n if (apply_BCs) then\n call apply_neumann_boundary_conditions(coarse)\n end if\n\n end subroutine restrict\n\n ! copies coarse into every other point in fine\n ! fill the other points using linear interpolation\n subroutine prolongate(coarse, fine, apply_BCs)\n implicit none\n ! arguments\n real, intent(in) :: coarse(:, :)\n real, intent(out) :: fine(:, :)\n logical, intent(in) :: apply_BCs\n ! local variables\n integer :: nx, ny\n integer :: i, j, ic, jc\n real, parameter :: a2 = 1.0 / 2.0\n real, parameter :: a4 = 1.0 / 4.0\n\n nx = size(fine, 1)\n ny = size(fine, 2)\n\n ! initialize fine to zero (+ Dirichlet(0) BCs)\n fine = 0.0\n\n jc = 2\n do j = 3, ny-2, 2\n ic = 2\n do i = 3, nx-2, 2\n fine(i, j) = coarse(ic, jc)\n fine(i+1, j) = fine(i+1, j) + a2 * coarse(ic, jc)\n fine(i-1, j) = fine(i-1, j) + a2 * coarse(ic, jc)\n fine(i, j+1) = fine(i, j+1) + a2 * coarse(ic, jc)\n fine(i, j-1) = fine(i, j-1) + a2 * coarse(ic, jc)\n fine(i+1, j+1) = fine(i+1, j+1) + a4 * coarse(ic, jc)\n fine(i+1, j-1) = fine(i+1, j-1) + a4 * coarse(ic, jc)\n fine(i-1, j+1) = fine(i-1, j+1) + a4 * coarse(ic, jc)\n fine(i-1, j-1) = fine(i-1, j-1) + a4 * coarse(ic, jc)\n ic = ic + 1\n end do\n jc = jc + 1\n end do\n\n ! apply Neumann BCs for temperature T\n if (apply_BCs) then\n call apply_neumann_boundary_conditions(fine)\n end if\n\n end subroutine prolongate\n\n ! Vcycle multigrid\n recursive function Vcycle_2DPoisson(u_f, rhs, h, c, apply_BCs) result (resV)\n implicit none\n real resV\n ! arguments\n real, intent(inout) :: u_f(:, :)\n real, intent(in) :: rhs(:, :), h, c\n logical, intent(in) :: apply_BCs\n ! local variables\n integer :: nx, ny, nxc, nyc, i\n real, allocatable :: res_c(:, :), corr_c(:, :), res_f(:, :), corr_f(:, :)\n real :: alpha=1.0, res_rms\n\n nx = size(u_f, 1); ny = size(u_f, 2) ! must be power of 2 plus 1\n\n if( nx-1 /= 2*((nx-1)/2) .or. ny-1 /= 2*((ny-1)/2) ) then\n stop 'ERROR:not a power of 2'\n end if\n\n nxc = 1+(nx-1)/2; nyc = 1+(ny-1)/2 ! coarse grid size\n\n if (min(nx, ny) > 5) then ! not the coarsest level\n\n allocate(res_f(nx, ny), corr_f(nx, ny), &\n corr_c(nxc, nyc), res_c(nxc, nyc))\n\n !---------- take 2 iterations on the fine grid--------------\n res_rms = iteration_2DPoisson(u_f, rhs, h, c, alpha)\n res_rms = iteration_2DPoisson(u_f, rhs, h, c, alpha)\n\n !--------- restrict the residual to the coarse grid --------\n call residual_2DPoisson(u_f, rhs, h, c, res_f)\n call restrict(res_f, res_c, apply_BCs)\n\n !---------- solve for the coarse grid correction -----------\n corr_c = 0.\n res_rms = Vcycle_2DPoisson(corr_c, res_c, h*2, c, apply_BCs) ! *RECURSIVE CALL*\n\n !---- prolongate (interpolate) the correction to the fine grid\n call prolongate(corr_c, corr_f, apply_BCs)\n\n !---------- correct the fine-grid solution -----------------\n u_f = u_f - corr_f\n\n !---------- two more smoothing iterations on the fine grid---\n res_rms = iteration_2DPoisson(u_f, rhs, h, c, alpha)\n res_rms = iteration_2DPoisson(u_f, rhs, h, c, alpha)\n\n deallocate(res_f, corr_f, res_c, corr_c)\n\n else\n\n !----- coarsest level (ny=5): iterate to get 'exact' solution\n\n do i = 1, 100\n res_rms = iteration_2DPoisson(u_f, rhs, h, c, alpha)\n end do\n\n end if\n\n resV = res_rms ! returns the rms. residual\n\n end function Vcycle_2DPoisson\n\nend module m_mg\n", "meta": {"hexsha": "5445e420244ad2b4d3ced09a797b040c39672371", "size": 8030, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "m_mg.f90", "max_stars_repo_name": "ntselepidis/FDM-Navier-Stokes", "max_stars_repo_head_hexsha": "fbb9a1741b1d8e3e550db0c2e756d25780c48ed6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-21T15:16:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-21T15:16:04.000Z", "max_issues_repo_path": "m_mg.f90", "max_issues_repo_name": "ntselepidis/FDM-Navier-Stokes", "max_issues_repo_head_hexsha": "fbb9a1741b1d8e3e550db0c2e756d25780c48ed6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "m_mg.f90", "max_forks_repo_name": "ntselepidis/FDM-Navier-Stokes", "max_forks_repo_head_hexsha": "fbb9a1741b1d8e3e550db0c2e756d25780c48ed6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.6785714286, "max_line_length": 85, "alphanum_fraction": 0.5054794521, "num_tokens": 2774, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418283357702, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7598193703447697}} {"text": " program laplace_acc\n\n implicit none\n\n integer :: i,j,k\n integer :: iter,count_rate, count_max,count\n integer :: t_start,t_final\n integer, parameter :: nx=8192,ny=nx,max_iter=2000\n double precision, parameter :: pi=4d0*dtan(1d0) \n real, parameter :: error=0.001\n double precision :: max_err,time_s,&\n d2fx,d2fy\n double precision, allocatable :: f(:,:), f_k(:,:)\n\n allocate(f(nx,ny)); allocate(f_k(nx,ny))\n\n!generate a random vector to define the initial conditions\n\n do i=1,nx\n f(i,1) = dsin(pi*(i-1)/(nx-1))\n f(i,ny) =0d0\n enddo\n do j=1,ny\n f(1,j) = dsin(pi*(j-1)/(ny-1))\n f(nx,j) = 0d0\n enddo\n\n call system_clock(count_max=count_max, count_rate=count_rate)\n\n call system_clock(t_start)\n \n print*, \"--Start the iteration\"\n iter = 0; max_err=1.0\n\n do while (max_err.gt.error.and.iter.le.max_iter)\n\n do j=2,ny-1\n do i=2,nx-1\n d2fx = f(i+1,j) + f(i-1,j)\n d2fy = f(i,j+1) + f(i,j-1)\n\n f_k(i,j) = 0.25*(d2fx + d2fy)\n enddo\n enddo\n\n max_err=0.\n\n do j=2,ny-1\n do i=2,nx-1\n max_err = max(dabs(f_k(i,j) - f(i,j)),max_err)\n f(i,j) = f_k(i,j)\n enddo\n enddo\n\n if(mod(iter,20).eq.0 ) write(*,'(i5,f10.6)') iter,max_err \n iter = iter +1 \n\n enddo\n\n call system_clock(t_final)\n\n time_s = real(t_final - t_start)/real(count_rate)\n\n print*, '--Time it takes (s)', time_s\n print*,\"--Sum\",sum(f_k(:,:))\n end\n\n", "meta": {"hexsha": "ce8b0f00611fbb5aeaef1f361a1fbdab9d7ada96", "size": 1725, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Exercices/Task6/laplace_acc.f90", "max_stars_repo_name": "HichamAgueny/GPU-course", "max_stars_repo_head_hexsha": "295257c7fbc770394e743eb7aa07bf489be10646", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Exercices/Task6/laplace_acc.f90", "max_issues_repo_name": "HichamAgueny/GPU-course", "max_issues_repo_head_hexsha": "295257c7fbc770394e743eb7aa07bf489be10646", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Exercices/Task6/laplace_acc.f90", "max_forks_repo_name": "HichamAgueny/GPU-course", "max_forks_repo_head_hexsha": "295257c7fbc770394e743eb7aa07bf489be10646", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-30T09:04:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T09:04:22.000Z", "avg_line_length": 25.3676470588, "max_line_length": 68, "alphanum_fraction": 0.4834782609, "num_tokens": 527, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787563, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7598193594473065}} {"text": " SUBROUTINE DG01MD( INDI, N, XR, XI, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the discrete Fourier transform, or inverse transform,\nC of a complex signal.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC INDI CHARACTER*1\nC Indicates whether a Fourier transform or inverse Fourier\nC transform is to be performed as follows:\nC = 'D': (Direct) Fourier transform;\nC = 'I': Inverse Fourier transform.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The number of complex samples. N must be a power of 2.\nC N >= 2.\nC\nC XR (input/output) DOUBLE PRECISION array, dimension (N)\nC On entry, this array must contain the real part of either\nC the complex signal z if INDI = 'D', or f(z) if INDI = 'I'.\nC On exit, this array contains either the real part of the\nC computed Fourier transform f(z) if INDI = 'D', or the\nC inverse Fourier transform z of f(z) if INDI = 'I'.\nC\nC XI (input/output) DOUBLE PRECISION array, dimension (N)\nC On entry, this array must contain the imaginary part of\nC either z if INDI = 'D', or f(z) if INDI = 'I'.\nC On exit, this array contains either the imaginary part of\nC f(z) if INDI = 'D', or z if INDI = 'I'.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC If INDI = 'D', then the routine performs a discrete Fourier\nC transform on the complex signal Z(i), i = 1,2,...,N. If the result\nC is denoted by FZ(k), k = 1,2,...,N, then the relationship between\nC Z and FZ is given by the formula:\nC\nC N ((k-1)*(i-1))\nC FZ(k) = SUM ( Z(i) * V ),\nC i=1\nC 2\nC where V = exp( -2*pi*j/N ) and j = -1.\nC\nC If INDI = 'I', then the routine performs an inverse discrete\nC Fourier transform on the complex signal FZ(k), k = 1,2,...,N. If\nC the result is denoted by Z(i), i = 1,2,...,N, then the\nC relationship between Z and FZ is given by the formula:\nC\nC N ((k-1)*(i-1))\nC Z(i) = SUM ( FZ(k) * W ),\nC k=1\nC\nC where W = exp( 2*pi*j/N ).\nC\nC Note that a discrete Fourier transform, followed by an inverse\nC discrete Fourier transform, will result in a signal which is a\nC factor N larger than the original input signal.\nC\nC REFERENCES\nC\nC [1] Rabiner, L.R. and Rader, C.M.\nC Digital Signal Processing.\nC IEEE Press, 1972.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm requires 0( N*log(N) ) operations.\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Feb. 1997.\nC Supersedes Release 2.0 routine DG01AD by R. Dekeyser, State\nC University of Gent, Belgium.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Complex signals, digital signal processing, fast Fourier\nC transform.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, HALF, ONE, TWO, EIGHT\n PARAMETER ( ZERO = 0.0D0, HALF = 0.5D0, ONE = 1.0D0,\n $ TWO = 2.0D0, EIGHT = 8.0D0 )\nC .. Scalar Arguments ..\n CHARACTER INDI\n INTEGER INFO, N\nC .. Array Arguments ..\n DOUBLE PRECISION XI(*), XR(*)\nC .. Local Scalars ..\n LOGICAL LINDI\n INTEGER I, J, K, L, M\n DOUBLE PRECISION PI2, TI, TR, WHELP, WI, WR, WSTPI, WSTPR\nC .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nC .. External Subroutines ..\n EXTERNAL XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC ATAN, DBLE, MOD, SIN\nC .. Executable Statements ..\nC\n INFO = 0\n LINDI = LSAME( INDI, 'D' )\nC\nC Test the input scalar arguments.\nC\n IF( .NOT.LINDI .AND. .NOT.LSAME( INDI, 'I' ) ) THEN\n INFO = -1\n ELSE\n J = 0\n IF( N.GE.2 ) THEN\n J = N\nC WHILE ( MOD( J, 2 ).EQ.0 ) DO\n 10 CONTINUE\n IF ( MOD( J, 2 ).EQ.0 ) THEN\n J = J/2\n GO TO 10\n END IF\nC END WHILE 10\n END IF\n IF ( J.NE.1 ) INFO = -2\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'DG01MD', -INFO )\n RETURN\n END IF\nC\nC Inplace shuffling of data.\nC\n J = 1\nC\n DO 30 I = 1, N\n IF ( J.GT.I ) THEN\n TR = XR(I)\n TI = XI(I)\n XR(I) = XR(J)\n XI(I) = XI(J)\n XR(J) = TR\n XI(J) = TI\n END IF\n K = N/2\nC REPEAT\n 20 IF ( J.GT.K ) THEN\n J = J - K\n K = K/2\n IF ( K.GE.2 ) GO TO 20\n END IF\nC UNTIL ( K.LT.2 )\n J = J + K\n 30 CONTINUE\nC\nC Transform by decimation in time.\nC\n PI2 = EIGHT*ATAN( ONE )\n IF ( LINDI ) PI2 = -PI2\nC\n I = 1\nC\nC WHILE ( I.LT.N ) DO\nC\n 40 IF ( I.LT.N ) THEN\n L = 2*I\n WHELP = PI2/DBLE( L )\n WSTPI = SIN( WHELP )\n WHELP = SIN( HALF*WHELP )\n WSTPR = -TWO*WHELP*WHELP\n WR = ONE\n WI = ZERO\nC\n DO 60 J = 1, I\nC\n DO 50 K = J, N, L\n M = K + I\n TR = WR*XR(M) - WI*XI(M)\n TI = WR*XI(M) + WI*XR(M)\n XR(M) = XR(K) - TR\n XI(M) = XI(K) - TI\n XR(K) = XR(K) + TR\n XI(K) = XI(K) + TI\n 50 CONTINUE\nC\n WHELP = WR\n WR = WR + WR*WSTPR - WI*WSTPI\n WI = WI + WHELP*WSTPI + WI*WSTPR\n 60 CONTINUE\nC\n I = L\n GO TO 40\nC END WHILE 40\n END IF\nC\n RETURN\nC *** Last line of DG01MD ***\n END\n", "meta": {"hexsha": "0a4800a5d5bae5032e34ba4791cc8fff4b5256bf", "size": 6127, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/DG01MD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/DG01MD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/DG01MD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 27.5990990991, "max_line_length": 72, "alphanum_fraction": 0.4886567651, "num_tokens": 1921, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9489172673767973, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7597904666393499}} {"text": " program demo_floor\n implicit none\n real :: x = 63.29\n real :: y = -63.59\n print *, x, floor(x)\n print *, y, floor(y)\n ! elemental\n print *,floor([ &\n & -2.7, -2.5, -2.2, -2.0, -1.5, -1.0, -0.5, &\n & 0.0, &\n & +0.5, +1.0, +1.5, +2.0, +2.2, +2.5, +2.7 ])\n\n ! note even a small deviation from the whole number changes the result\n print *, [2.0,2.0-epsilon(0.0),2.0-2*epsilon(0.0)]\n print *,floor([2.0,2.0-epsilon(0.0),2.0-2*epsilon(0.0)])\n\n ! A=Nan, Infinity or huge(0_KIND) is undefined\n end program demo_floor\n", "meta": {"hexsha": "0dacb2609dae641b601348fd6e558e0d5f02a77b", "size": 629, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/floor.f90", "max_stars_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_stars_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-12-31T17:21:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T15:56:29.000Z", "max_issues_repo_path": "example/floor.f90", "max_issues_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_issues_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/floor.f90", "max_forks_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_forks_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-06T15:56:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-06T15:56:31.000Z", "avg_line_length": 33.1052631579, "max_line_length": 77, "alphanum_fraction": 0.4912559618, "num_tokens": 255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.7597809124115024}} {"text": "SUBROUTINE invar(stress,sigm,dsbar,theta)\r\n!\r\n! This subroutine forms the stress invariants in 2- or 3-d.\r\n!\r\n IMPLICIT NONE\r\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\r\n REAL(iwp),INTENT(IN)::stress(:)\r\n REAL(iwp),INTENT(OUT),OPTIONAL::sigm,dsbar,theta\r\n REAL(iwp)::sx,sy,sz,txy,dx,dy,dz,xj3,sine,s1,s2,s3,s4,s5,s6,ds1,ds2,ds3, &\r\n d2,d3,sq3,zero=0.0_iwp,small=1.e-10_iwp,one=1.0_iwp,two=2.0_iwp, &\r\n three=3.0_iwp,six=6.0_iwp,thpt5=13.5_iwp\r\n INTEGER::nst \r\n nst=UBOUND(stress,1)\r\n SELECT CASE(nst)\r\n CASE(4)\r\n sx=stress(1)\r\n sy=stress(2)\r\n txy=stress(3)\r\n sz=stress(4)\r\n sigm=(sx+sy+sz)/three\r\n dsbar=SQRT((sx-sy)**2+(sy-sz)**2+(sz-sx)**2+six*txy**2)/SQRT(two)\r\n IF(dsbar=one)sine=one\r\n IF(sine<-one)sine=-one\r\n theta=ASIN(sine)/three\r\n END IF\r\n CASE(6)\r\n sq3=SQRT(three)\r\n s1=stress(1) \r\n s2=stress(2)\r\n s3=stress(3) \r\n s4=stress(4)\r\n s5=stress(5)\r\n s6=stress(6)\r\n sigm=(s1+s2+s3)/three\r\n d2=((s1-s2)**2+(s2-s3)**2+(s3-s1)**2)/six+s4*s4+s5*s5+s6*s6\r\n ds1=s1-sigm \r\n ds2=s2-sigm \r\n ds3=s3-sigm\r\n d3=ds1*ds2*ds3-ds1*s5*s5-ds2*s6*s6-ds3*s4*s4+two*s4*s5*s6\r\n dsbar=sq3*SQRT(d2)\r\n IF(dsbar=one)sine=one \r\n IF(sine<-one)sine=-one \r\n theta=ASIN(sine)/three\r\n END IF\r\n CASE DEFAULT\r\n WRITE(*,*)\"wrong size for nst in invar\"\r\n END SELECT\r\nRETURN\r\nEND SUBROUTINE invar\r\n\r\n\r\n\r\n", "meta": {"hexsha": "951d2fb5747de31e8254f122b3a6dab054606719", "size": 1649, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/main/invar.f03", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/main/invar.f03", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/main/invar.f03", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.3692307692, "max_line_length": 76, "alphanum_fraction": 0.605215282, "num_tokens": 721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122708828602, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.7597259321183066}} {"text": "SUBROUTINE inputvector(elev,azim,inputV)\n !** This subroutine converts elev and azim to a 3D vector.\n IMPLICIT NONE\n REAL(8), intent(in) :: elev, azim\n REAL(8), intent(inout), dimension(0:2) :: inputV\n REAL(8) :: elevr, azimr\n REAL(8), parameter :: PI = 4 * atan (1.0_8)\n\n elevr = elev * PI/180\n azimr = azim * PI/180\n\n inputV(0) = sin(azimr)*sin(elevr)\n inputV(1) = -cos(azimr)*sin(elevr)\n inputV(2) = cos(elevr)\n\nEND SUBROUTINE inputvector\n\nSUBROUTINE inv_norm_vector(inputV,inv_inputV,norm_inputV)\n !** This subroutine computes the normalized inverse of the input vector\n IMPLICIT NONE\n REAL(8), intent(in), dimension(0:2) :: inputV\n REAL(8), intent(inout), dimension(0:2) :: inv_inputV, norm_inputV\n\n inv_inputV = -inputV/Maxval(ABS(inputV(0:1)))\n norm_inputV(2) = sqrt(inputV(0)**2+inputV(1)**2)\n norm_inputV(0) = -inputV(0)*inputV(2)/norm_inputV(2)\n norm_inputV(1) = -inputV(1)*inputV(2)/norm_inputV(2)\n\nEND SUBROUTINE inv_norm_vector\n\nSUBROUTINE lineofsight(dem, elev, azim, los, cols, rows)\n !**This routine is adapted from the R/arcgis insol module and is modified\n !**to run in python through the NumPy f2py tool.\n\n IMPLICIT NONE\n INTEGER, intent(in) :: cols, rows\n REAL(8), intent(inout) :: elev, azim\n REAL(8), intent(in), dimension(rows*cols) :: dem\n REAL(8), intent(inout), dimension(0:rows-1, 0:cols-1) :: los\n!f2py intent(in,out) :: los\n REAL(8), dimension(0:rows-1, 0:cols-1) :: z\n REAL(8), dimension(0:2) :: inputV,inv_inputV, norm_inputV, vec2origin\n REAL(8) :: dx, dy, zproj, zcomp\n INTEGER :: idx, jdy, n, i, j, f_i, f_j, casx, casy, newshape(2)\n EXTERNAL :: inputvector, inv_norm_vector\n\n newshape(1)=cols\n newshape(2)=rows\n z=reshape(dem,newshape)\n\n call inputvector(elev, azim, inputV)\n call inv_norm_vector(inputV,inv_inputV,norm_inputV)\n\n !** Make the casx integer large enough to compare effectively\n casx=NINT(1e6*inputV(0))\n SELECT CASE (casx)\n !** if case (:0), inputV(x) negative, vector is West: beginning of grid cols\n CASE (:0)\n f_i=0\n !** Otherwise, vector is East: end of grid cols\n CASE default\n f_i=cols-1\n END SELECT\n\n !** Make the casy integer large enough to compare effectively\n casy=NINT(1e6*inputV(1))\n SELECT CASE (casy)\n !** if case (:0), inputV(x) negative, vector is North: beginning of grid rows\n CASE (:0)\n f_j=0\n !** Otherwise, vector is south: end of grid rows\n CASE default\n f_j=rows-1\n END SELECT\n\n !******************* Grid scanning *******************************\n !** The array los stores cell binary line of sight value. Input is all 1's.\n !** Here we loop col and row wise to find where lineofsight==0.\n !*****************************************************************\n j=f_j\n DO i=0, cols-1\n n = 0\n zcomp = -HUGE(zcomp) !** initial value lower than any possible zproj\n DO\n dx=inv_inputV(0)*n\n dy=inv_inputV(1)*n\n idx = NINT(i+dx)\n jdy = NINT(j+dy)\n IF ((idx < 0) .OR. (idx >= cols) .OR. (jdy < 0) .OR. (jdy >= rows)) exit\n vec2origin(0) = dx\n vec2origin(1) = dy\n vec2origin(2) = z(idx,jdy)\n zproj = Dot_PRODUCT(vec2origin,norm_inputV)\n IF (zproj < zcomp) THEN\n los(idx,jdy) = 0\n ELSE\n zcomp = zproj\n END IF\n n=n+1\n END DO\n END DO\n\n i=f_i\n DO j=0,rows-1\n n = 0\n zcomp = -HUGE(zcomp) !** initial value lower than any possible zproj\n DO\n dx=inv_inputV(0)*n\n dy=inv_inputV(1)*n\n idx = NINT(i+dx)\n jdy = NINT(j+dy)\n IF ((idx < 0) .OR. (idx >= cols) .OR. (jdy < 0) .OR. (jdy >= rows)) exit\n vec2origin(0) = dx\n vec2origin(1) = dy\n vec2origin(2) = z(idx,jdy)\n zproj = Dot_PRODUCT(vec2origin,norm_inputV)\n IF (zproj < zcomp) THEN\n los(idx,jdy) = 0\n ELSE\n zcomp = zproj\n END IF\n n=n+1\n END DO\n END DO\nEND SUBROUTINE lineofsight\n", "meta": {"hexsha": "a367a2021c57cf925be226cc30072b9940687267", "size": 4016, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "roughness/fortran/lineofsight.f90", "max_stars_repo_name": "NAU-PIXEL/roughness", "max_stars_repo_head_hexsha": "dfaa3d2bc448a2ca19cb2d6001cc5dcf8ee26f82", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "roughness/fortran/lineofsight.f90", "max_issues_repo_name": "NAU-PIXEL/roughness", "max_issues_repo_head_hexsha": "dfaa3d2bc448a2ca19cb2d6001cc5dcf8ee26f82", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-11-18T16:26:19.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-18T16:39:08.000Z", "max_forks_repo_path": "roughness/fortran/lineofsight.f90", "max_forks_repo_name": "NAU-PIXEL/roughness", "max_forks_repo_head_hexsha": "dfaa3d2bc448a2ca19cb2d6001cc5dcf8ee26f82", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-10-09T08:01:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-09T08:01:11.000Z", "avg_line_length": 31.873015873, "max_line_length": 82, "alphanum_fraction": 0.5908864542, "num_tokens": 1361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122732859021, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7597259199709386}} {"text": " subroutine mapc2m_torus(blockno,xc,yc,xp,yp,zp,alpha)\n implicit none\n\n integer blockno\n double precision xc,yc,xp,yp,zp\n double precision alpha, r\n\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n r = 1 + alpha*cos(pi2*yc)\n\n xp = r*cos(pi2*xc)\n yp = r*sin(pi2*xc)\n zp = alpha*sin(pi2*yc)\n\n end\n\n subroutine mapc2m_torus_invert(xp,yp,zp,xc1,yc1,alpha)\n implicit none\n\n double precision xp,yp,zp,xc1,yc1\n double precision alpha\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n double precision r\n\n xc1 = atan2(yp,xp)\n if (xc1 .lt. 0) then\n xc1 = xc1 + pi2\n endif\n xc1 = xc1/pi2\n\n yc1 = asin(zp/alpha)\n\n r = sqrt(xp**2 + yp**2);\n if (r .gt. 1 .and. yc1 .lt. 0) then\nc # Quad IV\n yc1 = yc1 + pi2\n elseif (r .le. 1) then\nc # Quads II and III \n yc1 = pi-yc1\n endif\n yc1 = yc1/pi2\n\n end\n", "meta": {"hexsha": "ddb7c69208a27e060cc67acb97566617ad5f3d22", "size": 987, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/mappings/torus/mapc2m_torus.f", "max_stars_repo_name": "mjberger/forestclaw", "max_stars_repo_head_hexsha": "26038e637b9c5c5224b2cab18fbae0b286106e0c", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/mappings/torus/mapc2m_torus.f", "max_issues_repo_name": "mjberger/forestclaw", "max_issues_repo_head_hexsha": "26038e637b9c5c5224b2cab18fbae0b286106e0c", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mappings/torus/mapc2m_torus.f", "max_forks_repo_name": "mjberger/forestclaw", "max_forks_repo_head_hexsha": "26038e637b9c5c5224b2cab18fbae0b286106e0c", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.74, "max_line_length": 60, "alphanum_fraction": 0.5309017224, "num_tokens": 342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122744874228, "lm_q2_score": 0.7931059414036511, "lm_q1q2_score": 0.7597259162394601}} {"text": "module MC_randoms\r\n use mt_mod\r\n implicit none\r\n integer,parameter:: ik=selected_int_kind(11)\r\n integer,parameter:: rk=selected_real_kind(11,11)\r\n !LCG parameters.\r\n integer(kind=ik),parameter::lcg_m=113829760, lcg_a=10671541, lcg_c=3\r\n integer(kind=ik)::lcg_seed\r\n !Park-Miller parameters\r\n integer(kind=ik),parameter::pm_m=2147483647, pm_a=16807,pm_q=127773,pm_r=2836\r\n integer(kind=ik)::pm_seed\r\n\r\ncontains\r\n !LCG routines\r\n subroutine seed_lcg(seed)\r\n implicit none\r\n integer(kind=ik),intent(in)::seed\r\n lcg_seed=seed\r\n end subroutine seed_lcg\r\n\r\n real(rk) function rand_lcg()\r\n implicit none\r\n integer(kind=ik)::lcg_r\r\n lcg_r=mod(int(lcg_a*lcg_seed+lcg_c,ik),int(lcg_m,ik))\r\n !Return value between [0,1)\r\n rand_lcg=real(lcg_r,rk)/lcg_m\r\n !Change the value for I\r\n lcg_seed=lcg_r\r\n end function rand_lcg\r\n\r\n !Park-Miller routines\r\n subroutine seed_pm(seed)\r\n implicit none\r\n integer(kind=ik),intent(in)::seed\r\n pm_seed=seed\r\n end subroutine seed_pm\r\n\r\n real(rk) function rand_pm()\r\n implicit none\r\n integer(kind=ik)::k\r\n !Schrage approximations with the xor stuff from course material\r\n pm_seed=xor(pm_seed,123459876)\r\n k=pm_seed/pm_q\r\n pm_seed=pm_a*(pm_seed-k*pm_q)-pm_r*k\r\n !Adjust to correct interval\r\n if (rand_pm<0) then\r\n rand_pm=rand_pm + pm_m\r\n end if\r\n !Set the seed and result interval\r\n rand_pm=real(pm_seed,rk)/pm_m\r\n pm_seed=xor(pm_seed,123459876)\r\n end function rand_pm\r\nend module MC_randoms\r\n\r\nprogram MC_ex01_p03\r\n use MC_randoms\r\n implicit none\r\n integer::i\r\n real(rk)::a,b,c,a0,b0,c0\r\n real(rk),allocatable::rng_arr(:),temp_arr(:)\r\n !Problem 3 part a:\r\n call seed_lcg(int(15,ik))\r\n a=rand_lcg()\r\n call seed_pm(int(7895,ik))\r\n b=rand_pm()\r\n call init_genrand64(int(431,ik))\r\n c=genrand64_real3()\r\n print *,\"LCG value: \",a\r\n print *,\"Park-Miller value: \",b\r\n print *,\"Mersenne twister: \",c\r\n\r\n !Problem 3 part b:\r\n !LCG repeat interval:\r\n i=1\r\n do \r\n a0=rand_lcg()\r\n if (a0==a) exit\r\n i=i+1\r\n end do\r\n print*, \"LCG repeat interval:\",i\r\n !Park-Miller repeat interval:\r\n i=1\r\n do \r\n b0=rand_pm()\r\n if (b0==b) exit\r\n i=i+1\r\n end do\r\n print*, \"Park-Miller repeat interval:\",i\r\n !Mersenne twister repeat interval:\r\n i=1\r\n do \r\n c0=genrand64_real3()\r\n if (c0==c) exit\r\n i=i+1\r\n end do\r\n print*, \"Mersenne twister repeat interval:\",i\r\n\r\nend program MC_ex01_p03\r\n", "meta": {"hexsha": "bdcb38e58f6c8e08bc429b4c62ed5d348882e122", "size": 2680, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Nico_Toikka_ex1/p03/ex03.f95", "max_stars_repo_name": "toicca/basics-of-mc", "max_stars_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Nico_Toikka_ex1/p03/ex03.f95", "max_issues_repo_name": "toicca/basics-of-mc", "max_issues_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Nico_Toikka_ex1/p03/ex03.f95", "max_forks_repo_name": "toicca/basics-of-mc", "max_forks_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0707070707, "max_line_length": 82, "alphanum_fraction": 0.6, "num_tokens": 810, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181876, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.7596664294065669}} {"text": " PROGRAM xqromo\r\nC driver for routine qromo\r\n REAL AINF,X1,X2,X3\r\n PARAMETER(X1=0.0,X2=1.5707963,X3=3.1415926,AINF=1.0E20)\r\n REAL res1,res2,result\r\n EXTERNAL funcl,midsql,funcu,midsqu,fncinf,midinf,fncend,midexp\r\n write(*,'(/1x,a)') 'Improper integrals:'\r\n call qromo(funcl,X1,X2,result,midsql)\r\n write(*,'(/1x,a)')\r\n * 'Function: SQRT(x)/SIN(x) Interval: (0,pi/2)'\r\n write(*,'(1x,a,f8.4)')\r\n * 'Using: MIDSQL Result:',result\r\n call qromo(funcu,X2,X3,result,midsqu)\r\n write(*,'(/1x,a)')\r\n * 'Function: SQRT(pi-x)/SIN(x) Interval: (pi/2,pi)'\r\n write(*,'(1x,a,f8.4)')\r\n * 'Using: MIDSQU Result:',result\r\n call qromo(fncinf,X2,AINF,result,midinf)\r\n write(*,'(/1x,a)')\r\n * 'Function: SIN(x)/x**2 Interval: (pi/2,infty)'\r\n write(*,'(1x,a,f8.4)')\r\n * 'Using: MIDINF Result:',result\r\n call qromo(fncinf,-AINF,-X2,result,midinf)\r\n write(*,'(/1x,a)')\r\n * 'Function: SIN(x)/x**2 Interval: (-infty,-pi/2)'\r\n write(*,'(1x,a,f8.4)')\r\n * 'Using: MIDINF Result:',result\r\n call qromo(fncend,X1,X2,res1,midsql)\r\n call qromo(fncend,X2,AINF,res2,midinf)\r\n write(*,'(/1x,a)')\r\n * 'Function: EXP(-x)/SQRT(x) Interval: (0.0,infty)'\r\n write(*,'(1x,a,f8.4)')\r\n * 'Using: MIDSQL,MIDINF Result:',res1+res2\r\n call qromo(fncend,X2,AINF,res2,midexp)\r\n write(*,'(/1x,a)')\r\n * 'Function: EXP(-x)/SQRT(x) Interval: (0.0,infty)'\r\n write(*,'(1x,a,f8.4/)')\r\n * 'Using: MIDSQL,MIDEXP Result:',res1+res2\r\n END\r\n REAL FUNCTION funcl(x)\r\n REAL x\r\n funcl=sqrt(x)/sin(x)\r\n END\r\n REAL FUNCTION funcu(x)\r\n REAL PI\r\n PARAMETER(PI=3.1415926)\r\n REAL x\r\n funcu=sqrt(PI-x)/sin(x)\r\n END\r\n REAL FUNCTION fncinf(x)\r\n REAL x\r\n fncinf=sin(dble(x))/(x**2)\r\n END\r\n REAL FUNCTION fncend(x)\r\n REAL x\r\n fncend=exp(-x)/sqrt(x)\r\n END\r\n", "meta": {"hexsha": "9fd2a507d1770b1965e56bde708c2cbf2b3293de", "size": 2120, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xqromo.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xqromo.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xqromo.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.5517241379, "max_line_length": 69, "alphanum_fraction": 0.4966981132, "num_tokens": 734, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836382, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.759665797274445}} {"text": "! $UWHSPC/codes/mpi/jacobi1d_mpi.f90\n!\n! Domain decomposition version of Jacobi iteration illustrating\n! coarse grain parallelism with MPI.\n!\n! The one-dimensional Poisson problem is solved, u''(x) = -f(x)\n! with u(0) = alpha and u(1) = beta.\n!\n! The grid points are split up into ntasks disjoint sets and each task\n! is assigned one set that it updates for all iterations. The tasks \n! correspond to processes.\n!\n! The task (or process) number is called \"me\" in this code for brevity\n! rather than proc_num.\n!\n! Note that each task allocates only as much storage as needed for its \n! portion of the arrays.\n!\n! Each iteration, boundary values at the edge of each grid must be\n! exchanged with the neighbors.\n\n\nprogram jacobi1d_mpi\n use mpi\n\n implicit none\n\n integer, parameter :: maxiter = 100000, nprint = 5000\n real (kind=8), parameter :: alpha = 20.d0, beta = 60.d0\n\n integer :: i, iter, istart, iend, points_per_task, itask, n\n integer :: ierr, ntasks, me, req1, req2\n integer, dimension(MPI_STATUS_SIZE) :: mpistatus\n real (kind = 8), dimension(:), allocatable :: f, u, uold\n real (kind = 8) :: x, dumax_task, dumax_global, dx, tol\n\n ! Initialize MPI; get total number of tasks and ID of this task\n call mpi_init(ierr)\n call mpi_comm_size(MPI_COMM_WORLD, ntasks, ierr)\n call mpi_comm_rank(MPI_COMM_WORLD, me, ierr)\n\n ! Ask the user for the number of points\n if (me == 0) then\n print *, \"Input n ... \"\n read *, n\n end if\n ! Broadcast to all tasks; everybody gets the value of n from task 0\n call mpi_bcast(n, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)\n\n dx = 1.d0/real(n+1, kind=8)\n tol = 0.1d0*dx**2\n\n ! Determine how many points to handle with each task\n points_per_task = (n + ntasks - 1)/ntasks\n if (me == 0) then ! Only one task should print to avoid clutter\n print *, \"points_per_task = \", points_per_task\n end if\n\n ! Determine start and end index for this task's points\n istart = me * points_per_task + 1\n iend = min((me + 1)*points_per_task, n)\n\n ! Diagnostic: tell the user which points will be handled by which task\n print '(\"Task \",i2,\" will take i = \",i6,\" through i = \",i6)', &\n me, istart, iend\n\n\n ! Initialize:\n ! -----------\n\n ! This makes the indices run from istart-1 to iend+1\n ! This is more or less cosmetic, but makes things easier to think about\n allocate(f(istart-1:iend+1), u(istart-1:iend+1), uold(istart-1:iend+1))\n\n ! Each task sets its own, independent array\n do i = istart, iend\n ! Each task is a single thread with all its variables private\n ! so re-using the scalar variable x from one loop iteration to\n ! the next does not produce a race condition.\n x = dx*real(i, kind=8)\n f(i) = 100.d0*exp(x) ! Source term\n u(i) = alpha + x*(beta - alpha) ! Initial guess\n end do\n \n ! Set boundary conditions if this task is keeping track of a boundary\n ! point\n if (me == 0) u(istart-1) = alpha\n if (me == ntasks-1) u(iend+1) = beta\n\n\n ! Jacobi iteratation:\n ! -------------------\n\n do iter = 1, maxiter\n uold = u\n\n ! Send endpoint values to tasks handling neighboring sections\n ! of the array. Note that non-blocking sends are used; note\n ! also that this sends from uold, so the buffer we're sending\n ! from won't be modified while it's being sent.\n !\n ! tag=1 is used for messages sent to the left\n ! tag=2 is used for messages sent to the right\n\n if (me > 0) then\n ! Send left endpoint value to process to the \"left\"\n call mpi_isend(uold(istart), 1, MPI_DOUBLE_PRECISION, me - 1, &\n 1, MPI_COMM_WORLD, req1, ierr)\n end if\n if (me < ntasks-1) then\n ! Send right endpoint value to process on the \"right\"\n call mpi_isend(uold(iend), 1, MPI_DOUBLE_PRECISION, me + 1, &\n 2, MPI_COMM_WORLD, req2, ierr)\n end if\n\n ! Accept incoming endpoint values from other tasks. Note that\n ! these are blocking receives, because we can't run the next step\n ! of the Jacobi iteration until we've received all the\n ! incoming data.\n\n if (me < ntasks-1) then\n ! Receive right endpoint value\n call mpi_recv(uold(iend+1), 1, MPI_DOUBLE_PRECISION, me + 1, &\n 1, MPI_COMM_WORLD, mpistatus, ierr)\n end if\n if (me > 0) then\n ! Receive left endpoint value\n call mpi_recv(uold(istart-1), 1, MPI_DOUBLE_PRECISION, me - 1, &\n 2, MPI_COMM_WORLD, mpistatus, ierr)\n end if\n\n dumax_task = 0.d0 ! Max seen by this task\n\n ! Apply Jacobi iteration on this task's section of the array\n do i = istart, iend\n u(i) = 0.5d0*(uold(i-1) + uold(i+1) + dx**2*f(i))\n dumax_task = max(dumax_task, abs(u(i) - uold(i)))\n end do\n\n ! Take global maximum of dumax values\n call mpi_allreduce(dumax_task, dumax_global, 1, MPI_DOUBLE_PRECISION, &\n MPI_MAX, MPI_COMM_WORLD, ierr)\n ! Note that this MPI_ALLREDUCE call acts as an implicit barrier,\n ! since no process can return from it until all processes\n ! have called it. Because of this, after this call we know\n ! that all the send and receive operations initiated at the\n ! top of the loop have finished -- all the MPI_RECV calls have\n ! finished in order for each process to get here, and if the\n ! MPI_RECV calls have finished, the corresponding MPI_ISEND\n ! calls have also finished. Thus we can safely modify uold\n ! again.\n\n ! Also periodically report progress to the user\n if (me == 0) then\n if (mod(iter, nprint)==0) then\n print '(\"After \",i8,\" iterations, dumax = \",d16.6,/)', &\n iter, dumax_global\n end if\n end if\n\n ! All tasks now have dumax_global, and can check for convergence\n if (dumax_global < tol) exit\n end do\n\n print '(\"Task number \",i2,\" finished after \",i9,\" iterations, dumax = \",&\n e16.6)', me, iter, dumax_global\n\n\n ! Output result:\n ! --------------\n\n ! Note: this only works if all processes share a file system\n ! and can all open and write to the same file!\n\n ! Synchronize to keep the next part from being non-deterministic\n call mpi_barrier(MPI_COMM_WORLD, ierr)\n\n ! Have each task output to a file in sequence, using messages to\n ! coordinate\n\n if (me == 0) then ! Task 0 goes first\n ! Open file for writing, replacing any previous version:\n open(unit=20, file=\"heatsoln.txt\", status=\"replace\")\n write(20,*) \" x u\"\n write(20, '(2e20.10)') 0.d0, u(0) ! Boundary value at left end\n\n do i = istart, iend\n write(20, '(2e20.10)') i*dx, u(i)\n end do\n\n close(unit=20)\n ! Closing the file should guarantee that all the ouput \n ! will be written to disk.\n ! If the file isn't closed before the next process starts writing,\n ! output may be jumbled or missing.\n\n ! Send go-ahead message to next task\n ! Only the fact that the message was sent is important, not its contents\n ! so we send the special address MPI_BOTTOM and length 0.\n ! tag=4 is used for this message.\n\n if (ntasks > 1) then\n call mpi_send(MPI_BOTTOM, 0, MPI_INTEGER, 1, 4, &\n MPI_COMM_WORLD, ierr)\n endif\n\n else\n ! Wait for go-ahead message from previous task\n call mpi_recv(MPI_BOTTOM, 0, MPI_INTEGER, me - 1, 4, &\n MPI_COMM_WORLD, mpistatus, ierr)\n ! Open file for appending; do not destroy previous contents\n open(unit=20, file=\"heatsoln.txt\", status=\"old\", access=\"append\")\n do i = istart, iend\n write(20, '(2e20.10)') i*dx, u(i)\n end do\n\n ! Boundary value at right end:\n if (me == ntasks - 1) write(20, '(2e20.10)') 1.d0, u(iend+1) \n\n ! Flush all pending writes to disk\n close(unit=20)\n\n if (me < ntasks - 1) then\n ! Send go-ahead message to next task\n call mpi_send(MPI_BOTTOM, 0, MPI_INTEGER, me + 1, 4, &\n MPI_COMM_WORLD, ierr)\n end if\n end if\n\n ! Notify the user when all tasks have finished writing\n if (me == ntasks - 1) print *, \"Solution is in heatsoln.txt\"\n\n ! Close out MPI\n call mpi_finalize(ierr)\n\nend program jacobi1d_mpi\n", "meta": {"hexsha": "8e744b2bfda5f7ea6c4ed666af787be1d3945df5", "size": 8642, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/codes/mpi/jacobi1d_mpi.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/codes/mpi/jacobi1d_mpi.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/codes/mpi/jacobi1d_mpi.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.4641350211, "max_line_length": 80, "alphanum_fraction": 0.6050682712, "num_tokens": 2366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836383, "lm_q2_score": 0.83973396967765, "lm_q1q2_score": 0.7596657936460537}} {"text": "!********************************************************************************\n! Laguerre_LIMITACC: Test limiting accuracy of compensated Laguerre method\n! Authors: Thomas R. Cameron and Aidan O'Neill\n! Institution: Davidson College, Mathematics and Computer Science Department\n! Last Modified: 22 March 2019\n!********************************************************************************\nprogram laguerre_limitAcc\n use eft\n use mproutines\n implicit none\n ! parameters\n integer, parameter :: itnum = 5\n ! polynomial variables\n integer :: deg\n real(kind=dp) :: x\n complex(kind=dp) :: z\n real(kind=dp), allocatable :: poly(:)\n complex(kind=dp), allocatable :: cpoly(:)\n ! testing variables\n real(kind=dp) :: bound, error, compBound, compError, cond, exact, g\n complex(kind=dp) :: cexact\n \n ! random seed\n call init_random_seed()\n ! open real test file\n open(unit=1,file=\"data_files/laguerre_limitAcc_real.dat\")\n write(1,'(A)') 'cond, stan_err_bound, stan_err, comp_err_bound, comp_err'\n ! run real test\n do deg=1,40\n ! allocate polynomial variable\n allocate(poly(deg+1))\n ! polynomial\n call limAccPoly(poly,deg)\n ! exact root\n exact = limAccRoot(poly,deg)\n ! condition number and error bounds\n g = 2*deg*mu/(1-2*deg*mu)\n cond = compCond(poly,exact,deg)\n bound = cond*g\n compBound = mu + cond*g**2\n if(bound>1.0_dp) bound = 1.0_dp\n if(compBound>1.0_dp) compBound = 1.0_dp\n ! standard Laguerre method\n x = exact + exact*compBound\n call SLaguerre(poly,x,deg)\n error = abs(x - exact)/abs(exact)\n if(error1.0_dp) then\n error = 1.0_dp\n end if \n ! compensated Laguerre method\n x = exact + exact*compBound\n call CLaguerre(poly,x,deg)\n compError = abs(x - exact)/abs(exact)\n if(compError1.0_dp) then\n compError = 1.0_dp\n end if\n ! deallocate polynomial\n deallocate(poly)\n ! write to file\n write(1,'(ES15.2)', advance='no') cond\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)', advance='no') bound\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)', advance='no') error\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)', advance='no') compBound\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)') compError\n end do\n ! close real test file\n close(1)\n \n ! open complex test file\n open(unit=1,file=\"data_files/laguerre_limitAcc_cmplx.dat\")\n write(1,'(A)') 'cond, stan_err_bound, stan_err, comp_err_bound, comp_err'\n ! run complex text\n do deg=1,40\n ! allocate polynomial variable\n allocate(cpoly(deg+1))\n ! polynomial\n call limAccPolyCplx(cpoly,deg)\n ! exact root\n cexact = limAccRootCplx(cpoly,deg)\n ! condition number and error bounds\n g = 2*mu/(1-2*mu)\n g = 2*deg*sqrt(2.0_dp)*g/(1-2*deg*sqrt(2.0_dp)*g)\n cond = compCondCplx(cpoly,cexact,deg)\n bound = cond*g\n compBound = mu + cond*g**2\n if(bound>1.0_dp) bound = 1.0_dp\n if(compBound>1.0_dp) compBound = 1.0_dp\n ! standard Laguerre method\n z = cexact + cexact*compBound\n call SLaguerreCplx(cpoly,z,deg)\n error = abs(z - cexact)/abs(cexact)\n if(error1.0_dp) then\n error = 1.0_dp\n end if\n ! compensated Laguerre method\n z = cexact + cexact*compBound\n call CLaguerreCplx(cpoly,z,deg)\n compError = abs(z - cexact)/abs(cexact)\n if(compError1.0_dp) then\n compError = 1.0_dp\n end if\n ! deallocate polynomial\n deallocate(cpoly)\n ! write to file\n write(1,'(ES15.2)', advance='no') cond\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)', advance='no') bound\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)', advance='no') error\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)', advance='no') compBound\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)') compError\n end do\n ! close complex test file\n close(1)\ncontains\n !************************************************\n ! init_random_seed *\n !************************************************\n ! Initiate random seed using system_clock. This\n ! seed is then available for the random number\n ! generator in random_number for the life of\n ! the program.\n !************************************************\n subroutine init_random_seed()\n implicit none\n ! local variables\n integer :: i, n, clock\n integer, dimension(:), allocatable :: seed\n ! intrinsic subroutines\n intrinsic :: random_seed, system_clock\n \n ! main\n call random_seed(size = n)\n allocate(seed(n))\n \n call system_clock(count = clock)\n seed = clock + 37 * (/ (i - 1, i = 1,n) /)\n call random_seed(put = seed)\n \n deallocate(seed)\n end subroutine init_random_seed\n !********************************************************\n ! Standard Laguerre *\n !********************************************************\n ! Computes a root approximation of a polynomial using\n ! standard Laguerre method in dp-precision. The result\n ! is stored in x. \n !********************************************************\n subroutine SLaguerre(poly,x,deg)\n implicit none\n ! argument variables\n integer, intent(in) :: deg\n real(kind=dp), intent(in) :: poly(:)\n real(kind=dp), intent(inout) :: x\n ! local variables\n integer :: j, k\n real(kind=dp) :: alpha, beta, gamma\n \n ! Laguerre's method\n do k=1,itnum\n ! compute alpha and beta\n alpha = poly(deg+1)\n beta = 0.0_dp\n gamma = 0.0_dp\n do j=deg,1,-1\n gamma = x*gamma + beta\n beta = x*beta + alpha\n alpha = x*alpha + poly(j)\n end do\n ! check residual\n if(abs(alpha)abs(beta)) then\n x = x - (deg/alpha)\n else\n x = x - (deg/beta)\n end if\n end do\n end subroutine SLaguerre\n !********************************************************\n ! Standard Laguerre Cplx *\n !********************************************************\n ! Complex version of Standard Laguerre.\n !********************************************************\n subroutine SLaguerreCplx(poly,x,deg)\n implicit none\n ! argument variables\n integer, intent(in) :: deg\n complex(kind=dp), intent(in) :: poly(:)\n complex(kind=dp), intent(inout) :: x\n ! local variables\n integer :: j, k\n complex(kind=dp) :: alpha, beta, gamma\n \n ! Laguerre's method\n do k=1,itnum\n ! compute alpha and beta\n alpha = poly(deg+1)\n beta = cmplx(0.0_dp,0.0_dp,kind=dp)\n gamma = cmplx(0.0_dp,0.0_dp,kind=dp)\n do j=deg,1,-1\n gamma = x*gamma + beta\n beta = x*beta + alpha\n alpha = x*alpha + poly(j)\n end do\n ! check residual\n if(abs(alpha)abs(beta)) then\n x = x - (deg/alpha)\n else\n x = x - (deg/beta)\n end if\n end do\n end subroutine SLaguerreCplx\n !********************************************************\n ! Compensated Laguerre *\n !********************************************************\n ! Computes a root approximation of a polynomial using\n ! compensated Laguerre method in dp-precision, i.e.,\n ! the polynomial evaluation is done using a compensated\n ! Horner's method. The result is stored in x. \n !********************************************************\n subroutine CLaguerre(poly,x,deg)\n ! argument variables\n integer, intent(in) :: deg\n real(kind=dp), intent(in) :: poly(:)\n real(kind=dp), intent(inout) :: x\n ! local variables\n integer :: j, k\n real(kind=dp) :: alpha, alphaErr, beta, betaErr, gamma, gammaErr\n type(REFT) :: prod, sum\n \n ! Laguerre method\n do k=1,itnum\n ! compute alpha and beta\n alpha = poly(deg+1)\n alphaErr = 0.0_dp\n beta = 0.0_dp\n betaErr = 0.0_dp\n gamma = 0.0_dp\n gammaErr = 0.0_dp\n do j=deg,1,-1\n ! product and sum for gamma\n prod = TwoProduct(gamma,x)\n sum = TwoSum(prod%x,beta)\n ! update gamma and gammaErr\n gamma = sum%x\n gammaErr = x*gammaErr + betaErr + (prod%y + sum%y)\n ! product and sum for beta\n prod = TwoProduct(beta,x)\n sum = TwoSum(prod%x,alpha)\n ! update beta and betaErr\n beta = sum%x\n betaErr = x*betaErr + alphaErr + (prod%y + sum%y)\n ! product and sum for alpha\n prod = TwoProduct(alpha,x)\n sum = TwoSum(prod%x,poly(j))\n ! update alpha and alphaErr\n alpha = sum%x\n alphaErr = x*alphaErr + (prod%y + sum%y)\n end do\n ! add error back into result\n gamma = gamma + gammaErr\n beta = beta + betaErr\n alpha = alpha + alphaErr\n ! check residual\n if(abs(alpha)abs(beta)) then\n x = x - (deg/alpha)\n else\n x = x - (deg/beta)\n end if\n end do\n end subroutine CLaguerre\n !********************************************************\n ! Compensated Laguerre Cplx *\n !********************************************************\n ! Complex version of Compensated Laguerre.\n !********************************************************\n subroutine CLaguerreCplx(poly,x,deg)\n ! argument variables\n integer, intent(in) :: deg\n complex(kind=dp), intent(in) :: poly(:)\n complex(kind=dp), intent(inout) :: x\n ! local variables\n integer :: j, k\n complex(kind=dp) :: alpha, alphaErr, beta, betaErr, gamma, gammaErr\n type(CEFTSum) :: sum\n type(CEFTProd) :: prod\n \n ! Laguerre method\n do k=1,itnum\n ! compute alpha and beta\n alpha = poly(deg+1)\n alphaErr = cmplx(0.0_dp,0.0_dp,kind=dp)\n beta = cmplx(0.0_dp,0.0_dp,kind=dp)\n betaErr = cmplx(0.0_dp,0.0_dp,kind=dp)\n gamma = cmplx(0.0_dp,0.0_dp,kind=dp)\n gammaErr = cmplx(0.0_dp,0.0_dp,kind=dp)\n do j=deg,1,-1\n ! product and sum for gamma\n prod = TwoProductCplx(gamma,x)\n sum = TwoSumCplx(prod%p,beta)\n ! update gamma and gammaErr\n gamma = sum%x\n gammaErr = x*gammaErr + betaErr + FaithSumCplx(prod%e,prod%f,prod%g,sum%y)\n ! product and sum for beta\n prod = TwoProductCplx(beta,x)\n sum = TwoSumCplx(prod%p,alpha)\n ! update beta and betaErr\n beta = sum%x\n betaErr = x*betaErr + alphaErr + FaithSumCplx(prod%e,prod%f,prod%g,sum%y)\n ! product and sum for alpha\n prod = TwoProductCplx(alpha,x)\n sum = TwoSumCplx(prod%p,poly(j))\n ! update alpha and alphaErr\n alpha = sum%x\n alphaErr = x*alphaErr + FaithSumCplx(prod%e,prod%f,prod%g,sum%y)\n end do\n ! add error back into result\n gamma = gamma + gammaErr\n beta = beta + betaErr\n alpha = alpha + alphaErr\n ! check residual\n if(abs(alpha)abs(beta)) then\n x = x - (deg/alpha)\n else\n x = x - (deg/beta)\n end if\n end do\n end subroutine CLaguerreCplx\nend program laguerre_limitAcc", "meta": {"hexsha": "da5a705864476f2a3adf7281578fb684ebb8b5df", "size": 14294, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/laguerre_limitAcc.f90", "max_stars_repo_name": "trcameron/FPML-Comp", "max_stars_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/laguerre_limitAcc.f90", "max_issues_repo_name": "trcameron/FPML-Comp", "max_issues_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/laguerre_limitAcc.f90", "max_forks_repo_name": "trcameron/FPML-Comp", "max_forks_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.2192513369, "max_line_length": 90, "alphanum_fraction": 0.463830978, "num_tokens": 3532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.7596657821635926}} {"text": "!> Staged solution\nprogram main\n\n use auto_diff, only: sigmoid\n use auto_diff, only: tree_t, rk, assignment(=)\n use auto_diff, only: operator(*), operator(+), operator(/), operator(**)\n implicit none\n type(tree_t) :: x1, x2\n type(tree_t) :: y\n \n x1 = 3.0_rk\n x2 = -4.0_rk\n\n print *, \"staged demo: y = (x1 + sigmoid(x2))/(sigmoid(x1) + (x1 + x2)**2)\"\n y = (x1 + sigmoid(x2))/(sigmoid(x1) + (x1 + x2)**2)\n\n print *, \"y = \", y%get_value()\n call y%backward()\n\n print *, \"dy/dx1 = \", x1%get_grad()\n print *, \"dy/dx2 = \", x2%get_grad()\n\nend program main\n\n!> staged demo: y = (x1 + sigmoid(x2))/(sigmoid(x1) + (x1 + x2)**2)\n!> y = 1.5456448841066441 \n!> dy/dx1 = -1.1068039935182090\n!> dy/dx2 = -1.5741410376065648", "meta": {"hexsha": "8c0838a7db06da3b60b238b2cb70f1fadbab90b6", "size": 773, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo3.f90", "max_stars_repo_name": "zoziha/Auto-Diff", "max_stars_repo_head_hexsha": "35e62246675cbe6dcd04ce25a81f7885653feabe", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-11-25T13:38:15.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-25T04:14:44.000Z", "max_issues_repo_path": "example/demo3.f90", "max_issues_repo_name": "zoziha/Auto-Diff", "max_issues_repo_head_hexsha": "35e62246675cbe6dcd04ce25a81f7885653feabe", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-24T20:39:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T12:53:58.000Z", "max_forks_repo_path": "example/demo3.f90", "max_forks_repo_name": "zoziha/Auto-Diff", "max_forks_repo_head_hexsha": "35e62246675cbe6dcd04ce25a81f7885653feabe", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.6071428571, "max_line_length": 79, "alphanum_fraction": 0.5549805951, "num_tokens": 291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947455, "lm_q2_score": 0.8128673201042493, "lm_q1q2_score": 0.7595392946630874}} {"text": "! =======================================================================\n! WEIGHTS Compute coefficients for finite difference approximation for\n! the derivatives 1 to m at point z assuming data is known at \n! points in array x. Based on the program \"weights\" in \n! B. Fornberg, \"Calculation of weights in finite difference \n! formulas\", SIAM Review 40 (1998), pp. 685-691.\n! Arguments\n!\n! z (input) DOUBLE\n! location where approximations are to be accurate\n!\n! x (input) DOUBLE Array\n! array containing interpolation points\n!\n! m (input) INTEGER\n! highest derivative for which weights are sought\n!\n! W (output) DOUBLE array, dimension(size(x),m+1)\n! matrix that gives weights at grid locations x for \n! derivative of order j<=m are found in c(:,j)\n! =======================================================================\n\nsubroutine weights_z(z,x,m,W)\n\n ! Arguments\n complex(dp), intent(in) :: z\n complex(dp), intent(in) :: x(:)\n integer, intent(in) :: m\n complex(dp), intent(out) :: W(size(x),m+1)\n\n ! Variable Declarations\n complex(dp) :: c1, c2, c3, c4, c5\n integer :: i,j,k,n,mn\n\n c1 = 1.0_dp\n c4 = x(1) - z\n W = 0.0_dp\n W(1,1) = 1.0_dp\n\n n = size(x)\n do i=2,n\n mn = min(i,m+1)\n c2 = 1.0_dp\n c5 = c4\n c4 = x(i) - z\n do j=1,i-1\n c3 = x(i) - x(j)\n c2 = c2*c3;\n if(j == i-1) then\n do k=mn,2,-1\n W(i,k) = c1*(real(k-1,dp)*W(i-1,k-1) - c5*W(i-1,k))/c2;\n enddo\n W(i,1) = -c1*c5*W(i-1,1)/c2;\n endif\n do k=mn,2,-1\n W(j,k) = (c4*W(j,k) - real(k-1,dp)*W(j,k-1))/c3;\n enddo\n W(j,1) = c4*W(j,1)/c3;\n enddo\n c1 = c2;\n enddo\n\nend subroutine weights_z", "meta": {"hexsha": "b0033a704260416ab2c133335aa2c27e41ca76c7", "size": 1897, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "partitioned/fortran/tools/subroutines/weights_z.f90", "max_stars_repo_name": "buvoli/epbm", "max_stars_repo_head_hexsha": "32ffe175a2e3456799ebc3e6feeb085ff5c83f81", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "partitioned/fortran/tools/subroutines/weights_z.f90", "max_issues_repo_name": "buvoli/epbm", "max_issues_repo_head_hexsha": "32ffe175a2e3456799ebc3e6feeb085ff5c83f81", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "partitioned/fortran/tools/subroutines/weights_z.f90", "max_forks_repo_name": "buvoli/epbm", "max_forks_repo_head_hexsha": "32ffe175a2e3456799ebc3e6feeb085ff5c83f81", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.1111111111, "max_line_length": 75, "alphanum_fraction": 0.4675803901, "num_tokens": 589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7595131680916047}} {"text": "program simple_pi\n\n ! To run, use\n ! $ gfortran -O3 -fcoarray=lib simple_pi.f90 -lcaf_mpi -o simple_pi\n ! $ cafrun -np 4 ./simple_pi\n\n !! implements calculation:\n !! $$ \\pi = \\int_{-1}^1 \\frac{dx}{\\sqrt{1-x^2}}$$\n \n use, intrinsic:: iso_fortran_env, only: dp=>real64, int64, stderr=>error_unit\n implicit none\n \n integer, parameter :: wp = dp\n real(wp), parameter :: x0 = -1.0_wp, x1 = 1.0_wp\n real(wp), parameter :: pi = 4._wp*atan(1.0_wp)\n real(wp) :: psum[*] ! this is a scalar coarray\n integer(int64) :: rate,tic,toc\n real(wp) :: f,x,telaps, dx\n integer :: i, stat, im, Ni\n \n psum = 0._wp\n \n dx = 1e-9_wp ! resolution\n \n Ni = int((x1-x0) / dx) ! (1 - (-1)) / interval\n im = this_image()\n \n !---------------------------------\n if (im == 1) then\n call system_clock(tic)\n print *, \"=========================================\"\n print *,'approximating pi in ',Ni,' steps.'\n print *, \"=========================================\"\n end if\n !---------------------------------\n \n do i = im, Ni-1, num_images() ! Each image works on a subset of the problem\n x = x0 + i*dx\n f = dx / sqrt(1.0_wp - x**2)\n psum = psum + f\n end do\n \n call co_sum(psum)\n \n if (im == 1) then\n print *,'pi:',pi,' iterated pi: ',psum\n print '(A,E10.3)', 'pi error',pi - psum\n endif\n \n if (im == 1) then\n call system_clock(toc)\n call system_clock(count_rate=rate)\n telaps = real((toc - tic), wp) / rate\n print '(A,E9.3,A,I3,A)', 'Elapsed wall clock time ', telaps, ' seconds, using',num_images(),' images.'\n end if\n \nend program simple_pi\n", "meta": {"hexsha": "a9929a8309e5b498123575b64f5ecf2f120db1f1", "size": 1602, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code/simple_pi.f90", "max_stars_repo_name": "carlosal1015/pybr2019", "max_stars_repo_head_hexsha": "fa61c3e33b0acdb8ea88449590b137a4c7d908fb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-10-26T18:06:31.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-06T02:39:26.000Z", "max_issues_repo_path": "code/simple_pi.f90", "max_issues_repo_name": "carlosal1015/pybr2019", "max_issues_repo_head_hexsha": "fa61c3e33b0acdb8ea88449590b137a4c7d908fb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "code/simple_pi.f90", "max_forks_repo_name": "carlosal1015/pybr2019", "max_forks_repo_head_hexsha": "fa61c3e33b0acdb8ea88449590b137a4c7d908fb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-06T02:39:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-06T02:39:30.000Z", "avg_line_length": 27.6206896552, "max_line_length": 107, "alphanum_fraction": 0.5199750312, "num_tokens": 536, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487573, "lm_q2_score": 0.8740772400852111, "lm_q1q2_score": 0.7594217017800572}} {"text": " ! A composite is a number containing at least \n ! two prime factors. For example, 15 = 3 × 5; \n ! 9 = 3 × 3; 12 = 2 × 2 × 3.\n\n ! There are ten composites below thirty containing \n ! precisely two, not necessarily distinct, prime \n ! factors: 4, 6, 9, 10, 14, 15, 21, 22, 25, 26.\n\n ! How many composite integers, n < 10**8, have\n ! precisely two, not necessarily distinct, prime factors?\n\n ! Project Euler: 187 \n !\n ! Answer: 17427258 !/\n\nprogram main\n\n use euler\n\nimplicit none\n\n integer (int32), parameter :: MAXIMUM = 100000000;\n integer (int32), parameter :: N_PRIMES = 3005000;\n integer (int32), allocatable :: primes(:);\n integer (int32) :: i, j, s_count, lim;\n integer (int64) :: tmp;\n\n lim = MAXIMUM / 2;\n\n allocate (primes(N_PRIMES));\n\n call init_primes(primes, lim);\n\n s_count = 0;\n\n outer: &\n do i = 1, N_PRIMES, 1\n\n if(primes(i) == 0) then\n exit outer;\n endif\n\n inner: &\n do j = i, N_PRIMES, 1\n\n tmp = primes(i);\n tmp = tmp * primes(j);\n\n if(tmp == 0 .OR. tmp >= MAXIMUM) then\n exit inner;\n endif\n\n call inc(s_count, 1);\n\n end do inner\n\n end do outer\n\n call printint(s_count);\n\ncontains\n\n subroutine init_primes(primes, n)\n\n integer (int32), intent(out) :: primes(:);\n integer (int32), intent(in) :: n;\n integer (int32) :: i, c;\n primes = 0;\n\n c = 2;\n primes(1) = 2;\n\n do i = 3, n, 2\n\n if(isprime(i)) then\n primes(c) = i;\n call inc(c, 1);\n endif\n end do\n\n end subroutine init_primes\n\n\nend program main\n\n", "meta": {"hexsha": "4fbd868909e1a048f73238ecaff4debb98edd5a6", "size": 1999, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/semiprimes.f95", "max_stars_repo_name": "guynan/project_euler", "max_stars_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-03-08T09:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T13:52:49.000Z", "max_issues_repo_path": "fortran/semiprimes.f95", "max_issues_repo_name": "guynan/project_euler", "max_issues_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-11-03T01:20:46.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-24T22:54:59.000Z", "max_forks_repo_path": "fortran/semiprimes.f95", "max_forks_repo_name": "guynan/project_euler", "max_forks_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-11-03T01:14:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T13:52:51.000Z", "avg_line_length": 23.2441860465, "max_line_length": 61, "alphanum_fraction": 0.4497248624, "num_tokens": 504, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.7593988095933744}} {"text": "!--------------------------------------------------\n!..A SIMPLE EULER SOLVER for ODEs\n!..AE305 - Numerical Methods\n!--------------------------------------------------\nModule data\n parameter ( grav = 9.81 )\n parameter ( fric = 12.5 )\n parameter ( xmass = 70. )\nEnd module\n\nProgram EULER\n character*40 fname\n\n!..Read the stepsize\n print*,\" \"\n write(*,'(/,(a))',advance='no')' Enter TimeStep and FinalTime :> '\n read(*,*) stepsize, finaltime\n\n!..open the output file\n write(*,'(a)',advance='no')' Enter the output file name [velocity.dat]: '\n read(*,\"(a)\") fname\n if( fname .eq. \" \") fname = \"velocity.dat\"\n open(1,file=fname,form=\"formatted\")\n\n!..Set the Initial Conditions and output them\n time = 0.\n velocity = 0.\n write(1,\"(3f12.3)\") time, velocity\n\n\n!..Solution loop\n do while ( time .lt. finaltime )\n time = time + stepsize\n velocity = velocity + ODE(velocity)*stepsize\n write(1,\"(3f12.3)\") time, velocity\n enddo\n\n!..Close the output file\n close(1)\n\n!..Plot the solution with \"xgraph\", \"xmgr\" or \"gnuplot\" on Linux X-windows\n! call SYSTEM(\"xg velocity.dat &\")\n! call SYSTEM(\"xmgr velocity.dat &\")\n! call SYSTEM(\"gnuplot plot.gpl\")\n\n stop\nEnd\n\n\n!--------------------------------------------------\n!..Define the ODE as a function\nFunction ODE(vel)\n use data\n ODE = grav - fric/xmass * vel\n return\nEnd\n", "meta": {"hexsha": "8ac250d324101baaf1fe91601c0cecc38388cc35", "size": 1374, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Homework1/euler.f90", "max_stars_repo_name": "Atknssl/AE305-Homeworks", "max_stars_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-06T18:42:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-04T13:27:27.000Z", "max_issues_repo_path": "Homework1/euler.f90", "max_issues_repo_name": "Atknssl/AE305-Homeworks", "max_issues_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework1/euler.f90", "max_forks_repo_name": "Atknssl/AE305-Homeworks", "max_forks_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.1052631579, "max_line_length": 77, "alphanum_fraction": 0.5553129549, "num_tokens": 404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952921073469, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.759398543365668}} {"text": "! chk_recursive_elemental.f90 --\r\n! Check: does the compiler support recursive elemental functions?\r\n!\r\n! This is a Fortran 2018 feature\r\n!\r\n! Use the somewhat overly used Fibonacci numbers (inspired by a\r\n! blog by Milan Curcic)\r\n!\r\nprogram chk_recursive_elemental\r\n implicit none\r\n\r\n integer, dimension(10) :: f\r\n\r\n f = fibonacci( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] )\r\n\r\n write( *, '(a,10i5)' ) 'The first ten Fibonacci numbers: ', f\r\ncontains\r\nrecursive elemental function fibonacci( n ) result(fib)\r\n integer, intent(in) :: n\r\n integer :: fib\r\n\r\n if ( n <= 0 ) then\r\n fib = 0\r\n elseif ( n == 1 ) then\r\n fib = 1\r\n else\r\n fib = fibonacci(n-1) + fibonacci(n-2)\r\n endif\r\nend function fibonacci\r\nend program chk_recursive_elemental\r\n", "meta": {"hexsha": "57879846d8c6297f666c03527bee5c2f857f4e57", "size": 808, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "chkfeatures/chk_recursive_elemental.f90", "max_stars_repo_name": "timcera/flibs_from_svn", "max_stars_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chkfeatures/chk_recursive_elemental.f90", "max_issues_repo_name": "timcera/flibs_from_svn", "max_issues_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chkfeatures/chk_recursive_elemental.f90", "max_forks_repo_name": "timcera/flibs_from_svn", "max_forks_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.064516129, "max_line_length": 70, "alphanum_fraction": 0.6027227723, "num_tokens": 229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.8152324983301567, "lm_q1q2_score": 0.7593585066564016}} {"text": "\n!Recursive FFT implementation inspired by a Single Assignment C version.\n!Copyright Paul Keir 2012-2016\n!Distributed under the Boost Software License, Version 1.0.\n!(See accompanying file license.txt or copy at http://boost.org/LICENSE_1_0.txt)\n\nmodule fftmod\n\n public :: fft, condense\n integer, parameter :: k = 8 ! kind size\n integer, parameter :: n = SZ ! #define SZ macro. Try 8: gfortran -cpp -DSZ=8\n\n contains\n\n function condense(i,x) result (y)\n integer, intent(in) :: i\n complex(kind=k), dimension(:), intent(in) :: x\n complex(kind=k), dimension(size(x)/i) :: y\n y = x(1:size(x):i)\n end function condense\n\n function cat(a,b) result(res)\n complex(kind=k), dimension(:), intent(in) :: a, b ! Different lengths OK?\n complex(kind=k), dimension(size(a)+size(b)) :: res\n res(1:size(a)) = a\n res(size(a)+1:size(a)+size(b)) = b\n end function cat\n\n recursive function fft(v,rofu) result(res)\n complex(kind=k), dimension(:), intent(in) :: v\n complex(kind=k), dimension(:), intent(in) :: rofu ! size(v/2)\n complex(kind=k), dimension(size(v)) :: res\n complex(kind=k), dimension(size(v)/2) :: left, right\n complex(kind=k), dimension(size(v)/2) :: fft_left, fft_right\n complex(kind=k), dimension(size(rofu)/2) :: rofu_select\n\n if (size(v) > 2) then\n left = condense(2,v)\n right = condense(2,cshift(v,1))\n\n rofu_select = condense(2, rofu)\n\n fft_left = fft(left, rofu_select) !!\n fft_right = fft(right, rofu_select)\n\n fft_right = fft_right * rofu\n\n res = cat(fft_left + fft_right, fft_left - fft_right)\n else\n res = [v(1)+v(2),v(1)-v(2)]\n endif\n\n end function fft\n\nend module fftmod\n\nprogram p\n\n use fftmod\n integer :: i\n integer, parameter :: m = n/2\n real(kind=k), parameter :: pi = 3.141592653589793d0\n complex(kind=k), dimension(m) :: d = (/ (exp(-2. * pi * (0, 1.) / n) ** i, i = 0, m-1) /)\n complex(kind=k), dimension(n) :: x,y\n real(kind=8) :: t1, t2\n\n x = (/ (i, i=0,n-1) /)\n x = 2 * pi / n * x\n x = sin(x)\n\n! write(*,'(8 (\"(\", en12.3, \",\", en12.3, \")\", /))') x\n print *, x\n! print *\n y = fft(x,d)\n y = 2 * pi / n * y\n! write(*,'(8 (\"(\", en12.3, \",\", en12.3, \")\", /))') y\n print *, y\n\nend program p\n\n", "meta": {"hexsha": "11b553296fef5f799e3b6dbfa8e2e08e18a493be", "size": 2307, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "sac_fft.f95", "max_stars_repo_name": "pkeir/ctfft", "max_stars_repo_head_hexsha": "c9ffd0cc5d83836df787f034f108822cbc586b26", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2015-05-29T22:11:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-10T02:11:33.000Z", "max_issues_repo_path": "sac_fft.f95", "max_issues_repo_name": "pkeir/ctfft", "max_issues_repo_head_hexsha": "c9ffd0cc5d83836df787f034f108822cbc586b26", "max_issues_repo_licenses": ["BSL-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sac_fft.f95", "max_forks_repo_name": "pkeir/ctfft", "max_forks_repo_head_hexsha": "c9ffd0cc5d83836df787f034f108822cbc586b26", "max_forks_repo_licenses": ["BSL-1.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2015-07-22T05:17:54.000Z", "max_forks_repo_forks_event_max_datetime": "2016-09-10T06:49:23.000Z", "avg_line_length": 28.4814814815, "max_line_length": 91, "alphanum_fraction": 0.573905505, "num_tokens": 753, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705932, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.7593584956632248}} {"text": "Module gsld !高斯—勒让德积分高斯点及权重的求解模块\n Implicit None\n Integer, Parameter :: n = 5 !设置求解高斯点的个数\n Integer, Parameter :: DP = Selected_Real_Kind( p=13 ) !设置kind的数值\n Real(kind=DP) , parameter :: EPS = 1.0e-15_DP !精度设置\n\nContains\n\n Real(Kind=DP) Function f(x) !定义函数f(x)\n Implicit None\n Integer :: i\n Real (Kind=DP) :: a(n), x !a(n)代表n阶勒让德多项式\n a(1) = x !1阶勒让德多项式\n a(2) = 1.5_DP*(x**2) - 0.5_DP !2阶勒让德多项式\n Do i = 3, n\n a(i) = (2*i-1)*x*a(i-1)/i - (i-1)*a(i-2)/i\n !利用递推关系产生n阶勒让德多项式\n End Do\n f = a(n) !生成的n阶勒让德多项式 \n End Function f\n\n Real(Kind=DP) Function f1(x)\n Implicit None\n Integer :: i\n Real (Kind=DP) :: a(n), x\n a(1) = x\n a(2) = 1.5_DP*x**2 - 0.5_DP\n Do i = 3, n - 1\n a(i) = (2*i-1)*x*a(i-1)/i - (i-1)*a(i-2)/i\n End Do\n f1 = a(n-1) !生成的(n-1)阶勒让德多项式 \n End Function f1\n\n Real (Kind=DP) Function g(x)\n Implicit None\n Integer :: i\n Real (Kind=DP) :: a(n), x\n a(1) = x\n a(2) = 1.5_DP*x**2 - 0.5_DP\n Do i = 3, n\n a(i) = (2*i-1)*x*a(i-1)/i - (i-1)*a(i-2)/i\n End Do\n g = n*a(n-1)/(1-x**2) - n*x*a(n)/(1-x**2)\n !生成n阶勒让德多项式的导数表达式\n End Function g\n\n Real (Kind=DP) Function bis(a, b) !二分法求解函数的解\n Implicit None\n Real (Kind=DP) :: a, b, c\n !a,b是传递进来的划分好的有一个解存在的区间\n Do\n c = (a+b)/2.0_DP\n If (f(c)*f(a)<0) Then\n b = c\n Else\n a = c\n End If\n If ((b-a)b/2\n !\n write (*,\"('Parameters for potential well: V_0, b > ')\", advance=\"no\")\n read (*,*) v0, b\n if ( v0 <= 0.0_dp .or. b <= 0.0_dp) stop ' wrong input parameters, stopping '\n write (*,\"(' V_0, b =',2f10.4)\") v0, b\n !\n ! Plane waves between -a/2 < x < a/2, k_i=+-2*pi*i/a, i=0,1,...,n\n !\n do\n write (*,\"('Parameters for plane waves: a, n > ')\", advance=\"no\")\n ! To exit the loop, type 0 0 or something similar\n read (*,*) a, n\n if ( a <= b .or. n <= 0) stop ' wrong input parameters '\n write (*,\"('a, n=',f8.4,i6)\") a, n\n npw = 2*n+1\n allocate (kn(npw), e(npw), work(3*npw), h(npw,npw) )\n !\n ! Assign values of k_n: n=0,+1,-1,+2,-2, etc\n !\n kn(1) = 0.0_dp\n do i=2,npw-1,2\n kn(i ) = (i/2)*2.0_dp*pi/a\n kn(i+1) =-(i/2)*2.0_dp*pi/a\n end do\n ! cleanup\n h(:,:) = 0.0_dp\n !\n ! Assign values of the matrix elements of the hamiltonian \n ! on the plane wave basis\n !\n do i=1,npw\n do j=1,npw\n if ( i ==j ) then\n h(i,j) = kn(i)**2 - v0/a*b\n else\n h(i,j) = -v0/a * sin( (kn(j)-kn(i))*b/2.0_dp ) / (kn(j)-kn(i))*2.0_dp\n end if\n !print '(2i4,f12.6)', i,j, h(i,j)\n end do\n end do\n !\n ! Solution [expansion coefficients are stored into h(j,i)\n ! j=basis function index, i= eigenvalue index]\n !\n lwork = 3*npw\n ! The \"leading dimension of array\" h is its first dimension\n ! For dynamically allocated matrices, see the \"allocate\" command\n call dsyev ( 'V', 'U', npw, h, npw, e, work, lwork, info )\n if (info /= 0) stop 'H-matrix diagonalization failed '\n !\n write (*,\"(' Lowest eigenvalues:',3f12.6)\") (e(i),i=1,3)\n !\n ! Write to output file the lowest-energy state:\n !\n open (7,file='gs-wfc.out',status='unknown',form='formatted')\n write(7,'(\" x |psi(x)|^2 Re[psi(x)] Im[psi(x)]\")')\n dx = 0.01_dp\n nr = nint(a/2.0_dp/dx)\n norm = 0.d0\n do i=-nr, nr\n x = dx*i\n f = 0.d0\n do j=1,npw\n f = f + h(j,1)*exp((0.0,1.0)*kn(j)*x)/sqrt(a)\n end do\n prob = f*conjg(f)\n norm = norm + prob*dx\n write(7,'(f12.6,3f12.6)') x, prob, f\n end do\n ! verify normalization (if desired):\n write (*,\"(' norm: ',f12.6)\") norm\n close(7)\n deallocate ( h, work, e, kn)\n end do\n !\nend program potentialwell\n\n\n", "meta": {"hexsha": "5cf7e21e5388be24c5a1a82e90ecbb3e4e9c58a8", "size": 3258, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/assgn07_solns/Assgn07_variational_method/Assgn07_potential.f90", "max_stars_repo_name": "Anantha-Rao12/ComPhys", "max_stars_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Solutions/assgn07_solns/Assgn07_variational_method/Assgn07_potential.f90", "max_issues_repo_name": "Anantha-Rao12/ComPhys", "max_issues_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Solutions/assgn07_solns/Assgn07_variational_method/Assgn07_potential.f90", "max_forks_repo_name": "Anantha-Rao12/ComPhys", "max_forks_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.2574257426, "max_line_length": 83, "alphanum_fraction": 0.4815837937, "num_tokens": 1128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.942506726044381, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7593137546334859}} {"text": "SUBMODULE( AutoDiff_Module ) Methods\nIMPLICIT NONE\n\nCONTAINS\n\n!----------------------------------------------------------------------------\n! Derivative\n!----------------------------------------------------------------------------\n\nMODULE PROCEDURE derivative_R_to_R\n Ans = 0.5_DFP * (f( x+eps ) - f( x-eps ))/eps\nEND PROCEDURE derivative_R_to_R\n\n!----------------------------------------------------------------------------\n! Derivative\n!----------------------------------------------------------------------------\n\nMODULE PROCEDURE derivative_R2_to_R\n Ans(1) = 0.5_DFP * (f( x+eps, y ) - f( x-eps, y ))/eps\n Ans(2) = 0.5_DFP * (f( x, y+eps ) - f( x, y-eps ))/eps\nEND PROCEDURE derivative_R2_to_R\n\nEND SUBMODULE Methods", "meta": {"hexsha": "6af95f363478def1aced554750e0171e3d24c285", "size": 851, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pass_func_to_subroutine/AutoDiff_Module@Methods.f90", "max_stars_repo_name": "vickysharma0812/modernFortran", "max_stars_repo_head_hexsha": "54c1ea61e9269f4679462e113f65a7ad383923a9", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pass_func_to_subroutine/AutoDiff_Module@Methods.f90", "max_issues_repo_name": "vickysharma0812/modernFortran", "max_issues_repo_head_hexsha": "54c1ea61e9269f4679462e113f65a7ad383923a9", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pass_func_to_subroutine/AutoDiff_Module@Methods.f90", "max_forks_repo_name": "vickysharma0812/modernFortran", "max_forks_repo_head_hexsha": "54c1ea61e9269f4679462e113f65a7ad383923a9", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.0, "max_line_length": 77, "alphanum_fraction": 0.3360752056, "num_tokens": 171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067163548471, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7593137534249006}} {"text": "program example_lmdif1\n\nuse minpack_module, only: wp, enorm, lmdif1\nuse iso_fortran_env, only: nwrite => output_unit\n\nimplicit none\n\ninteger, parameter :: n = 3\ninteger, parameter :: m = 15\ninteger, parameter :: lwa = m*n+5*n+m\n\ninteger :: info\nreal(wp) :: tol, x(n), fvec(m), wa(lwa)\ninteger :: iwa(n)\n\n! The following starting values provide a rough fit.\nx = [1.0_wp, 1.0_wp, 1.0_wp]\n\n! Set tol to the square root of the machine precision. Unless high precision\n! solutions are required, this is the recommended setting.\ntol = sqrt(epsilon(1.0_wp))\n\ncall lmdif1(fcn, m, n, x, fvec, tol, info, iwa, wa, lwa)\n\nwrite(nwrite, '(5x,a,d15.7//,5x,a,16x,i10//,5x,a//(5x,3d15.7))') &\n 'FINAL L2 NORM OF THE RESIDUALS', enorm(m, fvec), &\n 'EXIT PARAMETER', info, &\n 'FINAL APPROXIMATE SOLUTION', x\n\ncontains\n\nsubroutine fcn(m, n, x, fvec, iflag)\n\n integer, intent(in) :: m\n integer, intent(in) :: n\n real(wp), intent(in) :: x(n)\n real(wp), intent(out) :: fvec(m)\n integer, intent(inout) :: iflag\n\n integer :: i\n real(wp) :: tmp1, tmp2, tmp3\n\n real(wp),parameter :: y(15) = [1.4e-1_wp, 1.8e-1_wp, 2.2e-1_wp, 2.5e-1_wp, 2.9e-1_wp, &\n 3.2e-1_wp, 3.5e-1_wp, 3.9e-1_wp, 3.7e-1_wp, 5.8e-1_wp, &\n 7.3e-1_wp, 9.6e-1_wp, 1.34e0_wp, 2.1e0_wp, 4.39e0_wp]\n\n if (iflag > 0) then ! just to avoid the compiler warning\n do i = 1, 15\n tmp1 = i\n tmp2 = 16 - i\n tmp3 = tmp1\n if (i > 8) tmp3 = tmp2\n fvec(i) = y(i) - (x(1) + tmp1/(x(2)*tmp2 + x(3)*tmp3))\n end do\n end if\n\nend subroutine fcn\n\nend program example_lmdif1", "meta": {"hexsha": "a12bc5d9a4109cad02c3b46787f1d01e80e6c370", "size": 1678, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/example_lmdif1.f90", "max_stars_repo_name": "awvwgk/minpack", "max_stars_repo_head_hexsha": "dc14d611af8d9c16d08039d6e5a6d45b766b8022", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2022-02-02T14:46:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T21:34:09.000Z", "max_issues_repo_path": "examples/example_lmdif1.f90", "max_issues_repo_name": "fortran-lang/minpack", "max_issues_repo_head_hexsha": "c0b5aea9fcd2b83865af921a7a7e881904f8d3c2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 58, "max_issues_repo_issues_event_min_datetime": "2022-02-02T14:43:38.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-18T02:18:48.000Z", "max_forks_repo_path": "examples/example_lmdif1.f90", "max_forks_repo_name": "awvwgk/minpack", "max_forks_repo_head_hexsha": "dc14d611af8d9c16d08039d6e5a6d45b766b8022", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2022-02-02T14:58:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T17:17:47.000Z", "avg_line_length": 28.4406779661, "max_line_length": 91, "alphanum_fraction": 0.5798569726, "num_tokens": 629, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476384, "lm_q2_score": 0.8333246035907933, "lm_q1q2_score": 0.7593084766753594}} {"text": " recursive subroutine factorial(i,f)\n implicit none\n integer f,i,j\n intent(in) i\n intent(out) f\n if (i.le.0) then\n stop 'argument must be > 0'\n else if (i.eq.1) then\n f=i\n else\n call factorial(i-1,j)\n f=i*j\n end if\n end subroutine factorial\n", "meta": {"hexsha": "aec4185bb0f4c47c7be6ad7942bc677fc4fee516", "size": 320, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/t0216x/include/factorial.f", "max_stars_repo_name": "maddenp/ppp", "max_stars_repo_head_hexsha": "81956c0fc66ff742531817ac9028c4df940cc13e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-08-13T16:32:02.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-21T12:37:58.000Z", "max_issues_repo_path": "tests/t0216x/include/factorial.f", "max_issues_repo_name": "maddenp/ppp", "max_issues_repo_head_hexsha": "81956c0fc66ff742531817ac9028c4df940cc13e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/t0216x/include/factorial.f", "max_forks_repo_name": "maddenp/ppp", "max_forks_repo_head_hexsha": "81956c0fc66ff742531817ac9028c4df940cc13e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2015-07-30T17:02:27.000Z", "max_forks_repo_forks_event_max_datetime": "2015-08-03T16:29:41.000Z", "avg_line_length": 21.3333333333, "max_line_length": 41, "alphanum_fraction": 0.51875, "num_tokens": 89, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.759308457320476}} {"text": "\nMODULE USER_DEFINED\n\nUSE MPI\nUSE BASIS, ONLY: GL_POINT\n\nIMPLICIT NONE\n\nCONTAINS\n\nSUBROUTINE INITIAL_CONDITION(N, SOLUTION1)\n!-----------------------------------------------------------------------\n! USER DEFINE INITIAL CONDITION FOR THE WAVE FUNCTION\n!-----------------------------------------------------------------------\n\n IMPLICIT NONE\n \n INTEGER :: N ! PLOYNOMIAL ORDER\n INTEGER :: I\n \n DOUBLE PRECISION :: X\n DOUBLE PRECISION :: SOLUTION1(0:N)\n DOUBLE PRECISION :: SIGMA = 0.2D0\n \n DO I=0, N\n \n X = GL_POINT(I)\n \n SOLUTION1(I) = DEXP((-DLOG(2.0D0)*(X+1.0D0)**2)/(SIGMA**2))\n! SOLUTION1(I) = 1.0D0\n \n ENDDO\n\nEND SUBROUTINE INITIAL_CONDITION\n\nFUNCTION BOUNDARY_SOLUTION(T)\n!!----------------------------------------------------------------------\n!! SOLUTION ON THE BOUNDARY\n!! B.C.\n!!----------------------------------------------------------------------\n USE PARAM, ONLY: C\n\n IMPLICIT NONE\n \n DOUBLE PRECISION :: BOUNDARY_SOLUTION\n DOUBLE PRECISION :: T ! TIME\n DOUBLE PRECISION :: SIGMA = 0.2D0\n \n BOUNDARY_SOLUTION = DEXP(-DLOG(2.0D0)*((C*T)**2)/(SIGMA**2))\n! BOUNDARY_SOLUTION = 1.0D0\n \n RETURN\n \nEND FUNCTION BOUNDARY_SOLUTION\n\nSUBROUTINE EXACT_SOLUTION(T, X, N, EXACT_SOLU)\n\n USE PARAM, ONLY: C\n\n IMPLICIT NONE\n \n INTEGER :: N ! POLY ORDER\n INTEGER :: I\n \n DOUBLE PRECISION :: X(0:N) ! NODES\n DOUBLE PRECISION :: T ! END TIME\n DOUBLE PRECISION :: EXACT_SOLU(0:N) ! RESULTS\n DOUBLE PRECISION :: SIGMA = 0.2D0\n \n DO I=0, N\n EXACT_SOLU(I) = DEXP(-DLOG(2.0D0)*&\n (X(I)-C*T+1.0D0)**2/(SIGMA**2))\n\n ENDDO\n \n \n \n\nEND SUBROUTINE EXACT_SOLUTION\n\nEND MODULE USER_DEFINED\n", "meta": {"hexsha": "568b1019dcb2620cdbc7ddf0075604e1a225ef2f", "size": 1784, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/user_defined.f90", "max_stars_repo_name": "ShiqiHe000/1d_DG_advaction", "max_stars_repo_head_hexsha": "05f0dd809dabc43aa3ee3d765261f658508a21ff", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-15T01:38:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-15T01:38:37.000Z", "max_issues_repo_path": "src/user_defined.f90", "max_issues_repo_name": "ShiqiHe000/1d_DG_advaction", "max_issues_repo_head_hexsha": "05f0dd809dabc43aa3ee3d765261f658508a21ff", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/user_defined.f90", "max_forks_repo_name": "ShiqiHe000/1d_DG_advaction", "max_forks_repo_head_hexsha": "05f0dd809dabc43aa3ee3d765261f658508a21ff", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.756097561, "max_line_length": 72, "alphanum_fraction": 0.4943946188, "num_tokens": 483, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206870747658, "lm_q2_score": 0.8418256393148982, "lm_q1q2_score": 0.759259959008047}} {"text": "c this file contains the following user-callable routines:\nc\nc\nc routine idd_house calculates the vector and scalar\nc needed to apply the Householder transformation reflecting\nc a given vector into its first component.\nc\nc routine idd_houseapp applies a Householder matrix to a vector.\nc\nc\nccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc\nc\nc\nc\n subroutine idd_houseapp(n,vn,u,ifrescal,scal,v)\nc\nc applies the Householder matrix\nc identity_matrix - scal * vn * transpose(vn)\nc to the vector u, yielding the vector v;\nc\nc scal = 2/(1 + vn(2)^2 + ... + vn(n)^2)\nc when vn(2), ..., vn(n) don't all vanish;\nc\nc scal = 0\nc when vn(2), ..., vn(n) do all vanish\nc (including when n = 1).\nc\nc input:\nc n -- size of vn, u, and v, though the indexing on vn goes\nc from 2 to n\nc vn -- components 2 to n of the Householder vector vn;\nc vn(1) is assumed to be 1 \nc u -- vector to be transformed\nc ifrescal -- set to 1 to recompute scal from vn(2), ..., vn(n);\nc set to 0 to use scal as input\nc scal -- see the entry for ifrescal in the decription\nc of the input\nc\nc output:\nc scal -- see the entry for ifrescal in the decription\nc of the input\nc v -- result of applying the Householder matrix to u;\nc it's O.K. to have v be the same as u\nc in order to apply the matrix to the vector in place\nc\nc reference:\nc Golub and Van Loan, \"Matrix Computations,\" 3rd edition,\nc Johns Hopkins University Press, 1996, Chapter 5.\nc\n implicit none\n save\n integer n,k,ifrescal\n real*8 vn(2:*),scal,u(n),v(n),fact,sum\nc\nc\nc Get out of this routine if n = 1.\nc\n if(n .eq. 1) then\n v(1) = u(1)\n return\n endif\nc\nc\n if(ifrescal .eq. 1) then\nc\nc\nc Calculate (vn(2))^2 + ... + (vn(n))^2.\nc\n sum = 0\n do k = 2,n\n sum = sum+vn(k)**2\n enddo ! k\nc\nc\nc Calculate scal.\nc\n if(sum .eq. 0) scal = 0\n if(sum .ne. 0) scal = 2/(1+sum)\nc\nc\n endif\nc\nc\nc Calculate fact = scal * transpose(vn) * u.\nc\n fact = u(1)\nc\n do k = 2,n\n fact = fact+vn(k)*u(k)\n enddo ! k\nc\n fact = fact*scal\nc\nc\nc Subtract fact*vn from u, yielding v.\nc \n v(1) = u(1) - fact\nc\n do k = 2,n\n v(k) = u(k) - fact*vn(k)\n enddo ! k\nc\nc\n return\n end\nc\nc\nc\nc\n subroutine idd_house(n,x,rss,vn,scal)\nc\nc constructs the vector vn with vn(1) = 1\nc and the scalar scal such that\nc H := identity_matrix - scal * vn * transpose(vn) is orthogonal\nc and Hx = +/- e_1 * the root-sum-square of the entries of x\nc (H is the Householder matrix corresponding to x).\nc\nc input:\nc n -- size of x and vn, though the indexing on vn goes\nc from 2 to n\nc x -- vector to reflect into its first component\nc\nc output:\nc rss -- first entry of the vector resulting from the application\nc of the Householder matrix to x;\nc its absolute value is the root-sum-square\nc of the entries of x\nc vn -- entries 2 to n of the Householder vector vn;\nc vn(1) is assumed to be 1\nc scal -- scalar multiplying vn * transpose(vn);\nc\nc scal = 2/(1 + vn(2)^2 + ... + vn(n)^2)\nc when vn(2), ..., vn(n) don't all vanish;\nc\nc scal = 0\nc when vn(2), ..., vn(n) do all vanish\nc (including when n = 1)\nc\nc reference:\nc Golub and Van Loan, \"Matrix Computations,\" 3rd edition,\nc Johns Hopkins University Press, 1996, Chapter 5.\nc\n implicit none\n save\n integer n,k\n real*8 x(n),rss,sum,v1,scal,vn(2:*),x1\nc\nc\n x1 = x(1)\nc\nc\nc Get out of this routine if n = 1.\nc\n if(n .eq. 1) then\n rss = x1\n scal = 0\n return\n endif\nc\nc\nc Calculate (x(2))^2 + ... (x(n))^2\nc and the root-sum-square value of the entries in x.\nc\nc\n sum = 0\n do k = 2,n\n sum = sum+x(k)**2\n enddo ! k\nc\nc\nc Get out of this routine if sum = 0;\nc flag this case as such by setting v(2), ..., v(n) all to 0.\nc\n if(sum .eq. 0) then\nc\n rss = x1\n do k = 2,n\n vn(k) = 0\n enddo ! k\n scal = 0\nc\n return\nc\n endif\nc\nc\n rss = x1**2 + sum\n rss = sqrt(rss)\nc\nc\nc Determine the first component v1\nc of the unnormalized Householder vector\nc v = x - rss * (1 0 0 ... 0 0)^T.\nc\nc If x1 <= 0, then form x1-rss directly,\nc since that expression cannot involve any cancellation.\nc\n if(x1 .le. 0) v1 = x1-rss\nc\nc If x1 > 0, then use the fact that\nc x1-rss = -sum / (x1+rss),\nc in order to avoid potential cancellation.\nc\n if(x1 .gt. 0) v1 = -sum / (x1+rss)\nc\nc\nc Compute the vector vn and the scalar scal such that vn(1) = 1\nc in the Householder transformation\nc identity_matrix - scal * vn * transpose(vn).\nc\n do k = 2,n\n vn(k) = x(k)/v1\n enddo ! k\nc\nc scal = 2\nc / ( vn(1)^2 + vn(2)^2 + ... + vn(n)^2 )\nc\nc = 2\nc / ( 1 + vn(2)^2 + ... + vn(n)^2 )\nc\nc = 2*v(1)^2\nc / ( v(1)^2 + (v(1)*vn(2))^2 + ... + (v(1)*vn(n))^2 )\nc\nc = 2*v(1)^2\nc / ( v(1)^2 + (v(2)^2 + ... + v(n)^2) )\nc\n scal = 2*v1**2 / (v1**2+sum)\nc\nc\n return\n end\nc\nc\nc\nc\n subroutine idd_housemat(n,vn,scal,h)\nc\nc fills h with the Householder matrix\nc identity_matrix - scal * vn * transpose(vn).\nc\nc input:\nc n -- size of vn and h, though the indexing of vn goes\nc from 2 to n\nc vn -- entries 2 to n of the vector vn;\nc vn(1) is assumed to be 1\nc scal -- scalar multiplying vn * transpose(vn)\nc\nc output:\nc h -- identity_matrix - scal * vn * transpose(vn)\nc\n implicit none\n save\n integer n,j,k\n real*8 vn(2:*),h(n,n),scal,factor1,factor2\nc\nc\nc Fill h with the identity matrix.\nc\n do j = 1,n\n do k = 1,n\nc\n if(j .eq. k) h(k,j) = 1\n if(j .ne. k) h(k,j) = 0\nc\n enddo ! k\n enddo ! j\nc\nc\nc Subtract from h the matrix scal*vn*transpose(vn).\nc\n do j = 1,n\n do k = 1,n\nc\n if(j .eq. 1) factor1 = 1\n if(j .ne. 1) factor1 = vn(j)\nc\n if(k .eq. 1) factor2 = 1\n if(k .ne. 1) factor2 = vn(k)\nc\n h(k,j) = h(k,j) - scal*factor1*factor2\nc\n enddo ! k\n enddo ! j\nc\nc\n return\n end\n", "meta": {"hexsha": "d7b1d0f85a52642a57eaa31b353a7bd78d41c6a5", "size": 6887, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "scipy/linalg/src/id_dist/src/idd_house.f", "max_stars_repo_name": "Ennosigaeon/scipy", "max_stars_repo_head_hexsha": "2d872f7cf2098031b9be863ec25e366a550b229c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9095, "max_stars_repo_stars_event_min_datetime": "2015-01-02T18:24:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T20:35:31.000Z", "max_issues_repo_path": "scipy/linalg/src/id_dist/src/idd_house.f", "max_issues_repo_name": "Ennosigaeon/scipy", "max_issues_repo_head_hexsha": "2d872f7cf2098031b9be863ec25e366a550b229c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 11500, "max_issues_repo_issues_event_min_datetime": "2015-01-01T01:15:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:07:35.000Z", "max_forks_repo_path": "scipy/linalg/src/id_dist/src/idd_house.f", "max_forks_repo_name": "Ennosigaeon/scipy", "max_forks_repo_head_hexsha": "2d872f7cf2098031b9be863ec25e366a550b229c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5838, "max_forks_repo_forks_event_min_datetime": "2015-01-05T11:56:42.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T23:21:19.000Z", "avg_line_length": 23.830449827, "max_line_length": 71, "alphanum_fraction": 0.5144475098, "num_tokens": 2236, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569268, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.7592599582191163}} {"text": "subroutine cc_abscissas ( n, x )\n\n!*****************************************************************************80\n!\n!! CC_ABSCISSAS computes the Clenshaw Curtis abscissas.\n!\n! Discussion:\n!\n! The interval is [ -1, 1 ].\n!\n! The abscissas are the cosines of equally spaced angles between\n! 180 and 0 degrees, including the endpoints.\n!\n! X(I) = cos ( ( ORDER - I ) * PI / ( ORDER - 1 ) )\n!\n! except for the basic case ORDER = 1, when\n!\n! X(1) = 0.\n!\n! If the value of ORDER is increased in a sensible way, then\n! the new set of abscissas will include the old ones. One such\n! sequence would be ORDER(K) = 2*K+1 for K = 0, 1, 2, ...\n!\n! When doing interpolation with Lagrange polynomials, the Clenshaw Curtis\n! abscissas can be a better choice than regularly spaced abscissas.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 04 December 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Charles Clenshaw, Alan Curtis,\n! A Method for Numerical Integration on an Automatic Computer,\n! Numerische Mathematik,\n! Volume 2, Number 1, December 1960, pages 197-205.\n!\n! Philip Davis, Philip Rabinowitz,\n! Methods of Numerical Integration,\n! Second Edition,\n! Dover, 2007,\n! ISBN: 0486453391,\n! LC: QA299.3.D28.\n!\n! Joerg Waldvogel,\n! Fast Construction of the Fejer and Clenshaw-Curtis Quadrature Rules,\n! BIT Numerical Mathematics,\n! Volume 43, Number 1, 2003, pages 1-18.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the rule.\n!\n! Output, real ( kind = 8 ) X(N), the abscissas.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) i\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) theta(n)\n real ( kind = 8 ) x(n)\n\n if ( n < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CC_ABSCISSA - Fatal error!'\n write ( *, '(a)' ) ' N < 1.'\n stop\n end if\n\n if ( n == 1 ) then\n x(1) = 0.0D+00\n return\n end if\n\n do i = 1, n\n theta(i) = real ( n - i, kind = 8 ) * pi &\n / real ( n - 1, kind = 8 )\n end do\n\n x(1:n) = cos ( theta(1:n) )\n\n return\nend\nsubroutine cc_abscissas_ab ( a, b, n, x )\n\n!*****************************************************************************80\n!\n!! CC_ABSCISSAS_AB computes Clenshaw Curtis abscissas for the interval [A,B].\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 December 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the endpoints of the interval.\n!\n! Input, integer ( kind = 4 ) N, the order of the rule.\n!\n! Output, real ( kind = 8 ) X(N), the abscissas.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) i\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) theta(n)\n real ( kind = 8 ) x(n)\n\n if ( n < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CC_ABSCISSAS_AB - Fatal error!'\n write ( *, '(a)' ) ' N < 1.'\n stop\n end if\n\n if ( n == 1 ) then\n x(1) = 0.5D+00 * ( b + a )\n return\n end if\n\n do i = 1, n\n theta(i) = real ( n - i, kind = 8 ) * pi &\n / real ( n - 1, kind = 8 )\n end do\n\n x(1:n) = 0.5D+00 * ( ( b + a ) + ( b - a ) * cos ( theta(1:n) ) )\n\n return\nend\nsubroutine f1_abscissas ( n, x )\n\n!*****************************************************************************80\n!\n!! F1_ABSCISSAS computes Fejer type 1 abscissas.\n!\n! Discussion:\n!\n! The interval is [ -1, +1 ].\n!\n! The abscissas are the cosines of equally spaced angles, which\n! are the midpoints of N equal intervals between 0 and PI.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 December 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Philip Davis, Philip Rabinowitz,\n! Methods of Numerical Integration,\n! Second Edition,\n! Dover, 2007,\n! ISBN: 0486453391,\n! LC: QA299.3.D28.\n!\n! Walter Gautschi,\n! Numerical Quadrature in the Presence of a Singularity,\n! SIAM Journal on Numerical Analysis,\n! Volume 4, Number 3, 1967, pages 357-362.\n!\n! Joerg Waldvogel,\n! Fast Construction of the Fejer and Clenshaw-Curtis Quadrature Rules,\n! BIT Numerical Mathematics,\n! Volume 43, Number 1, 2003, pages 1-18.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the rule.\n!\n! Output, real ( kind = 8 ) X(N), the abscissas.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) i\n real ( kind = 8 ) :: pi = 3.141592653589793D+00\n real ( kind = 8 ) theta(n)\n real ( kind = 8 ) x(n)\n\n if ( n < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'F1_ABSCISSAS - Fatal error!'\n write ( *, '(a)' ) ' N < 1.'\n stop\n end if\n\n if ( n == 1 ) then\n x(1) = 0.0D+00\n return\n end if\n\n do i = 1, n\n theta(i) = real ( 2 * n - 2 * i + 1, kind = 8 ) * pi &\n / real ( 2 * n, kind = 8 )\n end do\n\n x(1:n) = cos ( theta(1:n) )\n\n return\nend\nsubroutine f1_abscissas_ab ( a, b, n, x )\n\n!*****************************************************************************80\n!\n!! F1_ABSCISSAS_AB computes Fejer type 1 abscissas for the interval [A,B].\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 December 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Philip Davis, Philip Rabinowitz,\n! Methods of Numerical Integration,\n! Second Edition,\n! Dover, 2007,\n! ISBN: 0486453391,\n! LC: QA299.3.D28.\n!\n! Walter Gautschi,\n! Numerical Quadrature in the Presence of a Singularity,\n! SIAM Journal on Numerical Analysis,\n! Volume 4, Number 3, 1967, pages 357-362.\n!\n! Joerg Waldvogel,\n! Fast Construction of the Fejer and Clenshaw-Curtis Quadrature Rules,\n! BIT Numerical Mathematics,\n! Volume 43, Number 1, 2003, pages 1-18.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the endpoints of the interval.\n!\n! Input, integer ( kind = 4 ) N, the order of the rule.\n!\n! Output, real ( kind = 8 ) X(N), the abscissas.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) i\n real ( kind = 8 ) :: pi = 3.141592653589793D+00\n real ( kind = 8 ) theta(n)\n real ( kind = 8 ) x(n)\n\n if ( n < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'F1_ABSCISSAS_AB - Fatal error!'\n write ( *, '(a)' ) ' N < 1.'\n stop\n end if\n\n if ( n == 1 ) then\n x(1) = 0.5D+00 * ( b + a )\n return\n end if\n\n do i = 1, n\n theta(i) = real ( 2 * n - 2 * i + 1, kind = 8 ) * pi &\n / real ( 2 * n, kind = 8 )\n end do\n\n x(1:n) = 0.5D+00 * ( ( b + a ) + ( b - a ) * cos ( theta(1:n) ) )\n\n return\nend\nsubroutine f2_abscissas ( n, x )\n\n!*****************************************************************************80\n!\n!! F2_ABSCISSAS computes Fejer Type 2 abscissas.\n!\n! Discussion:\n!\n! The interval is [-1,+1].\n!\n! The abscissas are the cosines of equally spaced angles.\n! The angles are computed as N+2 equally spaced values between 0 and PI,\n! but with the first and last angle omitted.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 December 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Philip Davis, Philip Rabinowitz,\n! Methods of Numerical Integration,\n! Second Edition,\n! Dover, 2007,\n! ISBN: 0486453391,\n! LC: QA299.3.D28.\n!\n! Walter Gautschi,\n! Numerical Quadrature in the Presence of a Singularity,\n! SIAM Journal on Numerical Analysis,\n! Volume 4, Number 3, 1967, pages 357-362.\n!\n! Joerg Waldvogel,\n! Fast Construction of the Fejer and Clenshaw-Curtis Quadrature Rules,\n! BIT Numerical Mathematics,\n! Volume 43, Number 1, 2003, pages 1-18.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the rule.\n!\n! Output, real ( kind = 8 ) X(N), the abscissas.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) i\n real ( kind = 8 ) :: pi = 3.141592653589793D+00\n real ( kind = 8 ) theta(n)\n real ( kind = 8 ) x(n)\n\n if ( n < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'F2_ABSCISSAS - Fatal error!'\n write ( *, '(a)' ) ' N < 1.'\n stop\n end if\n\n if ( n == 1 ) then\n x(1) = 0.0D+00\n return\n else if ( n == 2 ) then\n x(1) = -0.5D+00\n x(2) = 0.5D+00\n return\n end if\n\n do i = 1, n\n theta(i) = real ( n + 1 - i, kind = 8 ) * pi &\n / real ( n + 1, kind = 8 )\n end do\n\n x(1:n) = cos ( theta(1:n) )\n\n return\nend\nsubroutine f2_abscissas_ab ( a, b, n, x )\n\n!*****************************************************************************80\n!\n!! F2_ABSCISSAS_AB computes Fejer Type 2 abscissas for the interval [A,B].\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 December 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the endpoints of the interval.\n!\n! Input, integer ( kind = 4 ) N, the order of the rule.\n!\n! Output, real ( kind = 8 ) X(N), the abscissas.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) i\n real ( kind = 8 ) :: pi = 3.141592653589793D+00\n real ( kind = 8 ) theta(n)\n real ( kind = 8 ) x(n)\n\n if ( n < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'F2_ABSCISSAS_AB - Fatal error!'\n write ( *, '(a)' ) ' N < 1.'\n stop\n end if\n\n do i = 1, n\n theta(i) = real ( n + 1 - i, kind = 8 ) * pi &\n / real ( n + 1, kind = 8 )\n end do\n\n x(1:n) = 0.5D+00 * ( ( b + a ) + ( b - a ) * cos ( theta(1:n) ) )\n\n return\nend\nsubroutine interp_lagrange ( m, data_num, t_data, p_data, interp_num, &\n t_interp, p_interp )\n\n!*****************************************************************************80\n!\n!! INTERP_LAGRANGE: Lagrange polynomial interpolant to a curve in M dimensions.\n!\n! Discussion:\n!\n! From a space of M dimensions, we are given a sequence of\n! DATA_NUM points, which are presumed to be successive samples\n! from a curve of points P.\n!\n! We are also given a parameterization of this data, that is,\n! an associated sequence of DATA_NUM values of a variable T.\n!\n! Thus, we have a sequence of values P(T), where T is a scalar,\n! and each value of P is of dimension M.\n!\n! We are then given INTERP_NUM values of T, for which values P\n! are to be produced, by linear interpolation of the data we are given.\n!\n! The user may request extrapolation. This occurs whenever\n! a T_INTERP value is less than the minimum T_DATA or greater than the\n! maximum T_DATA. In that case, extrapolation is used.\n!\n! For each spatial component, a polynomial of degree\n! ( DATA_NUM - 1 ) is generated for the interpolation. In most cases,\n! such a polynomial interpolant begins to oscillate as DATA_NUM\n! increases, even if the original data seems well behaved. Typically,\n! values of DATA_NUM should be no greater than 10!\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 December 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, the spatial dimension.\n!\n! Input, integer ( kind = 4 ) DATA_NUM, the number of data points.\n!\n! Input, real ( kind = 8 ) T_DATA(DATA_NUM), the value of the\n! independent variable at the sample points.\n!\n! Input, real ( kind = 8 ) P_DATA(M,DATA_NUM), the value of the\n! dependent variables at the sample points.\n!\n! Input, integer ( kind = 4 ) INTERP_NUM, the number of points\n! at which interpolation is to be done.\n!\n! Input, real ( kind = 8 ) T_INTERP(INTERP_NUM), the value of the\n! independent variable at the interpolation points.\n!\n! Output, real ( kind = 8 ) P_INTERP(M,DATA_NUM), the interpolated\n! values of the dependent variables at the interpolation points.\n!\n implicit none\n\n integer ( kind = 4 ) data_num\n integer ( kind = 4 ) m\n integer ( kind = 4 ) interp_num\n\n real ( kind = 8 ) l_interp(data_num,interp_num)\n real ( kind = 8 ) p_data(m,data_num)\n real ( kind = 8 ) p_interp(m,interp_num)\n real ( kind = 8 ) t_data(data_num)\n real ( kind = 8 ) t_interp(interp_num)\n!\n! Evaluate the DATA_NUM Lagrange polynomials associated with T_DATA(1:DATA_NUM)\n! for the interpolation points T_INTERP(1:INTERP_NUM).\n!\n call lagrange_value ( data_num, t_data, interp_num, t_interp, l_interp )\n!\n! Multiply P_DATA(1:M,1:DATA_NUM) * L_INTERP(1:DATA_NUM,1:INTERP_NUM)\n! to get P_INTERP(1:M,1:INTERP_NUM).\n!\n p_interp(1:m,1:interp_num) = &\n matmul ( p_data(1:m,1:data_num), l_interp(1:data_num,1:interp_num) )\n\n return\nend\nsubroutine interp_linear ( m, data_num, t_data, p_data, interp_num, &\n t_interp, p_interp )\n\n!*****************************************************************************80\n!\n!! INTERP_LINEAR: piecewise linear interpolation to a curve in M dimensions.\n!\n! Discussion:\n!\n! From a space of M dimensions, we are given a sequence of\n! DATA_NUM points, which are presumed to be successive samples\n! from a curve of points P.\n!\n! We are also given a parameterization of this data, that is,\n! an associated sequence of DATA_NUM values of a variable T.\n! The values of T are assumed to be strictly increasing.\n!\n! Thus, we have a sequence of values P(T), where T is a scalar,\n! and each value of P is of dimension M.\n!\n! We are then given INTERP_NUM values of T, for which values P\n! are to be produced, by linear interpolation of the data we are given.\n!\n! Note that the user may request extrapolation. This occurs whenever\n! a T_INTERP value is less than the minimum T_DATA or greater than the\n! maximum T_DATA. In that case, linear extrapolation is used.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 December 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, the spatial dimension.\n!\n! Input, integer ( kind = 4 ) DATA_NUM, the number of data points.\n!\n! Input, real ( kind = 8 ) T_DATA(DATA_NUM), the value of the\n! independent variable at the sample points. The values of T_DATA\n! must be strictly increasing.\n!\n! Input, real ( kind = 8 ) P_DATA(M,DATA_NUM), the value of the\n! dependent variables at the sample points.\n!\n! Input, integer ( kind = 4 ) INTERP_NUM, the number of points\n! at which interpolation is to be done.\n!\n! Input, real ( kind = 8 ) T_INTERP(INTERP_NUM), the value of the\n! independent variable at the interpolation points.\n!\n! Output, real ( kind = 8 ) P_INTERP(M,DATA_NUM), the interpolated\n! values of the dependent variables at the interpolation points.\n!\n implicit none\n\n integer ( kind = 4 ) data_num\n integer ( kind = 4 ) m\n integer ( kind = 4 ) interp_num\n\n integer ( kind = 4 ) interp\n integer ( kind = 4 ) left\n real ( kind = 8 ) p_data(m,data_num)\n real ( kind = 8 ) p_interp(m,interp_num)\n logical r8vec_ascends_strictly\n integer ( kind = 4 ) right\n real ( kind = 8 ) t\n real ( kind = 8 ) t_data(data_num)\n real ( kind = 8 ) t_interp(interp_num)\n\n if ( .not. r8vec_ascends_strictly ( data_num, t_data ) ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'INTERP_LINEAR - Fatal error!'\n write ( *, '(a)' ) &\n ' Independent variable array T_DATA is not strictly increasing.'\n stop\n end if\n\n do interp = 1, interp_num\n\n t = t_interp(interp)\n!\n! Find the interval [ TDATA(LEFT), TDATA(RIGHT) ] that contains, or is\n! nearest to, TVAL.\n!\n call r8vec_bracket ( data_num, t_data, t, left, right )\n\n p_interp(1:m,interp) = &\n ( ( t_data(right) - t ) * p_data(1:m,left) &\n + ( t - t_data(left) ) * p_data(1:m,right) ) &\n / ( t_data(right) - t_data(left) )\n\n end do\n\n return\nend\nsubroutine interp_nearest ( m, data_num, t_data, p_data, interp_num, &\n t_interp, p_interp )\n\n!*****************************************************************************80\n!\n!! INTERP_NEAREST: Nearest neighbor interpolation to a curve in M dimensions.\n!\n! Discussion:\n!\n! From a space of M dimensions, we are given a sequence of\n! DATA_NUM points, which are presumed to be successive samples\n! from a curve of points P.\n!\n! We are also given a parameterization of this data, that is,\n! an associated sequence of DATA_NUM values of a variable T.\n!\n! Thus, we have a sequence of values P(T), where T is a scalar,\n! and each value of P is of dimension M.\n!\n! We are then given INTERP_NUM values of T, for which values P\n! are to be produced, by nearest neighbor interpolation.\n!\n! The user may request extrapolation. This occurs whenever\n! a T_INTERP value is less than the minimum T_DATA or greater than the\n! maximum T_DATA. In that case, extrapolation is used.\n!\n! The resulting interpolant is piecewise constant.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 July 2012\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, the spatial dimension.\n!\n! Input, integer ( kind = 4 ) DATA_NUM, the number of data points.\n!\n! Input, real ( kind = 8 ) T_DATA(DATA_NUM), the value of the\n! independent variable at the sample points.\n!\n! Input, real ( kind = 8 ) P_DATA(M,DATA_NUM), the value of the\n! dependent variables at the sample points.\n!\n! Input, integer ( kind = 4 ) INTERP_NUM, the number of points\n! at which interpolation is to be done.\n!\n! Input, real ( kind = 8 ) T_INTERP(INTERP_NUM), the value of the\n! independent variable at the interpolation points.\n!\n! Output, real ( kind = 8 ) P_INTERP(M,DATA_NUM), the interpolated\n! values of the dependent variables at the interpolation points.\n!\n implicit none\n\n integer ( kind = 4 ) data_num\n integer ( kind = 4 ) m\n integer ( kind = 4 ) interp_num\n\n integer ( kind = 4 ) jd\n integer ( kind = 4 ) ji\n real ( kind = 8 ) p_data(m,data_num)\n real ( kind = 8 ) p_interp(m,interp_num)\n integer ( kind = 4 ) r8vec_sorted_nearest\n real ( kind = 8 ) t_data(data_num)\n real ( kind = 8 ) t_interp(interp_num)\n!\n! For each interpolation point, find the index of the nearest data point.\n!\n do ji = 1, interp_num\n jd = r8vec_sorted_nearest ( data_num, t_data, t_interp(ji) )\n p_interp(1:m,ji) = p_data(1:m,jd)\n end do\n\n return\nend\nsubroutine lagrange_value ( data_num, t_data, interp_num, t_interp, l_interp )\n\n!*****************************************************************************80\n!\n!! LAGRANGE_VALUE evaluates the Lagrange polynomials.\n!\n! Discussion:\n!\n! Given DATA_NUM distinct abscissas, T_DATA(1:DATA_NUM),\n! the I-th Lagrange polynomial L(I)(T) is defined as the polynomial of\n! degree DATA_NUM - 1 which is 1 at T_DATA(I) and 0 at the DATA_NUM - 1\n! other abscissas.\n!\n! A formal representation is:\n!\n! L(I)(T) = Product ( 1 <= J <= DATA_NUM, I /= J )\n! ( T - T(J) ) / ( T(I) - T(J) )\n!\n! This routine accepts a set of INTERP_NUM values at which all the Lagrange\n! polynomials should be evaluated.\n!\n! Given data values P_DATA at each of the abscissas, the value of the\n! Lagrange interpolating polynomial at each of the interpolation points\n! is then simple to compute by matrix multiplication:\n!\n! P_INTERP(1:INTERP_NUM) =\n! P_DATA(1:DATA_NUM) * L_INTERP(1:DATA_NUM,1:INTERP_NUM)\n!\n! or, in the case where P is multidimensional:\n!\n! P_INTERP(1:M,1:INTERP_NUM) =\n! P_DATA(1:M,1:DATA_NUM) * L_INTERP(1:DATA_NUM,1:INTERP_NUM)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 December 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) DATA_NUM, the number of data points.\n! DATA_NUM must be at least 1.\n!\n! Input, real ( kind = 8 ) T_DATA(DATA_NUM), the data points.\n!\n! Input, integer ( kind = 4 ) INTERP_NUM, the number of\n! interpolation points.\n!\n! Input, real ( kind = 8 ) T_INTERP(INTERP_NUM), the\n! interpolation points.\n!\n! Output, real ( kind = 8 ) L_INTERP(DATA_NUM,INTERP_NUM), the values\n! of the Lagrange polynomials at the interpolation points.\n!\n implicit none\n\n integer ( kind = 4 ) data_num\n integer ( kind = 4 ) interp_num\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n real ( kind = 8 ) l_interp(data_num,interp_num)\n real ( kind = 8 ) t_data(data_num)\n real ( kind = 8 ) t_interp(interp_num)\n!\n! Evaluate the polynomial.\n!\n l_interp(1:data_num,1:interp_num) = 1.0D+00\n\n do i = 1, data_num\n\n do j = 1, data_num\n\n if ( j /= i ) then\n\n l_interp(i,1:interp_num) = l_interp(i,1:interp_num) &\n * ( t_interp(1:interp_num) - t_data(j) ) / ( t_data(i) - t_data(j) )\n\n end if\n\n end do\n\n end do\n\n return\nend\nsubroutine ncc_abscissas ( n, x )\n\n!*****************************************************************************80\n!\n!! NCC_ABSCISSAS computes the Newton Cotes Closed abscissas.\n!\n! Discussion:\n!\n! The interval is [ -1, 1 ].\n!\n! The abscissas are the equally spaced points between -1 and 1,\n! including the endpoints.\n!\n! If N is 1, however, the single abscissas is X = 0.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 December 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the rule.\n!\n! Output, real ( kind = 8 ) X(N), the abscissas.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) i\n real ( kind = 8 ) x(n)\n\n if ( n < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'NCC_ABSCISSAS - Fatal error!'\n write ( *, '(a)' ) ' N < 1.'\n stop\n end if\n\n if ( n == 1 ) then\n x(1) = 0.0D+00\n return\n end if\n\n do i = 1, n\n x(i) = ( real ( n - i, kind = 8 ) * ( -1.0D+00 ) &\n + real ( i - 1, kind = 8 ) * ( +1.0D+00 ) ) &\n / real ( n - 1, kind = 8 )\n end do\n\n return\nend\nsubroutine ncc_abscissas_ab ( a, b, n, x )\n\n!*****************************************************************************80\n!\n!! NCC_ABSCISSAS_AB computes the Newton Cotes Closed abscissas for [A,B].\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 December 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the endpoints of the interval.\n!\n! Input, integer ( kind = 4 ) N, the order of the rule.\n!\n! Output, real ( kind = 8 ) X(N), the abscissas.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) i\n real ( kind = 8 ) x(n)\n\n if ( n < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'NCC_ABSCISSAS_AB - Fatal error!'\n write ( *, '(a)' ) ' N < 1.'\n stop\n end if\n\n if ( n == 1 ) then\n x(1) = 0.5D+00 * ( b + a )\n return\n end if\n\n do i = 1, n\n x(i) = ( real ( n - i, kind = 8 ) * a &\n + real ( i - 1, kind = 8 ) * b ) &\n / real ( n - 1, kind = 8 )\n end do\n\n return\nend\nsubroutine nco_abscissas ( n, x )\n\n!*****************************************************************************80\n!\n!! NCO_ABSCISSAS computes the Newton Cotes Open abscissas.\n!\n! Discussion:\n!\n! The interval is [ -1, 1 ].\n!\n! The abscissas are the equally spaced points between -1 and 1,\n! not including the endpoints.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 December 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the rule.\n!\n! Output, real ( kind = 8 ) X(N), the abscissas.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) i\n real ( kind = 8 ) x(n)\n\n if ( n < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'NCO_ABSCISSAS - Fatal error!'\n write ( *, '(a)' ) ' N < 1.'\n stop\n end if\n\n do i = 1, n\n x(i) = ( real ( n - i + 1, kind = 8 ) * ( -1.0D+00 ) &\n + real ( i, kind = 8 ) * ( +1.0D+00 ) ) &\n / real ( n + 1, kind = 8 )\n end do\n\n return\nend\nsubroutine nco_abscissas_ab ( a, b, n, x )\n\n!*****************************************************************************80\n!\n!! NCO_ABSCISSAS_AB computes the Newton Cotes Open abscissas for [A,B].\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 December 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the endpoints of the interval.\n!\n! Input, integer ( kind = 4 ) N, the order of the rule.\n!\n! Output, real ( kind = 8 ) X(N), the abscissas.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) i\n real ( kind = 8 ) x(n)\n\n if ( n < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'NCO_ABSCISSAS_AB - Fatal error!'\n write ( *, '(a)' ) ' N < 1.'\n stop\n end if\n\n do i = 1, n\n x(i) = ( real ( n - i + 1, kind = 8 ) * a &\n + real ( i, kind = 8 ) * b ) &\n / real ( n + 1, kind = 8 )\n end do\n\n return\nend\nsubroutine parameterize_arc_length ( m, data_num, p_data, t_data )\n\n!*****************************************************************************80\n!\n!! PARAMETERIZE_ARC_LENGTH parameterizes data by pseudo-arclength.\n!\n! Discussion:\n!\n! A parameterization is required for the interpolation.\n!\n! This routine provides a parameterization by computing the\n! pseudo-arclength of the data, that is, the Euclidean distance\n! between successive points.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 19 May 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, the spatial dimension.\n!\n! Input, integer ( kind = 4 ) DATA_NUM, the number of data points.\n!\n! Input, real ( kind = 8 ) P_DATA(M,DATA_NUM), the data values.\n!\n! Output, real ( kind = 8 ) T_DATA(DATA_NUM), parameter values\n! assigned to the data.\n!\n implicit none\n\n integer ( kind = 4 ) data_num\n integer ( kind = 4 ) m\n\n integer ( kind = 4 ) j\n real ( kind = 8 ) p_data(m,data_num)\n real ( kind = 8 ) t_data(data_num)\n\n t_data(1) = 0.0D+00\n do j = 2, data_num\n t_data(j) = t_data(j-1) &\n + sqrt ( sum ( ( p_data(1:m,j) - p_data(1:m,j-1) )**2 ) )\n end do\n\n return\nend\nsubroutine parameterize_index ( m, data_num, p_data, t_data )\n\n!*****************************************************************************80\n!\n!! PARAMETERIZE_INDEX parameterizes data by its index.\n!\n! Discussion:\n!\n! A parameterization is required for the interpolation.\n!\n! This routine provides a naive parameterization by vector index.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 19 May 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, the spatial dimension.\n!\n! Input, integer ( kind = 4 ) DATA_NUM, the number of data points.\n!\n! Input, real ( kind = 8 ) P_DATA(M,DATA_NUM), the data values.\n!\n! Output, real ( kind = 8 ) T_DATA(DATA_NUM), parameter values\n! assigned to the data.\n!\n implicit none\n\n integer ( kind = 4 ) data_num\n integer ( kind = 4 ) m\n\n integer ( kind = 4 ) j\n real ( kind = 8 ) p_data(m,data_num)\n real ( kind = 8 ) t_data(data_num)\n\n t_data(1) = 0.0D+00\n do j = 2, data_num\n t_data(j) = real ( j - 1, kind = 8 )\n end do\n\n return\nend\nsubroutine r8mat_expand_linear2 ( m, n, a, m2, n2, a2 )\n\n!*****************************************************************************80\n!\n!! R8MAT_EXPAND_LINEAR2 expands an R8MAT by linear interpolation.\n!\n! Discussion:\n!\n! An R8MAT is an array of R8 values.\n!\n! In this version of the routine, the expansion is indicated\n! by specifying the dimensions of the expanded array.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 07 December 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the number of rows and columns in A.\n!\n! Input, real ( kind = 8 ) A(M,N), a \"small\" M by N array.\n!\n! Input, integer ( kind = 4 ) M2, N2, the number of rows and columns in A2.\n!\n! Output, real ( kind = 8 ) A2(M2,N2), the expanded array, which\n! contains an interpolated version of the data in A.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) m2\n integer ( kind = 4 ) n\n integer ( kind = 4 ) n2\n\n real ( kind = 8 ) a(m,n)\n real ( kind = 8 ) a2(m2,n2)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i1\n integer ( kind = 4 ) i2\n integer ( kind = 4 ) j\n integer ( kind = 4 ) j1\n integer ( kind = 4 ) j2\n real ( kind = 8 ) r\n real ( kind = 8 ) r1\n real ( kind = 8 ) r2\n real ( kind = 8 ) s\n real ( kind = 8 ) s1\n real ( kind = 8 ) s2\n\n do i = 1, m2\n\n if ( m2 == 1 ) then\n r = 0.5D+00\n else\n r = real ( i - 1, kind = 8 ) &\n / real ( m2 - 1, kind = 8 )\n end if\n\n i1 = 1 + int ( r * real ( m - 1, kind = 8 ) )\n i2 = i1 + 1\n\n if ( m < i2 ) then\n i1 = m - 1\n i2 = m\n end if\n\n r1 = real ( i1 - 1, kind = 8 ) &\n / real ( m - 1, kind = 8 )\n\n r2 = real ( i2 - 1, kind = 8 ) &\n / real ( m - 1, kind = 8 )\n\n do j = 1, n2\n\n if ( n2 == 1 ) then\n s = 0.5D+00\n else\n s = real ( j - 1, kind = 8 ) &\n / real ( n2 - 1, kind = 8 )\n end if\n\n j1 = 1 + int ( s * real ( n - 1, kind = 8 ) )\n j2 = j1 + 1\n\n if ( n < j2 ) then\n j1 = n - 1\n j2 = n\n end if\n\n s1 = real ( j1 - 1, kind = 8 ) &\n / real ( n - 1, kind = 8 )\n\n s2 = real ( j2 - 1, kind = 8 ) &\n / real ( n - 1, kind = 8 )\n\n a2(i,j) = &\n ( ( r2 - r ) * ( s2 - s ) * a(i1,j1) &\n + ( r - r1 ) * ( s2 - s ) * a(i2,j1) &\n + ( r2 - r ) * ( s - s1 ) * a(i1,j2) &\n + ( r - r1 ) * ( s - s1 ) * a(i2,j2) ) &\n / ( ( r2 - r1 ) * ( s2 - s1 ) )\n\n end do\n\n end do\n\n return\nend\nfunction r8vec_ascends_strictly ( n, x )\n\n!*****************************************************************************80\n!\n!! R8VEC_ASCENDS_STRICTLY determines if an R8VEC is strictly ascending.\n!\n! Discussion:\n!\n! An R8VEC is a vector of R8 values.\n!\n! Notice the effect of entry number 6 in the following results:\n!\n! X = ( -8.1, 1.3, 2.2, 3.4, 7.5, 7.4, 9.8 )\n! Y = ( -8.1, 1.3, 2.2, 3.4, 7.5, 7.5, 9.8 )\n! Z = ( -8.1, 1.3, 2.2, 3.4, 7.5, 7.6, 9.8 )\n!\n! R8VEC_ASCENDS_STRICTLY ( X ) = FALSE\n! R8VEC_ASCENDS_STRICTLY ( Y ) = FALSE\n! R8VEC_ASCENDS_STRICTLY ( Z ) = TRUE\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 December 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the size of the array.\n!\n! Input, real ( kind = 8 ) X(N), the array to be examined.\n!\n! Output, logical R8VEC_ASCENDS_STRICTLY, is TRUE if the\n! entries of X strictly ascend.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) i\n logical r8vec_ascends_strictly\n real ( kind = 8 ) x(n)\n\n do i = 1, n - 1\n if ( x(i+1) <= x(i) ) then\n r8vec_ascends_strictly = .false.\n return\n end if\n end do\n\n r8vec_ascends_strictly = .true.\n\n return\nend\nsubroutine r8vec_bracket ( n, x, xval, left, right )\n\n!*****************************************************************************80\n!\n!! R8VEC_BRACKET searches a sorted R8VEC for successive brackets of a value.\n!\n! Discussion:\n!\n! An R8VEC is an array of double precision real values.\n!\n! If the values in the vector are thought of as defining intervals\n! on the real line, then this routine searches for the interval\n! nearest to or containing the given value.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, length of input array.\n!\n! Input, real ( kind = 8 ) X(N), an array sorted into ascending order.\n!\n! Input, real ( kind = 8 ) XVAL, a value to be bracketed.\n!\n! Output, integer ( kind = 4 ) LEFT, RIGHT, the results of the search.\n! Either:\n! XVAL < X(1), when LEFT = 1, RIGHT = 2;\n! X(N) < XVAL, when LEFT = N-1, RIGHT = N;\n! or\n! X(LEFT) <= XVAL <= X(RIGHT).\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) left\n integer ( kind = 4 ) right\n real ( kind = 8 ) x(n)\n real ( kind = 8 ) xval\n\n do i = 2, n - 1\n\n if ( xval < x(i) ) then\n left = i - 1\n right = i\n return\n end if\n\n end do\n\n left = n - 1\n right = n\n\n return\nend\nsubroutine r8vec_expand_linear ( n, x, fat, xfat )\n\n!*****************************************************************************80\n!\n!! R8VEC_EXPAND_LINEAR linearly interpolates new data into an R8VEC.\n!\n! Discussion:\n!\n! This routine copies the old data, and inserts NFAT new values\n! between each pair of old data values. This would be one way to\n! determine places to evenly sample a curve, given the (unevenly\n! spaced) points at which it was interpolated.\n!\n! An R8VEC is an array of double precision real values.\n!\n! Example:\n!\n! N = 3\n! NFAT = 2\n!\n! X(1:N) = (/ 0.0, 6.0, 7.0 /)\n! XFAT(1:2*3+1) = (/ 0.0, 2.0, 4.0, 6.0, 6.33, 6.66, 7.0 /)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 October 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of input data values.\n!\n! Input, real ( kind = 8 ) X(N), the original data.\n!\n! Input, integer ( kind = 4 ) FAT, the number of data values to interpolate\n! between each pair of original data values.\n!\n! Output, real ( kind = 8 ) XFAT((N-1)*(FAT+1)+1), the \"fattened\" data.\n!\n implicit none\n\n integer ( kind = 4 ) fat\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n integer ( kind = 4 ) k\n real ( kind = 8 ) x(n)\n real ( kind = 8 ) xfat((n-1)*(fat+1)+1)\n\n k = 0\n\n do i = 1, n - 1\n\n k = k + 1\n xfat(k) = x(i)\n\n do j = 1, fat\n k = k + 1\n xfat(k) = ( real ( fat - j + 1, kind = 8 ) * x(i) &\n + real ( j, kind = 8 ) * x(i+1) ) &\n / real ( fat + 1, kind = 8 )\n end do\n\n end do\n\n k = k + 1\n xfat(k) = x(n)\n\n return\nend\nsubroutine r8vec_expand_linear2 ( n, x, before, fat, after, xfat )\n\n!*****************************************************************************80\n!\n!! R8VEC_EXPAND_LINEAR2 linearly interpolates new data into an R8VEC.\n!\n! Discussion:\n!\n! This routine starts with a vector of data.\n!\n! The intent is to \"fatten\" the data, that is, to insert more points\n! between successive values of the original data.\n!\n! There will also be extra points placed BEFORE the first original\n! value and AFTER that last original value.\n!\n! The \"fattened\" data is equally spaced between the original points.\n!\n! The BEFORE data uses the spacing of the first original interval,\n! and the AFTER data uses the spacing of the last original interval.\n!\n! Example:\n!\n! N = 3\n! BEFORE = 3\n! FAT = 2\n! AFTER = 1\n!\n! X = (/ 0.0, 6.0, 7.0 /)\n! XFAT = (/ -6.0, -4.0, -2.0, 0.0, 2.0, 4.0, 6.0, 6.33, 6.66, 7.0, 7.66 /)\n! 3 \"BEFORE's\" Old 2 \"FATS\" Old 2 \"FATS\" Old 1 \"AFTER\"\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 December 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of input data values.\n! N must be at least 2.\n!\n! Input, real ( kind = 8 ) X(N), the original data.\n!\n! Input, integer ( kind = 4 ) BEFORE, the number of \"before\" values.\n!\n! Input, integer ( kind = 4 ) FAT, the number of data values to interpolate\n! between each pair of original data values.\n!\n! Input, integer ( kind = 4 ) AFTER, the number of \"after\" values.\n!\n! Output, real ( kind = 8 ) XFAT(BEFORE+(N-1)*(FAT+1)+1+AFTER), the\n! \"fattened\" data.\n!\n implicit none\n\n integer ( kind = 4 ) after\n integer ( kind = 4 ) before\n integer ( kind = 4 ) fat\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n integer ( kind = 4 ) k\n real ( kind = 8 ) x(n)\n real ( kind = 8 ) xfat(before+(n-1)*(fat+1)+1+after)\n\n k = 0\n!\n! Points BEFORE.\n!\n do j = 1 - before + fat, fat\n k = k + 1\n xfat(k) = ( real ( fat - j + 1, kind = 8 ) * ( x(1) - ( x(2) - x(1) ) ) &\n + real ( j, kind = 8 ) * x(1) ) &\n / real ( fat + 1, kind = 8 )\n end do\n!\n! Original points and FAT points.\n!\n do i = 1, n - 1\n\n k = k + 1\n xfat(k) = x(i)\n\n do j = 1, fat\n k = k + 1\n xfat(k) = ( real ( fat - j + 1, kind = 8 ) * x(i) &\n + real ( j, kind = 8 ) * x(i+1) ) &\n / real ( fat + 1, kind = 8 )\n end do\n\n end do\n\n k = k + 1\n xfat(k) = x(n)\n!\n! Points AFTER.\n!\n do j = 1, after\n k = k + 1\n xfat(k) = &\n ( real ( fat - j + 1, kind = 8 ) * x(n) &\n + real ( j, kind = 8 ) * ( x(n) + ( x(n) - x(n-1) ) ) ) &\n / real ( fat + 1, kind = 8 )\n end do\n\n return\nend\nfunction r8vec_sorted_nearest ( n, a, value )\n\n!*****************************************************************************80\n!\n!! R8VEC_SORTED_NEAREST returns the nearest element in a sorted R8VEC.\n!\n! Discussion:\n!\n! An R8VEC is a vector of R8's.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 April 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of elements of A.\n!\n! Input, real ( kind = 8 ) A(N), a sorted vector.\n!\n! Input, real ( kind = 8 ) VALUE, the value whose nearest vector\n! entry is sought.\n!\n! Output, integer ( kind = 4 ) R8VEC_SORTED_NEAREST, the index of the nearest\n! entry in the vector.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n integer ( kind = 4 ) r8vec_sorted_nearest\n integer ( kind = 4 ) hi\n integer ( kind = 4 ) lo\n integer ( kind = 4 ) mid\n real ( kind = 8 ) value\n\n if ( n < 1 ) then\n r8vec_sorted_nearest = -1\n return\n end if\n\n if ( n == 1 ) then\n r8vec_sorted_nearest = 1\n return\n end if\n\n if ( a(1) < a(n) ) then\n\n if ( value < a(1) ) then\n r8vec_sorted_nearest = 1\n return\n else if ( a(n) < value ) then\n r8vec_sorted_nearest = n\n return\n end if\n!\n! Seek an interval containing the value.\n!\n lo = 1\n hi = n\n\n do while ( lo < hi - 1 )\n\n mid = ( lo + hi ) / 2\n\n if ( value == a(mid) ) then\n r8vec_sorted_nearest = mid\n return\n else if ( value < a(mid) ) then\n hi = mid\n else\n lo = mid\n end if\n\n end do\n!\n! Take the nearest.\n!\n if ( abs ( value - a(lo) ) < abs ( value - a(hi) ) ) then\n r8vec_sorted_nearest = lo\n else\n r8vec_sorted_nearest = hi\n end if\n\n return\n!\n! A descending sorted vector A.\n!\n else\n\n if ( value < a(n) ) then\n r8vec_sorted_nearest = n\n return\n else if ( a(1) < value ) then\n r8vec_sorted_nearest = 1\n return\n end if\n!\n! Seek an interval containing the value.\n!\n lo = n\n hi = 1\n\n do while ( lo < hi - 1 )\n\n mid = ( lo + hi ) / 2\n\n if ( value == a(mid) ) then\n r8vec_sorted_nearest = mid\n return\n else if ( value < a(mid) ) then\n hi = mid\n else\n lo = mid\n end if\n\n end do\n!\n! Take the nearest.\n!\n if ( abs ( value - a(lo) ) < abs ( value - a(hi) ) ) then\n r8vec_sorted_nearest = lo\n else\n r8vec_sorted_nearest = hi\n end if\n\n return\n\n end if\n\n return\nend\nsubroutine timestamp ( )\n\n!*****************************************************************************80\n!\n!! TIMESTAMP prints the current YMDHMS date as a time stamp.\n!\n! Example:\n!\n! 31 May 2001 9:45:54.872 AM\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 May 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! None\n!\n implicit none\n\n character ( len = 8 ) ampm\n integer ( kind = 4 ) d\n integer ( kind = 4 ) h\n integer ( kind = 4 ) m\n integer ( kind = 4 ) mm\n character ( len = 9 ), parameter, dimension(12) :: month = (/ &\n 'January ', 'February ', 'March ', 'April ', &\n 'May ', 'June ', 'July ', 'August ', &\n 'September', 'October ', 'November ', 'December ' /)\n integer ( kind = 4 ) n\n integer ( kind = 4 ) s\n integer ( kind = 4 ) values(8)\n integer ( kind = 4 ) y\n\n call date_and_time ( values = values )\n\n y = values(1)\n m = values(2)\n d = values(3)\n h = values(5)\n n = values(6)\n s = values(7)\n mm = values(8)\n\n if ( h < 12 ) then\n ampm = 'AM'\n else if ( h == 12 ) then\n if ( n == 0 .and. s == 0 ) then\n ampm = 'Noon'\n else\n ampm = 'PM'\n end if\n else\n h = h - 12\n if ( h < 12 ) then\n ampm = 'PM'\n else if ( h == 12 ) then\n if ( n == 0 .and. s == 0 ) then\n ampm = 'Midnight'\n else\n ampm = 'AM'\n end if\n end if\n end if\n\n write ( *, '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) &\n d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm )\n\n return\nend\n\n", "meta": {"hexsha": "55aff6a97ffa538633b6670ee69b474cffa47624", "size": 41778, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "interp/interp.f90", "max_stars_repo_name": "wesleybowman/fortran", "max_stars_repo_head_hexsha": "a704a79aa5ba7c20967db71552873adcdadb241f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-10T14:02:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-10T14:02:03.000Z", "max_issues_repo_path": "interp/interp.f90", "max_issues_repo_name": "wesleybowman/fortran", "max_issues_repo_head_hexsha": "a704a79aa5ba7c20967db71552873adcdadb241f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "interp/interp.f90", "max_forks_repo_name": "wesleybowman/fortran", "max_forks_repo_head_hexsha": "a704a79aa5ba7c20967db71552873adcdadb241f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.2487479132, "max_line_length": 80, "alphanum_fraction": 0.5549810905, "num_tokens": 13762, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8774767746654974, "lm_q1q2_score": 0.7592140434415896}} {"text": "INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(15)\nINTEGER :: i=1, limit=100\nREAL(dp) :: d, e, f, x, x1, x2\n\nf(x) = x*x*x - 3.0_dp*x*x + 2.0_dp*x\n\nx1 = -1.0_dp ; x2 = 3.0_dp ; e = 1.0e-15_dp\n\nDO\n IF (i > limit) THEN\n WRITE(*,*) \"Function not converging\"\n EXIT\n END IF\n d = (x2 - x1) / (f(x2) - f(x1)) * f(x2)\n IF (ABS(d) < e) THEN\n WRITE(*,\"(A,F18.15)\") \"Root found at x = \", x2\n EXIT\n END IF\n x1 = x2\n x2 = x2 - d\n i = i + 1\nEND DO\n", "meta": {"hexsha": "31131675c5a0823686f920b74a9aefa81d8def93", "size": 452, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Roots-of-a-function/Fortran/roots-of-a-function-2.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Roots-of-a-function/Fortran/roots-of-a-function-2.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Roots-of-a-function/Fortran/roots-of-a-function-2.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 19.652173913, "max_line_length": 50, "alphanum_fraction": 0.5199115044, "num_tokens": 215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422241476943, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7591891424983994}} {"text": "subroutine convergencet(t, atw, ate, ats, atn, atp, bt, itmax, jtmax, residualt)\n!use variables\nuse kind_parameters\nimplicit none\n\ninteger, intent(in):: itmax, jtmax\nreal(kind=dp), dimension(itmax,jtmax):: t, atw, ate, ats, atn, atp, bt\nreal(kind=dp):: temp1, temp2, sum_nom, sum_den\ninteger:: it, jt\nreal(kind=dp), intent(out):: residualt\n\nsum_nom = 0.0d0\nsum_den = 0.0d0\n\ndo jt=2,jtmax-1\n\n do it=2,itmax-1\n\n temp1 = atp(it,jt)*t(it,jt)\n temp2 = atw(it,jt)*t(it-1,jt) + ate(it,jt)*t(it+1,jt) + ats(it,jt)*t(it,jt-1) + atn(it,jt)*t(it,jt+1)\n sum_nom = sum_nom + dabs(temp1 - temp2 - bt(it,jt))\n sum_den = sum_den + dabs(temp1)\n\n end do\n\nend do\n\t\nresidualt = sum_nom/sum_den\n\nend subroutine\n", "meta": {"hexsha": "e5eff1d4da53a0f523edc9e725c6a58cd64f0e21", "size": 754, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "convergencet.f90", "max_stars_repo_name": "pratanuroy/Multigrid_Cavity", "max_stars_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-11T12:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-11T12:01:52.000Z", "max_issues_repo_path": "convergencet.f90", "max_issues_repo_name": "pratanuroy/Multigrid_Cavity", "max_issues_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "convergencet.f90", "max_forks_repo_name": "pratanuroy/Multigrid_Cavity", "max_forks_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.3225806452, "max_line_length": 115, "alphanum_fraction": 0.6193633952, "num_tokens": 284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7591353024682199}} {"text": "subroutine wind(Nm,Nx,Ny,windy)\n\nimplicit none\ninteger, intent(in) :: Nx,Ny,Nm\nreal(8), dimension(Nm,Nx,Ny), intent(out) :: windy\n\ninteger :: i,j,m\nreal(8) :: pi = 3.14159265358979d0\nreal(8), dimension(Nx,Ny) :: tau\n\ntau(:,:) = 0.d0\nwindy(:,:,:) = 0.d0\n\ndo i=1,Nx\n do j=1,Ny\n\n tau(i,j) = cos(2.*pi*((j-1.)/(Ny-1.)-0.5))+2.*sin(pi*((j-1.)/(Ny-1.)-0.5))\n! tau(i,j) = -1./(2.*pi)*cos(2.*pi*(j-1.)/(Ny-1.))\n! tau(i,j) = -cos(pi*(j-1.)/(Ny-1.))\n! tau(i,j) = -cos(pi*(j-1.5)/(ny-2.)) ! what they had in the code\n! tau(i,j) = -1./pi*cos(pi*(j-1.)/(Ny-1.)) ! what I used\n! tau(i,j) = -1./pi*cos(pi*(j-1.)/(ny-1.))*sin(pi*(i-1.)/(ny-1.)) ! Veronis (1966) ????\n\n end do\nend do\n\ndo m=1,Nm\n do i=2,Nx-1\n do j=2,Ny-1\n\n windy(m,i,j) = -tau(i,j+1)+tau(i,j-1) ! include the whole curl, i.e., also x-derivative for generality ?????\n\n end do\n end do\nend do\n\n! write(*,*) tau\n! write(*,*) windy\n\nend\n\n\n! real(8), allocatable, dimension (:,:) :: wind_term\n! allocate (wind_term(Nx,Ny))\n! call wind(Nx,Ny,wind_term)\n\n\n", "meta": {"hexsha": "dc60ea02a69377a6a27fbf99e37e7a024cffb9a5", "size": 1178, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/omuse/community/qgmodel/src/wind.f90", "max_stars_repo_name": "ipelupessy/omuse", "max_stars_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2020-03-25T10:02:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T00:28:35.000Z", "max_issues_repo_path": "src/omuse/community/qgmodel/src/wind.f90", "max_issues_repo_name": "ipelupessy/omuse", "max_issues_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 45, "max_issues_repo_issues_event_min_datetime": "2020-03-03T16:07:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T09:01:07.000Z", "max_forks_repo_path": "src/omuse/community/qgmodel/src/wind.f90", "max_forks_repo_name": "ipelupessy/omuse", "max_forks_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-03-03T13:28:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T09:20:02.000Z", "avg_line_length": 24.5416666667, "max_line_length": 153, "alphanum_fraction": 0.4685908319, "num_tokens": 462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087926320945, "lm_q2_score": 0.8175744850834648, "lm_q1q2_score": 0.7590433405831459}} {"text": " PROGRAM xchder\r\nC driver for routine chder\r\n INTEGER NVAL\r\n REAL PIO2\r\n PARAMETER(NVAL=40, PIO2=1.5707963)\r\n INTEGER i,mval\r\n REAL a,b,chebev,fder,func,x,c(NVAL),cder(NVAL)\r\n EXTERNAL func,fder\r\n a=-PIO2\r\n b=PIO2\r\n call chebft(a,b,c,NVAL,func)\r\nC test derivative\r\n10 write(*,*) 'How many terms in Chebyshev evaluation?'\r\n write(*,'(1x,a,i2,a)') 'Enter n between 6 and ',NVAL,\r\n * '. Enter n=0 to END.'\r\n read(*,*) mval\r\n if ((mval.le.0).or.(mval.gt.NVAL)) goto 20\r\n call chder(a,b,c,cder,mval)\r\n write(*,'(1x,t10,a,t19,a,t28,a)') 'X','Actual','Cheby. Deriv.'\r\n do 11 i=-8,8,1\r\n x=i*PIO2/10.0\r\n write(*,'(1x,3f12.6)') x,fder(x),chebev(a,b,cder,mval,x)\r\n11 continue\r\n goto 10\r\n20 END\r\n REAL FUNCTION func(x)\r\n REAL x\r\n func=(x**2)*(x**2-2.0)*sin(x)\r\n END\r\n REAL FUNCTION fder(x)\r\nC derivative of FUNC\r\n REAL x\r\n fder=4.0*x*((x**2)-1.0)*sin(x)+(x**2)*(x**2-2.0)*cos(x)\r\n END\r\n", "meta": {"hexsha": "b809d68b48de4baa2557f99bd2ac405b9922fd7b", "size": 1042, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xchder.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xchder.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xchder.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.7714285714, "max_line_length": 69, "alphanum_fraction": 0.5211132438, "num_tokens": 384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947148047777, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7589949970791326}} {"text": "\tFUNCTION PR_DDEN ( pres, tmpc )\nC************************************************************************\nC* PR_DDEN\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes DDEN from PRES, TMPC. The following\t\t*\nC* equation is used:\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* DDEN = 100 * PRES / ( RDGAS * TMPK )\t\t \t*\nC*\t\t\t\t\t\t\t\t\t*\nC* 100: conversion from millibars to pascals\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_DDEN ( PRES, TMPC )\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tPRES\t\tREAL\t \tPressure in millibars\t\t*\nC*\tTMPC\t\tREAL\t\tTemperature in Celsius\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_DDEN\t\tREAL\t \tDensity of dry air in kg/(m**3)\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* G. Huffman/GSC\t8/88\tOriginal PR_DDEN\t\t\t*\nC* G. Krueger/EAI 4/96 Replaced C->K constant with TMCK\t*\nC************************************************************************\n INCLUDE \t'GEMPRM.PRM'\n INCLUDE \t'ERMISS.FNC'\nC------------------------------------------------------------------------\nC*\tCheck for bad data.\nC\n\tIF ( ERMISS ( pres ) .or. ERMISS ( tmpc )\n * .or. ( tmpc .lt. -TMCK ) ) THEN\n\t pr_dden = RMISSD\n\t RETURN\n\tEND IF\nC\nC*\tConvert temperature and compute.\nC\n\ttmpk = PR_TMCK ( tmpc )\n\tPR_DDEN = 100. * pres / ( RDGAS * tmpk )\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "120d451a537f7c1b5098033a4cbe48d486001c9f", "size": 1286, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prdden.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/prmcnvlib/pr/prdden.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/prmcnvlib/pr/prdden.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 29.9069767442, "max_line_length": 73, "alphanum_fraction": 0.4447900467, "num_tokens": 407, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947086083139, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.7589949965544672}} {"text": "\nmodule kmod\n \n contains\n\n ! Metric distance between two vectors\n ! let's use Euclidean metric\n function distance(a,b) result(c)\n implicit none\n \n real,intent(in) :: a(:),b(:)\n real :: c\n \n integer :: i\n \n c = 0\n do i = 1,size(a,1)\n c = c + (a(i)-b(i))**2\n end do\n c = sqrt(c)\n end function\n\n function cost(medoids,dados,labels) result(c)\n implicit none\n \n real,intent(in) :: medoids(:,:)\n real,intent(in) :: dados(:,:)\n integer,intent(in) :: labels(:)\n real :: c\n \n integer :: i\n \n do i = 1,size(dados,1)\n c = c + distance(dados(i,:),medoids(labels(i),:))\n end do\n end function\nend module\n\nprogram kmed\n use kmod\n implicit none\n \n integer,parameter :: datalength = 300\n real :: data(datalength,2)\n real :: medoid(3,2)\n real :: d,d_min\n real :: c1,c2\n real :: tmp(2),best(2)\n integer :: i,j,k(1),swap\n integer :: label(datalength)\n real :: s(datalength)\n integer :: clustersize(3)\n real :: t(3)\n real :: a,b\n \n character(len=50) :: fname\n logical :: existent\n logical :: change\n \n \n \n ! Load image\n open(1,file=\"data.dat\",status=\"old\")\n \n do i = 1,datalength\n read(1,*) data(i,:)\n end do\n \n close(1) \n \n ! Set itial medoids\n medoid(1,:) = data(50,:)\n medoid(2,:) = data(150,:)\n medoid(3,:) = data(250,:)\n \n swap = 1\n do while(swap > 0)\n ! Assignment step\n do i = 1,datalength\n d_min = 1E5\n do j = 1,3\n d = distance(data(i,:),medoid(j,:))\n if (d < d_min) then\n label(i) = j\n d_min = d\n end if\n end do\n end do\n \n ! For each medoid...\n swap = 0\n do j = 1,3\n c1 = cost(medoid,data,label)\n tmp = medoid(j,:)\n ! ...check if non-medoid point has lower cost, and...\n do i = 1,datalength\n medoid(j,:) = data(i,:)\n c2 = cost(medoid,data,label)\n ! ... remember the best choice.\n if (c2 < c1) then\n c1 = c2\n best = medoid(j,:)\n change = .true.\n end if\n end do\n ! If any non-medoid improved, swap\n if (change) then\n medoid(j,:) = best\n swap = swap + 1\n else\n medoid(j,:) = tmp\n end if\n end do\n end do\n \n ! Save labels\n fname = \"labels.dat\"\n inquire(file=fname,exist=existent)\n \n if (existent) then\n open(1,file=fname,status=\"old\")\n else\n open(1,file=fname,status=\"new\")\n end if\n \n do i = 1,datalength\n write(1,*) label(i)\n end do\n \n close(1)\n do i = 1,3\n write(*,*) medoid(i,:)\n end do\n \n ! Silhouette\n ! find cluster sizes\n clustersize = 0\n s = 0\n t = 0\n do i = 1,datalength\n do j = 1,3\n if (label(i) == j) then\n clustersize(j) = clustersize(j) + 1\n end if\n end do\n end do\n \n ! Find coefficients a and b\n do i = 1,datalength\n a = 0\n d_min = 1E5\n do j = 1,datalength\n ! If they are from the same cluster\n if (label(j) .eq. label(i)) then\n if (i .ne. j) then\n a = a + distance(data(i,:),data(j,:))\n end if\n else\n t(label(j)) = t(label(j)) + distance(data(i,:),data(j,:))\n end if\n end do\n if (clustersize(label(i)) .le. 1) then\n s(i) = 0\n else\n a = a/(clustersize(label(i))-1)\n \n select case(label(i))\n case(1)\n if (t(2) < t(3)) then\n b = t(2)/clustersize(2)\n else\n b = t(3)/clustersize(3)\n end if\n case(2)\n if (t(1) < t(3)) then\n b = t(1)/clustersize(1)\n else\n b = t(3)/clustersize(3)\n end if\n case(3)\n if (t(1) < t(2)) then\n b = t(1)/clustersize(1)\n else\n b = t(2)/clustersize(2)\n end if\n end select \n \n write(*,*) a,b,a/b\n \n if (a < b) then\n s(i) = 1.0-a/b\n end if\n if (a == b) then\n s(i) = 0\n end if\n if (a > b) then\n s(i) = b/a-1.0\n end if\n end if\n end do\n \n ! Save filhouette\n fname = \"silhouette.dat\"\n inquire(file=fname,exist=existent)\n \n if (existent) then\n open(1,file=fname,status=\"old\")\n else\n open(1,file=fname,status=\"new\")\n end if\n \n do i = 1,datalength\n write(1,*) s(i)\n end do\n \n close(1) \n \n \nend program\n", "meta": {"hexsha": "10d98e1acd382c2aaf443ca02e51d741307d788e", "size": 5485, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unsupervised/clustering/kmedoids.f90", "max_stars_repo_name": "StxGuy/MachineLearning", "max_stars_repo_head_hexsha": "c68842e24192f7aa32c49930ea9c55f9961c1581", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-12-09T14:28:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-10T12:57:43.000Z", "max_issues_repo_path": "unsupervised/clustering/kmedoids.f90", "max_issues_repo_name": "StxGuy/MachineLearning", "max_issues_repo_head_hexsha": "c68842e24192f7aa32c49930ea9c55f9961c1581", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "unsupervised/clustering/kmedoids.f90", "max_forks_repo_name": "StxGuy/MachineLearning", "max_forks_repo_head_hexsha": "c68842e24192f7aa32c49930ea9c55f9961c1581", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.9318181818, "max_line_length": 73, "alphanum_fraction": 0.3859617138, "num_tokens": 1455, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947132556618, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7589949869305794}} {"text": "module mod_rootfinding\n use mod_kinds, only: rk, ik\n use mod_constants, only: ZERO, ONE, TWO, RKTOL\n use type_point, only: point_t\n use type_function, only: function_t\n implicit none\n\n\n\n\ncontains\n\n\n !> Use the bisection method to find the root of a function, given\n !! two locations that are known to bound the root. \n !!\n !! Note: because functions are defined in ChiDG as functions of space and time, we\n !! set time here to zero, and use the first coordinate of the point data type\n !! point%c1_ for our working coordinate.\n !!\n !! @author Nathan A. Wukie\n !! @date 4/13/2016\n !!\n !! @param[in] fcn Function definition that can be evaluated.\n !! @param[in] xlower Lower location, smaller than the location of the root.\n !! @param[in] xupper Upper location, larger than the location of the root.\n !! @param[in] tol Optional tolerance on convergnance\n !!\n !------------------------------------------------------------------------------------\n function bisect(fcn, xlower, xupper, tol_in) result(xout)\n class(function_t), intent(inout) :: fcn\n real(rk), intent(in) :: xlower\n real(rk), intent(in) :: xupper\n real(rk), intent(inout), optional :: tol_in\n\n logical :: not_zero\n real(rk) :: fa, fb, fc, time, tol, xout\n type(point_t) :: a, b, c\n\n call a%set(ZERO, ZERO, ZERO)\n call b%set(ZERO, ZERO, ZERO)\n call c%set(ZERO, ZERO, ZERO)\n time = ZERO\n\n\n !\n ! Set default tolerance\n !\n if ( present(tol_in) ) then\n tol = tol_in\n else\n tol = RKTOL\n end if\n\n\n !\n ! Initialize bounds\n !\n a%c1_ = xlower ! lower bound - 'a'\n b%c1_ = xupper ! upper bound - 'b'\n fa = fcn%compute(time,a) ! function value at 'a'\n fb = fcn%compute(time,b) ! function value at 'b'\n\n\n !\n ! Bisection iteration\n !\n not_zero = .true.\n do while ( not_zero ) \n\n ! Compute new location\n c%c1_ = (a%c1_ + b%c1_)/TWO\n\n ! Compute new function value at middle location 'c'\n fc = fcn%compute(time,c)\n\n ! Check for convergence\n not_zero = ( fc > tol ) .or. ((b%c1_-a%c1_)/TWO > tol)\n\n ! Update bounds\n if ( int(sign(ONE,fc)) == int(sign(ONE,fa)) ) then\n a = c\n fa = fcn%compute(time,a)\n else\n b = c\n fb = fcn%compute(time,b)\n end if\n\n end do\n\n ! Save root\n xout = c%c1_\n\n end function bisect\n !*************************************************************************************\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nend module mod_rootfinding\n", "meta": {"hexsha": "22cb22b6471c8e4ecf8228ff7de50d1b28ac354c", "size": 2938, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical_methods/mod_rootfinding.f90", "max_stars_repo_name": "wanglican/ChiDG", "max_stars_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-07T11:24:04.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-07T11:24:04.000Z", "max_issues_repo_path": "src/numerical_methods/mod_rootfinding.f90", "max_issues_repo_name": "haohb/ChiDG", "max_issues_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/numerical_methods/mod_rootfinding.f90", "max_forks_repo_name": "haohb/ChiDG", "max_forks_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-27T17:12:32.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-27T17:12:32.000Z", "avg_line_length": 22.953125, "max_line_length": 90, "alphanum_fraction": 0.4792375766, "num_tokens": 750, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7589224605131343}} {"text": " SUBROUTINE MC01VD( A, B, C, Z1RE, Z1IM, Z2RE, Z2IM, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the roots of a quadratic equation with real\nC coefficients.\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC A (input) DOUBLE PRECISION\nC The value of the coefficient of the quadratic term.\nC\nC B (input) DOUBLE PRECISION\nC The value of the coefficient of the linear term.\nC\nC C (input) DOUBLE PRECISION\nC The value of the coefficient of the constant term.\nC\nC Z1RE (output) DOUBLE PRECISION\nC Z1IM (output) DOUBLE PRECISION\nC The real and imaginary parts, respectively, of the largest\nC root in magnitude.\nC\nC Z2RE (output) DOUBLE PRECISION\nC Z2IM (output) DOUBLE PRECISION\nC The real and imaginary parts, respectively, of the\nC smallest root in magnitude.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC = 1: if on entry, either A = B = 0.0 or A = 0.0 and the\nC root -C/B overflows; in this case Z1RE, Z1IM, Z2RE\nC and Z2IM are unassigned;\nC = 2: if on entry, A = 0.0; in this case Z1RE contains\nC BIG and Z1IM contains zero, where BIG is a\nC representable number near the overflow threshold\nC of the machine (see LAPACK Library Routine DLAMCH);\nC = 3: if on entry, either C = 0.0 and the root -B/A\nC overflows or A, B and C are non-zero and the largest\nC real root in magnitude cannot be computed without\nC overflow; in this case Z1RE contains BIG and Z1IM\nC contains zero;\nC = 4: if the roots cannot be computed without overflow; in\nC this case Z1RE, Z1IM, Z2RE and Z2IM are unassigned.\nC\nC METHOD\nC\nC The routine computes the roots (r1 and r2) of the real quadratic\nC equation\nC 2\nC a * x + b * x + c = 0\nC\nC as\nC - b - SIGN(b) * SQRT(b * b - 4 * a * c) c\nC r1 = --------------------------------------- and r2 = ------\nC 2 * a a * r1\nC\nC unless a = 0, in which case\nC\nC -c\nC r1 = --.\nC b\nC\nC Precautions are taken to avoid overflow and underflow wherever\nC possible.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm is numerically stable.\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Mar. 1997.\nC Supersedes Release 2.0 routine MC01JD by A.J. Geurts.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Quadratic equation, zeros.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE, FOUR\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, FOUR=4.0D0 )\nC .. Scalar Arguments ..\n INTEGER INFO\n DOUBLE PRECISION A, B, C, Z1IM, Z1RE, Z2IM, Z2RE\nC .. Local Scalars ..\n LOGICAL OVFLOW\n INTEGER BETA, EA, EAPLEC, EB, EB2, EC, ED\n DOUBLE PRECISION ABSA, ABSB, ABSC, BIG, M1, M2, MA, MB, MC, MD,\n $ SFMIN, W\nC .. External Functions ..\n DOUBLE PRECISION DLAMCH\n EXTERNAL DLAMCH\nC .. External Subroutines ..\n EXTERNAL MC01SW, MC01SY\nC .. Intrinsic Functions ..\n INTRINSIC ABS, MOD, SIGN, SQRT\nC .. Executable Statements ..\nC\nC Detect special cases.\nC\n INFO = 0\n BETA = DLAMCH( 'Base' )\n SFMIN = DLAMCH( 'Safe minimum' )\n BIG = ONE/SFMIN\n IF ( A.EQ.ZERO ) THEN\n IF ( B.EQ.ZERO ) THEN\n INFO = 1\n ELSE\n OVFLOW = .FALSE.\n Z2RE = ZERO\n IF ( C.NE.ZERO ) THEN\n ABSB = ABS( B )\n IF ( ABSB.GE.ONE ) THEN\n IF ( ABS( C ).GE.ABSB*SFMIN ) Z2RE = -C/B\n ELSE\n IF ( ABS( C ).LE.ABSB*BIG ) THEN\n Z2RE = -C/B\n ELSE\n OVFLOW = .TRUE.\n Z2RE = BIG\n IF ( SIGN( ONE, B )*SIGN( ONE, C ).GT.ZERO )\n $ Z2RE = -BIG\n END IF\n END IF\n END IF\n IF ( OVFLOW ) THEN\n INFO = 1\n ELSE\n Z1RE = BIG\n Z1IM = ZERO\n Z2IM = ZERO\n INFO = 2\n END IF\n END IF\n RETURN\n END IF\nC\n IF ( C.EQ.ZERO ) THEN\n OVFLOW = .FALSE.\n Z1RE = ZERO\n IF ( B.NE.ZERO ) THEN\n ABSA = ABS( A )\n IF ( ABSA.GE.ONE ) THEN\n IF ( ABS( B ).GE.ABSA*SFMIN ) Z1RE = -B/A\n ELSE\n IF ( ABS( B ).LE.ABSA*BIG ) THEN\n Z1RE = -B/A\n ELSE\n OVFLOW = .TRUE.\n Z1RE = BIG\n END IF\n END IF\n END IF\n IF ( OVFLOW ) INFO = 3\n Z1IM = ZERO\n Z2RE = ZERO\n Z2IM = ZERO\n RETURN\n END IF\nC\nC A and C are non-zero.\nC\n IF ( B.EQ.ZERO ) THEN\n OVFLOW = .FALSE.\n ABSC = SQRT( ABS( C ) )\n ABSA = SQRT( ABS( A ) )\n W = ZERO\n IF ( ABSA.GE.ONE ) THEN\n IF ( ABSC.GE.ABSA*SFMIN ) W = ABSC/ABSA\n ELSE\n IF ( ABSC.LE.ABSA*BIG ) THEN\n W = ABSC/ABSA\n ELSE\n OVFLOW = .TRUE.\n W = BIG\n END IF\n END IF\n IF ( OVFLOW ) THEN\n INFO = 4\n ELSE\n IF ( SIGN( ONE, A )*SIGN( ONE, C ).GT.ZERO ) THEN\n Z1RE = ZERO\n Z2RE = ZERO\n Z1IM = W\n Z2IM = -W\n ELSE\n Z1RE = W\n Z2RE = -W\n Z1IM = ZERO\n Z2IM = ZERO\n END IF\n END IF\n RETURN\n END IF\nC\nC A, B and C are non-zero.\nC\n CALL MC01SW( A, BETA, MA, EA )\n CALL MC01SW( B, BETA, MB, EB )\n CALL MC01SW( C, BETA, MC, EC )\nC\nC Compute a 'near' floating-point representation of the discriminant\nC D = MD * BETA**ED.\nC\n EAPLEC = EA + EC\n EB2 = 2*EB\n IF ( EAPLEC.GT.EB2 ) THEN\n CALL MC01SY( MB*MB, EB2-EAPLEC, BETA, W, OVFLOW )\n W = W - FOUR*MA*MC\n CALL MC01SW( W, BETA, MD, ED )\n ED = ED + EAPLEC\n ELSE\n CALL MC01SY( FOUR*MA*MC, EAPLEC-EB2, BETA, W, OVFLOW )\n W = MB*MB - W\n CALL MC01SW( W, BETA, MD, ED )\n ED = ED + EB2\n END IF\nC\n IF ( MOD( ED, 2 ).NE.0 ) THEN\n ED = ED + 1\n MD = MD/BETA\n END IF\nC\nC Complex roots.\nC\n IF ( MD.LT.ZERO ) THEN\n CALL MC01SY( -MB/( 2*MA ), EB-EA, BETA, Z1RE, OVFLOW )\n IF ( OVFLOW ) THEN\n INFO = 4\n ELSE\n CALL MC01SY( SQRT( -MD )/( 2*MA ), ED/2-EA, BETA, Z1IM,\n $ OVFLOW )\n IF ( OVFLOW ) THEN\n INFO = 4\n ELSE\n Z2RE = Z1RE\n Z2IM = -Z1IM\n END IF\n END IF\n RETURN\n END IF\nC\nC Real roots.\nC\n MD = SQRT( MD )\n ED = ED/2\n IF ( ED.GT.EB ) THEN\n CALL MC01SY( ABS( MB ), EB-ED, BETA, W, OVFLOW )\n W = W + MD\n M1 = -SIGN( ONE, MB )*W/( 2*MA )\n CALL MC01SY( M1, ED-EA, BETA, Z1RE, OVFLOW )\n IF ( OVFLOW ) THEN\n Z1RE = BIG\n INFO = 3\n END IF\n M2 = -SIGN( ONE, MB )*2*MC/W\n CALL MC01SY( M2, EC-ED, BETA, Z2RE, OVFLOW )\n ELSE\n CALL MC01SY( MD, ED-EB, BETA, W, OVFLOW )\n W = W + ABS( MB )\n M1 = -SIGN( ONE, MB )*W/( 2*MA )\n CALL MC01SY( M1, EB-EA, BETA, Z1RE, OVFLOW )\n IF ( OVFLOW ) THEN\n Z1RE = BIG\n INFO = 3\n END IF\n M2 = -SIGN( ONE, MB )*2*MC/W\n CALL MC01SY( M2, EC-EB, BETA, Z2RE, OVFLOW )\n END IF\n Z1IM = ZERO\n Z2IM = ZERO\nC\n RETURN\nC *** Last line of MC01VD ***\n END\n", "meta": {"hexsha": "3475dc397759767154cf30f0464198259dd83587", "size": 8301, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MC01VD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MC01VD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MC01VD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 28.5257731959, "max_line_length": 72, "alphanum_fraction": 0.4533188772, "num_tokens": 2570, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.939024825960626, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7587951702305306}} {"text": "module module_math\n use module_globals\n use module_autodiff\n implicit none\n\n private\n public IntegralTest, load_integral_test, f, Df\n\n type :: IntegralTest\n real(8) :: st, en, le, cn, seikai\n end type IntegralTest\n \ncontains\n !========================================================================================\n subroutine load_integral_test(test)\n type(IntegralTest),intent(out) :: test\n\n ! int_[a->b](sin(x))dx\n test%st=0.d0\n test%en=30.d0\n test%seikai=-cos(test%en)+cos(test%st)\n\n !int_[0.01->2](sin(x)/x)dx\n ! test%st=0.01d0\n ! test%en=1.d0\n ! test%seikai=0.93608312592257190411368860853800106052127274d0\n\n ! !int_[0->30](sin(x)/x)dx\n ! test%st=1.d0\n ! test%en=30.d0\n ! test%seikai=0.620673469663168096042377995183618508711157d0\n\n ! int_[-1->1] 1/(1+25*x^2) dx\n test%st=-5.d0\n test%en=5.d0\n test%seikai=(atan(5.d0*test%en)-atan(5.d0*test%st))/5.d0\n\n ! int_[0,1] bessel_j0(x) dx\n ! test%st=0.d0\n ! test%en=1.d0\n ! test%seikai=0.919730410089760239314421194080619970661d0\n\n ! test%st=0.d0\n ! test%en=2.d0\n ! test%seikai=(test%en**30-test%st**30)/30.d0\n \n test%le=test%en-test%st\n test%cn=(test%st+test%en)*0.5d0\n\n end subroutine load_integral_test\n\n !========================================================================================\n real(8) function f(x)\n real(8),intent(in) :: x\n !f=sin(x)\n !f=sin(x)/x\n !f=sin(x)/x\n f=1.d0/(1.d0+25.d0*x*x)\n !f=bessel_j0(x)\n !f=x**29\n end function f\n\n !========================================================================================\n type(Dcomplex8) function Df(x)\n type(Dcomplex8),intent(in) :: x\n !Df=sin(x)\n !Df=sin(x)/x\n !Df=sin(x)/x\n Df=1.d0/(1.d0+25.d0*x*x)\n !Df=bessel_j0(x)\n !Df=x**29\n end function Df\n \nend module module_math\n", "meta": {"hexsha": "6889190dbb2e31989751c0024c842a68f7946785", "size": 1838, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/src/module_math.f90", "max_stars_repo_name": "isakari/gtq_quadp", "max_stars_repo_head_hexsha": "b6b6c7ade6c96cc1f07230dc7d15b3b49fd2a313", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/src/module_math.f90", "max_issues_repo_name": "isakari/gtq_quadp", "max_issues_repo_head_hexsha": "b6b6c7ade6c96cc1f07230dc7d15b3b49fd2a313", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/src/module_math.f90", "max_forks_repo_name": "isakari/gtq_quadp", "max_forks_repo_head_hexsha": "b6b6c7ade6c96cc1f07230dc7d15b3b49fd2a313", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.5066666667, "max_line_length": 91, "alphanum_fraction": 0.5255712731, "num_tokens": 671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699436, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7587641251152057}} {"text": "\n subroutine fort_set_dirichlet_bcs(lo,hi,domlo,domhi, &\n phi,phi_l1,phi_l2,phi_l3,phi_h1,phi_h2,phi_h3,dx);\n\n use amrex_fort_module, only : rt => amrex_real\n use bl_constants_module , only : M_PI\n use probdata_module , only : a1,a3,center\n use meth_params_module , only : NVAR\n use fundamental_constants_module, only : Gconst\n \n implicit none\n\n integer ,intent(in ) :: lo(3),hi(3),domlo(3),domhi(3)\n integer ,intent(in ) :: phi_l1,phi_l2,phi_l3,phi_h1,phi_h2,phi_h3\n real(rt),intent( out) :: phi(phi_l1:phi_h1,phi_l2:phi_h2,phi_l3:phi_h3)\n real(rt),intent(in ) :: dx(3)\n\n integer :: i,j,k\n real(rt) :: x,y,z,rsq,zsq\n real(rt) :: a1sq,a3sq\n real(rt) :: e,esq,b,lambda,h,ah\n\n a1sq = a1**2\n a3sq = a3**2\n\n esq = 1.d0 - a3sq/a1sq\n e = dsqrt(esq)\n\n if (lo(1).eq.domlo(1)) then\n i = lo(1)-1\n x = 0.d0 - center(1)\n do k = lo(3), hi(3)\n z = (dble(k)+0.5d0)*dx(3) - center(3)\n zsq = z**2\n do j = lo(2), hi(2)\n y = (dble(j)+0.5d0)*dx(2) - center(2)\n rsq = x**2 + y**2\n b = a1sq + a3sq - rsq - zsq\n lambda = 0.5d0 * ( -b + dsqrt( b**2 - 4.d0 * &\n (a1sq * a3sq - rsq * a3sq - zsq * a1sq) ) )\n h = a1 * e / (dsqrt(a3sq + lambda))\n ah = datan(h)\n phi(i,j,k) = &\n 2.d0 * M_PI * Gconst * a1 * a3 / e * ( &\n ah - 0.5d0 / (a1sq * esq) * &\n ( rsq * (ah - h / (1.d0+h**2) ) + 2.d0 * zsq * (h - ah) ) )\n\n end do\n end do\n end if\n\n if (hi(1).eq.domhi(1)) then\n i = hi(1)+1\n x = 1.d0 - center(1)\n do k = lo(3), hi(3)\n z = (dble(k)+0.5d0)*dx(3) - center(3)\n zsq = z**2\n do j = lo(2), hi(2)\n y = (dble(j)+0.5d0)*dx(2) - center(2)\n rsq = x**2 + y**2\n b = a1sq + a3sq - rsq - zsq\n lambda = 0.5d0 * ( -b + dsqrt( b**2 - 4.d0 * &\n (a1sq * a3sq - rsq * a3sq - zsq * a1sq) ) )\n h = a1 * e / (dsqrt(a3sq + lambda))\n ah = datan(h)\n phi(i,j,k) = &\n 2.d0 * M_PI * Gconst * a1 * a3 / e * ( &\n ah - 0.5d0 / (a1sq * esq) * &\n ( rsq * (ah - h / (1.d0+h**2) ) + 2.d0 * zsq * (h - ah) ) )\n end do\n end do\n end if\n\n if (lo(2).eq.domlo(2)) then\n j = lo(2)-1\n y = 0.d0 - center(2)\n do k = lo(3), hi(3)\n z = (dble(k)+0.5d0)*dx(3) - center(3)\n zsq = z**2\n do i = lo(1), hi(1)\n x = (dble(i)+0.5d0)*dx(1) - center(1)\n rsq = x**2 + y**2\n b = a1sq + a3sq - rsq - zsq\n lambda = 0.5d0 * ( -b + dsqrt( b**2 - 4.d0 * &\n (a1sq * a3sq - rsq * a3sq - zsq * a1sq) ) )\n h = a1 * e / (dsqrt(a3sq + lambda))\n ah = datan(h)\n phi(i,j,k) = &\n 2.d0 * M_PI * Gconst * a1 * a3 / e * ( &\n ah - 0.5d0 / (a1sq * esq) * &\n ( rsq * (ah - h / (1.d0+h**2) ) + 2.d0 * zsq * (h - ah) ) )\n end do\n end do\n end if\n\n if (hi(2).eq.domhi(2)) then\n j = hi(2)+1\n y = 1.d0 - center(2)\n do k = lo(3), hi(3) \n z = (dble(k)+0.5d0)*dx(3) - center(3)\n zsq = z**2\n do i = lo(1), hi(1)\n x = (dble(i)+0.5d0)*dx(1) - center(1)\n rsq = x**2 + y**2\n b = a1sq + a3sq - rsq - zsq\n lambda = 0.5d0 * ( -b + dsqrt( b**2 - 4.d0 * &\n (a1sq * a3sq - rsq * a3sq - zsq * a1sq) ) )\n h = a1 * e / (dsqrt(a3sq + lambda))\n ah = datan(h)\n phi(i,j,k) = &\n 2.d0 * M_PI * Gconst * a1 * a3 / e * ( &\n ah - 0.5d0 / (a1sq * esq) * &\n ( rsq * (ah - h / (1.d0+h**2) ) + 2.d0 * zsq * (h - ah) ) )\n end do\n end do\n end if\n\n if (lo(3).eq.domlo(3)) then\n k = lo(3)-1\n z = 0.d0 - center(3)\n zsq = z**2\n do j = lo(2), hi(2)\n y = (dble(j)+0.5d0)*dx(2) - center(2)\n do i = lo(1), hi(1)\n x = (dble(i)+0.5d0)*dx(1) - center(1)\n rsq = x**2 + y**2\n b = a1sq + a3sq - rsq - zsq\n lambda = 0.5d0 * ( -b + dsqrt( b**2 - 4.d0 * &\n (a1sq * a3sq - rsq * a3sq - zsq * a1sq) ) )\n h = a1 * e / (dsqrt(a3sq + lambda))\n ah = datan(h)\n phi(i,j,k) = &\n 2.d0 * M_PI * Gconst * a1 * a3 / e * ( &\n ah - 0.5d0 / (a1sq * esq) * &\n ( rsq * (ah - h / (1.d0+h**2) ) + 2.d0 * zsq * (h - ah) ) )\n end do\n end do\n end if\n\n if (hi(3).eq.domhi(3)) then\n k = hi(3)+1\n z = 1.d0 - center(3)\n zsq = z**2\n do j = lo(2), hi(2)\n y = (dble(j)+0.5d0)*dx(2) - center(2)\n do i = lo(1), hi(1)\n x = (dble(i)+0.5d0)*dx(1) - center(1)\n rsq = x**2 + y**2\n b = a1sq + a3sq - rsq - zsq\n lambda = 0.5d0 * ( -b + dsqrt( b**2 - 4.d0 * &\n (a1sq * a3sq - rsq * a3sq - zsq * a1sq) ) )\n h = a1 * e / (dsqrt(a3sq + lambda))\n ah = datan(h)\n phi(i,j,k) = &\n 2.d0 * M_PI * Gconst * a1 * a3 / e * ( &\n ah - 0.5d0 / (a1sq * esq) * &\n ( rsq * (ah - h / (1.d0+h**2) ) + 2.d0 * zsq * (h - ah) ) )\n end do\n end do\n end if\n \n end subroutine fort_set_dirichlet_bcs\n\n subroutine fort_set_homog_bcs(lo,hi,domlo,domhi, &\n phi,phi_l1,phi_l2,phi_l3,phi_h1,phi_h2,phi_h3,dx);\n \n use amrex_fort_module, only : rt => amrex_real\n implicit none\n\n integer ,intent(in ) :: lo(3),hi(3),domlo(3),domhi(3)\n integer ,intent(in ) :: phi_l1,phi_l2,phi_l3,phi_h1,phi_h2,phi_h3\n real(rt),intent( out) :: phi(phi_l1:phi_h1,phi_l2:phi_h2,phi_l3:phi_h3)\n real(rt),intent(in ) :: dx(3)\n\n phi = 0.d0\n \n end subroutine fort_set_homog_bcs\n\n ! ************************************************************************************\n ! Loops over the particles and adds their monopole contribution to phi outside the boundary\n ! ************************************************************************************\n\n subroutine fort_add_monopole_bcs(lo,hi,domlo,domhi, &\n np,part_locs,part_mass, &\n phi,phi_l1,phi_l2,phi_l3,phi_h1,phi_h2,phi_h3,dx);\n\n use amrex_fort_module, only : rt => amrex_real\n use fundamental_constants_module, only : Gconst\n \n implicit none\n\n integer ,intent(in ) :: lo(3),hi(3),domlo(3),domhi(3),np\n integer ,intent(in ) :: phi_l1,phi_l2,phi_l3,phi_h1,phi_h2,phi_h3\n real(rt),intent(in ) :: part_locs(0:3*np-1)\n real(rt),intent(in ) :: part_mass(0: np-1)\n real(rt),intent( out) :: phi(phi_l1:phi_h1,phi_l2:phi_h2,phi_l3:phi_h3)\n real(rt),intent(in ) :: dx(3)\n\n ! Local variables\n integer :: i,j,k,n\n real(rt) :: x,y,z,r\n real(rt) :: x0,y0,z0\n\n phi = 0.d0\n\n ! Define phi = -G M / r where r is distance from particle and M is mass of particle\n\n do k = lo(3)-1,hi(3)+1\n do j = lo(2)-1,hi(2)+1\n do i = lo(1)-1,hi(1)+1\n\n if (i.lt.domlo(1) .or. i.gt.domhi(1) .or. &\n j.lt.domlo(2) .or. j.gt.domhi(2) .or. &\n k.lt.domlo(3) .or. k.gt.domhi(3)) then\n\n if (i.lt.domlo(1)) then\n x0 = (dble(i+1))*dx(1)\n else if (i.gt.domhi(1)) then\n x0 = (dble(i))*dx(1)\n else \n x0 = (dble(i)+0.5d0)*dx(1)\n end if\n \n if (j.lt.domlo(2)) then\n y0 = (dble(j+1))*dx(2)\n else if (j.gt.domhi(2)) then\n y0 = (dble(j))*dx(2)\n else \n y0 = (dble(j)+0.5d0)*dx(2)\n end if\n \n if (k.lt.domlo(3)) then\n z0 = (dble(k+1))*dx(3)\n else if (k.gt.domhi(3)) then\n z0 = (dble(k))*dx(3)\n else \n z0 = (dble(k)+0.5d0)*dx(3)\n end if\n\n do n = 0, np-1\n x = x0 - part_locs(3*n )\n y = y0 - part_locs(3*n+1)\n z = z0 - part_locs(3*n+2)\n r = sqrt(x*x + y*y + z*z)\n phi(i,j,k) = phi(i,j,k) - Gconst * part_mass(n) / r \n end do\n \n end if\n end do\n end do\n end do\n \n end subroutine fort_add_monopole_bcs\n", "meta": {"hexsha": "a6f368d1b468494b2808929803e37ebf1abfc04c", "size": 9657, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Exec/GravityTests/MacLaurin/set_dirichlet_bcs_3d.f90", "max_stars_repo_name": "Gosenca/axionyx_1.0", "max_stars_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 72, "max_stars_repo_stars_event_min_datetime": "2017-06-16T17:20:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-18T12:45:58.000Z", "max_issues_repo_path": "Exec/GravityTests/MacLaurin/set_dirichlet_bcs_3d.f90", "max_issues_repo_name": "Gosenca/axionyx_1.0", "max_issues_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 37, "max_issues_repo_issues_event_min_datetime": "2017-05-07T04:20:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T19:16:59.000Z", "max_forks_repo_path": "Exec/GravityTests/MacLaurin/set_dirichlet_bcs_3d.f90", "max_forks_repo_name": "Gosenca/axionyx_1.0", "max_forks_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 30, "max_forks_repo_forks_event_min_datetime": "2017-05-18T21:14:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T20:50:24.000Z", "avg_line_length": 38.0196850394, "max_line_length": 96, "alphanum_fraction": 0.3643988816, "num_tokens": 3238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9693241974031599, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.7586536743347001}} {"text": "!SUBROUTINE INVERSSYMDEF(A,AINV)\n! IMPLICIT REAL*8 (A-H,O-Z)\n! DIMENSION A(3,3),AINV(3,3)\n! det= a(1,1)*a(2,2)*a(3,3)+a(1,2)*a(2,3)*a(3,1)+a(1,3)*a(2,1)*a(3,2)-a(3,1)*a(2,2)*a(1,3)-a(1,1)*a(3,2)*a(2,3)-a(2,1)*a(1,2)*a(3,3)\n! AINV(1,1) =( A(2,2) * A(3,3) - A(2,3) * A(3,2) ) / det\n! AINV(2,1) =( - A(2,1) * A(3,3) + A(2,3) * A(3,1) ) / det\n! AINV(3,1) =( A(2,1) * A(3,2) - A(2,2) * A(3,1) ) / det\n! AINV(1,2) =( - A(1,2) * A(3,3) + A(1,3) * A(3,2) ) / det\n! AINV(2,2) =( A(1,1) * A(3,3) - A(1,3) * A(3,1) ) / det\n! AINV(3,2) =( - A(1,1) * A(3,2) + A(1,2) * A(3,1) ) / det\n! AINV(1,3) =( A(1,2) * A(2,3) - A(1,3) * A(2,2) ) / det\n! AINV(2,3) =( - A(1,1) * A(2,3) + A(1,3) * A(2,1) ) / det\n! AINV(3,3) =( A(1,1) * A(2,2) - A(1,2) * A(2,1) ) / det\n! RETURN\n!END SUBROUTINE INVERSSYMDEF\nSUBROUTINE inv_3x3(A,Ainv)\n IMPLICIT NONE\n REAL*8, intent(in) :: A(3,3)\n REAL*8, intent(out) :: Ainv(3,3)\n ! locals\n REAL*8 :: det\n det = A(1,1)*A(2,2)*A(3,3) + A(1,2)*A(2,3)*A(3,1) + A(1,3)*A(2,1)*A(3,2) &\n - A(3,1)*A(2,2)*A(1,3) - A(1,1)*A(3,2)*A(2,3) - A(2,1)*A(1,2)*A(3,3)\n Ainv(1,1) =( A(2,2) * A(3,3) - A(2,3) * A(3,2) ) / det\n Ainv(1,2) =( - A(1,2) * A(3,3) + A(1,3) * A(3,2) ) / det\n Ainv(1,3) =( A(1,2) * A(2,3) - A(1,3) * A(2,2) ) / det\n Ainv(2,1) =( - A(2,1) * A(3,3) + A(2,3) * A(3,1) ) / det\n Ainv(2,2) =( A(1,1) * A(3,3) - A(1,3) * A(3,1) ) / det\n Ainv(2,3) =( - A(1,1) * A(2,3) + A(1,3) * A(2,1) ) / det\n Ainv(3,1) =( A(2,1) * A(3,2) - A(2,2) * A(3,1) ) / det\n Ainv(3,2) =( - A(1,1) * A(3,2) + A(1,2) * A(3,1) ) / det\n Ainv(3,3) =( A(1,1) * A(2,2) - A(1,2) * A(2,1) ) / det\n RETURN\nEND SUBROUTINE inv_3x3\n", "meta": {"hexsha": "03f78304d1f79f7248bb5ce32bf779cc562ccc4d", "size": 1657, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/dmft1/inverss.f90", "max_stars_repo_name": "dmft-wien2k/dmft-wien2k-v2", "max_stars_repo_head_hexsha": "83481be27e8a9ff14b9635d6cc1cd9d96f053487", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-05-13T13:04:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T10:08:09.000Z", "max_issues_repo_path": "src/dmft1/inverss.f90", "max_issues_repo_name": "dmft-wien2k/dmft-wien2k-v2", "max_issues_repo_head_hexsha": "83481be27e8a9ff14b9635d6cc1cd9d96f053487", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-07-12T21:37:53.000Z", "max_issues_repo_issues_event_max_datetime": "2016-07-12T21:42:01.000Z", "max_forks_repo_path": "src/dmft1/inverss.f90", "max_forks_repo_name": "dmft-wien2k/dmft-wien2k", "max_forks_repo_head_hexsha": "83481be27e8a9ff14b9635d6cc1cd9d96f053487", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-07-22T15:46:56.000Z", "max_forks_repo_forks_event_max_datetime": "2016-08-02T15:05:12.000Z", "avg_line_length": 47.3428571429, "max_line_length": 133, "alphanum_fraction": 0.4194327097, "num_tokens": 1109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541577509315, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.7586269069638304}} {"text": "PROGRAM EXAMPLE\n IMPLICIT NONE\n\n INTEGER :: i, j\n\n DO i = 0, 3\n DO j = 0, 6\n WRITE(*, \"(I10)\", ADVANCE=\"NO\") Ackermann(i, j)\n END DO\n WRITE(*,*)\n END DO\n\nCONTAINS\n\n RECURSIVE FUNCTION Ackermann(m, n) RESULT(ack)\n INTEGER :: ack, m, n\n\n IF (m == 0) THEN\n ack = n + 1\n ELSE IF (n == 0) THEN\n ack = Ackermann(m - 1, 1)\n ELSE\n ack = Ackermann(m - 1, Ackermann(m, n - 1))\n END IF\n END FUNCTION Ackermann\n\nEND PROGRAM EXAMPLE\n", "meta": {"hexsha": "a58587772daa8a6c9ceb401fc2f6a48b98dd77a1", "size": 471, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Ackermann-function/Fortran/ackermann-function.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Ackermann-function/Fortran/ackermann-function.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Ackermann-function/Fortran/ackermann-function.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 16.8214285714, "max_line_length": 54, "alphanum_fraction": 0.5456475584, "num_tokens": 173, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541528387692, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.7586269052036498}} {"text": " SUBROUTINE WEIGHT (T, W)\nC----------------------------------------------------------------------\nC\nC Computes the weights at 0 <= t <= 1 for the spline function and\nC its 1st derivative defined by:\nC\nC x (t) = x1*W11(t) + x2*W21(t) + dx1*W31(t) + dx2*W41(t)\nC x' (t) = x1*W12(t) + x2*W22(t) + dx1*W32(t) + dx2*W42(t)\nC x''(t) = x1*W13(t) + x2*W23(t) + dx1*W33(t) + dx2*W43(t)\nC\nC 2 2\nC W (t) = (1 + 2t) (t-1), W (t)= t (t-1)\nC 11 31\nC 2 2\nC W (t) = (3 - 2t) t , W (t)= (t-1) t\nC 21 41\nC\nC\nC For t=0 W (:,1)= [ 1, 0, 0, 0],\nC W (:,2)= [ 0, 0, 1, 0],\nC W (:,3)= [-6, 6,-4,-2]\nC\nC For t=1 W (:,1)= [ 0, 1, 0, 0],\nC W (:,2)= [ 0, 0, 0, 1],\nC W (:,3)= [ 6,-6, 2, 4]\nC\nC x(t), x'(t) and x''(t) are continuous over an element\nC truncation error is O(h^4)\nC\nC----------------------------------------------------------------------\n IMPLICIT NONE\n INCLUDE 'knd_params.inc'\nC\n REAL(KIND=RK) T\n REAL(KIND=RK) W (4, 2)\nC\n W (1, 1) = (T - 1.0D0) ** 2 * (1.0D0 + 2.0D0 * T)\n W (2, 1) = T ** 2 * (3.0D0 - 2.0D0 * T)\n W (3, 1) = (T - 1.0D0) ** 2 * T\n W (4, 1) = T ** 2 * (T - 1.0D0)\n W (1, 2) = 6.0D0 * T * (T - 1.0D0)\n W (2, 2) =-6.0D0 * T * (T - 1.0D0)\n W (3, 2) = (3.0D0 * T - 1.0D0) * (T - 1.0D0)\n W (4, 2) = (3.0D0 * T - 2.0D0) * T\nC\n RETURN\n END\n", "meta": {"hexsha": "56197908d464634a446acd83688cf855e593574e", "size": 1575, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/weight.f", "max_stars_repo_name": "meggermo/waterwaves", "max_stars_repo_head_hexsha": "b4320a9545a0e85306abeb7e621b27feadb11b7f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/weight.f", "max_issues_repo_name": "meggermo/waterwaves", "max_issues_repo_head_hexsha": "b4320a9545a0e85306abeb7e621b27feadb11b7f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/weight.f", "max_forks_repo_name": "meggermo/waterwaves", "max_forks_repo_head_hexsha": "b4320a9545a0e85306abeb7e621b27feadb11b7f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.8125, "max_line_length": 71, "alphanum_fraction": 0.3263492063, "num_tokens": 714, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541626630935, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.758626895540716}} {"text": "module distributions\n use constants\n contains\n\n function maxbolt(v,v0)\n ! Maxwell-Boltzmann (MB) probability distribution \n \n implicit none\n \n real(kind=8), intent(in) :: v \n real(kind=8), intent(in) :: v0\n real(kind=8) :: maxbolt\n \n maxbolt = exp(-(v/v0)**2.0d0) / ((pi)**1.5d0 * v0**3.0d0)\n \n end function maxbolt\n\n function shm(v, v0, vesc)\n ! Standard halo model probability distribution, i.e.\n ! a MB distribution with a sharp cutoff to recognize the\n ! finite escape speed of the galaxy.\n \n implicit none\n\n real(kind=8), intent(in) :: v, v0, vesc\n real(kind=8) :: shm\n real(kind=8) :: Nresc, z, y\n\n if (v > vesc) then\n shm = 0d0\n return\n end if\n\n z = vesc / v0\n y = v / v0\n\n Nresc = erf(z) - 2d0*z * exp(-z*z)/sqrt(pi)\n shm = exp(-y*y) / (Nresc * (pi)**1.5d0 * v0**3d0)\n\n end function shm\n\n function sshm(v, ve, v0, vesc)\n ! Smooth standard halo model. Basically a SHM with an extra constant \n ! term meanth to smooth the distribution near vesc.\n \n implicit none\n\n real(kind=8), intent(in) :: v, ve, v0, vesc\n real(kind=8) :: sshm\n real(kind=8) :: Nesc, z\n\n z = vesc / v0\n\n Nesc = (erf(z)-2d0*z*(1d0+z*z/1.5d0)*exp(-z*z)/sqrt(pi))*pi**1.5d0*v0**3d0\n sshm = (Imbcutoff(v, ve, v0, vesc) - Isccutoff(v, ve, v0, vesc))/Nesc\n\n end function sshm\n\n function Imbcutoff(v, ve, v0, vesc)\n ! Integrand for radial part of Maxwell Boltzmann distribution with cutoff\n \n implicit none\n\n real(kind=8), intent(in) :: v, ve, v0, vesc\n real(kind=8) :: Imbcutoff\n\n if (vvesc-ve\n Imbcutoff = g(v-ve,v0)-g(vesc,v0)\n end if\n Imbcutoff = Imbcutoff * pi*(v0**2d0/ve)\n\n end function Imbcutoff\n\n function Isccutoff(v, ve, v0, vesc)\n ! Integrand for radial part of smooth component with cutoff\n \n implicit none\n\n real(kind=8), intent(in) :: v, ve, v0, vesc\n real(kind=8) :: Isccutoff\n\n if (vvesc-ve\n Isccutoff = (vesc**2d0 - (v-ve)**2d0)/(2d0*ve)\n end if\n Isccutoff = Isccutoff * 2d0*pi*g(vesc,v0)\n\n end function Isccutoff\n\n function g(v, v0)\n ! Gaussian term\n \n implicit none\n\n real(kind=8), intent(in) :: v\n real(kind=8), intent(in) :: v0\n real(kind=8) :: g\n\n g = exp(-(v/v0)**2d0) \n\n end function\n\nend module\n\n", "meta": {"hexsha": "b1926c3865fc178431aa7564162aeb063cbbcd2b", "size": 2706, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/distributions.f90", "max_stars_repo_name": "ogorton/dmfortfactor", "max_stars_repo_head_hexsha": "879e747a3c839687a729091f811282fdb9264869", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-28T20:58:51.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T20:58:51.000Z", "max_issues_repo_path": "src/distributions.f90", "max_issues_repo_name": "ogorton/dmfortfactor", "max_issues_repo_head_hexsha": "879e747a3c839687a729091f811282fdb9264869", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-24T20:35:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T21:51:53.000Z", "max_forks_repo_path": "src/distributions.f90", "max_forks_repo_name": "ogorton/dmfortfactor", "max_forks_repo_head_hexsha": "879e747a3c839687a729091f811282fdb9264869", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0555555556, "max_line_length": 82, "alphanum_fraction": 0.5266075388, "num_tokens": 879, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109756113862, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.7586054718703048}} {"text": "\nFUNCTION distance_between_points(x0,y0,z0,x1,y1,z1)\n IMPLICIT NONE\n DOUBLE PRECISION :: distance_between_points\n DOUBLE PRECISION :: x0,y0,z0,x1,y1,z1\n DOUBLE PRECISION :: dx,dy,dz\n dx = x1 - x0\n dy = y1 - y0\n dz = z1 - z0\n distance_between_points = SQRT(dx * dx + dy * dy + dz * dz)\nEND FUNCTION\n\n\nFUNCTION find_nearest_neighbors (npoints,x,y,z,n0,n1,n2)\n IMPLICIT NONE\n INTEGER, INTENT(IN):: npoints\n INTEGER :: i,j, k, kk\n INTEGER :: find_nearest_neighbors\n DOUBLE PRECISION :: x(npoints),y(npoints),z(npoints)\n INTEGER :: n0(npoints),n1(npoints),n2(npoints)\n DOUBLE PRECISION :: r\n DOUBLE PRECISION :: distance_between_points\n INTEGER :: nn_index(3)\n DOUBLE PRECISION :: nn_distance(3)\n \n DO i = 1, npoints, 1\n DO k = 1, 3\n nn_index(k) = 0\n nn_distance(k) = 0.0\n END DO\n \n DO j = 1, npoints, 1\n IF (i.NE.j) THEN\n r = distance_between_points(x(i), y(i), z(i), &\n x(j), y(j), z(j))\n \n DO k = 1, 3\n IF (nn_index(k).EQ.0) THEN\n nn_index(k) = j\n nn_distance(k) = r\n EXIT\n ELSE\n IF (r.LT.nn_distance(k)) THEN\n DO kk = 3, k, -1\n nn_index(kk) = nn_index(kk-1)\n nn_distance(kk) = nn_distance(kk-1)\n END DO\n nn_index(k) = j\n nn_distance(k) = r\n EXIT\n END IF\n END IF\n END DO\n END IF\n END DO\n \n n0(i) = nn_index(1)\n n1(i) = nn_index(2)\n n2(i) = nn_index(3)\n END DO\n \n find_nearest_neighbors = 0\nEND FUNCTION\n", "meta": {"hexsha": "210b487077ae3af37aa6a4b66125b20122d5634b", "size": 1923, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/tutorial/nearestneighbor/code.f90", "max_stars_repo_name": "rknop/amuse", "max_stars_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 131, "max_stars_repo_stars_event_min_datetime": "2015-06-04T09:06:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-01T12:11:29.000Z", "max_issues_repo_path": "doc/tutorial/nearestneighbor/code.f90", "max_issues_repo_name": "rknop/amuse", "max_issues_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 690, "max_issues_repo_issues_event_min_datetime": "2015-10-17T12:18:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:15:58.000Z", "max_forks_repo_path": "doc/tutorial/nearestneighbor/code.f90", "max_forks_repo_name": "rieder/amuse", "max_forks_repo_head_hexsha": "3ac3b6b8f922643657279ddee5c8ab3fc0440d5e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 102, "max_forks_repo_forks_event_min_datetime": "2015-01-22T10:00:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-09T13:29:43.000Z", "avg_line_length": 30.046875, "max_line_length": 67, "alphanum_fraction": 0.4503380135, "num_tokens": 518, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299488452012, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7585898651739976}} {"text": "C$Procedure MTXV ( Matrix transpose times vector, 3x3 )\n \n SUBROUTINE MTXV ( MATRIX, VIN, VOUT )\n \nC$ Abstract\nC\nC MTXV multiplies the transpose of a 3x3 matrix on the left with\nC a vector on the right.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC MATRIX\nC VECTOR\nC\nC$ Declarations\n \n DOUBLE PRECISION MATRIX ( 3,3 )\n DOUBLE PRECISION VIN ( 3 )\n DOUBLE PRECISION VOUT ( 3 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC MATRIX I 3X3 double precision matrix.\nC VIN I 3-dimensional double precision vector.\nC VOUT O 3-dimensional double precision vector. VOUT is\nC the product MATRIX**T * VIN.\nC\nC$ Detailed_Input\nC\nC MATRIX is an arbitrary 3x3 double precision matrix.\nC Typically, MATRIX will be a rotation matrix since\nC then its transpose is its inverse (but this is NOT\nC a requirement).\nC\nC VIN is an arbitrary 3-dimensional double precision\nC vector.\nC\nC$ Detailed_Output\nC\nC VOUT is a 3-dimensional double precision vector. VOUT is\nC the product VOUT = (MATRIX**T) x (VIN).\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC The code reflects precisely the following mathematical expression\nC\nC For each value of the subscript I from 1 to 3:\nC\nC VOUT(I) = Summation from K=1 to 3 of ( MATRIX(K,I) * VIN(K) )\nC\nC Note that the reversal of the K and I subscripts in the left-hand\nC matrix MATRIX is what makes VOUT the product of the TRANSPOSE of\nC and not simply of MATRIX itself. \nC\nC$ Examples\nC\nC Typically the matrix MATRIX will be a rotation matrix. Because\nC the transpose of an orthogonal matrix is equivalent to its\nC inverse, applying the rotation to the vector is accomplished by\nC multiplying the vector by the transpose of the matrix.\nC\nC -1\nC Let MATRIX * VIN = VOUT. If MATRIX is an orthogonal matrix,\nC then (MATRIX**T) * VIN = VOUT.\nC\nC\nC If MATRIX = | 1.0D0 1.0D0 0.0D0 | and VIN = | 5.0D0 |\nC | | | |\nC | -1.0D0 1.0D0 0.0D0 | | 10.0D0 |\nC | | | |\nC | 0.0D0 0.0D0 1.0D0 | | 15.0D0 |\nC\nC\nC then the call\nC\nC CALL MTXV ( MATRIX, VIN, VOUT )\nC\nC produces the vector\nC\nC\nC VOUT = | -5.0D0 |\nC | |\nC | 15.0D0 |\nC | |\nC | 15.0D0 |\nC\nC\nC$ Restrictions\nC\nC The user is responsible for checking the magnitudes of the\nC elements of MATRIX and VIN so that a floating point overflow does\nC not occur.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.M. Owen (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.2, 23-APR-2010 (NJB)\nC\nC Header correction: assertions that the output\nC can overwrite the input have been removed.\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WMO)\nC\nC-&\n \nC$ Index_Entries\nC\nC matrix_transpose times 3-dimensional vector\nC\nC-&\n \n \n \nC\nC Local variables\nC\n DOUBLE PRECISION PRODV(3)\n INTEGER I\n \n \nC\nC Perform the matrix-vector multiplication\nC\n DO I = 1, 3\n PRODV(I) = MATRIX(1,I)*VIN(1) +\n . MATRIX(2,I)*VIN(2) +\n . MATRIX(3,I)*VIN(3)\n END DO\n \nC\nC Move the result into VOUT\nC\n VOUT(1) = PRODV(1)\n VOUT(2) = PRODV(2)\n VOUT(3) = PRODV(3)\n \n \n RETURN\n END\n", "meta": {"hexsha": "945f189af33b30caffe9b2dca13e2e53b25f6680", "size": 5293, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/mtxv.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/mtxv.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/mtxv.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 27.2835051546, "max_line_length": 71, "alphanum_fraction": 0.6121292273, "num_tokens": 1564, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810496235896, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.7585604226122858}} {"text": "subroutine coarse_to_fine_uface(e_2h, nx, ny, e_h)\nuse kind_parameters\nimplicit none\n\ninteger, intent(in):: nx, ny\nreal(kind=dp), intent(in), dimension(nx,ny):: e_2h\nreal(kind=dp), intent(out), dimension(2*nx-1,2*ny-2):: e_h\ninteger:: i, j\n\n!write(*,*) nx, ny\n\n! Apply linear interpolation to get values from coarse to fine grid\n! Input\n! e_2h Variable in coarse grid\n! hx, hy grid spacing\n!\n! Output\n! e_h Variable in fine grid\n\n! Author: Pratanu Roy\n! History:\n! First Written: July 20, 2012\n\ndo j = 2,ny-2\n\n do i = 1,nx-1\n\n e_h(2*i-1,2*j-1) = (1.0/4.0)*(3.0*e_2h(i,j) + e_2h(i,j+1))\n e_h(2*i,2*j) = (1.0/8.0)*(3.0*e_2h(i,j+1) + 3.0*e_2h(i+1,j+1) + e_2h(i,j) + e_2h(i+1,j))\n e_h(2*i, 2*j-1) = (1.0/8.0)*(e_2h(i,j+1) + e_2h(i+1,j+1) + 3.0*e_2h(i,j) + 3.0*e_2h(i+1,j))\n e_h(2*i-1,2*j) = (1.0/4.0)*(e_2h(i,j) + 3.0*e_2h(i,j+1))\n\n end do\n\nend do\n\nj = 1\n\ndo i = 1,nx-1\n\n\te_h(2*i-1,2*j) = (1.0/2.0)*(e_2h(i,j) + e_2h(i,j+1))\n e_h(2*i,2*j) = (1.0/4.0)*(e_2h(i,j) + e_2h(i,j+1) + e_2h(i+1,j) + e_2h(i+1,j+1))\n\nend do\n\nj = ny-1\n\ndo i = 1,nx-1\n\n e_h(2*i-1,2*j-1) = (1.0/2.0)*(e_2h(i,j) + e_2h(i,j+1))\n e_h(2*i,2*j-1) = (1.0/4.0)*(e_2h(i,j) + e_2h(i,j+1) + e_2h(i+1,j) + e_2h(i+1,j+1))\n\nend do\n\nend subroutine\n", "meta": {"hexsha": "2d7b2b1cf9f9fd8aa4bd4a71c8d8f845ee640412", "size": 1254, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "coarse_to_fine_uface.f90", "max_stars_repo_name": "pratanuroy/Multigrid_Cavity", "max_stars_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-11T12:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-11T12:01:52.000Z", "max_issues_repo_path": "coarse_to_fine_uface.f90", "max_issues_repo_name": "pratanuroy/Multigrid_Cavity", "max_issues_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "coarse_to_fine_uface.f90", "max_forks_repo_name": "pratanuroy/Multigrid_Cavity", "max_forks_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.3928571429, "max_line_length": 99, "alphanum_fraction": 0.5518341308, "num_tokens": 655, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7585398092741388}} {"text": "! POUR EXECUTER SUR http://tpcg.io/5QC2CL, ENLEVER '-std=f95' DANS PROJECT->COMPILE OPTIONS\n\nprogram newton\n use, intrinsic :: iso_fortran_env, only: real128\n implicit none\n\n integer, parameter :: wp = real128\n real(wp) :: a, f, z\n integer :: it, itmax\n real(wp) :: gn, dgn, xn, tol\n real(wp) :: best\n \n write(*,*) '[INFO] Programme pour résoudre par Newton f = a cosh(phi z) / cosh(phi), inconnue phi, le module de Thiele'\n write(*,*) \" On reformule le problème : on cherche le zero de la fonction\"\n write(*,*) \" g(phi) = phi - acosh( a / f * cosh(phi z) )\"\n write(*,*)\n write(*,*) \"[INFO] Fournir depuis STDIN les valeurs numériques\"\n write(*,*) \" a Épaisseur du dépôt en micron à l'entrée du pore\"\n write(*,*) \" f Épaisseur du dépôt en micron en z\"\n write(*,*) \" z Distance relative entre l'entrée (z=1) et le milieu (z=0) du pore\"\n write(*,*) \" tol Tolérance: on accepte phi si g(phi) < tol. Mettre 1E-3 si inconnu \"\n write(*,*) \" itmax Nombre maximal d'itérations. Mettre 100 si inconnu. \"\n write(*,*) \" phi0 Estimation grossière du module pour démarrer l'algo. Mettre 1 si inconnu.\"\n write(*,*)\n \n read(*,*) a\n if (a.lt.0.) then\n write(*,*) \"[FAIL] a doit être positif\"\n error stop\n end if\n read(*,*) f\n if (f.lt.0.) then\n write(*,*) \"[FAIL] f doit être positif\"\n error stop\n end if\n read(*,*) z\n if ((z.lt.0.).or.(z.gt.1.)) then\n write(*,*) \"[FAIL] z doit être compris entre 0 et 1\"\n error stop\n end if\n read(*,*) tol\n read(*,*) itmax\n read(*,*) xn\n\n it = 0\n best = xn\n gn = g(xn,a,f,z)\n dgn = dg(xn,a,f,z)\n\n write(*,*) \"[INFO] Lancement de l'algorithme pour \"\n write(*,'(7x,*(a16,1x))') 'a','f','z'\n write(*,'(7x,*(es16.9,1x))') a, f, z\n write(*,*) \" ...\"\n do while ((abs(gn).gt.abs(tol)).and.(it.lt.itmax))\n gn = g(xn,a,f,z)\n dgn = dg(xn,a,f,z)\n if (abs(gn).lt.abs(g(best,a,f,z))) then\n best = xn\n end if\n ! write(*,'(i16,1x,3(es16.9,1x))') it, xn, gn, dgn\n xn = xn - gn/dgn\n it = it + 1\n end do\n if (it.lt.itmax) then\n write(*,*) \"[OK] L'algorithme a trouvé un zéro à la tolérance demandée.\"\n else\n write(*,*) \"[FAIL] L'algorithme n'a pas fini dans le nombre maximal d'itérations autorisées.\"\n write(*,*) \" Peut être faut-il plus d'itérations ou une tolérance plus grande.\"\n write(*,*) \" Néanmoins, le meilleur phi était\"\n end if\n write(*, '(1x,*(a,es12.5))') \"phi = \", best, ', g(phi) = ',g(best,a,f,z)\n \ncontains\n\npure function g(phi,a,f,z)\n real(wp) :: g\n real(wp),intent(in) :: phi,a,f,z\n g = phi - acosh(a/f*cosh(phi*z))\nend function\n\npure function dg(phi,a,f,z)\n real(wp) :: dg\n real(wp),intent(in) :: phi,a,f,z\n dg = 1._wp - (a*z*sinh(phi*z))/(f*sqrt((a*cosh(phi*z))/f - 1._wp)*sqrt((a*cosh(phi*z))/f + 1._wp))\nend function\nend program", "meta": {"hexsha": "a68abc2fd07b47d984db75f204632854ec60c13c", "size": 2997, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "newton.f03", "max_stars_repo_name": "pirpyn/module_thiele", "max_stars_repo_head_hexsha": "7fc860e23d4832d1eadfd8fe0411ce3bebd0996f", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "newton.f03", "max_issues_repo_name": "pirpyn/module_thiele", "max_issues_repo_head_hexsha": "7fc860e23d4832d1eadfd8fe0411ce3bebd0996f", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "newton.f03", "max_forks_repo_name": "pirpyn/module_thiele", "max_forks_repo_head_hexsha": "7fc860e23d4832d1eadfd8fe0411ce3bebd0996f", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.8488372093, "max_line_length": 123, "alphanum_fraction": 0.5455455455, "num_tokens": 1059, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582497090321, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.7585397867945988}} {"text": "module Stationary\n\ncontains\n\n ! Accepts row-major triple format\n \n subroutine sym_gauss_seidel(irows,icols,vals,b,N,NNZ,x, N_ITER)\n integer, intent(in) :: N, NNZ\n integer, intent(in), dimension(NNZ) :: irows, icols\n real(kind=8), intent(in), dimension(NNZ) :: vals\n real(kind=8), intent(in), dimension(N) :: b\n real(kind=8), intent(out), dimension(N) :: x\n integer,intent(in) :: N_ITER\n \n integer :: i,k\n real(kind=8) :: diag\n\n x = 0.0\n \n do it=1,n_iter\n\n ! Forward iteration\n k=1\n do i=1,N\n ! calculate x[i]\n x(i) = b(i)\n do while (k<=NNZ .AND. irows(k)==i)\n j=icols(k) ! column index\n if (i==j) then\n diag = vals(k) ! diagonal\n else\n x(i) = x(i) - x(j)*vals(k)\n end if\n k = k+1\n end do\n x(i) = x(i) / diag\n end do\n\n ! Backward iteration\n k=NNZ\n do i=N,1,-1\n ! calculate x[i]\n x(i) = b(i)\n do while (k>0 .AND. irows(k)==i)\n j=icols(k) ! column index\n if (i==j) then\n diag = vals(k) ! diagonal\n else\n x(i) = x(i) - x(j)*vals(k)\n end if\n k = k-1\n end do\n x(i) = x(i) / diag\n end do\n\n end do\n \n end subroutine sym_gauss_seidel\n\n ! Accepts row-major triple format\n ! Irows and icols can start with values 0\n ! This was modified by me\n \n subroutine sym_gauss_seidel_zero(irows,icols,vals,b,N,NNZ,x, N_ITER)\n integer, intent(in) :: N, NNZ\n integer, intent(in), dimension(NNZ) :: irows, icols\n real(kind=8), intent(in), dimension(NNZ) :: vals\n real(kind=8), intent(in), dimension(N) :: b\n real(kind=8), intent(out), dimension(N) :: x\n integer,intent(in) :: N_ITER\n \n integer :: i,k\n real(kind=8) :: diag\n\n x = 0.0\n \n do it=1,n_iter\n\n ! Forward iteration\n k=1\n do i=1,N\n ! calculate x[i]\n x(i) = b(i)\n do while (k<=NNZ .AND. irows(k)==i-1) ! see SGSFortranPreconditioner\n j=icols(k)+1 ! column index, see SGSFortranPreconditioner\n if (i==j) then\n diag = vals(k) ! diagonal\n else\n x(i) = x(i) - x(j)*vals(k)\n end if\n k = k+1\n end do\n x(i) = x(i) / diag\n end do\n\n ! Backward iteration\n k=NNZ\n do i=N,1,-1\n ! calculate x[i]\n x(i) = b(i)\n do while (k>0 .AND. irows(k)==i-1) ! see SGSFortranPreconditioner\n j=icols(k)+1 ! column index, see SGSFortranPreconditioner\n if (i==j) then\n diag = vals(k) ! diagonal\n else\n x(i) = x(i) - x(j)*vals(k)\n end if\n k = k-1\n end do\n x(i) = x(i) / diag\n end do\n\n end do\n \n end subroutine sym_gauss_seidel_zero\n \n ! Uses 0-based indexing\n ! Suggested by user thrope in freenode\n \n subroutine sym_gauss_seidel_thrope(irows,icols,vals,b,N,NNZ,x, N_ITER)\n integer, intent(in) :: N, NNZ\n integer, intent(in), dimension(0:NNZ-1) :: irows, icols\n real(kind=8), intent(in), dimension(0:NNZ-1) :: vals\n real(kind=8), intent(in), dimension(0:N-1) :: b\n real(kind=8), intent(out), dimension(0:N-1) :: x\n integer,intent(in) :: N_ITER\n \n integer :: i,k\n real(kind=8) :: diag\n\n x = 0.0\n \n do it=1,n_iter\n\n ! Forward iteration\n k=0\n do i=0,N-1\n ! calculate x[i]\n x(i) = b(i)\n do while (k=0 .AND. irows(k)==i)\n j=icols(k) ! column index\n if (i==j) then\n diag = vals(k) ! diagonal\n else\n x(i) = x(i) - x(j)*vals(k)\n end if\n k = k-1\n end do\n x(i) = x(i) / diag\n end do\n\n end do\n \n end subroutine sym_gauss_seidel_thrope\nend module Stationary\n", "meta": {"hexsha": "2925bf5d759bf864b27ac2f795e9924d31fb5d7f", "size": 4413, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "2009/scientific-computing/project1/src/stationary.f90", "max_stars_repo_name": "rla/old-code", "max_stars_repo_head_hexsha": "06aa69c3adef8434992410687d466dc42779e57b", "max_stars_repo_licenses": ["Ruby", "MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2015-11-08T10:01:47.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-10T00:00:58.000Z", "max_issues_repo_path": "2009/scientific-computing/project1/src/stationary.f90", "max_issues_repo_name": "rla/old-code", "max_issues_repo_head_hexsha": "06aa69c3adef8434992410687d466dc42779e57b", "max_issues_repo_licenses": ["Ruby", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2009/scientific-computing/project1/src/stationary.f90", "max_forks_repo_name": "rla/old-code", "max_forks_repo_head_hexsha": "06aa69c3adef8434992410687d466dc42779e57b", "max_forks_repo_licenses": ["Ruby", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.5086705202, "max_line_length": 78, "alphanum_fraction": 0.4702016769, "num_tokens": 1370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7585268227363681}} {"text": "PROGRAM BESSEL\n USE INTERPOLATION \n\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: N = 10, NGRID = 90\n\n REAL, DIMENSION(N) :: t, J0, J1, J2\n REAL, DIMENSION(NGRID + 1) :: x, Lx, S3\n\n INTEGER :: i\n REAL :: dgrid \n\n ! (t, y) for interpolation \n t = [ ( REAL(i), i = 1, N ) ]\n J0 = BESSEL_J0(t)\n J1 = BESSEL_J1(t)\n J2 = BESSEL_JN(2, t) \n\n ! 1d grid \n dgrid = (t(N) - t(1)) / NGRID\n x = [ ( t(1) + dgrid * i , i = 0, NGRID ) ]\n\n ! Lagrange interpolation\n ! N poly requires N+1 (x, f(x)) pair\n Lx = LAGRANGE_INTERPOLATION(x, t(4:7), J1(4:7))\n\n ! cubic spline interpolation\n S3 = CUBIC_SPLINE_INTERPOLATION(x, t, J1)\n\n ! debug \n DO i = 1, NGRID+1\n PRINT 1000, x(i), BESSEL_J1(x(i)), Lx(i), S3(i)\n 1000 FORMAT (4F13.6)\n END DO \n\nCONTAINS \n\nSUBROUTINE PRINT_TABLE\n IMPLICIT NONE \n\n INTEGER :: i \n \n DO i = 1, N\n PRINT 1000, i, J0(i), J1(i), J2(i)\n END DO \n\n 1000 FORMAT (I3, (3F13.6))\nEND SUBROUTINE Print_Table\n\nEND PROGRAM BESSEL\n", "meta": {"hexsha": "556560a3d70c872a0746d7674bc5c7817d384db9", "size": 1105, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "drivers/bessel.f90", "max_stars_repo_name": "vitduck/numerical-recipe", "max_stars_repo_head_hexsha": "0d025bd6c9a5b45af72c7691fb01cbfecf075ca6", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "drivers/bessel.f90", "max_issues_repo_name": "vitduck/numerical-recipe", "max_issues_repo_head_hexsha": "0d025bd6c9a5b45af72c7691fb01cbfecf075ca6", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "drivers/bessel.f90", "max_forks_repo_name": "vitduck/numerical-recipe", "max_forks_repo_head_hexsha": "0d025bd6c9a5b45af72c7691fb01cbfecf075ca6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.25, "max_line_length": 55, "alphanum_fraction": 0.5049773756, "num_tokens": 412, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942144788077, "lm_q2_score": 0.8519528076067261, "lm_q1q2_score": 0.758488655621245}} {"text": "program pi_openmp\n\n use ISO_FORTRAN_ENV\n\n implicit none\n \n double precision :: step, x, s, mypi, start, stop, omp_get_wtime\n integer(kind=int64) :: num_steps, i\n character(len=:), allocatable :: a\n integer, external :: omp_get_max_threads\n integer :: argl\n\n num_steps = 1000000000\n\n! Get command line args (Fortran 2003 standard)\n if (command_argument_count() > 0) then\n call get_command_argument(1, length=argl)\n allocate(character(argl) :: a)\n call get_command_argument(1, a)\n read(a,*) num_steps\n end if\n\n! Output start message\n\n write(*,'(A)') \"Calculating PI using:\"\n write(*,'(A,1I16,A)') \" \",num_steps, \" slices\"\n write(*,'(A,1I16,A)') \" \",omp_get_max_threads(),\" OpenMP threads\"\n\n! Initialise time counter and sum: set step size\n\n start = omp_get_wtime()\n s = 0d0\n step = 1.0d0 / num_steps\n\n! Specify that the loop be parallelised, with summation of individual\n! threads' s values to yield overall sum. Specify that the variable\n! x is local to each thread.\n\n!$OMP PARALLEL \n!$OMP DO PRIVATE(x) REDUCTION(+:s)\n do i = 1, num_steps\n x = (i - 0.5d0) * step\n s = s + 4.0d0 / (1.0d0 + x*x)\n end do\n!$OMP ENDDO\n!$OMP END PARALLEL\n\n! Evaluate PI from the final sum value, and stop the clock\n\n mypi = s * step\n stop = omp_get_wtime()\n\n! output value of PI and time taken\n\n write(*,'(A,1F12.10,A)') \"Obtained value of PI: \", mypi\n write(*,'(A,1F12.5,A)') \"Time taken: \",(stop-start), \" seconds\"\n\nend program pi_openmp\n\n", "meta": {"hexsha": "4b695e636d527be5e8025659dbe5e35e3a27a30f", "size": 1565, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran_omp_pi_dir/pi.f90", "max_stars_repo_name": "adrianjhpc/pi_examples", "max_stars_repo_head_hexsha": "ba624038a865e194b361d783a0e8647f2a9bb376", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2016-04-13T11:39:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T19:22:06.000Z", "max_issues_repo_path": "fortran_omp_pi_dir/pi.f90", "max_issues_repo_name": "adrianjhpc/pi_examples", "max_issues_repo_head_hexsha": "ba624038a865e194b361d783a0e8647f2a9bb376", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2016-05-24T11:28:57.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T16:22:17.000Z", "max_forks_repo_path": "fortran_omp_pi_dir/pi.f90", "max_forks_repo_name": "adrianjhpc/pi_examples", "max_forks_repo_head_hexsha": "ba624038a865e194b361d783a0e8647f2a9bb376", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2017-10-12T15:08:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-25T09:35:21.000Z", "avg_line_length": 26.0833333333, "max_line_length": 84, "alphanum_fraction": 0.6242811502, "num_tokens": 490, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942144788076, "lm_q2_score": 0.8519528019683105, "lm_q1q2_score": 0.7584886506013961}} {"text": "program example\n ! Example 10.3 from NMUM/Mathews.\n ! Integrate the 1D heat equation forward in time given simple initial\n ! conditions. This is a simple example of how to use Fortran90. There\n ! are better ways to code this problem...\n\n ! Begin the declaration section.\n ! ALWAYS start with implicit none.\n implicit none\n\n ! Declare some variables. Set intital values on some.\n ! Note that xLim is a 2-element vector.\n real :: dt=0.02, dx=0.2, tLimit=0.2, xLim(2)=(/0,1/)\n real :: r\n integer :: nX, nT, i, j\n logical :: DoTest = .true. \n\n ! Create character variables. We must declare their size.\n character(len=23) :: fmt1\n character(len=17) :: fmt2\n\n ! Domain array. We don't know the size yet because we need to\n ! calculate that. So let's make them \"allocatable.\"\n real, allocatable :: Domain_II(:,:), xGrid(:)\n\n ! Constants. Make them \"parameters\" that cannot be changed.\n integer, parameter :: iUnitFile=10\n real, parameter :: cDiffusion = 1.0\n\n ! Now, begin execution section.\n !---------------------------------------------------------------------\n ! Write a message to Standard Out with no defined format:\n write(*,*) \"Setting up simulation...\"\n\n ! Calculate the number of points in X and in time.\n ! Ceiling rounds up and returns an integer, which matches the data\n ! type of \"ceiling\". Without ceiling, our value would be a \"real\" type,\n ! which may be rounded up, down, or truncated (compiler dependent).\n nX = ceiling( (xLim(2)-xLim(1))/dx ) + 1\n nT = ceiling( tLimit/dt ) + 1\n\n ! If logical DoTest is .true., produce extra information to screen.\n if(DoTest)write(*,*) ' Grid size (nX, nT) = ', nX, nT\n \n ! Allocate arrays now that we know their size.\n ! Remember: if we do not de-allocate, it's possible to create a mem leak.\n allocate(Domain_II(nX, nT))\n allocate(xGrid(nX))\n \n !It's usually a good idea to fill matrices with zeros.\n Domain_II = 0 \n xGrid = 0\n\n ! Set the grid values and initial conditions:\n do i=1, nX\n xGrid(i) = (i-1) * dx\n Domain_II(i,1) = 4.0*xGrid(i) - 4.0*xGrid(i)**2.0\n end do\n \n ! Check stability as described in class.\n ! \"if () then\" means >1 line after if statement.\n if ( dt > (dx**2.0 / (2.0*cDiffusion**2.0)) ) then \n write(*,*) 'ERROR! WE ARE NOT STABLE!'\n stop ! Remember, fortran's stop is not good for parallel programming.\n end if\n\n ! integrate. See notes from class on the meaning below.\n write(*,*) 'Integrating...'\n r = cDiffusion**2.0 * dt / dx**2.0\n ! Loop from time 0 (j=1) to time t_final-deltaT.\n do j=1, nT-1\n Domain_II(2:nX-1, j+1) = (1.0 - 2.0*r) * Domain_II(2:nX-1, j) + &\n r*(Domain_II(1:nx-2,j) + Domain_II(3:nx, j))\n end do\n\n ! Now we want to write our results to file.\n write(*,*) 'Saving results to file.'\n \n ! Start by opening file in replace mode (over write existing file).\n ! Assign it to a file unit, iUnitFile.\n open(iUnitFile, file='results.txt', status='replace')\n\n ! Write a header line. Our write statement now writes to our\n ! file unit and not \"*\" for standard out. We also use format codes\n ! in place of our 2nd \"*\".\n write(iUnitFile, '(a)') 'Example 10.3 Results.'\n\n ! Write information about domain. Note the format code that fills in\n ! brackets, commas, etc. \n write(iUnitFile, \"(a,'[',f3.0,',',f4.0,'] ',a,f5.1,a)\") &\n 'Domain: x=',xLim, 't=[0.0,',tLimit,']'\n write(iUnitFile, \"(a, i5.5, 'x',i5.5)\") 'Domain size (x, Time) = ', nX, nT\n\n ! Our next format code depends on the size of our domain, which\n ! we won't know until run time. So, we'll write the format code\n ! to a character variable of the right size:\n write(fmt1, \"(a, i6.6, a)\") '(a13,', nX, '(1x, E12.6))'\n if(doTest) write(*,*) 'fmt1 = ', fmt1\n ! Write grid to file:\n write(iUnitFile, fmt1) 'Grid:', xGrid\n\n ! Create format code for time and result lines:\n write(fmt2, \"(a, i4.4,a)\") '(', nX+1, '(1x, E12.6))'\n if(doTest) write(*,*) 'fmt2 = ', fmt2\n ! Loop over results and write to file.\n do j=1, nT\n write(iUnitFile, fmt2) (j-1)*dt, Domain_II(:,j)\n end do\n\n ! Close our file:\n close(iUnitFile)\n\n !Deallocate arrays. ALWAYS DO THIS FOR ALLOCATABLE ARRAYS!\n deallocate(Domain_II)\n deallocate(xGrid)\n\n ! And that's it.\nend program example\n", "meta": {"hexsha": "ea54c4e124a3538dddcd0d8f6837c46240c98604", "size": 4268, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran90/HeatSimple/heateq_simple.f90", "max_stars_repo_name": "spacecataz/sciprog_teaching", "max_stars_repo_head_hexsha": "ebaacdb0b7ff9d3e29568a427f8d6078fcf439b5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fortran90/HeatSimple/heateq_simple.f90", "max_issues_repo_name": "spacecataz/sciprog_teaching", "max_issues_repo_head_hexsha": "ebaacdb0b7ff9d3e29568a427f8d6078fcf439b5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran90/HeatSimple/heateq_simple.f90", "max_forks_repo_name": "spacecataz/sciprog_teaching", "max_forks_repo_head_hexsha": "ebaacdb0b7ff9d3e29568a427f8d6078fcf439b5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-01T02:31:54.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T02:31:54.000Z", "avg_line_length": 35.8655462185, "max_line_length": 76, "alphanum_fraction": 0.6305060918, "num_tokens": 1384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072387, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7583449311499036}} {"text": "PROGRAM PROBS\n\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: trials = 1000000\n INTEGER :: i, j, probcount(8) = 0\n REAL :: expected(8), mapping(8), rnum\n CHARACTER(6) :: items(8) = (/ \"aleph \", \"beth \", \"gimel \", \"daleth\", \"he \", \"waw \", \"zayin \", \"heth \" /)\n\n expected(1:7) = (/ (1.0/i, i=5,11) /)\n expected(8) = 1.0 - SUM(expected(1:7))\n mapping(1) = 1.0 / 5.0\n DO i = 2, 7\n mapping(i) = mapping(i-1) + 1.0/(i+4.0)\n END DO\n mapping(8) = 1.0\n\n DO i = 1, trials\n CALL RANDOM_NUMBER(rnum)\n DO j = 1, 8\n IF (rnum < mapping(j)) THEN\n probcount(j) = probcount(j) + 1\n EXIT\n END IF\n END DO\n END DO\n\n WRITE(*, \"(A,I10)\") \"Trials: \", trials\n WRITE(*, \"(A,8A10)\") \"Items: \", items\n WRITE(*, \"(A,8F10.6)\") \"Target Probability: \", expected\n WRITE(*, \"(A,8F10.6)\") \"Attained Probability:\", REAL(probcount) / REAL(trials)\n\nENDPROGRAM PROBS\n", "meta": {"hexsha": "a809d3875bf03bd9de412d6bcbaa51a020ebec3d", "size": 919, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Probabilistic-choice/Fortran/probabilistic-choice.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Probabilistic-choice/Fortran/probabilistic-choice.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Probabilistic-choice/Fortran/probabilistic-choice.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 27.0294117647, "max_line_length": 113, "alphanum_fraction": 0.5244831338, "num_tokens": 360, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768651485396, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7583381149895514}} {"text": "! Subroutine MAXT\n!\n! This software is part of the glow model. Use is governed by the open source\n! academic research license agreement contained in the file glowlicense.txt.\n! For more information see the file glow.txt.\n!\n! Stan Solomon, 11/1989, 9/1991, 1/1994, 3/2005\n! Refactored to f90, 6/6/6/6/6/6/2016\n!\n! Generates Maxwellian electron spectra with, optionally, a low energy tail\n! of the form used by Meier et al., JGR 94, 13541, 1989.\n! Also can generate a monoenergetic flux in a single bin.\n!\n! Supplied by calling routine:\n! eflux total energy flux in erg cm-2 s-1\n! ezer characteristic energy in ev\n! ener energy grid in ev\n! del energy bin width in ev\n! nbins number of energy bins (dimension of ener, del, and phi)\n! itail 1 = maxwellian with low-energy tail, 0 = regular maxwellian\n! fmono additional monoenergetic energy flux in erg cm-2 s-1\n! emono characteristic enerngy of fmono in ev\n!\n! Returned by subroutine:\n! phi hemispherical flux in cm-2 s-1 ev-1\n\n\n subroutine maxt (eflux,ezer,ener,del,nbins,itail,fmono,emono,phi)\n\n implicit none\n\n integer,intent(in) :: nbins, itail\n real,intent(in) :: eflux, ezer, ener(nbins), del(nbins), fmono, emono\n real,intent(out) :: phi(nbins)\n\n integer :: k\n real :: te, b, phimax, erat\n\n te = 0.\n\n if (ezer < 500.) then\n b = 0.8*ezer\n else\n b = 0.1*ezer + 350.\n endif\n\n phimax = exp(-1.)\n\n do k=1,nbins\n erat = ener(k) / ezer\n if (erat > 60.) erat = 60.\n phi(k) = erat * exp(-erat)\n if (itail > 0) phi(k) = phi(k) + 0.4*phimax*(ezer/ener(k))*exp(-ener(k)/b)\n te = te + phi(k) * del(k) * ener(k) * 1.6022e-12\n enddo\n\n do k=1,nbins\n phi(k) = phi(k) * eflux / te\n enddo\n\n if (fmono > 0.) then\n do k=1,nbins\n if (emono > ener(k)-del(k)/2. .and. emono < ener(k)+del(k)/2.) &\n phi(k)=phi(k)+fmono/(1.6022e-12*del(k)*ener(k))\n enddo\n endif\n\n return\n\n end subroutine maxt\n", "meta": {"hexsha": "00960a88c387ad10683a2eabfdd4baa8ce9956e0", "size": 1996, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ncarglow/fortran/maxt.f90", "max_stars_repo_name": "scivision/NCAR-GLOW", "max_stars_repo_head_hexsha": "09cfd372ec6f87c24f0a5c2d63f916166c1c98fa", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-06-06T15:13:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-16T08:50:52.000Z", "max_issues_repo_path": "src/ncarglow/fortran/maxt.f90", "max_issues_repo_name": "space-physics/NCAR-GLOW", "max_issues_repo_head_hexsha": "09cfd372ec6f87c24f0a5c2d63f916166c1c98fa", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-09-29T17:03:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-14T15:38:15.000Z", "max_forks_repo_path": "src/ncarglow/fortran/maxt.f90", "max_forks_repo_name": "scivision/NCAR-GLOW", "max_forks_repo_head_hexsha": "09cfd372ec6f87c24f0a5c2d63f916166c1c98fa", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-03-01T16:24:45.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-22T19:37:48.000Z", "avg_line_length": 28.1126760563, "max_line_length": 80, "alphanum_fraction": 0.619238477, "num_tokens": 694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653856, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7583381143914055}} {"text": "subroutine extrapolate(neq, tin, tout, yin, yout)\r\n implicit none\r\n\r\n integer, intent(in) :: neq\r\n integer :: i, k, nrich, nsteps\r\n double precision :: yout(neq), bot\r\n double precision, intent(in) :: tin, tout, yin(neq)\r\n double precision, allocatable, dimension(:, :, :) :: table\r\n\r\n nrich = 10\r\n nsteps = 1\r\n allocate(table(0:nrich, 0:nrich, neq))\r\n\r\n do i = 0, nrich\r\n call euler(neq, tin, tout, nsteps, yin, yout)\r\n table(i,0,:) = yout\r\n nsteps = (nsteps * 2)\r\n end do\r\n\r\n do k = 1, nrich\r\n bot = (2.0d0**k - 1.0d0)\r\n do i = k, nrich\r\n table(i,k,:) = (table(i,k-1,:) + (table(i,k-1,:) - table(i-1,k-1,:)) / bot)\r\n end do\r\n end do\r\n\r\n yout = table(nrich, nrich, :)\r\n return\r\nend\r\n", "meta": {"hexsha": "d2c4a3577c9c6fed18b454b18329384d7dc69009", "size": 722, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "4670 Numerical Analysis/HomeworkG/extrapolate.f90", "max_stars_repo_name": "mwebber3/UnderGraduateCourses", "max_stars_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4670 Numerical Analysis/HomeworkG/extrapolate.f90", "max_issues_repo_name": "mwebber3/UnderGraduateCourses", "max_issues_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4670 Numerical Analysis/HomeworkG/extrapolate.f90", "max_forks_repo_name": "mwebber3/UnderGraduateCourses", "max_forks_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0666666667, "max_line_length": 82, "alphanum_fraction": 0.5595567867, "num_tokens": 268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.8577681013541613, "lm_q1q2_score": 0.7583006962257914}} {"text": "module substitution\n use precision\n use, intrinsic :: iso_fortran_env\n implicit none\n contains\n subroutine forward_subs(L, n, b, ierr)\n integer, intent(in) :: n\n real(DP), intent(in) :: L(n,n)\n real(DP), intent(inout) :: b(n)\n integer, intent(out) :: ierr\n integer :: j \n! write(OUTPUT_UNIT,*) L\n! write(OUTPUT_UNIT,*) L(1,1), L(2,2), L(3,3)\n do j=1,n-1\n if (L(j,j).eq.0d0) goto 911\n b(j)=b(j)/L(j,j)\n b(j+1:n)=b(j+1:n)-b(j)*L(j+1:n,j)\n end do\n b(n)=b(n)/L(n,n)\n return\n911 continue\n ierr = -1\n return\n end subroutine forward_subs\n\n subroutine backward_subs(U, n, b, ierr)\n integer, intent(in) :: n\n real(DP), intent(in) :: U(n,n)\n real(DP), intent(inout) :: b(n)\n integer, intent(out) :: ierr\n integer :: j \n\n do j=n,2,-1\n if (U(j,j).eq.0) goto 911\n b(j)=b(j)/U(j,j)\n b(1:j-1)=b(1:j-1)-b(j)*U(1:j-1,j)\n end do\n b(1)=b(1)/U(1,1)\n return\n911 continue\n ierr = -1\n return\n end subroutine backward_subs \nend module substitution\n", "meta": {"hexsha": "788e5317c41c65812bad97cdcaf2eec04533a7db", "size": 1182, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "HighPerformanceComputing/Homework3/substitution.f90", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HighPerformanceComputing/Homework3/substitution.f90", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HighPerformanceComputing/Homework3/substitution.f90", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.2666666667, "max_line_length": 52, "alphanum_fraction": 0.489001692, "num_tokens": 394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425399873764, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7582102600958348}} {"text": " program demo_acos\n use, intrinsic :: iso_fortran_env, only : real_kinds,real32,real64,real128\n implicit none\n real(kind=real64) :: x = 0.866_real64\n real(kind=real64),parameter :: D2R=acos(-1.0_real64)/180.0_real64\n write(*,*)'acos(',x,') is ', acos(x)\n write(*,*)'90 degrees is ', d2r*90.0_real64, ' radians'\n write(*,*)'180 degrees is ', d2r*180.0_real64, ' radians'\n write(*,*)'for reference &\n &PI= 3.14159265358979323846264338327950288419716939937510'\n end program demo_acos\n", "meta": {"hexsha": "1e8b8484eec324d639151553c7e477c403a32c61", "size": 591, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo_acos.f90", "max_stars_repo_name": "urbanjost/fortran-intrinsic-manpages", "max_stars_repo_head_hexsha": "672e0545bcbef3dd6c8169c8f6b8424dbb3f0880", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-06-30T07:29:39.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-10T07:36:25.000Z", "max_issues_repo_path": "example/demo_acos.f90", "max_issues_repo_name": "urbanjost/fortran-intrinsic-manpages", "max_issues_repo_head_hexsha": "672e0545bcbef3dd6c8169c8f6b8424dbb3f0880", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-10-07T21:29:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-07T00:19:52.000Z", "max_forks_repo_path": "example/demo_acos.f90", "max_forks_repo_name": "urbanjost/fortran-intrinsic-manpages", "max_forks_repo_head_hexsha": "672e0545bcbef3dd6c8169c8f6b8424dbb3f0880", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-10-08T00:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-08T00:41:17.000Z", "avg_line_length": 49.25, "max_line_length": 84, "alphanum_fraction": 0.5820642978, "num_tokens": 183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425399873763, "lm_q2_score": 0.8244619263765706, "lm_q1q2_score": 0.7582102600958346}} {"text": "!----------------------------------------------------------------------\n!Module: num_rec\n!---------------------------------------------------------------------\n!> Code to compute the regular and irregular Coulomb wave functions.\n!! See source code for detailed documentation\n!!\n!! @author A. R. Barnett\n!---------------------------------------------------------------------\nmodule coulombwf\n contains\n! C----------------------------------------------------------------------\n SUBROUTINE COUL90(X, ETA, XLMIN,LRANGE, FC,GC,FCP,GCP, KFN,IFAIL)\n! C----------------------------------------------------------------------\n! C\n! C COULOMB & BESSEL FUNCTION PROGRAM-- COUL90 -- USING STEED'S METHOD\n! C\n! C COUL90 RETURNS ARRAYS FC = F, GC = G, FCP = (D/DX) F, GCP = (D/DX) G\n! C FOR REAL X .GT. 0. ,REAL ETA (INCLUDING 0.), AND REAL XLMIN .GT.-1.\n! C FOR (LRANGE+1) INTEGER-SPACED LAMBDA VALUES.\n! C IT HENCE GIVES POSITIVE-ENERGY SOLUTIONS TO THE COULOMB SCHRODINGER\n! C EQUATION, TO THE KLEIN-GORDON EQUATION AND TO SUITABLE FORMS OF\n! C THE DIRAC EQUATION. BY SETTING ETA = 0.0 AND RENORMALISING\n! C SPHERICAL & CYLINDRICAL BESSEL FUNCTIONS ARE COMPUTED INSTEAD.\n! C----------------------------------------------------------------------\n! C CALLING VARIABLES; ALL REALS ARE DOUBLE PRECISION (REAL*8)\n! C\n! C X - REAL ARGUMENT FOR COULOMB FUNCTIONS > 0.0\n! C [ X > SQRT(ACCUR) : ACCUR IS TARGET ACCURACY 1.0D-14 ]\n! C ETA - REAL SOMMERFELD PARAMETER, UNRESTRICTED > = < 0.0\n! C XLMIN - REAL MINIMUM LAMBDA-VALUE (L-VALUE OR ORDER),\n! C GENERALLY IN RANGE 0.0 - 1.0 AND MOST USUALLY 0.0\n! C LRANGE - INTEGER NUMBER OF ADDITIONAL L-VALUES : RESULTS RETURNED\n! C FOR L-VALUES XLMIN TO XLMIN + LRANGE INCLUSIVE\n! C FC ,GC - REAL VECTORS F,G OF REGULAR, IRREGULAR COULOMB FUNCTIONS\n! C FCP,GCP - REAL VECTORS FOR THE X-DERIVATIVES OF F,G\n! C THESE VECTORS TO BE OF LENGTH AT LEAST MINL + LRANGE\n! C STARTING ELEMENT MINL = MAX0( IDINT(XLMIN+ACCUR),0 )\n! C KFN - INTEGER CHOICE OF FUNCTIONS TO BE COMPUTED :\n! C = 0 REAL COULOMB FUNCTIONS AND DERIVATIVES F & G\n! C = 1 SPHERICAL BESSEL \" \" \" j & y\n! C = 2 CYLINDRICAL BESSEL \" \" \" J & Y\n! C\n! C PRECISION: RESULTS TO WITHIN 2-3 DECIMALS OF \"MACHINE ACCURACY\"\n! C IN OSCILLATING REGION X .GE. [ETA + SQRT{ETA**2 + XLM*(XLM+1)}]\n! C I.E. THE TARGET ACCURACY ACCUR SHOULD BE 100 * ACC8 WHERE ACC8 IS\n! C THE SMALLEST NUMBER WITH 1.+ACC8.NE.1. FOR OUR WORKING PRECISION.\n! C THIS RANGES BETWEEN 4E-15 AND 2D-17 ON CRAY, VAX, SUN, PC FORTRANS\n! C SO CHOOSE A SENSIBLE ACCUR = 1.0D-14\n! C IF X IS SMALLER THAN [ ] ABOVE THE ACCURACY BECOMES STEADILY WORSE:\n! C THE VARIABLE PACCQ IN COMMON /STEED/ HAS AN ESTIMATE OF ACCURACY.\n! C----------------------------------------------------------------------\n! C ERROR RETURNS THE USER SHOULD TEST IFAIL ON EXIT\n! C\n! C IFAIL ON INPUT IS SET TO 0 LIMIT = 20000\n! C IFAIL IN OUTPUT = 0 : CALCULATIONS SATISFACTORY\n! C = 1 : CF1 DID NOT CONVERGE AFTER LIMIT ITERATIONS\n! C = 2 : CF2 DID NOT CONVERGE AFTER LIMIT ITERATIONS\n! C = -1 : X < 1D-7 = SQRT(ACCUR)\n! C = -2 : INCONSISTENCY IN ORDER VALUES (L-VALUES)\n! C----------------------------------------------------------------------\n! C MACHINE-DEPENDENT PARAMETERS: ACCUR - SEE ABOVE\n! C SMALL - OFFSET FOR RECURSION = APPROX SQRT(MIN REAL NO.)\n! C IE 1D-30 FOR IBM REAL*8, 1D-150 FOR DOUBLE PRECISION\n! C----------------------------------------------------------------------\n! C PROGRAMMING HISTORY AND BACKGROUND: CPC IS COMPUTER PHYSICS COMMUN.\n! C ORIGINAL PROGRAM RCWFN IN CPC 8 (1974) 377-395\n! C + RCWFF IN CPC 11 (1976) 141-142\n! C FULL DESCRIPTION OF ALGORITHM IN CPC 21 (1981) 297-314\n! C REVISED STANDARD COULFG IN CPC 27 (1982) 147-166\n! C BACKGROUND MATERIAL IN J. COMP. PHYSICS 46 (1982) 171-188\n! C CURRENT PROGRAM COUL90 (FORTRAN77) SUPERCEDES THESE EARLIER ONES\n! C (WHICH WERE WRITTEN IN FORTRAN 4) AND ALSO BY INCORPORATING THE NEW\n! C LENTZ-THOMPSON ALGORITHM FOR EVALUATING THE FIRST CONTINUED FRACTION\n! C ..SEE ALSO APPENDIX TO J. COMP. PHYSICS 64 (1986) 490-509 1.4.94\n! C----------------------------------------------------------------------\n! C AUTHOR: A. R. BARNETT MANCHESTER MARCH 1981/95\n! C AUCKLAND MARCH 1991\n! C----------------------------------------------------------------------\n IMPLICIT NONE\n INTEGER LRANGE, KFN, IFAIL\n DOUBLE PRECISION X, ETA, XLMIN\n DOUBLE PRECISION FC (0:*), GC (0:*), FCP(0:*), GCP(0:*)\n! C----- ARRAYS INDEXED FROM 0 INSIDE SUBROUTINE: STORAGE FROM MINL\n DOUBLE PRECISION ACCUR,ACCH,SMALL, ONE,ZERO,HALF,TWO,TEN2, RT2DPI\n DOUBLE PRECISION XINV,PK,CF1,C,D,PK1,ETAK,RK2,TK,DCF1,DEN,XLM,XLL\n DOUBLE PRECISION EL,XL,RL,SL, F,FCMAXL,FCMINL,GCMINL,OMEGA,WRONSK\n DOUBLE PRECISION WI, A,B, AR,AI,BR,BI,DR,DI,DP,DQ, ALPHA,BETA\n DOUBLE PRECISION E2MM1, FJWKB,GJWKB, P,Q,PACCQ, GAMMA,GAMMAI\n INTEGER IEXP, NFP, NPQ, L, MINL,MAXL, LIMIT\n LOGICAL ETANE0, XLTURN\n PARAMETER ( LIMIT = 20000, SMALL = 1.0D-150 )\n !COMMON /STEED/ PACCQ,NFP,NPQ,IEXP,MINL !not required in code\n !COMMON /DESET/ CF1,P,Q,F,GAMMA,WRONSK !information only\n! C----------------------------------------------------------------------\n! C COUL90 HAS CALLS TO: DSQRT,DABS,MAX0,IDINT,DSIGN,DFLOAT,DMIN1\n! C----------------------------------------------------------------------\n DATA ZERO,ONE,TWO,TEN2,HALF /0.0D0, 1.0D0, 2.0D0, 1.0D2, 0.5D0/\n DATA RT2DPI /0.797884560802865D0/\n! CQ DATA RT2DPI /0.79788 45608 02865 35587 98921 19868 76373 Q0/\n! C-----THIS CONSTANT IS DSQRT(TWO / PI):\n! C-----USE Q0 FOR IBM REAL*16: D0 FOR REAL*8 AND DOUBLE PRECISION\n! C----------------CHANGE ACCUR TO SUIT MACHINE AND PRECISION REQUIRED\n ACCUR = 1.0D-14\n IFAIL = 0\n IEXP = 1\n NPQ = 0\n GJWKB = ZERO\n PACCQ = ONE\n IF(KFN .NE. 0) ETA = ZERO\n ETANE0 = ETA .NE. ZERO\n ACCH = DSQRT(ACCUR)\n! C----- TEST RANGE OF X, EXIT IF.LE.DSQRT(ACCUR) OR IF NEGATIVE\n IF( X .LE. ACCH ) GO TO 100\n IF( KFN.EQ.2 ) THEN\n XLM = XLMIN - HALF\n ELSE\n XLM = XLMIN\n ENDIF\n IF( XLM.LE.-ONE .OR. LRANGE.LT.0 ) GO TO 105\n E2MM1 = XLM * XLM + XLM\n XLTURN = X * (X - TWO * ETA) .LT. E2MM1\n E2MM1 = E2MM1 + ETA * ETA\n XLL = XLM + FLOAT(LRANGE)\n! C----- LRANGE IS NUMBER OF ADDITIONAL LAMBDA VALUES TO BE COMPUTED\n! C----- XLL IS MAX LAMBDA VALUE [ OR 0.5 SMALLER FOR J,Y BESSELS ]\n! C----- DETERMINE STARTING ARRAY ELEMENT (MINL) FROM XLMIN\n MINL = MAX0( IDINT(XLMIN + ACCUR),0 ) ! index from 0\n MAXL = MINL + LRANGE\n! C----- EVALUATE CF1 = F = DF(L,ETA,X)/DX / F(L,ETA,X)\n XINV = ONE / X\n DEN = ONE ! unnormalised F(MAXL,ETA,X)\n PK = XLL + ONE\n CF1 = ETA / PK + PK * XINV\n IF( DABS(CF1).LT.SMALL ) CF1 = SMALL\n RK2 = ONE\n D = ZERO\n C = CF1\n! C----- BEGIN CF1 LOOP ON PK = K STARTING AT LAMBDA + 1: LENTZ-THOMPSON\n DO 10 L = 1 , LIMIT ! abort if reach LIMIT (20000)\n PK1 = PK + ONE\n IF( ETANE0 ) THEN\n ETAK = ETA / PK\n RK2 = ONE + ETAK * ETAK\n TK = (PK + PK1) * (XINV + ETAK / PK1)\n ELSE\n TK = (PK + PK1) * XINV\n ENDIF\n D = TK - RK2 * D ! direct ratio of B convergents\n C = TK - RK2 / C ! inverse ratio of A convergents\n IF( DABS(C).LT.SMALL ) C = SMALL\n IF( DABS(D).LT.SMALL ) D = SMALL\n D = ONE / D\n DCF1= D * C\n CF1 = CF1 * DCF1\n IF( D.LT.ZERO ) DEN = -DEN\n PK = PK1\n IF( DABS(DCF1-ONE).LT.ACCUR ) GO TO 20 ! proper exit\n 10 CONTINUE\n GO TO 110 ! error exit\n 20 NFP = INT(PK - XLL - 1) ! number of steps\n F = CF1 ! need DEN later\n! C----DOWNWARD RECURRENCE TO LAMBDA = XLM; ARRAYS GC, GCP STORE RL, SL\n IF( LRANGE.GT.0 ) THEN\n FCMAXL = SMALL * DEN\n FCP(MAXL) = FCMAXL * CF1\n FC (MAXL) = FCMAXL\n XL = XLL\n RL = ONE\n DO 30 L = MAXL, MINL+1, -1\n IF( ETANE0 ) THEN\n EL = ETA / XL\n RL = DSQRT( ONE + EL * EL )\n SL = XL * XINV + EL\n GC (L) = RL ! storage\n GCP(L) = SL\n ELSE\n SL = XL * XINV\n ENDIF\n FC (L-1) = ( FC(L) * SL + FCP(L) ) / RL\n FCP(L-1) = FC(L-1) * SL - FC (L) * RL\n XL = XL - ONE ! end value is XLM\n 30 CONTINUE\n IF( DABS(FC(MINL)).LT.ACCUR*SMALL ) FC(MINL) = ACCUR * SMALL\n F = FCP(MINL) / FC(MINL) ! F'/F at min L-value\n DEN = FC (MINL) ! normalisation\n ENDIF\n! C---------------------------------------------------------------------\n! C----- NOW WE HAVE REACHED LAMBDA = XLMIN = XLM\n! C----- EVALUATE CF2 = P + I.Q USING STEED'S ALGORITHM (NO ZEROS)\n! C---------------------------------------------------------------------\n IF( XLTURN ) CALL JWKB( X,ETA,DMAX1(XLM,ZERO),FJWKB,GJWKB,IEXP )\n IF( IEXP.GT.1 .OR. GJWKB.GT.(ONE / (ACCH*TEN2)) ) THEN\n OMEGA = FJWKB\n GAMMA = GJWKB * OMEGA\n P = F\n Q = ONE\n ELSE ! find cf2\n XLTURN = .FALSE.\n PK = ZERO\n WI = ETA + ETA\n P = ZERO\n Q = ONE - ETA * XINV\n AR = -E2MM1\n AI = ETA\n BR = TWO * (X - ETA)\n BI = TWO\n DR = BR / (BR * BR + BI * BI)\n DI = -BI / (BR * BR + BI * BI)\n DP = -XINV * (AR * DI + AI * DR)\n DQ = XINV * (AR * DR - AI * DI)\n DO 40 L = 1, LIMIT\n P = P + DP\n Q = Q + DQ\n PK = PK + TWO\n AR = AR + PK\n AI = AI + WI\n BI = BI + TWO\n D = AR * DR - AI * DI + BR\n DI = AI * DR + AR * DI + BI\n C = ONE / (D * D + DI * DI)\n DR = C * D\n DI = -C * DI\n A = BR * DR - BI * DI - ONE\n B = BI * DR + BR * DI\n C = DP * A - DQ * B\n DQ = DP * B + DQ * A\n DP = C\n IF( DABS(DP)+DABS(DQ).LT.(DABS(P)+DABS(Q)) * ACCUR ) GO TO 50\n 40 CONTINUE\n GO TO 120 ! error exit\n 50 NPQ = INT(PK / TWO) ! proper exit\n PACCQ = HALF * ACCUR / DMIN1( DABS(Q),ONE )\n IF( DABS(P).GT.DABS(Q) ) PACCQ = PACCQ * DABS(P)\n! C---------------------------------------------------------------------\n! C SOLVE FOR FCMINL = F AT LAMBDA = XLM AND NORMALISING FACTOR OMEGA\n! C---------------------------------------------------------------------\n GAMMA = (F - P) / Q\n GAMMAI = ONE / GAMMA\n IF( DABS(GAMMA) .LE. ONE ) THEN\n OMEGA = DSQRT( ONE + GAMMA * GAMMA )\n ELSE\n OMEGA = DSQRT( ONE + GAMMAI* GAMMAI) * DABS(GAMMA)\n ENDIF\n OMEGA = ONE / ( OMEGA * DSQRT(Q) )\n WRONSK = OMEGA\n ENDIF\n! C---------------------------------------------------------------------\n! C RENORMALISE IF SPHERICAL OR CYLINDRICAL BESSEL FUNCTIONS\n! C---------------------------------------------------------------------\n IF( KFN.EQ.1 ) THEN ! spherical Bessel functions\n ALPHA = XINV\n BETA = XINV\n ELSEIF( KFN.EQ.2 ) THEN ! cylindrical Bessel functions\n ALPHA = HALF * XINV\n BETA = DSQRT( XINV ) * RT2DPI\n ELSE ! kfn = 0, Coulomb functions\n ALPHA = ZERO\n BETA = ONE\n ENDIF\n FCMINL = DSIGN( OMEGA,DEN ) * BETA\n IF( XLTURN ) THEN\n GCMINL = GJWKB * BETA\n ELSE\n GCMINL = FCMINL * GAMMA\n ENDIF\n IF( KFN.NE.0 ) GCMINL = -GCMINL ! Bessel sign differs\n FC (MINL) = FCMINL\n GC (MINL) = GCMINL\n GCP(MINL) = GCMINL * (P - Q / GAMMA - ALPHA)\n FCP(MINL) = FCMINL * (F - ALPHA)\n IF( LRANGE.EQ.0 ) RETURN\n! C---------------------------------------------------------------------\n! C UPWARD RECURRENCE FROM GC(MINL),GCP(MINL) STORED VALUES ARE RL,SL\n! C RENORMALISE FC,FCP AT EACH LAMBDA AND CORRECT REGULAR DERIVATIVE\n! C XL = XLM HERE AND RL = ONE , EL = ZERO FOR BESSELS\n! C---------------------------------------------------------------------\n OMEGA = BETA * OMEGA / DABS(DEN)\n XL = XLM\n RL = ONE\n DO 60 L = MINL+1 , MAXL ! indexed from 0\n XL = XL + ONE\n IF( ETANE0 ) THEN\n RL = GC (L)\n SL = GCP(L)\n ELSE\n SL = XL * XINV\n ENDIF\n GC (L) = ( (SL - ALPHA) * GC(L-1) - GCP(L-1) ) / RL\n GCP(L) = RL * GC(L-1) - (SL + ALPHA) * GC(L)\n FCP(L) = OMEGA * ( FCP(L) - ALPHA * FC(L) )\n FC (L) = OMEGA * FC (L)\n 60 CONTINUE\n RETURN\n! C------------------ ERROR MESSAGES\n 100 IFAIL = -1\n WRITE(6,1000) X,ACCH\n 1000 FORMAT(' FOR X = ',1PD12.3,' TRY SMALL-X SOLUTIONS,'&\n ' OR X IS NEGATIVE'/ ,' SQUARE ROOT (ACCURACY) = ',D12.3/)\n RETURN\n 105 IFAIL = -2\n WRITE (6,1005) LRANGE,XLMIN,XLM\n 1005 FORMAT(/' PROBLEM WITH INPUT ORDER VALUES: LRANGE, XLMIN, XLM = ',&\n I10,1P2D15.6/)\n RETURN\n 110 IFAIL = 1\n WRITE (6,1010) LIMIT, CF1,DCF1, PK,ACCUR\n 1010 FORMAT(' CF1 HAS FAILED TO CONVERGE AFTER ',I10,' ITERATIONS',/&\n ' CF1,DCF1,PK,ACCUR = ',1P4D12.3/)\n RETURN\n 120 IFAIL = 2\n WRITE (6,1020) LIMIT,P,Q,DP,DQ,ACCUR\n 1020 FORMAT(' CF2 HAS FAILED TO CONVERGE AFTER ',I7,' ITERATIONS',/&\n ' P,Q,DP,DQ,ACCUR = ',1P4D17.7,D12.3/)\n RETURN\n END SUBROUTINE COUL90\n! C---------------------------------------------------------------------\n SUBROUTINE JWKB (X,ETA,XL, FJWKB,GJWKB, IEXP)\n DOUBLE PRECISION X,ETA,XL, FJWKB,GJWKB, DZERO\n! C----------------------------------------------------------------------\n! C-----COMPUTES JWKB APPROXIMATIONS TO COULOMB FUNCTIONS FOR XL .GE. 0.\n! C-----AS MODIFIED BY BIEDENHARN ET AL. PHYS REV 97 (1955) 542-554\n! C-----CALCULATED IN SINGLE, RETURNED IN DOUBLE PRECISION VARIABLES\n! C-----CALLS DMAX1, SQRT, ALOG, EXP, ATAN2, FLOAT, INT\n! C AUTHOR: A.R.BARNETT FEB 1981 LAST UPDATE MARCH 1991\n! C----------------------------------------------------------------------\n DOUBLE PRECISION ZERO,HALF,ONE,SIX,TEN,RL35,ALOGE\n DOUBLE PRECISION GH2,XLL1,HLL,HL,SL,RL2,GH,PHI,PHI10\n INTEGER IEXP, MAXEXP\n PARAMETER ( MAXEXP = 300 )\n DATA ZERO,HALF,ONE,SIX,TEN /0.0E0, 0.5E0, 1.0E0, 6.0E0, 1.0E1/\n DATA DZERO,RL35,ALOGE /0.0D0, 35.0E0, 0.4342945E0 /\n! C----------------------------------------------------------------------\n! CHOOSE MAXEXP NEAR MAX EXPONENT RANGE E.G. 1.D300 FOR DOUBLE PRECISION\n! C----------------------------------------------------------------------\n GH2 = X * (ETA + ETA - X)\n XLL1 = DMAX1( XL * XL + XL, DZERO )\n IF( GH2 + XLL1 .LE. ZERO ) RETURN\n HLL = XLL1 + SIX / RL35\n HL = SQRT(HLL)\n SL = ETA / HL + HL / X\n RL2 = ONE + ETA * ETA / HLL\n GH = SQRT(GH2 + HLL) / X\n PHI = X*GH - HALF*( HL*LOG((GH + SL)**2 / RL2) - LOG(GH) )\n IF ( ETA.NE.ZERO ) PHI = PHI - ETA * ATAN2(X*GH,X - ETA)\n PHI10 = -PHI * ALOGE\n IEXP = INT(PHI10)\n IF ( IEXP.GT.MAXEXP ) THEN\n GJWKB = TEN**(PHI10 - FLOAT(IEXP))\n ELSE\n GJWKB = EXP(-PHI)\n IEXP = 0\n ENDIF\n FJWKB = HALF / (GH * GJWKB)\n RETURN\n END SUBROUTINE JWKB\n! C---------------------------------------------------------------------\n! C END OF CONTINUED-FRACTION COULOMB & BESSEL PROGRAM COUL90\n! C---------------------------------------------------------------------\nend module coulombwf\n", "meta": {"hexsha": "51e217c7d1b108cb2c7a138346896d8f51afbc11", "size": 17003, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/coul90.f90", "max_stars_repo_name": "rnavarroperez/nn-scattering-fit", "max_stars_repo_head_hexsha": "055d21574fc02159ad0e785fa137ddfa874f88da", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-30T02:41:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-30T02:41:03.000Z", "max_issues_repo_path": "src/coul90.f90", "max_issues_repo_name": "rnavarroperez/nn-scattering-fit", "max_issues_repo_head_hexsha": "055d21574fc02159ad0e785fa137ddfa874f88da", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2020-04-17T02:13:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-05T21:11:08.000Z", "max_forks_repo_path": "src/coul90.f90", "max_forks_repo_name": "rnavarroperez/nn-scattering-fit", "max_forks_repo_head_hexsha": "055d21574fc02159ad0e785fa137ddfa874f88da", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.2305555556, "max_line_length": 73, "alphanum_fraction": 0.4482150209, "num_tokens": 5421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813513911654, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.7581944919969094}} {"text": "!-*- mode: compilation; default-directory: \"/tmp/\" -*-\n!Compilation started at Thu Jun 6 23:29:06\n!\n!a=./f && make $a && echo -2 | OMP_NUM_THREADS=2 $a\n!gfortran -std=f2008 -Wall -fopenmp -ffree-form -fall-intrinsics -fimplicit-none f.f08 -o f\n! assert 1 = */ 1\n! assert 2 = */ 2\n! assert 3 = */ 3\n! assert 4 = */ 2 2\n! assert 5 = */ 5\n! assert 6 = */ 2 3\n! assert 7 = */ 7\n! assert 8 = */ 2 2 2\n! assert 9 = */ 3 3\n! assert 10 = */ 2 5\n! assert 11 = */ 11\n! assert 12 = */ 3 2 2\n! assert 13 = */ 13\n! assert 14 = */ 2 7\n! assert 15 = */ 3 5\n! assert 16 = */ 2 2 2 2\n! assert 17 = */ 17\n! assert 18 = */ 3 2 3\n! assert 19 = */ 19\n! assert 20 = */ 2 2 5\n! assert 21 = */ 3 7\n! assert 22 = */ 2 11\n! assert 23 = */ 23\n! assert 24 = */ 3 2 2 2\n! assert 25 = */ 5 5\n! assert 26 = */ 2 13\n! assert 27 = */ 3 3 3\n! assert 28 = */ 2 2 7\n! assert 29 = */ 29\n! assert 30 = */ 5 2 3\n! assert 31 = */ 31\n! assert 32 = */ 2 2 2 2 2\n! assert 33 = */ 3 11\n! assert 34 = */ 2 17\n! assert 35 = */ 5 7\n! assert 36 = */ 3 3 2 2\n! assert 37 = */ 37\n! assert 38 = */ 2 19\n! assert 39 = */ 3 13\n! assert 40 = */ 5 2 2 2\n\nmodule prime_mod\n\n ! sieve_table stores 0 in prime numbers, and a prime factor in composites.\n integer, dimension(:), allocatable :: sieve_table\n private :: PrimeQ\n\ncontains\n\n ! setup routine must be called first!\n subroutine sieve(n) ! populate sieve_table. If n is 0 it deallocates storage, invalidating sieve_table.\n integer, intent(in) :: n\n integer :: status, i, j\n if ((n .lt. 1) .or. allocated(sieve_table)) deallocate(sieve_table)\n if (n .lt. 1) return\n allocate(sieve_table(n), stat=status)\n if (status .ne. 0) stop 'cannot allocate space'\n sieve_table(1) = 1\n do i=2,int(sqrt(real(n)))+1\n if (sieve_table(i) .eq. 0) then\n do j = i*i, n, i\n sieve_table(j) = i\n end do\n end if\n end do\n end subroutine sieve\n\n subroutine check_sieve(n)\n integer, intent(in) :: n\n if (.not. (allocated(sieve_table) .and. ((1 .le. n) .and. (n .le. size(sieve_table))))) stop 'Call sieve first'\n end subroutine check_sieve\n\n logical function isPrime(p)\n integer, intent(in) :: p\n call check_sieve(p)\n isPrime = PrimeQ(p)\n end function isPrime\n\n logical function isComposite(p)\n integer, intent(in) :: p\n isComposite = .not. isPrime(p)\n end function isComposite\n\n logical function PrimeQ(p)\n integer, intent(in) :: p\n PrimeQ = sieve_table(p) .eq. 0\n end function PrimeQ\n\n subroutine prime_factors(p, rv, n)\n integer, intent(in) :: p ! number to factor\n integer, dimension(:), intent(out) :: rv ! the prime factors\n integer, intent(out) :: n ! number of factors returned\n integer :: i, m\n call check_sieve(p)\n m = p\n i = 1\n if (p .ne. 1) then\n do while ((.not. PrimeQ(m)) .and. (i .lt. size(rv)))\n rv(i) = sieve_table(m)\n m = m/rv(i)\n i = i+1\n end do\n end if\n if (i .le. size(rv)) rv(i) = m\n n = i\n end subroutine prime_factors\n\nend module prime_mod\n\nprogram count_in_factors\n use prime_mod\n integer :: i, n\n integer, dimension(8) :: factors\n call sieve(40) ! setup\n do i=1,40\n factors = 0\n call prime_factors(i, factors, n)\n write(6,*)'assert',i,'= */',factors(:n)\n end do\n call sieve(0) ! release memory\nend program count_in_factors\n", "meta": {"hexsha": "bc6c75ef37814fcef6ac773fc9c26cea3bd2af86", "size": 4561, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Count-in-factors/Fortran/count-in-factors.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Count-in-factors/Fortran/count-in-factors.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Count-in-factors/Fortran/count-in-factors.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 35.9133858268, "max_line_length": 115, "alphanum_fraction": 0.430607323, "num_tokens": 1342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7581770739777497}} {"text": "program serialpi\n integer, parameter:: dp = kind(1.0d0)\n real(dp), parameter :: pi25 = 3.141592653589793238462643_dp\n integer :: n, i\n real(dp) :: pi, h, sum, x\n logical :: done\n\n done = .false.\n\n do while ( .not.done)\n write(*,'(\"Enter the number of intervals: (0 quits) \")')\n read(*,*) n\n\n if (n == 0) exit\n\n h = 1.0_dp/dble(n)\n sum = 0.0_dp\n\n do i = 1, n\n x = h * (i - 0.5_dp)\n sum = sum + 4.0_dp/(1.0_dp + x*x)\n enddo\n\n pi = h * sum\n\n write(*,'(\" pi is approximately \",f16.13,\" Error is \",f16.13)') &\n pi, abs(pi - pi25)\n\n end do\n\nend program serialpi\n", "meta": {"hexsha": "35d751074dd45b988802363a2f6c33ee9ad04568", "size": 623, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lectures5and6/example/src/serialpi.f90", "max_stars_repo_name": "sdm900/fortran_course", "max_stars_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lectures5and6/example/src/serialpi.f90", "max_issues_repo_name": "sdm900/fortran_course", "max_issues_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures5and6/example/src/serialpi.f90", "max_forks_repo_name": "sdm900/fortran_course", "max_forks_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.46875, "max_line_length": 70, "alphanum_fraction": 0.5248796148, "num_tokens": 230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178928, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7580890664944075}} {"text": "!-------------------------------------------------------------------------------\n! Copyright (c) 2016 The University of Tokyo\n! This software is released under the MIT License, see LICENSE.txt\n!-------------------------------------------------------------------------------\n!> \\brief This module contains functions for interpolation in 6 node\n!! prism element (Langrange interpolation)\nmodule shape_prism6n\n integer, parameter, private :: kreal = kind(0.0d0)\n\ncontains\n subroutine ShapeFunc_prism6n(ncoord,func)\n use shape_tri3n\n real(kind=kreal), intent(in) :: ncoord(3)\n real(kind=kreal) :: func(6)\n real(kind=kreal) :: xi, et, a, ze\n xi=ncoord(1); et=ncoord(2); ze=ncoord(3)\n a=1.d0-xi-et\n func(1)=0.5d0*a *(1.d0-ze)\n func(2)=0.5d0*xi*(1.d0-ze)\n func(3)=0.5d0*et*(1.d0-ze)\n func(4)=0.5d0*a *(1.d0+ze)\n func(5)=0.5d0*xi*(1.d0+ze)\n func(6)=0.5d0*et*(1.d0+ze)\n end subroutine\n\n subroutine ShapeDeriv_prism6n(ncoord,func)\n real(kind=kreal), intent(in) :: ncoord(3)\n real(kind=kreal) :: func(6,3)\n real(kind=kreal) :: xi, et, a, ze\n xi=ncoord(1); et=ncoord(2); ze=ncoord(3)\n a=1.d0-xi-et\n\n ! func(1,1) = 0.5d0*(1.d0-ncoord(3))\n ! func(2,1) = 0.d0\n ! func(3,1) = -0.5d0*(1.d0-ncoord(3))\n ! func(4,1) = 0.5d0*(1.d0+ncoord(3))\n ! func(5,1) = 0.d0\n ! func(6,1) = -0.5d0*(1.d0+ncoord(3))\n\n ! func(1,2) = 0.d0\n ! func(2,2) = 0.5d0*(1.d0-ncoord(3))\n ! func(3,2) = -0.5d0*(1.d0-ncoord(3))\n ! func(4,2) = 0.d0\n ! func(5,2) = 0.5d0*(1.d0+ncoord(3))\n ! func(6,2) = -0.5d0*(1.d0+ncoord(3))\n\n ! func(1,3) = -0.5d0*ncoord(1)\n ! func(2,3) = -0.5d0*ncoord(2)\n ! func(3,3) = -0.5d0*(1.d0-ncoord(1)-ncoord(2))\n ! func(4,3) = 0.5d0*ncoord(1)\n ! func(5,3) = 0.5d0*ncoord(2)\n ! func(6,3) = 0.5d0*(1.d0-ncoord(1)-ncoord(2))\n !\n ! local derivatives of the shape functions: xi-derivative\n !\n func(1,1)=-0.5d0*(1.d0-ze)\n func(2,1)= 0.5d0*(1.d0-ze)\n func(3,1)= 0.d0\n func(4,1)=-0.5d0*(1.d0+ze)\n func(5,1)= 0.5d0*(1.d0+ze)\n func(6,1)= 0.d0\n !\n ! local derivatives of the shape functions: eta-derivative\n !\n func(1,2)=-0.5d0*(1.d0-ze)\n func(2,2)= 0.d0\n func(3,2)= 0.5d0*(1.d0-ze)\n func(4,2)=-0.5d0*(1.d0+ze)\n func(5,2)= 0.d0\n func(6,2)= 0.5d0*(1.d0+ze)\n\n !\n ! local derivatives of the shape functions: zeta-derivative\n !\n func(1,3)=-0.5d0*a\n func(2,3)=-0.5d0*xi\n func(3,3)=-0.5d0*et\n func(4,3)= 0.5d0*a\n func(5,3)= 0.5d0*xi\n func(6,3)= 0.5d0*et\n end subroutine\n\nend module\n", "meta": {"hexsha": "64b32574876ab19e7b3d60d292c068d046bcd5b6", "size": 2610, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fistr1/src/lib/element/prism6n.f90", "max_stars_repo_name": "tkoyama010/FrontISTR", "max_stars_repo_head_hexsha": "2ce1f0425b87df76261c86ddb93bb4b588f72718", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fistr1/src/lib/element/prism6n.f90", "max_issues_repo_name": "tkoyama010/FrontISTR", "max_issues_repo_head_hexsha": "2ce1f0425b87df76261c86ddb93bb4b588f72718", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fistr1/src/lib/element/prism6n.f90", "max_forks_repo_name": "tkoyama010/FrontISTR", "max_forks_repo_head_hexsha": "2ce1f0425b87df76261c86ddb93bb4b588f72718", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.0714285714, "max_line_length": 80, "alphanum_fraction": 0.5164750958, "num_tokens": 1152, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465098415278, "lm_q2_score": 0.8104789155369048, "lm_q1q2_score": 0.7580786249475903}} {"text": "SUBROUTINE indirectJ2(C20,Re,GMmoon,rMoon,GMsun,rSun , a_iJ2)\n\n\n! ----------------------------------------------------------------------\n! SUBROUTINE: indirectJ2.f90\n! ----------------------------------------------------------------------\n! Purpose:\n! Computation of the so-called indirect J2 effect of Sun and Moon.\n! ----------------------------------------------------------------------\n! Input arguments\n! - C20 : fully normalized second zonal harmonic coefficient of Earth gravity field\n! - Re : Earth radius (meters)\n! - GMmoon : Moon gravity constant (m^3/sec^2)\n! - rMoon : Moon body-fixed geocentric position vector (meters)\n! - GMsun : Sun gravity constant (m^3/sec^2)\n! - rSun : Sun body-fixed geocentric position vector (meters)\n!\n! Output arguments:\n! - a_iJ2 : Acceleration in Body-fixed system (m/s/s)\n! ----------------------------------------------------------------------\n! Dr. Thomas Papanikolaou, Geoscience Australia 23 November 2015\n! ----------------------------------------------------------------------\n\n\n USE mdl_precision\n USE mdl_num\n IMPLICIT NONE\n\n! ---------------------------------------------------------------------------\n! Dummy arguments declaration\n! ---------------------------------------------------------------------------\n! IN\n REAL (KIND = prec_q), INTENT(IN), DIMENSION(3) :: rMoon, rSun\n REAL (KIND = prec_q), INTENT(IN) :: GMmoon, GMsun, C20, Re\n! OUT\n REAL (KIND = prec_q), INTENT(OUT), DIMENSION(3) :: a_iJ2\n! ---------------------------------------------------------------------------\n\n! ---------------------------------------------------------------------------\n! Local variables declaration\n! ---------------------------------------------------------------------------\n REAL (KIND = prec_q) :: xMoon,yMoon,zMoon,l_Moon , xSun,ySun,zSun,l_Sun\n REAL (KIND = prec_q) :: termMoon,termMoon_x,termMoon_y,termMoon_z , termSun,termSun_x,termSun_y,termSun_z\n REAL (KIND = prec_q) :: indirectJ2_coef\n REAL (KIND = prec_q) :: ax,ay,az\n! ---------------------------------------------------------------------------\n\n\n! ---------------------------------------------------------------------------\n! Celestial bodies Earth-centered coordinates and distance from Earth \n! ---------------------------------------------------------------------------\n! Moon\nxMoon = rMoon(1)\nyMoon = rMoon(2)\nzMoon = rMoon(3)\nl_Moon = sqrt(rMoon(1)**2 + rMoon(2)**2 + rMoon(3)**2)\n\n! Sun\nxSun = rSun(1)\nySun = rSun(2)\nzSun = rSun(3)\nl_Sun = sqrt(rSun(1)**2 + rSun(2)**2 + rSun(3)**2)\n! ---------------------------------------------------------------------------\n\n\n! ---------------------------------------------------------------------------\n! Moon terms\ntermMoon = (GMmoon / l_Moon**3) * (Re / l_Moon)**2\ntermMoon_x = termMoon * (5.0D0 * (zMoon/l_Moon)**2 - 1.0D0) * xMoon\ntermMoon_y = termMoon * (5.0D0 * (zMoon/l_Moon)**2 - 1.0D0) * yMoon\ntermMoon_z = termMoon * (5.0D0 * (zMoon/l_Moon)**2 - 3.0D0) * zMoon\n! ---------------------------------------------------------------------------\n! Sun terms\ntermSun = (GMsun / l_Sun**3) * (Re / l_Sun)**2\ntermSun_x = termSun * (5.0D0 * (zSun/l_Sun)**2 - 1.0D0) * xSun\ntermSun_y = termSun * (5.0D0 * (zSun/l_Sun)**2 - 1.0D0) * ySun\ntermSun_z = termSun * (5.0D0 * (zSun/l_Sun)**2 - 3.0D0) * zSun\n! ---------------------------------------------------------------------------\n\n\n! ---------------------------------------------------------------------------\n! Indirect J2 effect\n! ---------------------------------------------------------------------------\nindirectJ2_coef = -1.0D0 * ( ( 3.0D0 * sqrt(5.0D0) ) / 2.0D0 ) * C20\n! Acceleration cartesian components\nax = indirectJ2_coef * (termMoon_x + termSun_x)\nay = indirectJ2_coef * (termMoon_y + termSun_y)\naz = indirectJ2_coef * (termMoon_z + termSun_z)\n! ---------------------------------------------------------------------------\n a_iJ2(1) = ax\n a_iJ2(2) = ay\n a_iJ2(3) = az\n! ---------------------------------------------------------------------------\n\n\nEND", "meta": {"hexsha": "e5b7aa620a178d59497104bd4f0295bf0c48d544", "size": 4058, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/indirectJ2.f90", "max_stars_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_stars_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2021-07-08T23:35:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:17:58.000Z", "max_issues_repo_path": "src/fortran/indirectJ2.f90", "max_issues_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_issues_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-09-27T14:27:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T23:50:02.000Z", "max_forks_repo_path": "src/fortran/indirectJ2.f90", "max_forks_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_forks_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2021-07-12T05:42:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T15:15:34.000Z", "avg_line_length": 42.2708333333, "max_line_length": 111, "alphanum_fraction": 0.3962543125, "num_tokens": 982, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362489, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7580672653152307}} {"text": "!======================================================================!\n real function Math_Mod_Distance(x_a, y_a, z_a, x_b, y_b, z_b)\n!----------------------------------------------------------------------!\n! Calculates distance between two points in three-dimensional space. !\n!----------------------------------------------------------------------!\n implicit none\n!-----------------------------[Arguments]------------------------------!\n real :: x_a, y_a, z_a, x_b, y_b, z_b\n!======================================================================!\n\n Math_Mod_Distance = sqrt( (x_a-x_b)*(x_a-x_b) &\n + (y_a-y_b)*(y_a-y_b) &\n + (z_a-z_b)*(z_a-z_b) )\n\n end function\n", "meta": {"hexsha": "c96738ee1c7ef5d7d406a5fd904edb6603e9a7d0", "size": 730, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/Shared/Math_Mod/Distance.f90", "max_stars_repo_name": "Dundj/Convex_Geomotry", "max_stars_repo_head_hexsha": "38507824d97270b3e4ead194a16148ff6158b59f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 64, "max_stars_repo_stars_event_min_datetime": "2018-05-29T09:39:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T13:59:18.000Z", "max_issues_repo_path": "Sources/Shared/Math_Mod/Distance.f90", "max_issues_repo_name": "EdinSmartLab/T-Flows", "max_issues_repo_head_hexsha": "5a7f70421f18069453977142e6515cdc959a9e50", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 124, "max_issues_repo_issues_event_min_datetime": "2018-05-28T12:58:20.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T11:12:31.000Z", "max_forks_repo_path": "Sources/Shared/Math_Mod/Distance.f90", "max_forks_repo_name": "EdinSmartLab/T-Flows", "max_forks_repo_head_hexsha": "5a7f70421f18069453977142e6515cdc959a9e50", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2018-05-28T13:13:06.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T17:41:08.000Z", "avg_line_length": 45.625, "max_line_length": 72, "alphanum_fraction": 0.2945205479, "num_tokens": 139, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9381240125464115, "lm_q2_score": 0.8080672135527631, "lm_q1q2_score": 0.7580672567853162}} {"text": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc \nc this is the end of the debugging code and the beginning\nc of the actual chebychev expansion routine\nc \nccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc \nc \nc \n subroutine chebexps(itype,n,x,u,v,whts)\n implicit real *8 (a-h,o-z)\n save\n dimension x(1),whts(1),u(n,n),v(n,n)\nc \nc this subroutine constructs the chebychev nodes\nc on the interval [-1,1], and the weights for the\nc corresponding order n quadrature. it also constructs\nc the matrix converting the coefficients\nc of a chebychev expansion into its values at the n\nc chebychev nodes. no attempt has been made to\nc make this code efficient, but its speed is normally\nc sufficient, and it is mercifully short.\nc \nc input parameters:\nc \nc itype - the type of the calculation to be performed\nc itype=0 means that only the chebychev nodes are\nc to be constructed.\nc itype=1 means that only the nodes and the weights\nc are to be constructed\nc itype=2 means that the nodes, the weights, and\nc the matrices u, v are to be constructed\nc n - the number of chebychev nodes and weights to be generated\nc \nc output parameters:\nc \nc x - the order n chebychev nodes - computed independently\nc of the value of itype.\nc u - the n*n matrix converting the values at of a polynomial of order\nc n-1 at n chebychev nodes into the coefficients of its\nc chebychev expansion - computed only in itype=2\nc v - the n*n matrix converting the coefficients\nc of an n-term chebychev expansion into its values at\nc n chebychev nodes (note that v is the inverse of u)\nc - computed only in itype=2\nc whts - the corresponding quadrature weights - computed only\nc if itype .ge. 1\nc \nc . . . construct the chebychev nodes on the interval [-1,1]\nc \n ZERO=0\n DONE=1\n pi=datan(done)*4\n h=pi/(2*n)\nccc do 1200 i=n,1,-1\n do 1200 i=1,n\n t=(2*i-1)*h\n x(n-i+1)=dcos(t)\n1200 CONTINUE\nc \n if(itype .eq. 0) return\nc \nc construct the weights of the quadrature\nc formula based on the chebychev nodes,\nc and also the matrix of the chebychev transform\nc \nc . . . construct the first two rows of the matrix\nc \n if(itype .le. 1) goto 1350\n do 1300 i=1,n\n u(1,i)=1\n u(2,i)=x(i)\n 1300 continue\n 1350 continue\nc \nc construct all quadrature weights and the rest of the rows\nc \n do 2000 i=1,n\nc \nc construct the weight for the i-th node\nc \n Tjm2=1\n Tjm1=x(i)\n whts(i)=2\nc \n ic=-1\n do 1400 j=2,n-1\nc \nc calculate the T_j(x(i))\nc \n Tj=2*x(i)*Tjm1-Tjm2\nc \n if(itype .eq. 2) u(j+1,i)=tj\nc \n tjm2=tjm1\n tjm1=tj\nc \nc calculate the contribution of this power to the\nc weight\nc \n \n ic=-ic\n if(ic .lt. 0) goto 1400\n rint=-2*(done/(j+1)-done/(j-1))\n whts(i)=whts(i)-rint*tj\nccc whts(i)=whts(i)+rint*tj\n 1400 continue\n whts(i)=whts(i)/n\n 2000 continue\n if(itype .ne. 2) return\nc \nc now, normalize the matrix of the chebychev transform\nc \n do 3000 i=1,n\nc \n d=0\n do 2200 j=1,n\n d=d+u(i,j)**2\n 2200 continue\n d=done/dsqrt(d)\n do 2400 j=1,n\n u(i,j)=u(i,j)*d\n 2400 continue\n 3000 continue\nc \nc now, rescale the matrix\nc \n ddd=2\n ddd=dsqrt(ddd)\n dd=n\n dd=done/dsqrt(dd/2)\n do 3400 i=1,n\n do 3200 j=1,n\n u(j,i)=u(j,i)*dd\n 3200 continue\n u(1,i)=u(1,i)/ddd\n 3400 continue\nc \nc finally, construct the matrix v, converting the values at the\nc chebychev nodes into the coefficients of the chebychev\nc expansion\nc \n dd=n\n dd=dd/2\n do 4000 i=1,n\n do 3800 j=1,n\n v(j,i)=u(i,j)*dd\n 3800 continue\n 4000 continue\nc \n do 4600 i=1,n\n do 4400 j=1,n\nc\n d=v(j,i)\n v(j,i)=u(j,i) *n/2\n u(j,i)=d/n*2\n 4400 continue\n 4600 continue\nc\n do 5200 i=1,n\n v(1,i)=v(1,i)*2\n 5200 continue\nc\n do 5600 i=1,n\n do 5400 j=1,i-1\nc\n d=u(j,i)\n u(j,i)=u(i,j)\n u(i,j)=d\nc\n d=v(j,i)\n v(j,i)=v(i,j)\n v(i,j)=d\n 5400 continue\n 5600 continue\nc\n return\n end\nc \nc \nc \nc \nc \n subroutine chebinmt(n,ainte,adiff,x,whts,endinter,\n 1 itype,w)\n implicit real *8 (a-h,o-z)\n save\n dimension ainte(1),w(1),x(1),whts(1),adiff(1),endinter(1)\nc \nc \nc for the user-specified n, this subroutine constructs\nc the matrices of spectral indefinite integration and/or\nc spectral differentiation on the n Chebychev nodes\nc on the interval [-1,1]. Actually, this is only a\nc memory management routine. All the actual work is done\nc by the subroutine legeinm0 (see)\nc \nc input parameters:\nc \nc n - the number of Chebychev nodes on the interval [-1,1]\nc itype - the type of the calculation to be performed\nc EXPLANATION:\nc itype=1 means that only the matrix ainte will\nc be constructed\nc itype=2 means that only the matrix adiff will\nc be constructed\nc itype=3 means that both matrices ainte and adiff\nc will be constructed\nc \nc output paramaters:\nc \nc ainte - the matrix of spectral indefinite integration on\nc the Chebychev nodes\nc adiff - the matrix of spectral differentiation on\nc the Chebychev nodes\nc x - the n Chebychev nodes on the intervl [-1,1]\nc whts - the n Chebychev weights on the interval [-1,1]\nc endinter - the interpolation coefficients converting the\nc values of a function at n Chebychev nodes into its\nc value at 1 (the right end of the interval)\nc \nc work arrays:\nc \nc w - must be 3* n**2 + 2*n +50 *8 locations long\nc \nc . . . allocate memory for the construction of the integrating\nc matrix\nc \n ipolin=1\n lpolin=n+5\nc \n ipolout=ipolin+lpolin\n lpolout=n+5\nc \n iu=ipolout+lpolout\n lu=n**2+1\nc \n iv=iu+lu\n lv=n**2+1\nc \n iw=iv+lv\n lw=n**2+1\nc \n ltot=iw+lw\nc \nc construct the integrating matrix\nc \n call chebinm0(n,ainte,adiff,w(ipolin),w(ipolout),\n 1 x,whts,w(iu),w(iv),w(iw),itype,endinter)\nc \n return\n end\nc \nc \nc \nc \nc \n subroutine chebinm0(n,ainte,adiff,polin,polout,\n 1 x,whts,u,v,w,itype,endinter)\n implicit real *8 (a-h,o-z)\n save\n dimension ainte(n,n),u(n,n),v(n,n),w(n,n),\n 1 endinter(1),x(n),whts(n),polin(n),polout(n),\n 2 adiff(n,n)\nc \nc for the user-specified n, this subroutine constructs\nc the matrices of spectral indefinite integration and/or\nc spectral differentiation on the n Chebychev nodes\nc on the interval [-1,1]\nc \nc input parameters:\nc \nc n - the number of Chebychev nodes on the interval [-1,1]\nc itype - the type of the calculation to be performed\nc EXPLANATION:\nc itype=1 means that only the matrix ainte will\nc be constructed\nc itype=2 means that only the matrix adiff will\nc be constructed\nc itype=3 means that both matrices ainte and adiff\nc will be constructed\nc \nc output paramaters:\nc \nc ainte - the matrix of spectral indefinite integration on\nc the Chebychev nodes\nc adiff - the matrix of spectral differentiation on\nc the Chebychev nodes\nc x - the n Chebychev nodes on the intervl [-1,1]\nc whts - the n Chebychev weights on the interval [-1,1]\nc \nc work arrays:\nc \nc polin, polout - must be n+3 real *8 locations each\nc \nc u, v, w - must be n**2+1 real *8 locations each\nc \nc . . . construct the matrices of the forward and inverse\nc Chebychev transforms\nc \n itype2=2\n call chebexps(itype2,n,x,u,v,whts)\nc \nc if the user so requested,\nc construct the matrix converting the coefficients of\nc the Chebychev series of a function into the coefficients\nc of the indefinite integral of that function\nc \n if(itype. eq. 2) goto 2000\nc \n do 1600 i=1,n\nc \n do 1200 j=1,n\n polin(j)=0\n 1200 continue\nc \n polin(i)=1\n call chebinte(polin,n+1,polout)\nc \n do 1400 j=1,n\ncccc ainte(i,j)=polout(j)\n ainte(j,i)=polout(j)\n 1400 continue\nc \n 1600 continue\nc \nc multiply the three, obtaining the integrating matrix\nc \n call cheb_matmul(ainte,u,w,n)\n call cheb_matmul(v,w,ainte,n)\nc \n 2000 continue\n\ncccc return\n\nc \nc if the user so requested,\nc construct the matrix converting the coefficients of\nc the Chebychev series of a function into the coefficients\nc of the derivative of that function\nc \n if(itype. eq. 1) goto 3000\nc \n do 2600 i=1,n\nc \n do 2200 j=1,n+3\n polin(j)=0\n 2200 continue\nc \n polin(i)=1\n call chebdiff(polin,n+1,polout)\nc \n polout(n)=0\n do 2400 j=1,n\ncccc adiff(i,j)=polout(j)\n adiff(j,i)=polout(j)\n 2400 continue\nc \n 2600 continue\nc \nc multiply the three, obtaining the differentiating matrix\nc \ncc call cheb_matmula(adiff,v,w,n)\ncc call cheb_matamul(u,w,adiff,n)\n\n call cheb_matmul(adiff,u,w,n)\n call cheb_matmul(v,w,adiff,n)\nc \n 3000 continue\nc \nc construct the vector of interpolation coefficients\nc converting the values of a polynomial at the Chebychev\nc nodes into its value at the right end of the interval\nc \n do 3400 i=1,n\nc \n d=0\n do 3200 j=1,n\n d=d+u(j,i)\n 3200 continue\n endinter(i)=d\n 3400 continue\nc \n return\n end\nc \nc \nc \nc \nc \n subroutine chebpol(x,n,pol,der)\n implicit real *8 (a-h,o-z)\nc \n save\n d=dacos(x)\n pol=dcos(n*d)\n der=dsin(n*d)*n/dsqrt(1-x**2)\n return\n end\nc \nc \nc \nc \nc \n subroutine chebpols(x,n,pols)\n implicit real *8 (a-h,o-z)\n save\n dimension pols(1)\nc \n pkm1=1\n pk=x\nc \n pk=1\n pkp1=x\nc \nc \nc if n=0 or n=1 - exit\nc \n if(n .ge. 2) goto 1200\n pols(1)=1\n if(n .eq. 0) return\nc \n pols(2)=x\n return\n 1200 continue\nc \n pols(1)=1\n pols(2)=x\nc \nc n is greater than 2. conduct recursion\nc \n do 2000 k=1,n-1\n pkm1=pk\n pk=pkp1\n pkp1=2*x*pk-pkm1\n pols(k+2)=pkp1\n 2000 continue\nc \n return\n end\nc \nc \nc \nc \nc \n subroutine chebinte(polin,n,polout)\n implicit real *8 (a-h,o-z)\n save\n dimension polin(1),polout(1)\nc \nc this subroutine computes the indefinite integral of the\nc Chebychev expansion polin getting the expansion polout\nc \nc \nc input parameters:\nc \nc polin - the Chebychev expansion to be integrated\nc n - the order of the expansion polin\nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc also nothe that the order of the integrated expansion is\nc n+1 (who could think!)\nc \nc output parameters:\nc \nc polout - the Chebychev expansion of the integral of the function\nc represented by the expansion polin\nc \n do 1200 i=1,n+2\n polout(i)=0\n 1200 continue\nc \n polout(2)=polin(1)\n if(n .eq. 0) return\n polout(3)=polin(2)/4\n if(n .eq. 1) return\nc \n do 2000 k=3,n\nc \n polout(k+1)=polin(k)/(2*k)\n polout(k-1)=-polin(k)/(2*k-4)+polout(k-1)\nc \n 2000 continue\nc \n dd=0\n sss=-1\n do 2200 k=2,n+1\nc \n dd=dd+polout(k)*sss\n sss=-sss\n 2200 continue\nc \ncccc call prin2('dd=*',dd,1)\n polout(1)=-dd\nc \n return\n end\nc \nc \nc \nc \nc \n subroutine chebdiff(polin,n,polout)\n implicit real *8 (a-h,o-z)\n save\n dimension polin(1),polout(1)\nc \nc this subroutine differentiates the Chebychev\nc expansion polin getting the expansion polout\nc \nc \nc input parameters:\nc \nc polin - the Chebychev expansion to be differentiated\nc n - the order of the expansion polin\nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc also nothe that the order of the integrated expansion is\nc n+1 (who could think!)\nc \nc output parameters:\nc \nc polout - the Chebychev expansion of the derivative of the function\nc represented by the expansion polin\nc \n do 1200 i=1,n+1\n polout(i)=0\n 1200 continue\nc \n do 2000 k=1,n-1\nc \n polout(n-k)=polout(n-k+2)+(n-k)*polin(n-k+1) *2\n 2000 continue\n polout(1)=polout(1)/2\nc \n return\n end\nc \nc \nc \nc \nc \n SUBROUTINE chebexev(X,VAL,TEXP,N)\n IMPLICIT REAL *8 (A-H,O-Z)\n save\n REAL *8 TEXP(1)\nC \nC This subroutine computes the value o a Chebychev\nc expansion with coefficients TEXP at point X in interval [-1,1]\nC \nc input parameters:\nc \nC X = evaluation point\nC TEXP = expansion coefficients\nC N = order of expansion\nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc \nc output parameters:\nc \nC VAL = computed value\nC \n done=1\n pjm2=1\n pjm1=x\nc \n val=texp(1)*pjm2+texp(2)*pjm1\nc \n DO 600 J = 2,N\nc \n pj= 2*x*pjm1-pjm2\n val=val+texp(j+1)*pj\nc \n pjm2=pjm1\n pjm1=pj\n 600 CONTINUE\nc \n RETURN\n END\nc \nc \nc \nc \nc \n SUBROUTINE CHFUNDER(X,VAL,der,TEXP,N)\nC \nC This subroutine computes the value and the derivative\nc of a chebychev expansion with coefficients TEXP\nC at point X in interval [-1,1]\nC \nc input parameters:\nc \nC X = evaluation point\nC TEXP = expansion coefficients\nC N = order of expansion\nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc \nc output parameters:\nc \nC VAL = computed value\nC der = computed value of the derivative\nC \n IMPLICIT REAL *8 (A-H,O-Z)\n save\n REAL *8 TEXP(1)\nC \n done=1\n tjm2=1\n tjm1=x\n derjm2=0\n derjm1=1\nc \n val=texp(1)*tjm2+texp(2)*tjm1\n der=texp(2)\nc \n DO 600 J = 2,N\nc \n tj=2*x*tjm1-tjm2\n val=val+texp(j+1)*tj\nc \n derj=2*tjm1+2*x*derjm1-derjm2\n der=der+texp(j+1)*derj\nc \n tjm2=tjm1\n tjm1=tj\n derjm2=derjm1\n derjm1=derj\n 600 CONTINUE\nc \n RETURN\n END\nc \nc \nc \nc \nc \n SUBROUTINE CHebcval(X,VAL,TEXP,N)\nC \nC This subroutine computes the value and the derivative\nc of a chebychev expansion with coefficients TEXP\nC at point X in interval [-1,1]\nC \nc input parameters:\nc \nC X = evaluation point\nC TEXP = expansion coefficients\nC N = order of expansion\nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc \nc output parameters:\nc \nC VAL = computed value\nC der = computed value of the derivative\nC \n IMPLICIT REAL *8 (A-H,O-Z)\n save\n complex *16 TEXP(1),val\nC \n done=1\n tjm2=1\n tjm1=x\nc \n val=texp(1)*tjm2+texp(2)*tjm1\nc \n DO 600 J = 2,N\nc \n tj=2*x*tjm1-tjm2\n val=val+texp(j+1)*tj\nc \n tjm2=tjm1\n tjm1=tj\n 600 CONTINUE\nc \n RETURN\n END\nc \nc \nc \nc \nc \n SUBROUTINE CHebval(X,VAL,TEXP,N)\nC \nC This subroutine computes the value and the derivative\nc of a chebychev expansion with coefficients TEXP\nC at point X in interval [-1,1]\nC \nc input parameters:\nc \nC X = evaluation point\nC TEXP = expansion coefficients\nC N = order of expansion\nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc \nc output parameters:\nc \nC VAL = computed value\nC der = computed value of the derivative\nC \n IMPLICIT REAL *8 (A-H,O-Z)\n save\n real *8 TEXP(1),val\nC \n done=1\n tjm2=1\n tjm1=x\nc \n val=texp(1)*tjm2+texp(2)*tjm1\nc \n DO 600 J = 2,N\nc \n tj=2*x*tjm1-tjm2\n val=val+texp(j+1)*tj\nc \n tjm2=tjm1\n tjm1=tj\n 600 CONTINUE\nc \n RETURN\n END\nc \nc \nc \nc \nc \n SUBROUTINE CHFUNcDER(X,VAL,der,TEXP,N)\nC \nC This subroutine computes the value and the derivative\nc of a chebychev expansion with coefficients TEXP\nC at point X in interval [-1,1]\nC \nc input parameters:\nc \nC X = evaluation point\nC TEXP = expansion coefficients\nC N = order of expansion\nc IMPORTANT NOTE: n is {\\bf the order of the expansion, which is\nc one less than the number of terms in the expansion!!}\nc \nc output parameters:\nc \nC VAL = computed value\nC der = computed value of the derivative\nC \n IMPLICIT REAL *8 (A-H,O-Z)\n save\n complex *16 TEXP(1),val,der\nC \n done=1\n tjm2=1\n tjm1=x\n derjm2=0\n derjm1=1\nc \n val=texp(1)*tjm2+texp(2)*tjm1\n der=texp(2)\nc \n DO 600 J = 2,N\nc \n tj=2*x*tjm1-tjm2\n val=val+texp(j+1)*tj\nc \n derj=2*tjm1+2*x*derjm1-derjm2\n der=der+texp(j+1)*derj\nc \n tjm2=tjm1\n tjm1=tj\n derjm2=derjm1\n derjm1=derj\n 600 CONTINUE\nc \n RETURN\n END\nc \nc \nc \nc \nc \n subroutine cheb_matmula(a,b,c,n)\n implicit real *8 (a-h,o-z)\n save\n dimension a(n,n),b(n,n),c(n,n)\nc \n do 2000 i=1,n\n do 1800 j=1,n\n d=0\n do 1600 k=1,n\ncccc d=d+a(i,k)*b(k,j)\n d=d+a(i,k)*b(j,k)\n 1600 continue\n c(i,j)=d\n 1800 continue\n 2000 continue\n return\n end\nc \nc \nc \nc \nc \n subroutine cheb_matamul(a,b,c,n)\n implicit real *8 (a-h,o-z)\n save\n dimension a(n,n),b(n,n),c(n,n)\nc \n do 2000 i=1,n\n do 1800 j=1,n\n d=0\n do 1600 k=1,n\ncccc d=d+a(i,k)*b(k,j)\n d=d+a(k,i)*b(k,j)\n\n 1600 continue\n c(i,j)=d\n 1800 continue\n 2000 continue\n return\n end\nc \nc \nc \nc \nc \n subroutine cheb_matmul(a,b,c,n)\n implicit real *8 (a-h,o-z)\n save\n dimension a(n,n),b(n,n),c(n,n)\nc \n do 2000 i=1,n\n do 1800 j=1,n\n d=0\n do 1600 k=1,n\n d=d+a(i,k)*b(k,j)\n 1600 continue\n c(i,j)=d\n 1800 continue\n 2000 continue\n return\n end\nc \nc \nc \nc \nc \n subroutine chematrin(n,m,xs,amatrint,ts,w)\n implicit real *8 (a-h,o-z)\n save\n dimension amatrint(m,n),xs(1),w(1),ts(1)\nc \nc \nc This subroutine constructs the matrix interpolating\nc functions from the n-point Chebychev grid on the interval [-1,1]\nc to an arbitrary m-point grid (the nodes of the latter are\nc user-provided)\nc \nc Input parameters:\nc \nc n - the number of interpolation nodes\nc m - the number of nodes to which the functions will be interpolated\nc xs - the points at which the function is to be interpolated\nc \nc Output parameters:\nc \nc amatrint - the m \\times n matrix conerting the values of a function\nc at the n Chebychev nodes into its values at m user-specified\nc (arbitrary) nodes\nc ts - the n Chebychev nodes on the interval [-1,1]\nc \nc Work arrays:\nc \nc w - must be at least 2*n**2+n + 100 real *8 locations long\nc \n \n icoefs=1\n lcoefs=n+2\nc \n iu=icoefs+lcoefs\n lu=n**2+10\nc \n iv=iu+lu\nc \n ifinit=1\n do 2000 i=1,m\nc \n call chevecin(n,xs(i),ts,w(iu),w(iv),w(icoefs),ifinit)\nc \n do 1400 j=1,n\n amatrint(i,j)=w(j)\n 1400 continue\nc \n ifinit=0\n 2000 continue\nc \n return\n end\n \nc \nc \nc \nc \nc \n subroutine chevecin(n,x,ts,u,v,coefs,ifinit)\n implicit real *8 (a-h,o-z)\n save\n dimension u(n,n),v(n,n),ts(1),coefs(1)\nc \nc This subroutine constructs the coefficients of the\nc standard interpolation formula connecting the values of a\nc function at n Chebychev nodes on the interval [a,b] with\nc its value at the point x \\in R^1\nc \nc Input parameters:\nc \nc n - the number of interpolation nodes\nc x - the points at which the function is to be interpolated\nc ts - the n Chebychev nodes on the interval [-1,1]; please note that\nc it is an input parameter only if the parameter ifinit (see\nc below) has been set to 1; otherwise, it is an output parameter\nc u - the n*n matrix converting the values at of a polynomial of order\nc n-1 at n Chebychev nodes into the coefficients of its\nc Chebychev expansion; please note that\nc it is an input parameter only if the parameter ifinit (see\nc below) has been set to 1; otherwise, it is an output parameter\nc ifinit - an integer parameter telling the subroutine whether it should\nc initialize the Chebychev expander;\nc ifinit=1 will cause the subroutine to perform the initialization\nc ifinit=0 will cause the subroutine to skip the initialization\nc \nc Output parameters:\nc \nc coefs - the interpolation coefficients\nc \nc Work arrays:\nc \nc v - must be at least n*n real *8 locations long\nc \nc . . . construct the n Chebychev nodes on the interval [-1,1];\nc also the corresponding Chebychev expansion-evaluation\nc matrices\nc \n itype=2\n if(ifinit .ne.0) call chebexps(itype,n,ts,u,v,coefs)\nc \nc evaluate the n Chebychev polynomials at the point where the\nc functions will have to be interpolated\nc \n call chebpols(x,n+1,v)\nc \nc apply the interpolation matrix to the ector of values\nc of polynomials from the right\nc \n call chematvec(u,v,coefs,n)\n return\n end\nc \nc \nc \nc \nc \n subroutine chematvec(a,x,y,n)\n implicit real *8 (a-h,o-z)\n save\n dimension a(n,n),x(n),y(n)\nc \n do 1400 i=1,n\n d=0\n do 1200 j=1,n\n d=d+a(i,j)*x(j)\n 1200 continue\n y(i)=d\n 1400 continue\n return\n end\n \n", "meta": {"hexsha": "0aaa27959436feedd41e7c7fd9456df37c231637", "size": 22954, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/chebexps.f", "max_stars_repo_name": "askhamwhat/biharm-evals", "max_stars_repo_head_hexsha": "d836302f544670b3d899bd91ea4cb49e9afb6a75", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chebexps.f", "max_issues_repo_name": "askhamwhat/biharm-evals", "max_issues_repo_head_hexsha": "d836302f544670b3d899bd91ea4cb49e9afb6a75", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chebexps.f", "max_forks_repo_name": "askhamwhat/biharm-evals", "max_forks_repo_head_hexsha": "d836302f544670b3d899bd91ea4cb49e9afb6a75", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.494370522, "max_line_length": 75, "alphanum_fraction": 0.5799860591, "num_tokens": 7245, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693731004241, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7580135368330336}} {"text": "program tridiagnalmat\n !This program solves a tri diagonal matrix, A only has the diagonal matrix elements\n implicit none\n real, allocatable :: A(:,:), b(:), x(:)\n integer :: n,i\n\n print*, 'Give dimension of matrix' ; read*, n\n allocate(A(n,3), b(n),x(n))\n print*, 'Give matrix row-wise, only the tridiagonal terms with the first row being \" 0 x x \" and last being \"x x 0\"'\n do i=1,n\n read*, A(i,:)\n enddo\n if ((A(n,3) .ne. 0) .or. (A(1,1) .ne. 0) ) print*, \"ERROR : Matrix non-conforming to the input format\"\n print*, 'Give b'; read*, b\n print*, '--------------------Read complete, tridiagonal A: ---------------------'\n do i=1,n\n print*, A(i,:), b(i)\n enddo\n do i =2,n\n b(i) = b(i) - A(i,1)*b(i-1)/A(i-1,2)\n A(i,1:2) = A (i,1:2) - A(i,1)*A(i-1,2:3)/A(i-1,2)\n enddo\n do i=n-1,1,-1\n ! A(i,3) = A(i,3) - A(i+1,2) * (A(i,3)/A(i+1,2)) !unnecessary step, will not be used for solution, only for completeness\n b(i) = b(i) - b(i+1)*(A(i,3)/A(i+1,2))\n enddo\n do i=1,n\n x(i) = b(i)/A(i,2)\n enddo\n print*, \"------------------------------------------------\"; print*, \"The solutions are:\"\n print*, x\nend program tridiagnalmat", "meta": {"hexsha": "97df06d7c987b9fdf6a780750f84ceac261c93ab", "size": 1229, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tridiagmatrixsolver.f90", "max_stars_repo_name": "sciencyboi/smallfortran90programs", "max_stars_repo_head_hexsha": "9d79d9d27ebe229bae1dd2d6c131217fef71c1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tridiagmatrixsolver.f90", "max_issues_repo_name": "sciencyboi/smallfortran90programs", "max_issues_repo_head_hexsha": "9d79d9d27ebe229bae1dd2d6c131217fef71c1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tridiagmatrixsolver.f90", "max_forks_repo_name": "sciencyboi/smallfortran90programs", "max_forks_repo_head_hexsha": "9d79d9d27ebe229bae1dd2d6c131217fef71c1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.40625, "max_line_length": 128, "alphanum_fraction": 0.4979658259, "num_tokens": 440, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693688269985, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.7580135311425046}} {"text": "\nmodule forlab_stats\n\n use stdlib_kinds, only: sp, dp, qp, int8, int16, int32, int64\n implicit none\n private\n\n public :: mean, var, std\n public :: rng, randu, randn\n\n interface mean\n !! mean computes the mean value of an array.\n module function mean_1_sp(x) result(mean)\n real(sp), dimension(:), intent(in) :: x\n real(sp) :: mean\n end function mean_1_sp\n module function mean_2_sp(A, dim) result(mean)\n real(sp), dimension(:), allocatable :: mean\n real(sp), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: dim\n end function mean_2_sp\n module function mean_1_dp(x) result(mean)\n real(dp), dimension(:), intent(in) :: x\n real(dp) :: mean\n end function mean_1_dp\n module function mean_2_dp(A, dim) result(mean)\n real(dp), dimension(:), allocatable :: mean\n real(dp), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: dim\n end function mean_2_dp\n end interface mean\n\n !> Version: Experimental\n !>\n !> Generate a normal distributed data scalar or vector.\n !> ([Specification](../page/specs/forlab_stats.html#randn))\n interface randn\n module function randn_0_sp(mean, std) result(random)\n real(sp), intent(in) :: mean, std\n real(sp) :: random\n end function randn_0_sp\n module function randn_1_sp(mean, std, ndim) result(random)\n real(sp), intent(in) :: mean, std\n integer, intent(in) :: ndim\n real(sp) :: random(ndim)\n end function randn_1_sp\n module function randn_0_dp(mean, std) result(random)\n real(dp), intent(in) :: mean, std\n real(dp) :: random\n end function randn_0_dp\n module function randn_1_dp(mean, std, ndim) result(random)\n real(dp), intent(in) :: mean, std\n integer, intent(in) :: ndim\n real(dp) :: random(ndim)\n end function randn_1_dp\n end interface randn\n\n !> Version: Experimental\n !>\n !> Generate an uniformly distributed data scalar or vector.\n !> ([Specification](../page/specs/forlab_stats.html#randomrandu))\n interface randu\n module function randu_0_rsp(start, end) result(random)\n real(sp), intent(in) :: start, end\n real(sp) :: random\n end function randu_0_rsp\n module function randu_1_rsp(start, end, ndim) result(random)\n real(sp), intent(in) :: start, end\n integer, intent(in) :: ndim\n real(sp) :: random(ndim)\n end function randu_1_rsp\n module function randu_0_rdp(start, end) result(random)\n real(dp), intent(in) :: start, end\n real(dp) :: random\n end function randu_0_rdp\n module function randu_1_rdp(start, end, ndim) result(random)\n real(dp), intent(in) :: start, end\n integer, intent(in) :: ndim\n real(dp) :: random(ndim)\n end function randu_1_rdp\n module function randu_0_iint8(start, end) result(random)\n integer(int8), intent(in) :: start, end\n integer(int8) :: random\n end function randu_0_iint8\n module function randu_1_iint8(start, end, ndim) result(random)\n integer(int8), intent(in) :: start, end\n integer, intent(in) :: ndim\n integer(int8) :: random(ndim)\n end function randu_1_iint8\n module function randu_0_iint16(start, end) result(random)\n integer(int16), intent(in) :: start, end\n integer(int16) :: random\n end function randu_0_iint16\n module function randu_1_iint16(start, end, ndim) result(random)\n integer(int16), intent(in) :: start, end\n integer, intent(in) :: ndim\n integer(int16) :: random(ndim)\n end function randu_1_iint16\n module function randu_0_iint32(start, end) result(random)\n integer(int32), intent(in) :: start, end\n integer(int32) :: random\n end function randu_0_iint32\n module function randu_1_iint32(start, end, ndim) result(random)\n integer(int32), intent(in) :: start, end\n integer, intent(in) :: ndim\n integer(int32) :: random(ndim)\n end function randu_1_iint32\n module function randu_0_iint64(start, end) result(random)\n integer(int64), intent(in) :: start, end\n integer(int64) :: random\n end function randu_0_iint64\n module function randu_1_iint64(start, end, ndim) result(random)\n integer(int64), intent(in) :: start, end\n integer, intent(in) :: ndim\n integer(int64) :: random(ndim)\n end function randu_1_iint64\n end interface randu\n\n interface\n module subroutine rng(seed)\n integer, intent(in), optional :: seed\n end subroutine rng\n end interface\n\n interface var\n !! `var` computes vector and matrix variances.\n !!([Specification](../module/forlab_var.html))\n real(sp) module function var_1_sp(x, w)\n real(sp), dimension(:), intent(in) :: x\n integer, intent(in), optional :: w\n end function var_1_sp\n module function var_2_sp(A, w, dim)\n real(sp), dimension(:), allocatable :: var_2_sp\n real(sp), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: w, dim\n end function var_2_sp\n real(dp) module function var_1_dp(x, w)\n real(dp), dimension(:), intent(in) :: x\n integer, intent(in), optional :: w\n end function var_1_dp\n module function var_2_dp(A, w, dim)\n real(dp), dimension(:), allocatable :: var_2_dp\n real(dp), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: w, dim\n end function var_2_dp\n end interface var\n interface std\n !! `std` computes vector and matrix standard deviations.\n !!([Specification](../module/forlab_var.html))\n real(sp) module function std_1_sp(x, w)\n real(sp), dimension(:), intent(in) :: x\n integer, intent(in), optional :: w\n end function std_1_sp\n module function std_2_sp(A, w, dim)\n real(sp), dimension(:), allocatable :: std_2_sp\n real(sp), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: w, dim\n end function std_2_sp\n real(dp) module function std_1_dp(x, w)\n real(dp), dimension(:), intent(in) :: x\n integer, intent(in), optional :: w\n end function std_1_dp\n module function std_2_dp(A, w, dim)\n real(dp), dimension(:), allocatable :: std_2_dp\n real(dp), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: w, dim\n end function std_2_dp\n end interface std\n\nend module forlab_stats\n", "meta": {"hexsha": "1d36718bba54bd59dab144e407382b58c9c44d56", "size": 6986, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_stats.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/forlab_stats.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/forlab_stats.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.8538011696, "max_line_length": 71, "alphanum_fraction": 0.5844546235, "num_tokens": 1771, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693645535724, "lm_q2_score": 0.7981867777396211, "lm_q1q2_score": 0.7580135300110495}} {"text": "C> Calculate a four point interpolation from i-1 to i+2\nC> returns c array 4 of real*8 which are coeficients for\nC> \\f[\nC> f_i-c_1+c_2(r-r_i)\nC> +\\frac{(c_3-c_2)(r-r_i)+c_1}{1+c_4(r-r_i) (r_{i+1}-r)}\nC> \\f]\nC>\nC> It's obvious that \\f$ c_3=(f_{i+1}-f_i)/(r_{i+1}-r_i) \\f$.\nC> \\f$ c_2 \\f$ is adjustable and is chosen so to avoid possible singularities\nC> in eqns solving for \\f$ c_1 \\f$ and \\f$ c_4 \\f$.\nC> \\f[\nC> c_2=\\frac{f_{i+2}-f_{i+1}}{r_{i+2}-r_{i+1}}-\\frac{f_i-f_{i-1}}{r_i-r_{i-1}}\nC> \\f]\nC> and the sign is chosen so that it is opposite of\nC> \\f$ (f_{i+1}-f_{i-1})/(r_{i+1}-r_{i-1}) \\f$.\nC>\nC> @param r the mesh the function is defined on\nC> @param f the function to interpolate, defined on the meshpoint\nC> @param nr the size of the function and meshpoint tables\nC> @param i where to perform the interpolation based on four points i-1, i, i+1, i+2\nC> @param c the coefictients for the rational interpoalting function\n subroutine fit(r,f,nr,i,c)\n implicit real*8 (a-h,o-z)\n real*8 r(nr),f(nr),c(4)\nc does a four-point interpolation from i-1 to i+2\nc returns c array 4 of real*8 which are coeficients for\nc f(i)-c1+c2*(r-r(i))+((c3-c2)*(r-r(i))+c1)/(1+c4*(r-r(i))*(r(i+1)-r))\nc\nc It's obvious that c3=(f(i+1)-f(i))/(r(i+1)-r(i))\nc c2 is adjustable and is chosen so to avoid possible singularities\nc in eqns solving for c1 and c4.\nc\nc c2=((f(i+2)-f(i+1))/(r(i+2)-r(i+1))-(f(i)-f(i-1))/(r(i)-r(i-1)))\nc and the sign is chosen so that it is opposite of\nc (f(i+1)-f(i-1))/(r(i+1)-r(i-1))\nc\n\n if(i.lt.1) then\n write(6,'(''FIT: i<1'')')\n! call stop_with_backtrace('fit')\n stop 'fit'\n endif\n ip1=i+1\n if(ip1.gt.nr) then\n\tif(r(1).gt.r(nr)) then ! wrap around\n\t ip1=1\n\telse\n\twrite(6,*) \"FIT: i>n-1\",i,nr\n! call stop_with_backtrace('fit')\n\tstop 'fit'\n\tendif\n endif\n dr=r(ip1)-r(i)\n if(dr.eq.0.d0) then\n write(6,'(''FIT: degenerate grid'')')\n! call stop_with_backtrace('fit')\n stop'fit'\n endif\n drv=f(ip1)-f(i)\n c(3)=drv/dr\n\nc two point interpolation\n if(nr.eq.2) then\n\tc(1)=f(i)\n\tc(2)=0.d0\n\tc(4)=0.d0\n\treturn\n endif\n\nc fit the function to the two outside points\n if(i.gt.1) then\n i1=i-1\n else\n i1=min(4,nr)\n endif\n if(ip1.lt.nr) then\n i2=ip1+1\n else\n i2=max(nr-3,1)\n endif\nc If nr=3 then i1=i2\n if(i1.ne.i2) then\n\tc(2)=(f(i2)-f(ip1))/(r(i2)-r(ip1))-(f(i1)-f(i))/(r(i1)-r(i))\n\tif(c(2)*(f(i2)-f(i1))*(r(i2)-r(i1)).gt.0.d0) c(2)=-c(2)\nc solve the 2x2 equation for c(1) and c(4)\n\th1=r(i1)-r(i)\n\tc0=f(i1)-f(i)\n\tc1=c0-c(3)*h1\n\tc2=c0-c(2)*h1\n h1=h1*(r(ip1)-r(i1))\n\teqn12=-h1*c2\n h2=r(i2)-r(i)\n\tc0=f(i2)-f(i)\n\tc3=c0-c(3)*h2\n\tc4=c0-c(2)*h2\n h2=h2*(r(ip1)-r(i2))\n\teqn22=-h2*c4\n\tgj=(c4-c2)*h1*h2\n\tif(gj.eq.0.d0) then\n\t c(4)=0.d0\n\telse\n\t c(1)=(c1*eqn22-c3*eqn12)/gj\n\t c(4)=(c1*h2-c3*h1)/gj\n\tendif\n\t\nc If the points are on a line or nearly a line then use linear\nc interpolation\nc check this by checking to see if the denominator 1+c4*(r-r(i))*(r(i+1)-r)\nc can be zero or negative. The minimum is 1-c4*dr*dr/4\n\tgj=c(4)*dr*dr\n if(gj.gt.-4.d0.and.abs(gj).gt.1.d-14.and.gj.lt.1.d+14) then\n\t c(1)=c(1)/c(4)\n else\n c(1)=f(i)\n c(4)=0.d0\n endif\n else ! i1=i2\nc set A4=0.5*(f(i)+f(i+1)) and do a 3 point fit\n fj=0.5d0*(f(i)+f(ip1))\n c(1)=f(i)-fj\n\tc(2)=0.d0\n rj=r(i)+0.5d0*dr\n if(abs(r(i1)-rj).gt.abs(r(i2)-rj)) i1=i2\n h1=r(i1)-r(i)\n\tc1=f(i1)-f(i)-c(3)*h1\n h1=h1*(r(ip1)-r(i1))\n if(f(i1).ne.fj) then\n\t c(4)=-c1/((f(i1)-fj)*h1)\n\t gj=c(4)*dr*dr\n if(gj.le.-4.d0.or.abs(gj).le.1.d-14.or.gj.ge.1.d+14) then\n c(1)=f(i)\n c(4)=0.d0\n endif\n else\n\t c(1)=f(i)\n\t c(4)=0.d0\n endif\n endif ! f(i1)=f(i2)\n\n return\n end\n", "meta": {"hexsha": "0a8d09e2c7f6495415a725908ea66bba4763462c", "size": 3866, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/Misc/fit.f", "max_stars_repo_name": "rdietric/lsms", "max_stars_repo_head_hexsha": "8d0d5f01186abf9a1cc54db3f97f9934b422cf92", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2020-01-05T20:05:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T09:08:01.000Z", "max_issues_repo_path": "src/Misc/fit.f", "max_issues_repo_name": "rdietric/lsms", "max_issues_repo_head_hexsha": "8d0d5f01186abf9a1cc54db3f97f9934b422cf92", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-07-30T13:59:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T17:43:35.000Z", "max_forks_repo_path": "lsms/src/Misc/fit.f", "max_forks_repo_name": "hkershaw-brown/MuST", "max_forks_repo_head_hexsha": "9db4bc5061c2f2c4d7dfd92f53b4ef952602c070", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-02-11T17:04:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T09:23:46.000Z", "avg_line_length": 27.2253521127, "max_line_length": 84, "alphanum_fraction": 0.5506983963, "num_tokens": 1672, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218412907381, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.7579941191083999}} {"text": "PROGRAM three\n IMPLICIT NONE\n REAL:: x, xe, beta, De, MorseVx, HarmonicVx\n CHARACTER*10:: filename\n INTEGER:: i, outunit\n xe = 0.74\n beta = 1.0\n De = 109.4 * 1.59 * (10**(-3.0))\n\n WRITE(filename, fmt = \"(a, i0)\") \"output.\", 1\n OPEN(UNIT = outunit, FILE = filename, FORM = \"formatted\")\n x = -4.2 \n DO i = 1, 100 \n x = x + 0.20\n MorseVx = De * (1 - EXP(-beta * (x - xe))) * (1 - EXP(-beta * (x - xe)))\n HarmonicVx = De * beta * beta * (x-xe) * (x-xe)\n WRITE(outunit, * ) x, MorseVx, HarmonicVx\n ENDDO\n CLOSE(outunit)\nEND\n", "meta": {"hexsha": "ea0fdd1c01bd5dc2e02caaece21c40dcb77dd5a6", "size": 615, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Practice-2/3.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Practice-2/3.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practice-2/3.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 29.2857142857, "max_line_length": 80, "alphanum_fraction": 0.487804878, "num_tokens": 229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7579941140616342}} {"text": "!================================================================================\n! ActIII es un codigo para colocar particulas sobre una malla cuadrada separadas \n! uniformemente. \n! Autor: Martin Alejandro Paredes Sosa\n!================================================================================\n\nModule Control\n Logical :: Impar !Control Impar Logico(T/F)\n Real *8 :: sep !Separacion de las particulas\nEnd Module Control\n \nsubroutine CalcPos(i, Pos)\n\n Use Control\n Implicit None\n Integer :: i !Contador\n Real *8 :: Pos !Posiciones\n If (Impar) Then\n Pos = ((-1)**i)*((int((i-1)/2)*sep)+ (sep) )\n Else\n Pos = ((-1)**i)*((int((i-1)/2)*sep)+ (sep/2) ) !Calculo de Posicion Caso Par\n End If\nEnd Subroutine CalcPos\n\n\nProgram ActIII\n\n Use Control\n Implicit None\n Real *8 :: l !Longitud Malla\n Integer :: k, m !Contadores\n Integer :: N !#Particulas \n Real *8 :: xPos, yPos !Posiciones Posibles para X y Y, Limitado a 500 Particulas Por Lado\n \n !Entrada de Datos\n Write(*,*) \"Numero de Particulas Por Lado de la Malla\"\n Read(*,*) N\n Write(*,*) \"Longitud del Lado de la Malla\"\n Read(*,*) l\n \n !Calculo de la Separacion Entre Particulas\n sep = l/N\n\n !Dectectando N Impar\n Impar = mod(N,2) /= 0\n \n Open(1,File=\"Output.dat\") !Abriendo Archivo de Salida\n \n k = 1\n m = 1\n !Calculo y Escritura de las posiciones de la malla cuadrada\n Do While(k <= N)\n If (k==1 .AND. Impar) Then !Control Para N Impar\n xPos = 0 !Primera Posicion en el centro (x=0)\n Else If (K/=1 .AND. Impar) Then\n call CalcPos(k-1, xPos) !Calculando Posicion sobre X (Impar)\n Else\n Call CalcPos(k, xPos) !Calculando posicion sobre X\n End If\n\n Do while(m <= N)\n\n If(m==1 .AND. Impar) Then !Control Para N Impar\n yPos = 0 !Primera Posicion en el centro (y=0)\n Else If (m/=1 .AND. Impar) Then\n call CalcPos(m-1, yPos) !Calculando Posicion sobre Y (Impar)\n Else\n Call CalcPos(m, yPos) !Calculando Posición Sobre Y\n End If\n\n Write(1,*) xPos, yPos !Escribiendo en Salida\n m = m+1 !Avanzar Contador\n End Do\n \n m=1 !Reiniciar el Contador\n k = k+1 !Avanzar Contador\n End Do\n \n Close(1)\n \nEnd Program ActIII\n", "meta": {"hexsha": "233de8fee306cd591edb7b73a58fa517489f6d7c", "size": 2793, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Portafolio_I/Tarea_I/Act_3/Act3.f03", "max_stars_repo_name": "maps16/DesExpII", "max_stars_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Portafolio_I/Tarea_I/Act_3/Act3.f03", "max_issues_repo_name": "maps16/DesExpII", "max_issues_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Portafolio_I/Tarea_I/Act_3/Act3.f03", "max_forks_repo_name": "maps16/DesExpII", "max_forks_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.0609756098, "max_line_length": 116, "alphanum_fraction": 0.4633011099, "num_tokens": 721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921834855049, "lm_q2_score": 0.8221891283434877, "lm_q1q2_score": 0.7579941098003015}} {"text": "module expIntegral_module\nUSE nrtype\nimplicit none\nprivate\npublic::expint\ncontains\n\n ! Numerical recipes routines removed; use code from UEB-Veg\n\n ! ****************** EXPONENTIAL INTEGRAL FUNCTION *****************************************\n ! From UEB-Veg\n ! Computes the exponential integral function for the given value\n FUNCTION EXPINT (LAI)\n REAL(DP) LAI\n REAL(DP) EXPINT\n REAL(DP) a0,a1,a2,a3,a4,a5,b1,b2,b3,b4\n real(dp),parameter :: verySmall=tiny(1.0_dp) ! a very small number\n IF (LAI < verySmall)THEN\n EXPINT=1._dp\n\n ELSEIF (LAI.LE.1.0) THEN\n a0=-.57721566_dp\n a1=.99999193_dp\n a2=-.24991055_dp\n a3=.05519968_dp\n a4=-.00976004_dp\n a5=.00107857_dp\n\n EXPINT = a0+a1*LAI+a2*LAI**2+a3*LAI**3+a4*LAI**4+a5*LAI**5 - log(LAI)\n\n ELSE\n a1=8.5733287401_dp\n a2=18.0590169730_dp\n a3=8.6347637343_dp\n a4=.2677737343_dp\n b1=9.5733223454_dp\n b2=25.6329561486_dp\n b3=21.0996530827_dp\n b4=3.9584969228_dp\n\n EXPINT=(LAI**4+a1*LAI**3+a2*LAI**2+a3*LAI+a4)/ &\n ((LAI**4+b1*LAI**3+b2*LAI**2+b3*LAI+b4)*LAI*exp(LAI))\n\n END IF\n RETURN\n END FUNCTION EXPINT\n\nEND MODULE expIntegral_module\n", "meta": {"hexsha": "8045e0f04cdf4b735cddaafa7dba9c6ef347c8e4", "size": 1098, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lis/surfacemodels/land/summa.1.0/engine/expIntegral_module.f90", "max_stars_repo_name": "KathyNie/LISF", "max_stars_repo_head_hexsha": "5c3e8b94494fac5ff76a1a441a237e32af420d06", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 67, "max_stars_repo_stars_event_min_datetime": "2018-11-13T21:40:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-23T08:11:56.000Z", "max_issues_repo_path": "lis/surfacemodels/land/summa.1.0/engine/expIntegral_module.f90", "max_issues_repo_name": "dmocko/LISF", "max_issues_repo_head_hexsha": "08d024d6d5fe66db311e43e78740842d653749f4", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 679, "max_issues_repo_issues_event_min_datetime": "2018-11-13T20:10:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T19:55:25.000Z", "max_forks_repo_path": "lis/surfacemodels/land/summa.1.0/engine/expIntegral_module.f90", "max_forks_repo_name": "dmocko/LISF", "max_forks_repo_head_hexsha": "08d024d6d5fe66db311e43e78740842d653749f4", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 119, "max_forks_repo_forks_event_min_datetime": "2018-11-08T15:53:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T10:16:01.000Z", "avg_line_length": 22.4081632653, "max_line_length": 93, "alphanum_fraction": 0.6739526412, "num_tokens": 433, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533107374443, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.7579608153672034}} {"text": "\r\nsubroutine foo(a, n, m, b)\r\n implicit none\r\n\r\n real, intent(in) :: a(n, m)\r\n integer, intent(in) :: n, m\r\n real, intent(out) :: b(size(a, 1))\r\n\r\n integer :: i\r\n\r\n do i = 1, size(b)\r\n b(i) = sum(a(i,:))\r\n enddo\r\nend subroutine\r\n\r\nsubroutine trans(x,y)\r\n implicit none\r\n real, intent(in), dimension(:,:) :: x\r\n real, intent(out), dimension( size(x,2), size(x,1) ) :: y\r\n integer :: N, M, i, j\r\n N = size(x,1)\r\n M = size(x,2)\r\n DO i=1,N\r\n do j=1,M\r\n y(j,i) = x(i,j)\r\n END DO\r\n END DO\r\nend subroutine trans\r\n\r\nsubroutine flatten(x,y)\r\n implicit none\r\n real, intent(in), dimension(:,:) :: x\r\n real, intent(out), dimension( size(x) ) :: y\r\n integer :: N, M, i, j, k\r\n N = size(x,1)\r\n M = size(x,2)\r\n k = 1\r\n DO i=1,N\r\n do j=1,M\r\n y(k) = x(i,j)\r\n k = k + 1\r\n END DO\r\n END DO\r\nend subroutine flatten\r\n", "meta": {"hexsha": "2ad165877748ed6084daa804d9d57ee011c8f55a", "size": 859, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "libs/numpy/f2py/tests/src/size/foo.f90", "max_stars_repo_name": "rocketbot-cl/recognition", "max_stars_repo_head_hexsha": "cca8a87070ccaca3a26e37345c36ab1bf836e258", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 353, "max_stars_repo_stars_event_min_datetime": "2020-12-10T10:47:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:08:29.000Z", "max_issues_repo_path": "libs/numpy/f2py/tests/src/size/foo.f90", "max_issues_repo_name": "rocketbot-cl/recognition", "max_issues_repo_head_hexsha": "cca8a87070ccaca3a26e37345c36ab1bf836e258", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 80, "max_issues_repo_issues_event_min_datetime": "2020-12-10T09:54:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T22:08:45.000Z", "max_forks_repo_path": "libs/numpy/f2py/tests/src/size/foo.f90", "max_forks_repo_name": "rocketbot-cl/recognition", "max_forks_repo_head_hexsha": "cca8a87070ccaca3a26e37345c36ab1bf836e258", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2020-12-10T17:10:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T16:27:07.000Z", "avg_line_length": 19.0888888889, "max_line_length": 60, "alphanum_fraction": 0.5064027939, "num_tokens": 307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.8688267745399466, "lm_q1q2_score": 0.7579187500532903}} {"text": "C$Procedure VHATIP ( \"V-Hat\", 3-d unit vector along V, in place )\n \n SUBROUTINE VHATIP ( V )\n \nC$ Abstract\nC\nC Scale a three-dimensional vector to unit length.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC VECTOR\nC\nC$ Declarations\n \n DOUBLE PRECISION V ( 3 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC V I-O Vector to be normalized/unit vector.\nC\nC$ Detailed_Input\nC\nC V This is any double precision, 3-dimensional vector. If\nC this vector is the zero vector, this routine will detect\nC it, and will not attempt to divide by zero.\nC\nC$ Detailed_Output\nC\nC V V contains the unit vector in the direction of the input\nC vector. If on input V represents the zero vector, then\nC V will be returned as the zero vector.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC 1) The zero vector is returned if the input value of V is the\nC zero vector.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC This routine is provided for situation where it is convenient\nC to scale a vector to unit length in place rather than store\nC the result in a separate variable. Note that the call\nC \nC CALL VHAT ( V, V )\nC\nC is not permitted by the ANSI Fortran 77 standard; this routine\nC can be called instead to achieve the same result.\nC\nC VHATIP determines the magnitude of V and then, if the magnitude\nC is non-zero, divides each component of V by the magnitude. This\nC process is highly stable over the whole range of 3-dimensional\nC vectors.\nC\nC$ Examples\nC\nC The following table shows how selected vectors are mapped to\nC unit vectors\nC\nC V on input V on output\nC ------------------ ------------------\nC (5, 12, 0) (5/13, 12/13, 0)\nC (1D-7, 2D-7, 2D-7) (1/3, 2/3, 2/3)\nC\nC$ Restrictions\nC\nC There is no known case whereby floating point overflow may occur.\nC Thus, no error recovery or reporting scheme is incorporated\nC into this subroutine.\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC H.A. Neilan (JPL)\nC W.M. Owen (JPL)\nC W.L. Taber (JPL)\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Version\nC\nC- SPICELIB Version 1.1.0, 01-SEP-2005 (NJB) (HAN) (WMO) (WLT)\nC\nC-&\n \nC$ Index_Entries\nC\nC unitize a 3-dimensional vector in place\nC\nC-&\n \n\n \nC\nC SPICELIB functions\nC\n DOUBLE PRECISION VNORM\n\nC\nC Local variables\nC\n DOUBLE PRECISION VMAG\n\n\nC\nC Obtain the magnitude of V.\nC\n VMAG = VNORM ( V )\n\nC\nC If VMAG is nonzero, then normalize. Note that this process is\nC numerically stable: overflow could only happen if VMAG were\nC small, but this could only happen if each component of V1 were\nC small. In fact, the magnitude of any vector is never less than\nC the magnitude of any component.\nC\n IF ( VMAG .GT. 0.D0 ) THEN\n\n V(1) = V(1) / VMAG\n V(2) = V(2) / VMAG\n V(3) = V(3) / VMAG\n\n ELSE\n\n V(1) = 0.D0\n V(2) = 0.D0\n V(3) = 0.D0\n\n END IF\n \n RETURN\n END\n", "meta": {"hexsha": "963d6a17072d7dbd2412e1118abb8085fe6701c7", "size": 4597, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/vhatip.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/vhatip.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/vhatip.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 26.2685714286, "max_line_length": 71, "alphanum_fraction": 0.6486839243, "num_tokens": 1351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7577533495543869}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! BenchIT - Performance Measurement for Scientific Applications\n! Contact: developer@benchit.org\n!\n! $Id: matmul.f90 1 2009-09-11 12:26:19Z william $\n! $URL: svn+ssh://william@rupert.zih.tu-dresden.de/svn-base/benchit-root/BenchITv6/kernel/numerical/cannon/F95/MPI/0/double/matmul.f90 $\n! For license details see COPYING in the package base directory\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! Kernel: a MPI version of matrix-matrix multiplication\n! (cannon algotithm)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nSUBROUTINE multijk( matrixC, matrixA, matrixB, mA, nA, nB )\n\tINTEGER(kind=4) :: i, j, k, mA, nA, nB\n\tREAL(kind=8), DIMENSION(:, :) :: matrixC(mA,nB), matrixA(mA,nA), matrixB(nA,nB)\n\n\tDO i=1, mA\n\t\tDO j=1, nB\n\t\t\tDO k=1, nA\n\t\t\t\tmatrixC(i,j) = matrixC(i,j) + matrixA(i,k)*matrixB(k,j)\n\t\t\tEND DO\n\t\tEND DO\n\tEND DO\n\nEND SUBROUTINE multijk\n\nSUBROUTINE multikj( matrixC, matrixA, matrixB, mA, nA, nB )\n\tINTEGER(kind=4) :: i, j, k, mA, nA, nB\n\tREAL(kind=8), DIMENSION(:, :) :: matrixC(mA,nB), matrixA(mA,nA), matrixB(nA,nB)\n\n\tDO i=1, mA\n\t\tDO k=1, nA\n\t\t\tDO j=1, nB\n\t\t\t\tmatrixC(i,j) = matrixC(i,j) + matrixA(i,k)*matrixB(k,j)\n\t\t\tEND DO\n\t\tEND DO\n\tEND DO\n\nEND SUBROUTINE multikj\n\nSUBROUTINE multjik( matrixC, matrixA, matrixB, mA, nA, nB )\n\tINTEGER(kind=4) :: i, j, k, mA, nA, nB\n\tREAL(kind=8), DIMENSION(:, :) :: matrixC(mA,nB), matrixA(mA,nA), matrixB(nA,nB)\n\n\tDO j=1, nB\n\t\tDO i=1, mA\n\t\t\tDO k=1, nA\n\t\t\t\tmatrixC(i,j) = matrixC(i,j) + matrixA(i,k)*matrixB(k,j)\n\t\t\tEND DO\n\t\tEND DO\n\tEND DO\n\nEND SUBROUTINE multjik\n\nSUBROUTINE multjki( matrixC, matrixA, matrixB, mA, nA, nB )\n\tINTEGER(kind=4) :: i, j, k, mA, nA, nB\n\tREAL(kind=8), DIMENSION(:, :) :: matrixC(mA,nB), matrixA(mA,nA), matrixB(nA,nB)\n\n\tDO j=1, nB\n\t\tDO k=1, nA\n\t\t\tDO i=1, mA\n\t\t\t\tmatrixC(i,j) = matrixC(i,j) + matrixA(i,k)*matrixB(k,j)\n\t\t\tEND DO\n\t\tEND DO\n\tEND DO\n\nEND SUBROUTINE multjki\n\nSUBROUTINE multkij( matrixC, matrixA, matrixB, mA, nA, nB )\n\tINTEGER(kind=4) :: i, j, k, mA, nA, nB\n\tREAL(kind=8), DIMENSION(:, :) :: matrixC(mA,nB), matrixA(mA,nA), matrixB(nA,nB)\n\n\tDO k=1, nA\n\t\tDO i=1, mA\n\t\t\tDO j=1, nB\n\t\t\t\tmatrixC(i,j) = matrixC(i,j) + matrixA(i,k)*matrixB(k,j)\n\t\t\tEND DO\n\t\tEND DO\n\tEND DO\n\nEND SUBROUTINE multkij\n\nSUBROUTINE multkji( matrixC, matrixA, matrixB, mA, nA, nB )\n\tINTEGER(kind=4) :: i, j, k, mA, nA, nB\n\tREAL(kind=8), DIMENSION(:, :) :: matrixC(mA,nB), matrixA(mA,nA), matrixB(nA,nB)\n\n\tDO k=1, nA\n\t\tDO j=1, nB\n\t\t\tDO i=1, mA\n\t\t\t\tmatrixC(i,j) = matrixC(i,j) + matrixA(i,k)*matrixB(k,j)\n\t\t\tEND DO\n\t\tEND DO\n\tEND DO\n\nEND SUBROUTINE multkji\n\n", "meta": {"hexsha": "a1c5a6f5183695751dbb7a4e2afbec561f4a7b60", "size": 2645, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "kernel/numerical/cannon/F95/MPI/0/double/matmul.f90", "max_stars_repo_name": "Arka2009/x86_64-ubench-ecolab", "max_stars_repo_head_hexsha": "38461e73617c92449f85a84176cd108fb82434b2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "kernel/numerical/cannon/F95/MPI/0/double/matmul.f90", "max_issues_repo_name": "Arka2009/x86_64-ubench-ecolab", "max_issues_repo_head_hexsha": "38461e73617c92449f85a84176cd108fb82434b2", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "kernel/numerical/cannon/F95/MPI/0/double/matmul.f90", "max_forks_repo_name": "Arka2009/x86_64-ubench-ecolab", "max_forks_repo_head_hexsha": "38461e73617c92449f85a84176cd108fb82434b2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.2680412371, "max_line_length": 136, "alphanum_fraction": 0.5905482042, "num_tokens": 1060, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418283357703, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.757697728524957}} {"text": " SUBROUTINE BoostX(expH,A,Ap)\nc########################################################################\nc #\nc Makes Lorentz boost to X-axis direction!! #\nc 'bet' is relative velocity #\nc z z' #\nc | (K) | (K') #\nc | | #\nc | | #\nc | x | --> bet #\nc ---------> ------------> x' #\nc / / #\nc / / #\nc y/ y'/ #\nc # \nc expH = EXP(u) = Sqrt((1-bet)/(1+bet)) #\nc # \nc x0'= x0*ch(u)-x*sh(u) #\nc x' = x*ch(u) -x0*sh(u) #\nc y' = y #\nc z' = z #\nc #\nc For a reversed transformation: expH <--> 1/expH (bet <--> -bet !) #\nc #\nc########################################################################\n IMPLICIT NONE\n INTEGER i\n DOUBLE PRECISION A(0:3),Ap(0:3),At(0:3)\n DOUBLE PRECISION expH,A1pA0,A1mA0\n \n DO i=0,3\n At(i) = A(i) \n ENDDO\n\n A1pA0 = (At(1) + At(0))/2d0\n A1mA0 = (At(1) - At(0))/2d0\n\n Ap(0) = A1pA0/expH - A1mA0*expH\n Ap(1) = A1pA0/expH + A1mA0*expH\n Ap(2) = At(2)\n Ap(3) = At(3)\n \n RETURN\n END\n\n\n SUBROUTINE BoostZ(expH,A,Ap)\nc#######################################################################\nc #\nc Makes Lorentz boost to Z-axis direction!! #\nc 'bet' is relative velocity #\nc y y' #\nc | (K) | (K') #\nc | | #\nc | | #\nc | z | --> bet z' #\nc ---------> ------------> #\nc / / #\nc / / #\nc x/ x'/ #\nc # \nc expH = EXP(u) = Sqrt((1-bet)/(1+bet)) #\nc #\nc x0'= x0*ch(u)-x*sh(u) # \nc x' = x #\nc y' = y # \nc z' = z*ch(u)-x0*sh(u) #\nc #\nc For a reversed transformation: expH <--> 1/expH (bet <--> -bet !!) # \nc #\nc#######################################################################\n IMPLICIT NONE\n INTEGER i\n DOUBLE PRECISION A(0:3),Ap(0:3),At(0:3)\n DOUBLE PRECISION expH,A3pA0,A3mA0\n \n DO i=0,3\n At(i) = A(i) \n ENDDO\n\n A3pA0 = (At(3) + At(0))/2d0\n A3mA0 = (At(3) - At(0))/2d0\n\n Ap(0) = A3pA0/expH - A3mA0*expH\n Ap(1) = At(1)\n Ap(2) = At(2)\n Ap(3) = A3pA0/expH + A3mA0*expH\n \n RETURN\n END\n\n\n SUBROUTINE RotateY(theta,A,Ap)\nc###################################################\nc Makes rotation about Y-axis with theta angle!! #\nc ( Clockwise direction.. ) #\nc###################################################\n IMPLICIT NONE\n INTEGER i\n DOUBLE PRECISION A(0:3),Ap(0:3),At(0:3)\n DOUBLE PRECISION cosTh,sinTh,theta\n\n DO i=0,3\n At(i) = A(i) \n ENDDO\n \n cosTh = Dcos(theta) \n sinTh = Dsin(theta) \n\n Ap(1) = At(1)*cosTh - At(3)*sinTh\n Ap(2) = At(2)\n Ap(3) = At(3)*cosTh + At(1)*sinTh \n\n RETURN\n END\n\n\n SUBROUTINE RotateX(theta,A,Ap)\nc##################################################\nc Makes rotation about X-axis with theta angle!! # \nc ( Clockwise direction.. ) #\nc##################################################\n IMPLICIT NONE\n INTEGER i\n DOUBLE PRECISION A(0:3),Ap(0:3),At(0:3)\n DOUBLE PRECISION cosTh,sinTh,theta\n \n DO i=0,3\n At(i) = A(i) \n ENDDO\n\n cosTh = Dcos(theta) \n sinTh = Dsin(theta) \n\n Ap(1) = At(1)\n Ap(2) = At(2)*cosTh + At(3)*sinTh\n Ap(3) = At(3)*cosTh - At(2)*sinTh\n\n RETURN\n END\n\n\n SUBROUTINE RotateZ(theta,A,Ap)\nc##################################################\nc Makes rotation about Z-axis with theta angle!! # \nc ( Clockwise direction.. ) #\nc##################################################\n IMPLICIT NONE\n INTEGER i\n DOUBLE PRECISION A(0:3),Ap(0:3),At(0:3)\n DOUBLE PRECISION cosTh,sinTh,theta\n \n DO i=0,3\n At(i) = A(i) \n ENDDO\n\n cosTh = Dcos(theta) \n sinTh = Dsin(theta) \n\n Ap(1) = At(1)*cosTh + At(2)*sinTh\n Ap(2) = At(2)*cosTh - At(1)*sinTh\n Ap(3) = At(3)\n\n RETURN\n END\n\n\n SUBROUTINE GetAngles(X,theta,ph)\nc#############################################\nc Calculates the Polar(theta) and #\nc Azimuthal(ph) angles of X #\nc#############################################\n IMPLICIT NONE \n DOUBLE PRECISION X(0:3),theta,ph \n DOUBLE PRECISION XyXx,Xmod \n INCLUDE 'MC_Declare.h' \n\n Xmod = Dsqrt(X(1)**2 + X(2)**2 + X(3)**2)\n\n IF (Xmod.EQ.0d0) THEN\n PRINT*,\"ERROR IN GetAngles : ZERO VECTOR!!\"\n STOP\n ELSE\n theta = Dacos(X(3)/Xmod)\n IF (X(1).EQ.0d0.AND.X(2).GT.0d0) THEN\n ph = pi/2d0 \n ELSEIF (X(1).EQ.0d0.AND.X(2).LT.0d0) THEN\n ph = 3d0*pi/2d0 \n ELSE\n XyXx = Datan(Dabs(X(2))/Dabs(X(1)))\n IF (X(1).GT.0d0.AND.X(2).GT.0d0) THEN\n ph = XyXx\n ELSEIF (X(1).LT.0d0.AND.X(2).GT.0d0) THEN\n ph = pi - XyXx\n ELSEIF (X(1).LT.0d0.AND.X(2).LT.0d0) THEN\n ph = pi + XyXx\n ELSEIF (X(1).GT.0d0.AND.X(2).LT.0d0) THEN\n ph = 2d0*pi - XyXx\n ELSE\n PRINT*,\" \"\n PRINT*,\"ERROR In GetAngles : INCOMPLETE LOGIC!!\"\n PRINT*,\" \"\n STOP \n ENDIF\n ENDIF \n ENDIF \n\n RETURN\n END \n\n\n DOUBLE PRECISION FUNCTION getAngleXY(x,y)\nc###################################################\nc calculates the angle #\nc between x and y 3-vectors.. #\nc###################################################\n IMPLICIT NONE\n DOUBLE PRECISION x(0:3),y(0:3),cosTh\n DOUBLE PRECISION xMod,yMod,scalProd1\n \n xMod = Dsqrt(x(1)**2+x(2)**2+x(3)**2)\n yMod = Dsqrt(y(1)**2+y(2)**2+y(3)**2)\n IF ((xMod.NE.0d0).AND.(yMod.NE.0d0)) THEN\n scalProd1 = x(1)*y(1)+x(2)*y(2)+x(3)*y(3)\n cosTh = scalProd1/xMod/yMod\n getAngleXY = Dacos(cosTh)\n ELSE\n PRINT*,\"\"\n PRINT*,\"ERROR IN getAnglesXY() :\" \n PRINT*,\" ONE OF THE 3-VECTOR HAS ZERO LENGTH !!\"\n PRINT*,\"\"\n STOP\n ENDIF\n \n RETURN\n END \n", "meta": {"hexsha": "ed71a16fe9d57372ea192a79c46c5402e74b5189", "size": 8869, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Tauola1_1_5/SANC/SancLib_v1_02/BoostRotationLib.f", "max_stars_repo_name": "klendathu2k/StarGenerator", "max_stars_repo_head_hexsha": "7dd407c41d4eea059ca96ded80d30bda0bc014a4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T06:57:20.000Z", "max_issues_repo_path": "Tauola1_1_5/SANC/SancLib_v1_02/BoostRotationLib.f", "max_issues_repo_name": "klendathu2k/StarGenerator", "max_issues_repo_head_hexsha": "7dd407c41d4eea059ca96ded80d30bda0bc014a4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tauola1_1_5/SANC/SancLib_v1_02/BoostRotationLib.f", "max_forks_repo_name": "klendathu2k/StarGenerator", "max_forks_repo_head_hexsha": "7dd407c41d4eea059ca96ded80d30bda0bc014a4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.4219409283, "max_line_length": 77, "alphanum_fraction": 0.2747773142, "num_tokens": 2097, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475715065793, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7576720547354147}} {"text": "! Compute the matrix element on harmonic oscillator states\r\n! + k l\r\n! < m | (a ) (a) | n >\r\n!\r\n\r\nmodule mod_elem\r\n\r\n implicit none\r\n contains\r\n pure function elem(m, n, k, l)\r\n\r\n use, intrinsic :: iso_fortran_env\r\n implicit none\r\n\r\n integer(kind=int32), intent(in) :: m, n, k, l\r\n !real(kind=REAL128) :: elem\r\n real(kind=real64) :: elem\r\n\r\n integer(kind=int32) :: i\r\n\r\n elem = 0.\r\n\r\n if(m /= n - l + k) then\r\n return\r\n endif\r\n if(n < l) then\r\n return\r\n endif\r\n elem = 1.\r\n ! Apply creation operator\r\n do i = 0, l - 1\r\n !elem = elem * sqrt(real(n - i, 16))\r\n elem = elem * sqrt(real(n - i, 8))\r\n end do\r\n ! Apply anihilation operator\r\n do i = 1, k\r\n !elem = elem * sqrt(real(n - l + i, 16))\r\n elem = elem * sqrt(real(n - l + i, 8))\r\n end do\r\n\r\n end function elem\r\n\r\nend module mod_elem\r\n", "meta": {"hexsha": "8a70e0fc2c6583902232f3ea11d9422d4d2954fd", "size": 951, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source/Fortran/Hamiltonian/mod_elem.f90", "max_stars_repo_name": "SebastianM-C/Bachelor-Thesis", "max_stars_repo_head_hexsha": "30ced37a8638e71ff5fc53d2dd4b608f0f9f8d02", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-19T23:15:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-19T23:15:42.000Z", "max_issues_repo_path": "Source/Fortran/Hamiltonian/mod_elem.f90", "max_issues_repo_name": "SebastianM-C/Bachelor-Thesis", "max_issues_repo_head_hexsha": "30ced37a8638e71ff5fc53d2dd4b608f0f9f8d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Source/Fortran/Hamiltonian/mod_elem.f90", "max_forks_repo_name": "SebastianM-C/Bachelor-Thesis", "max_forks_repo_head_hexsha": "30ced37a8638e71ff5fc53d2dd4b608f0f9f8d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-19T23:15:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-19T23:15:46.000Z", "avg_line_length": 21.6136363636, "max_line_length": 62, "alphanum_fraction": 0.4815983176, "num_tokens": 280, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475810629193, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.7576720490775809}} {"text": "!Intrinsic_Function_Of_Array\nprogram Intrinsic_Function_Of_Array\n implicit none\n\n INTEGER :: i, j\n INTEGER :: a(5), mat(3, 4)\n\n a = (/10, 50, 64, 75, 23/)\n\n mat = reshape((/1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12/), (/3, 4/))\n\n print *, \"One Dimension Matrices\"\n do i = 1, 5\n print *, a(i)\n end do\n\n print *, \"\"\n\n print *, \"Two Dimension Matrices\"\n do i = 1, 3\n print *, (mat(i, j), j=1, 4)\n end do\n\n print *, \"\"\n\n print *, \"The shape of a is \", shape(a)\n print *, \"The shape of mat is \", shape(mat)\n\n print *, \"\"\n\n print *, \"The size of a is \", size(a)\n print *, \"The size of mat is \", size(mat)\n\n print *, \"\"\n\n print *, \"The rank of a is \", rank(a)\n print *, \"The rank of mat is \", rank(mat)\n\n print *, \"\"\n\n print *, \"The sum of all element of a is \", sum(a)\n print *, \"The sum of all element of mat is \", sum(mat)\n\n print *, \"\"\n\n print *, \"The sum of all element of a greater than 40 is \", sum(a, a > 40)\n print *, \"The sum of all element of mat less than 6 is \", sum(mat, mat < 6)\n\n print *, \"\"\n\n print *, \"The product of all element of a is \", product(a)\n print *, \"The product of all element of mat is \", product(mat)\n\n print *, \"\"\n\n print *, \"The product of all element of a greater than 40 is \", product(a, a > 40)\n print *, \"The product of all element of mat less than 6 is \", product(mat, mat < 6)\n\n print *, \"\"\n\n print *, \"Number of element in a greater than 40 is \", count(a > 40)\n print *, \"Number of element in mat less than 6 is \", count(mat < 6)\n\n print *, \"\"\n\n print *, \"Maximum value in a is \", MAXVAL(a)\n print *, \"Maximum value in mat is \", MAXVAL(mat)\n\n print *, \"\"\n\n print *, \"Minimum value in a is \", MINVAL(a)\n print *, \"Minimum value in mat is \", MINVAL(mat)\n\n print *, \"\"\n\n print *, \"Is all value in a is greater than 40: \", all(a > 40)\n print *, \"Is all value in mat is less than 20: \", all(mat < 20)\n\n print *, \"\"\n\n print *, \"Is any value in a is less than 40: \", any(a < 40)\n print *, \"Is any value in mat is greater than 20: \", any(mat > 20)\n\nend program Intrinsic_Function_Of_Array\n", "meta": {"hexsha": "7b6f14cecb79ac322e21c9aa361663e8b357feb4", "size": 2169, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Intrinsic_Function_Of_Array.f95", "max_stars_repo_name": "SusheelThapa/Code-With-FORTRAN", "max_stars_repo_head_hexsha": "4956fc1db5a0ce7e88883fdd787a3fd13a3b7fda", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Intrinsic_Function_Of_Array.f95", "max_issues_repo_name": "SusheelThapa/Code-With-FORTRAN", "max_issues_repo_head_hexsha": "4956fc1db5a0ce7e88883fdd787a3fd13a3b7fda", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Intrinsic_Function_Of_Array.f95", "max_forks_repo_name": "SusheelThapa/Code-With-FORTRAN", "max_forks_repo_head_hexsha": "4956fc1db5a0ce7e88883fdd787a3fd13a3b7fda", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.5176470588, "max_line_length": 87, "alphanum_fraction": 0.5573997234, "num_tokens": 663, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127603871312, "lm_q2_score": 0.8872045847699186, "lm_q1q2_score": 0.7575953160089997}} {"text": " SUBROUTINE shape7(a2,a3,shape,deriv)\r\n IMPLICIT NONE\r\n REAL (kind=8) a2,a3,shape(6),deriv(6,2)\r\n REAL (kind=8) a1\r\n\r\n a1 = 1d0-a2-a3\r\n\r\n shape(1) = (2d0*a1-1d0)*a1\r\n shape(2) = (2d0*a2-1d0)*a2\r\n shape(3) = (2d0*a3-1d0)*a3\r\n shape(4) = 4d0*a1*a2\r\n shape(5) = 4d0*a2*a3\r\n shape(6) = 4d0*a1*a3\r\n\r\n deriv(1,1) = 1d0-4d0*a1\r\n deriv(2,1) = 4d0*a2-1d0\r\n deriv(3,1) = 0d0\r\n deriv(4,1) = 4d0*(a1-a2)\r\n deriv(5,1) = 4d0*a3\r\n deriv(6,1) = -4d0*a3\r\n deriv(1,2) = 1d0-4d0*a1\r\n deriv(2,2) = 0d0\r\n deriv(3,2) = 4d0*a3-1d0\r\n deriv(4,2) = -4d0*a2\r\n deriv(5,2) = 4d0*a2\r\n deriv(6,2) = 4d0*(a1-a3)\r\n RETURN\r\n END SUBROUTINE shape7\r\n", "meta": {"hexsha": "548bf28fe68b05341be650b5d06e8249cbf74e74", "size": 624, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/shelt/shape7.f90", "max_stars_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_stars_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/shelt/shape7.f90", "max_issues_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_issues_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/shelt/shape7.f90", "max_forks_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_forks_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.5172413793, "max_line_length": 41, "alphanum_fraction": 0.5705128205, "num_tokens": 364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172659321807, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7574132102804346}} {"text": "! **************************************************************************\n! ... eof.f90\n! ... Quim Ballabrera, March 2013\n! ...\n! ... System Dynamics\n! ...\n! **************************************************************************\n\nprogram eof\n\nuse sysdyn\n\nimplicit none\n\nlogical Zexist\ninteger i,j,k,Nv,Nt,step,rank,iu\n\nreal(dp) xsum,xsum2\nreal(dp), dimension(:), allocatable :: Zm,Zs\nreal(dp), dimension(:,:), allocatable :: Z,cov\nreal(dp), dimension(:), allocatable :: Lambda,ev,pc\nreal(dp), dimension(:,:), allocatable :: U\nreal(dp), dimension(:), allocatable :: T\n\ncharacter(len=180) nfile,tfile,cfile,efile,pfile,mfile,sfile,xfile\ncharacter(len=180) rfile,line\n\nnamelist/nameof/tfile, &\n cfile, &\n efile, &\n pfile, &\n mfile, &\n sfile, &\n xfile\n\ncall header()\n\ntfile = 'lorenz_simulation.dat'\nmfile = 'lorenz.mean'\nsfile = 'lorenz.stdv'\ncfile = 'lorenz.cov'\nrfile = 'lorenz.cor'\nefile = 'lorenz.eof'\nxfile = 'lorenz.spm'\npfile = 'lorenz.pc'\n\nnfile = ''\nCALL getarg(1,nfile)\ninquire(file=nfile,exist=Zexist)\n\nif (len_trim(nfile).gt.0) then\n if (Zexist) then\n write(*,*) 'Reading ', trim(nfile)\n iu = unitfree()\n open(iu,FILE=nfile,STATUS='old')\n rewind(iu)\n read(iu,nameof)\n close(iu)\n else\n call stop_error (1,'Namelist file not found')\n endif\nendif\n\n\n! ... Open input trajectory\n! ...\niu = unitfree()\nwrite(*,*) 'Opening file ', trim(tfile)\nopen(iu,file=tfile,status='old')\nrewind(iu)\nNt = numlines(iu)\n\nrewind(iu)\nread(iu,'(A)') line\nNv = numwords(line) - 1\n\nallocate (Z(Nv,Nt))\nallocate (T(Nt))\nallocate (Zs(Nv))\nallocate (cov(Nv,Nv))\n\n! ... Load the data:\n! ...\nrewind(iu)\ndo step=1,Nt\n READ(iu,*) T(step),Z(:,step)\nenddo\nclose(iu)\n\n! ... Long term mean:\n! ...\nallocate (Zm(Nv))\nZm(:) = 0.0D0\ndo step=1,Nt\n Zm(:) = Zm(:) + Z(:,step)\nenddo\nZm(:) = Zm(:) / Nt\n\nwrite(*,*) 'Saving long term mean ', trim(mfile)\nopen(iu,file=mfile,status='unknown')\nrewind(iu)\nwrite(iu,*) 0.0, SNGL(Zm)\nclose(iu)\n\n! ... Anomalies:\n! ...\ndo i=1,Nv\n Z(i,:) = Z(i,:) - Zm(i)\nenddo\n\n! ... Calculate the covariance matrix\n! ...\ndo j=1,Nv\ndo i=j,Nv\n xsum = 0.0D0\n do k=1,Nt\n xsum = xsum + Z(i,k)*Z(j,k)\n enddo\n cov(i,j) = xsum / (Nt-1.0D0)\n cov(j,i) = cov(i,j)\nenddo\nenddo\n\nwrite(*,*) 'Covariance : '\ndo i=1,Nv\n write(*,'(100F9.3)') cov(i,:)\nenddo\n\nwrite(*,*) 'Saving covariance matrix ', trim(cfile)\niu = unitfree()\nopen(iu,file=cfile,status='unknown')\nrewind(iu)\nwrite(iu,*) Nv, Nv\ndo j=1,Nv\n write(iu,*) cov(:,j)\nenddo\nclose(iu)\n\n\n! ... Standard deviation\n! ...\ndo i=1,Nv\n Zs(i) = SQRT(DOT_PRODUCT(Z(i,:),Z(i,:))/(Nt-1.0D0))\nenddo\n\nwrite(*,*) 'Saving standard deviation ', trim(sfile)\nopen(iu,file=sfile,status='unknown')\nrewind(iu)\nwrite(iu,*) 0.0D0, SNGL(Zs)\nclose(iu)\n\n\n! ... Scale the anomalies:\n! ...\ndo i=1,Nv\n Z(i,:) = Z(i,:)/Zs(i)\nenddo\n\n! ... Calculate the correlation matrix\n! ...\ndo j=1,Nv\ndo i=j,Nv\n xsum = 0.0D0\n do k=1,Nt\n xsum = xsum + Z(i,k)*Z(j,k)\n enddo\n cov(i,j) = xsum / (Nt-1.0D0)\n cov(j,i) = cov(i,j)\nenddo\nenddo\n\nwrite(*,*)\nwrite(*,*) 'Mean : '\nwrite(*,*) SNGL(Zm)\nwrite(*,*) 'Standard deviation : '\nwrite(*,*) SNGL(Zs)\nwrite(*,*) 'Correlation : '\ndo i=1,Nv\n write(*,'(100F9.3)') cov(i,:)\nenddo\n\n! ... Save the covariance matrix\n! ...\nwrite(*,*) 'Saving correlation matrix ', trim(rfile)\niu = unitfree()\nopen(iu,file=rfile,status='unknown')\nrewind(iu)\nwrite(iu,*) Nv, Nv\ndo j=1,Nv\n write(iu,*) cov(:,j)\nenddo\nclose(iu)\n\n\n! ... Just to be safe: print the trace of the covariance matrix:\n! ...\nxsum = 0.0D0\ndo i=1,Nv\ndo k=1,Nt\n xsum = xsum + Z(i,k)*Z(i,k)\nenddo\nenddo\nwrite(*,*) 'Trace coavariance matrix (Z Z^T): ', xsum/(Nt-1.0D0)\n\n! ... EOFs:\n! ...\nrank = MIN(nv,nt-1)\nwrite(*,*) 'Rank: ', rank\n\nallocate (U(Nv,rank))\nallocate (Lambda(rank))\n\ncall get_the_eofs (Z,Nv,Nt,rank,U,Lambda)\n\n! ... The covariance matrix seen by the EOFs: Cov = U Lambda U^T\n! ...\nxsum = 0.0D0\ndo i=1,Nv\ndo k=1,rank\n xsum = xsum + Lambda(k)*U(i,k)*U(i,k)\nenddo\nenddo\nwrite(*,*) 'Trace coavariance matrix (U Lambda U^T): ', xsum\n\n! ... Explained variance:\n! ...\nallocate (ev(rank))\nxsum = SUM(Lambda(:))\nxsum2 = 0.0D0\ndo k=1,rank\n xsum2 = xsum2 + 100.0D0*Lambda(k)/xsum\n ev(k) = xsum2\nenddo\n\nwrite(*,*) 'Saving scpectrum file ', trim(xfile)\niu = unitfree()\nopen (iu,file=xfile,status='unknown')\nrewind(iu)\ndo k=1,rank\n write(iu,'(i5,F18.5,2F9.3)') k, Lambda(k), 100.0*Lambda(k)/xsum, ev(k)\nenddo\nclose(iu)\n\nwrite(*,*) 'Saving the EOFs matrix ', trim(efile)\niu = unitfree()\nopen(iu,file=efile,status='unknown')\nrewind(iu)\nwrite(iu,*) Nv, rank\ndo k=1,rank\n write(iu,*) U(:,k)\nenddo\nclose(iu)\n\n! ... Principal components:\n! ...\nallocate (pc(rank))\nwrite(*,*) 'Saving the PC matrix ', trim(pfile)\niu = unitfree()\nopen(iu,file=pfile,status='unknown')\nrewind(iu)\n\ndo step=1,Nt\n do k=1,rank\n xsum = 0.0D0\n do i=1,Nv\n xsum = xsum + U(i,k)*Z(i,step)\n enddo\n pc(k) = xsum\n enddo\n write(iu,'(4F10.4)') T(step), pc(:)\nenddo\nclose(iu)\n\n\ncall stop_error (0,'EOF Ok')\nend program eof\n! ...\n! =====================================================================\n! ... \nSUBROUTINE get_the_eofs (Z,Nv,Nt,rank,U,Lambda)\n\nuse sysdyn\n\nimplicit none\n\ninteger Nv,Nt,rank\nreal(dp), dimension(Nv,Nt), intent(in) :: Z\nreal(dp), dimension(Nv,rank), intent(out) :: U\nreal(dp), dimension(rank), intent(out) :: Lambda\n\ninteger Nm,k\nreal(dp), dimension(:), allocatable :: DD\nreal(dp), dimension(:,:), allocatable :: UU,VV\n\n\nif (Nv.GE.Nt) then\n write(*,*) 'Singular Value Decomposition of Z ...'\n\n Nm = Nt\n allocate (UU(Nv,Nt))\n allocate (VV(Nt,Nt))\n allocate (DD(Nt))\n\n UU(:,:) = Z(:,:)\n call svdcmp (UU,Nv,Nt,Nv,Nt,DD,VV)\n\nelse\n write(*,*) 'Singular Value Decomposition of Z^T ...'\n\n Nm = Nv\n allocate (UU(Nv,Nv))\n allocate (VV(Nt,Nv))\n allocate (DD(Nv))\n\n VV = TRANSPOSE(Z)\n call svdcmp (VV,Nt,Nv,Nt,Nv,DD,UU)\n\nendif\n\nDD(:) = DD(:)**2\ncall eigsort (DD,Nm,UU,Nv)\n\nIF (rank.GT.Nm) call stop_error(1,'ERROR: rank to large !!!!!')\n\n! ... Output arrays:\n! ...\ndo k=1,rank\n Lambda(k) = DD(k)/(Nt-1.0D0)\n U(:,k) = UU(:,k)\nenddo\n\ndeallocate (UU)\ndeallocate (VV)\ndeallocate (DD)\n\nreturn\nend\n! ...\n! ====================================================================\n! ...\n", "meta": {"hexsha": "84df5b12abe0283545a8af691a2b3a218e0c03f7", "size": 6297, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/eof/eof.f90", "max_stars_repo_name": "quimbp/system_dynamics", "max_stars_repo_head_hexsha": "366339d9f6fea2e4242f8a73b700f8ea0af07797", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-22T13:23:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-22T13:23:22.000Z", "max_issues_repo_path": "src/eof/eof.f90", "max_issues_repo_name": "quimbp/system_dynamics", "max_issues_repo_head_hexsha": "366339d9f6fea2e4242f8a73b700f8ea0af07797", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/eof/eof.f90", "max_forks_repo_name": "quimbp/system_dynamics", "max_forks_repo_head_hexsha": "366339d9f6fea2e4242f8a73b700f8ea0af07797", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.4662756598, "max_line_length": 76, "alphanum_fraction": 0.5678894712, "num_tokens": 2288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.757373430441577}} {"text": "module procedures\nimplicit none\ncontains\n\nsubroutine writes2d (A)\n real(kind=8), allocatable, dimension(:,:), intent(in) :: A\n integer :: n, m, i, j\n\n n = size(A, 1)\n m = size(A, 2)\n\n do i = 1,n\n write(*,'(20F8.3)') (A(i,j), j = 1, m)\n end do\n write(*,*)\nend subroutine writes2d\n\nsubroutine writes1d (A)\n real(kind=8), allocatable, dimension(:), intent(in) :: A\n integer :: n, i\n \n n = size(A)\n\n write(*,'(20F8.3)') (A(i), i = 1, n)\n write(*,*)\nend subroutine writes1d\n\nsubroutine Gauss_Elimination (A, n, M)\n real(kind=8), allocatable, dimension(:,:), intent(inout) :: A\n integer, intent(in) :: n !dimension\n real(kind=8), allocatable, dimension(:,:), intent(out) :: M\n real(kind=8) :: temp1, temp2\n integer :: i, j, k\n\n ! Initialize M:\n allocate (M(n,n))\n do i = 1, n\n do j = 1, n\n M(i,j) = 0.0\n if (i == j) then\n M(i,j) = 1\n end if\n end do\n end do\n \n ! Perform the Gauss Elimination:\n do k = 1, n-1 ! pivot row\n\n ! If the pivot element is very small:\n if (dabs(A(k,k)) .le. 0.01) then\n write(*,*)\n write(*,*)\"--------------------------------------\"\n write(*,*) \"pivot element too small...\"\n do i = k, n !look at the remaining rows\n if (dabs(A(k,i)) .gt. 0.01) then !if one of these rows has\n ! has A(k,i) > 0.01\n write(*,*) \"swtching rows\", i, \"and\", k\n write(*,*) \"--------------------------------------\"\n write(*,*)\n do j = 1, n !switch the i-th and the k-th row\n temp1 = A(k,j)\n temp2 = A(i,j)\n A(k,j) = temp2\n A(i,j) = temp1\n end do\n end if\n end do\n end if\n \n do i = 1, n-k ! now modify the n-k rows for this pivot\n M(i+k,k) = A(i+k,k)/A(k,k) ! find the multiplier for row i+k\n \n write(*,*) \"--------------------------------------\"\n write(*,'(A6,I3,A6,I3,A7,I1,A1,I1,A3,F7.3)') \" Step:\", k, \" Row:\", i+k, \" m(\", i+k,\",\", k, \"): \", m(i+k,k)\n write(*,*) \"--------------------------------------\"\n \n do j = k, n ! for every column, j, in row i+k\n A(i+k,j) = A(i+k,j) - M(i+k,k)*A(k,j) ! change the value of the matrix\n ! element A(i+k,j)\n end do\n call writes2d(A)\n end do\n end do\n\n write(*,*) '--------------------------------'\n write(*,*) '[L]: '\n write(*,*) '--------------------------------'\n call writes2d(M)\n write(*,*)\n write(*,*) '--------------------------------'\n write(*,*) '[U]: '\n write(*,*) '--------------------------------'\n call writes2d(a)\n\nend subroutine Gauss_Elimination\n\nsubroutine Forward_Substitution(L,b,n,Y)\n real(kind=8), allocatable, dimension(:,:), intent(inout) :: L\n real(kind=8), allocatable, dimension(:), intent(in) :: b\n integer, intent(in) :: n !dimension\n real(kind=8), allocatable, dimension(:), intent(out) :: Y \n integer :: i, j\n \n allocate( Y(n) )\n do i = 1, n\n Y(i) = b(i)\n do j = 1, i-1\n Y(i) = Y(i) - L(i,j)*Y(j)\n end do\n Y(i) = Y(i)/L(i,i)\n end do\nend subroutine Forward_Substitution\n\nsubroutine Back_Substitution(U,b,n,X)\n real(kind=8), allocatable, dimension(:,:), intent(inout) :: U\n real(kind=8), allocatable, dimension(:), intent(in) :: b\n integer, intent(in) :: n !dimension\n real(kind=8), allocatable, dimension(:), intent(out) :: X\n integer :: i, j\n\n \n allocate( X(n) )\n do i = n, 1, -1\n X(i) = b(i)\n do j = i+1, n\n X(i) = X(i) - U(i,j)*X(j)\n end do\n X(i) = X(i)/U(i,i)\n end do\n\nend subroutine Back_Substitution\n\nend module procedures\n", "meta": {"hexsha": "5e811c7b7429855ff526a832ca1a71f136e171cf", "size": 3813, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ME_Numerical_Methods/HW5/ex1/mod.f95", "max_stars_repo_name": "ElenaKusevska/Fortran_exercises", "max_stars_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ME_Numerical_Methods/HW5/ex1/mod.f95", "max_issues_repo_name": "ElenaKusevska/Fortran_exercises", "max_issues_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ME_Numerical_Methods/HW5/ex1/mod.f95", "max_forks_repo_name": "ElenaKusevska/Fortran_exercises", "max_forks_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.4552238806, "max_line_length": 120, "alphanum_fraction": 0.445056386, "num_tokens": 1171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.8397339596505965, "lm_q1q2_score": 0.757373416565303}} {"text": "module mGf90\nimplicit none\n\nprivate\npublic srand_mtGaus\ncontains\n\nreal function srand_mtGaus(N, mean, cvm) result(y)\nimplicit none\n\n!The dimension of the multivariate vector\ninteger, intent(in) :: N\n\nreal, intent(in) :: mean(N) !Mean values of the multivariate distribution\n\nreal, intent(in) :: cvm(N,N) !Covariance matrix of the multivariate distribution\ndimension :: y(N)\ninteger :: nullty ! i/o for cholesky subroutine\ninteger :: error \ninteger :: i, j\nreal :: cvm_(N*(N+1)/2)\nreal :: chol(N*(N+1)/2)\n\n!Convert cvm to a vector with length N*(N+1)/2\ndo i = 1, N\n do j = 1,i\n cvm_(i*(i-1)/2+j) = cvm(i,j)\n enddo\nenddo\n\ncall cholesky(cvm_,N,N*(N+1)/2,chol,nullty,error)\n\ny = multiGauss(chol,mean,N)\nend function srand_mtGaus\n\nreal function gasdev() result(gval)\n!This function generates an array of independent Gaussian variates\nimplicit none\nreal :: FAC, R, V1, V2, X\nreal, save :: GSET\ninteger, save :: ISET = 0\n\nIF (ISET.EQ.0) THEN\n R = 99 \n do while( R .ge. 1.0d0 )\n call random_number(V1)\n V1= 2d0*V1 - 1d0\n\n call random_number(V2)\n V2= 2d0*V2 - 1d0\n\n R = V1**2 + V2**2\n end do\n FAC = SQRT( -2.0d0*LOG(R)/R )\n GSET = V1*FAC\n gval = V2*FAC\n ISET = 1\nELSE\n gval=GSET\n ISET=0\nENDIF\n\nRETURN\nEND function gasdev\n\nsubroutine cholesky ( a, n, nn, u, nullty, ifault )\n!*****************************************************************************80\n!\n!! CHOLESKY computes the Cholesky factorization of a PDS matrix.\n!\n! Discussion:\n!\n! For a positive definite symmetric matrix A, the Cholesky factor U\n! is an upper triangular matrix such that A = U' * U.\n!\n! This routine was originally named \"CHOL\", but that conflicted with\n! a built in MATLAB routine name.\n!\n! Modified:\n!\n! 01 February 2008\n!\n! Author:\n!\n! Michael Healy\n! Modifications by AJ Miller.\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! Michael Healy,\n! Algorithm AS 6:\n! Triangular decomposition of a symmetric matrix,\n! Applied Statistics,\n! Volume 17, Number 2, 1968, pages 195-197.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A((N*(N+1))/2), a positive definite matrix \n! stored by rows in lower triangular form as a one dimensional array, \n! in the sequence\n! A(1,1),\n! A(2,1), A(2,2),\n! A(3,1), A(3,2), A(3,3), and so on.\n!\n! Input, integer ( kind = 4 ) N, the order of A.\n!\n! Input, integer NN, the dimension of the array used to store A, \n! which should be at least (N*(N+1))/2.\n!\n! Output, real ( kind = 8 ) U((N*(N+1))/2), an upper triangular matrix,\n! stored by columns, which is the Cholesky factor of A. The program is\n! written in such a way that A and U can share storage.\n! It is also the same as lower triangular matrix stored by rows (by B. Chen on 12 Aug 2019)\n!\n! Output, integer ( kind = 4 ) NULLTY, the rank deficiency of A. If NULLTY is zero,\n! the matrix is judged to have full rank.\n!\n! Output, integer ( kind = 4 ) IFAULT, an error indicator.\n! 0, no error was detected;\n! 1, if N < 1;\n! 2, if A is not positive semi-definite.\n! 3, NN < (N*(N+1))/2.\n!\n! Local Parameters:\n!\n! Local, real ( kind = 8 ) ETA, should be set equal to the smallest positive\n! value such that 1.0 + ETA is calculated as being greater than 1.0 in the\n! accuracy being used.\n!\n implicit none\n\n integer ( kind = 4 ), intent(in) :: n\n integer ( kind = 4 ), intent(in) :: nn\n\n real ( kind = 8 ), intent(in) :: a(nn)\n real ( kind = 8 ), parameter :: eta = 1.0D-19\n integer ( kind = 4 ) i\n integer ( kind = 4 ) icol\n integer ( kind = 4 ), intent(out) :: ifault\n integer ( kind = 4 ) ii\n integer ( kind = 4 ) irow\n integer ( kind = 4 ) j\n integer ( kind = 4 ) k\n integer ( kind = 4 ) kk\n integer ( kind = 4 ) l\n integer ( kind = 4 ) m\n integer ( kind = 4 ), intent(out) :: nullty\n real ( kind = 8 ), intent(out) :: u(nn)\n real ( kind = 8 ) w\n real ( kind = 8 ) x\n\n ifault = 0\n nullty = 0\n\n if ( n <= 0 ) then\n ifault = 1\n return\n end if\n\n if ( nn < ( n * ( n + 1 ) ) / 2 ) then\n ifault = 3\n return\n end if\n\n j = 1\n k = 0\n ii = 0\n!\n! Factorize column by column, ICOL = column number.\n!\n do icol = 1, n\n\n ii = ii + icol\n x = eta * eta * a(ii)\n l = 0\n kk = 0\n!\n! IROW = row number within column ICOL.\n!\n do irow = 1, icol\n\n kk = kk + irow\n k = k + 1\n w = a(k)\n m = j\n\n do i = 1, irow - 1\n l = l + 1\n w = w - u(l) * u(m)\n m = m + 1\n end do\n\n l = l + 1\n\n if ( irow == icol ) then\n exit\n end if\n\n if ( u(l) /= 0.0D+00 ) then\n\n u(k) = w / u(l)\n\n else\n\n u(k) = 0.0D+00\n\n if ( abs ( x * a(k) ) < w * w ) then\n ifault = 2\n return\n end if\n\n end if\n\n end do\n!\n! End of row, estimate relative accuracy of diagonal element.\n!\n if ( abs ( w ) <= abs ( eta * a(k) ) ) then\n\n u(k) = 0.0D+00\n nullty = nullty + 1\n\n else\n\n if ( w < 0.0D+00 ) then\n ifault = 2\n return\n end if\n\n u(k) = sqrt ( w )\n\n end if\n\n j = j + icol\n\n end do\n\n return\nend subroutine cholesky\n\n!-----------------------------------------------------------------------------\nsubroutine subchl ( a, b, n, u, nullty, ifault, ndim, det )\n\n!*****************************************************************************80\n! \n!! SUBCHL computes the Cholesky factorization of a (subset of a) PDS matrix.\n!\n! Modified:\n!\n! 11 February 2008\n!\n! Author:\n!\n! FORTRAN77 version by Michael Healy, PR Freeman\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! PR Freeman,\n! Remark AS R44:\n! A Remark on AS 6 and AS7: Triangular decomposition of a symmetric matrix\n! and Inversion of a positive semi-definite symmetric matrix,\n! Applied Statistics,\n! Volume 31, Number 3, 1982, pages 336-339.\n!\n! Michael Healy,\n! Algorithm AS 6:\n! Triangular decomposition of a symmetric matrix,\n! Applied Statistics,\n! Volume 17, Number 2, 1968, pages 195-197.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A((M*(M+1))/2), a positive definite matrix \n! stored by rows in lower triangular form as a one dimensional array, \n! in the sequence\n! A(1,1),\n! A(2,1), A(2,2),\n! A(3,1), A(3,2), A(3,3), and so on. \n! In the simplest case, M, the order of A, is equal to N.\n!\n! Input, integer ( kind = 4 ) B(N), indicates the order in which the\n! rows and columns of A are to be used. In the simplest case, \n! B = (1,2,3...,N).\n!\n! Input, integer ( kind = 4 ) N, the order of the matrix, that is, \n! the matrix formed by using B to select N rows and columns of A.\n!\n! Output, real ( kind = 8 ) U((N*(N+1))/2), an upper triangular matrix,\n! stored by columns, which is the Cholesky factor of A. The program is\n! written in such a way that A and U can share storage.\n!\n! Output, integer ( kind = 4 ) NULLTY, the rank deficiency of A. \n! If NULLTY is zero, the matrix is judged to have full rank.\n!\n! Output, integer ( kind = 4 ) IFAULT, an error indicator.\n! 0, no error was detected;\n! 1, if N < 1;\n! 2, if A is not positive semi-definite.\n!\n! Input, integer ( kind = 4 ) NDIM, the dimension of A and U, which might \n! be presumed to be (N*(N+1))/2.\n!\n! Output, real ( kind = 8 ) DET, the determinant of the matrix.\n!\n implicit none\n\n integer ( kind = 4 ) n\n integer ( kind = 4 ) ndim\n\n real ( kind = 8 ) a(ndim)\n integer ( kind = 4 ) b(n)\n real ( kind = 8 ) det\n real ( kind = 8 ), parameter :: eta = 1.0D-09\n integer ( kind = 4 ) i\n integer ( kind = 4 ) icol\n integer ( kind = 4 ) ifault\n integer ( kind = 4 ) ii\n integer ( kind = 4 ) ij\n integer ( kind = 4 ) irow\n integer ( kind = 4 ) j\n integer ( kind = 4 ) jj\n integer ( kind = 4 ) k\n integer ( kind = 4 ) kk\n integer ( kind = 4 ) l\n integer ( kind = 4 ) m\n integer ( kind = 4 ) nullty\n real ( kind = 8 ) u(ndim)\n real ( kind = 8 ) w\n real ( kind = 8 ) x\n\n ifault = 0\n nullty = 0\n det = 1.0D+00\n\n if ( n <= 0 ) then\n ifault = 1\n return\n end if\n\n ifault = 2\n j = 1\n k = 0\n\n do icol = 1, n\n\n ij = ( b(icol) * ( b(icol) - 1 ) ) / 2\n ii = ij + b(icol)\n x = eta * eta * a(ii)\n l = 0\n\n do irow = 1, icol\n\n kk = ( b(irow) * ( b(irow) + 1 ) ) / 2\n k = k + 1\n jj = ij + b(irow)\n w = a(jj)\n m = j\n\n do i = 1, irow - 1\n l = l + 1\n w = w - u(l) * u(m)\n m = m + 1\n end do\n\n l = l + 1\n\n if ( irow == icol ) then\n exit\n end if\n\n if ( u(l) /= 0.0D+00 ) then\n\n u(k) = w / u(l)\n\n else\n\n if ( abs ( x * a(kk) ) < w * w ) then\n ifault = 2\n return\n end if\n\n u(k) = 0.0D+00\n\n end if\n\n end do\n\n if ( abs ( eta * a(kk) ) <= abs ( w ) ) then\n\n if ( w < 0.0D+00 ) then\n ifault = 2\n return\n end if\n\n u(k) = sqrt ( w )\n\n else\n\n u(k) = 0.0D+00\n nullty = nullty + 1\n\n end if\n\n j = j + icol\n det = det * u(k) * u(k)\n\n end do\n\n return\nend subroutine subchl\n\nreal function multigauss(R,mu,n) result(G)\n!!$ Generates a one dimensional array of length n containing multivariate Gaussian pseudo-random numbers\n!!$ where R is the lower-triangular Cholesky factor of the covariance matrix of the desired distribution \n!!$ and mu is a one dimensional array of length n, containing the mean value for each random variable. \n!!$ R must be a one dimensional array, containing the lower-triangular matrix stored by row, starting from the \n!!$ uppermost, leftmost entry (first row, first column). \n implicit none\n integer, intent(in) :: n\n real, intent(in) :: R(n*(n+1)/2)\n real, intent(in) :: mu(n)\n real :: Nu(n)\n dimension :: G(n)\n integer :: i, j\n \n if( n*(n+1)/2 .ne. size(R) ) then\n write(6,*) ' n*(n+1)/2 != size(R) in multiGauss '\n write(6,*) ' Cholesky factor matrix has size ', size(R) \n write(6,*) ' but you are requesting a vector of size ',n\n stop\n else\n \n!!$ generate an array of independent Gaussian variates\n do j = 1, n\n Nu(j) = gasdev()\n end do\n\n!!$ start with the desired mean, and add the product of \n!!$ [the lower-triangular Cholesky factor of the covariance matrix] x [ the vector of iid Gaussian variates]\n do i = 1, n\n G(i) = mu(i)\n do j = 1,i\n G(i) = G(i) + R( i*(i-1)/2 + j ) * Nu(j)\n end do\n end do\n\n end if\n return\n end function multigauss\nend module mGf90\n", "meta": {"hexsha": "37a4b86a65bbae13ab45396493eeb9a24139a4f0", "size": 10557, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/multiGauss.f90", "max_stars_repo_name": "BingzhangChen/IBM", "max_stars_repo_head_hexsha": "16a443e159a088f2aecb0aefc1d1a4865462d62c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/multiGauss.f90", "max_issues_repo_name": "BingzhangChen/IBM", "max_issues_repo_head_hexsha": "16a443e159a088f2aecb0aefc1d1a4865462d62c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/multiGauss.f90", "max_forks_repo_name": "BingzhangChen/IBM", "max_forks_repo_head_hexsha": "16a443e159a088f2aecb0aefc1d1a4865462d62c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.3046357616, "max_line_length": 111, "alphanum_fraction": 0.553661078, "num_tokens": 3594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7573586205088693}} {"text": "module KinematicClass\n use, intrinsic :: iso_fortran_env\n use MathClass\n\n implicit none\n\ncontains\n\n! #############################################\nfunction RotationMatrix3D(rotx,roty,rotz,n,angle) result(Rmat)\n real(real64)::Rmat(3,3)\n real(real64),optional,intent(in)::rotx,roty,rotz,n(3),angle\n integer(int32) :: i\n Rmat(:,:)=0.0d0\n do i=1,3\n Rmat(i,i)=1.0d0\n enddo\n \n if(present(rotx) )then\n Rmat(2,2) = cos(rotx)\n Rmat(2,3) = -sin(rotx)\n Rmat(3,2) = sin(rotx)\n Rmat(3,3) = cos(rotx)\n endif\n\n if(present(rotx) )then\n Rmat(1,1) = cos(rotx)\n Rmat(1,3) = sin(rotx)\n Rmat(3,1) = -sin(rotx)\n Rmat(3,3) = cos(rotx)\n endif\n\n if(present(rotx) )then\n Rmat(2,2) = cos(rotx)\n Rmat(2,3) = -sin(rotx)\n Rmat(3,2) = sin(rotx)\n Rmat(3,3) = cos(rotx)\n endif\n\n if(present(n) .and. present(angle) )then\n ! Rodrigues' rotation formula\n Rmat(1,1)=cos(angle)+n(1)*n(1)*(1.0d0 - cos(angle) )\n Rmat(1,2)=n(1)*n(2)*(1.0d0 - cos(angle) )-n(3)*sin(angle)\n Rmat(1,3)=n(1)*n(3)*(1.0d0 + cos(angle) )-n(2)*sin(angle)\n Rmat(2,1)=n(2)*n(1)*(1.0d0 + cos(angle) )-n(3)*sin(angle)\n Rmat(2,2)=cos(angle)+n(2)*n(2)*(1.0d0 - cos(angle) )\n Rmat(2,3)=n(2)*n(3)*(1.0d0 - cos(angle) )-n(1)*sin(angle)\n Rmat(3,1)=n(3)*n(1)*(1.0d0 - cos(angle) )-n(2)*sin(angle)\n Rmat(3,2)=n(3)*n(2)*(1.0d0 + cos(angle) )-n(1)*sin(angle)\n Rmat(3,3)=cos(angle)+n(3)*n(3)*(1.0d0 - cos(angle) )\n endif\n\nend function\n! #############################################\n\n! #############################################\nfunction Rotation3D(vector,rotx,roty,rotz,n,angle) result(vec)\n real(real64)::vec(3)\n real(real64),intent(in)::vector(3)\n real(real64),optional,intent(in)::rotx,roty,rotz,n(3),angle\n\n vec(:) = matmul( RotationMatrix3D(rotx,roty,rotz,n,angle) ,vector)\n\nend function\n! #############################################\n\nend module", "meta": {"hexsha": "5446a57057e84f95d84d5150ad903a385beb6f33", "size": 2003, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/KinematicClass/KinematicClass.f90", "max_stars_repo_name": "kazulagi/plantfem_min", "max_stars_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2020-06-21T08:21:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:28:30.000Z", "max_issues_repo_path": "src/KinematicClass/KinematicClass.f90", "max_issues_repo_name": "kazulagi/plantfem_min", "max_issues_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-08T05:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:39:29.000Z", "max_forks_repo_path": "src/KinematicClass/KinematicClass.f90", "max_forks_repo_name": "kazulagi/plantfem_min", "max_forks_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-10-20T18:28:59.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-15T08:35:25.000Z", "avg_line_length": 29.8955223881, "max_line_length": 70, "alphanum_fraction": 0.5042436345, "num_tokens": 760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107966642556, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7573293148060722}} {"text": "implicit none\r\ndouble complex :: x, xold, f, fprime, top, bot\r\n\r\nx = (1,0d0, 3.0d0)\r\nxold = 2.0d0 * x\r\n\r\ndo while (abs(x - xold) > 1.0d-11)\r\n cold = x\r\n top = f(x)\r\n bot = fprime(x)\r\n x = (x - top) / bot\r\n print*, 'x = ', x\r\n print*, top\r\n print*,\r\nend do\r\nprint*, 'End of program.'\r\n\r\nstop\r\nend\r\n\r\ndouble complex function f(x)\r\n implicit none\r\n double complex :: x\r\n\r\n f = sin(x) - 2.0d0\r\n\r\n return\r\nend\r\n\r\ndouble complex function fprime(x)\r\n implicit none\r\n double complex :: x\r\n\r\n fprime = cos(x)\r\n\r\n return\r\nend \r\n", "meta": {"hexsha": "a396652c96c90d7aa9c4dd01d22fe76508294a3a", "size": 533, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "4670 Numerical Analysis/Class Examples/newton2.f90", "max_stars_repo_name": "mwebber3/UnderGraduateCourses", "max_stars_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4670 Numerical Analysis/Class Examples/newton2.f90", "max_issues_repo_name": "mwebber3/UnderGraduateCourses", "max_issues_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4670 Numerical Analysis/Class Examples/newton2.f90", "max_forks_repo_name": "mwebber3/UnderGraduateCourses", "max_forks_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.0263157895, "max_line_length": 47, "alphanum_fraction": 0.5590994371, "num_tokens": 192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037262250327, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7573222858233201}} {"text": "Program itsatrap\n implicit none\n REAL::x, f, a, b, Int, h\n INTEGER::i, N\n N=100000\n a=0\n b=1\n Int=0\n h=(b-a)/N\n do i=1, N\n x=a+i*h\n Int=Int+f(x)\n end do\n Int=(b-a)*(f(a)+2*Int+f(b))/(2*N)\n write(*, *) Int\nend Program itsatrap\n\nfunction f(x)\n implicit none\n REAL::x, f\n f=exp(-x**2)\nend function f\n", "meta": {"hexsha": "6f5bf73d4d700fa1e78e4ace57dfbb9d1284f641", "size": 320, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "31.- Regla del trapecio/Trapecio.f90", "max_stars_repo_name": "clivan/Fortran", "max_stars_repo_head_hexsha": "4f842c6433899cc36b8c27c71f7667ba0ed15312", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "31.- Regla del trapecio/Trapecio.f90", "max_issues_repo_name": "clivan/Fortran", "max_issues_repo_head_hexsha": "4f842c6433899cc36b8c27c71f7667ba0ed15312", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "31.- Regla del trapecio/Trapecio.f90", "max_forks_repo_name": "clivan/Fortran", "max_forks_repo_head_hexsha": "4f842c6433899cc36b8c27c71f7667ba0ed15312", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.9130434783, "max_line_length": 35, "alphanum_fraction": 0.55, "num_tokens": 144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797027760038, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7573206791229701}} {"text": " FUNCTION f_qv_from_rh (RH, T_K, RH0, T_K0, P_PA0) RESULT (QV_KG)\n!!!--------------------------------------------------------------------------\n!!!\n!!! FUNCTION F_QV_FROM_RH\n!!! **************************\n!!!\n!!! PURPOSE: \n!!! -------\n!!! TANGENT LINEAR CODE FOR\n!!! COMPUTING MIXING RATIO FROM RELATIVE HUMIDITY, TEMPERATURE AND PRESSURE\n!!!\n!!! THE ERROR DERIVATION SHOULD USED THE TANGENT LINEAR CODE, NOT THE\n!!! ORIGINAL NON-LINEAR CODE.\n!!!\n!! METHOD:\n!! ------\n!! LINEAR OR LOGARITHMIC VERTICAL INTERPOLATION\n!! OUT OF BOUND LOCATIONS ARE EXTRAPOLATED\n!!\n!! INPUT:\n!! -----\n!! RH: RELAITVE HUMIDITY in %\n!! P_PA: PRESSURE in Pa\n!! T_K: TEMPERATURE in K\n!!\n!! OUTPUT:\n!! ------\n!! QV_KG: MIXING RATIO IN kg/kg\n!!\n!! COMMON: NO\n!! -------\n!! EXTERNAL: NO \n!! --------\n!!\n!! REFERENCES:\n!! -----------\n!! R. R. ROGERS AND M. K. YAU, 1989: A SHORT COURSE IN CLOUD PHYSICS,\n!! 3ND EDITION, PERGAMON PRESS, PAGE 14-19.\n!!\n!! VERIFICATION SET:\n!! -----------------\n!! T_K = 268.15 K, \n!! TD_K = 262.55 K\n!! RH = 65 %, \n!! P_PA = 80000 Pa, \n!! QV = 2.11E-03 kg/kg,\n!!\n!! MODIFICATIONS:\n!! ------------\n!! Developed by Yong-Run Guo (11/07/00)\n!!----------------------------------------------------------------------------CC\n\n IMPLICIT NONE\n\n REAL T_K , RH , QV_KG\n REAL P_PA0, T_K0, RH0\n ! REAL P_MB, W_KG\n REAL ES , QS\n REAL P_MB0, ES0, QS0, QV_KG0\n!------------------------------------------------------------------------------C\n\n!...P in mb\n\n P_MB0 = P_PA0 / 100.\n\n!...VAPOR PRESSURE in mb\n\n ES = 6.112 * 17.67 * 243.5 * T_K / &\n ((T_K0-273.15+243.5)*(T_K0-273.15+243.5)) * &\n EXP (17.67*(T_K0-273.15)/(T_K0-273.15+243.5))\n ES0 = 6.112 * EXP (17.67*(T_K0-273.15)/(T_K0-273.15+243.5)) \n\n!...SATURATION MIXING RATIO in kg/kg\n\n QS = 0.622 * (P_MB0 * ES ) / &\n ((P_MB0 - ES0) * (P_MB0 - ES0))\n QS0 = 0.622 * ES0 /(P_MB0-ES0) \n\n!...MIXING RATIO in kg/kg\n\n QV_KG = 0.01 * (RH0 * QS + RH * QS0)\n QV_KG0 = 0.01 * RH0 * QS0\n\n!...Mixing ratio must be positive\n\n IF (QV_KG0 < 0.) QV_KG = 0.\n\n RETURN\n\n END FUNCTION f_qv_from_rh\n\n\n", "meta": {"hexsha": "3a4fd7177dc47e137a3b08e0d1795f1731976b82", "size": 2443, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "var/da/da_physics/f_qv_from_rh.f90", "max_stars_repo_name": "matzegoebel/WRF-fluxavg", "max_stars_repo_head_hexsha": "686ae53053bf7cb55d6f078916d0de50f819fc62", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2018-08-27T12:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-16T14:22:54.000Z", "max_issues_repo_path": "var/da/da_physics/f_qv_from_rh.f90", "max_issues_repo_name": "teb-model/wrf-teb", "max_issues_repo_head_hexsha": "60882e61a2a3d91f1c94cb5b542f46ffaebfad71", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2018-09-18T16:44:30.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-07T10:59:59.000Z", "max_forks_repo_path": "var/da/da_physics/f_qv_from_rh.f90", "max_forks_repo_name": "teb-model/wrf-teb", "max_forks_repo_head_hexsha": "60882e61a2a3d91f1c94cb5b542f46ffaebfad71", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-08-31T21:51:56.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-21T21:41:59.000Z", "avg_line_length": 26.2688172043, "max_line_length": 80, "alphanum_fraction": 0.41997544, "num_tokens": 789, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012655937034, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7572955134313248}} {"text": "\tREAL*4 FUNCTION \r\n .\tTPOWER(ITYPE,ALPHA,MYDIFF,SIGMA,N,M)\r\n\tUSE MSIMSL\r\nC\r\nC-Description-----------------------------------------------------------\r\n\tIMPLICIT NONE\r\nC\r\nC Function:\r\nC\tDetermine Power\r\nC Arguments:\r\nC input from user\r\nC\tALPHA\tType I error probability (two sided)\r\nC\tN\tNumber of experimental patients for independent\r\nC\t\tt-tests or the number of pairs of patients\r\nC\t\tfor paired t-tests\r\nC\tM\tthe number of control patients per experimental patient.\r\nC\t\tM is only defined for independent t-tests.\r\nC\tMYDIFF A difference in population means\r\nC\tSIGMA\tAn estimate of the within group standard deviation for\r\nC\t\tindependent tests. It is an estimate of the standard\r\nC\t\tdeviation of paired response MYDIFFerences for paired data.\r\nC output:\r\nC\tPOWER\tThe probability of correctly rejecting the null hypotheses\r\nC\t\tof equal population means given N pairs of patients (or\r\nC\t\tN experimental patients with M controls per experimental\r\nC\t\tpatient), and a type I error probability ALPHA when the\r\nC\t\ttrue MYDIFFerence in population means is MYDIFF.\r\nC\r\nC Notes:\r\nC\r\nC\tThis program gives results that are consistant with the\r\nC\tTSAMPLESIZE routine. An elementary reference is Steel and\r\nC\tTorrie: Principles and Procedures of Statistics: A Biometrical\r\nC\tApproach, 2nd ed. New York: McGraw-Hill 1980.\r\nC\r\nC\tLet TCRVALUE(P,NU) returns the critical value that is exceeded\r\nC\tby a t statistic with NU degrees of freedom with probability P.\r\nC\r\nC\tLet TCUM(T,NU) return the probability that a t statistic\r\nC\twith NU degrees of freedom will be <= T.\r\nC\r\nC\tThen the derivation of the study power given below follows\r\nC\tfrom elementary computations. The validity of these results\r\nC\tcan be confirmed by the analogous use of routine TSAMPLESIZE.\r\nC\r\nC\tThe resulting power calculations produced by this program\r\nC\tare in close agreement with those obtained from Table 10 of\r\nC\tPearson and Hartley, Biometrika Tables for Statisticians, Vol I,\r\nC\t3rd Ed., Cambridge: Cambridge U. Press, 1970.\r\nC\r\nC .\tThis routine was written by Dale Plummer\r\nC .\tDesigned by William Dupont\r\nC\r\nC-Declarations----------------------------------------------------------\r\nC\r\nC Arguments\r\nC\r\n\tINTEGER ITYPE\r\n\tREAL ALPHA,MYDIFF,SIGMA,N,M\r\nC\r\nC Functions\r\nC\r\n\tREAL TCUM,TCRVALUE\r\nC\r\nC Locals\r\nC\r\n REAL DELTA\r\n REAL DRN,TCRV,NU\r\nC\r\nC-Code------------------------------------------------------------------\r\nC\r\nC A single value of MYDIFF is specified.\r\nC\r\n\tIF (ITYPE.EQ.1) THEN\r\nC\r\nC Paired\r\nC Perform the computations.\r\nC\r\n\t\tNU=N-1.\r\n\t\tIF (NU.LT.1.) THEN\r\n\t\t\tTPOWER=-999\r\n\t\t\tRETURN\r\n\t\tEND IF\r\n\t\tDELTA=MYDIFF/SIGMA\r\n\t\tDRN=DELTA*SQRT(N)\r\nC\t\tTCRV=TCRVALUE(ALPHA/2.,NU)\r\n\t\tTCRV=TIN((1.-ALPHA/2.),NU)\r\n\t\tTPOWER=TCUM(DRN-TCRV,NU)+TCUM(-DRN-TCRV,NU)\r\n\tELSE\r\nC\r\nC Independent\r\nC Perform the computations.\r\nC\r\n\t\tNU=N*(M+1.)-2.\r\n\t\tIF (NU.LT.1.) THEN\r\n\t\t\tTPOWER=-999\r\n\t\t\tRETURN\r\n\t\tEND IF\r\n\t\tDELTA=MYDIFF/(SIGMA*SQRT(1.+1./M))\r\n\t\tDRN=DELTA*SQRT(N)\r\nC\t\tTCRV=TCRVALUE(ALPHA/2.,NU)\r\n\t\tTCRV=TIN((1.-ALPHA/2.),NU)\r\n\t\tTPOWER=TCUM(DRN-TCRV,NU)+TCUM(-DRN-TCRV,NU)\r\n\tEND IF\r\n\tRETURN\r\n\tEND\r\n", "meta": {"hexsha": "784045ce581f959ed740be8c0243a88b956efcd9", "size": 3087, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "misc/old_ps/ps-development-version/psDll/tpower.for", "max_stars_repo_name": "vubiostat/ps", "max_stars_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-12-29T14:19:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-06T15:08:46.000Z", "max_issues_repo_path": "misc/old_ps/ps-development-version/psDll/tpower.for", "max_issues_repo_name": "vubiostat/ps", "max_issues_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-04-30T16:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T00:26:02.000Z", "max_forks_repo_path": "misc/old_ps/ps-development-version/psDll/tpower.for", "max_forks_repo_name": "vubiostat/ps", "max_forks_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-07T20:11:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-11T19:18:59.000Z", "avg_line_length": 28.8504672897, "max_line_length": 73, "alphanum_fraction": 0.6760609006, "num_tokens": 910, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122684798184, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7572586955862678}} {"text": "PROGRAM monte_pi_serial\n\n IMPLICIT NONE\n \n INTEGER(kind=4) :: i, count\n REAL(kind=8) :: x, y, pi\n REAL(kind=8) :: t_start, t_end\n INTEGER(kind=8), PARAMETER :: num_points = 300000000\n\n count=0\n\n CALL cpu_time(t_start)\n CALL random_seed()\n DO i=0,num_points\n CALL random_number(x)\n CALL random_number(y)\n IF (x*x + y*y <= 1) count = count + 1\n END DO\n\n pi = 4.0*count/num_points\n \n CALL cpu_time(t_end)\n\n WRITE(*,*) \"Value of pi = \",pi\n WRITE(*,*) \"Expended wall clock time = \",t_end-t_start\n \nEND PROGRAM monte_pi_serial\n", "meta": {"hexsha": "f592ecc02db263b923a913acd0d71288b3580159", "size": 551, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "monte_pi/src/monte_pi_serial.f90", "max_stars_repo_name": "samjcus/pragma_pragma_pragma", "max_stars_repo_head_hexsha": "643d8440bde2ace2b8f940d783ca95e21d1c9f78", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "monte_pi/src/monte_pi_serial.f90", "max_issues_repo_name": "samjcus/pragma_pragma_pragma", "max_issues_repo_head_hexsha": "643d8440bde2ace2b8f940d783ca95e21d1c9f78", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2016-02-25T23:12:14.000Z", "max_issues_repo_issues_event_max_datetime": "2016-02-26T00:17:58.000Z", "max_forks_repo_path": "monte_pi/src/monte_pi_serial.f90", "max_forks_repo_name": "samjcus/pragma_pragma_pragma", "max_forks_repo_head_hexsha": "643d8440bde2ace2b8f940d783ca95e21d1c9f78", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.6785714286, "max_line_length": 56, "alphanum_fraction": 0.6424682396, "num_tokens": 184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995702, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7572519819882372}} {"text": "Subroutine triangulate(A, n)\n\tImplicit None\n\t\n\tInteger, Intent(In) :: n\n\tDouble Precision, Dimension(n, n), Intent(InOut) :: A\n\t\n\tDouble Precision, Dimension(n, n):: tmp\n\tInteger :: i, j, k\n\t\n\ttmp = A\n\tDo k = 1, n-1\n\t\tDo i = n, k+1, -1\n\t\t\tDo j = k, n\n\t\t\t\ttmp(i, j) = A(i, j) - A(i, k) * A(k, j) / A(k, k)\n\t\t\tEnd Do\n\t\tEnd Do\n\t\tA = tmp\n\tEnd Do\n\t\nEnd Subroutine triangulate", "meta": {"hexsha": "6eaba850523466f35d6599a99d81e58764e4a258", "size": 370, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Matrices/triangulate.f90", "max_stars_repo_name": "sajazaerica/FTools", "max_stars_repo_head_hexsha": "6d6342d9758752924290dd061beca85b655397f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Matrices/triangulate.f90", "max_issues_repo_name": "sajazaerica/FTools", "max_issues_repo_head_hexsha": "6d6342d9758752924290dd061beca85b655397f4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Matrices/triangulate.f90", "max_forks_repo_name": "sajazaerica/FTools", "max_forks_repo_head_hexsha": "6d6342d9758752924290dd061beca85b655397f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.5, "max_line_length": 54, "alphanum_fraction": 0.5675675676, "num_tokens": 143, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939913356558485, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7572244570900851}} {"text": " SUBROUTINE sla_DCS2C (A, B, V)\n*+\n* - - - - - -\n* D C S 2 C\n* - - - - - -\n*\n* Spherical coordinates to direction cosines (double precision)\n*\n* Given:\n* A,B dp spherical coordinates in radians\n* (RA,Dec), (Long,Lat) etc\n*\n* Returned:\n* V dp(3) x,y,z unit vector\n*\n* The spherical coordinates are longitude (+ve anticlockwise\n* looking from the +ve latitude pole) and latitude. The\n* Cartesian coordinates are right handed, with the x axis\n* at zero longitude and latitude, and the z axis at the\n* +ve latitude pole.\n*\n* P.T.Wallace Starlink October 1984\n*\n* Copyright (C) 1995 Rutherford Appleton Laboratory\n*\n* License:\n* This program is free software; you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation; either version 2 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program (see SLA_CONDITIONS); if not, write to the \n* Free Software Foundation, Inc., 59 Temple Place, Suite 330, \n* Boston, MA 02111-1307 USA\n*\n*-\n\n IMPLICIT NONE\n\n DOUBLE PRECISION A,B,V(3)\n\n DOUBLE PRECISION COSB\n\n\n\n COSB=COS(B)\n\n V(1)=COS(A)*COSB\n V(2)=SIN(A)*COSB\n V(3)=SIN(B)\n\n END\n", "meta": {"hexsha": "77c2f377338c966e213fc01c168be8381b05cf9a", "size": 1654, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Util/third/star/dcs2c.f", "max_stars_repo_name": "xuanyuanstar/psrchive_CDFT", "max_stars_repo_head_hexsha": "453c4dc05b8e901ea661cd02d4f0a30665dcaf35", "max_stars_repo_licenses": ["AFL-2.1"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Util/third/star/dcs2c.f", "max_issues_repo_name": "xuanyuanstar/psrchive_CDFT", "max_issues_repo_head_hexsha": "453c4dc05b8e901ea661cd02d4f0a30665dcaf35", "max_issues_repo_licenses": ["AFL-2.1"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Util/third/star/dcs2c.f", "max_forks_repo_name": "xuanyuanstar/psrchive_CDFT", "max_forks_repo_head_hexsha": "453c4dc05b8e901ea661cd02d4f0a30665dcaf35", "max_forks_repo_licenses": ["AFL-2.1"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-13T20:08:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-13T20:08:14.000Z", "avg_line_length": 28.0338983051, "max_line_length": 73, "alphanum_fraction": 0.6475211608, "num_tokens": 464, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.7572244560524799}} {"text": "!******************************************************************************\n!*\n!* VARIOUS APPLICATIONS OF FFT\n!*\n!******************************************************************************\n\n !==========================================================================\n ! 1) AUTHOR: F. Galliano\n !\n ! 2) HISTORY: \n ! - Created 07/2013 \n ! \n ! 3) DESCRIPTION: implements FFTs, and various relaed functions.\n !==========================================================================\n\nMODULE FFT_specials\n\n USE utilities, ONLY:\n USE constants, ONLY:\n USE arrays, ONLY:\n IMPLICIT NONE\n PRIVATE\n\n PUBLIC :: realft, correl\n\n\nCONTAINS\n\n\n !==========================================================================\n ! CALL FOURROW(data,isign)\n !\n ! Replaces each row (constant first index) of data(1:M,1:N) by its discrete\n ! Fourier transform (transform on second index), if isign is input as 1; or \n ! replaces each row of data by N times its inverse discrete Fourier \n ! transform, if isign is input as −1. N must be an integer power of 2. \n ! Parallelism is M-fold on the first index of data.\n !==========================================================================\n\n SUBROUTINE fourrow (data,isign)\n\n USE utilities, ONLY: DP, CDP, swap, strike\n USE constants, ONLY: pi\n IMPLICIT NONE\n COMPLEX(CDP), DIMENSION(:,:), INTENT(INOUT) :: data\n INTEGER, INTENT(IN) :: isign\n INTEGER :: N, i, istep, j, m, Mmax, N2\n REAL(DP) :: theta\n COMPLEX(CDP), DIMENSION(SIZE(data,1)) :: temp\n COMPLEX(CDP) :: w,wp\n COMPLEX(CDP) :: ws\n\n !-------------------------------------------------------------------------\n\n N = SIZE(data,2)\n IF (IAND(N,N-1) /= 0) CALL STRIKE(\"FOOURROW\",\"n must be a power of 2\")\n N2 = N / 2\n j = N2\n DO i=1,N-2\n IF (j > i) CALL SWAP(data(:,j+1),data(:,i+1))\n m = N2\n DO\n IF (m < 2 .OR. j < m) EXIT\n j = j - m\n m = m / 2\n END DO\n j = j + m\n END DO\n Mmax = 1\n DO\n IF (N <= Mmax) EXIT\n istep = 2 * Mmax\n theta = pi / (isign*Mmax)\n wp = CMPLX(-2._DP*SIN(0.5_DP*theta)**2,SIN(theta),KIND=CDP)\n w = CMPLX(1._DP,0._DP,KIND=CDP)\n DO m=1,Mmax\n ws = w\n DO i=m,n,istep\n j = i + Mmax\n temp = ws * data(:,j)\n data(:,j) = data(:,i) - temp\n data(:,i) = data(:,i) + temp\n END DO\n w = w * wp + w\n END DO\n Mmax = istep\n END DO\n\n !-------------------------------------------------------------------------\n\n END SUBROUTINE fourrow\n\n\n !==========================================================================\n ! CALL FOUR1(data,isign)\n !\n ! Replaces a complex array data by its discrete Fourier transform, if \n ! isign is input as 1; or replaces data by its inverse discrete Fourier \n ! transform times the size of data, if isign is input as −1. The size of \n ! data must be an integer power of 2. Parallelism is achieved by internally \n ! reshaping the input array to two dimensions. (Use this version if fourrow \n ! is faster than fourcol on your machine.)\n !==========================================================================\n\n SUBROUTINE four1 (data,isign)\n\n USE utilities, ONLY: DP, CDP, strike, arth\n USE constants, ONLY: twopi\n IMPLICIT NONE\n COMPLEX(CDP), DIMENSION(:), INTENT(INOUT) :: data\n INTEGER, INTENT(IN) :: isign\n COMPLEX(CDP), DIMENSION(:,:), ALLOCATABLE :: dat, temp\n COMPLEX(CDP), DIMENSION(:), ALLOCATABLE :: w, wp\n REAL(DP), DIMENSION(:), ALLOCATABLE :: theta\n INTEGER :: N, m1, m2, j\n\n !-------------------------------------------------------------------------\n\n N = SIZE(data)\n IF (IAND(N,N-1) /=0) CALL STRIKE(\"FOUR1\",\"N must be a power of 2\")\n m1 = 2**CEILING( 0.5_DP * LOG(REAL(N,DP)) / 0.693147_DP )\n m2 = n / m1\n ALLOCATE (dat(m1,m2),theta(m1),w(m1),wp(m1),temp(m2,m1))\n dat = RESHAPE(data,SHAPE(dat))\n CALL FOURROW(dat,isign)\n theta = ARTH(0,isign,m1) * TWOPI / N\n wp = CMPLX(-2._DP*SIN(0.5_DP*theta)**2,SIN(theta),KIND=CDP)\n w = CMPLX(1._DP,0._DP,KIND=CDP)\n DO j=2,m2\n w = w * wp + w\n dat(:,j) = dat(:,j) * w\n END DO\n temp = TRANSPOSE(dat)\n CALL FOURROW(temp,isign)\n data = RESHAPE(temp,SHAPE(data))\n DEALLOCATE (dat,w,wp,theta,temp)\n\n !-------------------------------------------------------------------------\n\n END SUBROUTINE four1\n\n\n !==========================================================================\n ! CALL REALFT(data,isign,zdata)\n !\n ! When isign = 1, calculates the Fourier transform of a set of N \n ! real-valued data points, input in the array data. If the optional argument \n ! zdata is not present, the data are replaced by the positive frequency half \n ! of its complex Fourier transform. The real-valued first and last components \n ! of the complex transform are returned as elements data(1) and data(2),\n ! respectively. If the complex array zdata of length N/2 is present, data is \n ! unchanged and the transform is returned in zdata. N must be a power of 2. \n ! If isign = 1, this routine calculates the inverse transform of a complex \n ! data array if it is the transform of real data. (Result in this case must \n ! be multiplied by 2/N.) The data can be supplied either in data, with zdata \n ! absent, or in zdata.\n !==========================================================================\n\n SUBROUTINE REALFT(data,isign,zdata)\n\n USE utilities, ONLY: DP, CDP, strike, zroots_unity\n IMPLICIT NONE\n REAL(DP), DIMENSION(:), INTENT(INOUT) :: data\n INTEGER, INTENT(IN) :: isign\n COMPLEX(CDP), DIMENSION(:), OPTIONAL, TARGET :: zdata\n INTEGER :: N, Ndum, Nh, Nq\n COMPLEX(CDP), DIMENSION(SIZE(data)/4) :: w\n COMPLEX(CDP), DIMENSION(SIZE(data)/4-1) :: h1, h2\n COMPLEX(CDP), DIMENSION(:), POINTER :: cdata\n COMPLEX(CDP) :: z\n REAL(DP) :: c1 = 0.5_DP, c2\n\n !-------------------------------------------------------------------------\n\n N = SIZE(data)\n IF (IAND(N,N-1) /= 0) CALL STRIKE(\"REALFT\",\"N must be a power of 2\")\n Nh = N / 2\n Nq = N / 4\n IF (PRESENT(zdata)) THEN\n Ndum = N / 2 \n IF (SIZE(zdata) /= N/2) CALL STRIKE(\"REALFT\",\"Wonrg size of input\")\n cdata => zdata\n IF (isign == 1) cdata = CMPLX(data(1:N-1:2),data(2:N:2),KIND=CDP)\n ELSE\n ALLOCATE (cdata(N/2))\n cdata = CMPLX(data(1:N-1:2),data(2:N:2),KIND=CDP)\n END IF\n\n IF (isign == 1) THEN\n c2 = - 0.5_DP\n CALL four1(cdata,+1)\n ELSE\n c2 = 0.5_DP\n END IF\n w = ZROOTS_UNITY(SIGN(N,isign),N/4)\n w = CMPLX(-AIMAG(w),REAL(w),KIND=CDP)\n h1 = c1 * (cdata(2:Nq)+CONJG(cdata(Nh:Nq+2:-1)))\n h2 = c2 * (cdata(2:Nq)-CONJG(cdata(Nh:Nq+2:-1)))\n cdata(2:Nq) = h1 + w(2:Nq) * h2\n cdata(Nh:Nq+2:-1) = CONJG(h1-w(2:Nq)*h2)\n z = cdata(1)\n IF (isign == 1) THEN\n cdata(1) = CMPLX(REAL(z)+AIMAG(z),REAL(z)-AIMAG(z),KIND=CDP)\n ELSE\n cdata(1) = CMPLX(c1*(REAL(z)+AIMAG(z)),c1*(REAL(z)-AIMAG(z)),KIND=CDP)\n CALL FOUR1(cdata,-1)\n END IF\n IF (PRESENT(zdata)) THEN\n IF (isign /= 1) THEN\n data(1:N-1:2) = REAL(cdata)\n data(2:N:2) = AIMAG(cdata)\n END IF\n ELSE\n data(1:N-1:2) = REAL(cdata)\n data(2:N:2) = AIMAG(cdata)\n DEALLOCATE(cdata)\n END IF\n\n !-------------------------------------------------------------------------\n\n END SUBROUTINE realft\n\n\n !==========================================================================\n ! f[N] = CORREL(data1[N],data2[N])\n !\n ! Computes the correlation of two arrays for a lag: f(N) to f(N/2+1) are\n ! negative lags, f(1) is lag 0, and f(1) to f(N/2) are positive lags.\n !==========================================================================\n\n FUNCTION correl (data1,data2)\n \n USE utilities, ONLY: DP, CDP, strike\n IMPLICIT NONE\n REAL(DP), DIMENSION(:), INTENT(INOUT) :: data1, data2\n REAL(DP), DIMENSION(SIZE(data1)) :: correl\n\n COMPLEX(CDP), DIMENSION(SIZE(data1)/2) :: cdat1, cdat2\n INTEGER :: No2, N\n\n !-------------------------------------------------------------------------\n\n ! Preliminaries\n N = SIZE(data1)\n IF (SIZE(data2) /= N) CALL STRIKE(\"CORREL\",\"Wrong size of input\")\n IF (IAND(N,N-1) /= 0) CALL STRIKE(\"CORREL\",\"N must be a power of 2\")\n No2 = N / 2\n\n ! Transform both data vectors\n CALL REALFT(data1,1,cdat1) \n CALL REALFT(data2,1,cdat2)\n \n ! Multiply to find FFT of their correlation\n cdat1(1) = CMPLX( REAL(cdat1(1)) * REAL(cdat2(1)) / No2, & \n AIMAG(cdat1(1)) * AIMAG(cdat2(1)) / No2, KIND=CDP ) \n cdat1(2:) = cdat1(2:) * CONJG(cdat2(2:)) / No2\n\n ! Inverse transform gives correlation\n CALL REALFT(correl,-1,cdat1) \n\n !-------------------------------------------------------------------------\n\n END FUNCTION correl\n\n\nEND MODULE FFT_specials\n", "meta": {"hexsha": "4ee1d876abbd6136ddcebc5cf962f360112d790a", "size": 8878, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MILES/swing/Math/fft_specials.f90", "max_stars_repo_name": "kxxdhdn/MISSILE", "max_stars_repo_head_hexsha": "89dea38aa9247f20c444ccd0b832c674be275fbf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MILES/swing/Math/fft_specials.f90", "max_issues_repo_name": "kxxdhdn/MISSILE", "max_issues_repo_head_hexsha": "89dea38aa9247f20c444ccd0b832c674be275fbf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MILES/swing/Math/fft_specials.f90", "max_forks_repo_name": "kxxdhdn/MISSILE", "max_forks_repo_head_hexsha": "89dea38aa9247f20c444ccd0b832c674be275fbf", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.2509363296, "max_line_length": 80, "alphanum_fraction": 0.4909889615, "num_tokens": 2692, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939913343093499, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.757224437469644}} {"text": "SUBROUTINE ludcmp_sp(a,indx,d)\n use mo_kind, ONLY : i4, sp\n use mo_nrutil, ONLY : assert_eq,imaxloc,nrerror,outerprod,swap\n IMPLICIT NONE\n REAL(SP), DIMENSION(:,:), INTENT(INOUT) :: a\n INTEGER(I4), DIMENSION(:), INTENT(OUT) :: indx\n REAL(SP), INTENT(OUT) :: d\n REAL(SP), DIMENSION(size(a,1)) :: vv\n REAL(SP), PARAMETER :: TINY=1.0e-20_sp\n INTEGER(I4) :: j,n,imax\n n=assert_eq(size(a,1),size(a,2),size(indx),'ludcmp')\n d=1.0_sp\n vv=maxval(abs(a),dim=2)\n if (any(vv == 0.0)) call nrerror('singular matrix in ludcmp')\n vv=1.0_sp/vv\n do j=1,n\n imax=(j-1)+imaxloc(vv(j:n)*abs(a(j:n,j)))\n if (j /= imax) then\n call swap(a(imax,:),a(j,:))\n d=-d\n vv(imax)=vv(j)\n end if\n indx(j)=imax\n if (a(j,j) == 0.0) a(j,j)=TINY\n a(j+1:n,j)=a(j+1:n,j)/a(j,j)\n a(j+1:n,j+1:n)=a(j+1:n,j+1:n)-outerprod(a(j+1:n,j),a(j,j+1:n))\n end do\nEND SUBROUTINE ludcmp_sp\n\nSUBROUTINE ludcmp_dp(a,indx,d)\n use mo_kind, ONLY : i4, dp\n use mo_nrutil, ONLY : assert_eq,imaxloc,nrerror,outerprod,swap\n IMPLICIT NONE\n REAL(DP), DIMENSION(:,:), INTENT(INOUT) :: a\n INTEGER(I4), DIMENSION(:), INTENT(OUT) :: indx\n REAL(DP), INTENT(OUT) :: d\n REAL(DP), DIMENSION(size(a,1)) :: vv\n REAL(DP), PARAMETER :: TINY=1.0e-20_dp\n INTEGER(I4) :: j,n,imax\n n=assert_eq(size(a,1),size(a,2),size(indx),'ludcmp')\n d=1.0_dp\n vv=maxval(abs(a),dim=2)\n if (any(vv == 0.0)) call nrerror('singular matrix in ludcmp')\n vv=1.0_dp/vv\n do j=1,n\n imax=(j-1)+imaxloc(vv(j:n)*abs(a(j:n,j)))\n if (j /= imax) then\n call swap(a(imax,:),a(j,:))\n d=-d\n vv(imax)=vv(j)\n end if\n indx(j)=imax\n if (a(j,j) == 0.0) a(j,j)=TINY\n a(j+1:n,j)=a(j+1:n,j)/a(j,j)\n a(j+1:n,j+1:n)=a(j+1:n,j+1:n)-outerprod(a(j+1:n,j),a(j,j+1:n))\n end do\nEND SUBROUTINE ludcmp_dp\n", "meta": {"hexsha": "7843a4f15636f0230ebd05b26da944aa31635a1d", "size": 1805, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "nr_jams/ludcmp.f90", "max_stars_repo_name": "mcuntz/jams_fortran", "max_stars_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2020-02-28T00:14:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-20T23:32:41.000Z", "max_issues_repo_path": "nr_jams/ludcmp.f90", "max_issues_repo_name": "mcuntz/jams_fortran", "max_issues_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-09T15:33:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T16:16:09.000Z", "max_forks_repo_path": "nr_jams/ludcmp.f90", "max_forks_repo_name": "mcuntz/jams_fortran", "max_forks_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-09T08:08:56.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-09T08:08:56.000Z", "avg_line_length": 31.1206896552, "max_line_length": 67, "alphanum_fraction": 0.5783933518, "num_tokens": 750, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.8519528076067261, "lm_q1q2_score": 0.7571805494010653}} {"text": "SUBROUTINE SubmergedBar_2D(FineGrid,x0,GhostGridX)\n!\n! Define bottom and bottom gradients for submerged bar test (2D)\n!\n! By Allan P. Engsig-Karup.\nUSE Precision\nUSE Constants\nUSE DataTypes\nIMPLICIT NONE\nTYPE (Level_def) :: FineGrid\nREAL(KIND=long) :: x,x0\nINTEGER :: Nx, i, j, GhostGridX\n\nNx = FineGrid%Nx+2*GhostGridX\nj=1\n\nDO i = 1 , Nx\n \tx = FineGrid%x(i,j)-x0\n IF (x<=6.0_long) THEN\n FineGrid%h(i,j) = 0.4_long\n FineGrid%hx(i,j) = zero\n FineGrid%hxx(i,j) = zero\n ELSE IF (x<=12.0_long) THEN\n FineGrid%h(i,j) = 0.4_long - 1.0_long/20.0_long*(x-6.0_long)\n FineGrid%hx(i,j) = -1.0_long/20.0_long\n FineGrid%hxx(i,j) = zero\n ELSE IF (x<=14.0_long) THEN\n FineGrid%h(i,j) = 0.1_long\n FineGrid%hx(i,j) = zero\n FineGrid%hxx(i,j) = zero\n ELSE IF (x<=17.0_long) THEN\n FineGrid%h(i,j) = 0.1_long + 1.0_long/10.0_long*(x-14.0_long)\n FineGrid%hx(i,j) = 1.0_long/10.0_long\n FineGrid%hxx(i,j) = zero\n ELSE\n FineGrid%h(i,j) = 0.4_long\n FineGrid%hx(i,j) = zero\n FineGrid%hxx(i,j) = zero\n ENDIF\nEND DO\n\n\nEND SUBROUTINE SubmergedBar_2D\n", "meta": {"hexsha": "c8167acd0cf4c8bc88e987c9c7bd6b8eda9f776b", "size": 1160, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/analyticalsolutions/submergedbar2D.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/analyticalsolutions/submergedbar2D.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/analyticalsolutions/submergedbar2D.f90", "max_forks_repo_name": "apengsigkarup/OceanWave3D", "max_forks_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-01T12:17:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T16:23:37.000Z", "avg_line_length": 26.3636363636, "max_line_length": 71, "alphanum_fraction": 0.6051724138, "num_tokens": 455, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179068309441, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7571736457420348}} {"text": "MODULE module_rectangle\n\n IMPLICIT NONE\n\nCONTAINS\n\n REAL FUNCTION rectagle_area( side_a_length , side_b_length )\n IMPLICIT NONE\n REAL, INTENT(IN) :: side_a_length\n REAL, INTENT(IN) :: side_b_length\n\n rectagle_area=side_a_length*side_b_length\n END FUNCTION\n\n REAL FUNCTION rectagle_perimeter( side_a_length , side_b_length )\n IMPLICIT NONE\n REAL, INTENT(IN) :: side_a_length\n REAL, INTENT(IN) :: side_b_length\n\n rectagle_perimeter=2*side_a_length+2*side_b_length\n END FUNCTION\n\n\nEND MODULE module_rectangle\n", "meta": {"hexsha": "c826b73fa601f6aa00ad52c527a16fb888434bdb", "size": 577, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/example_project_2/myLibrary/module_rectangle.f90", "max_stars_repo_name": "aperezhortal/fortran_debugging_tutorial", "max_stars_repo_head_hexsha": "17f8cf83cf0289485456e5c40d110ddf71fc4554", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-08-29T19:48:44.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-29T19:48:44.000Z", "max_issues_repo_path": "examples/example_project_2/myLibrary/module_rectangle.f90", "max_issues_repo_name": "aperezhortal/fortran_debugging_introduction", "max_issues_repo_head_hexsha": "17f8cf83cf0289485456e5c40d110ddf71fc4554", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/example_project_2/myLibrary/module_rectangle.f90", "max_forks_repo_name": "aperezhortal/fortran_debugging_introduction", "max_forks_repo_head_hexsha": "17f8cf83cf0289485456e5c40d110ddf71fc4554", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.08, "max_line_length": 69, "alphanum_fraction": 0.7019064125, "num_tokens": 145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.9086178969328287, "lm_q1q2_score": 0.7571736337325724}} {"text": "\\ Using Algorithm in http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes\n\\ by yap yapcheahshen@gmail.com 2008.1.23\n\n: n 1024 ; \\ find all prime below N\n: sqrt 0 swap 0 do 1 + dup 2 * 1 + +loop ; \\ square root\ncreate buffer n allot \\ buffer to hold numbers \nbuffer n 255 fill \\ initial value, all numbers are prime\n\n\\ sieve ( r -- ) remove all proper multiply of r , \n\\ which are r*2, r*3, r*4 ... r*m < n \n: sieve n over dup + do 0 i buffer + c! dup +loop drop ; \n\n\\ sieve all number less than square root of N\n: eratosthenes n sqrt 2 do buffer i + c@ if i sieve then loop ; \n\n: prime eratosthenes n 2 do buffer i + c@ if i . then loop ;\n.( Prime numbers below ) n . cr prime", "meta": {"hexsha": "cc2fd053f4f4a15b632ab3dd5f4b6817193d59a7", "size": 757, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "prime.f", "max_stars_repo_name": "ksanaforge/ksanavm", "max_stars_repo_head_hexsha": "09e9c919a5812d58538b08b9f1b9ae984a0bf15f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "prime.f", "max_issues_repo_name": "ksanaforge/ksanavm", "max_issues_repo_head_hexsha": "09e9c919a5812d58538b08b9f1b9ae984a0bf15f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "prime.f", "max_forks_repo_name": "ksanaforge/ksanavm", "max_forks_repo_head_hexsha": "09e9c919a5812d58538b08b9f1b9ae984a0bf15f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.5294117647, "max_line_length": 75, "alphanum_fraction": 0.6010568032, "num_tokens": 223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517106286379, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.7571638374887829}} {"text": " MODULE random_binomial_mod\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n CONTAINS\n\n!*********************************************************************\n\n FUNCTION random_binomial(n,pr)\n!**********************************************************************\n! INTEGER FUNCTION IGNBIN( N, pr )\n! GENerate BINomial random deviate\n! Function\n! Generates a single random deviate from a binomial\n! distribution whose number of trials is N and whose\n! probability of an event in each trial is P.\n! Arguments\n! N --> The number of trials in the binomial distribution\n! from which a random deviate is to be generated.\n! INTEGER N\n! JJV (N >= 0)\n! pr --> The probability of an event in each trial of the\n! binomial distribution from which a random deviate\n! is to be generated.\n! REAL pr\n! JJV (0.0 <= pr <= 1.0)\n! IGNBIN <-- A random deviate yielding the number of events\n! from N independent trials, each of which has\n! a probability of event P.\n! INTEGER IGNBIN\n! Note\n! Uses RANF so the value of the seeds, ISEED1 and ISEED2 must be set\n! by a call similar to the following\n! DUM = RANSET( ISEED1, ISEED2 )\n! Method\n! This is algorithm BTPE from:\n! Kachitvichyanukul, V. and Schmeiser, B. W.\n! Binomial Random Variate Generation.\n! Communications of the ACM, 31, 2\n! (February, 1988) 216.\n!**********************************************************************\n! SUBROUTINE BTPEC(N,pr,ISEED,JX)\n! BINOMIAL RANDOM VARIATE GENERATOR\n! MEAN .LT. 30 -- INVERSE CDF\n! MEAN .GE. 30 -- ALGORITHM BTPE: ACCEPTANCE-REJECTION VIA\n! FOUR REGION COMPOSITION. THE FOUR REGIONS ARE A TRIANGLE\n! (SYMMETRIC IN THE CENTER), A PAIR OF PARALLELOGRAMS (ABOVE\n! THE TRIANGLE), AND EXPONENTIAL LEFT AND RIGHT TAILS.\n! BTPE REFERS TO BINOMIAL-TRIANGLE-PARALLELOGRAM-EXPONENTIAL.\n! BTPEC REFERS TO BTPE AND \"COMBINED.\" THUS BTPE IS THE\n! RESEARCH AND BTPEC IS THE IMPLEMENTATION OF A COMPLETE\n! USABLE ALGORITHM.\n! REFERENCE: VORATAS KACHITVICHYANUKUL AND BRUCE SCHMEISER,\n! \"BINOMIAL RANDOM VARIATE GENERATION,\"\n! COMMUNICATIONS OF THE ACM, FORTHCOMING\n! WRITTEN: SEPTEMBER 1980.\n! LAST REVISED: MAY 1985, JULY 1987\n! REQUIRED SUBPROGRAM: RAND() -- A UNIFORM (0,1) RANDOM NUMBER\n! GENERATOR\n! ARGUMENTS\n! N : NUMBER OF BERNOULLI TRIALS (INPUT)\n! pr : PROBABILITY OF SUCCESS IN EACH TRIAL (INPUT)\n! ISEED: RANDOM NUMBER SEED (INPUT AND OUTPUT)\n! JX: RANDOMLY GENERATED OBSERVATION (OUTPUT)\n! VARIABLES\n! PSAVE: VALUE OF pr FROM THE LAST CALL TO BTPEC\n! NSAVE: VALUE OF N FROM THE LAST CALL TO BTPEC\n! XNP: VALUE OF THE MEAN FROM THE LAST CALL TO BTPEC\n! P: PROBABILITY USED IN THE GENERATION PHASE OF BTPEC\n! FFM: TEMPORARY VARIABLE EQUAL TO XNP + P\n! M: INTEGER VALUE OF THE CURRENT MODE\n! FM: FLOATING POINT VALUE OF THE CURRENT MODE\n! XNPQ: TEMPORARY VARIABLE USED IN SETUP AND SQUEEZING STEPS\n! P1: AREA OF THE TRIANGLE\n! C: HEIGHT OF THE PARALLELOGRAMS\n! XM: CENTER OF THE TRIANGLE\n! XL: LEFT END OF THE TRIANGLE\n! XR: RIGHT END OF THE TRIANGLE\n! AL: TEMPORARY VARIABLE\n! XLL: RATE FOR THE LEFT EXPONENTIAL TAIL\n! XLR: RATE FOR THE RIGHT EXPONENTIAL TAIL\n! P2: AREA OF THE PARALLELOGRAMS\n! P3: AREA OF THE LEFT EXPONENTIAL TAIL\n! P4: AREA OF THE RIGHT EXPONENTIAL TAIL\n! U: A U(0,P4) RANDOM VARIATE USED FIRST TO SELECT ONE OF THE\n! FOUR REGIONS AND THEN CONDITIONALLY TO GENERATE A VALUE\n! FROM THE REGION\n! V: A U(0,1) RANDOM NUMBER USED TO GENERATE THE RANDOM VALUE\n! (REGION 1) OR TRANSFORMED INTO THE VARIATE TO ACCEPT OR\n! REJECT THE CANDIDATE VALUE\n! IX: INTEGER CANDIDATE VALUE\n! X: PRELIMINARY CONTINUOUS CANDIDATE VALUE IN REGION 2 LOGIC\n! AND A FLOATING POINT IX IN THE ACCEPT/REJECT LOGIC\n! K: ABSOLUTE VALUE OF (IX-M)\n! F: THE HEIGHT OF THE SCALED DENSITY FUNCTION USED IN THE\n! ACCEPT/REJECT DECISION WHEN BOTH M AND IX ARE SMALL\n! ALSO USED IN THE INVERSE TRANSFORMATION\n! R: THE RATIO P/Q\n! G: CONSTANT USED IN CALCULATION OF PROBABILITY\n! MP: MODE PLUS ONE, THE LOWER INDEX FOR EXPLICIT CALCULATION\n! OF F WHEN IX IS GREATER THAN M\n! IX1: CANDIDATE VALUE PLUS ONE, THE LOWER INDEX FOR EXPLICIT\n! CALCULATION OF F WHEN IX IS LESS THAN M\n! I: INDEX FOR EXPLICIT CALCULATION OF F FOR BTPE\n! AMAXP: MAXIMUM ERROR OF THE LOGARITHM OF NORMAL BOUND\n! YNORM: LOGARITHM OF NORMAL BOUND\n! ALV: NATURAL LOGARITHM OF THE ACCEPT/REJECT VARIATE V\n! X1,F1,Z,W,Z2,X2,F2, AND W2 ARE TEMPORARY VARIABLES TO BE\n! USED IN THE FINAL ACCEPT/REJECT TEST\n! QN: PROBABILITY OF NO SUCCESS IN N TRIALS\n! REMARK\n! IX AND JX COULD LOGICALLY BE THE SAME VARIABLE, WHICH WOULD\n! SAVE A MEMORY POSITION AND A LINE OF CODE. HOWEVER, SOME\n! COMPILERS (E.G.,CDC MNF) OPTIMIZE BETTER WHEN THE ARGUMENTS\n! ARE NOT INVOLVED.\n! ISEED NEEDS TO BE DOUBLE PRECISION IF THE IMSL ROUTINE\n! GGUBFS IS USED TO GENERATE UNIFORM RANDOM NUMBER, OTHERWISE\n! TYPE OF ISEED SHOULD BE DICTATED BY THE UNIFORM GENERATOR\n!**********************************************************************\n!*****DETERMINE APPROPRIATE ALGORITHM AND WHETHER SETUP IS NECESSARY\n! JJV ..\n! JJV .. Save statement ..\n! JJV I am including the variables in data statements\n! JJV made these ridiculous starting values - the hope is that\n! JJV no one will call this the first time with them as args\n! .. Use Statements ..\n USE random_standard_uniform_mod\n! ..\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n! .. Function Return Value ..\n INTEGER :: random_binomial\n! ..\n! .. Scalar Arguments ..\n REAL, INTENT (IN) :: pr\n INTEGER, INTENT (IN) :: n\n! ..\n! .. Local Scalars ..\n REAL :: al, alv, amaxp, f, f1, f2, ffm, u, v, w, w2, x, x1, x2, &\n ynorm, z, z2\n REAL, SAVE :: c, fm, g, p, p1, p2, p3, p4, psave, q, qn, r, xl, &\n xll, xlr, xm, xnp, xnpq, xr\n INTEGER :: i, ix, ix1, k, mp\n INTEGER, SAVE :: m, nsave\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS, ALOG, AMIN1, IABS, INT, SQRT\n! ..\n! .. Data Statements ..\n DATA psave, nsave/ -1.0E37, -214748365/\n! ..\n! .. Executable Statements ..\n\n IF (pr==psave) THEN\n IF (n/=nsave) GO TO 10\n IF (xnp-30.<0.) GO TO 50\n GO TO 20\n END IF\n\n!*****SETUP, PERFORM ONLY WHEN PARAMETERS CHANGE\n\n\n! JJV added the argument checker - involved only renaming 10\n! JJV and 20 to the checkers and adding checkers\n! JJV Only remaining problem - if called initially with the\n! JJV initial values of psave and nsave, it will hang\n IF (pr<0.0) STOP 'pr < 0.0 in IGNBIN - ABORT!'\n IF (pr>1.0) STOP 'pr > 1.0 in IGNBIN - ABORT!'\n psave = pr\n p = AMIN1(psave,1.-psave)\n q = 1. - p\n10 CONTINUE\n IF (n<0) STOP 'N < 0 in IGNBIN - ABORT!'\n xnp = n*p\n nsave = n\n IF (xnp<30.) GO TO 40\n ffm = xnp + p\n m = ffm\n fm = m\n xnpq = xnp*q\n p1 = INT(2.195*SQRT(xnpq)-4.6*q) + 0.5\n xm = fm + 0.5\n xl = xm - p1\n xr = xm + p1\n c = 0.134 + 20.5/(15.3+fm)\n al = (ffm-xl)/(ffm-xl*p)\n xll = al*(1.+0.5*al)\n al = (xr-ffm)/(xr*q)\n xlr = al*(1.+0.5*al)\n p2 = p1*(1.+c+c)\n p3 = p2 + c/xll\n p4 = p3 + c/xlr\n! WRITE(6,100) N,P,P1,P2,P3,P4,XL,XR,XM,FM\n! 100 FORMAT(I15,4F18.7/5F18.7)\n\n!*****GENERATE VARIATE\n\n20 CONTINUE\n u = random_standard_uniform()*p4\n v = random_standard_uniform()\n\n! TRIANGULAR REGION\n\n IF (u<=p1) THEN\n ix = xm - p1*v + u\n GO TO 70\n END IF\n\n! PARALLELOGRAM REGION\n\n IF (u<=p2) THEN\n x = xl + (u-p1)/c\n v = v*c + 1. - ABS(xm-x)/p1\n IF (v>1. .OR. v<=0.) GO TO 20\n ix = x\n ELSE\n\n! LEFT TAIL\n\n IF (u<=p3) THEN\n ix = xl + ALOG(v)/xll\n IF (ix<0) GO TO 20\n v = v*(u-p2)*xll\n ELSE\n\n! RIGHT TAIL\n\n ix = xr - ALOG(v)/xlr\n IF (ix>n) GO TO 20\n v = v*(u-p3)*xlr\n\n!*****DETERMINE APPROPRIATE WAY TO PERFORM ACCEPT/REJECT TEST\n\n END IF\n END IF\n k = IABS(ix-m)\n IF (k<=20 .OR. k>=xnpq/2-1) THEN\n\n! EXPLICIT EVALUATION\n\n f = 1.0\n r = p/q\n g = (n+1)*r\n IF (m-ix<=0) THEN\n IF (m-ix==0) GO TO 30\n mp = m + 1\n DO i = mp, ix\n f = f*(g/i-r)\n END DO\n GO TO 30\n END IF\n\n ix1 = ix + 1\n DO i = ix1, m\n f = f/(g/i-r)\n END DO\n30 CONTINUE\n IF (v-f>0.) GO TO 20\n GO TO 70\n END IF\n\n! SQUEEZING USING UPPER AND LOWER BOUNDS ON ALOG(F(X))\n\n amaxp = (k/xnpq)*((k*(k/3.+0.625)+0.1666666666666)/xnpq+0.5)\n ynorm = -k*k/(2.*xnpq)\n alv = ALOG(v)\n IF (alvynorm+amaxp) GO TO 20\n\n! STIRLING'S FORMULA TO MACHINE ACCURACY FOR\n! THE FINAL ACCEPTANCE/REJECTION TEST\n\n x1 = ix + 1\n f1 = fm + 1.\n z = n + 1 - fm\n w = n - ix + 1.\n z2 = z*z\n x2 = x1*x1\n f2 = f1*f1\n w2 = w*w\n IF (alv-(xm*ALOG(f1/x1)+(n-m+0.5)*ALOG(z/w)+(ix-m)*ALOG(w*p/(x1*q &\n ))+(13860.-(462.-(132.-(99.-140./f2)/f2)/f2)/f2)/f1/166320.+( &\n 13860.-(462.-(132.-(99.-140./z2)/z2)/z2)/z2)/z/166320.+(13860.- &\n (462.-(132.-(99.-140./x2)/x2)/x2)/x2)/x1/166320.+(13860.-(462.- &\n (132.-(99.-140./w2)/w2)/w2)/w2)/w/166320.)>0.) GO TO 20\n GO TO 70\n\n! INVERSE CDF LOGIC FOR MEAN LESS THAN 30\n\n40 CONTINUE\n qn = q**n\n r = p/q\n g = r*(n+1)\n50 CONTINUE\n ix = 0\n f = qn\n u = random_standard_uniform()\n60 CONTINUE\n IF (u110) GO TO 50\n u = u - f\n ix = ix + 1\n f = f*(g/ix-r)\n GO TO 60\n\n70 CONTINUE\n IF (psave>0.5) ix = n - ix\n random_binomial = ix\n RETURN\n\n END FUNCTION random_binomial\n\n!*********************************************************************\n\n END MODULE random_binomial_mod\n", "meta": {"hexsha": "340fb7506a3ae68cfe9557dec46235384e251b26", "size": 10957, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/random_binomial_mod.f90", "max_stars_repo_name": "urbanjost/fpm_tools", "max_stars_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/random_binomial_mod.f90", "max_issues_repo_name": "urbanjost/fpm_tools", "max_issues_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/random_binomial_mod.f90", "max_forks_repo_name": "urbanjost/fpm_tools", "max_forks_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-14T11:36:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-14T11:36:01.000Z", "avg_line_length": 34.5646687697, "max_line_length": 75, "alphanum_fraction": 0.5295245049, "num_tokens": 3447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654264, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7571554302701238}} {"text": "module algebra\n\npublic :: normalize\npublic :: dot_product\npublic :: cross_product\npublic :: rotate_vector_angle_axis\npublic :: rotate_matrix_angle_axis\npublic :: jacobi\npublic :: eig_sort\npublic :: mean\npublic :: stdev\npublic :: coefvar\n\n!--------------------------------------------------------------------------------------------------!\ncontains\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine normalize(vector)\nimplicit none\ndouble precision :: vector(3)\ndouble precision :: magnitude\nmagnitude = sqrt(vector(1)*vector(1)+vector(2)*vector(2)+vector(3)*vector(3))\nvector = vector/magnitude\nreturn\nend\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine dot_product(vec1,vec2,dot)\nimplicit none\ndouble precision :: vec1(3), vec2(3)\ndouble precision :: dot\ndot = vec1(1)*vec2(1) + vec1(2)*vec2(2) + vec1(3)*vec2(3)\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine cross_product(vec1,vec2,cross)\nimplicit none\ndouble precision :: vec1(3), vec2(3)\ndouble precision :: cross(3)\ncross(1) = vec1(2)*vec2(3) - vec1(3)*vec2(2)\ncross(2) = vec1(3)*vec2(1) - vec1(1)*vec2(3)\ncross(3) = vec1(1)*vec2(2) - vec1(2)*vec2(1)\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine rotate_vector_angle_axis(vec_in,angle,axis,vec_out,ierr)\n!----\n! Rotate a vector counter-clockwise through a coordinate system by an angle (in degrees) about an\n! axis of the coordinate system.\n!----\n\nuse io, only: stderr\nuse trig, only: d2r\n\nimplicit none\n\n! Arguments\ndouble precision :: vec_in(3), angle\ndouble precision :: vec_out(3)\ncharacter(len=*) :: axis\ninteger :: ierr\n\n! Local variables\ndouble precision :: vec_tmp(3), rot_matrix(3,3), cosa, sina\n\n\n! Initialize error\nierr = 0\n\n! Cosine and sine of angle\ncosa = cos(angle*d2r)\nsina = sin(angle*d2r)\n\nvec_tmp = vec_in\n\n! Build the rotation matrix\nrot_matrix = 0.0d0\nif (axis.eq.'x') then\n rot_matrix(1,1) = 1.0d0\n rot_matrix(2,2) = cosa\n rot_matrix(3,3) = cosa\n rot_matrix(2,3) = -sina\n rot_matrix(3,2) = sina\nelseif (axis.eq.'y') then\n rot_matrix(2,2) = 1.0d0\n rot_matrix(3,3) = cosa\n rot_matrix(1,1) = cosa\n rot_matrix(3,1) = -sina\n rot_matrix(1,3) = sina\nelseif (axis.eq.'z') then\n rot_matrix(3,3) = 1.0d0\n rot_matrix(1,1) = cosa\n rot_matrix(2,2) = cosa\n rot_matrix(1,2) = -sina\n rot_matrix(2,1) = sina\nelse\n write(stderr,*) 'rotate_vector_angle_axis: no axis named \"',trim(axis),'\"'\n ierr = 1\n return\nendif\n\n! Multiply matrix and input vector to get rotated vector\nvec_out(1) = rot_matrix(1,1)*vec_tmp(1) + rot_matrix(1,2)*vec_tmp(2) + rot_matrix(1,3)*vec_tmp(3)\nvec_out(2) = rot_matrix(2,1)*vec_tmp(1) + rot_matrix(2,2)*vec_tmp(2) + rot_matrix(2,3)*vec_tmp(3)\nvec_out(3) = rot_matrix(3,1)*vec_tmp(1) + rot_matrix(3,2)*vec_tmp(2) + rot_matrix(3,3)*vec_tmp(3)\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine rotate_matrix_angle_axis(matrix_in,angle,axis,matrix_out,ierr)\n!----\n! Rotate a matrix counter-clockwise through a coordinate system by an angle (in degrees) about an\n! axis of the coordinate system.\n!----\n\nuse io, only: stderr\nuse trig, only: d2r\n\nimplicit none\n\n! Arguments\ndouble precision :: matrix_in(3,3), angle\ndouble precision :: matrix_out(3,3)\ncharacter(len=*) :: axis\ninteger :: ierr\n\n! Local variables\ndouble precision :: rot_matrix(3,3), rot_matrix_trans(3,3), matrix_tmp(3,3), cosa, sina\ninteger :: i, j\n\n\n! Initialize error\nierr = 0\n\n! Cosine and sine of angle\ncosa = cos(angle*d2r)\nsina = sin(angle*d2r)\n\n! Build the rotation matrix\nrot_matrix = 0.0d0\nif (axis.eq.'x') then\n rot_matrix(1,1) = 1.0d0\n rot_matrix(2,2) = cosa\n rot_matrix(3,3) = cosa\n rot_matrix(2,3) = -sina\n rot_matrix(3,2) = sina\nelseif (axis.eq.'y') then\n rot_matrix(2,2) = 1.0d0\n rot_matrix(3,3) = cosa\n rot_matrix(1,1) = cosa\n rot_matrix(3,1) = -sina\n rot_matrix(1,3) = sina\nelseif (axis.eq.'z') then\n rot_matrix(3,3) = 1.0d0\n rot_matrix(1,1) = cosa\n rot_matrix(2,2) = cosa\n rot_matrix(1,2) = -sina\n rot_matrix(2,1) = sina\nelse\n write(stderr,*) 'rotate_matrix_angle_axis: no axis named \"',trim(axis),'\"'\n ierr = 1\n return\nendif\n\n! And its transpose (inverse)\nrot_matrix_trans = rot_matrix\nrot_matrix_trans(1,2) = rot_matrix(2,1)\nrot_matrix_trans(1,3) = rot_matrix(3,1)\nrot_matrix_trans(2,1) = rot_matrix(1,2)\nrot_matrix_trans(2,3) = rot_matrix(3,2)\nrot_matrix_trans(3,1) = rot_matrix(1,3)\nrot_matrix_trans(3,2) = rot_matrix(2,3)\n\n! Multiply input matrix by rotation matrix and transpose to get rotated matrix: R*M*RT\ndo i = 1,3\n do j = 1,3\n matrix_tmp(i,j) = rot_matrix(i,1)*matrix_in(1,j) + &\n rot_matrix(i,2)*matrix_in(2,j) + &\n rot_matrix(i,3)*matrix_in(3,j)\n enddo\nenddo\ndo i = 1,3\n do j = 1,3\n matrix_out(i,j) = matrix_tmp(i,1)*rot_matrix_trans(1,j) + &\n matrix_tmp(i,2)*rot_matrix_trans(2,j) + &\n matrix_tmp(i,3)*rot_matrix_trans(3,j)\n enddo\nenddo\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine jacobi(a,n,np,d,v,nrot,ierr)\n!----\n! Computes all eigenvalues and eigenvectors of a real symmetric matrix a, which is of size n by n,\n! stored in a physical np by np array. On output, elements of a above the diagonal are destroyed. d\n! returns the eigenvalues of a in its first n elements. v is a matrix with the same logical and\n! physical dimensions as a, whose columns contain, on output, the normalized eigenvectors of a.\n! nrot returns the number of Jacobi rotations that were required.\n!\n! Numerical Recipes (Press et al.)\n!----\n\nuse io, only: stderr\n\nimplicit none\n\n! Arguments\ninteger :: n, np\ninteger :: nrot, ierr\ndouble precision :: a(np,np), d(np), v(np,np)\n\n! Local variables\ninteger, parameter :: NMAX = 500\ninteger :: i, ip, iq, j\ndouble precision :: c, g, h, s, sm, t, tau, theta, tresh, b(NMAX), z(NMAX)\ndouble precision, parameter :: eps = 1.0d-12\n\n\nierr = 0\n\n! Initialize v to the identity matrix\nv = 0.0d0\ndo ip = 1,n\n v(ip,ip) = 1.0d0\nenddo\n\n! Initialize b and d to the diagonal of a\n! Vector z will accumulate terms of the form tapq as in equation (11.1.14)\ndo ip = 1,n\n b(ip) = a(ip,ip)\n d(ip) = b(ip)\n z(ip) = 0.0d0\nenddo\n\nnrot = 0\ndo i = 1,50\n\n ! Sum off-diagonal elements\n sm = 0.0d0\n do ip = 1,n-1\n do iq = ip+1,n\n sm = sm + abs(a(ip,iq))\n enddo\n enddo\n\n ! The normal return, which relies on quadratic convergence\n if (abs(sm).lt.eps) then\n return\n endif\n\n if (i.lt.4) then\n tresh = 0.2d0*sm/n**2\n else\n tresh = 0.0d0\n endif\n\n do ip = 1,n-1\n do iq = ip+1,n\n\n g = 100.0d0*abs(a(ip,iq))\n\n ! After four sweeps, skip the rotation if the off-diagonal element is small\n if ((i.gt.4) .and. abs(g).lt.eps) then\n a(ip,iq) = 0.0d0\n elseif (abs(a(ip,iq)).gt.tresh) then\n h = d(iq)-d(ip)\n if (abs(g).lt.eps) then\n t = a(ip,iq)/h ! t = 1/(2theta)\n else\n theta = 0.5d0*h/a(ip,iq) !Equation (11.1.10)\n t = 1.0d0/(abs(theta)+sqrt(1.0d0+theta**2))\n if (theta.lt.0.0d0) then\n t = -t\n endif\n endif\n c = 1.0d0/sqrt(1.0d0+t**2)\n s = t*c\n tau = s/(1.0d0+c)\n h = t*a(ip,iq)\n z(ip) = z(ip)-h\n z(iq) = z(iq)+h\n d(ip) = d(ip)-h\n d(iq) = d(iq)+h\n a(ip,iq) = 0.0d0\n do j = 1,ip-1 ! Case of rotations 1 < j < p\n g = a(j,ip)\n h = a(j,iq)\n a(j,ip) = g-s*(h+g*tau)\n a(j,iq) = h+s*(g-h*tau)\n enddo\n do j = ip+1,iq-1 !Case of rotations p < j < q\n g = a(ip,j)\n h = a(j,iq)\n a(ip,j) = g-s*(h+g*tau)\n a(j,iq) = h+s*(g-h*tau)\n enddo\n do j = iq+1,n !Case of rotations q < j ≤ n\n g = a(ip,j)\n h = a(iq,j)\n a(ip,j) = g-s*(h+g*tau)\n a(iq,j) = h+s*(g-h*tau)\n enddo\n do j = 1,n\n g = v(j,ip)\n h = v(j,iq)\n v(j,ip) = g-s*(h+g*tau)\n v(j,iq) = h+s*(g-h*tau)\n enddo\n nrot = nrot + 1\n endif\n enddo\n enddo\n\n ! Update d with the sum of tapq, and reinitialize z\n do ip = 1,n\n b(ip) = b(ip)+z(ip)\n d(ip) = b(ip)\n z(ip) = 0.0d0\n enddo\nenddo\n\nwrite(stderr,*) 'Warning: jacobi: too many iterations'\nierr = 1\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine eig_sort(d,v,n,np)\n!----\n! Given the eigenvalues d and eigenvectors v as output from jacobi, this routine sorts the\n! eigenvalues into ascending order, and rearranges the columns of v correspondingly. The method\n! is straight insertion.\n!\n! Numerical Recipes (Press et al.)\n!----\n\nimplicit none\n\n! Arguments\ninteger :: n, np\ndouble precision :: d(np), v(np,np)\n\n! local variables\ninteger :: i, j, k\ndouble precision :: p\n\ndo i = 1,n-1\n k = i\n p = d(i)\n do j = i+1,n\n if (d(j).le.p) then\n k = j\n p = d(j)\n endif\n enddo\n if (k.ne.i) then\n d(k) = d(i)\n d(i) = p\n do j = 1,n\n p = v(j,i)\n v(j,i) = v(j,k)\n v(j,k) = p\n enddo\n endif\nenddo\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nfunction mean(values,nvalues,ierr)\n!----\n! Calculate mean of a set of values\n!----\n\nimplicit none\n\n! Arguments\ninteger :: nvalues\ninteger :: ierr\ndouble precision :: values(nvalues)\ndouble precision :: mean\n\n! Local variables\ninteger :: i\n\n! Initialize variables\nierr = 0\nmean = 0.0d0\n\n! Calculate sum of values\ndo i = 1,nvalues\n mean = mean + values(i)\nenddo\n\n! Divide by number of values\nmean = mean/dble(nvalues)\n\nreturn\nend function\n\n!--------------------------------------------------------------------------------------------------!\n\nfunction stdev(values,nvalues,ierr)\n!----\n! Calculate standard deviation of a set of values\n!----\n\nimplicit none\n\n! Arguments\ninteger :: nvalues\ninteger :: ierr\ndouble precision :: values(nvalues)\ndouble precision :: stdev\n\n! Local variables\ninteger :: i\ndouble precision :: m\n\n! Initialize variables\nierr = 0\nstdev = 0.0d0\n\n! Calculate mean\nm = mean(values,nvalues,ierr)\n\n! Calculate sum of differences squared\ndo i = 1,nvalues\n stdev = stdev + (values(i)-m)**2\nenddo\n\n! Divide by number of values, take square root\nstdev = sqrt(stdev/dble(nvalues-1))\n\nreturn\nend function\n\n!--------------------------------------------------------------------------------------------------!\n\nfunction coefvar(values,nvalues,ierr)\n!----\n! Calculate coefficient of variation (standard deviation divided by mean) of a set of values\n!----\n\nimplicit none\n\n! Arguments\ninteger :: nvalues\ninteger :: ierr\ndouble precision :: values(nvalues)\ndouble precision :: coefvar\n\n! Local variables\ndouble precision :: s, m\ndouble precision, parameter :: eps = 1.0d-30\n\n! Initialize variables\nierr = 0\ncoefvar = 0.0d0\n\n! Calculate mean\nm = mean(values,nvalues,ierr)\nif (abs(m).lt.eps) then\n return\n ierr = 1\nendif\n\n! Calculate standard deviation\ns = stdev(values,nvalues,ierr)\n\n! Divide standard devation by mean\ncoefvar = s/m\n\nreturn\nend function\n\nend module\n", "meta": {"hexsha": "56b22c41b1739470ab6a2ebe5600c2e96f6a2cdd", "size": 12139, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/algebra_module.f90", "max_stars_repo_name": "mherman09/ElasticHalfspaceToolbox", "max_stars_repo_head_hexsha": "168b9391654f6d3940f8778789ec7642574a523a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-05-07T03:34:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-11T16:08:50.000Z", "max_issues_repo_path": "src/algebra_module.f90", "max_issues_repo_name": "mherman09/ElasticHalfspaceToolbox", "max_issues_repo_head_hexsha": "168b9391654f6d3940f8778789ec7642574a523a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-10-09T19:27:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-04T13:17:03.000Z", "max_forks_repo_path": "src/algebra_module.f90", "max_forks_repo_name": "mherman09/Hdef", "max_forks_repo_head_hexsha": "2b1606bb69810ddcfe59ea23601d14a30b840ea8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.6727642276, "max_line_length": 100, "alphanum_fraction": 0.539830299, "num_tokens": 3570, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.7570632650202958}} {"text": "program tquadgs\n\n! David H. Bailey 28 April 2018\n\n! COPYRIGHT AND DISCLAIMER:\n! All software in this package (c) 2018 David H. Bailey.\n! By downloading or using this software you agree to the copyright, disclaimer\n! and license agreement in the accompanying file DISCLAIMER.txt.\n\n! NOTE: This program runs very long (800 seconds with MPFUN-MPFR or 2800\n! seconds with MPFUN-Fort, on the author's computer), compared with tquad.f90\n! and the other sample application programs. For this reason it is NOT\n! included in the script mpfun-tests.scr.\n\n! This program demonstrates the quadrature routine 'quadgs', which employs\n! Gaussian quadrature. The function quadgs is suitable to integrate a\n! function that is continuous, infinitely differentiable and integrable on an\n! open interval containing the given finite interval. It can also be used for\n! integrals on the entire real line, by making a variable transformation,\n! which can be achieved by merely computing a modified set of weights and\n! abscissas -- see subroutine initqgs and the examples below.\n\n! The quadrature computation proceeds level-by-level, with the computational\n! cost (and, often, the accuracy) approximately doubling with each iteration,\n! until a target accuracy (500-digit precision in this case), based on an\n! accuracy estimate computed by the program, is achieved. In most cases\n! quadgs is significantly faster than quadts (tanh-sinh quadrature) for\n! regular functions on finite intervals. However, quadgs is not effective\n! in cases where the function or one of its higher-order derivatives has a\n! singularity at one or both endpoints. Also, the computational cost of\n! generating weight-abscissa data in quadgs is MUCH greater than for quadts,\n! quades or quadss; on the other hand, these data can be computed once and\n! stored in a file -- see below. For additional details on Gaussian\n! quadrature versus tanh-sinh schemes, see:\n\n! David H. Bailey, Xiaoye S. Li and Karthik Jeyabalan, \"A comparison of\n! three high-precision quadrature schemes,\" Experimental Mathematics, \n! vol. 14 (2005), no. 3, pg. 317-329, preprint available at\n! http://www.davidhbailey.com/dhbpapers/quadrature-em.pdf.\n\n! The function to be integrated must be defined in an external function\n! subprogram (see samples below), and the name of the function must be\n! included in a \"type (mp_real)\" and an \"external\" statement. Prior to\n! calling the quadrature routine, the initialization routine initgs must\n! be called to initialize the weight-abscissa arrays wkgs, xkgs, wkgu and\n! xkgu, or else these arrays must be read from a file -- see idata below.\n\n! All of these routines are 100% THREAD SAFE -- all requisite parameters\n! and arrays are passed through subroutine arguments. \n\n! Specific instructions:\n\n! First call initqgs with the arrays wkgs, xkgs, xkgu and xkgu as the last\n! four arguments. The initialization routine initqgs may run for a long\n! time, depending on precision: for nq1 = 11 and ndp1 = 500, initqgs runs\n! 12 minutes on the author's computer. In the code below, one has the option\n! of calling initqgs and then writing wkgs, xkgs, wkgu and xkgu to a file,\n! or else reading the previously computed arrays from a file -- see the\n! parameter idata. \n\n! For finite interval problems, call quadgs with the arrays wkgs and xkgs \n! as the last two arguments. Set x1 and x2, the limits of integration,\n! in executable statements, using high precision (nwds2 words) if possible.\n! Note in the examples below, x1 and x2 and set using high-precision values\n! of zero, one and pi (the variables zero, one and mppic). Using high\n! precision values for x1 and x2 facilitates more accurate argument scaling\n! in quadgs and, if necessary, in the function routines. See examples below.\n\n! For problems over the entire real line, call quadgs with wkgu and xkgu as\n! the last two arguments, and set x1 = -one and x2 = one. See examples below.\n\n! The problems performed below are a subset of the problems performed in\n! tquad.f90; the problem numbers here correspond to those in tquad.f90.\n\n! The following inputs are set in the parameter statement below:\n! idata 0: compute abscissas and weights from scratch and write to file\n! before performing quadrature problems.\n! 1: read abscissas and weights from a file.\n! By default, idata = 0; the file name is \"gauss-mm-nnnn.dat\", where\n! \"mm\" is the value of nq1 and \"nnnn\" is the value of ndp1.\n! ndp1 Primary (\"low\") precision in digits; this is the working precision\n! and also the target accuracy of quadrature results.\n! ndp2 Secondary (\"high\") precision in digits. By default, ndp2 = 2*ndp1.\n! neps1 Log10 of the primary tolerance. By default, neps1 = - ndp1.\n! neps2 Log10 of the secondary tolerance. By default, neps2 = -ndp2.\n! nq1 Max number of phases in quadrature routine; adding 1 increases\n! (possibly doubles) the number of accurate digits in the result,\n! but also roughly doubles the run time. nq1 must be at least 3.\n! nq2 Space parameter for wk and xk arrays in the calling program. By\n! default it is set to 6 * 2^nq1 + 100.\n! nwds1 Low precision in words. By default nwds1 = int (ndp1 / mpdpw + 2).\n! nwds2 High precision in words. By default nwds2 = int (ndp2 / mpdpw + 2).\n\nuse mpmodule\nimplicit none\ninteger i, i1, i2, idata, ndp1, ndp2, neps1, neps2, nq1, nq2, nwds1, nwds2, n1\nparameter (idata = 0, ndp1 = 500, ndp2 = 1000, neps1 = -ndp1, neps2 = -ndp2, &\n nq1 = 11, nq2 = 6 * 2 ** nq1 + 100, nwds1 = int (ndp1 / mpdpw + 2), &\n nwds2 = int (ndp2 / mpdpw + 2))\ncharacter*32 chr32\nreal (8) dplog10q, d1, d2, second, tm0, tm1, tm2\ntype (mp_real) err, quadgs, fun01, fun02, fun03, fun04, &\n fun15, fun16, fun17, fun18, one, t1, t2, t3, t4, wkgs(-1:nq2), xkgs(-1:nq2), &\n wkgu(-1:nq2), xkgu(-1:nq2), zero\ntype (mp_real) mppic, mpl02, x1, x2\nexternal fun01, fun02, fun03, fun04, fun15, fun16, fun17, fun18, &\n quadgs, second\n\n! Check to see if default precision is high enough.\n\nif (ndp2 > mpipl) then\n write (6, '(\"Increase default precision in module MPFUNF.\")')\n stop\nendif\n\n! Compute pi and log(2) to high precision (nwds2 words).\n\none = mpreal (1.d0, nwds2)\nzero = mpreal (0.d0, nwds2)\nmppic = mppi (nwds2)\nmpl02 = mplog2 (nwds2)\n\nwrite (6, 1) nq1, ndp1, ndp2, neps1, neps2\n1 format ('Quadgs test: Quadlevel =',i6/'Digits1 =',i6,' Digits2 =',i6, &\n ' Epsilon1 =',i6,' Epsilon2 =',i6)\n\n! Initialize weights and abscissas: wkgs, xkgs, wkgu, xkgu.\n\nwrite (chr32, '(\"gauss-\"i2.2,\"-\",i4.4,\".dat\")') nq1, ndp1\nopen (11, file = chr32)\nrewind 11\ntm0 = second ()\nif (idata == 0) then\n\n! Generate xkgs, xkgs, wkgu and xkgu from scratch and write to file.\n\n call initqgs (nq1, nq2, nwds1, wkgs, xkgs, wkgu, xkgu)\n n1 = dble (xkgs(-1))\n\n do i = -1, n1\n write (11, '(2i6)') i, n1\n call mpwrite (11, ndp1 + 30, ndp1 + 10, wkgs(i), xkgs(i))\n call mpwrite (11, ndp1 + 30, ndp1 + 10, wkgu(i), xkgu(i))\n enddo\nelse\n\n! Read xkgs, xkgs, wkgu and xkgu from file.\n\n open (11, file = chr32)\n rewind 11\n read (11, '(2i6)') i1, i2\n call mpread (11, wkgs(-1), xkgs(-1), nwds1)\n call mpread (11, wkgu(-1), xkgu(-1), nwds1)\n n1 = dble (xkgs(-1))\n if (i1 /= -1 .or. i2 /= n1) stop\n\n do i = 0, n1\n read (11, '(2i6)') i1, i2\n if (i1 /= i .or. i2 /= n1) stop\n call mpread (11, wkgs(i), xkgs(i), nwds1)\n call mpread (11, wkgu(i), xkgu(i), nwds1)\n enddo\nendif\nclose (11)\ntm1 = second ()\ntm2 = tm1 - tm0\nwrite (6, 2) tm1 - tm0\n2 format ('Quadrature initialization completed: cpu time =',f12.4)\n\n! Begin quadrature tests.\n\nwrite (6, 11)\n11 format (/'Continuous functions on finite intervals:'//&\n 'Problem 1: Int_0^1 t*log(1+t) dt = 1/4'/)\nx1 = zero\nx2 = one\ntm0 = second ()\nt1 = quadgs (fun01, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkgs, xkgs)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\n3 format ('Quadrature completed: CPU time =',f12.6/'Result =')\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = mpreal (0.25d0, nwds1)\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n4 format ('Actual error =',f10.6,'x10^',i6)\n\nwrite (6, 12)\n12 format (/'Problem 2: Int_0^1 t^2*arctan(t) dt = (pi - 2 + 2*log(2))/12'/)\nx1 = zero\nx2 = one\ntm0 = second ()\nt1 = quadgs (fun02, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkgs, xkgs)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = (mppic - 2.d0 + 2.d0 * mpl02) / 12.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 13)\n13 format (/'Problem 3: Int_0^(pi/2) e^t*cos(t) dt = 1/2*(e^(pi/2) - 1)'/)\nx1 = zero\nx2 = 0.5d0 * mppic\ntm0 = second ()\nt1 = quadgs (fun03, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkgs, xkgs)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = 0.5d0 * (exp (0.5d0 * mppic) - 1.d0)\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 14)\n14 format (/ &\n 'Problem 4: Int_0^1 arctan(sqrt(2+t^2))/((1+t^2)sqrt(2+t^2)) dt = 5*Pi^2/96'/)\nx1 = zero\nx2 = one\ntm0 = second ()\nt1 = quadgs (fun04, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkgs, xkgs)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = 5.d0 * mppic**2 / 96.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 25)\n25 format (/ &\n 'Functions on the entire real line:'// &\n 'Problem 15: Int_-inf^inf 1/(1+t^2) dt = Pi'/)\nx1 = -one\nx2 = one\ntm0 = second ()\nt1 = quadgs (fun15, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkgu, xkgu)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = mppic\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 26)\n26 format (/'Problem 16: Int_-inf^inf 1/(1+t^4) dt = Pi/Sqrt(2)'/)\nx1 = -one\nx2 = one\ntm0 = second ()\nt1 = quadgs (fun16, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkgu, xkgu)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = mppic / sqrt (mpreal (2.d0, nwds1))\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 27)\n27 format (/'Problem 17: Int_-inf^inf e^(-t^2/2) dt = sqrt (2*Pi)'/)\nx1 = -one\nx2 = one\ntm0 = second ()\nt1 = quadgs (fun17, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkgu, xkgu)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = sqrt (2.d0 * mppic)\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 28)\n28 format (/'Problem 18: Int_-inf^inf e^(-t^2/2) cos(t) dt = sqrt (2*Pi/e)'/)\nx1 = -one\nx2 = one\ntm0 = second ()\nt1 = quadgs (fun18, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkgu, xkgu)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = sqrt (2.d0 * mppic / exp (mpreal (1.d0, nwds1)))\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 99) tm2\n99 format ('Total CPU time =',f12.6)\n\nstop\nend\n\nfunction fun01 (t, nwds1, nwds2)\n\n! fun01(t) = t * log(1+t)\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun01, t1, t2\ntype (mp_real) t\n\nt1 = mpreal (t, nwds1)\nfun01 = t1 * log (1.d0 + t1)\nreturn\nend\n\nfunction fun02 (t, nwds1, nwds2)\n\n! fun02(t) = t^2 * arctan(t)\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun02, t1\ntype (mp_real) t\n\nt1 = mpreal (t, nwds1)\nfun02 = t1 ** 2 * atan (t1)\nreturn\nend\n\nfunction fun03 (t, nwds1, nwds2)\n\n! fun03(t) = e^t * cos(t)\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun03, t1\ntype (mp_real) t\n\nt1 = mpreal (t, nwds1)\nfun03 = exp(t1) * cos(t1)\nreturn\nend\n\nfunction fun04 (t, nwds1, nwds2)\n\n! fun04(t) = arctan(sqrt(2+t^2))/((1+t^2)sqrt(2+t^2))\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun04, t1, t2\ntype (mp_real) t\n\nt1 = mpreal (t, nwds1)\nt2 = sqrt (2.d0 + t1**2)\nfun04 = atan(t2) / ((1.d0 + t1**2) * t2)\nreturn\nend\n\nfunction fun15 (t, nwds1, nwds2)\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) t, fun15\n\nfun15 = 1.d0 / (1.d0 + t**2)\nreturn\nend\n\nfunction fun16 (t, nwds1, nwds2)\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) t, fun16\n\nfun16 = 1.d0 / (1.d0 + t**4)\nreturn\nend\n\nfunction fun17 (t, nwds1, nwds2)\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) t, fun17\n\nfun17 = exp (-0.5d0 * t**2)\nreturn\nend\n\nfunction fun18 (t, nwds1, nwds2)\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) t, fun18\n\nfun18 = exp (-0.5d0 * t**2) * cos (t)\nreturn\nend\n\nsubroutine initqgs (nq1, nq2, nwds1, wkgs, xkgs, wkgu, xkgu)\n\n! This subroutine initializes the quadrature arrays wkgs and xkgs for standard\n! Gaussian quadrature, and also wkgu and xkgu for quadrature over the real line.\n! It employs a Newton iteration scheme with a dynamic precision level that\n! approximately doubles with each iteration. The argument nq2, which is the\n! space allocated for wkgs, xkgs, wkgu and xkgu in the calling program, should\n! be at least 6 * 2^nq1 + 100.\n\n! The wkgu and xkgu arrays are computed from wkgs and xkgs based on the\n! transformation t = tan (pi/2 * x), which transforms an integral on\n! (-infinity, infinity) to an integral on (-1, 1). In particular,\n! xkgu(i) = tan (pi/2 * xkgs(i))\n! wkgu(i) = pi/2 * wkgs(i) / cos (pi/2 * xkgs(i))^2\n\n! David H Bailey 28 Apr 2018\n\nuse mpmodule\nimplicit none\ninteger i, ierror, ik0, iprint, j, j1, k, n, ndebug, nq1, nq2, nwds1, nwp\nreal (8) dpi\nparameter (ik0 = 100, iprint = 1, ndebug = 2, dpi = 3.141592653589793238d0)\ntype (mp_real) eps, pi2, r, t1, t2, t3, t4, t5, wkgs(-1:nq2), xkgs(-1:nq2), &\n wkgu(-1:nq2), xkgu(-1:nq2), zero\n\nif (ndebug >= 1) then\n write (6, 1)\n1 format ('initqgs: Gaussian quadrature initialization')\nendif\n\npi2 = 0.5d0 * mppi (nwds1)\nzero = mpreal (0.d0, nwds1)\nwkgs(-1) = mpreal (dble (nq1), nwds1)\nxkgs(-1) = zero\nwkgs(0) = zero\nxkgs(0) = zero\nwkgs(1) = mpreal (dble (nq1), nwds1)\nxkgs(1) = mpreal (dble (ik0), nwds1)\nwkgu(-1) = mpreal (dble (nq1), nwds1)\nxkgu(-1) = zero\nwkgu(0) = zero\nxkgu(0) = zero\nwkgu(1) = mpreal (dble (nq1), nwds1)\nxkgu(1) = mpreal (dble (ik0), nwds1)\ni = ik0\n\ndo j = 2, ik0\n wkgs(j) = zero\n xkgs(j) = zero\n wkgu(j) = zero\n xkgu(j) = zero\nenddo\n\ndo k = 1, nq1\n if (ndebug >= 2 .and. mod (k, iprint) == 0) write (6, *) k, i, nq2\n n = 3 * 2 ** (k + 1)\n\n do j = 1, n / 2\n\n! Set working precision = 4 words, and compute a DP estimate of the root.\n\n nwp = 4\n eps = mpreal (2.d0 ** (48 - nwp * mpnbt), nwds1)\n r = mpreald (cos ((dpi * (j - 0.25d0)) / (n + 0.5d0)), nwp)\n\n! Compute the j-th root of the n-degree Legendre polynomial using Newton's\n! iteration.\n\n100 continue\n\n! Perform the next 11 lines with working precision nwp words.\n\n t1 = mpreal (1.d0, nwp)\n t2 = mpreal (0.d0, nwp)\n r = mpreal (r, nwp)\n\n do j1 = 1, n\n t3 = t2\n t2 = t1\n t1 = ((2 * j1 - 1) * r * t2 - (j1 - 1) * t3) / j1\n enddo\n\n t4 = n * (r * t1 - t2) / (r ** 2 - 1.d0)\n t5 = r\n r = r - t1 / t4\n \n! Once convergence is achieved at nwp = 4, then start doubling (almost) the\n! working precision level at each iteration until full precision is reached.\n\n if (nwp == 4) then\n if (abs (r - t5) > eps) goto 100\n nwp = min (2 * nwp - 1, nwds1)\n goto 100\n elseif (nwp < nwds1) then\n nwp = min (2 * nwp - 1, nwds1)\n goto 100\n endif\n\n i = i + 1\n if (i > nq2) goto 110\n xkgs(i) = r\n t4 = n * (r * t1 - t2) / (r ** 2 - 1.d0)\n wkgs(i) = 2.d0 / ((1.d0 - r ** 2) * t4 ** 2)\n xkgu(i) = tan (pi2 * r)\n wkgu(i) = pi2 * wkgs(i) / cos (pi2 * r)**2\n enddo\n\n! Save i (starting index for the next block) in the first 100 elements of \n! xkgs and xkgu.\n\n xkgs(k+1) = mpreal (dble (i), nwds1)\n xkgu(k+1) = mpreal (dble (i), nwds1)\nenddo\n\n! Save the size of the arrays in index -1 of xkgs and xkgu.\n\nxkgs(-1) = mpreal (dble (i), nwds1)\nxkgu(-1) = mpreal (dble (i), nwds1)\nif (ndebug >= 2) then\n write (6, 2) i\n2 format ('initqgs: Table spaced used =',i8)\nendif\ngoto 130\n\n110 continue\n\nwrite (6, 3) nq2\n3 format ('initqgs: Table space parameter is too small; value =',i8)\nstop\n\n130 continue\n\nreturn\nend\n\nfunction quadgs (fun, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkgs, xkgs)\n\n! This routine computes the integral of the function fun on the interval\n! (x1, x2) with a target tolerance of 10^neps1. The quadrature level is\n! progressively increased (approximately doubling the work with each level)\n! until level nq1 has been performed or the target tolerance has been met.\n! nq2 is the size of the wkgs and xkgs arrays, which must first be initialized\n! by calling initqgs. The function fun is not evaluated at the endpoints\n! x1 and x2. If quadgs outputs the message \"Increase Quadlevel\" or \"Terms\n! too large\", adjust nq1 and neps2 as necessary in the call to initqgs.\n\n! Both initqgs and quadgs are 100% THREAD SAFE -- all requisite parameters\n! and arrays are passed through subroutine arguments. \n\n! For some functions, it is important that the endpoints x1 and x2 be\n! computed to high precision (nwds2 words) in the calling program, that\n! these high-precision values be passed to quadgs (where scaled abscissas\n! are calculated to high precision), and that the function definition\n! itself uses these high-precision scaled abscissas in any initial\n! subtractions or other sensitive operations involving the input argument.\n! Otherwise the accuracy of the quadrature result might only be half as\n! high as it otherwise could be. See the function definitions of fun06,\n! fun07, fun09 and fun10 for examples on how this is done. Otherwise the\n! function evaluation can and should be performed with low precision\n! (nwds1 words) for faster run times. The two precision levels (nwds1\n! and nwds2) are specified by the user in the calling program.\n\n! David H Bailey 28 Apr 2018\n\nuse mpmodule\nimplicit none\ninteger i, ierror, ik0, iq, izx, k, j, n, ndebug, nds, nq1, nq2, &\n neps1, nerr, nwds1, nwds2, nwp\nlogical log1, log2\ndouble precision d1, d2, d3, dfrac, dplog10q\nparameter (dfrac = 100.d0, ik0 = 100, izx = 5, ndebug = 2)\ntype (mp_real) ax, bx, c10, eps1, eps2, epsilon1, err, fun, &\n quadgs, tsum, s1, s2, s3, t1, t2, tw1, tw2, twmx, wkgs(-1:nq2), xkgs(-1:nq2), &\n x1, x2, xx1, xx2\nexternal fun, dplog10q\n\n! These two lines are performed in high precision (nwds2 words).\n\nax = 0.5d0 * (x2 - x1)\nbx = 0.5d0 * (x2 + x1)\n\n! The remaining initialization is performed in low precision (nwds1 words).\n\nepsilon1 = dfrac * mpreal (10.d0, nwds1) ** neps1\ns1 = mpreal (0.d0, nwds1)\ns2 = mpreal (0.d0, nwds1)\nc10 = mpreal (10.d0, nwds1)\n\nif (wkgs(-1) < dble (nq1)) then\n write (6, 1) nq1\n1 format ('quadgs: quadrature arrays have not been initialized; nq1 =',i6)\n goto 140\nendif\n\n! Determine if the quadrature is over (-1,1) or (-inf,inf). \n\nif (dble (wkgs(101)) <= 1.d0) then\n iq = 0\nelse\n iq = 1\nendif\n\ndo k = 1, nq1\n n = 3 * 2 ** (k + 1)\n s3 = s2\n s2 = s1\n twmx = mpreal (0.d0, nwds1)\n tsum = mpreal (0.d0, nwds1)\n i = dble (xkgs(k))\n \n do j = 1, n / 2\n i = i + 1\n\n! These two lines are performed in high precision.\n\n xx1 = - ax * xkgs(i) + bx\n xx2 = ax * xkgs(i) + bx\n\n t1 = fun (xx1, nwds1, nwds2)\n tw1 = t1 * wkgs(i)\n\n if (j + k > 2) then\n t2 = fun (xx2, nwds1, nwds2)\n tw2 = t2 * wkgs(i)\n else\n t2 = mpreal (0.d0, nwds1)\n tw2 = mpreal (0.d0, nwds1)\n endif\n\n tsum = tsum + tw1 + tw2\n twmx = max (twmx, abs (tw1), abs (tw2))\n enddo\n\n! Compute s1 = current integral approximation and err = error estimate.\n! Tsum is the sum of all tw1 and tw2 from the loop above.\n! Twmx is the largest absolute value of tw1 and tw2 from the loop above.\n\n s1 = mpreal (ax, nwds1) * tsum\n eps1 = twmx * epsilon1\n d1 = dplog10q (abs ((s1 - s2) / s1))\n d2 = dplog10q (abs ((s1 - s3) / s1))\n d3 = dplog10q (eps1) - 1.d0\n\n if (k <= 2) then\n err = mpreal (1.d0, nwds1)\n elseif (d1 .eq. -999999.d0) then\n err = mpreal (0.d0, nwds1)\n else\n err = c10 ** nint (min (0.d0, max (d1 ** 2 / d2, 2.d0 * d1, d3)))\n endif\n \n! Output current integral approximation and error estimate, to 60 digits.\n\n if (ndebug >= 2) then\n write (6, 2) k, nq1, nint (dplog10q (abs (err)))\n2 format ('quadgs: Iteration',i3,' of',i3,'; est error = 10^',i7, &\n '; approx value =')\n call mpwrite (6, 80, 60, s1)\n endif\n\n if (k >= 3 .and. err < eps1) then\n write (6, 4) nint (dplog10q (abs (err)))\n4 format ('quadgs: Estimated error = 10^',i7)\n goto 140\n endif\nenddo\n\n140 continue\n\nquadgs = s1\nreturn\nend\n\nfunction dplog10q (a)\n\n! For input MP value a, this routine returns a DP approximation to log10 (a).\n\nuse mpmodule\nimplicit none\ninteger ia\nreal (8) da, dplog10q, t1\ntype (mp_real) a\n\ncall mpmdi (a, da, ia)\nif (da .eq. 0.d0) then\n dplog10q = -999999.d0\nelse\n dplog10q = log10 (abs (da)) + ia * log10 (2.d0)\nendif\n\n100 continue\nreturn\nend\n\nsubroutine decmdq (a, b, ib)\n\n! For input MP value a, this routine returns DP b and integer ib such that \n! a = b * 10^ib, with 1 <= abs (b) < 10 for nonzero a.\n\nuse mpmodule\nimplicit none\ninteger ia, ib\nreal (8) da, b, t1, xlt\nparameter (xlt = 0.3010299956639812d0)\ntype (mp_real) a\n\ncall mpmdi (a, da, ia)\nif (da .ne. 0.d0) then\n t1 = xlt * ia + log10 (abs (da))\n ib = t1\n if (t1 .lt. 0.d0) ib = ib - 1\n b = sign (10.d0 ** (t1 - ib), da)\nelse\n b = 0.d0\n ib = 0\nendif\n\nreturn\nend\n\n", "meta": {"hexsha": "370be00d08192175eb786eb88bbb06e3d1b48062", "size": 21472, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mpfun-mpfr-v10/fortran/tquadgs.f90", "max_stars_repo_name": "trcameron/FPML-Comp", "max_stars_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mpfun-mpfr-v10/fortran/tquadgs.f90", "max_issues_repo_name": "trcameron/FPML-Comp", "max_issues_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mpfun-mpfr-v10/fortran/tquadgs.f90", "max_forks_repo_name": "trcameron/FPML-Comp", "max_forks_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.9470013947, "max_line_length": 82, "alphanum_fraction": 0.6517324888, "num_tokens": 8368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896693699844, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7570632576529017}} {"text": " \n subroutine hypot_normal(x, y, h)\n double precision :: x, y, h\n\n h = SQRT(x*x + y*y)\n end subroutine\n \n subroutine hypot_safer_fabs(x, y, h)\n double precision :: x, y, h\n\n if (x > y) then\n h = ABS(x) * SQRT(1.0 +(y/x)*(y/x))\n else if(x < y) then\n h = ABS(y) * SQRT(1.0 +(x/y)*(x/y))\n else\n h = SQRT(2.0) * ABS(x)\n end if\n end subroutine\n", "meta": {"hexsha": "2c06cfe875ce85e438389bc08fc78f7a19d85afa", "size": 459, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Q1/Scientific/HW4/hypot.f", "max_stars_repo_name": "MalteWegener99/University", "max_stars_repo_head_hexsha": "b29f6e247336cb3faac9500136f5425605748c61", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Q1/Scientific/HW4/hypot.f", "max_issues_repo_name": "MalteWegener99/University", "max_issues_repo_head_hexsha": "b29f6e247336cb3faac9500136f5425605748c61", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Q1/Scientific/HW4/hypot.f", "max_forks_repo_name": "MalteWegener99/University", "max_forks_repo_head_hexsha": "b29f6e247336cb3faac9500136f5425605748c61", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-06T19:55:26.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-06T19:55:26.000Z", "avg_line_length": 24.1578947368, "max_line_length": 47, "alphanum_fraction": 0.4248366013, "num_tokens": 144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.75694039069063}} {"text": "C*******************************************************************\nC RETURN THE HISTOGRAM OF ARRAY X, THAT IS, THE NUMBER OF ELEMENTS\nC IN X FALLING INTO EACH BIN.\nC THE BIN ARRAY CONSISTS IN N BINS STARTING AT BIN0 WITH WIDTH DELTA.\nC HISTO H : | LOWER OUTLIERS | 1 | 2 | 3 | ... | N | UPPER OUTLIERS |\nC INDEX i : | 1 | 2 | 3 | 4 | ... | N+1 | N+2 |\n\n SUBROUTINE FIXED_BINSIZE(X, BIN0, DELTA, N, NX, H)\n\nC PARAMETERS\nC ----------\nC X : ARRAY \nC BIN0 : LEFT BIN EDGE\nC DELTA : BIN WIDTH\nC N : NUMBER OF BINS\nC H : HISTOGRAM\n\n IMPLICIT NONE\n INTEGER :: N, NX, i, K\n DOUBLE PRECISION :: X(NX), BIN0, DELTA\n INTEGER :: H(N+2), UP, LOW\n\nCF2PY INTEGER INTENT(IN) :: N\nCF2PY INTEGER INTENT(HIDE) :: NX = LEN(X)\nCF2PY DOUBLE PRECISION DIMENSION(NX), INTENT(IN) :: X\nCF2PY DOUBLE PRECISION INTENT(IN) :: BIN0, DELTA\nCF2PY INTEGER DIMENSION(N+2), INTENT(OUT) :: H\nCF2PY THREADSAFE\n\n\n DO i=1,N+2\n H(i) = 0\n ENDDO\n \nC OUTLIERS INDICES\n UP = N+2\n LOW = 1\n\n DO i=1,NX\n IF (X(i) >= BIN0) THEN\n K = INT((X(i)-BIN0)/DELTA)+1\n IF (K <= N) THEN\n H(K+1) = H(K+1) + 1\n ELSE \n H(UP) = H(UP) + 1\n ENDIF\n ELSE \n H(LOW) = H(LOW) + 1\n ENDIF\n ENDDO\n\n END SUBROUTINE\n\n\n\nC*******************************************************************\nC RETURN THE WEIGHTED HISTOGRAM OF ARRAY X, THAT IS, THE SUM OF THE \nC WEIGHTS OF THE ELEMENTS OF X FALLING INTO EACH BIN.\nC THE BIN ARRAY CONSISTS IN N BINS STARTING AT BIN0 WITH WIDTH DELTA.\nC HISTO H : | LOWER OUTLIERS | 1 | 2 | 3 | ... | N | UPPER OUTLIERS |\nC INDEX i : | 1 | 2 | 3 | 4 | ... | N+1 | N+2 |\n\n SUBROUTINE WEIGHTED_FIXED_BINSIZE(X, W, BIN0, DELTA, N, NX, H)\n\nC PARAMETERS\nC ----------\nC X : ARRAY \nC W : WEIGHTS\nC BIN0 : LEFT BIN EDGE\nC DELTA : BIN WIDTH\nC N : NUMBER OF BINS\nC H : HISTOGRAM\n\n IMPLICIT NONE\n INTEGER :: N, NX, i, K\n DOUBLE PRECISION :: X(NX), W(NX), BIN0, DELTA, H(N+2)\n INTEGER :: UP, LOW\n\nCF2PY INTEGER INTENT(IN) :: N\nCF2PY INTEGER INTENT(HIDE) :: NX = LEN(X)\nCF2PY DOUBLE PRECISION DIMENSION(NX), INTENT(IN) :: X, W\nCF2PY DOUBLE PRECISION INTENT(IN) :: BIN0, DELTA\nCF2PY DOUBLE PRECISION DIMENSION(N+2), INTENT(OUT) :: H\nCF2PY THREADSAFE\n\n\n DO i=1,N+2\n H(i) = 0.D0\n ENDDO\n \nC OUTLIERS INDICES\n UP = N+2\n LOW = 1\n\n DO i=1,NX\n IF (X(i) >= BIN0) THEN\n K = INT((X(i)-BIN0)/DELTA)+1\n IF (K <= N) THEN\n H(K+1) = H(K+1) + W(i)\n ELSE \n H(UP) = H(UP) + W(i)\n ENDIF\n ELSE \n H(LOW) = H(LOW) + W(i)\n ENDIF\n ENDDO\n\n END SUBROUTINE\n\n\nC*****************************************************************************\nC COMPUTE N DIMENSIONAL FLATTENED HISTOGRAM\n\n SUBROUTINE FIXED_BINSIZE_ND(X, BIN0, DELTA, N, COUNT, NX,D,NC)\n\nC PARAMETERS\nC ----------\nC X : ARRAY (NXD)\nC BIN0 : LEFT BIN EDGES (D) \nC DELTA : BIN WIDTH (D)\nC N : NUMBER OF BINS (D)\nC COUNT : FLATTENED HISTOGRAM (NC)\nC NC : PROD(N(:)+2)\n\n IMPLICIT NONE\n INTEGER :: NX, D, NC,N(D), i, j, k, T\n DOUBLE PRECISION :: X(NX,D), BIN0(D), DELTA(D)\n INTEGER :: INDEX(NX), ORDER(D), MULT, COUNT(NC)\n\n\nCF2PY DOUBLE PRECISION DIMENSION(NX,D), INTENT(IN) :: X\nCF2PY DOUBLE PRECISION DIMENSION(D) :: BIN0, DELTA\nCF2PY INTEGER INTENT(IN) :: N\nCF2PY INTEGER DIMENSION(NC), INTENT(OUT) :: COUNT\nCF2PY INTEGER INTENT(HIDE) :: NX=SHAPE(X,1)\nCF2PY INTEGER INTENT(HIDE) :: D=SHAPE(X,2)\nCF2PY THREADSAFE\n\n\nC INITIALIZE INDEX\n DO i=1, NX\n INDEX(i) = 0\n ENDDO\n\nC INITIALIZE COUNT\n DO i=1,NC\n COUNT(i) = 0\n ENDDO\n\nC ORDER THE BIN SIZE ARRAY N(D)\n CALL QSORTI(ORDER, D, N)\n\nC INITIALIZE THE DIMENSIONAL MULTIPLIER\n MULT=1\n\nC FIND THE FLATTENED INDEX OF EACH SAMPLE\n DO j=1, D\n k = ORDER(j)\n MULT=MULT*N(k)\n\n DO i=1, NX \n IF (X(i,k) >= BIN0(k)) THEN\n T = INT((X(i, k)-BIN0(k))/DELTA(k))+1\n IF (T <= N(k)) THEN\n T = T+1\n ELSE\n T = N(k)+2\n ENDIF\n ELSE\n T = 1\n ENDIF\n\n INDEX(i) = INDEX(I) + T*MULT\n ENDDO\n ENDDO\n\nC COUNT THE NUMBER OF SAMPLES FALLING INTO EACH BIN\n DO i=1,NX\n COUNT(INDEX(i)) = COUNT(INDEX(i)) + 1\n ENDDO\n\n END SUBROUTINE \n\n\nC From HDK@psuvm.psu.edu Thu Dec 8 15:27:16 MST 1994\nC \nC The following was converted from Algol recursive to Fortran iterative\nC by a colleague at Penn State (a long time ago - Fortran 66, please\nC excuse the GoTo's). The following code also corrects a bug in the\nC Quicksort algorithm published in the ACM (see Algorithm 402, CACM,\nC Sept. 1970, pp 563-567; also you younger folks who weren't born at\nC that time might find interesting the history of the Quicksort\nC algorithm beginning with the original published in CACM, July 1961,\nC pp 321-322, Algorithm 64). Note that the following algorithm sorts\nC integer data; actual data is not moved but sort is affected by sorting\nC a companion index array (see leading comments). The data type being\nC sorted can be changed by changing one line; see comments after\nC declarations and subsequent one regarding comparisons(Fortran\nC 77 takes care of character comparisons of course, so that comment\nC is merely historical from the days when we had to write character\nC compare subprograms, usually in assembler language for a specific\nC mainframe platform at that time). But the following algorithm is\nC good, still one of the best available.\n\n\n SUBROUTINE QSORTI (ORD,N,A)\nC\nC==============SORTS THE ARRAY A(I),I=1,2,...,N BY PUTTING THE\nC ASCENDING ORDER VECTOR IN ORD. THAT IS ASCENDING ORDERED A\nC IS A(ORD(I)),I=1,2,...,N; DESCENDING ORDER A IS A(ORD(N-I+1)),\nC I=1,2,...,N . THIS SORT RUNS IN TIME PROPORTIONAL TO N LOG N .\nC\nC\nC ACM QUICKSORT - ALGORITHM #402 - IMPLEMENTED IN FORTRAN 66 BY\nC WILLIAM H. VERITY, WHV@PSUVM.PSU.EDU\nC CENTER FOR ACADEMIC COMPUTING\nC THE PENNSYLVANIA STATE UNIVERSITY\nC UNIVERSITY PARK, PA. 16802\nC\n IMPLICIT INTEGER (A-Z)\nC\n DIMENSION ORD(N),POPLST(2,20)\n INTEGER X,XX,Z,ZZ,Y,N\nC\nC TO SORT DIFFERENT INPUT TYPES, CHANGE THE FOLLOWING\nC SPECIFICATION STATEMENTS; FOR EXAMPLE, FOR FORTRAN CHARACTER\nC USE THE FOLLOWING: CHARACTER *(*) A(N)\nC\n INTEGER A(N)\nC\n NDEEP=0\n U1=N\n L1=1\n DO 1 I=1,N\n 1 ORD(I)=I\n 2 IF (U1.LE.L1) RETURN\nC\n 3 L=L1\n U=U1\nC\nC PART\nC\n 4 P=L\n Q=U\nC FOR CHARACTER SORTS, THE FOLLOWING 3 STATEMENTS WOULD BECOME\nC X = ORD(P)\nC Z = ORD(Q)\nC IF (A(X) .LE. A(Z)) GO TO 2\nC\nC WHERE \"CLE\" IS A LOGICAL FUNCTION WHICH RETURNS \"TRUE\" IF THE\nC FIRST ARGUMENT IS LESS THAN OR EQUAL TO THE SECOND, BASED ON \"LEN\"\nC CHARACTERS.\nC\n X=A(ORD(P))\n Z=A(ORD(Q))\n IF (X.LE.Z) GO TO 5\n Y=X\n X=Z\n Z=Y\n YP=ORD(P)\n ORD(P)=ORD(Q)\n ORD(Q)=YP\n 5 IF (U-L.LE.1) GO TO 15\n XX=X\n IX=P\n ZZ=Z\n IZ=Q\nC\nC LEFT\nC\n 6 P=P+1\n IF (P.GE.Q) GO TO 7\n X=A(ORD(P))\n IF (X.GE.XX) GO TO 8\n GO TO 6\n 7 P=Q-1\n GO TO 13\nC\nC RIGHT\nC\n 8 Q=Q-1\n IF (Q.LE.P) GO TO 9\n Z=A(ORD(Q))\n IF (Z.LE.ZZ) GO TO 10\n GO TO 8\n 9 Q=P\n P=P-1\n Z=X\n X=A(ORD(P))\nC\nC DIST\nC\n 10 IF (X.LE.Z) GO TO 11\n Y=X\n X=Z\n Z=Y\n IP=ORD(P)\n ORD(P)=ORD(Q)\n ORD(Q)=IP\n 11 IF (X.LE.XX) GO TO 12\n XX=X\n IX=P\n 12 IF (Z.GE.ZZ) GO TO 6\n ZZ=Z\n IZ=Q\n GO TO 6\nC\nC OUT\nC\n 13 CONTINUE\n IF (.NOT.(P.NE.IX.AND.X.NE.XX)) GO TO 14\n IP=ORD(P)\n ORD(P)=ORD(IX)\n ORD(IX)=IP\n 14 CONTINUE\n IF (.NOT.(Q.NE.IZ.AND.Z.NE.ZZ)) GO TO 15\n IQ=ORD(Q)\n ORD(Q)=ORD(IZ)\n ORD(IZ)=IQ\n 15 CONTINUE\n IF (U-Q.LE.P-L) GO TO 16\n L1=L\n U1=P-1\n L=Q+1\n GO TO 17\n 16 U1=U\n L1=Q+1\n U=P-1\n 17 CONTINUE\n IF (U1.LE.L1) GO TO 18\nC\nC START RECURSIVE CALL\nC\n NDEEP=NDEEP+1\n POPLST(1,NDEEP)=U\n POPLST(2,NDEEP)=L\n GO TO 3\n 18 IF (U.GT.L) GO TO 4\nC\nC POP BACK UP IN THE RECURSION LIST\nC\n IF (NDEEP.EQ.0) GO TO 2\n U=POPLST(1,NDEEP)\n L=POPLST(2,NDEEP)\n NDEEP=NDEEP-1\n GO TO 18\nC\nC END SORT\nC END QSORT\nC\n END\n", "meta": {"hexsha": "5fdf75ad53622ac8e98fa1a64cc1f9c757295a9d", "size": 8532, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "pymc/histogram.f", "max_stars_repo_name": "CamDavidsonPilon/pymc", "max_stars_repo_head_hexsha": "26f05e60d0d414e8c3dc59d4d8fabe3ae3cfbcf9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-10-18T03:10:25.000Z", "max_stars_repo_stars_event_max_datetime": "2018-10-18T03:10:25.000Z", "max_issues_repo_path": "pymc/histogram.f", "max_issues_repo_name": "kforeman/pymc", "max_issues_repo_head_hexsha": "5783207904097c7443bfa834c0dbcc68aa38fb76", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pymc/histogram.f", "max_forks_repo_name": "kforeman/pymc", "max_forks_repo_head_hexsha": "5783207904097c7443bfa834c0dbcc68aa38fb76", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2015-05-11T06:17:00.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-17T23:22:46.000Z", "avg_line_length": 24.2386363636, "max_line_length": 78, "alphanum_fraction": 0.5492264416, "num_tokens": 2975, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866547, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7569184713988503}} {"text": "MODULE fifthpanel\r\n\r\n USE precise, ONLY : defaultp\r\n\r\n!! variable declarations\r\n\r\n IMPLICIT NONE ! makes sure the compiler complains about \r\n ! undeclared variables\r\n INTEGER, PARAMETER, PRIVATE :: WP=defaultp\r\n\r\nCONTAINS\r\n\r\n FUNCTION cross_product( a, b ) RESULT (c)\r\n !\r\n ! Function to compute the cross product of two 3D vectors a and b.\r\n ! It will return a 3D vector.\r\n ! Usage: c = cross_product(a,b)\r\n !\r\n REAL(wp), DIMENSION(3) :: a, b, c\r\n\r\n c(1) = a(2)*b(3) - a(3)*b(2)\r\n c(2) = a(3)*b(1) - a(1)*b(3)\r\n c(3) = a(1)*b(2) - a(2)*b(1)\r\n\r\n END FUNCTION cross_product\r\n\r\n\r\n SUBROUTINE panelgeometry(corners, coordsys, cornerslocal, area, center )\r\n !!\r\n !! procedure to compute the geometric properties of a\r\n !! quadrilateral panel. The actual quadrilateral is replaced by\r\n !! a flat panel.\r\n !! Input are the four corner points (3D). The points must form\r\n !! an anti-clockwise sequence if viewed from inside the hull. \r\n !! The normal vector will then point inside the hull.\r\n !!\r\n !! Output:\r\n !! coordsys: a 3x3 matrix containing the two tangent vectors\r\n !! and the normal vector\r\n !! t1x t2x nx\r\n !! t1y t2y ny\r\n !! t1z t2z nz\r\n !! i.e. coordsys(:,3) is the normal vector\r\n !! cornerlocal: 2D - coordinates of the panel corners with\r\n !! respect to the panel center\r\n !! area: the area of the panel\r\n !! center: the 3D coordinates of the panel center\r\n !!\r\n INTEGER :: i\r\n\r\n INTEGER, DIMENSION(4), PARAMETER :: ip1 = (/ 2, 3, 4, 1 /)\r\n\r\n REAL(wp) :: area, dxi, deta\r\n REAL(wp) :: momentxi, momenteta, xic, etac\r\n\r\n REAL(wp), DIMENSION(3,4) :: corners ! input, coordinates of \r\n ! the four corner points\r\n REAL(wp), DIMENSION(3) :: m1, m2, m3, m4 ! midpoints\r\n REAL(wp), DIMENSION(3) :: iv, jv, jvbar, nv ! temporary vectors\r\n REAL(wp), DIMENSION(3) :: center ! center of panel\r\n REAL(wp), DIMENSION(3,3) :: coordsys ! local coordinate system\r\n REAL(wp), DIMENSION(2,4) :: cornerslocal ! local coordinate system\r\n\r\n ! first we compute the midpoints of all four panel edges. The points\r\n ! m1 through m4 are situated on a plane even if the corners are not.\r\n m1(:) = 0.5*(corners(:,1)+corners(:,2))\r\n m2(:) = 0.5*(corners(:,2)+corners(:,3))\r\n m3(:) = 0.5*(corners(:,3)+corners(:,4))\r\n m4(:) = 0.5*(corners(:,4)+corners(:,1))\r\n\r\n ! second we compute a coordinate system local to the panel\r\n iv = m2-m4 ! first local coordinate vector\r\n iv = iv / SQRT(SUM(iv**2)) ! normalize to unit length\r\n\r\n jvbar = m3-m1 ! second temp. local coordinate vector\r\n\r\n ! Normal vector\r\n nv = cross_product( iv, jvbar )\r\n nv = nv / SQRT(SUM(nv**2)) ! normalize to unit length\r\n \r\n ! find second tangent vector which is perpendicular to nv and iv\r\n jv = cross_product( nv, iv )\r\n\r\n ! store the local coordinate system vectors in the matrix coordsys\r\n coordsys(:,1) = iv\r\n coordsys(:,2) = jv\r\n coordsys(:,3) = nv\r\n \r\n ! temporary origin\r\n center = 0.25*(m1+m2+m3+m4)\r\n\r\n ! corners in local (plane) coordinate system\r\n DO i = 1, 4\r\n ! xi component\r\n cornerslocal(1,i) = DOT_PRODUCT( (corners(:,i)-center), iv) \r\n ! eta component\r\n cornerslocal(2,i) = DOT_PRODUCT( (corners(:,i)-center), jv) \r\n END DO \r\n \r\n ! area and moment of panel. The equations are derived by means\r\n ! of the Stokes theorem.\r\n area = 0.\r\n momentxi = 0. ! the moments are with respect to the panel tangent \r\n ! vectors\r\n momenteta = 0.\r\n DO i = 1, 4\r\n dxi = cornerslocal(1,ip1(i))-cornerslocal(1,i) ! difference in xi\r\n deta = cornerslocal(2,ip1(i))-cornerslocal(2,i)! difference in eta\r\n \r\n area = area + deta*(cornerslocal(1,ip1(i))+cornerslocal(1,i))\r\n\r\n momentxi = momentxi + dxi * ( &\r\n cornerslocal(2,ip1(i))**2 &\r\n + cornerslocal(2,i)*cornerslocal(2,ip1(i)) &\r\n + cornerslocal(2,i)**2 &\r\n )\r\n momenteta = momenteta + deta * ( &\r\n cornerslocal(1,ip1(i))**2 &\r\n + cornerslocal(1,i)*cornerslocal(1,ip1(i)) &\r\n + cornerslocal(1,i)**2 &\r\n )\r\n END DO \r\n\r\n area = 0.5*area\r\n momentxi = -1./6.*momentxi\r\n momenteta = 1./6.*momenteta\r\n\r\n ! centroid\r\n IF (area > 0.0000000001) THEN\r\n ! We make sure that the panel is not degenerated with zero area\r\n xic = momenteta / area\r\n etac = momentxi / area\r\n ELSE\r\n xic = 0.\r\n etac = 0.\r\n ENDIF\r\n\r\n ! Correct the local coordinates of the corners to be measured from\r\n ! the true panel centroid.\r\n DO i = 1, 4\r\n cornerslocal(1,i) = cornerslocal(1,i) - xic\r\n cornerslocal(2,i) = cornerslocal(2,i) - etac\r\n END DO \r\n\r\n ! Finally move the centroid to its exact position\r\n center = center + xic*iv + etac*jv\r\n\r\n END SUBROUTINE panelgeometry\r\n\r\nEND MODULE fifthpanel\r\n", "meta": {"hexsha": "9955ce6059031675eab09173026b54536b1a3bdb", "size": 5162, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fifthpanel.f90", "max_stars_repo_name": "LukeMcCulloch/3DDoubleBodyFlows", "max_stars_repo_head_hexsha": "73fa94bf1df894a947aa39f80af206bebcbaddc3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/fifthpanel.f90", "max_issues_repo_name": "LukeMcCulloch/3DDoubleBodyFlows", "max_issues_repo_head_hexsha": "73fa94bf1df894a947aa39f80af206bebcbaddc3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/fifthpanel.f90", "max_forks_repo_name": "LukeMcCulloch/3DDoubleBodyFlows", "max_forks_repo_head_hexsha": "73fa94bf1df894a947aa39f80af206bebcbaddc3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.1854304636, "max_line_length": 75, "alphanum_fraction": 0.5633475397, "num_tokens": 1512, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554476, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7568690217808219}} {"text": "subroutine qinit(meqn,mbc,mx,xlower,dx,q,maux,aux)\n\n ! Set initial conditions for the q array.\n\n use geoclaw_module, only: sea_level\n use grid_module, only: xcell\n\n ! uncomment if any of these needed...\n !use geoclaw_module, only: dry_tolerance, grav\n\n implicit none\n\n integer, intent(in) :: meqn,mbc,mx,maux\n real(kind=8), intent(in) :: xlower,dx\n real(kind=8), intent(in) :: aux(maux,1-mbc:mx+mbc)\n real(kind=8), intent(inout) :: q(meqn,1-mbc:mx+mbc)\n\n !locals\n integer :: i\n\n real(kind=8) :: h0, eta, eta_star, x0, ampl, u, u_star, c, kappa, a\n\n x0 = -9.14d0 ! initial location of wave\n a = 0.259d0 ! dimensionless amplitude\n h0 = 0.218d0 ! depth for scaling\n ampl = a*h0 ! amplitude\n\n kappa = sqrt(3.d0*a / (4.d0*(a+1.d0)))\n c = sqrt(1.d0 + a)\n\n do i=1,mx\n eta = ampl / cosh(kappa*(xcell(i) - x0)/h0)**2\n eta_star = eta/h0\n u_star = c * eta_star/(1.d0 + eta_star)\n u = u_star * sqrt(9.81d0*h0)\n q(1,i) = max(sea_level, eta - aux(1,i))\n q(2,i) = q(1,i)*u\n\n enddo\n\n\nend subroutine qinit\n", "meta": {"hexsha": "5b16dded2ace3a783f4d391248ff08400118a1b3", "size": 1098, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/bouss_wavetank_usace/qinit.f90", "max_stars_repo_name": "clawpack/geoclaw_1d", "max_stars_repo_head_hexsha": "2272459a81f253720feaa3561094764433e7115a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/bouss_wavetank_usace/qinit.f90", "max_issues_repo_name": "clawpack/geoclaw_1d", "max_issues_repo_head_hexsha": "2272459a81f253720feaa3561094764433e7115a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-01-22T19:35:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-22T17:32:43.000Z", "max_forks_repo_path": "examples/bouss_wavetank_usace/qinit.f90", "max_forks_repo_name": "clawpack/geoclaw_1d", "max_forks_repo_head_hexsha": "2272459a81f253720feaa3561094764433e7115a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-04T04:39:16.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-04T04:39:16.000Z", "avg_line_length": 25.5348837209, "max_line_length": 71, "alphanum_fraction": 0.5883424408, "num_tokens": 407, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554476, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.756869011361572}} {"text": "!CALL polysvd(kpp,strial,ptrial,SIZE(strial),cfnt(1:kpp))\n SUBROUTINE polysvd(nfitin,x,y,m,b)\n! USAGE SVD regression of input vectors x, y of length m\n! producess nfitin polynoimial coefficients b\n USE stel_kinds\n USE stel_constants\n IMPLICIT NONE\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n INTEGER, INTENT(in) :: m, nfitin\n REAL (rprec), DIMENSION(m), INTENT(in) :: x,y\n REAL(rprec) ,DIMENSION(nfitin), INTENT(out) :: b\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n REAL (rprec) :: cutoff=1.e-7_dp\n REAL (rprec), DIMENSION(:,:), ALLOCATABLE\n 1 :: amatrix, vv ,uu, wwd\n REAL (rprec), DIMENSION(:) , ALLOCATABLE :: ww\n REAL (rprec), DIMENSION(:), ALLOCATABLE, SAVE :: apar\n INTEGER , DIMENSION(:) , ALLOCATABLE :: pwr\n INTEGER :: i, j, n=11\n n=nfitin\n ALLOCATE(amatrix(m,n))\n ALLOCATE(uu(m,n))\n ALLOCATE(pwr(n))\n ALLOCATE(apar(n))\n ALLOCATE(wwd(n,n))\n ALLOCATE(ww(n))\n ALLOCATE(vv(n,n))\n DO i=1,n\n pwr(i)=i-1\n ENDDO\n! make amatrix\n DO i=1,m\n DO j=1,n\n IF(x(i).eq.0.) THEN\n amatrix(i,j)=zero\n ELSE\n amatrix(i,j)=x(i)**pwr(j)\n ENDIF\n ENDDO \n ENDDO\n uu=amatrix\n CALL svdcmp(uu,m,n,m,n,ww,vv) ! m rows > n columns\n DO i=1,n\n DO j=1,n\n wwd(i,j)=0 ! reset after matmul\n ENDDO \n ENDDO \n DO i=1,n\n wwd(i,i)=1/ww(i)\n ENDDO\n DO i= 1,SIZE(ww)\n IF(ww(i) .lt. cutoff) wwd(i,i)=0\n ENDDO\n apar=0.\n apar=matmul(vv,matmul(wwd,matmul(TRANSPOSE(uu),y)))\n b(1:n)=apar(1:n)\n DEALLOCATE(amatrix)\n DEALLOCATE(uu)\n DEALLOCATE(pwr)\n DEALLOCATE(apar)\n DEALLOCATE(wwd)\n DEALLOCATE(ww)\n DEALLOCATE(vv)\n END SUBROUTINE polysvd\n\n! PROGRAM driver\n! TESTED against IDL with this PARAMETER set. Results agree.\n! USE stel_kinds\n! USE stel_constants\n! INTEGER, PARAMETER :: ns=50, kpp=5\n! REAL(rprec), DIMENSION(ns) :: s, y\n! REAL(rprec), DIMENSION(kpp) :: b\n! DO i=1,ns \n! s(i)=one*(i-1)/(ns-1)\n! ENDDO\n! y=COS(s*pio2)**2\n! CALL polysvd(kpp,s,y,SIZE(s),b)\n! WRITE(6,109)b\n! WRITE(6,109)s\n! WRITE (6,109)y\n!109 FORMAT(/,' =[',3(x,1pe14.6,1h,),'$')\n! END PROGRAM\n\n\n", "meta": {"hexsha": "5fa20b98bf3e815d9befa9d718c3ee4b81a146a5", "size": 2553, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Sources/SVDpack/polysvd.f", "max_stars_repo_name": "ORNL-Fusion/libstell", "max_stars_repo_head_hexsha": "92ac5c339b31e29d9d734c20eae3e7571de8f490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-19T06:24:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-08T21:10:12.000Z", "max_issues_repo_path": "Sources/SVDpack/polysvd.f", "max_issues_repo_name": "ORNL-Fusion/libstell", "max_issues_repo_head_hexsha": "92ac5c339b31e29d9d734c20eae3e7571de8f490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-09-21T14:00:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-03T00:48:39.000Z", "max_forks_repo_path": "Sources/SVDpack/polysvd.f", "max_forks_repo_name": "ORNL-Fusion/LIBSTELL", "max_forks_repo_head_hexsha": "ba938c678d776b84d7bb260ea541a9b45deb37e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.6853932584, "max_line_length": 60, "alphanum_fraction": 0.4915785351, "num_tokens": 865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129327, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7568690106847409}} {"text": "! if you load the wrong library type LP vs. ILP it will say invalid parameter 8\n! https://software.intel.com/en-us/mkl-developer-reference-fortran-gemm\n\nprogram intel_gemm\n\nuse blas95, only: gemm\nuse,intrinsic :: iso_fortran_env, only: dp=>real64\n\nIMPLICIT NONE (type, external)\n\nreal(dp) ALPHA, BETA\nINTEGER M, K, N, I, J\nPARAMETER (M=2000, K=200, N=1000)\nreal(dp) A(M,K), B(K,N), C(M,N)\n\nPRINT *, \"Initializing data for matrix multiplication C=A*B for \"\nPRINT '(a,I5,a,I5,a,I5,a,I5,a,/)', \" matrix A(\",M,\" x\",K, \") and matrix B(\", K,\" x\", N, \")\"\n\nALPHA = 1\nBETA = 0\n\nPRINT '(A,/)', \"Intializing matrix data\"\n\nforall (I = 1:M, J = 1:K) A(I,J) = (I-1) * K + J\n\nforall (I = 1:K, J = 1:N) B(I,J) = -((I-1) * N + J)\n\nC(:,:) = 0\n\nPRINT *, \"Computing matrix product using Intel(R) MKL GEMM subroutine\"\nCALL GEMM(A,B,C)\nPRINT '(A,/)', \"Computations completed.\"\n\nPRINT *, \"Top left corner of matrix A:\"\nPRINT '(6(F12.0,1x),/)', ((A(I,J), J = 1,MIN(K,6)), I = 1,MIN(M,6))\n\nPRINT *, \"Top left corner of matrix B:\"\nPRINT '(6(F12.0,1x),/)', ((B(I,J),J = 1,MIN(N,6)), I = 1,MIN(K,6))\n\nPRINT *, \"Top left corner of matrix C:\"\nPRINT '(6(ES12.4,1x),/)', ((C(I,J), J = 1,MIN(N,6)), I = 1,MIN(M,6))\n\nEND program\n", "meta": {"hexsha": "614a8131792ed988eac2301775eaed054cbe717e", "size": 1213, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "matmul/intel_gemm.f90", "max_stars_repo_name": "scienceopen/numba-examples", "max_stars_repo_head_hexsha": "1331ac4ef4a723d3d8353cd3ce90c9bf127fe547", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2017-03-10T07:41:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-17T16:35:46.000Z", "max_issues_repo_path": "matmul/intel_gemm.f90", "max_issues_repo_name": "scienceopen/numba-examples", "max_issues_repo_head_hexsha": "1331ac4ef4a723d3d8353cd3ce90c9bf127fe547", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-03-22T22:04:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-22T22:04:51.000Z", "max_forks_repo_path": "matmul/intel_gemm.f90", "max_forks_repo_name": "scienceopen/numba-examples", "max_forks_repo_head_hexsha": "1331ac4ef4a723d3d8353cd3ce90c9bf127fe547", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-10-16T04:37:17.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-08T12:35:54.000Z", "avg_line_length": 27.5681818182, "max_line_length": 91, "alphanum_fraction": 0.5943940643, "num_tokens": 464, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.756793667724354}} {"text": " real function SRANR(ALPHA)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1994-10-20 SRANR Krogh Changes to use M77CON\nc>> 1994-06-24 SRANR CLL Changed common to use RANC[D/S]1 & RANC[D/S]2.\nc>> 1992-03-16 CLL\nc>> 1991-11-26 CLL Reorganized common. Using RANCM[A/D/S].\nc>> 1991-11-22 CLL Added call to RAN0, and SGFLAG in common.\nc>> 1991-01-15 CLL Reordered common contents for efficiency.\nC>> 1990-01-23 CLL Making names in common same in all subprogams.\nC>> 1987-04-22 SRANR Lawson Initial code.\nc Returns one pseudorandom number from the Rayleigh distribution\nc with parameter, ALPHA, which should be positive.\nc If U is random, uniform on [0, 1], the Rayleigh variable is given\nc by SRANR = ALPHA * sqrt(-2.0 * log(U))\nc This variable has mean = ALPHA * sqrt(Pi/2)\nc and variance = (2 - Pi/2) * ALPHA**2\nc Code based on subprogram written for JPL by Stephen L. Ritchie,\nc Heliodyne Corp. and Wiley R. Bunton, JPL, 1969.\nc Adapted to Fortran 77 for the JPL MATH77 library by C. L. Lawson &\nc S. Y. Chiu, JPL, Apr 1987.\nc ------------------------------------------------------------------\nc--S replaces \"?\": ?RANR, ?RANUA, RANC?1, RANC?2, ?PTR, ?NUMS, ?GFLAG\nC RANCS1 and RANCS2 are common blocks.\nc Calls RAN0 to initialize SPTR and SGFLAG.\nc ------------------------------------------------------------------\n integer M\n parameter(M = 97)\n real SNUMS(M), ALPHA, MTWO\n parameter(MTWO = -2.0E0)\n common/RANCS2/SNUMS\n integer SPTR\n logical SGFLAG\n common/RANCS1/SPTR, SGFLAG\n save /RANCS1/, /RANCS2/, FIRST\n logical FIRST\n data FIRST / .true. /\nc ------------------------------------------------------------------\n if(FIRST) then\n FIRST = .false.\n call RAN0\n endif\nc\n SPTR = SPTR - 1\n if(SPTR .eq. 0) then\n call SRANUA(SNUMS, M)\n SPTR = M\n endif\n SRANR = ALPHA * sqrt(MTWO * log(SNUMS(SPTR)))\n return\n end\n", "meta": {"hexsha": "0dddb1f30142e7e14dffab2901fe5c28d4beffd3", "size": 2181, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/sranr.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/sranr.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/sranr.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 41.1509433962, "max_line_length": 72, "alphanum_fraction": 0.563044475, "num_tokens": 661, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391558356, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7567936506257827}} {"text": " \nC$Procedure PARTOF ( Parabolic time of flight )\n \n SUBROUTINE PARTOF ( MA, D )\n \nC$ Abstract\nC\nC Solve the time of flight equation MA = D + (D**3) / 3\nC for the parabolic eccentric anomaly D, given mean anomaly.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC CONIC\nC\nC$ Declarations\n \n DOUBLE PRECISION MA\n DOUBLE PRECISION D\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC MA I Mean anomaly at epoch.\nC D O Parabolic eccentric anomaly.\nC\nC$ Detailed_Input\nC\nC MA is the parabolic mean anomaly of an orbiting body at\nC some epoch t,\nC\nC 3 1/2\nC MA = (t-T) (mu/(2q ))\nC\nC where T is the time of periapsis passage, mu is\nC the gravitational parameter of the primary body,\nC and q is the perifocal distance.\nC\nC$ Detailed_Output\nC\nC D is the corresponding parabolic anomaly. This is the\nC solution to the time of flight equation\nC\nC 3\nC MA = D + D / 3\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC None.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC Iterate to solve\nC\nC 3\nC f(D,MA,p) = D + D / 3 - MA = 0\nC\nC$ Examples\nC\nC ELLTOF, HYPTOF, and PARTOF are used by CONICS.\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC [1] Roger Bate, Fundamentals of Astrodynamics, Dover, 1971.\nC\nC$ Author_and_Institution\nC\nC I.M. Underwood (JPL)\nC W.L. Taber (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 2.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 2.0.0, 19-APR-1991 (WLT)\nC\nC A write statement left over from debugging days was removed.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (IMU)\nC\nC-&\n \nC$ Index_Entries\nC\nC parabolic time of flight\nC\nC-&\n \n \n \n \nC$ Revisions\nC\nC- SPICELIB Version 2.0.0, 19-APR-1991 (WLT)\nC\nC A write statement left over from debugging days was removed.\nC\nC- Beta Version 1.0.1, 27-JAN-1989 (IMU)\nC\nC Examples section completed.\nC\nC-&\n \n \n \nC\nC SPICELIB functions\nC\n LOGICAL RETURN\n DOUBLE PRECISION DCBRT\n \nC\nC Local parameters\nC\n DOUBLE PRECISION TOL\n PARAMETER ( TOL = 1.D-13 )\n \nC\nC Local variables\nC\n DOUBLE PRECISION M\n DOUBLE PRECISION FN\n DOUBLE PRECISION DERIV\n DOUBLE PRECISION DERIV2\n DOUBLE PRECISION CHANGE\n \n \n \n \nC\nC Standard SPICE error handling.\nC\n IF ( RETURN () ) THEN\n RETURN\n ELSE\n CALL CHKIN ( 'PARTOF' )\n END IF\n \n \n \nC\nC If the mean anomaly is zero, the eccentric anomaly is also zero\nC (by inspection). If the mean anomaly is negative, we can pretend\nC that it's positive (by symmetry).\nC\n \n IF ( MA .EQ. 0.D0 ) THEN\n D = 0.D0\n CALL CHKOUT ( 'PARTOF' )\n RETURN\n ELSE\n M = ABS ( MA )\n END IF\n \n \nC\nC We need an initial guess for the eccentric anomaly D. The function\nC is well behaved, so just about any guess will do.\nC\n D = DCBRT ( 3.D0 * M )\n \n \nC\nC Use the Newton second-order method,\nC\nC 2\nC F = F - (f/f')*(1 + f*f''/2f' )\nC i+1 i\nC\nC where\nC\nC 3\nC f = D + D / 3 - M\nC\nC 2\nC f' = 1 + D\nC\nC\nC f'' = 2 D\nC\n \n CHANGE = 1.D0\n \n DO WHILE ( ABS ( CHANGE ) .GT. TOL )\n \n FN = D + D**3/3.D0 - M\n DERIV = 1.D0 + D**2\n DERIV2 = 2.D0 * D\n \n CHANGE = (FN/DERIV) * ( 1.D0 + (FN*DERIV2) / (2.D0*DERIV**2) )\n D = D - CHANGE\n \n END DO\n \n IF ( MA .LT. 0.D0 ) THEN\n D = -D\n END IF\n \n \n CALL CHKOUT ( 'PARTOF' )\n RETURN\n END\n", "meta": {"hexsha": "e954cc47153cfdea9b8870a50f225af7f6d3a691", "size": 5470, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/partof.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/partof.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/partof.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 22.1457489879, "max_line_length": 72, "alphanum_fraction": 0.5756855576, "num_tokens": 1660, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9511422241476942, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.7567840172595527}} {"text": "module rabs_functions_math\n!\n!***** February 2012, wide *****\n!-----------------------------------------------------------------------------------------------------------------------\n! This module contains a number of mathematical and related functions as they appear frequently in the computation of \n! atomic properties and structures.\n!-----------------------------------------------------------------------------------------------------------------------\n !\n use rabs_constant\n use rabs_naglib\n implicit none\n private\n !\n private :: arctan_0_2pi \n ! Returns the tan^(-1) (x/y) in the range 0 ... 2*pi.\n public :: beta_func \n ! Returns B(a,b) for integer and half-arguments.\n public :: calculate_determinant \n ! Calculates the determinant of a given quadratic matrix.\n public :: complete_contraction4 \n ! Calculates the complete contraction of a 4-dimensional with four vectors.\n public :: coul_cern_kabachnik\n ! Calculates the non-relativistic coulomb function for a free electron with given energy and orbital \n ! momentum.\n public :: distance\n ! Calculates the distance between two (3-dim) points, given either in \"cartesian\" or \"spherical\" \n ! coordinates. \n public :: double_factorial \n ! Returns the value n!! for given integer n.\n public :: factorial \n ! Returns the value n! for given integer n.\n public :: factorial_dp \n ! Returns the approximate value n! for given integer n as real(kind=dp).\n public :: gamma_complex \n ! Returns Gamma(arg) for complex arguments.\n public :: gamma_func \n ! Returns Gamma(n) for integer arguments.\n public :: Gammax_over_ax \n ! Calculates Gamma(x)/(a^x)\n public :: get_maximum_minimum\n ! Returns the value and location of a local maximum or minimum by interpolation\n public :: hypergeometric_2F1 \n ! Calculates Gauss' hypergeometric function 2F_1 = F(a,b,c;x) for real x.\n public :: hypergeometric_2F1_complex_b \n ! Calculates Gauss' hypergeometric function 2F_1 = F(a,b,c;x) for complex a, b, c and x.\n public :: hypergeometric_2F1_complex_g \n ! Calculates Gauss' hypergeometric function 2F_1 = F(a,b,c;x) for complex a, b, c and x.\n public :: hypergeometric_Phi \n ! Calculates the degenerate hypergeometric function 1F_1 = Phi(a,b;x) for real x.\n public :: incomplete_beta_func \n ! Returns the incomplete Beta(a,b,x) function.\n public :: integral_one_dim \n ! Calculates a simple estimate of an 1-dim integral in a given interval.\n public :: interpolation_aitken\n ! Interpolates a value by using Aitken's algorithm. \n public :: interpolation_lagrange\n ! Interpolates a value by using Lagrange's algorithm. \n public :: is_triangle\n ! Returns .true. if three integers fulfill the triangular condition and .false. otherwise. \n public :: legendre_associated\n ! Returns the (complex) value of the associated Legendre function P_n^m (z) for complex argument. \n public :: legendre_polynomial\n ! Returns the (complex) value of the Legendre polynomial P_n (z) for complex argument. \n public :: LU_decomposition_of_matrix \n ! Carries out a LU decomposition of a given matrix.\n public :: pochhammer \n ! Calculates the value of a pochhammer symbol\n public :: set_beta_gamma_arrays \n ! Initializes array for beta_func(), gamma_func(), and incomplete_beta_func().\n public :: set_gauss_zeros \n ! Returns the zeros and weights for a Gauss-Legendre integration.\n private :: set_gauss_zeros_aux \n ! Auxiliarity routine for set_gauss_zeros().\n public :: spherical_Bessel_jL \n ! Returns the value of the spherical Bessel function j_L(x) for real values of x.\n public :: spherical_Legendre_Pmn \n ! Returns the value of the spherical (associated) Legendre function P^m_n(x) for real x.\n public :: transform_cart_to_cylinder \n ! Transforms cartesian coordinates (x,y,z) into (rho,phi,z).\n public :: transform_cart_to_spherical \n ! Transforms cartesian coordinates (x,y,z) into (r,theta,phi).\n public :: transform_cylinder_to_cart \n ! Transforms cylindrical coordinates (rho,phi,z) into (x,y,z).\n public :: transform_spherical_to_cart \n ! Transforms spherical coordinates (r,theta,phi) into (x,y,z).\n public :: Whittaker_M \n ! Returns the value of the Whittaker function M_a,b(x) for real values of x.\n public :: Whittaker_W \n ! Returns the value of the Whittaker function W_a,b(x) for real values of x.\n !\n !\n integer, parameter, private :: ndbeta = 32, ndmx = 19\n real(kind=dp), pointer, dimension(:), private :: gamma_store\n real(kind=dp), pointer, dimension(:,:), private :: beta_store\n real(kind=dp), pointer, dimension(:,:,:), private :: beta_frac_coeff\n !\n integer, dimension(0:19), private, parameter :: dfak = &\n (/ 1, 1, 2, 3, &\n 8, 15, 48, 105, &\n 384, 945, 3840, 10395, &\n 46080, 135135, 645120, 2027025, &\n 10321920, 34459425, 185794560, 654729075 /)\n ! 3715891200, 13749310575, 81749606400, 316234143225 /)\n !\n integer, private :: ifail\n !\n !\ncontains\n !\n !\n function arctan_0_2pi(arg1,arg2) result(value)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns \n ! -1 \n ! value = tan (arg1/arg2), 0 <= value < 2*pi.\n !--------------------------------------------------------------------------------------------------------------------\n !\n real(kind=dp), intent(in) :: arg1, arg2\n real(kind=dp) :: value\n !\n logical, save :: first = .true., intrin = .true.\n !\n ! Determine whether the FORTRAN intrinsic function ATAN2 always\n ! returns a positive value\n if (first) then\n value = atan2(-one,-one)\n if (value > zero) then\n intrin = .true.\n else\n intrin = .false.\n end if\n first = .false.\n end if\n !\n ! Use the intrinsic function if it passes the above test; otherwise add 2*pi to the negative values returned by \n ! the intrinsic function\n if (intrin) then\n value = atan2(arg1,arg2)\n else\n if (arg1 >= zero) then\n value = atan2(arg1,arg2)\n else\n value = pi + pi + atan2(arg1,arg2)\n end if\n end if\n !\n end function arctan_0_2pi\n !\n !\n function beta_func(a2,b2) result(beta)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the value of the Beta(a,b) = Beta(a2/2,b2/2) function for integer and half-integer arguments using the array \n ! beta_store(:,:) which needs to be initialized before.\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: a2, b2\n real(kind=dp) :: beta\n !\n if (rabs_use_stop .and. &\n (a2 > ndbeta .or. b2 > ndbeta)) then\n stop \"beta_func(): program stop A.\"\n end if\n !\n beta = beta_store(a2,b2)\n !\n end function beta_func\n !\n !\n subroutine calculate_determinant(matrix,determinant,n)\n !--------------------------------------------------------------------------------------------------------------------\n ! Calculates the determinant of the n x n matrix; ndim is the dimension in the declaration of matrix.\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: n\n real(kind=dp), intent(out) :: determinant\n real(kind=dp), dimension(:,:), intent(inout) :: matrix\n !\n integer :: j, p\n real(kind=dp) :: d, wa\n !! integer :: ier\n !! real(kind=dp) :: d1, d2, wa\n !! real(kind=dp), dimension(n) :: worka, workb \n !\n ! Return zero if one 'raw' is identically zero\n determinant = zero\n do j = 1,n\n wa = zero\n\tdo p = 1,n\n\t wa = max(wa, abs(matrix(j,p)))\n\tend do\n\tif (wa < eps20) return\n end do\n !\n call LU_decomposition_of_matrix(matrix,n,d)\n determinant = d\n do j = 1,n\n determinant = determinant * matrix(j,j)\n end do\n !\n ! LU-decomposition\n !\n ! The following three lines show how to use the subroutine LUDATN from\n ! the IMSL Library (IMSL Inc, 1984, 7500 Bellaire Boulevard, Houston \n ! TX 77036, USA). This invokation has to be replaced if some other\n ! routine of numerical library is used.\n ! The only relevant OUTPUT parameter from this routine, however, is\n ! determinant = the value of the determinant det(DWD).\n !\n !! d1 = one; ier = 0\n !! call ludatn(matrix,ndim,n,matrix,ndim,0,d1,d2,worka,workb,wa,ier)\n !! determinant = d1 * two ** d2\n !! if (abs(determinant) > eps10) print *, \"determinant = \",determinant\n !\n ! NAG library function f03aaf\n !\n !! call f03aaf(matrix,ndim,5,determinant,work,ifail)\n !! if (ifail /= 0) then\n !! print *, \"calculate_determinant(), f03aaf: ifail = \",ifail\n !! end if\n !! print *, \"determinant, ifail = \",determinant, ifail\n !\n ! NAG library function f03aff\n !\n !! eps = eps10\n !! call f03aff(n,eps,matrix,ndim,d1,id2,work,ifail)\n !! if (ifail /= 0) then\n !! print *, \"calculate_determinant(): ifail = \",ifail\n !! end if\n !! deter = d1 * two ** id2\n !\n end subroutine calculate_determinant\n !\n !\n function complete_contraction4(wa,va,vc,vb,vd,na,nc,nb,nd) result(value)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the value of a complete contraction of the 4-dimensional array wa with the vectors va, vc, vb, vd in this \n ! sequence of indices.\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: na, nc, nb, nd\n real(kind=dp), dimension(1:na), intent(in) :: va\n real(kind=dp), dimension(1:nb), intent(in) :: vb\n real(kind=dp), dimension(1:nc), intent(in) :: vc\n real(kind=dp), dimension(1:nd), intent(in) :: vd\n real(kind=dp), dimension(1:na,1:nc,1:nb,1:nd), intent(in) :: wa\n real(kind=dp) :: value\n !\n integer :: a, b, c, d\n !\n value = zero\n do d = 1,nd\n do b = 1,nb\n do c = 1,nc\n do a = 1,na\n !x print *, \"complete_c: a,c,b,d,value = \",a,c,b,d,value\n value = value + wa(a,c,b,d)*va(a)*vc(c)*vb(b)*vd(d)\n end do\n end do\n end do\n end do\n !\n end function complete_contraction4\n !\n !\n subroutine coul_cern_kabachnik(rho,eta,minl,maxl,fc,fcp,gc,gcp,accur,step)\n !--------------------------------------------------------------------------------------------------------------------\n ! Coulomb wavefunctions calculated at r = rho by the continued-fraction method of steed. minl,maxl are actual \n ! l-values. See Barnett et al Comp. Phys. Commun. v.8 p.377 (1974).\n !--------------------------------------------------------------------------------------------------------------------\n !\n real(kind=dp) :: K,K1,K2,K3,K4,M1,M2,M3,M4\n real(kind=dp), dimension(:) :: FC,FCP,GC,GCP\n !\n integer :: minl, maxl, ktr, lmax, lmin1, ktrp, l, lp, i2\n real(kind=dp) :: rho, eta, accur, step, pace, acc, r, xll1, eta2, turn, tf, f, tfp, fp, etar, rho2, pl, pmx, dk, &\n del, d, h, p, q, ar, ai, br, bi, wi, dr, di, dq, t, g, gp, w, r3, h2, dp_x, etah, h2ll, s, rh2, rh\n !\n !\n PACE = STEP\n ACC = ACCUR\n IF(PACE.LT.100.0) PACE = 100.0\n IF(ACC.LT.1.0E-15.OR.ACC.GT.1.0E-6) ACC = 1.0E-6\n R = RHO\n KTR = 1\n LMAX = MAXL\n LMIN1 = MINL + 1\n XLL1 = FLOAT(MINL*LMIN1)\n ETA2 = ETA*ETA\n TURN = ETA + SQRT(ETA2 + XLL1)\n IF(R.LT.TURN.AND.ABS(ETA).GE.1.0E-6) KTR = -1\n KTRP = KTR\n GO TO 2\n1 R = TURN\n TF = F\n TFP = FP\n LMAX = MINL\n KTRP = 1\n2 ETAR = ETA*R\n RHO2 = R*R\n PL = FLOAT(LMAX + 1)\n PMX = PL + 0.5\n !\n ! *** CONTINUED FRACTION FOR FP(MAXL)/F(MAXL) XL IS F XLPRIME IS FP **\n !\n FP = ETA/PL + PL/R\n DK = ETAR*2.0\n DEL = 0.0\n D = 0.0\n F = 1.0\n K = (PL*PL - PL + ETAR)*(2.0*PL - 1.0)\n IF(PL*PL+PL+ETAR.NE.0.0) GO TO 3\n R = R + 1.0E-6\n GO TO 2\n3 H = (PL*PL + ETA2)*(1.0 - PL*PL)*RHO2\n K = K + DK + PL*PL*6.0\n D = 1.0/(D*H + K)\n DEL = DEL*(D*K - 1.0)\n IF(PL.LT.PMX) DEL = -R*(PL*PL + ETA2)*(PL +1.0)*D/PL\n PL = PL + 1.0\n FP = FP + DEL\n IF(D.LT.0.0) F=-F\n IF(PL.GT.20000.) GO TO 11\n IF(ABS(DEL/FP).GE.ACC) GO TO 3\n FP = F*FP\n IF(LMAX.EQ.MINL) GO TO 5\n FC(LMAX+1) = F\n FCP(LMAX+1) = FP\n !\n ! *** DOWNWARD RECURSION TO MINL FOR F AND FP, ARRAYS GC,GCP ARE STORAGE\n !\n L = LMAX\n DO 4 LP = LMIN1,LMAX\n PL = FLOAT(L)\n GC(L+1) = ETA/PL + PL/R\n GCP(L+1) = SQRT(ETA2 + PL*PL)/PL\n FC(L) = (GC(L+1)*FC(L+1) + FCP(L+1))/GCP(L+1)\n FCP(L) = GC(L+1)*FC(L) - GCP(L+1)*FC(L+1)\n4 L = L - 1\n F = FC(LMIN1)\n FP = FCP(LMIN1)\n5 IF(KTRP.EQ.-1) GO TO 1\n !\n ! *** REPEAT FOR R = TURN IF RHO LT TURN\n ! *** NOW OBTAIN P + 1.Q FOR MINL FROM CONTINUED FRACTION (32)\n ! *** REAL ARITHMETIC TO FACILITATE CONVERSION TO IBM USING REAL*8\n !\n P = 0.0\n Q = R - ETA\n PL = 0.0\n AR = -(ETA2 + XLL1)\n AI = ETA\n BR = 2.0*Q\n BI = 2.0\n WI = 2.0*ETA\n DR = BR/(BR*BR + BI*BI)\n DI = -BI/(BR*BR + BI*BI)\n DP_x = -(AR*DI + AI*DR)\n DQ = (AR*DR - AI*DI)\n6 P = P + DP_x\n Q = Q + DQ\n PL = PL +2.0\n AR = AR + PL\n AI = AI + WI\n BI = BI + 2.0\n D = AR*DR - AI*DI + BR\n DI = AI*DR + AR*DI + BI\n T = 1.0/(D*D + DI*DI)\n DR = T*D\n DI = -T*DI\n H = BR*DR - BI*DI - 1.0\n K = BI*DR + BR*DI\n T = DP_x*H - DQ*K\n DQ = DP_x*K + DQ*H\n DP_x = T\n IF(PL.GT.46000.) GO TO 11\n IF(ABS(DP_x)+ABS(DQ).GE.(ABS(P)+ABS(Q))*ACC) GO TO 6\n P = P/R\n Q = Q/R\n !\n ! *** SOLVE FOR FP,G,GP AND NORMALISE F AT L=MINL\n !\n G = (FP - P*F)/Q\n GP = P*G - Q*F\n W = 1.0/SQRT(FP*G - F*GP)\n G = W*G\n GP = W*GP\n IF(KTR.EQ.1) GO TO 8\n F = TF\n FP = TFP\n LMAX = MAXL\n !\n ! *** RUNGE-KUTTA INTEGRATION OF G(MINL) AND GP(MINL) INWARDS FROM TURN\n ! *** SEE FOX AND MAYERS 1968 PG 202\n !\n IF(RHO.LT.0.2*TURN) PACE = 999.0\n R3 = 1.0/3.0D0\n H = (RHO - TURN)/(PACE + 1.0)\n H2 = 0.5*H\n !!! I2 = IFIX(PACE + 0.001)\n I2 = INT(PACE + 0.001)\n ETAH = ETA*H\n H2LL = H2*XLL1\n S = (ETAH + H2LL/R)/R - H2\n7 RH2 = R + H2\n T = (ETAH + H2LL/RH2)/RH2 - H2\n K1 = H2*GP\n M1 = S*G\n K2 = H2*(GP + M1)\n M2 = T*(G + K1)\n K3 = H*(GP + M2)\n M3 = T*(G + K2)\n M3 = M3 + M3\n K4 = H2*(GP + M3)\n RH = R + H\n S = (ETAH + H2LL/RH)/RH - H2\n M4 = S*(G + K3)\n G = G + (K1 + K2 + K2 + K3 + K4)*R3\n GP = GP + (M1 + M2 + M2 + M3 + M4)*R3\n R = RH\n I2 = I2 - 1\n IF(ABS(GP).GT.1.0E37) GO TO 11\n IF(I2.GE.0) GO TO 7 \n W = 1.0/(FP*G - F*GP)\n !\n ! *** UPWARD RECURSION FROM GC(MINL) AND GCP(MINL),STORED VALUES ARE R,S\n ! *** RENORMALISE FC, FCP FOR EACH L-VALUE\n !\n8 GC (LMIN1) = G\n GCP(LMIN1) = GP\n IF (LMAX.EQ.MINL) GO TO 10\n DO 9 L=LMIN1,LMAX \n T = GC(L+1)\n GC(L+1) = (GC(L)*GC(L+1) - GCP(L))/GCP(L+1)\n GCP(L+1) = GC(L)*GCP(L+1) - GC(L+1)*T\n FC(L+1) = W*FC(L+1)\n9 FCP(L+1) = W*FCP(L+1)\n FC(LMIN1) = FC(LMIN1)*W\n FCP(LMIN1) = FCP(LMIN1)*W\n RETURN\n10 FC(LMIN1) = W*F\n FCP(LMIN1) = W*FP\n RETURN\n11 W = 0.0\n G = 0.0\n GP = 0.0\n GO TO 8\n !\n end subroutine coul_cern_kabachnik\n !\n !\n function distance(coordinates,x1,y1,z1,x2,y2,z2) result(value)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the \"distance\" between two 3-dimensional points; these points can be given in either \"cartesian\" or \n ! \"spherical\" coordinates.\n !\n ! Calls: transform_spherical_to_cart().\n !--------------------------------------------------------------------------------------------------------------------\n !\n character(len=9), intent(in) :: coordinates\n real(kind=dp), intent(in) :: x1, y1, z1, x2, y2, z2\n real(kind=dp) :: value, x1w, y1w, z1w, x2w, y2w, z2w\n !\n if (coordinates(1:9) == \"cartesian\") then\n value = sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1) )\n else if (coordinates(1:9) == \"spherical\") then\n call transform_spherical_to_cart(x1,y1,z1,x1w,y1w,z1w)\n call transform_spherical_to_cart(x2,y2,z2,x2w,y2w,z2w)\n value = sqrt( (x2w-x1w)*(x2w-x1w) + (y2w-y1w)*(y2w-y1w) + (z2w-z1w)*(z2w-z1w) )\n else if (rabs_use_stop) then\n stop \"distance(): program stop A.\"\n end if\n !\n end function distance\n !\n !\n function double_factorial(n) result(dfactorial)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the value n!! for given positive integer n.\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: n\n integer :: dfactorial\n !\n if (n < 0 .or. n > 23) then\n print *, \"n = \",n\n stop \"double_factorial(): program stop A.\"\n else\n dfactorial = dfak(n)\n end if\n !\n end function double_factorial\n !\n !\n function factorial(n) result(value)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the value n! for given positive integer n.\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: n\n integer :: value, i\n !\n if (rabs_use_stop .and. n < 0) then\n print *, \"n = \",n\n stop \"factorial(): program stop A.\"\n else if (n== 0) then\n value = 1 \n else\n value = 1\n\t do i = n,2,-1\n\t value = value * i\n\t end do \n end if\n !\n end function factorial\n !\n !\n function factorial_dp(n) result(value)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the value n! for given positive integer n.\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: n\n integer :: i\n real(kind=dp) :: value\n !\n if (rabs_use_stop .and. n < 0) then\n print *, \"n = \",n\n stop \"factorial_dp(): program stop A.\"\n else if (n== 0) then\n value = one \n else\n value = one\n\t do i = n,2,-1\n\t value = value * i\n\t end do \n end if\n !\n end function factorial_dp\n !\n !\n function gamma_complex(arg) result(cgamma)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns in cgamma the complex Gamma function of the complex argument arg. Only real(cgamma) is nonzero if aimag(arg) \n ! is zero. The arctan function required must return angles (in radians) in the range [0,2*\\pi).\n ! This routine was originally written by F A Parpia and has been adapted to the Fortran 90/95 standard.\n !--------------------------------------------------------------------------------------------------------------------\n !\n complex(kind=dp), intent(in) :: arg\n complex(kind=dp) :: cgamma\n !\n logical, save :: first = .true.\n real(kind=dp), save :: hlntpi, twoi\n logical :: negarg\n !\n ! These are the Bernoulli numbers B02, B04, ..., B14, expressed as rational numbers. From Abramowitz and Stegun, p. 810. \n real(kind=dp), dimension(7), save :: &\n fn = (/ 1.0_dp, -1.0_dp, 1.0_dp, -1.0_dp, 5.0_dp, -691.0_dp, 7.0_dp /), &\n fd = (/ 6.0_dp, 30.0_dp, 42.0_dp, 30.0_dp, 66.0_dp, 2730.0_dp, 6.0_dp /)\n !\n integer :: i\n real(kind=dp) :: argum, argur, argur2, argui, argui2, clngr, clngi, diff, fac, facneg, obasq, obasqi, obasqr, &\n ovlfac, ovlfr, ovlfi, termr, termi, zfacr, zfaci\n !\n ! On the first entry to this routine, set up the constants required for the reflection formula (cf. Abramowitz and \n ! Stegun 6.1.17) and Stirling's approximation (cf. Abramowitz and Stegun 6.1.40).\n if (first) then\n hlntpi = half * log(pi+pi)\n do i = 1,7\n fn(i) = fn(i) / fd(i)\n twoi = dble(i+i)\n fn(i) = fn(i) / (twoi*(twoi-one))\n end do\n first = .false.\n end if\n !\n ! Cases where the argument is real\n if (aimag(arg) == zero) then\n !\n ! Cases where the argument is real and negative\n if (real(arg) <= zero) then\n !\n ! Stop with an error message if the argument is too near a pole\n ! diff <= precis+precis, originally\n diff = abs( nint(real(arg)) - real(arg) )\n if (diff <= eps10*eps10) then\n print *, \"Argument (\",arg,\") is too close to a pole.\"\n stop \"gamma_complex(): program stop A.\"\n else\n !\n ! Otherwise use the reflection formula (Abramowitz and Stegun 6.1.17) to ensure that the argument is \n ! suitable for Stirling's formula\n argum = pi / (-real(arg) * sin(pi*real(arg)))\n if (argum < zero) then\n argum = -argum\n clngi = pi\n else\n clngi = zero\n end if\n facneg = log (argum)\n argur = -real(arg)\n negarg = .true.\n end if\n ! \n ! Cases where the argument is real and positive\n else\n clngi = zero\n argur = real(arg)\n negarg = .false.\n end if\n !\n ! Use abramowitz and stegun formula 6.1.15 to ensure that the argument in stirling's formula is greater than 10\n ovlfac = one\n 2 if (argur < ten) then\n ovlfac = ovlfac * argur\n argur = argur + one\n goto 2\n end if\n !\n ! Use stirling's formula to compute log (gamma (argum))\n clngr = (argur-half) * log(argur) - argur + hlntpi\n fac = argur\n obasq = one / (argur*argur)\n do i = 1,7\n fac = fac * obasq\n clngr = clngr + fn(i) * fac\n end do\n !\n ! Include the contributions from the recurrence and reflection formulae\n clngr = clngr - log(ovlfac)\n if (negarg) clngr = facneg - clngr\n else\n !\n ! Cases where the argument is complex\n argur = real(arg); argui = aimag(arg)\n argui2 = argui * argui\n !\n ! Use the recurrence formula (Abramowitz and Stegun 6.1.15) to ensure that the magnitude of the argument in \n ! Stirling's formula is greater than 10\n ovlfr = one; ovlfi = zero\n 4 argum = sqrt(argur*argur + argui2)\n if (argum < 10) then\n termr = ovlfr*argur - ovlfi*argui\n termi = ovlfr*argui + ovlfi*argur\n ovlfr = termr\n ovlfi = termi\n argur = argur + one\n goto 4\n end if\n !\n ! Use stirling's formula to compute log (gamma (argum))\n argur2 = argur * argur\n termr = half * log(argur2 + argui2)\n termi = arctan_0_2pi(argui,argur)\n clngr = (argur-half) * termr - argui*termi - argur+hlntpi\n clngi = (argur-half) * termi + argui*termr - argui\n fac = (argur2+argui2)**(-2)\n obasqr = (argur2-argui2) * fac\n obasqi = -two * argur * argui * fac\n zfacr = argur; zfaci = argui\n do i = 1,7\n termr = zfacr*obasqr - zfaci*obasqi\n termi = zfacr*obasqi + zfaci*obasqr\n fac = fn(i)\n clngr = clngr + termr*fac\n clngi = clngi + termi*fac\n zfacr = termr; zfaci = termi\n end do\n !\n ! Add in the relevant pieces from the recurrence formula\n clngr = clngr - half * log(ovlfr*ovlfr + ovlfi*ovlfi)\n clngi = clngi - arctan_0_2pi (ovlfi,ovlfr)\n end if\n !\n ! Now exponentiate the complex log gamma function to get the complex gamma function\n if (clngr <= maxexponent(one) .and. clngr >= minexponent(one)) then\n fac = exp (clngr)\n else\n print *, \"Argument to exponential function\",clngr,\"out of range.\"\n stop \"gamma_complex(): program stop A.\"\n end if\n !\n cgamma = cmplx(fac *cos(clngi), fac *sin(clngi))\n !\n end function gamma_complex\n !\n !\n function gamma_func(a2) result(gamma)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the value of the Gamma(a) = Gamma(a2/2) function for integer and half-integer arguments using the array \n ! gamma_store(:,:) which needs to be initialized before.\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: a2\n real(kind=dp) :: gamma\n !\n if (rabs_use_stop .and. a2 > ndbeta) then\n stop \"gamma_func(): program stop A.\"\n end if\n gamma = gamma_store(a2)\n !\n end function gamma_func\n !\n !\n function Gammax_over_ax(x,a) result(Gammax)\n !--------------------------------------------------------------------------------------------------------------------\n ! Calculates the value Gamma(x) / a^x by calling the function nag_nag_s14aaf() from the NAG library in order to compute \n ! Gamma function for non-integer arguments.\n !\n ! Calls: nag_s14aaf() [from NAG library].\n !--------------------------------------------------------------------------------------------------------------------\n !\n real(kind=dp), intent(in) :: a, x\n real(kind=dp) :: Gammax\n !\n if (rabs_use_naglib) then\n Gammax = nag_s14aaf(x,ifail) / ( a ** x )\n else \n stop \"Gammax_over_ax(): program stop A.\"\n end if\n !\n end function Gammax_over_ax\n !\n !\n subroutine get_maximum_minimum(keyword,x,y,n,xloc,yval) \n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the location xloc and the corresponding value yval of either a local maximum or minimum by interpolation. \n ! The 'function' must be contained in y(n) = f(x(n)) and must be either convex or concav according to the keyword. \n ! It is also assumed that the maximum/minimum is not located 'too close' of one of the boundaries x(1) and x(n).\n !--------------------------------------------------------------------------------------------------------------------\n !\n character(len=7), intent(in) :: keyword\n integer, intent(in) :: n\n real(kind=dp), dimension(1:n), intent(in) :: x, y\n real(kind=dp), intent(out) :: xloc, yval\n !\n real(kind=dp) :: x1, x2, x3, dx, y1, y2, y3\n !\n dx = (x(n) - x(1)) / (ten*two)\n x1 = x(1) - dx/two\n !\n do\n x1 = x1 + dx; x2 = x1 + dx; x3 = x2 + dx\n call interpolation_aitken(x,y,n,x1,y1)\n call interpolation_aitken(x,y,n,x2,y2)\n call interpolation_aitken(x,y,n,x3,y3)\n !\n select case(keyword)\n case(\"maximum\")\n if (y1 < y2 .and. y2 > y3) then\n if (abs(x1-x2) < 1.0e-6) then\n xloc = x2; yval = y2\n return\n end if\n dx = -dx / ten; x1 = x3 - dx\n else if (x1 < x(1) .or. x3 < x(1) .or. x1 > x(n) .or. x3 > x(n)) then\n stop \"get_maximum_minimum(): program stop A.\"\n end if\n case(\"minimum\")\n if (y1 > y2 .and. y2 < y3) then\n if (abs(x1-x2) < 1.0e-6) then\n xloc = x2; yval = y2\n return\n end if\n dx = -dx / ten; x1 = x3 - dx\n else if (x1 < x(1) .or. x3 < x(1) .or. x1 > x(n) .or. x3 > x(n)) then\n stop \"get_maximum_minimum(): program stop B.\"\n end if\n case default\n stop \"get_maximum_minimum(): program stop C.\"\n end select\n end do\n !\n end subroutine get_maximum_minimum\n !\n !\n function hypergeometric_2F1(a,b,c,x) result(value)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the value of the Gauss' hypergeometric function 2F_1 = F(a,b,c;x) for real parameter a, b, and c, and for \n ! real argument x. The hypergeometric function is calculated by its power expansion as given by I. S. Gradshteyn and \n ! I. M. Ryzhik, Tables of Integrals, Series, and Products (Academic Press, New York, London a.o. 1980).\n !--------------------------------------------------------------------------------------------------------------------\n !\n real(kind=dp), intent(in) :: a, b, c, x\n real(kind=dp) :: value\n !\n integer :: i\n real(kind=dp) :: wa, wb, wc, wd\n ! \n if (rabs_use_stop .and. c == zero) then\n stop \"hypergeometric_2F1(): program stop A.\"\n end if\n !\n wa = a*b/c; wb = x; wc = one; \n !\n value = one + wa*wb\n !\n do i = 2,400\n wa = wa * (a+i-1) * (b+i-1) / (c+i-1)\n wb = wb * x\n wc = wc * i\n wd = wa*wb/wc\n value = value + wd\n\t !\n if (abs(wd) < epsilon(value)) then\n return\n end if\n end do\n !\n print *, \"i, value, wd = \",i, value, wd\n stop \"hypergeometric_2F1(): program stop B.\"\n !\n end function hypergeometric_2F1\n !\n !\n function hypergeometric_2F1_complex_b(a,b,c,z) result(value)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the value of the Gauss' hypergeometric function 2F_1 = F(a,b,c;x) for real parameter a, and c, and for \n ! complex b and argument z. The hypergeometric function is calculated by its power expansion as given by \n ! I. S. Gradshteyn and I. M. Ryzhik, Tables of Integrals, Series, and Products (Academic Press, New York, \n ! London a.o. 1980).\n !--------------------------------------------------------------------------------------------------------------------\n !\n complex(kind=dp), intent(in) :: a, b, c, z\n complex(kind=dp) :: value\n !\n integer :: i\n complex(kind=dp) :: wa, wb, wc, wd\n ! \n if (rabs_use_stop .and. c == zero) then\n stop \"hypergeometric_2F1_complex_b(): program stop A.\"\n end if\n !\n wa = a*b/c; wb = z; wc = one; \n !\n value = one + wa*wb\n !\n do i = 2,400\n wa = wa * (a+i-1) * (b+i-1) / (c+i-1)\n wb = wb * z\n wc = wc * i\n wd = wa*wb/wc\n value = value + wd\n\t !\n if (abs(wd) < epsilon(abs(value))) then\n return\n end if\n end do\n !\n print *, \"i, value, wd = \",i, value, wd\n stop \"hypergeometric_2F1_complex_b(): program stop B.\"\n !\n end function hypergeometric_2F1_complex_b\n !\n !\n function hypergeometric_2F1_complex_g(a,b,c,z) result(value)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the value of the Gauss' hypergeometric function 2F_1 = F(a,b,c;x) for real parameter a, and c, and for \n ! complex b and argument z. The hypergeometric function is calculated by its power expansion as given by \n ! I. S. Gradshteyn and I. M. Ryzhik, Tables of Integrals, Series, and Products (Academic Press, New York, \n ! London a.o. 1980).\n !--------------------------------------------------------------------------------------------------------------------\n !\n complex(kind=dp), intent(in) :: a, b, c, z\n complex(kind=dp) :: value\n !\n integer :: i\n complex(kind=dp) :: wa, wb, wc, wd, F1, F2\n ! \n if (rabs_use_stop .and. c == zero) then\n stop \"hypergeometric_2F1_complex_g(): program stop A.\"\n else if (abs(z) <= one) then\n print *, \"Standard way\"\n value = hypergeometric_2F1_complex_b(a,b,c,z)\n !! else if (abs(one-one/z) < one \t .and. &\n !!\t abs(atan2(aimag(z),real(z))) < Pi .and. &\n !!\t abs(atan2(aimag(-z),real(one-z))) < Pi) then\n !! print *, \"3rd extended way\"\n !! value = gamma_complex(c)*gamma_complex(c-a-b)\t\t &\n !!\t /(gamma_complex(c-a)*gamma_complex(c-b)) *(z**a)\t &\n !!\t * hypergeometric_2F1_complex_b(a,a-c+one,a+b-c+one,one-one/z)&\n !!\t + (one-z)**(c-a-b) * z**(a-c) \t\t &\n !!\t * gamma_complex(c)*gamma_complex(a+b-c)\t\t &\n !!\t /(gamma_complex(a)*gamma_complex(b)) \t\t &\n !!\t * hypergeometric_2F1_complex_b(c-a,one-a,c-a-b+one,one-one/z)\n else if (abs(one-z) < one .and. &\n abs(atan2(aimag(-z),real(one-z))) < Pi) then\n F1 = gamma_complex(c)*gamma_complex(c-a-b) /(gamma_complex(c-a)*gamma_complex(c-b)) &\n * hypergeometric_2F1_complex_b(a,b,a+b-c+one,one-z)\n F2 = (one-z)**(c-a-b) * gamma_complex(c)*gamma_complex(a+b-c) &\n /(gamma_complex(a)*gamma_complex(b)) * hypergeometric_2F1_complex_b(c-a,c-b,c-a-b+one,one-z)\n print *, \"2nd extended way; F1, F2 = \",F1,F2\n !\n value = gamma_complex(c)*gamma_complex(c-a-b) /(gamma_complex(c-a)*gamma_complex(c-b)) &\n * hypergeometric_2F1_complex_b(a,b,a+b-c+one,one-z) &\n + (one-z)**(c-a-b) * gamma_complex(c)*gamma_complex(a+b-c) &\n /(gamma_complex(a)*gamma_complex(b)) * hypergeometric_2F1_complex_b(c-a,c-b,c-a-b+one,one-z)\n else if (abs(z) > one .and. &\n abs(atan2(aimag(-z),real(-z))) < Pi) then\n print *, \"1st extended way\"\n value = gamma_complex(c)*gamma_complex(b-a) /(gamma_complex(b)*gamma_complex(c-a)) * (-z)**(-a) &\n * hypergeometric_2F1_complex_b(a,one-c+a,one-b+a,one/z) &\n + gamma_complex(c)*gamma_complex(a-b) /(gamma_complex(c-b)*gamma_complex(a)) * (-z)**(-b) &\n * hypergeometric_2F1_complex_b(b,one-c+b,one-a+b,one/z)\n else\n stop \"hypergeometric_2F1_complex_g(): program stop B.\"\n end if\n !\n !\n end function hypergeometric_2F1_complex_g\n !\n !\n function hypergeometric_Phi(a,b,x) result(value)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the value of the degenerate hypergeometric function 1F_1 = Phi(a,b;x) for real parameters a and b, and for \n ! real argument x. The degenerate hypergeometric function is calculated by applying its power expansion as given by \n ! I. S. Gradshteyn and I. M. Ryzhik, Tables of Integrals, Series, and Products (Academic Press, New York, \n ! London a.o. 1980).\n !--------------------------------------------------------------------------------------------------------------------\n !\n real(kind=dp), intent(in) :: a, b, x\n real(kind=dp) :: value\n !\n integer :: i\n real(kind=dp) :: wa, wb, wc, wd\n ! \n if (rabs_use_stop .and. b == zero) then\n stop \"hypergeometric_Phi(): program stop A.\"\n end if\n !\n wa = a/b; wb = x; wc = one; \n !\n value = one + wa*wb\n !\n do i = 2,400\n wa = wa * (a+i-1) / (b+i-1)\n wb = wb * x / i\n wd = wa * wb\n value = value + wd\n if (abs(wd) < epsilon(value)) then\n return\n end if\n end do\n !\n !! print *, \"i, a, b, x, value, wd = \", i, a, b, x, value, wd\n print *, \"hypergeometric_Phi(): program stop B.\"\n stop\n !\n end function hypergeometric_Phi\n !\n !\n function incomplete_beta_func(a2,b2,x) result(incbeta)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the value of the incomplete Beta(a,b,x) = Beta(a2/2,b2/2,x) function for integer and half-integer arguments \n ! a, b by using the array beta_frac_coeff(:,:) which needs to be initialized before.\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: a2, b2\n real(kind=dp), intent(in) :: x\n real(kind=dp) :: incbeta\n !\n integer :: m\n real(kind=dp) :: a, b, bt, wn, wx\n !\n if (rabs_use_stop .and. &\n (a2 > ndbeta .or. b2 > ndbeta)) then\n stop \"incomplete_beta_func(): program stop A.\"\n end if\n !\n a = a2 / two\n b = b2 / two\n !\n if (rabs_use_stop .and. (x < zero .or. x > one)) then\n stop \"incomplete_beta_func(): program stop B.\"\n else if (x == zero .or. x == one ) then\n bt = zero\n else\n bt = (x**a) * ( (one - x)**b )\n end if\n !\n if (x < (a + one)/(a + b + two) ) then\n wx = x\n wn = beta_frac_coeff(ndmx,a2,b2) * wx + one\n do m = (ndmx-1),1,-1\n wn = beta_frac_coeff(m,a2,b2) * wx / wn + one\n end do\n incbeta = bt / (a * wn)\n else\n wx = one - x\n wn = beta_frac_coeff(ndmx,b2,a2) * wx + one\n do m = (ndmx-1),1,-1\n wn = beta_frac_coeff(m,b2,a2) * wx / wn + one\n end do\n incbeta = beta_store(a2,b2) - bt / (b * wn)\n endif\n !\n end function incomplete_beta_func\n !\n !\n function integral_one_dim(points,func,delta_x) result(value)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns a simple estimate of the integral value int func(x) dx with an equidistant step size delta_x. points is \n ! the number of grid points and func(i) contains the corresponding values of the function.\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: points\n real(kind=dp), intent(in) :: delta_x\n real(kind=dp), dimension(:), intent(in) :: func\n real(kind=dp) :: value\n !\n integer :: i\n ! \n value = zero\n do i = 2,points\n value = value + func(i) * delta_x \n end do\n !\n end function integral_one_dim\n !\n !\n subroutine interpolation_aitken(xarr,yarr,narr,xval,yval,accy)\n !--------------------------------------------------------------------------------------------------------------------\n ! This routine returns yval as the functions value of xval by interpolating a pair of arrays xarr(1:narr), \n ! yarr(1:narr), that tabulate a function. Aitken's algorithm is used. See, for instance, F B Hildebrand, Introduction \n ! to Numerical Analysis, 2nd ed., McGraw-Hill, New York, NY, 1974. accy is the desired accuracy of the estimate: \n ! a warning message is issued if this is not achieved. A warning is also issued when the routine is extrapolating. \n ! This procedures is adapted to Fortran 90/95 from the routine interp() of GRASP92 which originally was written by \n ! F A Parpia.\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: narr\n real(kind=dp), intent(in) :: xval\n real(kind=dp), intent(out) :: yval\n real(kind=dp), dimension(narr), intent(in) :: xarr, yarr\n real(kind=dp), intent(in), optional :: accy\n !\n ! mxord is the maximum order of the interpolation\n integer, parameter :: mxord = 11\n logical, dimension(2*mxord+2) :: used\n real(kind=dp), dimension(mxord) :: dx, x, est\n real(kind=dp), dimension((mxord*(mxord+1))/2) :: poly\n !\n logical :: set\n integer :: ibest, ilirok, ildiag, ilothr, irow, k, lhi, llo, llr, locnxt, nrsthi, nrstlo\n real(kind=dp) :: debe, debeb, diff, difft\n !\n ! Determine the nearest two XARR entries bounding XVAL\n if (xval < xarr(1)) then\n nrstlo = 1; nrsthi = 1\n print *, \"interpolation_aitken(): Extrapolating, not interpolating.\"\n elseif (xval > xarr(narr)) then\n nrstlo = narr; nrsthi = narr\n print *, \"interpolation_aitken(): Extrapolating, not interpolating.\"\n else\n k = 0\n 1 k = k+1\n if (xarr(k) < xval) then\n nrstlo = k\n goto 1\n else\n nrsthi = k\n end if\n end if\n !\n ! Clear relevant piece of use-indicator array\n llo = max(nrstlo-mxord, 1)\n lhi = min(nrsthi+mxord,narr)\n llr = llo - 1\n do k = llo,lhi\n used(k-llr) = .false.\n end do\n !\n ! Determine next-nearest XARR entry\n do irow = 1,mxord\n llo = max(nrstlo-irow+1, 1)\n lhi = min(nrsthi+irow-1,narr)\n set = .false.\n do k = llo,lhi\n if (.not.used(k-llr)) then\n if (.not.set) then\n diff = xarr(k) - xval\n locnxt = k\n set = .true.\n else\n difft = xarr(k) - xval\n if (abs(difft) < abs(diff)) then\n diff = difft\n locnxt = k\n end if\n end if\n end if\n end do\n used(locnxt-llr) = .true.\n x(irow) = xarr(locnxt)\n dx(irow) = diff\n !\n ! Fill table for this row\n do k = 1,irow\n ilirok = iloc(irow,k)\n if (k == 1) then\n poly(ilirok) = yarr(locnxt)\n else\n ildiag = iloc(k-1,k-1)\n ilothr = iloc(irow,k-1)\n poly(ilirok) = (poly(ildiag)*dx(irow) - poly(ilothr)*dx(k-1)) / (x(irow)-x(k-1))\n endif\n end do\n !\n ! Pick off the diagonal element\n ildiag = iloc(irow,irow)\n est(irow) = poly(ildiag)\n end do\n !\n ! Now the estimate vector is filled in, so obtain the best estimate\n debeb = abs((est(2) - est(1)) / est(2))\n ibest = 2\n do irow = 3,mxord\n debe = abs((est(irow) - est(irow-1)) / est(irow))\n if (debe < debeb) then\n debeb = debe\n ibest = irow\n end if\n end do\n yval = est(ibest)\n !\n if (present(accy)) then\n if (debeb > accy) then\n write(*,2) debeb, accy\n 2 format( \"interpolation_aitken(): Accuracy of interpolation (\", e10.3,\") is below input criterion (\",e10.3,\").\")\n end if\n end if\n !\n contains\n !\n function iloc (ind1,ind2) result(loc)\n !--------------------------------------------------------------------------------------------------------------\n ! This internal function dispenses with the need for a two-dimensional array for the interpolation. It replaces a\n ! statement function in the original code.\n !--------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: ind1, ind2\n integer :: loc\n !\n loc = (ind1*(ind1-1)) / 2 + ind2\n !\n end function iloc\n !\n end subroutine interpolation_aitken\n !\n !\n subroutine interpolation_lagrange(arg,val,x,y,n)\n !--------------------------------------------------------------------------------------------------------------------\n ! Interpolates the value val(x) from the values arg(i),val(i), i=1,n by using a Lagrange-interpolation formulae. \n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: n\n real(kind=dp), intent(in) :: x\n real(kind=dp), intent(out) :: y\n real(kind=dp), dimension(:), intent(in) :: arg, val\n !\n integer :: j, l\n real(kind=dp) :: pl\n !\n y = zero\n do l = 1,n\n pl = one\n do j = 1,n\n if (l-j /= 0) then\n pl = (x - arg(j)) * pl / (arg(l) - arg(j))\n end if\n end do\n y = y + pl * val(l)\n end do\n !\n end subroutine interpolation_lagrange\n !\n !\n function is_triangle(i1,i2,i3) result(yes)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns .true. if the lengths i1, i2, and i3 may form a triangle and .false. otherwise.\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: i1, i2, i3\n logical :: yes\n !\n if (i1 <= i2+i3 .and. i2 <= i3+i1 .and. i3 <= i1+i2) then\n yes = .true.\n else\n yes = .false.\n end if\n !\n end function is_triangle\n !\n !\n function legendre_associated(n,m,z) result(value)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the (complex) value of the Legendre function P_n^m (z) for complex argument z.\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: n, m\n complex(kind=dp), intent(in) :: z\n complex(kind=dp) :: value\n !\n integer :: i\n complex(kind=dp), dimension(0:n) :: Pm\n !\n if (rabs_use_stop .and. &\n (n < 0 .or. m /= 1)) then\n stop \"legendre_associated(): program stop A.\"\n else if (n == 0) then\n value = zero\n else if (n == 1) then\n value = sqrt(one - z*z)\n else\n Pm(0) = zero; Pm(1) = sqrt(one - z*z)\n\t do i = 1,n-1\n\t Pm(i+1) = ((two*i + one) *z* Pm(i) - (i+m)*Pm(i-1)) / (i - m + one)\n\t end do\n\t value = Pm(n)\n end if\n !\n end function legendre_associated\n !\n !\n function legendre_polynomial(n,z) result(value)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the (complex) value of the Legendre polynomial P_n (z) for complex argument z.\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: n\n complex(kind=dp), intent(in) :: z\n complex(kind=dp) :: value\n !\n integer :: i\n complex(kind=dp), dimension(0:n) :: P\n !\n if (rabs_use_stop .and. n < 0) then\n stop \"legendre_polynomial(): program stop A.\"\n else if (n == 0) then\n value = one\n else if (n == 1) then\n value = z\n else\n P(0) = one; P(1) = z\n\t do i = 1,n-1\n\t P(i+1) = ((two*i + one) * z * P(i) - i * P(i-1)) / (i + one)\n\t end do\n\t value = P(n)\n end if\n !\n end function legendre_polynomial\n !\n !\n subroutine LU_decomposition_of_matrix(matrix,n,d)\n !--------------------------------------------------------------------------------------------------------------------\n ! Calculates the LU decomposition of the n x n matrix; ndim is the dimension in the declaration of matrix. This routine \n ! has been adopted from an algorithmus as discussed in the 'Numerical Recipies'. The real, intent(out) parameter \n ! d = 1.0 or d = -1.0 denotes the number of permutations and may be used to calculate the determinant as d times the \n ! product of all diagonal matrix elements (at output time).\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: n\n real(kind=dp), intent(out) :: d\n real(kind=dp), dimension(:,:), intent(inout) :: matrix\n !\n integer :: i, imax, j, k\n real(kind=dp) :: a_max, dummy, sum\n integer, dimension(1:size(matrix,1)) :: index\n real(kind=dp), dimension(n) :: vv\n !\n d = one\n do i = 1,n\n a_max = zero\n do j = 1,n; a_max = max(a_max, abs(matrix(i,j))); end do\n if (a_max == zero) then\n print *, \"LU_decomposition_of_matrix(): singular matrix.\"\n ! stop\n else\n vv(i) = one / a_max\n end if\n end do\n !\n do j = 1,n\n do i = 1,j-1\n sum = matrix(i,j)\n do k = 1,i-1; sum = sum - matrix(i,k)*matrix(k,j); end do\n matrix(i,j) = sum\n end do\n a_max = zero\n do i = j,n\n sum = matrix(i,j)\n do k = 1,j-1; sum = sum - matrix(i,k)*matrix(k,j); end do\n matrix(i,j) = sum\n dummy = vv(i) * abs(sum)\n if (dummy >= a_max) then\n imax = i; a_max = dummy\n end if\n end do\n if (j /= imax) then\n do k = 1,n\n dummy = matrix(imax,k); matrix(imax,k) = matrix(j,k)\n matrix(j,k) = dummy\n end do\n d = -d; vv(imax) = vv(j)\n end if\n index(j) = imax\n if (matrix(j,j) == zero) matrix(j,j) = eps20\n if (j /= n) then\n dummy = one / matrix(j,j)\n do i = j+1,n; matrix(i,j) = matrix(i,j) * dummy; end do\n end if\n end do\n !\n end subroutine LU_decomposition_of_matrix\n ! \n !\n function pochhammer(x,n) result(ph)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the value of Pochhammer's symbol (z)_n for real arguments of x.\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: n\n real(kind=dp), intent(in) :: x\n real(kind=dp) :: ph\n !\n if (n == 0) then\n ph = one\n else if (rabs_use_naglib) then\n ph = nag_s14aaf(x+n,ifail) / nag_s14aaf(x,ifail)\n else \n stop \"pochhammer(): program stop A.\"\n end if\n !\n end function pochhammer\n !\n !\n subroutine set_beta_gamma_arrays()\n !--------------------------------------------------------------------------------------------------------------------\n ! This subprogram allocates and initializes some arrays for the calculation of the Beta function, the incomplete Beta \n ! function, as well as the Gamma function.\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer :: a, b, m\n real(kind=dp) :: wa, wb, wm, wa2m\n !! real(kind=dp) :: nag_s14aaf\n !\n ! Allocate the arrays\n allocate ( gamma_store(2*ndbeta) )\n allocate ( beta_store(ndbeta,ndbeta) )\n allocate ( beta_frac_coeff(ndmx,ndbeta,ndbeta) )\n !\n ! The array gamma_store(n) contains the value Gamma(n/2)\n do a = 1, 2*ndbeta\n wa = a / two\n !! if (rabs_use_naglib) then\n gamma_store(a) = nag_s14aaf(wa,ifail)\n !! else if (rabs_use_stop) then\n !! stop \"set_beta_gamma_arrays(): program stop A.\"\n !! end if\n end do\n !\n ! The array beta_store(a,b) contains the value Beta(a/2,b/2)\n do b = 1, ndbeta\n do a = 1, ndbeta\n beta_store(a,b) = gamma_store(a) * gamma_store(b) / gamma_store(a+b)\n end do\n enddo\n !\n ! The array beta_frac_coeff(n,a,b) contains fractional coefficients for the calculation of the incomplete \n ! Beta(x,a,b) function with integer and half-integer arguments a,b\n !\n do b = 1,ndbeta\n do a = 1,ndbeta\n wa = a / two\n wb = b / two\n beta_frac_coeff(1,a,b) = -(wa + wb) / (wa + one)\n do m = 1,(ndmx/2)\n wm = m\n wa2m = wa + wm + wm\n beta_frac_coeff(m+m,a,b) = wm * (wb - wm) / ((wa2m - one) * wa2m)\n beta_frac_coeff(m+m+1,a,b) = - (wa + wm) * (wa + wb + wm) / (wa2m * (wa2m + one) )\n end do\n end do\n end do\n !\n end subroutine set_beta_gamma_arrays\n !\n !\n subroutine set_gauss_zeros(ax,bx,nx,zw,w)\n !--------------------------------------------------------------------------------------------------------------------\n ! This subprogram set n-point gauss zeros and weights for the interval (ax,bx) into the arrays z(1:nx) and w(1:nx) \n ! respectively.\n !\n ! Calls: set_gauss_zeros_aux\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer :: nx\n real(kind=dp), intent(in) :: ax, bx\n real(kind=dp), dimension(1:nx), intent(out) :: zw, w\n !\n integer :: k, m, n, j, jp, jmid, jtab\n integer, dimension(1:96) :: ltab \n real(kind=dp) :: alpha, beta, delta, wtemp\n real(kind=dp), dimension(1:273) :: b, y \n !\n call set_gauss_zeros_aux(b,y,ltab)\n !\n ! Test n\n n = nx\n alpha = half *(bx+ax)\n beta = half *(bx-ax)\n if (n < 1) then\n print *, \"set_gauss_zeros(): n has a non-permissible value of \",n \n stop\n else if (n /= 1) then\n if ( n <= 16 .or. n == 20 .or. n == 24 .or. n == 32 .or. &\n n == 40 .or. n == 48 .or. n == 64 .or. n == 80 .or. n == 96 ) then \n goto 2\n else\n print *, \"set_gauss_zeros(): n has a non-permissible value of \",n \n stop\n end if\n else\n zw(1) = alpha\n w(1) = bx - ax\n goto 3\n end if\n !\n ! Set k equal to initial subscript and store results\n 2 k = ltab(n)\n m = n / 2\n !\n do j = 1,m\n jtab = k-1+j\n wtemp = beta * b(jtab)\n delta = beta * y(jtab)\n zw(j) = alpha - delta\n w(j) = wtemp\n jp = n+1-j\n zw(jp)= alpha + delta\n w(jp) = wtemp\n end do\n !\n if (n-m-m == 0) then\n else\n zw(m+1) = alpha\n jmid = k+m\n w(m+1) = beta * b(jmid)\n end if\n ! \n 3 continue\n !\n end subroutine set_gauss_zeros\n !\n !\n subroutine set_gauss_zeros_aux(b,y,ltab)\n !--------------------------------------------------------------------------------------------------------------------\n ! This subprogram is an auxilarity routine for set_gauss_zeros to set n-point Gauss zeros and weights.\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, dimension(1:96), intent(out) :: ltab \n real(kind=dp), dimension(1:273), intent(out) :: b(273), y(273) \n !\n integer :: i\n integer, dimension(1:96), save :: ktab \n real(kind=dp), dimension(1:273), save :: a(273), x(273) \n !\n ! Table of initial subscripts for n= 2 (1) 16 (4) 96\n data ktab(2)/1/; data ktab(3)/2/; data ktab(4)/4/\n data ktab(5)/6/; data ktab(6)/9/; data ktab(7)/12/\n data ktab(8)/16/; data ktab(9)/20/; data ktab(10)/25/\n data ktab(11)/30/; data ktab(12)/36/; data ktab(13)/42/\n data ktab(14)/49/; data ktab(15)/56/; data ktab(16)/64/\n data ktab(20)/72/; data ktab(24)/82/; data ktab(28)/82/\n data ktab(32)/94/; data ktab(36)/94/; data ktab(40)/110/\n data ktab(44)/110/; data ktab(48)/130/; data ktab(52)/130/\n data ktab(56)/130/; data ktab(60)/130/; data ktab(64)/154/\n data ktab(68)/154/; data ktab(72)/154/; data ktab(76)/154/\n data ktab(80)/186/; data ktab(84)/186/; data ktab(88)/186/\n data ktab(92)/186/; data ktab(96)/226/\n !\n ! Table of abscissae (x) and weights (a) for interval (-1,+1).\n !\n ! n = 2\n data x(1)/0.577350269189626_dp /, a(1)/1.000000000000000_dp /\n ! n = 3\n data x(2)/0.774596669241483_dp /, a(2)/0.555555555555556_dp /\n data x(3)/0.000000000000000_dp /, a(3)/0.888888888888889_dp /\n ! n = 4\n data x(4)/0.861136311594053_dp /, a(4)/0.347854845137454_dp /\n data x(5)/0.339981043584856_dp /, a(5)/0.652145154862546_dp /\n ! n = 5\n data x(6)/0.906179845938664_dp /, a(6)/0.236926885056189_dp /\n data x(7)/0.538469310105683_dp /, a(7)/0.478628670499366_dp /\n data x(8)/0.000000000000000_dp /, a(8)/0.568888888888889_dp /\n ! n = 6\n data x(9)/0.932469514203152_dp /, a(9)/0.171324492379170_dp /\n data x(10)/0.661209386466265_dp /, a(10)/0.360761573048139_dp /\n data x(11)/0.238619186083197_dp /, a(11)/0.467913934572691_dp /\n ! n = 7\n data x(12)/0.949107912342759_dp /, a(12)/0.129484966168870_dp /\n data x(13)/0.741531185599394_dp /, a(13)/0.279705391489277_dp /\n data x(14)/0.405845151377397_dp /, a(14)/0.381830050505119_dp /\n data x(15)/0.000000000000000_dp /, a(15)/0.417959183673469_dp /\n ! n = 8\n data x(16)/0.960289856497536_dp /, a(16)/0.101228536290376_dp /\n data x(17)/0.796666477413627_dp /, a(17)/0.222381034453374_dp /\n data x(18)/0.525532409916329_dp /, a(18)/0.313706645877887_dp /\n data x(19)/0.183434642495650_dp /, a(19)/0.362683783378362_dp /\n ! n = 9\n data x(20)/0.968160239507626_dp /, a(20)/0.081274388361574_dp /\n data x(21)/0.836031107326636_dp /, a(21)/0.180648160694857_dp /\n data x(22)/0.613371432700590_dp /, a(22)/0.260610696402935_dp /\n data x(23)/0.324253423403809_dp /, a(23)/0.312347077040003_dp /\n data x(24)/0.000000000000000_dp /, a(24)/0.330239355001260_dp /\n ! n = 10\n data x(25)/0.973906528517172_dp /, a(25)/0.066671344308688_dp /\n data x(26)/0.865063366688985_dp /, a(26)/0.149451349150581_dp /\n data x(27)/0.679409568299024_dp /, a(27)/0.219086362515982_dp /\n data x(28)/0.433395394129247_dp /, a(28)/0.269266719309996_dp /\n data x(29)/0.148874338981631_dp /, a(29)/0.295524224714753_dp /\n ! n = 11\n data x(30)/0.978228658146057_dp /, a(30)/0.055668567116174_dp /\n data x(31)/0.887062599768095_dp /, a(31)/0.125580369464905_dp /\n data x(32)/0.730152005574049_dp /, a(32)/0.186290210927734_dp /\n data x(33)/0.519096129206812_dp /, a(33)/0.233193764591990_dp /\n data x(34)/0.269543155952345_dp /, a(34)/0.262804544510247_dp /\n data x(35)/0.000000000000000_dp /, a(35)/0.272925086777901_dp /\n ! n = 12\n data x(36)/0.981560634246719_dp /, a(36)/0.047175336386512_dp /\n data x(37)/0.904117256370475_dp /, a(37)/0.106939325995318_dp /\n data x(38)/0.769902674194305_dp /, a(38)/0.160078328543346_dp /\n data x(39)/0.587317954286617_dp /, a(39)/0.203167426723066_dp /\n data x(40)/0.367831498998180_dp /, a(40)/0.233492536538355_dp /\n data x(41)/0.125233408511469_dp /, a(41)/0.249147045813403_dp /\n ! n = 13\n data x(42)/0.984183054718588_dp /, a(42)/0.040484004765316_dp /\n data x(43)/0.917598399222978_dp /, a(43)/0.092121499837728_dp /\n data x(44)/0.801578090733310_dp /, a(44)/0.138873510219787_dp /\n data x(45)/0.642349339440340_dp /, a(45)/0.178145980761946_dp /\n data x(46)/0.448492751036447_dp /, a(46)/0.207816047536889_dp /\n data x(47)/0.230458315955135_dp /, a(47)/0.226283180262897_dp /\n data x(48)/0.000000000000000_dp /, a(48)/0.232551553230874_dp /\n ! n = 14\n data x(49)/0.986283808696812_dp /, a(49)/0.035119460331752_dp /\n data x(50)/0.928434883663574_dp /, a(50)/0.080158087159760_dp /\n data x(51)/0.827201315069765_dp /, a(51)/0.121518570687903_dp /\n data x(52)/0.687292904811685_dp /, a(52)/0.157203167158194_dp /\n data x(53)/0.515248636358154_dp /, a(53)/0.185538397477938_dp /\n data x(54)/0.319112368927890_dp /, a(54)/0.205198463721296_dp /\n data x(55)/0.108054948707344_dp /, a(55)/0.215263853463158_dp /\n ! n = 15\n data x(56)/0.987992518020485_dp /, a(56)/0.030753241996117_dp /\n data x(57)/0.937273392400706_dp /, a(57)/0.070366047488108_dp /\n data x(58)/0.848206583410427_dp /, a(58)/0.107159220467172_dp /\n data x(59)/0.724417731360170_dp /, a(59)/0.139570677926154_dp /\n data x(60)/0.570972172608539_dp /, a(60)/0.166269205816994_dp /\n data x(61)/0.394151347077563_dp /, a(61)/0.186161000015562_dp /\n data x(62)/0.201194093997435_dp /, a(62)/0.198431485327111_dp /\n data x(63)/0.000000000000000_dp /, a(63)/0.202578241925561_dp /\n ! n = 16\n data x(64)/0.989400934991650_dp /, a(64)/0.027152459411754_dp /\n data x(65)/0.944575023073233_dp /, a(65)/0.062253523938648_dp /\n data x(66)/0.865631202387832_dp /, a(66)/0.095158511682493_dp /\n data x(67)/0.755404408355003_dp /, a(67)/0.124628971255534_dp /\n data x(68)/0.617876244402644_dp /, a(68)/0.149595988816577_dp /\n data x(69)/0.458016777657227_dp /, a(69)/0.169156519395003_dp /\n data x(70)/0.281603550779259_dp /, a(70)/0.182603415044924_dp /\n data x(71)/0.095012509837637_dp /, a(71)/0.189450610455069_dp /\n ! n = 20\n data x(72)/0.993128599185094_dp /, a(72)/0.017614007139152_dp /\n data x(73)/0.963971927277913_dp /, a(73)/0.040601429800386_dp /\n data x(74)/0.912234428251325_dp /, a(74)/0.062672048334109_dp /\n data x(75)/0.839116971822218_dp /, a(75)/0.083276741576704_dp /\n data x(76)/0.746331906460150_dp /, a(76)/0.101930119817240_dp /\n data x(77)/0.636053680726515_dp /, a(77)/0.118194531961518_dp /\n data x(78)/0.510867001950827_dp /, a(78)/0.131688638449176_dp /\n data x(79)/0.373706088715419_dp /, a(79)/0.142096109318382_dp /\n data x(80)/0.227785851141645_dp /, a(80)/0.149172986472603_dp /\n data x(81)/0.076526521133497_dp /, a(81)/0.152753387130725_dp /\n ! n = 24\n data x(82)/0.995187219997021_dp /, a(82)/0.012341229799987_dp /\n data x(83)/0.974728555971309_dp /, a(83)/0.028531388628933_dp /\n data x(84)/0.938274552002732_dp /, a(84)/0.044277438817419_dp /\n data x(85)/0.886415527004401_dp /, a(85)/0.059298584915436_dp /\n data x(86)/0.820001985973902_dp /, a(86)/0.073346481411080_dp /\n data x(87)/0.740124191578554_dp /, a(87)/0.086190161531953_dp /\n data x(88)/0.648093651936975_dp /, a(88)/0.097618652104113_dp /\n data x(89)/0.545421471388839_dp /, a(89)/0.107444270115965_dp /\n data x(90)/0.433793507626045_dp /, a(90)/0.115505668053725_dp /\n data x(91)/0.315042679696163_dp /, a(91)/0.121670472927803_dp /\n data x(92)/0.191118867473616_dp /, a(92)/0.125837456346828_dp /\n data x(93)/0.064056892862605_dp /, a(93)/0.127938195346752_dp /\n ! n = 32\n data x(94)/0.997263861849481_dp /, a(94)/0.007018610009470_dp /\n data x(95)/0.985611511545268_dp /, a(95)/0.016274394730905_dp /\n data x(96)/0.964762255587506_dp /, a(96)/0.025392065309262_dp /\n data x(97)/0.934906075937739_dp /, a(97)/0.034273862913021_dp /\n data x(98)/0.896321155766052_dp /, a(98)/0.042835898022226_dp /\n data x(99)/0.849367613732569_dp /, a(99)/0.050998059262376_dp /\n data x(100)/0.794483795967942_dp/, a(100)/0.058684093478535_dp/\n data x(101)/0.732182118740289_dp/, a(101)/0.065822222776361_dp/\n data x(102)/0.663044266930215_dp/, a(102)/0.072345794108848_dp/\n data x(103)/0.587715757240762_dp/, a(103)/0.078193895787070_dp/\n data x(104)/0.506899908932229_dp/, a(104)/0.083311924226946_dp/\n data x(105)/0.421351276130635_dp/, a(105)/0.087652093004403_dp/\n data x(106)/0.331868602282127_dp/, a(106)/0.091173878695763_dp/\n data x(107)/0.239287362252137_dp/, a(107)/0.093844399080804_dp/\n data x(108)/0.144471961582796_dp/, a(108)/0.095638720079274_dp/\n data x(109)/0.048307665687738_dp/, a(109)/0.096540088514727_dp/\n ! n = 40\n data x(110)/0.998237709710559_dp/, a(110)/0.004521277098533_dp/\n data x(111)/0.990726238699457_dp/, a(111)/0.010498284531152_dp/\n data x(112)/0.977259949983774_dp/, a(112)/0.016421058381907_dp/\n data x(113)/0.957916819213791_dp/, a(113)/0.022245849194166_dp/\n data x(114)/0.932812808278676_dp/, a(114)/0.027937006980023_dp/\n data x(115)/0.902098806968874_dp/, a(115)/0.033460195282547_dp/\n data x(116)/0.865959503212259_dp/, a(116)/0.038782167974472_dp/\n data x(117)/0.824612230833311_dp/, a(117)/0.043870908185673_dp/\n data x(118)/0.778305651426519_dp/, a(118)/0.048695807635072_dp/\n data x(119)/0.727318255189927_dp/, a(119)/0.053227846983936_dp/\n data x(120)/0.671956684614179_dp/, a(120)/0.057439769099391_dp/\n data x(121)/0.612553889667980_dp/, a(121)/0.061306242492928_dp/\n data x(122)/0.549467125095128_dp/, a(122)/0.064804013456601_dp/\n data x(123)/0.483075801686178_dp/, a(123)/0.067912045815233_dp/\n data x(124)/0.413779204371605_dp/, a(124)/0.070611647391286_dp/\n data x(125)/0.341994090825758_dp/, a(125)/0.072886582395804_dp/\n data x(126)/0.268152185007253_dp/, a(126)/0.074723169057968_dp/\n data x(127)/0.192697580701371_dp/, a(127)/0.076110361900626_dp/\n data x(128)/0.116084070675255_dp/, a(128)/0.077039818164247_dp/\n data x(129)/0.038772417506050_dp/, a(129)/0.077505947978424_dp/\n ! n = 48\n data x(130)/0.998771007252426_dp/, a(130)/0.003153346052305_dp/\n data x(131)/0.993530172266350_dp/, a(131)/0.007327553901276_dp/\n data x(132)/0.984124583722826_dp/, a(132)/0.011477234579234_dp/\n data x(133)/0.970591592546247_dp/, a(133)/0.015579315722943_dp/\n data x(134)/0.952987703160430_dp/, a(134)/0.019616160457355_dp/\n data x(135)/0.931386690706554_dp/, a(135)/0.023570760839324_dp/\n data x(136)/0.905879136715569_dp/, a(136)/0.027426509708356_dp/\n data x(137)/0.876572020274247_dp/, a(137)/0.031167227832798_dp/\n data x(138)/0.843588261624393_dp/, a(138)/0.034777222564770_dp/\n data x(139)/0.807066204029442_dp/, a(139)/0.038241351065830_dp/\n data x(140)/0.767159032515740_dp/, a(140)/0.041545082943464_dp/\n data x(141)/0.724034130923814_dp/, a(141)/0.044674560856694_dp/\n data x(142)/0.677872379632663_dp/, a(142)/0.047616658492490_dp/\n data x(143)/0.628867396776513_dp/, a(143)/0.050359035553854_dp/\n data x(144)/0.577224726083972_dp/, a(144)/0.052890189485193_dp/\n data x(145)/0.523160974722233_dp/, a(145)/0.055199503699984_dp/\n data x(146)/0.466902904750958_dp/, a(146)/0.057277292100403_dp/\n data x(147)/0.408686481990716_dp/, a(147)/0.059114839698395_dp/\n data x(148)/0.348755886292160_dp/, a(148)/0.060704439165893_dp/\n data x(149)/0.287362487355455_dp/, a(149)/0.062039423159892_dp/\n data x(150)/0.224763790394689_dp/, a(150)/0.063114192286254_dp/\n data x(151)/0.161222356068891_dp/, a(151)/0.063924238584648_dp/\n data x(152)/0.097004699209462_dp/, a(152)/0.064466164435950_dp/\n data x(153)/0.032380170962869_dp/, a(153)/0.064737696812683_dp/\n ! n = 64\n data x(154)/0.999305041735772_dp/, a(154)/0.001783280721696_dp/\n data x(155)/0.996340116771955_dp/, a(155)/0.004147033260562_dp/\n data x(156)/0.991013371476744_dp/, a(156)/0.006504457968978_dp/\n data x(157)/0.983336253884625_dp/, a(157)/0.008846759826363_dp/\n data x(158)/0.973326827789910_dp/, a(158)/0.011168139460131_dp/\n data x(159)/0.961008799652053_dp/, a(159)/0.013463047896718_dp/\n data x(160)/0.946411374858402_dp/, a(160)/0.015726030476024_dp/\n data x(161)/0.929569172131939_dp/, a(161)/0.017951715775697_dp/\n data x(162)/0.910522137078502_dp/, a(162)/0.020134823153530_dp/\n data x(163)/0.889315445995114_dp/, a(163)/0.022270173808383_dp/\n data x(164)/0.865999398154092_dp/, a(164)/0.024352702568710_dp/\n data x(165)/0.840629296252580_dp/, a(165)/0.026377469715054_dp/\n data x(166)/0.813265315122797_dp/, a(166)/0.028339672614259_dp/\n data x(167)/0.783972358943341_dp/, a(167)/0.030234657072402_dp/\n data x(168)/0.752819907260531_dp/, a(168)/0.032057928354851_dp/\n data x(169)/0.719881850171610_dp/, a(169)/0.033805161837141_dp/\n data x(170)/0.685236313054233_dp/, a(170)/0.035472213256882_dp/\n data x(171)/0.648965471254657_dp/, a(171)/0.037055128540240_dp/\n data x(172)/0.611155355172393_dp/, a(172)/0.038550153178615_dp/\n data x(173)/0.571895646202634_dp/, a(173)/0.039953741132720_dp/\n data x(174)/0.531279464019894_dp/, a(174)/0.041262563242623_dp/\n data x(175)/0.489403145707052_dp/, a(175)/0.042473515123653_dp/\n data x(176)/0.446366017253464_dp/, a(176)/0.043583724529323_dp/\n data x(177)/0.402270157963991_dp/, a(177)/0.044590558163756_dp/\n data x(178)/0.357220158337668_dp/, a(178)/0.045491627927418_dp/\n data x(179)/0.311322871990210_dp/, a(179)/0.046284796581314_dp/\n data x(180)/0.264687162208767_dp/, a(180)/0.046968182816210_dp/\n data x(181)/0.217423643740007_dp/, a(181)/0.047540165714830_dp/\n data x(182)/0.169644420423992_dp/, a(182)/0.047999388596458_dp/\n data x(183)/0.121462819296120_dp/, a(183)/0.048344762234802_dp/\n data x(184)/0.072993121787799_dp/, a(184)/0.048575467441503_dp/\n data x(185)/0.024350292663424_dp/, a(185)/0.048690957009139_dp/\n ! n = 80\n data x(186)/0.999553822651630_dp/, a(186)/0.001144950003186_dp/\n data x(187)/0.997649864398237_dp/, a(187)/0.002663533589512_dp/\n data x(188)/0.994227540965688_dp/, a(188)/0.004180313124694_dp/\n data x(189)/0.989291302499755_dp/, a(189)/0.005690922451403_dp/\n data x(190)/0.982848572738629_dp/, a(190)/0.007192904768117_dp/\n data x(191)/0.974909140585727_dp/, a(191)/0.008683945269260_dp/\n data x(192)/0.965485089043799_dp/, a(192)/0.010161766041103_dp/\n data x(193)/0.954590766343634_dp/, a(193)/0.011624114120797_dp/\n data x(194)/0.942242761309872_dp/, a(194)/0.013068761592401_dp/\n data x(195)/0.928459877172445_dp/, a(195)/0.014493508040509_dp/\n data x(196)/0.913263102571757_dp/, a(196)/0.015896183583725_dp/\n data x(197)/0.896675579438770_dp/, a(197)/0.017274652056269_dp/\n data x(198)/0.878722567678213_dp/, a(198)/0.018626814208299_dp/\n data x(199)/0.859431406663111_dp/, a(199)/0.019950610878141_dp/\n data x(200)/0.838831473580255_dp/, a(200)/0.021244026115782_dp/\n data x(201)/0.816954138681463_dp/, a(201)/0.022505090246332_dp/\n data x(202)/0.793832717504605_dp/, a(202)/0.023731882865930_dp/\n data x(203)/0.769502420135041_dp/, a(203)/0.024922535764115_dp/\n data x(204)/0.744000297583597_dp/, a(204)/0.026075235767565_dp/\n data x(205)/0.717365185362099_dp/, a(205)/0.027188227500486_dp/\n data x(206)/0.689637644342027_dp/, a(206)/0.028259816057276_dp/\n data x(207)/0.660859898986119_dp/, a(207)/0.029288369583267_dp/\n data x(208)/0.631075773046871_dp/, a(208)/0.030272321759557_dp/\n data x(209)/0.600330622829751_dp/, a(209)/0.031210174188114_dp/\n data x(210)/0.568671268122709_dp/, a(210)/0.032100498673487_dp/\n data x(211)/0.536145920897131_dp/, a(211)/0.032941939397645_dp/\n data x(212)/0.502804111888784_dp/, a(212)/0.033733214984611_dp/\n data x(213)/0.468696615170544_dp/, a(213)/0.034473120451753_dp/\n data x(214)/0.433875370831756_dp/, a(214)/0.035160529044747_dp/\n data x(215)/0.398393405881969_dp/, a(215)/0.035794393953416_dp/\n data x(216)/0.362304753499487_dp/, a(216)/0.036373749905835_dp/\n data x(217)/0.325664370747701_dp/, a(217)/0.036897714638276_dp/\n data x(218)/0.288528054884511_dp/, a(218)/0.037365490238730_dp/\n data x(219)/0.250952358392272_dp/, a(219)/0.037776364362001_dp/\n data x(220)/0.212994502857666_dp/, a(220)/0.038129711314477_dp/\n data x(221)/0.174712291832646_dp/, a(221)/0.038424993006959_dp/\n data x(222)/0.136164022809143_dp/, a(222)/0.038661759774076_dp/\n data x(223)/0.097408398441584_dp/, a(223)/0.038839651059051_dp/\n data x(224)/0.058504437152420_dp/, a(224)/0.038958395962769_dp/\n data x(225)/0.019511383256793_dp/, a(225)/0.039017813656306_dp/\n ! n = 96\n data x(226)/0.999689503883230_dp/, a(226)/0.000796792065552_dp/\n data x(227)/0.998364375863181_dp/, a(227)/0.001853960788946_dp/\n data x(228)/0.995981842987209_dp/, a(228)/0.002910731817934_dp/\n data x(229)/0.992543900323762_dp/, a(229)/0.003964554338444_dp/\n data x(230)/0.988054126329623_dp/, a(230)/0.005014202742927_dp/\n data x(231)/0.982517263563014_dp/, a(231)/0.006058545504235_dp/\n data x(232)/0.975939174585136_dp/, a(232)/0.007096470791153_dp/\n data x(233)/0.968326828463264_dp/, a(233)/0.008126876925698_dp/\n data x(234)/0.959688291448742_dp/, a(234)/0.009148671230783_dp/\n data x(235)/0.950032717784437_dp/, a(235)/0.010160770535008_dp/\n data x(236)/0.939370339752755_dp/, a(236)/0.011162102099838_dp/\n data x(237)/0.927712456722308_dp/, a(237)/0.012151604671088_dp/\n data x(238)/0.915071423120898_dp/, a(238)/0.013128229566961_dp/\n data x(239)/0.901460635315852_dp/, a(239)/0.014090941772314_dp/\n data x(240)/0.886894517402420_dp/, a(240)/0.015038721026994_dp/\n data x(241)/0.871388505909296_dp/, a(241)/0.015970562902562_dp/\n data x(242)/0.854959033434601_dp/, a(242)/0.016885479864245_dp/\n data x(243)/0.837623511228187_dp/, a(243)/0.017782502316045_dp/\n data x(244)/0.819400310737931_dp/, a(244)/0.018660679627411_dp/\n data x(245)/0.800308744139140_dp/, a(245)/0.019519081140145_dp/\n data x(246)/0.780369043867433_dp/, a(246)/0.020356797154333_dp/\n data x(247)/0.759602341176647_dp/, a(247)/0.021172939892191_dp/\n data x(248)/0.738030643744400_dp/, a(248)/0.021966644438744_dp/\n data x(249)/0.715676812348967_dp/, a(249)/0.022737069658329_dp/\n data x(250)/0.692564536642171_dp/, a(250)/0.023483399085926_dp/\n data x(251)/0.668718310043916_dp/, a(251)/0.024204841792364_dp/\n data x(252)/0.644163403784967_dp/, a(252)/0.024900633222483_dp/\n data x(253)/0.618925840125468_dp/, a(253)/0.025570036005349_dp/\n data x(254)/0.593032364777572_dp/, a(254)/0.026212340735672_dp/\n data x(255)/0.566510418561397_dp/, a(255)/0.026826866725591_dp/\n data x(256)/0.539388108324357_dp/, a(256)/0.027412962726029_dp/\n data x(257)/0.511694177154667_dp/, a(257)/0.027970007616848_dp/\n data x(258)/0.483457973920596_dp/, a(258)/0.028497411065085_dp/\n data x(259)/0.454709422167743_dp/, a(259)/0.028994614150555_dp/\n data x(260)/0.425478988407300_dp/, a(260)/0.029461089958167_dp/\n data x(261)/0.395797649828908_dp/, a(261)/0.029896344136328_dp/\n data x(262)/0.365696861472313_dp/, a(262)/0.030299915420827_dp/\n data x(263)/0.335208522892625_dp/, a(263)/0.030671376123669_dp/\n data x(264)/0.304364944354496_dp/, a(264)/0.031010332586313_dp/\n data x(265)/0.273198812591049_dp/, a(265)/0.031316425596861_dp/\n data x(266)/0.241743156163840_dp/, a(266)/0.031589330770727_dp/\n data x(267)/0.210031310460567_dp/, a(267)/0.031828758894411_dp/\n data x(268)/0.178096882367618_dp/, a(268)/0.032034456231992_dp/\n data x(269)/0.145973714654896_dp/, a(269)/0.032206204794030_dp/\n data x(270)/0.113695850110665_dp/, a(270)/0.032343822568575_dp/\n data x(271)/0.081297495464425_dp/, a(271)/0.032447163714064_dp/\n data x(272)/0.048812985136049_dp/, a(272)/0.032516118713868_dp/\n data x(273)/0.016276744849602_dp/, a(273)/0.032550614492363_dp/\n !\n do i=1,273\n b(i) = a(i)\n y(i) = x(i)\n end do\n do i=1,96\n ltab(i) = ktab(i)\n end do\n !\n end subroutine set_gauss_zeros_aux\n !\n !\n function spherical_Bessel_jL(L,x) result(value)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the value of the spherical Bessel function j_L(x) = sqrt(pi/2x) J_(L+1/2) (x) for real values of x by \n ! calling a proper function from the NAG library.\n !\n ! Call(s): nag_s17def() [from NAG library].\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: L\n real(kind=qp), intent(in) :: x\n !\n integer :: nz\n real(kind=dp) :: nu, value, test\n complex(kind=qp) :: zz\n complex(kind=qp), dimension(1) :: cy\n !\n value = one\n !\n if (rabs_use_naglib .and. x < 30000.0_dp .and. .false.) then\n nu = L + half \n zz = cmplx(x,zero,kind=qp)\n\t print *, \"nu, zz = \",nu, zz\n call nag_s17def(nu,zz,1,\"s\",cy(1),nz,ifail)\n !!x print *, \"Bessel, L, x, cy = \", L, x, cy\n !\n if (ifail /= 0 .or. nz /= 0) then\n print *, \"spherical_Bessel_jL(): program stop A.\"\n end if\n !\n value = sqrt( pi/(two*x) ) * cy(1)\n !\n ! Return here in all standard calculations\n return\n end if\n !\n ! Calculate directly\n select case(L)\n case(0)\n if (x < 1.0e-3) then\n test = one - x*x/6.0_dp + x**4/120.0_dp - x**6/5040.0_dp\n else\n test = sin(x) / x\n end if\n case(1)\n if (x < 1.0e-3) then\n test = x/three - x*x*x/30.0_dp + x**5/840.0_dp - x**7/45360.0_dp\n else\n test = sin(x) / (x*x) - cos(x)/x\n end if\n case(2)\n if (x < 1.0e-2) then\n test = x*x/15.0_dp - x**4/210.0_dp + x**6/7560.0_dp - x**8/498960.0_dp\n else\n test = three*sin(x)/(x**3) - three*cos(x)/(x*x) - sin(x)/x\n end if\n case(3)\n if (x < 9.0e-2) then\n test = x**3/105.0_dp - x**5/1890.0_dp + x**7/83160.0_dp - x**9/6486480.0_dp\n else\n test = cos(x)/x - 6.0_dp*sin(x)/(x*x) - 15.0_dp*cos(x)/(x**3) + 15.0_dp*sin(x)/(x**4)\n end if\n case(4)\n if (x < 3.0e-1) then\n test = x**4/945.0_dp - x**6/20790.0_dp + x**8/1081080.0_dp - x**10/97297200.0_dp\n else\n test = sin(x)/x + 10.0_dp*cos(x)/(x*x) - 45.0_dp*sin(x)/(x**3) - 105.0_dp*cos(x)/(x**4) + 105.0_dp*sin(x)/(x**5) \n end if\n case(5)\n if (x < 8.0e-1) then\n test = x**5/10395.0_dp - x**7/270270.0_dp + x**9/16216200.0_dp - x**11/1654052400.0_dp\n else\n test = -cos(x)/x + 15.0_dp*sin(x)/(x*x) + 105.0_dp*cos(x)/(x**3) - &\n 420.0_dp*sin(x)/(x**4) - 945.0_dp*cos(x)/(x**5) + 945.0_dp*sin(x)/(x**6)\n end if\n case default\n stop \"spherical_Bessel_jL():\"\n end select\n !\n value = test\n !\n !! ! Compare results\n !! if (abs((value - test)/value) > 1.0e-6_dp) then\n !! print *, \"spherical_Bessel_jL(): L, x, nag, direct = \", L, x, value, test\n !! end if\n !\n end function spherical_Bessel_jL\n !\n !\n function spherical_Bessel_jL_old(L,x) result(value)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the value of the spherical Bessel function j_L(x) = sqrt(pi/2x) J_(L+1/2) (x) for real values of x by calling\n ! a proper function from the NAG library.\n !\n ! Call(s): nag_s17def() [from NAG library].\n !--------------------------------------------------------------------------------------------------------------------\n !\n integer, intent(in) :: L\n real(kind=dp), intent(in) :: x\n !\n integer :: nz\n real(kind=dp) :: value, test\n complex*16 :: zz, cy\n character*1 :: scale\n DOUBLE PRECISION :: nu\n !\n if (rabs_use_naglib .and. x < 30000.0_dp) then\n scale = \"s\"\n nu = L + half\n zz = cmplx(x,zero,kind=dp)\n\t !\n\t !! print *, \"a:: nu,zz,1,scale,cy,nz,ifail = \", nu,zz,1,scale,cy,nz,ifail\n call nag_s17def(nu,zz,1,scale,cy,nz,ifail)\n !\n if (ifail /= 0 .or. nz /= 0) then\n print *, \"spherical_Bessel_jL(): program stop A.\"\n end if\n !\n value = sqrt( pi/(two*x) ) * cy\n !\n ! Return here in all standard calculations\n return\n end if\n !\n ! Calculate directly\n select case(L)\n case(0)\n if (x < 1.0e-3) then\n test = one - x*x/6.0_dp + x**4/120.0_dp - x**6/5040.0_dp\n else\n test = sin(x) / x\n end if\n case(1)\n if (x < 1.0e-3) then\n test = x/three - x*x*x/30.0_dp + x**5/840.0_dp - x**7/45360.0_dp\n else\n test = sin(x) / (x*x) - cos(x)/x\n end if\n case(2)\n if (x < 1.0e-2) then\n test = x*x/15.0_dp - x**4/210.0_dp + x**6/7560.0_dp - x**8/498960.0_dp\n else\n test = three*sin(x)/(x**3) - three*cos(x)/(x*x) - sin(x)/x\n end if\n case(3)\n if (x < 9.0e-2) then\n test = x**3/105.0_dp - x**5/1890.0_dp + x**7/83160.0_dp - &\n x**9/6486480.0_dp\n else\n test = cos(x)/x - 6.0_dp*sin(x)/(x*x) - 15.0_dp*cos(x)/(x**3) + 15.0_dp*sin(x)/(x**4)\n end if\n case(4)\n if (x < 3.0e-1) then\n test = x**4/945.0_dp - x**6/20790.0_dp + x**8/1081080.0_dp - x**10/97297200.0_dp\n else\n test = sin(x)/x + 10.0_dp*cos(x)/(x*x) - 45.0_dp*sin(x)/(x**3) - 105.0_dp*cos(x)/(x**4) + 105.0_dp*sin(x)/(x**5) \n end if\n case(5)\n if (x < 8.0e-1) then\n test = x**5/10395.0_dp - x**7/270270.0_dp + x**9/16216200.0_dp - x**11/1654052400.0_dp\n else\n test = -cos(x)/x + 15.0_dp*sin(x)/(x*x) + 105.0_dp*cos(x)/(x**3) - &\n 420.0_dp*sin(x)/(x**4) - 945.0_dp*cos(x)/(x**5) + 945.0_dp*sin(x)/(x**6)\n end if\n case default\n stop \"spherical_Bessel_jL():\"\n end select\n !\n !! print *, \"Bessel, L, x, test = \", L, x, test\n !\n !! ! Compare results\n !! if (abs((value - test)/value) > 1.0e-6_dp) then\n !! print *, \"spherical_Bessel_jL(): L, x, nag, direct = \", L, x, value, test\n !! end if\n !\n end function spherical_Bessel_jL_old\n !\n !\n function spherical_Legendre_Pmn(m,n,x) result(value)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the value of the spherical (associated) Legendre function P^m_n(x) as given in terms of the Gauss' \n ! hypergeometric function F(a,b,c;x) for real parameters a, b, c and real values of x.\n !\n ! Call(s): hypergeometric_2F1, nag_s14aaf (from NAG-Libarary).\n !--------------------------------------------------------------------------------------------------------------------\n !\n real(kind=dp), intent(in) :: m, n, x\n real(kind=dp) :: value\n !\n if (rabs_use_stop .and. x == 0) then\n stop \"spherical_Legendre_Pmn(): program stop A.\"\n end if\n !\n if (rabs_use_naglib) then\n value = ((1+x)/(1-x))**(m*half) / nag_s14aaf(1-m,ifail) * hypergeometric_2F1(-n,n+1,1-m,half*(one-x))\n else if (rabs_use_stop) then\n stop \"spherical_Legendre_Pmn(): program stop B.\"\n end if\n !\n end function spherical_Legendre_Pmn\n !\n !\n subroutine transform_cart_to_cylinder(x,y,z,rho,phi,zc)\n !--------------------------------------------------------------------------------------------------------------------\n ! This subprogram transforms the cartesian coordinates (x,y,z) into cylindrical coordinates (rho,phi,z). It terminates \n ! with a proper message if r = zero.\n !--------------------------------------------------------------------------------------------------------------------\n !\n real(kind=dp), intent(in) :: x, y, z\n real(kind=dp), intent(out) :: rho, phi, zc\n !\n real(kind=dp) :: xn\n intrinsic sqrt, atan\n !\n rho = sqrt( x*x + y*y )\n if (rabs_use_stop .and. rho <= zero) then\n stop \"transform_cart_to_cylinder(): program stop A.\"\n end if\n !\n if (x == zero) then\n xn = 1.0e-99_dp\n print *, \"transform_cart_to_cylinder(): x, xn = \", x, xn\n else\n xn = x\n end if\n phi = atan(y/xn)\n !\n zc = z\n !\n end subroutine transform_cart_to_cylinder\n !\n !\n subroutine transform_cart_to_spherical(x,y,z,r,theta,phi)\n !--------------------------------------------------------------------------------------------------------------------\n ! This subprogram transforms the cartesian coordinates (x,y,z) into spherical coordinates (r,theta,phi). It terminates \n ! with a proper message if r = zero.\n !--------------------------------------------------------------------------------------------------------------------\n !\n real(kind=dp), intent(in) :: x, y, z\n real(kind=dp), intent(out) :: r,theta,phi\n !\n real(kind=dp) :: xn\n intrinsic sqrt, atan, acos\n !\n r = sqrt( x*x + y*y + z*z )\n if (rabs_use_stop .and. r <= zero) then\n stop \"transform_cart_to_spherical(): program stop A.\"\n end if\n !\n if (x == zero) then\n xn = 1.0e-99_dp\n print *, \"xn = \",xn\n else\n xn = x\n end if\n phi = atan(y/xn)\n !\n theta = acos( z/r )\n !\n end subroutine transform_cart_to_spherical\n !\n !\n subroutine transform_cylinder_to_cart(rho,phi,zc,x,y,z)\n !--------------------------------------------------------------------------------------------------------------------\n ! This subprogram transforms the cylindrical coordinates (rho,phi,z) into cartesian coordinates (x,y,z). \n !--------------------------------------------------------------------------------------------------------------------\n !\n real(kind=dp), intent(in) :: rho, phi, zc\n real(kind=dp), intent(out) :: x, y, z\n !\n intrinsic sin, cos\n !\n x = rho * cos(phi)\n y = rho * sin(phi)\n z = zc\n !\n end subroutine transform_cylinder_to_cart\n !\n !\n subroutine transform_spherical_to_cart(r,theta,phi,x,y,z)\n !--------------------------------------------------------------------------------------------------------------------\n ! This subprogram transforms the spherical coordinates (r,theta,phi) into cartesian coordinates (x,y,z). \n !--------------------------------------------------------------------------------------------------------------------\n !\n real(kind=dp), intent(in) :: r,theta,phi\n real(kind=dp), intent(out) :: x, y, z\n !\n intrinsic sin, cos\n !\n x = r * sin(theta) * cos(phi)\n y = r * sin(theta) * sin(phi)\n z = r * cos(theta)\n !\n end subroutine transform_spherical_to_cart\n !\n !\n function Whittaker_M(a,b,x) result(value)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the value of the Whittaker function M_a,b(x) for real parameters a and b and for real argument of x. \n !\n ! Calls: hypergeometric_Phi().\n !--------------------------------------------------------------------------------------------------------------------\n !\n real(kind=dp), intent(in) :: a, b, x\n real(kind=dp) :: value\n !\n value = x**(b+half) * exp(-x*half) * hypergeometric_Phi(b-a+half,b+b+1,x)\n !\n end function Whittaker_M\n !\n !\n function Whittaker_W(a,b,x) result(value)\n !--------------------------------------------------------------------------------------------------------------------\n ! Returns the value of the Whittaker function W_a,b(x) for real parameters a and b and for real argument of x. \n !\n ! Calls: nag_s14aaf() [from NAG], Whittaker_M().\n !--------------------------------------------------------------------------------------------------------------------\n !\n real(kind=dp), intent(in) :: a, b, x\n real(kind=dp) :: value\n !! real(kind=dp) :: value, nag_s14aaf\n !\n print *, \"WARNING: function Whittaker_W() has not been tested.\"\n print *, \"WARNING: function Whittaker_W() has not been tested.\"\n !\n if (rabs_use_naglib) then\n value = nag_s14aaf(-b-b,ifail) / nag_s14aaf(half-b-a,ifail) * Whittaker_M(a,b,x) + &\n nag_s14aaf( b+b,ifail) / nag_s14aaf(half+b-a,ifail) * Whittaker_M(a,-b,x)\n else if (rabs_use_stop) then\n stop \"Whittaker_W(): program stop A.\"\n end if\n !\n end function Whittaker_W\n !\nend module rabs_functions_math\n", "meta": {"hexsha": "b586b49bc117fed2509fb1ed7d70cd0b696182ff", "size": 92688, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "deps/ratip2013-angular-coefficients/rabs_functions_math.f90", "max_stars_repo_name": "mfherbst/JAC.jl", "max_stars_repo_head_hexsha": "43563c049a995817ada86ce82908714d4e1a034b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-07-15T11:27:51.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-15T11:27:51.000Z", "max_issues_repo_path": "deps/ratip2013-angular-coefficients/rabs_functions_math.f90", "max_issues_repo_name": "mfherbst/JAC.jl", "max_issues_repo_head_hexsha": "43563c049a995817ada86ce82908714d4e1a034b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "deps/ratip2013-angular-coefficients/rabs_functions_math.f90", "max_forks_repo_name": "mfherbst/JAC.jl", "max_forks_repo_head_hexsha": "43563c049a995817ada86ce82908714d4e1a034b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-30T13:09:52.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-30T13:09:52.000Z", "avg_line_length": 43.6178823529, "max_line_length": 127, "alphanum_fraction": 0.4933001036, "num_tokens": 28106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611631680359, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7566985195439916}} {"text": " program demo_abs\n implicit none\n integer :: i = -1\n real :: x = -1.0\n complex :: z = (-3.0,-4.0)\n doubleprecision :: rr = -45.78d+00\n character(len=*),parameter :: &\n frmt = '(1x,a15,1x,\" In: \",g0, T51,\" Out: \",g0)', &\n frmtc = '(1x,a15,1x,\" In: (\",g0,\",\",g0,\")\",T51,\" Out: \",g0)'\n integer,parameter :: dp=kind(0.0d0)\n integer,parameter :: sp=kind(0.0)\n\n write(*, frmt) 'integer ', i, abs(i)\n write(*, frmt) 'real ', x, abs(x)\n write(*, frmt) 'doubleprecision ', rr, abs(rr)\n write(*, frmtc) 'complex ', z, abs(z)\n !\n !\n write(*, *)\n write(*, *) 'abs is elemental: ', abs([20, 0, -1, -3, 100])\n write(*, *)\n write(*, *) 'abs range test : ', abs(huge(0)), abs(-huge(0))\n write(*, *) 'abs range test : ', abs(huge(0.0)), abs(-huge(0.0))\n write(*, *) 'abs range test : ', abs(tiny(0.0)), abs(-tiny(0.0))\n\n write(*, *) 'returned real kind:', cmplx(30.0_dp,40.0_dp,kind=dp), &\n kind(cmplx(30.0_dp,40.0_dp,kind=dp))\n write(*, *) 'returned real kind:', cmplx(30.0_dp,40.0_dp),&\n kind(cmplx(30.0_dp,40.0_dp))\n write(*, *) 'returned real kind:', cmplx(30.0_sp,40.0_sp),&\n kind(cmplx(30.0_sp,40.0_sp))\n\n write(*, *)\n write(*, *) 'distance of from zero is', &\n & distance(30.0_dp,40.0_dp)\n\n contains\n\n real(kind=dp) elemental function distance(x,y)\n real(kind=dp),intent(in) :: x,y\n ! dusty corners:\n ! note that KIND=DP is NOT optional\n ! if the desired result is KIND=dp.\n ! See cmplx(3).\n distance=abs( cmplx(x,y,kind=dp) )\n end function distance\n end program demo_abs\n", "meta": {"hexsha": "342d819637e63ff74b18f1f3c72db2318a748a34", "size": 1918, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/abs.f90", "max_stars_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_stars_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-12-31T17:21:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T15:56:29.000Z", "max_issues_repo_path": "example/abs.f90", "max_issues_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_issues_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/abs.f90", "max_forks_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_forks_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-06T15:56:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-06T15:56:31.000Z", "avg_line_length": 39.9583333333, "max_line_length": 76, "alphanum_fraction": 0.4572471324, "num_tokens": 606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254318, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.7566060179119031}} {"text": "subroutine MakeEllipseCoord(coord, lat, lon, dec, A_theta, B_theta, cinterval, cnum)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis subroutine will return the latitude and longitude\n!\tcoordinates of an ellipse with semi-major and semi-minor axes \n!\tA_theta and B_theta (in degrees) at postition LAT and LON (in degrees)\n!\tand with a clockwise rotation of the semi-major axis DEC with respect\n!\tto local north (in degrees).\n!\n!\tCalling Parameters:\n!\t\tIN\n!\t\t\tlat, lon:\tLatitude and longitude in degrees.\n!\t\t\tA_theta:\tAngular radius of the semi-major axis in degrees.\n!\t\t\tB_theta:\tAngular radius of the semi-minor axis in degrees.\n!\t\t\tdec:\t\tClockwise rotation of the semi-major axis with \n!\t\t\t\t\trespect to local north in degrees.\n!\t\tOUT\n!\t\t\tcoord:\t\t360/interval (latitude, longitude) coordinates.\n!\t\tOPTIONAL, IN\n!\t\t\tcinterval:\tAngular spacing of latitude and longitude points\n!\t\t\t\t\tin degrees (default=1).\n!\n!\tDependencies: None\n!\n!\tWritten by Mark Wieczorek March 2010.\n!\n!\tCopyright (c) 2010, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\treal*8, intent(in) ::\tlat, lon, A_theta, B_theta, dec\n\treal*8, intent(out) :: coord(:,:)\n\treal*8, intent(in), optional ::\tcinterval\n\tinteger, intent(out), optional :: cnum\n\t\n\treal*8 :: pi, interval, xold, yold, zold, x, y, z, x1, phi, r\n\tinteger :: k, num\n\t\n\tif (present(cinterval)) then\n\t\tinterval = cinterval\n\telse\n\t\tinterval = 1.0d0\n\tendif\n\t\n\tnum = 360.0d0/interval\n\t\n\tif (present(cnum)) then\n\t\tcnum = num\n\tendif\n\t\n\tif (size(coord(:,1)) < num .or. size(coord(1,:)) < 2) then\n\t\tprint*, \"Error --- MakeEllipseCoord\"\n\t\tprint*, \"COORD must be dimensioned as (NUM, 2) where NUM is \", NUM\n\t\tprint*, \"Input array is dimensioned as \", size(coord(:,1)), size(coord(1,:))\n\t\tstop\n\tendif\n\t\n\tpi = acos(-1.0d0)\n\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t!\tCalculate grid points. First create a cirlce, then rotate these\n\t!\tpoints.\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\t\n\tdo k=1, num\n\t\tphi = dble(k-1)*(2.0d0*pi/dble(num))\n\t\tr = a_theta*b_theta / sqrt( (b_theta*cos(phi))**2 + (a_theta*sin(phi))**2 ) \n\t\txold = sin(r*pi/180.0d0)*cos(phi - dec*pi/180.0d0)\n\t\tyold = sin(r*pi/180.0d0)*sin(phi - dec*pi/180.0d0)\n\t\tzold = cos(r*pi/180.0d0)\n\t\t\n\t\t! rotate coordinate system 90-lat degrees about y axis\n\t\t\t\n\t\tx1 = xold*cos(pi/2.0-lat*pi/180.0d0) + zold*sin(pi/2.0-lat*pi/180.0d0)\n\t\tz = -xold*sin(pi/2.0-lat*pi/180.0d0) + zold*cos(pi/2.0-lat*pi/180.0d0)\n\n\t\t! rotate coordinate system lon degrees about z axis\n\t\t\t\n\t\tx = x1*cos(lon*pi/180.0d0) - yold*sin(lon*pi/180.0d0)\n\t\ty = x1*sin(lon*pi/180.0d0) + yold*cos(lon*pi/180.0d0)\n\t\t\n\t\tcoord(k,1) = (pi/2.0d0 - acos(z/sqrt(x**2+y**2+z**2)) ) * 180.0d0/pi\n\t\tcoord(k,2) = atan2(y, x) * 180.0d0/pi\n\n\tenddo\n\t\t\n\t\nend subroutine MakeEllipseCoord\n\n", "meta": {"hexsha": "494202785d5dca5cd344818b0d877dc5c796c1a3", "size": 2939, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/MakeEllipseCoord.f95", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "spherical_splines/SHTOOLS/src/MakeEllipseCoord.f95", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "spherical_splines/SHTOOLS/src/MakeEllipseCoord.f95", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 31.6021505376, "max_line_length": 84, "alphanum_fraction": 0.5916978564, "num_tokens": 961, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850075259039, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7565812192865236}} {"text": "! streeter.f90 --\n! Module to compute the minimum oxygen concentration\n! Belongs to the example.tbl file\n!\nmodule streeter_phelps\ncontains\n\n! compute_min_oxygen --\n! Compute the minimum oxygen concentration based on the\n! Streeter-Phelps BOD-DO model\n!\n! Arguments:\n! bod Initial BOD concentration (mg O2/l)\n! oxy Initial oxygen (DO) concentration (mg O2/l)\n! k Decay coefficient BOD (1/day)\n! ka Reaeration coefficient oxygen (m/day)\n! h Depth of the river (m)\n! oxysat Oxygen saturation concentration (mg O2/l)\n! dt Timestep (day)\n! oxymin Minimum oxygen concentration (mg O2/l; output)\n! time Time at which it occurs (day; output)\n!\n! Note:\n! Error conditions: k <= 0, ka <= 0, dt <= 0. Then oxymin and time\n! are set to -999.0\n!\nsubroutine compute_min_oxygen( bod, oxy, k, ka, h, oxysat, dt, oxymin, time )\n real, intent(in) :: bod\n real, intent(in) :: oxy\n real, intent(in) :: k\n real, intent(in) :: ka\n real, intent(in) :: h\n real, intent(in) :: oxysat\n real, intent(in) :: dt\n real, intent(out) :: oxymin\n real, intent(out) :: time\n\n real :: timemax\n real :: t\n real :: dbod\n real :: doxy\n real :: bodn\n real :: oxyn\n\n if ( k <= 0.0 .or. ka <= .0 .or. dt <= 0.0 ) then\n time = -999.0\n oxymin = -999.0\n return\n endif\n\n oxymin = oxy\n time = 0.0\n\n bodn = bod\n oxyn = oxy\n\n timemax = 10.0 / k ! More than safe time interval\n\n do while ( t < timemax )\n dbod = -k * bodn\n doxy = -k * bodn + ka * ( oxysat - oxyn ) / h\n\n t = t + dt\n bodn = bodn + dbod *dt\n oxyn = oxyn + doxy *dt\n\n if ( oxyn < oxymin ) then\n oxymin = oxyn\n time = t\n endif\n enddo\n\nend subroutine compute_min_oxygen\nend module streeter_phelps\n", "meta": {"hexsha": "7d9f53a5bb039c32d0485a770ce6e619d9d39ae3", "size": 2045, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/funit/streeter.f90", "max_stars_repo_name": "timcera/flibs_from_svn", "max_stars_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 828, "max_stars_repo_stars_event_min_datetime": "2016-06-20T15:08:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:32:10.000Z", "max_issues_repo_path": "flibs-0.9/flibs/tests/funit/streeter.f90", "max_issues_repo_name": "TerribleDev/Fortran-docker-mvc", "max_issues_repo_head_hexsha": "0f44d444d9bcc6f4a6c6c59cc53b684c7b9a8e1a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2016-06-27T05:52:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-29T20:08:05.000Z", "max_forks_repo_path": "flibs-0.9/flibs/tests/funit/streeter.f90", "max_forks_repo_name": "TerribleDev/Fortran-docker-mvc", "max_forks_repo_head_hexsha": "0f44d444d9bcc6f4a6c6c59cc53b684c7b9a8e1a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2016-06-21T02:15:50.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T06:32:39.000Z", "avg_line_length": 27.2666666667, "max_line_length": 77, "alphanum_fraction": 0.5188264059, "num_tokens": 611, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7565259944536898}} {"text": "***********************************************************************\n* KMPP - K-Means++ - Traditional data clustering with a special initialization\n* Public Domain - This program may be used by any person for any purpose.\n*\n* Origin:\n* Hugo Steinhaus, 1956\n*\n* Refer to:\n* \"kmeans++: the advantages of careful seeding\"\n* David Arthur and Sergei Vassilvitskii\n* Proceedings of the eighteenth annual ACM-SIAM symposium\n* on Discrete algorithms, 2007\n*\n*____Variable_______I/O_______Description___________________Type_______\n* X(P,N) In Data points Real\n* P In Dimension of the data Integer\n* N In Number of points Integer\n* K In # clusters Integer\n* C(P,K) Out Center points of clusters Real\n* Z(N) Out What cluster a point is in Integer\n* WORK(N) Neither Real\n* IFAULT Out Error code Integer\n************************************************************************\n SUBROUTINE KMPP (X, P, N, K, C, Z, WORK, IFAULT)\n\n IMPLICIT NONE\n INTEGER P, N, K, Z, IFAULT\n REAL X, C, WORK\n DIMENSION X(P,N), C(P,K), Z(N), WORK(N)\n\n* constants\n INTEGER ITER ! maximum iterations\n REAL BIG ! arbitrary large number\n PARAMETER (ITER = 1000,\n $ BIG = 1E33)\n\n* local variables\n INTEGER\n $ H, ! count iterations\n $ I, ! count points\n $ I1, ! point marked as initial center\n $ J, ! count dimensions\n $ L, ! count clusters\n $ L0, ! present cluster ID\n $ L1 ! new cluster ID\n\n REAL\n $ BEST, ! shortest distance to a center\n $ D2, ! squared distance\n $ TOT, ! a total\n $ W ! temp scalar\n\n LOGICAL CHANGE ! whether any points have been reassigned\n\n************************************************************************\n* Begin.\n************************************************************************\n IFAULT = 0\n IF (K < 1 .OR. K > N) THEN ! K out of bounds\n IFAULT = 3\n RETURN\n END IF\n DO I = 1, N ! clear Z\n Z(I) = 0\n END DO\n\n************************************************************************\n* initial centers\n************************************************************************\n DO I = 1, N\n WORK(I) = BIG\n END DO\n\n CALL RANDOM_NUMBER (W)\n I1 = MIN(INT(W * FLOAT(N)) + 1, N) ! choose first center at random\n DO J = 1, P\n C(J,1) = X(J,I1)\n END DO\n\n DO L = 2, K ! initialize other centers\n TOT = 0.\n DO I = 1, N ! measure from each point\n BEST = WORK(I)\n D2 = 0. ! to prior center\n DO J = 1, P\n D2 = D2 + (X(J,I) - C(J,L-1)) **2 ! Squared Euclidean distance\n IF (D2 .GE. BEST) GO TO 10 ! needless to add to D2\n END DO ! next J\n IF (D2 < BEST) BEST = D2 ! shortest squared distance\n WORK(I) = BEST\n 10 TOT = TOT + BEST ! cumulative squared distance\n END DO ! next data point\n\n************************************************************************\n* Choose center with probability proportional to its squared distance\n* from existing centers.\n************************************************************************\n CALL RANDOM_NUMBER (W)\n W = W * TOT ! uniform at random over cumulative distance\n TOT = 0.\n DO I = 1, N\n I1 = I\n TOT = TOT + WORK(I)\n IF (TOT > W) GO TO 20\n END DO ! next I\n 20 CONTINUE\n DO J = 1, P ! assign center\n C(J,L) = X(J,I1)\n END DO\n END DO ! next center to initialize\n\n************************************************************************\n* main loop\n************************************************************************\n DO H = 1, ITER\n CHANGE = .FALSE.\n\n* find nearest center for each point\n DO I = 1, N\n L0 = Z(I)\n L1 = 0\n BEST = BIG\n DO L = 1, K\n D2 = 0.\n DO J = 1, P\n D2 = D2 + (X(J,I) - C(J,L)) **2\n IF (D2 .GE. BEST) GO TO 30\n END DO\n 30 CONTINUE\n IF (D2 < BEST) THEN ! new nearest center\n BEST = D2\n L1 = L\n END IF\n END DO ! next L\n\n IF (L0 .NE. L1) THEN\n Z(I) = L1 ! reassign point\n CHANGE = .TRUE.\n END IF\n END DO ! next I\n IF (.NOT. CHANGE) RETURN ! success\n\n************************************************************************\n* find cluster centers\n************************************************************************\n DO L = 1, K ! zero population\n WORK(L) = 0.\n END DO\n DO L = 1, K ! zero centers\n DO J = 1, P\n C(J,L) = 0.\n END DO\n END DO\n\n DO I = 1, N\n L = Z(I)\n WORK(L) = WORK(L) + 1. ! count\n DO J = 1, P\n C(J,L) = C(J,L) + X(J,I) ! add\n END DO\n END DO\n\n DO L = 1, K\n IF (WORK(L) < 0.5) THEN ! empty cluster check\n IFAULT = 1 ! fatal error\n RETURN\n END IF\n W = 1. / WORK(L)\n DO J = 1, P\n C(J,L) = C(J,L) * W ! multiplication is faster than division\n END DO\n END DO\n\n END DO ! next H\n IFAULT = 2 ! too many iterations\n RETURN\n\n END ! of KMPP\n\n\n************************************************************************\n* test program (extra credit #1)\n************************************************************************\n PROGRAM TPEC1\n IMPLICIT NONE\n INTEGER N, P, K\n REAL TWOPI\n PARAMETER (N = 30 000,\n $ P = 2,\n $ K = 6,\n $ TWOPI = 6.2831853)\n INTEGER I, L, Z(N), IFAULT\n REAL X(P,N), C(P,K), R, THETA, W, WORK(N)\n\n* Begin\n CALL RANDOM_SEED()\n DO I = 1, N ! random points over unit circle\n CALL RANDOM_NUMBER (W)\n R = SQRT(W) ! radius\n CALL RANDOM_NUMBER (W)\n THETA = W * TWOPI ! angle\n X(1,I) = R * COS(THETA) ! Cartesian coordinates\n X(2,I) = R * SIN(THETA)\n END DO\n\n* Call subroutine\n CALL KMPP (X, P, N, K, C, Z, WORK, IFAULT)\n PRINT *, 'kmpp returns with error code ', IFAULT\n\n* Print lists of points in each cluster\n DO L = 1, K\n PRINT *, 'Cluster ', L, ' contains points: '\n 10 FORMAT (I6, $)\n 20 FORMAT ()\n DO I = 1, N\n IF (Z(I) .EQ. L) PRINT 10, I\n END DO\n PRINT 20\n END DO\n\n* Write CSV file with Y-coordinates in different columns by cluster\n OPEN (UNIT=1, FILE='tpec1.csv', STATUS='NEW', IOSTAT=IFAULT)\n IF (IFAULT .NE. 0) PRINT *, 'tpec1: trouble opening file'\n 30 FORMAT (F8.4, $)\n 40 FORMAT (',', $)\n 50 FORMAT (F8.4)\n DO I = 1, N\n WRITE (UNIT=1, FMT=30, IOSTAT=IFAULT) X(1,I)\n IF (IFAULT .NE. 0) PRINT *, 'tpec1: trouble writing X-coord'\n DO L = 1, Z(I) ! one comma per cluster ID\n WRITE (UNIT=1, FMT=40, IOSTAT=IFAULT)\n IF (IFAULT .NE. 0) PRINT *, 'tpec1: trouble writing comma'\n END DO\n WRITE (UNIT=1, FMT=50, IOSTAT=IFAULT) X(2,I)\n IF (IFAULT .NE. 0) PRINT *, 'tpec1: trouble writing Y-coord'\n END DO\n\n* Write the centroids in the far column\n DO L = 1, K\n WRITE (UNIT=1, FMT=30, IOSTAT=IFAULT) C(1,L)\n IF (IFAULT .NE. 0) PRINT *, 'tpec1: trouble writing X-coord'\n DO I = 1, K+1\n WRITE (UNIT=1, FMT=40, IOSTAT=IFAULT)\n IF (IFAULT .NE. 0) PRINT *, 'tpec1: trouble writing comma'\n END DO\n WRITE (UNIT=1, FMT=50, IOSTAT=IFAULT) C(2,L)\n IF (IFAULT .NE. 0) PRINT *, 'tpec1: trouble writing Y-coord'\n END DO\n CLOSE (UNIT=1)\n\n END ! of test program\n", "meta": {"hexsha": "9471aabd0114294c869f832b900990bf5abc7628", "size": 8977, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/K-means++-clustering/Fortran/k-means++-clustering.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/K-means++-clustering/Fortran/k-means++-clustering.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/K-means++-clustering/Fortran/k-means++-clustering.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 35.623015873, "max_line_length": 78, "alphanum_fraction": 0.3839812855, "num_tokens": 2253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7565259807694553}} {"text": "!-------------------------------------------------------------------------------\n! Copyright (c) 2016 The University of Tokyo\n! This software is released under the MIT License, see LICENSE.txt\n!-------------------------------------------------------------------------------\n!> \\brief This module contains functions for interpolation in 4 node\n!! qudrilateral element (Langrange interpolation)\nmodule shape_quad4n\n integer, parameter, private :: kreal = kind(0.0d0)\n\ncontains\n subroutine ShapeFunc_quad4n(lcoord,func)\n real(kind=kreal), intent(in) :: lcoord(2)\n real(kind=kreal) :: func(4)\n func(1) = 0.25d0*(1.d0-lcoord(1))*(1.d0-lcoord(2))\n func(2) = 0.25d0*(1.d0+lcoord(1))*(1.d0-lcoord(2))\n func(3) = 0.25d0*(1.d0+lcoord(1))*(1.d0+lcoord(2))\n func(4) = 0.25d0*(1.d0-lcoord(1))*(1.d0+lcoord(2))\n end subroutine\n\n subroutine ShapeDeriv_quad4n(lcoord,func)\n real(kind=kreal), intent(in) :: lcoord(2)\n real(kind=kreal) :: func(4,2)\n func(1,1) = -0.25d0*(1.d0-lcoord(2))\n func(2,1) = 0.25d0*(1.d0-lcoord(2))\n func(3,1) = 0.25d0*(1.d0+lcoord(2))\n func(4,1) = -0.25d0*(1.d0+lcoord(2))\n\n func(1,2) = -0.25d0*(1.d0-lcoord(1))\n func(2,2) = -0.25d0*(1.d0+lcoord(1))\n func(3,2) = 0.25d0*(1.d0+lcoord(1))\n func(4,2) = 0.25d0*(1.d0-lcoord(1))\n end subroutine\n\n subroutine Shape2ndDeriv_quad4n(func)\n real(kind=kreal) :: func(4,2,2)\n func(:,1,1) = 0.d0\n func(1,1,2) = 0.25d0\n func(2,1,2) = -0.25d0\n func(3,1,2) = 0.25d0\n func(4,1,2) = -0.25d0\n\n func(1,2,1) = 0.25d0\n func(2,2,1) = -0.25d0\n func(3,2,1) = 0.25d0\n func(4,2,1) = -0.25d0\n func(:,2,2) = 0.d0\n end subroutine\n\n\n ! (Gaku Hashimoto, The University of Tokyo, 2012/11/15) <\n !####################################################################\n subroutine NodalNaturalCoord_quad4n(nncoord)\n !####################################################################\n\n implicit none\n\n !--------------------------------------------------------------------\n\n real(kind = kreal), intent(out) :: nncoord(4, 2)\n\n !--------------------------------------------------------------------\n\n ! xi-coordinate at a node in a local element\n nncoord(1, 1) = -1.0D0\n nncoord(2, 1) = 1.0D0\n nncoord(3, 1) = 1.0D0\n nncoord(4, 1) = -1.0D0\n ! eta-coordinate at a node in a local element\n nncoord(1, 2) = -1.0D0\n nncoord(2, 2) = -1.0D0\n nncoord(3, 2) = 1.0D0\n nncoord(4, 2) = 1.0D0\n\n !--------------------------------------------------------------------\n\n return\n\n !####################################################################\n end subroutine NodalNaturalCoord_quad4n\n !####################################################################\n ! > (Gaku Hashimoto, The University of Tokyo, 2012/11/15)\n\n\nend module\n", "meta": {"hexsha": "f768ede01177159c119d5f21c580dc142e6a9851", "size": 2797, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fistr1/src/lib/element/quad4n.f90", "max_stars_repo_name": "tkoyama010/FrontISTR", "max_stars_repo_head_hexsha": "2ce1f0425b87df76261c86ddb93bb4b588f72718", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fistr1/src/lib/element/quad4n.f90", "max_issues_repo_name": "tkoyama010/FrontISTR", "max_issues_repo_head_hexsha": "2ce1f0425b87df76261c86ddb93bb4b588f72718", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fistr1/src/lib/element/quad4n.f90", "max_forks_repo_name": "tkoyama010/FrontISTR", "max_forks_repo_head_hexsha": "2ce1f0425b87df76261c86ddb93bb4b588f72718", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.9058823529, "max_line_length": 80, "alphanum_fraction": 0.4637111191, "num_tokens": 960, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294984, "lm_q2_score": 0.81047890180374, "lm_q1q2_score": 0.7565259786329623}} {"text": "subroutine LeastSquaresBuildSystem(msamp,ndof,X,y,systemMat,systemRHS)\n use typre\n implicit none\n !See http://en.wikipedia.org/wiki/Linear_least_squares_(mathematics) for notation\n \n integer(ip) :: ndof,msamp\n \n real(rp) :: X(msamp,ndof), y(msamp)\n real(rp) :: systemMAT(ndof,ndof), systemRHS(ndof)\n \n write(*,*) 'before leastsquresbuild'\n systemMat = 0.0_rp\n systemRHS = 0.0_rp\n write(*,*) 'before leastsquresbuild2'\n call LeastSquaresAddToSystem(msamp,ndof,X,y,systemMat,systemRHS)\n write(*,*) 'after leastsquresbuild'\nend subroutine\n\nsubroutine LeastSquaresAddToSystem(msamp,ndof,X,y,systemMat,systemRHS)\n use typre\n implicit none\n !See http://en.wikipedia.org/wiki/Linear_least_squares_(mathematics) for notation\n \n integer(ip) :: ndof,msamp\n \n real(rp) :: X(msamp,ndof), y(msamp)\n real(rp) :: systemMAT(ndof,ndof), systemRHS(ndof)\n \n real(rp) :: XT(ndof,msamp)\n \n XT = transpose(X)\n \n systemMat = matmul(XT,X)\n systemRHS = matmul(XT,y)\nend subroutine", "meta": {"hexsha": "d0fc621b2100dd9a8845885d2c48855cb5cb6579", "size": 1015, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/mathru/LeastSquares.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/mathru/LeastSquares.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/mathru/LeastSquares.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.0, "max_line_length": 84, "alphanum_fraction": 0.6975369458, "num_tokens": 326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.756525974130309}} {"text": "\tsubroutine euler(angles,v)\n\n*\tRotates vector given wrt (i,j,k) through Euler angles (i,w,Omega).\n\n\timplicit real*8 (a-h,o-z)\n\treal*8 v(3),angles(3),B(3,3),temp(3)\n\n\tcosi=cos(angles(1))\n\tsini=sin(angles(1))\n\tcosw=cos(angles(2))\n\tsinw=sin(angles(2))\n\tcosOm=cos(angles(3))\n\tsinOm=sin(angles(3))\n\n B(1,1) = cosw*cosOm - sinw*cosi*sinOm\n B(1,2) = cosw*sinOm + sinw*cosi*cosOm\n B(1,3) = sinw*sini\n B(2,1) = -sinw*cosOm - cosw*cosi*sinOm\n B(2,2) = -sinw*sinOm + cosw*cosi*cosOm\n B(2,3) = cosw*sini\n B(3,1) = sini*sinOm\n B(3,2) = -sini*cosOm\n B(3,3) = cosi\n\n\tdo i=1,3\n\t sum=0\n\t sum2=0\n\t do j=1,3\n\t sum=sum + B(j,i)*v(j)\n\t enddo\n\t temp(i)=sum\n\tenddo\n\tdo i=1,3\n\t v(i)=temp(i)\n\tenddo\n\n\tend\n\n", "meta": {"hexsha": "6894af8d7d90c00216847ad5be0b2c3552f530f0", "size": 761, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/amuse/community/aarsethzare/src/euler.f", "max_stars_repo_name": "rknop/amuse", "max_stars_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 131, "max_stars_repo_stars_event_min_datetime": "2015-06-04T09:06:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-01T12:11:29.000Z", "max_issues_repo_path": "src/amuse/community/aarsethzare/src/euler.f", "max_issues_repo_name": "rknop/amuse", "max_issues_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 690, "max_issues_repo_issues_event_min_datetime": "2015-10-17T12:18:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:15:58.000Z", "max_forks_repo_path": "src/amuse/community/aarsethzare/src/euler.f", "max_forks_repo_name": "rieder/amuse", "max_forks_repo_head_hexsha": "3ac3b6b8f922643657279ddee5c8ab3fc0440d5e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 102, "max_forks_repo_forks_event_min_datetime": "2015-01-22T10:00:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-09T13:29:43.000Z", "avg_line_length": 19.5128205128, "max_line_length": 68, "alphanum_fraction": 0.5479632063, "num_tokens": 334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248242542283, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.7565086202895114}} {"text": " program fortran_newtons\n\n REAL :: x,v2,Psi,phi0\n REAL functionPhi\n REAL functionPhiDeri\n REAL functionNewtonsMethod\n\n x = 0.3\n v2 = 0.1\n Psi = 1.5\n phi0 = 3.0\n\n print *, 'function : ', functionPhi(x, v2, Psi, phi0)\n print *, 'functionDeri : ', functionPhiDeri(x, v2, Psi)\n\n ! need to implement the better guess here\n \n print *, 'newtonsMethod : ', functionNewtonsMethod(x, v2, \n * Psi, phi0)\n end\n\n ! phi = phi0 - v2 * sin[2(phi-Psi)]\n ! we need y = x + v2 * sin[2(x-Psi)] - phi0 = 0, where x is phi.\n FUNCTION functionPhi(x, v2, Psi, phi0)\n REAL x, v2, Psi, phi0\n functionPhi = ( x + v2*SIN(2*(x-Psi)) - phi0 )\n RETURN\n END FUNCTION\n\n ! y' = 1 + v2 * cos[2(x-Psi)]*2\n FUNCTION functionPhiDeri(x, v2, Psi)\n REAL x, v2, Psi\n functionPhiDeri = ( 1 + v2*COS(2*(x-Psi))*2 )\n RETURN\n END FUNCTION\n\n FUNCTION functionNewtonsMethod(x, v2, Psi, phi0)\n REAL x, v2, Psi, phi0\n REAL ratioFuncDeri\n ratioFuncDeri = functionPhi(x, v2, Psi, phi0) \n * / functionPhiDeri(x, v2, Psi)\n DO WHILE (ABS(ratioFuncDeri) > 0.0000001) \n ratioFuncDeri = functionPhi(x, v2, Psi, phi0) \n * / functionPhiDeri(x, v2, Psi)\n x = x - ratioFuncDeri\n END DO\n\n functionNewtonsMethod = x\n RETURN\n END FUNCTION\n \n\n\n", "meta": {"hexsha": "3dc9c94b09f79023e8c5d6a24f312a409f19e51a", "size": 1450, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "newtonsMethod/fortran/fortran_newtons.f", "max_stars_repo_name": "tuos/ampt", "max_stars_repo_head_hexsha": "01ef59c55b7368b3dc34394312ec415e16a64f80", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-01-10T03:13:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-17T16:05:57.000Z", "max_issues_repo_path": "newtonsMethod/fortran/fortran_newtons.f", "max_issues_repo_name": "tuos/ampt", "max_issues_repo_head_hexsha": "01ef59c55b7368b3dc34394312ec415e16a64f80", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-07-16T17:20:34.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-22T20:51:10.000Z", "max_forks_repo_path": "newtonsMethod/fortran/fortran_newtons.f", "max_forks_repo_name": "tuos/ampt", "max_forks_repo_head_hexsha": "01ef59c55b7368b3dc34394312ec415e16a64f80", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-04-09T21:34:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T22:04:56.000Z", "avg_line_length": 26.8518518519, "max_line_length": 70, "alphanum_fraction": 0.5344827586, "num_tokens": 479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248225478307, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7565086167237021}} {"text": "program euler_169\n integer, parameter :: int64 = selected_int_kind(15)\n integer, dimension(26) :: twos=0 ! use an array of length 26 to represent 10**25\n integer(int64) :: a, b, i=0\n twos(1) = 1\n twos(26) = 1 ! this is needed due to algorithm\n \n a = 1\n b = 0\n i = 0\n do\n if (mod(twos(26),2)==1) then\n b = a + b\n else\n a = a + b\n endif\n call divide_by_two(twos)\n i = i + 1\n print '(3(i0,2x),26(i0))',i,a,b,twos\n if (sum(twos)==0) exit\n end do \n print '(\"The hyperbinary representation of 10**25 = \",i0)',b\n\ncontains\n subroutine divide_by_two(twos)\n integer, dimension(26), intent(inout) :: twos\n integer :: i, tmp(26)\n tmp = 0\n ! do first round of integer division\n do i=1,26\n tmp(i) = twos(i)/2\n end do !- i\n ! add \"0.5\" term to odd terms\n do i=2,26\n if (mod(twos(i-1),2)==1) then\n tmp(i) = tmp(i) + 5\n end if\n end do ! -i\n twos(:) = tmp(:)\n end subroutine divide_by_two\nend program euler_169\n", "meta": {"hexsha": "dfb1b55619a91d8315f3c0c3ba91fc8f506d157d", "size": 1081, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "euler_169.f90", "max_stars_repo_name": "kylekanos/ProjectEuler", "max_stars_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-13T03:36:23.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-13T03:36:23.000Z", "max_issues_repo_path": "euler_169.f90", "max_issues_repo_name": "kylekanos/ProjectEuler", "max_issues_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "euler_169.f90", "max_forks_repo_name": "kylekanos/ProjectEuler", "max_forks_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.7380952381, "max_line_length": 85, "alphanum_fraction": 0.5226641998, "num_tokens": 381, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350351, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.7565086161653247}} {"text": "C NCLFORTSTART\n subroutine spareapolyi(vlat,vlon,nv,rad,area)\n implicit none\nc input\n integer nv\n double precision vlat(nv), vlon(nv), rad\nc output\n double precision area\nC NCLEND\nc local \n integer npts\n\nc Are beginning and end pts the same?\nc If so, pass one less value. spareapoly wants no duplicate pts.\n\n npts = nv\n if (vlat(1).eq.vlat(nv) .and. vlon(1).eq.vlon(nv)) then\n npts = nv-1\n end if\n call spareapoly(vlat,vlon,npts,rad,area)\n\n return\n end\n \nc --------------\n subroutine spareapoly(vlat,vlon,nv,rad,area)\n implicit none\nc input\n integer nv\n double precision vlat(nv), vlon(nv), rad\nc output\n double precision area\n\nC*************************************************************\nC Computing the Area of a Spherical Polygon of Arbitrary Shape\nC Bevis and Cambareri (1987)\nC Mathematical Geology, vol.19, Issue 4, pp 335-346 \nC*************************************************************\nc Computes the area of a spherical polygon with nv vertices and sides.\n\nc ARGUMENTS:\nc vlat,vlon ... vectors containing the latitude and longitude\nc of each vertex. The ith. vertex is located at \nc [vlat(i),vlon(i)].\nc nv ... the number of vertices and sides in the spherical\nc polygon\nc rad ... the radius of the sphere\n\nc area ... the area of the spherical polygon\n\nc UNITS:\nc Latitudes and longitudes are specified in degrees. The user selects\nc the units of length in which to specify the radius, and the polygon\nc area will be returned in the square of these units.\nc SIGN CONVENTION:\nc Latitudes are positive to the north and negative to the south.\nc Longitudes are positive to the east and negative to the west.\nc VERTEX ENUMERATION: \nc The vertices are numbered sequentially around the border of the\nc spherical polygon. Vertex 1 lies between vertex nv and vertex 2.\nc The user must follow the convention whereby in moving around the\nc polygon border in the direction of increasing vertex number clockwise\nc bends occur at salient vertices. A vertex is salient if the interior\nc angle'is less than 180 degrees. (In the case of a convex polygon\nc this convention implies that the vertices are numbered in clockwise\nc sequence).\nc\nc Two adjacent vertices may never be exactly 180 degrees apart\nc because they could be connected by infinitely many different\nc great circle arcs, and thus the border of the spherical\nc polygon would not be uniquely defined. \n\n\nc local\n integer iv\n double precision pi, twopi, suma\n double precision flat, flon, blat, blon, fang, bang, fvb\n parameter (pi=3.141592654d0, twopi=2.0d0*pi)\n\n suma = 0.0d0\n do iv=1,nv\n if (iv.eq.1) then\n flat=vlat(2)\n flon=vlon(2)\n blat=vlat(nv)\n blon=vlon(nv)\n elseif (iv.lt.nv) then\n flat=vlat(iv+1)\n flon=vlon(iv+1)\n blat=vlat(iv-1)\n blon=vlon(iv-1)\n else\n flat=vlat(1)\n flon=vlon(1)\n blat=vlat(nv-1)\n blon=vlon(nv-1)\n end if \n \n call trnsfrmlon (vlat(iv),vlon(iv),flat,flon,fang)\n call trnsfrmlon (vlat(iv),vlon(iv),blat,blon,bang) \n\n fvb = bang-fang\n if (fvb.lt. 0.0d0) fvb = fvb+twopi\n suma = suma+fvb\n end do\n\n area = (suma-pi*(nv-2))*rad**2\n\n return\n end\nc --- \n subroutine trnsfrmlon(plat,plon,qlat,qlon,tranlon)\n implicit none\nc Finds the \"longitude\" of point Q in a geographic coordinate system\nc for which point P acts as a \"north pole'.\nc input\nc plat,plon,qlat,qlon .... degrees\nc output\nc tranlon ... radians\nc input\n double precision plat,plon,qlat,qlon\nc output\n double precision tranlon\nc local\n double precision pi, dtr, tt, bb\n parameter (pi=3.141592654d0,dtr=pi/180.0d0)\n\n tt = sin((qlon-plon)*dtr)*cos(qlat*dtr)\n\n bb = sin(qlat*dtr)*cos(plat*dtr)-cos(qlat*dtr)*sin(plat*dtr) \n & *cos((qlon-plon)*dtr)\n\n tranlon = atan2(tt,bb)\n\n return\n end \n", "meta": {"hexsha": "f166db2ed01dbbc2c8ac03c02bb4ae65ea86bc55", "size": 4190, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/spareapoly.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ni/src/lib/nfpfort/spareapoly.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/spareapoly.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 30.5839416058, "max_line_length": 73, "alphanum_fraction": 0.6190930788, "num_tokens": 1192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299653388752, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7564444083831585}} {"text": "PURE FUNCTION func_var(arr, dof) RESULT(ans)\n ! NOTE: See https://numpy.org/doc/stable/reference/generated/numpy.var.html\n\n ! NOTE: In standard statistical practice:\n ! * dof=1 provides an unbiased estimator of the variance of a\n ! hypothetical infinite population\n ! * dof=0 provides a maximum likelihood estimate of the variance for\n ! normally distributed variables\n\n USE ISO_FORTRAN_ENV\n\n IMPLICIT NONE\n\n ! Declare inputs/outputs ...\n INTEGER(kind = INT64), INTENT(in), OPTIONAL :: dof\n REAL(kind = REAL64) :: ans\n REAL(kind = REAL64), DIMENSION(:), INTENT(in) :: arr\n\n ! Declare internal variables ...\n INTEGER(kind = INT64) :: n\n REAL(kind = REAL64), ALLOCATABLE, DIMENSION(:) :: tmp\n\n ! Find size of array ...\n n = SIZE(arr, kind = INT64)\n\n ! Allocate array ...\n ALLOCATE(tmp(n))\n\n ! Calculate the squared deviations from the mean ...\n tmp = ABS(arr - func_mean(arr)) ** 2\n\n ! Calculate the variance ...\n IF(PRESENT(dof))THEN\n ans = func_mean(tmp, dof)\n ELSE\n ans = func_mean(tmp, 0_INT64)\n END IF\n\n ! Clean up ...\n DEALLOCATE(tmp)\nEND FUNCTION func_var\n", "meta": {"hexsha": "47aab99b291bae3c84356516bc5123146afe1472", "size": 1393, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mod_safe/func_var.f90", "max_stars_repo_name": "Guymer/fortranlib", "max_stars_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-28T02:05:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-16T16:50:21.000Z", "max_issues_repo_path": "mod_safe/func_var.f90", "max_issues_repo_name": "Guymer/fortranlib", "max_issues_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-06-17T16:49:20.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-11T18:47:36.000Z", "max_forks_repo_path": "mod_safe/func_var.f90", "max_forks_repo_name": "Guymer/fortranlib", "max_forks_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-11T04:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-11T04:51:33.000Z", "avg_line_length": 33.1666666667, "max_line_length": 86, "alphanum_fraction": 0.5333811917, "num_tokens": 303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7563594176418349}} {"text": "program outputdata \nimplicit none \n\n real, dimension(100) :: x, y \n real, dimension(100) :: p, q\n integer :: i \n \n ! data \n do i = 1,100 \n x(i) = i * 0.1 \n y(i) = sin(x(i)) * (1-cos(x(i)/3.0)) \n end do \n \n ! output data into a file \n open(1, file = 'data1.dat', status='new') \n do i = 1,100 \n write(1,*) x(i), y(i) \n end do \n close(1) \n\n ! opening the file for reading\n open (2, file = 'data1.dat', status = 'old')\n\n do i = 1,100 \n read(2,*) p(i), q(i)\n end do \n \n close(2)\n \n do i = 1,100 \n write(*,*) p(i), q(i)\n end do \n \nend program outputdata\n", "meta": {"hexsha": "1770038c41caccc3b535439cb63df60aa73b7763", "size": 636, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main4=out.f90", "max_stars_repo_name": "ArkAngeL43/fortran-fun", "max_stars_repo_head_hexsha": "80ad2dd081af8606fa74afedeee1fe72cd0585c2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "main4=out.f90", "max_issues_repo_name": "ArkAngeL43/fortran-fun", "max_issues_repo_head_hexsha": "80ad2dd081af8606fa74afedeee1fe72cd0585c2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "main4=out.f90", "max_forks_repo_name": "ArkAngeL43/fortran-fun", "max_forks_repo_head_hexsha": "80ad2dd081af8606fa74afedeee1fe72cd0585c2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.1714285714, "max_line_length": 47, "alphanum_fraction": 0.4716981132, "num_tokens": 233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.8670357598021707, "lm_q1q2_score": 0.7563563630606693}} {"text": "! from QE-6.0\n\nsubroutine ylmr2 (lmax2, ng, g, gg, ylm)\n !\n ! Real spherical harmonics ylm(G) up to l=lmax\n ! lmax2 = (lmax+1)^2 is the total number of spherical harmonics\n ! Numerical recursive algorithm based on the one given in Numerical\n ! Recipes but avoiding the calculation of factorials that generate\n ! overflow for lmax > 11\n !\n implicit none\n integer, parameter :: DP = 8\n real(DP), parameter :: PI = 4.d0*atan(1.d0)\n real(DP), parameter :: FPI = 4.d0*PI\n !\n integer, intent(in) :: lmax2, ng\n real(DP), intent(in) :: g (3, ng), gg (ng)\n !\n ! BEWARE: gg = g(1)^2 + g(2)^2 +g(3)^2 is not checked on input\n ! incorrect results will ensue if the above does not hold\n !\n real(DP), intent(out) :: ylm (ng,lmax2)\n !\n ! local variables\n !\n real(DP), parameter :: eps = 1.0d-9\n real(DP), allocatable :: cost (:), sent(:), phi (:), Q(:,:,:)\n real(DP) :: c, gmod\n integer :: lmax, ig, l, m, lm\n !\n\n WRITE(*,*) 'PI = ', PI\n\n IF (ng < 1 .or. lmax2 < 1) RETURN \n\n DO lmax = 0, 25\n WRITE(*,*) 'lmax = ', lmax\n IF ((lmax+1)**2 == lmax2) go to 10\n ENDDO\n WRITE(*,*) 'Error ylmr: l > 25 or wrong number of Ylm required, lmax, lmax2 = ', lmax, lmax2\n STOP\n\n10 CONTINUE\n WRITE(*,*) 'JUMPED !!!', lmax\n !\n IF (lmax == 0) THEN\n ylm(:,1) = sqrt (1.d0 / fpi)\n RETURN \n ENDIF \n\n !\n ! theta and phi are polar angles, cost = cos(theta)\n !\n allocate(cost(ng), sent(ng), phi(ng), Q(ng,0:lmax,0:lmax) )\n Q(:,:,:) = 0.d0 ! ffr\n !\n\n do ig = 1, ng\n gmod = sqrt (gg (ig) )\n if (gmod < eps) then\n cost(ig) = 0.d0\n else\n cost(ig) = g(3,ig)/gmod\n endif\n !\n ! beware the arc tan, it is defined modulo pi\n !\n if (g(1,ig) > eps) then\n phi (ig) = atan( g(2,ig)/g(1,ig) )\n else if (g(1,ig) < -eps) THEN\n WRITE(*,*) 'Pass here -eps ...'\n phi (ig) = atan( g(2,ig)/g(1,ig) ) + pi\n else\n phi (ig) = sign( pi/2.d0,g(2,ig) )\n end if\n sent(ig) = sqrt(max(0d0,1.d0-cost(ig)**2))\n write(*,'(1x,I5,3F18.10)') ig, phi(ig), cost(ig), sent(ig)\n enddo\n !\n ! Q(:,l,m) are defined as sqrt ((l-m)!/(l+m)!) * P(:,l,m) where\n ! P(:,l,m) are the Legendre Polynomials (0 <= m <= l)\n !\n lm = 0\n do l = 0, lmax\n WRITE(*,*) 'l = ', l\n c = sqrt (DBLE(2*l+1) / fpi)\n if ( l == 0 ) then\n do ig = 1, ng\n Q (ig,0,0) = 1.d0\n end do\n else if ( l == 1 ) then\n do ig = 1, ng\n Q (ig,1,0) = cost(ig)\n Q (ig,1,1) =-sent(ig)/sqrt(2.d0)\n end do\n else\n !\n ! recursion on l for Q(:,l,m)\n !\n do m = 0, l - 2\n write(*,*) 'Enter this ....'\n do ig = 1, ng\n Q(ig,l,m) = cost(ig)*(2*l-1)/sqrt(DBLE(l*l-m*m))*Q(ig,l-1,m) &\n - sqrt(DBLE((l-1)*(l-1)-m*m))/sqrt(DBLE(l*l-m*m))*Q(ig,l-2,m)\n end do\n write(*,*) 'sum(Q) = ', sum(Q(:,l,m))\n end do\n do ig = 1, ng\n Q(ig,l,l-1) = cost(ig) * sqrt(DBLE(2*l-1)) * Q(ig,l-1,l-1)\n end do\n do ig = 1, ng\n Q(ig,l,l) = - sqrt(DBLE(2*l-1))/sqrt(DBLE(2*l))*sent(ig)*Q(ig,l-1,l-1)\n end do\n end if\n !\n ! Y_lm, m = 0\n !\n lm = lm + 1\n WRITE(*,*) 'm = 0: lm = ', lm\n do ig = 1, ng\n ylm(ig, lm) = c * Q(ig,l,0)\n end do\n !\n do m = 1, l\n !\n ! Y_lm, m > 0\n !\n lm = lm + 1\n WRITE(*,*) 'm > 0: lm = ', lm\n do ig = 1, ng\n ylm(ig, lm) = c * sqrt(2.d0) * Q(ig,l,m) * cos (m*phi(ig))\n end do\n !\n ! Y_lm, m < 0\n !\n lm = lm + 1\n WRITE(*,*) 'm < 0: lm = ', lm\n DO ig = 1, ng\n ylm(ig, lm) = c * sqrt(2.d0) * Q(ig,l,m) * sin (m*phi(ig))\n ENDDO\n ENDDO \n ENDDO \n !\n DEALLOCATE(cost, sent, phi, Q)\n !\n RETURN\nend subroutine ylmr2\n\n", "meta": {"hexsha": "efe56df645d034576f7085e822fceaae25d576c6", "size": 3867, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "PW/pseudo_HGH/ylmr2.f90", "max_stars_repo_name": "f-fathurrahman/ffr-ElectronicStructure.jl", "max_stars_repo_head_hexsha": "35dca9831bfc6a3e49bb0f3a5872558ffce4b211", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-01-03T02:19:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-29T13:30:20.000Z", "max_issues_repo_path": "PW/pseudo_HGH/ylmr2.f90", "max_issues_repo_name": "f-fathurrahman/ffr-ElectronicStructure.jl", "max_issues_repo_head_hexsha": "35dca9831bfc6a3e49bb0f3a5872558ffce4b211", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PW/pseudo_HGH/ylmr2.f90", "max_forks_repo_name": "f-fathurrahman/ffr-ElectronicStructure.jl", "max_forks_repo_head_hexsha": "35dca9831bfc6a3e49bb0f3a5872558ffce4b211", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-03-23T06:58:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-03T00:54:28.000Z", "avg_line_length": 25.9530201342, "max_line_length": 94, "alphanum_fraction": 0.4582363589, "num_tokens": 1553, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7563537395875535}} {"text": "!-----------------------------------------------------------------------\nsubroutine tridiagonal(N,au,bu,cu,du,fi,lt,value)\n!\n! !DESCRIPTION:\n! A linear equation with tridiagonal matrix structure is solved here. The main\n! diagonal is stored on {\\tt bu}, the upper diagonal on {\\tt au}, and the\n! lower diagonal on {\\tt cu}, the right hand side is stored on {\\tt du}.\n! The method used here is the simplified Gauss elimination, also called\n! \\emph{Thomas algorithm}.\n!\n! !USES:\n IMPLICIT NONE\n!\n! !INPUT PARAMETERS:\n integer, intent(in) :: N,fi,lt\n real(8), dimension(N), intent(in) :: au, bu, cu, du\n!\n! !OUTPUT PARAMETERS:\n real(8), intent(out) :: value(N)\n!\n!EOP\n!\n! !LOCAL VARIABLES:\n integer :: i\n real(8), dimension(N) :: ru, qu\n!\n!-----------------------------------------------------------------------\n!BOC\n ru(lt)=au(lt)/bu(lt)\n qu(lt)=du(lt)/bu(lt)\n\n do i=lt-1,fi+1,-1\n ru(i)=au(i)/(bu(i)-cu(i)*ru(i+1))\n qu(i)=(du(i)-cu(i)*qu(i+1))/(bu(i)-cu(i)*ru(i+1))\n end do\n\n qu(fi)=(du(fi)-cu(fi)*qu(fi+1))/(bu(fi)-cu(fi)*ru(fi+1))\n\n value(fi)=qu(fi)\n\n! write(6,*) 'fi = ',fi\n! write(6,*) 'value(fi) = ',value(fi)\n\n do i=fi+1,lt\n value(i)=qu(i)-ru(i)*value(i-1)\n end do\n\n! write(6,*) 'value(lt) = ',value(lt)\n\n return\nend subroutine tridiagonal\n\n", "meta": {"hexsha": "de8ae4c2c1589fdad8410b22936dc13d73bf3299", "size": 1371, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tridiagonal.f90", "max_stars_repo_name": "BingzhangChen/HOT", "max_stars_repo_head_hexsha": "c166ac038cd67a0e4dd5c8512bf5d678eb07b6cc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/tridiagonal.f90", "max_issues_repo_name": "BingzhangChen/HOT", "max_issues_repo_head_hexsha": "c166ac038cd67a0e4dd5c8512bf5d678eb07b6cc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/tridiagonal.f90", "max_forks_repo_name": "BingzhangChen/HOT", "max_forks_repo_head_hexsha": "c166ac038cd67a0e4dd5c8512bf5d678eb07b6cc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.8679245283, "max_line_length": 78, "alphanum_fraction": 0.5003646973, "num_tokens": 421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361628580401, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.7563537377970945}} {"text": "subroutine givens(h,M,beta)\n! Solve the least square problem M * x = beta \n! with Givens rotation and Back substitution \n! h is a hessenberg matrix\n! M is dimension of h, h=dim(M+1,M)\n! use beta as the out puts beta=x\n\ninteger M\nreal(8) h(M+1,M)\nreal(8) beta(M+1)\nreal(8) x(M+1)\n\ninteger i,j,k\nreal(8) tmp,tmp1,tmp2\nreal(8) s1,c1\nreal(8) tmph(2,M)\n\n! Givens rotation to get up-triangle matrix\ndo i=1,M\n\ttmp=sqrt(h(i,i)**2 + h(i+1,i)**2)\n\ts1=h(i+1,i)/tmp\n\tc1=h(i,i)/tmp\n\ttmp1=c1*beta(i)\n\ttmp2=-s1*beta(i)\n\tbeta(i)=tmp1\n\tbeta(i+1)=tmp2;\n\t\n\tdo j=i,M\n\t\ttmph(1,j)=c1*h(i,j)+s1*h(i+1,j)\n\t\ttmph(2,j)=-s1*h(i,j)+c1*h(i+1,j)\n\tend do\n\th(i:i+1,:)=tmph(1:2,:)\n\ttmph(:,:)=0.0d0\nend do\n!do i=1,M+1\n!write(*,*) ' h up-tri', h(i,:)\n!end do\n\n!write(*,*) 'beta', beta(:)\n! Back substitution used to solve a up-triangle system \nx(M)=beta(M)/h(M,M)\n\ndo j=M-1,1,-1\n\ttmp=0.0d0\n\tdo k=j+1,M\n\t\ttmp=tmp+x(k)*h(j,k)\n\tend do\n\tx(j)=(beta(j)-tmp)/h(j,j);\nend do\n\nbeta(:)=x(:)\n\nreturn\nend", "meta": {"hexsha": "f46bae8f9bf437b72c30fc5a6b7293904103ada2", "size": 957, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "givens.f90", "max_stars_repo_name": "biofluids/IFEM-archive", "max_stars_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-15T11:40:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-15T11:40:16.000Z", "max_issues_repo_path": "givens.f90", "max_issues_repo_name": "biofluids/IFEM-archive", "max_issues_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "givens.f90", "max_forks_repo_name": "biofluids/IFEM-archive", "max_forks_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-11T16:50:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T07:24:59.000Z", "avg_line_length": 17.7222222222, "max_line_length": 55, "alphanum_fraction": 0.605015674, "num_tokens": 421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582497090321, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7563390975827295}} {"text": "FUNCTION norm(x)RESULT(l2n)\n!\n! THis function calculates the l2 norm of vector x\n!\n IMPLICIT NONE\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n REAL(iwp),INTENT(IN)::x(:)\n REAL(iwp)::l2n\n l2n=SQRT(SUM(x**2))\nRETURN\nEND FUNCTION norm\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "c93f53a00e069e4c50bfbb593af7398374975660", "size": 244, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main/norm.f90", "max_stars_repo_name": "cunyizju/Programming-FEM-5th-Fortran", "max_stars_repo_head_hexsha": "7740d381c0871c7e860aee8a19c467bd97a4cf45", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 20, "max_stars_repo_stars_event_min_datetime": "2019-12-22T11:44:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T12:19:06.000Z", "max_issues_repo_path": "main/norm.f90", "max_issues_repo_name": "cunyizju/Programming-FEM-5th-Fortran", "max_issues_repo_head_hexsha": "7740d381c0871c7e860aee8a19c467bd97a4cf45", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-03-13T06:51:33.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-13T06:51:33.000Z", "max_forks_repo_path": "main/norm.f90", "max_forks_repo_name": "cunyizju/Programming-FEM-5th-Fortran", "max_forks_repo_head_hexsha": "7740d381c0871c7e860aee8a19c467bd97a4cf45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-06-03T12:47:06.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-30T13:35:28.000Z", "avg_line_length": 11.619047619, "max_line_length": 50, "alphanum_fraction": 0.7049180328, "num_tokens": 80, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026663679976, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.7562811312970059}} {"text": " SUBROUTINE CGBMV ( TRANS, M, N, KL, KU, ALPHA, A, LDA, X, INCX,\n $ BETA, Y, INCY )\nc .. Scalar Arguments ..\n COMPLEX ALPHA, BETA\n INTEGER INCX, INCY, KL, KU, LDA, M, N\n CHARACTER*1 TRANS\nc .. Array Arguments ..\n COMPLEX A( LDA, * ), X( * ), Y( * )\nc ..\nc\nc Purpose\nc =======\nc\nc CGBMV performs one of the matrix-vector operations\nc\nc y := alpha*A*x + beta*y, or y := alpha*A'*x + beta*y, or\nc\nc y := alpha*conjg( A' )*x + beta*y,\nc\nc where alpha and beta are scalars, x and y are vectors and A is an\nc m by n band matrix, with kl sub-diagonals and ku super-diagonals.\nc\nc Parameters\nc ==========\nc\nc TRANS - CHARACTER*1.\nc On entry, TRANS specifies the operation to be performed as\nc follows:\nc\nc TRANS = 'N' or 'n' y := alpha*A*x + beta*y.\nc\nc TRANS = 'T' or 't' y := alpha*A'*x + beta*y.\nc\nc TRANS = 'C' or 'c' y := alpha*conjg( A' )*x + beta*y.\nc\nc Unchanged on exit.\nc\nc M - INTEGER.\nc On entry, M specifies the number of rows of the matrix A.\nc M must be at least zero.\nc Unchanged on exit.\nc\nc N - INTEGER.\nc On entry, N specifies the number of columns of the matrix A.\nc N must be at least zero.\nc Unchanged on exit.\nc\nc KL - INTEGER.\nc On entry, KL specifies the number of sub-diagonals of the\nc matrix A. KL must satisfy 0 .le. KL.\nc Unchanged on exit.\nc\nc KU - INTEGER.\nc On entry, KU specifies the number of super-diagonals of the\nc matrix A. KU must satisfy 0 .le. KU.\nc Unchanged on exit.\nc\nc ALPHA - COMPLEX .\nc On entry, ALPHA specifies the scalar alpha.\nc Unchanged on exit.\nc\nc A - COMPLEX array of DIMENSION ( LDA, n ).\nc Before entry, the leading ( kl + ku + 1 ) by n part of the\nc array A must contain the matrix of coefficients, supplied\nc column by column, with the leading diagonal of the matrix in\nc row ( ku + 1 ) of the array, the first super-diagonal\nc starting at position 2 in row ku, the first sub-diagonal\nc starting at position 1 in row ( ku + 2 ), and so on.\nc Elements in the array A that do not correspond to elements\nc in the band matrix (such as the top left ku by ku triangle)\nc are not referenced.\nc The following program segment will transfer a band matrix\nc from conventional full matrix storage to band storage:\nc\nc DO 20, J = 1, N\nc K = KU + 1 - J\nc DO 10, I = MAX( 1, J - KU ), MIN( M, J + KL )\nc A( K + I, J ) = matrix( I, J )\nc 10 CONTINUE\nc 20 CONTINUE\nc\nc Unchanged on exit.\nc\nc LDA - INTEGER.\nc On entry, LDA specifies the first dimension of A as declared\nc in the calling (sub) program. LDA must be at least\nc ( kl + ku + 1 ).\nc Unchanged on exit.\nc\nc X - COMPLEX array of DIMENSION at least\nc ( 1 + ( n - 1 )*abs( INCX ) ) when TRANS = 'N' or 'n'\nc and at least\nc ( 1 + ( m - 1 )*abs( INCX ) ) otherwise.\nc Before entry, the incremented array X must contain the\nc vector x.\nc Unchanged on exit.\nc\nc INCX - INTEGER.\nc On entry, INCX specifies the increment for the elements of\nc X. INCX must not be zero.\nc Unchanged on exit.\nc\nc BETA - COMPLEX .\nc On entry, BETA specifies the scalar beta. When BETA is\nc supplied as zero then Y need not be set on input.\nc Unchanged on exit.\nc\nc Y - COMPLEX array of DIMENSION at least\nc ( 1 + ( m - 1 )*abs( INCY ) ) when TRANS = 'N' or 'n'\nc and at least\nc ( 1 + ( n - 1 )*abs( INCY ) ) otherwise.\nc Before entry, the incremented array Y must contain the\nc vector y. On exit, Y is overwritten by the updated vector y.\nc\nc\nc INCY - INTEGER.\nc On entry, INCY specifies the increment for the elements of\nc Y. INCY must not be zero.\nc Unchanged on exit.\nc\nc\nc Level 2 Blas routine.\nc\nc -- Written by Sourangshu Ghosh\nc\nc\nc .. Parameters ..\n COMPLEX ONE\n PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\nc .. Local Scalars ..\n COMPLEX TEMP\n INTEGER I, INFO, IX, IY, J, JX, JY, K, KUP1, KX, KY,\n $ LENX, LENY\n LOGICAL NOCONJ\nc .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nc .. External Subroutines ..\n EXTERNAL XERBLA\nc .. Intrinsic Functions ..\n INTRINSIC CONJG, MAX, MIN\nc ..\nc .. Executable Statements ..\nc\nc Test the input parameters.\nc\n INFO = 0\n IF ( .NOT.LSAME( TRANS, 'N' ).AND.\n $ .NOT.LSAME( TRANS, 'T' ).AND.\n $ .NOT.LSAME( TRANS, 'C' ) )THEN\n INFO = 1\n ELSE IF( M.LT.0 )THEN\n INFO = 2\n ELSE IF( N.LT.0 )THEN\n INFO = 3\n ELSE IF( KL.LT.0 )THEN\n INFO = 4\n ELSE IF( KU.LT.0 )THEN\n INFO = 5\n ELSE IF( LDA.LT.( KL + KU + 1 ) )THEN\n INFO = 8\n ELSE IF( INCX.EQ.0 )THEN\n INFO = 10\n ELSE IF( INCY.EQ.0 )THEN\n INFO = 13\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'CGBMV ', INFO )\n RETURN\n END IF\nc\nc Quick return if possible.\nc\n IF( ( M.EQ.0 ).OR.( N.EQ.0 ).OR.\n $ ( ( ALPHA.EQ.ZERO ).AND.( BETA.EQ.ONE ) ) )\n $ RETURN\nc\n NOCONJ = LSAME( TRANS, 'T' )\nc\nc Set LENX and LENY, the lengths of the vectors x and y, and set\nc up the start points in X and Y.\nc\n IF( LSAME( TRANS, 'N' ) )THEN\n LENX = N\n LENY = M\n ELSE\n LENX = M\n LENY = N\n END IF\n IF( INCX.GT.0 )THEN\n KX = 1\n ELSE\n KX = 1 - ( LENX - 1 )*INCX\n END IF\n IF( INCY.GT.0 )THEN\n KY = 1\n ELSE\n KY = 1 - ( LENY - 1 )*INCY\n END IF\nc\nc Start the operations. In this version the elements of A are\nc accessed sequentially with one pass through the band part of A.\nc\nc First form y := beta*y.\nc\n IF( BETA.NE.ONE )THEN\n IF( INCY.EQ.1 )THEN\n IF( BETA.EQ.ZERO )THEN\n DO 10, I = 1, LENY\n Y( I ) = ZERO\n 10 CONTINUE\n ELSE\n DO 20, I = 1, LENY\n Y( I ) = BETA*Y( I )\n 20 CONTINUE\n END IF\n ELSE\n IY = KY\n IF( BETA.EQ.ZERO )THEN\n DO 30, I = 1, LENY\n Y( IY ) = ZERO\n IY = IY + INCY\n 30 CONTINUE\n ELSE\n DO 40, I = 1, LENY\n Y( IY ) = BETA*Y( IY )\n IY = IY + INCY\n 40 CONTINUE\n END IF\n END IF\n END IF\n IF( ALPHA.EQ.ZERO )\n $ RETURN\n KUP1 = KU + 1\n IF( LSAME( TRANS, 'N' ) )THEN\nc\nc Form y := alpha*A*x + y.\nc\n JX = KX\n IF( INCY.EQ.1 )THEN\n DO 60, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n TEMP = ALPHA*X( JX )\n K = KUP1 - J\n DO 50, I = MAX( 1, J - KU ), MIN( M, J + KL )\n Y( I ) = Y( I ) + TEMP*A( K + I, J )\n 50 CONTINUE\n END IF\n JX = JX + INCX\n 60 CONTINUE\n ELSE\n DO 80, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n TEMP = ALPHA*X( JX )\n IY = KY\n K = KUP1 - J\n DO 70, I = MAX( 1, J - KU ), MIN( M, J + KL )\n Y( IY ) = Y( IY ) + TEMP*A( K + I, J )\n IY = IY + INCY\n 70 CONTINUE\n END IF\n JX = JX + INCX\n IF( J.GT.KU )\n $ KY = KY + INCY\n 80 CONTINUE\n END IF\n ELSE\nc\nc Form y := alpha*A'*x + y or y := alpha*conjg( A' )*x + y.\nc\n JY = KY\n IF( INCX.EQ.1 )THEN\n DO 110, J = 1, N\n TEMP = ZERO\n K = KUP1 - J\n IF( NOCONJ )THEN\n DO 90, I = MAX( 1, J - KU ), MIN( M, J + KL )\n TEMP = TEMP + A( K + I, J )*X( I )\n 90 CONTINUE\n ELSE\n DO 100, I = MAX( 1, J - KU ), MIN( M, J + KL )\n TEMP = TEMP + CONJG( A( K + I, J ) )*X( I )\n 100 CONTINUE\n END IF\n Y( JY ) = Y( JY ) + ALPHA*TEMP\n JY = JY + INCY\n 110 CONTINUE\n ELSE\n DO 140, J = 1, N\n TEMP = ZERO\n IX = KX\n K = KUP1 - J\n IF( NOCONJ )THEN\n DO 120, I = MAX( 1, J - KU ), MIN( M, J + KL )\n TEMP = TEMP + A( K + I, J )*X( IX )\n IX = IX + INCX\n 120 CONTINUE\n ELSE\n DO 130, I = MAX( 1, J - KU ), MIN( M, J + KL )\n TEMP = TEMP + CONJG( A( K + I, J ) )*X( IX )\n IX = IX + INCX\n 130 CONTINUE\n END IF\n Y( JY ) = Y( JY ) + ALPHA*TEMP\n JY = JY + INCY\n IF( J.GT.KU )\n $ KX = KX + INCX\n 140 CONTINUE\n END IF\n END IF\nc\n RETURN\nc\nc End of CGBMV .\nc\n END\n SUBROUTINE CGEMV ( TRANS, M, N, ALPHA, A, LDA, X, INCX,\n $ BETA, Y, INCY )\nc .. Scalar Arguments ..\n COMPLEX ALPHA, BETA\n INTEGER INCX, INCY, LDA, M, N\n CHARACTER*1 TRANS\nc .. Array Arguments ..\n COMPLEX A( LDA, * ), X( * ), Y( * )\nc ..\nc\nc Purpose\nc =======\nc\nc CGEMV performs one of the matrix-vector operations\nc\nc y := alpha*A*x + beta*y, or y := alpha*A'*x + beta*y, or\nc\nc y := alpha*conjg( A' )*x + beta*y,\nc\nc where alpha and beta are scalars, x and y are vectors and A is an\nc m by n matrix.\nc\nc Parameters\nc ==========\nc\nc TRANS - CHARACTER*1.\nc On entry, TRANS specifies the operation to be performed as\nc follows:\nc\nc TRANS = 'N' or 'n' y := alpha*A*x + beta*y.\nc\nc TRANS = 'T' or 't' y := alpha*A'*x + beta*y.\nc\nc TRANS = 'C' or 'c' y := alpha*conjg( A' )*x + beta*y.\nc\nc Unchanged on exit.\nc\nc M - INTEGER.\nc On entry, M specifies the number of rows of the matrix A.\nc M must be at least zero.\nc Unchanged on exit.\nc\nc N - INTEGER.\nc On entry, N specifies the number of columns of the matrix A.\nc N must be at least zero.\nc Unchanged on exit.\nc\nc ALPHA - COMPLEX .\nc On entry, ALPHA specifies the scalar alpha.\nc Unchanged on exit.\nc\nc A - COMPLEX array of DIMENSION ( LDA, n ).\nc Before entry, the leading m by n part of the array A must\nc contain the matrix of coefficients.\nc Unchanged on exit.\nc\nc LDA - INTEGER.\nc On entry, LDA specifies the first dimension of A as declared\nc in the calling (sub) program. LDA must be at least\nc max( 1, m ).\nc Unchanged on exit.\nc\nc X - COMPLEX array of DIMENSION at least\nc ( 1 + ( n - 1 )*abs( INCX ) ) when TRANS = 'N' or 'n'\nc and at least\nc ( 1 + ( m - 1 )*abs( INCX ) ) otherwise.\nc Before entry, the incremented array X must contain the\nc vector x.\nc Unchanged on exit.\nc\nc INCX - INTEGER.\nc On entry, INCX specifies the increment for the elements of\nc X. INCX must not be zero.\nc Unchanged on exit.\nc\nc BETA - COMPLEX .\nc On entry, BETA specifies the scalar beta. When BETA is\nc supplied as zero then Y need not be set on input.\nc Unchanged on exit.\nc\nc Y - COMPLEX array of DIMENSION at least\nc ( 1 + ( m - 1 )*abs( INCY ) ) when TRANS = 'N' or 'n'\nc and at least\nc ( 1 + ( n - 1 )*abs( INCY ) ) otherwise.\nc Before entry with BETA non-zero, the incremented array Y\nc must contain the vector y. On exit, Y is overwritten by the\nc updated vector y.\nc\nc INCY - INTEGER.\nc On entry, INCY specifies the increment for the elements of\nc Y. INCY must not be zero.\nc Unchanged on exit.\nc\nc\nc Level 2 Blas routine.\nc\nc -- Written by Sourangshu Ghosh\nc\nc\nc .. Parameters ..\n COMPLEX ONE\n PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\nc .. Local Scalars ..\n COMPLEX TEMP\n INTEGER I, INFO, IX, IY, J, JX, JY, KX, KY, LENX, LENY\n LOGICAL NOCONJ\nc .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nc .. External Subroutines ..\n EXTERNAL XERBLA\nc .. Intrinsic Functions ..\n INTRINSIC CONJG, MAX\nc\nc Test the input parameters.\nc\n INFO = 0\n IF ( .NOT. LSAME ( TRANS, 'N' ) .AND.\n & .NOT. LSAME ( TRANS, 'T' ) .AND.\n & .NOT. LSAME ( TRANS, 'C' ) ) THEN\n INFO = 1\n ELSE IF ( M .LT. 0 ) THEN\n INFO = 2\n ELSE IF ( N .LT. 0 ) THEN\n INFO = 3\n ELSE IF ( LDA .LT. MAX ( 1, M ) ) THEN\n INFO = 6\n ELSE IF ( INCX .EQ. 0 ) THEN\n INFO = 8\n ELSE IF ( INCY .EQ. 0 ) THEN\n INFO = 11\n END IF\n\n IF( INFO .NE. 0 )THEN\n CALL XERBLA ( 'CGEMV ', INFO )\n RETURN\n END IF\nc\nc Quick return if possible.\nc\n IF( ( M .EQ. 0 ) .OR. \n & ( N .EQ. 0 ) .OR.\n & ( ( ALPHA .EQ. ZERO ) .AND. ( BETA .EQ. ONE ) ) ) then\n RETURN\n end if\n\n NOCONJ = LSAME ( TRANS, 'T' )\nc\nc Set LENX and LENY, the lengths of the vectors x and y, and set\nc up the start points in X and Y.\nc\n IF ( LSAME ( TRANS, 'N' ) ) THEN\n LENX = N\n LENY = M\n ELSE\n LENX = M\n LENY = N\n END IF\n\n IF ( 0 .le. INCX ) THEN\n KX = 1\n ELSE\n KX = 1 - ( LENX - 1 ) * INCX\n END IF\n\n IF ( 0 .le. INCY ) THEN\n KY = 1\n ELSE\n KY = 1 - ( LENY - 1 ) * INCY\n END IF\nc\nc Start the operations. In this version the elements of A are\nc accessed sequentially with one pass through A.\nc\nc First form y := beta*y.\nc\n IF ( BETA .NE. ONE ) THEN\n IF ( INCY .EQ. 1 ) THEN\n IF ( BETA .EQ. ZERO ) THEN\n DO I = 1, LENY\n Y( I ) = ZERO\n end do\n ELSE\n DO I = 1, LENY\n Y( I ) = BETA * Y( I )\n end do\n END IF\n ELSE\n IY = KY\n IF ( BETA .EQ. ZERO ) THEN\n DO I = 1, LENY\n Y( IY ) = ZERO\n IY = IY + INCY\n end do\n ELSE\n DO I = 1, LENY\n Y( IY ) = BETA * Y( IY )\n IY = IY + INCY\n end do\n END IF\n END IF\n END IF\n\n IF ( ALPHA .EQ. ZERO ) then\n RETURN\n end if\nc\nc Form y := alpha*A*x + y.\nc\n IF ( LSAME ( TRANS, 'N' ) ) THEN\n JX = KX\n IF ( INCY .EQ. 1 ) THEN\n DO J = 1, N\n IF ( X( JX ) .NE. ZERO ) THEN\n TEMP = ALPHA * X( JX )\n DO I = 1, M\n Y( I ) = Y( I ) + TEMP * A( I, J )\n end do\n END IF\n JX = JX + INCX\n end do\n ELSE\n DO J = 1, N\n IF ( X( JX ) .NE. ZERO ) THEN\n TEMP = ALPHA * X( JX )\n IY = KY\n DO I = 1, M\n Y( IY ) = Y( IY ) + TEMP * A( I, J )\n IY = IY + INCY\n end do\n END IF\n JX = JX + INCX\n end do\n END IF\nc\nc Form y := alpha*A'*x + y or y := alpha*conjg( A' )*x + y.\nc\n ELSE\n JY = KY\n IF ( INCX .EQ. 1 ) THEN\n DO J = 1, N\n TEMP = ZERO\n IF ( NOCONJ ) THEN\n DO I = 1, M\n TEMP = TEMP + A( I, J ) * X( I )\n end do\n ELSE\n DO I = 1, M\n TEMP = TEMP + CONJG ( A( I, J ) ) * X( I )\n end do\n END IF\n Y( JY ) = Y( JY ) + ALPHA * TEMP\n JY = JY + INCY\n end do\n ELSE\n DO J = 1, N\n TEMP = ZERO\n IX = KX\n IF ( NOCONJ ) THEN\n DO I = 1, M\n TEMP = TEMP + A( I, J ) * X( IX )\n IX = IX + INCX\n end do\n ELSE\n DO I = 1, M\n TEMP = TEMP + CONJG ( A( I, J ) ) * X( IX )\n IX = IX + INCX\n end do\n END IF\n Y( JY ) = Y( JY ) + ALPHA * TEMP\n JY = JY + INCY\n end do\n END IF\n END IF\n\n RETURN\n END\n SUBROUTINE CGERC ( M, N, ALPHA, X, INCX, Y, INCY, A, LDA )\nc .. Scalar Arguments ..\n COMPLEX ALPHA\n INTEGER INCX, INCY, LDA, M, N\nc .. Array Arguments ..\n COMPLEX A( LDA, * ), X( * ), Y( * )\nc ..\nc\nc Purpose\nc =======\nc\nc CGERC performs the rank 1 operation\nc\nc A := alpha*x*conjg( y' ) + A,\nc\nc where alpha is a scalar, x is an m element vector, y is an n element\nc vector and A is an m by n matrix.\nc\nc Parameters\nc ==========\nc\nc M - INTEGER.\nc On entry, M specifies the number of rows of the matrix A.\nc M must be at least zero.\nc Unchanged on exit.\nc\nc N - INTEGER.\nc On entry, N specifies the number of columns of the matrix A.\nc N must be at least zero.\nc Unchanged on exit.\nc\nc ALPHA - COMPLEX .\nc On entry, ALPHA specifies the scalar alpha.\nc Unchanged on exit.\nc\nc X - COMPLEX array of dimension at least\nc ( 1 + ( m - 1 )*abs( INCX ) ).\nc Before entry, the incremented array X must contain the m\nc element vector x.\nc Unchanged on exit.\nc\nc INCX - INTEGER.\nc On entry, INCX specifies the increment for the elements of\nc X. INCX must not be zero.\nc Unchanged on exit.\nc\nc Y - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCY ) ).\nc Before entry, the incremented array Y must contain the n\nc element vector y.\nc Unchanged on exit.\nc\nc INCY - INTEGER.\nc On entry, INCY specifies the increment for the elements of\nc Y. INCY must not be zero.\nc Unchanged on exit.\nc\nc A - COMPLEX array of DIMENSION ( LDA, n ).\nc Before entry, the leading m by n part of the array A must\nc contain the matrix of coefficients. On exit, A is\nc overwritten by the updated matrix.\nc\nc LDA - INTEGER.\nc On entry, LDA specifies the first dimension of A as declared\nc in the calling (sub) program. LDA must be at least\nc max( 1, m ).\nc Unchanged on exit.\nc\nc\nc Level 2 Blas routine.\nc\nc -- Written by Sourangshu Ghosh\nc\nc\nc .. Parameters ..\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\nc .. Local Scalars ..\n COMPLEX TEMP\n INTEGER I, INFO, IX, J, JY, KX\nc .. External Subroutines ..\n EXTERNAL XERBLA\nc .. Intrinsic Functions ..\n INTRINSIC CONJG, MAX\nc ..\nc .. Executable Statements ..\nc\nc Test the input parameters.\nc\n INFO = 0\n IF ( M.LT.0 )THEN\n INFO = 1\n ELSE IF( N.LT.0 )THEN\n INFO = 2\n ELSE IF( INCX.EQ.0 )THEN\n INFO = 5\n ELSE IF( INCY.EQ.0 )THEN\n INFO = 7\n ELSE IF( LDA.LT.MAX( 1, M ) )THEN\n INFO = 9\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'CGERC ', INFO )\n RETURN\n END IF\nc\nc Quick return if possible.\nc\n IF( ( M.EQ.0 ).OR.( N.EQ.0 ).OR.( ALPHA.EQ.ZERO ) )\n $ RETURN\nc\nc Start the operations. In this version the elements of A are\nc accessed sequentially with one pass through A.\nc\n IF( INCY.GT.0 )THEN\n JY = 1\n ELSE\n JY = 1 - ( N - 1 )*INCY\n END IF\n IF( INCX.EQ.1 )THEN\n DO 20, J = 1, N\n IF( Y( JY ).NE.ZERO )THEN\n TEMP = ALPHA*CONJG( Y( JY ) )\n DO 10, I = 1, M\n A( I, J ) = A( I, J ) + X( I )*TEMP\n 10 CONTINUE\n END IF\n JY = JY + INCY\n 20 CONTINUE\n ELSE\n IF( INCX.GT.0 )THEN\n KX = 1\n ELSE\n KX = 1 - ( M - 1 )*INCX\n END IF\n DO 40, J = 1, N\n IF( Y( JY ).NE.ZERO )THEN\n TEMP = ALPHA*CONJG( Y( JY ) )\n IX = KX\n DO 30, I = 1, M\n A( I, J ) = A( I, J ) + X( IX )*TEMP\n IX = IX + INCX\n 30 CONTINUE\n END IF\n JY = JY + INCY\n 40 CONTINUE\n END IF\nc\n RETURN\nc\nc End of CGERC .\nc\n END\n SUBROUTINE CGERU ( M, N, ALPHA, X, INCX, Y, INCY, A, LDA )\nc .. Scalar Arguments ..\n COMPLEX ALPHA\n INTEGER INCX, INCY, LDA, M, N\nc .. Array Arguments ..\n COMPLEX A( LDA, * ), X( * ), Y( * )\nc ..\nc\nc Purpose\nc =======\nc\nc CGERU performs the rank 1 operation\nc\nc A := alpha*x*y' + A,\nc\nc where alpha is a scalar, x is an m element vector, y is an n element\nc vector and A is an m by n matrix.\nc\nc Parameters\nc ==========\nc\nc M - INTEGER.\nc On entry, M specifies the number of rows of the matrix A.\nc M must be at least zero.\nc Unchanged on exit.\nc\nc N - INTEGER.\nc On entry, N specifies the number of columns of the matrix A.\nc N must be at least zero.\nc Unchanged on exit.\nc\nc ALPHA - COMPLEX .\nc On entry, ALPHA specifies the scalar alpha.\nc Unchanged on exit.\nc\nc X - COMPLEX array of dimension at least\nc ( 1 + ( m - 1 )*abs( INCX ) ).\nc Before entry, the incremented array X must contain the m\nc element vector x.\nc Unchanged on exit.\nc\nc INCX - INTEGER.\nc On entry, INCX specifies the increment for the elements of\nc X. INCX must not be zero.\nc Unchanged on exit.\nc\nc Y - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCY ) ).\nc Before entry, the incremented array Y must contain the n\nc element vector y.\nc Unchanged on exit.\nc\nc INCY - INTEGER.\nc On entry, INCY specifies the increment for the elements of\nc Y. INCY must not be zero.\nc Unchanged on exit.\nc\nc A - COMPLEX array of DIMENSION ( LDA, n ).\nc Before entry, the leading m by n part of the array A must\nc contain the matrix of coefficients. On exit, A is\nc overwritten by the updated matrix.\nc\nc LDA - INTEGER.\nc On entry, LDA specifies the first dimension of A as declared\nc in the calling (sub) program. LDA must be at least\nc max( 1, m ).\nc Unchanged on exit.\nc\nc\nc Level 2 Blas routine.\nc\nc -- Written by Sourangshu Ghosh\nc\nc\nc .. Parameters ..\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\nc .. Local Scalars ..\n COMPLEX TEMP\n INTEGER I, INFO, IX, J, JY, KX\nc .. External Subroutines ..\n EXTERNAL XERBLA\nc .. Intrinsic Functions ..\n INTRINSIC MAX\nc ..\nc .. Executable Statements ..\nc\nc Test the input parameters.\nc\n INFO = 0\n IF ( M.LT.0 )THEN\n INFO = 1\n ELSE IF( N.LT.0 )THEN\n INFO = 2\n ELSE IF( INCX.EQ.0 )THEN\n INFO = 5\n ELSE IF( INCY.EQ.0 )THEN\n INFO = 7\n ELSE IF( LDA.LT.MAX( 1, M ) )THEN\n INFO = 9\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'CGERU ', INFO )\n RETURN\n END IF\nc\nc Quick return if possible.\nc\n IF( ( M.EQ.0 ).OR.( N.EQ.0 ).OR.( ALPHA.EQ.ZERO ) )\n $ RETURN\nc\nc Start the operations. In this version the elements of A are\nc accessed sequentially with one pass through A.\nc\n IF( INCY.GT.0 )THEN\n JY = 1\n ELSE\n JY = 1 - ( N - 1 )*INCY\n END IF\n IF( INCX.EQ.1 )THEN\n DO 20, J = 1, N\n IF( Y( JY ).NE.ZERO )THEN\n TEMP = ALPHA*Y( JY )\n DO 10, I = 1, M\n A( I, J ) = A( I, J ) + X( I )*TEMP\n 10 CONTINUE\n END IF\n JY = JY + INCY\n 20 CONTINUE\n ELSE\n IF( INCX.GT.0 )THEN\n KX = 1\n ELSE\n KX = 1 - ( M - 1 )*INCX\n END IF\n DO 40, J = 1, N\n IF( Y( JY ).NE.ZERO )THEN\n TEMP = ALPHA*Y( JY )\n IX = KX\n DO 30, I = 1, M\n A( I, J ) = A( I, J ) + X( IX )*TEMP\n IX = IX + INCX\n 30 CONTINUE\n END IF\n JY = JY + INCY\n 40 CONTINUE\n END IF\nc\n RETURN\nc\nc End of CGERU .\nc\n END\n SUBROUTINE CHBMV ( UPLO, N, K, ALPHA, A, LDA, X, INCX,\n $ BETA, Y, INCY )\nc .. Scalar Arguments ..\n COMPLEX ALPHA, BETA\n INTEGER INCX, INCY, K, LDA, N\n CHARACTER*1 UPLO\nc .. Array Arguments ..\n COMPLEX A( LDA, * ), X( * ), Y( * )\nc ..\nc\nc Purpose\nc =======\nc\nc CHBMV performs the matrix-vector operation\nc\nc y := alpha*A*x + beta*y,\nc\nc where alpha and beta are scalars, x and y are n element vectors and\nc A is an n by n hermitian band matrix, with k super-diagonals.\nc\nc Parameters\nc ==========\nc\nc UPLO - CHARACTER*1.\nc On entry, UPLO specifies whether the upper or lower\nc triangular part of the band matrix A is being supplied as\nc follows:\nc\nc UPLO = 'U' or 'u' The upper triangular part of A is\nc being supplied.\nc\nc UPLO = 'L' or 'l' The lower triangular part of A is\nc being supplied.\nc\nc Unchanged on exit.\nc\nc N - INTEGER.\nc On entry, N specifies the order of the matrix A.\nc N must be at least zero.\nc Unchanged on exit.\nc\nc K - INTEGER.\nc On entry, K specifies the number of super-diagonals of the\nc matrix A. K must satisfy 0 .le. K.\nc Unchanged on exit.\nc\nc ALPHA - COMPLEX .\nc On entry, ALPHA specifies the scalar alpha.\nc Unchanged on exit.\nc\nc A - COMPLEX array of DIMENSION ( LDA, n ).\nc Before entry with UPLO = 'U' or 'u', the leading ( k + 1 )\nc by n part of the array A must contain the upper triangular\nc band part of the hermitian matrix, supplied column by\nc column, with the leading diagonal of the matrix in row\nc ( k + 1 ) of the array, the first super-diagonal starting at\nc position 2 in row k, and so on. The top left k by k triangle\nc of the array A is not referenced.\nc The following program segment will transfer the upper\nc triangular part of a hermitian band matrix from conventional\nc full matrix storage to band storage:\nc\nc DO 20, J = 1, N\nc M = K + 1 - J\nc DO 10, I = MAX( 1, J - K ), J\nc A( M + I, J ) = matrix( I, J )\nc 10 CONTINUE\nc 20 CONTINUE\nc\nc Before entry with UPLO = 'L' or 'l', the leading ( k + 1 )\nc by n part of the array A must contain the lower triangular\nc band part of the hermitian matrix, supplied column by\nc column, with the leading diagonal of the matrix in row 1 of\nc the array, the first sub-diagonal starting at position 1 in\nc row 2, and so on. The bottom right k by k triangle of the\nc array A is not referenced.\nc The following program segment will transfer the lower\nc triangular part of a hermitian band matrix from conventional\nc full matrix storage to band storage:\nc\nc DO 20, J = 1, N\nc M = 1 - J\nc DO 10, I = J, MIN( N, J + K )\nc A( M + I, J ) = matrix( I, J )\nc 10 CONTINUE\nc 20 CONTINUE\nc\nc Note that the imaginary parts of the diagonal elements need\nc not be set and are assumed to be zero.\nc Unchanged on exit.\nc\nc LDA - INTEGER.\nc On entry, LDA specifies the first dimension of A as declared\nc in the calling (sub) program. LDA must be at least\nc ( k + 1 ).\nc Unchanged on exit.\nc\nc X - COMPLEX array of DIMENSION at least\nc ( 1 + ( n - 1 )*abs( INCX ) ).\nc Before entry, the incremented array X must contain the\nc vector x.\nc Unchanged on exit.\nc\nc INCX - INTEGER.\nc On entry, INCX specifies the increment for the elements of\nc X. INCX must not be zero.\nc Unchanged on exit.\nc\nc BETA - COMPLEX .\nc On entry, BETA specifies the scalar beta.\nc Unchanged on exit.\nc\nc Y - COMPLEX array of DIMENSION at least\nc ( 1 + ( n - 1 )*abs( INCY ) ).\nc Before entry, the incremented array Y must contain the\nc vector y. On exit, Y is overwritten by the updated vector y.\nc\nc INCY - INTEGER.\nc On entry, INCY specifies the increment for the elements of\nc Y. INCY must not be zero.\nc Unchanged on exit.\nc\nc\nc Level 2 Blas routine.\nc\nc -- Written by Sourangshu Ghosh\nc\nc\nc .. Parameters ..\n COMPLEX ONE\n PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\nc .. Local Scalars ..\n COMPLEX TEMP1, TEMP2\n INTEGER I, INFO, IX, IY, J, JX, JY, KPLUS1, KX, KY, L\nc .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nc .. External Subroutines ..\n EXTERNAL XERBLA\nc .. Intrinsic Functions ..\n INTRINSIC CONJG, MAX, MIN, REAL\nc ..\nc .. Executable Statements ..\nc\nc Test the input parameters.\nc\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) )THEN\n INFO = 1\n ELSE IF( N.LT.0 )THEN\n INFO = 2\n ELSE IF( K.LT.0 )THEN\n INFO = 3\n ELSE IF( LDA.LT.( K + 1 ) )THEN\n INFO = 6\n ELSE IF( INCX.EQ.0 )THEN\n INFO = 8\n ELSE IF( INCY.EQ.0 )THEN\n INFO = 11\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'CHBMV ', INFO )\n RETURN\n END IF\nc\nc Quick return if possible.\nc\n IF( ( N.EQ.0 ).OR.( ( ALPHA.EQ.ZERO ).AND.( BETA.EQ.ONE ) ) )\n $ RETURN\nc\nc Set up the start points in X and Y.\nc\n IF( INCX.GT.0 )THEN\n KX = 1\n ELSE\n KX = 1 - ( N - 1 )*INCX\n END IF\n IF( INCY.GT.0 )THEN\n KY = 1\n ELSE\n KY = 1 - ( N - 1 )*INCY\n END IF\nc\nc Start the operations. In this version the elements of the array A\nc are accessed sequentially with one pass through A.\nc\nc First form y := beta*y.\nc\n IF( BETA.NE.ONE )THEN\n IF( INCY.EQ.1 )THEN\n IF( BETA.EQ.ZERO )THEN\n DO 10, I = 1, N\n Y( I ) = ZERO\n 10 CONTINUE\n ELSE\n DO 20, I = 1, N\n Y( I ) = BETA*Y( I )\n 20 CONTINUE\n END IF\n ELSE\n IY = KY\n IF( BETA.EQ.ZERO )THEN\n DO 30, I = 1, N\n Y( IY ) = ZERO\n IY = IY + INCY\n 30 CONTINUE\n ELSE\n DO 40, I = 1, N\n Y( IY ) = BETA*Y( IY )\n IY = IY + INCY\n 40 CONTINUE\n END IF\n END IF\n END IF\n IF( ALPHA.EQ.ZERO )\n $ RETURN\n IF( LSAME( UPLO, 'U' ) )THEN\nc\nc Form y when upper triangle of A is stored.\nc\n KPLUS1 = K + 1\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 60, J = 1, N\n TEMP1 = ALPHA*X( J )\n TEMP2 = ZERO\n L = KPLUS1 - J\n DO 50, I = MAX( 1, J - K ), J - 1\n Y( I ) = Y( I ) + TEMP1*A( L + I, J )\n TEMP2 = TEMP2 + CONJG( A( L + I, J ) )*X( I )\n 50 CONTINUE\n Y( J ) = Y( J ) + TEMP1*REAL( A( KPLUS1, J ) )\n $ + ALPHA*TEMP2\n 60 CONTINUE\n ELSE\n JX = KX\n JY = KY\n DO 80, J = 1, N\n TEMP1 = ALPHA*X( JX )\n TEMP2 = ZERO\n IX = KX\n IY = KY\n L = KPLUS1 - J\n DO 70, I = MAX( 1, J - K ), J - 1\n Y( IY ) = Y( IY ) + TEMP1*A( L + I, J )\n TEMP2 = TEMP2 + CONJG( A( L + I, J ) )*X( IX )\n IX = IX + INCX\n IY = IY + INCY\n 70 CONTINUE\n Y( JY ) = Y( JY ) + TEMP1*REAL( A( KPLUS1, J ) )\n $ + ALPHA*TEMP2\n JX = JX + INCX\n JY = JY + INCY\n IF( J.GT.K )THEN\n KX = KX + INCX\n KY = KY + INCY\n END IF\n 80 CONTINUE\n END IF\n ELSE\nc\nc Form y when lower triangle of A is stored.\nc\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 100, J = 1, N\n TEMP1 = ALPHA*X( J )\n TEMP2 = ZERO\n Y( J ) = Y( J ) + TEMP1*REAL( A( 1, J ) )\n L = 1 - J\n DO 90, I = J + 1, MIN( N, J + K )\n Y( I ) = Y( I ) + TEMP1*A( L + I, J )\n TEMP2 = TEMP2 + CONJG( A( L + I, J ) )*X( I )\n 90 CONTINUE\n Y( J ) = Y( J ) + ALPHA*TEMP2\n 100 CONTINUE\n ELSE\n JX = KX\n JY = KY\n DO 120, J = 1, N\n TEMP1 = ALPHA*X( JX )\n TEMP2 = ZERO\n Y( JY ) = Y( JY ) + TEMP1*REAL( A( 1, J ) )\n L = 1 - J\n IX = JX\n IY = JY\n DO 110, I = J + 1, MIN( N, J + K )\n IX = IX + INCX\n IY = IY + INCY\n Y( IY ) = Y( IY ) + TEMP1*A( L + I, J )\n TEMP2 = TEMP2 + CONJG( A( L + I, J ) )*X( IX )\n 110 CONTINUE\n Y( JY ) = Y( JY ) + ALPHA*TEMP2\n JX = JX + INCX\n JY = JY + INCY\n 120 CONTINUE\n END IF\n END IF\nc\n RETURN\nc\nc End of CHBMV .\nc\n END\n SUBROUTINE CHEMV ( UPLO, N, ALPHA, A, LDA, X, INCX,\n $ BETA, Y, INCY )\nc .. Scalar Arguments ..\n COMPLEX ALPHA, BETA\n INTEGER INCX, INCY, LDA, N\n CHARACTER*1 UPLO\nc .. Array Arguments ..\n COMPLEX A( LDA, * ), X( * ), Y( * )\nc ..\nc\nc Purpose\nc =======\nc\nc CHEMV performs the matrix-vector operation\nc\nc y := alpha*A*x + beta*y,\nc\nc where alpha and beta are scalars, x and y are n element vectors and\nc A is an n by n hermitian matrix.\nc\nc Parameters\nc ==========\nc\nc UPLO - CHARACTER*1.\nc On entry, UPLO specifies whether the upper or lower\nc triangular part of the array A is to be referenced as\nc follows:\nc\nc UPLO = 'U' or 'u' Only the upper triangular part of A\nc is to be referenced.\nc\nc UPLO = 'L' or 'l' Only the lower triangular part of A\nc is to be referenced.\nc\nc Unchanged on exit.\nc\nc N - INTEGER.\nc On entry, N specifies the order of the matrix A.\nc N must be at least zero.\nc Unchanged on exit.\nc\nc ALPHA - COMPLEX .\nc On entry, ALPHA specifies the scalar alpha.\nc Unchanged on exit.\nc\nc A - COMPLEX array of DIMENSION ( LDA, n ).\nc Before entry with UPLO = 'U' or 'u', the leading n by n\nc upper triangular part of the array A must contain the upper\nc triangular part of the hermitian matrix and the strictly\nc lower triangular part of A is not referenced.\nc Before entry with UPLO = 'L' or 'l', the leading n by n\nc lower triangular part of the array A must contain the lower\nc triangular part of the hermitian matrix and the strictly\nc upper triangular part of A is not referenced.\nc Note that the imaginary parts of the diagonal elements need\nc not be set and are assumed to be zero.\nc Unchanged on exit.\nc\nc LDA - INTEGER.\nc On entry, LDA specifies the first dimension of A as declared\nc in the calling (sub) program. LDA must be at least\nc max( 1, n ).\nc Unchanged on exit.\nc\nc X - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCX ) ).\nc Before entry, the incremented array X must contain the n\nc element vector x.\nc Unchanged on exit.\nc\nc INCX - INTEGER.\nc On entry, INCX specifies the increment for the elements of\nc X. INCX must not be zero.\nc Unchanged on exit.\nc\nc BETA - COMPLEX .\nc On entry, BETA specifies the scalar beta. When BETA is\nc supplied as zero then Y need not be set on input.\nc Unchanged on exit.\nc\nc Y - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCY ) ).\nc Before entry, the incremented array Y must contain the n\nc element vector y. On exit, Y is overwritten by the updated\nc vector y.\nc\nc INCY - INTEGER.\nc On entry, INCY specifies the increment for the elements of\nc Y. INCY must not be zero.\nc Unchanged on exit.\nc\nc\nc Level 2 Blas routine.\nc\nc -- Written by Sourangshu Ghosh\nc\nc\nc .. Parameters ..\n COMPLEX ONE\n PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\nc .. Local Scalars ..\n COMPLEX TEMP1, TEMP2\n INTEGER I, INFO, IX, IY, J, JX, JY, KX, KY\nc .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nc .. External Subroutines ..\n EXTERNAL XERBLA\nc .. Intrinsic Functions ..\n INTRINSIC CONJG, MAX, REAL\nc ..\nc .. Executable Statements ..\nc\nc Test the input parameters.\nc\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) )THEN\n INFO = 1\n ELSE IF( N.LT.0 )THEN\n INFO = 2\n ELSE IF( LDA.LT.MAX( 1, N ) )THEN\n INFO = 5\n ELSE IF( INCX.EQ.0 )THEN\n INFO = 7\n ELSE IF( INCY.EQ.0 )THEN\n INFO = 10\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'CHEMV ', INFO )\n RETURN\n END IF\nc\nc Quick return if possible.\nc\n IF( ( N.EQ.0 ).OR.( ( ALPHA.EQ.ZERO ).AND.( BETA.EQ.ONE ) ) )\n $ RETURN\nc\nc Set up the start points in X and Y.\nc\n IF( INCX.GT.0 )THEN\n KX = 1\n ELSE\n KX = 1 - ( N - 1 )*INCX\n END IF\n IF( INCY.GT.0 )THEN\n KY = 1\n ELSE\n KY = 1 - ( N - 1 )*INCY\n END IF\nc\nc Start the operations. In this version the elements of A are\nc accessed sequentially with one pass through the triangular part\nc of A.\nc\nc First form y := beta*y.\nc\n IF( BETA.NE.ONE )THEN\n IF( INCY.EQ.1 )THEN\n IF( BETA.EQ.ZERO )THEN\n DO 10, I = 1, N\n Y( I ) = ZERO\n 10 CONTINUE\n ELSE\n DO 20, I = 1, N\n Y( I ) = BETA*Y( I )\n 20 CONTINUE\n END IF\n ELSE\n IY = KY\n IF( BETA.EQ.ZERO )THEN\n DO 30, I = 1, N\n Y( IY ) = ZERO\n IY = IY + INCY\n 30 CONTINUE\n ELSE\n DO 40, I = 1, N\n Y( IY ) = BETA*Y( IY )\n IY = IY + INCY\n 40 CONTINUE\n END IF\n END IF\n END IF\n IF( ALPHA.EQ.ZERO )\n $ RETURN\n IF( LSAME( UPLO, 'U' ) )THEN\nc\nc Form y when A is stored in upper triangle.\nc\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 60, J = 1, N\n TEMP1 = ALPHA*X( J )\n TEMP2 = ZERO\n DO 50, I = 1, J - 1\n Y( I ) = Y( I ) + TEMP1*A( I, J )\n TEMP2 = TEMP2 + CONJG( A( I, J ) )*X( I )\n 50 CONTINUE\n Y( J ) = Y( J ) + TEMP1*REAL( A( J, J ) ) + ALPHA*TEMP2\n 60 CONTINUE\n ELSE\n JX = KX\n JY = KY\n DO 80, J = 1, N\n TEMP1 = ALPHA*X( JX )\n TEMP2 = ZERO\n IX = KX\n IY = KY\n DO 70, I = 1, J - 1\n Y( IY ) = Y( IY ) + TEMP1*A( I, J )\n TEMP2 = TEMP2 + CONJG( A( I, J ) )*X( IX )\n IX = IX + INCX\n IY = IY + INCY\n 70 CONTINUE\n Y( JY ) = Y( JY ) + TEMP1*REAL( A( J, J ) ) + ALPHA*TEMP2\n JX = JX + INCX\n JY = JY + INCY\n 80 CONTINUE\n END IF\n ELSE\nc\nc Form y when A is stored in lower triangle.\nc\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 100, J = 1, N\n TEMP1 = ALPHA*X( J )\n TEMP2 = ZERO\n Y( J ) = Y( J ) + TEMP1*REAL( A( J, J ) )\n DO 90, I = J + 1, N\n Y( I ) = Y( I ) + TEMP1*A( I, J )\n TEMP2 = TEMP2 + CONJG( A( I, J ) )*X( I )\n 90 CONTINUE\n Y( J ) = Y( J ) + ALPHA*TEMP2\n 100 CONTINUE\n ELSE\n JX = KX\n JY = KY\n DO 120, J = 1, N\n TEMP1 = ALPHA*X( JX )\n TEMP2 = ZERO\n Y( JY ) = Y( JY ) + TEMP1*REAL( A( J, J ) )\n IX = JX\n IY = JY\n DO 110, I = J + 1, N\n IX = IX + INCX\n IY = IY + INCY\n Y( IY ) = Y( IY ) + TEMP1*A( I, J )\n TEMP2 = TEMP2 + CONJG( A( I, J ) )*X( IX )\n 110 CONTINUE\n Y( JY ) = Y( JY ) + ALPHA*TEMP2\n JX = JX + INCX\n JY = JY + INCY\n 120 CONTINUE\n END IF\n END IF\nc\n RETURN\nc\nc End of CHEMV .\nc\n END\n SUBROUTINE CHER2 ( UPLO, N, ALPHA, X, INCX, Y, INCY, A, LDA )\nc .. Scalar Arguments ..\n COMPLEX ALPHA\n INTEGER INCX, INCY, LDA, N\n CHARACTER*1 UPLO\nc .. Array Arguments ..\n COMPLEX A( LDA, * ), X( * ), Y( * )\nc ..\nc\nc Purpose\nc =======\nc\nc CHER2 performs the hermitian rank 2 operation\nc\nc A := alpha*x*conjg( y' ) + conjg( alpha )*y*conjg( x' ) + A,\nc\nc where alpha is a scalar, x and y are n element vectors and A is an n\nc by n hermitian matrix.\nc\nc Parameters\nc ==========\nc\nc UPLO - CHARACTER*1.\nc On entry, UPLO specifies whether the upper or lower\nc triangular part of the array A is to be referenced as\nc follows:\nc\nc UPLO = 'U' or 'u' Only the upper triangular part of A\nc is to be referenced.\nc\nc UPLO = 'L' or 'l' Only the lower triangular part of A\nc is to be referenced.\nc\nc Unchanged on exit.\nc\nc N - INTEGER.\nc On entry, N specifies the order of the matrix A.\nc N must be at least zero.\nc Unchanged on exit.\nc\nc ALPHA - COMPLEX .\nc On entry, ALPHA specifies the scalar alpha.\nc Unchanged on exit.\nc\nc X - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCX ) ).\nc Before entry, the incremented array X must contain the n\nc element vector x.\nc Unchanged on exit.\nc\nc INCX - INTEGER.\nc On entry, INCX specifies the increment for the elements of\nc X. INCX must not be zero.\nc Unchanged on exit.\nc\nc Y - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCY ) ).\nc Before entry, the incremented array Y must contain the n\nc element vector y.\nc Unchanged on exit.\nc\nc INCY - INTEGER.\nc On entry, INCY specifies the increment for the elements of\nc Y. INCY must not be zero.\nc Unchanged on exit.\nc\nc A - COMPLEX array of DIMENSION ( LDA, n ).\nc Before entry with UPLO = 'U' or 'u', the leading n by n\nc upper triangular part of the array A must contain the upper\nc triangular part of the hermitian matrix and the strictly\nc lower triangular part of A is not referenced. On exit, the\nc upper triangular part of the array A is overwritten by the\nc upper triangular part of the updated matrix.\nc Before entry with UPLO = 'L' or 'l', the leading n by n\nc lower triangular part of the array A must contain the lower\nc triangular part of the hermitian matrix and the strictly\nc upper triangular part of A is not referenced. On exit, the\nc lower triangular part of the array A is overwritten by the\nc lower triangular part of the updated matrix.\nc Note that the imaginary parts of the diagonal elements need\nc not be set, they are assumed to be zero, and on exit they\nc are set to zero.\nc\nc LDA - INTEGER.\nc On entry, LDA specifies the first dimension of A as declared\nc in the calling (sub) program. LDA must be at least\nc max( 1, n ).\nc Unchanged on exit.\nc\nc\nc Level 2 Blas routine.\nc\nc -- Written by Sourangshu Ghosh\nc\nc\nc .. Parameters ..\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\nc .. Local Scalars ..\n COMPLEX TEMP1, TEMP2\n INTEGER I, INFO, IX, IY, J, JX, JY, KX, KY\nc .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nc .. External Subroutines ..\n EXTERNAL XERBLA\nc .. Intrinsic Functions ..\n INTRINSIC CONJG, MAX, REAL\nc ..\nc .. Executable Statements ..\nc\nc Test the input parameters.\nc\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) )THEN\n INFO = 1\n ELSE IF( N.LT.0 )THEN\n INFO = 2\n ELSE IF( INCX.EQ.0 )THEN\n INFO = 5\n ELSE IF( INCY.EQ.0 )THEN\n INFO = 7\n ELSE IF( LDA.LT.MAX( 1, N ) )THEN\n INFO = 9\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'CHER2 ', INFO )\n RETURN\n END IF\nc\nc Quick return if possible.\nc\n IF( ( N.EQ.0 ).OR.( ALPHA.EQ.ZERO ) )\n $ RETURN\nc\nc Set up the start points in X and Y if the increments are not both\nc unity.\nc\n IF( ( INCX.NE.1 ).OR.( INCY.NE.1 ) )THEN\n IF( INCX.GT.0 )THEN\n KX = 1\n ELSE\n KX = 1 - ( N - 1 )*INCX\n END IF\n IF( INCY.GT.0 )THEN\n KY = 1\n ELSE\n KY = 1 - ( N - 1 )*INCY\n END IF\n JX = KX\n JY = KY\n END IF\nc\nc Start the operations. In this version the elements of A are\nc accessed sequentially with one pass through the triangular part\nc of A.\nc\n IF( LSAME( UPLO, 'U' ) )THEN\nc\nc Form A when A is stored in the upper triangle.\nc\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 20, J = 1, N\n IF( ( X( J ).NE.ZERO ).OR.( Y( J ).NE.ZERO ) )THEN\n TEMP1 = ALPHA*CONJG( Y( J ) )\n TEMP2 = CONJG( ALPHA*X( J ) )\n DO 10, I = 1, J - 1\n A( I, J ) = A( I, J ) + X( I )*TEMP1 + Y( I )*TEMP2\n 10 CONTINUE\n A( J, J ) = REAL( A( J, J ) ) +\n $ REAL( X( J )*TEMP1 + Y( J )*TEMP2 )\n ELSE\n A( J, J ) = REAL( A( J, J ) )\n END IF\n 20 CONTINUE\n ELSE\n DO 40, J = 1, N\n IF( ( X( JX ).NE.ZERO ).OR.( Y( JY ).NE.ZERO ) )THEN\n TEMP1 = ALPHA*CONJG( Y( JY ) )\n TEMP2 = CONJG( ALPHA*X( JX ) )\n IX = KX\n IY = KY\n DO 30, I = 1, J - 1\n A( I, J ) = A( I, J ) + X( IX )*TEMP1\n $ + Y( IY )*TEMP2\n IX = IX + INCX\n IY = IY + INCY\n 30 CONTINUE\n A( J, J ) = REAL( A( J, J ) ) +\n $ REAL( X( JX )*TEMP1 + Y( JY )*TEMP2 )\n ELSE\n A( J, J ) = REAL( A( J, J ) )\n END IF\n JX = JX + INCX\n JY = JY + INCY\n 40 CONTINUE\n END IF\n ELSE\nc\nc Form A when A is stored in the lower triangle.\nc\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 60, J = 1, N\n IF( ( X( J ).NE.ZERO ).OR.( Y( J ).NE.ZERO ) )THEN\n TEMP1 = ALPHA*CONJG( Y( J ) )\n TEMP2 = CONJG( ALPHA*X( J ) )\n A( J, J ) = REAL( A( J, J ) ) +\n $ REAL( X( J )*TEMP1 + Y( J )*TEMP2 )\n DO 50, I = J + 1, N\n A( I, J ) = A( I, J ) + X( I )*TEMP1 + Y( I )*TEMP2\n 50 CONTINUE\n ELSE\n A( J, J ) = REAL( A( J, J ) )\n END IF\n 60 CONTINUE\n ELSE\n DO 80, J = 1, N\n IF( ( X( JX ).NE.ZERO ).OR.( Y( JY ).NE.ZERO ) )THEN\n TEMP1 = ALPHA*CONJG( Y( JY ) )\n TEMP2 = CONJG( ALPHA*X( JX ) )\n A( J, J ) = REAL( A( J, J ) ) +\n $ REAL( X( JX )*TEMP1 + Y( JY )*TEMP2 )\n IX = JX\n IY = JY\n DO 70, I = J + 1, N\n IX = IX + INCX\n IY = IY + INCY\n A( I, J ) = A( I, J ) + X( IX )*TEMP1\n $ + Y( IY )*TEMP2\n 70 CONTINUE\n ELSE\n A( J, J ) = REAL( A( J, J ) )\n END IF\n JX = JX + INCX\n JY = JY + INCY\n 80 CONTINUE\n END IF\n END IF\nc\n RETURN\nc\nc End of CHER2 .\nc\n END\n SUBROUTINE CHER ( UPLO, N, ALPHA, X, INCX, A, LDA )\nc .. Scalar Arguments ..\n REAL ALPHA\n INTEGER INCX, LDA, N\n CHARACTER*1 UPLO\nc .. Array Arguments ..\n COMPLEX A( LDA, * ), X( * )\nc ..\nc\nc Purpose\nc =======\nc\nc CHER performs the hermitian rank 1 operation\nc\nc A := alpha*x*conjg( x' ) + A,\nc\nc where alpha is a real scalar, x is an n element vector and A is an\nc n by n hermitian matrix.\nc\nc Parameters\nc ==========\nc\nc UPLO - CHARACTER*1.\nc On entry, UPLO specifies whether the upper or lower\nc triangular part of the array A is to be referenced as\nc follows:\nc\nc UPLO = 'U' or 'u' Only the upper triangular part of A\nc is to be referenced.\nc\nc UPLO = 'L' or 'l' Only the lower triangular part of A\nc is to be referenced.\nc\nc Unchanged on exit.\nc\nc N - INTEGER.\nc On entry, N specifies the order of the matrix A.\nc N must be at least zero.\nc Unchanged on exit.\nc\nc ALPHA - REAL .\nc On entry, ALPHA specifies the scalar alpha.\nc Unchanged on exit.\nc\nc X - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCX ) ).\nc Before entry, the incremented array X must contain the n\nc element vector x.\nc Unchanged on exit.\nc\nc INCX - INTEGER.\nc On entry, INCX specifies the increment for the elements of\nc X. INCX must not be zero.\nc Unchanged on exit.\nc\nc A - COMPLEX array of DIMENSION ( LDA, n ).\nc Before entry with UPLO = 'U' or 'u', the leading n by n\nc upper triangular part of the array A must contain the upper\nc triangular part of the hermitian matrix and the strictly\nc lower triangular part of A is not referenced. On exit, the\nc upper triangular part of the array A is overwritten by the\nc upper triangular part of the updated matrix.\nc Before entry with UPLO = 'L' or 'l', the leading n by n\nc lower triangular part of the array A must contain the lower\nc triangular part of the hermitian matrix and the strictly\nc upper triangular part of A is not referenced. On exit, the\nc lower triangular part of the array A is overwritten by the\nc lower triangular part of the updated matrix.\nc Note that the imaginary parts of the diagonal elements need\nc not be set, they are assumed to be zero, and on exit they\nc are set to zero.\nc\nc LDA - INTEGER.\nc On entry, LDA specifies the first dimension of A as declared\nc in the calling (sub) program. LDA must be at least\nc max( 1, n ).\nc Unchanged on exit.\nc\nc\nc Level 2 Blas routine.\nc\nc -- Written by Sourangshu Ghosh\nc\nc\nc .. Parameters ..\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\nc .. Local Scalars ..\n COMPLEX TEMP\n INTEGER I, INFO, IX, J, JX, KX\nc .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nc .. External Subroutines ..\n EXTERNAL XERBLA\nc .. Intrinsic Functions ..\n INTRINSIC CONJG, MAX, REAL\nc ..\nc .. Executable Statements ..\nc\nc Test the input parameters.\nc\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) )THEN\n INFO = 1\n ELSE IF( N.LT.0 )THEN\n INFO = 2\n ELSE IF( INCX.EQ.0 )THEN\n INFO = 5\n ELSE IF( LDA.LT.MAX( 1, N ) )THEN\n INFO = 7\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'CHER ', INFO )\n RETURN\n END IF\nc\nc Quick return if possible.\nc\n IF( ( N.EQ.0 ).OR.( ALPHA.EQ.REAL( ZERO ) ) )\n $ RETURN\nc\nc Set the start point in X if the increment is not unity.\nc\n IF( INCX.LE.0 )THEN\n KX = 1 - ( N - 1 )*INCX\n ELSE IF( INCX.NE.1 )THEN\n KX = 1\n END IF\nc\nc Start the operations. In this version the elements of A are\nc accessed sequentially with one pass through the triangular part\nc of A.\nc\n IF( LSAME( UPLO, 'U' ) )THEN\nc\nc Form A when A is stored in upper triangle.\nc\n IF( INCX.EQ.1 )THEN\n DO 20, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n TEMP = ALPHA*CONJG( X( J ) )\n DO 10, I = 1, J - 1\n A( I, J ) = A( I, J ) + X( I )*TEMP\n 10 CONTINUE\n A( J, J ) = REAL( A( J, J ) ) + REAL( X( J )*TEMP )\n ELSE\n A( J, J ) = REAL( A( J, J ) )\n END IF\n 20 CONTINUE\n ELSE\n JX = KX\n DO 40, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n TEMP = ALPHA*CONJG( X( JX ) )\n IX = KX\n DO 30, I = 1, J - 1\n A( I, J ) = A( I, J ) + X( IX )*TEMP\n IX = IX + INCX\n 30 CONTINUE\n A( J, J ) = REAL( A( J, J ) ) + REAL( X( JX )*TEMP )\n ELSE\n A( J, J ) = REAL( A( J, J ) )\n END IF\n JX = JX + INCX\n 40 CONTINUE\n END IF\n ELSE\nc\nc Form A when A is stored in lower triangle.\nc\n IF( INCX.EQ.1 )THEN\n DO 60, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n TEMP = ALPHA*CONJG( X( J ) )\n A( J, J ) = REAL( A( J, J ) ) + REAL( TEMP*X( J ) )\n DO 50, I = J + 1, N\n A( I, J ) = A( I, J ) + X( I )*TEMP\n 50 CONTINUE\n ELSE\n A( J, J ) = REAL( A( J, J ) )\n END IF\n 60 CONTINUE\n ELSE\n JX = KX\n DO 80, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n TEMP = ALPHA*CONJG( X( JX ) )\n A( J, J ) = REAL( A( J, J ) ) + REAL( TEMP*X( JX ) )\n IX = JX\n DO 70, I = J + 1, N\n IX = IX + INCX\n A( I, J ) = A( I, J ) + X( IX )*TEMP\n 70 CONTINUE\n ELSE\n A( J, J ) = REAL( A( J, J ) )\n END IF\n JX = JX + INCX\n 80 CONTINUE\n END IF\n END IF\nc\n RETURN\nc\nc End of CHER .\nc\n END\n SUBROUTINE CHPMV ( UPLO, N, ALPHA, AP, X, INCX, BETA, Y, INCY )\nc .. Scalar Arguments ..\n COMPLEX ALPHA, BETA\n INTEGER INCX, INCY, N\n CHARACTER*1 UPLO\nc .. Array Arguments ..\n COMPLEX AP( * ), X( * ), Y( * )\nc ..\nc\nc Purpose\nc =======\nc\nc CHPMV performs the matrix-vector operation\nc\nc y := alpha*A*x + beta*y,\nc\nc where alpha and beta are scalars, x and y are n element vectors and\nc A is an n by n hermitian matrix, supplied in packed form.\nc\nc Parameters\nc ==========\nc\nc UPLO - CHARACTER*1.\nc On entry, UPLO specifies whether the upper or lower\nc triangular part of the matrix A is supplied in the packed\nc array AP as follows:\nc\nc UPLO = 'U' or 'u' The upper triangular part of A is\nc supplied in AP.\nc\nc UPLO = 'L' or 'l' The lower triangular part of A is\nc supplied in AP.\nc\nc Unchanged on exit.\nc\nc N - INTEGER.\nc On entry, N specifies the order of the matrix A.\nc N must be at least zero.\nc Unchanged on exit.\nc\nc ALPHA - COMPLEX .\nc On entry, ALPHA specifies the scalar alpha.\nc Unchanged on exit.\nc\nc AP - COMPLEX array of DIMENSION at least\nc ( ( n*( n + 1 ) )/2 ).\nc Before entry with UPLO = 'U' or 'u', the array AP must\nc contain the upper triangular part of the hermitian matrix\nc packed sequentially, column by column, so that AP( 1 )\nc contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 1, 2 )\nc and a( 2, 2 ) respectively, and so on.\nc Before entry with UPLO = 'L' or 'l', the array AP must\nc contain the lower triangular part of the hermitian matrix\nc packed sequentially, column by column, so that AP( 1 )\nc contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 2, 1 )\nc and a( 3, 1 ) respectively, and so on.\nc Note that the imaginary parts of the diagonal elements need\nc not be set and are assumed to be zero.\nc Unchanged on exit.\nc\nc X - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCX ) ).\nc Before entry, the incremented array X must contain the n\nc element vector x.\nc Unchanged on exit.\nc\nc INCX - INTEGER.\nc On entry, INCX specifies the increment for the elements of\nc X. INCX must not be zero.\nc Unchanged on exit.\nc\nc BETA - COMPLEX .\nc On entry, BETA specifies the scalar beta. When BETA is\nc supplied as zero then Y need not be set on input.\nc Unchanged on exit.\nc\nc Y - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCY ) ).\nc Before entry, the incremented array Y must contain the n\nc element vector y. On exit, Y is overwritten by the updated\nc vector y.\nc\nc INCY - INTEGER.\nc On entry, INCY specifies the increment for the elements of\nc Y. INCY must not be zero.\nc Unchanged on exit.\nc\nc\nc Level 2 Blas routine.\nc\nc -- Written by Sourangshu Ghosh\nc\nc\nc .. Parameters ..\n COMPLEX ONE\n PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\nc .. Local Scalars ..\n COMPLEX TEMP1, TEMP2\n INTEGER I, INFO, IX, IY, J, JX, JY, K, KK, KX, KY\nc .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nc .. External Subroutines ..\n EXTERNAL XERBLA\nc .. Intrinsic Functions ..\n INTRINSIC CONJG, REAL\nc ..\nc .. Executable Statements ..\nc\nc Test the input parameters.\nc\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) )THEN\n INFO = 1\n ELSE IF( N.LT.0 )THEN\n INFO = 2\n ELSE IF( INCX.EQ.0 )THEN\n INFO = 6\n ELSE IF( INCY.EQ.0 )THEN\n INFO = 9\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'CHPMV ', INFO )\n RETURN\n END IF\nc\nc Quick return if possible.\nc\n IF( ( N.EQ.0 ).OR.( ( ALPHA.EQ.ZERO ).AND.( BETA.EQ.ONE ) ) )\n $ RETURN\nc\nc Set up the start points in X and Y.\nc\n IF( INCX.GT.0 )THEN\n KX = 1\n ELSE\n KX = 1 - ( N - 1 )*INCX\n END IF\n IF( INCY.GT.0 )THEN\n KY = 1\n ELSE\n KY = 1 - ( N - 1 )*INCY\n END IF\nc\nc Start the operations. In this version the elements of the array AP\nc are accessed sequentially with one pass through AP.\nc\nc First form y := beta*y.\nc\n IF( BETA.NE.ONE )THEN\n IF( INCY.EQ.1 )THEN\n IF( BETA.EQ.ZERO )THEN\n DO 10, I = 1, N\n Y( I ) = ZERO\n 10 CONTINUE\n ELSE\n DO 20, I = 1, N\n Y( I ) = BETA*Y( I )\n 20 CONTINUE\n END IF\n ELSE\n IY = KY\n IF( BETA.EQ.ZERO )THEN\n DO 30, I = 1, N\n Y( IY ) = ZERO\n IY = IY + INCY\n 30 CONTINUE\n ELSE\n DO 40, I = 1, N\n Y( IY ) = BETA*Y( IY )\n IY = IY + INCY\n 40 CONTINUE\n END IF\n END IF\n END IF\n IF( ALPHA.EQ.ZERO )\n $ RETURN\n KK = 1\n IF( LSAME( UPLO, 'U' ) )THEN\nc\nc Form y when AP contains the upper triangle.\nc\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 60, J = 1, N\n TEMP1 = ALPHA*X( J )\n TEMP2 = ZERO\n K = KK\n DO 50, I = 1, J - 1\n Y( I ) = Y( I ) + TEMP1*AP( K )\n TEMP2 = TEMP2 + CONJG( AP( K ) )*X( I )\n K = K + 1\n 50 CONTINUE\n Y( J ) = Y( J ) + TEMP1*REAL( AP( KK + J - 1 ) )\n $ + ALPHA*TEMP2\n KK = KK + J\n 60 CONTINUE\n ELSE\n JX = KX\n JY = KY\n DO 80, J = 1, N\n TEMP1 = ALPHA*X( JX )\n TEMP2 = ZERO\n IX = KX\n IY = KY\n DO 70, K = KK, KK + J - 2\n Y( IY ) = Y( IY ) + TEMP1*AP( K )\n TEMP2 = TEMP2 + CONJG( AP( K ) )*X( IX )\n IX = IX + INCX\n IY = IY + INCY\n 70 CONTINUE\n Y( JY ) = Y( JY ) + TEMP1*REAL( AP( KK + J - 1 ) )\n $ + ALPHA*TEMP2\n JX = JX + INCX\n JY = JY + INCY\n KK = KK + J\n 80 CONTINUE\n END IF\n ELSE\nc\nc Form y when AP contains the lower triangle.\nc\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 100, J = 1, N\n TEMP1 = ALPHA*X( J )\n TEMP2 = ZERO\n Y( J ) = Y( J ) + TEMP1*REAL( AP( KK ) )\n K = KK + 1\n DO 90, I = J + 1, N\n Y( I ) = Y( I ) + TEMP1*AP( K )\n TEMP2 = TEMP2 + CONJG( AP( K ) )*X( I )\n K = K + 1\n 90 CONTINUE\n Y( J ) = Y( J ) + ALPHA*TEMP2\n KK = KK + ( N - J + 1 )\n 100 CONTINUE\n ELSE\n JX = KX\n JY = KY\n DO 120, J = 1, N\n TEMP1 = ALPHA*X( JX )\n TEMP2 = ZERO\n Y( JY ) = Y( JY ) + TEMP1*REAL( AP( KK ) )\n IX = JX\n IY = JY\n DO 110, K = KK + 1, KK + N - J\n IX = IX + INCX\n IY = IY + INCY\n Y( IY ) = Y( IY ) + TEMP1*AP( K )\n TEMP2 = TEMP2 + CONJG( AP( K ) )*X( IX )\n 110 CONTINUE\n Y( JY ) = Y( JY ) + ALPHA*TEMP2\n JX = JX + INCX\n JY = JY + INCY\n KK = KK + ( N - J + 1 )\n 120 CONTINUE\n END IF\n END IF\nc\n RETURN\nc\nc End of CHPMV .\nc\n END\n SUBROUTINE CHPR2 ( UPLO, N, ALPHA, X, INCX, Y, INCY, AP )\nc .. Scalar Arguments ..\n COMPLEX ALPHA\n INTEGER INCX, INCY, N\n CHARACTER*1 UPLO\nc .. Array Arguments ..\n COMPLEX AP( * ), X( * ), Y( * )\nc ..\nc\nc Purpose\nc =======\nc\nc CHPR2 performs the hermitian rank 2 operation\nc\nc A := alpha*x*conjg( y' ) + conjg( alpha )*y*conjg( x' ) + A,\nc\nc where alpha is a scalar, x and y are n element vectors and A is an\nc n by n hermitian matrix, supplied in packed form.\nc\nc Parameters\nc ==========\nc\nc UPLO - CHARACTER*1.\nc On entry, UPLO specifies whether the upper or lower\nc triangular part of the matrix A is supplied in the packed\nc array AP as follows:\nc\nc UPLO = 'U' or 'u' The upper triangular part of A is\nc supplied in AP.\nc\nc UPLO = 'L' or 'l' The lower triangular part of A is\nc supplied in AP.\nc\nc Unchanged on exit.\nc\nc N - INTEGER.\nc On entry, N specifies the order of the matrix A.\nc N must be at least zero.\nc Unchanged on exit.\nc\nc ALPHA - COMPLEX .\nc On entry, ALPHA specifies the scalar alpha.\nc Unchanged on exit.\nc\nc X - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCX ) ).\nc Before entry, the incremented array X must contain the n\nc element vector x.\nc Unchanged on exit.\nc\nc INCX - INTEGER.\nc On entry, INCX specifies the increment for the elements of\nc X. INCX must not be zero.\nc Unchanged on exit.\nc\nc Y - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCY ) ).\nc Before entry, the incremented array Y must contain the n\nc element vector y.\nc Unchanged on exit.\nc\nc INCY - INTEGER.\nc On entry, INCY specifies the increment for the elements of\nc Y. INCY must not be zero.\nc Unchanged on exit.\nc\nc AP - COMPLEX array of DIMENSION at least\nc ( ( n*( n + 1 ) )/2 ).\nc Before entry with UPLO = 'U' or 'u', the array AP must\nc contain the upper triangular part of the hermitian matrix\nc packed sequentially, column by column, so that AP( 1 )\nc contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 1, 2 )\nc and a( 2, 2 ) respectively, and so on. On exit, the array\nc AP is overwritten by the upper triangular part of the\nc updated matrix.\nc Before entry with UPLO = 'L' or 'l', the array AP must\nc contain the lower triangular part of the hermitian matrix\nc packed sequentially, column by column, so that AP( 1 )\nc contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 2, 1 )\nc and a( 3, 1 ) respectively, and so on. On exit, the array\nc AP is overwritten by the lower triangular part of the\nc updated matrix.\nc Note that the imaginary parts of the diagonal elements need\nc not be set, they are assumed to be zero, and on exit they\nc are set to zero.\nc\nc\nc Level 2 Blas routine.\nc\nc -- Written by Sourangshu Ghosh\nc\nc\nc .. Parameters ..\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\nc .. Local Scalars ..\n COMPLEX TEMP1, TEMP2\n INTEGER I, INFO, IX, IY, J, JX, JY, K, KK, KX, KY\nc .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nc .. External Subroutines ..\n EXTERNAL XERBLA\nc .. Intrinsic Functions ..\n INTRINSIC CONJG, REAL\nc ..\nc .. Executable Statements ..\nc\nc Test the input parameters.\nc\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) )THEN\n INFO = 1\n ELSE IF( N.LT.0 )THEN\n INFO = 2\n ELSE IF( INCX.EQ.0 )THEN\n INFO = 5\n ELSE IF( INCY.EQ.0 )THEN\n INFO = 7\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'CHPR2 ', INFO )\n RETURN\n END IF\nc\nc Quick return if possible.\nc\n IF( ( N.EQ.0 ).OR.( ALPHA.EQ.ZERO ) )\n $ RETURN\nc\nc Set up the start points in X and Y if the increments are not both\nc unity.\nc\n IF( ( INCX.NE.1 ).OR.( INCY.NE.1 ) )THEN\n IF( INCX.GT.0 )THEN\n KX = 1\n ELSE\n KX = 1 - ( N - 1 )*INCX\n END IF\n IF( INCY.GT.0 )THEN\n KY = 1\n ELSE\n KY = 1 - ( N - 1 )*INCY\n END IF\n JX = KX\n JY = KY\n END IF\nc\nc Start the operations. In this version the elements of the array AP\nc are accessed sequentially with one pass through AP.\nc\n KK = 1\n IF( LSAME( UPLO, 'U' ) )THEN\nc\nc Form A when upper triangle is stored in AP.\nc\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 20, J = 1, N\n IF( ( X( J ).NE.ZERO ).OR.( Y( J ).NE.ZERO ) )THEN\n TEMP1 = ALPHA*CONJG( Y( J ) )\n TEMP2 = CONJG( ALPHA*X( J ) )\n K = KK\n DO 10, I = 1, J - 1\n AP( K ) = AP( K ) + X( I )*TEMP1 + Y( I )*TEMP2\n K = K + 1\n 10 CONTINUE\n AP( KK + J - 1 ) = REAL( AP( KK + J - 1 ) ) +\n $ REAL( X( J )*TEMP1 + Y( J )*TEMP2 )\n ELSE\n AP( KK + J - 1 ) = REAL( AP( KK + J - 1 ) )\n END IF\n KK = KK + J\n 20 CONTINUE\n ELSE\n DO 40, J = 1, N\n IF( ( X( JX ).NE.ZERO ).OR.( Y( JY ).NE.ZERO ) )THEN\n TEMP1 = ALPHA*CONJG( Y( JY ) )\n TEMP2 = CONJG( ALPHA*X( JX ) )\n IX = KX\n IY = KY\n DO 30, K = KK, KK + J - 2\n AP( K ) = AP( K ) + X( IX )*TEMP1 + Y( IY )*TEMP2\n IX = IX + INCX\n IY = IY + INCY\n 30 CONTINUE\n AP( KK + J - 1 ) = REAL( AP( KK + J - 1 ) ) +\n $ REAL( X( JX )*TEMP1 +\n $ Y( JY )*TEMP2 )\n ELSE\n AP( KK + J - 1 ) = REAL( AP( KK + J - 1 ) )\n END IF\n JX = JX + INCX\n JY = JY + INCY\n KK = KK + J\n 40 CONTINUE\n END IF\n ELSE\nc\nc Form A when lower triangle is stored in AP.\nc\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 60, J = 1, N\n IF( ( X( J ).NE.ZERO ).OR.( Y( J ).NE.ZERO ) )THEN\n TEMP1 = ALPHA*CONJG( Y( J ) )\n TEMP2 = CONJG( ALPHA*X( J ) )\n AP( KK ) = REAL( AP( KK ) ) +\n $ REAL( X( J )*TEMP1 + Y( J )*TEMP2 )\n K = KK + 1\n DO 50, I = J + 1, N\n AP( K ) = AP( K ) + X( I )*TEMP1 + Y( I )*TEMP2\n K = K + 1\n 50 CONTINUE\n ELSE\n AP( KK ) = REAL( AP( KK ) )\n END IF\n KK = KK + N - J + 1\n 60 CONTINUE\n ELSE\n DO 80, J = 1, N\n IF( ( X( JX ).NE.ZERO ).OR.( Y( JY ).NE.ZERO ) )THEN\n TEMP1 = ALPHA*CONJG( Y( JY ) )\n TEMP2 = CONJG( ALPHA*X( JX ) )\n AP( KK ) = REAL( AP( KK ) ) +\n $ REAL( X( JX )*TEMP1 + Y( JY )*TEMP2 )\n IX = JX\n IY = JY\n DO 70, K = KK + 1, KK + N - J\n IX = IX + INCX\n IY = IY + INCY\n AP( K ) = AP( K ) + X( IX )*TEMP1 + Y( IY )*TEMP2\n 70 CONTINUE\n ELSE\n AP( KK ) = REAL( AP( KK ) )\n END IF\n JX = JX + INCX\n JY = JY + INCY\n KK = KK + N - J + 1\n 80 CONTINUE\n END IF\n END IF\nc\n RETURN\nc\nc End of CHPR2 .\nc\n END\n SUBROUTINE CHPR ( UPLO, N, ALPHA, X, INCX, AP )\nc .. Scalar Arguments ..\n REAL ALPHA\n INTEGER INCX, N\n CHARACTER*1 UPLO\nc .. Array Arguments ..\n COMPLEX AP( * ), X( * )\nc ..\nc\nc Purpose\nc =======\nc\nc CHPR performs the hermitian rank 1 operation\nc\nc A := alpha*x*conjg( x' ) + A,\nc\nc where alpha is a real scalar, x is an n element vector and A is an\nc n by n hermitian matrix, supplied in packed form.\nc\nc Parameters\nc ==========\nc\nc UPLO - CHARACTER*1.\nc On entry, UPLO specifies whether the upper or lower\nc triangular part of the matrix A is supplied in the packed\nc array AP as follows:\nc\nc UPLO = 'U' or 'u' The upper triangular part of A is\nc supplied in AP.\nc\nc UPLO = 'L' or 'l' The lower triangular part of A is\nc supplied in AP.\nc\nc Unchanged on exit.\nc\nc N - INTEGER.\nc On entry, N specifies the order of the matrix A.\nc N must be at least zero.\nc Unchanged on exit.\nc\nc ALPHA - REAL .\nc On entry, ALPHA specifies the scalar alpha.\nc Unchanged on exit.\nc\nc X - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCX ) ).\nc Before entry, the incremented array X must contain the n\nc element vector x.\nc Unchanged on exit.\nc\nc INCX - INTEGER.\nc On entry, INCX specifies the increment for the elements of\nc X. INCX must not be zero.\nc Unchanged on exit.\nc\nc AP - COMPLEX array of DIMENSION at least\nc ( ( n*( n + 1 ) )/2 ).\nc Before entry with UPLO = 'U' or 'u', the array AP must\nc contain the upper triangular part of the hermitian matrix\nc packed sequentially, column by column, so that AP( 1 )\nc contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 1, 2 )\nc and a( 2, 2 ) respectively, and so on. On exit, the array\nc AP is overwritten by the upper triangular part of the\nc updated matrix.\nc Before entry with UPLO = 'L' or 'l', the array AP must\nc contain the lower triangular part of the hermitian matrix\nc packed sequentially, column by column, so that AP( 1 )\nc contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 2, 1 )\nc and a( 3, 1 ) respectively, and so on. On exit, the array\nc AP is overwritten by the lower triangular part of the\nc updated matrix.\nc Note that the imaginary parts of the diagonal elements need\nc not be set, they are assumed to be zero, and on exit they\nc are set to zero.\nc\nc\nc Level 2 Blas routine.\nc\nc -- Written by Sourangshu Ghosh\nc\nc\nc .. Parameters ..\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\nc .. Local Scalars ..\n COMPLEX TEMP\n INTEGER I, INFO, IX, J, JX, K, KK, KX\nc .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nc .. External Subroutines ..\n EXTERNAL XERBLA\nc .. Intrinsic Functions ..\n INTRINSIC CONJG, REAL\nc ..\nc .. Executable Statements ..\nc\nc Test the input parameters.\nc\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) )THEN\n INFO = 1\n ELSE IF( N.LT.0 )THEN\n INFO = 2\n ELSE IF( INCX.EQ.0 )THEN\n INFO = 5\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'CHPR ', INFO )\n RETURN\n END IF\nc\nc Quick return if possible.\nc\n IF( ( N.EQ.0 ).OR.( ALPHA.EQ.REAL( ZERO ) ) )\n $ RETURN\nc\nc Set the start point in X if the increment is not unity.\nc\n IF( INCX.LE.0 )THEN\n KX = 1 - ( N - 1 )*INCX\n ELSE IF( INCX.NE.1 )THEN\n KX = 1\n END IF\nc\nc Start the operations. In this version the elements of the array AP\nc are accessed sequentially with one pass through AP.\nc\n KK = 1\n IF( LSAME( UPLO, 'U' ) )THEN\nc\nc Form A when upper triangle is stored in AP.\nc\n IF( INCX.EQ.1 )THEN\n DO 20, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n TEMP = ALPHA*CONJG( X( J ) )\n K = KK\n DO 10, I = 1, J - 1\n AP( K ) = AP( K ) + X( I )*TEMP\n K = K + 1\n 10 CONTINUE\n AP( KK + J - 1 ) = REAL( AP( KK + J - 1 ) )\n $ + REAL( X( J )*TEMP )\n ELSE\n AP( KK + J - 1 ) = REAL( AP( KK + J - 1 ) )\n END IF\n KK = KK + J\n 20 CONTINUE\n ELSE\n JX = KX\n DO 40, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n TEMP = ALPHA*CONJG( X( JX ) )\n IX = KX\n DO 30, K = KK, KK + J - 2\n AP( K ) = AP( K ) + X( IX )*TEMP\n IX = IX + INCX\n 30 CONTINUE\n AP( KK + J - 1 ) = REAL( AP( KK + J - 1 ) )\n $ + REAL( X( JX )*TEMP )\n ELSE\n AP( KK + J - 1 ) = REAL( AP( KK + J - 1 ) )\n END IF\n JX = JX + INCX\n KK = KK + J\n 40 CONTINUE\n END IF\n ELSE\nc\nc Form A when lower triangle is stored in AP.\nc\n IF( INCX.EQ.1 )THEN\n DO 60, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n TEMP = ALPHA*CONJG( X( J ) )\n AP( KK ) = REAL( AP( KK ) ) + REAL( TEMP*X( J ) )\n K = KK + 1\n DO 50, I = J + 1, N\n AP( K ) = AP( K ) + X( I )*TEMP\n K = K + 1\n 50 CONTINUE\n ELSE\n AP( KK ) = REAL( AP( KK ) )\n END IF\n KK = KK + N - J + 1\n 60 CONTINUE\n ELSE\n JX = KX\n DO 80, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n TEMP = ALPHA*CONJG( X( JX ) )\n AP( KK ) = REAL( AP( KK ) ) + REAL( TEMP*X( JX ) )\n IX = JX\n DO 70, K = KK + 1, KK + N - J\n IX = IX + INCX\n AP( K ) = AP( K ) + X( IX )*TEMP\n 70 CONTINUE\n ELSE\n AP( KK ) = REAL( AP( KK ) )\n END IF\n JX = JX + INCX\n KK = KK + N - J + 1\n 80 CONTINUE\n END IF\n END IF\nc\n RETURN\nc\nc End of CHPR .\nc\n END\n SUBROUTINE CTBMV ( UPLO, TRANS, DIAG, N, K, A, LDA, X, INCX )\nc .. Scalar Arguments ..\n INTEGER INCX, K, LDA, N\n CHARACTER*1 DIAG, TRANS, UPLO\nc .. Array Arguments ..\n COMPLEX A( LDA, * ), X( * )\nc ..\nc\nc Purpose\nc =======\nc\nc CTBMV performs one of the matrix-vector operations\nc\nc x := A*x, or x := A'*x, or x := conjg( A' )*x,\nc\nc where x is an n element vector and A is an n by n unit, or non-unit,\nc upper or lower triangular band matrix, with ( k + 1 ) diagonals.\nc\nc Parameters\nc ==========\nc\nc UPLO - CHARACTER*1.\nc On entry, UPLO specifies whether the matrix is an upper or\nc lower triangular matrix as follows:\nc\nc UPLO = 'U' or 'u' A is an upper triangular matrix.\nc\nc UPLO = 'L' or 'l' A is a lower triangular matrix.\nc\nc Unchanged on exit.\nc\nc TRANS - CHARACTER*1.\nc On entry, TRANS specifies the operation to be performed as\nc follows:\nc\nc TRANS = 'N' or 'n' x := A*x.\nc\nc TRANS = 'T' or 't' x := A'*x.\nc\nc TRANS = 'C' or 'c' x := conjg( A' )*x.\nc\nc Unchanged on exit.\nc\nc DIAG - CHARACTER*1.\nc On entry, DIAG specifies whether or not A is unit\nc triangular as follows:\nc\nc DIAG = 'U' or 'u' A is assumed to be unit triangular.\nc\nc DIAG = 'N' or 'n' A is not assumed to be unit\nc triangular.\nc\nc Unchanged on exit.\nc\nc N - INTEGER.\nc On entry, N specifies the order of the matrix A.\nc N must be at least zero.\nc Unchanged on exit.\nc\nc K - INTEGER.\nc On entry with UPLO = 'U' or 'u', K specifies the number of\nc super-diagonals of the matrix A.\nc On entry with UPLO = 'L' or 'l', K specifies the number of\nc sub-diagonals of the matrix A.\nc K must satisfy 0 .le. K.\nc Unchanged on exit.\nc\nc A - COMPLEX array of DIMENSION ( LDA, n ).\nc Before entry with UPLO = 'U' or 'u', the leading ( k + 1 )\nc by n part of the array A must contain the upper triangular\nc band part of the matrix of coefficients, supplied column by\nc column, with the leading diagonal of the matrix in row\nc ( k + 1 ) of the array, the first super-diagonal starting at\nc position 2 in row k, and so on. The top left k by k triangle\nc of the array A is not referenced.\nc The following program segment will transfer an upper\nc triangular band matrix from conventional full matrix storage\nc to band storage:\nc\nc DO 20, J = 1, N\nc M = K + 1 - J\nc DO 10, I = MAX( 1, J - K ), J\nc A( M + I, J ) = matrix( I, J )\nc 10 CONTINUE\nc 20 CONTINUE\nc\nc Before entry with UPLO = 'L' or 'l', the leading ( k + 1 )\nc by n part of the array A must contain the lower triangular\nc band part of the matrix of coefficients, supplied column by\nc column, with the leading diagonal of the matrix in row 1 of\nc the array, the first sub-diagonal starting at position 1 in\nc row 2, and so on. The bottom right k by k triangle of the\nc array A is not referenced.\nc The following program segment will transfer a lower\nc triangular band matrix from conventional full matrix storage\nc to band storage:\nc\nc DO 20, J = 1, N\nc M = 1 - J\nc DO 10, I = J, MIN( N, J + K )\nc A( M + I, J ) = matrix( I, J )\nc 10 CONTINUE\nc 20 CONTINUE\nc\nc Note that when DIAG = 'U' or 'u' the elements of the array A\nc corresponding to the diagonal elements of the matrix are not\nc referenced, but are assumed to be unity.\nc Unchanged on exit.\nc\nc LDA - INTEGER.\nc On entry, LDA specifies the first dimension of A as declared\nc in the calling (sub) program. LDA must be at least\nc ( k + 1 ).\nc Unchanged on exit.\nc\nc X - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCX ) ).\nc Before entry, the incremented array X must contain the n\nc element vector x. On exit, X is overwritten with the\nc tranformed vector x.\nc\nc INCX - INTEGER.\nc On entry, INCX specifies the increment for the elements of\nc X. INCX must not be zero.\nc Unchanged on exit.\nc\nc\nc Level 2 Blas routine.\nc\nc -- Written by Sourangshu Ghosh\nc\nc\nc .. Parameters ..\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\nc .. Local Scalars ..\n COMPLEX TEMP\n INTEGER I, INFO, IX, J, JX, KPLUS1, KX, L\n LOGICAL NOCONJ, NOUNIT\nc .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nc .. External Subroutines ..\n EXTERNAL XERBLA\nc .. Intrinsic Functions ..\n INTRINSIC CONJG, MAX, MIN\nc ..\nc .. Executable Statements ..\nc\nc Test the input parameters.\nc\n INFO = 0\n IF ( .NOT.LSAME( UPLO , 'U' ).AND.\n $ .NOT.LSAME( UPLO , 'L' ) )THEN\n INFO = 1\n ELSE IF( .NOT.LSAME( TRANS, 'N' ).AND.\n $ .NOT.LSAME( TRANS, 'T' ).AND.\n $ .NOT.LSAME( TRANS, 'C' ) )THEN\n INFO = 2\n ELSE IF( .NOT.LSAME( DIAG , 'U' ).AND.\n $ .NOT.LSAME( DIAG , 'N' ) )THEN\n INFO = 3\n ELSE IF( N.LT.0 )THEN\n INFO = 4\n ELSE IF( K.LT.0 )THEN\n INFO = 5\n ELSE IF( LDA.LT.( K + 1 ) )THEN\n INFO = 7\n ELSE IF( INCX.EQ.0 )THEN\n INFO = 9\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'CTBMV ', INFO )\n RETURN\n END IF\nc\nc Quick return if possible.\nc\n IF( N.EQ.0 )\n $ RETURN\nc\n NOCONJ = LSAME( TRANS, 'T' )\n NOUNIT = LSAME( DIAG , 'N' )\nc\nc Set up the start point in X if the increment is not unity. This\nc will be ( N - 1 )*INCX too small for descending loops.\nc\n IF( INCX.LE.0 )THEN\n KX = 1 - ( N - 1 )*INCX\n ELSE IF( INCX.NE.1 )THEN\n KX = 1\n END IF\nc\nc Start the operations. In this version the elements of A are\nc accessed sequentially with one pass through A.\nc\n IF( LSAME( TRANS, 'N' ) )THEN\nc\nc Form x := A*x.\nc\n IF( LSAME( UPLO, 'U' ) )THEN\n KPLUS1 = K + 1\n IF( INCX.EQ.1 )THEN\n DO 20, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n TEMP = X( J )\n L = KPLUS1 - J\n DO 10, I = MAX( 1, J - K ), J - 1\n X( I ) = X( I ) + TEMP*A( L + I, J )\n 10 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )*A( KPLUS1, J )\n END IF\n 20 CONTINUE\n ELSE\n JX = KX\n DO 40, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n TEMP = X( JX )\n IX = KX\n L = KPLUS1 - J\n DO 30, I = MAX( 1, J - K ), J - 1\n X( IX ) = X( IX ) + TEMP*A( L + I, J )\n IX = IX + INCX\n 30 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*A( KPLUS1, J )\n END IF\n JX = JX + INCX\n IF( J.GT.K )\n $ KX = KX + INCX\n 40 CONTINUE\n END IF\n ELSE\n IF( INCX.EQ.1 )THEN\n DO 60, J = N, 1, -1\n IF( X( J ).NE.ZERO )THEN\n TEMP = X( J )\n L = 1 - J\n DO 50, I = MIN( N, J + K ), J + 1, -1\n X( I ) = X( I ) + TEMP*A( L + I, J )\n 50 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )*A( 1, J )\n END IF\n 60 CONTINUE\n ELSE\n KX = KX + ( N - 1 )*INCX\n JX = KX\n DO 80, J = N, 1, -1\n IF( X( JX ).NE.ZERO )THEN\n TEMP = X( JX )\n IX = KX\n L = 1 - J\n DO 70, I = MIN( N, J + K ), J + 1, -1\n X( IX ) = X( IX ) + TEMP*A( L + I, J )\n IX = IX - INCX\n 70 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*A( 1, J )\n END IF\n JX = JX - INCX\n IF( ( N - J ).GE.K )\n $ KX = KX - INCX\n 80 CONTINUE\n END IF\n END IF\n ELSE\nc\nc Form x := A'*x or x := conjg( A' )*x.\nc\n IF( LSAME( UPLO, 'U' ) )THEN\n KPLUS1 = K + 1\n IF( INCX.EQ.1 )THEN\n DO 110, J = N, 1, -1\n TEMP = X( J )\n L = KPLUS1 - J\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ TEMP = TEMP*A( KPLUS1, J )\n DO 90, I = J - 1, MAX( 1, J - K ), -1\n TEMP = TEMP + A( L + I, J )*X( I )\n 90 CONTINUE\n ELSE\n IF( NOUNIT )\n $ TEMP = TEMP*CONJG( A( KPLUS1, J ) )\n DO 100, I = J - 1, MAX( 1, J - K ), -1\n TEMP = TEMP + CONJG( A( L + I, J ) )*X( I )\n 100 CONTINUE\n END IF\n X( J ) = TEMP\n 110 CONTINUE\n ELSE\n KX = KX + ( N - 1 )*INCX\n JX = KX\n DO 140, J = N, 1, -1\n TEMP = X( JX )\n KX = KX - INCX\n IX = KX\n L = KPLUS1 - J\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ TEMP = TEMP*A( KPLUS1, J )\n DO 120, I = J - 1, MAX( 1, J - K ), -1\n TEMP = TEMP + A( L + I, J )*X( IX )\n IX = IX - INCX\n 120 CONTINUE\n ELSE\n IF( NOUNIT )\n $ TEMP = TEMP*CONJG( A( KPLUS1, J ) )\n DO 130, I = J - 1, MAX( 1, J - K ), -1\n TEMP = TEMP + CONJG( A( L + I, J ) )*X( IX )\n IX = IX - INCX\n 130 CONTINUE\n END IF\n X( JX ) = TEMP\n JX = JX - INCX\n 140 CONTINUE\n END IF\n ELSE\n IF( INCX.EQ.1 )THEN\n DO 170, J = 1, N\n TEMP = X( J )\n L = 1 - J\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ TEMP = TEMP*A( 1, J )\n DO 150, I = J + 1, MIN( N, J + K )\n TEMP = TEMP + A( L + I, J )*X( I )\n 150 CONTINUE\n ELSE\n IF( NOUNIT )\n $ TEMP = TEMP*CONJG( A( 1, J ) )\n DO 160, I = J + 1, MIN( N, J + K )\n TEMP = TEMP + CONJG( A( L + I, J ) )*X( I )\n 160 CONTINUE\n END IF\n X( J ) = TEMP\n 170 CONTINUE\n ELSE\n JX = KX\n DO 200, J = 1, N\n TEMP = X( JX )\n KX = KX + INCX\n IX = KX\n L = 1 - J\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ TEMP = TEMP*A( 1, J )\n DO 180, I = J + 1, MIN( N, J + K )\n TEMP = TEMP + A( L + I, J )*X( IX )\n IX = IX + INCX\n 180 CONTINUE\n ELSE\n IF( NOUNIT )\n $ TEMP = TEMP*CONJG( A( 1, J ) )\n DO 190, I = J + 1, MIN( N, J + K )\n TEMP = TEMP + CONJG( A( L + I, J ) )*X( IX )\n IX = IX + INCX\n 190 CONTINUE\n END IF\n X( JX ) = TEMP\n JX = JX + INCX\n 200 CONTINUE\n END IF\n END IF\n END IF\nc\n RETURN\nc\nc End of CTBMV .\nc\n END\n SUBROUTINE CTBSV ( UPLO, TRANS, DIAG, N, K, A, LDA, X, INCX )\nc .. Scalar Arguments ..\n INTEGER INCX, K, LDA, N\n CHARACTER*1 DIAG, TRANS, UPLO\nc .. Array Arguments ..\n COMPLEX A( LDA, * ), X( * )\nc ..\nc\nc Purpose\nc =======\nc\nc CTBSV solves one of the systems of equations\nc\nc A*x = b, or A'*x = b, or conjg( A' )*x = b,\nc\nc where b and x are n element vectors and A is an n by n unit, or\nc non-unit, upper or lower triangular band matrix, with ( k + 1 )\nc diagonals.\nc\nc No test for singularity or near-singularity is included in this\nc routine. Such tests must be performed before calling this routine.\nc\nc Parameters\nc ==========\nc\nc UPLO - CHARACTER*1.\nc On entry, UPLO specifies whether the matrix is an upper or\nc lower triangular matrix as follows:\nc\nc UPLO = 'U' or 'u' A is an upper triangular matrix.\nc\nc UPLO = 'L' or 'l' A is a lower triangular matrix.\nc\nc Unchanged on exit.\nc\nc TRANS - CHARACTER*1.\nc On entry, TRANS specifies the equations to be solved as\nc follows:\nc\nc TRANS = 'N' or 'n' A*x = b.\nc\nc TRANS = 'T' or 't' A'*x = b.\nc\nc TRANS = 'C' or 'c' conjg( A' )*x = b.\nc\nc Unchanged on exit.\nc\nc DIAG - CHARACTER*1.\nc On entry, DIAG specifies whether or not A is unit\nc triangular as follows:\nc\nc DIAG = 'U' or 'u' A is assumed to be unit triangular.\nc\nc DIAG = 'N' or 'n' A is not assumed to be unit\nc triangular.\nc\nc Unchanged on exit.\nc\nc N - INTEGER.\nc On entry, N specifies the order of the matrix A.\nc N must be at least zero.\nc Unchanged on exit.\nc\nc K - INTEGER.\nc On entry with UPLO = 'U' or 'u', K specifies the number of\nc super-diagonals of the matrix A.\nc On entry with UPLO = 'L' or 'l', K specifies the number of\nc sub-diagonals of the matrix A.\nc K must satisfy 0 .le. K.\nc Unchanged on exit.\nc\nc A - COMPLEX array of DIMENSION ( LDA, n ).\nc Before entry with UPLO = 'U' or 'u', the leading ( k + 1 )\nc by n part of the array A must contain the upper triangular\nc band part of the matrix of coefficients, supplied column by\nc column, with the leading diagonal of the matrix in row\nc ( k + 1 ) of the array, the first super-diagonal starting at\nc position 2 in row k, and so on. The top left k by k triangle\nc of the array A is not referenced.\nc The following program segment will transfer an upper\nc triangular band matrix from conventional full matrix storage\nc to band storage:\nc\nc DO 20, J = 1, N\nc M = K + 1 - J\nc DO 10, I = MAX( 1, J - K ), J\nc A( M + I, J ) = matrix( I, J )\nc 10 CONTINUE\nc 20 CONTINUE\nc\nc Before entry with UPLO = 'L' or 'l', the leading ( k + 1 )\nc by n part of the array A must contain the lower triangular\nc band part of the matrix of coefficients, supplied column by\nc column, with the leading diagonal of the matrix in row 1 of\nc the array, the first sub-diagonal starting at position 1 in\nc row 2, and so on. The bottom right k by k triangle of the\nc array A is not referenced.\nc The following program segment will transfer a lower\nc triangular band matrix from conventional full matrix storage\nc to band storage:\nc\nc DO 20, J = 1, N\nc M = 1 - J\nc DO 10, I = J, MIN( N, J + K )\nc A( M + I, J ) = matrix( I, J )\nc 10 CONTINUE\nc 20 CONTINUE\nc\nc Note that when DIAG = 'U' or 'u' the elements of the array A\nc corresponding to the diagonal elements of the matrix are not\nc referenced, but are assumed to be unity.\nc Unchanged on exit.\nc\nc LDA - INTEGER.\nc On entry, LDA specifies the first dimension of A as declared\nc in the calling (sub) program. LDA must be at least\nc ( k + 1 ).\nc Unchanged on exit.\nc\nc X - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCX ) ).\nc Before entry, the incremented array X must contain the n\nc element right-hand side vector b. On exit, X is overwritten\nc with the solution vector x.\nc\nc INCX - INTEGER.\nc On entry, INCX specifies the increment for the elements of\nc X. INCX must not be zero.\nc Unchanged on exit.\nc\nc\nc Level 2 Blas routine.\nc\nc -- Written by Sourangshu Ghosh\nc\nc\nc .. Parameters ..\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\nc .. Local Scalars ..\n COMPLEX TEMP\n INTEGER I, INFO, IX, J, JX, KPLUS1, KX, L\n LOGICAL NOCONJ, NOUNIT\nc .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nc .. External Subroutines ..\n EXTERNAL XERBLA\nc .. Intrinsic Functions ..\n INTRINSIC CONJG, MAX, MIN\nc ..\nc .. Executable Statements ..\nc\nc Test the input parameters.\nc\n INFO = 0\n IF ( .NOT.LSAME( UPLO , 'U' ).AND.\n $ .NOT.LSAME( UPLO , 'L' ) )THEN\n INFO = 1\n ELSE IF( .NOT.LSAME( TRANS, 'N' ).AND.\n $ .NOT.LSAME( TRANS, 'T' ).AND.\n $ .NOT.LSAME( TRANS, 'C' ) )THEN\n INFO = 2\n ELSE IF( .NOT.LSAME( DIAG , 'U' ).AND.\n $ .NOT.LSAME( DIAG , 'N' ) )THEN\n INFO = 3\n ELSE IF( N.LT.0 )THEN\n INFO = 4\n ELSE IF( K.LT.0 )THEN\n INFO = 5\n ELSE IF( LDA.LT.( K + 1 ) )THEN\n INFO = 7\n ELSE IF( INCX.EQ.0 )THEN\n INFO = 9\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'CTBSV ', INFO )\n RETURN\n END IF\nc\nc Quick return if possible.\nc\n IF( N.EQ.0 )\n $ RETURN\nc\n NOCONJ = LSAME( TRANS, 'T' )\n NOUNIT = LSAME( DIAG , 'N' )\nc\nc Set up the start point in X if the increment is not unity. This\nc will be ( N - 1 )*INCX too small for descending loops.\nc\n IF( INCX.LE.0 )THEN\n KX = 1 - ( N - 1 )*INCX\n ELSE IF( INCX.NE.1 )THEN\n KX = 1\n END IF\nc\nc Start the operations. In this version the elements of A are\nc accessed by sequentially with one pass through A.\nc\n IF( LSAME( TRANS, 'N' ) )THEN\nc\nc Form x := inv( A )*x.\nc\n IF( LSAME( UPLO, 'U' ) )THEN\n KPLUS1 = K + 1\n IF( INCX.EQ.1 )THEN\n DO 20, J = N, 1, -1\n IF( X( J ).NE.ZERO )THEN\n L = KPLUS1 - J\n IF( NOUNIT )\n $ X( J ) = X( J )/A( KPLUS1, J )\n TEMP = X( J )\n DO 10, I = J - 1, MAX( 1, J - K ), -1\n X( I ) = X( I ) - TEMP*A( L + I, J )\n 10 CONTINUE\n END IF\n 20 CONTINUE\n ELSE\n KX = KX + ( N - 1 )*INCX\n JX = KX\n DO 40, J = N, 1, -1\n KX = KX - INCX\n IF( X( JX ).NE.ZERO )THEN\n IX = KX\n L = KPLUS1 - J\n IF( NOUNIT )\n $ X( JX ) = X( JX )/A( KPLUS1, J )\n TEMP = X( JX )\n DO 30, I = J - 1, MAX( 1, J - K ), -1\n X( IX ) = X( IX ) - TEMP*A( L + I, J )\n IX = IX - INCX\n 30 CONTINUE\n END IF\n JX = JX - INCX\n 40 CONTINUE\n END IF\n ELSE\n IF( INCX.EQ.1 )THEN\n DO 60, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n L = 1 - J\n IF( NOUNIT )\n $ X( J ) = X( J )/A( 1, J )\n TEMP = X( J )\n DO 50, I = J + 1, MIN( N, J + K )\n X( I ) = X( I ) - TEMP*A( L + I, J )\n 50 CONTINUE\n END IF\n 60 CONTINUE\n ELSE\n JX = KX\n DO 80, J = 1, N\n KX = KX + INCX\n IF( X( JX ).NE.ZERO )THEN\n IX = KX\n L = 1 - J\n IF( NOUNIT )\n $ X( JX ) = X( JX )/A( 1, J )\n TEMP = X( JX )\n DO 70, I = J + 1, MIN( N, J + K )\n X( IX ) = X( IX ) - TEMP*A( L + I, J )\n IX = IX + INCX\n 70 CONTINUE\n END IF\n JX = JX + INCX\n 80 CONTINUE\n END IF\n END IF\n ELSE\nc\nc Form x := inv( A' )*x or x := inv( conjg( A') )*x.\nc\n IF( LSAME( UPLO, 'U' ) )THEN\n KPLUS1 = K + 1\n IF( INCX.EQ.1 )THEN\n DO 110, J = 1, N\n TEMP = X( J )\n L = KPLUS1 - J\n IF( NOCONJ )THEN\n DO 90, I = MAX( 1, J - K ), J - 1\n TEMP = TEMP - A( L + I, J )*X( I )\n 90 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/A( KPLUS1, J )\n ELSE\n DO 100, I = MAX( 1, J - K ), J - 1\n TEMP = TEMP - CONJG( A( L + I, J ) )*X( I )\n 100 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/CONJG( A( KPLUS1, J ) )\n END IF\n X( J ) = TEMP\n 110 CONTINUE\n ELSE\n JX = KX\n DO 140, J = 1, N\n TEMP = X( JX )\n IX = KX\n L = KPLUS1 - J\n IF( NOCONJ )THEN\n DO 120, I = MAX( 1, J - K ), J - 1\n TEMP = TEMP - A( L + I, J )*X( IX )\n IX = IX + INCX\n 120 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/A( KPLUS1, J )\n ELSE\n DO 130, I = MAX( 1, J - K ), J - 1\n TEMP = TEMP - CONJG( A( L + I, J ) )*X( IX )\n IX = IX + INCX\n 130 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/CONJG( A( KPLUS1, J ) )\n END IF\n X( JX ) = TEMP\n JX = JX + INCX\n IF( J.GT.K )\n $ KX = KX + INCX\n 140 CONTINUE\n END IF\n ELSE\n IF( INCX.EQ.1 )THEN\n DO 170, J = N, 1, -1\n TEMP = X( J )\n L = 1 - J\n IF( NOCONJ )THEN\n DO 150, I = MIN( N, J + K ), J + 1, -1\n TEMP = TEMP - A( L + I, J )*X( I )\n 150 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/A( 1, J )\n ELSE\n DO 160, I = MIN( N, J + K ), J + 1, -1\n TEMP = TEMP - CONJG( A( L + I, J ) )*X( I )\n 160 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/CONJG( A( 1, J ) )\n END IF\n X( J ) = TEMP\n 170 CONTINUE\n ELSE\n KX = KX + ( N - 1 )*INCX\n JX = KX\n DO 200, J = N, 1, -1\n TEMP = X( JX )\n IX = KX\n L = 1 - J\n IF( NOCONJ )THEN\n DO 180, I = MIN( N, J + K ), J + 1, -1\n TEMP = TEMP - A( L + I, J )*X( IX )\n IX = IX - INCX\n 180 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/A( 1, J )\n ELSE\n DO 190, I = MIN( N, J + K ), J + 1, -1\n TEMP = TEMP - CONJG( A( L + I, J ) )*X( IX )\n IX = IX - INCX\n 190 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/CONJG( A( 1, J ) )\n END IF\n X( JX ) = TEMP\n JX = JX - INCX\n IF( ( N - J ).GE.K )\n $ KX = KX - INCX\n 200 CONTINUE\n END IF\n END IF\n END IF\nc\n RETURN\nc\nc End of CTBSV .\nc\n END\n SUBROUTINE CTPMV ( UPLO, TRANS, DIAG, N, AP, X, INCX )\nc .. Scalar Arguments ..\n INTEGER INCX, N\n CHARACTER*1 DIAG, TRANS, UPLO\nc .. Array Arguments ..\n COMPLEX AP( * ), X( * )\nc ..\nc\nc Purpose\nc =======\nc\nc CTPMV performs one of the matrix-vector operations\nc\nc x := A*x, or x := A'*x, or x := conjg( A' )*x,\nc\nc where x is an n element vector and A is an n by n unit, or non-unit,\nc upper or lower triangular matrix, supplied in packed form.\nc\nc Parameters\nc ==========\nc\nc UPLO - CHARACTER*1.\nc On entry, UPLO specifies whether the matrix is an upper or\nc lower triangular matrix as follows:\nc\nc UPLO = 'U' or 'u' A is an upper triangular matrix.\nc\nc UPLO = 'L' or 'l' A is a lower triangular matrix.\nc\nc Unchanged on exit.\nc\nc TRANS - CHARACTER*1.\nc On entry, TRANS specifies the operation to be performed as\nc follows:\nc\nc TRANS = 'N' or 'n' x := A*x.\nc\nc TRANS = 'T' or 't' x := A'*x.\nc\nc TRANS = 'C' or 'c' x := conjg( A' )*x.\nc\nc Unchanged on exit.\nc\nc DIAG - CHARACTER*1.\nc On entry, DIAG specifies whether or not A is unit\nc triangular as follows:\nc\nc DIAG = 'U' or 'u' A is assumed to be unit triangular.\nc\nc DIAG = 'N' or 'n' A is not assumed to be unit\nc triangular.\nc\nc Unchanged on exit.\nc\nc N - INTEGER.\nc On entry, N specifies the order of the matrix A.\nc N must be at least zero.\nc Unchanged on exit.\nc\nc AP - COMPLEX array of DIMENSION at least\nc ( ( n*( n + 1 ) )/2 ).\nc Before entry with UPLO = 'U' or 'u', the array AP must\nc contain the upper triangular matrix packed sequentially,\nc column by column, so that AP( 1 ) contains a( 1, 1 ),\nc AP( 2 ) and AP( 3 ) contain a( 1, 2 ) and a( 2, 2 )\nc respectively, and so on.\nc Before entry with UPLO = 'L' or 'l', the array AP must\nc contain the lower triangular matrix packed sequentially,\nc column by column, so that AP( 1 ) contains a( 1, 1 ),\nc AP( 2 ) and AP( 3 ) contain a( 2, 1 ) and a( 3, 1 )\nc respectively, and so on.\nc Note that when DIAG = 'U' or 'u', the diagonal elements of\nc A are not referenced, but are assumed to be unity.\nc Unchanged on exit.\nc\nc X - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCX ) ).\nc Before entry, the incremented array X must contain the n\nc element vector x. On exit, X is overwritten with the\nc tranformed vector x.\nc\nc INCX - INTEGER.\nc On entry, INCX specifies the increment for the elements of\nc X. INCX must not be zero.\nc Unchanged on exit.\nc\nc\nc Level 2 Blas routine.\nc\nc -- Written by Sourangshu Ghosh\nc\nc\nc .. Parameters ..\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\nc .. Local Scalars ..\n COMPLEX TEMP\n INTEGER I, INFO, IX, J, JX, K, KK, KX\n LOGICAL NOCONJ, NOUNIT\nc .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nc .. External Subroutines ..\n EXTERNAL XERBLA\nc .. Intrinsic Functions ..\n INTRINSIC CONJG\nc ..\nc .. Executable Statements ..\nc\nc Test the input parameters.\nc\n INFO = 0\n IF ( .NOT.LSAME( UPLO , 'U' ).AND.\n $ .NOT.LSAME( UPLO , 'L' ) )THEN\n INFO = 1\n ELSE IF( .NOT.LSAME( TRANS, 'N' ).AND.\n $ .NOT.LSAME( TRANS, 'T' ).AND.\n $ .NOT.LSAME( TRANS, 'C' ) )THEN\n INFO = 2\n ELSE IF( .NOT.LSAME( DIAG , 'U' ).AND.\n $ .NOT.LSAME( DIAG , 'N' ) )THEN\n INFO = 3\n ELSE IF( N.LT.0 )THEN\n INFO = 4\n ELSE IF( INCX.EQ.0 )THEN\n INFO = 7\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'CTPMV ', INFO )\n RETURN\n END IF\nc\nc Quick return if possible.\nc\n IF( N.EQ.0 )\n $ RETURN\nc\n NOCONJ = LSAME( TRANS, 'T' )\n NOUNIT = LSAME( DIAG , 'N' )\nc\nc Set up the start point in X if the increment is not unity. This\nc will be ( N - 1 )*INCX too small for descending loops.\nc\n IF( INCX.LE.0 )THEN\n KX = 1 - ( N - 1 )*INCX\n ELSE IF( INCX.NE.1 )THEN\n KX = 1\n END IF\nc\nc Start the operations. In this version the elements of AP are\nc accessed sequentially with one pass through AP.\nc\n IF( LSAME( TRANS, 'N' ) )THEN\nc\nc Form x:= A*x.\nc\n IF( LSAME( UPLO, 'U' ) )THEN\n KK = 1\n IF( INCX.EQ.1 )THEN\n DO 20, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n TEMP = X( J )\n K = KK\n DO 10, I = 1, J - 1\n X( I ) = X( I ) + TEMP*AP( K )\n K = K + 1\n 10 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )*AP( KK + J - 1 )\n END IF\n KK = KK + J\n 20 CONTINUE\n ELSE\n JX = KX\n DO 40, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n TEMP = X( JX )\n IX = KX\n DO 30, K = KK, KK + J - 2\n X( IX ) = X( IX ) + TEMP*AP( K )\n IX = IX + INCX\n 30 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*AP( KK + J - 1 )\n END IF\n JX = JX + INCX\n KK = KK + J\n 40 CONTINUE\n END IF\n ELSE\n KK = ( N*( N + 1 ) )/2\n IF( INCX.EQ.1 )THEN\n DO 60, J = N, 1, -1\n IF( X( J ).NE.ZERO )THEN\n TEMP = X( J )\n K = KK\n DO 50, I = N, J + 1, -1\n X( I ) = X( I ) + TEMP*AP( K )\n K = K - 1\n 50 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )*AP( KK - N + J )\n END IF\n KK = KK - ( N - J + 1 )\n 60 CONTINUE\n ELSE\n KX = KX + ( N - 1 )*INCX\n JX = KX\n DO 80, J = N, 1, -1\n IF( X( JX ).NE.ZERO )THEN\n TEMP = X( JX )\n IX = KX\n DO 70, K = KK, KK - ( N - ( J + 1 ) ), -1\n X( IX ) = X( IX ) + TEMP*AP( K )\n IX = IX - INCX\n 70 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*AP( KK - N + J )\n END IF\n JX = JX - INCX\n KK = KK - ( N - J + 1 )\n 80 CONTINUE\n END IF\n END IF\n ELSE\nc\nc Form x := A'*x or x := conjg( A' )*x.\nc\n IF( LSAME( UPLO, 'U' ) )THEN\n KK = ( N*( N + 1 ) )/2\n IF( INCX.EQ.1 )THEN\n DO 110, J = N, 1, -1\n TEMP = X( J )\n K = KK - 1\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ TEMP = TEMP*AP( KK )\n DO 90, I = J - 1, 1, -1\n TEMP = TEMP + AP( K )*X( I )\n K = K - 1\n 90 CONTINUE\n ELSE\n IF( NOUNIT )\n $ TEMP = TEMP*CONJG( AP( KK ) )\n DO 100, I = J - 1, 1, -1\n TEMP = TEMP + CONJG( AP( K ) )*X( I )\n K = K - 1\n 100 CONTINUE\n END IF\n X( J ) = TEMP\n KK = KK - J\n 110 CONTINUE\n ELSE\n JX = KX + ( N - 1 )*INCX\n DO 140, J = N, 1, -1\n TEMP = X( JX )\n IX = JX\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ TEMP = TEMP*AP( KK )\n DO 120, K = KK - 1, KK - J + 1, -1\n IX = IX - INCX\n TEMP = TEMP + AP( K )*X( IX )\n 120 CONTINUE\n ELSE\n IF( NOUNIT )\n $ TEMP = TEMP*CONJG( AP( KK ) )\n DO 130, K = KK - 1, KK - J + 1, -1\n IX = IX - INCX\n TEMP = TEMP + CONJG( AP( K ) )*X( IX )\n 130 CONTINUE\n END IF\n X( JX ) = TEMP\n JX = JX - INCX\n KK = KK - J\n 140 CONTINUE\n END IF\n ELSE\n KK = 1\n IF( INCX.EQ.1 )THEN\n DO 170, J = 1, N\n TEMP = X( J )\n K = KK + 1\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ TEMP = TEMP*AP( KK )\n DO 150, I = J + 1, N\n TEMP = TEMP + AP( K )*X( I )\n K = K + 1\n 150 CONTINUE\n ELSE\n IF( NOUNIT )\n $ TEMP = TEMP*CONJG( AP( KK ) )\n DO 160, I = J + 1, N\n TEMP = TEMP + CONJG( AP( K ) )*X( I )\n K = K + 1\n 160 CONTINUE\n END IF\n X( J ) = TEMP\n KK = KK + ( N - J + 1 )\n 170 CONTINUE\n ELSE\n JX = KX\n DO 200, J = 1, N\n TEMP = X( JX )\n IX = JX\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ TEMP = TEMP*AP( KK )\n DO 180, K = KK + 1, KK + N - J\n IX = IX + INCX\n TEMP = TEMP + AP( K )*X( IX )\n 180 CONTINUE\n ELSE\n IF( NOUNIT )\n $ TEMP = TEMP*CONJG( AP( KK ) )\n DO 190, K = KK + 1, KK + N - J\n IX = IX + INCX\n TEMP = TEMP + CONJG( AP( K ) )*X( IX )\n 190 CONTINUE\n END IF\n X( JX ) = TEMP\n JX = JX + INCX\n KK = KK + ( N - J + 1 )\n 200 CONTINUE\n END IF\n END IF\n END IF\nc\n RETURN\nc\nc End of CTPMV .\nc\n END\n SUBROUTINE CTPSV ( UPLO, TRANS, DIAG, N, AP, X, INCX )\nc .. Scalar Arguments ..\n INTEGER INCX, N\n CHARACTER*1 DIAG, TRANS, UPLO\nc .. Array Arguments ..\n COMPLEX AP( * ), X( * )\nc ..\nc\nc Purpose\nc =======\nc\nc CTPSV solves one of the systems of equations\nc\nc A*x = b, or A'*x = b, or conjg( A' )*x = b,\nc\nc where b and x are n element vectors and A is an n by n unit, or\nc non-unit, upper or lower triangular matrix, supplied in packed form.\nc\nc No test for singularity or near-singularity is included in this\nc routine. Such tests must be performed before calling this routine.\nc\nc Parameters\nc ==========\nc\nc UPLO - CHARACTER*1.\nc On entry, UPLO specifies whether the matrix is an upper or\nc lower triangular matrix as follows:\nc\nc UPLO = 'U' or 'u' A is an upper triangular matrix.\nc\nc UPLO = 'L' or 'l' A is a lower triangular matrix.\nc\nc Unchanged on exit.\nc\nc TRANS - CHARACTER*1.\nc On entry, TRANS specifies the equations to be solved as\nc follows:\nc\nc TRANS = 'N' or 'n' A*x = b.\nc\nc TRANS = 'T' or 't' A'*x = b.\nc\nc TRANS = 'C' or 'c' conjg( A' )*x = b.\nc\nc Unchanged on exit.\nc\nc DIAG - CHARACTER*1.\nc On entry, DIAG specifies whether or not A is unit\nc triangular as follows:\nc\nc DIAG = 'U' or 'u' A is assumed to be unit triangular.\nc\nc DIAG = 'N' or 'n' A is not assumed to be unit\nc triangular.\nc\nc Unchanged on exit.\nc\nc N - INTEGER.\nc On entry, N specifies the order of the matrix A.\nc N must be at least zero.\nc Unchanged on exit.\nc\nc AP - COMPLEX array of DIMENSION at least\nc ( ( n*( n + 1 ) )/2 ).\nc Before entry with UPLO = 'U' or 'u', the array AP must\nc contain the upper triangular matrix packed sequentially,\nc column by column, so that AP( 1 ) contains a( 1, 1 ),\nc AP( 2 ) and AP( 3 ) contain a( 1, 2 ) and a( 2, 2 )\nc respectively, and so on.\nc Before entry with UPLO = 'L' or 'l', the array AP must\nc contain the lower triangular matrix packed sequentially,\nc column by column, so that AP( 1 ) contains a( 1, 1 ),\nc AP( 2 ) and AP( 3 ) contain a( 2, 1 ) and a( 3, 1 )\nc respectively, and so on.\nc Note that when DIAG = 'U' or 'u', the diagonal elements of\nc A are not referenced, but are assumed to be unity.\nc Unchanged on exit.\nc\nc X - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCX ) ).\nc Before entry, the incremented array X must contain the n\nc element right-hand side vector b. On exit, X is overwritten\nc with the solution vector x.\nc\nc INCX - INTEGER.\nc On entry, INCX specifies the increment for the elements of\nc X. INCX must not be zero.\nc Unchanged on exit.\nc\nc\nc Level 2 Blas routine.\nc\nc -- Written by Sourangshu Ghosh\nc\nc\nc .. Parameters ..\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\nc .. Local Scalars ..\n COMPLEX TEMP\n INTEGER I, INFO, IX, J, JX, K, KK, KX\n LOGICAL NOCONJ, NOUNIT\nc .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nc .. External Subroutines ..\n EXTERNAL XERBLA\nc .. Intrinsic Functions ..\n INTRINSIC CONJG\nc ..\nc .. Executable Statements ..\nc\nc Test the input parameters.\nc\n INFO = 0\n IF ( .NOT.LSAME( UPLO , 'U' ).AND.\n $ .NOT.LSAME( UPLO , 'L' ) )THEN\n INFO = 1\n ELSE IF( .NOT.LSAME( TRANS, 'N' ).AND.\n $ .NOT.LSAME( TRANS, 'T' ).AND.\n $ .NOT.LSAME( TRANS, 'C' ) )THEN\n INFO = 2\n ELSE IF( .NOT.LSAME( DIAG , 'U' ).AND.\n $ .NOT.LSAME( DIAG , 'N' ) )THEN\n INFO = 3\n ELSE IF( N.LT.0 )THEN\n INFO = 4\n ELSE IF( INCX.EQ.0 )THEN\n INFO = 7\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'CTPSV ', INFO )\n RETURN\n END IF\nc\nc Quick return if possible.\nc\n IF( N.EQ.0 )\n $ RETURN\nc\n NOCONJ = LSAME( TRANS, 'T' )\n NOUNIT = LSAME( DIAG , 'N' )\nc\nc Set up the start point in X if the increment is not unity. This\nc will be ( N - 1 )*INCX too small for descending loops.\nc\n IF( INCX.LE.0 )THEN\n KX = 1 - ( N - 1 )*INCX\n ELSE IF( INCX.NE.1 )THEN\n KX = 1\n END IF\nc\nc Start the operations. In this version the elements of AP are\nc accessed sequentially with one pass through AP.\nc\n IF( LSAME( TRANS, 'N' ) )THEN\nc\nc Form x := inv( A )*x.\nc\n IF( LSAME( UPLO, 'U' ) )THEN\n KK = ( N*( N + 1 ) )/2\n IF( INCX.EQ.1 )THEN\n DO 20, J = N, 1, -1\n IF( X( J ).NE.ZERO )THEN\n IF( NOUNIT )\n $ X( J ) = X( J )/AP( KK )\n TEMP = X( J )\n K = KK - 1\n DO 10, I = J - 1, 1, -1\n X( I ) = X( I ) - TEMP*AP( K )\n K = K - 1\n 10 CONTINUE\n END IF\n KK = KK - J\n 20 CONTINUE\n ELSE\n JX = KX + ( N - 1 )*INCX\n DO 40, J = N, 1, -1\n IF( X( JX ).NE.ZERO )THEN\n IF( NOUNIT )\n $ X( JX ) = X( JX )/AP( KK )\n TEMP = X( JX )\n IX = JX\n DO 30, K = KK - 1, KK - J + 1, -1\n IX = IX - INCX\n X( IX ) = X( IX ) - TEMP*AP( K )\n 30 CONTINUE\n END IF\n JX = JX - INCX\n KK = KK - J\n 40 CONTINUE\n END IF\n ELSE\n KK = 1\n IF( INCX.EQ.1 )THEN\n DO 60, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n IF( NOUNIT )\n $ X( J ) = X( J )/AP( KK )\n TEMP = X( J )\n K = KK + 1\n DO 50, I = J + 1, N\n X( I ) = X( I ) - TEMP*AP( K )\n K = K + 1\n 50 CONTINUE\n END IF\n KK = KK + ( N - J + 1 )\n 60 CONTINUE\n ELSE\n JX = KX\n DO 80, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n IF( NOUNIT )\n $ X( JX ) = X( JX )/AP( KK )\n TEMP = X( JX )\n IX = JX\n DO 70, K = KK + 1, KK + N - J\n IX = IX + INCX\n X( IX ) = X( IX ) - TEMP*AP( K )\n 70 CONTINUE\n END IF\n JX = JX + INCX\n KK = KK + ( N - J + 1 )\n 80 CONTINUE\n END IF\n END IF\n ELSE\nc\nc Form x := inv( A' )*x or x := inv( conjg( A' ) )*x.\nc\n IF( LSAME( UPLO, 'U' ) )THEN\n KK = 1\n IF( INCX.EQ.1 )THEN\n DO 110, J = 1, N\n TEMP = X( J )\n K = KK\n IF( NOCONJ )THEN\n DO 90, I = 1, J - 1\n TEMP = TEMP - AP( K )*X( I )\n K = K + 1\n 90 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/AP( KK + J - 1 )\n ELSE\n DO 100, I = 1, J - 1\n TEMP = TEMP - CONJG( AP( K ) )*X( I )\n K = K + 1\n 100 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/CONJG( AP( KK + J - 1 ) )\n END IF\n X( J ) = TEMP\n KK = KK + J\n 110 CONTINUE\n ELSE\n JX = KX\n DO 140, J = 1, N\n TEMP = X( JX )\n IX = KX\n IF( NOCONJ )THEN\n DO 120, K = KK, KK + J - 2\n TEMP = TEMP - AP( K )*X( IX )\n IX = IX + INCX\n 120 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/AP( KK + J - 1 )\n ELSE\n DO 130, K = KK, KK + J - 2\n TEMP = TEMP - CONJG( AP( K ) )*X( IX )\n IX = IX + INCX\n 130 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/CONJG( AP( KK + J - 1 ) )\n END IF\n X( JX ) = TEMP\n JX = JX + INCX\n KK = KK + J\n 140 CONTINUE\n END IF\n ELSE\n KK = ( N*( N + 1 ) )/2\n IF( INCX.EQ.1 )THEN\n DO 170, J = N, 1, -1\n TEMP = X( J )\n K = KK\n IF( NOCONJ )THEN\n DO 150, I = N, J + 1, -1\n TEMP = TEMP - AP( K )*X( I )\n K = K - 1\n 150 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/AP( KK - N + J )\n ELSE\n DO 160, I = N, J + 1, -1\n TEMP = TEMP - CONJG( AP( K ) )*X( I )\n K = K - 1\n 160 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/CONJG( AP( KK - N + J ) )\n END IF\n X( J ) = TEMP\n KK = KK - ( N - J + 1 )\n 170 CONTINUE\n ELSE\n KX = KX + ( N - 1 )*INCX\n JX = KX\n DO 200, J = N, 1, -1\n TEMP = X( JX )\n IX = KX\n IF( NOCONJ )THEN\n DO 180, K = KK, KK - ( N - ( J + 1 ) ), -1\n TEMP = TEMP - AP( K )*X( IX )\n IX = IX - INCX\n 180 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/AP( KK - N + J )\n ELSE\n DO 190, K = KK, KK - ( N - ( J + 1 ) ), -1\n TEMP = TEMP - CONJG( AP( K ) )*X( IX )\n IX = IX - INCX\n 190 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/CONJG( AP( KK - N + J ) )\n END IF\n X( JX ) = TEMP\n JX = JX - INCX\n KK = KK - ( N - J + 1 )\n 200 CONTINUE\n END IF\n END IF\n END IF\nc\n RETURN\nc\nc End of CTPSV .\nc\n END\n SUBROUTINE CTRMV ( UPLO, TRANS, DIAG, N, A, LDA, X, INCX )\nc .. Scalar Arguments ..\n INTEGER INCX, LDA, N\n CHARACTER*1 DIAG, TRANS, UPLO\nc .. Array Arguments ..\n COMPLEX A( LDA, * ), X( * )\nc ..\nc\nc Purpose\nc =======\nc\nc CTRMV performs one of the matrix-vector operations\nc\nc x := A*x, or x := A'*x, or x := conjg( A' )*x,\nc\nc where x is an n element vector and A is an n by n unit, or non-unit,\nc upper or lower triangular matrix.\nc\nc Parameters\nc ==========\nc\nc UPLO - CHARACTER*1.\nc On entry, UPLO specifies whether the matrix is an upper or\nc lower triangular matrix as follows:\nc\nc UPLO = 'U' or 'u' A is an upper triangular matrix.\nc\nc UPLO = 'L' or 'l' A is a lower triangular matrix.\nc\nc Unchanged on exit.\nc\nc TRANS - CHARACTER*1.\nc On entry, TRANS specifies the operation to be performed as\nc follows:\nc\nc TRANS = 'N' or 'n' x := A*x.\nc\nc TRANS = 'T' or 't' x := A'*x.\nc\nc TRANS = 'C' or 'c' x := conjg( A' )*x.\nc\nc Unchanged on exit.\nc\nc DIAG - CHARACTER*1.\nc On entry, DIAG specifies whether or not A is unit\nc triangular as follows:\nc\nc DIAG = 'U' or 'u' A is assumed to be unit triangular.\nc\nc DIAG = 'N' or 'n' A is not assumed to be unit\nc triangular.\nc\nc Unchanged on exit.\nc\nc N - INTEGER.\nc On entry, N specifies the order of the matrix A.\nc N must be at least zero.\nc Unchanged on exit.\nc\nc A - COMPLEX array of DIMENSION ( LDA, n ).\nc Before entry with UPLO = 'U' or 'u', the leading n by n\nc upper triangular part of the array A must contain the upper\nc triangular matrix and the strictly lower triangular part of\nc A is not referenced.\nc Before entry with UPLO = 'L' or 'l', the leading n by n\nc lower triangular part of the array A must contain the lower\nc triangular matrix and the strictly upper triangular part of\nc A is not referenced.\nc Note that when DIAG = 'U' or 'u', the diagonal elements of\nc A are not referenced either, but are assumed to be unity.\nc Unchanged on exit.\nc\nc LDA - INTEGER.\nc On entry, LDA specifies the first dimension of A as declared\nc in the calling (sub) program. LDA must be at least\nc max( 1, n ).\nc Unchanged on exit.\nc\nc X - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCX ) ).\nc Before entry, the incremented array X must contain the n\nc element vector x. On exit, X is overwritten with the\nc tranformed vector x.\nc\nc INCX - INTEGER.\nc On entry, INCX specifies the increment for the elements of\nc X. INCX must not be zero.\nc Unchanged on exit.\nc\nc\nc Level 2 Blas routine.\nc\nc -- Written by Sourangshu Ghosh\nc\nc\nc .. Parameters ..\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\nc .. Local Scalars ..\n COMPLEX TEMP\n INTEGER I, INFO, IX, J, JX, KX\n LOGICAL NOCONJ, NOUNIT\nc .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nc .. External Subroutines ..\n EXTERNAL XERBLA\nc .. Intrinsic Functions ..\n INTRINSIC CONJG, MAX\nc ..\nc .. Executable Statements ..\nc\nc Test the input parameters.\nc\n INFO = 0\n IF ( .NOT.LSAME( UPLO , 'U' ).AND.\n $ .NOT.LSAME( UPLO , 'L' ) )THEN\n INFO = 1\n ELSE IF( .NOT.LSAME( TRANS, 'N' ).AND.\n $ .NOT.LSAME( TRANS, 'T' ).AND.\n $ .NOT.LSAME( TRANS, 'C' ) )THEN\n INFO = 2\n ELSE IF( .NOT.LSAME( DIAG , 'U' ).AND.\n $ .NOT.LSAME( DIAG , 'N' ) )THEN\n INFO = 3\n ELSE IF( N.LT.0 )THEN\n INFO = 4\n ELSE IF( LDA.LT.MAX( 1, N ) )THEN\n INFO = 6\n ELSE IF( INCX.EQ.0 )THEN\n INFO = 8\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'CTRMV ', INFO )\n RETURN\n END IF\nc\nc Quick return if possible.\nc\n IF( N.EQ.0 )\n $ RETURN\nc\n NOCONJ = LSAME( TRANS, 'T' )\n NOUNIT = LSAME( DIAG , 'N' )\nc\nc Set up the start point in X if the increment is not unity. This\nc will be ( N - 1 )*INCX too small for descending loops.\nc\n IF( INCX.LE.0 )THEN\n KX = 1 - ( N - 1 )*INCX\n ELSE IF( INCX.NE.1 )THEN\n KX = 1\n END IF\nc\nc Start the operations. In this version the elements of A are\nc accessed sequentially with one pass through A.\nc\n IF( LSAME( TRANS, 'N' ) )THEN\nc\nc Form x := A*x.\nc\n IF( LSAME( UPLO, 'U' ) )THEN\n IF( INCX.EQ.1 )THEN\n DO 20, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n TEMP = X( J )\n DO 10, I = 1, J - 1\n X( I ) = X( I ) + TEMP*A( I, J )\n 10 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )*A( J, J )\n END IF\n 20 CONTINUE\n ELSE\n JX = KX\n DO 40, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n TEMP = X( JX )\n IX = KX\n DO 30, I = 1, J - 1\n X( IX ) = X( IX ) + TEMP*A( I, J )\n IX = IX + INCX\n 30 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*A( J, J )\n END IF\n JX = JX + INCX\n 40 CONTINUE\n END IF\n ELSE\n IF( INCX.EQ.1 )THEN\n DO 60, J = N, 1, -1\n IF( X( J ).NE.ZERO )THEN\n TEMP = X( J )\n DO 50, I = N, J + 1, -1\n X( I ) = X( I ) + TEMP*A( I, J )\n 50 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )*A( J, J )\n END IF\n 60 CONTINUE\n ELSE\n KX = KX + ( N - 1 )*INCX\n JX = KX\n DO 80, J = N, 1, -1\n IF( X( JX ).NE.ZERO )THEN\n TEMP = X( JX )\n IX = KX\n DO 70, I = N, J + 1, -1\n X( IX ) = X( IX ) + TEMP*A( I, J )\n IX = IX - INCX\n 70 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*A( J, J )\n END IF\n JX = JX - INCX\n 80 CONTINUE\n END IF\n END IF\n ELSE\nc\nc Form x := A'*x or x := conjg( A' )*x.\nc\n IF( LSAME( UPLO, 'U' ) )THEN\n IF( INCX.EQ.1 )THEN\n DO 110, J = N, 1, -1\n TEMP = X( J )\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ TEMP = TEMP*A( J, J )\n DO 90, I = J - 1, 1, -1\n TEMP = TEMP + A( I, J )*X( I )\n 90 CONTINUE\n ELSE\n IF( NOUNIT )\n $ TEMP = TEMP*CONJG( A( J, J ) )\n DO 100, I = J - 1, 1, -1\n TEMP = TEMP + CONJG( A( I, J ) )*X( I )\n 100 CONTINUE\n END IF\n X( J ) = TEMP\n 110 CONTINUE\n ELSE\n JX = KX + ( N - 1 )*INCX\n DO 140, J = N, 1, -1\n TEMP = X( JX )\n IX = JX\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ TEMP = TEMP*A( J, J )\n DO 120, I = J - 1, 1, -1\n IX = IX - INCX\n TEMP = TEMP + A( I, J )*X( IX )\n 120 CONTINUE\n ELSE\n IF( NOUNIT )\n $ TEMP = TEMP*CONJG( A( J, J ) )\n DO 130, I = J - 1, 1, -1\n IX = IX - INCX\n TEMP = TEMP + CONJG( A( I, J ) )*X( IX )\n 130 CONTINUE\n END IF\n X( JX ) = TEMP\n JX = JX - INCX\n 140 CONTINUE\n END IF\n ELSE\n IF( INCX.EQ.1 )THEN\n DO 170, J = 1, N\n TEMP = X( J )\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ TEMP = TEMP*A( J, J )\n DO 150, I = J + 1, N\n TEMP = TEMP + A( I, J )*X( I )\n 150 CONTINUE\n ELSE\n IF( NOUNIT )\n $ TEMP = TEMP*CONJG( A( J, J ) )\n DO 160, I = J + 1, N\n TEMP = TEMP + CONJG( A( I, J ) )*X( I )\n 160 CONTINUE\n END IF\n X( J ) = TEMP\n 170 CONTINUE\n ELSE\n JX = KX\n DO 200, J = 1, N\n TEMP = X( JX )\n IX = JX\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ TEMP = TEMP*A( J, J )\n DO 180, I = J + 1, N\n IX = IX + INCX\n TEMP = TEMP + A( I, J )*X( IX )\n 180 CONTINUE\n ELSE\n IF( NOUNIT )\n $ TEMP = TEMP*CONJG( A( J, J ) )\n DO 190, I = J + 1, N\n IX = IX + INCX\n TEMP = TEMP + CONJG( A( I, J ) )*X( IX )\n 190 CONTINUE\n END IF\n X( JX ) = TEMP\n JX = JX + INCX\n 200 CONTINUE\n END IF\n END IF\n END IF\nc\n RETURN\nc\nc End of CTRMV .\nc\n END\n SUBROUTINE CTRSV ( UPLO, TRANS, DIAG, N, A, LDA, X, INCX )\nc .. Scalar Arguments ..\n INTEGER INCX, LDA, N\n CHARACTER*1 DIAG, TRANS, UPLO\nc .. Array Arguments ..\n COMPLEX A( LDA, * ), X( * )\nc ..\nc\nc Purpose\nc =======\nc\nc CTRSV solves one of the systems of equations\nc\nc A*x = b, or A'*x = b, or conjg( A' )*x = b,\nc\nc where b and x are n element vectors and A is an n by n unit, or\nc non-unit, upper or lower triangular matrix.\nc\nc No test for singularity or near-singularity is included in this\nc routine. Such tests must be performed before calling this routine.\nc\nc Parameters\nc ==========\nc\nc UPLO - CHARACTER*1.\nc On entry, UPLO specifies whether the matrix is an upper or\nc lower triangular matrix as follows:\nc\nc UPLO = 'U' or 'u' A is an upper triangular matrix.\nc\nc UPLO = 'L' or 'l' A is a lower triangular matrix.\nc\nc Unchanged on exit.\nc\nc TRANS - CHARACTER*1.\nc On entry, TRANS specifies the equations to be solved as\nc follows:\nc\nc TRANS = 'N' or 'n' A*x = b.\nc\nc TRANS = 'T' or 't' A'*x = b.\nc\nc TRANS = 'C' or 'c' conjg( A' )*x = b.\nc\nc Unchanged on exit.\nc\nc DIAG - CHARACTER*1.\nc On entry, DIAG specifies whether or not A is unit\nc triangular as follows:\nc\nc DIAG = 'U' or 'u' A is assumed to be unit triangular.\nc\nc DIAG = 'N' or 'n' A is not assumed to be unit\nc triangular.\nc\nc Unchanged on exit.\nc\nc N - INTEGER.\nc On entry, N specifies the order of the matrix A.\nc N must be at least zero.\nc Unchanged on exit.\nc\nc A - COMPLEX array of DIMENSION ( LDA, n ).\nc Before entry with UPLO = 'U' or 'u', the leading n by n\nc upper triangular part of the array A must contain the upper\nc triangular matrix and the strictly lower triangular part of\nc A is not referenced.\nc Before entry with UPLO = 'L' or 'l', the leading n by n\nc lower triangular part of the array A must contain the lower\nc triangular matrix and the strictly upper triangular part of\nc A is not referenced.\nc Note that when DIAG = 'U' or 'u', the diagonal elements of\nc A are not referenced either, but are assumed to be unity.\nc Unchanged on exit.\nc\nc LDA - INTEGER.\nc On entry, LDA specifies the first dimension of A as declared\nc in the calling (sub) program. LDA must be at least\nc max( 1, n ).\nc Unchanged on exit.\nc\nc X - COMPLEX array of dimension at least\nc ( 1 + ( n - 1 )*abs( INCX ) ).\nc Before entry, the incremented array X must contain the n\nc element right-hand side vector b. On exit, X is overwritten\nc with the solution vector x.\nc\nc INCX - INTEGER.\nc On entry, INCX specifies the increment for the elements of\nc X. INCX must not be zero.\nc Unchanged on exit.\nc\nc\nc Level 2 Blas routine.\nc\nc -- Written by Sourangshu Ghosh\nc\nc\nc .. Parameters ..\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\nc .. Local Scalars ..\n COMPLEX TEMP\n INTEGER I, INFO, IX, J, JX, KX\n LOGICAL NOCONJ, NOUNIT\nc .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nc .. External Subroutines ..\n EXTERNAL XERBLA\nc .. Intrinsic Functions ..\n INTRINSIC CONJG, MAX\nc ..\nc .. Executable Statements ..\nc\nc Test the input parameters.\nc\n INFO = 0\n IF ( .NOT.LSAME( UPLO , 'U' ).AND.\n $ .NOT.LSAME( UPLO , 'L' ) )THEN\n INFO = 1\n ELSE IF( .NOT.LSAME( TRANS, 'N' ).AND.\n $ .NOT.LSAME( TRANS, 'T' ).AND.\n $ .NOT.LSAME( TRANS, 'C' ) )THEN\n INFO = 2\n ELSE IF( .NOT.LSAME( DIAG , 'U' ).AND.\n $ .NOT.LSAME( DIAG , 'N' ) )THEN\n INFO = 3\n ELSE IF( N.LT.0 )THEN\n INFO = 4\n ELSE IF( LDA.LT.MAX( 1, N ) )THEN\n INFO = 6\n ELSE IF( INCX.EQ.0 )THEN\n INFO = 8\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'CTRSV ', INFO )\n RETURN\n END IF\nc\nc Quick return if possible.\nc\n IF( N.EQ.0 )\n $ RETURN\nc\n NOCONJ = LSAME( TRANS, 'T' )\n NOUNIT = LSAME( DIAG , 'N' )\nc\nc Set up the start point in X if the increment is not unity. This\nc will be ( N - 1 )*INCX too small for descending loops.\nc\n IF( INCX.LE.0 )THEN\n KX = 1 - ( N - 1 )*INCX\n ELSE IF( INCX.NE.1 )THEN\n KX = 1\n END IF\nc\nc Start the operations. In this version the elements of A are\nc accessed sequentially with one pass through A.\nc\n IF( LSAME( TRANS, 'N' ) )THEN\nc\nc Form x := inv( A )*x.\nc\n IF( LSAME( UPLO, 'U' ) )THEN\n IF( INCX.EQ.1 )THEN\n DO 20, J = N, 1, -1\n IF( X( J ).NE.ZERO )THEN\n IF( NOUNIT )\n $ X( J ) = X( J )/A( J, J )\n TEMP = X( J )\n DO 10, I = J - 1, 1, -1\n X( I ) = X( I ) - TEMP*A( I, J )\n 10 CONTINUE\n END IF\n 20 CONTINUE\n ELSE\n JX = KX + ( N - 1 )*INCX\n DO 40, J = N, 1, -1\n IF( X( JX ).NE.ZERO )THEN\n IF( NOUNIT )\n $ X( JX ) = X( JX )/A( J, J )\n TEMP = X( JX )\n IX = JX\n DO 30, I = J - 1, 1, -1\n IX = IX - INCX\n X( IX ) = X( IX ) - TEMP*A( I, J )\n 30 CONTINUE\n END IF\n JX = JX - INCX\n 40 CONTINUE\n END IF\n ELSE\n IF( INCX.EQ.1 )THEN\n DO 60, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n IF( NOUNIT )\n $ X( J ) = X( J )/A( J, J )\n TEMP = X( J )\n DO 50, I = J + 1, N\n X( I ) = X( I ) - TEMP*A( I, J )\n 50 CONTINUE\n END IF\n 60 CONTINUE\n ELSE\n JX = KX\n DO 80, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n IF( NOUNIT )\n $ X( JX ) = X( JX )/A( J, J )\n TEMP = X( JX )\n IX = JX\n DO 70, I = J + 1, N\n IX = IX + INCX\n X( IX ) = X( IX ) - TEMP*A( I, J )\n 70 CONTINUE\n END IF\n JX = JX + INCX\n 80 CONTINUE\n END IF\n END IF\n ELSE\nc\nc Form x := inv( A' )*x or x := inv( conjg( A' ) )*x.\nc\n IF( LSAME( UPLO, 'U' ) )THEN\n IF( INCX.EQ.1 )THEN\n DO 110, J = 1, N\n TEMP = X( J )\n IF( NOCONJ )THEN\n DO 90, I = 1, J - 1\n TEMP = TEMP - A( I, J )*X( I )\n 90 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/A( J, J )\n ELSE\n DO 100, I = 1, J - 1\n TEMP = TEMP - CONJG( A( I, J ) )*X( I )\n 100 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/CONJG( A( J, J ) )\n END IF\n X( J ) = TEMP\n 110 CONTINUE\n ELSE\n JX = KX\n DO 140, J = 1, N\n IX = KX\n TEMP = X( JX )\n IF( NOCONJ )THEN\n DO 120, I = 1, J - 1\n TEMP = TEMP - A( I, J )*X( IX )\n IX = IX + INCX\n 120 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/A( J, J )\n ELSE\n DO 130, I = 1, J - 1\n TEMP = TEMP - CONJG( A( I, J ) )*X( IX )\n IX = IX + INCX\n 130 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/CONJG( A( J, J ) )\n END IF\n X( JX ) = TEMP\n JX = JX + INCX\n 140 CONTINUE\n END IF\n ELSE\n IF( INCX.EQ.1 )THEN\n DO 170, J = N, 1, -1\n TEMP = X( J )\n IF( NOCONJ )THEN\n DO 150, I = N, J + 1, -1\n TEMP = TEMP - A( I, J )*X( I )\n 150 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/A( J, J )\n ELSE\n DO 160, I = N, J + 1, -1\n TEMP = TEMP - CONJG( A( I, J ) )*X( I )\n 160 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/CONJG( A( J, J ) )\n END IF\n X( J ) = TEMP\n 170 CONTINUE\n ELSE\n KX = KX + ( N - 1 )*INCX\n JX = KX\n DO 200, J = N, 1, -1\n IX = KX\n TEMP = X( JX )\n IF( NOCONJ )THEN\n DO 180, I = N, J + 1, -1\n TEMP = TEMP - A( I, J )*X( IX )\n IX = IX - INCX\n 180 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/A( J, J )\n ELSE\n DO 190, I = N, J + 1, -1\n TEMP = TEMP - CONJG( A( I, J ) )*X( IX )\n IX = IX - INCX\n 190 CONTINUE\n IF( NOUNIT )\n $ TEMP = TEMP/CONJG( A( J, J ) )\n END IF\n X( JX ) = TEMP\n JX = JX - INCX\n 200 CONTINUE\n END IF\n END IF\n END IF\nc\n RETURN\nc\nc End of CTRSV .\nc\n END\n", "meta": {"hexsha": "e85c8c60749ed3b3572c25abab520f8b4171bd71", "size": 151301, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "blas2_c/blas2_c.f", "max_stars_repo_name": "SourangshuGhosh/Basic-Linear-Algebra-Subprograms", "max_stars_repo_head_hexsha": "5b8b011a1acac19193203c54a97ebeed56fed6d3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-07-29T09:14:47.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-14T17:38:52.000Z", "max_issues_repo_path": "blas2_c/blas2_c.f", "max_issues_repo_name": "SourangshuGhosh/Basic-Linear-Algebra-Subprograms", "max_issues_repo_head_hexsha": "5b8b011a1acac19193203c54a97ebeed56fed6d3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "blas2_c/blas2_c.f", "max_forks_repo_name": "SourangshuGhosh/Basic-Linear-Algebra-Subprograms", "max_forks_repo_head_hexsha": "5b8b011a1acac19193203c54a97ebeed56fed6d3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.1370008496, "max_line_length": 72, "alphanum_fraction": 0.4177500479, "num_tokens": 45276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426832, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7562811083585343}} {"text": "! 4670 Numerical Analysis\n! Homework Four Due 11/6/17\n\nmodule secret \n\ninteger :: fcounter\n\nend module secret \n\n!-----------------------------------------------------------------------------------------------------\n\nprogram WebberHomework4Question1\nuse secret\nimplicit none\n\ndouble precision :: a, b, f, h, n\ndouble precision :: actual!, t, trapezoid\ndouble precision :: simpson, s\ninteger :: i!, n\n\na = 1.0d0\nb = 2.0d0\nn = 2.0d0\nactual = log(2.0d0)\n\nprint*, \"Newton and Composite Simpson Method\"\n\ndo i = 1, 25\n\th = (b - a) / dble(n)\nprint*, h\n\ts = simpson(n, a, b, f)\nprint*, s\n\t!write(*,* ) n, s, abs(actual - s), abs(actual - s) / h**4.0d0\n\tprint*, n, s, abs(actual - s), abs(actual - s) / h**4.0d0\n\tn = n * 2.0d0\nprint*, n\nend do\n\nstop\nend program WebberHomework4Question1\n\n!-----------------------------------------------------------------------------------------------------\n\ndouble precision function fprime(x)\nimplicit none\ndouble precision :: f, pi, x\n\nf = exp(1.0d0)\npi = (4.0d0 * ATAN(1.0d0))\t\t\t\t\t\t! most accurate for pi\n\nfprime = (1.0d0 / SQRT(2.0d0 * pi)) * (f**(-x**2.0d0) / 2.0d0)\n\nreturn \nend\n\n!-----------------------------------------------------------------------------------------------------\n\ndouble precision function simpson(n, a, b, fprime)\nimplicit none\n\ninteger :: i!, n\ndouble precision :: a, b, fv, h, n, fprime\ndouble precision :: se, so\n\nh = (b - a) / dble(n)\n\nsimpson = 0.0d0\nse = 0.0d0\nso = 0.0d0\n\ndo i = 1, n - 1\n\tfv = fprime(a + dble(i) * h)\n\tif (mod(i, 2) == 0) then\n\t\tse = se + fv\n\telse\n\t\tso = so + fv\n\tend if\nend do\n\nsimpson = (h / 3.0d0 * (fprime(a) + fprime(b) + 2.0d0 * se + 4.0d0 * so))\n\nreturn \nend\n\n!-----------------------------------------------------------------------------------------------------\n\ndouble precision function trapezoid(n, a, b, fprime)\nimplicit none\n\ninteger :: i, n\ndouble precision :: a, b, fprime, h, xuse\n\nh = (b - a) / dble(n)\n\ntrapezoid = 0.0d0\n\ndo i = 1, n - 1\n\txuse = a + dble(i) * h\n\ttrapezoid = fprime + fprime(xuse)\nend do\n\ntrapezoid = h / 2.0d0 * (2.0d0 * trapezoid + fprime(a) + fprime(b))\n\nreturn \nend\n", "meta": {"hexsha": "4f25edefa2d7567095cee14b033962e17f428c7c", "size": 2079, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "4670 Numerical Analysis/Homework4/testrun.f90", "max_stars_repo_name": "mwebber3/UnderGraduateCourses", "max_stars_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4670 Numerical Analysis/Homework4/testrun.f90", "max_issues_repo_name": "mwebber3/UnderGraduateCourses", "max_issues_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4670 Numerical Analysis/Homework4/testrun.f90", "max_forks_repo_name": "mwebber3/UnderGraduateCourses", "max_forks_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.6132075472, "max_line_length": 102, "alphanum_fraction": 0.4949494949, "num_tokens": 705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7562520031072107}} {"text": " SUBROUTINE MB02QY( M, N, NRHS, RANK, A, LDA, JPVT, B, LDB, TAU,\n $ DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To determine the minimum-norm solution to a real linear least\nC squares problem:\nC\nC minimize || A * X - B ||,\nC\nC using the rank-revealing QR factorization of a real general\nC M-by-N matrix A, computed by SLICOT Library routine MB03OD.\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC M (input) INTEGER\nC The number of rows of the matrices A and B. M >= 0.\nC\nC N (input) INTEGER\nC The number of columns of the matrix A. N >= 0.\nC\nC NRHS (input) INTEGER\nC The number of columns of the matrix B. NRHS >= 0.\nC\nC RANK (input) INTEGER\nC The effective rank of A, as returned by SLICOT Library\nC routine MB03OD. min(M,N) >= RANK >= 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension\nC ( LDA, N )\nC On entry, the leading min(M,N)-by-N upper trapezoidal\nC part of this array contains the triangular factor R, as\nC returned by SLICOT Library routine MB03OD. The strict\nC lower trapezoidal part of A is not referenced.\nC On exit, if RANK < N, the leading RANK-by-RANK upper\nC triangular part of this array contains the upper\nC triangular matrix R of the complete orthogonal\nC factorization of A, and the submatrix (1:RANK,RANK+1:N)\nC of this array, with the array TAU, represent the\nC orthogonal matrix Z (of the complete orthogonal\nC factorization of A), as a product of RANK elementary\nC reflectors.\nC On exit, if RANK = N, this array is unchanged.\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= max(1,M).\nC\nC JPVT (input) INTEGER array, dimension ( N )\nC The recorded permutations performed by SLICOT Library\nC routine MB03OD; if JPVT(i) = k, then the i-th column\nC of A*P was the k-th column of the original matrix A.\nC\nC B (input/output) DOUBLE PRECISION array, dimension\nC ( LDB, NRHS )\nC On entry, if NRHS > 0, the leading M-by-NRHS part of\nC this array must contain the matrix B (corresponding to\nC the transformed matrix A, returned by SLICOT Library\nC routine MB03OD).\nC On exit, if NRHS > 0, the leading N-by-NRHS part of this\nC array contains the solution matrix X.\nC If M >= N and RANK = N, the residual sum-of-squares\nC for the solution in the i-th column is given by the sum\nC of squares of elements N+1:M in that column.\nC If NRHS = 0, the array B is not referenced.\nC\nC LDB INTEGER\nC The leading dimension of the array B.\nC LDB >= max(1,M,N), if NRHS > 0.\nC LDB >= 1, if NRHS = 0.\nC\nC TAU (output) DOUBLE PRECISION array, dimension ( min(M,N) )\nC The scalar factors of the elementary reflectors.\nC If RANK = N, the array TAU is not referenced.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension ( LDWORK )\nC On exit, if INFO = 0, DWORK(1) returns the optimal value\nC of LDWORK.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= max( 1, N, NRHS ).\nC For good performance, LDWORK should sometimes be larger.\nC\nC If LDWORK = -1, then a workspace query is assumed;\nC the routine only calculates the optimal size of the\nC DWORK array, returns this value as the first entry of\nC the DWORK array, and no error message related to LDWORK\nC is issued by XERBLA.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC The routine uses a QR factorization with column pivoting:\nC\nC A * P = Q * R = Q * [ R11 R12 ],\nC [ 0 R22 ]\nC\nC where R11 is an upper triangular submatrix of estimated rank\nC RANK, the effective rank of A. The submatrix R22 can be\nC considered as negligible.\nC\nC If RANK < N, then R12 is annihilated by orthogonal\nC transformations from the right, arriving at the complete\nC orthogonal factorization:\nC\nC A * P = Q * [ T11 0 ] * Z.\nC [ 0 0 ]\nC\nC The minimum-norm solution is then\nC\nC X = P * Z' [ inv(T11)*Q1'*B ],\nC [ 0 ]\nC\nC where Q1 consists of the first RANK columns of Q.\nC\nC The input data for MB02QY are the transformed matrices Q' * A\nC (returned by SLICOT Library routine MB03OD) and Q' * B.\nC Matrix Q is not needed.\nC\nC NUMERICAL ASPECTS\nC\nC The implemented method is numerically stable.\nC\nC CONTRIBUTOR\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Aug. 1999.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Aug. 2011.\nC\nC KEYWORDS\nC\nC Least squares solutions; QR decomposition.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n INTEGER INFO, LDA, LDB, LDWORK, M, N, NRHS, RANK\nC .. Array Arguments ..\n INTEGER JPVT( * )\n DOUBLE PRECISION A( LDA, * ), B( LDB, * ), DWORK( * ), TAU( * )\nC .. Local Scalars ..\n LOGICAL LQUERY\n INTEGER I, IASCL, IBSCL, J, MN\n DOUBLE PRECISION ANRM, BIGNUM, BNRM, MAXWRK, SMLNUM\nC .. External Functions ..\n DOUBLE PRECISION DLAMCH, DLANGE, DLANTR\n EXTERNAL DLAMCH, DLANGE, DLANTR\nC .. External Subroutines ..\n EXTERNAL DCOPY, DLABAD, DLASCL, DLASET, DORMRZ, DTRSM,\n $ DTZRZF, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, MAX, MIN\nC ..\nC .. Executable Statements ..\nC\n MN = MIN( M, N )\nC\nC Test the input scalar arguments.\nC\n INFO = 0\n IF( M.LT.0 ) THEN\n INFO = -1\n ELSE IF( N.LT.0 ) THEN\n INFO = -2\n ELSE IF( NRHS.LT.0 ) THEN\n INFO = -3\n ELSE IF( RANK.LT.0 .OR. RANK.GT.MN ) THEN\n INFO = -4\n ELSE IF( LDA.LT.MAX( 1, M ) ) THEN\n INFO = -6\n ELSE IF( LDB.LT.1 .OR. ( NRHS.GT.0 .AND. LDB.LT.MAX( M, N ) ) )\n $ THEN\n INFO = -9\n ELSE\n I = MAX( 1, N, NRHS )\n LQUERY = LDWORK.EQ.-1\n IF ( LQUERY ) THEN\n RANK = MAX( 0, N-1 )\n CALL DTZRZF( RANK, N, A, LDA, TAU, DWORK, -1, INFO )\n MAXWRK = MAX( DBLE( I ), DWORK( 1 ) )\n CALL DORMRZ( 'Left', 'Transpose', N, NRHS, RANK, N-RANK, A,\n $ LDA, TAU, B, LDB, DWORK, -1, INFO )\n MAXWRK = MAX( MAXWRK, DWORK( 1 ) )\n END IF\n IF( LDWORK.LT.I .AND. .NOT.LQUERY )\n $ INFO = -12\n END IF\nC\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB02QY', -INFO )\n RETURN\n ELSE IF( LQUERY ) THEN\n DWORK(1) = MAXWRK\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( MIN( MN, NRHS ).EQ.0 ) THEN\n DWORK( 1 ) = ONE\n RETURN\n END IF\nC\nC Logically partition R = [ R11 R12 ],\nC [ 0 R22 ]\nC\nC where R11 = R(1:RANK,1:RANK). If RANK = N, let T11 = R11.\nC\n MAXWRK = DBLE( N )\n IF( RANK.LT.N ) THEN\nC\nC Get machine parameters.\nC\n SMLNUM = DLAMCH( 'Safe minimum' ) / DLAMCH( 'Precision' )\n BIGNUM = ONE / SMLNUM\n CALL DLABAD( SMLNUM, BIGNUM )\nC\nC Scale A, B if max entries outside range [SMLNUM,BIGNUM].\nC\n ANRM = DLANTR( 'MaxNorm', 'Upper', 'Non-unit', RANK, N, A, LDA,\n $ DWORK )\n IASCL = 0\n IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN\nC\nC Scale matrix norm up to SMLNUM.\nC\n CALL DLASCL( 'Upper', 0, 0, ANRM, SMLNUM, RANK, N, A, LDA,\n $ INFO )\n IASCL = 1\n ELSE IF( ANRM.GT.BIGNUM ) THEN\nC\nC Scale matrix norm down to BIGNUM.\nC\n CALL DLASCL( 'Upper', 0, 0, ANRM, BIGNUM, RANK, N, A, LDA,\n $ INFO )\n IASCL = 2\n ELSE IF( ANRM.EQ.ZERO ) THEN\nC\nC Matrix all zero. Return zero solution.\nC\n CALL DLASET( 'Full', N, NRHS, ZERO, ZERO, B, LDB )\n DWORK( 1 ) = ONE\n RETURN\n END IF\nC\n BNRM = DLANGE( 'MaxNorm', M, NRHS, B, LDB, DWORK )\n IBSCL = 0\n IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN\nC\nC Scale matrix norm up to SMLNUM.\nC\n CALL DLASCL( 'General', 0, 0, BNRM, SMLNUM, M, NRHS, B, LDB,\n $ INFO )\n IBSCL = 1\n ELSE IF( BNRM.GT.BIGNUM ) THEN\nC\nC Scale matrix norm down to BIGNUM.\nC\n CALL DLASCL( 'General', 0, 0, BNRM, BIGNUM, M, NRHS, B, LDB,\n $ INFO )\n IBSCL = 2\n END IF\nC\nC [R11,R12] = [ T11, 0 ] * Z.\nC Details of Householder rotations are stored in TAU.\nC Workspace need RANK, prefer RANK*NB.\nC\n CALL DTZRZF( RANK, N, A, LDA, TAU, DWORK, LDWORK, INFO )\n MAXWRK = MAX( MAXWRK, DWORK( 1 ) )\n END IF\nC\nC B(1:RANK,1:NRHS) := inv(T11) * B(1:RANK,1:NRHS).\nC\n CALL DTRSM( 'Left', 'Upper', 'No transpose', 'Non-unit', RANK,\n $ NRHS, ONE, A, LDA, B, LDB )\nC\n IF( RANK.LT.N ) THEN\nC\n CALL DLASET( 'Full', N-RANK, NRHS, ZERO, ZERO, B( RANK+1, 1 ),\n $ LDB )\nC\nC B(1:N,1:NRHS) := Z' * B(1:N,1:NRHS).\nC Workspace need NRHS, prefer NRHS*NB.\nC\n CALL DORMRZ( 'Left', 'Transpose', N, NRHS, RANK, N-RANK, A,\n $ LDA, TAU, B, LDB, DWORK, LDWORK, INFO )\n MAXWRK = MAX( MAXWRK, DWORK( 1 ) )\nC\nC Undo scaling.\nC\n IF( IASCL.EQ.1 ) THEN\n CALL DLASCL( 'General', 0, 0, ANRM, SMLNUM, N, NRHS, B, LDB,\n $ INFO )\n CALL DLASCL( 'Upper', 0, 0, SMLNUM, ANRM, RANK, RANK, A,\n $ LDA, INFO )\n ELSE IF( IASCL.EQ.2 ) THEN\n CALL DLASCL( 'General', 0, 0, ANRM, BIGNUM, N, NRHS, B, LDB,\n $ INFO )\n CALL DLASCL( 'Upper', 0, 0, BIGNUM, ANRM, RANK, RANK, A,\n $ LDA, INFO )\n END IF\n IF( IBSCL.EQ.1 ) THEN\n CALL DLASCL( 'General', 0, 0, SMLNUM, BNRM, N, NRHS, B, LDB,\n $ INFO )\n ELSE IF( IBSCL.EQ.2 ) THEN\n CALL DLASCL( 'General', 0, 0, BIGNUM, BNRM, N, NRHS, B, LDB,\n $ INFO )\n END IF\n END IF\nC\nC B(1:N,1:NRHS) := P * B(1:N,1:NRHS).\nC Workspace N.\nC\n DO 20 J = 1, NRHS\nC\n DO 10 I = 1, N\n DWORK( JPVT( I ) ) = B( I, J )\n 10 CONTINUE\nC\n CALL DCOPY( N, DWORK, 1, B( 1, J ), 1 )\n 20 CONTINUE\nC\n DWORK( 1 ) = MAXWRK\n RETURN\nC\nC *** Last line of MB02QY ***\n END\n", "meta": {"hexsha": "b0efc91be1339a3b9114df9db82ef498cbb87ebc", "size": 11497, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB02QY.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB02QY.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB02QY.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 33.1325648415, "max_line_length": 72, "alphanum_fraction": 0.5191789162, "num_tokens": 3742, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810496235896, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7561870272906331}} {"text": "\nmodule rational_numbers\n implicit none\ncontains\n\n function add(r1,r2)\n integer,dimension(2) :: add, r1,r2\n !(a1 * b2 + a2 * b1) / (b1 * b2)\n add(1) = r1(1)*r2(2)+r2(1)*r1(2)\n add(2) = r1(2)*r2(2)\n add = reduce(add)\n end function\n\n function sub(r1,r2)\n integer,dimension(2) :: sub, r1,r2\n !r₁ - r₂ = a₁/b₁ - a₂/b₂ = (a₁ * b₂ - a₂ * b₁) / (b₁ * b₂).\n sub(1) = r1(1)*r2(2)-r2(1)*r1(2)\n sub(2) = r1(2)*r2(2)\n sub = reduce(sub)\n end function\n\n function mul(r1,r2)\n integer,dimension(2) :: mul, r1,r2\n !r₁ * r₂ = (a₁ * a₂) / (b₁ * b₂).\n mul(1) = r1(1)*r2(1)\n mul(2) = r1(2)*r2(2)\n mul = reduce(mul)\n end function\n\n function div(r1,r2)\n integer,dimension(2) :: div, r1,r2\n ! r₁ / r₂ = (a₁ * b₂) / (a₂ * b₁)\n div(1) = r1(1)*r2(2)\n div(2) = r1(2)*r2(1)\n div = reduce(div)\n end function\n\n function rational_abs(r1)\n integer,dimension(2) :: rational_abs, r1\n rational_abs(1) = abs(r1(1))\n rational_abs(2) = abs(r1(2))\n end function\n\n\n function rational_to_pow(r1, ex)\n integer,dimension(2) :: rational_to_pow, r1\n integer :: ex\n !(a1 * b2 + a2 * b1) / (b1 * b2)\n rational_to_pow(1) = r1(1)**ex\n rational_to_pow(2) = r1(2)**ex\n end function\n\n \n function real_to_rational_pow(ex,r1)\n integer,dimension(2) :: r1\n real :: real_to_rational_pow,ex\n !(a1 * b2 + a2 * b1) / (b1 * b2)\n if ( r1(1)==0 ) then\n real_to_rational_pow=0.0\n else \n real_to_rational_pow = ex**(real(r1(1))/real(r1(2)))\n endif\n end function\n\n\n function gcd(m,n)\n integer,intent(in) :: m, n\n integer :: gcd,irest,ifirst\n ifirst=abs(m)\n gcd=abs(n)\n if(gcd==0)then\n gcd=ifirst\n else\n do\n irest = mod(ifirst,gcd)\n if(irest == 0) exit\n ifirst = gcd\n gcd = irest\n enddo\n gcd= abs(gcd)\n endif\n end function\n\n function reduce(r1)\n integer,dimension(2) :: reduce, r1\n integer :: gcd_num \n !(a1 * b2 + a2 * b1) / (b1 * b2)\n gcd_num = gcd(r1(1),r1(2))\n reduce(:) = r1(:)/gcd_num\n if (reduce(2)<0)then ! fix sign\n reduce = -reduce\n endif\n end function\n\nend module\n", "meta": {"hexsha": "827bba1feb2092c53360b62f32006d48c6723503", "size": 2138, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exercises/practice/rational-numbers/.meta/example.f90", "max_stars_repo_name": "ee7/exercism-fortran", "max_stars_repo_head_hexsha": "0aa3e236d086e26c1d1e8a0b5942b06d504f6bc3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exercises/practice/rational-numbers/.meta/example.f90", "max_issues_repo_name": "ee7/exercism-fortran", "max_issues_repo_head_hexsha": "0aa3e236d086e26c1d1e8a0b5942b06d504f6bc3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exercises/practice/rational-numbers/.meta/example.f90", "max_forks_repo_name": "ee7/exercism-fortran", "max_forks_repo_head_hexsha": "0aa3e236d086e26c1d1e8a0b5942b06d504f6bc3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.2708333333, "max_line_length": 63, "alphanum_fraction": 0.5523854069, "num_tokens": 866, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810407096791, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7561870201756676}} {"text": "c=======================================================================\nc\nc subroutine PEMRJBM\nc\nc Mean Reversion with Jump process (Marlim Model)\nc\nc S(t) = delta*(mu - S(t))dt + sigma*dW(t) + dq\nc\nc Poisson process dq\nc\nc dq = 0 with probability (1-lambda)dt\nc = phi with probability lambda*dt\nc\nc Method: Euler discretization of SDE\nc\nc S(1) = S\nc a = exp(- delta*dt )\nc b = sqrt((1 - exp(- 2*delta*dt))/(2*delta))\nc S(t+1) = S(t)*a + mu*(1 - a) + sigma*b*N(0,1)\nc\nc with dt = T/(N-1) \nc\nc-----------------------------------------------------------------------\nc\nc INPUT :\nc T : time (days, months, years) integer\nc N : number of sub-division(s) integer \nc S : initial value double\nc delta : velocity of the reversion double\nc mu : mean reversion double\nc sigma : process volatility double\nc lambda : jump frequency double\nc phi : jump level double\nc\nc OUTPUT :\nc y : generated step (N) double\nc info : diagnostic information integer \nc\nc-----------------------------------------------------------------------\nc\n SUBROUTINE pemrjbm ( T, N, S, delta, mu, sigma, lambda, phi,\n & y, info )\nc\n IMPLICIT NONE\nc\nc arguments i/o\n INTEGER N, T, info\n DOUBLE PRECISION S, delta, mu, sigma, lambda, phi, y(*)\nc\nc local variables \n INTEGER i, M\n DOUBLE PRECISION dt, jump, u, v, a, b\nc\nc external functions\n DOUBLE PRECISION rn, ranf\n EXTERNAL rn, ranf\nc\nc-----------------------------------------------------------------------\nc\nc initialization\n info = 0\n jump = 0 \nc\nc discetization step \n M = N - 1\n IF (M .EQ. 0) THEN\n info = -1\n RETURN\n ENDIF\n dt = (dfloat(T)/M)\nc\nc local parameters\n a = exp( - delta * dt)\n b = sqrt((1. - exp(- 2.* delta * dt))/(2. * delta))\n v = lambda * dt\nc \nc mean-reversion with jump\n y(1) = S\n DO i = 1,M\nc\nc uniform random variable U[0,1] \n u = ranf()\n IF (u .lt. v) THEN\n jump = phi\n ELSE\n jump = 0\n ENDIF\n y(i + 1) = (a*y(i)) + (mu*(1. - a)) + (b*sigma*rn()) + jump\n ENDDO\nc\n RETURN\n END\n", "meta": {"hexsha": "a2dbda9e8e3aa3d0f1ce10809a783e421bc3f4c6", "size": 2727, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/rnd/process/pemrjbm.f", "max_stars_repo_name": "alpgodev/numx", "max_stars_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-07-25T20:28:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-10T18:52:08.000Z", "max_issues_repo_path": "src/math/rnd/process/pemrjbm.f", "max_issues_repo_name": "alpgodev/numx", "max_issues_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/math/rnd/process/pemrjbm.f", "max_forks_repo_name": "alpgodev/numx", "max_forks_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.3225806452, "max_line_length": 73, "alphanum_fraction": 0.3846718005, "num_tokens": 698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810436809827, "lm_q2_score": 0.798186768138228, "lm_q1q2_score": 0.756187013451145}} {"text": " double precision function dnrm2(n,x,incx)\n integer n, incx\n double precision x(n)\nc **********\nc\nc Function dnrm2\nc\nc Given a vector x of length n, this function calculates the\nc Euclidean norm of x with stride incx.\nc\nc The function statement is\nc\nc double precision function dnrm2(n,x,incx)\nc\nc where\nc\nc n is an integer variable.\nc On entry n is the length of x.\nc On exit n is unchanged.\nc\nc x is a double precision array of dimension n.\nc On entry x specifies the vector x.\nc On exit x is unchanged.\nc\nc incx is an integer variable.\nc On entry incx specifies the stride.\nc On exit incx is unchanged.\nc\nc MINPACK-2 Project. October 1993.\nc Argonne National Laboratory and University of Minnesota.\nc Brett M. Averick and Jorge J. More'.\nc\nc **********\n double precision zero\n parameter (zero=0.0d0)\n\n integer i\n double precision scale\n\n scale = zero\n do 10 i = 1, n, incx\n scale = max(scale,abs(x(i)))\n 10 continue\n\n dnrm2 = zero\n if (scale .eq. zero) return\n\n do 20 i = 1, n, incx\n dnrm2 = dnrm2 + (x(i)/scale)**2\n 20 continue\n dnrm2 = scale*sqrt(dnrm2)\n\n end\n", "meta": {"hexsha": "f3e1c3dd353a86b0a2a7b5139575d856fbeb977b", "size": 1267, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "legacy_fortran/hsl/icfs/icf/dnrm2.f", "max_stars_repo_name": "dynamics-of-stellar-systems/dynamite_release", "max_stars_repo_head_hexsha": "a921d8a1bde98f48daeea78213fb17b3edb223bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-10-14T12:22:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T15:32:59.000Z", "max_issues_repo_path": "legacy_fortran/hsl/icfs/icf/dnrm2.f", "max_issues_repo_name": "dynamics-of-stellar-systems/dynamite_release", "max_issues_repo_head_hexsha": "a921d8a1bde98f48daeea78213fb17b3edb223bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2022-02-25T16:05:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T15:15:16.000Z", "max_forks_repo_path": "legacy_fortran/hsl/icfs/icf/dnrm2.f", "max_forks_repo_name": "dynamics-of-stellar-systems/dynamite", "max_forks_repo_head_hexsha": "5ccf936e4b1cd907db8dd7070d4ad204ed913337", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-11-04T04:36:40.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-01T01:07:38.000Z", "avg_line_length": 23.462962963, "max_line_length": 64, "alphanum_fraction": 0.5998421468, "num_tokens": 365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825849, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.7561200987250545}} {"text": "program power\nuse procedures\nimplicit none\n\nreal(kind=8), allocatable, dimension(:,:) :: a\nreal(kind=8), allocatable, dimension(:) :: x\nreal(kind=8) :: some_number, eigenval\ninteger :: n, i, j, io\n\nwrite(*,*)\n\n! Determine dimensions of a:\nopen (unit=2, file='a.txt', status='old', action='read')\nn = 0\ndo\n read(2,*,iostat=io) some_number\n if (io /= 0) exit \n n = n + 1\nend do\nwrite(*,*) \"number of equations and variables: \", n\nwrite(*,*)\nallocate(a(n,n), x(n))\n\n! Assign the elements of a:\nrewind(2)\ndo i = 1, n\n read(2,*) (a(i,j), j = 1,n)\nend do\nclose(2)\n\nwrite(*,*) \"The matrix a:\"\ncall writes2d(a)\nwrite(*,*)\n\n! Assign the elements of x:\nx(1) = 1.0d0\nx(2) = 1.0d0\nx(3) = 1.0d0\n\neigenval = MaxEig(A)\n\nend program power\n", "meta": {"hexsha": "09f635617973b11dee5deb0dac2b39e4a3a73cd7", "size": 734, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ME_Numerical_Methods/HW6/ex1/main.f95", "max_stars_repo_name": "ElenaKusevska/Fortran_exercises", "max_stars_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ME_Numerical_Methods/HW6/ex1/main.f95", "max_issues_repo_name": "ElenaKusevska/Fortran_exercises", "max_issues_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ME_Numerical_Methods/HW6/ex1/main.f95", "max_forks_repo_name": "ElenaKusevska/Fortran_exercises", "max_forks_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.0697674419, "max_line_length": 56, "alphanum_fraction": 0.6171662125, "num_tokens": 276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857378, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7560856017968834}} {"text": "ELEMENTAL FUNCTION func_normal_CDF(x, mean, stddev) RESULT(ans)\n ! NOTE: See https://en.wikipedia.org/wiki/Normal_distribution\n\n USE ISO_FORTRAN_ENV\n\n IMPLICIT NONE\n\n ! Declare inputs/outputs ...\n REAL(kind = REAL64) :: ans\n REAL(kind = REAL64), INTENT(in) :: mean\n REAL(kind = REAL64), INTENT(in) :: stddev\n REAL(kind = REAL64), INTENT(in) :: x\n\n ! Declare internal variables ...\n REAL(kind = REAL64) :: tmp\n\n ! Calculate short-hand ...\n tmp = (x - mean) / (stddev * SQRT(2.0e0_REAL64))\n\n ! Calculate CDF ...\n ans = 0.5e0_REAL64 * (1.0e0_REAL64 + ERF(tmp))\nEND FUNCTION func_normal_CDF\n", "meta": {"hexsha": "871f7b9630bd51ace2cad28a6df462f791569099", "size": 873, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mod_safe/func_normal_CDF.f90", "max_stars_repo_name": "Guymer/fortranlib", "max_stars_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-28T02:05:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-16T16:50:21.000Z", "max_issues_repo_path": "mod_safe/func_normal_CDF.f90", "max_issues_repo_name": "Guymer/fortranlib", "max_issues_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-06-17T16:49:20.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-11T18:47:36.000Z", "max_forks_repo_path": "mod_safe/func_normal_CDF.f90", "max_forks_repo_name": "Guymer/fortranlib", "max_forks_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-11T04:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-11T04:51:33.000Z", "avg_line_length": 37.9565217391, "max_line_length": 89, "alphanum_fraction": 0.4604810997, "num_tokens": 191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857379, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7560855924075969}} {"text": "\nmodule stdlib_math\n use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, qp\n use stdlib_optval, only: optval\n\n implicit none\n private\n public :: clip, linspace, logspace\n public :: EULERS_NUMBER_SP, EULERS_NUMBER_DP, EULERS_NUMBER_QP\n public :: DEFAULT_LINSPACE_LENGTH, DEFAULT_LOGSPACE_BASE, DEFAULT_LOGSPACE_LENGTH\n public :: arange\n\n integer, parameter :: DEFAULT_LINSPACE_LENGTH = 100\n integer, parameter :: DEFAULT_LOGSPACE_LENGTH = 50\n integer, parameter :: DEFAULT_LOGSPACE_BASE = 10\n\n ! Useful constants for lnspace\n real(sp), parameter :: EULERS_NUMBER_SP = exp(1.0_sp)\n real(dp), parameter :: EULERS_NUMBER_DP = exp(1.0_dp)\n real(qp), parameter :: EULERS_NUMBER_QP = exp(1.0_qp)\n\n interface clip\n module procedure clip_int8\n module procedure clip_int16\n module procedure clip_int32\n module procedure clip_int64\n module procedure clip_sp\n module procedure clip_dp\n module procedure clip_qp\n end interface clip\n\n interface linspace\n !! Version: Experimental\n !!\n !! Create rank 1 array of linearly spaced elements\n !! If the number of elements is not specified, create an array with size 100. If n is a negative value,\n !! return an array with size 0. If n = 1, return an array whose only element is end\n !!([Specification](../page/specs/stdlib_math.html#linspace-create-a-linearly-spaced-rank-one-array))\n module function linspace_default_1_rsp_rsp(start, end) result(res)\n real(sp), intent(in) :: start\n real(sp), intent(in) :: end\n\n real(sp) :: res(DEFAULT_LINSPACE_LENGTH)\n end function linspace_default_1_rsp_rsp\n module function linspace_default_1_rdp_rdp(start, end) result(res)\n real(dp), intent(in) :: start\n real(dp), intent(in) :: end\n\n real(dp) :: res(DEFAULT_LINSPACE_LENGTH)\n end function linspace_default_1_rdp_rdp\n module function linspace_default_1_rqp_rqp(start, end) result(res)\n real(qp), intent(in) :: start\n real(qp), intent(in) :: end\n\n real(qp) :: res(DEFAULT_LINSPACE_LENGTH)\n end function linspace_default_1_rqp_rqp\n module function linspace_default_1_csp_csp(start, end) result(res)\n complex(sp), intent(in) :: start\n complex(sp), intent(in) :: end\n\n complex(sp) :: res(DEFAULT_LINSPACE_LENGTH)\n end function linspace_default_1_csp_csp\n module function linspace_default_1_cdp_cdp(start, end) result(res)\n complex(dp), intent(in) :: start\n complex(dp), intent(in) :: end\n\n complex(dp) :: res(DEFAULT_LINSPACE_LENGTH)\n end function linspace_default_1_cdp_cdp\n module function linspace_default_1_cqp_cqp(start, end) result(res)\n complex(qp), intent(in) :: start\n complex(qp), intent(in) :: end\n\n complex(qp) :: res(DEFAULT_LINSPACE_LENGTH)\n end function linspace_default_1_cqp_cqp\n\n module function linspace_n_1_rsp_rsp(start, end, n) result(res)\n real(sp), intent(in) :: start\n real(sp), intent(in) :: end\n integer, intent(in) :: n\n\n real(sp) :: res(max(n, 0))\n end function linspace_n_1_rsp_rsp\n module function linspace_n_1_rdp_rdp(start, end, n) result(res)\n real(dp), intent(in) :: start\n real(dp), intent(in) :: end\n integer, intent(in) :: n\n\n real(dp) :: res(max(n, 0))\n end function linspace_n_1_rdp_rdp\n module function linspace_n_1_rqp_rqp(start, end, n) result(res)\n real(qp), intent(in) :: start\n real(qp), intent(in) :: end\n integer, intent(in) :: n\n\n real(qp) :: res(max(n, 0))\n end function linspace_n_1_rqp_rqp\n module function linspace_n_1_csp_csp(start, end, n) result(res)\n complex(sp), intent(in) :: start\n complex(sp), intent(in) :: end\n integer, intent(in) :: n\n\n complex(sp) :: res(max(n, 0))\n end function linspace_n_1_csp_csp\n module function linspace_n_1_cdp_cdp(start, end, n) result(res)\n complex(dp), intent(in) :: start\n complex(dp), intent(in) :: end\n integer, intent(in) :: n\n\n complex(dp) :: res(max(n, 0))\n end function linspace_n_1_cdp_cdp\n module function linspace_n_1_cqp_cqp(start, end, n) result(res)\n complex(qp), intent(in) :: start\n complex(qp), intent(in) :: end\n integer, intent(in) :: n\n\n complex(qp) :: res(max(n, 0))\n end function linspace_n_1_cqp_cqp\n\n\n ! Add support for integer linspace\n !!\n !! When dealing with integers as the `start` and `end` parameters, the return type is always a `real(dp)`.\n module function linspace_default_1_iint8_iint8(start, end) result(res)\n integer(int8), intent(in) :: start\n integer(int8), intent(in) :: end\n\n real(dp) :: res(DEFAULT_LINSPACE_LENGTH)\n end function linspace_default_1_iint8_iint8\n module function linspace_default_1_iint16_iint16(start, end) result(res)\n integer(int16), intent(in) :: start\n integer(int16), intent(in) :: end\n\n real(dp) :: res(DEFAULT_LINSPACE_LENGTH)\n end function linspace_default_1_iint16_iint16\n module function linspace_default_1_iint32_iint32(start, end) result(res)\n integer(int32), intent(in) :: start\n integer(int32), intent(in) :: end\n\n real(dp) :: res(DEFAULT_LINSPACE_LENGTH)\n end function linspace_default_1_iint32_iint32\n module function linspace_default_1_iint64_iint64(start, end) result(res)\n integer(int64), intent(in) :: start\n integer(int64), intent(in) :: end\n\n real(dp) :: res(DEFAULT_LINSPACE_LENGTH)\n end function linspace_default_1_iint64_iint64\n\n module function linspace_n_1_iint8_iint8(start, end, n) result(res)\n integer(int8), intent(in) :: start\n integer(int8), intent(in) :: end\n integer, intent(in) :: n\n\n real(dp) :: res(max(n, 0))\n end function linspace_n_1_iint8_iint8\n module function linspace_n_1_iint16_iint16(start, end, n) result(res)\n integer(int16), intent(in) :: start\n integer(int16), intent(in) :: end\n integer, intent(in) :: n\n\n real(dp) :: res(max(n, 0))\n end function linspace_n_1_iint16_iint16\n module function linspace_n_1_iint32_iint32(start, end, n) result(res)\n integer(int32), intent(in) :: start\n integer(int32), intent(in) :: end\n integer, intent(in) :: n\n\n real(dp) :: res(max(n, 0))\n end function linspace_n_1_iint32_iint32\n module function linspace_n_1_iint64_iint64(start, end, n) result(res)\n integer(int64), intent(in) :: start\n integer(int64), intent(in) :: end\n integer, intent(in) :: n\n\n real(dp) :: res(max(n, 0))\n end function linspace_n_1_iint64_iint64\n\n end interface\n\n interface logspace\n !! Version: Experimental\n !!\n !! Create rank 1 array of logarithmically spaced elements from base**start to base**end.\n !! If the number of elements is not specified, create an array with size 50. If n is a negative value,\n !! return an array with size 0. If n = 1, return an array whose only element is base**end. If no base\n !! is specified, logspace will default to using a base of 10\n !!\n !!([Specification](../page/specs/stdlib_math.html#logspace-create-a-logarithmically-spaced-rank-one-array))\n module function logspace_1_rsp_default(start, end) result(res)\n\n real(sp), intent(in) :: start\n real(sp), intent(in) :: end\n\n real(sp) :: res(DEFAULT_LOGSPACE_LENGTH)\n\n end function logspace_1_rsp_default\n module function logspace_1_rdp_default(start, end) result(res)\n\n real(dp), intent(in) :: start\n real(dp), intent(in) :: end\n\n real(dp) :: res(DEFAULT_LOGSPACE_LENGTH)\n\n end function logspace_1_rdp_default\n module function logspace_1_rqp_default(start, end) result(res)\n\n real(qp), intent(in) :: start\n real(qp), intent(in) :: end\n\n real(qp) :: res(DEFAULT_LOGSPACE_LENGTH)\n\n end function logspace_1_rqp_default\n module function logspace_1_csp_default(start, end) result(res)\n\n complex(sp), intent(in) :: start\n complex(sp), intent(in) :: end\n\n complex(sp) :: res(DEFAULT_LOGSPACE_LENGTH)\n\n end function logspace_1_csp_default\n module function logspace_1_cdp_default(start, end) result(res)\n\n complex(dp), intent(in) :: start\n complex(dp), intent(in) :: end\n\n complex(dp) :: res(DEFAULT_LOGSPACE_LENGTH)\n\n end function logspace_1_cdp_default\n module function logspace_1_cqp_default(start, end) result(res)\n\n complex(qp), intent(in) :: start\n complex(qp), intent(in) :: end\n\n complex(qp) :: res(DEFAULT_LOGSPACE_LENGTH)\n\n end function logspace_1_cqp_default\n module function logspace_1_iint32_default(start, end) result(res)\n\n integer, intent(in) :: start\n integer, intent(in) :: end\n\n real(dp) :: res(DEFAULT_LOGSPACE_LENGTH)\n\n end function logspace_1_iint32_default\n\n module function logspace_1_rsp_n(start, end, n) result(res)\n real(sp), intent(in) :: start\n real(sp), intent(in) :: end\n integer, intent(in) :: n\n\n real(sp) :: res(max(n, 0))\n end function logspace_1_rsp_n\n module function logspace_1_rdp_n(start, end, n) result(res)\n real(dp), intent(in) :: start\n real(dp), intent(in) :: end\n integer, intent(in) :: n\n\n real(dp) :: res(max(n, 0))\n end function logspace_1_rdp_n\n module function logspace_1_rqp_n(start, end, n) result(res)\n real(qp), intent(in) :: start\n real(qp), intent(in) :: end\n integer, intent(in) :: n\n\n real(qp) :: res(max(n, 0))\n end function logspace_1_rqp_n\n module function logspace_1_csp_n(start, end, n) result(res)\n complex(sp), intent(in) :: start\n complex(sp), intent(in) :: end\n integer, intent(in) :: n\n\n complex(sp) :: res(max(n, 0))\n end function logspace_1_csp_n\n module function logspace_1_cdp_n(start, end, n) result(res)\n complex(dp), intent(in) :: start\n complex(dp), intent(in) :: end\n integer, intent(in) :: n\n\n complex(dp) :: res(max(n, 0))\n end function logspace_1_cdp_n\n module function logspace_1_cqp_n(start, end, n) result(res)\n complex(qp), intent(in) :: start\n complex(qp), intent(in) :: end\n integer, intent(in) :: n\n\n complex(qp) :: res(max(n, 0))\n end function logspace_1_cqp_n\n module function logspace_1_iint32_n(start, end, n) result(res)\n integer, intent(in) :: start\n integer, intent(in) :: end\n integer, intent(in) :: n\n\n real(dp) :: res(n)\n end function logspace_1_iint32_n\n\n ! Generate logarithmically spaced sequence from sp base to the powers\n ! of sp start and end. [base^start, ... , base^end]\n ! Different combinations of parameter types will lead to different result types.\n ! Those combinations are indicated in the body of each function.\n module function logspace_1_rsp_n_rbase(start, end, n, base) result(res)\n real(sp), intent(in) :: start\n real(sp), intent(in) :: end\n integer, intent(in) :: n\n real(sp), intent(in) :: base\n ! real(sp) endpoints + real(sp) base = real(sp) result\n real(sp) :: res(max(n, 0))\n end function logspace_1_rsp_n_rbase\n\n module function logspace_1_rsp_n_cbase(start, end, n, base) result(res)\n real(sp), intent(in) :: start\n real(sp), intent(in) :: end\n integer, intent(in) :: n\n complex(sp), intent(in) :: base\n ! real(sp) endpoints + complex(sp) base = complex(sp) result\n real(sp) :: res(max(n, 0))\n end function logspace_1_rsp_n_cbase\n\n module function logspace_1_rsp_n_ibase(start, end, n, base) result(res)\n real(sp), intent(in) :: start\n real(sp), intent(in) :: end\n integer, intent(in) :: n\n integer, intent(in) :: base\n ! real(sp) endpoints + integer base = real(sp) result\n real(sp) :: res(max(n, 0))\n end function logspace_1_rsp_n_ibase\n ! Generate logarithmically spaced sequence from dp base to the powers\n ! of dp start and end. [base^start, ... , base^end]\n ! Different combinations of parameter types will lead to different result types.\n ! Those combinations are indicated in the body of each function.\n module function logspace_1_rdp_n_rbase(start, end, n, base) result(res)\n real(dp), intent(in) :: start\n real(dp), intent(in) :: end\n integer, intent(in) :: n\n real(dp), intent(in) :: base\n ! real(dp) endpoints + real(dp) base = real(dp) result\n real(dp) :: res(max(n, 0))\n end function logspace_1_rdp_n_rbase\n\n module function logspace_1_rdp_n_cbase(start, end, n, base) result(res)\n real(dp), intent(in) :: start\n real(dp), intent(in) :: end\n integer, intent(in) :: n\n complex(dp), intent(in) :: base\n ! real(dp) endpoints + complex(dp) base = complex(dp) result\n real(dp) :: res(max(n, 0))\n end function logspace_1_rdp_n_cbase\n\n module function logspace_1_rdp_n_ibase(start, end, n, base) result(res)\n real(dp), intent(in) :: start\n real(dp), intent(in) :: end\n integer, intent(in) :: n\n integer, intent(in) :: base\n ! real(dp) endpoints + integer base = real(dp) result\n real(dp) :: res(max(n, 0))\n end function logspace_1_rdp_n_ibase\n ! Generate logarithmically spaced sequence from qp base to the powers\n ! of qp start and end. [base^start, ... , base^end]\n ! Different combinations of parameter types will lead to different result types.\n ! Those combinations are indicated in the body of each function.\n module function logspace_1_rqp_n_rbase(start, end, n, base) result(res)\n real(qp), intent(in) :: start\n real(qp), intent(in) :: end\n integer, intent(in) :: n\n real(qp), intent(in) :: base\n ! real(qp) endpoints + real(qp) base = real(qp) result\n real(qp) :: res(max(n, 0))\n end function logspace_1_rqp_n_rbase\n\n module function logspace_1_rqp_n_cbase(start, end, n, base) result(res)\n real(qp), intent(in) :: start\n real(qp), intent(in) :: end\n integer, intent(in) :: n\n complex(qp), intent(in) :: base\n ! real(qp) endpoints + complex(qp) base = complex(qp) result\n real(qp) :: res(max(n, 0))\n end function logspace_1_rqp_n_cbase\n\n module function logspace_1_rqp_n_ibase(start, end, n, base) result(res)\n real(qp), intent(in) :: start\n real(qp), intent(in) :: end\n integer, intent(in) :: n\n integer, intent(in) :: base\n ! real(qp) endpoints + integer base = real(qp) result\n real(qp) :: res(max(n, 0))\n end function logspace_1_rqp_n_ibase\n ! Generate logarithmically spaced sequence from sp base to the powers\n ! of sp start and end. [base^start, ... , base^end]\n ! Different combinations of parameter types will lead to different result types.\n ! Those combinations are indicated in the body of each function.\n module function logspace_1_csp_n_rbase(start, end, n, base) result(res)\n complex(sp), intent(in) :: start\n complex(sp), intent(in) :: end\n integer, intent(in) :: n\n real(sp), intent(in) :: base\n ! complex(sp) endpoints + real(sp) base = complex(sp) result\n complex(sp) :: res(max(n, 0))\n end function logspace_1_csp_n_rbase\n\n module function logspace_1_csp_n_cbase(start, end, n, base) result(res)\n complex(sp), intent(in) :: start\n complex(sp), intent(in) :: end\n integer, intent(in) :: n\n complex(sp), intent(in) :: base\n ! complex(sp) endpoints + complex(sp) base = complex(sp) result\n complex(sp) :: res(max(n, 0))\n end function logspace_1_csp_n_cbase\n\n module function logspace_1_csp_n_ibase(start, end, n, base) result(res)\n complex(sp), intent(in) :: start\n complex(sp), intent(in) :: end\n integer, intent(in) :: n\n integer, intent(in) :: base\n ! complex(sp) endpoints + integer base = complex(sp) result\n complex(sp) :: res(max(n, 0))\n end function logspace_1_csp_n_ibase\n ! Generate logarithmically spaced sequence from dp base to the powers\n ! of dp start and end. [base^start, ... , base^end]\n ! Different combinations of parameter types will lead to different result types.\n ! Those combinations are indicated in the body of each function.\n module function logspace_1_cdp_n_rbase(start, end, n, base) result(res)\n complex(dp), intent(in) :: start\n complex(dp), intent(in) :: end\n integer, intent(in) :: n\n real(dp), intent(in) :: base\n ! complex(dp) endpoints + real(dp) base = complex(dp) result\n complex(dp) :: res(max(n, 0))\n end function logspace_1_cdp_n_rbase\n\n module function logspace_1_cdp_n_cbase(start, end, n, base) result(res)\n complex(dp), intent(in) :: start\n complex(dp), intent(in) :: end\n integer, intent(in) :: n\n complex(dp), intent(in) :: base\n ! complex(dp) endpoints + complex(dp) base = complex(dp) result\n complex(dp) :: res(max(n, 0))\n end function logspace_1_cdp_n_cbase\n\n module function logspace_1_cdp_n_ibase(start, end, n, base) result(res)\n complex(dp), intent(in) :: start\n complex(dp), intent(in) :: end\n integer, intent(in) :: n\n integer, intent(in) :: base\n ! complex(dp) endpoints + integer base = complex(dp) result\n complex(dp) :: res(max(n, 0))\n end function logspace_1_cdp_n_ibase\n ! Generate logarithmically spaced sequence from qp base to the powers\n ! of qp start and end. [base^start, ... , base^end]\n ! Different combinations of parameter types will lead to different result types.\n ! Those combinations are indicated in the body of each function.\n module function logspace_1_cqp_n_rbase(start, end, n, base) result(res)\n complex(qp), intent(in) :: start\n complex(qp), intent(in) :: end\n integer, intent(in) :: n\n real(qp), intent(in) :: base\n ! complex(qp) endpoints + real(qp) base = complex(qp) result\n complex(qp) :: res(max(n, 0))\n end function logspace_1_cqp_n_rbase\n\n module function logspace_1_cqp_n_cbase(start, end, n, base) result(res)\n complex(qp), intent(in) :: start\n complex(qp), intent(in) :: end\n integer, intent(in) :: n\n complex(qp), intent(in) :: base\n ! complex(qp) endpoints + complex(qp) base = complex(qp) result\n complex(qp) :: res(max(n, 0))\n end function logspace_1_cqp_n_cbase\n\n module function logspace_1_cqp_n_ibase(start, end, n, base) result(res)\n complex(qp), intent(in) :: start\n complex(qp), intent(in) :: end\n integer, intent(in) :: n\n integer, intent(in) :: base\n ! complex(qp) endpoints + integer base = complex(qp) result\n complex(qp) :: res(max(n, 0))\n end function logspace_1_cqp_n_ibase\n ! Generate logarithmically spaced sequence from qp base to the powers\n ! of qp start and end. [base^start, ... , base^end]\n ! Different combinations of parameter types will lead to different result types.\n ! Those combinations are indicated in the body of each function.\n module function logspace_1_iint32_n_rspbase(start, end, n, base) result(res)\n integer, intent(in) :: start\n integer, intent(in) :: end\n integer, intent(in) :: n\n real(sp), intent(in) :: base\n ! integer endpoints + real(sp) base = real(sp) result\n real(sp) :: res(max(n, 0))\n end function logspace_1_iint32_n_rspbase\n\n module function logspace_1_iint32_n_cspbase(start, end, n, base) result(res)\n integer, intent(in) :: start\n integer, intent(in) :: end\n integer, intent(in) :: n\n complex(sp), intent(in) :: base\n ! integer endpoints + complex(sp) base = complex(sp) result\n complex(sp) :: res(max(n, 0))\n end function logspace_1_iint32_n_cspbase\n module function logspace_1_iint32_n_rdpbase(start, end, n, base) result(res)\n integer, intent(in) :: start\n integer, intent(in) :: end\n integer, intent(in) :: n\n real(dp), intent(in) :: base\n ! integer endpoints + real(dp) base = real(dp) result\n real(dp) :: res(max(n, 0))\n end function logspace_1_iint32_n_rdpbase\n\n module function logspace_1_iint32_n_cdpbase(start, end, n, base) result(res)\n integer, intent(in) :: start\n integer, intent(in) :: end\n integer, intent(in) :: n\n complex(dp), intent(in) :: base\n ! integer endpoints + complex(dp) base = complex(dp) result\n complex(dp) :: res(max(n, 0))\n end function logspace_1_iint32_n_cdpbase\n module function logspace_1_iint32_n_rqpbase(start, end, n, base) result(res)\n integer, intent(in) :: start\n integer, intent(in) :: end\n integer, intent(in) :: n\n real(qp), intent(in) :: base\n ! integer endpoints + real(qp) base = real(qp) result\n real(qp) :: res(max(n, 0))\n end function logspace_1_iint32_n_rqpbase\n\n module function logspace_1_iint32_n_cqpbase(start, end, n, base) result(res)\n integer, intent(in) :: start\n integer, intent(in) :: end\n integer, intent(in) :: n\n complex(qp), intent(in) :: base\n ! integer endpoints + complex(qp) base = complex(qp) result\n complex(qp) :: res(max(n, 0))\n end function logspace_1_iint32_n_cqpbase\n\n module function logspace_1_iint32_n_ibase(start, end, n, base) result(res)\n integer, intent(in) :: start\n integer, intent(in) :: end\n integer, intent(in) :: n\n integer, intent(in) :: base\n ! integer endpoints + integer base = integer result\n integer :: res(max(n, 0))\n end function logspace_1_iint32_n_ibase\n\n\n end interface\n\n !> Version: experimental\n !>\n !> `arange` creates a one-dimensional `array` of the `integer/real` type \n !> with fixed-spaced values of given spacing, within a given interval.\n !> ([Specification](../page/specs/stdlib_math.html#arange))\n interface arange\n pure module function arange_r_sp(start, end, step) result(result)\n real(sp), intent(in) :: start\n real(sp), intent(in), optional :: end, step\n real(sp), allocatable :: result(:)\n end function arange_r_sp\n pure module function arange_r_dp(start, end, step) result(result)\n real(dp), intent(in) :: start\n real(dp), intent(in), optional :: end, step\n real(dp), allocatable :: result(:)\n end function arange_r_dp\n pure module function arange_r_qp(start, end, step) result(result)\n real(qp), intent(in) :: start\n real(qp), intent(in), optional :: end, step\n real(qp), allocatable :: result(:)\n end function arange_r_qp\n pure module function arange_i_int8(start, end, step) result(result)\n integer(int8), intent(in) :: start\n integer(int8), intent(in), optional :: end, step\n integer(int8), allocatable :: result(:)\n end function arange_i_int8\n pure module function arange_i_int16(start, end, step) result(result)\n integer(int16), intent(in) :: start\n integer(int16), intent(in), optional :: end, step\n integer(int16), allocatable :: result(:)\n end function arange_i_int16\n pure module function arange_i_int32(start, end, step) result(result)\n integer(int32), intent(in) :: start\n integer(int32), intent(in), optional :: end, step\n integer(int32), allocatable :: result(:)\n end function arange_i_int32\n pure module function arange_i_int64(start, end, step) result(result)\n integer(int64), intent(in) :: start\n integer(int64), intent(in), optional :: end, step\n integer(int64), allocatable :: result(:)\n end function arange_i_int64\n end interface arange\n\ncontains\n\n elemental function clip_int8(x, xmin, xmax) result(res)\n integer(int8), intent(in) :: x\n integer(int8), intent(in) :: xmin\n integer(int8), intent(in) :: xmax\n integer(int8) :: res\n\n res = max(min(x, xmax), xmin)\n end function clip_int8\n\n elemental function clip_int16(x, xmin, xmax) result(res)\n integer(int16), intent(in) :: x\n integer(int16), intent(in) :: xmin\n integer(int16), intent(in) :: xmax\n integer(int16) :: res\n\n res = max(min(x, xmax), xmin)\n end function clip_int16\n\n elemental function clip_int32(x, xmin, xmax) result(res)\n integer(int32), intent(in) :: x\n integer(int32), intent(in) :: xmin\n integer(int32), intent(in) :: xmax\n integer(int32) :: res\n\n res = max(min(x, xmax), xmin)\n end function clip_int32\n\n elemental function clip_int64(x, xmin, xmax) result(res)\n integer(int64), intent(in) :: x\n integer(int64), intent(in) :: xmin\n integer(int64), intent(in) :: xmax\n integer(int64) :: res\n\n res = max(min(x, xmax), xmin)\n end function clip_int64\n\n elemental function clip_sp(x, xmin, xmax) result(res)\n real(sp), intent(in) :: x\n real(sp), intent(in) :: xmin\n real(sp), intent(in) :: xmax\n real(sp) :: res\n\n res = max(min(x, xmax), xmin)\n end function clip_sp\n\n elemental function clip_dp(x, xmin, xmax) result(res)\n real(dp), intent(in) :: x\n real(dp), intent(in) :: xmin\n real(dp), intent(in) :: xmax\n real(dp) :: res\n\n res = max(min(x, xmax), xmin)\n end function clip_dp\n\n elemental function clip_qp(x, xmin, xmax) result(res)\n real(qp), intent(in) :: x\n real(qp), intent(in) :: xmin\n real(qp), intent(in) :: xmax\n real(qp) :: res\n\n res = max(min(x, xmax), xmin)\n end function clip_qp\n\nend module stdlib_math\n", "meta": {"hexsha": "44201dbb67b8214157292665acd5db8cfece1468", "size": 25626, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stdlib_math.f90", "max_stars_repo_name": "LKedward/stdlib-fpm", "max_stars_repo_head_hexsha": "312e798a2777d571efcf7e5f96f81a7297590685", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-05-05T10:52:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-26T02:40:56.000Z", "max_issues_repo_path": "src/stdlib_math.f90", "max_issues_repo_name": "LKedward/stdlib-fpm", "max_issues_repo_head_hexsha": "312e798a2777d571efcf7e5f96f81a7297590685", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-03-20T12:36:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-17T07:56:11.000Z", "max_forks_repo_path": "src/stdlib_math.f90", "max_forks_repo_name": "LKedward/stdlib-fpm", "max_forks_repo_head_hexsha": "312e798a2777d571efcf7e5f96f81a7297590685", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.3036809816, "max_line_length": 110, "alphanum_fraction": 0.6442285179, "num_tokens": 6940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122263731811, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7560855901083673}} {"text": "! A[r,s] * B[s,t] = C[r,t]\nsubroutine matrix_multiply(A,r,s,B,t,C)\n\tinteger :: r, s, t\n\treal, intent(in) :: A(r,s)\n\treal, intent(in) :: B(s,t)\n\treal, intent(out) :: C(r,t)\n\n\tC = matmul(A,B)\nend subroutine matrix_multiply\n\t\n\t", "meta": {"hexsha": "a40dac38d66fefa7a34acaeb47f9dbbb0602cfcb", "size": 224, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "f2py/arr1.f90", "max_stars_repo_name": "jonaslindemann/compute-course-public", "max_stars_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-09-12T12:07:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-29T17:38:34.000Z", "max_issues_repo_path": "f2py/arr1.f90", "max_issues_repo_name": "jonaslindemann/compute-course-public", "max_issues_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "f2py/arr1.f90", "max_forks_repo_name": "jonaslindemann/compute-course-public", "max_forks_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-10-24T16:02:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-28T20:57:46.000Z", "avg_line_length": 20.3636363636, "max_line_length": 39, "alphanum_fraction": 0.59375, "num_tokens": 78, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.907312213841788, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7560855796656493}} {"text": "function rosenbrock(x)\n\n!*****************************************************************************80\n!\n!! ROSENBROCK evaluates the Rosenbrock parabolic value function.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 19 February 2008\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! R ONeill,\n! Algorithm AS 47:\n! Function Minimization Using a Simplex Procedure,\n! Applied Statistics,\n! Volume 20, Number 3, 1971, pages 338-345.\n!\n! Parameters:\n!\n! Input, real(dp) X(2), the argument.\n!\n! Output, real(dp) ROSENBROCK, the value of the function.\n!\n use mo_kind, only: dp\n\n implicit none\n\n real(dp), dimension(:), intent(in) :: x\n real(dp) :: rosenbrock\n\n real(dp) :: fx\n real(dp) :: fx1\n real(dp) :: fx2\n\n fx1 = x(2) - x(1) * x(1)\n fx2 = 1.0_dp - x(1)\n\n fx = 100.0_dp * fx1 * fx1 + fx2 * fx2\n\n rosenbrock = fx\n\n return\n\nend function rosenbrock\n", "meta": {"hexsha": "9a87eb300667c6a9ae6f53c3ee32185048e97553", "size": 937, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_nelmin/rosenbrock.f90", "max_stars_repo_name": "mcuntz/jams_fortran", "max_stars_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2020-02-28T00:14:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-20T23:32:41.000Z", "max_issues_repo_path": "test/test_mo_nelmin/rosenbrock.f90", "max_issues_repo_name": "mcuntz/jams_fortran", "max_issues_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-09T15:33:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T16:16:09.000Z", "max_forks_repo_path": "test/test_mo_nelmin/rosenbrock.f90", "max_forks_repo_name": "mcuntz/jams_fortran", "max_forks_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-09T08:08:56.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-09T08:08:56.000Z", "avg_line_length": 17.3518518519, "max_line_length": 80, "alphanum_fraction": 0.5709711846, "num_tokens": 303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7560855779984782}} {"text": "Program P1\r\n\tImplicit none\r\n\treal*8 :: dt, min, max, t\r\n\treal*8, dimension(2) :: y\r\n\tinteger :: n\r\n\tparameter (n=2) ! y 1: pos; 2: vel; \r\n\r\n\t! inteval\r\n\tmin=0.0D0\r\n\tmax=200.0D0\r\n\t! time step\r\n\tdt=0.1D0\r\n\t! initial position\r\n\ty(1)=0.0D0\r\n\t! initial velocity\r\n\ty(2)=4.0D0\r\n\r\n\t! print the exact result\r\n\tprint *, sqrt(4.0D0**2.D0+2.d0*400*max/70)\r\n\tOpen(6, File='P1.dat')\r\n\r\n\t! Runga-Kutta iteration\r\n\tDo t=min, max, dt\r\n\t\tCall rk2(t, dt, y, n)\r\n\t\tWrite (6,*) t, y(2) ! y(2): vel\r\n\tenddo\r\n\r\n\tClose(6)\r\nEnd program P1\r\n\r\n! second-order Runge-Kutta subroutine \r\n! will update y(1) & y(2) based on n\r\nsubroutine rk2(t, dt, y, n)\r\n\tImplicit none\r\n\treal*8, external :: deriv\r\n\treal*8, intent(in) :: t, dt\r\n\treal*8, intent(inout), dimension(2) :: y\r\n\treal*8 :: h\r\n\treal*8, dimension(2) :: k1, k2, t1\r\n\tinteger :: i,n\r\n\r\n\th=dt/2.0D0\r\n\tDo i = 1,n\r\n\t k1(i) = dt * deriv(y, i)\r\n\t t1(i) = y(i) + 0.5D0*k1(i)\r\n\tenddo\r\n\tDo i = 1,n\r\n\t k2(i) = dt * deriv(t1, i)\r\n\t y(i) = y(i) + k2(i)\r\n\tenddo\r\n\tReturn\r\nEnd subroutine rk2\r\n\r\n! function which returns the derivatives (RHS)\r\nreal*8 function deriv(temp, i)\r\n\tImplicit none\r\n! declarations\r\n\tReal*8 :: omega\r\n\treal*8, dimension(2), intent(inout):: temp\r\n\tInteger :: i\r\n\tdata omega /5.7143d0/\r\n\t! dx/dt=v\r\n\t! dv/dt=P/(mv)= 400/70/v=5.7143/v\r\n\tIf (i .EQ. 1) deriv=temp(2)\r\n\tIf (i .EQ. 2) deriv=omega / temp(2)\r\n\tReturn\r\nEnd function deriv\r\n", "meta": {"hexsha": "d0145d9ccf915493829f0083e5c2dbdfdfa6cca3", "size": 1378, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "HW4/P1.f90", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW4/P1.f90", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW4/P1.f90", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.2647058824, "max_line_length": 47, "alphanum_fraction": 0.5812772134, "num_tokens": 559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7560166884886687}} {"text": "module m_geometry\n !! See Shewchuk 1997 Adaptive Precision Floating-Point Arithmetic and Fast Robust Geometric Predicates\n\n use variableKind, only: i32, i64, r32, r64\n use m_unitTester, only: tester\n\n private\n\n public :: orient2D\n public :: orient3D\n public :: geometryTest\n\n\n interface\n !====================================================================!\n module function inCircle(ax, ay, bx, by, cx, cy, dx, dy) result(determinant)\n !! Determines whether the point d is inside the circumcircle of the triangle formed by a-b-c\n !! Returns a positive value if d is inside.\n !! Returns a negative value if d is outside.\n !! Returns a zero if the four points are cocircular.\n !!\n !! Uses an adaptive floating method by Shewchuk. Only exact computations\n !! are carried out when needed.\n !====================================================================!\n real(r64), intent(in) :: ax\n !! x co-ordinate of the first point\n real(r64), intent(in) :: ay\n !! y co-ordinate of the first point\n real(r64), intent(in) :: bx\n !! x co-ordinate of the second point\n real(r64), intent(in) :: by\n !! y co-ordinate of the second point\n real(r64), intent(in) :: cx\n !! x co-ordinate of the third point\n real(r64), intent(in) :: cy\n !! y co-ordinate of the third point\n real(r64), intent(in) :: dx\n !! x co-ordinate of the fourth point\n real(r64), intent(in) :: dy\n !! y co-ordinate of the fourth point\n real(r64) :: determinant\n !! [-ve, 0, +ve] for point d [outside, on, inside] the circumcircle of a -> b -> c\n end function\n end interface\n\n interface\n !====================================================================!\n module function inSphere(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez) result(determinant)\n !! Determines whether the point e is inside the circumsphere of the tetrahedron formed by a-b-c-d\n !! Returns a positive value if e is inside.\n !! Returns a negative value if e is outside.\n !! Returns a zero if the five points are cospherical.\n !! a -> b -> c -> d must be ordered in a clockwise manner as defined by orient3D\n !!\n !! Uses an adaptive floating method by Shewchuk. Only exact computations\n !! are carried out when needed.\n !====================================================================!\n real(r64), intent(in) :: ax\n !! x co-ordinate of the first point\n real(r64), intent(in) :: ay\n !! y co-ordinate of the first point\n real(r64), intent(in) :: az\n !! z co-ordinate of the first point\n real(r64), intent(in) :: bx\n !! x co-ordinate of the second point\n real(r64), intent(in) :: by\n !! y co-ordinate of the second point\n real(r64), intent(in) :: bz\n !! z co-ordinate of the second point\n real(r64), intent(in) :: cx\n !! x co-ordinate of the third point\n real(r64), intent(in) :: cy\n !! y co-ordinate of the third point\n real(r64), intent(in) :: cz\n !! z co-ordinate of the third point\n real(r64), intent(in) :: dx\n !! x co-ordinate of the fourth point\n real(r64), intent(in) :: dy\n !! y co-ordinate of the fourth point\n real(r64), intent(in) :: dz\n !! z co-ordinate of the fourth point\n real(r64), intent(in) :: ex\n !! x co-ordinate of the fifth point\n real(r64), intent(in) :: ey\n !! y co-ordinate of the fifth point\n real(r64), intent(in) :: ez\n !! z co-ordinate of the fifth point\n real(r64) :: determinant\n !! [-ve, 0, +ve] for point e [outside, on, inside] the circumsphere defined by points a -> b -> c -> d\n end function\n !====================================================================!\n end interface\n\n interface\n !====================================================================!\n module function orient2D(ax, ay, bx, by, cx, cy) result(determinant)\n !! Determines whether three points a, b, c are in clockwise order.\n !! i.e. is the point c to the left or right of line a-b?\n !! Returns a positive value if a-b-c are in an anticlockwise order.\n !! Returns a negative value if a-b-c are in clockwise order.\n !! Returns a zero if the points are colinear.\n !!\n !! Uses an adaptive floating method by Shewchuk. Only exact computations\n !! are carried out when needed.\n !====================================================================!\n real(r64), intent(in) :: ax\n !! x co-ordinate of the first point\n real(r64), intent(in) :: ay\n !! y co-ordinate of the first point\n real(r64), intent(in) :: bx\n !! x co-ordinate of the second point\n real(r64), intent(in) :: by\n !! y co-ordinate of the second point\n real(r64), intent(in) :: cx\n !! x co-ordinate of the third point\n real(r64), intent(in) :: cy\n !! y co-ordinate of the third point\n real(r64) :: determinant\n !! [-ve, 0, +ve] for [clockwise, colinear, anticlockwise] points a -> b -> c\n end function\n end interface\n \n interface\n !====================================================================!\n module function orient3D(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz) result(determinant)\n !! Determines whether the points a, b, c, d defining a polyhedron are ordered\n !! in an anticlockwise manner.\n !! Returns a positive value if a-b-c-d are in an anticlockwise order.\n !! Returns a negative value if a-b-c-d are in clockwise order.\n !! Returns zero if they are coplanar.\n !! Clockwise is defined when viewed from above the plane defined by a-b-c.\n !!\n !! Uses an adaptive floating method by Shewchuk. Only exact computations\n !! are carried out when needed.\n !====================================================================!\n real(r64), intent(in) :: ax\n !! x co-ordinate of the first point\n real(r64), intent(in) :: ay\n !! y co-ordinate of the first point\n real(r64), intent(in) :: az\n !! z co-ordinate of the first point\n real(r64), intent(in) :: bx\n !! x co-ordinate of the second point\n real(r64), intent(in) :: by\n !! y co-ordinate of the second point\n real(r64), intent(in) :: bz\n !! z co-ordinate of the second point\n real(r64), intent(in) :: cx\n !! x co-ordinate of the third point\n real(r64), intent(in) :: cy\n !! y co-ordinate of the third point\n real(r64), intent(in) :: cz\n !! z co-ordinate of the third point\n real(r64), intent(in) :: dx\n !! x co-ordinate of the fourth point\n real(r64), intent(in) :: dy\n !! y co-ordinate of the fourth point\n real(r64), intent(in) :: dz\n !! z co-ordinate of the fourth point\n real(r64) :: determinant\n !! [-ve, 0, +ve] for point d [right, on, left] of the plane defined by points a -> b -> c\n end function\n end interface\n\n interface\n !====================================================================!\n module subroutine geometryTest(test)\n !====================================================================!\n class(tester) :: test\n end subroutine\n end interface\n !====================================================================!\n\n\nend module", "meta": {"hexsha": "41780f8fdade93d30cd8380b4c32d949e778e8d9", "size": 7233, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/spatial/m_geometry.f90", "max_stars_repo_name": "leonfoks/coretran", "max_stars_repo_head_hexsha": "bf998d4353badc91d3a12d23c78781c8377b9578", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 72, "max_stars_repo_stars_event_min_datetime": "2017-10-20T15:19:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T11:17:43.000Z", "max_issues_repo_path": "src/spatial/m_geometry.f90", "max_issues_repo_name": "leonfoks/coretran", "max_issues_repo_head_hexsha": "bf998d4353badc91d3a12d23c78781c8377b9578", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2017-10-20T15:54:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T09:45:01.000Z", "max_forks_repo_path": "src/spatial/m_geometry.f90", "max_forks_repo_name": "leonfoks/coretran", "max_forks_repo_head_hexsha": "bf998d4353badc91d3a12d23c78781c8377b9578", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-02-20T15:07:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-10T17:58:00.000Z", "avg_line_length": 41.3314285714, "max_line_length": 108, "alphanum_fraction": 0.5472141573, "num_tokens": 1827, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167045, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7560166794159174}} {"text": "module pend_len\n! Allows the declaration of global variables whose values can be assigned in other places.\ndouble precision :: l\nend module\n\nmodule dpend\ndouble precision :: l1, l2, m1, m2, ms\nend module\n\nmodule gonewiththewind\ndouble precision :: as, ar, k\nend module\n\nmodule per_harv\ndouble precision :: a, h, r\nend module\n\nprogram main\nuse pend_len\nuse dpend\nuse gonewiththewind\nuse per_harv\nimplicit none\n! call simple_pendulum\n call double_pendulum\n call double_pendulum_adapt\n! call gone_with_the_wind\n! call periodic_harvesting\n! call periodic_harvesting2\n! call periodic_harvesting_adapt\nend program main\n\nsubroutine periodic_harvesting\n! Excercise 7.2.19 of non-linear dynamics and chaos Strogatz\nuse per_harv\nimplicit none\ninteger, parameter :: n = 1\ndouble precision ti, tf, dt, tmax\ndouble precision xi(n), xf(n)\ninteger i\nexternal pharv\n\nopen(unit=1, file='pharv.dat')\n! initial data\nti = 0.0\ntmax = 100.0\ndt = 0.01\na = 0.5\nr = 1.0\nh = 0.2 ! criticals are roughly h s1) then\n exit\n end if\n write(unit=10, fmt=*) s, cond_theta(s)\n j = j + 1\n end do\n \n close(unit=10)\n \n end subroutine write_conductivity\n \n subroutine write_diffusivity (s0, s1, ds, filename)\n \n real(kind=r8), intent(in) :: s0, s1, ds\n character(len=*), intent(in) :: filename\n \n integer :: j\n real(kind=r8) :: s\n \n open(unit=10, file=filename, action=\"write\", position=\"rewind\", status=\"replace\")\n \n j = 0\n \n do\n s = s0 + j * ds\n if (s > s1) then\n exit\n end if\n write(unit=10, fmt=*) s, diffusivity(s)\n j = j + 1\n end do\n \n close(unit=10)\n \n end subroutine write_diffusivity\n \n subroutine write_saturation (p0, p1, dp, filename)\n \n real(kind=r8), intent(in) :: p0, p1, dp\n character(len=*), intent(in) :: filename\n \n integer :: j\n real(kind=r8) :: p\n \n open(unit=10, file=filename, action=\"write\", position=\"rewind\", status=\"replace\")\n \n j = 0\n \n do\n p = p0 + j * dp\n if (p > p1) then\n exit\n end if\n write(unit=10, fmt=*) p, saturation(p)\n j = j + 1\n end do\n \n close(unit=10)\n \n end subroutine write_saturation\n \nend module write_functions\n\nprogram plot_em\n\n use kind_parameters\n use richards_functions\n use write_functions\n \n real(kind=r8), parameter :: s0 = 0.076_r8, s1 = 0.286_r8, ds = 0.001_r8\n \n call write_diffusivity (s0=0.1_r8, s1=0.27_r8, ds=0.001_r8, filename=\"diff\")\n call write_conductivity (s0=0.1_r8, s1=0.27_r8, ds=0.001_r8, filename=\"cond\")\n !call write_saturation (p0=-61.5_r8, p1=-20.7_r8, dp=0.1_r8, filename=\"sat\")\n \nend program plot_em\n", "meta": {"hexsha": "70a0099e247cd22b9afd17895c614d6ae670a552", "size": 4772, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "richards/fun.f90", "max_stars_repo_name": "mfeproject/mfe1", "max_stars_repo_head_hexsha": "e07b27a5287ced55b19eb2e804a9b7a80e1a8791", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "richards/fun.f90", "max_issues_repo_name": "mfeproject/mfe1", "max_issues_repo_head_hexsha": "e07b27a5287ced55b19eb2e804a9b7a80e1a8791", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "richards/fun.f90", "max_forks_repo_name": "mfeproject/mfe1", "max_forks_repo_head_hexsha": "e07b27a5287ced55b19eb2e804a9b7a80e1a8791", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.9347826087, "max_line_length": 90, "alphanum_fraction": 0.545473596, "num_tokens": 1463, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465188527685, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7558228573573033}} {"text": "program main\n use plantFEM\n implicit none\n\n type(Random_) ::random\n type(IO_) :: f\n integer(int32) :: i\n real(real64),allocatable :: histogram(:,:)\n real(real64) :: list(10000)\n\n do i=1,10000\n list(i) = random%gauss(mu=10.0d0,sigma=2.0d0)\n enddo\n \n histogram = random%histogram(list=list,division=20)\n\n call f%open(\"gauss.txt\")\n\n do i=1,size(histogram,1)\n write(f%fh,*) histogram(i,1),histogram(i,2)\n enddo\n call f%close()\n \n\n do i=1,10000\n list(i) = random%ChiSquared(K=10.0d0)\n enddo\n \n histogram = random%histogram(list=list,division=20)\n\n call f%open(\"ChiSquared.txt\")\n \n do i=1,size(histogram,1)\n write(f%fh,*) histogram(i,1),histogram(i,2)\n enddo\n\n call f%close()\n\n do i=1,10000\n list(i) = random%Chauchy(mu=10.0d0,gamma=2.0d0)\n enddo\n \n histogram = random%histogram(list=list,division=20)\n\n call f%open(\"Chauchy.txt\")\n \n do i=1,size(histogram,1)\n write(f%fh,*) histogram(i,1),histogram(i,2)\n enddo\n call f%close()\n\n\n do i=1,10000\n list(i) = random%Lognormal(mu=10.0d0,sigma=2.0d0)\n enddo\n \n histogram = random%histogram(list=list,division=20)\n\n call f%open(\"Lognormal.txt\")\n \n do i=1,size(histogram,1)\n write(f%fh,*) histogram(i,1),histogram(i,2)\n enddo\n call f%close()\n\n\n\n do i=1,10000\n list(i) = random%InverseGauss(mu=10.0d0,lambda=2.0d0)\n enddo\n \n histogram = random%histogram(list=list,division=20)\n\n call f%open(\"InverseGauss.txt\")\n \n do i=1,size(histogram,1)\n write(f%fh,*) histogram(i,1),histogram(i,2)\n enddo\n \n call f%close()\n\nend program", "meta": {"hexsha": "b79bbd4c40d7a66707e6d5044491f586f6a29412", "size": 1689, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/playon_std/ex0018_random.f90", "max_stars_repo_name": "kazulagi/plantfem_min", "max_stars_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2020-06-21T08:21:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:28:30.000Z", "max_issues_repo_path": "Tutorial/std/ex0018_random.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-08T05:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:39:29.000Z", "max_forks_repo_path": "Tutorial/std/ex0018_random.f90", "max_forks_repo_name": "kazulagi/plantFEM_binary", "max_forks_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-10-20T18:28:59.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-15T08:35:25.000Z", "avg_line_length": 20.5975609756, "max_line_length": 61, "alphanum_fraction": 0.5908821788, "num_tokens": 571, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346504434783, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7558228413832628}} {"text": "!##############################################################################\n! PROGRAM piecewise_pol\n!\n! ## Piecewise polynomial interpolation (linear and cubic splines)\n!\n! This code is published under the GNU General Public License v3\n! (https://www.gnu.org/licenses/gpl-3.0.en.html)\n!\n! Authors: Hans Fehr and Fabian Kindermann\n! contact@ce-fortran.com\n!\n! #VC# VERSION: 1.0 (23 January 2018)\n!\n!##############################################################################\nprogram piecewise_pol\n\n use toolbox\n\n implicit none\n integer, parameter :: n = 10, nplot = 1000\n real*8 :: xi(0:n), yi(0:n)\n real*8 :: xplot(0:nplot), yplot(0:nplot), yreal(0:nplot)\n real*8 :: varphi, coeff(n+3)\n integer :: ix, il, ir\n\n ! get nodes and data for interpolation\n call grid_Cons_Equi(xi, -1d0, 1d0)\n yi = 1d0/(1d0+25*xi**2)\n\n ! get nodes and data for plotting\n call grid_Cons_Equi(xplot, -1d0, 1d0)\n yreal = 1d0/(1d0+25*xplot**2)\n call plot(xplot, yreal, legend='Original')\n\n ! piecewise linear interpolation\n do ix = 0, nplot\n call linint_Equi(xplot(ix), -1d0, 1d0, n, il, ir, varphi)\n yplot(ix) = varphi*yi(il) + (1d0-varphi)*yi(ir)\n enddo\n call plot(xplot, yplot, legend='Piecewise linear')\n\n ! cubic spline interpolation\n call spline_interp(yi, coeff)\n do ix = 0, nplot\n yplot(ix) = spline_eval(xplot(ix), coeff, -1d0, 1d0)\n enddo\n call plot(xplot, yplot, legend='Cubic spline')\n\n ! execute plot\n call execplot(xlim=(/-1d0,1d0/))\n\nend program\n", "meta": {"hexsha": "bd1a88946e304309fbadfd58fffec3639ba61d3e", "size": 1571, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog02/prog02_18/prog02_18.f90", "max_stars_repo_name": "aswinvk28/modflow_fortran", "max_stars_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "complete/prog02/prog02_18/prog02_18.f90", "max_issues_repo_name": "aswinvk28/modflow_fortran", "max_issues_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "complete/prog02/prog02_18/prog02_18.f90", "max_forks_repo_name": "aswinvk28/modflow_fortran", "max_forks_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-07T12:27:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-07T12:27:47.000Z", "avg_line_length": 29.641509434, "max_line_length": 79, "alphanum_fraction": 0.5671546785, "num_tokens": 482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.7558206190544234}} {"text": "C Copyright 2021 Dennis Decker Jensen\nC Date: 26 April 2021\nC Purpose: Find prime factors in integers\nC Tectonics: gfortran --std=f95 -ffixed-form -o euler047 euler047.f primefactors.f\n\n PROGRAM EULER047\n PARAMETER (MX=10,MXDGS=4)\n DIMENSION IFACS(2,MX)\n DIMENSION IRES(MX,MXDGS,2),NUMS(MXDGS),NFACS(MXDGS)\n\nC CALL PRIMEFACTORS_TRIALDIV(441, IFACS, MX, N)\nC PRINT 50,441,N,(IFACS(1:2,J),J=1,N)\n\nC CALL PRIMEFACTORS_TRIALDIV(9974, IFACS, MX, N)\nC PRINT 50,9974,N,(IFACS(1:2,J),J=1,N)\nC CALL PRIMEFACTORS_TRIALDIV(9975, IFACS, MX, N)\nC PRINT 50,9975,N,(IFACS(1:2,J),J=1,N)\nC CALL PRIMEFACTORS_TRIALDIV(9976, IFACS, MX, N)\nC PRINT 50,9976,N,(IFACS(1:2,J),J=1,N)\nC STOP\n\n M=0\n K=0\n DO 20 I=1,2**32-1\nC CALL PRIMEFACTORS_TRIALDIV(I,IFACS,MX,N)\n CALL PRIMEFACTORS_WHEEL(I,IFACS,MX,N)\nC PRINT 50,I,N,(IFACS(1:2,J),J=1,N)\nC IF (N.EQ.MXDGS) PRINT 50,I,N,(IFACS(1:2,J),J=1,N)\n\n ISP=1\n DO 05 J=1,N\n ISP=ISP*IFACS(1,J)**IFACS(2,J)\n 05 CONTINUE\n IF (ISP.NE.I) THEN\n PRINT *, 'WRONG!',I,'.NE.',ISP\n STOP\n ENDIF\n\n IF (N.EQ.MXDGS .AND. I.EQ.K+1) THEN\n M=M+1\n NUMS(M)=I\n NFACS(M)=N\n DO 10 L=1,N\n IRES(L,M,1)=IFACS(1,L)\n IRES(L,M,2)=IFACS(2,L)\n 10 CONTINUE\n IF (M.EQ.MXDGS) GOTO 30\n ELSE\n M=0\n ENDIF\n K=I\n 20 CONTINUE\n 30 DO 40 I=1,M\n PRINT 50, NUMS(I), NFACS(I),\n 1 (IRES(J,I,1:2),J=1,NFACS(I))\n 40 CONTINUE\n 50 FORMAT (I0,' HAS ',I0,' FACTORS: ',4(I0,'**',I0,' '))\n END\n", "meta": {"hexsha": "baac028e870fea54251ea964df477342d11c334f", "size": 1845, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "euler/euler047.f", "max_stars_repo_name": "dennisdjensen/Sketchbook", "max_stars_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-04-26T19:30:58.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-12T16:34:23.000Z", "max_issues_repo_path": "euler/euler047.f", "max_issues_repo_name": "dennisdjensen/sketchbook", "max_issues_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_issues_repo_licenses": ["0BSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "euler/euler047.f", "max_forks_repo_name": "dennisdjensen/sketchbook", "max_forks_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.2711864407, "max_line_length": 82, "alphanum_fraction": 0.4905149051, "num_tokens": 677, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240073565738, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.7557828932045866}} {"text": "! **********************************************************************************\n! * ROUTINES FOR COMPUTING THE SPHERICAL BESSEL AND HANKEL FUNCTIONS, *\n! * THE CYLINDRICAL BESSEL FUNCTIONS AND THE ASSOCIATED LEGENDRE FUNCTIONS *\n! * ------------------------------------------------------------------------- *\n! * Partial list of subroutines: *\n! * besel_j, besel_h, besel_h_complete, *\n! * J01, bes_J, Pmm, *\n! * pimm, Leg, P_mm_real, *\n! * pi_mm_real, tau_mm_real, Leg_normalized, *\n! * P_mm, pi_mm, tau_mm, *\n! * Leg_normalized_complex * \n! * Partial list of alternative subroutines: * \n! * besel_jA, besel_hA, besel_h_completeA, *\n! * besel_jB, besel_jC, bes_JA, *\n! * MSTA1, MSTA2, ENVJ *\n! **********************************************************************************\nsubroutine besel_j (z, N, j, jd)\n!-----------------------------------------------------------------------------------\n! The routine computes the spherical Bessel functions j(z) and the derivatives !\n! jd(z) = d(z*j(z))/dz. The order of the Bessel functions varies between 0 and N, !\n! and the backward recurrence relation !\n! j(n-1,z) + j(n+1,z) = [(2n+1) / z] * j(n,z). !\n! is used for computation. Here j(n,z) denotes the Bessel function of order n and !\n! argument z. The following parameters control the computation: ! \n! - ZeroSinXX (real) - for |z| < ZeroSinXX, we set j(0,z) = sin(z)/z = 1 and !\n! j(n,z) = 0, for n = 1,2,...,N. !\n! - FactNBes (real) - determines the order of the Bessel functions Nstart, !\n! at which the backward recurrence is started, i.e., Nstart = FactNBes * N. !\n! Default value: FactNBes = 400._O. !\n! - InitBesVal (real) - initial value of the Bessel function at the beginning of !\n! the backward recurrence. Default value: InitBesVal = 1.e-35_O. !\n! - MaxArgBes (real) - for |z| > MaxArgBes, the asymptotic expressions of !\n! spherical Bessel functions for large arguments are used. !\n! - UpperBoundSeq (real) - upper bound of the sequence of Bessel functions !\n! (if a Bessel function value exceeds this bound the entire sequence is scaled). !\n! Default value: UpperBoundSeq = 1.e+10_O. !\n! - LowerBoundSeq (real) - lower bound of the sequence of Bessel functions. !\n! Default value: LowerBoundSeq = 1.e-10_O. !\n! These parameters are specified in the routine \"DrvParameters\" from the file !\n! '../TMATROUTINES/MachParam.f90'. !\n! !\n! Input parameters: ! \n! - z (complex) - argument of the spherical Bessel functions. !\n! - N (integer) - maximum order of the spherical Bessel functions. !\n! !\n! Output parameters: !\n! - j (complex array) - spherical Bessel functions. !\n! - jd (complex array) - derivatives of the spherical Bessel functions. !\n!-----------------------------------------------------------------------------------\n use parameters\n use derived_parameters\n implicit none\n integer :: N\n complex(O) :: z, j(0:N), jd(0:N)\n!\n complex(O) :: j0, j1, f2, f1, f, kc, scale, argc\n real(O) :: a0, arg\n integer :: M, Ma, Mn, k, l\n! \n a0 = abs(z)\n do k = 0, N \n j(k) = zero\n jd(k) = zero\n end do\n if (a0 < ZeroSinXX) then\n j(0) = one\n else if (a0 >= ZeroSinXX .and. a0 < MaxArgBes) then\n j(0) = sin(z) / z\n j(1) = j(0) / z - cos(z) / z\n if (N >= 2) then\n j0 = j(0)\n j1 = j(1)\n Ma = nint(a0 + 4._O * a0**0.33_O + 2._O + sqrt(101._O + a0)) + 20 \n Mn = N + nint(sqrt(FactNBes * N))\n M = max(Ma,Mn) \n f2 = zero\n f1 = cmplx(InitBesVal,0.0,O)\n do k = M, 0, -1\n kc = cmplx(2 * k + 3,0.0,O)\n f = kc * f1 / z - f2 \n if (k <= N) j(k) = f\n f2 = f1\n f1 = f\n if (abs(f1) > UpperBoundSeq) then\n f2 = f2 * LowerBoundSeq\n f1 = f1 * LowerBoundSeq\n do l = k, N\n j(l) = j(l) * LowerBoundSeq\n end do\n else if (abs(f1) < LowerBoundSeq) then\n f2 = f2 * UpperBoundSeq\n f1 = f1 * UpperBoundSeq\n do l = k, N\n j(l) = j(l) * UpperBoundSeq\n end do\n end if\n end do \n if (abs(f1) > abs(f2)) then\n scale = j0 / f1\n else\n scale = j1 / f2\n end if \n do k = 0, N\n j(k) = scale * j(k)\n end do\n end if \n do k = 1, N\n kc = cmplx(k,0.0,O)\n jd(k) = z * j(k-1) - kc * j(k)\n end do\n else\n do k = 0, N\n arg = 0.5_O * real(k + 1,O) * pi\n argc = cmplx(arg,0.0,O) \n j(k) = cos (z - argc) / z\n end do \n do k = 1, N\n kc = cmplx(k,0.0,O)\n jd(k) = z * j(k-1) - kc * j(k)\n end do\n end if \nend subroutine besel_j\n!**********************************************************************************\nsubroutine besel_h (z, N, h, hd)\n!-----------------------------------------------------------------------------------\n! The routine computes the spherical Hankel functions of the first kind !\n! h(z) = j(z) + i*y(z) and the derivatives hd(z) = d(z*h(z))/dz, where j(z) and !\n! y(z) are the spherical Bessel and Neumann functions, respectively. The order of !\n! the functions varies between 0 and N, and the control parameters ZeroSinXX, !\n! FactNBes, InitBesVal, UpperBoundSeq and LowerBoundSeq are specified in the !\n! routine \"DrvParameters\" from the file '../TMATROUTINES/MachParam.f90'. !\n! !\n! Input parameters: ! \n! - z (complex) - argument of the spherical Hankel functions. !\n! - N (integer) - maximum order of the spherical Hankel functions. !\n! !\n! Output parameters: !\n! - h (complex array) - spherical Hankel functions. !\n! - hd (complex array) - derivatives of the spherical Hankel functions. !\n!-----------------------------------------------------------------------------------\n use parameters\n use derived_parameters\n implicit none\n integer :: N\n complex(O) :: z, h(0:N), hd(0:N)\n!\n integer :: Ma, Mn, M, k, l\n real(O) :: a0, arg\n complex(O) :: j0, j1, f, f1, f2, kc, z2, z3, scale, argc\n complex(O),allocatable :: j(:), y(:)\n! \n z2 = z * z\n z3 = z2 * z\n a0 = abs(z)\n allocate (j(0:N), y(0:N))\n do k = 0, N \n j(k) = zero\n y(k) = zero\n h(k) = zero\n hd(k) = zero\n end do\n if (a0 < ZeroSinXX) then\n j(0) = one\n else if (a0 >= ZeroSinXX .and. a0 < MaxArgBes) then\n j(0) = sin(z) / z\n j(1) = j(0) / z - cos(z) / z\n if (N >= 2) then\n j0 = j(0)\n j1 = j(1)\n Ma = nint(a0 + 4._O * a0**0.33_O + 2._O + sqrt(101._O + a0)) + 20 \n Mn = N + nint(sqrt(FactNBes * N))\n M = max(Ma,Mn) \n f2 = zero\n f1 = cmplx(InitBesVal,0.0,O)\n do k = M, 0, -1\n kc = cmplx(2 * k + 3,0.0,O)\n f = kc * f1 / z - f2 \n if (k <= N) j(k) = f\n f2 = f1\n f1 = f\n if (abs(f1) > UpperBoundSeq) then\n f2 = f2 * LowerBoundSeq\n f1 = f1 * LowerBoundSeq\n do l = k, N\n j(l) = j(l) * LowerBoundSeq\n end do\n else if (abs(f1) < LowerBoundSeq) then\n f2 = f2 * UpperBoundSeq\n f1 = f1 * UpperBoundSeq\n do l = k, N\n j(l) = j(l) * UpperBoundSeq\n end do\n end if\n end do \n if (abs(f1) > abs(f2)) then\n scale = j0 / f1\n else\n scale = j1 / f2\n end if \n do k = 0, N\n j(k) = scale * j(k)\n end do \n end if \n y(0) = - cos(z) / z\n y(1) = (y(0) - sin(z)) / z\n if (N >= 2) then \n do k = 2, N\n if (abs(j(k-1)) > abs(j(k-2))) then \n y(k) = (j(k) * y(k-1) - one / z2) / j(k-1)\n else \n kc = cmplx(2 * k - 1,0.0,O)\n y(k) = (j(k) * y(k-2) - kc / z3) / j(k-2)\n end if \n end do \n end if \n do k = 0, N\n h(k) = j(k) + im * y(k)\n end do\n do k = 1, N\n kc = cmplx(k,0.0,O)\n hd(k) = z * h(k-1) - kc * h(k)\n end do\n else\n do k = 0, N \n arg = 0.5_O * real(k + 1,O) * pi\n argc = cmplx(arg,0.0,O) \n h(k) = exp(im * (z - argc)) / z \n end do \n do k = 1, N\n kc = cmplx(k,0.0,O)\n hd(k) = z * h(k-1) - kc * h(k)\n end do\n end if\n deallocate (j, y)\nend subroutine besel_h\n!**********************************************************************************\nsubroutine besel_h_complete (z, N, j, y, h, hd)\n!-----------------------------------------------------------------------------------\n! The routine computes the spherical Bessel and Neumann functions j(z) and y(z), !\n! the spherical Hankel functions of the first kind h(z) = j(z) + i*y(z) and the !\n! derivatives hd(z) = d(z*h(z))/dz. The order of the functions varies between 0 !\n! and N, and the control parameters ZeroSinXX, FactNBes, InitBesVal, UpperBoundSeq !\n! and LowerBoundSeq are specified in the routine \"DrvParameters\" from the file !\n! '../TMATROUTINES/MachParam.f90'. !\n! !\n! Input parameters: ! \n! - z (complex) - argument of the spherical Bessel, Neumann and Hankel functions. !\n! - N (integer) - maximum order of the spherical functions. !\n! !\n! Output parameters: !\n! - j (complex array) - spherical Bessel functions. !\n! - y (complex array) - spherical Neumann functions. !\n! - h (complex array) - spherical Hankel functions. !\n! - hd (complex array) - derivatives of the spherical Hankel functions. !\n!-----------------------------------------------------------------------------------\n use parameters\n use derived_parameters\n implicit none\n integer :: N\n complex(O) :: z, j(0:N), y(0:N), h(0:N), hd(0:N)\n!\n integer :: Ma, Mn, M, k, l\n real(O) :: a0, arg\n complex(O) :: j0, j1, f, f1, f2, kc, z2, z3, scale, argc\n! \n z2 = z * z\n z3 = z2 * z\n a0 = abs(z)\n do k = 0, N \n j(k) = zero\n y(k) = zero\n h(k) = zero\n hd(k) = zero\n end do\n if (a0 < ZeroSinXX) then\n j(0) = one\n else if (a0 >= ZeroSinXX .and. a0 < MaxArgBes) then \n j(0) = sin(z) / z\n j(1) = j(0) / z - cos(z) / z\n if (N >= 2) then\n j0 = j(0)\n j1 = j(1)\n Ma = nint(a0 + 4._O * a0**0.33_O + 2._O + sqrt(101._O + a0)) + 20 \n Mn = N + nint(sqrt(FactNBes * N))\n M = max(Ma,Mn) \n f2 = zero\n f1 = cmplx(InitBesVal,0.0,O)\n do k = M, 0, -1\n kc = cmplx(2 * k + 3,0.0,O)\n f = kc * f1 / z - f2 \n if (k <= N) j(k) = f\n f2 = f1\n f1 = f\n if (abs(f1) > UpperBoundSeq) then\n f2 = f2 * LowerBoundSeq\n f1 = f1 * LowerBoundSeq\n do l = k, N\n j(l) = j(l) * LowerBoundSeq\n end do\n else if (abs(f1) < LowerBoundSeq) then\n f2 = f2 * UpperBoundSeq\n f1 = f1 * UpperBoundSeq\n do l = k, N\n j(l) = j(l) * UpperBoundSeq\n end do\n end if\n end do \n if (abs(f1) > abs(f2)) then\n scale = j0 / f1\n else\n scale = j1 / f2\n end if \n do k = 0, N\n j(k) = scale * j(k)\n end do \n end if \n y(0) = - cos(z) / z\n y(1) = (y(0) - sin(z)) / z\n if (N >= 2) then \n do k = 2, N\n if (abs(j(k-1)) > abs(j(k-2))) then \n y(k) = (j(k) * y(k-1) - one / z2) / j(k-1)\n else \n kc = cmplx(2 * k - 1,0.0,O)\n y(k) = (j(k) * y(k-2) - kc / z3) / j(k-2)\n end if \n end do \n end if \n do k = 0, N\n h(k) = j(k) + im * y(k)\n end do\n do k = 1, N\n kc = cmplx(k,0.0,O)\n hd(k) = z * h(k-1) - kc * h(k)\n end do\n else \n do k = 0, N \n arg = 0.5_O * real(k + 1,O) * pi\n argc = cmplx(arg,0.0,O) \n j(k) = cos (z - argc) / z\n y(k) = sin (z - argc) / z\n h(k) = j(k) + im * y(k) \n end do \n do k = 1, N\n kc = cmplx(k,0.0,O)\n hd(k) = z * h(k-1) - kc * h(k)\n end do\n end if\nend subroutine besel_h_complete\n!***********************************************************************************\nsubroutine J01 (z, J0, J1)\n use parameters\n use derived_parameters\n implicit none\n complex(O) :: z, J0, J1\n!\n complex(O) :: z2, z1, r, t1, p0, q0, u, t2, p1, q1, kc\n real(O) :: a0, rp2, A(12), B(12), A1(12), B1(12)\n integer :: k, k0 \n!\n rp2 = 2._O / pi\n a0 = abs(z)\n z2 = z * z\n z1 = z\n if (a0 == 0._O) then\n J0 = one\n J1 = zero \n else \n if (real(z) < 0._O) z1 = - z\n if (a0 <= 12._O) then\n J0 = one\n r = one\n do k = 1, 40\n kc = cmplx(k * k,0.0,O) \n r = - 0.25_O * r * z2 / kc\n J0 = J0 + r\n if (abs(r) < MachEps * abs(J0)) exit\n end do \n J1 = one\n r = one\n do k = 1, 40\n kc = cmplx(k * (k + 1),0.0,O)\n r = - 0.25_O * r * z2 / kc\n J1 = J1 + r\n if (abs(r) < MachEps * abs(J1)) exit\n end do \n J1 = 0.5_O * z1 * J1 \n else \n A = (/-.703125e-01_O , .1121520996093750e+00_O, & \n -.5725014209747314e+00_O, .6074042001273483e+01_O, &\n -.1100171402692467e+03_O, .3038090510922384e+04_O, &\n -.1188384262567832e+06_O, .6252951493434797e+07_O, &\n -.4259392165047669e+09_O, .3646840080706556e+11_O, &\n -.3833534661393944e+13_O, .4854014686852901e+15_O/)\n B = (/ .732421875e-01_O ,-.2271080017089844e+00_O, &\n .1727727502584457e+01_O,-.2438052969955606e+02_O, &\n .5513358961220206e+03_O,-.1825775547429318e+05_O, &\n .8328593040162893e+06_O,-.5006958953198893e+08_O, &\n .3836255180230433e+10_O,-.3649010818849833e+12_O, &\n .4218971570284096e+14_O,-.5827244631566907e+16_O/)\n A1 = (/ .1171875e+00_O ,-.1441955566406250e+00_O, &\n .6765925884246826e+00_O,-.6883914268109947e+01_O, &\n .1215978918765359e+03_O,-.3302272294480852e+04_O, &\n .1276412726461746e+06_O,-.6656367718817688e+07_O, &\n .4502786003050393e+09_O,-.3833857520742790e+11_O, &\n .4011838599133198e+13_O,-.5060568503314727e+15_O/)\n B1 = (/-.1025390625e+00_O , .2775764465332031e+00_O, &\n -.1993531733751297e+01_O, .2724882731126854e+02_O, &\n -.6038440767050702e+03_O, .1971837591223663e+05_O, &\n -.8902978767070678e+06_O, .5310411010968522e+08_O, &\n -.4043620325107754e+10_O, .3827011346598605e+12_O, &\n -.4406481417852278e+14_o, .6065091351222699e+16_O/)\n k0 = 12\n if (a0 >= 35._O) k0 = 10\n if (a0 >= 50._O) k0 = 8\n t1 = z1 - 0.25_O * pi\n p0 = one\n do k = 1, k0\n p0 = p0 + A(k) * z1**(- 2 * k)\n end do\n q0 = - 0.125_O / z1\n do k = 1, k0\n q0 = q0 + B(k) * z1**(- 2 * k - 1)\n end do\n u = sqrt(rp2 / z1)\n J0 = u * (p0 * cos(t1) - q0 * sin(t1)) \n t2 = z1 - 0.75_O * pi\n p1 = one\n do k = 1, k0\n p1 = p1 + A1(k) * z1**(- 2 * k)\n end do\n q1 = 0.375_O / z1\n do k = 1, k0\n q1 = q1 + B1(k) * z1**(- 2 * k - 1)\n end do\n J1 = u * (p1 * cos(t2) - q1 * sin(t2)) \n end if \n if (real(z) < 0._O) then\n J1 = - J1\n end if\n end if \nend subroutine J01\n!***********************************************************************************\nsubroutine bes_J (z, N, J)\n!-----------------------------------------------------------------------------------\n! The routine computes the cylindrical Bessel function J(z). The order of the !\n! Bessel function varies between 0 and N, and the control parameters ZeroSinXX, !\n! FactNBes, InitBesVal, UpperBoundSeq and LowerBoundSeq are specified in the !\n! routine \"DrvParameters\" from the file '../TMATROUTINES/MachParam.f90'. !\n! !\n! Input parameters: ! \n! - z (complex) - argument of the cylindrical Bessel functions. !\n! - N (integer) - maximum order of cylindrical Bessel functions. !\n! !\n! Output parameters: !\n! - J (complex array) - cylindrical Bessel functions. ! \n!-----------------------------------------------------------------------------------\n use parameters\n use derived_parameters\n implicit none\n integer :: N\n complex(O) :: z, J(0:N)\n!\n complex(O) :: J0, J1, S, S0, f2, f1, f, kc\n real(O) :: y0, a0\n integer :: k, M, Ma, Mn, l\n! \n y0 = abs(aimag(z))\n a0 = abs(z)\n do k = 0, N\n J(k) = zero\n end do\n if (a0 < ZeroSinXX) then \n J(0) = one\n else \n call J01 (z, J0, J1) \n J(0) = J0 \n J(1) = J1\n if (N > 1) then \n if (a0 <= 300._O .or. N > int(0.25_O * a0)) then\n Ma = nint(a0 + 4._O * a0**0.33_O + 2._O + sqrt(101._O + a0)) + 10 \n Mn = N + nint(sqrt(FactNBes * N))\n M = max(Ma,Mn) \n S = zero \n f2 = zero\n f1 = cmplx(InitBesVal,0.0,O) \n do k = M, 0, -1\n kc = cmplx(k + 1,0.0,O)\n f = 2._O * kc / z * f1 - f2\n if (k <= N) J(k) = f\n if (k == 2 * int(k / 2) .and. k /= 0) then\n if (y0 <= 1._O) then\n S = S + 2._O * f\n else \n S = S + (- 1._O)**(k / 2) * 2._O * f\n end if \n end if \n f2 = f1\n f1 = f\n if (abs(f1) > UpperBoundSeq) then\n f2 = f2 * LowerBoundSeq\n f1 = f1 * LowerBoundSeq\n S = S * LowerBoundSeq\n do l = k, N\n J(l) = J(l) * LowerBoundSeq\n end do\n else if (abs(f1) < LowerBoundSeq) then\n f2 = f2 * UpperBoundSeq\n f1 = f1 * UpperBoundSeq\n S = S * UpperBoundSeq\n do l = k, N\n J(l) = J(l) * UpperBoundSeq\n end do\n end if\n end do \n if (y0 <= 1._O) then\n S0 = S + f1\n else \n S0 = (S + f1) / cos(z)\n end if \n do k = 0, N\n J(k) = J(k) / S0\n end do \n else \n do k = 2, N\n kc = cmplx(k - 1,0.0,O)\n J(k) = 2._O * kc / z * J(k-1) - J(k-2) \n end do\n end if \n end if\n endif \nend subroutine bes_J\n!***********************************************************************************\nsubroutine Pmm (theta, m, Pm)\n!-----------------------------------------------------------------------------------\n! The routine computes the Legendre function Pmm(theta) for m > 0. !\n!-----------------------------------------------------------------------------------\n use parameters\n implicit none \n integer :: k, m\n real(O) :: theta, Pm, tamp, f, sth\n!\n sth = sin(theta)\n tamp = 1._O\n do k = 1, m\n f = real(2 * k - 1,O)\n tamp = f * sth * tamp \n end do\n Pm = tamp \nend subroutine Pmm\n!***********************************************************************************\nsubroutine pimm (theta, m, pim)\n!-----------------------------------------------------------------------------------\n! The routine computes the auxiliary function pimm, !\n! pimm(theta) = Pmm[cos(theta)] / sin(theta) !\n! for m > 1. !\n!-----------------------------------------------------------------------------------\n use parameters\n implicit none\n integer :: k, m\n real(O) :: theta, pim, tamp, f, sth \n!\n sth = sin(theta)\n tamp = 1._O\n do k = 1, m - 1\n f = real(2 * k - 1,O)\n tamp = f * sth * tamp \n end do\n f = real(2 * m - 1,O)\n pim = f * tamp\nend subroutine pimm\n!***********************************************************************************\nsubroutine Leg (theta, m, Nmax, Pnm, dPnm, pinm, taunm)\n!-----------------------------------------------------------------------------------\n! The routine computes the associated Legendre functions Pnm[cos(theta)], the !\n! derivatives dPn0[cos(theta)] = dPn0[cos(theta)]/d[cos(theta)], and the auxiliary !\n! functions pinm(theta) = Pnm[cos(theta)]/sin(theta), and taunm(theta) = !\n! dPnm[cos(theta)]/d(theta) of degree m. The order of the associated Legendre !\n! functions varies between 0 and Nmax, and note that for m > 0, the first m values !\n! of Pnm, pinm and taunm (corresponding to the orders 0, 1, ..., m - 1) are zero. !\n! The derivatives dPn0 are computed for the azimuthal mode m = 0 (for m >0, the !\n! Nmax values of dPn0 are zero). ! \n! !\n! Input parameteres: !\n! - theta (real) - polar angle (argument of the associated Legendre functions). !\n! - m (integer) - degree of the associated Legendre functions. !\n! - Nmax (integer) - maximum order of the associated Legendre functions. !\n! ! \n! Output parameters: !\n! - Pnm (real array) - associated Legendre functions. ! \n! - dPnm (real array) - derivatives of the associated Legendre functions !\n! for m = 0. !\n! - pinm and taunm (real arrays) - auxiliary functions. ! \n!----------------------------------------------------------------------------------- \n use parameters\n implicit none\n real(O) :: theta\n integer :: m, Nmax\n real(O) :: Pnm(0:Nmax), dPnm(0:Nmax), pinm(0:Nmax), taunm(0:Nmax)\n!\n real(O) :: Pm, pim, f1, f2, cth, sth\n integer :: n\n!\n cth = cos(theta)\n sth = sin(theta)\n if (m == 0) then\n Pnm(0) = 1._O\n Pnm(1) = cth\n do n = 1, Nmax - 1\n f1 = real(2 * n + 1,O) / real(n + 1,O)\n f2 = real(n,O) / real(n + 1,O)\n Pnm(n+1) = f1 * cth * Pnm(n) - f2 * Pnm(n-1)\n end do\n else\n do n = 0, m - 1\n Pnm(n) = 0._O\n end do\n call Pmm (theta, m, Pm)\n Pnm(m) = Pm\n do n = m, Nmax - 1\n f1 = real(2 * n + 1,O) / real(n + 1 - m,O)\n f2 = real(n + m,O) / real(n + 1 - m,O)\n Pnm(n+1) = f1 * cth * Pnm(n) - f2 * Pnm(n-1)\n end do\n end if\n if (m == 0) then\n dPnm(0) = 0._O\n do n = 1, Nmax\n f1 = real(n,O)\n dPnm(n) = f1 * Pnm(n-1) + cth * dPnm(n-1)\n end do\n else\n do n = 0, Nmax\n dPnm(n) = 0._O\n end do\n end if\n if (m == 0) then\n do n = 0, Nmax\n pinm(n) = 0._O\n taunm(n) = - sth * dPnm(n)\n end do\n else\n if (m == 1) then\n pinm(0) = 0._O \n taunm(0) = 0._O\n pinm(1) = 1._O\n else\n do n = 0, m - 1\n pinm(n) = 0._O\n taunm(n) = 0._O\n end do\n call pimm (theta, m, pim)\n pinm(m) = pim\n end if\n do n = m, Nmax - 1\n f1 = real(2 * n + 1,O) / real(n + 1 - m,O)\n f2 = real(n + m,O) / real(n + 1 - m,O)\n pinm(n+1) = f1 * cth * pinm(n) - f2 * pinm(n-1)\n end do\n do n = m, Nmax\n f1 = real(n,O)\n f2 = real(n + m,O)\n taunm(n) = f1 * cth * pinm(n) - f2 * pinm(n-1)\n end do\n end if \nend subroutine Leg\n!***********************************************************************************\nsubroutine P_mm_real (theta, m, Pm)\n!-----------------------------------------------------------------------------------\n! The routine computes the normalized Legendre function Pmm(theta) of real !\n! argument (real angle). ! \n!-----------------------------------------------------------------------------------\n use parameters\n implicit none\n integer :: k, m\n real(O) :: theta, Pm, tamp, f, cth, sth\n!\n cth = cos(theta)\n sth = sin(theta) \n if (m == 0) then\n Pm = sqrt(3._O / 2._O) * cth\n else\n tamp = 1._O\n do k = 1, m\n f = sqrt(real(m + k,O) / 4._O / real(k,O))\n tamp = f * sth * tamp \n end do\n f = sqrt(real(2 * m + 1,O) / 2._O)\n Pm = f * tamp\n end if\nend subroutine P_mm_real\n!***********************************************************************************\nsubroutine pi_mm_real (theta, m, pim)\n!-----------------------------------------------------------------------------------\n! The routine computes the normalized auxiliary function pimm, !\n! pimm(theta) = Pmm[cos(theta)] / sin(theta) !\n! of real argument (real angle). !\n!-----------------------------------------------------------------------------------\n use parameters\n implicit none\n integer :: k, m\n real(O) :: theta, pim, tamp, f, sth\n!\n sth = sin(theta)\n if (m == 0) then\n pim = 0._O\n else\n tamp = 1._O\n do k = 1, m - 1\n f = sqrt(real(m + k,O) / 4._O / real(k,O))\n tamp = f * sth * tamp \n end do \n f = sqrt(real(2 * m + 1,O)) / 2._O\n pim = f * tamp\n end if\nend subroutine pi_mm_real\n!***********************************************************************************\nsubroutine tau_mm_real (theta, m, taum)\n!-----------------------------------------------------------------------------------\n! The routine computes the normalized auxiliary function taumm, !\n! taumm(theta) = dPmm[cos(theta)] / d(theta) !\n! of real argument (real angle). !\n!-----------------------------------------------------------------------------------\n use parameters\n implicit none\n integer :: k, m\n real(O) :: theta, taum, tamp, f, cth, sth \n!\n cth = cos(theta)\n sth = sin(theta)\n if (m == 0) then\n taum = - sqrt(3._O / 2._O) * sth\n else\n tamp = 1._O\n do k = 1, m - 1\n f = sqrt(real(m + k,O) / 4._O / real(k,O)) \n tamp = f * sth * tamp \n end do\n f = real(m,O) * sqrt(real(2 * m + 1,O)) / 2._O\n taum = f * cth * tamp\n end if\nend subroutine tau_mm_real\n!***********************************************************************************\nsubroutine Leg_normalized (theta, m, Nmax, Pnm, dPnm, pinm, taunm)\n!------------------------------------------------------------------------------------\n! The routine computes the normalized associated Legendre functions !\n! Pnm[cos(theta)], the derivatives dPn0[cos(theta)] = dPn0[cos(theta)]/d[cos(theta)]!\n! and the auxiliary functions pinm(theta) = Pnm[cos(theta)]/sin(theta), and !\n! taunm(theta) = dPnm[cos(theta)]/d(theta) of degree m. The order of the normalized !\n! associated Legendre functions varies between 0 and Nmax, and note that for !\n! m > 0, the first m values of Pnm, pinm and taunm (corresponding to the orders !\n! 0, 1, ..., m - 1)are zero. The derivatives dPn0 are computed for the azimuthal !\n! mode m = 0 (for m >0, the Nmax values of dPn0 are zero). ! \n! !\n! Input parameteres: !\n! - theta (real) - polar angle (argument of the normalized associated Legendre !\n! functions). !\n! - m (integer) - degree of the normalized associated Legendre functions. !\n! - Nmax (integer) - maximum order of the normalized associated Legendre !\n! functions. !\n! ! \n! Output parameters: !\n! - Pnm (real array) - normalized associated Legendre functions. ! \n! - dPnm (real array) - derivatives of the normalized associated Legendre !\n! functions for m = 0. !\n! - pinm and taunm (real arrays) - normalized auxiliary functions. ! \n!------------------------------------------------------------------------------------ \n use parameters\n implicit none\n real(O) :: theta\n integer :: m, Nmax\n real(O) :: Pnm(0:Nmax), dPnm(0:Nmax), pinm(0:Nmax), taunm(0:Nmax)\n!\n real(O) :: Pm, pim, f1, f2, cth, sth\n integer :: n\n!\n cth = cos(theta)\n sth = sin(theta)\n if (m == 0) then\n Pnm(0) = sqrt(2._O) / 2._O\n Pnm(1) = sqrt(3._O / 2._O) * cos(theta)\n do n = 1, Nmax - 1\n f1 = sqrt(real(2 * n + 1,O) / real(n + 1,O))\n f1 = f1 * sqrt(real(2 * n + 3,O) / real(n + 1,O))\n f2 = sqrt(real(2 * n + 3,O) / real(2 * n - 1,O))\n f2 = f2 * real(n,O) / real(n + 1,O)\n Pnm(n+1) = f1 * cth * Pnm(n) - f2 * Pnm(n-1)\n end do\n else\n do n = 0, m - 1\n Pnm(n) = 0._O\n end do\n call P_mm_real (theta, m, Pm)\n Pnm(m) = Pm\n do n = m, Nmax - 1\n f1 = sqrt(real(2 * n + 1,O) / real(n + 1 - m,O))\n f1 = f1 * sqrt(real(2 * n + 3,O) / real(n + 1 + m,O))\n f2 = sqrt(real(2 * n + 3,O) / real(2 * n - 1,O))\n f2 = f2 * sqrt(real(n - m,O) / real(n - m + 1,O))\n f2 = f2 * sqrt(real(n + m,O) / real(n + m + 1,O))\n Pnm(n+1) = f1 * cth * Pnm(n) - f2 * Pnm(n-1)\n end do\n end if\n if (m == 0) then\n dPnm(0) = 0._O\n do n = 1, Nmax\n f2 = sqrt(real(2 * n + 1,O) / real(2 * n - 1,O))\n f1 = real(n,O) * f2\n dPnm(n) = f1 * Pnm(n-1) + f2 * cth * dPnm(n-1)\n end do\n else\n do n = 0, Nmax\n dPnm(n) = 0._O\n end do\n end if\n if (m == 0) then\n do n = 0, Nmax\n pinm(n) = 0._O\n taunm(n) = - sth * dPnm(n)\n end do\n else\n if (m == 1) then\n pinm(0) = 0._O \n taunm(0) = 0._O\n pinm(1) = sqrt(3._O) / 2._O\n else\n do n = 0, m - 1\n pinm(n) = 0._O\n taunm(n) = 0._O\n end do\n call pi_mm_real (theta, m, pim)\n pinm(m) = pim\n end if\n do n = m, Nmax - 1\n f1 = sqrt(real(2 * n + 1,O) / real(n + 1 - m,O))\n f1 = f1 * sqrt(real(2 * n + 3,O) / real(n + 1 + m,O))\n f2 = sqrt(real(2 * n + 3,O) / real(2 * n - 1,O))\n f2 = f2 * sqrt(real(n - m,O) / real(n - m + 1,O))\n f2 = f2 * sqrt(real(n + m,O) / real(n + m + 1,O))\n pinm(n+1) = f1 * cth * pinm(n) - f2 * pinm(n-1)\n end do\n do n = m, Nmax\n f1 = real(n,O)\n f2 = sqrt(real(2 * n + 1,O) / real(2 * n - 1,O))\n f2 = f2 * sqrt(real(n - m,O) / real(n + m,O))\n f2 = f2 * real(n + m,O)\n taunm(n) = f1 * cth * pinm(n) - f2 * pinm(n-1)\n end do\n end if \nend subroutine Leg_normalized\n!***********************************************************************************\nsubroutine P_mm (sint, cost, m, Pm)\n!-----------------------------------------------------------------------------------\n! The routine computes the normalized Legendre function Pmm(theta) of complex !\n! argument (complex angle). !\n!-----------------------------------------------------------------------------------\n use parameters\n implicit none\n integer :: k, m\n real(O) :: f\n complex(O) :: sint, cost, Pm, tamp \n!\n if (m == 0) then\n Pm = sqrt(3._O/2._O) * cost\n else\n tamp = one\n do k = 1, m\n f = sqrt(real(m + k,O) / 4._O / real(k,O)) \n tamp = f * sint * tamp \n end do\n f = sqrt(real(2 * m + 1,O) / 2._O)\n Pm = f * tamp\n end if \nend subroutine P_mm\n!***********************************************************************************\nsubroutine pi_mm (sint, m, pim)\n!-----------------------------------------------------------------------------------\n! The routine computes the normalized auxiliary function !\n! pimm(theta) = Pmm[cos(theta)] / sin(theta) !\n! of complex argument (complex angle). !\n!-----------------------------------------------------------------------------------\n use parameters\n implicit none\n integer :: k, m\n real(O) :: f\n complex(O) :: sint, pim, tamp \n!\n if (m == 0) then\n pim = zero\n else\n tamp = one\n do k = 1, m - 1\n f = sqrt(real(m + k,O) / 4._O / real(k,O))\n tamp = sint * f * tamp \n end do \n f = sqrt(real(2 * m + 1,O)) / 2._O\n pim = f * tamp\n end if \nend subroutine pi_mm\n!***********************************************************************************\nsubroutine tau_mm (sint, cost, m, taum)\n!-----------------------------------------------------------------------------------\n! The routine computes the normalized auxiliary function !\n! taumm(theta) = dPmm[cos(theta)] / d(theta) !\n! of complex argument (complex angle). !\n!-----------------------------------------------------------------------------------\n use parameters\n implicit none\n integer :: k, m\n real(O) :: f\n complex(O) :: sint, cost, taum, tamp \n!\n if (m == 0) then\n taum = - sqrt(3._O / 2._O) * sint\n else\n tamp = one\n do k = 1, m - 1\n f = sqrt(real(m + k,O) / 4._O / real(k,O))\n tamp = f * sint * tamp \n end do \n f = real(m,O) * sqrt(real(2 * m + 1,O)) / 2._O\n taum = f * cost * tamp\n end if \nend subroutine tau_mm\n!***********************************************************************************\nsubroutine Leg_normalized_complex (sint, cost, m, Nmax, Pnm, dPnm, pinm, taunm)\n!------------------------------------------------------------------------------------\n! The routine computes the normalized associated Legendre functions !\n! Pnm[cos(theta)], the derivatives dPn0[cos(theta)] = dPn0[cos(theta)]/d[cos(theta)]!\n! and the auxiliary functions pinm(theta) = Pnm[cos(theta)]/sin(theta), and !\n! taunm(theta) = dPnm[cos(theta)]/d(theta) of degree m and complex argument. !\n! The order of the normalized associated Legendre functions varies between 0 and !\n! Nmax, and note that for m > 0, the first m values of Pnm, pinm and taunm !\n! (corresponding to the orders 0, 1, ..., m - 1) are zero. The derivatives dPn0 !\n! are computed for the azimuthal mode m = 0 (for m >0, the Nmax values of dPn0 !\n! are zero). ! \n! !\n! Input parameteres: !\n! - sint (complex) - sint = sin(theta), where theta is the complex polar angle. !\n! - cost (complex) - cost = cos(theta), where theta is the complex polar angle. !\n! - m (integer) - degree of the normalized associated Legendre functions. !\n! - Nmax (integer) - maximum order of the normalized associated Legendre !\n! functions. !\n! ! \n! Output parameters: !\n! - Pnm (complex array) - normalized associated Legendre functions. ! \n! - dPnm (complex array) - derivatives of the normalized associated Legendre !\n! functions for m = 0. !\n! - pinm and taunm (complex arrays) - normalized auxiliary functions. ! \n!------------------------------------------------------------------------------------ \n use parameters\n implicit none\n integer :: m, Nmax\n complex(O) :: sint, cost\n complex(O) :: Pnm(0:Nmax), dPnm(0:Nmax), pinm(0:Nmax), taunm(0:Nmax)\n!\n complex(O) :: Pm, pim\n real(O) :: f1, f2\n integer :: n\n!\n if (m == 0) then\n Pnm(0) = cmplx(sqrt(2._O) / 2._O,0.0,O)\n Pnm(1) = sqrt(3._O / 2._O) * cost\n do n = 1, Nmax - 1\n f1 = sqrt(real(2 * n + 1,O) / real(n + 1,O))\n f1 = f1 * sqrt(real(2 * n + 3,O) / real(n + 1,O))\n f2 = sqrt(real(2 * n + 3,O) / real(2 * n - 1,O))\n f2 = f2 * real(n,O) / real(n + 1,O)\n Pnm(n+1) = f1 * cost * Pnm(n) - f2 * Pnm(n-1)\n end do\n else\n do n = 0, m - 1\n Pnm(n) = zero\n end do\n call P_mm (sint, cost, m, Pm)\n Pnm(m) = Pm\n do n = m, Nmax - 1\n f1 = sqrt(real(2 * n + 1,O) / real(n + 1 - m,O))\n f1 = f1 * sqrt(real(2 * n + 3,O) / real(n + 1 + m,O))\n f2 = sqrt(real(2 * n + 3,O) / real(2 * n - 1,O))\n f2 = f2 * sqrt(real(n - m,O) / real(n - m + 1,O))\n f2 = f2 * sqrt(real(n + m,O) / real(n + m + 1,O))\n Pnm(n+1) = f1 * cost * Pnm(n) - f2 * Pnm(n-1)\n end do\n end if\n if (m == 0) then\n dPnm(0) = zero\n do n = 1, Nmax\n f2 = sqrt(real(2 * n + 1,O) / real(2 * n - 1,O))\n f1 = real(n,O) * f2\n dPnm(n) = f1 * Pnm(n-1) + f2 * cost * dPnm(n-1)\n end do\n else\n do n = 0, Nmax\n dPnm(n) = zero\n end do\n end if\n if (m == 0) then\n do n = 0, Nmax\n pinm(n) = zero\n taunm(n) = - sint * dPnm(n)\n end do\n else\n if (m == 1) then\n pinm(0) = zero\n taunm(0) = zero\n pinm(1) = cmplx(sqrt(3._O) / 2._O,0.0,O)\n else\n do n = 0, m - 1\n pinm(n) = zero\n taunm(n) = zero\n end do\n call pi_mm (sint, m, pim) \n pinm(m) = pim\n end if\n do n = m, Nmax - 1\n f1 = sqrt(real(2 * n + 1,O) / real(n + 1 - m,O))\n f1 = f1 * sqrt(real(2 * n + 3,O) / real(n + 1 + m,O))\n f2 = sqrt(real(2 * n + 3,O) / real(2 * n - 1,O))\n f2 = f2 * sqrt(real(n - m,O) / real(n - m + 1,O))\n f2 = f2 * sqrt(real(n + m,O) / real(n + m + 1,O))\n pinm(n+1) = f1 * cost * pinm(n) - f2 * pinm(n-1)\n end do\n do n = m, Nmax\n f1 = real(n,O)\n f2 = sqrt(real(2 * n + 1,O) / real(2 * n - 1,O))\n f2 = f2 * sqrt(real(n - m,O) / real(n + m,O))\n f2 = f2 * real(n + m,O)\n taunm(n) = f1 * cost * pinm(n) - f2 * pinm(n-1)\n end do \n end if \nend subroutine Leg_normalized_complex\n! **********************************************************************************\n! * ALTERNATIVE ROUTINES FOR COMPUTING THE SPHERICAL BESSEL AND HANKEL *\n! * FUNCTIONS AND THE CYLINDRICAL BESSEL FUNCTIONS *\n! **********************************************************************************\nsubroutine besel_jA (z, N, j, jd)\n!-----------------------------------------------------------------------------------\n! The routine computes the spherical Bessel functions j(z) and the derivatives !\n! jd(z) = d(z*j(z))/dz. The order of the Bessel functions varies between 0 and N, !\n! and the backward recurrence relation !\n! csi(n,z) = 1.0 / ((2n+1) / z - csi(n+1,z)), n = Nstart,...,1, !\n! and the forward recurrence relations !\n! j(n,z) = csi(n,z) * j(n-1,z) !\n! jd(n,z) = ( z - n * csi(n,z)) * j(n-1,z), n = 1,...,N, !\n! with j(0,z) = sin(z) / z, are used for computation. Here Nstart is the downward !\n! starting index and j(n,z) denotes the Bessel function of order n and argument z. !\n! Note that: !\n! csi(n,z) = j(n,z) / j(n-1,z). ! \n! The following parmeters control the computation: ! \n! - ZeroSinXX (real) - for |z| < ZeroSinXX, we set j(0,z) = sin(z)/z = 1 and !\n! j(n,z) = 0, for n = 1,2,...,N. !\n! - NIterBes (integer) - maximum number of backward recurrences. Default value !\n! NIterBes = 5000. !\n! - TolJ0Val (real) - if abs(j(0,z) - sin(z)/z) > TolJ0Val, the starting index !\n! Nstart (of the backward recurrence) is increased by 20 and the recurrence is !\n! restarted. Default value: TolJ0Val = MachEps**0.666_O !\n! These parameters are specified in the routine \"DrvParameters\" from the file !\n! '../TMATROUTINES/MachParam.f90'. !\n! !\n! Input parameters: ! \n! - z (complex) - argument of the spherical Bessel functions. !\n! - N (integer) - maximum order of the spherical Bessel functions. !\n! !\n! Output parameters: !\n! - j (complex array) - spherical Bessel functions. !\n! - jd (complex array) - derivatives of the spherical Bessel functions. !\n! !\n! Note: This routine does not use the asymptotic expressions of spherical Bessel !\n! functions for large arguments. !\n!-----------------------------------------------------------------------------------\n use parameters\n use derived_parameters\n implicit none\n integer :: N\n complex(O) :: z, j(0:N), jd(0:N)\n! \n integer :: M, k\n real(O) :: a0, deps\n complex(O) :: csin1, csin, fct, j0, kc\n logical :: more\n complex(O),allocatable :: csi(:)\n! \n a0 = abs(z) \n allocate (csi(N))\n do k = 0, N \n j(k) = zero\n jd(k) = zero\n end do\n if (a0 < ZeroSinXX) then\n j(0) = one\n else\n j(0) = sin(z) / z\n j(1) = j(0) / z - cos(z) / z\n jd(1) = z * j(0) - j(1)\n if (N >= 2) then\n M = N + nint(a0 + 4._O * a0**0.33_O + 2._O + sqrt(101._O + a0)) + 10 \n more = .true. \n do while (more .and. M < NIterBes)\n csin1 = zero\n do k = M, 1, -1 \n fct = cmplx(2 * k + 1,0.0,O) / z\n csin = one / (fct - csin1)\n if (k <= N) csi(k) = csin\n csin1 = csin\n end do\n j(0) = cos(z) / (one - z * csi(1))\n j0 = sin(z) / z \n deps = abs (j0 - j(0)) \n if (deps < TolJ0Val) then\n more = .false.\n else\n M = M + 20\n end if\n end do\n if (more) then\n print \"(/,2x,'Error in subroutine besel_j:')\"\n print \"(2x,'the csi sequence can not be computed with the desired accuracy.')\"\n print \"(2x,'The tolerance TolJ0Val or the iteration number NIterBes specified')\"\n print \"(2x,'in the subroutine MachParam are too low. ')\"\n stop \n end if \n j(1) = csi(1) * j(0)\n jd(1) = (z - csi(1)) * j(0)\n do k = 2, N\n kc = cmplx(k,0.0,O)\n j(k) = csi(k) * j(k-1)\n jd(k) = (z - kc * csi(k)) * j(k-1)\n end do \n end if \n end if \n deallocate (csi)\nend subroutine besel_jA\n!**********************************************************************************\nsubroutine besel_hA (z, N, h, hd)\n!-----------------------------------------------------------------------------------\n! The routine computes the spherical Hankel functions of the first kind !\n! h(z) = j(z) + i*y(z) and the derivatives hd(z) = d(z*h(z))/dz, where j(z) and !\n! y(z) are the spherical Bessel and Neumann functions, respectively. The order of !\n! the functions varies between 0 and N, and the control parameters ZeroSinXX, !\n! NIterBes and TolJ0Val are specified in the routine \"DrvParameters\" from the file !\n! '../TMATROUTINES/MachParam.f90'. !\n! !\n! Input parameters: ! \n! - z (complex) - argument of the spherical Hankel functions. !\n! - N (integer) - maximum order of the spherical Hankel functions. !\n! !\n! Output parameters: !\n! - h (complex array) - spherical Hankel functions. !\n! - hd (complex array) - derivatives of the spherical Hankel functions. !\n! !\n! Note: This routine does not use the asymptotic expressions of spherical Bessel !\n! functions for large arguments. !\n!-----------------------------------------------------------------------------------\n use parameters\n use derived_parameters\n implicit none\n integer :: N\n complex(O) :: z, h(0:N), hd(0:N)\n!\n integer :: M, k\n real(O) :: a0, deps\n complex(O) :: csin1, csin, fct, j0, kc, z2, z3\n logical :: more\n complex(O),allocatable :: csi(:), j(:), y(:)\n! \n z2 = z * z\n z3 = z2 * z\n a0 = abs(z)\n allocate (csi(N), j(0:N), y(0:N))\n do k = 0, N \n j(k) = zero\n y(k) = zero\n h(k) = zero\n hd(k) = zero\n end do\n if (a0 < ZeroSinXX) then\n j(0) = one\n else\n j(0) = sin(z) / z\n j(1) = j(0) / z - cos(z) / z\n if (N >= 2) then\n M = N + nint(a0 + 4._O * a0**0.33_O + 2._O + sqrt(101._O + a0)) + 10\n more = .true. \n do while (more .and. M < NIterBes)\n csin1 = zero\n do k = M, 1, -1 \n fct = cmplx(2 * k + 1,0.0,O) / z\n csin = one / (fct - csin1)\n if (k <= N) csi(k) = csin\n csin1 = csin\n end do\n j(0) = cos(z) / (one - z * csi(1))\n j0 = sin(z) / z \n deps = abs (j0 - j(0)) \n if (deps < TolJ0Val) then\n more = .false.\n else\n M = M + 20\n end if\n end do \n if (more) then\n print \"(/,2x,'Error in subroutine besel_h:')\"\n print \"(2x,'the csi sequence can not be computed with the desired accuracy.')\"\n print \"(2x,'The tolerance TolJ0Val or the iteration number NIterBes specified')\"\n print \"(2x,'in the subroutine MachParam are too low. ')\" \n stop \n end if \n j(1) = csi(1) * j(0) \n do k = 2, N \n j(k) = csi(k) * j(k-1) \n end do \n end if \n y(0) = - cos(z) / z\n y(1) = (y(0) - sin(z)) / z\n if (N >= 2) then \n do k = 2, N\n if (abs(j(k-1)) > abs(j(k-2))) then \n y(k) = (j(k) * y(k-1) - one / z2) / j(k-1)\n else \n kc = cmplx(2 * k - 1,0.0,O)\n y(k) = (j(k) * y(k-2) - kc / z3) / j(k-2)\n end if \n end do \n end if \n do k = 0, N\n h(k) = j(k) + im * y(k)\n end do\n do k = 1, N\n kc = cmplx(k,0.0,O)\n hd(k) = z * h(k-1) - kc * h(k)\n end do\n end if\n deallocate (csi, j, y)\nend subroutine besel_hA\n!**********************************************************************************\nsubroutine besel_h_completeA (z, N, j, y, h, hd)\n!-----------------------------------------------------------------------------------\n! The routine computes the spherical Bessel and Neumann functions j(z) and y(z), !\n! the spherical Hankel functions of the first kind h(z) = j(z) + i*y(z) and the !\n! derivatives hd(z) = d(z*h(z))/dz. The order of the functions varies between 0 !\n! and N, and the control parameters ZeroSinXX, NIterBes and TolJ0Val are specified !\n! in the routine \"DrvParameters\" from the file '../TMATROUTINES/MachParam.f90'. !\n! !\n! Input parameters: ! \n! - z (complex) - argument of the spherical Bessel, Neumann and Hankel functions. !\n! - N (integer) - maximum order of the spherical functions. !\n! !\n! Output parameters: !\n! - j (complex array) - spherical Bessel functions. !\n! - y (complex array) - spherical Neumann functions. !\n! - h (complex array) - spherical Hankel functions. !\n! - hd (complex array) - derivatives of the spherical Hankel functions. !\n! !\n! Note: This routine does not use the asymptotic expressions of spherical Bessel !\n! functions for large arguments. !\n!-----------------------------------------------------------------------------------\n use parameters\n use derived_parameters\n implicit none\n integer :: N\n complex(O) :: z, j(0:N), y(0:N), h(0:N), hd(0:N)\n!\n integer :: M, k\n real(O) :: a0, deps\n complex(O) :: csin1, csin, fct, j0, kc, z2, z3\n logical :: more\n complex(O),allocatable :: csi(:)\n! \n z2 = z * z\n z3 = z2 * z\n a0 = abs(z) \n allocate (csi(N))\n do k = 0, N \n j(k) = zero\n y(k) = zero\n h(k) = zero\n hd(k) = zero\n end do\n if (a0 < ZeroSinXX) then\n j(0) = one\n else\n j(0) = sin(z) / z\n j(1) = j(0) / z - cos(z) / z\n if (N >= 2) then\n M = N + nint(a0 + 4._O * a0**0.33_O + 2._O + sqrt(101._O + a0)) + 10\n more = .true. \n do while (more .and. M < NIterBes)\n csin1 = zero\n do k = M, 1, -1 \n fct = cmplx(2 * k + 1,0.0,O) / z\n csin = one / (fct - csin1)\n if (k <= N) csi(k) = csin\n csin1 = csin\n end do\n j(0) = cos(z) / (one - z * csi(1))\n j0 = sin(z) / z \n deps = abs (j0 - j(0)) \n if (deps < TolJ0Val) then\n more = .false.\n else\n M = M + 20\n end if\n end do\n if (more) then\n print \"(/,2x,'Error in subroutine besel_h_complete:')\"\n print \"(2x,'the csi sequence can not be computed with the desired accuracy.')\"\n print \"(2x,'The tolerance TolJ0Val or the iteration number NIterBes specified')\"\n print \"(2x,'in the subroutine MachParam are too low. ')\" \n stop \n end if \n j(1) = csi(1) * j(0) \n do k = 2, N \n j(k) = csi(k) * j(k-1) \n end do \n end if \n y(0) = - cos(z) / z\n y(1) = (y(0) - sin(z)) / z\n if (N >= 2) then \n do k = 2, N\n if (abs(j(k-1)) > abs(j(k-2))) then \n y(k) = (j(k) * y(k-1) - one / z2) / j(k-1)\n else \n kc = cmplx(2 * k - 1,0.0,O)\n y(k) = (j(k) * y(k-2) - kc / z3) / j(k-2)\n end if \n end do \n end if \n do k = 0, N\n h(k) = j(k) + im * y(k)\n end do\n do k = 1, N\n kc = cmplx(k,0.0,O)\n hd(k) = z * h(k-1) - kc * h(k)\n end do\n end if\n deallocate (csi)\nend subroutine besel_h_completeA\n! **********************************************************************************\nsubroutine besel_jB (z, N, j, y)\n!-----------------------------------------------------------------------------------\n! The routine computes the spherical Bessel functions j(z) and the spherical !\n! Neumann functions y(z). The order of the functions varies between 0 and N, and !\n! a backward recurrence relation is used to compute the Bessel functions, while !\n! an upward recurrence relation is employed to compute the spherical Neumann !\n! functions. The control parameters ZeroSinXX, FactNBes, InitBesVal, UpperBoundSeq !\n! and LowerBoundSeq are specified in the routine \"DrvParameters\" from the file !\n! '../TMATROUTINES/MachParam.f90'. !\n! !\n! Input parameters: ! \n! - z (complex) - argument of the spherical Bessel and Neumann functions. !\n! - N (integer) - maximum order of the spherical functions. !\n! !\n! Output parameters: !\n! - j (complex array) - spherical Bessel functions. !\n! - y (complex array) - spherical Neumann functions. !\n! !\n! Note: This routine does not use the asymptotic expressions of spherical Bessel !\n! functions for large arguments. !\n!-----------------------------------------------------------------------------------\n use parameters\n use derived_parameters\n implicit none\n integer :: N\n complex(O) :: z, j(0:N), y(0:N)\n!\n complex(O) :: j0, j1, j2, f2, f1, f, kc, scale, z2, z3\n real(O) :: a0, ajscale\n integer :: M, Ma, Mn, k, l\n!\n z2 = z * z\n z3 = z2 * z\n a0 = abs(z) \n do k = 0, N \n j(k) = zero\n y(k) = zero\n end do\n if (a0 < ZeroSinXX) then\n j(0) = one\n else\n j(0) = sin(z) / z\n j(1) = j(0) / z - cos(z) / z\n if (N >= 2) then\n j0 = j(0)\n j1 = j(1)\n j2 = 3._O * j1 / z - j0\n Ma = nint(a0 + 4._O * a0**0.33_O + 2._O + sqrt(101._O + a0)) + 10 \n Mn = N + nint(sqrt(FactNBes * N))\n M = max(Ma,Mn) \n f2 = zero\n f1 = cmplx(InitBesVal,0.0,O)\n do k = M - 1, N, -1\n kc = cmplx(2 * k + 1,0.0,O)\n f = kc * f1 / z - f2 \n f2 = f1\n f1 = f\n if (abs(f1) > UpperBoundSeq) then\n f2 = f2 * LowerBoundSeq\n f1 = f1 * LowerBoundSeq \n else if (abs(f1) < LowerBoundSeq) then\n f2 = f2 * UpperBoundSeq\n f1 = f1 * UpperBoundSeq \n end if \n end do\n j(N) = f2\n j(N-1) = f1\n do k = N - 1, 1, -1\n kc = cmplx(2 * k + 1,0.0,O)\n j(k-1) = kc * j(k)/z - j(k+1)\n if (abs(j(k-1)) > UpperBoundSeq) then \n do l = k - 1, N\n j(l) = j(l) * LowerBoundSeq\n end do\n else if (abs(j(k-1)) < LowerBoundSeq) then \n do l = k - 1, N\n j(l) = j(l) * UpperBoundSeq\n end do \n end if\n end do\n ajscale = max(abs(j0), abs(j1), abs(j2))\n if (ajscale == abs(j0)) then\n scale = j0 / j(0)\n else if (ajscale == abs(j1)) then\n scale = j1 / j(1)\n else\n scale = j2 / j(2) \n end if\n do k = 0, N\n j(k) = scale * j(k)\n end do\n end if \n y(0) = - cos(z) / z\n y(1) = (y(0) - sin(z)) / z\n if (N >= 2) then \n do k = 2, N\n if (abs(j(k-1)) > abs(j(k-2))) then\n y(k) = (j(k) * y(k-1) - 1._O / z2) / j(k-1)\n else \n kc = cmplx(2 * k - 1,0.0,O)\n y(k) = (j(k) * y(k-2) - kc / z3) / j(k-2)\n end if \n end do \n end if\n end if \nend subroutine besel_jB\n!***********************************************************************************\nsubroutine besel_jC (z, N, j, y)\n!-----------------------------------------------------------------------------------\n! The routine computes the spherical Bessel functions j(z) and the spherical !\n! Neumann functions y(z). The order of the functions varies between 0 and N, and !\n! a backward recurrence relation is used to compute the Bessel functions, while !\n! an upward recurrence relation is employed to compute the spherical Neumann !\n! functions. The parameters which control the computation are ZeroSinXX, !\n! InitBesVal, UpperBoundSeq, LowerBoundSeq and LargestBesVal. LargestBesVal !\n! is real and denotes the largest (accepted) values of the spherical Neumann !\n! functions (default value: LargestBesVal = LargestPosNumber**0.333). These !\n! parameters are specified in the routine \"DrvParameters\" from the file !\n! '../TMATROUTINES/MachParam.f90'. !\n! !\n! Input parameters: ! \n! - z (complex) - argument of the spherical Bessel functions. !\n! - N (integer) - maximum order of the spherical Bessel functions. !\n! !\n! Output parameters: !\n! - j (complex array) - spherical Bessel functions. !\n! - y (complex array) - spherical Neumann functions. !\n! !\n! Note: This routine does not use the asymptotic expressions of spherical Bessel !\n! functions for large arguments. !\n!-----------------------------------------------------------------------------------\n use parameters\n use derived_parameters\n implicit none\n integer :: N\n complex(O) :: z, j(0:N), y(0:N)\n!\n complex(O) :: j0, j1, j2, f2, f1, f, y0, y1, g0, g1, yk, h2, h1, h0, yl2, yl1, &\n ylk, P11, P12, P21, P22, scale, z2, kc\n real(O) :: a0, yak, ya1, wa, ya0, ajscale\n integer :: NM, M, k, l, LB, LB0, MSTA1, MSTA2\n!\n z2 = z * z\n a0 = abs(z) \n NM = N \n do k = 0, N \n j(k) = zero\n y(k) = zero\n end do\n if (a0 < ZeroSinXX) then\n j(0) = one\n else\n j(0) = sin(z) / z\n j(1) = (j(0) - cos(z)) / z\n if (NM >= 2) then\n j0 = j(0)\n j1 = j(1)\n j2 = 3._O * j1 / z - j0 \n M = MSTA1 (a0, 200)\n if (M < N) then\n NM = M \n else \n M = MSTA2 (A0, N, 15)\n end if \n f2 = zero\n f1 = cmplx(InitBesVal,0.0,O)\n do k = M - 1, NM, -1\n kc = cmplx(2 * k + 1,0.0,O)\n f = kc * f1 / z - f2 \n f2 = f1\n f1 = f\n if (abs(f1) > UpperBoundSeq) then\n f2 = f2 * LowerBoundSeq\n f1 = f1 * LowerBoundSeq \n else if (abs(f1) < LowerBoundSeq) then\n f2 = f2 * UpperBoundSeq\n f1 = f1 * UpperBoundSeq \n end if \n end do\n j(NM) = f2\n j(NM-1) = f1\n do k = NM - 1, 1, -1\n kc = cmplx(2 * k + 1,0.0,O) \n j(k-1) = kc * j(k) / z - j(k+1)\n if (abs(j(k-1)) > UpperBoundSeq) then \n do l = k - 1, NM\n j(l) = j(l) * LowerBoundSeq\n end do\n else if (abs(j(k-1)) < LowerBoundSeq) then \n do l = k - 1, NM\n j(l) = j(l) * UpperBoundSeq\n end do \n end if \n end do\n ajscale = max(abs(j0), abs(j1), abs(j2))\n if (ajscale == abs(j0)) then\n scale = j0 / j(0)\n else if (ajscale == abs(j1)) then\n scale = j1 / j(1)\n else\n scale = j2 / j(2)\n end if \n do k = 0, NM\n j(k) = scale * j(k)\n end do\n end if \n y(0) = - cos(z) / z\n y(1) = (y(0) - sin(z)) / z \n if (NM >= 2) then\n y0 = y(0)\n y1 = y(1) \n ya0 = abs(y0)\n LB = 0\n g0 = y0\n g1 = y1\n do k = 2, NM\n kc = cmplx(2 * k - 1,0.0,O)\n yk = kc / z * g1 - g0\n if (abs (yk) > LargestBesVal) exit \n yak = abs(yk)\n ya1 = abs(g0)\n if ((yak < ya0) .and. (yak < ya1)) LB = k\n y(k) = yk\n g0 = g1\n g1 = yk\n end do \n do while ((LB > 4) .and. (aimag(z) /= 0._O) .and. (LB /= LB0)) \n h2 = one\n h1 = zero\n LB0 = LB\n do k = LB, 1, -1\n kc = cmplx(2 * k + 1,0.0,O)\n h0 = kc / z * h1 - h2\n h2 = h1\n h1 = h0\n end do\n P12 = h0\n P22 = h2\n h2 = zero\n h1 = one\n do k = LB, 1, -1\n kc = cmplx(2 * k + 1,0.0,O)\n h0 = kc / z * h1 - h2\n h2 = h1\n h1 = h0\n end do\n P11 = h0\n P21 = h2\n if (LB == NM) j(LB+1) = (2._O * LB + 1._O) / z * j(LB) - j(LB-1)\n if (abs(j(0)) > abs(j(1))) then \n y(LB+1) = (j(LB+1) * y0 - P11 / z2) / j(0)\n y(LB) = (j(LB) * y0 + P12 / z2) / j(0)\n else \n y(LB+1) = (j(LB+1) * y1 - P21 / z2) / j(1)\n y(LB) = (j(LB) * y1 + P22 / z2) / j(1)\n end if \n yl2 = y(LB+1)\n yl1 = y(LB)\n do k = LB - 1, 0, -1\n kc = cmplx(2 * k + 3,0.0,O)\n ylk = kc / z * yl1 - yl2\n y(k)= ylk \n yl2 = yl1\n yl1 = ylk \n end do\n yl1 = y(LB)\n yl2 = y(LB+1)\n do k = LB + 1, NM - 1\n kc = cmplx(2 * k + 1,0.0,O)\n ylk = kc /z * yl2 - yl1 \n y(k+1) = ylk \n yl1 = yl2\n yl2 = ylk\n end do\n do k = 2, NM\n wa = abs(y(k))\n IF (wa < abs(y(k-1))) LB = k\n end do \n end do \n end if\n end if \nend subroutine besel_jC\n! **********************************************************************************\nsubroutine bes_JA (z, N, J)\n!-----------------------------------------------------------------------------------\n! The routine computes the cylindrical Bessel function J(z). The order of the !\n! Bessel functions varies between 0 and N, and the control parameters ZeroSinXX, !\n! InitBesVal, UpperBoundSeq and LowerBoundSeq are specified in the routine !\n! \"DrvParameters\" from the file '../TMATROUTINES/MachParam.f90'. !\n! !\n! Input parameters: ! \n! - z (complex) - argument of the cylindrical Bessel functions. !\n! - N (integer) - maximum order of cylindrical Bessel functions. !\n! !\n! Output parameters: !\n! - J (complex array) - cylindrical Bessel functions. ! \n!-----------------------------------------------------------------------------------\n use parameters\n use derived_parameters\n implicit none \n integer :: N\n complex(O) :: z, J(0:N)\n!\n complex(O) :: J0, J1, f2, f1, f, scale, kc\n real(O) :: a0\n integer :: NM, M, k, l, MSTA1, MSTA2 \n!\n a0 = abs(z)\n NM = N \n do k = 0, N\n J(k) = zero\n end do\n if (a0 < ZeroSinXX) then \n J(0) = one\n else \n call J01 (z, J0, J1)\n J(0) = J0\n J(1) = J1 \n if (N > 1) then\n if (N < int(0.25_O * a0)) then \n do k = 2, N\n kc = cmplx(2 * (k - 1),0.0,O)\n J(k) = kc * J(k-1) / z - J(k-2) \n end do \n else \n M = MSTA1 (a0, 200)\n if (M < N) then\n NM = M \n else \n M = MSTA2 (A0, N, 15)\n end if \n f2 = zero\n f1 = cmplx(InitBesVal,0.0,O) \n do k = M, 0, -1\n kc = cmplx(2 * (k + 1),0.0,O) \n f = kc * f1 / z - f2 \n if (k <= NM) J(k) = f\n f2 = f1\n f1 = f\n if (abs(f1) > UpperBoundSeq) then\n f2 = f2 * LowerBoundSeq\n f1 = f1 * LowerBoundSeq\n do l = k, NM\n J(l) = J(l) * LowerBoundSeq\n end do\n else if (abs(f1) < LowerBoundSeq) then\n f2 = f2 * UpperBoundSeq\n f1 = f1 * UpperBoundSeq\n do l = k, NM\n J(l) = J(l) * UpperBoundSeq\n end do \n end if \n end do\n if (abs(f1) > abs(f2)) then\n scale = J0 / f1\n else \n scale = J1 / f2\n end if \n do k = 0, NM\n J(k) = scale * J(k)\n end do \n end if\n end if\n end if \nend subroutine bes_JA\n!***********************************************************************************\nfunction MSTA1 (x, MP) result (MSTA)\n use parameters\n implicit none \n real(O), intent(in) :: x\n integer,intent(in) :: MP \n integer :: MSTA, N0, N1, it, NN \n real(O) :: a0, f0, f1, f, ENVJ \n!\n a0 = abs(x)\n if (a0 < 1._O) a0 = 1._O\n N0 = int(1.1_O * a0) + 1\n f0 = ENVJ(N0,a0) - MP\n N1 = N0 + 5\n f1 = ENVJ(N1,a0) - MP\n do it = 1, 50 \n NN = N1 - int((N1 - N0) / (1._O - f0 / f1)) \n f = ENVJ(NN,a0) - MP\n if (abs(NN - N1) < 1) exit\n N0 = N1\n f0 = f1\n N1 = NN\n f1 = f\n end do \n MSTA = NN \nend function MSTA1\n!***********************************************************************************\nfunction MSTA2 (x, N, MP) result (MSTA)\n use parameters\n implicit none \n real(O), intent(in) :: x\n integer,intent(in) :: N, MP \n integer :: MSTA, N0, N1, it, NN\n real(O) :: a0, hmp, ejn, obj, f0, f1, f, ENVJ \n!\n a0 = abs(X)\n if (a0 < 1._O) a0 = 1._O\n hmp = 0.5_O * MP\n ejn = ENVJ(N,a0)\n if (ejn <= hmp) then\n obj = 1._O * MP\n N0 = int(1.1_O * a0)\n else\n obj = hmp + ejn\n N0 = N\n end if\n f0 = ENVJ(N0,a0) - obj\n N1 = N0 + 5\n f1 = ENVJ(N1,A0) - obj\n do it = 1, 50\n NN = N1 - int((N1 - N0) / (1._O - f0 / f1))\n f = ENVJ(NN,a0) - obj\n if (abs(NN - N1) < 1) exit\n N0 = N1\n f0 = f1\n N1 = NN\n f1 = f\n end do\n MSTA = NN + 10\nend function MSTA2\n!***********************************************************************************\nfunction ENVJ (N, x) result (ENV) \n use parameters\n implicit none \n real(O), intent(in) :: x\n integer,intent(in) :: N \n real(O) :: ENV\n!\n ENV = 0.5_O * log10(6.28_O * N) - N * log10(1.36_O * x / N) \nend function ENVJ\n\n\n\n", "meta": {"hexsha": "8f81c2179a84b6aca3cf4a3eeeb0fce98ff7662a", "size": 68941, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "smuthi/linearsystem/tmatrix/nfmds/NFM-DS/TMATSOURCES/BesLeg.f90", "max_stars_repo_name": "parkerwray/smuthi-1", "max_stars_repo_head_hexsha": "a5ced07461b8fd223dc37d28259261ceed78aed5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "smuthi/linearsystem/tmatrix/nfmds/NFM-DS/TMATSOURCES/BesLeg.f90", "max_issues_repo_name": "parkerwray/smuthi-1", "max_issues_repo_head_hexsha": "a5ced07461b8fd223dc37d28259261ceed78aed5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "smuthi/linearsystem/tmatrix/nfmds/NFM-DS/TMATSOURCES/BesLeg.f90", "max_forks_repo_name": "parkerwray/smuthi-1", "max_forks_repo_head_hexsha": "a5ced07461b8fd223dc37d28259261ceed78aed5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.7744656918, "max_line_length": 116, "alphanum_fraction": 0.3948738777, "num_tokens": 20516, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.959154281754899, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7557475848055721}} {"text": " PROGRAM xsprspm\r\nC driver for routine sprspm\r\n INTEGER NP,NMAX\r\n PARAMETER(NP=5,NMAX=2*NP*NP+1)\r\n INTEGER i,j,k,ija(NMAX),ijb(NMAX),ijbt(NMAX),ijc(NMAX)\r\n REAL sa(NMAX),sb(NMAX),sbt(NMAX),sc(NMAX)\r\n REAL a(NP,NP),b(NP,NP),c(NP,NP),ab(NP,NP)\r\n DATA a/1.0,0.5,0.0,0.0,0.0,\r\n * 0.5,2.0,0.5,0.0,0.0,\r\n * 0.0,0.5,3.0,0.5,0.0,\r\n * 0.0,0.0,0.5,4.0,0.5,\r\n * 0.0,0.0,0.0,0.5,5.0/\r\n DATA b/1.0,1.0,0.0,0.0,0.0,\r\n * 1.0,2.0,1.0,0.0,0.0,\r\n * 0.0,1.0,3.0,1.0,0.0,\r\n * 0.0,0.0,1.0,4.0,1.0,\r\n * 0.0,0.0,0.0,1.0,5.0/\r\n call sprsin(a,NP,NP,0.5,NMAX,sa,ija)\r\n call sprsin(b,NP,NP,0.5,NMAX,sb,ijb)\r\n call sprstp(sb,ijb,sbt,ijbt)\r\nC specify tridiagonal output, using fact that a is tridiagonal\r\n do 11 i=1,ija(ija(1)-1)-1\r\n ijc(i)=ija(i)\r\n11 continue\r\n call sprspm(sa,ija,sbt,ijbt,sc,ijc)\r\n do 14 i=1,NP\r\n do 13 j=1,NP\r\n ab(i,j)=0.0\r\n do 12 k=1,NP\r\n ab(i,j)=ab(i,j)+a(i,k)*b(k,j)\r\n12 continue\r\n13 continue\r\n14 continue\r\n write(*,*) 'Reference matrix:'\r\n write(*,'(5f7.1)') ((ab(i,j),j=1,NP),i=1,NP)\r\n write(*,*) 'sprspm matrix (should show only tridiagonals):'\r\n do 16 i=1,NP\r\n do 15 j=1,NP\r\n c(i,j)=0.0\r\n15 continue\r\n16 continue\r\n do 18 i=1,NP\r\n c(i,i)=sc(i)\r\n do 17 j=ijc(i),ijc(i+1)-1\r\n c(i,ijc(j))=sc(j)\r\n17 continue\r\n18 continue\r\n write(*,'(5f7.1)') ((c(i,j),j=1,NP),i=1,NP)\r\n END\r\n", "meta": {"hexsha": "4e2e6a7658a5e9a14ee77587d38aeb5a14727d35", "size": 1561, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xsprspm.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xsprspm.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xsprspm.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.22, "max_line_length": 67, "alphanum_fraction": 0.4746957079, "num_tokens": 719, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7555547640520288}} {"text": "program writeSampleBinData\n\n ! Created by Manuel A. Diaz, ENSMA 2020\n \n implicit none\n\n !-------- initialize variables -------------------\n character(len=30) :: output_file0 = \"fields_d0_it0.bin\"\n character(len=30) :: output_file1 = \"xp.dat\"\n character(len=30) :: output_file2 = \"yp.dat\"\n character(len=30) :: output_file3 = \"zp.dat\"\n character(len=10) :: Nx_char\n character(len=10) :: Ny_char\n character(len=10) :: Nz_char\n\n integer :: Nx, Ny, Nz ! Array dimensions\n integer :: output_file_id=3 ! File identifier\n real(8) :: Lx, Ly, Lz ! mesh Lengths\n real(8) :: dx, dy, dz ! mesh cell's sizes\n real(8), allocatable :: x(:), y(:), z(:) ! Axis points arrays\n real(8), allocatable :: p(:,:,:) ! Buffer for array\n real(8) :: IC_P0 = 1.0 ! Amplitude\n real(8) :: IC_x0 = 0.5 ! x-center\n real(8) :: IC_y0 = 0.5 ! y-center\n real(8) :: IC_z0 = 0.5 ! z-center\n real(8) :: IC_S0 = 0.31 ! Sigma\n integer :: buff_lenght ! Buffer length\n integer :: i, j, k ! dummy indexes\n\n !-------- Parse arguments from command -----------\n if ( command_argument_count() .NE. 3 ) then\n print*, \"Mode of use: ./sample_binFields.run [Nx] [Ny] [Nz]\"; stop\n else \n call get_command_argument(1,Nx_char); read(Nx_char,*) Nx\n call get_command_argument(2,Ny_char); read(Ny_char,*) Ny\n call get_command_argument(3,Nz_char); read(Nz_char,*) Nz\n print*, \"Attemping to write \",Nx,\"Nx\",Ny,\"Ny\",Nz,\"Nz array.\"\n end if\n\n !-------- Allocate space for the array -----------\n allocate( x(Nx) )\n allocate( y(Ny) )\n allocate( z(Nz) )\n allocate( p(Nx,Ny,Nz) )\n\n !-------- Build mesh grid axis -------------------\n Lx = 1.0; dx = Lx / (Nx-1) \n Ly = 1.0; dy = Ly / (Ny-1) \n Lz = 1.0; dz = Lz / (Nz-1) \n do i = 1,Nx\n x(i) = dx*real(i-1)\n end do\n do j = 1,Ny\n y(j) = dy*real(j-1)\n end do\n do k = 1,Nz\n z(k) = dz*real(k-1)\n end do\n\n !------ fill in the array with sample data -------\n do k = 1,Nz\n do j = 1,Ny\n do i = 1,Nx\n p(i,j,k) = IC_P0 * exp( -((x(i)-IC_x0)**2 + (y(j)-IC_y0)**2 + (z(k)-IC_z0)**2)/(IC_S0**2) )\n end do\n end do\n end do\n\n !------ write in data in a binary file -----------\n Inquire( iolength = buff_lenght ) p\n open (output_file_id,file=trim(output_file0), form='unformatted', access='direct', recl=buff_lenght)\n write(output_file_id,rec=1) p\n close(output_file_id)\n open (output_file_id,file=trim(output_file1), form='formatted', action='write')\n do i = 1, Nx\n write(output_file_id,'(F10.8)') x(i)\n end do\n close(output_file_id)\n open (output_file_id,file=trim(output_file2), form='formatted', action='write')\n do i = 1, Ny\n write(output_file_id,'(F10.8)') y(i)\n end do\n close(output_file_id)\n open (output_file_id,file=trim(output_file3), form='formatted', action='write')\n do i = 1, Nz\n write(output_file_id,'(F10.8)') z(i)\n end do\n close(output_file_id)\n\n ! If we reach this point then\n print*, \"outputs: \", output_file0, output_file1, output_file2, output_file3\n deallocate(x)\n deallocate(y)\n deallocate(z)\n deallocate(p)\n\n end program writeSampleBinData", "meta": {"hexsha": "71d724e612f931ee5494dbb5656bc9920271368b", "size": 3472, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/createSample_binFields_serial.f90", "max_stars_repo_name": "wme7/Fortran2Paraview_with_HDF5", "max_stars_repo_head_hexsha": "7afe4421fe72be316bd475e3b07e5e4f2a72b7af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-09-30T00:24:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-06T15:13:40.000Z", "max_issues_repo_path": "src/createSample_binFields_serial.f90", "max_issues_repo_name": "wme7/Fortran2Paraview_with_HDF5", "max_issues_repo_head_hexsha": "7afe4421fe72be316bd475e3b07e5e4f2a72b7af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/createSample_binFields_serial.f90", "max_forks_repo_name": "wme7/Fortran2Paraview_with_HDF5", "max_forks_repo_head_hexsha": "7afe4421fe72be316bd475e3b07e5e4f2a72b7af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-30T00:25:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-30T00:25:19.000Z", "avg_line_length": 35.793814433, "max_line_length": 107, "alphanum_fraction": 0.534562212, "num_tokens": 1086, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970904940926, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7555196543964421}} {"text": "module advance_module\n\n implicit none\n\n private\n\n public :: advance\n\ncontains\n \n subroutine advance(data,dx,dt)\n\n use multifab_module\n\n type(multifab) , intent(inout) :: data\n real(kind=dp_t), intent(in ) :: dx\n real(kind=dp_t), intent(in ) :: dt\n\n ! local variables\n integer :: lo(data%dim), hi(data%dim)\n integer :: dm, ng, i\n\n real(kind=dp_t), pointer :: dp(:,:,:,:)\n\n ! set these here so we don't have to pass them into the subroutine\n dm = data%dim\n ng = data%ng\n\n do i=1,nfabs(data)\n dp => dataptr(data,i)\n lo = lwb(get_box(data,i))\n hi = upb(get_box(data,i))\n select case(dm)\n case (2)\n call advance_2d(dp(:,:,1,:), ng, lo, hi, dx, dt)\n case (3)\n call advance_3d(dp(:,:,:,:), ng, lo, hi, dx, dt)\n end select\n end do\n \n ! fill ghost cells\n ! this only fills periodic ghost cells and ghost cells for neighboring\n ! grids at the same level. Physical boundary ghost cells are filled\n ! using multifab_physbc. But this problem is periodic, so this\n ! call is sufficient.\n call multifab_fill_boundary(data)\n\n end subroutine advance\n\n subroutine advance_2d(U, ng, lo, hi, dx, dt)\n\n integer :: lo(2), hi(2), ng\n double precision :: U(lo(1)-ng:,lo(2)-ng:,:)\n double precision :: dx, dt\n\n double precision, allocatable :: dU(:,:,:), Unew(:,:,:)\n\n double precision, parameter :: third = 1.d0/3.d0\n double precision, parameter :: twothirds = 2.d0/3.d0\n double precision, parameter :: fac1 = -1.d0/12.d0\n double precision, parameter :: fac2 = 4.d0/3.d0\n double precision, parameter :: fac3 = -5.0d0\n \n integer :: i,j,ndo\n\n allocate( dU(lo(1)-ng:hi(1)+ng,lo(2)-ng:hi(2)+ng,2))\n allocate(Unew(lo(1)-ng:hi(1)+ng,lo(2)-ng:hi(2)+ng,2))\n\n if (ng < 6) then\n print *,'NOT ENOUGH GHOST CELLS IN ADVANCE ',ng\n stop\n end if\n \n ! First call to get RHS = Lap(U)\n ndo = 4\n\n do j = lo(2)-ndo,hi(2)+ndo\n do i = lo(1)-ndo,hi(1)+ndo\n\n dU(i,j,1) = U(i,j,2)\n\n dU(i,j,2) = ( fac1 * ( U(i-2,j,1) + U(i+2,j,1) + &\n U(i,j-2,1) + U(i,j+2,1) ) &\n + fac2 * ( U(i-1,j,1) + U(i+1,j,1) + &\n U(i,j-1,1) + U(i,j+1,1) ) &\n + fac3 * U(i,j,1) ) / (dx*dx)\n end do\n end do\n\n ! First update\n ! This Unew lives at t^{n+1}\n Unew(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,1:2) = & \n U(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,1:2) &\n + dt * dU(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,1:2)\n\n ! Second call to get RHS = Lap(Unew)\n ndo = 2\n\n do j = lo(2)-ndo,hi(2)+ndo\n do i = lo(1)-ndo,hi(1)+ndo\n\n dU(i,j,1) = Unew(i,j,2)\n\n dU(i,j,2) = ( fac1 * ( Unew(i-2,j,1) + Unew(i+2,j,1) + &\n Unew(i,j-2,1) + Unew(i,j+2,1) ) &\n + fac2 * ( Unew(i-1,j,1) + Unew(i+1,j,1) + &\n Unew(i,j-1,1) + Unew(i,j+1,1) ) &\n + fac3 * Unew(i,j,1) ) / (dx*dx)\n end do\n end do\n\n ! Second update\n ! This Unew lives at t^{n+1/2}\n Unew(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,1:2) = &\n .75d0 * U(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,1:2) &\n + .25d0 * Unew(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,1:2) &\n + dt * .25d0 * dU(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,1:2)\n\n ! Third call to get RHS = Lap(Unew)\n ndo = 0\n\n do j = lo(2)-ndo,hi(2)+ndo\n do i = lo(1)-ndo,hi(1)+ndo\n\n dU(i,j,1) = Unew(i,j,2)\n\n dU(i,j,2) = ( fac1 * ( Unew(i-2,j,1) + Unew(i+2,j,1) + &\n Unew(i,j-2,1) + Unew(i,j+2,1) ) &\n + fac2 * ( Unew(i-1,j,1) + Unew(i+1,j,1) + &\n Unew(i,j-1,1) + Unew(i,j+1,1) ) &\n + fac3 * Unew(i,j,1) ) / (dx*dx)\n end do\n end do\n\n ! Third update\n ! This Unew lives at t^{n+1}\n U(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,1:2) = &\n third * U(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,1:2) &\n + twothirds * Unew(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,1:2) &\n + dt * twothirds * dU(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,1:2)\n\n deallocate(dU,Unew)\n\n end subroutine advance_2d\n\n subroutine advance_3d(U, ng, lo, hi, dx, dt)\n\n integer :: lo(3), hi(3), ng\n double precision :: U(lo(1)-ng:,lo(2)-ng:,lo(3)-ng:,:)\n double precision :: dx, dt\n\n double precision, allocatable :: dU(:,:,:,:), Unew(:,:,:,:)\n\n double precision, parameter :: third = 1.d0/3.d0\n double precision, parameter :: twothirds = 2.d0/3.d0\n double precision, parameter :: fac1 = -1.d0/12.d0\n double precision, parameter :: fac2 = 4.d0/3.d0\n double precision, parameter :: fac3 = -7.5d0\n \n integer :: i,j,k,ndo\n\n allocate( dU(lo(1)-ng:hi(1)+ng,lo(2)-ng:hi(2)+ng,lo(3)-ng:hi(3)+ng,2))\n allocate(Unew(lo(1)-ng:hi(1)+ng,lo(2)-ng:hi(2)+ng,lo(3)-ng:hi(3)+ng,2))\n\n if (ng < 6) then\n print *,'NOT ENOUGH GHOST CELLS IN ADVANCE ',ng\n stop\n end if\n \n ! First call to get RHS = Lap(U)\n ndo = 4\n\n do k = lo(3)-ndo,hi(3)+ndo\n do j = lo(2)-ndo,hi(2)+ndo\n do i = lo(1)-ndo,hi(1)+ndo\n\n dU(i,j,k,1) = U(i,j,k,2)\n \n dU(i,j,k,2) = ( fac1 * ( U(i-2,j,k,1) + U(i+2,j,k,1) + &\n U(i,j-2,k,1) + U(i,j+2,k,1) + &\n U(i,j,k-2,1) + U(i,j,k+2,1) ) &\n + fac2 * ( U(i-1,j,k,1) + U(i+1,j,k,1) + &\n U(i,j-1,k,1) + U(i,j+1,k,1) + &\n U(i,j,k-1,1) + U(i,j,k+1,1) ) &\n + fac3 * U(i,j,k,1) ) / (dx*dx)\n end do\n end do\n end do\n\n ! First update\n ! This Unew lives at t^{n+1}\n Unew(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,lo(3)-ndo:hi(3)+ndo,1:2) = & \n U(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,lo(3)-ndo:hi(3)+ndo,1:2) &\n + dt * dU(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,lo(3)-ndo:hi(3)+ndo,1:2)\n \n ! Second call to get RHS = Lap(Unew)\n ndo = 2\n\n do k = lo(3)-ndo,hi(3)+ndo\n do j = lo(2)-ndo,hi(2)+ndo\n do i = lo(1)-ndo,hi(1)+ndo\n\n dU(i,j,k,1) = Unew(i,j,k,2)\n\n dU(i,j,k,2) = ( fac1 * ( Unew(i-2,j,k,1) + Unew(i+2,j,k,1) + &\n Unew(i,j-2,k,1) + Unew(i,j+2,k,1) + &\n Unew(i,j,k-2,1) + Unew(i,j,k+2,1) ) &\n + fac2 * ( Unew(i-1,j,k,1) + Unew(i+1,j,k,1) + &\n Unew(i,j-1,k,1) + Unew(i,j+1,k,1) + &\n Unew(i,j,k-1,1) + Unew(i,j,k+1,1) ) &\n + fac3 * Unew(i,j,k,1) ) / (dx*dx)\n end do\n end do\n end do\n\n ! Second update\n ! This Unew lives at t^{n+1/2}\n Unew(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,lo(3)-ndo:hi(3)+ndo,1:2) = & \n .75d0 * U(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,lo(3)-ndo:hi(3)+ndo,1:2) &\n + .25d0 * Unew(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,lo(3)-ndo:hi(3)+ndo,1:2) &\n + dt * .25d0 * dU(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,lo(3)-ndo:hi(3)+ndo,1:2) \n\n ! Third call to get RHS = Lap(Unew)\n ndo = 0\n\n do k = lo(3)-ndo,hi(3)+ndo\n do j = lo(2)-ndo,hi(2)+ndo\n do i = lo(1)-ndo,hi(1)+ndo\n\n dU(i,j,k,1) = Unew(i,j,k,2)\n\n dU(i,j,k,2) = ( fac1 * ( Unew(i-2,j,k,1) + Unew(i+2,j,k,1) + &\n Unew(i,j-2,k,1) + Unew(i,j+2,k,1) + &\n Unew(i,j,k-2,1) + Unew(i,j,k+2,1) ) &\n + fac2 * ( Unew(i-1,j,k,1) + Unew(i+1,j,k,1) + &\n Unew(i,j-1,k,1) + Unew(i,j+1,k,1) + &\n Unew(i,j,k-1,1) + Unew(i,j,k+1,1) ) &\n + fac3 * Unew(i,j,k,1) ) / (dx*dx)\n\n end do\n end do\n end do\n\n ! Third update\n ! This Unew lives at t^{n+1}\n U(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,lo(3)-ndo:hi(3)+ndo,1:2) = &\n third * U(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,lo(3)-ndo:hi(3)+ndo,1:2) &\n + twothirds * Unew(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,lo(3)-ndo:hi(3)+ndo,1:2) &\n + dt * twothirds * dU(lo(1)-ndo:hi(1)+ndo,lo(2)-ndo:hi(2)+ndo,lo(3)-ndo:hi(3)+ndo,1:2)\n\n deallocate(dU,Unew)\n\n end subroutine advance_3d\n\nend module advance_module\n\n", "meta": {"hexsha": "dcfc4d1439ad2772991cb3f839dd168a6410403f", "size": 8779, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorials/WaveEquation_F/advance.f90", "max_stars_repo_name": "memmett/BoxLib", "max_stars_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Tutorials/WaveEquation_F/advance.f90", "max_issues_repo_name": "memmett/BoxLib", "max_issues_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorials/WaveEquation_F/advance.f90", "max_forks_repo_name": "memmett/BoxLib", "max_forks_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.1595330739, "max_line_length": 101, "alphanum_fraction": 0.440027338, "num_tokens": 3401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404057671714, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7555117297258265}} {"text": "!\r\n! dgv_mod.f90\r\n! \r\n! This module contains subroutines for working with Discontinuous Galerkin velocity discretization. \r\n! It contains definitions and routines for working with the basis functions \r\n! \r\n! Subroutines of this module complement the subroutines of setting up grids and cells and nodes in miscset\r\n!\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\nmodule dgvtools_mod\r\nuse nrtype ! contains kind parameters (DP), (DP), (I4B) etc. \r\n implicit none\r\n\r\n\r\n interface lagrbasfun\r\n module procedure lagrbasfun, lagrbasfun_xvec\r\n end interface\r\n\r\ncontains \r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1\r\n! lagrbasfun\r\n!\r\n! This subroutine evaluates the lagrange basis function given the x and the \r\n! array of nodes kappa\r\n! \r\n! \\Prod_{j\\neq i} \\frac{kappa(j)-x}{kappa(j)-kappa(i)}\r\n!\r\n\r\nfunction lagrbasfun(i,x,kappa) result (y)\r\n\r\ninteger (I4B) :: i ! the number of the node where the lagrange basis function is one. \r\nreal (DP) :: x ! the point where the function needs to be evaluated\r\nreal (DP), dimension(:) :: kappa ! the nodes of the lagrange basis functions\r\nreal (DP) :: y ! the value of the function \r\n!\r\ninteger (I4B) :: j ! some local counter\r\n\r\n\r\n!!!!!!!!!!!!!1\r\n! a quick consistancy check\r\nif ((i<1) .or. (i>size(kappa,1))) then \r\n print *,\" lagrbasfun: error. (i<1) .or. (i>size(kappa,1)) no Lagrange basis function with this number.\"\r\n stop\r\nendif \r\n!\r\ny=1.0_DP\r\ndo j=1,i-1\r\ny = y*(kappa(j)-x)/(kappa(j)-kappa(i))\r\nenddo \r\ndo j=i+1,size(kappa,1)\r\ny = y*(kappa(j)-x)/(kappa(j)-kappa(i))\r\nenddo \r\n\r\nend function lagrbasfun\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! lagrbasfun\r\n!\r\n! This subroutine evaluates the lagrange basis function given the x and the \r\n! array of nodes kappa\r\n! \r\n! \\Prod_{j\\neq i} \\frac{kappa(j)-x}{kappa(j)-kappa(i)}\r\n!\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\nfunction lagrbasfun_xvec(i,x,kappa) result (y)\r\n\r\ninteger (I4B) :: i ! the number of the node where the lagrange basis function is one. \r\nreal (DP), dimension(:) :: x ! the point where the function needs to be evaluated\r\nreal (DP), dimension(:) :: kappa ! the nodes of the lagrange basis functions\r\nreal (DP), dimension(1:size(x,1)) :: y ! the value of the function \r\n!\r\ninteger (I4B) :: j ! some local counter\r\n\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! a quick consistancy check\r\nif ((i<1) .or. (i>size(kappa,1))) then \r\n print *,\" lagrbasfun: error. (i<1) .or. (i>size(kappa,1)) no Lagrange basis function with this number.\"\r\n stop\r\nendif \r\n!\r\ny=1.0_DP\r\ndo j=1,i-1\r\ny = y*(kappa(j)-x)/(kappa(j)-kappa(i))\r\nenddo \r\ndo j=i+1,size(kappa,1)\r\ny = y*(kappa(j)-x)/(kappa(j)-kappa(i))\r\nenddo \r\n\r\nend function lagrbasfun_xvec\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! \r\n! EvalLagrBasisFunByNdsDGblzm\r\n! \r\n! This subroutine evaluates the basis function identified by a node \r\n! for a given a value of velocity. To do this, first the cell is found \r\n! to which this velocity belongs. Then the cell is found to which the basis function belongs and \r\n! the numbers of the 1D-basis functions are identified. Then if the basis function is defined on this \r\n! cell, then the basis function is evaluated using the function lagrbasfun. If the velocity and the \r\n! basis function belong to different cells then the value of the basis function is zero\r\n!\r\n! This function directly uses arrays from commvar.f90. Specifically, grids, cells and nodes.\r\n!\r\n! u,v,w = components of the velocity where the basis function needs to be evaluated. \r\n! \r\n! i = the number of the node associated with this basis function \r\n!\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\nfunction EvalLagrBasisFunByNdsDGblzm(u,v,w,i) result (y)\r\n\r\nuse commvar, only: nodes_pcell, nodes_u, nodes_v, nodes_w,&\r\n\t\t\t\t cells_pgrid, cells_cgrid, cells_lu, cells_lv, cells_lw, & \r\n cells_ru, cells_rv, cells_rw, cells_refu, cells_refv, & \r\n cells_refw, cells_gow, cells_gou, cells_gov, grids_cap_u, &\r\n grids_cap_v,grids_cap_w,grids_u,grids_v,grids_w,g_nds_all, &\r\n nodes_ui, nodes_vi, nodes_wi\r\n\r\nreal (DP) :: u,v,w ! the components of the given velocity\r\ninteger (I4B) :: i ! the number of the node in the nodes array. this the number of the node associated with \r\n ! the given basis function. Thus basis functions may be numbered using nodes... \r\nreal (DP) :: y ! the value of the basis function on the given velocity \r\n\r\n!!!!!!!!!!!!!! \r\ninteger (I4B) :: j ! a counter -- usually denotes the number of the grid we are working on. \r\ninteger (I4B) :: gi_v,gi_u,gi_w ! counters to help count nodes in the grids array\r\ninteger (I4B) :: celli, cellp ! these will store the number of the cell where the velocity belongs and the number of the \r\n ! parent cell where the basis function belongs. \r\ninteger (I4B) :: ui,vi,wi ! are the local numbers on the particular grids where u belongs. Because we have ierarchicval grids, \r\n ! there may be different grids that have ui,vi,wi defined. If one of these numbers is zero -- then the \r\n ! velocity u,v,w is not on the grid. Unless a mistake was done in setting the grids either all three of them \r\n ! are zero -- that means that the velocity is not on this (level zero grid) or all three are non-zero -- means that\r\n ! the velocity has been found. Mized results may indicate a breach in data integrity. \r\n !!!!!\r\ninteger (I4B) :: jj ! a counter\r\nreal (DP) :: unor,vnor,wnor ! scrap variables to store the normalized velus of the components u,v,w \r\n\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1\r\n! first, given a velocity, we need to identify the cell where it came from and its 1D numbers \r\n! we start looking in course cells first. If a cell is found that has that velocity we check if the cell is refined. \r\n! if it is, then we look into the corresponding grid and seek the smaller cell that has it and so on. \r\n!!!!!!!!\r\n!\r\nj=1\r\n!! set up the shift in grids_u/_v/_w corresponding to the first grid (zero shift):\r\ngi_u=0\r\ngi_v=0\r\ngi_w=0\r\ndo while (j<=size(grids_cap_u,1))\r\n call finduiviwi(grids_u(gi_u+1:gi_u+grids_cap_u(j)),grids_v(gi_v+1:gi_v+grids_cap_v(j)),&\r\n grids_w(gi_w+1:gi_w+grids_cap_w(j)),u,v,w,ui,vi,wi)\r\n if (ui*vi*wi /= 0) then \r\n ! now we need to find the cell that correspond to this grid and these ui,vi,wi\r\n celli=1\r\n do jj=1,j-1\r\n celli = celli + (grids_cap_u(jj)-1)*(grids_cap_v(jj)-1)*(grids_cap_w(jj)-1)\r\n end do\r\n celli=celli + (ui-2)*(grids_cap_v(j)-1)*(grids_cap_w(j)-1)+(vi-2)*(grids_cap_w(j)-1)+(wi-2)\r\n ! check if this cell is refined\r\n if ((cells_refu(celli)>1) .or. (cells_refv(celli)>1) .or. (cells_refw(celli)>1)) then \r\n j=cells_cgrid(celli)\r\n ! set up the shift in grids_u/_v/_w corresponding to the j'th grid:\r\n gi_u=0\r\n gi_v=0\r\n gi_w=0\r\n do jj=1,j-1\r\n gi_u = gi_u + grids_cap_u(jj)\r\n gi_v = gi_v + grids_cap_v(jj)\r\n gi_w = gi_w + grids_cap_w(jj)\r\n end do\r\n else \r\n exit\r\n endif\r\n else \r\n celli=0\r\n exit\r\n endif \r\nenddo\r\n! now \"celli\" either is the number of the cell or 0 (0 means that the velocity in not on any cell)\r\n! next step is to find the numbers that will help us compute the value of the basis function\r\n! first we need to know to what cell in u,v,w this basis function belongs. This is simple becasue this \r\n! information is stored in the nodes arrays -- nodes_pcell\r\ncellp=nodes_pcell(i)\r\n! A quick check, if the velocity is not on the cell than the value of the basis function is zero and we are all done\r\nif ((cellp /= celli) .or. (celli == 0)) then \r\ny=0.0_DP\r\n else \r\n! if the velocity is on the cell, then we need to compute the value of $y$:\r\ny=1.0_DP \r\n! next we need to know the three local indices that tell what velocity nodal values correspond to this \r\n! basis function. this is also simple since this information is also stored in the Nodes Arrays.\r\nunor = ( u - (cells_ru(cellp) + cells_lu(cellp))/2.0_DP )/(cells_ru(cellp) - cells_lu(cellp))*2.0_DP \r\ny=y*lagrbasfun(nodes_ui(i),unor,g_nds_all(:cells_gou(cellp),cells_gou(cellp)))\r\n!\r\nvnor = ( v - (cells_rv(cellp) + cells_lv(cellp))/2.0_DP )/(cells_rv(cellp) - cells_lv(cellp))*2.0_DP \r\ny=y*lagrbasfun(nodes_vi(i),vnor,g_nds_all(:cells_gov(cellp),cells_gov(cellp)))\r\n!\r\nwnor = ( w - (cells_rw(cellp) + cells_lw(cellp))/2.0_DP )/(cells_rw(cellp) - cells_lw(cellp))*2.0_DP \r\ny=y*lagrbasfun(nodes_wi(i),wnor,g_nds_all(:cells_gow(cellp),cells_gow(cellp)))\r\n! \r\n!!!!!!!!!!!!\r\nend if\r\n \r\nend function EvalLagrBasisFunByNdsDGblzm\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! \r\n! EvalLagrBasisFunByNdsDGblzmEZ\r\n! \r\n! This subroutine evaluates the basis function identified by a node \r\n! for a given a value of velocity. To do this, first the cell is found \r\n! to which this velocity belongs. We check if the velocity falls within the \r\n! cell where the basis function is defined. The \r\n! numbers of the 1D-basis functions are identified. Then the basis function is \r\n! evaluated using the function lagrbasfun. If the velocity and the \r\n! basis function belong to different cells then the value of the basis function is zero\r\n!\r\n! This function directly uses arrays from commvar.f90. Specifically, grids, cells and nodes.\r\n!\r\n! u,v,w = components of the velocity where the basis function needs to be evaluated. \r\n! \r\n! i = the number of the node associated with this basis function \r\n!\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\nfunction EvalLagrBasisFunByNdsDGblzmEZ(u,v,w,i) result (y)\r\n\r\nuse commvar, only: nodes_pcell, nodes_u, nodes_v, nodes_w,&\r\n\t\t\t\t cells_pgrid, cells_cgrid, cells_lu, cells_lv, cells_lw, & \r\n cells_ru, cells_rv, cells_rw, cells_refu, cells_refv, & \r\n cells_refw, cells_gow, cells_gou, cells_gov, grids_cap_u, &\r\n grids_cap_v,grids_cap_w,grids_u,grids_v,grids_w,g_nds_all, &\r\n nodes_ui, nodes_vi, nodes_wi\r\n\r\nreal (DP) :: u,v,w ! the components of the given velocity\r\ninteger (I4B) :: i ! the number of the node in the nodes array. this the number of the node associated with \r\n ! the given basis function. Thus basis functions may be numbered using nodes... \r\nreal (DP) :: y ! the value of the basis function on the given velocity \r\n\r\n!!!!!!!!!!!!!! \r\ninteger (I4B) :: cellp ! these will store the number of the cell where the velocity belongs and the number of the \r\n ! parent cell where the basis function belongs. \r\nreal (DP) :: lu,ru,lv,rv,lw,rw,unor,vnor,wnor ! scrap variables to store the normalized velus of the components u,v,w \r\n\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1\r\n! first, given the number of the node/basis function, we know the cell where the function belongs:\r\n!!!(rem to restore)!!!cellp= nodes_pcell(i) ! this is the number of the nodes parent cell. \r\n! Now we check is the velocity is within the cell bounds: \r\n!!!(rem to restore)!!!lu=cells_lu(cellp); ru=cells_ru(cellp) \r\n!!!(rem to restore)!!!lv=cells_lv(cellp); rv=cells_rv(cellp) \r\n!!!(rem to restore)!!!lw=cells_lw(cellp); rw=cells_rw(cellp) \r\n!!!(rem to restore)!!!if ((u ugrid(size(ugrid,1)) + epsill)) then \r\n ui=0\r\nelse\r\n ui=1\r\n do while ((u >=ugrid(ui)-epsill) .and. (ui vgrid(size(vgrid,1)) + epsill)) then \r\n vi=0\r\nelse\r\n vi=1\r\n do while ((v >= vgrid(vi)-epsill) .and. (vi wgrid(size(wgrid,1)) + epsill)) then \r\n wi=0\r\nelse\r\n wi=1\r\n do while ((w >= wgrid(wi)-epsill) .and. (wij$. Notice that the case \\xi=\\xi_{i} \r\n! gives value 0.\r\n! \r\n! This subroutine depends on the main program\r\n! \r\n! You should consult the notes n101011.tex for detail on the formulas. \r\n!\r\n! Evaluation of each entry of A involves a two dimensional integral. If the entry is smaller than some given number, \r\n! the entry is neglected/nullified by force\r\n! \r\n! The structure of the arrays related to the operator A: \r\n! A_capphi(i) gives the number of non-zero entries in A(\\xi,\\xi_{1},\\varphi^{j}_{p}) for each basis function with number i\r\n! for each non-zero entry of A this one keeps the index of velocities that produced that non-zero entries. \r\n! A(i) i -- is the index of nonzero entires, we need to use other A-arrrays to restore \r\n! what velocities and wnat basis function this index correcpods \r\n! for example, A_sind_xi(i) gives the first velocity, A_sind_xi1 gives the second velcity\r\n! and A_phi gives the index of the used basis function. \r\n! \r\n! A(\\xi,\\xi_{1};\\varphi^{j}_{p})=\\frac{d^2 |g|}{8} \\int_{0}^{\\pi} \\int_{0}^{2\\pi}\r\n!(\\varphi^{j}_{p}(\\xi')+\\varphi^{j}_{p}(\\xi'_{1}))\r\n! d\\varepsilon\\, \\sin \\chi d \\chi - \\frac{d^2 |g| \\pi }{2} (\\varphi^{j}_{p}(\\xi)+\\varphi^{j}_{p}(\\xi_{1})) \r\n!\r\n! Takes \r\n! Trad === This variable determines the cut off radius for $A$. It should be based on the estimated size of \r\n! ! non-trivial support for the distribution function\r\n! ErrChi == the parameter defining how accurate the evaluation of the integral in Chi should be. \r\n! ErrEps == the parameter defining how accurate the evaluation of the integral in Epsilon should be. \r\n! min_sens == minimum accepted value for A, values below will be neglected\r\n! I1_list == List of basis functions for which A-array is evaluated.\r\n!\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\nsubroutine SetA_DGV\r\nuse commvar, only: nodes_pcell, nodes_u, nodes_v, nodes_w, nodes_ui, nodes_vi, nodes_wi, &\r\n nodes_gwts,A_capphi,A_xi,A_xi1,A_phi,A,&\r\n cells_lu, cells_lv, cells_lw, cells_ru, cells_rv, cells_rw,&\r\n Trad, ErrChi, ErrEps, min_sens, I1_list,Num_OMP_threads\r\n\r\nuse gaussian_mod\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\nreal (DP), parameter :: pi25DT = 3.141592653589793238462643d0\r\ninteger (I4B), parameter :: NdsChi = 10000 ! The max number of cells for integration in chi and epsilon\r\nreal (DP) :: ires_e=100.0_DP ! this parameter will determine the resolution for integration in \\varepsilon\r\nreal (DP) :: ires_t=100.0_DP ! this parameter will determine the resolution in t.\r\n ! the number of points is dictated by the radius of the collision sphere, which is |g|/2\r\n ! the bigger is the radius, the more points is needed to integrate over the sphere.\r\n ! these parameters will represent a lengh of the arc that is desired for application of \r\n ! a gauss quadrature rule. Then the angular intervals will be broken in portions no bigger than \r\n ! ires_t(_e)/|g| to ensure sufficient angular resolution\r\n!!!!!!!!!!!!!!!!!!!!!!\r\nreal (DP), dimension (2*NdsChi) :: NodesChi1, NodesChi2 \r\nreal (DP), dimension (3*NdsChi) :: FuncChi1, FuncChi2 ! Arrays to store cells and functin values on cells Two copies are needed. Integration in Chi\r\ninteger (I4B), dimension (NdsChi) :: CellsChiRef1,CellsChiRef2 ! Arrays to keep refinement flags\r\n!!\r\ninteger (I4B) :: A_ct, phi_ct, loc_alloc_stat ! scrap variables. A_ct is a counter of how many records have been created for A\r\n\t\t\t\t\t\t\t!phi_ct counts how many records have been created for this particular basis function. \r\ninteger (I4B) :: An ! this varable will keep the current size of the array A.\r\ninteger (I4B) :: ni ! this one will keep the size of the nodes array\r\ninteger (I4B) :: i1,i2,i3,d,e ! local counters \r\ninteger (I4B) :: pci ! local integer\r\nreal (DP), dimension (8) :: uu,vv,ww ! coordinates of the 8 vertices of the support of the basis function\r\nreal (DP) :: dphi, dsph ! diameters for the circumscribed sphere for basis function and the collision shpere\r\nreal (DP) :: xiu,xiv,xiw,xi1u,xi1v,xi1w,xiupr,xivpr,&\r\n xiwpr,xi1upr,xi1vpr,xi1wpr,ugu,ugv,ugw ! scrap variables to keep the values of the pre and post collision velocities \r\nreal (DP) :: ugux2,ugvx2,ugwx2,ugux3,ugvx3,ugwx3 ! more screap variables\r\nreal (DP) :: ku,kv,kw ! coordinates of the post-coll g'\r\nreal (DP) :: dist2, g1,g2 ! useful variables \r\ninteger (I4B) :: Nchi1 ! numbers of subdivisions in epsilon and chi\r\nreal (DP) :: Atemp,quad,quad1,quad2,es,my_int1,varphi_xi,varphi_xi1 ! scrap variables.\r\nlogical :: chiadaptflag\r\n!\r\ninteger :: iiii ! a test variable to play with OpenMP runtime functions calls\r\n!!!!!!!!!!!!!!!!!!!!!!!!!! Interface for OpenMP runtime libraries !!!!!!!!!!!!!!!!!!!\r\n!interface \r\n! function omp_get_thread_num() result (y)\r\n! integer :: y \r\n! end function omp_get_thread_num\r\n! function omp_get_num_threads() result (y)\r\n! integer :: y \r\n! end function omp_get_num_threads \r\n! function omp_get_num_procs() result (y)\r\n! integer :: y \r\n! end function omp_get_num_procs\r\n! function omp_get_stack_size () result (y)\r\n! use nrtype\r\n! integer (I2B) :: y\r\n! end function omp_get_stack_size\r\n!end interface \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Initial Allocation of the A-arrays \r\nni=size(nodes_pcell,1)\r\nallocate (A_capphi(1:ni), stat=loc_alloc_stat)\r\n !\r\n if (loc_alloc_stat >0) then \r\n print *, \"SetA_DGV: Allocation error for variable A_capphi\"\r\n stop\r\n end if\r\nAn=10*ni\r\nallocate (A_xi(1:An), A_xi1(1:An), A(1:An), A_phi(1:An), stat=loc_alloc_stat)\r\n !\r\n if (loc_alloc_stat >0) then \r\n print *, \"SetA_DGV: Allocation error for variable A_xi, A_xi1, A_phi or A\"\r\n stop\r\n end if\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\nA_xi=0; A_xi1=0; A=0; A_phi=0; A_capphi=0\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\nA_ct=0 ! in the beginning there is zero records\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n!TEMP: do it just for one velocity nodes: do i1=1,ni ! loop in basis functions \r\ni1=I1_list(1)\r\n!!\r\nphi_ct=0 ! in the beginning there is zero records\r\npci=nodes_pcell(i1)\r\n!\r\nuu(1)=cells_lu(pci); vv(1)=cells_lv(pci); ww(1)=cells_lw(pci) ! the first one holds the lower left left corner\r\nuu(2)=cells_ru(pci); vv(2)=cells_rv(pci); ww(2)=cells_rw(pci) ! the second holds the upper right right corner\r\nuu(3)=cells_lu(pci); vv(3)=cells_lv(pci); ww(3)=cells_rw(pci)\r\nuu(4)=cells_lu(pci); vv(4)=cells_rv(pci); ww(4)=cells_lw(pci)\r\nuu(5)=cells_lu(pci); vv(5)=cells_rv(pci); ww(5)=cells_rw(pci)\r\nuu(6)=cells_ru(pci); vv(6)=cells_lv(pci); ww(6)=cells_lw(pci)\r\nuu(7)=cells_ru(pci); vv(7)=cells_lv(pci); ww(7)=cells_rw(pci)\r\nuu(8)=cells_ru(pci); vv(8)=cells_rv(pci); ww(8)=cells_lw(pci)\r\ndphi = sqrt((uu(2)-uu(1))**2+(vv(2)-vv(1))**2+(ww(2)-ww(1))**2)\r\n!! we set the resolution parameters based on the size of the velocity cell.\r\nires_t = max(uu(2)-uu(1),vv(2)-vv(1),ww(2)-ww(1))/32\r\nires_e = ires_t\r\n!!!\r\n! Add openMP parallel directives here.... \r\n!!!\r\n! iiii=omp_get_num_procs\r\n! OpenMP set the number of threads: \r\n\r\n!call omp_set_num_threads(Num_OMP_threads)\r\n!$OMP PARALLEL DO PRIVATE(xiu,xiv,xiw,xi1u,xi1v,xi1w,dsph,dist2,ugu,ugv,ugw, & \r\n!$OMP ugux2,ugvx2,ugwx2,ugux3,ugvx3,ugwx3,g1,g2,Nchi1,NodesChi1,FuncChi1,d, & \r\n!$OMP CellsChiRef1,Atemp,ChiAdaptFlag,my_int1,NodesChi2,FuncChi2,CellsChiRef2,e, &\r\n!$OMP quad,quad1,quad2,es,i2,i3,iiii,varphi_xi,varphi_xi1) NUM_THREADS(Num_OMP_threads) &\r\n!$OMP SCHEDULE(DYNAMIC, 5) \r\ndo i2=1,ni ! loop in velocity 1\r\n!!!!\r\n xiu=nodes_u(i2); xiv=nodes_v(i2); xiw=nodes_w(i2)\r\n varphi_xi = EvalLagrBasisFunByNdsDGblzmEZ(xiu,xiv,xiw,i1) ! this is the value of the basis function on the first velocity -- will be passed to integrator\r\ndo i3=i2+1,ni ! loop in velocity 2\r\n xi1u=nodes_u(i3); xi1v=nodes_v(i3); xi1w=nodes_w(i3)\r\n varphi_xi1 = EvalLagrBasisFunByNdsDGblzmEZ(xi1u,xi1v,xi1w,i1) ! this is the value of the basis function on the second velocity -- -- will be passed to integrator\r\n!!!!!!!!!!!! evaluation of A !!!!!!!!!!!!!!!\r\n ! evaluate the diamieter of the collision sphere and the double distance from the center of the basis function support to the center of the collision sphere\r\n dsph = sqrt((xiu-xi1u)**2+(xiv-xi1v)**2+(xiw-xi1w)**2)\r\n dist2 = sqrt((xiu+xi1u-uu(1)-uu(2))**2+(xiv+xi1v-vv(1)-vv(2))**2+(xiw+xi1w-ww(1)-ww(2))**2)\r\n ! Now we calculate some useful quantities:\r\n ugu = (xiu-xi1u)/dsph ! need to introduce a unit vector in the direction of g\r\n ugv = (xiv-xi1v)/dsph \r\n ugw = (xiw-xi1w)/dsph\r\n ! The components of the vector (ugu,ugv,ugw) should be orthogonal to vecotor g. \r\n ! there is only one case when these componets are degenerate. is it when g is parallel to (1,1,1)\r\n ! in this case, we need to cook a non-trivial vecotor. The next if statement takes case of that: \r\n if (abs(ugw-ugv)+abs(ugu-ugw)+abs(ugv-ugu) < 1.0d-6) then \r\n ! first, we create two orthogonal non-trivial vectors\r\n ugux2 = ugv \r\n ugvx2 = -ugu \r\n ugwx2 = 0\r\n ugux3 = ugu*ugw\r\n ugvx3 = ugv*ugw\r\n ugwx3 = -(ugu)**2-(ugv)**2\r\n ! \r\n g1=sqrt(ugux2**2+ugvx2**2)\r\n g2=sqrt(ugux3**2+ugvx3**2+ugwx3**2)\r\n !\r\n else \r\n !first we create the components of two non-trivial orthogonal vectors: \r\n ugux2 = (ugw-ugv)\r\n ugvx2 = (ugu-ugw)\r\n ugwx2 = (ugv-ugu)\r\n ugux3 = ((ugv)**2-(ugv)*(ugu)-(ugw)*(ugu)+(ugw)**2)\r\n ugvx3 = ((ugw)**2-(ugw)*(ugv)-(ugu)*(ugv)+(ugu)**2)\r\n ugwx3 = ((ugu)**2-(ugu)*(ugw)-(ugv)*(ugw)+(ugv)**2)\r\n ! \r\n g1 = sqrt(ugux2**2 + ugvx2**2 + ugwx2**2)\r\n g2 = sqrt(ugux3**2+ugvx3**2+ugwx3**2)\r\n end if\r\n! First we estimate if A is zero by cheking the overlap of spheres\r\n if ((dist2 > dsph+dphi) .or. (dist2+dphi < dsph) .or. (dsph > Trad)) then \r\n cycle ! collision shpere does not hit the support of the basis function continue with the next velocity\r\n ! or the collision shpere is so large that it is not possible for distribution function to be nonzero for both velocities \r\n end if \r\n ! if we got here then the collision sphere has some possible overlap with the support of basis function\r\n ! To evaluate the integral, we will implement adaptive quadrature in both directions using Simpson's rule. \r\n !\r\n ! begin integration in \\chi\r\n ! first, we set up the initial mesh\r\n Nchi1=FLOOR(pi25DT*dsph/ires_t/2.0_DP)+1\r\n if (Nchi1>NdsChi) then \r\n Nchi1=NdsChi\r\n print *,\"SetA_DGV: Warning! Number of nodes (NdsChi) for integration in epsilon gives insufficient resolution\" \r\n end if \r\n ! we set the initial mesh\r\n do d=1,Nchi1\r\n NodesChi1(2*(d-1)+1)=(d-1)*pi25DT/Real(Nchi1,DP)\r\n NodesChi1(2*d)=d*pi25DT/Real(Nchi1,DP)\r\n end do\r\n ! now we evaluate the integrand on the initial mesh\r\n FuncChi1=0\r\n do d=1,Nchi1\r\n ! each d gives one cell\r\n ! First, we evaluate the integrand on the left node of the cell\r\n if ((d>1) .and. (NodesChi1(2*d-1) == NodesChi1(2*d-2))) then \r\n FuncChi1(3*d-2)= FuncChi1(3*d-3) ! if the node is repeating, the value has been computed already\r\n else \r\n FuncChi1(3*d-2) = A_IntEpsilon(NodesChi1(2*d-1),ires_e,xiu,xiv,xiw,xi1u,xi1v,xi1w,ugu,ugv,ugw,ugux2,ugvx2,ugwx2,&\r\n ugux3,ugvx3,ugwx3,g1,g2,dsph,i1,ErrEps,varphi_xi,varphi_xi1)\r\n end if\r\n ! This takes care of the left node in the cell... \r\n ! \r\n !Now we evaluate the solution on the right node of the cell and at the center. \r\n FuncChi1(3*d) = A_IntEpsilon(NodesChi1(2*d),ires_e,xiu,xiv,xiw,xi1u,xi1v,xi1w,ugu,ugv,ugw,ugux2,ugvx2,ugwx2,&\r\n ugux3,ugvx3,ugwx3,g1,g2,dsph,i1,ErrEps,varphi_xi,varphi_xi1)\r\n FuncChi1(3*d-1) = A_IntEpsilon((NodesChi1(2*d-1) + NodesChi1(2*d))/2.0_DP,ires_e,xiu,xiv,xiw,xi1u,xi1v,xi1w,&\r\n ugu,ugv,ugw,ugux2,ugvx2,ugwx2,ugux3,ugvx3,ugwx3,g1,g2,dsph,i1,ErrEps,varphi_xi,varphi_xi1)\r\n ! repeat for all cells... \r\n end do \r\n ! finally, we mark all cells for the refinement in the beginning... \r\n CellsChiRef1=0 \r\n CellsChiRef1(1:Nchi1)=1\r\n ! \r\n !Next we adaptively refine and evaluate the integral: \r\n Atemp=0\r\n ChiAdaptFlag =.true.\r\n my_int1 = 100*ErrChi ! initialize with something big for the intial iteration. \r\n do while (ChiAdaptFlag)\r\n ChiAdaptFlag =.false.\r\n ! Now we will go over the array of the integrand values and will cross \r\n ! out cells where the integrand is zero, and those that are not marked for the refinment \r\n ! on those cells we summ the integrand and keep the sum.\r\n ! Cells marked for the refinement we divide into halves \r\n NodesChi2=0\r\n FuncChi2=0\r\n CellsChiRef2=0\r\n e=0\r\n if (my_int1>ErrChi) then ! this checks that the integral over the mesh NodesChi1 will be small anyway\r\n my_int1=0 ! this will keep the estimate of the integral on the mesh NodesChi1 so that we stop resolving when this number is small\r\n do d=1,Nchi1\r\n if ((abs(FuncChi1(3*d-2))+abs(FuncChi1(3*d-1))+abs(FuncChi1(3*d)) > 1.0d-15) .and. (CellsChiRef1(d)==1)) then \r\n if (e > NdsChi-2) then \r\n print *,\"SetA_DGV: Number of nodes in chi is too big (e>NdsChi-2)\"\r\n stop\r\n end if\r\n ! save the nodes and the integrand values\r\n NodesChi2(2*e+1)=NodesChi1(2*d-1)\r\n FuncChi2(3*e+1)=FuncChi1(3*d-2)\r\n NodesChi2(2*e+4)=NodesChi1(2*d)\r\n FuncChi2(3*e+6)=FuncChi1(3*d)\r\n ! Evaluate the midpoint node: \r\n NodesChi2(2*e+2)=(NodesChi1(2*d-1)+NodesChi1(2*d))/2\r\n NodesChi2(2*e+3)=NodesChi2(2*e+2)\r\n ! Save the midpoint value of the integrand:\r\n FuncChi2(3*e+3)=FuncChi1(3*d-1)\r\n FuncChi2(3*e+4)=FuncChi2(3*e+3)\r\n ! Evaluate the integrand on the new nodes\r\n FuncChi2(3*e+2) = A_IntEpsilon((NodesChi2(2*e+2)+NodesChi2(2*e+1))/2.0_DP,ires_e,xiu,xiv,xiw,xi1u,xi1v,xi1w,ugu,ugv,&\r\n ugw,ugux2,ugvx2,ugwx2,ugux3,ugvx3,ugwx3,g1,g2,dsph,i1,ErrEps,varphi_xi,varphi_xi1)\r\n FuncChi2(3*e+5) = A_IntEpsilon((NodesChi2(2*e+4)+NodesChi2(2*e+3))/2.0_DP,ires_e,xiu,xiv,xiw,xi1u,xi1v,xi1w,ugu,ugv,&\r\n ugw,ugux2,ugvx2,ugwx2,ugux3,ugvx3,ugwx3,g1,g2,dsph,i1,ErrEps,varphi_xi,varphi_xi1)\r\n ! Now it is time to compare the quadratures and to mark cells for the refinement \r\n quad = (FuncChi1(3*d-2)+4*FuncChi1(3*d-1)+FuncChi1(3*d))*(NodesChi1(2*d)-NodesChi1(2*d-1))/6\r\n quad1 = (FuncChi2(3*e+1)+4*FuncChi2(3*e+2)+FuncChi2(3*e+3))*(NodesChi2(2*e+2)-NodesChi2(2*e+1))/6\r\n quad2 = (FuncChi2(3*e+4)+4*FuncChi2(3*e+5)+FuncChi2(3*e+6))*(NodesChi2(2*e+4)-NodesChi2(2*e+3))/6\r\n es = abs(quad1+quad2-quad)/15/(NodesChi1(2*d)-NodesChi1(2*d-1)) ! error indicator\r\n my_int1=my_int1+abs(quad1)+abs(quad2) ! this quantity estimates the integral over the entire mesh NodesChi2 that will be NodesChi1 soon.. \r\n if (es > ErrChi) then \r\n ChiAdaptFlag = .true.\r\n CellsChiRef2(e+1) = 1\r\n CellsChiRef2(e+2) = 1\r\n else\r\n CellsChiRef2(e+1) = 0\r\n CellsChiRef2(e+2) = 0\r\n Atemp = Atemp + quad1 + quad2 \r\n end if\r\n e=e+2\r\n ! end refinement \r\n end if \r\n end do \r\n !\r\n end if ! end of the check that the integral over the mesh NodesChi1 will be small anyway\r\n ! Finally, we need to replace the first mesh with the refined mesh \r\n FuncChi1=0\r\n FuncChi1=FuncChi2\r\n NodesChi1=0\r\n NodesChi1=NodesChi2\r\n CellsChiRef1=0\r\n CellsChiRef1=CellsChiRef2\r\n Nchi1=e\r\n end do\r\n !!!!!!!!!!!!!!!!!! Looks like we are done with the integration in chi !!!!! \r\n ! now it is time to check if the value of A is non-zero. If it is bigger than some specified level of \r\n ! minimum sensitivity, then is it added to storage, Otherwise we continue to the next velocity #2.\r\n if ( ABS(Atemp) > min_sens ) then \r\n!$omp critical \r\n A_ct = A_ct+1 ! we count the record for A\r\n phi_ct=phi_ct + 1 ! we count the record for this basis function. \r\n if (An < A_ct) then\r\n call ExtendAarraysDGV(An,ni)\r\n end if \r\n ! now we need to add the volume elements for xi and xi1 \r\n ! ATTENTION: molecular diameter mol_diam is removed in the dimensionless formulation)\r\n ! ATTENTION: for evaluation of A operator using the dimensional code use mol_diam = 1.0:\r\n ! ATTENTION: OLD (dimenional) code Atemp = Atemp*mod_diam^2*(nodes_gwts(i3))**(nodes_gwts(i2))\r\n ! Dimensionless code. Molecular diamter is accounted for in the spatial operator. \r\n ! xi1:\r\n Atemp = Atemp*(nodes_gwts(i3)) ! this takes care of the volume elements and the weight for xi1 \r\n ! xi\t\t\t\r\n Atemp = Atemp*(nodes_gwts(i2)) ! this takes care of the volume elements and the weight for xi \r\n !\t\t\r\n dsph=dsph/8.0_DP ! this takes care of the fraction 1/8 still need to add |g|\r\n A(A_ct) = Atemp*dsph ! this takes care of |g|/8\r\n A_xi(A_ct) = i2\r\n A_xi1(A_ct) = i3 \r\n A_phi(A_ct) = i1\r\n!!\r\n!iiii = omp_get_thread_num()\r\n!print *, \"I2=\", i2, \"Thread\", iiii, \"A_ct=\", A_ct, i3 \r\n!$omp end critical \r\n end if \r\n!!!!!!!!!!!! end evaluation of A !!!!!!!!!!!\r\nend do ! END LOOP in I3\r\n! add this two lines to track progress and Print a hello message to Check if parallel stuff worked... !!!!\r\n!iiii = omp_get_thread_num()\r\n!print *, \"I2=\", i2, \"Thread\", iiii, \"A_ct=%i8\", A_ct \r\n! \r\nend do ! END LOOP IN I2\r\nA_capphi(i1)=phi_ct\r\nprint *, \"Set_A i1=\", i1, \"A_ct=\", A_ct\r\n!! end do !! TEMPORARY do it for just one node... \r\n!!!!!!!!!!!!\r\ncall ShrinkAarraysDGV(A_ct)\r\n!!!!!!!!!!!!\r\nend subroutine SetA_DGV\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! ExtendAarraysDGV(An,ni)\r\n!\r\n! This subroutine extends arrays A, A_phi,A_xi,A_xi1 for additional ni records\r\n\r\nsubroutine ExtendAarraysDGV(An,ni)\r\n\r\nuse commvar, only: A,A_phi,A_xi,A_xi1\r\n\r\ninteger (I4B), intent (out) :: An ! An is the length of the arrays that will be updated. \r\ninteger (I4B), intent (in) :: ni ! ni is the number of records to add\r\n\r\n!!!\r\nreal (DP), dimension (:), allocatable :: A_rscr ! scrap array\r\ninteger (I4B) , dimension (:), allocatable :: A_iscr ! integer scrap array\r\ninteger (I4B) :: nn ! scrap variable\r\n!\r\ninteger (I4B) :: loc_alloc_stat\r\n!\r\nnn=size(A,1)\r\nAn=nn+ni\r\n! extending A ... \r\nallocate (A_rscr(1:nn), stat=loc_alloc_stat)\r\n !\r\n if (loc_alloc_stat >0) then \r\n print *, \"ExtendAarraysDGV: Allocation error for variable A_rscr, nn=\", nn\r\n stop\r\n end if\r\nA_rscr=A\r\ndeallocate(A)\r\nallocate (A(1:nn+ni), stat=loc_alloc_stat)\r\n !\r\n if (loc_alloc_stat >0) then \r\n print *, \"ExtendAarraysDGV: Allocation error for variable A, nn=\", nn+ni\r\n stop\r\n end if\r\nA(1:nn)=A_rscr\r\ndeallocate(A_rscr)\r\n! end extending A\r\n\r\n! extending A_xi\r\nallocate(A_iscr(1:nn), stat=loc_alloc_stat)\r\n !\r\n if (loc_alloc_stat >0) then \r\n print *, \"ExtendAarraysDGV: Allocation error for variable A_iscr, nn=\", nn\r\n stop\r\n end if\r\nA_iscr=A_xi\r\ndeallocate(A_xi)\r\nallocate (A_xi(1:nn+ni), stat=loc_alloc_stat)\r\n !\r\n if (loc_alloc_stat >0) then \r\n print *, \"ExtendAarraysDGV: Allocation error for variable A_xi, nn=\", nn+ni\r\n stop\r\n end if\r\nA_xi(1:nn)=A_iscr\r\n! extending A_xi1\r\nA_iscr=A_xi1\r\ndeallocate(A_xi1)\r\nallocate (A_xi1(1:nn+ni), stat=loc_alloc_stat)\r\n !\r\n if (loc_alloc_stat >0) then \r\n print *, \"ExtendAarraysDGV: Allocation error for variable A_xi1, nn=\", nn+ni\r\n stop\r\n end if\r\nA_xi1(1:nn)=A_iscr\r\n!extending A_phi\r\nA_iscr=A_phi\r\ndeallocate(A_phi)\r\nallocate (A_phi(1:nn+ni), stat=loc_alloc_stat)\r\n !\r\n if (loc_alloc_stat >0) then \r\n print *, \"ExtendAarraysDGV: Allocation error for variable A_phi, nn=\", nn+ni\r\n stop\r\n end if\r\nA_phi(1:nn)=A_iscr\r\n! end extending A_phi\r\ndeallocate(A_iscr)\r\n\r\nend subroutine ExtendAarraysDGV\r\n\r\nsubroutine ShrinkAarraysDGV(ni)\r\n\r\nuse commvar, only: A,A_phi,A_xi,A_xi1\r\n\r\ninteger (I4B), intent (in) :: ni ! ni is the new size of the arrays to be shrunk\r\n\r\n!!!\r\nreal (DP), dimension (:), allocatable :: A_rscr ! scrap array\r\ninteger (I4B), dimension (:), allocatable :: A_iscr ! integer scrap array\r\n!\r\ninteger (I4B) :: loc_alloc_stat \r\n\r\n! shrinking A ... \r\nallocate (A_rscr(1:ni), stat=loc_alloc_stat)\r\n !\r\n if (loc_alloc_stat >0) then \r\n print *, \"ShrinkAarraysDGV: Allocation error for variable A_rscr, nn=\", ni\r\n stop\r\n end if\r\nA_rscr=A(1:ni)\r\ndeallocate(A)\r\nallocate (A(1:ni), stat=loc_alloc_stat)\r\n !\r\n if (loc_alloc_stat >0) then \r\n print *, \"ShrinkAarraysDGV: Allocation error for variable A, nn=\", ni\r\n stop\r\n end if\r\nA=A_rscr\r\ndeallocate(A_rscr)\r\n! end shrinking A\r\n\r\n! shrinking A_xi\r\nallocate (A_iscr(1:ni), stat=loc_alloc_stat)\r\n !\r\n if (loc_alloc_stat >0) then \r\n print *, \"ShrinkAarraysDGV: Allocation error for variable A_iscr, nn=\", ni\r\n stop\r\n end if\r\nA_iscr=A_xi(1:ni)\r\ndeallocate(A_xi)\r\nallocate (A_xi(1:ni), stat=loc_alloc_stat)\r\n !\r\n if (loc_alloc_stat >0) then \r\n print *, \"ShrinkAarraysDGV: Allocation error for variable A_xi, nn=\", ni\r\n stop\r\n end if\r\nA_xi=A_iscr\r\n! extending A_xi1\r\nA_iscr=A_xi1(1:ni)\r\ndeallocate(A_xi1)\r\nallocate (A_xi1(1:ni), stat=loc_alloc_stat)\r\n !\r\n if (loc_alloc_stat >0) then \r\n print *, \"ShrinkAarraysDGV: Allocation error for variable A_xi1, nn=\", ni\r\n stop\r\n end if\r\nA_xi1=A_iscr\r\n!extending A_phi\r\nA_iscr=A_phi(1:ni)\r\ndeallocate(A_phi)\r\nallocate (A_phi(1:ni), stat=loc_alloc_stat)\r\n !\r\n if (loc_alloc_stat >0) then \r\n print *, \"ShrinkAarraysDGV: Allocation error for variable A_phi, nn=\", ni\r\n stop\r\n end if\r\nA_phi=A_iscr\r\n! end extending A_phi\r\ndeallocate(A_iscr)\r\nend subroutine ShrinkAarraysDGV\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1\r\n! IphiDGV\r\n!\r\n! This subroutine evaluates the moment of the collision integral for basis functions. \r\n! The basis functions are defined for each velocity node. The Collision Information Operator\r\n! is calculated for all (or few basis functions). \r\n! The subroutine will take calculate the moment for each basis function recorded in A\r\n!\r\n! Depends on the main program. A-arrays must be defined as well as the disftribution function f\r\n! \r\n!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\nfunction IphiDGV(f) result (Iphi)\r\n\r\nuse commvar, only: A,A_capphi,A_xi,A_xi1,A_phi,nodes_gwts,mol_diam,L_inf,N_inf\r\n\r\nreal (DP), dimension(:) :: f ! the main variable -- distribution function -- one component for each velocity node\r\nreal (DP), dimension (size(A_capphi,1)) :: Iphi ! the result of integration\r\nreal (DP), dimension(:), allocatable :: A_SP, F_SP\r\n!!! \r\ninteger (I4B) :: i,j, A_ct,my_count ! scrap variables,\r\n!!!\r\nallocate (A_SP(size(A,1)), F_SP(size(f,1)))\r\nA_SP = A\r\nf_SP = f\r\n!!!\r\nmy_count=0\r\nIphi=0\r\nA_ct=0\r\ndo i=1,size(A_capphi,1) ! loop in basis functions --- one node=one basis function\r\n Iphi(i)=0\r\n do j=1+A_ct,A_ct+A_capphi(i)\r\n Iphi(i)=Iphi(i)+A_SP(j)*f_SP(A_xi(j))*f_SP(A_xi1(j))\r\n if (ABS(A_SP(j)*f_SP(A_xi(j))*f_SP(A_xi1(j)))<1.0d-8) then \r\n my_count=my_count+1\r\n end if \r\n end do \r\n Iphi(i)=2*Iphi(i)/nodes_gwts(i)*((mol_diam/L_inf)**2*N_inf)\r\n A_ct=A_ct+A_capphi(i)\r\nend do \r\n!\r\ndeallocate (A_SP, f_SP)\r\nend function IphiDGV\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1\r\n! IphiDGV_decomp\r\n!\r\n! This is a diagnistics subroutine \r\n!\r\n! This subroutine evaluates the moment of the collision integral for basis functions. \r\n! using the decomposition method. It is to test the advantage of decomposition -- if any \r\n! the solution is split into a maxwellian adn the rest. The collision operator is evcaluated.\r\n! The basis functions are defined for each velocity node. The Collision Information Operator\r\n! is calculated for all (or few basis functions). \r\n! The subroutine will take calculate the moment for each basis function recorded in A\r\n!\r\n! Depends on the main program. A-arrays must be defined as well as the disftribution function f\r\n! \r\n!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\nfunction IphiDGV_decomp(f) result (Iphi)\r\n\r\nuse commvar, only: A,A_capphi,A_xi,A_xi1,A_phi,nodes_gwts,mol_diam,L_inf,N_inf,nodes_u, nodes_v, nodes_w\r\n\r\nuse distributions_mod\r\n\r\n\r\n\r\nreal (DP), dimension(:) :: f ! the main variable -- distribution function -- one component for each velocity node\r\nreal (DP), dimension (size(A_capphi,1)) :: Iphi ! the result of integration\r\n\r\n!!! \r\ninteger (I4B) :: i,j, A_ct ! scrap variables,\r\nreal (DP), dimension(size(f,1)) :: fmaxwellNew,Df\r\nreal (DP) :: LocDens,LocUbar,LocVbar,LocWbar,LocTempr \r\n!!!!!!!\r\ncall MassCheckRec (f,LocDens,LocUbar,LocVbar,LocWbar,LocTempr) ! First, we evaluate the macroparamters of the solution.\r\nfMaxwellNew = maxwelveldist(LocTempr,LocUbar,LocVbar,LocWbar,LocDens,nodes_u, nodes_v, nodes_w) ! now we populate the maxwellian with the same macroparamters.\r\nDf=f-fMaxwellNew ! evaluate the perturbation from the maxwellian. \r\n\r\nIphi=0\r\nA_ct=0\r\ndo i=1,size(A_capphi,1) ! loop in basis functions --- one node=one basis function\r\n Iphi(i)=0\r\n do j=1+A_ct,A_ct+A_capphi(i)\r\n Iphi(i)=Iphi(i) + A(j)*fMaxwellNew(A_xi(j))*Df(A_xi1(j))+A(j)*Df(A_xi(j))*fMaxwellNew(A_xi1(j)) + A(j)*Df(A_xi(j))*Df(A_xi1(j))\r\n end do \r\n Iphi(i)=2*Iphi(i)/nodes_gwts(i)*((mol_diam/L_inf)**2*N_inf)\r\n A_ct=A_ct+A_capphi(i)\r\nend do \r\n!\r\nend function IphiDGV_decomp\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n!!!!!!!!!!!!!!!\r\n!EvalPhiPostCollIntegrand\r\n!\r\n! This function helps to calculate the post collision velocities and calls evaluation of the basis function\r\n! on the post collision velocitis. The function is mainly to help coding -- to reduce the number of repeating lines. \r\n!\r\n!\r\n\r\nfunction EvalPhiPostCollIntegrand(xiu,xiv,xiw,xi1u,xi1v,xi1w,ugu,ugv,ugw,ugux2,ugvx2,ugwx2,&\r\n ugux3,ugvx3,ugwx3,epsil,sinchi,coschi,g1,g2,dsph,i1,varphi_xi,varphi_xi1) result (y)\r\n!\r\n!\r\nreal (DP), intent (in) :: sinchi, coschi, g1,g2 ! some useful numbers \r\nreal (DP), intent (in) :: ugu,ugv,ugw,ugux2,ugvx2,ugwx2,ugux3,ugvx3,ugwx3 ! useful coefficients\r\nreal (DP), intent (in) :: epsil ! the angle for which the integral must be evaluated.\r\nreal (DP), intent (in) :: dsph,xiu,xiv,xiw,xi1u,xi1v,xi1w ! the pre-collision velocities \r\ninteger (I4B), intent (in) :: i1 ! the number of the basis fucntion to evaluate\r\nreal (DP), intent (in) :: varphi_xi,varphi_xi1 ! the values of the basis function on xi and xi1\r\nreal (DP) :: y ! the result\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\nreal (DP) :: sinchicoseps, sinchisineps ! useful quantities\r\nreal (DP) :: xiupr,xivpr,xiwpr,xi1upr,xi1vpr,xi1wpr ! components of post-collision velocity\r\nreal (DP) :: z,ku,kv,kw ! compoents of the unit vector in the direction of post collision relative speed\r\n!!!!!!\r\n sinchicoseps = cos(epsil)*sinchi/g1\r\n sinchisineps = sin(epsil)*sinchi/g2\r\n ! Now it is time to evaluate post-collision velocities... \r\n ! First we evaluate the direction of $g'$ : \r\n ku = (ugu)*coschi - ugux2*sinchicoseps - ugux3*sinchisineps\r\n kv = (ugv)*coschi - ugvx2*sinchicoseps - ugvx3*sinchisineps\r\n kw = (ugw)*coschi - ugwx2*sinchicoseps - ugwx3*sinchisineps\r\n ! Now we calculate the post collision velocities: \r\n !\r\n xiupr=((xiu + xi1u) + dsph*ku)/2.0_DP\r\n xi1upr=((xiu + xi1u) - dsph*ku)/2.0_DP\r\n xivpr=((xiv + xi1v) + dsph*kv)/2.0_DP\r\n xi1vpr=((xiv + xi1v) - dsph*kv)/2.0_DP\r\n xiwpr=((xiw + xi1w) + dsph*kw)/2.0_DP\r\n xi1wpr=((xiw + xi1w) - dsph*kw)/2.0_DP\r\n\r\n ! now we evaluate basis the basis functions on these velocities \r\n z = EvalLagrBasisFunByNdsDGblzmEZ(xiupr,xivpr,xiwpr,i1) + &\r\n EvalLagrBasisFunByNdsDGblzmEZ(xi1upr,xi1vpr,xi1wpr,i1) - varphi_xi - varphi_xi1 \r\n y=z \r\nend function EvalPhiPostCollIntegrand \r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! A_IntEpsilon\r\n! This function is to shorten the code. It is pretty much a piece of code that is cut out\r\n! and paste in the form of a function to make the rest of the code read easier. \r\n! This portion implements the integration in \\varepsilon in the evaluation of operator A\r\n!\r\n! This code evaluates \\sin\\chi \\int_{0}^{2\\pi} (\\varphi(\\xi')+\\varphi(\\xi'_{1}) d\\varepsilon \r\n!\r\n!\r\n! The result is the integral for this particular angle \\chi\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\nfunction A_IntEpsilon(chi,ires_e,xiu,xiv,xiw,xi1u,xi1v,xi1w,ugu,ugv,ugw,ugux2,ugvx2,ugwx2,&\r\n ugux3,ugvx3,ugwx3,g1,g2,dsph,i1,ErrEps,varphi_xi,varphi_xi1) result (y)\r\n \r\nreal (DP), intent (in) :: chi,g1,g2,ires_e ! some useful numbers \r\nreal (DP), intent (in) :: ugu,ugv,ugw,ugux2,ugvx2,ugwx2,ugux3,ugvx3,ugwx3 ! useful coefficients\r\nreal (DP), intent (in) :: dsph,xiu,xiv,xiw,xi1u,xi1v,xi1w ! the pre-collision velocities \r\ninteger (I4B) :: i1 ! the number of the basis function which is to evaluate. \r\nreal (DP), intent (in) :: ErrEps ! the max set error of integral evauation. \r\nreal (DP), intent (in) :: varphi_xi,varphi_xi1 ! the values of the basis function on xi and xi1\r\n!\r\nreal (DP) :: y ! the result\r\n \r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!\r\nreal (DP) :: sinchi,coschi ! useful scrap constants to remember..\r\nreal (DP), parameter :: pi25DT = 3.141592653589793238462643d0 \r\ninteger (I4B), parameter :: NdsEps=10000 ! The max number of cells for integration in chi and epsilon\r\n\r\nreal (DP), dimension (2*NdsEps) :: NodesEps1, NodesEps2\r\nreal (DP), dimension (3*NdsEps) :: FuncEps1, FuncEps2 ! Arrays to store cells and functin values on cells Two copies are needed. Integration in Eps\r\ninteger (I4B), dimension (NdsEps) :: CellsEpsRef1,CellsEpsRef2 ! Arrays to keep refinement flags\r\nreal (DP) :: Atemp_temp,quad,quad1,quad2,es,my_int1 ! scrap variables.\r\n!!!!!\r\ninteger (I4B) :: Neps1,g ! variables to keep the number of integration cells\r\ninteger (I4B) :: f ! local counter\r\nlogical :: EpsAdaptFlag ! a logical variable to tell if any of the refinements need to be done. \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n sinchi=sin(chi) ! will be useful to remember this one... \r\n coschi=cos(chi) ! will be useful to remember this one too... \r\n! Begin Integration in epsilon ... \r\n Neps1=FLOOR(pi25DT*dsph*sinchi/ires_e)+1\r\n if (Neps1>NdsEps) then \r\n Neps1=NdsEps\r\n print *,\"SetA_DGV: Warning! Number of nodes (NdsEps) for integration in epsilon gives insufficient resolution\" \r\n end if \r\n ! we set the initial mesh\r\n do f=1,Neps1\r\n NodesEps1(2*(f-1)+1)=(f-1)*2*pi25DT/Real(Neps1,DP)\r\n NodesEps1(2*f)=f*2*pi25DT/Real(Neps1,DP)\r\n end do\r\n ! now we evaluate the integrand on the initial mesh\r\n FuncEps1=0\r\n do f=1,Neps1\r\n ! each f gives one cell\r\n ! First, we evaluate the integrand on the left node of the cell\r\n if ((f>1) .and. (NodesEps1(2*f-1) == NodesEps1(2*f-2))) then \r\n FuncEps1(3*f-2)= FuncEps1(3*f-3) ! if the node is repeating, the value has been computed already\r\n else \r\n FuncEps1(3*f-2) = EvalPhiPostCollIntegrand(xiu,xiv,xiw,xi1u,xi1v,xi1w,ugu,ugv,ugw,ugux2,ugvx2,ugwx2,&\r\n ugux3,ugvx3,ugwx3,NodesEps1(2*f-1),sinchi,coschi,g1,g2,dsph,i1,varphi_xi,varphi_xi1) \r\n end if\r\n ! This takes care of the left node in the cell... \r\n ! \r\n !Now we evaluate the solution on the right node of the cell and at the center. \r\n FuncEps1(3*f) = EvalPhiPostCollIntegrand(xiu,xiv,xiw,xi1u,xi1v,xi1w,ugu,ugv,ugw,ugux2,ugvx2,ugwx2,&\r\n ugux3,ugvx3,ugwx3,NodesEps1(2*f),sinchi,coschi,g1,g2,dsph,i1,varphi_xi,varphi_xi1) \r\n FuncEps1(3*f-1) = EvalPhiPostCollIntegrand(xiu,xiv,xiw,xi1u,xi1v,xi1w,ugu,ugv,ugw,ugux2,ugvx2,ugwx2,&\r\n ugux3,ugvx3,ugwx3,(NodesEps1(2*f)+NodesEps1(2*f-1))/2,sinchi,coschi,g1,g2,dsph,i1,varphi_xi,varphi_xi1)\r\n ! repeat for all cells... \r\n end do \r\n ! finally, we mark all cells for the refinement in the beginning... \r\n CellsEpsRef1=0 \r\n CellsEpsRef1(1:Neps1)=1\r\n ! \r\n !Next we adaptively refine and evaluate the integral: \r\n my_int1=10*ErrEps !! set it to a large number fo the rist run\r\n EpsAdaptFlag =.true.\r\n Atemp_temp=0\r\n do while (EpsAdaptFlag)\r\n EpsAdaptFlag =.false.\r\n ! Now we will go over the array of the integrand values and will cross \r\n ! out cells where the integrand is zero, and those that are not marked for the refinment \r\n ! on those cells we summ the integrand and keep the sum.\r\n ! Cells marked for the refinement we divide into halves \r\n NodesEps2=0\r\n FuncEps2=0\r\n CellsEpsRef2=0\r\n g=0\r\n if (my_int1 > ErrEps) then ! check is the integral over NodesEps1 is expected to be small. If it is small then the refinement is not performed\r\n my_int1=0 ! this will keep the estimate of the integral on the mesh NodesEps1 so that we stop resolving when this number is small\r\n do f=1,Neps1\r\n if ((abs(FuncEps1(3*f-2))+abs(FuncEps1(3*f-1))+abs(FuncEps1(3*f)) > 1.0d-15) .and. (CellsEpsRef1(f)==1)) then \r\n if (g > NdsEps-2) then \r\n print *,\"SetA_DGV: Number of nodes in epsilon is too big (g>NdsEps-2)\"\r\n stop\r\n end if\r\n ! save the nodes and the integrand values\r\n NodesEps2(2*g+1)=NodesEps1(2*f-1)\r\n FuncEps2(3*g+1)=FuncEps1(3*f-2)\r\n NodesEps2(2*g+4)=NodesEps1(2*f)\r\n FuncEps2(3*g+6)=FuncEps1(3*f)\r\n ! Evaluate the midpoint node: \r\n NodesEps2(2*g+2)=(NodesEps1(2*f-1)+NodesEps1(2*f))/2\r\n NodesEps2(2*g+3)=NodesEps2(2*g+2)\r\n ! Save the midpoint value of the integrand:\r\n FuncEps2(3*g+3)=FuncEps1(3*f-1)\r\n FuncEps2(3*g+4)=FuncEps2(3*g+3)\r\n ! Evaluate the integrand on the new nodes\r\n FuncEps2(3*g+2) = EvalPhiPostCollIntegrand(xiu,xiv,xiw,xi1u,xi1v,xi1w,ugu,ugv,ugw,ugux2,ugvx2,ugwx2,&\r\n ugux3,ugvx3,ugwx3,(NodesEps2(2*g+2)+NodesEps2(2*g+1))/2.0_DP,sinchi,coschi,g1,g2,dsph,i1,varphi_xi,varphi_xi1) \r\n FuncEps2(3*g+5) = EvalPhiPostCollIntegrand(xiu,xiv,xiw,xi1u,xi1v,xi1w,ugu,ugv,ugw,ugux2,ugvx2,ugwx2,&\r\n ugux3,ugvx3,ugwx3,(NodesEps2(2*g+4)+NodesEps2(2*g+3))/2.0_DP,sinchi,coschi,g1,g2,dsph,i1,varphi_xi,varphi_xi1) \r\n ! Now it is time to compare the quadratures and to mark cells for the refinement \r\n quad = (FuncEps1(3*f-2)+4*FuncEps1(3*f-1)+FuncEps1(3*f))*(NodesEps1(2*f)-NodesEps1(2*f-1))/6\r\n quad1 = (FuncEps2(3*g+1)+4*FuncEps2(3*g+2)+FuncEps2(3*g+3))*(NodesEps2(2*g+2)-NodesEps2(2*g+1))/6\r\n quad2 = (FuncEps2(3*g+4)+4*FuncEps2(3*g+5)+FuncEps2(3*g+6))*(NodesEps2(2*g+4)-NodesEps2(2*g+3))/6\r\n es = abs(quad1+quad2-quad)/15/(NodesEps1(2*f)-NodesEps1(2*f-1)) ! local error indicator for simpson's rule.\r\n my_int1 = my_int1 + abs(quad1) + abs(quad2) ! This will calculate the estimate from above to the total integral on the current mesh \r\n if (es > ErrEps) then \r\n EpsAdaptFlag = .true.\r\n CellsEpsRef2(g+1) = 1\r\n CellsEpsRef2(g+2) = 1\r\n else\r\n CellsEpsRef2(g+1) = 0\r\n CellsEpsRef2(g+2) = 0\r\n Atemp_temp = Atemp_temp + quad1 + quad2 \r\n end if \r\n g=g+2\r\n ! end refinement \r\n end if \r\n end do \r\n !\r\n end if ! end check if the integral over NodesEps1 is too small to worry about it. \r\n ! Finally, we need to replace the first mesh with the refined mesh \r\n FuncEps1=0\r\n FuncEps1=FuncEps2\r\n NodesEps1=0\r\n NodesEps1=NodesEps2\r\n CellsEpsRef1=0\r\n CellsEpsRef1=CellsEpsRef2\r\n Neps1=g\r\n end do\r\n !!!!!!!!!!!!!!!!!! Looks like we are done with the integration in epsilon !!!!! \r\n y=Atemp_temp*sinchi\r\nend function A_IntEpsilon\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! MassCheck\r\n! \r\n! this fucntions will try to calculate mass of the disctribution function. This is a debug subroutine\r\n! \r\n!!!!!!!!!!!!!!!!!\r\nfunction MassCheck (f) result (y)\r\nuse commvar, only: nodes_gwts,nodes_u,nodes_v,nodes_w,gasR\r\n\r\nreal (DP), dimension (:), intent (in) :: f !the vector of nodal values of the distribution function\r\nreal (DP) :: y ! the result (the mass) \r\n!!!!!!!!!!!!!!!!!!\r\nreal (DP) :: n,ubar,vbar,wbar,temp ! number density, av_v\r\n \r\ninteger (I4B) :: i ! scrap index\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! check mass\r\nn=sum(f*nodes_gwts)\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! check momentum \r\nubar=sum(f*nodes_gwts*nodes_u)/n\r\nvbar=sum(f*nodes_gwts*nodes_v)/n\r\nwbar=sum(f*nodes_gwts*nodes_w)/n\r\n! check \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\ntemp = sum(f*nodes_gwts*((nodes_u-ubar)**2+(nodes_v-vbar)**2+(nodes_w-wbar)**2))/n/3.0_DP*2.0_DP ! dimensionless temperature\r\n!\r\ny=ubar ! return this... \r\n\r\nend function MassCheck \r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! FindCellContainsPoint_DGV\r\n!\r\n! This subroutine find the number of the active cell in the cell arrays that containes\r\n! the point (u,v,w)\r\n!\r\n! the function returns zero if the velocity point is not on any cells. \r\n!\r\n!\r\n! the subroutine accesses arrays\r\n! nodes_pcell, nodes_u, nodes_v, nodes_w,&\r\n!\t\t\t\t cells_pgrid, cells_cgrid, cells_lu, cells_lv, cells_lw, & \r\n! cells_ru, cells_rv, cells_rw, cells_refu, cells_refv, & \r\n! cells_refw, cells_gow, cells_gou, cells_gov, grids_cap_u, &\r\n! grids_cap_v,grids_cap_w,grids_u,grids_v,grids_w,g_nds_all, &\r\n! nodes_ui, nodes_vi, nodes_wi\r\n!\r\n!\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\nfunction FindCellContainsPoint_DGV(u,v,w) result (y)\r\n\r\nuse commvar, only: nodes_pcell, nodes_u, nodes_v, nodes_w,&\r\n\t\t\t\t cells_pgrid, cells_cgrid, cells_lu, cells_lv, cells_lw, & \r\n cells_ru, cells_rv, cells_rw, cells_refu, cells_refv, & \r\n cells_refw, cells_gow, cells_gou, cells_gov, grids_cap_u, &\r\n grids_cap_v,grids_cap_w,grids_u,grids_v,grids_w,g_nds_all, &\r\n nodes_ui, nodes_vi, nodes_wi\r\n\r\nreal (DP) :: u,v,w ! the components of the given velocity point\r\ninteger (I4B) :: y ! the value of the index in the cell arrays that correcponds to the active cell containing point (u,v,w)\r\n\r\n!!!!!!!!!!!!!! \r\ninteger (I4B) :: j ! a counter -- usually denotes the number of the grid we are working on. \r\ninteger (I4B) :: gi_v,gi_u,gi_w ! counters to help count nodes in the grids array\r\ninteger (I4B) :: celli, cellp ! these will store the number of the cell where the velocity belongs and the number of the \r\n ! parent cell where the basis function belongs. \r\ninteger (I4B) :: ui,vi,wi ! are the local numbers on the particular grids where u belongs. Because we have ierarchicval grids, \r\n ! there may be different grids that have ui,vi,wi defined. If one of these numbers is zero -- then the \r\n ! velocity u,v,w is not on the grid. Unless a mistake was done in setting the grids either all three of them \r\n ! are zero -- that means that the velocity is not on this (level zero grid) or all three are non-zero -- means that\r\n ! the velocity has been found. Mized results may indicate a breach in data integrity. \r\n !!!!!\r\ninteger (I4B) :: jj ! a counter\r\nreal (DP) :: unor,vnor,wnor ! scrap variables to store the normalized velus of the components u,v,w \r\n\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1\r\n! first, given a velocity, we need to identify the cell where it came from and its 1D numbers \r\n! we start looking in course cells first. If a cell is found that has that velocity we check if the cell is refined. \r\n! if it is, then we look into the corresponding grid and seek the smaller cell that has it and so on. \r\n!!!!!!!!\r\n!\r\nj=1\r\n!! set up the shift in grids_u/_v/_w corresponding to the first grid (zero shift):\r\ngi_u=0\r\ngi_v=0\r\ngi_w=0\r\ndo while (j<=size(grids_cap_u,1))\r\n call finduiviwi(grids_u(gi_u+1:gi_u+grids_cap_u(j)),grids_v(gi_v+1:gi_v+grids_cap_v(j)),&\r\n grids_w(gi_w+1:gi_w+grids_cap_w(j)),u,v,w,ui,vi,wi)\r\n if (ui*vi*wi /= 0) then \r\n ! now we need to find the cell that correspond to this grid and these ui,vi,wi\r\n celli=1\r\n do jj=1,j-1\r\n celli = celli + (grids_cap_u(jj)-1)*(grids_cap_v(jj)-1)*(grids_cap_w(jj)-1)\r\n end do\r\n celli=celli + (ui-2)*(grids_cap_v(j)-1)*(grids_cap_w(j)-1)+(vi-2)*(grids_cap_w(j)-1)+(wi-2)\r\n ! check if this cell is refined\r\n if ((cells_refu(celli)>1) .or. (cells_refv(celli)>1) .or. (cells_refw(celli)>1)) then \r\n j=cells_cgrid(celli)\r\n ! set up the shift in grids_u/_v/_w corresponding to the j'th grid:\r\n gi_u=0\r\n gi_v=0\r\n gi_w=0\r\n do jj=1,j-1\r\n gi_u = gi_u + grids_cap_u(jj)\r\n gi_v = gi_v + grids_cap_v(jj)\r\n gi_w = gi_w + grids_cap_w(jj)\r\n end do\r\n else \r\n exit\r\n endif\r\n else \r\n celli=0\r\n exit\r\n endif \r\nenddo\r\n! now \"celli\" either is the number of the cell or 0 (0 means that the velocity in not on any cell)\r\n! we return this number \r\ny=celli\r\n! \r\nend function FindCellContainsPoint_DGV\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! FindI1sByCellNum_DGV\r\n!\r\n! This functions looks at the nodes arrays and finds the numbers of the nodes that\r\n! belong to cell with the number i\r\n! \r\n! The numbers will be recorded in the array of results with the first number indicating the number of useful records/\r\n! \r\n! For example: if the result array has a zero in its first place, then the cell has no nodes -- which is not expected, really... \r\n! \r\n! if the array has number 5 in its firs place, than elements 2--6 contain the I1s --- these numbers will be used to build the A-array.\r\n! \r\n! if there is no cell with the number i -- the program retrurns zero records and prints a worning\r\n! if the result array is too short to fit all the numbers i1, the program prints the error message and stops.\r\n!\r\n!\r\n! \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\nsubroutine FindI1sByCellNum_DGV(i,y)\r\n\r\nuse commvar, only: nodes_pcell,cells_lu\r\n \r\n \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\ninteger (I4B), intent (in) :: i ! the number of the cell where I1s need to be looked at. \r\ninteger (I4B), dimension (:), intent (out) :: y ! the numbers of the nodes (I1 -- in our sleng...) that belong to the cell with number i \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\ninteger (i4B) :: j,k,pcell_i,sizey ! local counters.\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\nsizey=size(y,1)\r\ny=0 ! nullify the thing... Just In Case \r\nk=0 ! in the beginning there is no records///\r\nif (i>size(cells_lu,1)) then ! check if i is too big\r\n y=0 !\r\n print *,\"FindI1sByCellNum_DGV: the cell with the provided number i do not exist -- i is too big. Returned zero records\"\r\nelse ! if i is not too big, \r\n do j=1,size(nodes_pcell,1)\r\n pcell_i=nodes_pcell(j) \r\n if (pcell_i==i) then ! check if the node belongs to cell i \r\n k=k+1 ! if it does, check if can still records in y\r\n if (k+1<=sizey) then \r\n y(1+k)=j !record\r\n else ! othersize print the error message and stop\r\n print *,\"FindI1sByCellNum_DGV: The size fo the result array is too small. Can not put all I1s. Stop\"\r\n stop\r\n end if\r\n end if \r\n end do \r\ny(1)=k ! the first records is reserved for the number of found I1s\r\nend if \r\nend subroutine FindI1sByCellNum_DGV\r\n\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! TruncAarrsTrhld_DGV (trhld)\r\n!\r\n! This subroutine trancates the A-arrays. All entries of A that are below the provided \r\n! treshhold value (trhld) are being cut, arrays Axi, Axi1, Aphi, A_capphi are updated correspondingly... \r\n!\r\n! ATTENTION: array nodes_Ashift need to be re-created after A has been truncated.\r\n!\r\n!\r\n!!!!!!!!!!!!!!!!!!!\r\nsubroutine TruncAarrsTrhls_DGV (trhld)\r\n\r\nuse commvar, only: A, A_xi, A_xi1, A_phi, A_capphi \r\n\r\n!!!!\r\nreal (DP), intent (in) :: trhld ! the treshhold at which to cut A:\r\n!!!\r\ninteger (I4B) :: nold,nnew ! are the old and new sizes of the A-arrays\r\ninteger (I4B) :: i,j,phicap ! scrap indices\r\n!!!\r\nreal (DP), dimension (:), allocatable :: Ascr ! real scrap array\r\ninteger (I4B), dimension (:), allocatable :: A_xiscr, A_xi1scr, A_phiscr ! integer scrap arrays\r\n!\r\ninteger (I4B) :: loc_alloc_stat \r\n\r\nnold = size(A,1)\r\n! shrinking A ... \r\nallocate (Ascr(1:nold), A_xiscr(1:nold), A_xi1scr(1:nold), A_phiscr(1:nold), stat=loc_alloc_stat)\r\n !\r\n if (loc_alloc_stat >0) then \r\n print *, \"TruncAarrsTrhls_DGV: Allocation error for variables Ascr, A_xiscr, _xi1scr, _phiscr\" \r\n stop\r\n end if\r\n! Save the A arrays .... \r\nAscr=A; A_xiscr=A_xi; A_xi1scr=A_xi1; A_phiscr=A_phi\r\n! Now clear the A-arrays; \r\nA=0.0_DP; A_xi=0; A_xi1=0; A_phi=0\r\n! Now start to fill them in, but omitting all records that are below the treshhold value\r\nnold=0 ! this will count the original records of A === similar to A_ct index\r\nnnew=0 ! this will count the records after the truncation. \r\ndo i = 1,size(A_capphi,1) ! loop in basis functions --- one node=one basis function\r\n phicap = 0\r\n do j = 1+nold,nold+A_capphi(i)\r\n if (ABS(Ascr(j))>trhld) then ! if records in A array are above treshhold, they are saved, otherwise ignored\r\n phicap = phicap+1\r\n nnew = nnew+1 \r\n A(nnew)=Ascr(j)\r\n A_xi(nnew)=A_xiscr(j)\r\n A_xi1(nnew)=A_xi1scr(j)\r\n A_phi(nnew)=A_phiscr(j)\r\n end if \r\n end do \r\n nold = nold+A_capphi(i) ! shift the start index to the place where record sfo rthe next basis function start.\r\n A_capphi(i) = phicap ! Update the A_capphi --- it now stores the number of records after the truncation\r\nend do \r\ndeallocate(Ascr,A_xiscr,A_xi1scr,A_phiscr) !\r\n\r\ncall ShrinkAarraysDGV(nnew)\r\n\r\nend subroutine TruncAarrsTrhls_DGV\r\n\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! TruncAarrsRadius_DGV (rad)\r\n!\r\n! This subroutine trancates the A-arrays based on the distance between xi and xi1. If the distance is larger than \r\n! the specified radus (rad), the record is discarded from A and arrays Axi, Axi1, Aphi, A_capphi are updated correspondingly... \r\n!\r\n! ATTENTION: array nodes_Ashift needs to be re-created after A has been truncated.\r\n!\r\n!\r\n!!!!!!!!!!!!!!!!!!!\r\nsubroutine TruncAarrsRadius_DGV (rad)\r\n\r\nuse commvar, only: A, A_xi, A_xi1, A_phi, A_capphi, nodes_u, nodes_v, nodes_w \r\n\r\n!!!!\r\nreal (DP), intent (in) :: rad ! the treshhold at which to cut A:\r\n!!!\r\ninteger (I4B) :: nold,nnew ! are the old and new sizes of the A-arrays\r\ninteger (I4B) :: i,j,phicap,ixi,ixi1 ! scrap indices\r\n!!!\r\nreal (DP), dimension (:), allocatable :: Ascr ! real scrap array\r\ninteger (I4B), dimension (:), allocatable :: A_xiscr, A_xi1scr, A_phiscr ! integer scrap arrays\r\nreal (DP) :: dsq, radsq ! scrap variables to keep distance squared and radius squared\r\n!\r\ninteger (I4B) :: loc_alloc_stat \r\n\r\nnold = size(A,1)\r\n! shrinking A ... \r\nallocate (Ascr(1:nold), A_xiscr(1:nold), A_xi1scr(1:nold), A_phiscr(1:nold), stat=loc_alloc_stat)\r\n !\r\n if (loc_alloc_stat >0) then \r\n print *, \"TruncAarrsTrhls_DGV: Allocation error for variables Ascr, A_xiscr, _xi1scr, _phiscr\" \r\n stop\r\n end if\r\n! Save the A arrays .... \r\nAscr=A; A_xiscr=A_xi; A_xi1scr=A_xi1; A_phiscr=A_phi\r\n! Now clear the A-arrays; \r\nA=0.0_DP; A_xi=0; A_xi1=0; A_phi=0\r\n! Now start to fill them in, but omitting all records that are below the treshhold value\r\nnold=0 ! this will count the original records of A === similar to A_ct index\r\nnnew=0 ! this will count the records after the truncation. \r\nradsq=rad**2\r\ndo i = 1,size(A_capphi,1) ! loop in basis functions --- one node=one basis function\r\n phicap = 0\r\n do j = 1+nold,nold+A_capphi(i)\r\n ixi=A_xiscr(j)\r\n ixi1=A_xi1scr(j)\r\n dsq = (nodes_u(ixi)-nodes_u(ixi1))**2 + (nodes_v(ixi)-nodes_v(ixi1))**2 + (nodes_w(ixi)-nodes_w(ixi1))**2\r\n if (dsq <= radsq) then ! if vectors xi and xi1 are at or closer than distance rad, the record in A is saved, otherwise ignored\r\n phicap = phicap+1\r\n nnew = nnew+1 \r\n A(nnew)=Ascr(j)\r\n A_xi(nnew)=A_xiscr(j)\r\n A_xi1(nnew)=A_xi1scr(j)\r\n A_phi(nnew)=A_phiscr(j)\r\n end if \r\n end do \r\n nold = nold+A_capphi(i) ! shift the start index to the place where record sfo rthe next basis function start.\r\n A_capphi(i) = phicap ! Update the A_capphi --- it now stores the number of records after the truncation\r\nend do \r\ndeallocate(Ascr,A_xiscr,A_xi1scr,A_phiscr) !\r\n\r\ncall ShrinkAarraysDGV(nnew)\r\n\r\nend subroutine TruncAarrsRadius_DGV\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! MassCheckRec\r\n! \r\n! this fucntions will try to calculate mass of the disctribution function. This is a debug subroutine\r\n! \r\n!!!!!!!!!!!!!!!!!\r\nsubroutine MassCheckRec (f,n,ubar,vbar,wbar,temp)\r\nuse commvar, only: nodes_gwts,nodes_u,nodes_v,nodes_w,gasR\r\n\r\nreal (DP), dimension (:), intent (in) :: f !the vector of nodal values of the distribution function\r\nreal (DP), intent (out) :: n,ubar,vbar,wbar,temp ! number density, av_v\r\n!!!!!!!!!!!!!!!!!!\r\n \r\ninteger (I4B) :: i ! scrap index\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! check mass\r\nn=sum(f*nodes_gwts)\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! check momentum \r\nubar=sum(f*nodes_gwts*nodes_u)/n\r\nvbar=sum(f*nodes_gwts*nodes_v)/n\r\nwbar=sum(f*nodes_gwts*nodes_w)/n\r\n! check \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\ntemp = sum(f*nodes_gwts*((nodes_u-ubar)**2+(nodes_v-vbar)**2+(nodes_w-wbar)**2))/n/3.0_DP*2.0_DP ! dimensionless temperature\r\n!\r\nend subroutine MassCheckRec \r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! MassCheckRecPlus\r\n! \r\n! this fucntions will try to calculate mass of the disctribution function. This is a debug subroutine\r\n! This one also calculase momentum, temperature and the directional temperature \r\n!!!!!!!!!!!!!!!!!\r\nsubroutine MassCheckRecPlus (f,n,ubar,vbar,wbar,temp,temp_u,temp_v,temp_w)\r\nuse commvar, only: nodes_gwts,nodes_u,nodes_v,nodes_w,gasR\r\n\r\nreal (DP), dimension (:), intent (in) :: f !the vector of nodal values of the distribution function\r\nreal (DP), intent (out) :: n,ubar,vbar,wbar,temp,temp_u,temp_v,temp_w ! number density, av_v\r\n!!!!!!!!!!!!!!!!!!\r\n \r\ninteger (I4B) :: i ! scrap index\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! check mass\r\nn=sum(f*nodes_gwts)\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! check momentum \r\nubar=sum(f*nodes_gwts*nodes_u)/n\r\nvbar=sum(f*nodes_gwts*nodes_v)/n\r\nwbar=sum(f*nodes_gwts*nodes_w)/n\r\n! check temperature \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\ntemp = sum(f*nodes_gwts*((nodes_u-ubar)**2+(nodes_v-vbar)**2+(nodes_w-wbar)**2))/n/3.0_DP*2.0_DP ! dimensionless temperature\r\n! check directional temperatures \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\ntemp_u = sum(f*nodes_gwts*(nodes_u-ubar)**2)/n/3.0_DP*2.0_DP ! dimensionless directional temperature Tx\r\ntemp_v = sum(f*nodes_gwts*(nodes_v-vbar)**2)/n/3.0_DP*2.0_DP ! dimensionless directional temperature Ty\r\ntemp_w = sum(f*nodes_gwts*(nodes_w-wbar)**2)/n/3.0_DP*2.0_DP ! dimensionless directional temperature Tz\r\n!!!!!!!!!!\r\nend subroutine MassCheckRecPlus \r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! MassCheckRecHighCMoments\r\n! \r\n! this fucntions will try to calculate mass of the disctribution function. This is a debug subroutine\r\n! This one also calculates momentum, temperature and the directional temperature as well as additional moments\r\n! and will update the moments history\r\n!!!!!!!!!!!!!!!!!\r\nsubroutine MassCheckRecHighCMoments (f,n,ubar,vbar,wbar,temp,temp_u,temp_v,temp_w,mom3_u,mom3_v,mom3_w,mom4_u,mom4_v,&\r\n mom4_w,mom5_u,mom5_v,mom5_w,mom6_u,mom6_v,mom6_w)\r\nuse commvar, only: nodes_gwts,nodes_u,nodes_v,nodes_w,gasR\r\n\r\nreal (DP), dimension (:), intent (in) :: f !the vector of nodal values of the distribution function\r\nreal (DP), intent (out) :: n,ubar,vbar,wbar,temp,temp_u,temp_v,temp_w,mom3_u,mom3_v,mom3_w\r\nreal (DP), intent (out) :: mom4_u,mom4_v,mom4_w,mom5_u,mom5_v,mom5_w,mom6_u,mom6_v,mom6_w ! number density, av_v\r\n!!!!!!!!!!!!!!!!!!\r\n\r\ninteger (I4B) :: i ! scrap index\r\n\r\n!!!!!!!!!\r\n! check mass\r\nn=sum(f*nodes_gwts)\r\n!!!!!!!!!\r\n! check momentum \r\nubar=sum(f*nodes_gwts*nodes_u)/n\r\nvbar=sum(f*nodes_gwts*nodes_v)/n\r\nwbar=sum(f*nodes_gwts*nodes_w)/n\r\n! check temperature \r\n!!!!!!!!!\r\ntemp = sum(f*nodes_gwts*((nodes_u-ubar)**2+(nodes_v-vbar)**2+(nodes_w-wbar)**2))/n/3.0_DP*2.0_DP ! dimensionless temperature\r\n! check directional temperatures \r\n!!!!!!!!!\r\ntemp_u = sum(f*nodes_gwts*(nodes_u-ubar)**2)/n/3.0_DP*2.0_DP ! dimensionless directional temperature Tx\r\ntemp_v = sum(f*nodes_gwts*(nodes_v-vbar)**2)/n/3.0_DP*2.0_DP ! dimensionless directional temperature Ty\r\ntemp_w = sum(f*nodes_gwts*(nodes_w-wbar)**2)/n/3.0_DP*2.0_DP ! dimensionless directional temperature Tz\r\n!!!!!!!!!\r\n! Moments for Q = u^3\r\nmom3_u = sum(f*nodes_gwts*(nodes_u-ubar)**3)/n\r\nmom3_v = sum(f*nodes_gwts*(nodes_v-vbar)**3)/n\r\nmom3_w = sum(f*nodes_gwts*(nodes_w-wbar)**3)/n\r\n!!!!!!!!!\r\n! Moments for Q = u^4\r\nmom4_u = sum(f*nodes_gwts*(nodes_u-ubar)**4)/n\r\nmom4_v = sum(f*nodes_gwts*(nodes_v-vbar)**4)/n\r\nmom4_w = sum(f*nodes_gwts*(nodes_w-wbar)**4)/n\r\n!!!!!!!!!\r\n! Moments for Q = u^5\r\nmom5_u = sum(f*nodes_gwts*(nodes_u-ubar)**5)/n\r\nmom5_v = sum(f*nodes_gwts*(nodes_v-vbar)**5)/n\r\nmom5_w = sum(f*nodes_gwts*(nodes_w-wbar)**5)/n\r\n!!!!!!!!!\r\n! Moments for Q = u^6\r\nmom6_u = sum(f*nodes_gwts*(nodes_u-ubar)**6)/n\r\nmom6_v = sum(f*nodes_gwts*(nodes_v-vbar)**6)/n\r\nmom6_w = sum(f*nodes_gwts*(nodes_w-wbar)**6)/n\r\n!!!!!!!!!\r\nend subroutine MassCheckRecHighCMoments\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n!! RecordMomDerivRelaxTimes_DGV\r\n!! \r\n!!\r\n!! This is a diagnostics subroutine that takes records derivatives and relaxation speeds of\r\n!! a selected group of moments. \r\n!! \r\n!! The derivatives of moments are evaluated for the problem of spatially homogeneous relaxation. \r\n!! The derivatives are thus computed by taking the moment of the collision integral. Also, derivatives of the local maxwellian are computed\r\n!! for true problem of spatial relaxatiopn this derivative is zero, however, due to the numerical erros, the \r\n!! maxwellian will change. These errors will tell us how bad is the violation of the conservation laws \r\n!! \r\n!! The relaxation speeds will be computed from the following definition: \r\n!! \\nu_{\\phi} = -\\partial_{t} \\ln | f_{\\varphi}(t) - f_{\\varphi}^M (t)|\r\n!! \r\n!! \r\n!! The records will be stored in an array - MomDerivRelaxT with the first two \r\n!! numbers being (1) the number of saved records -- how many times the derivatives and speeds were evaluated. \r\n!! (2) the number of columns in the record. The first column will the the time \r\n!! then there will go the columns for the derivatives and then for speeds. The number of columns is then 1+2*m where m \r\n!! is the number of moments. \r\n!! \r\n!! MomDerivRelaxT -- array to keep the data. Size of this array is (1+2*m)*num_eval_error \r\n!!\t\t\t\t\r\n!! MomDerivRelaxT_flag -- this variable will keep the status of the allocation of \r\n!!\r\n!! On the first call, the MomDerivRelaxT array will be allocated. Then adata will recorder in this array, adding one record \r\n!! every time the subroutine is called. The same subrouine will deallocated the array after the exectution is finished. \r\n!! In the MPI implementatio the subroutine will run on the master node. \r\n!! \r\n!! variables: \r\n!! \r\n!! from commvar: MomDerivRelaxT, MomDerivRelaxT_flag\r\n!! from commvar: frhs1 -- last evaluated collision operator\r\n!! from commvar: f1 -- value of f that corresponds to that frhs1\r\n!!\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\nsubroutine RecordMomDerivRelaxTimes_DGV(curr_time)\r\n\r\nuse commvar, only: MomDerivRelaxT,MomDerivRelaxT_flag,f1,frhs1,num_eval_error,t_R,nodes_u,nodes_v,nodes_w,&\r\n rkmts,nodes_gwts \r\nuse distributions_mod\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\nreal (DP), intent (in) :: curr_time ! the currect time\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\ninteger (I4B) :: i,j,k ! scrap indices \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\ninteger (I4B) :: loc_alloc_stat, info ! local variable to keep the allocation status\r\nreal (DP), parameter :: epps=0.01_DP ! threshhold parameters for evaluation of the relaxation times\r\nreal (DP) :: tresh ! this is a scrap variable to use in evaluation of relaxation times\r\nreal (DP) :: n,ubar,vbar,wbar,temp,temp_u,temp_v,temp_w,mom3_u,mom3_v,mom3_w ! scrap variables to store the moments\r\nreal (DP) :: mom4_u,mom4_v,mom4_w,mom5_u,mom5_v,mom5_w,mom6_u,mom6_v,mom6_w ! number density, av_v\r\nreal (DP) :: mn,mubar,mvbar,mwbar,mtemp,mtemp_u,mtemp_v,mtemp_w,mmom3_u,mmom3_v,mmom3_w ! scrap variables to store the difference in the moments between the solution and the local maxwellian\r\nreal (DP) :: mmom4_u,mmom4_v,mmom4_w,mmom5_u,mmom5_v,mmom5_w,mmom6_u,mmom6_v,mmom6_w ! number density, av_v\r\nreal (DP) :: dn,dubar,dvbar,dwbar,dtemp,dtemp_u,dtemp_v,dtemp_w,dmom3_u,dmom3_v,dmom3_w ! scrap vaiables to store derivatives of the moments...\r\nreal (DP) :: dmom4_u,dmom4_v,dmom4_w,dmom5_u,dmom5_v,dmom5_w,dmom6_u,dmom6_v,dmom6_w ! \r\nreal (DP) :: taun,tauubar,tauvbar,tauwbar,tautemp,tautemp_u,tautemp_v,tautemp_w,taumom3_u,taumom3_v,taumom3_w ! scrap vaiables to store relaxation times for the moments...\r\nreal (DP) :: taumom4_u,taumom4_v,taumom4_w,taumom5_u,taumom5_v,taumom5_w,taumom6_u,taumom6_v,taumom6_w ! \r\nreal (DP), dimension (size(f1,1)) :: fm,derfm ! this is the storage for the local Maxwellian and the derivative of the local maxwellian \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n! First the program will check if the array to store the moment derivatives has been created yet. \r\n! If it was not, it will create the array.\r\nif (MomDerivRelaxT_flag /= 1) then \r\n k = 1 + 2*20 !1+3+1+5x3 = 20 -- number of saved moments\r\n ! k is the total number of columents in the array.\r\n allocate (MomDerivRelaxT(1:2+k*(num_eval_error+3+rkmts+1)), stat=loc_alloc_stat) ! we added rkmts so that we can save on each of the step of the prepare MTS\r\n if (loc_alloc_stat >0) then \r\n print *, \"RecordMomDerivRelaxTimes_DGV: Allocation error for variable (MomDerivRelaxT)\"\r\n stop\r\n end if \r\n MomDerivRelaxT(1)=0 ! this cell stores the number of records\r\n MomDerivRelaxT(2) = k ! this cell stored the number of columns\r\n MomDerivRelaxT_flag = 1 ! set the flag to 1 to indicate that the array was created \r\nend if \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! Now we compute the moments, we will need them \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! check mass\r\nn=sum(f1*nodes_gwts)\r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! check momentum \r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\nubar=sum(f1*nodes_gwts*nodes_u)/n\r\nvbar=sum(f1*nodes_gwts*nodes_v)/n\r\nwbar=sum(f1*nodes_gwts*nodes_w)/n\r\n! check temperature \r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\ntemp = sum(f1*nodes_gwts*((nodes_u-ubar)**2+(nodes_v-vbar)**2+(nodes_w-wbar)**2))/n/3.0_DP*2.0_DP ! dimensionless temperature\r\n!!!!!!!!!\r\n! check directional temperatures \r\n!!!!!!!!!\r\ntemp_u = sum(f1*nodes_gwts*(nodes_u-ubar)**2)/n/3.0_DP*2.0_DP ! dimensionless directional temperature Tx\r\ntemp_v = sum(f1*nodes_gwts*(nodes_v-vbar)**2)/n/3.0_DP*2.0_DP ! dimensionless directional temperature Ty\r\ntemp_w = sum(f1*nodes_gwts*(nodes_w-wbar)**2)/n/3.0_DP*2.0_DP ! dimensionless directional temperature Tz\r\n!!!!!!!!!\r\n! Moments for Q = u^3\r\nmom3_u = sum(f1*nodes_gwts*(nodes_u-ubar)**3)/n\r\nmom3_v = sum(f1*nodes_gwts*(nodes_v-vbar)**3)/n\r\nmom3_w = sum(f1*nodes_gwts*(nodes_w-wbar)**3)/n\r\n!!!!!!!!!\r\n! Moments for Q = u^4\r\nmom4_u = sum(f1*nodes_gwts*(nodes_u-ubar)**4)/n\r\nmom4_v = sum(f1*nodes_gwts*(nodes_v-vbar)**4)/n\r\nmom4_w = sum(f1*nodes_gwts*(nodes_w-wbar)**4)/n\r\n!!!!!!!!!\r\n! Moments for Q = u^5\r\nmom5_u = sum(f1*nodes_gwts*(nodes_u-ubar)**5)/n\r\nmom5_v = sum(f1*nodes_gwts*(nodes_v-vbar)**5)/n\r\nmom5_w = sum(f1*nodes_gwts*(nodes_w-wbar)**5)/n\r\n!!!!!!!!!\r\n! Moments for Q = u^6\r\nmom6_u = sum(f1*nodes_gwts*(nodes_u-ubar)**6)/n\r\nmom6_v = sum(f1*nodes_gwts*(nodes_v-vbar)**6)/n\r\nmom6_w = sum(f1*nodes_gwts*(nodes_w-wbar)**6)/n\r\n!!!!!!!!!\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! Next we will calculate the derivatives of the moments and will save them into a whole bunch of scrap variables\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! Notice that the derivatives of the first five invariants must be zero in spatially homogeneous problem. The values of the derivatives \r\n! tell us how much the conservation laws are violated. \r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! derivative of mass\r\ndn = sum(frhs1*nodes_gwts)\r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! derivative of momentum \r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\ndubar = (sum(frhs1*nodes_gwts*nodes_u) - dn*ubar)/n\r\ndvbar = (sum(frhs1*nodes_gwts*nodes_v) - dn*vbar)/n\r\ndwbar = (sum(frhs1*nodes_gwts*nodes_w) - dn*wbar)/n\r\n! derivative of temperature \r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\ndtemp = ( sum(frhs1*nodes_gwts*((nodes_u-ubar)**2+(nodes_v-vbar)**2+(nodes_w-wbar)**2) &\r\n -f1*2.0_DP*((nodes_u-ubar)*dubar+(nodes_v-vbar)*dvbar+(nodes_w-wbar)*dwbar))/3.0_DP*2.0_DP &\r\n -dn*temp )/n ! derivative of dimensionless temperature\r\n!!!!!!!!!\r\n! BEGIN COMMENTED CODE. ALEX 06022014\r\n! IN THE COMMENTED LINES THE DERIVATIVES of the moments are evaluated \r\n! Assuming that there are non-trivial derivatives of the first five moments. However, \r\n! In the exact solution to spatially homogeneous relaxqtion the derivatives of the first five moments are zero\r\n! Nozero derivatives are due exclusively to the numerical errors. We suspect that these numerical errors contaminate \r\n! the derivatives of moments whose values are near zero??? Odd moments that tend to zero or may be some other moments. \r\n! Thefore we will comment these lines and replace them with formuls where the derivatives of the first five moments are\r\n! neglected. \r\n!\r\n! derivatives of directional temperatures \r\n!!!!!!!!!\r\n!dtemp_u =( sum(frhs1*nodes_gwts*(nodes_u-ubar)**2 - f1*2.0_DP*(nodes_u-ubar)*dubar)/3.0_DP*2.0_DP &\r\n! -dn*temp_u )/n ! derivative of dimensionless directional temperature Tx\r\n!dtemp_v =( sum(frhs1*nodes_gwts*(nodes_v-vbar)**2 - f1*2.0_DP*(nodes_v-vbar)*dvbar)/3.0_DP*2.0_DP &\r\n! -dn*temp_v )/n ! derivative of dimensionless directional temperature Ty\r\n!dtemp_w =( sum(frhs1*nodes_gwts*(nodes_w-wbar)**2 - f1*2.0_DP*(nodes_w-wbar)*dwbar)/3.0_DP*2.0_DP &\r\n! -dn*temp_w )/n ! derivative of dimensionless directional temperature Tz\r\n!!!!!!!!!!\r\n!! Derivatives of Moments for Q = u^3\r\n!dmom3_u = ( sum(frhs1*nodes_gwts*(nodes_u-ubar)**3 - f1*3.0_DP*((nodes_u-ubar)**2)*dubar) - dn*mom3_u )/n\r\n!dmom3_v = ( sum(frhs1*nodes_gwts*(nodes_v-vbar)**3 - f1*3.0_DP*((nodes_v-vbar)**2)*dvbar) - dn*mom3_v )/n\r\n!dmom3_w = ( sum(frhs1*nodes_gwts*(nodes_w-wbar)**3 - f1*3.0_DP*((nodes_w-wbar)**2)*dwbar) - dn*mom3_w )/n\r\n!!!!!!!!!!\r\n!! Derivatives of Moments for Q = u^4\r\n!dmom4_u = ( sum(frhs1*nodes_gwts*(nodes_u-ubar)**4 - f1*4.0_DP*((nodes_u-ubar)**3)*dubar) - dn*mom4_u )/n\r\n!dmom4_v = ( sum(frhs1*nodes_gwts*(nodes_v-vbar)**4 - f1*4.0_DP*((nodes_v-vbar)**3)*dvbar) - dn*mom4_v )/n\r\n!dmom4_w = ( sum(frhs1*nodes_gwts*(nodes_w-wbar)**4 - f1*4.0_DP*((nodes_w-wbar)**3)*dwbar) - dn*mom4_w )/n\r\n!!!!!!!!!\r\n! Moments for Q = u^5\r\n!dmom5_u = ( sum(frhs1*nodes_gwts*(nodes_u-ubar)**5 - f1*5.0_DP*((nodes_u-ubar)**4)*dubar) - dn*mom5_u )/n\r\n!dmom5_v = ( sum(frhs1*nodes_gwts*(nodes_v-vbar)**5 - f1*5.0_DP*((nodes_v-vbar)**4)*dvbar) - dn*mom5_v )/n\r\n!dmom5_w = ( sum(frhs1*nodes_gwts*(nodes_w-wbar)**5 - f1*5.0_DP*((nodes_w-wbar)**4)*dwbar) - dn*mom5_w )/n\r\n!!!!!!!!!\r\n! Moments for Q = u^6\r\n!dmom6_u = ( sum(frhs1*nodes_gwts*(nodes_u-ubar)**6 - f1*6.0_DP*((nodes_u-ubar)**5)*dubar) - dn*mom6_u )/n\r\n!dmom6_v = ( sum(frhs1*nodes_gwts*(nodes_v-vbar)**6 - f1*6.0_DP*((nodes_v-vbar)**5)*dvbar) - dn*mom6_v )/n\r\n!dmom6_w = ( sum(frhs1*nodes_gwts*(nodes_w-wbar)**6 - f1*6.0_DP*((nodes_w-wbar)**5)*dwbar) - dn*mom6_w )/n\r\n!!!!!!!!!\r\n! END COMMENTED LINES\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n\r\n! derivatives of directional temperatures \r\n!!!!!!!!!\r\ndtemp_u =( sum(frhs1*nodes_gwts*(nodes_u-ubar)**2))/3.0_DP*2.0_DP/n ! derivative of dimensionless directional temperature Tx. changes in the first four moments neglected \r\ndtemp_v =( sum(frhs1*nodes_gwts*(nodes_v-vbar)**2))/3.0_DP*2.0_DP/n ! derivative of dimensionless directional temperature Ty. changes in the first four moments neglected\r\ndtemp_w =( sum(frhs1*nodes_gwts*(nodes_w-wbar)**2))/3.0_DP*2.0_DP/n ! derivative of dimensionless directional temperature Tz. changes in the first four moments neglected\r\n!!!!!!!!!\r\n! Derivatives of Moments for Q = u^3\r\ndmom3_u = ( sum(frhs1*nodes_gwts*(nodes_u-ubar)**3))/n ! changes in the first four moments neglected\r\ndmom3_v = ( sum(frhs1*nodes_gwts*(nodes_v-vbar)**3))/n ! changes in the first four moments neglected\r\ndmom3_w = ( sum(frhs1*nodes_gwts*(nodes_w-wbar)**3))/n ! changes in the first four moments neglected\r\n!!!!!!!!!\r\n! Derivatives of Moments for Q = u^4\r\ndmom4_u = ( sum(frhs1*nodes_gwts*(nodes_u-ubar)**4))/n ! changes in the first four moments neglected\r\ndmom4_v = ( sum(frhs1*nodes_gwts*(nodes_v-vbar)**4))/n ! changes in the first four moments neglected\r\ndmom4_w = ( sum(frhs1*nodes_gwts*(nodes_w-wbar)**4))/n ! changes in the first four moments neglected\r\n!!!!!!!!!\r\n! Moments for Q = u^5\r\ndmom5_u = ( sum(frhs1*nodes_gwts*(nodes_u-ubar)**5))/n ! changes in the first four moments neglected\r\ndmom5_v = ( sum(frhs1*nodes_gwts*(nodes_v-vbar)**5))/n ! changes in the first four moments neglected\r\ndmom5_w = ( sum(frhs1*nodes_gwts*(nodes_w-wbar)**5))/n ! changes in the first four moments neglected\r\n!!!!!!!!!\r\n! Moments for Q = u^6\r\ndmom6_u = ( sum(frhs1*nodes_gwts*(nodes_u-ubar)**6))/n ! changes in the first four moments neglected\r\ndmom6_v = ( sum(frhs1*nodes_gwts*(nodes_v-vbar)**6))/n ! changes in the first four moments neglected\r\ndmom6_w = ( sum(frhs1*nodes_gwts*(nodes_w-wbar)**6))/n ! changes in the first four moments neglected\r\n!!!!!!!!!\r\n\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! Next we will calculate the local maxwellian\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\nfm = maxwelveldist(temp,ubar,vbar,wbar,n,nodes_u,nodes_v,nodes_w) ! now we have the maxwellian with the same macroparamters.\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! Now we compute the difference in the moments between the function and the local maxwellian, we will need them \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n!! MODIFIED ALEX: 06/02/2014\r\n!! explicitly will compute the moments of the steady state it and subtract them. Previously, momements of f1-fm were computed\r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! difference in mass\r\nmn=sum((f1-fm)*nodes_gwts) ! this one is a measure of how accurate is the evaluation of macroparameters.\r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! check momentum \r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\nmubar=sum((f1-fm)*nodes_gwts*nodes_u)/n !! this one is a measure of how accurate is the evaluation of macroparameters.\r\nmvbar=sum((f1-fm)*nodes_gwts*nodes_v)/n ! this one is a measure of how accurate is the evaluation of macroparameters.\r\nmwbar=sum((f1-fm)*nodes_gwts*nodes_w)/n ! this one is a measure of how accurate is the evaluation of macroparameters.\r\n! check temperature \r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\nmtemp = sum((f1-fm)*nodes_gwts*((nodes_u-ubar)**2+(nodes_v-vbar)**2+(nodes_w-wbar)**2))/n/3.0_DP*2.0_DP ! dimensionless temperature ! this one is a measure of how accurate is the evaluation of macroparameters.\r\n!!!!!!!!!\r\n! check directional temperatures \r\n!!!!!!!!!\r\nmtemp_u = sum(f1*nodes_gwts*(nodes_u-ubar)**2)/n/3.0_DP*2.0_DP - temp/3.0_DP ! dimensionless directional temperature Tx\r\nmtemp_v = sum(f1*nodes_gwts*(nodes_v-vbar)**2)/n/3.0_DP*2.0_DP - temp/3.0_DP ! dimensionless directional temperature Ty\r\nmtemp_w = sum(f1*nodes_gwts*(nodes_w-wbar)**2)/n/3.0_DP*2.0_DP - temp/3.0_DP! dimensionless directional temperature Tz\r\n!!!!!!!!!\r\n! Moments for Q = u^3 ! try without fm -- the corresponding moment is zero anyway... \r\nmmom3_u = sum(f1*nodes_gwts*(nodes_u-ubar)**3)/n\r\nmmom3_v = sum(f1*nodes_gwts*(nodes_v-vbar)**3)/n\r\nmmom3_w = sum(f1*nodes_gwts*(nodes_w-wbar)**3)/n\r\n!!!!!!!!!\r\n! Moments for Q = u^4\r\nmmom4_u = sum(f1*nodes_gwts*(nodes_u-ubar)**4)/n - 3.0_DP*temp**2/4.0_DP\r\nmmom4_v = sum(f1*nodes_gwts*(nodes_v-vbar)**4)/n - 3.0_DP*temp**2/4.0_DP\r\nmmom4_w = sum(f1*nodes_gwts*(nodes_w-wbar)**4)/n - 3.0_DP*temp**2/4.0_DP \r\n!!!!!!!!!\r\n! Moments for Q = u^5 ! try without fm -- the corresponding moment is zero anyway\r\nmmom5_u = sum(f1*nodes_gwts*(nodes_u-ubar)**5)/n \r\nmmom5_v = sum(f1*nodes_gwts*(nodes_v-vbar)**5)/n\r\nmmom5_w = sum(f1*nodes_gwts*(nodes_w-wbar)**5)/n\r\n!!!!!!!!!\r\n! Moments for Q = u^6\r\nmmom6_u = sum(f1*nodes_gwts*(nodes_u-ubar)**6)/n - 15.0_DP*temp**3/8.0_DP\r\nmmom6_v = sum(f1*nodes_gwts*(nodes_v-vbar)**6)/n - 15.0_DP*temp**3/8.0_DP\r\nmmom6_w = sum(f1*nodes_gwts*(nodes_w-wbar)**6)/n - 15.0_DP*temp**3/8.0_DP\r\n!!!!!!!!!\r\n\r\n!! END modified Alex\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! Next we compute the relaxation times/speeds for the moments\r\n! the formula for the relaxation times is\r\n! \r\n! \\nu_{\\phi} = -\\partial_{t} \\ln |f_{\\phi} - f_{\\phi}^{M}| , \\partial_{t} f_{\\phi}^{M}=0\r\n!\r\n! thus\r\n! \r\n! \\nu_{\\phi} = -\\partial_{t} f_{\\phi}/(f_{\\phi} - f_{\\phi}^{M}) \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n!!!\r\ntresh=abs(dn*epps) ! this is treshhold for sensitivity of the evaluation of relaxation times. \r\n! if the difference in $f_{\\varphi}-f^{M}_{\\varphi}$ falls below this treshhold, then \r\n! we values on the relaxation time probably are not reliable. in this case the relaxation time are equated to zero... \r\n!!!\r\nif (abs(mn) > tresh) then \r\n taun = dn/mn\r\nelse \r\n taun = 0.0_DP\r\nend if \r\n!!! \r\nif (abs(mubar) > tresh) then \r\n tauubar = -dubar/mubar \r\nelse \r\n tauubar = 0.0_DP\r\nend if \r\nif (abs(mvbar) > tresh) then \r\n tauvbar = -dvbar/mvbar \r\nelse \r\n tauvbar = 0.0_DP\r\nend if \r\nif (abs(mwbar) > tresh) then \r\n tauwbar = -dwbar/mwbar \r\nelse \r\n tauwbar = 0.0_DP\r\nend if \r\n!!!\r\nif (abs(mtemp) > tresh) then \r\n tautemp = -dtemp/mtemp \r\nelse \r\n tautemp = 0.0_DP\r\nend if \r\n!!!\r\nif (abs(mtemp_u) > tresh) then \r\n tautemp_u = -dtemp_u/mtemp_u \r\nelse \r\n tautemp_u = 0.0_DP\r\nend if \r\nif (abs(mtemp_v) > tresh) then \r\n tautemp_v = -dtemp_v/mtemp_v \r\nelse \r\n tautemp_v = 0.0_DP\r\nend if \r\nif (abs(mtemp_w) > tresh) then \r\n tautemp_w = -dtemp_w/mtemp_w \r\nelse \r\n tautemp_w = 0.0_DP\r\nend if \r\n!!!\r\nif (abs(mmom3_u) > tresh) then \r\n taumom3_u = -dmom3_u/mmom3_u \r\nelse \r\n taumom3_u = 0.0_DP\r\nend if \r\nif (abs(mmom3_v) > tresh) then \r\n taumom3_v = -dmom3_v/mmom3_v \r\nelse \r\n taumom3_v = 0.0_DP\r\nend if \r\nif (abs(mmom3_w) > tresh) then \r\n taumom3_w = -dmom3_w/mmom3_w \r\nelse \r\n taumom3_w = 0.0_DP\r\nend if \r\n!!!\r\nif (abs(mmom4_u) > tresh) then \r\n taumom4_u = -dmom4_u/mmom4_u \r\nelse \r\n taumom4_u = 0.0_DP\r\nend if \r\nif (abs(mmom4_v) > tresh) then \r\n taumom4_v = -dmom4_v/mmom4_v \r\nelse \r\n taumom4_v = 0.0_DP\r\nend if \r\nif (abs(mmom4_w) > tresh) then \r\n taumom4_w = -dmom4_w/mmom4_w \r\nelse \r\n taumom4_w = 0.0_DP\r\nend if \r\n!!! \r\nif (abs(mmom5_u) > tresh) then \r\n taumom5_u = -dmom5_u/mmom5_u \r\nelse \r\n taumom5_u = 0.0_DP\r\nend if \r\nif (abs(mmom5_v) > tresh) then \r\n taumom5_v = -dmom5_v/mmom5_v \r\nelse \r\n taumom5_v = 0.0_DP\r\nend if \r\nif (abs(mmom5_w) > tresh) then \r\n taumom5_w = -dmom5_w/mmom5_w \r\nelse \r\n taumom5_w = 0.0_DP\r\nend if \r\n!!!\r\nif (abs(mmom6_u) > tresh) then \r\n taumom6_u = -dmom6_u/mmom6_u \r\nelse \r\n taumom6_u = 0.0_DP\r\nend if \r\nif (abs(mmom6_v) > tresh) then \r\n taumom6_v = -dmom6_v/mmom6_v \r\nelse \r\n taumom6_v = 0.0_DP\r\nend if \r\nif (abs(mmom6_w) > tresh) then \r\n taumom6_w = -dmom6_w/mmom6_w \r\nelse \r\n taumom6_w = 0.0_DP\r\nend if \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n!! Next we will need to put the \r\n!! calculated quatities in the storage array... \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\ni = int(MomDerivRelaxT(1)) ! Number of records\r\nk = int(MomDerivRelaxT(2)) ! number of columns in the record\r\nj = 2+i*k ! now the index j points to the last filled cell. The first new record can be placed in the following cell.\r\n! A quick check if there is enought room for storing the computed values. \r\nif (j+k > size(MomDerivRelaxT,1)) then \r\n print *, \"RecordMomDerivRelaxTimes_DGV: Not enough memory in (MomDerivRelaxT) to store moments derivs. and relax. times.\"\r\nelse \r\n MomDerivRelaxT(1) = Real(i)+1.0 \r\n !!! Time\r\n MomDerivRelaxT(j+1)=curr_time\r\n !!!! First will go the derivatives of macroparameters. \r\n MomDerivRelaxT(j+2)=dn\r\n !!!\r\n MomDerivRelaxT(j+3)=dubar\r\n MomDerivRelaxT(j+4)=dvbar\r\n MomDerivRelaxT(j+5)=dwbar\r\n !!!\r\n MomDerivRelaxT(j+6)=dtemp\r\n !!!\r\n MomDerivRelaxT(j+7)=dtemp_u\r\n MomDerivRelaxT(j+8)=dtemp_v\r\n MomDerivRelaxT(j+9)=dtemp_w\r\n !!!\r\n MomDerivRelaxT(j+10)=dmom3_u\r\n MomDerivRelaxT(j+11)=dmom3_v\r\n MomDerivRelaxT(j+12)=dmom3_w\r\n !!!\r\n MomDerivRelaxT(j+13)=dmom4_u\r\n MomDerivRelaxT(j+14)=dmom4_v\r\n MomDerivRelaxT(j+15)=dmom4_w\r\n !!!\r\n MomDerivRelaxT(j+16)=dmom5_u\r\n MomDerivRelaxT(j+17)=dmom5_v\r\n MomDerivRelaxT(j+18)=dmom5_w\r\n !!!\r\n MomDerivRelaxT(j+19)=dmom6_u\r\n MomDerivRelaxT(j+20)=dmom6_v\r\n MomDerivRelaxT(j+21)=dmom6_w\r\n !!!\r\n !! Next go the frequences for the same moments\r\n !!!\r\n MomDerivRelaxT(j+22)=taun\r\n !!!\r\n MomDerivRelaxT(j+23)=tauubar\r\n MomDerivRelaxT(j+24)=tauvbar\r\n MomDerivRelaxT(j+25)=tauwbar\r\n !!!\r\n MomDerivRelaxT(j+26)=tautemp\r\n !!!\r\n MomDerivRelaxT(j+27)=tautemp_u\r\n MomDerivRelaxT(j+28)=tautemp_v\r\n MomDerivRelaxT(j+29)=tautemp_w\r\n !!!\r\n MomDerivRelaxT(j+30)=taumom3_u\r\n MomDerivRelaxT(j+31)=taumom3_v\r\n MomDerivRelaxT(j+32)=taumom3_w\r\n !!!\r\n MomDerivRelaxT(j+33)=taumom4_u\r\n MomDerivRelaxT(j+34)=taumom4_v\r\n MomDerivRelaxT(j+35)=taumom4_w\r\n !!!\r\n MomDerivRelaxT(j+36)=taumom5_u\r\n MomDerivRelaxT(j+37)=taumom5_v\r\n MomDerivRelaxT(j+38)=taumom5_w\r\n !!!\r\n MomDerivRelaxT(j+39)=taumom6_u\r\n MomDerivRelaxT(j+40)=taumom6_v\r\n MomDerivRelaxT(j+41)=taumom6_w\r\n !!!!!!!!!!!!!!!!!!!!\r\nend if \r\n\r\n!!! if the time(current time) is bigger than the final time t_R, then the program will deallocate the array -- this is a cleanup call\r\nif (curr_time > t_R) then\r\n deallocate(MomDerivRelaxT)\r\n MomDerivRelaxT_flag = 0 \r\nend if \r\n!!!!!!!!!!!!\r\nend subroutine RecordMomDerivRelaxTimes_DGV\r\n\r\n\r\n\r\n \r\nend module dgvtools_mod\r\n", "meta": {"hexsha": "02cb72d43739b56a4d2b7d76b0a7ff32b96493a9", "size": 89009, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "dgvtools_mod.f90", "max_stars_repo_name": "alexmalekseenko/DGV0D3V_direct_collision", "max_stars_repo_head_hexsha": "38547223b12b54af3984ff2f96cf4d369777de1f", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "dgvtools_mod.f90", "max_issues_repo_name": "alexmalekseenko/DGV0D3V_direct_collision", "max_issues_repo_head_hexsha": "38547223b12b54af3984ff2f96cf4d369777de1f", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dgvtools_mod.f90", "max_forks_repo_name": "alexmalekseenko/DGV0D3V_direct_collision", "max_forks_repo_head_hexsha": "38547223b12b54af3984ff2f96cf4d369777de1f", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.8684080828, "max_line_length": 210, "alphanum_fraction": 0.6433394376, "num_tokens": 28746, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741281688026, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7554922146530012}} {"text": "\tSUBROUTINE RCUBIC(A2,A1,A0,Z1,Z2,Z3)\nC\nC\tTHIS ROUTINE RETURNS Z1,Z2,Z3 = THREE ROOTS OF THE CUBIC\nC\nC\t\tZ**3 + A2*Z**2 + A1*Z + A0 = 0\nC\n\tCOMPLEX Z1,Z2,Z3\n\tDATA COEF /1.73205081/\n\tDATA PI /3.14159265/\nC\nC\nC\tTRIGONOMETRIC SOLUTION FROM \"MATHEMATICAL HANDBOOK FOR\nC\tSCIENTISTS AND ENGINEERS\" KORN AND KORN, P23 SECT 1.8-4\nC\nC\tNOTATION HERE QLC2 = q/2 in Korn and Korn\nC P3 = p/3 in Korn and Korn\nC\t\t\t Q = same, Q =P3**3 + QLC2**2 = (p/3)**3 + (q/2)**2\nC \n\tIF(A0.EQ.0) THEN\n\t print*,'case a0 = 0'\n\t Z1 = 0.\n\t DISC = A2**2 - 4.*A1\n\t Z2 = .5*(-A2 + CSQRT(CMPLX(DISC,0.)))\n\t Z3 = .5*(-A2 - CSQRT(CMPLX(DISC,0.)))\n\tprint*,'cube roots',z1,z2,z3\n\tprint*,'check sum,product',z1+z2+z3,z1*z2*z3\nC\t RETURN\n\tENDIF\n\tP3 = -(A2**2)/9. + A1/3. \n\tQLC2 = (A2**3)/27. - A1*A2/6. + .5*A0\n\tQ = P3**3 + QLC2**2\n\tprint*,'p3,qlc2,Q',p3,qlc2,q\n\tIF(Q.LT.0.) THEN\nC\tcase (a) certainly p3 is negative\n\t print*,'case a'\n\t COSALF = -QLC2/SQRT(-P3**3)\n\t print*,'cosalf',cosalf\n\t ALPHA = ACOS(COSALF)\n\t print*,'alpha',alpha,180.*alpha/pi\n\t AL3 = ALPHA/3.\n\t SQRTP3 = SQRT(-P3)\n\t Z1 = 2.*SQRTP3*COS(AL3) - A2/3.\n\t Z2 = -2.*SQRTP3*COS(AL3 + PI/3.) - A2/3.\n\t Z3 = -2.*SQRTP3*COS(AL3 - PI/3.) - A2/3.\n\tprint*,'cube roots',z1,z2,z3\n\tprint*,'check sum,product',z1+z2+z3,z1*z2*z3\n\tELSE\n\t IF(P3.GT.0.) THEN\nC\t case (b)\n\t print*,'case b'\n\t TANBET = SQRT(P3**3)/QLC2\n\t BETA2 = .5*ATAN(TANBET)\n\t IF(TANBET.GE.0.) THEN\n\t TANALF = (TAN(BETA2))**(1./3.)\n\t ELSE\n\t TANALF = -(-TAN(BETA2))**(1./3.)\n\t ENDIF\n\t ALPHA = ATAN(TANALF)\n\t SQRTP3 = SQRT(P3)\n\t Z1 = -2.*SQRTP3/TAN(2.*ALPHA) - A2/3.\n\t Z2 = SQRTP3*CMPLX(1./TAN(2.*ALPHA),COEF/SIN(2.*ALPHA)) - A2/3.\n\t Z3 = CONJG(Z2)\n\t ELSE\nC\t case (c)\n\t print*,'case c'\n\t SINBET = SQRT(-P3**3)/QLC2\n\t BETA2 = .5*ASIN(SINBET)\n\t IF(SINBET.GE.0.) THEN\n\t TANALF = (TAN(BETA2))**(1./3.)\n\t ELSE\n\t TANALF = -(-TAN(BETA2))**(1./3.)\n\t ENDIF\n\t ALPHA = ATAN(TANALF)\n\t SQRTP3 = SQRT(-P3)\n\t Z1 = -2.*SQRTP3/SIN(2.*ALPHA)\n\t Z2 = SQRTP3*CMPLX( 1./SIN(2.*ALPHA) , COEF/TAN(2.*ALPHA) )\n\t Z3 = CONJG(Z2)\n\t ENDIF\n\tENDIF\n\tprint*,'cube roots',z1,z2,z3\n\tprint*,'check sum,product',z1+z2+z3,z1*z2*z3\n\tRETURN\n\tEND\n", "meta": {"hexsha": "9a87f29cf42aba3896a5090281e7fc22d621c632", "size": 2304, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/rcubic_26.for", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/rcubic_26.for", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/rcubic_26.for", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.4285714286, "max_line_length": 70, "alphanum_fraction": 0.5364583333, "num_tokens": 1095, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741214369554, "lm_q2_score": 0.7931059560743423, "lm_q1q2_score": 0.7554922093139331}} {"text": "\tSUBROUTINE XYTORT ( x, y, r, theta, iret )\nC************************************************************************\nC* XYTORT\t\t\t\t\t\t\t\t*\nC* \t\t\t\t\t\t\t\t\t*\nC* This subroutine converts x, y in linear coordinates to r, theta \t*\nC* in polar coordinates.\t\t\t\t\t\t*\nC* \t\t\t\t\t\t\t\t\t*\nC* XYTORT ( X, Y, R, THETA, IRET )\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tX\t\tREAL\t\tValue of x\t\t\t*\nC*\tY\t\tREAL\t\tValue of y\t\t\t*\nC* \t\t\t\t\t\t\t\t\t*\nC* Output parameters: \t\t\t\t\t\t\t*\nC*\tR\t\tREAL\t\tValue of r\t\t\t*\nC*\tTHETA\t\tREAL\t\tValue of theta in degrees\t*\nC* \tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. desJardins/GSFC\t10/86\t\t\t\t\t\t*\nC* K. Brill/EMC\t\t 3/96\tInput and output variables can be same\t*\nC************************************************************************\n\tINCLUDE\t\t'ERROR.PRM'\n\tINCLUDE\t\t'GEMPRM.PRM'\nC--------------------------------------------------------------------------\n\tiret = NORMAL\nC\nC*\tDo transformations.\nC\n\trr = SQRT ( x**2 + y**2 )\n\tIF ( (x .eq. 0.) .and. (y .eq. 0.) ) THEN\n\t th = 0.\n\t ELSE\n\t th = ( ATAN2 ( y, x ) ) * RTD\n\t IF ( th .lt. 0. ) th = th + TWOPI\n\tEND IF\n\tr = rr\n\ttheta = th\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "3320903e5cf1ed9393fe0b12bbd3b2dcc35e466d", "size": 1137, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/gplt/transform/xytort.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/gplt/transform/xytort.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/gplt/transform/xytort.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 27.0714285714, "max_line_length": 75, "alphanum_fraction": 0.4204045734, "num_tokens": 389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7554667592075053}} {"text": "module module_math\n implicit none\n\n private\n public factorial\n\ncontains\n\n recursive real(8) function factorial(n) result(out)\n integer,intent(in) :: n\n\n if(n.lt.0) then\n stop \"aho\"\n elseif(n.eq.1.or.n.eq.0) then\n out=1.d0\n else\n out=dble(n)*factorial(n-1)\n end if\n end function factorial\n \nend module module_math\n\n", "meta": {"hexsha": "8c929ff7f47b833dbaa4a123eaafb9ad529b6ee2", "size": 353, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gtq_quadp/src/module_math.f90", "max_stars_repo_name": "isakari/gtq_quadp", "max_stars_repo_head_hexsha": "b6b6c7ade6c96cc1f07230dc7d15b3b49fd2a313", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "gtq_quadp/src/module_math.f90", "max_issues_repo_name": "isakari/gtq_quadp", "max_issues_repo_head_hexsha": "b6b6c7ade6c96cc1f07230dc7d15b3b49fd2a313", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gtq_quadp/src/module_math.f90", "max_forks_repo_name": "isakari/gtq_quadp", "max_forks_repo_head_hexsha": "b6b6c7ade6c96cc1f07230dc7d15b3b49fd2a313", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.347826087, "max_line_length": 53, "alphanum_fraction": 0.6430594901, "num_tokens": 103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7553471656445653}} {"text": " subroutine J2Invariant(J2, dev_stress)\n!***********************************************************************\n! Copyright 2011 Los Alamos National Security, LLC All rights reserved\n! Unless otherwise indicated, this information has been authored by an\n! employee or employees of the Los Alamos National Security, LLC (LANS),\n! operator of the Los Alamos National Laboratory under Contract No.\n! DE-AC52-06NA25396 with the U. S. Department of Energy. The U. S.\n! Government has rights to use, reproduce, and distribute this\n! information. The public may copy and use this information without\n! charge, provided that this Notice and any statement of authorship are\n! reproduced on all copies. Neither the Government nor LANS makes any\n! warranty, express or implied, or assumes any liability or\n! responsibility for the use of this information.\n!***********************************************************************\n!\n! Returns the J2-Invariant for a six-component deviatoric stress tensor\n!\n! Author : Sai Rapaka\n!\n\n implicit none\n real*8, dimension(6) :: dev_stress\n real*8 J2\n real*8 pressure\n\n pressure = (dev_stress(1) + dev_stress(2) + dev_stress(3))/3.0d0\n dev_stress(1) = dev_stress(1) - pressure\n dev_stress(2) = dev_stress(2) - pressure\n dev_stress(3) = dev_stress(3) - pressure\n\n J2 = 0.0d0\n J2 = 0.5d0*sum(dev_stress(1:3)**2) + sum(dev_stress(4:6)**2)\n\n end subroutine J2Invariant\n", "meta": {"hexsha": "413dbfb0c638a1f561b860c2a5685a50fcb28c1e", "size": 1509, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/J2Invariant.f", "max_stars_repo_name": "satkarra/FEHM", "max_stars_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2018-08-09T04:55:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T21:46:32.000Z", "max_issues_repo_path": "src/J2Invariant.f", "max_issues_repo_name": "satkarra/FEHM", "max_issues_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2018-04-06T16:17:14.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T04:40:14.000Z", "max_forks_repo_path": "src/J2Invariant.f", "max_forks_repo_name": "satkarra/FEHM", "max_forks_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2018-06-07T21:11:55.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-11T13:48:22.000Z", "avg_line_length": 43.1142857143, "max_line_length": 72, "alphanum_fraction": 0.6275679258, "num_tokens": 411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159727, "lm_q2_score": 0.826711791935942, "lm_q1q2_score": 0.7553471636941114}} {"text": "subroutine apply_linearized_pde_operator(t, q, p, output)\n\n! For the PDE q_t = g(q), calculates g'[q](p), i.e. the linearization\n! of g, about q, applied to perturbation p\n!\n! Args:\n! t: Time at which the operator is evaluated.\n! q: Base function of the linearization.\n! p: Perturbation to which the linearized operator is applied.\n! output: g'[q](p), calculated here.\n\n implicit none\n\n integer :: mx, mbc, meqn\n double precision :: dx, x_lower\n common /claw_config/ mx, mbc, x_lower, dx, meqn\n \n double precision, intent(in) :: t\n double precision, dimension(1-mbc:mx+mbc, meqn), intent(in) :: q, p\n double precision, dimension(1-mbc:mx+mbc, meqn), intent(out) :: output\n\n double precision, dimension(1-mbc:mx+mbc, meqn) :: temp1, temp2\n\n double precision :: epsilon, norm_p\n double precision, external :: l2_norm\n integer :: ix\n\n norm_p = l2_norm(p)\n epsilon = 1d-3 / norm_p\n\n temp1 = q + epsilon * p\n call apply_pde_operator(t, temp1, output)\n temp1 = q - epsilon * p\n call apply_pde_operator(t, temp1, temp2)\n do ix = 1, mx\n output(ix, 1) = (output(ix, 1) - temp2(ix, 1)) / (2 * epsilon)\n end do\n\nend subroutine apply_linearized_pde_operator\n", "meta": {"hexsha": "9d1778bd0146479247ba68657ea585b75883732c", "size": 1221, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "implicit_claw/1d/apply_linearized_pde_operator-approximate.f90", "max_stars_repo_name": "claridge/implicit_solvers", "max_stars_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-04-29T00:16:18.000Z", "max_stars_repo_stars_event_max_datetime": "2017-04-29T00:16:18.000Z", "max_issues_repo_path": "implicit_claw/1d/apply_linearized_pde_operator-approximate.f90", "max_issues_repo_name": "claridge/implicit_solvers", "max_issues_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "implicit_claw/1d/apply_linearized_pde_operator-approximate.f90", "max_forks_repo_name": "claridge/implicit_solvers", "max_forks_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.525, "max_line_length": 74, "alphanum_fraction": 0.6576576577, "num_tokens": 381, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676514011486, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.7553471520491283}} {"text": "module primes_mod\n implicit none\n\n private\n public :: is_prime\n\ncontains\n\n function is_prime(n) result(prime)\n implicit none\n integer, value :: n\n logical :: prime\n integer :: i\n\n if (n > 1) then\n prime = .true.\n do i = 2, nint(sqrt(real(n)))\n if (mod(n, i) == 0) then\n prime = .false.\n exit\n end if\n end do\n else\n prime = .false.\n end if\n end function is_prime\n\nend module primes_mod\n", "meta": {"hexsha": "a1da6f9d394726ca68d5f187969ea8aafbd98e03", "size": 561, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/primes/primes_mod.f90", "max_stars_repo_name": "caguerra/Fortran-MOOC", "max_stars_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-05-20T12:03:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T19:46:26.000Z", "max_issues_repo_path": "source_code/primes/primes_mod.f90", "max_issues_repo_name": "caguerra/Fortran-MOOC", "max_issues_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-30T04:25:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T08:21:30.000Z", "max_forks_repo_path": "source_code/primes/primes_mod.f90", "max_forks_repo_name": "caguerra/Fortran-MOOC", "max_forks_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-09-27T07:30:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T16:23:19.000Z", "avg_line_length": 19.3448275862, "max_line_length": 41, "alphanum_fraction": 0.4581105169, "num_tokens": 134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7553471520346933}} {"text": "! ********************************************************************\r\n! * *\r\n! * function beta *\r\n! * *\r\n! ********************************************************************\r\n! Single Precision Version 2.0\r\n! Written by Gordon A. Fenton, TUNS, Apr. 13, 1993\r\n!\r\n! PURPOSE returns the Beta distribution function for given x and parameters\r\n! alpha and beta.\r\n!\r\n! This routine employs a continued fraction solution to compute the\r\n! cumulative probability associated with a variable following the Beta\r\n! distribution (also called the incomplete beta function),\r\n!\r\n! G(a+b) x\r\n! F(x) = --------- INT (1-t)**(b-1) * t**(a-1) dt\r\n! G(a)*G(b) 0\r\n!\r\n! where G(a) is the Gamma function ((a-1)! if `a' is an integer).\r\n! The algorithm follows that proposed by Press etal in \"Numerical Recipes\r\n! in C\", pg 178.\r\n! Arguments to the routine are as follows;\r\n!\r\n! x real value giving the position at which the cumulative distribution\r\n! is desired. (input)\r\n!\r\n! a the alpha parameter of the Beta distribution. (input)\r\n!\r\n! b the beta parameter of the Beta distribution. (input)\r\n!\r\n! NOTES: 1) TOL is the acceptable relative error tolerance.\r\n! 2) set IDEBUG = 1 if error messages should be written out.\r\n! 3) IMAX is the maximum number of iterations allowed.\r\n!---------------------------------------------------------------------------\r\n real function betaf(x,a,b)\r\n parameter (IDEBUG = 1, IMAX = 200, TOL = 1.e-6 )\r\n data zero/0.0/, one/1.0/, two/2.0/\r\n 1 format(a)\r\n!\t\t\t\tcheck input data\r\n if( x .le. zero ) then\r\n betaf = zero\r\n return\r\n elseif( x .ge. one ) then\r\n betaf = one\r\n return\r\n endif\r\n\r\n ab = (one + a)/(a + b + two)\r\n bt = exp(gamln(a+b)-gamln(a)-gamln(b)+a*alog(x)+b*alog(one-x))\r\n if( x .lt. ab ) then\r\n xx = x\r\n aa = a\r\n bb = b\r\n st = zero\r\n else\r\n xx = one - x\r\n aa = b\r\n bb = a\r\n st = one\r\n bt = -bt\r\n endif\r\n!\t\t\t\tnow use the continued fraction (Press etal.)\r\n am = one\r\n bm = one\r\n az = one\r\n qab = aa + bb\r\n qap = aa + one\r\n qam = aa - one\r\n bz = one - qab*xx/qap\r\n do 10 m = 1, IMAX\r\n em = float(m)\r\n tem = em + em\r\n d = em*(bb-m)*xx/((qam+tem)*(aa+tem))\r\n ap = az + d*am\r\n bp = bz + d*bm\r\n d =-(aa+em)*(qab+em)*xx/((aa+tem)*(qap+tem))\r\n app = ap + d*az\r\n bpp = bp + d*bz\r\n aold = az\r\n am = ap/bpp\r\n bm = bp/bpp\r\n az = app/bpp\r\n bz = one\r\n if( abs((az-aold)/az) .lt. TOL )go to 20\r\n 10 continue\r\n if( IDEBUG .eq. 1 ) &\r\n write(0,1)'betaf couldn''t converge to a solution.'\r\n\r\n 20 betaf = st + bt*az/aa\r\n return\r\n end\r\n", "meta": {"hexsha": "c485a45f25e78f0e2a94f50bcc23ffe1aca97e38", "size": 3135, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/gaf95/beta.f95", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/gaf95/beta.f95", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/gaf95/beta.f95", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.7096774194, "max_line_length": 78, "alphanum_fraction": 0.4303030303, "num_tokens": 855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475810629194, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.7553308700834626}} {"text": "module randomm\nuse types\n\nimplicit none\nprivate\npublic gasdev\n\ncontains\n\n!! gasdev : Returns a normally distributed deviate with zero mean and unit variance from Numerical recipes\nreal(dp) function gasdev()\n real(dp) :: v1, v2, fac, rsq\n real(dp), save :: gset\n\n logical, save :: available = .false.\n\n if (available) then\n gasdev = gset\n available = .false.\n else\n do\n call random_number(v1)\n call random_number(v2)\n v1 = 2.0_dp*v1-1.0_dp\n v2 = 2.0_dp*v2-1.0_dp\n rsq = v1*v1 + v2*v2\n if ((rsq > 0.0_dp) .and. (rsq < 1.0_dp)) exit\n end do\n fac = sqrt(-2.0_dp * log(rsq) / rsq)\n gasdev = v1 * fac\n gset = v2 * fac\n available = .true.\n end if\nend function gasdev\n\nend module randomm", "meta": {"hexsha": "5a902181168e020561dc0873542fe674050d006a", "size": 819, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "include/random.f90", "max_stars_repo_name": "edwinb-ai/brownian-dynamics", "max_stars_repo_head_hexsha": "4f072f58ada42c7dc34aa6b348a06ece8dc358fc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "include/random.f90", "max_issues_repo_name": "edwinb-ai/brownian-dynamics", "max_issues_repo_head_hexsha": "4f072f58ada42c7dc34aa6b348a06ece8dc358fc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "include/random.f90", "max_forks_repo_name": "edwinb-ai/brownian-dynamics", "max_forks_repo_head_hexsha": "4f072f58ada42c7dc34aa6b348a06ece8dc358fc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.75, "max_line_length": 106, "alphanum_fraction": 0.568986569, "num_tokens": 255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998822, "lm_q2_score": 0.8289388062084421, "lm_q1q2_score": 0.7553122190592036}} {"text": "! Objetivo: Integrar a equacao diferencial que descreve o oscilador de Van der Pol \n! e analisar o espectro_de_f de frequencias de sua transformada de Fourier\n\nMODULE derivada\n\tREAL, PARAMETER :: mu=1.0,omega0=1.0,y0=1.0\nCONTAINS\n\tSUBROUTINE deriv_func_vanderpol(t,y,dydt)\n\t\tUSE nrtype\n \t\tIMPLICIT NONE\n \t\tREAL, INTENT(IN) :: t\n \t\tREAL, DIMENSION(:), INTENT(IN) :: y\n \t\tREAL, DIMENSION(:), INTENT(OUT) :: dydt\n \t\tdydt(1)= y(2)\n \t\tdydt(2)= mu*y(2)*(y0**2-(y(1))**2)-y(1)*omega0**2\n\tEND SUBROUTINE\nEND MODULE derivada\nPROGRAM FFT\n\tUSE nrtype\n\tUSE derivada\n\tUSE nr, ONLY : mmid,bsstep,odeint,four1,fourrow\n\tINTEGER, PARAMETER :: arquivo_saida1=8,arquivo_saida2=9,num_pontos=512,&\n\t\t\t\t\t\tnum_pontos_sob2=num_pontos/2\n\tREAL, PARAMETER :: x_inicial=2.0,t_inicial=0.0,v_inicial=0.0,&\n\t\t\t\treal_num_pontos=real(num_pontos), eps=1.0e-4 \n\tINTEGER :: contador\n\tREAL :: x1,x2,hmin=0.0,h1,f,deltaf,espectro_de_f\n\tCHARACTER(len=80) :: x_versus_t, delta_t\n\tCOMPLEX, DIMENSION(num_pontos) :: DATA\n\tREAL, DIMENSION(2) :: ystart\n\n\tPRINT *, \"Digite o intervalo do tempo?\"\n\tREAD *, h1\n! Criando o nome do arquivo de dados \n\tWRITE(x_versus_t,'(\"x_versus_t=\",f8.6,\".dat\")')h1\n\tWRITE(delta_t,'(\"delta_t=\",f8.6,\".dat\")')h1\n\tOPEN(unit=arquivo_saida1,file=x_versus_t)\n\tOPEN(unit=arquivo_saida2,file=delta_t) \n\tystart(1)=x_inicial\n\tystart(2)=v_inicial\n\tx1=t_inicial\n\tx2=x1+h1\n\tDO contador=1,num_pontos\n\t\tCALL odeint(ystart,x1,x2,eps,h1,hmin,deriv_func_vanderpol,bsstep)\n\t\tWRITE(arquivo_saida1,*) x2,ystart(1)\n\t\tDATA(contador)=cmplx(ystart(1))\n\t\tx1=x2\n\t\tx2=x1+h1\n\tEND DO\n\tCALL four1(DATA,1)\n\tdeltaf=1.0/(real_num_pontos*h1)\n\tf=0.0\n\tespectro_de_f=ABS(DATA(1))\n\tWRITE(arquivo_saida2,*) f,espectro_de_f\n\tf=f+deltaf\n! Escrevendo o espectro_de_f de frequencia versus a frequencia\n\tDO contador=2,num_pontos_sob2\n\t\tespectro_de_f=ABS(DATA(contador))+ABS(DATA(num_pontos-contador+2))\n\t\tWRITE(arquivo_saida2,*) f,espectro_de_f\n\t\tf=f+deltaf\n\tEND DO\nEND PROGRAM FFT\n", "meta": {"hexsha": "261bd212b0822cc6a80fd41b3a7b0745198bddb0", "size": 1966, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exercicio_9.f90", "max_stars_repo_name": "GuilhermeMonteiroPeixoto/Computational-Physics-using-Fortran", "max_stars_repo_head_hexsha": "3d2b3dd87d99b451aed5fe1e9e99813390396485", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exercicio_9.f90", "max_issues_repo_name": "GuilhermeMonteiroPeixoto/Computational-Physics-using-Fortran", "max_issues_repo_head_hexsha": "3d2b3dd87d99b451aed5fe1e9e99813390396485", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exercicio_9.f90", "max_forks_repo_name": "GuilhermeMonteiroPeixoto/Computational-Physics-using-Fortran", "max_forks_repo_head_hexsha": "3d2b3dd87d99b451aed5fe1e9e99813390396485", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.7096774194, "max_line_length": 84, "alphanum_fraction": 0.7141403866, "num_tokens": 775, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.7552975084713007}} {"text": "! Compute pi using OpenMP\n! First, the pseudorandom number generator\n real function lcgrandom()\n integer*8, parameter :: MULTIPLIER = 1366\n integer*8, parameter :: ADDEND = 150889\n integer*8, parameter :: PMOD = 714025\n integer*8, save :: random_last = 0\n\n integer*8 :: random_next = 0\n random_next = mod((MULTIPLIER * random_last + ADDEND), PMOD)\n random_last = random_next\n lcgrandom = (1.0*random_next)/PMOD\n return\n end\n\n! Now, we compute pi\n program darts\n implicit none\n integer*8 :: num_trials = 1000000, i = 0, Ncirc = 0\n real :: pi = 0.0, x = 0.0, y = 0.0, r = 1.0\n real :: r2 = 0.0\n real :: lcgrandom\n r2 = r*r\n\n!$OMP parallel private(x,y) reduction(+:Ncirc)\n!$OMP do\n do i = 1, num_trials\n!$OMP critical (randoms)\n x = lcgrandom()\n y = lcgrandom()\n!$OMP end critical (randoms)\n if ((x*x + y*y) .le. r2) then\n Ncirc = Ncirc+1\n end if\n end do\n!$OMP end parallel\n\n pi = 4.0*((1.0*Ncirc)/(1.0*num_trials))\n print*, ' '\n print*, ' Computing pi using OpenMP: '\n print*, ' For ', num_trials, ' trials, pi = ', pi\n print*, ' '\n\n end\n\n", "meta": {"hexsha": "5f0b220ee0d5c6c417a78633e1358523463f2c79", "size": 1344, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "darts/openmp/fortran/darts-omp.f", "max_stars_repo_name": "PawseySC/Intermediate-Supercomputing", "max_stars_repo_head_hexsha": "2adfdbe994d1a07491ffee783bfd2a2c03f03e7e", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-04-06T02:57:44.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-27T22:01:11.000Z", "max_issues_repo_path": "darts/openmp/fortran/darts-omp.f", "max_issues_repo_name": "PawseySupercomputing/Intermediate-Supercomputing", "max_issues_repo_head_hexsha": "28252556226354ef9a01178d6ebb54757b0bea2f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-09T07:20:40.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-22T04:23:27.000Z", "max_forks_repo_path": "darts/openmp/fortran/darts-omp.f", "max_forks_repo_name": "PawseySupercomputing/Intermediate-Supercomputing", "max_forks_repo_head_hexsha": "28252556226354ef9a01178d6ebb54757b0bea2f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-03-01T05:56:44.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:54:39.000Z", "avg_line_length": 29.2173913043, "max_line_length": 70, "alphanum_fraction": 0.5014880952, "num_tokens": 400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7552975082966866}} {"text": "C\nC\t$Id: css2c.f,v 1.4 2008-07-27 03:10:07 haley Exp $\nC \nC Copyright (C) 2000\nC University Corporation for Atmospheric Research\nC All Rights Reserved\nC\nC The use of this Software is governed by a License Agreement.\nC\n SUBROUTINE CSS2C (N,RLAT,RLON, X,Y,Z)\n INTEGER N\n REAL RLAT(N), RLON(N), X(N), Y(N), Z(N)\nC\nC This subroutine transforms spherical coordinates into\nC Cartesian coordinates on the unit sphere.\nC\nC On input:\nC\nC N = Number of nodes (points on the unit sphere)\nC whose coordinates are to be transformed.\nC\nC RLAT = Array of length N containing latitudinal\nC coordinates of the nodes in degrees.\nC\nC RLON = Array of length N containing longitudinal\nC coordinates of the nodes in degrees.\nC\nC The above parameters are not altered by this routine.\nC\nC X,Y,Z = Arrays of length at least N.\nC\nC On output:\nC\nC X,Y,Z = Cartesian coordinates in the range -1 to 1.\nC X(I)**2 + Y(I)**2 + Z(I)**2 = 1 for I = 1\nC to N.\nC\nC Modules required by CSS2C: None\nC\nC Intrinsic functions called by CSS2C: SIN, COS\nC\nC***********************************************************\nC\n PARAMETER (D2R=0.017453293, R2D=57.295778)\n INTEGER I, NN\n REAL COSPHI, PHI, THETA\nC\nC Local parameters:\nC\nC COSPHI = cos(PHI)\nC I = DO-loop index\nC NN = Local copy of N\nC PHI = Latitude\nC THETA = Longitude\nC\n NN = N\n DO 1 I = 1,NN\n RLATD = D2R*RLAT(I)\n RLOND = D2R*RLON(I)\n PHI = RLATD\n THETA = RLOND\n COSPHI = COS(PHI)\n X(I) = COSPHI*COS(THETA)\n Y(I) = COSPHI*SIN(THETA)\n Z(I) = SIN(PHI)\n 1 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "d4c8209848ed2f478f22b16abc472f77292eace9", "size": 1821, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ngmath/src/lib/gridpack/cssgrid/css2c.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ngmath/src/lib/gridpack/cssgrid/css2c.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ngmath/src/lib/gridpack/cssgrid/css2c.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 26.3913043478, "max_line_length": 71, "alphanum_fraction": 0.5579352004, "num_tokens": 542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7552974965301078}} {"text": "! test_bobyqa.f90 --\n!\n! Test problem for BOBYQA, the objective function being the sum of\n! the reciprocals of all pairwise distances between the points P_I,\n! I=1,2,...,M in two dimensions, where M=N/2 and where the components\n! of P_I are X(2*I-1) and X(2*I). Thus each vector X of N variables\n! defines the M points P_I. The initial X gives equally spaced points\n! on a circle. Four different choices of the pairs (N,NPT) are tried,\n! namely (10,16), (10,21), (20,26) and (20,41). Convergence to a local\n! minimum that is not global occurs in both the N=10 cases. The details\n! of the results are highly sensitive to computer rounding errors. The\n! choice IPRINT=2 provides the current X and optimal F so far whenever\n! RHO is reduced. The bound constraints of the problem require every\n! component of X to be in the interval [-1,1].\n!\nmodule bobyqa_functions\n use bobyqa_minimisation, only: wp\n implicit none\n\ncontains\nsubroutine calfun (x,f)\n real(kind=wp), dimension(:) :: x\n real(kind=wp) :: f\n\n integer :: i, j, n\n real(kind=wp) :: temp\n\n n = size(x)\n f = 0.0d0\n do i = 4,n,2\n do j=2,i-2,2\n temp = (x(i-1)-x(j-1))**2+(x(i)-x(j))**2\n temp = max( temp, 1.0d-6 )\n f = f + 1.0d0 / sqrt(temp)\n enddo\n enddo\nend subroutine calfun\nend module bobyqa_functions\n\nprogram test_bobyqa\n use bobyqa_minimisation\n use bobyqa_functions\n\n implicit none\n real(kind=wp), dimension(100) :: x, xl, xu\n real(kind=wp) :: twopi, bdl, bdu, rhobeg, rhoend, temp\n integer :: iprint, maxfun\n integer :: m, n, j, jcase, npt\n\n twopi = 8.0d0 * atan(1.0d0)\n bdl = -1.0d0\n bdu = 1.0d0\n iprint = 2\n maxfun = 500000\n rhobeg = 1.0d-1\n rhoend = 1.0d-6\n\n m = 5\n do while ( m <= 10 )\n n = 2 * m\n xl = bdl\n xu = bdu\n\n do jcase = 1,2\n npt = n + 6\n if ( jcase == 2 ) npt = 2 * n + 1\n print 30, m,n,npt\n 30 format (//5x,'2d output with m =',i4,', n =',i4, &\n ' and npt =',i4)\n do j = 1,m\n temp = real(j,wp) * twopi / real(m,wp)\n x(2*j-1) = cos(temp)\n x(2*j) = sin(temp)\n enddo\n\n call bobyqa( npt, x(1:n), xl(1:n), xu(1:n), rhobeg, rhoend, iprint, maxfun, calfun)\n enddo\n m = 2 * m\n enddo\nend program\n", "meta": {"hexsha": "2219256f771b0741455c1833bbf52d8f86854bfe", "size": 2556, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/computing/test_bobyqa.f90", "max_stars_repo_name": "timcera/flibs_from_svn", "max_stars_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2017-01-16T11:28:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-04T15:58:19.000Z", "max_issues_repo_path": "tests/computing/test_bobyqa.f90", "max_issues_repo_name": "timcera/flibs_from_svn", "max_issues_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/computing/test_bobyqa.f90", "max_forks_repo_name": "timcera/flibs_from_svn", "max_forks_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-06-08T07:29:08.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-24T02:07:22.000Z", "avg_line_length": 31.5555555556, "max_line_length": 95, "alphanum_fraction": 0.5316901408, "num_tokens": 854, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7551914523087402}} {"text": " SUBROUTINE REALFT (DATA, N, ISIGN)\n!\n! Numerical recipes FFT of a real function routine.\n!\n! Calculates the Fourier transform of a set of n real-valued data points.\n! Replaces this data by the positive frequency half of its complex Fourier\n! transform. The real valued first and last components of the complex transform are\n! returned as data(1) and data(2). n must be a power of 2. For isign=-1 the\n! inverse transform is returned and must be multiplied by 2/n.\n!\n REAL(8) WR, WI, WPR, WPI, WTEMP, THETA\n REAL(4) DATA ( * )\n THETA = 3.141592653589793D0 / DBLE (N / 2)\n C1 = 0.5\n IF (ISIGN.EQ.1) THEN\n C2 = - 0.5\n CALL FOUR1 (DATA, N / 2, + 1)\n ELSE\n C2 = 0.5\n THETA = - THETA\n ENDIF\n WPR = - 2.0D0 * DSIN (0.5D0 * THETA) **2\n WPI = DSIN (THETA)\n WR = 1.0D0 + WPR\n WI = WPI\n N2P3 = N + 3\n DO 11 I = 2, N / 4\n I1 = 2 * I - 1\n I2 = I1 + 1\n I3 = N2P3 - I2\n I4 = I3 + 1\n WRS = SNGL (WR)\n WIS = SNGL (WI)\n H1R = C1 * (DATA (I1) + DATA (I3) )\n H1I = C1 * (DATA (I2) - DATA (I4) )\n H2R = - C2 * (DATA (I2) + DATA (I4) )\n H2I = C2 * (DATA (I1) - DATA (I3) )\n DATA (I1) = H1R + WRS * H2R - WIS * H2I\n DATA (I2) = H1I + WRS * H2I + WIS * H2R\n DATA (I3) = H1R - WRS * H2R + WIS * H2I\n DATA (I4) = - H1I + WRS * H2I + WIS * H2R\n WTEMP = WR\n WR = WR * WPR - WI * WPI + WR\n WI = WI * WPR + WTEMP * WPI + WI\n11 END DO\n IF (ISIGN.EQ.1) THEN\n H1R = DATA (1)\n DATA (1) = H1R + DATA (2)\n DATA (2) = H1R - DATA (2)\n ELSE\n H1R = DATA (1)\n DATA (1) = C1 * (H1R + DATA (2) )\n DATA (2) = C1 * (H1R - DATA (2) )\n CALL FOUR1 (DATA, N / 2, - 1)\n ENDIF\n RETURN\n END SUBROUTINE REALFT\n", "meta": {"hexsha": "7f2e0fffc21c6abd07146993061a40b97187b136", "size": 1871, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fft/REALFT.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/fft/REALFT.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/fft/REALFT.f90", "max_forks_repo_name": "apengsigkarup/OceanWave3D", "max_forks_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-01T12:17:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T16:23:37.000Z", "avg_line_length": 32.2586206897, "max_line_length": 84, "alphanum_fraction": 0.4879743453, "num_tokens": 745, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567085, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.7551644770722651}} {"text": "program tarefac\n implicit real(8) (a-h,o-z)\n\n dt = 0.001d0\n tmax = 120d0\n\n g = 9.8d0\n a_l = 9.8d0\n gama = 0.5d0\n Omega = 2d0/3d0\n \n write(*,*) 'Entre com o valor de F0:'\n read(*,*) F0\n\n open(10, file='saida-c-10407962.dat')\n\n theta_i1 = 0.2d0\n omega_i1 = 0d0\n theta_i2 = theta_i1 + 0.001d0\n omega_i2 = omega_i1\n i = 0\n n = 0\n a_lyapunov = 0d0\n\n do while ( i*dt.le.tmax )\n\n dw_i1 = dw(g, a_l, theta_i1, gama, omega_i1, F0, Omega, dt*i)\n call oscilacao(theta_i1, omega_i1, dw_i1, dt)\n \n dw_i2 = dw(g, a_l, theta_i2, gama, omega_i2, F0, Omega, dt*i)\n call oscilacao(theta_i2, omega_i2, dw_i2, dt)\n\n deltaTheta = abs(theta_i2-theta_i1)\n a_lyapunov_i = log(deltaTheta)/(i*dt)\n\n if (((i*dt).gt.(tmax/2)).and.(abs(a_lyapunov_i).lt.9d300)) then\n a_lyapunov = a_lyapunov + a_lyapunov_i\n n = n + 1\n end if\n \n write(10, *) i*dt, deltaTheta\n \n i = i+1\n end do\n\n close(10)\n \n print *, F0, a_lyapunov/n\n\ncontains\n function dw(g, a_l, theta, gama, dTheta, F0, Omega, t)\n implicit real(8) (a-h,o-z)\n dw = -(g/a_l)*sin(theta) -gama*dTheta +F0*sin(Omega*t)\n return\n end function\n\n subroutine oscilacao(theta_i, omega_i, dw_i, dt)\n implicit real(8) (a-h,o-z)\n parameter (pi = 4d0*atan(1d0))\n omega_i = omega_i +dw_i*dt\n theta_i = theta_i +omega_i*dt\n\n do while (abs(theta_i).ge.pi)\n sinal = theta_i/abs(theta_i)\n theta_i = theta_i -sinal*2*pi\n end do\n return\n end subroutine\n\nend program tarefac\n", "meta": {"hexsha": "7252d0d3c528c8214497f687cf0074aadc70991e", "size": 1667, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "projeto-5/tarefa-c/tarefa-c-10407962.f90", "max_stars_repo_name": "ArexPrestes/introducao-fisica-computacional", "max_stars_repo_head_hexsha": "bf6e7a0134c11ddbaf9125c42eb0982250f970d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "projeto-5/tarefa-c/tarefa-c-10407962.f90", "max_issues_repo_name": "ArexPrestes/introducao-fisica-computacional", "max_issues_repo_head_hexsha": "bf6e7a0134c11ddbaf9125c42eb0982250f970d9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "projeto-5/tarefa-c/tarefa-c-10407962.f90", "max_forks_repo_name": "ArexPrestes/introducao-fisica-computacional", "max_forks_repo_head_hexsha": "bf6e7a0134c11ddbaf9125c42eb0982250f970d9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.4788732394, "max_line_length": 71, "alphanum_fraction": 0.5482903419, "num_tokens": 616, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.822189121808099, "lm_q1q2_score": 0.7551644670678898}} {"text": "\nc\nc =================================================\n double precision function psi(x,y)\nc =================================================\nc\nc # stream function \n\n implicit double precision (a-h,o-z)\n common /compsi/ pi\n\n psi = ((dsin(pi*x))**2 * (dsin(pi*y))**2) / pi\nc\n return\n end\n\n", "meta": {"hexsha": "0c05ad34a61dfea4ea6cd4c676130b15948b200b", "size": 331, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "docker/src/clawpack-5.3.1/amrclaw/examples/advection_2d_swirl/psi.f", "max_stars_repo_name": "ian-r-rose/visualization", "max_stars_repo_head_hexsha": "ed6d9fab95eb125e7340ab3fad3ed114ed3214af", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2015-05-27T08:16:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-21T06:36:24.000Z", "max_issues_repo_path": "apps/advection/2d/swirl/psi.f", "max_issues_repo_name": "che-wenchao/D-Claw", "max_issues_repo_head_hexsha": "8ab5d971c9a7a7130e03a447a4b8642e292f4e88", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 107, "max_issues_repo_issues_event_min_datetime": "2015-01-02T19:51:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-24T03:35:32.000Z", "max_forks_repo_path": "apps/advection/2d/swirl/psi.f", "max_forks_repo_name": "che-wenchao/D-Claw", "max_forks_repo_head_hexsha": "8ab5d971c9a7a7130e03a447a4b8642e292f4e88", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2015-01-10T00:03:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-11T23:52:34.000Z", "avg_line_length": 19.4705882353, "max_line_length": 55, "alphanum_fraction": 0.3595166163, "num_tokens": 77, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037384317888, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7551529025778111}} {"text": "\n\n subroutine LineSegIntersection(p,p2,q,q2,pRatio,qRatio,rPtc,bIntersect)\n !-- source http://www.codeproject.com/Tips/862988/Find-the-Intersection-Point-of-Two-Line-Segments\n use mod_parameters\n implicit none\n real*8 , intent(in)::p(2),p2(2),q(2),q2(2) !-input lines p-p2, q-q2\n real*8 , intent(out)::rPtc(2),pRatio,qRatio !- output intersection point\n integer ,intent(out)::bIntersect !- =0 for no intersection\n integer i\n real*8 r(2),s(2),qp(2),rxs,qpxr,qpxs,CorssProduct2d\n\n bIntersect=0\n r=p2-p\n s=q2-q\n qp=q-p\n rxs=CorssProduct2d(r,s)\n qpxr=CorssProduct2d(qp,r)\n !- If r x s = 0 and (q - p) x r = 0, then the two lines are collinear.\n if ((abs(rxs) < TolZero16) .and. (abs(qpxr) 8) THEN\n PRINT*, \"Polynomial order should be between 1 and 8\"\n err_in = .TRUE.\n ELSE\n ! In case we're re-defining\n IF(ALLOCATED(poly%coeffs)) DEALLOCATE(poly%coeffs)\n ALLOCATE(poly%coeffs(poly%order_plus))\n poly%coeffs = coeffs\n END IF\n\n ! Put value in before returning\n IF(PRESENT(err)) err = err_in\n\n\n END SUBROUTINE\n\n ! f is a terrible function name in general, but it matches the equation I am coding\n FUNCTION f(poly, x)\n TYPE(polynomial_wrapper) :: poly\n REAL(KIND=dbl) :: f, x, x_term\n INTEGER :: i\n\n f = 0.0\n x_term = 1.0\n\n ! I go backwards so I can accumulate the x powers\n DO i = poly%order_plus, 1, -1\n f = f + x_term * poly%coeffs(i)\n x_term = x_term * x\n END DO\n\n END FUNCTION f\n\n FUNCTION f_prime(poly, x)\n TYPE(polynomial_wrapper) :: poly\n REAL(KIND=dbl) :: f_prime, x, x_term\n INTEGER :: i\n\n f_prime = 0.0\n x_term = 1.0\n\n ! I go backwards so I can accumulate the x powers\n DO i = poly%order_plus-1, 1, -1\n f_prime = f_prime + x_term * poly%coeffs(i) * REAL(poly%order_plus-i)\n x_term = x_term * x\n END DO\n\n END FUNCTION f_prime\n\n\n FUNCTION root_near(poly, guess)\n ! Find a root of a function near a given guess\n ! We can return any valid root\n\n ! The polynomial\n TYPE(polynomial_wrapper) :: poly\n ! Initial guess for the root\n REAL(KIND=dbl), INTENT(IN) :: guess\n\n REAL(KIND=dbl):: change\n REAL(KIND=dbl) :: root_near\n REAL(KIND=dbl), PARAMETER :: threshold = 0.001_dbl\n INTEGER, PARAMETER :: max_iter = 50\n INTEGER :: i\n\n ! See numerical_root for discussion of termination condition\n\n root_near = guess\n ! Start with a number for change that definitely\n ! does not trip the fractional change limit\n change = guess * 100.0\n DO i = 1, max_iter\n !I chose to print the progress in this\n PRINT*, \"Iteration\", i, \"Fractional change\", change, \"Guess\", root_near\n ! I am using a fractional change limit\n IF(ABS(change/root_near) .LT. threshold) EXIT\n\n ! I am being a bit \"clever\" to minimise my temporaries here\n ! by storing the change before applying it\n ! I could also store the old and new values, or other\n ! approaches\n change = f(poly,root_near)/f_prime(poly,root_near)\n root_near = root_near - change\n END DO\n\n ! If we hit max_iter, we probably don't have a root\n ! This is a dumb way to create a NaN - we should really\n ! use the IEEE module, but I am keeping this simple\n IF(i >= max_iter) root_near = 0.0*1.0/(root_near-root_near)\n\n END FUNCTION root_near\n\n\nEND MODULE numerical_rootfinder\n\n\nPROGRAM main\n\n USE numerical_rootfinder\n\n IMPLICIT NONE\n\n ! Select some bounds for finding\n REAL(KIND=dbl) :: guess = 0.555555555_dbl\n REAL(KIND=dbl) :: res\n TYPE(polynomial_wrapper) :: poly\n\n CALL define_poly(poly, (/1.0_dbl, -0.31428571428_dbl, &\n -0.21549295774_dbl, 0.20845070422_dbl/))\n\n ! Calculate and print the answer\n ! The Fortran standard lets compilers do something unhelpful\n ! if you PRINT the result of a function which has a print in,\n ! so I generally always capture a result, then print it\n res = root_near(poly, guess)\n\n PRINT*, \"Root is \", res\n\nEND PROGRAM\n", "meta": {"hexsha": "f3e7e0b0e91859e3d99af40fc0be2bc0aa8c5fa8", "size": 4428, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ModelSolutions/Numerical_Root_type.f90", "max_stars_repo_name": "WarwickRSE/Fortran4Researchers", "max_stars_repo_head_hexsha": "14467a32a516fdc0cf33341aea8d5b26f4501b51", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-10-03T08:28:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-28T02:59:38.000Z", "max_issues_repo_path": "ModelSolutions/Numerical_Root_type.f90", "max_issues_repo_name": "WarwickRSE/Fortran4Researchers", "max_issues_repo_head_hexsha": "14467a32a516fdc0cf33341aea8d5b26f4501b51", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ModelSolutions/Numerical_Root_type.f90", "max_forks_repo_name": "WarwickRSE/Fortran4Researchers", "max_forks_repo_head_hexsha": "14467a32a516fdc0cf33341aea8d5b26f4501b51", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2038216561, "max_line_length": 85, "alphanum_fraction": 0.6752484192, "num_tokens": 1258, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969136, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.755108445893673}} {"text": " PROGRAM sphfinrot\nC----\nC Given a point (ilon,ilat), a pole of rotation (plon,plat), and a\nC finite angle of rotation, in degrees, calculate the new point\nC (olon,olat).\nC\nC Based on results found at:\nC inside.mines.edu/~gmurray/ArbitraryAxisRotation\nC----\n\n IMPLICIT none\n REAL*8 olon,olat,ilon,ilat,plon,plat,angle\n REAL*8 ix,iy,iz,px,py,pz,ox,oy,oz\n CHARACTER*30 ifile,ofile\n INTEGER user\n\n call gcmdln(ifile,ofile,user)\n\n if (user.eq.1) then\n print *,'Enter lon_init lat_init pole_lon pole_lat angle:'\n read *,ilon,ilat,plon,plat,angle\n call rotate(olon,olat,ilon,ilat,plon,plat,angle)\n write (*,9999), olon,olat\n else\n open (unit=11,file=ifile,status='old')\n open (unit=12,file=ofile,status='unknown')\n 101 read (11,*,end=102) ilon,ilat,plon,plat,angle\n call rotate(olon,olat,ilon,ilat,plon,plat,angle)\n write (12,9999) olon,olat\n goto 101\n 102 continue\n endif\n\n 9999 format(2F14.6)\n\n END\n\nC----------------------------------------------------------------------c\n\n SUBROUTINE rotate(olon,olat,ilon,ilat,plon,plat,angle)\n IMPLICIT NONE\n REAL*8 olon,olat,ilon,ilat,plon,plat,angle\n REAL*8 ix,iy,iz,px,py,pz,ox,oy,oz\n REAL*8 pi,d2r,r2d\n PARAMETER (pi=4.0d0*datan(1.0d0),d2r=pi/1.8d2,r2d=1.8d2/pi)\n\n call lonlat2xyz(ix,iy,iz,ilon,ilat)\n call lonlat2xyz(px,py,pz,plon,plat)\n\n ox = px*(px*ix+py*iy+pz*iz)*(1.0d0-dcos(angle*d2r))\n 1 + ix*dcos(angle*d2r)\n 2 + (-pz*iy+py*iz)*dsin(angle*d2r)\n oy = py*(px*ix+py*iy+pz*iz)*(1.0d0-dcos(angle*d2r))\n 1 + iy*dcos(angle*d2r)\n 2 + ( pz*ix-px*iz)*dsin(angle*d2r)\n oz = pz*(px*ix+py*iy+pz*iz)*(1.0d0-dcos(angle*d2r))\n 1 + iz*dcos(angle*d2r)\n 2 + (-py*ix+px*iy)*dsin(angle*d2r)\n\n olon = datan2(oy,ox)*r2d\n olat = dasin(oz)*r2d\n\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE lonlat2xyz(x,y,z,lon,lat)\n\n IMPLICIT none\n REAL*8 pi,d2r\n PARAMETER (pi=4.0d0*datan(1.0d0),d2r=pi/1.8d2)\n REAL*8 lon,lat,x,y,z\n\n x = dcos(lon*d2r)*dcos(lat*d2r)\n y = dsin(lon*d2r)*dcos(lat*d2r)\n z = dsin(lat*d2r)\n\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE gcmdln(ifile,ofile,user)\n\n IMPLICIT NONE\n CHARACTER*30 ifile,ofile,tag\n INTEGER i,narg,user\n\n user = 0\n ifile = 'sphfinrot.in'\n ofile = 'sphfinrot.out'\n\n narg = iargc()\n if (narg.eq.0) call usage()\n\n i = 0\n 9998 i = i + 1\n if (i.gt.narg) goto 9999\n call getarg(i,tag)\n if (tag(1:2).eq.'-f') then\n i = i + 1\n call getarg(i,ifile)\n elseif (tag(1:2).eq.'-o') then\n i = i + 1\n call getarg(i,ofile)\n elseif (tag(1:2).eq.'-d') then\n write(*,*) 'Running with default file names'\n elseif (tag(1:2).eq.'-u') then\n user = 1\n elseif (tag(1:2).eq.'-h'.or.tag(1:2).eq.'-?') then\n call usage()\n endif\n goto 9998\n 9999 continue\n\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE usage()\n IMPLICIT none\n\n write(*,*)\n 1 'Usage: sphfinrot -f [IFILE] -o [OFILE] -d -u -h/-?'\n write(*,*)\n 1 ' -f [IFILE] (Default sphfinrot.in) name of input file'\n write(*,*)\n 1 ' -o [OFILE] (Default sphfinrot.out) name of output file'\n write(*,*)\n 1 ' -d Run with default file names'\n write (*,*)\n 1 ' -u Prompt user to enter information through standard'\n write (*,*)\n 1 ' input for single calculation'\n write (*,*)\n 1 ' -h/-? Online help (this screen)'\n write (*,*) ''\n write (*,*)\n 1 ' sphfinrot makes a counter-clockwise finite rotation of a',\n 2 ' point around a pole'\n write (*,*) ''\n write (*,*)\n 1 ' Input file'\n write (*,*)\n 1 ' lon_init lat_init pole_lon pole_lat angle'\n write (*,*)\n 1 ' : :'\n write(*,*) ''\n write (*,*)\n 1 ' Output file'\n write (*,*)\n 1 ' lon_final lat_final'\n write (*,*)\n 1 ' : :'\n write (*,*) ''\n\n STOP\n END\n\n", "meta": {"hexsha": "e98868cda2814ee4645a5611698fbc417e9475d3", "size": 4473, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/sphfinrot.f", "max_stars_repo_name": "mherman09/src", "max_stars_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/sphfinrot.f", "max_issues_repo_name": "mherman09/src", "max_issues_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-06-27T16:35:46.000Z", "max_issues_repo_issues_event_max_datetime": "2017-07-16T14:55:39.000Z", "max_forks_repo_path": "src/sphfinrot.f", "max_forks_repo_name": "mherman09/src", "max_forks_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.6111111111, "max_line_length": 72, "alphanum_fraction": 0.4902749832, "num_tokens": 1486, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894576856559, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7551084394018689}} {"text": "\tProgram Eigenvalue\n\r\n!c gfortran eigen.f90 -I/use/include -L/usr/lib -llapack -lblas\r\n!c Confirm needed libraries are installed in your device\r\n\r\n!c I myself Byron Encinas claim no authorship over this example of code. \r\n\r\n\r\n!c finding the eigenvalues of a complex matrix using LAPACK\n\tImplicit none\n!c declarations, notice double precision\n\tcomplex*16 A(3,3), b(3), DUMMY(1,1), WORK(6)\n\tinteger i, ok\n!c define matrix A\n\tA(1,1)=(3.1, 0)\n\tA(1,2)=(1.3, 0) \n\tA(1,3)=(-5.7, 0)\n\tA(2,1)=(1.0, 0)\n\tA(2,2)=(-6.9, 0)\n\tA(2,3)=(5.8, 0)\n\tA(3,1)=(3.4, 0)\n\tA(3,2)=(7.2, 0)\n\tA(3,3)=(-8.8, 0)\n!c\n!c find the solution using the LAPACK routine ZGEEV\n\tcall ZGEEV('N', 'N', 3, A, 3, b, DUMMY, 1, DUMMY, 1, WORK, 6, WORK, ok)\n!c\n!c parameters in the order as they appear in the function call\n!c no left eigenvectors, no right eigenvectors, order of input matrix A,\n!c input matrix A, leading dimension of A, array for eigenvalues, \n!c array for left eigenvalue, leading dimension of DUMMY, \n!c array for right eigenvalues, leading dimension of DUMMY,\n!c workspace array dim>=2*order of A, dimension of WORK\n!c workspace array dim=2*order of A, return value \n!c\n!c output of eigenvalues\n\tif (ok .eq. 0) then\n\t do i=1, 3\n\t write(*,*) b(i)\n\t enddo\n\telse\n\t write (*,*) \"An error occurred\"\n\tendif\n\tend\r\n", "meta": {"hexsha": "c559a33e7c16ce9a136cf42eb7993011655465f1", "size": 1308, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "eigen.f90", "max_stars_repo_name": "ByronEncinas/Aprendo-Fortran", "max_stars_repo_head_hexsha": "ac1c72c022dfdbf0cdc496ae3c051304e784b791", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "eigen.f90", "max_issues_repo_name": "ByronEncinas/Aprendo-Fortran", "max_issues_repo_head_hexsha": "ac1c72c022dfdbf0cdc496ae3c051304e784b791", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "eigen.f90", "max_forks_repo_name": "ByronEncinas/Aprendo-Fortran", "max_forks_repo_head_hexsha": "ac1c72c022dfdbf0cdc496ae3c051304e784b791", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.0666666667, "max_line_length": 75, "alphanum_fraction": 0.6597859327, "num_tokens": 483, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107896491796, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.7550471887493102}} {"text": "PROGRAM linear_reg\nIMPLICIT NONE\n REAL :: x, y, x_sum = 0, y_sum = 0, xy_sum = 0, x2_sum = 0, x_mean, y_mean, m, b\n INTEGER :: num_records = 0, status\n CHARACTER(80) :: msg\n OPEN(UNIT=1, FILE='coords.dat', STATUS='OLD', ACTION='READ', IOSTAT=status, IOMSG=msg)\n\n DO\n READ(1, *, IOSTAT=status) x, y\n IF (status .ne. 0) THEN\n EXIT\n ELSE\n x_sum = x_sum + x\n y_sum = y_sum + y\n xy_sum = xy_sum + (x * y)\n x2_sum = x2_sum + (x**2)\n num_records = num_records + 1\n END IF\n END DO\n\n x_mean = x_sum / REAL(num_records)\n y_mean = y_sum / REAL(num_records)\n m = (xy_sum - x_sum * y_mean) / (x2_sum - x_sum * x_mean)\n b = y_mean - m * x_mean\n WRITE(*, '(A,F9.7,A,F9.7)') \"y = \",m, \"x + \",b\n\nEND PROGRAM linear_reg\n", "meta": {"hexsha": "08ca0c4e4556bf7f7a067d9b59b4a612cc4ab9e5", "size": 755, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap5/linear_reg.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap5/linear_reg.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap5/linear_reg.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.9642857143, "max_line_length": 88, "alphanum_fraction": 0.582781457, "num_tokens": 289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107896491796, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.7550471865624626}} {"text": "c gmm01f\r\nc THIS FILE IS PART OF THE ORIGINAL GMM01F DISTRIBUTION\r\n SUBROUTINE orientcd(BETAMI,BETAMX,THETMI,THETMX,PHIMIN,PHIMAX,\r\n & MXBETA,MXTHET,MXPHI,NBETA,NTHETA,NPHI,\r\n & BETA,THETA,PHI)\r\nC Arguments:\r\n INTEGER MXBETA,MXTHET,MXPHI,NBETA,NTHETA,NPHI\r\n double precision BETAMI,BETAMX,THETMI,THETMX,PHIMIN,PHIMAX\r\n double precision BETA(MXBETA),THETA(MXTHET),PHI(MXPHI)\r\nC Local variables:\r\n INTEGER J\r\n double precision DELTA\r\nC***********************************************************************\r\nC Given: BETAMI=minimum value of beta (radians)\r\nC BETAMX=maximum value of beta (radians)\r\nC THETMI=minimum value of theta (radians)\r\nC THETMX=maximum value of theta (radians)\r\nC PHIMIN=minimum value of phi (radians)\r\nC PHIMAX=maximum value of phi (radians)\r\nC MXBETA,MXTHET,MXPHI=dimensions of the arrays BETA,THETA,PHI\r\nC NBETA=number of values of beta\r\nC NTHETA=number of values of theta\r\nC NPHI=number of values of PHI\r\nC Returns: BETA(1-NBETA)=beta values (radians)\r\nC THETA(1-NTHETA)=theta values (radians)\r\nC PHI(1-NPHI)=phi values (radians)\r\nC Purpose: to generate a sequence of desired target orientations\r\nC Present version assumes:\r\nC beta to be uniformly distributed between BETAMI and BETAMX\r\nC cos(theta) to be uniformly distributed between cos(THETMI) and\r\nC cos(THETMX)\r\nC phi to be uniformly distributed between PHIMIN and PHIMAX\r\nC If NPHI=1, first angle is THETMI, last angle is THETMX\r\nC If NPHI>1, then angles are midpoints of intervals of equal\r\nC range in theta subdividing range from THETMI to THETMX\r\nC***********************************************************************\r\n BETA(1)=BETAMI\r\n IF(NBETA.GT.1)THEN\r\n DELTA=(BETAMX-BETAMI)/DBLE(NBETA-1)\r\n DO 1000 J=2,NBETA\r\n BETA(J)=BETA(1)+DELTA*DBLE(J-1)\r\n 1000 CONTINUE\r\n ENDIF\r\n IF(NPHI.EQ.1.AND.NTHETA.GT.1)THEN\r\n DELTA=(DCOS(THETMX)-DCOS(THETMI))/DBLE(NTHETA-1)\r\n THETA(1)=THETMI\r\n ELSE\r\n DELTA=(DCOS(THETMX)-DCOS(THETMI))/DBLE(NTHETA)\r\n THETA(1)=DACOS(DCOS(THETMI)+0.5d0*DELTA)\r\n ENDIF\r\n IF(NTHETA.GT.1)THEN\r\n DO 2000 J=2,NTHETA\r\n THETA(J)=DACOS(DCOS(THETA(1))+DELTA*DBLE(J-1))\r\n 2000 CONTINUE\r\n ENDIF\r\nc DELTA=(PHIMAX-PHIMIN)/DBLE(NPHI)\r\nc PHI(1)=PHIMIN+0.5D0*DELTA\r\n PHI(1)=PHIMIN\r\n IF(NPHI.GT.1)THEN\r\n DELTA=(PHIMAX-PHIMIN)/DBLE(NPHI-1)\r\n DO 3000 J=2,NPHI\r\n PHI(J)=PHI(1)+DELTA*DBLE(J-1)\r\n 3000 CONTINUE\r\n ENDIF\r\n RETURN\r\n END\r\n\r\n\r\n", "meta": {"hexsha": "c8dc57af366f56305e9fabf612c8746b324fa7c9", "size": 2726, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "GMM_FIELD/src/orientcd.f", "max_stars_repo_name": "m-ringler/GMM-DIP", "max_stars_repo_head_hexsha": "016a4ca0ecf50c9d665cc17fb209031d0093c9a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "GMM_FIELD/src/orientcd.f", "max_issues_repo_name": "m-ringler/GMM-DIP", "max_issues_repo_head_hexsha": "016a4ca0ecf50c9d665cc17fb209031d0093c9a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "GMM_FIELD/src/orientcd.f", "max_forks_repo_name": "m-ringler/GMM-DIP", "max_forks_repo_head_hexsha": "016a4ca0ecf50c9d665cc17fb209031d0093c9a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-06T14:43:40.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-07T12:05:00.000Z", "avg_line_length": 39.5072463768, "max_line_length": 73, "alphanum_fraction": 0.5920763023, "num_tokens": 893, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029486, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7550471857885076}} {"text": "PROGRAM stats\nIMPLICIT NONE\n INTEGER, PARAMETER :: MAX_SIZE = 32\n INTEGER, DIMENSION(MAX_SIZE) :: numbers\n INTEGER :: arr_size, smallest, start, swap, status, index = 1, diff = 0\n REAL :: median, mean, std_dev, x_sum = 0.0, diff2_sum = 0.0\n CHARACTER(LEN = 85) :: msg\n\n OPEN(UNIT=1, FILE='numbers.txt', STATUS='OLD', ACTION='READ', IOSTAT=status, IOMSG=msg)\n\n ! Read data from file and load it into numbers array. Calculate mean and\n ! std_dev in the process\n DO\n READ(1,*,IOSTAT=status) numbers(index)\n x_sum = x_sum + numbers(index)\n IF (status .ne. 0) THEN\n ! Get upper bound of array\n arr_size = index - 1\n EXIT\n END IF\n index = index + 1\n END DO\n\n mean = x_sum / arr_size\n WRITE(*, *) \"Mean: \", mean\n\n DO index = 1, arr_size\n diff = numbers(index) - mean\n diff2_sum = diff2_sum + diff**2\n END DO\n\n std_dev = SQRT(diff2_sum/(arr_size - 1))\n WRITE(*, *) \"Standard Deviation: \", std_dev\n\n ! Find smallest and swap it with the value stored in start\n outer: DO start = 1, arr_size\n smallest = start\n find_smallest: DO index = start, arr_size\n IF (numbers(index) < numbers(smallest)) THEN\n smallest = index\n END IF\n END DO find_smallest\n IF (start .ne. smallest) THEN\n swap = numbers(start)\n numbers(start) = numbers(smallest)\n numbers(smallest) = swap\n END IF\n END DO outer\n\n ! Calculate the median and print it\n IF (MODULO(arr_size,2) .ne. 0) THEN\n median = REAL(numbers(index/2))\n WRITE(*, *) \"Median: \", INT(median)\n ELSE\n median = REAL(numbers(index/2) + numbers(index/2 + 1)) / 2.0\n WRITE(*, *) \"Near median: \", numbers(index/2), numbers(index/2 + 1)\n WRITE(*, *) \"Median: \", median\n END IF\n\n\n CLOSE(1)\n\nEND PROGRAM stats\n", "meta": {"hexsha": "07e2eb4f2a39243f931c5a4c5ad80f2d71e4b1f5", "size": 1749, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap6/stats.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap6/stats.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap6/stats.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.328125, "max_line_length": 89, "alphanum_fraction": 0.6323613493, "num_tokens": 546, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104865, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7550471820537499}} {"text": "PROGRAM test_chi_squared\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(15, 60)\r\nINTEGER :: ndf\r\nREAL (dp) :: chi2\r\n\r\nINTERFACE\r\n FUNCTION chi_squared(ndf, chi2) RESULT(prob)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(15, 60)\r\n INTEGER, INTENT(IN) :: ndf\r\n REAL (dp), INTENT(IN) :: chi2\r\n REAL (dp) :: prob\r\n END FUNCTION chi_squared\r\nEND INTERFACE\r\n\r\nDO\r\n WRITE(*, *) 'Enter no. of degrees of freedom: '\r\n READ(*, *) ndf\r\n WRITE(*, *) 'Enter chi-squared value: '\r\n READ(*, *) chi2\r\n WRITE(*, *) 'Chi-squared probability = ', chi_squared(ndf, chi2)\r\nEND DO\r\nSTOP\r\n\r\nEND PROGRAM test_chi_squared\r\n\r\n\r\n\r\nFUNCTION chi_squared(ndf, chi2) RESULT(prob)\r\n! Calculate the chi-squared distribution function\r\n! ndf = number of degrees of freedom\r\n! chi2 = chi-squared value\r\n! prob = probability of a chi-squared value <= chi2 (i.e. the left-hand\r\n! tail area)\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(15, 60)\r\nINTEGER, INTENT(IN) :: ndf\r\nREAL (dp), INTENT(IN) :: chi2\r\nREAL (dp) :: prob\r\n\r\nINTERFACE\r\n FUNCTION gammad(x, p) RESULT(gamma_prob)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(15, 60)\r\n REAL (dp), INTENT(IN) :: x, p\r\n REAL (dp) :: gamma_prob\r\n END FUNCTION gammad\r\nEND INTERFACE\r\n\r\n! Local variables\r\nREAL (dp) :: half = 0.5d0, x, p\r\n\r\nx = half * chi2\r\np = half * REAL(ndf)\r\nprob = gammad(x, p)\r\nRETURN\r\n\r\nEND FUNCTION chi_squared\r\n\r\n\r\n\r\nFUNCTION gammad(x, p) RESULT(fn_val)\r\n\r\n! ALGORITHM AS239 APPL. STATIST. (1988) VOL. 37, NO. 3\r\n\r\n! Computation of the Incomplete Gamma Integral\r\n\r\n! Auxiliary functions required: lngamma = logarithm of the gamma\r\n! function, and ALNORM = algorithm AS66\r\n\r\n! ELF90-compatible version by Alan Miller\r\n! amiller@bigpond.net.au\r\n! Latest revision - 28 October 2000\r\n\r\n! N.B. Argument IFAULT has been removed\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\nREAL (dp), INTENT(IN) :: x, p\r\nREAL (dp) :: fn_val\r\n\r\nINTERFACE\r\n FUNCTION alnorm( x, upper ) RESULT( fn_val )\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(15, 100)\r\n REAL(dp), INTENT(IN) :: x\r\n LOGICAL, INTENT(IN) :: upper\r\n REAL(DP) :: fn_val\r\n END FUNCTION alnorm\r\n\r\n FUNCTION lngamma(z) RESULT(lanczos)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(15, 60)\r\n REAL(dp), INTENT(IN) :: z\r\n REAL(dp) :: lanczos\r\n END FUNCTION lngamma\r\nEND INTERFACE\r\n\r\n! Local variables\r\nREAL (dp) :: pn1, pn2, pn3, pn4, pn5, pn6, arg, c, rn, a, b, an\r\nREAL (dp), PARAMETER :: zero = 0.0_dp, one = 1.0_dp, two = 2.0_dp, &\r\n oflo = 1.d+37, three = 3.0_dp, nine = 9.0_dp, &\r\n tol = 1.d-14, xbig = 1.d+8, plimit = 1000.0_dp, &\r\n elimit = -88.0_dp\r\n! EXTERNAL lngamma, alnorm\r\n\r\nfn_val = zero\r\n\r\n! Check that we have valid values for X and P\r\n\r\nIF (p <= zero .OR. x < zero) THEN\r\n WRITE(*, *) 'AS239: Either p <= 0 or x < 0'\r\n RETURN\r\nEND IF\r\nIF (x == zero) RETURN\r\n\r\n! Use a normal approximation if P > PLIMIT\r\n\r\nIF (p > plimit) THEN\r\n pn1 = three * SQRT(p) * ((x / p) ** (one / three) + one /(nine * p) - one)\r\n fn_val = alnorm(pn1, .false.)\r\n RETURN\r\nEND IF\r\n\r\n! If X is extremely large compared to P then set fn_val = 1\r\n\r\nIF (x > xbig) THEN\r\n fn_val = one\r\n RETURN\r\nEND IF\r\n\r\nIF (x <= one .OR. x < p) THEN\r\n \r\n! Use Pearson's series expansion.\r\n! (Note that P is not large enough to force overflow in lngamma).\r\n! No need to test IFAULT on exit since P > 0.\r\n \r\n arg = p * LOG(x) - x - lngamma(p + one)\r\n c = one\r\n fn_val = one\r\n a = p\r\n DO\r\n a = a + one\r\n c = c * x / a\r\n fn_val = fn_val + c\r\n IF (c <= tol) EXIT\r\n END DO\r\n arg = arg + LOG(fn_val)\r\n fn_val = zero\r\n IF (arg >= elimit) fn_val = EXP(arg)\r\n \r\nELSE\r\n \r\n! Use a continued fraction expansion\r\n \r\n arg = p * LOG(x) - x - lngamma(p)\r\n a = one - p\r\n b = a + x + one\r\n c = zero\r\n pn1 = one\r\n pn2 = x\r\n pn3 = x + one\r\n pn4 = x * b\r\n fn_val = pn3 / pn4\r\n DO\r\n a = a + one\r\n b = b + two\r\n c = c + one\r\n an = a * c\r\n pn5 = b * pn3 - an * pn1\r\n pn6 = b * pn4 - an * pn2\r\n IF (ABS(pn6) > zero) THEN\r\n rn = pn5 / pn6\r\n IF (ABS(fn_val - rn) <= MIN(tol, tol * rn)) EXIT\r\n fn_val = rn\r\n END IF\r\n\r\n pn1 = pn3\r\n pn2 = pn4\r\n pn3 = pn5\r\n pn4 = pn6\r\n IF (ABS(pn5) >= oflo) THEN\r\n \r\n! Re-scale terms in continued fraction if terms are large\r\n \r\n pn1 = pn1 / oflo\r\n pn2 = pn2 / oflo\r\n pn3 = pn3 / oflo\r\n pn4 = pn4 / oflo\r\n END IF\r\n END DO\r\n\r\n arg = arg + LOG(fn_val)\r\n fn_val = one\r\n IF (arg >= elimit) fn_val = one - EXP(arg)\r\nEND IF\r\n\r\n\r\nRETURN\r\nEND FUNCTION gammad\r\n\r\n\r\n\r\n! Algorithm AS66 Applied Statistics (1973) vol.22, no.3\r\n\r\n! Evaluates the tail area of the standardised normal curve\r\n! from x to infinity if upper is .true. or\r\n! from minus infinity to x if upper is .false.\r\n\r\n! ELF90-compatible version by Alan Miller\r\n! Latest revision - 29 November 2001\r\n\r\nFUNCTION alnorm( x, upper ) RESULT( fn_val )\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(15, 100)\r\n REAL(dp), INTENT(IN) :: x\r\n LOGICAL, INTENT(IN) :: upper\r\n REAL(dp) :: fn_val\r\n\r\n ! Local variables\r\n REAL(dp), PARAMETER :: zero=0.0_dp, one=1.0_dp, half=0.5_dp, con=1.28_dp\r\n REAL(dp) :: z, y\r\n LOGICAL :: up\r\n\r\n ! Machine dependent constants\r\n REAL(dp), PARAMETER :: ltone = 7.0_dp, utzero = 18.66_dp\r\n REAL(dp), PARAMETER :: p = 0.398942280444_dp, q = 0.39990348504_dp, &\r\n r = 0.398942280385_dp, a1 = 5.75885480458_dp, &\r\n a2 = 2.62433121679_dp, a3 = 5.92885724438_dp, &\r\n b1 = -29.8213557807_dp, b2 = 48.6959930692_dp, &\r\n c1 = -3.8052D-8, c2 = 3.98064794D-4, &\r\n c3 = -0.151679116635_dp, c4 = 4.8385912808_dp, &\r\n c5 = 0.742380924027_dp, c6 = 3.99019417011_dp, &\r\n d1 = 1.00000615302_dp, d2 = 1.98615381364_dp, &\r\n d3 = 5.29330324926_dp, d4 = -15.1508972451_dp, &\r\n d5 = 30.789933034_dp\r\n\r\n up = upper\r\n z = x\r\n IF( z < zero ) THEN\r\n up = .NOT. up\r\n z = -z\r\n END IF\r\n IF( z <= ltone .OR. (up .AND. z <= utzero) ) THEN\r\n y = half*z*z\r\n IF( z > con ) THEN\r\n fn_val = r*EXP( -y )/(z+c1+d1/(z+c2+d2/(z+c3+d3/(z+c4+d4/(z+c5+d5/(z+c6))))))\r\n ELSE\r\n fn_val = half - z*(p-q*y/(y+a1+b1/(y+a2+b2/(y+a3))))\r\n END IF\r\n ELSE\r\n fn_val = zero\r\n END IF\r\n\r\n IF( .NOT. up ) fn_val = one - fn_val\r\n RETURN\r\nEND FUNCTION alnorm\r\n\r\n\r\n\r\nFUNCTION lngamma(z) RESULT(lanczos)\r\n\r\n! Uses Lanczos-type approximation to ln(gamma) for z > 0.\r\n! Reference:\r\n! Lanczos, C. 'A precision approximation of the gamma\r\n! function', J. SIAM Numer. Anal., B, 1, 86-96, 1964.\r\n! Accuracy: About 14 significant digits except for small regions\r\n! in the vicinity of 1 and 2.\r\n\r\n! Programmer: Alan Miller\r\n! 1 Creswick Street, Brighton, Vic. 3187, Australia\r\n! Latest revision - 14 October 1996\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(15, 60)\r\nREAL(dp), INTENT(IN) :: z\r\nREAL(dp) :: lanczos\r\n\r\n! Local variables\r\n\r\nREAL(dp) :: a(9) = (/ 0.9999999999995183D0, 676.5203681218835D0, &\r\n -1259.139216722289D0, 771.3234287757674D0, &\r\n -176.6150291498386D0, 12.50734324009056D0, &\r\n -0.1385710331296526D0, 0.9934937113930748D-05, &\r\n 0.1659470187408462D-06 /), zero = 0.D0, &\r\n one = 1.d0, lnsqrt2pi = 0.9189385332046727D0, &\r\n half = 0.5d0, sixpt5 = 6.5d0, seven = 7.d0, tmp\r\nINTEGER :: j\r\n\r\nIF (z <= zero) THEN\r\n WRITE(*, *) 'Error: zero or -ve argument for lngamma'\r\n RETURN\r\nEND IF\r\n\r\nlanczos = zero\r\ntmp = z + seven\r\nDO j = 9, 2, -1\r\n lanczos = lanczos + a(j)/tmp\r\n tmp = tmp - one\r\nEND DO\r\nlanczos = lanczos + a(1)\r\nlanczos = LOG(lanczos) + lnsqrt2pi - (z + sixpt5) + (z - half)*LOG(z + sixpt5)\r\nRETURN\r\n\r\nEND FUNCTION lngamma\r\n\r\n\r\n", "meta": {"hexsha": "6c16aaabbb3f375a60f73572a0d5930598c308ab", "size": 8440, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/chi_sq.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/chi_sq.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/chi_sq.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 27.2258064516, "max_line_length": 87, "alphanum_fraction": 0.5515402844, "num_tokens": 2810, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107878954105, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7550471764021788}} {"text": "!*********************************************************\n!>\n! Special Functions:\n! * Airy Function - Ai and Bi\n! * Bessel Functions - J and Y\n! * Bessel Function - I and K\n! * Spherical Bessel Functions\n! * Beta Function\n! * Incomplete Beta Function\n! * Chebyshev Polynomial - T and U\n! * Error Function and Complementary Error Function\n! * Factorial\n! * Hermite Polynomial (Physicists' and Probabilists')\n! * Laguerre Polynomial\n! * Associated Laguerre Polynomial\n! * Legendre Polynomial\n! * Sine Integrals\n! * Hyperbolic Sine Integrals\n! * Cosine Integrals\n! * Hyperbolic Cosine Integrals\n! * Hypergeometric Series: 0F1, 1F0, 1F1, 2F1, 3F2\n! * Dilogarithm (3F2)\n! * Add complex inputs to all functions that can have complex input\n!\n! Not 100% Right:\n! * Gamma Function\n!\n! Future:\n! * Hahn polynomials (3F2)\n! * Clausen Functions\n! * Coulomb Wave Functions (1F1)\n! * Coupling Coefficients (Wigner 3-j, 6-j, 9-j)\n! * Dawson Function\n! * Debye Functions\n! * Elliptic Integrals\n! * Fermi-Dirac Function\n! * Gegenbauer Functions\n! * Lambert W Functions\n! * Synchrotron Functions\n! * Zeta Functions\n\n\nmodule specialFunctions\n use constants\n use integration\n use odeSolver\n implicit none\n\n private\n integer, parameter :: dp = kind(0.d0)\n\n public :: pochhammerF, pochhammerR\n public :: besselJ, besselY, besselI, besselK, besselY_dd\n public :: sphBesselJ, sphBesselY\n public :: airyA, airyB\n public :: errf, errfc\n public :: beta, incBeta\n public :: gammaFunc\n public :: legendrePoly\n public :: hermitePoly, hermitePolyProb\n public :: laguerrePoly, assocLaguerrePoly\n public :: chebyPolyT, chebyPolyU\n public :: sini, hypSini\n public :: cosi, hypCosi\n public :: hypGeo0F1, hypGeo0F1Deriv\n public :: hypGeo1F0, hypGeo1F0Deriv\n public :: hypGeo1F1, hypGeo1F1Deriv\n public :: hypGeo2F1, hypGeo2F1Deriv\n public :: hypGeo3F2, hypGeo3F2Deriv\n public :: diLog\n\n interface pochhammerF\n module procedure pochhammerF_i, pochhammerF_r, pochhammerF_d, pochhammerF_Cr, pochhammerF_Cd\n end interface\n\n interface pochhammerR\n module procedure pochhammerR_i, pochhammerR_r, pochhammerR_d, pochhammerR_Cr, pochhammerR_Cd\n end interface\n\n interface besselJ\n module procedure besselJ_ii, besselJ_ir, besselJ_id, besselJ_ri, &\n besselJ_di, besselJ_rr, besselJ_rd, besselJ_dr, besselJ_dd\n end interface\n\n interface besselY\n module procedure besselY_ii, besselY_ir, besselY_id, besselY_ri, &\n besselY_di, besselY_rr, besselY_rd, besselY_dr, besselY_dd\n end interface\n\n interface besselI\n module procedure besselI_ii, besselI_ir, besselI_id, besselI_ri, &\n besselI_di, besselI_rr, besselI_rd, besselI_dr, besselI_dd\n end interface\n\n interface besselK\n module procedure besselK_ii, besselK_ir, besselK_id, besselK_ri, &\n besselK_di, besselK_rr, besselK_rd, besselK_dr, besselK_dd\n end interface\n\n interface sphBesselJ\n module procedure sphBesselJ_ii, sphBesselJ_ir, sphBesselJ_id, sphBesselJ_ri, &\n sphBesselJ_di, sphBesselJ_rr, sphBesselJ_rd, sphBesselJ_dr, sphBesselJ_dd\n end interface\n\n interface sphBesselY\n module procedure sphBesselY_ii, sphBesselY_ir, sphBesselY_id, sphBesselY_ri, &\n sphBesselY_di, sphBesselY_rr, sphBesselY_rd, sphBesselY_dr, sphBesselY_dd\n end interface\n\n interface airyA\n module procedure airyA_i, airyA_r, airyA_d\n end interface\n\n interface airyB\n module procedure airyB_i, airyB_r, airyB_d\n end interface\n\n interface errf\n module procedure errf_i, errf_r, errf_d\n end interface\n\n interface errfc\n module procedure errfc_i, errfc_r, errfc_d\n end interface\n\n interface beta\n module procedure beta_ii, beta_ir, beta_id, beta_ri, beta_di, beta_rr, &\n beta_rd, beta_dr, beta_dd\n end interface\n\n interface incBeta\n module procedure incBeta_iii, incBeta_iir, incBeta_iid, incBeta_iri, incBeta_irr, &\n incBeta_ird, incBeta_idi, incBeta_idr, incBeta_idd, incBeta_rii, incBeta_rir, &\n incBeta_rid, incBeta_rri, incBeta_rrr, incBeta_rrd, incBeta_rdi, incBeta_rdr, &\n incBeta_rdd, incBeta_dii, incBeta_dir, incBeta_did, incBeta_dri, incBeta_drr, &\n incBeta_drd, incBeta_ddi, incBeta_ddr, incBeta_ddd\n end interface\n\n interface legendrePoly\n module procedure legendrePoly_i, legendrePoly_r, legendrePoly_d\n end interface\n\n interface hermitePoly\n module procedure hermitePoly_i, hermitePoly_r, hermitePoly_d\n end interface\n\n interface hermitePolyProb\n module procedure hermitePolyProb_i, hermitePolyProb_r, hermitePolyProb_d\n end interface\n\n interface laguerrePoly\n module procedure laguerrePoly_i, laguerrePoly_r, laguerrePoly_d\n end interface\n\n interface assocLaguerrePoly\n module procedure assocLaguerrePoly_ii, assocLaguerrePoly_ir, assocLaguerrePoly_id, &\n assocLaguerrePoly_ri, assocLaguerrePoly_rr, assocLaguerrePoly_rd, assocLaguerrePoly_di, &\n assocLaguerrePoly_dr, assocLaguerrePoly_dd\n end interface\n\n interface chebyPolyT\n module procedure chebyPolyT_i, chebyPolyT_r, chebyPolyT_d\n end interface\n\n interface chebyPolyU\n module procedure chebyPolyU_i, chebyPolyU_r, chebyPolyU_d\n end interface\n\n interface sini\n module procedure sini_i, sini_r, sini_d\n end interface\n\n interface hypSini\n module procedure hypSini_i, hypSini_r, hypSini_d\n end interface\n\n interface cosi\n module procedure cosi_i, cosi_r, cosi_d\n end interface\n\n interface hypCosi\n module procedure hypCosi_i, hypCosi_r, hypCosi_d\n end interface\n\n interface hypGeo0F1\n module procedure hypGeo0F1_ii, hypGeo0F1_ir, hypGeo0F1_id, hypGeo0F1_ri, hypGeo0F1_rr, hypGeo0F1_rd, hypGeo0F1_di, &\n hypGeo0F1_dr, hypGeo0F1_dd, hypGeo0F1_iCr, hypGeo0F1_rCr, hypGeo0F1_dCr, hypGeo0F1_iCd, hypGeo0F1_rCd, hypGeo0F1_dCd, &\n hypGeo0F1_CrCr, hypGeo0F1_CrCd, hypGeo0F1_CdCd\n end interface\n\n interface hypGeo0F1Deriv\n module procedure hypGeo0F1Deriv_ii, hypGeo0F1Deriv_ir, hypGeo0F1Deriv_id, hypGeo0F1Deriv_ri, hypGeo0F1Deriv_rr, &\n hypGeo0F1Deriv_rd, hypGeo0F1Deriv_di, hypGeo0F1Deriv_dr, hypGeo0F1Deriv_dd, hypGeo0F1Deriv_iCr, hypGeo0F1Deriv_rCr, &\n hypGeo0F1Deriv_dCr, hypGeo0F1Deriv_iCd, hypGeo0F1Deriv_rCd, hypGeo0F1Deriv_dCd, hypGeo0F1Deriv_CrCr, hypGeo0F1Deriv_CrCd, &\n hypGeo0F1Deriv_CdCd\n end interface\n\n interface hypGeo1F0\n module procedure hypGeo1F0_ii, hypGeo1F0_ir, hypGeo1F0_id, hypGeo1F0_ri, hypGeo1F0_rr, hypGeo1F0_rd, hypGeo1F0_di, &\n hypGeo1F0_dr, hypGeo1F0_dd, hypGeo1F0_iCr, hypGeo1F0_rCr, hypGeo1F0_dCr, hypGeo1F0_iCd, hypGeo1F0_rCd, hypGeo1F0_dCd, &\n hypGeo1F0_CrCr, hypGeo1F0_CrCd, hypGeo1F0_CdCd\n end interface\n\n interface hypGeo1F0Deriv\n module procedure hypGeo1F0Deriv_ii, hypGeo1F0Deriv_ir, hypGeo1F0Deriv_id, hypGeo1F0Deriv_ri, hypGeo1F0Deriv_rr, &\n hypGeo1F0Deriv_rd, hypGeo1F0Deriv_di, hypGeo1F0Deriv_dr, hypGeo1F0Deriv_dd, hypGeo1F0Deriv_iCr, hypGeo1F0Deriv_rCr, &\n hypGeo1F0Deriv_dCr, hypGeo1F0Deriv_iCd, hypGeo1F0Deriv_rCd, hypGeo1F0Deriv_dCd, hypGeo1F0Deriv_CrCr, hypGeo1F0Deriv_CrCd, &\n hypGeo1F0Deriv_CdCd\n end interface\n\n interface hypGeo1F1\n module procedure hypGeo1F1_iii, hypGeo1F1_rri, hypGeo1F1_ddi, hypGeo1F1_iir, hypGeo1F1_rrr, hypGeo1F1_ddr, &\n hypGeo1F1_iid, hypGeo1F1_rrd, hypGeo1F1_ddd, hypGeo1F1_iiCr, hypGeo1F1_rrCr, hypGeo1F1_ddCr, hypGeo1F1_iiCd, &\n hypGeo1F1_rrCd, hypGeo1F1_ddCd, hypGeo1F1_CrCrCr, hypGeo1F1_CrCrCd, hypGeo1F1_CdCdCd\n end interface\n\n interface hypGeo1F1Deriv\n module procedure hypGeo1F1Deriv_iii, hypGeo1F1Deriv_rri, hypGeo1F1Deriv_ddi, hypGeo1F1Deriv_iir, hypGeo1F1Deriv_rrr, &\n hypGeo1F1Deriv_ddr, hypGeo1F1Deriv_iid, hypGeo1F1Deriv_rrd, hypGeo1F1Deriv_ddd, hypGeo1F1Deriv_iiCr, hypGeo1F1Deriv_rrCr, &\n hypGeo1F1Deriv_ddCr, hypGeo1F1Deriv_iiCd, hypGeo1F1Deriv_rrCd, hypGeo1F1Deriv_ddCd, hypGeo1F1Deriv_CrCrCr, &\n hypGeo1F1Deriv_CrCrCd, hypGeo1F1Deriv_CdCdCd\n end interface\n\n interface hypGeo2F1\n module procedure hypGeo2F1_iiii, hypGeo2F1_iiir, hypGeo2F1_iiid, hypGeo2F1_rrri, &\n hypGeo2F1_rrrr, hypGeo2F1_rrrd, hypGeo2F1_dddi, hypGeo2F1_dddr, hypGeo2F1_dddd, &\n hypGeo2F1_iiiCr, hypGeo2F1_rrrCr, hypGeo2F1_dddCr, hypGeo2F1_iiiCd, hypGeo2F1_rrrCd, &\n hypGeo2F1_dddCd, hypGeo2F1_CrCrCrCr, hypGeo2F1_CrCrCrCd, hypGeo2F1_CdCdCdCd\n end interface\n\n interface hypGeo2F1Deriv\n module procedure hypGeo2F1Deriv_iiii, hypGeo2F1Deriv_iiir, hypGeo2F1Deriv_iiid, hypGeo2F1Deriv_rrri, &\n hypGeo2F1Deriv_rrrr, hypGeo2F1Deriv_rrrd, hypGeo2F1Deriv_dddi, hypGeo2F1Deriv_dddr, hypGeo2F1Deriv_dddd, &\n hypGeo2F1Deriv_iiiCr, hypGeo2F1Deriv_rrrCr, hypGeo2F1Deriv_dddCr, hypGeo2F1Deriv_iiiCd, hypGeo2F1Deriv_rrrCd, &\n hypGeo2F1Deriv_dddCd, hypGeo2F1Deriv_CrCrCrCr, hypGeo2F1Deriv_CrCrCrCd, hypGeo2F1Deriv_CdCdCdCd\n end interface\n\n interface hypGeo3F2\n module procedure hypGeo3F2_iiiiii, hypGeo3F2_iiiiir, hypGeo3F2_iiiiid, hypGeo3F2_rrrrri, hypGeo3F2_rrrrrr, hypGeo3F2_rrrrrd, &\n hypGeo3F2_dddddi, hypGeo3F2_dddddr, hypGeo3F2_dddddd, hypGeo3F2_iiiiiCr, hypGeo3F2_iiiiiCd, hypGeo3F2_rrrrrCr, &\n hypGeo3F2_rrrrrCd, hypGeo3F2_dddddCr, hypGeo3F2_dddddCd, hypGeo3F2_CrCrCrCrCrCr, hypGeo3F2_CrCrCrCrCrCd, &\n hypGeo3F2_CdCdCdCdCdCd\n end interface\n\n interface hypGeo3F2Deriv\n module procedure hypGeo3F2Deriv_iiiiii, hypGeo3F2Deriv_iiiiir, hypGeo3F2Deriv_iiiiid, hypGeo3F2Deriv_rrrrri, &\n hypGeo3F2Deriv_rrrrrr, hypGeo3F2Deriv_rrrrrd, hypGeo3F2Deriv_dddddi, hypGeo3F2Deriv_dddddr, hypGeo3F2Deriv_dddddd, &\n hypGeo3F2Deriv_iiiiiCr, hypGeo3F2Deriv_iiiiiCd, hypGeo3F2Deriv_rrrrrCr, hypGeo3F2Deriv_rrrrrCd, hypGeo3F2Deriv_dddddCr, &\n hypGeo3F2Deriv_dddddCd, hypGeo3F2Deriv_CrCrCrCrCrCr, hypGeo3F2Deriv_CrCrCrCrCrCd, hypGeo3F2Deriv_CdCdCdCdCdCd\n end interface\n\n interface diLog\n module procedure diLog_i, diLog_r, diLog_d, diLog_Cr, diLog_Cd\n end interface\n\ncontains\n\n !********************!\n ! Pochhammer Falling !\n !********************!\n\n complex(dp) function pochhammerFFunc(x,n)\n integer :: i, n\n complex(dp) :: x, result\n if(n.eq.0) then\n pochhammerFFunc = 1.d0\n else\n result = x\n do i=1,n+1\n result = result*(x-dble(i))\n end do\n pochhammerFFunc = result\n end if\n end function\n\n real(dp) function pochhammerF_i(x,n)\n integer :: x, n\n pochhammerF_i = real(pochhammerFFunc(cmplx(real(x),0.d0,dp),n))\n end function\n\n real(dp) function pochhammerF_r(x,n)\n integer :: n\n real :: x\n pochhammerF_r = real(pochhammerFFunc(cmplx(real(x),0.d0,dp),n))\n end function\n\n real(dp) function pochhammerF_d(x,n)\n integer :: n\n real(dp) :: x\n pochhammerF_d = real(pochhammerFFunc(cmplx(real(x),0.d0,dp),n))\n end function\n\n complex(dp) function pochhammerF_Cr(x,n)\n integer :: n\n complex :: x\n pochhammerF_Cr = real(pochhammerFFunc(cmplx(real(x),aimag(x),dp),n))\n end function\n\n complex(dp) function pochhammerF_Cd(x,n)\n integer :: n\n complex(dp) :: x\n pochhammerF_Cd = real(pochhammerFFunc(x,n))\n end function\n\n !*******************!\n ! Pochhammer Rising !\n !*******************!\n\n complex(dp) function pochhammerRFunc(x,n)\n integer :: i, n\n complex(dp) :: x, result\n if(n.eq.0) then\n pochhammerRFunc = cmplx(1.d0,0.d0,dp)\n else\n result = x\n do i=1,n-1\n result = result*(x+i)\n end do\n pochhammerRFunc = result\n end if\n end function\n\n real(dp) function pochhammerR_i(x,n)\n integer :: x, n\n pochhammerR_i = real(pochhammerRFunc(cmplx(x,0.d0,dp),n))\n end function\n\n real(dp) function pochhammerR_r(x,n)\n integer :: n\n real :: x\n pochhammerR_r = real(pochhammerRFunc(cmplx(x,0.d0,dp),n))\n end function\n\n real(dp) function pochhammerR_d(x,n)\n integer :: n\n real(dp) :: x\n pochhammerR_d = real(pochhammerRFunc(cmplx(x,0.d0,dp),n))\n end function\n\n complex(dp) function pochhammerR_Cr(x,n)\n integer :: n\n complex :: x\n pochhammerR_Cr = pochhammerRFunc(cmplx(real(x),aimag(x),dp),n)\n end function\n\n complex(dp) function pochhammerR_Cd(x,n)\n integer :: n\n complex(dp) :: x\n pochhammerR_Cd = pochhammerRFunc(x,n)\n end function\n\n !***********************************!\n ! Bessel Function of the First Kind !\n !***********************************!\n\n real(dp) function besselJ_IntFunc1(n,c,x)\n integer :: n\n real(dp) :: c(n),x\n besselJ_IntFunc1 = cos(c(1)*x-c(2)*sin(x))\n end function\n\n real(dp) function besselJ_IntFunc2(n,c,x)\n integer :: n\n real(dp) :: c(n), x, func\n func = exp(-c(2)*sinh(-log(x))+c(1)*log(x))\n besselJ_IntFunc2 = func*sin(c(1)*pi_)/x\n end function\n\n real(dp) function besselJFunc(n,x)\n real(dp) :: n, x, intResults, consts(2)\n consts(1) = n\n consts(2) = x\n intResults = gaussLegendre(besselJ_IntFunc1,0.d0,pi_,2,consts)\n intResults = intResults- &\n gaussLegendre(besselJ_IntFunc2,0.d0,1.d0,2,consts)\n besselJFunc = intResults/pi_\n end function\n\n real(dp) function besselJ_ii(n,x)\n integer :: n, x\n besselJ_ii = besselJFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselJ_ir(n,x)\n integer :: n\n real :: x\n besselJ_ir = besselJFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselJ_id(n,x)\n integer :: n\n real(dp) :: x\n besselJ_id = besselJFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselJ_ri(n,x)\n real :: n\n integer :: x\n besselJ_ri = besselJFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselJ_di(n,x)\n real(dp) :: n\n integer :: x\n besselJ_di = besselJFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselJ_rr(n,x)\n real :: n, x\n besselJ_rr = besselJFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselJ_rd(n,x)\n real :: n\n real(dp) :: x\n besselJ_rd = besselJFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselJ_dr(n,x)\n real(dp) :: n\n real :: x\n besselJ_dr = besselJFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselJ_dd(n,x)\n real(dp) :: n, x\n besselJ_dd = besselJFunc(dble(n),dble(x))\n end function\n\n !************************************!\n ! Bessel Function of the Second Kind !\n !************************************!\n\n real(dp) function besselY_IntFunc1(n,c,x)\n integer :: n\n real(dp) :: c(n), x\n besselY_IntFunc1 = sin(c(2)*sin(x)-c(1)*x)\n end function\n\n real(dp) function besselY_IntFunc2(n,c,x)\n integer :: n\n real(dp) :: c(n), x, func\n func = (exp(c(1)*(-log(x)))+(cos(c(1)*pi_))*exp(-c(1)*(-log(x))))\n func = func*exp(-c(2)*sinh((-log(x))))\n besselY_IntFunc2 = func/x\n end function\n\n real(dp) function besselYFunc(n,x)\n real(dp) :: n, x, intResults, consts(2)\n consts(1) = n\n consts(2) = x\n intResults = gaussLegendre(besselY_IntFunc1,0.d0,pi_,2,consts)\n intResults = intResults- &\n gaussLegendre(besselY_IntFunc2,0.d0,1.d0,2,consts)\n besselYFunc = intResults/pi_\n end function\n\n real(dp) function besselY_ii(n,x)\n integer :: n, x\n besselY_ii = besselYFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselY_ir(n,x)\n integer :: n\n real :: x\n besselY_ir = besselYFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselY_id(n,x)\n integer :: n\n real(dp) :: x\n besselY_id = besselYFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselY_ri(n,x)\n real :: n\n integer :: x\n besselY_ri = besselYFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselY_di(n,x)\n real(dp) :: n\n integer :: x\n besselY_di = besselYFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselY_rr(n,x)\n real :: n, x\n besselY_rr = besselYFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselY_rd(n,x)\n real :: n\n real(dp) :: x\n besselY_rd = besselYFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselY_dr(n,x)\n real(dp) :: n\n real :: x\n besselY_dr = besselYFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselY_dd(n,x)\n real(dp) :: n, x\n besselY_dd = besselYFunc(dble(n),dble(x))\n end function\n\n !********************************************!\n ! Modified Bessel Function of the First Kind !\n !********************************************!\n\n real(dp) function besselI_IntFunc1(n,c,x)\n integer :: n\n real(dp) :: c(n), x\n besselI_IntFunc1 = exp(c(2)*cos(x))*cos(c(1)*x)\n end function\n\n real(dp) function besselI_IntFunc2(n,c,x)\n integer :: n\n real(dp) :: c(n), x, func\n func = exp(-c(2)*cosh(-log(x))+c(1)*log(x))\n besselI_IntFunc2 = func*sin(c(1)*pi_)/x\n end function\n\n real(dp) function besselIFunc(n,x)\n real(dp) :: n, x, intResults, consts(2)\n consts(1) = n\n consts(2) = x\n intResults = gaussLegendre(besselI_IntFunc1,0.d0,pi_,2,consts)\n intResults = intResults- &\n gaussLegendre(besselI_IntFunc2,0.d0,1.d0,2,consts)\n besselIFunc = intResults/pi_\n end function\n\n real(dp) function besselI_ii(n,x)\n integer :: n, x\n besselI_ii = besselIFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselI_ir(n,x)\n integer :: n\n real :: x\n besselI_ir = besselIFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselI_id(n,x)\n integer :: n\n real(dp) :: x\n besselI_id = besselIFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselI_ri(n,x)\n real :: n\n integer :: x\n besselI_ri = besselIFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselI_di(n,x)\n real(dp) :: n\n integer :: x\n besselI_di = besselIFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselI_rr(n,x)\n real :: n, x\n besselI_rr = besselIFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselI_rd(n,x)\n real :: n\n real(dp) :: x\n besselI_rd = besselIFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselI_dr(n,x)\n real(dp) :: n\n real :: x\n besselI_dr = besselIFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselI_dd(n,x)\n real(dp) :: n, x\n besselI_dd = besselIFunc(dble(n),dble(x))\n end function\n\n !*********************************************!\n ! Modified Bessel Function of the Second Kind !\n !*********************************************!\n\n real(dp) function besselK_IntFunc(n,c,x)\n integer :: n\n real(dp) :: c(n),x\n besselK_IntFunc = (exp(-c(2)*cosh(-log(x)))*cosh(-c(1)*log(x)))/x\n end function besselK_IntFunc\n\n real(dp) function besselKFunc(n,x)\n real(dp) :: n, x, consts(2)\n consts(1) = n\n consts(2) = x\n besselKFunc = gaussLegendre(besselK_IntFunc,0.d0,1.d0,2,consts)\n end function\n\n real(dp) function besselK_ii(n,x)\n integer :: n, x\n besselK_ii = besselKFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselK_ir(n,x)\n integer :: n\n real :: x\n besselK_ir = besselKFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselK_id(n,x)\n integer :: n\n real(dp) :: x\n besselK_id = besselKFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselK_ri(n,x)\n real :: n\n integer :: x\n besselK_ri = besselKFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselK_di(n,x)\n real(dp) :: n\n integer :: x\n besselK_di = besselKFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselK_rr(n,x)\n real :: n, x\n besselK_rr = besselKFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselK_rd(n,x)\n real :: n\n real(dp) :: x\n besselK_rd = besselKFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselK_dr(n,x)\n real(dp) :: n\n real :: x\n besselK_dr = besselKFunc(dble(n),dble(x))\n end function\n\n real(dp) function besselK_dd(n,x)\n real(dp) :: n, x\n besselK_dd = besselKFunc(dble(n),dble(x))\n end function\n\n !*********************************************!\n ! Spherical Bessel Function of the First Kind !\n !*********************************************!\n\n real(dp) function sphBesselJFunc(n,x)\n real(dp) :: n, x\n if(x.eq.0d0) then\n if(n.eq.0.d0) then\n sphBesselJFunc = 1.d0\n else\n sphBesselJFunc = 0.d0\n end if\n else\n sphBesselJFunc = sqrt(pi_/(2.d0*x))*besselJ(n+0.5d0,x)\n end if\n end function\n\n real(dp) function sphBesselJ_ii(n,x)\n integer :: n, x\n sphBesselJ_ii = sphBesselJFunc(dble(n),dble(x))\n end function\n\n real(dp) function sphBesselJ_ir(n,x)\n integer :: n\n real :: x\n sphBesselJ_ir = sphBesselJFunc(dble(n),dble(x))\n end function\n\n real(dp) function sphBesselJ_id(n,x)\n integer :: n\n real(dp) :: x\n sphBesselJ_id = sphBesselJFunc(dble(n),dble(x))\n end function\n\n real(dp) function sphBesselJ_ri(n,x)\n real :: n\n integer :: x\n sphBesselJ_ri = sphBesselJFunc(dble(n),dble(x))\n end function\n\n real(dp) function sphBesselJ_di(n,x)\n real(dp) :: n\n integer :: x\n sphBesselJ_di = sphBesselJFunc(dble(n),dble(x))\n end function\n\n real(dp) function sphBesselJ_rr(n,x)\n real :: n, x\n sphBesselJ_rr = sphBesselJFunc(dble(n),dble(x))\n end function\n\n real(dp) function sphBesselJ_rd(n,x)\n real :: n\n real(dp) :: x\n sphBesselJ_rd = sphBesselJFunc(dble(n),dble(x))\n end function\n\n real(dp) function sphBesselJ_dr(n,x)\n real(dp) :: n\n real :: x\n sphBesselJ_dr = sphBesselJFunc(dble(n),dble(x))\n end function\n\n real(dp) function sphBesselJ_dd(n,x)\n real(dp) :: n, x\n sphBesselJ_dd = sphBesselJFunc(dble(n),dble(x))\n end function\n\n !**********************************************!\n ! Spherical Bessel Function of the Second Kind !\n !**********************************************!\n\n real(dp) function sphBesselYFunc(n,x)\n real(dp) :: n, x\n sphBesselYFunc = sqrt(pi_/(2.d0*x))*besselY(n+0.5d0,x)\n end function\n\n real(dp) function sphBesselY_ii(n,x)\n integer :: n, x\n sphBesselY_ii = sphBesselYFunc(dble(n),dble(x))\n end function\n\n real(dp) function sphBesselY_ir(n,x)\n integer :: n\n real :: x\n sphBesselY_ir = sphBesselYFunc(dble(n),dble(x))\n end function\n\n real(dp) function sphBesselY_id(n,x)\n integer :: n\n real(dp) :: x\n sphBesselY_id = sphBesselYFunc(dble(n),dble(x))\n end function\n\n real(dp) function sphBesselY_ri(n,x)\n real :: n\n integer :: x\n sphBesselY_ri = sphBesselYFunc(dble(n),dble(x))\n end function\n\n real(dp) function sphBesselY_di(n,x)\n real(dp) :: n\n integer :: x\n sphBesselY_di = sphBesselYFunc(dble(n),dble(x))\n end function\n\n real(dp) function sphBesselY_rr(n,x)\n real :: n, x\n sphBesselY_rr = sphBesselYFunc(dble(n),dble(x))\n end function\n\n real(dp) function sphBesselY_rd(n,x)\n real :: n\n real(dp) :: x\n sphBesselY_rd = sphBesselYFunc(dble(n),dble(x))\n end function\n\n real(dp) function sphBesselY_dr(n,x)\n real(dp) :: n\n real :: x\n sphBesselY_dr = sphBesselYFunc(dble(n),dble(x))\n end function\n\n real(dp) function sphBesselY_dd(n,x)\n real(dp) :: n, x\n sphBesselY_dd = sphBesselYFunc(dble(n),dble(x))\n end function\n\n !*********************************!\n ! Airy Function of the First Kind !\n !*********************************!\n\n real(dp) function airyAFunc(x)\n real(dp) :: x, airyResult\n if(x.lt.0.d0) then\n airyResult = besselJ(1.d0/3.d0,(2.d0/3.d0)*(abs(x)**(3.d0/2.d0)))\n airyResult = airyResult+besselJ(-1.d0/3.d0,(2.d0/3.d0)*(abs(x)**(3.d0/2.d0)))\n airyResult = airyResult*sqrt(abs(x)/9.d0)\n elseif(x.eq.0.d0) then\n airyResult = 1.d0/((3.d0**(2.d0/3.d0))*gamma(2.d0/3.d0))\n else\n airyResult = besselK(1.d0/3.d0,(2.d0/3.d0)*(x**(3.d0/2.d0)))\n airyResult = airyResult*sqrt(x/3.d0)/pi_\n end if\n airyAFunc = airyResult\n end function\n\n real(dp) function airyA_i(x)\n integer :: x\n airyA_i = airyAFunc(dble(x))\n end function\n\n real(dp) function airyA_r(x)\n real :: x\n airyA_r = airyAFunc(dble(x))\n end function\n\n real(dp) function airyA_d(x)\n real(dp) :: x\n airyA_d = airyAFunc(dble(x))\n end function\n\n !**********************************!\n ! Airy Function of the Second Kind !\n !************************&*********!\n\n real(dp) function airyBFunc(x)\n real(dp) :: x, airyResult\n if(x.lt.0.d0) then\n airyResult = besselJ(-1.d0/3.d0,(2.d0/3.d0)*(abs(x)**(3.d0/2.d0)))\n airyResult = airyResult-besselJ(1.d0/3.d0,(2.d0/3.d0)*(abs(x)**(3.d0/2.d0)))\n airyResult = airyResult*sqrt(abs(x)/3.d0)\n elseif(x.eq.0.d0) then\n airyResult = 1.d0/((3.d0**(1.d0/6.d0))*gamma(2.d0/3.d0))\n else\n airyResult = besselI(1.d0/3.d0,(2.d0/3.d0)*(x**(3.d0/2.d0)))\n airyResult = airyResult+besselI(-1.d0/3.d0,(2.d0/3.d0)*(x**(3.d0/2.d0)))\n airyResult = airyResult*sqrt(x/3.d0)\n end if\n airyBFunc = airyResult\n end function\n\n real(dp) function airyB_i(x)\n integer :: x\n airyB_i = airyBFunc(dble(x))\n end function\n\n real(dp) function airyB_r(x)\n real :: x\n airyB_r = airyBFunc(dble(x))\n end function\n\n real(dp) function airyB_d(x)\n real(dp) :: x\n airyB_d = airyBFunc(dble(x))\n end function\n\n !****************!\n ! Error Function !\n !****************!\n\n real(dp) function errf_IntFunc(n,c,x)\n integer :: n\n real(dp) :: c(n), x\n errf_IntFunc = exp(-x*x)\n end function\n\n real(dp) function errfFunc(x)\n real(dp) :: x, consts(0)\n errfFunc = gaussLegendre(errf_IntFunc,0.d0,x,0,consts)*2.d0/sqrt(pi_)\n end function\n\n real(dp) function errf_i(x)\n integer :: x\n errf_i = errfFunc(dble(x))\n end function\n\n real(dp) function errf_r(x)\n real :: x\n errf_r = errfFunc(dble(x))\n end function\n\n real(dp) function errf_d(x)\n real(dp) :: x\n errf_d = errfFunc(dble(x))\n end function\n\n !******************************!\n ! Complementary Error Function !\n !******************************!\n\n real(dp) function errfcFunc(x)\n real(dp) :: x\n errfcFunc = 1.d0-errf(x)\n end function\n\n real(dp) function errfc_i(x)\n integer :: x\n errfc_i = errfcFunc(dble(x))\n end function\n\n real(dp) function errfc_r(x)\n real :: x\n errfc_r = errfcFunc(dble(x))\n end function\n\n real(dp) function errfc_d(x)\n real(dp) :: x\n errfc_d = errfcFunc(dble(x))\n end function\n\n !***************!\n ! Beta Function !\n !***************!\n\n real(dp) function beta_IntFunc(n,c,x)\n integer :: n\n real(dp) :: c(n), x, func\n func = x**(c(1)-1.d0)\n func = func*((1.d0-x)**(c(2)-1.d0))\n beta_IntFunc = func\n end function\n\n real(dp) function betaFunc(x,y)\n real(dp) :: x, y, consts(2), intResults\n consts(1) = x\n consts(2) = y\n !betaFunc = gaussLegendre(beta_IntFunc,0.d0,1.d0,2,consts)\n betaFunc = gamma(x)*gamma(y)/gamma(x+y)\n end function\n\n real(dp) function beta_ii(x,y)\n integer :: x, y\n beta_ii = betaFunc(dble(x),dble(y))\n end function\n\n real(dp) function beta_ir(x,y)\n integer :: x\n real :: y\n beta_ir = betaFunc(dble(x),dble(y))\n end function\n\n real(dp) function beta_id(x,y)\n integer :: x\n real(dp) :: y\n beta_id = betaFunc(dble(x),dble(y))\n end function\n\n real(dp) function beta_ri(x,y)\n real :: x\n integer :: y\n beta_ri = betaFunc(dble(x),dble(y))\n end function\n\n real(dp) function beta_di(x,y)\n real(dp) :: x\n integer :: y\n beta_di = betaFunc(dble(x),dble(y))\n end function\n\n real(dp) function beta_rr(x,y)\n real :: x, y\n beta_rr = betaFunc(dble(x),dble(y))\n end function\n\n real(dp) function beta_rd(x,y)\n real :: x\n real(dp) :: y\n beta_rd = betaFunc(dble(x),dble(y))\n end function\n\n real(dp) function beta_dr(x,y)\n real(dp) :: x\n real :: y\n beta_dr = betaFunc(dble(x),dble(y))\n end function\n\n real(dp) function beta_dd(x,y)\n real(dp) :: x, y\n beta_dd = betaFunc(dble(x),dble(y))\n end function\n\n !**************************!\n ! Incomplete Beta Function !\n !**************************!\n\n real(dp) function incBetaFunc(x,a,b)\n real(dp) :: x, a, b, consts(2)\n consts(1) = a\n consts(2) = b\n incBetaFunc = gaussLegendre(beta_IntFunc,0.d0,x,2,consts)\n end function\n\n real(dp) function incBeta_iii(x,a,b)\n integer :: x, a, b\n incBeta_iii = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_iir(x,a,b)\n integer :: x, a\n real :: b\n incBeta_iir = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_iid(x,a,b)\n integer :: x, a\n real(dp) :: b\n incBeta_iid = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_iri(x,a,b)\n integer :: x, b\n real :: a\n incBeta_iri = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_irr(x,a,b)\n integer :: x\n real :: a, b\n incBeta_irr = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_ird(x,a,b)\n integer :: x\n real :: a\n real(dp) :: b\n incBeta_ird = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_idi(x,a,b)\n integer :: x, b\n real(dp) :: a\n incBeta_idi = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_idr(x,a,b)\n integer :: x\n real(dp) :: a\n real :: b\n incBeta_idr = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_idd(x,a,b)\n integer :: x\n real(dp) :: a, b\n incBeta_idd = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_rii(x,a,b)\n real :: x\n integer :: a, b\n incBeta_rii = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_rir(x,a,b)\n real :: x, b\n integer :: a\n incBeta_rir = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_rid(x,a,b)\n real :: x\n integer :: a\n real(dp) :: b\n incBeta_rid = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_rri(x,a,b)\n real :: x, a\n integer :: b\n incBeta_rri = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_rrr(x,a,b)\n real :: x, a, b\n incBeta_rrr = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_rrd(x,a,b)\n real :: x, a\n real(dp) :: b\n incBeta_rrd = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_rdi(x,a,b)\n real :: x\n real(dp) :: a\n integer :: b\n incBeta_rdi = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_rdr(x,a,b)\n real :: x, b\n real(dp) :: a\n incBeta_rdr = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_rdd(x,a,b)\n real :: x\n real(dp) :: a, b\n incBeta_rdd = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_dii(x,a,b)\n real(dp) :: x\n integer :: a, b\n incBeta_dii = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_dir(x,a,b)\n real(dp) :: x\n integer :: a\n real :: b\n incBeta_dir = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_did(x,a,b)\n real(dp) :: x, b\n integer :: a\n incBeta_did = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_dri(x,a,b)\n real(dp) :: x\n real :: a\n integer :: b\n incBeta_dri = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_drr(x,a,b)\n real(dp) :: x\n real :: a, b\n incBeta_drr = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_drd(x,a,b)\n real(dp) :: x, b\n real :: a\n incBeta_drd = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_ddi(x,a,b)\n real(dp) :: x, a\n integer :: b\n incBeta_ddi = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_ddr(x,a,b)\n real(dp) :: x, a\n real :: b\n incBeta_ddr = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n real(dp) function incBeta_ddd(x,a,b)\n real(dp) :: x, a, b\n incBeta_ddd = incBetaFunc(dble(x),dble(a),dble(b))\n end function\n\n !****************!\n ! Gamma Function !\n !****************!\n\n recursive function gammaFunction(x) result(res)\n implicit none\n integer :: i\n real(dp) :: p(8)\n complex(dp) :: x, res, q, t\n p(1) = 676.5203681218851d0\n p(2) = -1259.1392167224028d0\n p(3) = 771.32342877765313d0\n p(4) = -176.61502916214059d0\n p(5) = 12.507343278686905d0\n p(6) = -0.13857109526572012d0\n p(7) = 9.9843695780195716d-6\n p(8) = 1.5056327351493116d-7\n\n if(real(x).lt.0.5d0) then\n res = pi_ / (sin(pi_*x)*gammaFunction(1.d0-x))\n else\n x = x-1.d0\n q = cmplx(0.99999999999980993d0,0.d0,dp)\n do i=1,8\n q = q+p(i)/(x+i+1.d0)\n end do\n t = x + 8 - 0.5\n res = sqrt(2.d0*pi_)*(t**(x+0.5d0))*exp(-t)*x\n end if\n end function\n\n real(dp) function gammaFunc(x)\n real(dp) :: x\n gammaFunc = real(gammaFunction(cmplx(x,0.d0,dp)))\n end function\n\n !**********************!\n ! Legendre Polynomials !\n !**********************!\n\n recursive function legendrePolyFunc(n,x) result(res)\n integer :: n\n real(dp) :: x, res\n if(n.eq.0) then\n res = 1\n elseif(n.eq.1) then\n res = x\n else\n res = (2*(n-1)+1)*x*legendrePolyFunc(n-1,x)\n res = res - (n-1)*legendrePolyFunc(n-2,x)\n res = res/n\n end if\n end function\n\n real(dp) function legendrePoly_i(n,x)\n integer :: n, x\n legendrePoly_i = legendrePolyFunc(n,dble(x))\n end function\n\n real(dp) function legendrePoly_r(n,x)\n integer :: n\n real :: x\n legendrePoly_r = legendrePolyFunc(n,dble(x))\n end function\n\n real(dp) function legendrePoly_d(n,x)\n integer :: n\n real(dp) :: x\n legendrePoly_d = legendrePolyFunc(n,dble(x))\n end function\n\n !***********************************!\n ! Hermite Polynomials (Physicists') !\n !***********************************!\n\n recursive function hermitePolyFunc(n,x) result(res)\n integer :: n\n real(dp) :: x, res\n if(n.eq.0) then\n res = 1.d0\n elseif(n.eq.1) then\n res = 2.d0*x\n else\n res = 2.d0*x*hermitePolyFunc(n-1,x)\n res = res - 2.d0*(n-1)*hermitePolyFunc(n-2,x)\n end if\n end function\n\n real(dp) function hermitePoly_i(n,x)\n integer :: n, x\n hermitePoly_i = hermitePolyFunc(n,dble(x))\n end function\n\n real(dp) function hermitePoly_r(n,x)\n integer :: n\n real :: x\n hermitePoly_r = hermitePolyFunc(n,dble(x))\n end function\n\n real(dp) function hermitePoly_d(n,x)\n integer :: n\n real(dp) :: x\n hermitePoly_d = hermitePolyFunc(n,dble(x))\n end function\n\n !*************************************!\n ! Hermite Polynomials (Probabilists') !\n !*************************************!\n\n recursive function hermitePolyProbFunc(n,x) result(res)\n integer :: n\n real(dp) :: x, res\n if(n.eq.0) then\n res = 1.d0\n elseif(n.eq.1) then\n res = x\n else\n res = x*hermitePolyProbFunc(n-1,x)\n res = res - (n-1)*hermitePolyProbFunc(n-2,x)\n end if\n end function\n\n real(dp) function hermitePolyProb_i(n,x)\n integer :: n, x\n hermitePolyProb_i = hermitePolyProbFunc(n,dble(x))\n end function\n\n real(dp) function hermitePolyProb_r(n,x)\n integer :: n\n real :: x\n hermitePolyProb_r = hermitePolyProbFunc(n,dble(x))\n end function\n\n real(dp) function hermitePolyProb_d(n,x)\n integer :: n\n real(dp) :: x\n hermitePolyProb_d = hermitePolyProbFunc(n,dble(x))\n end function\n\n !**********************!\n ! Laguerre Polynomials !\n !**********************!\n\n recursive function laguerrePolyFunc(n,x) result(res)\n integer :: n\n real(dp) :: x, res\n if(n.eq.0) then\n res = 1.d0\n elseif(n.eq.1) then\n res = 1.d0 - x\n else\n res = (2.d0*(n-1)+1.d0-x)*laguerrePolyFunc(n-1,x)\n res = res - (n-1)*laguerrePolyFunc(n-2,x)\n res = res/n\n end if\n end function\n\n real(dp) function laguerrePoly_i(n,x)\n integer :: n, x\n laguerrePoly_i = laguerrePolyFunc(n,dble(x))\n end function\n\n real(dp) function laguerrePoly_r(n,x)\n integer :: n\n real :: x\n laguerrePoly_r = laguerrePolyFunc(n,dble(x))\n end function\n\n real(dp) function laguerrePoly_d(n,x)\n integer :: n\n real(dp) :: x\n laguerrePoly_d = laguerrePolyFunc(n,dble(x))\n end function\n\n !*********************************!\n ! Associated Laguerre Polynomials !\n !*********************************!\n\n recursive function assocLaguerrePolyFunc(n,a,x) result(res)\n integer :: n\n real(dp) :: a, x, res\n if(n.eq.0) then\n res = 1.d0\n elseif(n.eq.1) then\n res = 1.d0 + a - x\n else\n res = (2.d0*(n-1)+1.d0+a-x)*assocLaguerrePolyFunc(n-1,a,x)\n res = res - (n-1+a)*assocLaguerrePolyFunc(n-2,a,x)\n res = res/n\n end if\n end function\n\n real(dp) function assocLaguerrePoly_ii(n,a,x)\n integer :: n, a, x\n assocLaguerrePoly_ii = assocLaguerrePolyFunc(n,dble(a),dble(x))\n end function\n\n real(dp) function assocLaguerrePoly_ir(n,a,x)\n integer :: n, a\n real :: x\n assocLaguerrePoly_ir = assocLaguerrePolyFunc(n,dble(a),dble(x))\n end function\n\n real(dp) function assocLaguerrePoly_id(n,a,x)\n integer :: n, a\n real(dp) :: x\n assocLaguerrePoly_id = assocLaguerrePolyFunc(n,dble(a),dble(x))\n end function\n\n real(dp) function assocLaguerrePoly_ri(n,a,x)\n integer :: n, x\n real :: a\n assocLaguerrePoly_ri = assocLaguerrePolyFunc(n,dble(a),dble(x))\n end function\n\n real(dp) function assocLaguerrePoly_rr(n,a,x)\n integer :: n\n real :: a, x\n assocLaguerrePoly_rr = assocLaguerrePolyFunc(n,dble(a),dble(x))\n end function\n\n real(dp) function assocLaguerrePoly_rd(n,a,x)\n integer :: n\n real :: a\n real(dp) :: x\n assocLaguerrePoly_rd = assocLaguerrePolyFunc(n,dble(a),dble(x))\n end function\n\n real(dp) function assocLaguerrePoly_di(n,a,x)\n integer :: n, x\n real(dp) :: a\n assocLaguerrePoly_di = assocLaguerrePolyFunc(n,dble(a),dble(x))\n end function\n\n real(dp) function assocLaguerrePoly_dr(n,a,x)\n integer :: n\n real(dp) :: a\n real :: x\n assocLaguerrePoly_dr = assocLaguerrePolyFunc(n,dble(a),dble(x))\n end function\n\n real(dp) function assocLaguerrePoly_dd(n,a,x)\n integer :: n\n real(dp) :: a, x\n assocLaguerrePoly_dd = assocLaguerrePolyFunc(n,dble(a),dble(x))\n end function\n\n !*****************************************!\n ! Chebyshev Polynomials of the First Kind !\n !*****************************************!\n\n recursive function chebyPolyTFunc(n,x) result(res)\n integer :: n\n real(dp) :: x, res\n if(n.eq.0) then\n res = 1.d0\n elseif(n.eq.1) then\n res = x\n else\n res = 2.d0*x*chebyPolyTFunc(n-1,x)\n res = res - chebyPolyTFunc(n-2,x)\n end if\n end function\n\n real(dp) function chebyPolyT_i(n,x)\n integer :: n, x\n chebyPolyT_i = chebyPolyTFunc(n,dble(x))\n end function\n\n real(dp) function chebyPolyT_r(n,x)\n integer :: n\n real :: x\n chebyPolyT_r = chebyPolyTFunc(n,dble(x))\n end function\n\n real(dp) function chebyPolyT_d(n,x)\n integer :: n\n real(dp) :: x\n chebyPolyT_d = chebyPolyTFunc(n,dble(x))\n end function\n\n !******************************************!\n ! Chebyshev Polynomials of the Second Kind !\n !******************************************!\n\n recursive function chebyPolyUFunc(n,x) result(res)\n integer :: n\n real(dp) :: x, res\n if(n.eq.0) then\n res = 1.d0\n elseif(n.eq.1) then\n res = 2.d0*x\n else\n res = 2.d0*x*chebyPolyUFunc(n-1,x)\n res = res - chebyPolyUFunc(n-2,x)\n end if\n end function\n\n real(dp) function chebyPolyU_i(n,x)\n integer :: n, x\n chebyPolyU_i = chebyPolyUFunc(n,dble(x))\n end function\n\n real(dp) function chebyPolyU_r(n,x)\n integer :: n\n real :: x\n chebyPolyU_r = chebyPolyUFunc(n,dble(x))\n end function\n\n real(dp) function chebyPolyU_d(n,x)\n integer :: n\n real(dp) :: x\n chebyPolyU_d = chebyPolyUFunc(n,dble(x))\n end function\n\n !****************!\n ! Sine Integrals !\n !****************!\n\n real(dp) function sini_IntFunc(n,c,x)\n integer :: n\n real(dp) :: c(n),x\n sini_IntFunc = sin(x)/x\n end function\n\n real(dp) function siniFunc(x)\n real(dp) :: x, consts(0)\n siniFunc = gaussLegendre(sini_IntFunc,0.d0,x,0,consts)\n end function\n\n real(dp) function sini_i(x)\n integer :: x\n sini_i = siniFunc(dble(x))\n end function\n\n real(dp) function sini_r(x)\n real :: x\n sini_r = siniFunc(dble(x))\n end function\n\n real(dp) function sini_d(x)\n real(dp) :: x\n sini_d = siniFunc(dble(x))\n end function\n\n !***************************!\n ! Hyperbolic Sine Integrals !\n !***************************!\n\n real(dp) function hypSini_IntFunc(n,c,x)\n integer :: n\n real(dp) :: c(n),x\n hypSini_IntFunc = sinh(x)/x\n end function\n\n real(dp) function hypSiniFunc(x)\n real(dp) :: x, consts(0)\n hypSiniFunc = gaussLegendre(hypSini_IntFunc,0.d0,x,0,consts)\n end function\n\n real(dp) function hypSini_i(x)\n integer :: x\n hypSini_i = hypSiniFunc(dble(x))\n end function\n\n real(dp) function hypSini_r(x)\n real :: x\n hypSini_r = hypSiniFunc(dble(x))\n end function\n\n real(dp) function hypSini_d(x)\n real(dp) :: x\n hypSini_d = hypSiniFunc(dble(x))\n end function\n\n !******************!\n ! Cosine Integrals !\n !******************!\n\n real(dp) function cosi_IntFunc(n,c,x)\n integer :: n\n real(dp) :: c(n),x\n cosi_IntFunc = (cos(x) - 1.d0)/x\n end function\n\n real(dp) function cosiFunc(x)\n real(dp) :: x, consts(0)\n cosiFunc = em_ + log(x) + gaussLegendre(cosi_IntFunc,0.d0,x,0,consts)\n end function\n\n real(dp) function cosi_i(x)\n integer :: x\n cosi_i = cosiFunc(dble(x))\n end function\n\n real(dp) function cosi_r(x)\n real :: x\n cosi_r = cosiFunc(dble(x))\n end function\n\n real(dp) function cosi_d(x)\n real(dp) :: x\n cosi_d = cosiFunc(dble(x))\n end function\n\n !*****************************!\n ! Hyperbolic Cosine Integrals !\n !*****************************!\n\n real(dp) function hypCosi_IntFunc(n,c,x)\n integer :: n\n real(dp) :: c(n),x\n hypCosi_IntFunc = (cosh(x) - 1.d0)/x\n end function\n\n real(dp) function hypCosiFunc(x)\n real(dp) :: x, consts(0)\n hypCosiFunc = em_ + log(x) + gaussLegendre(hypCosi_IntFunc,0.d0,x,0,consts)\n end function\n\n real(dp) function hypCosi_i(x)\n integer :: x\n hypCosi_i = hypCosiFunc(dble(x))\n end function\n\n real(dp) function hypCosi_r(x)\n real :: x\n hypCosi_r = hypCosiFunc(dble(x))\n end function\n\n real(dp) function hypCosi_d(x)\n real(dp) :: x\n hypCosi_d = hypCosiFunc(dble(x))\n end function\n\n !*****************************!\n ! Hypergeometric Function 0F1 !\n !*****************************!\n\n function hypGeo0F1_odeFunc(nF,nC,c,x,y)\n integer :: nF, nC\n real(dp) :: hypGeo0F1_odeFunc(nF), x, y(nF)\n complex(dp) :: c(nC), zs, fT, fpT, f, fp, dz\n dz = c(2)-c(1)\n zs = c(1) + x*dz\n fT = cmplx(y(1),y(2),dp); fpT = cmplx(y(3),y(4),dp)\n f = dz*fpT\n fp = (fT-c(3)*fpT)*(dz/zs)\n hypGeo0F1_odeFunc(1) = real(f); hypGeo0F1_odeFunc(2) = aimag(f)\n hypGeo0F1_odeFunc(3) = real(fp); hypGeo0F1_odeFunc(4) = aimag(fp)\n end function\n\n complex(dp) function hypGeo0F1_series(a,z)\n !! Returns Hypergeometric Function 0F1\n !! Should be only used for |z|<1.0\n integer :: i\n complex(dp) :: a, z, result, oldResult, indvResult\n result = cmplx(0.d0,0.d0,dp)\n oldResult = result\n do i=0, 100000\n indvResult = (z**i)/(pochhammerR(a,i)*gamma(dble(i)+1.d0))\n if (indvResult /= indvResult) exit\n result = result + indvResult\n if (abs(result-oldResult).le.1.d-16) exit\n oldResult = result\n end do\n hypGeo0F1_series = result\n end function\n\n complex(dp) function hypGeo0F1Deriv_series(a,z)\n !! Returns Derivative of the Hypergeometric Function 0F1\n !! Should be only used for |z|<1.0\n complex(dp) :: a, z\n hypGeo0F1Deriv_series = hypGeo1F0_series(a+1.d0,z)/a\n end function\n\n complex(dp) function hypGeo0F1Func(a,z)\n complex(dp) :: a, z\n real(dp) :: y0(4), odeResult(4)\n complex(dp) :: z0, series(2), consts(3)\n if(abs(z).lt.1.d0) then\n hypGeo0F1Func = hypGeo0F1_series(a,z)\n return\n else if(real(z).gt.0.d0 .and. real(z).lt.1.d0) then\n z0 = cmplx(0.5d0,0.d0,dp)\n else if(real(z).gt.-1.d0 .and. real(z).lt.0.d0) then\n z0 = cmplx(-0.5d0,0.d0,dp)\n else if(real(z).gt.1.d0) then\n z0 = cmplx(0.d0,0.5d0,dp)\n else if(real(z).lt.-1.d0) then\n z0 = cmplx(0.d0,-0.5d0,dp)\n end if\n series(1) = hypGeo0F1_series(a,z0)\n series(2) = hypGeo0F1Deriv_series(a,z0)\n consts(1) = z0; consts(2) = z; consts(3) = a;\n y0(1) = real(series(1)); y0(2) = aimag(series(1))\n y0(3) = real(series(2)); y0(4) = aimag(series(2))\n odeResult = rk1AdaptStepCmplxC(hypGeo0F1_odeFunc,4,0.d0,1.d0,y0,3,consts)\n hypGeo0F1Func = cmplx(odeResult(1),odeResult(2),dp)\n end function\n\n complex(dp) function hypGeo0F1DerivFunc(a,z)\n complex(dp) :: a, z\n hypGeo0F1DerivFunc = hypGeo0F1Func(a+1.d0,z)/a\n end function\n\n complex(dp) function hypGeo0F1_ii(a,z)\n integer :: a, z\n hypGeo0F1_ii = hypGeo0F1Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1_ri(a,z)\n integer :: z\n real :: a\n hypGeo0F1_ri = hypGeo0F1Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1_di(a,z)\n integer :: z\n real(dp) :: a\n hypGeo0F1_di = hypGeo0F1Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1_ir(a,z)\n integer :: a\n real :: z\n hypGeo0F1_ir = hypGeo0F1Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1_rr(a,z)\n real :: a, z\n hypGeo0F1_rr = hypGeo0F1Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1_dr(a,z)\n real :: z\n real(dp) :: a\n hypGeo0F1_dr = hypGeo0F1Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1_id(a,z)\n integer :: a\n real(dp) :: z\n hypGeo0F1_id = hypGeo0F1Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1_rd(a,z)\n real :: a\n real(dp) :: z\n hypGeo0F1_rd = hypGeo0F1Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1_dd(a,z)\n real(dp) :: a, z\n hypGeo0F1_dd = hypGeo0F1Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1_iCr(a,z)\n integer :: a\n complex :: z\n hypGeo0F1_iCr = hypGeo0F1Func(cmplx(a,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo0F1_rCr(a,z)\n real :: a\n complex :: z\n hypGeo0F1_rCr = hypGeo0F1Func(cmplx(a,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo0F1_dCr(a,z)\n real(dp) :: a\n complex :: z\n hypGeo0F1_dCr = hypGeo0F1Func(cmplx(a,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo0F1_iCd(a,z)\n integer :: a\n complex(dp) :: z\n hypGeo0F1_iCd = hypGeo0F1Func(cmplx(a,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo0F1_rCd(a,z)\n real :: a\n complex(dp) :: z\n hypGeo0F1_rCd = hypGeo0F1Func(cmplx(a,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo0F1_dCd(a,z)\n real(dp) :: a\n complex(dp) :: z\n hypGeo0F1_dCd = hypGeo0F1Func(cmplx(a,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo0F1_CrCr(a,z)\n complex :: a, z\n hypGeo0F1_CrCr = hypGeo0F1Func(cmplx(real(a),aimag(a),dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo0F1_CrCd(a,z)\n complex :: a\n complex(dp) :: z\n hypGeo0F1_CrCd = hypGeo0F1Func(cmplx(real(a),aimag(a),dp),z)\n end function\n\n complex(dp) function hypGeo0F1_CdCd(a,z)\n complex(dp) :: a, z\n hypGeo0F1_CdCd = hypGeo0F1Func(a,z)\n end function\n\n complex(dp) function hypGeo0F1Deriv_ii(a,z)\n integer :: a, z\n hypGeo0F1Deriv_ii = hypGeo0F1DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1Deriv_ri(a,z)\n integer :: z\n real :: a\n hypGeo0F1Deriv_ri = hypGeo0F1DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1Deriv_di(a,z)\n integer :: z\n real(dp) :: a\n hypGeo0F1Deriv_di = hypGeo0F1DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1Deriv_ir(a,z)\n integer :: a\n real :: z\n hypGeo0F1Deriv_ir = hypGeo0F1DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1Deriv_rr(a,z)\n real :: a, z\n hypGeo0F1Deriv_rr = hypGeo0F1DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1Deriv_dr(a,z)\n real :: z\n real(dp) :: a\n hypGeo0F1Deriv_dr = hypGeo0F1DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1Deriv_id(a,z)\n integer :: a\n real(dp) :: z\n hypGeo0F1Deriv_id = hypGeo0F1DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1Deriv_rd(a,z)\n real :: a\n real(dp) :: z\n hypGeo0F1Deriv_rd = hypGeo0F1DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1Deriv_dd(a,z)\n real(dp) :: a, z\n hypGeo0F1Deriv_dd = hypGeo0F1DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo0F1Deriv_iCr(a,z)\n integer :: a\n complex :: z\n hypGeo0F1Deriv_iCr = hypGeo0F1DerivFunc(cmplx(a,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo0F1Deriv_rCr(a,z)\n real :: a\n complex :: z\n hypGeo0F1Deriv_rCr = hypGeo0F1DerivFunc(cmplx(a,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo0F1Deriv_dCr(a,z)\n real(dp) :: a\n complex :: z\n hypGeo0F1Deriv_dCr = hypGeo0F1DerivFunc(cmplx(a,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo0F1Deriv_iCd(a,z)\n integer :: a\n complex(dp) :: z\n hypGeo0F1Deriv_iCd = hypGeo0F1DerivFunc(cmplx(a,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo0F1Deriv_rCd(a,z)\n real :: a\n complex(dp) :: z\n hypGeo0F1Deriv_rCd = hypGeo0F1DerivFunc(cmplx(a,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo0F1Deriv_dCd(a,z)\n real(dp) :: a\n complex(dp) :: z\n hypGeo0F1Deriv_dCd = hypGeo0F1DerivFunc(cmplx(a,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo0F1Deriv_CrCr(a,z)\n complex :: a, z\n hypGeo0F1Deriv_CrCr = hypGeo0F1DerivFunc(cmplx(real(a),aimag(a),dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo0F1Deriv_CrCd(a,z)\n complex :: a\n complex(dp) :: z\n hypGeo0F1Deriv_CrCd = hypGeo0F1DerivFunc(cmplx(real(a),aimag(a),dp),z)\n end function\n\n complex(dp) function hypGeo0F1Deriv_CdCd(a,z)\n complex(dp) :: a, z\n hypGeo0F1Deriv_CdCd = hypGeo0F1DerivFunc(a,z)\n end function\n\n !*****************************!\n ! Hypergeometric Function 1F0 !\n !*****************************!\n\n function hypGeo1F0_odeFunc(nF,nC,c,x,y)\n integer :: nF, nC\n real(dp) :: hypGeo1F0_odeFunc(nF), x, y(nF)\n complex(dp) :: c(nC), zs, fT, f, dz\n dz = c(2)-c(1)\n zs = c(1) + x*dz\n fT = cmplx(y(1),y(2),dp)\n f = dz*fT*c(3)/(1.d0-zs)\n hypGeo1F0_odeFunc(1) = real(f)\n hypGeo1F0_odeFunc(2) = aimag(f)\n end function\n\n complex(dp) function hypGeo1F0_series(a,z)\n !! Returns Hypergeometric Function 1F0\n !! Should be only used for |z|<1.0\n integer :: i\n complex(dp) :: a, z, result, oldResult, indvResult\n result = cmplx(0.d0,0.d0,dp)\n oldResult = result\n do i=0, 100000\n indvResult = pochhammerR(a,i)*(z**i)/gamma(dble(i)+1.d0)\n if (indvResult /= indvResult) exit\n result = result + indvResult\n if (abs(result-oldResult).le.1.d-16) exit\n oldResult = result\n end do\n hypGeo1F0_series = result\n end function\n\n complex(dp) function hypGeo1F0Deriv_series(a,z)\n !! Returns Derivative of the Hypergeometric Function 1F0\n !! Should be only used for |z|<1.0\n complex(dp) :: a, z\n hypGeo1F0Deriv_series = a*hypGeo1F0_series(a+1.d0,z)\n end function\n\n complex(dp) function hypGeo1F0Func(a,z)\n complex(dp) :: a, z\n real(dp) :: y0(2), odeResult(2)\n complex(dp) :: z0, series, consts(3)\n z0 = cmplx(0.d0,0.d0,dp)\n if(abs(z).lt.1.d0) then\n hypGeo1F0Func = hypGeo1F0_series(a,z)\n return\n else if(real(z).gt.0.d0 .and. real(z).lt.1.d0) then\n z0 = cmplx(0.5d0,0.d0,dp)\n else if(real(z).gt.-1.d0 .and. real(z).lt.0.d0) then\n z0 = cmplx(-0.5d0,0.d0,dp)\n else if(real(z).gt.1.d0) then\n z0 = cmplx(0.d0,0.5d0,dp)\n else if(real(z).lt.-1.d0) then\n z0 = cmplx(0.d0,-0.5d0,dp)\n end if\n series = hypGeo1F0_series(a,z0)\n consts(1) = z0; consts(2) = z; consts(3) = a;\n y0(1) = real(series); y0(2) = aimag(series)\n odeResult = rk1AdaptStepCmplxC(hypGeo1F0_odeFunc,2,0.d0,1.d0,y0,3,consts)\n hypGeo1F0Func = cmplx(odeResult(1),odeResult(2),dp)\n end function\n\n complex(dp) function hypGeo1F0DerivFunc(a,z)\n complex(dp) :: a, z\n hypGeo1F0DerivFunc = a*hypGeo1F0Func(a+1.d0,z)\n end function\n\n complex(dp) function hypGeo1F0_ii(a,z)\n integer :: a, z\n hypGeo1F0_ii = hypGeo1F0Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0_ri(a,z)\n integer :: z\n real :: a\n hypGeo1F0_ri = hypGeo1F0Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0_di(a,z)\n integer :: z\n real(dp) :: a\n hypGeo1F0_di = hypGeo1F0Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0_ir(a,z)\n integer :: a\n real :: z\n hypGeo1F0_ir = hypGeo1F0Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0_rr(a,z)\n real :: a, z\n hypGeo1F0_rr = hypGeo1F0Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0_dr(a,z)\n real :: z\n real(dp) :: a\n hypGeo1F0_dr = hypGeo1F0Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0_id(a,z)\n integer :: a\n real(dp) :: z\n hypGeo1F0_id = hypGeo1F0Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0_rd(a,z)\n real :: a\n real(dp) :: z\n hypGeo1F0_rd = hypGeo1F0Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0_dd(a,z)\n real(dp) :: a, z\n hypGeo1F0_dd = hypGeo1F0Func(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0_iCr(a,z)\n integer :: a\n complex :: z\n hypGeo1F0_iCr = hypGeo1F0Func(cmplx(a,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo1F0_rCr(a,z)\n real :: a\n complex :: z\n hypGeo1F0_rCr = hypGeo1F0Func(cmplx(a,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo1F0_dCr(a,z)\n real(dp) :: a\n complex :: z\n hypGeo1F0_dCr = hypGeo1F0Func(cmplx(a,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo1F0_iCd(a,z)\n integer :: a\n complex(dp) :: z\n hypGeo1F0_iCd = hypGeo1F0Func(cmplx(a,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo1F0_rCd(a,z)\n real :: a\n complex(dp) :: z\n hypGeo1F0_rCd = hypGeo1F0Func(cmplx(a,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo1F0_dCd(a,z)\n real(dp) :: a\n complex(dp) :: z\n hypGeo1F0_dCd = hypGeo1F0Func(cmplx(a,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo1F0_CrCr(a,z)\n complex :: a, z\n hypGeo1F0_CrCr = hypGeo1F0Func(cmplx(real(a),aimag(a),dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo1F0_CrCd(a,z)\n complex :: a\n complex(dp) :: z\n hypGeo1F0_CrCd = hypGeo1F0Func(cmplx(real(a),aimag(a),dp),z)\n end function\n\n complex(dp) function hypGeo1F0_CdCd(a,z)\n complex(dp) :: a, z\n hypGeo1F0_CdCd = hypGeo1F0Func(a,z)\n end function\n\n complex(dp) function hypGeo1F0Deriv_ii(a,z)\n integer :: a, z\n hypGeo1F0Deriv_ii = hypGeo1F0DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0Deriv_ri(a,z)\n integer :: z\n real :: a\n hypGeo1F0Deriv_ri = hypGeo1F0DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0Deriv_di(a,z)\n integer :: z\n real(dp) :: a\n hypGeo1F0Deriv_di = hypGeo1F0DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0Deriv_ir(a,z)\n integer :: a\n real :: z\n hypGeo1F0Deriv_ir = hypGeo1F0DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0Deriv_rr(a,z)\n real :: a, z\n hypGeo1F0Deriv_rr = hypGeo1F0DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0Deriv_dr(a,z)\n real :: z\n real(dp) :: a\n hypGeo1F0Deriv_dr = hypGeo1F0DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0Deriv_id(a,z)\n integer :: a\n real(dp) :: z\n hypGeo1F0Deriv_id = hypGeo1F0DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0Deriv_rd(a,z)\n real :: a\n real(dp) :: z\n hypGeo1F0Deriv_rd = hypGeo1F0DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0Deriv_dd(a,z)\n real(dp) :: a, z\n hypGeo1F0Deriv_dd = hypGeo1F0DerivFunc(cmplx(a,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F0Deriv_iCr(a,z)\n integer :: a\n complex :: z\n hypGeo1F0Deriv_iCr = hypGeo1F0DerivFunc(cmplx(a,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo1F0Deriv_rCr(a,z)\n real :: a\n complex :: z\n hypGeo1F0Deriv_rCr = hypGeo1F0DerivFunc(cmplx(a,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo1F0Deriv_dCr(a,z)\n real(dp) :: a\n complex :: z\n hypGeo1F0Deriv_dCr = hypGeo1F0DerivFunc(cmplx(a,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo1F0Deriv_iCd(a,z)\n integer :: a\n complex(dp) :: z\n hypGeo1F0Deriv_iCd = hypGeo1F0DerivFunc(cmplx(a,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo1F0Deriv_rCd(a,z)\n real :: a\n complex(dp) :: z\n hypGeo1F0Deriv_rCd = hypGeo1F0DerivFunc(cmplx(a,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo1F0Deriv_dCd(a,z)\n real(dp) :: a\n complex(dp) :: z\n hypGeo1F0Deriv_dCd = hypGeo1F0DerivFunc(cmplx(a,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo1F0Deriv_CrCr(a,z)\n complex :: a, z\n hypGeo1F0Deriv_CrCr = hypGeo1F0DerivFunc(cmplx(real(a),aimag(a),dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo1F0Deriv_CrCd(a,z)\n complex :: a\n complex(dp) :: z\n hypGeo1F0Deriv_CrCd = hypGeo1F0DerivFunc(cmplx(real(a),aimag(a),dp),z)\n end function\n\n complex(dp) function hypGeo1F0Deriv_CdCd(a,z)\n complex(dp) :: a, z\n hypGeo1F0Deriv_CdCd = hypGeo1F0DerivFunc(a,z)\n end function\n\n !*****************************!\n ! Hypergeometric Function 1F1 !\n !*****************************!\n\n function hypGeo1F1_odeFunc(nF,nC,c,x,y)\n integer :: nF, nC\n real(dp) :: hypGeo1F1_odeFunc(nF), x, y(nF)\n complex(dp) :: c(nC), zs, fT, fpT, f, fp, dz\n dz = c(2)-c(1)\n zs = c(1) + x*dz\n fT = cmplx(y(1),y(2),dp); fpT = cmplx(y(3),y(4),dp)\n f = dz*fpT\n fp = (c(3)*fT-(c(4)-zs)*fpT)*dz/zs\n hypGeo1F1_odeFunc(1) = real(f); hypGeo1F1_odeFunc(2) = aimag(f)\n hypGeo1F1_odeFunc(3) = real(fp); hypGeo1F1_odeFunc(4) = aimag(fp)\n end function\n\n complex(dp) function hypGeo1F1_series(a,b,z)\n !! Returns Hypergeometric Function 1F1\n !! Should be only used for |z|<1.0\n integer :: i\n complex(dp) :: a, b, z, result, oldResult, indvResult\n result = cmplx(0.d0,0.d0,dp)\n oldResult = result\n do i=0, 100000\n indvResult = (pochhammerR(a,i)/pochhammerR(b,i))*(z**i)/gamma(dble(i)+1.d0)\n if (indvResult /= indvResult) exit\n result = result + indvResult\n if (abs(result-oldResult).le.1.d-16) exit\n oldResult = result\n end do\n hypGeo1F1_series = result\n end function\n\n complex(dp) function hypGeo1F1Deriv_series(a,b,z)\n !! Returns Derivative of the Hypergeometric Function 1F1\n !! Should be only used for |z|<1.0\n complex(dp) :: a, b, z\n hypGeo1F1Deriv_series = (a/b)*hypGeo1F1_series(a+1.d0,b+1.d0,z)\n end function\n\n complex(dp) function hypGeo1F1Func(a,b,z)\n complex(dp) :: a, b, z\n real(dp) :: y0(4), odeResult(4)\n complex(dp) :: z0, series(2), consts(4)\n if(abs(z).lt.1.d0) then\n hypGeo1F1Func = hypGeo1F1_series(a,b,z)\n return\n else if(real(z).gt.0.d0 .and. real(z).lt.1.d0) then\n z0 = cmplx(0.5d0,0.d0,dp)\n else if(real(z).gt.-1.d0 .and. real(z).lt.0.d0) then\n z0 = cmplx(-0.5d0,0.d0,dp)\n else if(real(z).gt.1.d0) then\n z0 = cmplx(0.d0,0.5d0,dp)\n else if(real(z).lt.-1.d0) then\n z0 = cmplx(0.d0,-0.5d0,dp)\n end if\n series(1) = hypGeo1F1_series(a,b,z0)\n series(2) = hypGeo1F1Deriv_series(a,b,z0)\n consts(1) = z0; consts(2) = z\n consts(3) = a; consts(4) = b;\n y0(1) = real(series(1)); y0(2) = aimag(series(1))\n y0(3) = real(series(2)); y0(4) = aimag(series(2))\n odeResult = rk1AdaptStepCmplxC(hypGeo1F1_odeFunc,4,0.d0,1.d0,y0,4,consts)\n hypGeo1F1Func = cmplx(odeResult(1),odeResult(2),dp)\n end function\n\n complex(dp) function hypGeo1F1DerivFunc(a,b,z)\n complex(dp) :: a, b, z\n hypGeo1F1DerivFunc = (a/b)*hypGeo1F1Func(a+1.d0,b+1.d0,z)\n end function\n\n complex(dp) function hypGeo1F1_iii(a,b,z)\n integer :: a, b, z\n hypGeo1F1_iii = hypGeo1F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1_rri(a,b,z)\n integer :: z\n real :: a, b\n hypGeo1F1_rri = hypGeo1F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1_ddi(a,b,z)\n integer :: z\n real(dp) :: a, b\n hypGeo1F1_ddi = hypGeo1F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1_iir(a,b,z)\n integer :: a, b\n real :: z\n hypGeo1F1_iir = hypGeo1F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1_rrr(a,b,z)\n real :: a, b, z\n hypGeo1F1_rrr = hypGeo1F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1_ddr(a,b,z)\n real :: z\n real(dp) :: a, b\n hypGeo1F1_ddr = hypGeo1F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1_iid(a,b,z)\n integer :: a, b\n real(dp) :: z\n hypGeo1F1_iid = hypGeo1F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1_rrd(a,b,z)\n real :: a, b\n real(dp) :: z\n hypGeo1F1_rrd = hypGeo1F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1_ddd(a,b,z)\n real(dp) :: a, b, z\n hypGeo1F1_ddd = hypGeo1F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1_iiCr(a,b,z)\n integer :: a, b\n complex :: z\n hypGeo1F1_iiCr = hypGeo1F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo1F1_rrCr(a,b,z)\n real :: a, b\n complex :: z\n hypGeo1F1_rrCr = hypGeo1F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo1F1_ddCr(a,b,z)\n real(dp) :: a, b\n complex :: z\n hypGeo1F1_ddCr = hypGeo1F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo1F1_iiCd(a,b,z)\n integer :: a, b\n complex(dp) :: z\n hypGeo1F1_iiCd = hypGeo1F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo1F1_rrCd(a,b,z)\n real :: a, b\n complex(dp) :: z\n hypGeo1F1_rrCd = hypGeo1F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo1F1_ddCd(a,b,z)\n real(dp) :: a, b\n complex(dp) :: z\n hypGeo1F1_ddCd = hypGeo1F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo1F1_CrCrCr(a,b,z)\n complex :: a, b, z\n hypGeo1F1_CrCrCr = hypGeo1F1Func(cmplx(real(a),aimag(a),dp),cmplx(real(b),aimag(b),dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo1F1_CrCrCd(a,b,z)\n complex :: a, b\n complex(dp) :: z\n hypGeo1F1_CrCrCd = hypGeo1F1Func(cmplx(real(a),aimag(a),dp),cmplx(real(b),aimag(b),dp),z)\n end function\n\n complex(dp) function hypGeo1F1_CdCdCd(a,b,z)\n complex(dp) :: a, b, z\n hypGeo1F1_CdCdCd = hypGeo1F1Func(a,b,z)\n end function\n\n complex(dp) function hypGeo1F1Deriv_iii(a,b,z)\n integer :: a, b, z\n hypGeo1F1Deriv_iii = hypGeo1F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1Deriv_rri(a,b,z)\n integer :: z\n real :: a, b\n hypGeo1F1Deriv_rri = hypGeo1F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1Deriv_ddi(a,b,z)\n integer :: z\n real(dp) :: a, b\n hypGeo1F1Deriv_ddi = hypGeo1F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1Deriv_iir(a,b,z)\n integer :: a, b\n real :: z\n hypGeo1F1Deriv_iir = hypGeo1F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1Deriv_rrr(a,b,z)\n real :: a, b, z\n hypGeo1F1Deriv_rrr = hypGeo1F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1Deriv_ddr(a,b,z)\n real :: z\n real(dp) :: a, b\n hypGeo1F1Deriv_ddr = hypGeo1F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1Deriv_iid(a,b,z)\n integer :: a, b\n real(dp) :: z\n hypGeo1F1Deriv_iid = hypGeo1F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1Deriv_rrd(a,b,z)\n real :: a, b\n real(dp) :: z\n hypGeo1F1Deriv_rrd = hypGeo1F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1Deriv_ddd(a,b,z)\n real(dp) :: a, b, z\n hypGeo1F1Deriv_ddd = hypGeo1F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo1F1Deriv_iiCr(a,b,z)\n integer :: a, b\n complex :: z\n hypGeo1F1Deriv_iiCr = hypGeo1F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo1F1Deriv_rrCr(a,b,z)\n real :: a, b\n complex :: z\n hypGeo1F1Deriv_rrCr = hypGeo1F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo1F1Deriv_ddCr(a,b,z)\n real(dp) :: a, b\n complex :: z\n hypGeo1F1Deriv_ddCr = hypGeo1F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo1F1Deriv_iiCd(a,b,z)\n integer :: a, b\n complex(dp) :: z\n hypGeo1F1Deriv_iiCd = hypGeo1F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo1F1Deriv_rrCd(a,b,z)\n real :: a, b\n complex(dp) :: z\n hypGeo1F1Deriv_rrCd = hypGeo1F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo1F1Deriv_ddCd(a,b,z)\n real(dp) :: a, b\n complex(dp) :: z\n hypGeo1F1Deriv_ddCd = hypGeo1F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo1F1Deriv_CrCrCr(a,b,z)\n complex :: a, b, z\n hypGeo1F1Deriv_CrCrCr = hypGeo1F1DerivFunc(cmplx(real(a),aimag(a),dp),cmplx(real(b),aimag(b),dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo1F1Deriv_CrCrCd(a,b,z)\n complex :: a, b\n complex(dp) :: z\n hypGeo1F1Deriv_CrCrCd = hypGeo1F1DerivFunc(cmplx(real(a),aimag(a),dp),cmplx(real(b),aimag(b),dp),z)\n end function\n\n complex(dp) function hypGeo1F1Deriv_CdCdCd(a,b,z)\n complex(dp) :: a, b, z\n hypGeo1F1Deriv_CdCdCd = hypGeo1F1DerivFunc(a,b,z)\n end function\n\n\n !*****************************!\n ! Hypergeometric Function 2F1 !\n !*****************************!\n\n function hypGeo2F1_odeFunc(nF,nC,c,x,y)\n integer :: nF, nC\n real(dp) :: hypGeo2F1_odeFunc(nF), x, y(nF)\n complex(dp) :: c(nC), zs, fT, fpT, f, fp, dz\n dz = c(2)-c(1)\n zs = c(1) + x*dz\n fT = cmplx(y(1),y(2),dp); fpT = cmplx(y(3),y(4),dp)\n f = dz*fpT\n fp = (c(3)*c(4)*fT-(c(5)-(c(3)+c(4)+1.d0)*zs)*fpT)*dz/(zs*(1.d0-zs))\n hypGeo2F1_odeFunc(1) = real(f); hypGeo2F1_odeFunc(2) = aimag(f)\n hypGeo2F1_odeFunc(3) = real(fp); hypGeo2F1_odeFunc(4) = aimag(fp)\n end function\n\n complex(dp) function hypGeo2F1_series(a,b,c,z)\n !! Returns Hypergeometric Function 2F1\n !! Should be only used for |z|<1.0\n integer :: i\n complex(dp) :: a, b, c, z, result, oldResult, indvResult\n result = cmplx(0.d0,0.d0,dp)\n oldResult = result\n do i=0, 100000\n indvResult = ((pochhammerR(a,i)*pochhammerR(b,i))/pochhammerR(c,i))*(z**i)/gamma(dble(i)+1.d0)\n if (indvResult /= indvResult) exit\n result = result + indvResult\n if (abs(result-oldResult).le.1.d-16) exit\n oldResult = result\n end do\n hypGeo2F1_series = result\n end function\n\n complex(dp) function hypGeo2F1Deriv_series(a,b,c,z)\n !! Returns Derivative of the Hypergeometric Function 2F1\n !! Should be only used for |z|<1.0\n complex(dp) :: a, b, c, z\n hypGeo2F1Deriv_series = (a*b/c)*hypGeo2F1_series(a+1.d0,b+1.d0,c+1.d0,z)\n end function\n\n complex(dp) function hypGeo2F1Func(a,b,c,z)\n complex(dp) :: a, b, c, z\n real(dp) :: y0(4), odeResult(4)\n complex(dp) :: z0, series(2), consts(5)\n if(abs(z).lt.1.d0) then\n hypGeo2F1Func = hypGeo2F1_series(a,b,c,z)\n return\n else if(real(z).gt.0.d0 .and. real(z).lt.1.d0) then\n z0 = cmplx(0.5d0,0.d0,dp)\n else if(real(z).gt.-1.d0 .and. real(z).lt.0.d0) then\n z0 = cmplx(-0.5d0,0.d0,dp)\n else if(real(z).gt.1.d0) then\n z0 = cmplx(0.d0,0.5d0,dp)\n else if(real(z).lt.-1.d0) then\n z0 = cmplx(0.d0,-0.5d0,dp)\n end if\n series(1) = hypGeo2F1_series(a,b,c,z0)\n series(2) = hypGeo2F1Deriv_series(a,b,c,z0)\n consts(1) = z0; consts(2) = z\n consts(3) = a; consts(4) = b; consts(5) = c\n y0(1) = real(series(1)); y0(2) = aimag(series(1))\n y0(3) = real(series(2)); y0(4) = aimag(series(2))\n odeResult = rk1AdaptStepCmplxC(hypGeo2F1_odeFunc,4,0.d0,1.d0,y0,5,consts)\n hypGeo2F1Func = cmplx(odeResult(1),odeResult(2),dp)\n end function\n\n complex(dp) function hypGeo2F1DerivFunc(a,b,c,z)\n complex(dp) :: a, b, c, z\n hypGeo2F1DerivFunc = (a*b/c)*hypGeo2F1Func(a+1.d0,b+1.d0,c+1.d0,z)\n end function\n\n complex(dp) function hypGeo2F1_iiii(a,b,c,z)\n integer :: a, b, c, z\n hypGeo2F1_iiii = hypGeo2F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1_rrri(a,b,c,z)\n real :: a, b, c\n integer :: z\n hypGeo2F1_rrri = hypGeo2F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1_dddi(a,b,c,z)\n real(dp) :: a, b, c\n integer :: z\n hypGeo2F1_dddi = hypGeo2F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1_iiir(a,b,c,z)\n integer :: a, b, c\n real :: z\n hypGeo2F1_iiir = hypGeo2F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1_rrrr(a,b,c,z)\n real :: a, b, c, z\n hypGeo2F1_rrrr = hypGeo2F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1_dddr(a,b,c,z)\n real(dp) :: a, b, c\n real :: z\n hypGeo2F1_dddr = hypGeo2F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1_iiid(a,b,c,z)\n integer :: a, b, c\n real(dp) :: z\n hypGeo2F1_iiid = hypGeo2F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1_rrrd(a,b,c,z)\n real :: a, b, c\n real(dp) :: z\n hypGeo2F1_rrrd = hypGeo2F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1_dddd(a,b,c,z)\n real(dp) :: a, b, c, z\n hypGeo2F1_dddd = hypGeo2F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1_iiiCr(a,b,c,z)\n integer :: a, b, c\n complex :: z\n hypGeo2F1_iiiCr = hypGeo2F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo2F1_rrrCr(a,b,c,z)\n real :: a, b, c\n complex :: z\n hypGeo2F1_rrrCr = hypGeo2F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo2F1_dddCr(a,b,c,z)\n real(dp) :: a, b, c\n complex :: z\n hypGeo2F1_dddCr = hypGeo2F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo2F1_iiiCd(a,b,c,z)\n integer :: a, b, c\n complex(dp) :: z\n hypGeo2F1_iiiCd = hypGeo2F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo2F1_rrrCd(a,b,c,z)\n real :: a, b, c\n complex(dp) :: z\n hypGeo2F1_rrrCd = hypGeo2F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo2F1_dddCd(a,b,c,z)\n real(dp) :: a, b, c\n complex(dp) :: z\n hypGeo2F1_dddCd = hypGeo2F1Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo2F1_CrCrCrCr(a,b,c,z)\n complex :: a, b, c, z\n hypGeo2F1_CrCrCrCr = hypGeo2F1Func(cmplx(real(a),aimag(a),dp),cmplx(real(b),aimag(b),dp),cmplx(real(c),aimag(c),dp),&\n cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo2F1_CrCrCrCd(a,b,c,z)\n complex :: a, b, c\n complex(dp) :: z\n hypGeo2F1_CrCrCrCd = hypGeo2F1Func(cmplx(real(a),aimag(a),dp),cmplx(real(b),aimag(b),dp),cmplx(real(c),aimag(c),dp),z)\n end function\n\n complex(dp) function hypGeo2F1_CdCdCdCd(a,b,c,z)\n complex(dp) :: a, b, c, z\n hypGeo2F1_CdCdCdCd = hypGeo2F1Func(a,b,c,z)\n end function\n\n complex(dp) function hypGeo2F1Deriv_iiii(a,b,c,z)\n integer :: a, b, c, z\n hypGeo2F1Deriv_iiii = hypGeo2F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1Deriv_rrri(a,b,c,z)\n real :: a, b, c\n integer :: z\n hypGeo2F1Deriv_rrri = hypGeo2F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1Deriv_dddi(a,b,c,z)\n real(dp) :: a, b, c\n integer :: z\n hypGeo2F1Deriv_dddi = hypGeo2F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1Deriv_iiir(a,b,c,z)\n integer :: a, b, c\n real :: z\n hypGeo2F1Deriv_iiir = hypGeo2F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1Deriv_rrrr(a,b,c,z)\n real :: a, b, c, z\n hypGeo2F1Deriv_rrrr = hypGeo2F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1Deriv_dddr(a,b,c,z)\n real(dp) :: a, b, c\n real :: z\n hypGeo2F1Deriv_dddr = hypGeo2F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1Deriv_iiid(a,b,c,z)\n integer :: a, b, c\n real(dp) :: z\n hypGeo2F1Deriv_iiid = hypGeo2F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1Deriv_rrrd(a,b,c,z)\n real :: a, b, c\n real(dp) :: z\n hypGeo2F1Deriv_rrrd = hypGeo2F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1Deriv_dddd(a,b,c,z)\n real(dp) :: a, b, c, z\n hypGeo2F1Deriv_dddd = hypGeo2F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo2F1Deriv_iiiCr(a,b,c,z)\n integer :: a, b, c\n complex :: z\n hypGeo2F1Deriv_iiiCr = hypGeo2F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo2F1Deriv_rrrCr(a,b,c,z)\n real :: a, b, c\n complex :: z\n hypGeo2F1Deriv_rrrCr = hypGeo2F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo2F1Deriv_dddCr(a,b,c,z)\n real(dp) :: a, b, c\n complex :: z\n hypGeo2F1Deriv_dddCr = hypGeo2F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo2F1Deriv_iiiCd(a,b,c,z)\n integer :: a, b, c\n complex(dp) :: z\n hypGeo2F1Deriv_iiiCd = hypGeo2F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo2F1Deriv_rrrCd(a,b,c,z)\n real :: a, b, c\n complex(dp) :: z\n hypGeo2F1Deriv_rrrCd = hypGeo2F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo2F1Deriv_dddCd(a,b,c,z)\n real(dp) :: a, b, c\n complex(dp) :: z\n hypGeo2F1Deriv_dddCd = hypGeo2F1DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo2F1Deriv_CrCrCrCr(a,b,c,z)\n complex :: a, b, c, z\n hypGeo2F1Deriv_CrCrCrCr = hypGeo2F1DerivFunc(cmplx(real(a),aimag(a),dp),cmplx(real(b),aimag(b),dp),cmplx(real(c),aimag(c),dp),&\n cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo2F1Deriv_CrCrCrCd(a,b,c,z)\n complex :: a, b, c\n complex(dp) :: z\n hypGeo2F1Deriv_CrCrCrCd = hypGeo2F1DerivFunc(cmplx(real(a),aimag(a),dp),cmplx(real(b),aimag(b),dp),cmplx(real(c),aimag(c),dp),z)\n end function\n\n complex(dp) function hypGeo2F1Deriv_CdCdCdCd(a,b,c,z)\n complex(dp) :: a, b, c, z\n hypGeo2F1Deriv_CdCdCdCd = hypGeo2F1DerivFunc(a,b,c,z)\n end function\n\n !*****************************!\n ! Hypergeometric Function 3F2 !\n !*****************************!\n\n function hypGeo3F2_odeFunc(nF,nC,c,x,y)\n integer :: nF, nC\n real(dp) :: hypGeo3F2_odeFunc(nF), x, y(nF)\n complex(dp) :: c(nC), zs, fT, fpT, fppT, f, fp, fpp, dz\n complex(dp) :: factfT, factfpT, factfpT2, factfppT\n dz = c(2)-c(1)\n zs = c(1) + x*dz\n factfT = -c(3)*c(4)*c(5)\n factfpT = c(4)*c(3)+c(5)*c(3)+c(3)+c(4)+c(4)*c(5)+c(5)+1.d0\n factfpT2 = c(6)*c(7) - factfpT*zs\n factfppT = (-(c(3)+c(4)+c(5)+3.d0)*zs+c(6)+c(7)+1.d0)*zs\n fT = cmplx(y(1),y(2),dp); fpT = cmplx(y(3),y(4),dp); fppT = cmplx(y(5),y(6),dp)\n f = dz*fpT\n fp = dz*fppT\n fpp = -dz*(factfppT*fppT+factfpT2*fpT+factfT*fT)/(zs*zs*(1.d0-zs))\n hypGeo3F2_odeFunc(1) = real(f); hypGeo3F2_odeFunc(2) = aimag(f)\n hypGeo3F2_odeFunc(3) = real(fp); hypGeo3F2_odeFunc(4) = aimag(fp)\n hypGeo3F2_odeFunc(5) = real(fpp); hypGeo3F2_odeFunc(6) = aimag(fpp)\n end function\n\n complex(dp) function hypGeo3F2_series(a,b,c,d,e,z)\n !! Returns Hypergeometric Function 3F2\n !! Should be only used for |z|<1.0\n integer :: i\n complex(dp) :: a, b, c, d, e, z, result, oldResult, indvResult\n result = cmplx(0.d0,0.d0,dp)\n oldResult = result\n do i=0, 100000\n indvResult = ((pochhammerR(a,i)*pochhammerR(b,i)*pochhammerR(c,i))/(pochhammerR(d,i)*pochhammerR(e,i)))* &\n (z**i)/gamma(dble(i)+1.d0)\n if (indvResult /= indvResult) exit\n result = result + indvResult\n if (abs(result-oldResult).le.1.d-16) exit\n oldResult = result\n end do\n hypGeo3F2_series = result\n end function\n\n complex(dp) function hypGeo3F2Deriv_series(a,b,c,d,e,z)\n !! Returns Hypergeometric Function 3F2\n !! Should be only used for |z|<1.0\n complex(dp) :: a, b, c, d, e, z\n hypGeo3F2Deriv_series = (a*b*c/(d*e))*hypGeo3F2_series(a+1.d0,b+1.d0,c+1.d0,d+1.d0,e+1.d0,z)\n end function\n\n complex(dp) function hypGeo3F2Func(a,b,c,d,e,z)\n complex(dp) :: a, b, c, d, e, z\n real(dp) :: y0(6), odeResult(6)\n complex(dp) :: z0, series(3), consts(7)\n if(abs(z).lt.1.d0) then\n hypGeo3F2Func = hypGeo3F2_series(a,b,c,d,e,z)\n return\n else if(real(z).gt.0.d0 .and. real(z).lt.1.d0) then\n z0 = cmplx(0.5d0,0.d0,dp)\n else if(real(z).gt.-1.d0 .and. real(z).lt.0.d0) then\n z0 = cmplx(-0.5d0,0.d0,dp)\n else if(real(z).gt.1.d0) then\n z0 = cmplx(0.d0,0.5d0,dp)\n else if(real(z).lt.-1.d0) then\n z0 = cmplx(0.d0,-0.5d0,dp)\n end if\n series(1) = hypGeo3F2_series(a,b,c,d,e,z0)\n series(2) = hypGeo3F2Deriv_series(a,b,c,d,e,z0)\n series(3) = (a*(a+1.d0)*b*(b+1.d0)*c*(c+1.d0))/(d*(d+1.d0)*e*(e+1.d0))*&\n hypGeo3F2_series(a+2.d0,b+2.d0,c+2.d0,d+2.d0,e+2.d0,z0)\n consts(1) = z0; consts(2) = z\n consts(3) = a; consts(4) = b; consts(5) = c; consts(6) = d; consts(7) = e\n y0(1) = real(series(1)); y0(2) = aimag(series(1))\n y0(3) = real(series(2)); y0(4) = aimag(series(2))\n y0(5) = real(series(3)); y0(6) = aimag(series(3))\n odeResult = rk1AdaptStepCmplxC(hypGeo3F2_odeFunc,6,0.d0,1.d0,y0,7,consts)\n hypGeo3F2Func = cmplx(odeResult(1),odeResult(2),dp)\n end function\n\n complex(dp) function hypGeo3F2DerivFunc(a,b,c,d,e,z)\n complex(dp) :: a, b, c, d, e, z\n hypGeo3F2DerivFunc = (a*b*c/(d*e))*hypGeo3F2Func(a+1.d0,b+1.d0,c+1.d0,d+1.d0,e+1.d0,z)\n end function\n\n complex(dp) function hypGeo3F2_iiiiii(a,b,c,d,e,z)\n integer :: a, b, c, d, e, z\n hypGeo3F2_iiiiii = hypGeo3F2Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2_iiiiir(a,b,c,d,e,z)\n integer :: a, b, c, d, e\n real :: z\n hypGeo3F2_iiiiir = hypGeo3F2Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2_iiiiid(a,b,c,d,e,z)\n integer :: a, b, c, d, e\n real(dp) :: z\n hypGeo3F2_iiiiid = hypGeo3F2Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2_rrrrri(a,b,c,d,e,z)\n real :: a, b, c, d, e\n integer :: z\n hypGeo3F2_rrrrri = hypGeo3F2Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2_rrrrrr(a,b,c,d,e,z)\n real :: a, b, c, d, e, z\n hypGeo3F2_rrrrrr = hypGeo3F2Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2_rrrrrd(a,b,c,d,e,z)\n real :: a, b, c, d, e\n real(dp) :: z\n hypGeo3F2_rrrrrd = hypGeo3F2Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2_dddddi(a,b,c,d,e,z)\n real(dp) :: a, b, c, d, e\n integer :: z\n hypGeo3F2_dddddi = hypGeo3F2Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2_dddddr(a,b,c,d,e,z)\n real(dp) :: a, b, c, d, e\n real :: z\n hypGeo3F2_dddddr = hypGeo3F2Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2_dddddd(a,b,c,d,e,z)\n real(dp) :: a, b, c, d, e, z\n hypGeo3F2_dddddd = hypGeo3F2Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2_iiiiiCr(a,b,c,d,e,z)\n integer :: a, b, c, d, e\n complex :: z\n hypGeo3F2_iiiiiCr = hypGeo3F2Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo3F2_iiiiiCd(a,b,c,d,e,z)\n integer :: a, b, c, d, e\n complex(dp) :: z\n hypGeo3F2_iiiiiCd = hypGeo3F2Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo3F2_rrrrrCr(a,b,c,d,e,z)\n real :: a, b, c, d, e\n complex :: z\n hypGeo3F2_rrrrrCr = hypGeo3F2Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo3F2_rrrrrCd(a,b,c,d,e,z)\n real :: a, b, c, d, e\n complex(dp) :: z\n hypGeo3F2_rrrrrCd = hypGeo3F2Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo3F2_dddddCr(a,b,c,d,e,z)\n real(dp) :: a, b, c, d, e\n complex :: z\n hypGeo3F2_dddddCr = hypGeo3F2Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo3F2_dddddCd(a,b,c,d,e,z)\n real(dp) :: a, b, c, d, e\n complex(dp) :: z\n hypGeo3F2_dddddCd = hypGeo3F2Func(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo3F2_CrCrCrCrCrCr(a,b,c,d,e,z)\n complex :: a, b, c, d, e, z\n hypGeo3F2_CrCrCrCrCrCr = hypGeo3F2Func(cmplx(real(a),aimag(a),dp),cmplx(real(b),aimag(b),dp),&\n cmplx(real(c),aimag(c),dp), cmplx(real(d),aimag(d),dp),cmplx(real(e),aimag(e),dp), &\n cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo3F2_CrCrCrCrCrCd(a,b,c,d,e,z)\n complex :: a, b, c, d, e\n complex(dp) :: z\n hypGeo3F2_CrCrCrCrCrCd = hypGeo3F2Func(cmplx(real(a),aimag(a),dp),cmplx(real(b),aimag(b),dp),&\n cmplx(real(c),aimag(c),dp), cmplx(real(d),aimag(d),dp),cmplx(real(e),aimag(e),dp),z)\n end function\n\n complex(dp) function hypGeo3F2_CdCdCdCdCdCd(a,b,c,d,e,z)\n complex(dp) :: a, b, c, d, e, z\n hypGeo3F2_CdCdCdCdCdCd = hypGeo3F2Func(a,b,c,d,e,z)\n end function\n\n complex(dp) function hypGeo3F2Deriv_iiiiii(a,b,c,d,e,z)\n integer :: a, b, c, d, e, z\n hypGeo3F2Deriv_iiiiii = hypGeo3F2DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2Deriv_iiiiir(a,b,c,d,e,z)\n integer :: a, b, c, d, e\n real :: z\n hypGeo3F2Deriv_iiiiir = hypGeo3F2DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2Deriv_iiiiid(a,b,c,d,e,z)\n integer :: a, b, c, d, e\n real(dp) :: z\n hypGeo3F2Deriv_iiiiid = hypGeo3F2DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2Deriv_rrrrri(a,b,c,d,e,z)\n real :: a, b, c, d, e\n integer :: z\n hypGeo3F2Deriv_rrrrri = hypGeo3F2DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2Deriv_rrrrrr(a,b,c,d,e,z)\n real :: a, b, c, d, e, z\n hypGeo3F2Deriv_rrrrrr = hypGeo3F2DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2Deriv_rrrrrd(a,b,c,d,e,z)\n real :: a, b, c, d, e\n real(dp) :: z\n hypGeo3F2Deriv_rrrrrd = hypGeo3F2DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2Deriv_dddddi(a,b,c,d,e,z)\n real(dp) :: a, b, c, d, e\n integer :: z\n hypGeo3F2Deriv_dddddi = hypGeo3F2DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2Deriv_dddddr(a,b,c,d,e,z)\n real(dp) :: a, b, c, d, e\n real :: z\n hypGeo3F2Deriv_dddddr = hypGeo3F2DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2Deriv_dddddd(a,b,c,d,e,z)\n real(dp) :: a, b, c, d, e, z\n hypGeo3F2Deriv_dddddd = hypGeo3F2DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(z,0.d0,dp))\n end function\n\n complex(dp) function hypGeo3F2Deriv_iiiiiCr(a,b,c,d,e,z)\n integer :: a, b, c, d, e\n complex :: z\n hypGeo3F2Deriv_iiiiiCr = hypGeo3F2DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo3F2Deriv_iiiiiCd(a,b,c,d,e,z)\n integer :: a, b, c, d, e\n complex(dp) :: z\n hypGeo3F2Deriv_iiiiiCd = hypGeo3F2DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo3F2Deriv_rrrrrCr(a,b,c,d,e,z)\n real :: a, b, c, d, e\n complex :: z\n hypGeo3F2Deriv_rrrrrCr = hypGeo3F2DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo3F2Deriv_rrrrrCd(a,b,c,d,e,z)\n real :: a, b, c, d, e\n complex(dp) :: z\n hypGeo3F2Deriv_rrrrrCd = hypGeo3F2DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo3F2Deriv_dddddCr(a,b,c,d,e,z)\n real(dp) :: a, b, c, d, e\n complex :: z\n hypGeo3F2Deriv_dddddCr = hypGeo3F2DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo3F2Deriv_dddddCd(a,b,c,d,e,z)\n real(dp) :: a, b, c, d, e\n complex(dp) :: z\n hypGeo3F2Deriv_dddddCd = hypGeo3F2DerivFunc(cmplx(a,0.d0,dp),cmplx(b,0.d0,dp),cmplx(c,0.d0,dp), &\n cmplx(d,0.d0,dp),cmplx(e,0.d0,dp),z)\n end function\n\n complex(dp) function hypGeo3F2Deriv_CrCrCrCrCrCr(a,b,c,d,e,z)\n complex :: a, b, c, d, e, z\n hypGeo3F2Deriv_CrCrCrCrCrCr = hypGeo3F2DerivFunc(cmplx(real(a),aimag(a),dp),cmplx(real(b),aimag(b),dp),&\n cmplx(real(c),aimag(c),dp), cmplx(real(d),aimag(d),dp),cmplx(real(e),aimag(e),dp), &\n cmplx(real(z),aimag(z),dp))\n end function\n\n complex(dp) function hypGeo3F2Deriv_CrCrCrCrCrCd(a,b,c,d,e,z)\n complex :: a, b, c, d, e\n complex(dp) :: z\n hypGeo3F2Deriv_CrCrCrCrCrCd = hypGeo3F2DerivFunc(cmplx(real(a),aimag(a),dp),cmplx(real(b),aimag(b),dp),&\n cmplx(real(c),aimag(c),dp), cmplx(real(d),aimag(d),dp),cmplx(real(e),aimag(e),dp),z)\n end function\n\n complex(dp) function hypGeo3F2Deriv_CdCdCdCdCdCd(a,b,c,d,e,z)\n complex(dp) :: a, b, c, d, e, z\n hypGeo3F2Deriv_CdCdCdCdCdCd = hypGeo3F2DerivFunc(a,b,c,d,e,z)\n end function\n\n !*************!\n ! Dilogarithm !\n !*************!\n\n complex(dp) function diLog_series(x)\n integer :: i\n complex(dp) :: x, result, oldResult, indvResult\n result = 0.d0\n oldResult = result\n do i=1, 1000000\n indvResult = (x**i)/(i**2)\n if (indvResult /= indvResult) exit\n result = result + indvResult\n if (abs(result-oldResult).le.1.d-16) exit\n oldResult = result\n end do\n diLog_series = result\n end function\n\n complex(dp) function diLogFunc(x)\n complex(dp) :: x\n if(abs(x).lt.1.d0) then\n diLogFunc = diLog_series(x)\n return\n else\n diLogFunc = x*hypGeo3F2(1.d0,1.d0,1.d0,2.d0,2.d0,x)\n return\n end if\n end function\n\n complex(dp) function diLog_i(x)\n integer :: x\n diLog_i = diLogFunc(cmplx(x,0.d0,dp))\n end function\n\n complex(dp) function diLog_r(x)\n real :: x\n diLog_r = diLogFunc(cmplx(x,0.d0,dp))\n end function\n\n complex(dp) function diLog_d(x)\n real(dp) :: x\n diLog_d = diLogFunc(cmplx(x,0.d0,dp))\n end function\n\n complex(dp) function diLog_Cr(x)\n complex :: x\n diLog_Cr = diLogFunc(cmplx(real(x),aimag(x),dp))\n end function\n\n complex(dp) function diLog_Cd(x)\n complex(dp) :: x\n diLog_Cd = diLogFunc(x)\n end function\n\n\nend module\n", "meta": {"hexsha": "529a092f0b7c73af3c5633b34da2d2e02b34795d", "size": 92337, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "srcOLD/specialFunctions.f90", "max_stars_repo_name": "joshhooker/numFortran", "max_stars_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "srcOLD/specialFunctions.f90", "max_issues_repo_name": "joshhooker/numFortran", "max_issues_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "srcOLD/specialFunctions.f90", "max_forks_repo_name": "joshhooker/numFortran", "max_forks_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.9698149951, "max_line_length": 132, "alphanum_fraction": 0.640469151, "num_tokens": 35868, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107843878721, "lm_q2_score": 0.8056321819811829, "lm_q1q2_score": 0.7550471692026973}} {"text": "module mod_diff\n ! Module for finite difference functions\n implicit none\n\n private\n public :: diff_upwind, diff_centered\n\ncontains\n\n function diff_upwind(x) result(diff)\n ! 1st order upwind finite difference of x\n ! with periodic boundary condition.\n real, intent(in) :: x(:)\n real :: diff(size(x))\n integer :: grid_size\n grid_size = size(x)\n diff(1) = (x(1) - x(grid_size)) ! boundary condition\n diff(2:grid_size) = (x(2:grid_size) - x(1:grid_size-1))\n end function diff_upwind\n\n function diff_centered(x) result(diff)\n ! 2nd order centered finite difference of x\n ! with periodic boundary condition.\n real, intent(in) :: x(:)\n real :: diff(size(x))\n integer :: grid_size\n grid_size = size(x)\n diff(1) = (x(2) - x(grid_size)) ! left boundary condition\n diff(grid_size) = (x(1) - x(grid_size-1)) ! right boundary condition\n diff(2:grid_size-1) = x(3:grid_size) - x(1:grid_size-2)\n diff = diff / 2\n end function diff_centered\n\nend module mod_diff\n", "meta": {"hexsha": "fef7000edd40fb01a20ddd361601a0bdf880be11", "size": 1008, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mod_diff.f90", "max_stars_repo_name": "modern-fortran/twitch-stream-tsunami", "max_stars_repo_head_hexsha": "1b55e24960e0a954fbdb88df44db0fdd2c687960", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-06-14T17:31:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-30T23:31:18.000Z", "max_issues_repo_path": "src/mod_diff.f90", "max_issues_repo_name": "modern-fortran/twitch-stream-tsunami", "max_issues_repo_head_hexsha": "1b55e24960e0a954fbdb88df44db0fdd2c687960", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mod_diff.f90", "max_forks_repo_name": "modern-fortran/twitch-stream-tsunami", "max_forks_repo_head_hexsha": "1b55e24960e0a954fbdb88df44db0fdd2c687960", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-10-10T08:47:16.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-30T23:31:20.000Z", "avg_line_length": 28.8, "max_line_length": 72, "alphanum_fraction": 0.6666666667, "num_tokens": 297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.7550227606202062}} {"text": "\nsubmodule(forlab_linalg) forlab_linalg_norm\n\n implicit none\n\ncontains\n\n real(sp) module function norm1_sp(x, p)\n real(sp), dimension(:), intent(in) :: x\n real(sp), intent(in), optional :: p\n real(sp)::temp\n if (.not. present(p)) then\n temp = 2.0_sp\n else\n temp = p\n end if\n\n if (temp == 2.0_sp) then\n norm1_sp = sqrt(sum(abs(x)**2))\n elseif (temp == 1.0_sp) then\n norm1_sp = sum(abs(x))\n else\n norm1_sp = (sum(abs(x)**p))**(1.0_sp/p)\n end if\n end function norm1_sp\n\n real(sp) module function norm2_sp(A, p)\n real(sp), dimension(:, :), intent(in) :: A\n real(sp), intent(in), optional :: p\n real(sp)::temp\n real(sp), dimension(:), allocatable :: w\n if (.not. present(p)) then\n temp = 2.0_sp\n else\n temp = p\n end if\n if (temp == 2.0_sp) then\n call svd(A, w)\n norm2_sp = maxval(w)\n elseif (temp == 1.0_sp) then\n norm2_sp = maxval(sum(abs(A), dim=2))\n end if\n end function norm2_sp\n real(dp) module function norm1_dp(x, p)\n real(dp), dimension(:), intent(in) :: x\n real(dp), intent(in), optional :: p\n real(dp)::temp\n if (.not. present(p)) then\n temp = 2.0_dp\n else\n temp = p\n end if\n\n if (temp == 2.0_dp) then\n norm1_dp = sqrt(sum(abs(x)**2))\n elseif (temp == 1.0_dp) then\n norm1_dp = sum(abs(x))\n else\n norm1_dp = (sum(abs(x)**p))**(1.0_dp/p)\n end if\n end function norm1_dp\n\n real(dp) module function norm2_dp(A, p)\n real(dp), dimension(:, :), intent(in) :: A\n real(dp), intent(in), optional :: p\n real(dp)::temp\n real(dp), dimension(:), allocatable :: w\n if (.not. present(p)) then\n temp = 2.0_dp\n else\n temp = p\n end if\n if (temp == 2.0_dp) then\n call svd(A, w)\n norm2_dp = maxval(w)\n elseif (temp == 1.0_dp) then\n norm2_dp = maxval(sum(abs(A), dim=2))\n end if\n end function norm2_dp\n\nend submodule forlab_linalg_norm\n\n", "meta": {"hexsha": "83afe687889cebd14b39da1a650f3ca650d32009", "size": 2246, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_linalg_norm.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "src/forlab_linalg_norm.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "src/forlab_linalg_norm.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 27.0602409639, "max_line_length": 51, "alphanum_fraction": 0.4915405165, "num_tokens": 648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.7550227552108834}} {"text": "\n PROGRAM TEST\n USE FMZM\n USE FM_INTERVAL_ARITHMETIC\n\n! This program contains the code for the FM interval arithmetic examples that are discussed in\n! the paper \"A Multiple-Precision Interval Arithmetic Package\".\n\n IMPLICIT NONE\n\n INTEGER :: I, J, J_MAX, J_MIN, K, N, NF, K_FUNCTION, N_ORDER, N_STEPS, KPRT, KW, K_GRAPH, &\n BASE, N_PRECISION, DIGIT_COUNT(9)\n TYPE (FM_INTERVAL) :: A, B, RESULT, S, TERM, PI, C, X, Y, V(5), DET\n TYPE (FM_INTERVAL), ALLOCATABLE :: MATRIX(:,:), RHS(:), SOLN(:)\n INTEGER, ALLOCATABLE :: KSWAP(:)\n TYPE (FM) :: A_FM, B_FM, S_FM, PI_FM, C_FM, X_FM, Y_FM\n TYPE (FM) :: ERROR_FM, WIDTH_FM, LEAST_WIDTH_FM\n DOUBLE PRECISION :: RAND\n\n! Set the FM precision to 50 digits.\n\n CALL FM_SET(50)\n\n! Write output to file IntervalExamplesFM.out.\n! The FM_SETVAR call directs all output from within the FM package to unit 22 also.\n\n OPEN(22,FILE='IntervalExamplesFM.out')\n CALL FM_SETVAR(' KW = 22 ')\n\n! Unit 31 will be used to write several files that give the interval width\n! for each step of the different examples.\n\n K_GRAPH = 31\n\n\n! Example 1. Ignoring variable correlation in formulas causes interval arithmetic\n! to get too wide a resulting interval.\n\n WRITE (22,*) ' '\n WRITE (22,*) ' '\n WRITE (22,*) \" Example 1. Compute f(x) = X**2 - X + 3 using different formulas.\"\n WRITE (22,*) ' '\n\n X = TO_FM_INTERVAL( \" -0.5 \", \" 1.0 \" )\n\n WRITE (22,*) ' '\n WRITE (22,*) ' X is the interval [ -0.5 , 1.0 ]'\n WRITE (22,*) ' '\n\n X_FM = 0.5\n A_FM = X_FM**2 - X_FM + 3\n X_FM = LEFT_ENDPOINT(X)\n B_FM = X_FM**2 - X_FM + 3\n LEAST_WIDTH_FM = B_FM - A_FM\n\n Y = X**2\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A)\") ' X**2 gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]'\n\n Y = X*X\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A)\") ' X*X gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]'\n WRITE (22,*) ' '\n WRITE (22,*) ' '\n\n Y = X**2 - X + 3\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A,F6.3)\") ' X**2 - X + 3 gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]. Magnification = ', TO_DP(C_FM)\n\n Y = X*X - X + 3\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A,F6.3)\") ' X*X - X + 3 gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]. Magnification = ', TO_DP(C_FM)\n\n Y = X*(X - 1) + 3\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A,F6.3)\") ' X*(X - 1) + 3 gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]. Magnification = ', TO_DP(C_FM)\n\n Y = (X - 0.5)**2 + 2.75\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A,F6.3)\") ' (X - 0.5)**2 + 2.75 gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]. Magnification = ', TO_DP(C_FM)\n\n WRITE (22,*) ' '\n WRITE (22,*) ' '\n WRITE (22,*) ' '\n\n! Results are not as bad when the interval doesn't include zero.\n\n X = TO_FM_INTERVAL( \" 0.1 \", \" 1.0 \" )\n\n WRITE (22,*) ' '\n WRITE (22,*) ' X is the interval [ 0.1 , 1.0 ]'\n WRITE (22,*) ' '\n\n X_FM = 0.5\n A_FM = X_FM**2 - X_FM + 3\n X_FM = RIGHT_ENDPOINT(X)\n B_FM = X_FM**2 - X_FM + 3\n LEAST_WIDTH_FM = B_FM - A_FM\n\n Y = X**2 - X + 3\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A,F6.3)\") ' X**2 - X + 3 gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]. Magnification = ', TO_DP(C_FM)\n\n Y = X*X - X + 3\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A,F6.3)\") ' X*X - X + 3 gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]. Magnification = ', TO_DP(C_FM)\n\n Y = X*(X - 1) + 3\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A,F6.3)\") ' X*(X - 1) + 3 gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]. Magnification = ', TO_DP(C_FM)\n\n Y = (X - 0.5)**2 + 2.75\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A,F6.3)\") ' (X - 0.5)**2 + 2.75 gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]. Magnification = ', TO_DP(C_FM)\n\n WRITE (22,*) ' '\n WRITE (22,*) ' '\n WRITE (22,*) ' '\n\n! Results are better when the interval doesn't include a local minimum.\n\n X = TO_FM_INTERVAL( \" 0.9 \", \" 1.0 \" )\n\n WRITE (22,*) ' '\n WRITE (22,*) ' X is the interval [ 0.9 , 1.0 ]'\n WRITE (22,*) ' '\n\n X_FM = LEFT_ENDPOINT(X)\n A_FM = X_FM**2 - X_FM + 3\n X_FM = RIGHT_ENDPOINT(X)\n B_FM = X_FM**2 - X_FM + 3\n LEAST_WIDTH_FM = B_FM - A_FM\n\n Y = X**2 - X + 3\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A,F6.3)\") ' X**2 - X + 3 gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]. Magnification = ', TO_DP(C_FM)\n\n Y = X*X - X + 3\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A,F6.3)\") ' X*X - X + 3 gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]. Magnification = ', TO_DP(C_FM)\n\n Y = X*(X - 1) + 3\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A,F6.3)\") ' X*(X - 1) + 3 gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]. Magnification = ', TO_DP(C_FM)\n\n Y = (X - 0.5)**2 + 2.75\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A,F6.3)\") ' (X - 0.5)**2 + 2.75 gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]. Magnification = ', TO_DP(C_FM)\n\n WRITE (22,*) ' '\n WRITE (22,*) ' '\n WRITE (22,*) ' '\n\n! Look at an even smaller interval\n\n X = TO_FM_INTERVAL( \" 0.99 \", \" 1.0 \" )\n\n WRITE (22,*) ' '\n WRITE (22,*) ' X is the interval [ 0.99 , 1.0 ]'\n WRITE (22,*) ' '\n\n X_FM = LEFT_ENDPOINT(X)\n A_FM = X_FM**2 - X_FM + 3\n X_FM = RIGHT_ENDPOINT(X)\n B_FM = X_FM**2 - X_FM + 3\n LEAST_WIDTH_FM = B_FM - A_FM\n\n Y = X**2 - X + 3\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A,F6.3)\") ' X**2 - X + 3 gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]. Magnification = ', TO_DP(C_FM)\n\n Y = X*X - X + 3\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A,F6.3)\") ' X*X - X + 3 gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]. Magnification = ', TO_DP(C_FM)\n\n Y = X*(X - 1) + 3\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A,F6.3)\") ' X*(X - 1) + 3 gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]. Magnification = ', TO_DP(C_FM)\n\n Y = (X - 0.5)**2 + 2.75\n\n C_FM = (RIGHT_ENDPOINT(Y) - LEFT_ENDPOINT(Y)) / LEAST_WIDTH_FM\n WRITE (22,*) ' '\n WRITE (22,\"(A,F6.3,A,F6.3,A,F6.3)\") ' (X - 0.5)**2 + 2.75 gives [ ', &\n TO_DP(LEFT_ENDPOINT(Y)), ' , ', TO_DP(RIGHT_ENDPOINT(Y)), &\n ' ]. Magnification = ', TO_DP(C_FM)\n WRITE (22,*) ' '\n\n\n\n\n\n! Example 2. Sum 1 / n^7 from 1 to 100,000.\n\n\n OPEN(K_GRAPH,FILE='INTERVAL_EXAMPLES Sum')\n\n WRITE (K_GRAPH,\"(//A//)\") 'Example 2. Sum 1 / n^7 from 1 to 100,000.'\n\n N = 10**5\n S = 0\n DO J = 1, N\n TERM = J\n S = S + 1 / TERM**7\n IF (MOD(J,N/1000) == 1) THEN\n WIDTH_FM = MAX( RIGHT_ENDPOINT(S)-LEFT_ENDPOINT(S) , EPSILON(LEFT_ENDPOINT(S)) )\n WRITE (K_GRAPH,\"(A,I7,A,F8.3,A)\") '{', J, ',', TO_DP(LOG(WIDTH_FM)) / LOG(10.0D0), '},'\n ENDIF\n ENDDO\n\n WRITE (22,*) ' '\n WRITE (22,*) \" Example 2. Sum 1 / n^7 from 1 to 100,000 =\"\n CALL FMPRINT_INTERVAL(S)\n WRITE (22,*) ' '\n ERROR_FM = ABS( (RIGHT_ENDPOINT(S)-LEFT_ENDPOINT(S)) / RIGHT_ENDPOINT(S) )\n J = -NINT(LOG10(ERROR_FM))\n WRITE (22,\"(A,I3,A)\") ' The two endpoints agree to about',J,' decimal digits.'\n WRITE (22,*) ' '\n CLOSE(K_GRAPH)\n\n\n\n\n\n! Example 3. Use composite 9-point Gauss quadrature with 1,000 subintervals\n! to integrate sin(t) / t from t = 0 to t = 20.\n\n\n OPEN(K_GRAPH,FILE='INTERVAL_EXAMPLES Integration')\n\n WRITE (K_GRAPH,\"(//A//)\") &\n 'Example 3. Use composite 9-point Gauss quadrature with 1,000 subintervals'\n\n NF = 1\n N = 1000\n A = 0\n B = 20\n CALL GAUSS_9(NF, A, B, N, RESULT)\n\n WRITE (22,*) ' '\n WRITE (22,*) \" Example 3. Integrate sin(t) / t from t = 0 to t = 20:\"\n CALL FMPRINT_INTERVAL(RESULT)\n WRITE (22,*) ' '\n ERROR_FM = ABS( (RIGHT_ENDPOINT(RESULT)-LEFT_ENDPOINT(RESULT)) / RIGHT_ENDPOINT(RESULT) )\n J = -NINT(LOG10(ERROR_FM))\n WRITE (22,\"(A,I3,A)\") ' The two endpoints agree to about',J,' decimal digits.'\n WRITE (22,*) ' '\n CLOSE(K_GRAPH)\n\n\n\n\n\n! Example 4. Start with ( x, y ) = ( 1, 0 ) and step around the unit circle\n! using the recurrence ( x, y ) <-- ( x*c - y*d, y*c + x*d ),\n! c = cos(2*pi/n) and s = sin(2*pi/n)\n\n! After 23 trips around the circle with 100 steps per trip,\n! x = ( -58.6 , 60.6 ) and y = ( -59.6 , 59.6 )\n\n! After 21 trips around the circle with 1000 steps per trip,\n! x = ( 0.49 , 1.51 ) and y = ( -0.51 , 0.51 )\n\n\n OPEN(K_GRAPH,FILE='INTERVAL_EXAMPLES Circle Recurrence')\n\n WRITE (K_GRAPH,\"(//A//)\") &\n 'Example 4. Start with ( x, y ) = ( 1, 0 ) and step around the unit circle'\n\n N = 100\n X = 1\n Y = 0\n PI = ACOS(TO_FM(-1))\n C = COS(2*PI/N)\n S = SIN(2*PI/N)\n\n WRITE (22,*) ' '\n WRITE (22,*) \" Example 4. Step around the unit circle multiple times using a recurrence\"\n WRITE (22,*) ' '\n\n DO K = 1, 23\n DO J = 1, N\n A = X*C - Y*S\n B = Y*C + X*S\n X = A\n Y = B\n WIDTH_FM = MAX( RIGHT_ENDPOINT(X)-LEFT_ENDPOINT(X) , EPSILON(LEFT_ENDPOINT(X))/10**7 )\n WRITE (K_GRAPH,\"(A,I7,A,F8.3,A)\") '{', N*(K-1)+J, &\n ',', TO_DP(LOG(WIDTH_FM)) / LOG(10.0D0), '},'\n ENDDO\n ERROR_FM = ABS( (RIGHT_ENDPOINT(X)-LEFT_ENDPOINT(X)) / RIGHT_ENDPOINT(X) )\n J = -NINT(LOG10(ERROR_FM))\n WRITE (22,\"(I4,A,I3,A)\") K,' trips. The two endpoints for x agree to about', &\n J,' decimal digits.'\n ENDDO\n\n WRITE (22,*) ' '\n WRITE (22,*) ' X ='\n CALL FMPRINT_INTERVAL(X)\n WRITE (22,*) ' '\n WRITE (22,*) ' Y ='\n CALL FMPRINT_INTERVAL(Y)\n WRITE (22,*) ' '\n ERROR_FM = ABS( (RIGHT_ENDPOINT(X)-LEFT_ENDPOINT(X)) / RIGHT_ENDPOINT(X) )\n J = -NINT(LOG10(ERROR_FM))\n WRITE (22,\"(A,I3,A)\") ' The two endpoints for x agree to about',J,' decimal digits.'\n WRITE (22,*) ' '\n\n\n! Compare the same calculation in ordinary FM arithmetic.\n\n! After 23 trips around the circle with 100 steps per trip,\n! x = 1.0 to 60 digits and y = -2.3e-55\n\n! After 23 trips around the circle with 1000 steps per trip,\n! x = 1.0 exactly and y = -2.3e-55\n\n WRITE (22,*) ' '\n WRITE (22,*) ' Compare the same calculation in ordinary FM arithmetic.'\n WRITE (22,*) ' '\n N = 100\n X_FM = 1\n Y_FM = 0\n PI_FM = ACOS(TO_FM(-1))\n C_FM = COS(2*PI_FM/N)\n S_FM = SIN(2*PI_FM/N)\n\n DO K = 1, 23\n DO J = 1, N\n A_FM = X_FM*C_FM - Y_FM*S_FM\n B_FM = Y_FM*C_FM + X_FM*S_FM\n X_FM = A_FM\n Y_FM = B_FM\n ENDDO\n ERROR_FM = ABS( X_FM - 1 ) + TO_FM(' 1.0e-99 ')\n J = -NINT(LOG10(ERROR_FM))\n WRITE (22,\"(I4,A,I3,A)\") K,' trips. x agrees with 1.0 to about', &\n J,' decimal digits.'\n ENDDO\n\n WRITE (22,*) ' '\n WRITE (22,*) ' X ='\n CALL FM_PRINT(X_FM)\n WRITE (22,*) ' '\n WRITE (22,*) ' Y ='\n CALL FM_PRINT(Y_FM)\n WRITE (22,*) ' '\n CLOSE(K_GRAPH)\n\n\n! Test to see if it is x and y oscillating between positive and negative values\n! that causes the exponential growth of interval width, or if oscillation through\n! positive values alone can cause it.\n\n! Use the recurrence it oscillate back and forth between step number 8 and\n! step number 18 of the original recurrence.\n! Once back and forth takes 20 steps, so 5*23 = 115 trips back and forth will\n! take the same number of steps as the 23 trips around the circle above.\n\n\n OPEN(K_GRAPH,FILE='INTERVAL_EXAMPLES Back and Forth Recurrence')\n\n WRITE (K_GRAPH,\"(//A/A//)\") &\n 'Example 4b. Start with ( x, y ) = ( cos( 8* 2*pi/n), sin( 8* 2*pi/n) ) ', &\n ' and step around the unit circle to ( cos(18* 2*pi/n), sin(18* 2*pi/n) ) and back'\n\n WRITE (22,*) ' '\n WRITE (22,*) \" Example 4b. Step back and forth around the unit circle using a recurrence\"\n WRITE (22,*) ' '\n\n N = 100\n PI = ACOS(TO_FM(-1))\n X = COS(8* 2*PI/N)\n Y = SIN(8* 2*PI/N)\n C = COS(2*PI/N)\n S = SIN(2*PI/N)\n\n WRITE (22,*) ' '\n WRITE (22,*) ' Starting point for X ='\n CALL FMPRINT_INTERVAL(X)\n WRITE (22,*) ' '\n WRITE (22,*) ' Starting point for Y ='\n CALL FMPRINT_INTERVAL(Y)\n WRITE (22,*) ' '\n\n! 5 back and forth trips equals 100 steps, the same as one circle trip above.\n\n DO K = 1, 23 * 5\n DO J = 1, 20\n A = X*C - Y*S\n B = Y*C + X*S\n X = A\n Y = B\n WIDTH_FM = MAX( RIGHT_ENDPOINT(X)-LEFT_ENDPOINT(X) , EPSILON(LEFT_ENDPOINT(X))/10**7 )\n WRITE (K_GRAPH,\"(A,I7,A,F8.3,A)\") '{', (20*(K-1)+J), &\n ',', TO_DP(LOG(WIDTH_FM)) / LOG(10.0D0), '},'\n\n IF (MOD(J,10) == 0) THEN\n S = -S\n ENDIF\n ENDDO\n IF (MOD(K,5) == 0) THEN\n ERROR_FM = ABS( (RIGHT_ENDPOINT(X)-LEFT_ENDPOINT(X)) / RIGHT_ENDPOINT(X) )\n J = -NINT(LOG10(ERROR_FM))\n WRITE (22,\"(I4,A,I3,A)\") K,' trips. The two endpoints for x agree to about', &\n J,' decimal digits.'\n ENDIF\n ENDDO\n\n WRITE (22,*) ' '\n WRITE (22,*) ' X ='\n CALL FMPRINT_INTERVAL(X)\n WRITE (22,*) ' '\n WRITE (22,*) ' Y ='\n CALL FMPRINT_INTERVAL(Y)\n WRITE (22,*) ' '\n ERROR_FM = ABS( (RIGHT_ENDPOINT(X)-LEFT_ENDPOINT(X)) / RIGHT_ENDPOINT(X) )\n J = -NINT(LOG10(ERROR_FM))\n WRITE (22,\"(A,I3,A)\") ' The two endpoints for x agree to about',J,' decimal digits.'\n WRITE (22,*) ' '\n CLOSE(K_GRAPH)\n\n\n\n\n\n! Example 5. 2 * Product 4*n^2 / (4*n^2-1) from 1 to 10,000.\n\n\n OPEN(K_GRAPH,FILE='INTERVAL_EXAMPLES Product')\n\n WRITE (K_GRAPH,\"(//A//)\") &\n 'Example 5. 2 * Product 4*n^2 / (4*n^2-1) from 1 to 10,000.'\n\n N = 10**4\n S = 2\n DO J = 1, N\n K = 4 * J * J\n TERM = K\n TERM = TERM / ( K - 1 )\n S = S * TERM\n IF (MOD(J,N/1000) == 1) THEN\n WIDTH_FM = MAX( RIGHT_ENDPOINT(S)-LEFT_ENDPOINT(S) , EPSILON(LEFT_ENDPOINT(S)) )\n WRITE (K_GRAPH,\"(A,I7,A,F8.3,A)\") '{', J, ',', TO_DP(LOG(WIDTH_FM)) / LOG(10.0D0), '},'\n ENDIF\n ENDDO\n\n WRITE (22,*) ' '\n WRITE (22,*) \" Example 5. 2 * Product 4*n^2 / (4*n^2-1) from 1 to 10,000. =\"\n CALL FMPRINT_INTERVAL(S)\n WRITE (22,*) ' '\n ERROR_FM = ABS( (RIGHT_ENDPOINT(S)-LEFT_ENDPOINT(S)) / RIGHT_ENDPOINT(S) )\n J = -NINT(LOG10(ERROR_FM))\n WRITE (22,\"(A,I3,A)\") ' The two endpoints of y(30) agree to about',J,' decimal digits.'\n WRITE (22,*) ' '\n\n\n\n\n\n! Example 6. Differential equation. y'' = -y' / 10 - 2 * y / (x+2),\n! y(0) = 0, y'(0) = 1\n\n! This solution has 2 roots between 0 and 30.\n\n\n OPEN(K_GRAPH,FILE='INTERVAL_EXAMPLES Diff Eq 1')\n\n WRITE (K_GRAPH,\"(//A//)\") &\n \"Example 6. Differential equation. y'' = -y' / 10 - 2 * y / (x+2),\"\n\n\n WRITE (22,*) ' '\n WRITE (22,*) \" Example 6. Differential equation. y'' = -y' / 10 - 2 * y / (x+2)\"\n WRITE (22,*) ' '\n N_ORDER = 2\n A = 0\n B = 30\n N_STEPS = 10000\n V(1) = 0\n V(2) = 1\n K_FUNCTION = 1\n KPRT = N_STEPS / 10\n KW = 22\n CALL RK4(N_ORDER, A, B, N_STEPS, V, K_FUNCTION, KPRT, KW)\n WRITE (22,*) ' '\n WRITE (22,*) ' y(30) = '\n WRITE (22,*) ' '\n CALL FMPRINT_INTERVAL(V(1))\n WRITE (22,*) ' '\n WRITE (22,*) \" y'(30) = \"\n WRITE (22,*) ' '\n CALL FMPRINT_INTERVAL(V(2))\n WRITE (22,*) ' '\n ERROR_FM = ABS( (RIGHT_ENDPOINT(V(1))-LEFT_ENDPOINT(V(1))) / RIGHT_ENDPOINT(V(1)) )\n J = -NINT(LOG10(ERROR_FM))\n WRITE (22,\"(A,I3,A)\") ' The two endpoints of y(30) agree to about',J,' decimal digits.'\n WRITE (22,*) ' '\n\n\n\n\n\n! Example 7. Differential equation. y'' = -y' / 10 - 200 * y / (x+2),\n! y(0) = 0, y'(0) = 1\n\n! This solution has 38 roots between 0 and 30.\n! The rapid oscillation causes the interval calculation to be unstable\n! and lose accuracy in a manner similar to example 4, the stepping\n! recurrence making multiple trips around the unit circle.\n\n\n OPEN(K_GRAPH,FILE='INTERVAL_EXAMPLES Diff Eq 2')\n\n WRITE (K_GRAPH,\"(//A//)\") &\n \"Example 7. Differential equation. y'' = -y' / 10 - 200 * y / (x+2),\"\n\n\n WRITE (22,*) ' '\n WRITE (22,*) \" Example 7. Differential equation. y'' = -y' / 10 - 200 * y / (x+2)\"\n WRITE (22,*) ' '\n N_ORDER = 2\n A = 0\n B = 30\n N_STEPS = 10000\n V(1) = 0\n V(2) = 1\n K_FUNCTION = 2\n KPRT = N_STEPS / 10\n KW = 22\n CALL RK4(N_ORDER, A, B, N_STEPS, V, K_FUNCTION, KPRT, KW)\n WRITE (22,*) ' '\n WRITE (22,*) ' y(30) = '\n WRITE (22,*) ' '\n CALL FMPRINT_INTERVAL(V(1))\n WRITE (22,*) ' '\n WRITE (22,*) \" y'(30) = \"\n WRITE (22,*) ' '\n CALL FMPRINT_INTERVAL(V(2))\n WRITE (22,*) ' '\n ERROR_FM = ABS( (RIGHT_ENDPOINT(V(1))-LEFT_ENDPOINT(V(1))) / RIGHT_ENDPOINT(V(1)) )\n J = -NINT(LOG10(ERROR_FM))\n WRITE (22,\"(A,I3,A)\") ' The two endpoints of y(30) agree to about',J,' decimal digits.'\n WRITE (22,*) ' '\n CLOSE(K_GRAPH)\n\n\n\n\n\n! Example 8. Solve a \"random\" NxN linear system.\n\n\n WRITE (22,*) ' '\n WRITE (22,*) ' Example 8. Solve a \"random\" NxN linear system.'\n WRITE (22,*) ' '\n\n DO N = 10, 100, 10\n\n ALLOCATE( MATRIX(N,N), RHS(N), SOLN(N), KSWAP(N) )\n DO I = 1, N\n DO J = 1, N\n CALL FM_RANDOM_NUMBER(RAND)\n MATRIX(I,J) = RAND\n ENDDO\n RHS(I) = I\n ENDDO\n\n CALL FM_INTERVAL_FACTOR_LU(MATRIX, N, DET, KSWAP)\n CALL FM_INTERVAL_SOLVE_LU (MATRIX, N, RHS, SOLN, KSWAP)\n\n WRITE (22,*) ' '\n J_MIN = 99\n J_MAX = 0\n DO I = 1, N\n ERROR_FM = ABS( (RIGHT_ENDPOINT(SOLN(I))-LEFT_ENDPOINT(SOLN(I))) / &\n RIGHT_ENDPOINT(SOLN(I)) )\n J = -NINT(LOG10(ERROR_FM))\n J_MIN = MIN( J_MIN, J )\n J_MAX = MAX( J_MAX, J )\n ENDDO\n WRITE (22,\"(A,I3,A,I3,A,I3,A)\") ' For N = ', N, &\n ' the solution elements agree to between ', &\n J_MIN, ' and ', J_MAX, ' significant digits.'\n\n DEALLOCATE( MATRIX, RHS, SOLN, KSWAP )\n ENDDO\n\n\n\n\n\n! Example 9. Newton's method starting with a single point. Solve x*exp(x) - 2 = 0.\n\n\n WRITE (22,*) ' '\n WRITE (22,*) ' '\n WRITE (22,*) \" Example 9. Newton's method starting with a single point.\"\n WRITE (22,*) ' '\n\n X = 1\n DO J = 1, 10\n A = X*EXP(X) - 2\n B = (X+1)*EXP(X)\n X = X - A/B\n WRITE (22,*) ' '\n WRITE (22,\"(A,I2,A)\") \" Iteration \",J,'. X ='\n CALL FMPRINT_INTERVAL(X)\n ENDDO\n\n\n\n\n\n! Example 10. Newton's method starting with an interval containing a root.\n! Solve x*exp(x) - 2 = 0.\n! The next interval is xt - f(xt)/f'(x) intersected with x.\n! xt is a single point from the interval x (the midpoint is used here).\n! The idea is to have a contracting sequence of intervals that\n! each contain a root.\n! Refs: Hansen-Greenberg 83, Baker Kearfott 95-97,\n! Mayer 95, van Hentenryck et al. 97\n\n\n WRITE (22,*) ' '\n WRITE (22,*) ' '\n WRITE (22,*) \" Example 10. Newton's method starting with an interval containing a root\"\n WRITE (22,*) ' '\n\n X = TO_FM_INTERVAL( \" 0.5 \", \" 1.0 \" )\n DO J = 1, 9\n X_FM = LEFT_ENDPOINT(X)/2 + RIGHT_ENDPOINT(X)/2\n Y_FM = X_FM*EXP(X_FM) - 2\n B = (X+1)*EXP(X)\n Y = X_FM - Y_FM/B\n\n X = TO_FM_INTERVAL( MAX( LEFT_ENDPOINT(X),LEFT_ENDPOINT(Y) ) , &\n MIN( RIGHT_ENDPOINT(X),RIGHT_ENDPOINT(Y) ) )\n WRITE (22,*) ' '\n WRITE (22,\"(A,I2,A)\") \" Iteration \",J,'. X ='\n CALL FMPRINT_INTERVAL(X)\n ENDDO\n\n\n\n\n\n! Example 11. Check \"Benford's Law\", a result about the distribution of the\n! leading digits is sets of numerical data.\n! Count the exact number of leading digits 1, 2, ..., 9 found\n! in the first billion powers of base = 2, 3, 5.\n! Ref: \"The Surprising Accuracy of Benford's Law in Mathematics\",\n! Zhaodong Cai, Matthew Faust, A. J. Hildebrand, Junxian Li,\n! and Yuan Zhang -- American Mathematical Monthly, March 2020.\n\n\n BASE = 2\n\n WRITE (22,\"(//A,I2/)\") ' Example 11. Count leading digits of powers of', BASE\n\n N = 10**9\n N_PRECISION = 20\n CALL FM_SET(N_PRECISION)\n\n DIGIT_COUNT = 0\n X = 1\n DO J = 1, N\n X = X * BASE\n\n! Check that the two endpoints of the interval have the same leading digit.\n! If so, that proves we have computed the correct leading digit.\n! If not, write a message about needing higher precision and stop.\n\n A_FM = LEFT_ENDPOINT(X)\n B_FM = RIGHT_ENDPOINT(X)\n\n! In this comparison A_FM%MFM%MP(2) is the FM exponent and A_FM%MFM%MP(3) is the FM\n! first digit of A_FM. So this is a quick way to check that the two endpoints\n! of interval X agree about the leading digit of BASE**J.\n\n IF (A_FM%MFM%MP(2) /= B_FM%MFM%MP(2) .OR. A_FM%MFM%MP(3) /= B_FM%MFM%MP(3)) THEN\n WRITE (22,\"(//A,I6)\") ' In example 11 the two endpoints do not agree about the' // &\n ' leading digit. N_PRECISION was ', N_PRECISION\n WRITE (22,\"(//A//)\") ' Try again with N_PRECISION set 10 higher'\n STOP\n ENDIF\n\n! Extract the leading decimal digit from BASE**J.\n! FM is storing the numbers in a power-of-ten base, so the leading FM digit\n! may have several base 10 digits. Divide by 10 until the base 10 leading\n! digit remains.\n\n K = A_FM%MFM%MP(3)\n DO WHILE (K > 0)\n I = K/10\n IF (I == 0) THEN\n DIGIT_COUNT(K) = DIGIT_COUNT(K) + 1\n EXIT\n ELSE\n K = I\n ENDIF\n ENDDO\n\n! 5^(1,000,000,000) could overflow if FM is being run on a machine using 32-bit\n! integers. Since we only care about the leading digits of the powers, normalize\n! the FM exponent of X if it gets too big.\n\n IF (A_FM%MFM%MP(2) > 5.0D+7) THEN\n X%LEFT%MP(2) = 0\n X%RIGHT%MP(2) = 0\n ENDIF\n ENDDO\n\n WRITE (22,\"(//I2,A,9I10//)\") BASE, '^n counts = ', DIGIT_COUNT\n\n\n WRITE (22,*) ' '\n WRITE (22,*) ' '\n\n CLOSE(22)\n STOP\n\n END PROGRAM TEST\n\n\n FUNCTION F(NF, X) RESULT (RETURN_VALUE)\n\n USE FMZM\n USE FM_INTERVAL_ARITHMETIC\n IMPLICIT NONE\n INTEGER :: NF\n TYPE (FM_INTERVAL) :: RETURN_VALUE, X\n\n IF (NF == 1) THEN\n RETURN_VALUE = SIN(X) / X\n ENDIF\n\n END FUNCTION F\n\n\n SUBROUTINE GAUSS_9(NF, A, B, N, RESULT)\n\n! Sample subroutine usage for FM.\n\n! Integrate F(NF, X) from A to B using N subintervals, and return the answer in RESULT.\n\n! This does numerical integration using a 9-point Gauss quadrature rule.\n! It is not a very good way to do high-precision integration, but it is a short routine\n! and can often get 50 digits if f(x) is well-behaved and the interval of integration\n! is not too big.\n\n USE FMVALS\n USE FMZM\n USE FM_INTERVAL_ARITHMETIC\n IMPLICIT NONE\n TYPE (FM_INTERVAL) :: A, B, RESULT\n TYPE (FM_INTERVAL), SAVE :: AJ, H2, XJ, XI(9), WI(9)\n TYPE (FM_INTERVAL), EXTERNAL :: F\n TYPE (FM), SAVE :: WIDTH_FM\n INTEGER :: NF, N, J, K\n INTEGER, SAVE :: COEFF_BASE = 0, COEFF_PRECISION = 0\n INTENT (IN) :: N, A, B\n INTENT (INOUT) :: RESULT\n\n IF (COEFF_BASE /= MBASE .OR. COEFF_PRECISION < NDIG) THEN\n COEFF_BASE = MBASE\n COEFF_PRECISION = NDIG\n XI(9) = TO_FM(' 0.968160239507626089835576202903672870049404800491925329550023 ')\n XI(1) = -XI(9)\n XI(8) = TO_FM(' 0.836031107326635794299429788069734876544106718124675996104372 ')\n XI(2) = -XI(8)\n XI(7) = TO_FM(' 0.613371432700590397308702039341474184785720604940564692872813 ')\n XI(3) = -XI(7)\n XI(6) = TO_FM(' 0.324253423403808929038538014643336608571956260736973088827047 ')\n XI(4) = -XI(6)\n XI(5) = 0\n\n WI(9) = TO_FM(' 0.081274388361574411971892158110523650675661720782410750711108 ')\n WI(1) = WI(9)\n WI(8) = TO_FM(' 0.180648160694857404058472031242912809514337821732040484498336 ')\n WI(2) = WI(8)\n WI(7) = TO_FM(' 0.260610696402935462318742869418632849771840204437299951939997 ')\n WI(3) = WI(7)\n WI(6) = TO_FM(' 0.312347077040002840068630406584443665598754861261904645554011 ')\n WI(4) = WI(6)\n WI(5) = TO_FM(' 32768 ') / 99225\n ENDIF\n\n RESULT = 0\n H2 = ( B - A ) / ( 2 * N )\n DO J = 1, N\n AJ = A + (J-1) * 2 * H2\n DO K = 1, 9\n XJ = AJ + H2 + H2 * XI(K)\n RESULT = RESULT + F( NF, XJ ) * WI(K)\n ENDDO\n IF (MOD(J,N/1000) == 0) THEN\n WIDTH_FM = MAX( RIGHT_ENDPOINT(RESULT)-LEFT_ENDPOINT(RESULT) , &\n EPSILON(LEFT_ENDPOINT(RESULT)) )\n WRITE (31,\"(A,I7,A,F8.3,A)\") '{', J, ',', TO_DP(LOG(WIDTH_FM)) / LOG(10.0D0), '},'\n ENDIF\n ENDDO\n\n RESULT = RESULT * H2\n\n END SUBROUTINE GAUSS_9\n\n\n\n MODULE RK_FUNCT\n\n! For a function to return an array as its function value, there must be an explicit interface.\n\n! F is the generic name of the function, F_RK is the specific version for 1-dimensional arrays.\n\n INTERFACE F\n MODULE PROCEDURE F_RK\n END INTERFACE\n\n CONTAINS\n\n FUNCTION F_RK( X, V, K_FUNCTION ) RESULT (RETURN_VALUE)\n USE FMZM\n USE FM_INTERVAL_ARITHMETIC\n\n IMPLICIT NONE\n\n INTEGER :: K_FUNCTION\n TYPE (FM_INTERVAL) :: X, V(5), RETURN_VALUE(5)\n\n RETURN_VALUE = 0\n\n IF (K_FUNCTION == 1) THEN\n\n! Function 1. y'' = -y' / 10 - 2 * y / (x+2),\n! y(0) = 0, y'(0) = 1\n\n! v' = { y' , y'' } = { u , -u / 10 - 2 y / (x+2) } = F(x,v)\n\n RETURN_VALUE(1) = V(2)\n RETURN_VALUE(2) = -V(2) / 10 - 2 * V(1) / ( X + 2 )\n\n ELSE IF (K_FUNCTION == 2) THEN\n\n! Function 2. y'' = -y' / 10 - 200 * y / (x+2),\n! y(0) = 0, y'(0) = 1\n\n! v' = { y' , y'' } = { u , -u / 10 - 2 y / (x+2) } = F(x,v)\n\n RETURN_VALUE(1) = V(2)\n RETURN_VALUE(2) = -V(2) / 10 - 200 * V(1) / ( X + 2 )\n\n ELSE\n RETURN_VALUE(1) = X*V(1)\n ENDIF\n\n END FUNCTION F_RK\n\n END MODULE RK_FUNCT\n\n\n SUBROUTINE RK4(N_ORDER, A, B, N_STEPS, V, K_FUNCTION, KPRT, KW)\n USE FMZM\n USE FM_INTERVAL_ARITHMETIC\n USE RK_FUNCT\n\n! N_ORDER is the order of the DE\n! A is the initial x-value\n! B is the final x-value\n! N_STEPS is the number of steps done.\n! V contains the initial values at x = a on input, and is returned with the solution\n! values at x = b.\n! K_FUNCTION is the function number for the RHS.\n! KPRT > 0 causes the solution to be printed on unit KW after each KPRT steps.\n\n IMPLICIT NONE\n\n INTEGER :: J, K, K_FUNCTION, KPRT, KW, N_ORDER, N_STEPS\n TYPE (FM_INTERVAL) :: A, B, H, X, V(5), K1(5), K2(5), K3(5), K4(5)\n TYPE (FM) :: ERROR_FM, WIDTH_FM\n\n SAVE :: H, X, K1, K2, K3, K4\n\n X = A\n H = (B-A)/N_STEPS\n IF (N_ORDER < 5) V(N_ORDER+1:5) = 0\n\n DO J = 1, N_STEPS\n K1 = H * F( X , V , K_FUNCTION )\n K2 = H * F( X+H/2 , V+K1/2 , K_FUNCTION )\n K3 = H * F( X+H/2 , V+K2/2 , K_FUNCTION )\n K4 = H * F( X+H , V+K3 , K_FUNCTION )\n X = A + J*H\n V = V + ( K1 + 2*K2 + 2*K3 + K4 ) / 6\n\n IF (KPRT > 0) THEN\n IF (MOD(J,KPRT) == 0) THEN\n ERROR_FM = ABS( (RIGHT_ENDPOINT(V(1))-LEFT_ENDPOINT(V(1))) / RIGHT_ENDPOINT(V(1)) )\n K = -NINT(LOG10(ERROR_FM))\n WRITE (KW,\"(A,F15.10,A,2F20.15,A,I3,A)\") ' X = ',TO_DP(X),' V = ', &\n TO_DP(V(1:N_ORDER)),' Endpoints of V(1) agree to ', K, ' digits.'\n ENDIF\n ENDIF\n\n IF (MOD(J,N_STEPS/1000) == 1) THEN\n WIDTH_FM = MAX( RIGHT_ENDPOINT(V(1))-LEFT_ENDPOINT(V(1)) , &\n EPSILON(LEFT_ENDPOINT(V(1))) )\n IF (K_FUNCTION == 1) THEN\n WRITE (31,\"(A,I7,A,F8.3,A)\") '{', J, ',', TO_DP(LOG(WIDTH_FM)) / LOG(10.0D0), '},'\n ELSE\n WRITE (31,\"(A,I7,A,F8.3,A)\") '{', J, ',', TO_DP(LOG(WIDTH_FM)) / LOG(10.0D0), '},'\n ENDIF\n ENDIF\n ENDDO\n\n END SUBROUTINE RK4\n\n\n SUBROUTINE FM_INTERVAL_FACTOR_LU(A,N,DET,KSWAP)\n USE FMZM\n USE FM_INTERVAL_ARITHMETIC\n IMPLICIT NONE\n\n! Gauss elimination to factor the NxN matrix A (LU decomposition).\n\n! The time is proportional to N**3.\n\n! Once this factorization has been done, a linear system A x = b\n! with the same coefficient matrix A and Nx1 vector b can be solved\n! for x using routine FM_INTERVAL_SOLVE_LU in time proportional to N**2.\n\n! DET is returned as the determinant of A.\n! Nonzero DET means a solution can be found.\n! DET = 0 is returned if the system is singular.\n\n! KSWAP is a list of row interchanges made by the partial pivoting strategy during the\n! elimination phase.\n\n! After returning, the values in matrix A have been replaced by the multipliers\n! used during elimination. This is equivalent to factoring the A matrix into\n! a lower triangular matrix L times an upper triangular matrix U.\n\n INTEGER :: N\n INTEGER :: JCOL, JDIAG, JMAX, JROW, KSWAP(N)\n TYPE (FM_INTERVAL) :: A(N,N), DET\n TYPE (FM_INTERVAL), SAVE :: AMAX, AMULT, TEMP\n\n DET = 1\n KSWAP(1:N) = 1\n IF (N <= 0) THEN\n DET = 0\n RETURN\n ENDIF\n IF (N == 1) THEN\n KSWAP(1) = 1\n DET = A(1,1)\n RETURN\n ENDIF\n\n! Do the elimination phase.\n! JDIAG is the current diagonal element below which the elimination proceeds.\n\n DO JDIAG = 1, N-1\n\n! Pivot to put the element with the largest absolute value on the diagonal.\n\n AMAX = ABS(A(JDIAG,JDIAG))\n JMAX = JDIAG\n DO JROW = JDIAG+1, N\n IF (ABS(A(JROW,JDIAG)) > AMAX) THEN\n AMAX = ABS(A(JROW,JDIAG))\n JMAX = JROW\n ENDIF\n ENDDO\n\n! If AMAX is zero here then the system is singular.\n\n IF (AMAX == 0.0) THEN\n DET = 0\n RETURN\n ENDIF\n\n! Swap rows JDIAG and JMAX unless they are the same row.\n\n KSWAP(JDIAG) = JMAX\n IF (JMAX /= JDIAG) THEN\n DET = -DET\n DO JCOL = JDIAG, N\n TEMP = A(JDIAG,JCOL)\n A(JDIAG,JCOL) = A(JMAX,JCOL)\n A(JMAX,JCOL) = TEMP\n ENDDO\n ENDIF\n DET = DET * A(JDIAG,JDIAG)\n\n! For JROW = JDIAG+1, ..., N, eliminate A(JROW,JDIAG) by replacing row JROW by\n! row JROW - A(JROW,JDIAG) * row JDIAG / A(JDIAG,JDIAG)\n\n DO JROW = JDIAG+1, N\n IF (A(JROW,JDIAG) == 0) CYCLE\n AMULT = A(JROW,JDIAG)/A(JDIAG,JDIAG)\n\n! Save the multiplier for use later by FM_INTERVAL_SOLVE_LU.\n\n A(JROW,JDIAG) = AMULT\n A(JROW,JDIAG+1:N) = A(JROW,JDIAG+1:N) - AMULT*A(JDIAG,JDIAG+1:N)\n ENDDO\n ENDDO\n DET = DET * A(N,N)\n\n END SUBROUTINE FM_INTERVAL_FACTOR_LU\n\n SUBROUTINE FM_INTERVAL_SOLVE_LU(A,N,B,X,KSWAP)\n USE FMZM\n USE FM_INTERVAL_ARITHMETIC\n IMPLICIT NONE\n\n! Solve a linear system A x = b.\n! A is the NxN coefficient matrix, after having been factored by FM_INTERVAL_FACTOR_LU.\n! B is the Nx1 right-hand-side vector.\n! X is returned with the solution of the linear system.\n! KSWAP is a list of row interchanges made by the partial pivoting strategy during the\n! elimination phase in FM_INTERVAL_FACTOR_LU.\n! Time for this call is proportional to N**2.\n\n INTEGER :: N, KSWAP(N)\n TYPE (FM_INTERVAL) :: A(N,N), B(N), X(N)\n TYPE (FM_INTERVAL), SAVE :: TEMP\n INTEGER :: JDIAG, JMAX\n\n IF (N <= 0) THEN\n RETURN\n ENDIF\n IF (N == 1) THEN\n X(1) = B(1) / A(1,1)\n RETURN\n ENDIF\n X(1:N) = B(1:N)\n\n! Do the elimination phase operations only on X.\n! JDIAG is the current diagonal element below which the elimination proceeds.\n\n DO JDIAG = 1, N-1\n\n! Pivot to put the element with the largest absolute value on the diagonal.\n\n JMAX = KSWAP(JDIAG)\n\n! Swap rows JDIAG and JMAX unless they are the same row.\n\n IF (JMAX /= JDIAG) THEN\n TEMP = X(JDIAG)\n X(JDIAG) = X(JMAX)\n X(JMAX) = TEMP\n ENDIF\n\n! For JROW = JDIAG+1, ..., N, eliminate A(JROW,JDIAG) by replacing row JROW by\n! row JROW - A(JROW,JDIAG) * row JDIAG / A(JDIAG,JDIAG)\n! After factoring, A(JROW,JDIAG) is the original A(JROW,JDIAG) / A(JDIAG,JDIAG).\n\n X(JDIAG+1:N) = X(JDIAG+1:N) - A(JDIAG+1:N,JDIAG)*X(JDIAG)\n ENDDO\n\n! Do the back substitution.\n\n DO JDIAG = N, 1, -1\n\n! Divide row JDIAG by the diagonal element.\n\n X(JDIAG) = X(JDIAG) / A(JDIAG,JDIAG)\n\n! Zero above the diagonal in column JDIAG by replacing row JROW by\n! row JROW - A(JROW,JDIAG) * row JDIAG\n! For JROW = 1, ..., JDIAG-1.\n\n IF (JDIAG == 1) EXIT\n X(1:JDIAG-1) = X(1:JDIAG-1) - A(1:JDIAG-1,JDIAG)*X(JDIAG)\n ENDDO\n\n END SUBROUTINE FM_INTERVAL_SOLVE_LU\n", "meta": {"hexsha": "77e9876554b8fd61ca8f91f0a65a8dcd37d24284", "size": 38015, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Libraries/FM/FMinterval/IntervalExamplesFM.f95", "max_stars_repo_name": "andreypudov/projecteuler", "max_stars_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2022-01-30T20:37:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T21:03:21.000Z", "max_issues_repo_path": "Libraries/FM/FMinterval/IntervalExamplesFM.f95", "max_issues_repo_name": "andreypudov/projecteuler", "max_issues_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Libraries/FM/FMinterval/IntervalExamplesFM.f95", "max_forks_repo_name": "andreypudov/projecteuler", "max_forks_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.0852915579, "max_line_length": 100, "alphanum_fraction": 0.4985926608, "num_tokens": 12108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7549835908120971}} {"text": "program tarefac\n implicit real*8 (a-h,o-z)\n ! variaveis auxiliaris para indicar parada de cada metodo\n logical flag_dir, flag_new, flag_sec\n \n erro = 10d-6 ! erro\n nmax = 100 ! iteração maxima\n h_sec = 0.005 ! valor de h para o metodo da secante\n h_dir = 3 ! valor de h para definir intervalo a b do metodo direto\n n = 0 ! valor da iteração\n\n ! variaveis de desvio\n desv_dir = 2*erro\n desv_new = 2*erro\n desv_sec = 2*erro\n\n ! flags\n flag_dir = .true.\n flag_new = .true.\n flag_sec = .true.\n\n ! recebe o valor para iniciar\n write(*,*) 'Digite um valor para iniciar a busca:'\n read(*,*) a\n\n ! define o valor de b do intervalo\n b = a + h_dir\n\n ! loop para encontrar o melhor intervalo\n do while ( f(a)*f(b) .gt. 0 )\n a = b\n\tb = b + h_dir\n end do\n\n ! escreve o valor de que irá iniciar todos os metodos\n write(*,'(A,1F0.11)') 'Valor inicial encontrado = ', a\n\n ! definindo valor inicial para newton e secante\n x0_new = a\n x0_sec = a\n\n ! loop que itera cada metodo, e para quando todas as flags indicam false ou atingiu o nmax\n do while ( (n <= nmax) .and. (flag_dir .or. flag_new .or. flag_sec) )\n \n\t! metodo direto\n\t! verifica se o desvio já atingiu o erro\n\tif ( desv_dir .gt. erro ) then\n\t ! valor medio de ab\n x_dir = (a+b)/2\n ! verifica se o produto e redefine a ou b\n if ( f(x_dir)*f(a) .gt. 0 ) then\n a = x_dir\n else\n b = x_dir\n end if\n ! atualiza o valor do desvio\n desv_dir = abs(f(a)-f(b))\n else\n flag_dir = .false.\n end if\n\n\t! metodo de newton\n\t! verifica se o desvio já atingiu o erro\n if ( desv_new .gt. erro ) then\n x_new = x0_new - f(x0_new)/df(x0_new)\n\t ! atualiza o valor do desvio\n desv_new = abs(f(x_new) - f(x0_new))\n\t ! redefine x0\n x0_new = x_new\n else\n flag_new = .false.\n end if\n \n\n\t! metodo da secante\n ! verifica se o desvio já atingiu o erro\n if ( desv_sec .gt. erro ) then\n\t ! derivada numerica de f\n df_sec = ( f(x0_sec + h_sec) - f(x0_sec) ) / h_sec\n x_sec = x0_sec - f(x0_sec)/df_sec\n\t ! atualiza o desvio\n desv_sec = abs(f(x_sec) - f(x0_sec))\n\t ! redefine x0\n x0_sec = x_sec\n else\n flag_sec = .false.\n end if\n\n\t! escreve na tela o numero da iteração e o ultimo x encontrado\n write(*,*) n, x_dir, x_new, x_sec\n\t! soma 1 em n\n n = n + 1\n end do\n\ncontains ! funções utilizadas f(x) e a derivada de f(x)\n\n function f(x)\n f = x**3 -21*x -20\n return\n end function\n\n function df(x)\n df = 3*x**2 -21\n return\n end function\n\nend program tarefac\n", "meta": {"hexsha": "fe4bb3682dd40ed56b0196a3f91aa93bf81b61b1", "size": 2854, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "projeto-3/tarefa-c/tarefa-c-10407962.f90", "max_stars_repo_name": "ArexPrestes/introducao-fisica-computacional", "max_stars_repo_head_hexsha": "bf6e7a0134c11ddbaf9125c42eb0982250f970d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "projeto-3/tarefa-c/tarefa-c-10407962.f90", "max_issues_repo_name": "ArexPrestes/introducao-fisica-computacional", "max_issues_repo_head_hexsha": "bf6e7a0134c11ddbaf9125c42eb0982250f970d9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "projeto-3/tarefa-c/tarefa-c-10407962.f90", "max_forks_repo_name": "ArexPrestes/introducao-fisica-computacional", "max_forks_repo_head_hexsha": "bf6e7a0134c11ddbaf9125c42eb0982250f970d9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.4259259259, "max_line_length": 94, "alphanum_fraction": 0.5508058865, "num_tokens": 897, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.833324587033253, "lm_q1q2_score": 0.754983588696843}} {"text": "subroutine lsf_gauss(x,n,fwhm,lsf)\n\n!reconstructs a 1D Gaussian lsf\n\nuse share, only: dp, pi\n\nimplicit none\n\n!input/output\nreal(dp), intent(in) :: x(n) ! pixel location array\ninteger, intent(in) :: n ! number of data points\nreal(dp), intent(in) :: fwhm ! fwhm of the lsf\nreal(dp), intent(out):: lsf(n) ! lsf profile\n\n!locals\nreal(dp) :: sigma_to_fwhm \n\n\nsigma_to_fwhm = 2.0_dp*sqrt(-2.0_dp*log(0.5_dp))\n\nlsf(1:n)=1.0_dp/sqrt(2.0_dp*pi)/fwhm*sigma_to_fwhm * & \n\t\texp(-(x(1:n)/fwhm*sigma_to_fwhm)**2/2.0_dp)\n\nlsf(1:n)=lsf(1:n)/sum(lsf(1:n))\n\nend subroutine lsf_gauss\n\n", "meta": {"hexsha": "7240a6ae2a98af0cf95aa0d14c2523a792fda78f", "size": 585, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ferre/src/lsf_gauss.f90", "max_stars_repo_name": "dnidever/apogee", "max_stars_repo_head_hexsha": "83ad7496a0b4193df9e2c01b06dc36cb879ea6c1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-04-11T13:35:24.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-14T06:12:51.000Z", "max_issues_repo_path": "ferre/src/lsf_gauss.f90", "max_issues_repo_name": "dnidever/apogee", "max_issues_repo_head_hexsha": "83ad7496a0b4193df9e2c01b06dc36cb879ea6c1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ferre/src/lsf_gauss.f90", "max_forks_repo_name": "dnidever/apogee", "max_forks_repo_head_hexsha": "83ad7496a0b4193df9e2c01b06dc36cb879ea6c1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2018-09-20T22:07:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T07:13:38.000Z", "avg_line_length": 20.8928571429, "max_line_length": 56, "alphanum_fraction": 0.6615384615, "num_tokens": 232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9678992942089575, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7549545726939201}} {"text": "PROGRAM diff\nIMPLICIT NONE\nINTEGER, PARAMETER :: SGL = SELECTED_REAL_KIND(p=6,r=37)\nINTEGER, PARAMETER :: DBL = SELECTED_REAL_KIND(p=13)\nREAL(KIND=DBL) :: ans, d_ans, d_error, d_fx, d_fxdx, d_dx, d_x = 0.15_DBL\nINTEGER :: i\nREAL(KIND=SGL) :: s_ans, s_error, s_fx, s_fxdx, s_dx, s_x = 0.15_SGL\nWRITE(*, 1)\n1 FORMAT (' DX TRUE ANS SP ANS DP ANS', &\n ' SP ERR DP ERR')\nans = - (1.0_DBL / d_x**2)\nstep_size: DO i = 1, 10\n s_dx = 1.0 / 10.0**i\n d_dx = 1.0_DBL / 10.0_DBL**i\n s_fxdx = 1. / (s_x + s_dx)\n s_fx = 1. / s_x\n s_ans = (s_fxdx - s_fx) / s_dx\n s_error = (s_ans - REAL(ans)) / REAL(ans) * 100.\n d_fxdx = 1.0_DBL / (d_x + d_dx)\n d_fx = 1.0_DBL / d_x\n d_ans = (d_fxdx - d_fx) / d_dx\n d_error = (d_ans - ans) / ans * 100.\n WRITE(*, 100) d_dx, ans, s_ans, d_ans, s_error, d_error\n 100 FORMAT (ES10.3, F12.7, F12.7, ES22.14, F9.3, F9.3)\nEND DO step_size\n\nEND PROGRAM diff\n", "meta": {"hexsha": "a423ce428551357ed0886b8c59326a7d56d84dee", "size": 924, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap11/diff.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap11/diff.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap11/diff.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.0, "max_line_length": 73, "alphanum_fraction": 0.5963203463, "num_tokens": 412, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.7549493251193911}} {"text": "subroutine set_true_solution(x, y, t, components)\n\n implicit none\n\n double precision, intent(in) :: x, y, t\n double precision, dimension(2), intent(out) :: components\n \n double precision :: t0, tau, rho\n parameter(t0 = 1.d0)\n \n tau = t + t0\n rho = sqrt(x**2 + y**2) / tau**.25d0\n\n components(1) = 2.d0 * rho**2\n components(2) = -1.d0 / (8.d0 * tau**.5d0) * log(rho)\n\nend subroutine set_true_solution", "meta": {"hexsha": "9e78330d721d5d689d6604c95b5738b9a8a0613c", "size": 432, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/2d/Order2NonlinearSystem/true_solution.f90", "max_stars_repo_name": "claridge/implicit_solvers", "max_stars_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-04-29T00:16:18.000Z", "max_stars_repo_stars_event_max_datetime": "2017-04-29T00:16:18.000Z", "max_issues_repo_path": "applications/2d/Order2NonlinearSystem/true_solution.f90", "max_issues_repo_name": "claridge/implicit_solvers", "max_issues_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/2d/Order2NonlinearSystem/true_solution.f90", "max_forks_repo_name": "claridge/implicit_solvers", "max_forks_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.4117647059, "max_line_length": 61, "alphanum_fraction": 0.6018518519, "num_tokens": 143, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9518632247867715, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7549283882916885}} {"text": "subroutine djpi2(dj, lmax)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis subroutine computes \n!\t j\n!\td (pi/2)\n!\t m N\n!\n!\tfor all posible values of m (>=0) and N for 0vnor) vnor=abs(v(i))\n end do\n else if(inor==1) then\n do i=1,n\n vnor=vnor+abs(v(i))\n end do\n else if(inor==2) then\n do i=1,n\n vnor=vnor+v(i)*v(i)\n end do\n vnor=sqrt(vnor)\n end if\n \nend subroutine vecnor\n\nsubroutine vecnorALLMPI(v,ndime,n,vnor,inor,MPIComm,MPIrank,MPIroot,MPIsize) \n\n!-----------------------------------------------------------------------\n!\n! Compute the L1, L2 and L-inf norms of a vector V of length N\n!\n!-----------------------------------------------------------------------\n!Returns correct result only for rank 0!!\n use typre\n use MPI\n implicit none\n integer(ip), intent(in) :: n,inor,ndime\n real(rp), intent(in) :: v(ndime,n)\n real(rp), intent(out) :: vnor\n integer(ip) :: i\n integer(ip) :: MPIComm,MPIrank,MPIroot,MPIsize\n integer(ip) :: ierr,idime\n real(rp) :: vnor0,va\n\n vnor0=0.0_rp\n if(inor==0.or.inor==3) then\n do i = 1,n\n do idime = 1,ndime\n va = v(idime,i)\n if(abs(va)>vnor0) vnor0=abs(va)\n enddo\n end do\n\n call MPI_ALLREDUCE( vnor0, vnor, 1, MPI_REAL8, MPI_MAX, MPIroot,MPIcomm, ierr )\n\n else if(inor==1) then\n do i = 1,n\n do idime = 1,ndime\n va = v(idime,i)\n vnor0=vnor0+abs(va)\n enddo\n end do\n\n call MPI_ALLREDUCE( vnor0, vnor, 1, MPI_REAL8, MPI_SUM, MPIroot,MPIcomm, ierr )\n\n else if(inor==2) then\n\n do i = 1,n\n do idime = 1,ndime\n va = v(idime,i)\n vnor0 = vnor0 + va*va\n enddo\n end do\n\n call MPI_ALLREDUCE( vnor0, vnor, 1, MPI_REAL8, MPI_SUM, MPIroot,MPIcomm, ierr )\n\n vnor=sqrt(vnor)\n end if\n \nend subroutine vecnorALLMPI\n\nsubroutine vecnorMPI(v,n,vnor,inor,MPIComm,MPIrank,MPIroot,MPIsize) \n\n!-----------------------------------------------------------------------\n!\n! Compute the L1, L2 and L-inf norms of a vector V of length N\n!\n!-----------------------------------------------------------------------\n!Returns correct result only for rank 0!!\n use typre\n use MPI\n implicit none\n integer(ip), intent(in) :: n,inor\n real(rp), intent(in) :: v(n)\n real(rp), intent(out) :: vnor\n \n integer(ip) :: i\n integer(ip) :: MPIComm,MPIrank,MPIroot,MPIsize\n integer(ip) :: ierr\n real(rp) :: vnor0\n\n vnor0=0.0_rp\n if(inor==0.or.inor==3) then\n do i=1,n\n if(abs(v(i))>vnor0) vnor0=abs(v(i))\n end do\n \n call MPI_REDUCE( vnor0, vnor, 1, MPI_REAL8, MPI_MAX, MPIroot,MPIcomm, ierr )\n else if(inor==1) then\n do i=1,n\n vnor0=vnor0+abs(v(i))\n end do\n call MPI_REDUCE( vnor0, vnor, 1, MPI_REAL8, MPI_SUM, MPIroot,MPIcomm, ierr )\n else if(inor==2) then\n do i=1,n\n vnor0=vnor0+v(i)*v(i)\n end do\n call MPI_REDUCE( vnor0, vnor, 1, MPI_REAL8, MPI_SUM, MPIroot,MPIcomm, ierr )\n vnor=sqrt(vnor)\n end if\n \nend subroutine vecnorMPI\n\nsubroutine vecnorGenericMPI(v,n,ndime,vnor,inor,MPIcomm,MPIrank,MPIroot,MPIsize) \n\n!-----------------------------------------------------------------------\n!\n! Compute the L1, L2 and L-inf norms of a vector V of length N\n!\n!-----------------------------------------------------------------------\n!Returns correct result only for rank 0!!\n use typre\n use MPI\n implicit none\n integer(ip), intent(in) :: n,inor,ndime\n real(rp), intent(in) :: v(ndime,n)\n real(rp), intent(out) :: vnor\n \n integer(ip) :: i,idime\n integer(ip) :: MPIcomm,MPIrank,MPIroot,MPIsize\n integer(ip) :: ierr\n real(rp) :: vnor0,val\n\n val =0.0_rp\n vnor0=0.0_rp\n if(inor==0.or.inor==3) then\n\n do i=1,n\n do idime = 1,ndime\n if(abs(v(idime,i))>vnor0) vnor0=abs(v(idime,i))\n enddo\n end do\n \n call MPI_REDUCE( vnor0, vnor, 1, MPI_REAL8, MPI_MAX, MPIroot,MPIcomm, ierr )\n\n else if(inor==1) then\n\n do i=1,n\n do idime = 1,ndime\n vnor0=vnor0+abs(v(idime,i))\n enddo\n end do\n call MPI_REDUCE( vnor0, vnor, 1, MPI_REAL8, MPI_SUM, MPIroot,MPIcomm, ierr )\n\n else if(inor==2) then\n\n do i = 1,n\n do idime = 1,ndime\n val = v(idime,i)\n vnor0 = vnor0 + val*val\n enddo\n end do\n\n call MPI_REDUCE( vnor0, vnor, 1, MPI_REAL8, MPI_SUM, MPIroot,MPIcomm, ierr )\n vnor=sqrt(vnor)\n end if\n \nend subroutine vecnorGenericMPI\n\nsubroutine matNormF(ndime,matrix,matnor)\n !-----------------------------------------------------------------------\n !\n ! This routine computes the norm of a matrix\n ! norm = [sum_j sum_i |A_ij|^2]^0.5\n !\n !-----------------------------------------------------------------------\n use typre\n implicit none\n integer(ip), intent(in) :: ndime\n real(rp), intent(in) :: matrix(ndime,ndime)\n real(rp), intent(out) :: matnor\n\n real(rp) :: aux\n integer(ip) :: idime,jdime\n\n aux = 0.0_rp \n do idime = 1,ndime\n do jdime = 1,ndime\n aux = aux + (matrix(idime,jdime)*matrix(idime,jdime))\n enddo\n enddo\n\n matnor = sqrt(aux)\n\nend subroutine matNormF\n", "meta": {"hexsha": "168a155504fea7bb899aa60beb8cdac77f318e6b", "size": 5547, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/mathru/vecnor.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/mathru/vecnor.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/mathru/vecnor.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.0422535211, "max_line_length": 85, "alphanum_fraction": 0.5080223544, "num_tokens": 1778, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.8705972734445508, "lm_q1q2_score": 0.7548389594892216}} {"text": " program main\n use mpi\n double precision PI25DT\n parameter (PI25DT = 3.141592653589793238462643d0)\n double precision mypi, pi, h, sum, x, f, a\n integer n, myid, numprocs, i, ierr\n! function to integrate\n f(a) = 4.d0 / (1.d0 + a*a)\n\n call MPI_INIT(ierr)\n call MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr)\n call MPI_COMM_SIZE(MPI_COMM_WORLD, numprocs, ierr)\n\n do\n if (myid .eq. 0) then\n print *, 'Enter the number of intervals: (0 quits) '\n read(*,*) n\n endif\n! broadcast n\n call MPI_BCAST(n, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)\n! check for quit signal\n if (n .le. 0) exit\n! calculate the interval size\n h = 1.0d0/n\n sum = 0.0d0\n do i = myid+1, n, numprocs\n x = h * (dble(i) - 0.5d0)\n sum = sum + f(x)\n enddo\n mypi = h * sum\n! collect all the partial sums\n call MPI_REDUCE(mypi, pi, 1, MPI_DOUBLE_PRECISION, &\n MPI_SUM, 0, MPI_COMM_WORLD, ierr)\n! node 0 prints the answer.\n if (myid .eq. 0) then\n print *, 'pi is ', pi, ' Error is', abs(pi - PI25DT)\n endif\n enddo\n call MPI_FINALIZE(ierr)\n end\n", "meta": {"hexsha": "730c9158a2d97706918b68ad54272a96b17085bd", "size": 1403, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/mpi/Using_MPI/simplempi/pi3.f90", "max_stars_repo_name": "Fulayjan/ams250", "max_stars_repo_head_hexsha": "e72ab59a5f924728e69b46e2974914a2d3cab4c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-05-01T20:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T18:43:27.000Z", "max_issues_repo_path": "examples/mpi/Using_MPI/simplempi/pi3.f90", "max_issues_repo_name": "Fulayjan/ams250", "max_issues_repo_head_hexsha": "e72ab59a5f924728e69b46e2974914a2d3cab4c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-05-01T04:06:01.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-01T04:06:01.000Z", "max_forks_repo_path": "examples/mpi/Using_MPI/simplempi/pi3.f90", "max_forks_repo_name": "shawfdong/ams250", "max_forks_repo_head_hexsha": "e72ab59a5f924728e69b46e2974914a2d3cab4c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-06-03T22:37:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-07T01:52:07.000Z", "avg_line_length": 34.2195121951, "max_line_length": 66, "alphanum_fraction": 0.4818246614, "num_tokens": 397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942145139149, "lm_q2_score": 0.8354835289107309, "lm_q1q2_score": 0.7546874379867323}} {"text": "program compute_pi\nimplicit none\n\n\tinteger me,nimg,i,n\n\treal(selected_real_kind(p=33)) pi,psum,x,w\n\treal(selected_real_kind(p=33)) mypi[*]\n\tinteger(selected_int_kind(r=17)) st,et,rat\n\n\tnimg = num_images()\n\tme = this_image()\n\nprint *, nimg\nif(me==1) then\n write(*,*) \"please input steps:\"\n read(*,*) n\n call system_clock(count=st,count_rate=rat)\nend if\n\nw = 1.d0/n\npsum = 0.d0\ndo i= me,n,nimg\n x = w * (i - 0.5d0)\n psum = psum + 4.d0/(1.d0+x*x)\nenddo\nmypi = w * psum\nsync all\n\nif (me==1) then\n pi = mypi\n do i= 2,nimg\n pi = pi + mypi[i]\n enddo\n call system_clock(count=et)\n write(*,*) 'computed time ',(et-st)/real(rat,kind(pi)),'sec'\n write(*,*) 'computed pi = ',pi\n write(*,*) 'real pi = 3.1415926535897932384626433832795'\nendif\n\nend program\n", "meta": {"hexsha": "1c226cd0b7db457dfa4370fbc9f7e8b0cd4db157", "size": 771, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "a.f90", "max_stars_repo_name": "hxmhuang/Ex5", "max_stars_repo_head_hexsha": "de1a07404123c455e2359e3a7a067e32026a239c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "a.f90", "max_issues_repo_name": "hxmhuang/Ex5", "max_issues_repo_head_hexsha": "de1a07404123c455e2359e3a7a067e32026a239c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "a.f90", "max_forks_repo_name": "hxmhuang/Ex5", "max_forks_repo_head_hexsha": "de1a07404123c455e2359e3a7a067e32026a239c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.275, "max_line_length": 65, "alphanum_fraction": 0.6342412451, "num_tokens": 295, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7546874326617885}} {"text": "program P2\n ! integrate exp(-x) from [-1,+1] by Simpson algorithm\n implicit none\n integer :: i\n integer, dimension(4) :: N\n real*8 :: f_n,f_a,x0=-1.,xf=1.\n real*8, external :: f\n N = (/10,50,100,200/)\n f_a = -exp(x0)+exp(xf)\n\n do i = 1,4\n call simp(f,x0,xf,N(i),f_n)\n print *,N(i),f_n-f_a,(f_n-f_a)/f_a\n enddo\n \nend program P2\n\nsubroutine simp(f,x0,xf,N,sum)\n implicit none\n real*8, intent(in) :: x0,xf\n integer, intent(in) :: N\n real*8, external :: f\n real*8, intent(out) :: sum\n real*8 :: h\n integer :: i\n sum = -f(x0) + f(xf)\n h = (xf-x0)/2./N\n do i=0,2*N,2\n sum = sum + 4.*f(x0+h+i*h) + 2.*f(x0+i*h)\n enddo\n sum = sum*h/3.\nend subroutine simp\n\nreal*8 function f(x)\n implicit none\n real*8, intent(in) :: x\n f=exp(-x)\nend function f\n", "meta": {"hexsha": "ba2c13ec3cf308b7227676e4a24f9592ebbff9e6", "size": 774, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "HW2/P2.f90", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW2/P2.f90", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW2/P2.f90", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.8461538462, "max_line_length": 56, "alphanum_fraction": 0.5736434109, "num_tokens": 324, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088025362857, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.754673181592071}} {"text": "MODULE shape_mod\n USE input_mod,ONLY: runend\n USE esets_mod,ONLY: nnode\n IMPLICIT NONE\n !INTEGER(kind=4),PARAMETER :: shape_nodes=3\n\nCONTAINS\n!******************************************************************************\n!** 1-Dimension Shape Function Selector **\n!******************************************************************************\n! SUBROUTINE shape_1d_select(xi,N_shape,dN_shape)\n! IMPLICIT NONE\n! !--Dummy arguments\n! REAL(kind=8),INTENT(IN) :: xi\n! REAL(kind=8),ALLOCATABLE,DIMENSION(:),INTENT(OUT) :: N_shape,dN_shape\n! CHARACTER(len=5),INTENT(IN) :: ORDER\n!\n! SELECT CASE (nnode)\n! CASE (2)\n! ALLOCATE(N_shape(2),dN_shape(2))\n! CALL linear_shape_1d(xi,N_shape,dN_shape)\n! CASE (3)\n! ALLOCATE(N_shape(3),dN_shape(3))\n! CALL quadratic_shape_1d(xi,N_shape,dN_shape)\n! CASE DEFAULT\n! CALL runend('SHAPE_FUNCTIONS: ORDER not implemented')\n! END SELECT\n!******************************************************************************\n!** Linear Shape Functions 1-dimension **\n!******************************************************************************\n SUBROUTINE linear_shape_1d(xi,N_shape,dN_shape)\n IMPLICIT NONE\n !--Dummy arguments\n REAL(kind=8),INTENT(IN) :: xi\n REAL(kind=8),INTENT(OUT) :: N_shape(2),dN_shape(2)\n !--Local arguments\n\n !functions\n N_shape(1) = 0.5d0*(1.d0-xi)\n N_shape(2) = 0.5d0*(1.d0+xi)\n !derivatives\n dN_shape(1) = -0.5d0\n dN_shape(2) = 0.5d0\n\n END SUBROUTINE linear_shape_1d\n!******************************************************************************\n!** Quadratic Shape Functions 1-dimension **\n!******************************************************************************\n SUBROUTINE quadratic_shape_1d(xi,N_shape,dN_shape)\n IMPLICIT NONE\n !--Dummy arguments\n REAL(kind=8),INTENT(IN) :: xi\n REAL(kind=8),INTENT(OUT) :: N_shape(3),dN_shape(3)\n !--Local arguments\n\n !functions\n N_shape(1) = 0.5d0*xi*(xi-1.d0)\n N_shape(2) = 1.d0-xi**2.d0\n N_shape(3) = 0.5d0*xi*(xi+1.d0)\n !derivatives\n dN_shape(1) = 0.5d0*(2.d0*xi-1.d0)\n dN_shape(2) = 1.d0-2.d0*xi\n dN_shape(3) = 0.5d0*(2.d0*xi+1.d0)\n\n END SUBROUTINE quadratic_shape_1d\n\nEND MODULE shape_mod\n", "meta": {"hexsha": "88b1cf72a88304dc4fa49f94c4a460f7bc76a5fc", "size": 2308, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/shape_mod.f90", "max_stars_repo_name": "jdlaubrie/shell-elem", "max_stars_repo_head_hexsha": "f87cb9ca9179533d3a645a494e7ef4d39666ddc6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/shape_mod.f90", "max_issues_repo_name": "jdlaubrie/shell-elem", "max_issues_repo_head_hexsha": "f87cb9ca9179533d3a645a494e7ef4d39666ddc6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/shape_mod.f90", "max_forks_repo_name": "jdlaubrie/shell-elem", "max_forks_repo_head_hexsha": "f87cb9ca9179533d3a645a494e7ef4d39666ddc6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.9411764706, "max_line_length": 82, "alphanum_fraction": 0.4982668977, "num_tokens": 672, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.8633916152464017, "lm_q1q2_score": 0.7546709615833485}} {"text": "program intrinsics_18c\n! This program tests all trigonometric intrinsics, both in declarations\n! and in executable statements. Single and double precision, complex only.\ninteger, parameter :: dp = kind(0.d0)\n\ncomplex, parameter :: &\n s1 = sin((0.5,0.5)), &\n s2 = cos((0.5,0.5)), &\n s3 = tan((0.5,0.5)), &\n s4 = asin((0.5,0.5)), &\n s5 = acos((0.5,0.5)), &\n s6 = atan((0.5,0.5)), &\n s7 = sinh((0.5,0.5)), &\n s8 = cosh((0.5,0.5)), &\n s9 = tanh((0.5,0.5)), &\n s10 = asinh((0.5,0.5)), &\n s11 = acosh((1.5,1.5)), &\n s12 = atanh((0.5,0.5))\n\ncomplex(dp), parameter :: &\n d1 = sin((0.5_dp,0.5_dp)), &\n d2 = cos((0.5_dp,0.5_dp)), &\n d3 = tan((0.5_dp,0.5_dp)), &\n d4 = asin((0.5_dp,0.5_dp)), &\n d5 = acos((0.5_dp,0.5_dp)), &\n d6 = atan((0.5_dp,0.5_dp)), &\n d7 = sinh((0.5_dp,0.5_dp)), &\n d8 = cosh((0.5_dp,0.5_dp)), &\n d9 = tanh((0.5_dp,0.5_dp)), &\n d10 = asinh((0.5_dp,0.5_dp)), &\n d11 = acosh((1.5_dp,1.5_dp)), &\n d12 = atanh((0.5_dp,0.5_dp))\n\ncomplex :: x, x2\ncomplex(dp) :: y, y2\n\nx = (0.5,0.5)\ny = (0.5_dp,0.5_dp)\nx2 = (1.5,1.5)\ny2 = (1.5_dp,1.5_dp)\n\nprint *, sin((0.5,0.5)), sin((0.5_dp,0.5_dp)), s1, d1, sin(x), sin(y)\nprint *, cos((0.5,0.5)), cos((0.5_dp,0.5_dp)), s2, d2, cos(x), cos(y)\nprint *, tan((0.5,0.5)), tan((0.5_dp,0.5_dp)), s3, d3, tan(x), tan(y)\n\nprint *, asin((0.5,0.5)), asin((0.5_dp,0.5_dp)), s4, d4, asin(x), asin(y)\nprint *, acos((0.5,0.5)), acos((0.5_dp,0.5_dp)), s5, d5, acos(x), acos(y)\nprint *, atan((0.5,0.5)), atan((0.5_dp,0.5_dp)), s6, d6, atan(x), atan(y)\n\nprint *, sinh((0.5,0.5)), sinh((0.5_dp,0.5_dp)), s7, d7, sinh(x), sinh(y)\nprint *, cosh((0.5,0.5)), cosh((0.5_dp,0.5_dp)), s8, d8, cosh(x), cosh(y)\nprint *, tanh((0.5,0.5)), tanh((0.5_dp,0.5_dp)), s9, d9, tanh(x), tanh(y)\n\nprint *, asinh((0.5,0.5)), asinh((0.5_dp,0.5_dp)), s10, d10, asinh(x), asinh(y)\nprint *, acosh((1.5,1.5)), acosh((1.5_dp,1.5_dp)), s11, d11, acosh(x2), acosh(y2)\nprint *, atanh((0.5,0.5)), atanh((0.5_dp,0.5_dp)), s12, d12, atanh(x), atanh(y)\n\nend\n", "meta": {"hexsha": "fb464a7ad785ec9eef5b96e720a6927d5c02d863", "size": 2021, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/intrinsics_18c.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/intrinsics_18c.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/intrinsics_18c.f90", "max_forks_repo_name": "Thirumalai-Shaktivel/lfortran", "max_forks_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-03-28T19:40:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:28:55.000Z", "avg_line_length": 34.2542372881, "max_line_length": 81, "alphanum_fraction": 0.5329045027, "num_tokens": 979, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067211996142, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7546575913449394}} {"text": "\n!> Utility module description goes here!\n!! This is a continuation line for the module description.\n\n!> @author J. Kaye\n!> @version 0.0 \n\nmodule utils\n\ncontains\n \n !> Evaluate the function \\f$ (1-e^{-x})/x \\f$ using\n !! a numerically stable method when the exponent is close to unity.\n !! @param[in] x point to evaluate the function\n !! @param[out] val resulting value\n\n subroutine evalexpfun(x,val)\n\n implicit none\n real *8 x,val\n \n integer i\n real *8 one,x1,c\n\n one = 1.0d0\n\n if (x>1.0d-1) then\n\n val = (one-exp(-x))/x\n\n else\n\n val = one\n c = one\n x1 = x\n do i=1,10\n c = c*(i+1)\n val = val + ((-1)**i)*x1/c\n x1 = x1*x\n enddo\n\n endif\n\n end subroutine evalexpfun\n\nend module utils\n", "meta": {"hexsha": "b021e124d9698d6445a12d6578e09d32ce3e61e8", "size": 779, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/utils.f90", "max_stars_repo_name": "HugoStrand/readthedocs_test", "max_stars_repo_head_hexsha": "c989cd0a4d62a012cc8a90a85fd32374b05171e5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/utils.f90", "max_issues_repo_name": "HugoStrand/readthedocs_test", "max_issues_repo_head_hexsha": "c989cd0a4d62a012cc8a90a85fd32374b05171e5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/utils.f90", "max_forks_repo_name": "HugoStrand/readthedocs_test", "max_forks_repo_head_hexsha": "c989cd0a4d62a012cc8a90a85fd32374b05171e5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.5744680851, "max_line_length": 69, "alphanum_fraction": 0.567394095, "num_tokens": 249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391621868804, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7546532554283318}} {"text": "subroutine nbody_timestep(position,velocity)\n! Adjusts the timestep based on a standard step doubling algorithm\n! Takes two half timesteps and compares to the current result\n\nuse stardata,only: debug\nuse embryodata\n\nimplicit none\n\nreal,dimension(3,nbodies),intent(in) :: position,velocity\n\ninteger :: ibody,ix\nreal :: halfdt,error\nreal, dimension(3,nbodies) :: testpos1,testvel1,testpos2,testvel2\n\nhalfdt = dt_nbody/2\n\ncall nbody_integrate(halfdt,pos,vel,testpos1,testvel1)\ncall nbody_integrate(halfdt,testpos1,testvel1,testpos2,testvel2)\n\n! Compute error between half timestep and full timestep for each particle\n\nerror = 0.0\nmaxerror = -1.0e30\n\ndo ibody=1,nbodies\n\n error = 0.0\n do ix=1,3\n\n error = error + (position(ix,ibody)-testpos2(ix,ibody))*(position(ix,ibody)-testpos2(ix,ibody))\n error = error + (velocity(ix,ibody)-testvel2(ix,ibody))*(velocity(ix,ibody)-testvel2(ix,ibody))\n\n enddo\n\n error = sqrt(error)\n\n if(error>maxerror) maxerror = error\nenddo\n\n! Compute new deltat based on this error level\n! If current error below user defined tolerance, then dt is increased\n! If current error above tolerance, then dt is decreased\n\nif(maxerror>small) then\n dt_nbody = dt_nbody*abs(tolerance/maxerror)**0.2\nendif\n\nif(maxerror>tolerance) then\n if(debug=='y') then\n print*,'reducing timestep'\n print*,tolerance,maxerror,dt_nbody\n endif\n\n dt_nbody = dt_nbody*0.1\nendif\n\nend subroutine nbody_timestep\n", "meta": {"hexsha": "ccf3d9cffc005d73a5abc112f64bd066f628bd5a", "size": 1438, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/nbody/nbody_timestep.f90", "max_stars_repo_name": "dh4gan/grapus", "max_stars_repo_head_hexsha": "456707db38dd8920d319807f7f4f7297d6278b4a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/nbody/nbody_timestep.f90", "max_issues_repo_name": "dh4gan/grapus", "max_issues_repo_head_hexsha": "456707db38dd8920d319807f7f4f7297d6278b4a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/nbody/nbody_timestep.f90", "max_forks_repo_name": "dh4gan/grapus", "max_forks_repo_head_hexsha": "456707db38dd8920d319807f7f4f7297d6278b4a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.3728813559, "max_line_length": 101, "alphanum_fraction": 0.7496522949, "num_tokens": 432, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391600697869, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7546532536974503}} {"text": "! Name = ARPIT KUMAR JAIN ROLL No = 180122009\n! Code for Question 2 Simple Harmonic Oscillator --> Second Order ODEs (x\" = -x)\n\nMODULE precision\n IMPLICIT NONE\n\n ! dp = double precisiona\n INTEGER, PARAMETER:: dp = SELECTED_REAL_KIND(12)\nEND MODULE precision\n\n! Tp --> Time Period = 2π\n! h --> step size = 0.02T\nMODULE constants\n USE precision\n IMPLICIT NONE\n \n REAL(KIND = dp), PARAMETER :: pi = acos(-1.0), Tp = 2 * pi\n REAL(KIND = dp):: h = 0.02 * Tp\n REAL(KIND = dp):: tinitial = 0.0, xinitial = 1.0, pinitial = 0.0\nEND MODULE constants\n\nPROGRAM Simple_Harmonic_Oscillator\n USE precision\n USE constants\n IMPLICIT NONE\n \n ! t --> Time\n ! x0 --> value at starting point\n ! p0 --> value of X' at starting point\n ! x1 --> new value of x\n ! p1 --> new value of p\n REAL(KIND = dp):: t, x0, p0, x1, p1\n\n ! i --> iterator,, Nt --> number of iteration or Grid Points\n INTEGER:: i, Nt\n\n Nt = 500\n\n ! Propagating Euler Method Solution \n t = tinitial\n x0 = xinitial\n p0 = pinitial\n OPEN(UNIT = 10, FILE = 'Euler_P_vs_X.txt')\n OPEN(UNIT = 11, FILE = 'Euler_2E_vs_time.txt')\n OPEN(UNIT = 12, FILE = 'Euler_X_vs_time.txt')\n DO i = 1, Nt\n\n t = t + h\n CALL Euler_Method(t, x0, p0, x1, p1)\n\n WRITE(10, *) x1, p1\n WRITE(11, *) t/Tp, p1**2.0_dp + x1**2.0_dp\n WRITE(12, *) t/Tp, x1\n\n ! Update values for next itration\n x0 = x1\n p0 = p1\n ENDDO\n CLOSE(10)\n CLOSE(11)\n CLOSE(12)\n\n ! Propagating Runge-Kutta 4 Method Solution \n t = tinitial\n x0 = xinitial\n p0 = pinitial\n OPEN(UNIT = 20, FILE = 'RK4_P_vs_X.txt')\n OPEN(UNIT = 21, FILE = 'RK4_2E_vs_time.txt')\n OPEN(UNIT = 22, FILE = 'RK4_X_vs_time.txt')\n DO i = 1, Nt\n\n t = t + h\n CALL RK4_Method(t, x0, p0, x1, p1)\n\n WRITE(20, 5) x1, p1\n WRITE(21, 5) t/Tp, p1**2.0_dp + x1**2.0_dp\n WRITE(22, 5) t/Tp, x1\n 5 FORMAT(f7.4, 3x, f7.4)\n\n ! Update values for next itration\n x0 = x1\n p0 = p1\n ENDDO\n CLOSE(20)\n CLOSE(21)\n CLOSE(22)\n\n CONTAINS\n SUBROUTINE Euler_Method(t, x0, p0, x1, p1)\n USE precision\n USE constants\n IMPLICIT NONE\n\n REAL(KIND = dp):: t, x0, p0, x1, p1\n\n x1 = x0 + h * dx_by_dt(t, x0, p0)\n p1 = p0 + h * dp_by_dt(t, x0, p0)\n END SUBROUTINE Euler_Method\n\n SUBROUTINE RK4_Method(t, x0, p0, x1, p1)\n USE precision\n USE constants\n IMPLICIT NONE\n\n REAL(KIND = dp):: t, x0, p0, x1, p1\n REAL(KIND = dp):: s1x, s2x, s3x, s4x, s1p, s2p, s3p, s4p\n\n s1x = h * dx_by_dt(t, x0, p0)\n s1p = h * dp_by_dt(t, x0, p0)\n\n s2x = h * dx_by_dt(t + h/2.0_dp, x0 + s1x/2.0_dp, p0 + s1p/2.0_dp)\n s2p = h * dp_by_dt(t + h/2.0_dp, x0 + s1x/2.0_dp, p0 + s1p/2.0_dp)\n\n s3x = h * dx_by_dt(t + h/2.0_dp, x0 + s2x/2.0_dp, p0 + s2p/2.0_dp)\n s3p = h * dp_by_dt(t + h/2.0_dp, x0 + s2x/2.0_dp, p0 + s2p/2.0_dp)\n\n s4x = h * dx_by_dt(t + h, x0 + s3x, p0 + s3p)\n s4p = h * dp_by_dt(t + h, x0 + s3x, p0 + s3p)\n\n x1 = x0 + (s1x + 2.0_dp * s2x + 2.0_dp * s3x + s4x)/6.0_dp\n p1 = p0 + (s1p + 2.0_dp * s2p + 2.0_dp * s3p + s4p)/6.0_dp\n END SUBROUTINE RK4_Method\n\n FUNCTION dx_by_dt(t, x, p)\n IMPLICIT NONE\n\n REAL(KIND = dp):: dx_by_dt, t, x, p\n\n ! No change in t and x\n t = t\n x = x\n\n ! x' = p\n dx_by_dt = p\n RETURN\n END FUNCTION dx_by_dt\n\n FUNCTION dp_by_dt(t, x, p)\n IMPLICIT NONE\n\n REAL(KIND = dp):: dp_by_dt, t, x, p\n\n ! No change in t and p\n t = t\n p = p\n\n ! P' = -x\n dp_by_dt = -x\n RETURN\n END FUNCTION dp_by_dt\n\nEND PROGRAM Simple_Harmonic_Oscillator\n", "meta": {"hexsha": "e4065a1150d45b4548c1e193bd9495aaac239de4", "size": 3796, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "7. HA7 - ODEs/Arpit_Q2.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "7. HA7 - ODEs/Arpit_Q2.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "7. HA7 - ODEs/Arpit_Q2.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 24.8104575163, "max_line_length": 80, "alphanum_fraction": 0.5363540569, "num_tokens": 1491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.8757869835428966, "lm_q1q2_score": 0.7545239558716154}} {"text": "program P13301\n implicit none\n\n integer(8) :: current, prev, temp\n integer :: n\n integer :: i\n\n read (*,*) n\n\n current = 4\n prev = 2\n do i = 2, n\n temp = current\n current = current + prev\n prev = temp\n end do\n write (*, '(I0)') current\n\nend program P13301", "meta": {"hexsha": "38211ae330889d19b66f089ac82dcad497813291", "size": 306, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "P13301.f95", "max_stars_repo_name": "daily-boj/kiwiyou", "max_stars_repo_head_hexsha": "ceca96ddfee95708871af67d1682048e0bed0257", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-04-08T09:04:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T07:30:24.000Z", "max_issues_repo_path": "P13301.f95", "max_issues_repo_name": "daily-boj/kiwiyou", "max_issues_repo_head_hexsha": "ceca96ddfee95708871af67d1682048e0bed0257", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "P13301.f95", "max_forks_repo_name": "daily-boj/kiwiyou", "max_forks_repo_head_hexsha": "ceca96ddfee95708871af67d1682048e0bed0257", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-04-16T05:32:06.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-28T13:40:56.000Z", "avg_line_length": 16.1052631579, "max_line_length": 37, "alphanum_fraction": 0.5196078431, "num_tokens": 96, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182775, "lm_q2_score": 0.8418256393148982, "lm_q1q2_score": 0.7544873945064139}} {"text": "module misc\n use iso_fortran_env, only: wp => real64\n implicit none\n\n real(wp), parameter :: pi = 4._wp*datan(1._wp)\n\ncontains\n\n subroutine mysub(n, t, y, dy)\n integer, intent(in) :: n\n real(wp), intent(in) :: t\n real(wp), intent(in), dimension(n) :: y\n real(wp), intent(out), dimension(n) :: dy\n\n ! call simple_trig(n, t, y, dy)\n ! call simple_ode(n, t, y, dy)\n ! call vanderpol(n, t, y, dy)\n ! call lorenz(n, t, y, dy)\n ! call brusselator(n, t, y, dy)\n ! call stiff(n, t, y, dy)\n call robertson(n, t, y, dy)\n\n return\n end subroutine mysub\n\n subroutine simple_trig(n, t, y, dy)\n integer, intent(in) :: n\n real(wp), intent(in) :: t\n real(wp), intent(in), dimension(n) :: y\n real(wp), intent(out), dimension(n) :: dy\n\n dy(1) = dcos(t)\n dy(2) = -dsin(t)\n\n return\n end subroutine simple_trig\n\n subroutine simple_ode(n, t, y, dy)\n integer, intent(in) :: n\n real(wp), intent(in) :: t\n real(wp), intent(in), dimension(n) :: y\n real(wp), intent(out), dimension(n) :: dy\n\n dy(1) = y(2)\n dy(2) = -y(1)\n dy(3) = -y(2)\n\n return\n end subroutine simple_ode\n\n subroutine vanderpol(n, t, y, dy)\n integer, intent(in) :: n\n real(wp), intent(in) :: t\n real(wp), intent(in), dimension(n) :: y\n real(wp), intent(out), dimension(n) :: dy\n\n real(wp), parameter :: mu = 10._wp\n real(wp), parameter :: A = 0._wp\n real(wp), parameter :: omega = 2._wp*pi/11_wp\n\n dy(1) = y(2)\n dy(2) = mu * (1._wp-y(1)*y(1)) * y(2) - y(1) + A*dsin(t*omega)\n\n return\n end subroutine vanderpol\n\n subroutine lorenz(n, t, y, dy)\n integer, intent(in) :: n\n real(wp), intent(in) :: t\n real(wp), intent(in), dimension(n) :: y\n real(wp), intent(out), dimension(n) :: dy\n\n real(wp), parameter :: sigma = 10._wp\n real(wp), parameter :: rho = 28._wp\n real(wp), parameter :: beta = 8._wp/3._wp\n\n dy(1) = sigma * (y(2)-y(1))\n dy(2) = y(1) * (rho-y(3)) - y(2)\n dy(3) = y(1)*y(2) - beta*y(3)\n\n return\n end subroutine lorenz\n\n subroutine brusselator(n, t, y, dy)\n integer, intent(in) :: n\n real(wp), intent(in) :: t\n real(wp), intent(in), dimension(n) :: y\n real(wp), intent(out), dimension(n) :: dy\n\n dy(1) = 1._wp + y(1)*y(1)*y(2) - 4._wp*y(1)\n dy(2) = 3._wp*y(1) - y(1)*y(1)*y(2)\n\n return\n end subroutine brusselator\n\n subroutine stiff(n, t, y, dy)\n integer, intent(in) :: n\n real(wp), intent(in) :: t\n real(wp), intent(in), dimension(n) :: y\n real(wp), intent(out), dimension(n) :: dy\n\n dy(1) = -50._wp * ( y(1) - dcos(t) )\n\n return\n end subroutine stiff\n\n subroutine robertson(n, t, y, dy)\n integer, intent(in) :: n\n real(wp), intent(in) :: t\n real(wp), intent(in), dimension(n) :: y\n real(wp), intent(out), dimension(n) :: dy\n\n real(wp), dimension(n) :: k\n\n k = [ 4d-2, 3d7, 1d4 ]\n\n dy(1) = - k(1) * y(1) + k(3) * y(2) * y(3)\n dy(2) = k(1) * y(1) - k(3) * y(2) * y(3) - k(2) * y(2) * y(2)\n dy(3) = k(2) * y(2) * y(2)\n\n ! print*, y\n ! print*, dy\n ! stop\n\n return\n end subroutine robertson\n\nend module misc\n", "meta": {"hexsha": "89cfd3aaa0d307d02fb6d66629c4a25f9765f64c", "size": 3484, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/test/src/misc.f90", "max_stars_repo_name": "cbcoutinho/generic_rk", "max_stars_repo_head_hexsha": "eebf44cc47e9f62adf19c093d59479afda1b88ce", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2016-11-09T09:13:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-30T01:53:27.000Z", "max_issues_repo_path": "src/test/src/misc.f90", "max_issues_repo_name": "cbcoutinho/generic_rk", "max_issues_repo_head_hexsha": "eebf44cc47e9f62adf19c093d59479afda1b88ce", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/test/src/misc.f90", "max_forks_repo_name": "cbcoutinho/generic_rk", "max_forks_repo_head_hexsha": "eebf44cc47e9f62adf19c093d59479afda1b88ce", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-05-16T19:42:37.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-16T19:42:37.000Z", "avg_line_length": 27.007751938, "max_line_length": 67, "alphanum_fraction": 0.48163031, "num_tokens": 1183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7544207993358574}} {"text": "MODULE Conversion\n IMPLICIT NONE\n CHARACTER(36) :: alphanum = \"0123456789abcdefghijklmnopqrstuvwxyz\"\n\n CONTAINS\n\n FUNCTION ToDecimal(base, instr)\n INTEGER :: ToDecimal\n INTEGER :: length, i, n, base\n CHARACTER(*) :: instr\n\n ToDecimal = 0\n length = LEN(instr)\n DO i = 1, length\n n = INDEX(alphanum, instr(i:i)) - 1\n n = n * base**(length-i)\n Todecimal = ToDecimal + n\n END DO\n END FUNCTION ToDecimal\n\n FUNCTION ToBase(base, number)\n CHARACTER(31) :: ToBase\n INTEGER :: base, number, i, rem\n\n ToBase = \" \"\n DO i = 31, 1, -1\n IF(number < base) THEN\n ToBase(i:i) = alphanum(number+1:number+1)\n EXIT\n END IF\n rem = MOD(number, base)\n ToBase(i:i) = alphanum(rem+1:rem+1)\n number = number / base\n END DO\n ToBase = ADJUSTL(ToBase)\n END FUNCTION ToBase\n\nEND MODULE Conversion\n\nPROGRAM Base_Convert\n USE Conversion\n\n WRITE (*,*) ToDecimal(16, \"1a\")\n WRITE (*,*) ToBase(16, 26)\n\nEND PROGRAM\n", "meta": {"hexsha": "616030f1fa972228682ea8247ad83f931d852ab8", "size": 1013, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Non-decimal-radices-Convert/Fortran/non-decimal-radices-convert.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Non-decimal-radices-Convert/Fortran/non-decimal-radices-convert.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Non-decimal-radices-Convert/Fortran/non-decimal-radices-convert.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 21.5531914894, "max_line_length": 68, "alphanum_fraction": 0.5923000987, "num_tokens": 306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422269175634, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7543565605908286}} {"text": "! This file is F-compatible, except for upper/lower case conventions.\n!--------------------------------------------------------------------\nModule Volume_Computation\n\nUSE Precision_Model, ONLY: stnd\n\nImplicit NONE\n\nPRIVATE\nPUBLIC :: VOLUME\n\nCONTAINS\n FUNCTION VOLUME(DIMENS,GEOMETRY,VERTIC) RESULT(Value)\n!***BEGIN PROLOGUE VOLUME\n!***PURPOSE To compute the volume of a polytope\n!***AUTHORS\n! Ronald Cools Alan Genz\n! Dept. of Computer Science Computer Science Department\n! Katholieke Universiteit Leuven Washington State University\n! Celestijnenlaan 200A Pullman, WA 99164-2752\n! B-3001 Heverlee, Belgium USA\n!\n!***REVISION DATE 950419 (YYMMDD) (Fortran90 transformation)\n!***REVISION DATE 980408 (YYMMDD) (F transformation)\n!***DESCRIPTION VOLUME\n!\n! GEOMETRY = 1 : the VERTICes specify a simplex\n! GEOMETRY = 2 : the VERTICes specify a cube\n! GEOMETRY = 3 : the VERTICes specify an octahedron\n!\n! WARNING: If a region of an unsupported shape is presented,\n! then this function returns 0.\n! This is the only indication of a failure !\n!\n! Global variables.\n!\n INTEGER, INTENT(IN) :: DIMENS,GEOMETRY\n REAL(kind=stnd), DIMENSION(:,:), INTENT(IN) :: VERTIC\n REAL(kind=stnd) :: Value\n!\n! Local variables.\n!\n INTEGER :: I,J,K,PIVPOS,FACDIM\n REAL(kind=stnd) :: MULT,VOL\n REAL(kind=stnd), DIMENSION(DIMENS) :: TMP\n REAL(kind=stnd), DIMENSION(DIMENS,DIMENS) :: WORK\n\n IF ((GEOMETRY == 1) .OR. (GEOMETRY == 2) .OR. (GEOMETRY == 3)) THEN\n SELECT CASE (DIMENS)\n CASE (1) ! Compute length of an interval\n Value = ABS(VERTIC(1,2)-VERTIC(1,1))\n\n CASE (2) ! Compute area of a rectangle.\n Value = ABS((VERTIC(1,2)-VERTIC(1,1))* &\n (VERTIC(2,3)-VERTIC(2,1))- &\n (VERTIC(2,2)-VERTIC(2,1))* &\n (VERTIC(1,3)-VERTIC(1,1)))\n\n CASE (3) ! Compute the volume of a cube.\n Value = ABS((VERTIC(1,2)-VERTIC(1,1))* &\n ((VERTIC(2,3)-VERTIC(2,1))* (VERTIC(3, &\n 4)-VERTIC(3,1))- (VERTIC(2,4)-VERTIC(2, &\n 1))* (VERTIC(3,3)-VERTIC(3,1)))- &\n (VERTIC(2,2)-VERTIC(2,1))* &\n ((VERTIC(1,3)-VERTIC(1,1))* (VERTIC(3, &\n 4)-VERTIC(3,1))- (VERTIC(1,4)-VERTIC(1, &\n 1))* (VERTIC(3,3)-VERTIC(3,1)))+ &\n (VERTIC(3,2)-VERTIC(3,1))* &\n ((VERTIC(1,3)-VERTIC(1,1))* (VERTIC(2, &\n 4)-VERTIC(2,1))- (VERTIC(1,4)-VERTIC(1, &\n 1))* (VERTIC(2,3)-VERTIC(2,1))))\n\n CASE DEFAULT ! Compute the volume of a DIMENS-dimensional cube\n DO J = 1,DIMENS\n WORK(1:DIMENS,J) = VERTIC(1:DIMENS,J+1) - VERTIC(1:DIMENS,1)\n END DO\n VOL = 1\n DO K = 1,DIMENS\n PIVPOS = K\n DO J = K + 1,DIMENS\n IF (ABS(WORK(K,J)) > ABS(WORK(K,PIVPOS))) THEN\n PIVPOS = J\n END IF\n END DO\n TMP(K:DIMENS) = WORK(K:DIMENS,K)\n WORK(K:DIMENS,K) = WORK(K:DIMENS,PIVPOS)\n WORK(K:DIMENS,PIVPOS) = TMP(K:DIMENS)\n VOL = VOL*WORK(K,K)\n DO J = K + 1,DIMENS\n MULT = WORK(K,J)/WORK(K,K)\n WORK(K+1:DIMENS,J) = WORK(K+1:DIMENS,J) - MULT*WORK(K+1:DIMENS,K)\n END DO\n END DO\n Value = ABS(VOL)\n END SELECT\n IF ((GEOMETRY == 1) .OR. (GEOMETRY == 3)) THEN\n!\n! The volume of an DIMENS-dimensional simplex is the\n! DIMENS! part of the volume of the cube.\n!\n FACDIM = DIMENS\n DO I = 2,DIMENS - 1\n FACDIM = FACDIM*I\n END DO\n Value = Value/FACDIM\n END IF\n IF (GEOMETRY == 3) THEN\n!\n! The volume of an DIMENS-dimensional octahedron is\n! 2**(DIMENS-1) times the volume of the simplex.\n!\n Value = Value*2**(DIMENS-1)\n END IF\n ELSE\n Value = 0\n END IF\n RETURN\n END FUNCTION VOLUME\n\nEND MODULE Volume_Computation\n", "meta": {"hexsha": "d75766453d8a0ccc3346c21f338157080e2e38bd", "size": 4598, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "External/CUBPACK/volume.f90", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/CUBPACK/volume.f90", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/CUBPACK/volume.f90", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 38.0, "max_line_length": 87, "alphanum_fraction": 0.4691170074, "num_tokens": 1314, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.951142217223021, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7543565529020292}} {"text": "module user_functions\n implicit none\ncontains\n\nreal function f( x )\n real, intent(in) :: x\n f = x - x**2 + sin(x)\nend function f\n\nend module user_functions", "meta": {"hexsha": "e940c4aee3215b2c1dc3c39a35cf1229b00a735e", "size": 164, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "function.f90", "max_stars_repo_name": "Sunbuyu/Fortran_demo", "max_stars_repo_head_hexsha": "7293efef57d3a435537a42439e7a47c41bf96e77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "function.f90", "max_issues_repo_name": "Sunbuyu/Fortran_demo", "max_issues_repo_head_hexsha": "7293efef57d3a435537a42439e7a47c41bf96e77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "function.f90", "max_forks_repo_name": "Sunbuyu/Fortran_demo", "max_forks_repo_head_hexsha": "7293efef57d3a435537a42439e7a47c41bf96e77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.4, "max_line_length": 25, "alphanum_fraction": 0.6707317073, "num_tokens": 45, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9511422199928905, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7543565504475247}} {"text": "subroutine get_laplacian(q, q_laplacian)\n\n! Calculate Laplacian of q at cell centers. Fills ghost cells within the\n! outermost layer.\n\n !$ use omp_lib\n implicit none\n\n integer :: mx, my, mbc, meqn\n double precision :: x_lower, y_lower, dx, dy\n common /claw_config/ mx, my, mbc, x_lower, y_lower, dx, dy, meqn\n\n double precision, dimension(1-mbc:mx+mbc,1-mbc:my+mbc), intent(in) :: q\n double precision, dimension(1-mbc:mx+mbc,1-mbc:my+mbc), intent(out) :: q_laplacian\n\n integer :: ix, iy\n\n !$omp parallel do private(ix)\n do iy = 2-mbc,my+mbc-1\n do ix = 2-mbc,mx+mbc-1\n q_laplacian(ix,iy) = (q(ix-1,iy) - 2.d0*q(ix,iy) + q(ix+1,iy)) / dx**2\n q_laplacian(ix,iy) = q_laplacian(ix,iy) + &\n (q(ix,iy-1) - 2.d0*q(ix,iy) + q(ix,iy+1)) / dy**2\n end do\n end do\n \nend subroutine get_laplacian", "meta": {"hexsha": "a58ccb6e285861b5f22dd04a9d54c3a4a7d5302b", "size": 887, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "implicit_claw/2d/get_laplacian.f90", "max_stars_repo_name": "claridge/implicit_solvers", "max_stars_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-04-29T00:16:18.000Z", "max_stars_repo_stars_event_max_datetime": "2017-04-29T00:16:18.000Z", "max_issues_repo_path": "implicit_claw/2d/get_laplacian.f90", "max_issues_repo_name": "claridge/implicit_solvers", "max_issues_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "implicit_claw/2d/get_laplacian.f90", "max_forks_repo_name": "claridge/implicit_solvers", "max_forks_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.8518518519, "max_line_length": 86, "alphanum_fraction": 0.5941375423, "num_tokens": 326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.754321737129979}} {"text": " program demo_sinh\n use, intrinsic :: iso_fortran_env, only : &\n & real_kinds, real32, real64, real128\n implicit none\n real(kind=real64) :: x = - 1.0_real64\n real(kind=real64) :: nan, inf\n character(len=20) :: line\n\n print *, sinh(x)\n print *, (exp(x)-exp(-x))/2.0\n\n ! sinh(3) is elemental and can handle an array\n print *, sinh([x,2.0*x,x/3.0])\n\n ! a NaN input returns NaN\n line='NAN'\n read(line,*) nan\n print *, sinh(nan)\n\n ! a Inf input returns Inf\n line='Infinity'\n read(line,*) inf\n print *, sinh(inf)\n\n ! an overflow returns Inf\n x=huge(0.0d0)\n print *, sinh(x)\n\n end program demo_sinh\n", "meta": {"hexsha": "9ef683a4aaa3df499007acecd619746836ea2309", "size": 706, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/sinh.f90", "max_stars_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_stars_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-12-31T17:21:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T15:56:29.000Z", "max_issues_repo_path": "example/sinh.f90", "max_issues_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_issues_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/sinh.f90", "max_forks_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_forks_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-06T15:56:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-06T15:56:31.000Z", "avg_line_length": 23.5333333333, "max_line_length": 53, "alphanum_fraction": 0.5481586402, "num_tokens": 216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7543217351614966}} {"text": " function fcgd(xx)\n \n implicit none\n \n real :: fcgd ! |\n real :: tn ! |\n real :: top ! |\n real :: tx ! |\n real :: qq ! |\n real :: xx ! |\n \n tn = -5.\n\t top = 35.\n tx = 50.\n qq = (tn - top)/(top - tx)\n\t fcgd = ((xx-tn)**qq)*(tx-xx)/(((top-tn)**qq)*(tx-top))\n if (fcgd < 0.) fcgd = 0.\n end function", "meta": {"hexsha": "1cde0d9c6f084fb2957afa72934602827f7abe32", "size": 506, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/multifile_multimod/mfmm_02/fcgd.f90", "max_stars_repo_name": "mikiec84/delphi", "max_stars_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-03-03T11:57:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T21:19:54.000Z", "max_issues_repo_path": "tests/data/program_analysis/multifile_multimod/mfmm_02/fcgd.f90", "max_issues_repo_name": "mikiec84/delphi", "max_issues_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 385, "max_issues_repo_issues_event_min_datetime": "2018-02-21T16:52:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T07:44:56.000Z", "max_forks_repo_path": "tests/data/program_analysis/multifile_multimod/mfmm_02/fcgd.f90", "max_forks_repo_name": "mikiec84/delphi", "max_forks_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-03-20T01:08:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-29T01:04:49.000Z", "avg_line_length": 28.1111111111, "max_line_length": 57, "alphanum_fraction": 0.2727272727, "num_tokens": 134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7543217332550428}} {"text": "\tSUBROUTINE RTTOXY ( r, theta, x, y, iret )\nC************************************************************************\nC* RTTOXY\t\t\t\t\t\t\t\t*\nC* \t\t\t\t\t\t\t\t\t*\nC* This subroutine converts r, theta in polar coordinates to x, y\t*\nC* in linear coordinates.\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* RTTOXY ( R, THETA, X, Y, IRET )\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC* \tR\t\tREAL\t\tValue of r\t\t\t*\nC*\tTHETA\t\tREAL\t\tValue of theta in degrees\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tX\t\tREAL\t\tValue of x\t\t\t*\nC*\tY\t\tREAL\t\tValue of y\t\t\t*\nC* \tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. desJardins/GSFC\t10/86\t\t\t\t\t\t*\nC* K. Brill/EMC\t\t 3/96\tInput and output variables can be same\t*\nC************************************************************************\n\tINCLUDE\t\t'ERROR.PRM'\n\tINCLUDE\t\t'GEMPRM.PRM'\nC-------------------------------------------------------------------------\n\tiret = NORMAL\nC\nC*\tDo transformation.\nC\n\trr = r\n\tth = theta\n\tx = rr * COS ( th * DTR )\n\ty = rr * SIN ( th * DTR )\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "1d26bcf73e112ebca038dedf1bc08fe9ce3167d9", "size": 1010, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/gplt/transform/rttoxy.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/gplt/transform/rttoxy.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/gplt/transform/rttoxy.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 27.2972972973, "max_line_length": 74, "alphanum_fraction": 0.4277227723, "num_tokens": 320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147438, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.7543217332136902}} {"text": " program demo_log\n implicit none\n real(kind(0.0d0)) :: x = 2.71828182845904518d0\n complex :: z = (1.0, 2.0)\n write(*,*)x, log(x) ! will yield (approximately) 1\n write(*,*)z, log(z)\n end program demo_log\n", "meta": {"hexsha": "79ad3d9e02478b29de304378e777785fc276e710", "size": 235, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/log.f90", "max_stars_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_stars_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-12-31T17:21:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T15:56:29.000Z", "max_issues_repo_path": "example/log.f90", "max_issues_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_issues_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/log.f90", "max_forks_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_forks_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-06T15:56:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-06T15:56:31.000Z", "avg_line_length": 29.375, "max_line_length": 59, "alphanum_fraction": 0.5659574468, "num_tokens": 85, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525463, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7543217312245316}} {"text": "module SphereGeomModule\n!------------------------------------------------------------------------------\n! Lagrangian Particle / Panel Method - Spherical Model\n!------------------------------------------------------------------------------\n!\n!> @author\n!> Peter Bosler, Department of Mathematics, University of Michigan\n!\n!> @defgroup SphereGeom Spherical Geometry\n!> defines functions for performing geometric calculations on the surface of a sphere.\n!\n!\n! DESCRIPTION:\n!> @file\n!> defines functions for performing geometric calculations on the surface of a sphere.\n!\n!------------------------------------------------------------------------------\n\nuse NumberKindsModule\n\nimplicit none\n\npublic\n\ninterface SphereTriArea\n\tmodule procedure SphereTriAreaVector\n\tmodule procedure SphereTriAreaComponents\nend interface\n\ninterface SphereDistance\n\tmodule procedure SphereDistanceVector\n\tmodule procedure SphereDistanceComponents\nend interface\n\ninterface SphereArcLength\n\tmodule procedure SphereArcLengthVector\n\tmodule procedure SphereArcLengthComponents\nend interface\n\ninterface Latitude\n\tmodule procedure LatitudeVector\n\tmodule procedure LatitudeComponents\nend interface\n\ninterface Longitude\n\tmodule procedure LongitudeVector\n\tmodule procedure LongitudeComponents\n\tmodule procedure LongitudeComponents2\nend interface\n\ncontains\n\n!----------------\n! Basic geometry : length, area, coordinates, etc.\n!----------------\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Euclidean distance between two points on the sphere\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xyzA double precision real size(3); vector on the sphere\n!> @param[in] xyzB double precision real size(3); vector on the sphere\n!> @return Distance double precision real, straight-line distance between xyzA and xyzB\nfunction ChordDistance(xyzA, xyzB)\n\t! Outputs the Euclidean distance between two points in R3.\n\t! Units of length\n\treal(kreal), intent(in) :: xyzA(3), xyzB(3)\n\treal(kreal) :: ChordDistance\n\tChordDistance = sqrt( sum( (xyzB - xyzA)*(xyzB-xyzA) ) )\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Great-circle distance between two points in the plane\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xyzA double precision real size(3); vector on the sphere\n!> @param[in] xyzB double precision real size(3); vector on the sphere\n!> @return Distance double precision real, great-circle distance between xyzA and xyzB\n!------------------------------------------------------------------------------\nfunction SphereDistanceVector( xyzA, xyzB )\n! Finds the great circle distance between two points (xyzA and xyzB) on the sphere\n! Units of length\n\t! Calling parameters\n\treal(KREAL), dimension(3), intent(in) :: xyzA, xyzB\n\treal(KREAL) :: SphereDistanceVector\n\t! Local variables\n\treal(KREAL), dimension(3) :: crossProd\n\treal(KREAL) :: dotProd , crossNorm\n\n\tcrossProd = [xyzA(2)*xyzB(3)-xyzB(2)*xyzA(3),xyzB(1)*xyzA(3)-xyzA(1)*xyzB(3),&\n xyzA(1)*xyzB(2)-xyzB(1)*xyzA(2) ]\n\n crossNorm = sqrt(sum(crossProd*crossProd))\n\n dotProd = xyzA(1)*xyzB(1)+xyzA(2)*xyzB(2)+xyzA(3)*xyzB(3)\n\n SphereDistanceVector = atan2(crossNorm,dotProd)*EARTH_RADIUS\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Great-circle distance between two points in the plane\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xA double precision real \n!> @param[in] yA double precision real \n!> @param[in] zA\n!> @param[in] xB\n!> @param[in] yB\n!> @param[in] zB\n!> @return Distance double precision real, great-circle distance between xyzA and xyzB\n!------------------------------------------------------------------------------\nfunction SphereDistanceComponents(xA, yA, zA, xB, yB, zB)\n! Finds the great circle distance between two points (xyzA and xyzB) on the sphere\n! Units of length\n\treal(kreal), intent(in) :: xA, yA, zA\n\treal(kreal), intent(in) :: xB, yB, zB\n\treal(kreal) :: SphereDistanceComponents\n\treal(kreal) :: cp1, cp2, cp3, cpNorm, dp\n\n\tcp1 = yA*zB - yB*zA\n\tcp2 = xB*zA - xA*zB\n\tcp3 = xA*yB - xB*yA\n\n\tcpNorm = sqrt( cp1*cp1 + cp2*cp2 + cp3*cp3)\n\n\tdp = xA*xB + yA*yB + zA*zB\n\n\tSphereDistanceComponents = atan2(cpNorm,dp)*EARTH_RADIUS\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief central angle between two points in the plane\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xyzA double precision real size(3); vector on the sphere\n!> @param[in] xyzB double precision real size(3); vector on the sphere\n!> @return Distance double precision real, angular separation between xyzA and xyzB\n!------------------------------------------------------------------------------\nfunction SphereArcLengthVector(xyzA, xyzB)\n! returns the arc length between two vectors on the surface of a sphere.\n! dimensionless (angle)\n\t! Calling parameters\n\treal(KREAL), dimension(3), intent(in) :: xyzA, xyzB\n\treal(KREAL) :: SphereArcLengthVector\n\t! Local variables\n\treal(KREAL), dimension(3) :: crossProd\n\treal(KREAL) :: dotProd , crossNorm\n\n\tcrossProd = [xyzA(2)*xyzB(3)-xyzB(2)*xyzA(3),xyzB(1)*xyzA(3)-xyzA(1)*xyzB(3),&\n xyzA(1)*xyzB(2)-xyzB(1)*xyzA(2) ]\n\n crossNorm = sqrt(sum(crossProd*crossProd))\n\n dotProd = xyzA(1)*xyzB(1)+xyzA(2)*xyzB(2)+xyzA(3)*xyzB(3)\n\n SphereArcLengthVector = atan2(crossNorm,dotProd)\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief central angle between two points in the plane\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xA double precision real \n!> @param[in] yA double precision real \n!> @param[in] zA\n!> @param[in] xB\n!> @param[in] yB\n!> @param[in] zB\n!> @return Distance double precision real, angular separation between xyzA and xyzB\n!------------------------------------------------------------------------------\nfunction SphereArcLengthComponents(xA, yA, zA, xB, yB, zB)\n! dimensionless (angle)\n\treal(kreal), intent(in) :: xA, yA, zA\n\treal(kreal), intent(in) :: xB, yB, zB\n\treal(kreal) :: SphereArcLengthComponents\n\treal(kreal) :: cp1, cp2, cp3, cpNorm, dp\n\n\tcp1 = yA*zB - yB*zA\n\tcp2 = xB*zA - xA*zB\n\tcp3 = xA*yB - xB*yA\n\n\tcpNorm = sqrt( cp1*cp1 + cp2*cp2 + cp3*cp3)\n\n\tdp = xA*xB + yA*yB + zA*zB\n\n\tSphereArcLengthComponents = atan2(cpNorm,dp)\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief central angle between two points in the plane\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xyz double precision real size(3); vector on the sphere\n!> @return northward-pointing unit vector at position xyz\n!------------------------------------------------------------------------------\nfunction LatUnitVector(xyz)\n!\tReturns the latitudinal unit vector at the point xyz\n\treal(kreal) :: LatUnitVector(3)\n\treal(kreal), intent(in) :: xyz(3)\n\n\tif ( xyz(3) == 0.0_kreal) then\n\t\tLatUnitVector = [0.0_kreal,0.0_kreal,0.0_kreal]\n\telse\n\t\tLatUnitVector(1) = -xyz(1)*xyz(3)\n\t\tLatUnitVector(2) = -xyz(2)*xyz(3)\n\t\tLatUnitVector(3) = 1.0_kreal - xyz(3)*xyz(3)\n\n\t\tLatUnitVector = LatUnitVector / sqrt(LatUnitVector(3))\n\tendif\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief central angle between two points in the plane\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xyz double precision real size(3); vector on the sphere\n!> @return eastward-pointing unit vector at position xyz\n!-----------------------------------------------------------------------------\nfunction LonUnitVector(xyz)\n!\tReturns the Longitudinal unit vector at the point xyz\n\treal(kreal) :: LonUnitVector(3)\n\treal(kreal), intent(in) :: xyz(3)\n\n\tif ( xyz(3) == 0.0_kreal) then\n\t\tLonUnitVector = [0.0_kreal,0.0_kreal,0.0_kreal]\n\telse\n\t\tLonUnitVector(1) = -xyz(2)\n\t\tLonUnitVector(2) = -xyz(1)\n\t\tLonUnitVector(3) = 0.0_kreal\n\n\t\tLonUnitVector = LonUnitVector / sqrt( 1.0_kreal - xyz(3)*xyz(3))\n\tendif\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief midpoint of a great-circle segment connecting two points on the sphere\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xyzA double precision real size(3); vector on the sphere\n!> @param[in] xyzB double precision real size(3); vector on the sphere\n!> @return Midpoint vector\n!------------------------------------------------------------------------------\nfunction SphereMidpoint(xyzA, xyzB)\n! Finds the midpoint of two points on the sphere by finding the midpoint of the chord\n! connecting the two points, then projecting the chord midpoint to the sphere.\n\t! Calling parameters\n\treal(KREAL), dimension(3), intent(in) :: xyzA, xyzB\n\treal(KREAL), dimension(3) :: SphereMidpoint\n\n\tSphereMidpoint = (xyzA + xyzB)/2.0_KREAL\n\tSphereMidpoint = SphereMidpoint/sqrt(sum(sphereMidpoint*sphereMidpoint))*EARTH_RADIUS\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Finds the centroid of a spherical triangle defined by three vertices\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xyzA double precision real size(3); vector on the sphere\n!> @param[in] xyzB double precision real size(3); vector on the sphere\n!> @param[in] xyzC double precision real size(3); vector on the sphere\n!> @return centroid vector\n!------------------------------------------------------------------------------\nfunction SphereTriCenter(xyzA, xyzB, xyzC)\n! Finds the midpoint of three points on the sphere by find their average position in Cartesian\n! coordinates, then projecting that average onto the sphere.\n\t! Calling parameters\n\treal(KREAL), dimension(3), intent(in) :: xyzA, xyzB, xyzC\n\treal(KREAL), dimension(3) :: SphereTriCenter\n\n\tSphereTriCenter = (xyzA + xyzB + xyzC)/3.0_KREAL\n\tSphereTriCenter = SphereTriCenter/sqrt(sum(sphereTriCenter*sphereTriCenter))*EARTH_RADIUS\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Finds the centroid of a spherical quadrilateral defined by four vertices\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xyzA double precision real size(3); vector on the sphere\n!> @param[in] xyzB double precision real size(3); vector on the sphere\n!> @param[in] xyzC double precision real size(3); vector on the sphere\n!> @param[in] xyzD double precision real size(3); vector on the sphere\n!> @return centroid vector\n!------------------------------------------------------------------------------\nfunction SphereQuadCenter(xyzA, xyzB, xyzC, xyzD)\n! Finds the midpoint of four points on the sphere by finding their average position in\n! Cartesian coordinates, then projecting that average onto the sphere.\n\t! Calling parameters\n\treal(KREAL), dimension(3), intent(in) :: xyzA, xyzB, xyzC, xyzD\n\treal(KREAL), dimension(3) :: sphereQuadCenter\n\n\tSphereQuadCenter = (xyzA + xyzB + xyzC + xyzD)/4.0_KREAL\n\tSphereQuadCenter = SphereQuadCenter/sqrt(sum(sphereQuadCenter*sphereQuadCenter))*EARTH_RADIUS\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Finds the area of a spherical triangle defined by three vertices\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xyzA double precision real size(3); vector on the sphere\n!> @param[in] xyzB double precision real size(3); vector on the sphere\n!> @param[in] xyzC double precision real size(3); vector on the sphere\n!> @return scalar area\n!------------------------------------------------------------------------------\nfunction SphereTriAreaVector(xyzA, xyzB, xyzC)\n! Calculates the area of a spherical triangle on the unit sphere\n! NOTE : This function requires function sphereDistance.\n\t! Calling parameters\n\treal(KREAL), dimension(3), intent(in) :: xyzA, xyzB, xyzC\n\treal(KREAL) :: SphereTriAreaVector\n\t! Local variables\n\treal(KREAL) :: side1, side2, side3, halfPerimeter, zz\n\n\tside1 = SphereArcLength(xyzA,xyzB)\n\tside2 = SphereArcLength(xyzB,xyzC)\n\tside3 = SphereArcLength(xyzC,xyzA)\n\n\thalfPerimeter = (side1 + side2 + side3)/2.0_KREAL\n\n\tzz = tan(halfPerimeter/2.0_KREAL)*tan( (halfPerimeter-side1)/2.0_KREAL )*&\n\t\ttan( (halfPerimeter - side2)/2.0_KREAL )*tan( (halfPerimeter - side3)/2.0_KREAL )\n\n\tSphereTriAreaVector = 4.0_KREAL * atan2(sqrt(zz),1.0_KREAL)*EARTH_RADIUS*EARTH_RADIUS\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Finds the area of a spherical triangle defined by three vertices\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xA double precision real \n!> @param[in] yA double precision real \n!> @param[in] zA\n!> @param[in] xB\n!> @param[in] yB\n!> @param[in] zB\n!> @param[in] xC\n!> @param[in] yC\n!> @param[in] zC\n!> @return scalar area\n!------------------------------------------------------------------------------\nfunction SphereTriAreaComponents(xa,ya,za, xb,yb,zb, xc,yc,zc)\n\treal(kreal), intent(in) :: xa,ya,za\n\treal(kreal), intent(in) :: xb,yb,zb\n\treal(kreal), intent(in) :: xc,yc,zc\n\treal(kreal) :: SphereTriAreaComponents\n\treal(kreal) :: s1,s2,s3, halfPerim, zz\n\n\ts1 = SphereArcLengthComponents(xa,ya,za,xb,yb,zb)\n\ts2 = SphereArcLengthComponents(xb,yb,zb,xc,yc,zc)\n\ts3 = SphereArcLengthComponents(xc,yc,zc,xa,ya,za)\n\n\thalfPerim = (s1+s2+s3)/2.0_kreal\n\tzz = tan( halfPerim/2.0_kreal)*tan( (halfPerim-s1)/2.0_kreal) * &\n\t\t tan( (halfPerim-s2)/2.0_kreal)*tan( (halfPerim-s3)/2.0_kreal)\n\n\tSphereTriAreaComponents = 4.0_kreal*atan(sqrt(zz))*EARTH_RADIUS*EARTH_RADIUS\nend function\n\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Finds the area of a planar triangle defined by three vertices\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xyzA double precision real size(3); vector on the sphere\n!> @param[in] xyzB double precision real size(3); vector on the sphere\n!> @param[in] xyzC double precision real size(3); vector on the sphere\n!> @return scalar area\n!------------------------------------------------------------------------------\nfunction PlaneTriArea(xyzA,xyzB,xyzC)\n\t! Outputs the area of a planar triangle in R3 with vertices xyzA,B,C.\n\treal(kreal) :: PlaneTriArea\n\treal(kreal), intent(in) :: xyzA(3), xyzB(3), xyzC(3)\n\tPlaneTriArea = crossMagnitude( xyzB-xyzA, xyzC-xyzA)/2.0_kreal\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Finds the longitude of a point on the sphere\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xyz double precision real size(3); vector on the sphere in Cartesian coordinates\n!> @return Longitude of xyz\n!------------------------------------------------------------------------------\nfunction longitudeVector(xyz)\n\t! Outputs the longitude of a point on the sphere.\n\treal(KREAL) :: longitudeVector\n\treal(KREAL), intent(in) :: xyz(3)\n\tlongitudeVector = atan4(xyz(2),xyz(1))\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Finds the longitude of a point on the sphere\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xyz double precision real size(3); vector on the sphere in Cartesian coordinates\n!> @return Longitude of xyz\n!------------------------------------------------------------------------------\nfunction LongitudeComponents(x,y,z)\n\treal(kreal), intent(in) :: x, y, z\n\treal(kreal) :: LongitudeComponents\n\tLongitudeComponents = atan4(y,x)\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Finds the longitude of a point on the sphere\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xyz double precision real size(3); vector on the sphere in Cartesian coordinates\n!> @return Longitude of xyz\n!------------------------------------------------------------------------------\nfunction LongitudeComponents2(x,y)\n\treal(kreal), intent(in) :: x, y\n\treal(kreal) :: LongitudeComponents2\n\tLongitudeCOmponents2 = atan4(y,x)\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Finds the latitude of a point on the sphere\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xyz double precision real size(3); vector on the sphere in Cartesian coordinates\n!> @return Latitude of xyz\n!------------------------------------------------------------------------------\nfunction latitudeVector(xyz)\n\t! Outputs the latitude of a point on the unit sphere.\n\treal(KREAL) :: latitudeVector\n\treal(KREAL), intent(in) :: xyz(3)\n\tlatitudeVector = atan2(xyz(3),sqrt(xyz(1)**2 + xyz(2)**2))\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Finds the latitude of a point on the sphere\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xyz double precision real size(3); vector on the sphere in Cartesian coordinates\n!> @return Latitude of xyz\n!------------------------------------------------------------------------------\nfunction LatitudeComponents(x,y,z)\n\treal(kreal), intent(in) :: x, y, z\n\treal(kreal) :: LatitudeComponents\n\tLatitudeComponents = atan2(z,sqrt(x*x+y*y))\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief A 4-quadrant inverse tangent function with range 0 to 2*pi instead of -pi to pi.\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] y double precision real\n!> @param[in] x double precision real\n!> @return atan(y/x) in range 0 to 2*pi\n!------------------------------------------------------------------------------\nfunction atan4(y,x)\n\t!This function computes the inverse tangent (like atan2) but outputs angles in the range\n\t! 0 to 2 pi (rather than -pi to pi).\n\t! Adapted from John Burkhardt: http://people.sc.fsu.edu/~jburkhardt/m_src/halton/atan4.m\n\treal(kreal), intent(in) :: y,x\n\treal(kreal) :: atan4\n\treal(kreal) :: absY, absX, theta\n\tif ( x == 0.0_kreal) then\n\t\tif ( y > 0.0_kreal) then\n\t\t\tatan4 = PI/2.0_kreal\n\t\telseif ( y < 0.0_kreal) then\n\t\t\tatan4 = 3.0_kreal*PI/2.0_kreal\n\t\telseif ( y == 0.0_kreal) then\n\t\t\tatan4 = 0.0_kreal\n\t\tendif\n\telseif ( y == 0.0_kreal) then\n\t\tif ( x > 0.0_kreal) then\n\t\t\tatan4 = 0.0_kreal\n\t\telseif ( x < 0.0_kreal) then\n\t\t\tatan4 = PI\n\t\tendif\n\telse\n\t\tabsY = abs(y)\n\t\tabsX = abs(x)\n\t\ttheta = atan2(absY,absX)\n\t\tif ( (x>0.0_kreal) .and. (y>0.0_kreal)) then\n\t\t\tatan4 = theta\n\t\telseif ( (x < 0.0_kreal) .and. (y > 0.0_kreal)) then\n\t\t\tatan4 = pi -theta\n\t\telseif ( (x < 0.0_kreal) .and. (y < 0.0_kreal)) then\n\t\t\tatan4 = pi+ theta\n\t\telseif ( (x > 0.0_kreal) .and. (y<0.0_kreal)) then\n\t\t\tatan4 = 2.0_kreal*PI - theta\n\t\tendif\n\tendif\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Magnitude of the vector xyzA X xyzB\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xyzA double precision real size(3)\n!> @param[in] xyzB double precision real size(3)\n!> @return |xyzA x xyzB|\n!------------------------------------------------------------------------------\nfunction crossMagnitude(xyzA,xyzB)\n\t! Computes the magnitude of xyzA cross xyzB\n\treal(kreal) :: crossMagnitude\n\treal(kreal), intent(in) :: xyzA(3), xyzB(3)\n\tcrossMagnitude = sqrt( (xyzA(2)*xyzB(3) - xyzA(3)*xyzB(2))*(xyzA(2)*xyzB(3) - xyzB(2)*xyzA(3)) + &\n\t \t\t\t\t\t (xyzA(3)*xyzB(1) - xyzA(1)*xyzB(3))*(xyzA(3)*xyzB(1) - xyzA(1)*xyzB(3)) + &\n\t \t\t\t\t\t (xyzA(1)*xyzB(2) - xyzA(2)*xyzB(1))*(xyzA(1)*xyzB(2) - xyzA(2)*xyzB(1)))\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Computes a vector cross product \n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xyzA double precision real size(3)\n!> @param[in] xyzB double precision real size(3)\n!> @return xyzA x xyzB double precision real size(3)\n!------------------------------------------------------------------------------\nfunction crossProduct(xyzA,xyzB)\n\t! Computes the cross product vector xyzA cross xyzB\n\treal(kreal) :: crossProduct(3)\n\treal(kreal), intent(in) :: xyzA(3), xyzB(3)\n\tcrossProduct(1) = xyzA(2)*xyzB(3) - xyzA(3)*xyzB(2)\n\tcrossProduct(2) = xyzA(3)*xyzB(1) - xyzA(1)*xyzB(3)\n\tcrossProduct(3) = xyzA(1)*xyzB(2) - xyzA(2)*xyzB(1)\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Computes a vector triple product\n!\n!> @ingroup SphereGeom\n!\n!> @param[in] xA double precision real size(3)\n!> @param[in] xB double precision real size(3)\n!> @param[in] xC double precision real size(3)\n!> @return \\f$ x_A \\cdot (x_b \\times x_c) $\\f double precision real size(3)\n!------------------------------------------------------------------------------\nfunction Determinant(xA,xB,xC)\n\t! Computes the vector determinant (triple product) of xA, xB, and xC\n\t! This result will be positive if xA lies to the left of the directed arc\n\t! xB to xC, and negative if xA lies to the right of the arc xB->xC.\n\treal(kreal) :: Determinant\n\treal(kreal), intent(in) :: xA(3), xB(3), xC(3)\n\treal(kreal) :: cross(3)\n\tcross = CrossProduct(xB,xC)\n\tDeterminant = sum(xA*cross)\nend function\n\n!------------------------------------------------------------------------------\n!> @author Peter Bosler\n!> @brief Generates a random point on the surface of a sphere\n!\n!> @ingroup SphereGeom\n!\n!> @return random vector satisfying x^2 + y^2 + z^2 = R^2\n!------------------------------------------------------------------------------\nfunction RandomSpherePoint()\n\t! Outputs a random point on the unit sphere.\n\t! Note : the seed is not initialized, so each sequence of\n\t! random points will be the same.\n\treal(kreal) :: RandomSpherePoint(3)\n\treal(kreal) :: x, y, z\n\t!call Random_Seed()\n\tcall Random_Number(x)\n\tcall Random_Number(y)\n\tcall Random_Number(z)\n\tx = -1.0_kreal + 2.0_kreal*x\n\ty = -1.0_kreal + 2.0_kreal*y\n\tz = -1.0_kreal + 2.0_kreal*z\n\tRandomSpherePoint(1) = x\n\tRandomSpherePoint(2) = y\n\tRandomSpherePoint(3) = z\n\tRandomSpherePoint = RandomSpherePoint/sqrt(sum(RandomSpherePoint*RandomSpherePoint))*EARTH_RADIUS\nend function\n\nsubroutine NormalizePositionVectors(xyz)\n\treal(kreal), intent(inout) :: xyz(:,:)\n\tinteger(kint) :: j, n\n!\treal(kreal) :: norm\n\tif ( size(xyz,1) /= 3) stop 'ERROR : position vector array shape error.'\n\tn = size(xyz,2)\n\tdo j=1,n\n\t\txyz(:,j) = xyz(:,j)/(sqrt(sum(xyz(:,j)*xyz(:,j))))*EARTH_RADIUS\n\tenddo\nend subroutine\n\n\n!function NorthPoleRotationMatrix(xyz)\n!! returns a rotation matrix R so that R*x = (0,0,1)^T\n!\treal(kreal) :: NorthPoleRotationMatrix(3,3)\n!\treal(kreal), intent(in) :: xyz(3)\n!\treal(kreal) :: cy, sy, cx, sx\n!\n!\tcy = sqrt(xyz(2)*xyz(2) + xyz(3)*xyz(3))\n!\tsy = xyz(1)\n!\n!\tif (abs(cy) > ZERO_TOL) then\n!\t\tcx = xyz(3)/cy\n!\t\tsx = xyz(2)/cy\n!\telse\n!\t\tcx = 1.0_kreal\n!\t\tsx = 0.0_kreal\n!\tendif\n!\n!\tNorthPoleRotationMatrix(1,1) = cy\n!\tNorthPoleRotationMatrix(2,1) = 0.0_kreal\n!\tNorthPoleRotationMatrix(3,1) = sy\n!\n!\tNorthPoleRotationMatrix(1,2) = -sx*sy\n!\tNorthPoleRotationMatrix(2,2) = cx\n!\tNorthPoleRotationMatrix(3,2) = cy*sx\n!\n!\tNorthPoleRotationMatrix(1,3) = -cx*sy\n!\tNorthPoleRotationMatrix(2,3) = -sx\n!\tNorthPoleRotationMatrix(3,3) = cx*cy\n!\n!end function\n\nend module\n", "meta": {"hexsha": "98b6cf944139119208d088aa912bd2559b262628", "size": 23152, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SphereGeom3.f90", "max_stars_repo_name": "pbosler/LPPM", "max_stars_repo_head_hexsha": "33b9572120ceca28ee56630a1af54f3befbda672", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SphereGeom3.f90", "max_issues_repo_name": "pbosler/LPPM", "max_issues_repo_head_hexsha": "33b9572120ceca28ee56630a1af54f3befbda672", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2015-01-21T21:50:20.000Z", "max_issues_repo_issues_event_max_datetime": "2015-01-21T21:54:31.000Z", "max_forks_repo_path": "archive/SphereGeom3.f90", "max_forks_repo_name": "pbosler/LPPM", "max_forks_repo_head_hexsha": "33b9572120ceca28ee56630a1af54f3befbda672", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.2926829268, "max_line_length": 99, "alphanum_fraction": 0.5971406358, "num_tokens": 6397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850021922959, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7543013358264988}} {"text": "submodule (maptran) ecef\n\nimplicit none (type, external)\n\ncontains\n\nmodule procedure ecef2geodetic\n!! convert ECEF (meters) to geodetic coordintes\n!!\n!! based on:\n!! You, Rey-Jer. (2000). Transformation of Cartesian to Geodetic Coordinates without Iterations.\n!! Journal of Surveying Engineering. doi: 10.1061/(ASCE)0733-9453\n\nreal(wp) :: ea, eb, r, E, u, Q, huE, Beta, eps, sinBeta, cosBeta\ntype(Ellipsoid) :: ell\nlogical :: d, inside\n\nell = wgs84Ellipsoid\nif (present(spheroid)) ell = spheroid\n\nea = ell%SemimajorAxis\neb = ell%SemiminorAxis\n\nr = sqrt(x**2 + y**2 + z**2)\n\nE = sqrt(ea**2 - eb**2)\n\n! eqn. 4a\nu = sqrt(0.5 * (r**2 - E**2) + 0.5 * sqrt((r**2 - E**2)**2 + 4 * E**2 * z**2))\n\nQ = hypot(x, y)\n\nhuE = hypot(u, E)\n\n!> eqn. 4b\nBeta = atan2(huE / u * z, hypot(x, y))\n\n!> final output\nif (abs(beta-pi/2) <= epsilon(beta)) then !< singularity\n lat = pi/2\n cosBeta = 0\n sinBeta = 1\nelseif (abs(beta+pi/2) <= epsilon(beta)) then !< singularity\n lat = -pi/2\n cosBeta = 0\n sinBeta = -1\nelse\n !> eqn. 13\n eps = ((eb * u - ea * huE + E**2) * sin(Beta)) / (ea * huE * 1 / cos(Beta) - E**2 * cos(Beta))\n Beta = Beta + eps\n\n lat = atan(ea / eb * tan(Beta))\n cosBeta = cos(Beta)\n sinBeta = sin(Beta)\nendif\n\nlon = atan2(y, x)\n\n! eqn. 7\nif (present(alt)) then\n alt = hypot(z - eb * sinBeta, Q - ea * cosBeta)\n\n !> inside ellipsoid?\n inside = x**2 / ea**2 + y**2 / ea**2 + z**2 / eb**2 < 1._wp\n if (inside) alt = -alt\nendif\n\n\nd=.true.\nif (present(deg)) d = deg\n\nif (d) then\n lat = degrees(lat)\n lon = degrees(lon)\nendif\n\nend procedure ecef2geodetic\n\n\nmodule procedure geodetic2ecef\n!! # geodetic2ecef\n!! convert from geodetic to ECEF coordiantes\n!!\n!! ## Inputs\n!!\n!! * lat,lon, alt: ellipsoid geodetic coordinates of point(s) (degrees, degrees, meters)\n!! * spheroid: Ellipsoid parameter struct\n!! * deg: .true. degrees\n!!\n!! ## outputs\n!!\n!! * x,y,z: ECEF coordinates of test point(s) (meters)\n\nreal(wp) :: N, sinLat, cosLat, cosLon, sinLon, lat, lon\ntype(Ellipsoid) :: ell\nlogical :: d\n\nd = .true.\nif (present(deg)) d = deg\n\nell = wgs84Ellipsoid\nif (present(spheroid)) ell = spheroid\n\nlat = llat\nlon = llon\nif (d) then\n lat = radians(lat)\n lon = radians(lon)\nendif\n\n!> Radius of curvature of the prime vertical section\nN = radius_normal(lat, ell)\n\n!! Compute cartesian (geocentric) coordinates given (curvilinear) geodetic coordinates.\n\n!> singularities. Benchmark shows nearly zero runtime impact of these if statements for any real precision\nif (abs(lat) <= epsilon(lat)) then\n cosLat = 1\n sinLat = 0\nelseif (abs(lat-pi/2) <= epsilon(lat)) then\n cosLat = 0\n sinLat = 1\nelseif (abs(lat+pi/2) <= epsilon(lat)) then\n cosLat = 0\n sinLat = -1\nelse\n cosLat = cos(lat)\n sinLat = sin(lat)\nendif\n\nif (abs(lon) <= epsilon(lon)) then\n cosLon = 1\n sinLon = 0\nelseif (abs(lon-pi/2) <= epsilon(lon)) then\n cosLon = 0\n sinLon = 1\nelseif (abs(lon+pi/2) <= epsilon(lon)) then\n cosLon = 0\n sinLon = -1\nelseif (abs(lon+pi) <= epsilon(lon) .or. abs(lon-pi) <= epsilon(lon)) then\n cosLon = -1\n sinLon = 0\nelse\n cosLon = cos(lon)\n sinLon = sin(lon)\nendif\n\nx = (N + alt) * cosLat * cosLon\ny = (N + alt) * cosLat * sinLon\nz = (N * (ell%SemiminorAxis / ell%SemimajorAxis)**2 + alt) * sinLat\n\nend procedure geodetic2ecef\n\n\nmodule procedure enu2ecef\n! enu2ecef convert from ENU to ECEF coordiantes\n!\n! Inputs\n! ------\n! e,n,u: East, North, Up coordinates of test points (meters)\n! lat0, lon0, alt0: ellipsoid geodetic coordinates of observer/reference (degrees, degrees, meters)\n! spheroid: Ellipsoid parameter struct\n! angleUnit: string for angular units. Default 'd': degrees\n!\n! outputs\n! -------\n! x,y,z: Earth Centered Earth Fixed (ECEF) coordinates of test point (meters)\n\nreal(wp) :: x0,y0,z0,dx,dy,dz\n\ncall geodetic2ecef(lat0, lon0, alt0, x0, y0, z0, spheroid, deg)\ncall enu2uvw(e, n, u, lat0, lon0, dx, dy, dz, deg)\n\n x = x0 + dx\n y = y0 + dy\n z = z0 + dz\nend procedure enu2ecef\n\n\nmodule procedure ecef2enu\n!! ecef2enu convert ECEF to ENU\n!!\n!! ## Inputs\n!!\n!! * x,y,z: Earth Centered Earth Fixed (ECEF) coordinates of test point (meters)\n!! * lat0, lon0, alt0: ellipsoid geodetic coordinates of observer/reference (degrees, degrees, meters)\n!! * spheroid: Ellipsoid parameter struct\n!! * angleUnit: string for angular units. Default 'd': degrees\n!!\n!! ## outputs\n!!\n!! * e,n,u: East, North, Up coordinates of test points (meters)\n\nreal(wp) :: x0,y0,z0\n\ncall geodetic2ecef(lat0, lon0, alt0, x0,y0,z0, spheroid,deg)\ncall ecef2enuv(x - x0, y - y0, z - z0, lat0, lon0, east, north, up, deg)\nend procedure ecef2enu\n\n\nmodule procedure ecef2enuv\n!! ecef2enuv convert *vector projection* UVW to ENU\n!!\n!! ## Inputs\n!!\n!! * u,v,w: meters\n!! * lat0,lon0: geodetic latitude and longitude (degrees)\n!! * deg: .true. degrees\n!!\n!! ## Outputs\n!!\n!! * east,north,Up: East, North, Up vector\n\nreal(wp) :: t, lat0, lon0\nlogical :: d\n\nd=.true.\nif (present(deg)) d = deg\n\nlat0 = llat0\nlon0 = llon0\nif (d) then\n lat0 = radians(lat0)\n lon0 = radians(lon0)\nendif\n\nt = cos(lon0) * u + sin(lon0) * v\neast = -sin(lon0) * u + cos(lon0) * v\nup = cos(lat0) * t + sin(lat0) * w\nnorth = -sin(lat0) * t + cos(lat0) * w\nend procedure ecef2enuv\n\n\nelemental real(wp) function radius_normal(lat,E)\n\nreal(wp), intent(in) :: lat\ntype(Ellipsoid), intent(in) :: E\n\n!> singularity pi/2 issue is inherent to real32\nif (abs(lat) <= epsilon(lat)) then\n radius_normal = E%SemimajorAxis\nelse\n radius_normal = E%SemimajorAxis**2 / sqrt( E%SemimajorAxis**2 * cos(lat)**2 + E%SemiminorAxis**2 * sin(lat)**2 )\nendif\n\nend function radius_normal\n\nend submodule ecef\n", "meta": {"hexsha": "1d502110863daeb9f3389802a1813c200a439240", "size": 5557, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ecef.f90", "max_stars_repo_name": "geospace-code/maptran3d", "max_stars_repo_head_hexsha": "c41e12171ac5a87ba6ab497a3d8b1cf2cddd2a58", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-07-24T23:22:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-10T09:36:56.000Z", "max_issues_repo_path": "src/ecef.f90", "max_issues_repo_name": "geospace-code/maptran3d", "max_issues_repo_head_hexsha": "c41e12171ac5a87ba6ab497a3d8b1cf2cddd2a58", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/ecef.f90", "max_forks_repo_name": "geospace-code/maptran3d", "max_forks_repo_head_hexsha": "c41e12171ac5a87ba6ab497a3d8b1cf2cddd2a58", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-31T08:55:13.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-31T08:55:13.000Z", "avg_line_length": 22.3172690763, "max_line_length": 114, "alphanum_fraction": 0.6517905345, "num_tokens": 1993, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7543010135424391}} {"text": "!##############################################################################\n!# Tutorial 005c: Basic linear algebra\n!##############################################################################\n\nmodule tutorial005c\n\n ! Include basic Feat-2 modules\n use fsystem\n use genoutput\n use linearalgebra\n\n implicit none\n private\n \n public :: start_tutorial005c\n\ncontains\n\n ! ***************************************************************************\n\n subroutine start_tutorial005c\n \n ! Declare some variables\n real(DP), dimension(4) :: Dvec1, Dvec2, Dvec3, Dvec4, Dvec\n integer, dimension(4) :: Iperm\n real(DP) :: d\n integer :: i\n\n ! Print a message\n call output_lbrk()\n call output_separator (OU_SEP_STAR)\n call output_line (\"This is FEAT-2. Tutorial 005c\")\n call output_separator (OU_SEP_MINUS)\n \n ! =================================\n ! Initialise vectors\n ! =================================\n \n Dvec1 = (/ 1.0_DP, 2.0_DP, 3.0_DP, 4.0_DP /)\n Dvec2 = (/ -1.0_DP, 1.0_DP, -1.0_DP, 1.0_DP /)\n Dvec3 = (/ 0.0_DP, 0.0_DP, 1.0_DP, 0.0_DP /)\n Dvec4 = (/ 2.0_DP,-1.0_DP, 0.0_DP, 0.0_DP /)\n \n ! =================================\n ! Clear\n ! Dvec = 0\n ! =================================\n \n call lalg_clearVector (Dvec)\n\n do i=1,4\n call output_line (\" \" // sys_sdL(Dvec(i),2), bnolinebreak=(i .ne. 4) )\n end do\n\n ! =================================\n ! Set to constant\n ! Dvec = (1,1,1,1)\n ! =================================\n \n call lalg_setVector (Dvec,1.0_DP)\n\n do i=1,4\n call output_line (\" \" // sys_sdL(Dvec(i),2), bnolinebreak=(i .ne. 4) )\n end do\n\n ! =================================\n ! Copy and scale:\n ! Dvec = 2*Dvec1\n ! =================================\n \n call lalg_copyVector (Dvec1, Dvec)\n call lalg_scaleVector (Dvec, 2.0_DP)\n\n do i=1,4\n call output_line (\" \" // sys_sdL(Dvec(i),2), bnolinebreak=(i .ne. 4) )\n end do\n \n ! =================================\n ! Linear combination.\n ! Dvec = Dvec1 - (1,1,1,1)\n ! =================================\n \n call lalg_setVector (Dvec,1.0_DP)\n call lalg_vectorLinearComb (Dvec1,Dvec,1.0_DP,-1.0_DP)\n\n do i=1,4\n call output_line (\" \" // sys_sdL(Dvec(i),2), bnolinebreak=(i .ne. 4) )\n end do\n\n ! =================================\n ! Add constant\n ! Dvec = Dvec1 - (1,1,1,1)\n ! =================================\n \n call lalg_copyVector (Dvec1,Dvec)\n call lalg_vectorAddScalar (Dvec,-1.0_DP)\n\n do i=1,4\n call output_line (\" \" // sys_sdL(Dvec(i),2), bnolinebreak=(i .ne. 4) )\n end do\n\n ! =================================\n ! Sort vector backwards,\n ! Dvec = back(Dvec4)\n ! =================================\n \n Iperm = (/ 4, 3, 2, 1 /)\n call lalg_vectorSort (Dvec4, Dvec, Iperm)\n\n do i=1,4\n call output_line (\" \" // sys_sdL(Dvec(i),2), bnolinebreak=(i .ne. 4) )\n end do\n\n ! =================================\n ! Scalar product\n ! result = < Dvec2, Dvec3 >\n ! =================================\n \n d = lalg_scalarProduct(Dvec2,Dvec3)\n \n call output_line (\" = \" // sys_sdL(d,2) )\n\n ! =================================\n ! Different norms\n ! result = || Dvec4 || \n ! =================================\n \n ! SUM\n d = lalg_norm(Dvec4,LINALG_NORMSUM)\n call output_line (\"||vec4||_SUM = \" // sys_sdL(d,2) )\n\n ! Euclid-norm\n d = lalg_norm(Dvec4,LINALG_NORMEUCLID)\n call output_line (\"||vec4||_2 = \" // sys_sdL(d,2) )\n\n ! L1-norm\n d = lalg_norm(Dvec4,LINALG_NORML1)\n call output_line (\"||vec4||_l1 = \" // sys_sdL(d,2) )\n\n ! L2-norm\n d = lalg_norm(Dvec4,LINALG_NORML2)\n call output_line (\"||vec4||_l2 = \" // sys_sdL(d,2) )\n\n ! MAX-norm\n d = lalg_norm(Dvec4,LINALG_NORMMAX)\n call output_line (\"||vec4||_MAX = \" // sys_sdL(d,2) )\n\n end subroutine\n\nend module\n", "meta": {"hexsha": "8de6f2bf6bedb56621647c620aa327ed5a97629a", "size": 3972, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tutorials/tutorial01/src/tutorial005c.f90", "max_stars_repo_name": "trmcnealy/Featflow2", "max_stars_repo_head_hexsha": "4af17507bc2d80396bf8ea85c9e30e9e4d2383df", "max_stars_repo_licenses": ["Intel", "Unlicense"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-08-02T11:51:34.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-10T14:14:21.000Z", "max_issues_repo_path": "tutorials/tutorial01/src/tutorial005c.f90", "max_issues_repo_name": "tudo-math-ls3/FeatFlow2", "max_issues_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_issues_repo_licenses": ["Intel", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tutorials/tutorial01/src/tutorial005c.f90", "max_forks_repo_name": "tudo-math-ls3/FeatFlow2", "max_forks_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_forks_repo_licenses": ["Intel", "Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.3046357616, "max_line_length": 79, "alphanum_fraction": 0.4400805639, "num_tokens": 1228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320035, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7543009980582164}} {"text": "!##############################################################################\n! PROGRAM MC_Option_Pricing\n!\n! ## Option pricing with Monte Carlo simulations - Asian options\n!\n! This code is published under the GNU General Public License v3\n! (https://www.gnu.org/licenses/gpl-3.0.en.html)\n!\n! Authors: Hans Fehr and Fabian Kindermann\n! contact@ce-fortran.com\n!\n! #VC# VERSION: 1.0 (23 January 2018)\n!\n!##############################################################################\nprogram MC_Option_Pricing\n\n use toolbox\n\n implicit none\n real*8, parameter :: Del_TT = 62d0/250d0 ! exercise date (in annualized values)\n real*8, parameter :: S_0 = 25d0 ! initial stock price\n real*8, parameter :: r = 0.04d0 ! annual interest rate\n real*8, parameter :: sigma = 0.10d0 ! standard deviation of stock returns\n real*8, parameter :: KK = 25d0 ! strike price\n integer, parameter :: TT = 200 ! number of sub-periods\n integer, parameter :: JJ = 20000 ! maximum number of simulation paths\n\n real*8 :: S(0:TT), z(TT), del_t\n real*8 :: S_bar, pi_c(JJ), pi_p(JJ)\n real*8 :: c_AS(JJ), p_AS(JJ), npaths(JJ)\n integer :: ij, it\n\n ! get length of sub-periods\n del_t = Del_TT/dble(TT)\n\n ! simulate price paths and corresponding profits\n do ij = 1, JJ\n\n ! generate a price path\n call simulate_normal(z, 0d0, 1d0)\n S(0) = S_0\n do it = 1, TT\n S(it) = S(it-1)*exp((r-sigma**2/2d0)*del_t + sigma*sqrt(del_t)*z(it))\n enddo\n\n ! get average stock price\n S_bar = 0\n do it = 1, TT\n S_bar = S_bar + S(it)\n enddo\n S_bar = S_bar/dble(TT)\n\n ! calculate associated payoff\n pi_c(ij) = max(S_bar - KK, 0d0)\n pi_p(ij) = max(KK - S_bar, 0d0)\n enddo\n\n ! use different number of paths to compute premium\n do ij = 1, JJ\n c_AS(ij) = exp(-r*Del_TT)*sum(pi_c(1:ij))/dble(ij)\n p_AS(ij) = exp(-r*Del_TT)*sum(pi_p(1:ij))/dble(ij)\n npaths(ij) = dble(ij)\n enddo\n\n ! plot option price as a function of number of paths used\n call plot(npaths(1:10000), c_AS(1:10000), legend='Asian Call Option')\n call plot(npaths(1:10000), p_AS(1:10000), legend='Asian Put Option')\n call execplot()\n\n write(*,'(a)')'OPTION PRICING USING MC SIMULATION'\n write(*,'(a, f12.5)')'Call Price = ', c_AS(JJ)\n write(*,'(a, f12.5)')'Put Price = ', p_AS(JJ)\n\nend program\n", "meta": {"hexsha": "41f8e9a17ced2db643a609ebc2d80248116dc3a5", "size": 2526, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog04/prog04_05/prog04_05.f90", "max_stars_repo_name": "aswinvk28/modflow_fortran", "max_stars_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "complete/prog04/prog04_05/prog04_05.f90", "max_issues_repo_name": "aswinvk28/modflow_fortran", "max_issues_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "complete/prog04/prog04_05/prog04_05.f90", "max_forks_repo_name": "aswinvk28/modflow_fortran", "max_forks_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-07T12:27:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-07T12:27:47.000Z", "avg_line_length": 33.68, "max_line_length": 87, "alphanum_fraction": 0.5455265241, "num_tokens": 770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920387, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7542775273733315}} {"text": "! { dg-do compile }\n! Testcase from PR 25396: User defined operators returning arrays.\nmodule geometry\n\n implicit none\n\n interface operator(.cross.)\n module procedure cross\n end interface\n\ncontains\n\n ! Cross product between two 3d vectors.\n pure function cross(a, b)\n real, dimension(3), intent(in) :: a,b\n real, dimension(3) :: cross\n\n cross = (/ a(2) * b(3) - a(3) * b(2), &\n a(3) * b(1) - a(1) * b(3), &\n a(1) * b(2) - a(2) * b(1) /)\n end function cross\n\nend module geometry\n\nprogram opshape\n use geometry\n\n implicit none\n\n real :: t(3,3), a\n\n a = dot_product (t(:,1), t(:,2) .cross. t(:,3))\n\nend program opshape\n", "meta": {"hexsha": "bf965e5f7093a3f07502feaa9bedb1599a83defa", "size": 670, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/userdef_operator_1.f90", "max_stars_repo_name": "brugger1/testsuite", "max_stars_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-02-12T18:20:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-09T19:46:19.000Z", "max_issues_repo_path": "validation_tests/llvm/f18/gfortran.dg/userdef_operator_1.f90", "max_issues_repo_name": "brugger1/testsuite", "max_issues_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 24, "max_issues_repo_issues_event_min_datetime": "2020-08-31T22:05:07.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T18:30:03.000Z", "max_forks_repo_path": "validation_tests/llvm/f18/gfortran.dg/userdef_operator_1.f90", "max_forks_repo_name": "brugger1/testsuite", "max_forks_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2020-08-31T21:59:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-23T22:06:46.000Z", "avg_line_length": 19.1428571429, "max_line_length": 66, "alphanum_fraction": 0.5865671642, "num_tokens": 213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430812881347, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7542748403238051}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc file alf.f contains subroutines alfk,lfim,lfim1,lfin,lfin1,lfpt\nc for computing normalized associated legendre polynomials\nc\nc subroutine alfk (n,m,cp)\nc\nc dimension of real cp(n/2 + 1)\nc arguments\nc\nc purpose routine alfk computes single precision fourier\nc coefficients in the trigonometric series\nc representation of the normalized associated\nc legendre function pbar(n,m,theta) for use by\nc routines lfp and lfpt in calculating single\nc precision pbar(n,m,theta).\nc\nc first define the normalized associated\nc legendre functions\nc\nc pbar(m,n,theta) = sqrt((2*n+1)*factorial(n-m)\nc /(2*factorial(n+m)))*sin(theta)**m/(2**n*\nc factorial(n)) times the (n+m)th derivative of\nc (x**2-1)**n with respect to x=cos(theta)\nc\nc where theta is colatitude.\nc\nc then subroutine alfk computes the coefficients\nc cp(k) in the following trigonometric\nc expansion of pbar(m,n,theta).\nc\nc 1) for n even and m even, pbar(m,n,theta) =\nc .5*cp(1) plus the sum from k=1 to k=n/2\nc of cp(k+1)*cos(2*k*th)\nc\nc 2) for n even and m odd, pbar(m,n,theta) =\nc the sum from k=1 to k=n/2 of\nc cp(k)*sin(2*k*th)\nc\nc 3) for n odd and m even, pbar(m,n,theta) =\nc the sum from k=1 to k=(n+1)/2 of\nc cp(k)*cos((2*k-1)*th)\nc\nc 4) for n odd and m odd, pbar(m,n,theta) =\nc the sum from k=1 to k=(n+1)/2 of\nc cp(k)*sin((2*k-1)*th)\nc\nc\nc usage call alfk(n,m,cp)\nc\nc arguments\nc\nc on input n\nc nonnegative integer specifying the degree of\nc pbar(n,m,theta)\nc\nc m\nc is the order of pbar(n,m,theta). m can be\nc any integer however cp is computed such that\nc pbar(n,m,theta) = 0 if abs(m) is greater\nc than n and pbar(n,m,theta) = (-1)**m*\nc pbar(n,-m,theta) for negative m.\nc\nc on output cp\nc single precision array of length (n/2)+1\nc which contains the fourier coefficients in\nc the trigonometric series representation of\nc pbar(n,m,theta)\nc\nc\nc special conditions none\nc\nc precision single\nc\nc algorithm the highest order coefficient is determined in\nc closed form and the remainig coefficients are\nc determined as the solution of a backward\nc recurrence relation.\nc\nc accuracy comparison between routines alfk and double\nc precision dalfk on the cray1 indicates\nc greater accuracy for smaller values\nc of input parameter n. agreement to 14\nc places was obtained for n=10 and to 13\nc places for n=100.\nc\n SUBROUTINE DALFK(N,M,CP)\n DOUBLE PRECISION CP\n DOUBLE PRECISION SC10\n DOUBLE PRECISION SC20\n DOUBLE PRECISION SC40\n DOUBLE PRECISION FNUM\n DOUBLE PRECISION FNMH\n DOUBLE PRECISION PM1\n DOUBLE PRECISION T1\n DOUBLE PRECISION FDEN\n DOUBLE PRECISION T2\n DOUBLE PRECISION CP2\n DOUBLE PRECISION FNNP1\n DOUBLE PRECISION FNMSQ\n DOUBLE PRECISION FK\n DOUBLE PRECISION A1\n DOUBLE PRECISION B1\n DOUBLE PRECISION C1\n DIMENSION CP(N/2+1)\n PARAMETER (SC10=1024.D0)\n PARAMETER (SC20=SC10*SC10)\n PARAMETER (SC40=SC20*SC20)\nc\n CP(1) = 0.D0\n MA = IABS(M)\n IF (MA.GT.N) RETURN\n IF (N-1) 2,3,5\n 2 CP(1) = SQRT(2.D0)\n RETURN\n 3 IF (MA.NE.0) GO TO 4\n CP(1) = SQRT(1.5D0)\n RETURN\n 4 CP(1) = SQRT(.75D0)\n IF (M.EQ.-1) CP(1) = -CP(1)\n RETURN\n 5 IF (MOD(N+MA,2).NE.0) GO TO 10\n NMMS2 = (N-MA)/2\n FNUM = N + MA + 1\n FNMH = N - MA + 1\n PM1 = 1.D0\n GO TO 15\n 10 NMMS2 = (N-MA-1)/2\n FNUM = N + MA + 2\n FNMH = N - MA + 2\n PM1 = -1.D0\n 15 T1 = 1.D0/SC20\n NEX = 20\n FDEN = 2.D0\n IF (NMMS2.LT.1) GO TO 20\n DO 18 I = 1,NMMS2\n T1 = FNUM*T1/FDEN\n IF (T1.GT.SC20) THEN\n T1 = T1/SC40\n NEX = NEX + 40\n END IF\n FNUM = FNUM + 2.D0\n FDEN = FDEN + 2.D0\n 18 CONTINUE\n 20 T1 = T1/2.D0** (N-1-NEX)\n IF (MOD(MA/2,2).NE.0) T1 = -T1\n T2 = 1.D0\n IF (MA.EQ.0) GO TO 26\n DO 25 I = 1,MA\n T2 = FNMH*T2/ (FNMH+PM1)\n FNMH = FNMH + 2.D0\n 25 CONTINUE\n 26 CP2 = T1*SQRT((N+.5D0)*T2)\n FNNP1 = N* (N+1)\n FNMSQ = FNNP1 - 2.D0*MA*MA\n L = (N+1)/2\n IF (MOD(N,2).EQ.0 .AND. MOD(MA,2).EQ.0) L = L + 1\n CP(L) = CP2\n IF (M.GE.0) GO TO 29\n IF (MOD(MA,2).NE.0) CP(L) = -CP(L)\n 29 IF (L.LE.1) RETURN\n FK = N\n A1 = (FK-2.D0)* (FK-1.D0) - FNNP1\n B1 = 2.D0* (FK*FK-FNMSQ)\n CP(L-1) = B1*CP(L)/A1\n 30 L = L - 1\n IF (L.LE.1) RETURN\n FK = FK - 2.D0\n A1 = (FK-2.D0)* (FK-1.D0) - FNNP1\n B1 = -2.D0* (FK*FK-FNMSQ)\n C1 = (FK+1.D0)* (FK+2.D0) - FNNP1\n CP(L-1) = - (B1*CP(L)+C1*CP(L+1))/A1\n GO TO 30\n END\nc subroutine lfim (init,theta,l,n,nm,pb,id,wlfim)\nc\nc dimension of theta(l), pb(id,nm+1), wlfim(4*l*(nm+1))\nc arguments\nc\nc purpose given n and l, routine lfim calculates\nc the normalized associated legendre functions\nc pbar(n,m,theta) for m=0,...,n and theta(i)\nc for i=1,...,l where\nc\nc pbar(m,n,theta) = sqrt((2*n+1)*factorial(n-m)\nc /(2*factorial(n+m)))*sin(theta)**m/(2**n*\nc factorial(n)) times the (n+m)th derivative of\nc (x**2-1)**n with respect to x=cos(theta)\nc\nc usage call lfim (init,theta,l,n,nm,pb,id,wlfim)\nc\nc arguments\nc on input init\nc = 0\nc initialization only - using parameters\nc l, nm and array theta, subroutine lfim\nc initializes array wlfim for subsequent\nc use in the computation of the associated\nc legendre functions pb. initialization\nc does not have to be repeated unless\nc l, nm, or array theta are changed.\nc = 1\nc subroutine lfim uses the array wlfim that\nc was computed with init = 0 to compute pb.\nc\nc theta\nc an array that contains the colatitudes\nc at which the associated legendre functions\nc will be computed. the colatitudes must be\nc specified in radians.\nc\nc l\nc the length of the theta array. lfim is\nc vectorized with vector length l.\nc\nc n\nc nonnegative integer, less than nm, specifying\nc degree of pbar(n,m,theta). subroutine lfim\nc must be called starting with n=0. n must be\nc incremented by one in subsequent calls and\nc must not exceed nm.\nc\nc nm\nc the maximum value of n and m\nc\nc id\nc the first dimension of the two dimensional\nc array pb as it appears in the program that\nc calls lfim. (see output parameter pb)\nc\nc wlfim\nc an array with length 4*l*(nm+1) which\nc must be initialized by calling lfim\nc with init=0 (see parameter init) it\nc must not be altered between calls to\nc lfim.\nc\nc\nc on output pb\nc a two dimensional array with first\nc dimension id in the program that calls\nc lfim. the second dimension of pb must\nc be at least nm+1. starting with n=0\nc lfim is called repeatedly with n being\nc increased by one between calls. on each\nc call, subroutine lfim computes\nc = pbar(m,n,theta(i)) for m=0,...,n and\nc i=1,...l.\nc\nc wlfim\nc array containing values which must not\nc be altered unless l, nm or the array theta\nc are changed in which case lfim must be\nc called with init=0 to reinitialize the\nc wlfim array.\nc\nc special conditions n must be increased by one between calls\nc of lfim in which n is not zero.\nc\nc precision single\nc\nc\nc algorithm routine lfim calculates pbar(n,m,theta) using\nc a four term recurrence relation. (unpublished\nc notes by paul n. swarztrauber)\nc\n SUBROUTINE DLFIM(INIT,THETA,L,N,NM,PB,ID,WLFIM)\n DOUBLE PRECISION THETA\n DOUBLE PRECISION PB\n DOUBLE PRECISION WLFIM\n DIMENSION PB(1),WLFIM(1)\nc\nc total length of wlfim is 4*l*(nm+1)\nc\n LNX = L* (NM+1)\n IW1 = LNX + 1\n IW2 = IW1 + LNX\n IW3 = IW2 + LNX\n CALL DLFIM1(INIT,THETA,L,N,NM,ID,PB,WLFIM,WLFIM(IW1),WLFIM(IW2),\n + WLFIM(IW3),WLFIM(IW2))\n RETURN\n END\n SUBROUTINE DLFIM1(INIT,THETA,L,N,NM,ID,P3,PHZ,PH1,P1,P2,CP)\n DOUBLE PRECISION THETA\n DOUBLE PRECISION P3\n DOUBLE PRECISION PHZ\n DOUBLE PRECISION PH1\n DOUBLE PRECISION P1\n DOUBLE PRECISION P2\n DOUBLE PRECISION CP\n DOUBLE PRECISION SSQRT2\n DOUBLE PRECISION SQ5S6\n DOUBLE PRECISION SQ1S6\n DOUBLE PRECISION FN\n DOUBLE PRECISION TN\n DOUBLE PRECISION CN\n DOUBLE PRECISION FM\n DOUBLE PRECISION FNPM\n DOUBLE PRECISION FNMM\n DOUBLE PRECISION TEMP\n DOUBLE PRECISION CC\n DOUBLE PRECISION DD\n DOUBLE PRECISION EE\n DIMENSION P1(L,1),P2(L,1),P3(ID,1),PHZ(L,1),PH1(L,1),CP(1),\n + THETA(1)\n\n NMP1 = NM + 1\n IF (INIT.NE.0) GO TO 5\n SSQRT2 = 1.D0/SQRT(2.D0)\n DO 10 I = 1,L\n PHZ(I,1) = SSQRT2\n 10 CONTINUE\n DO 15 NP1 = 2,NMP1\n NH = NP1 - 1\n CALL DALFK(NH,0,CP)\n DO 16 I = 1,L\n CALL DLFPT(NH,0,THETA(I),CP,PHZ(I,NP1))\n 16 CONTINUE\n CALL DALFK(NH,1,CP)\n DO 17 I = 1,L\n CALL DLFPT(NH,1,THETA(I),CP,PH1(I,NP1))\n 17 CONTINUE\n 15 CONTINUE\n RETURN\n 5 IF (N.GT.2) GO TO 60\n IF (N-1) 25,30,35\n 25 DO 45 I = 1,L\n P3(I,1) = PHZ(I,1)\n 45 CONTINUE\n RETURN\n 30 DO 50 I = 1,L\n P3(I,1) = PHZ(I,2)\n P3(I,2) = PH1(I,2)\n 50 CONTINUE\n RETURN\n 35 SQ5S6 = SQRT(5.D0/6.D0)\n SQ1S6 = SQRT(1.D0/6.D0)\n DO 55 I = 1,L\n P3(I,1) = PHZ(I,3)\n P3(I,2) = PH1(I,3)\n P3(I,3) = SQ5S6*PHZ(I,1) - SQ1S6*P3(I,1)\n P1(I,1) = PHZ(I,2)\n P1(I,2) = PH1(I,2)\n P2(I,1) = PHZ(I,3)\n P2(I,2) = PH1(I,3)\n P2(I,3) = P3(I,3)\n 55 CONTINUE\n RETURN\n 60 NM1 = N - 1\n NP1 = N + 1\n FN = DBLE(N)\n TN = FN + FN\n CN = (TN+1.D0)/ (TN-3.D0)\n DO 65 I = 1,L\n P3(I,1) = PHZ(I,NP1)\n P3(I,2) = PH1(I,NP1)\n 65 CONTINUE\n IF (NM1.LT.3) GO TO 71\n DO 70 MP1 = 3,NM1\n M = MP1 - 1\n FM = DBLE(M)\n FNPM = FN + FM\n FNMM = FN - FM\n TEMP = FNPM* (FNPM-1.D0)\n CC = SQRT(CN* (FNPM-3.D0)* (FNPM-2.D0)/TEMP)\n DD = SQRT(CN*FNMM* (FNMM-1.D0)/TEMP)\n EE = SQRT((FNMM+1.D0)* (FNMM+2.D0)/TEMP)\n DO 70 I = 1,L\n P3(I,MP1) = CC*P1(I,MP1-2) + DD*P1(I,MP1) - EE*P3(I,MP1-2)\n 70 CONTINUE\n 71 FNPM = FN + FN - 1.D0\n TEMP = FNPM* (FNPM-1.D0)\n CC = SQRT(CN* (FNPM-3.D0)* (FNPM-2.D0)/TEMP)\n EE = SQRT(6.D0/TEMP)\n DO 75 I = 1,L\n P3(I,N) = CC*P1(I,N-2) - EE*P3(I,N-2)\n 75 CONTINUE\n FNPM = FN + FN\n TEMP = FNPM* (FNPM-1.D0)\n CC = SQRT(CN* (FNPM-3.D0)* (FNPM-2.D0)/TEMP)\n EE = SQRT(2.D0/TEMP)\n DO 80 I = 1,L\n P3(I,N+1) = CC*P1(I,N-1) - EE*P3(I,N-1)\n 80 CONTINUE\n DO 90 MP1 = 1,NP1\n DO 90 I = 1,L\n P1(I,MP1) = P2(I,MP1)\n P2(I,MP1) = P3(I,MP1)\n 90 CONTINUE\n RETURN\n END\nc subroutine lfin (init,theta,l,m,nm,pb,id,wlfin)\nc\nc dimension of theta(l), pb(id,nm+1), wlfin(4*l*(nm+1))\nc arguments\nc\nc purpose given m and l, routine lfin calculates\nc the normalized associated legendre functions\nc pbar(n,m,theta) for n=m,...,nm and theta(i)\nc for i=1,...,l where\nc\nc pbar(m,n,theta) = sqrt((2*n+1)*factorial(n-m)\nc /(2*factorial(n+m)))*sin(theta)**m/(2**n*\nc factorial(n)) times the (n+m)th derivative of\nc (x**2-1)**n with respect to x=cos(theta)\nc\nc usage call lfin (init,theta,l,m,nm,pb,id,wlfin)\nc\nc arguments\nc on input init\nc = 0\nc initialization only - using parameters\nc l, nm and the array theta, subroutine lfin\nc initializes the array wlfin for subsequent\nc use in the computation of the associated\nc legendre functions pb. initialization does\nc not have to be repeated unless l, nm or\nc the array theta are changed.\nc = 1\nc subroutine lfin uses the array wlfin that\nc was computed with init = 0 to compute pb\nc\nc theta\nc an array that contains the colatitudes\nc at which the associated legendre functions\nc will be computed. the colatitudes must be\nc specified in radians.\nc\nc l\nc the length of the theta array. lfin is\nc vectorized with vector length l.\nc\nc m\nc nonnegative integer, less than nm, specifying\nc degree of pbar(n,m,theta). subroutine lfin\nc must be called starting with n=0. n must be\nc incremented by one in subsequent calls and\nc must not exceed nm.\nc\nc nm\nc the maximum value of n and m\nc\nc id\nc the first dimension of the two dimensional\nc array pb as it appears in the program that\nc calls lfin. (see output parameter pb)\nc\nc wlfin\nc an array with length 4*l*(nm+1) which\nc must be initialized by calling lfin\nc with init=0 (see parameter init) it\nc must not be altered between calls to\nc lfin.\nc\nc\nc on output pb\nc a two dimensional array with first\nc dimension id in the program that calls\nc lfin. the second dimension of pb must\nc be at least nm+1. starting with m=0\nc lfin is called repeatedly with m being\nc increased by one between calls. on each\nc call, subroutine lfin computes pb(i,n+1)\nc = pbar(m,n,theta(i)) for n=m,...,nm and\nc i=1,...l.\nc\nc wlfin\nc array containing values which must not\nc be altered unless l, nm or the array theta\nc are changed in which case lfin must be\nc called with init=0 to reinitialize the\nc wlfin array.\nc\nc special conditions m must be increased by one between calls\nc of lfin in which m is not zero.\nc\nc precision single\nc\nc algorithm routine lfin calculates pbar(n,m,theta) using\nc a four term recurrence relation. (unpublished\nc notes by paul n. swarztrauber)\nc\n SUBROUTINE DLFIN(INIT,THETA,L,M,NM,PB,ID,WLFIN)\n DOUBLE PRECISION THETA\n DOUBLE PRECISION PB\n DOUBLE PRECISION WLFIN\n DIMENSION PB(1),WLFIN(1)\nc\nc total length of wlfin is 4*l*(nm+1)\nc\n LNX = L* (NM+1)\n IW1 = LNX + 1\n IW2 = IW1 + LNX\n IW3 = IW2 + LNX\n CALL DLFIN1(INIT,THETA,L,M,NM,ID,PB,WLFIN,WLFIN(IW1),WLFIN(IW2),\n + WLFIN(IW3),WLFIN(IW2))\n RETURN\n END\n SUBROUTINE DLFIN1(INIT,THETA,L,M,NM,ID,P3,PHZ,PH1,P1,P2,CP)\n DOUBLE PRECISION THETA\n DOUBLE PRECISION P3\n DOUBLE PRECISION PHZ\n DOUBLE PRECISION PH1\n DOUBLE PRECISION P1\n DOUBLE PRECISION P2\n DOUBLE PRECISION CP\n DOUBLE PRECISION SSQRT2\n DOUBLE PRECISION FM\n DOUBLE PRECISION TM\n DOUBLE PRECISION TEMP\n DOUBLE PRECISION CC\n DOUBLE PRECISION EE\n DOUBLE PRECISION FN\n DOUBLE PRECISION TN\n DOUBLE PRECISION CN\n DOUBLE PRECISION FNPM\n DOUBLE PRECISION FNMM\n DOUBLE PRECISION DD\n DIMENSION P1(L,1),P2(L,1),P3(ID,1),PHZ(L,1),PH1(L,1),CP(1),\n + THETA(1)\n\n NMP1 = NM + 1\n IF (INIT.NE.0) GO TO 5\n SSQRT2 = 1.D0/SQRT(2.D0)\n DO 10 I = 1,L\n PHZ(I,1) = SSQRT2\n 10 CONTINUE\n DO 15 NP1 = 2,NMP1\n NH = NP1 - 1\n CALL DALFK(NH,0,CP)\n DO 16 I = 1,L\n CALL DLFPT(NH,0,THETA(I),CP,PHZ(I,NP1))\n 16 CONTINUE\n CALL DALFK(NH,1,CP)\n DO 17 I = 1,L\n CALL DLFPT(NH,1,THETA(I),CP,PH1(I,NP1))\n 17 CONTINUE\n 15 CONTINUE\n RETURN\n 5 MP1 = M + 1\n FM = DBLE(M)\n TM = FM + FM\n IF (M-1) 25,30,35\n 25 DO 45 NP1 = 1,NMP1\n DO 45 I = 1,L\n P3(I,NP1) = PHZ(I,NP1)\n P1(I,NP1) = PHZ(I,NP1)\n 45 CONTINUE\n RETURN\n 30 DO 50 NP1 = 2,NMP1\n DO 50 I = 1,L\n P3(I,NP1) = PH1(I,NP1)\n P2(I,NP1) = PH1(I,NP1)\n 50 CONTINUE\n RETURN\n 35 TEMP = TM* (TM-1.D0)\n CC = SQRT((TM+1.D0)* (TM-2.D0)/TEMP)\n EE = SQRT(2.D0/TEMP)\n DO 85 I = 1,L\n P3(I,M+1) = CC*P1(I,M-1) - EE*P1(I,M+1)\n 85 CONTINUE\n IF (M.EQ.NM) RETURN\n TEMP = TM* (TM+1.D0)\n CC = SQRT((TM+3.D0)* (TM-2.D0)/TEMP)\n EE = SQRT(6.D0/TEMP)\n DO 70 I = 1,L\n P3(I,M+2) = CC*P1(I,M) - EE*P1(I,M+2)\n 70 CONTINUE\n MP3 = M + 3\n IF (NMP1.LT.MP3) GO TO 80\n DO 75 NP1 = MP3,NMP1\n N = NP1 - 1\n FN = DBLE(N)\n TN = FN + FN\n CN = (TN+1.D0)/ (TN-3.D0)\n FNPM = FN + FM\n FNMM = FN - FM\n TEMP = FNPM* (FNPM-1.D0)\n CC = SQRT(CN* (FNPM-3.D0)* (FNPM-2.D0)/TEMP)\n DD = SQRT(CN*FNMM* (FNMM-1.D0)/TEMP)\n EE = SQRT((FNMM+1.D0)* (FNMM+2.D0)/TEMP)\n DO 75 I = 1,L\n P3(I,NP1) = CC*P1(I,NP1-2) + DD*P3(I,NP1-2) - EE*P1(I,NP1)\n 75 CONTINUE\n 80 DO 90 NP1 = M,NMP1\n DO 90 I = 1,L\n P1(I,NP1) = P2(I,NP1)\n P2(I,NP1) = P3(I,NP1)\n 90 CONTINUE\n RETURN\n END\nc subroutine lfpt (n,m,theta,cp,pb)\nc\nc dimension of\nc arguments\nc cp((n/2)+1)\nc\nc purpose routine lfpt uses coefficients computed by\nc routine alfk to compute the single precision\nc normalized associated legendre function pbar(n,\nc m,theta) at colatitude theta.\nc\nc usage call lfpt(n,m,theta,cp,pb)\nc\nc arguments\nc\nc on input n\nc nonnegative integer specifying the degree of\nc pbar(n,m,theta)\nc m\nc is the order of pbar(n,m,theta). m can be\nc any integer however pbar(n,m,theta) = 0\nc if abs(m) is greater than n and\nc pbar(n,m,theta) = (-1)**m*pbar(n,-m,theta)\nc for negative m.\nc\nc theta\nc single precision colatitude in radians\nc\nc cp\nc single precision array of length (n/2)+1\nc containing coefficients computed by routine\nc alfk\nc\nc on output pb\nc single precision variable containing\nc pbar(n,m,theta)\nc\nc special conditions calls to routine lfpt must be preceded by an\nc appropriate call to routine alfk.\nc\nc precision single\nc\nc algorithm the trigonometric series formula used by\nc routine lfpt to calculate pbar(n,m,th) at\nc colatitude th depends on m and n as follows:\nc\nc 1) for n even and m even, the formula is\nc .5*cp(1) plus the sum from k=1 to k=n/2\nc of cp(k)*cos(2*k*th)\nc 2) for n even and m odd. the formula is\nc the sum from k=1 to k=n/2 of\nc cp(k)*sin(2*k*th)\nc 3) for n odd and m even, the formula is\nc the sum from k=1 to k=(n+1)/2 of\nc cp(k)*cos((2*k-1)*th)\nc 4) for n odd and m odd, the formula is\nc the sum from k=1 to k=(n+1)/2 of\nc cp(k)*sin((2*k-1)*th)\nc\nc accuracy comparison between routines lfpt and double\nc precision dlfpt on the cray1 indicates greater\nc accuracy for greater values on input parameter\nc n. agreement to 13 places was obtained for\nc n=10 and to 12 places for n=100.\nc\nc timing time per call to routine lfpt is dependent on\nc the input parameter n.\nc\n SUBROUTINE DLFPT(N,M,THETA,CP,PB)\n DOUBLE PRECISION THETA\n DOUBLE PRECISION CP\n DOUBLE PRECISION PB\n DOUBLE PRECISION CDT\n DOUBLE PRECISION SDT\n DOUBLE PRECISION CT\n DOUBLE PRECISION ST\n DOUBLE PRECISION SUM\n DOUBLE PRECISION CTH\n DIMENSION CP(1)\nc\n PB = 0.D0\n MA = IABS(M)\n IF (MA.GT.N) RETURN\n IF (N) 10,10,30\n 10 IF (MA) 20,20,30\n 20 PB = SQRT(.5D0)\n GO TO 140\n 30 NP1 = N + 1\n NMOD = MOD(N,2)\n MMOD = MOD(MA,2)\n IF (NMOD) 40,40,90\n 40 IF (MMOD) 50,50,70\n 50 KDO = N/2 + 1\n CDT = COS(THETA+THETA)\n SDT = SIN(THETA+THETA)\n CT = 1.D0\n ST = 0.D0\n SUM = .5D0*CP(1)\n DO 60 KP1 = 2,KDO\n CTH = CDT*CT - SDT*ST\n ST = SDT*CT + CDT*ST\n CT = CTH\n SUM = SUM + CP(KP1)*CT\n 60 CONTINUE\n PB = SUM\n GO TO 140\n 70 KDO = N/2\n CDT = COS(THETA+THETA)\n SDT = SIN(THETA+THETA)\n CT = 1.D0\n ST = 0.D0\n SUM = 0.D0\n DO 80 K = 1,KDO\n CTH = CDT*CT - SDT*ST\n ST = SDT*CT + CDT*ST\n CT = CTH\n SUM = SUM + CP(K)*ST\n 80 CONTINUE\n PB = SUM\n GO TO 140\n 90 KDO = (N+1)/2\n IF (MMOD) 100,100,120\n 100 CDT = COS(THETA+THETA)\n SDT = SIN(THETA+THETA)\n CT = COS(THETA)\n ST = -SIN(THETA)\n SUM = 0.D0\n DO 110 K = 1,KDO\n CTH = CDT*CT - SDT*ST\n ST = SDT*CT + CDT*ST\n CT = CTH\n SUM = SUM + CP(K)*CT\n 110 CONTINUE\n PB = SUM\n GO TO 140\n 120 CDT = COS(THETA+THETA)\n SDT = SIN(THETA+THETA)\n CT = COS(THETA)\n ST = -SIN(THETA)\n SUM = 0.D0\n DO 130 K = 1,KDO\n CTH = CDT*CT - SDT*ST\n ST = SDT*CT + CDT*ST\n CT = CTH\n SUM = SUM + CP(K)*ST\n 130 CONTINUE\n PB = SUM\n 140 RETURN\n END\n", "meta": {"hexsha": "b788d8d11640b305ae69604eb8d4ea3b3b1a29d5", "size": 26212, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/sphere3.1_dp/alf.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "external/sphere3.1_dp/alf.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "external/sphere3.1_dp/alf.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 34.7178807947, "max_line_length": 72, "alphanum_fraction": 0.4607813215, "num_tokens": 7755, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308165850443, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.7542748325304305}} {"text": "subroutine vecuni(n,v,mod)\n\n!-----------------------------------------------------------------------\n!\n! This routine computes the length of vector V and converts it to \n! a unit one \n!\n!-----------------------------------------------------------------------\n use typre\n implicit none\n integer(ip), intent(in) :: n\n real(rp), intent(out) :: v(n),mod\n integer(ip) :: i\n\n mod=0.0_rp\n do i=1,n\n mod=mod + v(i)*v(i)\n end do\n mod=sqrt(mod)\n if(mod>1.0e-8) v=v/mod\n \nend subroutine vecuni\n \n", "meta": {"hexsha": "a85ef6dcf619eb45bdfadc14ce9462a29f123ffe", "size": 524, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/mathru/vecuni.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/mathru/vecuni.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/mathru/vecuni.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.8333333333, "max_line_length": 72, "alphanum_fraction": 0.4198473282, "num_tokens": 134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070158103778, "lm_q2_score": 0.8289388062084421, "lm_q1q2_score": 0.7542572354465406}} {"text": "\tSUBROUTINE UT_85DY ( r85day, irptdt, iret )\nC************************************************************************\nC* UT_85DY\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This routine computes and returns the report date-time corresponding\t*\nC* to the \"1985 Day\" in the original report. The \"1985 Day\" is a count\t*\nC* of the number of days elapsed since 1/1/1985, 0000Z; for example:\t*\nC*\tat 1/1/1985, 0000Z, the \"1985 Day\" is 0.00,\t\t\t*\nC*\tat 1/2/1985, 0000Z, the \"1985 Day\" is 1.00,\t\t\t*\nC*\tat 1/3/1985, 0000Z, the \"1985 Day\" is 2.00,\t\t\t*\nC*\tat 1/3/1985, 1200Z, the \"1985 Day\" is 2.50, etc.\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* UT_85DY ( R85DAY, IRPTDT, IRET )\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tR85DAY\t\tREAL*8\t\t# of days since 1/1/1985, 0000Z\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tIRPTDT (*)\tINTEGER\t\tReport date-time\t\t*\nC*\t\t\t\t\t(YYYY, MM, DD, HH, MM ) \t*\nC*\tIRET\t\tINTEGER\t\tReturn code:\t\t\t*\nC*\t\t\t\t\t 0 = normal return\t\t*\nC*\t\t\t\t\t -1 = could not compute IRPTDT\t*\nC*\t\t\t\t\t\t\t\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* J. Ator/NCEP\t\t01/01\t\t\t\t\t\t*\nC* J. Ator/NCEP\t\t06/01\tFixed error in docblock\t\t\t*\nC* R. Hollern/NCEP\t07/02\tAdapted from NA_85DY\t\t\t*\nC* R. Hollern/NCEP\t04/03\tAdded logic to handle the case when the *\nC*\t\t\t\tcomputed report time hour is 24\t\t*\nC************************************************************************\n\tINTEGER\t\tirptdt (*), jrptdt (5)\n\tINTEGER\t\tiwkdt (3)\nC*\n\treal*8\t\tr85day\nC*\n\tLOGICAL\t\tgotyr\nC*-----------------------------------------------------------------------\n\tiret = -1\nC\nC*\tBeginning with 1985, determine how many days are in each\nC*\tsuccessive year, and continue doing so until the cumulative sum\nC*\tis greater than or equal to the whole (i.e. integer) portion of\nC*\tthe \"1985 Day\". The last year for which a count was determined\nC*\tis then equal to the year of the report.\nC\t\n\tiwk85d = INT ( r85day )\nC\n\tiwkdt (1) = 1985\n\tiwkdt (2) = 12\n\tiwkdt (3) = 31\nC\n\tgotyr = .false.\n\tDO WHILE ( .not. gotyr )\n\t CALL TI_ITOJ ( iwkdt, iwkyr, ijday, iertoj )\nC\nC*\t Note that 1/1/1985 represents day 0 (not day 1), so we need\nC*\t to decrement by 1 our count of the number of days for that\nC*\t particular year.\nC\n\t IF ( iwkdt (1) .eq. 1985 ) ijday = ijday - 1 \nC\n\t IF ( ijday .lt. iwk85d ) THEN\n\t\tiwk85d = iwk85d - ijday\n\t\tiwkdt (1) = iwkdt (1) + 1\n\t ELSE\n\t\tgotyr = .true.\n\t\tirptdt (1) = iwkdt (1)\n\t END IF\n\tEND DO\nC\nC*\tNow, determine the month and day of the report by using the\nC*\tremaining number of days that was leftover from the previous\nC*\tdetermination of the year of the report.\nC\n\tCALL TI_JTOI ( irptdt (1), iwk85d, iwkdt, iertoi )\n\tIF ( iertoi .ne. 0 ) THEN\n\t RETURN\n\tEND IF\n\tirptdt (2) = iwkdt (2)\n\tirptdt (3) = iwkdt (3)\nC\nC*\tNow, use the fractional portion of the \"1985 Day\" to determine\nC*\tthe hour and minute of the report.\nC\n\tnmins = NINT ( ( r85day - FLOAT ( INT ( r85day ) ) ) * 1440. )\n\tirptdt (4) = nmins / 60\n\tirptdt (5) = MOD ( nmins, 60 )\nC\nC*\tCheck if hour is 24. If it is, set hour to 00 and add a day\nC*\tto the date.\nC\n\tIF ( irptdt (4) .eq. 24 ) THEN\nC\n\t irptdt (4) = 0\nC\n\t CALL TI_ADDD ( irptdt, jrptdt, iret ) \nC\nC*\t IF ( iret .ne. 0 ) RETURN\nC\n\t irptdt (1) = jrptdt(1)\n\t irptdt (2) = jrptdt(2)\n\t irptdt (3) = jrptdt(3)\n\tEND IF\nC\n\tiret = 0\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "39a5869d8754d51cf976df0c4137ce915f1ca860", "size": 3242, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/ncepUT/ut85dy.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/ncepUT/ut85dy.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/ncepUT/ut85dy.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 29.2072072072, "max_line_length": 73, "alphanum_fraction": 0.5724861197, "num_tokens": 1283, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248140158416, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.7542001335945285}} {"text": "!**\n!* Provides functions to produce linearly and exponentially spaced grids\n!**\nmodule grids\n use kinds, only: dp\n implicit none\n private\n public :: build_grid\n\n contains\n\n ! **\n ! * Searches for the root of the function f(x, [p2,p3,p4,p5])-offset_in.\n ! *\n ! * Input:\n ! * - grid_length: the length of the grid to be produces\n ! * - min: the value of the first (lowest value) point in the grid\n ! * - max: the value of the last (highest value) point in the grid\n ! * - expg_in (optional): specifies the order of the exponential spacing of the grid. Default is 0, which\n ! * corresponds to a linear spacing of the grid (uniform grid). A value of 1 means an exponential grid,\n ! * a value of 2 corresponds to a double exponential grid, and so on.\n ! *\n ! * Return value: the grid\n ! **\n function build_grid(grid_length,min,max,expg_in) result(grid)\n integer, intent(in) :: grid_length\n real(dp), intent(in) :: min,max\n integer, intent(in), optional :: expg_in\n integer :: expg,i,e\n real(dp), dimension(grid_length) :: grid\n real(dp) :: v1,v2,step\n\n if (present(expg_in)) then\n expg = expg_in\n else\n expg = 0\n end if\n\n v1 = min\n v2 = max\n\n ! Loglinearize\n do e=1,expg\n v1 = log(v1+1)\n v2 = log(v2+1)\n end do\n\n step = (v2-v1) / (grid_length-1)\n do i=2,grid_length\n grid(i) = v1 + (i-1)*step\n end do\n\n ! Exp\n do e=1,expg\n grid = exp(grid)-1\n end do\n\n grid(1) = min\n grid(grid_length) = max\n\n end function build_grid\nend module\n", "meta": {"hexsha": "b8506a64c878b54876c2d5f9955201eb424398f2", "size": 1981, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "grids.f90", "max_stars_repo_name": "carlozanella/ncegm", "max_stars_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-03-14T23:31:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-14T23:31:35.000Z", "max_issues_repo_path": "grids.f90", "max_issues_repo_name": "carlozanella/ncegm", "max_issues_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "grids.f90", "max_forks_repo_name": "carlozanella/ncegm", "max_forks_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.4444444444, "max_line_length": 117, "alphanum_fraction": 0.485108531, "num_tokens": 491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7541962802464136}} {"text": "! This version solves the Schroedinger equation for the \n! one-dimensional \n! harmonic oscillator using matrix diagonalization\n\n! declaration of constants used in the calculations\n! define variables, where we have chosen to use atomic units for \n! m=c=hbar=k=1. \n\nMODULE parameters \n USE constants\n ! the step\n REAL(DP), PUBLIC :: step\n ! r min\n REAL(DP), PUBLIC, PARAMETER :: rmin=-10.0_dp\n ! r max\n REAL(DP), PUBLIC, PARAMETER :: rmax=10.0_dp\n ! number of steps from rmin to rmin to rmax\n INTEGER, PUBLIC, PARAMETER :: max_step=1000\n ! size of matrix to be diagonalized, do not need points at rmin and rmax\n INTEGER, PUBLIC, PARAMETER :: n=998\nEND MODULE parameters\n\n! main program starts here\n\nPROGRAM schroedinger_equation\n USE constants\n USE parameters\n USE f90library\n IMPLICIT NONE\n REAL(DP) :: potential, const1, const2\n REAL(DP), DIMENSION(:), ALLOCATABLE :: w, r\n REAL(DP), ALLOCATABLE, DIMENSION(:) :: e, d\n REAL(DP), ALLOCATABLE, DIMENSION(:,:) :: z\n INTEGER :: i\n\n ! reserve place in memory for the arrays w, r, e, d and z\n\n ALLOCATE ( e(n) , d(n))\n ALLOCATE ( w(0:max_step), r(0:max_step))\n\n ! define the step size\n\n step=(rmax-rmin)/FLOAT(max_step)\n\n ! define constants for the matrix to be diagonalized\n\n const1=2./(step*step)\n const2=-1./(step*step)\n\n ! set up r and the function w for energy =0\n ! w corresponds then to the potential\n ! values at \n\n DO i=0, max_step\n r(i) = rmin+i*step\n w(i) = potential(r(i))\n ENDDO\n\n ! setup the diagonal d and the non-diagonal part e of\n ! the tri-diagonal matrix to be diagonalized\n\n d(1:n)=const1+w(1:n) ; e(1:n)=const2\n\n ! allocate space for eigenvector info\n\n ALLOCATE ( z(n,n) )\n\n ! obtain the eigenvalues\n\n CALL tqli(d,e,n,z)\n\n ! sort eigenvalues as an ascending series \n\n CALL eigenvalue_sort(d,n)\n\n ! write out \n\n WRITE(6,*) ' Rmin and Rmax ', rmin, rmax\n WRITE(6,*) ' Number of steps -1 ', n\n WRITE(6,*) ' The 5 lowest eigenvalues '\n WRITE(6,'(5F12.6)') d(1:5)\n\n ! find the wave function for the lowest lying state\n\n CALL plot(d(1), w, r) \n\n ! deallocate space in memory\n\n DEALLOCATE (z)\n DEALLOCATE ( w, r, d, e)\n\nEND PROGRAM schroedinger_equation\n\n! Harmonic oscillator potential\n\nREAL(DP) FUNCTION potential(x)\n USE constants\n IMPLICIT NONE\n REAL(DP), INTENT(IN) :: x\n\n potential=x*x\n\nEND FUNCTION potential\n\n\n!\n! Sort the eigenvalues as\n! ascending series \n!\n\nSUBROUTINE eigenvalue_sort(e,n)\n USE constants\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: n\n INTEGER :: i, j\n REAL(DP), DIMENSION(n), INTENT(INOUT) :: e\n REAL(DP) :: temp\n\n DO i = 1, n\n DO j =i, n\n IF( ABS(e(i)) > ABS(e(j)) ) THEN\n ! change the energy \n temp=e(i)\n e(i)=e(j)\n e(j)=temp\n ENDIF\n ENDDO\n ENDDO\n\nEND SUBROUTINE eigenvalue_sort\n\n\n\n! This function plots the wave function at the final energy\n\nSUBROUTINE plot(energy, w ,r )\n USE constants\n USE parameters\n IMPLICIT NONE\n INTEGER :: i, match\n REAL(DP), DIMENSION(n) :: w, r\n REAL(DP), DIMENSION(:), ALLOCATABLE :: wf\n REAL(DP) :: energy, wwf, fac, norm, pi\n\n ALLOCATE ( wf(0:max_step))\n pi=ACOS(-1.) ; pi=SQRT(pi)\n\n ! add the chosen energy to the potential \n\n w=(w-energy)*step*step+2\n\n ! Boundary conditions\n ! value of the wave function at max step\n\n wf(max_step)=0.\n\n ! here we use the analytical form for the wave function for max step -1\n ! (taylor expansion of EXP(-r^2/2))\n\n wf(max_step-1)=step**2/2.\n\n ! start from right and move towards rmin\n\n OUTER_TO_INNER : DO\n DO i=max_step-2, 1, -1\n wf(i)=w(i+1)*wf(i+1)-wf(i+2)\n ! find point were the outer part starts turning in order to determine matching point\n IF ( wf(i) <= wf(i+1) ) EXIT OUTER_TO_INNER \n ENDDO\n ENDDO OUTER_TO_INNER\n match = i+1\n wwf=wf(match)\n\n ! start from rmin and move towards the matching point\n\n wf(0)=0.\n wf(1)=step**2/2.\n DO i=2, match\n wf(i)=w(i-1)*wf(i-1)-wf(i-2)\n ENDDO\n\n ! scale the wave function below the matching point\n\n fac=wwf/wf(match)\n wf(0:match)=wf(0:match)*fac\n\n ! normalize the wave function\n\n norm=step*SUM(wf*wf)\n IF ( norm > 0. ) norm = 1./SQRT(norm)\n wf=wf*norm\n WRITE(6,*) norm \n ! write out of numerically calculated and analytical expression for the wave functions\n\n WRITE(6,'(E12.6,2X,E12.6,2X,E12.6)')( r(i), wf(i), EXP(-(r(i)**2)/2.0_dp)/SQRT(pi),i=1, max_step)\n DEALLOCATE ( wf) \n\nEND SUBROUTINE plot\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "fc91bd187f46edc4ee9ee76c1d553c76a249b199", "size": 4514, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/Programs/LecturePrograms/programs/EigenProblems/Fortran/program1.f90", "max_stars_repo_name": "kimrojas/ComputationalPhysicsMSU", "max_stars_repo_head_hexsha": "a47cfc18b3ad6adb23045b3f49fab18c0333f556", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 87, "max_stars_repo_stars_event_min_datetime": "2015-01-21T08:29:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T07:11:53.000Z", "max_issues_repo_path": "doc/Programs/LecturePrograms/programs/EigenProblems/Fortran/program1.f90", "max_issues_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_issues_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-01-18T10:43:38.000Z", "max_issues_repo_issues_event_max_datetime": "2020-02-08T13:15:42.000Z", "max_forks_repo_path": "doc/Programs/LecturePrograms/programs/EigenProblems/Fortran/program1.f90", "max_forks_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_forks_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 54, "max_forks_repo_forks_event_min_datetime": "2015-02-09T10:02:00.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-07T10:44:14.000Z", "avg_line_length": 21.3933649289, "max_line_length": 99, "alphanum_fraction": 0.6362428002, "num_tokens": 1497, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7541962685356313}} {"text": "*DECK RJ\n REAL FUNCTION RJ (X, Y, Z, P, IER)\nC***BEGIN PROLOGUE RJ\nC***PURPOSE Compute the incomplete or complete (X or Y or Z is zero)\nC elliptic integral of the 3rd kind. For X, Y, and Z non-\nC negative, at most one of them zero, and P positive,\nC RJ(X,Y,Z,P) = Integral from zero to infinity of\nC -1/2 -1/2 -1/2 -1\nC (3/2)(t+X) (t+Y) (t+Z) (t+P) dt.\nC***LIBRARY SLATEC\nC***CATEGORY C14\nC***TYPE SINGLE PRECISION (RJ-S, DRJ-D)\nC***KEYWORDS COMPLETE ELLIPTIC INTEGRAL, DUPLICATION THEOREM,\nC INCOMPLETE ELLIPTIC INTEGRAL, INTEGRAL OF THE THIRD KIND,\nC TAYLOR SERIES\nC***AUTHOR Carlson, B. C.\nC Ames Laboratory-DOE\nC Iowa State University\nC Ames, IA 50011\nC Notis, E. M.\nC Ames Laboratory-DOE\nC Iowa State University\nC Ames, IA 50011\nC Pexton, R. L.\nC Lawrence Livermore National Laboratory\nC Livermore, CA 94550\nC***DESCRIPTION\nC\nC 1. RJ\nC Standard FORTRAN function routine\nC Single precision version\nC The routine calculates an approximation result to\nC RJ(X,Y,Z,P) = Integral from zero to infinity of\nC\nC -1/2 -1/2 -1/2 -1\nC (3/2)(t+X) (t+Y) (t+Z) (t+P) dt,\nC\nC where X, Y, and Z are nonnegative, at most one of them is\nC zero, and P is positive. If X or Y or Z is zero, the\nC integral is COMPLETE. The duplication theorem is iterated\nC until the variables are nearly equal, and the function is\nC then expanded in Taylor series to fifth order.\nC\nC\nC 2. Calling Sequence\nC RJ( X, Y, Z, P, IER )\nC\nC Parameters On Entry\nC Values assigned by the calling routine\nC\nC X - Single precision, nonnegative variable\nC\nC Y - Single precision, nonnegative variable\nC\nC Z - Single precision, nonnegative variable\nC\nC P - Single precision, positive variable\nC\nC\nC On Return (values assigned by the RJ routine)\nC\nC RJ - Single precision approximation to the integral\nC\nC IER - Integer\nC\nC IER = 0 Normal and reliable termination of the\nC routine. It is assumed that the requested\nC accuracy has been achieved.\nC\nC IER > 0 Abnormal termination of the routine\nC\nC\nC X, Y, Z, P are unaltered.\nC\nC\nC 3. Error Messages\nC\nC Value of IER assigned by the RJ routine\nC\nC Value Assigned Error Message Printed\nC IER = 1 MIN(X,Y,Z) .LT. 0.0E0\nC = 2 MIN(X+Y,X+Z,Y+Z,P) .LT. LOLIM\nC = 3 MAX(X,Y,Z,P) .GT. UPLIM\nC\nC\nC\nC 4. Control Parameters\nC\nC Values of LOLIM, UPLIM, and ERRTOL are set by the\nC routine.\nC\nC\nC LOLIM and UPLIM determine the valid range of X Y, Z, and P\nC\nC LOLIM is not less than the cube root of the value\nC of LOLIM used in the routine for RC.\nC\nC UPLIM is not greater than 0.3 times the cube root of\nC the value of UPLIM used in the routine for RC.\nC\nC\nC Acceptable Values For: LOLIM UPLIM\nC IBM 360/370 SERIES : 2.0E-26 3.0E+24\nC CDC 6000/7000 SERIES : 5.0E-98 3.0E+106\nC UNIVAC 1100 SERIES : 5.0E-13 6.0E+11\nC CRAY : 1.32E-822 1.4E+821\nC VAX 11 SERIES : 2.5E-13 9.0E+11\nC\nC\nC\nC ERRTOL determines the accuracy of the answer\nC\nC The value assigned by the routine will result\nC in solution precision within 1-2 decimals of\nC \"machine precision\".\nC\nC\nC\nC\nC Relative error due to truncation of the series for RJ\nC is less than 3 * ERRTOL ** 6 / (1 - ERRTOL) ** 3/2.\nC\nC\nC\nC The accuracy of the computed approximation to the inte-\nC gral can be controlled by choosing the value of ERRTOL.\nC Truncation of a Taylor series after terms of fifth order\nC Introduces an error less than the amount shown in the\nC second column of the following table for each value of\nC ERRTOL in the first column. In addition to the trunca-\nC tion error there will be round-off error, but in prac-\nC tice the total error from both sources is usually less\nC than the amount given in the table.\nC\nC\nC\nC Sample choices: ERRTOL Relative Truncation\nC error less than\nC 1.0E-3 4.0E-18\nC 3.0E-3 3.0E-15\nC 1.0E-2 4.0E-12\nC 3.0E-2 3.0E-9\nC 1.0E-1 4.0E-6\nC\nC Decreasing ERRTOL by a factor of 10 yields six more\nC decimal digits of accuracy at the expense of one or\nC two more iterations of the duplication theorem.\nC\nC *Long Description:\nC\nC RJ Special Comments\nC\nC\nC Check by addition theorem: RJ(X,X+Z,X+W,X+P)\nC + RJ(Y,Y+Z,Y+W,Y+P) + (A-B) * RJ(A,B,B,A) + 3 / SQRT(A)\nC = RJ(0,Z,W,P), where X,Y,Z,W,P are positive and X * Y\nC = Z * W, A = P * P * (X+Y+Z+W), B = P * (P+X) * (P+Y),\nC and B - A = P * (P-Z) * (P-W). The sum of the third and\nC fourth terms on the left side is 3 * RC(A,B).\nC\nC\nC On Input:\nC\nC X, Y, Z, and P are the variables in the integral RJ(X,Y,Z,P).\nC\nC\nC On Output:\nC\nC\nC X, Y, Z, and P are unaltered.\nC\nC ********************************************************\nC\nC Warning: Changes in the program may improve speed at the\nC expense of robustness.\nC\nC ------------------------------------------------------------\nC\nC\nC Special Functions via RJ and RF\nC\nC\nC Legendre form of ELLIPTIC INTEGRAL of 3rd kind\nC ----------------------------------------------\nC\nC\nC PHI 2 -1\nC P(PHI,K,N) = INT (1+N SIN (THETA) ) *\nC 0\nC\nC 2 2 -1/2\nC *(1-K SIN (THETA) ) D THETA\nC\nC\nC 2 2 2\nC = SIN (PHI) RF(COS (PHI), 1-K SIN (PHI),1)\nC\nC 3 2 2 2\nC -(N/3) SIN (PHI) RJ(COS (PHI),1-K SIN (PHI),\nC\nC 2\nC 1,1+N SIN (PHI))\nC\nC\nC\nC Bulirsch form of ELLIPTIC INTEGRAL of 3rd kind\nC ----------------------------------------------\nC\nC\nC 2 2 2\nC EL3(X,KC,P) = X RF(1,1+KC X ,1+X ) +\nC\nC 3 2 2 2 2\nC +(1/3)(1-P) X RJ(1,1+KC X ,1+X ,1+PX )\nC\nC\nC 2\nC CEL(KC,P,A,B) = A RF(0,KC ,1) +\nC\nC 2\nC +(1/3)(B-PA) RJ(0,KC ,1,P)\nC\nC\nC\nC\nC Heuman's LAMBDA function\nC ------------------------\nC\nC\nC 2 2 2 1/2\nC L(A,B,P) = (COS(A)SIN(B)COS(B)/(1-COS (A)SIN (B)) )\nC\nC 2 2 2\nC *(SIN(P) RF(COS (P),1-SIN (A) SIN (P),1)\nC\nC 2 3 2 2\nC +(SIN (A) SIN (P)/(3(1-COS (A) SIN (B))))\nC\nC 2 2 2\nC *RJ(COS (P),1-SIN (A) SIN (P),1,1-\nC\nC 2 2 2 2\nC -SIN (A) SIN (P)/(1-COS (A) SIN (B))))\nC\nC\nC\nC\nC (PI/2) LAMBDA0(A,B) =L(A,B,PI/2) =\nC\nC\nC 2 2 2 -1/2\nC = COS (A) SIN(B) COS(B) (1-COS (A) SIN (B))\nC\nC 2 2 2\nC *RF(0,COS (A),1) + (1/3) SIN (A) COS (A)\nC\nC 2 2 -3/2\nC *SIN(B) COS(B) (1-COS (A) SIN (B))\nC\nC 2 2 2 2 2\nC *RJ(0,COS (A),1,COS (A) COS (B)/(1-COS (A) SIN (B)))\nC\nC\nC\nC Jacobi ZETA function\nC --------------------\nC\nC\nC 2 2 2 1/2\nC Z(B,K) = (K/3) SIN(B) COS(B) (1-K SIN (B))\nC\nC\nC 2 2 2 2\nC *RJ(0,1-K ,1,1-K SIN (B)) / RF (0,1-K ,1)\nC\nC\nC -------------------------------------------------------------------\nC\nC***REFERENCES B. C. Carlson and E. M. Notis, Algorithms for incomplete\nC elliptic integrals, ACM Transactions on Mathematical\nC Software 7, 3 (September 1981), pp. 398-403.\nC B. C. Carlson, Computing elliptic integrals by\nC duplication, Numerische Mathematik 33, (1979),\nC pp. 1-16.\nC B. C. Carlson, Elliptic integrals of the first kind,\nC SIAM Journal of Mathematical Analysis 8, (1977),\nC pp. 231-242.\nC***ROUTINES CALLED R1MACH, RC, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 790801 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 891009 Removed unreferenced statement labels. (WRB)\nC 891009 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 900510 Changed calls to XERMSG to standard form, and some\nC editorial changes. (RWC)).\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE RJ\n CHARACTER*16 XERN3, XERN4, XERN5, XERN6, XERN7\n INTEGER IER\n REAL ALFA, BETA, C1, C2, C3, C4, EA, EB, EC, E2, E3\n REAL LOLIM, UPLIM, EPSLON, ERRTOL\n REAL LAMDA, MU, P, PN, PNDEV\n REAL POWER4, RC, SIGMA, S1, S2, S3, X, XN, XNDEV\n REAL XNROOT, Y, YN, YNDEV, YNROOT, Z, ZN, ZNDEV,\n * ZNROOT\n LOGICAL FIRST\n SAVE ERRTOL,LOLIM,UPLIM,C1,C2,C3,C4,FIRST\n DATA FIRST /.TRUE./\nC\nC***FIRST EXECUTABLE STATEMENT RJ\n IF (FIRST) THEN\n ERRTOL = (R1MACH(3)/3.0E0)**(1.0E0/6.0E0)\n LOLIM = (5.0E0 * R1MACH(1))**(1.0E0/3.0E0)\n UPLIM = 0.30E0*( R1MACH(2) / 5.0E0)**(1.0E0/3.0E0)\nC\n C1 = 3.0E0/14.0E0\n C2 = 1.0E0/3.0E0\n C3 = 3.0E0/22.0E0\n C4 = 3.0E0/26.0E0\n ENDIF\n FIRST = .FALSE.\nC\nC CALL ERROR HANDLER IF NECESSARY.\nC\n RJ = 0.0E0\n IF (MIN(X,Y,Z).LT.0.0E0) THEN\n IER = 1\n WRITE (XERN3, '(1PE15.6)') X\n WRITE (XERN4, '(1PE15.6)') Y\n WRITE (XERN5, '(1PE15.6)') Z\n CALL XERMSG ('SLATEC', 'RJ',\n * 'MIN(X,Y,Z).LT.0 WHERE X = ' // XERN3 // ' Y = ' // XERN4 //\n * ' AND Z = ' // XERN5, 1, 1)\n RETURN\n ENDIF\nC\n IF (MAX(X,Y,Z,P).GT.UPLIM) THEN\n IER = 3\n WRITE (XERN3, '(1PE15.6)') X\n WRITE (XERN4, '(1PE15.6)') Y\n WRITE (XERN5, '(1PE15.6)') Z\n WRITE (XERN6, '(1PE15.6)') P\n WRITE (XERN7, '(1PE15.6)') UPLIM\n CALL XERMSG ('SLATEC', 'RJ',\n * 'MAX(X,Y,Z,P).GT.UPLIM WHERE X = ' // XERN3 // ' Y = ' //\n * XERN4 // ' Z = ' // XERN5 // ' P = ' // XERN6 //\n * ' AND UPLIM = ' // XERN7, 3, 1)\n RETURN\n ENDIF\nC\n IF (MIN(X+Y,X+Z,Y+Z,P).LT.LOLIM) THEN\n IER = 2\n WRITE (XERN3, '(1PE15.6)') X\n WRITE (XERN4, '(1PE15.6)') Y\n WRITE (XERN5, '(1PE15.6)') Z\n WRITE (XERN6, '(1PE15.6)') P\n WRITE (XERN7, '(1PE15.6)') LOLIM\n CALL XERMSG ('SLATEC', 'RJ',\n * 'MIN(X+Y,X+Z,Y+Z,P).LT.LOLIM WHERE X = ' // XERN3 //\n * ' Y = ' // XERN4 // ' Z = ' // XERN5 // ' P = ' // XERN6 //\n * ' AND LOLIM = ', 2, 1)\n RETURN\n ENDIF\nC\n IER = 0\n XN = X\n YN = Y\n ZN = Z\n PN = P\n SIGMA = 0.0E0\n POWER4 = 1.0E0\nC\n 30 MU = (XN+YN+ZN+PN+PN)*0.20E0\n XNDEV = (MU-XN)/MU\n YNDEV = (MU-YN)/MU\n ZNDEV = (MU-ZN)/MU\n PNDEV = (MU-PN)/MU\n EPSLON = MAX(ABS(XNDEV), ABS(YNDEV), ABS(ZNDEV), ABS(PNDEV))\n IF (EPSLON.LT.ERRTOL) GO TO 40\n XNROOT = SQRT(XN)\n YNROOT = SQRT(YN)\n ZNROOT = SQRT(ZN)\n LAMDA = XNROOT*(YNROOT+ZNROOT) + YNROOT*ZNROOT\n ALFA = PN*(XNROOT+YNROOT+ZNROOT) + XNROOT*YNROOT*ZNROOT\n ALFA = ALFA*ALFA\n BETA = PN*(PN+LAMDA)*(PN+LAMDA)\n SIGMA = SIGMA + POWER4*RC(ALFA,BETA,IER)\n POWER4 = POWER4*0.250E0\n XN = (XN+LAMDA)*0.250E0\n YN = (YN+LAMDA)*0.250E0\n ZN = (ZN+LAMDA)*0.250E0\n PN = (PN+LAMDA)*0.250E0\n GO TO 30\nC\n 40 EA = XNDEV*(YNDEV+ZNDEV) + YNDEV*ZNDEV\n EB = XNDEV*YNDEV*ZNDEV\n EC = PNDEV*PNDEV\n E2 = EA - 3.0E0*EC\n E3 = EB + 2.0E0*PNDEV*(EA-EC)\n S1 = 1.0E0 + E2*(-C1+0.750E0*C3*E2-1.50E0*C4*E3)\n S2 = EB*(0.50E0*C2+PNDEV*(-C3-C3+PNDEV*C4))\n S3 = PNDEV*EA*(C2-PNDEV*C3) - C2*PNDEV*EC\n RJ = 3.0E0*SIGMA + POWER4*(S1+S2+S3)/(MU* SQRT(MU))\n RETURN\n END\n", "meta": {"hexsha": "93591224d46018c0ead17eb5c258446ae17c7ea6", "size": 14010, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/rj.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/rj.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/rj.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.1707317073, "max_line_length": 72, "alphanum_fraction": 0.4506780871, "num_tokens": 4654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582612793113, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.754116796164942}} {"text": "subroutine qinit(maxmx, maxmy, meqn, mbc, mx, my, x_low, y_low, dx, dy, q)\n\n! Sets initial conditions for:\n! film height = q(:,:,1);\n! surfactant concentration = q(:,:,2).\n\n implicit none\n\n integer, intent(in) :: maxmx, maxmy, meqn, mbc, mx, my\n double precision, intent(in) :: x_low, y_low, dx, dy\n double precision, intent(out) :: q(1-mbc:maxmx+mbc, 1-mbc:maxmy+mbc, meqn)\n\n integer :: i, j, imode, k(4)\n double precision :: x, y, a, b, big_b, c(4), pi=dacos(-1.d0)\n double precision :: heaviside_1mx\n\n a = 1.d-2\n b = 5.d-2\n big_b = 5.d0\n\n c(1) = 1.d0\n c(2) = 1.d0\n c(3) = 1.d0\n c(4) = 0.5d0\n\n k(1) = 2\n k(2) = 5\n k(3) = 7\n k(4) = 20\n\n do j = 1,my\n y = y_low + (j-0.5d0)*dy\n do i = 1,mx\n x = x_low + (i-0.5d0)*dx\n\n heaviside_1mx = 0.5d0*(1+tanh(20*(1-x)))\n\n q(i,j,1) = (1-x**2+b)*heaviside_1mx + b*(1.d0-heaviside_1mx)\n \n do imode = 1,4\n q(i,j,1) = q(i,j,1) + a * exp(-big_b*(x-1)**2) * c(imode) * cos(k(imode)*y)\n end do\n\n q(i,j,2) = heaviside_1mx\n\n end do\n end do\n \nend subroutine qinit\n", "meta": {"hexsha": "19a902229eee62ff0640c983d28c46122639f051", "size": 1171, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/2d/Surfactant/qinit.f90", "max_stars_repo_name": "claridge/implicit_solvers", "max_stars_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-04-29T00:16:18.000Z", "max_stars_repo_stars_event_max_datetime": "2017-04-29T00:16:18.000Z", "max_issues_repo_path": "applications/2d/Surfactant/qinit.f90", "max_issues_repo_name": "claridge/implicit_solvers", "max_issues_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/2d/Surfactant/qinit.f90", "max_forks_repo_name": "claridge/implicit_solvers", "max_forks_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.42, "max_line_length": 91, "alphanum_fraction": 0.4927412468, "num_tokens": 490, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669026, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7541062508987558}} {"text": "module random_mod\n use, intrinsic :: iso_fortran_env, only : sp => REAL32, dp => REAL64\n implicit none\n\n private\n public :: random_normal_number\n\ncontains\n\n subroutine random_normal_number(r)\n implicit none\n real(kind=dp), intent(out) :: r\n real(kind=dp), parameter :: pi = acos(-1.0_dp)\n real(kind=dp) :: x1, x2, r_temp\n real(kind=dp), save :: next_r\n logical, save :: prev_ok = .false.\n \n if (prev_ok) then\n prev_ok = .false.\n r = next_r\n else\n prev_ok = .true.\n call random_number(x1)\n call random_number(x2)\n r_temp = sqrt(-2.0_dp*log(x1))\n next_r = r_temp*cos(2.0_dp*pi*x2)\n r = r_temp*sin(2.0_dp*pi*x2)\n end if\n end subroutine random_normal_number\n\nend module random_mod\n", "meta": {"hexsha": "e833bda946642f7168bf4a4246df18481f495057", "size": 853, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/Types/random_mod.f90", "max_stars_repo_name": "Gjacquenot/training-material", "max_stars_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 115, "max_stars_repo_stars_event_min_datetime": "2015-03-23T13:34:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T00:27:21.000Z", "max_issues_repo_path": "Fortran/Types/random_mod.f90", "max_issues_repo_name": "Gjacquenot/training-material", "max_issues_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 56, "max_issues_repo_issues_event_min_datetime": "2015-02-25T15:04:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T07:42:48.000Z", "max_forks_repo_path": "Fortran/Types/random_mod.f90", "max_forks_repo_name": "Gjacquenot/training-material", "max_forks_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 59, "max_forks_repo_forks_event_min_datetime": "2015-11-26T11:44:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T00:27:22.000Z", "avg_line_length": 26.65625, "max_line_length": 72, "alphanum_fraction": 0.5592028136, "num_tokens": 228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7541062427520722}} {"text": "\nsubmodule(forlab_math) forlab_math_is_close\n\n use, intrinsic :: ieee_arithmetic, only: ieee_is_nan\n implicit none\n\ncontains\n\n elemental module logical function is_close_rsp(a, b, rel_tol, abs_tol, equal_nan) result(close)\n real(sp), intent(in) :: a, b\n real(sp), intent(in), optional :: rel_tol, abs_tol\n logical, intent(in), optional :: equal_nan\n logical :: equal_nan_\n\n equal_nan_ = optval(equal_nan, .false.)\n\n if (ieee_is_nan(a) .or. ieee_is_nan(b)) then\n close = merge(.true., .false., equal_nan_ .and. ieee_is_nan(a) .and. ieee_is_nan(b))\n else\n close = abs(a - b) <= max(abs(optval(rel_tol, 1.0e-9_sp)*max(abs(a), abs(b))), &\n abs(optval(abs_tol, 0.0_sp)))\n end if\n\n end function is_close_rsp\n elemental module logical function is_close_rdp(a, b, rel_tol, abs_tol, equal_nan) result(close)\n real(dp), intent(in) :: a, b\n real(dp), intent(in), optional :: rel_tol, abs_tol\n logical, intent(in), optional :: equal_nan\n logical :: equal_nan_\n\n equal_nan_ = optval(equal_nan, .false.)\n\n if (ieee_is_nan(a) .or. ieee_is_nan(b)) then\n close = merge(.true., .false., equal_nan_ .and. ieee_is_nan(a) .and. ieee_is_nan(b))\n else\n close = abs(a - b) <= max(abs(optval(rel_tol, 1.0e-9_dp)*max(abs(a), abs(b))), &\n abs(optval(abs_tol, 0.0_dp)))\n end if\n\n end function is_close_rdp\n\n elemental module logical function is_close_csp(a, b, rel_tol, abs_tol, equal_nan) result(close)\n complex(sp), intent(in) :: a, b\n real(sp), intent(in), optional :: rel_tol, abs_tol\n logical, intent(in), optional :: equal_nan\n\n close = is_close_rsp(a%re, b%re, rel_tol, abs_tol, equal_nan) .and. &\n is_close_rsp(a%im, b%im, rel_tol, abs_tol, equal_nan)\n\n end function is_close_csp\n elemental module logical function is_close_cdp(a, b, rel_tol, abs_tol, equal_nan) result(close)\n complex(dp), intent(in) :: a, b\n real(dp), intent(in), optional :: rel_tol, abs_tol\n logical, intent(in), optional :: equal_nan\n\n close = is_close_rdp(a%re, b%re, rel_tol, abs_tol, equal_nan) .and. &\n is_close_rdp(a%im, b%im, rel_tol, abs_tol, equal_nan)\n\n end function is_close_cdp\n\nend submodule forlab_math_is_close\n", "meta": {"hexsha": "1a27401de68cdb4d888367a7011952a0e1bc9187", "size": 2423, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_math_is_close.f90", "max_stars_repo_name": "fortran-fans/forlab", "max_stars_repo_head_hexsha": "1acee0a68a703dc0b9668167494b9cb8ee71264d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "src/forlab_math_is_close.f90", "max_issues_repo_name": "fortran-fans/forlab", "max_issues_repo_head_hexsha": "1acee0a68a703dc0b9668167494b9cb8ee71264d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "src/forlab_math_is_close.f90", "max_forks_repo_name": "fortran-fans/forlab", "max_forks_repo_head_hexsha": "1acee0a68a703dc0b9668167494b9cb8ee71264d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 39.0806451613, "max_line_length": 99, "alphanum_fraction": 0.6149401568, "num_tokens": 660, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.84997116805678, "lm_q1q2_score": 0.7540983248270702}} {"text": "subroutine SphericalCapCoef(coef, theta, lmax, exitstatus)\n!------------------------------------------------------------------------------\n!\n! This routine will return the coefficients for a spherical\n! cap (located at the north pole) with angular radius theta,\n! using the geodesy 4-pi normalization.\n!\n! Calling Parameters\n!\n! IN\n! theta Angular radius of spherical cap in RADIANS.\n!\n! OUT\n! coef m=0 coefficients normalized according to the\n! geodesy convention, further normalized such\n! that the degree-0 term is 1. (i.e., function\n! has an average value of one over the entire\n! sphere).\n!\n! OPTIONAL\n! lmax Maximum spherical harmonic degree.\n!\n! OPTIONAL (OUT)\n! exitstatus If present, instead of executing a STOP when an error\n! is encountered, the variable exitstatus will be\n! returned describing the error.\n! 0 = No errors;\n! 1 = Improper dimensions of input array;\n! 2 = Improper bounds for input variable;\n! 3 = Error allocating memory;\n! 4 = File IO error.\n!\n! Copyright (c) 2005-2019, SHTOOLS\n! All rights reserved.\n!\n!-------------------------------------------------------------------------------\n use SHTOOLS, only: PlBar\n use ftypes\n\n implicit none\n\n real(dp), intent(out) :: coef(:)\n real(dp), intent(in) :: theta\n integer(int32), intent(in), optional :: lmax\n integer(int32), intent(out), optional :: exitstatus\n real(dp) :: x, top, bot, pi\n real(dp), allocatable :: pl(:)\n integer(int32) :: l, lmax2, astat\n\n if (present(exitstatus)) exitstatus = 0\n\n pi = acos(-1.0_dp)\n coef = 0.0_dp\n x = cos(theta)\n\n if (present(lmax) ) then\n lmax2 = lmax\n\n else\n lmax2 = size(coef) - 1\n\n end if\n\n allocate (pl(lmax2+3), stat = astat)\n\n if(astat /= 0) then\n print*, \"Error --- SphericalCapCoef\"\n print*, \"Unable to allocate array pl\", astat\n if (present(exitstatus)) then\n exitstatus = 3\n return\n else\n stop\n end if\n\n end if\n\n if (present(exitstatus)) then\n call PlBar(pl, lmax2+2, x, exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call PlBar(pl, lmax2+2, x)\n end if\n\n coef(1) = 1.0_dp\n\n bot = pl(1) - pl(2) / sqrt(3.0_dp)\n\n do l = 1, lmax2\n top = pl(l) / sqrt(dble(2*l-1)) -pl(l+2) / sqrt(dble(2*l+3))\n coef(l+1) = top / (bot * sqrt(dble(2*l+1)))\n\n end do\n\n deallocate (pl)\n\nend subroutine SphericalCapCoef\n", "meta": {"hexsha": "5f6c12d4743a11b4b351da9249d9c634a7e04994", "size": 2770, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/SphericalCapCoef.f95", "max_stars_repo_name": "mjc87/SHTOOLS", "max_stars_repo_head_hexsha": "8d83c42d1313d5624c4db8c2e57300c5d819834e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 251, "max_stars_repo_stars_event_min_datetime": "2015-01-27T12:58:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T17:19:36.000Z", "max_issues_repo_path": "src/SphericalCapCoef.f95", "max_issues_repo_name": "mjc87/SHTOOLS", "max_issues_repo_head_hexsha": "8d83c42d1313d5624c4db8c2e57300c5d819834e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 193, "max_issues_repo_issues_event_min_datetime": "2015-03-11T06:21:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T14:05:45.000Z", "max_forks_repo_path": "src/SphericalCapCoef.f95", "max_forks_repo_name": "mreineck/SHTOOLS", "max_forks_repo_head_hexsha": "fec33f203ee0b47008fd69d4080304d6ebd272e7", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 100, "max_forks_repo_forks_event_min_datetime": "2015-04-03T07:11:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T23:46:33.000Z", "avg_line_length": 28.2653061224, "max_line_length": 80, "alphanum_fraction": 0.5133574007, "num_tokens": 727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.84997116805678, "lm_q1q2_score": 0.7540983197571689}} {"text": "module kernel_utils_mod\n\nuse globals_mod\nuse equations_mod, only: N_VARS\n\nprivate\n\npublic :: kernel_utils_init\npublic :: interpolate2visual \n\n!! -------------------------------------------------------------------------- !!\n!! nodes within reference element [-1,1]\n\nreal(dp), save, public :: refnodes(N_NODES)\nreal(dp), save, public :: refweights(N_NODES)\nreal(dp), save, public :: refweights2D(N_NODES,N_NODES)\n\n!! ------------------------------------------------------------------------- !!\n!! Weak-Form Standard DG operators (on Legendre-Gauss nodes)\n\nreal(dp), save, public :: diffMat(N_NODES,N_NODES)\n\nreal(dp), save, public :: surfMat(N_NODES,N_NODES)\nreal(dp), save, public :: surfTam(N_NODES,N_NODES)\n\n!! ------------------------------------------------------------------------- !!\n!! Visualization operator\n\nreal(dp), save :: visuMat(N_NODES,N_NODES)\nreal(dp), save :: visuTam(N_NODES,N_NODES)\n\ncontains\n\n!! ========================================================================== !!\n!! Routines regarding Lagrange polynomials as well as quadrature points generation\n\npure function lagrange_polynomial(N, nodes, j, x) result(lp)\n \n integer, intent(in) :: N\n real(dp), intent(in) :: nodes(N)\n integer, intent(in) :: j\n real(dp), intent(in) :: x\n\n real(dp) :: lp\n\n integer :: i\n\n lp = 1.0\n\n if (abs(x-nodes(j)) < 10*TOL) return !! Kronecker property\n\n do i = 1,N\n if (i == j) cycle\n lp = lp * (x - nodes(i))/(nodes(j) - nodes(i))\n end do\n \nend function\n\npure function lagrange_basis(N, nodes, x) result(lp)\n \n integer, intent(in) :: N\n real(dp), intent(in) :: nodes(N)\n real(dp), intent(in) :: x\n\n real(dp) :: lp(N)\n integer :: i\n\n !! Kronecker property\n if (any(abs(x-nodes) < 10*TOL)) then\n lp = merge(1.0,0.0,abs(x-nodes) < 10*TOL)\n return\n end if\n\n forall (i = 1:N) lp(i) = Lagrange_Polynomial(N, nodes, i, x)\n \nend function\n\npure subroutine lagrange_VanderMonde_Matrix(N, M, xs, ys, mat)\n\n integer, intent(in) :: N,M\n real(dp), intent(in) :: xs(N), ys(M)\n real(dp), intent(out) :: mat(M,N)\n\n integer :: i\n\n do i = 1,M\n mat(i,:) = Lagrange_Basis(N, xs, ys(i))\n end do\n\nend subroutine\n\nsubroutine barycentric_weights(N,nodes,weights)\n\n integer,intent(in) :: N\n real(dp),intent(in) :: nodes(N)\n real(dp),intent(out) :: weights(N)\n\n integer :: i,j\n\n weights = 1.0_dp\n\n do i = 2,N\n do j = 1,i-1\n weights(j) = weights(j)*(nodes(j) - nodes(i))\n weights(i) = weights(i)*(nodes(i) - nodes(j))\n end do\n end do\n\n weights = 1.0_dp/weights\n\nend subroutine\n\nsubroutine lagrange_diff_matrix(N,nodes,diffMat)\n\n integer,intent(in) :: N !! number of nodes\n real(dp),intent(in) :: nodes(N)\n real(dp),intent(out) :: diffMat(N,N)\n\n integer :: i,j\n real(dp) :: bweights(N)\n\n call barycentric_weights(N,nodes,bweights)\n\n diffMat = 0.0_dp\n\n do j = 1,N\n do i = 1,N\n if (i.ne.j) then\n diffMat(i,j) = bweights(j)/(bweights(i)*(nodes(i) - nodes(j)))\n diffMat(i,i) = diffMat(i,i) - diffMat(i,j)\n end if\n end do\n end do\n\nend subroutine\n\npure subroutine q_and_L_evaluation(p,x,q,dq,L_N)\n\n integer, intent(in) :: p !! polynomial order\n real(dp), intent(in) :: x\n real(dp), intent(out) :: L_n,q,dq\n\n integer :: k\n real(dp) :: L_n_1,L_n_2,L_k,dL_n,dL_n_1,dL_n_2,dL_k\n\n L_N_2 = 1.0_dp\n L_N_1 = x\n dL_N_2 = 0.0_dp\n dL_N_1 = 1.0_dp\n\n do k = 2,p\n L_N = (2.0_dp*real(k,dp) - 1.0_dp)/real(k,dp)*x*L_N_1 - (real(k,dp)-1.0_dp)/real(k,dp)*L_N_2\n dL_N = dL_N_2 + (2.0_dp*real(k,dp) - 1.0_dp) * L_N_1\n L_N_2 = L_N_1\n L_N_1 = L_N\n dL_N_2 = dL_N_1\n dL_N_1 = dL_N\n end do\n\n !! take another step\n k = p+1\n L_k = (2.0_dp*real(k,dp) - 1.0_dp)/real(k,dp)*x*L_N - (real(k,dp) - 1.0_dp)/real(k,dp)*L_N_2\n dL_k = dL_N_2 + (2.0_dp*real(k,dp) - 1.0_dp) * L_N_1\n q = L_k - L_N_2\n dq = dL_k - dL_N_2\n\nend subroutine\n\npure subroutine equidistant_nodes_and_weights(N,nodes,weights)\n\n integer,intent(in) :: N\n real(dp),intent(out) :: nodes(N)\n real(dp),intent(out),optional :: weights(N)\n\n integer :: i\n\n do i = 1,N\n nodes(i) = -1.0 + 2.0*(real(i,dp)-0.5)/real(N,dp)\n end do\n\n weights = 2.0/real(N,dp)\n\nend subroutine\n\npure subroutine Legendre_Gauss_Lobatto_Nodes_And_Weights(N,nodes,weights)\n\n integer, intent(in) :: N !! number of nodes\n real(dp), intent(out) :: nodes(N)\n real(dp), intent(out) :: weights(N)\n\n integer, parameter :: niter = 10\n real(dp) :: q,dq,L_n,delta\n\n integer :: i,j\n\n nodes(1) = -1.0_dp\n weights(1) = 2.0_dp / (real(N-1,dp)*real(N,dp))\n\n nodes(N) = -nodes(1)\n weights(N) = weights(1)\n\n if (N < 3) return\n \n do i = 2,N/2\n !! initial guess\n nodes(i) = -cos(((real(i-1,dp)+0.25_dp)*pi)/real(N-1,dp) - (3.0_dp/(8.0_dp*real(N-1,dp)*pi)) * (1.0_dp/(real(i-1,dp)+0.25_dp)))\n\n !! Newton iteration\n do j = 1,niter\n call q_And_L_Evaluation(N-1,nodes(i),q,dq,L_N)\n\n delta = q/dq\n nodes(i) = nodes(i) - delta\n\n if (abs(delta) < 10*tol*abs(nodes(i))) exit\n end do\n\n call q_And_L_Evaluation(N-1,nodes(i),q,dq,L_N)\n\n weights(i) = 2.0_dp / (real(N-1,dp)*real(N,dp) * L_N*L_N)\n\n nodes(N+1-i) = -nodes(i)\n weights(N+1-i) = weights(i)\n end do\n\n if (mod(N+1,2) == 0) then\n call q_And_L_Evaluation(N-1,0.0_dp,q,dq,L_N)\n\n nodes(N/2+1) = 0.0_dp\n weights(N/2+1) = 2.0_dp / (real(N-1,dp) * real(N,dp) * L_N*L_N)\n end if\n\nend subroutine\n\n!! ========================================================================== !!\n!! public routines\n\nsubroutine kernel_utils_init()\n\n integer, parameter :: N = N_NODES\n\n real(dp) :: fvnodes(N_NODES), fvweights(N_NODES)\n real(dp) :: dgnodes(N_NODES), dgweights(N_NODES)\n\n integer :: i,j\n\n call Equidistant_Nodes_And_Weights(N_NODES,fvnodes,fvweights)\n\n !! This implementation of the 'strong form' only valid for Gauss-Lobatto nodes!\n call Legendre_Gauss_Lobatto_Nodes_And_Weights(N_NODES,dgnodes,dgweights)\n\n !! --------------------------------------------------------------------- !!\n !! Surface Term Matrix (also called Stiffness Matrix)\n\n surfMat(:,:) = 0.0_dp\n surfMat(1,1) = 2.0_dp/dgweights(1)\n surfMat(N,N) = -2.0_dp/dgweights(N)\n surfTam = transpose(surfMat)\n\n !! --------------------------------------------------------------------- !!\n !! Volume Term Matrix (flux differencing form)\n\n call lagrange_Diff_Matrix(N_NODES,dgnodes,diffMat)\n diffMat = 4.0_dp*diffMat + surfMat\n\n !! --------------------------------------------------------------------- !!\n !! Visualization Matrix\n\n call lagrange_VanderMonde_Matrix(N_NODES,N_NODES,dgnodes,fvnodes,visuMat)\n visuTam = transpose(visuMat)\n\n !! --------------------------------------------------------------------- !!\n\n refnodes = dgnodes\n refweights = dgweights\n\n !! Scaled it to unity.\n do j = 1,N_NODES; do i = 1,N_NODES\n refweights2D(i,j) = 0.25*refweights(i)*refweights(j)\n end do; end do\n\n !! --------------------------------------------------------------------- !!\n\n# if 0\n write (*,*) 'fvnodes', fvnodes\n write (*,*) 'dgnodes', dgnodes\n write (*,*) 'dgweights', dgweights\n write (*,*)\n\n write (*,*) 'toBoundaryVec{M,P}'\n write (*,'(32(ES12.4))') toBoundaryVecM\n write (*,'(32(ES12.4))') toBoundaryVecP\n write (*,*)\n\n write (*,*) 'diffMat'\n do i = 1,N_NODES\n write (*,'(32(ES12.4))') diffMat(i,:)\n end do\n write (*,*)\n\n write (*,*) 'surfMat'\n do i = 1,N_NODES\n write (*,'(32(ES12.4))') surfmat(i,:)\n end do\n write (*,*)\n# endif\n\nend subroutine\n\npure subroutine interpolate2visual(input,output)\n\n real(dp), intent(in) :: input(N_NODES,N_NODES)\n real(dp), intent(out) :: output(N_NODES,N_NODES)\n \n output = matmul(visuMat,matmul(input,visuTam))\n\nend subroutine\n\nend module\n", "meta": {"hexsha": "8b0fe51ff538982f6483172130e400a14c53f648", "size": 8295, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/kernel/dg/splitform/kernel_utils_mod.f90", "max_stars_repo_name": "jmark/nemo2d", "max_stars_repo_head_hexsha": "a508f192d0f6da49e485ee9c8d1c049dbb81d033", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/kernel/dg/splitform/kernel_utils_mod.f90", "max_issues_repo_name": "jmark/nemo2d", "max_issues_repo_head_hexsha": "a508f192d0f6da49e485ee9c8d1c049dbb81d033", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/kernel/dg/splitform/kernel_utils_mod.f90", "max_forks_repo_name": "jmark/nemo2d", "max_forks_repo_head_hexsha": "a508f192d0f6da49e485ee9c8d1c049dbb81d033", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.921875, "max_line_length": 135, "alphanum_fraction": 0.5210367691, "num_tokens": 2564, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425223682085, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7540087755124092}} {"text": "module mod_union_find\n implicit none\n type union_find\n integer :: n\n integer, pointer :: par(:), rnk(:), siz(:)\n end type union_find\n private\n public :: union_find\n public :: init_union_find, release_union_find, find, same, unite, size_of\ncontains\n subroutine init_union_find(uf,n)\n implicit none\n type(union_find), intent(inout) :: uf\n integer, intent(in) :: n\n integer :: i\n uf%n = n\n allocate(uf%par(n),uf%rnk(n),uf%siz(n))\n uf%rnk = 0\n uf%siz = 1\n do i = 1, n\n uf%par(i) = i\n end do\n return\n end subroutine init_union_find\n subroutine release_union_find(uf)\n implicit none\n type(union_find), intent(inout) :: uf\n if (associated(uf%par)) deallocate(uf%par)\n if (associated(uf%rnk)) deallocate(uf%rnk)\n if (associated(uf%siz)) deallocate(uf%siz)\n return\n end subroutine release_union_find\n recursive function find(uf,i) result(j)\n implicit none\n type(union_find), intent(inout) :: uf\n integer, intent(in) :: i\n integer :: j\n if (uf%par(i).ne.i) then\n uf%par(i) = find(uf,uf%par(i))\n end if\n j = uf%par(i)\n return\n end function find\n function same(uf,i,j) result(y)\n implicit none\n type(union_find), intent(inout) :: uf\n integer, intent(in) :: i, j\n logical :: y\n y = find(uf,i).eq.find(uf,j)\n end function same\n subroutine unite(uf,i,j)\n implicit none\n type(union_find), intent(inout) :: uf\n integer, intent(in) :: i, j\n integer :: x, y\n x = find(uf,i)\n y = find(uf,j)\n if (x.eq.y) return\n if (uf%rnk(x).lt.uf%rnk(y)) then\n uf%par(x) = y\n uf%siz(y) = uf%siz(y)+uf%siz(x)\n else\n uf%par(y) = x\n uf%siz(x) = uf%siz(x)+uf%siz(y)\n if (uf%rnk(x).eq.uf%rnk(y)) uf%rnk(x) = uf%rnk(x)+1\n end if\n return\n end subroutine unite\n function size_of(uf,i) result(s)\n implicit none\n type(union_find), intent(inout) :: uf\n integer, intent(in) :: i\n integer :: s\n s = uf%siz(find(uf,i))\n end function size_of\nend module mod_union_find\n", "meta": {"hexsha": "d98c1eab2362d41d7b0f6f9ca90e989a0025c261", "size": 2015, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran90/union_find.f90", "max_stars_repo_name": "ue1221/fortran-utilities", "max_stars_repo_head_hexsha": "83037ee4e199e33f8d4774a9928fbfddeba2930e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran90/union_find.f90", "max_issues_repo_name": "ue1221/fortran-utilities", "max_issues_repo_head_hexsha": "83037ee4e199e33f8d4774a9928fbfddeba2930e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran90/union_find.f90", "max_forks_repo_name": "ue1221/fortran-utilities", "max_forks_repo_head_hexsha": "83037ee4e199e33f8d4774a9928fbfddeba2930e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.1688311688, "max_line_length": 75, "alphanum_fraction": 0.6129032258, "num_tokens": 673, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970904940926, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7538311969063575}} {"text": "module interpolation\n\npublic :: spline\npublic :: spline_interpolation\n\n!==================================================================================================!\ncontains\n!==================================================================================================!\n\nsubroutine spline(x,y,n,yp1,ypn,y2)\n!----\n! (From Press et al., Numerical Recipes)\n!\n! Given arrays x(1:n) and y(1:n) containing a tabulated function, i.e., yi = f(xi),\n! with x1 < x2 < ... < xN, and given values yp1 and ypn for the first derivative of the\n! interpolating function at points 1 and n, respectively, this routine returns an\n! array y2(1:n) of length n which contains the second derivatives of the interpolating\n! function at the tabulated points xi. If yp1 and/or ypn are equal to 1 × 10^30 or larger,\n! the routine is signaled to set the corresponding boundary condition for a natural spline,\n! with zero second derivative on that boundary.\n!\n! Parameter: NMAX is the largest anticipated value of n.\n!----\n\nimplicit none\n\n! Arguments\ninteger :: n\ndouble precision :: yp1, ypn, x(n), y(n), y2(n)\n\n! Local variables\ninteger, parameter :: nmax = 500\ninteger :: i, k\ndouble precision :: p, qn, sig, un, u(nmax)\n\n! Set the lower boundary condition to be natural or specified first derivative\nif (abs(yp1).ge.1.0d30) then\n y2(1) = 0.0d0\n u(1) = 0.0d0\nelse\n y2(1) = -0.5d0\n u(1) = (3.0d0/(x(2)-x(1)))*((y(2)-y(1))/(x(2)-x(1))-yp1)\nendif\n\n! Tridiagonal algorithm\ndo i = 2,n-1\n sig = (x(i)-x(i-1))/(x(i+1)-x(i-1))\n p = sig*y2(i-1)+2.0d0\n y2(i) = (sig-1.0d0)/p\n u(i) = (6.0d0*( &\n (y(i+1)-y(i))/(x(i+1)-x(i))-(y(i)-y(i-1))/(x(i)-x(i-1)) &\n )/(x(i+1)-x(i-1))-sig*u(i-1))/p\nenddo\n\n! Set the upper boundary condition to be natural or specified first derivative\nif (abs(ypn).gt.1.0d30) then\n qn = 0.0d0\n un = 0.0d0\nelse\n qn = 0.5d0\n un = (3.0d0/(x(n)-x(n-1)))*(ypn-(y(n)-y(n-1))/(x(n)-x(n-1)))\nendif\n\ny2(n) = (un-qn*u(n-1))/(qn*y2(n-1)+1.0d0)\n\n! Back-substitution of the tridiagonal algorithm\ndo k = n-1,1,-1\n y2(k) = y2(k)*y2(k+1)+u(k)\nenddo\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine spline_interpolation(xa,ya,y2a,n,x,y,dy,d2y)\n!----\n! (From Press et al., Numerical Recipes)\n!\n! Given the arrays xa(1:n) and ya(1:n) of length n, which tabulate a function (with the xai’s in\n! order), and given the array y2a(1:n), which is the output from spline above, and given a value\n! of x, this routine returns a cubic-spline interpolated value y.\n!----\n\nimplicit none\n\n! Arguments\ninteger :: n\ndouble precision :: x, y, dy, d2y, xa(n), y2a(n), ya(n)\n\n! Local variables\ninteger :: k, khi, klo\ndouble precision :: a, b, h\n\nklo = 1\nkhi = n\n\n! We will find the right place in the table by means of bisection. This is optimal if sequential\n! calls to this routine are at random values of x. If sequential calls are in order, and closely\n! spaced, one would do better to store previous values of klo and khi and test if they remain\n! appropriate on the next call.\n\n! khi and klo bracket the input value of x\ndo while (khi-klo.gt.1)\n k = (khi+klo)/2\n if (xa(k).gt.x) then\n khi = k\n else\n klo = k\n endif\nenddo\n\nh = xa(khi)-xa(klo)\n\n! The xa's must be distinct\nif (abs(h).lt.1.0d-10) then\n write(0,*) 'spline_interpolation: bad xa input'\nendif\n\n! Evaluate cubic spline polynomial value, derivative, and second derivative\na = (xa(khi)-x)/h\nb = (x-xa(klo))/h\ny = a*ya(klo) + b*ya(khi) + &\n ((a**3-a)*y2a(klo)+(b**3-b)*y2a(khi))*(h**2)/6.0d0\ndy = (ya(khi)-ya(klo))/(xa(khi)-xa(klo)) - &\n (3.0d0*a**2-1.0d0)*(xa(khi)-xa(klo))*y2a(klo)/6.0d0 + &\n (3.0d0*b**2-1.0d0)*(xa(khi)-xa(klo))*y2a(khi)/6.0d0\nd2y = a*y2a(klo) + b*y2a(khi)\n\nreturn\nend subroutine\n\nend module\n", "meta": {"hexsha": "57725bb5273bc05905b93f4c5ccbf123d25d9165", "size": 3829, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/interpolation_module.f90", "max_stars_repo_name": "mherman09/ElasticHalfspaceToolbox", "max_stars_repo_head_hexsha": "168b9391654f6d3940f8778789ec7642574a523a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-05-07T03:34:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-11T16:08:50.000Z", "max_issues_repo_path": "src/interpolation_module.f90", "max_issues_repo_name": "mherman09/ElasticHalfspaceToolbox", "max_issues_repo_head_hexsha": "168b9391654f6d3940f8778789ec7642574a523a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-10-09T19:27:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-04T13:17:03.000Z", "max_forks_repo_path": "src/interpolation_module.f90", "max_forks_repo_name": "mherman09/Hdef", "max_forks_repo_head_hexsha": "2b1606bb69810ddcfe59ea23601d14a30b840ea8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.5746268657, "max_line_length": 100, "alphanum_fraction": 0.5886654479, "num_tokens": 1308, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.7538252371010865}} {"text": "subroutine spline (n, x, y, b, c, d)\n integer n\n real(kind=8) ::x(n), y(n), b(n), c(n), d(n)\n!\n! the coefficients b(i), c(i), and d(i), i=1,2,...,n are computed\n! for a cubic interpolating spline\n!\n! s(x) = y(i) + b(i)*(x-x(i)) + c(i)*(x-x(i))**2 + d(i)*(x-x(i))**3\n!\n! for x(i) .le. x .le. x(i+1)\n!\n! input..\n!\n! n = the number of data points or knots (n.ge.2)\n! x = the abscissas of the knots in strictly increasing order\n! y = the ordinates of the knots\n!\n! output..\n!\n! b, c, d = arrays of spline coefficients as defined above.\n!\n! using p to denote differentiation,\n!\n! y(i) = s(x(i))\n! b(i) = sp(x(i))\n! c(i) = spp(x(i))/2\n! d(i) = sppp(x(i))/6 (derivative from the right)\n!\n! the accompanying function subprogram seval can be used\n! to evaluate the spline.\n!\n!\n integer nm1, ib, i\n real(kind=8) ::t\n\n nm1 = n-1\n if (n < 2) then\n return\n elseif ( n == 2 ) then\n b(1) = (y(2)-y(1))/(x(2)-x(1))\n c(1) = 0.\n d(1) = 0.\n b(2) = b(1)\n c(2) = 0.\n d(2) = 0.\n return\n else\n\n!\n! set up tridiagonal system\n!\n! b = diagonal, d = offdiagonal, c = right hand side.\n!\n d(1) = x(2) - x(1)\n c(2) = (y(2) - y(1))/d(1)\n do i = 2, nm1\n d(i) = x(i+1) - x(i)\n b(i) = 2.*(d(i-1) + d(i))\n c(i+1) = (y(i+1) - y(i))/d(i)\n c(i) = c(i+1) - c(i)\n enddo\n!\n! end conditions. third derivatives at x(1) and x(n)\n! obtained from divided differences\n!\n b(1) = -d(1)\n b(n) = -d(n-1)\n c(1) = 0.\n c(n) = 0.\n if ( n /= 3 ) then\n c(1) = c(3)/(x(4)-x(2)) - c(2)/(x(3)-x(1))\n c(n) = c(n-1)/(x(n)-x(n-2)) - c(n-2)/(x(n-1)-x(n-3))\n c(1) = c(1)*d(1)**2/(x(4)-x(1))\n c(n) = -c(n)*d(n-1)**2/(x(n)-x(n-3))\n endif\n!\n! forward elimination\n!\n do i = 2, n\n t = d(i-1)/b(i-1)\n b(i) = b(i) - t*d(i-1)\n c(i) = c(i) - t*c(i-1)\n enddo\n!\n! back substitution\n!\n c(n) = c(n)/b(n)\n do ib = 1, nm1\n i = n-ib\n c(i) = (c(i) - d(i)*c(i+1))/b(i)\n enddo\n!\n! c(i) is now the sigma(i) of the text\n!\n! compute polynomial coefficients\n!\n b(n) = (y(n) - y(nm1))/d(nm1) + d(nm1)*(c(nm1) + 2.*c(n))\n do i = 1, nm1\n b(i) = (y(i+1) - y(i))/d(i) - d(i)*(c(i+1) + 2.*c(i))\n d(i) = (c(i+1) - c(i))/d(i)\n c(i) = 3.*c(i)\n enddo\n c(n) = 3.*c(n)\n d(n) = d(n-1)\n return\n endif\n\nend subroutine spline\n\nreal(kind=8) function seval(n, u, x, y, b, c, d)\n\n implicit none\n integer n\n real(kind=8) :: u, x(n), y(n), b(n), c(n), d(n)\n!\n! this subroutine evaluates the cubic spline function\n!\n! seval = y(i) + b(i)*(u-x(i)) + c(i)*(u-x(i))**2 + d(i)*(u-x(i))**3\n!\n! where x(i) .lt. u .lt. x(i+1), using horner's rule\n!\n! if u .lt. x(1) then i = 1 is used.\n! if u .ge. x(n) then i = n is used.\n!\n! input..\n!\n! n = the number of data points\n! u = the abscissa at which the spline is to be evaluated\n! x,y = the arrays of data abscissas and ordinates\n! b,c,d = arrays of spline coefficients computed by spline\n!\n! if u is not in the same interval as the previous call, then a\n! binary search is performed to determine the proper interval.\n!\n integer i, j, k\n real(kind=8) ::dx\n data i/1/\n if ( i >= n ) i = 1\n if ( u < x(i) ) go to 10\n if ( u <= x(i+1) ) go to 30\n!\n! binary search\n!\n 10 i = 1\n j = n+1\n 20 k = (i+j)/2\n if ( u < x(k) ) j = k\n if ( u >= x(k) ) i = k\n if ( j > i+1 ) go to 20\n!\n! evaluate spline\n!\n 30 dx = u - x(i)\n seval = y(i) + dx*(b(i) + dx*(c(i) + dx*d(i)))\n return\n\nend function seval\n", "meta": {"hexsha": "d483684e55bc887fe3d3314c4769f04759e03f98", "size": 3499, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "TC-programs/DMP/source_binary/spline.f90", "max_stars_repo_name": "sklinkusch/scripts", "max_stars_repo_head_hexsha": "a717cadb559db823a0d5172545661d5afa2715e7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "TC-programs/DMP/source_binary/spline.f90", "max_issues_repo_name": "sklinkusch/scripts", "max_issues_repo_head_hexsha": "a717cadb559db823a0d5172545661d5afa2715e7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TC-programs/DMP/source_binary/spline.f90", "max_forks_repo_name": "sklinkusch/scripts", "max_forks_repo_head_hexsha": "a717cadb559db823a0d5172545661d5afa2715e7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.1455696203, "max_line_length": 71, "alphanum_fraction": 0.485281509, "num_tokens": 1508, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467157, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7538233168953904}} {"text": "subroutine calc_bpf_order(fl, fh, fs, ap, as, sample, m, n, c)\n use constants, only : pi\n implicit none\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !!! Butterworth band-pass filter by Saito(1978) \n !!! fl: low frequency cut-off (Hz) not normalized \n !!! fh: high frequency cut-off (Hz) not normalized \n !!! fs: stopped frequency (Hz) not normalized \n !!! Ap: maximum attenuation in fp (usually 0.5) \n !!! As: minimum attenuation in fs (usually 5.0) \n !!! sample: sampling interval (sec) \n !!! m: order of filter \n !!! n: order of butterworth function \n !!! c: filter coefficient \n !!! \n !!! Usage: \n !!! 1. call calc_bpf_order(fl, fh, fs, ap, as, sample, m, n, c)\n !!! 2. allocate filter coefficient allocate(h(4 * m)) \n !!! 3. call calc_bpf_coef(fl, fh, sample, m, n, h, c, gn) \n !!! 4. call tandem(data, data, ndata, h, m, nml) \n !!!\n !!! Author : Masashi Ogiso (masashi.ogiso@gmail.com)\n !!! Reference: Saito, M. (1978) An automatic design algorithm for band selective recursive\n !!! digital filters, Geophysical Exploration, 31(4), 240-263 (In Japanese)\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n real*8, intent(IN) :: fl,fh, fs, ap, as, sample\n integer, intent(OUT) :: m, n\n real*8, intent(OUT) :: c\n\n real*8 :: sigma_fl, sigma_fh, sigma_fs, op, os\n\n sigma_fl = pi * fl * sample\n sigma_fh = pi * fh * sample\n sigma_fs = abs(fs * sample) * pi\n\n op = sin(sigma_fh - sigma_fl) / (cos(sigma_fl) * cos(sigma_fh))\n os = abs(tan(sigma_fs) - tan(sigma_fh) * tan(sigma_fl) / tan(sigma_fs))\n\n n = max(2, ifix(abs(real(log(as / ap) / log(op / os))) + 0.5))\n m = n\n c = sqrt(exp(log(ap * as) / dble(n)) / (op * os))\n\n return\nend subroutine calc_bpf_order\n\n", "meta": {"hexsha": "3a3977b72072039681423e06817e3992793eb92a", "size": 2121, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "calc_bpf_order.f90", "max_stars_repo_name": "mogiso/AmplitudeSourceLocation", "max_stars_repo_head_hexsha": "ad00d36e0b14c0e1262b88c4bc2caf04e0570140", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2020-10-30T10:43:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-26T06:21:37.000Z", "max_issues_repo_path": "calc_bpf_order.f90", "max_issues_repo_name": "mogiso/AmplitudeSourceLocation", "max_issues_repo_head_hexsha": "ad00d36e0b14c0e1262b88c4bc2caf04e0570140", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc_bpf_order.f90", "max_forks_repo_name": "mogiso/AmplitudeSourceLocation", "max_forks_repo_head_hexsha": "ad00d36e0b14c0e1262b88c4bc2caf04e0570140", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-18T12:00:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T12:00:20.000Z", "avg_line_length": 45.1276595745, "max_line_length": 104, "alphanum_fraction": 0.4733616219, "num_tokens": 557, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810466522863, "lm_q2_score": 0.7956581097540519, "lm_q1q2_score": 0.7537914127961733}} {"text": "C\nC file hw3crt.f\nC\n SUBROUTINE HW3CRT (XS,XF,L,LBDCND,BDXS,BDXF,YS,YF,M,MBDCND,BDYS,\n 1 BDYF,ZS,ZF,N,NBDCND,BDZS,BDZF,ELMBDA,LDIMF,\n 2 MDIMF,F,PERTRB,IERROR,W)\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC * *\nC * copyright (c) 1999 by UCAR *\nC * *\nC * UNIVERSITY CORPORATION for ATMOSPHERIC RESEARCH *\nC * *\nC * all rights reserved *\nC * *\nC * FISHPACK version 4.1 *\nC * *\nC * A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE SOLUTION OF *\nC * *\nC * SEPARABLE ELLIPTIC PARTIAL DIFFERENTIAL EQUATIONS *\nC * *\nC * BY *\nC * *\nC * JOHN ADAMS, PAUL SWARZTRAUBER AND ROLAND SWEET *\nC * *\nC * OF *\nC * *\nC * THE NATIONAL CENTER FOR ATMOSPHERIC RESEARCH *\nC * *\nC * BOULDER, COLORADO (80307) U.S.A. *\nC * *\nC * WHICH IS SPONSORED BY *\nC * *\nC * THE NATIONAL SCIENCE FOUNDATION *\nC * *\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC\nC\nC DIMENSION OF BDXS(MDIMF,N+1), BDXF(MDIMF,N+1),\nC ARGUMENTS BDYS(LDIMF,N+1), BDYF(LDIMF,N+1),\nC BDZS(LDIMF,M+1), BDZF(LDIMF,M+1),\nC F(LDIMF,MDIMF,N+1), W(SEE ARGUMENT LIST)\nC\nC LATEST REVISION NOVEMBER 1988\nC\nC PURPOSE SOLVES THE STANDARD FIVE-POINT FINITE\nC DIFFERENCE APPROXIMATION TO THE HELMHOLTZ\nC EQUATION IN CARTESIAN COORDINATES. THIS\nC EQUATION IS\nC\nC (D/DX)(DU/DX) + (D/DY)(DU/DY) +\nC (D/DZ)(DU/DZ) + LAMBDA*U = F(X,Y,Z) .\nC\nC USAGE CALL HW3CRT (XS,XF,L,LBDCND,BDXS,BDXF,YS,YF,M,\nC MBDCND,BDYS,BDYF,ZS,ZF,N,NBDCND,\nC BDZS,BDZF,ELMBDA,LDIMF,MDIMF,F,\nC PERTRB,IERROR,W)\nC\nC ARGUMENTS\nC\nC ON INPUT XS,XF\nC\nC THE RANGE OF X, I.E. XS .LE. X .LE. XF .\nC XS MUST BE LESS THAN XF.\nC\nC L\nC THE NUMBER OF PANELS INTO WHICH THE\nC INTERVAL (XS,XF) IS SUBDIVIDED.\nC HENCE, THERE WILL BE L+1 GRID POINTS\nC IN THE X-DIRECTION GIVEN BY\nC X(I) = XS+(I-1)DX FOR I=1,2,...,L+1,\nC WHERE DX = (XF-XS)/L IS THE PANEL WIDTH.\nC L MUST BE AT LEAST 5.\nC\nC LBDCND\nC INDICATES THE TYPE OF BOUNDARY CONDITIONS\nC AT X = XS AND X = XF.\nC\nC = 0 IF THE SOLUTION IS PERIODIC IN X,\nC I.E. U(L+I,J,K) = U(I,J,K).\nC = 1 IF THE SOLUTION IS SPECIFIED AT\nC X = XS AND X = XF.\nC = 2 IF THE SOLUTION IS SPECIFIED AT\nC X = XS AND THE DERIVATIVE OF THE\nC SOLUTION WITH RESPECT TO X IS\nC SPECIFIED AT X = XF.\nC = 3 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO X IS SPECIFIED AT\nC X = XS AND X = XF.\nC = 4 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO X IS SPECIFIED AT\nC X = XS AND THE SOLUTION IS SPECIFIED\nC AT X=XF.\nC\nC BDXS\nC A TWO-DIMENSIONAL ARRAY THAT SPECIFIES THE\nC VALUES OF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO X AT X = XS.\nC\nC WHEN LBDCND = 3 OR 4,\nC\nC BDXS(J,K) = (D/DX)U(XS,Y(J),Z(K)),\nC J=1,2,...,M+1, K=1,2,...,N+1.\nC\nC WHEN LBDCND HAS ANY OTHER VALUE, BDXS\nC IS A DUMMY VARIABLE. BDXS MUST BE\nC DIMENSIONED AT LEAST (M+1)*(N+1).\nC\nC BDXF\nC A TWO-DIMENSIONAL ARRAY THAT SPECIFIES THE\nC VALUES OF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO X AT X = XF.\nC\nC WHEN LBDCND = 2 OR 3,\nC\nC BDXF(J,K) = (D/DX)U(XF,Y(J),Z(K)),\nC J=1,2,...,M+1, K=1,2,...,N+1.\nC\nC WHEN LBDCND HAS ANY OTHER VALUE, BDXF IS\nC A DUMMY VARIABLE. BDXF MUST BE\nC DIMENSIONED AT LEAST (M+1)*(N+1).\nC\nC YS,YF\nC THE RANGE OF Y, I.E. YS .LE. Y .LE. YF.\nC YS MUST BE LESS THAN YF.\nC\nC M\nC THE NUMBER OF PANELS INTO WHICH THE\nC INTERVAL (YS,YF) IS SUBDIVIDED.\nC HENCE, THERE WILL BE M+1 GRID POINTS IN\nC THE Y-DIRECTION GIVEN BY Y(J) = YS+(J-1)DY\nC FOR J=1,2,...,M+1,\nC WHERE DY = (YF-YS)/M IS THE PANEL WIDTH.\nC M MUST BE AT LEAST 5.\nC\nC MBDCND\nC INDICATES THE TYPE OF BOUNDARY CONDITIONS\nC AT Y = YS AND Y = YF.\nC\nC = 0 IF THE SOLUTION IS PERIODIC IN Y, I.E.\nC U(I,M+J,K) = U(I,J,K).\nC = 1 IF THE SOLUTION IS SPECIFIED AT\nC Y = YS AND Y = YF.\nC = 2 IF THE SOLUTION IS SPECIFIED AT\nC Y = YS AND THE DERIVATIVE OF THE\nC SOLUTION WITH RESPECT TO Y IS\nC SPECIFIED AT Y = YF.\nC = 3 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO Y IS SPECIFIED AT\nC Y = YS AND Y = YF.\nC = 4 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO Y IS SPECIFIED AT\nC AT Y = YS AND THE SOLUTION IS\nC SPECIFIED AT Y=YF.\nC\nC BDYS\nC A TWO-DIMENSIONAL ARRAY THAT SPECIFIES\nC THE VALUES OF THE DERIVATIVE OF THE\nC SOLUTION WITH RESPECT TO Y AT Y = YS.\nC\nC WHEN MBDCND = 3 OR 4,\nC\nC BDYS(I,K) = (D/DY)U(X(I),YS,Z(K)),\nC I=1,2,...,L+1, K=1,2,...,N+1.\nC\nC WHEN MBDCND HAS ANY OTHER VALUE, BDYS\nC IS A DUMMY VARIABLE. BDYS MUST BE\nC DIMENSIONED AT LEAST (L+1)*(N+1).\nC\nC BDYF\nC A TWO-DIMENSIONAL ARRAY THAT SPECIFIES\nC THE VALUES OF THE DERIVATIVE OF THE\nC SOLUTION WITH RESPECT TO Y AT Y = YF.\nC\nC WHEN MBDCND = 2 OR 3,\nC\nC BDYF(I,K) = (D/DY)U(X(I),YF,Z(K)),\nC I=1,2,...,L+1, K=1,2,...,N+1.\nC\nC WHEN MBDCND HAS ANY OTHER VALUE, BDYF\nC IS A DUMMY VARIABLE. BDYF MUST BE\nC DIMENSIONED AT LEAST (L+1)*(N+1).\nC\nC ZS,ZF\nC THE RANGE OF Z, I.E. ZS .LE. Z .LE. ZF.\nC ZS MUST BE LESS THAN ZF.\nC\nC N\nC THE NUMBER OF PANELS INTO WHICH THE\nC INTERVAL (ZS,ZF) IS SUBDIVIDED.\nC HENCE, THERE WILL BE N+1 GRID POINTS\nC IN THE Z-DIRECTION GIVEN BY\nC Z(K) = ZS+(K-1)DZ FOR K=1,2,...,N+1,\nC WHERE DZ = (ZF-ZS)/N IS THE PANEL WIDTH.\nC N MUST BE AT LEAST 5.\nC\nC NBDCND\nC INDICATES THE TYPE OF BOUNDARY CONDITIONS\nC AT Z = ZS AND Z = ZF.\nC\nC = 0 IF THE SOLUTION IS PERIODIC IN Z, I.E.\nC U(I,J,N+K) = U(I,J,K).\nC = 1 IF THE SOLUTION IS SPECIFIED AT\nC Z = ZS AND Z = ZF.\nC = 2 IF THE SOLUTION IS SPECIFIED AT\nC Z = ZS AND THE DERIVATIVE OF THE\nC SOLUTION WITH RESPECT TO Z IS\nC SPECIFIED AT Z = ZF.\nC = 3 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO Z IS SPECIFIED AT\nC Z = ZS AND Z = ZF.\nC = 4 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO Z IS SPECIFIED AT\nC Z = ZS AND THE SOLUTION IS SPECIFIED\nC AT Z=ZF.\nC\nC BDZS\nC A TWO-DIMENSIONAL ARRAY THAT SPECIFIES\nC THE VALUES OF THE DERIVATIVE OF THE\nC SOLUTION WITH RESPECT TO Z AT Z = ZS.\nC\nC WHEN NBDCND = 3 OR 4,\nC\nC BDZS(I,J) = (D/DZ)U(X(I),Y(J),ZS),\nC I=1,2,...,L+1, J=1,2,...,M+1.\nC\nC WHEN NBDCND HAS ANY OTHER VALUE, BDZS\nC IS A DUMMY VARIABLE. BDZS MUST BE\nC DIMENSIONED AT LEAST (L+1)*(M+1).\nC\nC BDZF\nC A TWO-DIMENSIONAL ARRAY THAT SPECIFIES\nC THE VALUES OF THE DERIVATIVE OF THE\nC SOLUTION WITH RESPECT TO Z AT Z = ZF.\nC\nC WHEN NBDCND = 2 OR 3,\nC\nC BDZF(I,J) = (D/DZ)U(X(I),Y(J),ZF),\nC I=1,2,...,L+1, J=1,2,...,M+1.\nC\nC WHEN NBDCND HAS ANY OTHER VALUE, BDZF\nC IS A DUMMY VARIABLE. BDZF MUST BE\nC DIMENSIONED AT LEAST (L+1)*(M+1).\nC\nC ELMBDA\nC THE CONSTANT LAMBDA IN THE HELMHOLTZ\nC EQUATION. IF LAMBDA .GT. 0, A SOLUTION\nC MAY NOT EXIST. HOWEVER, HW3CRT WILL\nC ATTEMPT TO FIND A SOLUTION.\nC\nC LDIMF\nC THE ROW (OR FIRST) DIMENSION OF THE\nC ARRAYS F,BDYS,BDYF,BDZS,AND BDZF AS IT\nC APPEARS IN THE PROGRAM CALLING HW3CRT.\nC THIS PARAMETER IS USED TO SPECIFY THE\nC VARIABLE DIMENSION OF THESE ARRAYS.\nC LDIMF MUST BE AT LEAST L+1.\nC\nC MDIMF\nC THE COLUMN (OR SECOND) DIMENSION OF THE\nC ARRAY F AND THE ROW (OR FIRST) DIMENSION\nC OF THE ARRAYS BDXS AND BDXF AS IT APPEARS\nC IN THE PROGRAM CALLING HW3CRT. THIS\nC PARAMETER IS USED TO SPECIFY THE VARIABLE\nC DIMENSION OF THESE ARRAYS.\nC MDIMF MUST BE AT LEAST M+1.\nC\nC F\nC A THREE-DIMENSIONAL ARRAY OF DIMENSION AT\nC AT LEAST (L+1)*(M+1)*(N+1), SPECIFYING THE\nC VALUES OF THE RIGHT SIDE OF THE HELMHOLZ\nC EQUATION AND BOUNDARY VALUES (IF ANY).\nC\nC ON THE INTERIOR, F IS DEFINED AS FOLLOWS:\nC FOR I=2,3,...,L, J=2,3,...,M,\nC AND K=2,3,...,N\nC F(I,J,K) = F(X(I),Y(J),Z(K)).\nC\nC ON THE BOUNDARIES, F IS DEFINED AS FOLLOWS:\nC FOR J=1,2,...,M+1, K=1,2,...,N+1,\nC AND I=1,2,...,L+1\nC\nC LBDCND F(1,J,K) F(L+1,J,K)\nC ------ --------------- ---------------\nC\nC 0 F(XS,Y(J),Z(K)) F(XS,Y(J),Z(K))\nC 1 U(XS,Y(J),Z(K)) U(XF,Y(J),Z(K))\nC 2 U(XS,Y(J),Z(K)) F(XF,Y(J),Z(K))\nC 3 F(XS,Y(J),Z(K)) F(XF,Y(J),Z(K))\nC 4 F(XS,Y(J),Z(K)) U(XF,Y(J),Z(K))\nC\nC MBDCND F(I,1,K) F(I,M+1,K)\nC ------ --------------- ---------------\nC\nC 0 F(X(I),YS,Z(K)) F(X(I),YS,Z(K))\nC 1 U(X(I),YS,Z(K)) U(X(I),YF,Z(K))\nC 2 U(X(I),YS,Z(K)) F(X(I),YF,Z(K))\nC 3 F(X(I),YS,Z(K)) F(X(I),YF,Z(K))\nC 4 F(X(I),YS,Z(K)) U(X(I),YF,Z(K))\nC\nC NBDCND F(I,J,1) F(I,J,N+1)\nC ------ --------------- ---------------\nC\nC 0 F(X(I),Y(J),ZS) F(X(I),Y(J),ZS)\nC 1 U(X(I),Y(J),ZS) U(X(I),Y(J),ZF)\nC 2 U(X(I),Y(J),ZS) F(X(I),Y(J),ZF)\nC 3 F(X(I),Y(J),ZS) F(X(I),Y(J),ZF)\nC 4 F(X(I),Y(J),ZS) U(X(I),Y(J),ZF)\nC\nC NOTE:\nC IF THE TABLE CALLS FOR BOTH THE SOLUTION\nC U AND THE RIGHT SIDE F ON A BOUNDARY,\nC THEN THE SOLUTION MUST BE SPECIFIED.\nC\nC W\nC A ONE-DIMENSIONAL ARRAY THAT MUST BE\nC PROVIDED BY THE USER FOR WORK SPACE.\nC THE LENGTH OF W MUST BE AT LEAST\nC 30 + L + M + 5*N + MAX(L,M,N) +\nC 7*(INT((L+1)/2) + INT((M+1)/2))\nC\nC\nC\nC\nC ON OUTPUT F\nC CONTAINS THE SOLUTION U(I,J,K) OF THE\nC FINITE DIFFERENCE APPROXIMATION FOR THE\nC GRID POINT (X(I),Y(J),Z(K)) FOR\nC I=1,2,...,L+1, J=1,2,...,M+1,\nC AND K=1,2,...,N+1.\nC\nC PERTRB\nC IF A COMBINATION OF PERIODIC OR DERIVATIVE\nC BOUNDARY CONDITIONS IS SPECIFIED FOR A\nC POISSON EQUATION (LAMBDA = 0), A SOLUTION\nC MAY NOT EXIST. PERTRB IS A CONSTANT,\nC CALCULATED AND SUBTRACTED FROM F, WHICH\nC ENSURES THAT A SOLUTION EXISTS. PWSCRT\nC THEN COMPUTES THIS SOLUTION, WHICH IS A\nC LEAST SQUARES SOLUTION TO THE ORIGINAL\nC APPROXIMATION. THIS SOLUTION IS NOT\nC UNIQUE AND IS UNNORMALIZED. THE VALUE OF\nC PERTRB SHOULD BE SMALL COMPARED TO THE\nC THE RIGHT SIDE F. OTHERWISE, A SOLUTION\nC IS OBTAINED TO AN ESSENTIALLY DIFFERENT\nC PROBLEM. THIS COMPARISON SHOULD ALWAYS\nC BE MADE TO INSURE THAT A MEANINGFUL\nC SOLUTION HAS BEEN OBTAINED.\nC\nC IERROR\nC AN ERROR FLAG THAT INDICATES INVALID INPUT\nC PARAMETERS. EXCEPT FOR NUMBERS 0 AND 12,\nC A SOLUTION IS NOT ATTEMPTED.\nC\nC = 0 NO ERROR\nC = 1 XS .GE. XF\nC = 2 L .LT. 5\nC = 3 LBDCND .LT. 0 .OR. LBDCND .GT. 4\nC = 4 YS .GE. YF\nC = 5 M .LT. 5\nC = 6 MBDCND .LT. 0 .OR. MBDCND .GT. 4\nC = 7 ZS .GE. ZF\nC = 8 N .LT. 5\nC = 9 NBDCND .LT. 0 .OR. NBDCND .GT. 4\nC = 10 LDIMF .LT. L+1\nC = 11 MDIMF .LT. M+1\nC = 12 LAMBDA .GT. 0\nC\nC SINCE THIS IS THE ONLY MEANS OF INDICATING\nC A POSSIBLY INCORRECT CALL TO HW3CRT, THE\nC USER SHOULD TEST IERROR AFTER THE CALL.\nC\nC SPECIAL CONDITIONS NONE\nC\nC I/O NONE\nC\nC PRECISION SINGLE\nC\nC REQUIRED LIBRARY POIS3D, FFTPACK, AND COMF FROM FISHPACK\nC FILES\nC\nC LANGUAGE FORTRAN\nC\nC HISTORY WRITTEN BY ROLAND SWEET AT NCAR IN THE LATE\nC 1970'S. RELEASED ON NCAR'S PUBLIC SOFTWARE\nC LIBRARIES IN JANUARY 1980.\nC\nC PORTABILITY FORTRAN 77\nC\nC ALGORITHM THIS SUBROUTINE DEFINES THE FINITE DIFFERENCE\nC EQUATIONS, INCORPORATES BOUNDARY DATA, AND\nC ADJUSTS THE RIGHT SIDE OF SINGULAR SYSTEMS AND\nC THEN CALLS POIS3D TO SOLVE THE SYSTEM.\nC\nC TIMING FOR LARGE L, M AND N, THE OPERATION COUNT\nC IS ROUGHLY PROPORTIONAL TO\nC L*M*N*(LOG2(L)+LOG2(M)+5),\nC BUT ALSO DEPENDS ON INPUT PARAMETERS LBDCND\nC AND MBDCND.\nC\nC ACCURACY THE SOLUTION PROCESS EMPLOYED RESULTS IN\nC A LOSS OF NO MORE THAN FOUR SIGNIFICANT\nC DIGITS FOR L, M AND N AS LARGE AS 32.\nC MORE DETAILED INFORMATION ABOUT ACCURACY\nC CAN BE FOUND IN THE DOCUMENTATION FOR\nC ROUTINE POIS3D WHICH IS THE ROUTINE THAT\nC ACTUALLY SOLVES THE FINITE DIFFERENCE\nC EQUATIONS.\nC\nC REFERENCES NONE\nC***********************************************************************\n DIMENSION BDXS(MDIMF,*) ,BDXF(MDIMF,*) ,\n 1 BDYS(LDIMF,*) ,BDYF(LDIMF,*) ,\n 2 BDZS(LDIMF,*) ,BDZF(LDIMF,*) ,\n 3 F(LDIMF,MDIMF,*) ,W(*)\nC\nC CHECK FOR INVALID INPUT.\nC\n IERROR = 0\n IF (XF .LE. XS) IERROR = 1\n IF (L .LT. 5) IERROR = 2\n IF (LBDCND.LT.0 .OR. LBDCND.GT.4) IERROR = 3\n IF (YF .LE. YS) IERROR = 4\n IF (M .LT. 5) IERROR = 5\n IF (MBDCND.LT.0 .OR. MBDCND.GT.4) IERROR = 6\n IF (ZF .LE. ZS) IERROR = 7\n IF (N .LT. 5) IERROR = 8\n IF (NBDCND.LT.0 .OR. NBDCND.GT.4) IERROR = 9\n IF (LDIMF .LT. L+1) IERROR = 10\n IF (MDIMF .LT. M+1) IERROR = 11\n IF (IERROR .NE. 0) GO TO 188\n DY = (YF-YS)/FLOAT(M)\n TWBYDY = 2./DY\n C2 = 1./(DY**2)\n MSTART = 1\n MSTOP = M\n MP1 = M+1\n MP = MBDCND+1\n GO TO (104,101,101,102,102),MP\n 101 MSTART = 2\n 102 GO TO (104,104,103,103,104),MP\n 103 MSTOP = MP1\n 104 MUNK = MSTOP-MSTART+1\n DZ = (ZF-ZS)/FLOAT(N)\n TWBYDZ = 2./DZ\n NP = NBDCND+1\n C3 = 1./(DZ**2)\n NP1 = N+1\n NSTART = 1\n NSTOP = N\n GO TO (108,105,105,106,106),NP\n 105 NSTART = 2\n 106 GO TO (108,108,107,107,108),NP\n 107 NSTOP = NP1\n 108 NUNK = NSTOP-NSTART+1\n LP1 = L+1\n DX = (XF-XS)/FLOAT(L)\n C1 = 1./(DX**2)\n TWBYDX = 2./DX\n LP = LBDCND+1\n LSTART = 1\n LSTOP = L\nC\nC ENTER BOUNDARY DATA FOR X-BOUNDARIES.\nC\n GO TO (122,109,109,112,112),LP\n 109 LSTART = 2\n DO 111 J=MSTART,MSTOP\n DO 110 K=NSTART,NSTOP\n F(2,J,K) = F(2,J,K)-C1*F(1,J,K)\n 110 CONTINUE\n 111 CONTINUE\n GO TO 115\n 112 DO 114 J=MSTART,MSTOP\n DO 113 K=NSTART,NSTOP\n F(1,J,K) = F(1,J,K)+TWBYDX*BDXS(J,K)\n 113 CONTINUE\n 114 CONTINUE\n 115 GO TO (122,116,119,119,116),LP\n 116 DO 118 J=MSTART,MSTOP\n DO 117 K=NSTART,NSTOP\n F(L,J,K) = F(L,J,K)-C1*F(LP1,J,K)\n 117 CONTINUE\n 118 CONTINUE\n GO TO 122\n 119 LSTOP = LP1\n DO 121 J=MSTART,MSTOP\n DO 120 K=NSTART,NSTOP\n F(LP1,J,K) = F(LP1,J,K)-TWBYDX*BDXF(J,K)\n 120 CONTINUE\n 121 CONTINUE\n 122 LUNK = LSTOP-LSTART+1\nC\nC ENTER BOUNDARY DATA FOR Y-BOUNDARIES.\nC\n GO TO (136,123,123,126,126),MP\n 123 DO 125 I=LSTART,LSTOP\n DO 124 K=NSTART,NSTOP\n F(I,2,K) = F(I,2,K)-C2*F(I,1,K)\n 124 CONTINUE\n 125 CONTINUE\n GO TO 129\n 126 DO 128 I=LSTART,LSTOP\n DO 127 K=NSTART,NSTOP\n F(I,1,K) = F(I,1,K)+TWBYDY*BDYS(I,K)\n 127 CONTINUE\n 128 CONTINUE\n 129 GO TO (136,130,133,133,130),MP\n 130 DO 132 I=LSTART,LSTOP\n DO 131 K=NSTART,NSTOP\n F(I,M,K) = F(I,M,K)-C2*F(I,MP1,K)\n 131 CONTINUE\n 132 CONTINUE\n GO TO 136\n 133 DO 135 I=LSTART,LSTOP\n DO 134 K=NSTART,NSTOP\n F(I,MP1,K) = F(I,MP1,K)-TWBYDY*BDYF(I,K)\n 134 CONTINUE\n 135 CONTINUE\n 136 CONTINUE\nC\nC ENTER BOUNDARY DATA FOR Z-BOUNDARIES.\nC\n GO TO (150,137,137,140,140),NP\n 137 DO 139 I=LSTART,LSTOP\n DO 138 J=MSTART,MSTOP\n F(I,J,2) = F(I,J,2)-C3*F(I,J,1)\n 138 CONTINUE\n 139 CONTINUE\n GO TO 143\n 140 DO 142 I=LSTART,LSTOP\n DO 141 J=MSTART,MSTOP\n F(I,J,1) = F(I,J,1)+TWBYDZ*BDZS(I,J)\n 141 CONTINUE\n 142 CONTINUE\n 143 GO TO (150,144,147,147,144),NP\n 144 DO 146 I=LSTART,LSTOP\n DO 145 J=MSTART,MSTOP\n F(I,J,N) = F(I,J,N)-C3*F(I,J,NP1)\n 145 CONTINUE\n 146 CONTINUE\n GO TO 150\n 147 DO 149 I=LSTART,LSTOP\n DO 148 J=MSTART,MSTOP\n F(I,J,NP1) = F(I,J,NP1)-TWBYDZ*BDZF(I,J)\n 148 CONTINUE\n 149 CONTINUE\nC\nC DEFINE A,B,C COEFFICIENTS IN W-ARRAY.\nC\n 150 CONTINUE\n IWB = NUNK+1\n IWC = IWB+NUNK\n IWW = IWC+NUNK\n DO 151 K=1,NUNK\n I = IWC+K-1\n W(K) = C3\n W(I) = C3\n I = IWB+K-1\n W(I) = -2.*C3+ELMBDA\n 151 CONTINUE\n GO TO (155,155,153,152,152),NP\n 152 W(IWC) = 2.*C3\n 153 GO TO (155,155,154,154,155),NP\n 154 W(IWB-1) = 2.*C3\n 155 CONTINUE\n PERTRB = 0.\nC\nC FOR SINGULAR PROBLEMS ADJUST DATA TO INSURE A SOLUTION WILL EXIST.\nC\n GO TO (156,172,172,156,172),LP\n 156 GO TO (157,172,172,157,172),MP\n 157 GO TO (158,172,172,158,172),NP\n 158 IF (ELMBDA) 172,160,159\n 159 IERROR = 12\n GO TO 172\n 160 CONTINUE\n MSTPM1 = MSTOP-1\n LSTPM1 = LSTOP-1\n NSTPM1 = NSTOP-1\n XLP = (2+LP)/3\n YLP = (2+MP)/3\n ZLP = (2+NP)/3\n S1 = 0.\n DO 164 K=2,NSTPM1\n DO 162 J=2,MSTPM1\n DO 161 I=2,LSTPM1\n S1 = S1+F(I,J,K)\n 161 CONTINUE\n S1 = S1+(F(1,J,K)+F(LSTOP,J,K))/XLP\n 162 CONTINUE\n S2 = 0.\n DO 163 I=2,LSTPM1\n S2 = S2+F(I,1,K)+F(I,MSTOP,K)\n 163 CONTINUE\n S2 = (S2+(F(1,1,K)+F(1,MSTOP,K)+F(LSTOP,1,K)+F(LSTOP,MSTOP,K))/\n 1 XLP)/YLP\n S1 = S1+S2\n 164 CONTINUE\n S = (F(1,1,1)+F(LSTOP,1,1)+F(1,1,NSTOP)+F(LSTOP,1,NSTOP)+\n 1 F(1,MSTOP,1)+F(LSTOP,MSTOP,1)+F(1,MSTOP,NSTOP)+\n 2 F(LSTOP,MSTOP,NSTOP))/(XLP*YLP)\n DO 166 J=2,MSTPM1\n DO 165 I=2,LSTPM1\n S = S+F(I,J,1)+F(I,J,NSTOP)\n 165 CONTINUE\n 166 CONTINUE\n S2 = 0.\n DO 167 I=2,LSTPM1\n S2 = S2+F(I,1,1)+F(I,1,NSTOP)+F(I,MSTOP,1)+F(I,MSTOP,NSTOP)\n 167 CONTINUE\n S = S2/YLP+S\n S2 = 0.\n DO 168 J=2,MSTPM1\n S2 = S2+F(1,J,1)+F(1,J,NSTOP)+F(LSTOP,J,1)+F(LSTOP,J,NSTOP)\n 168 CONTINUE\n S = S2/XLP+S\n PERTRB = (S/ZLP+S1)/((FLOAT(LUNK+1)-XLP)*(FLOAT(MUNK+1)-YLP)*\n 1 (FLOAT(NUNK+1)-ZLP))\n DO 171 I=1,LUNK\n DO 170 J=1,MUNK\n DO 169 K=1,NUNK\n F(I,J,K) = F(I,J,K)-PERTRB\n 169 CONTINUE\n 170 CONTINUE\n 171 CONTINUE\n 172 CONTINUE\n NPEROD = 0\n IF (NBDCND .EQ. 0) GO TO 173\n NPEROD = 1\n W(1) = 0.\n W(IWW-1) = 0.\n 173 CONTINUE\n CALL POIS3D (LBDCND,LUNK,C1,MBDCND,MUNK,C2,NPEROD,NUNK,W,W(IWB),\n 1 W(IWC),LDIMF,MDIMF,F(LSTART,MSTART,NSTART),IR,W(IWW))\nC\nC FILL IN SIDES FOR PERIODIC BOUNDARY CONDITIONS.\nC\n IF (LP .NE. 1) GO TO 180\n IF (MP .NE. 1) GO TO 175\n DO 174 K=NSTART,NSTOP\n F(1,MP1,K) = F(1,1,K)\n 174 CONTINUE\n MSTOP = MP1\n 175 IF (NP .NE. 1) GO TO 177\n DO 176 J=MSTART,MSTOP\n F(1,J,NP1) = F(1,J,1)\n 176 CONTINUE\n NSTOP = NP1\n 177 DO 179 J=MSTART,MSTOP\n DO 178 K=NSTART,NSTOP\n F(LP1,J,K) = F(1,J,K)\n 178 CONTINUE\n 179 CONTINUE\n 180 CONTINUE\n IF (MP .NE. 1) GO TO 185\n IF (NP .NE. 1) GO TO 182\n DO 181 I=LSTART,LSTOP\n F(I,1,NP1) = F(I,1,1)\n 181 CONTINUE\n NSTOP = NP1\n 182 DO 184 I=LSTART,LSTOP\n DO 183 K=NSTART,NSTOP\n F(I,MP1,K) = F(I,1,K)\n 183 CONTINUE\n 184 CONTINUE\n 185 CONTINUE\n IF (NP .NE. 1) GO TO 188\n DO 187 I=LSTART,LSTOP\n DO 186 J=MSTART,MSTOP\n F(I,J,NP1) = F(I,J,1)\n 186 CONTINUE\n 187 CONTINUE\n 188 CONTINUE\n RETURN\nC\nC REVISION HISTORY---\nC\nC SEPTEMBER 1973 VERSION 1\nC APRIL 1976 VERSION 2\nC JANUARY 1978 VERSION 3\nC DECEMBER 1979 VERSION 3.1\nC FEBRUARY 1985 DOCUMENTATION UPGRADE\nC NOVEMBER 1988 VERSION 3.2, FORTRAN 77 CHANGES\nC-----------------------------------------------------------------------\n END\n", "meta": {"hexsha": "fbf86caa34d8a6d0957ef6e97d1a80ee7cde1160", "size": 27324, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hw3crt.f", "max_stars_repo_name": "ipelupessy/omuse", "max_stars_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2020-03-25T10:02:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T00:28:35.000Z", "max_issues_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hw3crt.f", "max_issues_repo_name": "ipelupessy/omuse", "max_issues_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 45, "max_issues_repo_issues_event_min_datetime": "2020-03-03T16:07:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T09:01:07.000Z", "max_forks_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hw3crt.f", "max_forks_repo_name": "ipelupessy/omuse", "max_forks_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-03-03T13:28:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T09:20:02.000Z", "avg_line_length": 39.7151162791, "max_line_length": 72, "alphanum_fraction": 0.4030156639, "num_tokens": 8054, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342024724487, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7537619309470035}} {"text": "C LAST UPDATE 06/09/94\nC+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nC\n REAL FUNCTION KCOF(R,E,N)\n IMPLICIT NONE\nC\nC Purpose: Calculates the K coefficients for the Fourier-Bessel\nC interpolation of intensity.\nC\nC Calls 0:\nC Called by:\nC\nC-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\nC Parameters:\nC\n REAL TOL\n PARAMETER(TOL=1.0E-06)\nC\nC Arguments:\nC\n REAL R,E\n INTEGER N\nC\nC Local variables:\nC\n REAL DR2\nC\nC External function:\nC\n REAL BESSJ\n EXTERNAL BESSJ\nC\nC-----------------------------------------------------------------------\n IF(ABS(E-R).GT.TOL)THEN \n DR2 = (E+R)*(E-R)\n KCOF = 2.0*E*BESSJ(2*N,R)/(DR2*BESSJ(2*N+1,E))\n ELSE\n KCOF = 1.0\n ENDIF\n RETURN\n END \n", "meta": {"hexsha": "e062e73f6353dfaa8660f4bb8a1a5dac91fb4dda", "size": 844, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "software/sample/KCOF.f", "max_stars_repo_name": "scattering-central/CCP13", "max_stars_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "software/sample/KCOF.f", "max_issues_repo_name": "scattering-central/CCP13", "max_issues_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "software/sample/KCOF.f", "max_forks_repo_name": "scattering-central/CCP13", "max_forks_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-09-05T15:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T11:13:45.000Z", "avg_line_length": 20.0952380952, "max_line_length": 72, "alphanum_fraction": 0.4158767773, "num_tokens": 235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342012360932, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.7537619299728404}} {"text": "! 4670 Numerical Analysis\n! Homework Three Due 10/18/17\n\nmodule secret \n\ninteger :: fcounter\n\nend module secret \n\n\n\nprogram WebberHomework3Question1\nuse secret\nimplicit none\n\ninteger :: i\ninteger :: n\ndouble precision, allocatable, dimension(:) :: a\ndouble precision, allocatable, dimension(:) :: xdata\ndouble precision, allocatable, dimension(:) :: ydata\n\nn = 4\n\nallocate(xdata(0:n), ydata(0:n), a(0:n))\n\nxdata = (/ 2.0d0, 4.0d0, 6.0d0, 5.0d0, 9.0d0 /)\nydata = (/ 12.0d0, 19.0d0, 14.0d0, 17.0d0, 10.0d0 /)\n\nprint*, 'Newtons Divided Difference Coefficients: '\n\ncall divdiff(n, xdata, ydata, a)\n\ndo i = 0, n\n\tprint*, a(i)\nend do\n\ndeallocate(xdata, ydata, a)\n\nstop\nend program WebberHomework3Question1\n\n\n\nsubroutine divdiff(n, xdata, ydata, a)\n\ninteger :: i\ninteger :: j\ninteger :: n\ndouble precision :: a(0:n)\ndouble precision :: xdata(0:n)\ndouble precision :: ydata(0:n)\ndouble precision, allocatable, dimension(:,:) :: T\n\nallocate (T(0:n,0:n))\n\ndo i = 0, n\n\tT(i,0) = ydata(i)\nend do\n\na(0) = ydata(0)\n\ndo i = 1, n\n\tdo j = 1, n\n\t\tT(i,j) = ((T(i,(j - 1)) - T((i - 1),(j - 1))) / (xdata(i) - xdata(i - j)))\n\t\tif (i == j) then\n\t\t\ta(i) = T(i,j)\n\t\tend if\n\tend do\nend do\n\ndeallocate(T)\n\nend subroutine divdiff\n", "meta": {"hexsha": "43b6f2680420ff995878c19c79b4abfc493589b1", "size": 1203, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "4670 Numerical Analysis/Homework3/Homework3Question1.f90", "max_stars_repo_name": "mwebber3/UnderGraduateCourses", "max_stars_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4670 Numerical Analysis/Homework3/Homework3Question1.f90", "max_issues_repo_name": "mwebber3/UnderGraduateCourses", "max_issues_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4670 Numerical Analysis/Homework3/Homework3Question1.f90", "max_forks_repo_name": "mwebber3/UnderGraduateCourses", "max_forks_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.2567567568, "max_line_length": 76, "alphanum_fraction": 0.6450540316, "num_tokens": 458, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7536388069783884}} {"text": "program stencil\n implicit none\n integer, parameter :: nsources=3\n integer :: n=2400 ! n x n grid\n integer :: energy=1 ! energy to be injected per iteration\n integer :: niters=250 ! number of iterations\n integer :: iters, i, j, size, sizeStart, sizeEnd\n integer, dimension(3, 2) :: sources\n double precision, allocatable :: aold(:,:), anew(:,:)\n double precision :: t=0.0, t1=0.0, heat=0.0\n \n call cpu_time(t1)\n t = -t1\n \n size = n + 2\n sizeStart = 2\n sizeEnd = n + 1\n\n allocate(aold(size, size))\n allocate(anew(size, size))\n aold = 0.0\n anew = 0.0\n\n sources(1,:) = (/ n/2, n/2 /)\n sources(2,:) = (/ n/3, n/3 /)\n sources(3,:) = (/ n*4/5, n*8/9 /) ! 8/9 conforme Balaji\n\n do iters = 1, niters, 2\n \n ! iteracao impar: anew <- stencil(aold)\n\n do j = sizeStart, sizeEnd\n do i = sizeStart, sizeEnd\n anew(i,j)=1/2.0*(aold(i,j)+1/4.0*(aold(i-1,j)+aold(i+1,j)+ aold(i,j-1)+aold(i,j+1)))\n enddo\n enddo\n\n do i = 1, nsources\n anew(sources(i,1)+1, sources(i,2)+1) = &\n anew(sources(i,1)+1, sources(i,2)+1) + energy\n enddo\n\n\n ! iteracao par: aold <- stencil(anew)\n\n do j = sizeStart, sizeEnd\n do i = sizeStart, sizeEnd\n aold(i,j)=1/2.0*(anew(i,j)+1/4.0*(anew(i-1,j)+anew(i+1,j)+anew(i,j-1)+anew(i,j+1)))\n enddo\n enddo\n \n do i = 1, nsources\n aold(sources(i,1)+1, sources(i,2)+1) = &\n aold(sources(i,1)+1, sources(i,2)+1) + energy\n enddo\n\n enddo\n \n heat = 0.0\n do j = sizeStart, sizeEnd\n do i = sizeStart, sizeEnd\n heat = heat + aold(i,j)\n end do\n end do\n\n deallocate(aold)\n deallocate(anew)\n\n call cpu_time(t1)\n t = t + t1\n\n write(*, \"('Heat = ' f0.4' | ')\", advance=\"no\") heat\n write(*, \"('Time = 'f0.4)\") t\n\nend\n", "meta": {"hexsha": "805e5fbb3148a7eb6e9056615b6fe937ce12b472", "size": 2025, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sd/heat_seq.f90", "max_stars_repo_name": "efurlanm/hpc", "max_stars_repo_head_hexsha": "77e8e7e8a71e0528b871e79da553a7da1a9cc30a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sd/heat_seq.f90", "max_issues_repo_name": "efurlanm/hpc", "max_issues_repo_head_hexsha": "77e8e7e8a71e0528b871e79da553a7da1a9cc30a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sd/heat_seq.f90", "max_forks_repo_name": "efurlanm/hpc", "max_forks_repo_head_hexsha": "77e8e7e8a71e0528b871e79da553a7da1a9cc30a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.6447368421, "max_line_length": 100, "alphanum_fraction": 0.4819753086, "num_tokens": 695, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.753638806853376}} {"text": "C$Procedure VTMVG ( Vector transpose times matrix times vector )\n \n DOUBLE PRECISION FUNCTION VTMVG ( V1, MATRIX, V2, NROW, NCOL )\n \nC$ Abstract\nC\nC Multiply the transpose of a n-dimensional column vector,\nC a nxm matrix, and a m-dimensional column vector.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC MATRIX, VECTOR\nC\nC$ Declarations\n \n INTEGER NROW\n INTEGER NCOL\n DOUBLE PRECISION V1 ( NROW )\n DOUBLE PRECISION MATRIX ( NROW, NCOL )\n DOUBLE PRECISION V2 ( NCOL )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC V1 I N-dimensional double precision column vector.\nC MATRIX I NxM double precision matrix.\nC V2 I M-dimensional double porecision column vector.\nC NROW I Number of rows in MATRIX (number of rows in V1.)\nC NCOL I Number of columns in MATRIX (number of rows in\nC V2.)\nC\nC The function returns the result of (V1**T * MATRIX * V2 ).\nC\nC$ Detailed_Input\nC\nC V1 is an n-dimensional double precision vector.\nC\nC MATRIX is an n x m double precision matrix.\nC\nC V2 is an m-dimensional double precision vector.\nC\nC NROW is the number of rows in MATRIX. This is also\nC equivalent to the number of rows in the vector V1.\nC\nC NCOL is the number of columns in MATRIX. This is also\nC equivalent to the number of rows in the vector V2.\nC\nC$ Detailed_Output\nC\nC The function returns the double precision value of the equation\nC (V1**T * MATRIX * V2 ).\nC\nC Notice that VTMVG is actually the dot product of the vector\nC resulting from multiplying the transpose of V1 and MATRIX and the\nC vector V2.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Particulars\nC\nC This routine implements the following vector/matrix/vector\nC multiplication:\nC\nC T\nC VTMVG = [ V1 ] | | | |\nC | MATRIX | |V2|\nC | | | |\nC\nC by calculating over all values of the indices K and L from 1 to\nC NROW and 1 to NCOL, respectively, the expression\nC\nC VTMVG = Summation of ( V1(K)*MATRIX(K,L)*V2(L) ) .\nC\nC V1 is a column vector which becomes a row vector when transposed.\nC V2 is a column vector.\nC\nC No checking is performed to determine whether floating point\nC overflow has occurred.\nC\nC$ Examples\nC\nC If V1 = | 1.0D0 | MATRIX = | 2.0D0 0.0D0 | V2 = | 1.0D0 |\nC | | | | | |\nC | 2.0D0 | | 1.0D0 2.0D0 | | 2.0D0 |\nC | | | |\nC | 3.0D0 | | 1.0D0 1.0D0 |\nC\nC NROW = 3\nC NCOL = 2\nC\nC then the value of the function is 21.0D0.\nC\nC$ Restrictions\nC\nC Since no error detection or recovery is implemented, the\nC programmer is required to insure that the inputs to this routine\nC are both valid and within the proper range.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.M. Owen (JPL)\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WMO)\nC\nC-&\n \nC$ Index_Entries\nC\nC n-dimensional vector_transpose times matrix times vector\nC\nC-&\n \n INTEGER K,L\nC\nC Perform the multiplication\nC\n VTMVG = 0.D0\n DO K = 1, NROW\n DO L = 1, NCOL\n VTMVG = VTMVG + V1(K)*MATRIX(K,L)*V2(L)\n END DO\n END DO\n \n RETURN\n END\n", "meta": {"hexsha": "b0b67cb191e5bbe68300924454f5841239eac2ef", "size": 5260, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/vtmvg.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/vtmvg.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/vtmvg.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 29.7175141243, "max_line_length": 72, "alphanum_fraction": 0.6144486692, "num_tokens": 1513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768525822309, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.7536294841116546}} {"text": "MODULE length_interval\n IMPLICIT NONE\n PRIVATE\n PUBLIC :: flatten_method\nCONTAINS\n FUNCTION flatten_method(first_point_coord, second_point_coord) RESULT(interval)\n IMPLICIT NONE\n REAL, DIMENSION (1:3) :: first_point_coord, second_point_coord\n REAL :: interval\n INTEGER :: i\n interval = 0d0\n DO i = 1, 3\n interval = (first_point_coord(i) - second_point_coord(i)) ** 2 + interval\n END DO\n END FUNCTION flatten_method\nEND MODULE length_interval\n\nPROGRAM test_length_interval\n USE length_interval\n IMPLICIT NONE\n REAL, DIMENSION (1:3) :: x, y\n PRINT *, 'This program is used to calculated the interval between two points'\n PRINT *,'Input the first vector'\n READ (*,*) x(1),x(2),x(3)\n PRINT *,'Input the second vector'\n READ (*,*) y(1),y(2),y(3)\n PRINT *,'The length interval is :', flatten_method(x,y)\nEND PROGRAM test_length_interval\n", "meta": {"hexsha": "c6c67a5fff05fbeeb4c604122ca5c906aa8775d4", "size": 871, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "basics/Module/length_interval.f90", "max_stars_repo_name": "ComplicatedPhenomenon/Fortran_Takeoff", "max_stars_repo_head_hexsha": "a13180050367e59a91973af96ab680c2b76097be", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "basics/Module/length_interval.f90", "max_issues_repo_name": "ComplicatedPhenomenon/Fortran_Takeoff", "max_issues_repo_head_hexsha": "a13180050367e59a91973af96ab680c2b76097be", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "basics/Module/length_interval.f90", "max_forks_repo_name": "ComplicatedPhenomenon/Fortran_Takeoff", "max_forks_repo_head_hexsha": "a13180050367e59a91973af96ab680c2b76097be", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0344827586, "max_line_length": 81, "alphanum_fraction": 0.7106773823, "num_tokens": 243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465116437761, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.753545261996552}} {"text": "PROGRAM meulera\n \n! Code converted using TO_F90 by Alan Miller\n! Date: 2004-06-28 Time: 12:58:11\n\n! ==========================================================\n! Purpose: This program computes Euler number En using\n! subroutine EULERA\n! Example: Compute Euler number En for n = 0,2,...,10\n! Computed results:\n\n! n En\n! --------------------------\n! 0 .100000000000D+01\n! 2 -.100000000000D+01\n! 4 .500000000000D+01\n! 6 -.610000000000D+02\n! 8 .138500000000D+04\n! 10 -.505210000000D+05\n! ==========================================================\n\nDOUBLE PRECISION :: e\nDIMENSION e(0:200)\nWRITE(*,*)' Please enter Nmax '\n! READ(*,*)N\nn=10\nCALL eulera(n,e)\nWRITE(*,*)' n En'\nWRITE(*,*)' --------------------------'\nDO k=0,n,2\n WRITE(*,20)k,e(k)\nEND DO\n20 FORMAT(2X,i3,d22.12)\nEND PROGRAM meulera\n\n\nSUBROUTINE eulera(n,en)\n\n! ======================================\n! Purpose: Compute Euler number En\n! Input : n --- Serial number\n! Output: EN(n) --- En\n! ======================================\n\n\nINTEGER, INTENT(IN) :: n\nDOUBLE PRECISION, INTENT(OUT) :: en(0:n)\nIMPLICIT DOUBLE PRECISION (a-h,o-z)\n\n\nen(0)=1.0D0\nDO m=1,n/2\n s=1.0D0\n DO k=1,m-1\n r=1.0D0\n DO j=1,2*k\n r=r*(2.0D0*m-2.0D0*k+j)/j\n END DO\n s=s+r*en(2*k)\n END DO\n en(2*m)=-s\nEND DO\nRETURN\nEND SUBROUTINE eulera\n", "meta": {"hexsha": "72bc5c83930c1365da7acd53018cd598a8535e83", "size": 1608, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MATLAB/f2matlab/comp_spec_func/meulera.f90", "max_stars_repo_name": "vasaantk/bin", "max_stars_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATLAB/f2matlab/comp_spec_func/meulera.f90", "max_issues_repo_name": "vasaantk/bin", "max_issues_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATLAB/f2matlab/comp_spec_func/meulera.f90", "max_forks_repo_name": "vasaantk/bin", "max_forks_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.7384615385, "max_line_length": 66, "alphanum_fraction": 0.414800995, "num_tokens": 489, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.753516400164313}} {"text": " SUBROUTINE lubksb(a,n,np,indx,b)\r\n INTEGER n,np,indx(n)\r\n REAL a(np,np),b(n)\r\n INTEGER i,ii,j,ll\r\n REAL sum\r\n ii=0\r\n do 12 i=1,n\r\n ll=indx(i)\r\n sum=b(ll)\r\n b(ll)=b(i)\r\n if (ii.ne.0)then\r\n do 11 j=ii,i-1\r\n sum=sum-a(i,j)*b(j)\r\n11 continue\r\n else if (sum.ne.0.) then\r\n ii=i\r\n endif\r\n b(i)=sum\r\n12 continue\r\n do 14 i=n,1,-1\r\n sum=b(i)\r\n do 13 j=i+1,n\r\n sum=sum-a(i,j)*b(j)\r\n13 continue\r\n b(i)=sum/a(i,i)\r\n14 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "871ccfd1cb601a3c25cb3392f4fcf8a80db89bd5", "size": 607, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/lubksb.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/lubksb.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/lubksb.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.9310344828, "max_line_length": 39, "alphanum_fraction": 0.4085667216, "num_tokens": 197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.8080672204860317, "lm_q1q2_score": 0.7534849565574062}} {"text": "program projectile\n implicit none\n ! define constants\n real, parameter :: GRAVITY = 9.8\n real, parameter :: PI = 3.1415927\n\n ! Other Local variables\n real :: a, t, u, x, y\n real :: theta, v, vx, vy\n character(len=80) fmt\n\n ! Read values for a, t, and u from terminal\n read(*, *) a, t, u\n\n ! convert angle to radians\n a = a * PI / 180.0\n\n x = u * cos(a) * t\n y = u * sin(a) * t - 0.5 * GRAVITY * t * t\n vx = u * cos(a)\n vy = u * sin(a) - GRAVITY * t\n v = sqrt(vx*vx + vy*vy)\n theta = atan(vy / vx) * 180.0 / PI\n\n fmt = \"('x:', f7.2, ', y:', f7.1)\"\n write(*, fmt) x, y\n fmt = \"('v:', f7.2, ', theta:', f7.2)\"\n write(*, fmt) v, theta\nend program projectile\n", "meta": {"hexsha": "d3191204d2c56a8efc131580b5464e974f71e0fe", "size": 724, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/projectile.f90", "max_stars_repo_name": "apetcho/scicomp", "max_stars_repo_head_hexsha": "a9deece58df59ae88498697d8df07ac4296f4760", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/projectile.f90", "max_issues_repo_name": "apetcho/scicomp", "max_issues_repo_head_hexsha": "a9deece58df59ae88498697d8df07ac4296f4760", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/projectile.f90", "max_forks_repo_name": "apetcho/scicomp", "max_forks_repo_head_hexsha": "a9deece58df59ae88498697d8df07ac4296f4760", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.1333333333, "max_line_length": 47, "alphanum_fraction": 0.5027624309, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362486, "lm_q2_score": 0.8031738034238806, "lm_q1q2_score": 0.7534766354085148}} {"text": "program cdemo2\n complex :: a = (5,3), b = (0.5, 6) ! complex initializer\n real, parameter :: pi = 3.141592653589793 ! The constant \"pi\"\n complex, parameter :: i = (0, 1) ! the imaginary unit \"i\" (sqrt(-1))\n complex :: abdiff, abquot, abpow, aconj, p2cart, newc\n real :: areal, aimag, anorm, rho = 10, theta = pi / 3.0, x = 2.3, y = 3.0\n integer, parameter :: n = 50\n integer :: j\n complex, dimension(0:n-1) :: unit_circle\n\n abdiff = a - b\n abquot = a / b\n abpow = a ** b\n areal = real(a) ! Real part\n aimag = imag(a) ! Imaginary part\n newc = cmplx(x,y) ! Creating a complex on the fly from two reals intrinsically\n ! (initializer only works in declarations)\n newc = x + y*i ! Creating a complex on the fly from two reals arithmetically\n anorm = abs(a) ! Complex norm (or \"modulus\" or \"absolute value\")\n ! (use CABS before Fortran 90)\n aconj = conjg(a) ! Complex conjugate (same as real(a) - i*imag(a))\n p2cart = rho * exp(i * theta) ! Euler's polar complex notation to cartesian complex notation\n ! conversion (use CEXP before Fortran 90)\n\n ! The following creates an array of N evenly spaced points around the complex unit circle\n ! useful for FFT calculations, among other things\n unit_circle = exp(2*i*pi/n * (/ (j, j=0, n-1) /) )\nend program cdemo2\n", "meta": {"hexsha": "c4dd1a6208835b339c00aad5cdf2ae4cadea3ff2", "size": 1521, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Arithmetic-Complex/Fortran/arithmetic-complex-2.f", "max_stars_repo_name": "djgoku/RosettaCodeData", "max_stars_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Task/Arithmetic-Complex/Fortran/arithmetic-complex-2.f", "max_issues_repo_name": "djgoku/RosettaCodeData", "max_issues_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Arithmetic-Complex/Fortran/arithmetic-complex-2.f", "max_forks_repo_name": "djgoku/RosettaCodeData", "max_forks_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.4482758621, "max_line_length": 96, "alphanum_fraction": 0.5555555556, "num_tokens": 436, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.93812402119614, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.7534766315577061}} {"text": " FUNCTION rtsafe(funcd,x1,x2,xacc)\r\n INTEGER MAXIT\r\n REAL rtsafe,x1,x2,xacc\r\n EXTERNAL funcd\r\n PARAMETER (MAXIT=100)\r\n INTEGER j\r\n REAL df,dx,dxold,f,fh,fl,temp,xh,xl\r\n call funcd(x1,fl,df)\r\n call funcd(x2,fh,df)\r\n if((fl.gt.0..and.fh.gt.0.).or.(fl.lt.0..and.fh.lt.0.))pause\r\n *'root must be bracketed in rtsafe'\r\n if(fl.eq.0.)then\r\n rtsafe=x1\r\n return\r\n else if(fh.eq.0.)then\r\n rtsafe=x2\r\n return\r\n else if(fl.lt.0.)then\r\n xl=x1\r\n xh=x2\r\n else\r\n xh=x1\r\n xl=x2\r\n endif\r\n rtsafe=.5*(x1+x2)\r\n dxold=abs(x2-x1)\r\n dx=dxold\r\n call funcd(rtsafe,f,df)\r\n do 11 j=1,MAXIT\r\n if(((rtsafe-xh)*df-f)*((rtsafe-xl)*df-f).ge.0..or. abs(2.*\r\n *f).gt.abs(dxold*df) ) then\r\n dxold=dx\r\n dx=0.5*(xh-xl)\r\n rtsafe=xl+dx\r\n if(xl.eq.rtsafe)return\r\n else\r\n dxold=dx\r\n dx=f/df\r\n temp=rtsafe\r\n rtsafe=rtsafe-dx\r\n if(temp.eq.rtsafe)return\r\n endif\r\n if(abs(dx).lt.xacc) return\r\n call funcd(rtsafe,f,df)\r\n if(f.lt.0.) then\r\n xl=rtsafe\r\n else\r\n xh=rtsafe\r\n endif\r\n11 continue\r\n pause 'rtsafe exceeding maximum iterations'\r\n return\r\n END\r\n", "meta": {"hexsha": "4d552702b566eba1619f625e74b2180ea6ffd2a4", "size": 1343, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/rtsafe.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/rtsafe.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/rtsafe.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.8703703704, "max_line_length": 67, "alphanum_fraction": 0.4854802681, "num_tokens": 455, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164656, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7534766188012216}} {"text": "c program DRDBLAS2\nc>> 1996-06-18 DRDBLAS2 Krogh Minor format change for C conversion.\nc>> 1994-10-19 DRDBLAS2 Krogh Changes to use M77CON\nc>> 1991-11-27 DRDBLAS2 CLL\nc>> 1987-12-09 Lawson Initial Code.\nc\nc Demonstrates the use of BLAS subroutines DROTG, DROT, DAXPY,\nc and DCOPY to implement an algorithm for solving a linear\nc least squares problem using sequential accumulation of the\nc data and Givens orthogonal transformations.\nc YTAB() contains rounded values of -2 + 2*X + 3*Exp(-X)\nc -----------------------------------------------------------------\nc--D replaces \"?\": DR?BLAS2, ?ROTG, ?ROT, ?AXPY, ?COPY\nc -----------------------------------------------------------------\n integer MC, MC1, MXY\n parameter ( MC=3, MC1=MC+1, MXY=11 )\n integer IXY, J, NC, NC1, NXY\n double precision X, XTAB(MXY), Y, YTAB(MXY), W(MC1)\n double precision C, RG(MC1,MC1), S\n double precision COEF(MC), DIV, ESTSD, ZERO(1)\nc\n data XTAB / 0.0d0, .1d0, .2d0, .3d0, .4d0, .5d0,\n * .6d0, .7d0, .8d0, .9d0, 1.0d0 /\n data YTAB / 1.00d0, .91d0, .86d0, .82d0, .81d0, .82d0,\n * .85d0, .89d0, .95d0, 1.02d0, 1.10d0 /\n data NXY, NC / MXY, MC /\n data ZERO(1) / 0.0d0 /\nc -----------------------------------------------------------------\n NC1 = NC + 1\n call DCOPY(MC1*MC1, ZERO, 0, RG, 1)\n do 20 IXY = 1, NXY\n X = XTAB(IXY)\n Y = YTAB(IXY)\nc Build new row of [A:B] in W().\n W(1) = 1.0d0\n W(2) = X\n W(3) = exp(-X)\n W(4) = Y\nc Process W() into [R:G].\n do 10 J = 1, NC\n call DROTG(RG(J,J),W(J),C,S)\n call DROT(NC1-J,RG(J,J+1),MC1,W(J+1),1,C,S)\n 10 continue\n call DROTG(RG(NC1,NC1),W(NC1),C,S)\n 20 continue\nc Begin: Solve triangular system.\n call DCOPY(NC,RG(1,NC1),1,COEF,1)\n do 30 J = NC, 1, -1\n DIV = RG(J,J)\n if (DIV .eq. 0.0d0) then\n print '(''ERROR:ZERO DIVISOR AT J ='', I2)', J\n stop\n end if\n COEF(J) = COEF(J) / DIV\n call DAXPY(J-1,-COEF(J),RG(1,J),1,COEF,1)\n 30 continue\nc End: Solve triangular system.\nc\n print'('' Solution: COEF() = '',3f8.3)',(COEF(J),J=1,NC)\n ESTSD = abs(RG(NC1,NC1)) / sqrt(DBLE(NXY-NC))\n print'(/'' Estimated Std. Dev. of data errors ='',f9.5)', ESTSD\n stop\n end\n", "meta": {"hexsha": "668677be85aeaf1454325e3ff3873fcf045a1013", "size": 2558, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdblas2.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdblas2.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdblas2.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 39.96875, "max_line_length": 71, "alphanum_fraction": 0.4663799844, "num_tokens": 915, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240073565738, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.7534766116025251}} {"text": "module runge_kutta\n implicit none\n public order_4_step, ode_interface\n interface\n function ode_interface(t, y, rpar, ipar)\n integer, intent(in), optional :: ipar(:)\n real(8), intent(in) :: t\n real(8), intent(in) :: y(:)\n real(8), intent(in), optional :: rpar(:)\n real(8) :: ode_interface(size(y)) \n end function ode_interface\n end interface\ncontains\nfunction order_4_step(f, t, y, h, rpar, ipar)\n procedure(ode_interface) :: f\n integer, intent(in), optional :: ipar(:)\n real(8), intent(in) :: t\n real(8), intent(in) :: h\n real(8), intent(in) :: y(:)\n real(8), intent(in), optional :: rpar(:)\n real(8) :: order_4_step(size(y)) \n real(8) :: k(4,size(y))\n integer :: i\n k(1,:) = h/6.d0*f(t, y, rpar, ipar)\n k(2,:) = h/3.d0*f(t + 1.d0/2.d0*h, y + 1.d0/2.d0*k(1,:), rpar, ipar)\n k(3,:) = h/3.d0*f(t + 1.d0/2.d0*h, y + 1.d0/2.d0*k(2,:), rpar, ipar)\n k(4,:) = h/6.d0*f(t + h, y + k(3,:), rpar, ipar)\n do i = 1, size(y)\n order_4_step(i) = y(i) + sum(k(:,i))\n end do\n return\nend function order_4_step\nend module runge_kutta", "meta": {"hexsha": "3afe2a06b0c2baac23a3e8518664a7ea2f2fb48e", "size": 1150, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "runge_kutta.f90", "max_stars_repo_name": "gabrimig/numerial_methods", "max_stars_repo_head_hexsha": "e5017f3db4ad9cae00ead046f07bacd8d5bd49dd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "runge_kutta.f90", "max_issues_repo_name": "gabrimig/numerial_methods", "max_issues_repo_head_hexsha": "e5017f3db4ad9cae00ead046f07bacd8d5bd49dd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-11-09T11:39:01.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-09T11:39:01.000Z", "max_forks_repo_path": "runge_kutta.f90", "max_forks_repo_name": "gabrimig/numerial_methods", "max_forks_repo_head_hexsha": "e5017f3db4ad9cae00ead046f07bacd8d5bd49dd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.8484848485, "max_line_length": 72, "alphanum_fraction": 0.5408695652, "num_tokens": 414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418116217417, "lm_q2_score": 0.8152324983301567, "lm_q1q2_score": 0.7533904378997495}} {"text": "MODULE mo_errormeasures\n\n ! This module contains routines for the masked calculation of\n ! error measures like MSE, RMSE, BIAS, SSE, NSE, KGE, ...\n\n ! Note: all except variance and standard deviation are population and not sample moments,\n ! i.e. they are normally divided by n and not (n-1)\n\n ! Written Aug 2012, Matthias Zink\n ! Modified 2012-2018, Juliane Mai, Stephan Thober, Matthias Cuntz\n\n ! License\n ! -------\n ! This file is part of the JAMS Fortran package, distributed under the MIT License.\n !\n ! Copyright (c) 2012 Matthias Zink, Juliane Mai, Stephan Thober, Matthias Cuntz - mc (at) macu (dot) de\n !\n ! Permission is hereby granted, free of charge, to any person obtaining a copy\n ! of this software and associated documentation files (the \"Software\"), to deal\n ! in the Software without restriction, including without limitation the rights\n ! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n ! copies of the Software, and to permit persons to whom the Software is\n ! furnished to do so, subject to the following conditions:\n !\n ! The above copyright notice and this permission notice shall be included in all\n ! copies or substantial portions of the Software.\n !\n ! THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n ! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n ! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n ! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n ! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n ! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n ! SOFTWARE.\n\n USE mo_kind, ONLY: i4, sp, dp\n\n IMPLICIT NONE\n\n PUBLIC :: BIAS ! Bias\n PUBLIC :: KGE ! Kling-Gupta efficiency measure\n PUBLIC :: LNNSE ! Logarithmic Nash Sutcliffe efficiency\n PUBLIC :: MAE ! Mean of absolute errors\n PUBLIC :: MAE_PROB_ONE ! Mean absolute error of occurence probability with ONE cdf for obs and mod\n ! comment until mo_empcdf is commited\n ! PUBLIC :: MAE_PROB_TWO ! Mean absolute error of occurence probability with TWO separate cdfs for obs and mod\n PUBLIC :: MSE ! Mean of squared errors\n PUBLIC :: NSE ! Nash Sutcliffe efficiency\n PUBLIC :: SSE ! Sum of squared errors\n PUBLIC :: SAE ! Sum of absolute errors\n PUBLIC :: RMSE ! Root mean squared error\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! BIAS\n\n ! PURPOSE\n ! Calculates the bias\n ! BIAS = mean(y) - mean(x)\n !\n ! If an optinal mask is given, the calculations are over those locations that correspond to true values in the mask.\n ! x and y can be single or double precision. The result will have the same numerical precision.\n\n ! CALLING SEQUENCE\n ! out = BIAS(dat, mask=mask)\n\n ! INTENT(IN)\n ! real(sp/dp), dimension(:) :: x, y 1D-array with input numbers\n ! OR\n ! real(sp/dp), dimension(:,:) :: x, y 2D-array with input numbers\n ! OR\n ! real(sp/dp), dimension(:,:,:) :: x, y 3D-array with input numbers\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp) :: BIAS bias\n\n ! INTENT(IN), OPTIONAL\n ! logical :: mask(:) 1D-array of logical values with size(x/y).\n ! OR\n ! logical :: mask(:,:) 2D-array of logical values with size(x/y).\n ! OR\n ! logical :: mask(:,:,:) 3D-array of logical values with size(x/y).\n !\n ! If present, only those locations in vec corresponding to the true values in mask are used.\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! Input values must be floating points.\n\n ! EXAMPLE\n ! vec1 = (/ 1., 2, 3., -999., 5., 6. /)\n ! vec2 = (/ 1., 2, 3., -999., 5., 6. /)\n ! m = BIAS(vec1, vec2, mask=(vec >= 0.))\n ! -> see also example in test directory\n\n ! LITERATURE\n ! None\n\n ! HISTORY\n ! Written, Matthias Zink, Sept 2012\n INTERFACE BIAS\n MODULE PROCEDURE BIAS_1d_sp, BIAS_1d_dp, BIAS_2d_sp, BIAS_2d_dp, BIAS_3d_sp, BIAS_3d_dp\n END INTERFACE BIAS\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! KGE\n\n !> \\brief Kling-Gupta-Efficiency measure.\n\n !> \\details The Kling-Gupta model efficiency coefficient \\f$ KGE \\f$ is\n !> \\f[ KGE = 1 - \\sqrt{( (1-r)^2 + (1-\\alpha)^2 + (1-\\beta)^2 )} \\f]\n !> where \\n\n !> \\f$ r \\f$ = Pearson product-moment correlation coefficient \\n\n !> \\f$ \\alpha \\f$ = ratio of simulated mean to observed mean \\n\n !> \\f$ \\beta \\f$ = ratio of simulated standard deviation to\n !> observed standard deviation \\n\n !> This three measures are calculated between two arrays (1d, 2d, or 3d).\n !> Usually, one is an observation and the second is a modelled variable.\\n\n !>\n !> The higher the KGE the better the observation and simulation are matching.\n !> The upper limit of KGE is 1.\\n\n !>\n !> Therefore, if you apply a minimization algorithm to calibrate regarding\n !> KGE you have to use the objective function\n !> \\f[ obj\\_value = 1.0 - KGE \\f]\n !> which has then the optimum at 0.0.\n !> (Like for the NSE where you always optimize 1-NSE.)\\n\n !>\n\n ! INTENT(IN)\n !> real(sp/dp), dimension(:) :: x, y 1D-array with input numbers\n ! OR\n !> real(sp/dp), dimension(:,:) :: x, y 2D-array with input numbers\n ! OR\n !> real(sp/dp), dimension(:,:,:) :: x, y 3D-array with input numbers\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! None\n\n ! INTENT(IN), OPTIONAL\n !> logical :: mask(:) 1D-array of logical values with size(x/y).\n ! OR\n !> logical :: mask(:,:) 2D-array of logical values with size(x/y).\n ! OR\n !> logical :: mask(:,:,:) 3D-array of logical values with size(x/y).\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RETURN\n !> \\return kge — Kling-Gupta-Efficiency (value less equal 1.0)\n\n ! RESTRICTIONS\n !> \\note Input values must be floating points. \\n\n\n ! EXAMPLE\n ! para = (/ 1., 2, 3., -999., 5., 6. /)\n ! kge = kge(x,y,mask=mask)\n\n ! LITERATURE\n !> Gupta, Hoshin V., et al.\n !> \"Decomposition of the mean squared error and NSE performance criteria:\n !> Implications for improving hydrological modelling.\"\n !> Journal of Hydrology 377.1 (2009): 80-91.\n\n\n ! HISTORY\n !> \\author Rohini Kumar\n !> \\date August 2014\n ! Modified, R. Kumar & O. Rakovec - Sep. 2014\n ! J. Mai - remove double packing of input data (bug)\n ! - KGE instead of 1.0-KGE\n ! - 1d, 2d, 3d, version in sp and dp\n\n INTERFACE KGE\n MODULE PROCEDURE KGE_1d_dp, KGE_2d_dp, KGE_3d_dp, KGE_1d_sp, KGE_2d_sp, KGE_3d_sp\n END INTERFACE KGE\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! LNNSE\n\n ! PURPOSE\n ! Calculates the Logarithmic Nash Sutcliffe Efficiency\n ! LNNSE = sum((ln(y) - ln(x))**2) / sum( (ln(x) - ln(mean(x)))**2 )\n ! where x is the observation and y is the modelled data.\n !\n ! If an optinal mask is given, the calculations are over those locations that correspond to true values in the mask.\n ! Note that the mask is intent inout, since values which are less or equal zero will be masked additionally.\n ! x and y can be single or double precision. The result will have the same numerical precision.\n\n ! CALLING SEQUENCE\n ! out = LNNSE(dat, mask=mask)\n\n ! INTENT(IN)\n ! real(sp/dp), dimension(:) :: x, y 1D-array with input numbers\n ! OR\n ! real(sp/dp), dimension(:,:) :: x, y 2D-array with input numbers\n ! OR\n ! real(sp/dp), dimension(:,:,:) :: x, y 3D-array with input numbers\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp) :: LNNSE Logarithmic Nash Sutcliffe Efficiency\n\n ! INTENT(IN), OPTIONAL\n ! None\n\n ! INTENT(INOUT), OPTIONAL\n ! logical :: mask(:) 1D-array of logical values with size(x/y).\n ! OR\n ! logical :: mask(:,:) 2D-array of logical values with size(x/y).\n ! OR\n ! logical :: mask(:,:,:) 3D-array of logical values with size(x/y).\n !\n ! If present, only those locations in vec corresponding to the true values in mask are used.\n ! The mask will be updated if non-masked values are less equal zero.\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! Input values must be floating points.\n\n ! EXAMPLE\n ! vec1 = (/ 1., 2, 3., -999., 5., 6. /)\n ! vec2 = (/ 1., 2, 3., -999., 5., 6. /)\n ! m = LNNSE(vec1, vec2, mask=(vec >= 0.))\n ! -> see also example in test directory\n\n ! LITERATURE\n ! None\n\n ! HISTORY\n ! Written, Juliane Mai, May 2013\n ! updated, Rohin Kumar, May 2013 ! for mean of logQ\n INTERFACE LNNSE\n MODULE PROCEDURE LNNSE_1d_sp, LNNSE_1d_dp, LNNSE_2d_dp, LNNSE_2d_sp, LNNSE_3d_sp, LNNSE_3d_dp\n END INTERFACE LNNSE\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! MAE\n\n ! PURPOSE\n ! Calculates the mean absolute error\n ! MAE = sum(abs(y - x)) / count(mask)\n !\n ! If an optinal mask is given, the calculations are over those locations that correspond to true values in the mask.\n ! x and y can be single or double precision. The result will have the same numerical precision.\n\n ! CALLING SEQUENCE\n ! out = MAE(dat, mask=mask)\n\n ! INTENT(IN)\n ! real(sp/dp), dimension(:) :: x, y 1D-array with input numbers\n ! OR\n ! real(sp/dp), dimension(:,:) :: x, y 2D-array with input numbers\n ! OR\n ! real(sp/dp), dimension(:,:,:) :: x, y 3D-array with input numbers\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp) :: MAE Mean Absolute Error\n\n ! INTENT(IN), OPTIONAL\n ! logical :: mask(:) 1D-array of logical values with size(x/y).\n ! OR\n ! logical :: mask(:,:) 2D-array of logical values with size(x/y).\n ! OR\n ! logical :: mask(:,:,:) 3D-array of logical values with size(x/y).\n !\n ! If present, only those locations in vec corresponding to the true values in mask are used.\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! Input values must be floating points.\n\n ! EXAMPLE\n ! vec1 = (/ 1., 2, 3., -999., 5., 6. /)\n ! vec2 = (/ 1., 2, 3., -999., 5., 6. /)\n ! m = MAE(vec1, vec2, mask=(vec >= 0.))\n ! -> see also example in test directory\n\n ! LITERATURE\n ! None\n\n ! HISTORY\n ! Written, Matthias Zink, Sept 2012\n INTERFACE MAE\n MODULE PROCEDURE MAE_1d_sp, MAE_1d_dp, MAE_2d_sp, MAE_2d_dp, MAE_3d_sp, MAE_3d_dp\n END INTERFACE MAE\n\n ! ! ------------------------------------------------------------------\n\n ! ! NAME\n ! ! MAE_PROB_TWO\n\n ! ! PURPOSE\n ! ! Calculate mean absolute error of occurence probabilities\n ! ! MAE_PROB_TWO = mean( |P_sim(Q_obs(t)) - P_obs(Q_obs(t))| )\n ! !\n ! ! If an optional mask is given, the calculations are over those locations that correspond to true values in the mask.\n ! ! x and y have to be double precision. The result will have the same numerical precision.\n\n ! ! CALLING SEQUENCE\n ! ! out = MAE_PROB_TWO(dat, mask=mask)\n\n ! ! INTENT(IN)\n ! ! real(sp/dp), dimension(:) :: x, y 1D-array with input numbers\n\n ! ! INTENT(INOUT)\n ! ! None\n\n ! ! INTENT(OUT)\n ! ! real(sp/dp) :: BIAS bias\n\n ! ! INTENT(IN), OPTIONAL\n ! ! logical :: mask(:) 1D-array of logical values with size(x/y).\n ! !\n ! ! If present, only those locations in vec corresponding to the true values in mask are used.\n\n ! ! INTENT(INOUT), OPTIONAL\n ! ! None\n\n ! ! INTENT(OUT), OPTIONAL\n ! ! None\n\n ! ! RESTRICTIONS\n ! ! Input values must be floating points.\n\n ! ! EXAMPLE\n ! ! vec1 = (/ 1., 2, 3., -9999., 5., 6. /)\n ! ! vec2 = (/ 1., 2, 3., -9999., 5., 6. /)\n ! ! m = MAE_PROB_TWO(vec1, vec2, )\n ! ! -> see also example in test directory\n\n ! ! LITERATURE\n ! ! None\n\n ! ! HISTORY\n ! ! Written, Stephan Thober, May 2016\n ! INTERFACE MAE_PROB_TWO\n ! MODULE PROCEDURE MAE_PROB_TWO_1D_DP\n ! END INTERFACE MAE_PROB_TWO\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! MAE_PROB_ONE\n\n ! PURPOSE\n ! Calculate mean absolute error of occurence probabilities\n ! MAE_PROB_ONE = mean( |P_obs(Q_obs(t)) - P_obs(Q_sim(t))| )\n !\n ! If an optional mask is given, the calculations are over those locations that correspond to true values in the mask.\n ! x and y have to be double precision. The result will have the same numerical precision.\n\n ! CALLING SEQUENCE\n ! out = MAE_PROB_ONE(dat, mask=mask)\n\n ! INTENT(IN)\n ! real(sp/dp), dimension(:) :: x, y 1D-array with input numbers\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp) :: BIAS bias\n\n ! INTENT(IN), OPTIONAL\n ! logical :: mask(:) 1D-array of logical values with size(x/y).\n ! If present, only those locations in vec corresponding to\n ! the true values in mask are used.\n ! real(sp/dp), dimension(:) :: cdfx 1D-array with kernel_cumdensity of x\n ! real(sp/dp) :: h Silverman estimate of kernel_density bandwidth for x\n !\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! Input values must be floating points.\n\n ! EXAMPLE\n ! m = MAE_PROB(x, y, mask=mask)\n ! same as\n ! h = kernel_density_h(x, silverman=.true., mask=mask)\n ! cdfx = kernel_cumdensity(x, xout=x, h=h, mask=mask)\n ! m = MAE_PROB(vec1, vec2, mask=vec1, cdfx=cdf, h=h)\n ! but cumdensity of x is calculated outside and h is reused.\n ! -> see also example in test directory\n\n ! LITERATURE\n ! None\n\n ! HISTORY\n ! Written, Stephan Thober, May 2016\n ! Modified, Matthias Cuntz, Jun 2016 - rm dummy=pack(x), cdfx, h\n INTERFACE MAE_PROB_ONE\n MODULE PROCEDURE MAE_PROB_ONE_1D_DP\n END INTERFACE MAE_PROB_ONE\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! MSE\n\n ! PURPOSE\n ! Calculates the mean squared error\n ! MSE = sum((y - x)**2) / count(mask)\n !\n ! If an optinal mask is given, the calculations are over those locations that correspond to true values in the mask.\n ! x and y can be single or double precision. The result will have the same numerical precision.\n\n ! CALLING SEQUENCE\n ! out = MSE(dat, mask=mask)\n\n ! INTENT(IN)\n ! real(sp/dp), dimension(:) :: x, y 1D-array with input numbers\n ! OR\n ! real(sp/dp), dimension(:,:) :: x, y 2D-array with input numbers\n ! OR\n ! real(sp/dp), dimension(:,:,:) :: x, y 3D-array with input numbers\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp) :: MSE Mean squared error\n\n ! INTENT(IN), OPTIONAL\n ! logical :: mask(:) 1D-array of logical values with size(x/y).\n ! OR\n ! logical :: mask(:,:) 2D-array of logical values with size(x/y).\n ! OR\n ! logical :: mask(:,:,:) 3D-array of logical values with size(x/y).\n !\n ! If present, only those locations in vec corresponding to the true values in mask are used.\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! Input values must be floating points.\n\n ! EXAMPLE\n ! vec1 = (/ 1., 2, 3., -999., 5., 6. /)\n ! vec2 = (/ 1., 2, 3., -999., 5., 6. /)\n ! m = MSE(vec1, vec2, mask=(vec >= 0.))\n ! -> see also example in test directory\n\n ! LITERATURE\n ! None\n\n ! HISTORY\n ! Written, Matthias Zink, Sept 2012\n INTERFACE MSE\n MODULE PROCEDURE MSE_1d_sp, MSE_1d_dp, MSE_2d_sp, MSE_2d_dp, MSE_3d_sp, MSE_3d_dp\n END INTERFACE MSE\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! NSE\n\n ! PURPOSE\n ! Calculates the Nash Sutcliffe Efficiency\n ! NSE = sum((y - x)**2) / sum( (x - mean(x))**2)\n ! where x is the observation and y is the modelled data.\n !\n ! If an optinal mask is given, the calculations are over those locations that correspond to true values in the mask.\n ! x and y can be single or double precision. The result will have the same numerical precision.\n\n ! CALLING SEQUENCE\n ! out = NSE(dat, mask=mask)\n\n ! INTENT(IN)\n ! real(sp/dp), dimension(:) :: x, y 1D-array with input numbers\n ! OR\n ! real(sp/dp), dimension(:,:) :: x, y 2D-array with input numbers\n ! OR\n ! real(sp/dp), dimension(:,:,:) :: x, y 3D-array with input numbers\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp) :: NSE Nash Sutcliffe Efficiency\n\n ! INTENT(IN), OPTIONAL\n ! logical :: mask(:) 1D-array of logical values with size(x/y).\n ! OR\n ! logical :: mask(:,:) 2D-array of logical values with size(x/y).\n ! OR\n ! logical :: mask(:,:,:) 3D-array of logical values with size(x/y).\n !\n ! If present, only those locations in vec corresponding to the true values in mask are used.\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! Input values must be floating points.\n\n ! EXAMPLE\n ! vec1 = (/ 1., 2, 3., -999., 5., 6. /)\n ! vec2 = (/ 1., 2, 3., -999., 5., 6. /)\n ! m = NSE(vec1, vec2, mask=(vec >= 0.))\n ! -> see also example in test directory\n\n ! LITERATURE\n ! NASH, J., & SUTCLIFFE, J. (1970). River flow forecasting through conceptual models part I: A discussion of\n ! principles. Journal of Hydrology, 10(3), 282-290. doi:10.1016/0022-1694(70)90255-6\n\n ! HISTORY\n ! Written, Matthias Zink, Sept 2012\n INTERFACE NSE\n MODULE PROCEDURE NSE_1d_sp, NSE_1d_dp, NSE_2d_dp, NSE_2d_sp, NSE_3d_sp, NSE_3d_dp\n END INTERFACE NSE\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! SAE\n\n ! PURPOSE\n ! Calculates the sum of absolute errors\n ! SAE = sum(abs(y - x))\n !\n ! If an optinal mask is given, the calculations are over those locations that correspond to true values in the mask.\n ! x and y can be single or double precision. The result will have the same numerical precision.\n\n ! CALLING SEQUENCE\n ! out = SAE(x, y, mask=mask)\n\n ! INTENT(IN)\n ! real(sp/dp), dimension(:) :: x, y 1D-array with input numbers\n ! OR\n ! real(sp/dp), dimension(:,:) :: x, y 2D-array with input numbers\n ! OR\n ! real(sp/dp), dimension(:,:,:) :: x, y 3D-array with input numbers\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp) :: SAE sum of absolute errors\n\n ! INTENT(IN), OPTIONAL\n ! logical :: mask(:) 1D-array of logical values with size(x/y).\n ! OR\n ! logical :: mask(:,:) 2D-array of logical values with size(x/y).\n ! OR\n ! logical :: mask(:,:,:) 3D-array of logical values with size(x/y).\n !\n ! If present, only those locations in vec corresponding to the true values in mask are used.\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! Input values must be floating points.\n\n ! EXAMPLE\n ! vec1 = (/ 1., 2, 3., -999., 5., 6. /)\n ! vec2 = (/ 1., 2, 3., -999., 5., 6. /)\n ! m = SAE(vec1, vec2, mask=(vec >= 0.))\n ! -> see also example in test directory\n\n ! LITERATURE\n ! none\n\n ! HISTORY\n ! Written, Matthias Zink, Sept 2012\n INTERFACE SAE\n MODULE PROCEDURE SAE_1d_sp, SAE_1d_dp, SAE_2d_sp, SAE_2d_dp, SAE_3d_sp, SAE_3d_dp\n END INTERFACE SAE\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! SSE\n\n ! PURPOSE\n ! Calculates the sum of squared errors\n ! SSE = sum((y - x)**2)\n !\n ! If an optinal mask is given, the calculations are over those locations that correspond to true values in the mask.\n ! x and y can be single or double precision. The result will have the same numerical precision.\n\n ! CALLING SEQUENCE\n ! out = SSE(x, y, mask=mask)\n\n ! INTENT(IN)\n ! real(sp/dp), dimension(:) :: x, y 1D-array with input numbers\n ! OR\n ! real(sp/dp), dimension(:,:) :: x, y 2D-array with input numbers\n ! OR\n ! real(sp/dp), dimension(:,:,:) :: x, y 3D-array with input numbers\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp) :: SSE sum of squared errors\n\n ! INTENT(IN), OPTIONAL\n ! logical :: mask(:) 1D-array of logical values with size(x/y).\n ! OR\n ! logical :: mask(:,:) 2D-array of logical values with size(x/y).\n ! OR\n ! logical :: mask(:,:,:) 3D-array of logical values with size(x/y).\n !\n ! If present, only those locations in vec corresponding to the true values in mask are used.\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! Input values must be floating points.\n\n ! EXAMPLE\n ! vec1 = (/ 1., 2, 3., -999., 5., 6. /)\n ! vec2 = (/ 1., 2, 3., -999., 5., 6. /)\n ! m = SSE(vec1, vec2, mask=(vec >= 0.))\n ! -> see also example in test directory\n\n ! LITERATURE\n ! none\n\n ! HISTORY\n ! Written, Matthias Zink, Sept 2012\n INTERFACE SSE\n MODULE PROCEDURE SSE_1d_sp, SSE_1d_dp, SSE_2d_sp, SSE_2d_dp, SSE_3d_sp, SSE_3d_dp\n END INTERFACE SSE\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! RMSE\n\n ! PURPOSE\n ! Calculates the root-mean-square error\n ! RMSE = sqrt(sum((y - x)**2) / count(mask))\n !\n ! If an optinal mask is given, the calculations are over those locations that correspond to true values in the mask.\n ! x and y can be single or double precision. The result will have the same numerical precision.\n\n ! CALLING SEQUENCE\n ! out = RMSE(dat, mask=mask)\n\n ! INTENT(IN)\n ! real(sp/dp), dimension(:) :: x, y 1D-array with input numbers\n ! OR\n ! real(sp/dp), dimension(:,:) :: x, y 2D-array with input numbers\n ! OR\n ! real(sp/dp), dimension(:,:,:) :: x, y 3D-array with input numbers\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp) :: RMSE Root-mean-square error\n\n ! INTENT(IN), OPTIONAL\n ! logical :: mask(:) 1D-array of logical values with size(x/y).\n ! OR\n ! logical :: mask(:,:) 2D-array of logical values with size(x/y).\n ! OR\n ! logical :: mask(:,:,:) 3D-array of logical values with size(x/y).\n !\n ! If present, only those locations in vec corresponding to the true values in mask are used.\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! Input values must be floating points.\n\n ! EXAMPLE\n ! vec1 = (/ 1., 2, 3., -999., 5., 6. /)\n ! vec2 = (/ 1., 2, 3., -999., 5., 6. /)\n ! m = RMSE(vec1, vec2, mask=(vec >= 0.))\n ! -> see also example in test directory\n\n ! LITERATURE\n ! None\n\n ! HISTORY\n ! Written, Matthias Zink, Sept 2012\n INTERFACE RMSE\n MODULE PROCEDURE RMSE_1d_sp, RMSE_1d_dp, RMSE_2d_sp, RMSE_2d_dp, RMSE_3d_sp, RMSE_3d_dp\n END INTERFACE RMSE\n\n ! ------------------------------------------------------------------\n\n PRIVATE\n\n ! ------------------------------------------------------------------\n\nCONTAINS\n\n ! ------------------------------------------------------------------\n\n FUNCTION BIAS_1d_sp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: BIAS_1d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n !\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'BIAS_1d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n !\n if (n .LE. 1_i4) stop 'BIAS_1d_sp: number of arguments must be at least 2'\n !\n BIAS_1d_sp = average(y, mask=maske) - average(x, mask=maske)\n\n END FUNCTION BIAS_1d_sp\n\n FUNCTION BIAS_1d_dp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: BIAS_1d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n !\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'BIAS_1d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'BIAS_1d_dp: number of arguments must be at least 2'\n !\n BIAS_1d_dp = average(y, mask=maske) - average(x, mask=maske)\n\n END FUNCTION BIAS_1d_dp\n\n FUNCTION BIAS_2d_sp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: BIAS_2d_sp\n\n INTEGER(i4) :: n\n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x, dim=1), size(x, dim=2)):: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n !\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'BIAS_2d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x, dim=1) * size(x, dim=2)\n endif\n !\n if (n .LE. 1_i4) stop 'BIAS_2d_sp: number of arguments must be at least 2'\n !\n BIAS_2d_sp = average(reshape(y, (/size(y,dim=1) * size(y,dim=2)/)), &\n mask=reshape(maske,(/size(y,dim=1) * size(y,dim=2)/))) - &\n average(reshape(x, (/size(x,dim=1) * size(x,dim=2)/)), &\n mask=reshape(maske,(/size(x,dim=1) * size(x,dim=2)/)))\n !\n END FUNCTION BIAS_2d_sp\n\n FUNCTION BIAS_2d_dp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: BIAS_2d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x, dim=1), size(x, dim=2)):: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n !\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'BIAS_2d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x, dim=1) * size(x, dim=2)\n endif\n !\n if (n .LE. 1_i4) stop 'BIAS_2d_dp: number of arguments must be at least 2'\n !\n BIAS_2d_dp = average(reshape(y, (/size(y,dim=1) * size(y,dim=2)/)), &\n mask=reshape(maske,(/size(y,dim=1) * size(y,dim=2)/))) - &\n average(reshape(x, (/size(x,dim=1) * size(x,dim=2)/)), &\n mask=reshape(maske,(/size(x,dim=1) * size(x,dim=2)/)))\n !\n END FUNCTION BIAS_2d_dp\n\n FUNCTION BIAS_3d_sp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: BIAS_3d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x, dim=1), &\n size(x, dim=2), size(x, dim=3)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n !\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'BIAS_3d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x, dim=1) * size(x, dim=2) * size(x, dim=3)\n endif\n !\n ! not really sopisticated, it has to be checked if the 3 numbers of x and y are matching in arry position\n if (n .LE. 1_i4) stop 'BIAS_3d_sp: number of arguments must be at least 2'\n !\n BIAS_3d_sp = average(reshape(y, (/size(y,dim=1) * size(y,dim=2) * size(y,dim=3)/)), &\n mask=reshape(maske,(/size(y,dim=1) * size(y,dim=2) * size(y,dim=3)/))) - &\n average(reshape(x, (/size(x,dim=1) * size(x,dim=2) * size(x,dim=3)/)), &\n mask=reshape(maske,(/size(x,dim=1) * size(x,dim=2) * size(x,dim=3)/)))\n !\n END FUNCTION BIAS_3d_sp\n\n FUNCTION BIAS_3d_dp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: BIAS_3d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x, dim=1), &\n size(x, dim=2), size(x, dim=3)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n !\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'BIAS_3d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x, dim=1) * size(x, dim=2) * size(x, dim=3)\n endif\n !\n ! not really sopisticated, it has to be checked if the 3 numbers of x and y are matching in arry position\n if (n .LE. 1_i4) stop 'BIAS_3d_dp: number of arguments must be at least 2'\n !\n BIAS_3d_dp = average(reshape(y, (/size(y,dim=1) * size(y,dim=2) * size(y,dim=3)/)), &\n mask=reshape(maske,(/size(y,dim=1) * size(y,dim=2) * size(y,dim=3)/))) - &\n average(reshape(x, (/size(x,dim=1) * size(x,dim=2) * size(x,dim=3)/)), &\n mask=reshape(maske,(/size(x,dim=1) * size(x,dim=2) * size(x,dim=3)/)))\n !\n END FUNCTION BIAS_3d_dp\n\n ! ------------------------------------------------------------------\n\n FUNCTION KGE_1d_sp(x, y, mask)\n\n USE mo_moment, ONLY: average, stddev, correlation\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: KGE_1d_sp\n\n ! local variables\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x)) :: maske\n\n REAL(sp) :: mu_Obs, mu_Sim ! Mean of x and y\n REAL(sp) :: sigma_Obs, sigma_Sim ! Standard dev. of x and y\n REAL(sp) :: pearson_coor ! Pearson Corr. of x and y\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'KGE_1d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'KGE_1d_sp: sample size must be at least 2'\n\n ! Mean\n mu_Obs = average(x, mask=maske)\n mu_Sim = average(y, mask=maske)\n ! Standard Deviation\n sigma_Obs = stddev(x, mask=maske, ddof=1_i4)\n sigma_Sim = stddev(y, mask=maske, ddof=1_i4)\n ! Pearson product-moment correlation coefficient\n pearson_coor = correlation(x, y, mask=maske, ddof=1_i4)\n !\n KGE_1d_sp = 1.0 - SQRT( &\n ( 1.0_sp - (mu_Sim/mu_Obs) )**2 + &\n ( 1.0_sp - (sigma_Sim/sigma_Obs) )**2 + &\n ( 1.0_sp - pearson_coor)**2 &\n )\n\n END FUNCTION KGE_1d_sp\n\n FUNCTION KGE_2d_sp(x, y, mask)\n\n USE mo_moment, ONLY: average, stddev, correlation\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: KGE_2d_sp\n\n ! local variables\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x, dim=1), size(x, dim=2)) :: maske\n REAL(sp) :: mu_Obs, mu_Sim ! Mean of x and y\n REAL(sp) :: sigma_Obs, sigma_Sim ! Standard dev. of x and y\n REAL(sp) :: pearson_coor ! Pearson Corr. of x and y\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'KGE_2d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'KGE_2d_sp: sample size must be at least 2'\n\n ! Mean\n mu_Obs = average( &\n reshape(x(:,:), (/size(x, dim=1)*size(x, dim=2)/)), &\n mask=reshape(maske(:,:), (/size(x, dim=1)*size(x, dim=2)/)))\n mu_Sim = average( &\n reshape(y(:,:), (/size(y, dim=1)*size(y, dim=2)/)), &\n mask=reshape(maske(:,:), (/size(y, dim=1)*size(y, dim=2)/)))\n ! Standard Deviation\n sigma_Obs = stddev( &\n reshape(x(:,:), (/size(x, dim=1)*size(x, dim=2)/)), &\n mask=reshape(maske(:,:), (/size(x, dim=1)*size(x, dim=2)/)), ddof=1_i4)\n sigma_Sim = stddev( &\n reshape(y(:,:), (/size(y, dim=1)*size(y, dim=2)/)), &\n mask=reshape(maske(:,:), (/size(y, dim=1)*size(y, dim=2)/)), ddof=1_i4)\n ! Pearson product-moment correlation coefficient\n pearson_coor = correlation(&\n reshape(x(:,:), (/size(x, dim=1)*size(x, dim=2)/)), &\n reshape(y(:,:), (/size(y, dim=1)*size(y, dim=2)/)), &\n mask=reshape(maske(:,:), (/size(y, dim=1)*size(y, dim=2)/)), ddof=1_i4)\n !\n KGE_2d_sp = 1.0 - SQRT( &\n ( 1.0_sp - (mu_Sim/mu_Obs) )**2 + &\n ( 1.0_sp - (sigma_Sim/sigma_Obs) )**2 + &\n ( 1.0_sp - pearson_coor)**2 &\n )\n\n END FUNCTION KGE_2d_sp\n\n FUNCTION KGE_3d_sp(x, y, mask)\n\n USE mo_moment, ONLY: average, stddev, correlation\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: KGE_3d_sp\n\n ! local variables\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x, dim=1), size(x, dim=2), size(x, dim=3)) :: maske\n REAL(sp) :: mu_Obs, mu_Sim ! Mean of x and y\n REAL(sp) :: sigma_Obs, sigma_Sim ! Standard dev. of x and y\n REAL(sp) :: pearson_coor ! Pearson Corr. of x and y\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'KGE_3d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'KGE_3d_sp: sample size must be at least 2'\n\n ! Mean\n mu_Obs = average( &\n reshape(x(:,:,:), (/size(x, dim=1)*size(x, dim=2)*size(x, dim=3)/)), &\n mask=reshape(maske(:,:,:), (/size(x, dim=1)*size(x, dim=2)*size(x, dim=3)/)))\n mu_Sim = average( &\n reshape(y(:,:,:), (/size(y, dim=1)*size(y, dim=2)*size(y, dim=3)/)), &\n mask=reshape(maske(:,:,:), (/size(y, dim=1)*size(y, dim=2)*size(y, dim=3)/)))\n ! Standard Deviation\n sigma_Obs = stddev( &\n reshape(x(:,:,:), (/size(x, dim=1)*size(x, dim=2)*size(x, dim=3)/)), &\n mask=reshape(maske(:,:,:), (/size(x, dim=1)*size(x, dim=2)*size(x, dim=3)/)), ddof=1_i4)\n sigma_Sim = stddev( &\n reshape(y(:,:,:), (/size(y, dim=1)*size(y, dim=2)*size(y, dim=3)/)), &\n mask=reshape(maske(:,:,:), (/size(y, dim=1)*size(y, dim=2)*size(y, dim=3)/)), ddof=1_i4)\n ! Pearson product-moment correlation coefficient\n pearson_coor = correlation(&\n reshape(x(:,:,:), (/size(x, dim=1)*size(x, dim=2)*size(x, dim=3)/)), &\n reshape(y(:,:,:), (/size(y, dim=1)*size(y, dim=2)*size(y, dim=3)/)), &\n mask=reshape(maske(:,:,:), (/size(y, dim=1)*size(y, dim=2)*size(y, dim=3)/)), ddof=1_i4)\n !\n KGE_3d_sp = 1.0 - SQRT( &\n ( 1.0_sp - (mu_Sim/mu_Obs) )**2 + &\n ( 1.0_sp - (sigma_Sim/sigma_Obs) )**2 + &\n ( 1.0_sp - pearson_coor)**2 &\n )\n\n END FUNCTION KGE_3d_sp\n\n FUNCTION KGE_1d_dp(x, y, mask)\n\n USE mo_moment, ONLY: average, stddev, correlation\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: KGE_1d_dp\n\n ! local variables\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x)) :: maske\n\n REAL(dp) :: mu_Obs, mu_Sim ! Mean of x and y\n REAL(dp) :: sigma_Obs, sigma_Sim ! Standard dev. of x and y\n REAL(dp) :: pearson_coor ! Pearson Corr. of x and y\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'KGE_1d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'KGE_1d_dp: sample size must be at least 2'\n\n ! Mean\n mu_Obs = average(x, mask=maske)\n mu_Sim = average(y, mask=maske)\n ! Standard Deviation\n sigma_Obs = stddev(x, mask=maske, ddof=1_i4)\n sigma_Sim = stddev(y, mask=maske, ddof=1_i4)\n ! Pearson product-moment correlation coefficient\n pearson_coor = correlation(x, y, mask=maske, ddof=1_i4)\n !\n KGE_1d_dp = 1.0 - SQRT( &\n ( 1.0_dp - (mu_Sim/mu_Obs) )**2 + &\n ( 1.0_dp - (sigma_Sim/sigma_Obs) )**2 + &\n ( 1.0_dp - pearson_coor)**2 &\n )\n\n END FUNCTION KGE_1d_dp\n\n FUNCTION KGE_2d_dp(x, y, mask)\n\n USE mo_moment, ONLY: average, stddev, correlation\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: KGE_2d_dp\n\n ! local variables\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x, dim=1), size(x, dim=2)) :: maske\n REAL(dp) :: mu_Obs, mu_Sim ! Mean of x and y\n REAL(dp) :: sigma_Obs, sigma_Sim ! Standard dev. of x and y\n REAL(dp) :: pearson_coor ! Pearson Corr. of x and y\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'KGE_2d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'KGE_2d_dp: sample size must be at least 2'\n\n ! Mean\n mu_Obs = average( &\n reshape(x(:,:), (/size(x, dim=1)*size(x, dim=2)/)), &\n mask=reshape(maske(:,:), (/size(x, dim=1)*size(x, dim=2)/)))\n mu_Sim = average( &\n reshape(y(:,:), (/size(y, dim=1)*size(y, dim=2)/)), &\n mask=reshape(maske(:,:), (/size(y, dim=1)*size(y, dim=2)/)))\n ! Standard Deviation\n sigma_Obs = stddev( &\n reshape(x(:,:), (/size(x, dim=1)*size(x, dim=2)/)), &\n mask=reshape(maske(:,:), (/size(x, dim=1)*size(x, dim=2)/)), ddof=1_i4)\n sigma_Sim = stddev( &\n reshape(y(:,:), (/size(y, dim=1)*size(y, dim=2)/)), &\n mask=reshape(maske(:,:), (/size(y, dim=1)*size(y, dim=2)/)), ddof=1_i4)\n ! Pearson product-moment correlation coefficient\n pearson_coor = correlation(&\n reshape(x(:,:), (/size(x, dim=1)*size(x, dim=2)/)), &\n reshape(y(:,:), (/size(y, dim=1)*size(y, dim=2)/)), &\n mask=reshape(maske(:,:), (/size(y, dim=1)*size(y, dim=2)/)), ddof=1_i4)\n !\n KGE_2d_dp = 1.0 - SQRT( &\n ( 1.0_dp - (mu_Sim/mu_Obs) )**2 + &\n ( 1.0_dp - (sigma_Sim/sigma_Obs) )**2 + &\n ( 1.0_dp - pearson_coor)**2 &\n )\n\n END FUNCTION KGE_2d_dp\n\n FUNCTION KGE_3d_dp(x, y, mask)\n\n USE mo_moment, ONLY: average, stddev, correlation\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: KGE_3d_dp\n\n ! local variables\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x, dim=1), size(x, dim=2), size(x, dim=3)) :: maske\n REAL(dp) :: mu_Obs, mu_Sim ! Mean of x and y\n REAL(dp) :: sigma_Obs, sigma_Sim ! Standard dev. of x and y\n REAL(dp) :: pearson_coor ! Pearson Corr. of x and y\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'KGE_3d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'KGE_3d_dp: sample size must be at least 2'\n\n ! Mean\n mu_Obs = average( &\n reshape(x(:,:,:), (/size(x, dim=1)*size(x, dim=2)*size(x, dim=3)/)), &\n mask=reshape(maske(:,:,:), (/size(x, dim=1)*size(x, dim=2)*size(x, dim=3)/)))\n mu_Sim = average( &\n reshape(y(:,:,:), (/size(y, dim=1)*size(y, dim=2)*size(y, dim=3)/)), &\n mask=reshape(maske(:,:,:), (/size(y, dim=1)*size(y, dim=2)*size(y, dim=3)/)))\n ! Standard Deviation\n sigma_Obs = stddev( &\n reshape(x(:,:,:), (/size(x, dim=1)*size(x, dim=2)*size(x, dim=3)/)), &\n mask=reshape(maske(:,:,:), (/size(x, dim=1)*size(x, dim=2)*size(x, dim=3)/)), ddof=1_i4)\n sigma_Sim = stddev( &\n reshape(y(:,:,:), (/size(y, dim=1)*size(y, dim=2)*size(y, dim=3)/)), &\n mask=reshape(maske(:,:,:), (/size(y, dim=1)*size(y, dim=2)*size(y, dim=3)/)), ddof=1_i4)\n ! Pearson product-moment correlation coefficient\n pearson_coor = correlation(&\n reshape(x(:,:,:), (/size(x, dim=1)*size(x, dim=2)*size(x, dim=3)/)), &\n reshape(y(:,:,:), (/size(y, dim=1)*size(y, dim=2)*size(y, dim=3)/)), &\n mask=reshape(maske(:,:,:), (/size(y, dim=1)*size(y, dim=2)*size(y, dim=3)/)), ddof=1_i4)\n !\n KGE_3d_dp = 1.0 - SQRT( &\n ( 1.0_dp - (mu_Sim/mu_Obs) )**2 + &\n ( 1.0_dp - (sigma_Sim/sigma_Obs) )**2 + &\n ( 1.0_dp - pearson_coor)**2 &\n )\n\n END FUNCTION KGE_3d_dp\n\n ! ------------------------------------------------------------------\n\n FUNCTION LNNSE_1d_sp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(INOUT) :: mask\n REAL(sp) :: LNNSE_1d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x))) :: shapemask\n REAL(sp) :: xmean\n REAL(sp), DIMENSION(size(x)) :: logx, logy, v1, v2\n LOGICAL, DIMENSION(size(x)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'LNNSE_1d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n else\n maske = .true.\n endif\n\n ! mask all negative and zero entries\n where (x .lt. tiny(1.0_sp) .or. y .lt. tiny(1.0_sp))\n maske = .false.\n end where\n n = count(maske)\n if (n .LE. 1_i4) stop 'LNNSE_1d_sp: number of arguments must be at least 2'\n\n ! logarithms\n logx = 0.0_sp\n logy = 0.0_sp\n where (maske)\n logx = log(x)\n logy = log(y)\n end where\n\n ! mean of x\n xmean = average(logx, mask=maske)\n\n ! NSE\n v1 = merge(logy - logx, 0.0_sp, maske)\n v2 = merge(logx - xmean, 0.0_sp, maske)\n LNNSE_1d_sp = 1.0_sp - dot_product(v1,v1) / dot_product(v2,v2)\n\n END FUNCTION LNNSE_1d_sp\n\n ! ------------------------------------------------------------------\n\n FUNCTION LNNSE_1d_dp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(INOUT) :: mask\n REAL(dp) :: LNNSE_1d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x))) :: shapemask\n REAL(dp) :: xmean\n REAL(dp), DIMENSION(size(x)) :: logx, logy, v1, v2\n LOGICAL, DIMENSION(size(x)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'LNNSE_1d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n else\n maske = .true.\n endif\n\n ! mask all negative and zero entries\n where (x .lt. tiny(1.0_dp) .or. y .lt. tiny(1.0_dp))\n maske = .false.\n end where\n n = count(maske)\n if (n .LE. 1_i4) stop 'LNNSE_1d_dp: number of arguments must be at least 2'\n\n ! logarithms\n logx = 0.0_dp\n logy = 0.0_dp\n where (maske)\n logx = log(x)\n logy = log(y)\n end where\n\n ! mean of x\n xmean = average(logx, mask=maske)\n\n ! NSE\n v1 = merge(logy - logx, 0.0_dp, maske)\n v2 = merge(logx - xmean, 0.0_dp, maske)\n LNNSE_1d_dp = 1.0_dp - sum(v1*v1, mask=maske) / sum(v2*v2, mask=maske)\n\n END FUNCTION LNNSE_1d_dp\n\n ! ------------------------------------------------------------------\n\n FUNCTION LNNSE_2d_sp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(INOUT) :: mask\n REAL(sp) :: LNNSE_2d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x))) :: shapemask\n REAL(sp) :: xmean\n REAL(sp), DIMENSION(size(x,dim=1),size(x,dim=2)) :: logx, logy, v1, v2\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'LNNSE_2d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n else\n maske = .true.\n endif\n\n ! mask all negative and zero entries\n where (x .lt. tiny(1.0_sp) .or. y .lt. tiny(1.0_sp))\n maske = .false.\n end where\n n = count(maske)\n if (n .LE. 1_i4) stop 'LNNSE_2d_sp: number of arguments must be at least 2'\n\n ! logarithms\n logx = 0.0_sp\n logy = 0.0_sp\n where (maske)\n logx = log(x)\n logy = log(y)\n end where\n\n ! mean of x\n xmean = average(pack(logx,maske))\n\n ! NSE\n v1 = merge(logy - logx, 0.0_sp, maske)\n v2 = merge(logx - xmean, 0.0_sp, maske)\n LNNSE_2d_sp = 1.0_sp - sum(v1*v1, mask=maske) / sum(v2*v2, mask=maske)\n\n END FUNCTION LNNSE_2d_sp\n\n ! ------------------------------------------------------------------\n\n FUNCTION LNNSE_2d_dp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(INOUT) :: mask\n REAL(dp) :: LNNSE_2d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x))) :: shapemask\n REAL(dp) :: xmean\n REAL(dp), DIMENSION(size(x,dim=1),size(x,dim=2)) :: logx, logy, v1, v2\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'LNNSE_2d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n else\n maske = .true.\n endif\n\n ! mask all negative and zero entries\n where (x .lt. tiny(1.0_dp) .or. y .lt. tiny(1.0_dp))\n maske = .false.\n end where\n n = count(maske)\n if (n .LE. 1_i4) stop 'LNNSE_2d_dp: number of arguments must be at least 2'\n\n ! logarithms\n logx = 0.0_dp\n logy = 0.0_dp\n where (maske)\n logx = log(x)\n logy = log(y)\n end where\n\n ! mean of x\n xmean = average(pack(logx,maske))\n\n ! NSE\n v1 = merge(logy - logx, 0.0_dp, maske)\n v2 = merge(logx - xmean, 0.0_dp, maske)\n LNNSE_2d_dp = 1.0_dp - sum(v1*v1, mask=maske) / sum(v2*v2, mask=maske)\n\n END FUNCTION LNNSE_2d_dp\n\n ! ------------------------------------------------------------------\n\n FUNCTION LNNSE_3d_sp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(INOUT) :: mask\n REAL(sp) :: LNNSE_3d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x))) :: shapemask\n REAL(sp) :: xmean\n REAL(sp), DIMENSION(size(x,dim=1),size(x,dim=2),size(x,dim=3)) :: logx, logy, v1, v2\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2),size(x,dim=3)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'LNNSE_3d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n else\n maske = .true.\n endif\n\n ! mask all negative and zero entries\n where (x .lt. tiny(1.0_sp) .or. y .lt. tiny(1.0_sp))\n maske = .false.\n end where\n n = count(maske)\n if (n .LE. 1_i4) stop 'LNNSE_3d_sp: number of arguments must be at least 2'\n\n ! logarithms\n logx = 0.0_sp\n logy = 0.0_sp\n where (maske)\n logx = log(x)\n logy = log(y)\n end where\n\n ! mean of x\n xmean = average(pack(logx,maske))\n\n ! NSE\n v1 = merge(logy - logx, 0.0_sp, maske)\n v2 = merge(logx - xmean, 0.0_sp, maske)\n LNNSE_3d_sp = 1.0_sp - sum(v1*v1, mask=maske) / sum(v2*v2, mask=maske)\n\n END FUNCTION LNNSE_3d_sp\n\n ! ------------------------------------------------------------------\n\n FUNCTION LNNSE_3d_dp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(INOUT) :: mask\n REAL(dp) :: LNNSE_3d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x))) :: shapemask\n REAL(dp) :: xmean\n REAL(dp), DIMENSION(size(x,dim=1),size(x,dim=2),size(x,dim=3)) :: logx, logy, v1, v2\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2),size(x,dim=3)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'LNNSE_3d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n else\n maske = .true.\n endif\n\n ! mask all negative and zero entries\n where (x .lt. tiny(1.0_dp) .or. y .lt. tiny(1.0_dp))\n maske = .false.\n end where\n n = count(maske)\n if (n .LE. 1_i4) stop 'LNNSE_3d_dp: number of arguments must be at least 2'\n\n ! logarithms\n logx = 0.0_dp\n logy = 0.0_dp\n where (maske)\n logx = log(x)\n logy = log(y)\n end where\n\n ! mean of x\n xmean = average(pack(logx,maske))\n\n ! NSE\n v1 = merge(logy - logx, 0.0_dp, maske)\n v2 = merge(logx - xmean, 0.0_dp, maske)\n LNNSE_3d_dp = 1.0_dp - sum(v1*v1, mask=maske) / sum(v2*v2, mask=maske)\n\n END FUNCTION LNNSE_3d_dp\n\n ! ------------------------------------------------------------------\n\n FUNCTION MAE_1d_sp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: MAE_1d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x, dim=1)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'MAE_1d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1)\n endif\n if (n .LE. 1_i4) stop 'MAE_1d_sp: number of arguments must be at least 2'\n !\n MAE_1d_sp = SAE_1d_sp(x,y,mask=maske) / real(n, sp)\n\n END FUNCTION MAE_1d_sp\n\n FUNCTION MAE_1d_dp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: MAE_1d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x, dim=1)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'MAE_1d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1)\n endif\n if (n .LE. 1_i4) stop 'MAE_1d_dp: number of arguments must be at least 2'\n !\n MAE_1d_dp = SAE_1d_dp(x,y,mask=maske) / real(n, dp)\n\n END FUNCTION MAE_1d_dp\n\n FUNCTION MAE_2d_sp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: MAE_2d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'MAE_2d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1) * size(x,dim=2)\n endif\n if (n .LE. 1_i4) stop 'MAE_2d_sp: number of arguments must be at least 2'\n !\n MAE_2d_sp = SAE_2d_sp(x,y,mask=maske) / real(n, sp)\n\n END FUNCTION MAE_2d_sp\n\n FUNCTION MAE_2d_dp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: MAE_2d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'MAE_2d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1) * size(x,dim=2)\n endif\n if (n .LE. 1_i4) stop 'MAE_2d_dp: number of arguments must be at least 2'\n !\n MAE_2d_dp = SAE_2d_dp(x,y,mask=maske) / real(n, dp)\n\n END FUNCTION MAE_2d_dp\n\n FUNCTION MAE_3d_sp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: MAE_3d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2), &\n size(x,dim=3)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'MAE_3d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1) * size(x,dim=2) * size(x,dim=3)\n endif\n if (n .LE. 1_i4) stop 'MAE_3d_sp: number of arguments must be at least 2'\n !\n MAE_3d_sp = SAE_3d_sp(x,y,mask=maske) / real(n, sp)\n\n END FUNCTION MAE_3d_sp\n\n FUNCTION MAE_3d_dp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: MAE_3d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2), &\n size(x,dim=3)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'MAE_3d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1) * size(x,dim=2) * size(x,dim=3)\n endif\n if (n .LE. 1_i4) stop 'MAE_3d_dp: number of arguments must be at least 2'\n !\n MAE_3d_dp = SAE_3d_dp(x,y,mask=maske) / real(n, dp)\n\n END FUNCTION MAE_3d_dp\n\n ! ------------------------------------------------------------------\n\n FUNCTION MAE_PROB_ONE_1d_dp(x, y, mask, cdfx, h)\n\n USE mo_moment, ONLY: average\n USE mo_kernel, ONLY: kernel_cumdensity\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp), DIMENSION(:), OPTIONAL, INTENT(IN) :: cdfx\n REAL(dp), OPTIONAL, INTENT(IN) :: h\n REAL(dp) :: MAE_PROB_ONE_1d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'MAE_PROB_1d_dp: shapes of inputs(x,y) or mask are not matching'\n\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'MAE_PROB_1d_dp: number of arguments must be at least 2'\n\n if (present(cdfx)) then\n if (present(h)) then\n MAE_PROB_ONE_1d_dp = average(abs(cdfx - &\n kernel_cumdensity(x, xout=y, h=h, mask=maske, romberg=.true., epsint=1.0e-4_dp)))\n else\n MAE_PROB_ONE_1d_dp = average(abs(cdfx - &\n kernel_cumdensity(x, xout=y, silverman=.true., mask=maske, romberg=.true., epsint=1.0e-4_dp)))\n endif\n else\n if (present(h)) then\n MAE_PROB_ONE_1d_dp = average(abs(kernel_cumdensity(x, xout=x, h=h, mask=maske, romberg=.true., epsint=1.0e-4_dp) &\n - kernel_cumdensity(x, xout=y, h=h, mask=maske, romberg=.true., epsint=1.0e-4_dp)))\n else\n MAE_PROB_ONE_1d_dp = average(abs( &\n kernel_cumdensity(x, xout=x, silverman=.true., mask=maske, romberg=.true., epsint=1.0e-4_dp) &\n - kernel_cumdensity(x, xout=y, silverman=.true., mask=maske, romberg=.true., epsint=1.0e-4_dp)))\n endif\n endif\n MAE_PROB_ONE_1d_dp = MAE_PROB_ONE_1d_dp * 100._dp ! unit is [%]\n\n END FUNCTION MAE_PROB_ONE_1d_dp\n\n ! ------------------------------------------------------------------\n\n ! FUNCTION MAE_PROB_TWO_1d_dp(x, y, mask)\n\n ! USE mo_moment, ONLY: average\n ! USE mo_empcdf, ONLY: empcdf\n\n ! IMPLICIT NONE\n\n ! REAL(dp), DIMENSION(:), INTENT(IN) :: x, y\n ! LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n ! REAL(dp) :: MAE_PROB_TWO_1d_dp\n\n ! INTEGER(i4) :: n\n ! INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n ! LOGICAL, DIMENSION(size(x)) :: maske\n\n ! if (present(mask)) then\n ! shapemask = shape(mask)\n ! else\n ! shapemask = shape(x)\n ! end if\n ! !\n ! if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n ! stop 'MAE_PROB_1d_dp: shapes of inputs(x,y) or mask are not matching'\n ! !\n ! if (present(mask)) then\n ! maske = mask\n ! n = count(maske)\n ! else\n ! maske = .true.\n ! n = size(x)\n ! endif\n ! if (n .LE. 1_i4) stop 'MAE_PROB_1d_dp: number of arguments must be at least 2'\n ! !\n ! MAE_PROB_TWO_1d_dp = average(abs(EMPCDF(y, maske=maske, print_info=.False.) - EMPCDF(x, maske=maske, print_info=.False.)))\n\n ! END FUNCTION MAE_PROB_TWO_1d_dp\n\n ! ------------------------------------------------------------------\n\n FUNCTION MSE_1d_sp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: MSE_1d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x, dim=1)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'MSE_1d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1)\n endif\n if (n .LE. 1_i4) stop 'MSE_1d_sp: number of arguments must be at least 2'\n !\n MSE_1d_sp = SSE_1d_sp(x,y,mask=maske) / real(n, sp)\n\n END FUNCTION MSE_1d_sp\n\n FUNCTION MSE_1d_dp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: MSE_1d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x, dim=1)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'MSE_1d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1)\n endif\n if (n .LE. 1_i4) stop 'MSE_1d_dp: number of arguments must be at least 2'\n !\n MSE_1d_dp = SSE_1d_dp(x,y,mask=maske) / real(n, dp)\n\n END FUNCTION MSE_1d_dp\n\n FUNCTION MSE_2d_sp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: MSE_2d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'MSE_2d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1) * size(x,dim=2)\n endif\n if (n .LE. 1_i4) stop 'MSE_2d_sp: number of arguments must be at least 2'\n !\n MSE_2d_sp = SSE_2d_sp(x,y,mask=maske) / real(n, sp)\n\n END FUNCTION MSE_2d_sp\n\n FUNCTION MSE_2d_dp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: MSE_2d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'MSE_2d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1) * size(x,dim=2)\n endif\n if (n .LE. 1_i4) stop 'MSE_2d_dp: number of arguments must be at least 2'\n !\n MSE_2d_dp = SSE_2d_dp(x,y,mask=maske) / real(n, dp)\n\n END FUNCTION MSE_2d_dp\n\n FUNCTION MSE_3d_sp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: MSE_3d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2), &\n size(x,dim=3)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'MSE_3d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1) * size(x,dim=2) * size(x,dim=3)\n endif\n if (n .LE. 1_i4) stop 'MSE_3d_sp: number of arguments must be at least 2'\n !\n MSE_3d_sp = SSE_3d_sp(x,y,mask=maske) / real(n, sp)\n\n END FUNCTION MSE_3d_sp\n\n FUNCTION MSE_3d_dp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: MSE_3d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2), &\n size(x,dim=3)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'MSE_3d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1) * size(x,dim=2) * size(x,dim=3)\n endif\n if (n .LE. 1_i4) stop 'MSE_3d_dp: number of arguments must be at least 2'\n !\n MSE_3d_dp = SSE_3d_dp(x,y,mask=maske) / real(n, dp)\n\n END FUNCTION MSE_3d_dp\n\n ! ------------------------------------------------------------------\n\n FUNCTION NSE_1d_sp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: NSE_1d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x))) :: shapemask\n REAL(sp) :: xmean\n REAL(sp), DIMENSION(size(x)) :: v1, v2\n LOGICAL, DIMENSION(size(x)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'NSE_1d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'NSE_1d_sp: number of arguments must be at least 2'\n ! mean of x\n xmean = average(x, mask=maske)\n !\n v1 = merge(y - x , 0.0_sp, maske)\n v2 = merge(x - xmean, 0.0_sp, maske)\n !\n NSE_1d_sp = 1.0_sp - dot_product(v1,v1) / dot_product(v2,v2)\n\n END FUNCTION NSE_1d_sp\n\n FUNCTION NSE_1d_dp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: NSE_1d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n REAL(dp) :: xmean\n REAL(dp), DIMENSION(size(x)) :: v1, v2\n LOGICAL, DIMENSION(size(x)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'NSE_1d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'NSE_1d_dp: number of arguments must be at least 2'\n ! mean of x\n xmean = average(x, mask=maske)\n !\n v1 = merge(y - x , 0.0_dp, maske)\n v2 = merge(x - xmean, 0.0_dp, maske)\n !\n NSE_1d_dp = 1.0_dp - dot_product(v1,v1) / dot_product(v2,v2)\n\n END FUNCTION NSE_1d_dp\n\n FUNCTION NSE_2d_sp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: NSE_2d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n REAL(sp) :: xmean\n LOGICAL, DIMENSION(size(x, dim=1), size(x, dim=2)):: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'NSE_2d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x, dim=1) * size(x, dim=2)\n endif\n !\n if (n .LE. 1_i4) stop 'NSE_2d_sp: number of arguments must be at least 2'\n ! mean of x\n xmean = average(reshape(x(:,:), (/size(x, dim=1)*size(x, dim=2)/)), &\n mask=reshape(maske(:,:), (/size(x, dim=1)*size(x, dim=2)/)))\n !\n NSE_2d_sp = 1.0_sp - sum((y-x)*(y-x), mask=maske) / sum((x-xmean)*(x-xmean), mask=maske)\n !\n END FUNCTION NSE_2d_sp\n\n FUNCTION NSE_2d_dp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: NSE_2d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n REAL(dp) :: xmean\n LOGICAL, DIMENSION(size(x, dim=1), size(x, dim=2)):: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'NSE_2d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x, dim=1) * size(x, dim=2)\n endif\n !\n if (n .LE. 1_i4) stop 'NSE_2d_dp: number of arguments must be at least 2'\n ! mean of x\n xmean = average(reshape(x(:,:), (/size(x, dim=1)*size(x, dim=2)/)), &\n mask=reshape(maske(:,:), (/size(x, dim=1)*size(x, dim=2)/)))\n !\n NSE_2d_dp = 1.0_dp - sum((y-x)*(y-x), mask=maske) / sum((x-xmean)*(x-xmean), mask=maske)\n !\n END FUNCTION NSE_2d_dp\n\n FUNCTION NSE_3d_sp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: NSE_3d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n REAL(sp) :: xmean\n LOGICAL, DIMENSION(size(x, dim=1), &\n size(x, dim=2), size(x, dim=3)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'NSE_3d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x, dim=1) * size(x, dim=2) * size(x, dim=3)\n endif\n !\n if (n .LE. 1_i4) stop 'NSE_3d_sp: number of arguments must be at least 2'\n ! mean of x\n xmean = average(reshape(x(:,:,:), (/size(x, dim=1)*size(x, dim=2)*size(x, dim=3)/)), &\n mask=reshape(maske(:,:,:), (/size(x, dim=1)*size(x, dim=2)*size(x, dim=3)/)))\n !\n NSE_3d_sp = 1.0_sp - sum((y-x)*(y-x), mask=maske) / sum((x-xmean)*(x-xmean), mask=maske)\n !\n END FUNCTION NSE_3d_sp\n\n FUNCTION NSE_3d_dp(x, y, mask)\n\n USE mo_moment, ONLY: average\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: NSE_3d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n REAL(dp) :: xmean\n LOGICAL, DIMENSION(size(x, dim=1), &\n size(x, dim=2), size(x, dim=3)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'NSE_3d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x, dim=1) * size(x, dim=2) * size(x, dim=3)\n endif\n !\n if (n .LE. 1_i4) stop 'NSE_3d_dp: number of arguments must be at least 2'\n ! Average of x\n xmean = average(reshape(x(:,:,:), (/size(x, dim=1)*size(x, dim=2)*size(x, dim=3)/)), &\n mask=reshape(maske(:,:,:), (/size(x, dim=1)*size(x, dim=2)*size(x, dim=3)/)))\n !\n NSE_3d_dp = 1.0_dp - sum((y-x)*(y-x), mask=maske) / sum((x-xmean)*(x-xmean), mask=maske)\n !\n END FUNCTION NSE_3d_dp\n\n\n ! ------------------------------------------------------------------\n\n FUNCTION SAE_1d_sp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: SAE_1d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n !\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'SAE_1d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'SAE_1d_sp: number of arguments must be at least 2'\n !\n SAE_1d_sp = sum(abs(y - x) ,mask = maske)\n\n END FUNCTION SAE_1d_sp\n\n FUNCTION SAE_1d_dp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: SAE_1d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n !\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'SAE_1d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'SAE_1d_dp: number of arguments must be at least 2'\n !\n SAE_1d_dp = sum(abs(y - x) ,mask = maske)\n\n END FUNCTION SAE_1d_dp\n\n FUNCTION SAE_2d_sp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: SAE_2d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n !\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'SAE_2d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1) * size(x,dim=2)\n endif\n if (n .LE. 1_i4) stop 'SAE_2d_sp: number of arguments must be at least 2'\n !\n SAE_2d_sp = SAE_1d_sp(reshape(x, (/size(x, dim=1) * size(x, dim=2)/)), &\n reshape(y, (/size(y, dim=1) * size(y, dim=2)/)), &\n mask=reshape(maske, (/size(maske, dim=1) * size(maske, dim=2)/)) )\n\n END FUNCTION SAE_2d_sp\n\n FUNCTION SAE_2d_dp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: SAE_2d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n !\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'SAE_2d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1) * size(x,dim=2)\n endif\n if (n .LE. 1_i4) stop 'SAE_2d_dp: number of arguments must be at least 2'\n !\n SAE_2d_dp = SAE_1d_dp(reshape(x, (/size(x, dim=1) * size(x, dim=2)/)), &\n reshape(y, (/size(y, dim=1) * size(y, dim=2)/)), &\n mask=reshape(maske, (/size(maske, dim=1) * size(maske, dim=2)/)) )\n\n END FUNCTION SAE_2d_dp\n\n FUNCTION SAE_3d_sp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: SAE_3d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2), &\n size(x,dim=3)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n !\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'SAE_3d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1) * size(x,dim=2) * size(x,dim=3)\n endif\n if (n .LE. 1_i4) stop 'SAE_3d_sp: number of arguments must be at least 2'\n !\n SAE_3d_sp = SAE_1d_sp(reshape(x, (/size(x, dim=1) * size(x, dim=2) * size(x, dim=3)/)), &\n reshape(y, (/size(y, dim=1) * size(y, dim=2) * size(x, dim=3)/)), &\n mask=reshape(maske, (/size(maske, dim=1) * size(maske, dim=2) &\n * size(maske, dim=3)/)) )\n\n END FUNCTION SAE_3d_sp\n\n FUNCTION SAE_3d_dp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: SAE_3d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2), &\n size(x,dim=3)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n !\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'SAE_3d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1) * size(x,dim=2) * size(x,dim=3)\n endif\n if (n .LE. 1_i4) stop 'SAE_3d_dp: number of arguments must be at least 2'\n !\n SAE_3d_dp = SAE_1d_dp(reshape(x, (/size(x, dim=1) * size(x, dim=2) * size(x, dim=3)/)), &\n reshape(y, (/size(y, dim=1) * size(y, dim=2) * size(x, dim=3)/)), &\n mask=reshape(maske, (/size(maske, dim=1) * size(maske, dim=2) &\n * size(maske, dim=3)/)) )\n\n END FUNCTION SAE_3d_dp\n\n ! ------------------------------------------------------------------\n\n FUNCTION SSE_1d_sp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: SSE_1d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n !\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'SSE_1d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'SSE_1d_sp: number of arguments must be at least 2'\n !\n SSE_1d_sp = sum((y - x)**2_i4 ,mask = maske)\n\n END FUNCTION SSE_1d_sp\n\n FUNCTION SSE_1d_dp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: SSE_1d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'SSE_1d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'SSE_1d_dp: number of arguments must be at least 2'\n !\n SSE_1d_dp = sum((y - x)**2_i4 ,mask = maske)\n\n END FUNCTION SSE_1d_dp\n\n FUNCTION SSE_2d_sp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: SSE_2d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x))) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1), size(x,dim=2)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'SSE_2d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'SSE_2d_sp: number of arguments must be at least 2'\n !\n SSE_2d_sp = SSE_1d_sp(reshape(x, (/size(x, dim=1) * size(x, dim=2)/)), &\n reshape(y, (/size(y, dim=1) * size(y, dim=2)/)), &\n mask=reshape(maske, (/size(maske, dim=1) * size(maske, dim=2)/)) )\n\n END FUNCTION SSE_2d_sp\n\n FUNCTION SSE_2d_dp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: SSE_2d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x))) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1), size(x,dim=2)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'SSE_2d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'SSE_2d_dp: number of arguments must be at least 2'\n !\n SSE_2d_dp = SSE_1d_dp(reshape(x, (/size(x, dim=1) * size(x, dim=2)/)), &\n reshape(y, (/size(y, dim=1) * size(y, dim=2)/)), &\n mask=reshape(maske, (/size(maske, dim=1) * size(maske, dim=2)/)) )\n\n END FUNCTION SSE_2d_dp\n\n FUNCTION SSE_3d_sp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: SSE_3d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x))) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1), size(x,dim=2),&\n size(x,dim=3)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'SSE_3d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'SSE_3d_sp: number of arguments must be at least 2'\n !\n SSE_3d_sp = SSE_1d_sp(reshape(x, (/size(x, dim=1) * size(x, dim=2) * size(x, dim=3)/)), &\n reshape(y, (/size(y, dim=1) * size(y, dim=2) * size(x, dim=3)/)), &\n mask=reshape(maske, (/size(maske, dim=1) * size(maske, dim=2) &\n * size(maske, dim=3)/)))\n\n END FUNCTION SSE_3d_sp\n\n FUNCTION SSE_3d_dp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: SSE_3d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x))) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1), size(x,dim=2),&\n size(x,dim=3)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'SSE_3d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x)\n endif\n if (n .LE. 1_i4) stop 'SSE_3d_dp: number of arguments must be at least 2'\n !\n SSE_3d_dp = SSE_1d_dp(reshape(x, (/size(x, dim=1) * size(x, dim=2) * size(x, dim=3)/)), &\n reshape(y, (/size(y, dim=1) * size(y, dim=2) * size(x, dim=3)/)), &\n mask=reshape(maske, (/size(maske, dim=1) * size(maske, dim=2) &\n * size(maske, dim=3)/)))\n\n END FUNCTION SSE_3d_dp\n\n ! ------------------------------------------------------------------\n\n FUNCTION RMSE_1d_sp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: RMSE_1d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x, dim=1)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'RMSE_1d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1)\n endif\n if (n .LE. 1_i4) stop 'RMSE_1d_sp: number of arguments must be at least 2'\n !\n RMSE_1d_sp = sqrt(MSE_1d_sp(x,y,mask=maske))\n\n END FUNCTION RMSE_1d_sp\n\n FUNCTION RMSE_1d_dp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: RMSE_1d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x, dim=1)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'RMSE_1d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1)\n endif\n if (n .LE. 1_i4) stop 'RMSE_1d_dp: number of arguments must be at least 2'\n !\n RMSE_1d_dp = sqrt(MSE_1d_dp(x,y,mask=maske))\n\n END FUNCTION RMSE_1d_dp\n\n FUNCTION RMSE_2d_sp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: RMSE_2d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'RMSE_2d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1) * size(x,dim=2)\n endif\n if (n .LE. 1_i4) stop 'RMSE_2d_sp: number of arguments must be at least 2'\n !\n RMSE_2d_sp = sqrt(MSE_2d_sp(x,y,mask=maske))\n\n END FUNCTION RMSE_2d_sp\n\n FUNCTION RMSE_2d_dp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: RMSE_2d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'RMSE_2d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1) * size(x,dim=2)\n endif\n if (n .LE. 1_i4) stop 'RMSE_2d_dp: number of arguments must be at least 2'\n !\n RMSE_2d_dp = sqrt(MSE_2d_dp(x,y,mask=maske))\n\n END FUNCTION RMSE_2d_dp\n\n FUNCTION RMSE_3d_sp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp) :: RMSE_3d_sp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2), &\n size(x,dim=3)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'RMSE_3d_sp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1) * size(x,dim=2) * size(x,dim=3)\n endif\n if (n .LE. 1_i4) stop 'RMSE_3d_sp: number of arguments must be at least 2'\n !\n RMSE_3d_sp = sqrt(MSE_3d_sp(x,y,mask=maske))\n\n END FUNCTION RMSE_3d_sp\n\n FUNCTION RMSE_3d_dp(x, y, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:,:), INTENT(IN) :: x, y\n LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp) :: RMSE_3d_dp\n\n INTEGER(i4) :: n\n INTEGER(i4), DIMENSION(size(shape(x)) ) :: shapemask\n LOGICAL, DIMENSION(size(x,dim=1),size(x,dim=2), &\n size(x,dim=3)) :: maske\n\n if (present(mask)) then\n shapemask = shape(mask)\n else\n shapemask = shape(x)\n end if\n if ( (any(shape(x) .NE. shape(y))) .OR. (any(shape(x) .NE. shapemask)) ) &\n stop 'RMSE_3d_dp: shapes of inputs(x,y) or mask are not matching'\n !\n if (present(mask)) then\n maske = mask\n n = count(maske)\n else\n maske = .true.\n n = size(x,dim=1) * size(x,dim=2) * size(x,dim=3)\n endif\n if (n .LE. 1_i4) stop 'RMSE_3d_dp: number of arguments must be at least 2'\n !\n RMSE_3d_dp = sqrt(MSE_3d_dp(x,y,mask=maske))\n\n END FUNCTION RMSE_3d_dp\n\nEND MODULE mo_errormeasures\n", "meta": {"hexsha": "b779a783de1b8424176db60898c3218ffdd381d2", "size": 103250, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mo_errormeasures.f90", "max_stars_repo_name": "mcuntz/jams_fortran", "max_stars_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2020-02-28T00:14:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-20T23:32:41.000Z", "max_issues_repo_path": "mo_errormeasures.f90", "max_issues_repo_name": "mcuntz/jams_fortran", "max_issues_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-09T15:33:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T16:16:09.000Z", "max_forks_repo_path": "mo_errormeasures.f90", "max_forks_repo_name": "mcuntz/jams_fortran", "max_forks_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-09T08:08:56.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-09T08:08:56.000Z", "avg_line_length": 33.5554111147, "max_line_length": 129, "alphanum_fraction": 0.5026731235, "num_tokens": 32056, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.7533904339702517}} {"text": "* Home work #1\r\n* Question (1)\r\n* Suppose a,b,c are the following function of x:\r\n* a=x^3-8x^2+4 , b=tanx + sin2x , c=e^(7x+5)\r\n* write a program which reads x and prints x,a,b,c.\r\n\r\n Print*, ' Enter the value of x'\r\n read (*,*)x\r\n a=x*x*x-8*x*x+4\r\n b=tan(x) + sin(2*x)\r\n c=exp(7*x+5)\r\n \r\n print*, x,a,b,c\r\n \r\n Stop\r\n End\r\n \r\n", "meta": {"hexsha": "03e18a85ee958ec8d26d6272f721c5e2d0a86e1f", "size": 433, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "HW(1)/Problem (1)/Hw_1_problem_1_.f", "max_stars_repo_name": "Melhabbash/Computational-Physics-", "max_stars_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW(1)/Problem (1)/Hw_1_problem_1_.f", "max_issues_repo_name": "Melhabbash/Computational-Physics-", "max_issues_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW(1)/Problem (1)/Hw_1_problem_1_.f", "max_forks_repo_name": "Melhabbash/Computational-Physics-", "max_forks_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0555555556, "max_line_length": 58, "alphanum_fraction": 0.415704388, "num_tokens": 138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216356, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7532918537064097}} {"text": "subroutine simplex(start, n, EPSILON, scale, iprint,fun)\n use params\n implicit none\n\n external fun\n\n\n integer, intent (in) :: n, iprint\n double precision, intent (inout), dimension(0:n-1) :: start\n double precision, intent (in) :: EPSILON, scale\n double precision :: fun\n! Define Constants\n integer, parameter :: MAX_IT = 1000\n double precision, parameter :: ALPHA_S=1.0\n double precision, parameter :: BETA_S=0.5\n double precision, parameter :: GAMMA_S=2.0\n\n\n\n! ======================================================================\n! Variable Definitions\n!\n! Integer vs = vertex with the smallest value\n! Integer vh = vertex with next smallest value\n! Integer vg = vertex with largest value\n! Integer i,j,m,row\n! Integer k = track the number of function evaluations\n! Integer itr = track the number of iterations\n! double precision v = holds vertices of simplex\n! double precision pn,qn = values used to create initial simplex\n! double precision f = value of function at each vertex\n! double precision fr = value of function at reflection point\n! double precision fe = value of function at expansion point\n! double precision fc = value of function at contraction point\n! double precision vr = reflection - coordinates\n! double precision ve = expansion - coordinates\n! double precision vc = contraction - coordinates\n! double precision vm = centroid - coordinates\n! double precision min\n! double precision fsum,favg,s,cent\n! double precision vtmp = temporary array passed to finddelta\n! ======================================================================\n\n Integer :: vs,vh,vg\n Integer :: i,j,k,itr,m,row\n double precision, dimension(:,:), allocatable :: v\n double precision, dimension(:), allocatable :: f\n double precision, dimension(:), allocatable :: vr\n double precision, dimension(:), allocatable :: ve\n double precision, dimension(:), allocatable :: vc\n double precision, dimension(:), allocatable :: vtmp\n double precision, dimension(:), allocatable :: vm\n double precision :: pn,qn\n double precision :: fr,fe,fc\n double precision :: min,fsum,favg,cent,s\n\n allocate (v(0:n,0:n-1))\n allocate (f(0:n))\n allocate (vr(0:n-1))\n allocate (ve(0:n-1))\n allocate (vc(0:n-1))\n allocate (vm(0:n-1))\n allocate (vtmp(0:n-1))\n\n! create the initial simplex\n! assume one of the vertices is 0.0\n\n pn = scale*(sqrt(n+1.)-1.+n)/(n*sqrt(2.))\n qn = scale*(sqrt(n+1.)-1.)/(n*sqrt(2.))\n\n DO i=0,n-1\n v(0,i) = start(i)\n END DO\n\n DO i=1,n\n DO j=0,n-1\n IF (i-1 == j) THEN\n v(i,j) = pn + start(j)\n ELSE\n v(i,j) = qn + start(j)\n END IF\n END DO\n END DO\n\n\n! find the initial function values\n\n DO j=0,n\n! put coordinates into single dimension array\n! to pass it to finddelta\n DO m=0,n-1\n vtmp(m) = v(j,m)\n END DO\n f(j) = fun(vtmp)\n END DO\n\n! Print out the initial simplex\n! Print out the initial function values\n\n IF (iprint == 0) THEN\n Write(*,*) \"Initial Values\"\n Write(*,300) ((v(i,j),j=0,n-1),f(i),i=0,n)\n END IF\n\n k = n+1\n\n! begin main loop of the minimization\n\nDO itr=1,MAX_IT\n! find the index of the largest value\n vg = 0\n DO j=0,n\n IF (f(j) .GT. f(vg)) THEN\n vg = j\n END IF\n END DO\n\n! find the index of the smallest value\n vs = 0\n DO j=0,n\n If (f(j) .LT. f(vs)) Then\n vs = j\n END IF\n END DO\n\n! find the index of the second largest value\n vh = vs\n Do j=0,n\n If ((f(j) .GT. f(vh)) .AND. (f(j) .LT. f(vg))) Then\n vh = j\n END IF\n END DO\n\n! calculate the centroid\n DO j=0,n-1\n cent = 0.0\n DO m=0,n\n If (m .NE. vg) Then\n cent = cent + v(m,j)\n END IF\n END DO\n vm(j) = cent/n\n END DO\n\n! reflect vg to new vertex vr\n DO j=0,n-1\n vr(j) = (1+ALPHA_S)*vm(j) - ALPHA_S*v(vg,j)\n END DO\n fr = fun(vr)\n k = k+1\n\n If ((fr .LE. f(vh)) .AND. (fr .GT. f(vs))) Then\n DO j=0,n-1\n v(vg,j) = vr(j)\n END DO\n f(vg) = fr\n END IF\n\n! investigate a step further in this direction\n If (fr .LE. f(vs)) Then\n DO j=0,n-1\n ve(j) = GAMMA_S*vr(j) + (1-GAMMA_S)*vm(j)\n END DO\n fe = fun(ve)\n k = k+1\n\n! by making fe < fr as opposed to fe < f(vs), Rosenbrocks function\n! takes 62 iterations as opposed to 64.\n\n If (fe .LT. fr) Then\n DO j=0,n-1\n v(vg,j) = ve(j)\n END DO\n f(vg) = fe\n Else\n DO j=0,n-1\n v(vg,j) = vr(j)\n END DO\n f(vg) = fr\n END IF\n END IF\n\n! check to see if a contraction is necessary\n If (fr .GT. f(vh)) Then\n DO j=0,n-1\n vc(j) = BETA_S*v(vg,j) + (1-BETA_S)*vm(j)\n END DO\n fc = fun(vc)\n k = k+1\n If (fc .LT. f(vg)) Then\n DO j=0,n-1\n v(vg,j) = vc(j)\n END DO\n f(vg) = fc\n\n! at this point the contraction is not successful,\n! we must halve the distance from vs to all the\n! vertices of the simplex and then continue.\n! 10/31/97 - modified C program to account for\n! all vertices.\n\n Else\n DO row=0,n\n If (row .NE. vs) Then\n DO j=0,n-1\n v(row,j) = v(vs,j)+(v(row,j)-v(vs,j))/2.0\n END DO\n END IF\n END DO\n DO m=0,n-1\n vtmp(m) = v(vg,m)\n END DO\n f(vg) = fun(vtmp)\n k = k+1\n\n DO m=0,n-1\n vtmp(m) = v(vh,m)\n END DO\n f(vh) = fun(vtmp)\n k = k+1\n END IF\n END IF\n\n! print out the value at each iteration\n IF (iprint == 0) THEN\n Write(*,*) \"Iteration \",itr\n Write(*,300) ((v(i,j),j=0,n-1),f(i),i=0,n)\n END IF\n\n! test for convergence\n fsum = 0.0\n DO j=0,n\n fsum = fsum + f(j)\n END DO\n favg = fsum/(n+1.)\n s = 0.0\n DO j=0,n\n s = s + ((f(j)-favg)**2.)/n\n END DO\n s = sqrt(s)\n If (s .LT. EPSILON) Then\n EXIT ! Nelder Mead has converged - exit main loop\n END IF\nEND DO\n! end main loop of the minimization\n! find the index of the smallest value\n\n vs = 0\n DO j=0,n\n If (f(j) .LT. f(vs)) Then\n vs = j\n END IF\n END DO\n\n! print out the minimum\n\n DO m=0,n-1\n vtmp(m) = v(vs,m)\n END DO\n start=vtmp\n min = fun(vtmp)\n k = k+1\n\n250 FORMAT(A29,F7.4)\n300 FORMAT(F11.6,F11.6,F11.6)\n\n return\n end subroutine simplex\n", "meta": {"hexsha": "f6e9e8417e4d11cd94dcce0cb682ff4c69d48094", "size": 5986, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "FortranCode/landlord-code/simplex.f90", "max_stars_repo_name": "lnsongxf/housing-boom-bust", "max_stars_repo_head_hexsha": "bb75a2fd0646802dcdf4d5e56d1392bae7090e1c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-07-19T16:46:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-09T10:52:42.000Z", "max_issues_repo_path": "FortranCode/landlord-code/simplex.f90", "max_issues_repo_name": "floswald/housing-boom-bust", "max_issues_repo_head_hexsha": "bb75a2fd0646802dcdf4d5e56d1392bae7090e1c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-09-20T08:31:12.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-20T08:48:49.000Z", "max_forks_repo_path": "FortranCode/landlord-code/simplex.f90", "max_forks_repo_name": "kurtmitman/housing-boom-bust", "max_forks_repo_head_hexsha": "8c1ad640d79540488a5ef859f3c47ac5d4515e85", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-09-12T06:08:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T16:24:13.000Z", "avg_line_length": 22.2527881041, "max_line_length": 72, "alphanum_fraction": 0.5846976278, "num_tokens": 2035, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.929440403812707, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7532918377741473}} {"text": "program density_matrix\n! executed as ```gfortran density.f90 -o density_matrix definitions.o -llapack```\n\nuse definitions\nimplicit none\n\ninterface\n function rand_wf(NN)\n implicit none\n integer :: NN\n double complex, dimension(1:NN) :: rand_wf\n end function\nend interface\n\ndouble complex, allocatable :: wvfn(:), density(:,:), red_dens(:,:), matsie(:,:), wvfn_2(:), two_qubit(:,:)\nlogical :: separable\ninteger :: ii, jj, hilbert_dim, DD, NN, ok\ncomplex*16, allocatable :: org_hermitian(:,:), work(:), eigenvectors(:,:)\nreal*8,allocatable :: eigenvalues(:), rwork(:)\n\n\nwrite(*,*) \"What's the dimension D of the Hilbert space?\"\nread(*,*) DD\nwrite(*,*) \"How many subsystems compose the system?\"\nread(*,*) NN\nwrite(*,*) \"Is the system separable?\"\nread(*,*) separable\n\n! Describe a separable and a non-separable state\nif (separable) then\n write(*,*) \"Building representation of separable state\"\n hilbert_dim = DD*NN\n allocate(wvfn(1:hilbert_dim))\n do ii = 1, NN\n wvfn((ii-1)*DD+1:ii*DD) = rand_wf(DD)\n end do\nelse\n write(*,*) \"Building representation of non-separable state\"\n hilbert_dim = DD**NN\n allocate(wvfn(1:hilbert_dim))\n wvfn = rand_wf(hilbert_dim)\nend if\n\n! Build the density matrix for an N = 2 pure system\nhilbert_dim = DD**2\nallocate(wvfn_2(1:hilbert_dim))\nallocate(density(1:hilbert_dim,1:hilbert_dim))\n! Generate the pure system\nwvfn_2 = rand_wf(hilbert_dim)\n! Build the density matrix (outer product of wavefunction)\ndo jj = 1, hilbert_dim\n do ii = 1, hilbert_dim\n density(ii,jj) = wvfn_2(ii)*conjg(wvfn_2(jj))\n end do\nend do\n\n! get reduced matrix for a generic N = 2 density matrix\n! Theorem: Any positive trace-1 matrix is a density matrix \ndensity = rand_positive(hilbert_dim)\ndensity = density/mat_trace(density)\nallocate(red_dens(1:DD,1:DD))\nallocate(matsie(1:DD,1:DD))\ndo jj = 1, DD\n do ii = 1, DD\n matsie = density((ii-1)*DD+1:ii*DD,(jj-1)*DD+1:jj*DD)\n red_dens(ii,jj) = mat_trace(matsie)\n end do\nend do\n\n! apply to a two-qubit system\nallocate(two_qubit(1:2**2,1:2**2))\ntwo_qubit = rand_positive(2**2)\ntwo_qubit = two_qubit/mat_trace(two_qubit)\n\n! Obtain eigenvalues\nallocate(org_hermitian(1:2**2,1:2**2))\nallocate(eigenvalues(1:2**2))\nallocate(work(1:max(5000,2*2**2-1)))\nallocate(rwork(1:3*2**2-2))\n\n! copy the hermitian matrix to avoid modifying it\neigenvectors = two_qubit\n\n! Obtain an optimal lwork\ncall zheev('N','U',2**2,eigenvectors,2**2,eigenvalues,work,-1,rwork,ok)\n! the first element of work is the optimal lwork\ncall zheev('N','U',2**2,eigenvectors,2**2,eigenvalues,work,min(5000,int(work(1))),rwork,ok)\n\nif (ok.ne.0) stop \"Unsuccessful eigenvalue calculation for two-qubit system\"\n\nwrite(*,*) \"Eigenvalues of the two-qubit density matrix\"\ndo ii = 1, 2**2\n write(*,*) eigenvalues(ii)\nend do\n\n\nend program density_matrix\n\n\nfunction rand_wf(NN)\nimplicit none\ninteger :: NN, ii\ndouble complex, dimension(1:NN) :: rand_wf\nreal*8, dimension(1:NN) :: r_wf, i_wf\n\n call random_number(r_wf)\n call random_number(i_wf)\n\n r_wf = 2*r_wf - 1\n i_wf = 2*i_wf - 1\n\n do ii = 1, NN\n rand_wf(ii) = complex(r_wf(ii),i_wf(ii))\n end do\n\n ! Normalized state\n rand_wf = rand_wf/dot_product(rand_wf,rand_wf)\n\nend function rand_wf\n\n", "meta": {"hexsha": "8fd3420d7701703e7c6423f4ef6d5d4c36bcb9d5", "size": 3251, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "week_6/density.f90", "max_stars_repo_name": "eigen-carmona/quantum-computation-unipd", "max_stars_repo_head_hexsha": "f53b40bd83cb85119ce4b494e10e01b256917659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-01-11T19:41:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-05T19:22:24.000Z", "max_issues_repo_path": "week_6/density.f90", "max_issues_repo_name": "eigen-carmona/quantum-computation-unipd", "max_issues_repo_head_hexsha": "f53b40bd83cb85119ce4b494e10e01b256917659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week_6/density.f90", "max_forks_repo_name": "eigen-carmona/quantum-computation-unipd", "max_forks_repo_head_hexsha": "f53b40bd83cb85119ce4b494e10e01b256917659", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.867768595, "max_line_length": 107, "alphanum_fraction": 0.6911719471, "num_tokens": 1069, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.753291510551985}} {"text": "!\n! 20/03/2019\n! Author: Henrique Miranda\n! Create a linear system of equations to fit a quadratic function in 3D\n! the function has the general form:\n!\n! f = a +\n! ax*x + ay*y + az*z +\n! axy*x*y + axz*x*z + ayz*y*z +\n! ax2*x*x + ayy*y*y + azz*z*z (1)\n!\n! Use this as an interpolating function inside the tetrahedron\n! and apply the hybrid tetrahedron method described in\n!\n! A.H. MacDonald, S.H. Vosko, and P.T. Coleridge,\n! Journal of Physics C: Solid State Physics 12, 2991 (1979).\n!\nmodule m_defs\n integer, parameter :: dp=8\n real(dp), parameter :: zero = 0.0_dp, half = 0.5_dp, one = 1.0_dp, two=2.0_dp\n real(dp), parameter :: tol8 = 0.00000001_dp\n real(dp), parameter :: tol14 = 0.000000000000001_dp\n real(dp), parameter :: pi=3.141592653589793238462643383279502884197_dp\n real(dp), parameter :: two_pi = two*pi\nend module m_defs\n\nmodule m_quadratic\n use m_defs\n implicit none\n integer,parameter :: lwork=200\n real(dp),parameter :: rcond=tol8\n real(dp) :: work(lwork)\n\n contains\n real(dp) function f(kpt,parm)\n ! Compute the quadratic function on kpt\n real(dp),intent(in) :: kpt(3)\n real(dp),intent(in) :: parm(10)\n real(dp) :: x,y,z\n x = kpt(1);y = kpt(2);z = kpt(3)\n !f = parm(1) + &\n ! parm(2)*x + parm(3)*y + parm(4)*z + &\n ! parm(5)*x*y + parm(6)*x*z + parm(7)*y*z + &\n ! parm(8)*x*x + parm(9)*y*y + parm(10)*z*z\n f = parm(1)+x*(parm(2)+y*parm(5)+z*parm(6)+x*parm(8))+&\n y*(parm(3)+z*parm(7) +y*parm(9))+&\n z*(parm(4) +z*parm(10))\n end function f\n\n function df(kpt,parm)\n ! Compute the derivative of the quadratic function with respect to kx,ky,kz\n real(dp),intent(in) :: kpt(3)\n real(dp),intent(in) :: parm(10)\n real(dp) :: df(3)\n real(dp) :: x,y,z\n x = kpt(1);y = kpt(2);z = kpt(3)\n df(1) = parm(2) + &\n parm(5)*y + parm(6)*z + &\n 2.0_dp*parm(8)*x\n df(2) = parm(3) + &\n parm(5)*x + parm(7)*z + &\n 2.0_dp*parm(9)*y\n df(3) = parm(4) + &\n parm(6)*x + parm(7)*y + &\n 2.0_dp*parm(10)*z\n end function df\n\n subroutine fit4(kpts,eigs,parm,info)\n ! Fit a linear function using the values of the function evaluated in 4 points\n ! This is done solving a linear system of equations of the form Ax=b\n real(dp),intent(in) :: kpts(3,10)\n real(dp),intent(in) :: eigs(4)\n real(dp),intent(out) :: parm(10)\n integer,intent(out) :: info\n\n integer :: ii,irank\n real(dp) :: x,y,z\n real(dp) :: sgval(4)\n real(dp) :: a(4,4), b(4)\n\n ! Fill in the a matrix A\n do ii=1,4\n x=kpts(1,ii);y=kpts(2,ii);z=kpts(3,ii)\n a(ii,:) = [1.0_dp,x,y,z]\n end do\n\n ! Fill in the vector b\n b = eigs\n\n !solve a system of linear equations\n call dgelss(4,4,1,a,4,b,4,sgval,rcond,irank,work,lwork,info)\n parm(:4) = b(:)\n parm(5:) = zero\n end subroutine fit4\n\n subroutine fit10(kpts,eigs,parm,info)\n ! Fit a quadratic function using the values fo the function evaluated in 10 points\n ! This is done solving a linear system of equations of the form Ax=b\n real(dp),intent(in) :: kpts(3,10)\n real(dp),intent(in) :: eigs(10)\n real(dp),intent(out) :: parm(10)\n integer,intent(out) :: info\n\n integer :: ii,irank\n real(dp) :: x,y,z\n real(dp) :: sgval(10)\n real(dp) :: a(10,10), b(10)\n\n ! Fill in the a matrix A\n do ii=1,10\n x=kpts(1,ii);y=kpts(2,ii);z=kpts(3,ii)\n a(ii,:) = [1.0_dp,x,y,z,x*y,x*z,y*z,x*x,y*y,z*z]\n end do\n\n ! Fill in the vector b\n b = eigs\n\n !solve a system of linear equations\n call dgelss(10,10,1,a,10,b,10,sgval,rcond,irank,work,lwork,info)\n parm = b\n end subroutine fit10\n\n subroutine fit10_affine(eigs,parm)\n ! Fit a quadratic function using the values fo the function evaluated in 10 points\n ! This is done by inverting A of a linear system of equations of the form Ax=b\n ! A affine transformation of coordinates (x,y,z)->(a,b,c) is used following\n ! CMES: Computer Modeling in Engineering & Sciences, Vol. 94, No. 4, pp. 279-300, 2013\n ! (x1,y1,z1) -> (0,0,0)\n ! (x2,y2,z2) -> (1,0,0)\n ! (x3,y3,z3) -> (0,1,0)\n ! (x4,y4,z4) -> (0,0,1)\n !\n ! In this coordinates, the 10 vertices of the tetrahedra are:\n ! ( 0, 0, 0)\n ! ( 1, 0, 0)\n ! ( 0, 1, 0)\n ! ( 0, 0, 1)\n ! (1/2, 0, 0)\n ! ( 0, 1/2, 0)\n ! ( 0, 0 1/2)\n ! (1/2, 1/2, 0)\n ! ( 0, 1/2, 1/2)\n ! (1/2, 0, 1/2)\n !\n ! We want to describe a quadratic function (1)\n ! whose coefficients sym are:\n ! (a, ax, ay, az, axy, axz, ayz, ax2, ayy, azz)\n !\n ! A parm = eigs\n ! The matrix A is d f /d sym\n ! [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n ! [1, 1, 0, 0, 0, 0, 0, 1, 0, 0]\n ! [1, 0, 1, 0, 0, 0, 0, 0, 1, 0]\n ! [1, 0, 0, 1, 0, 0, 0, 0, 0, 1]\n ! [1, 1/2, 0, 0, 0, 0, 0, 1/4, 0, 0]\n ! [1, 0, 1/2, 0, 0, 0, 0, 0, 1/4, 0]\n ! [1, 0, 0, 1/2, 0, 0, 0, 0, 0, 1/4]\n ! [1, 1/2, 1/2, 0, 1/4, 0, 0, 1/4, 1/4, 0]\n ! [1, 0, 1/2, 1/2, 0, 0, 1/4, 0, 1/4, 1/4]\n ! [1, 1/2, 0, 1/2, 0, 1/4, 0, 1/4, 0, 1/4]\n !\n real(dp),intent(in) :: eigs(10)\n real(dp),intent(out) :: parm(10)\n\n !real(dp) :: inva(10,10)\n\n ! Fill in the inverse of the A matrix\n !inva(:,1) = [1,-3,-3,-3, 4, 4, 4, 2, 2, 2]\n !inva(:,2) = [0,-1, 0, 0, 0, 0, 0, 2, 0, 0]\n !inva(:,3) = [0, 0,-1, 0, 0, 0, 0, 0, 2, 0]\n !inva(:,4) = [0, 0, 0,-1, 0, 0, 0, 0, 0, 2]\n !inva(:,5) = [0, 4, 0, 0,-4,-4, 0,-4, 0, 0]\n !inva(:,6) = [0, 0, 4, 0,-4, 0,-4, 0,-4, 0]\n !inva(:,7) = [0, 0, 0, 4, 0,-4,-4, 0, 0,-4]\n !inva(:,8) = [0, 0, 0, 0, 4, 0, 0, 0, 0, 0]\n !inva(:,9) = [0, 0, 0, 0, 0, 0, 4, 0, 0, 0]\n !inva(:,10) = [0, 0, 0, 0, 0, 4, 0, 0, 0, 0]\n !call dgemv('N',10,10,one,inva,10,eigs,1,zero,parm,1)\n\n parm( 1) = eigs(1)\n parm( 2) = -3.0_dp*eigs(1)-eigs(2)+4.0_dp*eigs(5)\n parm( 3) = -3.0_dp*eigs(1)-eigs(3)+4.0_dp*eigs(6)\n parm( 4) = -3.0_dp*eigs(1)-eigs(4)+4.0_dp*eigs(7)\n parm( 5) = +4.0_dp*(eigs(1)-eigs(5)-eigs(6)+eigs(8))\n parm( 6) = +4.0_dp*(eigs(1)-eigs(5)-eigs(7)+eigs(10))\n parm( 7) = +4.0_dp*(eigs(1)-eigs(6)-eigs(7)+eigs(9))\n parm( 8) = +2.0_dp*(eigs(1)+eigs(2)-2.0_dp*eigs(5))\n parm( 9) = +2.0_dp*(eigs(1)+eigs(3)-2.0_dp*eigs(6))\n parm(10) = +2.0_dp*(eigs(1)+eigs(4)-2.0_dp*eigs(7))\n\n end subroutine fit10_affine\n\n subroutine fit4d(kpts,eigs,vels,parm,info)\n ! Fit a quadratic function using the values and derivatives of the function evaluated in 4 points\n ! This is done solving a linear system of equations of the form Ax=b\n real(dp),intent(in) :: kpts(3,4)\n real(dp),intent(in) :: eigs(4)\n real(dp),intent(in) :: vels(3,4)\n real(dp),intent(out) :: parm(10)\n integer,intent(out) :: info\n\n integer :: ii\n integer :: irank\n real(dp) :: x,y,z\n real(dp) :: sgval(10)\n real(dp) :: a(16,10),b(16)\n\n ! Fill in the a matrix for eigenvalues\n do ii=1,4\n x=kpts(1,ii);y=kpts(2,ii);z=kpts(3,ii)\n a(ii,:) = [1.0_dp,x,y,z,x*y,x*z,y*z,x*x,y*y,z*z]\n end do\n\n ! Fill in the matrix for velocities (explicit just because)\n x=kpts(1,1);y=kpts(2,1);z=kpts(3,1)\n a(5,:) = [0.0_dp,1.0_dp,0.0_dp,0.0_dp,y,z,0.0_dp,2.0_dp*x,0.0_dp,0.0_dp] !dx\n a(6,:) = [0.0_dp,0.0_dp,1.0_dp,0.0_dp,x,0.0_dp,z,0.0_dp,2.0_dp*y,0.0_dp] !dy\n a(7,:) = [0.0_dp,0.0_dp,0.0_dp,1.0_dp,0.0_dp,x,y,0.0_dp,0.0_dp,2.0_dp*z] !dz\n x=kpts(1,2);y=kpts(2,2);z=kpts(3,2)\n a(8,:) = [0.0_dp,1.0_dp,0.0_dp,0.0_dp,y,z,0.0_dp,2.0_dp*x,0.0_dp,0.0_dp] !dx\n a(9,:) = [0.0_dp,0.0_dp,1.0_dp,0.0_dp,x,0.0_dp,z,0.0_dp,2.0_dp*y,0.0_dp] !dy\n a(10,:) = [0.0_dp,0.0_dp,0.0_dp,1.0_dp,0.0_dp,x,y,0.0_dp,0.0_dp,2.0_dp*z] !dz\n x=kpts(1,3);y=kpts(2,3);z=kpts(3,3)\n a(11,:) = [0.0_dp,1.0_dp,0.0_dp,0.0_dp,y,z,0.0_dp,2.0_dp*x,0.0_dp,0.0_dp] !dx\n a(12,:) = [0.0_dp,0.0_dp,1.0_dp,0.0_dp,x,0.0_dp,z,0.0_dp,2.0_dp*y,0.0_dp] !dy\n a(13,:) = [0.0_dp,0.0_dp,0.0_dp,1.0_dp,0.0_dp,x,y,0.0_dp,0.0_dp,2.0_dp*z] !dz\n x=kpts(1,4);y=kpts(2,4);z=kpts(3,4)\n a(14,:) = [0.0_dp,1.0_dp,0.0_dp,0.0_dp,y,z,0.0_dp,2.0_dp*x,0.0_dp,0.0_dp] !dx\n a(15,:) = [0.0_dp,0.0_dp,1.0_dp,0.0_dp,x,0.0_dp,z,0.0_dp,2.0_dp*y,0.0_dp] !dy\n a(16,:) = [0.0_dp,0.0_dp,0.0_dp,1.0_dp,0.0_dp,x,y,0.0_dp,0.0_dp,2.0_dp*z] !dz\n\n ! Fill in the vector b\n b(:4) = eigs\n b(5:7) = vels(:,1)\n b(8:10) = vels(:,2)\n b(11:13) = vels(:,3)\n b(14:16) = vels(:,4)\n\n !solve a system of linear equations\n call dgelss(16,10,1,a,16,b,16,sgval,rcond,irank,work,lwork,info)\n parm = b(:10)\n end subroutine fit4d\n\nend module m_quadratic\n\nmodule m_tetralite\n\n use m_defs\n implicit none\n integer :: tetra_6lshifts(3,4,6)\n\n private :: f\n contains\n subroutine tetralite_init()\n tetra_6lshifts(:,1,1) = [0,0,0]\n tetra_6lshifts(:,2,1) = [1,0,0]\n tetra_6lshifts(:,3,1) = [0,1,0]\n tetra_6lshifts(:,4,1) = [1,0,1]\n tetra_6lshifts(:,1,2) = [1,0,0]\n tetra_6lshifts(:,2,2) = [1,1,0]\n tetra_6lshifts(:,3,2) = [0,1,0]\n tetra_6lshifts(:,4,2) = [1,0,1]\n tetra_6lshifts(:,1,3) = [0,1,0]\n tetra_6lshifts(:,2,3) = [1,1,0]\n tetra_6lshifts(:,3,3) = [1,0,1]\n tetra_6lshifts(:,4,3) = [1,1,1]\n tetra_6lshifts(:,1,4) = [0,0,0]\n tetra_6lshifts(:,2,4) = [0,1,0]\n tetra_6lshifts(:,3,4) = [0,0,1]\n tetra_6lshifts(:,4,4) = [1,0,1]\n tetra_6lshifts(:,1,5) = [0,0,1]\n tetra_6lshifts(:,2,5) = [1,0,1]\n tetra_6lshifts(:,3,5) = [0,1,0]\n tetra_6lshifts(:,4,5) = [0,1,1]\n tetra_6lshifts(:,1,6) = [0,1,0]\n tetra_6lshifts(:,2,6) = [1,0,1]\n tetra_6lshifts(:,3,6) = [0,1,1]\n tetra_6lshifts(:,4,6) = [1,1,1]\n end subroutine\n\n pure function grid(divs,gp) result(ik)\n integer,intent(in) :: divs(3),gp(3)\n integer :: ik\n integer :: ix,iy,iz\n ix=gp(1); iy=gp(2); iz=gp(3)\n ix = mod(ix-1,divs(1))+1\n iy = mod(iy-1,divs(2))+1\n iz = mod(iz-1,divs(3))+1\n ik = (ix-1)*divs(2)*divs(3)+(iy-1)*divs(3)+iz\n end function\n\n pure function gridp(divs,gp) result(ik)\n integer,intent(in) :: divs(3),gp(3)\n integer :: ik\n integer :: ix,iy,iz\n ix=gp(1); iy=gp(2); iz=gp(3)\n ik = (ix-1)*divs(2)*divs(3)+(iy-1)*divs(3)+iz\n end function\n\n pure function inv_grid(divs,ik) result(gp)\n integer,intent(in) :: divs(3),ik\n integer :: gp(3)\n integer :: ix,iy,iz,lda,ldb\n lda = divs(2)*divs(3)\n ldb = divs(3)\n ix=(ik-1)/lda\n iy=(ik-ix*lda-1)/ldb\n iz=(ik-ix*lda-iy*ldb-1)\n gp = [ix+1,iy+1,iz+1]\n end function\n\n pure function grid_kpoint(divs,gp) result(kpt)\n ! Get the kpoint coordinates from gridpoint\n integer,intent(in) :: divs(3),gp(3)\n real(dp) :: kpt(3)\n kpt = one*(gp-1)/divs-half\n end function\n\n pure real(dp) function f(n,m,w,eig)\n integer,intent(in) :: n,m\n real(dp),intent(in) :: w,eig(4)\n f = ((w - eig(m)) / (eig(n) - eig(m)))\n end function\n\n pure real(dp) function g1(w,eig)\n real(dp),intent(in) :: w,eig(4)\n g1 = (3.0_dp *&\n f(2, 1, w, eig) *&\n f(3, 1, w, eig) /&\n (eig(4) - eig(1)))\n end function\n\n pure real(dp) function g2(w,eig)\n real(dp),intent(in) :: w,eig(4)\n g2 = (3.0_dp /&\n (eig(4) - eig(1)) *&\n (f(2, 3, w, eig) *&\n f(3, 1, w, eig) +&\n f(3, 2, w, eig) *&\n f(2, 4, w, eig)))\n end function\n\n pure real(dp) function g3(w,eig)\n real(dp),intent(in) :: w,eig(4)\n g3 = (3.0_dp *&\n f(2, 4, w, eig) *&\n f(3, 4, w, eig) /&\n (eig(4) - eig(1)))\n end function\n\n pure real(dp) function I10(w,eig)\n real(dp),intent(in) :: w,eig(4)\n I10 = (f(1, 2, w, eig) +&\n f(1, 3, w, eig) +&\n f(1, 4, w, eig))\n end function\n\n pure real(dp) function I11(w,eig)\n real(dp),intent(in) :: w,eig(4)\n I11 = f(2, 1, w, eig)\n end function\n\n pure real(dp) function I12(w,eig)\n real(dp),intent(in) :: w,eig(4)\n I12 = f(3, 1, w, eig)\n end function\n\n pure real(dp) function I13(w,eig)\n real(dp),intent(in) :: w,eig(4)\n I13 = f(4, 1, w, eig)\n end function\n\n pure real(dp) function I20(w,eig)\n real(dp),intent(in) :: w,eig(4)\n I20 = (f(1, 4, w, eig) +&\n f(1, 3, w, eig) *&\n f(3, 1, w, eig) *&\n f(2, 3, w, eig) /&\n (f(2, 3, w, eig) *&\n f(3, 1, w, eig) +&\n f(3, 2, w, eig) *&\n f(2, 4, w, eig)))\n end function\n\n pure real(dp) function I21(w,eig)\n real(dp),intent(in) :: w,eig(4)\n I21 = (f(2, 3, w, eig) +&\n f(2, 4, w, eig) *&\n f(2, 4, w, eig) *&\n f(3, 2, w, eig) /&\n (f(2, 3, w, eig) *&\n f(3, 1, w, eig) +&\n f(3, 2, w, eig) *&\n f(2, 4, w, eig)))\n end function\n\n pure real(dp) function I22(w,eig)\n real(dp),intent(in) :: w,eig(4)\n I22 = (f(3, 2, w, eig) +&\n f(3, 1, w, eig) *&\n f(3, 1, w, eig) *&\n f(2, 3, w, eig) /&\n (f(2, 3, w, eig) *&\n f(3, 1, w, eig) +&\n f(3, 2, w, eig) *&\n f(2, 4, w, eig)))\n end function\n\n pure real(dp) function I23(w,eig)\n real(dp),intent(in) :: w,eig(4)\n I23 = (f(4, 1, w, eig) +&\n f(4, 2, w, eig) *&\n f(2, 4, w, eig) *&\n f(3, 2, w, eig) /&\n (f(2, 3, w, eig) *&\n f(3, 1, w, eig) +&\n f(3, 2, w, eig) *&\n f(2, 4, w, eig)))\n end function\n\n pure real(dp) function I30(w,eig)\n real(dp),intent(in) :: w,eig(4)\n I30 = f(1, 4, w, eig)\n end function\n\n pure real(dp) function I31(w,eig)\n real(dp),intent(in) :: w,eig(4)\n I31 = f(2, 4, w, eig)\n end function\n\n pure real(dp) function I32(w,eig)\n real(dp),intent(in) :: w,eig(4)\n I32 = f(3, 4, w, eig)\n end function\n\n pure real(dp) function I33(w,eig)\n real(dp),intent(in) :: w,eig(4)\n I33 = (f(4, 1, w, eig) +&\n f(4, 2, w, eig) +&\n f(4, 3, w, eig))\n end function\n\n subroutine tetralite_delta(eig,wvals,nw,alpha,integral)\n ! function to evaluate delta\n ! theare are the expressions from\n ! A.H. MacDonald, S.H. Vosko, and P.T. Coleridge,\n ! Journal of Physics C: Solid State Physics 12, 2991 (1979).\n ! as implemented in spglib implemented by Atsushi Togo translated into fortran\n integer,intent(in) :: nw\n real(dp),intent(in) :: eig(4),alpha(4)\n real(dp),intent(in) :: wvals(nw)\n real(dp),intent(out) :: integral(nw)\n integer :: iw\n real(dp) :: w,g\n\n do iw=1,nw\n w = wvals(iw)\n\n ! w < e1 nothing to do\n if (w < eig(1)) cycle\n\n ! e1 < w < e2\n if (w < eig(2)) then\n g = g1(w,eig)/3.0_dp\n integral(iw) = integral(iw)+g*I10(w,eig)*alpha(1)\n integral(iw) = integral(iw)+g*I11(w,eig)*alpha(2)\n integral(iw) = integral(iw)+g*I12(w,eig)*alpha(3)\n integral(iw) = integral(iw)+g*I13(w,eig)*alpha(4)\n cycle\n endif\n\n ! e2 < eps < e3\n if (w < eig(3)) then\n g = g2(w,eig)/3.0_dp\n integral(iw) = integral(iw)+g*I20(w,eig)*alpha(1)\n integral(iw) = integral(iw)+g*I21(w,eig)*alpha(2)\n integral(iw) = integral(iw)+g*I22(w,eig)*alpha(3)\n integral(iw) = integral(iw)+g*I23(w,eig)*alpha(4)\n cycle\n endif\n\n ! e3 < eps\n if (w < eig(4)) then\n g = g3(w,eig)/3.0_dp\n integral(iw) = integral(iw)+g*I30(w,eig)*alpha(1)\n integral(iw) = integral(iw)+g*I31(w,eig)*alpha(2)\n integral(iw) = integral(iw)+g*I32(w,eig)*alpha(3)\n integral(iw) = integral(iw)+g*I33(w,eig)*alpha(4)\n cycle\n endif\n\n ! e4 < eps\n if (eig(4) < w) exit\n\n end do\n\n end subroutine tetralite_delta\n\n pure subroutine sort_4tetra(list,perm)\n\n integer, intent(inout) :: perm(4)\n real(dp), intent(inout) :: list(4)\n\n integer :: ia,ib,ic,id\n integer :: ilow1,ilow2,ihigh1,ihigh2\n integer :: ilowest,ihighest\n integer :: imiddle1,imiddle2\n real(dp) :: va,vb,vc,vd\n real(dp) :: vlow1,vlow2,vhigh1,vhigh2\n real(dp) :: vlowest,vhighest\n real(dp) :: vmiddle1,vmiddle2\n\n va = list(1); ia = perm(1)\n vb = list(2); ib = perm(2)\n vc = list(3); ic = perm(3)\n vd = list(4); id = perm(4)\n\n if (va < vb) then\n vlow1 = va; vhigh1 = vb\n ilow1 = ia; ihigh1 = ib\n else\n vlow1 = vb; vhigh1 = va\n ilow1 = ib; ihigh1 = ia\n endif\n\n if (vc < vd) then\n vlow2 = vc; vhigh2 = vd\n ilow2 = ic; ihigh2 = id\n else\n vlow2 = vd; vhigh2 = vc\n ilow2 = id; ihigh2 = ic\n endif\n\n if (vlow1 < vlow2) then\n vlowest = vlow1; vmiddle1 = vlow2\n ilowest = ilow1; imiddle1 = ilow2\n else\n vlowest = vlow2; vmiddle1 = vlow1\n ilowest = ilow2; imiddle1 = ilow1\n endif\n\n if (vhigh1 > vhigh2) then\n vhighest = vhigh1; vmiddle2 = vhigh2\n ihighest = ihigh1; imiddle2 = ihigh2\n else\n vhighest = vhigh2; vmiddle2 = vhigh1\n ihighest = ihigh2; imiddle2 = ihigh1\n endif\n\n if (vmiddle1 < vmiddle2) then\n list = [vlowest,vmiddle1,vmiddle2,vhighest]\n perm = [ilowest,imiddle1,imiddle2,ihighest]\n else\n list = [vlowest,vmiddle2,vmiddle1,vhighest]\n perm = [ilowest,imiddle2,imiddle1,ihighest]\n endif\n\n end subroutine sort_4tetra\n\nend module\n\nmodule m_dividetetra\n ! This is to implement an quadratic hybrid tetrahedra integration method as deribed in:\n ! A.H. MacDonald, S.H. Vosko, and P.T. Coleridge,\n ! Journal of Physics C: Solid State Physics 12, 2991 (1979).\n use m_quadratic\n use m_tetralite\n implicit none\n integer :: ieigs(2,10)\n integer :: tetra8(4,8)\n integer :: tetra_6qshifts(3,10,6)\n\n contains\n subroutine dividetetra_init()\n ! Initialization routine\n integer :: itetra\n\n ! Indexes of the middlepoints w.r.t initial tetrahedron\n ieigs(:,1) = [1,2] !5\n ieigs(:,2) = [1,3] !6\n ieigs(:,3) = [1,4] !7\n ieigs(:,4) = [2,3] !8\n ieigs(:,5) = [3,4] !9\n ieigs(:,6) = [2,4] !10\n\n ! 8 tetrahedra from the paper\n tetra8(:,1) = [1,5, 6, 7]\n tetra8(:,2) = [2,5, 8,10]\n tetra8(:,3) = [3,8, 9, 6]\n tetra8(:,4) = [4,9, 7,10]\n\n tetra8(:,5) = [7,8,10, 9]\n tetra8(:,6) = [7,8,10, 5]\n tetra8(:,7) = [7,8, 6, 9]\n tetra8(:,8) = [7,8, 6, 5]\n\n ! Now I generate shifts for quadratic tetrahedron\n ! this is done by scaling the original shifts by 2\n ! and computing the 10 midpoints for each of the 6 tetrahedra\n do itetra=1,6\n ! the first 4 shifts are just a copy\n tetra_6qshifts(:,:4,itetra) = 2*tetra_6lshifts(:,:,itetra)\n ! the additional 6 are the midpoints\n tetra_6qshifts(:,5:,itetra) = nint(get_6midkpts(two*tetra_6lshifts(:,:,itetra)))\n end do\n\n end subroutine dividetetra_init\n\n function get_6midkpts(kpts) result(mid)\n real(dp),intent(in) :: kpts(3,4)\n real(dp) :: mid(3,6)\n integer :: ii,ik1,ik2\n ! get the 6 midpoints\n do ii=1,6\n ik1 = ieigs(1,ii)\n ik2 = ieigs(2,ii)\n mid(:,ii) = half*(kpts(:,ik1)+kpts(:,ik2))\n end do\n end function\n\n function get_values(kpts,n,parm) result(val)\n ! Get the values of the quadratic function on a list of kpoints\n integer,intent(in) :: n\n real(dp),intent(in) :: kpts(3,n)\n real(dp),intent(in) :: parm(10)\n real(dp) :: val(n)\n integer :: ii\n ! evaluate a functions on a list of points\n do ii=1,n\n val(ii) = f(kpts(:,ii),parm)\n end do\n end function\n\n subroutine get_8tetra(eig10,mat10,wvals,nw,integral)\n ! sum the contribution of 8 tetrahedra generated by dividing one tetrahedron\n integer,intent(in) :: nw\n real(dp),intent(in) :: eig10(10), mat10(10)\n real(dp),intent(in) :: wvals(nw)\n real(dp),intent(out) :: integral(nw)\n\n integer :: itetra\n integer :: ind(4)\n real(dp) :: eig4(4),mat4(4)\n\n ! Evaluate and add the contribution of 8 tetrahedra\n integral = 0.0_dp\n do itetra=1,8\n eig4(:) = eig10(tetra8(:,itetra))\n mat4(:) = mat10(tetra8(:,itetra))\n ind = [1,2,3,4]\n call sort_4tetra(eig4,ind)\n call tetralite_delta(eig4,wvals,nw,mat4(ind),integral)\n end do\n end subroutine\n\n recursive subroutine hybridtetra(kpt4,eig4,mat4,parm_eig,parm_mat,wvals,nw,integral,n,depth)\n ! subdivide tetrahedra n times and evaluate contibutions\n ! number of frequencies, desired depth\n integer,intent(in) :: nw,n\n ! quadratic coeficients for interpolation\n real(dp),intent(in) :: parm_eig(10),parm_mat(10)\n real(dp),intent(in) :: kpt4(3,4),eig4(4),mat4(4)\n real(dp),intent(in) :: wvals(nw)\n real(dp),intent(inout) :: integral(nw)\n integer,optional,intent(in) :: depth\n integer :: itetra,idepth\n integer :: ind(4)\n real(dp) :: eig(4),mat(4)\n real(dp) :: mid10(3,10),eig10(10),mat10(10)\n\n ! how deep are we?\n idepth = 1; if (present(depth)) idepth = depth\n if (idepth==1) integral = 0.0_dp\n\n ! if in the desired depth sum the contribution of this tetrahedron\n if (idepth==n) then\n eig = eig4\n mat = 1.0_dp/8.0_dp**(idepth-1)\n call sort_4tetra(eig,ind)\n call tetralite_delta(eig,wvals,nw,mat,integral)\n ! otherwise go deeper for each tetrahedron\n else\n ! copy 4 vertices data\n mid10(:,:4) = kpt4\n eig10(:4) = eig4\n mat10(:4) = mat4\n ! get the additional 6 middle points\n mid10(:,5:) = get_6midkpts(kpt4)\n eig10(5:) = get_values(mid10(:,5:),6,parm_eig)\n mat10(5:) = get_values(mid10(:,5:),6,parm_mat)\n ! Loop over the 8 sub tetrahedra\n do itetra=1,8\n ! get coordinates of k-points of this tetrahedron\n ind(:) = tetra8(:,itetra)\n ! subdivide and evaluate again\n call hybridtetra(mid10(:,ind),eig10(ind),mat10(ind),parm_eig,parm_mat,wvals,nw,integral,n,idepth+1)\n end do\n end if\n end subroutine\nend module\n\nprogram fit\n use m_quadratic\n use m_dividetetra\n use m_tetralite\n implicit none\n\n integer :: ii,info\n real(dp) :: kpts(3,10), eigs(10), vels(3,10)\n real(dp) :: parm_mat(10), parm_eig(10)\n\n ! Define a function to parametrize eigenvalues\n parm_eig = [ 1.0_dp,&\n 1.0_dp, 1.0_dp, 2.0_dp,&\n 2.0_dp, 1.2_dp, 2.0_dp,&\n 1.0_dp, 8.0_dp, 1.0_dp]\n\n parm_mat = [ 1.0_dp,&\n 0.0_dp, 0.0_dp, 0.0_dp,&\n 0.0_dp, 0.0_dp, 0.0_dp,&\n 0.0_dp, 0.0_dp, 0.0_dp]\n\n ! Generate 10 random points\n call random_number(kpts)\n\n ! Test fitting a quadratic function using 10 points or 4 points + derivatives\n fit_stuff : block\n ! Set eigenvalues and velocities\n do ii=1,10\n eigs(ii) = f(kpts(:,ii),parm_eig)\n vels(:,ii) = df(kpts(:,ii),parm_eig)\n end do\n write(*,'(10f8.3)') (parm_eig(ii),ii=1,10)\n\n ! Fit using 10 points\n call fit10(kpts,eigs,parm_eig,info)\n write(*,'(10f8.3)') (parm_eig(ii),ii=1,10)\n\n ! Fit using 4 points and derivatives\n call fit4d(kpts,eigs,vels,parm_eig,info)\n write(*,'(10f8.3)') (parm_eig(ii),ii=1,10)\n end block fit_stuff\n\n ! now its a bit of tetrahedron stuff\n ! subdivide a tetrahedron in 8 and get the value of the integral inside it\n tetradivide_stuff : block\n integer :: nw\n real(dp) :: mid6(3,6)\n real(dp) :: eig4(4), mat4(4)\n real(dp) :: eig10(10), mat10(10)\n real(dp),allocatable :: wvals(:)\n real(dp),allocatable :: integral(:)\n\n ! Initialize\n parm_eig = parm_eig\n call tetralite_init()\n call dividetetra_init()\n\n nw = 10\n allocate(wvals(nw))\n allocate(integral(nw))\n wvals = [(ii,ii=1,nw)]\n\n ! 4 of the points come from the mother\n eig10(:4) = eigs(:4)\n ! Get the additional 6 middle points and their eigenvalues\n mid6 = get_6midkpts(kpts)\n eig10(5:) = get_values(mid6,6,parm_eig)\n ! Here I set the matrix elements to constants.\n ! Could interpolate them as well (linearly or quadratically)\n mat10 = 1.0_dp\n call get_8tetra(eig10,mat10,wvals,nw,integral)\n\n ! now test the hybrid tetrahedron routine\n eig4 = get_values(kpts,4,parm_eig)\n mat4 = get_values(kpts,4,parm_mat)\n call hybridtetra(kpts(:,:4),eig4,mat4,parm_eig,parm_mat,wvals,nw,integral,1)\n deallocate(wvals)\n deallocate(integral)\n\n end block tetradivide_stuff\n\n tetralite_stuff: block\n integer :: ix,iy,iz\n integer :: ik,nk,nw\n integer :: itetra,isummit,idepth\n integer :: jtetra,jsummit,idx10\n integer :: band\n integer :: divs(3),ind(4),gp(3)\n character(len=100) :: fname\n real(dp) :: emin,emax,step\n real(dp) :: start_time, stop_time\n real(dp) :: kpt(3),kpt4(3,4),eig4(4),mat4(4),vel4(3,4)\n real(dp) :: kpt10(3,10),eig10(10),mat10(10)\n real(dp) :: parm_eig(10)\n real(dp),allocatable :: eig(:),vel(:,:)\n real(dp),allocatable :: wvals(:)\n real(dp),allocatable :: dweight(:,:)\n real(dp),allocatable :: integral(:), integral_tmp(:)\n\n ! choose TB band or parabola\n band = 1\n\n ! choose how many times to apply recursion\n idepth = 1\n divs = [2,2,2]\n divs = [4,4,4]\n divs = [6,6,6]\n divs = [8,8,8]\n divs = [10,10,10]\n !divs = [20,20,20]\n !divs = [30,30,30]\n !divs = [40,40,40]\n !divs = [50,50,50]\n divs = [100,100,100]\n nw = 500\n\n write(*,*) divs\n write(*,*) idepth\n\n nk = divs(1)*divs(2)*divs(3)\n allocate(eig(nk))\n allocate(vel(3,nk))\n allocate(wvals(nw))\n allocate(dweight(4,nw))\n allocate(integral(nw))\n allocate(integral_tmp(nw))\n\n ! Evaluate function on each kpoint\n ! We want to precompute the values of the function in the BZ and then use then to compute DOS\n ! Note that we assume that the functions are periodic, if this is not the case\n ! then the precomputed velocities will not be correct.\n ! this is the case for the parabola_band\n ! For testing purposes we can recompute the velocities for the quadratic tetrahedra bellow\n do ix=1,divs(1)\n do iy=1,divs(2)\n do iz=1,divs(3)\n kpt = grid_kpoint(divs,[ix,iy,iz])\n ik = grid(divs,[ix,iy,iz])\n select case(band)\n case(1)\n call tb_band(kpt,eig(ik),vel(:,ik))\n case(2)\n call parabola_band(kpt,eig(ik),vel(:,ik))\n end select\n end do\n end do\n end do\n ! For the moment I set the matrix elements to zero\n mat4 = one\n mat10 = one\n\n\n ! Determine DOS energy range\n emin = minval(eig)-0.2_dp\n emax = maxval(eig)+0.2_dp\n step = (emax-emin)/(nw-1)\n wvals = [(emin+ii*step,ii=0,nw-1)]\n\n ! Compute DOS with linear tetrahedron\n call cpu_time(start_time)\n integral = zero\n mat4 = one/nk\n do ix=1,divs(1)\n do iy=1,divs(2)\n do iz=1,divs(3)\n ! generate 6 tetrahedra for this point\n do itetra=1,6\n do isummit=1,4\n gp = [ix,iy,iz]+tetra_6lshifts(:,isummit,itetra)\n ! Get eigenvalues and velocities\n ik = grid(divs,gp)\n eig4(isummit) = eig(ik)\n vel4(:,isummit) = vel(:,ik)\n ! Compute eigenvalues and velocities\n !kpt = grid_kpoint(divs,gp)\n !call tb_band(kpt,eig4(isummit),vel4(:,isummit))\n !call parabola_band(kpt,eig4(isummit),vel4(:,isummit))\n end do\n call sort_4tetra(eig4,ind)\n call tetralite_delta(eig4,wvals,nw,mat4,integral)\n end do\n end do\n end do\n end do\n call cpu_time(stop_time)\n write(*,'(a30,f12.6,a)') 'linear dos took:',(stop_time-start_time), ' [s]'\n write(fname,'(a,i0,a)') 'dosl',divs(1),'.dat'\n call write_file(fname,nw,wvals,integral)\n\n ! Compute DOS with quadratic tetrahedron (fitting only scalars)\n call cpu_time(start_time)\n integral = zero\n mat4=one\n ! loop over points\n do ix=1,divs(1),2\n do iy=1,divs(2),2\n do iz=1,divs(3),2\n ! generate 6 tetrahedra for this point\n do itetra=1,6\n ! each tetrahdra has 10 points\n do isummit=1,10\n gp = [ix,iy,iz]+tetra_6qshifts(:,isummit,itetra)\n ! Get eigenvalues\n ik = grid(divs,gp)\n eig10(isummit) = eig(ik)\n kpt10(:,isummit) = grid_kpoint(divs,gp)\n end do\n ! fit energies\n call fit10(kpt10,eig10,parm_eig,info)\n ! now apply hibrid tetrahedron to each of the 8 tetrahedra\n do jtetra=1,8\n do jsummit=1,4\n idx10 = tetra8(jsummit,jtetra)\n eig4(jsummit) = eig10(idx10)\n kpt4(:,jsummit) = kpt10(:,idx10)\n end do\n ! get hybrid weights\n call hybridtetra(kpt4,eig4,mat4,parm_eig,parm_mat,wvals,nw,integral_tmp,idepth)\n integral = integral + integral_tmp/nk\n end do\n end do\n end do\n end do\n end do\n call cpu_time(stop_time)\n write(*,'(a30,f12.6,a)') 'quadratic scalar dos took:',(stop_time-start_time), ' [s]'\n write(fname,'(a,i0,a,i0,a)') 'dosqs',divs(1),'d',idepth,'.dat'\n call write_file(fname,nw,wvals,integral)\n\n ! Compute DOS with quadratic tetrahedron (fitting only scalars and using affine transformation)\n call cpu_time(start_time)\n integral = zero\n ! loop over points\n kpt10(:,1) = [0.0_dp,0.0_dp,0.0_dp]\n kpt10(:,2) = [1.0_dp,0.0_dp,0.0_dp]\n kpt10(:,3) = [0.0_dp,1.0_dp,0.0_dp]\n kpt10(:,4) = [0.0_dp,0.0_dp,1.0_dp]\n kpt10(:,5:) = get_6midkpts(kpt10(:,:4))\n do ix=1,divs(1),2\n do iy=1,divs(2),2\n do iz=1,divs(3),2\n ! generate 6 tetrahedra for this point\n do itetra=1,6\n ! each tetrahdra has 10 points\n do isummit=1,10\n gp = [ix,iy,iz]+tetra_6qshifts(:,isummit,itetra)\n ! Get eigenvalues\n ik = grid(divs,gp)\n eig10(isummit) = eig(ik)\n end do\n ! fit energies\n call fit10_affine(eig10,parm_eig)\n ! now apply hibrid tetrahedron to each of the 8 tetrahedra\n do jtetra=1,8\n do jsummit=1,4\n idx10 = tetra8(jsummit,jtetra)\n eig4(jsummit) = eig10(idx10)\n kpt4(:,jsummit) = kpt10(:,idx10)\n end do\n ! get hybrid weights\n call hybridtetra(kpt4,eig4,mat4,parm_eig,parm_mat,wvals,nw,integral_tmp,idepth)\n integral = integral + integral_tmp/nk\n end do\n end do\n end do\n end do\n end do\n call cpu_time(stop_time)\n write(*,'(a30,f12.6,a)') 'quadratic affine dos took:',(stop_time-start_time), ' [s]'\n write(fname,'(a,i0,a,i0,a)') 'dosqsa',divs(1),'d',idepth,'.dat'\n call write_file(fname,nw,wvals,integral)\n\n\n\n ! Compute DOS with quadratic tetrahedron (fitting the velocities)\n call cpu_time(start_time)\n integral = zero\n ! loop over points\n do ix=1,divs(1)\n do iy=1,divs(2)\n do iz=1,divs(3)\n ! generate 6 tetrahedra for this point\n do itetra=1,6\n do isummit=1,4\n gp = [ix,iy,iz]+tetra_6lshifts(:,isummit,itetra)\n ! Get eigenvalues and velocities\n ik = grid(divs,gp)\n eig4(isummit) = eig(ik)\n vel4(:,isummit) = vel(:,ik)\n kpt4(:,isummit) = grid_kpoint(divs,gp)\n ! Activate this for the parabola band\n ! Compute eigenvalues and velocities\n !kpt4(:,isummit) = grid_kpoint(divs,gp)\n !call tb_band(kpt4(:,isummit),eig4(isummit),vel4(:,isummit))\n !call parabola_band(kpt4(:,isummit),eig4(isummit),vel4(:,isummit))\n end do\n ! fit energies\n call fit4d(kpt4,eig4,vel4,parm_eig,info)\n ! get hybrid weights\n call hybridtetra(kpt4,eig4,mat4,parm_eig,parm_mat,wvals,nw,integral_tmp,idepth)\n integral = integral + integral_tmp/nk\n end do\n end do\n end do\n end do\n call cpu_time(stop_time)\n write(*,'(a30,f12.6,a)') 'quadratic velocity dos took:',(stop_time-start_time), ' [s]'\n write(fname,'(a,i0,a,i0,a)') 'dosq',divs(1),'d',idepth,'.dat'\n call write_file(fname,nw,wvals,integral)\n\n deallocate(eig)\n deallocate(vel)\n deallocate(wvals)\n deallocate(dweight)\n deallocate(integral)\n deallocate(integral_tmp)\n\n end block tetralite_stuff\n\n contains\n pure subroutine parabola_band(kpt,eig,vel)\n ! Simple parabola\n real(dp),intent(in) :: kpt(3)\n real(dp),intent(out) :: eig, vel(3)\n real(dp) :: x,y,z\n x = kpt(1)*two_pi\n y = kpt(2)*two_pi\n z = kpt(3)*two_pi\n eig = x*x+y*y+z*z\n vel(1) = 2*two_pi*x\n vel(2) = 2*two_pi*y\n vel(3) = 2*two_pi*z\n end subroutine\n\n pure subroutine tb_band(kpt,eig,vel)\n ! TB band\n real(dp),intent(in) :: kpt(3)\n real(dp),intent(out) :: eig, vel(3)\n real(dp) :: x,y,z\n x = kpt(1)*two_pi\n y = kpt(2)*two_pi\n z = kpt(3)*two_pi\n eig = -(cos(x)*cos(y) + cos(x)*cos(z) + cos(y)*cos(z))\n vel(1) = two_pi*(cos(y)*sin(x) + cos(z)*sin(x))\n vel(2) = two_pi*(cos(x)*sin(y) + cos(z)*sin(y))\n vel(3) = two_pi*(cos(x)*sin(z) + cos(y)*sin(z))\n end subroutine\n\n subroutine write_file(fname,nw,wvals,integral)\n integer :: iw,nw\n real(dp) :: wvals(nw), integral(nw)\n character(len=100) :: fname\n open(unit=1,file=fname)\n do iw=1,nw\n write(1,*) wvals(iw), integral(iw)\n end do\n close(1)\n end subroutine\nend program fit\n\n", "meta": {"hexsha": "bf0ed3e73c8f3a238f515b1b0c1ef55e09f38856", "size": 32861, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "quadratic/quadratic.f90", "max_stars_repo_name": "henriquemiranda/fortran_snippets", "max_stars_repo_head_hexsha": "bd6720505c22835cc00948cbe002b80d0cf16377", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "quadratic/quadratic.f90", "max_issues_repo_name": "henriquemiranda/fortran_snippets", "max_issues_repo_head_hexsha": "bd6720505c22835cc00948cbe002b80d0cf16377", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "quadratic/quadratic.f90", "max_forks_repo_name": "henriquemiranda/fortran_snippets", "max_forks_repo_head_hexsha": "bd6720505c22835cc00948cbe002b80d0cf16377", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.9425612053, "max_line_length": 107, "alphanum_fraction": 0.5628556648, "num_tokens": 13128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765140114859, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7532914948861383}} {"text": "program array_op_2d\nimplicit none\n\ninteger :: a(2, 2, 1), b(2, 2, 1), c(2, 2, 1)\ninteger :: i, j, k\n\ndo i = 1, 2\n do j = 1, 2\n do k = 1, 1\n a(i, j, k) = i*i\n b(i, j, k) = j*j\n end do\n end do\nend do\n\ni = 0\n\nprint *, a(1, 1, 1), a(1, 2, 1), a(2, 1, 1), a(2, 2, 1)\n\nprint *, b(1, 1, 1), b(1, 2, 1), b(2, 1, 1), b(2, 2, 1)\n\nc = a + b\nprint *, c(1, 1, 1), c(1, 2, 1), c(2, 1, 1), c(2, 2, 1)\n\nc = a - b\nprint *, c(1, 1, 1), c(1, 2, 1), c(2, 1, 1), c(2, 2, 1)\n\nc = a*b\nprint *, c(1, 1, 1), c(1, 2, 1), c(2, 1, 1), c(2, 2, 1)\n\nc = b/a\nprint *, c(1, 1, 1), c(1, 2, 1), c(2, 1, 1), c(2, 2, 1)\n\nend program", "meta": {"hexsha": "60108afb83fb00df5bde5c5f9134dfef35c8dffe", "size": 637, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/arrays_op_2.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/arrays_op_2.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/arrays_op_2.f90", "max_forks_repo_name": "Thirumalai-Shaktivel/lfortran", "max_forks_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-03-28T19:40:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:28:55.000Z", "avg_line_length": 18.7352941176, "max_line_length": 55, "alphanum_fraction": 0.3940345369, "num_tokens": 395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476384, "lm_q2_score": 0.8267117855317473, "lm_q1q2_score": 0.7532830109861077}} {"text": "PROGRAM funxy\r\n!\r\n! Purpose:\r\n! This program solves the function f(x,y) for a user-specified x and y,\r\n! where f(x,y) is defined as:\r\n! _\r\n! |\r\n! | X + Y X >= 0 and Y >= 0\r\n! | X + Y**2 X >= 0 and Y < 0\r\n! F(X,Y) = | X**2 + Y X < 0 and Y >= 0\r\n! | X**2 + Y**2 X < 0 and Y < 0\r\n! |_\r\n!\r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 11/06/06 S. J. Chapman Original code\r\n!\r\nIMPLICIT NONE\r\n\r\n! Data dictionary: declare variable types, definitions, & units \r\nREAL :: x ! First independent variable\r\nREAL :: y ! Second independent variable\r\nREAL :: fun ! Resulting function\r\n \r\n! Prompt the user for the values x and y\r\nWRITE (*,*) 'Enter the coefficients x and y: '\r\nREAD (*,*) x, y\r\n \r\n! Write the coefficients of x and y.\r\nWRITE (*,*) 'The coefficients x and y are: ', x, y\r\n \r\n! Calculate the function f(x,y) based upon the signs of x and y.\r\nIF ( ( x >= 0. ) .AND. ( y >= 0. ) ) THEN\r\n fun = x + y\r\nELSE IF ( ( x >= 0. ) .AND. ( y < 0. ) ) THEN \r\n fun = x + y**2\r\nELSE IF ( ( x < 0. ) .AND. ( y >= 0. ) ) THEN \r\n fun = x**2 + y\r\nELSE\r\n fun = x**2 + y**2\r\nEND IF\r\n \r\n! Write the value of the function.\r\nWRITE (*,*) 'The value of the function is: ', fun\r\n \r\nEND PROGRAM funxy\r\n", "meta": {"hexsha": "424ddd111de9314917d5aa175824de7da86ae9db", "size": 1498, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap3/funxy.f90", "max_stars_repo_name": "yangyang14641/FortranLearning", "max_stars_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-03-12T02:18:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-05T07:58:56.000Z", "max_issues_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap3/funxy.f90", "max_issues_repo_name": "yangyang14641/FortranLearning", "max_issues_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap3/funxy.f90", "max_forks_repo_name": "yangyang14641/FortranLearning", "max_forks_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-05-11T02:36:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T06:36:55.000Z", "avg_line_length": 31.2083333333, "max_line_length": 75, "alphanum_fraction": 0.4539385848, "num_tokens": 445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789547, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7532828283066105}} {"text": "PROGRAM matmulCheck\n IMPLICIT NONE\n\n REAL, ALLOCATABLE :: A(:, :), B(:, :)\n REAL:: D(10, 10) = 0 \n INTEGER:: L, M, N, O, i, j\n \n WRITE(*, *) \"Please Enter L M\" \n READ(*, *) L, M\n ALLOCATE(A(L, M))\n \n WRITE(*, *) \"Enter Matrix A()\"\n DO i = 1, L\n READ(*, *) (A(i,j), j=1,M) ! A() is L-by-M\n ENDDO\n\n WRITE(*, *) \"Please Enter N O\" \n READ(*, *) N, O \n ALLOCATE(B(N, O))\n \n WRITE(*, *) \"Enter Matrix B()\"\n DO i = 1, N \n READ(*, *) (B(i,j), j=1, O) ! B() is N-by-O\n ENDDO\n\n ! Matmul will be check for column(A) = row(B) or not => If not than give runtime error\n D = matmul(a, b)\n WRITE(*, *) \"Matrix D calculated from matmul library is \"\n DO i = 1, L\n Write(*, *) (D(i,j), j=1, O)\n ENDDO\n \nEND", "meta": {"hexsha": "150fe482b18b7c75311210841b57b57b65c419c5", "size": 785, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Practice-1/Mamul-Dimention_Check_Test.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Practice-1/Mamul-Dimention_Check_Test.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practice-1/Mamul-Dimention_Check_Test.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 23.7878787879, "max_line_length": 90, "alphanum_fraction": 0.4624203822, "num_tokens": 293, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897558991953, "lm_q2_score": 0.8006919925839876, "lm_q1q2_score": 0.75328282425353}} {"text": "!! ------------------------------------------------------------------------- !!\nmodule m_matrix\n\n implicit none\n private\n\n integer, parameter :: DP = selected_real_kind(13)\n integer, parameter :: STDERR = 0\n\n public matrix__gs\n\ncontains\n\n !! ----------------------------------------------------------------------- !!\n !>\n !! Solve the well-conditioned linear system\n !! Sum( m(i,j)*a(j) ) == v(i) for a(:)\n !! by Gauss-Seidel method.\n !<\n !! --\n subroutine matrix__gs( n, m, v, a )\n\n integer, intent(in) :: n !< model size\n real(DP), intent(in) :: m(n,n) !< coefficient matrix\n real(DP), intent(in) :: v(n) !< values\n real(DP), intent(out) :: a(n) !< answers\n real(DP), parameter :: TOL = 1e-6\n real(DP) :: a0(n)\n integer :: iter\n integer :: i, j\n real(DP) :: m_max, wk\n !! --\n\n a(:) = 0\n a0(:) = 0\n iter = 0\n m_max = maxval(abs(m))\n\n do\n do i=1, n\n wk = 0\n do j=1, i-1\n wk = wk + m(i,j) * a(j)\n end do\n do j=i+1, n\n wk = wk + m(i,j) * a(j)\n end do\n a(i) = (v(i) - wk) / m(i,i)\n end do\n if( maxval(abs(a0 - a))/m_max < TOL ) exit\n a0(:) = a(:)\n iter = iter + 1\n if(iter > 10000) then\n write(STDERR,*) \"does not converge\"\n exit\n end if\n end do\n\n end subroutine matrix__gs\n !! ----------------------------------------------------------------------- !!\n\nend module m_matrix\n!! ------------------------------------------------------------------------- !!\n", "meta": {"hexsha": "3c48f157d34a82c5f527e9d26771ac859e43a724", "size": 1543, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/m_matrix.f90", "max_stars_repo_name": "Team-RADDISH/tdac", "max_stars_repo_head_hexsha": "14f98abbb83a00df203d069e84b78eb3ca4a758e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-10T02:27:42.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-22T13:14:56.000Z", "max_issues_repo_path": "src/m_matrix.f90", "max_issues_repo_name": "Team-RADDISH/tdac", "max_issues_repo_head_hexsha": "14f98abbb83a00df203d069e84b78eb3ca4a758e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/m_matrix.f90", "max_forks_repo_name": "Team-RADDISH/tdac", "max_forks_repo_head_hexsha": "14f98abbb83a00df203d069e84b78eb3ca4a758e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-07-17T00:12:36.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-08T14:09:28.000Z", "avg_line_length": 24.109375, "max_line_length": 79, "alphanum_fraction": 0.388852884, "num_tokens": 451, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7532567255929202}} {"text": " subroutine fd_insolation(lyear,idayjl,isecdy,xlat, rsol)\r\n implicit none\r\n\r\nc Now, during the time period of 1978 through 1998, \r\nc the mean value of daily averages for the solar constant from six different satellites \r\nc yielded a solar constant of 1366.1 Wm2. This same source offers a minimum - maximum range of \r\nc the readings for 1363 - 1368 Wm2. Adjustments yielded \"a solar constant\" calculated to 1366.22 Wm2. \r\nc [Royal Meteorological Institute of Belgium: Department of Aerology; \r\nc http://remotesensing.oma.be/RadiometryPapers/article2.html.]. \r\nc\tc.gentemann gentemann@remss.com\r\nc\t6/2009\r\n\r\n\treal(4), parameter :: solar_constant=1366.2 !watts/m**2\r\n real(4), parameter :: pi=3.141592654\r\n\r\nc inputs and outputs\r\n\tinteger(4) lyear,idayjl,isecdy ! year, julian day, seconds in day\r\n\treal(4) xlat ! latitude of observation\r\n\treal(4) rsol ! average insolation watts/m**2 \r\n\treal(4) sunlat,sunlon,sundis,rr,H,sinh,Q\r\n\r\n\tcall sunloc1(lyear,idayjl,isecdy, sunlat,sunlon,sundis)\t !sundis is radius/(mean radius)\r\n \r\n rr=-tand(xlat)*tand(sunlat);\r\n if(rr> 1) rr= 1.\r\n if(rr<-1) rr=-1.\r\n\r\n H = acos(rr);\t \r\n sinH=sqrt(1 - rr**2) !sqrt(1-cos(h)**2) =sin(h)\r\n\tQ=sind(xlat)*sind(sunlat)*H + cosd(xlat)*cosd(sunlat)*sinH\r\n rsol = (solar_constant/pi)*Q/sundis**2\r\n\r\n return\r\n end\r\n", "meta": {"hexsha": "6a26b48e6cf920fb482176a3f6150220a1da5131", "size": 1392, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "subroutines/fd_insolation.f", "max_stars_repo_name": "cgentemann/posh_diurnal_model_fortran", "max_stars_repo_head_hexsha": "227fbea81016da29c3925a65fc2b3dcb5958e822", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-05T12:34:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-05T12:34:07.000Z", "max_issues_repo_path": "subroutines/fd_insolation.f", "max_issues_repo_name": "cgentemann/posh_diurnal_model_fortran", "max_issues_repo_head_hexsha": "227fbea81016da29c3925a65fc2b3dcb5958e822", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "subroutines/fd_insolation.f", "max_forks_repo_name": "cgentemann/posh_diurnal_model_fortran", "max_forks_repo_head_hexsha": "227fbea81016da29c3925a65fc2b3dcb5958e822", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.7714285714, "max_line_length": 103, "alphanum_fraction": 0.6566091954, "num_tokens": 443, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542817548989, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7532320830379494}} {"text": "module maths\nuse variables\nimplicit none\ncontains\n! *********************************************************\n! *********************************************************\n! MATHEMATICAL ROUTINES\n! *********************************************************\n! *********************************************************\n\n!-----------------------------------------------------------------\n! Returns the value of the exponential integral En(x)\n!-----------------------------------------------------------------\n FUNCTION expint(n,x)\n INTEGER n,MAXIT\n REAL(kind=8) expint,x,EPS,FPMIN,EULER\n PARAMETER (MAXIT=100,EPS=1.e-7,FPMIN=1.e-30,EULER=.5772156649)\n INTEGER i,ii,nm1\n REAL(kind=8) a,b,c,d,del,fact,h,psi\n nm1=n-1\n if(n.lt.0.or.x.lt.0..or.(x.eq.0..and.(n.eq.0.or.n.eq.1)))then\n print *,'bad arguments in expint'\n\t\t stop\n else if(n.eq.0)then\n expint=exp(-x)/x\n else if(x.eq.0.)then\n expint=1./nm1\n else if(x.gt.1.)then\n b=x+n\n c=1./FPMIN\n d=1./b\n h=d\n do 11 i=1,MAXIT\n a=-i*(nm1+i)\n b=b+2.\n d=1./(a*d+b)\n c=b+a/c\n del=c*d\n h=h*del\n if(abs(del-1.).lt.EPS)then\n expint=h*exp(-x)\n return\n endif\n11 continue\n print *,'continued fraction failed in expint'\n\t\t stop\n else\n if(nm1.ne.0)then\n expint=1./nm1\n else\n expint=-log(x)-EULER\n endif\n fact=1.\n do 13 i=1,MAXIT\n fact=-fact*x/i\n if(i.ne.nm1)then\n del=-fact/(i-nm1)\n else\n psi=-EULER\n do 12 ii=1,nm1\n psi=psi+1./ii\n12 continue\n del=fact*(-log(x)+psi)\n endif\n expint=expint+del\n if(abs(del).lt.abs(expint)*EPS) return\n13 continue\n print *, 'series failed in expint'\n\t\t stop\n endif\n return\n END function expint\n\t\t\n!-----------------------------------------------------------------\n! Returns the weights (w) and the abscissas (x) for a Gaussian integration using the \n! Gauss-Legendre formula, using n points\n!-----------------------------------------------------------------\n\tsubroutine gauleg(x1,x2,x,w,n)\n\tinteger, INTENT(IN) :: n\n\treal(kind=8), INTENT(IN) :: x1,x2\n\treal(kind=8), INTENT(INOUT) :: x(n),w(n)\n\treal(kind=8), parameter :: eps = 3.d-14\n\tinteger :: i,j,m\n\treal(kind=8) :: p1,p2,p3,pp,xl,xm,z,z1\n \n\tm=(n+1)/2\n xm=0.5d0*(x2+x1)\n xl=0.5d0*(x2-x1)\n do i=1,m\n \tz=dcos(3.141592654d0*(i-.25d0)/(n+.5d0))\n1 \tcontinue\n \tp1=1.d0\n \tp2=0.d0\n \tdo j=1,n\n \t\tp3=p2\n \tp2=p1\n \tp1=((2.d0*j-1.d0)*z*p2-(j-1.d0)*p3)/j\n\t\tenddo\n \tpp=n*(z*p1-p2)/(z*z-1.d0)\n \tz1=z\n \tz=z1-p1/pp\n \t\tif(abs(z-z1).gt.EPS)goto 1\n \tx(i)=xm-xl*z\n \tx(n+1-i)=xm+xl*z\n \tw(i)=2.d0*xl/((1.d0-z*z)*pp*pp)\n \tw(n+1-i)=w(i)\n\tenddo\n\t\n\tend subroutine gauleg\n\n! ---------------------------------------------------------\n! Returns the mean of the vector x\n! ---------------------------------------------------------\n\tfunction mean(x)\n\treal(kind=8) :: mean\n\treal(kind=8), INTENT(IN) :: x(:)\n\t\tmean = sum(x) / dble(size(x))\n\tend function mean\n\t\n! ---------------------------------------------------------\n! Derivative of a function using a 3-point Lagrange interpolation formulae\n! ---------------------------------------------------------\n\tfunction deriv(x0, x1, x2, f0, f1, f2, which)\n\treal(kind=8) :: deriv\n\treal(kind=8), INTENT(IN) :: x0, x1, x2, f0, f1, f2\n\tinteger, INTENT(IN) :: which\n\treal(kind=8) :: h1, h2, c0, c1, c2, x\n\t\n\t\tx = 0.d0\n\t\tif (which == 0) x = x0\n\t\tif (which == 1) x = x1\n\t\tif (which == 2) x = x2\n\t\th1 = x1 - x0\n\t\th2 = x2 - x1\n\t\tc0 = 1.d0 / (h1*(h1+h2))\n\t\tc1 = 1.d0 / (h1*h2)\n\t\tc2 = 1.d0 / (h2*(h1+h2))\n\t\t\n\t\tderiv = f0 * c0 * ( (x-x2) + (x-x1) ) - f1 * c1 * ( (x-x0) + (x-x2) ) + &\n\t\t\tf2 * c2 * ( (x-x0) + (x-x1) ) \n\t\t\t\n\tend function deriv\n\n! ---------------------------------------------------------\n! Derivative of a function using a 3-point Lagrange interpolation formulae\n! It seems to be wrong\n! ---------------------------------------------------------\n\tfunction lag_deriv(x0, x1, x2, f0, f1, f2, which)\n\treal(kind=8) :: lag_deriv\n\treal(kind=8), INTENT(IN) :: x0, x1, x2, f0, f1, f2\n\tinteger, INTENT(IN) :: which\n\treal(kind=8) :: h1, h2, c0, c1, c2\n\t\th1 = x1 - x0\n\t\th2 = x2 - x1\n\t\tc0 = 1.d0 / (h1*(h1+h2))\n\t\tc1 = 1.d0 / (h1*h2)\n\t\tc2 = 1.d0 / (h2*(h1+h2))\n\n\t\tlag_deriv = 0.d0\n\t\t\n\t\tif (which == 0) then\n\t\t\tlag_deriv = -c0 * f0 * (2d0 * h1 + h2) - c1 * f1 * (h1 + h2) - c2 * f2 * h1\n\t\tendif\n\t\t\n\t\tif (which == 1) then\n\t\t\tlag_deriv = -c0 * f0 * h2 + c1 * f1 * (h1 - h2) + c2 * f2 * h1\n\t\tendif\n\t\t\n\t\tif (which == 2) then\t\t\t\n\t\t\tlag_deriv = c0 * f0 * h2 + c1 * f1 * (h1 + h2) + c2 * f2 * (2.d0 * h2 + h1)\n\t\tendif\n\t\t\n\tend function lag_deriv\n! ---------------------------------------------------------\n! LU decomposition of a matrix\n! INPUT:\n!\t\t- a is the matrix to decompose\n!\t\t\n! OUTPUT:\n!\t\t- a is the LU decomposition of a\n!\t\t- indx is a vector that records the row permutation effected by the partial pivoting\n!\t\t- d takes values +1/-1 depending on whether the number of row interchanges was odd or even\n! ---------------------------------------------------------\n\tsubroutine ludcmp(a,indx,d)\n\tinteger, INTENT(INOUT) :: indx(:)\n\treal(kind=8), INTENT(INOUT) :: a(:,:), d\n\treal(kind=8), parameter :: TINY = 1.d-20\n\tinteger :: i, imax, j, k, n\n\treal(kind=8) :: aamax, dum, sum, vv(size(a,1))\n\t\td = 1.d0\n\t\tn = size(a,1)\n\n\t\timax = 0\n\t\t\n\t\tdo i = 1, n\n\t\t\taamax = 0.d0\t\n\t\t\taamax = maxval(dabs(a(i,:)))\n\t\t\tif (aamax == 0.d0) print *, 'Singular matrix in LU decomposition'\n\t\t\tvv(i) = 1.d0 / aamax\n\t\tenddo\n\t\t\n\t\tdo j = 1, n\n\t\t\tdo i = 1, j-1\n\t\t\t\tsum = a(i,j)\n\t\t\t\tdo k = 1, i-1\n\t\t\t\t\tsum = sum - a(i,k) * a(k,j)\n\t\t\t\tenddo\n\t\t\t\ta(i,j) = sum\n\t\t\tenddo\n\t\t\taamax = 0.d0\n\t\t\tdo i = j, n\n\t\t\t\tsum = a(i,j)\n\t\t\t\tdo k = 1, j-1\n\t\t\t\t\tsum = sum - a(i,k) * a(k,j)\n\t\t\t\tenddo\n\t\t\t\ta(i,j) = sum\n\t\t\t\tdum = vv(i) * dabs(sum)\n\t\t\t\tif (dum >= aamax) then\n\t\t\t\t\timax = i\n\t\t\t\t\taamax = dum\n\t\t\t\tendif\t\t\t\t\n\t\t\tenddo\n\t\t\tif (j /= imax) then\n\t\t\t\tdo k = 1, n\n\t\t\t\t\tdum = a(imax,k)\n\t\t\t\t\ta(imax,k) = a(j,k)\n\t\t\t\t\ta(j,k) = dum\n\t\t\t\tenddo\n\t\t\t\td = -d\n\t\t\t\tvv(imax) = vv(j)\n\t\t\tendif\n\t\t\tindx(j) = imax\n\t\t\tif (a(j,j) == 0.d0) a(j,j) = TINY\n\t\t\tif (j /= n) then\n\t\t\t\tdum = 1.d0 / a(j,j)\n\t\t\t\tdo i = j+1, n\n\t\t\t\t\ta(i,j) = a(i,j) * dum\n\t\t\t\tenddo\n\t\t\tendif\n\t\tenddo\n\t\n\tend subroutine ludcmp\n\n! ---------------------------------------------------------\n! Solves the set of equations AX=b where A is the LU decomposition of a matrix\n! INPUT:\n!\t\t- a is the LU decomposition of the system matrix\n!\t\t- b is the right hand side vector of the system\n! \t\t- indx is the vector returned by ludcmp\n! OUTPUT:\n!\t\t- b is the solution of the system\n! ---------------------------------------------------------\n\tsubroutine lubksb(a,indx,b)\n\treal(kind=8), INTENT(IN) :: a(:,:)\n\treal(kind=8), INTENT(INOUT) :: b(:)\n\tinteger, INTENT(IN) :: indx(:)\n\tinteger :: i, ii, n, j, ll\n\treal(kind=8) :: sum\n\t\tn = size(a,1)\n\t\tii = 0\n\t\tdo i = 1, n\n\t\t\tll = indx(i)\n\t\t\tsum = b(ll)\n\t\t\tb(ll) = b(i)\n\t\t\tif (ii /= 0) then\n\t\t\t\tdo j = ii, i-1\n\t\t\t\t\tsum = sum - a(i,j) * b(j)\n\t\t\t\tenddo\n\t\t\telse if (sum /= 0.d0) then\n\t\t\t\tii = i\n\t\t\tendif\n\t\t\tb(i) = sum\n\t\tenddo\n\t\tdo i = n, 1, -1\n\t\t\tsum = b(i)\n\t\t\tdo j = i+1, n\n\t\t\t\tsum = sum - a(i,j) * b(j)\n\t\t\tenddo\n\t\t\tb(i) = sum / a(i,i)\n\t\tenddo\n\tend subroutine lubksb\n\n! ---------------------------------------------------------\n! This subroutine solves a linear system of equations using a BiCGStab iterative method\n! ---------------------------------------------------------\t\t \n\tsubroutine bicgstab(a,b)\n\treal(kind=8), INTENT(INOUT) :: a(:,:), b(:)\n\treal(kind=8) :: x(size(b)), r(size(b)), rhat(size(b)), p(size(b)), phat(size(b)), v(size(b))\n\treal(kind=8) :: s(size(b)), shat(size(b)), t(size(b)), delta(size(b))\n\treal(kind=8) :: rho, rho_ant, alpha, beta, omega, relative\n\tinteger :: i\n\t\t\n\t\talpha = 0.d0\n\t\tomega = 0.d0\n! Initial solution\n\t\tx = 1.d0\n\t\n\t\tr = b - matmul(A,x)\n\t\trhat = r\n\t\trho = 1.d0\n\t\trelative = 1.d10\n\t\ti = 1\n\t\tdo while (relative > 1.d-10)\n\t\t\trho_ant = rho\n\t\t\trho = sum(rhat*r)\n\t\t\tif (rho == 0) then \n\t\t\t\tstop\n\t\t\tendif\n\t\t\tif (i == 1) then\n\t\t\t\tp = r\n\t\t\telse\n\t\t\t\tbeta = (rho/rho_ant) * (alpha/omega)\n\t\t\t\tp = r + beta * (p - omega * v)\n\t\t\tendif\n\t\t\tphat = p\n\t\t\tv = matmul(A,phat)\n\t\t\talpha = rho / sum(rhat*v)\n\t\t\ts = r - alpha * v\n\n\t\t\tshat = s\n\t\t\tt = matmul(A,shat)\n\t\t\tomega = sum(t*s)/sum(t*t)\n\t\t\tdelta = alpha * p + omega * s\n\t\t\trelative = maxval(abs(delta) / x)\n\t\t\tx = x + delta\t\t\n\t\t\tr = s - omega * t\n\t\t\ti = i + 1\n\t\tenddo\t\n\t\t\n\t\tb = x\n\t\t \n\tend subroutine bicgstab\t\n\t\n! ---------------------------------------------------------\n! This subroutine solves a linear system of equations using the SLAP routines\n! It uses an Incomplete LU BiConjugate Gradient Sparse Ax=b solver\n! ---------------------------------------------------------\t\t \n\tsubroutine slapsolver(a,b,initial)\n\treal(kind=8), INTENT(INOUT) :: a(:,:), b(:), initial(:)\n\tinteger :: i, j, k\n\treal(kind=8), allocatable :: a_sparse(:), x(:), rwork(:)\n\tinteger, allocatable :: ia(:), ja(:), iwork(:)\n\tinteger :: n, nelt, isym, itol, itmax, iter, ierr, iunit, lenw, leniw, nsave\n\treal(kind=8) :: tol\n\tinteger, allocatable :: indx(:)\n\n\t\titer = 0\n\t\tierr = 1\n\t\tn = size(b)\n\t\tallocate(x(n))\n\t\tk = 0\n\t\tdo i = 1, n\n\t\t\tdo j = 1, n\n\t\t\t\tif (a(j,i) /= 0.d0) k = k + 1\n\t\t\tenddo\n\t\tenddo\n\t\tnelt = k\n\t\tallocate(a_sparse(nelt))\n\t\tallocate(ia(nelt))\n\t\tallocate(ja(nelt))\t\t\n\t\t\n\t\tk = 1\n\t\tdo i = 1, n\n\t\t\tdo j = 1, n\n\t\t\t\tif (a(j,i) /= 0.d0) then\n\t\t\t\t\ta_sparse(k) = a(j,i)\n\t\t\t\t\tia(k) = j\n\t\t\t\t\tja(k) = i\n\t\t\t\t\tk = k + 1\n\t\t\t\tendif\n\t\t\tenddo\n\t\tenddo\n\t\t\n! First try with BiCGStab\n\t\tx = initial\n\t\tisym = 0\n\t\titol = 2\n\t\ttol = 1.d-10\n\t\titmax = 10000\n\t\tiunit = 0\n\t\tlenw = n*n\n\t\tleniw = n*n\n\t\tnsave = 10\n\t\tallocate(iwork(leniw))\n\t\tallocate(rwork(lenw))\n\t\t\n!\t\tprint *, 'Solving the system...'\n! \t\tcall ds2y( n, nelt, ia, ja, a_sparse, isym )\n! \t\tcall dslucs(n, b, x, nelt, ia, ja, a_sparse, isym, itol, tol, &\n! \t\t\titmax, iter, err, ierr, iunit, rwork, lenw, iwork, leniw )\n!\t\tprint *, 'Number of iterations : ', iter, 'of ', itmax\n!\t\tprint *, 'Error : ', err, ierr\n\t\tif (iter >= itmax+1 .or. ierr /= 0) then\n\t\t\tprint *, 'Couldn''t reach convergence. Trying other initialization...'\n!\t\t\twrite(17,*) 'Couldn''t reach convergence. Trying other initialization...'\n\t\t\tx = 1.d0\n\t\t\tisym = 0\n\t\t\titol = 2\n\t\t\ttol = 1.d-10\n\t\t\titmax = 10000\n\t\t\tiunit = 0\n\t\t\tlenw = n*n\n\t\t\tleniw = n*n\n\t\t\tnsave = 10\n! \t\t\tcall dslucs(n, b, x, nelt, ia, ja, a_sparse, isym, itol, tol, &\n! \t\t\titmax, iter, err, ierr, iunit, rwork, lenw, iwork, leniw )\n!\t\t\tprint *, 'Number of iterations : ', iter, 'of ', itmax\n!\t\t\tprint *, 'Error : ', err, ierr\n\t\tendif\n\t\t\n! Let's try GMRES\t\t\n\t\tif (iter >= itmax+1 .or. ierr /= 0) then\n\t\t\tprint *, 'Couldn''t reach convergence. Trying GMRES...'\n!\t\t\twrite(17,*) 'Couldn''t reach convergence. Trying GMRES...'\n\t\t\tx = 0.d0\n\t\t\tisym = 0\n\t\t\titol = 2\n\t\t\ttol = 1.d-10\n\t\t\titmax = 10000\n\t\t\tiunit = 0\n\t\t\tlenw = n*n\n\t\t\tleniw = n*n\n\t\t\tnsave = 10\n! \t\t\tcall dsdgmr(n, b, x, nelt, ia, ja, a_sparse, isym, nsave, itol, tol, &\n! \t\t\titmax, iter, err, ierr, iunit, rwork, lenw, iwork, leniw )\n!\t\t\tprint *, 'Number of iterations : ', iter, 'of ', itmax\n!\t\t\tprint *, 'Error : ', err, ierr\n\t\tendif\n\t\t\n\t\tif (iter >= itmax+1 .or. ierr /= 0) then\n\t\t\tprint *, 'Couldn''t reach convergence. Trying other initialization...'\n!\t\t\twrite(17,*) 'Couldn''t reach convergence. Trying other initialization...'\n\t\t\tx = 1.d0\n\t\t\tisym = 0\n\t\t\titol = 0\n\t\t\ttol = 1.d-10\n\t\t\titmax = 10000\n\t\t\tiunit = 0\n\t\t\tlenw = n*n\n\t\t\tleniw = n*n\n\t\t\tnsave = 10\n! \t\t\tcall dsdgmr(n, b, x, nelt, ia, ja, a_sparse, isym, nsave, itol, tol, &\n! \t\t\titmax, iter, err, ierr, iunit, rwork, lenw, iwork, leniw )\n!\t\t\tprint *, 'Number of iterations : ', iter, 'of ', itmax\n!\t\t\tprint *, 'Error : ', err, ierr\n\t\tendif\n\t\t\n\t\tb = x\n\t\t\n\t\tdeallocate(x)\n\t\tdeallocate(a_sparse)\n\t\tdeallocate(ia)\n\t\tdeallocate(ja)\n\t\tdeallocate(iwork)\n\t\tdeallocate(rwork)\n\t\t\n\t\tif (iter >= itmax+1 .or. ierr /= 0) then\n\t\t\tprint *, 'Couldn''t reach convergence. Trying LU decomposition...'\n\t\t\twrite(17,*) 'Couldn''t reach convergence. Trying LU decomposition...'\n\t\t\tallocate(indx(n))\n\t\t\tcall ludcmp(a,indx,tol)\n\t\t\tcall lubksb(a,indx,b)\n\t\t\tdeallocate(indx)\n\t\tendif\n\t\t\n\tend subroutine slapsolver\t\t\n\t\n\t\n! ---------------------------------------------------------\n! Interface to the LU solver\n! INPUT:\n!\t\t- a is the system matrix (if alu=0) or the LU decomposition (if alu /= 0)\n!\t\t- b is the right hand side of the system\n!\t\t- indx is the vector of permutations\n!\t\t- alu is a flag to indicate if LU decomposition has to be done or not\n! ---------------------------------------------------------\t\n\tsubroutine linsolve(a, b, indx, alu)\n\treal(kind=8), INTENT(INOUT) :: a(:,:), b(:)\n\tinteger, INTENT(INOUT) :: indx(:)\n\treal(kind=8) :: d, v(size(b),size(b)), w(size(b)), solution(size(b))\n\tinteger :: alu, n\n\t\tn = size(b)\n\t\t\n\t\tif (linear_solver_algorithm == 0) then\n\t\t\tif (alu == 0) then\n\t\t\t\tcall ludcmp(a,indx,d)\n\t\t\t\tcall lubksb(a,indx,b)\n\t\t\telse \n\t\t\t\tcall lubksb(a,indx,b)\n\t\t\tendif\n\t\telse if (linear_solver_algorithm == 1) then\n\t\t\tcall svdcmp(a,n,n,n,n,w,v)\n\t\t\tcall svbksb(a,w,v,n,n,n,n,b,solution)\n\t\t\tb = solution\n\t\telse if (linear_solver_algorithm == 2) then\n\t\t\tprint *, 'Not implemented yet'\n! \t\t\tcall slapsolver(a,b,initial)\n\t\telse\n! \t\t\tcall bicgstab(a,b)\n\t\tendif\n\t\t\n\tend subroutine linsolve\n\n! ---------------------------------------------------------\n! Returns the SVD decomposition of a matrix\n! ---------------------------------------------------------\t\t\n subroutine svdcmp(a,m,n,mp,np,w,v)\n integer :: m,mp,n,np\n integer, parameter :: nmax=500\n real(kind=8) :: a(mp,np),v(np,np),w(np)\n integer :: i,its,j,jj,k,l,nm\n real(kind=8) :: anorm,c,f,g,h,s,scale,x,y,z,rv1(NMAX)\n \tnm = 0\n \tg=0.d0\n \tscale=0.d0\n \tanorm=0.d0\n \tdo 25 i=1,n\n \t l=i+1\n \t rv1(i)=scale*g\n \t g=0.d0\n \t s=0.d0\n \t scale=0.d0\n \t if(i.le.m)then\n \t do 11 k=i,m\n\t \tscale=scale+abs(a(k,i))\n11 continue\n\t \t if(scale.ne.0.d0)then\n\t \tdo 12 k=i,m\n\t \t a(k,i)=a(k,i)/scale\n\t \t s=s+a(k,i)*a(k,i)\n12 continue\n\t \tf=a(i,i)\n\t \tg=-sign(sqrt(s),f)\n\t \th=f*g-s\n\t \ta(i,i)=f-g\n\t \tdo 15 j=l,n\n\t \t s=0.d0\n\t \t do 13 k=i,m\n\t \t s=s+a(k,i)*a(k,j)\n13 continue\n\t \t f=s/h\n\t \t do 14 k=i,m\n\t \t a(k,j)=a(k,j)+f*a(k,i)\n14 continue\n15 continue\n\t \tdo 16 k=i,m\n\t \t a(k,i)=scale*a(k,i)\n16 continue\n\t \t endif\n\t endif\n\t w(i)=scale *g\n\t g=0.d0\n\t s=0.d0\n\t scale=0.d0\n\t if((i.le.m).and.(i.ne.n))then\n\t \t do 17 k=l,n\n\t \tscale=scale+abs(a(i,k))\n17 continue\n\t \t if(scale.ne.0.d0)then\n\t \tdo 18 k=l,n\n\t \t a(i,k)=a(i,k)/scale\n\t \t s=s+a(i,k)*a(i,k)\n18 continue\n\t \tf=a(i,l)\n\t \tg=-sign(sqrt(s),f)\n\t \th=f*g-s\n\t \ta(i,l)=f-g\n\t \tdo 19 k=l,n\n\t \t rv1(k)=a(i,k)/h\n19 continue\n\t \tdo 23 j=l,m\n\t \t s=0.d0\n\t \t do 21 k=l,n\n\t \t s=s+a(j,k)*a(i,k)\n21 continue\n\t \t do 22 k=l,n\n\t \t a(j,k)=a(j,k)+s*rv1(k)\n22 continue\n23 continue\n\t \tdo 24 k=l,n\n\t \t a(i,k)=scale*a(i,k)\n24 continue\n\t \t endif\n\t endif\n\t anorm=max(anorm,(abs(w(i))+abs(rv1(i))))\n25 continue\n\t do 32 i=n,1,-1\n\t if(i.lt.n)then\n\t \t if(g.ne.0.d0)then\n\t \tdo 26 j=l,n\n\t \t v(j,i)=(a(i,j)/a(i,l))/g\n26 continue\n\t \tdo 29 j=l,n\n\t \t s=0.d0\n\t \t do 27 k=l,n\n\t \t s=s+a(i,k)*v(k,j)\n27 continue\n\t \t do 28 k=l,n\n\t \t v(k,j)=v(k,j)+s*v(k,i)\n28 continue\n29 continue\n\t \t endif\n\t \t do 31 j=l,n\n\t \tv(i,j)=0.d0\n\t \tv(j,i)=0.d0\n31 continue\n\t endif\n\t v(i,i)=1.d0\n\t g=rv1(i)\n\t l=i\n32 continue\n\t do 39 i=min(m,n),1,-1\n\t l=i+1\n\t g=w(i)\n\t do 33 j=l,n\n\t \t a(i,j)=0.d0\n33 continue\n\t if(g.ne.0.d0)then\n\t \t g=1.d0/g\n\t \t do 36 j=l,n\n\t \ts=0.d0\n\t \tdo 34 k=l,m\n\t \t s=s+a(k,i)*a(k,j)\n34 continue\n\t \tf=(s/a(i,i))*g\n\t \tdo 35 k=i,m\n\t \t a(k,j)=a(k,j)+f*a(k,i)\n35 continue\n36 continue\n\t \t do 37 j=i,m\n\t \ta(j,i)=a(j,i)*g\n37 continue\n\t else\n\t \t do 38 j= i,m\n\t \ta(j,i)=0.d0\n38 continue\n\t endif\n\t a(i,i)=a(i,i)+1.d0\n39 continue\n\t do 49 k=n,1,-1\n\t do 48 its=1,30\n\t \t do 41 l=k,1,-1\n\t \tnm=l-1\n\t \tif((abs(rv1(l))+anorm).eq.anorm) goto 2\n\t \tif((abs(w(nm))+anorm).eq.anorm) goto 1\n41 continue\n1 c=0.d0\n\t \t s=1.d0\n\t \t do 43 i=l,k\n\t \tf=s*rv1(i)\n\t \trv1(i)=c*rv1(i)\n\t \tif((abs(f)+anorm).eq.anorm) goto 2\n\t \tg=w(i)\n\t \th=pythag(f,g)\n\t \tw(i)=h\n\t \th=1.d0/h\n\t \tc= (g*h)\n\t \ts=-(f*h)\n\t \tdo 42 j=1,m\n\t \t y=a(j,nm)\n\t \t z=a(j,i)\n\t \t a(j,nm)=(y*c)+(z*s)\n\t \t a(j,i)=-(y*s)+(z*c)\n42 continue\n43 continue\n2 z=w(k)\n\t \t if(l.eq.k)then\n\t \tif(z.lt.0.d0)then\n\t \t w(k)=-z\n\t \t do 44 j=1,n\n\t \t v(j,k)=-v(j,k)\n44 continue\n\t \tendif\n\t \tgoto 3\n\t \t endif\n\t \t if(its.eq.30) then\n\t\t\t\tprint *, 'no convergence in svdcmp'\n\t\t\t\tstop\n\t\t\tendif\n\t \t x=w(l)\n\t \t nm=k-1\n\t \t y=w(nm)\n\t \t g=rv1(nm)\n\t \t h=rv1(k)\n\t \t f=((y-z)*(y+z)+(g-h)*(g+h))/(2.d0*h*y)\n\t \t g=pythag(f,1.d0)\n\t \t f=((x-z)*(x+z)+h*((y/(f+sign(g,f)))-h))/x\n\t \t c=1.d0\n\t \t s=1.d0\n\t \t do 47 j=l,nm\n\t \ti=j+1\n\t \tg=rv1(i)\n\t \ty=w(i)\n\t \th=s*g\n\t \tg=c*g\n\t \tz=pythag(f,h)\n\t \trv1(j)=z\n\t \tc=f/z\n\t \ts=h/z\n\t \tf= (x*c)+(g*s)\n\t \tg=-(x*s)+(g*c)\n\t \th=y*s\n\t \ty=y*c\n\t \tdo 45 jj=1,n\n\t \t x=v(jj,j)\n\t \t z=v(jj,i)\n\t \t v(jj,j)= (x*c)+(z*s)\n\t \t v(jj,i)=-(x*s)+(z*c)\n45 continue\n\t \tz=pythag(f,h)\n\t \tw(j)=z\n\t \tif(z.ne.0.d0)then\n\t \t z=1.d0/z\n\t \t c=f*z\n\t \t s=h*z\n\t \tendif\n\t \tf= (c*g)+(s*y)\n\t \tx=-(s*g)+(c*y)\n\t \tdo 46 jj=1,m\n\t \t y=a(jj,j)\n\t \t z=a(jj,i)\n\t \t a(jj,j)= (y*c)+(z*s)\n\t \t a(jj,i)=-(y*s)+(z*c)\n46 continue\n47 continue\n\t \t rv1(l)=0.d0\n\t \t rv1(k)=f\n\t \t w(k)=x\n48 continue\n3 continue\n49 continue\n\t return\n end subroutine svdcmp\n\n! ---------------------------------------------------------\n! Solves a linear system of equations using the SVD decomposition\n! ---------------------------------------------------------\t\n subroutine svbksb(u,w,v,m,n,mp,np,b,x)\n integer :: m,mp,n,np\n\tinteger, parameter :: NMAX=500\n real(kind=8) :: b(mp),u(mp,np),v(np,np),w(np),x(np)\n integer :: i,j,jj\n real(kind=8) :: s,tmp(NMAX)\n do 12 j=1,n\n s=0.d0\n if(w(j).ne.0.d0)then\n do 11 i=1,m\n s=s+u(i,j)*b(i)\n11 continue\n s=s/w(j)\n endif\n tmp(j)=s\n12 continue\n do 14 j=1,n\n s=0.d0\n do 13 jj=1,n\n s=s+v(j,jj)*tmp(jj)\n13 continue\n x(j)=s\n14 continue\n return\n end subroutine svbksb\n\t\t\n! ---------------------------------------------------------\n! Returns (a^2+b^2)^(1/2) without destructive underflow or overflow\n! ---------------------------------------------------------\t\n\tfunction pythag(a,b)\n real(kind=8) :: a,b,pythag\n real(kind=8) :: absa,absb\n absa=dabs(a)\n absb=dabs(b)\n if(absa.gt.absb)then\n pythag=absa*dsqrt(1.+(absb/absa)**2)\n else\n if(absb.eq.0.d0)then\n pythag=0.d0\n else\n pythag=absb*sqrt(1.d0+(absa/absb)**2)\n endif\n endif\n return\n\tend function pythag\n\t\n! ---------------------------------------------------------\n! Iterative improvement of a solution to a linear set of equations\n! ---------------------------------------------------------\n\tsubroutine mprove(a, alud, indx, b, x)\n\treal(kind=8), INTENT(IN) :: a(:,:), alud(:,:), b(:)\n\treal(kind=8), INTENT(INOUT) :: x(:)\n\tinteger, INTENT(IN) :: indx(:)\n\tinteger :: i, j, n\n\treal(kind=8) :: r(size(a,1)), sdp\n\t\tn = size(a,1)\n\t\tdo i = 1, n\n\t\t\tsdp = -b(i)\n\t\t\tdo j = 1, n\n\t\t\t\tsdp = sdp + a(i,j) * x(j)\n\t\t\tenddo\n\t\t\tr(i) = sdp\n\t\tenddo\n\t\tcall lubksb(alud,indx,r)\n\t\t\n\t\tx = x - r\n\n\tend subroutine mprove\n\n! ---------------------------------------------------------\n! Solves a symmetric linear system of equations\n! ---------------------------------------------------------\t\n\tsubroutine llslv(S,X,N,NR)\n\tinteger, INTENT(IN) :: n, nr\n\treal(kind=8), INTENT(INOUT) :: S(nr,nr), x(nr)\n\treal(kind=8) :: sum\n\tinteger :: i, j, k\n\t\n! Decompose symmetric matrix L*LT=S\n\tdo i = 1, n\n\t\tdo j = 1, i\n\t\t\tsum = s(i,j)\n\t\t\tdo k = 1, j-1\n\t\t\t\tsum = sum - S(i,k) * S(j,k)\n\t\t\tenddo !k\n\t\t\tif (j < i) then\n\t\t\t\ts(i,j) = sum / S(j,j)\n\t\t\telse\n\t\t\t\tS(i,j) = dsqrt(dabs(sum))\n\t\t\tendif\n\t\tenddo !j\n\tenddo !i\n\t\n\tentry llreslv(S,X,N,NR)\n! Solve the system\n\t\n\tdo i = 1, n\n\t\tsum = x(i)\n\t\tdo j = 1, i-1\n\t\t\tsum = sum - S(i,j)*x(j)\n\t\tenddo !j\n\t\tx(i) = sum / S(i,i)\n\tenddo !i\n\tdo i = n, 1, -1\n\t\tsum = x(i)\n\t\tdo j = n, i+1, -1\n\t\t\tsum = sum - S(j,i)*x(j)\n\t\tenddo !j\n\t\tx(i) = sum / S(i,i)\n\tenddo !i\n\t\n\tend subroutine llslv\n\t\n! ---------------------------------------------------------\n! Returns a Voigt profile for the line\n! ---------------------------------------------------------\n function voigt(a,vv,j)\n\t real(kind=8) :: voigt, a, vv\n\t integer :: j, k, i, kk, kkk\n\t real(kind=8) :: d1, d2, d3, d12, d13, d23, d, y\n real(kind=8) :: a0, a1, a2, a3, a4, a5, a6, b0, b1, b2, b3, b4, b5, b6\n\t real(kind=8) :: v\n complex :: z\n real(kind=8) :: xdws(28),ydws(28)\n\n data a0,a1,a2,a3,a4,a5,a6,b0,b1,b2,b3,b4,b5,b6/&\n 122.607931777104326d0,214.382388694706425d0,181.928533092181549d0,&\n 93.155580458138441d0,30.180142196210589d0,5.912626209773153d0,&\n .564189583562615d0,122.60793177387535d0,352.730625110963558d0,&\n 457.334478783897737d0,348.703917719495792d0,170.354001821091472d0,&\n 53.992906912940207d0,10.479857114260399d0/\n\n data xdws/.1d0,.2d0,.3d0,.4d0,.5d0,.6d0,.7d0,.8d0,.9d0,1.d0,1.2d0,1.4d0,1.6d0,1.8d0,2.d0,&\n 3.d0,4.d0,5.d0,6.d0,7.d0,8.d0,9.d0,10.d0,12.d0,14.d0,16.d0,18.d0,20.d0/,ydws/&\n 9.9335991d-02,1.9475104d-01,2.8263167d-01,3.5994348d-01,&\n 4.2443639d-01,4.7476321d-01,5.1050407d-01,5.3210169d-01,&\n 5.4072434d-01,5.3807950d-01,5.0727350d-01,4.5650724d-01,&\n 3.9993989d-01,3.4677279d-01,3.0134040d-01,1.7827103d-01,&\n 1.2934799d-01,1.0213407d-01,8.4542692d-02,7.2180972d-02,&\n 6.3000202d-02,5.5905048d-02,5.0253846d-02,4.1812878d-02,&\n 3.5806101d-02,3.1311397d-02,2.7820844d-02,2.5031367d-02/\n\n v=dabs(vv)\n IF(A.NE.0) GOTO 1 \n IF(J.NE.0) GOTO 3 \n VOIGT=DEXP(-V*V) \n RETURN\n 3 IF(V.GT.XDWS(1)) GOTO 4 \n D=V*(1.-.66666667d0*V*V)\n GOTO 8\n 4 IF(V.GT.XDWS(28)) GOTO 5 \n K=27 \n DO 7 I=2,27 \n IF(XDWS(I).LT.V) GOTO 7 \n K=I \n GOTO 6\n 7 CONTINUE \n 6 KK=K-1\n KKK=K+1 \n D1=V-XDWS(KK) \n D2=V-XDWS(K) \n D3=V-XDWS(KKK)\n D12=XDWS(KK)-XDWS(K) \n D13=XDWS(KK)-XDWS(KKK)\n D23=XDWS(K)-XDWS(KKK) \n D=YDWS(KK)*D2*D3/(D12*D13)-YDWS(K)*D1*D3/(D12*D23)+YDWS(KKK)*&\n D1*D2/(D13*D23)\n GOTO 8\n 5 Y=.5/V\n D=Y*(1.+Y/V) \n 8 VOIGT=5.641895836d-1*D\n 9 IF(VV.LT.0.) VOIGT=-VOIGT \n RETURN\n 1 Z=CMPLX(A,-V) \n Z=((((((A6*Z+A5)*Z+A4)*Z+A3)*Z+A2)*Z+A1)*Z+A0)/&\n (((((((Z+B6)*Z+B5)*Z+B4)*Z+B3)*Z+B2)*Z+B1)*Z+B0)\n IF(J.NE.0) GOTO 2 \n VOIGT=REAL(Z) \n RETURN\n 2 VOIGT=.5d0*AIMAG(Z) \n GOTO 9\n END function voigt\n\t\t\n! ---------------------------------------------------------\n! Given x(:) and y(:) which tabulate a function and the derivative at the boundary points\n! this function returns the second derivative of the spline at each point\n! ---------------------------------------------------------\n\t\tsubroutine splin1(x,y,yp1,ypn,y2)\n\t\treal(kind=8), INTENT(IN) :: x(:), y(:), yp1, ypn\n\t\treal(kind=8), INTENT(INOUT) :: y2(size(x))\n\t\tinteger :: n, i, k\n\t\treal(kind=8) :: p, qn, sig, un, u(size(x))\n\n\t\t\tn = size(x)\n\t\t\t\n\t\t\tif (yp1 > .99d30) then\n\t\t\t\ty2(1) = 0.d0\n\t\t\t\tu(1) = 0.d0\n\t\t\telse\n\t\t\t\ty2(1) = -0.5d0\n\t\t\t\tu(1) = (3.d0/(x(2)-x(1)))*((y(2)-y(1))/(x(2)-x(1))-yp1)\n\t\t\tendif\n\n\t\t\tdo i = 2, n-1\n\t\t\t\tsig = (x(i)-x(i-1))/(x(i+1)-x(i-1))\t\t\t\t\n\t\t\t\tp = sig * y2(i-1)+2.d0\n\t\t\t\ty2(i) = (sig-1.d0)/p\n\t\t\t\tu(i) = (6.d0*((y(i+1)-y(i))/(x(i+1)-x(i))-(y(i)-y(i-1))/(x(i)-x(i-1)))/&\n\t\t\t\t\t(x(i+1)-x(i-1))-sig*u(i-1))/p\n\t\t\tenddo\n\t\t\tif (ypn > .99d30) then\n\t\t\t\tqn = 0.d0\n\t\t\t\tun = 0.d0\n\t\t\telse\n\t\t\t\tqn = 0.5d0\n\t\t\t\tun = (3.d0/(x(n)-x(n-1)))*(ypn-(y(n)-y(n-1))/(x(n)-x(n-1)))\n\t\t\tendif\n\t\t\t\n\t\t\ty2(n) = (un-qn*u(n-1))/(qn*y2(n-1)+1.d0)\n\n\t\t\tdo k = n-1, 1, -1\n\t\t\t\ty2(k) = y2(k)*y2(k+1)+u(k)\n\t\t\tenddo\n\n\t\tend subroutine splin1\n\n! ---------------------------------------------------------\n! Given xa(:) and ya(:) which tabulate a function, returns the interpolation using\n! splines of vector x(:) in y(:)\n! ---------------------------------------------------------\n\t\tsubroutine spline(xa,ya,x,y,extrapolation)\n\t\treal(kind=8), INTENT(INOUT) :: y(:)\n\t\treal(kind=8), INTENT(IN) :: xa(:), ya(:), x(:)\n\t\treal(kind=8) :: y2a(size(xa))\n\t\tcharacter*4 :: extrapolation\n\t\tinteger :: n_x, n, i, k, khi, klo\n\t\treal(kind=8) :: a, b, h, extrap\n\t\t\t\n\t\t\tn = size(xa)\n\t\t\tn_x = size(x)\n\t\t\tcall splin1(xa,ya,1.d30,1.d30,y2a)\n\n\t\t\tdo i = 1, n_x\t\t\t\t\t\n\n! Downward extrapolation \n\t\t\t\tif (x(i) < xa(1)) then\n\t\t\t\t\tselect case(extrapolation)\n\t\t\t\t\t\tcase('NO ')\n\t\t\t\t\t\t\ty(i) = ya(1)\n\t\t\t\t\t\tcase('SQRT')\n\t\t\t\t\t\t\textrap = mean(ya/dsqrt(xa))\n\t\t\t\t\t\t\ty(i) = extrap * x(i)\n\t\t\t\t\tend select\n\t\t\t\telse \n\n! Upward extrapolation\n\t\t\t\tif (x(i) > xa(n)) then\n\t\t\t\t\tselect case(extrapolation)\n\t\t\t\t\t\tcase('NO ')\n\t\t\t\t\t\t\ty(i) = ya(n)\n\t\t\t\t\t\tcase('SQRT')\n\t\t\t\t\t\t\textrap = mean(ya/dsqrt(xa))\n\t\t\t\t\t\t\ty(i) = extrap * x(i)\n\t\t\t\t\tend select\n\t\t\t\telse\n! In range\n\t\t\t\t\t\tklo = 1\n\t\t\t\t\t\tkhi = n\n1\t\t\t\t\t\tif(khi-klo > 1) then\n\t\t\t\t\t\t\tk = (khi+klo)/2\n\t\t\t\t\t\t\tif (xa(k) > x(i)) then\n\t\t\t\t\t\t\t\tkhi = k\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tklo = k\n\t\t\t\t\t\t\tendif\t\t\t\t\t\n\t\t\t\t\t\t\tgo to 1\n\t\t\t\t\t\tendif\n\n\t\t\t\t\t\th = xa(khi)-xa(klo)\n\n\t\t\t\t\t\tif (h == 0.d0) then\n\t\t\t\t\t\t\tprint *, 'bad xa input in spline'\n\t\t\t\t\t\t\tstop\n\t\t\t\t\t\tendif\n\t\t\t\t\t\ta = (xa(khi)-x(i))/h\n\t\t\t\t\t\tb = (x(i)-xa(klo))/h\n\n\t\t\t\t\t\ty(i) = a*ya(klo)+b*ya(khi)+((a**3.d0-a)*y2a(klo)+(b**3.d0-b)*y2a(khi))*(h**2.d0)/6.d0\t\t\n\t\t\t\t\tendif\n\t\t\t\tendif\n\t\t\tenddo\n\n\t\tend subroutine spline\n\n! ---------------------------------------------------------\n! Returns the value at x0 with an interpolation in the data (x,y)\n! ---------------------------------------------------------\n\t\tfunction interpolate(x,y,x0)\n\t\treal(kind=8) :: interpolate\n\t\treal(kind=8) :: x0\n\t\treal(kind=8), INTENT(IN) :: x(:), y(:)\n\t\treal(kind=8) :: x1(1), y1(1)\n\t\t\tx1(1) = x0\n\t\t\tcall spline(x,y,x1,y1,'NO ')\n\t\t\tinterpolate = y1(1)\t\t\t\t\n\t\tend function interpolate\n\n! ---------------------------------------------------------\n! Returns the vector of linearly interpolated data for a given data x0, y0 at given values x\n! ---------------------------------------------------------\n\t\tsubroutine linear_interpol(x0,y0,x,y)\t\n\t\treal(kind=8), INTENT(IN) :: x0(:), y0(:)\n\t\treal(kind=8), INTENT(INOUT) :: x(:), y(:)\n\t\treal(kind=8) :: a, b, ya, yb, m, n\n\t\tinteger :: n1, n2, i, j, which\n\n\t\t\twhich = 0\n\t\t\t\n\t\t\tn1 = size(x0)\n\t\t\tn2 = size(x)\n\n\t\t\tdo i = 1, n2\n\t\t\t\tif (x(i) < x0(1)) then\n\t\t\t\t\twhich = 1\n\t\t\t\telse\n\t\t\t\t\tdo j = 1, n1-1\n\t\t\t\t\t\tif (x(i) >= x0(j) .and. x(i) <= x0(j+1)) then\n\t\t\t\t\t\t\twhich = j\n\t\t\t\t\t\tendif\n\t\t\t\t\tenddo\n\t\t\t\tendif\n\t\t\t\ta = x0(which)\n\t\t\t\tb = x0(which+1)\n\t\t\t\tya = y0(which)\n\t\t\t\tyb = y0(which+1)\n\t\t\t\t\n\t\t\t\tm = (ya-yb)/(a-b)\n\t\t\t\tn = (yb*a-ya*b)/(a-b)\n\t\t\t\ty(i) = m * x(i) + n\n\t\t\tenddo\n\n\t\t\t\t\t\t\n\t\tend subroutine linear_interpol\n\n! ---------------------------------------------------------\n! Returns the imaginary part of a complex number\n! ---------------------------------------------------------\n\t\tfunction imaginary(x)\t\t\n\t\treal(kind=8) :: imaginary\n\t\tcomplex(kind=8), INTENT(IN) :: x\n\t\tcomplex(kind=8) :: i\n\t\t\ti = cmplx(0.d0,1.d0)\n\t\t\timaginary = -real(i*x)\n\t\tend function imaginary\n\t\t\n\t\t\nend module maths\n", "meta": {"hexsha": "3b309b149a49d1afe37b9cac58b37b3a4df8ace3", "size": 28104, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source/math.f90", "max_stars_repo_name": "aasensio/gocciola", "max_stars_repo_head_hexsha": "d5adb942fec43602c035eefd7e9c402d60a0be3f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-23T17:35:06.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-23T17:35:06.000Z", "max_issues_repo_path": "Source/math.f90", "max_issues_repo_name": "aasensio/gocciola", "max_issues_repo_head_hexsha": "d5adb942fec43602c035eefd7e9c402d60a0be3f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Source/math.f90", "max_forks_repo_name": "aasensio/gocciola", "max_forks_repo_head_hexsha": "d5adb942fec43602c035eefd7e9c402d60a0be3f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.6657534247, "max_line_length": 96, "alphanum_fraction": 0.4634927412, "num_tokens": 10349, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.822189121808099, "lm_q1q2_score": 0.7532153643264472}} {"text": "module interpolation\n use lin_alg\ncontains\n subroutine pinex(xi,yi,x,y,dy)\n !=========================================================!\n ! Polynomial INterpolation and EXtrapolation (PINEX). !\n ! Runge-Kutta 4 Gill's method !\n ! Daniel Celis Garza 24 Sept. 2015 !\n !---------------------------------------------------------!\n ! Inputs: !\n ! x = independent variable !\n ! xi() = independent variable points !\n ! yi() = independent variable points !\n !---------------------------------------------------------!\n ! Outputs: !\n ! y = dependent variable !\n ! dy = dependent variable increment/error !\n !---------------------------------------------------------!\n ! Locals: !\n ! c() = small difference 1 !\n ! d() = small difference 2 !\n ! difx() = distance between point i and input x !\n ! aux_difx() = aux var to find distance of x to point i !\n ! den() = denominator !\n ! idx = closest point to x !\n ! aux_idx = aux var to find index i !\n ! i = counter !\n ! n = size(xi) !\n !=========================================================!\n implicit none\n real(dp), intent(in) :: x, xi(:), yi(:)\n real(dp), intent(out) :: y, dy\n real(dp), dimension(size(xi)) :: c, d, difx, aux_difx, den\n integer :: i, idx, aux_idx(1), n\n\n ! Making sure we're using equally sized arrays.\n check_size: if(size(xi) /= size(yi)) then\n print*, ' Size of x and y arrays must be equal.'\n return\n endif check_size\n\n ! The order of the interpolation.\n n = size(xi)\n\n ! Calculating (x-xi) for all i [and (xj-x) for all j].\n difx = x-xi\n\n ! Looking for the index of the entry with the closest value to x from xi.\n aux_difx = abs(x-xi)\n aux_idx = minloc(aux_difx)\n idx = aux_idx(1)\n\n ! Our initial best guess for y.\n y = yi(idx)\n\n ! Drop down an index because that's what's required by the relationships of Cs and Ds\n idx = idx - 1\n\n ! Initialising relationships of Cs and Ds.\n c = yi\n d = yi\n\n ! Looping over the columns of Neville's tree.\n nev_loop: do i = 1, n - 1\n den(1:n-i) = difx(1:n-i) - difx(1+i:n)\n if ( any( den(1:n-i) == 0._dp ) ) print*, ' Error: subr: poly_interpol: nev_loop. Division by zero.'\n den(1:n-i) = ( c(2:n-i+1) - d(1:n-i) ) / den(1:n-i)\n d(1:n-i) = difx(1+i:n) * den(1:n-i)\n c(1:n-i) = difx(1:n-i) * den(1:n-i)\n\n ! Calculate error terms.\n err: if (2*idx < n-i) then\n dy = c(idx+1)\n else err\n dy = d(idx)\n idx = idx-1\n end if err\n \n ! Increase the value of y.\n y = y + dy\n end do nev_loop\n end subroutine pinex\n\n subroutine rinex(xi,yi,x,y,dy)\n ! Polynomial INterpolation and EXtrapolation (PINEX).\n implicit none\n real(dp), intent(in) :: x, xi(:), yi(:)\n real(dp), intent(out) :: y, dy\n integer :: i, j, idx, aux_idx(1), n\n real(dp), dimension(size(xi)) :: c, d, difx, aux_difx, w, v\n real(dp), parameter :: tiny = 1.d-25\n\n ! Making sure we're using equally sized arrays.\n check_size: if(size(xi) /= size(yi)) then\n print*, \" Size of x and y/home/krunos/Documents/interpolation/interpol_mod.f08 arrays must be equal.\"\n return\n end if check_size\n\n ! The order of the interpolation.\n n = size(xi)\n\n ! Calculating (x-xi) for all i [and (xj-x) for all j].\n difx = x-xi\n\n ! Looking for the index of the entry with the closest value to x from xi.\n aux_difx = abs(x-xi)\n aux_idx = minloc(aux_difx)\n idx = aux_idx(1)\n\n ! Our initial best guess for y.\n y = yi(idx)\n\n ! Return when x == xi(idx).\n ret: if (x == xi(idx)) then\n dy = 0._dp\n return\n endif ret\n\n ! Drop down an index because that's what's required by the relationships of Cs and Ds\n idx = idx - 1\n\n ! Initialising relationships of Cs and Ds.\n c = yi\n d = yi + tiny\n\n ! Looping over the columns of Neville's tree.\n nev_loop: do i = 1, n - 1\n ! Calculating (x - x_{i}) / (x - x_{i+m+1}) * D_{m,i}.\n w( 1: n - i ) = ( x - xi( 1: n - i) ) * d( 1: n - i ) / difx( 1 + i: n )\n ! Calculating (x - x_{i}) / (x - x_{i+m+1}) * D_{m,i} - C_{m,i+1}.\n v( 1: n - i ) = w( 1: n - i ) - c( 2: n - i + 1 )\n\n ! Making sure we're using equally sized arrays.\n check_underflow: if( any( v( 1: n - 1 ) == 0._dp ) ) then\n print*, \" Error: rinex: nev_loop: Denominator = 0, use different points.\"\n return\n end if check_underflow\n\n ! Calculate the common factor ( c(m,i+1) - d(m,i) ) / ( (x - x_{i}) / ( x - x_{i+m+1}) * D_{m,i} - C_{m,i+1} ).\n v( 1: n - i ) = ( c(2: n - i + 1) - d( 1: n - i ) ) / v( 1: n - i )\n ! Calcualte D(m+1, i).\n d( 1: n - i ) = c(2: n - i + 1) * v ( 1: n - i )\n ! Calcualte C(m+1, i).\n c( 1: n - i ) = w(1: n - i ) * v ( 1: n - i )\n\n ! Calculate the interpolated value of y.\n ! Decide by how much we're going to increase y so as to cover Neville's tree the fastest.\n err: if ( 2 * idx < n - i ) then\n dy = c(idx+1)\n else err\n dy = d(idx)\n idx = idx-1\n end if err\n y = y + dy\n end do nev_loop\n end subroutine rinex\n\n subroutine csplinec(xi,yi,y,dydx1,dydx2)\n ! better way of doing things http://mathworld.wolfram.com/CubicSpline.html\n !===============================================!\n ! Cubic spline !\n ! Daniel Celis Garza 9 Apr. 2016 !\n !-----------------------------------------------!\n ! Inputs: !\n ! dydx = derivatives !\n ! xi = points in x !\n ! yi = points in y !\n ! dxdy = array of derivatives at points 1 and N !\n !-----------------------------------------------!\n ! Locals: !\n ! a() =\n ! b() =\n ! c() = !\n ! d() =\n !-----------------------------------------------!\n ! Outputs: !\n ! y() = array of interpolated values !\n !===============================================!\n implicit none\n real(dp), intent(in) :: xi(:), yi(:)\n real(dp), optional, intent(in) :: dydx1, dydx2\n real(dp), intent(out) :: y(:)\n real(dp), dimension(size(xi)) :: a, b, c, d\n integer :: n\n\n check_size: if (size(xi) /= size(yi) .or. size(xi) /= size(y)) then\n print*, \" Error: subr: csplinec: check_size: sizes of xi, yi and y arrays must be the same. \"\n return\n end if check_size\n\n ! Number of points.\n n = size(xi)\n\n ! Set up tridiagonal matrix.\n\n ! a(1) = x(2) - x(1)\n ! ...\n ! a(n-1) = x(n) - x(n-1)\n a(1: n - 1) = xi(2: n) - xi(1: n - 1)\n\n ! b(1) = 6 * ( y(2) - y(1) ) / ( x(2) - x(1) )\n ! ...\n ! b(n-1) = 6 * ( y(n) - y(n-1) ) / ( x(n) - x(n - 1) )\n b(1: n - 1) = 6._dp * ( yi(2: n) - yi(1: n - 1) ) / a(1: n - 1)\n\n ! b(2) = 6 *( ( y(3) - y(2) ) / ( x(3) - x(2) ) - ( y(2) - y(1) ) / ( x(2) - x(1) ) )\n ! ...\n ! b(n-1) = 6 *( ( y(n) - y(n - 1) ) / ( x(n) - x(n - 1) ) - ( y(n - 1) - y(n - 2) ) / ( x(n - 1) - x(n - 2) ) )\n b(2: n - 1) = b(2: n - 1) - b(1: n - 2)\n\n ! c(2) = x(2) - x(1)\n ! ...\n ! c(n-1) = x(n - 1) - x(n - 2)\n c(2: n - 1) = a(1: n - 2)\n\n ! d(2) = 2 * ( x(3) - x(2) + x(2) - x(1) )\n ! d(2) = 2 * ( x(3) - x(1) )\n ! ...\n ! d(n-1) = 2 * ( x(n - 1) - x(n - 2) + x(n - 2) - x(n - 3) )\n d(2: n - 1) = 2._dp * ( a(2: n - 1) + c(2: n - 1) )\n ! Because A = 1 at x1. numerical recipes 107--108\n d(1) = 1._dp\n ! Because B = 1 at xn. numerical recipes 107--108\n d(n) = 1._dp\n\n ! Lower boundary conditions.\n ! If the Lower Boundary Condition (LBC) is not present.\n lbc: if (present(dydx1) .eqv. .false.) then\n ! If there is no LBC, it is set to the natural value.\n a(1) = 0._dp\n b(1) = 0._dp\n else lbc\n ! Else, it is set to a specified first derivative.\n a(1) = 0.5_dp\n b(1) = ( 3._dp / ( xi(2) - xi(1) ) ) * ( ( yi(2) - yi(1) ) / ( xi(2) - xi(1) ) - dydx1 )\n end if lbc\n\n ! Lower boundary conditions.\n ! If the Upper Boundary Condition (UBC) is not present.\n ubc: if (present(dydx1) .eqv. .false.) then\n ! If there is no LBC, it is set to the natural value.\n c(n) = 0._dp\n b(n) = 0._dp\n else ubc\n ! Else, it is set to a specified first derivative.\n c(n) = 0.5_dp\n b(n) = ( - 3._dp / ( xi(n) - xi(n - 1) ) ) * ( ( yi(n) - yi(n - 1) ) / ( xi(n) - xi(n - 1) ) - dydx2 )\n end if ubc\n\n ! Call subroutine to solve tridiagonal matrix.\n call tridiag(c(2: n), d, a(1: n - 1), b, y)\n end subroutine csplinec\n\n subroutine csplnei(xi, yi, yi2, x, y)\n implicit none\n real(dp), intent(in) :: x, xi(:), yi(:), yi2(:)\n real(dp), intent(out) :: y\n real(dp) :: h, a, b\n integer :: n, oidx, nidx\n\n ! Set the value of n to be the number of dots to interpolate.\n n = size(xi)\n ! Check that the sizes of all arrays involved are the same.\n check_size: if ( n /= size(yi) .or. &\n n /= size(yi2) ) then\n write(*,*) \" Error: subr: csplinei: check_size: sizes of xi, yi and yi2 arrays must be the same; size(xi) = \", n, &\n \"; size(yi) = \", size(yi), \"; size(yi2) = \", size(yi2)\n return\n end if check_size\n\n ! Find the index corresponding to the value of x.\n oidx = vbisect(xi, x)\n\n nidx = oidx + 1\n\n ! Calculate the interval.\n h = xi( nidx ) - xi( oidx )\n ! Check if h is zero.\n if ( h == 0._dp ) write(*,*) \" Error: subr: csplinei: h is too small, wrong values of xi; h = \", h, \"; x(nidx) = \", xi(nidx), &\n \"; x(oidx) = \", xi(oidx)\n\n a = ( x - xi( oidx ) ) / h\n b = ( xi( nidx ) - x ) / h\n\n ! Construct the cubic equation.\n y = a * yi(nidx) + b * yi(oidx) + ( ( a*a*a - a ) * yi2(nidx) + ( b*b*b - b ) * yi2(oidx) ) * h*h / 6._dp\nend subroutine csplnei\n\nfunction vbisect(xi, x)\n ! Find x in within an interval in xa.\n implicit none\n real(dp), intent(in) :: xi(:), x\n integer :: vbisect\n integer :: n, i, a, b, c\n logical :: up\n\n n = size(xi)\n up = ( xi(n) >= xi(1) )\n a = 0\n b = n + 1\n\n ! Carry out Bisection.\n bisect: do\n ! If we are in adjacent or equal positions, exit.\n ! [ | n | n+1 | | ]\n ! Exit if (a = n and b = n + 1), or Exit if ( a = n and b = n )\n if ( b - a <= 1 ) exit bisect\n ! Find midpoint via integer division.\n c = ( a + b ) / 2\n ! Decide whether to move a Up or b Down.\n ud: if ( up .eqv. ( x >= xi(c) ) ) then\n a = c\n else ud\n b = c\n end if ud\n end do bisect\n\n ! Check Location of X Within the Interval (LXWI).\n lxwi: if ( x == xi(1) ) then\n vbisect = 1\n else if ( x == xi(n) ) then\n vbisect = n - 1\n else lxwi\n vbisect = a\n end if lxwi\n\nend function vbisect\nend module interpolation\n", "meta": {"hexsha": "80c78dadc9e969153ec19db7a615a878e3d89b16", "size": 11535, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "interpolation/interpol_mod.f08", "max_stars_repo_name": "dcelisgarza/applied_math", "max_stars_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2015-09-30T19:22:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T23:33:04.000Z", "max_issues_repo_path": "interpolation/interpol_mod.f08", "max_issues_repo_name": "dcelisgarza/applied_math", "max_issues_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "interpolation/interpol_mod.f08", "max_forks_repo_name": "dcelisgarza/applied_math", "max_forks_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.0607902736, "max_line_length": 129, "alphanum_fraction": 0.4475942783, "num_tokens": 3804, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179068309441, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7531886429880562}} {"text": "C$Procedure MTXVG ( Matrix transpose times vector, general dimension )\n \n SUBROUTINE MTXVG ( M1, V2, NC1, NR1R2, VOUT )\n \nC$ Abstract\nC\nC Multiply the transpose of a matrix and a vector of\nC arbitrary size.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC MATRIX, VECTOR\nC\nC$ Declarations\n \n INTEGER NC1\n INTEGER NR1R2\n DOUBLE PRECISION M1 ( NR1R2,NC1 )\n DOUBLE PRECISION V2 ( NR1R2 )\n DOUBLE PRECISION VOUT ( NC1 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC M1 I Left-hand matrix whose transpose is to be\nC multiplied.\nC V2 I Right-hand vector to be multiplied.\nC NC1 I Column dimension of M1 and length of VOUT.\nC NR1R2 I Row dimension of M1 and length of V2.\nC VOUT O Product vector M1**T * V2.\nC VOUT must NOT overwrite either M1 or V2.\nC\nC$ Detailed_Input\nC\nC M1 This is a double precision matrix of arbitrary size whose\nC transpose forms the left-hand matrix of the\nC multiplication.\nC\nC V2 This is a double precision vector on the right of the\nC multiplication.\nC\nC NC1 This is the column dimension of M1 and length of VOUT.\nC\nC NR1R2 This is the row dimension of M1 and length of V2.\nC\nC$ Detailed_Output\nC\nC VOUT This is the double precision vector which results from\nC the expression\nC\nC T\nC VOUT = (M1) x V2\nC\nC where the T denotes the transpose of M1.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Particulars\nC\nC The code reflects precisely the following mathematical expression\nC\nC For each value of the subscript I from 1 to NC1,\nC\nC VOUT(I) = Summation from K=1 to NR1R2 of ( M1(K,I) * V2(K) )\nC\nC Note that the reversal of the K and I subscripts in the left-hand\nC matrix M1 is what makes VOUT the product of the TRANSPOSE of M1\nC and not simply of M1 itself.\nC\nC Since this subroutine operates on matrices of arbitrary size, it\nC is not feasible to buffer intermediate results. Thus, VOUT\nC should NOT overwrite either M1 or V2.\nC\nC$ Examples\nC\nC | 1 2 |\nC Suppose that M1 = | 1 3 |\nC | 1 4 |\nC\nC | 1 |\nC and that V2 = | 2 |\nC | 3 |\nC\nC Then calling MTXVG according to the following calling sequence\nC\nC CALL MTXVG (M1, V2, 2, 3, VOUT)\nC\nC will yield the following vector value for VOUT\nC\nC VOUT = | 6 |\nC | 20 |\nC\nC$ Restrictions\nC\nC 1) The user is responsible for checking the magnitudes of the\nC elements of M1 and V2 so that a floating point overflow does\nC not occur.\nC 2) VOUT not overwrite M1 or V2 or else the intermediate\nC will affect the final result.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.M. Owen (JPL)\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WMO)\nC\nC-&\n \nC$ Index_Entries\nC\nC matrix_transpose times n-dimensional vector\nC\nC-&\n \n \n \nC\nC Local variables\nC\n DOUBLE PRECISION SUM\n INTEGER I,K\n \n \nC\nC Perform the matrix-vector multiplication\nC\n DO I = 1, NC1\n \n SUM = 0.D0\n \n DO K = 1, NR1R2\n SUM = SUM + M1(K,I)*V2(K)\n END DO\n \n VOUT(I) = SUM\n \n END DO\n \n RETURN\n END\n", "meta": {"hexsha": "8ab3f6146101521d9a08270df0c3251e31cfde25", "size": 5172, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/mtxvg.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/mtxvg.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/mtxvg.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 26.9375, "max_line_length": 72, "alphanum_fraction": 0.6243232792, "num_tokens": 1485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693659780477, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.753188428136483}} {"text": "SUBROUTINE rod_mm(mm,length)\n!\n! This subroutine forms the consistent mass matrix of a 1-d \"rod\" element.\n!\n IMPLICIT NONE\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n REAL(iwp),intent(in)::length\n REAL(iwp),intent(out)::mm(:,:)\n REAL(iwp)::one=1.0_iwp,d3=3.0_iwp,d6=6.0_iwp\n mm(1,1)=one/d3\n mm(1,2)=one/d6\n mm(2,1)=one/d6\n mm(2,2)=one/d3\n mm=mm*length\nRETURN\nEND SUBROUTINE rod_mm\n", "meta": {"hexsha": "6ef115fdb013bf8f8f8f02e657d3975c3d23ea1c", "size": 385, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main/rod_mm.f90", "max_stars_repo_name": "cunyizju/Programming-FEM-5th-Fortran", "max_stars_repo_head_hexsha": "7740d381c0871c7e860aee8a19c467bd97a4cf45", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 20, "max_stars_repo_stars_event_min_datetime": "2019-12-22T11:44:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T12:19:06.000Z", "max_issues_repo_path": "main/rod_mm.f90", "max_issues_repo_name": "cunyizju/Programming-FEM-5th-Fortran", "max_issues_repo_head_hexsha": "7740d381c0871c7e860aee8a19c467bd97a4cf45", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-03-13T06:51:33.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-13T06:51:33.000Z", "max_forks_repo_path": "main/rod_mm.f90", "max_forks_repo_name": "cunyizju/Programming-FEM-5th-Fortran", "max_forks_repo_head_hexsha": "7740d381c0871c7e860aee8a19c467bd97a4cf45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-06-03T12:47:06.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-30T13:35:28.000Z", "avg_line_length": 22.6470588235, "max_line_length": 74, "alphanum_fraction": 0.7116883117, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.949669363129097, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7531884235549122}} {"text": " SUBROUTINE shape3(deriv,shape,s,t,nnode )\r\n !********************************************************************\r\n !\r\n !*** calculates shape functions and their derivatives for 2d elements\r\n !\r\n !********************************************************************\r\n IMPLICIT NONE\r\n INTEGER (kind=4) :: nnode\r\n REAL (kind=8) deriv(nnode,2),shape(nnode),s,t\r\n REAL (kind=8) st\r\n\r\n st = s*t\r\n\r\n IF (nnode == 4) THEN\r\n\r\n ! shape functions for 4 noded element\r\n\r\n shape(1) = (1D0 - s - t + st)/4D0\r\n shape(2) = (1D0 + s - t - st)/4D0\r\n shape(3) = (1D0 + s + t + st)/4D0\r\n shape(4) = (1D0 - s + t - st)/4D0\r\n\r\n ! and derivatives\r\n\r\n deriv(1,1) = (-1d0 + t)/4d0\r\n deriv(2,1) = -deriv(1,1)\r\n deriv(3,1) = ( 1d0 + t)/4d0\r\n deriv(4,1) = -deriv(3,1)\r\n deriv(1,2) = (-1d0 + s)/4d0\r\n deriv(2,2) = (-1d0 - s)/4d0\r\n deriv(3,2) = -deriv(2,2)\r\n deriv(4,2) = -deriv(1,2)\r\n\r\n ELSE IF (nnode == 3) THEN\r\n\r\n ! shape functions for 3-node element\r\n\r\n shape(1) = 1.d0 - s - t\r\n shape(2) = s\r\n shape(3) = t\r\n\r\n ! and derivatives\r\n\r\n deriv(1,1) = -1.d0\r\n deriv(1,2) = -1.d0\r\n deriv(2,1) = 1.d0\r\n deriv(2,2) = 0.d0\r\n deriv(3,1) = 0.d0\r\n deriv(3,2) = 1.d0\r\n\r\n END IF\r\n\r\n END SUBROUTINE shape3\r\n", "meta": {"hexsha": "db3e6d4d609bfef753eb783e8305c2211cc9907a", "size": 1458, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/auxil/shape3.f90", "max_stars_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_stars_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/auxil/shape3.f90", "max_issues_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_issues_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/auxil/shape3.f90", "max_forks_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_forks_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0, "max_line_length": 77, "alphanum_fraction": 0.3875171468, "num_tokens": 502, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.753122019147518}} {"text": "!---------------------------------------------------!\n! Copyright (c) 2017 Shunsuke A. Sato !\n! Released under the MIT license !\n! https://opensource.org/licenses/mit-license.php !\n!---------------------------------------------------!\nsubroutine gaussian_random_number(x1,x2)\n implicit none\n real(8),parameter :: pi = 4d0*atan(1d0)\n real(8), intent(out) :: x1,x2\n real(8) :: r1,r2,tmp\n\n call random_number(r1)\n call random_number(r2)\n\n if(r1 == 0d0)then\n x1 = 0d0\n x2 = 0d0\n else \n tmp = sqrt(-2d0*log(r1))\n x1 = tmp*cos(2d0*pi*r2)\n x2 = tmp*sin(2d0*pi*r2)\n end if\n return\nend subroutine gaussian_random_number\n", "meta": {"hexsha": "589f790432cc4cff8b5449cccc996cb1c4e9357f", "size": 671, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/gaussian_random_number.f90", "max_stars_repo_name": "shunsuke-sato/quantum_liouville", "max_stars_repo_head_hexsha": "517870a90f1e5e7f18a08808d43d053d381275fc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/gaussian_random_number.f90", "max_issues_repo_name": "shunsuke-sato/quantum_liouville", "max_issues_repo_head_hexsha": "517870a90f1e5e7f18a08808d43d053d381275fc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/gaussian_random_number.f90", "max_forks_repo_name": "shunsuke-sato/quantum_liouville", "max_forks_repo_head_hexsha": "517870a90f1e5e7f18a08808d43d053d381275fc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.84, "max_line_length": 53, "alphanum_fraction": 0.521609538, "num_tokens": 204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.753122016883319}} {"text": "PROGRAM menxb\n \n! Code converted using TO_F90 by Alan Miller\n! Date: 2004-06-28 Time: 12:58:10\n\n! =========================================================\n! Purpose: This program computes the exponential integral\n! En(x) using subroutine ENXB\n! Example: x = 10.0\n! n En(x)\n! ----------------------\n! 0 .45399930D-05\n! 1 .41569689D-05\n! 2 .38302405D-05\n! 3 .35487626D-05\n! 4 .33041014D-05\n! 5 .30897289D-05\n! =========================================================\n\nIMPLICIT DOUBLE PRECISION (a-h,o-z)\nDIMENSION en(0:100)\nWRITE(*,*)'Please enter n and x '\n! READ(*,*)N,X\nn=5\nx=10.0\nWRITE(*,20)n,x\nWRITE(*,*)\nWRITE(*,*)' n En(x)'\nWRITE(*,*)' ----------------------'\nCALL enxb(n,x,en)\nDO k=0,n\n WRITE(*,30)k,en(k)\nEND DO\n20 FORMAT(5X,i3,', ','x=',f5.1)\n30 FORMAT(2X,i3,d18.8)\nEND PROGRAM menxb\n\n\nSUBROUTINE enxb(n,x,en)\n\n! ===============================================\n! Purpose: Compute exponential integral En(x)\n! Input : x --- Argument of En(x)\n! n --- Order of En(x) (n = 0,1,2,...)\n! Output: EN(n) --- En(x)\n! ===============================================\n\n\nINTEGER, INTENT(IN) :: n\nDOUBLE PRECISION, INTENT(IN) :: x\nDOUBLE PRECISION, INTENT(OUT) :: en(0:n)\nIMPLICIT DOUBLE PRECISION (a-h,o-z)\n\n\nIF (x == 0.0) THEN\n en(0)=1.0D+300\n en(1)=1.0D+300\n DO k=2,n\n en(k)=1.0D0/(k-1.0)\n END DO\n RETURN\nELSE IF (x <= 1.0) THEN\n en(0)=DEXP(-x)/x\n DO l=1,n\n rp=1.0D0\n DO j=1,l-1\n rp=-rp*x/j\n END DO\n ps=-0.5772156649015328D0\n DO m=1,l-1\n ps=ps+1.0D0/m\n END DO\n ens=rp*(-DLOG(x)+ps)\n s=0.0D0\n DO m=0,20\n IF (.NOT.(m == l-1)) THEN\n r=1.0D0\n DO j=1,m\n r=-r*x/j\n END DO\n s=s+r/(m-l+1.0D0)\n IF (DABS(s-s0) < DABS(s)*1.0D-15) EXIT\n s0=s\n END IF\n END DO\n 35 en(l)=ens-s\n END DO\nELSE\n en(0)=DEXP(-x)/x\n m=15+INT(100.0/x)\n DO l=1,n\n t0=0.0D0\n DO k=m,1,-1\n t0=(l+k-1.0D0)/(1.0D0+k/(x+t0))\n END DO\n t=1.0D0/(x+t0)\n en(l)=DEXP(-x)*t\n END DO\nEND IF\nEND SUBROUTINE enxb\n", "meta": {"hexsha": "03ffa3f47efd76f6adddca07cd4aed65d90703b9", "size": 2350, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MATLAB/f2matlab/comp_spec_func/menxb.f90", "max_stars_repo_name": "vasaantk/bin", "max_stars_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATLAB/f2matlab/comp_spec_func/menxb.f90", "max_issues_repo_name": "vasaantk/bin", "max_issues_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATLAB/f2matlab/comp_spec_func/menxb.f90", "max_forks_repo_name": "vasaantk/bin", "max_forks_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.2673267327, "max_line_length": 65, "alphanum_fraction": 0.4119148936, "num_tokens": 851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7531220141772134}} {"text": "program factorial\n\n implicit none\n integer :: n\n integer :: nmax\n integer :: fact\n\n fact = 1\n nmax = 10\n\n ! compute factorial version 1\n do n = 1, nmax\n fact = fact * n;\n end do\n print *, \"Version 1. Factorial of \", nmax, \"is: \", fact\n\n fact = 1\n n = 1\n do while(n <= nmax)\n fact = fact * n;\n print *, \"n = \", n, \" \", \"factorial = \", fact\n n = n + 1\n end do\n\nend program factorial\n\n", "meta": {"hexsha": "095347a790c86fbd41de049f6f1b7dffd47e3929", "size": 495, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "basics/factorial.f90", "max_stars_repo_name": "gmengaldo/fortran-gym", "max_stars_repo_head_hexsha": "e1e1f8e3256af8ec71bca87d8d9f10de0e531559", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "basics/factorial.f90", "max_issues_repo_name": "gmengaldo/fortran-gym", "max_issues_repo_head_hexsha": "e1e1f8e3256af8ec71bca87d8d9f10de0e531559", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "basics/factorial.f90", "max_forks_repo_name": "gmengaldo/fortran-gym", "max_forks_repo_head_hexsha": "e1e1f8e3256af8ec71bca87d8d9f10de0e531559", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.3333333333, "max_line_length": 64, "alphanum_fraction": 0.4525252525, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8991213718636752, "lm_q1q2_score": 0.7531220105326283}} {"text": "module special_functions\n use numerical_constants\n implicit none\n\ncontains\n subroutine gen_assoc_legendre_pol(x_pts, n_pts, lmax, alp)\n implicit none\n integer, intent(in) :: n_pts, lmax\n real(kind=dp), intent(in) :: x_pts(n_pts)\n real(kind=dp), intent(out) :: alp(n_pts, 0:lmax, -lmax:lmax)\n integer :: l, m, fact(lmax)\n\n call calc_factorials(lmax, fact)\n\n alp(:, 0, 0) = 1.0d0\n do l=1,lmax\n alp(:,l,l-1)=x_pts*(2.0d0*(l-1.0d0)+1.0d0)*alp(:,l-1,l-1)\n alp(:,l,-l+1)=(-1)**(l-1)*alp(:,l,l-1)/fact(l+l-1) !m=l-1\n alp(:,l,l)=-(2.0d0*(l-1.0d0)+1.0d0)*sqrt(1.d0-x_pts*x_pts)*alp(:,l-1,l-1)\n alp(:,l,-l)=(-1)**l*alp(:,l,l)/fact(l+l)\n do m=l-2,1,-1\n alp(:,l,m)=(x_pts*(2*l-1)*alp(:,l-1,m)-(l+m-1)*alp(:,l-2,m))/float(l-m)\n alp(:,l,-m)=(-1)**m*fact(l-m)*alp(:,l,m)/fact(l+m)\n end do\n alp(:,l,0)=(x_pts*(2*l-1)*alp(:,l-1,0)-(l-1)*alp(:,l-2,0))/float(l)\n end do\n end subroutine gen_assoc_legendre_pol\n\n subroutine calc_factorials(nmax, fact)\n implicit none\n integer, intent(in) :: nmax\n integer, intent(out) :: fact(nmax)\n integer :: i\n\n fact(0) = 1\n do i=1,nmax\n fact(i) = fact(i-1)*i\n end do\n\n end subroutine calc_factorials\nend module special_functions\n", "meta": {"hexsha": "156219b7a3cd80b41f729a975daa61dae66fce8e", "size": 1277, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exercises/special_functions.f90", "max_stars_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_stars_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exercises/special_functions.f90", "max_issues_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_issues_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exercises/special_functions.f90", "max_forks_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_forks_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.4047619048, "max_line_length": 83, "alphanum_fraction": 0.5638214565, "num_tokens": 512, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480237330998, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7530558277770183}} {"text": "! from http://calcul.math.cnrs.fr/Documents/Ecoles/2010/f2py-cours.pdf\n! Pierre Navaro\n\n\n! tableaux:\n! - attention: passer le bon type sinon, f2py effectue une copie\n! et travaille sur une variable temporaire (sans rien dire!)\n! - si multidim: specifier \"order='F'\" pour le tableau numpy!\n\nsubroutine move( positions, vitesses, dt, n)\n integer, intent(in) :: n\n real(8), intent(in) :: dt\n real(8), dimension(n,3), intent(in) :: vitesses\n real(8), dimension(n,3) :: positions\n do i = 1, n\n positions(i,:) = positions(i,:) + dt*vitesses(i,:)\n end do\nend subroutine move\n\n\n! creation d'un tableau et retour a python.\n! f2py se charge de la gestion de mémoire\nsubroutine create_array(A, n)\n integer, intent(in) :: n\n real(8), dimension(n,3), intent(out) :: A\n do i = 1, n\n do j = 1, n\n A(i,j) = i+j\n enddo\n enddo\nend subroutine create_array\n\n!\n! produit matriciel\n!\n\nsubroutine mult_array(A, B, C, m, n, k)\n\n real(8), dimension(m,k), intent(in) :: A\n real(8), dimension(k,n), intent(in) :: B\n integer :: m,n,k\n real(8), dimension(m,n), intent(out) :: C\n \n real(8) ::s\n integer :: i,j,l \n\n do i=1, m \n do j = 1, n \n s = 0.0\n do l = 1, k\n s = s + A(i,l)*B(l,j)\n enddo\n C(i,j) = s\n enddo\n enddo\nend subroutine mult_array", "meta": {"hexsha": "43e14bd7f13a3e49ec0815ca590c135574a7dabe", "size": 1380, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sandbox/fortranpython/navaro/fortranarrays.f90", "max_stars_repo_name": "rboman/progs", "max_stars_repo_head_hexsha": "c60b4e0487d01ccd007bcba79d1548ebe1685655", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-12-12T13:26:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T16:14:53.000Z", "max_issues_repo_path": "sandbox/fortranpython/navaro/fortranarrays.f90", "max_issues_repo_name": "rboman/progs", "max_issues_repo_head_hexsha": "c60b4e0487d01ccd007bcba79d1548ebe1685655", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2019-03-01T07:08:46.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-28T07:32:42.000Z", "max_forks_repo_path": "sandbox/fortranpython/navaro/fortranarrays.f90", "max_forks_repo_name": "rboman/progs", "max_forks_repo_head_hexsha": "c60b4e0487d01ccd007bcba79d1548ebe1685655", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-12-13T13:13:52.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-13T20:08:15.000Z", "avg_line_length": 24.6428571429, "max_line_length": 70, "alphanum_fraction": 0.5702898551, "num_tokens": 439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7530071427518076}} {"text": "let Rint (lo:Int) (hi:Int) :* = (x:Int. (and (lo<=x) (x false)\r\n (fn i l r =>\r\n (or (i=v) \r\n (if[Bool] v < i\r\n then search lo i l v\r\n else search i hi r v)));;\r\n\r\nlet rec insert (lo:Int) (hi:Int) (t:BiTree lo hi) (v:Rint lo hi) : (BiTree lo hi) =\r\n caseBiTree lo hi t (BiTree lo hi)\r\n (fn u =>\r\n Node lo hi v (Empty lo v) (Empty v hi))\r\n (fn i l r =>\r\n if[(BiTree lo hi)] v < i /* err if i <= v or v <= i*/\r\n then Node lo hi i (insert lo i l /*err if r*/ (v/* err if i */+0)) r /* err if l */\r\n else Node lo hi i l (insert i hi r (v+0)));;\r\n\r\nlet rec sum (lo:Int) (hi:Int) (t:BiTree lo hi) : Int =\r\n caseBiTree lo hi t Int\r\n (fn u => 0) \r\n (fn i l r =>\r\n (sum lo i l) + (sum i hi r));;\r\n\r\n\r\n\r\nlet MININT : Int = 0-32767;;\r\nlet MAXINT : Int = 32767;;\r\n\r\nlet BTree = BiTree MININT MAXINT;; \r\nlet Int16 = Rint MININT MAXINT;;\r\nlet mt:BTree = Empty MININT MAXINT;;\r\nlet ins (t:BTree) (v:Int16) : BTree = insert MININT MAXINT t v;;\r\nlet get (t:BTree) (v:Int16) : Bool = search MININT MAXINT t v;;\r\n\r\nlet t : BTree = (ins (ins (ins mt 1) 2) 3);;\r\n\r\n\r\nlet Pos = Rint 1 MAXINT;;\r\n\r\nlet PTree = BiTree 1 MAXINT;; \r\n\r\nlet mtP:PTree = Empty 1 MAXINT;;\r\nlet insP (t:PTree) (v:Pos) : PTree = insert 1 MAXINT t v;;\r\nlet getP (t:PTree) (v:Pos) : Bool = search 1 MAXINT t v;;\r\n\r\nlet x = 0-3;;\r\nlet tP : PTree = (insP (insP (insP mtP 1) 2) x);; \r\n\r\n(getP tP 2);; /* true */\r\n(getP tP 4);; /* false */\r\n\r\n\r\nlet sumAny = sum MININT MAXINT;;\r\nsumAny t;;\r\n/* sumAny tP;; */\r\n", "meta": {"hexsha": "46bcc33c98d80a8903ee12a759a2bdfbd31776ab", "size": 1782, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/bad/bst.10.f", "max_stars_repo_name": "ucsc-proglang/sage", "max_stars_repo_head_hexsha": "c62165999833fb044d2d86ffb0710b917b1ddacd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2015-01-18T14:34:40.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-11T02:06:09.000Z", "max_issues_repo_path": "tests/bad/bst.10.f", "max_issues_repo_name": "ucsc-proglang/sage", "max_issues_repo_head_hexsha": "c62165999833fb044d2d86ffb0710b917b1ddacd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/bad/bst.10.f", "max_forks_repo_name": "ucsc-proglang/sage", "max_forks_repo_head_hexsha": "c62165999833fb044d2d86ffb0710b917b1ddacd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.84375, "max_line_length": 89, "alphanum_fraction": 0.5364758698, "num_tokens": 678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037384317887, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7529620374615955}} {"text": " SUBROUTINE gaussj(a,n,np,b,m,mp)\r\n INTEGER m,mp,n,np,NMAX\r\n REAL a(np,np),b(np,mp)\r\n PARAMETER (NMAX=50)\r\n INTEGER i,icol,irow,j,k,l,ll,indxc(NMAX),indxr(NMAX),ipiv(NMAX)\r\n REAL big,dum,pivinv\r\n do 11 j=1,n\r\n ipiv(j)=0\r\n11 continue\r\n do 22 i=1,n\r\n big=0.\r\n do 13 j=1,n\r\n if(ipiv(j).ne.1)then\r\n do 12 k=1,n\r\n if (ipiv(k).eq.0) then\r\n if (abs(a(j,k)).ge.big)then\r\n big=abs(a(j,k))\r\n irow=j\r\n icol=k\r\n endif\r\n else if (ipiv(k).gt.1) then\r\n pause 'singular matrix in gaussj'\r\n endif\r\n12 continue\r\n endif\r\n13 continue\r\n ipiv(icol)=ipiv(icol)+1\r\n if (irow.ne.icol) then\r\n do 14 l=1,n\r\n dum=a(irow,l)\r\n a(irow,l)=a(icol,l)\r\n a(icol,l)=dum\r\n14 continue\r\n do 15 l=1,m\r\n dum=b(irow,l)\r\n b(irow,l)=b(icol,l)\r\n b(icol,l)=dum\r\n15 continue\r\n endif\r\n indxr(i)=irow\r\n indxc(i)=icol\r\n if (a(icol,icol).eq.0.) pause 'singular matrix in gaussj'\r\n pivinv=1./a(icol,icol)\r\n a(icol,icol)=1.\r\n do 16 l=1,n\r\n a(icol,l)=a(icol,l)*pivinv\r\n16 continue\r\n do 17 l=1,m\r\n b(icol,l)=b(icol,l)*pivinv\r\n17 continue\r\n do 21 ll=1,n\r\n if(ll.ne.icol)then\r\n dum=a(ll,icol)\r\n a(ll,icol)=0.\r\n do 18 l=1,n\r\n a(ll,l)=a(ll,l)-a(icol,l)*dum\r\n18 continue\r\n do 19 l=1,m\r\n b(ll,l)=b(ll,l)-b(icol,l)*dum\r\n19 continue\r\n endif\r\n21 continue\r\n22 continue\r\n do 24 l=n,1,-1\r\n if(indxr(l).ne.indxc(l))then\r\n do 23 k=1,n\r\n dum=a(k,indxr(l))\r\n a(k,indxr(l))=a(k,indxc(l))\r\n a(k,indxc(l))=dum\r\n23 continue\r\n endif\r\n24 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "9d6f12069831db39a4480df6b93e40aeea2f8fad", "size": 2025, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/gaussj.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/gaussj.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/gaussj.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0, "max_line_length": 70, "alphanum_fraction": 0.4217283951, "num_tokens": 639, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628703, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.7529620257555835}} {"text": "module funcs\nimplicit none\ncontains\n\nreal(kind=8) function f(x)\n real(kind=8) x\n\n f = 5*x*x*x + 2*x*x + 120\nend function f\n\nreal(kind=8) function df_dx(x)\n real(kind=8) x\n\n df_dx = 15*x*x + 4*x\nend function df_dx\n\nsubroutine check_NaN (x, label)\n real(kind=8), intent(in) :: x\n character(len=5), intent(in) :: label\n\n if (isnan(x)) then \n write(*,'(A4,A5,A12)') \"... \", label, \" is a NaN ...\"\n stop\n end if\nend subroutine check_NaN\n\nend module funcs\n", "meta": {"hexsha": "f426d0b96e435bcaf1d41138000099ef5f035f5c", "size": 476, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ME_Numerical_Methods/HW4/ex1/b/mod.f95", "max_stars_repo_name": "ElenaKusevska/Fortran_exercises", "max_stars_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ME_Numerical_Methods/HW4/ex1/b/mod.f95", "max_issues_repo_name": "ElenaKusevska/Fortran_exercises", "max_issues_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ME_Numerical_Methods/HW4/ex1/b/mod.f95", "max_forks_repo_name": "ElenaKusevska/Fortran_exercises", "max_forks_repo_head_hexsha": "69bab3c2ac6a17612e28e71e8a7bd322f4260153", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.0, "max_line_length": 59, "alphanum_fraction": 0.6134453782, "num_tokens": 163, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.8596637433190939, "lm_q1q2_score": 0.7528823291643357}} {"text": "************************************************************************\n* General collection of routines which might help somewhere...\n************************************************************************\n\n************************************************************************\n* Linear rescale\n*\n* Scales a coordinate x linearly from the interval [a,b] to the\n* interval [c,d].\n*\n* In:\n* x - coordinate to be rescaled\n* [a,b] - source interval\n* [c,d] - destination interval\n*\n* Out:\n* y - Rescaled coordinate\n************************************************************************\n\n SUBROUTINE LRSCLE (X,A,B,C,D,Y)\n \n IMPLICIT NONE\n \n DOUBLE PRECISION X,A,B,C,D,Y\n \n DOUBLE PRECISION D1,D2,D3\n \nC Calculate the coefficients of the transformation \nC D1*A+D2 = C, D1*B+D2 = D.\nC Use them to calculate Y=D1*X+D2.\n\n IF (A.EQ.B) THEN\n Y = C\n RETURN\n END IF\n\n D3 = 1D0/(A-B)\n D1 = (C-D)*D3\n D2 = (-B*C+A*D)*D3\n \n Y = D1*X+D2\n \n END\n", "meta": {"hexsha": "db88df345d9503b4c71aeb540456fbc064dab78c", "size": 1065, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "area51/cc2d_movbc_structured_2/src/misc/generalutil.f", "max_stars_repo_name": "tudo-math-ls3/FeatFlow2", "max_stars_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_stars_repo_licenses": ["Intel", "Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-09T15:48:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-09T15:48:37.000Z", "max_issues_repo_path": "area51/cc2d_movbc_structured_2/src/misc/generalutil.f", "max_issues_repo_name": "tudo-math-ls3/FeatFlow2", "max_issues_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_issues_repo_licenses": ["Intel", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "area51/cc2d_movbc_structured_2/src/misc/generalutil.f", "max_forks_repo_name": "tudo-math-ls3/FeatFlow2", "max_forks_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_forks_repo_licenses": ["Intel", "Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.2045454545, "max_line_length": 72, "alphanum_fraction": 0.3906103286, "num_tokens": 253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436483, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7528141395360571}} {"text": "!> \\brief \\b DROTG\n!\n! =========== DOCUMENTATION ===========\n!\n! Online html documentation available at\n! http://www.netlib.org/lapack/explore-html/\n!\n! Definition:\n! ===========\n!\n! DROTG constructs a plane rotation\n! [ c s ] [ a ] = [ r ]\n! [ -s c ] [ b ] [ 0 ]\n! satisfying c**2 + s**2 = 1.\n!\n!> \\par Purpose:\n! =============\n!>\n!> \\verbatim\n!>\n!> The computation uses the formulas\n!> sigma = sgn(a) if |a| > |b|\n!> = sgn(b) if |b| >= |a|\n!> r = sigma*sqrt( a**2 + b**2 )\n!> c = 1; s = 0 if r = 0\n!> c = a/r; s = b/r if r != 0\n!> The subroutine also computes\n!> z = s if |a| > |b|,\n!> = 1/c if |b| >= |a| and c != 0\n!> = 1 if c = 0\n!> This allows c and s to be reconstructed from z as follows:\n!> If z = 1, set c = 0, s = 1.\n!> If |z| < 1, set c = sqrt(1 - z**2) and s = z.\n!> If |z| > 1, set c = 1/z and s = sqrt( 1 - c**2).\n!>\n!> \\endverbatim\n!\n! Arguments:\n! ==========\n!\n!> \\param[in,out] A\n!> \\verbatim\n!> A is DOUBLE PRECISION\n!> On entry, the scalar a.\n!> On exit, the scalar r.\n!> \\endverbatim\n!>\n!> \\param[in,out] B\n!> \\verbatim\n!> B is DOUBLE PRECISION\n!> On entry, the scalar b.\n!> On exit, the scalar z.\n!> \\endverbatim\n!>\n!> \\param[out] C\n!> \\verbatim\n!> C is DOUBLE PRECISION\n!> The scalar c.\n!> \\endverbatim\n!>\n!> \\param[out] S\n!> \\verbatim\n!> S is DOUBLE PRECISION\n!> The scalar s.\n!> \\endverbatim\n!\n! Authors:\n! ========\n!\n!> \\author Edward Anderson, Lockheed Martin\n!\n!> \\par Contributors:\n! ==================\n!>\n!> Weslley Pereira, University of Colorado Denver, USA\n!\n!> \\ingroup single_blas_level1\n!\n!> \\par Further Details:\n! =====================\n!>\n!> \\verbatim\n!>\n!> Anderson E. (2017)\n!> Algorithm 978: Safe Scaling in the Level 1 BLAS\n!> ACM Trans Math Softw 44:1--28\n!> https://doi.org/10.1145/3061665\n!>\n!> \\endverbatim\n!\n! =====================================================================\nsubroutine DROTG( a, b, c, s )\n integer, parameter :: wp = kind(1.d0)\n!\n! -- Reference BLAS level1 routine --\n! -- Reference BLAS is a software package provided by Univ. of Tennessee, --\n! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n!\n! .. Constants ..\n real(wp), parameter :: zero = 0.0_wp\n real(wp), parameter :: one = 1.0_wp\n! ..\n! .. Scaling constants ..\n real(wp), parameter :: safmin = real(radix(0._wp),wp)**max( &\n minexponent(0._wp)-1, &\n 1-maxexponent(0._wp) &\n )\n real(wp), parameter :: safmax = real(radix(0._wp),wp)**max( &\n 1-minexponent(0._wp), &\n maxexponent(0._wp)-1 &\n )\n! ..\n! .. Scalar Arguments ..\n real(wp) :: a, b, c, s\n! ..\n! .. Local Scalars ..\n real(wp) :: anorm, bnorm, scl, sigma, r, z\n! ..\n anorm = abs(a)\n bnorm = abs(b)\n if( anorm == zero ) then\n c = zero\n s = one\n a = b\n b = one\n else if( bnorm == zero ) then\n c = one\n s = zero\n b = zero\n else\n scl = min( safmax, max( safmin, anorm, bnorm ) )\n if( anorm > bnorm ) then\n sigma = sign(one,a)\n else\n sigma = sign(one,b)\n end if\n r = sigma*( scl*sqrt((a/scl)**2 + (b/scl)**2) )\n c = a/r\n s = b/r\n if( anorm > bnorm ) then\n z = s\n else if( c /= zero ) then\n z = one/c\n else\n z = one\n end if\n a = r\n b = z\n end if\n return\nend subroutine\n", "meta": {"hexsha": "fd309c0af97c77ae8cffd07373b59cf420d19891", "size": 3474, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "BLAS/SRC/drotg.f90", "max_stars_repo_name": "sergey-v-kuznetsov/lapack", "max_stars_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "BLAS/SRC/drotg.f90", "max_issues_repo_name": "sergey-v-kuznetsov/lapack", "max_issues_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "BLAS/SRC/drotg.f90", "max_forks_repo_name": "sergey-v-kuznetsov/lapack", "max_forks_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.8552631579, "max_line_length": 80, "alphanum_fraction": 0.4835924007, "num_tokens": 1211, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896693699845, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7528141316196835}} {"text": "!************************************************************\r\n\r\nSUBROUTINE zludcmp(A,det,n)\r\nIMPLICIT NONE\r\n\r\nINTEGER*4, INTENT(IN) :: n\r\nCOMPLEX*16, DIMENSION(0:n-1,0:n-1), INTENT(IN) :: A\r\nCOMPLEX*16, INTENT(OUT) :: det\r\n\r\n! ******\r\n! For input variables with zero-based indexing:\r\n! Calculation of det(A) using LU decomposition. Note that in general,\r\n! numerical overflow may result unless LOG(det(A)) is formed instead.\r\n\r\nCOMPLEX*16, DIMENSION(:,:), ALLOCATABLE :: A_aux\r\nINTEGER, DIMENSION(:), ALLOCATABLE :: ipiv\r\nINTEGER :: m,i,info\r\n\r\nALLOCATE(A_aux(1:n,1:n))\r\nALLOCATE(ipiv(1:n))\r\n\r\nA_aux(1:n,1:n) = A(0:n-1,0:n-1)\r\n\r\nm = n\r\nCALL ZGETRF(m,m,A_aux,m,ipiv,info)\r\n\r\nIF (info /= 0) THEN\r\n\t\r\n\tWRITE (*,*) 'ZGETRF failed in zludcmp, code: ',info\r\n\tSTOP\r\n\r\nEND IF\r\n\r\ndet = 1.d0\r\n\r\nDO i = 1,n\r\n \r\n\tIF (ipiv(i) /= i) det = -det * A_aux(i,i)\r\n\tIF (ipiv(i) == i) det = det * A_aux(i,i)\r\n\r\nEND DO\r\n\r\nDEALLOCATE(A_aux,ipiv)\r\n\r\nEND SUBROUTINE zludcmp\r\n\r\n!************************************************************\r\n\r\nSUBROUTINE zludcmp_ratio(A,detratio,ldetref,n)\r\nIMPLICIT NONE\r\n\r\nINTEGER*4, INTENT(IN) :: n\r\nCOMPLEX*16, DIMENSION(0:n-1,0:n-1), INTENT(IN) :: A\r\nDOUBLE PRECISION, INTENT(IN) :: ldetref\r\nCOMPLEX*16 :: ldet\r\nCOMPLEX*16, INTENT(OUT) :: detratio\r\n\r\n! ******\r\n! For input variables with zero-based indexing:\r\n! Calculation of det(A)/detref = det(A)/exp(ldetref) using LU decomposition,\r\n! where detref is positive\r\n\r\nCOMPLEX*16, DIMENSION(:,:), ALLOCATABLE :: A_aux\r\nINTEGER, DIMENSION(:), ALLOCATABLE :: ipiv\r\nINTEGER :: m,i,info\r\n\r\nALLOCATE(A_aux(1:n,1:n))\r\nALLOCATE(ipiv(1:n))\r\n\r\nA_aux(1:n,1:n) = A(0:n-1,0:n-1)\r\n\r\nm = n\r\nCALL ZGETRF(m,m,A_aux,m,ipiv,info)\r\n\r\nIF (info /= 0) THEN\r\n\t\r\n\tWRITE (*,*) 'ZGETRF failed in zludcmp, code: ',info\r\n\tSTOP\r\n\r\nEND IF\r\n\r\nldet = 0.d0\r\n\r\nDO i = 1,n\r\n\r\n\tIF (ipiv(i) /= i) ldet = ldet + LOG(-A_aux(i,i))\r\n\tIF (ipiv(i) == i) ldet = ldet + LOG(A_aux(i,i))\r\n\r\nEND DO\r\n\r\ndetratio = exp(ldet-ldetref)\r\n\r\n!det = 1.d0\r\n!\r\n!DO i = 1,n\r\n! \r\n!\tIF (ipiv(i) /= i) det = -det * A_aux(i,i)\r\n!\tIF (ipiv(i) == i) det = det * A_aux(i,i)\r\n!\r\n!END DO\r\n\r\nDEALLOCATE(A_aux,ipiv)\r\n\r\nEND SUBROUTINE zludcmp_ratio\r\n\r\n!************************************************************\r\n\r\nSUBROUTINE zludcmp_log(A,ldet,n)\r\nIMPLICIT NONE\r\n\r\nINTEGER*4, INTENT(IN) :: n\r\nCOMPLEX*16, DIMENSION(0:n-1,0:n-1), INTENT(IN) :: A\r\nCOMPLEX*16, INTENT(OUT) :: ldet\r\n\r\n! ******\r\n! For input variables with zero-based indexing:\r\n! Calculation of log(det(A)) using LU decomposition.\r\n\r\nCOMPLEX*16, DIMENSION(:,:), ALLOCATABLE :: A_aux\r\nINTEGER, DIMENSION(:), ALLOCATABLE :: ipiv\r\nINTEGER :: m,i,info\r\n\r\nALLOCATE(A_aux(1:n,1:n))\r\nALLOCATE(ipiv(1:n))\r\n\r\nA_aux(1:n,1:n) = A(0:n-1,0:n-1)\r\n\r\nm = n\r\nCALL ZGETRF(m,m,A_aux,m,ipiv,info)\r\n\r\nIF (info /= 0) THEN\r\n\t\r\n\tWRITE (*,*) 'ZGETRF failed in zludcmp, code: ',info\r\n\tSTOP\r\n\r\nEND IF\r\n\r\nldet = 0.d0\r\n\r\nDO i = 1,n\r\n\r\n\tIF (ipiv(i) /= i) ldet = ldet + LOG(-A_aux(i,i))\r\n\tIF (ipiv(i) == i) ldet = ldet + LOG(A_aux(i,i))\r\n\r\nEND DO\r\n\r\n!det = 1.d0\r\n!\r\n!DO i = 1,n\r\n! \r\n!\tIF (ipiv(i) /= i) det = -det * A_aux(i,i)\r\n!\tIF (ipiv(i) == i) det = det * A_aux(i,i)\r\n!\r\n!END DO\r\n\r\nDEALLOCATE(A_aux,ipiv)\r\n\r\nEND SUBROUTINE zludcmp_log\r\n\r\n!***********************************************************\r\n\r\nSUBROUTINE zdoinv(A,x,det,n)\r\nIMPLICIT NONE\r\n\r\nINTEGER*4, INTENT(IN) :: n\r\nCOMPLEX*16, DIMENSION(0:n-1,0:n-1), INTENT(IN) :: A\r\nCOMPLEX*16, DIMENSION(0:n-1,0:n-1), INTENT(OUT) :: x\r\nCOMPLEX*16, INTENT(OUT) :: det\r\n\r\n! ******\r\n! For input variables with zero-based indexing:\r\n! Calculation of A^-1 from A*x = I including det(A).\r\n\r\nCOMPLEX*16, DIMENSION(:,:), ALLOCATABLE :: A_aux,B_aux\r\nINTEGER, DIMENSION(:), ALLOCATABLE :: ipiv\r\nINTEGER :: m,nRhs,i,info\r\n\r\nALLOCATE(A_aux(1:n,1:n))\r\nALLOCATE(ipiv(1:n))\r\n\r\nA_aux(1:n,1:n) = A(0:n-1,0:n-1)\r\n\r\nm = n\r\nCALL ZGETRF(m,m,A_aux,m,ipiv,info)\r\n\r\nIF (info /= 0) THEN\r\n\t\r\n\tWRITE (*,*) 'ZGETRF failed in zdoinv, code: ',info\r\n\tSTOP\r\n\r\nEND IF\r\n\r\ndet = 1.d0\r\n\r\nDO i = 1,n\r\n \r\n\tIF (ipiv(i) /= i) det = -det * A_aux(i,i)\r\n\tIF (ipiv(i) == i) det = det * A_aux(i,i)\r\n\r\nEND DO\r\n\r\nnRhs = n\r\nALLOCATE(B_aux(1:n,1:nRhs))\r\nB_aux = 0.d0\r\n\r\nDO i = 1,nRhs\r\n\r\n\tB_aux(i,i) = 1.d0 \r\n\r\nEND DO\r\n\r\nCALL ZGETRS('N',m,nRhs,A_aux,m,ipiv,B_aux,m,info)\r\n\r\nIF (info /= 0) THEN\r\n\t\r\n\tWRITE (*,*) 'ZGETRS failed in zdoinv, code: ',info\r\n\tSTOP\r\n\r\nEND IF\r\n\r\nx(0:n-1,0:n-1) = B_aux(1:n,1:n)\r\n\r\nDEALLOCATE(A_aux,B_aux,ipiv)\r\n\r\nEND SUBROUTINE zdoinv\r\n\r\n!***********************************************************\r\n\r\nSUBROUTINE zdoinv_log(A,x,ldet,n)\r\nIMPLICIT NONE\r\n\r\nINTEGER*4, INTENT(IN) :: n\r\nCOMPLEX*16, DIMENSION(0:n-1,0:n-1), INTENT(IN) :: A\r\nCOMPLEX*16, DIMENSION(0:n-1,0:n-1), INTENT(OUT) :: x\r\nCOMPLEX*16, INTENT(OUT) :: ldet\r\n\r\n! ******\r\n! For input variables with zero-based indexing:\r\n! Calculation of A^-1 from A*x = I including det(A).\r\n\r\nCOMPLEX*16, DIMENSION(:,:), ALLOCATABLE :: A_aux,B_aux\r\nINTEGER, DIMENSION(:), ALLOCATABLE :: ipiv\r\nINTEGER :: m,nRhs,i,info\r\n\r\nALLOCATE(A_aux(1:n,1:n))\r\nALLOCATE(ipiv(1:n))\r\n\r\nA_aux(1:n,1:n) = A(0:n-1,0:n-1)\r\n\r\nm = n\r\nCALL ZGETRF(m,m,A_aux,m,ipiv,info)\r\n\r\nIF (info /= 0) THEN\r\n\t\r\n\tWRITE (*,*) 'ZGETRF failed in zdoinv, code: ',info\r\n\tSTOP\r\n\r\nEND IF\r\n\r\nldet = 0.d0\r\n\r\nDO i = 1,n\r\n\r\n\tIF (ipiv(i) /= i) ldet = ldet + LOG(-A_aux(i,i))\r\n\tIF (ipiv(i) == i) ldet = ldet + LOG(A_aux(i,i))\r\n\r\nEND DO\r\n\r\n! det = 1.d0\r\n!\r\n! DO i = 1,n\r\n! \r\n!\tIF (ipiv(i) /= i) det = -det * A_aux(i,i)\r\n!\tIF (ipiv(i) == i) det = det * A_aux(i,i)\r\n!\r\n! END DO\r\n\r\nnRhs = n\r\nALLOCATE(B_aux(1:n,1:nRhs))\r\nB_aux = 0.d0\r\n\r\nDO i = 1,nRhs\r\n\r\n\tB_aux(i,i) = 1.d0 \r\n\r\nEND DO\r\n\r\nCALL ZGETRS('N',m,nRhs,A_aux,m,ipiv,B_aux,m,info)\r\n\r\nIF (info /= 0) THEN\r\n\t\r\n\tWRITE (*,*) 'ZGETRS failed in zdoinv, code: ',info\r\n\tSTOP\r\n\r\nEND IF\r\n\r\nx(0:n-1,0:n-1) = B_aux(1:n,1:n)\r\n\r\nDEALLOCATE(A_aux,B_aux,ipiv)\r\n\r\nEND SUBROUTINE zdoinv_log\r\n\r\n!*************************************************************\r\n", "meta": {"hexsha": "8a18ed322de08e0d5773048fec8d9b31383f85f9", "size": 5941, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/src/Chapter6-programs/new_solvers.f90", "max_stars_repo_name": "cpmoca/LectureNotesPhysics", "max_stars_repo_head_hexsha": "8e9f8c5d7f163ea10b14002850f7c79acc4513df", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2016-11-22T09:42:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T01:33:46.000Z", "max_issues_repo_path": "doc/src/Chapter6-programs/new_solvers.f90", "max_issues_repo_name": "cpmoca/LectureNotesPhysics", "max_issues_repo_head_hexsha": "8e9f8c5d7f163ea10b14002850f7c79acc4513df", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/src/Chapter6-programs/new_solvers.f90", "max_forks_repo_name": "cpmoca/LectureNotesPhysics", "max_forks_repo_head_hexsha": "8e9f8c5d7f163ea10b14002850f7c79acc4513df", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 25, "max_forks_repo_forks_event_min_datetime": "2016-05-24T22:54:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T00:08:19.000Z", "avg_line_length": 19.5427631579, "max_line_length": 77, "alphanum_fraction": 0.5497391012, "num_tokens": 2139, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436483, "lm_q2_score": 0.8175744695262777, "lm_q1q2_score": 0.7528141272575737}} {"text": " SUBROUTINE MTXMUL33(IFLAG,AMAT,BMAT,CMAT)\n IMPLICIT REAL*8(A-H,O-Z)\nC\nC FOR 3-BY-3 MATRICS AMAT AND BMAT, FORM ONE OF THE PRODUCTS\nC\nC CMAT = AMAT * BMAT\nC CMAT = AMAT * (BMAT-TRANSPOSE)\nC CMAT = (AMAT-TRANSPOSE) * BMAT\nC CMAT = (AMAT-TRANSPOSE) * (BMAT-TRANSPOSE)\nC\nC IN THE CALLING PROGRAM\nC\nC - CMAT MAY BE ONE OF AMAT OR BMAT\nC - AMAT AND BMAT MAY BE THE SAME MATRIX\nC\nC EXAMPLES:\nC CALL MTXMUL33(IFLAG,A,B,C)\nC CALL MTXMUL33(IFLAG,A,A,A)\nC CALL MTXMUL33(IFLAG,A,B,A)\nC CALL MTXMUL33(IFLAG(A,A,C)\nC\nC VAR DIM TYPE I/O DESCRIPTION\nC --- --- ---- --- -----------\nC\nC IFLAG 1 I*4 I FLAG TELLING THE ROUTINE WHICH PRODUCT\nC TO FORM.\nC\nC = 1, CMAT = AMAT * BMAT\nC = 2, CMAT = AMAT * (BMAT-TR)\nC = 3, CMAT = (AMAT-TR) * BMAT\nC = 4, CMAT = (AMAT-TR) * (BMAT-TR)\nC = OTHERWISE, NO PRODUCT FORMED AND\nC CMAT IS FILLED WITH 1.D10 VALUES.\nC THIS IS THE ONLY ERROR INDICATION.\nC\nC AMAT 3,3 R*8 I INPUT MATRIX. \nC\nC BMAT 3,3 R*8 I INPUT MATRIX.\nC\nC CMAT 3,3 R*8 O OUTPUT MATRIX.\nC\nC\nC***********************************************************************\nC\nC CODED BY C PETRUZZO. 5/83.\nC MODIFIED............\nC\nC***********************************************************************\nC\nC\n REAL*8 AMAT(3,3),BMAT(3,3),CMAT(3,3),HOLD(3,3)\nC\n IF(IFLAG.EQ.1) THEN ! AMAT * BMAT\n DO 100 I=1,3\n DO 100 J=1,3\n TEMP=0.D0\n DO 101 K=1,3\n 101 TEMP=TEMP + AMAT(I,K) * BMAT(K,J)\n 100 HOLD(I,J)=TEMP\n GO TO 5000\n END IF\nC\n IF(IFLAG.EQ.2) THEN ! AMAT * BMAT-TR\n DO 200 I=1,3\n DO 200 J=1,3\n TEMP=0.D0\n DO 201 K=1,3\n 201 TEMP=TEMP + AMAT(I,K) * BMAT(J,K)\n 200 HOLD(I,J)=TEMP\n GO TO 5000\n END IF\nC\n IF(IFLAG.EQ.3) THEN ! AMAT-TR * BMAT\n DO 300 I=1,3\n DO 300 J=1,3\n TEMP=0.D0\n DO 301 K=1,3\n 301 TEMP=TEMP + AMAT(K,I) * BMAT(K,J)\n 300 HOLD(I,J)=TEMP\n GO TO 5000\n END IF\nC\n IF(IFLAG.EQ.4) THEN ! AMAT-TR * BMAT-TR\n DO 400 I=1,3\n DO 400 J=1,3\n TEMP=0.D0\n DO 401 K=1,3\n 401 TEMP=TEMP + AMAT(K,I) * BMAT(J,K)\n 400 HOLD(I,J)=TEMP\n GO TO 5000\n END IF\nC\n DO 9900 I=1,3 ! WE GET THIS FAR ONLY WHEN IFLAG IS INVALID.\n DO 9900 J=1,3\n 9900 HOLD(I,J)=1.D10\nC\nC\n 5000 CONTINUE ! LOAD MATRIX TO BE RETURNED\n DO 1000 I=1,3\n DO 1000 J=1,3\n 1000 CMAT(I,J)=HOLD(I,J)\nC\n RETURN\n END\n", "meta": {"hexsha": "77883f56881b6d1be0312fcd91bd316d728644f4", "size": 2953, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "gsc-13083/mtxmul33.for", "max_stars_repo_name": "SteveDoyle2/nasa-cosmic", "max_stars_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-03-14T07:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-16T12:23:17.000Z", "max_issues_repo_path": "gsc-13083/mtxmul33.for", "max_issues_repo_name": "SteveDoyle2/nasa-cosmic", "max_issues_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_issues_repo_licenses": ["BSD-Source-Code"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gsc-13083/mtxmul33.for", "max_forks_repo_name": "SteveDoyle2/nasa-cosmic", "max_forks_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_forks_repo_licenses": ["BSD-Source-Code"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2016-02-12T22:18:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-08T17:46:54.000Z", "avg_line_length": 28.1238095238, "max_line_length": 72, "alphanum_fraction": 0.4351506942, "num_tokens": 1032, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395157060208, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.752778820116455}} {"text": " PROGRAM xqrupdt\r\nC driver for routine qrdupd\r\n INTEGER NP\r\n PARAMETER(NP=20)\r\n INTEGER i,j,k,l,m,n\r\n REAL con,a(NP,NP),au(NP,NP),c(NP),d(NP),q(NP,NP),qt(NP,NP),\r\n * r(NP,NP),s(NP,NP),u(NP),v(NP),x(NP,NP)\r\n CHARACTER txt*3\r\n LOGICAL sing\r\n open(7,file='MATRX1.DAT',status='old')\r\n read(7,*)\r\n10 read(7,*)\r\n read(7,*) n,m\r\n read(7,*)\r\n read(7,*) ((a(k,l), l=1,n), k=1,n)\r\n read(7,*)\r\n read(7,*) ((s(k,l), k=1,n), l=1,m)\r\nC print out a-matrix for comparison with product of Q and R\r\nC decomposition matrices.\r\n write(*,*) 'Original matrix:'\r\n do 11 k=1,n\r\n write(*,'(1x,6f12.6)') (a(k,l), l=1,n)\r\n11 continue\r\nC updated matrix we'll use later\r\n do 13 k=1,n\r\n do 12 l=1,n\r\n au(k,l)=a(k,l)+s(k,1)*s(l,2)\r\n12 continue\r\n13 continue\r\nC perform the initial decomposition\r\n call qrdcmp(a,n,NP,c,d,sing)\r\n if (sing) write(*,*) 'Singularity in QR decomposition.'\r\nC find the Q and R matrices\r\n do 15 k=1,n\r\n do 14 l=1,n\r\n if (l.gt.k) then\r\n r(k,l)=a(k,l)\r\n q(k,l)=0.0\r\n else if (l.lt.k) then\r\n r(k,l)=0.0\r\n q(k,l)=0.0\r\n else\r\n r(k,l)=d(k)\r\n q(k,l)=1.0\r\n endif\r\n14 continue\r\n15 continue\r\n do 23 i=n-1,1,-1\r\n con=0.0\r\n do 16 k=i,n\r\n con=con+a(k,i)**2\r\n16 continue\r\n con=con/2.0\r\n do 19 k=i,n\r\n do 18 l=i,n\r\n qt(k,l)=0.0\r\n do 17 j=i,n\r\n qt(k,l)=qt(k,l)+q(j,l)*a(k,i)*a(j,i)/con\r\n17 continue\r\n18 continue\r\n19 continue\r\n do 22 k=i,n\r\n do 21 l=i,n\r\n q(k,l)=q(k,l)-qt(k,l)\r\n21 continue\r\n22 continue\r\n23 continue\r\nC compute product of Q and R matrices for comparison with original matrix.\r\n do 26 k=1,n\r\n do 25 l=1,n\r\n x(k,l)=0.0\r\n do 24 j=1,n\r\n x(k,l)=x(k,l)+q(k,j)*r(j,l)\r\n24 continue\r\n25 continue\r\n26 continue\r\n write(*,*) 'Product of Q and R matrices:'\r\n do 27 k=1,n\r\n write(*,'(1x,6f12.6)') (x(k,l), l=1,n)\r\n27 continue\r\n write(*,*) 'Q matrix of the decomposition:'\r\n do 28 k=1,n\r\n write(*,'(1x,6f12.6)') (q(k,l), l=1,n)\r\n28 continue\r\n write(*,*) 'R matrix of the decomposition:'\r\n do 29 k=1,n\r\n write(*,'(1x,6f12.6)') (r(k,l), l=1,n)\r\n29 continue\r\nC Q transpose\r\n do 32 k=1,n\r\n do 31 l=1,n\r\n qt(k,l)=q(l,k)\r\n31 continue\r\n32 continue\r\n do 34 k=1,n\r\n v(k)=s(k,2)\r\n u(k)=0.0\r\n do 33 l=1,n\r\n u(k)=u(k)+qt(k,l)*s(l,1)\r\n33 continue\r\n34 continue\r\n call qrupdt(r,qt,n,NP,u,v)\r\n do 37 k=1,n\r\n do 36 l=1,n\r\n x(k,l)=0.0\r\n do 35 j=1,n\r\n x(k,l)=x(k,l)+qt(j,k)*r(j,l)\r\n35 continue\r\n36 continue\r\n37 continue\r\n write(*,*) 'Updated matrix:'\r\n do 38 k=1,n\r\n write(*,'(1x,6f12.6)') (au(k,l), l=1,n)\r\n38 continue\r\n write(*,*) 'Product of new Q and R matrices:'\r\n do 39 k=1,n\r\n write(*,'(1x,6f12.6)') (x(k,l), l=1,n)\r\n39 continue\r\n write(*,*) 'New Q matrix'\r\n do 41 k=1,n\r\n write(*,'(1x,6f12.6)') (qt(l,k), l=1,n)\r\n41 continue\r\n write(*,*) 'New R matrix'\r\n do 42 k=1,n\r\n write(*,'(1x,6f12.6)') (r(k,l), l=1,n)\r\n42 continue\r\n write(*,*) '***********************************'\r\n write(*,*) 'Press RETURN for next problem:'\r\n read(*,*)\r\n read(7,'(a3)') txt\r\n if (txt.ne.'END') goto 10\r\n close(7)\r\n END\r\n", "meta": {"hexsha": "1577554717f7800268377cdd5ab42d523f77e4f1", "size": 3745, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xqrupdt.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xqrupdt.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xqrupdt.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.947761194, "max_line_length": 79, "alphanum_fraction": 0.4349799733, "num_tokens": 1306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951643678381, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.7527788172826054}} {"text": "C\n SUBROUTINE QL ( M, ME, MMAX, N, NMAX, \n / MNN, C, D, A, B, \n / XL, XU, X, U, EPS, \n / MODE, IOUT, IFAIL, IPRINT, WAR, \n / LWAR, IWAR, LIWAR)\nC\nC*********************************************************************\nC\nC\nC AN IMPLEMENTATION OF A PRIMAL-DUAL QUADRATIC PROGRAMMING\nC\nC METHOD \nC\nC\nC The Problem:\nC \nC The code solves the strictly convex quadratic program\nC\nC minimize 1/2 x^ C x + c^x\nC subject to a_j^x + b_j = 0 , j=1,...,m_e\nC a_j^x + b_j >= 0 , j=m+1,...,m\nC x_l <= x <= x_u\nC\nC with an n by n positive definite matrix C, an n-dimensional vector d,\nC an m by n matrix A=(a_1,...,a_m)^, and an m-vector b. \nC\nC\nC\nC The Numerical Algorithm:\nC\nC The subroutine reorganizes some data to solve the quadratic program\nC by a modification or a code going back to Powell (1983). The numerical \nC algorithm is the primal-dual method of Goldfarb and Idnani (1983).\nC First, a solution of the unconstrained quadratic program is found\nC proceeding from a Cholesky decomposition of C. Subsequently, violated\nC constraints are added successively. Constraints no longer considered \nC as active ones, are dropped. Numerically stable orthogonal \nC decomposition are applied to find intermediate minima on hyperplane \nC of the active constraints. \nC\nC\nC\nC Usage:\nC\nC CALL QL ( M, ME, MMAX, N, NMAX, \nC / MNN, C, D, A, B, \nC / XL, XU, X, U, EPS, \nC / MODE, IOUT, IFAIL, IPRINT, WAR, \nC / LWAR, IWAR, LIWAR)\nC\nC\nC\nC Definition of the parameters:\nC\nC M : Number of constraints.\nC ME : Number of equality constraints.\nC MMAX : Row dimension of array A containing linear constraints.\nC MMAX must be at least one and greater or equal to M.\nC N : Number of optimization variables.\nC NMAX : Row dimension of C. NMAX must be at least one and greater\nC or equal to N.\nC MNN : Must be equal to M+N+N when calling QL, dimension of U.\nC C(NMAX,NMAX): Objective function matrix which should be symmetric \nC and positive definite. If MODE=0, C is supposed to be the\nC upper triangular factor of a Cholesky decomposition of C.\nC D(NMAX) : Contains the constant vector of the quadratic objective\nC function.\nC A(MMAX,NMAX): Matrix of the linear constraints, first ME rows for\nC equality, then M-ME rows for inequality constraints.\nC B(MMAX) : Constant values of linear constraints in the same order.\nC XL(N),XU(N) : On input, the one-dimensional arrays XL and XU must\nC contain the upper and lower bounds of the variables.\nC X(N) : On return, X contains the optimal solution.\nC U(MNN) : On return, U contains the multipliers subject to the \nC linear constraints and bounds. The first M locations \nC contain the multipliers of the M linear constraints, the \nC subsequent N locations the multipliers of the lower \nC bounds, and the final N locations the multipliers of the\nC upper bounds. At the optimal solution, all multipliers \nC with respect to inequality constraints should be \nC nonnegative.\nC EPS : The user has to specify the desired final accuracy\nC (e.g. 1.0D-12). The parameter value should not be smaller \nC than the underlying machine precision.\nC MODE : MODE=0 - The user provides an initial Cholesky factorization\nC of C, stored in the upper triangular part of the\nC array C.\nC MODE=1 - A Cholesky decomposition to get the first \nC unconstrained minimizer, is computed internally.\nC IOUT : Integer indicating the desired output unit number, i.e. all\nC write-statements start with 'WRITE(IOUT,... '.\nC IFAIL : The parameter shows the reason for terminating a solution\nC process. On return, IFAIL could get the following values:\nC IFAIL=0 : The optimality conditions are satisfied.\nC IFAIL=1 : The algorithm has been stopped after too many\nC MAXIT iterations (40*(N+M)).\nC IFAIL=2 : Termination accuracy insufficient to satisfy \nC convergence criterion. \nC IFAIL=3 : Internal inconsistency of QL, division by zero.\nC IFAIL=4 : Numerical instability prevents successful termination.\nC Use tolerance specified in WAR(1) for a restart.\nC IFAIL=5 : Length of a working array is too short. \nC IFAIL>100: Constraints are inconsistent and IFAIL=100+ICON,\nC where ICON denotes a constraint causing the conflict.\nC IPRINT : Specification of the desired output level.\nC IPRINT=0 : No output of the program.\nC IPRINT=1 : Only a final error message is given.\nC WAR(LWAR),LWAR : WAR is a real working array of length LWAR. LWAR \nC must be at least 3*NMAX*NMAX/2 + 10*NMAX + MMAX + M + 1.\nC IWAR(LIWAR),LIWAR : The user has to provide working space for an\nC integer array. LIWAR must be at least N.\nC\nC\nC\nC Copyright(C): Klaus Schittkowski, Department of Computer Science,\nC University of Bayreuth, D-95440 Bayreuth, Germany,\nC (1987-2010)\nC\nC\nC\nC Reference: M.J.D. Powell: ZQPCVX, A FORTRAN Subroutine for Convex\nC Programming, Report DAMTP/1983/NA17, University of \nC Cambridge, England, 1983\nC\nC D. Goldfarb, A. Idnani (1983): A numerically stable \nC method for solving strictly convex quadratic programs,\nC Mathematical Programming, Vol. 27, 1-33\nC\nC K. Schittkowski (2007): QL: A Fortran code for convex\nC quadratic programming - user's guide, Report, Department \nC of Computer Science, University of Bayreuth\nC\nC\nC\nC Version: 1.0 (Mar, 1987) - first implementation\nC 1.8 (Oct, 2002) - new tolerances \nC 2.0 (Apr, 2003) - parameter list, documentation\nC 2.1 (Sep, 2004) - new error message\nC 2.11 (Jul, 2005) - error message (LWAR)\nC 2.12 (Jul, 2007) - parameter declarations\nC 2.13 (Sep, 2007) - test for division by zero\nC 2.14 (Feb, 2009) - some if-statements changed\nC 2.15 (May, 2009) - comments\nC 2.16 (Jun, 2009) - IFAIL=4 introduced \nC 2.17 (Apr, 2010) - comments\nC 2.2 (Sep, 2010) - division by zero \nC\nC*********************************************************************\nC\n IMPLICIT NONE\n INTEGER NMAX,MMAX,N,MNN,LWAR,LIWAR\n DIMENSION C(NMAX,N),D(N),A(MMAX,N),B(MMAX),\n / XL(N),XU(N),X(N),U(MNN),WAR(LWAR),IWAR(LIWAR)\n DOUBLE PRECISION C,D,A,B,X,XL,XU,U,WAR,DIAG,ZERO,\n / EPS,QPEPS\n INTEGER M,ME,IOUT,MODE,IFAIL,IPRINT,IWAR,INW1,INW2,IN,J,LW,MN,I,\n / IDIAG,INFO,NACT,MAXIT\n LOGICAL LQL\n INTRINSIC INT\n EXTERNAL QL0002\nC\nC CONSTANT DATA\nC\n LQL=.FALSE.\n IF (MODE.EQ.1) LQL=.TRUE.\n ZERO=0.0D+0\n MAXIT=40*(M+N)\n QPEPS=EPS\n INW1=1\n INW2=INW1+MMAX\nC\nC PREPARE PROBLEM DATA FOR EXECUTION\nC\n IF (M.GT.0) THEN\n IN=INW1\n DO J=1,M\n WAR(IN)=-B(J)\n IN=IN+1\n ENDDO\n ENDIF \n LW=3*NMAX*NMAX/2 + 10*NMAX + M\n IF ((INW2+LW).GT.LWAR) GOTO 80\n IF (LIWAR.LT.N) GOTO 81\n IF (MNN.LT.M+N+N) GOTO 82\n MN=M+N\nC\nC CALL OF QL0002\nC\n CALL QL0002(N,M,ME,MMAX,MN,NMAX,LQL,A,WAR(INW1),\n / D,C,XL,XU,X,NACT,IWAR,MAXIT,QPEPS,INFO,DIAG,\n / WAR(INW2),LW)\nC\nC TEST OF MATRIX CORRECTIONS\nC\n IF ((INFO.EQ.3).OR.(INFO.EQ.4)) THEN\n DO I=1,N\n X(I) = 0.0D0\n ENDDO\n ENDIF \n IFAIL=0\n IF (INFO.EQ.1) GOTO 40\n IF (INFO.EQ.2) GOTO 90\n IF (INFO.EQ.3) GOTO 83\n IF (INFO.EQ.4) GOTO 95\n IDIAG=0\n IF ((DIAG.GT.ZERO).AND.(DIAG.LT.1000.0D0)) IDIAG=INT(DIAG)\n IF ((IPRINT.GT.0).AND.(IDIAG.GT.0))\n / WRITE(IOUT,1000) IDIAG\n IF (INFO .LT. 0) GOTO 70\nC\nC REORDER MULTIPLIER\nC\n DO 50 J=1,MNN\n 50 U(J)=ZERO\n IN=INW2-1\n IF (NACT.EQ.0) GOTO 30\n DO 60 I=1,NACT\n J=IWAR(I)\n U(J)=WAR(IN+I)\n 60 CONTINUE\n 30 CONTINUE\n RETURN\nC\nC ERROR MESSAGES\nC\n 70 IFAIL=-INFO+100\n IF ((IPRINT.GT.0).AND.(NACT.GT.0))\n / WRITE(IOUT,1100) -INFO,(IWAR(I),I=1,NACT)\n RETURN\n 80 IFAIL=5\n IF (IPRINT .GT. 0) WRITE(IOUT,1200)INW2+LW,LWAR\n RETURN\n 81 IFAIL=5\n IF (IPRINT .GT. 0) WRITE(IOUT,1210)\n RETURN\n 82 IFAIL=5\n IF (IPRINT .GT. 0) WRITE(IOUT,1220)\n RETURN\n 83 IFAIL=3\n IF (IPRINT .GT. 0) WRITE(IOUT,1230)\n RETURN\n 40 IFAIL=1\n IF (IPRINT.GT.0) WRITE(IOUT,1300) MAXIT\n RETURN\n 90 IFAIL=2\n IF (IPRINT.GT.0) WRITE(IOUT,1400)\n RETURN\n 95 IFAIL=4\n IF (IPRINT.GT.0) WRITE(IOUT,1500) WAR(1) \n RETURN\nC\nC FORMAT-INSTRUCTIONS\nC\n 1000 FORMAT(/8X,'*** ERROR (QL): Matrix G was enlarged',I3,\n / '-times by unit matrix!')\n 1100 FORMAT(/8X,'*** ERROR (QL): Constraint ',I5,\n / ' not consistent to ',/,(10X,10I5))\n 1200 FORMAT(/8X,'*** ERROR (QL): LWAR too small! Should be at least ',\n / I8,', but only ',I8,' is available.')\n 1210 FORMAT(/8X,'*** ERROR (QL): LIWAR too small!')\n 1220 FORMAT(/8X,'*** ERROR (QL): MNN too small!')\n 1230 FORMAT(/8X,'*** ERROR (QL): Internal error, division by zero!')\n 1300 FORMAT(/8X,'*** ERROR (QL): Too many iterations (more than',I6,\n / ')')\n 1400 FORMAT(/8X,'*** ERROR (QL): Accuracy insufficient to attain ',\n / 'convergence!')\n 1500 FORMAT(/8X,'*** ERROR (QL): Accuracy too small to detect ',\n / 'feasibility! Restart with tolerance ',d12.4,\n / ' in WA(1)!') \n END\nC\n SUBROUTINE QL0002(N,M,MEQ,MMAX,MN,NMAX,LQL,A,B,GRAD,G,\n / XL,XU,X,NACT,IACT,MAXIT,VSMALL,INFO,DIAG,W,LW)\nC\nC**************************************************************************\nC\nC\nC THIS SUBROUTINE SOLVES THE QUADRATIC PROGRAMMING PROBLEM \nC\nC MINIMIZE GRAD'*X + 0.5 * X*G*X\nC SUBJECT TO A(K)*X = B(K) K=1,2,...,MEQ,\nC A(K)*X >= B(K) K=MEQ+1,...,M,\nC XL <= X <= XU\nC\nC THE QUADRATIC PROGRAMMING METHOD PROCEEDS FROM AN INITIAL CHOLESKY-\nC DECOMPOSITION OF THE OBJECTIVE FUNCTION MATRIX, TO CALCULATE THE\nC UNIQUELY DETERMINED MINIMIZER OF THE UNCONSTRAINED PROBLEM. \nC SUCCESSIVELY ALL VIOLATED CONSTRAINTS ARE ADDED TO A WORKING SET \nC AND A MINIMIZER OF THE OBJECTIVE FUNCTION SUBJECT TO ALL CONSTRAINTS\nC IN THIS WORKING SET IS COMPUTED. IT IS POSSIBLE THAT CONSTRAINTS\nC HAVE TO LEAVE THE WORKING SET.\nC\nC\nC DESCRIPTION OF PARAMETERS:\nC\nC N : IS THE NUMBER OF VARIABLES.\nC M : TOTAL NUMBER OF CONSTRAINTS.\nC MEQ : NUMBER OF EQUALITY CONTRAINTS.\nC MMAX : ROW DIMENSION OF A, DIMENSION OF B. MMAX MUST BE AT\nC LEAST ONE AND GREATER OR EQUAL TO M.\nC MN : MUST BE EQUAL M + N.\nC NMAX : ROW DIEMSION OF G. MUST BE AT LEAST N.\nC LQL : DETERMINES INITIAL DECOMPOSITION.\nC LQL = .FALSE. : THE UPPER TRIANGULAR PART OF THE MATRIX G\nC CONTAINS INITIALLY THE CHOLESKY-FACTOR OF A SUITABLE\nC DECOMPOSITION.\nC LQL = .TRUE. : THE INITIAL CHOLESKY-FACTORISATION OF G IS TO BE\nC PERFORMED BY THE ALGORITHM.\nC A(MMAX,NMAX) : A IS A MATRIX WHOSE COLUMNS ARE THE CONSTRAINTS NORMALS.\nC B(MMAX) : CONTAINS THE RIGHT HAND SIDES OF THE CONSTRAINTS.\nC GRAD(N) : CONTAINS THE OBJECTIVE FUNCTION VECTOR GRAD.\nC G(NMAX,N): CONTAINS THE SYMMETRIC OBJECTIVE FUNCTION MATRIX.\nC XL(N), XU(N): CONTAIN THE LOWER AND UPPER BOUNDS FOR X.\nC X(N) : VECTOR OF VARIABLES.\nC NACT : FINAL NUMBER OF ACTIVE CONSTRAINTS.\nC IACT(K) (K=1,2,...,NACT): INDICES OF THE FINAL ACTIVE CONSTRAINTS.\nC INFO : REASON FOR THE RETURN FROM THE SUBROUTINE.\nC INFO = 0 : CALCULATION WAS TERMINATED SUCCESSFULLY.\nC INFO = 1 : MAXIMUM NUMBER OF ITERATIONS ATTAINED.\nC INFO = 2 : ACCURACY IS INSUFFICIENT TO MAINTAIN INCREASING\nC FUNCTION VALUES.\nC INFO = 3 : INTERNAL INCONSISTENCY OF QP, DIVISION BY ZERO.\nC INFO = 4 : ACCURACY TOO SMALL FOR SUCESSFUL TERMINATION.\nC INFO < 0 : THE CONSTRAINT WITH INDEX ABS(INFO) AND THE CON-\nC STRAINTS WHOSE INDICES ARE IACT(K), K=1,2,...,NACT,\nC ARE INCONSISTENT.\nC MAXIT : MAXIMUM NUMBER OF ITERATIONS.\nC VSMALL : REQUIRED ACCURACY TO BE ACHIEVED (E.G. IN THE ORDER OF THE \nC MACHINE PRECISION FOR SMALL AND WELL-CONDITIONED PROBLEMS).\nC DIAG : ON RETURN DIAG IS EQUAL TO THE MULTIPLE OF THE UNIT MATRIX\nC THAT WAS ADDED TO G TO ACHIEVE POSITIVE DEFINITENESS.\nC W(LW) : THE ELEMENTS OF W(.) ARE USED FOR WORKING SPACE. THE LENGTH\nC OF W MUST NOT BE LESS THAN (1.5*NMAX*NMAX + 10*NMAX + M).\nC WHEN INFO = 0 ON RETURN, THE LAGRANGE MULTIPLIERS OF THE\nC FINAL ACTIVE CONSTRAINTS ARE HELD IN W(K), K=1,2,...,NACT.\nC THE VALUES OF N, M, MEQ, MMAX, MN, AND NMAX AND THE ELEMENTS OF\nC A, B, GRAD AND G ARE NOT ALTERED.\nC\nC THE FOLLOWING INTEGERS ARE USED TO PARTITION W:\nC THE FIRST N ELEMENTS OF W HOLD LAGRANGE MULTIPLIER ESTIMATES.\nC W(IWZ+I+(N-1)*J) HOLDS THE MATRIX ELEMENT Z(I,J).\nC W(IWR+I+0.5*J*(J-1)) HOLDS THE UPPER TRIANGULAR MATRIX\nC ELEMENT R(I,J). THE SUBSEQUENT N COMPONENTS OF W MAY BE\nC TREATED AS AN EXTRA COLUMN OF R(.,.).\nC W(IWW-N+I) (I=1,2,...,N) ARE USED FOR TEMPORARY STORAGE.\nC W(IWW+I) (I=1,2,...,N) ARE USED FOR TEMPORARY STORAGE.\nC W(IWD+I) (I=1,2,...,N) HOLDS G(I,I) DURING THE CALCULATION.\nC W(IWX+I) (I=1,2,...,N) HOLDS VARIABLES THAT WILL BE USED TO\nC TEST THAT THE ITERATIONS INCREASE THE OBJECTIVE FUNCTION.\nC W(IWA+K) (K=1,2,...,M) USUALLY HOLDS THE RECIPROCAL OF THE\nC LENGTH OF THE K-TH CONSTRAINT, BUT ITS SIGN INDICATES\nC WHETHER THE CONSTRAINT IS ACTIVE.\nC\nC \nC AUTHOR: K. SCHITTKOWSKI,\nC MATHEMATISCHES INSTITUT,\nC UNIVERSITAET BAYREUTH,\nC 8580 BAYREUTH,\nC GERMANY, F.R.\nC\nC AUTHOR OF ORIGINAL VERSION:\nC M.J.D. POWELL, DAMTP,\nC UNIVERSITY OF CAMBRIDGE, SILVER STREET\nC CAMBRIDGE,\nC ENGLAND\nC\nC\nC REFERENCE: M.J.D. POWELL: ZQPCVX, A FORTRAN SUBROUTINE FOR CONVEX\nC PROGRAMMING, REPORT DAMTP/1983/NA17, UNIVERSITY OF\nC CAMBRIDGE, ENGLAND, 1983.\nC\nC\nC VERSION : 2.0 (MARCH, 1987)\nC\nC\nC*************************************************************************\nC\n IMPLICIT NONE\n INTEGER MMAX,NMAX,N,LW,NFLAG,IWWN\n DIMENSION A(MMAX,N),B(MMAX),GRAD(N),G(NMAX,N),X(N),IACT(N),\n / W(LW),XL(N),XU(N)\n INTEGER M,MEQ,MN,NACT,IACT,INFO,MAXIT\n DOUBLE PRECISION CVMAX,DIAG,DIAGR,FDIFF,FDIFFA,GA,GB,PARINC,\n / PARNEW,RATIO,RES,STEP,SUM,SUMX,SUMY,SUMA,SUMB,SUMC,\n / TEMP,TEMPA,VSMALL,XMAG,XMAGR,ZERO,ONE,TWO,ONHA,VFACT,\n / MINCV\n DOUBLE PRECISION A,B,G,GRAD,W,X,XL,XU\n DOUBLE PRECISION DMAX1,DSQRT,DABS,DMIN1\n INTEGER MAX0,MIN0\n INTRINSIC DMAX1,DSQRT,DABS,DMIN1,MAX0,MIN0\n INTEGER IWZ,IWR,IWW,IWD,IWA,IFINC,KFINC,I,IA,ID,II,IR,IRA,K,\n / IRB,J,NM,IZ,IZA,ITERC,ITREF,JFINC,IFLAG,IWS,IS,K1,IW,\n / KK,IL,IU,JU,KFLAG,LFLAG,JFLAG,KDROP,NU,MFLAG,\n / KNEXT,IX,IWX,IWY,IY,JL\n LOGICAL LQL,LOWER\nC\nC\tINITIALIZE VARIABLES THAT MAY BE UNINITIALIZED OTHERWISE\nC\n\tNFLAG = 0\n\tPARINC = 0.0D0\n\tPARNEW = 0.0D0\n\tRATIO = 0.0D0\n\tRES = 0.0D0\n\tSTEP = 0.0D0\n\tSUMY = 0.0D0\n\tTEMP = 0.0D0\n\tJ = 0\n\tJFLAG = 0\n\tKDROP = 0\n\tNU = 0\n\tMFLAG = 0\n\tKNEXT = 0\nC\nC INITIAL ADDRESSES\nC\n IWZ=NMAX\n IWR=IWZ+NMAX*NMAX\n IWW=IWR+(NMAX*(NMAX+3))/2\n IWD=IWW+NMAX\n IWX=IWD+NMAX\n IWA=IWX+NMAX\nC\nC SET SOME CONSTANTS.\nC\n ZERO=0.D+0\n ONE=1.D+0\n TWO=2.D+0\n ONHA=1.5D+0\n VFACT=1.D+0\n MINCV=1.D30\nC\nC SET SOME PARAMETERS.\nC NUMBER LESS THAN VSMALL ARE ASSUMED TO BE NEGLIGIBLE.\nC THE MULTIPLE OF I THAT IS ADDED TO G IS AT MOST DIAGR TIMES\nC THE LEAST MULTIPLE OF I THAT GIVES POSITIVE DEFINITENESS.\nC X IS RE-INITIALISED IF ITS MAGNITUDE IS REDUCED BY THE\nC FACTOR XMAGR.\nC A CHECK IS MADE FOR AN INCREASE IN F EVERY IFINC ITERATIONS,\nC AFTER KFINC ITERATIONS ARE COMPLETED.\nC\n DIAGR=TWO\n DIAG=ZERO\n XMAGR=1.0D-2\n IFINC=3\n KFINC=MAX0(10,N)\nC\nC FIND THE RECIPROCALS OF THE LENGTHS OF THE CONSTRAINT NORMALS.\nC RETURN IF A CONSTRAINT IS INFEASIBLE DUE TO A ZERO NORMAL.\nC\n NACT=0\n IF (M .LE. 0) GOTO 45\n DO 40 K=1,M\n SUM=ZERO\n DO I=1,N\n SUM=SUM+A(K,I)**2\n ENDDO\n IF (SUM .GT. ZERO) GOTO 20\n IF (B(K) .EQ. ZERO) GOTO 30\n INFO=-K\n IF (K .LE. MEQ) GOTO 730\nc IF (B(K)) 30,30,730\n IF (B(K) .LE. ZERO) THEN\n GOTO 30\n ELSE\n GOTO 730\n ENDIF \n 20 SUM=ONE/DSQRT(SUM)\n 30 IA=IWA+K\n W(IA)=SUM\n 40 CONTINUE \n 45 DO K=1,N\n IA=IWA+M+K\n W(IA)=ONE\n ENDDO\nC\nC IF NECESSARY INCREASE THE DIAGONAL ELEMENTS OF G.\nC\n IF (.NOT. LQL) GOTO 165\n DO 60 I=1,N\n ID=IWD+I\n W(ID)=G(I,I)\n DIAG=DMAX1(DIAG,VSMALL-W(ID))\n IF (I .EQ. N) GOTO 60\n II=I+1\n DO J=II,N\n GA=-DMIN1(W(ID),G(J,J))\n GB=DABS(W(ID)-G(J,J))+DABS(G(I,J))\n IF (GB .GT. ZERO) GA=GA+G(I,J)**2/GB\n DIAG=DMAX1(DIAG,GA)\n ENDDO\n 60 CONTINUE\n IF (DIAG .LE. ZERO) GOTO 90\n 70 DIAG=DIAGR*DIAG\n DO I=1,N\n ID=IWD+I\n G(I,I)=DIAG+W(ID)\n ENDDO\nC\nC FORM THE CHOLESKY FACTORISATION OF G. THE TRANSPOSE\nC OF THE FACTOR WILL BE PLACED IN THE R-PARTITION OF W.\nC\n 90 IR=IWR \n DO 130 J=1,N\n IRA=IWR\n IRB=IR+1\n DO 120 I=1,J\n TEMP=G(I,J)\n IF (I .EQ. 1) GOTO 110\n DO 100 K=IRB,IR\n IRA=IRA+1\n TEMP=TEMP-W(K)*W(IRA)\n 100 CONTINUE\n 110 IR=IR+1\n IRA=IRA+1\n IF (I .LT. J) W(IR)=TEMP/W(IRA)\n 120 CONTINUE\n IF (TEMP .LT. VSMALL) GOTO 140\n W(IR)=DSQRT(TEMP)\n 130 CONTINUE\n GOTO 170\nC\nC INCREASE FURTHER THE DIAGONAL ELEMENT OF G.\nC\n 140 W(J)=ONE\n SUMX=ONE\n K=J\n 150 SUM=ZERO\n IRA=IR-1\n DO I=K,J\n SUM=SUM-W(IRA)*W(I)\n IRA=IRA+I\n ENDDO\n IR=IR-K\n K=K-1\n IF (K.LT.1) GOTO 165\nC%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \n IF (W(IR).NE.0.0D0) THEN\n W(K)=SUM/W(IR)\n ELSE\n W(K)=1.0D30\n ENDIF \nC%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \n SUMX=SUMX+W(K)**2\n IF (K .GE. 2) GOTO 150\n DIAG=DIAG+VSMALL-TEMP/SUMX\n GOTO 70\nC\nC STORE THE CHOLESKY FACTORISATION IN THE R-PARTITION\nC OF W.\nC\n 165 CONTINUE\n IR=IWR\n DO I=1,N\n DO J=1,I\n IR=IR+1\n W(IR)=G(J,I)\n ENDDO\n ENDDO \nC\nC SET Z THE INVERSE OF THE MATRIX IN R.\nC\n 170 NM=N-1\n DO 220 I=1,N\n IZ=IWZ+I\n IF (I .GT. 1) THEN\n DO J=2,I\n W(IZ)=ZERO\n IZ=IZ+N\n ENDDO\n ENDIF \n IR=IWR+(I+I*I)/2\n W(IZ)=ONE/W(IR)\n IF (I .EQ. N) GOTO 220\n IZA=IZ\n DO 210 J=I,NM\n IR=IR+I\n SUM=ZERO\n DO K=IZA,IZ,N\n SUM=SUM+W(K)*W(IR)\n IR=IR+1\n ENDDO\n IZ=IZ+N\n 210 W(IZ)=-SUM/W(IR)\n 220 CONTINUE\nC\nC SET THE INITIAL VALUES OF SOME VARIABLES.\nC ITERC COUNTS THE NUMBER OF ITERATIONS.\nC ITREF IS SET TO ONE WHEN ITERATIVE REFINEMENT IS REQUIRED.\nC JFINC INDICATES WHEN TO TEST FOR AN INCREASE IN F.\nC\n ITERC=1\n ITREF=0\n JFINC=-KFINC\nC\nC SET X TO ZERO AND SET THE CORRESPONDING RESIDUALS OF THE\nC KUHN-TUCKER CONDITIONS.\nC\n 230 IFLAG=1\n IWS=IWW-N\n DO 240 I=1,N\n X(I)=ZERO\n IW=IWW+I\n W(IW)=GRAD(I)\n IF (I .GT. NACT) GOTO 240\n W(I)=ZERO\n IS=IWS+I\n K=IACT(I)\n IF (K .LE. M) GOTO 235\n IF (K .GT. MN) GOTO 234\n K1=K-M\n W(IS)=XL(K1)\n GOTO 240\n 234 K1=K-MN\n W(IS)=-XU(K1)\n GOTO 240\n 235 W(IS)=B(K)\n 240 CONTINUE\n XMAG=ZERO\n VFACT=1.D+0\nC IF (NACT) 340,340,280\n IF (NACT .LE. 0) THEN\n GOTO 340\n ELSE\n GOTO 280\n ENDIF \nC\nC SET THE RESIDUALS OF THE KUHN-TUCKER CONDITIONS FOR GENERAL X.\nC\n 250 IFLAG=2\n IWS=IWW-N\n DO 260 I=1,N\n IW=IWW+I\n W(IW)=GRAD(I)\n IF (LQL) GOTO 259\n ID=IWD+I\n W(ID)=ZERO\n DO 251 J=I,N\n 251 W(ID)=W(ID)+G(I,J)*X(J)\n DO 252 J=1,I\n ID=IWD+J\n 252 W(IW)=W(IW)+G(J,I)*W(ID)\n GOTO 260\n 259 DO 261 J=1,N\n 261 W(IW)=W(IW)+G(I,J)*X(J)\n 260 CONTINUE\n IF (NACT .EQ. 0) GOTO 340\n DO 270 K=1,NACT\n KK=IACT(K)\n IS=IWS+K\n IF (KK .GT. M) GOTO 265\n W(IS)=B(KK)\n DO 264 I=1,N\n IW=IWW+I\n W(IW)=W(IW)-W(K)*A(KK,I)\n 264 W(IS)=W(IS)-X(I)*A(KK,I)\n GOTO 270\n 265 IF (KK .GT. MN) GOTO 266\n K1=KK-M\n IW=IWW+K1\n W(IW)=W(IW)-W(K)\n W(IS)=XL(K1)-X(K1)\n GOTO 270\n 266 K1=KK-MN\n IW=IWW+K1\n W(IW)=W(IW)+W(K)\n W(IS)=-XU(K1)+X(K1)\n 270 CONTINUE\nC\nC PRE-MULTIPLY THE VECTOR IN THE S-PARTITION OF W BY THE\nC INVERS OF R TRANSPOSE.\nC\n 280 IR=IWR\nC IP=IWW+1\nC IPP=IWW+N\n IL=IWS+1\n IU=IWS+NACT\n DO 310 I=IL,IU\n SUM=ZERO\n IF (I .EQ. IL) GOTO 300\n JU=I-1\n DO 290 J=IL,JU\n IR=IR+1\n 290 SUM=SUM+W(IR)*W(J)\n 300 IR=IR+1\n 310 W(I)=(W(I)-SUM)/W(IR)\nC\nC SHIFT X TO SATISFY THE ACTIVE CONSTRAINTS AND MAKE THE\nC CORRESPONDING CHANGE TO THE GRADIENT RESIDUALS.\nC\n DO 330 I=1,N\n IZ=IWZ+I\n SUM=ZERO\n DO 320 J=IL,IU\n SUM=SUM+W(J)*W(IZ)\n 320 IZ=IZ+N\n X(I)=X(I)+SUM\n IF (LQL) GOTO 329\n ID=IWD+I\n W(ID)=ZERO\n DO 321 J=I,N\n 321 W(ID)=W(ID)+G(I,J)*SUM\n IW=IWW+I\n DO 322 J=1,I\n ID=IWD+J\n 322 W(IW)=W(IW)+G(J,I)*W(ID)\n GOTO 330\n 329 DO 331 J=1,N\n IW=IWW+J\n 331 W(IW)=W(IW)+SUM*G(I,J)\n 330 CONTINUE\nC\nC FORM THE SCALAR PRODUCT OF THE CURRENT GRADIENT RESIDUALS\nC WITH EACH COLUMN OF Z.\nC\n 340 KFLAG=1\n GOTO 930\n 350 IF (NACT .EQ. N) GOTO 380\nC\nC SHIFT X SO THAT IT SATISFIES THE REMAINING KUHN-TUCKER\nC CONDITIONS.\nC\n IL=IWS+NACT+1\n IZA=IWZ+NACT*N\n DO 370 I=1,N\n SUM=ZERO\n IZ=IZA+I\n DO 360 J=IL,IWW\n SUM=SUM+W(IZ)*W(J)\n 360 IZ=IZ+N\n 370 X(I)=X(I)-SUM\n INFO=0\n IF (NACT .EQ. 0) GOTO 410\nC\nC UPDATE THE LAGRANGE MULTIPLIERS.\nC\n 380 LFLAG=3\n GOTO 740\n 390 DO 400 K=1,NACT\n IW=IWW+K\n 400 W(K)=W(K)+W(IW)\n\nC\nC REVISE THE VALUES OF XMAG.\nC BRANCH IF ITERATIVE REFINEMENT IS REQUIRED.\nC\n 410 JFLAG=1\n GOTO 910\n 420 IF (IFLAG .EQ. ITREF) GOTO 250\nC\nC DELETE A CONSTRAINT IF A LAGRANGE MULTIPLIER OF AN\nC INEQUALITY CONSTRAINT IS NEGATIVE.\nC\n KDROP=0\n GOTO 440\n 430 KDROP=KDROP+1\n IF (W(KDROP) .GE. ZERO) GOTO 440\n IF (IACT(KDROP) .LE. MEQ) GOTO 440\n NU=NACT\n MFLAG=1\n GOTO 800\n 440 IF (KDROP .LT. NACT) GOTO 430\nC\nC SEEK THE GREATEAST NORMALISED CONSTRAINT VIOLATION, DISREGARDING\nC ANY THAT MAY BE DUE TO COMPUTER ROUNDING ERRORS.\nC\n 450 CVMAX=ZERO\n IF (M .LE. 0) GOTO 481\n DO 480 K=1,M\n IA=IWA+K\n IF (W(IA) .LE. ZERO) GOTO 480\n SUM=-B(K)\n DO 460 I=1,N\n 460 SUM=SUM+X(I)*A(K,I)\n SUMX=-SUM*W(IA)\n IF (K .LE. MEQ) SUMX=DABS(SUMX)\n IF (SUMX .LE. CVMAX) GOTO 480\n TEMP=DABS(B(K))\n DO 470 I=1,N\n 470 TEMP=TEMP+DABS(X(I)*A(K,I))\n TEMPA=TEMP+DABS(SUM)\n IF (TEMPA .LE. TEMP) GOTO 480\n TEMP=TEMP+ONHA*DABS(SUM)\n IF (TEMP .LE. TEMPA) GOTO 480\n CVMAX=SUMX\n RES=SUM\n KNEXT=K\n\n 480 CONTINUE\n 481 DO 485 K=1,N\n LOWER=.TRUE.\n IA=IWA+M+K\n IF (W(IA) .LE. ZERO) GOTO 485\n SUM=XL(K)-X(K)\nC IF (SUM) 482,485,483\n IF (SUM .LT. ZERO) THEN\n GOTO 482\n ELSE\n IF (SUM .EQ. ZERO) THEN\n GOTO 485\n ELSE\n GOTO 483\n ENDIF \n ENDIF \n 482 SUM=X(K)-XU(K)\n LOWER=.FALSE.\n 483 IF (SUM .LE. CVMAX) GOTO 485\n CVMAX=SUM\n RES=-SUM\n KNEXT=K+M\n IF (LOWER) GOTO 485\n KNEXT=K+MN\n 485 CONTINUE\n IF (CVMAX.LT.MINCV) MINCV=CVMAX\nC\nC TEST FOR CONVERGENCE\nC\n INFO=0\n IF (CVMAX .LE. VSMALL) GOTO 700\nC\nC RETURN IF, DUE TO ROUNDING ERRORS, THE ACTUAL CHANGE IN\nC X MAY NOT INCREASE THE OBJECTIVE FUNCTION\nC\n JFINC=JFINC+1\n IF (JFINC .EQ. 0) GOTO 510\n IF (JFINC .NE. IFINC) GOTO 530\n FDIFF=ZERO\n FDIFFA=ZERO\n DO 500 I=1,N\n SUM=TWO*GRAD(I)\n SUMX=DABS(SUM)\n IF (LQL) GOTO 489\n ID=IWD+I\n W(ID)=ZERO\n DO 486 J=I,N\n IX=IWX+J\n 486 W(ID)=W(ID)+G(I,J)*(W(IX)+X(J))\n DO 487 J=1,I\n ID=IWD+J\n TEMP=G(J,I)*W(ID)\n SUM=SUM+TEMP\n 487 SUMX=SUMX+DABS(TEMP)\n GOTO 495\n 489 DO 490 J=1,N\n IX=IWX+J\n TEMP=G(I,J)*(W(IX)+X(J))\n SUM=SUM+TEMP\n 490 SUMX=SUMX+DABS(TEMP)\n 495 IX=IWX+I\n FDIFF=FDIFF+SUM*(X(I)-W(IX))\n 500 FDIFFA=FDIFFA+SUMX*DABS(X(I)-W(IX))\n INFO=2\n SUM=FDIFFA+FDIFF\n IF (SUM .LE. FDIFFA) GOTO 700\n TEMP=FDIFFA+ONHA*FDIFF\n IF (TEMP .LE. SUM) GOTO 700\n JFINC=0\n INFO=0\n 510 DO 520 I=1,N\n IX=IWX+I\n 520 W(IX)=X(I)\nC\nC FORM THE SCALAR PRODUCT OF THE NEW CONSTRAINT NORMAL WITH EACH\nC COLUMN OF Z. PARNEW WILL BECOME THE LAGRANGE MULTIPLIER OF\nC THE NEW CONSTRAINT.\nC\n 530 ITERC=ITERC+1\n IF (ITERC.LE.MAXIT) GOTO 531\n INFO=1\n GOTO 710\n 531 CONTINUE\n IWS=IWR+(NACT+NACT*NACT)/2\n IF (KNEXT .GT. M) GOTO 541\n DO 540 I=1,N\n IW=IWW+I\n 540 W(IW)=A(KNEXT,I)\n GOTO 549\n 541 DO 542 I=1,N\n IW=IWW+I\n 542 W(IW)=ZERO\n K1=KNEXT-M\n IF (K1 .GT. N) GOTO 545\n IW=IWW+K1\n W(IW)=ONE\n IZ=IWZ+K1\n DO 543 I=1,N\n IS=IWS+I\n W(IS)=W(IZ)\n 543 IZ=IZ+N\n GOTO 550\n 545 K1=KNEXT-MN\n IW=IWW+K1\n W(IW)=-ONE\n IZ=IWZ+K1\n DO 546 I=1,N\n IS=IWS+I\n W(IS)=-W(IZ)\n 546 IZ=IZ+N\n GOTO 550\n 549 KFLAG=2\n GOTO 930\n 550 PARNEW=ZERO\nC\nC APPLY GIVENS ROTATIONS TO MAKE THE LAST (N-NACT-2) SCALAR\nC PRODUCTS EQUAL TO ZERO.\nC\n IF (NACT .EQ. N) GOTO 570\n NU=N\n NFLAG=1\n GOTO 860\nC\nC BRANCH IF THERE IS NO NEED TO DELETE A CONSTRAINT.\nC\n 560 IS=IWS+NACT\n IF (NACT .EQ. 0) GOTO 640\n SUMA=ZERO\n SUMB=ZERO\n SUMC=ZERO\n IZ=IWZ+NACT*N\n DO 563 I=1,N\n IZ=IZ+1\n IW=IWW+I\n SUMA=SUMA+W(IW)*W(IZ)\n SUMB=SUMB+DABS(W(IW)*W(IZ))\n 563 SUMC=SUMC+W(IZ)**2\n TEMP=SUMB+.1D+0*DABS(SUMA)\n TEMPA=SUMB+.2D+0*DABS(SUMA)\n IF (TEMP .LE. SUMB) GOTO 570\n IF (TEMPA .LE. TEMP) GOTO 570\n IF (SUMB .GT. VSMALL) GOTO 5\n GOTO 570\n 5 SUMC=DSQRT(SUMC)\n IA=IWA+KNEXT\n IF (KNEXT .LE. M) SUMC=SUMC/W(IA)\n TEMP=SUMC+.1D+0*DABS(SUMA)\n TEMPA=SUMC+.2D+0*DABS(SUMA)\n IF (TEMP .LE. SUMC) GOTO 567\n IF (TEMPA .LE. TEMP) GOTO 567\n GOTO 640\nC\nC CALCULATE THE MULTIPLIERS FOR THE NEW CONSTRAINT NORMAL\nC EXPRESSED IN TERMS OF THE ACTIVE CONSTRAINT NORMALS.\nC THEN WORK OUT WHICH CONTRAINT TO DROP.\nC\n 567 LFLAG=4\n GOTO 740\n 570 LFLAG=1\n GOTO 740\nC\nC COMPLETE THE TEST FOR LINEARLY DEPENDENT CONSTRAINTS.\nC\n 571 IF (KNEXT .GT. M) GOTO 574\n DO 573 I=1,N\n SUMA=A(KNEXT,I)\n SUMB=DABS(SUMA)\n IF (NACT.EQ.0) GOTO 581\n DO 572 K=1,NACT\n KK=IACT(K)\n IF (KK.LE.M) GOTO 568\n KK=KK-M\n TEMP=ZERO\n IF (KK.EQ.I) TEMP=W(IWW+KK)\n KK=KK-N\n IF (KK.EQ.I) TEMP=-W(IWW+KK)\n GOTO 569\n 568 CONTINUE\n IW=IWW+K\n TEMP=W(IW)*A(KK,I)\n 569 CONTINUE\n SUMA=SUMA-TEMP\n 572 SUMB=SUMB+DABS(TEMP)\n 581 IF (SUMA .LE. VSMALL) GOTO 573\n TEMP=SUMB+.1D+0*DABS(SUMA)\n TEMPA=SUMB+.2D+0*DABS(SUMA)\n IF (TEMP .LE. SUMB) GOTO 573\n IF (TEMPA .LE. TEMP) GOTO 573\n GOTO 630\n 573 CONTINUE\n LFLAG=1\n GOTO 775\n 574 K1=KNEXT-M\n IF (K1 .GT. N) K1=K1-N\n DO 578 I=1,N\n SUMA=ZERO\n IF (I .NE. K1) GOTO 575\n SUMA=ONE\n IF (KNEXT .GT. MN) SUMA=-ONE\n 575 SUMB=DABS(SUMA)\n IF (NACT.EQ.0) GOTO 582\n DO 577 K=1,NACT\n KK=IACT(K)\n IF (KK .LE. M) GOTO 579\n KK=KK-M\n TEMP=ZERO\n IF (KK.EQ.I) TEMP=W(IWW+KK)\n KK=KK-N\n IF (KK.EQ.I) TEMP=-W(IWW+KK)\n GOTO 576\n 579 IW=IWW+K\n TEMP=W(IW)*A(KK,I)\n 576 SUMA=SUMA-TEMP\n 577 SUMB=SUMB+DABS(TEMP)\n 582 TEMP=SUMB+.1D+0*DABS(SUMA)\n TEMPA=SUMB+.2D+0*DABS(SUMA)\n IF (TEMP .LE. SUMB) GOTO 578\n IF (TEMPA .LE. TEMP) GOTO 578\n GOTO 630\n 578 CONTINUE\n LFLAG=1\n GOTO 775\nC\nC BRANCH IF THE CONTRAINTS ARE INCONSISTENT.\nC\n 580 INFO=-KNEXT\n IF (KDROP .EQ. 0) GOTO 700\n PARINC=RATIO\n PARNEW=PARINC\nC\nC REVISE THE LAGRANGE MULTIPLIERS OF THE ACTIVE CONSTRAINTS.\nC\n 590 IF (NACT.EQ.0) GOTO 601\n DO 600 K=1,NACT\n IW=IWW+K\n W(K)=W(K)-PARINC*W(IW)\n IF (IACT(K) .GT. MEQ) W(K)=DMAX1(ZERO,W(K))\n 600 CONTINUE\n 601 IF (KDROP .EQ. 0) GOTO 680\nC\nC DELETE THE CONSTRAINT TO BE DROPPED.\nC SHIFT THE VECTOR OF SCALAR PRODUCTS.\nC THEN, IF APPROPRIATE, MAKE ONE MORE SCALAR PRODUCT ZERO.\nC\n NU=NACT+1\n MFLAG=2\n GOTO 800\n 610 IWS=IWS-NACT-1\n NU=MIN0(N,NU)\n DO 620 I=1,NU\n IS=IWS+I\n J=IS+NACT\n 620 W(IS)=W(J+1)\n NFLAG=2\n GOTO 860\nC\nC CALCULATE THE STEP TO THE VIOLATED CONSTRAINT.\nC\n 630 IS=IWS+NACT\n 640 SUMY=W(IS+1)\n IF (SUMY.EQ.0.0D0) THEN\n INFO=3\n RETURN\n ENDIF \n STEP=-RES/SUMY\n PARINC=STEP/SUMY\n IF (NACT .EQ. 0) GOTO 660\nC\nC CALCULATE THE CHANGES TO THE LAGRANGE MULTIPLIERS, AND REDUCE\nC THE STEP ALONG THE NEW SEARCH DIRECTION IF NECESSARY.\nC\n LFLAG=2\n GOTO 740\n 650 IF (KDROP .EQ. 0) GOTO 660\n TEMP=ONE-RATIO/PARINC\n IF (TEMP .LE. ZERO) KDROP=0\n IF (KDROP .EQ. 0) GOTO 660\n STEP=RATIO*SUMY\n PARINC=RATIO\n RES=TEMP*RES\nC\nC UPDATE X AND THE LAGRANGE MULTIPIERS.\nC DROP A CONSTRAINT IF THE FULL STEP IS NOT TAKEN.\nC\n 660 IWY=IWZ+NACT*N\n DO 670 I=1,N\n IY=IWY+I\n 670 X(I)=X(I)+STEP*W(IY)\n PARNEW=PARNEW+PARINC\n IF (NACT .GE. 1) GOTO 590\nC\nC ADD THE NEW CONSTRAINT TO THE ACTIVE SET.\nC\n 680 NACT=NACT+1\n W(NACT)=PARNEW\n IACT(NACT)=KNEXT\n IA=IWA+KNEXT\n IF (KNEXT .GT. MN) IA=IA-N\n W(IA)=-W(IA)\nC\nC ESTIMATE THE MAGNITUDE OF X. THEN BEGIN A NEW ITERATION,\nC RE-INITILISING X IF THIS MAGNITUDE IS SMALL.\nC\n JFLAG=2\n GOTO 910\n 690 IF (SUM .LT. (XMAGR*XMAG)) GOTO 230\nC IF (ITREF) 450,450,250\n IF (ITREF .LE. 0) THEN\n GOTO 450\n ELSE\n GOTO 250\n ENDIF \nC\nC INITIATE ITERATIVE REFINEMENT IF IT HAS NOT YET BEEN USED,\nC OR RETURN AFTER RESTORING THE DIAGONAL ELEMENTS OF G.\nC\n 700 IF (ITERC .EQ. 0) GOTO 710\n ITREF=ITREF+1\n\n JFINC=-1\n IF (ITREF .EQ. 1) GOTO 250\n\nC TERMINATION ACCURACY CANNOT BE REACHED DUE TO NUMERICAL INSTABILITIES \n 710 IF (INFO .LT. 0 .AND. MINCV .LT. 1D-8) THEN\n INFO = 4\n B(1)=MINCV + VSMALL\n ENDIF\n IF (.NOT. LQL) RETURN\n DO 720 I=1,N\n ID=IWD+I\n 720 G(I,I)=W(ID)\n 730 RETURN\nC\nC\nC THE REMAINING INSTRUCTIONS ARE USED AS SUBROUTINES.\nC\nC\nC********************************************************************\nC\nC\nC CALCULATE THE LAGRANGE MULTIPLIERS BY PRE-MULTIPLYING THE\nC VECTOR IN THE S-PARTITION OF W BY THE INVERSE OF R.\nC\n 740 IR=IWR+(NACT+NACT*NACT)/2\n I=NACT\n SUM=ZERO\n GOTO 770\n 750 IRA=IR-1\n SUM=ZERO\n IF (NACT.EQ.0) GOTO 761\n DO 760 J=I,NACT\n IW=IWW+J\n SUM=SUM+W(IRA)*W(IW)\n 760 IRA=IRA+J\n 761 IR=IR-I\n I=I-1\n 770 IW=IWW+I\n IS=IWS+I\n W(IW)=(W(IS)-SUM)/W(IR)\n IF (I .GT. 1) GOTO 750\n IF (LFLAG .EQ. 3) GOTO 390\n IF (LFLAG .EQ. 4) GOTO 571\nC\nC CALCULATE THE NEXT CONSTRAINT TO DROP.\nC\nC 775 IP=IWW+1\nC IPP=IWW+NACT\n 775 KDROP=0\n IF (NACT.EQ.0) GOTO 791\n DO 790 K=1,NACT\n IF (IACT(K) .LE. MEQ) GOTO 790\n IW=IWW+K\n IF ((RES*W(IW)) .GE. ZERO) GOTO 790\n IF (W(IW).EQ.0.0D0) THEN\n INFO=3\n RETURN\n ENDIF \n TEMP=W(K)/W(IW)\n IF (KDROP .EQ. 0) GOTO 780\n IF (DABS(TEMP) .GE. DABS(RATIO)) GOTO 790\n 780 KDROP=K\n RATIO=TEMP\n 790 CONTINUE\n 791 GOTO (580,650), LFLAG\nC\nC\nC********************************************************************\nC\nC\nC DROP THE CONSTRAINT IN POSITION KDROP IN THE ACTIVE SET.\nC\n 800 IA=IWA+IACT(KDROP)\n IF (IACT(KDROP) .GT. MN) IA=IA-N\n W(IA)=-W(IA)\n IF (KDROP .EQ. NACT) GOTO 850\nC\nC SET SOME INDICES AND CALCULATE THE ELEMENTS OF THE NEXT\nC GIVENS ROTATION.\nC\n IZ=IWZ+KDROP*N\n IR=IWR+(KDROP+KDROP*KDROP)/2\n 810 IRA=IR\n IR=IR+KDROP+1\n TEMP=DMAX1(DABS(W(IR-1)),DABS(W(IR)))\n IF (TEMP.GT.VSMALL) THEN \n SUM=TEMP*DSQRT((W(IR-1)/TEMP)**2+(W(IR)/TEMP)**2)\n ELSE\n SUM=VSMALL\n ENDIF \n GA=W(IR-1)/SUM\n GB=W(IR)/SUM\nC\nC EXCHANGE THE COLUMNS OF R.\nC\n DO 820 I=1,KDROP\n IRA=IRA+1\n J=IRA-KDROP\n TEMP=W(IRA)\n W(IRA)=W(J)\n 820 W(J)=TEMP\n W(IR)=ZERO\nC\nC APPLY THE ROTATION TO THE ROWS OF R.\nC\n W(J)=SUM\n KDROP=KDROP+1\n DO 830 I=KDROP,NU\n TEMP=GA*W(IRA)+GB*W(IRA+1)\n W(IRA+1)=GA*W(IRA+1)-GB*W(IRA)\n W(IRA)=TEMP\n 830 IRA=IRA+I\nC\nC APPLY THE ROTATION TO THE COLUMNS OF Z.\nC\n DO 840 I=1,N\n IZ=IZ+1\n J=IZ-N\n TEMP=GA*W(J)+GB*W(IZ)\n W(IZ)=GA*W(IZ)-GB*W(J)\n 840 W(J)=TEMP\nC\nC REVISE IACT AND THE LAGRANGE MULTIPLIERS.\nC\n IACT(KDROP-1)=IACT(KDROP)\n W(KDROP-1)=W(KDROP)\n IF (KDROP .LT. NACT) GOTO 810\n 850 NACT=NACT-1\n GOTO (250,610), MFLAG\nC\nC\nC********************************************************************\nC\nC\nC APPLY GIVENS ROTATION TO REDUCE SOME OF THE SCALAR\nC PRODUCTS IN THE S-PARTITION OF W TO ZERO.\nC\n 860 IZ=IWZ+NU*N\n 870 IZ=IZ-N\n 880 IS=IWS+NU\n NU=NU-1\n IF (NU .EQ. NACT) GOTO 900\n IF (W(IS) .EQ. ZERO) GOTO 870\n TEMP=DMAX1(DABS(W(IS-1)),DABS(W(IS)))\n SUM=TEMP*DSQRT((W(IS-1)/TEMP)**2+(W(IS)/TEMP)**2)\n GA=W(IS-1)/SUM\n GB=W(IS)/SUM\n W(IS-1)=SUM\n DO 890 I=1,N\n K=IZ+N\n TEMP=GA*W(IZ)+GB*W(K)\n W(K)=GA*W(K)-GB*W(IZ)\n W(IZ)=TEMP\n 890 IZ=IZ-1\n GOTO 880\n 900 GOTO (560,630), NFLAG\nC\nC\nC********************************************************************\nC\nC\nC CALCULATE THE MAGNITUDE OF X AN REVISE XMAG.\nC\n 910 SUM=ZERO\n DO 920 I=1,N\n SUM=SUM+DABS(X(I))*VFACT*(DABS(GRAD(I))+DABS(G(I,I)*X(I)))\n IF (LQL) GOTO 920\n IF (SUM .LT. 1.D-30) GOTO 920\n VFACT=1.D-5*VFACT\n SUM=1.D-5*SUM\n XMAG=1.D-5*XMAG\n 920 CONTINUE\n XMAG=DMAX1(XMAG,SUM)\n GOTO (420,690), JFLAG\nC\nC\nC********************************************************************\nC\nC\nC PRE-MULTIPLY THE VECTOR IN THE W-PARTITION OF W BY Z TRANSPOSE.\nC\n 930 JL=IWW+1\n IZ=IWZ\n DO 940 I=1,N\n IS=IWS+I\n W(IS)=ZERO\n IWWN=IWW+N\n DO 940 J=JL,IWWN\n IZ=IZ+1\n 940 W(IS)=W(IS)+W(IZ)*W(J)\n GOTO (350,550), KFLAG\n RETURN\n END\n", "meta": {"hexsha": "fb4b1a17ea5d906c7dbc38c4fe436ae76a92c9b5", "size": 36218, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/QLD/f/QLD.f", "max_stars_repo_name": "gergondet/eigen-qld", "max_stars_repo_head_hexsha": "47c09782fa15a6b43d8c4b1852c64d06dc517352", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2017-09-15T09:02:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-02T18:03:17.000Z", "max_issues_repo_path": "src/QLD/f/QLD.f", "max_issues_repo_name": "gergondet/eigen-qld", "max_issues_repo_head_hexsha": "47c09782fa15a6b43d8c4b1852c64d06dc517352", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2017-01-13T18:19:00.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-24T04:10:19.000Z", "max_forks_repo_path": "src/QLD/f/QLD.f", "max_forks_repo_name": "gergondet/eigen-qld", "max_forks_repo_head_hexsha": "47c09782fa15a6b43d8c4b1852c64d06dc517352", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2016-10-26T17:28:42.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-11T11:43:45.000Z", "avg_line_length": 27.8385857033, "max_line_length": 79, "alphanum_fraction": 0.5558285935, "num_tokens": 13428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377231430563, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7527478990888562}} {"text": "Module general_structural_functions\n\tuse math_constants\n\tuse quadratures\n\tuse hssw_structure\n\tuse hd_structure\n\tImplicit None\n\tcontains\n\n\t!Function that calculates the radial distribution function g(r) through the\n\t!structure factor. The function needs:\n\t! \"r\" -> value of the radial length\n\t! \"rho\" -> particle density of the system\n\t! \"k\" -> wave vector array\n\t! \"kw\" -> wave vector weights\n\t! \"sk\" -> structure factor\n\tFunction radial_dist_3D(r,rho,k,kw,s) result(g)\n\t\tImplicit None\n\t\tReal * 8, intent(in) :: r, rho !radial length and density\n\t\tReal * 8, intent(in), dimension(:) :: k, kw, s !wave vector, weights and structure factor\n\t\tReal * 8 :: g\n\t\tReal * 8, dimension(size(k)) :: integrand\n\t\tInteger :: i1\n\t\tdo i1 = 1, size(k)\n\t\t\tif ( k(i1) * r >= 0.075d0 ) integrand(i1) = dsin( k(i1) * r ) / r\n\t\t\tif ( k(i1) * r < 0.075d0 ) integrand(i1) = k(i1) - (( r * r * (k(i1) ** 3))/6.d0)\n\t\t\t!integrand(i1) = sin( k(i1) * r ) / r\n\t\t\tintegrand(i1) = k(i1) * kw(i1) * (S(i1) - 1.d0) * integrand(i1)\n\t\tend do\n\t\tg = 1.d0 + ( 1.d0 / ( 2.d0 * rho * pi * pi ) ) * sum(integrand)\n\t\treturn\n\tEnd function\n\n\n\t!Function that calculates the radial distribution function g(r) through the\n\t!structure factor. The function needs:\n\t! \"r\" -> value of the radial length\n\t! \"rho\" -> particle density of the system\n\t! \"k\" -> wave vector array\n\t! \"kw\" -> wave vector weights\n\t! \"sk\" -> structure factor\n\tFunction radial_dist_2D(r,rho,k,kw,s) result(g)\n\t\tImplicit None\n\t\tReal * 8, intent(in) :: r, rho !radial length and density\n\t\tReal * 8, intent(in), dimension(:) :: k, kw, s !wave vector, weights and structure factor\n\t\tReal * 8 :: g\n\t\tReal * 8, dimension(size(k)) :: integrand\n\t\tInteger :: i1\n\t\tdo i1 = 1, size(k)\n\t\t\tif ( k(i1) * r >= 0.075d0 ) integrand(i1) = dsin( k(i1) * r ) / r\n\t\t\tif ( k(i1) * r < 0.075d0 ) integrand(i1) = k(i1) - (( r * r * (k(i1) ** 3))/6.d0)\n\t\t\t!integrand(i1) = sin( k(i1) * r ) / r\n\t\t\tintegrand(i1) = k(i1) * kw(i1) * (S(i1) - 1.d0) * integrand(i1)\n\t\tend do\n\t\tg = 1.d0 + ( 1.d0 / ( 2.d0 * rho * pi * pi ) ) * sum(integrand)\n\t\treturn\n\tEnd function\n\n\t!Function that calculates the coordination number integral for a given set of points\n\t!given the value up to the starting point. The function needs:\n\t! \"rho\" -> system density\n\t! \"coor_last\" -> the value of the coordination number up to the starting value of the integral\n\t! \"r\" -> radial distance vector\n\t! \"rw\" -> weights of the radial distance\n\t! \"gr\" -> radial distribution function evaluated in the \"r\" distances\n\tFunction coordination_num_3D(rho,coor_last,r,rw,gr) result (coor_n)\n\t\tImplicit None\n\t\tReal * 8, intent(in) :: rho,coor_last\n\t\tReal * 8, intent(in), dimension(:) :: r, rw, gr\n\t\tReal * 8 :: coor_n\n\t\tReal * 8, dimension(size(r)) :: integrand\n\t\tintegrand = r * r * gr * rw\n\t\tcoor_n = coor_last + 4.d0 * pi * rho * sum(integrand)\n\t\treturn\n\tEnd Function\n\n\t!Function that calculates the potential energy of the system\n\t! \"rho\" -> system density\n\t! \"r\" -> radial distance vector\n\t! \"rw\" -> weights of the radial distance\n\t! \"gr\" -> radial distribution function evaluated in the \"r\" distances\n\t! \"ur\" -> pair potential array for each distance\n\t! \"energy\" -> output value of the energy\n\tFunction pot_energy_3D(rho,r,rw,gr,ur) result (energy)\n\t\tImplicit None\n\t\tReal * 8, intent(in) :: rho\n\t\tReal * 8, intent(in), dimension(:) :: r, rw, gr, ur\n\t\tReal * 8 :: energy\n\t\tReal * 8, dimension(size(r)) :: integrand\n\t\tintegrand = r * r * gr * ur * rw\n\t\tenergy = 2.d0 * pi * rho * sum(integrand)\n\t\treturn\n\tEnd Function\n\n\t!This subroutine calculates the radial distribution function as well as some other\n\t!properties dependent of this function. This function needs:\n\t! \"rho\" -> system density\n\t! \"k\" -> Wave-vectors array to calculate the Fourier transform\n\t! \"kw\" -> Wave-vectors weights\n\t! \"Sk\" -> Structure Factor array\n\t! \"r\" -> radial distance array in which we want to compute \"g(r)\"\n\t! \"dr\" -> differential array of radial distance for each distance in the array \"r\"\n\t! \"dr_quadp\" -> quadrature points associated with the integrals over \"g(r)\"\n\t! \"dr_quadw\" -> quadrature weights associated with the integrals over \"g(r)\"\n\t!The outputs are:\n\t! \"g_r\" -> Radial distribution function \"g(r)\"\n\t! \"coor_n_r\" -> Coordination number depending on the cutting value \"r\"\n\t! \"d\" -> dimension of the system\n\tSubroutine calc_gr_dependent_functions(rho,k,kw,Sk,r,dr_quadp,dr_quadw,g_r,coor_n_r,d)\n\t\tImplicit None\n\t\tReal * 8, intent(in), dimension(:) :: k, kw, Sk, r, dr_quadp, dr_quadw\n\t\tReal * 8, intent(out), dimension(:) :: g_r,coor_n_r\n\t\tReal * 8, intent(in) :: rho\n\t\tInteger, intent(in) :: d\n\t\tReal * 8, dimension(size(dr_quadp)) :: drqp, drqw, dg_r\n\t\tReal * 8 :: dr,coor_n_last\n\t\tInteger :: i1,i2\n\t\t!open(unit=11, file=\"gr_test_F.dat\", status=\"replace\")\n\t coor_n_r = 0.d0\n\t\tcoor_n_last = 0.d0\n\t\tdrqw = dr_quadw\n\t\tdr = r(2)-r(1)\n\t\tif (d == 3) then\n\t\t\tDo i1=1, size(r)\n\t\t\t\tdrqp = dr_quadp + r(i1) - dr\n\t\t\t\tg_r(i1)= radial_dist_3D(r(i1),rho,k,kw,sk)\n\t\t\t do i2=1, size(drqp)\n\t\t\t dg_r(i2) = radial_dist_3D(drqp(i2),rho,k,kw,sk)\n\t\t\t end do\n\t\t\t coor_n_r(i1) = coordination_num_3D(rho,coor_n_last,drqp,drqw,dg_r)\n\t\t\t ! write(11,*) r, gr,grtail, gr+grtail,ncoor, (ncoor)/(4.d0 * pi *rho* (r ** 3)/3.d0)\n\t\t\t coor_n_last = coor_n_r(i1)\n\t\t End do\n\t\tElse if(d == 2) Then\n\t\tEnd If\n\t !close(11)\n\tEnd Subroutine\n\n\t!This subroutine writes down the information of the system used, as well as the\n\t!approximation scheme\n\tSubroutine sys_writting(sys,sysp,approx,i_unit)\n\t\tImplicit None\n\t\tReal * 8, dimension(:), intent(in) :: sysp\n\t\tCharacter(len=4), intent(in) :: sys,approx\n\t\tInteger :: i_unit\n\t\tselect case(sys)\n\t\tcase(\"HSSW\")\n\t\t\tcall writting_hssw_p(sysp,approx,i_unit)\n\t\tcase(\"HD00\")\n\t\t\tcall writting_hd_p(sysp,approx,i_unit)\n\t\tcase(\"HS00\")\n\t\t\tcall writting_hs_p(sysp,approx,i_unit)\n\t\tend select\n\tEnd Subroutine\n\n\t!This subroutine is for the writting of the structure factor as well as the\n\t!weights of the quadrature and the information file\n\tSubroutine s_writting(k,sk,kw,i_unit)\n\t\tImplicit None\n\t\tReal * 8, dimension(:), intent(in) :: k, sk, kw\n\t\tInteger :: i1\n\t\tInteger, intent(in) :: i_unit\n\t\t!k S(k) kw WRITTING\n\t\tWrite (i_unit,*) \"# \t\t\tk \t\t\t\t\t\t\t\tS(k)\t\t\t\t\t\t\t\tWeights\"\n\t\tDo i1=1, size(k)\n\t\t\tWrite(i_unit,*) k(i1),sk(i1),kw(i1)\n\t\tEnd Do\n\tEnd Subroutine\n\n\t!This subroutine is for the writting of the radial distribution function\n\t!as well as other radial distance dependent functions\n\tSubroutine g_writting(r,gr,coor_n_r,i_unit)\n\t\tImplicit None\n\t\tReal * 8, dimension(:), intent(in) :: r, gr,coor_n_r\n\t\tInteger, Intent (in) :: i_unit\n\t\tInteger :: i1\n\t\tWrite (i_unit,*) \"# \t\t\tr \t\t\t\t\t\t\t\tg(r)\t\t\t\t\t\tCoordination Number\"\n\t\tDo i1=1, size(r)\n\t\t\tWrite(i_unit,*) r(i1),gr(i1),coor_n_r(i1)\n\t\tEnd Do\n\tEnd Subroutine\n\n\t!This subroutine is for the information with respect the wave-vectors used\n\tSubroutine k_info_writting(k,quadp,k_quad,i_unit)\n\t\tImplicit None\n\t\tReal * 8, dimension(:), intent(in) :: k,quadp\n\t\tCharacter(*), intent(in) :: k_quad\n\t\tInteger :: i1\n\t\tInteger, intent(in) :: i_unit\n\t\t!INFO FILE WRITTING\n\t\tWrite(i_unit,*) \"### Wave-Vectors Quadrature ###\"\n\t\tCall quad_writting(k_quad,i_unit,quadp)\n\t\tWrite(i_unit,*) \"### Wave-Vectors General INFO ###\"\n\t\tWrite(i_unit,*) \"number of points = \", size(k)\n\t\tWrite(i_unit,*) \"k minimum value = \", k(1)\n\t\tWrite(i_unit,*) \"k maximum value = \", k(size(k))\n\tEnd Subroutine\n\n\t!This subroutine is for the information with respect the radial distance used\n\tSubroutine r_info_writting(r,r_params,r_quad,i_unit)\n\t\tImplicit None\n\t\tReal * 8, dimension(:), intent(in) :: r, r_params\n\t\tCharacter(*), intent(in) :: r_quad\n\t\tInteger, intent(in) :: i_unit\n\t\t!INFO FILE WRITTING\n\t\tWrite(i_unit,*) \"### Radial distance Quadrature ###\"\n\t\tCall quad_writting(r_quad,i_unit,r_params)\n\t\tWrite(i_unit,*) \"### Radial distance General INFO ###\"\n\t\tWrite(i_unit,*) \"number of points = \", size(r)\n\t\tWrite(i_unit,*) \"r minimum value = \", r(1)\n\t\tWrite(i_unit,*) \"r maximum value = \", r(size(r))\n\tEnd Subroutine\n\n\t!This subroutine is for the information with respect the potential\n\tSubroutine Energy_info_writting(energy,r_params,r_quad,i_unit)\n\t\tImplicit None\n\t\tReal * 8 :: energy\n\t\tReal * 8, dimension(:), intent(in) :: r_params\n\t\tCharacter(*), intent(in) :: r_quad\n\t\tInteger, intent(in) :: i_unit\n\t\t!INFO FILE WRITTING\n\t\tWrite(i_unit,*) \"### Potential Energy info ###\"\n\t\tWrite(i_unit,*) \"Potential Energy = \", energy\n\t\tCall quad_writting(r_quad,i_unit,r_params)\n\tEnd Subroutine\n\n\t!This subroutine is for the information with respect the radial distance differential used\n\tSubroutine dr_info_writting(dr,dr_w,dr_params,dr_quad,i_unit)\n\t\tImplicit None\n\t\tReal * 8, dimension(:), intent(in) :: dr, dr_w, dr_params\n\t\tCharacter(*), intent(in) :: dr_quad\n\t\tInteger, intent(in) :: i_unit\n\t\tInteger :: i1\n\t\tWrite(i_unit,*) \"### Radial distance Differencial General INFO ###\"\n\t\tWrite(i_unit,*) \"number of points = \", size(dr)\n\t\tWrite(i_unit,*) \"dr minimum value = \", dr(1)\n\t\tWrite(i_unit,*) \"dr maximum value = \", dr(size(dr))\n\t\tWrite(i_unit,*) \"###############################\"\n\t\tWrite(i_unit,*) \"### Radial distance Differencial Quadrature ###\"\n\t\tCall quad_writting(dr_quad,i_unit,dr_params)\n\t\tWrite(i_unit,*) \"### Radial distance Differencial Quadrature values ###\"\n\t\tWrite(i_unit,*) \"\t\t\t\t\t\tr\t\t\t\t\t\t\t\t\t\t\t\tWeights\"\n\t\tDo i1=1, size(dr)\n\t\t\tWrite(i_unit,*) dr(i1), dr_w(i1)\n\t\tEnd Do\n\t\tWrite(i_unit,*) \"###############################\"\n\tEnd Subroutine\n\n\tSubroutine file_name_constructor(sys,sysp,folder,preffix,id,suffix,file_name)\n\t\tImplicit None\n\t\tReal * 8, dimension(:), intent(in) :: sysp\n\t\tCharacter(*), intent(in) :: sys,folder,preffix,suffix\n\t\tInteger, intent(in) :: id\n\t\tReal * 8 :: phi, T, lambda, z\n\t\tInteger :: i_phi, di_phi, i_T, di_T, i_L, di_L, i_z, di_z\n\t\tInteger, parameter :: i_phi_m=1, di_phi_m=6, i_T_m =2, di_T_m = 6, id_m=2\n\t\tInteger, parameter :: i_L_m = 2, di_L_m = 2, i_z_m = 2, di_z_m = 2\n\t\tCharacter (len=i_phi_m+di_phi_m+1) :: phi_char\n\t\tCharacter (len=i_T_m+di_T_m+1) :: T_char\n\t\tCharacter (len=i_L_m+di_L_m+1) :: L_char\n\t\tCharacter (len=i_z_m+di_z_m+1) :: z_char\n\t\tCharacter (len=id_m) :: id_char\n\t\tCharacter (len=100) :: sys_ID\n\t\tCharacter (*) :: file_name\n\t\tCharacter (len=50) :: FMT0,FMT1,FMT2,FMTID\n\t\tInteger :: i1\n\t\t!Global Formats\n\t\tWrite(FMT0,\"(A,I1,A1,I1,A5,I1,A1,I1,A1)\") \"(I\",i_phi_m,\".\",i_phi_m,\",A1,I\",di_phi_m,\".\",di_phi_m,\")\"\n\t\tWrite(FMTID,\"(A2,I1,A1,I1,A1)\") \"(I\",id_m,\".\",id_m,\")\"\n\t\t!Global character variables\n\t\tphi = sysp(1)\n\t\ti_phi = int(phi)\n\t\tdi_phi = nint((phi - dble(i_phi)) * (10.d0 ** di_phi_m) )\n\t\tWrite(id_char,trim(FMTID)) id\n\t\tWrite(phi_char,trim(FMT0)) i_phi,\"_\",di_phi\n\t\t!System selector\n\t\tselect case(sys)\n\t\tcase(\"HSSW\")\n\t\t\t!Formats\n\t\t\tWrite(FMT1,\"(A2,I1,A1,I1,A5,I1,A1,I1,A1)\") \"(I\",i_T_m,\".\",i_T_m,\",A1,I\",di_T_m,\".\",di_T_m,\")\"\n\t\t\tWrite(FMT2,\"(A2,I1,A1,I1,A5,I1,A1,I1,A1)\") \"(I\",i_L_m,\".\",i_L_m,\",A1,I\",di_L_m,\".\",di_L_m,\")\"\n\t\t\t!System conditions\n\t\t\tlambda = sysp(3)\n\t\t\tT = sysp(2)\n\t\t\t!Calculating the associated integers for phi, T and lambda:\n\t\t\ti_T = int(T)\n\t\t\tdi_T = nint( (T- dble(i_T)) * (10.d0 ** di_T_m) )\n\t\t\ti_L = int(lambda)\n\t\t\tdi_L = nint( (lambda- dble(i_L)) * (10.d0 ** di_L_m) )\n\t\t\t!Writting character variables\n\t\t\tWrite(T_char,FMT1) i_T,\"_\",di_T\n\t\t\tWrite(L_char,FMT2) i_L,\"_\",di_L\n\t\t\tWrite(id_char,\"(I2.2)\") id\n\t\t\t!Writting System ID\n\t\t\tsys_ID = trim(\"_HSSW_phi_\"//phi_char//\"_T_\"//T_char//\"_L_\"//L_char//\"_id_\"//id_char)\n\t\tcase(\"HD00\")\n\t\t\t!Writting System ID\n\t\t\tsys_ID = trim(\"_HD_phi_\"//phi_char//\"_id_\"//id_char)\n\t\tcase(\"HS00\")\n\t\t\t!Writting System ID\n\t\t\tsys_ID = trim(\"_HS_phi_\"//phi_char//\"_id_\"//id_char)\n\t\tcase(\"HSAY\")\n\t\t\t!Formats\n\t\t\tWrite(FMT1,\"(A2,I1,A1,I1,A5,I1,A1,I1,A1)\") \"(I\",i_T_m,\".\",i_T_m,\",A1,I\",di_T_m,\".\",di_T_m,\")\"\n\t\t\tWrite(FMT2,\"(A2,I1,A1,I1,A5,I1,A1,I1,A1)\") \"(I\",i_z_m,\".\",i_z_m,\",A1,I\",di_z_m,\".\",di_z_m,\")\"\n\t\t\t!System conditions\n\t\t\tz = sysp(3)\n\t\t\tT = sysp(2)\n\t\t\t!Calculating the associated integers for phi, T and lambda:\n\t\t\ti_T = int(T)\n\t\t\tdi_T = nint( (T- dble(i_T)) * (10.d0 ** di_T_m) )\n\t\t\ti_z = int(z)\n\t\t\tdi_z = nint( (z- dble(i_z)) * (10.d0 ** di_z_m) )\n\t\t\t!Writting character variables\n\t\t\tWrite(T_char,FMT1) i_T,\"_\",di_T\n\t\t\tWrite(z_char,FMT2) i_z,\"_\",di_z\n\t\t\tWrite(id_char,\"(I2.2)\") id\n\n\t\t\t!Writting System ID\n\t\t\tsys_ID = trim(\"_HSAY_phi_\"//phi_char//\"_T_\"//T_char//\"_z_\"//z_char//\"_id_\"//id_char)\n\t\tcase default\n\t\t\tsys_ID = trim(sys//\"_phi_\"//phi_char//\"_id_\"//id_char)\n\t\tend select\n\t\tfile_name = trim(trim(folder)//trim(preffix)//trim(sys_ID)//trim(suffix))\n\tEnd Subroutine\nEnd Module\n", "meta": {"hexsha": "45662dd4270c312be87e056ad974452edcaa98f3", "size": 12409, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "source_code/structures/general_structural_functions.f03", "max_stars_repo_name": "LANIMFE/HS_HSSW_quench_NESCGLE", "max_stars_repo_head_hexsha": "d6d18fc3158fc45b51db5e7a77e2ed4639eaf0de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-14T17:17:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-14T17:17:00.000Z", "max_issues_repo_path": "source_code/structures/general_structural_functions.f03", "max_issues_repo_name": "LANIMFE/HS_HSSW_quench_NESCGLE", "max_issues_repo_head_hexsha": "d6d18fc3158fc45b51db5e7a77e2ed4639eaf0de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source_code/structures/general_structural_functions.f03", "max_forks_repo_name": "LANIMFE/HS_HSSW_quench_NESCGLE", "max_forks_repo_head_hexsha": "d6d18fc3158fc45b51db5e7a77e2ed4639eaf0de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.0644171779, "max_line_length": 102, "alphanum_fraction": 0.6501732613, "num_tokens": 4394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7527431543426747}} {"text": "module fib_mod\n use, intrinsic :: iso_fortran_env, only : I8 => INT64, DP => REAL64\n implicit none\n\n private\n public :: fib_recursive, fib_skip_ahead, fib_memoization, &\n fib_iterative, fib_closed_form\n\ncontains\n\n recursive function fib_recursive(n) result(fib)\n implicit none\n integer(Kind=I8), value :: n\n integer(kind=I8) :: fib\n\n if (n == 0_I8) then\n fib = 0_I8\n else if (n == 1_I8) then\n fib = 1_I8\n else\n fib = fib_recursive(n - 1_I8) + fib_recursive(n - 2_I8)\n end if\n end function fib_recursive\n\n recursive function fib_skip_ahead(n) result(fib)\n implicit none\n integer(kind=I8), value :: n\n integer(kind=I8) :: fib\n if (n == 0_I8) then\n fib = 0_I8\n else if (n == 1_I8 .or. n == 2_I8) then\n fib = 1_I8\n else if (mod(n, 2_I8) == 0) then\n fib = fib_skip_ahead(n/2_I8)*(fib_skip_ahead(n/2_I8 + 1_I8) + &\n fib_skip_ahead(n/2_I8 - 1_I8))\n else\n fib = fib_skip_ahead(n/2_I8 + 1_I8)**2 + fib_skip_ahead(n/2_I8)**2\n end if\n end function fib_skip_ahead\n\n recursive function fib_memoization(n) result(fib)\n implicit none\n integer(kind=I8), value :: n\n integer(kind=I8) :: fib\n integer(kind=I8), parameter :: buffer_size = 1000000\n integer(kind=I8), dimension(0:buffer_size), save :: buffer = -1_I8\n\n buffer(0) = 0_I8\n buffer(1) = 1_I8\n if (n <= buffer_size) then\n if (buffer(n) == -1_I8) then\n buffer(n) = fib_memoization(n - 1_I8) + fib_memoization(n - 2_I8)\n end if\n fib = buffer(n)\n else\n fib = fib_memoization(n - 1_I8) + fib_memoization(n - 2_I8)\n end if\n end function fib_memoization\n\n function fib_iterative(n) result(fib)\n implicit none\n integer(kind=I8), value :: n\n integer(kind=I8) :: fib\n integer(kind=I8) :: fib_n_1, i, tmp\n\n if (n == 0_I8) then\n fib = 0_I8\n else\n fib_n_1 = 0_I8\n fib = 1_I8\n do i = 2_I8, n\n tmp = fib\n fib = fib + fib_n_1\n fib_n_1 = tmp\n end do\n end if\n end function fib_iterative\n\n function fib_closed_form(n) result(fib)\n implicit none\n integer(kind=I8), value :: n\n integer(kind=I8) :: fib\n real(kind=DP) :: alpha = (1.0_DP + sqrt(5.0_DP))/2.0_DP, &\n beta = (1.0_DP - sqrt(5.0_DP))/2.0_DP, &\n pre_factor = 1.0_DP/sqrt(5.0_DP)\n\n fib = nint(pre_factor*(alpha**n - beta**n), kind=I8)\n end function fib_closed_form\n\nend module fib_mod\n", "meta": {"hexsha": "3cbb02ddc835b3ad262ab50e6cee6866c322f3d9", "size": 2797, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/fibonacci/fib_mod.f90", "max_stars_repo_name": "caguerra/Fortran-MOOC", "max_stars_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-05-20T12:03:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T19:46:26.000Z", "max_issues_repo_path": "source_code/fibonacci/fib_mod.f90", "max_issues_repo_name": "caguerra/Fortran-MOOC", "max_issues_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-30T04:25:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T08:21:30.000Z", "max_forks_repo_path": "source_code/fibonacci/fib_mod.f90", "max_forks_repo_name": "caguerra/Fortran-MOOC", "max_forks_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-09-27T07:30:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T16:23:19.000Z", "avg_line_length": 30.7362637363, "max_line_length": 81, "alphanum_fraction": 0.5319985699, "num_tokens": 859, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7527372854576097}} {"text": "! Created by EverLookNeverSee@GitHub on 6/10/20\n! For more information see FCS/img/Exercise_11.png\n\nprogram main\n implicit none\n ! declaring variables\n integer :: i, j, k , root\n logical(1), dimension(1000) :: a\n ! initializing variables\n ! setting .true. for all elements of array\n a = .true.\n ! assigning false to first element of array(1 is not prime)\n a(1) = .false.\n ! calculating square root of size of array\n ! because we don't need to check all elements of array\n ! if i^2 > size of array, there is no non-prime number in array.\n root = int(sqrt(real(size(a))))\n ! checking elements of array\n do i = 2, root\n if (a(i)) then ! if a(i) is true\n ! set all multiples of i as false\n do j = i * i, size(a), i\n a(j) = .false.\n end do\n end if\n end do\n ! print all true(prime) numbers that are remained in array\n do k = 1, size(a)\n if (a(k)) then\n print *, k\n end if\n end do\nend program main", "meta": {"hexsha": "aa65baca6d610ea0dba2088dc630872fa5e02e5f", "size": 1035, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical methods/Exercise_11.f90", "max_stars_repo_name": "EverLookNeverSee/FCS", "max_stars_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-14T10:30:25.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-17T13:03:15.000Z", "max_issues_repo_path": "src/numerical methods/Exercise_11.f90", "max_issues_repo_name": "EverLookNeverSee/FCS", "max_issues_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-06-06T13:54:45.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-25T20:32:23.000Z", "max_forks_repo_path": "src/numerical methods/Exercise_11.f90", "max_forks_repo_name": "EverLookNeverSee/FCS", "max_forks_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-08T12:57:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T12:57:46.000Z", "avg_line_length": 31.3636363636, "max_line_length": 68, "alphanum_fraction": 0.5874396135, "num_tokens": 292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.8333246015211009, "lm_q1q2_score": 0.7527372848578285}} {"text": "!==============================================================================\n!\n!> @anchor test_mean2true\n!!\n!> @brief Program for testing transformation mean anomaly to true anomaly and vice versa.\n!!\t\tS/R from slam_astro_conversions are used\n!!\n!> @author Eduard Gamper (EG)\n!!\n!> @date
    \n!!
  • 05.01.2015 (initial design)
  • \n!!
\n!!\n!! @details Program for testing transformation mean anomaly to true anomaly and vice versa.\n!!\t\tUsed equations in functions: Vallado, S.54 eq.2-6, S.56 eq. 2-13, 2-14\n!!\n!!\n!------------------------------------------------------------------------\n\nProgram test_mean2true\n\nuse slam_astro_conversions\nuse slam_io, only: slam_message\nuse slam_types\nuse slam_time\nuse slam_orbit_types\nuse slam_math, only: eps15, eps9, eps6, eps3\n\nimplicit none\n\ntype(kepler_t) :: state_kepler\t\t\t! State vector with Kepler elements\ntype(kepler_t) :: state_kepler_literature\t! State vector with Kepler elements\n\t\t\t\t\t\t! (1) = semimajor axis [km]\n\t\t\t\t\t\t! (2) = eccentricity\n\t\t\t\t\t\t! (3) = orbit inclination [rad]\n\t\t\t\t\t\t! (4) = r.a. of asc. node [rad]\n\t\t\t\t\t\t! (5) = argument of perigee [rad]\n\t\t\t\t\t\t! (6) = mean anomaly [rad]\n\n\nlogical \t:: error = .false.\t\t! Error flag\nlogical \t:: error_all = .false.\t\t! Error flag\n\n\n! QUELLE: http://www.tle.info/data/ISS_DATA.TXT\n!\n! M50 Cartesian M50 Keplerian\n! ----------------------------------- --------------------------------\n! X = 3831218.94 A = 6778927.15 meter\n! Y = -3769807.71 meter E = .0013488\n! Z = 4131046.64 I = 51.67403\n! XDOT = 6287.659929 Wp = 38.31673\n! YDOT = 2227.041971 meter/sec RA = 172.87570 deg\n! ZDOT = -3782.037544 TA = 90.71589\n! MA = 90.56134\n! Ha = 220.633 n.mi\n! Hp = 212.869\n\n! subroutine mean2true( &\n! Ecc, & ! <-- DBL eccentricity\n! M, & ! <-- DBL mean anomaly / rad\n! E0, & ! --> DBL eccentric anomaly / rad\n! Nu & ! --> DBL true anomaly / rad\n! )\n\n! subroutine true2mean( &\n! Ecc, & ! <-- DBL eccentricity\n! Nu, & ! <-- DBL true anomly in rad\n! E0, & ! --> DBL eccentric anomaly in rad\n! M & ! --> DBL mean anomaly in rad\n! )\n\nstate_kepler_literature%ecc = 0.0013488d0\nstate_kepler_literature%man = 90.56134d0/180*pi\nstate_kepler_literature%tran = 90.71589d0/180*pi\n\nstate_kepler%ecc = state_kepler_literature%ecc\nstate_kepler%man = state_kepler_literature%man\n\nwrite(*,*) ''\nwrite(*,*) 'Testing transformation mean anomaly to true anomaly and vice versa'\nwrite(*,*) 'Functions mean2true() and true2mean() from module slam_astro_legacy are used'\nwrite(*,*) ''\nwrite(*,*) '------- Example ISS -------'\nwrite(*,*) '--Data from literature (ISS-Orbit):'\nwrite(*,*) 'Eccentricity: ', state_kepler_literature%ecc\nwrite(*,*) 'Mean anomaly: ', state_kepler_literature%man*180/pi\nwrite(*,*) 'True anomaly: ', state_kepler_literature%tran*180/pi\n\n!Transform mean anomaly to true anomaly\nCALL mean2true(state_kepler%ecc, state_kepler%man, state_kepler%ecan, state_kepler%tran)\n\nwrite(*,*) '--Transform mean anomaly to true anomaly (ISS-Orbit):'\nwrite(*,*) 'True anomaly: ', state_kepler%tran*180/pi\nwrite(*,*) 'Eccentric anomaly: ', state_kepler%ecan*180/pi\n\n!** Compare results of s/r mean2true(); use of eps6 because iteration from mean 2 true has allowed deviation of eps9\nif (abs(state_kepler%tran - state_kepler_literature%tran) .gt. eps6) error = .true.\n\n!** Display conclusion\nif (error) then\n CALL slam_message('mean2true not passed.',1)\n error_all = .true.\nelse\n CALL slam_message('mean2true passed.', 1)\nend if\n\n!Transform true anomaly back to mean anomaly\nCALL true2mean(state_kepler%ecc, state_kepler%tran, state_kepler%ecan, state_kepler%man)\n\nwrite(*,*) '--Transform true anomaly back to mean anomaly (ISS-Orbit):'\nwrite(*,*) 'Mean anomaly: ', state_kepler%man*180/pi\nwrite(*,*) 'Eccentric anomaly: ', state_kepler%ecan*180/pi\n\n!** Set error flag back to false\nerror = .false.\n\n!** Compare results of s/r true2mean()\nif (abs(state_kepler%man - state_kepler_literature%man) .gt. eps6) error = .true.\n\n!** Display conclusion\nif (error) then\n CALL slam_message('true2mean not passed.',1)\n error_all = .true.\nelse\n CALL slam_message('true2mean passed.', 1)\nend if\n\n! Example: High eccentricity\n! 0 MOLNIYA 3-50\n! 1 25847U 99036A 15310.12862371 -.00000116 +00000-0 -13949-3 0 9992\n! 2 25847 062.6934 338.4194 7400458 260.6635 016.9238 02.00678845119668\n\n! Mean Anomaly: 016.9238 deg\n! Eccentricity: 0.7400458\n\nstate_kepler_literature%ecc = 0.7400458d0\nstate_kepler_literature%man = 16.9238d0/180*pi\nstate_kepler_literature%tran = 99.203171087928723d0/180*pi !This is a calculated value (by s/r mean2true)\n\nstate_kepler%ecc = state_kepler_literature%ecc\nstate_kepler%man = state_kepler_literature%man\n! state_kepler%tran=90.71589d0/180*pi\n\nwrite(*,*) ''\nwrite(*,*) '------- Example Molniya -------'\nwrite(*,*) '--Data from literature (Molniya-Orbit):'\nwrite(*,*) 'Eccentricity: ', state_kepler%ecc\nwrite(*,*) 'Mean anomaly: ', state_kepler%man*180/pi\n! write(*,*) 'True anomaly: ', state_kepler%tran*180/pi\n\n!Transform mean anomaly to true anomaly (Molniya-Orbit)\nCALL mean2true(state_kepler%ecc, state_kepler%man, state_kepler%ecan, state_kepler%tran)\n\nwrite(*,*) '--Transform mean anomaly to true anomaly (Molniya-Orbit):'\nwrite(*,*) 'True anomaly: ', state_kepler%tran*180/pi\nwrite(*,*) 'Eccentric anomaly: ', state_kepler%ecan*180/pi\n\n!** Set error flag back to false\nerror = .false.\n\n!** Compare results of s/r mean2true()\nif (abs(state_kepler%tran - state_kepler_literature%tran) .gt. eps6) error = .true.\nwrite(*,*) abs(state_kepler%tran - state_kepler_literature%tran)\n\n!** Display conclusion\nif (error) then\n CALL slam_message('mean2true not passed.',1)\n error_all = .true.\nelse\n CALL slam_message('mean2true passed.', 1)\nend if\n\n!Transform true anomaly back to mean anomaly (Molniya-Orbit)\nCALL true2mean(state_kepler%ecc, state_kepler%tran, state_kepler%ecan, state_kepler%man)\n\nwrite(*,*) '--Transform true anomaly back to mean anomaly (Molniya-Orbit):'\nwrite(*,*) 'Mean anomaly: ', state_kepler%man*180/pi\nwrite(*,*) 'Eccentric anomaly: ', state_kepler%ecan*180/pi\n\n!** Set error flag back to false\nerror = .false.\n\n!** Compare results of s/r true2mean()\nif (abs(state_kepler%man - state_kepler_literature%man) .gt. eps6) error = .true.\n\n!** Display conclusion\nif (error) then\n CALL slam_message('true2mean not passed.',1)\n error_all = .true.\nelse\n CALL slam_message('true2mean passed.', 1)\nend if\n\n!** Display conclusion for complete test\nif (error_all) then\n CALL slam_message('Failed.',1)\n error_all = .true.\nelse\n CALL slam_message('All tests passed.', 1)\nend if\n\nend Program test_mean2true\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "2d554bd450674d9b9c9f12de8aeeffa65d322e79", "size": 7360, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/test_mean2true.f90", "max_stars_repo_name": "Space-Systems/libslam", "max_stars_repo_head_hexsha": "9a7bd64475fb48050abf33050764c192fc650876", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-03-30T08:42:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-05T10:58:24.000Z", "max_issues_repo_path": "tests/test_mean2true.f90", "max_issues_repo_name": "Space-Systems/libslam", "max_issues_repo_head_hexsha": "9a7bd64475fb48050abf33050764c192fc650876", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-06-18T13:53:57.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-12T17:41:40.000Z", "max_forks_repo_path": "tests/test_mean2true.f90", "max_forks_repo_name": "Space-Systems/libslam", "max_forks_repo_head_hexsha": "9a7bd64475fb48050abf33050764c192fc650876", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-06-17T19:50:12.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-05T10:58:27.000Z", "avg_line_length": 34.5539906103, "max_line_length": 116, "alphanum_fraction": 0.608423913, "num_tokens": 2184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7527372730407994}} {"text": "module p_mpfun_e1 ! Модуль рассчета E_1 на многократной точности\nuse mpmodule ! Пожключение модуля многократной точности\nimplicit none\n\ncontains\n\ntype (mp_real) function e141_mp(x) \nuse mpmodule ! Функция e141(x) вычисляет для\nimplicit none ! аргумента (x) значение первой \ntype (mp_real) x,w,g ! интегрально-показательной \n ! функции E1(x).\n\ncall mpinit (500) ! Инициализатор параметров MPFUN (таких как точность)\n ! Подробнее смотри в руководстве или в файле mpmod90.f\n\n! Многократная точность позволяет уточнить постоянную Эйлера. Для сравнения с результатами\n! четверной точности можно положить g таким, каким оно было задано в файле p_e1.f\n g = MPREAL('0.5772156649015328606065120900824024310421593359399235988')\n!g = MPREAL('0.57721566490153286061')\n\n! Процедура MPREAL преобразует число типа REAL в переменную типа MP_REAL\n! Процедуры EXP и LOG расширены для работы с переменными типа MP_REAL\n! Подробнее смотри в руководстве или в файле mpmod90.f\n\nif (x .ge. MPREAL('5.0')) then ! Расчёт ведется на основе известных\n w=e141c_mp(x)/x*EXP(-x) ! разложений E1(x) в ряд по полиномам\nelse ! Чебышева (см. книгу Люка: \n if (x .gt. MPREAL('0.0')) then ! Специальные математические \n w=e141a_mp(x)-g-LOG(x) ! функции и их аппроксимации.\n else ! Издательство \"МИР\". Москва, 1980.\n w = MPREAL('1.0') ! стр. 112-113 (таблица 4.1). \n endif\nendif \ne141_mp=w\nend function e141_mp\n\n \ntype (mp_real) function e141a_mp(x) ! Функция e141a(x) вычисляет для заданного аргумента\nuse mpmodule ! ( 0 <= x <= 8 ) значение E1(x)+gamma+ln(x) через\nimplicit none ! разложение в ряд по смещенным полиномам Чебышева.\ntype (mp_real) x ! Коэффициенты разложения взяты из книги Ю.Люка\ntype (mp_real) a(0:24) ! Специальные математические функции и их\ntype (mp_real) w,z ! аппроксимации. Издательство \"МИР\". Москва, 1980.\ntype (mp_real) b0, b1, b2 ! стр. 112 (таблица 4.1).\ninteger i \n\ncall mpinit (500)\n\na(0) = MPREAL(' 1.67391435474272057853')\na(1) = MPREAL(' 1.22849447854715595018') \na(2) = MPREAL('-0.31786989829837361369') ! Здесь:\na(3) = MPREAL(' 0.09274603919729219112') ! E1(x) - первая интегрально-\na(4) = MPREAL('-0.02602736316900119930') ! показательная\na(5) = MPREAL(' 0.00674815309464228057') ! функция;\na(6) = MPREAL('-0.00159897068934225285') ! gamma - постоянная Эйлера\na(7) = MPREAL(' 0.00034594453880095403')\na(8) = MPREAL('-0.00006853652682011094') \na(9) = MPREAL(' 0.00001248593239173701')\na(10) = MPREAL('-0.00000210134463871704')\na(11) = MPREAL(' 0.00000032818447981081')\na(12) = MPREAL('-0.00000004776878645154')\na(13) = MPREAL(' 0.00000000650581688192')\na(14) = MPREAL('-0.00000000083210193692')\na(15) = MPREAL(' 0.00000000010028101125')\na(16) = MPREAL('-0.00000000001142229304')\na(17) = MPREAL(' 0.00000000000123307945')\na(18) = MPREAL('-0.00000000000012648523')\na(19) = MPREAL(' 0.00000000000001235706')\na(20) = MPREAL('-0.00000000000000115226')\na(21) = MPREAL(' 0.00000000000000010276')\na(22) = MPREAL('-0.00000000000000000878')\na(23) = MPREAL(' 0.00000000000000000072')\na(24) = MPREAL('-0.00000000000000000006')\n\nw=MPREAL('0.125')*x\nz=MPREAL('4.0')*w-MPREAL('2.0')\nb0=MPREAL('0.0')\nb1=MPREAL('0.0')\n\ndo i=24, 0, -1\n b2=b1\n b1=b0\n b0=z*b1-b2+a(i)\nenddo\n\ne141a_mp=b0-b1*z/MPREAL('2.0')\n\nend function e141a_mp\n\n\ntype (mp_real) function e141c_mp(x) ! Функция e141c(x) вычисляет для заданного аргумента\nuse mpmodule ! ( x >= 5 ) значение выражения E1(x)*exp(x)*x через\nimplicit none ! его разложение в ряд по смещённым полиномам Чебышева.\ntype (mp_real) x ! Коэффициенты разложения взяты из книги \ntype (mp_real) c(0:30) ! Ю.Люка Специальные математические функции и их\ntype (mp_real) w,z ! аппроксимации. Издательство \"МИР\". Москва, 1980.\ntype (mp_real) b0,b1,b2 ! стр. 112-113 (таблица 4.1 (c)). \ninteger i \n\ncall mpinit (500)\n\nc(0) = MPREAL(' 0.92078514445389391645')\nc(1) = MPREAL('-0.07343411783162128775')\nc(2) = MPREAL(' 0.00520981196727232977')\nc(3) = MPREAL('-0.00050214071989599012')\nc(4) = MPREAL(' 0.00005920796937926337')\nc(5) = MPREAL('-0.00000808564513097880')\nc(6) = MPREAL(' 0.00000123720385647926')\nc(7) = MPREAL('-0.00000020750176860703')\nc(8) = MPREAL(' 0.00000003756005474022')\nc(9) = MPREAL('-0.00000000725410976004')\nc(10) = MPREAL(' 0.00000000148181601182')\nc(11) = MPREAL('-0.00000000031795682863')\nc(12) = MPREAL(' 0.00000000007126935828')\nc(13) = MPREAL('-0.00000000001661231319')\nc(14) = MPREAL(' 0.00000000000401155069')\nc(15) = MPREAL('-0.00000000000100038792')\nc(16) = MPREAL(' 0.00000000000025693341')\nc(17) = MPREAL('-0.00000000000006780374')\nc(18) = MPREAL(' 0.00000000000001834785')\nc(19) = MPREAL('-0.00000000000000508209')\nc(20) = MPREAL(' 0.00000000000000143861')\nc(21) = MPREAL('-0.00000000000000041560')\nc(22) = MPREAL(' 0.00000000000000012238')\nc(23) = MPREAL('-0.00000000000000003669')\nc(24) = MPREAL(' 0.00000000000000001119')\nc(25) = MPREAL('-0.00000000000000000347')\nc(26) = MPREAL(' 0.00000000000000000109')\nc(27) = MPREAL('-0.00000000000000000035')\nc(28) = MPREAL(' 0.00000000000000000011')\nc(29) = MPREAL('-0.00000000000000000004')\nc(30) = MPREAL(' 0.00000000000000000001')\n \nw=MPREAL('5.0')/x\nz=MPREAL('4.0')*w-MPREAL('2.0')\nb0=MPREAL('0.0')\nb1=MPREAL('0.0')\n\ndo i=30, 0, -1\n b2=b1\n b1=b0\n b0=z*b1-b2+c(i)\nenddo\n\ne141c_mp=b0-b1*z/MPREAL('2.0')\n\nend function e141c_mp\n\nend module p_mpfun_e1\n", "meta": {"hexsha": "69f2ad7b848acd8cc161562e2ec3e2dacb43f7bf", "size": 6021, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MPFUN90/E1/p_mpfun_e1.f", "max_stars_repo_name": "paveloom-p/P3", "max_stars_repo_head_hexsha": "57df3b6263db81685f137a7ed9428dbd3c1b4a5b", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MPFUN90/E1/p_mpfun_e1.f", "max_issues_repo_name": "paveloom-p/P3", "max_issues_repo_head_hexsha": "57df3b6263db81685f137a7ed9428dbd3c1b4a5b", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MPFUN90/E1/p_mpfun_e1.f", "max_forks_repo_name": "paveloom-p/P3", "max_forks_repo_head_hexsha": "57df3b6263db81685f137a7ed9428dbd3c1b4a5b", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.14, "max_line_length": 96, "alphanum_fraction": 0.6278026906, "num_tokens": 2408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191335436404, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.7527257423562403}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! z_scalar_argument\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine computes the argument of a complex number A.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! A COMPLEX(8)\n! complex number\n!\n! OUTPUT VARIABLES:\n!\n! ARG REAL(8)\n! arg of A in the interval [-pi,pi)\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine z_scalar_argument(A,ARG)\n\n ! input variables\n complex(8), intent(in) :: A\n real(8), intent(inout) :: ARG\n \n ! compute variables\n real(8), parameter :: PI = 3.14159265358979323846264338327950d0\n real(8) :: Ar, Ai\n integer :: INFO\n \n ! initialize INFO\n INFO = 0 \n \n ! check error in debug mode\n if (DEBUG) then\n \n ! check A\n call z_scalar_check(A,INFO)\n if (INFO.NE.0) then\n call u_infocode_check(__FILE__,__LINE__,\"A is invalid\",INFO,-1)\n return\n end if\n\n end if\n\n ! set Ar and Ai\n Ar = dble(A)\n Ai = aimag(A)\n \n ! compute arg 1\n if ((abs(Ar).EQ.0d0).AND.(abs(Ai).EQ.0d0)) then\n ARG = 0d0\n \n ! abs(Ar) > abs(Ai)\n else if (abs(Ar) > abs(Ai)) then\n \n ! compute ARG between [-pi/2,pi/2]\n ARG = atan(abs(Ai/Ar))\n \n ! abs(Ar) < abs(Ai)\n else\n \n ! compute ARG between [-pi/2,pi/2]\n ARG = atan(abs(Ar/Ai))\n ARG = PI/2d0 - ARG\n \n end if\n \n ! correct for [0,2pi)\n ! second quadrant\n if ((Ai >= 0).AND.(Ar < 0)) then\n ARG = PI-ARG\n \n ! third quadrant\n else if ((Ai < 0).AND.(Ar < 0)) then\n ARG = PI+ARG\n \n ! fourth quadrant\n else if ((Ai < 0).AND.(Ar > 0)) then\n ARG = 2d0*PI-ARG\n end if\n \n ! shift by pi\n ARG = ARG - PI\n \nend subroutine z_scalar_argument\n", "meta": {"hexsha": "df12b483cd59ccd1e8badc11787dffc787f9d43b", "size": 1824, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/AMVW/src/complex_double/z_scalar_argument.f90", "max_stars_repo_name": "trcameron/FPML", "max_stars_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/AMVW/src/complex_double/z_scalar_argument.f90", "max_issues_repo_name": "trcameron/FPML", "max_issues_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/AMVW/src/complex_double/z_scalar_argument.f90", "max_forks_repo_name": "trcameron/FPML", "max_forks_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.2666666667, "max_line_length": 70, "alphanum_fraction": 0.4824561404, "num_tokens": 559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.7525949855048502}} {"text": "C GCD.F 1 \nC COPYRIGHT (C) 2020 HUGH COLEMAN 2 \nC 3 \nC THIS FILE IS PART OF HUGHCOLEMAN/FORTRAN, AN ATTEMPT TO 4 \nC INVESTIGATE THE FORTRAN PROGRAMMING LANGUAGE AND LEARN ABOUT THE 5 \nC EARLY DAYS OF COMPUTING. IT IS RELEASED UNDER THE MIT LICENSE (SEE6 \nC LICENSE.) 7 \n 8 \nC THIS IS AN IMPLEMENTATION OF THE EUCLIDEAN ALGORITHM FOR FINDING 9 \nC THE GREATEST COMMON DIVISOR OF TWO POSITIVE INTEGERS A AND B. 10 \n 11 \n 10 FORMAT ( 2I5 ) 12 \n 11 FORMAT ( 1I5 ) 13 \n 14 \n 20 READ 10, IA, IB 15 \n 16 \nC IF EITHER OF THE SUPPLIED INTEGERS IS ZERO OR NEGATIVE, HALT. 17 \n IF (IA) 9999, 9999, 30 18 \n 30 IF (IB) 9999, 9999, 40 19 \n 20 \nC APPLY THE MODULAR REDUCTION 21 \n 40 ITMP = IB 22 \n IB = XMODF(IA, IB) 23 \n IA = ITMP 24 \n IF (IB) 80, 80, 40 25 \n 26 \n 80 PRINT 11, IA 27 \n GOTO 20 28 \n 29 \n 9999 STOP 30 \n", "meta": {"hexsha": "596f21024effda68db418dd18a560362c178d603", "size": 2400, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/gcd/prog.f", "max_stars_repo_name": "hughcoleman/retrocomputing", "max_stars_repo_head_hexsha": "9742bdf5bb93b2972848192ff1c4ee1f35ae4e26", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/gcd/prog.f", "max_issues_repo_name": "hughcoleman/retrocomputing", "max_issues_repo_head_hexsha": "9742bdf5bb93b2972848192ff1c4ee1f35ae4e26", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/gcd/prog.f", "max_forks_repo_name": "hughcoleman/retrocomputing", "max_forks_repo_head_hexsha": "9742bdf5bb93b2972848192ff1c4ee1f35ae4e26", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 77.4193548387, "max_line_length": 79, "alphanum_fraction": 0.2308333333, "num_tokens": 384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172615983308, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7525919343156028}} {"text": "\r\n\tsubroutine fitness(D, x, cost)\r\n\r\n\t\tinteger, intent(IN) :: D\r\n\t\treal(kind(1.0d0)), intent(out) :: cost\r\n\t\treal(kind(1.0d0)), dimension(D), intent(in) :: x\r\n\t\treal(kind(1.0d0)) :: temp1\r\n\t\treal(kind(1.0d0)) :: temp2\r\n\r\n\t\tinteger :: loop1\r\n\t\t!integer :: loop2\r\n\r\n\r\n\t\tcost = 0\r\n\t\ttemp1 = 0\r\n\t\ttemp2 = 0\r\n\r\n\t\t! -> Sphere function\r\n\t\t!do loop1 = 1, D\r\n\t\t!\tcost = cost + x(loop1)**2\r\n\t\t!end do\r\n\t\t! <- Sphere function\r\n\r\n\r\n\t\t! -> Hyper-Ellipsoid function\r\n\t\t!do loop1 = 1, D\r\n\t\t!\tcost = cost + ( 2**(loop1 -1) ) * x(loop1)**2\r\n\t\t!end do\r\n\t\t! <- Hyper-Ellipsoid function\r\n\r\n\t\t! -> Generalized Rosenbrock function\r\n\t\t!do loop1 = 1, D-1\r\n\t\t!\tcost = cost + 100*( x(loop1+1) - x(loop1)**2)**2 + (x(loop1) - 1)**2\r\n\t\t!end do\r\n\t\t! <- Generalized Rosenbrock function\r\n\r\n\t\t! -> Alpine function\r\n\t\t!do loop1 = 1, D\r\n\t\t!\tcost = cost + abs( x(loop1)*sin(x(loop1)) + 0.1*x(loop1) )\r\n\t\t!end do\r\n\t\t! <- Alpine function\r\n\r\n\t\t! -> Griewangkfunction\r\n\t\t!temp1 = 0\r\n\t\t!temp2 = 1\r\n\t\t!do loop1 = 1, D\r\n\t\t!\ttemp1 = temp1 + x(loop1)**2\r\n\t\t!\ttemp2 = temp2 * cos( x(loop1) / ( (loop1)**0.5 ) )\r\n\t\t!end do\r\n\t\t!cost = temp1/4000 - temp2 + 1\r\n\t\t! <- Griewangkfunction\r\n\r\n\r\n\r\n\t\t! -> Schwefel's Ridge\r\n\t\t!do loop1 = 1, D\r\n\t\t!\tdo loop2 = 1, loop1\r\n\t\t!\t\ttemp1 = temp1 + x(loop2)\r\n\t\t!\tend do\r\n\t\t!\tcost = cost + temp1**2\r\n\t\t!end do\r\n\t\t! <- Schwefel's Ridge\r\n\r\n\r\n\t\t! -> Ackley\r\n\t\tdo loop1 = 1, D\r\n\t\t\ttemp1 = temp1 + x(loop1)**2\r\n\t\t\ttemp2 = temp2 + cos(2*3.141592653589793*x(loop1))\r\n\t\tend do\r\n\t\ttemp1 = (temp1 / D)**0.5\r\n\t\ttemp2 = temp2/D\r\n\t\tcost = -20 * exp(-0.2 * temp1) - exp(temp2) + 20.0 + exp(1.0)\r\n\t\t! <- Ackley\r\n\r\n\r\n\t\t! -> Rastrigin\r\n\t\t!do loop1 = 1, D\r\n\t\t!\tcost = cost + x(loop1)**2 - 10*cos(2*3.141592653589793*x(loop1)) + 10\r\n\t\t!end do\r\n\t\t! <- Rastrigin\r\n\r\n\t\t! -> Salomon\r\n\t\t!do loop1 = 1, D\r\n\t\t!\ttemp1 = temp1 + x(loop1)**2\r\n\t\t!end do\r\n\t\t!temp1 = temp1 ** 0.5\r\n\t\t!cost = -cos(2*3.141592653589793*temp1) + 0.1*temp1 + 1\r\n\t\t! <- Salomon\r\n\r\n\r\n\t\t! -> Whitley\r\n\t\t!do loop1 = 1, D\r\n\t\t!\tdo loop2 = 1, D\r\n\t\t!\t\ttemp1 = 100 * (x(loop1) - x(loop2)**2)**2 + (1-x(loop2))**2\r\n\t\t!\t\ttemp2 = (temp1**2)/4000 - cos(temp1) + 1\r\n\t\t!\t\tcost = cost + temp2\r\n\t\t!\tend do\r\n\t\t!end do\r\n\t\t! <- Whitley\r\n\tend subroutine fitness", "meta": {"hexsha": "0a1cdc4fbc12b1f79fef1fe0559f072080d1d1dc", "size": 2172, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Fortran codes/fitness.f95", "max_stars_repo_name": "zaman13/Particle-Swarm-Optimization-Fortran-95", "max_stars_repo_head_hexsha": "abaef418d133ca9e55d81417836d7cbe2057fb29", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2018-07-02T20:48:05.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T02:58:21.000Z", "max_issues_repo_path": "Fortran codes/fitness.f95", "max_issues_repo_name": "zaman13/Particle-Swarm-Optimization-Fortran-95", "max_issues_repo_head_hexsha": "abaef418d133ca9e55d81417836d7cbe2057fb29", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran codes/fitness.f95", "max_forks_repo_name": "zaman13/Particle-Swarm-Optimization-Fortran-95", "max_forks_repo_head_hexsha": "abaef418d133ca9e55d81417836d7cbe2057fb29", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-19T06:54:06.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-19T06:54:06.000Z", "avg_line_length": 21.72, "max_line_length": 74, "alphanum_fraction": 0.523480663, "num_tokens": 971, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133515091156, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7525811076867645}} {"text": " PROGRAM xchint\r\nC driver for routine chint\r\n INTEGER NVAL\r\n REAL PIO2\r\n PARAMETER(NVAL=40, PIO2=1.5707963)\r\n INTEGER i,mval\r\n REAL a,b,chebev,fint,func,x,c(NVAL),cint(NVAL)\r\n EXTERNAL fint,func\r\n a=-PIO2\r\n b=PIO2\r\n call chebft(a,b,c,NVAL,func)\r\nC test integral\r\n10 write(*,*) 'How many terms in Chebyshev evaluation?'\r\n write(*,'(1x,a,i2,a)') 'Enter n between 6 and ',NVAL,\r\n * '. Enter n=0 to END.'\r\n read(*,*) mval\r\n if ((mval.le.0).or.(mval.gt.NVAL)) goto 20\r\n call chint(a,b,c,cint,mval)\r\n write(*,'(1x,t10,a,t19,a,t29,a)') 'X','Actual','Cheby. Integ.'\r\n do 11 i=-8,8,1\r\n x=i*PIO2/10.0\r\n write(*,'(1x,3f12.6)') x,fint(x)-fint(-PIO2),\r\n * chebev(a,b,cint,mval,x)\r\n11 continue\r\n goto 10\r\n20 END\r\n REAL FUNCTION func(x)\r\n REAL x\r\n func=(x**2)*(x**2-2.0)*sin(x)\r\n END\r\n REAL FUNCTION fint(x)\r\nC integral of FUNC\r\n REAL x\r\n fint=4.0*x*((x**2)-7.0)*sin(x)-((x**4)-14.0*(x**2)+28.0)*cos(x)\r\n END\r\n", "meta": {"hexsha": "e066e6f7d3ba2a7a7602f148853b80f65cf9d949", "size": 1073, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xchint.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xchint.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xchint.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.8055555556, "max_line_length": 70, "alphanum_fraction": 0.5135135135, "num_tokens": 396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133464597457, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7525810991735622}} {"text": " FUNCTION bessj(n,x)\r\n INTEGER n,IACC\r\n REAL bessj,x,BIGNO,BIGNI\r\n PARAMETER (IACC=40,BIGNO=1.e10,BIGNI=1.e-10)\r\nCU USES bessj0,bessj1\r\n INTEGER j,jsum,m\r\n REAL ax,bj,bjm,bjp,sum,tox,bessj0,bessj1\r\n if(n.lt.2)pause 'bad argument n in bessj'\r\n ax=abs(x)\r\n if(ax.eq.0.)then\r\n bessj=0.\r\n else if(ax.gt.float(n))then\r\n tox=2./ax\r\n bjm=bessj0(ax)\r\n bj=bessj1(ax)\r\n do 11 j=1,n-1\r\n bjp=j*tox*bj-bjm\r\n bjm=bj\r\n bj=bjp\r\n11 continue\r\n bessj=bj\r\n else\r\n tox=2./ax\r\n m=2*((n+int(sqrt(float(IACC*n))))/2)\r\n bessj=0.\r\n jsum=0\r\n sum=0.\r\n bjp=0.\r\n bj=1.\r\n do 12 j=m,1,-1\r\n bjm=j*tox*bj-bjp\r\n bjp=bj\r\n bj=bjm\r\n if(abs(bj).gt.BIGNO)then\r\n bj=bj*BIGNI\r\n bjp=bjp*BIGNI\r\n bessj=bessj*BIGNI\r\n sum=sum*BIGNI\r\n endif\r\n if(jsum.ne.0)sum=sum+bj\r\n jsum=1-jsum\r\n if(j.eq.n)bessj=bjp\r\n12 continue\r\n sum=2.*sum-bj\r\n bessj=bessj/sum\r\n endif\r\n if(x.lt.0..and.mod(n,2).eq.1)bessj=-bessj\r\n return\r\n END\r\n", "meta": {"hexsha": "931f9c6687461f029a3002e3c475fa2d30029a9f", "size": 1214, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/bessj.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/bessj.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/bessj.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.28, "max_line_length": 51, "alphanum_fraction": 0.4571663921, "num_tokens": 439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939913343093499, "lm_q2_score": 0.800692004473946, "lm_q1q2_score": 0.7525810987133414}} {"text": "*dk,finishbasis\n subroutine finishbasis(u,v,w)\nC #####################################################################\nC\nC PURPOSE -\nC\nC Give a unit vector U, FINISHBASIS selects unit vectors\nC V,W so that U-V-W are a righthanded orthonormal basis for R^3.\nC\nC INPUT ARGUMENTS -\nC\nC U - Unit vector in R^3.\nC\nC OUTPUT ARGUMENTS -\nC\nC V,W ... Orthonormal vectors to complete a righthanded\nC orthonormal basis for R^3.\nC\nC CHANGE HISTORY -\nC $Log: finishbasis.f,v $\nC Revision 2.00 2007/11/05 19:45:55 spchu\nC Import to CVS\nC\nCPVCS \r\nCPVCS Rev 1.0 31 Jan 2000 17:11:52 kuprat\r\nCPVCS Initial revision.\r\nC\nC ######################################################################\n\n implicit none\n include 'consts.h'\n \n real*8 u(3),v(3),w(3),au1,au2,au3,vlen\n \nC Our choice of V and W depend on which is the smallest component of U.\n \n au1=abs(u(1))\n au2=abs(u(2))\n au3=abs(u(3))\n \n if ((au3.le.au1).and.(au3.le.au2)) then\n v(1)=-u(2)\n v(2)=u(1)\n v(3)=zero\n w(1)=-u(1)*u(3)\n w(2)=-u(2)*u(3)\n w(3)=u(1)**2+u(2)**2\n \n elseif (au2.le.au1) then\n \n v(3)=-u(1)\n v(1)=u(3)\n v(2)=zero\n w(3)=-u(3)*u(2)\n w(1)=-u(1)*u(2)\n w(2)=u(3)**2+u(1)**2\n \n else\n \n v(2)=-u(3)\n v(3)=u(2)\n v(1)=zero\n w(2)=-u(2)*u(1)\n w(3)=-u(3)*u(1)\n w(1)=u(2)**2+u(3)**2\n \n endif\n \nc Normalize V and W.\n \n vlen=sqrt(v(1)**2+v(2)**2+v(3)**2)\n v(1)=v(1)/vlen\n v(2)=v(2)/vlen\n v(3)=v(3)/vlen\n \n vlen=sqrt(w(1)**2+w(2)**2+w(3)**2)\n w(1)=w(1)/vlen\n w(2)=w(2)/vlen\n w(3)=w(3)/vlen\n \n9999 continue\n return\n end\n \n", "meta": {"hexsha": "b1210014b3b89e6b33268ea17d1ced09a779166e", "size": 1788, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/finishbasis.f", "max_stars_repo_name": "millerta/LaGriT-1", "max_stars_repo_head_hexsha": "511ef22f3b7e839c7e0484604cd7f6a2278ae6b9", "max_stars_repo_licenses": ["CNRI-Python"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2017-02-09T17:54:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T22:22:32.000Z", "max_issues_repo_path": "src/finishbasis.f", "max_issues_repo_name": "millerta/LaGriT-1", "max_issues_repo_head_hexsha": "511ef22f3b7e839c7e0484604cd7f6a2278ae6b9", "max_issues_repo_licenses": ["CNRI-Python"], "max_issues_count": 166, "max_issues_repo_issues_event_min_datetime": "2017-01-26T17:15:45.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T21:36:28.000Z", "max_forks_repo_path": "src/lg_core/finishbasis.f", "max_forks_repo_name": "daniellivingston/LaGriT", "max_forks_repo_head_hexsha": "decd0ce0e5dab068034ef382cabcd134562de832", "max_forks_repo_licenses": ["Intel"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2017-02-08T21:56:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T06:48:36.000Z", "avg_line_length": 21.0352941176, "max_line_length": 72, "alphanum_fraction": 0.4435123043, "num_tokens": 682, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526935, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7524915042917554}} {"text": "! This program calculates an integral of a polynomial\n! Inputs:\n! integer np = the order of the polynomial\n! double precision poly = array of polynomial coefficients\n! double precision a = lower bound for integration\n! double precision b = upper bound for integration\n! double precision eps = desired accuracy\n! integer jmax = maximum subdivisions for the \n! trapezoidal integration\n! Suggested input:\n! 3\n! 1\n! 2\n! 3\n! 4\n! 0 1000\n! 1e-20 20\n!\n! Output:\n! Integral over the range 0 to 1000 = 1.001001e+12\n!\n! Timothy H. Kaiser \n! tkaiser@mines.edu\n! Aug 2010\n! Revised Sep 2012\n\nmodule numz\n!*************************************\n integer, parameter:: b8 = selected_real_kind(14) ! basic real types\n integer, parameter :: pmax=10\n real(b8) poly(0:pmax)\n integer np\nend module\n\n!myfunc: Evaluate a polynomial at a point (x)\n! The coefficients for the polynomial\n! are in the array poly. The order is\n! np.\n\nfunction myfunc(x)\n use numz\n implicit none\n real(b8) x,myfunc,sum,xt\n integer i\n sum=poly(0)\n xt=x\n do i=1,np\n sum=sum+xt*poly(i)\n xt=xt*x\n enddo\n myfunc=sum\nend function\n \n! trapzd and qsimp are adapted from:\n! Numerical Recipes: the art of scientific computing /William H. Press ... [et al.].\n! with various additions and years of publication\n! Publisher:\tCambridge University Press\n!\n! Taken together trapzd and qsimp calculate the integral \n! of a function over same range, a to b. The function to\n! be integrated is passed in as an argument. EPS is the\n! desired accuracy and JMAX is the maximum number of times\n! that trapzd is called, each time refining the previous\n! estimate of the integral. The routine trapzd integrates\n! by the trapezoidal rule.\n\nsubroutine trapzd(func,a,b,s,n)\n use numz\n implicit none\n real(b8) :: func,a,b,s\n integer n\n external func\n real(b8) :: del,sum,x\n integer it,tnm,j\n if (n.eq.1) then\n s=0.5_b8*(b-a)*(func(a)+func(b))\n else\n it=2**(n-2)\n tnm=it\n del=(b-a)/tnm\n x=a+0.5_b8*del\n sum=0.0_b8\n do j=1,it\n sum=sum+func(x)\n x=x+del\n enddo\n s=0.5_b8*(s+(b-a)*sum/tnm)\n endif\nend subroutine\n\nsubroutine qsimp(func,a,b,s,eps,jmax)\n use numz\n implicit none\n integer jmax\n real(b8) :: a,b,func,s,eps\n external func\n real(b8) ost,os,st\n integer j\n ost=-1.e30\n os= -1.e30\n do j=1,jmax\n! write(*,*)j\n call trapzd(func,a,b,st,j)\n s=(4.*st-ost)/3.\n if (abs(s-os).lt.eps*abs(os)) return\n if (s.eq.0..and.os.eq.0..and.j.gt.6) return\n os=s\n ost=st\n enddo\n write(*,*)'too many steps in qsimp'\nend subroutine\n\nprogram doint\n use numz\n implicit none\n external myfunc\n real(b8) a,b,s,eps,myfunc\n character (len=100)::aform\n integer jmax,i\n aform='(\"Integral over the range \",f10.5,\" to \",f10.5,\"=\",g20.7)'\n! We are integrating a polynomial read in the order (np)\n! then the coefficients (poly).\n read(*,*)np\n read(*,*)(poly(i),i=0,np)\n! Read the lower (a) and upper (b) integrations bounds.\n read(*,*)a,b\n! Read the desired accuracy (eps) and the \n! maximum subdivisions for the trapezoidal\n! integration (jmax).\n read(*,*)eps,jmax\n call qsimp(myfunc,a,b,s,eps,jmax)\n write(*,aform)a,b,s\nend program\n\n \n", "meta": {"hexsha": "f05e160cca793cb19169474f8622d3ff83eaea48", "size": 3458, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "assignments/doint.f90", "max_stars_repo_name": "timkphd/examples", "max_stars_repo_head_hexsha": "04c162ec890a1c9ba83498b275fbdc81a4704062", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-11-01T00:29:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-24T19:09:47.000Z", "max_issues_repo_path": "assignments/doint.f90", "max_issues_repo_name": "timkphd/examples", "max_issues_repo_head_hexsha": "04c162ec890a1c9ba83498b275fbdc81a4704062", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-09T01:59:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-09T01:59:47.000Z", "max_forks_repo_path": "assignments/doint.f90", "max_forks_repo_name": "timkphd/examples", "max_forks_repo_head_hexsha": "04c162ec890a1c9ba83498b275fbdc81a4704062", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.4264705882, "max_line_length": 84, "alphanum_fraction": 0.6087333719, "num_tokens": 1067, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7524557418882514}} {"text": "! Func Module\r\n\r\n module Func\r\n use Util\r\n implicit none\r\n\r\n! >> F1 <<\r\n character (len = *), parameter :: F1_NAME = \"f(x) = log(cosh(x * √(g * j))) - 50\"\r\n double precision :: F1_G = 9.80600D0\r\n double precision :: F1_K = 0.00341D0\r\n\r\n! >> F2 <<\r\n character (len = *), parameter :: F2_NAME = \"f(x) = 4 * cos(x) - exp(2 * x)\"\r\n\r\n! >> F3 <<\r\n character (len = *), parameter :: F3_NAME = \"f(x, y, z) :=\"//ENDL// &\r\n \"16x⁴ + 16y⁴ + z⁴ = 16\"//ENDL// &\r\n \"x² + y² + x² = 3\"//ENDL// &\r\n \"x³ - y + z = 1\"\r\n integer :: F3_N = 3\r\n\r\n! >> F4 <<\r\n character (len = *), parameter :: F4_NAME = \"f(c2, c3, c4) :=\"//ENDL// &\r\n \"c2² + 2 c3² + 6 c4² = 1\"//ENDL// &\r\n \"8 c3³ + 6 c3 c2² + 36 c3 c2 c4 + 108 c3 c4⁴ = θ1\"//ENDL// &\r\n \"60 * c3⁴ + 60 * c3² * c2² + 576 * c3² * c2 * c4 + \"// & \r\n \"2232 * c3² * c4² + 252 * c4² * c2² + \"// &\r\n \"1296 * c4³ c2 + 3348 c4⁴ + 24 c2³ c4 + 3 c2 = θ2\"\r\n double precision :: F4_TT1(3) = (/ 0.0D0, 0.75D0, 0.000D0 /)\r\n double precision :: F4_TT2(3) = (/ 3.0D0, 6.50D0, 11.667D0 /)\r\n double precision :: F4_T1 = 0.0D0\r\n double precision :: F4_T2 = 0.0D0\r\n integer :: F4_N = 3\r\n\r\n! >> F5 <<\r\n character (len = *), parameter :: F5_NAME = \"f(x) = b1 + b2 x^b3\"\r\n integer :: F5_N = 3\r\n \r\n! >> F6 <<\r\n character (len = *), parameter :: F6_NAME = \"f(x) = exp(-x²/2) / √(2 π)\"\r\n\r\n! >> F7 <<\r\n character (len = *), parameter :: F7_NAME = \"Sσ(ω) = RAO(ω)² Sη(ω)\"//ENDL//TAB// &\r\n \"RAO(ω) = 1 / √((1 - (ω/ωn)²)² + (2ξω/ωn)²)\"\r\n\r\n character (len = *), parameter :: F7a_NAME = \"Sη(ω) = 2\"\r\n character (len = *), parameter :: F7b_NAME = \"Sη(ω) = 2\"\r\n\r\n! >> F8 <<\r\n character (len = *), parameter :: F8_NAME = \"Sσ(ω) = RAO(ω)² Sη(ω)\"//ENDL//TAB// &\r\n \"RAO(ω) = 1 / √((1 - (ω/ωn)²)² + (2ξω/ωn)²)\"\r\n\r\n character (len = *), parameter :: F8a_NAME = \"Sη(ω) = ((4 π³ Hs²) / (ω⁵ Tz⁴)) exp(-(16 π³) / (ω⁴ Tz⁴))\"\r\n character (len = *), parameter :: F8b_NAME = \"Sη(ω) = ((4 π³ Hs²) / (ω⁵ Tz⁴)) exp(-(16 π³) / (ω⁴ Tz⁴))\"\r\n\r\n\r\n! >> F13 <<\r\n character (len = *), parameter :: F13_NAME = \"y'(t) = -2 t y(t)²\"//ENDL//\"y(0) = 1\"\r\n double precision :: F13_A = 0.0D0\r\n double precision :: F13_B = 10.0D0\r\n double precision :: F13_Y0 = 1.0D0\r\n\r\n! >> F14 <<\r\n character (len = *), parameter :: F14_NAME = \"m y''(t) + c y'(t) + k y(t) = F(t)\"//ENDL// &\r\n \"m = 1; c = 0.2; k = 1;\"//ENDL// &\r\n \"F(t) = 2 sin(w t) + sin(2 w t) + cos(3 w t)\"//ENDL// &\r\n \"w = 0.5;\"//ENDL// &\r\n \"y'(0) = 0; y(0) = 0;\"\r\n double precision :: F14_M = 1.0D0\r\n double precision :: F14_C = 0.2D0\r\n double precision :: F14_K = 1.0D0\r\n double precision :: F14_W = 0.5D0\r\n double precision :: F14_Y0 = 0.0D0\r\n double precision :: F14_DY0 = 0.0D0\r\n double precision :: F14_A = 0.0D0\r\n double precision :: F14_B = 100.0D0\r\n\r\n! >> F15 <<\r\n character (len = *), parameter :: F15_NAME = \"z''(t) = -g -k z'(t) |z'(t)|\"//ENDL// &\r\n \"z'(0) = 0; z(0) = 0;\"//ENDL// &\r\n \"g = 9.806; k = 1;\"\r\n double precision :: F15_G = 9.80600D0\r\n double precision :: F15_KD = 1.0D0\r\n double precision :: F15_BY0 = 100.0D0\r\n double precision :: F15_Y0 = 0.0D0\r\n double precision :: F15_DY0 = 0.0D0\r\n double precision :: F15_A = 0.0D0\r\n double precision :: F15_B = 20.0D0\r\n\r\n\r\n\r\n double precision :: t1 = 0.0D0\r\n double precision :: t2 = 0.0D0\r\n\r\n double precision :: wn = 1.00D0\r\n double precision :: xi = 0.05D0\r\n double precision :: Hs = 3.0D0\r\n double precision :: Tz = 5.0D0\r\n\r\n character (len = *), parameter :: F9_NAME = \"f(x) = 2 + 2x - x² + 3x³\"\r\n\r\n character (len = *), parameter :: F10_NAME = \"f(x) = 1 / (1 + x²)\"\r\n\r\n character (len = *), parameter :: F11_NAME = \"f(x) = exp(- x²/2) / √(2 π)\"\r\n character (len = *), parameter :: F12_NAME = \"f(x) = x² exp(- x²/2) / √(2 π)\"\r\n\r\n! >> L5-QE <<\r\n character (len = *), parameter :: FL5_QE1_NAME = 'f(x) = x³ + exp(-x)'\r\n character (len = *), parameter :: DFL5_QE1_NAME = \"f'(x) = 3 x² - exp(-x)\"\r\n character (len = *), parameter :: FL5_QE2_NAME = 'f(x) = ³√x + log(x)'\r\n character (len = *), parameter :: DFL5_QE2_NAME = \"f'(x) = 1 / (3 ³√x²) + (1 / x)\"\r\n character (len = *), parameter :: FL5_QE3_NAME = 'f(x) = 1 - exp(-x² / 25)'\r\n character (len = *), parameter :: DFL5_QE3_NAME = \"f'(x) = (2 x / 25) exp(-x² / 25)\"\r\n\r\n \r\n contains\r\n\r\n function FL5_QE1(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n y = x ** 3 + DEXP(-x)\r\n return\r\n end function\r\n\r\n function DFL5_QE1(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n y = 3 * x ** 2 - DEXP(-x)\r\n return\r\n end function\r\n\r\n function FL5_QE2(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n y = x ** (1.0D0/3.0D0) + DLOG(x)\r\n return\r\n end function\r\n\r\n function DFL5_QE2(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n y = 1 / (3 * x ** (2.0D0/3.0D0)) + (1 / x)\r\n return\r\n end function\r\n\r\n function FL5_QE3(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n y = 1 - DEXP(-(x ** 2) / 25)\r\n return\r\n end function\r\n\r\n function DFL5_QE3(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n y = (2 * X) / (25 * DEXP((x ** 2) / 25))\r\n return\r\n end function\r\n\r\n\r\n function f1(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n y = DLOG(DCOSH(x * DSQRT(F1_G * F1_K))) - 50.0D0\r\n return\r\n end function\r\n\r\n function df1(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n y = (DSINH(x * DSQRT(F1_G * F1_K)) * DSQRT(F1_G * F1_K)) / DCOSH(x * DSQRT(F1_G * F1_K))\r\n return\r\n end function\r\n \r\n function f2(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n y = 4 * DCOS(x) - DEXP(2 * x)\r\n return\r\n end function\r\n\r\n function df2(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n y = - 4 * DSIN(x) - 2 * DEXP(2 * x)\r\n return\r\n end function\r\n \r\n! ======= R^n -> R^n functions =======\r\n function f3(x, n) result (y)\r\n! R³ -> R³ (n == 3)\r\n implicit none\r\n integer :: n\r\n double precision, dimension(n) :: x, y\r\n\r\n y = (/ &\r\n (16 * x(1) ** 4 + 16 * x(2) ** 4 + x(3) ** 4) - 16.0D0, &\r\n x(1) ** 2 + x(2) ** 2 +x(3) ** 2 - 3.0D0, &\r\n x(1) ** 3 - x(2) + x(3) - 1.0D0 &\r\n /)\r\n return\r\n end function\r\n\r\n! ========== Derivative ===========\r\n function df3(x, n) result (J)\r\n implicit none\r\n integer :: n\r\n double precision, dimension(n) :: x\r\n double precision, dimension(n, n) :: J\r\n\r\n J(1, :) = (/ 64 * x(1) ** 3, 64 * x(2) ** 3, 4 * x(3) ** 3 /)\r\n J(2, :) = (/ 2 * x(1) , 2 * x(2) , 2 * x(3) /)\r\n J(3, :) = (/ 3 * x(1) ** 2, -1.0D0, 1.0D0 /)\r\n return\r\n end function\r\n\r\n! ================== Another function =====================\r\n function f4(x, n) result (y)\r\n implicit none\r\n integer :: n\r\n double precision, dimension(n) :: x, y\r\n y = (/ &\r\n x(1)**2+2*x(2)**2+6*x(3)**2, &\r\n 2*x(2)*(3*x(1)**2+4*x(2)**2+18*x(1)*x(3)+54*x(3)**4), &\r\n 3*(x(1)+20*x(1)**2*x(2)**2+20*x(2)**4+8*x(1)*(x(1)**2+24*x(2)**2)*x(3)+&\r\n 12*(7*x(1)**2+62*x(2)**2)*x(3)**2+432*x(1)*x(3)**3+1116*x(3)**4)&\r\n /) - (/ 1.0D0, F4_T1, F4_T2 /)\r\n return\r\n end function\r\n\r\n! ========== Derivatives =========== \r\n function df4(x, n) result (J)\r\n! R³ -> R³x3 (n == 3)\r\n implicit none\r\n integer :: n\r\n double precision :: x(n), J(n, n)\r\n\r\n J(1, :) = (/ &\r\n 2*x(1), &\r\n 4*x(2), &\r\n 12*x(3) &\r\n /)\r\n J(2, :) = (/ &\r\n 12*x(1)*x(2)+36*x(2)*x(3), &\r\n 6*x(1)**2+24*x(2)**2+36*x(1)*x(3)+108*x(3)**4, &\r\n 36*x(1)*x(2)+432*x(2)*x(3)**3 &\r\n /)\r\n J(3, :) = (/ &\r\n 3+120*x(1)*x(2)**2+72*x(1)**2*x(3)+576*x(2)**2*x(3)+504*x(1)*x(3)**2+1296*x(3)**3, &\r\n 120*x(1)**2*x(2)+240*x(2)**3+1152*x(1)*x(2)*x(3)+4464*x(2)*x(3)**2, &\r\n 24*x(1)**3+576*x(1)*x(2)**2+504*x(1)**2*x(3)+4464*x(2)**2*x(3)+3888*x(1)*x(3)**2+13392*x(3)**3 &\r\n /)\r\n return\r\n end function\r\n\r\n! ============ One more function =============\r\n function f5(x, b, m, n) result (z)\r\n implicit none\r\n integer :: m, n\r\n double precision, dimension(m), intent(in) :: b\r\n double precision, dimension(n), intent(in) :: x\r\n double precision, dimension(n) :: z\r\n\r\n z = b(1) + (b(2) * (x ** b(3)))\r\n return\r\n end function\r\n\r\n! ========= Derivatives ==========\r\n function df5(x, b, m, n) result (J)\r\n implicit none\r\n integer :: m, n\r\n double precision, dimension(m), intent(in) :: b\r\n double precision, dimension(n), intent(in) :: x\r\n double precision, dimension(n, m) :: J\r\n! m == 3\r\n J(:, 1) = 1.0D0\r\n J(:, 2) = x ** b(3)\r\n J(:, 3) = b(2) * DLOG(x) * (x ** b(3))\r\n return\r\n end function\r\n\r\n! ======== Function 6 ============\r\n function f6(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n\r\n y = DEXP(-(x*x)/2) / DSQRT(2 * PI)\r\n return\r\n end function\r\n\r\n! ======== Functions 7 & 8 ============\r\n function RAO(w) result (z)\r\n implicit none\r\n double precision :: w, z\r\n\r\n z = 1.0 / DSQRT((1.0D0 - (w/wn) ** 2) ** 2 + (2 * xi * (w/wn)) ** 2)\r\n end function\r\n\r\n function Sn1(w) result (z)\r\n implicit none\r\n double precision :: w, z\r\n z = 2.0D0\r\n return\r\n end function\r\n\r\n function Sn2(w) result (z)\r\n implicit none\r\n double precision :: w, z\r\n z = (4 * (Hs**2) * (PI**3)) / ( DEXP( (16 * (PI**3))/((Tz*w)**4) ) * (Tz**4) * (w**5) )\r\n return\r\n end function\r\n\r\n function Ss(w, Sn) result (z)\r\n implicit none\r\n double precision :: w, z\r\n interface\r\n function Sn(w) result (z)\r\n implicit none\r\n double precision :: w, z\r\n end function\r\n end interface\r\n z = (RAO(w) ** 2) * Sn(w)\r\n return\r\n end function\r\n\r\n function f7a(w) result (z)\r\n implicit none\r\n double precision :: w, z\r\n z = Ss(w, Sn1)\r\n return\r\n end function\r\n\r\n function f7b(w) result (z)\r\n implicit none\r\n double precision :: w, z\r\n z = (w ** 2) * Ss(w, Sn1)\r\n return\r\n end function\r\n\r\n function f8a(w) result (z)\r\n implicit none\r\n double precision :: w, z\r\n z = Ss(w, Sn2)\r\n return\r\n end function\r\n\r\n function f8b(w) result (z)\r\n implicit none\r\n double precision :: w, z\r\n z = (w ** 2) * Ss(w, Sn2)\r\n return\r\n end function\r\n\r\n! ========== Function 9 ==============\r\n function f9(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n y = 2.0D0 + 2.0D0 * x - x ** 2 + 3.0D0 * x ** 3\r\n return\r\n end function\r\n\r\n! ========== Function 10 ==============\r\n function f10(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n y = 1.0D0 / (1.0D0 + x ** 2)\r\n return\r\n end function\r\n\r\n! ========== Function 11 ==============\r\n function f11a(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n y = DEXP((x ** 2) / 2) / DSQRT(8 * PI)\r\n return\r\n end function\r\n\r\n function f11b(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n y = DEXP(-(x ** 2) / 2) / DSQRT(8 * PI)\r\n return\r\n end function\r\n\r\n! ========== Function 12 ==============\r\n function f12(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n y = (x ** 2) * DEXP((x ** 2) / 2) / DSQRT(2 * PI)\r\n return\r\n end function\r\n\r\n! ========== Function 13 ==============\r\n function df13(t, y) result (u)\r\n implicit none\r\n double precision :: t, y, u\r\n u = - 2 * t * (y ** 2)\r\n return\r\n end function\r\n\r\n function f13(t) result (y)\r\n implicit none\r\n double precision :: t, y\r\n y = 1 / (1 + (t**2))\r\n return\r\n end function\r\n\r\n! ========== Function 14 ===============\r\n function F14_F(t) result (y)\r\n implicit none\r\n double precision :: t, y\r\n y = 2 * DSIN(F14_W * t) + DSIN(2 * F14_W * t) + DCOS(3 * F14_W * t)\r\n return\r\n end function\r\n\r\n function d2f14(t, y, dy) result (u)\r\n implicit none\r\n double precision :: t, y, dy, u\r\n u = (F14_F(t) - F14_K * y - F14_C * dy) / F14_M\r\n return\r\n end function\r\n\r\n! ========== Function 15 ===============\r\n function d2f15(t, y, dy) result (u)\r\n implicit none\r\n double precision :: t, y, dy, u\r\n if (y >= 0) then\r\n u = - F15_G\r\n else\r\n u = - F15_G - F15_KD * dy * DABS(dy)\r\n end if\r\n return\r\n end function\r\n\r\n end module Func", "meta": {"hexsha": "95589bc4149a5fc774684f9e3c60ce114df6058e", "size": 13705, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/funcmod.f95", "max_stars_repo_name": "pedromxavier/COC473", "max_stars_repo_head_hexsha": "2bab0c45de6c13bba7ea7580992e1b8d090f3257", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/funcmod.f95", "max_issues_repo_name": "pedromxavier/COC473", "max_issues_repo_head_hexsha": "2bab0c45de6c13bba7ea7580992e1b8d090f3257", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/funcmod.f95", "max_forks_repo_name": "pedromxavier/COC473", "max_forks_repo_head_hexsha": "2bab0c45de6c13bba7ea7580992e1b8d090f3257", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.5057471264, "max_line_length": 112, "alphanum_fraction": 0.4304268515, "num_tokens": 4882, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396142, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7523778057401403}} {"text": "module util\n\nimplicit none\n\nreal(kind=8),parameter :: pi=3.141592653589793238d0\nreal(kind=8),parameter :: angbohr = 1.889725989d0\nreal(kind=8),parameter :: bohr2ang = 0.529177d0 \nreal(kind=8),parameter :: mass_proton = 1.6726219d-27\nreal(kind=8),parameter :: eleVolt = 1.602176634d-19\ncomplex(kind=8),parameter :: i_imag=cmplx(0,1,kind=8)\ncontains\n\nfunction linspace(k1,k2,nk,endpoint) result(k)\n\nreal(kind=8) :: k1,k2\ninteger(kind=4) :: nk\ninteger(kind=4) :: i\nreal(kind=8),allocatable :: k(:)\ninteger(kind=4) :: endpoint\n\nallocate(k(nk))\nif (endpoint .ne. 0) then\n do i = 1,nk\n k(i) = dble(i-1)/dble(nk-1)*(k2-k1) + k1 \n end do\nelse\n do i = 1,nk\n k(i) = dble(i-1)/dble(nk)*(k2-k1) + k1 \n end do\nend if\n\nend function\n\n! matrix inversion for real matrix\nfunction inv_real(A) result(Ainv)\nreal(kind=8), dimension(:,:), intent(in) :: A\nreal(kind=8), dimension(size(A,1),size(A,2)) :: Ainv\n\nreal(kind=8), dimension(size(A,1)) :: work ! work array for LAPACK\ninteger, dimension(size(A,1)) :: ipiv ! pivot indices\ninteger :: n, info\n\n! External procedures defined in LAPACK\nexternal DGETRF\nexternal DGETRI\n\n! Store A in Ainv to prevent it from being overwritten by LAPACK\nAinv = A\nn = size(A,1)\n\n! DGETRF computes an LU factorization of a general M-by-N matrix A\n! using partial pivoting with row interchanges.\ncall DGETRF(n, n, Ainv, n, ipiv, info)\n\nif (info /= 0) then\n stop 'Matrix is numerically singular!'\nend if\n\n! DGETRI computes the inverse of a matrix using the LU factorization\n! computed by DGETRF.\ncall DGETRI(n, Ainv, n, ipiv, work, n, info)\n\nif (info /= 0) then\n stop 'Matrix inversion failed!'\nend if\nend function inv_real\nFUNCTION cross(a, b)\n real(kind=8) :: cross(3)\n real(kind=8),dimension(3),INTENT(IN) :: a, b\n\n cross(1) = a(2) * b(3) - a(3) * b(2)\n cross(2) = a(3) * b(1) - a(1) * b(3)\n cross(3) = a(1) * b(2) - a(2) * b(1)\nEND FUNCTION cross\nsubroutine eigenH(A,w,vecr)\n\ninteger(kind=4) :: nwork=1\ninteger(kind=4) :: info\nreal(kind=8),allocatable :: rwork(:)\ncomplex(kind=8),allocatable :: work(:)\ncomplex(kind=8),intent(in) :: A(:,:)\ncomplex(kind=8),dimension(size(A,1),size(A,2)) :: At\nreal(kind=8),dimension(size(A,1)),intent(out) :: w\ncomplex(kind=8),dimension(size(A,1),size(A,2)),&\n intent(out) :: vecr\ninteger(kind=4) :: n\n\nn = size(A,1)\nAt = A\nallocate(work(nwork))\nallocate(rwork(3*n))\n\n! compute the eigenvalue and eigenvector\n! of Hermitian matrix\n! info = 0, the eigenvalues in ascending order\ncall zheev(\"V\",\"U\",n,At(:,:),n,w,work,-1,rwork,info)\n\nif(real(work(1)).gt.nwork) then\n nwork=idnint(2*real(work(1)))\n deallocate(work)\n allocate(work(nwork))\nend if\n\ncall zheev(\"V\",\"U\",n,At(:,:),n,w,work,nwork,rwork,info)\nvecr = At\nend subroutine\n\nfunction hermitian(A) result(B)\n\n implicit none\n\n complex(kind=8) :: A(:,:)\n complex(kind=8) :: B(size(A,1),size(A,2))\n\n B = 0.5*(A+transpose(dconjg(A)))\n\nend function hermitian\n\nfunction participation(A) result(B)\n\n implicit none\n\n complex(kind=8) :: A(:)\n integer(kind=4) :: n,i,j\n real(kind=8) :: B\n complex(kind=8) :: C,D\n\n n = size(A,1)\n C = 0.0d0\n D = 0.0d0\n\n do i = 1,n/3\n C = C + dot_product(A(3*(i-1)+1:3*i),A(3*(i-1)+1:3*i))\n D = D + dot_product(A(3*(i-1)+1:3*i),A(3*(i-1)+1:3*i))**2\n end do\n C = C**2\n D = D* n/3\n B = C/D\n\n \nend function participation\n\nfunction taumn(Temp,taum,taun,wm,wn) result(tmn)\n \n implicit none\n\n real(kind=8) :: temp,tmn,taum,taun,wm,wn\n\n tmn = (wm+wn)**2/4/wm/wn*(taum+taun)/((taum+taun)**2+(wm-wn)**2)+&\n (wm-wn)**2/4/wm/wn*(taum+taun)/((taum+taun)**2+(wm+wn)**2)\n\n\n\nend function\n\n\n\n\n\n\nend module\n\n", "meta": {"hexsha": "396fa643ff9df85f19ded478be639a3aa60608cb", "size": 3655, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ph/util.f90", "max_stars_repo_name": "KitchenSong/phinfortran", "max_stars_repo_head_hexsha": "ce5d6fcd491da1540b22f0eac0491c6077d3a1d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ph/util.f90", "max_issues_repo_name": "KitchenSong/phinfortran", "max_issues_repo_head_hexsha": "ce5d6fcd491da1540b22f0eac0491c6077d3a1d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ph/util.f90", "max_forks_repo_name": "KitchenSong/phinfortran", "max_forks_repo_head_hexsha": "ce5d6fcd491da1540b22f0eac0491c6077d3a1d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.4233128834, "max_line_length": 70, "alphanum_fraction": 0.6300957592, "num_tokens": 1348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.7523208939104051}} {"text": "REAL*8 function kern_sqexp(r)\nimplicit none\nREAL*8, intent(in) :: r\nkern_sqexp = exp(-0.5d0*r**2)\nend function\nREAL*8 function dkern_sqexp(r)\nimplicit none\nREAL*8, intent(in) :: r\ndkern_sqexp = -r*exp(-0.5d0*r**2)\nend function\nREAL*8 function d2kern_sqexp(r)\nimplicit none\nREAL*8, intent(in) :: r\nd2kern_sqexp = (r**2 - 1)*exp(-0.5d0*r**2)\nend function\nREAL*8 function kern_matern32(r)\nimplicit none\nREAL*8, intent(in) :: r\nkern_matern32 = (sqrt(3.0d0)*r + 1)*exp(-1.7320508075688773d0*r)\nend function\nREAL*8 function dkern_matern32(r)\nimplicit none\nREAL*8, intent(in) :: r\ndkern_matern32 = -3*r*exp(-1.7320508075688773d0*r)\nend function\nREAL*8 function d2kern_matern32(r)\nimplicit none\nREAL*8, intent(in) :: r\nd2kern_matern32 = 3*(sqrt(3.0d0)*r - 1)*exp(-1.7320508075688773d0*r)\nend function\nREAL*8 function kern_matern52(r)\nimplicit none\nREAL*8, intent(in) :: r\nkern_matern52 = ((5.0d0/3.0d0)*r + sqrt(5.0d0)*r + 1)*exp( &\n -2.2360679774997897d0*r)\nend function\nREAL*8 function dkern_matern52(r)\nimplicit none\nREAL*8, intent(in) :: r\ndkern_matern52 = -1.0d0/3.0d0*(5*sqrt(5.0d0)*r + 15*r - 5)*exp( &\n -2.2360679774997897d0*r)\nend function\nREAL*8 function d2kern_matern52(r)\nimplicit none\nREAL*8, intent(in) :: r\nd2kern_matern52 = (5.0d0/3.0d0)*(5*r + 3*sqrt(5.0d0)*r - 2*sqrt(5.0d0) - &\n 3)*exp(-2.2360679774997897d0*r)\nend function\nREAL*8 function kern_wend4(r)\nimplicit none\nREAL*8, intent(in) :: r\nkern_wend4 = (1 - r)**4*(4*r + 1)\nend function\nREAL*8 function dkern_wend4(r)\nimplicit none\nREAL*8, intent(in) :: r\ndkern_wend4 = 20*r*(r - 1)**3\nend function\nREAL*8 function d2kern_wend4(r)\nimplicit none\nREAL*8, intent(in) :: r\nd2kern_wend4 = (r - 1)**2*(80*r - 20)\nend function\n", "meta": {"hexsha": "1336fef68d9ad238492ffe34ee540e9f4152dd5b", "size": 1698, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "profit/sur/backend/kernels_base.f90", "max_stars_repo_name": "krystophny/profit", "max_stars_repo_head_hexsha": "c6316c9df7cfaa7b30332fdbbf85ad27175eaf92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2019-12-03T14:11:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T13:44:06.000Z", "max_issues_repo_path": "profit/sur/backend/kernels_base.f90", "max_issues_repo_name": "krystophny/profit", "max_issues_repo_head_hexsha": "c6316c9df7cfaa7b30332fdbbf85ad27175eaf92", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 118, "max_issues_repo_issues_event_min_datetime": "2019-11-16T19:51:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T13:52:00.000Z", "max_forks_repo_path": "profit/sur/backend/kernels_base.f90", "max_forks_repo_name": "krystophny/profit", "max_forks_repo_head_hexsha": "c6316c9df7cfaa7b30332fdbbf85ad27175eaf92", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2020-06-08T07:22:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-21T14:12:21.000Z", "avg_line_length": 26.53125, "max_line_length": 74, "alphanum_fraction": 0.7037691402, "num_tokens": 714, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067195846919, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.7522964060279346}} {"text": "\nmodule dz_module\n\n ! Module parameters:\n\n real(kind=8), parameter :: theta = 15.d0 * acos(-1.d0) / 180.d0\n real(kind=8), parameter :: costh = cos(theta)\n real(kind=8), parameter :: sinth = sin(theta)\n real(kind=8), parameter :: tanth = tan(theta)\n\n real(kind=8), parameter :: width = 0.680d0\n real(kind=8), parameter :: length = 0.395d0\n real(kind=8), parameter :: xlength = length*costh\n\n real(kind=8), parameter :: epsilon = 0.717d0\n real(kind=8), parameter :: C = acosh(1. / epsilon)\n real(kind=8), parameter :: Tprime = 0.082 + 0.004d0\n real(kind=8), parameter :: kb = 2*C / length\n real(kind=8), parameter :: kw = 2*C / width\n\n\n ! Module variables:\n\n real(kind=8) :: x4zeroin, eta4zeroin, xic, d, x0, dxfine\n real(kind=8), dimension(100) :: tk\n real(kind=8), dimension(100,7) :: sk\n integer :: scolumn \n\n save \n\ncontains\n\n real (kind=8) function zeta_fcn(xi, eta)\n implicit none\n real (kind=8), intent(in) :: xi,eta\n\n zeta_fcn = dmax1(0.d0, (Tprime/(1.-epsilon)) * &\n (1./(cosh(kb*xi)*cosh(kw*eta)) - epsilon))\n\n end function zeta_fcn\n\n \n subroutine read_ts()\n ! Read the data file and set tk and sk arrays.\n implicit none\n integer :: i, k\n open(unit=10,file='../kinematics-new.txt',status='old',form='formatted')\n\n do i=1,100\n read(10,*) tk(i),(sk(i,k),k=1,7)\n !write(6,*) i,tk(i),sk(i,1)\n enddo\n end subroutine read_ts\n\n\n real (kind=8) function s_fcn(t)\n ! Interpolate from sk array to the current time.\n ! Use column of sk determined by scolumn.\n implicit none\n real (kind=8), intent(in) :: t\n real (kind=8) :: dtk\n integer :: k\n\n k = min(100, int(t*10)+1)\n dtk = 0.1d0\n s_fcn = (sk(k,scolumn)*(tk(k+1)-t) + sk(k+1,scolumn)*(t-tk(k))) / dtk\n write(26,*) \"+++ t,k,dtk,sk,s_fcn: \",t,k,dtk,sk(k,scolumn),s_fcn\n \n\n end function s_fcn\n\n\n real (kind=8) function fxi(xi)\n ! Function we will apply zeroin to in order to find xi \n ! corresponding to a given x value.\n\n implicit none\n real (kind=8), intent(in) :: xi\n\n fxi = xi*costh + zeta_fcn(xi - xic, eta4zeroin)*sinth - x4zeroin\n\n end function fxi\n\n\nend module dz_module\n\n", "meta": {"hexsha": "3ad822df7f176db40c264f87d1443613562153a2", "size": 2253, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/geoclaw/benchmark_3/dz_module.f90", "max_stars_repo_name": "mandli/coastal", "max_stars_repo_head_hexsha": "8c80a4c740f92ea83b54c8a5432d11058c0d3476", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/geoclaw/benchmark_3/dz_module.f90", "max_issues_repo_name": "mandli/coastal", "max_issues_repo_head_hexsha": "8c80a4c740f92ea83b54c8a5432d11058c0d3476", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/geoclaw/benchmark_3/dz_module.f90", "max_forks_repo_name": "mandli/coastal", "max_forks_repo_head_hexsha": "8c80a4c740f92ea83b54c8a5432d11058c0d3476", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.8965517241, "max_line_length": 78, "alphanum_fraction": 0.5849977807, "num_tokens": 752, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067228145365, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7522963972942319}} {"text": "*DECK DRF\n DOUBLE PRECISION FUNCTION DRF (X, Y, Z, IER)\nC***BEGIN PROLOGUE DRF\nC***PURPOSE Compute the incomplete or complete elliptic integral of the\nC 1st kind. For X, Y, and Z non-negative and at most one of\nC them zero, RF(X,Y,Z) = Integral from zero to infinity of\nC -1/2 -1/2 -1/2\nC (1/2)(t+X) (t+Y) (t+Z) dt.\nC If X, Y or Z is zero, the integral is complete.\nC***LIBRARY SLATEC\nC***CATEGORY C14\nC***TYPE DOUBLE PRECISION (RF-S, DRF-D)\nC***KEYWORDS COMPLETE ELLIPTIC INTEGRAL, DUPLICATION THEOREM,\nC INCOMPLETE ELLIPTIC INTEGRAL, INTEGRAL OF THE FIRST KIND,\nC TAYLOR SERIES\nC***AUTHOR Carlson, B. C.\nC Ames Laboratory-DOE\nC Iowa State University\nC Ames, IA 50011\nC Notis, E. M.\nC Ames Laboratory-DOE\nC Iowa State University\nC Ames, IA 50011\nC Pexton, R. L.\nC Lawrence Livermore National Laboratory\nC Livermore, CA 94550\nC***DESCRIPTION\nC\nC 1. DRF\nC Evaluate an INCOMPLETE (or COMPLETE) ELLIPTIC INTEGRAL\nC of the first kind\nC Standard FORTRAN function routine\nC Double precision version\nC The routine calculates an approximation result to\nC DRF(X,Y,Z) = Integral from zero to infinity of\nC\nC -1/2 -1/2 -1/2\nC (1/2)(t+X) (t+Y) (t+Z) dt,\nC\nC where X, Y, and Z are nonnegative and at most one of them\nC is zero. If one of them is zero, the integral is COMPLETE.\nC The duplication theorem is iterated until the variables are\nC nearly equal, and the function is then expanded in Taylor\nC series to fifth order.\nC\nC 2. Calling sequence\nC DRF( X, Y, Z, IER )\nC\nC Parameters On entry\nC Values assigned by the calling routine\nC\nC X - Double precision, nonnegative variable\nC\nC Y - Double precision, nonnegative variable\nC\nC Z - Double precision, nonnegative variable\nC\nC\nC\nC On Return (values assigned by the DRF routine)\nC\nC DRF - Double precision approximation to the integral\nC\nC IER - Integer\nC\nC IER = 0 Normal and reliable termination of the\nC routine. It is assumed that the requested\nC accuracy has been achieved.\nC\nC IER > 0 Abnormal termination of the routine\nC\nC X, Y, Z are unaltered.\nC\nC\nC 3. Error Messages\nC\nC\nC Value of IER assigned by the DRF routine\nC\nC Value assigned Error Message Printed\nC IER = 1 MIN(X,Y,Z) .LT. 0.0D0\nC = 2 MIN(X+Y,X+Z,Y+Z) .LT. LOLIM\nC = 3 MAX(X,Y,Z) .GT. UPLIM\nC\nC\nC\nC 4. Control Parameters\nC\nC Values of LOLIM, UPLIM, and ERRTOL are set by the\nC routine.\nC\nC LOLIM and UPLIM determine the valid range of X, Y and Z\nC\nC LOLIM - Lower limit of valid arguments\nC\nC Not less than 5 * (machine minimum).\nC\nC UPLIM - Upper limit of valid arguments\nC\nC Not greater than (machine maximum) / 5.\nC\nC\nC Acceptable values for: LOLIM UPLIM\nC IBM 360/370 SERIES : 3.0D-78 1.0D+75\nC CDC 6000/7000 SERIES : 1.0D-292 1.0D+321\nC UNIVAC 1100 SERIES : 1.0D-307 1.0D+307\nC CRAY : 2.3D-2466 1.09D+2465\nC VAX 11 SERIES : 1.5D-38 3.0D+37\nC\nC\nC\nC ERRTOL determines the accuracy of the answer\nC\nC The value assigned by the routine will result\nC in solution precision within 1-2 decimals of\nC \"machine precision\".\nC\nC\nC\nC ERRTOL - Relative error due to truncation is less than\nC ERRTOL ** 6 / (4 * (1-ERRTOL) .\nC\nC\nC\nC The accuracy of the computed approximation to the integral\nC can be controlled by choosing the value of ERRTOL.\nC Truncation of a Taylor series after terms of fifth order\nC introduces an error less than the amount shown in the\nC second column of the following table for each value of\nC ERRTOL in the first column. In addition to the truncation\nC error there will be round-off error, but in practice the\nC total error from both sources is usually less than the\nC amount given in the table.\nC\nC\nC\nC\nC\nC Sample choices: ERRTOL Relative Truncation\nC error less than\nC 1.0D-3 3.0D-19\nC 3.0D-3 2.0D-16\nC 1.0D-2 3.0D-13\nC 3.0D-2 2.0D-10\nC 1.0D-1 3.0D-7\nC\nC\nC Decreasing ERRTOL by a factor of 10 yields six more\nC decimal digits of accuracy at the expense of one or\nC two more iterations of the duplication theorem.\nC\nC *Long Description:\nC\nC DRF Special Comments\nC\nC\nC\nC Check by addition theorem: DRF(X,X+Z,X+W) + DRF(Y,Y+Z,Y+W)\nC = DRF(0,Z,W), where X,Y,Z,W are positive and X * Y = Z * W.\nC\nC\nC On Input:\nC\nC X, Y, and Z are the variables in the integral DRF(X,Y,Z).\nC\nC\nC On Output:\nC\nC\nC X, Y, Z are unaltered.\nC\nC\nC\nC ********************************************************\nC\nC WARNING: Changes in the program may improve speed at the\nC expense of robustness.\nC\nC\nC\nC Special double precision functions via DRF\nC\nC\nC\nC\nC Legendre form of ELLIPTIC INTEGRAL of 1st kind\nC\nC -----------------------------------------\nC\nC\nC\nC 2 2 2\nC F(PHI,K) = SIN(PHI) DRF(COS (PHI),1-K SIN (PHI),1)\nC\nC\nC 2\nC K(K) = DRF(0,1-K ,1)\nC\nC\nC PI/2 2 2 -1/2\nC = INT (1-K SIN (PHI) ) D PHI\nC 0\nC\nC\nC\nC Bulirsch form of ELLIPTIC INTEGRAL of 1st kind\nC\nC -----------------------------------------\nC\nC\nC 2 2 2\nC EL1(X,KC) = X DRF(1,1+KC X ,1+X )\nC\nC\nC Lemniscate constant A\nC\nC -----------------------------------------\nC\nC\nC 1 4 -1/2\nC A = INT (1-S ) DS = DRF(0,1,2) = DRF(0,2,1)\nC 0\nC\nC\nC\nC -------------------------------------------------------------------\nC\nC***REFERENCES B. C. Carlson and E. M. Notis, Algorithms for incomplete\nC elliptic integrals, ACM Transactions on Mathematical\nC Software 7, 3 (September 1981), pp. 398-403.\nC B. C. Carlson, Computing elliptic integrals by\nC duplication, Numerische Mathematik 33, (1979),\nC pp. 1-16.\nC B. C. Carlson, Elliptic integrals of the first kind,\nC SIAM Journal of Mathematical Analysis 8, (1977),\nC pp. 231-242.\nC***ROUTINES CALLED D1MACH, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 790801 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 891009 Removed unreferenced statement labels. (WRB)\nC 891009 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 900510 Changed calls to XERMSG to standard form, and some\nC editorial changes. (RWC))\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE DRF\n CHARACTER*16 XERN3, XERN4, XERN5, XERN6\n INTEGER IER\n DOUBLE PRECISION LOLIM, UPLIM, EPSLON, ERRTOL, D1MACH\n DOUBLE PRECISION C1, C2, C3, E2, E3, LAMDA\n DOUBLE PRECISION MU, S, X, XN, XNDEV\n DOUBLE PRECISION XNROOT, Y, YN, YNDEV, YNROOT, Z, ZN, ZNDEV,\n * ZNROOT\n LOGICAL FIRST\n SAVE ERRTOL,LOLIM,UPLIM,C1,C2,C3,FIRST\n DATA FIRST /.TRUE./\nC\nC***FIRST EXECUTABLE STATEMENT DRF\nC\n IF (FIRST) THEN\n ERRTOL = (4.0D0*D1MACH(3))**(1.0D0/6.0D0)\n LOLIM = 5.0D0 * D1MACH(1)\n UPLIM = D1MACH(2)/5.0D0\nC\n C1 = 1.0D0/24.0D0\n C2 = 3.0D0/44.0D0\n C3 = 1.0D0/14.0D0\n ENDIF\n FIRST = .FALSE.\nC\nC CALL ERROR HANDLER IF NECESSARY.\nC\n DRF = 0.0D0\n IF (MIN(X,Y,Z).LT.0.0D0) THEN\n IER = 1\n WRITE (XERN3, '(1PE15.6)') X\n WRITE (XERN4, '(1PE15.6)') Y\n WRITE (XERN5, '(1PE15.6)') Z\n CALL XERMSG ('SLATEC', 'DRF',\n * 'MIN(X,Y,Z).LT.0 WHERE X = ' // XERN3 // ' Y = ' // XERN4 //\n * ' AND Z = ' // XERN5, 1, 1)\n RETURN\n ENDIF\nC\n IF (MAX(X,Y,Z).GT.UPLIM) THEN\n IER = 3\n WRITE (XERN3, '(1PE15.6)') X\n WRITE (XERN4, '(1PE15.6)') Y\n WRITE (XERN5, '(1PE15.6)') Z\n WRITE (XERN6, '(1PE15.6)') UPLIM\n CALL XERMSG ('SLATEC', 'DRF',\n * 'MAX(X,Y,Z).GT.UPLIM WHERE X = ' // XERN3 // ' Y = ' //\n * XERN4 // ' Z = ' // XERN5 // ' AND UPLIM = ' // XERN6, 3, 1)\n RETURN\n ENDIF\nC\n IF (MIN(X+Y,X+Z,Y+Z).LT.LOLIM) THEN\n IER = 2\n WRITE (XERN3, '(1PE15.6)') X\n WRITE (XERN4, '(1PE15.6)') Y\n WRITE (XERN5, '(1PE15.6)') Z\n WRITE (XERN6, '(1PE15.6)') LOLIM\n CALL XERMSG ('SLATEC', 'DRF',\n * 'MIN(X+Y,X+Z,Y+Z).LT.LOLIM WHERE X = ' // XERN3 //\n * ' Y = ' // XERN4 // ' Z = ' // XERN5 // ' AND LOLIM = ' //\n * XERN6, 2, 1)\n RETURN\n ENDIF\nC\n IER = 0\n XN = X\n YN = Y\n ZN = Z\nC\n 30 MU = (XN+YN+ZN)/3.0D0\n XNDEV = 2.0D0 - (MU+XN)/MU\n YNDEV = 2.0D0 - (MU+YN)/MU\n ZNDEV = 2.0D0 - (MU+ZN)/MU\n EPSLON = MAX(ABS(XNDEV),ABS(YNDEV),ABS(ZNDEV))\n IF (EPSLON.LT.ERRTOL) GO TO 40\n XNROOT = SQRT(XN)\n YNROOT = SQRT(YN)\n ZNROOT = SQRT(ZN)\n LAMDA = XNROOT*(YNROOT+ZNROOT) + YNROOT*ZNROOT\n XN = (XN+LAMDA)*0.250D0\n YN = (YN+LAMDA)*0.250D0\n ZN = (ZN+LAMDA)*0.250D0\n GO TO 30\nC\n 40 E2 = XNDEV*YNDEV - ZNDEV*ZNDEV\n E3 = XNDEV*YNDEV*ZNDEV\n S = 1.0D0 + (C1*E2-0.10D0-C2*E3)*E2 + C3*E3\n DRF = S/SQRT(MU)\nC\n RETURN\n END\n", "meta": {"hexsha": "e51362065b2c5cb79dc5347e44d7a53142037d3c", "size": 10781, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/SLATEC/src/drf.f", "max_stars_repo_name": "ygeorgi/MESS", "max_stars_repo_head_hexsha": "42db490295b08193dfc37496489467ccd2e5b6ae", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "external/SLATEC/src/drf.f", "max_issues_repo_name": "ygeorgi/MESS", "max_issues_repo_head_hexsha": "42db490295b08193dfc37496489467ccd2e5b6ae", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "external/SLATEC/src/drf.f", "max_forks_repo_name": "ygeorgi/MESS", "max_forks_repo_head_hexsha": "42db490295b08193dfc37496489467ccd2e5b6ae", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.6158357771, "max_line_length": 72, "alphanum_fraction": 0.5054262128, "num_tokens": 3513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067195846918, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.7522963947162126}} {"text": " SUBROUTINE rk4(y,dydx,n,x,h,yout,derivs)\r\n INTEGER n,NMAX\r\n REAL h,x,dydx(n),y(n),yout(n)\r\n EXTERNAL derivs\r\n PARAMETER (NMAX=50)\r\n INTEGER i\r\n REAL h6,hh,xh,dym(NMAX),dyt(NMAX),yt(NMAX)\r\n hh=h*0.5\r\n h6=h/6.\r\n xh=x+hh\r\n do 11 i=1,n\r\n yt(i)=y(i)+hh*dydx(i)\r\n11 continue\r\n call derivs(xh,yt,dyt)\r\n do 12 i=1,n\r\n yt(i)=y(i)+hh*dyt(i)\r\n12 continue\r\n call derivs(xh,yt,dym)\r\n do 13 i=1,n\r\n yt(i)=y(i)+h*dym(i)\r\n dym(i)=dyt(i)+dym(i)\r\n13 continue\r\n call derivs(x+h,yt,dyt)\r\n do 14 i=1,n\r\n yout(i)=y(i)+h6*(dydx(i)+dyt(i)+2.*dym(i))\r\n14 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "a343fe3b23af5f98611b6a7afd48f7230e368656", "size": 698, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/rk4.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/rk4.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/rk4.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0689655172, "max_line_length": 51, "alphanum_fraction": 0.4842406877, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.7522308611688182}} {"text": "program main\n implicit none\n real(8), parameter :: pi = acos(-1.d0)\n integer :: clock, n, i\n integer, allocatable :: seed(:)\n\n integer :: n_sample = 10000000, n_accept = 0\n real(8), parameter :: Xmax = 5.d0\n real(8) :: x = 0.d0, r1, r2, A, Integral = 0.d0\n\n integer, allocatable :: bin(:)\n integer :: Nbin = 1000\n real(8) :: binwidth\n\n real(8) :: mu, theta\n\n !real(8) ::\n\n ! seed initialization\n call SYSTEM_CLOCK(clock)\n call RANDOM_SEED(size = n)\n allocate(seed(n))\n do i = 1, n\n seed(i) = clock + 37 * i\n end do\n call RANDOM_SEED(put = seed)\n\n ! bin initialization\n binwidth = 2.d0 * Xmax / dble(Nbin)\n allocate(bin(Nbin))\n bin = 0\n\n ! Metropolis\n do i = 1, n_sample\n call RANDOM_NUMBER(r1)\n r1 = (r1 - .5d0) * (2.d0 * Xmax)\n A = exp(-(r1**2 - x**2) / 2.d0)\n call RANDOM_NUMBER(r2)\n if (r2 <= A) then\n x = r1\n bin(floor((x + Xmax) / binwidth)) = bin(floor((x + Xmax) / binwidth)) + 1\n n_accept = n_accept + 1\n end if\n integral = integral + x**2\n end do\n integral = sqrt(2.d0 * pi) * integral / dble(n_sample)\n write(*,'(\"Metropolis : \",f10.5,\" Acceptance rate : \",f10.5)') integral, dble(n_accept) / dble(n_sample)\n open(unit = 1, file = 'samples.txt', status = 'unknown')\n do i = 1, Nbin\n write(1,'(f10.5,i8)') -Xmax + (i - .5d0) * binwidth, bin(i)\n end do\n close(1)\n\n ! Importance sampling - inverse transform\n integral = 0.d0\n do i = 1, n_sample\n call RANDOM_NUMBER(mu)\n call RANDOM_NUMBER(theta)\n theta = 2.d0 * pi * theta\n x = sqrt(-2.d0 * log(mu)) * cos(theta)\n integral = integral + x**2\n end do\n integral = sqrt(2 * pi) * integral / n_sample\n write(*,'(\"Importance sampling (inverse transform) : \",f10.5)') integral\n\n ! Importance sampling - acceptance & rejection\n integral = 0.d0\n n_accept = 0\n do i = 1,n_sample\n call RANDOM_NUMBER(x)\n x = (x - .5d0) * (2 * Xmax)\n call WEIGHT(x,r1)\n call random_NUMBER(r2)\n if (r2 <= r1) then\n integral = integral + x**2\n n_accept = n_accept + 1\n end if\n end do\n integral = sqrt(2.d0 * pi) * integral / dble(n_accept)\n write(*,'(\"Important sampling (acceptance & rejection) : \",f10.5,\" Acceptance rate : \",f10.5)')&\n integral, dble(n_accept) / dble(n_sample)\nend program main\n\nsubroutine WEIGHT(x,p)\n implicit none\n real(8), parameter :: pi = acos(-1.d0)\n real(8), intent(in) :: x\n real(8), intent(out) :: p\n\n p = exp(-x**2 / 2.d0) / sqrt(2.d0 * pi)\nend subroutine WEIGHT\n", "meta": {"hexsha": "6592dda039f6d1fbd97e73f4505688209ba0ca90", "size": 2672, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Week-14/1-Metropolis.f90", "max_stars_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_stars_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-15T10:30:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T08:22:51.000Z", "max_issues_repo_path": "Week-14/1-Metropolis.f90", "max_issues_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_issues_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Week-14/1-Metropolis.f90", "max_forks_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_forks_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.0434782609, "max_line_length": 108, "alphanum_fraction": 0.5497754491, "num_tokens": 879, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949657, "lm_q2_score": 0.8267118004748678, "lm_q1q2_score": 0.7522308572066861}} {"text": " SUBROUTINE polylsq(coeff,xobs,yobs,nobs,ord)\nC----\nC Compute the best-fitting polynomial through a set of points\nC consisting of nobs ordered pairs (xobs(i),yobs(i)). The polynomial\nC is of order \"ord\" (lin = 1, quad = 2, ...), and the (ord+1)\nC coefficients are returned in the variable \"coeff.\"\nC\nC y = coeff(ord+1)*x^ord + coeff(ord)*x^(ord-1) + ... + coeff(1)\nC\nC Solution to system of linear equations is computed using LAPACK\nC subroutine \"dgels.\" On my computer, the LAPACK libraries are\nC /Users/mherman/Research/lapack-3.5.0/\nC liblapack.a, libmglib.a, librefblas.a\nC----\n IMPLICIT none\n INTEGER OBSMAX,ORDMAX,nrhs,lwmax\n PARAMETER (OBSMAX=100000,ORDMAX=20,nrhs=1,lwmax=100000)\n REAL*8 xobs(OBSMAX),yobs(OBSMAX),coeff(ORDMAX)\n CHARACTER*1 trans\n INTEGER nobs,ord,m,n,lda,ldb,lwork,info,i,j\n REAL*8 a(nobs,ord+1),b(nobs,nrhs),work(lwmax)\n\n trans = 'N' ! A matrix has form (nobs x nparam)\n m = nobs ! Number of rows in matrix A\n n = ord+1 ! Number of columns in matrix A\n lda = nobs ! Leading dimension of A lda >= max(1,m)\n ldb = nobs ! Leading dimension of b ldb >= max(1,m,n)\n\nC----\nC Load model matrix (A) and observation vector (b)\nC----\n do 102 i = 1,nobs\n do 101 j = 1,ord+1\n a(i,j) = xobs(i)**(j-1)\n 101 continue\n 102 continue\n do 103 i = 1,nobs\n b(i,1) = yobs(i)\n 103 continue\n\nC----\nC Determine the optimal workspace size for the solution\nC----\n lwork = -1 \n call dgels(trans,m,n,nrhs,a,lda,b,ldb,work,lwork,info)\n lwork = min(lwmax,int(work(1)))\n\nC----\nC Compute the polynomial coefficients\nC----\n call dgels(trans,m,n,nrhs,a,lda,b,ldb,work,lwork,info)\n do 104 i = 1,ord+1\n coeff(i) = b(i,1)\n 104 continue\n \n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE polylsqconstr(coeff,xobs,yobs,nobs,ord,xconstr,yconstr,\n 1 nconstr)\nC---- \nC Compute the best-fitting polynomial through a set of points\nC consisting of nobs ordered pairs (xobs(i),yobs(i)), constrained\nC to pass through nconstr points (xconstr(i),yconstr(i)). The\nC polynomial is of order \"ord\" (lin = 1, quad = 2, ...), and the\nC (ord+1) coefficients are returned in the variable \"coeff.\"\nC\nC Solution to system of linear equations with equality constraints is\nC computed using LAPACK subroutine dgglse.\nC----\n IMPLICIT none\n INTEGER OBSMAX,ORDMAX,CONSTRMAX,lwmax\n PARAMETER (OBSMAX=100000,ORDMAX=20,CONSTRMAX=21,lwmax=100000)\n REAL*8 xobs(OBSMAX),yobs(OBSMAX),coeff(ORDMAX),\n 1 xconstr(CONSTRMAX),yconstr(CONSTRMAX)\n INTEGER nobs,ord,nconstr,m,n,p,lda,ldb,lwork,info,i,j\n REAL*8 a(nobs,ord+1),b(nconstr,ord+1),c(nobs),d(nconstr),\n 1 work(lwmax),x(ord+1)\n\n if (nconstr.gt.ord+1) then\n write(*,*) 'Error: nconstr > ord+1'\n write(*,*) 'The number of equality constraints cannot be ',\n 1 'larger than the order of the polynomial plus one.'\n STOP\n endif\n\n m = nobs ! Number of rows in matrix A\n n = ord+1 ! Number of columns in matrices A and B\n p = nconstr ! Number of rows in matrix B\n lda = nobs ! Leading dimension of A lda >= max(1,m)\n ldb = nconstr ! Leading dimension of N ldb >= max(1,p)\n\nC---\nC Load model matrix (A), constraint matrix (B), observation vector (c),\nC and the constraint RHS vector (d).\nC--- \n do 101 j = 1,ord+1\n do 102 i = 1,nobs\n a(i,j) = xobs(i)**(j-1)\n 102 continue\n do 103 i = 1,nconstr\n b(i,j) = xconstr(i)**(j-1)\n 103 continue\n 101 continue\n do 104 i = 1,nobs\n c(i) = yobs(i)\n 104 continue\n do 105 i = 1,nconstr\n d(i) = yconstr(i)\n 105 continue\n\nC----\nC Determine the optimal workspace size for the solution\nC----\n lwork = -1\n call dgglse(m,n,p,a,lda,b,ldb,c,d,x,work,lwork,info)\n lwork = min(lwmax,int(work(1)))\n\nC----\nC Compute the polynomial coefficients\nC----\n call dgglse(m,n,p,a,lda,b,ldb,c,d,x,work,lwork,info)\n do 301 i = 1,ord+1\n coeff(i) = x(i)\n 301 continue\n\n RETURN\n END\n", "meta": {"hexsha": "cdd191614c416fad4ef026ca1ce89521dd18b38d", "size": 4239, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/lsqsubs.f", "max_stars_repo_name": "mherman09/src", "max_stars_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/lsqsubs.f", "max_issues_repo_name": "mherman09/src", "max_issues_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-06-27T16:35:46.000Z", "max_issues_repo_issues_event_max_datetime": "2017-07-16T14:55:39.000Z", "max_forks_repo_path": "src/lsqsubs.f", "max_forks_repo_name": "mherman09/src", "max_forks_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.358778626, "max_line_length": 72, "alphanum_fraction": 0.5994338287, "num_tokens": 1356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.8221891392358015, "lm_q1q2_score": 0.7522216324871832}} {"text": " PROGRAM MCJYVB\n!\n! =============================================================\n! Purpose: This program computes Bessel functions Jv(z), Yv(z),\n! and their derivatives for a complex argument using\n! subroutine CJYVB\n! Input : z --- Complex argument\n! v --- Order of Jv(z) and Yv(z)\n! ( v = n+v0, 0 Û n Û 250, 0 Û v0 < 1 )\n! Output: CBJ(n) --- Jn+v0(z)\n! CDJ(n) --- Jn+v0'(z)\n! CBY(n) --- Yn+v0(z)\n! CDY(n) --- Yn+v0'(z)\n! Example:\n! v = n +v0, v0 = 1/3, z = 4.0 + i 2.0\n!\n! n Re[Jv(z)] Im[Jv(z)] Re[Jv'(z)] Im[Jv'(z)]\n! -------------------------------------------------------------------\n! 0 -.13829878D+01 -.30855145D+00 -.18503756D+00 .13103689D+01\n! 1 .82553327D-01 -.12848394D+01 -.12336901D+01 .45079506D-01\n! 2 .10843924D+01 -.39871046D+00 -.33046401D+00 -.84574964D+00\n! 3 .74348135D+00 .40665987D+00 .45318486D+00 -.42198992D+00\n! 4 .17802266D+00 .44526939D+00 .39624497D+00 .97902890D-01\n! 5 -.49008598D-01 .21085409D+00 .11784299D+00 .19422044D+00\n!\n! n Re[Yv(z)] Im[Yv(z)] Re[Yv'(z)] Im[Yv'(z)]\n! -------------------------------------------------------------------\n! 0 .34099851D+00 -.13440666D+01 -.13544477D+01 -.15470699D+00\n! 1 .13323787D+01 .53735934D-01 -.21467271D-01 -.11807457D+01\n! 2 .38393305D+00 .10174248D+01 .91581083D+00 -.33147794D+00\n! 3 -.49924295D+00 .71669181D+00 .47786442D+00 .37321597D+00\n! 4 -.57179578D+00 .27099289D+00 -.12111686D+00 .23405313D+00\n! 5 -.25700924D+00 .24858555D+00 -.43023156D+00 -.13123662D+00\n! =============================================================\n!\n USE SPECFUN\n implicit none\n real*8 :: v,v0,vm,x,y\n! IMPLICIT DOUBLE PRECISION (V,X,Y)\n! IMPLICIT COMPLEX*16 (C,Z)\n complex*16 :: z\n integer :: n,ns,nm,k\n complex*16,dimension(0:250) :: cbj,cdj,cby,cdy\n! DIMENSION CBJ(0:250),CDJ(0:250),CBY(0:250),CDY(0:250)\n WRITE(*,*)' Please enter v, x and y ( z=x+iy )'\n READ(*,*)V,X,Y\n Z=CMPLX(X,Y)\n N=INT(V)\n V0=V-N\n WRITE(*,25)V0,X,Y\n IF (N.LE.8) THEN\n NS=1\n ELSE\n WRITE(*,*)' Please enter order step Ns'\n READ(*,*)NS\n ENDIF\n CALL CJYVB(V,Z,VM,CBJ,CDJ,CBY,CDY)\n NM=INT(VM)\n WRITE(*,*)\n WRITE(*,*)' n Re[Jv(z)] Im[Jv(z)]',&\n ' Re[Jv''(z)] Im[Jv''(z)]'\n WRITE(*,*)' ----------------------------------',&\n '-----------------------------------'\n DO 10 K=0,NM,NS\n10 WRITE(*,20) K,CBJ(K),CDJ(K)\n WRITE(*,*)\n WRITE(*,*)' n Re[Yv(z)] Im[Yv(z)]',&\n ' Re[Yv''(z)] Im[Yv''(z)]'\n WRITE(*,*)' ----------------------------------',&\n '-----------------------------------'\n DO 15 K=0,NM,NS\n15 WRITE(*,20) K,CBY(K),CDY(K)\n20 FORMAT(1X,I3,2X,4D16.8)\n25 FORMAT(8X,'v = n+v0',', v0 =',F5.2,', z =',F7.2,' +',F7.2,'i')\n END\n", "meta": {"hexsha": "02c4f35e2a108132b050aceca899fcb6a657f874", "size": 3293, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tunnelMowPao/prog90.f90", "max_stars_repo_name": "marshallcoz/turnt-octo-happiness", "max_stars_repo_head_hexsha": "84e2b7bf917587e7d593c07fe3d6c9b744a3b711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-08-19T02:30:23.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-10T07:36:32.000Z", "max_issues_repo_path": "tunnelMowPao/prog90.f90", "max_issues_repo_name": "marshallcoz/turnt-octo-happiness", "max_issues_repo_head_hexsha": "84e2b7bf917587e7d593c07fe3d6c9b744a3b711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tunnelMowPao/prog90.f90", "max_forks_repo_name": "marshallcoz/turnt-octo-happiness", "max_forks_repo_head_hexsha": "84e2b7bf917587e7d593c07fe3d6c9b744a3b711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-18T02:23:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T02:23:13.000Z", "avg_line_length": 43.3289473684, "max_line_length": 72, "alphanum_fraction": 0.3993319162, "num_tokens": 1204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.8221891283434877, "lm_q1q2_score": 0.7522216148908099}} {"text": "SUBROUTINE BeachGen2(h0,h1,l,x,h,hx,hxx,Nx)\n! By Allan P. Engsig-Karup.\nUSE Precision\nUSE Constants\nIMPLICIT NONE\nINTEGER :: i, Nx\nREAL(KIND=long) :: l, x(Nx), h0, h1, h(Nx), hx(Nx), hxx(Nx)\nDO i = 1, Nx\n IF (x(i) > zero .AND. x(i) < l) THEN\n ! GD: Always use integer power when possible... (more precise and faster)\n h(i) = h0 - (h0-h1)/two*(one+tanh(sin(pi*(x(i)-l/two)/l)/(one-(two*(x(i)-l/two)/l)**2)))\n hx(i) = -(one/two*h0-one/two*h1)*(one-tanh(sin(pi*(x(i)-one/two*l)/l)/(one-(two*x(i)-l)**2/l**2))**2)*(cos(pi*(x(i)&\n\t\t-one/two*l)/l)*pi/l/(one-(two*x(i)-l)**2/l**2)+four*sin(pi*(x(i)-one/two*l)/l)/(one-(two*x(i)-l)**2/l**2)&\n\t\t**2*(two*x(i)-l)/l**2)\n hxx(i) = two*(half*h0-half*h1)*tanh(sin(pi*(x(i)-half*l)/l)/(one-(two*x(i)-l)**2/l**2))*(one-tanh(sin(pi*(x(i)-half*l)/l)&\n\t\t/(one-(two*x(i)-l)**2/l**2))**2)*(cos(pi*(x(i)-half*l)/l)*pi/l/(one-(two*x(i)-l)**2/l**2)+four*sin(pi*(x(i)-half*l)/l)&\n\t\t/(one-(two*x(i)-l)**2/l**2)**2*(two*x(i)-l)/l**2)**2-(half*h0-half*h1)*(one-tanh(sin(pi*(x(i)-half*l)/l)/(one-(two*x(i)&\n\t\t-l)**2/l**2))**2)*(-sin(pi*(x(i)-half*l)/l)*pi**2/l**2/(one-(two*x(i)-l)**2/l**2)+eight*cos(pi*(x(i)-half*l)/l)*pi/l**3&\n\t\t/(one-(two*x(i)-l)**2/l**2)**2*(two*x(i)-l)+32.0_long*sin(pi*(x(i)-half*l)/l)/(one-(two*x(i)-l)**2/l**2)**3*(two*x(i)-l)&\n\t\t**2/l**4+eight*sin(pi*(x(i)-half*l)/l)/(one-(two*x(i)-l)**2/l**2)**2/l**2)\n!\t\thxx(i) = two*(half*h0-half*h1)*tanh(sin(pi*(x(i)-half*l)/l)/(one-(two*x(i)-l)**2/l**2))*(one-tanh(sin(pi*(x(i)-half*l)/l)/(one-(two*x(i)-l)**2/l**2))**2)*(cos(pi*(x(i)-half*l)/l)*pi/l/(one-(two*x(i)-l)**2/l**2)+four*sin(pi*(x(i)-half*l)/l)/(one-(two*x(i)-l)**2/l**2)**2*(two*x(i)-l)/l**2)**2-(half*h0-half*h1)*(one-tanh(sin(pi*(x(i)-half*l)/l)/(one-(two*x(i)-l)**2/l**2))**2)*(-sin(pi*(x(i)-half*l)/l)*pi**2/l**2/(one-(two*x(i)-l)**2/l**2)+eight*cos(pi*(x(i)-half*l)/l)*pi/l**3/(one-(two*x(i)-l)**2/l**2)**2*(two*x(i)-l)+32.0_long*sin(pi*(x(i)-half*l)/l)/(one-(two*x(i)-l)**2/l**2)**3*(two*x(i)-l)**2/l**4+eight*sin(pi*(x(i)-half*l)/l)/(one-(two*x(i)-l)**2/l**2)**2/l**2)\n else\n h(i) = h0\n hx(i) = zero\n hxx(i) = zero\n endif\nend do\ni = Nx\nh(i) = h0 - (h0-h1)\nEND SUBROUTINE BeachGen2\n\n!\n! GD: for flexibility (particularly to use relaxation zones on both ends)\n!\nSUBROUTINE BeachGen2_bis(h0,h1,ind1,ind2,x,h,hx,hxx,Nx)\nUSE Precision\nUSE Constants\nIMPLICIT NONE\nINTEGER :: i, Nx, ind1, ind2\nREAL(KIND=long) :: l, x(Nx), h0, h1, h(Nx), hx(Nx), hxx(Nx), tmp\n! Left part\nh(1:ind1) = h0\nhx(1:ind1) = zero\nhxx(1:ind1)= zero\n! Right part\nh(ind2:Nx) = h1\nhx(ind2:Nx) = zero\nhxx(ind2:Nx)= zero\n! length of the beach\nl=x(ind2)-x(ind1)\nDO i = ind1+1, ind2-1\n \ttmp = x(i)-x(ind1)\n ! GD: Always use integer power when possible... (more precise and faster)\n h(i) = h0 - (h0-h1)/two*(one+tanh(sin(pi*(tmp-l/two)/l)/(one-(two*(tmp-l/two)/l)**2)))\n hx(i) = -(one/two*h0-one/two*h1)*(one-tanh(sin(pi*(tmp-one/two*l)/l)/(one-(two*tmp-l)**2/l**2))**2)*(cos(pi*(tmp&\n -one/two*l)/l)*pi/l/(one-(two*tmp-l)**2/l**2)+four*sin(pi*(tmp-one/two*l)/l)/(one-(two*tmp-l)**2/l**2)&\n **2*(two*tmp-l)/l**2)\n hxx(i) = two*(half*h0-half*h1)*tanh(sin(pi*(tmp-half*l)/l)/(one-(two*tmp-l)**2/l**2))*(one-tanh(sin(pi*(tmp-half*l)/l)&\n /(one-(two*tmp-l)**2/l**2))**2)*(cos(pi*(tmp-half*l)/l)*pi/l/(one-(two*tmp-l)**2/l**2)+four*sin(pi*(tmp-half*l)/l)&\n /(one-(two*tmp-l)**2/l**2)**2*(two*tmp-l)/l**2)**2-(half*h0-half*h1)*(one-tanh(sin(pi*(tmp-half*l)/l)/(one-(two*tmp&\n -l)**2/l**2))**2)*(-sin(pi*(tmp-half*l)/l)*pi**2/l**2/(one-(two*tmp-l)**2/l**2)+eight*cos(pi*(tmp-half*l)/l)*pi/l**3&\n /(one-(two*tmp-l)**2/l**2)**2*(two*tmp-l)+32.0_long*sin(pi*(tmp-half*l)/l)/(one-(two*tmp-l)**2/l**2)**3*(two*tmp-l)&\n **2/l**4+eight*sin(pi*(tmp-half*l)/l)/(one-(two*tmp-l)**2/l**2)**2/l**2)\n!\t\thxx(i) = two*(half*h0-half*h1)*tanh(sin(pi*(x(i)-half*l)/l)/(one-(two*x(i)-l)**2/l**2))*(one-tanh(sin(pi*(x(i)-half*l)/l)/(one-(two*x(i)-l)**2/l**2))**2)*(cos(pi*(x(i)-half*l)/l)*pi/l/(one-(two*x(i)-l)**2/l**2)+four*sin(pi*(x(i)-half*l)/l)/(one-(two*x(i)-l)**2/l**2)**2*(two*x(i)-l)/l**2)**2-(half*h0-half*h1)*(one-tanh(sin(pi*(x(i)-half*l)/l)/(one-(two*x(i)-l)**2/l**2))**2)*(-sin(pi*(x(i)-half*l)/l)*pi**2/l**2/(one-(two*x(i)-l)**2/l**2)+eight*cos(pi*(x(i)-half*l)/l)*pi/l**3/(one-(two*x(i)-l)**2/l**2)**2*(two*x(i)-l)+32.0_long*sin(pi*(x(i)-half*l)/l)/(one-(two*x(i)-l)**2/l**2)**3*(two*x(i)-l)**2/l**4+eight*sin(pi*(x(i)-half*l)/l)/(one-(two*x(i)-l)**2/l**2)**2/l**2)\nend do\n\nEND SUBROUTINE BeachGen2_bis\n", "meta": {"hexsha": "fe0067090749b1b88d95bb81d5ba3e52e0b45394", "size": 4511, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/analyticalsolutions/beachgen2.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/analyticalsolutions/beachgen2.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/analyticalsolutions/beachgen2.f90", "max_forks_repo_name": "apengsigkarup/OceanWave3D", "max_forks_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-01T12:17:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T16:23:37.000Z", "avg_line_length": 66.3382352941, "max_line_length": 674, "alphanum_fraction": 0.5342496121, "num_tokens": 2012, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474220263198, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7521964894085944}} {"text": "!> Reference: Agnon & Glozman (1996) [p. 145].\n!! \"Periodic solutions for a complex Hamiltonian system: New standing\n!! water-waves\"\n!!\n!! Based on the assumptions:\n!! L = 2 m\n!! T = 1.13409 s\n!! deep water wave -> we set kh = 2*pi -> h = 2 m\n!! H = 0.08934064760240; % wave height\n!!\n!! By Allan P. Engsig-Karup.\n!<\nSUBROUTINE nonlinearstandingwave1D(k,h,X,uu, ww, eta, etax, etaxx, Nfs)\nUSE Precision\nUSE Constants\nIMPLICIT NONE\nINTEGER :: Nfs\nREAL(KIND=long) :: L,k,h\nREAL(KIND=long), DIMENSION(Nfs) :: eta, etax, etaxx, uu, ww, X\nL = two*pi/k\nIF (L/h < half) THEN ! check if conditions given result in a deep water wave\n\tPRINT *,'Conditions for a deep water wave is not given. Check ICs.'\n STOP\nEND IF\neta = half*(0.8867_long*10.0**(-1)*COS(pi*X)+&\n SQRT(SQRT(two))*0.5243*10.0**(-2)*COS(two*pi*X)+&\n SQRT(SQRT(three))*0.4978*10.0**(-3)*COS(three*pi*X)+&\n SQRT(SQRT(four))*0.6542*10.0**(-4)*COS(four*pi*X)+&\n SQRT(SQRT(five))*0.1007*10.0**(-4)*COS(five*pi*X)+&\n SQRT(SQRT(six))*0.1653*10.0**(-5)*COS(six*pi*X)+&\n SQRT(SQRT(seven))*0.2753*10.0**(-6)*COS(seven*pi*X)+&\n SQRT(SQRT(eight))*0.4522*10.0**(-7)*COS(eight*pi*X))\netax = -half*(0.8867_long*10.0**(-1)*pi*SIN(pi*X)+&\n SQRT(SQRT(two))*0.5243*10.0**(-2)*(two*pi)*SIN(two*pi*X)+&\n SQRT(SQRT(three))*0.4978*10.0**(-3)*(three*pi)*SIN(three*pi*X)+&\n SQRT(SQRT(four))*0.6542*10.0**(-4)*(four*pi)*SIN(four*pi*X)+&\n SQRT(SQRT(five))*0.1007*10.0**(-4)*(five*pi)*SIN(five*pi*X)+&\n SQRT(SQRT(six))*0.1653*10.0**(-5)*(six*pi)*SIN(six*pi*X)+&\n SQRT(SQRT(seven))*0.2753*10.0**(-6)*(seven*pi)*SIN(seven*pi*X)+&\n SQRT(SQRT(eight))*0.4522*10.0**(-7)*(eight*pi)*SIN(eight*pi*X))\netaxx = -half*(0.8867_long*10.0**(-1)*pi**2*COS(pi*X)+&\n SQRT(SQRT(two))*0.5243*10.0**(-2)*(two*pi)**2*COS(two*pi*X)+&\n SQRT(SQRT(three))*0.4978*10.0**(-3)*(three*pi)**2*COS(three*pi*X)+&\n SQRT(SQRT(four))*0.6542*10.0**(-4)*(four*pi)**2*COS(four*pi*X)+&\n SQRT(SQRT(five))*0.1007*10.0**(-4)*(five*pi)**2*COS(five*pi*X)+&\n SQRT(SQRT(six))*0.1653*10.0**(-5)*(six*pi)**2*COS(six*pi*X)+&\n SQRT(SQRT(seven))*0.2753*10.0**(-6)*(seven*pi)**2*COS(seven*pi*X)+&\n SQRT(SQRT(eight))*0.4522*10.0**(-7)*(eight*pi)**2*COS(eight*pi*X))\nuu = zero;\nww = zero;\nEND SUBROUTINE nonlinearstandingwave1D\n", "meta": {"hexsha": "f5ae844060022827ef38b30f3879924d8c537d99", "size": 2460, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/analyticalsolutions/nonlinearstandingwave1D.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/analyticalsolutions/nonlinearstandingwave1D.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/analyticalsolutions/nonlinearstandingwave1D.f90", "max_forks_repo_name": "apengsigkarup/OceanWave3D", "max_forks_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-01T12:17:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T16:23:37.000Z", "avg_line_length": 47.3076923077, "max_line_length": 79, "alphanum_fraction": 0.5544715447, "num_tokens": 1002, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474194456936, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7521964826212494}} {"text": "module fourier\n\n ! Healpix module\n use healpix_types\n\n implicit none\n real(kind=dp), parameter :: fourier_PI = 4.0_dp * datan(1.0_dp)\n\n contains\n\n subroutine p_lm_gen(j, n_max, p_lm_max, p_lm_array)\n\n ! j - for indexing on a map\n ! n_max - number of pixels for different phi\n ! p_lm_max - maximum of l and m\n ! p_lm_array - array for writing\n\n implicit none\n integer(kind=i8b), intent(in) :: j\n integer(kind=i4b), intent(in) :: n_max ! i4b\n integer(kind=i8b), intent(in) :: p_lm_max\n real(kind=dp), dimension(0:p_lm_max, 0:p_lm_max), &\n intent(out) :: p_lm_array\n\n integer(kind=i8b) :: m, l ! Vars for iterating\n real(kind=dp) :: theta ! theta - parameter for polynoms and map\n\n ! Initialization\n p_lm_array = 0.0_dp\n\n theta = 2.0_dp * fourier_PI * (j - 1.0_dp) / n_max\n\n p_lm_array(0, 0) = 1.0_dp / dsqrt(4.0_dp * fourier_PI)\n\n do m = 0, p_lm_max - 1, 1\n p_lm_array(m + 1, m + 1) = - p_lm_array(m, m) * dsin(theta) &\n * dsqrt(2.0_dp * m + 3.0_dp) / dsqrt(2.0_dp * m + 2.0_dp)\n end do\n\n do m = 0, p_lm_max - 1, 1\n p_lm_array(m, m + 1) = p_lm_array(m, m) * dcos(theta) &\n * dsqrt(2.0_dp * m + 3.0_dp)\n end do\n\n do m = 0, p_lm_max - 2, 1\n do l = m + 2, p_lm_max, 1\n p_lm_array(m, l) = ((2.0_dp * l - 1.0_dp) * dsqrt((l - m) &\n * (2.0_dp * l + 1.0_dp)) / dsqrt((l + m) * (2.0_dp * l - 1.0_dp)) &\n * p_lm_array(m, l - 1) * dcos(theta) - (l + m - 1.0_dp) &\n * dsqrt((l - m) * (l - 1.0_dp - m) * (2.0_dp * l + 1.0_dp)) &\n / dsqrt((l + m) * (l - 1.0_dp + m) * (2.0_dp * l - 3.0_dp)) &\n * p_lm_array(m, l - 2)) / (l - m)\n end do\n end do\n\n do m = 1, p_lm_max, 1\n do l = m, p_lm_max, 1\n p_lm_array(m, l) = p_lm_array(m, l) * dsqrt(2.0_dp)\n end do\n end do\n\n end subroutine p_lm_gen\n\n\n subroutine direct_fourier(n_max, map, p_lm_max, coef)\n\n ! n_max - number of pixels for different phi\n ! map - array for writing map\n ! p_lm_max - maximum of l and m\n ! coef - array for reading a_lm\n\n ! C module for fftw\n use, intrinsic :: iso_c_binding\n\n implicit none\n include 'fftw3.f03' ! Header for fftw\n integer(kind=i4b), intent(in) :: n_max ! i4b\n real(kind=dp), dimension(1:n_max+1, 1:n_max/2+1), intent(out) :: map\n integer(kind=i8b), intent(in) :: p_lm_max\n complex(kind=dpc), dimension(0:p_lm_max, 0:p_lm_max), intent(in) :: coef\n\n integer(kind=i8b) :: j ! Var for iterating in the map\n real(kind=dp) :: theta ! Theta as parameter for polynoms and map\n ! Array for p_lm_gen\n real(kind=dp), dimension(:, :), allocatable :: p_lm\n integer(kind=i8b) :: err_p_lm = 0 ! Error flag memory allocating\n integer(kind=i8b) :: m, l ! Vars for iterating\n ! Arrays for our fftw on sphere method\n real(kind=dp), dimension(:), allocatable :: p1, p2\n integer(kind=i8b) :: err_p1, err_p2 = 0 ! Error flags memory allocating\n\n type(C_PTR) :: plan ! Pointer for fftw plan\n ! Arrays for fftw\n complex(C_DOUBLE_COMPLEX), dimension(1:n_max) :: in, out\n\n plan = fftw_plan_dft_1d(n_max, in, out, FFTW_FORWARD, FFTW_ESTIMATE)\n\n allocate(p_lm(0:p_lm_max, 0:p_lm_max), stat=err_p_lm)\n if (err_p_lm /= 0) print *, \"p_lm: Allocation request denied\"\n\n allocate(p1(1:n_max), stat=err_p1)\n if (err_p1 /= 0) print *, \"p1: Allocation request denied\"\n\n allocate(p2(1:n_max), stat=err_p2)\n if (err_p2 /= 0) print *, \"p2: Allocation request denied\"\n\n ! Nyquist warning\n if ( p_lm_max > n_max / 2 + 1 ) then\n print *, \"Nyquist frequency warning!\"\n end if\n\n ! Initialization\n map = 0.0_dp\n\n do j = 1, n_max / 2 + 1, 1\n\n p1 = 0.0_dp\n p2 = 0.0_dp\n\n theta = 2.0_dp * fourier_PI * (j - 1.0_dp) / n_max\n\n call p_lm_gen(j, n_max, p_lm_max, p_lm)\n\n do m = 0, p_lm_max, 1\n do l = m, p_lm_max, 1\n p1(m + 1) = p1(m + 1) + dble(coef(m, l)) * p_lm(m, l)\n p2(m + 1) = p2(m + 1) + dimag(coef(m, l)) * p_lm(m, l)\n end do\n end do\n\n in = dcmplx(p1, 0.0_dp)\n out = (0.0_dp, 0.0_dp)\n\n call fftw_execute_dft(plan, in, out)\n\n map(1:n_max, j) = dble(out(1:n_max))\n map(n_max+1, j) = dble(out(1))\n\n in = dcmplx(p2, 0.0_dp)\n out = (0.0_dp, 0.0_dp)\n\n call fftw_execute_dft(plan, in, out)\n\n map(1:n_max, j) = map(1:n_max, j) + dimag(out(1:n_max))\n map(n_max+1, j) = map(n_max+1, j) + dimag(out(1))\n\n end do\n\n call fftw_destroy_plan(plan)\n\n if (allocated(p_lm)) deallocate(p_lm, stat=err_p_lm)\n if (err_p_lm /= 0) print *, \"p_lm: Deallocation request denied\"\n\n if (allocated(p1)) deallocate(p1, stat=err_p1)\n if (err_p1 /= 0) print *, \"p1: Deallocation request denied\"\n\n if (allocated(p2)) deallocate(p2, stat=err_p2)\n if (err_p2 /= 0) print *, \"p2: Deallocation request denied\"\n\n end subroutine direct_fourier\n\n\n real(kind=dp) function direct_point_fourier(i, j, n_max, p_lm_max, coef)\n\n ! j - for indexing on a map\n ! n_max - number of pixels for different phi\n ! p_lm_max - maximum of l and m\n ! coef - array with a_lm\n\n implicit none\n integer(kind=i8b), intent(in) :: i, j\n integer(kind=i4b), intent(in) :: n_max ! i4b\n integer(kind=i8b), intent(in) :: p_lm_max\n complex(kind=dpc), dimension(0:p_lm_max, 0:p_lm_max), intent(in) :: coef\n\n\n real(kind=dp) :: phi, theta ! Theta as parameter for polynoms and map\n ! Array for p_lm_gen\n real(kind=dp), dimension(:, :), allocatable :: p_lm\n integer(kind=i8b) :: err_p_lm = 0 ! Error flag memory allocating\n integer(kind=i8b) :: m, l ! Vars for iterating\n ! Arrays for our fftw on sphere method\n real(kind=dp), dimension(:), allocatable :: p1, p2\n integer(kind=i8b) :: err_p1, err_p2 = 0 ! Error flags memory allocating\n real(kind=dp) :: f = 0.0_dp\n\n allocate(p_lm(0:p_lm_max, 0:p_lm_max), stat=err_p_lm)\n if (err_p_lm /= 0) print *, \"p_lm: Allocation request denied\"\n\n allocate(p1(1:n_max), stat=err_p1)\n if (err_p1 /= 0) print *, \"p1: Allocation request denied\"\n\n allocate(p2(1:n_max), stat=err_p2)\n if (err_p2 /= 0) print *, \"p2: Allocation request denied\"\n\n ! Nyquist warning\n if ( p_lm_max > n_max / 2 + 1 ) then\n print *, \"Nyquist frequency warning!\"\n end if\n\n phi = 2.0_dp * fourier_PI * (i - 1.0_dp) / n_max\n theta = 2.0_dp * fourier_PI * (j - 1.0_dp) / n_max\n\n call p_lm_gen(j, n_max, p_lm_max, p_lm)\n\n p1 = 0.0_dp\n p2 = 0.0_dp\n\n do m = 0, p_lm_max, 1\n do l = m, p_lm_max, 1\n p1(m + 1) = p1(m + 1) + dble(coef(m, l)) * p_lm(m, l)\n p2(m + 1) = p2(m + 1) + dimag(coef(m, l)) * p_lm(m, l)\n end do\n end do\n\n do m = 0, p_lm_max, 1\n f = f + p1(m + 1) * dcos(phi * m) + p2(m + 1) * dsin(phi * m)\n end do\n\n if (allocated(p_lm)) deallocate(p_lm, stat=err_p_lm)\n if (err_p_lm /= 0) print *, \"p_lm: Deallocation request denied\"\n\n if (allocated(p1)) deallocate(p1, stat=err_p1)\n if (err_p1 /= 0) print *, \"p1: Deallocation request denied\"\n\n if (allocated(p2)) deallocate(p2, stat=err_p2)\n if (err_p2 /= 0) print *, \"p2: Deallocation request denied\"\n\n direct_point_fourier = f\n\n end function direct_point_fourier\n\n\n subroutine inverse_fourier(n_max, map, p_lm_max, coef)\n\n ! n_max - number of pixels for different phi\n ! map - array for reading map\n ! p_lm_max - maximum of l and m\n ! coef - array for writing\n\n ! C module for fftw\n use, intrinsic :: iso_c_binding\n\n implicit none\n include 'fftw3.f03' ! Header for fftw\n integer(kind=i4b), intent(in) :: n_max\n real(kind=dp), dimension(1:n_max+1, 1:n_max/2+1), intent(in) :: map\n integer(kind=i8b), intent(in) :: p_lm_max\n complex(kind=dpc), dimension(0:p_lm_max, 0:p_lm_max), intent(out) :: coef\n\n integer(kind=i8b) :: i, j ! Vars for iterating in the map\n real(kind=dp) :: theta ! Theta as parameter for polynoms and map\n ! Array for p_lm_gen\n real(kind=dp), dimension(:, :), allocatable :: p_lm\n integer(kind=i8b) :: err_p_lm = 0 ! Error flag memory allocating\n integer(kind=i8b) :: m, l ! Vars for iterating\n ! Normalization for backward fourier transform\n real(kind=dp) :: norm = 0.0_dp\n\n type(C_PTR) :: plan ! Pointer for fftw plan\n ! Arrays for fftw\n complex(C_DOUBLE_COMPLEX), dimension(1:n_max) :: in, out\n\n plan = fftw_plan_dft_1d(n_max, in, out, FFTW_BACKWARD, FFTW_ESTIMATE)\n\n allocate(p_lm(0:p_lm_max, 0:p_lm_max), stat=err_p_lm)\n if (err_p_lm /= 0) print *, \"p_lm: Allocation request denied\"\n\n ! Nyquist warning\n if ( p_lm_max > n_max / 2 + 1 ) then\n print *, \"Nyquist frequency warning!\"\n end if\n\n ! Initialization\n coef = (0.0_dp, 0.0_dp)\n\n do j = 1, n_max / 2 + 1, 1\n\n in = (0.0_dp, 0.0_dp)\n out = (0.0_dp, 0.0_dp)\n\n theta = 2.0_dp * fourier_PI * (j - 1.0_dp) / n_max\n\n call p_lm_gen(j, n_max, p_lm_max, p_lm)\n\n do i = 1, n_max, 1\n in(i) = dcmplx(map(i, j), 0.0_dp)\n end do\n\n call fftw_execute_dft(plan, in, out)\n\n do i = 2, n_max/2, 1\n out(i) = dcmplx(dble(out(i)) + dble(out(n_max + 2 - i)), &\n dimag(out(i)) - dimag(out(n_max + 2 - i)))\n end do\n\n out = out / n_max\n out(n_max/2+2:n_max) = (0.0_dp, 0.0_dp)\n\n norm = norm + dsin(theta)\n\n do m = 1, p_lm_max, 1\n do l = m, p_lm_max, 1\n coef(m, l) = coef(m, l) &\n + dcmplx(dble(out(m + 1)) * p_lm(m, l), 0.0_dp) * dsin(theta) &\n * 4.0_dp * fourier_PI / 2.0_dp\n coef(m, l) = coef(m, l) &\n + dcmplx(0.0_dp, dimag(out(m+1)) * p_lm(m, l)) * dsin(theta) &\n * 4.0_dp * fourier_PI / 2.0_dp\n end do\n end do\n\n do l = 0, p_lm_max, 1\n coef(0, l) = coef(0, l) &\n + dcmplx(dble(out(1)), 0.0_dp) * p_lm(0, l) * dsin(theta) &\n * 4.0_dp * fourier_PI\n coef(0, l) = coef(0, l) &\n + dcmplx(0.0_dp, dimag(out(1))) * p_lm(0, l) * dsin(theta) &\n * 4.0_dp * fourier_PI\n end do\n\n end do\n\n call fftw_destroy_plan(plan)\n\n if (allocated(p_lm)) deallocate(p_lm, stat=err_p_lm)\n if (err_p_lm /= 0) print *, \"p_lm: Deallocation request denied\"\n\n coef = coef / norm\n\n end subroutine inverse_fourier\n\nend module fourier\n", "meta": {"hexsha": "d00fa75ed691427912827c1e9106ab92563b3c44", "size": 10696, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lib/fourier.f90", "max_stars_repo_name": "heyfaraday/FORTCMB", "max_stars_repo_head_hexsha": "56366423546ca73e876eda58dc8a01a25e640098", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/fourier.f90", "max_issues_repo_name": "heyfaraday/FORTCMB", "max_issues_repo_head_hexsha": "56366423546ca73e876eda58dc8a01a25e640098", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/fourier.f90", "max_forks_repo_name": "heyfaraday/FORTCMB", "max_forks_repo_head_hexsha": "56366423546ca73e876eda58dc8a01a25e640098", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-02-13T04:26:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-13T04:26:12.000Z", "avg_line_length": 32.0239520958, "max_line_length": 79, "alphanum_fraction": 0.562920718, "num_tokens": 3685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474246069458, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.7521964771799823}} {"text": "program compute_pi\n use, intrinsic :: iso_fortran_env, only : I8 => INT64\n use :: mpi_f08\n implicit none\n real, parameter :: PI = acos(-1.0)\n integer(kind=I8), parameter :: nr_tries = 500000000\n integer(kind=I8) :: nr_success, total_nr_success\n integer(Kind=I8) :: i\n integer :: my_rank, my_size\n type(MPI_Datatype) :: int_t\n real :: x, y\n\n ! initialize MPI\n call MPI_Init()\n\n ! get rank in and size of communicator\n call MPI_Comm_rank(MPI_COMM_WORLD, my_rank)\n call MPI_Comm_size(MPI_COMM_WORLD, my_size)\n\n ! show number of processes, only rank 0\n if (my_rank == 0) &\n print '(A, I0, A)', 'running with ', my_size, ' processes'\n\n ! do local computation\n nr_success = 0\n do i = 1, nr_tries/my_size\n call random_number(x)\n call random_number(y)\n if (x**2 + y**2 <= 1.0) nr_success = nr_success + 1\n end do\n\n ! reduce the results, rank 0 will have the sum\n total_nr_success = 0\n call MPI_Type_match_size(MPI_TYPECLASS_INTEGER, I8, int_t)\n call MPI_Reduce(nr_success, total_nr_success, 1, int_t, MPI_SUM, 0, &\n MPI_COMM_WORLD)\n\n ! show the result, only rank 0\n if (my_rank == 0) then\n print '(A, F10.7)', 'sampled pi = ', 4.0*real(total_nr_success)/nr_tries\n print '(A, F10.7)', 'real pi = ', PI\n end if\n\n ! finalize MPI\n call MPI_Finalize()\nend program compute_pi\n", "meta": {"hexsha": "6300f8d914b5731d3b10bd30537c0b579e4631e1", "size": 1413, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/mpi/compute_pi.f90", "max_stars_repo_name": "caguerra/Fortran-MOOC", "max_stars_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-05-20T12:03:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T19:46:26.000Z", "max_issues_repo_path": "source_code/mpi/compute_pi.f90", "max_issues_repo_name": "gjbex/CMake-intro", "max_issues_repo_head_hexsha": "b4855c172f1d4a965f2b148b96ed160f4ea1e5bd", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-30T04:25:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T08:21:30.000Z", "max_forks_repo_path": "source_code/mpi/compute_pi.f90", "max_forks_repo_name": "gjbex/CMake-intro", "max_forks_repo_head_hexsha": "b4855c172f1d4a965f2b148b96ed160f4ea1e5bd", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-09-27T07:30:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T16:23:19.000Z", "avg_line_length": 30.0638297872, "max_line_length": 80, "alphanum_fraction": 0.6291578202, "num_tokens": 428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.7520903354267586}} {"text": " program regresion\nc programa para hacer regresiones lineales o logaritmicas con minimos cuadrados y xi cuadfrada\n integer nmax, nd\n parameter (nmax=1000000)\n CHARACTER archivo*50 \n\n real A01(nmax), A02(nmax), A03(nmax), A04(nmax)\n real LA01(nmax), LA03(nmax), sx, sy, sxy, sxx,syy\n real slx,sly, slxly, slxlx, slyly,b1,m1,m1l,b1l\n real p,pl, erry, errly, errm1, errb1, errm1l, errb1l\n real deltay, deltaly, xi, xired, xil, xilred,c1,ndr,c,cl\n\nc Datos de entrada Nombre del archivo, primer renglon del archivo debe de ser el numero de datos\nc A partir del segundo renglon estara los datos, primea colomna variable independiente\nc Segunda columna error variabble independiente, tercetra col Var dep, cuarta col error variable dep.\n\n print *, 'archivo de datos y numero de datos'\n read(*,*) archivo ,nd \n ndr=real(nd)\n sx=0.0\n sy=0.0\n sxy=0.0\n sxx=0.0\n syy=0.0\n slx=0.0\n sly=0.0\n slxly=0.0\n slxlx=0.0\n slyly=0.0\n \n open (1,FILE=archivo)\nc Lectura del archivo de datos y asignacion de variables\nc Loop over the data points\n do 10 i= 1, nd\n read(1,*) A01(i), A02(i), A03(i), A04(i)\n LA01(i)=log(A01(i))\n LA03(i)=log(A03(i))\n sx=sx+A01(i)\n slx=slx+LA01(i)\n sy=sy+A03(i)\n sly=sly+LA03(i)\n sxy=sxy+A01(i)*A03(i)\n slxly=slxly+LA01(i)*LA03(i)\n sxx=sxx+A01(i)*A01(i)\n slxlx=slxlx+LA01(i)*LA01(i)\n syy=syy+A03(i)*A03(i)\n slyly=slyly+LA03(i)*LA03(i)\n\nc continue\n 10 end do\nC ajuste de minimos cuadrados caso logaritmico\n m1l=(ndr*slxly-slx*sly)/(ndr*slxlx-slx*slx)\n b1l=(slxlx*sly-slx*slxly)/(ndr*slxlx-slx*slx)\nC ajuste minimos cuadrados a caso lineal\n m1=(ndr*sxy-sx*sy)/(ndr*sxx-sx*sx)\n b1=(sxx*sy-sx*sxy) / (ndr*sxx-sx*sx) \nc parámetro de correlacion de pearson caso lineal\n p=(nd*sxy-sx*sy)/sqrt((nd*sxx-sx*sx)*(nd*syy-sy*sy))\nc parametro de correlacion pearson caso log\n pl=(nd*slxly-slx*sly)/sqrt((nd*slxlx-slx*slx)*(nd*slyly-sly*sly))\n\nc error m y b caso lineal\n deltay=0.0\n do 20 j=1, nd\n deltay = deltay + (m1*A01(j)+b1-A03(j))**2\n 20 enddo\n erry=sqrt(deltay/(nd-2))\n errm1=erry*sqrt(nd/(nd*sxx-sx*sx))\n errb1=erry*sqrt(sxx/(nd*sxx-sx*sx))\n\nc error m y b caso log\n deltaly=0.0\n do 30 k=1, nd\n deltaly=deltaly+(m1l*LA01(k)+b1l-LA03(k))**2\n 30 enddo\n errly=sqrt(deltaly/(nd-2))\n errm1l=errly*sqrt(nd/(nd*slxlx-slx*slx))\n errb1l=errly*sqrt(slxlx/(nd*slxlx-slx*slx))\n\nC determinacion de xi cuadrada y xi cuadrada reducida para caso lineal y log\n xi=0.0\n xil=0.0\n do 40 l=1, nd\n xi=xi + (A03(l)-m1*A01(l)-b1)**2/(A04(l)**2)\n xil=xil + (A03(l)-exp(b1l)*A01(l)**m1l)**2/(A04(l)**2)\n 40 enddo\n xired=xi/(nd-2)\n xilred=xil/(nd-2)\nc cerrar archivo de datos\n close (1)\nC presentacion de resultados\nc parametros de correlacion de pearson lineal y log\n print*, 'parametros de correlacion lineal y en plano log'\n print *, p, pl \n PRINT *,'resultados de minimos cuadrados en plano lineal'\n print *, 'm, error en m, b, error en b'\n print *, m1, errm1, b1, errb1\n print *, 'resultados en plano log'\n print*, 'm, error en m, b, error en b'\n print*, m1l, errm1l, b1l, errb1l\n print*, 'Xi CR caso lineal, Xi CR ley potencias'\n print*, xired, xilred \n\n end\n", "meta": {"hexsha": "bfa9a8af9f527d95ff69d9ad38594a4f89848f6f", "size": 3514, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Programas/prueba.f", "max_stars_repo_name": "ajhuertaverde/Mecanica2015-2", "max_stars_repo_head_hexsha": "1c0a624bc3ded4978d506e4bee728fb5d56dcf66", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Programas/prueba.f", "max_issues_repo_name": "ajhuertaverde/Mecanica2015-2", "max_issues_repo_head_hexsha": "1c0a624bc3ded4978d506e4bee728fb5d56dcf66", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Programas/prueba.f", "max_forks_repo_name": "ajhuertaverde/Mecanica2015-2", "max_forks_repo_head_hexsha": "1c0a624bc3ded4978d506e4bee728fb5d56dcf66", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-25T21:23:35.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-25T21:23:35.000Z", "avg_line_length": 33.4666666667, "max_line_length": 101, "alphanum_fraction": 0.6004553216, "num_tokens": 1352, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.752090335261881}} {"text": "module functions\nimplicit none\ncontains\n\nsubroutine show_arr(arr, name)\n real, DIMENSION(:,:), ALLOCATABLE, intent(in) :: arr\n character (*), intent(in) :: name\n\n print *, name\n if (allocated(arr)) then\n write(*,\"(3f20.7)\") arr\n end if\nend subroutine show_arr\n\nSUBROUTINE FillMatrix(matrix)\n real, DIMENSION(:,:), ALLOCATABLE :: matrix\n matrix(1,1) = 1.0\n matrix(1,2) = sqrt(2.0)\n matrix(1,3) = 2.0\n matrix(2,1) = sqrt(2.0)\n matrix(2,2) = 3.0\n matrix(2,3) = sqrt(2.0)\n matrix(3,1) = 2.0\n matrix(3,2) = sqrt(2.0)\n matrix(3,3) = 1.0\n return\nEND\n\n\nSUBROUTINE fill_jacobi_matrix(matrix, p, q, phi)\n real, DIMENSION(:,:), ALLOCATABLE :: matrix\n real, intent(in) :: phi\n Integer i,j,p,q,N\n N = size(matrix,2)\n ForAll(i = 1:N, j = 1:N) matrix(i,j) = (i/j)*(j/i)\n matrix(p,p) = cos(phi)\n matrix(q,q) = matrix(p,p)\n matrix(p,q) = sin(phi)\n matrix(q,p) = -1.0*matrix(p,q)\n return\nEND\n\n\nsubroutine calculate_rotation_angle(matrix, p, q, rotation_angle)\n implicit none\n real, DIMENSION(:,:), ALLOCATABLE, intent(in) :: matrix\n real,intent(out) :: rotation_angle\n integer, intent(in) :: p,q\n\n rotation_angle = atan(2.0 * matrix(p,q) / (matrix(q,q) - matrix(p,p))) / 2.0\n\nend subroutine calculate_rotation_angle\n\nend module functions\n\n\nprogram Jacobi\n use functions\n implicit none\n integer :: i,j\n REAL A,SUM, rotation_angle\n real, DIMENSION(:,:), ALLOCATABLE :: matrix, jacobi_rotation_matrix\n ALLOCATE(matrix(3,3))\n ALLOCATE(jacobi_rotation_matrix(3,3))\n call FillMatrix(matrix)\n call calculate_rotation_angle(matrix, 1, 2, rotation_angle)\n \n call fill_jacobi_matrix(jacobi_rotation_matrix,1,2, rotation_angle)\n call show_arr(matrix, \"matrix\")\n call show_arr(jacobi_rotation_matrix, \"Jacobi Translation Matrix\")\n\nend program Jacobi\n", "meta": {"hexsha": "18179774d3e7951783442af44acc93436253e733", "size": 1814, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "jacobi.f90", "max_stars_repo_name": "j-hayes/jacobi", "max_stars_repo_head_hexsha": "fc34531e0a49da97f0b8690ba27a1b4ee2c30ddc", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "jacobi.f90", "max_issues_repo_name": "j-hayes/jacobi", "max_issues_repo_head_hexsha": "fc34531e0a49da97f0b8690ba27a1b4ee2c30ddc", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "jacobi.f90", "max_forks_repo_name": "j-hayes/jacobi", "max_forks_repo_head_hexsha": "fc34531e0a49da97f0b8690ba27a1b4ee2c30ddc", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.8493150685, "max_line_length": 79, "alphanum_fraction": 0.6626240353, "num_tokens": 597, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7520903300308918}} {"text": " integer function ISRANP(XMEAN)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 2000-12-01 ISRANP Krogh Removed unused parameter MONE.\nc>> 1996-03-30 ISRANP Krogh Added external statement, rem. F90 comment.\nc>> 1995-11-16 ISRANP Krogh Converted from SFTRAN to Fortran 77.\nc>> 1994-10-19 ISRANP Krogh Changes to use M77CON\nc>> 1994-06-24 ISRANP CLL Changed common to use RANC[D/S]1 & RANC[D/S]2.\nc>> 1994-06-23 CLL Changed name to I[D/S]RANP.\nc>> 1992-03-16 CLL\nc>> 1991-11-26 CLL Reorganized common. Using RANCM[A/D/S].\nc>> 1991-11-22 CLL Added call to RAN0, and SGFLAG in common.\nc>> 1991-01-15 CLL Reordered common contents for efficiency.\nC>> 1990-01-23 CLL Making names in common same in all subprogams.\nC>> 1987-04-23 IRANP Lawson Initial code.\nc Returns one pseudorandom integer from the Poisson distribution\nc with mean and variance = XMEAN.\nc The probability of occurrence of the nonnegative integer k in\nc the Poisson distribution with mean XMEAN is\n\nc P(k) = exp(-XMEAN) * XMEAN**k / k!\n\nc Let SUM(n) denote the sum for k = 0 to n of P(k).\nc Let U be a random sample from a uniform\nc distribution on [0.0, 1.0]. The returned value of ISRANP will be\nc the smallest integer such that S(ISRANP) .ge. U.\nc This variable has mean and variance = XMEAN.\nc Reference: Richard H. Snow, Algorithm 342, Comm ACM, V. 11,\nc Dec 1968, p. 819.\nc Code based on subprogram written for JPL by Stephen L. Ritchie,\nc Heliodyne Corp. and Wiley R. Bunton, JPL, 1969.\nc Adapted to Fortran 77 for the JPL MATH77 library by C. L. Lawson &\nc S. Y. Chiu, JPL, Apr 1987.\nc ------------------------------------------------------------------\nc Subprogram argument and result\nc\nc XMEAN [in] Mean value for the desired distribution.\nc Must be positive and not so large that exp(-XMEAN)\nc will underflow. For example, on a machine with underflow\nc limit 0.14E-38, XMEAN must not exceed 88.\nc\nc ISRANP [Returned function value] Will be set to a nonnegative\nc integer value if computation is successful.\nc Will be set to -1 if XMEAN is out of range.\nc ------------------------------------------------------------------\nc--S replaces \"?\": I?RANP, ?ERM1, ?ERV1, ?RANUA\nc--& RANC?1, RANC?2, ?PTR, ?NUMS, ?GFLAG\nc Generic intrinsic functions referenced: EXP, LOG, MIN, NINT\nc Other MATH77 subprogram referenced: RAN0\nc Other MATH77 subprograms needed: ERMSG, ERFIN, AMACH\nc Common referenced: /RANCS1/, /RANCS2/\nc ------------------------------------------------------------------\n external R1MACH\n integer M, NMAX\n parameter(M = 97, NMAX = 84)\n real ELIMIT, R1MACH\n real S, SNUMS(M), SPREV, SUM(0:NMAX)\n real TERM, TLAST, TWO\n real U, XMEAN, XMSAVE, ZERO\n integer LAST, N, NMID\n logical FIRST\n parameter(ZERO = 0.0E0, TWO = 2.0E0)\n common/RANCS2/SNUMS\nc\n integer SPTR\n logical SGFLAG\n common/RANCS1/SPTR, SGFLAG\nc\n save /RANCS1/, /RANCS2/\n save ELIMIT, FIRST, LAST, NMID, SUM, TLAST, XMSAVE\n data FIRST / .true. /\n data ELIMIT / ZERO /\n data XMSAVE / 0.E0 /\nc ------------------------------------------------------------------\n if(FIRST .or. (XMEAN .ne. XMSAVE)) then\nc Set for new XMEAN\nc R1MACH(1) gives the underflow limit.\nc ELIMIT gives a limit for arguments to the exponential function\nc such that if XMEAN .le. ELIMIT, exp(-XMEAN) should not\nc underflow.\nc\n if(ELIMIT .eq. ZERO) ELIMIT = -log(R1MACH(1) * TWO)\n if(XMEAN .le. ZERO .or. XMEAN .gt. ELIMIT) then\n call SERM1('ISRANP',1, 0,'Require 0 .lt. XMEAN .le. ELIMIT',\n * 'XMEAN',XMEAN,',')\n call SERV1('ELIMIT',ELIMIT,'.')\n ISRANP = -1\n else\n LAST = 0\n TLAST = exp(-XMEAN)\n SUM(0) = TLAST\n XMSAVE = XMEAN\n NMID = nint(XMEAN)\n end if\n if(FIRST) then\n FIRST = .false.\n call RAN0\n end if\n end if\nc SET U = UNIFORM RANDOM NUMBER\n SPTR = SPTR - 1\n if(SPTR .eq. 0) then\n call SRANUA(SNUMS,M)\n SPTR = M\n endif\n U = SNUMS(SPTR)\nc\n if(U .gt. SUM(LAST)) then\nc COMPUTE MORE SUMS\n N = LAST\n SPREV = SUM(LAST)\n TERM = TLAST\n 50 continue\n N = N + 1\n TERM = TERM * XMEAN / real(N)\n S = SPREV + TERM\n if(S .eq. SPREV) then\n ISRANP = N\n return\n endif\n if(N .le. NMAX) then\n LAST = N\n SUM(LAST) = S\n TLAST = TERM\n endif\n if(U .le. S) then\n ISRANP = N\n return\n endif\n SPREV = S\n go to 50\n else\nc SEARCH THROUGH STORED SUMS\nc Here we already know that U .le. SUM(LAST).\nc It is most likely that U will be near SUM(NMID).\nc\n if(NMID .lt. LAST) then\n if( U .gt. SUM(NMID) ) then\n do 100 N = NMID+1, LAST\n if(U .le. SUM(N)) then\n ISRANP = N\n return\n endif\n 100 continue\n endif\n endif\nc\n do 150 N = min(NMID, LAST)-1, 0,-1\n if(U .gt. SUM(N)) then\n ISRANP = N+1\n return\n endif\n 150 continue\n ISRANP = 0\n endif\n return\n end\n", "meta": {"hexsha": "7cc24a520c1622eba3cf1af4cf5270cb5bd816a1", "size": 5837, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/isranp.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/isranp.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/isranp.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 36.7106918239, "max_line_length": 72, "alphanum_fraction": 0.5276683228, "num_tokens": 1754, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.7520892003172679}} {"text": "program mortgage\n implicit none\n INTEGER :: i, n\n INTEGER :: d = 0 !! Duration - Number of years\n INTEGER :: d_m !! Duration - Number of month\n REAL*8 :: a = 0 !! Amount borrowed\n REAL*8 :: r = 0 !! Interest Rate\n REAL*8 :: r_m !! Interest Rate (Monthly)\n REAL*8 :: top_line , bottom_line, ap, mp \n CHARACTER(len=25) :: arg, c_a, c_r, c_d\n CHARACTER(LEN=20) :: FMT\n n = IARGC ( )\n do i=1,n \n call GETARG(i,arg)\n if ( i < n ) then\n if ( arg .eq. \"-a\" ) then\n call GETARG(i + 1, c_a)\n write (*,*) \"The amount borrowed is £\", trim(c_a)\n read(c_a,*) a\n end if\n if ( arg .eq. \"-r\" ) then\n call GETARG(i + 1, c_r)\n write (*,*) \"The interest rate is \", trim(c_r), \"%\"\n read(c_r,*) r\n end if\n if ( arg .eq. \"-d\" ) then\n call GETARG(i + 1, c_d)\n write (*,*) \"The loan duration is \", trim(c_d), \" years\"\n read(c_d,*) d\n end if\n end if\n end do\n if ( a == 0 ) then\n write (*,*) \"Please enter an amount using the -a parameter\"\n call exit(-1)\n end if\n if ( r == 0 ) then\n write (*,*) \"Please enter an interest rate using the -r parameter\"\n call exit(-1)\n end if\n if ( d == 0 ) then\n write (*,*) \"Please enter duration using the -d parameter\"\n call exit(-1)\n end if\n !! Capitalise Monthly\n r_m = r / 12\n d_m = d * 12\n top_line = ( a * r_m * ( 1 + ( r_m / 100 ))**d_m )\n bottom_line = 100 * (( (1 + ( r_m / 100 ))**d_m) -1)\n mp = top_line / bottom_line \n ap = mp * 12\n\n FMT = '(\" \",A,\"£\",F10.2)'\n write (*,FMT) \"Annual repayments will be \", ap\n write (*,FMT) \"Monthly repayments will be \", mp\n write (*,FMT) \"Total cost of loan is \", (ap * d) \nend program mortgage\n", "meta": {"hexsha": "2ba7b8975f7fb18534674f623ebe68d1da088b8e", "size": 1804, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/mortgage.f90", "max_stars_repo_name": "timjinx/repo", "max_stars_repo_head_hexsha": "1a0f4dd79addefdac67ac01c9569f70353e3da87", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fortran/mortgage.f90", "max_issues_repo_name": "timjinx/repo", "max_issues_repo_head_hexsha": "1a0f4dd79addefdac67ac01c9569f70353e3da87", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran/mortgage.f90", "max_forks_repo_name": "timjinx/repo", "max_forks_repo_head_hexsha": "1a0f4dd79addefdac67ac01c9569f70353e3da87", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.1034482759, "max_line_length": 72, "alphanum_fraction": 0.5055432373, "num_tokens": 598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299529686201, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7520891860581936}} {"text": "! Preprocessor definitions\n! Indexes used by the numerical schemes\n#define ix 2:x_dim\n#define ix_m 1:(x_dim-1)\n#define ix_c 2:(x_dim-1)\n#define ix_cp 3:x_dim\n#define ix_cm 1:(x_dim-2)\n\n! Usage from Python:\n! step_advection(dx, dt, u, C)\nsubroutine step_ftbs(dx, dt, u, C, x_dim)\n implicit none\n ! Arguments\n integer :: x_dim\n real, intent(in) :: dx, dt\n real, intent(in) :: u(x_dim)\n real, intent(inout) :: C(x_dim)\n !f2py intent(in,out) :: C\n\n !---------------\n ! Begin program\n !---------------\n\n C(ix) = dt * ( -u(ix)* (C(ix)-C(ix_m)) - C(ix) * (u(ix)-u(ix_m)) ) * &\n dt/dx + C(ix)\n\nend subroutine\n\n! Usage from Python:\n! step_ftbs_diffusion(dx, dt, u, D, C)\nsubroutine step_ftbs_diffusion(dx, dt, u, D, C, x_dim)\n implicit none\n ! Arguments\n integer :: x_dim\n real, intent(in) :: dx, dt, D\n real, intent(in) :: u(x_dim)\n real, intent(inout) :: C(x_dim)\n !f2py intent(in,out) :: C\n\n !---------------\n ! Begin program\n !---------------\n\n C(ix_c) = D * ( (C(ix_cp) -2*C(ix_c) + C(ix_cm))/dx**2 &\n - u(ix_c) * (C(ix_c) - C(ix_cm))/dx ) * dt + C(ix_c)\n\nend subroutine\n", "meta": {"hexsha": "2fb12daf9bd047bf88af17fb796724db853f3395", "size": 1262, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Numerical_Schemes_One_Dim.f95", "max_stars_repo_name": "asura6/Fortran-Python-Advection-and-Diffusion-Models", "max_stars_repo_head_hexsha": "5fbdaba9acc69b3d21e83d9cc208bc551b72ba9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Numerical_Schemes_One_Dim.f95", "max_issues_repo_name": "asura6/Fortran-Python-Advection-and-Diffusion-Models", "max_issues_repo_head_hexsha": "5fbdaba9acc69b3d21e83d9cc208bc551b72ba9e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Numerical_Schemes_One_Dim.f95", "max_forks_repo_name": "asura6/Fortran-Python-Advection-and-Diffusion-Models", "max_forks_repo_head_hexsha": "5fbdaba9acc69b3d21e83d9cc208bc551b72ba9e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.2916666667, "max_line_length": 80, "alphanum_fraction": 0.499207607, "num_tokens": 404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.8128673087708698, "lm_q1q2_score": 0.7520891852155928}} {"text": "!! ----------------------------------------------------------------------------------\n!! MODULE Polynomial234RootSolvers\n!!\n!! This module contains the three root solvers for quadratic,\n!! cubic and quartic polynomials.\n!!\n!! ----------------------------------------------------------------------------------\n\nmodule Polynomial234RootSolvers\n\nuse SetWorkingPrecision, ONLY : wp, wpformat\n\ncontains\n\n!!-----------------------------------------------------------------------------------\n!!\n!! CUBIC POLYNOMIAL ROOT SOLVER\n!!\n!! SYNOPSIS\n!!\n!! call cubicRoots (real, intent (in) :: c2,\n!! real, intent (in) :: c1,\n!! real, intent (in) :: c0,\n!! integer, intent (out) :: nReal,\n!! real, intent (out) :: root (1:3,1:2),\n!! logical, optional, intent (in) :: printInfo)\n!!\n!! DESCRIPTION\n!!\n!! Calculates all real + complex roots of the cubic polynomial:\n!!\n!! x^3 + c2 * x^2 + c1 * x + c0\n!!\n!! The first real root (which always exists) is obtained using an optimized\n!! Newton-Raphson scheme. The other remaining roots are obtained through\n!! composite deflation into a quadratic. An option for printing detailed info\n!! about the intermediate stages in solving the cubic is available.\n!!\n!! The cubic root solver can handle any size of cubic coefficients and there is\n!! no danger of overflow due to proper rescaling of the cubic polynomial.\n!!\n!! The order of the roots is as follows:\n!!\n!! 1) For real roots, the order is according to their algebraic value\n!! on the number scale (largest positive first, largest negative last).\n!!\n!! 2) Since there can be only one complex conjugate pair root, no order\n!! is necessary.\n!!\n!! 3) All real roots preceede the complex ones.\n!!\n!! ARGUMENTS\n!!\n!! c2 : coefficient of x^2 term\n!! c1 : coefficient of x term\n!! c0 : independent coefficient\n!! nReal : number of real roots found\n!! root (n,1) : real part of n-th root\n!! root (n,2) : imaginary part of n-th root\n!! printInfo : if given and true, detailed info will be printed about intermediate stages\n!!\n!! NOTES\n!!\n!!***\n\nsubroutine cubicRoots (c2, c1, c0, nReal, root, printInfo)\n\n implicit none\n\n logical, optional , intent (in) :: printInfo\n integer , intent (out) :: nReal\n real (kind = wp), intent (in) :: c2, c1, c0\n real (kind = wp), intent (out) :: root (1:3,1:2)\n\n logical :: bisection\n logical :: converged\n logical :: doPrint\n\n integer :: cubicType\n integer :: deflateCase\n integer :: oscillate\n\n integer, parameter :: Re = 1\n integer, parameter :: Im = 2\n\n integer, parameter :: allzero = 0\n integer, parameter :: linear = 1\n integer, parameter :: quadratic = 2\n integer, parameter :: general = 3\n\n real (kind = wp) :: a0, a1, a2\n real (kind = wp) :: a, b, c, k, s, t, u, x, y, z\n real (kind = wp) :: xShift\n\n real (kind = wp), parameter :: macheps = epsilon (1.0_wp)\n real (kind = wp), parameter :: one27th = 1.0_wp / 27.0_wp\n real (kind = wp), parameter :: two27th = 2.0_wp / 27.0_wp\n real (kind = wp), parameter :: third = 1.0_wp / 3.0_wp\n\n real (kind = wp), parameter :: p1 = 1.09574_wp !\n real (kind = wp), parameter :: q1 = 3.23900e-1_wp ! Newton-Raphson coeffs for class 1 and 2\n real (kind = wp), parameter :: r1 = 3.23900e-1_wp !\n real (kind = wp), parameter :: s1 = 9.57439e-2_wp !\n\n real (kind = wp), parameter :: p3 = 1.14413_wp !\n real (kind = wp), parameter :: q3 = 2.75509e-1_wp ! Newton-Raphson coeffs for class 3\n real (kind = wp), parameter :: r3 = 4.45578e-1_wp !\n real (kind = wp), parameter :: s3 = 2.59342e-2_wp !\n\n real (kind = wp), parameter :: q4 = 7.71845e-1_wp ! Newton-Raphson coeffs for class 4\n real (kind = wp), parameter :: s4 = 2.28155e-1_wp !\n\n real (kind = wp), parameter :: p51 = 8.78558e-1_wp !\n real (kind = wp), parameter :: p52 = 1.92823e-1_wp !\n real (kind = wp), parameter :: p53 = 1.19748_wp !\n real (kind = wp), parameter :: p54 = 3.45219e-1_wp !\n real (kind = wp), parameter :: q51 = 5.71888e-1_wp !\n real (kind = wp), parameter :: q52 = 5.66324e-1_wp !\n real (kind = wp), parameter :: q53 = 2.83772e-1_wp ! Newton-Raphson coeffs for class 5 and 6\n real (kind = wp), parameter :: q54 = 4.01231e-1_wp !\n real (kind = wp), parameter :: r51 = 7.11154e-1_wp !\n real (kind = wp), parameter :: r52 = 5.05734e-1_wp !\n real (kind = wp), parameter :: r53 = 8.37476e-1_wp !\n real (kind = wp), parameter :: r54 = 2.07216e-1_wp !\n real (kind = wp), parameter :: s51 = 3.22313e-1_wp !\n real (kind = wp), parameter :: s52 = 2.64881e-1_wp !\n real (kind = wp), parameter :: s53 = 3.56228e-1_wp !\n real (kind = wp), parameter :: s54 = 4.45532e-3_wp !\n!\n!\n! ...Start.\n!\n!\n if (present (printInfo)) then\n doPrint = printInfo\n else\n doPrint = .false.\n end if\n\n if (doPrint) then\n write (*,wpformat) ' initial cubic c2 = ',c2\n write (*,wpformat) ' initial cubic c1 = ',c1\n write (*,wpformat) ' initial cubic c0 = ',c0\n write (*,wpformat) ' ------------------------------------------------'\n end if\n!\n!\n! ...Handle special cases.\n!\n! 1) all terms zero\n! 2) only quadratic term is nonzero -> linear equation.\n! 3) only independent term is zero -> quadratic equation.\n!\n!\n if (c0 == 0.0_wp .and. c1 == 0.0_wp .and. c2 == 0.0_wp) then\n\n cubicType = allzero\n\n else if (c0 == 0.0_wp .and. c1 == 0.0_wp) then\n\n k = 1.0_wp\n a2 = c2\n\n cubicType = linear\n\n else if (c0 == 0.0_wp) then\n\n k = 1.0_wp\n a2 = c2\n a1 = c1\n\n cubicType = quadratic\n\n else\n!\n!\n! ...The general case. Rescale cubic polynomial, such that largest absolute coefficient\n! is (exactly!) equal to 1. Honor the presence of a special cubic case that might have\n! been obtained during the rescaling process (due to underflow in the coefficients).\n!\n!\n x = abs (c2)\n y = sqrt (abs (c1))\n z = abs (c0) ** third\n u = max (x,y,z)\n\n if (u == x) then\n\n k = 1.0_wp / x\n a2 = sign (1.0_wp , c2)\n a1 = (c1 * k) * k\n a0 = ((c0 * k) * k) * k\n\n else if (u == y) then\n\n k = 1.0_wp / y\n a2 = c2 * k\n a1 = sign (1.0_wp , c1)\n a0 = ((c0 * k) * k) * k\n\n else\n\n k = 1.0_wp / z\n a2 = c2 * k\n a1 = (c1 * k) * k\n a0 = sign (1.0_wp , c0)\n\n end if\n\n if (doPrint) then\n write (*,wpformat) ' rescaling factor = ',k\n write (*,wpformat) ' ------------------------------------------------'\n write (*,wpformat) ' rescaled cubic c2 = ',a2\n write (*,wpformat) ' rescaled cubic c1 = ',a1\n write (*,wpformat) ' rescaled cubic c0 = ',a0\n write (*,wpformat) ' ------------------------------------------------'\n end if\n\n k = 1.0_wp / k\n\n if (a0 == 0.0_wp .and. a1 == 0.0_wp .and. a2 == 0.0_wp) then\n cubicType = allzero\n else if (a0 == 0.0_wp .and. a1 == 0.0_wp) then\n cubicType = linear\n else if (a0 == 0.0_wp) then\n cubicType = quadratic\n else\n cubicType = general\n end if\n\n end if\n!\n!\n! ...Select the case.\n!\n! 1) Only zero roots.\n!\n!\n select case (cubicType)\n\n case (allzero)\n\n nReal = 3\n\n root (:,Re) = 0.0_wp\n root (:,Im) = 0.0_wp\n!\n!\n! ...2) The linear equation case -> additional 2 zeros.\n!\n!\n case (linear)\n\n x = - a2 * k\n\n nReal = 3\n\n root (1,Re) = max (0.0_wp, x)\n root (2,Re) = 0.0_wp\n root (3,Re) = min (0.0_wp, x)\n root (:,Im) = 0.0_wp\n!\n!\n! ...3) The quadratic equation case -> additional 1 zero.\n!\n!\n case (quadratic)\n\n call quadraticRoots (a2, a1, nReal, root (1:2,1:2))\n\n if (nReal == 2) then\n\n x = root (1,1) * k ! real roots of quadratic are ordered x >= y\n y = root (2,1) * k\n\n nReal = 3\n\n root (1,Re) = max (x, 0.0_wp)\n root (2,Re) = max (y, min (x, 0.0_wp))\n root (3,Re) = min (y, 0.0_wp)\n root (:,Im) = 0.0_wp\n\n else\n\n nReal = 1\n\n root (3,Re) = root (2,Re) * k\n root (2,Re) = root (1,Re) * k\n root (1,Re) = 0.0_wp\n root (3,Im) = root (2,Im) * k\n root (2,Im) = root (1,Im) * k\n root (1,Im) = 0.0_wp\n\n end if\n!\n!\n! ...3) The general cubic case. Set the best Newton-Raphson root estimates for the cubic.\n! The easiest and most robust conditions are checked first. The most complicated\n! ones are last and only done when absolutely necessary.\n!\n!\n case (general)\n\n if (a0 == 1.0_wp) then\n\n x = - p1 + q1 * a1 - a2 * (r1 - s1 * a1)\n\n a = a2\n b = a1\n c = a0\n xShift = 0.0_wp\n\n else if (a0 == - 1.0_wp) then\n\n x = p1 - q1 * a1 - a2 * (r1 - s1 * a1)\n\n a = a2\n b = a1\n c = a0\n xShift = 0.0_wp\n\n else if (a1 == 1.0_wp) then\n\n if (a0 > 0.0_wp) then\n x = a0 * (- q4 - s4 * a2)\n else\n x = a0 * (- q4 + s4 * a2)\n end if\n\n a = a2\n b = a1\n c = a0\n xShift = 0.0_wp\n\n else if (a1 == - 1.0_wp) then\n\n y = - two27th\n y = y * a2\n y = y * a2 - third\n y = y * a2\n\n if (a0 < y) then\n x = + p3 - q3 * a0 - a2 * (r3 + s3 * a0) ! + guess\n else\n x = - p3 - q3 * a0 - a2 * (r3 - s3 * a0) ! - guess\n end if\n\n a = a2\n b = a1\n c = a0\n xShift = 0.0_wp\n\n else if (a2 == 1.0_wp) then\n\n b = a1 - third\n c = a0 - one27th\n\n if (abs (b) < macheps .and. abs (c) < macheps) then ! triple -1/3 root\n\n x = - third * k\n\n nReal = 3\n\n root (:,Re) = x\n root (:,Im) = 0.0_wp\n\n return\n\n else\n\n y = third * a1 - two27th\n\n if (a1 <= third) then\n if (a0 > y) then\n x = - p51 - q51 * a0 + a1 * (r51 - s51 * a0) ! - guess\n else\n x = + p52 - q52 * a0 - a1 * (r52 + s52 * a0) ! + guess\n end if\n else\n if (a0 > y) then\n x = - p53 - q53 * a0 + a1 * (r53 - s53 * a0) ! <-1/3 guess\n else\n x = + p54 - q54 * a0 - a1 * (r54 + s54 * a0) ! >-1/3 guess\n end if\n end if\n\n if (abs (b) < 1.e-2_wp .and. abs (c) < 1.e-2_wp) then ! use shifted root\n c = - third * b + c\n if (abs (c) < macheps) c = 0.0_wp ! prevent random noise\n a = 0.0_wp\n xShift = third\n x = x + xShift\n else\n a = a2\n b = a1\n c = a0\n xShift = 0.0_wp\n end if\n\n end if\n\n else if (a2 == - 1.0_wp) then\n\n b = a1 - third\n c = a0 + one27th\n\n if (abs (b) < macheps .and. abs (c) < macheps) then ! triple 1/3 root\n\n x = third * k\n\n nReal = 3\n\n root (:,Re) = x\n root (:,Im) = 0.0_wp\n\n return\n\n else\n\n y = two27th - third * a1\n\n if (a1 <= third) then\n if (a0 < y) then\n x = + p51 - q51 * a0 - a1 * (r51 + s51 * a0) ! +1 guess\n else\n x = - p52 - q52 * a0 + a1 * (r52 - s52 * a0) ! -1 guess\n end if\n else\n if (a0 < y) then\n x = + p53 - q53 * a0 - a1 * (r53 + s53 * a0) ! >1/3 guess\n else\n x = - p54 - q54 * a0 + a1 * (r54 - s54 * a0) ! <1/3 guess\n end if\n end if\n\n if (abs (b) < 1.e-2_wp .and. abs (c) < 1.e-2_wp) then ! use shifted root\n c = third * b + c\n if (abs (c) < macheps) c = 0.0_wp ! prevent random noise\n a = 0.0_wp\n xShift = - third\n x = x + xShift\n else\n a = a2\n b = a1\n c = a0\n xShift = 0.0_wp\n end if\n\n end if\n\n end if\n!\n!\n! ...Perform Newton/Bisection iterations on x^3 + ax^2 + bx + c.\n!\n!\n z = x + a\n y = x + z\n z = z * x + b\n y = y * x + z ! C'(x)\n z = z * x + c ! C(x)\n t = z ! save C(x) for sign comparison\n x = x - z / y ! 1st improved root\n\n oscillate = 0\n bisection = .false.\n converged = .false.\n\n do while (.not.converged .and. .not.bisection) ! Newton-Raphson iterates\n\n z = x + a\n y = x + z\n z = z * x + b\n y = y * x + z\n z = z * x + c\n\n if (z * t < 0.0_wp) then ! does Newton start oscillating ?\n if (z < 0.0_wp) then\n oscillate = oscillate + 1 ! increment oscillation counter\n s = x ! save lower bisection bound\n else\n u = x ! save upper bisection bound\n end if\n t = z ! save current C(x)\n end if\n\n y = z / y ! Newton correction\n x = x - y ! new Newton root\n\n bisection = oscillate > 2 ! activate bisection\n converged = abs (y) <= abs (x) * macheps ! Newton convergence indicator\n\n if (doPrint) write (*,wpformat) ' Newton root = ',x\n\n end do\n\n if (bisection) then\n\n t = u - s ! initial bisection interval\n do while (abs (t) > abs (x) * macheps) ! bisection iterates\n\n z = x + a !\n z = z * x + b ! C (x)\n z = z * x + c !\n\n if (z < 0.0_wp) then !\n s = x !\n else ! keep bracket on root\n u = x !\n end if !\n\n t = 0.5_wp * (u - s) ! new bisection interval\n x = s + t ! new bisection root\n\n if (doPrint) write (*,wpformat) ' Bisection root = ',x\n\n end do\n end if\n\n if (doPrint) write (*,wpformat) ' ------------------------------------------------'\n\n x = x - xShift ! unshift root\n!\n!\n! ...Forward / backward deflate rescaled cubic (if needed) to check for other real roots.\n! The deflation analysis is performed on the rescaled cubic. The actual deflation must\n! be performed on the original cubic, not the rescaled one. Otherwise deflation errors\n! will be enhanced when undoing the rescaling on the extra roots.\n!\n!\n z = abs (x)\n s = abs (a2)\n t = abs (a1)\n u = abs (a0)\n\n y = z * max (s,z) ! take maximum between |x^2|,|a2 * x|\n\n deflateCase = 1 ! up to now, the maximum is |x^3| or |a2 * x^2|\n\n if (y < t) then ! check maximum between |x^2|,|a2 * x|,|a1|\n y = t * z ! the maximum is |a1 * x|\n deflateCase = 2 ! up to now, the maximum is |a1 * x|\n else\n y = y * z ! the maximum is |x^3| or |a2 * x^2|\n end if\n\n if (y < u) then ! check maximum between |x^3|,|a2 * x^2|,|a1 * x|,|a0|\n deflateCase = 3 ! the maximum is |a0|\n end if\n\n y = x * k ! real root of original cubic\n\n select case (deflateCase)\n\n case (1)\n x = 1.0_wp / y\n t = - c0 * x ! t -> backward deflation on unscaled cubic\n s = (t - c1) * x ! s -> backward deflation on unscaled cubic\n case (2)\n s = c2 + y ! s -> forward deflation on unscaled cubic\n t = - c0 / y ! t -> backward deflation on unscaled cubic\n case (3)\n s = c2 + y ! s -> forward deflation on unscaled cubic\n t = c1 + s * y ! t -> forward deflation on unscaled cubic\n end select\n\n if (doPrint) then\n write (*,wpformat) ' Residual quadratic q1 = ',s\n write (*,wpformat) ' Residual quadratic q0 = ',t\n write (*,wpformat) ' ------------------------------------------------'\n end if\n\n call quadraticRoots (s, t, nReal, root (1:2,1:2))\n\n if (nReal == 2) then\n\n x = root (1,Re) ! real roots of quadratic are ordered x >= z\n z = root (2,Re) ! use 'z', because 'y' is original cubic real root\n\n nReal = 3\n\n root (1,Re) = max (x, y)\n root (2,Re) = max (z, min (x, y))\n root (3,Re) = min (z, y)\n root (:,Im) = 0.0_wp\n\n else\n\n nReal = 1\n\n root (3,Re) = root (2,Re)\n root (2,Re) = root (1,Re)\n root (1,Re) = y\n root (3,Im) = root (2,Im)\n root (2,Im) = root (1,Im)\n root (1,Im) = 0.0_wp\n\n end if\n\n end select\n!\n!\n! ...Ready!\n!\n!\n return\nend subroutine cubicRoots\n\n\n\n!!-----------------------------------------------------------------------------------\n!!\n!! QUADRATIC POLYNOMIAL ROOT SOLVER\n!!\n!! SYNOPSIS\n!!\n!! call quadraticRoots (real, intent (in) :: q1,\n!! real, intent (in) :: q0,\n!! integer, intent (out) :: nReal,\n!! real, intent (out) :: root (1:2,1:2))\n!!\n!! DESCRIPTION\n!!\n!! Calculates all real + complex roots of the quadratic polynomial:\n!!\n!! x^2 + q1 * x + q0\n!!\n!! The code checks internally, if rescaling of the coefficients is needed to\n!! avoid overflow.\n!!\n!! The order of the roots is as follows:\n!!\n!! 1) For real roots, the order is according to their algebraic value\n!! on the number scale (largest positive first, largest negative last).\n!!\n!! 2) Since there can be only one complex conjugate pair root, no order\n!! is necessary.\n!!\n!! ARGUMENTS\n!!\n!! q1 : coefficient of x term\n!! q0 : independent coefficient\n!! nReal : number of real roots found\n!! root (n,1) : real part of n-th root\n!! root (n,2) : imaginary part of n-th root\n!!\n!! NOTES\n!!\n!!***\n\nsubroutine quadraticRoots (q1, q0, nReal, root)\n implicit none\n\n integer , intent (out) :: nReal\n real (kind = wp), intent (in) :: q1, q0\n real (kind = wp), intent (out) :: root (1:2,1:2)\n\n logical :: rescale\n\n real (kind = wp) :: a0, a1\n real (kind = wp) :: k, x, y, z\n\n integer, parameter :: Re = 1\n integer, parameter :: Im = 2\n\n real (kind = wp), parameter :: LPN = huge (1.0_wp) ! the (L)argest (P)ositive (N)umber\n real (kind = wp), parameter :: sqrtLPN = sqrt (LPN) ! and the square root of it\n!\n!\n! ...Handle special cases.\n!\n!\n if (q0 == 0.0_wp .and. q1 == 0.0_wp) then\n\n nReal = 2\n\n root (:,Re) = 0.0_wp\n root (:,Im) = 0.0_wp\n\n else if (q0 == 0.0_wp) then\n\n nReal = 2\n\n root (1,Re) = max (0.0_wp, - q1)\n root (2,Re) = min (0.0_wp, - q1)\n root (:,Im) = 0.0_wp\n\n else if (q1 == 0.0_wp) then\n\n x = sqrt (abs (q0))\n\n if (q0 < 0.0_wp) then\n\n nReal = 2\n\n root (1,Re) = x\n root (2,Re) = - x\n root (:,Im) = 0.0_wp\n\n else\n\n nReal = 0\n\n root (:,Re) = 0.0_wp\n root (1,Im) = x\n root (2,Im) = - x\n\n end if\n\n else\n!\n!\n! ...The general case. Do rescaling, if either squaring of q1/2 or evaluation of\n! (q1/2)^2 - q0 will lead to overflow. This is better than to have the solver\n! crashed. Note, that rescaling might lead to loss of accuracy, so we only\n! invoke it when absolutely necessary.\n!\n!\n rescale = (q1 > sqrtLPN + sqrtLPN) ! this detects overflow of (q1/2)^2\n\n if (.not.rescale) then\n x = q1 * 0.5 ! we are sure here that x*x will not overflow\n rescale = (q0 < x * x - LPN) ! this detects overflow of (q1/2)^2 - q0\n end if\n\n if (rescale) then\n\n x = abs (q1)\n y = sqrt (abs (q0))\n\n if (x > y) then\n k = x\n z = 1.0_wp / x\n a1 = sign (1.0_wp , q1)\n a0 = (q0 * z) * z\n else\n k = y\n a1 = q1 / y\n a0 = sign (1.0_wp , q0)\n end if\n\n else\n a1 = q1\n a0 = q0\n end if\n!\n!\n! ...Determine the roots of the quadratic. Note, that either a1 or a0 might\n! have become equal to zero due to underflow. But both cannot be zero.\n!\n!\n x = a1 * 0.5_wp\n y = x * x - a0\n\n if (y >= 0.0_wp) then\n\n y = sqrt (y)\n\n if (x > 0.0_wp) then\n y = - x - y\n else\n y = - x + y\n end if\n\n if (rescale) then\n y = y * k ! very important to convert to original\n z = q0 / y ! root first, otherwise complete loss of\n else ! root due to possible a0 = 0 underflow\n z = a0 / y\n end if\n\n nReal = 2\n\n root (1,Re) = max (y,z) ! 1st real root of x^2 + a1 * x + a0\n root (2,Re) = min (y,z) ! 2nd real root of x^2 + a1 * x + a0\n root (:,Im) = 0.0_wp\n\n else\n\n y = sqrt (- y)\n\n nReal = 0\n\n root (1,Re) = - x\n root (2,Re) = - x\n root (1,Im) = y ! complex conjugate pair of roots\n root (2,Im) = - y ! of x^2 + a1 * x + a0\n\n if (rescale) then\n root = root * k\n end if\n\n end if\n\n end if\n!\n!\n! ...Ready!\n!\n!\n return\nend subroutine quadraticRoots\n\n\n\n\n\n!!-----------------------------------------------------------------------------------\n!!\n!! QUARTIC POLYNOMIAL ROOT SOLVER\n!!\n!! SYNOPSIS\n!!\n!! call quarticRoots (real, intent (in) :: q3,\n!! real, intent (in) :: q2,\n!! real, intent (in) :: q1,\n!! real, intent (in) :: q0,\n!! integer, intent (out) :: nReal,\n!! real, intent (out) :: root (1:4,1:2),\n!! logical, optional, intent (in) :: printInfo)\n!!\n!! DESCRIPTION\n!!\n!! Calculates all real + complex roots of the quartic polynomial:\n!!\n!! x^4 + q3 * x^3 + q2 * x^2 + q1 * x + q0\n!!\n!! An option for printing detailed info about the intermediate stages in solving\n!! the quartic is available. This enables a detailed check in case something went\n!! wrong and the roots obtained are not proper.\n!!\n!! The quartic root solver can handle any size of quartic coefficients and there is\n!! no danger of overflow, due to proper rescaling of the quartic polynomial.\n!!\n!! The order of the roots is as follows:\n!!\n!! 1) For real roots, the order is according to their algebraic value\n!! on the number scale (largest positive first, largest negative last).\n!!\n!! 2) For complex conjugate pair roots, the order is according to the\n!! algebraic value of their real parts (largest positive first). If\n!! the real parts are equal, the order is according to the algebraic\n!! value of their imaginary parts (largest first).\n!!\n!! 3) All real roots preceede the complex ones.\n!!\n!! ARGUMENTS\n!!\n!! q3 : coefficient of x^3 term\n!! q2 : coefficient of x^2 term\n!! q1 : coefficient of x term\n!! q0 : independent coefficient\n!! nReal : number of real roots found\n!! root (n,1) : real part of n-th root\n!! root (n,2) : imaginary part of n-th root\n!! printInfo : if given and true, detailed info will be printed about intermediate stages\n!!\n!! NOTES\n!!\n!!***\n\nsubroutine quarticRoots (q3, q2, q1, q0, nReal, root, printInfo)\n \n implicit none\n\n logical, optional , intent (in) :: printInfo\n integer , intent (out) :: nReal\n real (kind = wp), intent (in) :: q3, q2, q1, q0\n real (kind = wp), intent (out) :: root (1:4,1:2)\n\n logical :: bisection\n logical :: converged\n logical :: doPrint\n logical :: iterate\n logical :: minimum\n logical :: notZero\n\n integer :: deflateCase\n integer :: oscillate\n integer :: quarticType\n\n integer, parameter :: Re = 1\n integer, parameter :: Im = 2\n\n integer, parameter :: biquadratic = 2\n integer, parameter :: cubic = 3\n integer, parameter :: general = 4\n\n real (kind = wp) :: a0, a1, a2, a3\n real (kind = wp) :: a, b, c, d, k, s, t, u, x, y, z\n\n real (kind = wp), parameter :: macheps = epsilon (1.0_wp)\n real (kind = wp), parameter :: third = 1.0_wp / 3.0_wp\n!\n!\n! ...Start.\n!\n!\n if (present (printInfo)) then\n doPrint = printInfo\n else\n doPrint = .false.\n end if\n\n if (doPrint) then\n write (*,wpformat) ' initial quartic q3 = ',q3\n write (*,wpformat) ' initial quartic q2 = ',q2\n write (*,wpformat) ' initial quartic q1 = ',q1\n write (*,wpformat) ' initial quartic q0 = ',q0\n write (*,wpformat) ' ------------------------------------------------'\n end if\n!\n!\n! ...Handle special cases. Since the cubic solver handles all its\n! special cases by itself, we need to check only for two cases:\n!\n! 1) independent term is zero -> solve cubic and include\n! the zero root\n!\n! 2) the biquadratic case.\n!\n!\n if (q0 == 0.0_wp) then\n\n k = 1.0_wp\n a3 = q3\n a2 = q2\n a1 = q1\n\n quarticType = cubic\n\n else if (q3 == 0.0_wp .and. q1 == 0.0_wp) then\n\n k = 1.0_wp\n a2 = q2\n a0 = q0\n\n quarticType = biquadratic\n\n else\n!\n!\n! ...The general case. Rescale quartic polynomial, such that largest absolute coefficient\n! is (exactly!) equal to 1. Honor the presence of a special quartic case that might have\n! been obtained during the rescaling process (due to underflow in the coefficients).\n!\n!\n s = abs (q3)\n t = sqrt (abs (q2))\n u = abs (q1) ** third\n x = sqrt (sqrt (abs (q0)))\n y = max (s,t,u,x)\n\n if (y == s) then\n\n k = 1.0_wp / s\n a3 = sign (1.0_wp , q3)\n a2 = (q2 * k) * k\n a1 = ((q1 * k) * k) * k\n a0 = (((q0 * k) * k) * k) * k\n\n else if (y == t) then\n\n k = 1.0_wp / t\n a3 = q3 * k\n a2 = sign (1.0_wp , q2)\n a1 = ((q1 * k) * k) * k\n a0 = (((q0 * k) * k) * k) * k\n\n else if (y == u) then\n\n k = 1.0_wp / u\n a3 = q3 * k\n a2 = (q2 * k) * k\n a1 = sign (1.0_wp , q1)\n a0 = (((q0 * k) * k) * k) * k\n\n else\n\n k = 1.0_wp / x\n a3 = q3 * k\n a2 = (q2 * k) * k\n a1 = ((q1 * k) * k) * k\n a0 = sign (1.0_wp , q0)\n\n end if\n\n k = 1.0_wp / k\n\n if (doPrint) then\n write (*,wpformat) ' rescaling factor = ',k\n write (*,wpformat) ' ------------------------------------------------'\n write (*,wpformat) ' rescaled quartic q3 = ',a3\n write (*,wpformat) ' rescaled quartic q2 = ',a2\n write (*,wpformat) ' rescaled quartic q1 = ',a1\n write (*,wpformat) ' rescaled quartic q0 = ',a0\n write (*,wpformat) ' ------------------------------------------------'\n end if\n\n if (a0 == 0.0_wp) then\n quarticType = cubic\n else if (a3 == 0.0_wp .and. a1 == 0.0_wp) then\n quarticType = biquadratic\n else\n quarticType = general\n end if\n\n end if\n!\n!\n! ...Select the case.\n!\n! 1) The quartic with independent term = 0 -> solve cubic and add a zero root.\n!\n!\n select case (quarticType)\n\n case (cubic)\n\n call cubicRoots (a3, a2, a1, nReal, root (1:3,1:2), printInfo)\n\n if (nReal == 3) then\n\n x = root (1,Re) * k ! real roots of cubic are ordered x >= y >= z\n y = root (2,Re) * k\n z = root (3,Re) * k\n\n nReal = 4\n\n root (1,Re) = max (x, 0.0_wp)\n root (2,Re) = max (y, min (x, 0.0_wp))\n root (3,Re) = max (z, min (y, 0.0_wp))\n root (4,Re) = min (z, 0.0_wp)\n root (:,Im) = 0.0_wp\n\n else ! there is only one real cubic root here\n\n x = root (1,Re) * k\n\n nReal = 2\n\n root (4,Re) = root (3,Re) * k\n root (3,Re) = root (2,Re) * k\n root (2,Re) = min (x, 0.0_wp)\n root (1,Re) = max (x, 0.0_wp)\n\n root (4,Im) = root (3,Im) * k\n root (3,Im) = root (2,Im) * k\n root (2,Im) = 0.0_wp\n root (1,Im) = 0.0_wp\n\n end if\n!\n!\n! ...2) The quartic with x^3 and x terms = 0 -> solve biquadratic.\n!\n!\n case (biquadratic)\n\n call quadraticRoots (q2, q0, nReal, root (1:2,1:2))\n\n if (nReal == 2) then\n\n x = root (1,Re) ! real roots of quadratic are ordered x >= y\n y = root (2,Re)\n\n if (y >= 0.0_wp) then\n\n x = sqrt (x) * k\n y = sqrt (y) * k\n\n nReal = 4\n\n root (1,Re) = x\n root (2,Re) = y\n root (3,Re) = - y\n root (4,Re) = - x\n root (:,Im) = 0.0_wp\n\n else if (x >= 0.0_wp .and. y < 0.0_wp) then\n\n x = sqrt (x) * k\n y = sqrt (abs (y)) * k\n\n nReal = 2\n\n root (1,Re) = x\n root (2,Re) = - x\n root (3,Re) = 0.0_wp\n root (4,Re) = 0.0_wp\n root (1,Im) = 0.0_wp\n root (2,Im) = 0.0_wp\n root (3,Im) = y\n root (4,Im) = - y\n\n else if (x < 0.0_wp) then\n\n x = sqrt (abs (x)) * k\n y = sqrt (abs (y)) * k\n\n nReal = 0\n\n root (:,Re) = 0.0_wp\n root (1,Im) = y\n root (2,Im) = x\n root (3,Im) = - x\n root (4,Im) = - y\n\n end if\n\n else ! complex conjugate pair biquadratic roots x +/- iy.\n \n x = root (1,Re) * 0.5_wp\n y = root (1,Im) * 0.5_wp\n z = sqrt (x * x + y * y)\n y = sqrt (z - x) * k\n x = sqrt (z + x) * k\n\n nReal = 0\n\n root (1,Re) = x\n root (2,Re) = x\n root (3,Re) = - x\n root (4,Re) = - x\n root (1,Im) = y\n root (2,Im) = - y\n root (3,Im) = y\n root (4,Im) = - y\n\n end if\n!\n!\n! ...3) The general quartic case. Search for stationary points. Set the first\n! derivative polynomial (cubic) equal to zero and find its roots.\n! Check, if any minimum point of Q(x) is below zero, in which case we\n! must have real roots for Q(x). Hunt down only the real root, which\n! will potentially converge fastest during Newton iterates. The remaining\n! roots will be determined by deflation Q(x) -> cubic.\n!\n! The best roots for the Newton iterations are the two on the opposite\n! ends, i.e. those closest to the +2 and -2. Which of these two roots\n! to take, depends on the location of the Q(x) minima x = s and x = u,\n! with s > u. There are three cases:\n!\n! 1) both Q(s) and Q(u) < 0\n! ----------------------\n!\n! The best root is the one that corresponds to the lowest of\n! these minima. If Q(s) is lowest -> start Newton from +2\n! downwards (or zero, if s < 0 and a0 > 0). If Q(u) is lowest\n! -> start Newton from -2 upwards (or zero, if u > 0 and a0 > 0).\n!\n! 2) only Q(s) < 0\n! -------------\n!\n! With both sides +2 and -2 possible as a Newton starting point,\n! we have to avoid the area in the Q(x) graph, where inflection\n! points are present. Solving Q''(x) = 0, leads to solutions\n! x = -a3/4 +/- discriminant, i.e. they are centered around -a3/4.\n! Since both inflection points must be either on the r.h.s or l.h.s.\n! from x = s, a simple test where s is in relation to -a3/4 allows\n! us to avoid the inflection point area.\n!\n! 3) only Q(u) < 0\n! -------------\n!\n! Same of what has been said under 2) but with x = u.\n!\n!\n case (general)\n\n x = 0.75_wp * a3\n y = 0.50_wp * a2\n z = 0.25_wp * a1\n\n if (doPrint) then\n write (*,wpformat) ' dQ(x)/dx cubic c2 = ',x\n write (*,wpformat) ' dQ(x)/dx cubic c1 = ',y\n write (*,wpformat) ' dQ(x)/dx cubic c0 = ',z\n write (*,wpformat) ' ------------------------------------------------'\n end if\n\n call cubicRoots (x, y, z, nReal, root (1:3,1:2), printInfo)\n\n s = root (1,Re) ! Q'(x) root s (real for sure)\n x = s + a3\n x = x * s + a2\n x = x * s + a1\n x = x * s + a0 ! Q(s)\n\n y = 1.0_wp ! dual info: Q'(x) has more real roots, and if so, is Q(u) < 0 ? \n\n if (nReal > 1) then\n u = root (3,Re) ! Q'(x) root u\n y = u + a3\n y = y * u + a2\n y = y * u + a1\n y = y * u + a0 ! Q(u)\n end if\n\n if (doPrint) then\n write (*,wpformat) ' dQ(x)/dx root s = ',s\n write (*,wpformat) ' Q(s) = ',x\n write (*,wpformat) ' dQ(x)/dx root u = ',u\n write (*,wpformat) ' Q(u) = ',y\n write (*,wpformat) ' ------------------------------------------------'\n end if\n\n if (x < 0.0_wp .and. y < 0.0_wp) then\n\n if (x < y) then\n if (s < 0.0_wp) then\n x = 1.0_wp - sign (1.0_wp,a0)\n else\n x = 2.0_wp\n end if\n else\n if (u > 0.0_wp) then\n x = - 1.0_wp + sign (1.0_wp,a0)\n else\n x = - 2.0_wp\n end if\n end if\n\n nReal = 1\n\n else if (x < 0.0_wp) then\n\n if (s < - a3 * 0.25_wp) then\n if (s > 0.0_wp) then\n x = - 1.0_wp + sign (1.0_wp,a0)\n else\n x = - 2.0_wp\n end if\n else\n if (s < 0.0_wp) then\n x = 1.0_wp - sign (1.0_wp,a0)\n else\n x = 2.0_wp\n end if\n end if\n\n nReal = 1\n\n else if (y < 0.0_wp) then\n\n if (u < - a3 * 0.25_wp) then\n if (u > 0.0_wp) then\n x = - 1.0_wp + sign (1.0_wp,a0)\n else\n x = - 2.0_wp\n end if\n else\n if (u < 0.0_wp) then\n x = 1.0_wp - sign (1.0_wp,a0)\n else\n x = 2.0_wp\n end if\n end if\n\n nReal = 1\n else\n nReal = 0\n end if\n!\n!\n! ...Do all necessary Newton iterations. In case we have more than 2 oscillations,\n! exit the Newton iterations and switch to bisection. Note, that from the\n! definition of the Newton starting point, we always have Q(x) > 0 and Q'(x)\n! starts (-ve/+ve) for the (-2/+2) starting points and (increase/decrease) smoothly\n! and staying (< 0 / > 0). In practice, for extremely shallow Q(x) curves near the\n! root, the Newton procedure can overshoot slightly due to rounding errors when\n! approaching the root. The result are tiny oscillations around the root. If such\n! a situation happens, the Newton iterations are abandoned after 3 oscillations\n! and further location of the root is done using bisection starting with the\n! oscillation brackets.\n!\n!\n if (nReal > 0) then\n\n oscillate = 0\n bisection = .false.\n converged = .false.\n\n do while (.not.converged .and. .not.bisection) ! Newton-Raphson iterates\n\n y = x + a3 !\n z = x + y !\n y = y * x + a2 ! y = Q(x)\n z = z * x + y !\n y = y * x + a1 ! z = Q'(x)\n z = z * x + y !\n y = y * x + a0 !\n\n if (y < 0.0_wp) then ! does Newton start oscillating ?\n oscillate = oscillate + 1 ! increment oscillation counter\n s = x ! save lower bisection bound\n else\n u = x ! save upper bisection bound\n end if\n\n y = y / z ! Newton correction\n x = x - y ! new Newton root\n\n bisection = oscillate > 2 ! activate bisection\n converged = abs (y) <= abs (x) * macheps ! Newton convergence indicator\n\n if (doPrint) write (*,wpformat) ' Newton root = ',x\n\n end do\n\n if (bisection) then\n\n t = u - s ! initial bisection interval\n do while (abs (t) > abs (x) * macheps) ! bisection iterates\n\n y = x + a3 !\n y = y * x + a2 ! y = Q(x)\n y = y * x + a1 !\n y = y * x + a0 !\n\n if (y < 0.0_wp) then !\n s = x !\n else ! keep bracket on root\n u = x !\n end if !\n\n t = 0.5_wp * (u - s) ! new bisection interval\n x = s + t ! new bisection root\n\n if (doPrint) write (*,wpformat) ' Bisection root = ',x\n\n end do\n end if\n\n if (doPrint) write (*,wpformat) ' ------------------------------------------------'\n!\n!\n! ...Find remaining roots -> reduce to cubic. The reduction to a cubic polynomial\n! is done using composite deflation to minimize rounding errors. Also, while\n! the composite deflation analysis is done on the reduced quartic, the actual\n! deflation is being performed on the original quartic again to avoid enhanced\n! propagation of root errors.\n!\n!\n z = abs (x) !\n a = abs (a3) !\n b = abs (a2) ! prepare for composite deflation\n c = abs (a1) !\n d = abs (a0) !\n\n y = z * max (a,z) ! take maximum between |x^2|,|a3 * x|\n\n deflateCase = 1 ! up to now, the maximum is |x^4| or |a3 * x^3|\n\n if (y < b) then ! check maximum between |x^2|,|a3 * x|,|a2|\n y = b * z ! the maximum is |a2| -> form |a2 * x|\n deflateCase = 2 ! up to now, the maximum is |a2 * x^2|\n else\n y = y * z ! the maximum is |x^3| or |a3 * x^2|\n end if\n\n if (y < c) then ! check maximum between |x^3|,|a3 * x^2|,|a2 * x|,|a1|\n y = c * z ! the maximum is |a1| -> form |a1 * x|\n deflateCase = 3 ! up to now, the maximum is |a1 * x|\n else\n y = y * z ! the maximum is |x^4|,|a3 * x^3| or |a2 * x^2|\n end if\n\n if (y < d) then ! check maximum between |x^4|,|a3 * x^3|,|a2 * x^2|,|a1 * x|,|a0|\n deflateCase = 4 ! the maximum is |a0|\n end if\n\n x = x * k ! 1st real root of original Q(x)\n\n select case (deflateCase)\n\n case (1)\n z = 1.0_wp / x\n u = - q0 * z ! u -> backward deflation on original Q(x)\n t = (u - q1) * z ! t -> backward deflation on original Q(x)\n s = (t - q2) * z ! s -> backward deflation on original Q(x)\n case (2)\n z = 1.0_wp / x\n u = - q0 * z ! u -> backward deflation on original Q(x)\n t = (u - q1) * z ! t -> backward deflation on original Q(x)\n s = q3 + x ! s -> forward deflation on original Q(x)\n case (3)\n s = q3 + x ! s -> forward deflation on original Q(x)\n t = q2 + s * x ! t -> forward deflation on original Q(x)\n u = - q0 / x ! u -> backward deflation on original Q(x)\n case (4)\n s = q3 + x ! s -> forward deflation on original Q(x)\n t = q2 + s * x ! t -> forward deflation on original Q(x)\n u = q1 + t * x ! u -> forward deflation on original Q(x)\n end select\n\n if (doPrint) then\n write (*,wpformat) ' Residual cubic c2 = ',s\n write (*,wpformat) ' Residual cubic c1 = ',t\n write (*,wpformat) ' Residual cubic c0 = ',u\n write (*,wpformat) ' ------------------------------------------------'\n end if\n\n call cubicRoots (s, t, u, nReal, root (1:3,1:2), printInfo)\n\n if (nReal == 3) then\n\n s = root (1,Re) !\n t = root (2,Re) ! real roots of cubic are ordered s >= t >= u\n u = root (3,Re) !\n\n root (1,Re) = max (s, x)\n root (2,Re) = max (t, min (s, x))\n root (3,Re) = max (u, min (t, x))\n root (4,Re) = min (u, x)\n root (:,Im) = 0.0_wp\n\n nReal = 4\n\n else ! there is only one real cubic root here\n\n s = root (1,Re)\n\n root (4,Re) = root (3,Re)\n root (3,Re) = root (2,Re)\n root (2,Re) = min (s, x)\n root (1,Re) = max (s, x)\n root (4,Im) = root (3,Im)\n root (3,Im) = root (2,Im)\n root (2,Im) = 0.0_wp\n root (1,Im) = 0.0_wp\n\n nReal = 2\n\n end if\n\n else\n!\n!\n! ...If no real roots have been found by now, only complex roots are possible.\n! Find real parts of roots first, followed by imaginary components.\n!\n!\n s = a3 * 0.5_wp\n t = s * s - a2\n u = s * t + a1 ! value of Q'(-a3/4) at stationary point -a3/4\n\n notZero = (abs (u) >= macheps) ! H(-a3/4) is considered > 0 at stationary point\n\n if (doPrint) then\n write (*,wpformat) ' dQ/dx (-a3/4) value = ',u\n write (*,wpformat) ' ------------------------------------------------'\n end if\n\n if (a3 /= 0.0_wp) then\n s = a1 / a3\n minimum = (a0 > s * s) ! H''(-a3/4) > 0 -> minimum\n else\n minimum = (4 * a0 > a2 * a2) ! H''(-a3/4) > 0 -> minimum\n end if\n\n iterate = notZero .or. (.not.notZero .and. minimum)\n\n if (iterate) then\n\n x = sign (2.0_wp,a3) ! initial root -> target = smaller mag root\n\n oscillate = 0\n bisection = .false.\n converged = .false.\n\n do while (.not.converged .and. .not.bisection) ! Newton-Raphson iterates\n\n a = x + a3 !\n b = x + a ! a = Q(x)\n c = x + b !\n d = x + c ! b = Q'(x)\n a = a * x + a2 !\n b = b * x + a ! c = Q''(x) / 2\n c = c * x + b !\n a = a * x + a1 ! d = Q'''(x) / 6\n b = b * x + a !\n a = a * x + a0 !\n y = a * d * d - b * c * d + b * b ! y = H(x), usually < 0\n z = 2 * d * (4 * a - b * d - c * c) ! z = H'(x)\n\n if (y > 0.0_wp) then ! does Newton start oscillating ?\n oscillate = oscillate + 1 ! increment oscillation counter\n s = x ! save upper bisection bound\n else\n u = x ! save lower bisection bound\n end if\n\n y = y / z ! Newton correction\n x = x - y ! new Newton root\n\n bisection = oscillate > 2 ! activate bisection\n converged = abs (y) <= abs (x) * macheps ! Newton convergence criterion\n\n if (doPrint) write (*,wpformat) ' Newton H(x) root = ',x\n\n end do\n\n if (bisection) then\n\n t = u - s ! initial bisection interval\n do while (abs (t) > abs (x * macheps)) ! bisection iterates\n\n a = x + a3 !\n b = x + a ! a = Q(x)\n c = x + b !\n d = x + c ! b = Q'(x)\n a = a * x + a2 !\n b = b * x + a ! c = Q''(x) / 2\n c = c * x + b !\n a = a * x + a1 ! d = Q'''(x) / 6\n b = b * x + a !\n a = a * x + a0 !\n y = a * d * d - b * c * d + b * b ! y = H(x)\n\n if (y > 0.0_wp) then !\n s = x !\n else ! keep bracket on root\n u = x !\n end if !\n\n t = 0.5_wp * (u - s) ! new bisection interval\n x = s + t ! new bisection root\n\n if (doPrint) write (*,wpformat) ' Bisection H(x) root = ',x\n\n end do\n end if\n\n if (doPrint) write (*,wpformat) ' ------------------------------------------------'\n\n a = x * k ! 1st real component -> a\n b = - 0.5_wp * q3 - a ! 2nd real component -> b\n\n x = 4 * a + q3 ! Q'''(a)\n y = x + q3 + q3 !\n y = y * a + q2 + q2 ! Q'(a)\n y = y * a + q1 !\n y = max (y / x, 0.0_wp) ! ensure Q'(a) / Q'''(a) >= 0\n x = 4 * b + q3 ! Q'''(b)\n z = x + q3 + q3 !\n z = z * b + q2 + q2 ! Q'(b)\n z = z * b + q1 !\n z = max (z / x, 0.0_wp) ! ensure Q'(b) / Q'''(b) >= 0\n c = a * a ! store a^2 for later\n d = b * b ! store b^2 for later\n s = c + y ! magnitude^2 of (a + iy) root\n t = d + z ! magnitude^2 of (b + iz) root\n\n if (s > t) then ! minimize imaginary error\n c = sqrt (y) ! 1st imaginary component -> c\n d = sqrt (q0 / s - d) ! 2nd imaginary component -> d\n else\n c = sqrt (q0 / t - c) ! 1st imaginary component -> c\n d = sqrt (z) ! 2nd imaginary component -> d\n end if\n\n else ! no bisection -> real components equal\n\n a = - 0.25_wp * q3 ! 1st real component -> a\n b = a ! 2nd real component -> b = a\n\n x = a + q3 !\n x = x * a + q2 ! Q(a)\n x = x * a + q1 !\n x = x * a + q0 !\n y = - 0.1875_wp * q3 * q3 + 0.5_wp * q2 ! Q''(a) / 2\n z = max (y * y - x, 0.0_wp) ! force discriminant to be >= 0\n z = sqrt (z) ! square root of discriminant\n y = y + sign (z,y) ! larger magnitude root\n x = x / y ! smaller magnitude root\n c = max (y, 0.0_wp) ! ensure root of biquadratic > 0\n d = max (x, 0.0_wp) ! ensure root of biquadratic > 0\n c = sqrt (c) ! large magnitude imaginary component\n d = sqrt (d) ! small magnitude imaginary component\n\n end if\n\n if (a > b) then\n\n root (1,Re) = a\n root (2,Re) = a\n root (3,Re) = b\n root (4,Re) = b\n root (1,Im) = c\n root (2,Im) = - c\n root (3,Im) = d\n root (4,Im) = - d\n\n else if (a < b) then\n\n root (1,Re) = b\n root (2,Re) = b\n root (3,Re) = a\n root (4,Re) = a\n root (1,Im) = d\n root (2,Im) = - d\n root (3,Im) = c\n root (4,Im) = - c\n\n else\n\n root (1,Re) = a\n root (2,Re) = a\n root (3,Re) = a\n root (4,Re) = a\n root (1,Im) = c\n root (2,Im) = - c\n root (3,Im) = d\n root (4,Im) = - d\n\n end if\n\n end if ! # of real roots 'if'\n\n end select ! quartic type select\n!\n!\n! ...Ready!\n!\n!\n return\nend subroutine quarticRoots\n\nend module Polynomial234RootSolvers\n", "meta": {"hexsha": "069a37a94384848a8fb544930ab1ad445849b376", "size": 52573, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SRC/contrib/Polynomial234RootSolvers.f90", "max_stars_repo_name": "micheder/GORILLA_fork", "max_stars_repo_head_hexsha": "78c01af79229c9dcae17e4aa4b7c66f60ac8730b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SRC/contrib/Polynomial234RootSolvers.f90", "max_issues_repo_name": "micheder/GORILLA_fork", "max_issues_repo_head_hexsha": "78c01af79229c9dcae17e4aa4b7c66f60ac8730b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SRC/contrib/Polynomial234RootSolvers.f90", "max_forks_repo_name": "micheder/GORILLA_fork", "max_forks_repo_head_hexsha": "78c01af79229c9dcae17e4aa4b7c66f60ac8730b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.2138480392, "max_line_length": 107, "alphanum_fraction": 0.4045802979, "num_tokens": 15085, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430812881347, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7520019134002075}} {"text": "! $UWHPSC/codes/fortran/circles/circle_mod.f90\n! Version where pi is a module variable.\n\nmodule circle_mod\n\n implicit none\n real(kind=8) :: pi \n save \n\ncontains\n\n real(kind=8) function area(r)\n real(kind=8), intent(in) :: r\n area = pi * r**2\n end function area\n\n real(kind=8) function circumference(r)\n real(kind=8), intent(in) :: r\n circumference = 2.d0 * pi * r\n end function circumference\n\nend module circle_mod\n", "meta": {"hexsha": "ba98a191e296e460bf1bb430d8a591315d6df92c", "size": 465, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/codes/fortran/circles2/circle_mod.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/codes/fortran/circles2/circle_mod.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/codes/fortran/circles2/circle_mod.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.2173913043, "max_line_length": 46, "alphanum_fraction": 0.6322580645, "num_tokens": 130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308184368928, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7520019069857954}} {"text": "\nsubroutine cum_simps(np,n,x,f,g)\n ! !INPUT/OUTPUT PARAMETERS:\n ! np : order of fitting polynomial (in,integer)\n ! n : number of points (in,integer)\n ! x : abscissa array (in,real(n))\n ! f : function array (in,real(n))\n ! g : integrated function (out,real(n))\n ! !DESCRIPTION:\n ! Calculates the integrals $g(x_i)$ of a function $f$ defined on a set of\n ! points $x_i$ as follows\n ! $$ g(x_i)=\\int_0^{x_i} f(x)\\,dx. $$\n ! This is performed by piecewise fitting the function to polynomials of order\n ! $n_p-1$ and performing the integrations analytically.\n !\n ! !REVISION HISTORY:\n ! Created May 2002 (JKD)\n !EOP\n !BOC\n implicit none\n ! arguments\n integer, intent(in) :: np\n integer, intent(in) :: n\n real(8), intent(in) :: x(n)\n real(8), intent(in) :: f(n)\n real(8), intent(out) :: g(n)\n ! local variables\n integer i,i0,npo2\n ! automatic arrays\n real(8) c(np)\n ! external functions\n real(8) polynom\n external polynom\n if (n.lt.2) then\n write(*,*)\n write(*,'(\"Error(fint): n < 2 : \",I8)') n\n write(*,*)\n stop\n end if\n if (np.lt.2) then\n write(*,*)\n write(*,'(\"Error(fint): np < 2 : \",I8)') np\n write(*,*)\n stop\n end if\n if (n.lt.np) then\n write(*,*)\n write(*,'(\"Error(fint): n < np : \",2I8)') n,np\n write(*,*)\n stop\n end if\n npo2=np/2\n g(1)=0.d0\n do i=2,n\n if (i.le.npo2) then\n i0=1\n else if (i.gt.n-npo2) then\n i0=n-np+1\n else\n i0=i-npo2\n end if\n g(i)=polynom(-1,np,x(i0),f(i0),c,x(i))+g(i0)\n end do\n return\nend subroutine cum_simps\n!EOC\n\nreal(8) function polynom(m,np,xa,ya,c,x)\n implicit none\n integer, intent(in) :: m\n integer, intent(in) :: np\n real(8), intent(in) :: xa(np)\n real(8), intent(in) :: ya(np)\n real(8), intent(out) :: c(np)\n real(8), intent(in) :: x\n ! !LOCAL VARIABLES:\n integer i,j\n real(8) x1,t1,sum\n if (np.le.0) then\n write(6,*)\n write(6,'(\"Error(polynom): np <= 0 : \",I8)') np\n write(6,*)\n print *, \"ERROR: polynom\", \"np<=0\"\n end if\n if (m.gt.np) then\n polynom=0.d0\n return\n end if\n x1=xa(1)\n ! find the polynomial coefficients in divided differences form\n c(:)=ya(:)\n do i=2,np\n do j=np,i,-1\n c(j)=(c(j)-c(j-1))/(xa(j)-xa(j+1-i))\n end do\n end do\n ! special case m=0\n if (m.eq.0) then\n sum=c(1)\n t1=1.d0\n do i=2,np\n t1=t1*(x-xa(i-1))\n sum=sum+c(i)*t1\n end do\n polynom=sum\n return\n end if\n ! convert to standard form\n do j=1,np-1\n do i=1,np-j\n c(np-i)=c(np-i)-(xa(np-i-j+1)-x1)*c(np-i+1)\n end do\n end do\n if (m.gt.0) then\n ! take the m'th derivative\n do j=1,m\n do i=m+1,np\n c(i)=c(i)*dble(i-j)\n end do\n end do\n t1=c(np)\n do i=np-1,m+1,-1\n t1=t1*(x-x1)+c(i)\n end do\n polynom=t1\n else\n ! find the integral\n t1=c(np)/dble(np)\n do i=np-1,1,-1\n t1=t1*(x-x1)+c(i)/dble(i)\n end do\n polynom=t1*(x-x1)\n end if\n return\nend function polynom\n!EOC\n\n", "meta": {"hexsha": "2df62863fba9521962e0b4bac44e2628b89018c7", "size": 3021, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "cum_simps.f90", "max_stars_repo_name": "kunyuan/PyGW", "max_stars_repo_head_hexsha": "7b32065586f7d7cc221d051b5254397fdf0a3076", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-07-06T01:56:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-13T13:07:06.000Z", "max_issues_repo_path": "cum_simps.f90", "max_issues_repo_name": "kunyuan/PyGW", "max_issues_repo_head_hexsha": "7b32065586f7d7cc221d051b5254397fdf0a3076", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cum_simps.f90", "max_forks_repo_name": "kunyuan/PyGW", "max_forks_repo_head_hexsha": "7b32065586f7d7cc221d051b5254397fdf0a3076", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-06T01:56:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-06T01:56:59.000Z", "avg_line_length": 21.8913043478, "max_line_length": 81, "alphanum_fraction": 0.5385633896, "num_tokens": 1163, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308073258007, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7520019023903975}} {"text": " subroutine taper(w,lb,p,sw,nt,io)\r\nc***************************************\r\nc M.J. Hinich Version: 8-22-94\r\nc Compute trancated cosine taper array\r\nc=======================================\r\nc Input:\r\nc lb Number of samples in frame\r\nc p % of data series to be tapered (0.< p < 50.)\r\nc io File number for error message\r\nc Output:\r\nc w Cosine taper weights as a symmetric array\r\nc sw mean sum of squares of the taper including the middle 1's\r\nc nt Number of observations tapered on each end of window\r\nc=======================================\r\n real w(lb)\r\n intent(in) lb,p,io\r\n intent(out) w,sw,nt\r\nc***************************************\r\n pi=acos(-1.)\r\nc Return if p=0\r\n if(p<=0.) then\r\n return\r\n endif\r\n if(p<0..or.p>50.) then\r\n write(io,*) '* ERROR * Improper % for tapering: ',p\r\n return\r\n endif\r\nc-------\r\nc Compute number of values to be tapered on each end\r\n nt=nint(p*float(lb)/200.)\r\n if(nt>lb/4) then\r\n write(io,*) 'Taper size ',nt,' > lb/4. Increase data frame ',lb\r\n return\r\n endif\r\nc Taper weights and sum of squares sw\r\n sw=0.\r\n do k=1,nt\r\n w(k)=sin(pi*k/(2.*float(nt+1)))\r\n w(lb+1-k)=w(k)\r\n sw=sw+w(k)*w(k)\r\n enddo\r\n sw=(2.*sw+float(lb-2*nt))/float(lb)\r\nc Fill out w array\r\n do k=nt+1,lb-nt\r\n w(k)=1.\r\n enddo\r\nc-------\r\n return\r\n end\r\n", "meta": {"hexsha": "589ef1cfbbc3590399f0e0c990841a719020b1f7", "size": 1458, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "taper.for", "max_stars_repo_name": "emammendes/bispectrum", "max_stars_repo_head_hexsha": "03d46999d478911615dc01c7d9108870eadc9ab6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2015-09-29T05:27:08.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-09T09:09:36.000Z", "max_issues_repo_path": "taper.for", "max_issues_repo_name": "emammendes/bispectrum", "max_issues_repo_head_hexsha": "03d46999d478911615dc01c7d9108870eadc9ab6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "taper.for", "max_forks_repo_name": "emammendes/bispectrum", "max_forks_repo_head_hexsha": "03d46999d478911615dc01c7d9108870eadc9ab6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.16, "max_line_length": 71, "alphanum_fraction": 0.4801097394, "num_tokens": 430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308073258009, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7520018980343421}} {"text": " MODULE random_multivariate_normal_mod\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n! .. Local Arrays ..\n REAL, ALLOCATABLE, SAVE :: param(:)\n! ..\n CONTAINS\n\n!*********************************************************************\n\n SUBROUTINE random_multivariate_normal(x)\n! .. Use Statements ..\n USE random_standard_normal_mod\n! ..\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n! .. Array Arguments ..\n REAL, INTENT (OUT) :: x(:)\n! ..\n! .. Local Scalars ..\n REAL :: ae\n INTEGER :: i, icount, j, p\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ALLOCATED, INT, SIZE\n! ..\n! .. Local Arrays ..\n REAL, ALLOCATABLE :: work(:)\n! ..\n! .. Executable Statements ..\n\n!----------------------------------------------------------------------\n! SUBROUTINE RANDOM_MULTIVARIATE_NORMAL(X)\n! Arguments\n! X <-- Vector deviate generated.\n! REAL X(P)\n! Method\n! 1) Generate P independent standard normal deviates - Ei ~ N(0,1)\n! 2) Using Cholesky decomposition find A s.t. trans(A)*A = COVM\n! 3) trans(A)E + MEANV ~ N(MEANV,COVM)\n!______________________________________________________________________\n p = INT(param(1))\n\n! Allocate array work if necessary\n\n IF ( .NOT. ALLOCATED(work)) ALLOCATE (work(p))\n\n IF (SIZE(work) Mean vector of multivariate normal distribution.\n! REAL MEANV(P)\n! COVM <--> (Input) Covariance matrix of the multivariate\n! normal distribution. This routine uses only the\n! (1:P,1:P) slice of COVM, but needs to know DIM1_COVM.\n! (Output) Destroyed on output\n! REAL COVM(DIM1_COVM,P)\n! P --> Dimension of the normal, or length of MEANV.\n! INTEGER P\n!**********************************************************************\n IF (p<=0) THEN\n WRITE (*,*) 'P nonpositive in SET_RANDOM_MULTIVARIATE_NORMAL'\n WRITE (*,*) 'Value of P: ', p\n STOP 'P nonpositive in SET_RANDOM_MULTIVARIATE_NORMAL'\n END IF\n\n dim1_covm = SIZE(covm,dim=1)\n dim2_covm = SIZE(covm,dim=2)\n\n IF ((dim1_covm0) THEN\n param(icount+1:p-i+1+icount) = covm(i,i:p)\n icount = p - i + 1 + icount\n END IF\n END DO\n RETURN\n\n CONTAINS\n\n!.....................................................................\n\n FUNCTION sdot(n,sx,incx,sy,incy)\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n! .. Function Return Value ..\n REAL :: sdot\n! ..\n! .. Scalar Arguments ..\n INTEGER, INTENT (IN) :: incx, incy, n\n! ..\n! .. Array Arguments ..\n REAL, INTENT (IN) :: sx(1), sy(1)\n! ..\n! .. Local Scalars ..\n REAL :: stemp\n INTEGER :: ix, iy, m, mp1\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC DOT_PRODUCT, MOD\n! ..\n! .. Executable Statements ..\n\n!-----------------------------------------------\n stemp = 0.0E0\n sdot = 0.0E0\n IF (n<=0) RETURN\n IF (incx/=1 .OR. incy/=1) THEN\n ix = 1\n iy = 1\n IF (incx<0) ix = ((-n)+1)*incx + 1\n IF (incy<0) iy = ((-n)+1)*incy + 1\n stemp = DOT_PRODUCT(sx(ix:(n-1)*incx+ix:incx),sy(iy:(n- &\n 1)*incy+iy:incy))\n sdot = stemp\n RETURN\n END IF\n\n m = MOD(n,5)\n IF (m==0) GO TO 10\n stemp = DOT_PRODUCT(sx(:m),sy(:m))\n IF (n<5) GO TO 20\n10 CONTINUE\n mp1 = m + 1\n stemp = stemp + DOT_PRODUCT(sx(mp1:((n-mp1+5)/5)*5-1+mp1),sy( &\n mp1:((n-mp1+5)/5)*5-1+mp1))\n20 CONTINUE\n sdot = stemp\n RETURN\n\n END FUNCTION sdot\n\n!.....................................................................\n\n SUBROUTINE spofa(a,lda,n,info)\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n! .. Scalar Arguments ..\n INTEGER, INTENT (OUT) :: info\n INTEGER, INTENT (IN) :: lda, n\n! ..\n! .. Array Arguments ..\n REAL :: a(lda,1)\n! ..\n! .. Local Scalars ..\n REAL :: s, t\n INTEGER :: j, jm1, k\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC SQRT\n! ..\n! .. Executable Statements ..\n\n!**********************************************************************\n! SPOFA FACTORS A REAL SYMMETRIC POSITIVE DEFINITE MATRIX.\n! SPOFA IS USUALLY CALLED BY SPOCO, BUT IT CAN BE CALLED\n! DIRECTLY WITH A SAVING IN TIME IF RCOND IS NOT NEEDED.\n! (TIME FOR SPOCO) = (1 + 18/N)*(TIME FOR SPOFA) .\n! ON ENTRY\n! A REAL(LDA, N)\n! THE SYMMETRIC MATRIX TO BE FACTORED. ONLY THE\n! DIAGONAL AND UPPER TRIANGLE ARE USED.\n! LDA INTEGER\n! THE LEADING DIMENSION OF THE ARRAY A .\n! N INTEGER\n! THE ORDER OF THE MATRIX A .\n! ON RETURN\n! A AN UPPER TRIANGULAR MATRIX R SO THAT A = TRANS(R)*R\n! WHERE TRANS(R) IS THE TRANSPOSE.\n! THE STRICT LOWER TRIANGLE IS UNALTERED.\n! IF INFO .NE. 0 , THE FACTORIZATION IS NOT COMPLETE.\n! INFO INTEGER\n! = 0 FOR NORMAL RETURN.\n! = K SIGNALS AN ERROR CONDITION. THE LEADING MINOR\n! OF ORDER K IS NOT POSITIVE DEFINITE.\n! LINPACK. THIS VERSION DATED 08/14/78 .\n! CLEVE MOLER, UNIVERSITY OF NEW MEXICO, ARGONNE NATIONAL LAB.\n! SUBROUTINES AND FUNCTIONS\n! BLAS SDOT\n! FORTRAN SQRT\n! INTERNAL VARIABLES\n! BEGIN BLOCK WITH ...EXITS TO 40\n!**********************************************************************\n DO j = 1, n\n info = j\n s = 0.0E0\n jm1 = j - 1\n IF (jm1>=1) THEN\n DO k = 1, jm1\n t = a(k,j) - sdot(k-1,a(1,k),1,a(1,j),1)\n t = t/a(k,k)\n a(k,j) = t\n s = s + t*t\n END DO\n END IF\n s = a(j,j) - s\n IF (s<=0.0E0) GO TO 10\n a(j,j) = SQRT(s)\n END DO\n info = 0\n10 CONTINUE\n RETURN\n\n END SUBROUTINE spofa\n\n!.....................................................................\n\n END SUBROUTINE set_random_multivariate_normal\n\n!*********************************************************************\n\n END MODULE random_multivariate_normal_mod\n", "meta": {"hexsha": "ac3a0c38dd59c3ecd13f992071bdb9635c8bc8b3", "size": 10281, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/random_multivariate_normal_mod.f90", "max_stars_repo_name": "urbanjost/fpm_tools", "max_stars_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/random_multivariate_normal_mod.f90", "max_issues_repo_name": "urbanjost/fpm_tools", "max_issues_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/random_multivariate_normal_mod.f90", "max_forks_repo_name": "urbanjost/fpm_tools", "max_forks_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-14T11:36:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-14T11:36:01.000Z", "avg_line_length": 31.536809816, "max_line_length": 74, "alphanum_fraction": 0.4684369225, "num_tokens": 2785, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.7519995716381714}} {"text": "program compute_distance\n use, intrinsic :: iso_fortran_env, only : error_unit, DP => REAL64\n implicit none\n real(kind=DP), parameter :: PI = acos(-1.0_DP), &\n PHI = 0.5_DP*(1.0_DP + sqrt(5.0_DP)), &\n B_REC = 0.5_DP*PI/log(PHI), &\n DELTA_R = 1e-3_DP\n integer :: nr_values, i\n real(kind=DP) :: r, theta, x, y, distance, x_old, y_old\n\n call get_arguments(nr_values)\n\n distance = 0.0_DP\n r = 1.0_DP\n x_old = 1.0_DP\n y_old = 0.0_DP\n do i = 1, nr_values\n theta = golden_spiral(r)\n x = r*cos(theta)\n y = r*sin(theta)\n distance = distance + sqrt((x_old - x)**2 + (y_old - y)**2)\n x_old = x\n y_old = y\n r = r + DELTA_R\n end do\n\n print '(A, E27.15)', 'distance = ', distance\n\ncontains\n\n subroutine get_arguments(nr_values)\n implicit none\n integer, intent(out) :: nr_values\n character(len=128) :: buffer, msg\n integer :: istat\n\n if (command_argument_count() /= 1) then\n write (unit=error_unit, fmt='(A)') &\n 'error: expecting number of values as argument'\n stop 1\n end if\n\n call get_command_argument(1, buffer)\n read (buffer, fmt=*, iomsg=msg, iostat=istat) nr_values\n if (istat /= 0) then\n write (unit=error_unit, fmt='(2A)') 'error: ', trim(msg)\n stop 2\n end if\n end subroutine get_arguments\n\n function golden_spiral(r) result(theta)\n implicit none\n real(kind=DP), value :: r\n real(kind=DP) :: theta\n theta = B_REC*log(r)\n end function golden_spiral\n\nend program compute_distance\n", "meta": {"hexsha": "6c848a5cf763a2b285b990c0cb7aaaaa84b2ff45", "size": 1722, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/io_performance/sequential/compute_distance.f90", "max_stars_repo_name": "caguerra/Fortran-MOOC", "max_stars_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-05-20T12:03:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T19:46:26.000Z", "max_issues_repo_path": "source_code/io_performance/sequential/compute_distance.f90", "max_issues_repo_name": "caguerra/Fortran-MOOC", "max_issues_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-30T04:25:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T08:21:30.000Z", "max_forks_repo_path": "source_code/io_performance/sequential/compute_distance.f90", "max_forks_repo_name": "caguerra/Fortran-MOOC", "max_forks_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-09-27T07:30:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T16:23:19.000Z", "avg_line_length": 29.186440678, "max_line_length": 71, "alphanum_fraction": 0.5418118467, "num_tokens": 493, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7519275022445525}} {"text": "FUNCTION bessi1_s(x)\n use mo_kind\n use mo_nrutil, ONLY : poly\n IMPLICIT NONE\n REAL(SP), INTENT(IN) :: x\n REAL(SP) :: bessi1_s\n REAL(SP) :: ax\n REAL(sp), DIMENSION(7) :: p = (/0.5_sp,0.87890594_sp,&\n 0.51498869_sp,0.15084934_sp,0.2658733e-1_sp,&\n 0.301532e-2_sp,0.32411e-3_sp/)\n REAL(sp), DIMENSION(9) :: q = (/0.39894228_sp,-0.3988024e-1_sp,&\n -0.362018e-2_sp,0.163801e-2_sp,-0.1031555e-1_sp,&\n 0.2282967e-1_sp,-0.2895312e-1_sp,0.1787654e-1_sp,&\n -0.420059e-2_sp/)\n ax=abs(x)\n if (ax < 3.75_sp) then\n bessi1_s=ax*poly(real((x/3.75_sp)**2,sp),p)\n else\n bessi1_s=(exp(ax)/sqrt(ax))*poly(real(3.75_sp/ax,sp),q)\n end if\n if (x < 0.0_sp) bessi1_s=-bessi1_s\nEND FUNCTION bessi1_s\n\n\nFUNCTION bessi1_v(x)\n use mo_kind\n use mo_nrutil, ONLY : poly\n IMPLICIT NONE\n REAL(SP), DIMENSION(:), INTENT(IN) :: x\n REAL(SP), DIMENSION(size(x)) :: bessi1_v\n REAL(SP), DIMENSION(size(x)) :: ax\n REAL(sp), DIMENSION(size(x)) :: y\n LOGICAL(LGT), DIMENSION(size(x)) :: mask\n REAL(sp), DIMENSION(7) :: p = (/0.5_sp,0.87890594_sp,&\n 0.51498869_sp,0.15084934_sp,0.2658733e-1_sp,&\n 0.301532e-2_sp,0.32411e-3_sp/)\n REAL(sp), DIMENSION(9) :: q = (/0.39894228_sp,-0.3988024e-1_sp,&\n -0.362018e-2_sp,0.163801e-2_sp,-0.1031555e-1_sp,&\n 0.2282967e-1_sp,-0.2895312e-1_sp,0.1787654e-1_sp,&\n -0.420059e-2_sp/)\n ax=abs(x)\n mask = (ax < 3.75_sp)\n where (mask)\n bessi1_v=ax*poly(real((x/3.75_sp)**2,sp),p,mask)\n elsewhere\n y=3.75_sp/ax\n bessi1_v=(exp(ax)/sqrt(ax))*poly(real(y,sp),q,.not. mask)\n end where\n where (x < 0.0_sp) bessi1_v=-bessi1_v\nEND FUNCTION bessi1_v\n\nFUNCTION dbessi1_s(x)\n use mo_kind\n use mo_nrutil, ONLY : poly\n IMPLICIT NONE\n REAL(DP), INTENT(IN) :: x\n REAL(DP) :: dbessi1_s\n REAL(DP) :: ax\n REAL(DP), DIMENSION(7) :: p = (/0.5_dp,0.87890594_dp,&\n 0.51498869_dp,0.15084934_dp,0.2658733e-1_dp,&\n 0.301532e-2_dp,0.32411e-3_dp/)\n REAL(DP), DIMENSION(9) :: q = (/0.39894228_dp,-0.3988024e-1_dp,&\n -0.362018e-2_dp,0.163801e-2_dp,-0.1031555e-1_dp,&\n 0.2282967e-1_dp,-0.2895312e-1_dp,0.1787654e-1_dp,&\n -0.420059e-2_dp/)\n ax=abs(x)\n if (ax < 3.75_dp) then\n dbessi1_s=ax*poly(real((x/3.75_dp)**2,dp),p)\n else\n dbessi1_s=(exp(ax)/sqrt(ax))*poly(real(3.75_dp/ax,dp),q)\n end if\n if (x < 0.0_dp) dbessi1_s=-dbessi1_s\nEND FUNCTION dbessi1_s\n\n\nFUNCTION dbessi1_v(x)\n use mo_kind\n use mo_nrutil, ONLY : poly\n IMPLICIT NONE\n REAL(DP), DIMENSION(:), INTENT(IN) :: x\n REAL(DP), DIMENSION(size(x)) :: dbessi1_v\n REAL(DP), DIMENSION(size(x)) :: ax\n REAL(DP), DIMENSION(size(x)) :: y\n LOGICAL(LGT), DIMENSION(size(x)) :: mask\n REAL(DP), DIMENSION(7) :: p = (/0.5_dp,0.87890594_dp,&\n 0.51498869_dp,0.15084934_dp,0.2658733e-1_dp,&\n 0.301532e-2_dp,0.32411e-3_dp/)\n REAL(DP), DIMENSION(9) :: q = (/0.39894228_dp,-0.3988024e-1_dp,&\n -0.362018e-2_dp,0.163801e-2_dp,-0.1031555e-1_dp,&\n 0.2282967e-1_dp,-0.2895312e-1_dp,0.1787654e-1_dp,&\n -0.420059e-2_dp/)\n ax=abs(x)\n where (ax .gt. 709._dp)\n ax = 709._dp\n end where\n mask = (ax < 3.75_dp)\n where (mask)\n dbessi1_v=ax*poly(real((x/3.75_dp)**2,dp),p,mask)\n elsewhere\n y=3.75_dp/ax\n dbessi1_v=(exp(ax)/sqrt(ax))*poly(real(y,dp),q,.not. mask)\n end where\n where (x < 0.0_dp) dbessi1_v=-dbessi1_v\nEND FUNCTION dbessi1_v\n\n", "meta": {"hexsha": "3d2861eb20868c7242e6bf8191fe0ce0fe914038", "size": 3342, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_pumpingtests/bessi1.f90", "max_stars_repo_name": "mcuntz/jams_fortran", "max_stars_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2020-02-28T00:14:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-20T23:32:41.000Z", "max_issues_repo_path": "test/test_mo_pumpingtests/bessi1.f90", "max_issues_repo_name": "mcuntz/jams_fortran", "max_issues_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-09T15:33:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T16:16:09.000Z", "max_forks_repo_path": "test/test_mo_pumpingtests/bessi1.f90", "max_forks_repo_name": "mcuntz/jams_fortran", "max_forks_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-09T08:08:56.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-09T08:08:56.000Z", "avg_line_length": 31.5283018868, "max_line_length": 66, "alphanum_fraction": 0.6328545781, "num_tokens": 1519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593496, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7519274921279654}} {"text": "! save this program as file f.f08\n! gnu-linux command to build and test\n! $ a=./f && gfortran -Wall -std=f2008 $a.f08 -o $a && echo -e 2\\\\n5\\\\n\\\\n | $a\n\n! -*- mode: compilation; default-directory: \"/tmp/\" -*-\n! Compilation started at Fri Apr 4 23:20:27\n!\n! a=./f && gfortran -Wall -std=f2008 $a.f08 -o $a && echo -e 2\\\\n8\\\\ny\\\\n | $a\n! Enter the number of terms to sum: Show the the first how many terms of the sequence? Accept this initial sequence (y/n)?\n! 1 1\n! 1 1 2 3 5 8 13 21\n!\n! Compilation finished at Fri Apr 4 23:20:27\n\nprogram f\n implicit none\n integer :: n, terms\n integer, allocatable, dimension(:) :: sequence\n integer :: i\n character :: answer\n write(6,'(a)',advance='no')'Enter the number of terms to sum: '\n read(5,*) n\n if ((n < 2) .or. (29 < n)) stop'Unreasonable! Exit.'\n write(6,'(a)',advance='no')'Show the the first how many terms of the sequence? '\n read(5,*) terms\n if (terms < 1) stop'Lazy programmer has not implemented backward sequences.'\n n = min(n, terms)\n allocate(sequence(1:terms))\n sequence(1) = 1\n do i = 0, n - 2\n sequence(i+2) = 2**i\n end do\n write(6,*)'Accept this initial sequence (y/n)?'\n write(6,*) sequence(:n)\n read(5,*) answer\n if (answer .eq. 'n') then\n write(6,*) 'Fine. Enter the initial terms.'\n do i=1, n\n write(6, '(i2,a2)', advance = 'no') i, ': '\n read(5, *) sequence(i)\n end do\n end if\n call nacci(n, sequence)\n write(6,*) sequence(:terms)\n deallocate(sequence)\n\ncontains\n\n subroutine nacci(n, s)\n ! nacci =: (] , +/@{.)^:(-@#@]`(-#)`])\n integer, intent(in) :: n\n integer, intent(inout), dimension(:) :: s\n integer :: i, terms\n terms = size(s)\n! do i = n+1, terms\n ! s(i) = sum(s(i-n:i-1))\n ! end do\n i = n+1\n if (n+1 .le. terms) s(i) = sum(s(i-n:i-1))\n do i = n + 2, terms\n s(i) = 2*s(i-1) - s(i-(n+1))\n end do\n end subroutine nacci\nend program f\n", "meta": {"hexsha": "210376c9be3eeb8e47876830b1e4d3e2896cf1a6", "size": 2041, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Fibonacci-n-step-number-sequences/Fortran/fibonacci-n-step-number-sequences.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Fibonacci-n-step-number-sequences/Fortran/fibonacci-n-step-number-sequences.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Fibonacci-n-step-number-sequences/Fortran/fibonacci-n-step-number-sequences.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 31.4, "max_line_length": 124, "alphanum_fraction": 0.5418912298, "num_tokens": 712, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.8311430499496095, "lm_q1q2_score": 0.7518940112921263}} {"text": " function rotation_2(phi,i)\n implicit none\n \n real(kind=8), intent(in) :: phi\n integer, intent(in) :: i\n real(kind=8), dimension(2,2) :: R\n type(Tensor2) :: rotation_2\n \n R = reshape( (/cos(phi), sin(phi),\n * -sin(phi), cos(phi)/), (/2,2/) )\n \n rotation_2 = identity2(rotation_2)\n \n if (i == 1) then\n rotation_2%ab(2:3,2:3) = R\n else if (i == 3) then\n rotation_2%ab(1:2,1:2) = R\n else !i == 2\n rotation_2%ab(1,1) = R(1,1)\n rotation_2%ab(3,3) = R(2,2)\n rotation_2%ab(1,3) = R(1,2)\n rotation_2%ab(3,1) = R(2,1)\n end if\n \n end function rotation_2", "meta": {"hexsha": "d1e8da584839e5d61eb50b2cb8247f8cd7717b37", "size": 763, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ttb/librotation.f", "max_stars_repo_name": "kengwit/ttb", "max_stars_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 41, "max_stars_repo_stars_event_min_datetime": "2018-02-27T06:31:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-30T07:58:45.000Z", "max_issues_repo_path": "ttb/librotation.f", "max_issues_repo_name": "kengwit/ttb", "max_issues_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-12-01T07:47:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-16T05:42:06.000Z", "max_forks_repo_path": "ttb/librotation.f", "max_forks_repo_name": "kengwit/ttb", "max_forks_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-07-12T01:45:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-25T08:03:13.000Z", "avg_line_length": 30.52, "max_line_length": 55, "alphanum_fraction": 0.4311926606, "num_tokens": 253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947055100817, "lm_q2_score": 0.795658104908603, "lm_q1q2_score": 0.7518926965348149}} {"text": "module linalg\n implicit none\n \n integer,parameter :: dp = kind(1.d0) \n \n interface GAssembly\n procedure GAssembly1\n procedure GAssembly2\n procedure GAssembly3\n end interface\n \n contains\n\n !-------- Matrix inversion --------!\n function inv(A) result(Ainv)\n implicit none\n \n complex(dp),intent(in) :: A(:,:)\n complex(dp) :: Ainv(size(A,1),size(A,2))\n \n integer :: s(2), nrows, ncols\n integer :: lda, lwork, info\n \n integer :: ipiv(size(A,1))\n complex(dp) :: work(size(A,1))\n \n external zgetrf\n external zgetri\n \n s = shape(A)\n nrows = s(1)\n ncols = s(2)\n lda = max(1,nrows)\n lwork = max(1,nrows)\n \n \n Ainv = A\n call zgetrf(nrows,ncols,Ainv,lda,ipiv,info)\n \n if (info .ne. 0) then\n print *, \"Error in the LU factorization!\"\n end if\n \n call zgetri(nrows,Ainv,lda,ipiv,work,lwork,info)\n \n if (info .ne. 0) then\n print *,\"Error in the matrix inversion!\"\n end if\n\n end function\n\n !------- Solve Linear System -------!\n function solve(A,B) result(X)\n implicit none\n \n complex(dp),intent(in) :: A(:,:), B(:,:)\n complex(dp) :: X(size(B,1),size(B,2))\n complex(dp) :: Y(size(A,1),size(A,2))\n \n integer :: s(2), nra, nrb, nca, ncb\n integer :: lda, ldb, info\n \n integer :: ipiv(size(A,1))\n \n external zgesv\n \n s = shape(A)\n nra = s(1)\n nca = s(2)\n s = shape(B)\n nrb = s(1)\n ncb = s(2)\n lda = max(1,nra)\n ldb = max(1,nrb)\n \n \n X = B\n Y = A\n call zgesv(nra,ncb,Y,lda,ipiv,X,ldb,info)\n \n if (info .ne. 0) then\n print *,\"Error in the linear system solver!\"\n end if\n end function \n\n !---------------------------------------------------!\n ! Triple Matrix Product !\n ! !\n ! D = A.B.C !\n ! !\n ! A: Complex !\n ! B: Real !\n ! C: Complex !\n !---------------------------------------------------!\n function tri(A,B,C) result(D)\n implicit none\n \n complex(dp),intent(in) :: A(:,:)\n complex(dp),intent(in) :: B(:,:)\n complex(dp),intent(in) :: C(:,:)\n complex(dp) :: D(size(A,1),size(C,2))\n \n \n ! Hu & Shing matrix chain multiplication\n ! [m] ---B--- [k]\n ! | |\n ! A C\n ! | |\n ! [n]---ABC-- [l]\n \n integer :: n,m,k,l\n integer :: s(2)\n\n \n s = shape(A)\n n = s(1)\n m = s(2)\n s = shape(C)\n k = s(1)\n l = s(2)\n \n if (n*m*k + n*k*l < m*k*l + n*m*l) then\n D = matmul(matmul(A,B),C)\n else \n D = matmul(A,matmul(B,C))\n end if\n end function\n \n \n !---------------------------------------------------!\n ! For a diagonal matrix B: !\n ! C = B.A.B+ if invert = false !\n ! C = B+.A.B if invert = true !\n !---------------------------------------------------!\n function d2tri(A,B,invert) result(C)\n use omp_lib\n implicit none\n \n complex(dp),intent(in) :: A(:,:)\n complex(dp),intent(in) :: B(:,:)\n logical,intent(in) :: invert\n complex(dp) :: C(size(A,1),size(A,2))\n \n integer :: i,j\n complex(dp) :: p\n \n !$OMP PARALLEL DO\n do j = 1,size(B,1)\n p = B(j,j)\n if (invert .eqv. .false.) then\n p = conjg(p)\n end if\n do i = 1,size(A,1)\n C(i,j) = p*A(i,j)\n if (invert .eqv. .false.) then\n C(i,j) = C(i,j)*B(i,i)\n else\n C(i,j) = C(i,j)*conjg(B(i,i))\n end if\n end do\n end do\n !$OMP END PARALLEL DO\n end function \n\n !---------------------------------------------------!\n ! G = [(E+i.eta).I - H - S1 - S2]^(-1) !\n !---------------------------------------------------!\n function GAssembly3(E,H,S1,S2,eta) result(G)\n implicit none\n \n real,intent(in) :: E\n complex(dp),intent(in) :: H(:,:)\n complex(dp),intent(in) :: S1(:,:)\n complex(dp),intent(in) :: S2(:,:)\n real(dp),intent(in) :: eta\n complex(dp) :: G(size(H,1),size(H,2))\n \n integer :: i\n \n ! G = (E+i.eta).I - H - S1 - S2\n G = -(H + S1 + S2)\n do i = 1,size(H,2)\n G(i,i) = G(i,i) + E + cmplx(0,1)*eta\n end do\n \n G = inv(G)\n end function \n \n !---------------------------------------------------!\n ! G = [(E+i.eta).I - H - S]^(-1) !\n !---------------------------------------------------!\n function GAssembly2(E,H,S,eta) result(G)\n implicit none\n \n real,intent(in) :: E\n complex(dp),intent(in) :: H(:,:)\n complex(dp),intent(in) :: S(:,:)\n real(dp),intent(in) :: eta\n complex(dp) :: G(size(H,1),size(H,2))\n \n integer :: i\n \n ! G = (E+i.eta).I - H - S\n G = -(H + S) \n do i = 1,size(H,2)\n G(i,i) = G(i,i) + E + cmplx(0,1)*eta\n end do\n \n G = inv(G)\n end function \n \n !---------------------------------------------------!\n ! G = [(E+i.eta).I - H]^(-1) !\n !---------------------------------------------------!\n function GAssembly1(E,H,eta) result(G)\n implicit none\n \n real,intent(in) :: E\n complex(dp),intent(in) :: H(:,:)\n real(dp),intent(in) :: eta\n complex(dp) :: G(size(H,1),size(H,2))\n \n integer :: i\n \n ! G = (E+i.eta).I - H \n G = -H\n do i = 1,size(H,2)\n G(i,i) = G(i,i) + E + cmplx(0,1)*eta\n end do\n \n G = inv(G)\n end function \n \n \nend module\n", "meta": {"hexsha": "d7f5f6e3a6b431db59e57bc8c085c8c024d3b6ed", "size": 6894, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/source/linalg.f90", "max_stars_repo_name": "StxGuy/GreenCheetah", "max_stars_repo_head_hexsha": "c942d37629147a278686ca9c596a704a1492808b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fortran/source/linalg.f90", "max_issues_repo_name": "StxGuy/GreenCheetah", "max_issues_repo_head_hexsha": "c942d37629147a278686ca9c596a704a1492808b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran/source/linalg.f90", "max_forks_repo_name": "StxGuy/GreenCheetah", "max_forks_repo_head_hexsha": "c942d37629147a278686ca9c596a704a1492808b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2118644068, "max_line_length": 65, "alphanum_fraction": 0.3228894691, "num_tokens": 1723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7518728194119784}} {"text": "C polygraf.for:\nC\nC Graphs the polynomial (x-x0)(x-x1)...(x-xn) where xi are equally-spaced.\nC\nC link with FUNGRAF,COREGFX\nC\nC This is the well-known \"error polynomial:\" the error in interpolation\nC of a function by a polynomial of order n is bounded by a limit\nC proportional to this polynomial. The lessons to learn are: 1) see\nC how it takes off outside [-1,1] illustrating the hazard of using\nC polynomials for extrapolation, and 2) observe that within [-1,1] it\nC has smallest amplitude near x=0, in contrast to the Chebyshev polynomials\nC which are well-balanced over the whole interval [-1,1].\nC\nC NOTE: If your compiler does not accept identifiers over 6 chars\nC long, all such identifiers herein can be safely truncated to 6\nC characters by chopping off their ends.\nC\nC This program is associated with the CORE graphics package. See\nC the CORE documentation for explanation of the graphics routines.\nC\nC CORE Version 1.1\nC January, 1990\nC \nC Robert Moniot NOTE: This is free software. It may\nC Fordham University be freely copied so long as it is not\nC College at Lincoln Center being directly sold for profit. No\nC New York, NY 10023 guarantees accompany the software.\nC If you find bugs, please notify me,\nC MONIOT@FORDMULC.BITNET and I will try to fix them when I get\nC the chance. This does not apply to\nC problems which may arise in porting\nC the code to non-VMS systems.\n parameter (MAX=20)\n external poly,cheby\n real poly,cheby, x(0:MAX)\n common /polyn/ n\n character *4 namdev\n character choice\nC\nC pick up the standard logical unit numbers.\nC\n call inqgfu(igrafu)\n call inqeru(mesgu)\n call inqinu(inptu)\nC\nC Give instructions to user.\nC\n write(mesgu, *)\n $ 'This program will graph either the error polynomial'\n write(mesgu, *) 'or the Chebyshev polynomial. Which do you want?'\n write(mesgu, *) 'Enter E for error poly and C for Chebyshev'\n read(inptu,1000) choice\n1000 format(a1)\n if(choice .eq. 'e') choice = 'E'\n write(mesgu,*)\n if(choice .eq. 'E') then\n write(mesgu,*)\n $ 'Graph of the polynomial psi(x)=x(x-h)(x-2h)...(x-nh)'\n write(mesgu,*)\n $ 'where nh=1. The error in interpolation by a polynomial'\n write(mesgu,*)\n $ 'of order n is bounded by a term proportional to psi(x).'\n else\n write(mesgu,*)\n $'Graph of the Chebyshev polynomial. The family of Chebyshev'\n write(mesgu,*)\n $'polynomials is well suited to approximation of functions. The'\n write(mesgu,*)\n $'zeroes of a Chebyshev polynomial are not equally spaced, but'\n write(mesgu,*)\n $'chosen so that the polynomial oscillates between +1 and -1 on'\n write(mesgu,*)\n $'the interval [-1,1].'\n \n endif\n \n call grafinstrs\nC\nC Get device from user: graph can be made on various types.\nC\n call grafdev(namdev)\n call getspd(igrafu,ibaud)\nC\n \n1 continue\n write(mesgu, *) 'Enter order n (-1 to stop)'\n read(inptu,*) n\n if(n .lt. 0) stop\n if(n .gt. MAX) then\n write(mesgu, *) 'Enter n between 0 and',MAX\n goto 1\n endif\n \n if(n .ne. 0) then\n h = 2.0/n\n else\n h = 1.0\n endif\n \n do 10 i=0,n\n x(i) = -1.0 + i*h\n10 continue\n \n xmax = 1.0+h\n xmin = -1.0-h\n if(choice .eq. 'E') then\n ymax = abs(poly(1.0 - 0.5*h,x))*1.1\n else\n ymax = abs(cheby(1.0 + 0.1*h,x))*1.1\n endif\n if(n .eq. 0) ymax = ymax*1.5\n ymin = -ymax\nC\nC Draw the graph\nC\n call startgraf(xmin,xmax,ymin,ymax,namdev,ibaud)\n \n if(choice .eq. 'E') then\n call fungraf(poly,x,1)\n call legend('Error Polynomial')\n else\n call fungraf(cheby,x,1)\n call legend('Chebyshev Polynomial')\n endif\n \n call endgraf\n goto 1\n end\nC\nC Function to be graphed is defined here.\nC\n function poly(x,p)\n common /polyn/ n\n real p(1)\nC\n poly = 1.0\n do 10 i=0,n\n poly = poly * (x - p(i+1))\n10 continue\n return\n end\nC\nC Chebyshev polynomial computed here. Uses the recurrence formula:\nC\nC T (x) = 2*x*T (x) - T (x)\nC n+1 n n-1\nC\n function cheby(x,p)\n common /polyn/ n\n real p(1)\nC\n \n if(n .eq. 0) then\n cheby = 1.0\n return\n else\n t1 = 1.0\n cheby = x\n do 10 i=2,n\n t0 = t1\n t1 = cheby\n cheby = 2.0*x*t1 - t0\n10 continue\n endif\n return\n end\n \n \n \n", "meta": {"hexsha": "8d597bfefd0ac2d567b8215d729bb3bc365c909f", "size": 4794, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "test/polygraf.f", "max_stars_repo_name": "kurtsansom/ftnchek", "max_stars_repo_head_hexsha": "cb5b24689fec20e0dac4d158ae57a5b7387e9723", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/polygraf.f", "max_issues_repo_name": "kurtsansom/ftnchek", "max_issues_repo_head_hexsha": "cb5b24689fec20e0dac4d158ae57a5b7387e9723", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/polygraf.f", "max_forks_repo_name": "kurtsansom/ftnchek", "max_forks_repo_head_hexsha": "cb5b24689fec20e0dac4d158ae57a5b7387e9723", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0350877193, "max_line_length": 76, "alphanum_fraction": 0.5794743429, "num_tokens": 1450, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424217727027, "lm_q2_score": 0.8887588023318196, "lm_q1q2_score": 0.7518387736163863}} {"text": " subroutine resid_dph(ctfmp,n_K,n_alpha,n_beta,n_divbeta,n_phi,np1_\n &K,np1_alpha,np1_beta,np1_divbeta,np1_phi,x,Nx,ht,hx,myzero,zepsdis\n &,phys_bdy,res)\n implicit none\n integer i\n integer Nx\n real*8 ht\n real*8 hx\n real*8 myzero\n real*8 zepsdis\n real*8 ctfmp(Nx)\n real*8 n_K(Nx)\n real*8 n_alpha(Nx)\n real*8 n_beta(Nx)\n real*8 n_divbeta(Nx)\n real*8 n_phi(Nx)\n real*8 np1_K(Nx)\n real*8 np1_alpha(Nx)\n real*8 np1_beta(Nx)\n real*8 np1_divbeta(Nx)\n real*8 np1_phi(Nx)\n real*8 x(Nx)\n integer phys_bdy(2)\n real*8 res\n real*8 qb\n res = 0.0D0\n if (phys_bdy(1) .eq. 1) then\n do i=1, 1, 1\n qb = -0.5000000000000000D0 * (0.3D1 * np1_phi(i) - 0.4D1 * np1_phi\n #(i + 1) + np1_phi(i + 2)) / hx\n res = res + qb**2\n end do\n endif\n if (phys_bdy(1) .eq. 1) then\n do i=2, 2, 1\n qb = (-0.1D1 * n_phi(i) + np1_phi(i)) / ht + 0.2500000000000000D0 \n #/ ctfmp(i) * (np1_phi(i - 1) - 0.1D1 * np1_phi(i + 1)) / hx * np1_\n #beta(i) + 0.8333333333333333D-1 * np1_alpha(i) * np1_K(i) - 0.8333\n #333333333333D-1 * np1_divbeta(i) + 0.2500000000000000D0 / ctfmp(i)\n # * (n_phi(i - 1) - 0.1D1 * n_phi(i + 1)) / hx * n_beta(i) + 0.8333\n #333333333333D-1 * n_alpha(i) * n_K(i) - 0.8333333333333333D-1 * n_\n #divbeta(i) + 0.3125000000000000D-1 * zepsdis / ht * (0.7D1 * np1_p\n #hi(i) + np1_phi(i + 2) - 0.4D1 * np1_phi(i + 1) - 0.4D1 * np1_phi(\n #i - 1)) + 0.3125000000000000D-1 * zepsdis / ht * (0.7D1 * n_phi(i)\n # + n_phi(i + 2) - 0.4D1 * n_phi(i + 1) - 0.4D1 * n_phi(i - 1))\n res = res + qb**2\n end do\n endif\n do i=3, Nx-2, 1\n qb = (-0.1D1 * n_phi(i) + np1_phi(i)) / ht + 0.2500000000000000D0 \n #/ ctfmp(i) * (np1_phi(i - 1) - 0.1D1 * np1_phi(i + 1)) / hx * np1_\n #beta(i) + 0.8333333333333333D-1 * np1_alpha(i) * np1_K(i) - 0.8333\n #333333333333D-1 * np1_divbeta(i) + 0.2500000000000000D0 / ctfmp(i)\n # * (n_phi(i - 1) - 0.1D1 * n_phi(i + 1)) / hx * n_beta(i) + 0.8333\n #333333333333D-1 * n_alpha(i) * n_K(i) - 0.8333333333333333D-1 * n_\n #divbeta(i) + 0.3125000000000000D-1 * zepsdis / ht * (0.6D1 * np1_p\n #hi(i) + np1_phi(i + 2) + np1_phi(i - 2) - 0.4D1 * np1_phi(i + 1) -\n # 0.4D1 * np1_phi(i - 1)) + 0.3125000000000000D-1 * zepsdis / ht * \n #(0.6D1 * n_phi(i) + n_phi(i + 2) + n_phi(i - 2) - 0.4D1 * n_phi(i \n #+ 1) - 0.4D1 * n_phi(i - 1))\n res = res + qb**2\n end do\n do i=Nx-1, Nx-1, 1\n qb = (-0.1D1 * n_phi(i) + np1_phi(i)) / ht + 0.2500000000000000D0 \n #/ ctfmp(i) * (np1_phi(i - 1) - 0.1D1 * np1_phi(i + 1)) / hx * np1_\n #beta(i) + 0.8333333333333333D-1 * np1_alpha(i) * np1_K(i) - 0.8333\n #333333333333D-1 * np1_divbeta(i) + 0.2500000000000000D0 / ctfmp(i)\n # * (n_phi(i - 1) - 0.1D1 * n_phi(i + 1)) / hx * n_beta(i) + 0.8333\n #333333333333D-1 * n_alpha(i) * n_K(i) - 0.8333333333333333D-1 * n_\n #divbeta(i)\n res = res + qb**2\n end do\n if (phys_bdy(2) .eq. 1) then\n do i=Nx, Nx, 1\n qb = (-0.1D1 * n_phi(i) + np1_phi(i)) / ht - 0.1D1 * myzero * x(i)\n res = res + qb**2\n end do\n endif\n res = sqrt(res/(1*Nx))\n END\n", "meta": {"hexsha": "a3b8ee8465b219915b840fec7f837b3a92014f63", "size": 3262, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/resid_dph.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/resid_dph.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/resid_dph.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.2716049383, "max_line_length": 72, "alphanum_fraction": 0.5355610055, "num_tokens": 1540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.957277806109987, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7517584802415587}} {"text": "!! implements calculation:\n!! $$ \\pi = \\int^1_{-1} \\frac{dx}{\\sqrt{1-x^2}}\n\nuse, intrinsic:: iso_fortran_env, only: dp=>real64, int64, stderr=>error_unit\nimplicit none\n\ninteger, parameter :: wp = dp\nreal(wp), parameter :: x0 = -1.0_wp, x1 = 1.0_wp\nreal(wp), parameter :: pi = 4._wp*atan(1.0_wp)\nreal(wp) :: psum[*] ! this is a scalar coarray\ninteger(int64) :: rate,tic,toc\nreal(wp) :: f,x,telaps, dx\ninteger :: i, stat, im, Ni\ncharacter(16) :: cbuf\n\npsum = 0._wp\n\nif (command_argument_count() > 0) then\n call get_command_argument(1, cbuf)\n read(cbuf,*, iostat=stat) dx\n if (stat/=0) error stop 'must input real number for resolution e.g. 1e-6'\nelse\n dx = 1e-6\nendif\n\nNi = int((x1-x0) / dx) ! (1 - (-1)) / interval\nim = this_image()\n\n!---------------------------------\nif (im == 1) then\n call system_clock(tic)\n print '(A,I3)', 'number of Fortran coarray images:', num_images()\n print *,'approximating pi in ',Ni,' steps.'\nend if\n!---------------------------------\n\ndo i = im, Ni-1, num_images() ! Each image works on a subset of the problem\n x = x0 + i*dx\n f = dx / sqrt(1.0_wp - x**2)\n psum = psum + f\n! print *,x,f,psum\nend do\n\n! --- co_sum is much simpler, but not working on ifort 2017 yet\n! ---- alternative to Fortran 2018 co_sum for Fortran 2008\nsync all\nif (im==1) then\n do i = 2, num_images()\n psum = psum + psum[i]\n enddo\nendif\n\nif (im == 1) then\n print *,'pi:',pi,' iterated pi: ',psum\n print '(A,E10.3)', 'pi error',pi - psum\nendif\n\nif (im == 1) then\n call system_clock(toc)\n call system_clock(count_rate=rate)\n telaps = real((toc - tic),wp) / rate\n print '(A,E10.3,A,I3,A)', 'Elapsed wall clock time ', telaps, ' seconds, using',num_images(),' images.'\nend if\n\nend program", "meta": {"hexsha": "4a36255c78bbb545c80276240d2c4930ebcc6390", "size": 1740, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "coarray/pi2008.f90", "max_stars_repo_name": "plasmasimulation/fortran2018-examples", "max_stars_repo_head_hexsha": "0a7d336e0fc8508b2d6c0e30eff0c3325c57f735", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-04-28T02:10:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-28T02:10:26.000Z", "max_issues_repo_path": "coarray/pi2008.f90", "max_issues_repo_name": "plasmasimulation/fortran2018-examples", "max_issues_repo_head_hexsha": "0a7d336e0fc8508b2d6c0e30eff0c3325c57f735", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "coarray/pi2008.f90", "max_forks_repo_name": "plasmasimulation/fortran2018-examples", "max_forks_repo_head_hexsha": "0a7d336e0fc8508b2d6c0e30eff0c3325c57f735", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.7692307692, "max_line_length": 107, "alphanum_fraction": 0.6034482759, "num_tokens": 603, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.8670357735451834, "lm_q1q2_score": 0.7517510206914109}} {"text": "! Program to perform a random walk in 2 dimensions\n! with equal probability for moves to the letf, right, up and down\n! Only one walker present\n\nPROGRAM random_walk_2dim\n USE constants\n USE f90library\n IMPLICIT NONE\n INTEGER:: max_trials, number_walks\n REAL(dp):: move_probability\n INTEGER, ALLOCATABLE, DIMENSION(:) :: x_cum, x2_cum, y_cum, y2_cum\n\n ! get max trials, number of walks and the probability to move\n CALL initialise(max_trials, number_walks, move_probability) \n ! allocate memory\n ALLOCATE (x_cum(number_walks), x2_cum(number_walks), &\n y_cum(number_walks), y2_cum(number_walks))\n x_cum = 0; y_cum = 0; x2_cum = 0; y2_cum = 0 \n ! do the Monte Carlo move\n CALL mc_sampling(max_trials, number_walks, move_probability, &\n x_cum, x2_cum, y_cum, y2_cum)\n ! Print out results \n CALL output(max_trials, number_walks, x_cum, x2_cum, y_cum, y2_cum) \n ! free memory\n DEALLOCATE(x_cum, x2_cum, y_cum, y2_cum) \nEND PROGRAM random_walk_2dim\n\n! Read in data from screen\n\nSUBROUTINE initialise(max_trials, number_walks, move_probability) \n USE constants\n IMPLICIT NONE\n INTEGER, INTENT(inout) ::max_trials, number_walks\n REAL(DP) :: move_probability\n WRITE(*,*)'Number of Monte Carlo trials =' \n READ(*,*) max_trials\n WRITE(*,*) 'Number of attempted walks='\n READ(*,*) number_walks\n WRITE(*,*) 'Move probability='\n READ(*,*) move_probability\nEND SUBROUTINE initialise\n\n! Output of expectation values, , and their variances\n! - ^2 and - ^2\n\nSUBROUTINE output(max_trials, number_walks, x_cum, x2_cum, y_cum, y2_cum)\n USE constants\n IMPLICIT NONE\n INTEGER :: i\n INTEGER, INTENT(in) :: max_trials, number_walks\n INTEGER, INTENT(in) :: x_cum(number_walks), x2_cum(number_walks), &\n y_cum(number_walks), y2_cum(number_walks)\n REAL(dp) :: xaverage, yaverage , x2average, y2average, total_average, &\n total_variance, yvariance, xvariance\n\n OPEN(UNIT=6, FILE='out.dat')\n DO i =1, number_walks \n xaverage = x_cum(i)/FLOAT(max_trials)\n x2average = x2_cum(i)/FLOAT(max_trials)\n xvariance = x2average - xaverage*xaverage\n yaverage = y_cum(i)/FLOAT(max_trials)\n y2average = y2_cum(i)/FLOAT(max_trials)\n yvariance = y2average - yaverage*yaverage\n total_average = xaverage+yaverage\n total_variance = xvariance+yvariance\n WRITE(6,'(I3,2X,6F12.6)') i, xaverage, yaverage ,xvariance, yvariance, &\n total_average, total_variance\n ENDDO\nEND SUBROUTINE output\n\n! Here we perform the Monte Carlo samplings and moves in 2 dim\n\nSUBROUTINE mc_sampling(max_trials,number_walks, move_probability, x_cum, &\n x2_cum, y_cum, y2_cum)\n USE constants\n USE f90library\n IMPLICIT NONE\n INTEGER, INTENT(in) :: max_trials,number_walks\n INTEGER, INTENT(inout) :: x_cum(number_walks), x2_cum(number_walks), &\n y_cum(number_walks), y2_cum(number_walks)\n INTEGER :: idum, x, y, trial, walks\n REAL(dp) :: rantest\n REAL(dp), INTENT(in) :: move_probability\n idum=-1 \n ! loop over Monte Carlo trials\n DO trial = 1, max_trials\n x = 0; y = 0\n ! loop over attempted walks in 2 dimensions\n DO walks = 1, number_walks\n ! note code taylored to equal probability for up, down, left and right\n rantest = ran0(idum)\n IF (rantest <= move_probability) THEN\n x = x+1\n ELSEIF(rantest <= 2*move_probability)THEN\n x = x-1\n ELSEIF(rantest <= 3*move_probability)THEN\n y = y+1\n ELSE\n y = y-1\n ENDIF\n x_cum(walks) = x_cum(walks)+x\n x2_cum(walks) = x2_cum(walks)+x*x\n y_cum(walks) = y_cum(walks)+y\n y2_cum(walks) = y2_cum(walks)+y*y\n ENDDO\n ENDDO\nEND SUBROUTINE mc_sampling\n\n\n", "meta": {"hexsha": "ba1c8c36f2c9126809520a2bcc8b8cb002c75e42", "size": 3706, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/Programs/LecturePrograms/programs/RandomWalks/Fortran/program2.f90", "max_stars_repo_name": "kimrojas/ComputationalPhysicsMSU", "max_stars_repo_head_hexsha": "a47cfc18b3ad6adb23045b3f49fab18c0333f556", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 220, "max_stars_repo_stars_event_min_datetime": "2016-08-25T09:18:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T14:09:16.000Z", "max_issues_repo_path": "doc/Programs/LecturePrograms/programs/RandomWalks/Fortran/program2.f90", "max_issues_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_issues_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-01-18T10:43:38.000Z", "max_issues_repo_issues_event_max_datetime": "2020-02-08T13:15:42.000Z", "max_forks_repo_path": "doc/Programs/LecturePrograms/programs/RandomWalks/Fortran/program2.f90", "max_forks_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_forks_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 136, "max_forks_repo_forks_event_min_datetime": "2016-08-25T09:04:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T09:54:21.000Z", "avg_line_length": 33.6909090909, "max_line_length": 79, "alphanum_fraction": 0.6875337291, "num_tokens": 1168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.8633916152464017, "lm_q1q2_score": 0.7516663818002}} {"text": "program matrice_grad\r\n\r\n! compilation et lien: gfortran.exe -O matrice_grad.f90 -o matrice_grad.exe\r\n\r\n! deux exemples d'allocation de memoire\r\n\r\n! 1. programmation avec memoire statique\r\n\r\n! parameter(N=100) ! matrice NxN\r\n! real x(N),xx(N),a(N,N),b(N)\r\n! real gk(N),agk(N),dk(N),adk(N)\r\n! real solg(N),solgc(N)\r\n\r\n! 2. allocation dynamique de la memoire pour remplacer \r\n! l'allocation statique \r\n\r\nreal, allocatable, dimension(:):: x,xx,b\r\nreal, allocatable, dimension(:,:):: a\r\nreal, allocatable, dimension(:):: gk,agk,dk,adk\r\nreal, allocatable, dimension(:):: solg,solgc\r\n\r\nprint *,'Taille matrice ?'\r\nread(5,*) N\r\n\r\nallocate(x(N))\r\nallocate(xx(N))\r\nallocate(b(N))\r\nallocate(a(N,N))\r\nallocate(gk(N))\r\nallocate(agk(N))\r\nallocate(dk(N))\r\nallocate(adk(N))\r\nallocate(solg(N))\r\nallocate(solgc(N))\r\n\r\n\r\n\r\nigc=1 ! gradient ou gradient conjugue\r\nnbgrad=30 ! nbre iterations gradient\r\n\r\nb(1:N)=0\r\n\r\nopen(1,file='matrix.dat',status='unknown')\r\ndo i=1,N\r\n x(i)=i\r\n do j=1,N\r\n a(i,j)=exp(-0.05*(i-j)**2)\r\n\t\twrite(1,*) i,j,a(i,j)\r\n enddo\r\n\t write(1,'()')\r\nenddo\r\nclose(1)\r\n\r\n! visualisation de matrix.dat avec gnuplot\r\n! splot 'matrix.dat' w l \r\n\r\nb=matmul(a,x) !cible\r\n\r\n!\r\n!inversion par minimisation d'energie\r\n! methode de gradient a x = b , il faut retrouver x\r\n!\r\n! initialisaiton\r\n\r\nxx(1:N)=0\r\n\r\n!if(igc.eq.0) then\r\n\r\ndo 1 iter=1,nbgrad\r\n\r\n!gk=matmul(a,xx)-b \r\n \r\ndo i=1,N\r\n gk(i)=0\r\n do j=1,N\r\n gk(i)=gk(i)+a(i,j)*xx(j)\r\n enddo\r\n gk(i)=gk(i)-b(i)\r\nenddo\r\n\r\n!agk=matmul(a,gk)\r\n\r\ndo i=1,N\r\n agk(i)=0\r\n do j=1,N\r\n agk(i)=agk(i)+a(i,j)*gk(j)\r\n enddo\r\nenddo\r\n\r\n\r\n!gkgk=dot_product(gk,gk)\r\n!agkgk=dot_product(agk,gk)\r\n\r\ngkgk=0\r\nagkgk=0\r\ndo i=1,N\r\n gkgk=gkgk+gk(i)**2\r\n agkgk=agkgk+agk(i)*gk(i)\r\nenddo\r\n\r\nalphak=gkgk/agkgk\r\n\r\n! xx(1:N)=xx(1:N)-alphak*gk(1:N)\r\n\r\n do i=1,N\r\n xx(i)=xx(i)-alphak*gk(i)\r\n enddo\r\n\r\n\tprint *,iter,gkgk\r\n\t\r\n1 continue !nbgrad\r\n\r\nsolg(1:N)=xx(1:N)\r\n\r\n\r\n!endif ! igc=0\r\n\r\n\r\n!if(igc.eq.1) then ! gradient conjugue\r\n\r\nxx(1:N)=0\r\ngk=matmul(a,xx)-b\r\ndk(1:N)=gk(1:N) \r\n\r\ndo 2 iter=1,nbgrad\r\n \r\nadk=matmul(a,dk)\r\ngkgk=dot_product(gk,gk)\r\nadkdk=dot_product(adk,dk)\r\nalphak=gkgk/adkdk\r\nxx(1:N)=xx(1:N)-alphak*dk(1:N)\r\ngk(1:N)=gk(1:N)-alphak*adk(1:N) \r\ngk1gk1=dot_product(gk,gk) \r\nbetak1=gk1gk1/gkgk\r\ndk(1:N)=gk(1:N)+betak1*dk(1:N)\r\n\r\n\tprint *,iter,gkgk\r\n\r\n2 continue\r\n\r\nsolgc(1:N)=xx(1:N)\r\n \r\n!endif !igc=1\r\n\r\n \r\n\tdo i=1,N\r\n\t print *,x(i),solg(i),solgc(i)\r\n\tenddo\r\n\t\r\n\t\r\n! visu gnuplot : plot 'sol_ggc.dat' w l,'sol_ggc.dat' u 1:3 w l,'sol_ggc.dat' u 1:4 w l\r\n\r\n\topen(1,file='sol_ggc.dat',status='unknown')\r\n\t do i=1,N\r\n\t write(1,*) i,x(i),solg(i),solgc(i)\r\n\t enddo\r\n\t close(1)\r\n\r\n\r\ndeallocate(x)\r\ndeallocate(xx)\r\ndeallocate(b)\r\ndeallocate(a)\r\ndeallocate(gk)\r\ndeallocate(agk)\r\ndeallocate(dk)\r\ndeallocate(adk)\r\ndeallocate(solg)\r\ndeallocate(solgc)\r\n\r\n\r\nprint *,'fin normal' \r\n \t\r\nend\r\n", "meta": {"hexsha": "41474bd2fe96b22172661fb4a3bf7dda9cd9bd5f", "size": 2911, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "matrice_grad/old sources/matrice_grad.f90", "max_stars_repo_name": "christof337/ACSEL", "max_stars_repo_head_hexsha": "67c5e164e943c55ba1b04e4f455ce376f049fb84", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-10-09T20:01:20.000Z", "max_stars_repo_stars_event_max_datetime": "2017-10-09T20:01:20.000Z", "max_issues_repo_path": "matrice_grad/old sources/matrice_grad.f90", "max_issues_repo_name": "christof337/ACSEL", "max_issues_repo_head_hexsha": "67c5e164e943c55ba1b04e4f455ce376f049fb84", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-10-10T14:45:33.000Z", "max_issues_repo_issues_event_max_datetime": "2017-11-30T13:26:03.000Z", "max_forks_repo_path": "matrice_grad/old sources/matrice_grad.f90", "max_forks_repo_name": "christof337/ACSEL", "max_forks_repo_head_hexsha": "67c5e164e943c55ba1b04e4f455ce376f049fb84", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.6342857143, "max_line_length": 89, "alphanum_fraction": 0.5946410168, "num_tokens": 1122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541577509316, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.751615900180631}} {"text": "subroutine flaplace(u, t, n, m, it)\n! Solve Laplace's equation on a rectangular domain\n! with values at an equispaced grid of points.\n! Use the boundaries of the array u as the boundary conditions\n! Perform 'it' number of iterations on the values in u.\n! In each iteration set each value to the\n! average of its four neighbors\n implicit none\n integer, intent(in) :: n, m, it\n! Columns are listed first in in array shapes in Fortran.\n double precision, dimension(n, m), intent(inout) :: u\n! t is a preallocated temporary array.\n double precision, dimension(n-2, m-2), intent(inout) :: t\n integer i\n do i = 1, it\n! & is the line continuation character in Fortran.\n! Fortran supports array slice notation.\n! Indices for arrays start at 1.\n! The ranges indicated in the slices include the end points\n! of the range.\n! Column indices come before row indices.\n t = .25 * (u(1:n-2,2:m-1) +&\n u(3:n,2:m-1) + u(2:n-1,1:m-2) + u(2:n-1,3:m))\n u(2:n-1,2:m-1) = t\n enddo\nend subroutine flaplace\n", "meta": {"hexsha": "420f253efbb7b89a42df28194f9f710fedfe7365", "size": 1080, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Python/f2py/flaplace/flaplace.f90", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Python/f2py/flaplace/flaplace.f90", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Python/f2py/flaplace/flaplace.f90", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 40.0, "max_line_length": 65, "alphanum_fraction": 0.6453703704, "num_tokens": 317, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541528387691, "lm_q2_score": 0.7981867681382279, "lm_q1q2_score": 0.751615884958318}} {"text": "!***********************************************************************\n! *\n SUBROUTINE ES(F, S2F, S3F)\n! *\n! Evaluate the sum of the series *\n! *\n! infinity n k *\n! S (F) = Sum (-1) exp (n*F) / n *\n! k n = 0 *\n! *\n! for k = 2, 3 to machine precision. This is a utility subroutine, *\n! called by SUBROUTINEs NUCPOT and NCHARG. *\n! *\n! Written by Farid A Parpia, at Oxford Last revision: 28 Sep 1992 *\n! *\n!***********************************************************************\n!...Translated by Pacific-Sierra Research 77to90 4.3E 10:47:25 2/14/04\n!...Modified by Charlotte Froese Fischer\n! Gediminas Gaigalas 10/05/17\n!-----------------------------------------------\n! M o d u l e s\n!-----------------------------------------------\n USE vast_kind_param, ONLY: DOUBLE\n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n REAL(DOUBLE), INTENT(IN) :: F\n REAL(DOUBLE), INTENT(OUT) :: S2F\n REAL(DOUBLE), INTENT(OUT) :: S3F\n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n INTEGER :: N\n REAL(DOUBLE) :: FASE, EN, OBN, ENF, TERM2, TERM3, S2LAST\n!-----------------------------------------------\n!\n N = 0\n S2F = 0.0D00\n S3F = 0.0D00\n FASE = 1.0D00\n N = N + 1\n EN = DBLE(N)\n OBN = 1.0D00/EN\n FASE = -FASE\n ENF = EXP(EN*F)\n TERM2 = FASE*ENF*OBN*OBN\n TERM3 = TERM2*OBN\n S2LAST = S2F\n S2F = S2F + TERM2\n S3F = S3F + TERM3\n DO WHILE(ABS(S2F) /= ABS(S2LAST))\n N = N + 1\n EN = DBLE(N)\n OBN = 1.0D00/EN\n FASE = -FASE\n ENF = EXP(EN*F)\n TERM2 = FASE*ENF*OBN*OBN\n TERM3 = TERM2*OBN\n S2LAST = S2F\n S2F = S2F + TERM2\n S3F = S3F + TERM3\n END DO\n!\n RETURN\n END SUBROUTINE ES\n", "meta": {"hexsha": "48d854ec78386a775146f1a8f54b2c005f429544", "size": 2615, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/lib9290/es.f90", "max_stars_repo_name": "sylas/grasp-continuum", "max_stars_repo_head_hexsha": "f5e2fb18bb2bca4f715072190bf455fba889320f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 33, "max_stars_repo_stars_event_min_datetime": "2019-03-10T04:00:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T22:01:15.000Z", "max_issues_repo_path": "src/lib/lib9290/es.f90", "max_issues_repo_name": "sylas/grasp-continuum", "max_issues_repo_head_hexsha": "f5e2fb18bb2bca4f715072190bf455fba889320f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 65, "max_issues_repo_issues_event_min_datetime": "2019-03-07T17:56:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-16T16:45:24.000Z", "max_forks_repo_path": "src/lib/lib9290/es.f90", "max_forks_repo_name": "sylas/grasp-continuum", "max_forks_repo_head_hexsha": "f5e2fb18bb2bca4f715072190bf455fba889320f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2019-03-10T04:00:43.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T02:06:40.000Z", "avg_line_length": 39.0298507463, "max_line_length": 74, "alphanum_fraction": 0.2929254302, "num_tokens": 662, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7515926746453299}} {"text": "function bvalu(t, coef, nctl, K, ideriv, s)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract bvalu is the generic 1D spline interpolant\n ! function. It is similar to the function of the same\n ! name from the tensbs library without the work arrays\n !\n ! Description of Arguments\n ! Input\n ! t - Real, Knot vector. Length nctl+k\n ! coef - Real, Array of b-sline coefficients Size (nctl)\n ! nctl - Integer, Number of control points\n ! k - Integer, order of B-spline \n ! ideriv - Integer, degree of derivatve to evaluate\n ! s - Real, Position to evaluate \n !\n ! Ouput bvalu - Real, Evaluated point or derivative\n\n use precision\n implicit none\n\n ! Input\n integer , intent(in) :: k, nctl, ideriv\n real(kind=realType), intent(in) :: s\n real(kind=realType), intent(in) :: t(nctl+k)\n real(kind=realType), intent(in) :: coef(nctl)\n\n ! Output\n real(kind=realType) :: bvalu\n\n ! Working\n integer :: l, istart, ileft\n real(kind=realType) :: B(k), Bd(ideriv+1,k)\n\n bvalu = 0.0\n\n ! Find knot span\n call findSpan(s, k, t, nctl, ileft)\n istart = ileft-k\n if (ideriv ==0) then ! Use basis function\n call basis(t, nctl, k, s, ileft, B)\n do l=1, k\n bvalu = bvalu + B(l)*coef(istart+l)\n end do\n else\n ! Evalute derivative basis functions up to depree specified by\n ! ideriv\n call derivBasis(t, nctl, k, s, ileft, ideriv, Bd)\n do l=1, k\n bvalu = bvalu + Bd(ideriv+1,l)*coef(istart+l)\n end do\n end if\nend function bvalu\n\nfunction b2val(u, v, idu, idv, tu, tv, nctlu, nctlv, ku, kv, coef)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract bvalu is the generic 2D spline interpolant\n ! function. It is similar to the function of the same\n ! name from the tensbs library without the work array\n !\n ! Description of Arguments\n ! Input\n ! u - Real, parametric position 1\n ! v - Real, parametric position 2\n ! idu - Integer, derivative in u to evaluate\n ! idv - Integer, derivative in v to evaluate\n ! tu - Real, U Knot vector. Length nctlu+ku\n ! tv - Real, V Knot vector. Length nctlv+kv\n ! Nctlu - Integer, Number of u control points\n ! Nctlv - Integer, Number of v control points\n ! ku - Integer, order of spline in u direction\n ! kv - Integer, order of spline in v direction\n ! coef - Real, Array size Nctlu x Nctlv, B-spline coefficients\n !\n ! Ouput \n ! b2val - Real, Evaluated point or derivative\n\n use precision\n implicit none\n\n ! Input\n integer , intent(in) :: ku, kv, nctlu, nctlv, idu, idv\n real(kind=realType), intent(in) :: u,v, tu(nctlu+ku), tv(nctlv+kv)\n real(kind=realType), intent(in) :: coef(nctlu,nctlv)\n\n ! Output\n real(kind=realType) :: b2val\n\n ! Working\n integer :: i, j\n integer :: ileftu, ileftv, istartu, istartv\n real(kind=realType) :: Bu(ku), Bv(kv)\n real(kind=realType) :: Bud(idu+1, ku), Bvd(idv+1, kv)\n\n ! Find knot spans\n call findSpan(u, ku, tu, nctlu, ileftu)\n istartu = ileftu-ku\n\n call findSpan(v, kv, tv, nctlv, ileftv)\n istartv = ileftv-kv\n\n b2val = 0.0\n\n ! Check if we can just use regular basis functions:\n if (idu + idv == 0) then\n call basis(tu, nctlu, ku, u, ileftu, Bu)\n call basis(tv, nctlv, kv, v, ileftv, Bv)\n\n do i=1, ku\n do j=1, kv\n b2val = b2val + Bu(i)*Bv(j)*coef(istartu+i, istartv+j)\n end do\n end do\n else\n ! We need derivative basis functions\n call derivBasis(tu, nctlu, ku, u, ileftu, idu, Bud)\n call derivBasis(tv, nctlv, kv, v, ileftv, idv, Bvd)\n\n do i=1, ku\n do j=1, kv\n b2val = b2val + Bud(idu+1,i)*Bvd(idv+1,j)*coef(istartu+i, istartv+j)\n end do\n end do\n end if\n\nend function b2val\n\nfunction b3val(u, v, w, idu, idv, idw, tu, tv, tw, nctlu, nctlv, nctlw, &\n ku, kv, kw, coef)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract bvalu is the generic 2D spline interpolant\n ! function. It is similar to the function of the same\n ! name from the tensbs library without the work array\n !\n ! Description of Arguments\n ! Input\n ! u - Real, parametric position 1\n ! v - Real, parametric position 2\n ! w - Real, parametric position 3\n ! idu - Integer, derivative in u to evaluate\n ! idv - Integer, derivative in v to evaluate\n ! idw - Integer, derivative in w to evaluate\n ! tu - Real, U Knot vector. Length nctlu+ku\n ! tv - Real, V Knot vector. Length nctlv+kv\n ! tv - Real, W Knot vector. Length nctlw+kw\n ! Nctlu - Integer, Number of u control points\n ! Nctlv - Integer, Number of v control points\n ! Nctlw - Integer, Number of w control points\n ! ku - Integer, order of spline in u direction\n ! kv - Integer, order of spline in v direction\n ! kw - Integer, order of spline in w direction\n ! coef - Real, Array size Nctlu x Nctlv x Nctlw, B-spline coefficients\n !\n ! Ouput \n ! b3val - Real, Evaluated point or derivative\n\n use precision\n implicit none\n\n ! Input\n integer , intent(in) :: ku, kv, kw, nctlu, nctlv, nctlw\n integer , intent(in) :: idu, idv, idw\n real(kind=realType), intent(in) :: u, v, w\n real(kind=realType), intent(in) :: tu(nctlu+ku), tv(nctlv+kv), tw(nctlw+kw)\n real(kind=realType), intent(in) :: coef(nctlu,nctlv,nctlw)\n\n ! Output\n real(kind=realType) :: b3val\n\n ! Working\n integer :: i, j, k\n integer :: ileftu, ileftv, ileftw\n integer :: istartu, istartv, istartw\n real(kind=realType) :: Bu(ku), Bv(kv), Bw(kw)\n real(kind=realType) :: Bud(idu+1, ku)\n real(kind=realType) :: Bvd(idv+1, kv)\n real(kind=realType) :: Bwd(idw+1, kw)\n\n ! Find knot spans\n call findSpan(u, ku, tu, nctlu, ileftu)\n istartu = ileftu-ku\n\n call findSpan(v, kv, tv, nctlv, ileftv)\n istartv = ileftv-kv\n\n call findSpan(w, kw, tw, nctlw, ileftw)\n istartw = ileftw-kw\n\n b3val = 0.0\n\n ! Check if we can just use regular basis functions:\n if (idu + idv + idw == 0) then\n call basis(tu, nctlu, ku, u, ileftu, Bu)\n call basis(tv, nctlv, kv, v, ileftv, Bv)\n call basis(tw, nctlw, kw, w, ileftw, Bw)\n\n do i=1, ku\n do j=1, kv\n do k=1, kw\n b3val = b3val + Bu(i)*Bv(j)*Bw(k)*&\n coef(istartu+i, istartv+j, istartw+k)\n end do\n end do\n end do\n else\n ! We need derivative basis functions\n call derivBasis(tu, nctlu, ku, u, ileftu, idu, Bud)\n call derivBasis(tv, nctlv, kv, v, ileftv, idv, Bvd)\n call derivBasis(tw, nctlw, kw, w, ileftw, idw, Bwd)\n\n do i=1, ku\n do j=1, kv\n do k=1, kw\n b3val = b3val + Bud(idu+1, i)*Bvd(idv+1, j)*Bwd(idw+1, k) * &\n coef(istartu+i, istartv+j, istartw+k)\n end do\n end do\n end do\n end if\n\nend function b3val\n\n! Also define complex versions --- these are only here for\n! TACS. pySpline doesn't need them\n\nfunction cbvalu(t, coef, nctl, K, ideriv, s)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract bvalu is the generic 1D spline interpolant\n ! function. It is similar to the function of the same\n ! name from the tensbs library without the work arrays\n !\n ! Description of Arguments\n ! Input\n ! t - Real, Knot vector. Length nctl+k\n ! coef - Complex, Array of b-sline coefficients Size (nctl)\n ! nctl - Integer, Number of control points\n ! k - Integer, order of B-spline \n ! ideriv - Integer, degree of derivatve to evaluate\n ! s - Real, Position to evaluate \n !\n ! Ouput bvalu - Complex, Evaluated point or derivative\n\n use precision\n implicit none\n\n ! Input\n integer , intent(in) :: k, nctl, ideriv\n real(kind=realType), intent(in) :: s\n real(kind=realType), intent(in) :: t(nctl+k)\n complex(kind=realType), intent(in) :: coef(nctl)\n\n ! Output\n complex(kind=realType) :: cbvalu\n\n ! Working\n integer :: l, istart, ileft\n real(kind=realType) :: B(k), Bd(k,k)\n\n cbvalu = cmplx(0.0, 0.0)\n\n ! Find knot span\n call findSpan(s, k, t, nctl, ileft)\n istart = ileft-k\n if (ideriv ==0) then ! Use basis function\n call basis(t, nctl, k, s, ileft, B)\n do l=1, k\n cbvalu = cbvalu + B(l)*coef(istart+l)\n end do\n else\n ! Evalute derivative basis functions up to depree specified by\n ! ideriv\n call derivBasis(t, nctl, k, s, ileft, ideriv, Bd)\n do l=1, k\n cbvalu = cbvalu + Bd(ideriv+1,l)*coef(istart+l)\n end do\n end if\nend function cbvalu\n\nfunction cb2val(u, v, idu, idv, tu, tv, nctlu, nctlv, ku, kv, coef)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract bvalu is the generic 2D spline interpolant\n ! function. It is similar to the function of the same\n ! name from the tensbs library without the work array\n !\n ! Description of Arguments\n ! Input\n ! u - Real, parametric position 1\n ! v - Real, parametric position 2\n ! idu - Integer, derivative in u to evaluate\n ! idv - Integer, derivative in v to evaluate\n ! tu - Real, U Knot vector. Length nctlu+ku\n ! tv - Real, V Knot vector. Length nctlv+kv\n ! Nctlu - Integer, Number of u control points\n ! Nctlv - Integer, Number of v control points\n ! ku - Integer, order of spline in u direction\n ! kv - Integer, order of spline in v direction\n ! coef - Complex, Array size Nctlu x Nctlv, B-spline coefficients\n !\n ! Ouput \n ! b2val - Complex, Evaluated point or derivative\n\n use precision\n implicit none\n\n ! Input\n integer , intent(in) :: ku, kv, nctlu, nctlv, idu, idv\n real(kind=realType), intent(in) :: u,v, tu(nctlu+ku), tv(nctlv+kv)\n complex(kind=realType), intent(in) :: coef(nctlu,nctlv)\n\n ! Output\n complex(kind=realType) :: cb2val\n\n ! Working\n integer :: i, j\n integer :: ileftu, ileftv, istartu, istartv\n real(kind=realType) :: Bu(ku), Bv(kv)\n real(kind=realType) :: Bud(ku, ku), Bvd(kv, kv)\n\n ! Find knot spans\n call findSpan(u, ku, tu, nctlu, ileftu)\n istartu = ileftu-ku\n\n call findSpan(v, kv, tv, nctlv, ileftv)\n istartv = ileftv-kv\n\n cb2val = cmplx(0.0, 0.0)\n\n ! Check if we can just use regular basis functions:\n if (idu + idv == 0) then\n call basis(tu, nctlu, ku, u, ileftu, Bu)\n call basis(tv, nctlv, kv, v, ileftv, Bv)\n\n do i=1, ku\n do j=1, kv\n cb2val = cb2val + Bu(i)*Bv(j)*coef(istartu+i, istartv+j)\n end do\n end do\n else\n ! We need derivative basis functions\n call derivBasis(tu, nctlu, ku, u, ileftu, idu, Bu)\n call derivBasis(tv, nctlv, kv, v, ileftv, idv, BV)\n\n do i=1, ku\n do j=1, kv\n cb2val = cb2val + Bud(idu+1,i)*Bvd(idv+1,j)*coef(istartu+i, istartv+j)\n end do\n end do\n end if\n\nend function cb2val\n\nfunction cb3val(u, v, w, idu, idv, idw, tu, tv, tw, nctlu, nctlv, nctlw, &\n ku, kv, kw, coef)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract bvalu is the generic 2D spline interpolant\n ! function. It is similar to the function of the same\n ! name from the tensbs library without the work array\n !\n ! Description of Arguments\n ! Input\n ! u - Real, parametric position 1\n ! v - Real, parametric position 2\n ! w - Real, parametric position 3\n ! idu - Integer, derivative in u to evaluate\n ! idv - Integer, derivative in v to evaluate\n ! idw - Integer, derivative in w to evaluate\n ! tu - Real, U Knot vector. Length nctlu+ku\n ! tv - Real, V Knot vector. Length nctlv+kv\n ! tv - Real, W Knot vector. Length nctlw+kw\n ! Nctlu - Integer, Number of u control points\n ! Nctlv - Integer, Number of v control points\n ! Nctlw - Integer, Number of w control points\n ! ku - Integer, order of spline in u direction\n ! kv - Integer, order of spline in v direction\n ! kw - Integer, order of spline in w direction\n ! coef - Complex, Array size Nctlu x Nctlv x Nctlw, B-spline coefficients\n !\n ! Ouput \n ! b3val - Complex, Evaluated point or derivative\n\n use precision\n implicit none\n\n ! Input\n integer , intent(in) :: ku, kv, kw, nctlu, nctlv, nctlw\n integer , intent(in) :: idu, idv, idw\n real(kind=realType), intent(in) :: u, v, w\n real(kind=realType), intent(in) :: tu(nctlu+ku), tv(nctlv+kv), tw(nctlw+kw)\n complex(kind=realType), intent(in) :: coef(nctlu,nctlv,nctlw)\n\n ! Output\n complex(kind=realType) :: cb3val\n\n ! Working\n integer :: i, j, k\n integer :: ileftu, ileftv, ileftw\n integer :: istartu, istartv, istartw\n real(kind=realType) :: Bu(ku), Bv(kv), Bw(kw)\n real(kind=realType) :: Bud(ku, ku), Bvd(kv, kv), Bwd(kw, kw)\n\n ! Find knot spans\n call findSpan(u, ku, tu, nctlu, ileftu)\n istartu = ileftu-ku\n\n call findSpan(v, kv, tv, nctlv, ileftv)\n istartv = ileftv-kv\n\n call findSpan(w, kw, tw, nctlw, ileftw)\n istartw = ileftw-kw\n\n cb3val = cmplx(0.0, 0.0)\n\n ! Check if we can just use regular basis functions:\n if (idu + idv + idw == 0) then\n call basis(tu, nctlu, ku, u, ileftu, Bu)\n call basis(tv, nctlv, kv, v, ileftv, Bv)\n call basis(tw, nctlw, kw, w, ileftw, Bw)\n\n do i=1, ku\n do j=1, kv\n do k=1, kw\n cb3val = cb3val + Bu(i)*Bv(j)*Bw(k)*&\n coef(istartu+i, istartv+j, istartw+k)\n end do\n end do\n end do\n else\n ! We need derivative basis functions\n call derivBasis(tu, nctlu, ku, u, ileftu, idu, Bud)\n call derivBasis(tv, nctlv, kv, v, ileftv, idv, Bvd)\n call derivBasis(tw, nctlw, kw, w, ileftw, idw, Bwd)\n\n do i=1, ku\n do j=1, kv\n do k=1, kw\n cb3val = cb3val + Bud(idu+1, i)*Bvd(idv+1, j)*Bwd(idw+1, k) * &\n coef(istartu+i, istartv+j, istartw+k)\n end do\n end do\n end do\n end if\n\nend function cb3val\n", "meta": {"hexsha": "d5a36a856b1789319384d2c3818faf25eca291ae", "size": 14896, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/evaluations.f90", "max_stars_repo_name": "eirikurj/pyspline", "max_stars_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2019-04-18T00:49:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-20T14:40:08.000Z", "max_issues_repo_path": "src/evaluations.f90", "max_issues_repo_name": "eirikurj/pyspline", "max_issues_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2019-10-17T20:39:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T15:27:42.000Z", "max_forks_repo_path": "src/evaluations.f90", "max_forks_repo_name": "eirikurj/pyspline", "max_forks_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2019-05-29T16:56:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-08T13:51:24.000Z", "avg_line_length": 31.8972162741, "max_line_length": 82, "alphanum_fraction": 0.5666621912, "num_tokens": 4974, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7515926727786314}} {"text": "!> @brief This subroutine solves a REAL32 quadratic equation of the form \"ax2 + bx + c = 0\".\n!>\n!> @param[in] a The first coefficient\n!>\n!> @param[in] b The second coefficient\n!>\n!> @param[in] c The third coefficient\n!>\n!> @param[out] x1 The first solution\n!>\n!> @param[out] x2 The second solution\n!>\n!> @note For a concise explanation see https://people.csail.mit.edu/bkph/articles/Quadratics.pdf by B.K.P. Horn (see https://people.csail.mit.edu/bkph/).\n!>\n\nPURE SUBROUTINE sub_solve_quadratic_REAL32_equation(a, b, c, x1, x2)\n USE ISO_FORTRAN_ENV\n\n IMPLICIT NONE\n\n ! Declare inputs/outputs ...\n REAL(kind = REAL32), INTENT(in) :: a\n REAL(kind = REAL32), INTENT(in) :: b\n REAL(kind = REAL32), INTENT(in) :: c\n REAL(kind = REAL32), INTENT(out) :: x1\n REAL(kind = REAL32), INTENT(out) :: x2\n\n ! Check sign of b ...\n IF(b >= 0.0e0_REAL32)THEN\n x1 = (-b - SQRT(b ** 2 - 4.0e0_REAL32 * a * c)) / (2.0e0_REAL32 * a)\n x2 = (2.0e0_REAL32 * c) / (-b - SQRT(b ** 2 - 4.0e0_REAL32 * a * c))\n ELSE\n x1 = (2.0e0_REAL32 * c) / (-b + SQRT(b ** 2 - 4.0e0_REAL32 * a * c))\n x2 = (-b + SQRT(b ** 2 - 4.0e0_REAL32 * a * c)) / (2.0e0_REAL32 * a)\n END IF\nEND SUBROUTINE sub_solve_quadratic_REAL32_equation\n", "meta": {"hexsha": "7ed009edfd6952f4ad3cf825985d92f76c2d206a", "size": 1468, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mod_safe/sub_solve_quadratic_equation/sub_solve_quadratic_REAL32_equation.f90", "max_stars_repo_name": "Guymer/fortranlib", "max_stars_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-28T02:05:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-16T16:50:21.000Z", "max_issues_repo_path": "mod_safe/sub_solve_quadratic_equation/sub_solve_quadratic_REAL32_equation.f90", "max_issues_repo_name": "Guymer/fortranlib", "max_issues_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-06-17T16:49:20.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-11T18:47:36.000Z", "max_forks_repo_path": "mod_safe/sub_solve_quadratic_equation/sub_solve_quadratic_REAL32_equation.f90", "max_forks_repo_name": "Guymer/fortranlib", "max_forks_repo_head_hexsha": "30e27b010cf4bc5acf0f3a63d50f11789640e0e3", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-11T04:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-11T04:51:33.000Z", "avg_line_length": 39.6756756757, "max_line_length": 153, "alphanum_fraction": 0.5190735695, "num_tokens": 460, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.7514125239254105}} {"text": "* write program to find serivstive of f(x)=sin(x)\r\n* for x=1 , usimg 3 point method\r\n\r\n 10 Read(*,*)X\r\n write(*,*)'Enter the value of H'\r\n Read(*,*)H\r\n If(H.LE.0)stop\r\n fbrime=(sin(x+H)-sin(x-H))/2*h\r\n exact=cos(x)\r\n Error=exact-fbrime\r\n write(*,*)H,Error,fbrime,exact\r\n Go to 10\r\n* Stop\r\n End\r\n \r\n", "meta": {"hexsha": "ffdb7fb134a8dfc3d08ccd411a8410c8b6f8b8f1", "size": 391, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "last28-52009/Example/Difrentiation function/Difrentiation function.f", "max_stars_repo_name": "Melhabbash/Computational-Physics-", "max_stars_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "last28-52009/Example/Difrentiation function/Difrentiation function.f", "max_issues_repo_name": "Melhabbash/Computational-Physics-", "max_issues_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "last28-52009/Example/Difrentiation function/Difrentiation function.f", "max_forks_repo_name": "Melhabbash/Computational-Physics-", "max_forks_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.4375, "max_line_length": 56, "alphanum_fraction": 0.4578005115, "num_tokens": 126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. Yes\n2. Yes", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.7514079111468828}} {"text": "submodule (stdlib_specialfunctions) stdlib_specialfunctions_legendre\n implicit none\n\ncontains\n\n ! derivatives of legegendre polynomials\n ! unspecified behaviour if n is negative\n pure elemental module function dlegendre_fp64(n,x) result(dleg)\n integer, intent(in) :: n\n real(dp), intent(in) :: x\n real(dp) :: dleg\n\n select case(n)\n case(0)\n dleg = 0\n case(1)\n dleg = 1\n case default\n block\n real(dp) :: leg_down1, leg_down2, leg\n real(dp) :: dleg_down1, dleg_down2\n integer :: i \n\n leg_down1 = x\n dleg_down1 = 1\n\n leg_down2 = 1\n dleg_down2 = 0\n\n do i = 2, n\n leg = (2*i-1)*x*leg_down1/i - (i-1)*leg_down2/i\n dleg = dleg_down2 + (2*i-1)*leg_down1\n leg_down2 = leg_down1\n leg_down1 = leg\n dleg_down2 = dleg_down1\n dleg_down1 = dleg\n end do\n end block\n end select\n end function\n\n ! legegendre polynomials\n ! unspecified behaviour if n is negative\n pure elemental module function legendre_fp64(n,x) result(leg)\n integer, intent(in) :: n\n real(dp), intent(in) :: x\n real(dp) :: leg\n select case(n)\n case(0)\n leg = 1\n case(1)\n leg = x\n case default\n block\n real(dp) :: leg_down1, leg_down2\n integer :: i \n\n leg_down1 = x\n leg_down2 = 1\n\n do i = 2, n\n leg = (2*i-1)*x*leg_down1/i - (i-1)*leg_down2/i\n leg_down2 = leg_down1\n leg_down1 = leg\n end do\n end block\n end select\n end function\n\nend submodule\n\n\n", "meta": {"hexsha": "fb2812bbc64b44e2ef9682b4dc75853a7216d60e", "size": 2076, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stdlib_specialfunctions_legendre.f90", "max_stars_repo_name": "freevryheid/stdlib", "max_stars_repo_head_hexsha": "084f3c4cef67e234895292c597c455d02f52840b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 653, "max_stars_repo_stars_event_min_datetime": "2019-12-14T23:20:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:31:07.000Z", "max_issues_repo_path": "src/stdlib_specialfunctions_legendre.f90", "max_issues_repo_name": "seanwallawalla-forks/stdlib", "max_issues_repo_head_hexsha": "f58da3b1141a0bb0ce741aa6b74f636a1376706d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 593, "max_issues_repo_issues_event_min_datetime": "2019-12-14T23:19:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T19:40:29.000Z", "max_forks_repo_path": "src/stdlib_specialfunctions_legendre.f90", "max_forks_repo_name": "ejovo13/stdlib", "max_forks_repo_head_hexsha": "ce3a106f14afcc01b8d2e48437c94e7c5e7a19a1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 122, "max_forks_repo_forks_event_min_datetime": "2019-12-19T17:51:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T21:08:11.000Z", "avg_line_length": 28.4383561644, "max_line_length": 71, "alphanum_fraction": 0.4349710983, "num_tokens": 496, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7514079109928546}} {"text": "! Calculating Pi with using method: \n! integral 4.0/(1+x^2) dx = p\t \n! \t OpenMP Version 2\t \nprogram pi_omp_v1\nimplicit none\ninteger*8 :: num_steps = 1000000000\ninteger i,tid,nthreads,omp_get_num_threads,omp_get_thread_num\nreal*8 :: PI_ref=3.1415926535897932,step,x,pi\nreal*8 :: summation=0.0\nreal*8 :: start,finish,omp_get_wtime\n!call cpu_time(start)\nstep = 1/(1.0 * num_steps)\nstart=omp_get_wtime()\n!$omp parallel do private(x) reduction(+:summation) shared(step)\n\tdo i =1,num_steps\n\t\tx=((i-1)+0.5) * step;\n\t\tsummation=summation + (4.0/(1.0+(x*x)))\n\tend do\n!$omp end parallel do\n\tpi=step*summation\n\n!call cpu_time(finish)\nfinish=omp_get_wtime()\n\twrite(*,*) \"Estimated value of pi =\",pi\n\twrite(*,*) \"Error =\", abs(PI_ref - pi)\n\twrite(*,*) \"Compute time=\", (finish-start),\" seconds\"\nend\n\n\n", "meta": {"hexsha": "6060fa89292cfeb0e2cd8203a4bc7116337c1631", "size": 804, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/ftn/src/pi-omp-v2.f90", "max_stars_repo_name": "pelahi/Develop-with-OpenMP", "max_stars_repo_head_hexsha": "3b3d485aac3f74148b303515fb897e58dfbef18d", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Solutions/ftn/src/pi-omp-v2.f90", "max_issues_repo_name": "pelahi/Develop-with-OpenMP", "max_issues_repo_head_hexsha": "3b3d485aac3f74148b303515fb897e58dfbef18d", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Solutions/ftn/src/pi-omp-v2.f90", "max_forks_repo_name": "pelahi/Develop-with-OpenMP", "max_forks_repo_head_hexsha": "3b3d485aac3f74148b303515fb897e58dfbef18d", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-03T02:07:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-03T02:07:35.000Z", "avg_line_length": 26.8, "max_line_length": 64, "alphanum_fraction": 0.6853233831, "num_tokens": 280, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810451666346, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7513735449606818}} {"text": "PROGRAM DERIVADAS\n! CALL derivada(n,x,h,func,A) esta subrutina calcula con una presicion 'n', el valor 'A' de la derivada en un punto 'x' con un paso de 'h' de una funcion 'func'(definida como external antes del programa. todo con presicion doble\n\n!-----------------------------------------------------------------------\n\tcontains\n! ---------------------------------------------------------------------- \n subroutine derivada(n,x,h,func,A)\n !esta subrutina calcula con una presicion 'n', el valor 'A' de la derivada en un punto 'x' con un paso de 'h' de una funcion 'func'(definida como external antes del programa. todo con presicion doble\n implicit none\n real*8::h,x,A,func\n REAL*8,ALLOCATABLE,DIMENSION(:,:)::D\n integer*4::i,j,n\n\n allocate(D(n,n))\n D(:,:)=0.0d1\n !CADA fila es un D(fila ejemplo 1) con la primer cordenada 2H la segunda H la tercera H/2. la segunda fila es un D2 con primer elemento H segundo H/2 Y ASI \n do j=0,n-1\n do i=1,n-j\n if (j==0) then\n if (i==1) then\n D(j+1,i)=((func(x+h)-func(x-h))/(2*h))\n else\n D(j+1,i)=((func(x+(h/(2**(i-1))))-func(x-(h/(2**(i-1)))))/(2*(h/(2**(i-1)))))\n end if\n else\n D(j+1,i)=(((2**(2*(j))))*D(j,i+1)-D(j,i))/((2**(2*(j)))-1)\n end if\n end do\n end do\n A=D(n,1)\n deallocate(D) \n return \n end subroutine\nEND\n\n\n", "meta": {"hexsha": "c899561d6a2c051d96ac007f514c5e0b4591a2b1", "size": 1404, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fedora/subderivadas.f90", "max_stars_repo_name": "patricio-c/fortran", "max_stars_repo_head_hexsha": "da11f9e06010399703e8d8e51f57c44a7663857f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fedora/subderivadas.f90", "max_issues_repo_name": "patricio-c/fortran", "max_issues_repo_head_hexsha": "da11f9e06010399703e8d8e51f57c44a7663857f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fedora/subderivadas.f90", "max_forks_repo_name": "patricio-c/fortran", "max_forks_repo_head_hexsha": "da11f9e06010399703e8d8e51f57c44a7663857f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.9459459459, "max_line_length": 228, "alphanum_fraction": 0.514957265, "num_tokens": 439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109770159682, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7513286901824369}} {"text": "C$Procedure DVDOT ( Derivative of Vector Dot Product, 3-D )\n \n DOUBLE PRECISION FUNCTION DVDOT ( S1, S2 )\n \nC$ Abstract\nC\nC Compute the derivative of the dot product of two double\nC precision position vectors.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC VECTOR\nC DERIVATIVE\nC\nC$ Declarations\n \n \n DOUBLE PRECISION S1 ( 6 )\n DOUBLE PRECISION S2 ( 6 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC S1 I First state vector in the dot product.\nC S2 I Second state vector in the dot product.\nC\nC The function returns the derivative of the dot product \nC\nC$ Detailed_Input\nC\nC S1 Any state vector. The componets are in order\nC (x, y, z, dx/dt, dy/dt, dz/dt )\nC\nC S2 Any state vector.\nC\nC$ Detailed_Output\nC\nC The function returns the derivative of the dot product of the\nC position portions of the two state vectors S1 and S2.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Files\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Particulars\nC\nC Given two state vectors S1 and S2 made up of position and\nC velocity components (P1,V1) and (P2,V2) respectively,\nC DVDOT calculates the derivative of the dot product of P1 and P2,\nC i.e. the time derivative\nC\nC d\nC -- < P1, P2 > = < V1, P2 > + < P1, V2 >\nC dt\nC\nC where <,> denotes the dot product operation.\nC\nC$ Examples\nC\nC Suppose that given two state vectors (S1 and S2)whose position\nC components are unit vectors, and that we need to compute the\nC rate of change of the angle between the two vectors.\nC\nC We know that the Cosine of the angle THETA between them is given\nC by\nC\nC COSINE(THETA) = VDOT(S1,S2)\nC\nC Thus by the chain rule, the derivative of the angle is given\nC by:\nC\nC SINE(THETA) dTHETA/dt = DVDOT(S1,S2)\nC\nC Thus for values of THETA away from zero we can compute\nC\nC dTHETA/dt as\nC\nC DTHETA = DVDOT(S1,S2) / SQRT ( 1 - VDOT(S1,S2)**2 )\nC\nC Note that position components of S1 and S2 are parallel, the\nC derivative of the angle between the positions does not\nC exist. Any code that computes the derivative of the angle\nC between two position vectors should account for the case\nC when the position components are parallel.\nC\nC$ Restrictions\nC\nC The user is responsible for determining that the states S1 and\nC S2 are not so large as to cause numeric overflow. In most cases\nC this won't present a problem.\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.0, 18-MAY-1995 (WLT)\nC\nC\nC-&\n \n \nC$ Index_Entries\nC\nC Compute the derivative of a dot product\nC\nC-&\nC\n \n DVDOT = S1(1)*S2(4) + S1(2)*S2(5) + S1(3)*S2(6)\n . + S1(4)*S2(1) + S1(5)*S2(2) + S1(6)*S2(3)\n \n RETURN\n END\n \n \n \n \n \n", "meta": {"hexsha": "bbd87388d69fb767a83338f2a23fdc6fc67b1175", "size": 4352, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/dvdot.f", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/nasa_f/dvdot.f", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/nasa_f/dvdot.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 26.6993865031, "max_line_length": 71, "alphanum_fraction": 0.6698069853, "num_tokens": 1316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465170505205, "lm_q2_score": 0.8031737892899221, "lm_q1q2_score": 0.7512458063985973}} {"text": "!\n! lab1_7.f90\n!\n! Copyright 2016 Bruno S \n!\n! This program is free software; you can redistribute it and/or modify\n! it under the terms of the GNU General Public License as published by\n! the Free Software Foundation; either version 2 of the License, or\n! (at your option) any later version.\n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n! GNU General Public License for more details.\n!\n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,\n! MA 02110-1301, USA.\n!\n!\n!\nPROGRAM lab1_7\n\nuse precision, pr => dp\n!include \"/usr/include/fftw3.f\"\n\nIMPLICIT NONE\n\ninclude \"/usr/include/fftw3.f\"\ninteger(kind=8) :: plan_rc, plan_cr\n\ninteger :: i, j, k\ninteger, parameter :: n=1024\nreal(pr) :: start_time, finish_time\nreal(pr) :: pi, ti, tf, L, factor, fre, fim\nreal(pr), dimension(n) :: f, t\ncomplex(pr), dimension(n/2 + 1) :: f_hat\n\nopen(unit=10, file='f_t_ej7.dat', status='UNKNOWN', action='WRITE')\nopen(unit=16, file='fft_ej7.dat', status='UNKNOWN', action='WRITE')\nwrite(10, *) \"# t f\"\nwrite(16, *) \"# freq real imag\"\ncall dfftw_plan_dft_r2c_1d(plan_rc, n, f, f_hat, FFTW_MEASURE)\n\npi = 4._pr*atan(1._pr)\nti = 0._pr\ntf = 4._pr\nL = (tf - ti)\n\nt(1:n) = (/ (i, i=1, n) /)\nt = t*L/real(n, pr)\n\nf = sin(pi/2._pr * t) + cos(20._pr * pi * t)\ndo i=1, n\n write(10, *) t(i), f(i)\nend do\n\ncall cpu_time(start_time)\n\ncall dfftw_execute_dft_r2c(plan_rc, f, f_hat)\n\ncall cpu_time(finish_time)\n\n\n!write(16,*) '# freq f_hat'\nfactor = 1024._pr / L\n\ndo i = -n/2, n/2, 1\n if (i < 0) then\n fre = real(conjg(f_hat(-i+1) )/real(n, pr))\n fim = imag(conjg(f_hat(-i+1) )/real(n, pr))\n write(16,*) factor*real(i, pr), fre, fim\n else\n fre = real(f_hat(i+1) /real(n, pr))\n fim = imag(f_hat(i+1) /real(n, pr))\n write(16,*) factor*real(i, pr), fre, fim\n endif\nenddo\n\nEND PROGRAM lab1_7\n", "meta": {"hexsha": "6f41c2609571672b5394d6b54b4b69bfe5560b08", "size": 2130, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lab1/7/lab1_7.f90", "max_stars_repo_name": "BrunoSanchez/fisicaComp", "max_stars_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lab1/7/lab1_7.f90", "max_issues_repo_name": "BrunoSanchez/fisicaComp", "max_issues_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lab1/7/lab1_7.f90", "max_forks_repo_name": "BrunoSanchez/fisicaComp", "max_forks_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.9756097561, "max_line_length": 70, "alphanum_fraction": 0.6563380282, "num_tokens": 720, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.8577681013541613, "lm_q1q2_score": 0.7512221505783343}} {"text": "double precision function lngamma(z)\n! Uses Lanczos-type approximation to ln(gamma) for z > 0.\n! Reference:\n! Lanczos, C. 'A precision approximation of the gamma function', J. SIAM Numer. Anal., B, 1, 86-96, 1964.\n! Accuracy: About 14 significant digits except for small regions in the vicinity of 1 and 2.\n!\n! Programmer: Alan Miller\n! 1 Creswick Street, Brighton, Vic. 3187, Australia\n! Latest revision - 17 April 1988\n implicit none\n double precision a(9), z, lnsqrt2pi, tmp\n integer j\n data a/0.9999999999995183d0, 676.5203681218835d0, -1259.139216722289d0, 771.3234287757674d0,&\n -176.6150291498386d0, 12.50734324009056d0, -0.1385710331296526d0, 0.9934937113930748d-05,&\n 0.1659470187408462d-06/\n\n data lnsqrt2pi/0.9189385332046727d0/\n\n if (z <= 0.d0) return\n\n lngamma = 0.d0\n tmp = z + 7.d0\n do j = 9, 2, -1\n lngamma = lngamma + a(j)/tmp\n tmp = tmp - 1.d0\n end do\n lngamma = lngamma + a(1)\n lngamma = log(lngamma) + lnsqrt2pi - (z+6.5d0) + (z-0.5d0)*log(z+6.5d0)\nend\n\nsubroutine get_xgwg(x1, x2, x, w, n)\n ! gauleg.f90 P145 Numerical Recipes in Fortran\n ! compute x(i) and w(i) i=1,n Gauss-Legendre ordinates and weights\n ! on interval -1.0 to 1.0 (length is 2.0)\n ! use ordinates and weights for Gauss Legendre integration\n ! After f2py implicit argument wrapping: x, w = get_xgwg(x1, x2, n)\n implicit none\n integer, intent(in) :: n\n double precision, intent(in) :: x1, x2\n double precision, dimension(n), intent(out) :: x, w\n integer :: i, j, m\n double precision :: p1, p2, p3, pp, xl, xm, z, z1\n double precision, parameter :: eps=1.d-15\n\n m = (n+1)/2\n xm = 0.5d0*(x2+x1)\n xl = 0.5d0*(x2-x1)\n do i=1,m\n z = cos(3.141592654d0*(i-0.25d0)/(n+0.5d0))\n z1 = 0.d0\n do while(abs(z-z1) > eps)\n p1 = 1.0d0\n p2 = 0.0d0\n do j=1,n\n p3 = p2\n p2 = p1\n p1 = ((2.0d0*j-1.0d0)*z*p2-(j-1.0d0)*p3)/j\n end do\n pp = n*(z*p1-p2)/(z*z-1.0d0)\n z1 = z\n z = z1 - p1/pp\n end do\n x(i) = xm - xl*z\n x(n+1-i) = xm + xl*z\n w(i) = (2.0d0*xl)/((1.0d0-z*z)*pp*pp)\n w(n+1-i) = w(i)\n end do\nend subroutine get_xgwg\n\nsubroutine wignerpos(xi, cl, x, m1, m2, nx, lmax)\n ! Position-space representation\n ! sum_l Cl (2l + 1) / 4pi d^l_{m1,m2}(x)\n implicit None\n integer, intent(in) :: m1, m2, lmax, nx\n double precision, intent(in) :: x(nx), cl(0:lmax)\n double precision, intent(out) :: xi(nx)\n double precision :: d0(nx), d1(nx), d2(nx)\n double precision, external :: lngamma\n integer :: a, b, lmin, n, in, sgn\n double precision :: alfbet, a2, b2, n2_ab2, norm, a0, ak_km1, akm1_km2\n\n lmin = max(abs(m1), abs(m2))\n a = abs(m1 - m2)\n b = abs(m1 + m2)\n if (m1 > m2) then\n sgn = (-1) ** (m1 - m2)\n else\n sgn = 1\n end if\n n = max(lmax, lmin) - lmin\n alfbet= a + b\n a2 = a * a\n b2 = b * b\n\n a0 = exp(0.5d0 * (lngamma(2d0 * lmin + 1d0) - lngamma(a + 1d0) - lngamma(2 * lmin - a + 1d0)))\n ak_km1 = sqrt((1.d0 + 2 * lmin) / (1.d0 + a) / (1.d0 + b))\n ! a1 / a0. (ak is coefficient relating Jacobi to Wigner)\n ! lmin\n d0 = sgn * a0 * ((1.d0 - x) * 0.5d0) ** (0.5d0 * a) * ((1. + x) * 0.5d0) ** (b * 0.5d0)\n xi = (2 * lmin + 1) * cl(lmin) * d0\n if (n > 0) then\n ! lmin + 1\n d1 = ak_km1 * d0 * 0.5d0 * (2 * (a + 1) + (alfbet + 2d0) * (x - 1d0))\n xi = xi + (2 * lmin + 3) * cl(lmin + 1) * d1\n end if\n do in = 1, n -1\n akm1_km2 = ak_km1\n ak_km1 = sqrt((1d0 + lmin * 2d0 / (in + 1d0)) / (1d0 + a / (in + 1d0)) / (1d0 + b/(in + 1d0)))\n n2_ab2 = 2 * in + alfbet\n norm = 2 * (in + 1) * (in + 1 + alfbet) * n2_ab2\n !lmin + in + 1\n d2 = (((n2_ab2 + 1.d0) * ((n2_ab2 + 2.d0) * n2_ab2 * x + a2 - b2)) * ak_km1 * d1 &\n - 2 * ( in + a) * (in + b) * (n2_ab2 + 2d0) * akm1_km2 * ak_km1 * d0) / norm\n xi = xi + (2 * (lmin + in + 1) + 1) * cl(lmin + in + 1) * d2\n d0 = d1\n d1 = d2\n end do\n xi = xi * (0.25d0 / 3.14159265358979323846d0)\nend subroutine wignerpos\n\nsubroutine wignercoeff(h, xiw, x, m1, m2, lmax, nx)\n ! Returns 2pi * sum_i xiw[i] d^l_{m1, m2}(x_i) for 0 <= l <= lmax.\n ! If xiw is the product of Gauss-Legend quadrature weights, x the GL quadrature points,\n ! then this is the Wigner transform harmonic coefficient cl = 2pi \\int_{-1}^{1} dx d^l_{m1,m2}(x) xi(x),\n ! with xi(x) = sum_l cl (2l + 1) / 4pi d^l_{m1, m2}.\n\n implicit None\n integer, intent(in) :: lmax, nx, m1, m2\n double precision, intent(in) :: x(nx), xiw(nx)\n double precision, intent(out) :: h(0:lmax)\n double precision :: d0(nx), d1(nx), d2(nx)\n double precision, external :: lngamma\n integer :: a, b, lmin, n, in, sgn\n double precision :: alfbet, a2, b2, n2_ab2, norm, a0, ak_km1, akm1_km2\n lmin = max(abs(m1), abs(m2))\n a = abs(m1 - m2)\n b = abs(m1 + m2)\n if (m1 > m2) then\n sgn = (-1) ** (m1 - m2)\n else\n sgn = 1\n end if\n n = max(lmax, lmin) - lmin\n n = max(Lmax, lmin) - lmin\n\n alfbet= a + b\n a2 = a * a\n b2 = b * b\n\n a0 = exp(0.5d0 * (lngamma(2d0 * lmin + 1d0) - lngamma(a + 1d0) - lngamma(2 * lmin - a + 1d0)))\n ak_km1 = sqrt((1.d0 + 2 * lmin) / (1.d0 + a) / (1.d0 + b))\n ! a1 / a0. (ak is coefficient relating Jacobi to Wigner)\n ! lmin\n d0 = sgn * a0 * ((1.d0 - x) * 0.5d0) ** (0.5d0 * a) * ((1. + x) * 0.5d0) ** (b * 0.5d0)\n h(lmin) = sum(xiw * d0)\n if (n > 0) then\n ! lmin + 1\n d1 = ak_km1 * d0 * 0.5d0 * (2 * (a + 1) + (alfbet + 2d0) * (x - 1d0))\n h(lmin + 1) = sum(xiw * d1)\n end if\n do in = 1, n -1\n akm1_km2 = ak_km1\n ak_km1 = sqrt((1d0 + lmin * 2d0 / (in + 1d0)) / (1d0 + a / (in + 1d0)) / (1d0 + b/(in + 1d0)))\n n2_ab2 = 2 * in + alfbet\n norm = 2 * (in + 1) * (in + 1 + alfbet) * n2_ab2\n !lmin + in + 1\n d2 = (((n2_ab2 + 1.d0) * ((n2_ab2 + 2.d0) * n2_ab2 * x + a2 - b2)) * ak_km1 * d1 &\n - 2 * ( in + a) * (in + b) * (n2_ab2 + 2d0) * akm1_km2 * ak_km1 * d0) / norm\n h(lmin + in + 1) = sum(xiw * d2)\n d0 = d1\n d1 = d2\n end do\n h = h * (2d0 * 3.14159265358979323846d0)\n\nend subroutine wignercoeff", "meta": {"hexsha": "3827d2131c42093eef6657565e4a11f2b1f9d6ba", "size": 6290, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "plancklens/wigners/wigners.f90", "max_stars_repo_name": "pcampeti/plancklens", "max_stars_repo_head_hexsha": "44b8a932551cb6534965892cd7c72b0a9cd8c3a5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "plancklens/wigners/wigners.f90", "max_issues_repo_name": "pcampeti/plancklens", "max_issues_repo_head_hexsha": "44b8a932551cb6534965892cd7c72b0a9cd8c3a5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "plancklens/wigners/wigners.f90", "max_forks_repo_name": "pcampeti/plancklens", "max_forks_repo_head_hexsha": "44b8a932551cb6534965892cd7c72b0a9cd8c3a5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-04-07T07:48:29.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-07T07:48:29.000Z", "avg_line_length": 35.9428571429, "max_line_length": 116, "alphanum_fraction": 0.5259141494, "num_tokens": 2776, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642906, "lm_q2_score": 0.8221891283434877, "lm_q1q2_score": 0.7512149063060483}} {"text": "module slf_threshold\n\n use iso_fortran_env, only: r64 => real64\n implicit none\n\n real(r64), parameter, private :: pi = 4*atan(real(1,r64))\n\ncontains\n\n elemental real(r64) function THRSTEP(x) result(y)\n real(r64), intent(in) :: x\n if ( x .ge. 0 ) then\n y = 1.\n else\n y = 0.\n end if\n end function\n\n elemental real(r64) function THRLIN(x) result(y)\n real(r64), intent(in) :: x\n if ( x < -0.5_r64) then\n y = 0\n elseif ( x > 0.5_r64) then\n y = 1\n else\n y = x + 0.5_r64\n end if\n end function\n\n elemental real(r64) function THR2POLY(x,ord) result(y)\n real(r64), intent(in) :: x\n integer, intent(in), optional :: ord\n integer :: n\n real(r64) :: a, b\n\n n = 3\n if ( present(ord) ) n = ord\n\n a = THRLIN(0.5 + 2*x/n)\n b = THRLIN(0.5 - 2*x/n)\n\n y = (a**n - b**n + 1) / 2\n end function\n\n elemental real(r64) function THR4POLY(x,ord) result(y)\n real(r64), intent(in) :: x\n integer, intent(in), optional :: ord\n integer :: n\n real(r64) :: a, b, c\n\n n = 3\n if ( present(ord) ) n = ord\n\n a = THRLIN((3 + x*4)/2)\n b = 2*THRLIN(x) - 1\n c = THRLIN((3 - x*4)/2)\n\n y = (a**n - c**n + b*(2*n - abs(b)**(n-1)) + 2*n)/(4*n)\n\n end function\n\n elemental real(r64) function THRSIN(x) result(y)\n real(r64), intent(in) :: x\n real(r64) :: z\n\n z = 2*THRLIN(x / 2) - 1\n y = (sin( pi * z) / pi + z + 1) / 2\n end function\n\n elemental real(r64) function THRATAN(x) result(y)\n real(r64), intent(in) :: x\n y = atan(x*pi) / pi + 0.5\n end function\n\n elemental real(r64) function thrsqrt(x) result(y)\n real(r64), intent(in) :: x\n y = 0.5_r64 + x / sqrt( 1 + 4 * x**2 )\n end function\n\n elemental real(r64) function thrtanh(x) result(y)\n real(r64), intent(in) :: x\n y = 1d0 / ( 1d0 + exp(-4*x) )\n end function\n\nend module\n\n!------------------------------------------------------------------------------!\n!------------------------------------------------------------------------------!\n\nmodule slf_ramps\n\n use iso_fortran_env, only: r64 => real64\n implicit none\n\ncontains\n\n !----------------------------------------------------------------------------!\n ! this is a linear ramp\n\n elemental function ramp1(i,n) result(y)\n integer, intent(in) :: i,n\n real(r64) :: y\n y = real(max(min(i, n), 0), r64) / n\n end function\n\n !----------------------------------------------------------------------------!\n ! this is a very steep ramp, for later iterations\n\n elemental function ramp2(i,n) result(y)\n integer, intent(in) :: i,n\n real(r64) :: t,y\n t = real(max(min(i, n), 0), r64) / n\n y = t * (2 - t)\n end function\n\n !----------------------------------------------------------------------------!\n ! this is a very smooth, s-shaped ramp\n ! slow convergence but good if we are away from the solution\n\n elemental function ramp3(i,n) result(y)\n integer, intent(in) :: i,n\n real(r64) :: t,y\n t = real(max(min(i, n), 0), r64) / n\n y = (3 - 2*t) * t**2\n end function\n\n !----------------------------------------------------------------------------!\n ! this is a very smooth ramp where you can control the starting\n ! level as well as slope of the starting point. It may be applied\n ! for very unstable equations (A = 0, B = 0) or for a very quick\n ! convergence (A = 0.25, B = 1)\n\n elemental real(r64) function ramp4r(x, A, B) result(y)\n real(r64), intent(in) :: x\n real(r64), intent(in) :: A,B\n y = A + (1 - A) * B * x &\n + 3 * (A - 1) * (B - 2) * x**2 &\n - (A - 1) * (3*B - 8) * x**3 &\n + (A - 1) * (B - 3) * x**4\n end function\n\n elemental function ramp4(i,n,A,B) result(y)\n integer, intent(in) :: i,n\n real(r64), intent(in) :: A,B\n real(r64) :: x,y\n x = real(max(min(i, n), 0), r64) / n\n y = ramp4r(x, A, B)\n end function\n\n !----------------------------------------------------------------------------!\n ! this ramp starts smoothly, rises rapidly, and then slowly saturates to 1\n\n elemental real(r64) function ramp5r(x) result(y)\n real(r64), intent(in) :: x\n y = (6 + x * (x * 3 - 8)) * x**2\n end function\n\n elemental function ramp5(i,n) result(y)\n integer, intent(in) :: i,n\n real(r64) :: t,y\n t = real(max(min(i, n), 0), r64) / n\n y = ramp5r(t)\n end function\n\n !----------------------------------------------------------------------------!\n\n elemental real(r64) function ramp6r(x) result(y)\n real(r64), intent(in) :: x\n y = x**2 * (5 + x * (10 + x * (x * 8 - 20))) / 3\n end function\n\n elemental function ramp6(i,n) result(y)\n integer, intent(in) :: i,n\n real(r64) :: t,y\n t = real(max(min(i, n), 0), r64) / n\n y = ramp6r(t)\n end function\n\n !----------------------------------------------------------------------------!\n\nend module slf_ramps\n", "meta": {"hexsha": "484f838755283cce63452e8219c19eef109aac20", "size": 4798, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/math/thrfun.f90", "max_stars_repo_name": "gronki/diskvert", "max_stars_repo_head_hexsha": "459238a46fc173c9fec3ff609cd42595bbc0c858", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/math/thrfun.f90", "max_issues_repo_name": "gronki/diskvert", "max_issues_repo_head_hexsha": "459238a46fc173c9fec3ff609cd42595bbc0c858", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/math/thrfun.f90", "max_forks_repo_name": "gronki/diskvert", "max_forks_repo_head_hexsha": "459238a46fc173c9fec3ff609cd42595bbc0c858", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.3626373626, "max_line_length": 80, "alphanum_fraction": 0.4720716965, "num_tokens": 1544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.751214902440837}} {"text": "MODULE ylm_module ! Spherical Harmonic Function\n\n implicit none\n\n PRIVATE\n PUBLIC :: Ylm\n PUBLIC :: ZYlm\n\nCONTAINS\n\n FUNCTION Ylm( x,y,z, L, M_in )\n\n implicit none\n real(8) :: Ylm\n real(8),intent(IN) :: x,y,z\n integer,intent(IN) :: L,M_in\n integer :: k1,k2,k,M\n real(8) :: r,r2,Clm,ct,phi,c,pi4\n real(8),parameter :: ep=1.d-10, zero=0.0d0\n real(8),parameter :: half=0.5d0, one=1.0d0, two=2.0d0\n real(8),parameter :: pi=3.141592653589793238d0\n\n Ylm = zero\n M = abs(M_in)\n pi4 = 4.0d0*pi\n\n if ( L < 0 .or. M > L ) then\n write(*,*) \"L,M_in=\",L,M_in\n stop \"Bad arguments (stop at Ylm)\"\n end if\n\n if ( L == 0 ) then\n Ylm=one/sqrt(pi4)\n return\n end if\n\n if ( x == 0.0d0 .and. y == 0.0d0 .and. z == 0.0d0 ) return\n\n c=one\n do k=L-M+1,L+M\n c=c*dble(k)\n end do\n Clm=sqrt((two*L+one)/(c*pi4))\n\n r = sqrt(x*x+y*y+z*z)\n ct = z/r\n if ( abs(x) < ep ) then\n phi = half*pi*sign(one,y)\n else\n phi = atan(y/x)\n if ( x < 0 ) phi = phi + pi\n end if\n\n if ( M_in > 0 ) then\n\n Ylm = sqrt(two)*Clm*Plm(L,M,ct)*cos(phi*M)\n\n else if ( M_in == 0 ) then\n\n Ylm = Clm*Plm(L,M,ct)\n\n else if ( mod(M,2) == 0 ) then\n\n Ylm =-sqrt(two)*Clm*Plm(L,M,ct)*sin(phi*M)\n\n else\n\n Ylm = sqrt(two)*Clm*Plm(L,M,ct)*sin(phi*M)\n\n end if\n\n return\n END FUNCTION Ylm\n\n\n FUNCTION ZYlm( x,y,z, L, M_in )\n\n implicit none\n complex(8) :: ZYlm\n real(8),intent(IN) :: x,y,z\n integer,intent(IN) :: L,M_in\n integer :: k1,k2,k,M\n real(8) :: r,r2,Clm,ct,phi,c,pi4\n real(8),parameter :: ep=1.d-10\n real(8),parameter :: half=0.5d0, one=1.0d0, two=2.0d0\n real(8),parameter :: pi=3.141592653589793238d0\n complex(8),parameter :: zero=(0.0d0,0.0d0)\n\n ZYlm = zero\n M = abs(M_in)\n pi4 = 4.0d0*pi\n\n if ( L < 0 .or. M > L ) then\n! write(*,*) \"L,M_in=\",L,M_in\n! stop \"Bad arguments (stop at ZYlm)\"\n return\n end if\n\n if ( L == 0 ) then\n ZYlm=one/sqrt(pi4)\n return\n end if\n\n if ( x == 0.0d0 .and. y == 0.0d0 .and. z == 0.0d0 ) return\n\n c=one\n do k=L-M+1,L+M\n c=c*dble(k)\n end do\n Clm=sqrt((two*L+one)/(c*pi4))\n\n r = sqrt(x*x+y*y+z*z)\n ct = z/r\n if ( abs(x) < ep ) then\n phi = half*pi*sign(one,y)\n else\n phi = atan(y/x)\n if ( x < 0 ) phi = phi + pi\n end if\n\n ZYlm = Clm*Plm(L,M,ct)*dcmplx( cos(phi*M), sin(phi*M) )\n\n if ( M_in < 0 ) then\n ZYlm = conjg( ZYlm )\n if ( mod(M,2) /= 0 ) ZYlm=-ZYlm\n end if\n\n return\n END FUNCTION ZYlm\n\n!----------------------------------- Associated Legendre Polynomial Plm(x)\n\n FUNCTION Plm(L,M,xi)\n\n implicit none\n real(8) :: Plm\n integer,intent(IN) :: L,M\n real(8),intent(IN) :: xi\n real(8),parameter :: ep=1.d-13,one=1.0d0,two=2.0d0\n real(8) :: pmm,somx2,fact,pmmp1,pll,tmp,x\n integer :: i,ll\n\n x = xi\n tmp = abs(abs(x)-one) ; if ( tmp < ep ) x = sign(one,x)\n\n if( m < 0 .or. m > l .or. abs(x) > one ) then\n stop \"Bad arguments (stop at Plm)\"\n end if\n\n pmm=one\n\n if ( m > 0 ) then\n somx2=sqrt((one-x)*(one+x))\n fact=one\n do i=1,M\n pmm=-pmm*fact*somx2\n fact=fact+two\n end do\n end if\n\n if ( L == M ) then\n Plm = pmm\n else\n pmmp1 = x*(two*m+one)*pmm\n if ( L == M+1 ) then\n Plm=pmmp1\n else\n do ll=M+2,L\n pll=(x*(two*ll-one)*pmmp1-(ll+M-one)*pmm)/(ll-M)\n pmm=pmmp1\n pmmp1=pll\n end do\n Plm=pll\n end if\n end if\n\n return\n END FUNCTION Plm\n\n\nEND MODULE ylm_module\n", "meta": {"hexsha": "4b62e9a7623c1ac5bd53dc9fec4db1d11de93805", "size": 3660, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ylm_module.f90", "max_stars_repo_name": "j-iwata/RSDFT_DEVELOP", "max_stars_repo_head_hexsha": "14e79a4d78a19e5e5c6fd7b3d2f2f0986f2ff6df", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-02T05:03:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-02T05:03:05.000Z", "max_issues_repo_path": "src/ylm_module.f90", "max_issues_repo_name": "j-iwata/RSDFT_DEVELOP", "max_issues_repo_head_hexsha": "14e79a4d78a19e5e5c6fd7b3d2f2f0986f2ff6df", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/ylm_module.f90", "max_forks_repo_name": "j-iwata/RSDFT_DEVELOP", "max_forks_repo_head_hexsha": "14e79a4d78a19e5e5c6fd7b3d2f2f0986f2ff6df", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-01-22T02:44:58.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-22T02:44:58.000Z", "avg_line_length": 20.1098901099, "max_line_length": 74, "alphanum_fraction": 0.4978142077, "num_tokens": 1458, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603709, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7512144003399952}} {"text": "! Flow field calculations have been intentionally left out to save development time.\n! The flow field can be calculated using the pure python version of floris \n\n! This implementation is fully smooth and differentiable with the exception of a \n! discontinuity at the hub of each turbine. The discontinuity only presents issues if\n! turbines are place within 1E-15 * rotor diameter of one another, which is extremely \n! unlikely during optimization if the user does not explicitly place them there.\n\n \nsubroutine Hermite_Spline(x, x0, x1, y0, dy0, y1, dy1, y)\n ! This function produces the y and dy values for a hermite cubic spline\n ! interpolating between two end points with known slopes\n !\n ! :param x: x position of output y\n ! :param x0: x position of upwind endpoint of spline\n ! :param x1: x position of downwind endpoint of spline\n ! :param y0: y position of upwind endpoint of spline\n ! :param dy0: slope at upwind endpoint of spline\n ! :param y1: y position of downwind endpoint of spline\n ! :param dy1: slope at downwind endpoint of spline\n !\n ! :return: y: y value of spline at location x\n \n implicit none\n \n ! define precision to be the standard for a double precision ! on local system\n integer, parameter :: dp = kind(0.d0)\n \n ! in\n real(dp), intent(in) :: x, x0, x1, y0, dy0, y1, dy1\n \n ! out\n real(dp), intent(out) :: y !, dy_dx\n \n ! local\n real(dp) :: c3, c2, c1, c0\n\n ! initialize coefficients for parametric cubic spline\n c3 = (2.0_dp*(y1))/(x0**3 - 3.0_dp*x0**2*x1 + 3.0_dp*x0*x1**2 - x1**3) - &\n (2.0_dp*(y0))/(x0**3 - 3.0_dp*x0**2*x1 + 3.0_dp*x0*x1**2 - x1**3) + &\n (dy0)/(x0**2 - 2.0_dp*x0*x1 + x1**2) + &\n (dy1)/(x0**2 - 2.0_dp*x0*x1 + x1**2)\n \n c2 = (3.0_dp*(y0)*(x0 + x1))/(x0**3 - 3.0_dp*x0**2*x1 + 3.0_dp*x0*x1**2 - x1**3) - &\n ((dy1)*(2.0_dp*x0 + x1))/(x0**2 - 2.0_dp*x0*x1 + x1**2) - ((dy0)*(x0 + &\n 2.0_dp*x1))/(x0**2 - 2.0_dp*x0*x1 + x1**2) - (3.0_dp*(y1)*(x0 + x1))/(x0**3 - &\n 3.0_dp*x0**2*x1 + 3.0_dp*x0*x1**2 - x1**3)\n \n c1 = ((dy0)*(x1**2 + 2.0_dp*x0*x1))/(x0**2 - 2.0_dp*x0*x1 + x1**2) + ((dy1)*(x0**2 + &\n 2.0_dp*x1*x0))/(x0**2 - 2.0_dp*x0*x1 + x1**2) - (6.0_dp*x0*x1*(y0))/(x0**3 - &\n 3.0_dp*x0**2*x1 + 3.0_dp*x0*x1**2 - x1**3) + (6.0_dp*x0*x1*(y1))/(x0**3 - &\n 3.0_dp*x0**2*x1 + 3.0_dp*x0*x1**2 - x1**3)\n \n c0 = ((y0)*(- x1**3 + 3.0_dp*x0*x1**2))/(x0**3 - 3.0_dp*x0**2*x1 + 3.0_dp*x0*x1**2 - &\n x1**3) - ((y1)*(- x0**3 + 3.0_dp*x1*x0**2))/(x0**3 - 3.0_dp*x0**2*x1 + &\n 3.0_dp*x0*x1**2 - x1**3) - (x0*x1**2*(dy0))/(x0**2 - 2.0_dp*x0*x1 + x1**2) - &\n (x0**2*x1*(dy1))/(x0**2 - 2.0_dp*x0*x1 + x1**2)\n! print *, 'c3 = ', c3\n! print *, 'c2 = ', c2\n! print *, 'c1 = ', c1\n! print *, 'c0 = ', c0\n ! Solve for y and dy values at the given point\n y = c3*x**3 + c2*x**2 + c1*x + c0\n !dy_dx = c3*3*x**2 + c2*2*x + c1\n\nend subroutine Hermite_Spline\n\n\nsubroutine calcOverlapAreas(nTurbines, turbineX, turbineY, rotorDiameter, wakeDiameters, &\n wakeCenters, wakeOverlapTRel_mat)\n! calculate overlap of rotors and wake zones (wake zone location defined by wake \n! center and wake diameter)\n! turbineX,turbineY is x,y-location of center of rotor\n!\n! wakeOverlap(TURBI,TURB,ZONEI) = overlap area of zone ZONEI of wake of turbine \n! TURB with rotor of downstream turbine\n! TURBI\n\n implicit none\n \n ! define precision to be the standard for a double precision ! on local system\n integer, parameter :: dp = kind(0.d0)\n \n ! in\n integer, intent(in) :: nTurbines\n real(dp), dimension(nTurbines), intent(in) :: turbineX, turbineY, rotorDiameter\n real(dp), dimension(nTurbines, nTurbines, 3), intent(in) :: wakeDiameters\n real(dp), dimension(nTurbines, nTurbines), intent(in) :: wakeCenters\n \n ! out \n real(dp), dimension(nTurbines, nTurbines, 3), intent(out) :: wakeOverlapTRel_mat\n \n ! local\n integer :: turb, turbI, zone\n real(dp), parameter :: pi = 3.141592653589793_dp, tol = 0.000001_dp\n real(dp) :: OVdYd, OVr, OVRR, OVL, OVz\n real(dp), dimension(nTurbines, nTurbines, 3) :: wakeOverlap\n \n wakeOverlapTRel_mat = 0.0_dp\n wakeOverlap = 0.0_dp\n \n do turb = 1, nTurbines\n do turbI = 1, nTurbines\n if (turbineX(turbI) > turbineX(turb)) then\n OVdYd = wakeCenters(turbI, turb)-turbineY(turbI) ! distance between wake center and rotor center\n OVr = rotorDiameter(turbI)/2 ! rotor diameter\n do zone = 1, 3\n OVRR = wakeDiameters(turbI, turb, zone)/2.0_dp ! wake diameter\n OVdYd = abs(OVdYd)\n if (OVdYd >= 0.0_dp + tol) then\n ! calculate the distance from the wake center to the vertical line between\n ! the two circle intersection points\n OVL = (-OVr*OVr+OVRR*OVRR+OVdYd*OVdYd)/(2.0_dp*OVdYd)\n else\n OVL = 0.0_dp\n end if\n\n OVz = OVRR*OVRR-OVL*OVL\n\n ! Finish calculating the distance from the intersection line to the outer edge of the wake zone\n if (OVz > 0.0_dp + tol) then\n OVz = sqrt(OVz)\n else\n OVz = 0.0_dp\n end if\n\n if (OVdYd < (OVr+OVRR)) then ! if the rotor overlaps the wake zone\n\n if (OVL < OVRR .and. (OVdYd-OVL) < OVr) then\n wakeOverlap(turbI, turb, zone) = OVRR*OVRR*dacos(OVL/OVRR) + OVr*OVr*dacos((OVdYd-OVL)/OVr) - OVdYd*OVz\n else if (OVRR > OVr) then\n wakeOverlap(turbI, turb, zone) = pi*OVr*OVr\n else\n wakeOverlap(turbI, turb, zone) = pi*OVRR*OVRR\n end if\n else\n wakeOverlap(turbI, turb, zone) = 0.0_dp\n end if\n \n end do\n \n end if\n \n end do\n \n end do\n\n\n do turb = 1, nTurbines\n \n do turbI = 1, nTurbines\n \n wakeOverlap(turbI, turb, 3) = wakeOverlap(turbI, turb, 3)-wakeOverlap(turbI, turb, 2)\n wakeOverlap(turbI, turb, 2) = wakeOverlap(turbI, turb, 2)-wakeOverlap(turbI, turb, 1)\n \n end do\n \n end do\n \n wakeOverlapTRel_mat = wakeOverlap\n\n do turbI = 1, nTurbines\n wakeOverlapTRel_mat(turbI, :, :) = wakeOverlapTRel_mat(turbI, :, &\n :)/((pi*rotorDiameter(turbI) &\n *rotorDiameter(turbI))/4.0_dp)\n end do\n \n ! do turbI = 1, nTurbines\n! do turb = 1, nTurbines\n! do zone = 1, 3\n! print *, \"wakeOverlapTRel_mat[\", turbI, \", \", turb, \", \", zone, \"] = \", wakeOverlapTRel_mat(turbI, turb, zone)\n! end do\n! end do\n! end do\n \n \n \nend subroutine calcOverlapAreas\n\n\nsubroutine CTtoAxialInd(CT, nTurbines, axial_induction)\n \n implicit none\n \n ! define precision to be the standard for a double precision ! on local system\n integer, parameter :: dp = kind(0.d0)\n\n ! in\n integer, intent(in) :: nTurbines\n real(dp), dimension(nTurbines), intent(in) :: CT\n\n ! local\n integer :: i\n\n ! out\n real(dp), dimension(nTurbines), intent(out) :: axial_induction\n\n axial_induction = 0.0_dp\n\n ! execute\n do i = 1, nTurbines\n if (CT(i) > 0.96) then ! Glauert condition\n axial_induction(i) = 0.143_dp + sqrt(0.0203_dp-0.6427_dp*(0.889_dp - CT(i)))\n else\n axial_induction(i) = 0.5_dp*(1.0_dp-sqrt(1.0_dp-CT(i)))\n end if\n end do\n \nend subroutine CTtoAxialInd\n \n\nsubroutine floris_unified(nTurbines, turbineXw, turbineYw, yaw_deg, rotorDiameter, Vinf, &\n & Ct, a_in, ke_in, kd, me, initialWakeDisplacement, bd, MU, &\n & aU, bU, initialWakeAngle, cos_spread, keCorrCT, Region2CT, &\n & keCorrArray, useWakeAngle, adjustInitialWakeDiamToYaw, & \n & axialIndProvided, useaUbU, velocitiesTurbines, &\n & wakeCentersYT_vec, wakeDiametersT_vec, wakeOverlapTRel_vec)\n \n ! independent variables: yaw_deg Ct turbineXw turbineYw rotorDiameter a_in \n ! dependent variables: velocitiesTurbines\n \n implicit none\n \n ! define precision to be the standard for a double precision ! on local system\n integer, parameter :: dp = kind(0.d0)\n \n ! in\n integer, intent(in) :: nTurbines\n real(dp), intent(in) :: kd, initialWakeDisplacement, initialWakeAngle, ke_in\n real(dp), intent(in) :: keCorrCT, Region2CT, bd, cos_spread, Vinf, keCorrArray\n real(dp), dimension(nTurbines), intent(in) :: yaw_deg, Ct, a_in, turbineXw, turbineYw\n real(dp), dimension(nTurbines), intent(in) :: rotorDiameter\n real(dp), dimension(3), intent(in) :: me, MU\n real(dp), intent(in) :: aU, bU\n logical, intent(in) :: useWakeAngle, adjustInitialWakeDiamToYaw, axialIndProvided, &\n & useaUbU\n \n ! local (General)\n real(dp), dimension(nTurbines) :: ke, yaw\n real(dp) :: deltax\n Integer :: turb, turbI, zone \n real(dp), parameter :: pi = 3.141592653589793_dp\n \n ! local (Wake centers and diameters)\n real(dp) :: spline_bound ! in rotor diameters \n real(dp) :: wakeAngleInit, zeroloc\n real(dp) :: factor, displacement, x, x1, x2, y1, y2, dy1, dy2\n real(dp) :: wakeDiameter0\n real(dp), dimension(nTurbines, nTurbines, 3) :: wakeDiametersT_mat\n real(dp), dimension(nTurbines, nTurbines) :: wakeCentersYT_mat\n \n ! local (Wake overlap)\n real(dp) :: rmax\n real(dp), dimension(nTurbines, nTurbines, 3) :: wakeOverlapTRel_mat\n\n ! local (Velocity)\n real(dp), dimension(nTurbines) :: a, keArray\n real(dp), dimension(3) :: mmU\n real(dp) :: s, cosFac, wakeEffCoeff, wakeEffCoeffPerZone\n \n ! out\n real(dp), dimension(nTurbines), intent(out) :: velocitiesTurbines\n real(dp), dimension(nTurbines*nTurbines), intent(out) :: wakeCentersYT_vec\n real(dp), dimension(3*nTurbines*nTurbines), intent(out) :: wakeDiametersT_vec \n real(dp), dimension(3*nTurbines*nTurbines), intent(out) :: wakeOverlapTRel_vec\n \n intrinsic cos\n \n !!!!!!!!!!!!!!!!!!!!!!!!!!!! Wake Centers and Diameters !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n spline_bound = 1.0_dp\n \n yaw = yaw_deg*pi/180.0_dp\n \n ! calculate y-locations of wake centers in wind ref. frame\n wakeCentersYT_mat = 0.0_dp\n \n do turb = 1, nTurbines\n wakeAngleInit = 0.5_dp*sin(yaw(turb))*Ct(turb)\n \n if (useWakeAngle) then\n wakeAngleInit = wakeAngleInit + initialWakeAngle*pi/180.0_dp\n end if\n \n do turbI = 1, nTurbines \n \n if (turbineXw(turb) < turbineXw(turbI)) then\n deltax = turbineXw(turbI) - turbineXw(turb)\n factor = (2.0_dp*kd*deltax/rotorDiameter(turb)) + 1.0_dp\n wakeCentersYT_mat(turbI, turb) = turbineYw(turb)\n \n displacement = wakeAngleInit*(wakeAngleInit* &\n & wakeAngleInit + 15.0_dp*factor*factor* &\n factor*factor)/((30.0_dp*kd/ & \n rotorDiameter(turb))*(factor*factor* &\n & factor*factor*factor))\n \n displacement = displacement - &\n & wakeAngleInit*(wakeAngleInit* &\n & wakeAngleInit + 15.0_dp)/(30.0_dp*kd/ &\n rotorDiameter(turb))\n\n wakeCentersYT_mat(turbI, turb) = wakeCentersYT_mat(turbI, turb)+ &\n & initialWakeDisplacement + displacement\n \n if (useWakeAngle .eqv. .false.) then\n wakeCentersYT_mat(turbI, turb) = wakeCentersYT_mat(turbI, turb) + bd*(deltax)\n end if\n \n end if\n\n end do\n \n end do\n \n !adjust k_e to C_T, adjusted to yaw\n ke = ke_in + keCorrCT*(Ct-Region2CT)\n \n wakeDiametersT_mat = 0.0_dp\n\n do turb = 1, nTurbines\n \n if (adjustInitialWakeDiamToYaw) then\n wakeDiameter0 = rotorDiameter(turb)*cos(yaw(turb))\n else\n wakeDiameter0 = rotorDiameter(turb) \n end if\n \n do turbI = 1, nTurbines\n \n ! turbine separation\n deltax = turbineXw(turbI) - turbineXw(turb) \n \n ! x position of interest\n x = turbineXw(turbI) \n \n zone = 1\n ! define centerpoint of spline\n zeroloc = turbineXw(turb) - wakeDiameter0/(2.0_dp*ke(turb)*me(zone))\n \n if (zeroloc + spline_bound*rotorDiameter(turb) < turbineXw(turbI)) then ! check this\n wakeDiametersT_mat(turbI, turb, zone) = 0.0_dp\n \n else if (zeroloc - spline_bound*rotorDiameter(turb) < turbineXw(turbI)) then !check this\n \n !!!!!!!!!!!!!!!!!!!!!! calculate spline values !!!!!!!!!!!!!!!!!!!!!!!!!!\n \n ! position of upwind point\n x1 = zeroloc - spline_bound*rotorDiameter(turb)\n \n ! diameter of upwind point\n y1 = wakeDiameter0+2.0_dp*ke(turb)*me(zone)*(x1 - turbineXw(turb))\n \n ! slope at upwind point\n dy1 = 2.0_dp*ke(turb)*me(zone)\n \n ! position of downwind point\n x2 = zeroloc+spline_bound*rotorDiameter(turb) \n\n ! diameter at downwind point\n y2 = 0.0_dp\n \n ! slope at downwind point\n dy2 = 0.0_dp\n \n ! solve for the wake zone diameter and its derivative w.r.t. the downwind\n ! location at the point of interest\n call Hermite_Spline(x, x1, x2, y1, dy1, y2, dy2, wakeDiametersT_mat(turbI, turb, zone))\n \n else if (turbineXw(turb) < turbineXw(turbI)) then\n wakeDiametersT_mat(turbI, turb, zone) = wakeDiameter0+2.0_dp*ke(turb)*me(zone)*deltax \n end if\n \n \n if (turbineXw(turb) < turbineXw(turbI)) then\n zone = 2\n wakeDiametersT_mat(turbI, turb, zone) = wakeDiameter0 + 2.0_dp*ke(turb)*me(zone)*deltax \n zone = 3\n wakeDiametersT_mat(turbI, turb, zone) = wakeDiameter0+2.0_dp*ke(turb)*me(zone)*deltax\n end if \n \n end do\n \n end do\n \n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Wake Overlap !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n \n ! calculate relative overlap\n call calcOverlapAreas(nTurbines, turbineXw, turbineYw, rotorDiameter, &\n & wakeDiametersT_mat, wakeCentersYT_mat, wakeOverlapTRel_mat)\n! \n! ! calculate cosine factor TODO: put this into the same loop as velocity\n! do turbI = 1, nTurbines\n! do turb = 1, nTurbines\n! if (turbineXw(turb) < turbineXw(turbI)) then\n! do zone = 1, 3\n! rmax = cos_spread*0.5_dp*(wakeDiametersT_mat(turbI, turb, 3) + rotorDiameter(turbI))\n! cosFac_mat(turbI, turb, zone) = 0.5_dp*(1.0_dp + cos(pi*dabs( &\n! wakeCentersYT_mat(turbI, turb)-turbineYw(turbI))/rmax))\n! !cosFac_mat(turbI, turb, zone) = 1.0_dp\n! \n! end do\n! else\n! cosFac_mat(turbI, turb, :) = 1.0_dp \n! end if \n! end do\n! end do\n \n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Velocity !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n \n ! convert yaw from degrees to radians\n yaw = yaw_deg*pi/180.0_dp\n\n if (axialIndProvided) then\n a = a_in\n else\n call CTtoAxialInd(Ct, nTurbines, a)\n end if\n \n ! adjust ke to Ct as adjusted to yaw\n ke = ke_in + keCorrCT*(Ct-Region2CT)\n\n do turb = 1, nTurbines\n s = sum(wakeOverlapTRel_mat(turb, :, 1) + wakeOverlapTRel_mat(turb, :, 2))\n keArray(turb) = ke(turb)*(1+s*keCorrArray) \n end do\n \n ! find effective wind speeds at downstream turbines, then predict the power of \n ! downstream turbine \n velocitiesTurbines = Vinf\n do turbI = 1, nTurbines\n wakeEffCoeff = 0.0_dp\n \n ! find overlap-area weighted effect of each wake zone\n do turb = 1, nTurbines\n wakeEffCoeffPerZone = 0.0_dp\n deltax = turbineXw(turbI) - turbineXw(turb)\n \n if (useaUbU) then\n mmU = MU/cos(aU*pi/180.0_dp + bU*yaw(turb))\n end if\n \n if (deltax > 0 .and. turbI /= turb) then\n do zone = 1, 3\n \n rmax = cos_spread*0.5_dp*(wakeDiametersT_mat(turbI, turb, 3) + rotorDiameter(turbI))\n cosFac = 0.5_dp*(1.0_dp + cos(pi*dabs(wakeCentersYT_mat(turbI, turb) &\n & - turbineYw(turbI))/rmax))\n \n if (useaUbU) then\n wakeEffCoeffPerZone = wakeEffCoeffPerZone + &\n (((cosFac*rotorDiameter(turb))/(rotorDiameter(turb)+2.0_dp*keArray(turb) &\n *mmU(zone)*deltax))**2)*wakeOverlapTRel_mat(turbI, turb, zone) \n else\n wakeEffCoeffPerZone = wakeEffCoeffPerZone + &\n (((cosFac*rotorDiameter(turb))/(rotorDiameter(turb)+2.0_dp*keArray(turb) &\n *MU(zone)*deltax))**2)*wakeOverlapTRel_mat(turbI, turb, zone) \n end if \n \n end do\n wakeEffCoeff = wakeEffCoeff + (a(turb)*wakeEffCoeffPerZone)**2\n end if\n end do\n wakeEffCoeff = 1.0_dp - 2.0_dp*sqrt(wakeEffCoeff)\n \n ! multiply the inflow speed with the wake coefficients to find effective wind \n ! speed at turbine\n velocitiesTurbines(turbI) = velocitiesTurbines(turbI)*wakeEffCoeff\n end do\n \n ! pack desired matrices into vectors for output\n do turbI = 1, nTurbines\n ! wake centers\n wakeCentersYT_vec(nTurbines*(turbI-1)+1:nTurbines*(turbI-1)+nTurbines) &\n = wakeCentersYT_mat(turbI, :)\n \n ! wake diameters\n wakeDiametersT_vec(3*nTurbines*(turbI-1)+1:3*nTurbines*(turbI-1)+nTurbines) &\n = wakeDiametersT_mat(turbI, :, 1)\n wakeDiametersT_vec(3*nTurbines*(turbI-1)+nTurbines+1:3*nTurbines*(turbI-1) &\n +2*nTurbines) = wakeDiametersT_mat(turbI, :, 2)\n wakeDiametersT_vec(3*nTurbines*(turbI-1)+2*nTurbines+1:nTurbines*(turbI-1) &\n +3*nTurbines) = wakeDiametersT_mat(turbI, :, 3) \n \n ! relative wake overlap\n wakeOverlapTRel_vec(3*nTurbines*(turbI-1)+1:3*nTurbines*(turbI-1)+nTurbines) &\n = wakeOverlapTRel_mat(turbI, :, 1)\n wakeOverlapTRel_vec(3*nTurbines*(turbI-1)+nTurbines+1:3*nTurbines*(turbI-1) &\n +2*nTurbines) = wakeOverlapTRel_mat(turbI, :, 2)\n wakeOverlapTRel_vec(3*nTurbines*(turbI-1)+2*nTurbines+1:3*nTurbines*(turbI-1) &\n +3*nTurbines) = wakeOverlapTRel_mat(turbI, :, 3)\n \n \n end do\n \nend subroutine floris_unified\n\n\n\n\n! Generated by TAPENADE (INRIA, Ecuador team)\n! Tapenade 3.11 (r5902M) - 15 Dec 2015 09:00\n!\n! Differentiation of floris_unified in reverse (adjoint) mode:\n! gradient of useful results: velocitiesturbines\n! with respect to varying inputs: rotordiameter turbinexw yaw_deg\n! velocitiesturbines turbineyw ct a_in\n! RW status of diff variables: rotordiameter:out turbinexw:out\n! yaw_deg:out velocitiesturbines:in-zero turbineyw:out\n! ct:out a_in:out\nSUBROUTINE FLORIS_UNIFIED_BV(nturbines, turbinexw, turbinexwb, turbineyw&\n& , turbineywb, yaw_deg, yaw_degb, rotordiameter, rotordiameterb, vinf, &\n& ct, ctb, a_in, a_inb, ke_in, kd, me, initialwakedisplacement, bd, mu, &\n& au, bu, initialwakeangle, cos_spread, kecorrct, region2ct, kecorrarray&\n& , usewakeangle, adjustinitialwakediamtoyaw, axialindprovided, useaubu&\n& , velocitiesturbinesb, nbdirs)\n \n! Hint: nbdirs should be the maximum number of differentiation directions\n IMPLICIT NONE\n! define precision to be the standard for a double precision ! on local system\n INTEGER, PARAMETER :: dp=KIND(0.d0)\n! in\n INTEGER, INTENT(IN) :: nturbines\n REAL(dp), INTENT(IN) :: kd, initialwakedisplacement, initialwakeangle&\n& , ke_in\n REAL(dp), INTENT(IN) :: kecorrct, region2ct, bd, cos_spread, vinf, &\n& kecorrarray\n REAL(dp), DIMENSION(nturbines), INTENT(IN) :: yaw_deg, ct, a_in, &\n& turbinexw, turbineyw\n REAL(dp), DIMENSION(nbdirs, nturbines), intent(out) :: yaw_degb, ctb, a_inb, &\n& turbinexwb, turbineywb\n REAL(dp), DIMENSION(nturbines), INTENT(IN) :: rotordiameter\n REAL(dp), DIMENSION(nbdirs, nturbines), intent(out) :: rotordiameterb\n REAL(dp), DIMENSION(3), INTENT(IN) :: me, mu\n REAL(dp), INTENT(IN) :: au, bu\n LOGICAL, INTENT(IN) :: usewakeangle, adjustinitialwakediamtoyaw, &\n& axialindprovided, useaubu\n! local (General)\n REAL(dp), DIMENSION(nturbines) :: ke, yaw\n REAL(dp), DIMENSION(nbdirs, nturbines) :: keb, yawb\n REAL(dp) :: deltax\n REAL(dp), DIMENSION(nbdirs) :: deltaxb\n INTEGER :: turb, turbi, zone\n REAL(dp), PARAMETER :: pi=3.141592653589793_dp\n! local (Wake centers and diameters)\n! in rotor diameters \n REAL(dp) :: spline_bound\n REAL(dp) :: wakeangleinit, zeroloc\n REAL(dp), DIMENSION(nbdirs) :: wakeangleinitb, zerolocb\n REAL(dp) :: factor, displacement, x, x1, x2, y1, y2, dy1, dy2\n REAL(dp), DIMENSION(nbdirs) :: factorb, displacementb, xb, x1b, x2b&\n& , y1b, dy1b\n REAL(dp) :: wakediameter0\n REAL(dp), DIMENSION(nbdirs) :: wakediameter0b\n REAL(dp), DIMENSION(nturbines, nturbines, 3) :: wakediameterst_mat\n REAL(dp), DIMENSION(nbdirs, nturbines, nturbines, 3) :: &\n& wakediameterst_matb\n REAL(dp), DIMENSION(nturbines, nturbines) :: wakecentersyt_mat\n REAL(dp), DIMENSION(nbdirs, nturbines, nturbines) :: &\n& wakecentersyt_matb\n! local (Wake overlap)\n REAL(dp) :: rmax\n REAL(dp), DIMENSION(nbdirs) :: rmaxb\n REAL(dp), DIMENSION(nturbines, nturbines, 3) :: wakeoverlaptrel_mat\n REAL(dp), DIMENSION(nbdirs, nturbines, nturbines, 3) :: &\n& wakeoverlaptrel_matb\n! local (Velocity)\n REAL(dp), DIMENSION(nturbines) :: a, kearray\n REAL(dp), DIMENSION(nbdirs, nturbines) :: ab, kearrayb\n REAL(dp), DIMENSION(3) :: mmu\n REAL(dp), DIMENSION(nbdirs, 3) :: mmub\n REAL(dp) :: s, cosfac, wakeeffcoeff, wakeeffcoeffperzone\n REAL(dp), DIMENSION(nbdirs) :: sb, cosfacb, wakeeffcoeffb, &\n& wakeeffcoeffperzoneb\n! out\n REAL(dp), DIMENSION(nturbines) :: velocitiesturbines\n REAL(dp), DIMENSION(nbdirs, nturbines) :: velocitiesturbinesb\n REAL(dp), DIMENSION(nturbines*nturbines) :: &\n& wakecentersyt_vec\n REAL(dp), DIMENSION(3*nturbines*nturbines) :: &\n& wakediameterst_vec\n REAL(dp), DIMENSION(3*nturbines*nturbines) :: &\n& wakeoverlaptrel_vec\n INTRINSIC COS\n INTRINSIC KIND\n INTRINSIC SIN\n INTRINSIC SUM\n INTRINSIC DABS\n INTRINSIC SQRT\n INTEGER :: nd\n INTEGER :: branch\n INTEGER :: nbdirs\n REAL(dp) :: temp3\n REAL(dp) :: temp2\n REAL(dp) :: temp1\n REAL(dp) :: temp0\n REAL(dp) :: tempb9(nbdirs)\n REAL(dp) :: tempb8(nbdirs)\n REAL :: tempb7(nbdirs)\n REAL(dp) :: tempb6(nbdirs)\n REAL(dp) :: tempb5(nbdirs)\n REAL(dp) :: tempb4(nbdirs)\n REAL(dp) :: tempb3(nbdirs)\n REAL(dp) :: tempb2(nbdirs)\n REAL(dp) :: tempb1(nbdirs)\n REAL(dp) :: tempb0(nbdirs)\n REAL(dp) :: tempb13(nbdirs)\n REAL(dp) :: tempb12(nbdirs)\n REAL(dp) :: tempb11(nbdirs)\n REAL(dp) :: tempb10(nbdirs)\n DOUBLE PRECISION :: dabs0b(nbdirs)\n REAL(dp) :: temp11\n REAL(dp) :: temp10\n REAL(dp) :: tempb(nbdirs)\n DOUBLE PRECISION :: dabs0\n REAL(dp) :: temp\n REAL(dp) :: temp9\n REAL(dp) :: temp8\n REAL(dp) :: temp7\n REAL(dp) :: temp6\n REAL(dp) :: temp5\n REAL(dp) :: temp4\n!!!!!!!!!!!!!!!!!!!!!!!!!!!! Wake Centers and Diameters !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n spline_bound = 1.0_dp\n yaw = yaw_deg*pi/180.0_dp\n! calculate y-locations of wake centers in wind ref. frame\n wakecentersyt_mat = 0.0_dp\n DO turb=1,nturbines\n CALL PUSHREAL4ARRAY(wakeangleinit, dp/4)\n wakeangleinit = 0.5_dp*SIN(yaw(turb))*ct(turb)\n IF (usewakeangle) wakeangleinit = wakeangleinit + initialwakeangle*&\n& pi/180.0_dp\n DO turbi=1,nturbines\n IF (turbinexw(turb) .LT. turbinexw(turbi)) THEN\n CALL PUSHREAL4ARRAY(deltax, dp/4)\n deltax = turbinexw(turbi) - turbinexw(turb)\n factor = 2.0_dp*kd*deltax/rotordiameter(turb) + 1.0_dp\n wakecentersyt_mat(turbi, turb) = turbineyw(turb)\n displacement = wakeangleinit*(wakeangleinit*wakeangleinit+&\n& 15.0_dp*factor*factor*factor*factor)/(30.0_dp*kd/rotordiameter&\n& (turb)*(factor*factor*factor*factor*factor))\n displacement = displacement - wakeangleinit*(wakeangleinit*&\n& wakeangleinit+15.0_dp)/(30.0_dp*kd/rotordiameter(turb))\n wakecentersyt_mat(turbi, turb) = wakecentersyt_mat(turbi, turb) &\n& + initialwakedisplacement + displacement\n IF (usewakeangle .EQV. .false.) THEN\n wakecentersyt_mat(turbi, turb) = wakecentersyt_mat(turbi, turb&\n& ) + bd*deltax\n CALL PUSHCONTROL2B(2)\n ELSE\n CALL PUSHCONTROL2B(1)\n END IF\n ELSE\n CALL PUSHCONTROL2B(0)\n END IF\n END DO\n END DO\n!adjust k_e to C_T, adjusted to yaw\n ke = ke_in + kecorrct*(ct-region2ct)\n wakediameterst_mat = 0.0_dp\n DO turb=1,nturbines\n IF (adjustinitialwakediamtoyaw) THEN\n CALL PUSHREAL4ARRAY(wakediameter0, dp/4)\n wakediameter0 = rotordiameter(turb)*COS(yaw(turb))\n CALL PUSHCONTROL1B(1)\n ELSE\n CALL PUSHREAL4ARRAY(wakediameter0, dp/4)\n wakediameter0 = rotordiameter(turb)\n CALL PUSHCONTROL1B(0)\n END IF\n DO turbi=1,nturbines\n! turbine separation\n CALL PUSHREAL4ARRAY(deltax, dp/4)\n deltax = turbinexw(turbi) - turbinexw(turb)\n! x position of interest\n x = turbinexw(turbi)\n CALL PUSHINTEGER4(zone)\n zone = 1\n! define centerpoint of spline\n zeroloc = turbinexw(turb) - wakediameter0/(2.0_dp*ke(turb)*me(zone&\n& ))\n IF (zeroloc + spline_bound*rotordiameter(turb) .LT. turbinexw(&\n& turbi)) THEN\n! check this\n wakediameterst_mat(turbi, turb, zone) = 0.0_dp\n CALL PUSHCONTROL2B(0)\n ELSE IF (zeroloc - spline_bound*rotordiameter(turb) .LT. turbinexw&\n& (turbi)) THEN\n!check this\n!!!!!!!!!!!!!!!!!!!!!! calculate spline values !!!!!!!!!!!!!!!!!!!!!!!!!!\n! position of upwind point\n x1 = zeroloc - spline_bound*rotordiameter(turb)\n! diameter of upwind point\n y1 = wakediameter0 + 2.0_dp*ke(turb)*me(zone)*(x1-turbinexw(turb&\n& ))\n! slope at upwind point\n dy1 = 2.0_dp*ke(turb)*me(zone)\n! position of downwind point\n x2 = zeroloc + spline_bound*rotordiameter(turb)\n! diameter at downwind point\n y2 = 0.0_dp\n! slope at downwind point\n dy2 = 0.0_dp\n! solve for the wake zone diameter and its derivative w.r.t. the downwind\n! location at the point of interest\n CALL HERMITE_SPLINE(x, x1, x2, y1, dy1, y2, dy2, &\n& wakediameterst_mat(turbi, turb, zone))\n CALL PUSHCONTROL2B(1)\n ELSE IF (turbinexw(turb) .LT. turbinexw(turbi)) THEN\n wakediameterst_mat(turbi, turb, zone) = wakediameter0 + 2.0_dp*&\n& ke(turb)*me(zone)*deltax\n CALL PUSHCONTROL2B(2)\n ELSE\n CALL PUSHCONTROL2B(3)\n END IF\n IF (turbinexw(turb) .LT. turbinexw(turbi)) THEN\n CALL PUSHINTEGER4(zone)\n zone = 2\n wakediameterst_mat(turbi, turb, zone) = wakediameter0 + 2.0_dp*&\n& ke(turb)*me(zone)*deltax\n zone = 3\n wakediameterst_mat(turbi, turb, zone) = wakediameter0 + 2.0_dp*&\n& ke(turb)*me(zone)*deltax\n CALL PUSHCONTROL1B(1)\n ELSE\n CALL PUSHCONTROL1B(0)\n END IF\n END DO\n END DO\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Wake Overlap !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! calculate relative overlap\n CALL CALCOVERLAPAREAS(nturbines, turbinexw, turbineyw, rotordiameter, &\n& wakediameterst_mat, wakecentersyt_mat, &\n& wakeoverlaptrel_mat)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Velocity !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! convert yaw from degrees to radians\n CALL PUSHREAL4ARRAY(yaw, dp*nturbines/4)\n yaw = yaw_deg*pi/180.0_dp\n IF (axialindprovided) THEN\n a = a_in\n CALL PUSHCONTROL1B(0)\n ELSE\n CALL CTTOAXIALIND(ct, nturbines, a)\n CALL PUSHCONTROL1B(1)\n END IF\n! adjust ke to Ct as adjusted to yaw\n ke = ke_in + kecorrct*(ct-region2ct)\n DO turb=1,nturbines\n CALL PUSHREAL4ARRAY(s, dp/4)\n s = SUM(wakeoverlaptrel_mat(turb, :, 1) + wakeoverlaptrel_mat(turb, &\n& :, 2))\n kearray(turb) = ke(turb)*(1+s*kecorrarray)\n END DO\n! find effective wind speeds at downstream turbines, then predict the power of \n! downstream turbine \n velocitiesturbines = vinf\n DO turbi=1,nturbines\n CALL PUSHREAL4ARRAY(wakeeffcoeff, dp/4)\n wakeeffcoeff = 0.0_dp\n! find overlap-area weighted effect of each wake zone\n DO turb=1,nturbines\n CALL PUSHREAL4ARRAY(wakeeffcoeffperzone, dp/4)\n wakeeffcoeffperzone = 0.0_dp\n CALL PUSHREAL4ARRAY(deltax, dp/4)\n deltax = turbinexw(turbi) - turbinexw(turb)\n IF (useaubu) THEN\n CALL PUSHREAL4ARRAY(mmu, dp*3/4)\n mmu = mu/COS(au*pi/180.0_dp+bu*yaw(turb))\n CALL PUSHCONTROL1B(0)\n ELSE\n CALL PUSHCONTROL1B(1)\n END IF\n IF (deltax .GT. 0 .AND. turbi .NE. turb) THEN\n CALL PUSHINTEGER4(zone)\n DO zone=1,3\n rmax = cos_spread*0.5_dp*(wakediameterst_mat(turbi, turb, 3)+&\n& rotordiameter(turbi))\n IF (wakecentersyt_mat(turbi, turb) - turbineyw(turbi) .GE. 0.&\n& ) THEN\n CALL PUSHREAL8(dabs0)\n dabs0 = wakecentersyt_mat(turbi, turb) - turbineyw(turbi)\n CALL PUSHCONTROL1B(0)\n ELSE\n CALL PUSHREAL8(dabs0)\n dabs0 = -(wakecentersyt_mat(turbi, turb)-turbineyw(turbi))\n CALL PUSHCONTROL1B(1)\n END IF\n CALL PUSHREAL4ARRAY(cosfac, dp/4)\n cosfac = 0.5_dp*(1.0_dp+COS(pi*dabs0/rmax))\n IF (useaubu) THEN\n wakeeffcoeffperzone = wakeeffcoeffperzone + (cosfac*&\n& rotordiameter(turb)/(rotordiameter(turb)+2.0_dp*kearray(&\n& turb)*mmu(zone)*deltax))**2*wakeoverlaptrel_mat(turbi, &\n& turb, zone)\n CALL PUSHCONTROL1B(1)\n ELSE\n wakeeffcoeffperzone = wakeeffcoeffperzone + (cosfac*&\n& rotordiameter(turb)/(rotordiameter(turb)+2.0_dp*kearray(&\n& turb)*mu(zone)*deltax))**2*wakeoverlaptrel_mat(turbi, turb&\n& , zone)\n CALL PUSHCONTROL1B(0)\n END IF\n END DO\n wakeeffcoeff = wakeeffcoeff + (a(turb)*wakeeffcoeffperzone)**2\n CALL PUSHCONTROL1B(1)\n ELSE\n CALL PUSHCONTROL1B(0)\n END IF\n END DO\n CALL PUSHREAL4ARRAY(wakeeffcoeff, dp/4)\n wakeeffcoeff = 1.0_dp - 2.0_dp*SQRT(wakeeffcoeff)\n! multiply the inflow speed with the wake coefficients to find effective wind \n! speed at turbine\n END DO\n DO nd=1,nbdirs\n rotordiameterb(nd, :) = 0.0\n turbinexwb(nd, :) = 0.0\n turbineywb(nd, :) = 0.0\n kearrayb(nd, :) = 0.0\n yawb(nd, :) = 0.0\n wakeoverlaptrel_matb(nd, :, :, :) = 0.0\n wakediameterst_matb(nd, :, :, :) = 0.0\n wakecentersyt_matb(nd, :, :) = 0.0\n mmub(nd, :) = 0.0\n ab(nd, :) = 0.0\n END DO\n DO turbi=nturbines,1,-1\n DO nd=1,nbdirs\n wakeeffcoeffb(nd) = velocitiesturbines(turbi)*velocitiesturbinesb(&\n& nd, turbi)\n velocitiesturbinesb(nd, turbi) = wakeeffcoeff*velocitiesturbinesb(&\n& nd, turbi)\n END DO\n CALL POPREAL4ARRAY(wakeeffcoeff, dp/4)\n DO nd=1,nbdirs\n IF (wakeeffcoeff .EQ. 0.0) THEN\n wakeeffcoeffb(nd) = 0.0\n ELSE\n wakeeffcoeffb(nd) = -(2.0_dp*wakeeffcoeffb(nd)/(2.0*SQRT(&\n& wakeeffcoeff)))\n END IF\n END DO\n DO turb=nturbines,1,-1\n CALL POPCONTROL1B(branch)\n IF (branch .EQ. 0) THEN\n DO nd=1,nbdirs\n deltaxb(nd) = 0.0\n END DO\n ELSE\n DO nd=1,nbdirs\n tempb13(nd) = 2*a(turb)*wakeeffcoeffperzone*wakeeffcoeffb(nd)\n ab(nd, turb) = ab(nd, turb) + wakeeffcoeffperzone*tempb13(nd)\n wakeeffcoeffperzoneb(nd) = a(turb)*tempb13(nd)\n END DO\n deltax = turbinexw(turbi) - turbinexw(turb)\n DO nd=1,nbdirs\n deltaxb(nd) = 0.0\n END DO\n DO zone=3,1,-1\n CALL POPCONTROL1B(branch)\n IF (branch .EQ. 0) THEN\n temp11 = 2.0_dp*mu(zone)\n temp8 = rotordiameter(turb) + temp11*kearray(turb)*deltax\n temp10 = wakeoverlaptrel_mat(turbi, turb, zone)\n temp9 = cosfac**2*rotordiameter(turb)**2\n DO nd=1,nbdirs\n tempb11(nd) = wakeeffcoeffperzoneb(nd)/temp8**2\n tempb12(nd) = -(temp9*temp10*2*tempb11(nd)/temp8)\n cosfacb(nd) = rotordiameter(turb)**2*temp10*2*cosfac*&\n& tempb11(nd)\n rotordiameterb(nd, turb) = rotordiameterb(nd, turb) + &\n& tempb12(nd) + cosfac**2*temp10*2*rotordiameter(turb)*&\n& tempb11(nd)\n wakeoverlaptrel_matb(nd, turbi, turb, zone) = &\n& wakeoverlaptrel_matb(nd, turbi, turb, zone) + temp9*&\n& tempb11(nd)\n kearrayb(nd, turb) = kearrayb(nd, turb) + temp11*deltax*&\n& tempb12(nd)\n deltaxb(nd) = deltaxb(nd) + temp11*kearray(turb)*tempb12(&\n& nd)\n END DO\n ELSE\n temp5 = rotordiameter(turb) + 2.0_dp*kearray(turb)*deltax*&\n& mmu(zone)\n temp7 = wakeoverlaptrel_mat(turbi, turb, zone)\n temp6 = cosfac**2*rotordiameter(turb)**2\n DO nd=1,nbdirs\n tempb8(nd) = wakeeffcoeffperzoneb(nd)/temp5**2\n tempb9(nd) = -(temp6*temp7*2*tempb8(nd)/temp5)\n tempb10(nd) = 2.0_dp*mmu(zone)*tempb9(nd)\n cosfacb(nd) = rotordiameter(turb)**2*temp7*2*cosfac*tempb8&\n& (nd)\n rotordiameterb(nd, turb) = rotordiameterb(nd, turb) + &\n& tempb9(nd) + cosfac**2*temp7*2*rotordiameter(turb)*&\n& tempb8(nd)\n wakeoverlaptrel_matb(nd, turbi, turb, zone) = &\n& wakeoverlaptrel_matb(nd, turbi, turb, zone) + temp6*&\n& tempb8(nd)\n kearrayb(nd, turb) = kearrayb(nd, turb) + deltax*tempb10(&\n& nd)\n deltaxb(nd) = deltaxb(nd) + kearray(turb)*tempb10(nd)\n mmub(nd, zone) = mmub(nd, zone) + 2.0_dp*kearray(turb)*&\n& deltax*tempb9(nd)\n END DO\n END IF\n rmax = cos_spread*0.5_dp*(wakediameterst_mat(turbi, turb, 3)+&\n& rotordiameter(turbi))\n CALL POPREAL4ARRAY(cosfac, dp/4)\n DO nd=1,nbdirs\n tempb7(nd) = -(pi*SIN(pi*(dabs0/rmax))*0.5_dp*cosfacb(nd)/&\n& rmax)\n dabs0b(nd) = tempb7(nd)\n rmaxb(nd) = -(dabs0*tempb7(nd)/rmax)\n END DO\n CALL POPCONTROL1B(branch)\n IF (branch .EQ. 0) THEN\n CALL POPREAL8(dabs0)\n DO nd=1,nbdirs\n wakecentersyt_matb(nd, turbi, turb) = wakecentersyt_matb(&\n& nd, turbi, turb) + dabs0b(nd)\n turbineywb(nd, turbi) = turbineywb(nd, turbi) - dabs0b(nd)\n END DO\n ELSE\n CALL POPREAL8(dabs0)\n DO nd=1,nbdirs\n turbineywb(nd, turbi) = turbineywb(nd, turbi) + dabs0b(nd)\n wakecentersyt_matb(nd, turbi, turb) = wakecentersyt_matb(&\n& nd, turbi, turb) - dabs0b(nd)\n END DO\n END IF\n DO nd=1,nbdirs\n tempb6(nd) = cos_spread*0.5_dp*rmaxb(nd)\n wakediameterst_matb(nd, turbi, turb, 3) = &\n& wakediameterst_matb(nd, turbi, turb, 3) + tempb6(nd)\n rotordiameterb(nd, turbi) = rotordiameterb(nd, turbi) + &\n& tempb6(nd)\n END DO\n END DO\n CALL POPINTEGER4(zone)\n END IF\n CALL POPCONTROL1B(branch)\n IF (branch .EQ. 0) THEN\n CALL POPREAL4ARRAY(mmu, dp*3/4)\n temp4 = au*pi/180.0_dp + bu*yaw(turb)\n temp3 = COS(temp4)\n DO nd=1,nbdirs\n yawb(nd, turb) = yawb(nd, turb) - SIN(temp4)*bu*SUM(-(mu*mmub(&\n& nd, :)/temp3))/temp3\n END DO\n DO nd=1,nbdirs\n mmub(nd, :) = 0.0\n END DO\n END IF\n CALL POPREAL4ARRAY(deltax, dp/4)\n CALL POPREAL4ARRAY(wakeeffcoeffperzone, dp/4)\n DO nd=1,nbdirs\n turbinexwb(nd, turbi) = turbinexwb(nd, turbi) + deltaxb(nd)\n turbinexwb(nd, turb) = turbinexwb(nd, turb) - deltaxb(nd)\n END DO\n END DO\n CALL POPREAL4ARRAY(wakeeffcoeff, dp/4)\n END DO\n DO nd=1,nbdirs\n keb(nd, :) = 0.0\n END DO\n DO turb=nturbines,1,-1\n DO nd=1,nbdirs\n keb(nd, turb) = keb(nd, turb) + (kecorrarray*s+1)*kearrayb(nd, &\n& turb)\n sb(nd) = ke(turb)*kecorrarray*kearrayb(nd, turb)\n kearrayb(nd, turb) = 0.0\n wakeoverlaptrel_matb(nd, turb, :, 1) = wakeoverlaptrel_matb(nd, &\n& turb, :, 1) + sb(nd)\n wakeoverlaptrel_matb(nd, turb, :, 2) = wakeoverlaptrel_matb(nd, &\n& turb, :, 2) + sb(nd)\n END DO\n CALL POPREAL4ARRAY(s, dp/4)\n END DO\n DO nd=1,nbdirs\n ctb(nd, :) = 0.0\n ctb(nd, :) = kecorrct*keb(nd, :)\n END DO\n CALL POPCONTROL1B(branch)\n IF (branch .EQ. 0) THEN\n DO nd=1,nbdirs\n a_inb(nd, :) = 0.0\n a_inb(nd, :) = ab(nd, :)\n END DO\n ELSE\n CALL CTTOAXIALIND_BV(ct, ctb, nturbines, a, ab, nbdirs)\n DO nd=1,nbdirs\n a_inb(nd, :) = 0.0\n END DO\n END IF\n DO nd=1,nbdirs\n yaw_degb(nd, :) = 0.0\n yaw_degb(nd, :) = pi*yawb(nd, :)/180.0_dp\n END DO\n CALL POPREAL4ARRAY(yaw, dp*nturbines/4)\n CALL CALCOVERLAPAREAS_BV(nturbines, turbinexw, turbineyw, turbineywb, &\n& rotordiameter, rotordiameterb, wakediameterst_mat, &\n& wakediameterst_matb, wakecentersyt_mat, &\n& wakecentersyt_matb, wakeoverlaptrel_mat, &\n& wakeoverlaptrel_matb, nbdirs)\n ke = ke_in + kecorrct*(ct-region2ct)\n DO nd=1,nbdirs\n yawb(nd, :) = 0.0\n keb(nd, :) = 0.0\n END DO\n DO turb=nturbines,1,-1\n DO nd=1,nbdirs\n wakediameter0b(nd) = 0.0\n END DO\n DO turbi=nturbines,1,-1\n CALL POPCONTROL1B(branch)\n IF (branch .EQ. 0) THEN\n DO nd=1,nbdirs\n deltaxb(nd) = 0.0\n END DO\n ELSE\n deltax = turbinexw(turbi) - turbinexw(turb)\n zone = 3\n DO nd=1,nbdirs\n tempb4(nd) = me(zone)*2.0_dp*wakediameterst_matb(nd, turbi, &\n& turb, zone)\n wakediameter0b(nd) = wakediameter0b(nd) + wakediameterst_matb(&\n& nd, turbi, turb, zone)\n wakediameterst_matb(nd, turbi, turb, zone) = 0.0\n END DO\n zone = 2\n DO nd=1,nbdirs\n tempb5(nd) = me(zone)*2.0_dp*wakediameterst_matb(nd, turbi, &\n& turb, zone)\n keb(nd, turb) = keb(nd, turb) + deltax*tempb5(nd) + deltax*&\n& tempb4(nd)\n deltaxb(nd) = ke(turb)*tempb5(nd) + ke(turb)*tempb4(nd)\n wakediameter0b(nd) = wakediameter0b(nd) + wakediameterst_matb(&\n& nd, turbi, turb, zone)\n wakediameterst_matb(nd, turbi, turb, zone) = 0.0\n END DO\n CALL POPINTEGER4(zone)\n END IF\n CALL POPCONTROL2B(branch)\n IF (branch .LT. 2) THEN\n IF (branch .EQ. 0) THEN\n DO nd=1,nbdirs\n wakediameterst_matb(nd, turbi, turb, zone) = 0.0\n END DO\n DO nd=1,nbdirs\n xb(nd) = 0.0\n zerolocb(nd) = 0.0\n END DO\n ELSE\n zone = 1\n dy1 = 2.0_dp*ke(turb)*me(zone)\n zeroloc = turbinexw(turb) - wakediameter0/(2.0_dp*ke(turb)*me(&\n& zone))\n x1 = zeroloc - spline_bound*rotordiameter(turb)\n y1 = wakediameter0 + 2.0_dp*ke(turb)*me(zone)*(x1-turbinexw(&\n& turb))\n dy2 = 0.0_dp\n y2 = 0.0_dp\n x = turbinexw(turbi)\n x2 = zeroloc + spline_bound*rotordiameter(turb)\n CALL HERMITE_SPLINE_BV(x, xb, x1, x1b, x2, x2b, y1, y1b, dy1, &\n& dy1b, y2, dy2, wakediameterst_mat(turbi, turb&\n& , zone), wakediameterst_matb(1, turbi, turb, &\n& zone), nbdirs)\n DO nd=1,nbdirs\n tempb2(nd) = me(zone)*2.0_dp*y1b(nd)\n x1b(nd) = x1b(nd) + ke(turb)*tempb2(nd)\n wakediameterst_matb(nd, turbi, turb, zone) = 0.0\n zerolocb(nd) = x1b(nd) + x2b(nd)\n rotordiameterb(nd, turb) = rotordiameterb(nd, turb) + &\n& spline_bound*x2b(nd) - spline_bound*x1b(nd)\n keb(nd, turb) = keb(nd, turb) + (x1-turbinexw(turb))*tempb2(&\n& nd) + me(zone)*2.0_dp*dy1b(nd)\n wakediameter0b(nd) = wakediameter0b(nd) + y1b(nd)\n turbinexwb(nd, turb) = turbinexwb(nd, turb) - ke(turb)*&\n& tempb2(nd)\n END DO\n END IF\n ELSE\n IF (branch .EQ. 2) THEN\n DO nd=1,nbdirs\n tempb3(nd) = me(zone)*2.0_dp*wakediameterst_matb(nd, turbi, &\n& turb, zone)\n wakediameter0b(nd) = wakediameter0b(nd) + &\n& wakediameterst_matb(nd, turbi, turb, zone)\n keb(nd, turb) = keb(nd, turb) + deltax*tempb3(nd)\n deltaxb(nd) = deltaxb(nd) + ke(turb)*tempb3(nd)\n wakediameterst_matb(nd, turbi, turb, zone) = 0.0\n END DO\n END IF\n DO nd=1,nbdirs\n xb(nd) = 0.0\n zerolocb(nd) = 0.0\n END DO\n END IF\n temp2 = 2.0_dp*me(zone)*ke(turb)\n DO nd=1,nbdirs\n turbinexwb(nd, turb) = turbinexwb(nd, turb) + zerolocb(nd)\n wakediameter0b(nd) = wakediameter0b(nd) - zerolocb(nd)/temp2\n keb(nd, turb) = keb(nd, turb) + wakediameter0*2.0_dp*me(zone)*&\n& zerolocb(nd)/temp2**2\n turbinexwb(nd, turbi) = turbinexwb(nd, turbi) + deltaxb(nd) + xb&\n& (nd)\n turbinexwb(nd, turb) = turbinexwb(nd, turb) - deltaxb(nd)\n END DO\n CALL POPINTEGER4(zone)\n CALL POPREAL4ARRAY(deltax, dp/4)\n END DO\n CALL POPCONTROL1B(branch)\n IF (branch .EQ. 0) THEN\n CALL POPREAL4ARRAY(wakediameter0, dp/4)\n yaw = yaw_deg*pi/180.0_dp\n DO nd=1,nbdirs\n rotordiameterb(nd, turb) = rotordiameterb(nd, turb) + &\n& wakediameter0b(nd)\n END DO\n ELSE\n yaw = yaw_deg*pi/180.0_dp\n CALL POPREAL4ARRAY(wakediameter0, dp/4)\n DO nd=1,nbdirs\n rotordiameterb(nd, turb) = rotordiameterb(nd, turb) + COS(yaw(&\n& turb))*wakediameter0b(nd)\n yawb(nd, turb) = yawb(nd, turb) - rotordiameter(turb)*SIN(yaw(&\n& turb))*wakediameter0b(nd)\n END DO\n END IF\n END DO\n DO nd=1,nbdirs\n ctb(nd, :) = ctb(nd, :) + kecorrct*keb(nd, :)\n END DO\n DO turb=nturbines,1,-1\n DO nd=1,nbdirs\n wakeangleinitb(nd) = 0.0\n END DO\n DO turbi=nturbines,1,-1\n CALL POPCONTROL2B(branch)\n IF (branch .NE. 0) THEN\n IF (branch .EQ. 1) THEN\n DO nd=1,nbdirs\n deltaxb(nd) = 0.0\n END DO\n ELSE\n deltax = turbinexw(turbi) - turbinexw(turb)\n DO nd=1,nbdirs\n deltaxb(nd) = bd*wakecentersyt_matb(nd, turbi, turb)\n END DO\n END IF\n factor = 2.0_dp*kd*deltax/rotordiameter(turb) + 1.0_dp\n temp1 = 30.0_dp*kd*factor**5\n temp0 = wakeangleinit*rotordiameter(turb)\n temp = wakeangleinit**2 + 15.0_dp*factor**4\n DO nd=1,nbdirs\n displacementb(nd) = wakecentersyt_matb(nd, turbi, turb)\n tempb(nd) = -((wakeangleinit**2+15.0_dp)*displacementb(nd)/(&\n& 30.0_dp*kd))\n tempb0(nd) = displacementb(nd)/temp1\n wakeangleinitb(nd) = wakeangleinitb(nd) + (temp*rotordiameter(&\n& turb)+temp0*2*wakeangleinit)*tempb0(nd) + rotordiameter(turb&\n& )*tempb(nd) - wakeangleinit**2*rotordiameter(turb)*2*&\n& displacementb(nd)/(30.0_dp*kd)\n factorb(nd) = (15.0_dp*temp0*4*factor**3-30.0_dp*kd*temp*temp0&\n& *5*factor**4/temp1)*tempb0(nd)\n turbineywb(nd, turb) = turbineywb(nd, turb) + &\n& wakecentersyt_matb(nd, turbi, turb)\n wakecentersyt_matb(nd, turbi, turb) = 0.0\n tempb1(nd) = kd*2.0_dp*factorb(nd)/rotordiameter(turb)\n rotordiameterb(nd, turb) = rotordiameterb(nd, turb) + temp*&\n& wakeangleinit*tempb0(nd) - deltax*tempb1(nd)/rotordiameter(&\n& turb) + wakeangleinit*tempb(nd)\n deltaxb(nd) = deltaxb(nd) + tempb1(nd)\n turbinexwb(nd, turbi) = turbinexwb(nd, turbi) + deltaxb(nd)\n turbinexwb(nd, turb) = turbinexwb(nd, turb) - deltaxb(nd)\n END DO\n CALL POPREAL4ARRAY(deltax, dp/4)\n END IF\n END DO\n CALL POPREAL4ARRAY(wakeangleinit, dp/4)\n DO nd=1,nbdirs\n yawb(nd, turb) = yawb(nd, turb) + ct(turb)*0.5_dp*COS(yaw(turb))*&\n& wakeangleinitb(nd)\n ctb(nd, turb) = ctb(nd, turb) + 0.5_dp*SIN(yaw(turb))*&\n& wakeangleinitb(nd)\n END DO\n END DO\n DO nd=1,nbdirs\n yaw_degb(nd, :) = yaw_degb(nd, :) + pi*yawb(nd, :)/180.0_dp\n END DO\n DO nd=1,nbdirs\n velocitiesturbinesb(nd, :) = 0.0\n END DO\nEND SUBROUTINE FLORIS_UNIFIED_BV\n\n! Differentiation of hermite_spline in reverse (adjoint) mode:\n! gradient of useful results: y\n! with respect to varying inputs: x x0 x1 dy0 y0\n! Flow field calculations have been intentionally left out to save development time.\n! The flow field can be calculated using the pure python version of floris \n! This implementation is fully smooth and differentiable with the exception of a \n! discontinuity at the hub of each turbine. The discontinuity only presents issues if\n! turbines are place within 1E-15 * rotor diameter of one another, which is extremely \n! unlikely during optimization if the user does not explicitly place them there.\nSUBROUTINE HERMITE_SPLINE_BV(x, xb, x0, x0b, x1, x1b, y0, y0b, dy0, dy0b&\n& , y1, dy1, y, yb, nbdirs)\n \n! Hint: nbdirs should be the maximum number of differentiation directions\n IMPLICIT NONE\n!dy_dx = c3*3*x**2 + c2*2*x + c1\n! define precision to be the standard for a double precision ! on local system\n INTEGER, PARAMETER :: dp=KIND(0.d0)\n! in\n REAL(dp), INTENT(IN) :: x, x0, x1, y0, dy0, y1, dy1\n REAL(dp), DIMENSION(nbdirs) :: xb, x0b, x1b, y0b, dy0b\n! out\n!, dy_dx\n REAL(dp) :: y\n REAL(dp), DIMENSION(nbdirs) :: yb\n! local\n REAL(dp) :: c3, c2, c1, c0\n REAL(dp), DIMENSION(nbdirs) :: c3b, c2b, c1b, c0b\n INTRINSIC KIND\n INTEGER :: nd\n INTEGER :: nbdirs\n REAL(dp) :: temp3\n REAL(dp) :: temp2\n REAL(dp) :: temp1\n REAL(dp) :: temp0\n REAL(dp) :: tempb9(nbdirs)\n REAL(dp) :: tempb8(nbdirs)\n REAL(dp) :: tempb7(nbdirs)\n REAL(dp) :: tempb6(nbdirs)\n REAL(dp) :: tempb5(nbdirs)\n REAL(dp) :: tempb4(nbdirs)\n REAL(dp) :: tempb19(nbdirs)\n REAL(dp) :: tempb3(nbdirs)\n REAL(dp) :: tempb18(nbdirs)\n REAL(dp) :: tempb2(nbdirs)\n REAL(dp) :: tempb17(nbdirs)\n REAL(dp) :: tempb1(nbdirs)\n REAL(dp) :: tempb16(nbdirs)\n REAL(dp) :: tempb0(nbdirs)\n REAL(dp) :: tempb15(nbdirs)\n REAL(dp) :: tempb14(nbdirs)\n REAL(dp) :: tempb13(nbdirs)\n REAL(dp) :: tempb12(nbdirs)\n REAL(dp) :: tempb11(nbdirs)\n REAL(dp) :: tempb10(nbdirs)\n REAL(dp) :: temp16\n REAL(dp) :: temp15\n REAL(dp) :: temp14\n REAL(dp) :: temp13\n REAL(dp) :: temp12\n REAL(dp) :: temp11\n REAL(dp) :: temp10\n REAL(dp) :: tempb(nbdirs)\n REAL(dp) :: tempb30(nbdirs)\n REAL(dp) :: tempb29(nbdirs)\n REAL(dp) :: tempb28(nbdirs)\n REAL(dp) :: tempb27(nbdirs)\n REAL(dp) :: tempb26(nbdirs)\n REAL(dp) :: tempb25(nbdirs)\n REAL(dp) :: temp\n REAL(dp) :: tempb24(nbdirs)\n REAL(dp) :: tempb23(nbdirs)\n REAL(dp) :: tempb22(nbdirs)\n REAL(dp) :: temp9\n REAL(dp) :: tempb21(nbdirs)\n REAL(dp) :: temp8\n REAL(dp) :: tempb20(nbdirs)\n REAL(dp) :: temp7\n REAL(dp) :: temp6\n REAL(dp) :: temp5\n REAL(dp) :: temp4\n! initialize coefficients for parametric cubic spline\n c3 = 2.0_dp*y1/(x0**3-3.0_dp*x0**2*x1+3.0_dp*x0*x1**2-x1**3) - 2.0_dp*&\n& y0/(x0**3-3.0_dp*x0**2*x1+3.0_dp*x0*x1**2-x1**3) + dy0/(x0**2-2.0_dp&\n& *x0*x1+x1**2) + dy1/(x0**2-2.0_dp*x0*x1+x1**2)\n c2 = 3.0_dp*y0*(x0+x1)/(x0**3-3.0_dp*x0**2*x1+3.0_dp*x0*x1**2-x1**3) -&\n& dy1*(2.0_dp*x0+x1)/(x0**2-2.0_dp*x0*x1+x1**2) - dy0*(x0+2.0_dp*x1)/(&\n& x0**2-2.0_dp*x0*x1+x1**2) - 3.0_dp*y1*(x0+x1)/(x0**3-3.0_dp*x0**2*x1&\n& +3.0_dp*x0*x1**2-x1**3)\n c1 = dy0*(x1**2+2.0_dp*x0*x1)/(x0**2-2.0_dp*x0*x1+x1**2) + dy1*(x0**2+&\n& 2.0_dp*x1*x0)/(x0**2-2.0_dp*x0*x1+x1**2) - 6.0_dp*x0*x1*y0/(x0**3-&\n& 3.0_dp*x0**2*x1+3.0_dp*x0*x1**2-x1**3) + 6.0_dp*x0*x1*y1/(x0**3-&\n& 3.0_dp*x0**2*x1+3.0_dp*x0*x1**2-x1**3)\n! print *, 'c3 = ', c3\n! print *, 'c2 = ', c2\n! print *, 'c1 = ', c1\n! print *, 'c0 = ', c0\n! Solve for y and dy values at the given point\n temp13 = x0**3 - 3.0_dp*x0**2*x1 + 3.0_dp*x0*x1**2 - x1**3\n temp12 = 3.0_dp*x0*x1**2 - x1**3\n temp14 = x0**3 - 3.0_dp*x0**2*x1 + 3.0_dp*x0*x1**2 - x1**3\n temp15 = x0**2 - 2.0_dp*x0*x1 + x1**2\n temp16 = x0**2 - 2.0_dp*x0*x1 + x1**2\n temp8 = x0**2 - 2.0_dp*x0*x1 + x1**2\n temp7 = x1**2 + 2.0_dp*x0*x1\n temp9 = x0**2 - 2.0_dp*x0*x1 + x1**2\n temp10 = x0**3 - 3.0_dp*x0**2*x1 + 3.0_dp*x0*x1**2 - x1**3\n temp11 = x0**3 - 3.0_dp*x0**2*x1 + 3.0_dp*x0*x1**2 - x1**3\n temp3 = x0**3 - 3.0_dp*x0**2*x1 + 3.0_dp*x0*x1**2 - x1**3\n temp4 = x0**2 - 2.0_dp*x0*x1 + x1**2\n temp5 = x0**2 - 2.0_dp*x0*x1 + x1**2\n temp6 = x0**3 - 3.0_dp*x0**2*x1 + 3.0_dp*x0*x1**2 - x1**3\n temp = x0**3 - 3.0_dp*x0**2*x1 + 3.0_dp*x0*x1**2 - x1**3\n temp0 = x0**3 - 3.0_dp*x0**2*x1 + 3.0_dp*x0*x1**2 - x1**3\n temp1 = x0**2 - 2.0_dp*x0*x1 + x1**2\n temp2 = x0**2 - 2.0_dp*x0*x1 + x1**2\n DO nd=1,nbdirs\n c3b(nd) = x**3*yb(nd)\n xb(nd) = (c1+c2*2*x+c3*3*x**2)*yb(nd)\n c2b(nd) = x**2*yb(nd)\n c1b(nd) = x*yb(nd)\n c0b(nd) = yb(nd)\n tempb(nd) = c0b(nd)/temp13\n tempb0(nd) = y0*tempb(nd)\n tempb1(nd) = -(y0*temp12*tempb(nd)/temp13)\n tempb2(nd) = -(y1*c0b(nd)/temp14)\n tempb3(nd) = -((3.0_dp*(x1*x0**2)-x0**3)*tempb2(nd)/temp14)\n tempb4(nd) = -(c0b(nd)/temp15)\n tempb5(nd) = x1**2*tempb4(nd)\n tempb6(nd) = -(x1**2*x0*dy0*tempb4(nd)/temp15)\n tempb7(nd) = -(dy1*c0b(nd)/temp16)\n tempb8(nd) = -(x0**2*x1*tempb7(nd)/temp16)\n tempb30(nd) = c1b(nd)/temp8\n tempb12(nd) = dy0*tempb30(nd)\n tempb13(nd) = -(dy0*temp7*tempb30(nd)/temp8)\n tempb14(nd) = dy1*c1b(nd)/temp9\n tempb15(nd) = -((x0**2+2.0_dp*(x1*x0))*tempb14(nd)/temp9)\n tempb16(nd) = y1*6.0_dp*c1b(nd)/temp10\n tempb17(nd) = -(x0*x1*tempb16(nd)/temp10)\n tempb9(nd) = -(6.0_dp*c1b(nd)/temp11)\n tempb18(nd) = -(x0*x1*y0*tempb9(nd)/temp11)\n tempb11(nd) = 3.0_dp*c2b(nd)/temp3\n tempb29(nd) = -(y0*(x0+x1)*tempb11(nd)/temp3)\n tempb28(nd) = -(dy1*c2b(nd)/temp4)\n tempb27(nd) = -((2.0_dp*x0+x1)*tempb28(nd)/temp4)\n tempb26(nd) = -(c2b(nd)/temp5)\n dy0b(nd) = temp7*tempb30(nd) + c3b(nd)/temp1 + (x0+2.0_dp*x1)*&\n& tempb26(nd) + x0*tempb5(nd)\n tempb25(nd) = -(dy0*(x0+2.0_dp*x1)*tempb26(nd)/temp5)\n tempb24(nd) = -(y1*3.0_dp*c2b(nd)/temp6)\n tempb23(nd) = -((x0+x1)*tempb24(nd)/temp6)\n tempb19(nd) = -(y1*2.0_dp*c3b(nd)/temp**2)\n tempb10(nd) = -(2.0_dp*c3b(nd)/temp0)\n y0b(nd) = x0*x1*tempb9(nd) + tempb10(nd) + (x0+x1)*tempb11(nd) + &\n& temp12*tempb(nd)\n tempb20(nd) = -(y0*tempb10(nd)/temp0)\n tempb21(nd) = -(dy0*c3b(nd)/temp1**2)\n tempb22(nd) = -(dy1*c3b(nd)/temp2**2)\n x0b(nd) = 2.0_dp*x1*tempb12(nd) + (2*x0-2.0_dp*x1)*tempb13(nd) + (&\n& 2.0_dp*x1+2*x0)*tempb14(nd) + (2*x0-2.0_dp*x1)*tempb15(nd) + x1*&\n& tempb16(nd) + (3.0_dp*x1**2-x1*3.0_dp*2*x0+3*x0**2)*tempb17(nd) + &\n& y0*x1*tempb9(nd) + (3.0_dp*x1**2-x1*3.0_dp*2*x0+3*x0**2)*tempb18(&\n& nd) + (3.0_dp*x1**2-x1*3.0_dp*2*x0+3*x0**2)*tempb19(nd) + (3.0_dp*&\n& x1**2-x1*3.0_dp*2*x0+3*x0**2)*tempb20(nd) + (2*x0-2.0_dp*x1)*&\n& tempb21(nd) + (2*x0-2.0_dp*x1)*tempb22(nd) + (3.0_dp*x1**2-x1*&\n& 3.0_dp*2*x0+3*x0**2)*tempb23(nd) + tempb24(nd) + (2*x0-2.0_dp*x1)*&\n& tempb25(nd) + dy0*tempb26(nd) + (2*x0-2.0_dp*x1)*tempb27(nd) + &\n& 2.0_dp*tempb28(nd) + (3.0_dp*x1**2-x1*3.0_dp*2*x0+3*x0**2)*tempb29&\n& (nd) + y0*tempb11(nd) + (2*x0-2.0_dp*x1)*tempb8(nd) + x1*2*x0*&\n& tempb7(nd) + (2*x0-2.0_dp*x1)*tempb6(nd) + dy0*tempb5(nd) + (&\n& 3.0_dp*x1**2-x1*3.0_dp*2*x0+3*x0**2)*tempb3(nd) + (x1*3.0_dp*2*x0-&\n& 3*x0**2)*tempb2(nd) + (3.0_dp*x1**2-x1*3.0_dp*2*x0+3*x0**2)*tempb1&\n& (nd) + 3.0_dp*x1**2*tempb0(nd)\n x1b(nd) = (2.0_dp*x0+2*x1)*tempb12(nd) + (2*x1-2.0_dp*x0)*tempb13(nd&\n& ) + 2.0_dp*x0*tempb14(nd) + (2*x1-2.0_dp*x0)*tempb15(nd) + x0*&\n& tempb16(nd) + (x0*3.0_dp*2*x1-3*x1**2-3.0_dp*x0**2)*tempb17(nd) + &\n& y0*x0*tempb9(nd) + (x0*3.0_dp*2*x1-3*x1**2-3.0_dp*x0**2)*tempb18(&\n& nd) + (x0*3.0_dp*2*x1-3*x1**2-3.0_dp*x0**2)*tempb19(nd) + (x0*&\n& 3.0_dp*2*x1-3*x1**2-3.0_dp*x0**2)*tempb20(nd) + (2*x1-2.0_dp*x0)*&\n& tempb21(nd) + (2*x1-2.0_dp*x0)*tempb22(nd) + (x0*3.0_dp*2*x1-3*x1&\n& **2-3.0_dp*x0**2)*tempb23(nd) + tempb24(nd) + (2*x1-2.0_dp*x0)*&\n& tempb25(nd) + dy0*2.0_dp*tempb26(nd) + (2*x1-2.0_dp*x0)*tempb27(nd&\n& ) + tempb28(nd) + (x0*3.0_dp*2*x1-3*x1**2-3.0_dp*x0**2)*tempb29(nd&\n& ) + y0*tempb11(nd) + (2*x1-2.0_dp*x0)*tempb8(nd) + x0**2*tempb7(nd&\n& ) + (2*x1-2.0_dp*x0)*tempb6(nd) + x0*dy0*2*x1*tempb4(nd) + (x0*&\n& 3.0_dp*2*x1-3*x1**2-3.0_dp*x0**2)*tempb3(nd) + 3.0_dp*x0**2*tempb2&\n& (nd) + (x0*3.0_dp*2*x1-3*x1**2-3.0_dp*x0**2)*tempb1(nd) + (x0*&\n& 3.0_dp*2*x1-3*x1**2)*tempb0(nd)\n END DO\nEND SUBROUTINE HERMITE_SPLINE_BV\n\n! Differentiation of calcoverlapareas in reverse (adjoint) mode:\n! gradient of useful results: rotordiameter turbiney wakeoverlaptrel_mat\n! wakediameters wakecenters\n! with respect to varying inputs: rotordiameter turbiney wakediameters\n! wakecenters\nSUBROUTINE CALCOVERLAPAREAS_BV(nturbines, turbinex, turbiney, turbineyb&\n& , rotordiameter, rotordiameterb, wakediameters, wakediametersb, &\n& wakecenters, wakecentersb, wakeoverlaptrel_mat, wakeoverlaptrel_matb, &\n& nbdirs)\n \n! Hint: nbdirs should be the maximum number of differentiation directions\n IMPLICIT NONE\n! do turbI = 1, nTurbines\n! do turb = 1, nTurbines\n! do zone = 1, 3\n! print *, \"wakeOverlapTRel_mat[\", turbI, \", \", turb, \", \", zone, \"] = \", wakeOverlapTRel_mat(turbI, turb, zone)\n! end do\n! end do\n! end do\n! define precision to be the standard for a double precision ! on local system\n INTEGER, PARAMETER :: dp=KIND(0.d0)\n! in\n INTEGER, INTENT(IN) :: nturbines\n REAL(dp), DIMENSION(nturbines), INTENT(IN) :: turbinex, turbiney, &\n& rotordiameter\n REAL(dp), DIMENSION(nbdirs, nturbines) :: turbineyb, rotordiameterb\n REAL(dp), DIMENSION(nturbines, nturbines, 3), INTENT(IN) :: &\n& wakediameters\n REAL(dp), DIMENSION(nbdirs, nturbines, nturbines, 3) :: &\n& wakediametersb\n REAL(dp), DIMENSION(nturbines, nturbines), INTENT(IN) :: wakecenters\n REAL(dp), DIMENSION(nbdirs, nturbines, nturbines) :: wakecentersb\n! out \n REAL(dp), DIMENSION(nturbines, nturbines, 3) :: wakeoverlaptrel_mat\n REAL(dp), DIMENSION(nbdirs, nturbines, nturbines, 3) :: &\n& wakeoverlaptrel_matb\n! local\n INTEGER :: turb, turbi, zone\n REAL(dp), PARAMETER :: pi=3.141592653589793_dp, tol=0.000001_dp\n REAL(dp) :: ovdyd, ovr, ovrr, ovl, ovz\n REAL(dp), DIMENSION(nbdirs) :: ovdydb, ovrb, ovrrb, ovlb, ovzb\n REAL(dp), DIMENSION(nturbines, nturbines, 3) :: wakeoverlap\n REAL(dp), DIMENSION(nbdirs, nturbines, nturbines, 3) :: &\n& wakeoverlapb\n INTRINSIC KIND\n INTRINSIC ABS\n INTRINSIC SQRT\n INTRINSIC DACOS\n INTEGER :: nd\n INTEGER :: branch\n INTEGER :: nbdirs\n REAL(dp) :: temp1\n REAL(dp) :: temp0\n REAL(dp) :: tempb2(nbdirs, nturbines, 3)\n REAL(dp) :: tempb1(nbdirs)\n REAL(dp) :: tempb0(nbdirs)\n REAL(dp) :: tempb(nbdirs)\n REAL(dp) :: temp\n wakeoverlap = 0.0_dp\n DO turb=1,nturbines\n DO turbi=1,nturbines\n IF (turbinex(turbi) .GT. turbinex(turb)) THEN\n! distance between wake center and rotor center\n CALL PUSHREAL4ARRAY(ovdyd, dp/4)\n ovdyd = wakecenters(turbi, turb) - turbiney(turbi)\n! rotor diameter\n CALL PUSHREAL4ARRAY(ovr, dp/4)\n ovr = rotordiameter(turbi)/2\n DO zone=1,3\n! wake diameter\n ovrr = wakediameters(turbi, turb, zone)/2.0_dp\n IF (ovdyd .GE. 0.) THEN\n CALL PUSHREAL4ARRAY(ovdyd, dp/4)\n ovdyd = ovdyd\n CALL PUSHCONTROL1B(0)\n ELSE\n CALL PUSHREAL4ARRAY(ovdyd, dp/4)\n ovdyd = -ovdyd\n CALL PUSHCONTROL1B(1)\n END IF\n IF (ovdyd .GE. 0.0_dp + tol) THEN\n! calculate the distance from the wake center to the vertical line between\n! the two circle intersection points\n CALL PUSHREAL4ARRAY(ovl, dp/4)\n ovl = (-(ovr*ovr)+ovrr*ovrr+ovdyd*ovdyd)/(2.0_dp*ovdyd)\n CALL PUSHCONTROL1B(0)\n ELSE\n CALL PUSHREAL4ARRAY(ovl, dp/4)\n ovl = 0.0_dp\n CALL PUSHCONTROL1B(1)\n END IF\n CALL PUSHREAL4ARRAY(ovz, dp/4)\n ovz = ovrr*ovrr - ovl*ovl\n! Finish calculating the distance from the intersection line to the outer edge of the wake zone\n IF (ovz .GT. 0.0_dp + tol) THEN\n CALL PUSHREAL4ARRAY(ovz, dp/4)\n ovz = SQRT(ovz)\n CALL PUSHCONTROL1B(0)\n ELSE\n ovz = 0.0_dp\n CALL PUSHCONTROL1B(1)\n END IF\n IF (ovdyd .LT. ovr + ovrr) THEN\n! if the rotor overlaps the wake zone\n IF (ovl .LT. ovrr .AND. ovdyd - ovl .LT. ovr) THEN\n wakeoverlap(turbi, turb, zone) = ovrr*ovrr*DACOS(ovl/ovrr)&\n& + ovr*ovr*DACOS((ovdyd-ovl)/ovr) - ovdyd*ovz\n CALL PUSHCONTROL2B(3)\n ELSE IF (ovrr .GT. ovr) THEN\n wakeoverlap(turbi, turb, zone) = pi*ovr*ovr\n CALL PUSHCONTROL2B(2)\n ELSE\n wakeoverlap(turbi, turb, zone) = pi*ovrr*ovrr\n CALL PUSHCONTROL2B(1)\n END IF\n ELSE\n wakeoverlap(turbi, turb, zone) = 0.0_dp\n CALL PUSHCONTROL2B(0)\n END IF\n END DO\n CALL PUSHCONTROL1B(1)\n ELSE\n CALL PUSHCONTROL1B(0)\n END IF\n END DO\n END DO\n DO turb=1,nturbines\n DO turbi=1,nturbines\n wakeoverlap(turbi, turb, 3) = wakeoverlap(turbi, turb, 3) - &\n& wakeoverlap(turbi, turb, 2)\n wakeoverlap(turbi, turb, 2) = wakeoverlap(turbi, turb, 2) - &\n& wakeoverlap(turbi, turb, 1)\n END DO\n END DO\n wakeoverlaptrel_mat = wakeoverlap\n DO turbi=nturbines,1,-1\n temp1 = pi*rotordiameter(turbi)**2\n DO nd=1,nbdirs\n tempb2(nd, :, :) = 4.0_dp*wakeoverlaptrel_matb(nd, turbi, :, :)/&\n& temp1\n rotordiameterb(nd, turbi) = rotordiameterb(nd, turbi) + pi*2*&\n& rotordiameter(turbi)*SUM(-(wakeoverlaptrel_mat(turbi, :, :)*&\n& tempb2(nd, :, :)/temp1))\n wakeoverlaptrel_matb(nd, turbi, :, :) = tempb2(nd, :, :)\n END DO\n END DO\n DO nd=1,nbdirs\n wakeoverlapb(nd, :, :, :) = 0.0\n wakeoverlapb(nd, :, :, :) = wakeoverlaptrel_matb(nd, :, :, :)\n END DO\n DO turb=nturbines,1,-1\n DO turbi=nturbines,1,-1\n DO nd=1,nbdirs\n wakeoverlapb(nd, turbi, turb, 1) = wakeoverlapb(nd, turbi, turb&\n& , 1) - wakeoverlapb(nd, turbi, turb, 2)\n wakeoverlapb(nd, turbi, turb, 2) = wakeoverlapb(nd, turbi, turb&\n& , 2) - wakeoverlapb(nd, turbi, turb, 3)\n END DO\n END DO\n END DO\n DO turb=nturbines,1,-1\n DO turbi=nturbines,1,-1\n CALL POPCONTROL1B(branch)\n IF (branch .NE. 0) THEN\n DO nd=1,nbdirs\n ovdydb(nd) = 0.0\n ovrb(nd) = 0.0\n END DO\n DO zone=3,1,-1\n CALL POPCONTROL2B(branch)\n IF (branch .LT. 2) THEN\n IF (branch .EQ. 0) THEN\n DO nd=1,nbdirs\n wakeoverlapb(nd, turbi, turb, zone) = 0.0\n END DO\n ovrr = wakediameters(turbi, turb, zone)/2.0_dp\n DO nd=1,nbdirs\n ovlb(nd) = 0.0\n ovrrb(nd) = 0.0\n ovzb(nd) = 0.0\n END DO\n GOTO 100\n ELSE\n ovrr = wakediameters(turbi, turb, zone)/2.0_dp\n DO nd=1,nbdirs\n ovrrb(nd) = pi*2*ovrr*wakeoverlapb(nd, turbi, turb, zone&\n& )\n wakeoverlapb(nd, turbi, turb, zone) = 0.0\n END DO\n END IF\n ELSE IF (branch .EQ. 2) THEN\n DO nd=1,nbdirs\n ovrb(nd) = ovrb(nd) + pi*2*ovr*wakeoverlapb(nd, turbi, &\n& turb, zone)\n wakeoverlapb(nd, turbi, turb, zone) = 0.0\n END DO\n ovrr = wakediameters(turbi, turb, zone)/2.0_dp\n DO nd=1,nbdirs\n ovrrb(nd) = 0.0\n END DO\n ELSE\n ovrr = wakediameters(turbi, turb, zone)/2.0_dp\n temp = ovl/ovrr\n temp0 = (ovdyd-ovl)/ovr\n DO nd=1,nbdirs\n IF (temp .EQ. 1.0 .OR. temp .EQ. (-1.0)) THEN\n tempb0(nd) = 0.0\n ELSE\n tempb0(nd) = -(ovrr*wakeoverlapb(nd, turbi, turb, zone)/&\n& SQRT(1.D0-temp**2))\n END IF\n IF (temp0 .EQ. 1.0 .OR. temp0 .EQ. (-1.0)) THEN\n tempb1(nd) = 0.0\n ELSE\n tempb1(nd) = -(ovr*wakeoverlapb(nd, turbi, turb, zone)/&\n& SQRT(1.D0-temp0**2))\n END IF\n ovrrb(nd) = DACOS(temp)*2*ovrr*wakeoverlapb(nd, turbi, &\n& turb, zone) - temp*tempb0(nd)\n ovlb(nd) = tempb0(nd) - tempb1(nd)\n ovrb(nd) = ovrb(nd) + DACOS(temp0)*2*ovr*wakeoverlapb(nd, &\n& turbi, turb, zone) - temp0*tempb1(nd)\n ovdydb(nd) = ovdydb(nd) + tempb1(nd) - ovz*wakeoverlapb(nd&\n& , turbi, turb, zone)\n ovzb(nd) = -(ovdyd*wakeoverlapb(nd, turbi, turb, zone))\n wakeoverlapb(nd, turbi, turb, zone) = 0.0\n END DO\n GOTO 100\n END IF\n DO nd=1,nbdirs\n ovlb(nd) = 0.0\n ovzb(nd) = 0.0\n END DO\n 100 CALL POPCONTROL1B(branch)\n IF (branch .EQ. 0) THEN\n CALL POPREAL4ARRAY(ovz, dp/4)\n DO nd=1,nbdirs\n IF (ovz .EQ. 0.0) THEN\n ovzb(nd) = 0.0\n ELSE\n ovzb(nd) = ovzb(nd)/(2.0*SQRT(ovz))\n END IF\n END DO\n ELSE\n DO nd=1,nbdirs\n ovzb(nd) = 0.0\n END DO\n END IF\n CALL POPREAL4ARRAY(ovz, dp/4)\n DO nd=1,nbdirs\n ovrrb(nd) = ovrrb(nd) + 2*ovrr*ovzb(nd)\n ovlb(nd) = ovlb(nd) - 2*ovl*ovzb(nd)\n END DO\n CALL POPCONTROL1B(branch)\n IF (branch .EQ. 0) THEN\n CALL POPREAL4ARRAY(ovl, dp/4)\n DO nd=1,nbdirs\n tempb(nd) = ovlb(nd)/(2.0_dp*ovdyd)\n ovrrb(nd) = ovrrb(nd) + 2*ovrr*tempb(nd)\n ovrb(nd) = ovrb(nd) - 2*ovr*tempb(nd)\n ovdydb(nd) = ovdydb(nd) + (2*ovdyd-(ovrr**2-ovr**2+ovdyd**&\n& 2)/ovdyd)*tempb(nd)\n END DO\n ELSE\n CALL POPREAL4ARRAY(ovl, dp/4)\n END IF\n CALL POPCONTROL1B(branch)\n IF (branch .EQ. 0) THEN\n CALL POPREAL4ARRAY(ovdyd, dp/4)\n ELSE\n CALL POPREAL4ARRAY(ovdyd, dp/4)\n DO nd=1,nbdirs\n ovdydb(nd) = -ovdydb(nd)\n END DO\n END IF\n DO nd=1,nbdirs\n wakediametersb(nd, turbi, turb, zone) = wakediametersb(nd, &\n& turbi, turb, zone) + ovrrb(nd)/2.0_dp\n END DO\n END DO\n CALL POPREAL4ARRAY(ovr, dp/4)\n CALL POPREAL4ARRAY(ovdyd, dp/4)\n DO nd=1,nbdirs\n rotordiameterb(nd, turbi) = rotordiameterb(nd, turbi) + ovrb(&\n& nd)/2\n wakecentersb(nd, turbi, turb) = wakecentersb(nd, turbi, turb) &\n& + ovdydb(nd)\n turbineyb(nd, turbi) = turbineyb(nd, turbi) - ovdydb(nd)\n END DO\n END IF\n END DO\n END DO\nEND SUBROUTINE CALCOVERLAPAREAS_BV\n\n! Differentiation of cttoaxialind in reverse (adjoint) mode:\n! gradient of useful results: axial_induction ct\n! with respect to varying inputs: ct\nSUBROUTINE CTTOAXIALIND_BV(ct, ctb, nturbines, axial_induction, &\n& axial_inductionb, nbdirs)\n \n! Hint: nbdirs should be the maximum number of differentiation directions\n IMPLICIT NONE\n! define precision to be the standard for a double precision ! on local system\n INTEGER, PARAMETER :: dp=KIND(0.d0)\n! in\n INTEGER, INTENT(IN) :: nturbines\n REAL(dp), DIMENSION(nturbines), INTENT(IN) :: ct\n REAL(dp), DIMENSION(nbdirs, nturbines) :: ctb\n! local\n INTEGER :: i\n! out\n REAL(dp), DIMENSION(nturbines) :: axial_induction\n REAL(dp), DIMENSION(nbdirs, nturbines) :: axial_inductionb\n INTRINSIC KIND\n INTRINSIC SQRT\n INTEGER :: nd\n INTEGER :: branch\n INTEGER :: nbdirs\n! execute\n DO i=1,nturbines\n IF (ct(i) .GT. 0.96) THEN\n CALL PUSHCONTROL1B(1)\n ELSE\n CALL PUSHCONTROL1B(0)\n END IF\n END DO\n DO i=nturbines,1,-1\n CALL POPCONTROL1B(branch)\n IF (branch .EQ. 0) THEN\n DO nd=1,nbdirs\n IF (.NOT.1.0_dp - ct(i) .EQ. 0.0) ctb(nd, i) = ctb(nd, i) + &\n& 0.5_dp*axial_inductionb(nd, i)/(2.0*SQRT(1.0_dp-ct(i)))\n axial_inductionb(nd, i) = 0.0\n END DO\n ELSE\n DO nd=1,nbdirs\n IF (.NOT.0.0203_dp - 0.6427_dp*(0.889_dp-ct(i)) .EQ. 0.0) ctb(nd&\n& , i) = ctb(nd, i) + 0.6427_dp*axial_inductionb(nd, i)/(2.0*&\n& SQRT(0.0203_dp-0.6427_dp*(0.889_dp-ct(i))))\n axial_inductionb(nd, i) = 0.0\n END DO\n END IF\n END DO\nEND SUBROUTINE CTTOAXIALIND_BV\n\n\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n! Generated by TAPENADE (INRIA, Ecuador team)\n! Tapenade 3.11 (r5902M) - 15 Dec 2015 09:00\n!\n! Differentiation of floris_unified in forward (tangent) mode:\n! variations of useful results: velocitiesturbines\n! with respect to varying inputs: rotordiameter turbinexw yaw_deg\n! turbineyw ct a_in\n! RW status of diff variables: rotordiameter:in turbinexw:in\n! yaw_deg:in velocitiesturbines:out turbineyw:in\n! ct:in a_in:in\nSUBROUTINE FLORIS_UNIFIED_DV(nturbines, turbinexw, turbinexwd, turbineyw&\n& , turbineywd, yaw_deg, yaw_degd, rotordiameter, rotordiameterd, vinf, &\n& ct, ctd, a_in, a_ind, ke_in, kd, me, initialwakedisplacement, bd, mu, &\n& au, bu, initialwakeangle, cos_spread, kecorrct, region2ct, kecorrarray&\n& , usewakeangle, adjustinitialwakediamtoyaw, axialindprovided, useaubu&\n& , velocitiesturbinesd, nbdirs)\n \n! Hint: nbdirs should be the maximum number of differentiation directions\n IMPLICIT NONE\n! define precision to be the standard for a double precision ! on local system\n INTEGER, PARAMETER :: dp=KIND(0.d0)\n! in\n INTEGER, INTENT(IN) :: nturbines\n REAL(dp), INTENT(IN) :: kd, initialwakedisplacement, initialwakeangle&\n& , ke_in\n REAL(dp), INTENT(IN) :: kecorrct, region2ct, bd, cos_spread, vinf, &\n& kecorrarray\n REAL(dp), DIMENSION(nturbines), INTENT(IN) :: yaw_deg, ct, a_in, &\n& turbinexw, turbineyw\n REAL(dp), DIMENSION(nbdirs, nturbines), INTENT(IN) :: yaw_degd, ctd&\n& , a_ind, turbinexwd, turbineywd\n REAL(dp), DIMENSION(nturbines), INTENT(IN) :: rotordiameter\n REAL(dp), DIMENSION(nbdirs, nturbines), INTENT(IN) :: &\n& rotordiameterd\n REAL(dp), DIMENSION(3), INTENT(IN) :: me, mu\n REAL(dp), INTENT(IN) :: au, bu\n LOGICAL, INTENT(IN) :: usewakeangle, adjustinitialwakediamtoyaw, &\n& axialindprovided, useaubu\n! local (General)\n REAL(dp), DIMENSION(nturbines) :: ke, yaw\n REAL(dp), DIMENSION(nbdirs, nturbines) :: ked, yawd\n REAL(dp) :: deltax\n REAL(dp), DIMENSION(nbdirs) :: deltaxd\n INTEGER :: turb, turbi, zone\n REAL(dp), PARAMETER :: pi=3.141592653589793_dp\n! local (Wake centers and diameters)\n! in rotor diameters \n REAL(dp) :: spline_bound\n REAL(dp) :: wakeangleinit, zeroloc\n REAL(dp), DIMENSION(nbdirs) :: wakeangleinitd, zerolocd\n REAL(dp) :: factor, displacement, x, x1, x2, y1, y2, dy1, dy2\n REAL(dp), DIMENSION(nbdirs) :: factord, displacementd, xd, x1d, x2d&\n& , y1d, dy1d\n REAL(dp) :: wakediameter0\n REAL(dp), DIMENSION(nbdirs) :: wakediameter0d\n REAL(dp), DIMENSION(nturbines, nturbines, 3) :: wakediameterst_mat\n REAL(dp), DIMENSION(nbdirs, nturbines, nturbines, 3) :: &\n& wakediameterst_matd\n REAL(dp), DIMENSION(nturbines, nturbines) :: wakecentersyt_mat\n REAL(dp), DIMENSION(nbdirs, nturbines, nturbines) :: &\n& wakecentersyt_matd\n! local (Wake overlap)\n REAL(dp) :: rmax\n REAL(dp), DIMENSION(nbdirs) :: rmaxd\n REAL(dp), DIMENSION(nturbines, nturbines, 3) :: wakeoverlaptrel_mat\n REAL(dp), DIMENSION(nbdirs, nturbines, nturbines, 3) :: &\n& wakeoverlaptrel_matd\n REAL(dp), DIMENSION(nturbines, nturbines, 3) :: cosfac_mat\n REAL(dp), DIMENSION(nbdirs, nturbines, nturbines, 3) :: cosfac_matd\n! local (Velocity)\n REAL(dp), DIMENSION(nturbines) :: a, kearray\n REAL(dp), DIMENSION(nbdirs, nturbines) :: ad, kearrayd\n REAL(dp), DIMENSION(3) :: mmu\n REAL(dp), DIMENSION(nbdirs, 3) :: mmud\n REAL(dp) :: s, wakeeffcoeff, wakeeffcoeffperzone\n REAL(dp), DIMENSION(nbdirs) :: sd, wakeeffcoeffd, &\n& wakeeffcoeffperzoned\n! out\n REAL(dp), DIMENSION(nturbines) :: velocitiesturbines\n REAL(dp), DIMENSION(nbdirs, nturbines), INTENT(OUT) :: &\n& velocitiesturbinesd\n REAL(dp), DIMENSION(nturbines*nturbines) :: &\n& wakecentersyt_vec\n REAL(dp), DIMENSION(3*nturbines*nturbines) :: &\n& wakediameterst_vec\n REAL(dp), DIMENSION(3*nturbines*nturbines) :: &\n& wakeoverlaptrel_vec\n INTRINSIC COS\n INTRINSIC KIND\n INTRINSIC SIN\n INTRINSIC DABS\n INTRINSIC SUM\n INTRINSIC SQRT\n REAL(dp) :: arg1\n REAL(dp), DIMENSION(nbdirs) :: arg1d\n REAL(dp), DIMENSION(nturbines) :: arg10\n REAL(dp), DIMENSION(nbdirs, nturbines) :: arg10d\n REAL(dp) :: result1\n REAL(dp), DIMENSION(nbdirs) :: result1d\n INTEGER :: nd\n INTEGER :: nbdirs\n DOUBLE PRECISION :: dabs0d(nbdirs)\n DOUBLE PRECISION :: dabs0\n!!!!!!!!!!!!!!!!!!!!!!!!!!!! Wake Centers and Diameters !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n spline_bound = 1.0_dp\n DO nd=1,nbdirs\n yawd(nd, :) = pi*yaw_degd(nd, :)/180.0_dp\n END DO\n yaw = yaw_deg*pi/180.0_dp\n! calculate y-locations of wake centers in wind ref. frame\n wakecentersyt_mat = 0.0_dp\n DO nd=1,nbdirs\n wakecentersyt_matd(nd, :, :) = 0.0\n END DO\n DO turb=1,nturbines\n DO nd=1,nbdirs\n wakeangleinitd(nd) = 0.5_dp*(yawd(nd, turb)*COS(yaw(turb))*ct(turb&\n& )+SIN(yaw(turb))*ctd(nd, turb))\n END DO\n wakeangleinit = 0.5_dp*SIN(yaw(turb))*ct(turb)\n IF (usewakeangle) wakeangleinit = wakeangleinit + initialwakeangle*&\n& pi/180.0_dp\n DO turbi=1,nturbines\n IF (turbinexw(turb) .LT. turbinexw(turbi)) THEN\n deltax = turbinexw(turbi) - turbinexw(turb)\n factor = 2.0_dp*kd*deltax/rotordiameter(turb) + 1.0_dp\n DO nd=1,nbdirs\n deltaxd(nd) = turbinexwd(nd, turbi) - turbinexwd(nd, turb)\n factord(nd) = (2.0_dp*kd*deltaxd(nd)*rotordiameter(turb)-&\n& 2.0_dp*kd*deltax*rotordiameterd(nd, turb))/rotordiameter(&\n& turb)**2\n wakecentersyt_matd(nd, turbi, turb) = turbineywd(nd, turb)\n displacementd(nd) = ((wakeangleinitd(nd)*(wakeangleinit*&\n& wakeangleinit+15.0_dp*factor*factor*factor*factor)+&\n& wakeangleinit*(wakeangleinitd(nd)*wakeangleinit+&\n& wakeangleinit*wakeangleinitd(nd)+15.0_dp*((factord(nd)*&\n& factor+factor*factord(nd))*factor**2+factor**2*(factord(nd)*&\n& factor+factor*factord(nd)))))*30.0_dp*kd*factor**5/&\n& rotordiameter(turb)-wakeangleinit*(wakeangleinit*&\n& wakeangleinit+15.0_dp*factor*factor*factor*factor)*(30.0_dp*&\n& kd*(((factord(nd)*factor+factor*factord(nd))*factor+factor**&\n& 2*factord(nd))*factor**2+factor**3*(factord(nd)*factor+&\n& factor*factord(nd)))/rotordiameter(turb)-30.0_dp*kd*&\n& rotordiameterd(nd, turb)*factor**5/rotordiameter(turb)**2))/&\n& (30.0_dp*kd/rotordiameter(turb)*(factor*factor*factor*factor&\n& *factor))**2\n displacementd(nd) = displacementd(nd) - ((wakeangleinitd(nd)*(&\n& wakeangleinit*wakeangleinit+15.0_dp)+wakeangleinit*(&\n& wakeangleinitd(nd)*wakeangleinit+wakeangleinit*&\n& wakeangleinitd(nd)))*30.0_dp*kd/rotordiameter(turb)+&\n& wakeangleinit*(wakeangleinit*wakeangleinit+15.0_dp)*30.0_dp*&\n& kd*rotordiameterd(nd, turb)/rotordiameter(turb)**2)/(30.0_dp&\n& *kd/rotordiameter(turb))**2\n wakecentersyt_matd(nd, turbi, turb) = wakecentersyt_matd(nd, &\n& turbi, turb) + displacementd(nd)\n END DO\n wakecentersyt_mat(turbi, turb) = turbineyw(turb)\n displacement = wakeangleinit*(wakeangleinit*wakeangleinit+&\n& 15.0_dp*factor*factor*factor*factor)/(30.0_dp*kd/rotordiameter&\n& (turb)*(factor*factor*factor*factor*factor))\n displacement = displacement - wakeangleinit*(wakeangleinit*&\n& wakeangleinit+15.0_dp)/(30.0_dp*kd/rotordiameter(turb))\n wakecentersyt_mat(turbi, turb) = wakecentersyt_mat(turbi, turb) &\n& + initialwakedisplacement + displacement\n IF (usewakeangle .EQV. .false.) THEN\n DO nd=1,nbdirs\n wakecentersyt_matd(nd, turbi, turb) = wakecentersyt_matd(nd&\n& , turbi, turb) + bd*deltaxd(nd)\n END DO\n wakecentersyt_mat(turbi, turb) = wakecentersyt_mat(turbi, turb&\n& ) + bd*deltax\n END IF\n END IF\n END DO\n END DO\n DO nd=1,nbdirs\n!adjust k_e to C_T, adjusted to yaw\n ked(nd, :) = kecorrct*ctd(nd, :)\n END DO\n ke = ke_in + kecorrct*(ct-region2ct)\n wakediameterst_mat = 0.0_dp\n DO nd=1,nbdirs\n wakediameterst_matd(nd, :, :, :) = 0.0\n END DO\n DO turb=1,nturbines\n IF (adjustinitialwakediamtoyaw) THEN\n DO nd=1,nbdirs\n wakediameter0d(nd) = rotordiameterd(nd, turb)*COS(yaw(turb)) - &\n& rotordiameter(turb)*yawd(nd, turb)*SIN(yaw(turb))\n END DO\n wakediameter0 = rotordiameter(turb)*COS(yaw(turb))\n ELSE\n DO nd=1,nbdirs\n wakediameter0d(nd) = rotordiameterd(nd, turb)\n END DO\n wakediameter0 = rotordiameter(turb)\n END IF\n DO turbi=1,nturbines\n zone = 1\n DO nd=1,nbdirs\n! turbine separation\n deltaxd(nd) = turbinexwd(nd, turbi) - turbinexwd(nd, turb)\n! x position of interest\n xd(nd) = turbinexwd(nd, turbi)\n! define centerpoint of spline\n zerolocd(nd) = turbinexwd(nd, turb) - (wakediameter0d(nd)*2.0_dp&\n& *ke(turb)*me(zone)-wakediameter0*2.0_dp*me(zone)*ked(nd, turb)&\n& )/(2.0_dp*ke(turb)*me(zone))**2\n END DO\n deltax = turbinexw(turbi) - turbinexw(turb)\n x = turbinexw(turbi)\n zeroloc = turbinexw(turb) - wakediameter0/(2.0_dp*ke(turb)*me(zone&\n& ))\n IF (zeroloc + spline_bound*rotordiameter(turb) .LT. turbinexw(&\n& turbi)) THEN\n DO nd=1,nbdirs\n! check this\n wakediameterst_matd(nd, turbi, turb, zone) = 0.0\n END DO\n wakediameterst_mat(turbi, turb, zone) = 0.0_dp\n ELSE IF (zeroloc - spline_bound*rotordiameter(turb) .LT. turbinexw&\n& (turbi)) THEN\n x1 = zeroloc - spline_bound*rotordiameter(turb)\n DO nd=1,nbdirs\n!check this\n!!!!!!!!!!!!!!!!!!!!!! calculate spline values !!!!!!!!!!!!!!!!!!!!!!!!!!\n! position of upwind point\n x1d(nd) = zerolocd(nd) - spline_bound*rotordiameterd(nd, turb)\n! diameter of upwind point\n y1d(nd) = wakediameter0d(nd) + 2.0_dp*me(zone)*(ked(nd, turb)*&\n& (x1-turbinexw(turb))+ke(turb)*(x1d(nd)-turbinexwd(nd, turb))&\n& )\n! slope at upwind point\n dy1d(nd) = 2.0_dp*me(zone)*ked(nd, turb)\n! position of downwind point\n x2d(nd) = zerolocd(nd) + spline_bound*rotordiameterd(nd, turb)\n END DO\n y1 = wakediameter0 + 2.0_dp*ke(turb)*me(zone)*(x1-turbinexw(turb&\n& ))\n dy1 = 2.0_dp*ke(turb)*me(zone)\n x2 = zeroloc + spline_bound*rotordiameter(turb)\n! diameter at downwind point\n y2 = 0.0_dp\n! slope at downwind point\n dy2 = 0.0_dp\n! solve for the wake zone diameter and its derivative w.r.t. the downwind\n! location at the point of interest\n CALL HERMITE_SPLINE_DV(x, xd, x1, x1d, x2, x2d, y1, y1d, dy1, &\n& dy1d, y2, dy2, wakediameterst_mat(turbi, turb, &\n& zone), wakediameterst_matd(:, turbi, turb, zone&\n& ), nbdirs)\n ELSE IF (turbinexw(turb) .LT. turbinexw(turbi)) THEN\n DO nd=1,nbdirs\n wakediameterst_matd(nd, turbi, turb, zone) = wakediameter0d(nd&\n& ) + 2.0_dp*me(zone)*(ked(nd, turb)*deltax+ke(turb)*deltaxd(&\n& nd))\n END DO\n wakediameterst_mat(turbi, turb, zone) = wakediameter0 + 2.0_dp*&\n& ke(turb)*me(zone)*deltax\n END IF\n IF (turbinexw(turb) .LT. turbinexw(turbi)) THEN\n zone = 2\n DO nd=1,nbdirs\n wakediameterst_matd(nd, turbi, turb, zone) = wakediameter0d(nd&\n& ) + 2.0_dp*me(zone)*(ked(nd, turb)*deltax+ke(turb)*deltaxd(&\n& nd))\n END DO\n wakediameterst_mat(turbi, turb, zone) = wakediameter0 + 2.0_dp*&\n& ke(turb)*me(zone)*deltax\n zone = 3\n DO nd=1,nbdirs\n wakediameterst_matd(nd, turbi, turb, zone) = wakediameter0d(nd&\n& ) + 2.0_dp*me(zone)*(ked(nd, turb)*deltax+ke(turb)*deltaxd(&\n& nd))\n END DO\n wakediameterst_mat(turbi, turb, zone) = wakediameter0 + 2.0_dp*&\n& ke(turb)*me(zone)*deltax\n END IF\n END DO\n END DO\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Wake Overlap !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! calculate relative overlap\n CALL CALCOVERLAPAREAS_DV(nturbines, turbinexw, turbineyw, turbineywd, &\n& rotordiameter, rotordiameterd, wakediameterst_mat, &\n& wakediameterst_matd, wakecentersyt_mat, &\n& wakecentersyt_matd, wakeoverlaptrel_mat, &\n& wakeoverlaptrel_matd, nbdirs)\n DO nd=1,nbdirs\n cosfac_matd(nd, :, :, :) = 0.0\n END DO\n! calculate cosine factor TODO: put this into the same loop as velocity\n DO turbi=1,nturbines\n DO turb=1,nturbines\n IF (turbinexw(turb) .LT. turbinexw(turbi)) THEN\n DO zone=1,3\n DO nd=1,nbdirs\n rmaxd(nd) = cos_spread*0.5_dp*(wakediameterst_matd(nd, turbi&\n& , turb, 3)+rotordiameterd(nd, turbi))\n END DO\n rmax = cos_spread*0.5_dp*(wakediameterst_mat(turbi, turb, 3)+&\n& rotordiameter(turbi))\n IF (wakecentersyt_mat(turbi, turb) - turbineyw(turbi) .GE. 0.&\n& ) THEN\n DO nd=1,nbdirs\n dabs0d(nd) = wakecentersyt_matd(nd, turbi, turb) - &\n& turbineywd(nd, turbi)\n END DO\n dabs0 = wakecentersyt_mat(turbi, turb) - turbineyw(turbi)\n ELSE\n DO nd=1,nbdirs\n dabs0d(nd) = -(wakecentersyt_matd(nd, turbi, turb)-&\n& turbineywd(nd, turbi))\n END DO\n dabs0 = -(wakecentersyt_mat(turbi, turb)-turbineyw(turbi))\n END IF\n arg1 = pi*dabs0/rmax\n DO nd=1,nbdirs\n arg1d(nd) = (pi*dabs0d(nd)*rmax-pi*dabs0*rmaxd(nd))/rmax**2\n cosfac_matd(nd, turbi, turb, zone) = -(0.5_dp*arg1d(nd)*SIN(&\n& arg1))\n END DO\n cosfac_mat(turbi, turb, zone) = 0.5_dp*(1.0_dp+COS(arg1))\n END DO\n ELSE\n DO nd=1,nbdirs\n!cosFac_mat(turbI, turb, zone) = 1.0_dp\n cosfac_matd(nd, turbi, turb, :) = 0.0\n END DO\n cosfac_mat(turbi, turb, :) = 1.0_dp\n END IF\n END DO\n END DO\n DO nd=1,nbdirs\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Velocity !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! convert yaw from degrees to radians\n yawd(nd, :) = pi*yaw_degd(nd, :)/180.0_dp\n END DO\n yaw = yaw_deg*pi/180.0_dp\n IF (axialindprovided) THEN\n DO nd=1,nbdirs\n ad(nd, :) = a_ind(nd, :)\n END DO\n a = a_in\n ELSE\n CALL CTTOAXIALIND_DV(ct, ctd, nturbines, a, ad, nbdirs)\n END IF\n DO nd=1,nbdirs\n! adjust ke to Ct as adjusted to yaw\n ked(nd, :) = kecorrct*ctd(nd, :)\n END DO\n ke = ke_in + kecorrct*(ct-region2ct)\n DO nd=1,nbdirs\n kearrayd(nd, :) = 0.0\n END DO\n DO turb=1,nturbines\n arg10(:) = wakeoverlaptrel_mat(turb, :, 1) + wakeoverlaptrel_mat(&\n& turb, :, 2)\n s = SUM(arg10(:))\n DO nd=1,nbdirs\n arg10d(nd, :) = wakeoverlaptrel_matd(nd, turb, :, 1) + &\n& wakeoverlaptrel_matd(nd, turb, :, 2)\n sd(nd) = SUM(arg10d(nd, :))\n kearrayd(nd, turb) = ked(nd, turb)*(1+s*kecorrarray) + ke(turb)*&\n& kecorrarray*sd(nd)\n END DO\n kearray(turb) = ke(turb)*(1+s*kecorrarray)\n END DO\n! find effective wind speeds at downstream turbines, then predict the power of \n! downstream turbine \n velocitiesturbines = vinf\n DO nd=1,nbdirs\n velocitiesturbinesd(nd, :) = 0.0\n mmud(nd, :) = 0.0\n END DO\n DO turbi=1,nturbines\n wakeeffcoeff = 0.0_dp\n DO nd=1,nbdirs\n wakeeffcoeffd(nd) = 0.0\n END DO\n! find overlap-area weighted effect of each wake zone\n DO turb=1,nturbines\n wakeeffcoeffperzone = 0.0_dp\n DO nd=1,nbdirs\n deltaxd(nd) = turbinexwd(nd, turbi) - turbinexwd(nd, turb)\n END DO\n deltax = turbinexw(turbi) - turbinexw(turb)\n IF (useaubu) THEN\n arg1 = au*pi/180.0_dp + bu*yaw(turb)\n DO nd=1,nbdirs\n arg1d(nd) = bu*yawd(nd, turb)\n mmud(nd, :) = -((-(mu*arg1d(nd)*SIN(arg1)))/COS(arg1)**2)\n END DO\n mmu = mu/COS(arg1)\n END IF\n IF (deltax .GT. 0 .AND. turbi .NE. turb) THEN\n DO nd=1,nbdirs\n wakeeffcoeffperzoned(nd) = 0.0\n END DO\n DO zone=1,3\n IF (useaubu) THEN\n DO nd=1,nbdirs\n wakeeffcoeffperzoned(nd) = wakeeffcoeffperzoned(nd) + 2*&\n& cosfac_mat(turbi, turb, zone)*rotordiameter(turb)*((&\n& cosfac_matd(nd, turbi, turb, zone)*rotordiameter(turb)+&\n& cosfac_mat(turbi, turb, zone)*rotordiameterd(nd, turb))*&\n& (rotordiameter(turb)+2.0_dp*kearray(turb)*mmu(zone)*&\n& deltax)-cosfac_mat(turbi, turb, zone)*rotordiameter(turb&\n& )*(rotordiameterd(nd, turb)+2.0_dp*((kearrayd(nd, turb)*&\n& deltax+kearray(turb)*deltaxd(nd))*mmu(zone)+kearray(turb&\n& )*deltax*mmud(nd, zone))))*wakeoverlaptrel_mat(turbi, &\n& turb, zone)/(rotordiameter(turb)+2.0_dp*kearray(turb)*&\n& mmu(zone)*deltax)**3 + cosfac_mat(turbi, turb, zone)**2*&\n& rotordiameter(turb)**2*wakeoverlaptrel_matd(nd, turbi, &\n& turb, zone)/(rotordiameter(turb)+2.0_dp*kearray(turb)*&\n& mmu(zone)*deltax)**2\n END DO\n wakeeffcoeffperzone = wakeeffcoeffperzone + (cosfac_mat(&\n& turbi, turb, zone)*rotordiameter(turb)/(rotordiameter(turb&\n& )+2.0_dp*kearray(turb)*mmu(zone)*deltax))**2*&\n& wakeoverlaptrel_mat(turbi, turb, zone)\n ELSE\n DO nd=1,nbdirs\n wakeeffcoeffperzoned(nd) = wakeeffcoeffperzoned(nd) + 2*&\n& cosfac_mat(turbi, turb, zone)*rotordiameter(turb)*((&\n& cosfac_matd(nd, turbi, turb, zone)*rotordiameter(turb)+&\n& cosfac_mat(turbi, turb, zone)*rotordiameterd(nd, turb))*&\n& (rotordiameter(turb)+2.0_dp*kearray(turb)*mu(zone)*&\n& deltax)-cosfac_mat(turbi, turb, zone)*rotordiameter(turb&\n& )*(rotordiameterd(nd, turb)+2.0_dp*mu(zone)*(kearrayd(nd&\n& , turb)*deltax+kearray(turb)*deltaxd(nd))))*&\n& wakeoverlaptrel_mat(turbi, turb, zone)/(rotordiameter(&\n& turb)+2.0_dp*kearray(turb)*mu(zone)*deltax)**3 + &\n& cosfac_mat(turbi, turb, zone)**2*rotordiameter(turb)**2*&\n& wakeoverlaptrel_matd(nd, turbi, turb, zone)/(&\n& rotordiameter(turb)+2.0_dp*kearray(turb)*mu(zone)*deltax&\n& )**2\n END DO\n wakeeffcoeffperzone = wakeeffcoeffperzone + (cosfac_mat(&\n& turbi, turb, zone)*rotordiameter(turb)/(rotordiameter(turb&\n& )+2.0_dp*kearray(turb)*mu(zone)*deltax))**2*&\n& wakeoverlaptrel_mat(turbi, turb, zone)\n END IF\n END DO\n DO nd=1,nbdirs\n wakeeffcoeffd(nd) = wakeeffcoeffd(nd) + 2*a(turb)*&\n& wakeeffcoeffperzone*(ad(nd, turb)*wakeeffcoeffperzone+a(turb&\n& )*wakeeffcoeffperzoned(nd))\n END DO\n wakeeffcoeff = wakeeffcoeff + (a(turb)*wakeeffcoeffperzone)**2\n END IF\n END DO\n DO nd=1,nbdirs\n IF (wakeeffcoeff .EQ. 0.0) THEN\n result1d(nd) = 0.0\n ELSE\n result1d(nd) = wakeeffcoeffd(nd)/(2.0*SQRT(wakeeffcoeff))\n END IF\n wakeeffcoeffd(nd) = -(2.0_dp*result1d(nd))\n END DO\n result1 = SQRT(wakeeffcoeff)\n wakeeffcoeff = 1.0_dp - 2.0_dp*result1\n DO nd=1,nbdirs\n! multiply the inflow speed with the wake coefficients to find effective wind \n! speed at turbine\n velocitiesturbinesd(nd, turbi) = velocitiesturbinesd(nd, turbi)*&\n& wakeeffcoeff + velocitiesturbines(turbi)*wakeeffcoeffd(nd)\n END DO\n velocitiesturbines(turbi) = velocitiesturbines(turbi)*wakeeffcoeff\n END DO\n! pack desired matrices into vectors for output\n DO turbi=1,nturbines\n! wake centers\n wakecentersyt_vec(nturbines*(turbi-1)+1:nturbines*(turbi-1)+&\n& nturbines) = wakecentersyt_mat(turbi, :)\n! wake diameters\n wakediameterst_vec(3*nturbines*(turbi-1)+1:3*nturbines*(turbi-1)+&\n& nturbines) = wakediameterst_mat(turbi, :, 1)\n wakediameterst_vec(3*nturbines*(turbi-1)+nturbines+1:3*nturbines*(&\n& turbi-1)+2*nturbines) = wakediameterst_mat(turbi, :, 2)\n wakediameterst_vec(3*nturbines*(turbi-1)+2*nturbines+1:nturbines*(&\n& turbi-1)+3*nturbines) = wakediameterst_mat(turbi, :, 3)\n! relative wake overlap\n wakeoverlaptrel_vec(3*nturbines*(turbi-1)+1:3*nturbines*(turbi-1)+&\n& nturbines) = wakeoverlaptrel_mat(turbi, :, 1)\n wakeoverlaptrel_vec(3*nturbines*(turbi-1)+nturbines+1:3*nturbines*(&\n& turbi-1)+2*nturbines) = wakeoverlaptrel_mat(turbi, :, 2)\n wakeoverlaptrel_vec(3*nturbines*(turbi-1)+2*nturbines+1:3*nturbines*&\n& (turbi-1)+3*nturbines) = wakeoverlaptrel_mat(turbi, :, 3)\n END DO\nEND SUBROUTINE FLORIS_UNIFIED_DV\n\n! Differentiation of hermite_spline in forward (tangent) mode:\n! variations of useful results: y\n! with respect to varying inputs: x x0 x1 dy0 y0\n! Flow field calculations have been intentionally left out to save development time.\n! The flow field can be calculated using the pure python version of floris \n! This implementation is fully smooth and differentiable with the exception of a \n! discontinuity at the hub of each turbine. The discontinuity only presents issues if\n! turbines are place within 1E-15 * rotor diameter of one another, which is extremely \n! unlikely during optimization if the user does not explicitly place them there.\nSUBROUTINE HERMITE_SPLINE_DV(x, xd, x0, x0d, x1, x1d, y0, y0d, dy0, dy0d&\n& , y1, dy1, y, yd, nbdirs)\n \n! Hint: nbdirs should be the maximum number of differentiation directions\n IMPLICIT NONE\n!dy_dx = c3*3*x**2 + c2*2*x + c1\n! define precision to be the standard for a double precision ! on local system\n INTEGER, PARAMETER :: dp=KIND(0.d0)\n! in\n REAL(dp), INTENT(IN) :: x, x0, x1, y0, dy0, y1, dy1\n REAL(dp), DIMENSION(nbdirs), INTENT(IN) :: xd, x0d, x1d, y0d, dy0d\n! out\n!, dy_dx\n REAL(dp), INTENT(OUT) :: y\n REAL(dp), DIMENSION(nbdirs), INTENT(OUT) :: yd\n! local\n REAL(dp) :: c3, c2, c1, c0\n REAL(dp), DIMENSION(nbdirs) :: c3d, c2d, c1d, c0d\n INTRINSIC KIND\n INTEGER :: nd\n INTEGER :: nbdirs\n c3 = 2.0_dp*y1/(x0**3-3.0_dp*x0**2*x1+3.0_dp*x0*x1**2-x1**3) - 2.0_dp*&\n& y0/(x0**3-3.0_dp*x0**2*x1+3.0_dp*x0*x1**2-x1**3) + dy0/(x0**2-2.0_dp&\n& *x0*x1+x1**2) + dy1/(x0**2-2.0_dp*x0*x1+x1**2)\n c2 = 3.0_dp*y0*(x0+x1)/(x0**3-3.0_dp*x0**2*x1+3.0_dp*x0*x1**2-x1**3) -&\n& dy1*(2.0_dp*x0+x1)/(x0**2-2.0_dp*x0*x1+x1**2) - dy0*(x0+2.0_dp*x1)/(&\n& x0**2-2.0_dp*x0*x1+x1**2) - 3.0_dp*y1*(x0+x1)/(x0**3-3.0_dp*x0**2*x1&\n& +3.0_dp*x0*x1**2-x1**3)\n c1 = dy0*(x1**2+2.0_dp*x0*x1)/(x0**2-2.0_dp*x0*x1+x1**2) + dy1*(x0**2+&\n& 2.0_dp*x1*x0)/(x0**2-2.0_dp*x0*x1+x1**2) - 6.0_dp*x0*x1*y0/(x0**3-&\n& 3.0_dp*x0**2*x1+3.0_dp*x0*x1**2-x1**3) + 6.0_dp*x0*x1*y1/(x0**3-&\n& 3.0_dp*x0**2*x1+3.0_dp*x0*x1**2-x1**3)\n DO nd=1,nbdirs\n! initialize coefficients for parametric cubic spline\n c3d(nd) = (dy0d(nd)*(x0**2-2.0_dp*x0*x1+x1**2)-dy0*(2*x0*x0d(nd)-&\n& 2.0_dp*(x0d(nd)*x1+x0*x1d(nd))+2*x1*x1d(nd)))/(x0**2-2.0_dp*x0*x1+&\n& x1**2)**2 - (2.0_dp*y0d(nd)*(x0**3-3.0_dp*x0**2*x1+3.0_dp*x0*x1**2&\n& -x1**3)-2.0_dp*y0*(3*x0**2*x0d(nd)-3.0_dp*(2*x0*x0d(nd)*x1+x0**2*&\n& x1d(nd))+3.0_dp*(x0d(nd)*x1**2+x0*2*x1*x1d(nd))-3*x1**2*x1d(nd)))/&\n& (x0**3-3.0_dp*x0**2*x1+3.0_dp*x0*x1**2-x1**3)**2 - 2.0_dp*y1*(3*x0&\n& **2*x0d(nd)-3.0_dp*(2*x0*x0d(nd)*x1+x0**2*x1d(nd))+3.0_dp*(x0d(nd)&\n& *x1**2+x0*2*x1*x1d(nd))-3*x1**2*x1d(nd))/(x0**3-3.0_dp*x0**2*x1+&\n& 3.0_dp*x0*x1**2-x1**3)**2 - dy1*(2*x0*x0d(nd)-2.0_dp*(x0d(nd)*x1+&\n& x0*x1d(nd))+2*x1*x1d(nd))/(x0**2-2.0_dp*x0*x1+x1**2)**2\n c2d(nd) = (3.0_dp*(y0d(nd)*(x0+x1)+y0*(x0d(nd)+x1d(nd)))*(x0**3-&\n& 3.0_dp*x0**2*x1+3.0_dp*x0*x1**2-x1**3)-3.0_dp*y0*(x0+x1)*(3*x0**2*&\n& x0d(nd)-3.0_dp*(2*x0*x0d(nd)*x1+x0**2*x1d(nd))+3.0_dp*(x0d(nd)*x1&\n& **2+x0*2*x1*x1d(nd))-3*x1**2*x1d(nd)))/(x0**3-3.0_dp*x0**2*x1+&\n& 3.0_dp*x0*x1**2-x1**3)**2 - (dy1*(2.0_dp*x0d(nd)+x1d(nd))*(x0**2-&\n& 2.0_dp*x0*x1+x1**2)-dy1*(2.0_dp*x0+x1)*(2*x0*x0d(nd)-2.0_dp*(x0d(&\n& nd)*x1+x0*x1d(nd))+2*x1*x1d(nd)))/(x0**2-2.0_dp*x0*x1+x1**2)**2 - &\n& ((dy0d(nd)*(x0+2.0_dp*x1)+dy0*(x0d(nd)+2.0_dp*x1d(nd)))*(x0**2-&\n& 2.0_dp*x0*x1+x1**2)-dy0*(x0+2.0_dp*x1)*(2*x0*x0d(nd)-2.0_dp*(x0d(&\n& nd)*x1+x0*x1d(nd))+2*x1*x1d(nd)))/(x0**2-2.0_dp*x0*x1+x1**2)**2 - &\n& (3.0_dp*y1*(x0d(nd)+x1d(nd))*(x0**3-3.0_dp*x0**2*x1+3.0_dp*x0*x1**&\n& 2-x1**3)-3.0_dp*y1*(x0+x1)*(3*x0**2*x0d(nd)-3.0_dp*(2*x0*x0d(nd)*&\n& x1+x0**2*x1d(nd))+3.0_dp*(x0d(nd)*x1**2+x0*2*x1*x1d(nd))-3*x1**2*&\n& x1d(nd)))/(x0**3-3.0_dp*x0**2*x1+3.0_dp*x0*x1**2-x1**3)**2\n c1d(nd) = ((dy0d(nd)*(x1**2+2.0_dp*x0*x1)+dy0*(2*x1*x1d(nd)+2.0_dp*(&\n& x0d(nd)*x1+x0*x1d(nd))))*(x0**2-2.0_dp*x0*x1+x1**2)-dy0*(x1**2+&\n& 2.0_dp*x0*x1)*(2*x0*x0d(nd)-2.0_dp*(x0d(nd)*x1+x0*x1d(nd))+2*x1*&\n& x1d(nd)))/(x0**2-2.0_dp*x0*x1+x1**2)**2 + (dy1*(2*x0*x0d(nd)+&\n& 2.0_dp*(x1d(nd)*x0+x1*x0d(nd)))*(x0**2-2.0_dp*x0*x1+x1**2)-dy1*(x0&\n& **2+2.0_dp*x1*x0)*(2*x0*x0d(nd)-2.0_dp*(x0d(nd)*x1+x0*x1d(nd))+2*&\n& x1*x1d(nd)))/(x0**2-2.0_dp*x0*x1+x1**2)**2 - (6.0_dp*((x0d(nd)*x1+&\n& x0*x1d(nd))*y0+x0*x1*y0d(nd))*(x0**3-3.0_dp*x0**2*x1+3.0_dp*x0*x1&\n& **2-x1**3)-6.0_dp*x0*x1*y0*(3*x0**2*x0d(nd)-3.0_dp*(2*x0*x0d(nd)*&\n& x1+x0**2*x1d(nd))+3.0_dp*(x0d(nd)*x1**2+x0*2*x1*x1d(nd))-3*x1**2*&\n& x1d(nd)))/(x0**3-3.0_dp*x0**2*x1+3.0_dp*x0*x1**2-x1**3)**2 + (&\n& 6.0_dp*y1*(x0d(nd)*x1+x0*x1d(nd))*(x0**3-3.0_dp*x0**2*x1+3.0_dp*x0&\n& *x1**2-x1**3)-6.0_dp*x0*x1*y1*(3*x0**2*x0d(nd)-3.0_dp*(2*x0*x0d(nd&\n& )*x1+x0**2*x1d(nd))+3.0_dp*(x0d(nd)*x1**2+x0*2*x1*x1d(nd))-3*x1**2&\n& *x1d(nd)))/(x0**3-3.0_dp*x0**2*x1+3.0_dp*x0*x1**2-x1**3)**2\n c0d(nd) = ((y0d(nd)*(-(x1**3)+3.0_dp*x0*x1**2)+y0*(3.0_dp*(x0d(nd)*&\n& x1**2+x0*2*x1*x1d(nd))-3*x1**2*x1d(nd)))*(x0**3-3.0_dp*x0**2*x1+&\n& 3.0_dp*x0*x1**2-x1**3)-y0*(-(x1**3)+3.0_dp*x0*x1**2)*(3*x0**2*x0d(&\n& nd)-3.0_dp*(2*x0*x0d(nd)*x1+x0**2*x1d(nd))+3.0_dp*(x0d(nd)*x1**2+&\n& x0*2*x1*x1d(nd))-3*x1**2*x1d(nd)))/(x0**3-3.0_dp*x0**2*x1+3.0_dp*&\n& x0*x1**2-x1**3)**2 - (y1*(3.0_dp*(x1d(nd)*x0**2+x1*2*x0*x0d(nd))-3&\n& *x0**2*x0d(nd))*(x0**3-3.0_dp*x0**2*x1+3.0_dp*x0*x1**2-x1**3)-y1*(&\n& -(x0**3)+3.0_dp*x1*x0**2)*(3*x0**2*x0d(nd)-3.0_dp*(2*x0*x0d(nd)*x1&\n& +x0**2*x1d(nd))+3.0_dp*(x0d(nd)*x1**2+x0*2*x1*x1d(nd))-3*x1**2*x1d&\n& (nd)))/(x0**3-3.0_dp*x0**2*x1+3.0_dp*x0*x1**2-x1**3)**2 - (((x0d(&\n& nd)*dy0+x0*dy0d(nd))*x1**2+x0*dy0*2*x1*x1d(nd))*(x0**2-2.0_dp*x0*&\n& x1+x1**2)-x0*x1**2*dy0*(2*x0*x0d(nd)-2.0_dp*(x0d(nd)*x1+x0*x1d(nd)&\n& )+2*x1*x1d(nd)))/(x0**2-2.0_dp*x0*x1+x1**2)**2 - (dy1*(2*x0*x0d(nd&\n& )*x1+x0**2*x1d(nd))*(x0**2-2.0_dp*x0*x1+x1**2)-x0**2*x1*dy1*(2*x0*&\n& x0d(nd)-2.0_dp*(x0d(nd)*x1+x0*x1d(nd))+2*x1*x1d(nd)))/(x0**2-&\n& 2.0_dp*x0*x1+x1**2)**2\n! print *, 'c3 = ', c3\n! print *, 'c2 = ', c2\n! print *, 'c1 = ', c1\n! print *, 'c0 = ', c0\n! Solve for y and dy values at the given point\n yd(nd) = c3d(nd)*x**3 + c3*3*x**2*xd(nd) + c2d(nd)*x**2 + c2*2*x*xd(&\n& nd) + c1d(nd)*x + c1*xd(nd) + c0d(nd)\n END DO\n c0 = y0*(-(x1**3)+3.0_dp*x0*x1**2)/(x0**3-3.0_dp*x0**2*x1+3.0_dp*x0*x1&\n& **2-x1**3) - y1*(-(x0**3)+3.0_dp*x1*x0**2)/(x0**3-3.0_dp*x0**2*x1+&\n& 3.0_dp*x0*x1**2-x1**3) - x0*x1**2*dy0/(x0**2-2.0_dp*x0*x1+x1**2) - &\n& x0**2*x1*dy1/(x0**2-2.0_dp*x0*x1+x1**2)\n y = c3*x**3 + c2*x**2 + c1*x + c0\nEND SUBROUTINE HERMITE_SPLINE_DV\n\n! Differentiation of calcoverlapareas in forward (tangent) mode:\n! variations of useful results: wakeoverlaptrel_mat\n! with respect to varying inputs: rotordiameter turbiney wakediameters\n! wakecenters\nSUBROUTINE CALCOVERLAPAREAS_DV(nturbines, turbinex, turbiney, turbineyd&\n& , rotordiameter, rotordiameterd, wakediameters, wakediametersd, &\n& wakecenters, wakecentersd, wakeoverlaptrel_mat, wakeoverlaptrel_matd, &\n& nbdirs)\n \n! Hint: nbdirs should be the maximum number of differentiation directions\n IMPLICIT NONE\n! do turbI = 1, nTurbines\n! do turb = 1, nTurbines\n! do zone = 1, 3\n! print *, \"wakeOverlapTRel_mat[\", turbI, \", \", turb, \", \", zone, \"] = \", wakeOverlapTRel_mat(turbI, turb, zone)\n! end do\n! end do\n! end do\n! define precision to be the standard for a double precision ! on local system\n INTEGER, PARAMETER :: dp=KIND(0.d0)\n! in\n INTEGER, INTENT(IN) :: nturbines\n REAL(dp), DIMENSION(nturbines), INTENT(IN) :: turbinex, turbiney, &\n& rotordiameter\n REAL(dp), DIMENSION(nbdirs, nturbines), INTENT(IN) :: turbineyd, &\n& rotordiameterd\n REAL(dp), DIMENSION(nturbines, nturbines, 3), INTENT(IN) :: &\n& wakediameters\n REAL(dp), DIMENSION(nbdirs, nturbines, nturbines, 3), INTENT(IN) ::&\n& wakediametersd\n REAL(dp), DIMENSION(nturbines, nturbines), INTENT(IN) :: wakecenters\n REAL(dp), DIMENSION(nbdirs, nturbines, nturbines), INTENT(IN) :: &\n& wakecentersd\n! out \n REAL(dp), DIMENSION(nturbines, nturbines, 3), INTENT(OUT) :: &\n& wakeoverlaptrel_mat\n REAL(dp), DIMENSION(nbdirs, nturbines, nturbines, 3), INTENT(OUT) &\n& :: wakeoverlaptrel_matd\n! local\n INTEGER :: turb, turbi, zone\n REAL(dp), PARAMETER :: pi=3.141592653589793_dp, tol=0.000001_dp\n REAL(dp) :: ovdyd, ovr, ovrr, ovl, ovz\n REAL(dp), DIMENSION(nbdirs) :: ovdydd, ovrd, ovrrd, ovld, ovzd\n REAL(dp), DIMENSION(nturbines, nturbines, 3) :: wakeoverlap\n REAL(dp), DIMENSION(nbdirs, nturbines, nturbines, 3) :: &\n& wakeoverlapd\n INTRINSIC KIND\n INTRINSIC ABS\n INTRINSIC SQRT\n INTRINSIC DACOS\n REAL(dp) :: arg1\n REAL(dp), DIMENSION(nbdirs) :: arg1d\n DOUBLE PRECISION :: result1\n DOUBLE PRECISION, DIMENSION(nbdirs) :: result1d\n REAL(dp) :: arg2\n REAL(dp), DIMENSION(nbdirs) :: arg2d\n DOUBLE PRECISION :: result2\n DOUBLE PRECISION, DIMENSION(nbdirs) :: result2d\n INTEGER :: nd\n INTEGER :: nbdirs\n wakeoverlaptrel_mat = 0.0_dp\n wakeoverlap = 0.0_dp\n DO nd=1,nbdirs\n wakeoverlapd(nd, :, :, :) = 0.0\n END DO\n DO turb=1,nturbines\n DO turbi=1,nturbines\n IF (turbinex(turbi) .GT. turbinex(turb)) THEN\n DO nd=1,nbdirs\n! distance between wake center and rotor center\n ovdydd(nd) = wakecentersd(nd, turbi, turb) - turbineyd(nd, &\n& turbi)\n! rotor diameter\n ovrd(nd) = rotordiameterd(nd, turbi)/2\n END DO\n ovdyd = wakecenters(turbi, turb) - turbiney(turbi)\n ovr = rotordiameter(turbi)/2\n DO zone=1,3\n DO nd=1,nbdirs\n! wake diameter\n ovrrd(nd) = wakediametersd(nd, turbi, turb, zone)/2.0_dp\n END DO\n ovrr = wakediameters(turbi, turb, zone)/2.0_dp\n IF (ovdyd .GE. 0.) THEN\n ovdyd = ovdyd\n ELSE\n DO nd=1,nbdirs\n ovdydd(nd) = -ovdydd(nd)\n END DO\n ovdyd = -ovdyd\n END IF\n IF (ovdyd .GE. 0.0_dp + tol) THEN\n DO nd=1,nbdirs\n! calculate the distance from the wake center to the vertical line between\n! the two circle intersection points\n ovld(nd) = ((ovrrd(nd)*ovrr-ovr*ovrd(nd)-ovrd(nd)*ovr+ovrr&\n& *ovrrd(nd)+ovdydd(nd)*ovdyd+ovdyd*ovdydd(nd))*2.0_dp*&\n& ovdyd-(-(ovr*ovr)+ovrr*ovrr+ovdyd*ovdyd)*2.0_dp*ovdydd(&\n& nd))/(2.0_dp*ovdyd)**2\n END DO\n ovl = (-(ovr*ovr)+ovrr*ovrr+ovdyd*ovdyd)/(2.0_dp*ovdyd)\n ELSE\n ovl = 0.0_dp\n DO nd=1,nbdirs\n ovld(nd) = 0.0\n END DO\n END IF\n DO nd=1,nbdirs\n ovzd(nd) = ovrrd(nd)*ovrr + ovrr*ovrrd(nd) - ovld(nd)*ovl - &\n& ovl*ovld(nd)\n END DO\n ovz = ovrr*ovrr - ovl*ovl\n! Finish calculating the distance from the intersection line to the outer edge of the wake zone\n IF (ovz .GT. 0.0_dp + tol) THEN\n DO nd=1,nbdirs\n IF (ovz .EQ. 0.0) THEN\n ovzd(nd) = 0.0\n ELSE\n ovzd(nd) = ovzd(nd)/(2.0*SQRT(ovz))\n END IF\n END DO\n ovz = SQRT(ovz)\n ELSE\n ovz = 0.0_dp\n DO nd=1,nbdirs\n ovzd(nd) = 0.0\n END DO\n END IF\n IF (ovdyd .LT. ovr + ovrr) THEN\n! if the rotor overlaps the wake zone\n IF (ovl .LT. ovrr .AND. ovdyd - ovl .LT. ovr) THEN\n arg1 = ovl/ovrr\n result1 = DACOS(arg1)\n arg2 = (ovdyd-ovl)/ovr\n result2 = DACOS(arg2)\n DO nd=1,nbdirs\n arg1d(nd) = (ovld(nd)*ovrr-ovl*ovrrd(nd))/ovrr**2\n IF (arg1 .EQ. 1.0 .OR. arg1 .EQ. (-1.0)) THEN\n result1d(nd) = 0.D0\n ELSE\n result1d(nd) = -(arg1d(nd)/SQRT(1.D0-arg1**2))\n END IF\n arg2d(nd) = ((ovdydd(nd)-ovld(nd))*ovr-(ovdyd-ovl)*ovrd(&\n& nd))/ovr**2\n IF (arg2 .EQ. 1.0 .OR. arg2 .EQ. (-1.0)) THEN\n result2d(nd) = 0.D0\n ELSE\n result2d(nd) = -(arg2d(nd)/SQRT(1.D0-arg2**2))\n END IF\n wakeoverlapd(nd, turbi, turb, zone) = (ovrrd(nd)*ovrr+&\n& ovrr*ovrrd(nd))*result1 + ovrr**2*result1d(nd) + (ovrd&\n& (nd)*ovr+ovr*ovrd(nd))*result2 + ovr**2*result2d(nd) -&\n& ovdydd(nd)*ovz - ovdyd*ovzd(nd)\n END DO\n wakeoverlap(turbi, turb, zone) = ovrr*ovrr*result1 + ovr*&\n& ovr*result2 - ovdyd*ovz\n ELSE IF (ovrr .GT. ovr) THEN\n DO nd=1,nbdirs\n wakeoverlapd(nd, turbi, turb, zone) = pi*(ovrd(nd)*ovr+&\n& ovr*ovrd(nd))\n END DO\n wakeoverlap(turbi, turb, zone) = pi*ovr*ovr\n ELSE\n DO nd=1,nbdirs\n wakeoverlapd(nd, turbi, turb, zone) = pi*(ovrrd(nd)*ovrr&\n& +ovrr*ovrrd(nd))\n END DO\n wakeoverlap(turbi, turb, zone) = pi*ovrr*ovrr\n END IF\n ELSE\n DO nd=1,nbdirs\n wakeoverlapd(nd, turbi, turb, zone) = 0.0\n END DO\n wakeoverlap(turbi, turb, zone) = 0.0_dp\n END IF\n END DO\n END IF\n END DO\n END DO\n DO turb=1,nturbines\n DO turbi=1,nturbines\n DO nd=1,nbdirs\n wakeoverlapd(nd, turbi, turb, 3) = wakeoverlapd(nd, turbi, turb&\n& , 3) - wakeoverlapd(nd, turbi, turb, 2)\n wakeoverlapd(nd, turbi, turb, 2) = wakeoverlapd(nd, turbi, turb&\n& , 2) - wakeoverlapd(nd, turbi, turb, 1)\n END DO\n wakeoverlap(turbi, turb, 3) = wakeoverlap(turbi, turb, 3) - &\n& wakeoverlap(turbi, turb, 2)\n wakeoverlap(turbi, turb, 2) = wakeoverlap(turbi, turb, 2) - &\n& wakeoverlap(turbi, turb, 1)\n END DO\n END DO\n DO nd=1,nbdirs\n wakeoverlaptrel_matd(nd, :, :, :) = wakeoverlapd(nd, :, :, :)\n END DO\n wakeoverlaptrel_mat = wakeoverlap\n DO turbi=1,nturbines\n DO nd=1,nbdirs\n wakeoverlaptrel_matd(nd, turbi, :, :) = (wakeoverlaptrel_matd(nd, &\n& turbi, :, :)*pi*rotordiameter(turbi)**2/4.0_dp-&\n& wakeoverlaptrel_mat(turbi, :, :)*pi*(rotordiameterd(nd, turbi)*&\n& rotordiameter(turbi)+rotordiameter(turbi)*rotordiameterd(nd, &\n& turbi))/4.0_dp)/(pi*rotordiameter(turbi)*rotordiameter(turbi)/&\n& 4.0_dp)**2\n END DO\n wakeoverlaptrel_mat(turbi, :, :) = wakeoverlaptrel_mat(turbi, :, :)/&\n& (pi*rotordiameter(turbi)*rotordiameter(turbi)/4.0_dp)\n END DO\nEND SUBROUTINE CALCOVERLAPAREAS_DV\n\n! Differentiation of cttoaxialind in forward (tangent) mode:\n! variations of useful results: axial_induction\n! with respect to varying inputs: ct\nSUBROUTINE CTTOAXIALIND_DV(ct, ctd, nturbines, axial_induction, &\n& axial_inductiond, nbdirs)\n \n! Hint: nbdirs should be the maximum number of differentiation directions\n IMPLICIT NONE\n! define precision to be the standard for a double precision ! on local system\n INTEGER, PARAMETER :: dp=KIND(0.d0)\n! in\n INTEGER, INTENT(IN) :: nturbines\n REAL(dp), DIMENSION(nturbines), INTENT(IN) :: ct\n REAL(dp), DIMENSION(nbdirs, nturbines), INTENT(IN) :: ctd\n! local\n INTEGER :: i\n! out\n REAL(dp), DIMENSION(nturbines), INTENT(OUT) :: axial_induction\n REAL(dp), DIMENSION(nbdirs, nturbines), INTENT(OUT) :: &\n& axial_inductiond\n INTRINSIC KIND\n INTRINSIC SQRT\n REAL(dp) :: arg1\n REAL(dp), DIMENSION(nbdirs) :: arg1d\n REAL(dp) :: result1\n REAL(dp), DIMENSION(nbdirs) :: result1d\n INTEGER :: nd\n INTEGER :: nbdirs\n axial_induction = 0.0_dp\n DO nd=1,nbdirs\n axial_inductiond(nd, :) = 0.0\n END DO\n! execute\n DO i=1,nturbines\n IF (ct(i) .GT. 0.96) THEN\n arg1 = 0.0203_dp - 0.6427_dp*(0.889_dp-ct(i))\n DO nd=1,nbdirs\n! Glauert condition\n arg1d(nd) = 0.6427_dp*ctd(nd, i)\n IF (arg1 .EQ. 0.0) THEN\n result1d(nd) = 0.0\n ELSE\n result1d(nd) = arg1d(nd)/(2.0*SQRT(arg1))\n END IF\n axial_inductiond(nd, i) = result1d(nd)\n END DO\n result1 = SQRT(arg1)\n axial_induction(i) = 0.143_dp + result1\n ELSE\n arg1 = 1.0_dp - ct(i)\n DO nd=1,nbdirs\n arg1d(nd) = -ctd(nd, i)\n IF (arg1 .EQ. 0.0) THEN\n result1d(nd) = 0.0\n ELSE\n result1d(nd) = arg1d(nd)/(2.0*SQRT(arg1))\n END IF\n axial_inductiond(nd, i) = -(0.5_dp*result1d(nd))\n END DO\n result1 = SQRT(arg1)\n axial_induction(i) = 0.5_dp*(1.0_dp-result1)\n END IF\n END DO\nEND SUBROUTINE CTTOAXIALIND_DV\n\n\n", "meta": {"hexsha": "84d924de9feac92560d98dde28afe86018f902d9", "size": 104958, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "acoustic_model/optimization/florisUnified.f90", "max_stars_repo_name": "BYUFLOWLab/BPMTurbineAcoustics", "max_stars_repo_head_hexsha": "b1cd5cfda86d52dc133f7d0acd5ce13b09357c04", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-06-17T15:40:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-24T10:20:16.000Z", "max_issues_repo_path": "acoustic_model/optimization/florisUnified.f90", "max_issues_repo_name": "byuflowlab/bpm-turbine-acoustics", "max_issues_repo_head_hexsha": "b1cd5cfda86d52dc133f7d0acd5ce13b09357c04", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "acoustic_model/optimization/florisUnified.f90", "max_forks_repo_name": "byuflowlab/bpm-turbine-acoustics", "max_forks_repo_head_hexsha": "b1cd5cfda86d52dc133f7d0acd5ce13b09357c04", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.0450209844, "max_line_length": 131, "alphanum_fraction": 0.5720955049, "num_tokens": 37704, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832973, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7512143901247768}} {"text": "\n\n\n do J = 1, NUPAR\n CUPAR=UPAR(J)\n\n\t\n\t g_33j = 0.0\n\n do K = 2, NUPER - 1\n CUPER=UPER(K)\n g_33j = g_33j + UPAR(J)*(UPER(K)*DFDUPAR(K,J)-UPAR(J)*DFDUPER(K,J))\n end do\n\n\t k = 1\n g_33j = g_33j + 0.5 * UPAR(J)*(UPER(K)*DFDUPAR(K,J)-UPAR(J)*DFDUPER(K,J))\n\n\t k = nuper\n g_33j = g_33j + 0.5 * UPAR(J)*(UPER(K)*DFDUPAR(K,J)-UPAR(J)*DFDUPER(K,J))\n\t\n\t du = (uper(nuper) - uper(1))/(nuper - 1)\n\n\t ga_33(j) = g_33j * du\n\n end do\n\n! the uperp integral is now done; now do parallel\n\n\n call EQSIMPSON1D_2(NUPAR, UPAR, ga_33, g_33)\n\t\n\n\n\n", "meta": {"hexsha": "833c1e66b0912303ad750bbb10de1eccd437e63f", "size": 628, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/CQL3D_SETUP/SAVE/work.f", "max_stars_repo_name": "ORNL-Fusion/aorsa", "max_stars_repo_head_hexsha": "82bab1e3b88e10e6bd5ca9b16589b11a97dd8f39", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-03-12T13:33:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-11T08:28:46.000Z", "max_issues_repo_path": "src/CQL3D_SETUP/SAVE/work.f", "max_issues_repo_name": "ORNL-Fusion/aorsa", "max_issues_repo_head_hexsha": "82bab1e3b88e10e6bd5ca9b16589b11a97dd8f39", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 29, "max_issues_repo_issues_event_min_datetime": "2020-01-24T15:58:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T15:16:05.000Z", "max_forks_repo_path": "src/CQL3D_SETUP/SAVE/work.f", "max_forks_repo_name": "ORNL-Fusion/aorsa", "max_forks_repo_head_hexsha": "82bab1e3b88e10e6bd5ca9b16589b11a97dd8f39", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-10T16:48:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-10T16:48:52.000Z", "avg_line_length": 17.9428571429, "max_line_length": 83, "alphanum_fraction": 0.4856687898, "num_tokens": 264, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7512046821112213}} {"text": "module numz\n integer, parameter:: b8 = selected_real_kind(14)\n real(b8), parameter :: pi = 3.141592653589793239_b8\n integer gene_size\nend module \n\nmodule ran_mod\n! module contains three functions\n! ran1 returns a uniform random number between 0-1\n! spread returns random number between min - max\n! normal returns a normal distribution\n\ncontains\n function ran1() !returns random number between 0 - 1\n use numz\n implicit none\n real(b8) ran1,x\n call random_number(x) ! built in fortran 90 random number function\n ran1=x\n end function ran1\n\n function spread(min,max) !returns random number between min - max\n use numz\n implicit none\n real(b8) spread\n real(b8) min,max\n spread=(max - min) * ran1() + min\n end function spread\n \n function normal2(mean2,sigma2)\n use numz\n real :: normal2, mean2, sigma2\n real(b8) :: mean, sigma\n mean=mean2\n sigma=sigma2\n normal2=normal(mean,sigma)\n return\n end function normal2\n\n function normal(mean,sigma) !returns a normal distribution\n use numz\n implicit none\n real(b8) normal,tmp\n real(b8) mean,sigma\n integer flag\n real(b8) fac,gsave,rsq,r1,r2\n save flag,gsave\n data flag /0/\n if (flag.eq.0) then\n rsq=2.0_b8\n do while(rsq.ge.1.0_b8.or.rsq.eq.0.0_b8) ! new from for do\n r1=2.0_b8*ran1()-1.0_b8\n r2=2.0_b8*ran1()-1.0_b8\n rsq=r1*r1+r2*r2\n enddo\n fac=sqrt(-2.0_b8*log(rsq)/rsq)\n gsave=r1*fac\n tmp=r2*fac\n flag=1\n else\n tmp=gsave\n flag=0\n endif\n normal=tmp*sigma+mean\n return\n end function normal\n\nend module ran_mod \n", "meta": {"hexsha": "bf3bac0525f6858b6bdc0d44c67339a5ed417539", "size": 1809, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src_f90/random.f90", "max_stars_repo_name": "mgrecu35/cmbv7", "max_stars_repo_head_hexsha": "5fe0f2cc2a98d6fa0ce8b3864b3735b371b07958", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src_f90/random.f90", "max_issues_repo_name": "mgrecu35/cmbv7", "max_issues_repo_head_hexsha": "5fe0f2cc2a98d6fa0ce8b3864b3735b371b07958", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src_f90/random.f90", "max_forks_repo_name": "mgrecu35/cmbv7", "max_forks_repo_head_hexsha": "5fe0f2cc2a98d6fa0ce8b3864b3735b371b07958", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.2173913043, "max_line_length": 74, "alphanum_fraction": 0.5898286346, "num_tokens": 531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7511651334255819}} {"text": "FUNCTION bino(n,k,p)\n!\nIMPLICIT NONE\n!\n! Function arguments\n!\nINTEGER :: k,n\nREAL :: p\nREAL :: bino\n!\n! Local variables\n!\nREAL :: bico\nREAL*8 :: dble\nREAL :: factln\n!\n! + + + purpose + + +\n! addition to the bico function which returns binomial coefficient\n! as a floating point number.\n!\n! modification based on:\n! 'numerical recipes - the art of scientific computing',\n! w.h. press, b.p. flannery, s.a. teukolsky, w.t. vetterling\n! cambridge university press, 1986\n! pg 158\n!\n! + + + keywords + + +\n! binomial function\n!\n! + + + argument declarations + + +\n!\n!\n! + + + argument definitions + + +\n! n,k - inputs for computing binomial coefficient\n! p - probability value\n!\n! + + + local variables + + +\n!\n!\n! + + + local variable definitions + + +\n!\n! bico - computed binomial coefficient\n!\n! + + + end specifications + + +\n!\nbico = anint(exp(factln(n)-factln(k)-factln(n-k)))\nbino = bico*(p**dble(k))*((1.0-p)**dble(n-k))\n! \nEND FUNCTION bino\n", "meta": {"hexsha": "6032b2f6668373b0d8b9a733558edfc7af11ad73", "size": 1026, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Project Documents/Source Code Original/Bino.f90", "max_stars_repo_name": "USDA-ARS-WMSRU/upgm-standalone", "max_stars_repo_head_hexsha": "1ae5dee5fe2cdba97b69c19d51b1cf61ceeab3d7", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Project Documents/Source Code Original/Bino.f90", "max_issues_repo_name": "USDA-ARS-WMSRU/upgm-standalone", "max_issues_repo_head_hexsha": "1ae5dee5fe2cdba97b69c19d51b1cf61ceeab3d7", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Project Documents/Source Code Original/Bino.f90", "max_forks_repo_name": "USDA-ARS-WMSRU/upgm-standalone", "max_forks_repo_head_hexsha": "1ae5dee5fe2cdba97b69c19d51b1cf61ceeab3d7", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.52, "max_line_length": 70, "alphanum_fraction": 0.5886939571, "num_tokens": 311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.953275045356249, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7511151462640839}} {"text": "program aks\n implicit none\n\n ! Coefficients of polynomial expansion\n integer(kind=16), dimension(:), allocatable :: coeffs\n integer(kind=16) :: n\n ! Character variable for I/O\n character(len=40) :: tmp\n\n ! Point #2\n do n = 0, 7\n write(tmp, *) n\n call polynomial_expansion(n, coeffs)\n write(*, fmt='(A)', advance='no') '(x - 1)^'//trim(adjustl(tmp))//' ='\n call print_polynom(coeffs)\n end do\n\n ! Point #4\n do n = 2, 35\n if (is_prime(n)) write(*, '(I4)', advance='no') n\n end do\n write(*, *)\n\n ! Point #5\n do n = 2, 124\n if (is_prime(n)) write(*, '(I4)', advance='no') n\n end do\n write(*, *)\n\n if (allocated(coeffs)) deallocate(coeffs)\ncontains\n ! Calculate coefficients of (x - 1)^n using binomial theorem\n subroutine polynomial_expansion(n, coeffs)\n integer(kind=16), intent(in) :: n\n integer(kind=16), dimension(:), allocatable, intent(out) :: coeffs\n integer(kind=16) :: i, j\n\n if (allocated(coeffs)) deallocate(coeffs)\n\n allocate(coeffs(n + 1))\n\n do i = 1, n + 1\n coeffs(i) = binomial(n, i - 1)*(-1)**(n - i - 1)\n end do\n end subroutine\n\n ! Calculate binomial coefficient using recurrent relation, as calculation\n ! using factorial overflows too quickly.\n function binomial(n, k) result (res)\n integer(kind=16), intent(in) :: n, k\n integer(kind=16) :: res\n integer(kind=16) :: i\n\n if (k == 0) then\n res = 1\n return\n end if\n\n res = 1\n do i = 0, k - 1\n res = res*(n - i)/(i + 1)\n end do\n end function\n\n ! Outputs polynomial with given coefficients\n subroutine print_polynom(coeffs)\n integer(kind=16), dimension(:), allocatable, intent(in) :: coeffs\n integer(kind=4) :: i, p\n character(len=40) :: cbuf, pbuf\n logical(kind=1) :: non_zero\n\n if (.not. allocated(coeffs)) return\n\n non_zero = .false.\n\n do i = 1, size(coeffs)\n if (coeffs(i) .eq. 0) cycle\n\n p = i - 1\n write(cbuf, '(I40)') abs(coeffs(i))\n write(pbuf, '(I40)') p\n\n if (non_zero) then\n if (coeffs(i) .gt. 0) then\n write(*, fmt='(A)', advance='no') ' + '\n else\n write(*, fmt='(A)', advance='no') ' - '\n endif\n else\n if (coeffs(i) .gt. 0) then\n write(*, fmt='(A)', advance='no') ' '\n else\n write(*, fmt='(A)', advance='no') ' - '\n endif\n endif\n\n if (p .eq. 0) then\n write(*, fmt='(A)', advance='no') trim(adjustl(cbuf))\n elseif (p .eq. 1) then\n if (coeffs(i) .eq. 1) then\n write(*, fmt='(A)', advance='no') 'x'\n else\n write(*, fmt='(A)', advance='no') trim(adjustl(cbuf))//'x'\n end if\n else\n if (coeffs(i) .eq. 1) then\n write(*, fmt='(A)', advance='no') 'x^'//trim(adjustl(pbuf))\n else\n write(*, fmt='(A)', advance='no') &\n trim(adjustl(cbuf))//'x^'//trim(adjustl(pbuf))\n end if\n end if\n non_zero = .true.\n end do\n\n write(*, *)\n end subroutine\n\n ! Test if n is prime using AKS test. Point #3.\n function is_prime(n) result (res)\n integer(kind=16), intent (in) :: n\n logical(kind=1) :: res\n integer(kind=16), dimension(:), allocatable :: coeffs\n integer(kind=16) :: i\n\n call polynomial_expansion(n, coeffs)\n coeffs(1) = coeffs(1) + 1\n coeffs(n + 1) = coeffs(n + 1) - 1\n\n res = .true.\n\n do i = 1, n + 1\n res = res .and. (mod(coeffs(i), n) == 0)\n end do\n\n if (allocated(coeffs)) deallocate(coeffs)\n end function\nend program aks\n", "meta": {"hexsha": "5bc2c2d561924c94b075e1797c2902a54e48e9ac", "size": 3496, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/AKS-test-for-primes/Fortran/aks-test-for-primes.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/AKS-test-for-primes/Fortran/aks-test-for-primes.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/AKS-test-for-primes/Fortran/aks-test-for-primes.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 25.1510791367, "max_line_length": 75, "alphanum_fraction": 0.5483409611, "num_tokens": 1138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750360641185, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.7511151341953693}} {"text": "! fortran_free_source\n!\n! This module is part of PERFCODE, written by Bradley J Eck.\n!\nMODULE solvers \nimplicit none\ncontains\n\n!============================================================================\n! Subroutines related to solving linear systems:\n! 1. DIAGDOM_PENTA checks for diagonal dominance\n! given the bands of a penta-diagonal matrix\n! 2. GAUSS_SEIDEL_PENTA uses the Gauss-Seidel method\n! for iterative solution of a penta-diagonal system \n! of linear equations. \n! 3. THOMAS uses the tri-diagonal matrix algorithm to solve\n! a tri-diagonal linear system \n\n\n!===================================================================\n! \\\\\\\\\\\\\\\\\\\\ B E G I N S U B R O U T I N E ///////////\n! ////////// D I A G D O M _ P E N T A \\\\\\\\\\\\\\\\\\\\\\\n!===================================================================\n!\n! Purpose: Checks to see if a penta-diagonal matrix is\n! diagonally dominant. Knowing this helps select\n! a solver. The routine operates only on the bands\n! of the coefficent matrix.\nsubroutine diagdom_penta( A, B, C, D, E, n, LB, UB, diagdom)\n! A,B -- lower bands of the penta-diagonal matrix\n! C -- main diagonal\n! D,E -- upper banks of the penta-diagonal matrix\n! n -- number of unknowns (size of system)\n! LB -- lower bandwidth\n! UB -- upper bandwidth\n! tolit-- iteration tolerence\n! diagdom-- a logical that stores the result.\n!-------------------------------------------------------------------\n! VARIABLE DECLARATIONS\n\n! Arguments\ninteger, intent(in) :: n, LB, UB\nreal, intent( in ) :: A(n), B(n), C(n), D(n), E(n)\nlogical, intent(out) :: diagdom\n! Internal Variables\ninteger :: k\nreal :: T1, T2, T4, T5\nreal :: tot\n\n\n!--------------------------------------------------------------\n\n! set the logical to true, the following loop changes it if \n! a row is not diagonally dominant.\ndiagdom = .true.\n\ndo k = 1, n\n ! compute the magnitude of each term in the row of the matrix\n if( k-LB .LT. 1 ) then; T1 = 0. ; else; T1 = abs( A(k) ); endif\n if( k .EQ. 1 ) then; T2 = 0. ; else; T2 = abs( B(k) ); endif\n if( k .EQ. n ) then; T4 = 0. ; else; T4 = abs( D(k) ); endif\n if( k+UB .GT. n ) then; T5 = 0. ; else; T5 = abs( E(k) ); endif\n ! Test for diagonal dominance\n tot = T1 + T2 + T4 + T5\n if( tot .GT. abs( C(k) ) ) then\n write(*,*) 'Row ', k, 'of the matrix is not diagonally dominant'\n diagdom = .false.\n endif\nenddo\n!----------------------------------------------------------------\nend subroutine diagdom_penta\n!===================================================================\n! \\\\\\\\\\\\\\\\\\\\ E N D S U B R O U T I N E ///////////\n! ////////// D I A G D O M _ P E N T A \\\\\\\\\\\\\\\\\\\\\\\n!===================================================================\n\n!===================================================================\n! \\\\\\\\\\\\\\\\\\\\ B E G I N S U B R O U T I N E ///////////\n! ////////// G A U S S _ S E I D E L _ P E N T A \\\\\\\\\\\\\\\\\\\\\\\n!===================================================================\n\n! CAUTION -- This routine DOES NOT check convergence criteria\n! so it possible to converge to the wrong answer.\n\n\nsubroutine gauss_seidel_penta( A, B, C, D, E, F, n , LB, UB, &\n tolit, maxit, Xold, Xnew, dev, numits )\n! A,B -- lower bands of the penta-diagonal matrix\n! C -- main diagonal\n! D,E -- upper banks of the penta-diagonal matrix\n! F -- right hand side (force vector) of linear system\n! n -- number of unknowns (size of system)\n! LB -- lower bandwidth\n! UB -- upper bandwidth\n! tolit-- iteration tolerence\n! maxit-- maximum number of iterations allowed \n! Xold -- initial guess\n! Xnew -- converged solution\n! dev -- device for outputting information from the solver\n!numits-- number of iterations required to converge \n!----------------------------------------------------------------------\n!DECLARATIONS\nuse utilities, only: F_L2_NORM \n!arguments\ninteger, intent(IN) :: n, LB, UB\nreal, intent(in ) :: A(n), B(n), C(n), D(n), E(n), F(n)\nreal, intent(in ) :: tolit\ninteger, intent(in) :: maxit\nreal, intent(in) :: Xold(n) \nreal, intent(out) :: Xnew(n)\ninteger, intent(in) :: dev\ninteger, intent(out):: numits ! number of iterations required\n! internal variables\ninteger :: k ! array index\ninteger :: m ! iteration index\nreal :: T1, T2, T4, T5 ! Terms in the equation \nreal :: relchng(n) !relative change between iterations\nreal :: Xtmp(n) !temporary array to store the progressive solutions\n\n!------------------------------------------------------------------------\n\n!store the starting guess in the temporary array\nXtmp = Xold\n\n! Perform the iterative solution\ndo m = 1, maxit\n! write(*,*) ' iteration Number = ', m\n! WRITe(*,*) 'Row, T1, T2, T4, T5, Xnew'\n do k = 1, n\n ! compute terms in the expression using if statements to \n ! sort out which terms apply based on the indices\n if( k-LB .LT. 1 ) then; T1 = 0. ; else; T1 = A(k)*Xnew(k-LB); endif\n if( k .EQ. 1 ) then; T2 = 0. ; else; T2 = B(k)*Xnew(k-1 ); endif\n if( k .EQ. n ) then; T4 = 0. ; else; T4 = D(k)*Xtmp(k+1 ); endif\n if( k+UB .GT. n ) then; T5 = 0. ; else; T5 = E(k)*Xtmp(k+UB); endif\n ! Compute \n Xnew( k ) = 1./C(k) * ( F(k) - T1 - T2 - T4 - T5 )\n! write(*,10) k, T1, T2, T4, T5, Xnew( k )\n end do\n !compute relative change for this iteration\n do k = 1, n\n relchng(k) = ( Xnew(k) - Xtmp(k) ) / Xtmp(k)\n end do\n ! check for convergence\n! write(dev,*) 'GAUSS_SEIDEL_PENTA: Iteration', m, ', Max rel change:', maxval(abs(relchng)), 'L2_norm:', F_L2_Norm( relchng, n)\n if( maxval( abs( relchng ) ) .LT. tolit .AND. &\n F_L2_Norm( relchng, n) .LT. tolit ) then\n! write(dev,*) 'GAUSS_SEIDEL_PENTA: Iterations required to converge: ', m\n numits = m\n exit ! exit iteration loop\n! elseif( maxval( abs(relchng) ) .GT. tolit ) then\n else\n Xtmp = Xnew\n endif\n!end iteration loop\nend do\n! Print message if maximum number of iterations was exceeded\nif ( m .gt. maxit ) then\n write(*,*) 'GAUSS_SEIDEL_PENTA: maximum number of iterations &\n &exceeded; program will terminate.'\n STOP\nendif\n\n10 format( I12, 10f12.7 )\n\n!---------------------------------------------------------------------------\nend subroutine gauss_seidel_penta\n!============================================================================\n! \\\\\\\\\\\\\\\\\\\\ E N D S U B R O U T I N E //////////\n! ////////// G A U S S _ S E I D E L _ P E N T A \\\\\\\\\\\\\\\\\\\\\n!============================================================================\n \n\n\n\n!======================================================================\n! \\\\\\\\\\\\\\\\\\\\ B E G I N S U B R O U T I N E //////////\n! ////////// T H O M A S \\\\\\\\\\\\\\\\\\\\\n!======================================================================\nSUBROUTINE THOMAS(A,B,C,D,X,N)\ninteger :: N\nREAL A(N), B(N), C(N), D(N), X(N), Q(n+1), G(n+1)\nREAL :: WI\ninteger :: i,j \n!\n! Purpose: Solve a system of linear equations that appear\n! as a tri-diagonal matrix.\n!\n! Source: This algorithm was handed out in class.\n! Written By: Brad Eck\n! Revision 0: Original coding on 19 Feb 09\n!\n! A -- Main diagonal\n! B -- Superdiagonal\n! C -- Subdiagonal\n! D -- RHS vector\n! X -- Solution vector\n! N -- number of unknowns\n!-----------------------------------------------------------------------\n\nWI=A(1)\nG(1)=D(1)/WI\nDO I=2,n\n Q(I-1) = B(I-1)/WI\n WI = A(I) - C(I) * Q(I-1)\n G(I) = ( D(I) -C(I) * G(I-1))/WI\nEND DO\n\nX(N) = G(N)\n\nDO I=2,n\n J = N - I + 1\n X(J) = G(J) - Q(J) * X(J+1)\nEND DO\n\nEND SUBROUTINE THOMAS\n\n!=========================================================================\n! \\\\\\\\\\\\\\\\\\\\ E N D S U B R O U T I N E //////////\n! ////////// T H O M A S \\\\\\\\\\\\\\\\\\\\\n!========================================================================\n\nEND MODULE solvers\n", "meta": {"hexsha": "8afd9497917d12732e804b2fe932edb59ffd9f00", "size": 8324, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/solvers.f95", "max_stars_repo_name": "bradleyjeck/Perfcode", "max_stars_repo_head_hexsha": "13495f27f8492467f07caaa0c26ee3aee1f1c817", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/solvers.f95", "max_issues_repo_name": "bradleyjeck/Perfcode", "max_issues_repo_head_hexsha": "13495f27f8492467f07caaa0c26ee3aee1f1c817", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/solvers.f95", "max_forks_repo_name": "bradleyjeck/Perfcode", "max_forks_repo_head_hexsha": "13495f27f8492467f07caaa0c26ee3aee1f1c817", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.1607142857, "max_line_length": 131, "alphanum_fraction": 0.4555502162, "num_tokens": 2301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086368, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7511121613767028}} {"text": " \n SUBROUTINE SHTORH (IMODE,NGP,TA,PS,SIG,QA,RH,QSAT)\nC--\nC-- SUBROUTINE SHTORH (IMODE,NGP,TA,PS,SIG,QA,RH,QSAT)\nC--\nC-- Purpose: compute saturation specific humidity and \nC-- relative hum. from specific hum. (or viceversa)\nC-- Input: IMODE : mode of operation\nC-- NGP : no. of grid-points\nC-- TA : abs. temperature\nC-- PS : normalized pressure (= p/1000_hPa) [if SIG < 0]\nC-- : normalized sfc. pres. (= ps/1000_hPa) [if SIG > 0]\nC-- SIG : sigma level\nC-- QA : specific humidity in g/kg [if IMODE > 0]\nC-- RH : relative humidity [if IMODE < 0]\nC-- QSAT : saturation spec. hum. in g/kg \nC-- Output: RH : relative humidity [if IMODE > 0] \nC-- QA : specific humidity in g/kg [if IMODE < 0]\nC-- \n REAL TA(NGP), PS(*), QA(NGP), RH(NGP), QSAT(NGP)\nC\nC--- 1. Compute Qsat (g/kg) from T (degK) and normalized pres. P (= p/1000_hPa)\nC If SIG > 0, P = Ps * sigma, otherwise P = Ps(1) = const. \nC\n E0= 6.108E-3\n C1= 17.269\n C2= 21.875\n T0=273.16\n T1= 35.86\n T2= 7.66\n \n DO 110 J=1,NGP\n IF (TA(J).GE.T0) THEN\n QSAT(J)=E0*EXP(C1*(TA(J)-T0)/(TA(J)-T1))\n ELSE\n QSAT(J)=E0*EXP(C2*(TA(J)-T0)/(TA(J)-T2))\n ENDIF\n 110 CONTINUE\nC\n IF (SIG.LE.0.0) THEN\n DO 120 J=1,NGP\n QSAT(J)=622.*QSAT(J)/(PS(1)-0.378*QSAT(J))\n 120 CONTINUE\n ELSE\n DO 130 J=1,NGP\n QSAT(J)=622.*QSAT(J)/(SIG*PS(J)-0.378*QSAT(J))\n 130 CONTINUE\n ENDIF\nC\nC--- 2. Compute rel.hum. RH=Q/Qsat (IMODE>0), or Q=RH*Qsat (IMODE<0)\nC\n IF (IMODE.GT.0) THEN\n DO 210 J=1,NGP\n RH(J)=QA(J)/QSAT(J)\n 210 CONTINUE\n ELSE IF (IMODE.LT.0) THEN\n DO 220 J=1,NGP\n QA(J)=RH(J)*QSAT(J)\n 220 CONTINUE\n ENDIF\nC\t\t\t\t\n RETURN\n END\n\n SUBROUTINE ZMEDDY (NLON,NLAT,FF,ZM,EDDY)\nC\nC *** Decompose a field into zonal-mean and eddy component\nC\n REAL FF(NLON,NLAT), ZM(NLAT), EDDY(NLON,NLAT)\nC\n RNLON=1./NLON\nC\n DO 130 J=1,NLAT\nC\n ZM(J)=0.\n DO 110 I=1,NLON\n ZM(J)=ZM(J)+FF(I,J)\n 110 CONTINUE\n ZM(J)=ZM(J)*RNLON\nC\n DO 120 I=1,NLON\n EDDY(I,J)=FF(I,J)-ZM(J)\n 120 CONTINUE\nC\n 130 CONTINUE\nC\nC--\n RETURN\n END\n\n\n\n\n", "meta": {"hexsha": "538fc0381b77ae2f481db4179211446690538f4b", "size": 2403, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "models/speedy/t21/phy_shtorh.f", "max_stars_repo_name": "enino84/AMLCS", "max_stars_repo_head_hexsha": "7a37cca01c9305afb99b652baeb9e0952ebe889b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "models/speedy/t21/phy_shtorh.f", "max_issues_repo_name": "enino84/AMLCS", "max_issues_repo_head_hexsha": "7a37cca01c9305afb99b652baeb9e0952ebe889b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "models/speedy/t21/phy_shtorh.f", "max_forks_repo_name": "enino84/AMLCS", "max_forks_repo_head_hexsha": "7a37cca01c9305afb99b652baeb9e0952ebe889b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.5638297872, "max_line_length": 80, "alphanum_fraction": 0.5064502705, "num_tokens": 936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404096760998, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7510503263063446}} {"text": "subroutine SHReturnTapersMap(tapers, eigenvalues, dh_mask, n_dh, sampling, lmax, Ntapers)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis subroutine will calculate the eigenvalues and eigenfunctions of the generalized\n!\tconcentration problem where the region of interest R is given by the grid DH_MASK. This\n!\tmatrix is sampled according to the Driscoll and Healy sampling theorem, and possesses a value \n!\tof 1 inside of R, and 0 elsewhere. Returned tapers and eigenvalues are ordered from the largest\n!\tto smallest eigenvalue, and the spectral coefficients are packed into a 1D column vector\n!\taccording to the scheme described in YilmIndex.\n!\n!\tThe elements Dij are calculated approximately using spherical harmonic transforms.\n!\tThe effective bandwidth of the grid DH_MASK should in general be larger than LMAX by about a factor \n!\tof 4 or so for accurate results. In addition, as a result of the approximate manner in which\n!\tthe space-concentration kernel is calculated, it is preferable to use SAMPLING=1.\n!\tAs one test of the accuracy, the area of the input grid DH_MASK, is compared to the calculated \n!\tarea given in the elements D(1,1).\n!\n!\tCalling Parameters\n!\t\tIN\n!\t\t\tdh_mask\t\tInteger grid sampled according to the Driscoll and Healy sampling\n!\t\t\t\t\ttheorem. A value of 1 indicates the the grid node is in the concentration\n!\t\t\t\t\tdomain, and a value of 0 indicates that it is outside. Dimensioned as\n!\t\t\t\t\t(n_dh, n_dh) for SAMPLING = 1 or (n_dh, 2*n_dh) for SAMPLING = 2.\n!\t\t\tn_dh\t\tThe number of latitude samples in the Driscoll and Healy sampled grid.\n!\t\t\tSAMPLING\t1 corresponds to equal sampling (n_dh, n_dh), whereas 2 corresponds\n!\t\t\t\t\tto equal spaced grids (n_dh, 2*n_dh).\n!\t\t\tlmax\t\tMaximum spherical harmonic degree of the outpt spherical harmonic coefficients.\n!\t\tIN, OPTIONAL\n!\t\t\tntapers\t\tNumber of tapers and eigenvalues to output\n!\t\tOUT\n!\t\t\tTapers\t\tColumn vectors contain the spherical harmonic coefficients, packed according\n!\t\t\t\t\tto the scheme described in YilmIndex. The dimension of this array is \n!\t\t\t\t\t(lmax+1)**2 by (lmax+1)**2, or (lmax+1)**2 by NTapers if NTapers is present.\n!\t\t\tEigenvalues\tA 1-dimensional vector containing the eigenvalues corresponding to the columns\n!\t\t\t\t\tof Tapers, dimensioned as (lmax+1)**2.\n!\n!\tWritten by Mark Wieczorek (August 2009)\n!\n!\tCopyright (c) 2009, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\tuse SHTOOLS, only : EigValVecSym, ComputeDMap\n\t\n\timplicit none\n\t\t\n\treal*8, intent(out) ::\ttapers(:,:), eigenvalues(:)\n\tinteger, intent(in) ::\tdh_mask(:,:), n_dh, sampling, lmax\n\tinteger, intent(in), optional ::\tntapers\n\t\n\treal*8, allocatable ::\tdij(:,:)\n\tinteger ::\t\tnlat, nlong, lmax_dh, astat, i, j\n\treal*8 ::\t\tarea, areaf, pi, colat, long_int, lat_int, da\n\t\n\tpi = acos(-1.0d0)\n\t\n\tif (present(ntapers)) then\n\t\tif (ntapers > (lmax+1)**2) then\n\t\t\tprint*, \"Error --- SHRetrunTapersMap\"\n\t\t\tprint*, \"The number of output tapers must be less than or equal to (LMAX+1)**2.\"\n\t\t\tprint*, \"LMAX = \", lmax\n\t\t\tprint*, \"NTAPERS = \", ntapers\n\t\t\tstop\n\t\telseif (size(tapers(:,1)) < (lmax+1)**2 .or. size(tapers(1,:)) < ntapers) then\n\t\t\t\tprint*, \"Error --- SHReturnTapersMap\"\n\t\t\t\tprint*, \"TAPERS must be dimensioned as ((LMAX+1)**2, NTAPERS).\"\n\t\t\t\tprint*, \"Dimension of TAPERS = \", size(tapers(:,1)), size(tapers(1,:))\n\t\t\t\tprint*, \"LMAX = \", lmax\n\t\t\t\tprint*, \"NTAPERS = \", ntapers\n\t\t\t\tstop\n\t\telseif (size(eigenvalues(:)) < ntapers) then\n\t\t\tprint*, \"Error --- SHReturnTapersMap\"\n\t\t\tprint*, \"EIGENVALUES must be dimensioned as NTAPERS.\"\n\t\t\tprint*, \"Dimension of EIGENVALUES = \", size(eigenvalues)\n\t\t\tprint*, \"NTAPERS = \", ntapers\n\t\t\tstop\n\t\tendif\n\telse\n\t\tif (size(tapers(:,1)) < (lmax+1)**2 .or. size(tapers(1,:)) < (lmax+1)**2) then\n\t\t\tprint*, \"Error --- SHReturnTapersMap\"\n\t\t\tprint*, \"TAPERS must be dimensioned as ((LMAX+1)**2, (LMAX+1)**2).\"\n\t\t\tprint*, \"Dimension of TAPERS = \", size(tapers(:,1)), size(tapers(1,:))\n\t\t\tprint*, \"LMAX = \", lmax\n\t\t\tstop\n\t\telseif (size(eigenvalues(:)) < (lmax+1)**2) then\n\t\t\tprint*, \"Error --- SHReturnTapersMap\"\n\t\t\tprint*, \"EIGENVALUES must be dimensioned as (LMAX+1)**2\"\n\t\t\tprint*, \"Dimension of EIGENVALUES = \", size(eigenvalues)\n\t\t\tprint*, \"LMAX = \", lmax\n\t\t\tstop\n\t\tendif\n\tendif\n\t\n\tif (mod(n_dh,2) /= 0) then\n\t\tprint*, \"Error --- SHReturnTapersMap\"\n\t\tprint*, \"Number of samples in latitude must be even for the Driscoll and Healy sampling theorem.\"\n\t\tprint*, \"N_DH = \", n_dh\n\t\tstop\n\tendif\n\t\n\tnlat = n_dh\n\tlat_int = pi/dble(nlat)\n\tif (sampling == 1) then\n\t\tnlong = nlat\n\t\tlong_int = 2.0d0 * lat_int\n\telseif (sampling == 2) then\n\t\tnlong = 2*nlat\n\t\tlong_int = lat_int\n\telse \n\t\tprint*, \"Error --- SHReturnTapersMap\"\n\t\tprint*, \"SAMPLING must be either 1 (equally sampled) or 2 (equally spaced).\"\n\t\tprint*, \"SAMPLING = \", sampling\n\t\tstop\n\tendif\n\t\n\tif (size(dh_mask(:,1)) < nlat .or. size(dh_mask(1,:)) < nlong) then\n\t\tprint*, \"Error --- SHReturnTapersMap\"\n\t\tprint*, \"DH_MASK must be dimensioned as \", nlat, nlong\n\t\tprint*, \"Dimensions of DH_MASK are \", size(dh_mask(:,1)), size(dh_mask(1,:))\n\t\tstop\n\tendif\n\t\n\tlmax_dh = n_dh/2 - 1\n\n\tif (lmax_dh < lmax) then\n\t\tprint*, \"Error --- SHReturnTapersMap\"\n\t\tprint*, \"The effective bandwith of the input grid DH_MASK must be greater or equal than LMAX.\"\n\t\tprint*, \"Experience suggests that this should be about 4 times LMAX.\"\n\t\tprint*, \"LMAX = \", lmax\n\t\tprint*, \"Effective bandwidth of DH_MASK = (N/2 -1) = \", lmax_dh\n\t\tstop\n\tendif\n\t\n\tallocate(dij((lmax+1)**2, (lmax+1)**2), stat = astat)\n\tif (astat /= 0) then\n\t\tprint*, \"Error --- SHReturnTapersMap\"\n\t\tprint*, \"Problem allocating DIJ((LMAX+1)**2,(LMAX+1)**2)\"\n\t\tprint*, \"LMAX = \", lmax\n\t\tstop\n\tendif\n\t\n\tcall ComputeDMap(Dij, dh_mask, n_dh, sampling, lmax)\n\t\n\tif (present(ntapers)) then\n\t\tcall EigValVecSym(Dij, (lmax+1)**2, eigenvalues, tapers, k = ntapers)\n\telse\n\t\tcall EigValVecSym(Dij, (lmax+1)**2, eigenvalues, tapers)\n\tendif\n\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t! \tCheck and see how good the solutions are.\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\tarea = 0.0d0\n\tareaf = 0.0d0\n\t\n\tdo i=2, nlat\n\t\tcolat = dble(i-1)*lat_int\n\t\tdo j=1, nlong\n\t\t\tda = -( cos(colat + lat_int/2.0d0) - cos(colat - lat_int/2.0d0) ) * long_int\n\t\t\tarea = area + da\n\t\t\tif (dh_mask(i,j) == 1) areaf = areaf + da\n\t\tenddo\n\tenddo\n\n\tda = 2.0d0 * pi * (1.0d0 - cos(lat_int/2.0d0) )\n\tarea = area + 2.0d0 * da\n\tif (dh_mask(1,1) == 1) areaf = areaf + da\n\tif (dh_mask(nlat,nlong) == 1) areaf = areaf + da\n\t\n\tprint*, \"SHReturnTapersMap --- (Area of entire grid) / 4pi = \", area / 4.0d0 / pi\n\tprint*, \"SHReturnTapersMap --- (Area of DH_MASK) / 4pi = \", areaf / 4.0d0 / pi\n\tprint*, \"SHReturnTapersMap --- (Area of DH_MASK) / 4pi / D00 = \", areaf / 4.0d0 / pi / Dij(1,1)\n\n\tdeallocate(dij)\n\t\t\nend subroutine SHReturnTapersMap\n", "meta": {"hexsha": "8c1806b0b860ee6cbf4f1ca71ae722c8ddd6593a", "size": 6940, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/SHReturnTapersMap.f95", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "spherical_splines/SHTOOLS/src/SHReturnTapersMap.f95", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "spherical_splines/SHTOOLS/src/SHReturnTapersMap.f95", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 38.5555555556, "max_line_length": 104, "alphanum_fraction": 0.6383285303, "num_tokens": 2230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404116305639, "lm_q2_score": 0.8080672158638528, "lm_q1q2_score": 0.7510503257376631}} {"text": "\tProgram pai\n\tImplicit none\n\tinteger max\nc declarations\n\tReal volume, x, y, area\n\tInteger i, pi3, pi2\n\n\tprint*,'input the number for try'\n\tread(5,*) max\n\tpi2=0\nc execute\n\tDo 10 i=1, max\nC generate (x,y) within [-1,1]:\n\t x = rand()*2-1\n\t y = rand()*2-1\t\n\t If ((x*x + y*y ) .LE. 1) pi2 = pi2 + 1\n\t area = 4.0 * pi2/Real(i)\n\n \t if(mod(i,1000).eq.1) Write(6,100) i, area\n 10 \tContinue\n\n Write(6,100) max, area\n100\tformat(1x,'try= ',i8,2x,'pai=',f8.4)\n\tstop\n\tend\n \t\n", "meta": {"hexsha": "3bec0de4c47a296fb39bc91350cf97754ad351f9", "size": 478, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Math3/pi2d.f", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/pi2d.f", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/pi2d.f", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.7037037037, "max_line_length": 46, "alphanum_fraction": 0.5774058577, "num_tokens": 205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216356, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.7510503118388862}} {"text": " program int_expr\n implicit none\n integer zero, one, two, a, b, c, d\n\n zero = 0\n one = 1\n two = 2\n\n if (zero .ne. 0 .or. one .ne. 1 .or. two .ne. 2) goto 99\n\n zero = zero**zero + (-one/one)\n if (zero .ne. 0) goto 99\n\n one = +one*one + 0 + zero*one + one - 1\n if (one .ne. 1) goto 99\n\n one = one**one + one**two/4\n if (one .ne. 1) goto 99\n\n two = two**two/two+zero+two**zero-one\n if (two .ne. 2) goto 99\n\n a = one*(one - 2)\n if (a .ne. -1) goto 99\n\n b = -a\n if (b .ne. 1) goto 99\n\n c = 13*a/4\n d = 13*b/4\n if (c .ne. -3 .or. d .ne. 3) goto 99\n\n c = +1.01*one\n d = +1.99*one\n\n if (c .ne. 1 .or. d .ne. 1) goto 99\n\n c = -1.01*two\n d = -1.99*two\n\n if (c .ne. -2 .or. d .ne. -3) goto 99\n\nC These tests passes\n goto 100\n\nC These tests failed\n99 stop 1\n\n100 end program\n", "meta": {"hexsha": "9690d1244c7bffb742fd7b77a5a7c6576246f822", "size": 1002, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/executable/integer_expressions.f", "max_stars_repo_name": "OpenFortranProject/ofp-sdf", "max_stars_repo_head_hexsha": "202591cf4ac4981b21ddc38c7077f9c4d1c16f54", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2015-03-05T14:41:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-22T23:51:25.000Z", "max_issues_repo_path": "tests/executable/integer_expressions.f", "max_issues_repo_name": "OpenFortranProject/ofp-sdf", "max_issues_repo_head_hexsha": "202591cf4ac4981b21ddc38c7077f9c4d1c16f54", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 33, "max_issues_repo_issues_event_min_datetime": "2015-11-05T09:50:04.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-10T21:32:48.000Z", "max_forks_repo_path": "tests/executable/integer_expressions.f", "max_forks_repo_name": "OpenFortranProject/ofp-sdf", "max_forks_repo_head_hexsha": "202591cf4ac4981b21ddc38c7077f9c4d1c16f54", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2015-06-24T01:22:58.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-16T06:47:15.000Z", "avg_line_length": 20.04, "max_line_length": 65, "alphanum_fraction": 0.4161676647, "num_tokens": 391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898305367524, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.7510101247334589}} {"text": "program ejemplo2\n use iso_fortran_env, only: wp => real64\n use roots, only: fzero\n implicit none (type, external)\n real(wp) :: a,b\n real(wp) :: rerror, aerror\n integer :: code\n\n a = 3.0_wp\n b = 4.0_wp\n rerror = 5.0e-8_wp\n aerror = 0.0_wp\n\n call fzero ( f, a, b, rerror, aerror, code )\n write(*,'(a,i0)') 'Code = ', code\n write(*,'(a,g0)') 'Root = ', a\n\ncontains\n\n real(wp) function f(x)\n real(wp), intent(in) :: x\n f = 1.0_wp/( x - 3.0_wp ) - 6.0_wp\n end function f\n\nend program ejemplo2\n", "meta": {"hexsha": "fb6d4e9f4c08b1e168ab064f25f4f73926836920", "size": 509, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/ejemplo2.f90", "max_stars_repo_name": "pjs-f/roots", "max_stars_repo_head_hexsha": "0cfdd5d314624dc03b3aaedd1b1b3a3604b8d86c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/ejemplo2.f90", "max_issues_repo_name": "pjs-f/roots", "max_issues_repo_head_hexsha": "0cfdd5d314624dc03b3aaedd1b1b3a3604b8d86c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/ejemplo2.f90", "max_forks_repo_name": "pjs-f/roots", "max_forks_repo_head_hexsha": "0cfdd5d314624dc03b3aaedd1b1b3a3604b8d86c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.5769230769, "max_line_length": 46, "alphanum_fraction": 0.5933202358, "num_tokens": 206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7510101216803943}} {"text": "MODULE NEWTON_MOD\r\nIMPLICIT NONE\r\nPUBLIC :: F, FP\r\nCONTAINS\r\n!==============================================================================\r\nFUNCTION F(X,URef,RefHt,HubHt) RESULT (Y)\r\nUSE NWTC_Library\r\nREAL(ReKi), INTENT(IN) :: X\r\n!REAL(ReKi), INTENT(IN) :: V_10\r\nREAL(ReKi), INTENT(IN) :: URef\r\nREAL(ReKi), INTENT(IN) :: RefHt\r\nREAL(ReKi), INTENT(IN) :: HubHt\r\nREAL(ReKi) :: Y\r\nREAL(ReKi) :: C_1\r\nREAL(ReKi) :: C_2\r\nREAL(ReKi) :: D_1\r\nREAL(ReKi) :: D_2\r\nREAL(ReKi) :: D_3\r\nREAL(ReKi) :: D_4\r\n\r\nIF ( EqualRealNos( RefHt, 10.0_ReKi ) ) THEN\r\n C_1=1.0-0.41*0.06*LOG(600.0/3600.0)\r\n C_2=0.41*0.06*0.043*LOG(600.0/3600.0)\r\n Y=C_1*X-C_2*X*X-URef\r\nELSEIF ( EqualRealNos( RefHt, HubHt) ) THEN\r\n D_1=1.0-0.41*0.06*LOG(600.0/3600.0)*(RefHt/10.0)**(-0.22)\r\n D_2=0.41*0.06*0.043*LOG(600.0/3600.0)*(RefHt/10.0)**(-0.22)\r\n D_3=D_1*0.0573*LOG(RefHt/10.0)\r\n D_4=D_2*0.0573*LOG(RefHt/10.0)\r\n Y=D_1*X-D_2*X*X+D_3*X*(1.0+0.15*X)**0.5-D_4*X*X*(1.0+0.15*X)**0.5-URef \r\nELSE\r\n Y = -9999999 \r\nENDIF\r\n\r\nEND FUNCTION F\r\n!==============================================================================\r\nFUNCTION FP(X,URef,RefHt,HubHt) RESULT (Y)\r\nUSE NWTC_Library\r\nREAL(ReKi), INTENT(IN) :: X\r\nREAL(ReKi), INTENT(IN) :: URef\r\nREAL(ReKi), INTENT(IN) :: RefHt\r\nREAL(ReKi), INTENT(IN) :: HubHt\r\nREAL(ReKi) :: Y\r\nREAL(ReKi) :: C_1\r\nREAL(ReKi) :: C_2\r\nREAL(ReKi) :: D_1\r\nREAL(ReKi) :: D_2\r\nREAL(ReKi) :: D_3\r\nREAL(ReKi) :: D_4\r\n\r\nIF ( EqualRealNos( RefHt, 10.0_ReKi ) ) THEN\r\n C_1 = 1.0-0.41*0.06*LOG(600.0/3600.0)\r\n C_2 = 0.41*0.06*0.043*LOG(600.0/3600.0)\r\n Y = C_1-2.0*C_2*X\r\nELSEIF ( EqualRealNos( RefHt, HubHt) ) THEN\r\n C_1 = 1.0 - 0.41 * 0.06 * LOG(600.0/3600.0)\r\n C_2 = 0.41 * 0.06*0.043 * LOG(600.0/3600.0)\r\n D_1 = 1.0-0.41*0.06*LOG(600.0/3600.0)*(RefHt/10.0)**(-0.22)\r\n D_2 = 0.41*0.06*0.043*LOG(600.0/3600.0)*(RefHt/10.0)**(-0.22)\r\n D_3 = D_1*0.0573*LOG(RefHt/10.0)\r\n D_4 = D_2*0.0573*LOG(RefHt/10.0)\r\n Y = D_1-2.0*D_2*X+D_3*((1.0+0.15*X)**0.5+0.15*X/2.0/(1.0+0.15*X)**0.5) &\r\n -D_4*(2.0*X*(1.0+0.15*X)**0.5+0.15*X*X/2.0/(1.0+0.15*X)**0.5)\r\nELSE\r\n Y = -9999999\r\nENDIF\r\n\r\nEND FUNCTION FP\r\n!==============================================================================\r\nEND MODULE NEWTON_MOD\r\n \r\n \r\nSUBROUTINE ROOT_SEARCHING(X0,X,URef,RefHt,HubHt)\r\nUSE NEWTON_MOD\r\nUSE NWTC_Library\r\nIMPLICIT NONE\r\n\r\nREAL(ReKi), PARAMETER :: TOL=1.0E-5\r\n\r\nREAL(ReKi), INTENT(IN ) :: URef\r\nREAL(ReKi), INTENT(IN ) :: RefHt\r\nREAL(ReKi), INTENT(IN ) :: HubHt\r\nREAL(ReKi), INTENT(IN ) :: X0\r\nREAL(ReKi), INTENT( OUT) :: X\r\n\r\nX=X0\r\nDO ! bjj: I'd like this better if there were absolutely no way to have an infinite loop here...\r\n X = X - F(X,URef,RefHt,HubHt) / FP(X,URef,RefHt,HubHt)\r\n IF (ABS(F(X,URef,RefHt,HubHt)) < TOL) THEN\r\n EXIT\r\n END IF\r\n \r\nEND DO\r\nEND SUBROUTINE ROOT_SEARCHING\r\n \r\n \r\n\r\n ", "meta": {"hexsha": "5eb7d22eb9263e5cecddcf4bda13dd93b0a4462f", "size": 3026, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "modules-local/turbsim/src/Root_Searching.f90", "max_stars_repo_name": "RFeil/openfast_distributed_aero_control", "max_stars_repo_head_hexsha": "0d071ec764a6e8b697b6e1a7e3e4baa52e298e4d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-03-06T13:45:38.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-06T13:45:38.000Z", "max_issues_repo_path": "modules-local/turbsim/src/Root_Searching.f90", "max_issues_repo_name": "RFeil/openfast_distributed_aero_control", "max_issues_repo_head_hexsha": "0d071ec764a6e8b697b6e1a7e3e4baa52e298e4d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "modules-local/turbsim/src/Root_Searching.f90", "max_forks_repo_name": "RFeil/openfast_distributed_aero_control", "max_forks_repo_head_hexsha": "0d071ec764a6e8b697b6e1a7e3e4baa52e298e4d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.8775510204, "max_line_length": 97, "alphanum_fraction": 0.5122273629, "num_tokens": 1318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.7509260055767677}} {"text": "program ex3p2\r\n use mt_mod\r\n implicit none\r\n integer, parameter:: ik=selected_int_kind(11), rk=selected_real_kind(11,100)\r\n real(kind=rk), parameter :: pi = 4.0*atan(1.0)\r\n real(kind=rk) :: fsum=0, fmean, V, r=1, err\r\n integer(kind=ik), parameter :: N=100000\r\n integer(kind=ik) :: d, i\r\n\r\n call init_genrand64(int(123465, ik))\r\n\r\n do d=1, 15\r\n !Count the number of hits\r\n do i=1, N \r\n fsum=fsum+f(d)\r\n end do\r\n\r\n !Get the statistics, formula for error from lecture notes\r\n fmean=fsum/N\r\n err=(2*r)**d*sqrt(fsum-fsum**2/N)/N\r\n\r\n !Volume, with V_e being the volume of a n-cube (or d-cube with these variables)\r\n V=(2*r)**d*fmean\r\n\r\n !Print results and reset sum for next dimension\r\n print('(A, I2, 4X, A, f6.4, 4X, A, f6.4)'),\"Dimension: \",d,\"Volume: \",V,\"Error: +/- \",err\r\n fsum=0\r\n end do\r\n\r\ncontains\r\nreal(kind=rk) function f(dim)\r\n integer(kind=ik), intent(in) :: dim\r\n integer(kind=ik) :: k\r\n real(kind=rk), dimension(dim) :: arr\r\n real(kind=rk) :: sq\r\n\r\n !Generate a list of random points on interval [-r, r] based on given dimension\r\n arr=[((r*(2*genrand64_real1()-1))**2, k=1, dim, 1)]\r\n\r\n !Check if the random coordinates hit inside the sphere\r\n sq=sum(arr)\r\n if(sq<(r*r)) then\r\n f=1 !hit\r\n else\r\n f=0 !no hit\r\n end if\r\nend function f\r\nend program ex3p2\r\n", "meta": {"hexsha": "803e1941551a9c2f3deabf4bb5057d3666a1d302", "size": 1435, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Nico_Toikka_ex3/p2/ex3p2.f95", "max_stars_repo_name": "toicca/basics-of-mc", "max_stars_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Nico_Toikka_ex3/p2/ex3p2.f95", "max_issues_repo_name": "toicca/basics-of-mc", "max_issues_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Nico_Toikka_ex3/p2/ex3p2.f95", "max_forks_repo_name": "toicca/basics-of-mc", "max_forks_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2857142857, "max_line_length": 98, "alphanum_fraction": 0.5672473868, "num_tokens": 460, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897459384731, "lm_q2_score": 0.798186768138228, "lm_q1q2_score": 0.7509259268082145}} {"text": "program floor_02\n real, parameter :: a1 = 3.3 ! 3\n real, parameter :: a2 = 3.5 ! 3\n real, parameter :: a3 = 3.7 ! 3\n real, parameter :: b1 = -3.3 ! -4\n real, parameter :: b2 = -3.5 ! -4\n real, parameter :: b3 = -3.7 ! -4\n integer, parameter :: x1 = floor(a1) ! 3\n integer, parameter :: x2 = floor(a2) ! 3\n integer, parameter :: x3 = floor(a3) ! 3\n integer, parameter :: y1 = floor(b1) ! -4\n integer, parameter :: y2 = floor(b2) ! -4\n integer, parameter :: y3 = floor(b3) ! -4\n print*, x1, x2, x3\n print*, y1, y2, y3\nend program\n", "meta": {"hexsha": "008d34f650e078df4390b92206d5fa3879219104", "size": 542, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/floor_02.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/floor_02.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/floor_02.f90", "max_forks_repo_name": "Thirumalai-Shaktivel/lfortran", "max_forks_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-03-28T19:40:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:28:55.000Z", "avg_line_length": 31.8823529412, "max_line_length": 43, "alphanum_fraction": 0.573800738, "num_tokens": 224, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037323284109, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.7507496359545967}} {"text": " subroutine asset_path ( s0, mu, sigma, t1, n, seed, s )\n\nc*********************************************************************72\nc\ncc ASSET_PATH simulates the behavior of an asset price over time.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 17 February 2012\nc\nc Author:\nc\nc Original MATLAB version by Desmond Higham.\nc FORTRAN77 version by John Burkardt.\nc\nc Reference:\nc\nc Desmond Higham,\nc Black-Scholes for Scientific Computing Students,\nc Computing in Science and Engineering,\nc November/December 2004, Volume 6, Number 6, pages 72-79.\nc\nc Parameters:\nc\nc Input, double precision S0, the asset price at time 0.\nc\nc Input, double precision MU, the expected growth rate.\nc\nc Input, double precision SIGMA, the volatility of the asset.\nc\nc Input, double precision T1, the expiry date.\nc\nc Input, integer N, the number of steps to take between 0 and T1.\nc\nc Input/output, integer SEED, a seed for the random number generator.\nc\nc Output, double precision S(0:N), the option values from time 0 to T1 \nc in equal steps.\nc\n implicit none\n\n integer n\n\n double precision dt\n integer i\n double precision mu\n double precision p\n double precision r(n)\n double precision s(0:n)\n double precision s0\n integer seed\n double precision sigma\n double precision t1\n\n dt = t1 / dble ( n )\n\n call r8vec_normal_01 ( n, seed, r )\n\n s(0) = s0\n p = s0\n do i = 1, n\n p = p * exp ( ( mu - sigma * sigma ) * dt \n & + sigma * sqrt ( dt ) * r(i) )\n s(i) = p\n end do\n\n return\n end\n subroutine binomial ( s0, e, r, sigma, t1, m, c )\n\nc*********************************************************************72\nc\ncc BINOMIAL uses the binomial method for a European call.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 17 February 2012\nc\nc Author:\nc\nc Original MATLAB version by Desmond Higham.\nc FORTRAN77 version by John Burkardt.\nc\nc Reference:\nc\nc Desmond Higham,\nc Black-Scholes for Scientific Computing Students,\nc Computing in Science and Engineering,\nc November/December 2004, Volume 6, Number 6, pages 72-79.\nc\nc Parameters:\nc\nc Input, double precision S0, the asset price at time 0.\nc\nc Input, double precision E, the exercise price.\nc\nc Input, double precision R, the interest rate.\nc\nc Input, double precision SIGMA, the volatility of the asset.\nc\nc Input, double precision T1, the expiry date.\nc\nc Input, integer M, the number of steps to take \nc between 0 and T1.\nc\nc Output, double precision C, the option value at time 0.\nc\n implicit none\n\n double precision a\n double precision b\n double precision c\n double precision d\n double precision dt\n double precision e\n integer i\n integer m\n integer n\n double precision p\n double precision r\n double precision s0\n double precision sigma\n double precision t1\n double precision u\n double precision w(1:m+1)\nc\nc Time stepsize.\nc\n dt = t1 / dble ( m )\n\n a = 0.5D+00 * ( exp ( - r * dt ) + exp ( ( r + sigma**2 ) * dt ) )\n\n d = a - sqrt ( a * a - 1.0D+00 )\n u = a + sqrt ( a * a - 1.0D+00 )\n\n p = ( exp ( r * dt ) - d ) / ( u - d )\n\n do i = 1, m + 1\n w(i) = max ( s0 * d**(m+1-i) * u**(i-1) - e, 0.0D+00 )\n end do\nc\nc Trace backwards to get the option value at time 0.\nc\n do n = m, 1, -1\n do i = 1, n\n w(i) = ( 1.0D+00 - p ) * w(i) + p * w(i+1)\n end do\n end do\n\n do i = 1, m + 1\n w(i) = exp ( - r * t1 ) * w(i)\n end do\n\n c = w(1)\n\n return\n end\n subroutine bsf ( s0, t0, e, r, sigma, t1, c )\n\nc*********************************************************************72\nc\ncc BSF evaluates the Black-Scholes formula for a European call.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 17 February 2012\nc\nc Author:\nc\nc Original MATLAB version by Desmond Higham.\nc FORTRAN77 version by John Burkardt.\nc\nc Reference:\nc\nc Desmond Higham,\nc Black-Scholes for Scientific Computing Students,\nc Computing in Science and Engineering,\nc November/December 2004, Volume 6, Number 6, pages 72-79.\nc\nc Parameters:\nc\nc Input, double precision S0, the asset price at time T0.\nc\nc Input, double precision T0, the time at which the asset price is known.\nc\nc Input, double precision E, the exercise price.\nc\nc Input, double precision R, the interest rate.\nc\nc Input, double precision SIGMA, the volatility of the asset.\nc\nc Input, double precision T1, the expiry date.\nc\nc Output, double precision C, the value of the call option.\nc\n implicit none\n\n double precision c\n double precision d1\n double precision d2\n double precision e\n double precision n1\n double precision n2\n double precision r\n double precision s0\n double precision sigma\n double precision t0\n double precision t1\n double precision tau\n\n tau = t1 - t0\n\n if ( 0.0D+00 .lt. tau ) then\n\n d1 = ( log ( s0 / e ) + ( r + 0.5D+00 * sigma * sigma ) * tau )\n & / ( sigma * sqrt ( tau ) )\n\n d2 = d1 - sigma * sqrt ( tau )\n\n n1 = 0.5D+00 * ( 1.0D+00 + erf ( d1 / sqrt ( 2.0D+00 ) ) )\n n2 = 0.5D+00 * ( 1.0D+00 + erf ( d2 / sqrt ( 2.0D+00 ) ) )\n\n c = s0 * n1 - e * exp ( - r * tau ) * n2\n\n else\n\n c = max ( s0 - e, 0.0D+00 )\n\n end if\n\n return\n end\n subroutine forward ( e, r, sigma, t1, nx, nt, smax, u )\n\nc*********************************************************************72\nc\ncc FORWARD uses the forward difference method to value a European call option.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 17 February 2012\nc\nc Author:\nc\nc Original MATLAB version by Desmond Higham.\nc FORTRAN77 version by John Burkardt.\nc\nc Reference:\nc\nc Desmond Higham,\nc Black-Scholes for Scientific Computing Students,\nc Computing in Science and Engineering,\nc November/December 2004, Volume 6, Number 6, pages 72-79.\nc\nc Parameters:\nc\nc Input, double precision E, the exercise price.\nc\nc Input, double precision R, the interest rate.\nc\nc Input, double precision SIGMA, the volatility of the asset.\nc\nc Input, double precision T1, the expiry date.\nc\nc Input, integer NX, the number of \"space\" steps used to \nc divide the interval [0,L].\nc\nc Input, integer NT, the number of time steps.\nc\nc Input, double precision SMAX, the maximum value of S to consider.\nc\nc Output, double precision U(NX-1,NT+1), the value of the European \nc call option.\nc\n implicit none\n\n integer nt\n integer nx\n\n double precision a(2:nx-1)\n double precision b(1:nx-1)\n double precision c(1:nx-2)\n double precision dt\n double precision dx\n double precision e\n integer i\n integer j\n double precision p\n double precision r\n double precision sigma\n double precision smax\n double precision t\n double precision t1\n double precision u(nx-1,nt+1)\n double precision u0\n\n dt = t1 / dble ( nt )\n dx = smax / dble ( nx )\n\n do i = 1, nx - 1\n b(i) = 1.0D+00 - r * dt - dt * ( sigma * i )**2\n end do\n\n do i = 1, nx - 2\n c(i) = 0.5D+00 * dt * ( sigma * i )**2 + 0.5D+00 * dt * r * i\n end do\n\n do i = 2, nx - 1\n a(i) = 0.5D+00 * dt * ( sigma * i )**2 - 0.5D+00 * dt * r * i\n end do\n\n u0 = 0.0D+00\n do i = 1, nx - 1\n u0 = u0 + dx\n u(i,1) = max ( u0 - e, 0.0D+00 )\n end do\n \n do j = 1, nt\n\n t = dble ( j - 1 ) * t1 / dble ( nt )\n\n p = 0.5D+00 * dt * ( nx - 1 ) \n & * ( sigma * sigma * ( nx - 1 ) + r ) \n & * ( smax - e * exp ( - r * t ) )\n\n do i = 1, nx - 1\n u(i,j+1) = b(i) * u(i,j)\n end do\n\n do i = 1, nx - 2\n u(i,j+1) = u(i,j+1) + c(i) * u(i+1,j)\n end do\n\n do i = 2, nx - 1\n u(i,j+1) = u(i,j+1) + a(i) * u(i-1,j)\n end do\n\n u(nx-1,j+1) = u(nx-1,j+1) + p\n\n end do\n\n return\n end\n subroutine get_unit ( iunit )\n\nc*********************************************************************72\nc\ncc GET_UNIT returns a free FORTRAN unit number.\nc\nc Discussion:\nc\nc A \"free\" FORTRAN unit number is a value between 1 and 99 which\nc is not currently associated with an I/O device. A free FORTRAN unit\nc number is needed in order to open a file with the OPEN command.\nc\nc If IUNIT = 0, then no free FORTRAN unit could be found, although\nc all 99 units were checked (except for units 5, 6 and 9, which\nc are commonly reserved for console I/O).\nc\nc Otherwise, IUNIT is a value between 1 and 99, representing a\nc free FORTRAN unit. Note that GET_UNIT assumes that units 5 and 6\nc are special, and will never return those values.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 02 September 2013\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Output, integer IUNIT, the free unit number.\nc\n implicit none\n\n integer i\n integer iunit\n logical value\n\n iunit = 0\n\n do i = 1, 99\n\n if ( i .ne. 5 .and. i .ne. 6 .and. i .ne. 9 ) then\n\n inquire ( unit = i, opened = value, err = 10 )\n\n if ( .not. value ) then\n iunit = i\n return\n end if\n\n end if\n\n10 continue\n\n end do\n\n return\n end\n subroutine mc ( s0, e, r, sigma, t1, m, seed, conf )\n\nc*********************************************************************72\nc\ncc MC uses Monte Carlo valuation on a European call.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 17 February 2012\nc\nc Author:\nc\nc Original MATLAB version by Desmond Higham.\nc FORTRAN77 version by John Burkardt.\nc\nc Reference:\nc\nc Desmond Higham,\nc Black-Scholes for Scientific Computing Students,\nc Computing in Science and Engineering,\nc November/December 2004, Volume 6, Number 6, pages 72-79.\nc\nc Parameters:\nc\nc Input, double precision S0, the asset price at time 0.\nc\nc Input, double precision E, the exercise price.\nc\nc Input, double precision R, the interest rate.\nc\nc Input, double precision SIGMA, the volatility of the asset.\nc\nc Input, double precision T1, the expiry date.\nc\nc Input, integer M, the number of simulations.\nc\nc Input/output, integer SEED, a seed for the random\nc number generator.\nc\nc Output, double precision CONF(2), the estimated range of the valuation.\nc\n implicit none\n\n integer m\n\n double precision conf(2)\n double precision e\n integer i\n double precision pmean\n double precision pvals(m)\n double precision r\n double precision s0\n integer seed\n double precision sigma\n double precision std\n double precision svals(m)\n double precision t1\n double precision u(m)\n double precision width\n\n call r8vec_normal_01 ( m, seed, u )\n\n do i = 1, m\n svals(i) = s0 * exp ( ( r - 0.5D+00 * sigma * sigma ) * t1 \n & + sigma * sqrt ( t1 ) * u(i) )\n end do\n\n do i = 1, m\n pvals(i) = exp ( - r * t1 ) * max ( svals(i) - e, 0.0D+00 )\n end do\n\n pmean = 0.0D+00\n do i = 1, m\n pmean = pmean + pvals(i)\n end do\n pmean = pmean / dble ( m )\n\n std = 0.0D+00\n do i = 1, m\n std = std + ( pvals(i) - pmean ) ** 2\n end do\n std = sqrt ( std / dble ( m - 1 ) )\n\n width = 1.96D+00 * std / sqrt ( dble ( m ) )\n\n conf(1) = pmean - width\n conf(2) = pmean + width\n\n return\n end\n function r8_normal_01 ( seed )\n\nc*********************************************************************72\nc\ncc R8_NORMAL_01 returns a unit pseudonormal R8.\nc\nc Discussion:\nc\nc Because this routine uses the Box Muller method, it requires pairs\nc of uniform random values to generate a pair of normal random values.\nc This means that on every other call, the code can use the second\nc value that it calculated.\nc\nc However, if the user has changed the SEED value between calls,\nc the routine automatically resets itself and discards the saved data.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 08 January 2007\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input/output, integer SEED, a seed for the random number generator.\nc\nc Output, double precision R8_NORMAL_01, a sample of the standard normal PDF.\nc\n implicit none\n\n double precision pi\n parameter ( pi = 3.141592653589793D+00 )\n double precision r1\n double precision r2\n double precision r8_normal_01\n double precision r8_uniform_01\n integer seed\n integer seed1\n integer seed2\n integer seed3\n integer used\n double precision v1\n double precision v2\n\n save seed1\n save seed2\n save seed3\n save used\n save v2\n\n data seed2 / 0 /\n data used / 0 /\n data v2 / 0.0D+00 /\nc\nc If USED is odd, but the input SEED does not match\nc the output SEED on the previous call, then the user has changed\nc the seed. Wipe out internal memory.\nc\n if ( mod ( used, 2 ) .eq. 1 ) then\n\n if ( seed .ne. seed2 ) then\n used = 0\n seed1 = 0\n seed2 = 0\n seed3 = 0\n v2 = 0.0D+00\n end if\n\n end if\nc\nc If USED is even, generate two uniforms, create two normals,\nc return the first normal and its corresponding seed.\nc\n if ( mod ( used, 2 ) .eq. 0 ) then\n\n seed1 = seed\n\n r1 = r8_uniform_01 ( seed )\n\n if ( r1 .eq. 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_NORMAL_01 - Fatal error!'\n write ( *, '(a)' ) ' R8_UNIFORM_01 returned a value of 0.'\n stop\n end if\n\n seed2 = seed\n\n r2 = r8_uniform_01 ( seed )\n\n seed3 = seed\n\n v1 = sqrt ( -2.0D+00 * log ( r1 ) ) * cos ( 2.0D+00 * pi * r2 )\n v2 = sqrt ( -2.0D+00 * log ( r1 ) ) * sin ( 2.0D+00 * pi * r2 )\n\n r8_normal_01 = v1\n seed = seed2\nc\nc If USED is odd (and the input SEED matched the output value from\nc the previous call), return the second normal and its corresponding seed.\nc\n else\n\n r8_normal_01 = v2\n seed = seed3\n\n end if\n\n used = used + 1\n\n return\n end\n function r8_uniform_01 ( seed )\n\nc*********************************************************************72\nc\ncc R8_UNIFORM_01 returns a unit pseudorandom R8.\nc\nc Discussion:\nc\nc This routine implements the recursion\nc\nc seed = 16807 * seed mod ( 2**31 - 1 )\nc r8_uniform_01 = seed / ( 2**31 - 1 )\nc\nc The integer arithmetic never requires more than 32 bits,\nc including a sign bit.\nc\nc If the initial seed is 12345, then the first three computations are\nc\nc Input Output R8_UNIFORM_01\nc SEED SEED\nc\nc 12345 207482415 0.096616\nc 207482415 1790989824 0.833995\nc 1790989824 2035175616 0.947702\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 11 August 2004\nc\nc Author:\nc\nc John Burkardt\nc\nc Reference:\nc\nc Paul Bratley, Bennett Fox, Linus Schrage,\nc A Guide to Simulation,\nc Springer Verlag, pages 201-202, 1983.\nc\nc Pierre L'Ecuyer,\nc Random Number Generation,\nc in Handbook of Simulation,\nc edited by Jerry Banks,\nc Wiley Interscience, page 95, 1998.\nc\nc Bennett Fox,\nc Algorithm 647:\nc Implementation and Relative Efficiency of Quasirandom\nc Sequence Generators,\nc ACM Transactions on Mathematical Software,\nc Volume 12, Number 4, pages 362-376, 1986.\nc\nc Peter Lewis, Allen Goodman, James Miller,\nc A Pseudo-Random Number Generator for the System/360,\nc IBM Systems Journal,\nc Volume 8, pages 136-143, 1969.\nc\nc Parameters:\nc\nc Input/output, integer SEED, the \"seed\" value, which should NOT be 0.\nc On output, SEED has been updated.\nc\nc Output, double precision R8_UNIFORM_01, a new pseudorandom variate,\nc strictly between 0 and 1.\nc\n implicit none\n\n double precision r8_uniform_01\n integer k\n integer seed\n\n if ( seed .eq. 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_UNIFORM_01 - Fatal error!'\n write ( *, '(a)' ) ' Input value of SEED = 0.'\n stop\n end if\n\n k = seed / 127773\n\n seed = 16807 * ( seed - k * 127773 ) - k * 2836\n\n if ( seed .lt. 0 ) then\n seed = seed + 2147483647\n end if\n\n r8_uniform_01 = dble ( seed ) * 4.656612875D-10\n\n return\n end\n subroutine r8vec_normal_01 ( n, seed, x )\n\nc*********************************************************************72\nc\ncc R8VEC_NORMAL_01 returns a unit pseudonormal R8VEC.\nc\nc Discussion:\nc\nc An R8VEC is a vector of R8's.\nc\nc The standard normal probability distribution function (PDF) has\nc mean 0 and standard deviation 1.\nc\nc This routine can generate a vector of values on one call. It\nc has the feature that it should provide the same results\nc in the same order no matter how we break up the task.\nc\nc The Box-Muller method is used, which is efficient, but\nc generates an even number of values each time. On any call\nc to this routine, an even number of new values are generated.\nc Depending on the situation, one value may be left over.\nc In that case, it is saved for the next call.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 17 July 2006\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer N, the number of values desired. If N is negative,\nc then the code will flush its internal memory; in particular,\nc if there is a saved value to be used on the next call, it is\nc instead discarded. This is useful if the user has reset the\nc random number seed, for instance.\nc\nc Input/output, integer SEED, a seed for the random number generator.\nc\nc Output, double precision X(N), a sample of the standard normal PDF.\nc\nc Local parameters:\nc\nc Local, integer MADE, records the number of values that have\nc been computed. On input with negative N, this value overwrites\nc the return value of N, so the user can get an accounting of\nc how much work has been done.\nc\nc Local, integer SAVED, is 0 or 1 depending on whether there is a\nc single saved value left over from the previous call.\nc\nc Local, integer X_LO_INDEX, X_HI_INDEX, records the range of entries of\nc X that we need to compute. This starts off as 1:N, but is adjusted\nc if we have a saved value that can be immediately stored in X(1),\nc and so on.\nc\nc Local, double precision Y, the value saved from the previous call, if\nc SAVED is 1.\nc\n implicit none\n\n integer n\n\n integer i\n integer m\n integer made\n double precision pi\n parameter ( pi = 3.141592653589793D+00 )\n double precision r(2)\n double precision r8_uniform_01\n integer saved\n integer seed\n double precision x(n)\n integer x_hi_index\n integer x_lo_index\n double precision y\n\n save made\n save saved\n save y\n\n data made / 0 /\n data saved / 0 /\n data y / 0.0D+00 /\nc\nc I'd like to allow the user to reset the internal data.\nc But this won't work properly if we have a saved value Y.\nc I'm making a crock option that allows the user to signal\nc explicitly that any internal memory should be flushed,\nc by passing in a negative value for N.\nc\n if ( n .lt. 0 ) then\n n = made\n made = 0\n saved = 0\n y = 0.0D+00\n return\n else if ( n .eq. 0 ) then\n return\n end if\nc\nc Record the range of X we need to fill in.\nc\n x_lo_index = 1\n x_hi_index = n\nc\nc Use up the old value, if we have it.\nc\n if ( saved .eq. 1 ) then\n x(1) = y\n saved = 0\n x_lo_index = 2\n end if\nc\nc Maybe we don't need any more values.\nc\n if ( x_hi_index - x_lo_index + 1 .eq. 0 ) then\nc\nc If we need just one new value, do that here to avoid null arrays.\nc\n else if ( x_hi_index - x_lo_index + 1 .eq. 1 ) then\n\n r(1) = r8_uniform_01 ( seed )\n\n if ( r(1) .eq. 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8VEC_NORMAL_01 - Fatal errorc'\n write ( *, '(a)' ) ' R8_UNIFORM_01 returned a value of 0.'\n stop\n end if\n\n r(2) = r8_uniform_01 ( seed )\n\n x(x_hi_index) =\n & sqrt ( -2.0D+00 * log ( r(1) ) )\n & * cos ( 2.0D+00 * pi * r(2) )\n y = sqrt ( -2.0D+00 * log ( r(1) ) )\n & * sin ( 2.0D+00 * pi * r(2) )\n\n saved = 1\n\n made = made + 2\nc\nc If we require an even number of values, that's easy.\nc\n else if ( mod ( x_hi_index - x_lo_index + 1, 2 ) .eq. 0 ) then\n\n do i = x_lo_index, x_hi_index, 2\n\n call r8vec_uniform_01 ( 2, seed, r )\n\n x(i) =\n & sqrt ( -2.0D+00 * log ( r(1) ) )\n & * cos ( 2.0D+00 * pi * r(2) )\n\n x(i+1) =\n & sqrt ( -2.0D+00 * log ( r(1) ) )\n & * sin ( 2.0D+00 * pi * r(2) )\n\n end do\n\n made = made + x_hi_index - x_lo_index + 1\nc\nc If we require an odd number of values, we generate an even number,\nc and handle the last pair specially, storing one in X(N), and\nc saving the other for later.\nc\n else\n\n do i = x_lo_index, x_hi_index - 1, 2\n\n call r8vec_uniform_01 ( 2, seed, r )\n\n x(i) =\n & sqrt ( -2.0D+00 * log ( r(1) ) )\n & * cos ( 2.0D+00 * pi * r(2) )\n\n x(i+1) =\n & sqrt ( -2.0D+00 * log ( r(1) ) )\n & * sin ( 2.0D+00 * pi * r(2) )\n\n end do\n\n call r8vec_uniform_01 ( 2, seed, r )\n\n x(n) = sqrt ( -2.0D+00 * log ( r(1) ) )\n & * cos ( 2.0D+00 * pi * r(1) )\n\n y = sqrt ( -2.0D+00 * log ( r(2) ) )\n & * sin ( 2.0D+00 * pi * r(2) )\n\n saved = 1\n\n made = made + x_hi_index - x_lo_index + 2\n\n end if\n\n return\n end\n subroutine r8vec_print_part ( n, a, max_print, title )\n\nc*********************************************************************72\nc\ncc R8VEC_PRINT_PART prints \"part\" of an R8VEC.\nc\nc Discussion:\nc\nc The user specifies MAX_PRINT, the maximum number of lines to print.\nc\nc If N, the size of the vector, is no more than MAX_PRINT, then\nc the entire vector is printed, one entry per line.\nc\nc Otherwise, if possible, the first MAX_PRINT-2 entries are printed,\nc followed by a line of periods suggesting an omission,\nc and the last entry.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 22 June 2010\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer N, the number of entries of the vector.\nc\nc Input, double precision A(N), the vector to be printed.\nc\nc Input, integer MAX_PRINT, the maximum number of lines to print.\nc\nc Input, character*(*) TITLE, a title.\nc\n implicit none\n\n integer n\n\n double precision a(n)\n integer i\n integer max_print\n character*(*) title\n\n if ( max_print .le. 0 ) then\n return\n end if\n\n if ( n .le. 0 ) then\n return\n end if\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) title\n write ( *, '(a)' ) ' '\n\n if ( n .le. max_print ) then\n\n do i = 1, n\n write ( *, '(2x,i8,a1,1x,g14.6)' ) i, ':', a(i)\n end do\n\n else if ( 3 .le. max_print ) then\n\n do i = 1, max_print - 2\n write ( *, '(2x,i8,a1,1x,g14.6)' ) i, ':', a(i)\n end do\n\n write ( *, '(a)' ) ' ........ ..............'\n i = n\n\n write ( *, '(2x,i8,a1,1x,g14.6)' ) i, ':', a(i)\n\n else\n\n do i = 1, max_print - 1\n write ( *, '(2x,i8,a1,1x,g14.6)' ) i, ':', a(i)\n end do\n\n i = max_print\n\n write ( *, '(2x,i8,a1,1x,g14.6,a)' )\n & i, ':', a(i), '...more entries...'\n\n end if\n\n return\n end\n subroutine r8vec_uniform_01 ( n, seed, r )\n\nc*********************************************************************72\nc\ncc R8VEC_UNIFORM_01 returns a unit pseudorandom R8VEC.\nc\nc Discussion:\nc\nc An R8VEC is a vector of R8's.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 17 July 2006\nc\nc Author:\nc\nc John Burkardt\nc\nc Reference:\nc\nc Paul Bratley, Bennett Fox, Linus Schrage,\nc A Guide to Simulation,\nc Springer Verlag, pages 201-202, 1983.\nc\nc Bennett Fox,\nc Algorithm 647:\nc Implementation and Relative Efficiency of Quasirandom\nc Sequence Generators,\nc ACM Transactions on Mathematical Software,\nc Volume 12, Number 4, pages 362-376, 1986.\nc\nc Peter Lewis, Allen Goodman, James Miller,\nc A Pseudo-Random Number Generator for the System/360,\nc IBM Systems Journal,\nc Volume 8, pages 136-143, 1969.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vector.\nc\nc Input/output, integer SEED, the \"seed\" value, which should NOT be 0.\nc On output, SEED has been updated.\nc\nc Output, double precision R(N), the vector of pseudorandom values.\nc\n implicit none\n\n integer n\n\n integer i\n integer k\n integer seed\n double precision r(n)\n\n do i = 1, n\n\n k = seed / 127773\n\n seed = 16807 * ( seed - k * 127773 ) - k * 2836\n\n if ( seed .lt. 0 ) then\n seed = seed + 2147483647\n end if\n\n r(i) = dble ( seed ) * 4.656612875D-10\n\n end do\n\n return\n end\n subroutine r8vec_write ( output_filename, n, x )\n\nc*********************************************************************72\nc\ncc R8VEC_WRITE writes an R8VEC file.\nc\nc Discussion:\nc\nc An R8VEC is a vector of R8's.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 10 July 2011\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, character * ( * ) OUTPUT_FILENAME, the output file name.\nc\nc Input, integer N, the number of points.\nc\nc Input, double precision X(N), the data.\nc\n implicit none\n\n integer m\n integer n\n\n integer j\n character * ( * ) output_filename\n integer output_unit\n double precision x(n)\nc\nc Open the file.\nc\n call get_unit ( output_unit )\n\n open ( unit = output_unit, file = output_filename,\n & status = 'replace' )\nc\nc Create the format string.\nc\n if ( 0 .lt. n ) then\nc\nc Write the data.\nc\n do j = 1, n\n write ( output_unit, '(2x,g24.16)' ) x(j)\n end do\n\n end if\nc\nc Close the file.\nc\n close ( unit = output_unit )\n\n return\n end\n subroutine timestamp ( )\n\nc*********************************************************************72\nc\ncc TIMESTAMP prints out the current YMDHMS date as a timestamp.\nc\nc Discussion:\nc\nc This FORTRAN77 version is made available for cases where the\nc FORTRAN90 version cannot be used.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 12 January 2007\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc None\nc\n implicit none\n\n character * ( 8 ) ampm\n integer d\n character * ( 8 ) date\n integer h\n integer m\n integer mm\n character * ( 9 ) month(12)\n integer n\n integer s\n character * ( 10 ) time\n integer y\n\n save month\n\n data month /\n & 'January ', 'February ', 'March ', 'April ',\n & 'May ', 'June ', 'July ', 'August ',\n & 'September', 'October ', 'November ', 'December ' /\n\n call date_and_time ( date, time )\n\n read ( date, '(i4,i2,i2)' ) y, m, d\n read ( time, '(i2,i2,i2,1x,i3)' ) h, n, s, mm\n\n if ( h .lt. 12 ) then\n ampm = 'AM'\n else if ( h .eq. 12 ) then\n if ( n .eq. 0 .and. s .eq. 0 ) then\n ampm = 'Noon'\n else\n ampm = 'PM'\n end if\n else\n h = h - 12\n if ( h .lt. 12 ) then\n ampm = 'PM'\n else if ( h .eq. 12 ) then\n if ( n .eq. 0 .and. s .eq. 0 ) then\n ampm = 'Midnight'\n else\n ampm = 'AM'\n end if\n end if\n end if\n\n write ( *,\n & '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' )\n & d, month(m), y, h, ':', n, ':', s, '.', mm, ampm\n\n return\n end\n", "meta": {"hexsha": "35abda68e77a4bef26257cc3c12fcc5fccc2c521", "size": 28879, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "black_scholes.f", "max_stars_repo_name": "FortranSoftwares/BLACK_SCHOLES", "max_stars_repo_head_hexsha": "e700bff9129cfd30358cb39b643a1ab13b43f805", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-07-27T06:17:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-28T16:12:23.000Z", "max_issues_repo_path": "black_scholes.f", "max_issues_repo_name": "FortranSoftwares/BLACK_SCHOLES", "max_issues_repo_head_hexsha": "e700bff9129cfd30358cb39b643a1ab13b43f805", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "black_scholes.f", "max_forks_repo_name": "FortranSoftwares/BLACK_SCHOLES", "max_forks_repo_head_hexsha": "e700bff9129cfd30358cb39b643a1ab13b43f805", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.1959839357, "max_line_length": 80, "alphanum_fraction": 0.5721112227, "num_tokens": 8941, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642804, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.7507494231222738}} {"text": "program main\n ! Default\n implicit none\n\n ! Parameters\n integer(4), parameter :: targ = 10001\n\n ! Variables\n integer(4) :: idx\n integer(8) :: i\n\n ! Do work\n idx = 0\n i = 2\n do\n if (is_prime(i)) then\n idx = idx + 1\n if (idx==targ) exit\n endif\n i = i + 1\n enddo\n\n ! Write out answer\n write(*,*) \"The prime with index \",targ,\"is: \",i\n\n\ncontains\n\n\n pure function is_prime(targ)\n ! Default\n implicit none\n\n ! Function arguments\n integer(8), intent(in) :: targ\n logical :: is_prime\n\n ! Local variables\n integer(8) :: i,max_try\n\n ! Find the max we should try\n max_try = int(sqrt(1D0*targ))\n\n do i=2,max_try\n if (mod(targ,i)==0) then\n is_prime = .false.\n return\n endif\n enddo\n\n is_prime = .true.\n return\n end function is_prime\n\n\nend program main\n", "meta": {"hexsha": "989c8a4a657f7de5cc01ba979e3cc519d01f54b2", "size": 865, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/problem7/problem7.f90", "max_stars_repo_name": "plaplant/Project_Euler", "max_stars_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/problem7/problem7.f90", "max_issues_repo_name": "plaplant/Project_Euler", "max_issues_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/problem7/problem7.f90", "max_forks_repo_name": "plaplant/Project_Euler", "max_forks_repo_head_hexsha": "e6d9ae066c9741bf7fbd62d25eb466a9caccf1b1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-01-07T21:43:45.000Z", "max_forks_repo_forks_event_max_datetime": "2017-01-07T21:43:45.000Z", "avg_line_length": 15.1754385965, "max_line_length": 50, "alphanum_fraction": 0.5560693642, "num_tokens": 271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7507180404851173}} {"text": "module class_Circle\n implicit none\n private\n public :: Circle\n public :: circle_area\n public :: circle_print\n\n ! Class-wide private constant\n real :: pi = 3.1415926535897931d0\n\n type Circle\n real :: radius\n end type Circle\n\ncontains\n\n function circle_area(this) result(area)\n type(Circle), intent(in) :: this\n real :: area\n\n area = pi * this%radius**2\n\n end function circle_area\n\n subroutine circle_print(this)\n type(Circle), intent(in) :: this\n real :: area\n\n ! Call the circle_area function\n area = circle_area(this)\n\n print *, 'Circle'\n print *, ' r = ', this%radius, &\n ' area = ', area\n\n end subroutine circle_print\n\nend module class_Circle\n", "meta": {"hexsha": "699856dc62ce49bb83eaed5868fd36a8a79fdcec", "size": 814, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "OOP/fortran90/shape_module.f90", "max_stars_repo_name": "gmengaldo/fortran-gym", "max_stars_repo_head_hexsha": "e1e1f8e3256af8ec71bca87d8d9f10de0e531559", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "OOP/fortran90/shape_module.f90", "max_issues_repo_name": "gmengaldo/fortran-gym", "max_issues_repo_head_hexsha": "e1e1f8e3256af8ec71bca87d8d9f10de0e531559", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "OOP/fortran90/shape_module.f90", "max_forks_repo_name": "gmengaldo/fortran-gym", "max_forks_repo_head_hexsha": "e1e1f8e3256af8ec71bca87d8d9f10de0e531559", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.8717948718, "max_line_length": 43, "alphanum_fraction": 0.5626535627, "num_tokens": 189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896845856297, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7506576688011344}} {"text": "! Largest prime factor\n! Problem 3\n! The prime factors of 13195 are 5, 7, 13 and 29.\n!\n! What is the largest prime factor of the number 600851475143?\n\n! Answer: 6857\n\nprogram ex003\n implicit none\n\n integer(kind=8), parameter :: num = 600851475143_8\n integer, parameter :: sieve_size = floor(sqrt(real(num, 8)))\n integer :: res = 0\n\n print *, 'Sieve size:', sieve_size\n\n call each_prime(sieve_size, assign_prime_if_factor)\n\n print *, 'Answer:', res\ncontains\n subroutine each_prime(sieve_size, callback)\n implicit none\n\n integer, intent(in) :: sieve_size\n interface\n subroutine callback(arg)\n integer, intent(in) :: arg\n end subroutine callback\n end interface\n logical, dimension(:), allocatable :: sieve\n integer :: sqrt_sieve_size, i\n\n sqrt_sieve_size = floor(sqrt(real(sieve_size)))\n\n allocate(sieve(2:sieve_size))\n sieve(:) = .true.\n\n do i = 2, sieve_size\n if (sieve(i) .eqv. .true.) then\n if (i <= sqrt_sieve_size) sieve(i*i:sieve_size:i) = .false.\n\n call callback(i)\n end if\n end do\n\n deallocate(sieve)\n end subroutine each_prime\n\n subroutine assign_prime_if_factor(n)\n implicit none\n\n integer, intent(in) :: n\n\n if (mod(num, n) == 0) res = n\n end subroutine assign_prime_if_factor\nend program ex003\n", "meta": {"hexsha": "158f54f49cc52ecc73f331744988efb61a665b03", "size": 1366, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "fortran/ex003/solution.f03", "max_stars_repo_name": "neglectedvalue/projecteuler", "max_stars_repo_head_hexsha": "7a89caad448307ad8a0123382cfd9f120933a6a7", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-05-17T21:42:35.000Z", "max_stars_repo_stars_event_max_datetime": "2017-05-17T21:42:35.000Z", "max_issues_repo_path": "fortran/ex003/solution.f03", "max_issues_repo_name": "neglectedvalue/projecteuler", "max_issues_repo_head_hexsha": "7a89caad448307ad8a0123382cfd9f120933a6a7", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/ex003/solution.f03", "max_forks_repo_name": "neglectedvalue/projecteuler", "max_forks_repo_head_hexsha": "7a89caad448307ad8a0123382cfd9f120933a6a7", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5517241379, "max_line_length": 71, "alphanum_fraction": 0.6368960469, "num_tokens": 364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.750657661123555}} {"text": " SUBROUTINE CNMN07 (II,XBAR,EPS,X1,Y1,X2,Y2,X3,Y3)\n IMPLICIT DOUBLE PRECISION(A-H,O-Z)\nC ROUTINE TO FIND FIRST XBAR.GE.EPS CORRESPONDING TO A REAL ZERO\nC OF A ONE-DIMENSIONAL FUNCTION BY POLYNOMIEL INTERPOLATION.\nC BY G. N. VANDERPLAATS APRIL, 1972. \nC NASA-AMES RESEARCH CENTER, MOFFETT FIELD, CALIF. \nC II = CALCULATION CONTROL. \nC 1: 2-POINT LINEAR INTERPOLATION, GIVEN X1, Y1, X2 AND Y2. \nC 2: 3-POINT QUADRATIC INTERPOLATION, GIVEN X1, Y1, X2, Y2, \nC X3 AND Y3. \nC EPS MAY BE NEGATIVE.\nC IF REQUIRED ZERO ON Y DOES NOT EXITS, OR THE FUNCTION IS\nC ILL-CONDITIONED, XBAR = EPS-1.0 WILL BE RETURNED AS AN ERROR\nC INDICATOR.\nC IF DESIRED INTERPOLATION IS ILL-CONDITIONED, A LOWER ORDER\nC INTERPOLATION, CONSISTANT WITH INPUT DATA, WILL BE ATTEMPTED AND\nC II WILL BE CHANGED ACCORDINGLY. \n XBAR1=EPS-1.\n XBAR=XBAR1\n JJ=0\n X21=X2-X1 \n IF (ABS(X21).LT.1.0E-20) RETURN \n IF (II.EQ.2) GO TO 30 \nC \n10 CONTINUE\nC ------------------------------------------------------------------\nC II=1: 2-POINT LINEAR INTERPOLATION \nC ------------------------------------------------------------------\n II=1\n YY=Y1*Y2\n IF (JJ.EQ.0.OR.YY.LT.0.) GO TO 20 \nC INTERPOLATE BETWEEN X2 AND X3.\n DY=Y3-Y2\n IF (ABS(DY).LT.1.0E-20) GO TO 20\n XBAR=X2+Y2*(X2-X3)/DY \n IF (XBAR.LT.EPS) XBAR=XBAR1 \n RETURN\n20 DY=Y2-Y1\nC INTERPOLATE BETWEEN X1 AND X2.\n IF (ABS(DY).LT.1.0E-20) RETURN\n XBAR=X1+Y1*(X1-X2)/DY \n IF (XBAR.LT.EPS) XBAR=XBAR1 \n RETURN\n30 CONTINUE\nC ------------------------------------------------------------------\nC II=2: 3-POINT QUADRATIC INTERPOLATION \nC ------------------------------------------------------------------\n JJ=1\n X31=X3-X1 \n X32=X3-X2 \n QQ=X21*X31*X32\n IF (ABS(QQ).LT.1.0E-20) RETURN\n AA=(Y1*X32-Y2*X31+Y3*X21)/QQ\n IF (ABS(AA).LT.1.0E-20) GO TO 10\n BB=(Y2-Y1)/X21-AA*(X1+X2) \n CC=Y1-X1*(AA*X1+BB) \n BAC=BB*BB-4.*AA*CC\n IF (BAC.LT.0.) GO TO 10 \n BAC=SQRT(BAC) \n AA=.5/AA\n XBAR=AA*(BAC-BB)\n XB2=-AA*(BAC+BB)\n IF (XBAR.LT.EPS) XBAR=XB2 \n IF (XB2.LT.XBAR.AND.XB2.GT.EPS) XBAR=XB2\n IF (XBAR.LT.EPS) XBAR=XBAR1 \n RETURN\n END ", "meta": {"hexsha": "ccf479a6bc51cabced8bfa4fe5cb20a6c94bd8a0", "size": 2389, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "docker/optimization/pyOpt/tags/v1.2.0/pyOpt/pyCONMIN/source/cnmn07.f", "max_stars_repo_name": "liujiamingustc/phd", "max_stars_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-01-06T03:01:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T03:02:55.000Z", "max_issues_repo_path": "docker/optimization/pyOpt/tags/v1.2.0/pyOpt/pyCONMIN/source/cnmn07.f", "max_issues_repo_name": "liujiamingustc/phd", "max_issues_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docker/optimization/pyOpt/tags/v1.2.0/pyOpt/pyCONMIN/source/cnmn07.f", "max_forks_repo_name": "liujiamingustc/phd", "max_forks_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.6567164179, "max_line_length": 72, "alphanum_fraction": 0.5081624111, "num_tokens": 864, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475810629193, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.750582139476752}} {"text": " FUNCTION aspectratio()\n USE vmec_main\n USE realspace\n USE vmec_io\n IMPLICIT NONE\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n INTEGER :: lk, l\n REAL(rprec) :: rb, zub, pi, t1, aspectratio\nC-----------------------------------------------\n!\n! routine for computing aspect-ratio (independent of elongation):\n! A = /**.5\n!\n! WHERE pi **2 = Area (toroidally averaged)\n! 2*pi * * Area = Volume\n! Use integration by parts to compute as surface integral (Stoke''s theorem)\n!\n\n pi = 4*ATAN(one)\n\n!\n! Compute Volume and Mean (toroidally averaged) Cross Section Area\n!\n volume_p = 0\n cross_area_p = 0\n DO lk = 1, nznt\n l = ns*lk\n rb = r1(l,0) + r1(l,1)\n zub = zu(l,0) + zu(l,1)\n t1 = rb*zub*wint(l)\n volume_p = volume_p + rb*t1\n cross_area_p = cross_area_p + t1\n END DO\n\n volume_p = 2*pi*pi*ABS(volume_p)\n cross_area_p = 2*pi*ABS(cross_area_p)\n\n Rmajor_p = volume_p/(2*pi*cross_area_p)\n Aminor_p = SQRT(cross_area_p/pi)\n\n aspectratio = Rmajor_p/Aminor_p\n\n END FUNCTION aspectratio\n", "meta": {"hexsha": "e6d047e5a73c78e5cabb84ce04069f6106198b33", "size": 1243, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "VMEC2000/Sources/General/aspectratio.f", "max_stars_repo_name": "jonathanschilling/VMEC_8_00", "max_stars_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "VMEC2000/Sources/General/aspectratio.f", "max_issues_repo_name": "jonathanschilling/VMEC_8_00", "max_issues_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "VMEC2000/Sources/General/aspectratio.f", "max_forks_repo_name": "jonathanschilling/VMEC_8_00", "max_forks_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 27.0217391304, "max_line_length": 80, "alphanum_fraction": 0.5060337892, "num_tokens": 365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741308615412, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.750562864380896}} {"text": "module basic_stats_mod\n\n implicit none\n \ncontains\n \n !>-------------------------------------\n !! Compute the mean over the first dimension\n !!\n !! precondition: nt>0\n !!\n !!-------------------------------------\n subroutine time_mean(input, mean)\n implicit none\n real, intent(in), dimension(:,:,:) :: input\n real, intent(inout),dimension(:,:) :: mean\n \n integer :: nx, ny, nt\n integer :: x, y\n \n nt = size(input,1)\n nx = size(input,2)\n ny = size(input,3)\n \n do y=1,ny\n do x=1,nx\n mean(x,y) = sum(input(:,x,y)) / nt\n end do\n end do\n \n end subroutine time_mean\n \n !>-------------------------------------\n !! Compute the standard deviation over the first dimension\n !!\n !! precondition: nt>1\n !!\n !!-------------------------------------\n subroutine time_stddev(input, stddev, mean_in)\n implicit none\n real, intent(in), dimension(:,:,:) :: input\n real, intent(inout), dimension(:,:) :: stddev\n real, intent(in), dimension(:,:), optional :: mean_in\n real, dimension(:,:), allocatable :: mean\n \n integer :: nx, ny, nt\n integer :: x, y\n \n nt = size(input,1)\n nx = size(input,2)\n ny = size(input,3)\n \n ! There are one pass stddev algorithms, this is clear and provides a nice option to use an existing mean\n allocate(mean(nx,ny))\n if (.not.present(mean_in)) then\n call time_mean(input,mean)\n else\n mean = mean_in\n endif\n \n ! note, for nt==1, stddev is undefined. Here return the 10x the mean just to show it is BIG\n if (nt<=1) then\n stddev = abs(mean) * 10\n write(*,*) \"WARNING: attempting to compute a standard deviation of one value!\", shape(input)\n return\n endif\n \n do y=1,ny\n do x=1,nx\n stddev(x,y) = sqrt( sum( (input(:,x,y) - mean(x,y))**2 ) / (nt-1) )\n end do\n end do\n \n end subroutine time_stddev\n \n function stddev(input, mean_in)\n implicit none\n real, dimension(:) :: input\n real, intent(in), optional :: mean_in\n real :: stddev\n \n real :: mean\n integer :: x, n\n \n n = size(input)\n \n if (present(mean_in)) then\n mean = mean_in\n else\n mean = sum(input) / n\n endif\n \n stddev = sqrt( sum( (input - mean)**2 ) / (n-1) )\n \n end function stddev\n\n\nend module basic_stats_mod\n", "meta": {"hexsha": "1a94b1734e401aeb820dd37542635deff9144431", "size": 2695, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utilities/basic_stats.f90", "max_stars_repo_name": "gutmann/downscale", "max_stars_repo_head_hexsha": "a2267389722950c100cbfbd27dce6cf53c709949", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-07-12T16:15:06.000Z", "max_stars_repo_stars_event_max_datetime": "2016-11-02T20:32:09.000Z", "max_issues_repo_path": "src/utilities/basic_stats.f90", "max_issues_repo_name": "gutmann/downscale", "max_issues_repo_head_hexsha": "a2267389722950c100cbfbd27dce6cf53c709949", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/utilities/basic_stats.f90", "max_forks_repo_name": "gutmann/downscale", "max_forks_repo_head_hexsha": "a2267389722950c100cbfbd27dce6cf53c709949", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2016-05-23T20:41:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T03:06:58.000Z", "avg_line_length": 27.2222222222, "max_line_length": 112, "alphanum_fraction": 0.4634508349, "num_tokens": 632, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7505240156003548}} {"text": "\n function func(x)\n real*8::x,func\n func= x*exp(x)\n end\n \n program aa\n \n! subroutine prder(x,func,n,h,D)\n !primera derivada de orden n en el error, en el intervalo h\n \n implicit none\n external func\n real*8::h,x\n real*8::func\n REAL*8,ALLOCATABLE,DIMENSION(:,:)::D\n integer*4::i,j,n\n x=2.\n n=4\n h=4d-1\n allocate(D(n,n))\n D(:,:)=0.0d1\n !CADA fila es un D(fila ejemplo 1) con la primer cordenada 2H la segunda H la tercera H/2. la segunda fila es un D2 con primer elemento H segundo H/2 Y ASI\n \n do j=0,n-1\n do i=1,n-j\n\n if (j==0) then\n if (i==1) then\n D(j+1,i)=((func(x+h)-func(x-h))/(2*h))\n print*, j+1,i, D(j+1,i), 'a'\n else\n D(j+1,i)=((func(x+(h/(2**(i-1))))-func(x-(h/(2**(i-1)))))/(2*(h/(2**(i-1)))))\n print*, j+1,i, D(j+1,i), 'b'\n end if\n else\n D(j+1,i)=(((2**(2*(j))))*D(j,i+1)-D(j,i))/((2**(2*(j)))-1)\n print*, j+1,i, D(j+1,i), 'c'\n \n\n end if\n end do\n\n end do\n \n print*, ' '\n print*,'el valor de h usado es', h\n print*, ' '\n print*,'el valor de x usado es', x\n print*, ' '\n print*, 'de la funcion ', ' f(x) = exp(x)*x'\n print*, ' '\n \n \n print*, 'la matriz D es '\n\n do i=1,n\n print*, D(:,i)\n end do\n print*, ' '\n \n print*, 'el valor final con presicion',n, 'es', D(n,1)\n \n print*, 'el valor de la derivada analitica es ', (exp(2.)*3)\n \n return \n end\n\n\n", "meta": {"hexsha": "f7205ba832a0237d71ecb5c355a9e3b44a1efc47", "size": 1562, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fedora/a.f90", "max_stars_repo_name": "patricio-c/fortran", "max_stars_repo_head_hexsha": "da11f9e06010399703e8d8e51f57c44a7663857f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fedora/a.f90", "max_issues_repo_name": "patricio-c/fortran", "max_issues_repo_head_hexsha": "da11f9e06010399703e8d8e51f57c44a7663857f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fedora/a.f90", "max_forks_repo_name": "patricio-c/fortran", "max_forks_repo_head_hexsha": "da11f9e06010399703e8d8e51f57c44a7663857f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.3142857143, "max_line_length": 161, "alphanum_fraction": 0.4487836108, "num_tokens": 553, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.7504817165988745}} {"text": "PROGRAM MAIN\n\n IMPLICIT NONE\n\n INTEGER :: i, sgn\n INTEGER, PARAMETER :: max_iter = 100\n REAL :: term, sin_approx, x\n\n x = 3.14159/ 8.0 ! Pi/16\n\n ! Keep a running sign for simplicity\n sgn = -1\n\n !I compute the first term explicitly here:\n term = x\n sin_approx = term\n\n ! Only need odd numbered terms so use loop stride for clarity\n DO i = 3, max_iter, 2\n ! A sneaky way to do less computation. Each term adds another factor of x**2 and\n ! 2 contributions to the factorial.\n ! I do not store factorial. Also I do the type conversions explicitly\n ! NB : turning an integer into a real CAN change its value. Doing it for i or even i*(i-1)\n ! will be fine for these values, but for an entire n! can change. But that only\n ! gives us a fractional error\n term = sgn * term * x**2 / REAL(i)/ REAL(i-1)\n\n sin_approx = sin_approx + term\n\n sgn = -1 * sgn\n\n END DO\n\n PRINT*, \"An approximation to sin(x) for x=\", x, \" is: \", sin_approx\n\nEND PROGRAM\n", "meta": {"hexsha": "15bfe210dad5c56d5659cfa2babcd0955bddc7b4", "size": 977, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ModelSolutions/Sin.f90", "max_stars_repo_name": "WarwickRSE/Fortran4Researchers", "max_stars_repo_head_hexsha": "14467a32a516fdc0cf33341aea8d5b26f4501b51", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-10-03T08:28:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-28T02:59:38.000Z", "max_issues_repo_path": "ModelSolutions/Sin.f90", "max_issues_repo_name": "WarwickRSE/Fortran4Researchers", "max_issues_repo_head_hexsha": "14467a32a516fdc0cf33341aea8d5b26f4501b51", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ModelSolutions/Sin.f90", "max_forks_repo_name": "WarwickRSE/Fortran4Researchers", "max_forks_repo_head_hexsha": "14467a32a516fdc0cf33341aea8d5b26f4501b51", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.4054054054, "max_line_length": 94, "alphanum_fraction": 0.659160696, "num_tokens": 292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951643678382, "lm_q2_score": 0.8031737940012417, "lm_q1q2_score": 0.7504817092617304}} {"text": " real*8 function dstn1(rn1,rn2) result (r_dstn1)\r\n\r\n!! ~ ~ ~ PURPOSE ~ ~ ~\r\n!! this function computes the distance from the mean of a normal \r\n!! distribution with mean = 0 and standard deviation = 1, given two\r\n!! random numbers\r\n\r\n!! ~ ~ ~ INCOMING VARIABLES ~ ~ ~\r\n!! name |units |definition\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \r\n!! rn1 |none |first random number\r\n!! rn2 |none |second random number\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \r\n\r\n!! ~ ~ ~ OUTGOING VARIABLES ~ ~ ~\r\n!! name |units |definition\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \r\n!! dstn1 | |\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \r\n\r\n!! ~ ~ ~ SUBROUTINES/FUNCTIONS CALLED ~ ~ ~\r\n!! Intrinsic: Sqrt, Log, Cos\r\n\r\n!! ~ ~ ~ ~ ~ ~ END SPECIFICATIONS ~ ~ ~ ~ ~ ~\r\n\r\n real*8, intent (in) :: rn1, rn2\r\n\r\n r_dstn1 = 0.\r\n r_dstn1 = Sqrt(-2. * Log(rn1)) * Cos(6.283185 * rn2)\r\n\r\n return\r\n end", "meta": {"hexsha": "e98a3491a0d048828df8b7c67ef5f592bd08245a", "size": 1125, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "swat_cli/rev670_source/dstn1.f", "max_stars_repo_name": "GISWAT/erosion-sediment", "max_stars_repo_head_hexsha": "6ab469eba99cba8e5c365cd4d18cba2e8781ccf6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-05T06:33:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-05T06:33:14.000Z", "max_issues_repo_path": "swat_cli/rev670_source/dstn1.f", "max_issues_repo_name": "GISWAT/erosion-sediment", "max_issues_repo_head_hexsha": "6ab469eba99cba8e5c365cd4d18cba2e8781ccf6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "swat_cli/rev670_source/dstn1.f", "max_forks_repo_name": "GISWAT/erosion-sediment", "max_forks_repo_head_hexsha": "6ab469eba99cba8e5c365cd4d18cba2e8781ccf6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.15625, "max_line_length": 71, "alphanum_fraction": 0.3671111111, "num_tokens": 391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9688561658682131, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.7504598826857092}} {"text": " SUBROUTINE qromb(func,a,b,ss)\r\n INTEGER JMAX,JMAXP,K,KM\r\n REAL a,b,func,ss,EPS\r\n EXTERNAL func\r\n PARAMETER (EPS=1.e-6, JMAX=20, JMAXP=JMAX+1, K=5, KM=K-1)\r\nCU USES polint,trapzd\r\n INTEGER j\r\n REAL dss,h(JMAXP),s(JMAXP)\r\n h(1)=1.\r\n do 11 j=1,JMAX\r\n call trapzd(func,a,b,s(j),j)\r\n if (j.ge.K) then\r\n call polint(h(j-KM),s(j-KM),K,0.,ss,dss)\r\n if (abs(dss).le.EPS*abs(ss)) return\r\n endif\r\n s(j+1)=s(j)\r\n h(j+1)=0.25*h(j)\r\n11 continue\r\n pause 'too many steps in qromb'\r\n END\r\n", "meta": {"hexsha": "0e5c4c96ebe0afffbbe51653629e03de652b0b9e", "size": 587, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/qromb.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/qromb.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/qromb.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.9523809524, "max_line_length": 64, "alphanum_fraction": 0.5059625213, "num_tokens": 221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.931462514578343, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.75041617805343}} {"text": "c=======================================================================\nc\nc subroutine KATP\nc\nc Kato decomposition of a symmetric matrix with positive eigenvalues \nc (eigenvalues > eps kato )\nc\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc X : input matrix (n*n) double\nc epskat : Kato sensibility double\nc\nc WORKSPACE \nc iwork : vector ( 12*n ) integer\nc dwork : matrix ( n*(2*n+26) ) double\nc\nc OUTPUT \nc eigval : eigenvalues vector (n) double\nc soreig : sorted eigenvalues (n) double\nc vpmat : ordered eigenvectors (n*n) double\nc nbkgrp : number of Kato groups integer\nc grpkat : Kato groups (n) output size (nbkgrp) integer\nc info : diagnostic argument integer\nc\nc CALL \nc SCHURSO : SCHUR decomposition of a symmetric matrix\nc sorts eigenvalues and eigenvectors (decrease order)\nc GREPS : computes groups for a sensibility epsilon\nc\nc METHOD \nc for Kato groups vector \nc for an example of eigenvalues vector ( size = 7 ) : \nc eigval = [ 5.2, 5.1, 3.5, 3.4, 3.3, 1.7 1.3 ] \nc and epskat = 0.15, the routine computes \nc nbkgrp = 4 \nc grpvec = [ 2, 3, 1, 1 ] \nc\nc-----------------------------------------------------------------------\nc\n SUBROUTINE katp ( n, X, epskat, iwork, dwork,\n & eigval, soreig, vpmat, nbkgrp, grpkat, info )\nc\n IMPLICIT NONE\nc\nc arguments i/o\n INTEGER n, nbkgrp, info\n INTEGER grpkat(*)\n DOUBLE PRECISION epskat\n DOUBLE PRECISION eigval(*), soreig(*), X(*), vpmat(n,*)\nc\nc workspaces\n INTEGER iwork(*)\n DOUBLE PRECISION dwork(*)\nc\nc local variables\n INTEGER i\nc\nc external subroutines\n EXTERNAL schurso, greps\nc \nc intrinsic functions\n INTRINSIC MAX\nc\nc-----------------------------------------------------------------------\nc\nc SCHUR decomposition of a symmetric matrix\nc sorts eigenvalues and eigenvectors (decrease order)\n CALL schurso ( n, X, iwork, dwork,\n & eigval, soreig, vpmat, info )\n IF (info .LT. 0) RETURN\nc\nc up eigenvalues to epskat\n DO i=1,n\n soreig(i) = MAX( epskat , soreig(i) )\n ENDDO\nc\nc computes Kato groups for a sensibility epsilon\n CALL greps ( n, soreig, epskat, nbkgrp, grpkat, info )\nc\n RETURN\n END\n\n", "meta": {"hexsha": "b380af898824c192c6cb3012e7f2d695618943dc", "size": 2837, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/alglin/cmc/katp.f", "max_stars_repo_name": "alpgodev/numx", "max_stars_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-07-25T20:28:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-10T18:52:08.000Z", "max_issues_repo_path": "src/math/alglin/cmc/katp.f", "max_issues_repo_name": "alpgodev/numx", "max_issues_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/math/alglin/cmc/katp.f", "max_forks_repo_name": "alpgodev/numx", "max_forks_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.3764705882, "max_line_length": 74, "alphanum_fraction": 0.4649277406, "num_tokens": 718, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705932, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.750416175628518}} {"text": "!********************************************************************************\n! NEWTON_LIMITACC: Test limiting accuracy of compensated Newton's method\n! Authors: Thomas R. Cameron and Aidan O'Neill\n! Institution: Davidson College, Mathematics and Computer Science Department\n! Last Modified: 22 March 2019\n!********************************************************************************\nprogram newton_limitAcc\n use eft\n use mproutines\n implicit none\n ! parameters\n integer, parameter :: itnum = 5\n ! polynomial variables\n integer :: deg\n real(kind=dp) :: x\n complex(kind=dp) :: z\n real(kind=dp), allocatable :: poly(:)\n complex(kind=dp), allocatable :: cpoly(:)\n ! testing variables\n real(kind=dp) :: bound, error, compBound, compError, cond, exact, g\n complex(kind=dp) :: cexact\n \n ! random seed\n call init_random_seed()\n ! open real test file\n open(unit=1,file=\"data_files/newton_limitAcc_real.dat\")\n write(1,'(A)') 'cond, stan_err_bound, stan_err, comp_err_bound, comp_err'\n ! run real test\n do deg=1,40\n ! allocate polynomial variable\n allocate(poly(deg+1))\n ! polynomial\n call limAccPoly(poly,deg)\n ! exact root\n exact = limAccRoot(poly,deg)\n ! condition number and error bounds\n g = 2*deg*mu/(1-2*deg*mu)\n cond = compCond(poly,exact,deg)\n bound = cond*g\n compBound = mu + cond*g**2\n if(bound>1.0_dp) bound = 1.0_dp\n if(compBound>1.0_dp) compBound = 1.0_dp\n ! standard Newton's method\n x = exact + exact*compBound\n call SNewton(poly,x,deg)\n error = abs(x - exact)/abs(exact)\n if(error1.0_dp) then\n error = 1.0_dp\n end if \n ! compensated Newton's method\n x = exact + exact*compBound\n call CNewton(poly,x,deg)\n compError = abs(x - exact)/abs(exact)\n if(compError1.0_dp) then\n compError = 1.0_dp\n end if\n ! deallocate polynomial\n deallocate(poly)\n ! write to file\n write(1,'(ES15.2)', advance='no') cond\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)', advance='no') bound\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)', advance='no') error\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)', advance='no') compBound\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)') compError\n end do\n ! close real test file\n close(1)\n \n ! open complex test file\n open(unit=1,file=\"data_files/newton_limitAcc_cmplx.dat\")\n write(1,'(A)') 'cond, stan_err_bound, stan_err, comp_err_bound, comp_err'\n ! run complex text\n do deg=1,40\n ! allocate polynomial variable\n allocate(cpoly(deg+1))\n ! polynomial\n call limAccPolyCplx(cpoly,deg)\n ! exact root\n cexact = limAccRootCplx(cpoly,deg)\n ! condition number and error bounds\n g = 2*mu/(1-2*mu)\n g = 2*deg*sqrt(2.0_dp)*g/(1-2*deg*sqrt(2.0_dp)*g)\n cond = compCondCplx(cpoly,cexact,deg)\n bound = cond*g\n compBound = mu + cond*g**2\n if(bound>1.0_dp) bound = 1.0_dp\n if(compBound>1.0_dp) compBound = 1.0_dp\n ! standard Newton's method\n z = cexact + cexact*compBound\n call SNewtonCplx(cpoly,z,deg)\n error = abs(z - cexact)/abs(cexact)\n if(error1.0_dp) then\n error = 1.0_dp\n end if\n ! compensated Newton's method\n z = cexact + cexact*compBound\n call CNewtonCplx(cpoly,z,deg)\n compError = abs(z - cexact)/abs(cexact)\n if(compError1.0_dp) then\n compError = 1.0_dp\n end if\n ! deallocate polynomial\n deallocate(cpoly)\n ! write to file\n write(1,'(ES15.2)', advance='no') cond\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)', advance='no') bound\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)', advance='no') error\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)', advance='no') compBound\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)') compError\n end do\n ! close complex test file\n close(1)\ncontains\n !************************************************\n ! init_random_seed *\n !************************************************\n ! Initiate random seed using system_clock. This\n ! seed is then available for the random number\n ! generator in random_number for the life of\n ! the program.\n !************************************************\n subroutine init_random_seed()\n implicit none\n ! local variables\n integer :: i, n, clock\n integer, dimension(:), allocatable :: seed\n ! intrinsic subroutines\n intrinsic :: random_seed, system_clock\n \n ! main\n call random_seed(size = n)\n allocate(seed(n))\n \n call system_clock(count = clock)\n seed = clock + 37 * (/ (i - 1, i = 1,n) /)\n call random_seed(put = seed)\n \n deallocate(seed)\n end subroutine init_random_seed\n !********************************************************\n ! Standard Newton *\n !********************************************************\n ! Computes a root approximation of a polynomial using\n ! standard Newton's method in dp-precision. The result\n ! is stored in x. \n !********************************************************\n subroutine SNewton(poly,x,deg)\n implicit none\n ! argument variables\n integer, intent(in) :: deg\n real(kind=dp), intent(in) :: poly(:)\n real(kind=dp), intent(inout) :: x\n ! local variables\n integer :: j, k\n real(kind=dp) :: alpha, beta\n \n ! Newton's method\n do k=1,itnum\n ! compute alpha and beta\n alpha = poly(deg+1)\n beta = 0.0_dp\n do j=deg,1,-1\n beta = x*beta + alpha\n alpha = x*alpha + poly(j)\n end do\n ! update x\n x = x - (alpha/beta)\n end do\n end subroutine SNewton\n !********************************************************\n ! Standard Newton Cplx *\n !********************************************************\n ! Complex version of Standard Newton.\n !********************************************************\n subroutine SNewtonCplx(poly,x,deg)\n implicit none\n ! argument variables\n integer, intent(in) :: deg\n complex(kind=dp), intent(in) :: poly(:)\n complex(kind=dp), intent(inout) :: x\n ! local variables\n integer :: j, k\n complex(kind=dp) :: alpha, beta\n \n ! Newton's method\n do k=1,itnum\n ! compute alpha and beta\n alpha = poly(deg+1)\n beta = cmplx(0.0_dp,0.0_dp,kind=dp)\n do j=deg,1,-1\n beta = x*beta + alpha\n alpha = x*alpha + poly(j)\n end do\n ! update x\n x = x - (alpha/beta)\n end do\n end subroutine SNewtonCplx\n !********************************************************\n ! Compensated Newton *\n !********************************************************\n ! Computes a root approximation of a polynomial using\n ! compensated Newton's method in dp-precision, i.e.,\n ! the polynomial evaluation is done using a compensated\n ! Horner's method. The result is stored in x. \n !********************************************************\n subroutine CNewton(poly,x,deg)\n ! argument variables\n integer, intent(in) :: deg\n real(kind=dp), intent(in) :: poly(:)\n real(kind=dp), intent(inout) :: x\n ! local variables\n integer :: j, k\n real(kind=dp) :: alpha, alphaErr, beta, betaErr\n type(REFT) :: prod, sum\n \n ! Newton's method\n do k=1,itnum\n ! compute alpha and beta\n alpha = poly(deg+1)\n alphaErr = 0.0_dp\n beta = 0.0_dp\n betaErr = 0.0_dp\n do j=deg,1,-1\n ! product and sum for beta\n prod = TwoProduct(beta,x)\n sum = TwoSum(prod%x,alpha)\n ! update beta and betaErr\n beta = sum%x\n betaErr = x*betaErr + alphaErr + (prod%y + sum%y)\n ! product and sum for alpha\n prod = TwoProduct(alpha,x)\n sum = TwoSum(prod%x,poly(j))\n ! update alpha and alphaErr\n alpha = sum%x\n alphaErr = x*alphaErr + (prod%y + sum%y)\n end do\n ! add error back into result\n beta = beta + betaErr\n alpha = alpha + alphaErr\n ! update x\n x = x - (alpha/beta)\n end do\n end subroutine CNewton\n !********************************************************\n ! Compensated Newton Cplx *\n !********************************************************\n ! Complex version of Compensated Newton.\n !********************************************************\n subroutine CNewtonCplx(poly,x,deg)\n ! argument variables\n integer, intent(in) :: deg\n complex(kind=dp), intent(in) :: poly(:)\n complex(kind=dp), intent(inout) :: x\n ! local variables\n integer :: j, k\n complex(kind=dp) :: alpha, alphaErr, beta, betaErr\n type(CEFTSum) :: sum\n type(CEFTProd) :: prod\n \n ! Newton's method\n do k=1,itnum\n ! compute alpha and beta\n alpha = poly(deg+1)\n alphaErr = cmplx(0.0_dp,0.0_dp,kind=dp)\n beta = cmplx(0.0_dp,0.0_dp,kind=dp)\n betaErr = cmplx(0.0_dp,0.0_dp,kind=dp)\n do j=deg,1,-1\n ! product and sum for beta\n prod = TwoProductCplx(beta,x)\n sum = TwoSumCplx(prod%p,alpha)\n ! update beta and betaErr\n beta = sum%x\n betaErr = x*betaErr + alphaErr + FaithSumCplx(prod%e,prod%f,prod%g,sum%y)\n ! product and sum for alpha\n prod = TwoProductCplx(alpha,x)\n sum = TwoSumCplx(prod%p,poly(j))\n ! update alpha and alphaErr\n alpha = sum%x\n alphaErr = x*alphaErr + FaithSumCplx(prod%e,prod%f,prod%g,sum%y)\n end do\n ! add error back into result\n beta = beta + betaErr\n alpha = alpha + alphaErr\n ! update x\n x = x - (alpha/beta)\n end do\n end subroutine CNewtonCplx\nend program newton_limitAcc", "meta": {"hexsha": "c732b6d822d76a59dcc8a50c3047ba6cd99a5fe1", "size": 11522, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/newton_limitAcc.f90", "max_stars_repo_name": "trcameron/FPML-Comp", "max_stars_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/newton_limitAcc.f90", "max_issues_repo_name": "trcameron/FPML-Comp", "max_issues_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/newton_limitAcc.f90", "max_forks_repo_name": "trcameron/FPML-Comp", "max_forks_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.9013157895, "max_line_length": 89, "alphanum_fraction": 0.4609442805, "num_tokens": 2798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381604, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.7503083815575605}} {"text": "subroutine elmder(nnode,ndime,deriv,elcod,cartd,detjm,xjacm,xjaci)\n!-----------------------------------------------------------------------\n! NAME\n! elmder\n! DESCRIPTION\n! This routine calculates the Cartesian derivatives cartd and detjm.\n! USES\n! invmtx\n!-----------------------------------------------------------------------\n use typre\n implicit none\n integer(ip), intent(in) :: nnode,ndime\n real(rp), intent(in) :: deriv(ndime,nnode),elcod(ndime,nnode)\n real(rp), intent(out) :: detjm,cartd(ndime,nnode)\n real(rp), intent(out) :: xjacm(ndime,ndime)\n real(rp), intent(out) :: xjaci(ndime,ndime)\n \n xjacm=matmul(elcod,transpose(deriv))\n call invmtx(xjacm,xjaci,detjm,ndime)\n cartd=matmul(transpose(xjaci),deriv)\n \nend subroutine elmder\n!-----------------------------------------------------------------------\n! NOTES\n! Try to remember... when life was so tender...\n! _ _ _ _\n! | x1 x2 x3 | | dN1/ds dN2/ds dN3/ds |\n! elcod=| |, deriv=| |\n! |_y1 y2 y3_| |_dN1/dt dN2/dt dN3/dt_|\n! _ _ \n! | dx/ds dx/dt | t\n! xjacm=| |=elcod*deriv\n! |_dy/ds dy/dt_|\n! _ _\n! | ds/dx ds/dy | -1\n! xjaci=| |=xjacm .This is because:\n! |_dt/dx dt/dy_|\n! _ _ _ _ _ _ \n! | du/dx | | ds/dx dt/dx | | du/ds | \n! | |=| | | | and\n! |_du/dy_| |_ds/dy dt/dy_| |_du/dt_| \n! _ _ _ _ _ _ _ _ _ _ -1 _ _ \n! | du/ds | | dx/ds dy/ds | | du/dx | | du/dx | | dx/ds dy/ds | | du/ds |\n! | |=| | | | => | |=| | | |\n! |_du/dt_| |_dx/dt dy/dt_| |_du/dy_| |_du/dy_| |_dx/dt dy/dt_| |_du/dt_| \n! _ _ _ _ -1\n! | ds/dx dt/dx | | dx/ds dy/ds | -1\n! Therefore | |=| |=xjacm \n! |_ds/dy dt/dy_| |_dx/dt dy/dt_| \n! _ _ \n! | dN1/ds*ds/dx+dN1/dt*dt/dx dN2/ds*ds/dx+dN2/dt*dt/dx dN3/ds*ds/dx+dN3/dt*dt/dx | \n! cartd=| | \n! |_dN1/ds*ds/dy+dN1/dt*dt/dy dN2/ds*ds/dy+dN2/dt*dt/dy dN3/ds*ds/dy+dN3/dt*dt/dy _|\n! t\n! =xjaci *deriv\n! _ _\n! | du/dx | t\n! Example: | |=cartd*[U1 U2 U3]\n! |_du/dy_| \n! \n!***\n!-----------------------------------------------------------------------\n", "meta": {"hexsha": "cc1b9b8ba31f140a4a156208f76412aad6799867", "size": 2768, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/domain/elmder.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/domain/elmder.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/domain/elmder.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.9365079365, "max_line_length": 94, "alphanum_fraction": 0.349349711, "num_tokens": 863, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552536, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7503083749095542}} {"text": "! Copyright (c) 2019 Etienne Descamps\n! All rights reserved.\n!\n! Redistribution and use in source and binary forms, with or without modification,\n! are permitted provided that the following conditions are met:\n!\n! 1. Redistributions of source code must retain the above copyright notice,\n! this list of conditions and the following disclaimer.\n!\n! 2. Redistributions in binary form must reproduce the above copyright notice,\n! this list of conditions and the following disclaimer in the documentation and/or\n! other materials provided with the distribution.\n!\n! 3. Neither the name of the copyright holder nor the names of its contributors may be\n! used to endorse or promote products derived from this software without specific prior\n! written permission.\n!\n! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\n! ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n! WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n! IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n! INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n! (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n! THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n! NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n! EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n! This module contains a more readable version (in Fortran 2008) \n! of the linear equation solver implemented as ACM's Algorithm 423\n\nModule mlf_linalg\n Use ieee_arithmetic\n Use iso_c_binding \n IMPLICIT NONE\n PRIVATE\n\n Public :: DecompMatrix, SolveMatrix\n\n Interface DecompMatrix\n module procedure DecompMatrixDouble\n module procedure DecompMatrixComplex\n End Interface DecompMatrix\n\n Interface SolveMatrix\n module procedure SolveMatrixDouble\n module procedure SolveMatrixComplex\n End Interface SolveMatrix\nContains\n Integer Function DecompMatrixDouble(A, IP) Result(K)\n real(c_double), intent(inout) :: A(:,:)\n integer, intent(out) :: IP(:)\n integer :: N, M, J\n real(c_double) :: T\n logical :: P\n N = SIZE(A,2)\n IP(N) = 0\n P = .FALSE.\n Do K = 1, N-1\n M = K - 1 + MAXLOC(ABS(A(K:,K)), DIM = 1)\n IP(K) = M\n If(M /= K) Then\n P = .NOT. P\n T = A(M,K); A(M,K) = A(K,K); A(K,K) = T ! Swap A(K,K) and A(M,K)\n Endif\n If(A(K,K) == 0d0) RETURN\n A(K+1:,K) = -A(K+1:,K)/A(K,K)\n Do J = K+1, N\n T = A(M,J); A(M,J) = A(K,J); A(K,J) = T ! Swap A(M,J) and A(K,J)\n If(A(K,J) /= 0d0) A(K+1:,J) = A(K+1:,J)+A(K+1:,K)*A(K,J)\n End Do\n End Do\n If(A(N,N) /= 0d0) Then\n K = 0\n IP(N) = MERGE(-1, 1, P)\n Endif\n End Function DecompMatrixDouble\n\n Subroutine SolveMatrixDouble(A, B, IP)\n real(c_double), intent(in) :: A(:,:)\n real(c_double), intent(inout) :: B(:)\n integer, intent(in) :: IP(:)\n integer :: K, N, M\n real(c_double) :: T\n N = SIZE(A,2)\n Do K = 1, N-1\n M = IP(K)\n T = B(M); B(M) = B(K); B(K) = T ! Swap B(M) and B(K)\n B(K+1:) = B(K+1:) + A(K+1:,K)*B(K)\n End Do\n Do K = N, 2, -1\n B(K) = B(K)/A(K,K)\n B(:K-1) = B(:K-1) - A(:K-1, K)*B(K)\n End Do\n B(1) = B(1)/A(1,1)\n End Subroutine SolveMatrixDouble\n\n Integer Function DecompMatrixComplex(A, IP) Result(K)\n complex(KIND = 8), intent(inout) :: A(:,:)\n integer, intent(out) :: IP(:)\n integer :: N, M, J\n complex(KIND = 8) :: T\n logical :: P\n N = SIZE(A,2)\n IP(N) = 0\n P = .FALSE.\n Do K = 1, N-1\n M = K - 1 + MAXLOC(ABS(A(K:,K)), DIM = 1)\n IP(K) = M\n If(M /= K) Then\n P = .NOT. P\n T = A(M,K); A(M,K) = A(K,K); A(K,K) = T ! Swap A(K,K) and A(M,K)\n Endif\n If(ABS(A(K,K)) == 0d0) RETURN\n A(K+1:,K) = -A(K+1:,K)/A(K,K)\n Do J = K+1, N\n T = A(M,J); A(M,J) = A(K,J); A(K,J) = T ! Swap A(M,J) and A(K,J)\n If(A(K,J) /= 0d0) A(K+1:,J) = A(K+1:,J)+A(K+1:,K)*A(K,J)\n End Do\n End Do\n If(ABS(A(N,N)) > 0d0) Then\n K = 0\n IP(N) = MERGE(-1, 1, P)\n Endif\n End Function DecompMatrixComplex\n\n Subroutine SolveMatrixComplex(A, B, IP)\n complex(KIND = 8), intent(in) :: A(:,:)\n complex(KIND = 8), intent(inout) :: B(:)\n integer, intent(in) :: IP(:)\n integer :: K, N, M\n complex(KIND = 8) :: T\n N = SIZE(A,2)\n Do K = 1, N-1\n M = IP(K)\n T = B(M); B(M) = B(K); B(K) = T ! Swap B(M) and B(K)\n B(K+1:) = B(K+1:) + A(K+1:,K)*B(K)\n End Do\n Do K = N, 2, -1\n B(K) = B(K)/A(K,K)\n B(:K-1) = B(:K-1) - A(:K-1, K)*B(K)\n End Do\n B(1) = B(1)/A(1,1)\n End Subroutine SolveMatrixComplex\n\n\nEnd Module mlf_linalg\n\n", "meta": {"hexsha": "f6b684201c54ea6b0d9f637fb304810c5494c70b", "size": 4824, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mlf_linalg.f90", "max_stars_repo_name": "Etdescamps/MlFortran", "max_stars_repo_head_hexsha": "c35a041ee01125b0f9df443c9bb0a42411b3c41e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-19T16:48:02.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-19T16:48:02.000Z", "max_issues_repo_path": "src/mlf_linalg.f90", "max_issues_repo_name": "Etdescamps/MlFortran", "max_issues_repo_head_hexsha": "c35a041ee01125b0f9df443c9bb0a42411b3c41e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mlf_linalg.f90", "max_forks_repo_name": "Etdescamps/MlFortran", "max_forks_repo_head_hexsha": "c35a041ee01125b0f9df443c9bb0a42411b3c41e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.3758389262, "max_line_length": 90, "alphanum_fraction": 0.5941127695, "num_tokens": 1589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391558355999, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7503083670476032}} {"text": "FUNCTION julday(dd,mm,yyyy)\n!\nIMPLICIT NONE\n!\n! PARAMETER definitions\n!\nINTEGER,PARAMETER :: igreg = 15 + 31*(10+12*1582)\n!\n! Function arguments\n!\nINTEGER :: dd,mm,yyyy\nINTEGER :: julday\n!\n! Local variables\n!\nREAL*8 :: dble\nINTEGER :: int\nINTEGER :: ja,jm,jy,y_nw\n!\n! + + + purpose + + +\n! in this routine julday returns the julian day number which begins at\n! noon of the calendar date specified by day \"dd\", month \"mm\", & year \"yyyy\"\n! all are integer variables. positive year signifies a.d.; negative, b.c.\n! remember that the year after 1 b.c. was 1 a.d.\n \n! the following invalid calendar dates are checked for and reported:\n! 1. zero year\n! 2. dates between 4/10/1582 and 15/10/1582 are specified.\n!\n! additional checking for other invalid dates could be added\n! in the future if necessary.\n!\n! + + + keywords + + +\n! date, utility\n!\n! + + + argument declarations + + +\n!\n! + + + argument definitions + + +\n! dd - integer value of day in the range 1-31\n! julday - value returned by the julday function. debe added 09/09/09\n! mm - integer value of month in the range 1-12\n! yyyy - integer value of year (negative a.d., positive b.c.)\n!\n! + + + parameters + + +\n! gregorian calendar was adopted on oct. 15, 1582.\n!\n! + + + local variable definitions + + +\n! dble - \n! int - \n! ja - \n! jm - \n! jy - \n! y_nw - \n\n! + + + end specifications + + +\n!\nIF (yyyy.EQ.0) WRITE (*,*) 'there is no year zero'\nIF ((yyyy.EQ.1582).AND.(mm.EQ.10).AND.(dd.LT.15).AND.(dd.GT.4)) WRITE (*,*) &\n & 'this is an invalid date'\nIF (yyyy.LT.0) THEN\n y_nw = yyyy + 1\nELSE\n y_nw = yyyy\nEND IF\nIF (mm.GT.2) THEN\n jy = y_nw\n jm = mm + 1\nELSE\n jy = y_nw - 1\n jm = mm + 13\nEND IF\njulday = int(365.25*jy) + int(30.6001*jm) + dd + 1720995\nIF (dd+31*(mm+12*y_nw).GE.igreg) THEN\n ja = jy/100\n! ja=int(dble(0.01)*dble(jy))\n julday = julday + 2 - ja + int(dble(0.25)*dble(ja))\nEND IF\n!\nEND FUNCTION julday\n", "meta": {"hexsha": "57c60794493ddf3d436604fd4a5368abcbcf0fa4", "size": 2006, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Project Documents/Source Code Original/Julday.f90", "max_stars_repo_name": "USDA-ARS-WMSRU/upgm-standalone", "max_stars_repo_head_hexsha": "1ae5dee5fe2cdba97b69c19d51b1cf61ceeab3d7", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Project Documents/Source Code Original/Julday.f90", "max_issues_repo_name": "USDA-ARS-WMSRU/upgm-standalone", "max_issues_repo_head_hexsha": "1ae5dee5fe2cdba97b69c19d51b1cf61ceeab3d7", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Project Documents/Source Code Original/Julday.f90", "max_forks_repo_name": "USDA-ARS-WMSRU/upgm-standalone", "max_forks_repo_head_hexsha": "1ae5dee5fe2cdba97b69c19d51b1cf61ceeab3d7", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.075, "max_line_length": 81, "alphanum_fraction": 0.6011964108, "num_tokens": 693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381606, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.7503083669119467}} {"text": "| Example of GCD algorithm:\n\n: gcd ( a b -- gcd )\n\t0; tuck mod gcd ;\n\n\n: .gcd ( a b -- )\n\t.\" GCD of \"\n\t2dup . .\" and \" . .\" is:\"\n\tgcd . cr ;\n\n\n100 80 .gcd\n23 17 .gcd\n64 12 .gcd\n5 0 .gcd\nbye\n\n", "meta": {"hexsha": "ec771220ed69b001d34cda535440dd954bf44f34", "size": 191, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/gcd.f", "max_stars_repo_name": "ronaaron/reva", "max_stars_repo_head_hexsha": "edc8cbef27219ecf8ff00ad9afdf92687796e7a2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2020-07-30T06:46:51.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-01T22:30:24.000Z", "max_issues_repo_path": "examples/gcd.f", "max_issues_repo_name": "ronaaron/reva", "max_issues_repo_head_hexsha": "edc8cbef27219ecf8ff00ad9afdf92687796e7a2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-30T06:08:02.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-30T06:08:02.000Z", "max_forks_repo_path": "examples/gcd.f", "max_forks_repo_name": "ronaaron/reva", "max_forks_repo_head_hexsha": "edc8cbef27219ecf8ff00ad9afdf92687796e7a2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-07-30T06:46:54.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-01T22:34:14.000Z", "avg_line_length": 10.0526315789, "max_line_length": 27, "alphanum_fraction": 0.4921465969, "num_tokens": 79, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7502167066107814}} {"text": "PROGRAM quad_surf\r\n! Fit a quadratic surface to a set of data\r\n\r\nUSE lsq\r\nIMPLICIT NONE\r\nINTEGER :: iostatus, n, ier, row, col\r\nINTEGER, PARAMETER :: nmax = 100\r\nREAL (dp), PARAMETER :: wt = 1.0_dp\r\nREAL (dp) :: rh, temp, yval, x(nmax,5), y(nmax), xrow(0:5), b(0:5), &\r\n yfit(3)\r\n\r\nOPEN(UNIT=8, FILE='dry_bulb.dat', STATUS='OLD')\r\nn = 0\r\nCALL startup(5, .TRUE.)\r\nDO\r\n READ(8, *, IOSTAT=iostatus) rh, temp, yval\r\n IF (iostatus < 0) EXIT\r\n IF (iostatus > 0) CYCLE\r\n n = n + 1\r\n rh = rh - 70._dp\r\n temp = temp - 95._dp\r\n y(n) = yval\r\n x(n,1) = rh\r\n x(n,2) = temp\r\n x(n,3) = rh**2\r\n x(n,4) = rh*temp\r\n x(n,5) = temp**2\r\n xrow(1:5) = x(n,:)\r\n xrow(0) = 1.0_dp\r\n CALL includ(wt, xrow, y(n))\r\nEND DO\r\n\r\nCALL regcf(b, 6, ier)\r\nWRITE(*, *) 'Fitted quadratic surface:'\r\nWRITE(*, '(a, 2f8.3, a, f8.4, a, f8.4, a, f8.4, a, f8.4, a)') &\r\n ' Y = ', b(0), b(1), '*X1 ', b(2), '*X2 ', b(3), '*X1^2 ', &\r\n b(4), '*X1*X2 ', b(5), '*X2^2'\r\nWRITE(*, *)\r\nWRITE(*, *) 'Fitted values:'\r\nWRITE(*, *) ' %RH 90 95 100'\r\nWRITE(*, *) '-------------------------------------'\r\nDO row = 1, 4\r\n xrow(0) = 1.0_dp\r\n xrow(1) = 20.0 - 10.0*row\r\n xrow(3) = xrow(1)**2\r\n DO col = 1, 3\r\n xrow(2) = -10.0 + 5.0*col\r\n xrow(4) = xrow(1)*xrow(2)\r\n xrow(5) = xrow(2)**2\r\n yfit(col) = DOT_PRODUCT( b, xrow )\r\n END DO\r\n WRITE(*, '(f8.0, \" \", 3f9.1)') xrow(1) + 70., yfit\r\nEND DO\r\n\r\nSTOP\r\nEND PROGRAM quad_surf\r\n", "meta": {"hexsha": "2684d687135522c8715604f8ac66cce28169e37d", "size": 1489, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/quadsurf.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/quadsurf.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/quadsurf.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 26.1228070175, "max_line_length": 81, "alphanum_fraction": 0.4701141706, "num_tokens": 662, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769414, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7501950974147398}} {"text": "module initial_conditions_mod\n use physical_params_mod\n use field_mod\n implicit none\n private\n\n !> Amplitude of initial oscillations in stream function\n !! Used by invoke_init_stream_fn_kernel()\n REAL(go_wp), PARAMETER :: A = 1.0D6\n !> 2PI/{m,n}\n REAL(go_wp), SAVE :: di, dj\n\n PUBLIC init_initial_condition_params\n PUBLIC invoke_init_stream_fn_kernel\n PUBLIC init_pressure\n PUBLIC init_velocity_u\n PUBLIC init_velocity_v\n\nCONTAINS\n\n !===================================================\n\n !> \\brief Set-up parameters related to the model domain which\n !! are stored in this module. We could compute these on the\n !! fly in init_stream_fn_code() and init_pressure() and\n !! rely on compiler magic to make sure they're not\n !! recomputed for every grid point.\n SUBROUTINE init_initial_condition_params(pfld)\n IMPLICIT none\n type(r2d_field), intent(in) :: pfld\n\n di = TPI/pfld%internal%nx\n dj = TPI/pfld%internal%ny\n\n END SUBROUTINE init_initial_condition_params\n\n !===================================================\n\n subroutine invoke_init_stream_fn_kernel(psifld)\n implicit none\n type(r2d_field), intent(inout) :: psifld\n ! Locals\n integer :: idim1, idim2\n integer :: i, j\n\n idim1 = SIZE(psifld%data, 1)\n idim2 = SIZE(psifld%data, 2)\n\n ! Loop over 'columns'\n DO J=1, idim2\n DO I=1, idim1\n\n CALL init_stream_fn_code(i, j, psifld%data)\n\n END DO\n END DO\n\n CONTAINS\n\n SUBROUTINE init_stream_fn_code(i, j, psi)\n IMPLICIT none\n !> The grid point (column) to act on\n INTEGER, INTENT(in) :: i, j\n !> Array holding the stream function values\n REAL(KIND=8), INTENT(out), DIMENSION(:,:) :: psi\n\n ! di = 2Pi/(Extent of mesh in x)\n ! dj = 2Pi/(Extent of mesh in y)\n ! Original code:\n ! PSI(I,J) = A*SIN((I-.5d0)*DI)*SIN((J-.5d0)*DJ)\n ! Psi is on F points. Our first internal F point is at 3,3\n ! rather than 2,2 so shift appropriately.\n PSI(I,J) = A*SIN((I-1.5d0)*DI)*SIN((J-1.5d0)*DJ)\n\n END SUBROUTINE init_stream_fn_code\n\n END SUBROUTINE invoke_init_stream_fn_kernel\n\n !===================================================\n\n SUBROUTINE init_pressure(pfld)\n IMPLICIT none\n type(r2d_field), target, intent(inout) :: pfld\n REAL(KIND=go_wp), DIMENSION(:,:), pointer :: p\n ! Locals\n INTEGER :: i, j, idim1, idim2\n !> Extent in x of model domain\n REAL(go_wp) :: el\n !> Computed amplitude of initial oscillations in\n !! pressure field.\n REAL(go_wp) :: pcf\n\n p => pfld%data\n\n EL = pfld%internal%nx * pfld%grid%dx\n PCF = PI*PI*A*A/(EL*EL)\n \n idim1 = SIZE(pfld%data, 1)\n idim2 = SIZE(pfld%data, 2)\n\n ! di = 2Pi/(Extent of mesh in x) where extent is from namelist\n ! dj = 2Pi/(Extent of mesh in y) \" \" \" \" \"\n DO J=1,idim2\n DO I=1, idim1\n! Original code:\n! P(I,J) = PCF*(COS(2.0d0*(I-1)*DI) & \n! +COS(2.0d0*(J-1)*DJ))+50000.d0\n! Our first internal T pt is at 2,2 rather than 1,1 so we shift\n! the expression appropriately:\n P(I,J) = PCF*(COS(2.0d0*(I-2)*DI) & \n +COS(2.0d0*(J-2)*DJ))+50000.d0\n END DO\n END DO\n\n END SUBROUTINE init_pressure\n\n !===================================================\n\n subroutine init_velocity_u(ufld, psifld)\n implicit none\n ! The horizontal velocity field to initialise\n type(r2d_field), intent(inout), target :: ufld\n ! The stream function used in the initialisation\n type(r2d_field), intent(in), target :: psifld\n ! Locals\n real(kind=go_wp), pointer, dimension(:,:) :: u, psi\n integer :: j\n real(go_wp) :: dy\n\n u => ufld%data\n psi => psifld%data\n\n ! dy is a property of the mesh\n dy = ufld%grid%dy\n\n do J=1,ufld%internal%ystop\n U(:,J) = -(PSI(:,j+1) - PSI(:,j))/dy\n end do\n\n end subroutine init_velocity_u\n\n !===================================================\n\n SUBROUTINE init_velocity_v(vfld, psifld)\n implicit none\n ! The vertical velocity field to initialise\n type(r2d_field), intent(inout), target :: vfld\n ! The stream function used in the initialisation\n type(r2d_field), intent(in), target :: psifld\n ! Locals\n real(kind=go_wp), pointer, dimension(:,:) :: v, psi\n integer :: I\n real(go_wp) :: dx\n\n v => vfld%data\n psi => psifld%data\n\n dx = vfld%grid%dx\n\n do I=1, vfld%internal%xstop\n v(I,:) = (psi(i+1,:) - psi(i,:))/dx\n end do\n\n end subroutine init_velocity_v\n\nend module initial_conditions_mod\n", "meta": {"hexsha": "5c26bd438a66c8223f0590d74134fbcb5cc80e95", "size": 4547, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "benchmarks/shallow/SEQ/initial_conditions_mod.f90", "max_stars_repo_name": "stfc/PSycloneBench", "max_stars_repo_head_hexsha": "f3c65c904eb286b4e3f63c43273a80d25e92cbe4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-03-30T23:33:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T13:32:01.000Z", "max_issues_repo_path": "benchmarks/shallow/SEQ/initial_conditions_mod.f90", "max_issues_repo_name": "stfc/PSycloneBench", "max_issues_repo_head_hexsha": "f3c65c904eb286b4e3f63c43273a80d25e92cbe4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 76, "max_issues_repo_issues_event_min_datetime": "2018-01-31T14:16:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T13:56:17.000Z", "max_forks_repo_path": "benchmarks/shallow/SEQ/initial_conditions_mod.f90", "max_forks_repo_name": "stfc/PSycloneBench", "max_forks_repo_head_hexsha": "f3c65c904eb286b4e3f63c43273a80d25e92cbe4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-08-01T10:23:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-28T13:23:01.000Z", "avg_line_length": 27.2275449102, "max_line_length": 66, "alphanum_fraction": 0.5909390807, "num_tokens": 1401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949656, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7501836829697098}} {"text": "program Sierpinski_triangle\n implicit none\n\n call Triangle(4)\n\ncontains\n\nsubroutine Triangle(n)\n implicit none\n integer, parameter :: i64 = selected_int_kind(18)\n integer, intent(in) :: n\n integer :: i, k\n integer(i64) :: c\n\n do i = 0, n*4-1\n c = 1\n write(*, \"(a)\", advance=\"no\") repeat(\" \", 2 * (n*4 - 1 - i))\n do k = 0, i\n if(mod(c, 2) == 0) then\n write(*, \"(a)\", advance=\"no\") \" \"\n else\n write(*, \"(a)\", advance=\"no\") \" * \"\n end if\n c = c * (i - k) / (k + 1)\n end do\n write(*,*)\n end do\nend subroutine Triangle\nend program Sierpinski_triangle\n", "meta": {"hexsha": "d4f3a5df5d5c2ab24812f676636f311fd4c59076", "size": 608, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Sierpinski-triangle/Fortran/sierpinski-triangle.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Sierpinski-triangle/Fortran/sierpinski-triangle.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Sierpinski-triangle/Fortran/sierpinski-triangle.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 20.2666666667, "max_line_length": 64, "alphanum_fraction": 0.5361842105, "num_tokens": 213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172572644806, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.7501478524105729}} {"text": "PROGRAM me1xb\n \n! Code converted using TO_F90 by Alan Miller\n! Date: 2004-06-28 Time: 12:58:10\n\n! =========================================================\n! Purpose: This program computes the exponential integral\n! E1(x) using subroutine E1XB\n! Input : x --- Argument of E1(x) ( x > 0 )\n! Output: E1 --- E1(x)\n! Example:\n! x E1(x)\n! -------------------------\n! 0.0 .1000000000+301\n! 1.0 .2193839344E+00\n! 2.0 .4890051071E-01\n! 3.0 .1304838109E-01\n! 4.0 .3779352410E-02\n! 5.0 .1148295591E-02\n! =========================================================\n\nDOUBLE PRECISION :: e1,x\nWRITE(*,*)'Please enter x '\n! READ(*,*) X\nx=5.0\nWRITE(*,*)' x E1(x)'\nWRITE(*,*)' -------------------------'\nCALL e1xb(x,e1)\nWRITE(*,10)x,e1\n10 FORMAT(1X,f5.1,e20.10)\nEND PROGRAM me1xb\n\n\nSUBROUTINE e1xb(x,e1)\n\n! ============================================\n! Purpose: Compute exponential integral E1(x)\n! Input : x --- Argument of E1(x)\n! Output: E1 --- E1(x) ( x > 0 )\n! ============================================\n\n\n\nDOUBLE PRECISION, INTENT(IN) :: x\nDOUBLE PRECISION, INTENT(OUT) :: e1\nIMPLICIT DOUBLE PRECISION (a-h,o-z)\nIF (x == 0.0) THEN\n e1=1.0D+300\nELSE IF (x <= 1.0) THEN\n e1=1.0D0\n r=1.0D0\n DO k=1,25\n r=-r*k*x/(k+1.0D0)**2\n e1=e1+r\n IF (DABS(r) <= DABS(e1)*1.0D-15) EXIT\n END DO\n 15 ga=0.5772156649015328D0\n e1=-ga-DLOG(x)+x*e1\nELSE\n m=20+INT(80.0/x)\n t0=0.0D0\n DO k=m,1,-1\n t0=k/(1.0D0+k/(x+t0))\n END DO\n t=1.0D0/(x+t0)\n e1=DEXP(-x)*t\nEND IF\nRETURN\nEND SUBROUTINE e1xb\n", "meta": {"hexsha": "479b9d54b605051c1d323974e8394f3c987fc575", "size": 1791, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MATLAB/f2matlab/comp_spec_func/me1xb.f90", "max_stars_repo_name": "vasaantk/bin", "max_stars_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATLAB/f2matlab/comp_spec_func/me1xb.f90", "max_issues_repo_name": "vasaantk/bin", "max_issues_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATLAB/f2matlab/comp_spec_func/me1xb.f90", "max_forks_repo_name": "vasaantk/bin", "max_forks_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.5857142857, "max_line_length": 65, "alphanum_fraction": 0.4221105528, "num_tokens": 633, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735665, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.7501422453431518}} {"text": "*DECK DRJ\n DOUBLE PRECISION FUNCTION DRJ (X, Y, Z, P, IER)\nC***BEGIN PROLOGUE DRJ\nC***PURPOSE Compute the incomplete or complete (X or Y or Z is zero)\nC elliptic integral of the 3rd kind. For X, Y, and Z non-\nC negative, at most one of them zero, and P positive,\nC RJ(X,Y,Z,P) = Integral from zero to infinity of\nC -1/2 -1/2 -1/2 -1\nC (3/2)(t+X) (t+Y) (t+Z) (t+P) dt.\nC***LIBRARY SLATEC\nC***CATEGORY C14\nC***TYPE DOUBLE PRECISION (RJ-S, DRJ-D)\nC***KEYWORDS COMPLETE ELLIPTIC INTEGRAL, DUPLICATION THEOREM,\nC INCOMPLETE ELLIPTIC INTEGRAL, INTEGRAL OF THE THIRD KIND,\nC TAYLOR SERIES\nC***AUTHOR Carlson, B. C.\nC Ames Laboratory-DOE\nC Iowa State University\nC Ames, IA 50011\nC Notis, E. M.\nC Ames Laboratory-DOE\nC Iowa State University\nC Ames, IA 50011\nC Pexton, R. L.\nC Lawrence Livermore National Laboratory\nC Livermore, CA 94550\nC***DESCRIPTION\nC\nC 1. DRJ\nC Standard FORTRAN function routine\nC Double precision version\nC The routine calculates an approximation result to\nC DRJ(X,Y,Z,P) = Integral from zero to infinity of\nC\nC -1/2 -1/2 -1/2 -1\nC (3/2)(t+X) (t+Y) (t+Z) (t+P) dt,\nC\nC where X, Y, and Z are nonnegative, at most one of them is\nC zero, and P is positive. If X or Y or Z is zero, the\nC integral is COMPLETE. The duplication theorem is iterated\nC until the variables are nearly equal, and the function is\nC then expanded in Taylor series to fifth order.\nC\nC\nC 2. Calling Sequence\nC DRJ( X, Y, Z, P, IER )\nC\nC Parameters on Entry\nC Values assigned by the calling routine\nC\nC X - Double precision, nonnegative variable\nC\nC Y - Double precision, nonnegative variable\nC\nC Z - Double precision, nonnegative variable\nC\nC P - Double precision, positive variable\nC\nC\nC On Return (values assigned by the DRJ routine)\nC\nC DRJ - Double precision approximation to the integral\nC\nC IER - Integer\nC\nC IER = 0 Normal and reliable termination of the\nC routine. It is assumed that the requested\nC accuracy has been achieved.\nC\nC IER > 0 Abnormal termination of the routine\nC\nC\nC X, Y, Z, P are unaltered.\nC\nC\nC 3. Error Messages\nC\nC Value of IER assigned by the DRJ routine\nC\nC Value assigned Error Message printed\nC IER = 1 MIN(X,Y,Z) .LT. 0.0D0\nC = 2 MIN(X+Y,X+Z,Y+Z,P) .LT. LOLIM\nC = 3 MAX(X,Y,Z,P) .GT. UPLIM\nC\nC\nC\nC 4. Control Parameters\nC\nC Values of LOLIM, UPLIM, and ERRTOL are set by the\nC routine.\nC\nC\nC LOLIM and UPLIM determine the valid range of X, Y, Z, and P\nC\nC LOLIM is not less than the cube root of the value\nC of LOLIM used in the routine for DRC.\nC\nC UPLIM is not greater than 0.3 times the cube root of\nC the value of UPLIM used in the routine for DRC.\nC\nC\nC Acceptable values for: LOLIM UPLIM\nC IBM 360/370 SERIES : 2.0D-26 3.0D+24\nC CDC 6000/7000 SERIES : 5.0D-98 3.0D+106\nC UNIVAC 1100 SERIES : 5.0D-103 6.0D+101\nC CRAY : 1.32D-822 1.4D+821\nC VAX 11 SERIES : 2.5D-13 9.0D+11\nC\nC\nC\nC ERRTOL determines the accuracy of the answer\nC\nC the value assigned by the routine will result\nC in solution precision within 1-2 decimals of\nC \"machine precision\".\nC\nC\nC\nC\nC Relative error due to truncation of the series for DRJ\nC is less than 3 * ERRTOL ** 6 / (1 - ERRTOL) ** 3/2.\nC\nC\nC\nC The accuracy of the computed approximation to the integral\nC can be controlled by choosing the value of ERRTOL.\nC Truncation of a Taylor series after terms of fifth order\nC introduces an error less than the amount shown in the\nC second column of the following table for each value of\nC ERRTOL in the first column. In addition to the truncation\nC error there will be round-off error, but in practice the\nC total error from both sources is usually less than the\nC amount given in the table.\nC\nC\nC\nC Sample choices: ERRTOL Relative truncation\nC error less than\nC 1.0D-3 4.0D-18\nC 3.0D-3 3.0D-15\nC 1.0D-2 4.0D-12\nC 3.0D-2 3.0D-9\nC 1.0D-1 4.0D-6\nC\nC Decreasing ERRTOL by a factor of 10 yields six more\nC decimal digits of accuracy at the expense of one or\nC two more iterations of the duplication theorem.\nC\nC *Long Description:\nC\nC DRJ Special Comments\nC\nC\nC Check by addition theorem: DRJ(X,X+Z,X+W,X+P)\nC + DRJ(Y,Y+Z,Y+W,Y+P) + (A-B) * DRJ(A,B,B,A) + 3.0D0 / SQRT(A)\nC = DRJ(0,Z,W,P), where X,Y,Z,W,P are positive and X * Y\nC = Z * W, A = P * P * (X+Y+Z+W), B = P * (P+X) * (P+Y),\nC and B - A = P * (P-Z) * (P-W). The sum of the third and\nC fourth terms on the left side is 3.0D0 * DRC(A,B).\nC\nC\nC On Input:\nC\nC X, Y, Z, and P are the variables in the integral DRJ(X,Y,Z,P).\nC\nC\nC On Output:\nC\nC\nC X, Y, Z, P are unaltered.\nC\nC ********************************************************\nC\nC WARNING: Changes in the program may improve speed at the\nC expense of robustness.\nC\nC -------------------------------------------------------------------\nC\nC\nC Special double precision functions via DRJ and DRF\nC\nC\nC Legendre form of ELLIPTIC INTEGRAL of 3rd kind\nC -----------------------------------------\nC\nC\nC PHI 2 -1\nC P(PHI,K,N) = INT (1+N SIN (THETA) ) *\nC 0\nC\nC\nC 2 2 -1/2\nC *(1-K SIN (THETA) ) D THETA\nC\nC\nC 2 2 2\nC = SIN (PHI) DRF(COS (PHI), 1-K SIN (PHI),1)\nC\nC 3 2 2 2\nC -(N/3) SIN (PHI) DRJ(COS (PHI),1-K SIN (PHI),\nC\nC 2\nC 1,1+N SIN (PHI))\nC\nC\nC\nC Bulirsch form of ELLIPTIC INTEGRAL of 3rd kind\nC -----------------------------------------\nC\nC\nC 2 2 2\nC EL3(X,KC,P) = X DRF(1,1+KC X ,1+X ) +\nC\nC 3 2 2 2 2\nC +(1/3)(1-P) X DRJ(1,1+KC X ,1+X ,1+PX )\nC\nC\nC 2\nC CEL(KC,P,A,B) = A RF(0,KC ,1) +\nC\nC\nC 2\nC +(1/3)(B-PA) DRJ(0,KC ,1,P)\nC\nC\nC Heuman's LAMBDA function\nC -----------------------------------------\nC\nC\nC 2 2 2 1/2\nC L(A,B,P) =(COS (A)SIN(B)COS(B)/(1-COS (A)SIN (B)) )\nC\nC 2 2 2\nC *(SIN(P) DRF(COS (P),1-SIN (A) SIN (P),1)\nC\nC 2 3 2 2\nC +(SIN (A) SIN (P)/(3(1-COS (A) SIN (B))))\nC\nC 2 2 2\nC *DRJ(COS (P),1-SIN (A) SIN (P),1,1-\nC\nC 2 2 2 2\nC -SIN (A) SIN (P)/(1-COS (A) SIN (B))))\nC\nC\nC\nC (PI/2) LAMBDA0(A,B) =L(A,B,PI/2) =\nC\nC 2 2 2 -1/2\nC = COS (A) SIN(B) COS(B) (1-COS (A) SIN (B))\nC\nC 2 2 2\nC *DRF(0,COS (A),1) + (1/3) SIN (A) COS (A)\nC\nC 2 2 -3/2\nC *SIN(B) COS(B) (1-COS (A) SIN (B))\nC\nC 2 2 2 2 2\nC *DRJ(0,COS (A),1,COS (A) COS (B)/(1-COS (A) SIN (B)))\nC\nC\nC Jacobi ZETA function\nC -----------------------------------------\nC\nC 2 2 2 1/2\nC Z(B,K) = (K/3) SIN(B) COS(B) (1-K SIN (B))\nC\nC\nC 2 2 2 2\nC *DRJ(0,1-K ,1,1-K SIN (B)) / DRF (0,1-K ,1)\nC\nC\nC ---------------------------------------------------------------------\nC\nC***REFERENCES B. C. Carlson and E. M. Notis, Algorithms for incomplete\nC elliptic integrals, ACM Transactions on Mathematical\nC Software 7, 3 (September 1981), pp. 398-403.\nC B. C. Carlson, Computing elliptic integrals by\nC duplication, Numerische Mathematik 33, (1979),\nC pp. 1-16.\nC B. C. Carlson, Elliptic integrals of the first kind,\nC SIAM Journal of Mathematical Analysis 8, (1977),\nC pp. 231-242.\nC***ROUTINES CALLED D1MACH, DRC, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 790801 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 891009 Removed unreferenced statement labels. (WRB)\nC 891009 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 900510 Changed calls to XERMSG to standard form, and some\nC editorial changes. (RWC)).\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE DRJ\n INTEGER IER\n CHARACTER*16 XERN3, XERN4, XERN5, XERN6, XERN7\n DOUBLE PRECISION ALFA, BETA, C1, C2, C3, C4, EA, EB, EC, E2, E3\n DOUBLE PRECISION LOLIM, UPLIM, EPSLON, ERRTOL, D1MACH\n DOUBLE PRECISION LAMDA, MU, P, PN, PNDEV\n DOUBLE PRECISION POWER4, DRC, SIGMA, S1, S2, S3, X, XN, XNDEV\n DOUBLE PRECISION XNROOT, Y, YN, YNDEV, YNROOT, Z, ZN, ZNDEV,\n * ZNROOT\n LOGICAL FIRST\n SAVE ERRTOL,LOLIM,UPLIM,C1,C2,C3,C4,FIRST\n DATA FIRST /.TRUE./\nC\nC***FIRST EXECUTABLE STATEMENT DRJ\n IF (FIRST) THEN\n ERRTOL = (D1MACH(3)/3.0D0)**(1.0D0/6.0D0)\n LOLIM = (5.0D0 * D1MACH(1))**(1.0D0/3.0D0)\n UPLIM = 0.30D0*( D1MACH(2) / 5.0D0)**(1.0D0/3.0D0)\nC\n C1 = 3.0D0/14.0D0\n C2 = 1.0D0/3.0D0\n C3 = 3.0D0/22.0D0\n C4 = 3.0D0/26.0D0\n ENDIF\n FIRST = .FALSE.\nC\nC CALL ERROR HANDLER IF NECESSARY.\nC\n DRJ = 0.0D0\n IF (MIN(X,Y,Z).LT.0.0D0) THEN\n IER = 1\n WRITE (XERN3, '(1PE15.6)') X\n WRITE (XERN4, '(1PE15.6)') Y\n WRITE (XERN5, '(1PE15.6)') Z\n CALL XERMSG ('SLATEC', 'DRJ',\n * 'MIN(X,Y,Z).LT.0 WHERE X = ' // XERN3 // ' Y = ' // XERN4 //\n * ' AND Z = ' // XERN5, 1, 1)\n RETURN\n ENDIF\nC\n IF (MAX(X,Y,Z,P).GT.UPLIM) THEN\n IER = 3\n WRITE (XERN3, '(1PE15.6)') X\n WRITE (XERN4, '(1PE15.6)') Y\n WRITE (XERN5, '(1PE15.6)') Z\n WRITE (XERN6, '(1PE15.6)') P\n WRITE (XERN7, '(1PE15.6)') UPLIM\n CALL XERMSG ('SLATEC', 'DRJ',\n * 'MAX(X,Y,Z,P).GT.UPLIM WHERE X = ' // XERN3 // ' Y = ' //\n * XERN4 // ' Z = ' // XERN5 // ' P = ' // XERN6 //\n * ' AND UPLIM = ' // XERN7, 3, 1)\n RETURN\n ENDIF\nC\n IF (MIN(X+Y,X+Z,Y+Z,P).LT.LOLIM) THEN\n IER = 2\n WRITE (XERN3, '(1PE15.6)') X\n WRITE (XERN4, '(1PE15.6)') Y\n WRITE (XERN5, '(1PE15.6)') Z\n WRITE (XERN6, '(1PE15.6)') P\n WRITE (XERN7, '(1PE15.6)') LOLIM\n CALL XERMSG ('SLATEC', 'RJ',\n * 'MIN(X+Y,X+Z,Y+Z,P).LT.LOLIM WHERE X = ' // XERN3 //\n * ' Y = ' // XERN4 // ' Z = ' // XERN5 // ' P = ' // XERN6 //\n * ' AND LOLIM = ', 2, 1)\n RETURN\n ENDIF\nC\n IER = 0\n XN = X\n YN = Y\n ZN = Z\n PN = P\n SIGMA = 0.0D0\n POWER4 = 1.0D0\nC\n 30 MU = (XN+YN+ZN+PN+PN)*0.20D0\n XNDEV = (MU-XN)/MU\n YNDEV = (MU-YN)/MU\n ZNDEV = (MU-ZN)/MU\n PNDEV = (MU-PN)/MU\n EPSLON = MAX(ABS(XNDEV), ABS(YNDEV), ABS(ZNDEV), ABS(PNDEV))\n IF (EPSLON.LT.ERRTOL) GO TO 40\n XNROOT = SQRT(XN)\n YNROOT = SQRT(YN)\n ZNROOT = SQRT(ZN)\n LAMDA = XNROOT*(YNROOT+ZNROOT) + YNROOT*ZNROOT\n ALFA = PN*(XNROOT+YNROOT+ZNROOT) + XNROOT*YNROOT*ZNROOT\n ALFA = ALFA*ALFA\n BETA = PN*(PN+LAMDA)*(PN+LAMDA)\n SIGMA = SIGMA + POWER4*DRC(ALFA,BETA,IER)\n POWER4 = POWER4*0.250D0\n XN = (XN+LAMDA)*0.250D0\n YN = (YN+LAMDA)*0.250D0\n ZN = (ZN+LAMDA)*0.250D0\n PN = (PN+LAMDA)*0.250D0\n GO TO 30\nC\n 40 EA = XNDEV*(YNDEV+ZNDEV) + YNDEV*ZNDEV\n EB = XNDEV*YNDEV*ZNDEV\n EC = PNDEV*PNDEV\n E2 = EA - 3.0D0*EC\n E3 = EB + 2.0D0*PNDEV*(EA-EC)\n S1 = 1.0D0 + E2*(-C1+0.750D0*C3*E2-1.50D0*C4*E3)\n S2 = EB*(0.50D0*C2+PNDEV*(-C3-C3+PNDEV*C4))\n S3 = PNDEV*EA*(C2-PNDEV*C3) - C2*PNDEV*EC\n DRJ = 3.0D0*SIGMA + POWER4*(S1+S2+S3)/(MU* SQRT(MU))\n RETURN\n END\n", "meta": {"hexsha": "944f5b73dbe2b1a9b877d7161b03cf063f1d87d5", "size": 14033, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/drj.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/drj.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/drj.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.5640394089, "max_line_length": 72, "alphanum_fraction": 0.4591320459, "num_tokens": 4699, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012640659996, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7501206157933861}} {"text": " SUBROUTINE DHTGEN (MODE,LPIVOT,L1,M,U,LDU,COLU,UPARAM,\n * C,LDC,NVC,COLC)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1996-03-30 DHTGEN Krogh Added external statement.\nC>> 1994-11-11 DHTGEN Krogh Declared all vars.\nC>> 1994-10-20 DHTGEN Krogh Changes to use M77CON\nC>> 1987-08-19 DHTGEN Lawson Initial code.\nc--D replaces \"?\": ?HTGEN, ?AXPY, ?DOT, ?NRM2\nc\nC Construction and/or application of a single Householder\nC transformation.. Q = I + U*(U**T)/b\nc where I is the MxM identity matrix, b is a scalar, and U is an\nc M-dimensional Householder vector.\nc All vectors are M-vectors but only the components in positions\nc LPIVOT, and L1 through M, will be referenced.\nc This version, identified by GEN at the end of its name,\nc has the GENerality to handle the options of the U-vector being\nc stored either as a column or row of a matrix, and the vectors in\nc C() may be either column or row vectors.\nc ------------------------------------------------------------------\nC Subroutine arguments\nc\nC MODE [in] = 1 OR 2 When MODE = 1 this subr determines the\nc parameters for a Householder transformation and applies\nc the transformation to NVC vectors. When MODE = 2 this\nc subr applies a previously determined Householder\nc transformation.\nC LPIVOT [in] The index of the pivot element.\nC L1,M [in] If L1 .le. M elements LPIVOT and L1 through M will\nc be referenced. If L1 .gt. M the subroutine returns\nc immediately. This may be regarded\nc as performing an identity transformation.\nC U() [inout] Contains the \"pivot\" vector. Typically U() will be\nc a two-dimensional array in the calling program and the pivot\nc vector may be either a column or row in this array.\nc When MODE = 1 this is the vector from which Householder\nc parameters are to be determined.\nc When MODE = 2 this is the result from previous computation\nc with MODE = 1.\nc LDU [in] Leading dimensioning parameter for U() in the calling\nc program where U() is a two-dimensional array. Gives\nc storage spacing between elements in a row of U() when U() is\nc regarded as a two-dimensional array.\nC COLU [in] True means the pivot vector is a column of the 2-dim\nc array U(). Thus the successive elements of the pivot vector\nc are at unit storage spacing.\nc False means the pivot vector is a row of the 2-dim array U()\nc Thus the storage spacing between successive elements is LDU.\nc UPARAM [inout] Holds a value that supplements the contents\nc of U() to complete the definition of a\nc Householder transformation. Computed when MODE = 1 and\nc reused when MODE = 2.\nc UPARAM is the pivot component of the Householder U-vector.\nC C() [inout] On entry contains a set of NVC M-vectors to which a\nc Householder transformation is to be applied.\nc On exit contains the set of transformed vectors.\nc Typically in the calling program C() will be a 2-dim array\nc with leading dimensioning parameter LDC.\nC These vectors are the columns of an M x NVC matrix in C(,) if\nc COLC = true, and are rows of an NVC x M matrix in C(,) if\nc COLC = false.\nC LDC [in] Leading dimension of C(,). Require LDC .ge. M if\nc COLC = true. Require LDC .ge. NVC if COLC = false.\nC NVC [in] Number of vectors in C(,) to be transformed.\nc If NVC .le. 0 no reference will be made to the array C(,).\nc COLC [in] True means the transformations are to be applied to\nc columns of the array C(,). False means the transformations\nc are to be applied to rows of the array C(,).\nc ------------------------------------------------------------------\nc Subprograms referenced: DAXPY, DDOT, DNRM2\nc ------------------------------------------------------------------\nc This code was originally developed by Charles L. Lawson and\nc Richard J. Hanson at Jet Propulsion Laboratory in 1973. The\nc original code was described and listed in the book,\nc\nc Solving Least Squares Problems\nc C. L. Lawson and R. J. Hanson\nc Prentice-Hall, 1974\nc\nc Feb, 1985, C. L. Lawson & S. Y. Chan, JPL. Adapted code from the\nc Lawson & Hanson book to Fortran 77 for use in the JPL MATH77\nc library.\nc Prefixing subprogram names with S or D for s.p. or d.p. versions.\nc Using generic names for intrinsic functions.\nc Adding calls to BLAS and MATH77 error processing subrs in some\nc program units.\nc July, 1987. CLL. Changed user interface so method of specifying\nc column/row storage options is more language-independent.\nC ------------------------------------------------------------------\n external DDOT, DNRM2\n double precision U(*), UPARAM, C(*), DDOT, DNRM2\n double precision B, FAC, HOLD, VNORM, ONE, ZERO, SUM, BINV\n integer MODE, LPIVOT, L1, M, LDU, LDC, NVC\n integer IUPIV, IUL1, IUINC, IUL0\n integer ICE, ICV, I2, I3, INCR, NTERMS, J\n logical COLU, COLC\n parameter (ONE = 1.0D0, ZERO = 0.0D0)\nC ------------------------------------------------------------------\n if (0.ge.LPIVOT .or. LPIVOT.ge.L1 .or. L1.gt.M) return\n if(COLU) then\n IUPIV = LPIVOT\n IUL1 = L1\n IUINC = 1\n else\n IUPIV = 1 + LDU * (LPIVOT-1)\n IUL1 = 1 + LDU * (L1-1)\n IUINC = LDU\n endif\nc\n if( MODE .eq. 1) then\nC ****** CONSTRUCT THE TRANSFORMATION. ******\n IUL0 = IUL1 - IUINC\n if(IUL0 .eq. IUPIV) then\n VNORM = DNRM2(M-L1+2, U(IUL0), IUINC)\n else\n HOLD = U(IUL0)\n U(IUL0) = U(IUPIV)\n VNORM = DNRM2(M-L1+2, U(IUL0), IUINC)\n U(IUL0) = HOLD\n endif\nc\n if (U(IUPIV) .gt. ZERO) VNORM = -VNORM\n UPARAM = U(IUPIV)-VNORM\n U(IUPIV) = VNORM\n endif\nC ****** Apply the transformation I + U*(U**T)/B to C. ****\nC\n if (NVC.LE.0) return\n B = UPARAM * U(IUPIV)\nc Here B .le. 0. If B = 0., return.\n if (B .eq. ZERO) return\n BINV = ONE / B\nc I2 = 1 - ICV + ICE*(LPIVOT-1)\nc INCR = ICE * (L1-LPIVOT)\n if(COLC) then\n ICE = 1\n ICV = LDC\n I2 = LPIVOT - LDC\n INCR = L1 - LPIVOT\n else\n ICE = LDC\n ICV = 1\n I2 = ICE*(LPIVOT-1)\n INCR = ICE*(L1-LPIVOT)\n endif\nc\n NTERMS = M-L1+1\n do 120 J = 1,NVC\n I2 = I2 + ICV\n I3 = I2 + INCR\n SUM = UPARAM * C(I2) + DDOT(NTERMS, U(IUL1),IUINC, C(I3),ICE)\n if (SUM .ne. ZERO) then\n FAC = SUM*BINV\n C(I2) = C(I2) + FAC*UPARAM\n call DAXPY(NTERMS, FAC, U(IUL1),IUINC, C(I3),ICE)\n endif\n 120 continue\n return\n end\n", "meta": {"hexsha": "d55bc7a61ed054a05173c4df58921308f0572e31", "size": 7308, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dhtgen.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/dhtgen.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/dhtgen.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 45.1111111111, "max_line_length": 72, "alphanum_fraction": 0.565270936, "num_tokens": 2106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355092, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7500857098891446}} {"text": "MODULE GS\n\n CONTAINS\n \n SUBROUTINE GaussSeidel_UV2( A, u, b, t, rb, fator)\n \n USE ClassMatrizA\n \n IMPLICIT NONE\n \n TYPE ( MatrizA ), INTENT(IN) :: A\n DOUBLE PRECISION, DIMENSION(:, :), INTENT(INOUT) :: u\n DOUBLE PRECISION, DIMENSION(:, :), INTENT(IN) :: b\n INTEGER, INTENT(IN) :: t, rb\n DOUBLE PRECISION, INTENT(IN) :: fator\n \n INTEGER :: p, pp, stencil, ite, se ! se = elemento do stencil\n DOUBLE PRECISION :: ax, ux, sm, correcao ! Soma dos componentes do stencil\n INTEGER :: linha, inicio, new_rb\n \n new_rb = (1 + rb)/2\n inicio = ABS(MOD(t,2) - new_rb )\n \n DO pp = 1 + inicio, A % Nx * A % Ny, 2\n \n ! Calculando a linha de p\n linha = (pp-1)/(A % Nx) + 1\n \n ! Fazendo a correcao do caso Nx par (black points sao pares ao inves de impares)\n p = pp + MOD(linha + 1, 2)*MOD(A % Nx + 1, 2)*(1 - 2*inicio)\n \n ! Obtendo o stencil do volume\n stencil = A % v(p)\n \n ! Para cada coeficiente do stencil da matriz\n ! Lembrando que o primeiro e sempre ap e Gauss-Seidel\n ! e definido como \n ! u(p) = (aw * u(p-1) + ae * u(p+1) + as * u(p-Nx) ... + b(p)) / ap\n ! O codigo abaixo soma aw * u(p-1) + ae * u(p+1) + as * u(p-Nx) ...\n sm = 0.0d0\n DO se = 2, SIZE(A % s(stencil) % p) !(comeca em 2 porque nao considera o ap)\n \n ! ax = aw, ae, as, an, aww, ann, etc...\n ! ux = u(p-1), u(p+1), u(p-Nx), u(p+Nx), u(p-2), u(p+2*Nx), etc...\n ! Logo\n ! ax * ux = aw * u(p-1), ae * u(p+1), as * u(p-Nx), etc...\n \n ax = A % s(stencil) % c(se)\n ux = u(p + A % s(stencil) % p(se), t+1)\n \n sm = sm + ax * ux\n \n END DO \n \n ! Obtendo o ap\n ax = A % s(stencil) % c(1)\n sm = sm + u(p, t) * fator\n \n ! Somando b(p) e divindo por ap para completar o Gauss-Seidel\n u(p, t+1) = (sm + b(p, t))/ax\n \n END DO\n \n \n END SUBROUTINE GaussSeidel_UV2\n\n \n \n SUBROUTINE GaussSeidel_UV( A, u, b, t, rb)\n \n USE ClassMatrizA\n \n IMPLICIT NONE\n \n TYPE ( MatrizA ), INTENT(IN) :: A\n DOUBLE PRECISION, DIMENSION(:, :), INTENT(INOUT) :: u\n DOUBLE PRECISION, DIMENSION(:, :), INTENT(IN) :: b\n INTEGER, INTENT(IN) :: t, rb\n \n INTEGER :: p, pp, stencil, ite, se ! se = elemento do stencil\n DOUBLE PRECISION :: ax, ux, sm, correcao ! Soma dos componentes do stencil\n INTEGER :: linha, inicio, new_rb\n \n new_rb = (1 + rb)/2\n inicio = ABS(MOD(t,2) - new_rb )\n \n DO pp = 1 + inicio, A % Nx * A % Ny, 2\n \n ! Calculando a linha de p\n linha = (pp-1)/(A % Nx) + 1\n \n ! Fazendo a correcao do caso Nx par (black points sao pares ao inves de impares)\n p = pp + MOD(linha + 1, 2)*MOD(A % Nx + 1, 2)*(1 - 2*inicio)\n \n ! Obtendo o stencil do volume\n stencil = A % v(p)\n \n ! Para cada coeficiente do stencil da matriz\n ! Lembrando que o primeiro e sempre ap e Gauss-Seidel\n ! e definido como \n ! u(p) = (aw * u(p-1) + ae * u(p+1) + as * u(p-Nx) ... + b(p)) / ap\n ! O codigo abaixo soma aw * u(p-1) + ae * u(p+1) + as * u(p-Nx) ...\n sm = 0.0d0\n DO se = 2, SIZE(A % s(stencil) % p) !(comeca em 2 porque nao considera o ap)\n \n ! ax = aw, ae, as, an, aww, ann, etc...\n ! ux = u(p-1), u(p+1), u(p-Nx), u(p+Nx), u(p-2), u(p+2*Nx), etc...\n ! Logo\n ! ax * ux = aw * u(p-1), ae * u(p+1), as * u(p-Nx), etc...\n \n ax = A % s(stencil) % c(se)\n ux = u(p + A % s(stencil) % p(se), t+1)\n \n sm = sm + ax * ux\n \n END DO \n \n ! Obtendo o ap\n ax = A % s(stencil) % c(1)\n sm = sm + u(p, t)\n \n ! Somando b(p) e divindo por ap para completar o Gauss-Seidel\n u(p, t+1) = (sm + b(p, t))/ax\n \n END DO\n \n \n END SUBROUTINE GaussSeidel_UV\n\n \n \n SUBROUTINE GaussSeidel( A, u, b, iteracoes )\n \n USE ClassMatrizA\n \n IMPLICIT NONE\n \n TYPE ( MatrizA ), INTENT(IN) :: A\n DOUBLE PRECISION, DIMENSION(:), INTENT(INOUT) :: u\n DOUBLE PRECISION, DIMENSION(:), INTENT(IN) :: b\n INTEGER, INTENT(IN) :: iteracoes\n \n INTEGER :: p, stencil, ite, se ! se = elemento do stencil\n DOUBLE PRECISION :: ax, ux, sm ! Soma dos componentes do stencil\n \n DO ite = 1, iteracoes\n \n DO p = 1, A % Nx * A % Ny\n \n ! Obtendo o stencil do volume\n stencil = A % v(p)\n \n ! Para cada coeficiente do stencil da matriz\n ! Lembrando que o primeiro e sempre ap e Gauss-Seidel\n ! e definido como \n ! u(p) = (aw * u(p-1) + ae * u(p+1) + as * u(p-Nx) ... + b(p)) / ap\n ! O codigo abaixo soma aw * u(p-1) + ae * u(p+1) + as * u(p-Nx) ...\n sm = 0.0d0\n DO se = 2, SIZE(A % s(stencil) % p) !(comeca em 2 porque nao considera o ap)\n \n ! ax = aw, ae, as, an, aww, ann, etc...\n ! ux = u(p-1), u(p+1), u(p-Nx), u(p+Nx), u(p-2), u(p+2*Nx), etc...\n ! Logo\n ! ax * ux = aw * u(p-1), ae * u(p+1), as * u(p-Nx), etc...\n \n ax = A % s(stencil) % c(se)\n ux = u(p + A % s(stencil) % p(se))\n \n sm = sm + ax * ux\n \n !if (A % s(stencil) % p(se) .eq. -1) then\n !write(*,*) p, ax, A % s(stencil) % p(se)\n !end if\n \n END DO \n \n ! Obtendo o ap\n ax = A % s(stencil) % c(1)\n \n ! Somando b(p) e divindo por ap para completar o Gauss-Seidel\n u(p) = (sm + b(p))/ax\n \n END DO\n !call exit()\n \n END DO\n \n END SUBROUTINE GaussSeidel\n\nEND MODULE GS\n", "meta": {"hexsha": "d63caaafebebde298068b70e2d85ae6c0801d231", "size": 7175, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gs.f90", "max_stars_repo_name": "RevertonLuis/NavierStokesSpaceTimeParallelProjectionMethod", "max_stars_repo_head_hexsha": "23fbf3b01a34c244d8928fae4ad9d12bffef8d07", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-02T16:28:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-02T16:28:12.000Z", "max_issues_repo_path": "gs.f90", "max_issues_repo_name": "RevertonLuis/NavierStokesSpaceTimeParallelProjectionMethod", "max_issues_repo_head_hexsha": "23fbf3b01a34c244d8928fae4ad9d12bffef8d07", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gs.f90", "max_forks_repo_name": "RevertonLuis/NavierStokesSpaceTimeParallelProjectionMethod", "max_forks_repo_head_hexsha": "23fbf3b01a34c244d8928fae4ad9d12bffef8d07", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.5654450262, "max_line_length": 99, "alphanum_fraction": 0.3793728223, "num_tokens": 1996, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7500191931805685}} {"text": " subroutine DSTAT1(XTAB, NX, STATS, IHIST, NCELLS, X1, X2)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1997-04-25 DSTAT1 Krogh Simplified code (WVS suggestion)\nC>> 1994-11-11 DSTAT1 Krogh Declared all vars.\nC>> 1994-10-20 DSTAT1 Krogh Changes to use M77CON\nC>> 1989-10-20 DSTAT1 CLL\nC>> 1987-05-01 DSTAT1 Lawson Initial code.\nc--D replaces \"?\": ?STAT1, ?STAT2\nc\nc This subr computes basic statistics for X, storing them is\nc STATS() as follows:\nc\nc STATS(1) = Total count\nc STATS(2) = Min\nc STATS(3) = Max\nc STATS(4) = Mean\nc STATS(5) = Standard deviation\nc\nc This subr also accumulates counts in IHIST() to develop a\nc histogram of values of X.\nc\nc The data to be treated is given in XTAB(1:NX). If the\nc value of STATS(1) on entry is positive , say = COUNT, it is\nc assumed that COUNT data values have been processed previously\nc and results from that processing are in IHIST() and STATS().\nc These results will be updated to reflect the additional set of\nc NX values.\nc\nc Alternatively, if STATS(1) is zero, the initial contents of\nc STATS(2:5) and IHIST() will be ignored and results will be\nc computed just for the present data set XTAB(1:NX).\nc\nc The user must specify the range and resolution of the histogram\nc by setting X1, X2, and NCELLS. The end cells, IHIST(1) and\nc IHIST(NCELLS) will be used to count occurences of X less than X1\nc or greater than X2 respectively.\nc The cells IHIST(2) through IHIST(NCELLS-1) will\nc be used to count occurences of X in NCELLS-2 equal-length\nc subintervals of [X1, X2].\nc\nc Define h = (X2 - X1)/(NCELLS-2). X-intervals will be\nc associated with elements of IHIST() as follows.\nc\nc X interval Counting cell\nc\nc (-Infinity, X1) IHIST(1)\nc [X1+(i-2)*h, X1+(i-1)*h) IHIST(i), i = 2,...,NCELLS-2\nc [X2-h, X2] IHIST(NCELLS-1)\nc (X2, Infinity) IHIST(NCELLS)\nc\nc After use of this subroutine, the user can call\nc DSTAT2, to produce a printer-plot of the histogram and print the\nc statistics.\nc\nc Remark: It is more efficient to call this subroutine one\nc time giving it N points rather than calling it N times giving it\nc one point each time, but the results will be the same to within\nc arithmetic limitations either way.\nc ------------------------------------------------------------------\nc Subroutine arguments\nc\nc XTAB() [in] Array of NX values whose statistics are to be\nc computed.\nc NX [in] Number of values given in XTAB().\nc Require NX .ge. 1.\nc STATS() [inout] Array of length 5 into which statistics are or\nc will be stored. Initial value of STATS(1) must be positive\nc if IHIST() and STATS() contain prior results that are to be\nc updated. Otherwise the initial value of STATS(1) must be\nc zero.\nc IHIST() [inout] Integer array of length at least NCELLS into\nc which counts will be accumulated.\nc NCELLS [in] Total number of classification regions.\nc Require NCELLS .ge. 3.\nc X1,X2 [in] Lower and upper boundaries, respectively defining\nc the range of y values to be classified into NCELLS-2 equal\nc intervals. Require X1 < X2.\nc ------------------------------------------------------------------\nc The value of FAC is not critical. It should be greater than\nc one. The program does less computation each time the test\nc (abs(DELTA) .lt. TEST) is satisfied. It will be true more\nc frequently if FAC is larger. There is probably not much advantage\nc in setting FAC larger than 4, so 64 is probably more than ample.\nc ------------------------------------------------------------------\nc C. L. Lawson and S. Y. Chiu, JPL, Apr 1987.\nC 1989-10-20 CLL Moved integer declaration earlier to avoid warning\nc msg from Cray compiler.\nc ------------------------------------------------------------------\n integer NCELLS, NX\n integer IHIST(NCELLS)\n integer I, INDEX, J\n double precision COUNT, DELTA, FAC, PREV\n double precision SCALE, RSCALE, SCLNEW, STATS(5), SUMSCL\n double precision TEMP, TEST, X, X1, X2, XMAX, XMEAN, XMIN\n double precision XTAB(NX)\n parameter(FAC = 64.0D0)\nc ------------------------------------------------------------------\n if(NX .lt. 1) return\n COUNT = STATS(1)\n if(COUNT .eq. 0.D0) then\n do 10 I=1,NCELLS\n IHIST(I) = 0\n 10 continue\nc\nc Begin: Special for first point\nc\n PREV = 0.D0\n X = XTAB(1)\n XMIN = X\n XMAX = X\n XMEAN = 0.D0\n TEST = -1.0D0\n SUMSCL = 0.D0\nc End: Special for first point\nc\n else\nc Here when COUNT is > zero on entry.\n XMIN = STATS(2)\n XMAX = STATS(3)\n XMEAN = STATS(4)\nc\n if(STATS(5) .eq. 0.D0) then\n TEST = -1.0D0\n SUMSCL = 0.D0\n else\nc\nc STATS(5) contains the old value of Sigma. Since it is\nc nonzero (positive) here, COUNT must be at least 2.\nc\n SCALE = STATS(5)\n RSCALE = 1.0D0/SCALE\n TEST = FAC * SCALE\n SUMSCL = COUNT - 1.0D0\n endif\n endif\nc\n do 30 J = 1, NX\n PREV = COUNT\n COUNT = COUNT + 1.0D0\n X = XTAB(J)\n XMIN = min(X, XMIN)\n XMAX = max(X, XMAX)\nc . Begin: Tally in histogram.\n if(X .lt. X1) then\n IHIST(1) = IHIST(1) + 1\n elseif(X .gt. X2) then\n IHIST(NCELLS) = IHIST(NCELLS) + 1\n else\nc Following stmt converts integer to float.\n TEMP = NCELLS-2\nc Following stmt converts float to integer.\n INDEX = TEMP*(X-X1)/(X2-X1)\n IHIST(INDEX + 2) = IHIST(INDEX + 2) + 1\n endif\nc . End: Tally in histogram.\nc\n DELTA = X - XMEAN\nc\nc Expect abs(DELTA) .le. TEST most of the time.\nc\n if(abs(DELTA) .gt. TEST) then\n if( DELTA .eq. 0.D0 ) go to 20\nc\nc Here abs(DELTA) .gt. TEST and DELTA .ne. 0.D0\nc Must compute new SCALE, RSCALE and TEST\nc and update SUMSCL if it is nonzero.\nc\n SCLNEW = abs(DELTA)\n RSCALE = 1.0D0 / SCLNEW\n TEST = FAC * SCLNEW\n if(SUMSCL .ne. 0.D0) SUMSCL = SUMSCL * (SCALE * RSCALE)**2\n SCALE = SCLNEW\n endif\n XMEAN = XMEAN + DELTA / COUNT\n SUMSCL = SUMSCL + (PREV/COUNT) * (DELTA*RSCALE)**2\n 20 continue\n 30 continue\nc\n STATS(1) = COUNT\n STATS(2) = XMIN\n STATS(3) = XMAX\n STATS(4) = XMEAN\n if(PREV .eq. 0.D0) then\n STATS(5) = 0.D0\n else\n STATS(5) = SCALE * sqrt( SUMSCL / PREV )\n endif\n return\n end\n", "meta": {"hexsha": "b95a2c598601eb7320c838ddcc8a0c54b3d6d6cc", "size": 7299, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dstat1.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/dstat1.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/dstat1.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 38.015625, "max_line_length": 72, "alphanum_fraction": 0.5459652007, "num_tokens": 2123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.7500191837154586}} {"text": "double precision Function nansum(a,n)\n implicit none\n integer*8, intent(in) :: n\n double precision, intent(in), dimension(n) :: a\n integer*8 :: i\n nansum=0.\n do i = 1,n\n if ( isnan(a(i)) ) cycle\n nansum=nansum+a(i)\n enddo\nend Function nansum\n\ndouble precision Function nanmean(a,n)\n implicit none\n integer*8, intent(in) :: n\n double precision, intent(in), dimension(n) :: a\n integer*8 :: i,counter\n nanmean=0.; counter=0\n do i = 1,n\n if ( isnan(a(i)) ) cycle\n nanmean=nanmean+a(i)\n counter=counter+1\n enddo\n if (counter >= 1) nanmean=nanmean/counter\nend Function nanmean\n\ndouble precision Function nanstd(a,n)\n implicit none\n integer*8, intent(in) :: n\n double precision, intent(in), dimension(n) :: a\n integer*8 :: i,counter\n double precision :: nmean,nanmean\n nmean=nanmean(a,n)\n nanstd=0.; counter=0\n do i=1,n\n if ( isnan(a(i)) ) cycle\n nanstd=nanstd+(a(i)-nmean)**2\n counter=counter+1\n enddo\n if (counter >= 1) nanstd=sqrt(nanstd/counter)\nend Function nanstd\n\nsubroutine dropna(ai,n,ao,counter)\n implicit none\n integer*8, intent(in) :: n\n double precision, intent(in), dimension(n) :: ai\n double precision, intent(out), dimension(n) :: ao\n integer*8, intent(out) :: counter\n integer*8 :: i\n ao=0.; counter=0\n do i=1,n\n if ( isnan(ai(i)) ) cycle\n counter = counter+1\n ao(counter) = ai(i)\n enddo\nend subroutine dropna\n\ndouble precision Function nan_mean(a,n)\n implicit none\n integer*8, intent(in) :: n\n double precision, intent(in), dimension(n) :: a\n double precision :: at(n)\n integer*8 :: cntr\n call dropna(a,n,at,cntr)\n nan_mean=sum(at(1:cntr))/cntr\nend Function nan_mean\n\ndouble precision Function nan_median(a,n)\n implicit none\n integer*8, intent(in) :: n\n double precision, intent(in), dimension(n) :: a\n double precision :: at(n)\n double precision, allocatable, dimension(:) :: tmp\n integer*8 :: cntr\n call dropna(a,n,at,cntr)\n allocate(tmp(cntr)); tmp=at(1:cntr)\n call qsort(tmp,cntr)\n nan_median=tmp(int(cntr/2+1))\n deallocate(tmp)\nend Function nan_median\n", "meta": {"hexsha": "b3624a1bf19b0780498036a07b224d27470f0d83", "size": 2128, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Analysis/TimeSeries/OLLibs/F90/DataCleaning/nan_algebra.f90", "max_stars_repo_name": "ahmadryan/TurbAn", "max_stars_repo_head_hexsha": "b8866d103a2ca2f5fbad73bcd4416f19299f22b2", "max_stars_repo_licenses": ["BSD-2-Clause-Patent"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Analysis/TimeSeries/OLLibs/F90/DataCleaning/nan_algebra.f90", "max_issues_repo_name": "ahmadryan/TurbAn", "max_issues_repo_head_hexsha": "b8866d103a2ca2f5fbad73bcd4416f19299f22b2", "max_issues_repo_licenses": ["BSD-2-Clause-Patent"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Analysis/TimeSeries/OLLibs/F90/DataCleaning/nan_algebra.f90", "max_forks_repo_name": "ahmadryan/TurbAn", "max_forks_repo_head_hexsha": "b8866d103a2ca2f5fbad73bcd4416f19299f22b2", "max_forks_repo_licenses": ["BSD-2-Clause-Patent"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-03-22T15:30:12.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-10T02:55:50.000Z", "avg_line_length": 26.2716049383, "max_line_length": 53, "alphanum_fraction": 0.6484962406, "num_tokens": 672, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183443, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7500096410738255}} {"text": "!Autor: Claudio Iván Esparza Castañeda\n!Título: Müller\n!Descripción: Se encarga de calcular las raíces de un polinomio a partir del método de Müller\n!Fecha: 22/03/2020\nProgram bair\n implicit none\n REAL, allocatable, dimension(:)::A, B, BP, BQ\n REAL::e, h, f, p, q, dp, dq, dn, r, rt, z, x1, x2\n INTEGER::i, n, j\n COMPLEX::y1, y2\n COMPLEX, allocatable, dimension(:)::C\n1 WRITE(*, *) \"Grado del polinomio:\"\n READ(*, *) n\n allocate(A(0:n), B(0:n), BP(0:n), BQ(0:n))\n WRITE(*, *) \"Coeficientes del polinomio a0+a1x+a2x²+...anx^n\"\n do i=0, n\n READ(*, *) A(i)\n end do\n p=0\n q=0\n WRITE(*, *) \"Error\"\n READ(*, *) e\n do\n do i=n, 1, -1\n B(i)=A(i)-p*B(i+1)-q*B(i+2)\n end do\n B(0)=A(0)-Q*B(2)\n do i=n, 1, -1\n BP(i)=-B(i+1)-p*BP(i+1)-Q*BP(i+2)\n BQ(i)=-BQ(i+1)-B(i+2)-Q*BQ(i+2)\n end do\n BP(0)=-Q*BP(2)\n BQ(0)=-Q*BQ(2)-B(2)\n dn=BP(0)*BQ(1)-BP(1)*BQ(0)\n dp=(B(0)*BQ(1)-B(1)*BQ(0))/dn\n p=p-dp\n dq=(B(1)*BP(0)-B(0)*BP(1))/dn\n q=q-dq\n j=j+1\n if (abs(dq)*abs(dp) .le. e) then\n EXIT\n end if\n end do\n WRITE(*, *) p, q\n r=p*p-4*q\n if (r .ge. 0) then\n rt=sqrt(r)\n x1=(-p+rt)/2\n x2=(-p-rt)/2\n WRITE(*, *) \"Las raíces son:\"\n WRITE(*, *) x1, x2\n end if\n if (r .lt. 0) then\n rt=sqrt(-r)\n y1=COMPLEX(-p/2, rt/2)\n y2=COMPLEX(-p/2, -rt/2)\n WRITE(*, *) \"Las raíces son:\"\n WRITE(*, *) y1, y2\n end if\n WRITE(*, *) \"Orden Coeficientes\"\n do i=2, n\n WRITE(*, *) i-2, B(i)\n end do\n deallocate(A, B, BP, BQ)\n goto 1\nend Program bair\n\n\n\n\n", "meta": {"hexsha": "6797e7bf291b021131a242fcdf8d1d2ecb11b520", "size": 1563, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "17.- Bairstow/Bairstow.f90", "max_stars_repo_name": "clivan/Fortran", "max_stars_repo_head_hexsha": "4f842c6433899cc36b8c27c71f7667ba0ed15312", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "17.- Bairstow/Bairstow.f90", "max_issues_repo_name": "clivan/Fortran", "max_issues_repo_head_hexsha": "4f842c6433899cc36b8c27c71f7667ba0ed15312", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "17.- Bairstow/Bairstow.f90", "max_forks_repo_name": "clivan/Fortran", "max_forks_repo_head_hexsha": "4f842c6433899cc36b8c27c71f7667ba0ed15312", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.014084507, "max_line_length": 93, "alphanum_fraction": 0.5022392834, "num_tokens": 736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7500096369947901}}